SimpleLink CC31xx/CC32xx Host Driver  Version 3.0.1.71
Simplifies the implementation of Internet connectivity
Socket

Controls standard client/server sockets programming options and capabilities. More...

Functions

_i16 sl_Socket (_i16 Domain, _i16 Type, _i16 Protocol)
 Create an endpoint for communication. More...
 
_i16 sl_Close (_i16 sd)
 Gracefully close socket. More...
 
_i16 sl_Accept (_i16 sd, SlSockAddr_t *addr, SlSocklen_t *addrlen)
 Accept a connection on a socket. More...
 
_i16 sl_Bind (_i16 sd, const SlSockAddr_t *addr, _i16 addrlen)
 Assign a name to a socket. More...
 
_i16 sl_Listen (_i16 sd, _i16 backlog)
 Listen for connections on a socket. More...
 
_i16 sl_Connect (_i16 sd, const SlSockAddr_t *addr, _i16 addrlen)
 Initiate a connection on a socket. More...
 
_i16 sl_Select (_i16 nfds, SlFdSet_t *readsds, SlFdSet_t *writesds, SlFdSet_t *exceptsds, struct SlTimeval_t *timeout)
 Monitor socket activity. More...
 
_i16 sl_SetSockOpt (_i16 sd, _i16 level, _i16 optname, const void *optval, SlSocklen_t optlen)
 Set socket options. More...
 
_i16 sl_GetSockOpt (_i16 sd, _i16 level, _i16 optname, void *optval, SlSocklen_t *optlen)
 Get socket options. More...
 
_i16 sl_Recv (_i16 sd, void *buf, _i16 len, _i16 flags)
 Read data from TCP socket. More...
 
_i16 sl_RecvFrom (_i16 sd, void *buf, _i16 len, _i16 flags, SlSockAddr_t *from, SlSocklen_t *fromlen)
 Read data from socket. More...
 
_i16 sl_Send (_i16 sd, const void *buf, _i16 len, _i16 flags)
 Write data to TCP socket. More...
 
_i16 sl_SendTo (_i16 sd, const void *buf, _i16 len, _i16 flags, const SlSockAddr_t *to, SlSocklen_t tolen)
 Write data to socket. More...
 
_i16 sl_StartTLS (_i16 sd)
 Initiate TLS connection on a socket. More...
 
_u32 sl_Htonl (_u32 val)
 Reorder the bytes of a 32-bit unsigned value. More...
 
_u16 sl_Htons (_u16 val)
 Reorder the bytes of a 16-bit unsigned value. More...
 
int32_t slNetIfWifi_connEnable (void *ifContext)
 Create and maintains a wifi connection to the local network. More...
 
int16_t slNetIfWifi_connDisable (void *ifContext)
 Gracefully close connection. More...
 
int16_t SlNetIfWifi_socket (void *ifContext, int16_t Domain, int16_t Type, int16_t Protocol, void **sdContext)
 Create an endpoint for communication. More...
 
int32_t SlNetIfWifi_close (int16_t sd, void *sdContext)
 Gracefully close socket. More...
 
int16_t SlNetIfWifi_accept (int16_t sd, void *sdContext, SlNetSock_Addr_t *addr, SlNetSocklen_t *addrlen, uint8_t flags, void **acceptedSdContext)
 Accept a connection on a socket. More...
 
int32_t SlNetIfWifi_bind (int16_t sd, void *sdContext, const SlNetSock_Addr_t *addr, int16_t addrlen)
 Assign a name to a socket. More...
 
int32_t SlNetIfWifi_listen (int16_t sd, void *sdContext, int16_t backlog)
 Listen for connections on a socket. More...
 
int32_t SlNetIfWifi_connect (int16_t sd, void *sdContext, const SlNetSock_Addr_t *addr, SlNetSocklen_t addrlen, uint8_t flags)
 Initiate a connection on a socket. More...
 
int32_t SlNetIfWifi_getSockName (int16_t sd, void *sdContext, SlNetSock_Addr_t *addr, SlNetSocklen_t *addrlen)
 Get local address info by socket descriptor
Returns the local address info of the socket descriptor. More...
 
int32_t SlNetIfWifi_select (void *ifContext, int16_t nfds, SlNetSock_SdSet_t *readsds, SlNetSock_SdSet_t *writesds, SlNetSock_SdSet_t *exceptsds, SlNetSock_Timeval_t *timeout)
 Monitor socket activity. More...
 
int32_t SlNetIfWifi_setSockOpt (int16_t sd, void *sdContext, int16_t level, int16_t optname, void *optval, SlNetSocklen_t optlen)
 Set socket options-. More...
 
int32_t SlNetIfWifi_getSockOpt (int16_t sd, void *sdContext, int16_t level, int16_t optname, void *optval, SlNetSocklen_t *optlen)
 Get socket options. More...
 
int32_t SlNetIfWifi_recv (int16_t sd, void *sdContext, void *buf, uint32_t len, uint32_t flags)
 Read data from TCP socket. More...
 
int32_t SlNetIfWifi_recvFrom (int16_t sd, void *sdContext, void *buf, uint32_t len, uint32_t flags, SlNetSock_Addr_t *from, SlNetSocklen_t *fromlen)
 Read data from socket. More...
 
int32_t SlNetIfWifi_send (int16_t sd, void *sdContext, const void *buf, uint32_t len, uint32_t flags)
 Write data to TCP socket. More...
 
int32_t SlNetIfWifi_sendTo (int16_t sd, void *sdContext, const void *buf, uint32_t len, uint32_t flags, const SlNetSock_Addr_t *to, SlNetSocklen_t tolen)
 Write data to socket. More...
 
int32_t SlNetIfWifi_sockstartSec (int16_t sd, void *sdContext, SlNetSockSecAttrib_t *secAttrib, uint8_t flags)
 Start a security session on an opened socket. More...
 
int32_t SlNetIfWifi_getHostByName (void *ifContext, char *name, const uint16_t nameLen, uint32_t *ipAddr, uint16_t *ipAddrLen, const uint8_t family)
 Get host IP by name
Obtain the IP Address of machine on network, by machine name. More...
 
uint32_t SlNetIfWifi_ping (void *ifContext, const SlNetSock_Addr_t *addr, SlNetSocklen_t addrLen, uint32_t attempts, uint16_t timeout, uint16_t interval, uint16_t packetSize, int16_t flags)
 Performs a ping. More...
 
int32_t SlNetIfWifi_getIPAddr (void *ifContext, SlNetIfAddressType_e addrType, uint16_t *addrConfig, uint32_t *ipAddr)
 Get IP Address of specific interface. More...
 
int32_t SlNetIfWifi_getConnectionStatus (void *ifContext)
 Get interface connection status. More...
 
int32_t SlNetIfWifi_loadSecObj (void *ifContext, uint16_t objType, char *objName, int16_t objNameLen, uint8_t *objBuff, int16_t objBuffLen)
 Load secured buffer to the network stack. More...
 
int32_t SlNetIfWifi_CreateContext (uint16_t ifID, const char *ifName, void **ifContext, SlNetIf_Event_t ifCallback)
 Allocate and store interface data. Registers to interface event handlers. More...
 
int32_t SlNetIfWifi_DeleteContext (uint16_t ifID, void **ifContext)
 Free allocations of interface data. Remove registration of interface event handlers. More...
 

Typedefs

typedef struct SlInAddr_t SlInAddr_t
 
typedef struct SlIn6Addr_t SlIn6Addr_t
 
typedef _i32 SlTime_t
 
typedef _i32 SlSuseconds_t
 
typedef struct SlTimeval_t SlTimeval_t
 
typedef _u16 SlSocklen_t
 
typedef struct SlSockAddr_t SlSockAddr_t
 
typedef struct SlSockAddrIn6_t SlSockAddrIn6_t
 
typedef struct SlSockAddrIn_t SlSockAddrIn_t
 
typedef struct SlFdSet_t SlFdSet_t
 

Enumerations

enum  SlTxInhibitThreshold_e {
  SL_TX_INHIBIT_THRESHOLD_MIN = 1,
  SL_TX_INHIBIT_THRESHOLD_LOW = 2,
  SL_TX_INHIBIT_THRESHOLD_DEFAULT = 3,
  SL_TX_INHIBIT_THRESHOLD_MED = 4,
  SL_TX_INHIBIT_THRESHOLD_HIGH = 5,
  SL_TX_INHIBIT_THRESHOLD_MAX = 6
}
 
enum  slSockTransceiverTXRateTable_e {
  SL_SOCK_TX_RATE_1M = 1,
  SL_SOCK_TX_RATE_2M = 2,
  SL_SOCK_TX_RATE_5_5M = 3,
  SL_SOCK_TX_RATE_11M = 4,
  SL_SOCK_TX_RATE_6M = 6,
  SL_SOCK_TX_RATE_9M = 7,
  SL_SOCK_TX_RATE_12M = 8,
  SL_SOCK_TX_RATE_18M = 9,
  SL_SOCK_TX_RATE_24M = 10,
  SL_SOCK_TX_RATE_36M = 11,
  SL_SOCK_TX_RATE_48M = 12,
  SL_SOCK_TX_RATE_54M = 13,
  SL_SOCK_TX_RATE_MCS_0 = 14,
  SL_SOCK_TX_RATE_MCS_1 = 15,
  SL_SOCK_TX_RATE_MCS_2 = 16,
  SL_SOCK_TX_RATE_MCS_3 = 17,
  SL_SOCK_TX_RATE_MCS_4 = 18,
  SL_SOCK_TX_RATE_MCS_5 = 19,
  SL_SOCK_TX_RATE_MCS_6 = 20,
  SL_SOCK_TX_RATE_MCS_7 = 21,
  SL_SOCK_TX_MAX_NUM_RATES = 0xFF
}
 
enum  SlSockTransceiverRXRates_e {
  SL_SOCK_RX_RATE_1M = 0,
  SL_SOCK_RX_RATE_2M = 1,
  SL_SOCK_RX_RATE_5_5M = 2,
  SL_SOCK_RX_RATE_11M = 3,
  SL_SOCK_RX_RATE_6M = 4,
  SL_SOCK_RX_RATE_9M = 5,
  SL_SOCK_RX_RATE_12M = 6,
  SL_SOCK_RX_RATE_18M = 7,
  SL_SOCK_RX_RATE_24M = 8,
  SL_SOCK_RX_RATE_36M = 9,
  SL_SOCK_RX_RATE_48M = 10,
  SL_SOCK_RX_RATE_54M = 11,
  SL_SOCK_RX_RATE_MCS0 = 12,
  SL_SOCK_RX_RATE_MCS1 = 13,
  SL_SOCK_RX_RATE_MCS2 = 14,
  SL_SOCK_RX_RATE_MCS3 = 15,
  SL_SOCK_RX_RATE_MCS4 = 16,
  SL_SOCK_RX_RATE_MCS5 = 17,
  SL_SOCK_RX_RATE_MCS6 = 18,
  SL_SOCK_RX_RATE_MCS7 = 19,
  SL_SOCK_RX_RATE_MCS7_SGI = 20
}
 
enum  SlSockSecureSocketFilesIndex_e {
  SL_BSD_SECURED_PRIVATE_KEY_IDX = 0,
  SL_BSD_SECURED_CERTIFICATE_IDX,
  SL_BSD_SECURED_CA_IDX,
  SL_BSD_SECURED_DH_IDX
}
 

Variables

SlNetIf_Config_t SlNetIfConfigWifi
 

Detailed Description

Controls standard client/server sockets programming options and capabilities.

Function Documentation

§ sl_Accept()

_i16 sl_Accept ( _i16  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.
- 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 error code.
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

Definition at line 692 of file sl_socket.c.

693 {
694  _SlSockAcceptMsg_u Msg;
695  _SlReturnVal_t RetVal;
696  SlSocketAddrResponse_u AsyncRsp;
697  int ret_pool = 0; // for _SlDrvReleasePoolObj
698 
699  _i16 ObjIdx = MAX_CONCURRENT_ACTIONS;
700 
701  /* verify that this api is allowed. if not allowed then
702  ignore the API execution and return immediately with an error */
703  VERIFY_API_ALLOWED(SL_OPCODE_SILO_SOCKET);
704 
705  Msg.Cmd.Sd = (_u8)sd;
706 
707  if((addr != NULL) && (addrlen != NULL))
708  {
709  /* If addr is present, addrlen has to be provided */
710  Msg.Cmd.Family = (_u8)((sizeof(SlSockAddrIn_t) == *addrlen) ? SL_AF_INET : SL_AF_INET6);
711  }
712  else
713  {
714  /* In any other case, addrlen is ignored */
715  Msg.Cmd.Family = (_u8)0;
716  }
717 
718  ObjIdx = _SlDrvProtectAsyncRespSetting((_u8*)&AsyncRsp, ACCEPT_ID, (_u8)sd & SL_BSD_SOCKET_ID_MASK);
719 
720  if (ObjIdx < 0)
721  {
722  return ObjIdx;
723  }
724 
725  /* send the command */
726  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlAcceptCmdCtrl, &Msg, NULL));
727  VERIFY_PROTOCOL(Msg.Rsp.Sd == (_u8)sd);
728 
729  RetVal = Msg.Rsp.StatusOrLen;
730 
731  if(SL_OS_RET_CODE_OK == RetVal)
732  {
733  /* in case socket is non-blocking one, the async event should be received immediately */
734  if( g_pCB->SocketNonBlocking & (1<<(sd & SL_BSD_SOCKET_ID_MASK) ))
735  {
736  ret_pool = _SlDrvWaitForInternalAsyncEvent(ObjIdx, SL_DRIVER_TIMEOUT_SHORT, SL_OPCODE_SOCKET_ACCEPTASYNCRESPONSE);
737  }
738  else
739  {
740  /* wait for async and get Data Read parameters */
741  ret_pool = _SlDrvWaitForInternalAsyncEvent(ObjIdx,0,0);
742  }
743 
744  RetVal = AsyncRsp.IpV4.StatusOrLen;
745 
746  if (0 <= RetVal)
747  {
748  VERIFY_PROTOCOL(AsyncRsp.IpV4.Sd == (_u8)sd);
749  }
750 
751 
752 #if 0 /* Kept for backup */
753  _SlSocketParseAddress(&AsyncRsp, addr, addrlen);
754 #else
755  if((addr != NULL) && (addrlen != NULL))
756  {
757  addr->sa_family = AsyncRsp.IpV4.Family;
758 
759  if(SL_AF_INET == addr->sa_family)
760  {
761  if( *addrlen == (SlSocklen_t)sizeof( SlSockAddrIn_t ) )
762  {
763  ((SlSockAddrIn_t *)addr)->sin_port = AsyncRsp.IpV4.Port;
764  ((SlSockAddrIn_t *)addr)->sin_addr.s_addr = AsyncRsp.IpV4.Address;
765  }
766  else
767  {
768  *addrlen = 0;
769  }
770  }
771 #ifdef SL_SUPPORT_IPV6
772  else if(SL_AF_INET6 == addr->sa_family)
773  {
774  if( *addrlen == sizeof( SlSockAddrIn6_t ) )
775  {
776  ((SlSockAddrIn6_t *)addr)->sin6_port = AsyncRsp.IpV6.Port ;
777  sl_Memcpy(((SlSockAddrIn6_t *)addr)->sin6_addr._S6_un._S6_u32, AsyncRsp.IpV6.Address, 16);
778  }
779  else
780  {
781  *addrlen = 0;
782  }
783  }
784 #endif
785  }
786 #endif
787  }
788 
789  _SlDrvReleasePoolObj(ObjIdx);
790 
791  if(ret_pool < 0)
792  {
793  return ret_pool;
794  }
795  else
796  {
797  return (_i16)RetVal;
798  }
799 }

§ sl_Bind()

