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) 55 #define IP_PACKET_OFFSET (ETHERNET_HEADER_LENGTH + ETHERNET_HEADER_OFFSET - M2M_HIF_HDR_OFFSET) 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) 61 #define SOCKET_REQUEST(reqID, reqArgs, reqSize, reqPayload, reqPayloadSize, reqPayloadOffset) \ 62 hif_send(M2M_REQ_GROUP_IP, reqID, reqArgs, reqSize, reqPayload, reqPayloadSize, reqPayloadOffset) 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 136 uint32 u32Address = u32StartAddress;
141 if((u16ReadCount > 0) && (gastrSockets[sock].pu8UserBuffer !=
NULL) && (gastrSockets[sock].u16UserBufferSize > 0) && (gastrSockets[sock].bIsUsed == 1))
143 u16Read = u16ReadCount;
155 if(gastrSockets[sock].u16UserBufferSize == 0)
163 M2M_INFO(
"(ERRR)Current <%d>\n", u16ReadCount);
196 strBind.
status = strBindReply.s8Status;
207 strListen.
status = strListenReply.s8Status;
218 if(strAcceptReply.sConnectedSock >= 0)
220 gastrSockets[strAcceptReply.sConnectedSock].
u8SSLFlags = 0;
221 gastrSockets[strAcceptReply.sConnectedSock].
bIsUsed = 1;
232 strAccept.
sock = strAcceptReply.sConnectedSock;
246 strConnMsg.
sock = strConnectReply.sock;
247 strConnMsg.
s8Error = strConnectReply.s8Error;
261 strDnsReply.
u32HostIP = strDnsReply.u32HostIP;
286 sock = strRecvReply.sock;
287 u16SessionID = strRecvReply.u16SessionID;
288 M2M_DBG(
"recv callback session ID = %d\r\n",u16SessionID);
299 if(u16SessionID == gastrSockets[sock].u16SessionID)
301 if((s16RecvStatus > 0) && (s16RecvStatus < u16BufferSize))
305 u32Address += u16DataOffset;
311 u16ReadSize = (
uint16)s16RecvStatus;
326 M2M_DBG(
"Discard recv callback %d %d \r\n",u16SessionID , gastrSockets[sock].u16SessionID);
327 if(u16ReadSize < u16BufferSize)
346 sock = strReply.sock;
347 u16SessionID = strReply.u16SessionID;
348 M2M_DBG(
"send callback session ID = %d\r\n",u16SessionID);
352 if(u16SessionID == gastrSockets[sock].u16SessionID)
359 M2M_DBG(
"Discard send callback %d %d \r\n",u16SessionID , gastrSockets[sock].u16SessionID);
371 gfpPingCb(strPingReply.u32IPAddr, strPingReply.u32RTT, strPingReply.u8ErrorCode);
483 static volatile uint8 u8NextTcpSock = 0;
484 static volatile uint8 u8NextUdpSock = 0;
493 u8SockID = u8NextTcpSock;
494 pstrSock = &gastrSockets[u8NextTcpSock];
495 u8NextTcpSock = (u8NextTcpSock + 1) % TCP_SOCK_MAX;
508 u8SockID = u8NextUdpSock;
509 pstrSock = &pastrUDPSockets[u8NextUdpSock];
510 u8NextUdpSock = (u8NextUdpSock + 1) % UDP_SOCK_MAX;
522 pstrSock->bIsUsed = 1;
566 if((pstrAddr !=
NULL) && (sock >= 0) && (gastrSockets[sock].bIsUsed == 1) && (u8AddrLen != 0))
611 if(sock >= 0 && (gastrSockets[sock].bIsUsed == 1))
615 strListen.
sock = sock;
649 if(sock >= 0 && (gastrSockets[sock].bIsUsed == 1) )
677 if((sock >= 0) && (pstrAddr !=
NULL) && (gastrSockets[sock].bIsUsed == 1) && (u8AddrLen != 0))
686 strConnect.
sock = sock;
773 if(gastrSockets[sock].bIsUsed)
779 strSendTo.sock = sock;
781 strSendTo.u16SessionID = gastrSockets[sock].
u16SessionID;
783 if(pstrDestAddr !=
NULL)
786 pstrAddr = (
void*)pstrDestAddr;
788 strSendTo.strAddr.u16Family = pstrAddr->
sin_family;
789 strSendTo.strAddr.u16Port = pstrAddr->
sin_port;
826 if((sock >= 0) && (pvRecvBuf !=
NULL) && (u16BufLen != 0) && (gastrSockets[sock].bIsUsed == 1))
832 if(!gastrSockets[sock].bIsRecvPending)
844 if(u32Timeoutmsec == 0)
883 M2M_INFO(
"Sock to delete <%d>\n", sock);
885 if(sock >= 0 && (gastrSockets[sock].bIsUsed == 1))
889 strclose.
sock = sock;
927 if((sock >= 0) && (pvRecvBuf !=
NULL) && (u16BufLen != 0) && (gastrSockets[sock].bIsUsed == 1))
929 if(gastrSockets[sock].bIsUsed)
935 if(!gastrSockets[sock].bIsRecvPending)
942 if(u32Timeoutmsec == 0)
993 for(i = 0; i < 4; ++i)
1004 if(c ==
'.' || c == 0)
1009 else if(c >=
'0' && c <=
'9')
1011 tmp = (tmp * 10) + (c -
'0');
1018 }
while(c !=
'.' && c != 0);
1082 int optVal = *((
int*)pvOptVal);
1095 int optVal = *((
int*)pvOptVal);
1108 int optVal = *((
int*)pvOptVal);
1142 M2M_ERR(
"SNI Exceeds Max Length\n");
1147 M2M_ERR(
"Unknown SSL Socket Option %d\n",u8Opt);
1176 const void *option_value,
uint16 u16OptionLen)
1179 if((sock >= 0) && (option_value !=
NULL) && (gastrSockets[sock].bIsUsed == 1))
1183 if((option_name ==
SO_SSL_SNI) || (u16OptionLen ==
sizeof(
int)))
1185 s8Ret =
sslSetSockOpt(sock, option_name, option_value, u16OptionLen);
1190 if(u16OptionLen ==
sizeof(
uint32))
1194 strSetSockOpt.
u8Option=option_name;
1195 strSetSockOpt.
sock = sock;
1254 if((u32DstIP != 0) && (fpPingCb !=
NULL))
1261 strPingCmd.
u8TTL = u8TTL;
NMI_API void m2m_memcpy(uint8 *pDst, uint8 *pSrc, uint32 sz)
Copy specified number of bytes from source buffer to destination buffer.
sint8 connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
#define SOCKET_CMD_RECVFROM
#define SOCKET_REQUEST(reqID, reqArgs, reqSize, reqPayload, reqPayloadSize, reqPayloadOffset)
#define SOCKET_CMD_DNS_RESOLVE
#define SOCKET_CMD_SSL_RECV
BSD compatible socket interface internal types.
volatile uint16 gu16BufferSize
sint16 recvfrom(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec)
signed short sint16
Range of values between -32768 to 32767.
volatile tpfPingCb gfpPingCb
SOCKET socket(uint16 u16Domain, uint8 u8Type, uint8 u8Flags)
Connect Reply, contains sock number and error value.
signed char sint8
Range of values between -128 to 127.
sint8 listen(SOCKET sock, uint8 backlog)
#define SOCK_ERR_NO_ERROR
NMI_API void Socket_ReadSocketData(SOCKET sock, tstrSocketRecvMsg *pstrRecv, uint8 u8SocketMsg, uint32 u32StartAddress, uint16 u16ReadCount)
static sint8 sslSetSockOpt(SOCKET sock, uint8 u8Opt, const void *pvOptVal, uint16 u16OptLen)
sint16 recv(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec)
static void m2m_ip_cb(uint8 u8OpCode, uint16 u16BufferSize, uint32 u32Address)
#define M2M_HIF_HDR_OFFSET
#define M2M_ERR_MEM_ALLOC
volatile tstrSocket gastrSockets[MAX_SOCKET]
#define SOCK_ERR_BUFFER_FULL
sint8 m2m_ping_req(uint32 u32DstIP, uint8 u8TTL, tpfPingCb fpPingCb)
Socket address structure for IPV4 addresses. Used to specify socket address information to connect to...
sint8 accept(SOCKET sock, struct sockaddr *addr, uint8 *addrlen)
#define SSL_FLAGS_BYPASS_X509
uint32 nmi_inet_addr(char *pcIpAddr)
unsigned short uint16
Range of values between 0 to 65535.
#define SSL_FLAGS_CHECK_CERTNAME
void(* tpfAppSocketCb)(SOCKET sock, uint8 u8Msg, void *pvMsg)
The main socket application callback function. Applications register their main socket application ca...
sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
sint8 setsockopt(SOCKET sock, uint8 u8Level, uint8 option_name, const void *option_value, uint16 u16OptionLen)
void(* tpfAppResolveCb)(uint8 *pu8DomainName, uint32 u32ServerIP)
DNS resolution callback function. Applications requiring DNS resolution should register their callbac...
struct sockaddr_in strAddr
sint8 getsockopt(SOCKET sock, uint8 u8Level, uint8 u8OptName, const void *pvOptValue, uint8 *pu8OptLen)
volatile tpfAppResolveCb gpfAppResolveCb
sint8 hif_register_cb(uint8 u8Grp, tpfHifCallBack fn)
sint8 gethostbyname(uint8 *pcHostName)
#define SOCKET_CMD_SSL_CLOSE
volatile uint16 gu16SessionID
Generic socket address structure.
#define SO_SSL_BYPASS_X509_VERIF
#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.
#define UDP_TX_PACKET_OFFSET
#define SO_SSL_ENABLE_SESSION_CACHING
NMI_API uint16 m2m_strlen(uint8 *pcStr)
Returns the string length of a null terminated string buffer.
DNS Reply, contains hostName and HostIP.
#define SOCKET_CMD_ACCEPT
volatile tpfAppSocketCb gpfAppSocketCb
void socketDeinit(void)
Socket Layer De-initialization.
#define SOCKET_BUFFER_MAX_LENGTH
#define HOSTNAME_MAX_SIZE
#define SOCKET_CMD_SSL_SET_SOCK_OPT
#define M2M_ERR_INVALID_ARG
volatile uint8 gbSocketInit
#define SOCKET_CMD_SENDTO
#define TCP_TX_PACKET_OFFSET
struct sockaddr_in strRemoteAddr
#define SOCKET_CMD_SSL_SEND
volatile sint8 gsockerrno
#define SOCKET_CMD_CONNECT
#define SSL_FLAGS_CACHE_SESSION
#define SOCKET_CMD_SSL_CONNECT
unsigned long uint32
Range of values between 0 to 4294967295.
This module contains WINC3400 BSP APIs declarations.
unsigned char uint8
Range of values between 0 to 255.
#define SO_SSL_ENABLE_CERTNAME_VALIDATION
#define SOCK_ERR_INVALID_ARG
sint16 send(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags)
BSD compatible socket interface.
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)
#define SOCKET_CMD_SET_SOCKET_OPTION
This module contains M2M host interface APIs implementation.
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)
void(* tpfPingCb)(uint32 u32IPAddr, uint32 u32RTT, uint8 u8ErrorCode)
PING Callback.
sint8 hif_receive(uint32 u32Addr, uint8 *pu8Buf, uint16 u16Sz, uint8 isDone)