Update revision to use TI's mqtt and Freertos.

Dependencies:   mbed client server

Fork of cc3100_Test_mqtt_CM3 by David Fletcher

Committer:
dflet
Date:
Thu Sep 03 14:02:37 2015 +0000
Revision:
3:a8c249046181
SPI Mode change 1 to 0

Who changed what in which revision?

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