SimpleLink CC32xx ATCommands Library
Simplifies the implementation of Internet connectivity
Socket

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

Functions

int32_t ATCmdSock_socketCallback (void *arg)
 Sock Socket callback. More...
 
int32_t ATCmdSock_closeCallback (void *arg)
 Sock Close callback. More...
 
int32_t ATCmdSock_acceptCallback (void *arg)
 Sock Accept callback. More...
 
int32_t ATCmdSock_bindCallback (void *arg)
 Sock Bind callback. More...
 
int32_t ATCmdSock_listenCallback (void *arg)
 Sock Listen callback. More...
 
int32_t ATCmdSock_connectCallback (void *arg)
 Sock Connect callback. More...
 
int32_t ATCmdSock_selectCallback (void *arg)
 Sock Select callback. More...
 
int32_t ATCmdSock_setSockOptCallback (void *arg)
 Sock SetSockOpt callback. More...
 
int32_t ATCmdSock_getSockOptCallback (void *arg)
 Sock GetSockOpt callback. More...
 
int32_t ATCmdSock_sendCallback (void *arg)
 Sock Send callback. More...
 
int32_t ATCmdSock_recvCallback (void *arg)
 Sock Recv callback. More...
 
int32_t ATCmdSock_sendToCallback (void *arg)
 Sock SendTo callback. More...
 
int32_t ATCmdSock_recvFromCallback (void *arg)
 Sock RecvFrom callback. More...
 

Detailed Description

Controls standard client/server sockets programming options and capabilities.

Function Documentation

§ ATCmdSock_acceptCallback()

int32_t ATCmdSock_acceptCallback ( void *  arg)

Sock Accept callback.

This routine Accept a connection on a socket.

Parameters
arg- Points to command line buffer.
Returns
Zero on success, or negative error code on failure

This routine Accept a connection on a socket.

Parameters
arg- Points to command line buffer.
Returns
Upon successful completion, the function shall return 0. In case of failure, this function would return an error;

Definition at line 406 of file atcmd_socket.c.

407 {
408  int32_t ret = 0;
409  ATCmdSock_Accept_t *params;
410 
411  params = malloc(sizeof(ATCmdSock_Accept_t));
412 
413  if (params == NULL)
414  {
415  ATCmd_errorResult(ATCmd_errorAllocStr,0);
416  return -1;
417  }
418  memset(params, 0x0, sizeof(ATCmdSock_Accept_t));
419 
420  /* Call the command parser */
421  ret = ATCmdSock_acceptParse((char *)arg, params);
422 
423  if (ret < 0)
424  {
425  ATCmd_errorResult(ATCmd_errorParseStr,ret);
426  ATCmdSock_acceptFree(params);
427  return -1;
428  }
429 
430  /* return command complete for blocked command */
431  ATCmd_okResult();
432 
433  /* create socket */
434  params->ret.sd = sl_Accept(params->sd,&params->ret.addr,&params->ret.addrlen);
435 
436  if (params->ret.sd < 0)
437  {
438  ATCmd_errorResult(ATCmd_errorCmdStr,params->ret.sd);
439  ATCmdSock_acceptFree(params);
440  }
441  else
442  {
443  ATCmd_commandResult(ATCmdSock_acceptResult,params,0);
444  ATCmd_okResult();
445  }
446 
447  return ret;
448 }

§ ATCmdSock_bindCallback()

int32_t ATCmdSock_bindCallback ( void *  arg)

Sock Bind callback.

This routine assign a name to a socket.

Parameters
arg- Points to command line buffer.
Returns
Zero on success, or negative error code on failure

This routine assign a name to a socket.

Parameters
arg- Points to command line buffer.
Returns
Upon successful completion, the function shall return 0. In case of failure, this function would return an error;

Definition at line 537 of file atcmd_socket.c.

538 {
539  int32_t ret = 0;
540  ATCmdSock_t params;
541 
542  memset(&params, 0x0, sizeof(ATCmdSock_t));
543 
544  /* Call the command parser */
545  ret = ATCmdSock_parse((char **)&arg, &params,ATCMD_DELIM_TRM);
546 
547  if (ret < 0)
548  {
549  ATCmd_errorResult(ATCmd_errorParseStr,ret);
550  return -1;
551  }
552 
553  /* bind socket */
554  ret = sl_Bind(params.sd,&params.addr,params.addrlen);
555 
556  if (ret < 0)
557  {
558  ATCmd_errorResult(ATCmd_errorCmdStr,ret);
559  }
560  else
561  {
562  ATCmd_okResult();
563  }
564 
565  return ret;
566 }

