Modules#

CoAP type definitions

CoAP#

The Wi-SUN CoAP component provides an application layer implementation on top of the Wi-SUN stack and its socket API. The CoAP protocol is designed as a specialized Internet Application Protocol for constrained devices in lossy networks (see RFC 7252 for additional information). Wi-SUN FAN networks fit this definition. The CoAP implementation relies on the UDP transport layer to send and receive packets.

A number of helper functions are part of the component to help build CoAP payloads, parse CoAP packets, free CoAP packets, and more.

CoAP Resource Handler service handles registered resources. Resource Discovery request provides an interface to get information about available resources. Resource has more attributes over URI (Uniform Resource Identifier) path, which can be filtered by particular Resource Discovery request.

To use the CoAP component in your application, add it to your project and initialize it with sl_wisun_coap_init().

Functions#

bool
sl_wisun_coap_init(const sl_wisun_coap_tx_callback tx_callback, const sl_wisun_coap_rx_callback rx_callback, const sl_wisun_coap_version_t version)

Initialize Wi-SUN CoAP.

bool

Initialize Wi-SUN CoAP default.

bool

Get lib state.

void *
sl_wisun_coap_malloc(uint16_t size)

Implement malloc.

void
sl_wisun_coap_free(void *addr)

Free Wi-SUN CoAP.

sl_wisun_coap_parser(uint16_t packet_data_len, uint8_t *packet_data)

CoAP parser wrapper function.

uint16_t
sl_wisun_coap_builder_calc_size(const sl_wisun_coap_packet_t *message)

CoAP packet calc size wrapper.

int16_t
sl_wisun_coap_builder(uint8_t *dest_buff, const sl_wisun_coap_packet_t *message)

CoAP message builder Wi-SUN.

sl_wisun_coap_build_response(const sl_wisun_coap_packet_t *req, sl_wisun_coap_message_code_t msg_code)

Build generic response for request wrapper function.

void
sl_wisun_coap_print_packet(const sl_wisun_coap_packet_t *packet, const bool hex_format)

Print CoAP packets and all of attached buffer, payload, token, uri_path.

char *
sl_wisun_coap_get_uri_path_str(const sl_wisun_coap_packet_t *const packet)

Prepare URI path string.

void

Destroy URI path string.

Get the library handler pointer from the internal handler structure.

void
sl_wisun_coap_destroy_packet(sl_wisun_coap_packet_t *packet)

Destroy packet.

char *
sl_wisun_coap_get_payload_str(const sl_wisun_coap_packet_t *const packet)

Prepare payload string.

void

Destroy payload string.

Macros#

#define

CoAP Service loop.

Function Documentation#

sl_wisun_coap_init#

bool sl_wisun_coap_init (const sl_wisun_coap_tx_callback tx_callback, const sl_wisun_coap_rx_callback rx_callback, const sl_wisun_coap_version_t version)

Initialize Wi-SUN CoAP.

Parameters
[in]tx_callback

TX callback, if it's NULL, the default callback is applied

[in]rx_callback

RX callback, if it's NULL, the default callback is applied

[in]version

CoAP version

Set the Wi-SUN CoAP internal descriptor. Returns

  • true Proper initialization

  • false Error


Definition at line 143 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_init_default#

static bool sl_wisun_coap_init_default (void )

Initialize Wi-SUN CoAP default.

Parameters
N/A

Initializes the internal descriptor with default values. Returns

  • true Proper initialization

  • false Error


Definition at line 153 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_is_initialized#

bool sl_wisun_coap_is_initialized (void )

Get lib state.

Parameters
N/A

Gets the initialized state of the CoAP library to decide whether the init is needed. Returns

  • true Initialized

  • false Not initialized


Definition at line 164 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_malloc#

void* sl_wisun_coap_malloc (uint16_t size)

Implement malloc.

Parameters
N/Asize

size for malloc

OS-dependent thread-safe implementation. Returns

  • void* the memory pointer


Definition at line 172 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_free#

void sl_wisun_coap_free (void * addr)

Free Wi-SUN CoAP.

Parameters
N/Aaddr

