cc3100_Socket_Wifi_Server version for LPC1768

Dependencies:   mbed

Fork of cc3100_Test_Demo by David Fletcher

Committer:
artpes
Date:
Fri May 26 19:26:11 2017 +0000
Revision:
8:e79bacf664cc
Parent:
6:778b081f6a13
Fork

Who changed what in which revision?

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