_i16 sl_Bind ( _i16  sd,
const SlSockAddr_t addr,
_i16  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.
- socket address, the length depends on the code format
[in]addrlenContains the size of the structure pointed to by addr
Returns
Zero on success, or negative error code on failure
See also
sl_Socket sl_Accept sl_Listen
Note
belongs to basic_api
Warning

Definition at line 237 of file sl_socket.c.

238 {
239  _SlSockBindMsg_u Msg;
240  _SlCmdCtrl_t CmdCtrl = {0, 0, (_SlArgSize_t)sizeof(SlSocketResponse_t)};
241 
242  /* verify that this api is allowed. if not allowed then
243  ignore the API execution and return immediately with an error */
244  VERIFY_API_ALLOWED(SL_OPCODE_SILO_SOCKET);
245 
246  switch(addr->sa_family)
247  {
248  case SL_AF_INET:
249  CmdCtrl.Opcode = SL_OPCODE_SOCKET_BIND;
250  CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(SlSocketAddrIPv4Command_t);
251  break;
252 #ifdef SL_SUPPORT_IPV6
253  case SL_AF_INET6:
254  CmdCtrl.Opcode = SL_OPCODE_SOCKET_BIND_V6;
255  CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(SlSocketAddrIPv6Command_t);
256  break;
257 #endif
258  case SL_AF_RF:
259  default:
260  return SL_RET_CODE_INVALID_INPUT;
261  }
262 
263  Msg.Cmd.IpV4.LenOrPadding = 0;
264  Msg.Cmd.IpV4.Sd = (_u8)sd;
265 
266  _SlSocketBuildAddress(addr, &Msg.Cmd);
267  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, &Msg, NULL));
268 
269  return Msg.Rsp.StatusOrLen;
270 }

§ sl_Close()

_i16 sl_Close ( _i16  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
Zero on success, or negative error code on failure
See also
sl_Socket
Note
belongs to ext_api
Warning

Definition at line 176 of file sl_socket.c.

177 {
178  _SlSockCloseMsg_u Msg;
179  _i16 ObjIdx = MAX_CONCURRENT_ACTIONS;
180  SlSocketResponse_t AsyncRsp;
181  _SlReturnVal_t RetVal;
182  _u8 bSocketInAction = FALSE;
183 
184  /* verify that this api is allowed. if not allowed then
185  ignore the API execution and return immediately with an error */
186  VERIFY_API_ALLOWED(SL_OPCODE_SILO_SOCKET);
187 
188  Msg.Cmd.Sd = (_u8)sd;
189  _SlDrvMemZero(&AsyncRsp, sizeof(SlSocketResponse_t));
190 
191  /* check if the socket has already action in progress */
192  bSocketInAction = !!(g_pCB->ActiveActionsBitmap & (1<<sd));
193 
194  if (bSocketInAction == FALSE)
195  {
196  ObjIdx = _SlDrvProtectAsyncRespSetting((_u8*)&AsyncRsp, CLOSE_ID, (_u8)(sd & SL_BSD_SOCKET_ID_MASK));
197 
198  if (ObjIdx < 0)
199  {
200  return ObjIdx;
201  }
202  }
203 
204  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlSockCloseCmdCtrl, &Msg, NULL));
205 
206  RetVal = Msg.Rsp.StatusOrLen;
207 
208  if (bSocketInAction == FALSE)
209  {
210  if( SL_RET_CODE_OK == RetVal)
211  {
212  RetVal = _SlDrvWaitForInternalAsyncEvent(ObjIdx, SL_DRIVER_TIMEOUT_LONG, SL_OPCODE_SOCKET_SOCKETCLOSEASYNCEVENT);
213 
214  if(RetVal >= 0)
215  {
216  RetVal = AsyncRsp.StatusOrLen;
217  }
218  }
219 
220  _SlDrvReleasePoolObj(ObjIdx);
221  }
222 
223  return RetVal;
224 }

§ sl_Connect()

_i16 sl_Connect ( _i16  sd,
const SlSockAddr_t addr,
_i16  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.
- 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

Definition at line 449 of file sl_socket.c.

450 {
451  _SlSockConnectMsg_u Msg;
452  _SlReturnVal_t RetVal;
453  _SlCmdCtrl_t CmdCtrl = {0, (_SlArgSize_t)0, (_SlArgSize_t)sizeof(SlSocketResponse_t)};
454  SlSocketResponse_t AsyncRsp;
455  _i16 ObjIdx = MAX_CONCURRENT_ACTIONS;
456 
457  /* verify that this api is allowed. if not allowed then
458  ignore the API execution and return immediately with an error */
459  VERIFY_API_ALLOWED(SL_OPCODE_SILO_SOCKET);
460  _SlDrvMemZero(&AsyncRsp, sizeof(SlSocketResponse_t));
461 
462  switch(addr->sa_family)
463  {
464  case SL_AF_INET :
465  CmdCtrl.Opcode = SL_OPCODE_SOCKET_CONNECT;
466  CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(SlSocketAddrIPv4Command_t);
467  /* Do nothing - cmd already initialized to this type */
468  break;
469 #ifdef SL_SUPPORT_IPV6
470  case SL_AF_INET6:
471  CmdCtrl.Opcode = SL_OPCODE_SOCKET_CONNECT_V6;
472  CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(SlSocketAddrIPv6Command_t);
473  break;
474 #endif
475  case SL_AF_RF:
476  default:
477  return SL_RET_CODE_INVALID_INPUT;
478  }
479 
480  Msg.Cmd.IpV4.LenOrPadding = 0;
481  Msg.Cmd.IpV4.Sd = (_u8)sd;
482 
483  _SlSocketBuildAddress(addr, &Msg.Cmd);
484 
485  ObjIdx = _SlDrvProtectAsyncRespSetting((_u8*)&AsyncRsp, CONNECT_ID, (_u8)(sd & SL_BSD_SOCKET_ID_MASK));
486 
487  if (ObjIdx < 0)
488  {
489  return ObjIdx;
490  }
491 
492  /* send the command */
493  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&CmdCtrl, &Msg, NULL));
494  VERIFY_PROTOCOL(Msg.Rsp.Sd == (_u8)sd);
495 
496  RetVal = Msg.Rsp.StatusOrLen;
497 
498  int ret_pool = 0; // for _SlDrvReleasePoolObj
499  if(SL_RET_CODE_OK == RetVal)
500  {
501  /*In case socket is non-blocking one, the async event should be received immediately */
502  if( g_pCB->SocketNonBlocking & (1<<(sd & SL_BSD_SOCKET_ID_MASK) ))
503  {
504  ret_pool = _SlDrvWaitForInternalAsyncEvent(ObjIdx, SL_DRIVER_TIMEOUT_SHORT, SL_OPCODE_SOCKET_CONNECTASYNCRESPONSE);
505  }
506  else
507  {
508  /* wait for async and get Data Read parameters */
509  ret_pool = _SlDrvWaitForInternalAsyncEvent(ObjIdx, 0, 0);
510  }
511 
512  RetVal = AsyncRsp.StatusOrLen;
513 
514  if (0 <= RetVal)
515  {
516  VERIFY_PROTOCOL(AsyncRsp.Sd == (_u8)sd);
517  }
518  }
519 
520  _SlDrvReleasePoolObj(ObjIdx);
521 
522  if(ret_pool < 0)
523  {
524  return ret_pool;
525  }
526  else
527  {
528  return RetVal;
529  }
530 }

§ sl_GetSockOpt()

_i16 sl_GetSockOpt ( _i16  sd,
_i16  level,
_i16  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 protocol 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 optvalues 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
Zero on success, or negative error code on failure
See also
sl_SetSockOpt
Note
See sl_SetSockOpt Belongs to ext_api
Warning

Definition at line 975 of file sl_socket.c.

976 {
977  _SlGetSockOptMsg_u Msg;
978  _SlCmdExt_t CmdExt;
979 
980  /* verify that this api is allowed. if not allowed then
981  ignore the API execution and return immediately with an error */
982  VERIFY_API_ALLOWED(SL_OPCODE_SILO_SOCKET);
983  if (*optlen == 0)
984  {
985  return SL_EZEROLEN;
986  }
987 
988  _SlDrvResetCmdExt(&CmdExt);
989  CmdExt.RxPayloadLen = (_i16)(*optlen);
990  CmdExt.pRxPayload = optval;
991 
992  Msg.Cmd.Sd = (_u8)sd;
993  Msg.Cmd.Level = (_u8)level;
994  Msg.Cmd.OptionLen = (_u8)(*optlen);
995  Msg.Cmd.OptionName = (_u8)optname;
996 
997  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlGetSockOptCmdCtrl, &Msg, &CmdExt));
998 
999  if (CmdExt.RxPayloadLen < CmdExt.ActualRxPayloadLen)
1000  {
1001  *optlen = Msg.Rsp.OptionLen;
1002  return SL_ESMALLBUF;
1003  }
1004  else
1005  {
1006  *optlen = (_u8)CmdExt.ActualRxPayloadLen;
1007  }
1008  return (_i16)Msg.Rsp.Status;
1009 }

§ sl_Htonl()

_u32 sl_Htonl ( _u32  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]valVariable 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

Definition at line 806 of file sl_socket.c.

807 {
808  _u32 i = 1;
809  _i8 *p = (_i8 *)&i;
810  if (p[0] == 1) /* little endian */
811  {
812  p[0] = ((_i8* )&val)[3];
813  p[1] = ((_i8* )&val)[2];
814  p[2] = ((_i8* )&val)[1];
815  p[3] = ((_i8* )&val)[0];
816  return i;
817  }
818  else /* big endian */
819  {
820  return val;
821  }
822 }

§ sl_Htons()

_u16 sl_Htons ( _u16  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]valVariable 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

Definition at line 827 of file sl_socket.c.

828 {
829  _i16 i = 1;
830  _i8 *p = (_i8 *)&i;
831  if (p[0] == 1) /* little endian */
832  {
833  p[0] = ((_i8* )&val)[1];
834  p[1] = ((_i8* )&val)[0];
835  return (_u16)i;
836  }
837  else /* big endian */
838  {
839  return val;
840  }
841 }

§ sl_Listen()

_i16 sl_Listen ( _i16  sd,
_i16  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
Zero on success, or negative error code on failure
See also
sl_Socket sl_Accept sl_Bind
Note
Belongs to server_side
Warning

Definition at line 658 of file sl_socket.c.

659 {
660  _SlListenMsg_u Msg;
661 
662  /* verify that this api is allowed. if not allowed then
663  ignore the API execution and return immediately with an error */
664  VERIFY_API_ALLOWED(SL_OPCODE_SILO_SOCKET);
665 
666  Msg.Cmd.Sd = (_u8)sd;
667  Msg.Cmd.Backlog = (_u8)backlog;
668 
669  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlListenCmdCtrl, &Msg, NULL));
670  return (_i16)Msg.Rsp.status;
671 }

§ sl_Recv()

