Modules#

Socket API type definitions

POSIX-compliant Socket#

The Socket component offers a POSIX-compliant alternative to the Wi-SUN stack native socket API. The Portable Operating System Interface (POSIX) is a family of standards specified by the IEEE Computer Society. It promotes compatibility and portability of software solutions and is extremely valuable in the IP world to leverage the various application protocols. In this sense, the socket component can accelerate the integration of existing software libraries on top of the Wi-SUN stack.

The component allows the application to create/destroy sockets, set socket options, and send or receive IP packets using the APIs defined in the POSIX standard. The APIs exposed by the component are thread safe. The graphical configuration interface gives access to a number of configurations like the maximum count of available sockets and the FIFO buffer size. The component includes the socket-related event handler implementations.

To use the component in your application, add it to your project.

Enumerations#

enum
SOL_SOCKET_HANDLER = 0
SOL_SOCKET = 1
}

Socket option level enum type definition.

enum
SO_HANDLER_OVERWRITE_PREV_RCV_BUFF = -1
}

Socket option level enum type definition.

Typedefs#

typedef enum socket_option_level

Socket option level enum type definition.

typedef enum socket_handler_opt

Socket option level enum type definition.

Variables#

Definition of any address for IPv6.

Functions#

int32_t
socket(sock_domain_t domain, sock_type_t type, proto_type_t protocol)

Create an endpoint for ocket ID communication and return.

int32_t
close(int32_t sockid)

Close a socket.

int32_t
bind(int32_t sockid, const struct sockaddr *addr, socklen_t addrlen)

Bind a name to a socket.

int32_t
listen(int32_t sockid, int32_t backlog)

Listen for connections on a socket.

int32_t
accept(int32_t sockid, struct sockaddr *addr, socklen_t *addrlen)

Accept a connection on a socket.

int32_t
connect(int32_t sockid, const struct sockaddr *addr, socklen_t addrlen)

Initiate a connection on a socket.

int32_t
send(int32_t sockid, const void *buff, uint32_t len, int32_t flags)

Send a message on a socket.

int32_t
sendto(int32_t sockid, const void *buff, uint32_t len, int32_t flags, const struct sockaddr *dest_addr, socklen_t addr_len)

Send a message on a socket.

int32_t
recv(int32_t sockid, void *buf, uint32_t len, int32_t flags)

Receive a message from a socket.

int32_t
recvfrom(int32_t sockid, void *buf, uint32_t len, int32_t flags, struct sockaddr *src_addr, socklen_t *addrlen)

Receive messages from a socket.

int32_t
setsockopt(int32_t sockid, int32_t level, int32_t optname, const void *optval, socklen_t optlen)

Set socket option.

int32_t
getsockopt(int32_t sockid, int32_t level, int32_t optname, void *optval, socklen_t *optlen)

Get socket option.

__STATIC_INLINE uint32_t
htonl(uint32_t hostlong)

Convert the long host byte order to network order.

__STATIC_INLINE uint16_t
htons(uint16_t hostshort)

Convert the short host byte order to network order.

__STATIC_INLINE uint32_t
ntohl(uint32_t netlong)

Convert the long network byte order to host byte order.

__STATIC_INLINE uint16_t
ntohs(uint16_t netshort)

Convert the short network byte order to host byte order.

int32_t
inet_pton(sock_domain_t af, const char *src, void *dst)

Convert the IPv4 and IPv6 addresses from text to binary form.

const char *
inet_ntop(sock_domain_t af, const void *src, char *dst, socklen_t size)

Convert IPv4 and IPv6 addresses from binary to text form.

Macros#

#define

Socket API error return value.

#define

Socket API OK return value.

#define
SOCKET_INVALID_ID (SOCKET_RETVAL_ERROR)

Invalid socket ID.

#define

Socket EOF.

#define

Definition of any address for IPv4.

Enumeration Documentation#

socket_option_level#

socket_option_level

Socket option level enum type definition.

Enumerator
SOL_SOCKET_HANDLER

Special Wi-SUN Socket handler options.

SOL_SOCKET

POSIX style.


Definition at line 173 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

socket_handler_opt#

socket_handler_opt

Socket option level enum type definition.