address ptr

OS-dependent thread-safe implementation.


Definition at line 179 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_parser#

sl_wisun_coap_packet_t* sl_wisun_coap_parser (uint16_t packet_data_len, uint8_t * packet_data)

CoAP parser wrapper function.

Parameters
[in]packet_data_len

packet data size

[in]packet_data

packet data ptr

Used sn_coap_parser Returns

  • sl_wisun_coap_packet_t* Parsed packet pointer


Definition at line 188 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_builder_calc_size#

uint16_t sl_wisun_coap_builder_calc_size (const sl_wisun_coap_packet_t * message)

CoAP packet calc size wrapper.

Parameters
[in]message

message ptr

Used sn_coap_builder_calc_needed_packet_data_size. Returns

  • uint16_t size


Definition at line 197 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_builder#

int16_t sl_wisun_coap_builder (uint8_t * dest_buff, const sl_wisun_coap_packet_t * message)

CoAP message builder Wi-SUN.

Parameters
[out]dest_buff

destination buffer for raw message

[in]message

message structure

Used sl_wisun_coap_builder. Returns

  • int16_t On success bytes of built message, on failure -1 if CoAP header structure is wrong -2 if NULL ptr set as argument


Definition at line 208 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_build_response#

sl_wisun_coap_packet_t* sl_wisun_coap_build_response (const sl_wisun_coap_packet_t * req, sl_wisun_coap_message_code_t msg_code)

Build generic response for request wrapper function.

Parameters
[in]req

request

[in]msg_code

message code to build

Used sn_coap_build_response. Returns

  • sl_wisun_coap_header_t* built packet ptr on the heap


Definition at line 218 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_print_packet#

void sl_wisun_coap_print_packet (const sl_wisun_coap_packet_t * packet, const bool hex_format)

Print CoAP packets and all of attached buffer, payload, token, uri_path.

Parameters
[in]packet

packet to print

[in]hex_format

hex format bool to decide buffer print format

Pretty printer function, with hex format option for buffers


Definition at line 227 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_get_uri_path_str#

char* sl_wisun_coap_get_uri_path_str (const sl_wisun_coap_packet_t *const packet)

Prepare URI path string.

Parameters
[in]packet

Packet

'\0' terminated string in the heap, it must be freed Returns

  • char* URI path string, NULL on error


Definition at line 236 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_destroy_uri_path_str#

static void sl_wisun_coap_destroy_uri_path_str (char * uri_str)

Destroy URI path string.

Parameters
[in]uri_str

URI string ptr

Call free on allocated pointer


Definition at line 243 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_get_lib_handler#

const sl_wisun_coap_handle_t* sl_wisun_coap_get_lib_handler (void )

Get the library handler pointer from the internal handler structure.

Parameters
N/A

Not thread safe! It is needed only to use Pelion mbed-coap library functions Returns

  • const sl_wisun_coap_handle_t* pointer to the lib handler


Definition at line 253 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_destroy_packet#

void sl_wisun_coap_destroy_packet (sl_wisun_coap_packet_t * packet)

Destroy packet.

Parameters
N/Apacket

packet

It must be used to avoid memory leaks! Free the all of allocated buffer for packet


Definition at line 261 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_get_payload_str#

char* sl_wisun_coap_get_payload_str (const sl_wisun_coap_packet_t *const packet)

Prepare payload string.

Parameters
[in]packet

Packet

'\0' terminated string in the heap, it must be freed Returns

  • char* payload string, NULL on error


Definition at line 269 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

sl_wisun_coap_destroy_payload_str#

static void sl_wisun_coap_destroy_payload_str (char * str)

Destroy payload string.

Parameters
[in]str

String

'\0' terminated string in the heap, it must be freed


Definition at line 276 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h

Macro Definition Documentation#

SL_COAP_SERVICE_LOOP#

#define SL_COAP_SERVICE_LOOP
Value:
()

CoAP Service loop.


Definition at line 63 of file /mnt/raid/workspaces/ws.VedEDj2Fn/overlay/gsdk/app/wisun/component/coap/sl_wisun_coap.h