Modules#

sl_wisun_evt

Wi-SUN API#

Callbacks#

void
sl_wisun_on_event(sl_wisun_evt_t *evt)

Callback handler for a single event.

Functions#

sl_status_t
sl_wisun_set_network_size(sl_wisun_network_size_t size)

Set the size of the Wi-SUN network.

sl_status_t
sl_wisun_connect(const uint8_t *name, sl_wisun_regulatory_domain_t reg_domain, sl_wisun_operating_class_t op_class, sl_wisun_operating_mode_t op_mode)

Initiate connection to a Wi-SUN network.

sl_status_t
sl_wisun_get_ip_address(sl_wisun_ip_address_type_t address_type, sl_wisun_ip_address_t *address)

Read an IP address.

sl_status_t
sl_wisun_open_socket(sl_wisun_socket_protocol_t protocol, sl_wisun_socket_id_t *socket_id)

Open a socket.

sl_status_t
sl_wisun_close_socket(sl_wisun_socket_id_t socket_id)

Close a socket.

sl_status_t
sl_wisun_sendto_on_socket(sl_wisun_socket_id_t socket_id, const sl_wisun_ip_address_t *remote_address, uint16_t remote_port, uint16_t data_length, const uint8_t *data)

Write data to an unconnected socket.

sl_status_t
sl_wisun_listen_on_socket(sl_wisun_socket_id_t socket_id)

Set a TCP socket to listening state.

sl_status_t
sl_wisun_accept_on_socket(sl_wisun_socket_id_t socket_id, sl_wisun_socket_id_t *remote_socket_id, sl_wisun_ip_address_t *remote_address, uint16_t *remote_port)

Accept a pending connection request on a TCP socket.

sl_status_t
sl_wisun_connect_socket(sl_wisun_socket_id_t socket_id, const sl_wisun_ip_address_t *remote_address, uint16_t remote_port)

Initiate a connection from a socket to a remote peer socket.

sl_status_t
sl_wisun_bind_socket(sl_wisun_socket_id_t socket_id, const sl_wisun_ip_address_t *local_address, uint16_t local_port)

Bind a socket to a specific local address and/or a port number.

sl_status_t
sl_wisun_send_on_socket(sl_wisun_socket_id_t socket_id, uint16_t data_length, const uint8_t *data)

Write data to a connected socket.

sl_status_t
sl_wisun_receive_on_socket(sl_wisun_socket_id_t socket_id, sl_wisun_ip_address_t *remote_address, uint16_t *remote_port, uint16_t *data_length, uint8_t *data)

Read data from a socket.

sl_status_t

Disconnect from the Wi-SUN network.

sl_status_t
sl_wisun_set_trusted_certificate(uint16_t certificate_options, uint16_t certificate_length, const uint8_t *certificate)

Set a trusted certificate used to verify the authentication server certificate.

sl_status_t
sl_wisun_set_device_certificate(uint16_t certificate_options, uint16_t certificate_length, const uint8_t *certificate)

Set the device certificate used to authenticate to the authentication server.

sl_status_t
sl_wisun_set_device_private_key(uint16_t key_options, uint16_t key_length, const uint8_t *key)

Set the private key of the device certificate.

sl_status_t
sl_wisun_get_statistics(sl_wisun_statistics_type_t statistics_type, sl_wisun_statistics_t *statistics)

Read a set of statistics.

sl_status_t
sl_wisun_set_socket_option(sl_wisun_socket_id_t socket_id, sl_wisun_socket_option_t option, const sl_wisun_socket_option_data_t *option_data)

Set a socket option.

sl_status_t
sl_wisun_set_tx_power(int8_t tx_power)

Set the maximum TX power.

sl_status_t
sl_wisun_set_channel_plan(uint32_t ch0_frequency, uint16_t number_of_channels, sl_wisun_channel_spacing_t channel_spacing)

Set a channel plan.

sl_status_t
sl_wisun_set_channel_mask(const sl_wisun_channel_mask_t *channel_mask)

Set a mask of operating channels.

sl_status_t
sl_wisun_allow_mac_address(const sl_wisun_mac_address_t *address)

Add a MAC address to the list of allowed addresses.

