Microchip® Advanced Software Framework

socket.c File Reference

BSD compatible socket interface.

Copyright (c) 2017-2021 Microchip Technology Inc. and its subsidiaries.

Data Structures

struct  tstrCloseCmd
 
struct  tstrSocket
 

Macros

#define ETHERNET_HEADER_LENGTH   (14)
 
#define ETHERNET_HEADER_OFFSET   (34)
 
#define IP_PACKET_OFFSET   (ETHERNET_HEADER_LENGTH + ETHERNET_HEADER_OFFSET - M2M_HIF_HDR_OFFSET)
 
#define SOCKET_REQUEST(reqID, reqArgs, reqSize, reqPayload, reqPayloadSize, reqPayloadOffset)   hif_send(M2M_REQ_GROUP_IP, reqID, reqArgs, reqSize, reqPayload, reqPayloadSize, reqPayloadOffset)
 
#define SSL_FLAGS_ACTIVE   NBIT0
 
#define SSL_FLAGS_BYPASS_X509   NBIT1
 
#define SSL_FLAGS_CACHE_SESSION   NBIT4
 
#define SSL_FLAGS_CHECK_CERTNAME   NBIT6
 
#define SSL_FLAGS_DELAY   NBIT7
 
#define SSL_TX_PACKET_OFFSET   (TCP_TX_PACKET_OFFSET + TLS_RECORD_HEADER_LENGTH)
 
#define TCP_IP_HEADER_LENGTH   (40)
 
#define TCP_TX_PACKET_OFFSET   (IP_PACKET_OFFSET + TCP_IP_HEADER_LENGTH)
 
#define TLS_RECORD_HEADER_LENGTH   (5)
 
#define UDP_IP_HEADER_LENGTH   (28)
 
#define UDP_TX_PACKET_OFFSET   (IP_PACKET_OFFSET + UDP_IP_HEADER_LENGTH)
 

Functions

sint8 accept (SOCKET sock, struct sockaddr *addr, uint8 *addrlen)
 
