This section contains description about network stack API’s, used to configure the embedded TCP/IP stack of Quessence™ and data transfer over network.

rsi_socket

Prototype int32_t  rsi_socket (int32_t protocolFamily, int32_t type,

int32_t protocol)

Input Arguments int32_t protocolFamily: Configuration for protocol family – IPv4 or IPv6
  • AF_INET: IPv4
  • AF_INET6: IPv6 (not supported currently)

int32_t type: Configuration for socket type UDP or TCP

  • SOCK_STREAM: TCP socket
  • SOCK_DGRM: UDP socket

int32_t protocol: Configuration for SSL or non-SSL socket

  • 0 : non SSL socket
  • 1 : SSL socket
Return Value int32_t: Status of socket creation.
  • Socket Descriptor: Successful creation of socket.
  • -1 : Failure
Description This API is used to create a tcp socket for the protocol family specified.
Example Usage socket (AF_INET, SOCK_STREAM, 1);

rsi_bind

Prototype int32_t  rsi_bind(int32_t sockID, struct sockaddr *localAddress, int32_t addressLength)
Input Arguments int32_t sockID: Socket descriptor

struct sockaddr *localAddress: Pointer to a buffer containing the  address assigned to socket. The format is compatible with BSD socket.

int32_t addressLength: Length of the address in bytes

Return Value int32_t: Status of address assignment to a socket.
  • 0:  Successful address assignment.
  • -1 : Failure
Description This API is used to assign an address(local address) to a socket.
Example Usage bind(client_socket, (struct sockaddr *) &client_addr, sizeof(client_addr));

rsi_connect

Prototype int32_t  rsi_connect (int32_t sockID, struct sockaddr *remoteAddress, int32_t addressLength)
Input Arguments int32_t sockID: Socket descriptor

struct sockaddr *remoteAddress: Pointer to a buffer containing the Remote peer address. The format is compatible with BSD socket.

int32_t addressLength: Length of the address in bytes

Return Value int32_t: Status of socket level connection.
  • 0:  Successful socket connection.
  • -1 : Failure
Description This API is used to connect the socket to specified remote address
Example Usage connect(client_socket, (struct sockaddr *) &server_addr, sizeof(server_addr));

rsi_listen

Prototype int32_t  rsi_listen (int32_t sockID, int32_t backlog)
Input Arguments int32_t sockID: Socket descriptor

int32_t backlog: Maximum length to which the queue of pending connections can hold.

Return Value int32_t: Status of listen request on a socket
  • 0:  Success
  • -1 : Failure
Description This API is used to configure a socket to listen for remote connection request in passive mode .
Example Usage listen(server_socket, 1);

rsi_accept

Prototype int32_t rsi_ accept (int32_t sockID, struct sockaddr *ClientAddress, int32_t *addressLength)
Input Arguments int32_t sockID: Socket descriptor

struct sockaddr *ClientAddress: Pointer to the location to be used for storing the remote peer address. This parameter is populated by the driver on successful connection acceptance. The format is compatible with BSD socket.

int32_t *addressLength: Pointer to the location for storing length of the address in bytes

Return Value int32_t: Status of request to accept a socket connection from a remote peer.
  • Socket Descriptor: Successful creation of socket.
  • -1 : Failure
Description This API is used to accept the connection request from a remote peer. It extracts the connection request from the queue of pending connections on listening socket and accepts it.
Example Usage accept(server_socket, (struct sockaddr *)&client_addr, &addr_size);

rsi_recvfrom

Prototype int32_t rsi_ recvfrom (int32_t sockID, int8_t *buffer, int32_t buffersize, int32_t flags, struct rsi_sockaddr *fromAddr, int32_t *fromAddrLen)
Input Arguments int32_t sockID: Socket descriptor

int8_t *buffer: Pointer to application buffer to hold the received data. This is an output parameter

int32_t buffersize: Size of the buffer supplied.

int32_t flags: Reserved

struct rsi_sockaddr *fromAddr: Pointer to the location for storing the address of the remote peer from where the current packet was received. It is an output parameter.

int32_t *fromAddrLen: Pointer to the location for storing the address length in bytes

Return Value int32_t: Status of receive data.
  • Number of Bytes received: Successful receive
  • -1 : Failure
Description This API is used to receive data from a specified remote peer (address provided in the api argument) on a given socket descriptor.
Example Usage recvfrom(server_socket, recv_buffer, recv_size, 0, (struct sockaddr *)&client_addr, &addr_size);

rsi_recv

Prototype int32_t  recv (int32_t sockID, void *rcvBuffer, int32_t bufferLength, int32_t flags)
Input Arguments int32_t sockID: Socket descriptor

void *rcvbuffer: Pointer to buffer to hold receive data.

