socket.h
Go to the documentation of this file.
1 
38 #ifndef __SOCKET_H__
39 #define __SOCKET_H__
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
46 INCLUDES
47 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
48 
50 
51 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
52 MACROS
53 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
59 #define HOSTNAME_MAX_SIZE 100
60 
66 #define SOCKET_BUFFER_MAX_LENGTH 1400
67 
72 #define AF_INET 2
73 
79 #define SOCK_STREAM 1
80 
85 #define SOCK_DGRAM 2
86 
92 #define SOCKET_FLAGS_SSL 0x01
93 
97 #define TCP_SOCK_MAX (7)
98 
102 #define UDP_SOCK_MAX 4
103 
107 #define MAX_SOCKET (TCP_SOCK_MAX + UDP_SOCK_MAX)
108 
112 #define SOL_SOCKET 1
113 
118 #define SO_SET_UDP_SEND_CALLBACK 0x00
119 
125 #define IP_ADD_MEMBERSHIP 0x01
126 
132 #define IP_DROP_MEMBERSHIP 0x02
133 
139 // SSL Socket options
140 
141 #define SOL_SSL_SOCKET 2
142 
148 #define SO_SSL_BYPASS_X509_VERIF 0x01
149 
160 #define SO_SSL_SNI 0x02
161 
170 #define SO_SSL_ENABLE_SESSION_CACHING 0x03
171 
180 #define SO_SSL_ENABLE_CERTNAME_VALIDATION 0x04
181 
190 #define SO_SSL_ENABLE_SNI_VALIDATION 0x04
191 
197 
206 #define SSL_CIPHER_RSA_WITH_AES_128_CBC_SHA NBIT0
207 #define SSL_CIPHER_RSA_WITH_AES_128_CBC_SHA256 NBIT1
208 #define SSL_CIPHER_DHE_RSA_WITH_AES_128_CBC_SHA NBIT2
209 #define SSL_CIPHER_DHE_RSA_WITH_AES_128_CBC_SHA256 NBIT3
210 #define SSL_CIPHER_RSA_WITH_AES_128_GCM_SHA256 NBIT4
211 #define SSL_CIPHER_DHE_RSA_WITH_AES_128_GCM_SHA256 NBIT5
212 #define SSL_CIPHER_RSA_WITH_AES_256_CBC_SHA NBIT6
213 #define SSL_CIPHER_RSA_WITH_AES_256_CBC_SHA256 NBIT7
214 #define SSL_CIPHER_DHE_RSA_WITH_AES_256_CBC_SHA NBIT8
215 #define SSL_CIPHER_DHE_RSA_WITH_AES_256_CBC_SHA256 NBIT9
216 #define SSL_CIPHER_ECDHE_RSA_WITH_AES_128_CBC_SHA NBIT10
217 #define SSL_CIPHER_ECDHE_RSA_WITH_AES_256_CBC_SHA NBIT11
218 #define SSL_CIPHER_ECDHE_RSA_WITH_AES_128_CBC_SHA256 NBIT12
219 #define SSL_CIPHER_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 NBIT13
220 #define SSL_CIPHER_ECDHE_RSA_WITH_AES_128_GCM_SHA256 NBIT14
221 #define SSL_CIPHER_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 NBIT15
222 
223 
224 #define SSL_ECC_ONLY_CIPHERS \
225 (\
226  SSL_CIPHER_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 | \
227  SSL_CIPHER_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 \
228 )
229 
235 #define SSL_DEFAULT_CIPHERS \
236 (\
237  SSL_CIPHER_RSA_WITH_AES_128_CBC_SHA | \
238  SSL_CIPHER_RSA_WITH_AES_128_CBC_SHA256 | \
239  SSL_CIPHER_DHE_RSA_WITH_AES_128_CBC_SHA | \
240  SSL_CIPHER_DHE_RSA_WITH_AES_128_CBC_SHA256 | \
241  SSL_CIPHER_RSA_WITH_AES_128_GCM_SHA256 | \
242  SSL_CIPHER_DHE_RSA_WITH_AES_128_GCM_SHA256 | \
243  SSL_CIPHER_RSA_WITH_AES_256_CBC_SHA | \
244  SSL_CIPHER_RSA_WITH_AES_256_CBC_SHA256 | \
245  SSL_CIPHER_DHE_RSA_WITH_AES_256_CBC_SHA | \
246  SSL_CIPHER_DHE_RSA_WITH_AES_256_CBC_SHA256 \
247 )
248 
253 
258 #ifdef _NM_BSP_BIG_END
259 #define _htonl(m) (m)
260 
263 #define _htons(A) (A)
264 
267 #else
268 #define _htonl(m) \
269  (uint32)(((uint32)(m << 24)) | ((uint32)((m & 0x0000FF00) << 8)) | ((uint32)((m & 0x00FF0000) >> 8)) | ((uint32)(((uint32)m) >> 24)))
270 
274 #define _htons(A) (uint16)((((uint16) (A)) << 8) | (((uint16) (A)) >> 8))
275 
278 #endif
279 
280 
281 #define _ntohl _htonl
282 
287 #define _ntohs _htons
288 
292 
293 /**************
294 Socket Errors
295 **************/
302 #define SOCK_ERR_NO_ERROR 0
303 
309 #define SOCK_ERR_INVALID_ADDRESS -1
310 
316 #define SOCK_ERR_ADDR_ALREADY_IN_USE -2
317 
323 #define SOCK_ERR_MAX_TCP_SOCK -3
324 
330 #define SOCK_ERR_MAX_UDP_SOCK -4
331 
337 #define SOCK_ERR_INVALID_ARG -6
338 
343 #define SOCK_ERR_MAX_LISTEN_SOCK -7
344 
350 #define SOCK_ERR_INVALID -9
351 
357 #define SOCK_ERR_ADDR_IS_REQUIRED -11
358 
364 #define SOCK_ERR_CONN_ABORTED -12
365 
370 #define SOCK_ERR_TIMEOUT -13
371 
376 #define SOCK_ERR_BUFFER_FULL -14
377 
382 
383 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
384 DATA TYPES
385 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
386 
400 typedef sint8 SOCKET;
402 
414 typedef struct{
415  uint32 s_addr;
420 }in_addr;
421 
422 
433 struct sockaddr{
438  uint8 sa_data[14];
442 };
443 
452 struct sockaddr_in{
453  uint16 sin_family;
459  uint16 sin_port;
466  in_addr sin_addr;
472  uint8 sin_zero[8];
476 };
477 
502 typedef enum{
503  SOCKET_MSG_BIND = 1,
540 // @}
541 
542 
555 typedef struct{
556  sint8 status;
563 
564 
576 typedef struct{
577  sint8 status;
583 
584 
585 
595 typedef struct{
596  SOCKET sock;
601  struct sockaddr_in strAddr;
606 
607 
618 typedef struct{
619  SOCKET sock;
623  sint8 s8Error;
630 
631 
648 typedef struct{
649  uint8 *pu8Buffer;
653  sint16 s16BufferSize;
658  uint16 u16RemainingSize;
662  struct sockaddr_in strRemoteAddr;
667 
711 typedef void (*tpfAppSocketCb) (SOCKET sock, uint8 u8Msg, void * pvMsg);
712 
713 
729 typedef void (*tpfAppResolveCb) (uint8* pu8DomainName, uint32 u32ServerIP);
730 
752 typedef void (*tpfPingCb)(uint32 u32IPAddr, uint32 u32RTT, uint8 u8ErrorCode);
753 
755 /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
756 FUNCTION PROTOTYPES
757 *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
807 NMI_API void socketInit(void);
808 
818 NMI_API void socketDeinit(void);
944 NMI_API SOCKET socket(uint16 u16Domain, uint8 u8Type, uint8 u8Flags);
1018 NMI_API sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen);
1134 NMI_API sint8 listen(SOCKET sock, uint8 backlog);
1158 NMI_API sint8 accept(SOCKET sock, struct sockaddr *addr, uint8 *addrlen);
1255 NMI_API sint8 connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen);
1357 NMI_API sint16 recv(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec);
1464 NMI_API sint16 recvfrom(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec);
1521 NMI_API sint16 send(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 u16Flags);
1576 NMI_API sint16 sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen);
1601 NMI_API sint8 close(SOCKET sock);
1620 NMI_API uint32 nmi_inet_addr(char *pcIpAddr);
1642 NMI_API sint8 gethostbyname(uint8 * pcHostName);
1643 
1689 NMI_API sint8 setsockopt(SOCKET socket, uint8 u8Level, uint8 option_name,
1690  const void *option_value, uint16 u16OptionLen);
1712 NMI_API sint8 getsockopt(SOCKET sock, uint8 u8Level, uint8 u8OptName, const void *pvOptValue, uint8* pu8OptLen);
1732 NMI_API sint8 m2m_ping_req(uint32 u32DstIP, uint8 u8TTL, tpfPingCb fpPingCb);
1736 #ifdef __cplusplus
1737 }
1738 #endif /* __cplusplus */
1739 
1740 #endif /* __SOCKET_H__ */
NMI_API sint8 connect(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
Definition: socket.c:674
NMI_API 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
static void socket_cb(SOCKET sock, uint8_t u8Msg, void *pvMsg)
Callback to get the Data from socket.
Definition: wifi.c:144
NMI_API SOCKET socket(uint16 u16Domain, uint8 u8Type, uint8 u8Flags)
Definition: socket.c:477
signed char sint8
Range of values between -128 to 127.
Definition: nm_bsp.h:111
NMI_API sint8 listen(SOCKET sock, uint8 backlog)
Definition: socket.c:607
sint8 SOCKET
Definition: socket.h:403
NMI_API sint16 recv(SOCKET sock, void *pvRecvBuf, uint16 u16BufLen, uint32 u32Timeoutmsec)
Definition: socket.c:822
Socket recv status.
Definition: socket.h:651
NMI_API 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
NMI_API sint8 accept(SOCKET sock, struct sockaddr *addr, uint8 *addrlen)
Definition: socket.c:645
WINC3400 IoT Application Interface Internal Types.
NMI_API uint32 nmi_inet_addr(char *pcIpAddr)
Definition: socket.c:983
uint8 sa_data[14]
Definition: socket.h:441
unsigned short uint16
Range of values between 0 to 65535.
Definition: nm_bsp.h:96
tenuSocketCallbackMsgType
Asynchronous APIs make use of callback functions in-order to return back the results once the corresp...
Definition: socket.h:505
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
NMI_API sint8 bind(SOCKET sock, struct sockaddr *pstrAddr, uint8 u8AddrLen)
Definition: socket.c:563
NMI_API sint8 setsockopt(SOCKET socket, uint8 u8Level, uint8 option_name, const void *option_value, uint16 u16OptionLen)
Definition: socket.c:1175
void(* tpfAppResolveCb)(uint8 *pu8DomainName, uint32 u32ServerIP)
DNS resolution callback function. Applications requiring DNS resolution should register their callbac...
Definition: socket.h:732
NMI_API sint8 getsockopt(SOCKET sock, uint8 u8Level, uint8 u8OptName, const void *pvOptValue, uint8 *pu8OptLen)
Definition: socket.c:1227
NMI_API sint8 gethostbyname(uint8 *pcHostName)
Definition: socket.c:1041
Generic socket address structure.
Definition: socket.h:436
NMI_API void socketInit(void)
Definition: socket.c:394
uint16 sa_family
Definition: socket.h:437
Socket listen status.
Definition: socket.h:579
IPv4 address representation.
Definition: socket.h:417
NMI_API void socketDeinit(void)
Socket Layer De-initialization.
Definition: socket.c:423
Socket connect status.
Definition: socket.h:621
NMI_API sint8 close(SOCKET sock)
Definition: socket.c:879
Socket accept status.
Definition: socket.h:598
unsigned long uint32
Range of values between 0 to 4294967295.
Definition: nm_bsp.h:103
unsigned char uint8
Range of values between 0 to 255.
Definition: nm_bsp.h:89
NMI_API sint16 send(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 u16Flags)
Definition: socket.c:715
NMI_API sint16 sendto(SOCKET sock, void *pvSendBuffer, uint16 u16SendLength, uint16 flags, struct sockaddr *pstrDestAddr, uint8 u8AddrLen)
Definition: socket.c:767
Socket bind status.
Definition: socket.h:558
NMI_API void registerSocketCallback(tpfAppSocketCb socket_cb, tpfAppResolveCb resolve_cb)
Definition: socket.c:451
void(* tpfPingCb)(uint32 u32IPAddr, uint32 u32RTT, uint8 u8ErrorCode)
PING Callback.
Definition: socket.h:755
#define NMI_API
Definition: nm_bsp.h:45


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