socket.c
Go to the documentation of this file.
1 
35 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
36 INCLUDES
37 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
38 
39 #include "bsp/include/nm_bsp.h"
40 #include "socket/include/socket.h"
41 #include "driver/source/m2m_hif.h"
43 
44 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
45 MACROS
46 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
47 
48 
49 #define TLS_RECORD_HEADER_LENGTH (5)
50 #define ETHERNET_HEADER_OFFSET (34)
51 #define ETHERNET_HEADER_LENGTH (14)
52 #define TCP_IP_HEADER_LENGTH (40)
53 #define UDP_IP_HEADER_LENGTH (28)
54 
55 #define IP_PACKET_OFFSET (ETHERNET_HEADER_LENGTH + ETHERNET_HEADER_OFFSET - M2M_HIF_HDR_OFFSET)
56 
57 #define TCP_TX_PACKET_OFFSET (IP_PACKET_OFFSET + TCP_IP_HEADER_LENGTH)
58 #define UDP_TX_PACKET_OFFSET (IP_PACKET_OFFSET + UDP_IP_HEADER_LENGTH)
59 #define SSL_TX_PACKET_OFFSET (TCP_TX_PACKET_OFFSET + TLS_RECORD_HEADER_LENGTH)
60 
61 #define SOCKET_REQUEST(reqID, reqArgs, reqSize, reqPayload, reqPayloadSize, reqPayloadOffset) \
62  hif_send(M2M_REQ_GROUP_IP, reqID, reqArgs, reqSize, reqPayload, reqPayloadSize, reqPayloadOffset)
63 
64 
65 #define SSL_FLAGS_ACTIVE NBIT0
66 #define SSL_FLAGS_BYPASS_X509 NBIT1
67 #define SSL_FLAGS_CACHE_SESSION NBIT4
68 #define SSL_FLAGS_CHECK_CERTNAME NBIT6
69 
70 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
71 PRIVATE DATA TYPES
72 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
73 
74 
78 typedef struct{
83 
84 
88 typedef struct{
96 }tstrSocket;
97 
98 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
99 GLOBALS
100 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
101 
102 volatile sint8 gsockerrno;
104 volatile uint8 gu8OpCode;
106 volatile uint16 gu16SessionID = 0;
107 
110 volatile uint8 gbSocketInit = 0;
112 
113 /*********************************************************************
114 Function
115  Socket_ReadSocketData
116 
117 Description
118  Callback function used by the NMC1500 driver to deliver messages
119  for socket layer.
120 
121 Return
122  None.
123 
124 Author
125  Ahmed Ezzat
126 
127 Version
128  1.0
129 
130 Date
131  17 July 2012
132 *********************************************************************/
133 NMI_API void Socket_ReadSocketData(SOCKET sock, tstrSocketRecvMsg *pstrRecv,uint8 u8SocketMsg,
134  uint32 u32StartAddress,uint16 u16ReadCount)
135 {
136  uint32 u32Address = u32StartAddress;
137  uint16 u16Read;
138  sint16 s16Diff;
139 
140  pstrRecv->u16RemainingSize = u16ReadCount;
141  if((u16ReadCount > 0) && (gastrSockets[sock].pu8UserBuffer != NULL) && (gastrSockets[sock].u16UserBufferSize > 0) && (gastrSockets[sock].bIsUsed == 1))
142  {
143  u16Read = u16ReadCount;
144  s16Diff = u16Read - gastrSockets[sock].u16UserBufferSize;
145  if(s16Diff > 0)
146  u16Read = gastrSockets[sock].u16UserBufferSize;
147 
148  if(hif_receive(u32Address, gastrSockets[sock].pu8UserBuffer, u16Read, 1) == M2M_SUCCESS)
149  {
150  pstrRecv->pu8Buffer = gastrSockets[sock].pu8UserBuffer;
151  pstrRecv->s16BufferSize = u16Read;
152  pstrRecv->u16RemainingSize -= u16Read;
153 
154  gastrSockets[sock].u16UserBufferSize -= u16Read;
155  if(gastrSockets[sock].u16UserBufferSize == 0)
156  gastrSockets[sock].pu8UserBuffer = NULL;
157 
158  if (gpfAppSocketCb)
159  gpfAppSocketCb(sock,u8SocketMsg, pstrRecv);
160  }
161  else
162  {
163  M2M_INFO("(ERRR)Current <%d>\n", u16ReadCount);
164  }
165  }
166 }
167 /*********************************************************************
168 Function
169  m2m_ip_cb
170 
171 Description
172  Callback function used by the NMC1000 driver to deliver messages
173  for socket layer.
174 
175 Return
176  None.
177 
178 Author
179  Ahmed Ezzat
180 
181 Version
182  1.0
183 
184 Date
185  17 July 2012
186 *********************************************************************/
187 static void m2m_ip_cb(uint8 u8OpCode, uint16 u16BufferSize,uint32 u32Address)
188 {
189  if(u8OpCode == SOCKET_CMD_BIND)
190  {
191  tstrBindReply strBindReply;
192  tstrSocketBindMsg strBind;
193 
194  if(hif_receive(u32Address, (uint8*)&strBindReply, sizeof(tstrBindReply), 0) == M2M_SUCCESS)
195  {
196  strBind.status = strBindReply.s8Status;
197  if(gpfAppSocketCb)
198  gpfAppSocketCb(strBindReply.sock,SOCKET_MSG_BIND,&strBind);
199  }
200  }
201  else if(u8OpCode == SOCKET_CMD_LISTEN)
202  {
203  tstrListenReply strListenReply;
204  tstrSocketListenMsg strListen;
205  if(hif_receive(u32Address, (uint8*)&strListenReply, sizeof(tstrListenReply), 0) == M2M_SUCCESS)
206  {
207  strListen.status = strListenReply.s8Status;
208  if(gpfAppSocketCb)
209  gpfAppSocketCb(strListenReply.sock,SOCKET_MSG_LISTEN, &strListen);
210  }
211  }
212  else if(u8OpCode == SOCKET_CMD_ACCEPT)
213  {
214  tstrAcceptReply strAcceptReply;
215  tstrSocketAcceptMsg strAccept;
216  if(hif_receive(u32Address, (uint8*)&strAcceptReply, sizeof(tstrAcceptReply), 0) == M2M_SUCCESS)
217  {
218  if(strAcceptReply.sConnectedSock >= 0)
219  {
220  gastrSockets[strAcceptReply.sConnectedSock].u8SSLFlags = 0;
221  gastrSockets[strAcceptReply.sConnectedSock].bIsUsed = 1;
222 
223  /* The session ID is used to distinguish different socket connections
224  by comparing the assigned session ID to the one reported by the firmware*/
225  ++gu16SessionID;
226  if(gu16SessionID == 0)
227  ++gu16SessionID;
228 
229  gastrSockets[strAcceptReply.sConnectedSock].u16SessionID = gu16SessionID;
230  M2M_DBG("Socket %d session ID = %d\r\n",strAcceptReply.sConnectedSock , gu16SessionID );
231  }
232  strAccept.sock = strAcceptReply.sConnectedSock;
233  strAccept.strAddr.sin_family = AF_INET;
234  strAccept.strAddr.sin_port = strAcceptReply.strAddr.u16Port;
235  strAccept.strAddr.sin_addr.s_addr = strAcceptReply.strAddr.u32IPAddr;
236  if(gpfAppSocketCb)
237  gpfAppSocketCb(strAcceptReply.sListenSock, SOCKET_MSG_ACCEPT, &strAccept);
238  }
239  }
240  else if((u8OpCode == SOCKET_CMD_CONNECT) || (u8OpCode == SOCKET_CMD_SSL_CONNECT))
241  {
242  tstrConnectReply strConnectReply;
243  tstrSocketConnectMsg strConnMsg;
244  if(hif_receive(u32Address, (uint8*)&strConnectReply, sizeof(tstrConnectReply), 0) == M2M_SUCCESS)
245  {
246  strConnMsg.sock = strConnectReply.sock;
247  strConnMsg.s8Error = strConnectReply.s8Error;
248  if(strConnectReply.s8Error == SOCK_ERR_NO_ERROR)
249  {
250  gastrSockets[strConnectReply.sock].u16DataOffset = strConnectReply.u16AppDataOffset - M2M_HIF_HDR_OFFSET;
251  }
252  if(gpfAppSocketCb)
253  gpfAppSocketCb(strConnectReply.sock,SOCKET_MSG_CONNECT, &strConnMsg);
254  }
255  }
256  else if(u8OpCode == SOCKET_CMD_DNS_RESOLVE)
257  {
258  tstrDnsReply strDnsReply;
259  if(hif_receive(u32Address, (uint8*)&strDnsReply, sizeof(tstrDnsReply), 0) == M2M_SUCCESS)
260  {
261  strDnsReply.u32HostIP = strDnsReply.u32HostIP;
262  if(gpfAppResolveCb)
263  gpfAppResolveCb((uint8*)strDnsReply.acHostName, strDnsReply.u32HostIP);
264  }
265  }
266  else if((u8OpCode == SOCKET_CMD_RECV) || (u8OpCode == SOCKET_CMD_RECVFROM) || (u8OpCode == SOCKET_CMD_SSL_RECV))
267  {
268  SOCKET sock;
269  sint16 s16RecvStatus;
270  tstrRecvReply strRecvReply;
271  uint16 u16ReadSize;
272  tstrSocketRecvMsg strRecvMsg;
273  uint8 u8CallbackMsgID = SOCKET_MSG_RECV;
274  uint16 u16DataOffset;
275 
276  if(u8OpCode == SOCKET_CMD_RECVFROM)
277  u8CallbackMsgID = SOCKET_MSG_RECVFROM;
278 
279  /* Read RECV REPLY data structure.
280  */
281  u16ReadSize = sizeof(tstrRecvReply);
282  if(hif_receive(u32Address, (uint8*)&strRecvReply, u16ReadSize, 0) == M2M_SUCCESS)
283  {
284  uint16 u16SessionID = 0;
285 
286  sock = strRecvReply.sock;
287  u16SessionID = strRecvReply.u16SessionID;
288  M2M_DBG("recv callback session ID = %d\r\n",u16SessionID);
289 
290  /* Reset the Socket RX Pending Flag.
291  */
292  gastrSockets[sock].bIsRecvPending = 0;
293 
294  s16RecvStatus = NM_BSP_B_L_16(strRecvReply.s16RecvStatus);
295  u16DataOffset = NM_BSP_B_L_16(strRecvReply.u16DataOffset);
296  strRecvMsg.strRemoteAddr.sin_port = strRecvReply.strRemoteAddr.u16Port;
297  strRecvMsg.strRemoteAddr.sin_addr.s_addr = strRecvReply.strRemoteAddr.u32IPAddr;
298 
299  if(u16SessionID == gastrSockets[sock].u16SessionID)
300  {
301  if((s16RecvStatus > 0) && (s16RecvStatus < u16BufferSize))
302  {
303  /* Skip incoming bytes until reaching the Start of Application Data.
304  */
305  u32Address += u16DataOffset;
306 
307  /* Read the Application data and deliver it to the application callback in
308  the given application buffer. If the buffer is smaller than the received data,
309  the data is passed to the application in chunks according to its buffer size.
310  */
311  u16ReadSize = (uint16)s16RecvStatus;
312  Socket_ReadSocketData(sock, &strRecvMsg, u8CallbackMsgID, u32Address, u16ReadSize);
313  }
314  else
315  {
316  /* Don't tidy up here. Application must call close().
317  */
318  strRecvMsg.s16BufferSize = s16RecvStatus;
319  strRecvMsg.pu8Buffer = NULL;
320  if(gpfAppSocketCb)
321  gpfAppSocketCb(sock,u8CallbackMsgID, &strRecvMsg);
322  }
323  }
324  else
325  {
326  M2M_DBG("Discard recv callback %d %d \r\n",u16SessionID , gastrSockets[sock].u16SessionID);
327  if(u16ReadSize < u16BufferSize)
328  hif_receive(0, NULL, 0, 1);
329  }
330  }
331  }
332  else if((u8OpCode == SOCKET_CMD_SEND) || (u8OpCode == SOCKET_CMD_SENDTO) || (u8OpCode == SOCKET_CMD_SSL_SEND))
333  {
334  SOCKET sock;
335  sint16 s16Rcvd;
336  tstrSendReply strReply;
337  uint8 u8CallbackMsgID = SOCKET_MSG_SEND;
338 
339  if(u8OpCode == SOCKET_CMD_SENDTO)
340  u8CallbackMsgID = SOCKET_MSG_SENDTO;
341 
342  if(hif_receive(u32Address, (uint8*)&strReply, sizeof(tstrSendReply), 0) == M2M_SUCCESS)
343  {
344  uint16 u16SessionID = 0;
345 
346  sock = strReply.sock;
347  u16SessionID = strReply.u16SessionID;
348  M2M_DBG("send callback session ID = %d\r\n",u16SessionID);
349 
350  s16Rcvd = NM_BSP_B_L_16(strReply.s16SentBytes);
351 
352  if(u16SessionID == gastrSockets[sock].u16SessionID)
353  {
354  if(gpfAppSocketCb)
355  gpfAppSocketCb(sock,u8CallbackMsgID, &s16Rcvd);
356  }
357  else
358  {
359  M2M_DBG("Discard send callback %d %d \r\n",u16SessionID , gastrSockets[sock].u16SessionID);
360  }
361  }
362  }
363  else if(u8OpCode == SOCKET_CMD_PING)
364  {
365  tstrPingReply strPingReply;
366  if(hif_receive(u32Address, (uint8*)&strPingReply, sizeof(tstrPingReply), 1) == M2M_SUCCESS)
367  {
368  gfpPingCb = (void (*)(uint32 , uint32 , uint8))strPingReply.u32CmdPrivate;
369  if(gfpPingCb != NULL)
370  {
371  gfpPingCb(strPingReply.u32IPAddr, strPingReply.u32RTT, strPingReply.u8ErrorCode);
372 }
373  }
374  }
375 }
376 /*********************************************************************
377 Function
378  socketInit
379 
380 Description
381 
382 Return
383  None.
384 
385 Author
386  Ahmed Ezzat
387 
388 Version
389  1.0
390 
391 Date
392  4 June 2012
393 *********************************************************************/
394 void socketInit(void)
395 {
396  if(gbSocketInit==0)
397  {
398  m2m_memset((uint8*)gastrSockets, 0, MAX_SOCKET * sizeof(tstrSocket));
400  gbSocketInit=1;
401  gu16SessionID = 0;
402  }
403 }
404 
405 /*********************************************************************
406 Function
407  socketDeinit
408 
409 Description
410 
411 Return
412  None.
413 
414 Author
415  Samer Sarhan
416 
417 Version
418  1.0
419 
420 Date
421  27 Feb 2015
422 *********************************************************************/
423 void socketDeinit(void)
424 {
425  m2m_memset((uint8*)gastrSockets, 0, MAX_SOCKET * sizeof(tstrSocket));
429  gbSocketInit = 0;
430 }
431 
432 
433 /*********************************************************************
434 Function
435  registerSocketCallback
436 
437 Description
438 
439 Return
440  None.
441 
442 Author
443  Ahmed Ezzat
444 
445 Versio
446  1.0
447 
448 Date
449  4 June 2012
450 *********************************************************************/
451 void registerSocketCallback(tpfAppSocketCb pfAppSocketCb, tpfAppResolveCb pfAppResolveCb)
452 {
453  gpfAppSocketCb = pfAppSocketCb;
454  gpfAppResolveCb = pfAppResolveCb;
455 }
456 
457 /*********************************************************************
458 Function
459  socket
460 
461 Description
462  Creates a socket.
463 
464 Return
465  - Negative value for error.
466  - ZERO or positive value as a socket ID if successful.
467 
468 Author
469  Ahmed Ezzat
470 
471 Version
472  1.0
473 
474 Date
475  4 June 2012
476 *********************************************************************/
477 SOCKET socket(uint16 u16Domain, uint8 u8Type, uint8 u8Flags)
478 {
479  SOCKET sock = -1;
480  uint8 u8SockID;
481  uint8 u8Count;
482  volatile tstrSocket *pstrSock;
483  static volatile uint8 u8NextTcpSock = 0;
484  static volatile uint8 u8NextUdpSock = 0;
485 
486  /* The only supported family is the AF_INET for UDP and TCP transport layer protocols. */
487  if(u16Domain == AF_INET)
488  {
489  if(u8Type == SOCK_STREAM)
490  {
491  for(u8Count = 0; u8Count < TCP_SOCK_MAX; u8Count ++)
492  {
493  u8SockID = u8NextTcpSock;
494  pstrSock = &gastrSockets[u8NextTcpSock];
495  u8NextTcpSock = (u8NextTcpSock + 1) % TCP_SOCK_MAX;
496  if(!pstrSock->bIsUsed)
497  {
498  sock = (SOCKET)u8SockID;
499  break;
500  }
501  }
502  }
503  else if(u8Type == SOCK_DGRAM)
504  {
505  volatile tstrSocket *pastrUDPSockets = &gastrSockets[TCP_SOCK_MAX];
506  for(u8Count = 0; u8Count < UDP_SOCK_MAX; u8Count ++)
507  {
508  u8SockID = u8NextUdpSock;
509  pstrSock = &pastrUDPSockets[u8NextUdpSock];
510  u8NextUdpSock = (u8NextUdpSock + 1) % UDP_SOCK_MAX;
511  if(!pstrSock->bIsUsed)
512  {
513  sock = (SOCKET)(u8SockID + TCP_SOCK_MAX);
514  break;
515  }
516  }
517  }
518 
519  if(sock >= 0)
520  {
521  m2m_memset((uint8*)pstrSock, 0, sizeof(tstrSocket));
522  pstrSock->bIsUsed = 1;
523 
524  /* The session ID is used to distinguish different socket connections
525  by comparing the assigned session ID to the one reported by the firmware*/
526  ++gu16SessionID;
527  if(gu16SessionID == 0)
528  ++gu16SessionID;
529 
530  pstrSock->u16SessionID = gu16SessionID;
531  M2M_INFO("Socket %d session ID = %d\r\n",sock, gu16SessionID );
532 
533  if(u8Flags & SOCKET_FLAGS_SSL)
534  {
535  tstrSSLSocketCreateCmd strSSLCreate;
536  strSSLCreate.sslSock = sock;
537  pstrSock->u8SSLFlags = SSL_FLAGS_ACTIVE;
538  SOCKET_REQUEST(SOCKET_CMD_SSL_CREATE, (uint8*)&strSSLCreate, sizeof(tstrSSLSocketCreateCmd), 0, 0, 0);
539  }
540  }
541  }
542  return sock;
543 }
544 /*********************************************************************
545 Function
546  bind
547 
548 Description
549  Request to bind a socket on a local address.
550 
551 Return
552 
553 
554 Author
555  Ahmed Ezzat
556 
557 Version
558  1.0
559 
560 Date
561  5 June 2012
562 *********************************************************************/
563 sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
564 {
565  sint8 s8Ret = SOCK_ERR_INVALID_ARG;
566  if((pstrAddr != NULL) && (sock >= 0) && (gastrSockets[sock].bIsUsed == 1) && (u8AddrLen != 0))
567  {
568  tstrBindCmd strBind;
569 
570  /* Build the bind request. */
571  strBind.sock = sock;
572  m2m_memcpy((uint8 *)&strBind.strAddr, (uint8 *)pstrAddr, sizeof(tstrSockAddr));
573 
574  strBind.strAddr.u16Family = strBind.strAddr.u16Family;
575  strBind.strAddr.u16Port = strBind.strAddr.u16Port;
576  strBind.strAddr.u32IPAddr = strBind.strAddr.u32IPAddr;
577  strBind.u16SessionID = gastrSockets[sock].u16SessionID;
578 
579  /* Send the request. */
580  s8Ret = SOCKET_REQUEST(SOCKET_CMD_BIND, (uint8*)&strBind,sizeof(tstrBindCmd) , NULL , 0, 0);
581  if(s8Ret != SOCK_ERR_NO_ERROR)
582  {
583  s8Ret = SOCK_ERR_INVALID;
584  }
585  }
586  return s8Ret;
587 }
588 /*********************************************************************
589 Function
590  listen
591 
592 Description
593 
594 
595 Return
596 
597 
598 Author
599  Ahmed Ezzat
600 
601 Version
602  1.0
603 
604 Date
605  5 June 2012
606 *********************************************************************/
607 sint8 listen(SOCKET sock, uint8 backlog)
608 {
609  sint8 s8Ret = SOCK_ERR_INVALID_ARG;
610 
611  if(sock >= 0 && (gastrSockets[sock].bIsUsed == 1))
612  {
613  tstrListenCmd strListen;
614 
615  strListen.sock = sock;
616  strListen.u8BackLog = backlog;
617  strListen.u16SessionID = gastrSockets[sock].u16SessionID;
618 
619  s8Ret = SOCKET_REQUEST(SOCKET_CMD_LISTEN, (uint8*)&strListen, sizeof(tstrListenCmd), NULL, 0, 0);
620  if(s8Ret != SOCK_ERR_NO_ERROR)
621  {
622  s8Ret = SOCK_ERR_INVALID;
623  }
624  }
625  return s8Ret;
626 }
627 /*********************************************************************
628 Function
629  accept
630 
631 Description
632 
633 Return
634 
635 
636 Author
637  Ahmed Ezzat
638 
639 Version
640  1.0
641 
642 Date
643  5 June 2012
644 *********************************************************************/
645 sint8 accept(SOCKET sock, struct sockaddr *addr, uint8 *addrlen)
646 {
647  sint8 s8Ret = SOCK_ERR_INVALID_ARG;
648 
649  if(sock >= 0 && (gastrSockets[sock].bIsUsed == 1) )
650  {
651  s8Ret = SOCK_ERR_NO_ERROR;
652  }
653  return s8Ret;
654 }
655 /*********************************************************************
656 Function
657  connect
658 
659 Description
660  Connect to a remote TCP Server.
661 
662 Return
663 
664 
665 Author
666  Ahmed Ezzat
667 
668 Version
669  1.0
670 
671 Date
672  5 June 2012
673 *********************************************************************/
674 sint8 connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
675 {
676  sint8 s8Ret = SOCK_ERR_INVALID_ARG;
677  if((sock >= 0) && (pstrAddr != NULL) && (gastrSockets[sock].bIsUsed == 1) && (u8AddrLen != 0))
678  {
679  tstrConnectCmd strConnect;
680  uint8 u8Cmd = SOCKET_CMD_CONNECT;
681  if((gastrSockets[sock].u8SSLFlags) & SSL_FLAGS_ACTIVE)
682  {
683  u8Cmd = SOCKET_CMD_SSL_CONNECT;
684  strConnect.u8SslFlags = gastrSockets[sock].u8SSLFlags;
685  }
686  strConnect.sock = sock;
687  m2m_memcpy((uint8 *)&strConnect.strAddr, (uint8 *)pstrAddr, sizeof(tstrSockAddr));
688 
689  strConnect.u16SessionID = gastrSockets[sock].u16SessionID;
690  s8Ret = SOCKET_REQUEST(u8Cmd, (uint8*)&strConnect,sizeof(tstrConnectCmd), NULL, 0, 0);
691  if(s8Ret != SOCK_ERR_NO_ERROR)
692  {
693  s8Ret = SOCK_ERR_INVALID;
694  }
695  }
696  return s8Ret;
697 }
698 /*********************************************************************
699 Function
700  send
701 
702 Description
703 
704 Return
705 
706 Author
707  Ahmed Ezzat
708 
709 Version
710  1.0
711 
712 Date
713  5 June 2012
714 *********************************************************************/
715 sint16 send(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags)
716 {
717  sint16 s16Ret = SOCK_ERR_INVALID_ARG;
718 
719  if((sock >= 0) && (pvSendBuffer != NULL) && (u16SendLength <= SOCKET_BUFFER_MAX_LENGTH) && (gastrSockets[sock].bIsUsed == 1))
720  {
721  uint16 u16DataOffset;
722  tstrSendCmd strSend;
723  uint8 u8Cmd;
724 
725  u8Cmd = SOCKET_CMD_SEND;
726  u16DataOffset = TCP_TX_PACKET_OFFSET;
727 
728  strSend.sock = sock;
729  strSend.u16DataSize = NM_BSP_B_L_16(u16SendLength);
730  strSend.u16SessionID = gastrSockets[sock].u16SessionID;
731 
732  if(sock >= TCP_SOCK_MAX)
733  {
734  u16DataOffset = UDP_TX_PACKET_OFFSET;
735  }
736  if(gastrSockets[sock].u8SSLFlags & SSL_FLAGS_ACTIVE)
737  {
738  u8Cmd = SOCKET_CMD_SSL_SEND;
739  u16DataOffset = gastrSockets[sock].u16DataOffset;
740  }
741 
742  s16Ret = SOCKET_REQUEST(u8Cmd|M2M_REQ_DATA_PKT, (uint8*)&strSend, sizeof(tstrSendCmd), pvSendBuffer, u16SendLength, u16DataOffset);
743  if(s16Ret != SOCK_ERR_NO_ERROR)
744  {
745  s16Ret = SOCK_ERR_BUFFER_FULL;
746  }
747  }
748  return s16Ret;
749 }
750 /*********************************************************************
751 Function
752  sendto
753 
754 Description
755 
756 Return
757 
758 Author
759  Ahmed Ezzat
760 
761 Version
762  1.0
763 
764 Date
765  4 June 2012
766 *********************************************************************/
767 sint16 sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen)
768 {
769  sint16 s16Ret = SOCK_ERR_INVALID_ARG;
770 
771  if((sock >= 0) && (pvSendBuffer != NULL) && (u16SendLength <= SOCKET_BUFFER_MAX_LENGTH) && (gastrSockets[sock].bIsUsed == 1))
772  {
773  if(gastrSockets[sock].bIsUsed)
774  {
775  tstrSendCmd strSendTo;
776 
777  m2m_memset((uint8*)&strSendTo, 0, sizeof(tstrSendCmd));
778 
779  strSendTo.sock = sock;
780  strSendTo.u16DataSize = NM_BSP_B_L_16(u16SendLength);
781  strSendTo.u16SessionID = gastrSockets[sock].u16SessionID;
782 
783  if(pstrDestAddr != NULL)
784  {
785  struct sockaddr_in *pstrAddr;
786  pstrAddr = (void*)pstrDestAddr;
787 
788  strSendTo.strAddr.u16Family = pstrAddr->sin_family;
789  strSendTo.strAddr.u16Port = pstrAddr->sin_port;
790  strSendTo.strAddr.u32IPAddr = pstrAddr->sin_addr.s_addr;
791  }
792  s16Ret = SOCKET_REQUEST(SOCKET_CMD_SENDTO|M2M_REQ_DATA_PKT, (uint8*)&strSendTo, sizeof(tstrSendCmd),
793  pvSendBuffer, u16SendLength, UDP_TX_PACKET_OFFSET);
794 
795  if(s16Ret != SOCK_ERR_NO_ERROR)
796  {
797  s16Ret = SOCK_ERR_BUFFER_FULL;
798  }
799  }
800  }
801  return s16Ret;
802 }
803 /*********************************************************************
804 Function
805  recv
806 
807 Description
808 
809 Return
810 
811 
812 Author
813  Ahmed Ezzat
814 
815 Version
816  1.0
817  2.0 9 April 2013 --> Add timeout for recv operation.
818 
819 Date
820  5 June 2012
821 *********************************************************************/
822 sint16 recv(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec)
823 {
824  sint16 s16Ret = SOCK_ERR_INVALID_ARG;
825 
826  if((sock >= 0) && (pvRecvBuf != NULL) && (u16BufLen != 0) && (gastrSockets[sock].bIsUsed == 1))
827  {
828  s16Ret = SOCK_ERR_NO_ERROR;
829  gastrSockets[sock].pu8UserBuffer = (uint8*)pvRecvBuf;
830  gastrSockets[sock].u16UserBufferSize = u16BufLen;
831 
832  if(!gastrSockets[sock].bIsRecvPending)
833  {
834  tstrRecvCmd strRecv;
835  uint8 u8Cmd = SOCKET_CMD_RECV;
836 
837  gastrSockets[sock].bIsRecvPending = 1;
838  if(gastrSockets[sock].u8SSLFlags & SSL_FLAGS_ACTIVE)
839  {
840  u8Cmd = SOCKET_CMD_SSL_RECV;
841  }
842 
843  /* Check the timeout value. */
844  if(u32Timeoutmsec == 0)
845  strRecv.u32Timeoutmsec = 0xFFFFFFFF;
846  else
847  strRecv.u32Timeoutmsec = NM_BSP_B_L_32(u32Timeoutmsec);
848  strRecv.sock = sock;
849  strRecv.u16SessionID = gastrSockets[sock].u16SessionID;
850  strRecv.u16BufLen = u16BufLen;
851 
852  s16Ret = SOCKET_REQUEST(u8Cmd, (uint8*)&strRecv, sizeof(tstrRecvCmd), NULL , 0, 0);
853  if(s16Ret != SOCK_ERR_NO_ERROR)
854  {
855  s16Ret = SOCK_ERR_BUFFER_FULL;
856  }
857  }
858  }
859  return s16Ret;
860 }
861 /*********************************************************************
862 Function
863  close
864 
865 Description
866 
867 Return
868  None.
869 
870 Author
871  Ahmed Ezzat
872 
873 Version
874  1.0
875 
876 Date
877  4 June 2012
878 *********************************************************************/
880 {
881  sint8 s8Ret = SOCK_ERR_INVALID_ARG;
882 
883  M2M_INFO("Sock to delete <%d>\n", sock);
884 
885  if(sock >= 0 && (gastrSockets[sock].bIsUsed == 1))
886  {
887  uint8 u8Cmd = SOCKET_CMD_CLOSE;
888  tstrCloseCmd strclose;
889  strclose.sock = sock;
890  strclose.u16SessionID = gastrSockets[sock].u16SessionID;
891 
892  if(gastrSockets[sock].u8SSLFlags & SSL_FLAGS_ACTIVE)
893  {
894  u8Cmd = SOCKET_CMD_SSL_CLOSE;
895  }
896  s8Ret = SOCKET_REQUEST(u8Cmd, (uint8*)&strclose, sizeof(tstrCloseCmd), NULL,0, 0);
897  if(s8Ret != SOCK_ERR_NO_ERROR)
898  {
899  s8Ret = SOCK_ERR_INVALID;
900  }
901  m2m_memset((uint8*)&gastrSockets[sock], 0, sizeof(tstrSocket));
902  }
903  return s8Ret;
904 }
905 /*********************************************************************
906 Function
907  recvfrom
908 
909 Description
910 
911 Return
912 
913 
914 Author
915  Ahmed Ezzat
916 
917 Version
918  1.0
919  2.0 9 April 2013 --> Add timeout for recv operation.
920 
921 Date
922  5 June 2012
923 *********************************************************************/
924 sint16 recvfrom(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec)
925 {
926  sint16 s16Ret = SOCK_ERR_NO_ERROR;
927  if((sock >= 0) && (pvRecvBuf != NULL) && (u16BufLen != 0) && (gastrSockets[sock].bIsUsed == 1))
928  {
929  if(gastrSockets[sock].bIsUsed)
930  {
931  s16Ret = SOCK_ERR_NO_ERROR;
932  gastrSockets[sock].pu8UserBuffer = (uint8*)pvRecvBuf;
933  gastrSockets[sock].u16UserBufferSize = u16BufLen;
934 
935  if(!gastrSockets[sock].bIsRecvPending)
936  {
937  tstrRecvCmd strRecv;
938 
939  gastrSockets[sock].bIsRecvPending = 1;
940 
941  /* Check the timeout value. */
942  if(u32Timeoutmsec == 0)
943  strRecv.u32Timeoutmsec = 0xFFFFFFFF;
944  else
945  strRecv.u32Timeoutmsec = NM_BSP_B_L_32(u32Timeoutmsec);
946  strRecv.sock = sock;
947  strRecv.u16SessionID = gastrSockets[sock].u16SessionID;
948  strRecv.u16BufLen = u16BufLen;
949 
950  s16Ret = SOCKET_REQUEST(SOCKET_CMD_RECVFROM, (uint8*)&strRecv, sizeof(tstrRecvCmd), NULL , 0, 0);
951  if(s16Ret != SOCK_ERR_NO_ERROR)
952  {
953  s16Ret = SOCK_ERR_BUFFER_FULL;
954  }
955  }
956  }
957  }
958  else
959  {
960  s16Ret = SOCK_ERR_INVALID_ARG;
961  }
962  return s16Ret;
963 }
964 /*********************************************************************
965 Function
966  nmi_inet_addr
967 
968 Description
969 
970 Return
971  Unsigned 32-bit integer representing the IP address in Network
972  byte order.
973 
974 Author
975  Ahmed Ezzat
976 
977 Version
978  1.0
979 
980 Date
981  4 June 2012
982 *********************************************************************/
983 uint32 nmi_inet_addr(char *pcIpAddr)
984 {
985  uint8 tmp;
986  uint32 u32IP = 0;
987  uint8 au8IP[4];
988  uint8 c;
989  uint8 i, j;
990 
991  tmp = 0;
992 
993  for(i = 0; i < 4; ++i)
994  {
995  j = 0;
996  do
997  {
998  c = *pcIpAddr;
999  ++j;
1000  if(j > 4)
1001  {
1002  return 0;
1003  }
1004  if(c == '.' || c == 0)
1005  {
1006  au8IP[i] = tmp;
1007  tmp = 0;
1008  }
1009  else if(c >= '0' && c <= '9')
1010  {
1011  tmp = (tmp * 10) + (c - '0');
1012  }
1013  else
1014  {
1015  return 0;
1016  }
1017  ++pcIpAddr;
1018  } while(c != '.' && c != 0);
1019  }
1020  m2m_memcpy((uint8*)&u32IP, au8IP, 4);
1021  return u32IP;
1022 }
1023 /*********************************************************************
1024 Function
1025  gethostbyname
1026 
1027 Description
1028 
1029 Return
1030  None.
1031 
1032 Author
1033  Ahmed Ezzat
1034 
1035 Version
1036  1.0
1037 
1038 Date
1039  4 June 2012
1040 *********************************************************************/
1042 {
1043  sint8 s8Err = SOCK_ERR_INVALID_ARG;
1044  uint8 u8HostNameSize = (uint8)m2m_strlen(pcHostName);
1045  if(u8HostNameSize <= HOSTNAME_MAX_SIZE)
1046  {
1047  s8Err = SOCKET_REQUEST(SOCKET_CMD_DNS_RESOLVE|M2M_REQ_DATA_PKT, (uint8*)pcHostName, u8HostNameSize + 1, NULL,0, 0);
1048  if(s8Err != SOCK_ERR_NO_ERROR)
1049  {
1050  s8Err = SOCK_ERR_INVALID;
1051  }
1052  }
1053  return s8Err;
1054 }
1055 /*********************************************************************
1056 Function
1057  setsockopt
1058 
1059 Description
1060 
1061 Return
1062  None.
1063 
1064 Author
1065  Abdelrahman Diab
1066 
1067 Version
1068  1.0
1069 
1070 Date
1071  9 September 2014
1072 *********************************************************************/
1073 static sint8 sslSetSockOpt(SOCKET sock, uint8 u8Opt, const void *pvOptVal, uint16 u16OptLen)
1074 {
1075  sint8 s8Ret = SOCK_ERR_INVALID_ARG;
1076  if(sock < TCP_SOCK_MAX)
1077  {
1078  if(gastrSockets[sock].u8SSLFlags & SSL_FLAGS_ACTIVE)
1079  {
1080  if(u8Opt == SO_SSL_BYPASS_X509_VERIF)
1081  {
1082  int optVal = *((int*)pvOptVal);
1083  if(optVal)
1084  {
1085  gastrSockets[sock].u8SSLFlags |= SSL_FLAGS_BYPASS_X509;
1086  }
1087  else
1088  {
1089  gastrSockets[sock].u8SSLFlags &= ~SSL_FLAGS_BYPASS_X509;
1090  }
1091  s8Ret = SOCK_ERR_NO_ERROR;
1092  }
1093  else if(u8Opt == SO_SSL_ENABLE_SESSION_CACHING)
1094  {
1095  int optVal = *((int*)pvOptVal);
1096  if(optVal)
1097  {
1098  gastrSockets[sock].u8SSLFlags |= SSL_FLAGS_CACHE_SESSION;
1099  }
1100  else
1101  {
1102  gastrSockets[sock].u8SSLFlags &= ~SSL_FLAGS_CACHE_SESSION;
1103  }
1104  s8Ret = SOCK_ERR_NO_ERROR;
1105  }
1106  else if(u8Opt == SO_SSL_ENABLE_CERTNAME_VALIDATION)
1107  {
1108  int optVal = *((int*)pvOptVal);
1109  if(optVal)
1110  {
1111  gastrSockets[sock].u8SSLFlags |= SSL_FLAGS_CHECK_CERTNAME;
1112  }
1113  else
1114  {
1115  gastrSockets[sock].u8SSLFlags &= ~SSL_FLAGS_CHECK_CERTNAME;
1116  }
1117  s8Ret = SOCK_ERR_NO_ERROR;
1118  }
1119  else if(u8Opt == SO_SSL_SNI)
1120  {
1121  if(u16OptLen < HOSTNAME_MAX_SIZE)
1122  {
1123  uint8 *pu8SNI = (uint8*)pvOptVal;
1124  tstrSSLSetSockOptCmd strCmd;
1125 
1126  strCmd.sock = sock;
1127  strCmd.u16SessionID = gastrSockets[sock].u16SessionID;
1128  strCmd.u8Option = u8Opt;
1129  strCmd.u32OptLen = u16OptLen;
1130  m2m_memcpy(strCmd.au8OptVal, pu8SNI, HOSTNAME_MAX_SIZE);
1131 
1133  0, 0, 0) == M2M_ERR_MEM_ALLOC)
1134  {
1136  (uint8*)&strCmd, sizeof(tstrSSLSetSockOptCmd), 0, 0, 0);
1137  }
1138  s8Ret = SOCK_ERR_NO_ERROR;
1139  }
1140  else
1141  {
1142  M2M_ERR("SNI Exceeds Max Length\n");
1143  }
1144  }
1145  else
1146  {
1147  M2M_ERR("Unknown SSL Socket Option %d\n",u8Opt);
1148  }
1149  }
1150  else
1151  {
1152  M2M_ERR("Not SSL Socket\n");
1153  }
1154  }
1155  return s8Ret;
1156 }
1157 /*********************************************************************
1158 Function
1159  setsockopt
1160 
1161 Description
1162 
1163 Return
1164  None.
1165 
1166 Author
1167  Abdelrahman Diab
1168 
1169 Version
1170  1.0
1171 
1172 Date
1173  9 September 2014
1174 *********************************************************************/
1175 sint8 setsockopt(SOCKET sock, uint8 u8Level, uint8 option_name,
1176  const void *option_value, uint16 u16OptionLen)
1177 {
1178  sint8 s8Ret = SOCK_ERR_INVALID_ARG;
1179  if((sock >= 0) && (option_value != NULL) && (gastrSockets[sock].bIsUsed == 1))
1180  {
1181  if(u8Level == SOL_SSL_SOCKET)
1182  {
1183  if((option_name == SO_SSL_SNI) || (u16OptionLen == sizeof(int)))
1184  {
1185  s8Ret = sslSetSockOpt(sock, option_name, option_value, u16OptionLen);
1186  }
1187  }
1188  else
1189  {
1190  if(u16OptionLen == sizeof(uint32))
1191  {
1193  tstrSetSocketOptCmd strSetSockOpt;
1194  strSetSockOpt.u8Option=option_name;
1195  strSetSockOpt.sock = sock;
1196  strSetSockOpt.u32OptionValue = *(uint32*)option_value;
1197  strSetSockOpt.u16SessionID = gastrSockets[sock].u16SessionID;
1198 
1199  s8Ret = SOCKET_REQUEST(u8Cmd, (uint8*)&strSetSockOpt, sizeof(tstrSetSocketOptCmd), NULL,0, 0);
1200  if(s8Ret != SOCK_ERR_NO_ERROR)
1201  {
1202  s8Ret = SOCK_ERR_INVALID;
1203  }
1204  }
1205  }
1206  }
1207  return s8Ret;
1208 }
1209 /*********************************************************************
1210 Function
1211  getsockopt
1212 
1213 Description
1214 
1215 Return
1216  None.
1217 
1218 Author
1219  Ahmed Ezzat
1220 
1221 Version
1222  1.0
1223 
1224 Date
1225  24 August 2014
1226 *********************************************************************/
1227 sint8 getsockopt(SOCKET sock, uint8 u8Level, uint8 u8OptName, const void *pvOptValue, uint8* pu8OptLen)
1228 {
1229  // This is not implemented so return a value that will cause failure should this be used.
1230  return SOCK_ERR_INVALID_ARG;
1231 }
1232 /*********************************************************************
1233 Function
1234  m2m_ping_req
1235 
1236 Description
1237  Send Ping request.
1238 
1239 Return
1240 
1241 Author
1242  Ahmed Ezzat
1243 
1244 Version
1245  1.0
1246 
1247 Date
1248  4 June 2015
1249 *********************************************************************/
1250 sint8 m2m_ping_req(uint32 u32DstIP, uint8 u8TTL, tpfPingCb fpPingCb)
1251 {
1252  sint8 s8Ret = M2M_ERR_INVALID_ARG;
1253 
1254  if((u32DstIP != 0) && (fpPingCb != NULL))
1255  {
1256  tstrPingCmd strPingCmd;
1257 
1258  strPingCmd.u16PingCount = 1;
1259  strPingCmd.u32DestIPAddr = u32DstIP;
1260  strPingCmd.u32CmdPrivate = (uint32)fpPingCb;
1261  strPingCmd.u8TTL = u8TTL;
1262 
1263  s8Ret = SOCKET_REQUEST(SOCKET_CMD_PING, (uint8*)&strPingCmd, sizeof(tstrPingCmd), NULL, 0, 0);
1264  }
1265  return s8Ret;
1266 }
NMI_API void m2m_memcpy(uint8 *pDst, uint8 *pSrc, uint32 sz)
Copy specified number of bytes from source buffer to destination buffer.
Definition: nm_common.c:36
sint8 connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
Definition: socket.c:674
#define SOCKET_CMD_RECVFROM
#define SOCKET_REQUEST(reqID, reqArgs, reqSize, reqPayload, reqPayloadSize, reqPayloadOffset)
Definition: socket.c:61
#define SOCKET_CMD_DNS_RESOLVE
#define SOCKET_CMD_SSL_RECV
BSD compatible socket interface internal types.
volatile uint16 gu16BufferSize
Definition: socket.c:105
sint16 recvfrom(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec)
Definition: socket.c:924
signed short sint16
Range of values between -32768 to 32767.
Definition: nm_bsp.h:118
#define SOCKET_CMD_PING
#define SOL_SSL_SOCKET
Definition: socket.h:141
volatile tpfPingCb gfpPingCb
Definition: socket.c:111
#define SOCK_DGRAM
Definition: socket.h:85
SOCKET socket(uint16 u16Domain, uint8 u8Type, uint8 u8Flags)
Definition: socket.c:477
Connect Reply, contains sock number and error value.
signed char sint8
Range of values between -128 to 127.
Definition: nm_bsp.h:111
#define TCP_SOCK_MAX
Definition: socket.h:97
tstrSockAddr strAddr
uint16 sin_port
Definition: socket.h:462
sint8 listen(SOCKET sock, uint8 backlog)
Definition: socket.c:607
#define SOCK_ERR_NO_ERROR
Definition: socket.h:305
NMI_API void Socket_ReadSocketData(SOCKET sock, tstrSocketRecvMsg *pstrRecv, uint8 u8SocketMsg, uint32 u32StartAddress, uint16 u16ReadCount)
Definition: socket.c:133
static sint8 sslSetSockOpt(SOCKET sock, uint8 u8Opt, const void *pvOptVal, uint16 u16OptLen)
Definition: socket.c:1073
sint16 recv(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec)
Definition: socket.c:822
SOCKET sock
Definition: socket.c:79
Socket recv status.
Definition: socket.h:651
static void m2m_ip_cb(uint8 u8OpCode, uint16 u16BufferSize, uint32 u32Address)
Definition: socket.c:187
#define M2M_HIF_HDR_OFFSET
Definition: m2m_hif.h:56
#define M2M_ERR_MEM_ALLOC
Definition: nm_common.h:54
#define M2M_SUCCESS
Definition: nm_common.h:51
volatile tstrSocket gastrSockets[MAX_SOCKET]
Definition: socket.c:103
#define AF_INET
Definition: socket.h:72
#define SOCKET_CMD_CLOSE
#define NM_BSP_B_L_16(x)
Definition: nm_bsp.h:241
#define SOCK_ERR_BUFFER_FULL
Definition: socket.h:379
sint8 m2m_ping_req(uint32 u32DstIP, uint8 u8TTL, tpfPingCb fpPingCb)
Definition: socket.c:1250
Socket address structure for IPV4 addresses. Used to specify socket address information to connect to...
Definition: socket.h:455
sint8 accept(SOCKET sock, struct sockaddr *addr, uint8 *addrlen)
Definition: socket.c:645
#define SSL_FLAGS_BYPASS_X509
Definition: socket.c:66
#define NULL
Definition: nm_bsp.h:52
uint32 nmi_inet_addr(char *pcIpAddr)
Definition: socket.c:983
unsigned short uint16
Range of values between 0 to 65535.
Definition: nm_bsp.h:96
uint8 * pu8UserBuffer
Definition: socket.c:89
#define SSL_FLAGS_CHECK_CERTNAME
Definition: socket.c:68
#define MAX_SOCKET
Definition: socket.h:107
volatile uint8 gu8OpCode
Definition: socket.c:104
void(* tpfAppSocketCb)(SOCKET sock, uint8 u8Msg, void *pvMsg)
The main socket application callback function. Applications register their main socket application ca...
Definition: socket.h:714
sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
Definition: socket.c:563
sint8 setsockopt(SOCKET sock, uint8 u8Level, uint8 option_name, const void *option_value, uint16 u16OptionLen)
Definition: socket.c:1175
uint16 u16RemainingSize
Definition: socket.h:661
void(* tpfAppResolveCb)(uint8 *pu8DomainName, uint32 u32ServerIP)
DNS resolution callback function. Applications requiring DNS resolution should register their callbac...
Definition: socket.h:732
struct sockaddr_in strAddr
Definition: socket.h:604
#define NM_BSP_B_L_32(x)
Definition: nm_bsp.h:239
sint8 getsockopt(SOCKET sock, uint8 u8Level, uint8 u8OptName, const void *pvOptValue, uint8 *pu8OptLen)
Definition: socket.c:1227
volatile tpfAppResolveCb gpfAppResolveCb
Definition: socket.c:109
#define M2M_DBG(...)
Definition: nm_debug.h:81
sint8 hif_register_cb(uint8 u8Grp, tpfHifCallBack fn)
Definition: m2m_hif.c:839
sint8 gethostbyname(uint8 *pcHostName)
Definition: socket.c:1041
#define SOCKET_CMD_SSL_CLOSE
volatile uint16 gu16SessionID
Definition: socket.c:106
uint8 * pu8Buffer
Definition: socket.h:652
#define SSL_FLAGS_ACTIVE
Definition: socket.c:65
tstrSockAddr strAddr
Generic socket address structure.
Definition: socket.h:436
void socketInit(void)
Definition: socket.c:394
#define SO_SSL_BYPASS_X509_VERIF
Definition: socket.h:148
#define SOCKET_CMD_LISTEN
NMI_API void m2m_memset(uint8 *pBuf, uint8 val, uint32 sz)
Set specified number of data bytes in specified data buffer to specified value.
Definition: nm_common.c:58
Socket listen status.
Definition: socket.h:579
#define UDP_TX_PACKET_OFFSET
Definition: socket.c:58
#define SO_SSL_ENABLE_SESSION_CACHING
Definition: socket.h:170
NMI_API uint16 m2m_strlen(uint8 *pcStr)
Returns the string length of a null terminated string buffer.
Definition: nm_common.c:68
uint16 u16UserBufferSize
Definition: socket.c:90
DNS Reply, contains hostName and HostIP.
#define SOCKET_CMD_ACCEPT
#define SOCKET_CMD_BIND
#define M2M_ERR(...)
Definition: nm_debug.h:80
volatile tpfAppSocketCb gpfAppSocketCb
Definition: socket.c:108
void socketDeinit(void)
Socket Layer De-initialization.
Definition: socket.c:423
uint8 u8Dummy
Definition: socket.c:80
#define SOCKET_BUFFER_MAX_LENGTH
Definition: socket.h:66
Socket connect status.
Definition: socket.h:621
#define HOSTNAME_MAX_SIZE
Definition: socket.h:59
#define SOCKET_CMD_SSL_SET_SOCK_OPT
#define M2M_ERR_INVALID_ARG
Definition: nm_common.h:69
uint16 u16DataOffset
Definition: socket.c:92
volatile uint8 gbSocketInit
Definition: socket.c:110
sint8 close(SOCKET sock)
Definition: socket.c:879
#define SOCKET_CMD_SENDTO
#define SOCKET_CMD_SEND
#define TCP_TX_PACKET_OFFSET
Definition: socket.c:57
Socket accept status.
Definition: socket.h:598
struct sockaddr_in strRemoteAddr
Definition: socket.h:665
#define SOCKET_CMD_SSL_SEND
uint8 bIsUsed
Definition: socket.c:93
#define SOCK_ERR_INVALID
Definition: socket.h:353
#define M2M_INFO(...)
Definition: nm_debug.h:83
volatile sint8 gsockerrno
Definition: socket.c:102
#define SOCKET_CMD_CONNECT
#define SOCKET_CMD_RECV
#define SSL_FLAGS_CACHE_SESSION
Definition: socket.c:67
#define SOCKET_CMD_SSL_CONNECT
unsigned long uint32
Range of values between 0 to 4294967295.
Definition: nm_bsp.h:103
This module contains WINC3400 BSP APIs declarations.
#define UDP_SOCK_MAX
Definition: socket.h:102
uint16 u16SessionID
Definition: socket.c:81
uint16 sin_family
Definition: socket.h:456
unsigned char uint8
Range of values between 0 to 255.
Definition: nm_bsp.h:89
#define SO_SSL_ENABLE_CERTNAME_VALIDATION
Definition: socket.h:180
#define SOCK_ERR_INVALID_ARG
Definition: socket.h:340
sint16 send(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags)
Definition: socket.c:715
BSD compatible socket interface.
uint8 bIsRecvPending
Definition: socket.c:95
uint32 s_addr
Definition: socket.h:418
Send Reply, contains socket number and number of sent bytes.
sint16 sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen)
Definition: socket.c:767
#define SO_SSL_SNI
Definition: socket.h:160
#define SOCKET_CMD_SET_SOCKET_OPTION
This module contains M2M host interface APIs implementation.
uint8 u8SSLFlags
Definition: socket.c:94
Socket bind status.
Definition: socket.h:558
in_addr sin_addr
Definition: socket.h:469
sint8 SOCKET
Definition for socket handler data type. Socket ID,used with all socket operations to uniquely identi...
#define SOCKET_CMD_SSL_CREATE
void registerSocketCallback(tpfAppSocketCb pfAppSocketCb, tpfAppResolveCb pfAppResolveCb)
Definition: socket.c:451
sint16 s16BufferSize
Definition: socket.h:656
void(* tpfPingCb)(uint32 u32IPAddr, uint32 u32RTT, uint8 u8ErrorCode)
PING Callback.
Definition: socket.h:755
uint8 au8OptVal[SSL_MAX_OPT_LEN]
#define SOCKET_FLAGS_SSL
Definition: socket.h:92
uint16 u16SessionID
Definition: socket.c:91
#define SOCK_STREAM
Definition: socket.h:79
sint8 hif_receive(uint32 u32Addr, uint8 *pu8Buf, uint16 u16Sz, uint8 isDone)
Definition: m2m_hif.c:762
#define NMI_API
Definition: nm_bsp.h:45


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:58