60 #define COAP_MAX_PACKET_SIZE (COAP_MAX_HEADER_SIZE + COAP_MAX_CHUNK_SIZE) 63 #ifndef COAP_MAX_BLOCK_SIZE 64 #define COAP_MAX_BLOCK_SIZE (COAP_MAX_CHUNK_SIZE < 32 ? 16 : \ 65 (COAP_MAX_CHUNK_SIZE < 64 ? 32 : \ 66 (COAP_MAX_CHUNK_SIZE < 128 ? 64 : \ 67 (COAP_MAX_CHUNK_SIZE < 256 ? 128 : \ 68 (COAP_MAX_CHUNK_SIZE < 512 ? 256 : \ 69 (COAP_MAX_CHUNK_SIZE < 1024 ? 512 : \ 70 (COAP_MAX_CHUNK_SIZE < 2048 ? 1024 : 2048))))))) 74 #define COAP_OPTION_MAP_SIZE (sizeof(uint8_t) * 8) 81 coap_message_type_t type;
86 uint8_t token[COAP_TOKEN_LEN];
88 uint8_t options[COAP_OPTION_SIZE1 / COAP_OPTION_MAP_SIZE + 1];
90 uint16_t content_format;
93 uint8_t etag[COAP_ETAG_LEN];
95 const char *proxy_uri;
96 size_t proxy_scheme_len;
97 const char *proxy_scheme;
100 size_t location_path_len;
101 const char *location_path;
103 size_t location_query_len;
104 const char *location_query;
106 const char *uri_path;
109 uint8_t if_match_len;
110 uint8_t if_match[COAP_ETAG_LEN];
113 uint16_t block2_size;
114 uint32_t block2_offset;
117 uint16_t block1_size;
118 uint32_t block1_offset;
121 size_t uri_query_len;
122 const char *uri_query;
123 uint8_t if_none_match;
125 const coap_endpoint_t *src_ep;
127 uint16_t payload_len;
132 coap_set_option(coap_message_t *message,
unsigned int opt)
134 if(opt > COAP_OPTION_SIZE1) {
137 message->options[opt / COAP_OPTION_MAP_SIZE] |= 1 << (opt % COAP_OPTION_MAP_SIZE);
142 coap_is_option(
const coap_message_t *message,
unsigned int opt)
144 return (opt <= COAP_OPTION_SIZE1) &&
145 (message->options[opt / COAP_OPTION_MAP_SIZE] & (1 << (opt % COAP_OPTION_MAP_SIZE))) != 0;
149 #define COAP_SERIALIZE_INT_OPTION(number, field, text) \ 150 if(coap_is_option(coap_pkt, number)) { \ 151 LOG_DBG(text " [%u]\n", (unsigned int)coap_pkt->field); \ 152 option += coap_serialize_int_option(number, current_number, option, coap_pkt->field); \ 153 current_number = number; \ 155 #define COAP_SERIALIZE_BYTE_OPTION(number, field, text) \ 156 if(coap_is_option(coap_pkt, number)) { \ 157 LOG_DBG(text " %u [0x%02X%02X%02X%02X%02X%02X%02X%02X]\n", (unsigned int)coap_pkt->field##_len, \ 158 coap_pkt->field[0], \ 159 coap_pkt->field[1], \ 160 coap_pkt->field[2], \ 161 coap_pkt->field[3], \ 162 coap_pkt->field[4], \ 163 coap_pkt->field[5], \ 164 coap_pkt->field[6], \ 167 option += coap_serialize_array_option(number, current_number, option, coap_pkt->field, coap_pkt->field##_len, '\0'); \ 168 current_number = number; \ 170 #define COAP_SERIALIZE_STRING_OPTION(number, field, splitter, text) \ 171 if(coap_is_option(coap_pkt, number)) { \ 172 LOG_DBG(text " ["); \ 173 LOG_DBG_COAP_STRING(coap_pkt->field, coap_pkt->field##_len); \ 175 option += coap_serialize_array_option(number, current_number, option, (uint8_t *)coap_pkt->field, coap_pkt->field##_len, splitter); \ 176 current_number = number; \ 178 #define COAP_SERIALIZE_BLOCK_OPTION(number, field, text) \ 179 if(coap_is_option(coap_pkt, number)) { \ 180 LOG_DBG(text " [%lu%s (%u B/blk)]\n", (unsigned long)coap_pkt->field##_num, coap_pkt->field##_more ? "+" : "", coap_pkt->field##_size); \ 181 uint32_t block = coap_pkt->field##_num << 4; \ 182 if(coap_pkt->field##_more) { block |= 0x8; } \ 183 block |= 0xF & coap_log_2(coap_pkt->field##_size / 16); \ 184 LOG_DBG(text " encoded: 0x%lX\n", (unsigned long)block); \ 185 option += coap_serialize_int_option(number, current_number, option, block); \ 186 current_number = number; \ 190 extern coap_status_t coap_status_code;
191 extern const char *coap_error_message;
193 void coap_init_connection(
void);
194 uint16_t coap_get_mid(
void);
196 void coap_init_message(coap_message_t *message, coap_message_type_t type,
197 uint8_t code, uint16_t mid);
198 size_t coap_serialize_message(coap_message_t *message, uint8_t *buffer);
199 coap_status_t coap_parse_message(coap_message_t *request, uint8_t *data,
202 int coap_get_query_variable(coap_message_t *message,
const char *name,
204 int coap_get_post_variable(coap_message_t *message,
const char *name,
208 coap_get_method_type(coap_message_t *message)
213 static inline const coap_endpoint_t *
214 coap_get_src_endpoint(coap_message_t *request)
216 return request->src_ep;
220 coap_set_src_endpoint(coap_message_t *request,
const coap_endpoint_t *ep)
222 request->src_ep = ep;
226 int coap_set_status_code(coap_message_t *message,
unsigned int code);
228 int coap_set_token(coap_message_t *message,
const uint8_t *token,
231 int coap_get_header_content_format(coap_message_t *message,
unsigned int *format);
232 int coap_set_header_content_format(coap_message_t *message,
unsigned int format);
234 int coap_get_header_accept(coap_message_t *message,
unsigned int *
accept);
235 int coap_set_header_accept(coap_message_t *message,
unsigned int accept);
237 int coap_get_header_max_age(coap_message_t *message, uint32_t *age);
238 int coap_set_header_max_age(coap_message_t *message, uint32_t age);
240 int coap_get_header_etag(coap_message_t *message,
const uint8_t **etag);
241 int coap_set_header_etag(coap_message_t *message,
const uint8_t *etag,
244 int coap_get_header_if_match(coap_message_t *message,
const uint8_t **etag);
245 int coap_set_header_if_match(coap_message_t *message,
const uint8_t *etag,
248 int coap_get_header_if_none_match(coap_message_t *message);
249 int coap_set_header_if_none_match(coap_message_t *message);
252 int coap_get_header_proxy_uri(coap_message_t *message,
const char **uri);
253 int coap_set_header_proxy_uri(coap_message_t *message,
const char *uri);
256 int coap_get_header_proxy_scheme(coap_message_t *message,
const char **scheme);
257 int coap_set_header_proxy_scheme(coap_message_t *message,
const char *scheme);
260 int coap_get_header_uri_host(coap_message_t *message,
const char **host);
261 int coap_set_header_uri_host(coap_message_t *message,
const char *host);
264 int coap_get_header_uri_path(coap_message_t *message,
const char **path);
265 int coap_set_header_uri_path(coap_message_t *message,
const char *path);
268 int coap_get_header_uri_query(coap_message_t *message,
const char **query);
269 int coap_set_header_uri_query(coap_message_t *message,
const char *query);
272 int coap_get_header_location_path(coap_message_t *message,
const char **path);
274 int coap_set_header_location_path(coap_message_t *message,
const char *path);
277 int coap_get_header_location_query(coap_message_t *message,
const char **query);
278 int coap_set_header_location_query(coap_message_t *message,
const char *query);
280 int coap_get_header_observe(coap_message_t *message, uint32_t *observe);
281 int coap_set_header_observe(coap_message_t *message, uint32_t observe);
283 int coap_get_header_block2(coap_message_t *message, uint32_t *num, uint8_t *more,
284 uint16_t *size, uint32_t *offset);
285 int coap_set_header_block2(coap_message_t *message, uint32_t num, uint8_t more,
288 int coap_get_header_block1(coap_message_t *message, uint32_t *num, uint8_t *more,
289 uint16_t *size, uint32_t *offset);
290 int coap_set_header_block1(coap_message_t *message, uint32_t num, uint8_t more,
293 int coap_get_header_size2(coap_message_t *message, uint32_t *size);
294 int coap_set_header_size2(coap_message_t *message, uint32_t size);
296 int coap_get_header_size1(coap_message_t *message, uint32_t *size);
297 int coap_set_header_size1(coap_message_t *message, uint32_t size);
299 int coap_get_payload(coap_message_t *message,
const uint8_t **payload);
300 int coap_set_payload(coap_message_t *message,
const void *payload,
size_t length);
static uint8_t output(const linkaddr_t *localdest)
Take an IP packet and format it to be sent on an 802.15.4 network using 6lowpan.
static uint8_t accept(uint8_t in)
Processes an incoming or outgoing multicast message and determines whether it should be dropped or ac...
Collection of default configuration values.
coap_resource_flags_t
Resource flags for allowed methods and special functionalities.
Collection of constants specified in the CoAP standard.