Enumerator
SO_HANDLER_OVERWRITE_PREV_RCV_BUFF

Enable overwriting previous received buffer.


Definition at line 181 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

Typedef Documentation#

socket_option_level_t#

typedef enum socket_option_level socket_option_level_t

Socket option level enum type definition.


Definition at line 178 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

socket_handler_opt_t#

typedef enum socket_handler_opt socket_handler_opt_t

Socket option level enum type definition.


Definition at line 184 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

Variable Documentation#

in6addr_any#

const in6_addr_t in6addr_any

Definition of any address for IPv6.


Definition at line 191 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

Function Documentation#

socket#

int32_t socket (sock_domain_t domain, sock_type_t type, proto_type_t protocol)

Create an endpoint for ocket ID communication and return.

Parameters
[in]domain

The communication domain, this selects the protocol family. It can be: AF_WISUN - Wi-SUN FAN AF_INET6 - External IPv6 network socket (future implementation) AF_INET - External IPv4 network address (future implementation)

[in]type

The communication semantics It can be: SOCK_STREAM - Stream Socket type (TCP) SOCK_DGRAM - Datagram Socket type (UDP) SOCK_RAW - Raw Socket type (ICMP)

[in]protocol

Specifies the particular protocol to be used. It can be: IPPROTO_AUTO - Auto selection SOCK_STREAM -> TCP, SOCK_DGRAM -> UDP IPPROTO_IP - Same then IPPROTO_AUTO IPPROTO_ICMP - Ping IPPROTO_TCP - TCP protocol IPPROTO_UDP - UDP protocol

Socket API supports Wi-SUN FAN and external IP network communications. External handlers can be implemented; Default implementations are weak functions. Created sockets are added to the socket handler automatically. Returns

  • if any error occurred, return with -1, otherwise return with the socket id


Definition at line 222 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

close#

int32_t close (int32_t sockid)

Close a socket.

Parameters
[in]sockid

socket id

Close a socket and remove from the socket handler storage. Returns

  • if any error occurred, return with -1, otherwise return with the socket id


Definition at line 230 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

bind#

int32_t bind (int32_t sockid, const struct sockaddr * addr, socklen_t addrlen)

Bind a name to a socket.

Parameters
[in]sockid

socket id

[in]addr

address structure ptr

[in]addrlen

address structure size

Assigns the address to the socket, referred to by the socket ID, as specified by addr. It is normally necessary to assign a local address using bind() before a SOCK_STREAM socket may receive connections. Returns

  • On success, zero is returned. On error, -1 is returned


Definition at line 242 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

listen#

int32_t listen (int32_t sockid, int32_t backlog)

Listen for connections on a socket.

Parameters
[in]sockid

socket id

[in]backlog

Argument defines the maximum length to which the queue of pending connections for sockid may grow. Not implemented for Wi-SUN, the connection queue size is always 1

Marks the socket referred to by sockid as a passive socket, that is, as a socket that will be used to accept incoming connection requests using accept. Returns

  • On success, zero is returned. On error, -1 is returned


Definition at line 256 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

accept#

int32_t accept (int32_t sockid, struct sockaddr * addr, socklen_t * addrlen)

Accept a connection on a socket.

Parameters
[in]sockid

socket ID

[inout]addr

Is filled in with the address of the peer (remote) socket For Wi-SUN, it shouldn't be NULL ptr, but for external sockets should be.

[inout]addrlen

It is the byte size of the address. For Wi-SUN, it won't be set to the actual size on return.

Used with connection-based socket types (TCP). It extracts the first connection request on the queue of pending connections for the listening socket. Returns

  • On success, return with the socket id for accepted socket, on error -1 is returned.


Definition at line 270 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

connect#

int32_t connect (int32_t sockid, const struct sockaddr * addr, socklen_t addrlen)

Initiate a connection on a socket.

Parameters
[in]sockid

socket id

[inout]addr

If the socket sockid is of type SOCK_DGRAM, addr is the address to which datagrams are sent by default and the only address from which datagrams are received. If the socket is of type SOCK_STREAM, this call attempts to make a connection to the socket that is bound to the address specified by addr.

[inout]addrlen

