Zephyr Project API 3.7.0
A Scalable Open Source RTOS
|
CoAP Service API. More...
Macros | |
#define | COAP_RESOURCE_DEFINE(_name, _service, ...) |
Define a static CoAP resource owned by the service named _service . | |
#define | COAP_SERVICE_DEFINE(_name, _host, _port, _flags) |
Define a CoAP service with static resources. | |
#define | COAP_SERVICE_COUNT(_dst) STRUCT_SECTION_COUNT(coap_service, _dst) |
Count the number of CoAP services. | |
#define | COAP_SERVICE_RESOURCE_COUNT(_service) ((_service)->res_end - (_service)->res_begin) |
Count CoAP service static resources. | |
#define | COAP_SERVICE_HAS_RESOURCE(_service, _resource) ((_service)->res_begin <= _resource && _resource < (_service)->res_end) |
Check if service has the specified resource. | |
#define | COAP_SERVICE_FOREACH(_it) STRUCT_SECTION_FOREACH(coap_service, _it) |
Iterate over all CoAP services. | |
#define | COAP_RESOURCE_FOREACH(_service, _it) STRUCT_SECTION_FOREACH_ALTERNATE(coap_resource_##_service, coap_resource, _it) |
Iterate over static CoAP resources associated with a given _service . | |
#define | COAP_SERVICE_FOREACH_RESOURCE(_service, _it) |
Iterate over all static resources associated with _service . | |
Functions | |
int | coap_service_start (const struct coap_service *service) |
Start the provided service . | |
int | coap_service_stop (const struct coap_service *service) |
Stop the provided service . | |
int | coap_service_is_running (const struct coap_service *service) |
Query the provided service running state. | |
int | coap_service_send (const struct coap_service *service, const struct coap_packet *cpkt, const struct sockaddr *addr, socklen_t addr_len, const struct coap_transmission_parameters *params) |
Send a CoAP message from the provided service . | |
int | coap_resource_send (const struct coap_resource *resource, const struct coap_packet *cpkt, const struct sockaddr *addr, socklen_t addr_len, const struct coap_transmission_parameters *params) |
Send a CoAP message from the provided resource . | |
int | coap_resource_parse_observe (struct coap_resource *resource, const struct coap_packet *request, const struct sockaddr *addr) |
Parse a CoAP observe request for the provided resource . | |
int | coap_resource_remove_observer_by_addr (struct coap_resource *resource, const struct sockaddr *addr) |
Lookup an observer by address and remove it from the resource . | |
int | coap_resource_remove_observer_by_token (struct coap_resource *resource, const uint8_t *token, uint8_t token_len) |
Lookup an observer by token and remove it from the resource . | |
CoAP Service configuration flags | |
#define | COAP_SERVICE_AUTOSTART BIT(0) |
Start the service on boot. | |
CoAP Service API.
#define COAP_RESOURCE_DEFINE | ( | _name, | |
_service, | |||
... | |||
) |
#include <include/zephyr/net/coap_service.h>
Define a static CoAP resource owned by the service named _service
.
_name | Name of the resource. |
_service | Name of the associated service. |
#define COAP_RESOURCE_FOREACH | ( | _service, | |
_it | |||
) | STRUCT_SECTION_FOREACH_ALTERNATE(coap_resource_##_service, coap_resource, _it) |
#include <include/zephyr/net/coap_service.h>
Iterate over static CoAP resources associated with a given _service
.
_service
is defined with COAP_SERVICE_DEFINE._service | Name of CoAP service |
_it | Name of iterator (of type coap_resource) |
#define COAP_SERVICE_AUTOSTART BIT(0) |
#include <include/zephyr/net/coap_service.h>
Start the service on boot.
#define COAP_SERVICE_COUNT | ( | _dst | ) | STRUCT_SECTION_COUNT(coap_service, _dst) |
#include <include/zephyr/net/coap_service.h>
Count the number of CoAP services.
[out] | _dst | Pointer to location where result is written. |
#define COAP_SERVICE_DEFINE | ( | _name, | |
_host, | |||
_port, | |||
_flags | |||
) |
#include <include/zephyr/net/coap_service.h>
Define a CoAP service with static resources.
_host
parameter can be NULL
. If not, it is used to specify an IP address either in IPv4 or IPv6 format a fully-qualified hostname or a virtual host, otherwise the any address is used._port
parameter must be non-NULL
. It points to a location that specifies the port number to use for the service. If the specified port number is zero, then an ephemeral port number will be used and the actual port number assigned will be written back to memory. For ephemeral port numbers, the memory pointed to by _port
must be writeable._name | Name of the service. | |
_host | IP address or hostname associated with the service. | |
[in,out] | _port | Pointer to port associated with the service. |
_flags | Configuration flags |
#define COAP_SERVICE_FOREACH | ( | _it | ) | STRUCT_SECTION_FOREACH(coap_service, _it) |
#include <include/zephyr/net/coap_service.h>
Iterate over all CoAP services.
_it | Name of iterator (of type CoAP service API) |
#define COAP_SERVICE_FOREACH_RESOURCE | ( | _service, | |
_it | |||
) |
#include <include/zephyr/net/coap_service.h>
Iterate over all static resources associated with _service
.
_service
defined with COAP_SERVICE_DEFINE._service | Pointer to COAP service |
_it | Name of iterator (of type coap_resource) |
#define COAP_SERVICE_HAS_RESOURCE | ( | _service, | |
_resource | |||
) | ((_service)->res_begin <= _resource && _resource < (_service)->res_end) |
#include <include/zephyr/net/coap_service.h>
Check if service has the specified resource.
_service | Pointer to a service. |
_resource | Pointer to a resource. |
#define COAP_SERVICE_RESOURCE_COUNT | ( | _service | ) | ((_service)->res_end - (_service)->res_begin) |
#include <include/zephyr/net/coap_service.h>
Count CoAP service static resources.
_service | Pointer to a service. |
int coap_resource_parse_observe | ( | struct coap_resource * | resource, |
const struct coap_packet * | request, | ||
const struct sockaddr * | addr | ||
) |
#include <include/zephyr/net/coap_service.h>
Parse a CoAP observe request for the provided resource
.
resource
defined with COAP_RESOURCE_DEFINE.If the observe option value is equal to 0, an observer will be added, if the value is equal to 1, an existing observer will be removed.
resource | Pointer to CoAP resource |
request | CoAP request to parse |
addr | Peer address |
int coap_resource_remove_observer_by_addr | ( | struct coap_resource * | resource, |
const struct sockaddr * | addr | ||
) |
#include <include/zephyr/net/coap_service.h>
Lookup an observer by address and remove it from the resource
.
resource
defined with COAP_RESOURCE_DEFINE.resource | Pointer to CoAP resource |
addr | Peer address |
int coap_resource_remove_observer_by_token | ( | struct coap_resource * | resource, |
const uint8_t * | token, | ||
uint8_t | token_len | ||
) |
#include <include/zephyr/net/coap_service.h>
Lookup an observer by token and remove it from the resource
.
resource
defined with COAP_RESOURCE_DEFINE.resource | Pointer to CoAP resource |
token | Pointer to the token |
token_len | Length of valid bytes in the token |
int coap_resource_send | ( | const struct coap_resource * | resource, |
const struct coap_packet * | cpkt, | ||
const struct sockaddr * | addr, | ||
socklen_t | addr_len, | ||
const struct coap_transmission_parameters * | params | ||
) |
#include <include/zephyr/net/coap_service.h>
Send a CoAP message from the provided resource
.
resource
defined with COAP_RESOURCE_DEFINE.resource | Pointer to CoAP resource |
cpkt | CoAP Packet to send |
addr | Peer address |
addr_len | Peer address length |
params | Pointer to transmission parameters structure or NULL to use default values. |
int coap_service_is_running | ( | const struct coap_service * | service | ) |
#include <include/zephyr/net/coap_service.h>
Query the provided service
running state.
service
defined with COAP_SERVICE_DEFINE.service | Pointer to CoAP service |
1 | if the service is running |
0 | if the service is stopped |
negative | in case of an error. |
int coap_service_send | ( | const struct coap_service * | service, |
const struct coap_packet * | cpkt, | ||
const struct sockaddr * | addr, | ||
socklen_t | addr_len, | ||
const struct coap_transmission_parameters * | params | ||
) |
#include <include/zephyr/net/coap_service.h>
Send a CoAP message from the provided service
.
service
defined with COAP_SERVICE_DEFINE.service | Pointer to CoAP service |
cpkt | CoAP Packet to send |
addr | Peer address |
addr_len | Peer address length |
params | Pointer to transmission parameters structure or NULL to use default values. |
int coap_service_start | ( | const struct coap_service * | service | ) |
#include <include/zephyr/net/coap_service.h>
Start the provided service
.
service
defined with COAP_SERVICE_DEFINE.service | Pointer to CoAP service |
0 | in case of success. |
-EALREADY | in case of an already running service. |
-ENOTSUP | in case the server has no valid host and port configuration. |
int coap_service_stop | ( | const struct coap_service * | service | ) |
#include <include/zephyr/net/coap_service.h>
Stop the provided service
.
service
defined with COAP_SERVICE_DEFINE.service | Pointer to CoAP service |
0 | in case of success. |
-EALREADY | in case the service isn't running. |