sint8 bind (SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
 
sint8 close (SOCKET sock)
 Synchronous close function, releases all the socket assigned resources. More...
 
sint8 connect (SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
 
sint8 get_alpn_index (SOCKET sock)
 
sint8 get_error_detail (SOCKET sock, tstrSockErr *pstrErr)
 
sint8 gethostbyname (uint8 *pcHostName)
 
sint8 getsockopt (SOCKET sock, uint8 u8Level, uint8 u8OptName, const void *pvOptValue, uint8 *pu8OptLen)
 Get socket options retrieves. This Function isn't implemented yet but this is the form that will be released later. More...
 
uint8 IsSocketReady (void)
 
sint8 listen (SOCKET sock, uint8 backlog)
 
static void m2m_ip_cb (uint8 u8OpCode, uint16 u16BufferSize, uint32 u32Address)
 
sint8 m2m_ping_req (uint32 u32DstIP, uint8 u8TTL, tpfPingCb fpPingCb)
 The function request to send ping request to the given IP Address. More...
 
uint32 nmi_inet_addr (char *pcIpAddr)
 
static sint8 rawSetSockOpt (SOCKET sock, uint8 u8Opt, const void *pvOptVal, uint16 u16OptLen)
 
sint16 recv (SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec)
 
sint16 recvfrom (SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec)
 
void registerSocketCallback (tpfAppSocketCb pfAppSocketCb, tpfAppResolveCb pfAppResolveCb)
 
sint8 secure (SOCKET sock)
 
sint16 send (SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags)
 
sint16 sendto (SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen)
 Asynchronous sending function, used to send data on a UDP socket. Called by the application code when there is data required to be sent on a UDP socket. More...
 
sint8 set_alpn_list (SOCKET sock, const char *pcProtocolList)
 
sint8 setsockopt (SOCKET sock, uint8 u8Level, uint8 option_name, const void *option_value, uint16 u16OptionLen)
 
SOCKET socket (uint16 u16Domain, uint8 u8Type, uint8 u8Config)
 
NMI_API void Socket_ReadSocketData (SOCKET sock, tstrSocketRecvMsg *pstrRecv, uint8 u8SocketMsg, uint32 u32StartAddress, uint16 u16ReadCount)
 
void socketDeinit (void)
 Socket Layer De-initialization. More...
 
void socketInit (void)
 
static sint8 sslSetSockOpt (SOCKET sock, uint8 u8Opt, const void *pvOptVal, uint16 u16OptLen)
 

Variables

volatile tstrSocket gastrSockets [MAX_SOCKET]
 
volatile uint8 gbSocketInit = 0
 
static tpfPingCb gfpPingCb = NULL
 
volatile tpfAppResolveCb gpfAppResolveCb
 
volatile tpfAppSocketCb gpfAppSocketCb
 
volatile sint8 gsockerrno
 
volatile uint16 gu16BufferSize
 
volatile uint16 gu16SessionID = 0
 
static uint32 gu32PingId = 0
 
volatile uint8 gu8OpCode
 

#define ETHERNET_HEADER_LENGTH   (14)
#define ETHERNET_HEADER_OFFSET   (34)

Referenced by sendto().

#define SOCKET_REQUEST (   reqID,
  reqArgs,
  reqSize,
  reqPayload,
  reqPayloadSize,
  reqPayloadOffset 
)    hif_send(M2M_REQ_GROUP_IP, reqID, reqArgs, reqSize, reqPayload, reqPayloadSize, reqPayloadOffset)
#define SSL_FLAGS_ACTIVE   NBIT0
#define SSL_FLAGS_BYPASS_X509   NBIT1

Referenced by sslSetSockOpt().

#define SSL_FLAGS_CACHE_SESSION   NBIT4

Referenced by sslSetSockOpt().

#define SSL_FLAGS_CHECK_CERTNAME   NBIT6

Referenced by sslSetSockOpt().

#define SSL_FLAGS_DELAY   NBIT7

Referenced by recv(), secure(), send(), and socket().

#define SSL_TX_PACKET_OFFSET   (TCP_TX_PACKET_OFFSET + TLS_RECORD_HEADER_LENGTH)
#define TCP_IP_HEADER_LENGTH   (40)
#define TCP_TX_PACKET_OFFSET   (IP_PACKET_OFFSET + TCP_IP_HEADER_LENGTH)

Referenced by send().

#define TLS_RECORD_HEADER_LENGTH   (5)
#define UDP_IP_HEADER_LENGTH   (28)
#define UDP_TX_PACKET_OFFSET   (IP_PACKET_OFFSET + UDP_IP_HEADER_LENGTH)

Referenced by send(), and sendto().

static void m2m_ip_cb ( uint8  u8OpCode,
uint16  u16BufferSize,
uint32  u32Address 
)
static

References tstrDnsReply::acHostName, AF_INET, tstrSocket::bIsRecvPending, tstrSocket::bIsUsed, gfpPingCb, gpfAppResolveCb, gpfAppSocketCb, gu16SessionID, gu32PingId, hif_receive(), M2M_DBG, M2M_HIF_HDR_OFFSET, M2M_SUCCESS, MAX_SOCKET, NM_BSP_B_L_16, NULL, tstrSocketRecvMsg::pu8Buffer, tstrSocketRecvMsg::s16BufferSize, tstrRecvReply::s16RecvStatus, tstrSendReply::s16SentBytes, tstrConnectReply::s8Error, tstrSocketConnectMsg::s8Error, tstrBindReply::s8Status, tstrListenReply::s8Status, in_addr::s_addr, tstrAcceptReply::sConnectedSock, sockaddr_in::sin_addr, sockaddr_in::sin_family, sockaddr_in::sin_port, tstrAcceptReply::sListenSock, tstrBindReply::sock, tstrListenReply::sock, tstrConnectReply::sock, tstrSendReply::sock, tstrRecvReply::sock, tstrSocketAcceptMsg::sock, tstrSocketConnectMsg::sock, SOCK_ERR_NO_ERROR, SOCKET_CMD_ACCEPT, SOCKET_CMD_BIND, SOCKET_CMD_CONNECT, SOCKET_CMD_DNS_RESOLVE, SOCKET_CMD_LISTEN, SOCKET_CMD_PING, SOCKET_CMD_RECV, SOCKET_CMD_RECVFROM, SOCKET_CMD_SEND, SOCKET_CMD_SENDTO, SOCKET_CMD_SSL_CONNECT, SOCKET_CMD_SSL_CONNECT_ALPN, SOCKET_CMD_SSL_RECV, SOCKET_CMD_SSL_SEND, SOCKET_MSG_ACCEPT, SOCKET_MSG_BIND, SOCKET_MSG_CONNECT, SOCKET_MSG_LISTEN, SOCKET_MSG_RECV, SOCKET_MSG_RECVFROM, SOCKET_MSG_SECURE, SOCKET_MSG_SEND, SOCKET_MSG_SENDTO, Socket_ReadSocketData(), tstrSocketBindMsg::status, tstrSocketListenMsg::status, tstrAcceptReply::strAddr, tstrSocketAcceptMsg::strAddr, tstrConnectAlpnReply::strConnReply, tstrRecvReply::strRemoteAddr, tstrSocketRecvMsg::strRemoteAddr, tstrConnectReply::u16AppDataOffset, tstrSocket::u16DataOffset, tstrRecvReply::u16DataOffset, tstrSockAddr::u16Port, tstrSocket::u16SessionID, tstrSendReply::u16SessionID, tstrRecvReply::u16SessionID, tstrPingReply::u32CmdPrivate, tstrDnsReply::u32HostIP, tstrSockAddr::u32IPAddr, tstrPingReply::u32IPAddr, tstrPingReply::u32RTT, tstrSocket::u8AlpnStatus, tstrConnectAlpnReply::u8AppProtocolIdx, tstrSocket::u8ErrCode, tstrConnectReply::u8ErrCode, tstrPingReply::u8ErrorCode, tstrSocket::u8ErrSource, tstrConnectReply::u8ErrSource, and tstrSocket::u8SSLFlags.

Referenced by socketInit().

volatile tstrSocket gastrSockets[MAX_SOCKET]
volatile uint8 gbSocketInit = 0
tpfPingCb gfpPingCb = NULL
static

Referenced by m2m_ip_cb(), and m2m_ping_req().

volatile tpfAppResolveCb gpfAppResolveCb
volatile sint8 gsockerrno
volatile uint16 gu16BufferSize
volatile uint16 gu16SessionID = 0

Referenced by m2m_ip_cb(), socket(), and socketInit().

uint32 gu32PingId = 0
static

Referenced by m2m_ip_cb(), and m2m_ping_req().

volatile uint8 gu8OpCode