SiWx91x Sockets#

This section provides a reference to the SiWx91x chipset's socket API functions.

Modules#

sl_si91x_socket_metadata_t

sl_si91x_sock_info_query_t

sl_si91x_socket_info_response_t

SiWx91x Socket Option Name

Typedefs#

typedef void(*
receive_data_callback)(uint32_t socket, uint8_t *buffer, uint32_t length, const sl_si91x_socket_metadata_t *firmware_socket_response)

This callback is used to read data asynchronously from a socket.

typedef void(*
accept_callback)(int32_t socket, struct sockaddr *addr, uint8_t ip_version)

This callback is used to provide the parameters of a newly accepted connection.

typedef void(*
data_transfer_complete_handler)(int32_t socket, uint16_t length)

This callback is used to indicate the status of a data transfer.

typedef void(*
select_callback)(fd_set *fd_read, fd_set *fd_write, fd_set *fd_except, int32_t status)

This callback is used to indicate when an asynchronous response reaches the select request.

typedef void(*
remote_socket_termination_callback)(int socket, uint16_t port, uint32_t bytes_sent)

This callback is used to indicate when a remote socket is terminated.

Functions#

int
sl_si91x_socket(int family, int type, int protocol)

Creates a new socket.

int
sl_si91x_socket_async(int family, int type, int protocol, receive_data_callback callback)

Creates an asynchronous socket and registers the provided callback.

int
sl_si91x_setsockopt_async(int32_t socket, int level, int option_name, const void *option_value, socklen_t option_len)

Sets a specified socket option on the identified socket asynchronously.

int
sl_si91x_bind(int socket, const struct sockaddr *addr, socklen_t addr_len)

Assigns a local protocol address to a socket.

int
sl_si91x_listen(int socket, int max_number_of_clients)

Enables a socket to listen for remote connection requests in passive mode.

int
sl_si91x_accept(int socket, const struct sockaddr *addr, socklen_t addr_len)

Accepts a connection request from a remote peer.

int
sl_si91x_accept_async(int socket, accept_callback callback)

Accepts a connection request from the remote peer and registers a callback.

int
sl_si91x_connect(int socket, const struct sockaddr *addr, socklen_t addr_len)

Initiates a connection to a remote socket specified by the addr parameter.

int
sl_si91x_send(int socket, const uint8_t *buffer, size_t buffer_length, int32_t flags)

Sends the data to the remote peer on the given socket.

int
sl_si91x_send_async(int socket, const uint8_t *buffer, size_t buffer_length, int32_t flags, data_transfer_complete_handler callback)

Transmits one or more messages to a socket asynchronously.

int
sl_si91x_sendto(int socket, const uint8_t *buffer, size_t buffer_length, int32_t flags, const struct sockaddr *addr, socklen_t addr_len)

Transmits one or more messages to another socket.

int
sl_si91x_sendto_async(int socket, const uint8_t *buffer, size_t buffer_length, int32_t flags, const struct sockaddr *to_addr, socklen_t to_addr_len, data_transfer_complete_handler callback)

Transmits one or more messages to another socket asynchronously and receives acknowledgement through the registered callback.

int
sl_si91x_send_large_data(int socket, const uint8_t *buffer, size_t buffer_length, int32_t flags)

Sends the data that is greater than MSS size.

int
sl_si91x_recv(int socket, uint8_t *buffer, size_t bufferLength, int32_t flags)

Receives data from a connected socket.

int
sl_si91x_recvfrom(int socket, uint8_t *buffer, size_t buffersize, int32_t flags, struct sockaddr *fromAddr, socklen_t *fromAddrLen)

Receives data from an unconnected socket typically like a UDP socket.

int
sl_si91x_shutdown(int socket, int how)

Disables send or receive on a socket.

int
sl_si91x_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, const struct timeval *timeout, select_callback callback)

Monitors multiple file descriptors, including sockets, for various I/O events, such as readiness for reading or writing, and exceptional conditions.

void
sl_si91x_set_remote_termination_callback(remote_socket_termination_callback callback)

Register callback for remote socket termination event.

int
sl_si91x_set_custom_sync_sockopt(int socket_id, int option_level, int option_name, const void *option_value, socklen_t option_length)

Set SiWx91X specific socket options.