_i16 sl_Recv ( _i16  sd,
void *  buf,
_i16  len,
_i16  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
Examples

Definition at line 881 of file sl_socket.c.

882 {
883  _SlRecvMsg_u Msg;
884  _SlCmdExt_t CmdExt;
885  _SlReturnVal_t status;
886 
887  /* verify that this api is allowed. if not allowed then
888  ignore the API execution and return immediately with an error */
889  VERIFY_API_ALLOWED(SL_OPCODE_SILO_SOCKET);
890 
891  _SlDrvResetCmdExt(&CmdExt);
892  CmdExt.RxPayloadLen = Len;
893  CmdExt.pRxPayload = (_u8 *)pBuf;
894 
895  Msg.Cmd.Sd = (_u8)sd;
896  Msg.Cmd.StatusOrLen = (_u16)Len;
897 
898  /* no size truncation in recv path */
899  CmdExt.RxPayloadLen = (_i16)Msg.Cmd.StatusOrLen;
900 
901  Msg.Cmd.FamilyAndFlags = (_u8)(flags & 0x0F);
902 
903  status = _SlDrvDataReadOp((_SlSd_t)sd, (_SlCmdCtrl_t *)&_SlRecvCmdCtrl, &Msg, &CmdExt);
904  if( status != SL_OS_RET_CODE_OK )
905  {
906  return status;
907  }
908 
909  /* if the Device side sends less than expected it is not the Driver's role */
910  /* the returned value could be smaller than the requested size */
911  return (_i16)Msg.Rsp.StatusOrLen;
912 }

§ sl_RecvFrom()

_i16 sl_RecvFrom ( _i16  sd,
void *  buf,
_i16  len,
_i16  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.
- 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

Definition at line 360 of file sl_socket.c.

361 {
362  _SlRecvfromMsg_u Msg;
363  _SlCmdExt_t CmdExt;
364  _i16 RetVal;
365 
366  /* verify that this api is allowed. if not allowed then
367  ignore the API execution and return immediately with an error */
368  VERIFY_API_ALLOWED(SL_OPCODE_SILO_SOCKET);
369 
370  /* RAW transceiver use only sl_Recv */
371  if ((sd & SL_SOCKET_PAYLOAD_TYPE_MASK) == SL_SOCKET_PAYLOAD_TYPE_RAW_TRANCEIVER)
372  {
373  return SL_ERROR_BSD_SOC_ERROR;
374  }
375 
376  _SlDrvResetCmdExt(&CmdExt);
377  CmdExt.RxPayloadLen = Len;
378  CmdExt.pRxPayload = (_u8 *)buf;
379 
380  Msg.Cmd.Sd = (_u8)sd;
381  Msg.Cmd.StatusOrLen = (_u16)Len;
382 
383  /* no size truncation in recv path */
384  CmdExt.RxPayloadLen = (_i16)Msg.Cmd.StatusOrLen;
385 
386  Msg.Cmd.FamilyAndFlags = (_u8)(flags & 0x0F);
387 
388  if(sizeof(SlSockAddrIn_t) == *fromlen)
389  {
390  Msg.Cmd.FamilyAndFlags |= (SL_AF_INET << 4);
391  }
392  else if (sizeof(SlSockAddrIn6_t) == *fromlen)
393  {
394  Msg.Cmd.FamilyAndFlags |= (SL_AF_INET6 << 4);
395  }
396  else
397  {
398  return SL_RET_CODE_INVALID_INPUT;
399  }
400 
401  RetVal = _SlDrvDataReadOp((_SlSd_t)sd, (_SlCmdCtrl_t *)&_SlRecvfomCmdCtrl, &Msg, &CmdExt);
402  if( RetVal != SL_OS_RET_CODE_OK )
403  {
404  return RetVal;
405  }
406 
407  RetVal = Msg.Rsp.IpV4.StatusOrLen;
408 
409  if(RetVal >= 0)
410  {
411  VERIFY_PROTOCOL(sd == (_i16)Msg.Rsp.IpV4.Sd);
412 #if 0
413  _SlSocketParseAddress(&Msg.Rsp, from, fromlen);
414 #else
415  from->sa_family = Msg.Rsp.IpV4.Family;
416  if(SL_AF_INET == from->sa_family)
417  {
418  ((SlSockAddrIn_t *)from)->sin_port = Msg.Rsp.IpV4.Port;
419  ((SlSockAddrIn_t *)from)->sin_addr.s_addr = Msg.Rsp.IpV4.Address;
420  *fromlen = (SlSocklen_t)sizeof(SlSockAddrIn_t);
421  }
422 #ifdef SL_SUPPORT_IPV6
423  else if(SL_AF_INET6 == from->sa_family)
424  {
425  VERIFY_PROTOCOL(*fromlen >= sizeof(SlSockAddrIn6_t));
426 
427  ((SlSockAddrIn6_t *)from)->sin6_port = Msg.Rsp.IpV6.Port;
428  sl_Memcpy(((SlSockAddrIn6_t *)from)->sin6_addr._S6_un._S6_u32, Msg.Rsp.IpV6.Address, 16);
429  *fromlen = sizeof(SlSockAddrIn6_t);
430  }
431 #endif
432 #endif
433  }
434 
435  return (_i16)RetVal;
436 }

§ sl_Select()

_i16 sl_Select ( _i16  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. If trigger mode is enabled the active fdset is the one that was retrieved in the first triggered call. To enable the trigger mode, an handler must be statically registered as slcb_SocketTriggerEventHandler in user.h

Parameters
[in]nfdsThe highest-numbered file descriptor in any of the three sets, plus 1.
[out]readsdsSocket descriptors list for read monitoring and accept monitoring
[out]writesdsSocket descriptors list for connect monitoring only, write monitoring is not supported
[out]exceptsdsSocket descriptors list for exception monitoring, not supported.
[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. In trigger mode the timout fields must be set to zero.
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 10ms it will automatically set to 10ms to prevent overload of the system
Belongs to basic_api

Several threads can call sl_Select at the same time.Calling this API while the same command is called from another thread, may result in one of the following scenarios:

  1. The command will be executed alongside other select callers (success).
  2. The command will wait (internal) until the previous sl_select finish, and then be executed.
  3. 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.

In case all the user sockets are open, sl_Select will exhibit the behavior mentioned in (2) This is due to the fact sl_select supports multiple callers by utilizing one user socket internally. User who wish to ensure multiple select calls at any given time, must reserve one socket out of the 16 given.

Warning
multiple select calls aren't supported when trigger mode is active. The two are mutually exclusive.

Definition at line 1762 of file sl_socket.c.

1763 {
1764  _SlSelectMsg_u Msg;
1765  SlSelectAsyncResponse_t AsyncRsp;
1766  _i16 ObjIdx = MAX_CONCURRENT_ACTIONS;
1767  _i16 ret = 0;
1768 #if ((defined(SL_RUNTIME_EVENT_REGISTERATION) || defined(slcb_SocketTriggerEventHandler)))
1769  _u8 IsNonBlocking = FALSE;
1770 #endif
1771 
1772  /* verify that this API is allowed. if not allowed then
1773  ignore the API execution and return immediately with an error */
1774  VERIFY_API_ALLOWED(SL_OPCODE_SILO_SOCKET);
1775 
1776 #if ((defined(SL_RUNTIME_EVENT_REGISTERATION) || defined(slcb_SocketTriggerEventHandler)))
1777  if(1 == _SlIsEventRegistered(SL_EVENT_HDL_SOCKET_TRIGGER))
1778  {
1779  if( NULL != timeout )
1780  {
1781  /* Set that we are in Non-Blocking mode */
1782  if ( (0 == timeout->tv_sec) && (0 == timeout->tv_usec) )
1783  {
1784  IsNonBlocking = TRUE;
1785  }
1786  else
1787  {
1788  SL_DRV_PROTECTION_OBJ_LOCK_FOREVER();
1789 
1790  /* If there is a trigger select running in the progress abort the new blocking request */
1791  if (g_pCB->SocketTriggerSelect.Info.State > SOCK_TRIGGER_READY)
1792  {
1793  SL_DRV_PROTECTION_OBJ_UNLOCK();
1794  return SL_RET_CODE_SOCKET_SELECT_IN_PROGRESS_ERROR;
1795  }
1796 
1797  SL_DRV_PROTECTION_OBJ_UNLOCK();
1798  }
1799 
1800  if (IsNonBlocking == TRUE)
1801  {
1802  /* return EAGAIN if we alreay have select trigger in progress */
1803  if (g_pCB->SocketTriggerSelect.Info.State == SOCK_TRIGGER_WAITING_FOR_RESP)
1804  {
1805  return SL_ERROR_BSD_EAGAIN;
1806  }
1807  /* return the stored response if already received */
1808  else if (g_pCB->SocketTriggerSelect.Info.State == SOCK_TRIGGER_RESP_RECEIVED)
1809  {
1810  if( ((_i16)g_pCB->SocketTriggerSelect.Resp.Status) >= 0 )
1811  {
1812  if( readsds )
1813  {
1814  readsds->fd_array[0] = g_pCB->SocketTriggerSelect.Resp.ReadFds;
1815  }
1816  if( writesds )
1817  {
1818  writesds->fd_array[0] = g_pCB->SocketTriggerSelect.Resp.WriteFds;
1819  }
1820  }
1821 
1822  /* Now relaese the pool object */
1823  _SlDrvReleasePoolObj(g_pCB->SocketTriggerSelect.Info.ObjPoolIdx);
1824 
1825  g_pCB->SocketTriggerSelect.Info.ObjPoolIdx = MAX_CONCURRENT_ACTIONS;
1826 
1827  /* Reset the socket select trigger object */
1828  g_pCB->SocketTriggerSelect.Info.State = SOCK_TRIGGER_READY;
1829 
1830  return (_i16)g_pCB->SocketTriggerSelect.Resp.Status;
1831  }
1832  }
1833  }
1834  }
1835 #endif
1836 
1837  Msg.Cmd.Nfds = (_u8)nfds;
1838  Msg.Cmd.ReadFdsCount = 0;
1839  Msg.Cmd.WriteFdsCount = 0;
1840 
1841  Msg.Cmd.ReadFds = 0;
1842  Msg.Cmd.WriteFds = 0;
1843 
1844 
1845  if( readsds )
1846  {
1847  Msg.Cmd.ReadFds = (_u16)readsds->fd_array[0];
1848  }
1849  if( writesds )
1850  {
1851  Msg.Cmd.WriteFds = (_u16)writesds->fd_array[0];
1852  }
1853  if( NULL == timeout )
1854  {
1855  Msg.Cmd.tv_sec = 0xffff;
1856  Msg.Cmd.tv_usec = 0xffff;
1857  }
1858  else
1859  {
1860  if( 0xffff <= timeout->tv_sec )
1861  {
1862  Msg.Cmd.tv_sec = 0xffff;
1863  }
1864  else
1865  {
1866  Msg.Cmd.tv_sec = (_u16)timeout->tv_sec;
1867  }
1868 
1869  /* convert to milliseconds */
1870  timeout->tv_usec = timeout->tv_usec >> 10;
1871 
1872  if( 0xffff <= timeout->tv_usec )
1873  {
1874  Msg.Cmd.tv_usec = 0xffff;
1875  }
1876  else
1877  {
1878  Msg.Cmd.tv_usec = (_u16)timeout->tv_usec;
1879  }
1880 
1881  }
1882 
1883  /* Use Obj to issue the command, if not available try later */
1884  ObjIdx = _SlDrvProtectAsyncRespSetting((_u8*)&AsyncRsp, SELECT_ID, SL_MAX_SOCKETS);
1885 
1886  if (ObjIdx < 0)
1887  {
1888  return ObjIdx;
1889  }
1890 
1891  /* send the command */
1892  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlSelectCmdCtrl, &Msg, NULL));
1893 
1894  if(SL_OS_RET_CODE_OK == (_i16)Msg.Rsp.status)
1895  {
1896  ret = _SlDrvWaitForInternalAsyncEvent(ObjIdx,0,0);
1897 
1898  Msg.Rsp.status = (_i16)AsyncRsp.Status;
1899 
1900  /* this code handles the socket trigger mode case */
1901 #if((defined(SL_RUNTIME_EVENT_REGISTERATION) || defined(slcb_SocketTriggerEventHandler)))
1902  if(1 == _SlIsEventRegistered(SL_EVENT_HDL_SOCKET_TRIGGER))
1903  {
1904  /* if no data returned and we are in trigger mode,
1905  send another select cmd but now with timeout infinite,
1906  and return immediately with EAGAIN to the user */
1907  if ((IsNonBlocking == TRUE) && (AsyncRsp.Status == 0))
1908  {
1909  /* set the select trigger-in-progress bit */
1910  g_pCB->SocketTriggerSelect.Info.State = SOCK_TRIGGER_WAITING_FOR_RESP;
1911 
1912  Msg.Cmd.tv_sec = 0xffff;
1913  Msg.Cmd.tv_usec = 0xffff;
1914 
1915  /* Release pool object and try to take another call */
1916  _SlDrvReleasePoolObj(ObjIdx);
1917 
1918  if(ret < 0)
1919  {
1920  return ret;
1921  }
1922 
1923  /* Use Obj to issue the command, if not available try later */
1924  ObjIdx = _SlDrvProtectAsyncRespSetting((_u8*)&g_pCB->SocketTriggerSelect.Resp, SELECT_ID, SL_MAX_SOCKETS);
1925 
1926  if (MAX_CONCURRENT_ACTIONS == ObjIdx)
1927  {
1928  return SL_POOL_IS_EMPTY;
1929  }
1930 
1931  /* Save the pool index to be released only after the user read the response */
1932  g_pCB->SocketTriggerSelect.Info.ObjPoolIdx = ObjIdx;
1933 
1934  /* send the command */
1935  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlSelectCmdCtrl, &Msg, NULL));
1936  return SL_ERROR_BSD_EAGAIN;
1937 
1938  }
1939  }
1940 #endif
1941 
1942  if( ((_i16)Msg.Rsp.status) >= 0 )
1943  {
1944  if( readsds )
1945  {
1946  readsds->fd_array[0] = AsyncRsp.ReadFds;
1947  }
1948  if( writesds )
1949  {
1950  writesds->fd_array[0] = AsyncRsp.WriteFds;
1951  }
1952  }
1953  }
1954 
1955  _SlDrvReleasePoolObj(ObjIdx);
1956 
1957  if(ret < 0)
1958  {
1959  return ret;
1960  }
1961 
1962  return (_i16)Msg.Rsp.status;
1963 }
void slcb_SocketTriggerEventHandler(SlSockTriggerEvent_t *pSlSockTriggerEvent)
Socket trigger routine. This routine will notify the application that a netwrok activity has been com...

§ sl_Send()

