Zephyr API Documentation
3.6.99
A Scalable Open Source RTOS
|
CoAP implementation for Zephyr. More...
#include <zephyr/types.h>
#include <stddef.h>
#include <stdbool.h>
#include <zephyr/net/net_ip.h>
#include <zephyr/sys/math_extras.h>
#include <zephyr/sys/slist.h>
Go to the source code of this file.
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... | |
Macros | |
#define | COAP_MAKE_RESPONSE_CODE(class, det) ((class << 5) | (det)) |
Utility macro to create a CoAP response code. | |
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. | |
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, uint8_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, uint8_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. | |
CoAP implementation for Zephyr.