int
sl_si91x_get_custom_sync_sockopt(int socket_id, int option_level, int option_name, void *option_value, socklen_t *option_length)

Get SiWx91X specific socket options.

sl_status_t
sl_si91x_get_socket_info(sl_si91x_socket_info_response_t *socket_info_response)

Retrieve information about currently opened sockets from the network stack.

int16_t
sl_si91x_get_socket_mss(int32_t socketIndex)

Retrieves the Maximum Segment Size (MSS) for a specific socket.

Typedef Documentation#

receive_data_callback#

receive_data_callback )(uint32_t socket, uint8_t *buffer, uint32_t length, const sl_si91x_socket_metadata_t *firmware_socket_response)

This callback is used to read data asynchronously from a socket.

Parameters
N/Asocket

Socket ID.

N/Abuffer

Pointer to the buffer that will store the received data.

N/Alength

Size of the buffer.

N/Afirmware_socket_response

sl_si91x_socket_metadata_t It contains the meta data of the received packet, like IPV4/V6 address and port number.

It is registered when the sl_si91x_socket_async API is called. Returns

  • N/A


Definition at line 64 of file components/device/silabs/si91x/wireless/socket/inc/sl_si91x_socket_types.h

accept_callback#

accept_callback )(int32_t socket, struct sockaddr *addr, uint8_t ip_version)

This callback is used to provide the parameters of a newly accepted connection.

Parameters
N/Asocket

Socket ID of the accepted connection.

N/Aaddr

Address of the remote peer.

N/Aip_version

IP version of the connection.

It is registered when the sl_si91x_accept_async API is called. Returns

  • N/A


Definition at line 81 of file components/device/silabs/si91x/wireless/socket/inc/sl_si91x_socket_types.h

data_transfer_complete_handler#

data_transfer_complete_handler )(int32_t socket, uint16_t length)

This callback is used to indicate the status of a data transfer.

Parameters
N/Asocket

Socket ID.

N/Alength

Number of bytes transferred.

It is registered when either the sl_si91x_send_async or sl_si91x_sendto_async API is called. Returns

  • N/A


Definition at line 93 of file components/device/silabs/si91x/wireless/socket/inc/sl_si91x_socket_types.h

select_callback#

select_callback )(fd_set *fd_read, fd_set *fd_write, fd_set *fd_except, int32_t status)

This callback is used to indicate when an asynchronous response reaches the select request.

Parameters
N/Afd_read

Read file descriptor set.

N/Afd_write

Write file descriptor set.

N/Afd_except

Exception file descriptor set.

N/Astatus

Status of the select request.

It is registered when the sl_si91x_select API is called. Returns

  • N/A


Definition at line 109 of file components/device/silabs/si91x/wireless/socket/inc/sl_si91x_socket_types.h

remote_socket_termination_callback#

remote_socket_termination_callback )(int socket, uint16_t port, uint32_t bytes_sent)

This callback is used to indicate when a remote socket is terminated.

Parameters
N/Asocket

Socket ID.

N/Aport

Port number of the remote socket.

N/Abytes_sent

Number of bytes sent before termination.

It is registered when the sl_si91x_set_remote_termination_callback API is called. Returns

  • N/A


Definition at line 123 of file components/device/silabs/si91x/wireless/socket/inc/sl_si91x_socket_types.h

Function Documentation#

sl_si91x_socket#

int sl_si91x_socket (int family, int type, int protocol)

Creates a new socket.

Parameters
[in]family

Specifies the communication domain for the socket. This selects the protocol family to be used. Accepts values from Socket Address Family. Currently, only AF_INET and AF_INET6 are supported.

[in]type

Specifies the type of the socket, which determines the semantics of communication. Accepts values from Socket Type. Currently, only SOCK_STREAM and SOCK_DGRAM are supported.

[in]protocol

Specifies a particular protocol to be used with the socket. Accepts values from Socket Protocol. Currently, only IPPROTO_TCP, IPPROTO_UDP, and IPPROTO_IP are supported.

Returns

  • int


Definition at line 36 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_socket_async#

int sl_si91x_socket_async (int family, int type, int protocol, receive_data_callback callback)

Creates an asynchronous socket and registers the provided callback.

Parameters
[in]family

