SiWx91x Sockets#

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

Functions#

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

This sl_si91x_socket_async() function creates an asynchronous socket and registers the provided callback.

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

The sl_si91x_socket() function creates a new socket.

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

The sl_si91x_setsockopt_async() function's purpose would be to set the specified socket option on the identified socket asynchronously.

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

The sl_si91x_bind() api assigns the local protocol address to a socket.

int
sl_si91x_listen(int socket, int max_number_of_clients)

The sl_si91x_listen() function listen for socket connections.

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

The purpose of the sl_si91x_accept function is to block until a client attempts to connect to the server socket, once a connection request is received.

int
sl_si91x_accept_async(int socket, accept_callback callback)

The sl_si91x_accept_async() api primary purpose is to set up the server socket to listen for incoming connections and immediately return without blocking the main program's execution.

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

The purpose of this sl_si91x_connect() function is to initiate 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)

The sl_si91x_send() function is used to transmit one or more messages to a socket.

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

The sl_si91x_send_async() function is used to transmit one or more messages to a socket asynchronously.

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

The sl_si91x_sendto() function is used to transmit one or more messages to another socket.

int
sl_si91x_sendto_async(int socket, 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)

The sl_si91x_sendto_async() function is used to transmit one or more messages to another socket asynchronously.

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

Basically sl_si91x_send_large_data() function is used to send the data that is greater than MSS size.

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

The purpose of the sl_si91x_recv function is to receive 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)

The purpose of the sl_si91x_recvfrom function is to receive data from an unconnected socket typically like a UDP socket.

int
sl_si91x_shutdown(int socket, int how)

The purpose of the sl_si91x_shutdown is to disable sends or receives on a socket.

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

The purpose of the sl_si91x_select function is to monitor 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)

A function to register callback for remote socket termination event.

Function Documentation#

sl_si91x_socket_async#

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

This sl_si91x_socket_async() function creates an asynchronous socket and registers the provided callback.

Parameters
[in]family

This specifies a communication domain within which communication will take place; this selects the protocol family which should be used.

[in]type

The socket has the indicate type, which specifies the semantics of communication. Currently defined types are SOCK_STREAM, SOCK_DGRAM.

[in]protocol

The protocol argument specifies a particular protocol to be used with the socket.

[in]callback

A function pointer that will be called when the socket receive the data.

Returns

  • int


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

sl_si91x_socket#

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

The sl_si91x_socket() function creates a new socket.

Parameters
[in]family

This specifies a communication domain within which communication will take place; this selects the protocol family which should be used.

[in]type

The socket has the indicate type, which specifies the semantics of communication. Currently defined types are SOCK_STREAM, SOCK_DGRAM.

[in]protocol

The protocol argument specifies a particular protocol to be used with the socket.

Returns

  • int


Definition at line 56 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 sockID, int level, int option_name, const void * option_value, socklen_t option_len)

The sl_si91x_setsockopt_async() function's purpose would be to set the specified socket option on the identified socket asynchronously.

Parameters
[in]sockID

Socket identification number.

[in]level

Level for which the option is set.

[in]option_name

This parameter is used to specify the particular socket option that may be set.

[in]option_value

Pointer to option data.

[in]option_len

The option_length is a value-result argument, initially containing the size of the buffer pointed to by option_value, and modified on return to indicate the actual size of the value returned. If no option value is to be supplied or returned, optval may be NULL.

Returns

  • int


Definition at line 75 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)

The sl_si91x_bind() api assigns the local protocol address to a socket.

Parameters
[in]socket

The socket_id argument is a socket.

[in]addr

The addr argument is the address is that to which datagrams are to be sent.

[in]addr_len

The addr_len argument indicates the amount of space pointed to by addr, in bytes.

Returns

  • int


Definition at line 92 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)

The sl_si91x_listen() function listen for socket connections.

Parameters
[in]socket

The socket_id argument is a socket.

[in]max_number_of_clients

The maximum number of clients that the socket can accept.

Returns

  • int


Definition at line 103 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)

The purpose of the sl_si91x_accept function is to block until a client attempts to connect to the server socket, once a connection request is received.

Parameters
[in]socket

The socket_id argument is a socket.

[in]addr

The addr argument is used to store the accepted client socket address.

[in]addr_len

The addr_len argument indicates the amount of space pointed to by addr, in bytes.

Returns

  • int


Definition at line 117 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)

