Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: TYBLE16_simple_data_logger TYBLE16_MP3_Air
coap_message_handler.h
00001 /* 00002 * Copyright (c) 2015-2017, Arm Limited and affiliates. 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 #ifndef __COAP_MESSAGE_HANDLER_H__ 00019 #define __COAP_MESSAGE_HANDLER_H__ 00020 00021 #include <inttypes.h> 00022 #include "mbed-coap/sn_coap_header.h" 00023 #include "ns_list.h" 00024 00025 #define TRANSACTION_LIFETIME 180 00026 00027 /* Default value for CoAP duplicate message buffer (0 = disabled) */ 00028 #define DUPLICATE_MESSAGE_BUFFER_SIZE 0 00029 00030 /* Default value for CoAP blockwise data size (0 = disabled) */ 00031 #define DEFAULT_BLOCKWISE_DATA_SIZE 0 00032 00033 /* Default values for CoAP resendings */ 00034 #define COAP_RESENDING_COUNT 3 00035 #define COAP_RESENDING_INTERVAL 10 00036 00037 /** 00038 * \brief Service message response receive callback. 00039 * 00040 * Function that handles CoAP service message receiving and parsing 00041 * 00042 * \param msg_id Id number of the current message. 00043 * \param response_ptr Pointer to CoAP header structure. 00044 * 00045 * \return 0 for success / -1 for failure 00046 */ 00047 typedef int coap_message_handler_response_recv(int8_t service_id, uint8_t source_address[static 16], uint16_t source_port, sn_coap_hdr_s *response_ptr); 00048 00049 typedef struct coap_msg_handler_s { 00050 void *(*sn_coap_service_malloc)(uint16_t); 00051 void (*sn_coap_service_free)(void *); 00052 uint8_t (*sn_coap_tx_callback)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *); 00053 struct coap_s *coap; 00054 } coap_msg_handler_t; 00055 00056 typedef struct coap_transaction { 00057 uint8_t remote_address[16]; 00058 uint8_t local_address[16]; 00059 uint8_t token[8]; 00060 uint32_t valid_until; 00061 uint8_t *data_ptr; 00062 coap_message_handler_response_recv *resp_cb; 00063 uint16_t remote_port; 00064 uint16_t msg_id; 00065 uint16_t data_len; 00066 int8_t service_id; 00067 uint8_t options; 00068 uint8_t token_len; 00069 sn_coap_msg_type_e req_msg_type; 00070 bool client_request: 1; 00071 00072 ns_list_link_t link; 00073 } coap_transaction_t; 00074 00075 /** 00076 * \brief Service message processing callback. 00077 * 00078 * Function that processes CoAP service message 00079 * 00080 * \param socket_id Socket that receives the message. 00081 * \param recv_if_id Interface where message is received. 00082 * \param coap_message Actual CoAP message. 00083 * \param transaction_ptr Message transaction. 00084 * \param local_addr Address where message is received. 00085 * 00086 * \return 0 for success / -1 for failure 00087 */ 00088 typedef int16_t coap_msg_process_cb(int8_t socket_id, int8_t recv_if_id, sn_coap_hdr_s *coap_message, coap_transaction_t *transaction_ptr, const uint8_t *local_addr); 00089 00090 extern coap_msg_handler_t *coap_message_handler_init(void *(*used_malloc_func_ptr)(uint16_t), void (*used_free_func_ptr)(void *), 00091 uint8_t (*used_tx_callback_ptr)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *)); 00092 00093 extern int8_t coap_message_handler_destroy(coap_msg_handler_t *handle); 00094 00095 extern coap_transaction_t *coap_message_handler_transaction_valid(coap_transaction_t *tr_ptr); 00096 00097 extern coap_transaction_t *coap_message_handler_find_transaction(uint8_t *address_ptr, uint16_t port); 00098 00099 extern int16_t coap_message_handler_coap_msg_process(coap_msg_handler_t *handle, int8_t socket_id, int8_t recv_if_id, const uint8_t source_addr_ptr[static 16], uint16_t port, 00100 const uint8_t dst_addr_ptr[static 16], uint8_t *data_ptr, uint16_t data_len, coap_msg_process_cb *msg_process_callback); 00101 00102 extern uint16_t coap_message_handler_request_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, const uint8_t destination_addr[static 16], 00103 uint16_t destination_port, sn_coap_msg_type_e msg_type, sn_coap_msg_code_e msg_code, const char *uri, sn_coap_content_format_e cont_type, 00104 const uint8_t *payload_ptr, uint16_t payload_len, coap_message_handler_response_recv *request_response_cb); 00105 00106 extern int8_t coap_message_handler_response_send(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, sn_coap_hdr_s *request_ptr, sn_coap_msg_code_e message_code, 00107 sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len); 00108 00109 extern int8_t coap_message_handler_request_delete(coap_msg_handler_t *handle, int8_t service_id, uint16_t msg_id); 00110 00111 extern int8_t coap_message_handler_request_delete_by_service_id(coap_msg_handler_t *handle, int8_t service_id); 00112 00113 extern int8_t coap_message_handler_exec(coap_msg_handler_t *handle, uint32_t current_time); 00114 00115 extern void transaction_delete(coap_transaction_t *this); 00116 00117 extern void transactions_delete_all(uint8_t *address_ptr, uint16_t port); 00118 00119 extern int8_t coap_message_handler_response_send_by_msg_id(coap_msg_handler_t *handle, int8_t service_id, uint8_t options, uint16_t msg_id, sn_coap_msg_code_e message_code, 00120 sn_coap_content_format_e content_type, const uint8_t *payload_ptr, uint16_t payload_len); 00121 00122 #endif
Generated on Tue Jul 12 2022 13:54:12 by