int32_t bufferLength: Length of the buffer

int32_t flags: Reserved

Return Value int32_t: Status of receive data
  • Number of Bytes received: : Successful receive .
  • -1 : Failure
Description This API is used to receive data from a remote peer on the specified socket.
Example Usage recv(server_socket, recv_buffer, recv_size, 0);

rsi_sendto

Prototype int32_t  sendto(int32_t sockID, int8_t *msg, int32_t msgLength, int32_t flags, struct rsi_sockaddr *destAddr, int32_t destAddrLen)
Input Arguments int32_t sockID: Socket descriptor

int8_t *msg: Pointer to buffer containing data to send to remote peer

int32_t msgLength: Length of the buffer

int32_t flags: Reserved

struct sockaddr *destAddr: Address of the remote peer to send data.

int32_t *destAddrLen: Length of the address in bytes

Return Value int32_t: Status of data transmission
  • Number of Bytes sent: Successful sent
  • -1 : Failure
Description This API is used to send data to the specified remote peer on a given socket.
Example Usage sendto(client_socket, “Hello from UDP client!!!”, (sizeof(“Hello from UDP client!!!”) – 1), 0, (struct sockaddr *)&server_addr, sizeof(server_addr));

rsi_send

Prototype int32_t  rsi_send(int32_t sockID, const int8_t *msg, int32_t msgLength, int32_t flags)
Input Arguments int32_t sockID: Socket descriptor

int8_t *msg: Pointer to buffer containing data to send to remote peer

int32_t msgLength: Length of the buffer

int32_t flags: Reserved

Return Value int32_t: Status of data transmission
  • Number of Bytes sent: Successfully sent data
  • -1 : Failure
Description This API is used to send data to a remote peer on the specified socket.
Example Usage send(client_socket, “Hello from UDP client!!!”, (sizeof(“Hello from UDP client!!!”) – 1), 0);

rsi_shutdown

Prototype int32_t  rsi_shutdown(int32_t sockID, int32_t how)
Input Arguments int32_t sockID: Socket descriptor

int32_t how: Configuration to decide which sockets to close

  • 0: Close the socket specified by sockID.
  • 1: Close all the sockets open on specified socket’s source port number.  Valid for passively open TCP sockets (listen) with more than one backlogs specified
Return Value int32_t: Status of socket closure request
  • 0: Successful closed socket.
  • -1 : Failure
Description This API is used to close socket(s).
Example Usage shutdown(client_socket,0);

rsi_socket_async

Prototype int32_t  rsi_socket_async(int32_t protocolFamily, int32_t type, int32_t protocol, void (callback*)(uint32_t sock_no, uin8_t *buffer, uint32_t length));
Input Arguments int32_t protocolFamily: Configuration for protocol family – IPv4 or IPv6
  • AF_INET: IPv4
  • AF_INET6: IPv6 (not supported currently)

int32_t type: Configuration for socket type UDP or TCP

  • SOCK_STREAM: TCP socket
  • SOCK_DGRM: UDP socket

int32_t protocol: Configuration for SSL or non-SSL socket

  • 0 : non SSL socket
  • 1 : SSL socket

void callback*: Application callback function which  will be called by driver on reception of receive packet on socket.

Return Value int32_t: Status of socket creation and callback function registration
  • 0: Successful socket creation and callback function registration
  • -1 : Failure
Description This API is used to create a socket and register a callback which will be used by the driver to forward received packets asynchronously to application (on packet reception) without waiting for recv and recvfrom API calls.
Example Usage socket (AF_INET, SOCK_STREAM, 1, recv_callback);

rsi_dns_req

Prototype int32_t rsi_dns_req(uint8_t ip_version, uint8_t *url_name, uint8_t *server_address,  rsi_rsp_dns_query_t *dns_query_resp, uint16_t length)
Input Arguments uint8_t ip_version: Configuration for protocol family – IPv4 or IPv6
  • AF_INET: IPv4
  • AF_INET6: IPv6 (not supported currently)

uint8_t *url_name: Pointer to domain name, to resolve IP address

uint8_t *server_address: Pointer to IP address of DNS server. This parameter is optional if DNS server address is received using DHCP.

rsi_rsp_dns_query_t *dns_query_resp: Pointer to hold DNS query results, this is an output parameter. Refer to the DNS Query Response Structure section for details.

uint16_t length: Length of the results buffer.

Minimum lagth required is 32 bytes.

Return Value int32_t: Status of DNS query request
  • 0: Successfully queried IP address
  • -1: Failure
Description This API is used to query IP address for the given domain name.
Example Usage rsi_dns_req(AF_INET, url_buf, server_addr, &dns_resp_buf, sizeof(dns_resp_buf));