_i16 sl_Send ( _i16  sd,
const void *  buf,
_i16  len,
_i16  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_SOCKET_TX_FAILED_EVENT 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.
[in]flagsSpecifies the type of message transmission. On this version, this parameter is not supported for TCP. For transceiver mode, the SL_WLAN_RAW_RF_TX_PARAMS macro can be used to determine transmission parameters (channel,rate,tx_power,preamble) -rate need to be define using slSockTransceiverTXRateTable_e
Returns
On success, number of transmitted bytes is return, or negative error code on failure
See also
sl_SendTo
Note
Belongs to send_api
Warning
Example

Definition at line 594 of file sl_socket.c.

595 {
596  _SlSendMsg_u Msg;
597  _SlCmdExt_t CmdExt;
598  _i16 RetVal;
599  _u32 tempVal;
600 
601  /* verify that this api is allowed. if not allowed then
602  ignore the API execution and return immediately with an error */
603  VERIFY_API_ALLOWED(SL_OPCODE_SILO_SOCKET);
604 
605  _SlDrvResetCmdExt(&CmdExt);
606  CmdExt.TxPayload1Len = (_u16)Len;
607  CmdExt.pTxPayload1 = (_u8 *)pBuf;
608 
609  /* Only for RAW transceiver type socket, relay the flags parameter in the 2 bytes (4 byte aligned) before the actual payload */
610  if ((sd & SL_SOCKET_PAYLOAD_TYPE_MASK) == SL_SOCKET_PAYLOAD_TYPE_RAW_TRANCEIVER)
611  {
612  tempVal = (_u32)flags;
613  CmdExt.pRxPayload = (_u8 *)&tempVal;
614  CmdExt.RxPayloadLen = -4; /* the (-) sign is used to mark the rx buff as output buff as well*/
615  }
616  else
617  {
618  CmdExt.pRxPayload = NULL;
619  if (Len < 1)
620  {
621  /* ignore */
622  return 0;
623  }
624  }
625 
626  Msg.Cmd.StatusOrLen = Len;
627  Msg.Cmd.Sd = (_u8)sd;
628  Msg.Cmd.FamilyAndFlags |= flags & 0x0F;
629 
630  RetVal = _SlDrvDataWriteOp((_u8)sd, (_SlCmdCtrl_t *)&_SlSendCmdCtrl, &Msg, &CmdExt);
631  if(SL_OS_RET_CODE_OK != RetVal)
632  {
633  return RetVal;
634  }
635 
636  return (_i16)Len;
637 }

§ sl_SendTo()

_i16 sl_SendTo ( _i16  sd,
const void *  buf,
_i16  len,
_i16  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_SOCKET_TX_FAILED_EVENT 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.
[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.
- socket address, the length depends on the code format
[in]tolenDestination address structure size
Returns
On success, number of transmitted bytes is return, or negative error code on failure
See also
sl_Send
Note
Belongs to send_api
Warning
Example

Definition at line 283 of file sl_socket.c.

284 {
285  _SlSendtoMsg_u Msg;
286  _SlCmdCtrl_t CmdCtrl = {0, 0, 0};
287  _SlCmdExt_t CmdExt;
288  _i16 RetVal;
289 
290  /* verify that this api is allowed. if not allowed then
291  ignore the API execution and return immediately with an error */
292  VERIFY_API_ALLOWED(SL_OPCODE_SILO_SOCKET);
293  /* RAW transceiver use only sl_Send */
294  if ((sd & SL_SOCKET_PAYLOAD_TYPE_MASK) == SL_SOCKET_PAYLOAD_TYPE_RAW_TRANCEIVER)
295  {
296  return SL_ERROR_BSD_SOC_ERROR;
297  }
298  else
299  {
300  if (Len < 1)
301  {
302  /* ignore */
303  return 0;
304  }
305  }
306 
307  _SlDrvResetCmdExt(&CmdExt);
308  CmdExt.TxPayload1Len = (_u16)Len;
309  CmdExt.pTxPayload1 = (_u8 *)pBuf;
310 
311  switch(to->sa_family)
312  {
313  case SL_AF_INET:
314  CmdCtrl.Opcode = SL_OPCODE_SOCKET_SENDTO;
315  CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(SlSocketAddrIPv4Command_t);
316  break;
317 #ifdef SL_SUPPORT_IPV6
318  case SL_AF_INET6:
319  CmdCtrl.Opcode = SL_OPCODE_SOCKET_SENDTO_V6;
320  CmdCtrl.TxDescLen = (_SlArgSize_t)sizeof(SlSocketAddrIPv6Command_t);
321  break;
322 #endif
323  case SL_AF_RF:
324  default:
325  return SL_RET_CODE_INVALID_INPUT;
326  }
327 
328  Msg.Cmd.IpV4.LenOrPadding = Len;
329  Msg.Cmd.IpV4.Sd = (_u8)sd;
330  _SlSocketBuildAddress(to, &Msg.Cmd);
331  Msg.Cmd.IpV4.FamilyAndFlags |= flags & 0x0F;
332 
333  RetVal = _SlDrvDataWriteOp((_SlSd_t)sd, &CmdCtrl, &Msg, &CmdExt);
334  if(SL_OS_RET_CODE_OK != RetVal)
335  {
336  return RetVal;
337  }
338 
339  return (_i16)Len;
340 }

§ sl_SetSockOpt()

_i16 sl_SetSockOpt ( _i16  sd,
_i16  level,
_i16  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
  • SL_SOL_SOCKET - Socket level configurations (L4, transport layer)
  • SL_IPPROTO_IP - IP level configurations (L3, network layer)
  • SL_SOL_PHY_OPT - Link level configurations (L2, link layer)
[in]optnameDefines the option name to interrogate
  • SL_SOL_SOCKET
  • SL_SO_KEEPALIVE
    Enable/Disable periodic keep alive. Keeps TCP connections active by enabling the periodic transmission of messages
    Timeout is 5 minutes.
    Default: Enabled
    This options takes SlSockKeepalive_t struct as parameter
  • SL_SO_KEEPALIVETIME
    Set keep alive timeout. Value is in seconds
    Default: 5 minutes
  • SL_SO_RX_NO_IP_BOUNDARY
    Enable/Disable rx ip boundary. In connectionless socket (udp/raw), unread data is dropped (when recvfrom len parameter < data size), Enable this option in order to read the left data on the next recvfrom iteration Default: Disabled, IP boundary kept,
    This options takes SlSockRxNoIpBoundary_t struct as parameter
  • SL_SO_RCVTIMEO
    Sets the timeout value that specifies the maximum amount of time an input function waits until it completes.
    Default: No timeout
    This options takes SlTimeval_t struct as parameter
  • SL_SO_SNDTIMEO
    Sets the timeout value that specifies the maximum amount of time an output function waits until it completes.
    Default: No timeout
    This options takes SlTimeval_t struct as parameter
  • SL_SO_RCVBUF
    Sets tcp max recv window size.
    This options takes SlSockWinsize_t struct as parameter
  • SL_SO_NONBLOCKING
    Sets socket to non-blocking operation Impacts: connect, accept, send, sendto, recv and recvfrom.
    Default: Blocking. This options takes SlSockNonblocking_t struct as parameter
  • SL_SO_SECMETHOD
    Sets method to tcp secured socket (SL_SEC_SOCKET)
    Default: SL_SO_SEC_METHOD_SSLv3_TLSV1_2
    This options takes SlSockSecureMethod_t struct as parameter
  • SL_SO_SECURE_MASK
    Sets specific cipher to tcp secured socket (SL_SEC_SOCKET)
    Default: "Best" cipher suitable to method
    This options takes SlSockSecureMask_t struct as parameter
  • SL_SO_SECURE_FILES_CA_FILE_NAME
    Map secured socket to CA file by name
    This options takes _u8 buffer as parameter
  • SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME
    Map secured socket to private key by name
    This options takes _u8 buffer as parameter
  • SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME
    Map secured socket to certificate file by name
    This options takes _u8 buffer as parameter
  • SL_SO_SECURE_FILES_DH_KEY_FILE_NAME
    Map secured socket to Diffie Hellman file by name
    This options takes _u8 buffer as parameter
  • SL_SO_CHANGE_CHANNEL
    Sets channel in transceiver mode. This options takes _u32 as channel number parameter
  • SL_SO_SECURE_ALPN
    Sets the ALPN list. the parameter is a bit map consist of or of the following values - SL_SECURE_ALPN_H1 SL_SECURE_ALPN_H2 SL_SECURE_ALPN_H2C SL_SECURE_ALPN_H2_14 SL_SECURE_ALPN_H2_16 SL_SECURE_ALPN_FULL_LIST Use getsockopt with the SL_SO_SECURE_ALPN to indicate what protocol is picked by the server after the connection. the bit that stayed set is the one the server picked, if no bit is set, then the server did not pick any protocol.
  • SL_SO_SECURE_ALPN_GENERAL
    Set one free text protocol name - can be used alone too add the ALPN extension to the client hello message and also can be combined with the list of fixed ALPN protocol names if used along with SL_SO_SECURE_ALPN option. This option is available only in client mode. Errors that could return from usage of this API- SL_ERROR_BSD_ESOCKTNOSUPPORT - been used on non tcp socket or server accept socket SL_ERROR_BSD_ESECNOTALLOWEDWHENLISTENING - cannot be used on listener socket SL_ERROR_BSD_EINVAL - length of ALPN name must be less than 256 bytes To retrieve the resault from the server after connection (indicate if this protocol been selected or not), use getsockopt with this opt ID. If the SL_SO_SECURE_ALPN is also used, issue a getsockopt with the SL_SO_SECURE_ALPN, to indicate if the server picked one of the fixed protocol names.
  • SL_SO_SECURE_EXT_CLIENT_CHLNG_RESP
    Set with no parameter to indicate that the client uses external signature using netapp request.
    needs netapp request handler
  • SL_SO_SECURE_DOMAIN_NAME_VERIFICATION
    Set a domain name, to check in ssl client connection.
  • SL_SO_SECURE_ENABLE_OCSP
    Enable OCSP check on a secured client socket - supports OCSP legacy,stapling and stapling v2. the method is automatically negotiated with the server.
  • SL_IPPROTO_IP
  • SL_IP_MULTICAST_TTL
    Set the time-to-live value of outgoing multicast packets for this socket.
    This options takes _u8 as parameter
  • SL_IP_ADD_MEMBERSHIP
    UDP socket, Join a multicast group.
    This options takes SlSockIpMreq_t struct as parameter
  • SL_IP_DROP_MEMBERSHIP
    UDP socket, Leave a multicast group
    This options takes SlSockIpMreq_t struct as parameter
  • SL_IP_RAW_RX_NO_HEADER
    Raw socket remove IP header from received data.
    Default: data includes ip header
    This options takes _u32 as parameter
  • 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
    This options takes _u32 as parameter
  • SL_IP_RAW_IPV6_HDRINCL (inactive)
    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
    This options takes _u32 as parameter
  • SL_SOL_PHY_OPT
  • SL_SO_PHY_RATE
    RAW socket, set WLAN PHY transmit rate
    The values are based on SlWlanRateIndex_e
    This options takes _u32 as parameter
  • SL_SO_PHY_TX_POWER
    RAW socket, set WLAN PHY TX power
    Valid rage is 1-15
    This options takes _u32 as parameter
  • SL_SO_PHY_NUM_FRAMES_TO_TX
    RAW socket, set number of frames to transmit in transceiver mode. Default: 1 packet This options takes _u32 as parameter
  • SL_SO_PHY_PREAMBLE
    RAW socket, set WLAN PHY preamble for Long/Short
    This options takes _u32 as parameter
  • SL_SO_PHY_TX_INHIBIT_THRESHOLD
    RAW socket, set WLAN Tx Set CCA threshold.
    The values are based on SlTxInhibitThreshold_e
    This options takes _u32 as parameter
  • SL_SO_PHY_TX_TIMEOUT
    RAW socket, set WLAN Tx changes the TX timeout (lifetime) of transceiver frames.
    Value in Ms, maximum value is 100ms
    This options takes _u32 as parameter
  • SL_SO_PHY_ALLOW_ACKS
    RAW socket, set WLAN Tx Enable sending ACKs in transceiver mode
    0 = disabled / 1 = enabled
    This options takes _u32 as parameter
  • SL_SO_LINGER
    Socket lingers on close pending remaining send/receive packets
[in]optvalSpecifies a value for the option
[in]optlenSpecifies the length of the option value
Persistent
All params are Non- Persistent
Returns
Zero on success, or negative error code on failure
See also
sl_getsockopt
Note
Belongs to basic_api
Warning
Examples
  • SL_SO_KEEPALIVE (disable Keepalive):
    SlSockKeepalive_t enableOption;
    enableOption.KeepaliveEnabled = 0;
    sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_KEEPALIVE, (_u8 *)&enableOption,sizeof(enableOption));

  • SL_SO_KEEPALIVETIME (Set Keepalive timeout):
    _i16 Status;
    _u32 TimeOut = 120;
    sl_SetSockOpt(Sd, SL_SOL_SOCKET, SL_SO_KEEPALIVETIME,( _u8*) &TimeOut, sizeof(TimeOut));

  • SL_SO_RX_NO_IP_BOUNDARY (disable boundary):
    enableOption.RxIpNoBoundaryEnabled = 1;
    sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_RX_NO_IP_BOUNDARY, (_u8 *)&enableOption,sizeof(enableOption));

  • SL_SO_RCVTIMEO:
    struct SlTimeval_t timeVal;
    timeVal.tv_sec = 1; // Seconds
    timeVal.tv_usec = 0; // Microseconds. 10000 microseconds resolution
    sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_RCVTIMEO, (_u8 *)&timeVal, sizeof(timeVal)); // Enable receive timeout

  • SL_SO_SNDTIMEO:
    struct SlTimeval_t timeVal;
    timeVal.tv_sec = 20; // Seconds
    timeVal.tv_usec = 0; // Microseconds. 10000 microseconds resolution
    sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SNDTIMEO, (_u8 *)&timeVal, sizeof(timeVal)); // Enable send timeout

  • SL_SO_RCVBUF:
    size.Winsize = 3000; // bytes
    sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_RCVBUF, (_u8 *)&size, sizeof(size));

  • SL_SO_NONBLOCKING:
    SlSockNonblocking_t enableOption;
    enableOption.NonBlockingEnabled = 1;
    sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_NONBLOCKING, (_u8 *)&enableOption,sizeof(enableOption)); // Enable/disable nonblocking mode

  • SL_SO_SECMETHOD:
    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_SECMETHOD, (_u8 *)&method, sizeof(method));

  • SL_SO_SECURE_MASK:
    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_SECURE_MASK,(_u8 *)&cipher, sizeof(cipher));

  • SL_SO_SECURE_FILES_CA_FILE_NAME:
    sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CA_FILE_NAME,"exuifaxCaCert.der",strlen("exuifaxCaCert.der"));

  • SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME;
    sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME,"myPrivateKey.der",strlen("myPrivateKey.der"));

  • SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME:
    sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME,"myCertificate.der",strlen("myCertificate.der"));

  • SL_SO_SECURE_FILES_DH_KEY_FILE_NAME:
    sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_DH_KEY_FILE_NAME,"myDHinServerMode.der",strlen("myDHinServerMode.der"));

  • SL_SO_SECURE_ENABLE_OCSP
    _u32 enable;
    enable = 1;
    sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_ENABLE_OCSP,&enable,sizeof(_u32));

  • SL_IP_MULTICAST_TTL:
    _u8 ttl = 20;
    sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_MULTICAST_TTL, &ttl, sizeof(ttl));

  • SL_IP_ADD_MEMBERSHIP:
    sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));

  • SL_IP_DROP_MEMBERSHIP:
    sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));

  • SL_SO_CHANGE_CHANNEL:
    _u32 newChannel = 6; // range is 1-13
    sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_CHANGE_CHANNEL, &newChannel, sizeof(newChannel));

  • SL_SO_SECURE_ALPN:
    alpn.SecureALPN = SL_SECURE_ALPN_H2 | SL_SECURE_ALPN_H2_14;
    sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SECURE_ALPN, &alpn, sizeof(SlSockSecureALPN_t));
  • SL_SO_SECURE_ALPN_GENERAL
    sl_SetSockOpt(sd,SL_SOL_SOCKET,SL_SO_SECURE_ALPN_GENERAL,"h2",strlen("h2"));
    sl_Connect(sd, ( SlSockAddr_t *)&addr, addrSize);
    length = 10;
    sl_GetSockOpt(sd,SL_SOL_SOCKET,SL_SO_SECURE_ALPN_GENERAL,buf,&length);
    if(length == 0)
    {
    //this protocol was not selected by the server
    }
    else if(memcmp(buf,"h2",length) == 0)
    {
    //the protocol that was set was picked by the server
    }

  • SL_IP_RAW_RX_NO_HEADER:
    _u32 header = 1; // remove ip header
    sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_RAW_RX_NO_HEADER, &header, sizeof(header));

  • SL_IP_HDRINCL:
    _u32 header = 1;
    sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_HDRINCL, &header, sizeof(header));

  • SL_IP_RAW_IPV6_HDRINCL:
    _u32 header = 1;
    sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_RAW_IPV6_HDRINCL, &header, sizeof(header));

  • SL_SO_PHY_RATE:
    _u32 rate = 6; // see wlan.h SlWlanRateIndex_e for values
    sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_RATE, &rate, sizeof(rate));

  • SL_SO_PHY_TX_POWER:
    _u32 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:
    _u32 numframes = 1;
    sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_NUM_FRAMES_TO_TX, &numframes, sizeof(numframes));

  • SL_SO_PHY_PREAMBLE:
    _u32 preamble = 1;
    sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_PREAMBLE, &preamble, sizeof(preamble));

  • SL_SO_PHY_TX_INHIBIT_THRESHOLD:
    _u32 thrshld = SL_TX_INHIBIT_THRESHOLD_MED;
    sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_TX_INHIBIT_THRESHOLD , &thrshld, sizeof(thrshld));

  • SL_SO_PHY_TX_TIMEOUT:
    _u32 timeout = 50;
    sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_TX_TIMEOUT , &timeout, sizeof(timeout));

  • SL_SO_PHY_ALLOW_ACKS:
    _u32 acks = 1; // 0 = disabled / 1 = enabled
    sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_ALLOW_ACKS, &acks, sizeof(acks));

  • SL_SO_PHY_RX_BSSID_DATA_FRAMES
    flag.enableDisable = 1;
    sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_PHY_RX_BSSID_DATA_FRAMES,&flag,sizeof(SlRxMetricsEnableDisableRXOnBSS_t));

  • SL_SO_LINGER:
    linger.l_onoff = 1;
    linger.l_linger = 10;
    sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_LINGER, &linger, sizeof(linger));

  • SL_SO_SECURE_EXT_CLIENT_CHLNG_RESP:
    int dummy;
    sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SECURE_EXT_CLIENT_CHLNG_RESP, &dummy, sizeof(dummy));

  • SL_SO_SECURE_DOMAIN_NAME_VERIFICATION:
    sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_DOMAIN_NAME_VERIFICATION,"www.google.co.il",strlen("www.google.co.il"));

Definition at line 932 of file sl_socket.c.

933 {
934  _SlSetSockOptMsg_u Msg;
935  _SlCmdExt_t CmdExt;
936 
937  /* verify that this api is allowed. if not allowed then
938  ignore the API execution and return immediately with an error */
939  VERIFY_API_ALLOWED(SL_OPCODE_SILO_SOCKET);
940 
941  _SlDrvResetCmdExt(&CmdExt);
942  CmdExt.TxPayload1Len = optlen;
943  CmdExt.pTxPayload1 = (_u8 *)optval;
944 
945  Msg.Cmd.Sd = (_u8)sd;
946  Msg.Cmd.Level = (_u8)level;
947  Msg.Cmd.OptionLen = (_u8)optlen;
948  Msg.Cmd.OptionName = (_u8)optname;
949 
950  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlSetSockOptCmdCtrl, &Msg, &CmdExt));
951 
952  return (_i16)Msg.Rsp.StatusOrLen;
953 }

§ sl_Socket()

_i16 sl_Socket ( _i16  Domain,
_i16  Type,
_i16  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:
  • SL_AF_INET for network protocol IPv4
  • SL_AF_INET6 for network protocol IPv6
  • SL_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
[in]Typespecifies the communication semantic, one of:
  • SL_SOCK_STREAM (reliable stream-oriented service or Stream Sockets)
  • SL_SOCK_DGRAM (datagram service or Datagram Sockets)
  • SL_SOCK_RAW (raw protocols atop the network layer)
  • when used with AF_RF:
    • SL_SOCK_DGRAM - L2 socket
    • SL_SOCK_RAW - L1 socket - bypass WLAN CCA (Clear Channel Assessment) The Protocol parameter is used to set the channel number. Within this parameter, low power low rate flag can be set by using the macro SL_WLAN_RAW_RF_SOCKET_CHANNEL. i.e sl_Socket(SL_AF_RF, SL_SOCK_RAW, SL_WLAN_RAW_RF_SOCKET_CHANNEL(36, TRANSCEIVER_5G_LOW_POWER_LOW_RATE));
    • SL_SOCK_RX_MTR - opening socket to receive information frames with the following format in STA and P2P client only. | SlRxMetrics_TLV_t | SlTransceiverRxOverHead_t | WLAN header (24 / 26 bytes depending on QOS) payload | collecting WLAN headers and RX metrics between the device and the AP. if used with the setsockopt - SL_SO_PHY_RX_BSSID_DATA_FRAMES, the device start collecting WLAN headers of other devices in the BSS
[in]Protocolspecifies a particular transport to be used with the socket.
The most common are
  • SL_IPPROTO_TCP
  • SL_IPPROTO_UDP 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 - illegal domain parameter
  • SL_EPROTOTYPE - illegal type parameter
  • SL_EACCES - permission denied
  • SL_ENSOCK - exceeded maximal number of socket
  • SL_ENOMEM - memory allocation error
  • SL_EINVAL - error in socket configuration
  • SL_EPROTONOSUPPORT - illegal protocol parameter
  • SL_EOPNOTSUPP - illegal combination of protocol and type parameters
See also
sl_Close
Note
belongs to basic_api
Warning

Definition at line 133 of file sl_socket.c.

134 {
135  _SlSockSocketMsg_u Msg;
136 
137  Msg.Cmd.Domain = (_u8)Domain;
138  Msg.Cmd.Type = (_u8)Type;
139  Msg.Cmd.Protocol = (_u8)Protocol;
140 
141  /* verify that this api is allowed. if not allowed then
142  ignore the API execution and return immediately with an error */
143  VERIFY_API_ALLOWED(SL_OPCODE_SILO_SOCKET);
144 
145  VERIFY_RET_OK(_SlDrvCmdOp((_SlCmdCtrl_t *)&_SlSockSocketCmdCtrl, &Msg, NULL));
146 
147  if( Msg.Rsp.StatusOrLen < 0 )
148  {
149  return ( Msg.Rsp.StatusOrLen);
150  }
151  else
152  {
153  return (_i16)((_u8)Msg.Rsp.Sd);
154  }
155 }

§ sl_StartTLS()

_i16 sl_StartTLS ( _i16  sd)

Initiate TLS connection on a socket.

Function Initiate TLS connection on the socket referred to by the socket descriptor sd. This function will works on blocking mode until the TLS handshake success or fails.

Parameters
[in]sdSocket descriptor (handle)
Returns
Zero on success, or negative error code on failure
See also
sl_Socket
Note
belongs to client_side
Warning

Definition at line 1972 of file sl_socket.c.

1973 {
1974  _SlReturnVal_t RetVal;
1975  SlSocketAsyncEvent_t AsyncRsp;
1976  _u32 tempValue;
1977  _i16 ObjIdx = MAX_CONCURRENT_ACTIONS;
1978  _i8 ret;
1979  int ret_pool = 0; // for _SlDrvReleasePoolObj
1980  SlEventsListNode_t startTLS;
1981  _u8 ActionIndex;
1982 
1983  /* verify that this api is allowed. if not allowed then
1984  ignore the API execution and return immediately with an error */
1985  VERIFY_API_ALLOWED(SL_OPCODE_SILO_SOCKET);
1986  _SlDrvMemZero(&AsyncRsp, sizeof(SlSocketAsyncEvent_t));
1987 
1988  /* Check if there already Object with ActionID "startTLS" on the same socket */
1989  for (ActionIndex = 0; ActionIndex < MAX_CONCURRENT_ACTIONS; ++ActionIndex)
1990  {
1991  if(((g_pCB->ObjPool[ActionIndex].AdditionalData & 0x0F) == sd) && ((g_pCB->ObjPool[ActionIndex].ActionID) == START_TLS_ID))
1992  {
1993  return SL_RET_CODE_STARTTLS_IN_PROGRESS_ON_THIS_SD;
1994  }
1995 
1996  }
1997 
1998  ObjIdx = _SlDrvProtectAsyncRespSetting((_u8*)&AsyncRsp, START_TLS_ID, (_u8)(sd & SL_BSD_SOCKET_ID_MASK));
1999 
2000  if (ObjIdx < 0)
2001  {
2002  return ObjIdx;
2003  }
2004 
2005  startTLS.event = (void *)_SlSocketHandleAsync_StartTLS;
2006  sl_RegisterLibsEventHandler(SL_EVENT_HDL_SOCKET, &startTLS);
2007 
2008  /* send Start TLS to sl_SetSockOpt */
2009  RetVal = sl_SetSockOpt(sd, SL_SOL_SOCKET, SL_SO_STARTTLS, &tempValue, sizeof(tempValue));
2010 
2011  if(SL_RET_CODE_OK == RetVal)
2012  {
2013  /* wait for async and get Data Read parameters */
2014  ret_pool = _SlDrvWaitForInternalAsyncEvent(ObjIdx,0,0);
2015 
2016  VERIFY_PROTOCOL(AsyncRsp.Sd == (_u8)sd);
2017 
2018  RetVal = AsyncRsp.Val;
2019  }
2020 
2021  ret = sl_UnregisterLibsEventHandler(SL_EVENT_HDL_SOCKET, &startTLS);
2022  _SlDrvReleasePoolObj(ObjIdx);
2023  if(ret < 0)
2024  {
2025  return ret;
2026  }
2027 
2028  if(ret_pool < 0)
2029  {
2030  return ret_pool;
2031  }
2032 
2033  return RetVal;
2034 }
_i16 sl_SetSockOpt(_i16 sd, _i16 level, _i16 optname, const void *optval, SlSocklen_t optlen)
Set socket options.
Definition: sl_socket.c:932

§ SlNetIfWifi_accept()

int16_t SlNetIfWifi_accept ( int16_t  sd,
void *  sdContext,
SlNetSock_Addr_t *  addr,
SlNetSocklen_t *  addrlen,
uint8_t  flags,
void **  acceptedSdContext 
)

Accept a connection on a socket.

The SlNetIfWifi_accept 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 SlNetIfWifi_socket(), bound to a local address with SlNetIfWifi_bind(), and is listening for connections after a SlNetIfWifi_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)
[in]sdContextMay store socket data if implemented in the SlNetIfWifi_socket function.
[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.
- 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
[in]flagsSpecifies socket descriptor flags.
The available flags are:
  • SLNETSOCK_SEC_START_SECURITY_SESSION_ONLY
  • SLNETSOCK_SEC_BIND_CONTEXT_ONLY Note: This flags can be used in order to start security session if needed
[in]acceptedSdContextAllocate and store data for the new socket if needed in other to use it in other slnetwifi socket functions
Returns
On success, a socket descriptor.
On a non-blocking accept a possible negative value is SLNETERR_BSD_EAGAIN.
On failure, negative error code.
SLNETERR_BSD_ENOMEM 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
SlNetIfWifi_Socket SlNetIfWifi_Bind SlNetIfWifi_Listen
Note
Warning

Definition at line 186 of file slnetifwifi.c.

187 {
188  return sl_Accept(sd, (SlSockAddr_t *)addr, addrlen);
189 }
_i16 sl_Accept(_i16 sd, SlSockAddr_t *addr, SlSocklen_t *addrlen)
Accept a connection on a socket.
Definition: sl_socket.c:692

§ SlNetIfWifi_bind()

int32_t SlNetIfWifi_bind ( int16_t  sd,
void *  sdContext,
const SlNetSock_Addr_t *  addr,
int16_t  addrlen 
)

Assign a name to a socket.

This SlNetIfWifi_bind 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]sdContextMay store socket data if implemented in the SlNetIfWifi_socket function.
[in]addrSpecifies the destination addrs
sockaddr:
- code for the address format.
- socket address, the length depends on the code format
[in]addrlenContains the size of the structure pointed to by addr
Returns
Zero on success, or negative error code on failure
See also
SlNetIfWifi_Socket SlNetIfWifi_accept SlNetIfWifi_Listen
Note
Warning

