SimpleLink Host Driver  0.0.5.1
 All Data Structures Functions Variables Groups
Socket

Macros

#define sl_Ntohl   sl_Htonl /* Reorder the bytes of a 16-bit unsigned value from network order to processor orde. */
 
#define sl_Ntohs   sl_Htons /* Reorder the bytes of a 16-bit unsigned value from network order to processor orde. */
 

Functions

int sl_Socket (int Domain, int Type, int Protocol)
 create an endpoint for communication More...
 
int sl_Close (int sd)
 gracefully close socket More...
 
int sl_Accept (int sd, SlSockAddr_t *addr, SlSocklen_t *addrlen)
 Accept a connection on a socket. More...
 
int sl_Bind (int sd, const SlSockAddr_t *addr, int addrlen)
 assign a name to a socket More...
 
int sl_Listen (int sd, int backlog)
 listen for connections on a socket More...
 
int sl_Connect (int sd, const SlSockAddr_t *addr, int addrlen)
 Initiate a connection on a socket. More...
 
int sl_Select (int nfds, SlFdSet_t *readsds, SlFdSet_t *writesds, SlFdSet_t *exceptsds, struct SlTimeval_t *timeout)
 Monitor socket activity. More...
 
void SL_FD_SET (int fd, SlFdSet_t *fdset)
 Select's SlFdSet_t SET function. More...
 
void SL_FD_CLR (int fd, SlFdSet_t *fdset)
 Select's SlFdSet_t CLR function. More...
 
int SL_FD_ISSET (int fd, SlFdSet_t *fdset)
 Select's SlFdSet_t ISSET function. More...
 
void SL_FD_ZERO (SlFdSet_t *fdset)
 Select's SlFdSet_t ZERO function. More...
 
int sl_SetSockOpt (int sd, int level, int optname, const void *optval, SlSocklen_t optlen)
 set socket options More...
 
int sl_GetSockOpt (int sd, int level, int optname, void *optval, SlSocklen_t *optlen)
 Get socket options. More...
 
int sl_Recv (int sd, void *buf, int Len, int flags)
 read data from TCP socket More...
 
int sl_RecvFrom (int sd, void *buf, int Len, int flags, SlSockAddr_t *from, SlSocklen_t *fromlen)
 read data from socket More...
 
int sl_Send (int sd, const void *buf, int Len, int flags)
 write data to TCP socket More...
 
int sl_SendTo (int sd, const void *buf, int Len, int flags, const SlSockAddr_t *to, SlSocklen_t tolen)
 write data to socket More...
 
unsigned long sl_Htonl (unsigned long val)
 Reorder the bytes of a 32-bit unsigned value. More...
 
unsigned short sl_Htons (unsigned short val)
 Reorder the bytes of a 16-bit unsigned value. More...
 

Detailed Description

Function Documentation

int sl_Accept ( int  sd,
SlSockAddr_t addr,
SlSocklen_t *  addrlen 
)

Accept a connection on a socket.

This function is used with connection-based socket types (SOCK_STREAM). It extracts the first connection request on the queue of pending connections, creates a new connected socket, and returns a new file descriptor referring to that socket. The newly created socket is not in the listening state. The original socket sd is unaffected by this call. The argument sd is a socket that has been created with sl_Socket(), bound to a local address with sl_Bind(), and is listening for connections after a sl_Listen(). The argument addr is a pointer to a sockaddr structure. This structure is filled in with the address of the peer socket, as known to the communications layer. The exact format of the address returned addr is determined by the socket's address family. The addrlen argument is a value-result argument: it should initially contain the size of the structure pointed to by addr, on return it will contain the actual length (in bytes) of the address returned.

Parameters
[in]sdsocket descriptor (handle)
[out]addrthe argument addr is a pointer to a sockaddr structure. This structure is filled in with the address of the peer socket, as known to the communications layer. The exact format of the address returned addr is determined by the socket's address
sockaddr:
- code for the address format. On this version only AF_INET is supported.
- socket address, the length depends on the code format
[out]addrlenthe addrlen argument is a value-result argument: it should initially contain the size of the structure pointed to by addr
Returns
On success, a socket handle. On a non-blocking accept a possible negative value is SL_EAGAIN. On failure, negative value. SL_POOL_IS_EMPTY may be return in case there are no resources in the system In this case try again later or increase MAX_CONCURRENT_ACTIONS
See Also
sl_Socket sl_Bind sl_Listen
Note
belongs to server_side
Warning
int sl_Bind ( int  sd,
const SlSockAddr_t addr,
int  addrlen 
)

