37 #ifndef __SL_SOCKET_H__
38 #define __SL_SOCKET_H__
43 #include "simplelink.h"
61 #define SL_FD_SETSIZE SL_MAX_SOCKETS
62 #define BSD_SOCKET_ID_MASK (0x0F)
64 #define SL_SOCK_STREAM (1)
65 #define SL_SOCK_DGRAM (2)
66 #define SL_SOCK_RAW (3)
67 #define SL_IPPROTO_TCP (6)
68 #define SL_IPPROTO_UDP (17)
69 #define SL_IPPROTO_RAW (255)
70 #define SL_SEC_SOCKET (100)
73 #define SL_AF_INET (2)
74 #define SL_AF_INET6 (3)
75 #define SL_AF_INET6_EUI_48 (9)
77 #define SL_AF_PACKET (17)
79 #define SL_PF_INET AF_INET
80 #define SL_PF_INET6 AF_INET6
81 #define SL_INADDR_ANY (0)
84 #define SL_SOC_ERROR (-1)
85 #define SL_SOC_OK ( 0)
88 #define SL_ENSOCK (-10)
89 #define SL_EAGAIN (-11)
90 #define SL_EWOULDBLOCK SL_EAGAIN
91 #define SL_ENOMEM (-12)
92 #define SL_EACCES (-13)
93 #define SL_EFAULT (-14)
94 #define SL_ECLOSE (-15)
95 #define SL_EALREADY_ENABLED (-21)
96 #define SL_EINVAL (-22)
97 #define SL_EAUTO_CONNECT_OR_CONNECTING (-69)
98 #define SL_CONNECTION_PENDING (-72)
99 #define SL_EUNSUPPORTED_ROLE (-86)
100 #define SL_EDESTADDRREQ (-89)
101 #define SL_EPROTOTYPE (-91)
102 #define SL_ENOPROTOOPT (-92)
103 #define SL_EPROTONOSUPPORT (-93)
104 #define SL_ESOCKTNOSUPPORT (-94)
105 #define SL_EOPNOTSUPP (-95)
106 #define SL_EAFNOSUPPORT (-97)
107 #define SL_EADDRINUSE (-98)
108 #define SL_EADDRNOTAVAIL (-99)
109 #define SL_ENETUNREACH (-101)
110 #define SL_ENOBUFS (-105)
111 #define SL_EOBUFF SL_ENOBUFS
112 #define SL_EISCONN (-106)
113 #define SL_ENOTCONN (-107)
114 #define SL_ETIMEDOUT (-110)
115 #define SL_ECONNREFUSED (-111)
116 #define SL_EALREADY (-114)
118 #define SL_ESEC_RSA_WRONG_TYPE_E (-130)
119 #define SL_ESEC_RSA_BUFFER_E (-131)
120 #define SL_ESEC_BUFFER_E (-132)
121 #define SL_ESEC_ALGO_ID_E (-133)
122 #define SL_ESEC_PUBLIC_KEY_E (-134)
123 #define SL_ESEC_DATE_E (-135)
124 #define SL_ESEC_SUBJECT_E (-136)
125 #define SL_ESEC_ISSUER_E (-137)
126 #define SL_ESEC_CA_TRUE_E (-138)
127 #define SL_ESEC_EXTENSIONS_E (-139)
128 #define SL_ESEC_ASN_PARSE_E (-140)
129 #define SL_ESEC_ASN_VERSION_E (-141)
130 #define SL_ESEC_ASN_GETINT_E (-142)
131 #define SL_ESEC_ASN_RSA_KEY_E (-143)
132 #define SL_ESEC_ASN_OBJECT_ID_E (-144)
133 #define SL_ESEC_ASN_TAG_NULL_E (-145)
134 #define SL_ESEC_ASN_EXPECT_0_E (-146)
135 #define SL_ESEC_ASN_BITSTR_E (-147)
136 #define SL_ESEC_ASN_UNKNOWN_OID_E (-148)
137 #define SL_ESEC_ASN_DATE_SZ_E (-149)
138 #define SL_ESEC_ASN_BEFORE_DATE_E (-150)
139 #define SL_ESEC_ASN_AFTER_DATE_E (-151)
140 #define SL_ESEC_ASN_SIG_OID_E (-152)
141 #define SL_ESEC_ASN_TIME_E (-153)
142 #define SL_ESEC_ASN_INPUT_E (-154)
143 #define SL_ESEC_ASN_SIG_CONFIRM_E (-155)
144 #define SL_ESEC_ASN_SIG_HASH_E (-156)
145 #define SL_ESEC_ASN_SIG_KEY_E (-157)
146 #define SL_ESEC_ASN_DH_KEY_E (-158)
147 #define SL_ESEC_ASN_NTRU_KEY_E (-159)
148 #define SL_ESEC_ECC_BAD_ARG_E (-170)
149 #define SL_ESEC_ASN_ECC_KEY_E (-171)
150 #define SL_ESEC_ECC_CURVE_OID_E (-172)
151 #define SL_ESEC_BAD_FUNC_ARG (-173)
152 #define SL_ESEC_NOT_COMPILED_IN (-174)
153 #define SL_ESEC_UNICODE_SIZE_E (-175)
154 #define SL_ESEC_NO_PASSWORD (-176)
155 #define SL_ESEC_ALT_NAME_E (-177)
156 #define SL_ESEC_AES_GCM_AUTH_E (-180)
157 #define SL_ESEC_AES_CCM_AUTH_E (-181)
159 #define SL_ESEC_CLOSE_NOTIFY (-300)
160 #define SL_ESEC_UNEXPECTED_MESSAGE (-310)
161 #define SL_ESEC_BAD_RECORD_MAC (-320)
162 #define SL_ESEC_DECRYPTION_FAILED (-321)
163 #define SL_ESEC_RECORD_OVERFLOW (-322)
164 #define SL_ESEC_DECOMPRESSION_FAILURE (-330)
165 #define SL_ESEC_HANDSHAKE_FAILURE (-340)
166 #define SL_ESEC_NO_CERTIFICATE (-341)
167 #define SL_ESEC_BAD_CERTIFICATE (-342)
168 #define SL_ESEC_UNSUPPORTED_CERTIFICATE (-343)
169 #define SL_ESEC_CERTIFICATE_REVOKED (-344)
170 #define SL_ESEC_CERTIFICATE_EXPIRED (-345)
171 #define SL_ESEC_CERTIFICATE_UNKNOWN (-346)
172 #define SL_ESEC_ILLEGAL_PARAMETER (-347)
173 #define SL_ESEC_UNKNOWN_CA (-348)
174 #define SL_ESEC_ACCESS_DENIED (-349)
175 #define SL_ESEC_DECODE_ERROR (-350)
176 #define SL_ESEC_DECRYPT_ERROR (-351)
177 #define SL_ESEC_EXPORT_RESTRICTION (-360)
178 #define SL_ESEC_PROTOCOL_VERSION (-370)
179 #define SL_ESEC_INSUFFICIENT_SECURITY (-371)
180 #define SL_ESEC_INTERNAL_ERROR (-380)
181 #define SL_ESEC_USER_CANCELLED (-390)
182 #define SL_ESEC_NO_RENEGOTIATION (-400)
183 #define SL_ESEC_UNSUPPORTED_EXTENSION (-410)
184 #define SL_ESEC_CERTIFICATE_UNOBTAINABLE (-411)
185 #define SL_ESEC_UNRECOGNIZED_NAME (-412)
186 #define SL_ESEC_BAD_CERTIFICATE_STATUS_RESPONSE (-413)
187 #define SL_ESEC_BAD_CERTIFICATE_HASH_VALUE (-414)
189 #define SL_ESECGENERAL (-450)
190 #define SL_ESECDECRYPT (-451)
191 #define SL_ESECCLOSED (-452)
192 #define SL_ESECSNOVERIFY (-453)
193 #define SL_ESECNOCAFILE (-454)
194 #define SL_ESECMEMORY (-455)
195 #define SL_ESECBADCAFILE (-456)
196 #define SL_ESECBADCERTFILE (-457)
197 #define SL_ESECBADPRIVATEFILE (-458)
198 #define SL_ESECBADDHFILE (-459)
199 #define SL_ESECT00MANYSSLOPENED (-460)
200 #define SL_ESECDATEERROR (-461)
201 #define SL_ESECHANDSHAKETIMEDOUT (-462)
206 #define SL_SOCKET_PAYLOAD_TYPE_MASK (0xF0)
207 #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV4 (0x00)
208 #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV4 (0x10)
209 #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV6 (0x20)
210 #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV6 (0x30)
211 #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV4_SECURE (0x40)
212 #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV4_SECURE (0x50)
213 #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV6_SECURE (0x60)
214 #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV6_SECURE (0x70)
215 #define SL_SOCKET_PAYLOAD_TYPE_RAW_TRANCEIVER (0x80)
216 #define SL_SOCKET_PAYLOAD_TYPE_RAW_PACKET (0x90)
217 #define SL_SOCKET_PAYLOAD_TYPE_RAW_IP4 (0xa0)
218 #define SL_SOCKET_PAYLOAD_TYPE_RAW_IP6 (SL_SOCKET_PAYLOAD_TYPE_RAW_IP4 )
222 #define SL_SOL_SOCKET (1)
223 #define SL_IPPROTO_IP (2)
224 #define SL_SOL_PHY_OPT (3)
226 #define SL_SO_RCVBUF (8)
227 #define SL_SO_KEEPALIVE (9)
228 #define SL_SO_RCVTIMEO (20)
229 #define SL_SO_NONBLOCKING (24)
230 #define SL_SO_SECMETHOD (25)
231 #define SL_SO_SECURE_MASK (26)
232 #define SL_SO_SECURE_FILES (27)
233 #define SL_SO_CHANGE_CHANNEL (28)
234 #define SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME (30)
235 #define SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME (31)
236 #define SL_SO_SECURE_FILES_CA_FILE_NAME (32)
237 #define SL_SO_SECURE_FILES_DH_KEY_FILE_NAME (33)
239 #define SL_IP_MULTICAST_IF (60)
240 #define SL_IP_MULTICAST_TTL (61)
241 #define SL_IP_ADD_MEMBERSHIP (65)
242 #define SL_IP_DROP_MEMBERSHIP (66)
243 #define SL_IP_HDRINCL (67)
244 #define SL_IP_RAW_RX_NO_HEADER (68)
245 #define SL_IP_RAW_IPV6_HDRINCL (69)
247 #define SL_SO_PHY_RATE (100)
248 #define SL_SO_PHY_TX_POWER (101)
249 #define SL_SO_PHY_NUM_FRAMES_TO_TX (102)
250 #define SL_SO_PHY_PREAMBLE (103)
252 #define SL_SO_SEC_METHOD_SSLV3 (0)
253 #define SL_SO_SEC_METHOD_TLSV1 (1)
254 #define SL_SO_SEC_METHOD_TLSV1_1 (2)
255 #define SL_SO_SEC_METHOD_TLSV1_2 (3)
256 #define SL_SO_SEC_METHOD_SSLv3_TLSV1_2 (4)
257 #define SL_SO_SEC_METHOD_DLSV1 (5)
259 #define SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA (1 << 0)
260 #define SL_SEC_MASK_SSL_RSA_WITH_RC4_128_MD5 (1 << 1)
261 #define SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA (1 << 2)
262 #define SL_SEC_MASK_TLS_DHE_RSA_WITH_AES_256_CBC_SHA (1 << 3)
263 #define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (1 << 4)
264 #define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_RC4_128_SHA (1 << 5)
265 #define SL_SEC_MASK_SECURE_DEFAULT ((SEC_MASK_TLS_ECDHE_RSA_WITH_RC4_128_SHA << 1) - 1)
267 #define SL_MSG_DONTWAIT (0x00000008)
270 #define SL_IP_LEASE_PEER_RELEASE (0)
271 #define SL_IP_LEASE_PEER_DECLINE (1)
272 #define SL_IP_LEASE_EXPIRED (2)
275 #define SSL_ACCEPT (1)
276 #define RX_FRAGMENTATION_TOO_BIG (2)
277 #define OTHER_SIDE_CLOSE_SSL_DATA_NOT_ENCRYPTED (3)
281 #ifdef SL_INC_STD_BSD_API_NAMING
283 #define FD_SETSIZE SL_FD_SETSIZE
285 #define SOCK_STREAM SL_SOCK_STREAM
286 #define SOCK_DGRAM SL_SOCK_DGRAM
287 #define SOCK_RAW SL_SOCK_RAW
288 #define IPPROTO_TCP SL_IPPROTO_TCP
289 #define IPPROTO_UDP SL_IPPROTO_UDP
290 #define IPPROTO_RAW SL_IPPROTO_RAW
292 #define AF_INET SL_AF_INET
293 #define AF_INET6 SL_AF_INET6
294 #define AF_INET6_EUI_48 SL_AF_INET6_EUI_48
295 #define AF_RF SL_AF_RF
296 #define AF_PACKET SL_AF_PACKET
298 #define PF_INET SL_PF_INET
299 #define PF_INET6 SL_PF_INET6
301 #define INADDR_ANY SL_INADDR_ANY
302 #define ERROR SL_SOC_ERROR
303 #define INEXE SL_INEXE
304 #define EBADF SL_EBADF
305 #define ENSOCK SL_ENSOCK
306 #define EAGAIN SL_EAGAIN
307 #define EWOULDBLOCK SL_EWOULDBLOCK
308 #define ENOMEM SL_ENOMEM
309 #define EACCES SL_EACCES
310 #define EFAULT SL_EFAULT
311 #define EINVAL SL_EINVAL
312 #define EDESTADDRREQ SL_EDESTADDRREQ
313 #define EPROTOTYPE SL_EPROTOTYPE
314 #define ENOPROTOOPT SL_ENOPROTOOPT
315 #define EPROTONOSUPPORT SL_EPROTONOSUPPORT
316 #define ESOCKTNOSUPPORT SL_ESOCKTNOSUPPORT
317 #define EOPNOTSUPP SL_EOPNOTSUPP
318 #define EAFNOSUPPORT SL_EAFNOSUPPORT
319 #define EADDRINUSE SL_EADDRINUSE
320 #define EADDRNOTAVAIL SL_EADDRNOTAVAIL
321 #define ENETUNREACH SL_ENETUNREACH
322 #define ENOBUFS SL_ENOBUFS
323 #define EOBUFF SL_EOBUFF
324 #define EISCONN SL_EISCONN
325 #define ENOTCONN SL_ENOTCONN
326 #define ETIMEDOUT SL_ETIMEDOUT
327 #define ECONNREFUSED SL_ECONNREFUSED
329 #define SOL_SOCKET SL_SOL_SOCKET
330 #define IPPROTO_IP SL_IPPROTO_IP
331 #define SO_KEEPALIVE SL_SO_KEEPALIVE
333 #define SO_RCVTIMEO SL_SO_RCVTIMEO
334 #define SO_NONBLOCKING SL_SO_NONBLOCKING
336 #define IP_MULTICAST_IF SL_IP_MULTICAST_IF
337 #define IP_MULTICAST_TTL SL_IP_MULTICAST_TTL
338 #define IP_ADD_MEMBERSHIP SL_IP_ADD_MEMBERSHIP
339 #define IP_DROP_MEMBERSHIP SL_IP_DROP_MEMBERSHIP
341 #define socklen_t SlSocklen_t
342 #define timeval SlTimeval_t
343 #define sockaddr SlSockAddr_t
344 #define in6_addr SlIn6Addr_t
345 #define sockaddr_in6 SlSockAddrIn6_t
346 #define in_addr SlInAddr_t
347 #define sockaddr_in SlSockAddrIn_t
349 #define MSG_DONTWAIT SL_MSG_DONTWAIT
351 #define FD_SET SL_FD_SET
352 #define FD_CLR SL_FD_CLR
353 #define FD_ISSET SL_FD_ISSET
354 #define FD_ZERO SL_FD_ZERO
355 #define fd_set SlFdSet_t
357 #define socket sl_Socket
358 #define close sl_Close
359 #define accept sl_Accept
361 #define listen sl_Listen
362 #define connect sl_Connect
363 #define select sl_Select
364 #define setsockopt sl_SetSockOpt
365 #define getsockopt sl_GetSockOpt
367 #define recvfrom sl_RecvFrom
368 #define write sl_Write
370 #define sendto sl_SendTo
371 #define gethostbyname sl_NetAppDnsGetHostByName
372 #define htonl sl_Htonl
373 #define ntohl sl_Ntohl
374 #define htons sl_Htons
375 #define ntohs sl_Ntohs
389 struct { _u8 s_b1,s_b2,s_b3,s_b4; } S_un_b;
390 struct { _u8 s_w1,s_w2; } S_un_w;
400 _u32 KeepaliveEnabled;
405 _u32 ReuseaddrEnabled;
415 _u32 NonblockingEnabled;
452 SL_BSD_SECURED_PRIVATE_KEY_IDX = 0,
453 SL_BSD_SECURED_CERTIFICATE_IDX,
454 SL_BSD_SECURED_CA_IDX,
455 SL_BSD_SECURED_DH_IDX
456 }slBsd_secureSocketFilesIndex_e;
466 typedef _u32 SlTime_t;
467 typedef _u32 SlSuseconds_t;
472 SlSuseconds_t tv_usec;
475 typedef _u16 SlSocklen_t;
569 _u32 fd_array[(SL_FD_SETSIZE + 31)/32];
638 #if _SL_INCLUDE_FUNC(sl_Socket)
639 _i16 sl_Socket(_i16 Domain, _i16 Type, _i16 Protocol);
657 #if _SL_INCLUDE_FUNC(sl_Close)
658 _i16 sl_Close(_i16 sd);
711 #if _SL_INCLUDE_FUNC(sl_Accept)
712 _i16 sl_Accept(_i16 sd,
SlSockAddr_t *addr, SlSocklen_t *addrlen);
741 #if _SL_INCLUDE_FUNC(sl_Bind)
742 _i16 sl_Bind(_i16 sd,
const SlSockAddr_t *addr, _i16 addrlen);
765 #if _SL_INCLUDE_FUNC(sl_Listen)
766 _i16 sl_Listen(_i16 sd, _i16 backlog);
807 #if _SL_INCLUDE_FUNC(sl_Connect)
808 _i16 sl_Connect(_i16 sd,
const SlSockAddr_t *addr, _i16 addrlen);
859 #if _SL_INCLUDE_FUNC(sl_Select)
868 void SL_FD_SET(_i16 fd,
SlFdSet_t *fdset);
875 void SL_FD_CLR(_i16 fd,
SlFdSet_t *fdset);
886 _i16 SL_FD_ISSET(_i16 fd,
SlFdSet_t *fdset);
1169 #if _SL_INCLUDE_FUNC(sl_SetSockOpt)
1170 _i16 sl_SetSockOpt(_i16 sd, _i16 level, _i16 optname,
const void *optval, SlSocklen_t optlen);
1213 #if _SL_INCLUDE_FUNC(sl_GetSockOpt)
1214 _i16 sl_GetSockOpt(_i16 sd, _i16 level, _i16 optname,
void *optval, SlSocklen_t *optlen);
1279 #if _SL_INCLUDE_FUNC(sl_Recv)
1280 _i16 sl_Recv(_i16 sd,
void *buf, _i16 Len, _i16 flags);
1338 #if _SL_INCLUDE_FUNC(sl_RecvFrom)
1339 _i16 sl_RecvFrom(_i16 sd,
void *buf, _i16 Len, _i16 flags,
SlSockAddr_t *from, SlSocklen_t *fromlen);
1388 #if _SL_INCLUDE_FUNC(sl_Send )
1389 _i16 sl_Send(_i16 sd,
const void *buf, _i16 Len, _i16 flags);
1442 #if _SL_INCLUDE_FUNC(sl_SendTo)
1443 _i16 sl_SendTo(_i16 sd,
const void *buf, _i16 Len, _i16 flags,
const SlSockAddr_t *to, SlSocklen_t tolen);
1459 #if _SL_INCLUDE_FUNC(sl_Htonl )
1460 _u32 sl_Htonl( _u32 val );
1462 #define sl_Ntohl sl_Htonl
1478 #if _SL_INCLUDE_FUNC(sl_Htons )
1479 _u16 sl_Htons( _u16 val );
1481 #define sl_Ntohs sl_Htons