Specifies the communication domain for the socket. This selects the protocol family to be used. Accepts values from Socket Address Family. Currently, only AF_INET and AF_INET6 are supported.

[in]type

Specifies the type of the socket, which determines the semantics of communication. Accepts values from Socket Type. Currently, only SOCK_STREAM and SOCK_DGRAM are supported.

[in]protocol

Specifies a particular protocol to be used with the socket. Accepts values from Socket Protocol. Currently, only IPPROTO_TCP, IPPROTO_UDP, and IPPROTO_IP are supported.

[in]callback

A function pointer of type receive_data_callback. This function is called when the socket receives data.

Returns

  • int


Definition at line 50 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_setsockopt_async#

int sl_si91x_setsockopt_async (int32_t socket, int level, int option_name, const void * option_value, socklen_t option_len)

Sets a specified socket option on the identified socket asynchronously.

Parameters
[in]socket

The socket ID.

[in]level

The option level. Accepts values from Socket Option Level.

[in]option_name

The option to be configured. Accepts values from SiWx91x Socket Option Name. Currently, only the following options are supported:

[in]option_value

The value of the parameter.

[in]option_len

The length of the parameter of type socklen_t.

Returns

  • int


Definition at line 77 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_bind#

int sl_si91x_bind (int socket, const struct sockaddr * addr, socklen_t addr_len)

Assigns a local protocol address to a socket.

Parameters
[in]socket

The socket ID.

[in]addr

The address of type sockaddr to which datagrams are to be sent.

[in]addr_len

The length of the socket address of type socklen_t in bytes.

Returns

  • int


Definition at line 91 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_listen#

int sl_si91x_listen (int socket, int max_number_of_clients)

Enables a socket to listen for remote connection requests in passive mode.

Parameters
[in]socket

The socket ID.

[in]max_number_of_clients

The maximum number of clients that the socket can accept.

Returns

  • int


Definition at line 100 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_accept#

int sl_si91x_accept (int socket, const struct sockaddr * addr, socklen_t addr_len)

Accepts a connection request from a remote peer.

Parameters
[in]socket

The socket ID.

[in]addr

The address of type sockaddr to which datagrams are to be sent.

[in]addr_len

The length of the socket address of type socklen_t in bytes.

This function blocks until a client attempts to connect to the server socket. After receiving a connection request, it proceeds.

Returns

  • int


Definition at line 112 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_accept_async#

int sl_si91x_accept_async (int socket, accept_callback callback)

Accepts a connection request from the remote peer and registers a callback.

Parameters
[in]socket

Socket ID.

[in]callback

A function pointer of type accept_callback that will be called when a new client is connected to the server.

This function sets up the server socket to listen for incoming connections and immediately returns without blocking the main program's execution.

Returns

  • int


Definition at line 127 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_connect#

int sl_si91x_connect (int socket, const struct sockaddr * addr, socklen_t addr_len)

Initiates a connection to a remote socket specified by the addr parameter.

Parameters
[in]socket

Socket ID.

[in]addr

Address of type sockaddr to which datagrams are to be sent.

[in]addr_len

Length of the socket address of type socklen_t in bytes.

Returns

  • int


Definition at line 140 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_send#

int sl_si91x_send (int socket, const uint8_t * buffer, size_t buffer_length, int32_t flags)

Sends the data to the remote peer on the given socket.

Parameters
[in]socket

Socket ID.

[in]buffer

Pointer to the buffer containing data to send to the remote peer.

[in]buffer_length

Length of the buffer pointed to by the buffer parameter.

[in]flags

Controls the transmission of the data.

This should be used only when the socket is in a connected state.

Returns

  • int

Note

  • The flags parameter is not currently supported.


Definition at line 159 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_send_async#

int sl_si91x_send_async (int socket, const uint8_t * buffer, size_t buffer_length, int32_t flags, data_transfer_complete_handler callback)

Transmits one or more messages to a socket asynchronously.

Parameters
[in]socket

Socket ID.

[in]buffer

Pointer to the buffer containing data to send to the remote peer

[in]buffer_length

Length of the buffer pointed to by the buffer parameter.

[in]flags

Controls the transmission of the data.

[in]callback

A function pointer of type data_transfer_complete_handler that will be called after complete data transfer.