assign a name to a socket

This function gives the socket the local address addr. addr is addrlen bytes long. Traditionally, this is called When a socket is created with socket, it exists in a name space (address family) but has no name assigned. It is necessary to assign a local address before a SOCK_STREAM socket may receive connections.

Parameters
[in]sdsocket descriptor (handle)
[in]addrspecifies the destination addrs
sockaddr:
- code for the address format. On this version only AF_INET is supported.
- socket address, the length depends on the code format
[in]addrlencontains the size of the structure pointed to by addr
Returns
On success, zero is returned. On error, a negative error code is returned.
See Also
sl_Socket sl_Accept sl_Listen
Note
belongs to basic_api
Warning
int sl_Close ( int  sd)

gracefully close socket

This function causes the system to release resources allocated to a socket.
In case of TCP, the connection is terminated.

Parameters
[in]sdsocket handle (received in sl_Socket)
Returns
On success, zero is returned. On error, a negative number is returned.
See Also
sl_Socket
Note
belongs to ext_api
Warning
int sl_Connect ( int  sd,
const SlSockAddr_t addr,
int  addrlen 
)

Initiate a connection on a socket.

Function connects the socket referred to by the socket descriptor sd, to the address specified by addr. The addrlen argument specifies the size of addr. The format of the address in addr is determined by the address space of the socket. If it is of type SOCK_DGRAM, this call specifies the peer with which the socket is to be associated; this address is that to which datagrams are to be sent, and the only address from which datagrams are to be received. If the socket is of type SOCK_STREAM, this call attempts to make a connection to another socket. The other socket is specified by address, which is an address in the communications space of the socket.

Parameters
[in]sdsocket descriptor (handle)
[in]addrspecifies the destination addr
sockaddr:
- code for the address format. On this version only AF_INET is supported.
- socket address, the length depends on the code format
[in]addrlencontains the size of the structure pointed to by addr
Returns
On success, a socket handle. On a non-blocking connect a possible negative value is SL_EALREADY. On failure, negative value. SL_POOL_IS_EMPTY may be return in case there are no resources in the system In this case try again later or increase MAX_CONCURRENT_ACTIONS
See Also
sl_Socket
Note
belongs to client_side
Warning
void SL_FD_CLR ( int  fd,
SlFdSet_t fdset 
)

Select's SlFdSet_t CLR function.

Clears current socket descriptor on SlFdSet_t container

int SL_FD_ISSET ( int  fd,
SlFdSet_t fdset 
)

Select's SlFdSet_t ISSET function.

Checks if current socket descriptor is set (TRUE/FALSE)

Returns
Returns TRUE if set, FALSE if unset
void SL_FD_SET ( int  fd,
SlFdSet_t fdset 
)

Select's SlFdSet_t SET function.

Sets current socket descriptor on SlFdSet_t container

void SL_FD_ZERO ( SlFdSet_t fdset)

Select's SlFdSet_t ZERO function.

Clears all socket descriptors from SlFdSet_t

int sl_GetSockOpt ( int  sd,
int  level,
int  optname,
void *  optval,
SlSocklen_t *  optlen 
)

Get socket options.

This function manipulate the options associated with a socket. Options may exist at multiple protocol levels; they are always present at the uppermost socket level.

When manipulating socket options the level at which the option resides and the name of the option must be specified. To manipulate options at the socket level, level is specified as SOL_SOCKET. To manipulate options at any other level the protocol number of the appropriate proto- col controlling the option is supplied. For example, to indicate that an option is to be interpreted by the TCP protocol, level should be set to the protocol number of TCP;

The parameters optval and optlen are used to access optval - ues for setsockopt(). For getsockopt() they identify a buffer in which the value for the requested option(s) are to be returned. For getsockopt(), optlen is a value-result parameter, 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, option_value may be NULL.

Parameters
[in]sdsocket handle
[in]leveldefines the protocol level for this option
[in]optnamedefines the option name to interrogate
[out]optvalspecifies a value for the option
[out]optlenspecifies the length of the option value
Returns
On success, zero is returned. On error, a negative value is returned.
See Also
sl_SetSockOpt
Note
See sl_SetSockOpt belongs to ext_api
Warning
unsigned long sl_Htonl ( unsigned long  val)