Definition at line 197 of file slnetifwifi.c.

198 {
199  return sl_Bind(sd, (const SlSockAddr_t *)addr, addrlen);
200 }
_i16 sl_Bind(_i16 sd, const SlSockAddr_t *addr, _i16 addrlen)
Assign a name to a socket.
Definition: sl_socket.c:237

§ SlNetIfWifi_close()

int32_t SlNetIfWifi_close ( int16_t  sd,
void *  sdContext 
)

Gracefully close socket.

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

Parameters
[in]sdSocket descriptor (handle), received in SlNetIfWifi_socket
[in]sdContextMay store socket data if implemented in the SlNetIfWifi_socket function.
Returns
Zero on success, or negative error code on failure
See also
SlNetIfWifi_socket
Note
Warning

Definition at line 174 of file slnetifwifi.c.

175 {
176  /* Close socket and return the return value of the function */
177  return sl_Close(sd);
178 }
_i16 sl_Close(_i16 sd)
Gracefully close socket.
Definition: sl_socket.c:176

§ slNetIfWifi_connDisable()

int16_t slNetIfWifi_connDisable ( void *  ifContext)

Gracefully close connection.

The slNetIfWifi_disconnect function close wifi connection by.
This function is called by the connection manager library layer to obtain disconnect.

Returns
Zero on success, or negative error code on failure.
See also
slNetIfWifi_disconnect
Note
Warning

Definition at line 147 of file slnetifwifi.c.

148 {
149  int retVal;
150 
151  retVal = SlWifiConn_disable();
152 
153  return retVal;
154 }

§ SlNetIfWifi_connect()

int32_t SlNetIfWifi_connect ( int16_t  sd,
void *  sdContext,
const SlNetSock_Addr_t *  addr,
SlNetSocklen_t  addrlen,
uint8_t  flags 
)

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 SLNETSOCK_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 SLNETSOCK_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]sdContextMay store socket data if implemented in the SlNetIfWifi_socket function.
[in]addrSpecifies the destination addr
sockaddr:
- code for the address format.
- socket address, the length depends on the code format
[in]addrlenContains the size of the structure pointed to by addr
[in]flagsSpecifies socket descriptor flags.
The available flags are:
  • SLNETSOCK_SEC_START_SECURITY_SESSION_ONLY
  • SLNETSOCK_SEC_BIND_CONTEXT_ONLY Note: This flags can be used in order to start security session if needed
Returns
On success, a socket descriptor (handle).
On a non-blocking connect a possible negative value is NETSCOK_EALREADY. On failure, negative value.
NETSCOK_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
SlNetIfWifi_socket
Note
Warning

Definition at line 219 of file slnetifwifi.c.

220 {
221  return sl_Connect(sd, (const SlSockAddr_t *)addr, addrlen);
222 }
_i16 sl_Connect(_i16 sd, const SlSockAddr_t *addr, _i16 addrlen)
Initiate a connection on a socket.
Definition: sl_socket.c:449

§ slNetIfWifi_connEnable()

int32_t slNetIfWifi_connEnable ( void *  ifContext)

Create and maintains a wifi connection to the local network.

The slNetIfWifi_enabelIf function creates wifi connection by provisioning process.
This function is called by the connection manager library layer to obtain connection.

Parameters
[in]connContextAllocate and store connection data if needed for using in other slnetwifi connection functions
Returns
Zero on success, or negative error code on failure.
See also
slNetIfWifi_createConnect
Note
Warning

Definition at line 133 of file slnetifwifi.c.

134 {
135  int retVal;
136 
137  retVal = SlWifiConn_enable();
138 
139  return retVal;
140 }

§ SlNetIfWifi_CreateContext()

int32_t SlNetIfWifi_CreateContext ( uint16_t  ifID,
const char *  ifName,
void **  ifContext,
SlNetIf_Event_t  ifCallback 
)

Allocate and store interface data. Registers to interface event handlers.

The SlNetIfWifi_CreateContext function stores interface related data.

Parameters
[in]ifIDSpecifies the interface which its configuration needs to be retrieved.
The values of the interface identifier is defined with the prefix SLNETIF_ID_ which defined in slnetif.h
[in]ifNameSpecifies the interface which its interface identifier needs to be retrieved.
[in]ifContextSpecifies the interface data if needed.
[in]ifCallbackSpecifies the interface callback function.
Returns
Zero on success, or negative error code on failure.
See also
Note
Warning
Examples
void *ifContext;
connection_status = SlNetIfWifi_CreateContext(&context);


Definition at line 694 of file slnetifwifi.c.

695 {
696  int32_t retVal = 0;
697 
698  gIfID = ifID;
699  retVal = SlWifiConn_registerNetIFCallback(ifCallback, ifID);
700 
701  return (retVal);
702 }

§ SlNetIfWifi_DeleteContext()

int32_t SlNetIfWifi_DeleteContext ( uint16_t  ifID,
void **  ifContext 
)

Free allocations of interface data. Remove registration of interface event handlers.

Parameters
[in]ifIDSpecifies the interface which its configuration needs to be remove.
The values of the interface identifier is defined with the prefix SLNETIF_ID_ which defined in slnetif.h
[in]ifContextSpecifies the interface data which needs to be remove.
Returns
Zero on success, or negative error code on failure.
See also
Note
Warning
Examples
void *ifContext;
connection_status = SlNetIfWifi_CreateContext(&context);


Definition at line 710 of file slnetifwifi.c.

711 {
712  return (0);
713 }

§ SlNetIfWifi_getConnectionStatus()

int32_t SlNetIfWifi_getConnectionStatus ( void *  ifContext)

Get interface connection status.

The SlNetIfWifi_getConnectionStatus function gets the connection status of the interface (connected Or disconnected).

Parameters
[in]ifContextStores interface data if CreateContext function supported and implemented. Can be used in all SlNetIf_Config_t functions
Returns
Connection status of the interface on success, or negative error code on failure
See also
Note
Warning
Examples
int16_t connection_status
connection_status = SlNetIfWifi_getConnectionStatus();


Definition at line 603 of file slnetifwifi.c.

604 {
605  SlWlanConnStatusParam_t connectionParams;
606  uint16_t Opt = 0;
607  int32_t retVal = 0;
608  uint16_t Size = 0;
609 
610  Size = sizeof(SlWlanConnStatusParam_t);
611  memset(&connectionParams, 0, Size);
612 
613  retVal = sl_WlanGet(SL_WLAN_CONNECTION_INFO, &Opt, &Size, (uint8_t *)&connectionParams);
614 
615  /* Check if the function returned an error */
616  if (retVal < SLNETERR_RET_CODE_OK)
617  {
618  /* Return error code */
619  return retVal;
620  }
621  return connectionParams.ConnStatus;
622 }
_i16 sl_WlanGet(const _u16 ConfigId, _u16 *pConfigOpt, _u16 *pConfigLen, _u8 *pValues)
Getting WLAN configurations.
Definition: wlan.c:1201

§ SlNetIfWifi_getHostByName()

int32_t SlNetIfWifi_getHostByName ( void *  ifContext,
char *  name,
const uint16_t  nameLen,
uint32_t *  ipAddr,
uint16_t *  ipAddrLen,
const uint8_t  family 
)

Get host IP by name
Obtain the IP Address of machine on network, by machine name.

Parameters
[in]ifContextStores interface data if CreateContext function supported and implemented. Can be used in all SlNetIf_Config_t functions
[in]ifBitmapSpecifies the interfaces which the host ip needs to be retrieved from (according to the priority until one of them will return an answer).
The values of the interface identifiers is defined with the prefix SLNETIF_ID_ which defined in slnetif.h
[in]nameHost name
[in]nameLenName length
[out]ipAddrThis parameter is filled in with host IP addresses. In case that host name is not resolved, out_ip_addr is zero.
[in,out]ipAddrLenHolds the size of the ipAddr array, when function successful, the ipAddrLen parameter will be updated with the number of the IP addresses found.
[in]familyProtocol family
Returns
Zero on success, or negative on failure.
SLNETUTIL_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 Possible DNS error codes:
  • SLNETUTIL_DNS_QUERY_NO_RESPONSE
  • SLNETUTIL_DNS_NO_SERVER
  • SLNETUTIL_DNS_QUERY_FAILED
  • SLNETUTIL_DNS_MALFORMED_PACKET
  • SLNETUTIL_DNS_MISMATCHED_RESPONSE
See also
Note
Only one sl_NetAppDnsGetHostByName 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 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
In case an IP address in a string format is set as input, without any prefix (e.g. "1.2.3.4") the device will not try to access the DNS and it will return the input address on the 'out_ip_addr' field
Example
  • Getting host by name:
    uint16_t DestIPListSize = 1;
    uint32_t DestIP[1];
    uint32_t ifID;
    int16_t SockId;
    SlNetSock_AddrIn_t LocalAddr; //address of the server to connect to
    int32_t LocalAddrSize;
    SlNetIfWifi_getHostByName(0, "www.google.com", strlen("www.google.com"), (uint32_t *)DestIP, &DestIPListSize, SLNETSOCK_PF_INET);
    LocalAddr.sin_family = SLNETSOCK_AF_INET;
    LocalAddr.sin_addr.s_addr = SlNetUtil_htonl(DestIP[0]);
    LocalAddr.sin_port = SlNetUtil_htons(80);
    LocalAddrSize = sizeof(SlNetSock_AddrIn_t);
    SockId = SlNetIfWifi_socket(SLNETSOCK_AF_INET, SLNETSOCK_SOCK_STREAM, ifID, 0);
    if (SockId >= 0)
    {
    status = SlNetIfWifi_connect(SockId, (SlNetSock_Addr_t *) &LocalAddr, LocalAddrSize);
    }

Definition at line 444 of file slnetifwifi.c.

445 {
446  int32_t retVal = SLNETERR_RET_CODE_OK;
447 
448  /* sl_NetAppDnsGetHostByName can receive only one ipAddr variable, so
449  only the first slot of the array will be used and the ipAddrLen will
450  be updated to 1 when function is successfully */
451  retVal = sl_NetAppDnsGetHostByName((signed char *)name, nameLen, (_u32 *)ipAddr, family);
452 
453  if (retVal == SLNETERR_RET_CODE_OK)
454  {
455  *ipAddrLen = 1;
456  }
457 
458  return retVal;
459 
460 }
_i16 sl_NetAppDnsGetHostByName(_i8 *pHostName, const _u16 NameLen, _u32 *OutIpAddr, const _u8 Family)
Get host IP by name Obtain the IP Address of machine on network, by machine name. ...
Definition: netapp.c:849

§ SlNetIfWifi_getIPAddr()

int32_t SlNetIfWifi_getIPAddr ( void *  ifContext,
SlNetIfAddressType_e  addrType,
uint16_t *  addrConfig,
uint32_t *  ipAddr 
)

Get IP Address of specific interface.

The SlNetIfWifi_getIPAddr function retrieve the IP address of a specific interface according to the Address Type, IPv4, IPv6 LOCAL or IPv6 GLOBAL.

Parameters
[in]ifContextStores interface data if CreateContext function supported and implemented. Can be used in all SlNetIf_Config_t functions
[in]ifIDSpecifies the interface which its connection state needs to be retrieved.
The values of the interface identifier is defined with the prefix SLNETIF_ID_ which defined in slnetif.h
[in]addrTypeAddress type:
  • SLNETIF_IPV4_ADDR
  • SLNETIF_IPV6_ADDR_LOCAL
  • SLNETIF_IPV6_ADDR_GLOBAL
[out]addrConfigAddress config:
  • SLNETIF_ADDR_CFG_UNKNOWN
  • SLNETIF_ADDR_CFG_DHCP
  • SLNETIF_ADDR_CFG_DHCP_LLA
  • SLNETIF_ADDR_CFG_STATIC
  • SLNETIF_ADDR_CFG_STATELESS
  • SLNETIF_ADDR_CFG_STATEFUL
[out]ipAddrIP Address according to the Address Type
Returns
Zero on success, or negative error code on failure
See also
SlNetIfAddressType_e
Note
Warning
Examples
SlNetSock_In6Addr_t IPAdd;
uint16_t addressConfig = 0;
SlNetIfWifi_getIPAddr(SLNETIF_ID_1 ,SLNETIF_IPV6_ADDR_LOCAL ,&addressConfig ,(uint8_t *)ipAddr);


Definition at line 572 of file slnetifwifi.c.