sl_status_t
sl_wisun_deny_mac_address(const sl_wisun_mac_address_t *address)

Add a MAC address to the list of denied addresses.

sl_status_t
sl_wisun_get_socket_option(sl_wisun_socket_id_t socket_id, sl_wisun_socket_option_t option, sl_wisun_socket_option_data_t *option_data)

Get a socket option.

sl_status_t
sl_wisun_get_join_state(sl_wisun_join_state_t *join_state)

Get the current join state.

sl_status_t

Clear the credential cache.

sl_status_t
sl_wisun_get_mac_address(sl_wisun_mac_address_t *address)

Get the current MAC address in use.

sl_status_t
sl_wisun_set_mac_address(const sl_wisun_mac_address_t *address)

Set the MAC address to be used.

Callbacks Documentation#

sl_wisun_on_event#

void sl_wisun_on_event (sl_wisun_evt_t *evt)

Callback handler for a single event.

Parameters
N/Aevt

The event to be handled

This function is called when the stack sends an event to the application. The application can declare its own version this function to customize event handling. The default implementation discards all events.


Definition at line 59 of file protocol/wisun/wisun/inc/sl_wisun_api.h

Function Documentation#

sl_wisun_set_network_size#

sl_status_t sl_wisun_set_network_size (sl_wisun_network_size_t size)

Set the size of the Wi-SUN network.

Parameters
[in]size

Size of the network SL_WISUN_NETWORK_SIZE_AUTOMATIC: network size is managed automatically SL_WISUN_NETWORK_SIZE_SMALL: less than 100 nodes SL_WISUN_NETWORK_SIZE_MEDIUM: 100 to 800 nodes SL_WISUN_NETWORK_SIZE_LARGE: 800 to 1500 nodes

This function sets the size of the network. The value is used to adjust internal behavior, such as timing parameters, to optimize device behavior in regard to the size. The device will function with any setting but may exhibit non-optimal behavior. Setting the size too large may cause slow connection speeds and increased latency. Conversely, a value too small may cause increased network traffic. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 82 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_connect#

sl_status_t sl_wisun_connect (const uint8_t *name, sl_wisun_regulatory_domain_t reg_domain, sl_wisun_operating_class_t op_class, sl_wisun_operating_mode_t op_mode)

Initiate connection to a Wi-SUN network.

Parameters
[in]name

Name of the Wi-SUN network as a zero-terminated string

[in]reg_domain

Regulatory domain of the Wi-SUN network

[in]op_class

Operating class of the Wi-SUN network

[in]op_mode

Operating mode of the Wi-SUN network

This function initiates connection to a Wi-SUN network. Completion of the request is indicated with a SL_WISUN_MSG_CONNECTED_IND_ID event. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 95 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_get_ip_address#

sl_status_t sl_wisun_get_ip_address (sl_wisun_ip_address_type_t address_type, sl_wisun_ip_address_t *address)

Read an IP address.

Parameters
[in]address_type

Type of the IP address to read SL_WISUN_IP_ADDRESS_TYPE_LINK_LOCAL: Link-local IPv6 address of the device SL_WISUN_IP_ADDRESS_TYPE_GLOBAL: Global unicast IPv6 address of the device SL_WISUN_IP_ADDRESS_TYPE_BORDER_ROUTER: Global unicast IPv6 address of the border router SL_WISUN_IP_ADDRESS_TYPE_PRIMARY_PARENT: Link-local IPv6 address of the primary parent SL_WISUN_IP_ADDRESS_TYPE_SECONDARY_PARENT: Link-local IPv6 address of the secondary parent

[out]address

IP address to read

Returns

  • SL_STATUS_OK if successful, an error code otherwise.


Definition at line 111 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_open_socket#

sl_status_t sl_wisun_open_socket (sl_wisun_socket_protocol_t protocol, sl_wisun_socket_id_t *socket_id)

Open a socket.

Parameters
[in]protocol

Protocol type of the socket

[out]socket_id

ID of the opened socket

Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 120 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_close_socket#

sl_status_t sl_wisun_close_socket (sl_wisun_socket_id_t socket_id)

Close a socket.

Parameters
[in]socket_id

ID of the socket

Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 128 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_sendto_on_socket#

