Microchip® Advanced Software Framework

socket.h File Reference

BSD compatible socket interface.

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

Data Structures

struct  in_addr
 IPv4 address representation. More...
 
struct  sockaddr
 Generic socket address structure. More...
 
struct  sockaddr_in
 Socket address structure for IPV4 addresses. Used to specify socket address information to connect to. Can be cast to sockaddr structure. More...
 
struct  tstrSockErr
 Detail about socket failures. Used with get_error_detail. More...
 
struct  tstrSocketAcceptMsg
 Socket accept status. More...
 
struct  tstrSocketBindMsg
 Socket bind status. More...
 
struct  tstrSocketConnectMsg
 Socket connect status. More...
 
struct  tstrSocketListenMsg
 Socket listen status. More...
 
struct  tstrSocketRecvMsg
 Socket recv status. More...
 

Macros

#define _htonl(m)   (uint32)(((uint32)(m << 24)) | ((uint32)((m & 0x0000FF00) << 8)) | ((uint32)((m & 0x00FF0000) >> 8)) | ((uint32)(((uint32)m) >> 24)))
 
#define _htons(A)   (uint16)((((uint16) (A)) << 8) | (((uint16) (A)) >> 8))
 
#define _ntohl   _htonl
 
#define _ntohs   _htons
 
#define AF_INET   2
 
#define ALPN_LIST_MAX_APP_LENGTH   30
 
#define HOSTNAME_MAX_SIZE   100
 
#define IP_ADD_MEMBERSHIP   0x01
 
#define IP_DROP_MEMBERSHIP   0x02
 
#define MAX_SOCKET   (TCP_SOCK_MAX + UDP_SOCK_MAX + RAW_SOCK_MAX)
 
#define RAW_SOCK_ID   (TCP_SOCK_MAX + UDP_SOCK_MAX)
 
#define RAW_SOCK_MAX   1
 
#define SO_ICMP_FILTER   0x01
 
#define SO_SET_UDP_SEND_CALLBACK   0x00
 
#define SO_SSL_ALPN   0x05
 
#define SO_SSL_BYPASS_X509_VERIF   0x01
 
#define SO_SSL_ENABLE_CERTNAME_VALIDATION   0x04
 
#define SO_SSL_ENABLE_SESSION_CACHING   0x03
 
#define SO_SSL_ENABLE_SNI_VALIDATION   0x04
 
#define SO_SSL_SNI   0x02
 
#define SO_TCP_KEEPALIVE   0x04
 
#define SO_TCP_KEEPCNT   0x07
 
#define SO_TCP_KEEPIDLE   0x05
 
#define SO_TCP_KEEPINTVL   0x06
 
#define SOCK_DGRAM   2
 
#define SOCK_ERR_ADDR_ALREADY_IN_USE   -2
 
#define SOCK_ERR_ADDR_IS_REQUIRED   -11
 
#define SOCK_ERR_BUFFER_FULL   -14
 
#define SOCK_ERR_CONN_ABORTED   -12
 
#define SOCK_ERR_INVALID   -9
 
#define SOCK_ERR_INVALID_ADDRESS   -1
 
#define SOCK_ERR_INVALID_ARG   -6
 
#define SOCK_ERR_MAX_LISTEN_SOCK   -7
 
#define SOCK_ERR_MAX_TCP_SOCK   -3
 
#define SOCK_ERR_MAX_UDP_SOCK   -4
 
#define SOCK_ERR_NO_ERROR   0
 
#define SOCK_ERR_TIMEOUT   -13
 
#define SOCK_RAW   3
 
#define SOCK_STREAM   1
 
#define SOCKET_BUFFER_MAX_LENGTH   1400
 
#define SOCKET_CONFIG_DEFAULT   0
 
#define SOCKET_CONFIG_IPPROTO_RAW   2
 
#define SOCKET_CONFIG_SSL_DELAY   2
 
#define SOCKET_CONFIG_SSL_OFF   0
 
#define SOCKET_CONFIG_SSL_ON   1
 
#define SOCKET_FLAGS_IPPROTO_RAW   0x02
 
#define SOCKET_FLAGS_SSL   0x01
 
#define SOL_RAW   255
 
#define SOL_SOCKET   1
 
#define SOL_SSL_SOCKET   2
 
#define SSL_CIPHER_DHE_RSA_WITH_AES_128_CBC_SHA   NBIT2
 
#define SSL_CIPHER_DHE_RSA_WITH_AES_128_CBC_SHA256   NBIT3
 
#define SSL_CIPHER_DHE_RSA_WITH_AES_128_GCM_SHA256   NBIT5
 
#define SSL_CIPHER_DHE_RSA_WITH_AES_256_CBC_SHA   NBIT8
 
#define SSL_CIPHER_DHE_RSA_WITH_AES_256_CBC_SHA256   NBIT9
 
#define SSL_CIPHER_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256   NBIT13
 
#define SSL_CIPHER_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256   NBIT15
 