573 {
574  int32_t retVal;
575  uint16_t ipAddrLen;
576  SlNetCfg_e newAddrType;
577 
578  /* Translate the addrType of SlNetSock type to addrType of SlNetSockIfWifi type */
579  retVal = matchModeByRole(addrType, &newAddrType, &ipAddrLen);
580  if(retVal == SLNETERR_RET_CODE_OK)
581  {
582  retVal = sl_NetCfgGet(newAddrType, addrConfig, &ipAddrLen, (unsigned char *)ipAddr);
583  }
584 
585  /*
586  * If the type is IPv4 we need to reorder the address as the Simplelink CC32xx device
587  * returns the address in host order
588  */
589  if(SLNETIF_IPV4_ADDR == addrType)
590  {
591  *ipAddr = SlNetUtil_htonl(*ipAddr);
592  }
593 
594  return retVal;
595 }
_i16 sl_NetCfgGet(const _u16 ConfigId, _u16 *pConfigOpt, _u16 *pConfigLen, _u8 *pValues)
Getting network configurations.
Definition: netcfg.c:104

§ SlNetIfWifi_getSockName()

int32_t SlNetIfWifi_getSockName ( int16_t  sd,
void *  sdContext,
SlNetSock_Addr_t *  addr,
SlNetSocklen_t *  addrlen 
)

Get local address info by socket descriptor
Returns the local address info of the socket descriptor.

Parameters
[in]sdSocket descriptor (handle)
[in]sdContextMay store socket data if implemented in the SlNetIfWifi_socket function.
[out]addrThe argument addr is a pointer to a SlNetSock_Addr_t 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
SlNetSock_Addr_t:
- code for the address format.
- 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
Zero on success, or negative on failure.
See also
SlNetSock_create SlNetSock_bind
Note
If the provided buffer is too small the returned address will be truncated and the addrlen will contain the actual size of the socket address
Warning

Definition at line 231 of file slnetifwifi.c.

232 {
233 // Not implemented in NWP
234  return SLNETERR_INVALPARAM;
235 }

§ SlNetIfWifi_getSockOpt()

int32_t SlNetIfWifi_getSockOpt ( int16_t  sd,
void *  sdContext,
int16_t  level,
int16_t  optname,
void *  optval,
SlNetSocklen_t *  optlen 
)

Get socket options.

The SlNetIfWifi_getSockOpt function gets the options associated with a socket. Options may exist at multiple protocol levels; they are always present at the uppermost socket level.
The parameters optval and optlen identify a buffer in which the value for the requested option(s) are to be returned. 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 descriptor (handle)
[in]sdContextMay store socket data if implemented in the SlNetIfWifi_socket function.
[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
Zero on success, or negative error code on failure
See also
SlNetIfWifi_setSockOpt
Note
Warning

Definition at line 301 of file slnetifwifi.c.

302 {
303  SlSocklen_t len;
304  int32_t status = 0;
305  SlNetSock_Timeval_t *slNetSockTimeVal;
306  SlTimeval_t tv;
307 
308  switch (level)
309  {
310  case SLNETSOCK_LVL_SOCKET:
311  {
312  switch (optname)
313  {
314  case SLNETSOCK_OPSOCK_RCV_TIMEO:
315  {
316  if (*optlen < sizeof(SlNetSock_Timeval_t))
317  {
318  return (SLNETERR_RET_CODE_INVALID_INPUT);
319  }
320  len = sizeof(SlTimeval_t);
321  status =
322  sl_GetSockOpt(sd, level, optname, (void *)&tv, &len);
323 
324  slNetSockTimeVal = (SlNetSock_Timeval_t *)optval;
325  slNetSockTimeVal->tv_sec = tv.tv_sec;
326  slNetSockTimeVal->tv_usec = tv.tv_usec;
327  *optlen = sizeof(SlNetSock_Timeval_t);
328  break;
329  }
330 
331  default:
332  {
333  /* Pass values into sl_SetSockOpt directly */
334  status = sl_GetSockOpt(sd, level, optname, optval, optlen);
335  break;
336  }
337 
338  }
339  break;
340  }
341  default:
342  {
343  /* Pass values into sl_SetSockOpt directly */
344  status = sl_GetSockOpt(sd, level, optname, optval, optlen);
345  break;
346  }
347  }
348 
349  return (status);
350 }
_i16 sl_GetSockOpt(_i16 sd, _i16 level, _i16 optname, void *optval, SlSocklen_t *optlen)
Get socket options.
Definition: sl_socket.c:975

§ SlNetIfWifi_listen()

int32_t SlNetIfWifi_listen ( int16_t  sd,
void *  sdContext,
int16_t  backlog 
)

Listen for connections on a socket.

The willingness to accept incoming connections and a queue limit for incoming connections are specified with SlNetIfWifi_listen(), and then the connections are accepted with SlNetIfWifi_accept().
The SlNetIfWifi_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]sdContextMay store socket data if implemented in the SlNetIfWifi_socket function.
[in]backlogSpecifies the listen queue depth.
Returns
Zero on success, or negative error code on failure
See also
SlNetIfWifi_Socket SlNetIfWifi_accept SlNetIfWifi_bind
Note
Warning

Definition at line 208 of file slnetifwifi.c.

209 {
210  return sl_Listen(sd, backlog);
211 }
_i16 sl_Listen(_i16 sd, _i16 backlog)
Listen for connections on a socket.
Definition: sl_socket.c:658

§ SlNetIfWifi_loadSecObj()

int32_t SlNetIfWifi_loadSecObj ( void *  ifContext,
uint16_t  objType,
char *  objName,
int16_t  objNameLen,
uint8_t *  objBuff,
int16_t  objBuffLen 
)

Load secured buffer to the network stack.

The SlNetSock_secLoadObj function loads buffer/files into the inputted network stack for future usage of the socket SSL/TLS connection. This option is relevant for network stacks with file system and also for network stacks that lack file system that can store the secured files.

Parameters
[in]ifContextStores interface data if CreateContext function supported and implemented. Can be used in all SlNetIf_Config_t functions
[in]objTypeSpecifies the security object type which could be one of the following:
  • SLNETIF_SEC_OBJ_TYPE_RSA_PRIVATE_KEY
  • SLNETIF_SEC_OBJ_TYPE_CERTIFICATE
  • SLNETIF_SEC_OBJ_TYPE_DH_KEY
[in]objNameSpecifies the name/input identifier of the secured buffer loaded for file systems - this can be the file name for plain text buffer loading this can be the name of the object
[in]objNameLenSpecifies the buffer name length to be loaded.
[in]objBuffSpecifies the pointer to the secured buffer to be loaded.
[in]objBuffLenSpecifies the buffer length to be loaded.
Returns
On success, buffer type handler index to be used when attaching the secured buffer to a socket.
A successful return code should be a positive number (int16)
On error, a negative value will be returned specifying the error code.
  • SLNETERR_STATUS_ERROR - load operation failed
See also
SlNetIfWifi_setSockOpt
Note
Warning

Definition at line 630 of file slnetifwifi.c.

631 {
632  int32_t retVal; /* negative retVal is an error */
633  uint16_t i;
634  uint32_t Offset = 0;
635  uint32_t MasterToken = 0;
636  int32_t OpenFlags = 0;
637  int32_t DeviceFileHandle = (-1);
638  uint16_t macAddressLen = SL_MAC_ADDR_LEN;
639  char *deviceFileName = objName;
640  uint8_t macAddress[SL_MAC_ADDR_LEN];
641 
642  /* Check if the inputs exists */
643  if ((NULL == objName) || (NULL == objBuff))
644  {
645  /* input not valid, return error code */
646  return SLNETERR_RET_CODE_INVALID_INPUT;
647  }
648  /* Print device MAC address */
649  retVal = sl_NetCfgGet(SL_NETCFG_MAC_ADDRESS_GET, 0, &macAddressLen, &macAddress[0]);
650 
651  /* Generating Random MasterPassword but constant per deviceFileName */
652  for (i = 0; i < strlen(deviceFileName); i++)
653  {
654  MasterToken = ((MasterToken << 8) ^ deviceFileName[i]);
655  }
656 
657  /* Create a file and write data. The file is secured, without
658  signature and with a fail safe commit, with vendor token which is
659  a XOR combination between the MAC address of the device and the
660  object file name */
661  OpenFlags = SL_FS_CREATE;
662  OpenFlags |= SL_FS_OVERWRITE;
663  OpenFlags |= SL_FS_CREATE_SECURE;
664  OpenFlags |= SL_FS_CREATE_VENDOR_TOKEN;
665  OpenFlags |= SL_FS_CREATE_NOSIGNATURE;
666  OpenFlags |= SL_FS_CREATE_FAILSAFE;
667 
668  /* Create a secure file if not exists and open it for write. */
669  DeviceFileHandle = sl_FsOpen((unsigned char *)deviceFileName, OpenFlags | SL_FS_CREATE_MAX_SIZE( objBuffLen ), (unsigned long *)&MasterToken);
670 
671  /* Check if file created successfully */
672  if ( DeviceFileHandle < SLNETERR_RET_CODE_OK )
673  {
674  return DeviceFileHandle;
675  }
676 
677  Offset = 0;
678  /* Write the buffer to the new file */
679  retVal = sl_FsWrite(DeviceFileHandle, Offset, (unsigned char *)objBuff, objBuffLen);
680 
681  /* Close the file */
682  retVal = sl_FsClose(DeviceFileHandle, NULL, NULL , 0);
683 
684  return retVal;
685 }
_i32 sl_FsOpen(const _u8 *pFileName, const _u32 AccessModeAndMaxSize, _u32 *pToken)
open file for read or write from/to storage device
Definition: fs.c:157
_i16 sl_FsClose(const _i32 FileHdl, const _u8 *pCeritificateFileName, const _u8 *pSignature, const _u32 SignatureLen)
Close file in storage device.
Definition: fs.c:250
_i16 sl_NetCfgGet(const _u16 ConfigId, _u16 *pConfigOpt, _u16 *pConfigLen, _u8 *pValues)
Getting network configurations.
Definition: netcfg.c:104
_i32 sl_FsWrite(const _i32 FileHdl, _u32 Offset, _u8 *pData, _u32 Len)
Write block of data to a file in storage device.
Definition: fs.c:379

§ SlNetIfWifi_ping()

uint32_t SlNetIfWifi_ping ( void *  ifContext,
const SlNetSock_Addr_t *  addr,
SlNetSocklen_t  addrLen,
uint32_t  attempts,
uint16_t  timeout,
uint16_t  interval,
uint16_t  packetSize,
int16_t  flags 
)

Performs a ping.

This functions is used to perform a ping request and check its response.

Parameters
[in]ifContextStores interface data if CreateContext function supported and implemented. Can be used in all SlNetIf_Config_t functions
[in]addrSpecifies the destination addrs
sockaddr:
- code for the address format.
- socket address, the length depends on the code format
[in]addrLenContains the size of the structure pointed to by addr.
[in]attemptsSpecifies the number of ping request attempts.
[in]timeoutSpecifies the timeout to wait for a ping response
[in]intervalSpecifies the interval between subsequent ping attempts
[in]packetSizePing packet size in bytes including ICMP header, therefore must be greater than 8
[in]flagsReserved
Returns
The number of successful packets, 0 on failure

Definition at line 467 of file slnetifwifi.c.

468 {
469  int32_t retVal;
470  SlNetAppPingReport_t report;
471  SlNetAppPingCommand_t pingCommand;
472 
473  if(addr->sa_family == SLNETSOCK_AF_INET)
474  {
475  /* destination IP of gateway */
476  pingCommand.Ip = ((SlNetSock_AddrIn_t*)addr)->sin_addr.s_addr;
477  }
478  else if(addr->sa_family == SLNETSOCK_AF_INET6)
479  {
480  /* destination IP of gateway */
481  *((SlNetSock_In6Addr_t*)&pingCommand.Ip) = ((SlNetSock_AddrIn6_t*)addr)->sin6_addr;
482  }
483 
484  /* size of ping, in bytes */
485  pingCommand.PingSize = packetSize;
486 
487  /* delay between pings, in milliseconds */
488  pingCommand.PingIntervalTime = interval;
489 
490  /* timeout for every ping in milliseconds */
491  pingCommand.PingRequestTimeout = timeout;
492 
493  /* max number of ping requests. 0 - forever */
494  pingCommand.TotalNumberOfAttempts = attempts;
495 
496  /* report only when finished */
497  pingCommand.Flags = 0;
498 
499  /* Ping Gateway */
500  retVal = sl_NetAppPing( &pingCommand, addr->sa_family, &report, NULL );
501 
502  if(retVal == 0)
503  {
504  return report.PacketsReceived;
505  }
506  else
507  return 0;
508 }
_i16 sl_NetAppPing(const SlNetAppPingCommand_t *pPingParams, const _u8 Family, SlNetAppPingReport_t *pReport, const P_SL_DEV_PING_CALLBACK pPingCallback)
send ICMP ECHO_REQUEST to network hosts
Definition: netapp.c:1003

§ SlNetIfWifi_recv()

int32_t SlNetIfWifi_recv ( int16_t  sd,
void *  sdContext,
void *  buf,
uint32_t  len,
uint32_t  flags 
)

Read data from TCP socket.

The SlNetIfWifi_recv function receives a message from a connection-mode socket

Parameters
[in]sdSocket descriptor (handle)
[in]sdContextMay store socket data if implemented in the SlNetIfWifi_socket function.
[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]flagsUpper 8 bits specifies the security flags Lower 24 bits specifies the type of message reception. On this version, the lower 24 bits are 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 SLNETERR_BSD_EAGAIN.
SLNETERR_BSD_ENOMEM 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
SlNetIfWifi_recvFrom
Note
Warning
Examples
  • Receiving data using TCP socket:
    SlNetSock_AddrIn_t Addr;
    SlNetSock_AddrIn_t LocalAddr;
    int16_t AddrSize = sizeof(SlNetSock_AddrIn_t);
    int16_t SockID, newSockID;
    int16_t Status;
    int8_t Buf[RECV_BUF_LEN];
    LocalAddr.sin_family = SLNETSOCK_AF_INET;
    LocalAddr.sin_port = SlNetSock_htons(5001);
    LocalAddr.sin_addr.s_addr = 0;
    Addr.sin_family = SLNETSOCK_AF_INET;
    Addr.sin_port = SlNetSock_htons(5001);
    Addr.sin_addr.s_addr = SlNetSock_htonl(SLNETSOCK_IPV4_VAL(10,1,1,200));
    SockID = SlNetIfWifi_socket(SLNETSOCK_AF_INET, SLNETSOCK_SOCK_STREAM, 0, 0, 0);
    Status = SlNetIfWifi_bind(SockID, (SlNetSock_Addr_t *)&LocalAddr, AddrSize);
    Status = SlNetIfWifi_listen(SockID, 0);
    newSockID = SlNetIfWifi_accept(SockID, (SlNetSock_Addr_t*)&Addr, (SlNetSocklen_t*) &AddrSize);
    Status = SlNetIfWifi_recv(newSockID, Buf, 1460, 0);

  • Rx transceiver mode using a raw socket:
    int8_t buffer[1536];
    int16_t sd;
    uint16_t size;
    SlNetSock_TransceiverRxOverHead_t *transHeader;
    sd = SlNetIfWifi_socket(SLNETSOCK_AF_RF, SLNETSOCK_SOCK_RAW, 11, 0, 0); // channel 11
    while(1)
    {
    size = SlNetIfWifi_recv(sd,buffer,1536,0);
    transHeader = (SlNetSock_TransceiverRxOverHead_t *)buffer;
    printf("RSSI is %d frame type is 0x%x size %d\n",transHeader->rssi,buffer[sizeof(SlNetSock_TransceiverRxOverHead_t)],size);
    }

Definition at line 358 of file slnetifwifi.c.

359 {
360  DISABLE_SEC_BITS_FROM_INPUT_FLAGS(flags);
361  return sl_Recv(sd, buf, len, flags);
362 }
_i16 sl_Recv(_i16 sd, void *buf, _i16 len, _i16 flags)
Read data from TCP socket.
Definition: sl_socket.c:881

§ SlNetIfWifi_recvFrom()

int32_t SlNetIfWifi_recvFrom ( int16_t  sd,
void *  sdContext,
void *  buf,
uint32_t  len,
uint32_t  flags,
SlNetSock_Addr_t *  from,
SlNetSocklen_t *  fromlen 
)

Read data from socket.

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