sl_status_t sl_wisun_sendto_on_socket (sl_wisun_socket_id_t socket_id, const sl_wisun_ip_address_t *remote_address, uint16_t remote_port, uint16_t data_length, const uint8_t *data)

Write data to an unconnected socket.

Parameters
[in]socket_id

ID of the socket

[in]remote_address

IP address of the remote peer

[in]remote_port

Port number of the remote peer

[in]data_length

Amount of data to write

[in]data

Pointer to the data

This function initiates transmission of data to a remote peer and can only be used on an unconnected UDP or ICMP socket. Completion of the transmission is indicated with a SL_WISUN_MSG_SOCKET_DATA_SENT_IND_ID event. The function takes a copy of the data, the caller may free the resource when the function returns. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 145 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_listen_on_socket#

sl_status_t sl_wisun_listen_on_socket (sl_wisun_socket_id_t socket_id)

Set a TCP socket to listening state.

Parameters
[in]socket_id

ID of the socket

This function sets a TCP socket to listening state, allowing it to act as a server socket, i.e., to receive connection requests from clients. Connection requests are indicated with SL_WISUN_MSG_SOCKET_CONNECTION_AVAILABLE_IND_ID events and accepted using sl_wisun_accept_on_socket(). This function can only be used on an unconnected TCP socket. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 162 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_accept_on_socket#

sl_status_t sl_wisun_accept_on_socket (sl_wisun_socket_id_t socket_id, sl_wisun_socket_id_t *remote_socket_id, sl_wisun_ip_address_t *remote_address, uint16_t *remote_port)

Accept a pending connection request on a TCP socket.

Parameters
[in]socket_id

ID of the socket on listening state

[out]remote_socket_id

ID of the new connected socket

[out]remote_address

IP address of the remote peer

[out]remote_port

Port number of the remote peer

This function accepts a pending connection request from a remote peer and creates a new connected TCP socket for the connection. To decline a connection request, the request must be accepted and then closed using sl_wisun_close_socket(). Use this function only on a TCP socket on listening state. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 177 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_connect_socket#

sl_status_t sl_wisun_connect_socket (sl_wisun_socket_id_t socket_id, const sl_wisun_ip_address_t *remote_address, uint16_t remote_port)

Initiate a connection from a socket to a remote peer socket.

Parameters
[in]socket_id

ID of the socket

[in]remote_address

IP address of the remote peer

[in]remote_port

Port number of the remote peer

This function initiates a connection from a local socket to to a remote peer socket. The result of the connection is indicated with a SL_WISUN_MSG_SOCKET_CONNECTED_IND_ID event. Connecting a socket is mandatory for TCP client sockets but may be also used on other types of sockets. A connected socket can only receive and transmit data with the designated peer. Use this function only on an unconnected TCP or UDP socket. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 196 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_bind_socket#

sl_status_t sl_wisun_bind_socket (sl_wisun_socket_id_t socket_id, const sl_wisun_ip_address_t *local_address, uint16_t local_port)

Bind a socket to a specific local address and/or a port number.

Parameters
[in]socket_id

ID of the socket

[in]local_address

Local IP address to use on the socket. NULL if not bound.

[in]local_port

Local port number to use on the socket. Zero if not bound.

This function binds the local address and/or the port of a socket. When the local address is bound, the socket will only accept traffic sent to the specified address and the transmitted packets will use the address as the source address. If not bound, the socket will accept data sent to any valid address of the device and the source address is selected by the stack. Binding the local port number sets the port number for received and transmitted packets. If not bound, the stack will select a port number automatically. This function can only be used on an unconnected TCP or UDP socket. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 216 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_send_on_socket#

sl_status_t sl_wisun_send_on_socket (sl_wisun_socket_id_t socket_id, uint16_t data_length, const uint8_t *data)

Write data to a connected socket.

Parameters
[in]socket_id

ID of the socket

[in]data_length

Amount of data to write

[in]data

Pointer to the data

This function initiates transmission of data to a connected remote peer and can only be used on a connected socket. Completion of the transmission is indicated with a SL_WISUN_MSG_SOCKET_DATA_SENT_IND_ID event. The function takes a copy of the data, the caller may free the resource when the function returns. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 233 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_receive_on_socket#