Reorder the bytes of a 32-bit unsigned value.

This function is used to Reorder the bytes of a 32-bit unsigned value from processor order to network order.

Parameters
[in]varvariable to reorder
Returns
Return the reorder variable,
See Also
sl_SendTo sl_Bind sl_Connect sl_RecvFrom sl_Accept
Note
belongs to send_api
Warning
unsigned short sl_Htons ( unsigned short  val)

Reorder the bytes of a 16-bit unsigned value.

This function is used to Reorder the bytes of a 16-bit unsigned value from processor order to network order.

Parameters
[in]varvariable to reorder
Returns
Return the reorder variable,
See Also
sl_SendTo sl_Bind sl_Connect sl_RecvFrom sl_Accept
Note
belongs to send_api
Warning
int sl_Listen ( int  sd,
int  backlog 
)

listen for connections on a socket

The willingness to accept incoming connections and a queue limit for incoming connections are specified with listen(), and then the connections are accepted with accept. The listen() call applies only to sockets of type SOCK_STREAM The backlog parameter defines the maximum length the queue of pending connections may grow to.

Parameters
[in]sdsocket descriptor (handle)
[in]backlogspecifies the listen queue depth.
Returns
On success, zero is returned. On error, a negative error code is returned.
See Also
sl_Socket sl_Accept sl_Bind
Note
belongs to server_side
Warning
int sl_Recv ( int  sd,
void *  buf,
int  Len,
int  flags 
)

read data from TCP socket

function receives a message from a connection-mode socket

Parameters
[in]sdsocket handle
[out]bufPoints to the buffer where the message should be stored.
[in]LenSpecifies the length in bytes of the buffer pointed to by the buffer argument. Range: 1-16000 bytes
[in]flagsSpecifies the type of message reception. On this version, this parameter is not supported.
Returns
return the number of bytes received, or a negative value if an error occurred. using a non-blocking recv a possible negative value is SL_EAGAIN. SL_POOL_IS_EMPTY may be return in case there are no resources in the system In this case try again later or increase MAX_CONCURRENT_ACTIONS
See Also
sl_RecvFrom
Note
belongs to recv_api
Warning
Example:
An example of receiving data:
SlSockAddrIn_t LocalAddr;
int AddrSize = sizeof(SlSockAddrIn_t);
int SockID, newSockID;
int Status;
char Buf[RECV_BUF_LEN];
LocalAddr.sin_family = SL_AF_INET;
LocalAddr.sin_port = sl_Htons(5001);
LocalAddr.sin_addr.s_addr = 0;
Addr.sin_family = SL_AF_INET;
Addr.sin_port = sl_Htons(5001);
Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
Status = sl_Listen(SockID, 0);
newSockID = sl_Accept(SockID, (SlSockAddr_t*)&Addr, (SlSocklen_t*) &AddrSize);
Status = sl_Recv(newSockID, Buf, 1460, 0);
int sl_RecvFrom ( int  sd,
void *  buf,
int  Len,
int  flags,
SlSockAddr_t from,
SlSocklen_t *  fromlen 
)

read data from socket

function receives a message from a connection-mode or connectionless-mode socket

