mbed client lightswitch demo
Dependencies: mbed Socket lwip-eth lwip-sys lwip
Fork of mbed-client-classic-example-lwip by
mbed-client-c/source/libCoap/src/include/sn_coap_protocol_internal.h@11:cada08fc8a70, 2016-06-09 (annotated)
- Committer:
- mbedAustin
- Date:
- Thu Jun 09 17:08:36 2016 +0000
- Revision:
- 11:cada08fc8a70
Commit for public Consumption
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedAustin | 11:cada08fc8a70 | 1 | /* |
mbedAustin | 11:cada08fc8a70 | 2 | * Copyright (c) 2011-2015 ARM Limited. All rights reserved. |
mbedAustin | 11:cada08fc8a70 | 3 | * SPDX-License-Identifier: Apache-2.0 |
mbedAustin | 11:cada08fc8a70 | 4 | * Licensed under the Apache License, Version 2.0 (the License); you may |
mbedAustin | 11:cada08fc8a70 | 5 | * not use this file except in compliance with the License. |
mbedAustin | 11:cada08fc8a70 | 6 | * You may obtain a copy of the License at |
mbedAustin | 11:cada08fc8a70 | 7 | * |
mbedAustin | 11:cada08fc8a70 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbedAustin | 11:cada08fc8a70 | 9 | * |
mbedAustin | 11:cada08fc8a70 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbedAustin | 11:cada08fc8a70 | 11 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
mbedAustin | 11:cada08fc8a70 | 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbedAustin | 11:cada08fc8a70 | 13 | * See the License for the specific language governing permissions and |
mbedAustin | 11:cada08fc8a70 | 14 | * limitations under the License. |
mbedAustin | 11:cada08fc8a70 | 15 | */ |
mbedAustin | 11:cada08fc8a70 | 16 | |
mbedAustin | 11:cada08fc8a70 | 17 | /** |
mbedAustin | 11:cada08fc8a70 | 18 | * \file sn_coap_protocol_internal.h |
mbedAustin | 11:cada08fc8a70 | 19 | * |
mbedAustin | 11:cada08fc8a70 | 20 | * \brief Header file for CoAP Protocol part |
mbedAustin | 11:cada08fc8a70 | 21 | * |
mbedAustin | 11:cada08fc8a70 | 22 | */ |
mbedAustin | 11:cada08fc8a70 | 23 | |
mbedAustin | 11:cada08fc8a70 | 24 | #ifndef SN_COAP_PROTOCOL_INTERNAL_H_ |
mbedAustin | 11:cada08fc8a70 | 25 | #define SN_COAP_PROTOCOL_INTERNAL_H_ |
mbedAustin | 11:cada08fc8a70 | 26 | |
mbedAustin | 11:cada08fc8a70 | 27 | #include "ns_list.h" |
mbedAustin | 11:cada08fc8a70 | 28 | #include "sn_coap_header_internal.h" |
mbedAustin | 11:cada08fc8a70 | 29 | |
mbedAustin | 11:cada08fc8a70 | 30 | #ifdef __cplusplus |
mbedAustin | 11:cada08fc8a70 | 31 | extern "C" { |
mbedAustin | 11:cada08fc8a70 | 32 | #endif |
mbedAustin | 11:cada08fc8a70 | 33 | |
mbedAustin | 11:cada08fc8a70 | 34 | struct coap_s { |
mbedAustin | 11:cada08fc8a70 | 35 | void *(*sn_coap_protocol_malloc)(uint16_t); |
mbedAustin | 11:cada08fc8a70 | 36 | void (*sn_coap_protocol_free)(void *); |
mbedAustin | 11:cada08fc8a70 | 37 | |
mbedAustin | 11:cada08fc8a70 | 38 | uint8_t (*sn_coap_tx_callback)(uint8_t *, uint16_t, sn_nsdl_addr_s *, void *); |
mbedAustin | 11:cada08fc8a70 | 39 | int8_t (*sn_coap_rx_callback)(sn_coap_hdr_s *, sn_nsdl_addr_s *, void *); |
mbedAustin | 11:cada08fc8a70 | 40 | }; |
mbedAustin | 11:cada08fc8a70 | 41 | |
mbedAustin | 11:cada08fc8a70 | 42 | /* * * * * * * * * * * */ |
mbedAustin | 11:cada08fc8a70 | 43 | /* * * * DEFINES * * * */ |
mbedAustin | 11:cada08fc8a70 | 44 | /* * * * * * * * * * * */ |
mbedAustin | 11:cada08fc8a70 | 45 | |
mbedAustin | 11:cada08fc8a70 | 46 | /* * For Message resending * */ |
mbedAustin | 11:cada08fc8a70 | 47 | #define ENABLE_RESENDINGS 1 /**< Enable / Disable resending from library in building */ |
mbedAustin | 11:cada08fc8a70 | 48 | |
mbedAustin | 11:cada08fc8a70 | 49 | #define SN_COAP_RESENDING_MAX_COUNT 3 /**< Default number of re-sendings */ |
mbedAustin | 11:cada08fc8a70 | 50 | #define SN_COAP_RESENDING_QUEUE_SIZE_MSGS 2 /**< Default re-sending queue size - defines how many messages can be stored. Setting this to 0 disables feature */ |
mbedAustin | 11:cada08fc8a70 | 51 | #define SN_COAP_RESENDING_QUEUE_SIZE_BYTES 0 /**< Default re-sending queue size - defines size of the re-sending buffer. Setting this to 0 disables feature */ |
mbedAustin | 11:cada08fc8a70 | 52 | #define DEFAULT_RESPONSE_TIMEOUT 10 /**< Default re-sending timeout as seconds */ |
mbedAustin | 11:cada08fc8a70 | 53 | |
mbedAustin | 11:cada08fc8a70 | 54 | /* These parameters sets maximum values application can set with API */ |
mbedAustin | 11:cada08fc8a70 | 55 | #define SN_COAP_MAX_ALLOWED_RESENDING_COUNT 6 /**< Maximum allowed count of re-sending */ |
mbedAustin | 11:cada08fc8a70 | 56 | #define SN_COAP_MAX_ALLOWED_RESENDING_BUFF_SIZE_MSGS 6 /**< Maximum allowed number of saved re-sending messages */ |
mbedAustin | 11:cada08fc8a70 | 57 | #define SN_COAP_MAX_ALLOWED_RESENDING_BUFF_SIZE_BYTES 512 /**< Maximum allowed size of re-sending buffer */ |
mbedAustin | 11:cada08fc8a70 | 58 | #define SN_COAP_MAX_ALLOWED_RESPONSE_TIMEOUT 40 /**< Maximum allowed re-sending timeout */ |
mbedAustin | 11:cada08fc8a70 | 59 | |
mbedAustin | 11:cada08fc8a70 | 60 | #define RESPONSE_RANDOM_FACTOR 1 /**< Resending random factor, value is specified in IETF CoAP specification */ |
mbedAustin | 11:cada08fc8a70 | 61 | |
mbedAustin | 11:cada08fc8a70 | 62 | /* * For Message duplication detecting * */ |
mbedAustin | 11:cada08fc8a70 | 63 | |
mbedAustin | 11:cada08fc8a70 | 64 | /* Init value for the maximum count of messages to be stored for duplication detection */ |
mbedAustin | 11:cada08fc8a70 | 65 | /* Setting of this value to 0 will disable duplication check, also reduce use of ROM memory */ |
mbedAustin | 11:cada08fc8a70 | 66 | #ifndef SN_COAP_DUPLICATION_MAX_MSGS_COUNT |
mbedAustin | 11:cada08fc8a70 | 67 | #define SN_COAP_DUPLICATION_MAX_MSGS_COUNT 0 |
mbedAustin | 11:cada08fc8a70 | 68 | #endif |
mbedAustin | 11:cada08fc8a70 | 69 | /* Maximum allowed number of saved messages for duplicate searching */ |
mbedAustin | 11:cada08fc8a70 | 70 | #define SN_COAP_MAX_ALLOWED_DUPLICATION_MESSAGE_COUNT 6 |
mbedAustin | 11:cada08fc8a70 | 71 | |
mbedAustin | 11:cada08fc8a70 | 72 | /* Maximum time in seconds of messages to be stored for duplication detection */ |
mbedAustin | 11:cada08fc8a70 | 73 | #define SN_COAP_DUPLICATION_MAX_TIME_MSGS_STORED 60 /* RESPONSE_TIMEOUT * RESPONSE_RANDOM_FACTOR * (2 ^ MAX_RETRANSMIT - 1) + the expected maximum round trip time */ |
mbedAustin | 11:cada08fc8a70 | 74 | |
mbedAustin | 11:cada08fc8a70 | 75 | /* * For Message blockwising * */ |
mbedAustin | 11:cada08fc8a70 | 76 | |
mbedAustin | 11:cada08fc8a70 | 77 | /* Init value for the maximum payload size to be sent and received at one blockwise message */ |
mbedAustin | 11:cada08fc8a70 | 78 | /* Setting of this value to 0 will disable this feature, and also reduce use of ROM memory */ |
mbedAustin | 11:cada08fc8a70 | 79 | /* Note: Current Coap implementation supports Blockwise transfers specification version draft-ietf-core-block-03 */ |
mbedAustin | 11:cada08fc8a70 | 80 | /* Note: This define is common for both received and sent Blockwise messages */ |
mbedAustin | 11:cada08fc8a70 | 81 | #ifndef SN_COAP_BLOCKWISE_MAX_PAYLOAD_SIZE |
mbedAustin | 11:cada08fc8a70 | 82 | #define SN_COAP_BLOCKWISE_MAX_PAYLOAD_SIZE 0 /**< Must be 2^x and x is at least 4. Suitable values: 0, 16, 32, 64, 128, 256, 512 and 1024 */ |
mbedAustin | 11:cada08fc8a70 | 83 | #endif |
mbedAustin | 11:cada08fc8a70 | 84 | |
mbedAustin | 11:cada08fc8a70 | 85 | #ifndef SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED |
mbedAustin | 11:cada08fc8a70 | 86 | #define SN_COAP_BLOCKWISE_MAX_TIME_DATA_STORED 10 /**< Maximum time in seconds of data (messages and payload) to be stored for blockwising */ |
mbedAustin | 11:cada08fc8a70 | 87 | #endif |
mbedAustin | 11:cada08fc8a70 | 88 | |
mbedAustin | 11:cada08fc8a70 | 89 | |
mbedAustin | 11:cada08fc8a70 | 90 | /* * * * * * * * * * * * * * */ |
mbedAustin | 11:cada08fc8a70 | 91 | /* * * * ENUMERATIONS * * * */ |
mbedAustin | 11:cada08fc8a70 | 92 | /* * * * * * * * * * * * * * */ |
mbedAustin | 11:cada08fc8a70 | 93 | |
mbedAustin | 11:cada08fc8a70 | 94 | /* * * * * * * * * * * * * */ |
mbedAustin | 11:cada08fc8a70 | 95 | /* * * * STRUCTURES * * * */ |
mbedAustin | 11:cada08fc8a70 | 96 | /* * * * * * * * * * * * * */ |
mbedAustin | 11:cada08fc8a70 | 97 | |
mbedAustin | 11:cada08fc8a70 | 98 | |
mbedAustin | 11:cada08fc8a70 | 99 | /* Structure which is stored to Linked list for message sending purposes */ |
mbedAustin | 11:cada08fc8a70 | 100 | typedef struct coap_send_msg_ { |
mbedAustin | 11:cada08fc8a70 | 101 | uint8_t resending_counter; /* Tells how many times message is still tried to resend */ |
mbedAustin | 11:cada08fc8a70 | 102 | uint32_t resending_time; /* Tells next resending time */ |
mbedAustin | 11:cada08fc8a70 | 103 | |
mbedAustin | 11:cada08fc8a70 | 104 | sn_nsdl_transmit_s *send_msg_ptr; |
mbedAustin | 11:cada08fc8a70 | 105 | |
mbedAustin | 11:cada08fc8a70 | 106 | struct coap_s *coap; /* CoAP library handle */ |
mbedAustin | 11:cada08fc8a70 | 107 | void *param; /* Extra parameter that will be passed to TX/RX callback functions */ |
mbedAustin | 11:cada08fc8a70 | 108 | |
mbedAustin | 11:cada08fc8a70 | 109 | ns_list_link_t link; |
mbedAustin | 11:cada08fc8a70 | 110 | } coap_send_msg_s; |
mbedAustin | 11:cada08fc8a70 | 111 | |
mbedAustin | 11:cada08fc8a70 | 112 | typedef NS_LIST_HEAD(coap_send_msg_s, link) coap_send_msg_list_t; |
mbedAustin | 11:cada08fc8a70 | 113 | |
mbedAustin | 11:cada08fc8a70 | 114 | /* Structure which is stored to Linked list for message duplication detection purposes */ |
mbedAustin | 11:cada08fc8a70 | 115 | typedef struct coap_duplication_info_ { |
mbedAustin | 11:cada08fc8a70 | 116 | uint32_t timestamp; /* Tells when duplication information is stored to Linked list */ |
mbedAustin | 11:cada08fc8a70 | 117 | |
mbedAustin | 11:cada08fc8a70 | 118 | uint8_t addr_len; |
mbedAustin | 11:cada08fc8a70 | 119 | uint8_t *addr_ptr; |
mbedAustin | 11:cada08fc8a70 | 120 | uint16_t port; |
mbedAustin | 11:cada08fc8a70 | 121 | |
mbedAustin | 11:cada08fc8a70 | 122 | uint16_t msg_id; |
mbedAustin | 11:cada08fc8a70 | 123 | |
mbedAustin | 11:cada08fc8a70 | 124 | struct coap_s *coap; /* CoAP library handle */ |
mbedAustin | 11:cada08fc8a70 | 125 | |
mbedAustin | 11:cada08fc8a70 | 126 | ns_list_link_t link; |
mbedAustin | 11:cada08fc8a70 | 127 | } coap_duplication_info_s; |
mbedAustin | 11:cada08fc8a70 | 128 | |
mbedAustin | 11:cada08fc8a70 | 129 | typedef NS_LIST_HEAD(coap_duplication_info_s, link) coap_duplication_info_list_t; |
mbedAustin | 11:cada08fc8a70 | 130 | |
mbedAustin | 11:cada08fc8a70 | 131 | /* Structure which is stored to Linked list for blockwise messages sending purposes */ |
mbedAustin | 11:cada08fc8a70 | 132 | typedef struct coap_blockwise_msg_ { |
mbedAustin | 11:cada08fc8a70 | 133 | uint32_t timestamp; /* Tells when Blockwise message is stored to Linked list */ |
mbedAustin | 11:cada08fc8a70 | 134 | |
mbedAustin | 11:cada08fc8a70 | 135 | sn_coap_hdr_s *coap_msg_ptr; |
mbedAustin | 11:cada08fc8a70 | 136 | struct coap_s *coap; /* CoAP library handle */ |
mbedAustin | 11:cada08fc8a70 | 137 | |
mbedAustin | 11:cada08fc8a70 | 138 | ns_list_link_t link; |
mbedAustin | 11:cada08fc8a70 | 139 | } coap_blockwise_msg_s; |
mbedAustin | 11:cada08fc8a70 | 140 | |
mbedAustin | 11:cada08fc8a70 | 141 | typedef NS_LIST_HEAD(coap_blockwise_msg_s, link) coap_blockwise_msg_list_t; |
mbedAustin | 11:cada08fc8a70 | 142 | |
mbedAustin | 11:cada08fc8a70 | 143 | /* Structure which is stored to Linked list for blockwise messages receiving purposes */ |
mbedAustin | 11:cada08fc8a70 | 144 | typedef struct coap_blockwise_payload_ { |
mbedAustin | 11:cada08fc8a70 | 145 | uint32_t timestamp; /* Tells when Payload is stored to Linked list */ |
mbedAustin | 11:cada08fc8a70 | 146 | |
mbedAustin | 11:cada08fc8a70 | 147 | uint8_t addr_len; |
mbedAustin | 11:cada08fc8a70 | 148 | uint8_t *addr_ptr; |
mbedAustin | 11:cada08fc8a70 | 149 | uint16_t port; |
mbedAustin | 11:cada08fc8a70 | 150 | |
mbedAustin | 11:cada08fc8a70 | 151 | uint16_t payload_len; |
mbedAustin | 11:cada08fc8a70 | 152 | uint8_t *payload_ptr; |
mbedAustin | 11:cada08fc8a70 | 153 | struct coap_s *coap; /* CoAP library handle */ |
mbedAustin | 11:cada08fc8a70 | 154 | |
mbedAustin | 11:cada08fc8a70 | 155 | ns_list_link_t link; |
mbedAustin | 11:cada08fc8a70 | 156 | } coap_blockwise_payload_s; |
mbedAustin | 11:cada08fc8a70 | 157 | |
mbedAustin | 11:cada08fc8a70 | 158 | typedef NS_LIST_HEAD(coap_blockwise_payload_s, link) coap_blockwise_payload_list_t; |
mbedAustin | 11:cada08fc8a70 | 159 | |
mbedAustin | 11:cada08fc8a70 | 160 | #ifdef __cplusplus |
mbedAustin | 11:cada08fc8a70 | 161 | } |
mbedAustin | 11:cada08fc8a70 | 162 | #endif |
mbedAustin | 11:cada08fc8a70 | 163 | |
mbedAustin | 11:cada08fc8a70 | 164 | #endif /* SN_COAP_PROTOCOL_INTERNAL_H_ */ |
mbedAustin | 11:cada08fc8a70 | 165 | |
mbedAustin | 11:cada08fc8a70 | 166 |