§ ATCmdSock_closeCallback()

int32_t ATCmdSock_closeCallback ( void *  arg)

Sock Close callback.

This routine close socket.

Parameters
arg- Points to command line buffer.
Returns
Zero on success, or negative error code on failure

This routine close socket.

Parameters
arg- Points to command line buffer.
Returns
Upon successful completion, the function shall return 0. In case of failure, this function would return an error;

Definition at line 257 of file atcmd_socket.c.

258 {
259  int32_t ret = 0;
260  int16_t sock;
261 
262  /* Call the command parser */
263  if ((ret = StrMpl_getVal((char **)&arg, (void *)&sock, ATCMD_DELIM_TRM,STRMPL_FLAG_PARAM_SIZE_16 )) < 0)
264  {
265  ATCmd_errorResult(ATCmd_errorParseStr,ret);
266  return -1;
267  }
268 
269  /* create socket */
270  ret = sl_Close(sock);
271 
272  if (ret < 0)
273  {
274  ATCmd_errorResult(ATCmd_errorCmdStr,ret);
275  }
276  else
277  {
278  ATCmd_commandResult(ATCmdSock_closeResult,NULL,sock);
279  ATCmd_okResult();
280  }
281 
282  return ret;
283 }

§ ATCmdSock_connectCallback()

int32_t ATCmdSock_connectCallback ( void *  arg)

Sock Connect callback.

This routine initiate a connection on a socket.

Parameters
arg- Points to command line buffer.
Returns
Zero on success, or negative error code on failure

This routine initiate a connection on a socket.

Parameters
arg- Points to command line buffer.
Returns
Upon successful completion, the function shall return 0. In case of failure, this function would return an error;

Definition at line 714 of file atcmd_socket.c.

715 {
716  int32_t ret = 0;
717  ATCmdSock_t *params;
718 
719  params = malloc(sizeof(ATCmdSock_t));
720 
721  if (params == NULL)
722  {
723  ATCmd_errorResult(ATCmd_errorAllocStr,0);
724  return -1;
725  }
726  memset(params, 0x0, sizeof(ATCmdSock_t));
727 
728  /* Call the command parser */
729  ret = ATCmdSock_parse((char **)&arg, params,ATCMD_DELIM_TRM);
730 
731  if (ret < 0)
732  {
733  ATCmd_errorResult(ATCmd_errorParseStr,ret);
734  ATCmdSock_connectFree(params);
735  return -1;
736  }
737 
738  /* return command complete for blocked command */
739  ATCmd_okResult();
740 
741  /* connect */
742  ret = sl_Connect(params->sd,&params->addr,params->addrlen);
743 
744  if (ret < 0)
745  {
746  ATCmd_errorResult(ATCmd_errorCmdStr,ret);
747  ATCmdSock_connectFree(params);
748  }
749  else
750  {
751  ATCmd_commandResult(ATCmdSock_connectResult,params,0);
752  ATCmd_okResult();
753  }
754 
755  return ret;
756 }

§ ATCmdSock_getSockOptCallback()

int32_t ATCmdSock_getSockOptCallback ( void *  arg)

Sock GetSockOpt callback.

This routine get socket options

Parameters
arg- Points to command line buffer.
Returns
Zero on success, or negative error code on failure

This routine get socket options

Parameters
arg- Points to command line buffer.
Returns
Upon successful completion, the function shall return 0. In case of failure, this function would return an error;

Definition at line 1402 of file atcmd_socket.c.

1403 {
1404  int32_t ret = 0;
1405  ATCmdSock_SetSockOpt_t *params;
1406 
1407  params = malloc(sizeof(ATCmdSock_SetSockOpt_t));
1408 
1409  if (params == NULL)
1410  {
1411  ATCmd_errorResult(ATCmd_errorAllocStr,0);
1412  return -1;
1413  }
1414  memset(params, 0x0, sizeof(ATCmdSock_SetSockOpt_t));
1415 
1416  /* Call the command parser */
1417  ret = ATCmdSock_getSockOptParse((char *)arg, params);
1418 
1419  if (ret < 0)
1420  {
1421  ATCmd_errorResult(ATCmd_errorParseStr,ret);
1422  ATCmdSock_getSockOptFree(params);
1423  return -1;
1424  }
1425 
1426  /* set sock opt */
1427  ret = sl_GetSockOpt(params->sd,params->level,params->optname,params->optval,&params->optlen);
1428 
1429  if (ret < 0)
1430  {
1431  ATCmd_errorResult(ATCmd_errorCmdStr,ret);
1432  ATCmdSock_getSockOptFree(params);
1433  }
1434  else
1435  {
1436  ATCmd_commandResult(ATCmdSock_getSockOptResult,params,0);
1437  ATCmd_okResult();
1438  }
1439 
1440  return ret;
1441 }