Parameters
[in]sdSocket descriptor (handle)
[in]sdContextMay store socket data if implemented in the SlNetIfWifi_socket function.
[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]flagsUpper 8 bits specifies the security flags Lower 24 bits specifies the type of message reception. On this version, the lower 24 bits are not supported
[in]fromPointer to an address structure indicating the source address.
sockaddr:
- code for the address format.
- 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 SLNETERR_BSD_EAGAIN. SLNETSOCK_RET_CODE_INVALID_INPUT (-2) will be returned if fromlen has incorrect length.
SLNETERR_BSD_ENOMEM 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
SlNetIfWifi_recv
Note
Warning
Example
  • Receiving data:
    SlNetSock_AddrIn_t Addr;
    SlNetSock_AddrIn_t LocalAddr;
    int16_t AddrSize = sizeof(SlNetSock_AddrIn_t);
    int16_t SockID;
    int16_t Status;
    int8_t Buf[RECV_BUF_LEN];
    LocalAddr.sin_family = SLNETSOCK_AF_INET;
    LocalAddr.sin_port = SlNetSock_htons(5001);
    LocalAddr.sin_addr.s_addr = 0;
    SockID = SlNetIfWifi_socket(SLNETSOCK_AF_INET, SLNETSOCK_SOCK_DGRAM, 0, 0, 0);
    Status = SlNetIfWifi_bind(SockID, (SlNetSock_Addr_t *)&LocalAddr, AddrSize);
    Status = SlNetIfWifi_recvFrom(SockID, Buf, 1472, 0, (SlNetSock_Addr_t *)&Addr, (SlNetSocklen_t*)&AddrSize);

Definition at line 370 of file slnetifwifi.c.

371 {
372  DISABLE_SEC_BITS_FROM_INPUT_FLAGS(flags);
373  return sl_RecvFrom(sd, buf, len, flags, (SlSockAddr_t *)from, fromlen);
374 }
_i16 sl_RecvFrom(_i16 sd, void *buf, _i16 len, _i16 flags, SlSockAddr_t *from, SlSocklen_t *fromlen)
Read data from socket.
Definition: sl_socket.c:360

§ SlNetIfWifi_select()

int32_t SlNetIfWifi_select ( void *  ifContext,
int16_t  nfds,
SlNetSock_SdSet_t *  readsds,
SlNetSock_SdSet_t *  writesds,
SlNetSock_SdSet_t *  exceptsds,
SlNetSock_Timeval_t *  timeout 
)

Monitor socket activity.

SlNetIfWifi_send 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. If trigger mode is enabled the active sdset is the one that retrieved in the first triggered call. To enable the trigger mode, an handler must be statically registered to the slcb_SocketTriggerEventHandler (user.h)

Parameters
[in]ifContextStores interface data if CreateContext function supported and implemented. Can be used in all SlNetIf_Config_t functions
[in]nsdsThe highest-numbered file descriptor in any of the three sets, plus 1.
[in,out]readsdsSocket descriptors list for read monitoring and accept monitoring
[in,out]writesdsSocket descriptors list for connect monitoring only, write monitoring is not supported
[in,out]exceptsdsSocket descriptors list for exception monitoring, not supported.
[in]timeoutIs an upper bound on the amount of time elapsed before SlNetIfWifi_send() 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. In trigger mode the timeout fields must be set to zero.
Returns
On success, SlNetIfWifi_send() returns the number of file descriptors contained in the three returned descriptor sets (that is, the total number of bits that are set in readsds, writesds, exceptsds) 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.
SLNETERR_BSD_ENOMEM 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
SlNetIfWifi_socket
Note
If the timeout value set to less than 10ms it will automatically set to 10ms to prevent overload of the system
Only one SlNetIfWifi_send can be handled at a time. Calling this API while the same command is called from another thread, may result in one of the following scenarios:
  1. The command will wait (internal) until the previous command finish, and then be executed.
  2. There are not enough resources and SLNETERR_BSD_ENOMEM error will return. In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try again later to issue the command.
  3. In case there is already a triggered SlNetIfWifi_send in progress, the following call will return with SLNETSOCK_RET_CODE_SOCKET_SELECT_IN_PROGRESS_ERROR.
Warning

Definition at line 243 of file slnetifwifi.c.

244 {
245  SlNetSock_Timeval_t *slNetSockTimeVal;
246  SlTimeval_t tv;
247  /* Translate from SlNetSock_Timeval_t into SlTimeval_t */
248  slNetSockTimeVal = (SlNetSock_Timeval_t *)timeout;
249  tv.tv_sec = slNetSockTimeVal->tv_sec;
250  tv.tv_usec = slNetSockTimeVal->tv_usec;
251  return sl_Select(nfds, (SlFdSet_t *)readsds, (SlFdSet_t *)writesds, (SlFdSet_t *)exceptsds, &tv);
252 }
_i16 sl_Select(_i16 nfds, SlFdSet_t *readsds, SlFdSet_t *writesds, SlFdSet_t *exceptsds, struct SlTimeval_t *timeout)
Monitor socket activity.
Definition: sl_socket.c:1762

§ SlNetIfWifi_send()

int32_t SlNetIfWifi_send ( int16_t  sd,
void *  sdContext,
const void *  buf,
uint32_t  len,
uint32_t  flags 
)

Write data to TCP socket.

The SlNetIfWifi_send 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 SLNETSOCK_SOCKET_TX_FAILED_EVENT 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 descriptor (handle)
[in]sdContextMay store socket data if implemented in the SlNetIfWifi_socket function.
[in]bufPoints to a buffer containing the message to be sent
[in]lenMessage size in bytes. Range: 1-1460 bytes
[in]flagsUpper 8 bits specifies the security flags Lower 24 bits specifies the type of message reception. On this version, the lower 24 bits are not supported for TCP. For transceiver mode, the SLNETSOCK_WLAN_RAW_RF_TX_PARAMS macro can be used to determine transmission parameters (channel,rate,tx_power,preamble)
Returns
Zero on success, or negative error code on failure
See also
SlNetIfWifi_sendTo
Note
Warning
Example
  • Sending data:
    SlNetSock_AddrIn_t Addr;
    int16_t AddrSize = sizeof(SlNetSock_AddrIn_t);
    int16_t SockID;
    int16_t Status;
    int8_t Buf[SEND_BUF_LEN];
    Addr.sin_family = SLNETSOCK_AF_INET;
    Addr.sin_port = SlNetSock_htons(5001);
    Addr.sin_addr.s_addr = SlNetSock_htonl(SLNETSOCK_IPV4_VAL(10,1,1,200));
    SockID = SlNetIfWifi_socket(SLNETSOCK_AF_INET, SLNETSOCK_SOCK_STREAM, 0, 0, 0);
    Status = SlNetIfWifi_connect(SockID, (SlNetSock_Addr_t *)&Addr, AddrSize);
    Status = SlNetIfWifi_send(SockID, Buf, 1460, 0 );

Definition at line 382 of file slnetifwifi.c.

383 {
384  DISABLE_SEC_BITS_FROM_INPUT_FLAGS(flags);
385  return sl_Send(sd, buf, len, flags);
386 }
_i16 sl_Send(_i16 sd, const void *buf, _i16 len, _i16 flags)
Write data to TCP socket.
Definition: sl_socket.c:594

§ SlNetIfWifi_sendTo()

int32_t SlNetIfWifi_sendTo ( int16_t  sd,
void *  sdContext,
const void *  buf,
uint32_t  len,
uint32_t  flags,
const SlNetSock_Addr_t *  to,
SlNetSocklen_t  tolen 
)

Write data to socket.

The SlNetIfWifi_sendTo function is used to transmit a message on a connectionless socket (connection less socket SLNETSOCK_SOCK_DGRAM, SLNETSOCK_SOCK_RAW).
Returns immediately after sending data to device.
In case of transmission failure an async event SLNETSOCK_SOCKET_TX_FAILED_EVENT is going to be received.

Parameters
[in]sdSocket descriptor (handle)
[in]sdContextMay store socket data if implemented in the SlNetIfWifi_socket function.
[in]bufPoints to a buffer containing the message to be sent
[in]lenmessage size in bytes. Range: 1-1460 bytes
[in]flagsUpper 8 bits specifies the security flags Lower 24 bits specifies the type of message reception. On this version, the lower 24 bits are not supported
[in]toPointer to an address structure indicating the destination address.
sockaddr:
- code for the address format.
- socket address, the length depends on the code format
[in]tolenDestination address structure size
Returns
Zero on success, or negative error code on failure
See also
SlNetIfWifi_send
Note
Warning
Example
  • Sending data:
    SlNetSock_AddrIn_t Addr;
    int16_t AddrSize = sizeof(SlNetSock_AddrIn_t);
    int16_t SockID;
    int16_t Status;
    int8_t Buf[SEND_BUF_LEN];
    Addr.sin_family = SLNETSOCK_AF_INET;
    Addr.sin_port = SlNetSock_htons(5001);
    Addr.sin_addr.s_addr = SlNetSock_htonl(SLNETSOCK_IPV4_VAL(10,1,1,200));
    SockID = SlNetIfWifi_socket(SLNETSOCK_AF_INET, SLNETSOCK_SOCK_DGRAM, 0, 0, 0);
    Status = SlNetIfWifi_sendTo(SockID, Buf, 1472, 0, (SlNetSock_Addr_t *)&Addr, AddrSize);

Definition at line 394 of file slnetifwifi.c.

395 {
396  DISABLE_SEC_BITS_FROM_INPUT_FLAGS(flags);
397  return sl_SendTo(sd, buf, len, flags, (const SlSockAddr_t *)to, tolen);
398 }
_i16 sl_SendTo(_i16 sd, const void *buf, _i16 len, _i16 flags, const SlSockAddr_t *to, SlSocklen_t tolen)
Write data to socket.
Definition: sl_socket.c:283

§ SlNetIfWifi_setSockOpt()

int32_t SlNetIfWifi_setSockOpt ( int16_t  sd,
void *  sdContext,
int16_t  level,
int16_t  optname,
void *  optval,
SlNetSocklen_t  optlen 
)

Set socket options-.

The SlNetIfWifi_setSockOpt 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 protocol 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 opt_values for SlNetIfWifi_setSockOpt(). For SlNetIfWifi_getSockOpt() they identify a buffer in which the value for the requested option(s) are to be returned. For SlNetIfWifi_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 descriptor (handle)
[in]sdContextMay store socket data if implemented in the SlNetIfWifi_socket function.
[in]levelDefines the protocol level for this option
  • SLNETSOCK_LVL_SOCKET Socket level configurations (L4, transport layer)
  • SLNETSOCK_LVL_IP IP level configurations (L3, network layer)
  • SLNETSOCK_LVL_PHY Link level configurations (L2, link layer)
[in]optnameDefines the option name to interrogate
  • SLNETSOCK_LVL_SOCKET
    • SLNETSOCK_OPSOCK_RCV_BUF
      Sets tcp max recv window size.
      This options takes SlNetSock_Winsize_t struct as parameter
    • SLNETSOCK_OPSOCK_RCV_TIMEO
      Sets the timeout value that specifies the maximum amount of time an input function waits until it completes.
      Default: No timeout
      This options takes SlNetSock_Timeval_t struct as parameter
    • SLNETSOCK_OPSOCK_KEEPALIVE
      Enable or Disable periodic keep alive. Keeps TCP connections active by enabling the periodic transmission of messages
      Timeout is 5 minutes.
      Default: Enabled
      This options takes SlNetSock_Keepalive_t struct as parameter
    • SLNETSOCK_OPSOCK_KEEPALIVE_TIME
      Set keep alive timeout. Value is in seconds
      Default: 5 minutes
    • SLNETSOCK_OPSOCK_LINGER
      Socket lingers on close pending remaining send/receive packets
    • SLNETSOCK_OPSOCK_NON_BLOCKING
      Sets socket to non-blocking operation Impacts: connect, accept, send, sendto, recv and recvfrom.
      Default: Blocking. This options takes SlNetSock_Nonblocking_t struct as parameter
    • SLNETSOCK_OPSOCK_NON_IP_BOUNDARY
      Enable or Disable rx ip boundary. In connectionless socket (udp/raw), unread data is dropped (when SlNetIfWifi_recvfrom len parameter < data size), Enable this option in order to read the left data on the next SlNetIfWifi_recvfrom iteration Default: Disabled, IP boundary kept,
      This options takes SlNetSock_NonIpBoundary_t struct as parameter
  • SLNETSOCK_LVL_IP
    • SLNETSOCK_OPIP_MULTICAST_TTL
      Set the time-to-live value of outgoing multicast packets for this socket.
      This options takes uint8_t as parameter
    • SLNETSOCK_OPIP_ADD_MEMBERSHIP
      UDP socket, Join a multicast group.
      This options takes SlNetSock_IpMreq_t struct as parameter
    • SLNETSOCK_OPIP_DROP_MEMBERSHIP
      UDP socket, Leave a multicast group
      This options takes SlNetSock_IpMreq_t struct as parameter
    • SLNETSOCK_OPIP_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
      This options takes uint32_t as parameter
    • SLNETSOCK_OPIP_RAW_RX_NO_HEADER
      Raw socket remove IP header from received data.
      Default: data includes ip header
      This options takes uint32_t as parameter
    • SLNETSOCK_OPIP_RAW_IPV6_HDRINCL (inactive)
      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
      This options takes uint32_t as parameter
  • SLNETSOCK_LVL_PHY
    • SLNETSOCK_OPPHY_CHANNEL
      Sets channel in transceiver mode. This options takes uint32_t as channel number parameter
    • SLNETSOCK_OPPHY_RATE
      RAW socket, set WLAN PHY transmit rate
      The values are based on SlWlanRateIndex_e
      This options takes uint32_t as parameter
    • SLNETSOCK_OPPHY_TX_POWER
      RAW socket, set WLAN PHY TX power
      Valid rage is 1-15
      This options takes uint32_t as parameter
    • SLNETSOCK_OPPHY_NUM_FRAMES_TO_TX
      RAW socket, set number of frames to transmit in transceiver mode. Default: 1 packet This options takes uint32_t as parameter
    • SLNETSOCK_OPPHY_PREAMBLE
      RAW socket, set WLAN PHY preamble for Long/Short
      This options takes uint32_t as parameter
    • SLNETSOCK_OPPHY_TX_INHIBIT_THRESHOLD
      RAW socket, set WLAN Tx - Set CCA threshold.
      The values are based on SlNetSockTxInhibitThreshold_e
      This options takes uint32_t as parameter
    • SLNETSOCK_OPPHY_TX_TIMEOUT
      RAW socket, set WLAN Tx - changes the TX timeout (lifetime) of transceiver frames.
      Value in Ms, maximum value is 10ms
      This options takes uint32_t as parameter
    • SLNETSOCK_OPPHY_ALLOW_ACKS
      RAW socket, set WLAN Tx - Enable or Disable sending ACKs in transceiver mode
      0 = disabled / 1 = enabled
      This options takes uint32_t as parameter