sl_status_t sl_wisun_receive_on_socket (sl_wisun_socket_id_t socket_id, sl_wisun_ip_address_t *remote_address, uint16_t *remote_port, uint16_t *data_length, uint8_t *data)

Read data from a socket.

Parameters
[in]socket_id

ID of the socket

[out]remote_address

IP address of the remote peer

[out]remote_port

Port number of the remote peer

[inout]data_length

Amount of data to read on input, amount of data read on output

[in]data

Pointer to where the read data is stored

This function reads buffered data from a socket. When reading data from a UDP or ICMP socket, the entire packet must be read. Any data left unread is discarded after this call. TCP sockets allow reading only a part of the buffered data. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 250 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_disconnect#

sl_status_t sl_wisun_disconnect ()

Disconnect from the Wi-SUN network.

This function disconnects an active connection or cancels an ongoing connection attempt. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 262 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_set_trusted_certificate#

sl_status_t sl_wisun_set_trusted_certificate (uint16_t certificate_options, uint16_t certificate_length, const uint8_t *certificate)

Set a trusted certificate used to verify the authentication server certificate.

Parameters
[in]certificate_options

Options for the certificate SL_WISUN_CERTIFICATE_OPTION_APPEND: Append the certificate to the list of trusted certificates instead of replacing the previous entries SL_WISUN_CERTIFICATE_OPTION_IS_REF: The application guarantees the certificate data will remain in scope and can therefore be referenced instead of copied

[in]certificate_length

Size of the certificate data

[in]certificate

Pointer to the certificate data

Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 275 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_set_device_certificate#

sl_status_t sl_wisun_set_device_certificate (uint16_t certificate_options, uint16_t certificate_length, const uint8_t *certificate)

Set the device certificate used to authenticate to the authentication server.

Parameters
[in]certificate_options

Options for the certificate. SL_WISUN_CERTIFICATE_OPTION_APPEND: Append the certificate to the list of trusted certificates instead of replacing the previous entries SL_WISUN_CERTIFICATE_OPTION_IS_REF: The application guarantees the certificate data will remain in scope and can therefore be referenced instead of copied SL_WISUN_CERTIFICATE_OPTION_HAS_KEY: The certificate has a private key

[in]certificate_length

Size of the certificate data

[in]certificate

Pointer to the certificate data

Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 291 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_set_device_private_key#

sl_status_t sl_wisun_set_device_private_key (uint16_t key_options, uint16_t key_length, const uint8_t *key)

Set the private key of the device certificate.

Parameters
[in]key_options

Options for the private key SL_WISUN_PRIVATE_KEY_OPTION_IS_REF: The application guarantees the private key data will remain in scope and can therefore be referenced instead of copied

[in]key_length

Size of the private key data

[in]key

Pointer to the private key data

Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 304 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_get_statistics#

sl_status_t sl_wisun_get_statistics (sl_wisun_statistics_type_t statistics_type, sl_wisun_statistics_t *statistics)

Read a set of statistics.

Parameters
[in]statistics_type

Type of statistics to read SL_WISUN_STATISTICS_TYPE_PHY: PHY/RF statistics SL_WISUN_STATISTICS_TYPE_MAC: MAC statistics SL_WISUN_STATISTICS_TYPE_FHSS: Frequency hopping statistics SL_WISUN_STATISTICS_TYPE_WISUN: Wi-SUN statistics SL_WISUN_STATISTICS_TYPE_NETWORK: 6LoWPAN/IP stack statistics

[out]statistics

Set of statistics read

This function reads a set of statistics from the stack. Statistics are cumulative and reset when a connection is initiated. Returns

  • SL_STATUS_OK if successful, an error code otherwise.


Definition at line 321 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_set_socket_option#

sl_status_t sl_wisun_set_socket_option (sl_wisun_socket_id_t socket_id, sl_wisun_socket_option_t option, const sl_wisun_socket_option_data_t *option_data)

Set a socket option.

Parameters
[in]socket_id

ID of the socket

[in]option

Socket option to set SL_WISUN_SOCKET_OPTION_EVENT_MODE: Event mode SL_WISUN_SOCKET_OPTION_MULTICAST_GROUP: Multicast group

[in]option_data