§ ATCmdSock_listenCallback()

int32_t ATCmdSock_listenCallback ( void *  arg)

Sock Listen callback.

This routine Listen for connections on a socket.

Parameters
arg- Points to command line buffer.
Returns
Zero on success, or negative error code on failure

This routine Listen for connections on a socket.

Parameters
arg- Points to command line buffer.
Returns
Upon successful completion, the function shall return 0. In case of failure, this function would return an error;

Definition at line 609 of file atcmd_socket.c.

610 {
611  int32_t ret = 0;
612  ATCmdSock_Listen_t params;
613 
614  memset(&params, 0x0, sizeof(ATCmdSock_Listen_t));
615 
616  /* Call the command parser */
617  ret = ATCmdSock_listenParse((char *)arg, &params);
618 
619  if (ret < 0)
620  {
621  ATCmd_errorResult(ATCmd_errorParseStr,ret);
622  return -1;
623  }
624 
625  /* create socket */
626  ret = sl_Listen(params.sd,params.backlog);
627 
628  if (ret < 0)
629  {
630  ATCmd_errorResult(ATCmd_errorCmdStr,ret);
631  }
632  else
633  {
634  ATCmd_okResult();
635  }
636 
637  return ret;
638 }

§ ATCmdSock_recvCallback()

int32_t ATCmdSock_recvCallback ( void *  arg)

Sock Recv callback.

This routine This routine read data from TCP socket

Parameters
arg- Points to command line buffer.
Returns
Zero on success, or negative error code on failure

This routine This routine read data from TCP socket

Parameters
arg- Points to command line buffer.
Returns
Upon successful completion, the function shall return 0. In case of failure, this function would return an error;

Definition at line 1684 of file atcmd_socket.c.

1685 {
1686  int32_t ret = 0;
1687  ATCmdSock_tcp_t *params;
1688 
1689  params = malloc(sizeof(ATCmdSock_tcp_t));
1690 
1691  if (params == NULL)
1692  {
1693  ATCmd_errorResult(ATCmd_errorAllocStr,0);
1694  return -1;
1695  }
1696 
1697  memset(params, 0x0, sizeof(ATCmdSock_tcp_t));
1698 
1699  /* Call the command parser */
1700  ret = ATCmdSock_recvParse((char *)arg, params);
1701 
1702  if (ret < 0)
1703  {
1704  ATCmd_errorResult(ATCmd_errorParseStr,ret);
1705  ATCmdSock_recvFree(params);
1706  return -1;
1707  }
1708 
1709  /* return command complete for blocked command */
1710  ATCmd_okResult();
1711 
1712  /* recv */
1713  params->len = sl_Recv(params->sd, params->data, params->len, params->flags);
1714 
1715  if (params->len < 0)
1716  {
1717  ATCmd_errorResult(ATCmd_errorCmdStr,params->len);
1718  ATCmdSock_recvFree(params);
1719  }
1720  else
1721  {
1722  ATCmd_commandResult(ATCmdSock_recvResult,params,0);
1723  ATCmd_okResult();
1724  }
1725 
1726  return ret;
1727 }

§ ATCmdSock_recvFromCallback()

int32_t ATCmdSock_recvFromCallback ( void *  arg)

Sock RecvFrom callback.

This routine read data from socket

Parameters
arg- Points to command line buffer.
Returns
Zero on success, or negative error code on failure

This routine read data from socket

Parameters
arg- Points to command line buffer.
Returns
Upon successful completion, the function shall return 0. In case of failure, this function would return an error;

Definition at line 1972 of file atcmd_socket.c.

