BSD Sockets#

Functions#

int32_t
rsi_web_socket_create(int8_t flags, uint8_t *server_ip_addr, uint16_t server_port, uint16_t device_port, uint8_t *webs_resource_name, uint8_t *webs_host_name, int32_t *socket_id, void(*web_socket_data_receive_notify_callback)(uint32_t sock_no, uint8_t *buffer, uint32_t length))

Create a web socket client. This is a blocking API.

int32_t
rsi_web_socket_send_async(int32_t sockID, uint8_t opcode, int8_t *msg, int32_t msg_length)

Send data from the web socket client. This is a non-blocking API.

int32_t
rsi_web_socket_close(int32_t sockID)

Close the web socket client. This is a non-blocking API.

uint32_t
rsi_network_app_protocol_config(nw_app_protocol protocol, nw_app_config config_type, void *config, uint16_t config_length)

Set the network application protocols configuration. This is a non-blocking API.

int32_t
ROM_WL_rsi_get_application_socket_descriptor(global_cb_t *global_cb_p, int32_t sock_id)

Get the application socket descriptor from module’s socket descriptor. This is a non-blocking API.

int32_t
ROM_WL_rsi_get_primary_socket_id(global_cb_t *global_cb_p, uint16_t port_number)

Get socket descriptor from port_number.
This is a non-blocking API.

uint8_t
ROM_WL_calculate_buffers_required(global_cb_t *global_cb_p, uint8_t type, uint16_t length)

Calculate number of buffers required for the data packet.
This is a non-blocking API.

uint16_t
ROM_WL_calculate_length_to_send(global_cb_t *global_cb_p, uint8_t type, uint8_t buffers)

Calculate the length available in the buffers for the message. This is a non-blocking API.

int32_t

Set the socket configuration parameters. The configurations can be done using the Socket configuration in the rsi_wlan_config.h file.
Using this API is highly recommended. Based on the socket configuration, module will use available buffers effectively.
This is a blocking API.

Function Documentation#

rsi_web_socket_create#

int32_t rsi_web_socket_create (int8_t flags, uint8_t * server_ip_addr, uint16_t server_port, uint16_t device_port, uint8_t * webs_resource_name, uint8_t * webs_host_name, int32_t * socket_id, void(*)(uint32_t sock_no, uint8_t *buffer, uint32_t length) web_socket_data_receive_notify_callback, sock_no, buffer, length)

Create a web socket client. This is a blocking API.

Parameters
TypeDirectionArgument NameDescription
int8_t[in]flags

- Select IP version and security
BIT(0): RSI_IPV6 - Set this bit to enable IPv6, by default it is configured to IPv4
BIT(1): RSI_SSL_ENABLE - Set this bit to enable SSL feature

uint8_t *[in]server_ip_addr

- Web server IP address

uint16_t[in]server_port

- Web server socket port

uint16_t[in]device_port

- Local port

uint8_t *[in]webs_resource_name

- Web resource name

uint8_t *[in]webs_host_name

- Web host name

int32_t *[in]socket_id

- Socket ID

void(*)(uint32_t sock_no, uint8_t *buffer, uint32_t length)[in]web_socket_data_receive_notify_callback

- Callback when data packet is received on the created socket

[out]sock_no

- Application socket ID

[out]buffer

- Buffer pointer

[out]length

- Length of data

Returns

  • 0 - Success

  • Negative Value - Failure (Possible Error Codes - 0xfffffffe, 0xfffffffc)

Note


rsi_web_socket_send_async#

int32_t rsi_web_socket_send_async (int32_t sockID, uint8_t opcode, int8_t * msg, int32_t msg_length)

Send data from the web socket client. This is a non-blocking API.

Parameters
TypeDirectionArgument NameDescription
int32_t[in]sockID

- Application socket ID

uint8_t[in]opcode

- Type of the packet to be included in web socket header

int8_t *[in]msg

- Data

int32_t[in]msg_length

- Data length

Returns

  • 0 - Success

  • Negative Value - Failure

Note


rsi_web_socket_close#

int32_t rsi_web_socket_close (int32_t sockID)

Close the web socket client. This is a non-blocking API.

Parameters
TypeDirectionArgument NameDescription
int32_t[in]sockID

- Socket ID of particular socket

Returns

  • 0 - Success

  • Negative Value - Failure

Note


rsi_network_app_protocol_config#

uint32_t rsi_network_app_protocol_config (nw_app_protocol protocol, nw_app_config config_type, void * config, uint16_t config_length)

Set the network application protocols configuration. This is a non-blocking API.

Parameters
TypeDirectionArgument NameDescription
nw_app_protocol[in]protocol

- The following table lists in below

Protocol

Value

RSI_HTTP

0

nw_app_config[in]config_type

- The following table lists in below

config_type

Value

RSI_CIPHER_SELECTION

0

void *[in]config

- The following table lists in below

Protocol

config_type

config

RSI_HTTP

RSI_CIPHER_SELECTION

Configure the Cipher values as explained on the SSL/TLS Cipher Selection page.

uint16_t[in]config_length