Socket option specific data

Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 333 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_set_tx_power#

sl_status_t sl_wisun_set_tx_power (int8_t tx_power)

Set the maximum TX power.

Parameters
[in]tx_power

TX power in dBm

This function sets the maximum TX power to be used. The device may utilize a lower value based on internal decision making or hardware limitations but will never exceed the given value. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 345 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_set_channel_plan#

sl_status_t sl_wisun_set_channel_plan (uint32_t ch0_frequency, uint16_t number_of_channels, sl_wisun_channel_spacing_t channel_spacing)

Set a channel plan.

Parameters
[in]ch0_frequency

Frequency of the first channel in kHz

[in]number_of_channels

Number of channels

[in]channel_spacing

Spacing between the channels

This function sets an application-specific channel plan to be used in the following connections. By default, the channel plan is set indirectly based on the regulatory domain and the operating class given in sl_wisun_connect(). Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 358 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_set_channel_mask#

sl_status_t sl_wisun_set_channel_mask (const sl_wisun_channel_mask_t *channel_mask)

Set a mask of operating channels.

Parameters
[in]channel_mask

Mask of operating channels

This function sets a mask of channels the device is allowed to operate in. By default, all channels in the channel plan are allowed. The mask can only be used to further restrict the channels, channels outside the channel plan or channels internally excluded are ignored. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 372 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_allow_mac_address#

sl_status_t sl_wisun_allow_mac_address (const sl_wisun_mac_address_t *address)

Add a MAC address to the list of allowed addresses.

Parameters
[in]address

MAC address broadcast address: allow all MAC addresses unicast address: allow the given MAC address

This function adds a MAC address to the list of allowed addresses. When the first address is added to the list, the list of denied addresses is cleared and the device will start preventing communication with any device whose MAC address does not match any of addresses on the list. By default, all MAC addresses are allowed. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 386 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_deny_mac_address#

sl_status_t sl_wisun_deny_mac_address (const sl_wisun_mac_address_t *address)

Add a MAC address to the list of denied addresses.

Parameters
[in]address

MAC address broadcast address: deny all MAC addresses unicast address: deny the given MAC address

This function adds a MAC address to the list of denied addresses. When the first address is added to the list, the list of allowed addresses is cleared and the device will start preventing communication with any device whose MAC address matches any of the addresses on the list. By default, all MAC addresses are allowed. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 401 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_get_socket_option#

sl_status_t sl_wisun_get_socket_option (sl_wisun_socket_id_t socket_id, sl_wisun_socket_option_t option, sl_wisun_socket_option_data_t *option_data)

Get a socket option.

Parameters
[in]socket_id

ID of the socket

[in]option

Socket option to get SL_WISUN_SOCKET_OPTION_SEND_BUFFER_LIMIT: Send buffer limit

[out]option_data

Socket option specific data

This function retrieves the value of a socket option. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 412 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_get_join_state#

sl_status_t sl_wisun_get_join_state (sl_wisun_join_state_t *join_state)

Get the current join state.

Parameters
[out]join_state

Join state

This function retrieves the current state of the connection process. The function can only be used when a connection has been initiated. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 424 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_clear_credential_cache#

sl_status_t sl_wisun_clear_credential_cache ()

Clear the credential cache.

This function clears the cached authentication credentials stored in non-volatile storage. The function is intended for test purposes. Note that clearing the credential cache may prevent the node from reconnecting to the same parent until the corresponding cache entry has expired on the parent. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 435 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_get_mac_address#

sl_status_t sl_wisun_get_mac_address (sl_wisun_mac_address_t *address)

Get the current MAC address in use.

Parameters
[out]address

MAC address

Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 442 of file protocol/wisun/wisun/inc/sl_wisun_api.h

sl_wisun_set_mac_address#

sl_status_t sl_wisun_set_mac_address (const sl_wisun_mac_address_t *address)

Set the MAC address to be used.

Parameters
[in]address

MAC address

This function sets the MAC address to be used in the following connections. By default, the device will use the built-in unique device MAC address. The address is reset to the built-in value upon power up. Returns

  • SL_STATUS_OK if successful, an error code otherwise


Definition at line 453 of file protocol/wisun/wisun/inc/sl_wisun_api.h