1973 {
1974  int32_t ret = 0;
1975  ATCmdSock_udp_t *params;
1976 
1977  params = malloc(sizeof(ATCmdSock_udp_t));
1978 
1979  if (params == NULL)
1980  {
1981  ATCmd_errorResult(ATCmd_errorAllocStr,0);
1982  return -1;
1983  }
1984 
1985  memset(params, 0x0, sizeof(ATCmdSock_udp_t));
1986 
1987  /* Call the command parser */
1988  ret = ATCmdSock_recvFromParse((char *)arg, params);
1989 
1990  if (ret < 0)
1991  {
1992  ATCmd_errorResult(ATCmd_errorParseStr,ret);
1993  ATCmdSock_recvFromFree(params);
1994  return -1;
1995  }
1996 
1997  /* return command complete for blocked command */
1998  ATCmd_okResult();
1999 
2000  /* recv from */
2001  params->len = sl_RecvFrom(params->target.sd, params->data, params->len, params->flags,&params->target.addr,&params->target.addrlen);
2002 
2003  if (params->len < 0)
2004  {
2005  ATCmd_errorResult(ATCmd_errorCmdStr,params->len);
2006  ATCmdSock_recvFromFree(params);
2007  }
2008  else
2009  {
2010  ATCmd_commandResult(ATCmdSock_recvFromResult,params,0);
2011  ATCmd_okResult();
2012  }
2013 
2014  return ret;
2015 }

§ ATCmdSock_selectCallback()

int32_t ATCmdSock_selectCallback ( void *  arg)

Sock Select callback.

This routine monitor socket activity.

Parameters
arg- Points to command line buffer.
Returns
Zero on success, or negative error code on failure

This routine monitor socket activity.

Parameters
arg- Points to command line buffer.
Returns
Upon successful completion, the function shall return 0. In case of failure, this function would return an error;

Definition at line 848 of file atcmd_socket.c.

849 {
850  int32_t ret = 0;
851  ATCmdSock_Select_t *params;
852 
853  params = malloc(sizeof(ATCmdSock_Select_t));
854 
855  if (params == NULL)
856  {
857  ATCmd_errorResult(ATCmd_errorAllocStr,0);
858  return -1;
859  }
860  memset(params, 0x0, sizeof(ATCmdSock_Select_t));
861 
862  /* Call the command parser */
863  ret = ATCmdSock_selectParse((char *)arg, params);
864 
865  if (ret < 0)
866  {
867  ATCmd_errorResult(ATCmd_errorParseStr,ret);
868  ATCmdSock_selectFree(params);
869  return -1;
870  }
871  else
872  {
873  ATCmd_okResult();
874  }
875 
876  /* select */
877  ret = sl_Select(params->nfds,&params->readsds,NULL,NULL,&params->timeout);
878 
879  if (ret < 0)
880  {
881  ATCmd_errorResult(ATCmd_errorCmdStr,ret);
882  ATCmdSock_selectFree(params);
883  }
884  else
885  {
886  ATCmd_commandResult(ATCmdSock_selectResult,params,0);
887  ATCmd_okResult();
888  }
889 
890  return ret;
891 }

§ ATCmdSock_sendCallback()

int32_t ATCmdSock_sendCallback ( void *  arg)

Sock Send callback.

This routine write data to TCP socket

Parameters
arg- Points to command line buffer.
Returns
Zero on success, or negative error code on failure

This routine write data to TCP socket

Parameters
arg- Points to command line buffer.
Returns
Upon successful completion, the function shall return 0. In case of failure, this function would return an error;

Definition at line 1534 of file atcmd_socket.c.

1535 {
1536  int32_t ret = 0;
1537  ATCmdSock_tcp_t params;
1538 
1539  memset(&params, 0x0, sizeof(ATCmdSock_tcp_t));
1540 
1541  /* Call the command parser */
1542  ret = ATCmdSock_sendParse((char *)arg, &params);
1543 
1544  if (ret < 0)
1545  {
1546  ATCmd_errorResult(ATCmd_errorParseStr,ret);
1547  ATCmdSock_sendFree(&params);
1548  return -1;
1549  }
1550 
1551  /* send */
1552  ret = sl_Send(params.sd, params.data, params.len, params.flags);
1553 
1554  if (ret < 0)
1555  {
1556  ATCmd_errorResult(ATCmd_errorCmdStr,ret);
1557  }
1558  else
1559  {
1560  ATCmd_okResult();
1561  }
1562 
1563  ATCmdSock_sendFree(&params);
1564  return ret;
1565 }