It is the byte size of the address. For Wi-SUN, it won't be set to the actual size on return.

Connects the socket referred to by the socketid to the address specified by addr. Returns

  • If the connection or binding succeeds, zero is returned. On error, -1 is returned.


Definition at line 285 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

send#

int32_t send (int32_t sockid, const void * buff, uint32_t len, int32_t flags)

Send a message on a socket.

Parameters
[in]sockid

socket ID

[in]buff

buffer pointer to send

[in]len

length of buffer to send

[in]flags

In Wi-SUN domain, the flags is not used.

Preferred with connection-oriented sockets (TCP). Returns

  • On success, these calls return the number of bytes sent. On error, -1 is returned


Definition at line 296 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

sendto#

int32_t sendto (int32_t sockid, const void * buff, uint32_t len, int32_t flags, const struct sockaddr * dest_addr, socklen_t addr_len)

Send a message on a socket.

Parameters
[in]sockid

socket ID

[in]buff

buffer pointer to send

[in]len

length of buffer to send

[in]flags

In Wi-SUN domain, the flags parameter is not used.

[in]dest_addr

destination address ptr, the structure must be prepared for UDP sockets

[in]addr_len

destination address length

Preferred in datagram mode (UDP). Returns

  • On success, these calls return the number of bytes sent. On error, -1 is returned


Definition at line 309 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

recv#

int32_t recv (int32_t sockid, void * buf, uint32_t len, int32_t flags)

Receive a message from a socket.

Parameters
[in]sockid

socket id

[out]buf

destination buffer ptr

[in]len

length of data to read

[in]flags

In Wi-SUN domain, the flags is not used.

Should be used for connection-oriented protocol (TCP) Returns

  • return the number of bytes received, or -1 if an error occurred


Definition at line 321 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

recvfrom#

int32_t recvfrom (int32_t sockid, void * buf, uint32_t len, int32_t flags, struct sockaddr * src_addr, socklen_t * addrlen)

Receive messages from a socket.

Parameters
[in]sockid

socket id

[out]buf

destination buffer ptr

[in]len

length of data to read

[in]flags

In Wi-SUN domain, the flags is not used.

[in]src_addr

Source address

[in]addrlen

length of the source address

Receives data on a socket whether or not it is connection-oriented. Returns

  • return the number of bytes received, or -1 if an error occurred


Definition at line 334 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

setsockopt#

int32_t setsockopt (int32_t sockid, int32_t level, int32_t optname, const void * optval, socklen_t optlen)

Set socket option.

Parameters
[in]sockid

socket ID

[in]level

SO_SOCKET for Wi-SUN socket options, or SO_SOCKET_HANDLER for socket handler options.

[in]optname

Option name. For Wi-SUN: SL_WISUN_SOCKET_OPTION_EVENT_MODE - Option for socket event mode SL_WISUN_SOCKET_OPTION_MULTICAST_GROUP - Option for multicast group SL_WISUN_SOCKET_OPTION_SEND_BUFFER_LIMIT - Option for send buffer limit

[in]optval

Option value structure pointer. For Wi-SUN it is casted to sl_wisun_socket_option_t

[in]optlen

Must be the size of sl_wisun_socket_option_data_t union

This function can set socket properties. Limitation for the Wi-SUN domain are that optlen and level args are not used. optname and optval are cast to the corresponding Wi-SUN types: sl_wisun_socket_option_t and sl_wisun_socket_option_data_t. sl_wisun_socket_option_data_t is a union type to include all of implemented Wi-SUN socket options Returns

  • Return 0 on success, other wise -1


Definition at line 355 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

getsockopt#

int32_t getsockopt (int32_t sockid, int32_t level, int32_t optname, void * optval, socklen_t * optlen)

Get socket option.

Parameters
[in]sockid

socket ID

[in]level

SO_SOCKET for Wi-SUN socket options, or SO_SOCKET_HANDLER for socket handler options.

[in]optname

Option name. For Wi-SUN: SL_WISUN_SOCKET_OPTION_EVENT_MODE - Option for socket event mode SL_WISUN_SOCKET_OPTION_MULTICAST_GROUP - Option for multicast group SL_WISUN_SOCKET_OPTION_SEND_BUFFER_LIMIT - Option for send buffer limit