This should be used only when the socket is in a connected state.

Returns

  • int

Note

  • The flags parameter is not currently supported.


Definition at line 180 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_sendto#

int sl_si91x_sendto (int socket, const uint8_t * buffer, size_t buffer_length, int32_t flags, const struct sockaddr * addr, socklen_t addr_len)

Transmits one or more messages to another socket.

Parameters
[in]socket

Socket ID.

[in]buffer

Pointer to data buffer containing data to send to remote peer.

[in]buffer_length

Length of the buffer pointed to by the buffer parameter.

[in]flags

Controls the transmission of the data.

[in]addr

Address of type sockaddr to which datagrams are to be sent.

[in]addr_len

Length of the socket address of type socklen_t in bytes.

The function can also be called from an unconnected socket, typically like a UDP socket.

Returns

  • int

Note

  • The flags parameter is not currently supported.


Definition at line 207 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_sendto_async#

int sl_si91x_sendto_async (int socket, const uint8_t * buffer, size_t buffer_length, int32_t flags, const struct sockaddr * to_addr, socklen_t to_addr_len, data_transfer_complete_handler callback)

Transmits one or more messages to another socket asynchronously and receives acknowledgement through the registered callback.

Parameters
[in]socket

Socket ID.

[in]buffer

Pointer to data buffer containing data to send to remote peer.

[in]buffer_length

Length of the buffer pointed to by the buffer parameter.

[in]flags

Controls the transmission of the data.

[in]to_addr

Address of type sockaddr to which datagrams are to be sent.

[in]to_addr_len

Length of the socket address of type socklen_t in bytes.

[in]callback

A function pointer of type data_transfer_complete_handler that will be called after complete data transfer.

The function can also be called from an unconnected socket, typically like a UDP socket.

Returns

  • int

Note

  • The flags parameter is not currently supported.


Definition at line 237 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_send_large_data#

int sl_si91x_send_large_data (int socket, const uint8_t * buffer, size_t buffer_length, int32_t flags)

Sends the data that is greater than MSS size.

Parameters
[in]socket

Socket ID.

[in]buffer

Pointer to data buffer containing data to send to remote peer.

[in]buffer_length

Length of the buffer pointed to by the buffer parameter.

[in]flags

Controls the transmission of the data.

Returns

  • int

Note

  • The flags parameter is not currently supported.


Definition at line 259 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_recv#

int sl_si91x_recv (int socket, uint8_t * buffer, size_t bufferLength, int32_t flags)

Receives data from a connected socket.

Parameters
[in]socket

Socket ID.

[in]buffer

Pointer to the buffer to hold the data received from the remote peer.

[in]bufferLength

Length of the buffer pointed to by the buffer parameter.

[in]flags

Controls the reception of the data.

Returns

  • int

Note

  • The flags parameter is not currently supported.


Definition at line 275 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_recvfrom#

int sl_si91x_recvfrom (int socket, uint8_t * buffer, size_t buffersize, int32_t flags, struct sockaddr * fromAddr, socklen_t * fromAddrLen)

Receives data from an unconnected socket typically like a UDP socket.

Parameters
[in]socket

Socket Id.

[in]buffer

Pointer to the buffer to hold the data received from the remote peer.

[in]buffersize

Size of the buffer pointed to by the buffer parameter.

[in]flags

Controls the reception of the data.

[in]fromAddr

Address of remote peer of type sockaddr, from where current packet was received.

[in]fromAddrLen

Pointer that contains remote peer address (fromAddr) length of type socklen_t

Returns

  • int

Note

  • The flags parameter is not currently supported.


Definition at line 295 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_shutdown#

int sl_si91x_shutdown (int socket, int how)

Disables send or receive on a socket.

Parameters
[in]socket

Socket ID that is to be closed.

[in]how

Determines whether the socket is closed based on given socket ID or port number.

  • 0: Close the specified socket.

  • 1: Close all the sockets open on a specified socket's source port number.

Returns

  • int

Note

  • In case of socket being a server socket, the "how" parameter would be ignored and socket shall always be closed based on port number.


Definition at line 315 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_select#

int sl_si91x_select (int nfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, const struct timeval * timeout, select_callback callback)

