38 #include "simplelink.h"
40 #ifndef __SL_SOCKET_H__
41 #define __SL_SOCKET_H__
49 #define SL_FD_SETSIZE SL_MAX_SOCKETS
50 #define BSD_SOCKET_ID_MASK 0x0F
53 #define SL_SOCK_STREAM (1)
54 #define SL_SOCK_DGRAM (2)
55 #define SL_SOCK_RAW (3)
56 #define SL_IPPROTO_TCP (6)
57 #define SL_IPPROTO_UDP (17)
58 #define SL_IPPROTO_RAW (255)
59 #define SL_SEC_SOCKET (100)
63 #define SL_AF_INET (2)
64 #define SL_AF_INET6 (3)
65 #define SL_AF_INET6_EUI_48 (9)
67 #define SL_AF_PACKET (17)
69 #define SL_PF_INET AF_INET
70 #define SL_PF_INET6 AF_INET6
72 #define SL_INADDR_ANY (0)
75 #define SL_SOC_ERROR (-1)
76 #define SL_SOC_OK ( 0)
79 #define SL_ENSOCK (-10)
80 #define SL_EAGAIN (-11)
81 #define SL_EWOULDBLOCK SL_EAGAIN
82 #define SL_ENOMEM (-12)
83 #define SL_EACCES (-13)
84 #define SL_EFAULT (-14)
85 #define SL_ECLOSE (-15)
86 #define SL_EALREADY_ENABLED (-21)
87 #define SL_EINVAL (-22)
88 #define SL_EAUTO_CONNECT_OR_CONNECTING (-69)
89 #define SL_EUNSUPPORTED_ROLE (-86)
90 #define SL_EDESTADDRREQ (-89)
91 #define SL_EPROTOTYPE (-91)
92 #define SL_ENOPROTOOPT (-92)
93 #define SL_EPROTONOSUPPORT (-93)
94 #define SL_ESOCKTNOSUPPORT (-94)
95 #define SL_EOPNOTSUPP (-95)
96 #define SL_EAFNOSUPPORT (-97)
97 #define SL_EADDRINUSE (-98)
98 #define SL_EADDRNOTAVAIL (-99)
99 #define SL_ENETUNREACH (-101)
100 #define SL_ENOBUFS (-105)
101 #define SL_EOBUFF SL_ENOBUFS
102 #define SL_EISCONN (-106)
103 #define SL_ENOTCONN (-107)
104 #define SL_ETIMEDOUT (-110)
105 #define SL_ECONNREFUSED (-111)
106 #define SL_EALREADY (-114)
108 #define SL_ESEC_RSA_WRONG_TYPE_E (-130)
109 #define SL_ESEC_RSA_BUFFER_E (-131)
110 #define SL_ESEC_BUFFER_E (-132)
111 #define SL_ESEC_ALGO_ID_E (-133)
112 #define SL_ESEC_PUBLIC_KEY_E (-134)
113 #define SL_ESEC_DATE_E (-135)
114 #define SL_ESEC_SUBJECT_E (-136)
115 #define SL_ESEC_ISSUER_E (-137)
116 #define SL_ESEC_CA_TRUE_E (-138)
117 #define SL_ESEC_EXTENSIONS_E (-139)
118 #define SL_ESEC_ASN_PARSE_E (-140)
119 #define SL_ESEC_ASN_VERSION_E (-141)
120 #define SL_ESEC_ASN_GETINT_E (-142)
121 #define SL_ESEC_ASN_RSA_KEY_E (-143)
122 #define SL_ESEC_ASN_OBJECT_ID_E (-144)
123 #define SL_ESEC_ASN_TAG_NULL_E (-145)
124 #define SL_ESEC_ASN_EXPECT_0_E (-146)
125 #define SL_ESEC_ASN_BITSTR_E (-147)
126 #define SL_ESEC_ASN_UNKNOWN_OID_E (-148)
127 #define SL_ESEC_ASN_DATE_SZ_E (-149)
128 #define SL_ESEC_ASN_BEFORE_DATE_E (-150)
129 #define SL_ESEC_ASN_AFTER_DATE_E (-151)
130 #define SL_ESEC_ASN_SIG_OID_E (-152)
131 #define SL_ESEC_ASN_TIME_E (-153)
132 #define SL_ESEC_ASN_INPUT_E (-154)
133 #define SL_ESEC_ASN_SIG_CONFIRM_E (-155)
134 #define SL_ESEC_ASN_SIG_HASH_E (-156)
135 #define SL_ESEC_ASN_SIG_KEY_E (-157)
136 #define SL_ESEC_ASN_DH_KEY_E (-158)
137 #define SL_ESEC_ASN_NTRU_KEY_E (-159)
138 #define SL_ESEC_ECC_BAD_ARG_E (-170)
139 #define SL_ESEC_ASN_ECC_KEY_E (-171)
140 #define SL_ESEC_ECC_CURVE_OID_E (-172)
141 #define SL_ESEC_BAD_FUNC_ARG (-173)
142 #define SL_ESEC_NOT_COMPILED_IN (-174)
143 #define SL_ESEC_UNICODE_SIZE_E (-175)
144 #define SL_ESEC_NO_PASSWORD (-176)
145 #define SL_ESEC_ALT_NAME_E (-177)
146 #define SL_ESEC_AES_GCM_AUTH_E (-180)
147 #define SL_ESEC_AES_CCM_AUTH_E (-181)
150 #define SL_ESEC_CLOSE_NOTIFY (-300)
151 #define SL_ESEC_UNEXPECTED_MESSAGE (-310)
152 #define SL_ESEC_BAD_RECORD_MAC (-320)
153 #define SL_ESEC_DECRYPTION_FAILED (-321)
154 #define SL_ESEC_RECORD_OVERFLOW (-322)
155 #define SL_ESEC_DECOMPRESSION_FAILURE (-330)
156 #define SL_ESEC_HANDSHAKE_FAILURE (-340)
157 #define SL_ESEC_NO_CERTIFICATE (-341)
158 #define SL_ESEC_BAD_CERTIFICATE (-342)
159 #define SL_ESEC_UNSUPPORTED_CERTIFICATE (-343)
160 #define SL_ESEC_CERTIFICATE_REVOKED (-344)
161 #define SL_ESEC_CERTIFICATE_EXPIRED (-345)
162 #define SL_ESEC_CERTIFICATE_UNKNOWN (-346)
163 #define SL_ESEC_ILLEGAL_PARAMETER (-347)
164 #define SL_ESEC_UNKNOWN_CA (-348)
165 #define SL_ESEC_ACCESS_DENIED (-349)
166 #define SL_ESEC_DECODE_ERROR (-350)
167 #define SL_ESEC_DECRYPT_ERROR (-351)
168 #define SL_ESEC_EXPORT_RESTRICTION (-360)
169 #define SL_ESEC_PROTOCOL_VERSION (-370)
170 #define SL_ESEC_INSUFFICIENT_SECURITY (-371)
171 #define SL_ESEC_INTERNAL_ERROR (-380)
172 #define SL_ESEC_USER_CANCELLED (-390)
173 #define SL_ESEC_NO_RENEGOTIATION (-400)
174 #define SL_ESEC_UNSUPPORTED_EXTENSION (-410)
175 #define SL_ESEC_CERTIFICATE_UNOBTAINABLE (-411)
176 #define SL_ESEC_UNRECOGNIZED_NAME (-412)
177 #define SL_ESEC_BAD_CERTIFICATE_STATUS_RESPONSE (-413)
178 #define SL_ESEC_BAD_CERTIFICATE_HASH_VALUE (-414)
180 #define SL_ESECGENERAL (-450)
181 #define SL_ESECDECRYPT (-451)
182 #define SL_ESECCLOSED (-452)
183 #define SL_ESECSNOVERIFY (-453)
184 #define SL_ESECNOCAFILE (-454)
185 #define SL_ESECMEMORY (-455)
186 #define SL_ESECBADCAFILE (-456)
187 #define SL_ESECBADCERTFILE (-457)
188 #define SL_ESECBADPRIVATEFILE (-458)
189 #define SL_ESECBADDHFILE (-459)
190 #define SL_ESECT00MANYSSLOPENED (-460)
191 #define SL_ESECDATEERROR (-461)
192 #define SL_ESECHANDSHAKETIMEDOUT (-462)
197 #define SL_SOCKET_PAYLOAD_TYPE_MASK (0xF0)
198 #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV4 (0x00)
199 #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV4 (0x10)
200 #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV6 (0x20)
201 #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV6 (0x30)
202 #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV4_SECURE (0x40)
203 #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV4_SECURE (0x50)
204 #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV6_SECURE (0x60)
205 #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV6_SECURE (0x70)
206 #define SL_SOCKET_PAYLOAD_TYPE_RAW_TRANCEIVER (0x80)
207 #define SL_SOCKET_PAYLOAD_TYPE_RAW_PACKET (0x90)
208 #define SL_SOCKET_PAYLOAD_TYPE_RAW_IP4 (0xa0)
209 #define SL_SOCKET_PAYLOAD_TYPE_RAW_IP6 (SL_SOCKET_PAYLOAD_TYPE_RAW_IP4 )
213 #define SL_SOL_SOCKET (1)
214 #define SL_IPPROTO_IP (2)
215 #define SL_SOL_PHY_OPT (3)
217 #define SL_SO_RCVBUF (8)
218 #define SL_SO_KEEPALIVE (9)
219 #define SL_SO_RCVTIMEO (20)
220 #define SL_SO_NONBLOCKING (24)
221 #define SL_SO_SECMETHOD (25)
222 #define SL_SO_SECURE_MASK (26)
223 #define SL_SO_SECURE_FILES (27)
224 #define SL_SO_CHANGE_CHANNEL (28)
225 #define SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME (30)
226 #define SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME (31)
227 #define SL_SO_SECURE_FILES_CA_FILE_NAME (32)
228 #define SL_SO_SECURE_FILES_DH_KEY_FILE_NAME (33)
230 #define SL_IP_MULTICAST_IF (60)
231 #define SL_IP_MULTICAST_TTL (61)
232 #define SL_IP_ADD_MEMBERSHIP (65)
233 #define SL_IP_DROP_MEMBERSHIP (66)
234 #define SL_IP_HDRINCL (67)
235 #define SL_IP_RAW_RX_NO_HEADER (68)
236 #define SL_IP_RAW_IPV6_HDRINCL (69)
238 #define SL_SO_PHY_RATE (100)
239 #define SL_SO_PHY_TX_POWER (101)
240 #define SL_SO_PHY_NUM_FRAMES_TO_TX (102)
241 #define SL_SO_PHY_PREAMBLE (103)
243 #define SL_SO_SEC_METHOD_SSLV3 (0)
244 #define SL_SO_SEC_METHOD_TLSV1 (1)
245 #define SL_SO_SEC_METHOD_TLSV1_1 (2)
246 #define SL_SO_SEC_METHOD_TLSV1_2 (3)
247 #define SL_SO_SEC_METHOD_SSLv3_TLSV1_2 (4)
248 #define SL_SO_SEC_METHOD_DLSV1 (5)
250 #define SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA (1 << 0)
251 #define SL_SEC_MASK_SSL_RSA_WITH_RC4_128_MD5 (1 << 1)
252 #define SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA (1 << 2)
253 #define SL_SEC_MASK_TLS_DHE_RSA_WITH_AES_256_CBC_SHA (1 << 3)
254 #define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (1 << 4)
255 #define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_RC4_128_SHA (1 << 5)
256 #define SL_SEC_MASK_SECURE_DEFAULT ((SEC_MASK_TLS_ECDHE_RSA_WITH_RC4_128_SHA << 1) - 1)
258 #define SL_MSG_DONTWAIT 0x00000008
260 #define SL_NETAPP_IPV4_ACQUIRED 1
261 #define SL_NETAPP_IPV6_ACQUIRED 2
262 #define SL_NETAPP_SOCKET_TX_FAILED 3
263 #define SL_NETAPP_IP_LEASED 4
264 #define SL_NETAPP_IP_RELEASED 5
267 #define SL_IP_LEASE_PEER_RELEASE 0
268 #define SL_IP_LEASE_PEER_DECLINE 1
269 #define SL_IP_LEASE_EXPIRED 2
271 #ifdef SL_INC_STD_BSD_API_NAMING
273 #define FD_SETSIZE SL_FD_SETSIZE
275 #define SOCK_STREAM SL_SOCK_STREAM
276 #define SOCK_DGRAM SL_SOCK_DGRAM
277 #define SOCK_RAW SL_SOCK_RAW
278 #define IPPROTO_TCP SL_IPPROTO_TCP
279 #define IPPROTO_UDP SL_IPPROTO_UDP
280 #define IPPROTO_RAW SL_IPPROTO_RAW
282 #define AF_INET SL_AF_INET
283 #define AF_INET6 SL_AF_INET6
284 #define AF_INET6_EUI_48 SL_AF_INET6_EUI_48
285 #define AF_RF SL_AF_RF
286 #define AF_PACKET SL_AF_PACKET
288 #define PF_INET SL_PF_INET
289 #define PF_INET6 SL_PF_INET6
291 #define INADDR_ANY SL_INADDR_ANY
292 #define ERROR SL_SOC_ERROR
293 #define INEXE SL_INEXE
294 #define EBADF SL_EBADF
295 #define ENSOCK SL_ENSOCK
296 #define EAGAIN SL_EAGAIN
297 #define EWOULDBLOCK SL_EWOULDBLOCK
298 #define ENOMEM SL_ENOMEM
299 #define EACCES SL_EACCES
300 #define EFAULT SL_EFAULT
301 #define EINVAL SL_EINVAL
302 #define EDESTADDRREQ SL_EDESTADDRREQ
303 #define EPROTOTYPE SL_EPROTOTYPE
304 #define ENOPROTOOPT SL_ENOPROTOOPT
305 #define EPROTONOSUPPORT SL_EPROTONOSUPPORT
306 #define ESOCKTNOSUPPORT SL_ESOCKTNOSUPPORT
307 #define EOPNOTSUPP SL_EOPNOTSUPP
308 #define EAFNOSUPPORT SL_EAFNOSUPPORT
309 #define EADDRINUSE SL_EADDRINUSE
310 #define EADDRNOTAVAIL SL_EADDRNOTAVAIL
311 #define ENETUNREACH SL_ENETUNREACH
312 #define ENOBUFS SL_ENOBUFS
313 #define EOBUFF SL_EOBUFF
314 #define EISCONN SL_EISCONN
315 #define ENOTCONN SL_ENOTCONN
316 #define ETIMEDOUT SL_ETIMEDOUT
317 #define ECONNREFUSED SL_ECONNREFUSED
319 #define SOL_SOCKET SL_SOL_SOCKET
320 #define IPPROTO_IP SL_IPPROTO_IP
321 #define SO_KEEPALIVE SL_SO_KEEPALIVE
323 #define SO_RCVTIMEO SL_SO_RCVTIMEO
324 #define SO_NONBLOCKING SL_SO_NONBLOCKING
326 #define IP_MULTICAST_IF SL_IP_MULTICAST_IF
327 #define IP_MULTICAST_TTL SL_IP_MULTICAST_TTL
328 #define IP_ADD_MEMBERSHIP SL_IP_ADD_MEMBERSHIP
329 #define IP_DROP_MEMBERSHIP SL_IP_DROP_MEMBERSHIP
331 #define socklen_t SlSocklen_t
332 #define timeval SlTimeval_t
333 #define sockaddr SlSockAddr_t
334 #define in6_addr SlIn6Addr_t
335 #define sockaddr_in6 SlSockAddrIn6_t
336 #define in_addr SlInAddr_t
337 #define sockaddr_in SlSockAddrIn_t
339 #define MSG_DONTWAIT SL_MSG_DONTWAIT
341 #define FD_SET SL_FD_SET
342 #define FD_CLR SL_FD_CLR
343 #define FD_ISSET SL_FD_ISSET
344 #define FD_ZERO SL_FD_ZERO
345 #define fd_set SlFdSet_t
347 #define socket sl_Socket
348 #define close sl_Close
349 #define accept sl_Accept
351 #define listen sl_Listen
352 #define connect sl_Connect
353 #define select sl_Select
354 #define setsockopt sl_SetSockOpt
355 #define getsockopt sl_GetSockOpt
357 #define recvfrom sl_RecvFrom
358 #define write sl_Write
360 #define sendto sl_SendTo
361 #define gethostbyname sl_NetAppDnsGetHostByName
362 #define htonl sl_Htonl
363 #define ntohl sl_Ntohl
364 #define htons sl_Htons
365 #define ntohs sl_Ntohs
374 unsigned long s_addr;
377 struct {
unsigned char s_b1,s_b2,s_b3,s_b4; } S_un_b;
378 struct {
unsigned char s_w1,s_w2; } S_un_w;
379 unsigned long S_addr;
389 unsigned long KeepaliveEnabled;
394 unsigned long ReuseaddrEnabled;
399 unsigned long Winsize;
404 unsigned long NonblockingEnabled;
422 unsigned long secureMask;
427 unsigned char secureMethod;
432 SL_BSD_SECURED_PRIVATE_KEY_IDX = 0,
433 SL_BSD_SECURED_CERTIFICATE_IDX,
434 SL_BSD_SECURED_CA_IDX,
435 SL_BSD_SECURED_DH_IDX
436 }slBsd_secureSocketFilesIndex_e;
448 typedef unsigned long SlTime_t;
449 typedef unsigned long SlSuseconds_t;
454 SlSuseconds_t tv_usec;
457 typedef unsigned int SlSocklen_t;
462 unsigned short sa_family;
463 unsigned char sa_data[14];
472 unsigned char _S6_u8[16];
473 unsigned long _S6_u32[4];
480 unsigned short sin6_family;
481 unsigned short sin6_port;
482 unsigned long sin6_flowinfo;
484 unsigned long sin6_scope_id;
491 unsigned short sin_family;
492 unsigned short sin_port;
500 unsigned long gateway;
508 unsigned long gateway[4];
509 unsigned long dns[4];
514 unsigned long ip_address;
515 unsigned long lease_time;
516 unsigned char mac[6];
517 unsigned short padding;
522 unsigned long ip_address;
523 unsigned char mac[6];
524 unsigned short reason;
545 unsigned char secureFiles[4];
551 unsigned long fd_array[(SL_FD_SETSIZE + 31)/32];
623 #if _SL_INCLUDE_FUNC(sl_Socket)
624 int sl_Socket(
int Domain,
int Type,
int Protocol);
642 #if _SL_INCLUDE_FUNC(sl_Close)
696 #if _SL_INCLUDE_FUNC(sl_Accept)
727 #if _SL_INCLUDE_FUNC(sl_Bind)
751 #if _SL_INCLUDE_FUNC(sl_Listen)
793 #if _SL_INCLUDE_FUNC(sl_Connect)
845 #if _SL_INCLUDE_FUNC(sl_Select)
1091 #if _SL_INCLUDE_FUNC(sl_SetSockOpt)
1092 int sl_SetSockOpt(
int sd,
int level,
int optname,
const void *optval, SlSocklen_t optlen);
1135 #if _SL_INCLUDE_FUNC(sl_GetSockOpt)
1136 int sl_GetSockOpt(
int sd,
int level,
int optname,
void *optval, SlSocklen_t *optlen);
1189 #if _SL_INCLUDE_FUNC(sl_Recv)
1190 int sl_Recv(
int sd,
void *buf,
int Len,
int flags);
1248 #if _SL_INCLUDE_FUNC(sl_RecvFrom)
1298 #if _SL_INCLUDE_FUNC(sl_Send )
1299 int sl_Send(
int sd,
const void *buf,
int Len,
int flags);
1352 #if _SL_INCLUDE_FUNC(sl_SendTo)
1353 int sl_SendTo(
int sd,
const void *buf,
int Len,
int flags,
const SlSockAddr_t *to, SlSocklen_t tolen);
1369 #if _SL_INCLUDE_FUNC(sl_Htonl )
1370 unsigned long sl_Htonl(
unsigned long val );
1372 #define sl_Ntohl sl_Htonl
1389 #if _SL_INCLUDE_FUNC(sl_Htons )
1390 unsigned short sl_Htons(
unsigned short val );
1392 #define sl_Ntohs sl_Htons
int sl_SendTo(int sd, const void *buf, int Len, int flags, const SlSockAddr_t *to, SlSocklen_t tolen)
write data to socket
int sl_Select(int nfds, SlFdSet_t *readsds, SlFdSet_t *writesds, SlFdSet_t *exceptsds, struct SlTimeval_t *timeout)
Monitor socket activity.
void SL_FD_ZERO(SlFdSet_t *fdset)
Select's SlFdSet_t ZERO function.
int sl_Connect(int sd, const SlSockAddr_t *addr, int addrlen)
Initiate a connection on a socket.
int SL_FD_ISSET(int fd, SlFdSet_t *fdset)
Select's SlFdSet_t ISSET function.
int sl_Recv(int sd, void *buf, int Len, int flags)
read data from TCP socket
int sl_Send(int sd, const void *buf, int Len, int flags)
write data to TCP socket
void SL_FD_SET(int fd, SlFdSet_t *fdset)
Select's SlFdSet_t SET function.
int sl_Accept(int sd, SlSockAddr_t *addr, SlSocklen_t *addrlen)
Accept a connection on a socket.
int sl_Socket(int Domain, int Type, int Protocol)
create an endpoint for communication
void SL_FD_CLR(int fd, SlFdSet_t *fdset)
Select's SlFdSet_t CLR function.
int sl_Bind(int sd, const SlSockAddr_t *addr, int addrlen)
assign a name to a socket
int sl_GetSockOpt(int sd, int level, int optname, void *optval, SlSocklen_t *optlen)
Get socket options.
unsigned short sl_Htons(unsigned short val)
Reorder the bytes of a 16-bit unsigned value.
int sl_Close(int sd)
gracefully close socket
int sl_SetSockOpt(int sd, int level, int optname, const void *optval, SlSocklen_t optlen)
set socket options
int sl_Listen(int sd, int backlog)
listen for connections on a socket
unsigned long sl_Htonl(unsigned long val)
Reorder the bytes of a 32-bit unsigned value.
int sl_RecvFrom(int sd, void *buf, int Len, int flags, SlSockAddr_t *from, SlSocklen_t *fromlen)
read data from socket