David Fletcher / simplelink_V2

Fork of simplelink_V2 by David Fletcher

Committer:
dflet
Date:
Sat Jun 06 13:31:01 2015 +0000
Revision:
0:1a07906111ec
Changes made to use external spawn Freertos

Who changed what in which revision?

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