Zephyr API Documentation 4.0.99
A Scalable Open Source RTOS
|
COAP library . More...
Data Structures | |
struct | coap_resource |
Description of CoAP resource. More... | |
struct | coap_observer |
Represents a remote device that is observing a local resource. More... | |
struct | coap_packet |
Representation of a CoAP Packet. More... | |
struct | coap_option |
Representation of a CoAP option. More... | |
struct | coap_transmission_parameters |
CoAP transmission parameters. More... | |
struct | coap_pending |
Represents a request awaiting for an acknowledgment (ACK). More... | |
struct | coap_reply |
Represents the handler for the reply of a request, it is also used when observing resources. More... | |
struct | coap_block_context |
Represents the current state of a block-wise transaction. More... | |
struct | coap_core_metadata |
In case you want to add attributes to the resources included in the 'well-known/core' "virtual" resource, the 'user_data' field should point to a valid coap_core_metadata structure. More... | |
Macros | |
#define | COAP_MAKE_RESPONSE_CODE(class, det) |
Utility macro to create a CoAP response code. | |
#define | COAP_WELL_KNOWN_CORE_PATH ((const char * const[]) { ".well-known", "core", NULL }) |
This resource should be added before all other resources that should be included in the responses of the .well-known/core resource if is to be used with coap_well_known_core_get. | |
Typedefs | |
typedef int(* | coap_method_t) (struct coap_resource *resource, struct coap_packet *request, struct sockaddr *addr, socklen_t addr_len) |
Type of the callback being called when a resource's method is invoked by the remote entity. | |
typedef 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 happens. | |
typedef int(* | coap_reply_t) (const struct coap_packet *response, struct coap_reply *reply, const struct sockaddr *from) |
Helper function to be called when a response matches the a pending request. | |
Functions | |
uint8_t | coap_header_get_version (const struct coap_packet *cpkt) |
Returns the version present in a CoAP packet. | |
uint8_t | coap_header_get_type (const struct coap_packet *cpkt) |
Returns the type of the CoAP packet. | |
uint8_t | coap_header_get_token (const struct coap_packet *cpkt, uint8_t *token) |
Returns the token (if any) in the CoAP packet. | |
uint8_t | coap_header_get_code (const struct coap_packet *cpkt) |
Returns the code of the CoAP packet. | |
int | coap_header_set_code (const struct coap_packet *cpkt, uint8_t code) |
Modifies the code of the CoAP packet. | |
uint16_t | coap_header_get_id (const struct coap_packet *cpkt) |
Returns the message id associated with the CoAP packet. | |
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. | |
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_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. | |
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. | |
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_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. | |
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. | |
uint8_t * | coap_next_token (void) |
Returns a randomly generated array of 8 bytes, that can be used as a message's token. | |
uint16_t | coap_next_id (void) |
Helper to generate message ids. | |
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_packet_append_option (struct coap_packet *cpkt, uint16_t code, const uint8_t *value, uint16_t len) |
Appends an option to the packet. | |
int | coap_packet_remove_option (struct coap_packet *cpkt, uint16_t code) |
Remove an option from the packet. | |
unsigned int | coap_option_value_to_int (const struct coap_option *option) |
Converts an option to its integer representation. | |
int | coap_append_option_int (struct coap_packet *cpkt, uint16_t code, unsigned int val) |
Appends an integer value option to the packet. | |
int | coap_packet_append_payload_marker (struct coap_packet *cpkt) |
Append payload marker to CoAP packet. | |
int | coap_packet_append_payload (struct coap_packet *cpkt, const uint8_t *payload, uint16_t payload_len) |
Append payload to CoAP packet. | |
bool | coap_packet_is_request (const struct coap_packet *cpkt) |
Check if a CoAP packet is a CoAP request. | |
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 sockaddr *addr, socklen_t addr_len) |
When a request is received, call the appropriate methods of the matching resources. | |
int | coap_handle_request (struct coap_packet *cpkt, struct coap_resource *resources, struct coap_option *options, uint8_t opt_num, struct sockaddr *addr, socklen_t addr_len) |
When a request is received, call the appropriate methods of the matching resources. | |
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. | |
static enum coap_block_size | coap_bytes_to_block_size (uint16_t bytes) |
Helper for converting block size in bytes to enumeration. | |
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_append_descriptive_block_option (struct coap_packet *cpkt, struct coap_block_context *ctx) |
Append BLOCK1 or BLOCK2 option to the packet. | |
bool | coap_has_descriptive_block_option (struct coap_packet *cpkt) |
Check if a descriptive block option is set in the packet. | |
int | coap_remove_descriptive_block_option (struct coap_packet *cpkt) |
Remove BLOCK1 or BLOCK2 option from the packet. | |
bool | coap_block_has_more (struct coap_packet *cpkt) |
Check if BLOCK1 or BLOCK2 option has more flag set. | |
int | coap_append_block1_option (struct coap_packet *cpkt, struct coap_block_context *ctx) |
Append BLOCK1 option to the packet. | |
int | coap_append_block2_option (struct coap_packet *cpkt, struct coap_block_context *ctx) |
Append BLOCK2 option to the packet. | |
int | coap_append_size1_option (struct coap_packet *cpkt, struct coap_block_context *ctx) |
Append SIZE1 option to the packet. | |
int | coap_append_size2_option (struct coap_packet *cpkt, struct coap_block_context *ctx) |
Append SIZE2 option to the packet. | |
int | coap_get_option_int (const struct coap_packet *cpkt, uint16_t code) |
Get the integer representation of a CoAP option. | |
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. | |
int | coap_get_block2_option (const struct coap_packet *cpkt, bool *has_more, uint32_t *block_number) |
Get values from CoAP block2 option. | |
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. | |
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 correct offset in the body of data being transferred. | |
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 data being transferred. | |
void | coap_observer_init (struct coap_observer *observer, const struct coap_packet *request, const struct sockaddr *addr) |
Indicates that the remote device referenced by addr, with request, wants to observe a resource. | |
bool | coap_register_observer (struct coap_resource *resource, struct coap_observer *observer) |
After the observer is initialized, associate the observer with an resource. | |
bool | coap_remove_observer (struct coap_resource *resource, struct coap_observer *observer) |
Remove this observer from the list of registered observers of that resource. | |
struct coap_observer * | coap_find_observer (struct coap_observer *observers, size_t len, const struct sockaddr *addr, const uint8_t *token, uint8_t token_len) |
Returns the observer that matches address addr and has token token. | |
struct coap_observer * | coap_find_observer_by_addr (struct coap_observer *observers, size_t len, const struct sockaddr *addr) |
Returns the observer that matches address addr. | |
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. | |
struct coap_observer * | coap_observer_next_unused (struct coap_observer *observers, size_t len) |
Returns the next available observer representation. | |
void | coap_reply_init (struct coap_reply *reply, const struct coap_packet *request) |
Indicates that a reply is expected for request. | |
int | coap_pending_init (struct coap_pending *pending, const struct coap_packet *request, const struct sockaddr *addr, const struct coap_transmission_parameters *params) |
Initialize a pending request with a request. | |
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 request. | |
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 received. | |
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. | |
struct coap_reply * | coap_response_received (const struct coap_packet *response, const struct sockaddr *from, struct coap_reply *replies, size_t len) |
After a response is received, call coap_reply_t handler registered in coap_reply structure. | |
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. | |
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. | |
void | coap_pending_clear (struct coap_pending *pending) |
Cancels the pending retransmission, so it again becomes available. | |
void | coap_pendings_clear (struct coap_pending *pendings, size_t len) |
Cancels all pending retransmissions, so they become available again. | |
size_t | coap_pendings_count (struct coap_pending *pendings, size_t len) |
Count number of pending requests. | |
void | coap_reply_clear (struct coap_reply *reply) |
Cancels awaiting for this reply, so it becomes available again. | |
void | coap_replies_clear (struct coap_reply *replies, size_t len) |
Cancels all replies, so they become available again. | |
int | coap_resource_notify (struct coap_resource *resource) |
Indicates that this resource was updated and that the notify callback should be called for every registered observer. | |
bool | coap_request_is_observe (const struct coap_packet *request) |
Returns if this request is enabling observing a resource. | |
struct coap_transmission_parameters | coap_get_transmission_parameters (void) |
Get currently active CoAP transmission parameters. | |
void | coap_set_transmission_parameters (const struct coap_transmission_parameters *params) |
Set CoAP transmission parameters. | |
int | coap_well_known_core_get (struct coap_resource *resource, const struct coap_packet *request, struct coap_packet *response, uint8_t *data, uint16_t data_len) |
Build a CoAP response for a .well-known/core CoAP request. | |
int | coap_well_known_core_get_len (struct coap_resource *resources, size_t resources_len, const struct coap_packet *request, struct coap_packet *response, uint8_t *data, uint16_t data_len) |
Build a CoAP response for a .well-known/core CoAP request. | |
COAP library .
#define COAP_MAKE_RESPONSE_CODE | ( | class, | |
det ) |
#include <zephyr/net/coap.h>
Utility macro to create a CoAP response code.
class | Class of the response code (ex. 2, 4, 5, ...) |
det | Detail of the response code |
#define COAP_WELL_KNOWN_CORE_PATH ((const char * const[]) { ".well-known", "core", NULL }) |
#include <zephyr/net/coap_link_format.h>
This resource should be added before all other resources that should be included in the responses of the .well-known/core resource if is to be used with coap_well_known_core_get.
typedef int(* coap_method_t) (struct coap_resource *resource, struct coap_packet *request, struct sockaddr *addr, socklen_t addr_len) |
#include <zephyr/net/coap.h>
Type of the callback being called when a resource's method is invoked by the remote entity.
typedef void(* coap_notify_t) (struct coap_resource *resource, struct coap_observer *observer) |
#include <zephyr/net/coap.h>
Type of the callback being called when a resource's has observers to be informed when an update happens.
typedef int(* coap_reply_t) (const struct coap_packet *response, struct coap_reply *reply, const struct sockaddr *from) |
#include <zephyr/net/coap.h>
Helper function to be called when a response matches the a pending request.
When sending blocks, the callback is only executed when the reply of the last block is received. i.e. it is not called when the code of the reply is 'continue' (2.31).
enum coap_block_size |
#include <zephyr/net/coap.h>
Represents the size of each block that will be transferred using block-wise transfers [RFC7959]:
Each entry maps directly to the value that is used in the wire.
https://tools.ietf.org/html/rfc7959
enum coap_content_format |
#include <zephyr/net/coap.h>
Set of Content-Format option values for CoAP.
To be used when encoding or decoding a Content-Format option.
enum coap_method |
#include <zephyr/net/coap.h>
Available request methods.
To be used when creating a request or a response.
Enumerator | |
---|---|
COAP_METHOD_GET | GET. |
COAP_METHOD_POST | POST. |
COAP_METHOD_PUT | PUT. |
COAP_METHOD_DELETE | DELETE. |
COAP_METHOD_FETCH | FETCH. |
COAP_METHOD_PATCH | PATCH. |
COAP_METHOD_IPATCH | IPATCH. |
enum coap_msgtype |
#include <zephyr/net/coap.h>
CoAP packets may be of one of these types.
enum coap_no_response |
#include <zephyr/net/coap.h>
Set of No-Response option values for CoAP.
To be used when encoding or decoding a No-Response option defined in RFC 7967.
Enumerator | |
---|---|
COAP_NO_RESPONSE_SUPPRESS_2_XX | |
COAP_NO_RESPONSE_SUPPRESS_4_XX | |
COAP_NO_RESPONSE_SUPPRESS_5_XX | |
COAP_NO_RESPONSE_SUPPRESS_ALL |
enum coap_option_num |
#include <zephyr/net/coap.h>
Set of CoAP packet options we are aware of.
Users may add options other than these to their packets, provided they know how to format them correctly. The only restriction is that all options must be added to a packet in numeric order.
Refer to RFC 7252, section 12.2 for more information.
enum coap_response_code |
#include <zephyr/net/coap.h>
Set of response codes available for a response packet.
To be used when creating a response.
int coap_ack_init | ( | struct coap_packet * | cpkt, |
const struct coap_packet * | req, | ||
uint8_t * | data, | ||
uint16_t | max_len, | ||
uint8_t | code ) |
#include <zephyr/net/coap.h>
Create a new CoAP Acknowledgment message for given request.
This function works like coap_packet_init, filling CoAP header type, CoAP header token, and CoAP header message id fields according to acknowledgment rules.
cpkt | New packet to be initialized using the storage from data. |
req | CoAP request packet that is being acknowledged |
data | Data that will contain a CoAP packet information |
max_len | Maximum allowable length of data |
code | CoAP header code |
int coap_append_block1_option | ( | struct coap_packet * | cpkt, |
struct coap_block_context * | ctx ) |
#include <zephyr/net/coap.h>
Append BLOCK1 option to the packet.
cpkt | Packet to be updated |
ctx | Block context from which to retrieve the information for the Block1 option |
int coap_append_block2_option | ( | struct coap_packet * | cpkt, |
struct coap_block_context * | ctx ) |
#include <zephyr/net/coap.h>
Append BLOCK2 option to the packet.
cpkt | Packet to be updated |
ctx | Block context from which to retrieve the information for the Block2 option |
int coap_append_descriptive_block_option | ( | struct coap_packet * | cpkt, |
struct coap_block_context * | ctx ) |
#include <zephyr/net/coap.h>
Append BLOCK1 or BLOCK2 option to the packet.
If the CoAP packet is a request then BLOCK1 is appended otherwise BLOCK2 is appended.
cpkt | Packet to be updated |
ctx | Block context from which to retrieve the information for the block option |
int coap_append_option_int | ( | struct coap_packet * | cpkt, |
uint16_t | code, | ||
unsigned int | val ) |
#include <zephyr/net/coap.h>
Appends an integer value option to the packet.
The option must be added in numeric order of their codes, and the least amount of bytes will be used to encode the value.
cpkt | Packet to be updated |
code | Option code to add to the packet, see coap_option_num |
val | Integer value to be added |
int coap_append_size1_option | ( | struct coap_packet * | cpkt, |
struct coap_block_context * | ctx ) |
#include <zephyr/net/coap.h>
Append SIZE1 option to the packet.
cpkt | Packet to be updated |
ctx | Block context from which to retrieve the information for the Size1 option |
int coap_append_size2_option | ( | struct coap_packet * | cpkt, |
struct coap_block_context * | ctx ) |
#include <zephyr/net/coap.h>
Append SIZE2 option to the packet.
cpkt | Packet to be updated |
ctx | Block context from which to retrieve the information for the Size2 option |
bool coap_block_has_more | ( | struct coap_packet * | cpkt | ) |
#include <zephyr/net/coap.h>
Check if BLOCK1 or BLOCK2 option has more flag set.
cpkt | Packet to be checked. |
|
inlinestatic |
#include <zephyr/net/coap.h>
Helper for converting the enumeration to the size expressed in bytes.
block_size | The block size to be converted |
int coap_block_transfer_init | ( | struct coap_block_context * | ctx, |
enum coap_block_size | block_size, | ||
size_t | total_size ) |
#include <zephyr/net/coap.h>
Initializes the context of a block-wise transfer.
ctx | The context to be initialized |
block_size | The size of the block |
total_size | The total size of the transfer, if known |
|
inlinestatic |
#include <zephyr/net/coap.h>
Helper for converting block size in bytes to enumeration.
NOTE: Only valid CoAP block sizes map correctly.
bytes | CoAP block size in bytes. |
struct coap_observer * coap_find_observer | ( | struct coap_observer * | observers, |
size_t | len, | ||
const struct sockaddr * | addr, | ||
const uint8_t * | token, | ||
uint8_t | token_len ) |
#include <zephyr/net/coap.h>
Returns the observer that matches address addr and has token token.
observers | Pointer to the array of observers |
len | Size of the array of observers |
addr | Address of the endpoint observing a resource |
token | Pointer to the token |
token_len | Length of valid bytes in the token |
struct coap_observer * coap_find_observer_by_addr | ( | struct coap_observer * | observers, |
size_t | len, | ||
const struct sockaddr * | addr ) |
#include <zephyr/net/coap.h>
Returns the observer that matches address addr.
observers | Pointer to the array of observers |
len | Size of the array of observers |
addr | Address of the endpoint observing a resource |
struct coap_observer * coap_find_observer_by_token | ( | struct coap_observer * | observers, |
size_t | len, | ||
const uint8_t * | token, | ||
uint8_t | token_len ) |
#include <zephyr/net/coap.h>
Returns the observer that has token token.
observers | Pointer to the array of observers |
len | Size of the array of observers |
token | Pointer to the token |
token_len | Length of valid bytes in the token |
int coap_find_options | ( | const struct coap_packet * | cpkt, |
uint16_t | code, | ||
struct coap_option * | options, | ||
uint16_t | veclen ) |
#include <zephyr/net/coap.h>
Return the values associated with the option of value code.
cpkt | CoAP packet representation |
code | Option number to look for |
options | Array of coap_option where to store the value of the options found |
veclen | Number of elements in the options array |
int coap_get_block1_option | ( | const struct coap_packet * | cpkt, |
bool * | has_more, | ||
uint32_t * | block_number ) |
#include <zephyr/net/coap.h>
Get the block size, more flag and block number from the CoAP block1 option.
cpkt | Packet to be inspected |
has_more | Is set to the value of the more flag |
block_number | Is set to the number of the block |
int coap_get_block2_option | ( | const struct coap_packet * | cpkt, |
bool * | has_more, | ||
uint32_t * | block_number ) |
#include <zephyr/net/coap.h>
Get values from CoAP block2 option.
Decode block number, more flag and block size from option.
cpkt | Packet to be inspected |
has_more | Is set to the value of the more flag |
block_number | Is set to the number of the block |
int coap_get_option_int | ( | const struct coap_packet * | cpkt, |
uint16_t | code ) |
#include <zephyr/net/coap.h>
Get the integer representation of a CoAP option.
cpkt | Packet to be inspected |
code | CoAP option code |
struct coap_transmission_parameters coap_get_transmission_parameters | ( | void | ) |
#include <zephyr/net/coap.h>
Get currently active CoAP transmission parameters.
int coap_handle_request | ( | struct coap_packet * | cpkt, |
struct coap_resource * | resources, | ||
struct coap_option * | options, | ||
uint8_t | opt_num, | ||
struct sockaddr * | addr, | ||
socklen_t | addr_len ) |
#include <zephyr/net/coap.h>
When a request is received, call the appropriate methods of the matching resources.
cpkt | Packet received |
resources | Array of known resources (terminated with empty resource) |
options | Parsed options from coap_packet_parse() |
opt_num | Number of options |
addr | Peer address |
addr_len | Peer address length |
>= | 0 in case of success. |
-ENOTSUP | in case of invalid request code. |
-EPERM | in case resource handler is not implemented. |
-ENOENT | in case the resource is not found. |
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 sockaddr * | addr, | ||
socklen_t | addr_len ) |
#include <zephyr/net/coap.h>
When a request is received, call the appropriate methods of the matching resources.
cpkt | Packet received |
resources | Array of known resources |
resources_len | Number of resources in the array |
options | Parsed options from coap_packet_parse() |
opt_num | Number of options |
addr | Peer address |
addr_len | Peer address length |
>= | 0 in case of success. |
-ENOTSUP | in case of invalid request code. |
-EPERM | in case resource handler is not implemented. |
-ENOENT | in case the resource is not found. |
bool coap_has_descriptive_block_option | ( | struct coap_packet * | cpkt | ) |
#include <zephyr/net/coap.h>
Check if a descriptive block option is set in the packet.
If the CoAP packet is a request then an available BLOCK1 option would be checked otherwise a BLOCK2 option would be checked.
cpkt | Packet to be checked. |
uint8_t coap_header_get_code | ( | const struct coap_packet * | cpkt | ) |
#include <zephyr/net/coap.h>
Returns the code of the CoAP packet.
cpkt | CoAP packet representation |
uint16_t coap_header_get_id | ( | const struct coap_packet * | cpkt | ) |
#include <zephyr/net/coap.h>
Returns the message id associated with the CoAP packet.
cpkt | CoAP packet representation |
uint8_t coap_header_get_token | ( | const struct coap_packet * | cpkt, |
uint8_t * | token ) |
#include <zephyr/net/coap.h>
Returns the token (if any) in the CoAP packet.
cpkt | CoAP packet representation |
token | Where to store the token, must point to a buffer containing at least COAP_TOKEN_MAX_LEN bytes |
uint8_t coap_header_get_type | ( | const struct coap_packet * | cpkt | ) |
#include <zephyr/net/coap.h>
Returns the type of the CoAP packet.
cpkt | CoAP packet representation |
uint8_t coap_header_get_version | ( | const struct coap_packet * | cpkt | ) |
#include <zephyr/net/coap.h>
Returns the version present in a CoAP packet.
cpkt | CoAP packet representation |
int coap_header_set_code | ( | const struct coap_packet * | cpkt, |
uint8_t | code ) |
#include <zephyr/net/coap.h>
Modifies the code of the CoAP packet.
cpkt | CoAP packet representation |
code | CoAP code |
size_t coap_next_block | ( | const struct coap_packet * | cpkt, |
struct coap_block_context * | ctx ) |
#include <zephyr/net/coap.h>
Updates ctx so after this is called the current entry indicates the correct offset in the body of data being transferred.
cpkt | Packet in which to look for block-wise transfers options |
ctx | Block context to be updated |
int coap_next_block_for_option | ( | const struct coap_packet * | cpkt, |
struct coap_block_context * | ctx, | ||
enum coap_option_num | option ) |
#include <zephyr/net/coap.h>
Updates ctx according to option set in cpkt so after this is called the current entry indicates the correct offset in the body of data being transferred.
cpkt | Packet in which to look for block-wise transfers options |
ctx | Block context to be updated |
option | Either COAP_OPTION_BLOCK1 or COAP_OPTION_BLOCK2 |
uint16_t coap_next_id | ( | void | ) |
uint8_t * coap_next_token | ( | void | ) |
#include <zephyr/net/coap.h>
Returns a randomly generated array of 8 bytes, that can be used as a message's token.
void coap_observer_init | ( | struct coap_observer * | observer, |
const struct coap_packet * | request, | ||
const struct sockaddr * | addr ) |
#include <zephyr/net/coap.h>
Indicates that the remote device referenced by addr, with request, wants to observe a resource.
observer | Observer to be initialized |
request | Request on which the observer will be based |
addr | Address of the remote device |
struct coap_observer * coap_observer_next_unused | ( | struct coap_observer * | observers, |
size_t | len ) |
#include <zephyr/net/coap.h>
Returns the next available observer representation.
observers | Pointer to the array of observers |
len | Size of the array of observers |
unsigned int coap_option_value_to_int | ( | const struct coap_option * | option | ) |
#include <zephyr/net/coap.h>
Converts an option to its integer representation.
Assumes that the number is encoded in the network byte order in the option.
option | Pointer to the option value, retrieved by coap_find_options() |
int coap_packet_append_option | ( | struct coap_packet * | cpkt, |
uint16_t | code, | ||
const uint8_t * | value, | ||
uint16_t | len ) |
#include <zephyr/net/coap.h>
Appends an option to the packet.
Note: options can be added out of numeric order of their codes. But it's more efficient to add them in order.
cpkt | Packet to be updated |
code | Option code to add to the packet, see coap_option_num |
value | Pointer to the value of the option, will be copied to the packet |
len | Size of the data to be added |
int coap_packet_append_payload | ( | struct coap_packet * | cpkt, |
const uint8_t * | payload, | ||
uint16_t | payload_len ) |
#include <zephyr/net/coap.h>
Append payload to CoAP packet.
cpkt | Packet to append the payload |
payload | CoAP packet payload |
payload_len | CoAP packet payload len |
int coap_packet_append_payload_marker | ( | struct coap_packet * | cpkt | ) |
#include <zephyr/net/coap.h>
Append payload marker to CoAP packet.
cpkt | Packet to append the payload marker (0xFF) |
const uint8_t * coap_packet_get_payload | ( | const struct coap_packet * | cpkt, |
uint16_t * | len ) |
#include <zephyr/net/coap.h>
Returns the data pointer and length of the CoAP packet.
cpkt | CoAP packet representation |
len | Total length of CoAP payload |
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 ) |
#include <zephyr/net/coap.h>
Creates a new CoAP Packet from input data.
cpkt | New packet to be initialized using the storage from data. |
data | Data that will contain a CoAP packet information |
max_len | Maximum allowable length of data |
ver | CoAP header version |
type | CoAP header type |
token_len | CoAP header token length |
token | CoAP header token |
code | CoAP header code |
id | CoAP header message id |
bool coap_packet_is_request | ( | const struct coap_packet * | cpkt | ) |
#include <zephyr/net/coap.h>
Check if a CoAP packet is a CoAP request.
cpkt | Packet to be checked. |
int coap_packet_parse | ( | struct coap_packet * | cpkt, |
uint8_t * | data, | ||
uint16_t | len, | ||
struct coap_option * | options, | ||
uint8_t | opt_num ) |
#include <zephyr/net/coap.h>
Parses the CoAP packet in data, validating it and initializing cpkt.
data must remain valid while cpkt is used.
cpkt | Packet to be initialized from received data. |
data | Data containing a CoAP packet, its data pointer is positioned on the start of the CoAP packet. |
len | Length of the data |
options | Parse options and cache its details. |
opt_num | Number of options |
0 | in case of success. |
-EINVAL | in case of invalid input args. |
-EBADMSG | in case of malformed coap packet header. |
-EILSEQ | in case of malformed coap options. |
int coap_packet_remove_option | ( | struct coap_packet * | cpkt, |
uint16_t | code ) |
#include <zephyr/net/coap.h>
Remove an option from the packet.
cpkt | Packet to be updated |
code | Option code to remove from the packet, see coap_option_num |
int coap_packet_set_path | ( | struct coap_packet * | cpkt, |
const char * | path ) |
#include <zephyr/net/coap.h>
Parses provided coap path (with/without query) or query and appends that as options to the cpkt.
cpkt | Packet to append path and query options for. |
path | Null-terminated string of coap path, query or both. |
0 | in case of success or negative in case of error. |
void coap_pending_clear | ( | struct coap_pending * | pending | ) |
#include <zephyr/net/coap.h>
Cancels the pending retransmission, so it again becomes available.
pending | Pending representation to be canceled |
bool coap_pending_cycle | ( | struct coap_pending * | pending | ) |
#include <zephyr/net/coap.h>
After a request is sent, user may want to cycle the pending retransmission so the timeout is updated.
pending | Pending representation to have its timeout updated |
int coap_pending_init | ( | struct coap_pending * | pending, |
const struct coap_packet * | request, | ||
const struct sockaddr * | addr, | ||
const struct coap_transmission_parameters * | params ) |
#include <zephyr/net/coap.h>
Initialize a pending request with a request.
The request's fields are copied into the pending struct, so request doesn't have to live for as long as the pending struct lives, but "data" that needs to live for at least that long.
pending | Structure representing the waiting for a confirmation message, initialized with data from request |
request | Message waiting for confirmation |
addr | Address to send the retransmission |
params | Pointer to the CoAP transmission parameters struct, or NULL to use default values |
struct coap_pending * coap_pending_next_to_expire | ( | struct coap_pending * | pendings, |
size_t | len ) |
#include <zephyr/net/coap.h>
Returns the next pending about to expire, pending->timeout informs how many ms to next expiration.
pendings | Pointer to the array of coap_pending structures |
len | Size of the array of coap_pending structures |
struct coap_pending * coap_pending_next_unused | ( | struct coap_pending * | pendings, |
size_t | len ) |
#include <zephyr/net/coap.h>
Returns the next available pending struct, that can be used to track the retransmission status of a request.
pendings | Pointer to the array of coap_pending structures |
len | Size of the array of coap_pending structures |
struct coap_pending * coap_pending_received | ( | const struct coap_packet * | response, |
struct coap_pending * | pendings, | ||
size_t | len ) |
#include <zephyr/net/coap.h>
After a response is received, returns if there is any matching pending request exits.
User has to clear all pending retransmissions related to that response by calling coap_pending_clear().
response | The received response |
pendings | Pointer to the array of coap_reply structures |
len | Size of the array of coap_reply structures |
void coap_pendings_clear | ( | struct coap_pending * | pendings, |
size_t | len ) |
#include <zephyr/net/coap.h>
Cancels all pending retransmissions, so they become available again.
pendings | Pointer to the array of coap_pending structures |
len | Size of the array of coap_pending structures |
size_t coap_pendings_count | ( | struct coap_pending * | pendings, |
size_t | len ) |
#include <zephyr/net/coap.h>
Count number of pending requests.
len | Number of elements in array. |
pendings | Array of pending requests. |
bool coap_register_observer | ( | struct coap_resource * | resource, |
struct coap_observer * | observer ) |
#include <zephyr/net/coap.h>
After the observer is initialized, associate the observer with an resource.
resource | Resource to add an observer |
observer | Observer to be added |
int coap_remove_descriptive_block_option | ( | struct coap_packet * | cpkt | ) |
#include <zephyr/net/coap.h>
Remove BLOCK1 or BLOCK2 option from the packet.
If the CoAP packet is a request then BLOCK1 is removed otherwise BLOCK2 is removed.
cpkt | Packet to be updated. |
bool coap_remove_observer | ( | struct coap_resource * | resource, |
struct coap_observer * | observer ) |
#include <zephyr/net/coap.h>
Remove this observer from the list of registered observers of that resource.
resource | Resource in which to remove the observer |
observer | Observer to be removed |
void coap_replies_clear | ( | struct coap_reply * | replies, |
size_t | len ) |
#include <zephyr/net/coap.h>
Cancels all replies, so they become available again.
replies | Pointer to the array of coap_reply structures |
len | Size of the array of coap_reply structures |
void coap_reply_clear | ( | struct coap_reply * | reply | ) |
#include <zephyr/net/coap.h>
Cancels awaiting for this reply, so it becomes available again.
User responsibility to free the memory associated with data.
reply | The reply to be canceled |
void coap_reply_init | ( | struct coap_reply * | reply, |
const struct coap_packet * | request ) |
#include <zephyr/net/coap.h>
Indicates that a reply is expected for request.
reply | Reply structure to be initialized |
request | Request from which reply will be based |
struct coap_reply * coap_reply_next_unused | ( | struct coap_reply * | replies, |
size_t | len ) |
#include <zephyr/net/coap.h>
Returns the next available reply struct, so it can be used to track replies and notifications received.
replies | Pointer to the array of coap_reply structures |
len | Size of the array of coap_reply structures |
bool coap_request_is_observe | ( | const struct coap_packet * | request | ) |
#include <zephyr/net/coap.h>
Returns if this request is enabling observing a resource.
request | Request to be checked |
int coap_resource_notify | ( | struct coap_resource * | resource | ) |
#include <zephyr/net/coap.h>
Indicates that this resource was updated and that the notify callback should be called for every registered observer.
resource | Resource that was updated |
struct coap_reply * coap_response_received | ( | const struct coap_packet * | response, |
const struct sockaddr * | from, | ||
struct coap_reply * | replies, | ||
size_t | len ) |
#include <zephyr/net/coap.h>
After a response is received, call coap_reply_t handler registered in coap_reply structure.
response | A response received |
from | Address from which the response was received |
replies | Pointer to the array of coap_reply structures |
len | Size of the array of coap_reply structures |
int coap_rst_init | ( | struct coap_packet * | cpkt, |
const struct coap_packet * | req, | ||
uint8_t * | data, | ||
uint16_t | max_len ) |
#include <zephyr/net/coap.h>
Create a new CoAP Reset message for given request.
This function works like coap_packet_init, filling CoAP header type, and CoAP header message id fields.
cpkt | New packet to be initialized using the storage from data. |
req | CoAP request packet that is being acknowledged |
data | Data that will contain a CoAP packet information |
max_len | Maximum allowable length of data |
void coap_set_transmission_parameters | ( | const struct coap_transmission_parameters * | params | ) |
#include <zephyr/net/coap.h>
Set CoAP transmission parameters.
params | Pointer to the transmission parameters structure. |
int coap_update_from_block | ( | const struct coap_packet * | cpkt, |
struct coap_block_context * | ctx ) |
#include <zephyr/net/coap.h>
Retrieves BLOCK{1,2} and SIZE{1,2} from cpkt and updates ctx accordingly.
cpkt | Packet in which to look for block-wise transfers options |
ctx | Block context to be updated |
bool coap_uri_path_match | ( | const char *const * | path, |
struct coap_option * | options, | ||
uint8_t | opt_num ) |
#include <zephyr/net/coap.h>
Verify if CoAP URI path matches with provided options.
path | Null-terminated array of strings. |
options | Parsed options from coap_packet_parse() |
opt_num | Number of options |
int coap_well_known_core_get | ( | struct coap_resource * | resource, |
const struct coap_packet * | request, | ||
struct coap_packet * | response, | ||
uint8_t * | data, | ||
uint16_t | data_len ) |
#include <zephyr/net/coap_link_format.h>
Build a CoAP response for a .well-known/core CoAP request.
resource | Array of known resources, terminated with an empty resource |
request | A pointer to the .well-known/core CoAP request |
response | A pointer to a CoAP response, will be initialized |
data | A data pointer to be used to build the CoAP response |
data_len | The maximum length of the data buffer |
int coap_well_known_core_get_len | ( | struct coap_resource * | resources, |
size_t | resources_len, | ||
const struct coap_packet * | request, | ||
struct coap_packet * | response, | ||
uint8_t * | data, | ||
uint16_t | data_len ) |
#include <zephyr/net/coap_link_format.h>
Build a CoAP response for a .well-known/core CoAP request.
resources | Array of known resources |
resources_len | Number of resources in the array |
request | A pointer to the .well-known/core CoAP request |
response | A pointer to a CoAP response, will be initialized |
data | A data pointer to be used to build the CoAP response |
data_len | The maximum length of the data buffer |