Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
coap.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Intel Corporation
3 * Copyright (c) 2021 Nordic Semiconductor
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
13
14#ifndef ZEPHYR_INCLUDE_NET_COAP_H_
15#define ZEPHYR_INCLUDE_NET_COAP_H_
16
25
26#include <zephyr/types.h>
27#include <stddef.h>
28#include <stdbool.h>
29#include <zephyr/net/net_ip.h>
31#include <zephyr/sys/slist.h>
32
33#if defined(CONFIG_COAP_OSCORE)
34struct coap_oscore_context;
35#endif /* defined(CONFIG_COAP_OSCORE) */
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
80
95
97
98#define COAP_REQUEST_MASK 0x07
99
100#define COAP_VERSION_1 1U
101
102#define COAP_OBSERVE_MAX_AGE 0xFFFFFF
103
105
138
145#define COAP_MAKE_RESPONSE_CODE(class, det) ((class << 5) | (det))
146
219};
220
222
223#define COAP_CODE_EMPTY (0)
224
225#define COAP_TOKEN_MAX_LEN 8UL
226#define COAP_FIXED_HEADER_SIZE 4UL
227
228/* CoAP TCP header constants (RFC 8323) */
229/* Len/TKL + Code */
230#define COAP_TCP_BASIC_HEADER_SIZE (2)
231/* Extended length field values */
232#define COAP_TCP_HEADER_LEN_EXT_1B (13)
233#define COAP_TCP_HEADER_LEN_EXT_2B (14)
234#define COAP_TCP_HEADER_LEN_EXT_4B (15)
235/* Extended length offset values */
236#define COAP_TCP_HEADER_LEN_EXT_0B_MAX (13)
237#define COAP_TCP_HEADER_LEN_EXT_1B_MAX (269)
238#define COAP_TCP_HEADER_LEN_EXT_2B_MAX (65805)
239
241
258
274
276
277/* block option helper */
278#define GET_BLOCK_NUM(v) ((v) >> 4)
279#define GET_BLOCK_SIZE(v) (((v) & 0x7))
280#define GET_MORE(v) (!!((v) & 0x08))
281
283
284struct coap_observer;
285struct coap_packet;
286struct coap_pending;
287struct coap_reply;
288struct coap_resource;
289
295typedef int (*coap_method_t)(struct coap_resource *resource,
296 struct coap_packet *request,
297 struct net_sockaddr *addr, net_socklen_t addr_len);
298
304typedef void (*coap_notify_t)(struct coap_resource *resource,
305 struct coap_observer *observer);
306
329
337 struct net_sockaddr_storage addr;
342#if defined(CONFIG_COAP_OSCORE) || defined(__DOXYGEN__)
347 struct coap_oscore_context *oscore_ctx;
348#endif
349};
350
361#if defined(CONFIG_COAP_KEEP_USER_DATA) || defined(__DOXYGEN__)
367#endif
368#if defined(CONFIG_COAP_OSCORE) || defined(__DOXYGEN__)
373 struct coap_oscore_context *oscore_ctx;
374#endif
375};
376
382#if defined(CONFIG_COAP_EXTENDED_OPTIONS_LEN)
384 uint8_t value[CONFIG_COAP_EXTENDED_OPTIONS_LEN_VALUE];
385#else
388#endif
389};
390
399typedef int (*coap_reply_t)(const struct coap_packet *response,
400 struct coap_reply *reply,
401 const struct net_sockaddr *from);
402
409#if defined(CONFIG_COAP_RANDOMIZE_ACK_TIMEOUT) || defined(__DOXYGEN__)
415#endif /* defined(CONFIG_COAP_RANDOMIZE_ACK_TIMEOUT) */
420};
421
441
460
469
478
489
498
506int coap_header_set_code(const struct coap_packet *cpkt, uint8_t code);
507
516
527 uint16_t *len);
528
539bool coap_uri_path_match(const char * const *path,
540 struct coap_option *options,
541 uint8_t opt_num);
542
559int coap_packet_parse(struct coap_packet *cpkt, uint8_t *data, uint16_t len,
560 struct coap_option *options, uint8_t opt_num);
561
571int coap_packet_set_path(struct coap_packet *cpkt, const char *path);
572
588int coap_packet_init(struct coap_packet *cpkt, uint8_t *data, uint16_t max_len,
589 uint8_t ver, uint8_t type, uint8_t token_len,
590 const uint8_t *token, uint8_t code, uint16_t id);
591
607int coap_ack_init(struct coap_packet *cpkt, const struct coap_packet *req,
608 uint8_t *data, uint16_t max_len, uint8_t code);
609
623int coap_rst_init(struct coap_packet *cpkt, const struct coap_packet *req,
624 uint8_t *data, uint16_t max_len);
632
639
653int coap_find_options(const struct coap_packet *cpkt, uint16_t code,
654 struct coap_option *options, uint16_t veclen);
655
671 const uint8_t *value, uint16_t len);
672
682
694unsigned int coap_option_value_to_int(const struct coap_option *option);
695
709 unsigned int val);
710
719
729int coap_packet_append_payload(struct coap_packet *cpkt, const uint8_t *payload,
730 uint16_t payload_len);
731
740bool coap_packet_is_request(const struct coap_packet *cpkt);
741
760 struct coap_resource *resources,
761 size_t resources_len,
762 struct coap_option *options,
763 uint8_t opt_num,
764 struct net_sockaddr *addr, net_socklen_t addr_len);
765
783 struct coap_resource *resources,
784 struct coap_option *options,
785 uint8_t opt_num,
786 struct net_sockaddr *addr, net_socklen_t addr_len);
787
806
816 enum coap_block_size block_size)
817{
818 /* BERT (SZX=7) acts like 1024 bytes for size calculations per RFC 8323 */
819 if (block_size == COAP_BLOCK_BERT) {
820 return 1024;
821 }
822
823 return (1 << (block_size + 4));
824}
825
835{
836 int sz = u32_count_trailing_zeros(bytes) - 4;
837
838 if (sz < COAP_BLOCK_16) {
839 return COAP_BLOCK_16;
840 }
841 if (sz > COAP_BLOCK_1024) {
842#if defined(CONFIG_COAP_OVER_RELIABLE_TRANSPORT)
843 return COAP_BLOCK_BERT;
844#else
845 return COAP_BLOCK_1024;
846#endif /* defined(CONFIG_COAP_OVER_RELIABLE_TRANSPORT) */
847 }
848 return (enum coap_block_size)sz;
849}
850
862
873 enum coap_block_size block_size,
874 size_t total_size);
875
889
902
914
923
934 struct coap_block_context *ctx);
935
946 struct coap_block_context *ctx);
947
958 struct coap_block_context *ctx);
959
970 struct coap_block_context *ctx);
971
981int coap_get_option_int(const struct coap_packet *cpkt, uint16_t code);
982
994int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint32_t *block_number);
995
1008int coap_get_block2_option(const struct coap_packet *cpkt, bool *has_more,
1009 uint32_t *block_number);
1010
1021 struct coap_block_context *ctx);
1022
1036 struct coap_block_context *ctx,
1037 enum coap_option_num option);
1038
1050size_t coap_next_block(const struct coap_packet *cpkt,
1051 struct coap_block_context *ctx);
1052
1061void coap_observer_init(struct coap_observer *observer,
1062 const struct coap_packet *request,
1063 const struct net_sockaddr *addr);
1064
1065#if defined(CONFIG_COAP_OSCORE) || defined(__DOXYGEN__)
1078void coap_observer_init_oscore(struct coap_observer *observer, const struct coap_packet *request,
1079 const struct net_sockaddr *addr,
1080 struct coap_oscore_context *oscore_ctx);
1081#endif /* CONFIG_COAP_OSCORE */
1082
1093 struct coap_observer *observer);
1094
1105 struct coap_observer *observer);
1106
1121 struct coap_observer *observers, size_t len,
1122 const struct net_sockaddr *addr,
1123 const uint8_t *token, uint8_t token_len);
1124
1139 struct coap_observer *observers, size_t len,
1140 const struct net_sockaddr *addr);
1141
1157 struct coap_observer *observers, size_t len,
1158 const uint8_t *token, uint8_t token_len);
1159
1170 struct coap_observer *observers, size_t len);
1171
1178void coap_reply_init(struct coap_reply *reply,
1179 const struct coap_packet *request);
1180
1198 const struct coap_packet *request,
1199 const struct net_sockaddr *addr,
1200 const struct coap_transmission_parameters *params);
1201
1213 struct coap_pending *pendings, size_t len);
1214
1226 struct coap_reply *replies, size_t len);
1227
1242 const struct coap_packet *response,
1243 struct coap_pending *pendings, size_t len);
1244
1258 const struct coap_packet *response,
1259 const struct net_sockaddr *from,
1260 struct coap_reply *replies, size_t len);
1261
1273 struct coap_pending *pendings, size_t len);
1274
1283bool coap_pending_cycle(struct coap_pending *pending);
1284
1291void coap_pending_clear(struct coap_pending *pending);
1292
1300void coap_pendings_clear(struct coap_pending *pendings, size_t len);
1301
1309size_t coap_pendings_count(struct coap_pending *pendings, size_t len);
1310
1317void coap_reply_clear(struct coap_reply *reply);
1318
1325void coap_replies_clear(struct coap_reply *replies, size_t len);
1326
1336
1345bool coap_request_is_observe(const struct coap_packet *request);
1346
1353
1360
1379
1390 uint8_t *token);
1391
1400
1411 uint32_t *len);
1412
1430 struct coap_option *options, uint8_t opt_num);
1431
1445 uint16_t max_len, uint8_t token_len,
1446 const uint8_t *token, uint8_t code);
1447
1456
1467 struct coap_block_context *ctx);
1468
1479 struct coap_block_context *ctx);
1480
1492size_t coap_tcp_next_block(const struct coap_packet *cpkt,
1493 struct coap_block_context *ctx);
1494
1495#ifdef __cplusplus
1496}
1497#endif
1498
1502
1503#endif /* ZEPHYR_INCLUDE_NET_COAP_H_ */
int(* coap_method_t)(struct coap_resource *resource, struct coap_packet *request, struct net_sockaddr *addr, net_socklen_t addr_len)
Type of the callback being called when a resource's method is invoked by the remote entity.
Definition coap.h:295
void coap_pending_clear(struct coap_pending *pending)
Cancels the pending retransmission, so it again becomes available.
int coap_pending_init(struct coap_pending *pending, const struct coap_packet *request, const struct net_sockaddr *addr, const struct coap_transmission_parameters *params)
Initialize a pending request with a request.
int coap_get_block1_option(const struct coap_packet *cpkt, bool *has_more, uint32_t *block_number)
Get the block size, more flag and block number from the CoAP block1 option.
size_t coap_next_block(const struct coap_packet *cpkt, struct coap_block_context *ctx)
Updates ctx so after this is called the current entry indicates the correct offset in the body of dat...
int coap_get_block2_option(const struct coap_packet *cpkt, bool *has_more, uint32_t *block_number)
Get values from CoAP block2 option.
const uint8_t * coap_tcp_packet_get_payload(const struct coap_packet *cpkt, uint32_t *len)
Returns the data pointer and length of the CoAP TCP packet.
struct coap_transmission_parameters coap_get_transmission_parameters(void)
Get currently active CoAP transmission parameters.
coap_response_code
Set of response codes available for a response packet.
Definition coap.h:154
int coap_get_option_int(const struct coap_packet *cpkt, uint16_t code)
Get the integer representation of a CoAP option.
int coap_packet_append_payload_marker(struct coap_packet *cpkt)
Append payload marker to CoAP packet.
struct coap_observer * coap_observer_next_unused(struct coap_observer *observers, size_t len)
Returns the next available observer representation.
void coap_observer_init(struct coap_observer *observer, const struct coap_packet *request, const struct net_sockaddr *addr)
Indicates that the remote device referenced by addr, with request, wants to observe a resource.
int coap_packet_parse(struct coap_packet *cpkt, uint8_t *data, uint16_t len, struct coap_option *options, uint8_t opt_num)
Parses the CoAP packet in data, validating it and initializing cpkt.
static enum coap_block_size coap_bytes_to_block_size(uint16_t bytes)
Helper for converting block size in bytes to enumeration.
Definition coap.h:834
const uint8_t * coap_packet_get_payload(const struct coap_packet *cpkt, uint16_t *len)
Returns the data pointer and length of the CoAP packet.
coap_no_response
Set of No-Response option values for CoAP.
Definition coap.h:265
int coap_packet_append_option(struct coap_packet *cpkt, uint16_t code, const uint8_t *value, uint16_t len)
Appends an option to the packet.
bool coap_pending_cycle(struct coap_pending *pending)
After a request is sent, user may want to cycle the pending retransmission so the timeout is updated.
unsigned int coap_option_value_to_int(const struct coap_option *option)
Converts an option to its integer representation.
bool coap_packet_is_request(const struct coap_packet *cpkt)
Check if a CoAP packet is a CoAP request.
bool coap_remove_observer(struct coap_resource *resource, struct coap_observer *observer)
Remove this observer from the list of registered observers of that resource.
int coap_tcp_update_from_block(const struct coap_packet *cpkt, struct coap_block_context *ctx)
Retrieves BLOCK{1,2} and SIZE{1,2} from cpkt and updates ctx accordingly.
void coap_observer_init_oscore(struct coap_observer *observer, const struct coap_packet *request, const struct net_sockaddr *addr, struct coap_oscore_context *oscore_ctx)
Indicates that the remote device referenced by addr, with request, wants to observe a resource.
int coap_append_block2_option(struct coap_packet *cpkt, struct coap_block_context *ctx)
Append BLOCK2 option to the packet.
void coap_reply_clear(struct coap_reply *reply)
Cancels awaiting for this reply, so it becomes available again.
int coap_update_from_block(const struct coap_packet *cpkt, struct coap_block_context *ctx)
Retrieves BLOCK{1,2} and SIZE{1,2} from cpkt and updates ctx accordingly.
coap_msgtype
CoAP packets may be of one of these types.
Definition coap.h:109
bool coap_register_observer(struct coap_resource *resource, struct coap_observer *observer)
After the observer is initialized, associate the observer with an resource.
int coap_append_size1_option(struct coap_packet *cpkt, struct coap_block_context *ctx)
Append SIZE1 option to the packet.
void(* coap_notify_t)(struct coap_resource *resource, struct coap_observer *observer)
Type of the callback being called when a resource's has observers to be informed when an update happe...
Definition coap.h:304
struct coap_reply * coap_response_received(const struct coap_packet *response, const struct net_sockaddr *from, struct coap_reply *replies, size_t len)
After a response is received, call coap_reply_t handler registered in coap_reply structure.
bool coap_request_is_observe(const struct coap_packet *request)
Returns if this request is enabling observing a resource.
int coap_next_block_for_option(const struct coap_packet *cpkt, struct coap_block_context *ctx, enum coap_option_num option)
Updates ctx according to option set in cpkt so after this is called the current entry indicates the c...
int coap_append_block1_option(struct coap_packet *cpkt, struct coap_block_context *ctx)
Append BLOCK1 option to the packet.
int coap_block_transfer_init(struct coap_block_context *ctx, enum coap_block_size block_size, size_t total_size)
Initializes the context of a block-wise transfer.
int coap_check_unsupported_critical_options(const struct coap_packet *cpkt, uint16_t *opt)
Check if a CoAP packet contains unsupported critical options.
int coap_tcp_packet_init(struct coap_packet *cpkt, uint8_t *data, uint16_t max_len, uint8_t token_len, const uint8_t *token, uint8_t code)
Creates a new CoAP TCP Packet from input data.
uint16_t coap_header_get_id(const struct coap_packet *cpkt)
Returns the message id associated with the CoAP packet.
struct coap_observer * coap_find_observer_by_addr(struct coap_observer *observers, size_t len, const struct net_sockaddr *addr)
Returns the observer that matches address addr.
struct coap_reply * coap_reply_next_unused(struct coap_reply *replies, size_t len)
Returns the next available reply struct, so it can be used to track replies and notifications receive...
uint8_t * coap_next_token(void)
Returns a randomly generated array of 8 bytes, that can be used as a message's token.
uint8_t coap_header_get_token(const struct coap_packet *cpkt, uint8_t *token)
Returns the token (if any) in the CoAP packet.
coap_method
Available request methods.
Definition coap.h:86
int coap_append_option_int(struct coap_packet *cpkt, uint16_t code, unsigned int val)
Appends an integer value option to the packet.
void coap_pendings_clear(struct coap_pending *pendings, size_t len)
Cancels all pending retransmissions, so they become available again.
coap_block_size
Represents the size of each block that will be transferred using block-wise transfers [RFC7959]:
Definition coap.h:796
coap_option_num
Set of CoAP packet options we are aware of.
Definition coap.h:50
struct coap_pending * coap_pending_next_unused(struct coap_pending *pendings, size_t len)
Returns the next available pending struct, that can be used to track the retransmission status of a r...
int(* coap_reply_t)(const struct coap_packet *response, struct coap_reply *reply, const struct net_sockaddr *from)
Helper function to be called when a response matches the a pending request.
Definition coap.h:399
int coap_append_descriptive_block_option(struct coap_packet *cpkt, struct coap_block_context *ctx)
Append BLOCK1 or BLOCK2 option to the packet.
bool coap_uri_path_match(const char *const *path, struct coap_option *options, uint8_t opt_num)
Verify if CoAP URI path matches with provided options.
int coap_packet_init(struct coap_packet *cpkt, uint8_t *data, uint16_t max_len, uint8_t ver, uint8_t type, uint8_t token_len, const uint8_t *token, uint8_t code, uint16_t id)
Creates a new CoAP Packet from input data.
int coap_remove_descriptive_block_option(struct coap_packet *cpkt)
Remove BLOCK1 or BLOCK2 option from the packet.
coap_content_format
Set of Content-Format option values for CoAP.
Definition coap.h:247
struct coap_pending * coap_pending_received(const struct coap_packet *response, struct coap_pending *pendings, size_t len)
After a response is received, returns if there is any matching pending request exits.
int coap_rst_init(struct coap_packet *cpkt, const struct coap_packet *req, uint8_t *data, uint16_t max_len)
Create a new CoAP Reset message for given request.
size_t coap_tcp_next_block(const struct coap_packet *cpkt, struct coap_block_context *ctx)
Updates ctx so after this is called the current entry indicates the correct offset in the body of dat...
struct coap_pending * coap_pending_next_to_expire(struct coap_pending *pendings, size_t len)
Returns the next pending about to expire, pending->timeout informs how many ms to next expiration.
int coap_handle_request(struct coap_packet *cpkt, struct coap_resource *resources, struct coap_option *options, uint8_t opt_num, struct net_sockaddr *addr, net_socklen_t addr_len)
When a request is received, call the appropriate methods of the matching resources.
uint8_t coap_tcp_header_get_token(const struct coap_packet *cpkt, uint8_t *token)
Returns the token (if any) in the CoAP TCP packet.
bool coap_has_descriptive_block_option(struct coap_packet *cpkt)
Check if a descriptive block option is set in the packet.
struct coap_observer * coap_find_observer(struct coap_observer *observers, size_t len, const struct net_sockaddr *addr, const uint8_t *token, uint8_t token_len)
Returns the observer that matches address addr and has token token.
uint8_t coap_tcp_header_get_code(const struct coap_packet *cpkt)
Returns the code of the CoAP TCP packet.
int coap_handle_request_len(struct coap_packet *cpkt, struct coap_resource *resources, size_t resources_len, struct coap_option *options, uint8_t opt_num, struct net_sockaddr *addr, net_socklen_t addr_len)
When a request is received, call the appropriate methods of the matching resources.
int coap_packet_set_path(struct coap_packet *cpkt, const char *path)
Parses provided coap path (with/without query) or query and appends that as options to the cpkt.
#define COAP_MAKE_RESPONSE_CODE(class, det)
Utility macro to create a CoAP response code.
Definition coap.h:145
int coap_packet_remove_option(struct coap_packet *cpkt, uint16_t code)
Remove an option from the packet.
void coap_reply_init(struct coap_reply *reply, const struct coap_packet *request)
Indicates that a reply is expected for request.
int coap_resource_notify(struct coap_resource *resource)
Indicates that this resource was updated and that the notify callback should be called for every regi...
size_t coap_pendings_count(struct coap_pending *pendings, size_t len)
Count number of pending requests.
int coap_packet_append_payload(struct coap_packet *cpkt, const uint8_t *payload, uint16_t payload_len)
Append payload to CoAP packet.
void coap_replies_clear(struct coap_reply *replies, size_t len)
Cancels all replies, so they become available again.
uint16_t coap_next_id(void)
Helper to generate message ids.
struct coap_observer * coap_find_observer_by_token(struct coap_observer *observers, size_t len, const uint8_t *token, uint8_t token_len)
Returns the observer that has token token.
uint8_t coap_header_get_code(const struct coap_packet *cpkt)
Returns the code of the CoAP packet.
int coap_tcp_packet_update_len(struct coap_packet *cpkt)
Updates the length field within the header of a CoAP TCP packet.
int coap_ack_init(struct coap_packet *cpkt, const struct coap_packet *req, uint8_t *data, uint16_t max_len, uint8_t code)
Create a new CoAP Acknowledgment message for given request.
uint8_t coap_header_get_type(const struct coap_packet *cpkt)
Returns the type of the CoAP packet.
int coap_find_options(const struct coap_packet *cpkt, uint16_t code, struct coap_option *options, uint16_t veclen)
Return the values associated with the option of value code.
int coap_tcp_packet_parse(struct coap_packet *cpkt, uint8_t *data, uint16_t len, struct coap_option *options, uint8_t opt_num)
Parses the CoAP TCP packet in data, validating it and initializing cpkt.
int coap_tcp_append_block2_option(struct coap_packet *cpkt, struct coap_block_context *ctx)
Append BLOCK2 option to the TCP packet.
void coap_set_transmission_parameters(const struct coap_transmission_parameters *params)
Set CoAP transmission parameters.
int coap_append_size2_option(struct coap_packet *cpkt, struct coap_block_context *ctx)
Append SIZE2 option to the packet.
bool coap_block_has_more(struct coap_packet *cpkt)
Check if BLOCK1 or BLOCK2 option has more flag set.
uint8_t coap_header_get_version(const struct coap_packet *cpkt)
Returns the version present in a CoAP packet.
int coap_header_set_code(const struct coap_packet *cpkt, uint8_t code)
Modifies the code of the CoAP packet.
static uint16_t coap_block_size_to_bytes(enum coap_block_size block_size)
Helper for converting the enumeration to the size expressed in bytes.
Definition coap.h:815
@ COAP_SIGNAL_CODE_RELEASE
7.04 - Release
Definition coap.h:216
@ COAP_RESPONSE_CODE_INTERNAL_ERROR
5.00 - Internal Server Error
Definition coap.h:197
@ COAP_RESPONSE_CODE_PRECONDITION_FAILED
4.12 - Precondition Failed
Definition coap.h:186
@ COAP_RESPONSE_CODE_NOT_ALLOWED
4.05 - Method Not Allowed
Definition coap.h:178
@ COAP_RESPONSE_CODE_CHANGED
2.04 - Changed
Definition coap.h:162
@ COAP_RESPONSE_CODE_NOT_ACCEPTABLE
4.06 - Not Acceptable
Definition coap.h:180
@ COAP_RESPONSE_CODE_UNPROCESSABLE_ENTITY
4.22 - Unprocessable Entity
Definition coap.h:193
@ COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED
5.05 - Proxying Not Supported
Definition coap.h:207
@ COAP_RESPONSE_CODE_BAD_REQUEST
4.00 - Bad Request
Definition coap.h:168
@ COAP_RESPONSE_CODE_INCOMPLETE
4.08 - Request Entity Incomplete
Definition coap.h:182
@ COAP_SIGNAL_CODE_PING
7.02 - Ping
Definition coap.h:212
@ COAP_RESPONSE_CODE_NOT_IMPLEMENTED
5.01 - Not Implemented
Definition coap.h:199
@ COAP_RESPONSE_CODE_NOT_FOUND
4.04 - Not Found
Definition coap.h:176
@ COAP_RESPONSE_CODE_BAD_GATEWAY
5.02 - Bad Gateway
Definition coap.h:201
@ COAP_SIGNAL_CODE_ABORT
7.05 - Abort
Definition coap.h:218
@ COAP_RESPONSE_CODE_BAD_OPTION
4.02 - Bad Option
Definition coap.h:172
@ COAP_RESPONSE_CODE_REQUEST_TOO_LARGE
4.13 - Request Entity Too Large
Definition coap.h:188
@ COAP_RESPONSE_CODE_TOO_MANY_REQUESTS
4.29 - Too Many Requests
Definition coap.h:195
@ COAP_RESPONSE_CODE_CONFLICT
4.09 - Conflict
Definition coap.h:184
@ COAP_SIGNAL_CODE_PONG
7.03 - Pong
Definition coap.h:214
@ COAP_RESPONSE_CODE_DELETED
2.02 - Deleted
Definition coap.h:158
@ COAP_SIGNAL_CODE_CSM
7.01 - Capabilities and Settings Message
Definition coap.h:210
@ COAP_RESPONSE_CODE_UNAUTHORIZED
4.01 - Unauthorized
Definition coap.h:170
@ COAP_RESPONSE_CODE_CREATED
2.01 - Created
Definition coap.h:156
@ COAP_RESPONSE_CODE_CONTENT
2.05 - Content
Definition coap.h:164
@ COAP_RESPONSE_CODE_CONTINUE
2.31 - Continue
Definition coap.h:166
@ COAP_RESPONSE_CODE_VALID
2.03 - Valid
Definition coap.h:160
@ COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT
4.15 - Unsupported Content-Format
Definition coap.h:190
@ COAP_RESPONSE_CODE_GATEWAY_TIMEOUT
5.04 - Gateway Timeout
Definition coap.h:205
@ COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE
5.03 - Service Unavailable
Definition coap.h:203
@ COAP_RESPONSE_CODE_FORBIDDEN
4.03 - Forbidden
Definition coap.h:174
@ COAP_NO_RESPONSE_SUPPRESS_5_XX
Definition coap.h:268
@ COAP_NO_RESPONSE_SUPPRESS_ALL
Definition coap.h:270
@ COAP_NO_RESPONSE_SUPPRESS_4_XX
Definition coap.h:267
@ COAP_NO_RESPONSE_SUPPRESS_2_XX
Definition coap.h:266
@ COAP_TYPE_RESET
Reset.
Definition coap.h:136
@ COAP_TYPE_NON_CON
Non-confirmable message.
Definition coap.h:123
@ COAP_TYPE_CON
Confirmable message.
Definition coap.h:116
@ COAP_TYPE_ACK
Acknowledge.
Definition coap.h:129
@ COAP_METHOD_GET
GET.
Definition coap.h:87
@ COAP_METHOD_IPATCH
IPATCH.
Definition coap.h:93
@ COAP_METHOD_PUT
PUT.
Definition coap.h:89
@ COAP_METHOD_POST
POST.
Definition coap.h:88
@ COAP_METHOD_PATCH
PATCH.
Definition coap.h:92
@ COAP_METHOD_DELETE
DELETE.
Definition coap.h:90
@ COAP_METHOD_FETCH
FETCH.
Definition coap.h:91
@ COAP_BLOCK_128
128-byte block size
Definition coap.h:800
@ COAP_BLOCK_32
32-byte block size
Definition coap.h:798
@ COAP_BLOCK_BERT
BERT block size (RFC 8323) - acts like 1024 for calculations.
Definition coap.h:804
@ COAP_BLOCK_1024
1024-byte block size
Definition coap.h:803
@ COAP_BLOCK_64
64-byte block size
Definition coap.h:799
@ COAP_BLOCK_16
16-byte block size
Definition coap.h:797
@ COAP_BLOCK_256
256-byte block size
Definition coap.h:801
@ COAP_BLOCK_512
512-byte block size
Definition coap.h:802
@ COAP_OPTION_OBSERVE
Observe (RFC 7641).
Definition coap.h:55
@ COAP_OPTION_IF_NONE_MATCH
If-None-Match.
Definition coap.h:54
@ COAP_OPTION_ETAG
ETag.
Definition coap.h:53
@ COAP_OPTION_SIZE2
Size2 (RFC 7959).
Definition coap.h:67
@ COAP_OPTION_REQUEST_TAG
Request-Tag (RFC 9175).
Definition coap.h:73
@ COAP_OPTION_SIGNAL_701_MMS
Signal 7.01 Max message size (RFC 8323).
Definition coap.h:74
@ COAP_OPTION_PROXY_SCHEME
Proxy-Scheme.
Definition coap.h:69
@ COAP_OPTION_URI_PORT
Uri-Port.
Definition coap.h:56
@ COAP_OPTION_URI_HOST
Uri-Host.
Definition coap.h:52
@ COAP_OPTION_BLOCK2
Block2 (RFC 7959).
Definition coap.h:65
@ COAP_OPTION_IF_MATCH
If-Match.
Definition coap.h:51
@ COAP_OPTION_SIZE1
Size1.
Definition coap.h:70
@ COAP_OPTION_ECHO
Echo (RFC 9175).
Definition coap.h:71
@ COAP_OPTION_SIGNAL_705_BAD_CSM
Signal 7.05 Bad-CSM-Option (RFC 8323).
Definition coap.h:78
@ COAP_OPTION_NO_RESPONSE
No-Response (RFC 7967).
Definition coap.h:72
@ COAP_OPTION_BLOCK1
Block1 (RFC 7959).
Definition coap.h:66
@ COAP_OPTION_URI_PATH
Uri-Path.
Definition coap.h:59
@ COAP_OPTION_SIGNAL_704_ALT_ADDR
Signal 7.04 Alternative-Address (RFC 8323).
Definition coap.h:76
@ COAP_OPTION_OSCORE
OSCORE (RFC 8613).
Definition coap.h:58
@ COAP_OPTION_MAX_AGE
Max-Age.
Definition coap.h:61
@ COAP_OPTION_CONTENT_FORMAT
Content-Format.
Definition coap.h:60
@ COAP_OPTION_LOCATION_QUERY
Location-Query.
Definition coap.h:64
@ COAP_OPTION_URI_QUERY
Uri-Query.
Definition coap.h:62
@ COAP_OPTION_PROXY_URI
Proxy-Uri.
Definition coap.h:68
@ COAP_OPTION_LOCATION_PATH
Location-Path.
Definition coap.h:57
@ COAP_OPTION_SIGNAL_701_BWT
Signal 7.01 Block-wise transfer (RFC 8323).
Definition coap.h:75
@ COAP_OPTION_SIGNAL_704_HOLD_OFF
Signal 7.04 Hold-Off (RFC 8323).
Definition coap.h:77
@ COAP_OPTION_ACCEPT
Accept.
Definition coap.h:63
@ COAP_CONTENT_FORMAT_APP_JSON_PATCH_JSON
application/json-patch+json
Definition coap.h:254
@ COAP_CONTENT_FORMAT_APP_LINK_FORMAT
application/link-format
Definition coap.h:249
@ COAP_CONTENT_FORMAT_APP_MERGE_PATCH_JSON
application/merge-patch+json
Definition coap.h:255
@ COAP_CONTENT_FORMAT_APP_EXI
application/exi
Definition coap.h:252
@ COAP_CONTENT_FORMAT_APP_CBOR
application/cbor
Definition coap.h:256
@ COAP_CONTENT_FORMAT_APP_OCTET_STREAM
application/octet-stream
Definition coap.h:251
@ COAP_CONTENT_FORMAT_APP_JSON
application/json
Definition coap.h:253
@ COAP_CONTENT_FORMAT_APP_XML
application/xml
Definition coap.h:250
@ COAP_CONTENT_FORMAT_TEXT_PLAIN
text/plain;charset=utf-8
Definition coap.h:248
uint32_t net_socklen_t
Length of a socket address.
Definition net_ip.h:172
static int u32_count_trailing_zeros(uint32_t x)
Count the number of trailing zero bits in a 32-bit integer.
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:54
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:44
Extra arithmetic and bit-manipulation functions.
IPv6 and IPv4 definitions.
Header file for the single-linked list API.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT64_TYPE__ int64_t
Definition stdint.h:75
Represents the current state of a block-wise transaction.
Definition coap.h:854
size_t total_size
Total size of the block-wise transaction.
Definition coap.h:856
enum coap_block_size block_size
Block size.
Definition coap.h:860
size_t current
Current size of the block-wise transaction.
Definition coap.h:858
In case you want to add attributes to the resources included in the 'well-known/core' "virtual" resou...
Definition coap_link_format.h:72
Represents a remote device that is observing a local resource.
Definition coap.h:333
sys_snode_t list
Observer list node.
Definition coap.h:335
struct net_sockaddr_storage addr
Observer connection end point information.
Definition coap.h:337
uint8_t token[8]
Observer token.
Definition coap.h:339
struct coap_oscore_context * oscore_ctx
Not-NULL if the observer is OSCORE protected.
Definition coap.h:347
uint8_t tkl
Extended token length.
Definition coap.h:341
Representation of a CoAP option.
Definition coap.h:380
uint8_t len
Option length.
Definition coap.h:386
uint16_t delta
Option delta.
Definition coap.h:381
uint8_t value[12]
Option value.
Definition coap.h:387
Representation of a CoAP Packet.
Definition coap.h:354
uint16_t offset
CoAP lib maintains offset while adding data.
Definition coap.h:356
uint16_t max_len
Max CoAP packet data length.
Definition coap.h:357
uint8_t * data
User allocated buffer.
Definition coap.h:355
uint16_t delta
Used for delta calculation in CoAP packet.
Definition coap.h:360
uint8_t hdr_len
CoAP header length.
Definition coap.h:358
struct coap_oscore_context * oscore_ctx
Not-NULL if the packet was received OSCORE protected.
Definition coap.h:373
void * user_data
Application specific user data.
Definition coap.h:366
uint16_t opt_len
Total options length (delta + len + value).
Definition coap.h:359
Represents a request awaiting for an acknowledgment (ACK).
Definition coap.h:425
struct coap_transmission_parameters params
Transmission parameters.
Definition coap.h:439
uint8_t * data
User allocated buffer.
Definition coap.h:436
uint16_t len
Length of the CoAP packet.
Definition coap.h:437
uint8_t retries
Number of times the request has been sent.
Definition coap.h:438
uint16_t id
Message id.
Definition coap.h:435
int64_t t0
Time when the request was sent.
Definition coap.h:433
struct net_sockaddr_storage addr_storage
Remote address storage.
Definition coap.h:431
uint32_t timeout
Timeout in ms.
Definition coap.h:434
Represents the handler for the reply of a request, it is also used when observing resources.
Definition coap.h:446
uint8_t tkl
Extended token length.
Definition coap.h:458
uint8_t token[8]
Reply token.
Definition coap.h:456
coap_reply_t reply
CoAP reply callback.
Definition coap.h:448
uint16_t id
Reply id.
Definition coap.h:454
void * user_data
User specific opaque data.
Definition coap.h:450
int age
Reply age.
Definition coap.h:452
Description of CoAP resource.
Definition coap.h:313
coap_method_t post
Definition coap.h:315
void * user_data
User specific opaque data.
Definition coap.h:321
coap_method_t put
Definition coap.h:315
coap_notify_t notify
Notify function to call.
Definition coap.h:317
sys_slist_t observers
List of resource observers.
Definition coap.h:325
coap_method_t fetch
Definition coap.h:315
struct coap_core_metadata * metadata
Resource metadata for '.well-known/core' responses.
Definition coap.h:323
coap_method_t ipatch
Definition coap.h:315
coap_method_t del
Definition coap.h:315
coap_method_t patch
Definition coap.h:315
const char *const * path
Resource path.
Definition coap.h:319
int age
Resource age.
Definition coap.h:327
coap_method_t get
Which function to be called for each CoAP method.
Definition coap.h:315
CoAP transmission parameters.
Definition coap.h:406
uint16_t ack_random_percent
Set CoAP ack random factor.
Definition coap.h:414
uint8_t max_retransmission
Maximum number of retransmissions.
Definition coap.h:419
uint16_t coap_backoff_percent
Set CoAP retry backoff factor.
Definition coap.h:417
uint32_t ack_timeout
Initial ACK timeout.
Definition coap.h:408
Generic sockaddr struct.
Definition net_ip.h:455