Parameters
[in]sdsocket handle
[out]bufPoints to the buffer where the message should be stored.
[in]LenSpecifies the length in bytes of the buffer pointed to by the buffer argument. Range: 1-16000 bytes
[in]flagsSpecifies the type of message reception. On this version, this parameter is not supported.
[in]frompointer to an address structure indicating the source address.
sockaddr:
- code for the address format. On this version only AF_INET is supported.
- socket address, the length depends on the code format
[in]fromlensource address structure size. This parameter MUST be set to the size of the structure pointed to by addr.
Returns
return the number of bytes received, or a negative value if an error occurred. using a non-blocking recv a possible negative value is SL_EAGAIN. SL_RET_CODE_INVALID_INPUT (-2) will be returned if fromlen has incorrect length. SL_POOL_IS_EMPTY may be return in case there are no resources in the system In this case try again later or increase MAX_CONCURRENT_ACTIONS
See Also
sl_Recv
Note
belongs to recv_api
Warning
Example:
An example of receiving data:
SlSockAddrIn_t LocalAddr;
int AddrSize = sizeof(SlSockAddrIn_t);
int SockID;
int Status;
char Buf[RECV_BUF_LEN];
LocalAddr.sin_family = SL_AF_INET;
LocalAddr.sin_port = sl_Htons(5001);
LocalAddr.sin_addr.s_addr = 0;
SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
Status = sl_RecvFrom(SockID, Buf, 1472, 0, (SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize);
int sl_Select ( int  nfds,
SlFdSet_t readsds,
SlFdSet_t writesds,
SlFdSet_t exceptsds,
struct SlTimeval_t timeout 
)

Monitor socket activity.

Select allow 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

Parameters
[in]nfdsthe highest-numbered file descriptor in any of the three sets, plus 1.
[out]writesdssocket descriptors list for write monitoring
[out]readsdssocket descriptors list for read monitoring
[out]exceptsdssocket descriptors list for exception monitoring
[in]timeoutis an upper bound on the amount of time elapsed before select() returns. Null or above 0xffff seconds means infinity timeout. The minimum timeout is 10 milliseconds, less than 10 milliseconds will be set automatically to 10 milliseconds. Max microseconds supported is 0xfffc00.
Returns
On success, select() returns the number of file descriptors contained in the three returned descriptor sets (that is, the total number of bits that are set in readfds, writefds, exceptfds) which may be zero if the timeout expires before anything interesting happens. On error, a negative value is returned. readsds - return the sockets on which Read request will return without delay with valid data. writesds - return the sockets on which Write request will return without delay. exceptsds - return the sockets closed recently. SL_POOL_IS_EMPTY may be return in case there are no resources in the system In this case try again later or increase MAX_CONCURRENT_ACTIONS
See Also
sl_Socket
Note
If the timeout value set to less than 5ms it will automatically set to 5ms to prevent overload of the system belongs to basic_api

Only one sl_Select can be handled at a time. Calling this API while the same command is called from another thread, may result in one of the two scenarios:

  1. The command will wait (internal) until the previous command finish, and then be executed.
  2. There are not enough resources and SL_POOL_IS_EMPTY error will return. In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try again later to issue the command.
Warning
int sl_Send ( int  sd,
const void *  buf,
int  Len,
int  flags 
)

write data to TCP socket

This function is used to transmit a message to another socket. Returns immediately after sending data to device. In case of TCP failure an async event SL_NETAPP_SOCKET_TX_FAILED is going to be received. In case of a RAW socket (transceiver mode), extra 4 bytes should be reserved at the end of the frame data buffer for WLAN FCS

Parameters
[in]sdsocket handle
[in]bufPoints to a buffer containing the message to be sent
[in]Lenmessage size in bytes. Range: 1-1460 bytes
[in]flagsSpecifies the type of message transmission. On this version, this parameter is not supported for TCP. For transceiver mode, the SL_RAW_RF_TX_PARAMS macro can be used to determine transmission parameters (channel,rate,tx_power,preamble)
Returns
Return the number of bytes transmitted, or -1 if an error occurred
See Also
sl_SendTo
Note
belongs to send_api
Warning
Example:
An example of sending data:
int AddrSize = sizeof(SlSockAddrIn_t);
int SockID;
int Status;
char Buf[SEND_BUF_LEN];
Addr.sin_family = SL_AF_INET;
Addr.sin_port = sl_Htons(5001);
Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
Status = sl_Connect(SockID, (SlSockAddr_t *)&Addr, AddrSize);
Status = sl_Send(SockID, Buf, 1460, 0 );
int sl_SendTo ( int  sd,
const void *  buf,
int  Len,
int  flags,
const SlSockAddr_t to,
SlSocklen_t  tolen 
)

write data to socket

This function is used to transmit a message to another socket (connection less socket SOCK_DGRAM, SOCK_RAW). Returns immediately after sending data to device. In case of transmission failure an async event SL_NETAPP_SOCKET_TX_FAILED is going to be received.

Parameters
[in]sdsocket handle
[in]bufPoints to a buffer containing the message to be sent
[in]Lenmessage size in bytes. Range: 1-1460 bytes
[in]flagsSpecifies the type of message transmission. On this version, this parameter is not supported
[in]topointer to an address structure indicating the destination address.
sockaddr:
- code for the address format. On this version only AF_INET is supported.
- socket address, the length depends on the code format
[in]tolendestination address structure size
Returns
Return the number of transmitted bytes, or -1 if an error occurred
See Also
sl_Send
Note
belongs to send_api
Warning
Example:
An example of sending data:
int AddrSize = sizeof(SlSockAddrIn_t);
int SockID;
int Status;
char Buf[SEND_BUF_LEN];
Addr.sin_family = SL_AF_INET;
Addr.sin_port = sl_Htons(5001);
Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
Status = sl_SendTo(SockID, Buf, 1472, 0, (SlSockAddr_t *)&Addr, AddrSize);
int sl_SetSockOpt ( int  sd,
int  level,
int  optname,
const void *  optval,
SlSocklen_t  optlen 
)

set socket options

This function manipulate the options associated with a socket. Options may exist at multiple protocol levels; they are always present at the uppermost socket level.

When manipulating socket options the level at which the option resides and the name of the option must be specified. To manipulate options at the socket level, level is specified as SOL_SOCKET. To manipulate options at any other level the protocol number of the appropriate proto- col controlling the option is supplied. For example, to indicate that an option is to be interpreted by the TCP protocol, level should be set to the protocol number of TCP;

The parameters optval and optlen are used to access optval - ues for setsockopt(). For getsockopt() they identify a buffer in which the value for the requested option(s) are to be returned. For getsockopt(), optlen is a value-result parameter, 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, option_value may be NULL.

Parameters
[in]sdsocket handle
[in]leveldefines the protocol level for this option
[in]optnamedefines the option name to interrogate
[in]optvalspecifies a value for the option
[in]optlenspecifies the length of the option value
Returns
On success, zero is returned. On error, a negative value is returned.
See Also
sl_getsockopt
Note
belongs to basic_api
Warning
Examples:
SL_SO_KEEPALIVE:
Keeps TCP connections active by enabling the periodic transmission of messages
Enable/Disable periodic keep alive.
Default: Enabled, keep alive timeout 300 seconds.
SlSockKeepalive_t enableOption = 1;
sl_SetSockOpt(sd,SOL_SOCKET,SL_SO_KEEPALIVE, &enableOption,sizeof(enableOption)); // Keeps connections active by enabling the periodic transmission of messages
SL_SO_RCVTIMEO:
Sets the timeout value that specifies the maximum amount of time an input function waits until it completes.
Default: No timeout
struct SlTimeval_t timeval;
timeVal.tv_sec = 1; // Seconds
timeVal.tv_usec = 0; // Microseconds. 10000 microseconds resolution
sl_SetSockOpt(sd,SOL_SOCKET,SL_SO_RCVTIMEO, &timeVal, sizeof(timeVal)); // Enable receive timeout
SL_SO_RCVBUF:
Sets tcp max recv window
size = 3000; // bytes
sl_SetSockOpt(sd,SOL_SOCKET,SL_SO_RCVBUF, &size, sizeof(size));
SL_SO_NONBLOCKING:
Sets socket to non-blocking operation
Impact on: connect, accept, send, sendto, recv and recvfrom.
Default: Blocking.
SlSockNonblocking_t enableOption = 1;
sl_SetSockOpt(sd,SOL_SOCKET,SL_SO_NONBLOCKING, &enableOption,sizeof(enableOption)); // Enable/disable nonblocking mode
SL_SO_SECMETHOD + SL_SO_SECURE_MASK:
Sets method to tcp secured socket (SL_SEC_SOCKET)
Default: SL_SO_SEC_METHOD_SSLv3_TLSV1_2
method.secureMethod = SL_SO_SEC_METHOD_SSLV3; // security method we want to use
SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET);
sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SEC_METHOD, &method, sizeof(method));
SL_SO_SECURE_MASK:
Sets specific cipher to tcp secured socket (SL_SEC_SOCKET)
Default: "Best" cipher suitable to method
cipher.secureMask = SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA; // cipher type
SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET);
sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SEC_MASK, &cipher, sizeof(cipher));
SL_SO_SECURE_FILES:
Map programmed files TCP secured socket (SL_SEC_SOCKET)
SlSockSecureFiles_t securedFiles;
securedFiles[SL_BSD_SECURED_PRIVATE_KEY_IDX] = [private key file index]
securedFiles[SL_BSD_SECURED_CERTIFICATE_IDX] = [secured certificate file index]
securedFiles[SL_BSD_SECURED_CA_IDX] = [secured CA file index]
securedFiles[SL_BSD_SECURED_DH_IDX] = [secured DH file index]
sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SECURE_FILES, &securedFiles[0], sizeof(SlSockSecureFiles_t));
SL_SO_CHANGE_CHANNEL:
sets channel in transceiver mode
unsigned long newChannel = 6; // range is 1-13
sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_CHANGE_CHANNEL, &newChannel, sizeof(newChannel));
SL_IP_MULTICAST_TTL:
Set the time-to-live value of outgoing multicast packets for this socket
sets channel in transceiver mode
unsigned char ttl = 20;
sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_MULTICAST_TTL, &ttl, sizeof(ttl));
SL_IP_RAW_RX_NO_HEADER:
Raw socket remove IP header from received data.
Default: data includes ip header
unsigned long header = 1; // remove ip header
sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_RAW_RX_NO_HEADER, &header, sizeof(header));
SL_IP_HDRINCL:
RAW socket only, the IPv4 layer generates an IP header when sending a packet unless
the IP_HDRINCL socket option is enabled on the socket. When it is enabled, the packet must contain an IP header
Default: disabled, IPv4 header generated by Network Stack
unsigned long header = 1;
sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_HDRINCL, &header, sizeof(header));
SL_IP_RAW_IPV6_HDRINCL:
RAW socket only, the IPv6 layer generates an IP header when sending a packet unless
the IP_HDRINCL socket option is enabled on the socket. When it is enabled, the packet must contain an IP header
Default: disabled, IPv4 header generated by Network Stack
unsigned long header = 1;
sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_RAW_IPV6_HDRINCL, &header, sizeof(header));
SL_IP_ADD_MEMBERSHIP:
UDP socket, Join a multicast group
sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
SL_IP_DROP_MEMBERSHIP:
UDP socket, Leave a multicast group
sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
SL_SO_PHY_RATE:
RAW socket, set WLAN PHY transmit rate
unsigned long rate = 6; // see wlan.h RateIndex_e for values
sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_RATE, &rate, sizeof(rate));
SL_SO_PHY_TX_POWER:
RAW socket, set WLAN PHY TX power
unsigned long txpower = 1; // valid range is 1-15
sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_TX_POWER, &txpower, sizeof(txpower));
SL_SO_PHY_NUM_FRAMES_TO_TX:
RAW socket, set number of frames to transmit in transceiver mode
unsigned long numframes = 1;
sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_NUM_FRAMES_TO_TX, &numframes, sizeof(numframes));
SL_SO_PHY_PREAMBLE:
RAW socket, set WLAN PHY preamble
unsigned long preamble = 1;
sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_PREAMBLE, &preamble, sizeof(preamble));
int sl_Socket ( int  Domain,
int  Type,
int  Protocol 
)

