1 /*
2  * socket.h - CC31xx/CC32xx Host Driver Implementation
3  *
4  * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
5  *
6  *
7  *  Redistribution and use in source and binary forms, with or without
8  *  modification, are permitted provided that the following conditions
9  *  are met:
10  *
11  *    Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  *    Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the
17  *    distribution.
18  *
19  *    Neither the name of Texas Instruments Incorporated nor the names of
20  *    its contributors may be used to endorse or promote products derived
21  *    from this software without specific prior written permission.
22  *
23  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35 */
36 
37 /*****************************************************************************/
38 /* Include files                                                             */
39 /*****************************************************************************/
40 #include "simplelink.h"
41 
42 #ifndef __SL_SOCKET_H__
43 #define __SL_SOCKET_H__
44 
45 
46 
47 
48 #ifdef    __cplusplus
49 extern "C" {
50 #endif
51 
52 /*!
53 
54     \addtogroup socket
55     @{
56 
57 */
58 
59 /*****************************************************************************/
60 /* Macro declarations                                                        */
61 /*****************************************************************************/
62 
63 #define SL_FD_SETSIZE                         SL_MAX_SOCKETS         /* Number of sockets to select on - same is max sockets!               */
64 #define BSD_SOCKET_ID_MASK                     (0x0F)                 /* Index using the LBS 4 bits for socket id 0-7 */
65 /* Define some BSD protocol constants.  */
66 #define SL_SOCK_STREAM                         (1)                       /* TCP Socket                                                          */
67 #define SL_SOCK_DGRAM                          (2)                       /* UDP Socket                                                          */
68 #define SL_SOCK_RAW                            (3)                       /* Raw socket                                                          */
69 #define SL_IPPROTO_TCP                         (6)                       /* TCP Raw Socket                                                      */
70 #define SL_IPPROTO_UDP                         (17)                      /* UDP Raw Socket                                                      */
71 #define SL_IPPROTO_RAW                         (255)                     /* Raw Socket                                                          */
72 #define SL_SEC_SOCKET                          (100)                     /* Secured Socket Layer (SSL,TLS)                                      */
73 
74 /* Address families.  */
75 #define     SL_AF_INET                         (2)                       /* IPv4 socket (UDP, TCP, etc)                                          */
76 #define     SL_AF_INET6                        (3)                       /* IPv6 socket (UDP, TCP, etc)                                          */
77 #define     SL_AF_INET6_EUI_48                 (9)
78 #define     SL_AF_RF                           (6)                       /* data include RF parameter, All layer by user (Wifi could be disconnected) */
79 #define     SL_AF_PACKET                       (17)
80 /* Protocol families, same as address families.  */
81 #define     SL_PF_INET                         AF_INET
82 #define     SL_PF_INET6                        AF_INET6
83 #define     SL_INADDR_ANY                      (0)                       /*  bind any address  */
84 
85 /* error codes */
86 #define SL_SOC_ERROR                          (-1)  /* Failure.                                                             */
87 #define SL_SOC_OK                             ( 0)  /* Success.                                                             */
88 #define SL_INEXE                              (-8)   /* socket command in execution  */
89 #define SL_EBADF                              (-9)   /* Bad file number */
90 #define SL_ENSOCK                             (-10)  /* The system limit on the total number of open socket, has been reached */
91 #define SL_EAGAIN                             (-11)  /* Try again */
92 #define SL_EWOULDBLOCK                        SL_EAGAIN
93 #define SL_ENOMEM                             (-12)  /* Out of memory */
94 #define SL_EACCES                             (-13)  /* Permission denied */
95 #define SL_EFAULT                             (-14)  /* Bad address */
96 #define SL_ECLOSE                             (-15)  /* close socket operation failed to transmit all queued packets */
97 #define SL_EALREADY_ENABLED                   (-21)  /* Transceiver - Transceiver already ON. there could be only one */
98 #define SL_EINVAL                             (-22)  /* Invalid argument */
99 #define SL_EAUTO_CONNECT_OR_CONNECTING        (-69)  /* Transceiver - During connection, connected or auto mode started */
100 #define SL_CONNECTION_PENDING                  (-72)  /* Transceiver - Device is connected, disconnect first to open transceiver */
101 #define SL_EUNSUPPORTED_ROLE                  (-86)  /* Transceiver - Trying to start when WLAN role is AP or P2P GO */
102 #define SL_EDESTADDRREQ                       (-89)  /* Destination address required */
103 #define SL_EPROTOTYPE                         (-91)  /* Protocol wrong type for socket */
104 #define SL_ENOPROTOOPT                        (-92)  /* Protocol not available */
105 #define SL_EPROTONOSUPPORT                    (-93)  /* Protocol not supported */
106 #define SL_ESOCKTNOSUPPORT                    (-94)  /* Socket type not supported */
107 #define SL_EOPNOTSUPP                         (-95)  /* Operation not supported on transport endpoint */
108 #define SL_EAFNOSUPPORT                       (-97)  /* Address family not supported by protocol */
109 #define SL_EADDRINUSE                         (-98)  /* Address already in use */
110 #define SL_EADDRNOTAVAIL                      (-99)  /* Cannot assign requested address */
111 #define SL_ENETUNREACH                        (-101) /* Network is unreachable */
112 #define SL_ENOBUFS                            (-105) /* No buffer space available */
113 #define SL_EOBUFF                             SL_ENOBUFS
114 #define SL_EISCONN                            (-106) /* Transport endpoint is already connected */
115 #define SL_ENOTCONN                           (-107) /* Transport endpoint is not connected */
116 #define SL_ETIMEDOUT                          (-110) /* Connection timed out */
117 #define SL_ECONNREFUSED                       (-111) /* Connection refused */
118 #define SL_EALREADY                           (-114) /* Non blocking connect in progress, try again */
119 
120 #define SL_ESEC_RSA_WRONG_TYPE_E              (-130)  /* RSA wrong block type for RSA function */
121 #define SL_ESEC_RSA_BUFFER_E                  (-131)  /* RSA buffer error, output too small or */
122 #define SL_ESEC_BUFFER_E                      (-132)  /* output buffer too small or input too large */
123 #define SL_ESEC_ALGO_ID_E                     (-133)  /* setting algo id error */
124 #define SL_ESEC_PUBLIC_KEY_E                  (-134)  /* setting public key error */
125 #define SL_ESEC_DATE_E                        (-135)  /* setting date validity error */
126 #define SL_ESEC_SUBJECT_E                     (-136)  /* setting subject name error */
127 #define SL_ESEC_ISSUER_E                      (-137)  /* setting issuer  name error */
128 #define SL_ESEC_CA_TRUE_E                     (-138)  /* setting CA basic constraint true error */
129 #define SL_ESEC_EXTENSIONS_E                  (-139)  /* setting extensions error */
130 #define SL_ESEC_ASN_PARSE_E                   (-140)  /* ASN parsing error, invalid input */
131 #define SL_ESEC_ASN_VERSION_E                 (-141)  /* ASN version error, invalid number */
132 #define SL_ESEC_ASN_GETINT_E                  (-142)  /* ASN get big _i16 error, invalid data */
133 #define SL_ESEC_ASN_RSA_KEY_E                 (-143)  /* ASN key init error, invalid input */
134 #define SL_ESEC_ASN_OBJECT_ID_E               (-144)  /* ASN object id error, invalid id */
135 #define SL_ESEC_ASN_TAG_NULL_E                (-145)  /* ASN tag error, not null */
136 #define SL_ESEC_ASN_EXPECT_0_E                (-146)  /* ASN expect error, not zero */
137 #define SL_ESEC_ASN_BITSTR_E                  (-147)  /* ASN bit string error, wrong id */
138 #define SL_ESEC_ASN_UNKNOWN_OID_E             (-148)  /* ASN oid error, unknown sum id */
139 #define SL_ESEC_ASN_DATE_SZ_E                 (-149)  /* ASN date error, bad size */
140 #define SL_ESEC_ASN_BEFORE_DATE_E             (-150)  /* ASN date error, current date before */
141 #define SL_ESEC_ASN_AFTER_DATE_E              (-151)  /* ASN date error, current date after */
142 #define SL_ESEC_ASN_SIG_OID_E                 (-152)  /* ASN signature error, mismatched oid */
143 #define SL_ESEC_ASN_TIME_E                    (-153)  /* ASN time error, unknown time type */
144 #define SL_ESEC_ASN_INPUT_E                   (-154)  /* ASN input error, not enough data */
145 #define SL_ESEC_ASN_SIG_CONFIRM_E             (-155)  /* ASN sig error, confirm failure */
146 #define SL_ESEC_ASN_SIG_HASH_E                (-156)  /* ASN sig error, unsupported hash type */
147 #define SL_ESEC_ASN_SIG_KEY_E                 (-157)  /* ASN sig error, unsupported key type */
148 #define SL_ESEC_ASN_DH_KEY_E                  (-158)  /* ASN key init error, invalid input */
149 #define SL_ESEC_ASN_NTRU_KEY_E                (-159)  /* ASN ntru key decode error, invalid input */
150 #define SL_ESEC_ECC_BAD_ARG_E                 (-170)  /* ECC input argument of wrong type */
151 #define SL_ESEC_ASN_ECC_KEY_E                 (-171)  /* ASN ECC bad input */
152 #define SL_ESEC_ECC_CURVE_OID_E               (-172)  /* Unsupported ECC OID curve type */
153 #define SL_ESEC_BAD_FUNC_ARG                  (-173)  /* Bad function argument provided */
154 #define SL_ESEC_NOT_COMPILED_IN               (-174)  /* Feature not compiled in */
155 #define SL_ESEC_UNICODE_SIZE_E                (-175)  /* Unicode password too big */
156 #define SL_ESEC_NO_PASSWORD                   (-176)  /* no password provided by user */
157 #define SL_ESEC_ALT_NAME_E                    (-177)  /* alt name size problem, too big */
158 #define SL_ESEC_AES_GCM_AUTH_E                (-180)  /* AES-GCM Authentication check failure */
159 #define SL_ESEC_AES_CCM_AUTH_E                (-181)  /* AES-CCM Authentication check failure */
160 #define SL_SOCKET_ERROR_E                     (-208)  /* Error state on socket */
161 
162 #define SL_ESEC_MEMORY_ERROR                  (-203)  /* out of memory            */
163 #define SL_ESEC_VERIFY_FINISHED_ERROR         (-204)  /* verify problem on finished */
164 #define SL_ESEC_VERIFY_MAC_ERROR              (-205)  /* verify mac problem       */
165 #define SL_ESEC_UNKNOWN_HANDSHAKE_TYPE        (-207)  /* weird handshake type     */
166 #define SL_ESEC_SOCKET_ERROR_E                (-208)  /* error state on socket    */
167 #define SL_ESEC_SOCKET_NODATA                 (-209)  /* expected data, not there */
168 #define SL_ESEC_INCOMPLETE_DATA               (-210)  /* don't have enough data to complete task            */
169 #define SL_ESEC_UNKNOWN_RECORD_TYPE           (-211)  /* unknown type in record hdr */
170 #define SL_ESEC_FATAL_ERROR                   (-213)  /* recvd alert fatal error  */
171 #define SL_ESEC_ENCRYPT_ERROR                 (-214)  /* error during encryption  */
172 #define SL_ESEC_NO_PEER_KEY                   (-216)  /* need peer's key          */
173 #define SL_ESEC_NO_PRIVATE_KEY                (-217)  /* need the private key     */
174 #define SL_ESEC_RSA_PRIVATE_ERROR             (-218)  /* error during rsa priv op */
175 #define SL_ESEC_NO_DH_PARAMS                  (-219)  /* server missing DH params */
176 #define SL_ESEC_BUILD_MSG_ERROR               (-220)  /* build message failure    */
177 #define SL_ESEC_BAD_HELLO                     (-221)  /* client hello malformed   */
178 #define SL_ESEC_DOMAIN_NAME_MISMATCH          (-222)  /* peer subject name mismatch */
179 #define SL_ESEC_WANT_READ                     (-223)  /* want read, call again    */
180 #define SL_ESEC_NOT_READY_ERROR               (-224)  /* handshake layer not ready */
181 #define SL_ESEC_PMS_VERSION_ERROR             (-225)  /* pre m secret version error */
182 #define SL_ESEC_VERSION_ERROR                 (-226)  /* record layer version error */
183 #define SL_ESEC_WANT_WRITE                    (-227)  /* want write, call again   */
184 #define SL_ESEC_BUFFER_ERROR                  (-228)  /* malformed buffer input   */
185 #define SL_ESEC_VERIFY_CERT_ERROR             (-229)  /* verify cert error        */
186 #define SL_ESEC_VERIFY_SIGN_ERROR             (-230)  /* verify sign error        */
187 
188 #define SL_ESEC_LENGTH_ERROR                  (-241)  /* record layer length error */
189 #define SL_ESEC_PEER_KEY_ERROR                (-242)  /* can't decode peer key */
190 #define SL_ESEC_ZERO_RETURN                   (-243)  /* peer sent close notify */
191 #define SL_ESEC_SIDE_ERROR                    (-244)  /* wrong client/server type */
192 #define SL_ESEC_NO_PEER_CERT                  (-245)  /* peer didn't send key */
193 #define SL_ESEC_ECC_CURVETYPE_ERROR           (-250)  /* Bad ECC Curve Type */
194 #define SL_ESEC_ECC_CURVE_ERROR               (-251)  /* Bad ECC Curve */
195 #define SL_ESEC_ECC_PEERKEY_ERROR             (-252)  /* Bad Peer ECC Key */
196 #define SL_ESEC_ECC_MAKEKEY_ERROR             (-253)  /* Bad Make ECC Key */
197 #define SL_ESEC_ECC_EXPORT_ERROR              (-254)  /* Bad ECC Export Key */
198 #define SL_ESEC_ECC_SHARED_ERROR              (-255)  /* Bad ECC Shared Secret */
199 #define SL_ESEC_NOT_CA_ERROR                  (-257)  /* Not a CA cert error */
200 #define SL_ESEC_BAD_PATH_ERROR                (-258)  /* Bad path for opendir */
201 #define SL_ESEC_BAD_CERT_MANAGER_ERROR        (-259)  /* Bad Cert Manager */
202 #define SL_ESEC_MAX_CHAIN_ERROR               (-268)  /* max chain depth exceeded */
203 #define SL_ESEC_SUITES_ERROR                  (-271)  /* suites pointer error */
204 #define SL_ESEC_SSL_NO_PEM_HEADER             (-272)  /* no PEM header found */
205 #define SL_ESEC_OUT_OF_ORDER_E                (-273)  /* out of order message */
206 #define SL_ESEC_SANITY_CIPHER_E               (-275)  /* sanity check on cipher error */
207 #define SL_ESEC_GEN_COOKIE_E                  (-277)  /* Generate Cookie Error */
208 #define SL_ESEC_NO_PEER_VERIFY                (-278)  /* Need peer cert verify Error */
209 #define SL_ESEC_UNKNOWN_SNI_HOST_NAME_E       (-281)  /* Unrecognized host name Error */
210 /* begin negotiation parameter errors */
211 #define SL_ESEC_UNSUPPORTED_SUITE     (-290)            /* unsupported cipher suite */
212 #define SL_ESEC_MATCH_SUITE_ERROR      (-291 )            /* can't match cipher suite */
213 
214 /* ssl tls security start with -300 offset */
215 #define SL_ESEC_CLOSE_NOTIFY                  (-300) /* ssl/tls alerts */
216 #define SL_ESEC_UNEXPECTED_MESSAGE            (-310) /* ssl/tls alerts */
217 #define SL_ESEC_BAD_RECORD_MAC                (-320) /* ssl/tls alerts */
218 #define SL_ESEC_DECRYPTION_FAILED             (-321) /* ssl/tls alerts */
219 #define SL_ESEC_RECORD_OVERFLOW               (-322) /* ssl/tls alerts */
220 #define SL_ESEC_DECOMPRESSION_FAILURE         (-330) /* ssl/tls alerts */
221 #define SL_ESEC_HANDSHAKE_FAILURE             (-340) /* ssl/tls alerts */
222 #define SL_ESEC_NO_CERTIFICATE                (-341) /* ssl/tls alerts */
223 #define SL_ESEC_BAD_CERTIFICATE               (-342) /* ssl/tls alerts */
224 #define SL_ESEC_UNSUPPORTED_CERTIFICATE       (-343) /* ssl/tls alerts */
225 #define SL_ESEC_CERTIFICATE_REVOKED           (-344) /* ssl/tls alerts */
226 #define SL_ESEC_CERTIFICATE_EXPIRED           (-345) /* ssl/tls alerts */
227 #define SL_ESEC_CERTIFICATE_UNKNOWN           (-346) /* ssl/tls alerts */
228 #define SL_ESEC_ILLEGAL_PARAMETER             (-347) /* ssl/tls alerts */
229 #define SL_ESEC_UNKNOWN_CA                    (-348) /* ssl/tls alerts */
230 #define SL_ESEC_ACCESS_DENIED                 (-349) /* ssl/tls alerts */
231 #define SL_ESEC_DECODE_ERROR                  (-350) /* ssl/tls alerts */
232 #define SL_ESEC_DECRYPT_ERROR                 (-351) /* ssl/tls alerts */
233 #define SL_ESEC_EXPORT_RESTRICTION            (-360) /* ssl/tls alerts */
234 #define SL_ESEC_PROTOCOL_VERSION              (-370) /* ssl/tls alerts */
235 #define SL_ESEC_INSUFFICIENT_SECURITY         (-371) /* ssl/tls alerts */
236 #define SL_ESEC_INTERNAL_ERROR                (-380) /* ssl/tls alerts */
237 #define SL_ESEC_USER_CANCELLED                (-390) /* ssl/tls alerts */
238 #define SL_ESEC_NO_RENEGOTIATION              (-400) /* ssl/tls alerts */
239 #define SL_ESEC_UNSUPPORTED_EXTENSION         (-410) /* ssl/tls alerts */
240 #define SL_ESEC_CERTIFICATE_UNOBTAINABLE      (-411) /* ssl/tls alerts */
241 #define SL_ESEC_UNRECOGNIZED_NAME             (-412) /* ssl/tls alerts */
242 #define SL_ESEC_BAD_CERTIFICATE_STATUS_RESPONSE  (-413) /* ssl/tls alerts */
243 #define SL_ESEC_BAD_CERTIFICATE_HASH_VALUE    (-414) /* ssl/tls alerts */
244 /* propierty secure */
245 #define SL_ESECGENERAL                        (-450)  /* error secure level general error */
246 #define SL_ESECDECRYPT                        (-451)  /* error secure level, decrypt recv packet fail */
247 #define SL_ESECCLOSED                         (-452)  /* secure layrer is closed by other size , tcp is still connected  */
248 #define SL_ESECSNOVERIFY                      (-453)  /* Connected without server verification */
249 #define SL_ESECNOCAFILE                       (-454)  /* error secure level CA file not found*/
250 #define SL_ESECMEMORY                         (-455)  /* error secure level No memory  space available */
251 #define SL_ESECBADCAFILE                      (-456)  /* error secure level bad CA file */
252 #define SL_ESECBADCERTFILE                    (-457)  /* error secure level bad Certificate file */
253 #define SL_ESECBADPRIVATEFILE                 (-458)  /* error secure level bad private file */
254 #define SL_ESECBADDHFILE                      (-459)  /* error secure level bad DH file */
255 #define SL_ESECT00MANYSSLOPENED               (-460)  /* MAX SSL Sockets are opened */
256 #define SL_ESECDATEERROR                      (-461)  /* connected with certificate date verification error */
257 #define SL_ESECHANDSHAKETIMEDOUT              (-462)  /* connection timed out due to handshake time */
258 
259 /* end error codes */
260 
261 /* Max payload size by protocol */
262 #define SL_SOCKET_PAYLOAD_TYPE_MASK            (0xF0)  /*4 bits type, 4 bits sockets id */
263 #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV4        (0x00)  /* 1472 bytes */
264 #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV4        (0x10)  /* 1460 bytes */
265 #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV6        (0x20)  /* 1452 bytes */
266 #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV6        (0x30)  /* 1440 bytes */
267 #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV4_SECURE (0x40)  /*            */
268 #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV4_SECURE (0x50)  /*            */
269 #define SL_SOCKET_PAYLOAD_TYPE_UDP_IPV6_SECURE (0x60)  /*            */
270 #define SL_SOCKET_PAYLOAD_TYPE_TCP_IPV6_SECURE (0x70)  /*            */
271 #define SL_SOCKET_PAYLOAD_TYPE_RAW_TRANCEIVER  (0x80)  /* 1536 bytes */
272 #define SL_SOCKET_PAYLOAD_TYPE_RAW_PACKET      (0x90)  /* 1536 bytes */
273 #define SL_SOCKET_PAYLOAD_TYPE_RAW_IP4         (0xa0)
274 #define SL_SOCKET_PAYLOAD_TYPE_RAW_IP6         (SL_SOCKET_PAYLOAD_TYPE_RAW_IP4 )
275 
276 
277 
278 #define SL_SOL_SOCKET          (1)   /* Define the socket option category. */
279 #define SL_IPPROTO_IP          (2)   /* Define the IP option category.     */
280 #define SL_SOL_PHY_OPT         (3)   /* Define the PHY option category.    */
281 
282 #define SL_SO_RCVBUF           (8)   /* Setting TCP receive buffer size */
283 #define SL_SO_KEEPALIVE        (9)   /* Connections are kept alive with periodic messages */
284 #define SL_SO_RCVTIMEO         (20)  /* Enable receive timeout */
285 #define SL_SO_NONBLOCKING      (24)  /* Enable . disable nonblocking mode  */
286 #define SL_SO_SECMETHOD        (25)  /* security metohd */
287 #define SL_SO_SECURE_MASK      (26)  /* security mask */
288 #define SL_SO_SECURE_FILES     (27)  /* security files */
289 #define SL_SO_CHANGE_CHANNEL   (28)  /* This option is available only when transceiver started */
290 #define SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME (30) /* This option used to configue secure file */
291 #define SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME (31) /* This option used to configue secure file */
292 #define SL_SO_SECURE_FILES_CA_FILE_NAME          (32) /* This option used to configue secure file */
293 #define SL_SO_SECURE_FILES_DH_KEY_FILE_NAME      (33) /* This option used to configue secure file */
294 
295 #define SL_IP_MULTICAST_IF     (60) /* Specify outgoing multicast interface */
296 #define SL_IP_MULTICAST_TTL    (61) /* Specify the TTL value to use for outgoing multicast packet. */
297 #define SL_IP_ADD_MEMBERSHIP   (65) /* Join IPv4 multicast membership */
298 #define SL_IP_DROP_MEMBERSHIP  (66) /* Leave IPv4 multicast membership */
299 #define SL_IP_HDRINCL          (67) /* Raw socket IPv4 header included. */
300 #define SL_IP_RAW_RX_NO_HEADER (68) /* Proprietary socket option that does not includeIPv4/IPv6 header (and extension headers) on received raw sockets*/
301 #define SL_IP_RAW_IPV6_HDRINCL (69) /* Transmitted buffer over IPv6 socket contains IPv6 header. */
302 
303 #define SL_SO_PHY_RATE              (100)   /* WLAN Transmit rate */
304 #define SL_SO_PHY_TX_POWER          (101)   /* TX Power level */
305 #define SL_SO_PHY_NUM_FRAMES_TO_TX  (102)   /* Number of frames to transmit */
306 #define SL_SO_PHY_PREAMBLE          (103)   /* Preamble for transmission */
307 
308 #define SL_SO_SEC_METHOD_SSLV3                             (0)  /* security metohd SSL v3*/
309 #define SL_SO_SEC_METHOD_TLSV1                             (1)  /* security metohd TLS v1*/
310 #define SL_SO_SEC_METHOD_TLSV1_1                           (2)  /* security metohd TLS v1_1*/
311 #define SL_SO_SEC_METHOD_TLSV1_2                           (3)  /* security metohd TLS v1_2*/
312 #define SL_SO_SEC_METHOD_SSLv3_TLSV1_2                     (4)  /* use highest possible version from SSLv3 - TLS 1.2*/
313 #define SL_SO_SEC_METHOD_DLSV1                             (5)  /* security metohd DTL v1  */
314 
315 #define SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA               (1 << 0)
316 #define SL_SEC_MASK_SSL_RSA_WITH_RC4_128_MD5               (1 << 1)
317 #define SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA           (1 << 2)
318 #define SL_SEC_MASK_TLS_DHE_RSA_WITH_AES_256_CBC_SHA       (1 << 3)
319 #define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA     (1 << 4)
320 #define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_RC4_128_SHA         (1 << 5)
321 #define SL_SEC_MASK_TLS_RSA_WITH_AES_128_CBC_SHA256              (1 << 6)
322 #define SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA256              (1 << 7)
323 #define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256        (1 << 8)
324 #define SL_SEC_MASK_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256      (1 << 9)
325 
326 
327 #define SL_SEC_MASK_SECURE_DEFAULT                         ((SL_SEC_MASK_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256  <<  1)  -  1)
328 
329 #define SL_MSG_DONTWAIT                                   (0x00000008)  /* Nonblocking IO */
330 
331 /* AP DHCP Server - IP Release reason code */
332 #define SL_IP_LEASE_PEER_RELEASE     (0)
333 #define SL_IP_LEASE_PEER_DECLINE     (1)
334 #define SL_IP_LEASE_EXPIRED          (2)
335 
336 /* possible types when receiving SL_SOCKET_ASYNC_EVENT*/
337 #define SSL_ACCEPT                                (1) /* accept failed due to ssl issue ( tcp pass) */
338 #define RX_FRAGMENTATION_TOO_BIG                  (2) /* connection less mode, rx packet fragmentation > 16K, packet is being released */
339 #define OTHER_SIDE_CLOSE_SSL_DATA_NOT_ENCRYPTED   (3) /* remote side down from secure to unsecure */
340 
341 
342 
343 #ifdef SL_INC_STD_BSD_API_NAMING
344 
345 #define FD_SETSIZE                          SL_FD_SETSIZE
346 
347 #define SOCK_STREAM                         SL_SOCK_STREAM
348 #define SOCK_DGRAM                          SL_SOCK_DGRAM
349 #define SOCK_RAW                            SL_SOCK_RAW
350 #define IPPROTO_TCP                         SL_IPPROTO_TCP
351 #define IPPROTO_UDP                         SL_IPPROTO_UDP
352 #define IPPROTO_RAW                         SL_IPPROTO_RAW
353 
354 #define AF_INET                             SL_AF_INET
355 #define AF_INET6                            SL_AF_INET6
356 #define AF_INET6_EUI_48                     SL_AF_INET6_EUI_48
357 #define AF_RF                               SL_AF_RF
358 #define AF_PACKET                           SL_AF_PACKET
359 
360 #define PF_INET                             SL_PF_INET
361 #define PF_INET6                            SL_PF_INET6
362 
363 #define INADDR_ANY                          SL_INADDR_ANY
364 #define ERROR                               SL_SOC_ERROR
365 #define INEXE                               SL_INEXE
366 #define EBADF                               SL_EBADF
367 #define ENSOCK                              SL_ENSOCK
368 #define EAGAIN                              SL_EAGAIN
369 #define EWOULDBLOCK                         SL_EWOULDBLOCK
370 #define ENOMEM                              SL_ENOMEM
371 #define EACCES                              SL_EACCES
372 #define EFAULT                              SL_EFAULT
373 #define EINVAL                              SL_EINVAL
374 #define EDESTADDRREQ                        SL_EDESTADDRREQ
375 #define EPROTOTYPE                          SL_EPROTOTYPE
376 #define ENOPROTOOPT                         SL_ENOPROTOOPT
377 #define EPROTONOSUPPORT                     SL_EPROTONOSUPPORT
378 #define ESOCKTNOSUPPORT                     SL_ESOCKTNOSUPPORT
379 #define EOPNOTSUPP                          SL_EOPNOTSUPP
380 #define EAFNOSUPPORT                        SL_EAFNOSUPPORT
381 #define EADDRINUSE                          SL_EADDRINUSE
382 #define EADDRNOTAVAIL                       SL_EADDRNOTAVAIL
383 #define ENETUNREACH                         SL_ENETUNREACH
384 #define ENOBUFS                             SL_ENOBUFS
385 #define EOBUFF                              SL_EOBUFF
386 #define EISCONN                             SL_EISCONN
387 #define ENOTCONN                            SL_ENOTCONN
388 #define ETIMEDOUT                           SL_ETIMEDOUT
389 #define ECONNREFUSED                        SL_ECONNREFUSED
390 
391 #define SOL_SOCKET                          SL_SOL_SOCKET
392 #define IPPROTO_IP                          SL_IPPROTO_IP
393 #define SO_KEEPALIVE                        SL_SO_KEEPALIVE
394 
395 #define SO_RCVTIMEO                         SL_SO_RCVTIMEO
396 #define SO_NONBLOCKING                      SL_SO_NONBLOCKING
397 
398 #define IP_MULTICAST_IF                     SL_IP_MULTICAST_IF
399 #define IP_MULTICAST_TTL                    SL_IP_MULTICAST_TTL
400 #define IP_ADD_MEMBERSHIP                   SL_IP_ADD_MEMBERSHIP
401 #define IP_DROP_MEMBERSHIP                  SL_IP_DROP_MEMBERSHIP
402 
403 #define socklen_t                           SlSocklen_t
404 #define timeval                             SlTimeval_t
405 #define sockaddr                            SlSockAddr_t
406 #define in6_addr                            SlIn6Addr_t
407 #define sockaddr_in6                        SlSockAddrIn6_t
408 #define in_addr                             SlInAddr_t
409 #define sockaddr_in                         SlSockAddrIn_t
410 
411 #define MSG_DONTWAIT                        SL_MSG_DONTWAIT
412 
413 #define FD_SET                              SL_FD_SET
414 #define FD_CLR                              SL_FD_CLR
415 #define FD_ISSET                            SL_FD_ISSET
416 #define FD_ZERO                             SL_FD_ZERO
417 #define fd_set                              SlFdSet_t
418 
419 #define socket                              sl_Socket
420 #define close                               sl_Close
421 #define accept                              sl_Accept
422 #define bind                                sl_Bind
423 #define listen                              sl_Listen
424 #define connect                             sl_Connect
425 #define select                              sl_Select
426 #define setsockopt                          sl_SetSockOpt
427 #define getsockopt                          sl_GetSockOpt
428 #define recv                                sl_Recv
429 #define recvfrom                            sl_RecvFrom
430 #define write                               sl_Write
431 #define send                                sl_Send
432 #define sendto                              sl_SendTo
433 #define gethostbyname                       sl_NetAppDnsGetHostByName
434 #define htonl                               sl_Htonl
435 #define ntohl                               sl_Ntohl
436 #define htons                               sl_Htons
437 #define ntohs                               sl_Ntohs
438 #endif
439 
440 /*****************************************************************************/
441 /* Structure/Enum declarations                                               */
442 /*****************************************************************************/
443 
444 /* Internet address   */
445 typedef struct SlInAddr_t
446 {
447 #ifndef s_addr
448     _u32           s_addr;             /* Internet address 32 bits */
449 #else
450     union S_un {
451        struct { _u8 s_b1,s_b2,s_b3,s_b4; } S_un_b;
452        struct { _u8 s_w1,s_w2; } S_un_w;
453         _u32 S_addr;
454     } S_un;
455 #endif
456 }SlInAddr_t;
457 
458 
459 /* sockopt */
460 typedef struct
461 {
462     _u32 KeepaliveEnabled; /* 0 = disabled;1 = enabled; default = 1*/
463 }SlSockKeepalive_t;
464 
465 typedef struct
466 {
467     _u32 ReuseaddrEnabled; /* 0 = disabled; 1 = enabled; default = 1*/
468 }SlSockReuseaddr_t;
469 
470 typedef struct
471 {
472     _u32 Winsize;          /* receive window size for tcp sockets  */
473 }SlSockWinsize_t;
474 
475 typedef struct
476 {
477     _u32 NonblockingEnabled;/* 0 = disabled;1 = enabled;default = 1*/
478 }SlSockNonblocking_t;
479 
480 
481 typedef struct
482 {
483   _u8   sd;
484   _u8   type;
485   _i16  val;
486   _u8*  pExtraInfo;
487 } SlSocketAsyncEvent_t;
488 
489 typedef struct
490 {
491   _i16       status;
492   _u8        sd;
493   _u8        padding;
494 } SlSockTxFailEventData_t;
495 
496 
497 typedef union
498 {
499   SlSockTxFailEventData_t   SockTxFailData;
500   SlSocketAsyncEvent_t      SockAsyncData;
501 } SlSockEventData_u;
502 
503 
504 typedef struct
505 {
506    _u32                    Event;
507    SlSockEventData_u       socketAsyncEvent;
508 } SlSockEvent_t;
509 
510 
511 
512 
513 
514 
515 typedef struct
516 {
517     _u32    secureMask;
518 } SlSockSecureMask;
519 
520 typedef struct
521 {
522     _u8     secureMethod;
523 } SlSockSecureMethod;
524 
525 typedef enum
526 {
527   SL_BSD_SECURED_PRIVATE_KEY_IDX = 0,
528   SL_BSD_SECURED_CERTIFICATE_IDX,
529   SL_BSD_SECURED_CA_IDX,
530   SL_BSD_SECURED_DH_IDX
531 }slBsd_secureSocketFilesIndex_e;
532 
533 typedef struct
534 {
535     SlInAddr_t   imr_multiaddr;     /* The IPv4 multicast address to join */
536     SlInAddr_t   imr_interface;     /* The interface to use for this group */
537 } SlSockIpMreq;
538 
539 
540 /* sockopt */
541 typedef _u32   SlTime_t;
542 typedef _u32   SlSuseconds_t;
543 
544 typedef struct SlTimeval_t
545 {
546     SlTime_t          tv_sec;             /* Seconds      */
547     SlSuseconds_t     tv_usec;            /* Microseconds */
548 }SlTimeval_t;
549 
550 typedef _u16 SlSocklen_t;
551 
552 /* IpV4 socket address */
553 typedef struct SlSockAddr_t
554 {
555     _u16          sa_family;     /* Address family (e.g. , AF_INET)     */
556     _u8           sa_data[14];  /* Protocol- specific address information*/
557 }SlSockAddr_t;
558 
559 
560 /* IpV6 or Ipv6 EUI64 */
561 typedef struct SlIn6Addr_t
562 {
563     union
564     {
565         _u8   _S6_u8[16];
566         _u32  _S6_u32[4];
567     } _S6_un;
568 }SlIn6Addr_t;
569 
570 typedef struct SlSockAddrIn6_t
571 {
572     _u16           sin6_family;                 /* AF_INET6 || AF_INET6_EUI_48*/
573     _u16           sin6_port;                   /* Transport layer port.  */
574     _u32           sin6_flowinfo;               /* IPv6 flow information. */
575     SlIn6Addr_t             sin6_addr;                   /* IPv6 address. */
576     _u32           sin6_scope_id;               /* set of interfaces for a scope. */
577 }SlSockAddrIn6_t;
578 
579 /* Socket address, Internet style. */
580 
581 typedef struct SlSockAddrIn_t
582 {
583     _u16              sin_family;         /* Internet Protocol (AF_INET).                    */
584     _u16              sin_port;           /* Address port (16 bits).                         */
585     SlInAddr_t                  sin_addr;           /* Internet address (32 bits).                     */
586     _i8               sin_zero[8];        /* Not used.                                       */
587 }SlSockAddrIn_t;
588 
589 typedef struct
590 {
591     _u32 ip;
592     _u32 gateway;
593     _u32 dns;
594 }SlIpV4AcquiredAsync_t;
595 
596 typedef struct
597 {
598     _u32 type;
599     _u32 ip[4];
600     _u32 gateway[4];
601     _u32 dns[4];
602 }SlIpV6AcquiredAsync_t;
603 
604 typedef struct
605 {
606    _u32    ip_address;
607    _u32    lease_time;
608    _u8     mac[6];
609    _u16    padding;
610 }SlIpLeasedAsync_t;
611 
612 typedef struct
613 {
614   _u32    ip_address;
615   _u8     mac[6];
616   _u16    reason;
617 }SlIpReleasedAsync_t;
618 
619 
620 typedef union
621 {
622   SlIpV4AcquiredAsync_t    ipAcquiredV4; /*SL_NETAPP_IPV4_IPACQUIRED_EVENT*/
623   SlIpV6AcquiredAsync_t    ipAcquiredV6; /*SL_NETAPP_IPV6_IPACQUIRED_EVENT*/
624   _u32                      sd;           /*SL_SOCKET_TX_FAILED_EVENT*/
625   SlIpLeasedAsync_t        ipLeased;     /* SL_NETAPP_IP_LEASED_EVENT   */
626   SlIpReleasedAsync_t      ipReleased;   /* SL_NETAPP_IP_RELEASED_EVENT */
627 } SlNetAppEventData_u;
628 
629 typedef struct
630 {
631    _u32                     Event;
632    SlNetAppEventData_u       EventData;
633 }SlNetAppEvent_t;
634 
635 
636 typedef struct sock_secureFiles
637 {
638     _u8                     secureFiles[4];
639 }SlSockSecureFiles_t;
640 
641 
642 typedef struct SlFdSet_t                    /* The select socket array manager */
643 {
644    _u32        fd_array[(SL_FD_SETSIZE + 31)/32]; /* Bit map of SOCKET Descriptors */
645 } SlFdSet_t;
646 
647 typedef struct
648 {
649     _u8   rate;               /* Recevied Rate  */
650     _u8   channel;            /* The received channel*/
651     _i8    rssi;               /* The computed RSSI value in db of current frame */
652     _u8   padding;                                           /* pad to align to 32 bits */
653     _u32  timestamp;          /* Timestamp in microseconds,     */
654 }SlTransceiverRxOverHead_t;
655 
656 
657 
658 /*****************************************************************************/
659 /* Function prototypes                                                       */
660 /*****************************************************************************/
661 
662 /*!
663 
664     \brief create an endpoint for communication
665 
666     The socket function creates a new socket of a certain socket type, identified
667     by an integer number, and allocates system resources to it.
668     This function is called by the application layer to obtain a socket handle.
669 
670     \param[in] domain           specifies the protocol family of the created socket.
671                                 For example:
672                                    AF_INET for network protocol IPv4
673                                    AF_RF for starting transceiver mode. Notes:
674                                    - sending and receiving any packet overriding 802.11 header
675                                    - for optimized power consumption the socket will be started in TX
676                                      only mode until receive command is activated
677                                    AF_INET6 for IPv6
678 
679 
680     \param[in] type              specifies the communication semantic, one of:
681                                    SOCK_STREAM (reliable stream-oriented service or Stream Sockets)
682                                    SOCK_DGRAM (datagram service or Datagram Sockets)
683                                    SOCK_RAW (raw protocols atop the network layer)
684                                    when used with AF_RF:
685                                                                      SOCK_DGRAM - L2 socket
686                                                                      SOCK_RAW - L1 socket - bypass WLAN CCA (Clear Channel Assessment)
687 
688     \param[in] protocol         specifies a particular transport to be used with
689                                 the socket.
690                                 The most common are IPPROTO_TCP, IPPROTO_SCTP, IPPROTO_UDP,
691                                 IPPROTO_DCCP.
692                                 The value 0 may be used to select a default
693                                 protocol from the selected domain and type
694 
695 
696     \return                     On success, socket handle that is used for consequent socket operations.
697                                 A successful return code should be a positive number (int16)
698                                 On error, a negative (int16) value will be returned specifying the error code.
699                            SL_EAFNOSUPPORT  - illegal domain parameter
700                            SL_EPROTOTYPE  - illegal type parameter
701                            SL_EACCES   - permission denied
702                            SL_ENSOCK  - exceeded maximal number of socket
703                            SL_ENOMEM  - memory allocation error
704                            SL_EINVAL  - error in socket configuration
705                            SL_EPROTONOSUPPORT  - illegal protocol parameter
706                            SL_EOPNOTSUPP  - illegal combination of protocol and type parameters
707 
708 
709     \sa                         sl_Close
710     \note                       belongs to \ref basic_api
711     \warning
712 */
713 #if _SL_INCLUDE_FUNC(sl_Socket)
714 _i16 sl_Socket(_i16 Domain, _i16 Type, _i16 Protocol);
715 #endif
716 
717 /*!
718     \brief gracefully close socket
719 
720     This function causes the system to release resources allocated to a socket.  \n
721     In case of TCP, the connection is terminated.
722 
723     \param[in] sd               socket handle (received in sl_Socket)
724 
725     \return                        On success, zero is returned.
726                                 On error, a negative number is returned.
727 
728     \sa                         sl_Socket
729     \note                       belongs to \ref ext_api
730     \warning
731 */
732 #if _SL_INCLUDE_FUNC(sl_Close)
733 _i16 sl_Close(_i16 sd);
734 #endif
735 
736 /*!
737     \brief Accept a connection on a socket
738 
739     This function is used with connection-based socket types (SOCK_STREAM).
740     It extracts the first connection request on the queue of pending
741     connections, creates a new connected socket, and returns a new file
742     descriptor referring to that socket.
743     The newly created socket is not in the listening state. The
744     original socket sd is unaffected by this call.
745     The argument sd is a socket that has been created with
746     sl_Socket(), bound to a local address with sl_Bind(), and is
747     listening for connections after a sl_Listen(). The argument \b
748     \e addr is a pointer to a sockaddr structure. This structure
749     is filled in with the address of the peer socket, as known to
750     the communications layer. The exact format of the address
751     returned addr is determined by the socket's address family.
752     The \b \e addrlen argument is a value-result argument: it
753     should initially contain the size of the structure pointed to
754     by addr, on return it will contain the actual length (in
755     bytes) of the address returned.
756 
757     \param[in] sd               socket descriptor (handle)
758     \param[out] addr            the argument addr is a pointer
759                                 to a sockaddr structure. This
760                                 structure is filled in with the
761                                 address of the peer socket, as
762                                 known to the communications
763                                 layer. The exact format of the
764                                 address returned addr is
765                                 determined by the socket's
766                                 address\n
767                                 sockaddr:\n - code for the
768                                 address format. On this version
769                                 only AF_INET is supported.\n -
770                                 socket address, the length
771                                 depends on the code format
772     \param[out] addrlen         the addrlen argument is a value-result
773                                 argument: it should initially contain the
774                                 size of the structure pointed to by addr
775 
776     \return                        On success, a socket handle.
777                                 On a non-blocking accept a possible negative value is SL_EAGAIN.
778                                 On failure, negative value.
779                                 SL_POOL_IS_EMPTY may be return in case there are no resources in the system
780                                  In this case try again later or increase MAX_CONCURRENT_ACTIONS
781 
782     \sa                         sl_Socket  sl_Bind  sl_Listen
783     \note                       belongs to \ref server_side
784     \warning
785 */
786 #if _SL_INCLUDE_FUNC(sl_Accept)
787 _i16 sl_Accept(_i16 sd, SlSockAddr_t *addr, SlSocklen_t *addrlen);
788 #endif
789 
790 /*!
791     \brief assign a name to a socket
792 
793     This function gives the socket the local address addr.
794     addr is addrlen bytes long. Traditionally, this is called
795     When a socket is created with socket, it exists in a name
796     space (address family) but has no name assigned.
797     It is necessary to assign a local address before a SOCK_STREAM
798     socket may receive connections.
799 
800     \param[in] sd                socket descriptor (handle)
801     \param[in] addr              specifies the destination
802                                 addrs\n sockaddr:\n - code for
803                                 the address format. On this
804                                 version only AF_INET is
805                                 supported.\n - socket address,
806                                 the length depends on the code
807                                 format
808     \param[in] addrlen          contains the size of the structure pointed to by addr
809 
810     \return                        On success, zero is returned. On error, a negative error code is returned.
811 
812     \sa                         sl_Socket  sl_Accept sl_Listen
813     \note                       belongs to \ref basic_api
814     \warning
815 */
816 #if _SL_INCLUDE_FUNC(sl_Bind)
817 _i16 sl_Bind(_i16 sd, const SlSockAddr_t *addr, _i16 addrlen);
818 #endif
819 
820 /*!
821     \brief listen for connections on a socket
822 
823     The willingness to accept incoming connections and a queue
824     limit for incoming connections are specified with listen(),
825     and then the connections are accepted with accept.
826     The listen() call applies only to sockets of type SOCK_STREAM
827     The backlog parameter defines the maximum length the queue of
828     pending connections may grow to.
829 
830     \param[in] sd               socket descriptor (handle)
831     \param[in] backlog          specifies the listen queue depth.
832 
833 
834     \return                    On success, zero is returned. On error, a negative error code is returned.
835 
836     \sa                         sl_Socket  sl_Accept  sl_Bind
837     \note                       belongs to \ref server_side
838     \warning
839 */
840 #if _SL_INCLUDE_FUNC(sl_Listen)
841 _i16 sl_Listen(_i16 sd, _i16 backlog);
842 #endif
843 
844 /*!
845     \brief Initiate a connection on a socket
846 
847     Function connects the socket referred to by the socket
848     descriptor sd, to the address specified by addr. The addrlen
849     argument specifies the size of addr. The format of the
850     address in addr is determined by the address space of the
851     socket. If it is of type SOCK_DGRAM, this call specifies the
852     peer with which the socket is to be associated; this address
853     is that to which datagrams are to be sent, and the only
854     address from which datagrams are to be received.  If the
855     socket is of type SOCK_STREAM, this call attempts to make a
856     connection to another socket. The other socket is specified
857     by address, which is an address in the communications space
858     of the socket.
859 
860 
861     \param[in] sd               socket descriptor (handle)
862     \param[in] addr             specifies the destination addr\n
863                                 sockaddr:\n - code for the
864                                 address format. On this version
865                                 only AF_INET is supported.\n -
866                                 socket address, the length
867                                 depends on the code format
868 
869     \param[in] addrlen          contains the size of the structure pointed
870                                 to by addr
871 
872     \return                     On success, a socket handle.
873                                 On a non-blocking connect a possible negative value is SL_EALREADY.
874                                 On failure, negative value.
875                                 SL_POOL_IS_EMPTY may be return in case there are no resources in the system
876                                   In this case try again later or increase MAX_CONCURRENT_ACTIONS
877 
878     \sa                         sl_Socket
879     \note                       belongs to \ref client_side
880     \warning
881 */
882 #if _SL_INCLUDE_FUNC(sl_Connect)
883 _i16 sl_Connect(_i16 sd, const SlSockAddr_t *addr, _i16 addrlen);
884 #endif
885 
886 /*!
887     \brief Monitor socket activity
888 
889     Select allow a program to monitor multiple file descriptors,
890     waiting until one or more of the file descriptors become
891     "ready" for some class of I/O operation
892 
893 
894     \param[in]  nfds        the highest-numbered file descriptor in any of the
895                             three sets, plus 1.
896     \param[out] readsds     socket descriptors list for read monitoring and accept monitoring
897     \param[out] writesds    socket descriptors list for connect monitoring only, write monitoring is not supported, non blocking connect is supported
898     \param[out] exceptsds   socket descriptors list for exception monitoring, not supported.
899     \param[in]  timeout     is an upper bound on the amount of time elapsed
900                             before select() returns. Null or above 0xffff seconds means
901                             infinity timeout. The minimum timeout is 10 milliseconds,
902                             less than 10 milliseconds will be set automatically to 10 milliseconds.
903                             Max microseconds supported is 0xfffc00.
904 
905     \return                    On success, select()  returns the number of
906                             file descriptors contained in the three returned
907                             descriptor sets (that is, the total number of bits that
908                             are set in readfds, writefds, exceptfds) which may be
909                             zero if the timeout expires before anything interesting
910                             happens. On error, a negative value is returned.
911                             readsds - return the sockets on which Read request will
912                             return without delay with valid data.
913                             writesds - return the sockets on which Write request
914                             will return without delay.
915                             exceptsds - return the sockets closed recently.
916                             SL_POOL_IS_EMPTY may be return in case there are no resources in the system
917                                In this case try again later or increase MAX_CONCURRENT_ACTIONS
918 
919     \sa     sl_Socket
920     \note   If the timeout value set to less than 5ms it will automatically set
921             to 5ms to prevent overload of the system
922             belongs to \ref basic_api
923 
924             Only one sl_Select can be handled at a time.
925             Calling this API while the same command is called from another thread, may result
926                 in one of the two scenarios:
927             1. The command will wait (internal) until the previous command finish, and then be executed.
928             2. There are not enough resources and SL_POOL_IS_EMPTY error will return.
929             In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try
930             again later to issue the command.
931 
932     \warning
933 */
934 #if _SL_INCLUDE_FUNC(sl_Select)
935 _i16 sl_Select(_i16 nfds, SlFdSet_t *readsds, SlFdSet_t *writesds, SlFdSet_t *exceptsds, struct SlTimeval_t *timeout);
936 
937 
938 /*!
939     \brief Select's SlFdSet_t SET function
940 
941     Sets current socket descriptor on SlFdSet_t container
942 */
943 void SL_FD_SET(_i16 fd, SlFdSet_t *fdset);
944 
945 /*!
946     \brief Select's SlFdSet_t CLR function
947 
948     Clears current socket descriptor on SlFdSet_t container
949 */
950 void SL_FD_CLR(_i16 fd, SlFdSet_t *fdset);
951 
952 
953 /*!
954     \brief Select's SlFdSet_t ISSET function
955 
956     Checks if current socket descriptor is set (TRUE/FALSE)
957 
958     \return            Returns TRUE if set, FALSE if unset
959 
960 */
961 _i16  SL_FD_ISSET(_i16 fd, SlFdSet_t *fdset);
962 
963 /*!
964     \brief Select's SlFdSet_t ZERO function
965 
966     Clears all socket descriptors from SlFdSet_t
967 */
968 void SL_FD_ZERO(SlFdSet_t *fdset);
969 
970 
971 
972 #endif
973 
974 /*!
975     \brief set socket options
976 
977     This function manipulate the options associated with a socket.
978     Options may exist at multiple protocol levels; they are always
979     present at the uppermost socket level.
980 
981     When manipulating socket options the level at which the option resides
982     and the name of the option must be specified.  To manipulate options at
983     the socket level, level is specified as SOL_SOCKET.  To manipulate
984     options at any other level the protocol number of the appropriate proto-
985     col controlling the option is supplied.  For example, to indicate that an
986     option is to be interpreted by the TCP protocol, level should be set to
987     the protocol number of TCP;
988 
989     The parameters optval and optlen are used to access optval -
990     ues for setsockopt().  For getsockopt() they identify a
991     buffer in which the value for the requested option(s) are to
992     be returned.  For getsockopt(), optlen is a value-result
993     parameter, initially containing the size of the buffer
994     pointed to by option_value, and modified on return to
995     indicate the actual size of the value returned.  If no option
996     value is to be supplied or returned, option_value may be
997     NULL.
998 
999     \param[in] sd               socket handle
1000     \param[in] level            defines the protocol level for this option
1001                                 - <b>SL_SOL_SOCKET</b>   Socket level configurations (L4, transport layer)
1002                                 - <b>SL_IPPROTO_IP</b>   IP level configurations (L3, network layer)
1003                                 - <b>SL_SOL_PHY_OPT</b>  Link level configurations (L2, link layer)
1004     \param[in] optname          defines the option name to interrogate
1005                                 - <b>SL_SOL_SOCKET</b>
1006                                   - <b>SL_SO_KEEPALIVE</b>  \n
1007                                                  Enable/Disable periodic keep alive.
1008                                                  Keeps TCP connections active by enabling the periodic transmission of messages \n
1009                                                  Timeout is 5 minutes.\n
1010                                                  Default: Enabled \n
1011                                                  This options takes SlSockKeepalive_t struct as parameter
1012                                   - <b>SL_SO_RCVTIMEO</b>  \n
1013                                                  Sets the timeout value that specifies the maximum amount of time an input function waits until it completes. \n
1014                                                  Default: No timeout \n
1015                                                  This options takes SlTimeval_t struct as parameter
1016                                   - <b>SL_SO_RCVBUF</b>  \n
1017                                                  Sets tcp max recv window size. \n
1018                                                  This options takes SlSockWinsize_t struct as parameter
1019                                   - <b>SL_SO_NONBLOCKING</b> \n
1020                                                  Sets socket to non-blocking operation Impacts: connect, accept, send, sendto, recv and recvfrom. \n
1021                                                  Default: Blocking.
1022                                                  This options takes SlSockNonblocking_t struct as parameter
1023                                   - <b>SL_SO_SECMETHOD</b> \n
1024                                                  Sets method to tcp secured socket (SL_SEC_SOCKET) \n
1025                                                  Default: SL_SO_SEC_METHOD_SSLv3_TLSV1_2 \n
1026                                                  This options takes SlSockSecureMethod struct as parameter
1027                                   - <b>SL_SO_SEC_MASK</b> \n
1028                                                  Sets specific cipher to tcp secured socket (SL_SEC_SOCKET) \n
1029                                                  Default: "Best" cipher suitable to method \n
1030                                                  This options takes SlSockSecureMask struct as parameter
1031                                   - <b>SL_SO_SECURE_FILES_CA_FILE_NAME</b> \n
1032                                                  Map secured socket to CA file by name \n
1033                                                  This options takes <b>_u8</b> buffer as parameter
1034                                   - <b>SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME</b> \n
1035                                                  Map secured socket to private key by name \n
1036                                                  This options takes <b>_u8</b> buffer as parameter
1037                                   - <b>SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME</b> \n
1038                                                  Map secured socket to certificate file by name \n
1039                                                  This options takes <b>_u8</b> buffer as parameter
1040                                   - <b>SL_SO_SECURE_FILES_DH_KEY_FILE_NAME</b> \n
1041                                                  Map secured socket to Diffie Hellman file by name \n
1042                                                  This options takes <b>_u8</b> buffer as parameter
1043                                   - <b>SL_SO_CHANGE_CHANNEL</b> \n
1044                                                  Sets channel in transceiver mode.
1045                                                  This options takes <b>_u32</b> as channel number parameter
1046                                 - <b>SL_IPPROTO_IP</b>
1047                                   - <b>SL_IP_MULTICAST_TTL</b> \n
1048                                                  Set the time-to-live value of outgoing multicast packets for this socket. \n
1049                                                  This options takes <b>_u8</b> as parameter
1050                                   - <b>SL_IP_ADD_MEMBERSHIP</b> \n
1051                                                  UDP socket, Join a multicast group. \n
1052                                                  This options takes SlSockIpMreq struct as parameter
1053                                   - <b>SL_IP_DROP_MEMBERSHIP</b> \n
1054                                                  UDP socket, Leave a multicast group \n
1055                                                  This options takes SlSockIpMreq struct as parameter
1056                                   - <b>SL_IP_RAW_RX_NO_HEADER</b> \n
1057                                                  Raw socket remove IP header from received data. \n
1058                                                  Default: data includes ip header \n
1059                                                  This options takes <b>_u32</b> as parameter
1060                                   - <b>SL_IP_HDRINCL</b> \n
1061                                                  RAW socket only, the IPv4 layer generates an IP header when sending a packet unless \n
1062                                                  the IP_HDRINCL socket option is enabled on the socket.    \n
1063                                                  When it is enabled, the packet must contain an IP header. \n
1064                                                  Default: disabled, IPv4 header generated by Network Stack \n
1065                                                  This options takes <b>_u32</b> as parameter
1066                                   - <b>SL_IP_RAW_IPV6_HDRINCL</b> (inactive) \n
1067                                                  RAW socket only, the IPv6 layer generates an IP header when sending a packet unless \n
1068                                                  the IP_HDRINCL socket option is enabled on the socket. When it is enabled, the packet must contain an IP header \n
1069                                                  Default: disabled, IPv4 header generated by Network Stack \n
1070                                                  This options takes <b>_u32</b> as parameter
1071                                 - <b>SL_SOL_PHY_OPT</b>
1072                                   - <b>SL_SO_PHY_RATE</b> \n
1073                                                  RAW socket, set WLAN PHY transmit rate \n
1074                                                  The values are based on RateIndex_e    \n
1075                                                  This options takes <b>_u32</b> as parameter
1076                                   - <b>SL_SO_PHY_TX_POWER</b> \n
1077                                                  RAW socket, set WLAN PHY TX power \n
1078                                                  Valid rage is 1-15 \n
1079                                                  This options takes <b>_u32</b> as parameter
1080                                   - <b>SL_SO_PHY_NUM_FRAMES_TO_TX</b> \n
1081                                                  RAW socket, set number of frames to transmit in transceiver mode.
1082                                                  Default: 1 packet
1083                                                  This options takes <b>_u32</b> as parameter
1084                                   - <b>SL_SO_PHY_PREAMBLE</b> \n
1085                                                  RAW socket, set WLAN PHY preamble for Long/Short\n
1086                                                  This options takes <b>_u32</b> as parameter
1087 
1088     \param[in] optval           specifies a value for the option
1089     \param[in] optlen           specifies the length of the
1090         option value
1091 
1092     \return                     On success, zero is returned.
1093                                 On error, a negative value is returned.
1094     \sa     sl_getsockopt
1095     \note   belongs to \ref basic_api
1096     \warning
1097     \par   Examples:
1098     \par
1099     <b> SL_SO_KEEPALIVE: </b>(disable Keepalive)
1100     \code
1101            SlSockKeepalive_t enableOption;
1102            enableOption.KeepaliveEnabled = 0;
1103            sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_KEEPALIVE, (_u8 *)&enableOption,sizeof(enableOption));
1104     \endcode
1105     \par
1106     <b> SL_SO_RCVTIMEO: </b>
1107     \code
1108            struct SlTimeval_t timeVal;
1109            timeVal.tv_sec =  1;             // Seconds
1110            timeVal.tv_usec = 0;             // Microseconds. 10000 microseconds resolution
1111            sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_RCVTIMEO, (_u8 *)&timeVal, sizeof(timeVal));    // Enable receive timeout
1112     \endcode
1113     \par
1114     <b>    SL_SO_RCVBUF: </b>
1115     \code
1116            SlSockWinsize_t size;
1117            size.Winsize = 3000;  // bytes
1118            sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_RCVBUF, (_u8 *)&size, sizeof(size));
1119     \endcode
1120     \par
1121     <b>    SL_SO_NONBLOCKING: </b>
1122     \code
1123            SlSockNonblocking_t enableOption;
1124            enableOption.NonblockingEnabled = 1;
1125            sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_NONBLOCKING, (_u8 *)&enableOption,sizeof(enableOption)); // Enable/disable nonblocking mode
1126     \endcode
1127     \par
1128     <b>    SL_SO_SECMETHOD:</b>
1129     \code
1130            SlSockSecureMethod method;
1131            method.secureMethod = SL_SO_SEC_METHOD_SSLV3;                                 // security method we want to use
1132            SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET);
1133            sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SECMETHOD, (_u8 *)&method, sizeof(method));
1134     \endcode
1135     \par
1136     <b>   SL_SO_SECURE_MASK:</b>
1137     \code
1138            SlSockSecureMask cipher;
1139            cipher.secureMask = SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA;                   // cipher type
1140            SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET);
1141            sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SEC_MASK,(_u8 *)&cipher, sizeof(cipher));
1142     \endcode
1143     \par
1144     <b>   SL_SO_SECURE_FILES_CA_FILE_NAME:</b>
1145     \code
1146            sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CA_FILE_NAME,"exuifaxCaCert.der",strlen("exuifaxCaCert.der"));
1147      \endcode
1148 
1149    \par
1150     <b>   SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME:</b>
1151      \code
1152            sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME,"myPrivateKey.der",strlen("myPrivateKey.der"));
1153      \endcode
1154 
1155    \par
1156     <b>   SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME:</b>
1157      \code
1158            sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME,"myCertificate.der",strlen("myCertificate.der"));
1159      \endcode
1160 
1161    \par
1162     <b>   SL_SO_SECURE_FILES_DH_KEY_FILE_NAME:</b>
1163      \code
1164            sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_DH_KEY_FILE_NAME,"myDHinServerMode.der",strlen("myDHinServerMode.der"));
1165      \endcode
1166 
1167    \par
1168     <b>   SL_IP_MULTICAST_TTL:</b>
1169      \code
1170            _u8 ttl = 20;
1171            sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_MULTICAST_TTL, &ttl, sizeof(ttl));
1172      \endcode
1173 
1174    \par
1175     <b>   SL_IP_ADD_MEMBERSHIP:</b>
1176      \code
1177            SlSockIpMreq mreq;
1178            sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
1179     \endcode
1180 
1181    \par
1182     <b>   SL_IP_DROP_MEMBERSHIP:</b>
1183     \code
1184            SlSockIpMreq mreq;
1185            sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
1186     \endcode
1187 
1188    \par
1189     <b>   SL_SO_CHANGE_CHANNEL:</b>
1190     \code
1191           _u32 newChannel = 6; // range is 1-13
1192           sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_CHANGE_CHANNEL, &newChannel, sizeof(newChannel));
1193     \endcode
1194 
1195     \par
1196     <b>   SL_IP_RAW_RX_NO_HEADER:</b>
1197     \code
1198           _u32 header = 1;  // remove ip header
1199           sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_RAW_RX_NO_HEADER, &header, sizeof(header));
1200     \endcode
1201 
1202    \par
1203     <b>   SL_IP_HDRINCL:</b>
1204     \code
1205          _u32 header = 1;
1206          sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_HDRINCL, &header, sizeof(header));
1207     \endcode
1208    \par
1209     <b>   SL_IP_RAW_IPV6_HDRINCL:</b>
1210     \code
1211           _u32 header = 1;
1212           sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_RAW_IPV6_HDRINCL, &header, sizeof(header));
1213     \endcode
1214 
1215    \par
1216     <b>   SL_SO_PHY_RATE:</b>
1217     \code
1218           _u32 rate = 6; // see wlan.h RateIndex_e for values
1219           sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_RATE, &rate, sizeof(rate));
1220     \endcode
1221 
1222    \par
1223     <b>   SL_SO_PHY_TX_POWER:</b>
1224     \code
1225           _u32 txpower = 1; // valid range is 1-15
1226           sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_TX_POWER, &txpower, sizeof(txpower));
1227     \endcode
1228 
1229    \par
1230     <b>   SL_SO_PHY_NUM_FRAMES_TO_TX:</b>
1231     \code
1232      	  _u32 numframes = 1;
1233           sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_NUM_FRAMES_TO_TX, &numframes, sizeof(numframes));
1234     \endcode
1235 
1236    \par
1237     <b>   SL_SO_PHY_PREAMBLE:</b>
1238     \code
1239           _u32 preamble = 1;
1240           sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_PREAMBLE, &preamble, sizeof(preamble));
1241     \endcode
1242 
1243 */
1244 #if _SL_INCLUDE_FUNC(sl_SetSockOpt)
1245 _i16 sl_SetSockOpt(_i16 sd, _i16 level, _i16 optname, const void *optval, SlSocklen_t optlen);
1246 #endif
1247 
1248 /*!
1249     \brief Get socket options
1250 
1251     This function manipulate the options associated with a socket.
1252     Options may exist at multiple protocol levels; they are always
1253     present at the uppermost socket level.
1254 
1255     When manipulating socket options the level at which the option resides
1256     and the name of the option must be specified.  To manipulate options at
1257     the socket level, level is specified as SOL_SOCKET.  To manipulate
1258     options at any other level the protocol number of the appropriate proto-
1259     col controlling the option is supplied.  For example, to indicate that an
1260     option is to be interpreted by the TCP protocol, level should be set to
1261     the protocol number of TCP;
1262 
1263     The parameters optval and optlen are used to access optval -
1264     ues for setsockopt().  For getsockopt() they identify a
1265     buffer in which the value for the requested option(s) are to
1266     be returned.  For getsockopt(), optlen is a value-result
1267     parameter, initially containing the size of the buffer
1268     pointed to by option_value, and modified on return to
1269     indicate the actual size of the value returned.  If no option
1270     value is to be supplied or returned, option_value may be
1271     NULL.
1272 
1273 
1274     \param[in]  sd              socket handle
1275     \param[in]  level           defines the protocol level for this option
1276     \param[in]  optname         defines the option name to interrogate
1277     \param[out] optval          specifies a value for the option
1278     \param[out] optlen          specifies the length of the
1279                                 option value
1280 
1281     \return                        On success, zero is returned.
1282                                 On error, a negative value is returned.
1283     \sa     sl_SetSockOpt
1284     \note   See sl_SetSockOpt
1285             belongs to \ref ext_api
1286     \warning
1287 */
1288 #if _SL_INCLUDE_FUNC(sl_GetSockOpt)
1289 _i16 sl_GetSockOpt(_i16 sd, _i16 level, _i16 optname, void *optval, SlSocklen_t *optlen);
1290 #endif
1291 
1292 /*!
1293     \brief read data from TCP socket
1294 
1295     function receives a message from a connection-mode socket
1296 
1297     \param[in]  sd              socket handle
1298     \param[out] buf             Points to the buffer where the
1299                                 message should be stored.
1300     \param[in]  Len             Specifies the length in bytes of
1301                                 the buffer pointed to by the buffer argument.
1302                                 Range: 1-16000 bytes
1303     \param[in]  flags           Specifies the type of message
1304                                 reception. On this version, this parameter is not
1305                                 supported.
1306 
1307     \return                     return the number of bytes received,
1308                                 or a negative value if an error occurred.
1309                                 using a non-blocking recv a possible negative value is SL_EAGAIN.
1310                                 SL_POOL_IS_EMPTY may be return in case there are no resources in the system
1311                                  In this case try again later or increase MAX_CONCURRENT_ACTIONS
1312 
1313     \sa     sl_RecvFrom
1314     \note                       belongs to \ref recv_api
1315     \warning
1316     \par        Examples:
1317     \code       An example of receiving data using TCP socket:
1318 
1319                 SlSockAddrIn_t  Addr;
1320                 SlSockAddrIn_t  LocalAddr;
1321                 _i16 AddrSize = sizeof(SlSockAddrIn_t);
1322                 _i16 SockID, newSockID;
1323                 _i16 Status;
1324                 _i8 Buf[RECV_BUF_LEN];
1325 
1326                 LocalAddr.sin_family = SL_AF_INET;
1327                 LocalAddr.sin_port = sl_Htons(5001);
1328                 LocalAddr.sin_addr.s_addr = 0;
1329 
1330                 Addr.sin_family = SL_AF_INET;
1331                 Addr.sin_port = sl_Htons(5001);
1332                 Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
1333 
1334                 SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
1335                 Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
1336                 Status = sl_Listen(SockID, 0);
1337                 newSockID = sl_Accept(SockID, (SlSockAddr_t*)&Addr, (SlSocklen_t*) &AddrSize);
1338                 Status = sl_Recv(newSockID, Buf, 1460, 0);
1339     \endcode
1340     \code      Example code for Rx transceiver mode using a raw socket
1341                _i8 buffer[1536];
1342                _i16 sd;
1343                _u16 size;
1344                SlTransceiverRxOverHead_t *transHeader;
1345                sd = sl_Socket(SL_AF_RF,SL_SOCK_RAW,11); // channel 11
1346                while(1)
1347                {
1348                   size = sl_Recv(sd,buffer,1536,0);
1349                   transHeader = (SlTransceiverRxOverHead_t *)buffer;
1350                   printf("RSSI is %d frame type is 0x%x size %d\n",transHeader->rssi,buffer[sizeof(SlTransceiverRxOverHead_t)],size);
1351                }
1352     \endcode
1353 */
1354 #if _SL_INCLUDE_FUNC(sl_Recv)
1355 _i16 sl_Recv(_i16 sd, void *buf, _i16 Len, _i16 flags);
1356 #endif
1357 
1358 /*!
1359     \brief read data from socket
1360 
1361     function receives a message from a connection-mode or
1362     connectionless-mode socket
1363 
1364     \param[in]  sd              socket handle
1365     \param[out] buf             Points to the buffer where the message should be stored.
1366     \param[in]  Len             Specifies the length in bytes of the buffer pointed to by the buffer argument.
1367                                 Range: 1-16000 bytes
1368     \param[in]  flags           Specifies the type of message
1369                                 reception. On this version, this parameter is not
1370                                 supported.
1371     \param[in]  from            pointer to an address structure
1372                                 indicating the source
1373                                 address.\n sockaddr:\n - code
1374                                 for the address format. On this
1375                                 version only AF_INET is
1376                                 supported.\n - socket address,
1377                                 the length depends on the code
1378                                 format
1379     \param[in]  fromlen         source address structure
1380                                 size. This parameter MUST be set to the size of the structure pointed to by addr.
1381 
1382 
1383     \return                     return the number of bytes received,
1384                                 or a negative value if an error occurred.
1385                                 using a non-blocking recv a possible negative value is SL_EAGAIN.
1386                                 SL_RET_CODE_INVALID_INPUT (-2) will be returned if fromlen has incorrect length.
1387                                 SL_POOL_IS_EMPTY may be return in case there are no resources in the system
1388                                  In this case try again later or increase MAX_CONCURRENT_ACTIONS
1389 
1390     \sa     sl_Recv
1391     \note                       belongs to \ref recv_api
1392     \warning
1393     \par        Example:
1394     \code       An example of receiving data:
1395 
1396                 SlSockAddrIn_t  Addr;
1397                 SlSockAddrIn_t  LocalAddr;
1398                 _i16 AddrSize = sizeof(SlSockAddrIn_t);
1399                 _i16 SockID;
1400                 _i16 Status;
1401                 _i8 Buf[RECV_BUF_LEN];
1402 
1403                 LocalAddr.sin_family = SL_AF_INET;
1404                 LocalAddr.sin_port = sl_Htons(5001);
1405                 LocalAddr.sin_addr.s_addr = 0;
1406 
1407                 SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
1408                 Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
1409                 Status = sl_RecvFrom(SockID, Buf, 1472, 0, (SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize);
1410 
1411     \endcode
1412 */
1413 #if _SL_INCLUDE_FUNC(sl_RecvFrom)
1414 _i16 sl_RecvFrom(_i16 sd, void *buf, _i16 Len, _i16 flags, SlSockAddr_t *from, SlSocklen_t *fromlen);
1415 #endif
1416 
1417 /*!
1418     \brief write data to TCP socket
1419 
1420     This function is used to transmit a message to another socket.
1421     Returns immediately after sending data to device.
1422     In case of TCP failure an async event SL_SOCKET_TX_FAILED_EVENT is going to
1423     be received.
1424     In case of a RAW socket (transceiver mode), extra 4 bytes should be reserved at the end of the
1425     frame data buffer for WLAN FCS
1426 
1427     \param[in] sd               socket handle
1428     \param[in] buf              Points to a buffer containing
1429                                 the message to be sent
1430     \param[in] Len              message size in bytes. Range: 1-1460 bytes
1431     \param[in] flags            Specifies the type of message
1432                                 transmission. On this version, this parameter is not
1433                                 supported for TCP.
1434                                 For transceiver mode, the SL_RAW_RF_TX_PARAMS macro can be used to determine
1435                                 transmission parameters (channel,rate,tx_power,preamble)
1436 
1437 
1438     \return                     Return the number of bytes transmitted,
1439                                 or -1 if an error occurred
1440 
1441     \sa     sl_SendTo
1442     \note                       belongs to \ref send_api
1443     \warning
1444     \par        Example:
1445     \code       An example of sending data:
1446 
1447                 SlSockAddrIn_t  Addr;
1448                 _i16 AddrSize = sizeof(SlSockAddrIn_t);
1449                 _i16 SockID;
1450                 _i16 Status;
1451                 _i8 Buf[SEND_BUF_LEN];
1452 
1453                 Addr.sin_family = SL_AF_INET;
1454                 Addr.sin_port = sl_Htons(5001);
1455                 Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
1456 
1457                 SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
1458                 Status = sl_Connect(SockID, (SlSockAddr_t *)&Addr, AddrSize);
1459                 Status = sl_Send(SockID, Buf, 1460, 0 );
1460 
1461     \endcode
1462  */
1463 #if _SL_INCLUDE_FUNC(sl_Send )
1464 _i16 sl_Send(_i16 sd, const void *buf, _i16 Len, _i16 flags);
1465 #endif
1466 
1467 /*!
1468     \brief write data to socket
1469 
1470     This function is used to transmit a message to another socket
1471     (connection less socket SOCK_DGRAM,  SOCK_RAW).
1472     Returns immediately after sending data to device.
1473     In case of transmission failure an async event SL_SOCKET_TX_FAILED_EVENT is going to
1474     be received.
1475 
1476     \param[in] sd               socket handle
1477     \param[in] buf              Points to a buffer containing
1478                                 the message to be sent
1479     \param[in] Len              message size in bytes. Range: 1-1460 bytes
1480     \param[in] flags            Specifies the type of message
1481                                 transmission. On this version, this parameter is not
1482                                 supported
1483     \param[in] to               pointer to an address structure
1484                                 indicating the destination
1485                                 address.\n sockaddr:\n - code
1486                                 for the address format. On this
1487                                 version only AF_INET is
1488                                 supported.\n - socket address,
1489                                 the length depends on the code
1490                                 format
1491     \param[in] tolen            destination address structure size
1492 
1493     \return                     Return the number of transmitted bytes,
1494                                 or -1 if an error occurred
1495 
1496     \sa     sl_Send
1497     \note                       belongs to \ref send_api
1498     \warning
1499     \par        Example:
1500     \code       An example of sending data:
1501 
1502                 SlSockAddrIn_t  Addr;
1503                 _i16 AddrSize = sizeof(SlSockAddrIn_t);
1504                 _i16 SockID;
1505                 _i16 Status;
1506                 _i8 Buf[SEND_BUF_LEN];
1507 
1508                 Addr.sin_family = SL_AF_INET;
1509                 Addr.sin_port = sl_Htons(5001);
1510                 Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
1511 
1512                 SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
1513                 Status = sl_SendTo(SockID, Buf, 1472, 0, (SlSockAddr_t *)&Addr, AddrSize);
1514 
1515     \endcode
1516 */
1517 #if _SL_INCLUDE_FUNC(sl_SendTo)
1518 _i16 sl_SendTo(_i16 sd, const void *buf, _i16 Len, _i16 flags, const SlSockAddr_t *to, SlSocklen_t tolen);
1519 #endif
1520 
1521 /*!
1522     \brief Reorder the bytes of a 32-bit unsigned value
1523 
1524     This function is used to Reorder the bytes of a 32-bit unsigned value from processor order to network order.
1525 
1526     \param[in] var              variable to reorder
1527 
1528     \return                     Return the reorder variable,
1529 
1530     \sa     sl_SendTo  sl_Bind  sl_Connect  sl_RecvFrom  sl_Accept
1531     \note                       belongs to \ref send_api
1532     \warning
1533 */
1534 #if _SL_INCLUDE_FUNC(sl_Htonl )
1535 _u32 sl_Htonl( _u32 val );
1536 
1537 #define sl_Ntohl sl_Htonl  /* Reorder the bytes of a 16-bit unsigned value from network order to processor orde. */
1538 #endif
1539 
1540 /*!
1541     \brief Reorder the bytes of a 16-bit unsigned value
1542 
1543     This function is used to Reorder the bytes of a 16-bit unsigned value from processor order to network order.
1544 
1545     \param[in] var              variable to reorder
1546 
1547     \return                     Return the reorder variable,
1548 
1549     \sa     sl_SendTo  sl_Bind    sl_Connect  sl_RecvFrom  sl_Accept
1550     \note                       belongs to \ref send_api
1551     \warning
1552 */
1553 #if _SL_INCLUDE_FUNC(sl_Htons )
1554 _u16 sl_Htons( _u16 val );
1555 
1556 #define sl_Ntohs sl_Htons   /* Reorder the bytes of a 16-bit unsigned value from network order to processor orde. */
1557 #endif
1558 
1559 /*!
1560 
1561  Close the Doxygen group.
1562  @}
1563 
1564  */
1565 
1566 
1567 #ifdef  __cplusplus
1568 }
1569 #endif /* __cplusplus */
1570 
1571 #endif /* __SOCKET_H__ */
1572 
1573 
1574