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