Loading...
Searching...
No Matches
nanocoap.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2016-2018 Kaspar Schleiser <kaspar@schleiser.de>
3 * SPDX-FileCopyrightText: 2018 Freie Universität Berlin
4 * SPDX-FileCopyrightText: 2018 Inria
5 * SPDX-FileCopyrightText: 2018 Ken Bannister <kb2ma@runbox.com>
6 * SPDX-License-Identifier: LGPL-2.1-only
7 */
8
9#pragma once
10
75
76#include <assert.h>
77#include <stdint.h>
78#include <stdbool.h>
79#include <stddef.h>
80#include <string.h>
81#include <unistd.h>
82
83#include "bitarithm.h"
84#include "bitfield.h"
85#include "byteorder.h"
86#include "iolist.h"
87#include "macros/utils.h"
88#include "modules.h"
89#include "net/coap.h"
90#include "net/sock/udp.h"
91
92#if defined(MODULE_NANOCOAP_RESOURCES)
93#include "xfa.h"
94#endif
95
96#ifdef __cplusplus
97extern "C" {
98#endif
99
105#define COAP_GET (0x01)
106#define COAP_POST (0x02)
107#define COAP_PUT (0x04)
108#define COAP_DELETE (0x08)
109#define COAP_FETCH (0x10)
110#define COAP_PATCH (0x20)
111#define COAP_IPATCH (0x40)
112#define COAP_IGNORE (0xFF)
114#define COAP_MATCH_SUBTREE (0x8000)
117
121#define COAP_FORMAT_NONE (UINT16_MAX)
122
130#ifndef CONFIG_NANOCOAP_NOPTS_MAX
131# define CONFIG_NANOCOAP_NOPTS_MAX (16)
132#endif
133
138#ifndef CONFIG_NANOCOAP_URI_MAX
139# define CONFIG_NANOCOAP_URI_MAX (64)
140#endif
141
145#ifndef CONFIG_NANOCOAP_BLOCK_SIZE_MAX
146# define CONFIG_NANOCOAP_BLOCK_SIZE_MAX COAP_BLOCKSIZE_64
147#endif
148
152#ifndef CONFIG_NANOCOAP_BLOCKSIZE_DEFAULT
153# define CONFIG_NANOCOAP_BLOCKSIZE_DEFAULT COAP_BLOCKSIZE_64
154#endif
155
157#ifndef CONFIG_NANOCOAP_QS_MAX
158# define CONFIG_NANOCOAP_QS_MAX (64)
159#endif
161
167#ifndef CONFIG_NANOCOAP_BLOCK_HEADER_MAX
168# define CONFIG_NANOCOAP_BLOCK_HEADER_MAX (80)
169#endif
170
178#define COAP_OPT_FINISH_NONE (0x0000)
180#define COAP_OPT_FINISH_PAYLOAD (0x0001)
182
186typedef struct __attribute__((packed)) {
187 uint8_t ver_t_tkl;
188 uint8_t code;
189 uint16_t id;
191
199
203typedef struct {
204 uint16_t opt_num;
205 uint16_t offset;
207
226typedef struct {
227 union {
233 uint8_t *buf;
246 };
247 uint8_t *payload;
249 uint16_t payload_len;
250 uint16_t options_len;
253#ifdef MODULE_GCOAP
254 uint32_t observe_value;
255#endif
256} coap_pkt_t;
257
262
285typedef ssize_t (*coap_handler_t)(coap_pkt_t *pkt, uint8_t *buf, size_t len,
286 coap_request_ctx_t *context);
287
300typedef int (*coap_blockwise_cb_t)(void *arg, size_t offset, uint8_t *buf, size_t len, int more);
301
312typedef int (*coap_request_cb_t)(void *arg, coap_pkt_t *pkt);
313
319typedef uint16_t coap_method_flags_t;
320
330
334typedef const struct {
336 const size_t resources_numof;
338
346
353 union {
356 };
357#if defined(MODULE_SOCK_AUX_LOCAL) || DOXYGEN
358 union {
361 };
362#endif
363#if defined(MODULE_GCOAP) || DOXYGEN
370 uint32_t tl_type;
371#endif
372};
373
374/* forward declarations */
375static inline uint8_t *coap_hdr_data_ptr(const coap_udp_hdr_t *hdr);
376static inline size_t coap_hdr_get_token_len(const coap_udp_hdr_t *hdr);
377static inline const void *coap_hdr_get_token(const coap_udp_hdr_t *hdr);
378
387
396
406
416
426
451typedef struct {
452 uint8_t *buf;
453 uint16_t pos;
454 uint16_t size;
455 uint16_t last_opt_num;
457
461typedef struct {
462 size_t offset;
463 uint32_t blknum;
464 uint8_t szx;
465 int8_t more;
468
472typedef struct {
473 size_t start;
474 size_t end;
475 size_t cur;
476 uint8_t *opt_value;
478
479#if defined(MODULE_NANOCOAP_RESOURCES) || DOXYGEN
485#define NANOCOAP_RESOURCE(name) \
486 XFA_CONST(coap_resource_t, coap_resources_xfa, 0) CONCAT(coap_resource_, name) =
487#else
493extern const coap_resource_t coap_resources[];
494
500extern const unsigned coap_resources_numof;
501#endif
502
516{
517 /* currently only UDP as transport supported */
518 return (coap_udp_hdr_t *)pkt->buf;
519}
520
524static inline const coap_udp_hdr_t *coap_get_udp_hdr_const(const coap_pkt_t *pkt)
525{
526 /* currently only UDP as transport supported */
527 return (const coap_udp_hdr_t *)pkt->buf;
528}
529
538static inline uint8_t coap_code(unsigned cls, unsigned detail)
539{
540 return (cls << 5) | detail;
541}
542
550static inline unsigned coap_get_code_raw(const coap_pkt_t *pkt)
551{
552 return coap_get_udp_hdr_const(pkt)->code;
553}
554
562static inline unsigned coap_get_code_class(const coap_pkt_t *pkt)
563{
564 return coap_get_code_raw(pkt) >> 5;
565}
566
574static inline unsigned coap_get_code_detail(const coap_pkt_t *pkt)
575{
576 return coap_get_code_raw(pkt) & 0x1f;
577}
578
586static inline unsigned coap_get_code_decimal(const coap_pkt_t *pkt)
587{
588 return (coap_get_code_class(pkt) * 100) + coap_get_code_detail(pkt);
589}
590
598static inline coap_method_t coap_get_method(const coap_pkt_t *pkt)
599{
600 return coap_get_code_raw(pkt);
601}
602
610static inline unsigned coap_get_id(const coap_pkt_t *pkt)
611{
612 return ntohs(coap_get_udp_hdr_const(pkt)->id);
613}
614
621static inline void coap_set_id(coap_pkt_t *pkt, uint16_t id)
622{
623 coap_get_udp_hdr(pkt)->id = htons(id);
624}
625
633static inline unsigned coap_get_token_len(const coap_pkt_t *pkt)
634{
635 return coap_hdr_get_token_len((const coap_udp_hdr_t *)pkt->buf);
636}
637
645static inline void *coap_get_token(const coap_pkt_t *pkt)
646{
648}
649
659static inline unsigned coap_get_total_len(const coap_pkt_t *pkt)
660{
661 return (uintptr_t)pkt->payload - (uintptr_t)pkt->buf + pkt->payload_len;
662}
663
674static inline unsigned coap_get_type(const coap_pkt_t *pkt)
675{
676 return (coap_get_udp_hdr_const(pkt)->ver_t_tkl & 0x30) >> 4;
677}
678
686static inline unsigned coap_get_ver(const coap_pkt_t *pkt)
687{
688 return (coap_get_udp_hdr_const(pkt)->ver_t_tkl & 0x60) >> 6;
689}
690
711bool coap_is_hdr_in_bounds(const coap_pkt_t *pkt, size_t len);
712
722static inline uint8_t *coap_hdr_data_ptr(const coap_udp_hdr_t *hdr)
723{
724 return ((uint8_t *)hdr) + sizeof(coap_udp_hdr_t);
725}
726
734static inline unsigned coap_get_total_hdr_len(const coap_pkt_t *pkt)
735{
736 return sizeof(coap_udp_hdr_t) + coap_get_token_len(pkt);
737}
738
746static inline unsigned coap_get_response_hdr_len(const coap_pkt_t *pkt)
747{
748 return coap_get_total_hdr_len(pkt);
749}
750
759static inline void coap_hdr_set_code(coap_udp_hdr_t *hdr, uint8_t code)
760{
761 hdr->code = code;
762}
763
770static inline void coap_pkt_set_code(coap_pkt_t *pkt, uint8_t code)
771{
773}
774
785static inline void coap_hdr_set_type(coap_udp_hdr_t *hdr, unsigned type)
786{
787 /* assert correct range of type */
788 assert(!(type & ~0x3));
789
790 hdr->ver_t_tkl &= ~0x30;
791 hdr->ver_t_tkl |= type << 4;
792}
793
809static inline size_t coap_hdr_get_token_len(const coap_udp_hdr_t *hdr)
810{
811 return hdr->ver_t_tkl & 0x0f;
812}
813
829static inline const void * coap_hdr_get_token(const coap_udp_hdr_t *hdr)
830{
831 uint8_t *token = (void *)hdr;
832 /* token comes directly after the fixed size header for UDP */
833 token += sizeof(*hdr);
834 return token;
835}
836
851static inline size_t coap_hdr_len(const coap_udp_hdr_t *hdr)
852{
853 return sizeof(*hdr) + coap_hdr_get_token_len(hdr);
854}
855
864static inline void coap_pkt_set_type(coap_pkt_t *pkt, unsigned type)
865{
867
868 if (hdr) {
869 coap_hdr_set_type(hdr, type);
870 }
871}
872
883static inline void coap_pkt_set_tkl(coap_pkt_t *pkt, uint8_t tkl)
884{
885 coap_udp_hdr_t * hdr = coap_get_udp_hdr(pkt);
886 hdr->ver_t_tkl &= 0xf0;
887 hdr->ver_t_tkl |= (tkl & 0x0f);
888}
889
890
907
917uint8_t *coap_find_option(coap_pkt_t *pkt, unsigned opt_num);
918
931uint8_t *coap_iterate_option(coap_pkt_t *pkt, unsigned opt_num,
932 uint8_t **opt_pos, int *opt_len);
933
943
953
966int coap_opt_get_uint(coap_pkt_t *pkt, uint16_t optnum, uint32_t *value);
967
985ssize_t coap_opt_get_string(coap_pkt_t *pkt, uint16_t optnum,
986 char *target, size_t max_len, char separator);
987
1003static inline ssize_t coap_get_location_path(coap_pkt_t *pkt,
1004 char *target, size_t max_len)
1005{
1006 return coap_opt_get_string(pkt, COAP_OPT_LOCATION_PATH,
1007 target, max_len, '/');
1008}
1009
1025static inline ssize_t coap_get_location_query(coap_pkt_t *pkt,
1026 char *target, size_t max_len)
1027{
1028 return coap_opt_get_string(pkt, COAP_OPT_LOCATION_QUERY,
1029 target, max_len, '&');
1030}
1031
1046static inline ssize_t coap_get_uri_path(coap_pkt_t *pkt, char *target)
1047{
1048 return coap_opt_get_string(pkt, COAP_OPT_URI_PATH, target,
1050}
1051
1065static inline ssize_t coap_get_uri_query_string(coap_pkt_t *pkt, char *target,
1066 size_t max_len)
1067{
1068 return coap_opt_get_string(pkt, COAP_OPT_URI_QUERY,
1069 target, max_len, '&');
1070}
1071
1086bool coap_find_uri_query(coap_pkt_t *pkt, const char *key,
1087 const char **value, size_t *len);
1088
1111 char *key, size_t key_len_max,
1112 char *value, size_t value_len_max);
1113
1144 uint8_t **value, bool init_opt);
1145
1162ssize_t coap_opt_get_opaque(coap_pkt_t *pkt, unsigned opt_num, uint8_t **value);
1164
1177static inline ssize_t coap_get_proxy_uri(coap_pkt_t *pkt, char **target)
1178{
1179 return coap_opt_get_opaque(pkt, COAP_OPT_PROXY_URI, (uint8_t **)target);
1180}
1181
1199void coap_block_object_init(coap_block1_t *block, size_t blknum, size_t blksize,
1200 int more);
1201
1217
1232static inline bool coap_block1_finish(coap_block_slicer_t *slicer)
1233{
1234 return coap_block_finish(slicer);
1235}
1236
1251static inline bool coap_block2_finish(coap_block_slicer_t *slicer)
1252{
1253 return coap_block_finish(slicer);
1254}
1255
1270
1285 size_t blksize);
1286
1305 const void *c, size_t len);
1306
1325 const void *c, size_t len);
1326
1344
1362
1381int coap_get_block(coap_pkt_t *pkt, coap_block1_t *block, uint16_t option);
1382
1400static inline int coap_get_block1(coap_pkt_t *pkt, coap_block1_t *block)
1401{
1402 return coap_get_block(pkt, block, COAP_OPT_BLOCK1);
1403}
1404
1414static inline int coap_get_block2(coap_pkt_t *pkt, coap_block1_t *block)
1415{
1416 return coap_get_block(pkt, block, COAP_OPT_BLOCK2);
1417}
1418
1431int coap_get_blockopt(coap_pkt_t *pkt, uint16_t option, uint32_t *blknum, uint8_t *szx);
1432
1452
1484 bool more, uint16_t option);
1485
1504static inline ssize_t coap_opt_add_block1(coap_pkt_t *pkt,
1505 coap_block_slicer_t *slicer, bool more)
1506{
1507 return coap_opt_add_block(pkt, slicer, more, COAP_OPT_BLOCK1);
1508}
1509
1528static inline ssize_t coap_opt_add_block2(coap_pkt_t *pkt,
1529 coap_block_slicer_t *slicer, bool more)
1530{
1531 return coap_opt_add_block(pkt, slicer, more, COAP_OPT_BLOCK2);
1532}
1533
1547ssize_t coap_opt_add_uint(coap_pkt_t *pkt, uint16_t optnum, uint32_t value);
1548
1562static inline ssize_t coap_opt_add_block1_control(coap_pkt_t *pkt, coap_block1_t *block) {
1563 return coap_opt_add_uint(pkt, COAP_OPT_BLOCK1,
1564 (block->blknum << 4) | block->szx | (block->more ? 0x8 : 0));
1565}
1566
1580static inline ssize_t coap_opt_add_block2_control(coap_pkt_t *pkt, coap_block1_t *block) {
1581 /* block.more must be zero, so no need to 'or' it in */
1582 return coap_opt_add_uint(pkt, COAP_OPT_BLOCK2,
1583 (block->blknum << 4) | block->szx);
1584}
1585
1599static inline ssize_t coap_opt_add_accept(coap_pkt_t *pkt, uint16_t format)
1600{
1601 return coap_opt_add_uint(pkt, COAP_OPT_ACCEPT, format);
1602}
1603
1617static inline ssize_t coap_opt_add_format(coap_pkt_t *pkt, uint16_t format)
1618{
1619 return coap_opt_add_uint(pkt, COAP_OPT_CONTENT_FORMAT, format);
1620}
1621
1637ssize_t coap_opt_add_opaque(coap_pkt_t *pkt, uint16_t optnum, const void *val, size_t val_len);
1638
1656ssize_t coap_opt_add_uri_query2(coap_pkt_t *pkt, const char *key, size_t key_len,
1657 const char *val, size_t val_len);
1658
1675static inline ssize_t coap_opt_add_uri_query(coap_pkt_t *pkt, const char *key,
1676 const char *val)
1677{
1678 return coap_opt_add_uri_query2(pkt, key, strlen(key), val, val ? strlen(val) : 0);
1679}
1680
1695ssize_t coap_opt_add_proxy_uri(coap_pkt_t *pkt, const char *uri);
1696
1715ssize_t coap_opt_add_chars(coap_pkt_t *pkt, uint16_t optnum, const char *chars,
1716 size_t chars_len, char separator);
1717
1735static inline ssize_t coap_opt_add_string(coap_pkt_t *pkt, uint16_t optnum,
1736 const char *string, char separator)
1737{
1738 return coap_opt_add_chars(pkt, optnum, string, strlen(string), separator);
1739}
1740
1755static inline ssize_t coap_opt_add_uri_path(coap_pkt_t *pkt, const char *path)
1756{
1757 return coap_opt_add_string(pkt, COAP_OPT_URI_PATH, path, '/');
1758}
1759
1775static inline ssize_t coap_opt_add_uri_path_buffer(coap_pkt_t *pkt,
1776 const char *path,
1777 size_t path_len)
1778{
1779 return coap_opt_add_chars(pkt, COAP_OPT_URI_PATH, path, path_len, '/');
1780}
1781
1794ssize_t coap_opt_finish(coap_pkt_t *pkt, uint16_t flags);
1795
1813ssize_t coap_opt_remove(coap_pkt_t *pkt, uint16_t optnum);
1815
1849int coap_builder_init(coap_builder_t *state, void *buf, size_t buf_len,
1850 size_t header_len);
1851
1860static inline bool coap_builder_has_overflown(const coap_builder_t *state)
1861{
1862 return (state->size == 0);
1863}
1864
1875static inline ssize_t coap_builder_msg_size(const coap_builder_t *state)
1876{
1877 if (coap_builder_has_overflown(state)) {
1878 return -EOVERFLOW;
1879 }
1880
1881 return state->pos;
1882}
1883
1894static inline size_t coap_builder_buf_size(const coap_builder_t *state)
1895{
1896 return state->size;
1897}
1898
1906static inline size_t coap_builder_buf_remaining(const coap_builder_t *state)
1907{
1908 if (state->size > state->pos) {
1909 return state->size - state->pos;
1910 }
1911
1912 return 0;
1913}
1914
1938int coap_builder_init_reply(coap_builder_t *state, void *buf, size_t buf_len,
1939 coap_pkt_t *req, uint8_t code);
1940
1962int coap_builder_add_payload(coap_builder_t *state, const void *pld, size_t pld_len);
1963
1990void * coap_builder_allocate_payload(coap_builder_t *state, size_t pld_len);
1991
2006{
2007 return coap_builder_add_payload(state, NULL, 0);
2008}
2009
2029 uint16_t option);
2030
2047static inline int coap_opt_put_block1(coap_builder_t *state,
2048 coap_block_slicer_t *slicer)
2049{
2050 return coap_opt_put_block(state, slicer, COAP_OPT_BLOCK1);
2051}
2052
2069static inline int coap_opt_put_block2(coap_builder_t *state,
2070 coap_block_slicer_t *slicer)
2071{
2072 return coap_opt_put_block(state, slicer, COAP_OPT_BLOCK2);
2073}
2074
2093int coap_opt_put_uint(coap_builder_t *state, uint16_t onum, uint32_t value);
2094
2112 coap_block1_t *block)
2113{
2114 return coap_opt_put_uint(state, COAP_OPT_BLOCK1,
2115 (block->blknum << 4) | block->szx | (block->more ? 0x8 : 0));
2116}
2117
2137 coap_block1_t *block)
2138{
2139 /* block.more must be zero, so no need to 'or' it in */
2140 return coap_opt_put_uint(state, COAP_OPT_BLOCK2,
2141 (block->blknum << 4) | block->szx);
2142}
2143
2160static inline int coap_opt_put_observe(coap_builder_t *state, uint32_t obs)
2161{
2162 obs &= COAP_OBS_MAX_VALUE_MASK; /* trim obs down to 24 bit */
2163 return coap_opt_put_uint(state, COAP_OPT_OBSERVE, obs);
2164}
2165
2187 const char *string, size_t len, char separator);
2207static inline int coap_opt_put_string(coap_builder_t *state, uint16_t optnum,
2208 const char *string, char separator)
2209{
2210 return coap_opt_put_string_with_len(state, optnum,
2211 string, strlen(string), separator);
2212}
2213
2231 const char *location)
2232{
2233 return coap_opt_put_string(state, COAP_OPT_LOCATION_PATH,
2234 location, '/');
2235}
2236
2254 const char *location)
2255{
2256 return coap_opt_put_string(state, COAP_OPT_LOCATION_QUERY,
2257 location, '&');
2258}
2259
2276static inline int coap_opt_put_uri_path(coap_builder_t *state, const char *uri)
2277{
2278 return coap_opt_put_string(state, COAP_OPT_URI_PATH, uri, '/');
2279}
2280
2298 const char *uri_query)
2299{
2300 return coap_opt_put_string(state, COAP_OPT_URI_QUERY, uri_query, '&');
2301}
2302
2326int coap_opt_put_uri_pathquery(coap_builder_t *state, const char *uri);
2327
2344static inline int coap_opt_put_proxy_uri(coap_builder_t *state, const char *uri)
2345{
2346 return coap_opt_put_string(state, COAP_OPT_PROXY_URI, uri, '\0');
2347}
2348
2374
2399int coap_opt_put(coap_builder_t *state, uint16_t onum, const void *odata, size_t olen);
2400
2420 unsigned blknum, unsigned szx, int more)
2421{
2422 return coap_opt_put_uint(state, COAP_OPT_BLOCK1,
2423 (blknum << 4) | szx | (more ? 0x8 : 0));
2424}
2425
2442static inline int coap_opt_put_ct(coap_builder_t *state, uint16_t content_type)
2443{
2444 return coap_opt_put_uint(state, COAP_OPT_CONTENT_FORMAT, content_type);
2445}
2446
2447
2467ssize_t coap_build_udp_hdr(void *buf, size_t buf_len, uint8_t type, const void *token,
2468 size_t token_len, uint8_t code, uint16_t id);
2490static inline ssize_t coap_build_hdr(coap_udp_hdr_t *hdr, unsigned type, const void *token,
2491 size_t token_len, unsigned code, uint16_t id)
2492{
2493 size_t fingers_crossed_size = sizeof(*hdr) + token_len;
2494
2495 return coap_build_udp_hdr(hdr, fingers_crossed_size, type, token, token_len, code, id);
2496}
2497
2559ssize_t coap_build_reply(coap_pkt_t *pkt, unsigned code,
2560 uint8_t *rbuf, unsigned rlen, unsigned max_data_len);
2561
2577
2592ssize_t coap_handle_req(coap_pkt_t *pkt, uint8_t *resp_buf, unsigned resp_buf_len,
2593 coap_request_ctx_t *ctx);
2594
2611ssize_t coap_tree_handler(coap_pkt_t *pkt, uint8_t *resp_buf,
2612 unsigned resp_buf_len, coap_request_ctx_t *ctx,
2613 const coap_resource_t *resources,
2614 size_t resources_numof);
2615
2633ssize_t coap_subtree_handler(coap_pkt_t *pkt, uint8_t *resp_buf,
2634 size_t resp_buf_len, coap_request_ctx_t *context);
2635
2643static inline coap_method_flags_t coap_method2flag(unsigned code)
2644{
2645 return (1 << (code - 1));
2646}
2647
2663ssize_t coap_parse_udp(coap_pkt_t *pkt, uint8_t *buf, size_t len);
2664
2670static inline ssize_t coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
2671{
2672 return coap_parse_udp(pkt, buf, len);
2673}
2674
2689void coap_pkt_init(coap_pkt_t *pkt, uint8_t *buf, size_t len, size_t header_len);
2690
2704static inline void coap_payload_advance_bytes(coap_pkt_t *pkt, size_t len)
2705{
2706 pkt->payload += len;
2707 pkt->payload_len -= len;
2708}
2709
2731ssize_t coap_payload_put_bytes(coap_pkt_t *pkt, const void *data, size_t len);
2732
2746ssize_t coap_payload_put_char(coap_pkt_t *pkt, char c);
2747
2773ssize_t coap_build_reply_header(coap_pkt_t *pkt, unsigned code,
2774 void *buf, size_t len, uint16_t ct,
2775 void **payload, size_t *payload_len_max);
2776
2801 uint8_t code,
2802 uint8_t *buf, size_t len,
2803 uint16_t ct,
2804 const void *payload, size_t payload_len);
2805
2811 uint8_t *buf, size_t len,
2812 coap_request_ctx_t *context);
2814
2818#ifndef CONFIG_NANOCOAP_SERVER_WELL_KNOWN_CORE
2819#define CONFIG_NANOCOAP_SERVER_WELL_KNOWN_CORE !IS_USED(MODULE_GCOAP)
2820#endif
2821
2837int coap_match_path(const coap_resource_t *resource, const char *uri);
2838
2839#if defined(MODULE_GCOAP) || defined(DOXYGEN)
2852static inline bool coap_has_observe(coap_pkt_t *pkt)
2853{
2854 return pkt->observe_value != UINT32_MAX;
2855}
2856
2862static inline void coap_clear_observe(coap_pkt_t *pkt)
2863{
2864 pkt->observe_value = UINT32_MAX;
2865}
2866
2874static inline uint32_t coap_get_observe(coap_pkt_t *pkt)
2875{
2876 return pkt->observe_value;
2877}
2878
2879#endif
2880
2884#define COAP_WELL_KNOWN_CORE_DEFAULT_HANDLER \
2885 { \
2886 .path = "/.well-known/core", \
2887 .methods = COAP_GET, \
2888 .handler = coap_well_known_core_default_handler \
2889 }
2890
2891#ifdef __cplusplus
2892}
2893#endif
POSIX.1-2008 compliant version of the assert macro.
#define assert(cond)
abort the program if assertion is false
Definition assert.h:143
Helper functions for bit arithmetic.
Bitfield operations on bitfields of arbitrary length.
Functions to work with different byte orders.
static uint16_t ntohs(uint16_t v)
Convert from network byte order to host byte order, 16 bit.
Definition byteorder.h:532
static uint16_t htons(uint16_t v)
Convert from host byte order to network byte order, 16 bit.
Definition byteorder.h:517
#define WARN_UNUSED_RESULT
Attribute to add to a function whose return value should not silently be discarded.
Various helper macros.
#define EOVERFLOW
Value too large to be stored in data type.
Definition errno.h:133
#define COAP_OBS_MAX_VALUE_MASK
observe value is 24 bits
Definition coap.h:533
coap_method_t
CoAP method codes used in request.
Definition coap.h:171
#define CONFIG_NANOCOAP_NOPTS_MAX
Maximum number of Options in a message.
Definition nanocoap.h:131
#define CONFIG_NANOCOAP_URI_MAX
Maximum length of a resource path string read from or written to a message.
Definition nanocoap.h:139
uint32_t coap_request_ctx_get_tl_type(const coap_request_ctx_t *ctx)
Get transport the packet was received over.
uint8_t * coap_find_option(coap_pkt_t *pkt, unsigned opt_num)
Get pointer to an option field by type.
static ssize_t coap_opt_add_uri_query(coap_pkt_t *pkt, const char *key, const char *val)
Adds a single Uri-Query option in the form 'key=value' into pkt.
Definition nanocoap.h:1675
int coap_blockwise_put_char(coap_builder_t *state, coap_block_slicer_t *slicer, char c)
Add a single character to a block2 reply when building the response using a coap_builder_t structure ...
int coap_opt_put_block(coap_builder_t *state, coap_block_slicer_t *slicer, uint16_t option)
Insert block option into buffer.
ssize_t coap_opt_get_string(coap_pkt_t *pkt, uint16_t optnum, char *target, size_t max_len, char separator)
Read a full option as null terminated string into the target buffer.
int coap_match_path(const coap_resource_t *resource, const char *uri)
Checks if a CoAP resource path matches a given URI.
bool coap_is_hdr_in_bounds(const coap_pkt_t *pkt, size_t len)
Validate that the header of pkt is no longer than len bytes.
static void coap_pkt_set_code(coap_pkt_t *pkt, uint8_t code)
Write the given raw message code to given CoAP pkt.
Definition nanocoap.h:770
static ssize_t coap_build_hdr(coap_udp_hdr_t *hdr, unsigned type, const void *token, size_t token_len, unsigned code, uint16_t id)
Builds a CoAP header.
Definition nanocoap.h:2490
static ssize_t coap_opt_add_block2(coap_pkt_t *pkt, coap_block_slicer_t *slicer, bool more)
Add block2 option in descriptive use from a slicer object.
Definition nanocoap.h:1528
static unsigned coap_get_code_raw(const coap_pkt_t *pkt)
Get a message's raw code (class + detail)
Definition nanocoap.h:550
void coap_pkt_init(coap_pkt_t *pkt, uint8_t *buf, size_t len, size_t header_len)
Initialize a packet struct, to build a message buffer.
static ssize_t coap_opt_add_format(coap_pkt_t *pkt, uint16_t format)
Append a Content-Format option to the pkt buffer.
Definition nanocoap.h:1617
int coap_blockwise_put_char_pkt(coap_pkt_t *pdu, coap_block_slicer_t *slicer, char c)
Add a single character to a block2 reply when building the response using a coap_pkt_t structure to a...
static uint8_t coap_code(unsigned cls, unsigned detail)
Encode given code class and code detail to raw code.
Definition nanocoap.h:538
bool coap_has_unprocessed_critical_options(const coap_pkt_t *pkt)
Check whether any of the packet's options that are critical.
static ssize_t coap_opt_add_uri_path(coap_pkt_t *pkt, const char *path)
Adds one or multiple Uri-Path options in the form '/path' into pkt.
Definition nanocoap.h:1755
static ssize_t coap_get_uri_query_string(coap_pkt_t *pkt, char *target, size_t max_len)
Convenience function for getting the packet's URI_QUERY option.
Definition nanocoap.h:1065
static ssize_t coap_get_location_path(coap_pkt_t *pkt, char *target, size_t max_len)
Convenience function for getting the packet's LOCATION_PATH option.
Definition nanocoap.h:1003
static int coap_opt_put_block2(coap_builder_t *state, coap_block_slicer_t *slicer)
Insert block2 option into buffer.
Definition nanocoap.h:2069
ssize_t coap_handle_req(coap_pkt_t *pkt, uint8_t *resp_buf, unsigned resp_buf_len, coap_request_ctx_t *ctx)
Handle incoming CoAP request.
static size_t coap_builder_buf_size(const coap_builder_t *state)
Get the size of the buffer in state.
Definition nanocoap.h:1894
static unsigned coap_get_id(const coap_pkt_t *pkt)
Get the message ID of the given CoAP packet.
Definition nanocoap.h:610
bool coap_block_finish(coap_block_slicer_t *slicer)
Finish a block request (block1 or block2)
static int coap_opt_put_ct(coap_builder_t *state, uint16_t content_type)
Insert content type option into buffer.
Definition nanocoap.h:2442
static ssize_t coap_opt_add_accept(coap_pkt_t *pkt, uint16_t format)
Append an Accept option to the pkt buffer.
Definition nanocoap.h:1599
static int coap_opt_put_location_path(coap_builder_t *state, const char *location)
Convenience function for inserting LOCATION_PATH option into buffer.
Definition nanocoap.h:2230
int coap_builder_add_payload(coap_builder_t *state, const void *pld, size_t pld_len)
Add a payload marker and payload with bounds checking.
static int coap_opt_put_uri_path(coap_builder_t *state, const char *uri)
Convenience function for inserting URI_PATH option into buffer.
Definition nanocoap.h:2276
void * coap_builder_allocate_payload(coap_builder_t *state, size_t pld_len)
Write the payload marker into the current position of state and allocate pld_len bytes of payload aft...
void coap_request_ctx_init(coap_request_ctx_t *ctx, sock_udp_ep_t *remote)
Initialize CoAP request context.
ssize_t coap_payload_put_bytes(coap_pkt_t *pkt, const void *data, size_t len)
Add payload data to the CoAP request.
static int coap_opt_put_proxy_uri(coap_builder_t *state, const char *uri)
Convenience function for inserting PROXY_URI option into buffer.
Definition nanocoap.h:2344
static ssize_t coap_get_location_query(coap_pkt_t *pkt, char *target, size_t max_len)
Convenience function for getting the packet's LOCATION_QUERY option.
Definition nanocoap.h:1025
uint8_t * coap_iterate_option(coap_pkt_t *pkt, unsigned opt_num, uint8_t **opt_pos, int *opt_len)
Get pointer to an option field, can be called in a loop if there are multiple options with the same n...
int coap_opt_get_uint(coap_pkt_t *pkt, uint16_t optnum, uint32_t *value)
Get a uint32 option value.
unsigned coap_get_accept(coap_pkt_t *pkt)
Get the Accept option value from a packet if present.
static const void * coap_hdr_get_token(const coap_udp_hdr_t *hdr)
Get the Token of a CoAP over UDP (DTLS) packet.
Definition nanocoap.h:829
uint16_t coap_method_flags_t
Method flag type.
Definition nanocoap.h:319
ssize_t coap_build_udp_hdr(void *buf, size_t buf_len, uint8_t type, const void *token, size_t token_len, uint8_t code, uint16_t id)
Build a CoAP over UDP header.
static coap_udp_hdr_t * coap_get_udp_hdr(coap_pkt_t *pkt)
Get the CoAP header of a CoAP over UDP packet.
Definition nanocoap.h:515
int coap_get_block(coap_pkt_t *pkt, coap_block1_t *block, uint16_t option)
Block option getter.
static unsigned coap_get_ver(const coap_pkt_t *pkt)
Get the CoAP version number.
Definition nanocoap.h:686
ssize_t coap_opt_get_next(const coap_pkt_t *pkt, coap_optpos_t *opt, uint8_t **value, bool init_opt)
Iterate over a packet's options.
ssize_t coap_parse_udp(coap_pkt_t *pkt, uint8_t *buf, size_t len)
Parse a CoAP PDU in UDP / DTLS format.
static bool coap_block2_finish(coap_block_slicer_t *slicer)
Finish a block2 response.
Definition nanocoap.h:1251
int coap_opt_put_uint(coap_builder_t *state, uint16_t onum, uint32_t value)
Encode the given uint option into buffer.
static coap_method_t coap_get_method(const coap_pkt_t *pkt)
Get a request's method type.
Definition nanocoap.h:598
static unsigned coap_get_total_hdr_len(const coap_pkt_t *pkt)
Get the total header length (4-byte header + token length)
Definition nanocoap.h:734
ssize_t coap_subtree_handler(coap_pkt_t *pkt, uint8_t *resp_buf, size_t resp_buf_len, coap_request_ctx_t *context)
Generic coap subtree handler.
static void coap_pkt_set_type(coap_pkt_t *pkt, unsigned type)
Set the message type for the given CoAP packet.
Definition nanocoap.h:864
static unsigned coap_get_code_class(const coap_pkt_t *pkt)
Get a message's code class (3 most significant bits of code)
Definition nanocoap.h:562
static int coap_get_block2(coap_pkt_t *pkt, coap_block1_t *block)
Block2 option getter.
Definition nanocoap.h:1414
int coap_opt_put_uri_pathquery(coap_builder_t *state, const char *uri)
Convenience function for inserting URI_PATH and URI_QUERY into buffer This function will automaticall...
static size_t coap_hdr_get_token_len(const coap_udp_hdr_t *hdr)
Get the token length of a CoAP over UDP (DTLS) packet.
Definition nanocoap.h:809
static ssize_t coap_builder_msg_size(const coap_builder_t *state)
Get the size of the CoAP message in state.
Definition nanocoap.h:1875
int coap_blockwise_put_bytes(coap_builder_t *state, coap_block_slicer_t *slicer, const void *c, size_t len)
Add a byte array to a block2 reply when building the response using a coap_builder_t structure to ass...
int coap_blockwise_put_bytes_pkt(coap_pkt_t *pdu, coap_block_slicer_t *slicer, const void *c, size_t len)
Add a byte array to a block2 reply when building the response using a coap_pkt_t structure to assembl...
static ssize_t coap_opt_add_string(coap_pkt_t *pkt, uint16_t optnum, const char *string, char separator)
Encode the given string as option(s) into pkt.
Definition nanocoap.h:1735
ssize_t coap_build_empty_ack(const coap_pkt_t *pkt, coap_udp_hdr_t *ack)
Build empty reply to CoAP request.
WARN_UNUSED_RESULT int coap_block2_init(coap_pkt_t *pkt, coap_block_slicer_t *slicer)
Initialize a block2 slicer struct for writing the payload.
int coap_put_block1_ok(coap_builder_t *state, coap_block1_t *block1)
Insert block1 option into buffer (from coap_block1_t)
static unsigned coap_get_code_detail(const coap_pkt_t *pkt)
Get a message's code detail (5 least significant bits of code)
Definition nanocoap.h:574
static int coap_get_block1(coap_pkt_t *pkt, coap_block1_t *block)
Block1 option getter.
Definition nanocoap.h:1400
ssize_t(* coap_handler_t)(coap_pkt_t *pkt, uint8_t *buf, size_t len, coap_request_ctx_t *context)
Resource handler type.
Definition nanocoap.h:285
ssize_t coap_payload_put_char(coap_pkt_t *pkt, char c)
Add a single character to the payload data of the CoAP request.
ssize_t coap_well_known_core_default_handler(coap_pkt_t *pkt, uint8_t *buf, size_t len, coap_request_ctx_t *context)
Reference to the default .well-known/core handler defined by the application.
static void coap_payload_advance_bytes(coap_pkt_t *pkt, size_t len)
Advance the payload pointer.
Definition nanocoap.h:2704
bool coap_find_uri_query(coap_pkt_t *pkt, const char *key, const char **value, size_t *len)
Find a URI query option of the packet.
static uint32_t coap_get_observe(coap_pkt_t *pkt)
Get the value of the observe option from the given packet.
Definition nanocoap.h:2874
static ssize_t coap_opt_add_block2_control(coap_pkt_t *pkt, coap_block1_t *block)
Encode the given block2 option in control use.
Definition nanocoap.h:1580
static unsigned coap_get_type(const coap_pkt_t *pkt)
Get the message type.
Definition nanocoap.h:674
static int coap_opt_put_uri_query(coap_builder_t *state, const char *uri_query)
Convenience function for inserting URI_QUERY option into buffer.
Definition nanocoap.h:2297
static int coap_opt_put_string(coap_builder_t *state, uint16_t optnum, const char *string, char separator)
Encode the given string as multi-part option into buffer.
Definition nanocoap.h:2207
static unsigned coap_get_code_decimal(const coap_pkt_t *pkt)
Get a message's code in decimal format ((class * 100) + detail)
Definition nanocoap.h:586
static void coap_pkt_set_tkl(coap_pkt_t *pkt, uint8_t tkl)
Set the message token length for the given CoAP packet.
Definition nanocoap.h:883
static int coap_opt_put_block1(coap_builder_t *state, coap_block_slicer_t *slicer)
Insert block1 option into buffer.
Definition nanocoap.h:2047
static unsigned coap_get_response_hdr_len(const coap_pkt_t *pkt)
Get the header length a response to the given packet will have.
Definition nanocoap.h:746
ssize_t coap_opt_get_opaque(coap_pkt_t *pkt, unsigned opt_num, uint8_t **value)
Retrieve the value for an option as an opaque array of bytes.
static int coap_opt_put_block2_control(coap_builder_t *state, coap_block1_t *block)
Insert block2 option into buffer in control usage.
Definition nanocoap.h:2136
static int coap_opt_put_block1_control(coap_builder_t *state, coap_block1_t *block)
Insert block1 option into buffer in control usage.
Definition nanocoap.h:2111
int coap_iterate_uri_query(coap_pkt_t *pkt, void **ctx, char *key, size_t key_len_max, char *value, size_t value_len_max)
Iterate over a packet's URI Query options.
ssize_t coap_opt_add_opaque(coap_pkt_t *pkt, uint16_t optnum, const void *val, size_t val_len)
Encode the given buffer as an opaque data option into pkt.
static ssize_t coap_opt_add_uri_path_buffer(coap_pkt_t *pkt, const char *path, size_t path_len)
Adds one or multiple Uri-Path options in the form '/path' into pkt.
Definition nanocoap.h:1775
static void * coap_get_token(const coap_pkt_t *pkt)
Get pointer to a message's token.
Definition nanocoap.h:645
int coap_get_blockopt(coap_pkt_t *pkt, uint16_t option, uint32_t *blknum, uint8_t *szx)
Generic block option getter.
ssize_t coap_reply_simple(coap_pkt_t *pkt, uint8_t code, uint8_t *buf, size_t len, uint16_t ct, const void *payload, size_t payload_len)
Create CoAP reply (convenience function)
static const coap_udp_hdr_t * coap_get_udp_hdr_const(const coap_pkt_t *pkt)
Same as coap_get_udp_hdr but for const memory.
Definition nanocoap.h:524
static uint8_t * coap_hdr_data_ptr(const coap_udp_hdr_t *hdr)
Get the start of data after the header.
Definition nanocoap.h:722
static ssize_t coap_parse(coap_pkt_t *pkt, uint8_t *buf, size_t len)
Alias for coap_parse_udp.
Definition nanocoap.h:2670
static bool coap_block1_finish(coap_block_slicer_t *slicer)
Finish a block1 request.
Definition nanocoap.h:1232
static int coap_opt_put_observe(coap_builder_t *state, uint32_t obs)
Insert an CoAP Observe Option into the buffer.
Definition nanocoap.h:2160
void * coap_request_ctx_get_context(const coap_request_ctx_t *ctx)
Get resource context associated with a CoAP request.
ssize_t coap_build_reply_header(coap_pkt_t *pkt, unsigned code, void *buf, size_t len, uint16_t ct, void **payload, size_t *payload_len_max)
Create CoAP reply header (convenience function)
ssize_t coap_opt_add_proxy_uri(coap_pkt_t *pkt, const char *uri)
Adds a single Proxy-URI option into pkt.
static size_t coap_builder_buf_remaining(const coap_builder_t *state)
Get the remaining free buffer space in state.
Definition nanocoap.h:1906
int(* coap_blockwise_cb_t)(void *arg, size_t offset, uint8_t *buf, size_t len, int more)
Coap blockwise request callback descriptor.
Definition nanocoap.h:300
ssize_t coap_build_reply(coap_pkt_t *pkt, unsigned code, uint8_t *rbuf, unsigned rlen, unsigned max_data_len)
Build reply to CoAP request.
int(* coap_request_cb_t)(void *arg, coap_pkt_t *pkt)
Coap request callback descriptor.
Definition nanocoap.h:312
static int coap_opt_put_location_query(coap_builder_t *state, const char *location)
Convenience function for inserting LOCATION_QUERY option into buffer.
Definition nanocoap.h:2253
WARN_UNUSED_RESULT int coap_builder_init_reply(coap_builder_t *state, void *buf, size_t buf_len, coap_pkt_t *req, uint8_t code)
Initialize state for building a response and add the response header with matching token and suitable...
const char * coap_request_ctx_get_path(const coap_request_ctx_t *ctx)
Get resource path associated with a CoAP request.
ssize_t coap_opt_add_block(coap_pkt_t *pkt, coap_block_slicer_t *slicer, bool more, uint16_t option)
Add block option in descriptive use from a slicer object.
static ssize_t coap_get_uri_path(coap_pkt_t *pkt, char *target)
Convenience function for getting the packet's URI_PATH.
Definition nanocoap.h:1046
const sock_udp_ep_t * coap_request_ctx_get_remote_udp(const coap_request_ctx_t *ctx)
Get the remote endpoint from which the request was received.
static void coap_hdr_set_type(coap_udp_hdr_t *hdr, unsigned type)
Set the message type for the given CoAP header.
Definition nanocoap.h:785
static bool coap_builder_has_overflown(const coap_builder_t *state)
Check if building the message failed due to insufficient buffer space.
Definition nanocoap.h:1860
const sock_udp_ep_t * coap_request_ctx_get_local_udp(const coap_request_ctx_t *ctx)
Get the local endpoint on which the request has been received.
WARN_UNUSED_RESULT int coap_block_slicer_init(coap_block_slicer_t *slicer, size_t blknum, size_t blksize)
Initialize a block slicer struct from content information.
void coap_block_object_init(coap_block1_t *block, size_t blknum, size_t blksize, int more)
Initialize a block struct from content information.
ssize_t coap_opt_add_chars(coap_pkt_t *pkt, uint16_t optnum, const char *chars, size_t chars_len, char separator)
Encode the given array of characters as option(s) into pkt.
static void coap_hdr_set_code(coap_udp_hdr_t *hdr, uint8_t code)
Write the given raw message code to given CoAP header.
Definition nanocoap.h:759
ssize_t coap_opt_remove(coap_pkt_t *pkt, uint16_t optnum)
Removes an option previously added with function in the coap_opt_add_...() group.
unsigned coap_get_content_type(coap_pkt_t *pkt)
Get content type from packet.
static ssize_t coap_get_proxy_uri(coap_pkt_t *pkt, char **target)
Convenience function for getting the packet's Proxy-Uri option.
Definition nanocoap.h:1177
static size_t coap_hdr_len(const coap_udp_hdr_t *hdr)
Get the header length of a CoAP packet.
Definition nanocoap.h:851
static int coap_builder_add_payload_marker(coap_builder_t *state)
Add a payload marker with bounds checking.
Definition nanocoap.h:2005
ssize_t coap_opt_add_uint(coap_pkt_t *pkt, uint16_t optnum, uint32_t value)
Encode the given uint option into pkt.
static unsigned coap_get_total_len(const coap_pkt_t *pkt)
Get the total length of a CoAP packet in the packet buffer.
Definition nanocoap.h:659
int coap_opt_put_string_with_len(coap_builder_t *state, uint16_t optnum, const char *string, size_t len, char separator)
Encode the given string as multi-part option into buffer.
struct _coap_request_ctx coap_request_ctx_t
Forward declaration of internal CoAP resource request handler context.
Definition nanocoap.h:261
static bool coap_has_observe(coap_pkt_t *pkt)
Identifies a packet containing an observe option.
Definition nanocoap.h:2852
int coap_opt_put(coap_builder_t *state, uint16_t onum, const void *odata, size_t olen)
Insert a CoAP option into buffer.
static ssize_t coap_opt_add_block1(coap_pkt_t *pkt, coap_block_slicer_t *slicer, bool more)
Add block1 option in descriptive use from a slicer object.
Definition nanocoap.h:1504
static coap_method_flags_t coap_method2flag(unsigned code)
Convert message code (request method) into a corresponding bit field.
Definition nanocoap.h:2643
static ssize_t coap_opt_add_block1_control(coap_pkt_t *pkt, coap_block1_t *block)
Encode the given block1 option in control use.
Definition nanocoap.h:1562
ssize_t coap_tree_handler(coap_pkt_t *pkt, uint8_t *resp_buf, unsigned resp_buf_len, coap_request_ctx_t *ctx, const coap_resource_t *resources, size_t resources_numof)
Pass a coap request to a matching handler.
static void coap_set_id(coap_pkt_t *pkt, uint16_t id)
Set the message ID of the given CoAP packet.
Definition nanocoap.h:621
static unsigned coap_get_token_len(const coap_pkt_t *pkt)
Get a message's token length [in byte].
Definition nanocoap.h:633
static void coap_clear_observe(coap_pkt_t *pkt)
Clears the observe option value from a packet.
Definition nanocoap.h:2862
ssize_t coap_opt_finish(coap_pkt_t *pkt, uint16_t flags)
Finalizes options as required and prepares for payload.
coap_udp_hdr_t coap_hdr_t
Alias for coap_udp_hdr_t for backward compatibility.
Definition nanocoap.h:198
int coap_builder_init(coap_builder_t *state, void *buf, size_t buf_len, size_t header_len)
Initialize state for building a message.
ssize_t coap_opt_add_uri_query2(coap_pkt_t *pkt, const char *key, size_t key_len, const char *val, size_t val_len)
Adds a single Uri-Query option in the form 'key=value' into pkt.
static int coap_opt_put_block1_raw(coap_builder_t *state, unsigned blknum, unsigned szx, int more)
Insert block1 option into buffer.
Definition nanocoap.h:2419
struct _sock_tl_ep sock_udp_ep_t
An end point for a UDP sock object.
Definition udp.h:292
struct iolist iolist_t
iolist forward declaration
Definition iolist.h:30
iolist scatter / gather IO
Common macros and compiler attributes/pragmas configuration.
Generic CoAP values as defined by RFC7252.
UDP sock definitions.
CoAP resource request handler context.
Definition nanocoap.h:351
sock_udp_ep_t * local
deprecated alias for local_udp
Definition nanocoap.h:360
const coap_resource_t * resource
resource of the request
Definition nanocoap.h:352
sock_udp_ep_t * local_udp
local UDP endpoint of the request
Definition nanocoap.h:359
sock_udp_ep_t * remote
deprecated alias for request_udp
Definition nanocoap.h:355
uint32_t tl_type
transport the packet was received over
Definition nanocoap.h:370
sock_udp_ep_t * remote_udp
remote UDP endpoint of the request
Definition nanocoap.h:354
Block1 helper struct.
Definition nanocoap.h:461
int8_t more
-1 for no option, 0 for last block, 1 for more blocks coming
Definition nanocoap.h:465
uint32_t blknum
block number
Definition nanocoap.h:463
size_t offset
offset of received data
Definition nanocoap.h:462
uint8_t szx
szx value
Definition nanocoap.h:464
Blockwise transfer helper struct.
Definition nanocoap.h:472
size_t end
End offset of the current block.
Definition nanocoap.h:474
size_t start
Start offset of the current block.
Definition nanocoap.h:473
uint8_t * opt_value
Pointer to the value of the placed option.
Definition nanocoap.h:476
size_t cur
Offset of the generated content.
Definition nanocoap.h:475
Structure to hold the state for building a CoAP message.
Definition nanocoap.h:451
uint16_t last_opt_num
Number of the last option added (for delta-encoding)
Definition nanocoap.h:455
uint16_t pos
Position of the next byte to write within buf
Definition nanocoap.h:453
uint16_t size
Size of buf in bytes.
Definition nanocoap.h:454
uint8_t * buf
Buffer to build the message into.
Definition nanocoap.h:452
CoAP option array entry.
Definition nanocoap.h:203
uint16_t offset
offset in packet
Definition nanocoap.h:205
uint16_t opt_num
full CoAP option number
Definition nanocoap.h:204
CoAP PDU parsing context structure.
Definition nanocoap.h:226
coap_optpos_t options[CONFIG_NANOCOAP_NOPTS_MAX]
option offset array
Definition nanocoap.h:251
coap_udp_hdr_t * hdr
Deprecated alias for coap_pkt_t::buf.
Definition nanocoap.h:245
uint8_t * payload
pointer to end of the header
Definition nanocoap.h:247
uint16_t payload_len
length of payload
Definition nanocoap.h:249
uint16_t options_len
length of options array
Definition nanocoap.h:250
uint8_t * buf
pointer to the beginning of the buffer holding the pkt
Definition nanocoap.h:233
BITFIELD(opt_crit, CONFIG_NANOCOAP_NOPTS_MAX)
unhandled critical option
iolist_t * snips
payload snips (optional)
Definition nanocoap.h:248
Type for CoAP resource subtrees.
Definition nanocoap.h:334
const size_t resources_numof
number of entries in array
Definition nanocoap.h:336
const coap_resource_t * resources
ptr to resource array
Definition nanocoap.h:335
Type for CoAP resource entry.
Definition nanocoap.h:324
const char * path
URI path of resource.
Definition nanocoap.h:325
coap_method_flags_t methods
OR'ed methods this resource allows.
Definition nanocoap.h:326
coap_handler_t handler
ptr to resource handler
Definition nanocoap.h:327
void * context
ptr to user defined context data
Definition nanocoap.h:328
Raw CoAP over UDP PDU header structure.
Definition nanocoap.h:186
uint8_t code
CoAP code (e.g.m 205)
Definition nanocoap.h:188
uint8_t ver_t_tkl
version, token, token length
Definition nanocoap.h:187
uint16_t id
Req/resp ID.
Definition nanocoap.h:189
Cross File Arrays.