#define SSL_CIPHER_ECDHE_RSA_WITH_AES_128_CBC_SHA   NBIT10
 
#define SSL_CIPHER_ECDHE_RSA_WITH_AES_128_CBC_SHA256   NBIT12
 
#define SSL_CIPHER_ECDHE_RSA_WITH_AES_128_GCM_SHA256   NBIT14
 
#define SSL_CIPHER_ECDHE_RSA_WITH_AES_256_CBC_SHA   NBIT11
 
#define SSL_CIPHER_RSA_WITH_AES_128_CBC_SHA   NBIT0
 
#define SSL_CIPHER_RSA_WITH_AES_128_CBC_SHA256   NBIT1
 
#define SSL_CIPHER_RSA_WITH_AES_128_GCM_SHA256   NBIT4
 
#define SSL_CIPHER_RSA_WITH_AES_256_CBC_SHA   NBIT6
 
#define SSL_CIPHER_RSA_WITH_AES_256_CBC_SHA256   NBIT7
 
#define SSL_DEFAULT_CIPHERS
 
#define SSL_ECC_ONLY_CIPHERS
 
#define TCP_SOCK_MAX   (7)
 
#define UDP_SOCK_MAX   4
 

Typedefs

typedef sint8 SOCKET
 
typedef void(* tpfAppResolveCb )(uint8 *pu8DomainName, uint32 u32ServerIP)
 
DNS resolution callback function.

Applications requiring DNS resolution should register their callback through this function by calling registerSocketCallback. The following callback is triggered in response to an asynchronous call to the gethostbyname function (DNS Resolution callback). More...

 
typedef void(* tpfAppSocketCb )(SOCKET sock, uint8 u8Msg, void *pvMsg)
 The main socket application callback function. Applications register their main socket application callback through this function by calling registerSocketCallback. In response to events received, the following callback function is called to handle the corresponding asynchronous function called. Example: bind, connect,...etc. More...
 
typedef void(* tpfPingCb )(uint32 u32IPAddr, uint32 u32RTT, uint8 u8ErrorCode)
 PING Callback. More...
 

Enumerations

enum  tenuSockErrSource {
  SOCKET_ERR_UNKNOWN = 0,
  SOCKET_ERR_TLS_REMOTE,
  SOCKET_ERR_TLS_LOCAL
}
 Source of socket error (local, remote or unknown). More...
 
enum  tenuSocketCallbackMsgType {
  SOCKET_MSG_BIND = 1,
  SOCKET_MSG_LISTEN,
  SOCKET_MSG_DNS_RESOLVE,
  SOCKET_MSG_ACCEPT,
  SOCKET_MSG_CONNECT,
  SOCKET_MSG_RECV,
  SOCKET_MSG_SEND,
  SOCKET_MSG_SENDTO,
  SOCKET_MSG_RECVFROM,
  SOCKET_MSG_SECURE
}
 Asynchronous APIs make use of callback functions in-order to return back the results once the corresponding socket operation is completed. Hence resuming the normal execution of the application code while the socket operation returns the results. Callback functions expect event messages to be passed in, in-order to identify the operation they're returning the results for. The following enum identifies the type of events that are received in the callback function. More...
 

Functions

NMI_API sint8 accept (SOCKET sock, struct sockaddr *addr, uint8 *addrlen)
 
NMI_API sint8 bind (SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
 
NMI_API sint8 close (SOCKET sock)
 Synchronous close function, releases all the socket assigned resources. More...
 
NMI_API sint8 connect (SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
 
sint8 get_alpn_index (SOCKET sock)
 
sint8 get_error_detail (SOCKET sock, tstrSockErr *pstrErr)
 
NMI_API sint8 gethostbyname (uint8 *pcHostName)
 
NMI_API 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...
 
NMI_API uint8 IsSocketReady (void)
 
NMI_API sint8 listen (SOCKET sock, uint8 backlog)
 
NMI_API sint8 m2m_ping_req (uint32 u32DstIP, uint8 u8TTL, tpfPingCb fpPingCb)
 The function request to send ping request to the given IP Address. More...
 
NMI_API uint32 nmi_inet_addr (char *pcIpAddr)
 
NMI_API sint16 recv (SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec)
 
NMI_API sint16 recvfrom (SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec)
 
NMI_API void registerSocketCallback (tpfAppSocketCb socket_cb, tpfAppResolveCb resolve_cb)
 
sint8 secure (SOCKET sock)
 
NMI_API sint16 send (SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 u16Flags)
 
NMI_API 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)
 
NMI_API sint8 setsockopt (SOCKET socket, uint8 u8Level, uint8 option_name, const void *option_value, uint16 u16OptionLen)
 
NMI_API SOCKET socket (uint16 u16Domain, uint8 u8Type, uint8 u8Config)
 
NMI_API void socketDeinit (void)
 Socket Layer De-initialization. More...
 
NMI_API void socketInit (void)