Zephyr Project API 3.7.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
COAP Library

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)   ((class << 5) | (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.
 

Enumerations

enum  coap_option_num {
  COAP_OPTION_IF_MATCH = 1 , COAP_OPTION_URI_HOST = 3 , COAP_OPTION_ETAG = 4 , COAP_OPTION_IF_NONE_MATCH = 5 ,
  COAP_OPTION_OBSERVE = 6 , COAP_OPTION_URI_PORT = 7 , COAP_OPTION_LOCATION_PATH = 8 , COAP_OPTION_URI_PATH = 11 ,
  COAP_OPTION_CONTENT_FORMAT = 12 , COAP_OPTION_MAX_AGE = 14 , COAP_OPTION_URI_QUERY = 15 , COAP_OPTION_ACCEPT = 17 ,
  COAP_OPTION_LOCATION_QUERY = 20 , COAP_OPTION_BLOCK2 = 23 , COAP_OPTION_BLOCK1 = 27 , COAP_OPTION_SIZE2 = 28 ,
  COAP_OPTION_PROXY_URI = 35 , COAP_OPTION_PROXY_SCHEME = 39 , COAP_OPTION_SIZE1 = 60 , COAP_OPTION_ECHO = 252 ,
  COAP_OPTION_REQUEST_TAG = 292
}
 Set of CoAP packet options we are aware of. More...
 
enum  coap_method {
  COAP_METHOD_GET = 1 , COAP_METHOD_POST = 2 , COAP_METHOD_PUT = 3 , COAP_METHOD_DELETE = 4 ,
  COAP_METHOD_FETCH = 5 , COAP_METHOD_PATCH = 6 , COAP_METHOD_IPATCH = 7
}
 Available request methods. More...
 
enum  coap_msgtype { COAP_TYPE_CON = 0 , COAP_TYPE_NON_CON = 1 , COAP_TYPE_ACK = 2 , COAP_TYPE_RESET = 3 }
 CoAP packets may be of one of these types. More...
 
enum  coap_response_code {
  COAP_RESPONSE_CODE_OK = (( 2 << 5) | ( 0 )) , COAP_RESPONSE_CODE_CREATED = (( 2 << 5) | ( 1 )) , COAP_RESPONSE_CODE_DELETED = (( 2 << 5) | ( 2 )) , COAP_RESPONSE_CODE_VALID = (( 2 << 5) | ( 3 )) ,
  COAP_RESPONSE_CODE_CHANGED = (( 2 << 5) | ( 4 )) , COAP_RESPONSE_CODE_CONTENT = (( 2 << 5) | ( 5 )) , COAP_RESPONSE_CODE_CONTINUE = (( 2 << 5) | ( 31 )) , COAP_RESPONSE_CODE_BAD_REQUEST = (( 4 << 5) | ( 0 )) ,
  COAP_RESPONSE_CODE_UNAUTHORIZED = (( 4 << 5) | ( 1 )) , COAP_RESPONSE_CODE_BAD_OPTION = (( 4 << 5) | ( 2 )) , COAP_RESPONSE_CODE_FORBIDDEN = (( 4 << 5) | ( 3 )) , COAP_RESPONSE_CODE_NOT_FOUND = (( 4 << 5) | ( 4 )) ,
  COAP_RESPONSE_CODE_NOT_ALLOWED = (( 4 << 5) | ( 5 )) , COAP_RESPONSE_CODE_NOT_ACCEPTABLE = (( 4 << 5) | ( 6 )) , COAP_RESPONSE_CODE_INCOMPLETE = (( 4 << 5) | ( 8 )) , COAP_RESPONSE_CODE_CONFLICT = (( 4 << 5) | ( 9 )) ,
  COAP_RESPONSE_CODE_PRECONDITION_FAILED = (( 4 << 5) | ( 12 )) , COAP_RESPONSE_CODE_REQUEST_TOO_LARGE = (( 4 << 5) | ( 13 )) , COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT , COAP_RESPONSE_CODE_UNPROCESSABLE_ENTITY = (( 4 << 5) | ( 22 )) ,
  COAP_RESPONSE_CODE_TOO_MANY_REQUESTS = (( 4 << 5) | ( 29 )) , COAP_RESPONSE_CODE_INTERNAL_ERROR = (( 5 << 5) | ( 0 )) , COAP_RESPONSE_CODE_NOT_IMPLEMENTED = (( 5 << 5) | ( 1 )) , COAP_RESPONSE_CODE_BAD_GATEWAY = (( 5 << 5) | ( 2 )) ,
  COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE = (( 5 << 5) | ( 3 )) , COAP_RESPONSE_CODE_GATEWAY_TIMEOUT = (( 5 << 5) | ( 4 )) , COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED
}
 Set of response codes available for a response packet. More...
 
enum  coap_content_format {
  COAP_CONTENT_FORMAT_TEXT_PLAIN = 0 , COAP_CONTENT_FORMAT_APP_LINK_FORMAT = 40 , COAP_CONTENT_FORMAT_APP_XML = 41 , COAP_CONTENT_FORMAT_APP_OCTET_STREAM = 42 ,
  COAP_CONTENT_FORMAT_APP_EXI = 47 , COAP_CONTENT_FORMAT_APP_JSON = 50 , COAP_CONTENT_FORMAT_APP_JSON_PATCH_JSON = 51 , COAP_CONTENT_FORMAT_APP_MERGE_PATCH_JSON = 52 ,
  COAP_CONTENT_FORMAT_APP_CBOR = 60
}
 Set of Content-Format option values for CoAP. More...
 
enum  coap_block_size {
  COAP_BLOCK_16 , COAP_BLOCK_32 , COAP_BLOCK_64 , COAP_BLOCK_128 ,
  COAP_BLOCK_256 , COAP_BLOCK_512 , COAP_BLOCK_1024
}
 Represents the size of each block that will be transferred using block-wise transfers [RFC7959]: More...
 

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_tcoap_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_tcoap_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_observercoap_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_observercoap_find_observer_by_addr (struct coap_observer *observers, size_t len, const struct sockaddr *addr)
 Returns the observer that matches address addr.
 
struct coap_observercoap_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_observercoap_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_pendingcoap_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_replycoap_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_pendingcoap_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_replycoap_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_pendingcoap_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.
 

Detailed Description

COAP library.

Since
1.10
Version
0.8.0

Macro Definition Documentation

◆ COAP_MAKE_RESPONSE_CODE

#define COAP_MAKE_RESPONSE_CODE (   class,
  det 
)    ((class << 5) | (det))

#include <include/zephyr/net/coap.h>

Utility macro to create a CoAP response code.

Parameters
classClass of the response code (ex. 2, 4, 5, ...)
detDetail of the response code
Returns
Response code literal

◆ COAP_WELL_KNOWN_CORE_PATH

#define COAP_WELL_KNOWN_CORE_PATH    ((const char * const[]) { ".well-known", "core", NULL })

#include <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 Documentation

◆ coap_method_t

coap_method_t

#include <include/zephyr/net/coap.h>

Type of the callback being called when a resource's method is invoked by the remote entity.

◆ coap_notify_t

coap_notify_t

#include <include/zephyr/net/coap.h>

Type of the callback being called when a resource's has observers to be informed when an update happens.

◆ coap_reply_t

coap_reply_t

#include <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).

Enumeration Type Documentation

◆ coap_block_size

#include <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

Enumerator
COAP_BLOCK_16 

16-byte block size

COAP_BLOCK_32 

32-byte block size

COAP_BLOCK_64 

64-byte block size

COAP_BLOCK_128 

128-byte block size

COAP_BLOCK_256 

256-byte block size

COAP_BLOCK_512 

512-byte block size

COAP_BLOCK_1024 

1024-byte block size

◆ coap_content_format

#include <include/zephyr/net/coap.h>

Set of Content-Format option values for CoAP.

To be used when encoding or decoding a Content-Format option.

Enumerator
COAP_CONTENT_FORMAT_TEXT_PLAIN 

text/plain;charset=utf-8

COAP_CONTENT_FORMAT_APP_LINK_FORMAT 

application/link-format

COAP_CONTENT_FORMAT_APP_XML 

application/xml

COAP_CONTENT_FORMAT_APP_OCTET_STREAM 

application/octet-stream

COAP_CONTENT_FORMAT_APP_EXI 

application/exi

COAP_CONTENT_FORMAT_APP_JSON 

application/json

COAP_CONTENT_FORMAT_APP_JSON_PATCH_JSON 

application/json-patch+json

COAP_CONTENT_FORMAT_APP_MERGE_PATCH_JSON 

application/merge-patch+json

COAP_CONTENT_FORMAT_APP_CBOR 

application/cbor

◆ coap_method

#include <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.

◆ coap_msgtype

#include <include/zephyr/net/coap.h>

CoAP packets may be of one of these types.

Enumerator
COAP_TYPE_CON 

Confirmable message.

The packet is a request or response the destination end-point must acknowledge.

COAP_TYPE_NON_CON 

Non-confirmable message.

The packet is a request or response that doesn't require acknowledgements.

COAP_TYPE_ACK 

Acknowledge.

Response to a confirmable message.

COAP_TYPE_RESET 

Reset.

Rejecting a packet for any reason is done by sending a message of this type.

◆ coap_option_num

#include <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.

Enumerator
COAP_OPTION_IF_MATCH 

If-Match.

COAP_OPTION_URI_HOST 

Uri-Host.

COAP_OPTION_ETAG 

ETag.

COAP_OPTION_IF_NONE_MATCH 

If-None-Match.

COAP_OPTION_OBSERVE 

Observe (RFC 7641)

COAP_OPTION_URI_PORT 

Uri-Port.

COAP_OPTION_LOCATION_PATH 

Location-Path.

COAP_OPTION_URI_PATH 

Uri-Path.

COAP_OPTION_CONTENT_FORMAT 

Content-Format.

COAP_OPTION_MAX_AGE 

Max-Age.

COAP_OPTION_URI_QUERY 

Uri-Query.

COAP_OPTION_ACCEPT 

Accept.

COAP_OPTION_LOCATION_QUERY 

Location-Query.

COAP_OPTION_BLOCK2 

Block2 (RFC 7959)

COAP_OPTION_BLOCK1 

Block1 (RFC 7959)

COAP_OPTION_SIZE2 

Size2 (RFC 7959)

COAP_OPTION_PROXY_URI 

Proxy-Uri.

COAP_OPTION_PROXY_SCHEME 

Proxy-Scheme.

COAP_OPTION_SIZE1 

Size1.

COAP_OPTION_ECHO 

Echo (RFC 9175)

COAP_OPTION_REQUEST_TAG 

Request-Tag (RFC 9175)

◆ coap_response_code

#include <include/zephyr/net/coap.h>

Set of response codes available for a response packet.

To be used when creating a response.

Enumerator
COAP_RESPONSE_CODE_OK 

2.00 - OK

COAP_RESPONSE_CODE_CREATED 

2.01 - Created

COAP_RESPONSE_CODE_DELETED 

2.02 - Deleted

COAP_RESPONSE_CODE_VALID 

2.03 - Valid

COAP_RESPONSE_CODE_CHANGED 

2.04 - Changed

COAP_RESPONSE_CODE_CONTENT 

2.05 - Content

COAP_RESPONSE_CODE_CONTINUE 

2.31 - Continue

COAP_RESPONSE_CODE_BAD_REQUEST 

4.00 - Bad Request

COAP_RESPONSE_CODE_UNAUTHORIZED 

4.01 - Unauthorized

COAP_RESPONSE_CODE_BAD_OPTION 

4.02 - Bad Option

COAP_RESPONSE_CODE_FORBIDDEN 

4.03 - Forbidden

COAP_RESPONSE_CODE_NOT_FOUND 

4.04 - Not Found

COAP_RESPONSE_CODE_NOT_ALLOWED 

4.05 - Method Not Allowed

COAP_RESPONSE_CODE_NOT_ACCEPTABLE 

4.06 - Not Acceptable

COAP_RESPONSE_CODE_INCOMPLETE 

4.08 - Request Entity Incomplete

COAP_RESPONSE_CODE_CONFLICT 

4.12 - Precondition Failed

COAP_RESPONSE_CODE_PRECONDITION_FAILED 

4.12 - Precondition Failed

COAP_RESPONSE_CODE_REQUEST_TOO_LARGE 

4.13 - Request Entity Too Large

COAP_RESPONSE_CODE_UNSUPPORTED_CONTENT_FORMAT 

4.15 - Unsupported Content-Format

COAP_RESPONSE_CODE_UNPROCESSABLE_ENTITY 

4.22 - Unprocessable Entity

COAP_RESPONSE_CODE_TOO_MANY_REQUESTS 

4.29 - Too Many Requests

COAP_RESPONSE_CODE_INTERNAL_ERROR 

5.00 - Internal Server Error

COAP_RESPONSE_CODE_NOT_IMPLEMENTED 

5.01 - Not Implemented

COAP_RESPONSE_CODE_BAD_GATEWAY 

5.02 - Bad Gateway

COAP_RESPONSE_CODE_SERVICE_UNAVAILABLE 

5.03 - Service Unavailable

COAP_RESPONSE_CODE_GATEWAY_TIMEOUT 

5.04 - Gateway Timeout

COAP_RESPONSE_CODE_PROXYING_NOT_SUPPORTED 

5.05 - Proxying Not Supported

Function Documentation

◆ coap_ack_init()

int coap_ack_init ( struct coap_packet cpkt,
const struct coap_packet req,
uint8_t data,
uint16_t  max_len,
uint8_t  code 
)

#include <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.

Parameters
cpktNew packet to be initialized using the storage from data.
reqCoAP request packet that is being acknowledged
dataData that will contain a CoAP packet information
max_lenMaximum allowable length of data
codeCoAP header code
Returns
0 in case of success or negative in case of error.

◆ coap_append_block1_option()

int coap_append_block1_option ( struct coap_packet cpkt,
struct coap_block_context ctx 
)

#include <include/zephyr/net/coap.h>

Append BLOCK1 option to the packet.

Parameters
cpktPacket to be updated
ctxBlock context from which to retrieve the information for the Block1 option
Returns
0 in case of success or negative in case of error.

◆ coap_append_block2_option()

int coap_append_block2_option ( struct coap_packet cpkt,
struct coap_block_context ctx 
)

#include <include/zephyr/net/coap.h>

Append BLOCK2 option to the packet.

Parameters
cpktPacket to be updated
ctxBlock context from which to retrieve the information for the Block2 option
Returns
0 in case of success or negative in case of error.

◆ coap_append_descriptive_block_option()

int coap_append_descriptive_block_option ( struct coap_packet cpkt,
struct coap_block_context ctx 
)

#include <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.

Parameters
cpktPacket to be updated
ctxBlock context from which to retrieve the information for the block option
Returns
0 in case of success or negative in case of error.

◆ coap_append_option_int()

int coap_append_option_int ( struct coap_packet cpkt,
uint16_t  code,
unsigned int  val 
)

#include <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.

Parameters
cpktPacket to be updated
codeOption code to add to the packet, see coap_option_num
valInteger value to be added
Returns
0 in case of success or negative in case of error.

◆ coap_append_size1_option()

int coap_append_size1_option ( struct coap_packet cpkt,
struct coap_block_context ctx 
)

#include <include/zephyr/net/coap.h>

Append SIZE1 option to the packet.

Parameters
cpktPacket to be updated
ctxBlock context from which to retrieve the information for the Size1 option
Returns
0 in case of success or negative in case of error.

◆ coap_append_size2_option()

int coap_append_size2_option ( struct coap_packet cpkt,
struct coap_block_context ctx 
)

#include <include/zephyr/net/coap.h>

Append SIZE2 option to the packet.

Parameters
cpktPacket to be updated
ctxBlock context from which to retrieve the information for the Size2 option
Returns
0 in case of success or negative in case of error.

◆ coap_block_has_more()

bool coap_block_has_more ( struct coap_packet cpkt)

#include <include/zephyr/net/coap.h>

Check if BLOCK1 or BLOCK2 option has more flag set.

Parameters
cpktPacket to be checked.
Returns
true If more flag is set in BLOCK1 or BLOCK2
false If MORE flag is not set or BLOCK header not found.

◆ coap_block_size_to_bytes()

static uint16_t coap_block_size_to_bytes ( enum coap_block_size  block_size)
inlinestatic

#include <include/zephyr/net/coap.h>

Helper for converting the enumeration to the size expressed in bytes.

Parameters
block_sizeThe block size to be converted
Returns
The size in bytes that the block_size represents

◆ coap_block_transfer_init()

int coap_block_transfer_init ( struct coap_block_context ctx,
enum coap_block_size  block_size,
size_t  total_size 
)

#include <include/zephyr/net/coap.h>

Initializes the context of a block-wise transfer.

Parameters
ctxThe context to be initialized
block_sizeThe size of the block
total_sizeThe total size of the transfer, if known
Returns
0 in case of success or negative in case of error.

◆ coap_bytes_to_block_size()

static enum coap_block_size coap_bytes_to_block_size ( uint16_t  bytes)
inlinestatic

#include <include/zephyr/net/coap.h>

Helper for converting block size in bytes to enumeration.

NOTE: Only valid CoAP block sizes map correctly.

Parameters
bytesCoAP block size in bytes.
Returns
enum coap_block_size

◆ coap_find_observer()

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 <include/zephyr/net/coap.h>

Returns the observer that matches address addr and has token token.

Parameters
observersPointer to the array of observers
lenSize of the array of observers
addrAddress of the endpoint observing a resource
tokenPointer to the token
token_lenLength of valid bytes in the token
Returns
A pointer to a observer if a match is found, NULL otherwise.

◆ coap_find_observer_by_addr()

struct coap_observer * coap_find_observer_by_addr ( struct coap_observer observers,
size_t  len,
const struct sockaddr addr 
)

#include <include/zephyr/net/coap.h>

Returns the observer that matches address addr.

Parameters
observersPointer to the array of observers
lenSize of the array of observers
addrAddress of the endpoint observing a resource
Note
The function coap_find_observer() should be preferred if both the observer's address and token are known.
Returns
A pointer to a observer if a match is found, NULL otherwise.

◆ coap_find_observer_by_token()

struct coap_observer * coap_find_observer_by_token ( struct coap_observer observers,
size_t  len,
const uint8_t token,
uint8_t  token_len 
)

#include <include/zephyr/net/coap.h>

Returns the observer that has token token.

Parameters
observersPointer to the array of observers
lenSize of the array of observers
tokenPointer to the token
token_lenLength of valid bytes in the token
Note
The function coap_find_observer() should be preferred if both the observer's address and token are known.
Returns
A pointer to a observer if a match is found, NULL otherwise.

◆ coap_find_options()

int coap_find_options ( const struct coap_packet cpkt,
uint16_t  code,
struct coap_option options,
uint16_t  veclen 
)

#include <include/zephyr/net/coap.h>

Return the values associated with the option of value code.

Parameters
cpktCoAP packet representation
codeOption number to look for
optionsArray of coap_option where to store the value of the options found
veclenNumber of elements in the options array
Returns
The number of options found in packet matching code, negative on error.

◆ coap_get_block1_option()

int coap_get_block1_option ( const struct coap_packet cpkt,
bool has_more,
uint32_t block_number 
)

#include <include/zephyr/net/coap.h>

Get the block size, more flag and block number from the CoAP block1 option.

Parameters
cpktPacket to be inspected
has_moreIs set to the value of the more flag
block_numberIs set to the number of the block
Returns
Integer value of the block size in case of success or negative in case of error.

◆ coap_get_block2_option()

int coap_get_block2_option ( const struct coap_packet cpkt,
bool has_more,
uint32_t block_number 
)

#include <include/zephyr/net/coap.h>

Get values from CoAP block2 option.

Decode block number, more flag and block size from option.

Parameters
cpktPacket to be inspected
has_moreIs set to the value of the more flag
block_numberIs set to the number of the block
Returns
Integer value of the block size in case of success or negative in case of error.

◆ coap_get_option_int()

int coap_get_option_int ( const struct coap_packet cpkt,
uint16_t  code 
)

#include <include/zephyr/net/coap.h>

Get the integer representation of a CoAP option.

Parameters
cpktPacket to be inspected
codeCoAP option code
Returns
Integer value >= 0 in case of success or negative in case of error.

◆ coap_get_transmission_parameters()

struct coap_transmission_parameters coap_get_transmission_parameters ( void  )

#include <include/zephyr/net/coap.h>

Get currently active CoAP transmission parameters.

Returns
CoAP transmission parameters structure.

◆ coap_handle_request()

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 <include/zephyr/net/coap.h>

When a request is received, call the appropriate methods of the matching resources.

Parameters
cpktPacket received
resourcesArray of known resources (terminated with empty resource)
optionsParsed options from coap_packet_parse()
opt_numNumber of options
addrPeer address
addr_lenPeer address length
Return values
>=0 in case of success.
-ENOTSUPin case of invalid request code.
-EPERMin case resource handler is not implemented.
-ENOENTin case the resource is not found.

◆ coap_handle_request_len()

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 <include/zephyr/net/coap.h>

When a request is received, call the appropriate methods of the matching resources.

Parameters
cpktPacket received
resourcesArray of known resources
resources_lenNumber of resources in the array
optionsParsed options from coap_packet_parse()
opt_numNumber of options
addrPeer address
addr_lenPeer address length
Return values
>=0 in case of success.
-ENOTSUPin case of invalid request code.
-EPERMin case resource handler is not implemented.
-ENOENTin case the resource is not found.

◆ coap_has_descriptive_block_option()

bool coap_has_descriptive_block_option ( struct coap_packet cpkt)

#include <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.

Parameters
cpktPacket to be checked.
Returns
true if the corresponding block option is set, false otherwise.

◆ coap_header_get_code()

uint8_t coap_header_get_code ( const struct coap_packet cpkt)

#include <include/zephyr/net/coap.h>

Returns the code of the CoAP packet.

Parameters
cpktCoAP packet representation
Returns
the code present in the packet

◆ coap_header_get_id()

uint16_t coap_header_get_id ( const struct coap_packet cpkt)

#include <include/zephyr/net/coap.h>

Returns the message id associated with the CoAP packet.

Parameters
cpktCoAP packet representation
Returns
the message id present in the packet

◆ coap_header_get_token()

uint8_t coap_header_get_token ( const struct coap_packet cpkt,
uint8_t token 
)

#include <include/zephyr/net/coap.h>

Returns the token (if any) in the CoAP packet.

Parameters
cpktCoAP packet representation
tokenWhere to store the token, must point to a buffer containing at least COAP_TOKEN_MAX_LEN bytes
Returns
Token length in the CoAP packet (0 - COAP_TOKEN_MAX_LEN).

◆ coap_header_get_type()

uint8_t coap_header_get_type ( const struct coap_packet cpkt)

#include <include/zephyr/net/coap.h>

Returns the type of the CoAP packet.

Parameters
cpktCoAP packet representation
Returns
the type of the packet

◆ coap_header_get_version()

uint8_t coap_header_get_version ( const struct coap_packet cpkt)

#include <include/zephyr/net/coap.h>

Returns the version present in a CoAP packet.

Parameters
cpktCoAP packet representation
Returns
the CoAP version in packet

◆ coap_header_set_code()

int coap_header_set_code ( const struct coap_packet cpkt,
uint8_t  code 
)

#include <include/zephyr/net/coap.h>

Modifies the code of the CoAP packet.

Parameters
cpktCoAP packet representation
codeCoAP code
Returns
0 on success, -EINVAL on failure

◆ coap_next_block()

size_t coap_next_block ( const struct coap_packet cpkt,
struct coap_block_context ctx 
)

#include <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.

Parameters
cpktPacket in which to look for block-wise transfers options
ctxBlock context to be updated
Returns
The offset in the block-wise transfer, 0 if the transfer has finished.

◆ coap_next_block_for_option()

int coap_next_block_for_option ( const struct coap_packet cpkt,
struct coap_block_context ctx,
enum coap_option_num  option 
)

#include <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.

Parameters
cpktPacket in which to look for block-wise transfers options
ctxBlock context to be updated
optionEither COAP_OPTION_BLOCK1 or COAP_OPTION_BLOCK2
Returns
The offset in the block-wise transfer, 0 if the transfer has finished or a negative value in case of an error.

◆ coap_next_id()

uint16_t coap_next_id ( void  )

#include <include/zephyr/net/coap.h>

Helper to generate message ids.

Returns
a new message id

◆ coap_next_token()

uint8_t * coap_next_token ( void  )

#include <include/zephyr/net/coap.h>

Returns a randomly generated array of 8 bytes, that can be used as a message's token.

Returns
a 8-byte pseudo-random token.

◆ coap_observer_init()

void coap_observer_init ( struct coap_observer observer,
const struct coap_packet request,
const struct sockaddr addr 
)

#include <include/zephyr/net/coap.h>

Indicates that the remote device referenced by addr, with request, wants to observe a resource.

Parameters
observerObserver to be initialized
requestRequest on which the observer will be based
addrAddress of the remote device

◆ coap_observer_next_unused()

struct coap_observer * coap_observer_next_unused ( struct coap_observer observers,
size_t  len 
)

#include <include/zephyr/net/coap.h>

Returns the next available observer representation.

Parameters
observersPointer to the array of observers
lenSize of the array of observers
Returns
A pointer to a observer if there's an available observer, NULL otherwise.

◆ coap_option_value_to_int()

unsigned int coap_option_value_to_int ( const struct coap_option option)

#include <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.

Parameters
optionPointer to the option value, retrieved by coap_find_options()
Returns
The integer representation of the option

◆ coap_packet_append_option()

int coap_packet_append_option ( struct coap_packet cpkt,
uint16_t  code,
const uint8_t value,
uint16_t  len 
)

#include <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.

Parameters
cpktPacket to be updated
codeOption code to add to the packet, see coap_option_num
valuePointer to the value of the option, will be copied to the packet
lenSize of the data to be added
Returns
0 in case of success or negative in case of error.

◆ coap_packet_append_payload()

int coap_packet_append_payload ( struct coap_packet cpkt,
const uint8_t payload,
uint16_t  payload_len 
)

#include <include/zephyr/net/coap.h>

Append payload to CoAP packet.

Parameters
cpktPacket to append the payload
payloadCoAP packet payload
payload_lenCoAP packet payload len
Returns
0 in case of success or negative in case of error.

◆ coap_packet_append_payload_marker()

int coap_packet_append_payload_marker ( struct coap_packet cpkt)

#include <include/zephyr/net/coap.h>

Append payload marker to CoAP packet.

Parameters
cpktPacket to append the payload marker (0xFF)
Returns
0 in case of success or negative in case of error.

◆ coap_packet_get_payload()

const uint8_t * coap_packet_get_payload ( const struct coap_packet cpkt,
uint16_t len 
)

#include <include/zephyr/net/coap.h>

Returns the data pointer and length of the CoAP packet.

Parameters
cpktCoAP packet representation
lenTotal length of CoAP payload
Returns
data pointer and length if payload exists NULL pointer and length set to 0 in case there is no payload

◆ coap_packet_init()

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 <include/zephyr/net/coap.h>

Creates a new CoAP Packet from input data.

Parameters
cpktNew packet to be initialized using the storage from data.
dataData that will contain a CoAP packet information
max_lenMaximum allowable length of data
verCoAP header version
typeCoAP header type
token_lenCoAP header token length
tokenCoAP header token
codeCoAP header code
idCoAP header message id
Returns
0 in case of success or negative in case of error.

◆ coap_packet_is_request()

bool coap_packet_is_request ( const struct coap_packet cpkt)

#include <include/zephyr/net/coap.h>

Check if a CoAP packet is a CoAP request.

Parameters
cpktPacket to be checked.
Returns
true if the packet is a request, false otherwise.

◆ coap_packet_parse()

int coap_packet_parse ( struct coap_packet cpkt,
uint8_t data,
uint16_t  len,
struct coap_option options,
uint8_t  opt_num 
)

#include <include/zephyr/net/coap.h>

Parses the CoAP packet in data, validating it and initializing cpkt.

data must remain valid while cpkt is used.

Parameters
cpktPacket to be initialized from received data.
dataData containing a CoAP packet, its data pointer is positioned on the start of the CoAP packet.
lenLength of the data
optionsParse options and cache its details.
opt_numNumber of options
Return values
0in case of success.
-EINVALin case of invalid input args.
-EBADMSGin case of malformed coap packet header.
-EILSEQin case of malformed coap options.

◆ coap_packet_remove_option()

int coap_packet_remove_option ( struct coap_packet cpkt,
uint16_t  code 
)

#include <include/zephyr/net/coap.h>

Remove an option from the packet.

Parameters
cpktPacket to be updated
codeOption code to remove from the packet, see coap_option_num
Returns
0 in case of success or negative in case of error.

◆ coap_packet_set_path()

int coap_packet_set_path ( struct coap_packet cpkt,
const char *  path 
)

#include <include/zephyr/net/coap.h>

Parses provided coap path (with/without query) or query and appends that as options to the cpkt.

Parameters
cpktPacket to append path and query options for.
pathNull-terminated string of coap path, query or both.
Return values
0in case of success or negative in case of error.

◆ coap_pending_clear()

void coap_pending_clear ( struct coap_pending pending)

#include <include/zephyr/net/coap.h>

Cancels the pending retransmission, so it again becomes available.

Parameters
pendingPending representation to be canceled

◆ coap_pending_cycle()

bool coap_pending_cycle ( struct coap_pending pending)

#include <include/zephyr/net/coap.h>

After a request is sent, user may want to cycle the pending retransmission so the timeout is updated.

Parameters
pendingPending representation to have its timeout updated
Returns
false if this is the last retransmission.

◆ coap_pending_init()

int coap_pending_init ( struct coap_pending pending,
const struct coap_packet request,
const struct sockaddr addr,
const struct coap_transmission_parameters params 
)

#include <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.

Parameters
pendingStructure representing the waiting for a confirmation message, initialized with data from request
requestMessage waiting for confirmation
addrAddress to send the retransmission
paramsPointer to the CoAP transmission parameters struct, or NULL to use default values
Returns
0 in case of success or negative in case of error.

◆ coap_pending_next_to_expire()

struct coap_pending * coap_pending_next_to_expire ( struct coap_pending pendings,
size_t  len 
)

#include <include/zephyr/net/coap.h>

Returns the next pending about to expire, pending->timeout informs how many ms to next expiration.

Parameters
pendingsPointer to the array of coap_pending structures
lenSize of the array of coap_pending structures
Returns
The next coap_pending to expire, NULL if none is about to expire.

◆ coap_pending_next_unused()

struct coap_pending * coap_pending_next_unused ( struct coap_pending pendings,
size_t  len 
)

#include <include/zephyr/net/coap.h>

Returns the next available pending struct, that can be used to track the retransmission status of a request.

Parameters
pendingsPointer to the array of coap_pending structures
lenSize of the array of coap_pending structures
Returns
pointer to a free coap_pending structure, NULL in case none could be found.

◆ coap_pending_received()

struct coap_pending * coap_pending_received ( const struct coap_packet response,
struct coap_pending pendings,
size_t  len 
)

#include <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().

Parameters
responseThe received response
pendingsPointer to the array of coap_reply structures
lenSize of the array of coap_reply structures
Returns
pointer to the associated coap_pending structure, NULL in case none could be found.

◆ coap_pendings_clear()

void coap_pendings_clear ( struct coap_pending pendings,
size_t  len 
)

#include <include/zephyr/net/coap.h>

Cancels all pending retransmissions, so they become available again.

Parameters
pendingsPointer to the array of coap_pending structures
lenSize of the array of coap_pending structures

◆ coap_pendings_count()

size_t coap_pendings_count ( struct coap_pending pendings,
size_t  len 
)

#include <include/zephyr/net/coap.h>

Count number of pending requests.

Parameters
lenNumber of elements in array.
pendingsArray of pending requests.
Returns
count of elements where timeout is not zero.

◆ coap_register_observer()

bool coap_register_observer ( struct coap_resource resource,
struct coap_observer observer 
)

#include <include/zephyr/net/coap.h>

After the observer is initialized, associate the observer with an resource.

Parameters
resourceResource to add an observer
observerObserver to be added
Returns
true if this is the first observer added to this resource.

◆ coap_remove_descriptive_block_option()

int coap_remove_descriptive_block_option ( struct coap_packet cpkt)

#include <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.

Parameters
cpktPacket to be updated.
Returns
0 in case of success or negative in case of error.

◆ coap_remove_observer()

bool coap_remove_observer ( struct coap_resource resource,
struct coap_observer observer 
)

#include <include/zephyr/net/coap.h>

Remove this observer from the list of registered observers of that resource.

Parameters
resourceResource in which to remove the observer
observerObserver to be removed
Returns
true if the observer was found and removed.

◆ coap_replies_clear()

void coap_replies_clear ( struct coap_reply replies,
size_t  len 
)

#include <include/zephyr/net/coap.h>

Cancels all replies, so they become available again.

Parameters
repliesPointer to the array of coap_reply structures
lenSize of the array of coap_reply structures

◆ coap_reply_clear()

void coap_reply_clear ( struct coap_reply reply)

#include <include/zephyr/net/coap.h>

Cancels awaiting for this reply, so it becomes available again.

User responsibility to free the memory associated with data.

Parameters
replyThe reply to be canceled

◆ coap_reply_init()

void coap_reply_init ( struct coap_reply reply,
const struct coap_packet request 
)

#include <include/zephyr/net/coap.h>

Indicates that a reply is expected for request.

Parameters
replyReply structure to be initialized
requestRequest from which reply will be based

◆ coap_reply_next_unused()

struct coap_reply * coap_reply_next_unused ( struct coap_reply replies,
size_t  len 
)

#include <include/zephyr/net/coap.h>

Returns the next available reply struct, so it can be used to track replies and notifications received.

Parameters
repliesPointer to the array of coap_reply structures
lenSize of the array of coap_reply structures
Returns
pointer to a free coap_reply structure, NULL in case none could be found.

◆ coap_request_is_observe()

bool coap_request_is_observe ( const struct coap_packet request)

#include <include/zephyr/net/coap.h>

Returns if this request is enabling observing a resource.

Parameters
requestRequest to be checked
Returns
True if the request is enabling observing a resource, False otherwise

◆ coap_resource_notify()

int coap_resource_notify ( struct coap_resource resource)

#include <include/zephyr/net/coap.h>

Indicates that this resource was updated and that the notify callback should be called for every registered observer.

Parameters
resourceResource that was updated
Returns
0 in case of success or negative in case of error.

◆ coap_response_received()

struct coap_reply * coap_response_received ( const struct coap_packet response,
const struct sockaddr from,
struct coap_reply replies,
size_t  len 
)

#include <include/zephyr/net/coap.h>

After a response is received, call coap_reply_t handler registered in coap_reply structure.

Parameters
responseA response received
fromAddress from which the response was received
repliesPointer to the array of coap_reply structures
lenSize of the array of coap_reply structures
Returns
Pointer to the reply matching the packet received, NULL if none could be found.

◆ coap_set_transmission_parameters()

void coap_set_transmission_parameters ( const struct coap_transmission_parameters params)

#include <include/zephyr/net/coap.h>

Set CoAP transmission parameters.

Parameters
paramsPointer to the transmission parameters structure.

◆ coap_update_from_block()

int coap_update_from_block ( const struct coap_packet cpkt,
struct coap_block_context ctx 
)

#include <include/zephyr/net/coap.h>

Retrieves BLOCK{1,2} and SIZE{1,2} from cpkt and updates ctx accordingly.

Parameters
cpktPacket in which to look for block-wise transfers options
ctxBlock context to be updated
Returns
0 in case of success or negative in case of error.

◆ coap_uri_path_match()

bool coap_uri_path_match ( const char *const *  path,
struct coap_option options,
uint8_t  opt_num 
)

#include <include/zephyr/net/coap.h>

Verify if CoAP URI path matches with provided options.

Parameters
pathNull-terminated array of strings.
optionsParsed options from coap_packet_parse()
opt_numNumber of options
Returns
true if the CoAP URI path matches, false otherwise.

◆ coap_well_known_core_get()

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 <include/zephyr/net/coap_link_format.h>

Build a CoAP response for a .well-known/core CoAP request.

Parameters
resourceArray of known resources, terminated with an empty resource
requestA pointer to the .well-known/core CoAP request
responseA pointer to a CoAP response, will be initialized
dataA data pointer to be used to build the CoAP response
data_lenThe maximum length of the data buffer
Returns
0 in case of success or negative in case of error.

◆ coap_well_known_core_get_len()

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 <include/zephyr/net/coap_link_format.h>

Build a CoAP response for a .well-known/core CoAP request.

Parameters
resourcesArray of known resources
resources_lenNumber of resources in the array
requestA pointer to the .well-known/core CoAP request
responseA pointer to a CoAP response, will be initialized
dataA data pointer to be used to build the CoAP response
data_lenThe maximum length of the data buffer
Returns
0 in case of success or negative in case of error.