- Length of the config parameter

Returns

  • 0 - Success

  • Non-Zero Value - Failure (Possible Error Codes - 0xffffff82)

Note

  • Precondition - rsi_config_ipaddress() API needs to be called before this API.

  • Examples : rsi_network_app_protocol_config(RSI_HTTP, RSI_CIPHER_SELECTION, &cipher_value, 4);
    cipher_value : (SSL_NEW_CIPHERS | BIT_DHE_RSA_GCM | BIT_ECDHE_RSA_GCM )

  • RSI_WLAN_REQ_NWK_APP_PROTOCOL_CONFIG is introduced to pass network application configurations to firmware.


ROM_WL_rsi_get_application_socket_descriptor#

int32_t ROM_WL_rsi_get_application_socket_descriptor (global_cb_t * global_cb_p, int32_t sock_id)

Get the application socket descriptor from module’s socket descriptor. This is a non-blocking API.

Parameters
TypeDirectionArgument NameDescription
global_cb_t *[in]global_cb_p

- Pointer to the global control block

int32_t[in]sock_id

- Module's socket descriptor

Returns

  • Positive value - Application socket descriptor

  • Negative value - If socket is not found


ROM_WL_rsi_get_primary_socket_id#

int32_t ROM_WL_rsi_get_primary_socket_id (global_cb_t * global_cb_p, uint16_t port_number)

Get socket descriptor from port_number.
This is a non-blocking API.

Parameters
TypeDirectionArgument NameDescription
global_cb_t *[in]global_cb_p

- Pointer to the global control block

uint16_t[in]port_number

- Port number

Returns

  • Positive value - Socket descriptor

  • Negative value - If socket is not found


ROM_WL_calculate_buffers_required#

uint8_t ROM_WL_calculate_buffers_required (global_cb_t * global_cb_p, uint8_t type, uint16_t length)

Calculate number of buffers required for the data packet.
This is a non-blocking API.

Parameters
TypeDirectionArgument NameDescription
global_cb_t *[in]global_cb_p

- Pointer to the global control block

uint8_t[in]type

- Type of socket to create

uint16_t[in]length

- Length of the message

Returns

  • Number of buffers required for the data packet


ROM_WL_calculate_length_to_send#

uint16_t ROM_WL_calculate_length_to_send (global_cb_t * global_cb_p, uint8_t type, uint8_t buffers)

Calculate the length available in the buffers for the message. This is a non-blocking API.

Parameters
TypeDirectionArgument NameDescription
global_cb_t *[in]global_cb_p

- Pointer to the global control block

uint8_t[in]type

- Type of the socket stream

uint8_t[in]buffers

- Available buffers

Returns

  • Length available in the buffers for message


rsi_socket_config#

int32_t rsi_socket_config (void )

Set the socket configuration parameters. The configurations can be done using the Socket configuration in the rsi_wlan_config.h file.
Using this API is highly recommended. Based on the socket configuration, module will use available buffers effectively.
This is a blocking API.

Parameters
TypeDirectionArgument NameDescription
voidN/A


Returns

  • 0 - Success

  • Non-Zero Value - Failure (Possible Error Codes - 0x0021, 0x0025, 0x002C, 0xFF6D)

Note

  • Precondition - rsi_config_ipaddress() API and socket creation should be done before this API is called.

  • The following parameters are provided by user,

    Parameters

    Description

    total socket

    Desired total number of sockets to open

    total_tcp_sockets

    Desired total number of TCP sockets to open

    total_udp_sockets

    Desired total number of UDP sockets to open

    tcp_tx_only_sockets

    Desired total number of TCP sockets to open which are used only for data transmission

    tcp_rx_only_sockets

    Desired total number of TCP sockets to open which are used only for data reception

    udp_tx_only_sockets

    Desired total number of UDP sockets to open which are used only for data transmission

    udp_rx_only_sockets

    Desired total number of UDP sockets to open which are used only for data reception

    tcp_rx_high_performance_sockets

    Desired total number of high performance TCP sockets to open. High performance sockets can be

    ^ allocated with more buffers based on the buffers availability. This option is valid only for TCP
    ^ data receive sockets. Socket can be opened as high performance by setting high performance bit in
    ^ socket create command. tcp_rx_window_size_cap | Desired total to increase the TCP RX window size tcp_ack_window_div_factor | In case of high latency networks to configure the TCP ACK division factor with respective to the
    ^ window size; Increases the ACK frequency for asynchronous sockets
    ^ Note:
    ^ Default value is tcp_rx_window_size_cap.

  • The following conditions must be met:

  • total_sockets <= Maximum allowed sockets(10)

  • (total_tcp_sockets + total_udp_sockets) <= total_sockets

  • (total_tcp_tx_only_sockets + total_tcp_rx_only_sockets) <= total_tcp_sockets

  • (total_udp_tx_only_sockets + total_udp_rx_only_sockets) <= total_udp_sockets

  • total_tcp_rx_high_performance_sockets <= total_tcp_rx_only_sockets

  • Refer to Error Codes for the description of above error codes.