The sl_si91x_accept_async() api primary purpose is to set up the server socket to listen for incoming connections and immediately return without blocking the main program's execution.

Parameters
[in]socket

The socket_id argument is a socket.

[in]callback

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

Returns

  • int


Definition at line 129 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)

The purpose of this sl_si91x_connect() function is to initiate a connection to a remote socket specified by the addr parameter.

Parameters
[in]socket

The socket_id argument is a socket.

[in]addr

The addr argument is the address is that to which datagrams are to be sent.

[in]addr_len

The addr_len argument indicates the amount of space pointed to by addr, in bytes.

Returns

  • int


Definition at line 142 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)

The sl_si91x_send() function is used to transmit one or more messages to a socket.

Parameters
[in]socket

The socket_id argument is a socket.

[in]buffer

Pointer to the buffer that receives the data.

[in]buffer_length

Length of the buffer pointed to by the buffer parameter.

[in]flags

Controls the transmission of the data.

The sl_si91x_send() function may be used only when the socket is in a connected state. Returns

  • int

Note

  • The argument flags are not supported currently.


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)

The sl_si91x_send_async() function is used to transmit one or more messages to a socket asynchronously.

Parameters
[in]socket

The socket_id argument is a socket.

[in]buffer

Pointer to the buffer that receives the data.

[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 that will be called when the socket receive the data.

The sl_si91x_send_async() function may be used only when the socket is in a connected state. Returns

  • int

Note

  • The argument flags are not supported currently.


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

sl_si91x_sendto#

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

The sl_si91x_sendto() function is used to transmit one or more messages to another socket.

Parameters
[in]socket

The socket_id argument is a socket.

[in]buffer

Pointer to the buffer that receives the data.

[in]buffer_length

Length of the buffer pointed to by the buffer parameter.

[in]flags

Controls the transmission of the data.

[in]addr

The addr argument is the address is that to which datagrams are to be sent.

[in]addr_len

The addr_len argument indicates the amount of space pointed to by addr, in bytes.

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

  • int

Note

  • The argument flags are not supported currently.


Definition at line 203 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, 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)

The sl_si91x_sendto_async() function is used to transmit one or more messages to another socket asynchronously.

Parameters
[in]socket

The socket_id argument is a socket.

[in]buffer

Pointer to the buffer that receives the data.

[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 the target.

[in]to_addr_len

Size of the address pointed by to_addr.

[in]callback

A function pointer that will be called when the socket receive the data.

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

  • int

Note

  • The argument flags are not supported currently.


Definition at line 231 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)

Basically sl_si91x_send_large_data() function is used to send the data that is greater than MSS size.

Parameters
[in]socket

The socket_id argument is a socket

[in]buffer

Pointer to the buffer that receives the data.

[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 argument flags are not supported currently.


Definition at line 253 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)

The purpose of the sl_si91x_recv function is to receive data from a connected socket.

Parameters
[in]socket

The socket_id argument is a socket

[in]buffer

Pointer to the buffer that receives the data.

[in]bufferLength

Length of the buffer pointed to by the buffer parameter.

[in]flags

Controls the reception of the data.

Returns

  • int

Note

  • The argument flags are not supported currently.


Definition at line 269 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)

The purpose of the sl_si91x_recvfrom function is to receive data from an unconnected socket typically like a UDP socket.

Parameters
[in]socket

The socket_id argument is a socket.

[in]buffer

Pointer to the buffer that receives the data.

[in]buffersize

Size of the buffer pointed to by the buffer parameter.

[in]flags

Controls the reception of the data.

[in]fromAddr

Pointer to a socket address structure from which data is received.

[in]fromAddrLen

The fromAddrLen argument is a value-result argument, initialized to the size of the buffer associated with from_addr, and modified on return to indicate the actual size of the address stored there.

Returns

  • int

Note

  • The argument flags are not supported currently.


Definition at line 290 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)

The purpose of the sl_si91x_shutdown is to disable sends or receives on a socket.

Parameters
[in]socket

Socket FD that is to be closed.

[in]how

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

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 307 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, struct timeval * timeout, select_callback callback)

The purpose of the sl_si91x_select function is to monitor 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 that will be called when the socket receive the data.

It allows you to efficiently manage multiple sockets and determine when they are available for specific I/O operations. Returns

  • int

Note

  • The readfds, writefds are modified incase of callback being NULL. exceptfds are not currently being supported.


Definition at line 329 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)

A function to register callback for remote socket termination event.

Parameters
[in]callback

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


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