Soletta™ Framework
|
API to handle Constrained Application Protocol (CoAP) protocol. More...
Data Structures | |
struct | sol_coap_resource |
Description for a CoAP resource. More... | |
Macros | |
#define | SOL_COAP_CODE_EMPTY (0) |
Macro to indicates that the header code was not set. More... | |
#define | sol_coap_make_response_code(clas, det) ((clas << 5) | (det)) |
Macro to create a response code. More... | |
#define | SOL_COAP_REQUEST_MASK 0x07 |
Mask of CoAP requests. More... | |
Typedefs | |
typedef struct sol_coap_packet | sol_coap_packet |
Opaque handler for a CoAP packet. More... | |
typedef struct sol_coap_resource | sol_coap_resource |
Description for a CoAP resource. More... | |
typedef struct sol_coap_server | sol_coap_server |
Opaque handler for a CoAP server. More... | |
Functions | |
int | sol_coap_add_option (struct sol_coap_packet *pkt, uint16_t code, const void *value, uint16_t len) |
Adds an option to the CoAP packet. More... | |
int | sol_coap_cancel_send_packet (struct sol_coap_server *server, struct sol_coap_packet *pkt, struct sol_network_link_addr *cliaddr) |
Cancel a packet sent using sol_coap_send_packet() or sol_coap_send_packet_with_reply() functions. More... | |
const void * | sol_coap_find_first_option (const struct sol_coap_packet *pkt, uint16_t code, uint16_t *len) |
Finds the first apeearence of the specified option in a packet. More... | |
int | sol_coap_find_options (const struct sol_coap_packet *pkt, uint16_t code, struct sol_str_slice *vec, uint16_t veclen) |
Gets a number of specified option in a packet. More... | |
int | sol_coap_header_get_code (const struct sol_coap_packet *pkt, uint8_t *code) |
Gets the request/response code in the packet. More... | |
int | sol_coap_header_get_id (const struct sol_coap_packet *pkt, uint16_t *id) |
Gets the message ID. More... | |
uint8_t * | sol_coap_header_get_token (const struct sol_coap_packet *pkt, uint8_t *len) |
Gets the token of the packet, if any. More... | |
int | sol_coap_header_get_type (const struct sol_coap_packet *pkt, uint8_t *type) |
Gets the type of the message container in the packet. More... | |
int | sol_coap_header_get_version (const struct sol_coap_packet *pkt, uint8_t *version) |
Gets the CoAP protocol version of the packet. More... | |
int | sol_coap_header_set_code (struct sol_coap_packet *pkt, uint8_t code) |
Sets the code of the message. More... | |
int | sol_coap_header_set_id (struct sol_coap_packet *pkt, uint16_t id) |
Sets the message ID. More... | |
int | sol_coap_header_set_token (struct sol_coap_packet *pkt, uint8_t *token, uint8_t tokenlen) |
Sets a token in the packet. More... | |
int | sol_coap_header_set_type (struct sol_coap_packet *pkt, uint8_t type) |
Sets the message type in the packet's header. More... | |
int | sol_coap_header_set_version (struct sol_coap_packet *pkt, uint8_t ver) |
Sets the CoAP protocol version in the packet's header. More... | |
int | sol_coap_notify (struct sol_coap_server *server, struct sol_coap_resource *resource, struct sol_coap_packet *pkt) |
Sends the notification packet to all registered observers. More... | |
int | sol_coap_notify_by_callback (struct sol_coap_server *server, struct sol_coap_resource *resource, int(*cb)(void *cb_data, struct sol_coap_server *server, struct sol_coap_resource *resource, struct sol_network_link_addr *addr, struct sol_coap_packet **pkt), const void *cb_data) |
Sends the notification packet returned by a callback to all registered observers. More... | |
int | sol_coap_packet_add_uri_path_option (struct sol_coap_packet *pkt, const char *uri) |
Convenience function to add the the SOL_COAP_OPTION_URI_PATH from a string. More... | |
static void | sol_coap_packet_debug (struct sol_coap_packet *pkt) |
Print information about the packet pkt. More... | |
int | sol_coap_packet_get_payload (struct sol_coap_packet *pkt, struct sol_buffer **buf, size_t *offset) |
Gets a pointer to the packet's payload. More... | |
bool | sol_coap_packet_has_payload (struct sol_coap_packet *pkt) |
Checks if the given packet contains a payload. More... | |
struct sol_coap_packet * | sol_coap_packet_new (struct sol_coap_packet *old) |
Creates a new CoAP packet. More... | |
struct sol_coap_packet * | sol_coap_packet_new_notification (struct sol_coap_server *server, struct sol_coap_resource *resource) |
Convenience function to create a packet suitable to send as a notification. More... | |
struct sol_coap_packet * | sol_coap_packet_new_request (enum sol_coap_method method, enum sol_coap_message_type type) |
Convenience function to create a new packet for a request. More... | |
struct sol_coap_packet * | sol_coap_packet_ref (struct sol_coap_packet *pkt) |
Take a reference of the given packet. More... | |
void | sol_coap_packet_unref (struct sol_coap_packet *pkt) |
Release a reference from the given packet. More... | |
int | sol_coap_path_to_buffer (const struct sol_str_slice path[], struct sol_buffer *buf, size_t offset, size_t *size) |
Inserts a path given in slices form to a sol-buffer , at a given offset. More... | |
int | sol_coap_send_packet (struct sol_coap_server *server, struct sol_coap_packet *pkt, const struct sol_network_link_addr *cliaddr) |
Sends a packet to the given address. More... | |
int | sol_coap_send_packet_with_reply (struct sol_coap_server *server, struct sol_coap_packet *pkt, const struct sol_network_link_addr *cliaddr, bool(*reply_cb)(void *data, struct sol_coap_server *server, struct sol_coap_packet *req, const struct sol_network_link_addr *cliaddr), const void *data) |
Sends a packet to the given address. More... | |
bool | sol_coap_server_is_secure (const struct sol_coap_server *server) |
Check if a given CoAP server instance is running over DTLS or not. More... | |
struct sol_coap_server * | sol_coap_server_new (const struct sol_network_link_addr *addr, bool secure) |
Creates a new CoAP server instance. More... | |
struct sol_coap_server * | sol_coap_server_new_by_cipher_suites (const struct sol_network_link_addr *addr, enum sol_socket_dtls_cipher *cipher_suites, uint16_t cipher_suites_len) |
Creates a new DTLS-Secured CoAP server instance. More... | |
struct sol_coap_server * | sol_coap_server_ref (struct sol_coap_server *server) |
Take a reference of the given server. More... | |
int | sol_coap_server_register_resource (struct sol_coap_server *server, const struct sol_coap_resource *resource, const void *data) |
Register a sol_coap_resource with the server. More... | |
int | sol_coap_server_set_unknown_resource_handler (struct sol_coap_server *server, int(*handler)(void *data, struct sol_coap_server *server, struct sol_coap_packet *req, const struct sol_network_link_addr *cliaddr), const void *data) |
Register a unknown handler callback. More... | |
void | sol_coap_server_unref (struct sol_coap_server *server) |
Release a reference from the given server. More... | |
int | sol_coap_server_unregister_resource (struct sol_coap_server *server, const struct sol_coap_resource *resource) |
Unregisters a resource from the server. More... | |
int | sol_coap_unobserve_by_token (struct sol_coap_server *server, const struct sol_network_link_addr *cliaddr, uint8_t *token, uint8_t tkl) |
Remove observation identified by token from server. More... | |
API to handle Constrained Application Protocol (CoAP) protocol.
The Constrained Application Protocol (CoAP) is a specialized web transfer protocol for use with constrained nodes and constrained (e.g., low-power, lossy) networks. The nodes often have 8-bit microcontrollers with small amounts of ROM and RAM, while constrained networks such as IPv6 over Low-Power Wireless Personal Area Networks (6LoWPANs) often have high packet error rates and a typical throughput of 10s of kbit/s. The protocol is designed for machine-to-machine (M2M) applications such as smart energy and building automation.
CoAP provides a request/response interaction model between application endpoints, supports built-in discovery of services and resources, and includes key concepts of the Web such as URIs and Internet media types. CoAP is designed to easily interface with HTTP for integration with the Web while meeting specialized requirements such as multicast support, very low overhead, and simplicity for constrained environments.
Relevant RFCs:
#define SOL_COAP_CODE_EMPTY (0) |
Macro to indicates that the header code was not set.
To be used with sol_coap_header_set_code()
#define sol_coap_make_response_code | ( | clas, | |
det | |||
) | ((clas << 5) | (det)) |
Macro to create a response code.
CoAP message code field is a 8-bit unsigned integer, composed by 3 most significants bits representing class (0-7) and 5 bits representing detail (00-31).
It's usually represented as "c.dd". E.g.: 2.00 for "OK".
#define SOL_COAP_REQUEST_MASK 0x07 |
Mask of CoAP requests.
It may be used to identify, given a code, if it's a request or a response.
Example to identify a request:
Opaque handler for a CoAP packet.
typedef struct sol_coap_resource sol_coap_resource |
Description for a CoAP resource.
CoAP servers will want to register resources, so that clients can act on them, by fetching their state or requesting updates to them. These resources are registered using this struct and the sol_coap_server_register_resource() function.
Opaque handler for a CoAP server.
Some content-types available for use with the CONTENT_FORMAT option.
Refer to RFC 7252, section 12.3 for more information.
Enumerator | |
---|---|
SOL_COAP_CONTENT_TYPE_NONE | |
SOL_COAP_CONTENT_TYPE_TEXT_PLAIN | |
SOL_COAP_CONTENT_TYPE_APPLICATION_LINK_FORMAT | |
SOL_COAP_CONTENT_TYPE_APPLICATION_CBOR | |
SOL_COAP_CONTENT_TYPE_APPLICATION_JSON |
enum sol_coap_flags |
Flags accepted by a sol_coap_resource.
Enumerator | |
---|---|
SOL_COAP_FLAGS_NONE | |
SOL_COAP_FLAGS_WELL_KNOWN |
If the resource should be exported in the CoRE well-known registry. |
CoAP packets may be of one of these types.
Enumerator | |
---|---|
SOL_COAP_MESSAGE_TYPE_CON |
Confirmable messsage. Packet is a request or response that the destination end-point must acknowledge. If received and processed properly, it will receive a response of matching |
SOL_COAP_MESSAGE_TYPE_NON_CON |
Non-confirmable message. Packet is a request or response that does not need acknowledge. Destinataries should not reply to them with an ACK, but may respond with a message of type SOL_COAP_MESSAGE_TYPE_RESET if the package could not be processed due to being faulty. |
SOL_COAP_MESSAGE_TYPE_ACK |
Acknowledge. When a confirmable message is received, a response should be sent to the source with the same |
SOL_COAP_MESSAGE_TYPE_RESET |
Reset. Rejecting a packet for any reason is done by sending a message of this type with the |
enum sol_coap_method |
Available request methods.
To be used with sol_coap_header_set_code() when crafting a request.
Enumerator | |
---|---|
SOL_COAP_METHOD_GET |
A GET request. |
SOL_COAP_METHOD_POST |
A POST request. |
SOL_COAP_METHOD_PUT |
A PUT request. |
SOL_COAP_METHOD_DELETE |
A DELETE request. |
enum sol_coap_option |
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.
Set of response codes available for a response packet.
To be used with sol_coap_header_set_code() when crafting a reply.
int sol_coap_add_option | ( | struct sol_coap_packet * | pkt, |
uint16_t | code, | ||
const void * | value, | ||
uint16_t | len | ||
) |
Adds an option to the CoAP packet.
Options must be added in order, according to their numeric definitions.
pkt | The packet to which the option will be added. |
code | The option code, one of sol_coap_option. |
value | Pointer to the value of the option, or NULL if none. |
len | Length in bytes of value, or 0 if value is NULL. |
Referenced by disable_observing(), and main().
int sol_coap_cancel_send_packet | ( | struct sol_coap_server * | server, |
struct sol_coap_packet * | pkt, | ||
struct sol_network_link_addr * | cliaddr | ||
) |
Cancel a packet sent using sol_coap_send_packet() or sol_coap_send_packet_with_reply() functions.
For observating packets, an unobserve packet will be sent to server and no more replies will be processed.
server | The server through which the packet was sent. |
pkt | The packet sent. |
cliaddr | The source address of the sent packet. |
const void* sol_coap_find_first_option | ( | const struct sol_coap_packet * | pkt, |
uint16_t | code, | ||
uint16_t * | len | ||
) |
Finds the first apeearence of the specified option in a packet.
pkt | The packet holding the options. |
code | The option code to look for. Pass one of the sol_coap_option values or any custom option code. |
len | The length in bytes of the option's value. |
int sol_coap_find_options | ( | const struct sol_coap_packet * | pkt, |
uint16_t | code, | ||
struct sol_str_slice * | vec, | ||
uint16_t | veclen | ||
) |
Gets a number of specified option in a packet.
pkt | The packet holding the options. |
code | The option code to look for. Pass one of the sol_coap_option values or any custom option code. |
vec | An vector of struct sol_str_slice to hold the options. |
veclen | The length of vec. |
int sol_coap_header_get_code | ( | const struct sol_coap_packet * | pkt, |
uint8_t * | code | ||
) |
Gets the request/response code in the packet.
If the packet is a request, the code returned is one of sol_coap_method. If it's a response, it will be one of sol_coap_response_code. If the code was not set, the returned code will be SOL_COAP_CODE_EMPTY.
pkt | The packet to get the code from. |
code | The request/response code. |
int sol_coap_header_get_id | ( | const struct sol_coap_packet * | pkt, |
uint16_t * | id | ||
) |
Gets the message ID.
pkt | The packet from which to get the message ID. |
id | The message ID. |
uint8_t* sol_coap_header_get_token | ( | const struct sol_coap_packet * | pkt, |
uint8_t * | len | ||
) |
Gets the token of the packet, if any.
If the packet contains a token, this function can retrieve it.
pkt | The packet with the token. |
len | Pointer where to store the length in bytes of the token. |
NULL
in case of error (when errno
will be set to EINVAL
), otherwise a pointer to an internal buffer containint the token. It must not be modified. int sol_coap_header_get_type | ( | const struct sol_coap_packet * | pkt, |
uint8_t * | type | ||
) |
Gets the type of the message container in the packet.
pkt | The packet containing the message. |
type | The type of the message, one of sol_coap_message_type. |
int sol_coap_header_get_version | ( | const struct sol_coap_packet * | pkt, |
uint8_t * | version | ||
) |
Gets the CoAP protocol version of the packet.
pkt | The packet to get version from. |
version | The CoAP protocol version the packet implements. |
int sol_coap_header_set_code | ( | struct sol_coap_packet * | pkt, |
uint8_t | code | ||
) |
Sets the code of the message.
For requests, it must be one of sol_coap_method. For responses, it must be one of sol_coap_response_code.
pkt | The packet on which to set the code. |
code | The request/response code. |
Referenced by disable_observing(), light_method_get(), light_method_put(), and update_light().
int sol_coap_header_set_id | ( | struct sol_coap_packet * | pkt, |
uint16_t | id | ||
) |
Sets the message ID.
CoAP packets require an ID to identify a request, so that their response can be matched by it. It's not usually necessary to call this function, as packets created by sol_coap_packet_new() will have generated an ID already,
pkt | The packet on which to set the ID. |
id | The ID to set. |
int sol_coap_header_set_token | ( | struct sol_coap_packet * | pkt, |
uint8_t * | token, | ||
uint8_t | tokenlen | ||
) |
Sets a token in the packet.
Tokens can be used, besides the ID, to identify a specific request. For OBSERVE
requests, the server will send notifications with the same token used to make the request.
pkt | The packet on which to set the token. |
token | The token to set, can be any array of bytes. |
tokenlen | The length in bytes of token. |
Referenced by main().
int sol_coap_header_set_type | ( | struct sol_coap_packet * | pkt, |
uint8_t | type | ||
) |
Sets the message type in the packet's header.
Must be one of sol_coap_message_type.
pkt | The packet to set the type to. |
type | The message type to set. |
Referenced by disable_observing(), light_method_get(), and light_method_put().
int sol_coap_header_set_version | ( | struct sol_coap_packet * | pkt, |
uint8_t | ver | ||
) |
Sets the CoAP protocol version in the packet's header.
Usually not needed, as packets created with sol_coap_packet_new() will already have the version set.
pkt | The packet to set the version. |
ver | The version to set. |
int sol_coap_notify | ( | struct sol_coap_server * | server, |
struct sol_coap_resource * | resource, | ||
struct sol_coap_packet * | pkt | ||
) |
Sends the notification packet to all registered observers.
Sends the notification pkt to all the registered observers for the resource resource, setting the correct token for each instance.
server | The server through which the notifications will be sent. |
resource | The resource the notification is about. |
pkt | The notification packet to send. |
Referenced by update_light().
int sol_coap_notify_by_callback | ( | struct sol_coap_server * | server, |
struct sol_coap_resource * | resource, | ||
int(*)(void *cb_data, struct sol_coap_server *server, struct sol_coap_resource *resource, struct sol_network_link_addr *addr, struct sol_coap_packet **pkt) | cb, | ||
const void * | cb_data | ||
) |
Sends the notification packet returned by a callback to all registered observers.
Sends the notification pkt
to all the registered observers for the resource resource, setting the correct token for each instance. The pkt
will be filled by a callback cb
given to this function, probably based on the observer's address and/or any other used data.
server | The server through which the notifications will be sent. |
resource | The resource the notification is about. |
cb | A callback that is used to create the pkt - data User data; server The server through which the notifications will be sent; resource The resource the notification is about; addr The address of the observer; pkt The pkt to be filled. |
cb_data | The user data to cb . |
int sol_coap_packet_add_uri_path_option | ( | struct sol_coap_packet * | pkt, |
const char * | uri | ||
) |
Convenience function to add the the SOL_COAP_OPTION_URI_PATH from a string.
pkt | The packet to the add the path to. |
uri | The path to add, must start with '/'. |
|
inlinestatic |
Print information about the packet pkt.
Used for debug purposes.
pkt | The packet to be debuged. |
int sol_coap_packet_get_payload | ( | struct sol_coap_packet * | pkt, |
struct sol_buffer ** | buf, | ||
size_t * | offset | ||
) |
Gets a pointer to the packet's payload.
When creating a packet, first set all the packet header parameters and options, then use this function to get a pointer to the packet's payload buffer. One may then append content to the payload buffer (all sol-buffer
appending functions will do). Note that only appending is permitted, otherwise the packet headers/options – that are also payload – will get corrupted.
Getting the payload pointer marks the end of the header and options in the packet, so after that point, it's no longer possible to set any of those.
When receiving a packet, first check if it contains a payload with sol_coap_packet_has_payload(), and if so, this function will return in buf the packet's buffer and in offset, where in that buffer the user's payload actually begins.
pkt | The packet to fetch the payload of. |
buf | Where to store the address of the payload buffer. |
offset | Where to store the offset, in buf, where the actual payload starts. |
Referenced by light_method_get(), light_method_put(), reply_cb(), and update_light().
bool sol_coap_packet_has_payload | ( | struct sol_coap_packet * | pkt | ) |
Checks if the given packet contains a payload.
For packets received as a request or response, this function checks if they contain a payload. It should be used before calling sol_coap_packet_get_payload().
pkt | The packet to check. |
struct sol_coap_packet* sol_coap_packet_new | ( | struct sol_coap_packet * | old | ) |
Creates a new CoAP packet.
Creates a packet to send as a request or response. If old is not NULL
, its ID
and token
(if any) will be copied to the new packet. This is useful when crafting a new packet as a response to old. It's also important to note that if old has sol_coap_message_type equal to SOL_COAP_MESSAGE_TYPE_CON, the new packet message type will be set to SOL_COAP_MESSAGE_TYPE_ACK. If it has it equal to SOL_COAP_MESSAGE_TYPE_NON_CON, the new packet message type will be set to SOL_COAP_MESSAGE_TYPE_NON_CON.
old | An optional packet to use as basis. |
NULL
on failure. Referenced by disable_observing(), light_method_get(), and light_method_put().
struct sol_coap_packet* sol_coap_packet_new_notification | ( | struct sol_coap_server * | server, |
struct sol_coap_resource * | resource | ||
) |
Convenience function to create a packet suitable to send as a notification.
When notifying observing clients of changes in a resource, this function simplifies the creation of the notification packet by handling the management of the resource age (and setting the id) and type of the packet.
It should be used along sol_coap_notify() to ensure that the correct token is added to the packet sent to the clients.
server | The server holding the resource that changed. |
resource | The resource the notification is about. |
id
and type
set accordingly, or NULL on failure.Referenced by update_light().
struct sol_coap_packet* sol_coap_packet_new_request | ( | enum sol_coap_method | method, |
enum sol_coap_message_type | type | ||
) |
Convenience function to create a new packet for a request.
Creates a new packet, automatically setting a new id
, and setting the request method to method and message type to type.
method | The method to use for the request. |
type | The message type. |
id
, method
and type
already set. Referenced by main().
struct sol_coap_packet* sol_coap_packet_ref | ( | struct sol_coap_packet * | pkt | ) |
Take a reference of the given packet.
Increment the reference count of the packet, if it's still valid.
pkt | The packet to reference. |
NULL
if invalid. void sol_coap_packet_unref | ( | struct sol_coap_packet * | pkt | ) |
Release a reference from the given packet.
When the last reference is released, the packet will be freed.
pkt | The packet to release. |
Referenced by disable_observing(), light_method_get(), light_method_put(), and update_light().
int sol_coap_path_to_buffer | ( | const struct sol_str_slice | path[], |
struct sol_buffer * | buf, | ||
size_t | offset, | ||
size_t * | size | ||
) |
Inserts a path given in slices form to a sol-buffer
, at a given offset.
Takes a path, as respresented by sol_coap_resource and inserts all its components, in order, separated by '/', to buf's offset position.
path | Array of slices, last one empty, representing the path. |
buf | Buffer where to append the string version of the path. |
offset | Where to insert the paths string into buf. |
size | Pointer where to store the number of bytes written to buf If NULL , it will be ignored. |
Referenced by light_resource_to_rep().
int sol_coap_send_packet | ( | struct sol_coap_server * | server, |
struct sol_coap_packet * | pkt, | ||
const struct sol_network_link_addr * | cliaddr | ||
) |
Sends a packet to the given address.
Sends the packet pkt to the destination address especified by cliaddr, which may be a multicast address for discovery purposes.
If a response is expected, then sol_coap_send_packet_with_reply() should be used instead.
server | The server through which the packet will be sent. |
pkt | The packet to send. |
cliaddr | The recipient address. |
Referenced by disable_observing(), light_method_get(), and light_method_put().
int sol_coap_send_packet_with_reply | ( | struct sol_coap_server * | server, |
struct sol_coap_packet * | pkt, | ||
const struct sol_network_link_addr * | cliaddr, | ||
bool(*)(void *data, struct sol_coap_server *server, struct sol_coap_packet *req, const struct sol_network_link_addr *cliaddr) | reply_cb, | ||
const void * | data | ||
) |
Sends a packet to the given address.
Sends the packet pkt to the destination address especified by cliaddr, which may be a multicast address for discovery purposes, and issues a given callback when a response arrives.
If reply_cb is NULL
, this function will behave exactly like sol_coap_send_packet(). If a valid function is passed, when a response is received, the function reply_cb will be called. As long as this function returns true
, server will continue waiting for more responses. When it returns false
, the internal response handler will be freed and any new reply that may arrive for this request will be ignored. For unobserving packets, server will also be notified using an unobserve packet.
After an internal timeout is reached, reply_cb will be called with NULL
req
and cliaddr
. The same behavior is expected for its return: if true
, server will issue a new timeout and continue waiting responses until it ends, otherwise server will terminate response waiting.
true
, that will be interpreted as if the user wishes to wait for responses indefinetely and no timeout will apply anymore. The user is then responsible for cancelling the request with sol_coap_cancel_send_packet().server | The server through which the packet will be sent. |
pkt | The packet to send. |
cliaddr | The recipient address. |
reply_cb | The function to call when a response is received. |
data | The user data pointer to pass to the reply_cb function. |
Referenced by main().
bool sol_coap_server_is_secure | ( | const struct sol_coap_server * | server | ) |
Check if a given CoAP server instance is running over DTLS or not.
server | The server to be checked. |
struct sol_coap_server* sol_coap_server_new | ( | const struct sol_network_link_addr * | addr, |
bool | secure | ||
) |
Creates a new CoAP server instance.
Creates a new, CoAP server instance listening on address addr. If the server cannot be created, NULL will be returned and errno
will be set to indicate the reason.
addr | The address where the server will listen on. |
secure | Set to true to create a server that will encrypt communication with its endpoints using DTLS or false otherwise. |
secure
is true
, this function will create a sol_coap_server
over a DTLS Socket supporting only the SOL_SOCKET_DTLS_CIPHER_PSK_AES128_CCM8 Cipher Suite. The recommended function for creating secure sol_coap_server
is sol_coap_server_new_by_cipher_suites
.Referenced by main().
struct sol_coap_server* sol_coap_server_new_by_cipher_suites | ( | const struct sol_network_link_addr * | addr, |
enum sol_socket_dtls_cipher * | cipher_suites, | ||
uint16_t | cipher_suites_len | ||
) |
Creates a new DTLS-Secured CoAP server instance.
Creates a new, DTLS-Secured CoAP server instance listening on address addr. If the server cannot be created, NULL will be returned and errno
will be set to indicate the reason.
addr | The address where the server will listen on. |
cipher_suites | Indicates the desired cipher suites to use. |
cipher_suites_len | Indicates the length of the cipher_suites array. |
struct sol_coap_server* sol_coap_server_ref | ( | struct sol_coap_server * | server | ) |
Take a reference of the given server.
Increment the reference count of the server, if it's still valid.
server | The server to reference. |
int sol_coap_server_register_resource | ( | struct sol_coap_server * | server, |
const struct sol_coap_resource * | resource, | ||
const void * | data | ||
) |
Register a sol_coap_resource with the server.
Registers the given resource with the server, in order to be able to handle requests related to it made by clients. The same resource can be registered on multiple servers.
server | The server on which the resource wil be registered. |
resource | The resource to register. |
data | User data pointer that will be passed to the requests callbacks. |
errno
on error. Referenced by main().
int sol_coap_server_set_unknown_resource_handler | ( | struct sol_coap_server * | server, |
int(*)(void *data, struct sol_coap_server *server, struct sol_coap_packet *req, const struct sol_network_link_addr *cliaddr) | handler, | ||
const void * | data | ||
) |
Register a unknown handler callback.
Every time the server receives a request for a sol_coap_resource that was not registered with sol_coap_server_register_resource() the handler will be called.
server | The server to register the unknown resource handler. |
handler | The unknown handler callback or NULL to unregister. |
data | The data to handler |
NULL
. void sol_coap_server_unref | ( | struct sol_coap_server * | server | ) |
Release a reference from the given server.
When the last reference is released, the server and all resources associated with it will be freed.
server | The server to release. |
Referenced by main().
int sol_coap_server_unregister_resource | ( | struct sol_coap_server * | server, |
const struct sol_coap_resource * | resource | ||
) |
Unregisters a resource from the server.
Unregisters a resource previously registered with sol_coap_server_register_resource(). This specific server will no longer handle requests made to the given resource, but if its registered in other servers, it may still be found by clients.
server | The server from which to unregister the resource. |
resource | The resource to unregister. |
int sol_coap_unobserve_by_token | ( | struct sol_coap_server * | server, |
const struct sol_network_link_addr * | cliaddr, | ||
uint8_t * | token, | ||
uint8_t | tkl | ||
) |
Remove observation identified by token from server.
Send to server an unobserve packet so client identified by token will be removed from the server's observation list. We are suppose to stop receiving new notifications.
If observation was added using sol_coap_send_packet_with_reply() function we will have no more calls to reply_cb.
server | The server through which the observation packet was sent. |
cliaddr | The source address of the observation packet sent. |
token | The observation token |
tkl | The observation token length |