Monitors multiple file descriptors, including sockets, for various I/O events, such as readiness for reading or writing, and exceptional conditions.

Parameters
[in]nfds

The first nfds descriptors are checked in each set; i.e., the descriptors from 0 through nfds-1.

[inout]readfds

A pointer to a fd_set object that specifies the descriptors to check for files that are ready for reading.

[inout]writefds

A pointer to a fd_set object that specifies the descriptors to check for files that are ready for writing.

[inout]exceptfds

A pointer to a fd_set object that will be watched for exceptions.

[in]timeout

If timeout is not a null pointer, it specifies the maximum interval to wait for the selection to complete.

[in]callback

A function pointer of type select_callback that will be called when asynchronous response reach the select request.

select() allows a program to monitor multiple file descriptors, waiting until one or more of the file descriptors become "ready" for some class of I/O operation (e.g., input possible). A file descriptor is considered ready if it is possible to perform a corresponding I/O operation without blocking.

Returns

  • int

Note

  • The readfds and writefds parameters are modified in the case of callback being NULL. The exceptfds parameter is not currently supported.


Definition at line 343 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_set_remote_termination_callback#

void sl_si91x_set_remote_termination_callback (remote_socket_termination_callback callback)

Register callback for remote socket termination event.

Parameters
[in]callback

A valid function pointer of type remote_socket_termination_callback that will be called when remote socket is terminated.


Definition at line 356 of file components/device/silabs/si91x/wireless/asynchronous_socket/inc/sl_si91x_socket.h

sl_si91x_set_custom_sync_sockopt#

int sl_si91x_set_custom_sync_sockopt (int socket_id, int option_level, int option_name, const void * option_value, socklen_t option_length)

Set SiWx91X specific socket options.

Parameters
[in]socket_id


Identifier for the socket.

[in]option_level


Level at which the option is defined. One of the values from Socket Option Level.

[in]option_name


Name of the option to be set. Currently, ONLY SO_CERT_INDEX, SO_HIGH_PERFORMANCE_SOCKET, SO_TLS_SNI are supported.

[in]option_value


Pointer to the value for the option.

[in]option_length


Length of the option value.

Returns


  • Returns 0 on success or -1 on error (in which case, errno is set appropriately).


Definition at line 88 of file components/service/bsd_socket/si91x_socket/sl_si91x_socket_support.h

sl_si91x_get_custom_sync_sockopt#

int sl_si91x_get_custom_sync_sockopt (int socket_id, int option_level, int option_name, void * option_value, socklen_t * option_length)

Get SiWx91X specific socket options.

Parameters
[in]socket_id


Identifier for the socket.

[in]option_level


Level at which the option is defined. One of the values from Socket Option Level.

[in]option_name


Name of the option to be retrieved. Currently, ONLY SO_CERT_INDEX is supported.

[in]option_value


Pointer to the value for the option.

[in]option_length


Pointer to the size of the option value.

Returns


  • Returns 0 on success, or -1 on error (in which case, errno is set appropriately).


Definition at line 110 of file components/service/bsd_socket/si91x_socket/sl_si91x_socket_support.h

sl_si91x_get_socket_info#

sl_status_t sl_si91x_get_socket_info (sl_si91x_socket_info_response_t * socket_info_response)

Retrieve information about currently opened sockets from the network stack.

Parameters
[out]socket_info_response

Pointer to a sl_si91x_socket_info_response_t structure that will hold the response from the firmware.

Returns

  • sl_status_t

Note

  • The socket IDs in the response are specific to the firmware and should not be used as file descriptors in socket APIs.


Definition at line 125 of file components/service/bsd_socket/si91x_socket/sl_si91x_socket_support.h

sl_si91x_get_socket_mss#

int16_t sl_si91x_get_socket_mss (int32_t socketIndex)

Retrieves the Maximum Segment Size (MSS) for a specific socket.

Parameters
[in]socketIndex

The index of the socket for which the MSS is to be retrieved. This is an integer value that uniquely identifies the socket.

The MSS is the largest amount of data, specified in bytes, that a computer or communications device can handle in a single, unfragmented piece. Returns

  • Returns an int16_t value representing the MSS of the specified socket in bytes.


Definition at line 47 of file components/device/silabs/si91x/wireless/socket/inc/sl_bsd_utility.h