joey shelton / LED_Demo

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers coap_service_api.h Source File

coap_service_api.h

00001 /*
00002  * Copyright (c) 2015-2016 ARM Limited. All Rights Reserved.
00003  *
00004  * SPDX-License-Identifier: Apache-2.0
00005  *
00006  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00007  * not use this file except in compliance with the License.
00008  * You may obtain a copy of the License at
00009  *
00010  * http://www.apache.org/licenses/LICENSE-2.0
00011  *
00012  * Unless required by applicable law or agreed to in writing, software
00013  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00014  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00015  * See the License for the specific language governing permissions and
00016  * limitations under the License.
00017  */
00018 
00019 #ifndef COAP_SERVICE_API_H_
00020 #define COAP_SERVICE_API_H_
00021 
00022 #ifdef __cplusplus
00023 extern "C" {
00024 #endif
00025 
00026 #include <string.h>
00027 
00028 #include "ns_types.h"
00029 #include "sn_coap_header.h"
00030 #include "ns_address.h"
00031 
00032 /**
00033  * This interface is used in sending and receiving of CoAP messages to multicast address and receive multiple responses.
00034  */
00035 
00036 // Allowed_methods
00037 #define COAP_SERVICE_ACCESS_ALL_ALLOWED         0x0F
00038 #define COAP_SERVICE_ACCESS_GET_ALLOWED         0x01
00039 #define COAP_SERVICE_ACCESS_PUT_ALLOWED         0x02
00040 #define COAP_SERVICE_ACCESS_POST_ALLOWED        0x04
00041 #define COAP_SERVICE_ACCESS_DELETE_ALLOWED      0x08
00042 
00043 // Bits for service options
00044 #define COAP_SERVICE_OPTIONS_NONE               0x00
00045 #define COAP_SERVICE_OPTIONS_VIRTUAL_SOCKET     0x01
00046 #define COAP_SERVICE_OPTIONS_SECURE             0x02
00047 #define COAP_SERVICE_OPTIONS_EPHEMERAL_PORT     0x04
00048 /** Link-layer security bypass option is set*/
00049 #define COAP_SERVICE_OPTIONS_SECURE_BYPASS      0x80
00050 
00051 // Bits for request options
00052 #define COAP_REQUEST_OPTIONS_NONE               0x00
00053 #define COAP_REQUEST_OPTIONS_ADDRESS_DEFAULT    0x00//!< default is not setting either short or long.
00054 #define COAP_REQUEST_OPTIONS_ADDRESS_LONG       0x01
00055 #define COAP_REQUEST_OPTIONS_ADDRESS_SHORT      0x02
00056 #define COAP_REQUEST_OPTIONS_MULTICAST          0x04 //!< indicates that CoAP library support multicasting
00057 #define COAP_REQUEST_OPTIONS_SECURE_BYPASS      0x08
00058 
00059 /**
00060  * \brief Service message response receive callback.
00061  *
00062  * Function that handles CoAP service message receiving and parsing
00063  *
00064  * \param msg_id           Id number of the current message.
00065  * \param source_address   IPv6 source address.
00066  * \param source_port      Source port
00067  * \param response_ptr     Pointer to CoAP header structure.
00068  *
00069  * \return 0 for success / -1 for failure
00070   */
00071 typedef int coap_service_response_recv(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *response_ptr);
00072 
00073 /**
00074  * \brief CoAP service request callback
00075  *
00076  * CoAP service request message receiving and parsing function
00077  *
00078  * \param service_id         Id number of the current service.
00079  * \param source_address     IPv6 source address.
00080  * \param source_port        Source port
00081  * \param request_ptr        Pointer to CoAP header structure.
00082  *
00083  * \return Status
00084  */
00085 typedef int coap_service_request_recv_cb(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *request_ptr);
00086 
00087 /**
00088  * \brief Security service start callback
00089  *
00090  * Starts security service handling and fetches device password.
00091  *
00092  * \param service_id         Id number of the current service.
00093  * \param address            Address of sender
00094  * \param port               Port of the device
00095  *
00096  * \return 0 for success / -1 for failure
00097  */
00098 typedef int coap_service_security_start_cb(int8_t service_id, uint8_t address[static 16], uint16_t port, uint8_t* pw, uint8_t *pw_len);
00099 
00100 /**
00101  * \brief CoAP service security done callback
00102  *
00103  * CoAP service security done callback function.
00104  *
00105  * \param service_id         Id number of the current service.
00106  * \param address            Address of sender
00107  * \param keyblock           Security key (40 bits)
00108  *
00109  * \return 0 for success / -1 for failure
00110  */
00111 typedef int coap_service_security_done_cb(int8_t service_id, uint8_t address[static 16], uint8_t keyblock[static 40]);
00112 
00113 /**
00114  * \brief Initialise server instance.
00115  *
00116  * Initialise Thread services for the registered application.
00117  *
00118  * \param interface_id       Informs registered application interface id. This parameter is passed to socket implementation.
00119  * \param listen_port        Port that Application wants to use for communicate with coap server.
00120  * \param service_options    Options of the current service.
00121  * \param *start_ptr         Callback to inform security handling is started and to fetch device password.
00122  * \param *coap_security_done_cb  Callback to inform security handling is done.
00123  *
00124  *  \return service_id / -1 for failure
00125  */
00126 extern int8_t coap_service_initialize(int8_t interface_id, uint16_t listen_port, uint8_t service_options, coap_service_security_start_cb *start_ptr, coap_service_security_done_cb *coap_security_done_cb);
00127 
00128 /**
00129  * \brief Service delete
00130  *
00131  * Removes all data related to this instance
00132  *
00133  * \param service_id         Id number of the current service.
00134  */
00135 extern void coap_service_delete( int8_t service_id );
00136 
00137 /**
00138  * \brief Close secure connection
00139  *
00140  * Closes secure connection (if present), but leaves socket open.
00141  *
00142  * \param service_id         Id number of the current service.
00143  */
00144 extern void coap_service_close_secure_connection(int8_t service_id, uint8_t destination_addr_ptr[static 16], uint16_t port);
00145 
00146 /**
00147  * \brief Sets password for device
00148  *
00149  * \param service_id         Service id
00150  * \param address            Device address
00151  * \param port               Device port
00152  * \param pw_ptr             Pointer to password.
00153  * \param pw_len             Lenght of password.
00154  *
00155  * \return 0 for success / -1 for failure
00156  */
00157 //int coap_service_security_key_set(int8_t service_id, uint8_t address[static 16], uint16_t port, uint8_t *pw_ptr, uint8_t pw_len);
00158 
00159 /**
00160  * \brief Virtual socket sent callback.
00161  *
00162  * Sent data to virtual socket.
00163  *
00164  * \param service_id                       Id number of the current service.
00165  * \param destination_addr_ptr             Receiver IPv6 address.
00166  * \param port                             Receiver port number.
00167  * \param *data_ptr                        Pointer to the data.
00168  * \param data_len                         Lenght of the data.
00169  *
00170  * \return 0 for success / -1 for failure
00171   */
00172 typedef int coap_service_virtual_socket_send_cb(int8_t service_id, uint8_t destination_addr_ptr[static 16], uint16_t port, const uint8_t *data_ptr, uint16_t data_len);
00173 
00174 /**
00175  * \brief Virtual socket read.
00176  *
00177  * Receive data from virtual socket.
00178  *
00179  * \param service_id                       Id number of the current service.
00180  * \param source_addr_ptr                  Receiver IPv6 address.
00181  * \param port                             Receiver port number.
00182  * \param *data_ptr                        Pointer to the data
00183  * \param data_len                         Lenght of the data
00184  *
00185  * \return 0 for success / -1 for failure
00186   */
00187 extern int16_t coap_service_virtual_socket_recv(int8_t service_id, uint8_t source_addr_ptr[static 16], uint16_t port, uint8_t *data_ptr, uint16_t data_len);
00188 
00189 /**
00190  * \brief Set virtual socket
00191  *
00192  * Sets virtual socket for CoAP services.
00193  *
00194  * \param service_id         Id number of the current service.
00195  * \param *send_method_ptr   Callback to coap virtual socket.
00196  *
00197  * \return 0 for success / -1 for failure
00198  */
00199 extern int16_t coap_service_virtual_socket_set_cb(int8_t service_id, coap_service_virtual_socket_send_cb *send_method_ptr);
00200 
00201 /**
00202  * \brief Register unsecure callback methods to CoAP server
00203  *
00204  * Register application and informs CoAP services unsecure registery callback function.
00205  *
00206  * \param service_id       Id number of the current service.
00207  * \param *uri             Uri address.
00208  * \param port             port that Application wants to use for communicate with coap server.
00209  * \param allowed_method   Informs method that is allowed to use (used defines described above).
00210  * \param *request_recv_cb CoAP service request receive callback function pointer.
00211  *
00212  * \return 0 for success / -1 for failure
00213  */
00214 extern int8_t coap_service_register_uri(int8_t service_id, const char *uri, uint8_t allowed_method, coap_service_request_recv_cb *request_recv_cb);
00215 
00216 /**
00217  * \brief Unregister unsecure callback methods to CoAP server
00218  *
00219  * Register application and informs CoAP services unsecure registery callback function.
00220  *
00221  * \param service_id       Id number of the current service.
00222  * \param *uri             Uri address.
00223  *
00224  * \return 0 for success / -1 for failure
00225  */
00226 extern int8_t coap_service_unregister_uri(int8_t service_id, const char *uri);
00227 
00228 /**
00229  * \brief Sends CoAP service request
00230  *
00231  * Build and sends CoAP service request message.
00232  *
00233  * \param service_id            Id number of the current service.
00234  * \param options               Options defined above.
00235  * \param destination_addr                  IPv6 address.
00236  * \param destination_port      Destination port
00237  * \param msg_type              Message type can be found from sn_coap_header.
00238  * \param msg_code              Message code can be found from sn_coap_header.
00239  * \param *uri                  Uri address.
00240  * \param cont_type             Content type can be found from sn_coap_header.
00241  * \param payload_ptr           Pointer to message content.
00242  * \param payload_len           Lenght of the message.
00243  * \param *request_response_cb  Callback to inform result of the request.
00244  *
00245  * \return msg_id               Id number of the current message.
00246  */
00247 extern uint16_t coap_service_request_send(int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], uint16_t destination_port, sn_coap_msg_type_e msg_type, sn_coap_msg_code_e msg_code, const char *uri,
00248         sn_coap_content_format_e cont_type, const uint8_t *payload_ptr, uint16_t payload_len, coap_service_response_recv *request_response_cb);
00249 
00250 /**
00251  * \brief Sends CoAP service response
00252  *
00253  * Build and sends CoAP service response message.
00254  *
00255  * \param service_id       Id number of the current service.
00256  * \param msg_id           Message ID number.
00257  * \param options          Options defined above.
00258  * \param response_ptr     Pointer to CoAP header structure.
00259  *
00260  * \return -1              For failure
00261  *-         0              For success
00262  */
00263 extern int8_t coap_service_response_send(int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, sn_coap_content_format_e content_type, const uint8_t *payload_ptr,uint16_t payload_len);
00264 
00265 extern int8_t coap_service_set_handshake_timeout(int8_t service_id, uint32_t min, uint32_t max);
00266 #ifdef __cplusplus
00267 }
00268 #endif
00269 
00270 #endif /* COAP_SERVICE_API_H_ */