TI's CC3100. A test demo with very little testing done!

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cc3100_socket.h Source File

cc3100_socket.h

00001 /*
00002  * socket.h - CC31xx/CC32xx Host Driver Implementation
00003  *
00004  * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
00005  *
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *    Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  *    Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in the
00016  *    documentation and/or other materials provided with the
00017  *    distribution.
00018  *
00019  *    Neither the name of Texas Instruments Incorporated nor the names of
00020  *    its contributors may be used to endorse or promote products derived
00021  *    from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00026  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00027  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035 */
00036 
00037 /*****************************************************************************/
00038 /* Include files                                                             */
00039 /*****************************************************************************/
00040 #include "cc3100_simplelink.h"
00041 
00042 #ifndef SL_SOCKET_H_
00043 #define SL_SOCKET_H_
00044 
00045 #include "cc3100_protocol.h"
00046 
00047 namespace mbed_cc3100  {
00048 
00049 //#include "cc3100_driver.h"
00050 
00051 /*!
00052 
00053     \addtogroup socket
00054     @{
00055 
00056 */
00057 
00058 /*****************************************************************************/
00059 /* Macro declarations                                                        */
00060 /*****************************************************************************/
00061 
00062 const uint8_t SL_FD_SETSIZE                      =   SL_MAX_SOCKETS;         /* Number of sockets to select on - same is max sockets!               */
00063 const uint8_t BSD_SOCKET_ID_MASK                 =    (0x0F);                 /* Index using the LBS 4 bits for socket id 0-7 */
00064 /* Define some BSD protocol constants.  */
00065 const uint8_t SL_SOCK_STREAM                     =    (1);                       /* TCP Socket                                                          */
00066 const uint8_t SL_SOCK_DGRAM                      =    (2);                       /* UDP Socket                                                          */
00067 const uint8_t SL_SOCK_RAW                        =    (3);                       /* Raw socket                                                          */
00068 const uint8_t SL_IPPROTO_TCP                     =    (6);                       /* TCP Raw Socket                                                      */
00069 const uint8_t SL_IPPROTO_UDP                     =    (17);                      /* UDP Raw Socket                                                      */
00070 const uint8_t SL_IPPROTO_RAW                     =    (255);                     /* Raw Socket                                                          */
00071 const uint8_t SL_SEC_SOCKET                      =    (100);                     /* Secured Socket Layer (SSL,TLS)                                      */
00072 
00073 /* Address families.  */
00074 const uint8_t     SL_AF_INET                     =    (2);                       /* IPv4 socket (UDP, TCP, etc)                                          */
00075 const uint8_t     SL_AF_INET6                    =    (3);                       /* IPv6 socket (UDP, TCP, etc)                                          */
00076 const uint8_t     SL_AF_INET6_EUI_48             =    (9);
00077 const uint8_t AF_INET                            =    SL_AF_INET;
00078 const uint8_t AF_INET6                           =    SL_AF_INET6;
00079 const uint8_t     SL_AF_RF                       =    (6);                       /* data include RF parameter, All layer by user (Wifi could be disconnected) */
00080 const uint8_t     SL_AF_PACKET                   =    (17);
00081 /* Protocol families, same as address families.  */
00082 const uint8_t     SL_PF_INET                     =    AF_INET;
00083 const uint8_t     SL_PF_INET6                    =    AF_INET6;
00084 const uint8_t     SL_INADDR_ANY                  =    (0);                       /*  bind any address  */
00085 
00086 /* error codes */
00087 const int8_t SL_SOC_ERROR                       =   (-1);  /* Failure.                                                             */
00088 const int8_t SL_SOC_OK                          =   ( 0);  /* Success.                                                             */
00089 const int8_t SL_INEXE                           =   (-8);   /* socket command in execution  */
00090 const int8_t SL_EBADF                           =   (-9);   /* Bad file number */
00091 const int8_t SL_ENSOCK                          =   (-10);  /* The system limit on the total number of open socket, has been reached */
00092 const int8_t SL_EAGAIN                          =   (-11);  /* Try again */
00093 const int8_t SL_EWOULDBLOCK                     =   SL_EAGAIN;
00094 const int8_t SL_ENOMEM                          =   (-12);  /* Out of memory */
00095 const int8_t SL_EACCES                          =   (-13);  /* Permission denied */
00096 const int8_t SL_EFAULT                          =   (-14);  /* Bad address */
00097 const int8_t SL_ECLOSE                          =   (-15);  /* close socket operation failed to transmit all queued packets */
00098 const int8_t SL_EALREADY_ENABLED                =   (-21);  /* Transceiver - Transceiver already ON. there could be only one */
00099 const int8_t SL_EINVAL                          =   (-22);  /* Invalid argument */
00100 const int8_t SL_EAUTO_CONNECT_OR_CONNECTING     =   (-69);  /* Transceiver - During connection, connected or auto mode started */
00101 const int8_t SL_CONNECTION_PENDING              =   (-72);  /* Transceiver - Device is connected, disconnect first to open transceiver */
00102 const int8_t SL_EUNSUPPORTED_ROLE               =   (-86);  /* Transceiver - Trying to start when WLAN role is AP or P2P GO */
00103 const int8_t SL_EDESTADDRREQ                    =   (-89);  /* Destination address required */
00104 const int8_t SL_EPROTOTYPE                      =   (-91);  /* Protocol wrong type for socket */
00105 const int8_t SL_ENOPROTOOPT                     =   (-92);  /* Protocol not available */
00106 const int8_t SL_EPROTONOSUPPORT                 =   (-93);  /* Protocol not supported */
00107 const int8_t SL_ESOCKTNOSUPPORT                 =   (-94);  /* Socket type not supported */
00108 const int8_t SL_EOPNOTSUPP                      =   (-95);  /* Operation not supported on transport endpoint */
00109 const int8_t SL_EAFNOSUPPORT                    =   (-97);  /* Address family not supported by protocol */
00110 const int8_t SL_EADDRINUSE                      =   (-98);  /* Address already in use */
00111 const int8_t SL_EADDRNOTAVAIL                   =   (-99);  /* Cannot assign requested address */
00112 const int8_t SL_ENETUNREACH                     =   (-101); /* Network is unreachable */
00113 const int8_t SL_ENOBUFS                         =   (-105); /* No buffer space available */
00114 const int8_t SL_EOBUFF                          =   SL_ENOBUFS;
00115 const int8_t SL_EISCONN                         =   (-106); /* Transport endpoint is already connected */
00116 const int8_t SL_ENOTCONN                        =   (-107); /* Transport endpoint is not connected */
00117 const int8_t SL_ETIMEDOUT                       =   (-110); /* Connection timed out */
00118 const int8_t SL_ECONNREFUSED                    =   (-111); /* Connection refused */
00119 const int8_t SL_EALREADY                        =   (-114); /* Non blocking connect in progress, try again */
00120 
00121 const int16_t SL_ESEC_RSA_WRONG_TYPE_E          =    (-130);  /* RSA wrong block type for RSA function */
00122 const int16_t SL_ESEC_RSA_BUFFER_E              =    (-131);  /* RSA buffer error, output too small or */
00123 const int16_t SL_ESEC_BUFFER_E                  =    (-132);  /* output buffer too small or input too large */
00124 const int16_t SL_ESEC_ALGO_ID_E                 =    (-133);  /* setting algo id error */
00125 const int16_t SL_ESEC_PUBLIC_KEY_E              =    (-134);  /* setting public key error */
00126 const int16_t SL_ESEC_DATE_E                    =    (-135);  /* setting date validity error */
00127 const int16_t SL_ESEC_SUBJECT_E                 =    (-136);  /* setting subject name error */
00128 const int16_t SL_ESEC_ISSUER_E                  =    (-137);  /* setting issuer  name error */
00129 const int16_t SL_ESEC_CA_TRUE_E                 =    (-138);  /* setting CA basic constraint true error */
00130 const int16_t SL_ESEC_EXTENSIONS_E              =    (-139);  /* setting extensions error */
00131 const int16_t SL_ESEC_ASN_PARSE_E               =    (-140);  /* ASN parsing error, invalid input */
00132 const int16_t SL_ESEC_ASN_VERSION_E             =    (-141);  /* ASN version error, invalid number */
00133 const int16_t SL_ESEC_ASN_GETINT_E              =    (-142);  /* ASN get big int16_t error, invalid data */
00134 const int16_t SL_ESEC_ASN_RSA_KEY_E             =    (-143);  /* ASN key init error, invalid input */
00135 const int16_t SL_ESEC_ASN_OBJECT_ID_E           =    (-144);  /* ASN object id error, invalid id */
00136 const int16_t SL_ESEC_ASN_TAG_NULL_E            =    (-145);  /* ASN tag error, not null */
00137 const int16_t SL_ESEC_ASN_EXPECT_0_E            =    (-146);  /* ASN expect error, not zero */
00138 const int16_t SL_ESEC_ASN_BITSTR_E              =    (-147);  /* ASN bit string error, wrong id */
00139 const int16_t SL_ESEC_ASN_UNKNOWN_OID_E         =    (-148);  /* ASN oid error, unknown sum id */
00140 const int16_t SL_ESEC_ASN_DATE_SZ_E             =    (-149);  /* ASN date error, bad size */
00141 const int16_t SL_ESEC_ASN_BEFORE_DATE_E         =    (-150);  /* ASN date error, current date before */
00142 const int16_t SL_ESEC_ASN_AFTER_DATE_E          =    (-151);  /* ASN date error, current date after */
00143 const int16_t SL_ESEC_ASN_SIG_OID_E             =    (-152);  /* ASN signature error, mismatched oid */
00144 const int16_t SL_ESEC_ASN_TIME_E                =    (-153);  /* ASN time error, unknown time type */
00145 const int16_t SL_ESEC_ASN_INPUT_E               =    (-154);  /* ASN input error, not enough data */
00146 const int16_t SL_ESEC_ASN_SIG_CONFIRM_E         =    (-155);  /* ASN sig error, confirm failure */
00147 const int16_t SL_ESEC_ASN_SIG_HASH_E            =    (-156);  /* ASN sig error, unsupported hash type */
00148 const int16_t SL_ESEC_ASN_SIG_KEY_E             =    (-157);  /* ASN sig error, unsupported key type */
00149 const int16_t SL_ESEC_ASN_DH_KEY_E              =    (-158);  /* ASN key init error, invalid input */
00150 const int16_t SL_ESEC_ASN_NTRU_KEY_E            =    (-159);  /* ASN ntru key decode error, invalid input */
00151 const int16_t SL_ESEC_ECC_BAD_ARG_E             =    (-170);  /* ECC input argument of wrong type */
00152 const int16_t SL_ESEC_ASN_ECC_KEY_E             =    (-171);  /* ASN ECC bad input */
00153 const int16_t SL_ESEC_ECC_CURVE_OID_E           =    (-172);  /* Unsupported ECC OID curve type */
00154 const int16_t SL_ESEC_BAD_FUNC_ARG              =    (-173);  /* Bad function argument provided */
00155 const int16_t SL_ESEC_NOT_COMPILED_IN           =    (-174);  /* Feature not compiled in */
00156 const int16_t SL_ESEC_UNICODE_SIZE_E            =    (-175);  /* Unicode password too big */
00157 const int16_t SL_ESEC_NO_PASSWORD               =    (-176);  /* no password provided by user */
00158 const int16_t SL_ESEC_ALT_NAME_E                =    (-177);  /* alt name size problem, too big */
00159 const int16_t SL_ESEC_AES_GCM_AUTH_E            =    (-180);  /* AES-GCM Authentication check failure */
00160 const int16_t SL_ESEC_AES_CCM_AUTH_E            =    (-181);  /* AES-CCM Authentication check failure */
00161 #define SL_SOCKET_ERROR_E                     (-208)  /* Error state on socket */
00162 
00163 #define SL_ESEC_MEMORY_ERROR                  (-203)  /* out of memory            */
00164 #define SL_ESEC_VERIFY_FINISHED_ERROR         (-204)  /* verify problem on finished */
00165 #define SL_ESEC_VERIFY_MAC_ERROR              (-205)  /* verify mac problem       */
00166 #define SL_ESEC_UNKNOWN_HANDSHAKE_TYPE        (-207)  /* weird handshake type     */
00167 #define SL_ESEC_SOCKET_ERROR_E                (-208)  /* error state on socket    */
00168 #define SL_ESEC_SOCKET_NODATA                 (-209)  /* expected data, not there */
00169 #define SL_ESEC_INCOMPLETE_DATA               (-210)  /* don't have enough data to complete task            */
00170 #define SL_ESEC_UNKNOWN_RECORD_TYPE           (-211)  /* unknown type in record hdr */
00171 #define SL_ESEC_FATAL_ERROR                   (-213)  /* recvd alert fatal error  */
00172 #define SL_ESEC_ENCRYPT_ERROR                 (-214)  /* error during encryption  */
00173 #define SL_ESEC_NO_PEER_KEY                   (-216)  /* need peer's key          */
00174 #define SL_ESEC_NO_PRIVATE_KEY                (-217)  /* need the private key     */
00175 #define SL_ESEC_RSA_PRIVATE_ERROR             (-218)  /* error during rsa priv op */
00176 #define SL_ESEC_NO_DH_PARAMS                  (-219)  /* server missing DH params */
00177 #define SL_ESEC_BUILD_MSG_ERROR               (-220)  /* build message failure    */
00178 #define SL_ESEC_BAD_HELLO                     (-221)  /* client hello malformed   */
00179 #define SL_ESEC_DOMAIN_NAME_MISMATCH          (-222)  /* peer subject name mismatch */
00180 #define SL_ESEC_WANT_READ                     (-223)  /* want read, call again    */
00181 #define SL_ESEC_NOT_READY_ERROR               (-224)  /* handshake layer not ready */
00182 #define SL_ESEC_PMS_VERSION_ERROR             (-225)  /* pre m secret version error */
00183 #define SL_ESEC_VERSION_ERROR                 (-226)  /* record layer version error */
00184 #define SL_ESEC_WANT_WRITE                    (-227)  /* want write, call again   */
00185 #define SL_ESEC_BUFFER_ERROR                  (-228)  /* malformed buffer input   */
00186 #define SL_ESEC_VERIFY_CERT_ERROR             (-229)  /* verify cert error        */
00187 #define SL_ESEC_VERIFY_SIGN_ERROR             (-230)  /* verify sign error        */
00188 
00189 #define SL_ESEC_LENGTH_ERROR                  (-241)  /* record layer length error */
00190 #define SL_ESEC_PEER_KEY_ERROR                (-242)  /* can't decode peer key */
00191 #define SL_ESEC_ZERO_RETURN                   (-243)  /* peer sent close notify */
00192 #define SL_ESEC_SIDE_ERROR                    (-244)  /* wrong client/server type */
00193 #define SL_ESEC_NO_PEER_CERT                  (-245)  /* peer didn't send key */
00194 #define SL_ESEC_ECC_CURVETYPE_ERROR           (-250)  /* Bad ECC Curve Type */
00195 #define SL_ESEC_ECC_CURVE_ERROR               (-251)  /* Bad ECC Curve */
00196 #define SL_ESEC_ECC_PEERKEY_ERROR             (-252)  /* Bad Peer ECC Key */
00197 #define SL_ESEC_ECC_MAKEKEY_ERROR             (-253)  /* Bad Make ECC Key */
00198 #define SL_ESEC_ECC_EXPORT_ERROR              (-254)  /* Bad ECC Export Key */
00199 #define SL_ESEC_ECC_SHARED_ERROR              (-255)  /* Bad ECC Shared Secret */
00200 #define SL_ESEC_NOT_CA_ERROR                  (-257)  /* Not a CA cert error */
00201 #define SL_ESEC_BAD_PATH_ERROR                (-258)  /* Bad path for opendir */
00202 #define SL_ESEC_BAD_CERT_MANAGER_ERROR        (-259)  /* Bad Cert Manager */
00203 #define SL_ESEC_MAX_CHAIN_ERROR               (-268)  /* max chain depth exceeded */
00204 #define SL_ESEC_SUITES_ERROR                  (-271)  /* suites pointer error */
00205 #define SL_ESEC_SSL_NO_PEM_HEADER             (-272)  /* no PEM header found */
00206 #define SL_ESEC_OUT_OF_ORDER_E                (-273)  /* out of order message */
00207 #define SL_ESEC_SANITY_CIPHER_E               (-275)  /* sanity check on cipher error */
00208 #define SL_ESEC_GEN_COOKIE_E                  (-277)  /* Generate Cookie Error */
00209 #define SL_ESEC_NO_PEER_VERIFY                (-278)  /* Need peer cert verify Error */
00210 #define SL_ESEC_UNKNOWN_SNI_HOST_NAME_E       (-281)  /* Unrecognized host name Error */
00211 /* begin negotiation parameter errors */
00212 #define SL_ESEC_UNSUPPORTED_SUITE     (-290)            /* unsupported cipher suite */
00213 #define SL_ESEC_MATCH_SUITE_ERROR      (-291 )            /* can't match cipher suite */
00214 
00215 /* ssl tls security start with -300 offset */
00216 const int16_t SL_ESEC_CLOSE_NOTIFY              =    (-300); /* ssl/tls alerts */
00217 const int16_t SL_ESEC_UNEXPECTED_MESSAGE        =    (-310); /* ssl/tls alerts */
00218 const int16_t SL_ESEC_BAD_RECORD_MAC            =    (-320); /* ssl/tls alerts */
00219 const int16_t SL_ESEC_DECRYPTION_FAILED         =    (-321); /* ssl/tls alerts */
00220 const int16_t SL_ESEC_RECORD_OVERFLOW           =    (-322); /* ssl/tls alerts */
00221 const int16_t SL_ESEC_DECOMPRESSION_FAILURE     =    (-330); /* ssl/tls alerts */
00222 const int16_t SL_ESEC_HANDSHAKE_FAILURE         =    (-340); /* ssl/tls alerts */
00223 const int16_t SL_ESEC_NO_CERTIFICATE            =    (-341); /* ssl/tls alerts */
00224 const int16_t SL_ESEC_BAD_CERTIFICATE           =    (-342); /* ssl/tls alerts */
00225 const int16_t SL_ESEC_UNSUPPORTED_CERTIFICATE   =    (-343); /* ssl/tls alerts */
00226 const int16_t SL_ESEC_CERTIFICATE_REVOKED       =    (-344); /* ssl/tls alerts */
00227 const int16_t SL_ESEC_CERTIFICATE_EXPIRED       =    (-345); /* ssl/tls alerts */
00228 const int16_t SL_ESEC_CERTIFICATE_UNKNOWN       =    (-346); /* ssl/tls alerts */
00229 const int16_t SL_ESEC_ILLEGAL_PARAMETER         =    (-347); /* ssl/tls alerts */
00230 const int16_t SL_ESEC_UNKNOWN_CA                =    (-348); /* ssl/tls alerts */
00231 const int16_t SL_ESEC_ACCESS_DENIED             =    (-349); /* ssl/tls alerts */
00232 const int16_t SL_ESEC_DECODE_ERROR              =    (-350); /* ssl/tls alerts */
00233 const int16_t SL_ESEC_DECRYPT_ERROR             =    (-351); /* ssl/tls alerts */
00234 const int16_t SL_ESEC_EXPORT_RESTRICTION        =    (-360); /* ssl/tls alerts */
00235 const int16_t SL_ESEC_PROTOCOL_VERSION          =    (-370); /* ssl/tls alerts */
00236 const int16_t SL_ESEC_INSUFFICIENT_SECURITY     =    (-371); /* ssl/tls alerts */
00237 const int16_t SL_ESEC_INTERNAL_ERROR            =    (-380); /* ssl/tls alerts */
00238 const int16_t SL_ESEC_USER_CANCELLED            =    (-390); /* ssl/tls alerts */
00239 const int16_t SL_ESEC_NO_RENEGOTIATION          =    (-400); /* ssl/tls alerts */
00240 const int16_t SL_ESEC_UNSUPPORTED_EXTENSION     =    (-410); /* ssl/tls alerts */
00241 const int16_t SL_ESEC_CERTIFICATE_UNOBTAINABLE  =    (-411); /* ssl/tls alerts */
00242 const int16_t SL_ESEC_UNRECOGNIZED_NAME         =    (-412); /* ssl/tls alerts */
00243 const int16_t SL_ESEC_BAD_CERTIFICATE_STATUS_RESPONSE = (-413); /* ssl/tls alerts */
00244 const int16_t SL_ESEC_BAD_CERTIFICATE_HASH_VALUE =   (-414); /* ssl/tls alerts */
00245 /* propierty secure */
00246 const int16_t SL_ESECGENERAL                    =    (-450);  /* error secure level general error */
00247 const int16_t SL_ESECDECRYPT                    =    (-451);  /* error secure level, decrypt recv packet fail */
00248 const int16_t SL_ESECCLOSED                     =    (-452);  /* secure layrer is closed by other size , tcp is still connected  */
00249 const int16_t SL_ESECSNOVERIFY                  =    (-453);  /* Connected without server verification */
00250 const int16_t SL_ESECNOCAFILE                   =    (-454);  /* error secure level CA file not found*/
00251 const int16_t SL_ESECMEMORY                     =    (-455);  /* error secure level No memory  space available */
00252 const int16_t SL_ESECBADCAFILE                  =    (-456);  /* error secure level bad CA file */
00253 const int16_t SL_ESECBADCERTFILE                =    (-457);  /* error secure level bad Certificate file */
00254 const int16_t SL_ESECBADPRIVATEFILE             =    (-458);  /* error secure level bad private file */
00255 const int16_t SL_ESECBADDHFILE                  =    (-459);  /* error secure level bad DH file */
00256 const int16_t SL_ESECT00MANYSSLOPENED           =    (-460);  /* MAX SSL Sockets are opened */
00257 const int16_t SL_ESECDATEERROR                  =    (-461);  /* connected with certificate date verification error */
00258 const int16_t SL_ESECHANDSHAKETIMEDOUT          =    (-462);  /* connection timed out due to handshake time */
00259 
00260 /* end error codes */
00261 
00262 /* Max payload size by protocol */
00263 const uint8_t SL_SOCKET_PAYLOAD_TYPE_MASK       =     (0xF0);  /*4 bits type, 4 bits sockets id */
00264 const uint8_t SL_SOCKET_PAYLOAD_TYPE_UDP_IPV4   =     (0x00);  /* 1472 bytes */
00265 const uint8_t SL_SOCKET_PAYLOAD_TYPE_TCP_IPV4   =     (0x10);  /* 1460 bytes */
00266 const uint8_t SL_SOCKET_PAYLOAD_TYPE_UDP_IPV6   =     (0x20);  /* 1452 bytes */
00267 const uint8_t SL_SOCKET_PAYLOAD_TYPE_TCP_IPV6   =     (0x30);  /* 1440 bytes */
00268 const uint8_t SL_SOCKET_PAYLOAD_TYPE_UDP_IPV4_SECURE =(0x40);  /*            */
00269 const uint8_t SL_SOCKET_PAYLOAD_TYPE_TCP_IPV4_SECURE =(0x50);  /*            */
00270 const uint8_t SL_SOCKET_PAYLOAD_TYPE_UDP_IPV6_SECURE =(0x60);  /*            */
00271 const uint8_t SL_SOCKET_PAYLOAD_TYPE_TCP_IPV6_SECURE =(0x70);  /*            */
00272 const uint8_t SL_SOCKET_PAYLOAD_TYPE_RAW_TRANCEIVER  =(0x80);  /* 1536 bytes */
00273 const uint8_t SL_SOCKET_PAYLOAD_TYPE_RAW_PACKET =     (0x90);  /* 1536 bytes */
00274 const uint8_t SL_SOCKET_PAYLOAD_TYPE_RAW_IP4    =     (0xa0);
00275 const uint8_t SL_SOCKET_PAYLOAD_TYPE_RAW_IP6    =     (SL_SOCKET_PAYLOAD_TYPE_RAW_IP4 );
00276 
00277 
00278 
00279 const uint8_t SL_SOL_SOCKET        =  (1);   /* Define the socket option category. */
00280 const uint8_t SL_IPPROTO_IP        =  (2);   /* Define the IP option category.     */
00281 const uint8_t SL_SOL_PHY_OPT       =  (3);   /* Define the PHY option category.    */
00282 
00283 const uint8_t SL_SO_RCVBUF         =  (8);   /* Setting TCP receive buffer size */
00284 const uint8_t SL_SO_KEEPALIVE      =  (9);   /* Connections are kept alive with periodic messages */
00285 const uint8_t SL_SO_RCVTIMEO       =  (20);  /* Enable receive timeout */
00286 const uint8_t SL_SO_NONBLOCKING    =  (24);  /* Enable . disable nonblocking mode  */
00287 const uint8_t SL_SO_SECMETHOD      =  (25);  /* security metohd */
00288 const uint8_t SL_SO_SECURE_MASK    =  (26);  /* security mask */
00289 const uint8_t SL_SO_SECURE_FILES   =  (27);  /* security files */
00290 const uint8_t SL_SO_CHANGE_CHANNEL =  (28);  /* This option is available only when transceiver started */
00291 const uint8_t SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME =(30); /* This option used to configue secure file */
00292 const uint8_t SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME =(31); /* This option used to configue secure file */
00293 const uint8_t SL_SO_SECURE_FILES_CA_FILE_NAME      =    (32); /* This option used to configue secure file */
00294 const uint8_t SL_SO_SECURE_FILES_DH_KEY_FILE_NAME  =    (33); /* This option used to configue secure file */
00295 
00296 const uint8_t SL_IP_MULTICAST_IF   =  (60); /* Specify outgoing multicast interface */
00297 const uint8_t SL_IP_MULTICAST_TTL  =  (61); /* Specify the TTL value to use for outgoing multicast packet. */
00298 const uint8_t SL_IP_ADD_MEMBERSHIP =  (65); /* Join IPv4 multicast membership */
00299 const uint8_t SL_IP_DROP_MEMBERSHIP=  (66); /* Leave IPv4 multicast membership */
00300 const uint8_t SL_IP_HDRINCL        =  (67); /* Raw socket IPv4 header included. */
00301 const uint8_t SL_IP_RAW_RX_NO_HEADER =(68); /* Proprietary socket option that does not includeIPv4/IPv6 header (and extension headers) on received raw sockets*/
00302 const uint8_t SL_IP_RAW_IPV6_HDRINCL =(69); /* Transmitted buffer over IPv6 socket contains IPv6 header. */
00303 
00304 const uint8_t SL_SO_PHY_RATE           =   (100);   /* WLAN Transmit rate */
00305 const uint8_t SL_SO_PHY_TX_POWER       =   (101);   /* TX Power level */
00306 const uint8_t SL_SO_PHY_NUM_FRAMES_TO_TX = (102);   /* Number of frames to transmit */
00307 const uint8_t SL_SO_PHY_PREAMBLE       =   (103);   /* Preamble for transmission */
00308 
00309 const uint8_t SL_SO_SEC_METHOD_SSLV3                  =           (0);  /* security metohd SSL v3*/
00310 const uint8_t SL_SO_SEC_METHOD_TLSV1                  =           (1);  /* security metohd TLS v1*/
00311 const uint8_t SL_SO_SEC_METHOD_TLSV1_1                =           (2);  /* security metohd TLS v1_1*/
00312 const uint8_t SL_SO_SEC_METHOD_TLSV1_2                =           (3);  /* security metohd TLS v1_2*/
00313 const uint8_t SL_SO_SEC_METHOD_SSLv3_TLSV1_2          =           (4);  /* use highest possible version from SSLv3 - TLS 1.2*/
00314 const uint8_t SL_SO_SEC_METHOD_DLSV1                  =           (5);  /* security metohd DTL v1  */
00315 
00316 #define SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA               (1 << 0)
00317 #define SL_SEC_MASK_SSL_RSA_WITH_RC4_128_MD5               (1 << 1)
00318 #define SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA           (1 << 2)
00319 #define SL_SEC_MASK_TLS_DHE_RSA_WITH_AES_256_CBC_SHA       (1 << 3)
00320 #define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA     (1 << 4)
00321 #define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_RC4_128_SHA         (1 << 5)
00322 #define SL_SEC_MASK_TLS_RSA_WITH_AES_128_CBC_SHA256              (1 << 6)
00323 #define SL_SEC_MASK_TLS_RSA_WITH_AES_256_CBC_SHA256              (1 << 7)
00324 #define SL_SEC_MASK_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256        (1 << 8)
00325 #define SL_SEC_MASK_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256      (1 << 9)
00326 
00327 #define SL_SEC_MASK_SECURE_DEFAULT                         ((SL_SEC_MASK_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256  <<  1)  -  1)
00328 
00329 const uint32_t SL_MSG_DONTWAIT                       =            (0x00000008);  /* Nonblocking IO */
00330 
00331 /* AP DHCP Server - IP Release reason code */
00332 const uint8_t SL_IP_LEASE_PEER_RELEASE  =   (0);
00333 const uint8_t SL_IP_LEASE_PEER_DECLINE  =   (1);
00334 const uint8_t SL_IP_LEASE_EXPIRED       =   (2);
00335 
00336 /* possible types when receiving SL_SOCKET_ASYNC_EVENT*/
00337 const uint8_t SSL_ACCEPT                               = (1); /* accept failed due to ssl issue ( tcp pass) */
00338 const uint8_t RX_FRAGMENTATION_TOO_BIG                 = (2); /* connection less mode, rx packet fragmentation > 16K, packet is being released */
00339 const uint8_t OTHER_SIDE_CLOSE_SSL_DATA_NOT_ENCRYPTED  = (3); /* remote side down from secure to unsecure */
00340 
00341 
00342 
00343 #ifdef SL_INC_STD_BSD_API_NAMING
00344 
00345 #define FD_SETSIZE                          SL_FD_SETSIZE
00346 
00347 #define SOCK_STREAM                         SL_SOCK_STREAM
00348 #define SOCK_DGRAM                          SL_SOCK_DGRAM
00349 #define SOCK_RAW                            SL_SOCK_RAW
00350 #define IPPROTO_TCP                         SL_IPPROTO_TCP
00351 #define IPPROTO_UDP                         SL_IPPROTO_UDP
00352 #define IPPROTO_RAW                         SL_IPPROTO_RAW
00353 
00354 #define AF_INET6_EUI_48                     SL_AF_INET6_EUI_48
00355 #define AF_RF                               SL_AF_RF
00356 #define AF_PACKET                           SL_AF_PACKET
00357 
00358 #define PF_INET                             SL_PF_INET
00359 #define PF_INET6                            SL_PF_INET6
00360 
00361 #define INADDR_ANY                          SL_INADDR_ANY
00362 #define ERROR                               SL_SOC_ERROR
00363 #define INEXE                               SL_INEXE
00364 #define EBADF                               SL_EBADF
00365 #define ENSOCK                              SL_ENSOCK
00366 #define EAGAIN                              SL_EAGAIN
00367 #define EWOULDBLOCK                         SL_EWOULDBLOCK
00368 #define ENOMEM                              SL_ENOMEM
00369 #define EACCES                              SL_EACCES
00370 #define EFAULT                              SL_EFAULT
00371 #define EINVAL                              SL_EINVAL
00372 #define EDESTADDRREQ                        SL_EDESTADDRREQ
00373 #define EPROTOTYPE                          SL_EPROTOTYPE
00374 #define ENOPROTOOPT                         SL_ENOPROTOOPT
00375 #define EPROTONOSUPPORT                     SL_EPROTONOSUPPORT
00376 #define ESOCKTNOSUPPORT                     SL_ESOCKTNOSUPPORT
00377 #define EOPNOTSUPP                          SL_EOPNOTSUPP
00378 #define EAFNOSUPPORT                        SL_EAFNOSUPPORT
00379 #define EADDRINUSE                          SL_EADDRINUSE
00380 #define EADDRNOTAVAIL                       SL_EADDRNOTAVAIL
00381 #define ENETUNREACH                         SL_ENETUNREACH
00382 #define ENOBUFS                             SL_ENOBUFS
00383 #define EOBUFF                              SL_EOBUFF
00384 #define EISCONN                             SL_EISCONN
00385 #define ENOTCONN                            SL_ENOTCONN
00386 #define ETIMEDOUT                           SL_ETIMEDOUT
00387 #define ECONNREFUSED                        SL_ECONNREFUSED
00388 
00389 #define SOL_SOCKET                          SL_SOL_SOCKET
00390 #define IPPROTO_IP                          SL_IPPROTO_IP
00391 #define SO_KEEPALIVE                        SL_SO_KEEPALIVE
00392 
00393 #define SO_RCVTIMEO                         SL_SO_RCVTIMEO
00394 #define SO_NONBLOCKING                      SL_SO_NONBLOCKING
00395 
00396 #define IP_MULTICAST_IF                     SL_IP_MULTICAST_IF
00397 #define IP_MULTICAST_TTL                    SL_IP_MULTICAST_TTL
00398 #define IP_ADD_MEMBERSHIP                   SL_IP_ADD_MEMBERSHIP
00399 #define IP_DROP_MEMBERSHIP                  SL_IP_DROP_MEMBERSHIP
00400 
00401 #define socklen_t                           SlSocklen_t
00402 #define timeval                             SlTimeval_t
00403 #define sockaddr                            SlSockAddr_t
00404 #define in6_addr                            SlIn6Addr_t
00405 #define sockaddr_in6                        SlSockAddrIn6_t
00406 #define in_addr                             SlInAddr_t
00407 #define sockaddr_in                         SlSockAddrIn_t
00408 
00409 #define MSG_DONTWAIT                        SL_MSG_DONTWAIT
00410 
00411 #define FD_SET                              SL_FD_SET
00412 #define FD_CLR                              SL_FD_CLR
00413 #define FD_ISSET                            SL_FD_ISSET
00414 #define FD_ZERO                             SL_FD_ZERO
00415 #define fd_set                              SlFdSet_t
00416 
00417 #define socket                              sl_Socket
00418 #define close                               sl_Close
00419 #define accept                              sl_Accept
00420 #define bind                                sl_Bind
00421 #define listen                              sl_Listen
00422 #define connect                             sl_Connect
00423 #define select                              sl_Select
00424 #define setsockopt                          sl_SetSockOpt
00425 #define getsockopt                          sl_GetSockOpt
00426 #define recv                                sl_Recv
00427 #define recvfrom                            sl_RecvFrom
00428 #define write_                               sl_Write
00429 #define send                                sl_Send
00430 #define sendto                              sl_SendTo
00431 #define gethostbyname                       sl_NetAppDnsGetHostByName
00432 #define htonl                               sl_Htonl
00433 #define ntohl                               sl_Ntohl
00434 #define htons                               sl_Htons
00435 #define ntohs                               sl_Ntohs
00436 #endif
00437 
00438 
00439 /*****************************************************************************/
00440 /* Structure/Enum declarations                                               */
00441 /*****************************************************************************/
00442 
00443 /* Internet address   */
00444 typedef struct SlInAddr_t {
00445 #ifndef s_addr
00446     uint32_t           s_addr;             /* Internet address 32 bits */
00447 #else
00448     union S_un {
00449         struct {
00450             uint8_t s_b1,s_b2,s_b3,s_b4;
00451         } S_un_b;
00452         struct {
00453             uint8_t s_w1,s_w2;
00454         } S_un_w;
00455         uint32_t S_addr;
00456     } S_un;
00457 #endif
00458 } SlInAddr_t;
00459 
00460 
00461 /* sockopt */
00462 typedef struct {
00463     uint32_t KeepaliveEnabled; /* 0 = disabled;1 = enabled; default = 1*/
00464 } SlSockKeepalive_t;
00465 
00466 typedef struct {
00467     uint32_t ReuseaddrEnabled; /* 0 = disabled; 1 = enabled; default = 1*/
00468 } SlSockReuseaddr_t;
00469 
00470 typedef struct {
00471     uint32_t Winsize;          /* receive window size for tcp sockets  */
00472 } SlSockWinsize_t;
00473 
00474 typedef struct {
00475     uint32_t NonblockingEnabled;/* 0 = disabled;1 = enabled;default = 1*/
00476 } SlSockNonblocking_t;
00477 
00478 typedef struct {
00479     uint8_t   sd;
00480     uint8_t   type;
00481     uint16_t  val;
00482     uint8_t*  pExtraInfo;
00483 } SlSocketAsyncEvent_t;
00484 
00485 typedef struct {
00486     int16_t        status;
00487     uint8_t        sd;
00488     uint8_t        padding;
00489 } SlSockTxFailEventData_t;
00490 
00491 
00492 typedef union
00493 {
00494   SlSockTxFailEventData_t   SockTxFailData;
00495   SlSocketAsyncEvent_t      SockAsyncData;
00496 } SlSockEventData_u;
00497 
00498 
00499 typedef struct {
00500     uint32_t                Event;
00501     SlSockEventData_u       socketAsyncEvent;
00502 } SlSockEvent_t;
00503 
00504 
00505 typedef struct {
00506     uint32_t    secureMask;
00507 } SlSockSecureMask;
00508 
00509 typedef struct {
00510     uint8_t     secureMethod;
00511 } SlSockSecureMethod;
00512 
00513 typedef enum {
00514     SL_BSD_SECURED_PRIVATE_KEY_IDX = 0,
00515     SL_BSD_SECURED_CERTIFICATE_IDX,
00516     SL_BSD_SECURED_CA_IDX,
00517     SL_BSD_SECURED_DH_IDX
00518 } slBsd_secureSocketFilesIndex_e;
00519 
00520 typedef struct {
00521     SlInAddr_t   imr_multiaddr;     /* The IPv4 multicast address to join */
00522     SlInAddr_t   imr_interface;     /* The interface to use for this group */
00523 } SlSockIpMreq;
00524 
00525 
00526 /* sockopt */
00527 typedef uint32_t   SlTime_t;
00528 typedef uint32_t   SlSuseconds_t;
00529 
00530 typedef struct  {
00531     SlTime_t          tv_sec;             /* Seconds      */
00532     SlSuseconds_t     tv_usec;            /* Microseconds */
00533 } SlTimeval_t;
00534 
00535 typedef uint16_t SlSocklen_t;
00536 
00537 /* IpV4 socket address */
00538 typedef struct  {
00539     uint16_t          sa_family;     /* Address family (e.g. , AF_INET)     */
00540     uint8_t           sa_data[14];  /* Protocol- specific address information*/
00541 } SlSockAddr_t;
00542 
00543 
00544 /* IpV6 or Ipv6 EUI64 */
00545 typedef struct  {
00546     union {
00547         uint8_t   _S6_u8[16];
00548         uint32_t  _S6_u32[4];
00549     } _S6_un;
00550 } SlIn6Addr_t;
00551 
00552 typedef struct  {
00553     uint16_t           sin6_family;                 /* AF_INET6 || AF_INET6_EUI_48*/
00554     uint16_t           sin6_port;                   /* Transport layer port.  */
00555     uint32_t           sin6_flowinfo;               /* IPv6 flow information. */
00556     SlIn6Addr_t        sin6_addr;                   /* IPv6 address. */
00557     uint32_t           sin6_scope_id;               /* set of interfaces for a scope. */
00558 } SlSockAddrIn6_t;
00559 
00560 /* Socket address, Internet style. */
00561 
00562 typedef struct  {
00563     uint16_t              sin_family;         /* Internet Protocol (AF_INET).                    */
00564     uint16_t              sin_port;           /* Address port (16 bits).                         */
00565     SlInAddr_t            sin_addr;           /* Internet address (32 bits).                     */
00566     int8_t                sin_zero[8];        /* Not used.                                       */
00567 } SlSockAddrIn_t;
00568 
00569 typedef struct {
00570     uint32_t ip;
00571     uint32_t gateway;
00572     uint32_t dns;
00573 } SlIpV4AcquiredAsync_t;
00574 
00575 typedef struct {
00576     uint32_t type;
00577     uint32_t ip[4];
00578     uint32_t gateway[4];
00579     uint32_t dns[4];
00580 } SlIpV6AcquiredAsync_t;
00581 
00582 typedef struct {
00583     uint32_t    ip_address;
00584     uint32_t    lease_time;
00585     uint8_t     mac[6];
00586     uint16_t    padding;
00587 } SlIpLeasedAsync_t;
00588 
00589 typedef struct {
00590     uint32_t    ip_address;
00591     uint8_t     mac[6];
00592     uint16_t    reason;
00593 } SlIpReleasedAsync_t;
00594 
00595 
00596 typedef union {
00597     SlIpV4AcquiredAsync_t    ipAcquiredV4; /*SL_NETAPP_IPV4_IPACQUIRED_EVENT*/
00598     SlIpV6AcquiredAsync_t    ipAcquiredV6; /*SL_NETAPP_IPV6_IPACQUIRED_EVENT*/
00599     uint32_t                      sd;           /*SL_SOCKET_TX_FAILED_EVENT*/
00600     SlIpLeasedAsync_t        ipLeased;     /* SL_NETAPP_IP_LEASED_EVENT   */
00601     SlIpReleasedAsync_t      ipReleased;   /* SL_NETAPP_IP_RELEASED_EVENT */
00602 } SlNetAppEventData_u;
00603 
00604 typedef struct {
00605     uint32_t                     Event;
00606     SlNetAppEventData_u       EventData;
00607 } SlNetAppEvent_t;
00608 
00609 
00610 typedef struct sock_secureFiles {
00611     uint8_t                     secureFiles[4];
00612 } SlSockSecureFiles_t;
00613 
00614 
00615 typedef struct SlFdSet_t {                  /* The select socket array manager */
00616     uint32_t        fd_array[(SL_FD_SETSIZE + 31)/32]; /* Bit map of SOCKET Descriptors */
00617 } SlFdSet_t;
00618 
00619 typedef struct {
00620     uint8_t   rate;               /* Recevied Rate  */
00621     uint8_t   channel;            /* The received channel*/
00622     int8_t    rssi;               /* The computed RSSI value in db of current frame */
00623     uint8_t   padding;                                           /* pad to align to 32 bits */
00624     uint32_t  timestamp;          /* Timestamp in microseconds,     */
00625 } SlTransceiverRxOverHead_t;
00626 
00627 class cc3100_nonos;
00628 
00629 class cc3100_socket
00630 {
00631 
00632 public:
00633 
00634     cc3100_socket(cc3100_driver &driver, cc3100_nonos &nonos);
00635 
00636     ~cc3100_socket();
00637 
00638     /*******************************************************************************/
00639     /* Functions prototypes                                                        */
00640     /*******************************************************************************/
00641     void   _sl_BuildAddress(const SlSockAddr_t *addr, _SocketAddrCommand_u *pCmd);
00642     void   _sl_ParseAddress(_SocketAddrResponse_u *pRsp, SlSockAddr_t *addr, SlSocklen_t *addrlen);
00643     uint16_t   _sl_TruncatePayloadByProtocol(const int16_t pSd,const uint16_t length);
00644 
00645     /*****************************************************************************/
00646     /* Function prototypes                                                       */
00647     /*****************************************************************************/
00648 
00649     /*!
00650 
00651         \brief create an endpoint for communication
00652 
00653         The socket function creates a new socket of a certain socket type, identified
00654         by an integer number, and allocates system resources to it.
00655         This function is called by the application layer to obtain a socket handle.
00656 
00657         \param[in] domain           specifies the protocol family of the created socket.
00658                                     For example:
00659                                        AF_INET for network protocol IPv4
00660                                        AF_RF for starting transceiver mode. Notes:
00661                                        - sending and receiving any packet overriding 802.11 header
00662                                        - for optimized power consumption the socket will be started in TX
00663                                          only mode until receive command is activated
00664                                        AF_INET6 for IPv6
00665 
00666 
00667         \param[in] type              specifies the communication semantic, one of:
00668                                        SOCK_STREAM (reliable stream-oriented service or Stream Sockets)
00669                                        SOCK_DGRAM (datagram service or Datagram Sockets)
00670                                        SOCK_RAW (raw protocols atop the network layer)
00671                                        when used with AF_RF:
00672                                                                          SOCK_DGRAM - L2 socket
00673                                                                          SOCK_RAW - L1 socket - bypass WLAN CCA (Clear Channel Assessment)
00674 
00675         \param[in] protocol         specifies a particular transport to be used with
00676                                     the socket.
00677                                     The most common are IPPROTO_TCP, IPPROTO_SCTP, IPPROTO_UDP,
00678                                     IPPROTO_DCCP.
00679                                     The value 0 may be used to select a default
00680                                     protocol from the selected domain and type
00681 
00682 
00683         \return                     On success, socket handle that is used for consequent socket operations.
00684                                     A successful return code should be a positive number (int16)
00685                                     On error, a negative (int16) value will be returned specifying the error code.
00686                                SL_EAFNOSUPPORT  - illegal domain parameter
00687                                SL_EPROTOTYPE  - illegal type parameter
00688                                SL_EACCES   - permission denied
00689                                SL_ENSOCK  - exceeded maximal number of socket
00690                                SL_ENOMEM  - memory allocation error
00691                                SL_EINVAL  - error in socket configuration
00692                                SL_EPROTONOSUPPORT  - illegal protocol parameter
00693                                SL_EOPNOTSUPP  - illegal combination of protocol and type parameters
00694 
00695 
00696         \sa                         sl_Close
00697         \note                       belongs to \ref basic_api
00698         \warning
00699     */
00700 #if _SL_INCLUDE_FUNC(sl_Socket)
00701     int16_t sl_Socket(int16_t Domain, int16_t Type, int16_t Protocol);
00702 #endif
00703 
00704     /*!
00705         \brief gracefully close socket
00706 
00707         This function causes the system to release resources allocated to a socket.  \n
00708         In case of TCP, the connection is terminated.
00709 
00710         \param[in] sd               socket handle (received in sl_Socket)
00711 
00712         \return                        On success, zero is returned.
00713                                     On error, a negative number is returned.
00714 
00715         \sa                         sl_Socket
00716         \note                       belongs to \ref ext_api
00717         \warning
00718     */
00719 #if _SL_INCLUDE_FUNC(sl_Close)
00720     int16_t sl_Close(int16_t sd);
00721 #endif
00722 
00723     /*!
00724         \brief Accept a connection on a socket
00725 
00726         This function is used with connection-based socket types (SOCK_STREAM).
00727         It extracts the first connection request on the queue of pending
00728         connections, creates a new connected socket, and returns a new file
00729         descriptor referring to that socket.
00730         The newly created socket is not in the listening state. The
00731         original socket sd is unaffected by this call.
00732         The argument sd is a socket that has been created with
00733         sl_Socket(), bound to a local address with sl_Bind(), and is
00734         listening for connections after a sl_Listen(). The argument \b
00735         \e addr is a pointer to a sockaddr structure. This structure
00736         is filled in with the address of the peer socket, as known to
00737         the communications layer. The exact format of the address
00738         returned addr is determined by the socket's address family.
00739         The \b \e addrlen argument is a value-result argument: it
00740         should initially contain the size of the structure pointed to
00741         by addr, on return it will contain the actual length (in
00742         bytes) of the address returned.
00743 
00744         \param[in] sd               socket descriptor (handle)
00745         \param[out] addr            the argument addr is a pointer
00746                                     to a sockaddr structure. This
00747                                     structure is filled in with the
00748                                     address of the peer socket, as
00749                                     known to the communications
00750                                     layer. The exact format of the
00751                                     address returned addr is
00752                                     determined by the socket's
00753                                     address\n
00754                                     sockaddr:\n - code for the
00755                                     address format. On this version
00756                                     only AF_INET is supported.\n -
00757                                     socket address, the length
00758                                     depends on the code format
00759         \param[out] addrlen         the addrlen argument is a value-result
00760                                     argument: it should initially contain the
00761                                     size of the structure pointed to by addr
00762 
00763         \return                        On success, a socket handle.
00764                                     On a non-blocking accept a possible negative value is SL_EAGAIN.
00765                                     On failure, negative value.
00766                                     SL_POOL_IS_EMPTY may be return in case there are no resources in the system
00767                                      In this case try again later or increase MAX_CONCURRENT_ACTIONS
00768 
00769         \sa                         sl_Socket  sl_Bind  sl_Listen
00770         \note                       belongs to \ref server_side
00771         \warning
00772     */
00773 #if _SL_INCLUDE_FUNC(sl_Accept)
00774     int16_t sl_Accept(int16_t sd, SlSockAddr_t *addr, SlSocklen_t *addrlen);
00775 #endif
00776 
00777     /*!
00778         \brief assign a name to a socket
00779 
00780         This function gives the socket the local address addr.
00781         addr is addrlen bytes long. Traditionally, this is called
00782         When a socket is created with socket, it exists in a name
00783         space (address family) but has no name assigned.
00784         It is necessary to assign a local address before a SOCK_STREAM
00785         socket may receive connections.
00786 
00787         \param[in] sd                socket descriptor (handle)
00788         \param[in] addr              specifies the destination
00789                                     addrs\n sockaddr:\n - code for
00790                                     the address format. On this
00791                                     version only AF_INET is
00792                                     supported.\n - socket address,
00793                                     the length depends on the code
00794                                     format
00795         \param[in] addrlen          contains the size of the structure pointed to by addr
00796 
00797         \return                        On success, zero is returned. On error, a negative error code is returned.
00798 
00799         \sa                         sl_Socket  sl_Accept sl_Listen
00800         \note                       belongs to \ref basic_api
00801         \warning
00802     */
00803 #if _SL_INCLUDE_FUNC(sl_Bind)
00804     int16_t sl_Bind(int16_t sd, const SlSockAddr_t *addr, int16_t addrlen);
00805 #endif
00806 
00807     /*!
00808         \brief listen for connections on a socket
00809 
00810         The willingness to accept incoming connections and a queue
00811         limit for incoming connections are specified with listen(),
00812         and then the connections are accepted with accept.
00813         The listen() call applies only to sockets of type SOCK_STREAM
00814         The backlog parameter defines the maximum length the queue of
00815         pending connections may grow to.
00816 
00817         \param[in] sd               socket descriptor (handle)
00818         \param[in] backlog          specifies the listen queue depth.
00819 
00820 
00821         \return                    On success, zero is returned. On error, a negative error code is returned.
00822 
00823         \sa                         sl_Socket  sl_Accept  sl_Bind
00824         \note                       belongs to \ref server_side
00825         \warning
00826     */
00827 #if _SL_INCLUDE_FUNC(sl_Listen)
00828     int16_t sl_Listen(int16_t sd, int16_t backlog);
00829 #endif
00830 
00831     /*!
00832         \brief Initiate a connection on a socket
00833 
00834         Function connects the socket referred to by the socket
00835         descriptor sd, to the address specified by addr. The addrlen
00836         argument specifies the size of addr. The format of the
00837         address in addr is determined by the address space of the
00838         socket. If it is of type SOCK_DGRAM, this call specifies the
00839         peer with which the socket is to be associated; this address
00840         is that to which datagrams are to be sent, and the only
00841         address from which datagrams are to be received.  If the
00842         socket is of type SOCK_STREAM, this call attempts to make a
00843         connection to another socket. The other socket is specified
00844         by address, which is an address in the communications space
00845         of the socket.
00846 
00847 
00848         \param[in] sd               socket descriptor (handle)
00849         \param[in] addr             specifies the destination addr\n
00850                                     sockaddr:\n - code for the
00851                                     address format. On this version
00852                                     only AF_INET is supported.\n -
00853                                     socket address, the length
00854                                     depends on the code format
00855 
00856         \param[in] addrlen          contains the size of the structure pointed
00857                                     to by addr
00858 
00859         \return                     On success, a socket handle.
00860                                     On a non-blocking connect a possible negative value is SL_EALREADY.
00861                                     On failure, negative value.
00862                                     SL_POOL_IS_EMPTY may be return in case there are no resources in the system
00863                                       In this case try again later or increase MAX_CONCURRENT_ACTIONS
00864 
00865         \sa                         sl_Socket
00866         \note                       belongs to \ref client_side
00867         \warning
00868     */
00869 #if _SL_INCLUDE_FUNC(sl_Connect)
00870     int16_t sl_Connect(int16_t sd, const SlSockAddr_t *addr, int16_t addrlen);
00871 #endif
00872 
00873     /*!
00874         \brief Monitor socket activity
00875 
00876         Select allow a program to monitor multiple file descriptors,
00877         waiting until one or more of the file descriptors become
00878         "ready" for some class of I/O operation
00879 
00880 
00881         \param[in]  nfds        the highest-numbered file descriptor in any of the
00882                                 three sets, plus 1.
00883         \param[out] readsds     socket descriptors list for read monitoring and accept monitoring
00884         \param[out] writesds    socket descriptors list for connect monitoring only, write monitoring is not supported, non blocking connect is supported
00885         \param[out] exceptsds   socket descriptors list for exception monitoring, not supported.
00886         \param[in]  timeout     is an upper bound on the amount of time elapsed
00887                                 before select() returns. Null or above 0xffff seconds means
00888                                 infinity timeout. The minimum timeout is 10 milliseconds,
00889                                 less than 10 milliseconds will be set automatically to 10 milliseconds.
00890                                 Max microseconds supported is 0xfffc00.
00891 
00892         \return                    On success, select()  returns the number of
00893                                 file descriptors contained in the three returned
00894                                 descriptor sets (that is, the total number of bits that
00895                                 are set in readfds, writefds, exceptfds) which may be
00896                                 zero if the timeout expires before anything interesting
00897                                 happens. On error, a negative value is returned.
00898                                 readsds - return the sockets on which Read request will
00899                                 return without delay with valid data.
00900                                 writesds - return the sockets on which Write request
00901                                 will return without delay.
00902                                 exceptsds - return the sockets closed recently.
00903                                 SL_POOL_IS_EMPTY may be return in case there are no resources in the system
00904                                    In this case try again later or increase MAX_CONCURRENT_ACTIONS
00905 
00906         \sa     sl_Socket
00907         \note   If the timeout value set to less than 5ms it will automatically set
00908                 to 5ms to prevent overload of the system
00909                 belongs to \ref basic_api
00910 
00911                 Only one sl_Select can be handled at a time.
00912                 Calling this API while the same command is called from another thread, may result
00913                     in one of the two scenarios:
00914                 1. The command will wait (internal) until the previous command finish, and then be executed.
00915                 2. There are not enough resources and SL_POOL_IS_EMPTY error will return.
00916                 In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try
00917                 again later to issue the command.
00918 
00919         \warning
00920     */
00921 #if _SL_INCLUDE_FUNC(sl_Select)
00922     int16_t sl_Select(int16_t nfds, SlFdSet_t *readsds, SlFdSet_t *writesds, SlFdSet_t *exceptsds, SlTimeval_t *timeout);
00923 
00924 
00925     /*!
00926         \brief Select's SlFdSet_t SET function
00927 
00928         Sets current socket descriptor on SlFdSet_t container
00929     */
00930     void SL_FD_SET(int16_t fd, SlFdSet_t *fdset);
00931 
00932     /*!
00933         \brief Select's SlFdSet_t CLR function
00934 
00935         Clears current socket descriptor on SlFdSet_t container
00936     */
00937     void SL_FD_CLR(int16_t fd, SlFdSet_t *fdset);
00938 
00939 
00940     /*!
00941         \brief Select's SlFdSet_t ISSET function
00942 
00943         Checks if current socket descriptor is set (TRUE/FALSE)
00944 
00945         \return            Returns TRUE if set, FALSE if unset
00946 
00947     */
00948     int16_t  SL_FD_ISSET(int16_t fd, SlFdSet_t *fdset);
00949 
00950     /*!
00951         \brief Select's SlFdSet_t ZERO function
00952 
00953         Clears all socket descriptors from SlFdSet_t
00954     */
00955     void SL_FD_ZERO(SlFdSet_t *fdset);
00956 
00957 
00958 
00959 #endif
00960 
00961     /*!
00962         \brief set socket options
00963 
00964         This function manipulate the options associated with a socket.
00965         Options may exist at multiple protocol levels; they are always
00966         present at the uppermost socket level.
00967 
00968         When manipulating socket options the level at which the option resides
00969         and the name of the option must be specified.  To manipulate options at
00970         the socket level, level is specified as SOL_SOCKET.  To manipulate
00971         options at any other level the protocol number of the appropriate proto-
00972         col controlling the option is supplied.  For example, to indicate that an
00973         option is to be interpreted by the TCP protocol, level should be set to
00974         the protocol number of TCP;
00975 
00976         The parameters optval and optlen are used to access optval -
00977         ues for setsockopt().  For getsockopt() they identify a
00978         buffer in which the value for the requested option(s) are to
00979         be returned.  For getsockopt(), optlen is a value-result
00980         parameter, initially containing the size of the buffer
00981         pointed to by option_value, and modified on return to
00982         indicate the actual size of the value returned.  If no option
00983         value is to be supplied or returned, option_value may be
00984         NULL.
00985 
00986         \param[in] sd               socket handle
00987         \param[in] level            defines the protocol level for this option
00988                                     - <b>SL_SOL_SOCKET</b>   Socket level configurations (L4, transport layer)
00989                                     - <b>SL_IPPROTO_IP</b>   IP level configurations (L3, network layer)
00990                                     - <b>SL_SOL_PHY_OPT</b>  Link level configurations (L2, link layer)
00991         \param[in] optname          defines the option name to interrogate
00992                                     - <b>SL_SOL_SOCKET</b>
00993                                       - <b>SL_SO_KEEPALIVE</b>  \n
00994                                                      Enable/Disable periodic keep alive.
00995                                                      Keeps TCP connections active by enabling the periodic transmission of messages \n
00996                                                      Timeout is 5 minutes.\n
00997                                                      Default: Enabled \n
00998                                                      This options takes SlSockKeepalive_t struct as parameter
00999                                       - <b>SL_SO_RCVTIMEO</b>  \n
01000                                                      Sets the timeout value that specifies the maximum amount of time an input function waits until it completes. \n
01001                                                      Default: No timeout \n
01002                                                      This options takes SlTimeval_t struct as parameter
01003                                       - <b>SL_SO_RCVBUF</b>  \n
01004                                                      Sets tcp max recv window size. \n
01005                                                      This options takes SlSockWinsize_t struct as parameter
01006                                       - <b>SL_SO_NONBLOCKING</b> \n
01007                                                      Sets socket to non-blocking operation Impacts: connect, accept, send, sendto, recv and recvfrom. \n
01008                                                      Default: Blocking.
01009                                                      This options takes SlSockNonblocking_t struct as parameter
01010                                       - <b>SL_SO_SECMETHOD</b> \n
01011                                                      Sets method to tcp secured socket (SL_SEC_SOCKET) \n
01012                                                      Default: SL_SO_SEC_METHOD_SSLv3_TLSV1_2 \n
01013                                                      This options takes SlSockSecureMethod struct as parameter
01014                                       - <b>SL_SO_SEC_MASK</b> \n
01015                                                      Sets specific cipher to tcp secured socket (SL_SEC_SOCKET) \n
01016                                                      Default: "Best" cipher suitable to method \n
01017                                                      This options takes SlSockSecureMask struct as parameter
01018                                       - <b>SL_SO_SECURE_FILES_CA_FILE_NAME</b> \n
01019                                                      Map secured socket to CA file by name \n
01020                                                      This options takes <b>uint8_t</b> buffer as parameter
01021                                       - <b>SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME</b> \n
01022                                                      Map secured socket to private key by name \n
01023                                                      This options takes <b>uint8_t</b> buffer as parameter
01024                                       - <b>SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME</b> \n
01025                                                      Map secured socket to certificate file by name \n
01026                                                      This options takes <b>uint8_t</b> buffer as parameter
01027                                       - <b>SL_SO_SECURE_FILES_DH_KEY_FILE_NAME</b> \n
01028                                                      Map secured socket to Diffie Hellman file by name \n
01029                                                      This options takes <b>uint8_t</b> buffer as parameter
01030                                       - <b>SL_SO_CHANGE_CHANNEL</b> \n
01031                                                      Sets channel in transceiver mode.
01032                                                      This options takes <b>uint32_t</b> as channel number parameter
01033                                     - <b>SL_IPPROTO_IP</b>
01034                                       - <b>SL_IP_MULTICAST_TTL</b> \n
01035                                                      Set the time-to-live value of outgoing multicast packets for this socket. \n
01036                                                      This options takes <b>uint8_t</b> as parameter
01037                                       - <b>SL_IP_ADD_MEMBERSHIP</b> \n
01038                                                      UDP socket, Join a multicast group. \n
01039                                                      This options takes SlSockIpMreq struct as parameter
01040                                       - <b>SL_IP_DROP_MEMBERSHIP</b> \n
01041                                                      UDP socket, Leave a multicast group \n
01042                                                      This options takes SlSockIpMreq struct as parameter
01043                                       - <b>SL_IP_RAW_RX_NO_HEADER</b> \n
01044                                                      Raw socket remove IP header from received data. \n
01045                                                      Default: data includes ip header \n
01046                                                      This options takes <b>uint32_t</b> as parameter
01047                                       - <b>SL_IP_HDRINCL</b> \n
01048                                                      RAW socket only, the IPv4 layer generates an IP header when sending a packet unless \n
01049                                                      the IP_HDRINCL socket option is enabled on the socket.    \n
01050                                                      When it is enabled, the packet must contain an IP header. \n
01051                                                      Default: disabled, IPv4 header generated by Network Stack \n
01052                                                      This options takes <b>uint32_t</b> as parameter
01053                                       - <b>SL_IP_RAW_IPV6_HDRINCL</b> (inactive) \n
01054                                                      RAW socket only, the IPv6 layer generates an IP header when sending a packet unless \n
01055                                                      the IP_HDRINCL socket option is enabled on the socket. When it is enabled, the packet must contain an IP header \n
01056                                                      Default: disabled, IPv4 header generated by Network Stack \n
01057                                                      This options takes <b>uint32_t</b> as parameter
01058                                     - <b>SL_SOL_PHY_OPT</b>
01059                                       - <b>SL_SO_PHY_RATE</b> \n
01060                                                      RAW socket, set WLAN PHY transmit rate \n
01061                                                      The values are based on RateIndex_e    \n
01062                                                      This options takes <b>uint32_t</b> as parameter
01063                                       - <b>SL_SO_PHY_TX_POWER</b> \n
01064                                                      RAW socket, set WLAN PHY TX power \n
01065                                                      Valid rage is 1-15 \n
01066                                                      This options takes <b>uint32_t</b> as parameter
01067                                       - <b>SL_SO_PHY_NUM_FRAMES_TO_TX</b> \n
01068                                                      RAW socket, set number of frames to transmit in transceiver mode.
01069                                                      Default: 1 packet
01070                                                      This options takes <b>uint32_t</b> as parameter
01071                                       - <b>SL_SO_PHY_PREAMBLE</b> \n
01072                                                      RAW socket, set WLAN PHY preamble for Long/Short\n
01073                                                      This options takes <b>uint32_t</b> as parameter
01074 
01075         \param[in] optval           specifies a value for the option
01076         \param[in] optlen           specifies the length of the
01077             option value
01078 
01079         \return                     On success, zero is returned.
01080                                     On error, a negative value is returned.
01081         \sa     sl_getsockopt
01082         \note   belongs to \ref basic_api
01083         \warning
01084         \par   Examples:
01085         \par
01086         <b> SL_SO_KEEPALIVE: </b>(disable Keepalive)
01087         \code
01088                SlSockKeepalive_t enableOption;
01089                enableOption.KeepaliveEnabled = 0;
01090                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_KEEPALIVE, (uint8_t *)&enableOption,sizeof(enableOption));
01091         \endcode
01092         \par
01093         <b> SL_SO_RCVTIMEO: </b>
01094         \code
01095                struct SlTimeval_t timeVal;
01096                timeVal.tv_sec =  1;             // Seconds
01097                timeVal.tv_usec = 0;             // Microseconds. 10000 microseconds resolution
01098                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_RCVTIMEO, (uint8_t *)&timeVal, sizeof(timeVal));    // Enable receive timeout
01099         \endcode
01100         \par
01101         <b>    SL_SO_RCVBUF: </b>
01102         \code
01103                SlSockWinsize_t size;
01104                size.Winsize = 3000;  // bytes
01105                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_RCVBUF, (uint8_t *)&size, sizeof(size));
01106         \endcode
01107         \par
01108         <b>    SL_SO_NONBLOCKING: </b>
01109         \code
01110                SlSockNonblocking_t enableOption;
01111                enableOption.NonblockingEnabled = 1;
01112                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_NONBLOCKING, (uint8_t *)&enableOption,sizeof(enableOption)); // Enable/disable nonblocking mode
01113         \endcode
01114         \par
01115         <b>    SL_SO_SECMETHOD:</b>
01116         \code
01117                SlSockSecureMethod method;
01118                method.secureMethod = SL_SO_SEC_METHOD_SSLV3;                                 // security method we want to use
01119                SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET);
01120                sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SECMETHOD, (uint8_t *)&method, sizeof(method));
01121         \endcode
01122         \par
01123         <b>   SL_SO_SECURE_MASK:</b>
01124         \code
01125                SlSockSecureMask cipher;
01126                cipher.secureMask = SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA;                   // cipher type
01127                SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET);
01128                sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SEC_MASK,(uint8_t *)&cipher, sizeof(cipher));
01129         \endcode
01130         \par
01131         <b>   SL_SO_SECURE_FILES_CA_FILE_NAME:</b>
01132         \code
01133                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CA_FILE_NAME,"exuifaxCaCert.der",strlen("exuifaxCaCert.der"));
01134          \endcode
01135 
01136        \par
01137         <b>   SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME:</b>
01138          \code
01139                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME,"myPrivateKey.der",strlen("myPrivateKey.der"));
01140          \endcode
01141 
01142        \par
01143         <b>   SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME:</b>
01144          \code
01145                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME,"myCertificate.der",strlen("myCertificate.der"));
01146          \endcode
01147 
01148        \par
01149         <b>   SL_SO_SECURE_FILES_DH_KEY_FILE_NAME:</b>
01150          \code
01151                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_DH_KEY_FILE_NAME,"myDHinServerMode.der",strlen("myDHinServerMode.der"));
01152          \endcode
01153 
01154        \par
01155         <b>   SL_IP_MULTICAST_TTL:</b>
01156          \code
01157                uint8_t ttl = 20;
01158                sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_MULTICAST_TTL, &ttl, sizeof(ttl));
01159          \endcode
01160 
01161        \par
01162         <b>   SL_IP_ADD_MEMBERSHIP:</b>
01163          \code
01164                SlSockIpMreq mreq;
01165                sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
01166         \endcode
01167 
01168        \par
01169         <b>   SL_IP_DROP_MEMBERSHIP:</b>
01170         \code
01171                SlSockIpMreq mreq;
01172                sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
01173         \endcode
01174 
01175        \par
01176         <b>   SL_SO_CHANGE_CHANNEL:</b>
01177         \code
01178               uint32_t newChannel = 6; // range is 1-13
01179               sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_CHANGE_CHANNEL, &newChannel, sizeof(newChannel));
01180         \endcode
01181 
01182         \par
01183         <b>   SL_IP_RAW_RX_NO_HEADER:</b>
01184         \code
01185               uint32_t header = 1;  // remove ip header
01186               sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_RAW_RX_NO_HEADER, &header, sizeof(header));
01187         \endcode
01188 
01189        \par
01190         <b>   SL_IP_HDRINCL:</b>
01191         \code
01192              uint32_t header = 1;
01193              sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_HDRINCL, &header, sizeof(header));
01194         \endcode
01195        \par
01196         <b>   SL_IP_RAW_IPV6_HDRINCL:</b>
01197         \code
01198               uint32_t header = 1;
01199               sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_RAW_IPV6_HDRINCL, &header, sizeof(header));
01200         \endcode
01201 
01202        \par
01203         <b>   SL_SO_PHY_RATE:</b>
01204         \code
01205               uint32_t rate = 6; // see wlan.h RateIndex_e for values
01206               sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_RATE, &rate, sizeof(rate));
01207         \endcode
01208 
01209        \par
01210         <b>   SL_SO_PHY_TX_POWER:</b>
01211         \code
01212               uint32_t txpower = 1; // valid range is 1-15
01213               sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_TX_POWER, &txpower, sizeof(txpower));
01214         \endcode
01215 
01216        \par
01217         <b>   SL_SO_PHY_NUM_FRAMES_TO_TX:</b>
01218         \code
01219               uint32_t numframes = 1;
01220               sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_NUM_FRAMES_TO_TX, &numframes, sizeof(numframes));
01221         \endcode
01222 
01223        \par
01224         <b>   SL_SO_PHY_PREAMBLE:</b>
01225         \code
01226               uint32_t preamble = 1;
01227               sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_PREAMBLE, &preamble, sizeof(preamble));
01228         \endcode
01229 
01230     */
01231 #if _SL_INCLUDE_FUNC(sl_SetSockOpt)
01232     int16_t sl_SetSockOpt(int16_t sd, int16_t level, int16_t optname, const void *optval, SlSocklen_t optlen);
01233 #endif
01234 
01235     /*!
01236         \brief Get socket options
01237 
01238         This function manipulate the options associated with a socket.
01239         Options may exist at multiple protocol levels; they are always
01240         present at the uppermost socket level.
01241 
01242         When manipulating socket options the level at which the option resides
01243         and the name of the option must be specified.  To manipulate options at
01244         the socket level, level is specified as SOL_SOCKET.  To manipulate
01245         options at any other level the protocol number of the appropriate proto-
01246         col controlling the option is supplied.  For example, to indicate that an
01247         option is to be interpreted by the TCP protocol, level should be set to
01248         the protocol number of TCP;
01249 
01250         The parameters optval and optlen are used to access optval -
01251         ues for setsockopt().  For getsockopt() they identify a
01252         buffer in which the value for the requested option(s) are to
01253         be returned.  For getsockopt(), optlen is a value-result
01254         parameter, initially containing the size of the buffer
01255         pointed to by option_value, and modified on return to
01256         indicate the actual size of the value returned.  If no option
01257         value is to be supplied or returned, option_value may be
01258         NULL.
01259 
01260 
01261         \param[in]  sd              socket handle
01262         \param[in]  level           defines the protocol level for this option
01263         \param[in]  optname         defines the option name to interrogate
01264         \param[out] optval          specifies a value for the option
01265         \param[out] optlen          specifies the length of the
01266                                     option value
01267 
01268         \return                        On success, zero is returned.
01269                                     On error, a negative value is returned.
01270         \sa     sl_SetSockOpt
01271         \note   See sl_SetSockOpt
01272                 belongs to \ref ext_api
01273         \warning
01274     */
01275 #if _SL_INCLUDE_FUNC(sl_GetSockOpt)
01276     int16_t sl_GetSockOpt(int16_t sd, int16_t level, int16_t optname, void *optval, SlSocklen_t *optlen);
01277 #endif
01278 
01279     /*!
01280         \brief read data from TCP socket
01281 
01282         function receives a message from a connection-mode socket
01283 
01284         \param[in]  sd              socket handle
01285         \param[out] buf             Points to the buffer where the
01286                                     message should be stored.
01287         \param[in]  Len             Specifies the length in bytes of
01288                                     the buffer pointed to by the buffer argument.
01289                                     Range: 1-16000 bytes
01290         \param[in]  flags           Specifies the type of message
01291                                     reception. On this version, this parameter is not
01292                                     supported.
01293 
01294         \return                     return the number of bytes received,
01295                                     or a negative value if an error occurred.
01296                                     using a non-blocking recv a possible negative value is SL_EAGAIN.
01297                                     SL_POOL_IS_EMPTY may be return in case there are no resources in the system
01298                                      In this case try again later or increase MAX_CONCURRENT_ACTIONS
01299 
01300         \sa     sl_RecvFrom
01301         \note                       belongs to \ref recv_api
01302         \warning
01303         \par        Examples:
01304         \code       An example of receiving data using TCP socket:
01305 
01306                     SlSockAddrIn_t  Addr;
01307                     SlSockAddrIn_t  LocalAddr;
01308                     int16_t AddrSize = sizeof(SlSockAddrIn_t);
01309                     int16_t SockID, newSockID;
01310                     int16_t Status;
01311                     int8_t Buf[RECV_BUF_LEN];
01312 
01313                     LocalAddr.sin_family = SL_AF_INET;
01314                     LocalAddr.sin_port = sl_Htons(5001);
01315                     LocalAddr.sin_addr.s_addr = 0;
01316 
01317                     Addr.sin_family = SL_AF_INET;
01318                     Addr.sin_port = sl_Htons(5001);
01319                     Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
01320 
01321                     SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
01322                     Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
01323                     Status = sl_Listen(SockID, 0);
01324                     newSockID = sl_Accept(SockID, (SlSockAddr_t*)&Addr, (SlSocklen_t*) &AddrSize);
01325                     Status = sl_Recv(newSockID, Buf, 1460, 0);
01326         \endcode
01327         \code      Example code for Rx transceiver mode using a raw socket
01328                    int8_t buffer[1536];
01329                    int16_t sd;
01330                    uint16_t size;
01331                    SlTransceiverRxOverHead_t *transHeader;
01332                    sd = sl_Socket(SL_AF_RF,SL_SOCK_RAW,11); // channel 11
01333                    while(1)
01334                    {
01335                       size = sl_Recv(sd,buffer,1536,0);
01336                       transHeader = (SlTransceiverRxOverHead_t *)buffer;
01337                       printf("RSSI is %d frame type is 0x%x size %d\n",transHeader->rssi,buffer[sizeof(SlTransceiverRxOverHead_t)],size);
01338                    }
01339         \endcode
01340     */
01341 #if _SL_INCLUDE_FUNC(sl_Recv)
01342     int16_t sl_Recv(int16_t sd, void *buf, int16_t Len, int16_t flags);
01343 #endif
01344 
01345     /*!
01346         \brief read data from socket
01347 
01348         function receives a message from a connection-mode or
01349         connectionless-mode socket
01350 
01351         \param[in]  sd              socket handle
01352         \param[out] buf             Points to the buffer where the message should be stored.
01353         \param[in]  Len             Specifies the length in bytes of the buffer pointed to by the buffer argument.
01354                                     Range: 1-16000 bytes
01355         \param[in]  flags           Specifies the type of message
01356                                     reception. On this version, this parameter is not
01357                                     supported.
01358         \param[in]  from            pointer to an address structure
01359                                     indicating the source
01360                                     address.\n sockaddr:\n - code
01361                                     for the address format. On this
01362                                     version only AF_INET is
01363                                     supported.\n - socket address,
01364                                     the length depends on the code
01365                                     format
01366         \param[in]  fromlen         source address structure
01367                                     size. This parameter MUST be set to the size of the structure pointed to by addr.
01368 
01369 
01370         \return                     return the number of bytes received,
01371                                     or a negative value if an error occurred.
01372                                     using a non-blocking recv a possible negative value is SL_EAGAIN.
01373                                     SL_RET_CODE_INVALID_INPUT (-2) will be returned if fromlen has incorrect length.
01374                                     SL_POOL_IS_EMPTY may be return in case there are no resources in the system
01375                                      In this case try again later or increase MAX_CONCURRENT_ACTIONS
01376 
01377         \sa     sl_Recv
01378         \note                       belongs to \ref recv_api
01379         \warning
01380         \par        Example:
01381         \code       An example of receiving data:
01382 
01383                     SlSockAddrIn_t  Addr;
01384                     SlSockAddrIn_t  LocalAddr;
01385                     int16_t AddrSize = sizeof(SlSockAddrIn_t);
01386                     int16_t SockID;
01387                     int16_t Status;
01388                     int8_t Buf[RECV_BUF_LEN];
01389 
01390                     LocalAddr.sin_family = SL_AF_INET;
01391                     LocalAddr.sin_port = sl_Htons(5001);
01392                     LocalAddr.sin_addr.s_addr = 0;
01393 
01394                     SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
01395                     Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
01396                     Status = sl_RecvFrom(SockID, Buf, 1472, 0, (SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize);
01397 
01398         \endcode
01399     */
01400 #if _SL_INCLUDE_FUNC(sl_RecvFrom)
01401     int16_t sl_RecvFrom(int16_t sd, void *buf, int16_t Len, int16_t flags, SlSockAddr_t *from, SlSocklen_t *fromlen);
01402 #endif
01403 
01404     /*!
01405         \brief write data to TCP socket
01406 
01407         This function is used to transmit a message to another socket.
01408         Returns immediately after sending data to device.
01409         In case of TCP failure an async event SL_SOCKET_TX_FAILED_EVENT is going to
01410         be received.
01411         In case of a RAW socket (transceiver mode), extra 4 bytes should be reserved at the end of the
01412         frame data buffer for WLAN FCS
01413 
01414         \param[in] sd               socket handle
01415         \param[in] buf              Points to a buffer containing
01416                                     the message to be sent
01417         \param[in] Len              message size in bytes. Range: 1-1460 bytes
01418         \param[in] flags            Specifies the type of message
01419                                     transmission. On this version, this parameter is not
01420                                     supported for TCP.
01421                                     For transceiver mode, the SL_RAW_RF_TX_PARAMS macro can be used to determine
01422                                     transmission parameters (channel,rate,tx_power,preamble)
01423 
01424 
01425         \return                     Return the number of bytes transmitted,
01426                                     or -1 if an error occurred
01427 
01428         \sa     sl_SendTo
01429         \note                       belongs to \ref send_api
01430         \warning
01431         \par        Example:
01432         \code       An example of sending data:
01433 
01434                     SlSockAddrIn_t  Addr;
01435                     int16_t AddrSize = sizeof(SlSockAddrIn_t);
01436                     int16_t SockID;
01437                     int16_t Status;
01438                     int8_t Buf[SEND_BUF_LEN];
01439 
01440                     Addr.sin_family = SL_AF_INET;
01441                     Addr.sin_port = sl_Htons(5001);
01442                     Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
01443 
01444                     SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
01445                     Status = sl_Connect(SockID, (SlSockAddr_t *)&Addr, AddrSize);
01446                     Status = sl_Send(SockID, Buf, 1460, 0 );
01447 
01448         \endcode
01449      */
01450 #if _SL_INCLUDE_FUNC(sl_Send )
01451     int16_t sl_Send(int16_t sd, const void *buf, int16_t Len, int16_t flags);
01452 #endif
01453 
01454     /*!
01455         \brief write data to socket
01456 
01457         This function is used to transmit a message to another socket
01458         (connection less socket SOCK_DGRAM,  SOCK_RAW).
01459         Returns immediately after sending data to device.
01460         In case of transmission failure an async event SL_SOCKET_TX_FAILED_EVENT is going to
01461         be received.
01462 
01463         \param[in] sd               socket handle
01464         \param[in] buf              Points to a buffer containing
01465                                     the message to be sent
01466         \param[in] Len              message size in bytes. Range: 1-1460 bytes
01467         \param[in] flags            Specifies the type of message
01468                                     transmission. On this version, this parameter is not
01469                                     supported
01470         \param[in] to               pointer to an address structure
01471                                     indicating the destination
01472                                     address.\n sockaddr:\n - code
01473                                     for the address format. On this
01474                                     version only AF_INET is
01475                                     supported.\n - socket address,
01476                                     the length depends on the code
01477                                     format
01478         \param[in] tolen            destination address structure size
01479 
01480         \return                     Return the number of transmitted bytes,
01481                                     or -1 if an error occurred
01482 
01483         \sa     sl_Send
01484         \note                       belongs to \ref send_api
01485         \warning
01486         \par        Example:
01487         \code       An example of sending data:
01488 
01489                     SlSockAddrIn_t  Addr;
01490                     int16_t AddrSize = sizeof(SlSockAddrIn_t);
01491                     int16_t SockID;
01492                     int16_t Status;
01493                     int8_t Buf[SEND_BUF_LEN];
01494 
01495                     Addr.sin_family = SL_AF_INET;
01496                     Addr.sin_port = sl_Htons(5001);
01497                     Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
01498 
01499                     SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
01500                     Status = sl_SendTo(SockID, Buf, 1472, 0, (SlSockAddr_t *)&Addr, AddrSize);
01501 
01502         \endcode
01503     */
01504 #if _SL_INCLUDE_FUNC(sl_SendTo)
01505     int16_t sl_SendTo(int16_t sd, const void *buf, int16_t Len, int16_t flags, const SlSockAddr_t *to, SlSocklen_t tolen);
01506 #endif
01507 
01508     /*!
01509         \brief Reorder the bytes of a 32-bit unsigned value
01510 
01511         This function is used to Reorder the bytes of a 32-bit unsigned value from processor order to network order.
01512 
01513         \param[in] var              variable to reorder
01514 
01515         \return                     Return the reorder variable,
01516 
01517         \sa     sl_SendTo  sl_Bind  sl_Connect  sl_RecvFrom  sl_Accept
01518         \note                       belongs to \ref send_api
01519         \warning
01520     */
01521 #if _SL_INCLUDE_FUNC(sl_Htonl )
01522     uint32_t sl_Htonl( uint32_t val );
01523 
01524 #define sl_Ntohl sl_Htonl  /* Reorder the bytes of a 16-bit unsigned value from network order to processor orde. */
01525 #endif
01526 
01527     /*!
01528         \brief Reorder the bytes of a 16-bit unsigned value
01529 
01530         This function is used to Reorder the bytes of a 16-bit unsigned value from processor order to network order.
01531 
01532         \param[in] var              variable to reorder
01533 
01534         \return                     Return the reorder variable,
01535 
01536         \sa     sl_SendTo  sl_Bind    sl_Connect  sl_RecvFrom  sl_Accept
01537         \note                       belongs to \ref send_api
01538         \warning
01539     */
01540 #if _SL_INCLUDE_FUNC(sl_Htons )
01541     uint16_t sl_Htons( uint16_t val );
01542 
01543 #define sl_Ntohs sl_Htons   /* Reorder the bytes of a 16-bit unsigned value from network order to processor orde. */
01544 #endif
01545 
01546 private:
01547 
01548     cc3100_driver   &_driver;
01549     cc3100_nonos    &_nonos;
01550     
01551 };//class
01552 
01553 
01554 }//namespace mbed_cc3100    
01555 
01556     /*!
01557 
01558      Close the Doxygen group.
01559      @}
01560 
01561      */
01562 
01563 #endif /* __SOCKET_H__ */
01564 
01565 
01566