[out]optval

Destination structure pointer. For Wi-SUN it is casted to sl_wisun_socket_option_t

[in]optlen

Must be the size of sl_wisun_socket_option_data_t union

The function gets socket option by optname, and copies option data to optval ptr. Returns

  • Return 0 on success, other wise -1


Definition at line 372 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

htonl#

__STATIC_INLINE uint32_t htonl (uint32_t hostlong)

Convert the long host byte order to network order.

Parameters
[in]hostlong

Long host integer

This function converts the unsigned integer hostlong from host byte order to network byte order. For Wi-SUN, the conversion is not needed. Dummy implementation Returns

  • Long network integer


Definition at line 382 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

htons#

__STATIC_INLINE uint16_t htons (uint16_t hostshort)

Convert the short host byte order to network order.

Parameters
[in]hostshort

Short host integer

This function converts the unsigned short integer hostshort from host byte order to network byte order. For Wi-SUN, the conversion is not needed. Dummy implementation Returns

  • Short network integer


Definition at line 394 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

ntohl#

__STATIC_INLINE uint32_t ntohl (uint32_t netlong)

Convert the long network byte order to host byte order.

Parameters
[in]netlong

Long network integer

This function converts the unsigned integer netlong from network byte order to host byte order. For Wi-SUN, the conversion is not needed. Dummy implementation Returns

  • Long host integer


Definition at line 406 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

ntohs#

__STATIC_INLINE uint16_t ntohs (uint16_t netshort)

Convert the short network byte order to host byte order.

Parameters
[in]netshort

This function converts the unsigned short integer netshort from the network byte order to host byte order. For Wi-SUN, the conversion is not needed. Dummy implementation Returns

  • Short host integer


Definition at line 418 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

inet_pton#

int32_t inet_pton (sock_domain_t af, const char * src, void * dst)

Convert the IPv4 and IPv6 addresses from text to binary form.

Parameters
[in]af

Address family. The af argument must be either AF_WISUN, AF_INET6 or AF_INET

[in]src

Source string

[out]dst

Destination address pointer

This function converts the character string src into a network address structure in the af address family, then copies the network address structure to dst. For AF_WISUN or AF_INET6, stoip6(src, len, dst) called within the implementation AF_INET (IPv4) case not implemented. Returns

  • 1 on succes, -1 on error (POSIX described the 0 value too)


Definition at line 434 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

inet_ntop#

const char * inet_ntop (sock_domain_t af, const void * src, char * dst, socklen_t size)

Convert IPv4 and IPv6 addresses from binary to text form.

Parameters
[in]af

Address family. The af argument must be either AF_WISUN, AF_INET6 or AF_INET

[in]src

Source address in byte form

[out]dst

Destination buffer ptr

[in]size

Size of the destination buffer.

Converts the network address structure src in the af address family into a character string. The resulting string is copied to the buffer pointed to by dst, which must be a non-null pointer. The caller specifies the number of bytes available in this buffer in the argument size. For AF_WISUN or AF_INET6, stoip6(src, len, dst) called within the implementation AF_INET (IPv4) case not implemented. Returns

  • It returns a non-null pointer to dst. NULL is returned if there was an error


Definition at line 450 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

Macro Definition Documentation#

SOCKET_RETVAL_ERROR#

#define SOCKET_RETVAL_ERROR
Value:
(-1L)

Socket API error return value.


Definition at line 56 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

SOCKET_RETVAL_OK#

#define SOCKET_RETVAL_OK
Value:
(0L)

Socket API OK return value.


Definition at line 59 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

SOCKET_INVALID_ID#

#define SOCKET_INVALID_ID
Value:
(SOCKET_RETVAL_ERROR)

Invalid socket ID.


Definition at line 62 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

SOCKET_EOF#

#define SOCKET_EOF
Value:
(0L)

Socket EOF.


Definition at line 65 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h

INADDR_ANY#

#define INADDR_ANY
Value:
(0UL)

Definition of any address for IPv4.


Definition at line 170 of file /mnt/raid/workspaces/ws.vHmYkJajL/overlay/gsdk/app/wisun/component/socket/socket.h