create an endpoint for communication

The socket function creates a new socket of a certain socket type, identified by an integer number, and allocates system resources to it. This function is called by the application layer to obtain a socket handle.

Parameters
[in]domainspecifies the protocol family of the created socket. For example: AF_INET for network protocol IPv4 AF_RF for starting transceiver mode. Notes:
  • sending and receiving any packet overriding 802.11 header
  • for optimized power consumption the socket will be started in TX only mode until receive command is activated AF_INET6 for IPv6
[in]typespecifies the communication semantic, one of: SOCK_STREAM (reliable stream-oriented service or Stream Sockets) SOCK_DGRAM (datagram service or Datagram Sockets) SOCK_SEQPACKET (reliable sequenced packet service) SOCK_RAW (raw protocols atop the network layer) when used with AF_RF: SOCK_DGRAM - L2 socket SOCK_RAW - L1 socket - bypass WLAN CCA (Clear Channel Assessment)
[in]protocolspecifies a particular transport to be used with the socket. The most common are IPPROTO_TCP, IPPROTO_SCTP, IPPROTO_UDP, IPPROTO_DCCP. The value 0 may be used to select a default protocol from the selected domain and type
Returns
On success, socket handle that is used for consequent socket operations. A successful return code should be a positive number (int16) On error, a negative (int16) value will be returned specifying the error code. SL_EAFNOSUPPORT (-97) - illegal domain parameter SL_EPROTOTYPE (-91) - illegal type parameter SL_EACCES (-13) - permission denied SL_ENSOCK (-10) - exceeded maximal number of socket SL_ENOMEM (-12) - memory allocation error SL_NX_SOC_ERROR - resources allocation error SL_EINVAL (-22) - error in socket configuration SL_EPROTONOSUPPORT (-93) - illegal protocol parameter SL_EOPNOTSUPP (-95) - illegal combination of protocol and type parameters
See Also
sl_Close
Note
belongs to basic_api
Warning