§ ATCmdSock_sendToCallback()

int32_t ATCmdSock_sendToCallback ( void *  arg)

Sock SendTo callback.

This routine write data to socket

Parameters
arg- Points to command line buffer.
Returns
Zero on success, or negative error code on failure

This routine write data to socket

Parameters
arg- Points to command line buffer.
Returns
Upon successful completion, the function shall return 0. In case of failure, this function would return an error;

Definition at line 1820 of file atcmd_socket.c.

1821 {
1822  int32_t ret = 0;
1823  ATCmdSock_udp_t params;
1824 
1825  memset(&params, 0x0, sizeof(ATCmdSock_udp_t));
1826 
1827  /* Call the command parser */
1828  ret = ATCmdSock_sendToParse((char *)arg, &params);
1829 
1830  if (ret < 0)
1831  {
1832  ATCmd_errorResult(ATCmd_errorParseStr,ret);
1833  ATCmdSock_sendToFree(&params);
1834  return -1;
1835  }
1836 
1837  /* send */
1838  ret = sl_SendTo(params.target.sd, params.data, params.len, params.flags,&params.target.addr,params.target.addrlen);
1839 
1840  if (ret < 0)
1841  {
1842  ATCmd_errorResult(ATCmd_errorCmdStr,ret);
1843  }
1844  else
1845  {
1846  ATCmd_okResult();
1847  }
1848 
1849  ATCmdSock_sendToFree(&params);
1850  return ret;
1851 }

§ ATCmdSock_setSockOptCallback()

int32_t ATCmdSock_setSockOptCallback ( void *  arg)

Sock SetSockOpt callback.

This routine Set socket options

Parameters
arg- Points to command line buffer.
Returns
Zero on success, or negative error code on failure

This routine Set socket options

Parameters
arg- Points to command line buffer.
Returns
Upon successful completion, the function shall return 0. In case of failure, this function would return an error;

Definition at line 1144 of file atcmd_socket.c.

1145 {
1146  int32_t ret = 0;
1147  ATCmdSock_SetSockOpt_t params;
1148 
1149  memset(&params, 0x0, sizeof(ATCmdSock_SetSockOpt_t));
1150 
1151  /* Call the command parser */
1152  ret = ATCmdSock_setSockOptParse((char *)arg, &params);
1153 
1154  if (ret < 0)
1155  {
1156  ATCmd_errorResult(ATCmd_errorParseStr,ret);
1157  ATCmdSock_setSockOptFree(&params);
1158  return -1;
1159  }
1160 
1161  /* set sock opt */
1162  ret = sl_SetSockOpt(params.sd,params.level,params.optname,(const void *)params.optval,params.optlen);
1163 
1164  if (ret < 0)
1165  {
1166  ATCmd_errorResult(ATCmd_errorCmdStr,ret);
1167  }
1168  else
1169  {
1170  ATCmd_okResult();
1171  }
1172 
1173  ATCmdSock_setSockOptFree(&params);
1174  return ret;
1175 }

§ ATCmdSock_socketCallback()

int32_t ATCmdSock_socketCallback ( void *  arg)

Sock Socket callback.

This routine create socket.

Parameters
arg- Points to command line buffer.
Returns
Zero on success, or negative error code on failure

This routine create socket.

Parameters
arg- Points to command line buffer.
Returns
Upon successful completion, the function shall return 0. In case of failure, this function would return an error;

Definition at line 193 of file atcmd_socket.c.

194 {
195  int32_t ret = 0;
196  ATCmdSock_Socket_t sockParams;
197 
198  memset(&sockParams, 0x0, sizeof(ATCmdSock_Socket_t));
199 
200  /* Call the command parser */
201  ret = ATCmdSock_socketParse((char *)arg,&sockParams);
202 
203  if(ret < 0)
204  {
205  ATCmd_errorResult(ATCmd_errorParseStr,ret);
206  return -1;
207  }
208 
209  /* create socket */
210  ret = sl_Socket(sockParams.domain, sockParams.type, sockParams.protocol);
211 
212  if (ret < 0)
213  {
214  ATCmd_errorResult(ATCmd_errorCmdStr,ret);
215  }
216  else
217  {
218  ATCmd_commandResult(ATCmdSock_socketResult,NULL,ret);
219  ATCmd_okResult();
220  }
221 
222  return ret;
223 }