TI's CC3100 websocket camera demo with Arducam mini ov5642 and freertos. Should work with other M3's. Work in progress test demo.

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 #ifndef SL_PLATFORM_MULTI_THREADED
00635     cc3100_socket(cc3100_driver &driver, cc3100_nonos &nonos);
00636 #else
00637     cc3100_socket(cc3100_driver &driver);
00638 #endif
00639     ~cc3100_socket();
00640 
00641     /*******************************************************************************/
00642     /* Functions prototypes                                                        */
00643     /*******************************************************************************/
00644     void   _sl_BuildAddress(const SlSockAddr_t *addr, _SocketAddrCommand_u *pCmd);
00645     void   _sl_ParseAddress(_SocketAddrResponse_u *pRsp, SlSockAddr_t *addr, SlSocklen_t *addrlen);
00646     uint16_t   _sl_TruncatePayloadByProtocol(const int16_t pSd,const uint16_t length);
00647 
00648     /*****************************************************************************/
00649     /* Function prototypes                                                       */
00650     /*****************************************************************************/
00651 
00652     /*!
00653 
00654         \brief create an endpoint for communication
00655 
00656         The socket function creates a new socket of a certain socket type, identified
00657         by an integer number, and allocates system resources to it.
00658         This function is called by the application layer to obtain a socket handle.
00659 
00660         \param[in] domain           specifies the protocol family of the created socket.
00661                                     For example:
00662                                        AF_INET for network protocol IPv4
00663                                        AF_RF for starting transceiver mode. Notes:
00664                                        - sending and receiving any packet overriding 802.11 header
00665                                        - for optimized power consumption the socket will be started in TX
00666                                          only mode until receive command is activated
00667                                        AF_INET6 for IPv6
00668 
00669 
00670         \param[in] type              specifies the communication semantic, one of:
00671                                        SOCK_STREAM (reliable stream-oriented service or Stream Sockets)
00672                                        SOCK_DGRAM (datagram service or Datagram Sockets)
00673                                        SOCK_RAW (raw protocols atop the network layer)
00674                                        when used with AF_RF:
00675                                                                          SOCK_DGRAM - L2 socket
00676                                                                          SOCK_RAW - L1 socket - bypass WLAN CCA (Clear Channel Assessment)
00677 
00678         \param[in] protocol         specifies a particular transport to be used with
00679                                     the socket.
00680                                     The most common are IPPROTO_TCP, IPPROTO_SCTP, IPPROTO_UDP,
00681                                     IPPROTO_DCCP.
00682                                     The value 0 may be used to select a default
00683                                     protocol from the selected domain and type
00684 
00685 
00686         \return                     On success, socket handle that is used for consequent socket operations.
00687                                     A successful return code should be a positive number (int16)
00688                                     On error, a negative (int16) value will be returned specifying the error code.
00689                                SL_EAFNOSUPPORT  - illegal domain parameter
00690                                SL_EPROTOTYPE  - illegal type parameter
00691                                SL_EACCES   - permission denied
00692                                SL_ENSOCK  - exceeded maximal number of socket
00693                                SL_ENOMEM  - memory allocation error
00694                                SL_EINVAL  - error in socket configuration
00695                                SL_EPROTONOSUPPORT  - illegal protocol parameter
00696                                SL_EOPNOTSUPP  - illegal combination of protocol and type parameters
00697 
00698 
00699         \sa                         sl_Close
00700         \note                       belongs to \ref basic_api
00701         \warning
00702     */
00703 #if _SL_INCLUDE_FUNC(sl_Socket)
00704     int16_t sl_Socket(int16_t Domain, int16_t Type, int16_t Protocol);
00705 #endif
00706 
00707     /*!
00708         \brief gracefully close socket
00709 
00710         This function causes the system to release resources allocated to a socket.  \n
00711         In case of TCP, the connection is terminated.
00712 
00713         \param[in] sd               socket handle (received in sl_Socket)
00714 
00715         \return                        On success, zero is returned.
00716                                     On error, a negative number is returned.
00717 
00718         \sa                         sl_Socket
00719         \note                       belongs to \ref ext_api
00720         \warning
00721     */
00722 #if _SL_INCLUDE_FUNC(sl_Close)
00723     int16_t sl_Close(int16_t sd);
00724 #endif
00725 
00726     /*!
00727         \brief Accept a connection on a socket
00728 
00729         This function is used with connection-based socket types (SOCK_STREAM).
00730         It extracts the first connection request on the queue of pending
00731         connections, creates a new connected socket, and returns a new file
00732         descriptor referring to that socket.
00733         The newly created socket is not in the listening state. The
00734         original socket sd is unaffected by this call.
00735         The argument sd is a socket that has been created with
00736         sl_Socket(), bound to a local address with sl_Bind(), and is
00737         listening for connections after a sl_Listen(). The argument \b
00738         \e addr is a pointer to a sockaddr structure. This structure
00739         is filled in with the address of the peer socket, as known to
00740         the communications layer. The exact format of the address
00741         returned addr is determined by the socket's address family.
00742         The \b \e addrlen argument is a value-result argument: it
00743         should initially contain the size of the structure pointed to
00744         by addr, on return it will contain the actual length (in
00745         bytes) of the address returned.
00746 
00747         \param[in] sd               socket descriptor (handle)
00748         \param[out] addr            the argument addr is a pointer
00749                                     to a sockaddr structure. This
00750                                     structure is filled in with the
00751                                     address of the peer socket, as
00752                                     known to the communications
00753                                     layer. The exact format of the
00754                                     address returned addr is
00755                                     determined by the socket's
00756                                     address\n
00757                                     sockaddr:\n - code for the
00758                                     address format. On this version
00759                                     only AF_INET is supported.\n -
00760                                     socket address, the length
00761                                     depends on the code format
00762         \param[out] addrlen         the addrlen argument is a value-result
00763                                     argument: it should initially contain the
00764                                     size of the structure pointed to by addr
00765 
00766         \return                        On success, a socket handle.
00767                                     On a non-blocking accept a possible negative value is SL_EAGAIN.
00768                                     On failure, negative value.
00769                                     SL_POOL_IS_EMPTY may be return in case there are no resources in the system
00770                                      In this case try again later or increase MAX_CONCURRENT_ACTIONS
00771 
00772         \sa                         sl_Socket  sl_Bind  sl_Listen
00773         \note                       belongs to \ref server_side
00774         \warning
00775     */
00776 #if _SL_INCLUDE_FUNC(sl_Accept)
00777     int16_t sl_Accept(int16_t sd, SlSockAddr_t *addr, SlSocklen_t *addrlen);
00778 #endif
00779 
00780     /*!
00781         \brief assign a name to a socket
00782 
00783         This function gives the socket the local address addr.
00784         addr is addrlen bytes long. Traditionally, this is called
00785         When a socket is created with socket, it exists in a name
00786         space (address family) but has no name assigned.
00787         It is necessary to assign a local address before a SOCK_STREAM
00788         socket may receive connections.
00789 
00790         \param[in] sd                socket descriptor (handle)
00791         \param[in] addr              specifies the destination
00792                                     addrs\n sockaddr:\n - code for
00793                                     the address format. On this
00794                                     version only AF_INET is
00795                                     supported.\n - socket address,
00796                                     the length depends on the code
00797                                     format
00798         \param[in] addrlen          contains the size of the structure pointed to by addr
00799 
00800         \return                        On success, zero is returned. On error, a negative error code is returned.
00801 
00802         \sa                         sl_Socket  sl_Accept sl_Listen
00803         \note                       belongs to \ref basic_api
00804         \warning
00805     */
00806 #if _SL_INCLUDE_FUNC(sl_Bind)
00807     int16_t sl_Bind(int16_t sd, const SlSockAddr_t *addr, int16_t addrlen);
00808 #endif
00809 
00810     /*!
00811         \brief listen for connections on a socket
00812 
00813         The willingness to accept incoming connections and a queue
00814         limit for incoming connections are specified with listen(),
00815         and then the connections are accepted with accept.
00816         The listen() call applies only to sockets of type SOCK_STREAM
00817         The backlog parameter defines the maximum length the queue of
00818         pending connections may grow to.
00819 
00820         \param[in] sd               socket descriptor (handle)
00821         \param[in] backlog          specifies the listen queue depth.
00822 
00823 
00824         \return                    On success, zero is returned. On error, a negative error code is returned.
00825 
00826         \sa                         sl_Socket  sl_Accept  sl_Bind
00827         \note                       belongs to \ref server_side
00828         \warning
00829     */
00830 #if _SL_INCLUDE_FUNC(sl_Listen)
00831     int16_t sl_Listen(int16_t sd, int16_t backlog);
00832 #endif
00833 
00834     /*!
00835         \brief Initiate a connection on a socket
00836 
00837         Function connects the socket referred to by the socket
00838         descriptor sd, to the address specified by addr. The addrlen
00839         argument specifies the size of addr. The format of the
00840         address in addr is determined by the address space of the
00841         socket. If it is of type SOCK_DGRAM, this call specifies the
00842         peer with which the socket is to be associated; this address
00843         is that to which datagrams are to be sent, and the only
00844         address from which datagrams are to be received.  If the
00845         socket is of type SOCK_STREAM, this call attempts to make a
00846         connection to another socket. The other socket is specified
00847         by address, which is an address in the communications space
00848         of the socket.
00849 
00850 
00851         \param[in] sd               socket descriptor (handle)
00852         \param[in] addr             specifies the destination addr\n
00853                                     sockaddr:\n - code for the
00854                                     address format. On this version
00855                                     only AF_INET is supported.\n -
00856                                     socket address, the length
00857                                     depends on the code format
00858 
00859         \param[in] addrlen          contains the size of the structure pointed
00860                                     to by addr
00861 
00862         \return                     On success, a socket handle.
00863                                     On a non-blocking connect a possible negative value is SL_EALREADY.
00864                                     On failure, negative value.
00865                                     SL_POOL_IS_EMPTY may be return in case there are no resources in the system
00866                                       In this case try again later or increase MAX_CONCURRENT_ACTIONS
00867 
00868         \sa                         sl_Socket
00869         \note                       belongs to \ref client_side
00870         \warning
00871     */
00872 #if _SL_INCLUDE_FUNC(sl_Connect)
00873     int16_t sl_Connect(int16_t sd, const SlSockAddr_t *addr, int16_t addrlen);
00874 #endif
00875 
00876     /*!
00877         \brief Monitor socket activity
00878 
00879         Select allow a program to monitor multiple file descriptors,
00880         waiting until one or more of the file descriptors become
00881         "ready" for some class of I/O operation
00882 
00883 
00884         \param[in]  nfds        the highest-numbered file descriptor in any of the
00885                                 three sets, plus 1.
00886         \param[out] readsds     socket descriptors list for read monitoring and accept monitoring
00887         \param[out] writesds    socket descriptors list for connect monitoring only, write monitoring is not supported, non blocking connect is supported
00888         \param[out] exceptsds   socket descriptors list for exception monitoring, not supported.
00889         \param[in]  timeout     is an upper bound on the amount of time elapsed
00890                                 before select() returns. Null or above 0xffff seconds means
00891                                 infinity timeout. The minimum timeout is 10 milliseconds,
00892                                 less than 10 milliseconds will be set automatically to 10 milliseconds.
00893                                 Max microseconds supported is 0xfffc00.
00894 
00895         \return                    On success, select()  returns the number of
00896                                 file descriptors contained in the three returned
00897                                 descriptor sets (that is, the total number of bits that
00898                                 are set in readfds, writefds, exceptfds) which may be
00899                                 zero if the timeout expires before anything interesting
00900                                 happens. On error, a negative value is returned.
00901                                 readsds - return the sockets on which Read request will
00902                                 return without delay with valid data.
00903                                 writesds - return the sockets on which Write request
00904                                 will return without delay.
00905                                 exceptsds - return the sockets closed recently.
00906                                 SL_POOL_IS_EMPTY may be return in case there are no resources in the system
00907                                    In this case try again later or increase MAX_CONCURRENT_ACTIONS
00908 
00909         \sa     sl_Socket
00910         \note   If the timeout value set to less than 5ms it will automatically set
00911                 to 5ms to prevent overload of the system
00912                 belongs to \ref basic_api
00913 
00914                 Only one sl_Select can be handled at a time.
00915                 Calling this API while the same command is called from another thread, may result
00916                     in one of the two scenarios:
00917                 1. The command will wait (internal) until the previous command finish, and then be executed.
00918                 2. There are not enough resources and SL_POOL_IS_EMPTY error will return.
00919                 In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try
00920                 again later to issue the command.
00921 
00922         \warning
00923     */
00924 #if _SL_INCLUDE_FUNC(sl_Select)
00925     int16_t sl_Select(int16_t nfds, SlFdSet_t *readsds, SlFdSet_t *writesds, SlFdSet_t *exceptsds, SlTimeval_t *timeout);
00926 
00927 
00928     /*!
00929         \brief Select's SlFdSet_t SET function
00930 
00931         Sets current socket descriptor on SlFdSet_t container
00932     */
00933     void SL_FD_SET(int16_t fd, SlFdSet_t *fdset);
00934 
00935     /*!
00936         \brief Select's SlFdSet_t CLR function
00937 
00938         Clears current socket descriptor on SlFdSet_t container
00939     */
00940     void SL_FD_CLR(int16_t fd, SlFdSet_t *fdset);
00941 
00942 
00943     /*!
00944         \brief Select's SlFdSet_t ISSET function
00945 
00946         Checks if current socket descriptor is set (TRUE/FALSE)
00947 
00948         \return            Returns TRUE if set, FALSE if unset
00949 
00950     */
00951     int16_t  SL_FD_ISSET(int16_t fd, SlFdSet_t *fdset);
00952 
00953     /*!
00954         \brief Select's SlFdSet_t ZERO function
00955 
00956         Clears all socket descriptors from SlFdSet_t
00957     */
00958     void SL_FD_ZERO(SlFdSet_t *fdset);
00959 
00960 
00961 
00962 #endif
00963 
00964     /*!
00965         \brief set socket options
00966 
00967         This function manipulate the options associated with a socket.
00968         Options may exist at multiple protocol levels; they are always
00969         present at the uppermost socket level.
00970 
00971         When manipulating socket options the level at which the option resides
00972         and the name of the option must be specified.  To manipulate options at
00973         the socket level, level is specified as SOL_SOCKET.  To manipulate
00974         options at any other level the protocol number of the appropriate proto-
00975         col controlling the option is supplied.  For example, to indicate that an
00976         option is to be interpreted by the TCP protocol, level should be set to
00977         the protocol number of TCP;
00978 
00979         The parameters optval and optlen are used to access optval -
00980         ues for setsockopt().  For getsockopt() they identify a
00981         buffer in which the value for the requested option(s) are to
00982         be returned.  For getsockopt(), optlen is a value-result
00983         parameter, initially containing the size of the buffer
00984         pointed to by option_value, and modified on return to
00985         indicate the actual size of the value returned.  If no option
00986         value is to be supplied or returned, option_value may be
00987         NULL.
00988 
00989         \param[in] sd               socket handle
00990         \param[in] level            defines the protocol level for this option
00991                                     - <b>SL_SOL_SOCKET</b>   Socket level configurations (L4, transport layer)
00992                                     - <b>SL_IPPROTO_IP</b>   IP level configurations (L3, network layer)
00993                                     - <b>SL_SOL_PHY_OPT</b>  Link level configurations (L2, link layer)
00994         \param[in] optname          defines the option name to interrogate
00995                                     - <b>SL_SOL_SOCKET</b>
00996                                       - <b>SL_SO_KEEPALIVE</b>  \n
00997                                                      Enable/Disable periodic keep alive.
00998                                                      Keeps TCP connections active by enabling the periodic transmission of messages \n
00999                                                      Timeout is 5 minutes.\n
01000                                                      Default: Enabled \n
01001                                                      This options takes SlSockKeepalive_t struct as parameter
01002                                       - <b>SL_SO_RCVTIMEO</b>  \n
01003                                                      Sets the timeout value that specifies the maximum amount of time an input function waits until it completes. \n
01004                                                      Default: No timeout \n
01005                                                      This options takes SlTimeval_t struct as parameter
01006                                       - <b>SL_SO_RCVBUF</b>  \n
01007                                                      Sets tcp max recv window size. \n
01008                                                      This options takes SlSockWinsize_t struct as parameter
01009                                       - <b>SL_SO_NONBLOCKING</b> \n
01010                                                      Sets socket to non-blocking operation Impacts: connect, accept, send, sendto, recv and recvfrom. \n
01011                                                      Default: Blocking.
01012                                                      This options takes SlSockNonblocking_t struct as parameter
01013                                       - <b>SL_SO_SECMETHOD</b> \n
01014                                                      Sets method to tcp secured socket (SL_SEC_SOCKET) \n
01015                                                      Default: SL_SO_SEC_METHOD_SSLv3_TLSV1_2 \n
01016                                                      This options takes SlSockSecureMethod struct as parameter
01017                                       - <b>SL_SO_SEC_MASK</b> \n
01018                                                      Sets specific cipher to tcp secured socket (SL_SEC_SOCKET) \n
01019                                                      Default: "Best" cipher suitable to method \n
01020                                                      This options takes SlSockSecureMask struct as parameter
01021                                       - <b>SL_SO_SECURE_FILES_CA_FILE_NAME</b> \n
01022                                                      Map secured socket to CA file by name \n
01023                                                      This options takes <b>uint8_t</b> buffer as parameter
01024                                       - <b>SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME</b> \n
01025                                                      Map secured socket to private key by name \n
01026                                                      This options takes <b>uint8_t</b> buffer as parameter
01027                                       - <b>SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME</b> \n
01028                                                      Map secured socket to certificate file by name \n
01029                                                      This options takes <b>uint8_t</b> buffer as parameter
01030                                       - <b>SL_SO_SECURE_FILES_DH_KEY_FILE_NAME</b> \n
01031                                                      Map secured socket to Diffie Hellman file by name \n
01032                                                      This options takes <b>uint8_t</b> buffer as parameter
01033                                       - <b>SL_SO_CHANGE_CHANNEL</b> \n
01034                                                      Sets channel in transceiver mode.
01035                                                      This options takes <b>uint32_t</b> as channel number parameter
01036                                     - <b>SL_IPPROTO_IP</b>
01037                                       - <b>SL_IP_MULTICAST_TTL</b> \n
01038                                                      Set the time-to-live value of outgoing multicast packets for this socket. \n
01039                                                      This options takes <b>uint8_t</b> as parameter
01040                                       - <b>SL_IP_ADD_MEMBERSHIP</b> \n
01041                                                      UDP socket, Join a multicast group. \n
01042                                                      This options takes SlSockIpMreq struct as parameter
01043                                       - <b>SL_IP_DROP_MEMBERSHIP</b> \n
01044                                                      UDP socket, Leave a multicast group \n
01045                                                      This options takes SlSockIpMreq struct as parameter
01046                                       - <b>SL_IP_RAW_RX_NO_HEADER</b> \n
01047                                                      Raw socket remove IP header from received data. \n
01048                                                      Default: data includes ip header \n
01049                                                      This options takes <b>uint32_t</b> as parameter
01050                                       - <b>SL_IP_HDRINCL</b> \n
01051                                                      RAW socket only, the IPv4 layer generates an IP header when sending a packet unless \n
01052                                                      the IP_HDRINCL socket option is enabled on the socket.    \n
01053                                                      When it is enabled, the packet must contain an IP header. \n
01054                                                      Default: disabled, IPv4 header generated by Network Stack \n
01055                                                      This options takes <b>uint32_t</b> as parameter
01056                                       - <b>SL_IP_RAW_IPV6_HDRINCL</b> (inactive) \n
01057                                                      RAW socket only, the IPv6 layer generates an IP header when sending a packet unless \n
01058                                                      the IP_HDRINCL socket option is enabled on the socket. When it is enabled, the packet must contain an IP header \n
01059                                                      Default: disabled, IPv4 header generated by Network Stack \n
01060                                                      This options takes <b>uint32_t</b> as parameter
01061                                     - <b>SL_SOL_PHY_OPT</b>
01062                                       - <b>SL_SO_PHY_RATE</b> \n
01063                                                      RAW socket, set WLAN PHY transmit rate \n
01064                                                      The values are based on RateIndex_e    \n
01065                                                      This options takes <b>uint32_t</b> as parameter
01066                                       - <b>SL_SO_PHY_TX_POWER</b> \n
01067                                                      RAW socket, set WLAN PHY TX power \n
01068                                                      Valid rage is 1-15 \n
01069                                                      This options takes <b>uint32_t</b> as parameter
01070                                       - <b>SL_SO_PHY_NUM_FRAMES_TO_TX</b> \n
01071                                                      RAW socket, set number of frames to transmit in transceiver mode.
01072                                                      Default: 1 packet
01073                                                      This options takes <b>uint32_t</b> as parameter
01074                                       - <b>SL_SO_PHY_PREAMBLE</b> \n
01075                                                      RAW socket, set WLAN PHY preamble for Long/Short\n
01076                                                      This options takes <b>uint32_t</b> as parameter
01077 
01078         \param[in] optval           specifies a value for the option
01079         \param[in] optlen           specifies the length of the
01080             option value
01081 
01082         \return                     On success, zero is returned.
01083                                     On error, a negative value is returned.
01084         \sa     sl_getsockopt
01085         \note   belongs to \ref basic_api
01086         \warning
01087         \par   Examples:
01088         \par
01089         <b> SL_SO_KEEPALIVE: </b>(disable Keepalive)
01090         \code
01091                SlSockKeepalive_t enableOption;
01092                enableOption.KeepaliveEnabled = 0;
01093                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_KEEPALIVE, (uint8_t *)&enableOption,sizeof(enableOption));
01094         \endcode
01095         \par
01096         <b> SL_SO_RCVTIMEO: </b>
01097         \code
01098                struct SlTimeval_t timeVal;
01099                timeVal.tv_sec =  1;             // Seconds
01100                timeVal.tv_usec = 0;             // Microseconds. 10000 microseconds resolution
01101                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_RCVTIMEO, (uint8_t *)&timeVal, sizeof(timeVal));    // Enable receive timeout
01102         \endcode
01103         \par
01104         <b>    SL_SO_RCVBUF: </b>
01105         \code
01106                SlSockWinsize_t size;
01107                size.Winsize = 3000;  // bytes
01108                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_RCVBUF, (uint8_t *)&size, sizeof(size));
01109         \endcode
01110         \par
01111         <b>    SL_SO_NONBLOCKING: </b>
01112         \code
01113                SlSockNonblocking_t enableOption;
01114                enableOption.NonblockingEnabled = 1;
01115                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_NONBLOCKING, (uint8_t *)&enableOption,sizeof(enableOption)); // Enable/disable nonblocking mode
01116         \endcode
01117         \par
01118         <b>    SL_SO_SECMETHOD:</b>
01119         \code
01120                SlSockSecureMethod method;
01121                method.secureMethod = SL_SO_SEC_METHOD_SSLV3;                                 // security method we want to use
01122                SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET);
01123                sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SECMETHOD, (uint8_t *)&method, sizeof(method));
01124         \endcode
01125         \par
01126         <b>   SL_SO_SECURE_MASK:</b>
01127         \code
01128                SlSockSecureMask cipher;
01129                cipher.secureMask = SL_SEC_MASK_SSL_RSA_WITH_RC4_128_SHA;                   // cipher type
01130                SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, SL_SEC_SOCKET);
01131                sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_SEC_MASK,(uint8_t *)&cipher, sizeof(cipher));
01132         \endcode
01133         \par
01134         <b>   SL_SO_SECURE_FILES_CA_FILE_NAME:</b>
01135         \code
01136                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CA_FILE_NAME,"exuifaxCaCert.der",strlen("exuifaxCaCert.der"));
01137          \endcode
01138 
01139        \par
01140         <b>   SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME:</b>
01141          \code
01142                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_PRIVATE_KEY_FILE_NAME,"myPrivateKey.der",strlen("myPrivateKey.der"));
01143          \endcode
01144 
01145        \par
01146         <b>   SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME:</b>
01147          \code
01148                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_CERTIFICATE_FILE_NAME,"myCertificate.der",strlen("myCertificate.der"));
01149          \endcode
01150 
01151        \par
01152         <b>   SL_SO_SECURE_FILES_DH_KEY_FILE_NAME:</b>
01153          \code
01154                sl_SetSockOpt(SockID,SL_SOL_SOCKET,SL_SO_SECURE_FILES_DH_KEY_FILE_NAME,"myDHinServerMode.der",strlen("myDHinServerMode.der"));
01155          \endcode
01156 
01157        \par
01158         <b>   SL_IP_MULTICAST_TTL:</b>
01159          \code
01160                uint8_t ttl = 20;
01161                sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_MULTICAST_TTL, &ttl, sizeof(ttl));
01162          \endcode
01163 
01164        \par
01165         <b>   SL_IP_ADD_MEMBERSHIP:</b>
01166          \code
01167                SlSockIpMreq mreq;
01168                sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq));
01169         \endcode
01170 
01171        \par
01172         <b>   SL_IP_DROP_MEMBERSHIP:</b>
01173         \code
01174                SlSockIpMreq mreq;
01175                sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_DROP_MEMBERSHIP, &mreq, sizeof(mreq));
01176         \endcode
01177 
01178        \par
01179         <b>   SL_SO_CHANGE_CHANNEL:</b>
01180         \code
01181               uint32_t newChannel = 6; // range is 1-13
01182               sl_SetSockOpt(SockID, SL_SOL_SOCKET, SL_SO_CHANGE_CHANNEL, &newChannel, sizeof(newChannel));
01183         \endcode
01184 
01185         \par
01186         <b>   SL_IP_RAW_RX_NO_HEADER:</b>
01187         \code
01188               uint32_t header = 1;  // remove ip header
01189               sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_RAW_RX_NO_HEADER, &header, sizeof(header));
01190         \endcode
01191 
01192        \par
01193         <b>   SL_IP_HDRINCL:</b>
01194         \code
01195              uint32_t header = 1;
01196              sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_HDRINCL, &header, sizeof(header));
01197         \endcode
01198        \par
01199         <b>   SL_IP_RAW_IPV6_HDRINCL:</b>
01200         \code
01201               uint32_t header = 1;
01202               sl_SetSockOpt(SockID, SL_IPPROTO_IP, SL_IP_RAW_IPV6_HDRINCL, &header, sizeof(header));
01203         \endcode
01204 
01205        \par
01206         <b>   SL_SO_PHY_RATE:</b>
01207         \code
01208               uint32_t rate = 6; // see wlan.h RateIndex_e for values
01209               sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_RATE, &rate, sizeof(rate));
01210         \endcode
01211 
01212        \par
01213         <b>   SL_SO_PHY_TX_POWER:</b>
01214         \code
01215               uint32_t txpower = 1; // valid range is 1-15
01216               sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_TX_POWER, &txpower, sizeof(txpower));
01217         \endcode
01218 
01219        \par
01220         <b>   SL_SO_PHY_NUM_FRAMES_TO_TX:</b>
01221         \code
01222               uint32_t numframes = 1;
01223               sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_NUM_FRAMES_TO_TX, &numframes, sizeof(numframes));
01224         \endcode
01225 
01226        \par
01227         <b>   SL_SO_PHY_PREAMBLE:</b>
01228         \code
01229               uint32_t preamble = 1;
01230               sl_SetSockOpt(SockID, SL_SOL_PHY_OPT, SL_SO_PHY_PREAMBLE, &preamble, sizeof(preamble));
01231         \endcode
01232 
01233     */
01234 #if _SL_INCLUDE_FUNC(sl_SetSockOpt)
01235     int16_t sl_SetSockOpt(int16_t sd, int16_t level, int16_t optname, const void *optval, SlSocklen_t optlen);
01236 #endif
01237 
01238     /*!
01239         \brief Get socket options
01240 
01241         This function manipulate the options associated with a socket.
01242         Options may exist at multiple protocol levels; they are always
01243         present at the uppermost socket level.
01244 
01245         When manipulating socket options the level at which the option resides
01246         and the name of the option must be specified.  To manipulate options at
01247         the socket level, level is specified as SOL_SOCKET.  To manipulate
01248         options at any other level the protocol number of the appropriate proto-
01249         col controlling the option is supplied.  For example, to indicate that an
01250         option is to be interpreted by the TCP protocol, level should be set to
01251         the protocol number of TCP;
01252 
01253         The parameters optval and optlen are used to access optval -
01254         ues for setsockopt().  For getsockopt() they identify a
01255         buffer in which the value for the requested option(s) are to
01256         be returned.  For getsockopt(), optlen is a value-result
01257         parameter, initially containing the size of the buffer
01258         pointed to by option_value, and modified on return to
01259         indicate the actual size of the value returned.  If no option
01260         value is to be supplied or returned, option_value may be
01261         NULL.
01262 
01263 
01264         \param[in]  sd              socket handle
01265         \param[in]  level           defines the protocol level for this option
01266         \param[in]  optname         defines the option name to interrogate
01267         \param[out] optval          specifies a value for the option
01268         \param[out] optlen          specifies the length of the
01269                                     option value
01270 
01271         \return                        On success, zero is returned.
01272                                     On error, a negative value is returned.
01273         \sa     sl_SetSockOpt
01274         \note   See sl_SetSockOpt
01275                 belongs to \ref ext_api
01276         \warning
01277     */
01278 #if _SL_INCLUDE_FUNC(sl_GetSockOpt)
01279     int16_t sl_GetSockOpt(int16_t sd, int16_t level, int16_t optname, void *optval, SlSocklen_t *optlen);
01280 #endif
01281 
01282     /*!
01283         \brief read data from TCP socket
01284 
01285         function receives a message from a connection-mode socket
01286 
01287         \param[in]  sd              socket handle
01288         \param[out] buf             Points to the buffer where the
01289                                     message should be stored.
01290         \param[in]  Len             Specifies the length in bytes of
01291                                     the buffer pointed to by the buffer argument.
01292                                     Range: 1-16000 bytes
01293         \param[in]  flags           Specifies the type of message
01294                                     reception. On this version, this parameter is not
01295                                     supported.
01296 
01297         \return                     return the number of bytes received,
01298                                     or a negative value if an error occurred.
01299                                     using a non-blocking recv a possible negative value is SL_EAGAIN.
01300                                     SL_POOL_IS_EMPTY may be return in case there are no resources in the system
01301                                      In this case try again later or increase MAX_CONCURRENT_ACTIONS
01302 
01303         \sa     sl_RecvFrom
01304         \note                       belongs to \ref recv_api
01305         \warning
01306         \par        Examples:
01307         \code       An example of receiving data using TCP socket:
01308 
01309                     SlSockAddrIn_t  Addr;
01310                     SlSockAddrIn_t  LocalAddr;
01311                     int16_t AddrSize = sizeof(SlSockAddrIn_t);
01312                     int16_t SockID, newSockID;
01313                     int16_t Status;
01314                     int8_t Buf[RECV_BUF_LEN];
01315 
01316                     LocalAddr.sin_family = SL_AF_INET;
01317                     LocalAddr.sin_port = sl_Htons(5001);
01318                     LocalAddr.sin_addr.s_addr = 0;
01319 
01320                     Addr.sin_family = SL_AF_INET;
01321                     Addr.sin_port = sl_Htons(5001);
01322                     Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
01323 
01324                     SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
01325                     Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
01326                     Status = sl_Listen(SockID, 0);
01327                     newSockID = sl_Accept(SockID, (SlSockAddr_t*)&Addr, (SlSocklen_t*) &AddrSize);
01328                     Status = sl_Recv(newSockID, Buf, 1460, 0);
01329         \endcode
01330         \code      Example code for Rx transceiver mode using a raw socket
01331                    int8_t buffer[1536];
01332                    int16_t sd;
01333                    uint16_t size;
01334                    SlTransceiverRxOverHead_t *transHeader;
01335                    sd = sl_Socket(SL_AF_RF,SL_SOCK_RAW,11); // channel 11
01336                    while(1)
01337                    {
01338                       size = sl_Recv(sd,buffer,1536,0);
01339                       transHeader = (SlTransceiverRxOverHead_t *)buffer;
01340                       printf("RSSI is %d frame type is 0x%x size %d\n",transHeader->rssi,buffer[sizeof(SlTransceiverRxOverHead_t)],size);
01341                    }
01342         \endcode
01343     */
01344 #if _SL_INCLUDE_FUNC(sl_Recv)
01345     int16_t sl_Recv(int16_t sd, void *buf, int16_t Len, int16_t flags);
01346 #endif
01347 
01348     /*!
01349         \brief read data from socket
01350 
01351         function receives a message from a connection-mode or
01352         connectionless-mode socket
01353 
01354         \param[in]  sd              socket handle
01355         \param[out] buf             Points to the buffer where the message should be stored.
01356         \param[in]  Len             Specifies the length in bytes of the buffer pointed to by the buffer argument.
01357                                     Range: 1-16000 bytes
01358         \param[in]  flags           Specifies the type of message
01359                                     reception. On this version, this parameter is not
01360                                     supported.
01361         \param[in]  from            pointer to an address structure
01362                                     indicating the source
01363                                     address.\n sockaddr:\n - code
01364                                     for the address format. On this
01365                                     version only AF_INET is
01366                                     supported.\n - socket address,
01367                                     the length depends on the code
01368                                     format
01369         \param[in]  fromlen         source address structure
01370                                     size. This parameter MUST be set to the size of the structure pointed to by addr.
01371 
01372 
01373         \return                     return the number of bytes received,
01374                                     or a negative value if an error occurred.
01375                                     using a non-blocking recv a possible negative value is SL_EAGAIN.
01376                                     SL_RET_CODE_INVALID_INPUT (-2) will be returned if fromlen has incorrect length.
01377                                     SL_POOL_IS_EMPTY may be return in case there are no resources in the system
01378                                      In this case try again later or increase MAX_CONCURRENT_ACTIONS
01379 
01380         \sa     sl_Recv
01381         \note                       belongs to \ref recv_api
01382         \warning
01383         \par        Example:
01384         \code       An example of receiving data:
01385 
01386                     SlSockAddrIn_t  Addr;
01387                     SlSockAddrIn_t  LocalAddr;
01388                     int16_t AddrSize = sizeof(SlSockAddrIn_t);
01389                     int16_t SockID;
01390                     int16_t Status;
01391                     int8_t Buf[RECV_BUF_LEN];
01392 
01393                     LocalAddr.sin_family = SL_AF_INET;
01394                     LocalAddr.sin_port = sl_Htons(5001);
01395                     LocalAddr.sin_addr.s_addr = 0;
01396 
01397                     SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
01398                     Status = sl_Bind(SockID, (SlSockAddr_t *)&LocalAddr, AddrSize);
01399                     Status = sl_RecvFrom(SockID, Buf, 1472, 0, (SlSockAddr_t *)&Addr, (SlSocklen_t*)&AddrSize);
01400 
01401         \endcode
01402     */
01403 #if _SL_INCLUDE_FUNC(sl_RecvFrom)
01404     int16_t sl_RecvFrom(int16_t sd, void *buf, int16_t Len, int16_t flags, SlSockAddr_t *from, SlSocklen_t *fromlen);
01405 #endif
01406 
01407     /*!
01408         \brief write data to TCP socket
01409 
01410         This function is used to transmit a message to another socket.
01411         Returns immediately after sending data to device.
01412         In case of TCP failure an async event SL_SOCKET_TX_FAILED_EVENT is going to
01413         be received.
01414         In case of a RAW socket (transceiver mode), extra 4 bytes should be reserved at the end of the
01415         frame data buffer for WLAN FCS
01416 
01417         \param[in] sd               socket handle
01418         \param[in] buf              Points to a buffer containing
01419                                     the message to be sent
01420         \param[in] Len              message size in bytes. Range: 1-1460 bytes
01421         \param[in] flags            Specifies the type of message
01422                                     transmission. On this version, this parameter is not
01423                                     supported for TCP.
01424                                     For transceiver mode, the SL_RAW_RF_TX_PARAMS macro can be used to determine
01425                                     transmission parameters (channel,rate,tx_power,preamble)
01426 
01427 
01428         \return                     Return the number of bytes transmitted,
01429                                     or -1 if an error occurred
01430 
01431         \sa     sl_SendTo
01432         \note                       belongs to \ref send_api
01433         \warning
01434         \par        Example:
01435         \code       An example of sending data:
01436 
01437                     SlSockAddrIn_t  Addr;
01438                     int16_t AddrSize = sizeof(SlSockAddrIn_t);
01439                     int16_t SockID;
01440                     int16_t Status;
01441                     int8_t Buf[SEND_BUF_LEN];
01442 
01443                     Addr.sin_family = SL_AF_INET;
01444                     Addr.sin_port = sl_Htons(5001);
01445                     Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
01446 
01447                     SockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);
01448                     Status = sl_Connect(SockID, (SlSockAddr_t *)&Addr, AddrSize);
01449                     Status = sl_Send(SockID, Buf, 1460, 0 );
01450 
01451         \endcode
01452      */
01453 #if _SL_INCLUDE_FUNC(sl_Send )
01454     int16_t sl_Send(int16_t sd, const void *buf, int16_t Len, int16_t flags);
01455 #endif
01456 
01457     /*!
01458         \brief write data to socket
01459 
01460         This function is used to transmit a message to another socket
01461         (connection less socket SOCK_DGRAM,  SOCK_RAW).
01462         Returns immediately after sending data to device.
01463         In case of transmission failure an async event SL_SOCKET_TX_FAILED_EVENT is going to
01464         be received.
01465 
01466         \param[in] sd               socket handle
01467         \param[in] buf              Points to a buffer containing
01468                                     the message to be sent
01469         \param[in] Len              message size in bytes. Range: 1-1460 bytes
01470         \param[in] flags            Specifies the type of message
01471                                     transmission. On this version, this parameter is not
01472                                     supported
01473         \param[in] to               pointer to an address structure
01474                                     indicating the destination
01475                                     address.\n sockaddr:\n - code
01476                                     for the address format. On this
01477                                     version only AF_INET is
01478                                     supported.\n - socket address,
01479                                     the length depends on the code
01480                                     format
01481         \param[in] tolen            destination address structure size
01482 
01483         \return                     Return the number of transmitted bytes,
01484                                     or -1 if an error occurred
01485 
01486         \sa     sl_Send
01487         \note                       belongs to \ref send_api
01488         \warning
01489         \par        Example:
01490         \code       An example of sending data:
01491 
01492                     SlSockAddrIn_t  Addr;
01493                     int16_t AddrSize = sizeof(SlSockAddrIn_t);
01494                     int16_t SockID;
01495                     int16_t Status;
01496                     int8_t Buf[SEND_BUF_LEN];
01497 
01498                     Addr.sin_family = SL_AF_INET;
01499                     Addr.sin_port = sl_Htons(5001);
01500                     Addr.sin_addr.s_addr = sl_Htonl(SL_IPV4_VAL(10,1,1,200));
01501 
01502                     SockID = sl_Socket(SL_AF_INET,SL_SOCK_DGRAM, 0);
01503                     Status = sl_SendTo(SockID, Buf, 1472, 0, (SlSockAddr_t *)&Addr, AddrSize);
01504 
01505         \endcode
01506     */
01507 #if _SL_INCLUDE_FUNC(sl_SendTo)
01508     int16_t sl_SendTo(int16_t sd, const void *buf, int16_t Len, int16_t flags, const SlSockAddr_t *to, SlSocklen_t tolen);
01509 #endif
01510 
01511     /*!
01512         \brief Reorder the bytes of a 32-bit unsigned value
01513 
01514         This function is used to Reorder the bytes of a 32-bit unsigned value from processor order to network order.
01515 
01516         \param[in] var              variable to reorder
01517 
01518         \return                     Return the reorder variable,
01519 
01520         \sa     sl_SendTo  sl_Bind  sl_Connect  sl_RecvFrom  sl_Accept
01521         \note                       belongs to \ref send_api
01522         \warning
01523     */
01524 #if _SL_INCLUDE_FUNC(sl_Htonl )
01525     uint32_t sl_Htonl( uint32_t val );
01526 
01527 #define sl_Ntohl sl_Htonl  /* Reorder the bytes of a 16-bit unsigned value from network order to processor orde. */
01528 #endif
01529 
01530     /*!
01531         \brief Reorder the bytes of a 16-bit unsigned value
01532 
01533         This function is used to Reorder the bytes of a 16-bit unsigned value from processor order to network order.
01534 
01535         \param[in] var              variable to reorder
01536 
01537         \return                     Return the reorder variable,
01538 
01539         \sa     sl_SendTo  sl_Bind    sl_Connect  sl_RecvFrom  sl_Accept
01540         \note                       belongs to \ref send_api
01541         \warning
01542     */
01543 #if _SL_INCLUDE_FUNC(sl_Htons )
01544     uint16_t sl_Htons( uint16_t val );
01545 
01546 #define sl_Ntohs sl_Htons   /* Reorder the bytes of a 16-bit unsigned value from network order to processor orde. */
01547 #endif
01548 
01549 private:
01550 
01551     cc3100_driver   &_driver;
01552 #ifndef SL_PLATFORM_MULTI_THREADED    
01553     cc3100_nonos    &_nonos;
01554 #endif    
01555     
01556 };//class
01557 
01558 
01559 }//namespace mbed_cc3100    
01560 
01561     /*!
01562 
01563      Close the Doxygen group.
01564      @}
01565 
01566      */
01567 
01568 #endif /* __SOCKET_H__ */
01569 
01570 
01571