[in]optvalSpecifies a value for the option
[in]optlenSpecifies the length of the option value
Returns
Zero on success, or negative error code on failure
Persistent
All params are Non- Persistent
See also
SlNetIfWifi_getSockOpt
Note
Warning
Examples
  • SLNETSOCK_OPSOCK_RCV_BUF:
    SlNetSock_Winsize_t size;
    size.winsize = 3000; // bytes
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_RCV_BUF, (uint8_t *)&size, sizeof(size));

  • SLNETSOCK_OPSOCK_RCV_TIMEO:
    struct SlNetSock_Timeval_t timeVal;
    timeVal.tv_sec = 1; // Seconds
    timeVal.tv_usec = 0; // Microseconds. 10000 microseconds resolution
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_RCV_TIMEO, (uint8_t *)&timeVal, sizeof(timeVal)); // Enable receive timeout

  • SLNETSOCK_OPSOCK_KEEPALIVE: //disable Keepalive
    SlNetSock_Keepalive_t enableOption;
    enableOption.keepaliveEnabled = 0;
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_KEEPALIVE, (uint8_t *)&enableOption, sizeof(enableOption));

  • SLNETSOCK_OPSOCK_KEEPALIVE_TIME: //Set Keepalive timeout
    int16_t Status;
    uint32_t TimeOut = 120;
    SlNetIfWifi_setSockOpt(Sd, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_KEEPALIVE_TIME, (uint8_t *)&TimeOut, sizeof(TimeOut));

  • SLNETSOCK_OPSOCK_NON_BLOCKING: //Enable or disable nonblocking mode
    SlNetSock_Nonblocking_t enableOption;
    enableOption.nonBlockingEnabled = 1;
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_NON_BLOCKING, (uint8_t *)&enableOption, sizeof(enableOption));

  • SLNETSOCK_OPSOCK_NON_IP_BOUNDARY: //disable boundary
    SlNetSock_NonIpBoundary_t enableOption;
    enableOption.nonIpBoundaryEnabled = 1;
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_NON_IP_BOUNDARY, (uint8_t *)&enableOption, sizeof(enableOption));

  • SLNETSOCK_OPSOCK_LINGER:
    SlNetSock_linger_t linger;
    linger.l_onoff = 1;
    linger.l_linger = 10;
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_LINGER, &linger, sizeof(linger));

  • SLNETSOCK_OPIP_MULTICAST_TTL:
    uint8_t ttl = 20;
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_MULTICAST_TTL, &ttl, sizeof(ttl));

  • SLNETSOCK_OPIP_ADD_MEMBERSHIP:
    SlNetSock_IpMreq_t mreq;
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));

  • SLNETSOCK_OPIP_DROP_MEMBERSHIP:
    SlNetSock_IpMreq_t mreq;
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));

  • SLNETSOCK_OPIP_RAW_RX_NO_HEADER:
    uint32_t header = 1; // remove ip header
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_RAW_RX_NO_HEADER, &header, sizeof(header));

  • SLNETSOCK_OPIP_HDRINCL:
    uint32_t header = 1;
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_HDRINCL, &header, sizeof(header));

  • SLNETSOCK_OPIP_RAW_IPV6_HDRINCL:
    uint32_t header = 1;
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_RAW_IPV6_HDRINCL, &header, sizeof(header));

  • SLNETSOCK_OPPHY_CHANNEL:
    uint32_t newChannel = 6; // range is 1-13
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPPHY_CHANNEL, &newChannel, sizeof(newChannel));

  • SLNETSOCK_OPPHY_RATE:
    uint32_t rate = 6; // see wlan.h SlWlanRateIndex_e for values
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_RATE, &rate, sizeof(rate));

  • SLNETSOCK_OPPHY_TX_POWER:
    uint32_t txpower = 1; // valid range is 1-15
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_TX_POWER, &txpower, sizeof(txpower));

  • SLNETSOCK_OPPHY_NUM_FRAMES_TO_TX:
    uint32_t numframes = 1;
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_NUM_FRAMES_TO_TX, &numframes, sizeof(numframes));

  • SLNETSOCK_OPPHY_PREAMBLE:
    uint32_t preamble = 1;
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_PREAMBLE, &preamble, sizeof(preamble));

  • SLNETSOCK_OPPHY_TX_INHIBIT_THRESHOLD:
    uint32_t thrshld = SLNETSOCK_TX_INHIBIT_THRESHOLD_MED;
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_TX_INHIBIT_THRESHOLD , &thrshld, sizeof(thrshld));

  • SLNETSOCK_OPPHY_TX_TIMEOUT:
    uint32_t timeout = 50;
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_TX_TIMEOUT , &timeout, sizeof(timeout));

  • SLNETSOCK_OPPHY_ALLOW_ACKS:
    uint32_t acks = 1; // 0 = disabled / 1 = enabled
    SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_ALLOW_ACKS, &acks, sizeof(acks));

Definition at line 260 of file slnetifwifi.c.

261 {
262  SlNetSock_Timeval_t *slNetSockTimeVal;
263  SlTimeval_t tv;
264 
265  switch (level)
266  {
267  case SLNETSOCK_LVL_SOCKET:
268  {
269  switch (optname)
270  {
271  case SLNETSOCK_OPSOCK_RCV_TIMEO:
272  {
273  /* Translate from SlNetSock_Timeval_t into SlTimeval_t */
274  slNetSockTimeVal = (SlNetSock_Timeval_t *)optval;
275  tv.tv_sec = slNetSockTimeVal->tv_sec;
276  tv.tv_usec = slNetSockTimeVal->tv_usec;
277  optval = (void *)&tv;
278  optlen = sizeof(SlTimeval_t);
279  break;
280  }
281  default:
282  /* Pass values into sl_SetSockOpt directly */
283  break;
284  }
285  break;
286  }
287  default:
288  /* Pass values into sl_SetSockOpt directly */
289  break;
290  }
291 
292  return sl_SetSockOpt(sd, level, optname, optval, optlen);
293 }
_i16 sl_SetSockOpt(_i16 sd, _i16 level, _i16 optname, const void *optval, SlSocklen_t optlen)
Set socket options.
Definition: sl_socket.c:932

§ SlNetIfWifi_socket()

int16_t SlNetIfWifi_socket ( void *  ifContext,
int16_t  Domain,
int16_t  Type,
int16_t  Protocol,
void **  sdContext 
)

Create an endpoint for communication.

The SlNetIfWifi_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 descriptor (handle).

Parameters
[in]ifContextStores interface data if CreateContext function supported and implemented.
[in]domainSpecifies the protocol family of the created socket. For example:
  • SLNETSOCK_AF_INET for network protocol IPv4
  • SLNETSOCK_AF_INET6 for network protocol IPv6
  • SLNETSOCK_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
[in]typeSpecifies the socket type, which determines the semantics of communication over the socket. The socket types supported by the system are implementation-dependent. Possible socket types include:
  • SLNETSOCK_SOCK_STREAM (reliable stream-oriented service or Stream Sockets)
  • SLNETSOCK_SOCK_DGRAM (datagram service or Datagram Sockets)
  • SLNETSOCK_SOCK_RAW (raw protocols atop the network layer)
  • when used with AF_RF:
    • SLNETSOCK_SOCK_RX_MTR
    • SLNETSOCK_SOCK_MAC_WITH_CCA
    • SLNETSOCK_SOCK_MAC_WITH_NO_CCA
    • SLNETSOCK_SOCK_BRIDGE
    • SLNETSOCK_SOCK_ROUTER
[in]protocolSpecifies a particular transport to be used with the socket.
The most common are
  • SLNETSOCK_PROTO_TCP
  • SLNETSOCK_PROTO_UDP
  • SLNETSOCK_PROTO_RAW
  • SLNETSOCK_PROTO_SECURE The value 0 may be used to select a default protocol from the selected domain and type
[in]sdContextAllocate and store socket data if needed for using in other slnetwifi socket functions
Returns
On success, socket descriptor (handle) that is used for consequent socket operations.
A successful return code should be a positive number (int16)
On error, a negative value will be returned specifying the error code.
  • SLNETERR_BSD_EAFNOSUPPORT - illegal domain parameter
  • SLNETERR_BSD_EPROTOTYPE - illegal type parameter
  • SLNETERR_BSD_EACCES - permission denied
  • SLNETERR_BSD_ENSOCK - exceeded maximal number of socket
  • SLNETERR_BSD_ENOMEM - memory allocation error
  • SLNETERR_BSD_EINVAL - error in socket configuration
  • SLNETERR_BSD_EPROTONOSUPPORT - illegal protocol parameter
  • SLNETERR_BSD_EOPNOTSUPP - illegal combination of protocol and type parameters
See also
SlNetIfWifi_socket
Note
Warning

Definition at line 161 of file slnetifwifi.c.

162 {
163  /* Create socket and return the return value of the function */
164  int16_t mappedSocketType = socketType[Type - 1];
165  return (sl_Socket(Domain, mappedSocketType, Protocol));
166 }
_i16 sl_Socket(_i16 Domain, _i16 Type, _i16 Protocol)
Create an endpoint for communication.
Definition: sl_socket.c:133

§ SlNetIfWifi_sockstartSec()

int32_t SlNetIfWifi_sockstartSec ( int16_t  sd,
void *  sdContext,
SlNetSockSecAttrib_t *  secAttrib,
uint8_t  flags 
)

Start a security session on an opened socket.

The SlNetIfWifi_sockstartSec function is used start a security session on an opened socket. If the security handle is NULL the session would be started with the default security settings.

Parameters
[in]sdSocket descriptor (handle)
[in]sdContextMay store socket data if implemented in the SlNetIfWifi_socket function.
[in]secAttribSecure attribute handle
[in]flagsSpecifies flags.
The available flags are:
  • SLNETSOCK_SEC_START_SECURITY_SESSION_ONLY
  • SLNETSOCK_SEC_BIND_CONTEXT_ONLY
  • SLNETSOCK_SEC_IS_SERVER
Returns
Zero on success, or negative error code on failure
See also
Note
Warning
Example
  • start security session on an opened socket:

Definition at line 406 of file slnetifwifi.c.

407 {
408  SlNetSock_SecAttribNode_t *tempSecAttrib = *secAttrib;
409  int32_t retVal = SLNETERR_RET_CODE_OK;
410 
411  if ( 0 != (flags & SLNETSOCK_SEC_BIND_CONTEXT_ONLY) )
412  {
413  /* run over all attributes and set them */
414  while (NULL != tempSecAttrib)
415  {
416  if ( tempSecAttrib->attribName <= SLNETSOCK_SEC_ATTRIB_DISABLE_CERT_STORE)
417  {
418  retVal = sl_SetSockOpt(sd, SL_SOL_SOCKET, StartSecOptName[tempSecAttrib->attribName], tempSecAttrib->attribBuff, tempSecAttrib->attribBuffLen);
419  }
420  else
421  {
422  return SLNETERR_RET_CODE_INVALID_INPUT;
423  }
424  tempSecAttrib = tempSecAttrib->next;
425  }
426  }
427 
428  if ( 0 != (flags & SLNETSOCK_SEC_START_SECURITY_SESSION_ONLY) )
429  {
430  /* Start TLS session */
431  retVal = sl_StartTLS(sd);
432  }
433 
434  return retVal;
435 }
_i16 sl_SetSockOpt(_i16 sd, _i16 level, _i16 optname, const void *optval, SlSocklen_t optlen)
Set socket options.
Definition: sl_socket.c:932
_i16 sl_StartTLS(_i16 sd)
Initiate TLS connection on a socket.
Definition: sl_socket.c:1972

Data Structure Documentation

§ SlInAddr_t

struct SlInAddr_t

Definition at line 224 of file sl_socket.h.

Data Fields
_u32 s_addr
union S_un S_un

§ SlIn6Addr_t

struct SlIn6Addr_t

Definition at line 238 of file sl_socket.h.

Data Fields
union SlIn6Addr_t _S6_un

§ SlIn6Addr_t._S6_un

union SlIn6Addr_t._S6_un

Definition at line 240 of file sl_socket.h.

Data Fields
_u32 _S6_u32[4]
_u8 _S6_u8[16]

§ SlSockKeepalive_t

struct SlSockKeepalive_t

Definition at line 249 of file sl_socket.h.

Data Fields
_u32 KeepaliveEnabled

§ SlSockReuseaddr_t

struct SlSockReuseaddr_t

Definition at line 254 of file sl_socket.h.

Data Fields
_u32 ReuseaddrEnabled

§ SlSockRxNoIpBoundary_t

struct SlSockRxNoIpBoundary_t

Definition at line 259 of file sl_socket.h.

Data Fields
_i32 RxIpNoBoundaryEnabled

§ SlSockWinsize_t

struct SlSockWinsize_t

Definition at line 264 of file sl_socket.h.

Data Fields
_u32 WinSize

§ SlSockNonblocking_t

struct SlSockNonblocking_t

Definition at line 269 of file sl_socket.h.

Data Fields
_u32 NonBlockingEnabled

§ SlSocketAsyncEvent_t

struct SlSocketAsyncEvent_t

Definition at line 274 of file sl_socket.h.

Data Fields
_i8 pExtraInfo[128]
_u8 Sd
_u8 Type
_i16 Val

§ SlSockTxFailEventData_t

struct SlSockTxFailEventData_t

Definition at line 282 of file sl_socket.h.

Data Fields
_u8 Padding
_u8 Sd
_i16 Status

§ SlSockEventData_u

union SlSockEventData_u

Definition at line 290 of file sl_socket.h.

Data Fields
SlSocketAsyncEvent_t SockAsyncData
SlSockTxFailEventData_t SockTxFailData

§ SlSockEvent_t

struct SlSockEvent_t

Definition at line 297 of file sl_socket.h.

Data Fields
_u32 Event
SlSockEventData_u SocketAsyncEvent

§ SlSockTriggerEvent_t

struct SlSockTriggerEvent_t

Definition at line 303 of file sl_socket.h.

Data Fields
_u32 Event
_u32 EventData

§ SlSockSecureALPN_t

struct SlSockSecureALPN_t

Definition at line 310 of file sl_socket.h.

Data Fields
_u32 SecureALPN

§ SlSockSecureMask_t

struct SlSockSecureMask_t

Definition at line 315 of file sl_socket.h.

Data Fields
_u32 SecureMask

§ SlSockSecureMethod_t

struct SlSockSecureMethod_t

Definition at line 320 of file sl_socket.h.

Data Fields
_u8 SecureMethod

§ SlSockSSLCertInfo_t

struct SlSockSSLCertInfo_t

Definition at line 325 of file sl_socket.h.

Data Fields
_i8 FromDate[8]
_i8 IssuerName[SL_MAX_ISSUER_AND_SUBJECT_NAME_LEN]
_i8 IssuerNameLen
_u16 IssuerNameXoredSha1
_i8 Padding[2]
_i8 SubjectName[SL_MAX_ISSUER_AND_SUBJECT_NAME_LEN]
_i8 SubjectNameLen
_u16 SubjectNameXoredSha1
_i8 ToDate[8]

§ SlSockSSLConnectionParams_t

struct SlSockSSLConnectionParams_t

Definition at line 339 of file sl_socket.h.

Data Fields
_u32 SecureALPNChosenProtocol
_u32 SecureCipherSuit
_u32 SecureIsPeerValidated
SlSockSSLCertInfo_t SecurePeerCertinfo
_u32 SecureVersion

§ SlRxMetrics_TLV_t

struct SlRxMetrics_TLV_t

Definition at line 355 of file sl_socket.h.

Data Fields
_u16 length
_u16 type

§ SlSockIpMreq_t

struct SlSockIpMreq_t

Definition at line 422 of file sl_socket.h.

Data Fields
SlInAddr_t imr_interface
SlInAddr_t imr_multiaddr

§ SlSockIpV6Mreq_t

struct SlSockIpV6Mreq_t

Definition at line 428 of file sl_socket.h.

Data Fields
_u32 ipv6mr_interface
SlIn6Addr_t ipv6mr_multiaddr

§ SlSocklinger_t

struct SlSocklinger_t

Definition at line 433 of file sl_socket.h.

Data Fields
_u32 l_linger
_u32 l_onoff

§ SlTimeval_t

struct SlTimeval_t

Definition at line 443 of file sl_socket.h.

Data Fields
SlTime_t tv_sec
SlSuseconds_t tv_usec

§ SlSockAddr_t

struct SlSockAddr_t

Definition at line 452 of file sl_socket.h.

Data Fields
_u8 sa_data[14]
_u16 sa_family

§ SlSockAddrIn6_t

struct SlSockAddrIn6_t

Definition at line 458 of file sl_socket.h.

Data Fields
SlIn6Addr_t sin6_addr
_u16 sin6_family
_u32 sin6_flowinfo
_u16 sin6_port
_u32 sin6_scope_id

§ SlSockAddrIn_t

struct SlSockAddrIn_t

Definition at line 469 of file sl_socket.h.

Data Fields
SlInAddr_t sin_addr
_u16 sin_family
_u16 sin_port
_i8 sin_zero[8]

§ SlSockSecureFiles_t

struct SlSockSecureFiles_t

Definition at line 477 of file sl_socket.h.

Data Fields
_u8 SecureFiles[4]

§ SlFdSet_t

struct SlFdSet_t

Definition at line 482 of file sl_socket.h.

Data Fields
_u32 fd_array[(SL_FD_SETSIZE+(_u8) 31)/(_u8) 32]

§ SlTransceiverRxOverHead_t

struct SlTransceiverRxOverHead_t

Definition at line 487 of file sl_socket.h.

Data Fields
_u8 Channel
_u8 Padding
_u8 Rate
_i8 Rssi
_u32 Timestamp

§ SlRxMetricsEnableDisableRXOnBSS_t

struct SlRxMetricsEnableDisableRXOnBSS_t

Definition at line 496 of file sl_socket.h.

Data Fields
_u32 enableDisable

Variable Documentation

§ SlNetIfConfigWifi

SlNetIf_Config_t SlNetIfConfigWifi

SlNetIfConfigWifi structure contains all the function callbacks that are expected to be filled by the relevant network stack interface Each interface has different capabilities, so not all the API's must be supported. Interface that is not supporting a non-mandatory API are set to NULL

Definition at line 68 of file slnetifwifi.c.