1 /* 2 * Copyright (c) 2017-2019, Texas Instruments Incorporated 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of Texas Instruments Incorporated nor the names of 17 * its contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /*! 34 35 36 \page SlNetSock_overview SlNetSock 37 38 \section intro_sec Introduction 39 40 SlNetSock provides a standard BSD API for TCP and UDP transport 41 layers, and a lower-level SlNetSock API for basic and extended 42 usage. Supported use cases include: 43 44 - Support of multi interface (WiFi NS, Ethernet NDK) 45 - Selecting which interfaces the host will use, one or more. 46 - Support of different types of sockets (TCP, TLS, UDP, RAW, RF, etc.) 47 - BSD and proprietary errors 48 49 The SlNetSock API's lead to easier portability to microcontrollers, 50 without compromising the capabilities and robustness of the final 51 application. 52 53 54 \section modules_sec Module Names 55 TI's SlNetSock layer is divided into the following software modules: 56 -# \ref SlNet - Interface for general SlNet services 57 -# \ref SlNetSock - Controls standard client/server sockets options and capabilities 58 -# \ref SlNetIf - Controls standard stack/interface options and capabilities 59 -# \ref SlNetUtils - Provides sockets related commands and configuration 60 -# \ref SlNetErr - Provide BSD and proprietary errors 61 62 In addition, SlNetSock provides a standard BSD API, built atop the 63 SlNet* APIs. The BSD headers are placed in ti/net/bsd directory, 64 which users should place on their include path. 65 66 Also, there is a light 67 \subpage porting_guide "SL Interface Porting Guide" 68 with information available for adding SlNetSock support for other stacks. 69 70 \page porting_guide SL Interface Porting Guide 71 72 \section Introduction 73 74 The generic SlNetSock layer sits between the application/service and 75 the interface stack. This guide describes the details of adding a network stack into the SlNetSock environment. 76 77 The porting steps for adding new interface: 78 -# Create slnetifxxx file for the new interface 79 -# Select the capabilities set 80 -# Adding the interface to your application/service 81 -# Add the relevant functions to your application/service 82 -# Test your code to validate the correctness of your porting 83 84 \subsection porting_step1 Step 1 - slnetifxxx.c and slnetifxxx.h file for your interface 85 86 - Create slnetifxxx file (replace xxx with your interface/stack 87 name). Likely you will copy from an existing port. 88 89 - Implement the needed API's. 90 91 Each interface needs to provide a set of API's to work with the 92 interface. Some are mandatory, others are optional (but recommended). 93 94 - Mandatory API's: 95 - \ref SlNetIf_Config_t.sockCreate "sockCreate" 96 - \ref SlNetIf_Config_t.sockClose "sockClose" 97 - \ref SlNetIf_Config_t.sockSelect "sockSelect" 98 - \ref SlNetIf_Config_t.sockSetOpt "sockSetOpt" 99 - \ref SlNetIf_Config_t.sockGetOpt "sockGetOpt" 100 - \ref SlNetIf_Config_t.sockRecvFrom "sockRecvFrom" 101 - \ref SlNetIf_Config_t.sockSendTo "sockSendTo" 102 - \ref SlNetIf_Config_t.ifGetIPAddr "ifGetIPAddr" 103 - \ref SlNetIf_Config_t.ifGetConnectionStatus "ifGetConnectionStatus" 104 105 - The non-mandatory API's set: 106 - \ref SlNetIf_Config_t.sockShutdown "sockShutdown" 107 - \ref SlNetIf_Config_t.sockAccept "sockAccept" 108 - \ref SlNetIf_Config_t.sockBind "sockBind" 109 - \ref SlNetIf_Config_t.sockListen "sockListen" 110 - \ref SlNetIf_Config_t.sockConnect "sockConnect" 111 - \ref SlNetIf_Config_t.sockGetPeerName "sockGetPeerName" 112 - \ref SlNetIf_Config_t.sockGetLocalName "sockGetLocalName" 113 - \ref SlNetIf_Config_t.sockRecv "sockRecv" 114 - \ref SlNetIf_Config_t.sockSend "sockSend" 115 - \ref SlNetIf_Config_t.sockstartSec "sockstartSec" 116 - \ref SlNetIf_Config_t.utilGetHostByName "utilGetHostByName" 117 - \ref SlNetIf_Config_t.ifLoadSecObj "ifLoadSecOjb" 118 - \ref SlNetIf_Config_t.ifCreateContext "ifCreateContext" 119 120 121 \note The list of API's and more data can be found in ::SlNetIf_Config_t structure in SlNetIf module \n \n 122 123 \subsection porting_step2 Step 2 - Select the capabilities set 124 125 The capabilities prototype should be declared in your slnetifxxx.h and implemented in your slnetifxxx.c 126 127 Each mandatory API's must be set, additional API's can be set or must 128 be set to NULL. 129 130 An example config declaration for TI's SimpleLink CC31XX/CC32xx 131 132 \code 133 SlNetIfConfig SlNetIfConfigWiFi = 134 { 135 SlNetIfWifi_socket, // Callback function sockCreate in slnetif module 136 SlNetIfWifi_close, // Callback function sockClose in slnetif module 137 NULL, // Callback function sockShutdown in slnetif module 138 SlNetIfWifi_accept, // Callback function sockAccept in slnetif module 139 SlNetIfWifi_bind, // Callback function sockBind in slnetif module 140 SlNetIfWifi_listen, // Callback function sockListen in slnetif module 141 SlNetIfWifi_connect, // Callback function sockConnect in slnetif module 142 NULL, // Callback function sockGetPeerName in slnetif module 143 NULL, // Callback function sockGetLocalName in slnetif module 144 SlNetIfWifi_select, // Callback function sockSelect in slnetif module 145 SlNetIfWifi_setSockOpt, // Callback function sockSetOpt in slnetif module 146 SlNetIfWifi_getSockOpt, // Callback function sockGetOpt in slnetif module 147 SlNetIfWifi_recv, // Callback function sockRecv in slnetif module 148 SlNetIfWifi_recvFrom, // Callback function sockRecvFrom in slnetif module 149 SlNetIfWifi_send, // Callback function sockSend in slnetif module 150 SlNetIfWifi_sendTo, // Callback function sockSendTo in slnetif module 151 SlNetIfWifi_sockstartSec, // Callback function sockstartSec in slnetif module 152 SlNetIfWifi_getHostByName, // Callback function utilGetHostByName in slnetif module 153 SlNetIfWifi_getIPAddr, // Callback function ifGetIPAddr in slnetif module 154 SlNetIfWifi_getConnectionStatus, // Callback function ifGetConnectionStatus in slnetif module 155 SlNetIfWifi_loadSecObj, // Callback function ifLoadSecObj in slnetif module 156 NULL // Callback function ifCreateContext in slnetif module 157 }; 158 \endcode 159 160 In the example above the following API's are not supported by the interface, 161 and are set to NULL: 162 - sockShutdown 163 - sockGetPeerName 164 - sockGetLocalName 165 - utilGetHostByName 166 - ifCreateContext 167 168 \subsection porting_step3 Step 3 - Adding the interface to your application/service 169 170 \b Include the new file in the board header file in the application. 171 172 \subsection porting_step4 Step 4 - Add the relevant functions to your application/service 173 174 After configuring the capabilities of the interface, Adding the interface to the SlNetSock 175 is required. 176 177 Use ::SlNetIf_add in order to add the interface and set his ID, Name, function list and priority. 178 Later on you need to use the BSD API's or SlNetSock API's for socket handling. 179 180 \subsection porting_step5 Step 5 - Test your code to validate the correctness of your porting 181 182 After porting the layer into your setup, validate that your code work as expected 183 184 */ 185 186 /*****************************************************************************/ 187 /* Include files */ 188 /*****************************************************************************/ 189 190 #ifndef __SL_NET_SOCK_H__ 191 #define __SL_NET_SOCK_H__ 192 193 #include <stdint.h> 194 /* 195 * Commented out to prevent zsock_timeval from being redefined 196 * Can remove this if support for CONFIG_NET_SOCKETS_POSIX_NAMES 197 * is dropped someday 198 */ 199 #if defined(CONFIG_NET_SOCKETS_POSIX_NAMES) || defined(CONFIG_POSIX_CLOCK) \ 200 || defined(CONFIG_POSIX_API) 201 #include <sys/time.h> 202 #endif 203 204 #ifdef __cplusplus 205 extern "C" { 206 #endif 207 208 209 /*! 210 \defgroup SlNetSock SlNetSock group 211 212 \short Controls standard client/server sockets options and capabilities 213 214 */ 215 /*! 216 217 \addtogroup SlNetSock 218 @{ 219 220 */ 221 222 /*****************************************************************************/ 223 /* Macro declarations */ 224 /*****************************************************************************/ 225 226 #define SLNETSOCK_MAX_CONCURRENT_SOCKETS (32) /**< Declares the maximum sockets that can be opened */ 227 228 /* Address families. */ 229 #define SLNETSOCK_AF_UNSPEC (0) /**< Unspecified address family */ 230 #define SLNETSOCK_AF_INET (2) /**< IPv4 socket (UDP, TCP, etc) */ 231 #define SLNETSOCK_AF_INET6 (3) /**< IPv6 socket (UDP, TCP, etc) */ 232 #define SLNETSOCK_AF_RF (6) /**< Data include RF parameter, All layer by user (Wifi could be disconnected) */ 233 #define SLNETSOCK_AF_PACKET (17) /**< Network bypass */ 234 235 /* Protocol families, same as address families. */ 236 #define SLNETSOCK_PF_UNSPEC SLNETSOCK_AF_UNSPEC 237 #define SLNETSOCK_PF_INET SLNETSOCK_AF_INET 238 #define SLNETSOCK_PF_INET6 SLNETSOCK_AF_INET6 239 240 /* Define argument types specifies the socket type. */ 241 #define SLNETSOCK_SOCK_STREAM (1) /**< TCP Socket */ 242 #define SLNETSOCK_SOCK_DGRAM (2) /**< UDP Socket */ 243 #define SLNETSOCK_SOCK_RAW (3) /**< Raw socket */ 244 #define SLNETSOCK_SOCK_RX_MTR (4) /**< RX Metrics socket */ 245 #define SLNETSOCK_SOCK_MAC_WITH_CCA (5) 246 #define SLNETSOCK_SOCK_MAC_WITH_NO_CCA (6) 247 #define SLNETSOCK_SOCK_BRIDGE (7) 248 #define SLNETSOCK_SOCK_ROUTER (8) 249 250 /* Define some BSD protocol constants. */ 251 #define SLNETSOCK_PROTO_TCP (6) /**< TCP Raw Socket */ 252 #define SLNETSOCK_PROTO_UDP (17) /**< UDP Raw Socket */ 253 #define SLNETSOCK_PROTO_RAW (255) /**< Raw Socket */ 254 #define SLNETSOCK_PROTO_SECURE (100) /**< Secured Socket Layer (SSL,TLS) */ 255 256 /* bind any addresses */ 257 #define SLNETSOCK_INADDR_ANY (0) 258 #define SLNETSOCK_IN6ADDR_ANY (0) 259 260 261 /* socket options */ 262 263 /* possible values for the level parameter in slNetSock_setOpt / slNetSock_getOpt */ 264 #define SLNETSOCK_LVL_SOCKET (1) /**< Define the socket option category. */ 265 #define SLNETSOCK_LVL_IP (2) /**< Define the IP option category. */ 266 #define SLNETSOCK_LVL_PHY (3) /**< Define the PHY option category. */ 267 268 /* possible values for the option parameter in slNetSock_setOpt / slNetSock_getOpt */ 269 270 /* socket level options (SLNETSOCK_LVL_SOCKET) */ 271 #define SLNETSOCK_OPSOCK_RCV_BUF (8) /**< Setting TCP receive buffer size (window size) - This options takes SlNetSock_Winsize_t struct as parameter */ 272 #define SLNETSOCK_OPSOCK_SND_BUF (202) /**< Sets or gets the maximum socket send buffer in bytes. - This option takes an int as a parameter */ 273 #define SLNETSOCK_OPSOCK_RCV_TIMEO (20) /**< Enable receive timeout - This options takes SlNetSock_Timeval_t struct as parameter */ 274 #define SLNETSOCK_OPSOCK_SND_TIMEO (21) /**< Enable send timeout - This options takes SlNetSock_Timeval_t struct as parameter */ 275 #define SLNETSOCK_OPSOCK_KEEPALIVE (9) /**< Connections are kept alive with periodic messages - This options takes SlNetSock_Keepalive_t struct as parameter */ 276 #define SLNETSOCK_OPSOCK_KEEPALIVE_TIME (37) /**< keepalive time out - This options takes <b>uint32_t</b> as parameter */ 277 #define SLNETSOCK_OPSOCK_LINGER (13) /**< Socket lingers on close pending remaining send/receive packets - This options takes SlNetSock_linger_t struct as parameter */ 278 #define SLNETSOCK_OPSOCK_NON_BLOCKING (24) /**< Enable/disable nonblocking mode - This options takes SlNetSock_Nonblocking_t struct as parameter */ 279 #define SLNETSOCK_OPSOCK_NON_IP_BOUNDARY (39) /**< connectionless socket disable rx boundary - This options takes SlNetSock_NonIpBoundary_t struct as parameter */ 280 #define SLNETSOCK_OPSOCK_ERROR (58) /**< Socket level error code */ 281 #define SLNETSOCK_OPSOCK_SLNETSOCKSD (59) /**< Used by the BSD layer in order to retrieve the slnetsock sd */ 282 #define SLNETSOCK_OPSOCK_BROADCAST (200) /**< Enable/disable broadcast signals - This option takes SlNetSock_Broadcast_t struct as parameters */ 283 #define SLNETSOCK_OPSOCK_REUSEADDR (201) /**< Enable/disable allowing reuse of local addresses for bind calls - This option takes an int as a parameter */ 284 #define SLNETSOCK_OPSOCK_REUSEPORT (203) /**< Enable/disable multiple sockets to be bound to an identical socket address. - This option takes an int as a parameter */ 285 286 /* IP level options (SLNETSOCK_LVL_IP) */ 287 #define SLNETSOCK_OPIP_MULTICAST_TTL (61) /**< Specify the TTL value to use for outgoing multicast packet. - This options takes <b>uint8_t</b> as parameter */ 288 #define SLNETSOCK_OPIP_ADD_MEMBERSHIP (65) /**< Join IPv4 multicast membership - This options takes SlNetSock_IpMreq_t struct as parameter */ 289 #define SLNETSOCK_OPIP_DROP_MEMBERSHIP (66) /**< Leave IPv4 multicast membership - This options takes SlNetSock_IpMreq_t struct as parameter */ 290 #define SLNETSOCK_OPIP_HDRINCL (67) /**< Raw socket IPv4 header included - This options takes <b>uint32_t</b> as parameter */ 291 #define SLNETSOCK_OPIP_RAW_RX_NO_HEADER (68) /**< Proprietary socket option that does not includeIPv4/IPv6 header (and extension headers) on received raw sockets - This options takes <b>uint32_t</b> as parameter */ 292 #define SLNETSOCK_OPIP_RAW_IPV6_HDRINCL (69) /**< Transmitted buffer over IPv6 socket contains IPv6 header - This options takes <b>uint32_t</b> as parameter */ 293 #define SLNETSOCK_OPIPV6_ADD_MEMBERSHIP (70) /**< Join IPv6 multicast membership - This options takes SlNetSock_IpV6Mreq_t struct as parameter */ 294 #define SLNETSOCK_OPIPV6_DROP_MEMBERSHIP (71) /**< Leave IPv6 multicast membership - This options takes SlNetSock_IpV6Mreq_t struct as parameter */ 295 #define SLNETSOCK_OPIPV6_MULTICAST_HOPS (72) /**< Specify the hops value to use for outgoing multicast packet. */ 296 297 /* PHY level options (SLNETSOCK_LVL_PHY) */ 298 #define SLNETSOCK_OPPHY_CHANNEL (28) /**< This option is available only when transceiver started - This options takes <b>uint32_t</b> as channel number parameter */ 299 #define SLNETSOCK_OPPHY_RATE (100) /**< WLAN Transmit rate - This options takes <b>uint32_t</b> as parameter based on SlWlanRateIndex_e */ 300 #define SLNETSOCK_OPPHY_TX_POWER (101) /**< TX Power level - This options takes <b>uint32_t</b> as parameter */ 301 #define SLNETSOCK_OPPHY_NUM_FRAMES_TO_TX (102) /**< Number of frames to transmit - This options takes <b>uint32_t</b> as parameter */ 302 #define SLNETSOCK_OPPHY_PREAMBLE (103) /**< Preamble for transmission - This options takes <b>uint32_t</b> as parameter */ 303 #define SLNETSOCK_OPPHY_TX_INHIBIT_THRESHOLD (104) /**< TX Inhibit Threshold (CCA) - This options takes <b>uint32_t</b> as parameter based on SlNetSockTxInhibitThreshold_e */ 304 #define SLNETSOCK_OPPHY_TX_TIMEOUT (105) /**< TX timeout for Transceiver frames (lifetime) in miliseconds (max value is 100ms) - This options takes <b>uint32_t</b> as parameter */ 305 #define SLNETSOCK_OPPHY_ALLOW_ACKS (106) /**< Enable sending ACKs in transceiver mode - This options takes <b>uint32_t</b> as parameter */ 306 307 /* TCP level options (SLNETSOCK_PROTO_TCP) */ 308 #define SLNETSOCK_TCP_NODELAY (203) /**< Disables TCP send delay/coalesce algorithm - This option takes SLNetSock_NoDelay_t struct as a parameter */ 309 #define SLNETSOCK_TCP_MAXSEG (204) /**< Set the maximum TCP segment size - This option takes SLNetSock_MaxSeg_t struct as a parameter */ 310 #define SLNETSOCK_TCP_NOPUSH (205) /**< Do not send data just to finish a data block (attempt to coalesce). - This option takes SLNetSock_NoPush_t struct as a parameter */ 311 #define SLNETSOCK_TCP_NOOPT (206) /**< Do not use TCP options. - This option takes SLNetSock_NoOpt_t struct as a parameter */ 312 #define SLNETSOCK_TCP_SACKPERMITTED (207) /**< Permit RFC-2018 Selective Acknowledgment(SACK) conformant connection - This option takes SLNetSock_SackPermitted_t struct as a parameter */ 313 #define SLNETSOCK_TCP_MAXRTT (208) /**< The maximum TCP Round Trip Time value allowed in the determination of the estimated TCP RTT - This option takes SLNetSock_MaxRtt_t struct as a parameter */ 314 315 /*! 316 \brief The SlNetSockTxInhibitThreshold_e enumerations is used in SLNETSOCK_OPPHY_TX_INHIBIT_THRESHOLD PHY level option 317 */ 318 typedef enum 319 { 320 SLNETSOCK_TX_INHIBIT_THRESHOLD_MIN = 1, 321 SLNETSOCK_TX_INHIBIT_THRESHOLD_LOW = 2, 322 SLNETSOCK_TX_INHIBIT_THRESHOLD_DEFAULT = 3, 323 SLNETSOCK_TX_INHIBIT_THRESHOLD_MED = 4, 324 SLNETSOCK_TX_INHIBIT_THRESHOLD_HIGH = 5, 325 SLNETSOCK_TX_INHIBIT_THRESHOLD_MAX = 6 326 } SlNetSockTxInhibitThreshold_e; 327 328 /*! 329 \brief The SlNetSockSecAttrib_e enumerations are used to declare security 330 attribute objects in SlNetSock_secAttribSet(). 331 332 \sa SlNetSock_secAttribSet() 333 */ 334 typedef enum 335 { 336 SLNETSOCK_SEC_ATTRIB_PRIVATE_KEY = 0, 337 SLNETSOCK_SEC_ATTRIB_LOCAL_CERT = 1, 338 SLNETSOCK_SEC_ATTRIB_PEER_ROOT_CA = 2, 339 SLNETSOCK_SEC_ATTRIB_DH_KEY = 3, 340 SLNETSOCK_SEC_ATTRIB_METHOD = 4, 341 SLNETSOCK_SEC_ATTRIB_CIPHERS = 5, 342 SLNETSOCK_SEC_ATTRIB_ALPN = 6, 343 SLNETSOCK_SEC_ATTRIB_EXT_CLIENT_CHLNG_RESP = 7, 344 SLNETSOCK_SEC_ATTRIB_DOMAIN_NAME = 8, 345 346 /*! 347 @c SLNETSOCK_SEC_ATTRIB_DISABLE_CERT_STORE is 348 currently only supported on CC3xxx devices. 349 350 The certificate store is a file, provided by TI, 351 containing a list of known and trusted root CAs by TI. 352 For more information, see the CC3xxx documentation. 353 354 The certificate store is used only in client mode. Servers 355 use a proprietary root CA to authenticate clients, and 356 therefore cannot use the certificate store. 357 358 Using this attribute allows using root CA which isn't a 359 part of the provided certificate store. 360 */ 361 362 SLNETSOCK_SEC_ATTRIB_DISABLE_CERT_STORE = 9 363 } SlNetSockSecAttrib_e; 364 365 /* available values for SLNETSOCK_SEC_ATTRIB_METHOD */ 366 #define SLNETSOCK_SEC_METHOD_SSLV3 (0) /**< security method SSL v3 */ 367 #define SLNETSOCK_SEC_METHOD_TLSV1 (1) /**< security method TLS v1 */ 368 #define SLNETSOCK_SEC_METHOD_TLSV1_1 (2) /**< security method TLS v1_1 */ 369 #define SLNETSOCK_SEC_METHOD_TLSV1_2 (3) /**< security method TLS v1_2 */ 370 #define SLNETSOCK_SEC_METHOD_SSLv3_TLSV1_2 (4) /**< use highest possible version from SSLv3 - TLS 1.2 */ 371 #define SLNETSOCK_SEC_METHOD_DLSV1 (5) /**< security method DTL v1 */ 372 373 /* available values for SLNETSOCK_SEC_ATTRIB_CIPHERS. The value is bitmap! */ 374 #define SLNETSOCK_SEC_CIPHER_SSL_RSA_WITH_RC4_128_SHA (1 << 0) 375 #define SLNETSOCK_SEC_CIPHER_SSL_RSA_WITH_RC4_128_MD5 (1 << 1) 376 #define SLNETSOCK_SEC_CIPHER_TLS_RSA_WITH_AES_256_CBC_SHA (1 << 2) 377 #define SLNETSOCK_SEC_CIPHER_TLS_DHE_RSA_WITH_AES_256_CBC_SHA (1 << 3) 378 #define SLNETSOCK_SEC_CIPHER_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (1 << 4) 379 #define SLNETSOCK_SEC_CIPHER_TLS_ECDHE_RSA_WITH_RC4_128_SHA (1 << 5) 380 #define SLNETSOCK_SEC_CIPHER_TLS_RSA_WITH_AES_128_CBC_SHA256 (1 << 6) 381 #define SLNETSOCK_SEC_CIPHER_TLS_RSA_WITH_AES_256_CBC_SHA256 (1 << 7) 382 #define SLNETSOCK_SEC_CIPHER_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 (1 << 8) 383 #define SLNETSOCK_SEC_CIPHER_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 (1 << 9) 384 #define SLNETSOCK_SEC_CIPHER_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA (1 << 10) 385 #define SLNETSOCK_SEC_CIPHER_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA (1 << 11) 386 #define SLNETSOCK_SEC_CIPHER_TLS_RSA_WITH_AES_128_GCM_SHA256 (1 << 12) 387 #define SLNETSOCK_SEC_CIPHER_TLS_RSA_WITH_AES_256_GCM_SHA384 (1 << 13) 388 #define SLNETSOCK_SEC_CIPHER_TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 (1 << 14) 389 #define SLNETSOCK_SEC_CIPHER_TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 (1 << 15) 390 #define SLNETSOCK_SEC_CIPHER_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (1 << 16) 391 #define SLNETSOCK_SEC_CIPHER_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (1 << 17) 392 #define SLNETSOCK_SEC_CIPHER_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 (1 << 18) 393 #define SLNETSOCK_SEC_CIPHER_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (1 << 19) 394 #define SLNETSOCK_SEC_CIPHER_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 (1 << 20) 395 #define SLNETSOCK_SEC_CIPHER_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (1 << 21) 396 #define SLNETSOCK_SEC_CIPHER_TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (1 << 22) 397 #define SLNETSOCK_SEC_CIPHER_FULL_LIST (0xFFFFFFFF) 398 399 /* available values for SLNETSOCK_SEC_ATTRIB_ALPN */ 400 #define SLNETSOCK_SEC_ALPN_H1 (1 << 0) 401 #define SLNETSOCK_SEC_ALPN_H2 (1 << 1) 402 #define SLNETSOCK_SEC_ALPN_H2C (1 << 2) 403 #define SLNETSOCK_SEC_ALPN_H2_14 (1 << 3) 404 #define SLNETSOCK_SEC_ALPN_H2_16 (1 << 4) 405 #define SLNETSOCK_SEC_ALPN_FULL_LIST ((SLNETSOCK_SEC_ALPN_H2_16 << 1 ) - 1) 406 407 /* available values for the flags of the SlNetSock_startSec function */ 408 #define SLNETSOCK_SEC_START_SECURITY_SESSION_ONLY (1 << 0) /**< Sends the command that will start the security session for a specific socket descriptor */ 409 #define SLNETSOCK_SEC_BIND_CONTEXT_ONLY (1 << 1) /**< Binds the security context to a specific socket descriptor */ 410 #define SLNETSOCK_SEC_IS_SERVER (1 << 2) /**< Used to define if the socket is client/server socket */ 411 412 /* available values for the flags of the SlNetSock_create function */ 413 414 #define SLNETSOCK_CREATE_IF_STATE_ENABLE (1 << 0) /**< Creation of the socket will be on enabled state */ 415 #define SLNETSOCK_CREATE_IF_STATUS_CONNECTED (1 << 1) /**< Creation of the socket will be on status connected */ 416 #define SLNETSOCK_CREATE_ALLOW_PARTIAL_MATCH (1 << 2) /**< Creation of the socket will be on the interface with 417 the highest priority if the other flags will fail */ 418 419 /* Definitions for shutting down some or all parts of a full duplex connection */ 420 #define SLNETSOCK_SHUT_RD (0) /**< Further receptions will be disallowed */ 421 #define SLNETSOCK_SHUT_WR (1) /**< Further transmissions will be disallowed */ 422 #define SLNETSOCK_SHUT_RDWR (2) /**< Further receptions and transmissions will be disallowed */ 423 424 /* Length of address string representation */ 425 #define SLNETSOCK_INET6_ADDRSTRLEN (46) 426 #define SLNETSOCK_INET_ADDRSTRLEN (16) 427 428 /* flags used in send/recv and friends. 429 * 430 * Note these flags must not exceed 24-bits. The implementation will 431 * OR the 8-bits of security flags into the remaining high 8 bits of 432 * 32-bit flag variables. 433 */ 434 #define SLNETSOCK_MSG_OOB (0x0001) 435 #define SLNETSOCK_MSG_PEEK (0x0002) 436 #define SLNETSOCK_MSG_WAITALL (0x0004) 437 #define SLNETSOCK_MSG_DONTWAIT (0x0008) 438 #define SLNETSOCK_MSG_DONTROUTE (0x0010) 439 #define SLNETSOCK_MSG_NOSIGNAL (0x0020) 440 441 442 /*****************************************************************************/ 443 /* Structure/Enum declarations */ 444 /*****************************************************************************/ 445 446 /*! 447 \brief Internet address 448 */ 449 typedef struct SlNetSock_InAddr_t 450 { 451 #ifndef s_addr 452 uint32_t s_addr; /* Internet address 32 bits */ 453 #else 454 /*! 455 \brief Different representations for in addr for different hosts. 456 */ 457 union S_un 458 { 459 uint32_t S_addr; 460 struct 461 { 462 uint8_t s_b1,s_b2,s_b3,s_b4; 463 } S_un_b; 464 struct 465 { 466 uint16_t s_w1,s_w2; 467 } S_un_w; 468 } S_un; 469 #endif 470 } SlNetSock_InAddr_t; 471 472 /*! 473 \brief IpV6 or Ipv6 EUI64 474 */ 475 typedef struct SlNetSock_In6Addr_t 476 { 477 union 478 { 479 uint8_t _S6_u8[16]; 480 uint16_t _S6_u16[8]; 481 uint32_t _S6_u32[4]; 482 } _S6_un; 483 } SlNetSock_In6Addr_t; 484 485 /*! 486 \brief The SlNetSock_NoDelay_t structure is used in #SLNETSOCK_TCP_NODELAY TCP level option 487 */ 488 typedef struct SlNetSock_NoDelay_t 489 { 490 uint32_t noDelayEnabled; /**< 0 = disabled;1 = enabled; default = 0 */ 491 } SlNetSock_NoDelay_t; 492 493 /*! 494 \brief The SlNetSock_MaxSeg_t structure is used in #SLNETSOCK_TCP_MAXSEG TCP level option 495 */ 496 typedef struct SlNetSock_MaxSeg_t 497 { 498 uint32_t maxSeg; /**< Maximum TCP segment size. Default = 536 */ 499 } SlNetSock_MaxSeg_t; 500 501 /*! 502 \brief The SlNetSock_NoPush_t structure is used in #SLNETSOCK_TCP_NOPUSH TCP level option 503 */ 504 typedef struct SlNetSock_NoPush_t 505 { 506 uint32_t noPushEnabled; /**< 0 = disabled;1 = enabled; default = 0 */ 507 } SlNetSock_NoPush_t; 508 509 /*! 510 \brief The SlNetSock_NoOpt_t structure is used in #SLNETSOCK_TCP_NOOPT TCP level option 511 */ 512 typedef struct SlNetSock_NoOpt_t 513 { 514 uint32_t noOptEnabled; /**< 0 = disabled;1 = enabled; default = 0 */ 515 } SlNetSock_NoOpt_t; 516 517 /*! 518 \brief The SlNetSock_SackPermitted_t structure is used in #SLNETSOCK_TCP_NOPUSH TCP level option 519 */ 520 typedef struct SlNetSock_SackPermitted_t 521 { 522 uint32_t sackPermittedEnabled; /**< 0 = disabled;1 = enabled; default = 0 */ 523 } SlNetSock_SackPermitted_t; 524 525 /*! 526 \brief The SlNetSock_MaxRtt_t structure is used in #SLNETSOCK_TCP_MAXRTT TCP level option 527 */ 528 typedef struct SlNetSock_MaxRtt_t 529 { 530 uint32_t maxRtt; /**< Maximum TCP Round Trip Time value allowed; Default = 360000000 */ 531 } SlNetSock_MaxRtt_t; 532 533 /*! 534 \brief The SlNetSock_Keepalive_t structure is used in #SLNETSOCK_OPSOCK_KEEPALIVE socket level option 535 */ 536 typedef struct SlNetSock_Keepalive_t 537 { 538 uint32_t keepaliveEnabled; /**< 0 = disabled;1 = enabled; default = 1 */ 539 } SlNetSock_Keepalive_t; 540 541 /*! 542 \brief The SlNetSock_NonIpBoundary_t structure is used in #SLNETSOCK_OPSOCK_NON_IP_BOUNDARY socket level option 543 */ 544 typedef struct SlNetSock_NonIpBoundary_t 545 { 546 int32_t nonIpBoundaryEnabled; /**< 0 = keep IP boundary; 1 = don`t keep ip boundary; default = 0; */ 547 } SlNetSock_NonIpBoundary_t; 548 549 /*! 550 \brief The SlNetSock_Winsize_t structure is used in #SLNETSOCK_OPSOCK_RCV_BUF socket level option 551 */ 552 typedef struct SlNetSock_Winsize_t 553 { 554 uint32_t winSize; /**< receive window size for tcp sockets */ 555 } SlNetSock_Winsize_t; 556 557 /*! 558 \brief The SlNetSock_Nonblocking_t structure is used in #SLNETSOCK_OPSOCK_NON_BLOCKING socket level option 559 */ 560 typedef struct SlNetSock_Nonblocking_t 561 { 562 uint32_t nonBlockingEnabled; /**< 0 = disabled, 1 = enabled, default = 1*/ 563 } SlNetSock_Nonblocking_t; 564 565 /*! 566 \brief The SlNetSock_Broadcast_t structure is used in #SLNETSOCK_OPSOCK_BROADCAST socket level option 567 */ 568 typedef struct SlNetSock_Broadcast_t 569 { 570 uint32_t broadcastEnabled; /**< 0 = disabled, 1 = enabled, default = 0*/ 571 } SlNetSock_Broadcast_t; 572 573 /*! 574 \brief Secure socket attribute context 575 */ 576 typedef struct SlNetSock_SecAttribNode_t 577 { 578 SlNetSockSecAttrib_e attribName; /**< Security attribute name */ 579 uint8_t *attribBuff; /**< Security attribute buffer */ 580 uint16_t attribBuffLen; /**< Security attribute buffer length */ 581 struct SlNetSock_SecAttribNode_t *next; 582 } SlNetSock_SecAttribNode_t; 583 584 /*! 585 \brief Secure socket attribute handler 586 */ 587 typedef SlNetSock_SecAttribNode_t * SlNetSockSecAttrib_t; 588 589 /*! 590 \brief Secure ALPN structure 591 */ 592 typedef struct SlNetSock_SecureALPN_t 593 { 594 uint32_t secureALPN; 595 } SlNetSock_SecureALPN_t; 596 597 /*! 598 \brief Secure Mask structure 599 */ 600 typedef struct SlNetSock_SecureMask_t 601 { 602 uint32_t secureMask; 603 } SlNetSock_SecureMask_t; 604 605 /*! 606 \brief Secure Method structure 607 */ 608 typedef struct SlNetSock_SecureMethod_t 609 { 610 uint8_t secureMethod; 611 } SlNetSock_SecureMethod_t; 612 613 /*! 614 \brief The SlNetSock_IpMreq_t structure is used in #SLNETSOCK_OPIP_ADD_MEMBERSHIP and #SLNETSOCK_OPIP_DROP_MEMBERSHIP IP level option 615 */ 616 typedef struct SlNetSock_IpMreq_t 617 { 618 SlNetSock_InAddr_t imr_multiaddr; /**< The IPv4 multicast address to join */ 619 uint32_t imr_interface; /**< The interface to use for this group */ 620 } SlNetSock_IpMreq_t; 621 622 /*! 623 \brief The SlNetSock_IpV6Mreq_t structure is used in #SLNETSOCK_OPIPV6_ADD_MEMBERSHIP and #SLNETSOCK_OPIPV6_DROP_MEMBERSHIP IP level option 624 */ 625 typedef struct SlNetSock_IpV6Mreq_t 626 { 627 SlNetSock_In6Addr_t ipv6mr_multiaddr; /**< IPv6 multicast address of group */ 628 uint32_t ipv6mr_interface; /**< should be 0 to choose the default multicast interface */ 629 } SlNetSock_IpV6Mreq_t; 630 631 /*! 632 \brief The SlNetSock_linger_t structure is used in #SLNETSOCK_OPSOCK_LINGER socket level option 633 */ 634 typedef struct SlNetSock_linger_t 635 { 636 uint32_t l_onoff; /**< 0 = disabled; 1 = enabled; default = 0; */ 637 uint32_t l_linger; /**< linger time in seconds; default = 0; */ 638 } SlNetSock_linger_t; 639 640 /*! 641 \brief The @c SlNetSock_Timeval_t structure is used in the 642 #SLNETSOCK_OPSOCK_RCV_TIMEO and #SLNETSOCK_OPSOCK_SND_TIMEO 643 socket level options 644 645 \remarks Note that @c SlNetSock_Timeval_t is intentionally defined 646 to be equivalent to the POSIX-defined <tt>struct 647 timeval</tt> data type. 648 */ 649 typedef struct timeval SlNetSock_Timeval_t; 650 651 /*! 652 \brief The SlNetSocklen_t is used for declaring the socket length parameter 653 */ 654 typedef uint16_t SlNetSocklen_t; 655 656 /*! 657 \brief IpV4 socket address 658 */ 659 typedef struct SlNetSock_Addr_t 660 { 661 uint16_t sa_family; /**< Address family (e.g. AF_INET) */ 662 uint8_t sa_data[14]; /**< Protocol- specific address information */ 663 } SlNetSock_Addr_t; 664 665 /*! 666 \brief SlNetSock IPv6 address, Internet style 667 */ 668 typedef struct SlNetSock_AddrIn6_t 669 { 670 uint16_t sin6_family; /**< SLNETSOCK_AF_INET6 */ 671 uint16_t sin6_port; /**< Transport layer port. */ 672 uint32_t sin6_flowinfo; /**< IPv6 flow information. */ 673 SlNetSock_In6Addr_t sin6_addr; /**< IPv6 address. */ 674 uint32_t sin6_scope_id; /**< set of interfaces for a scope. */ 675 } SlNetSock_AddrIn6_t; 676 677 /*! 678 \brief SlNetSock IPv4 address, Internet style 679 */ 680 typedef struct SlNetSock_AddrIn_t 681 { 682 uint16_t sin_family; /**< Internet Protocol (AF_INET). */ 683 uint16_t sin_port; /**< Address port (16 bits). */ 684 SlNetSock_InAddr_t sin_addr; /**< Internet address (32 bits). */ 685 int8_t sin_zero[8]; /**< Not used. */ 686 } SlNetSock_AddrIn_t; 687 688 /* ss_family + pad must be large enough to hold max of 689 * _SlNetSock_AddrIn6_t or _SlNetSock_AddrIn_t 690 */ 691 /*! 692 \brief Generic socket address type to hold either IPv4 or IPv6 address 693 */ 694 typedef struct SlNetSock_SockAddrStorage_t 695 { 696 uint16_t ss_family; 697 uint8_t pad[26]; 698 } SlNetSock_SockAddrStorage_t; 699 700 /*! 701 \brief The SlNetSock_SdSet_t structure holds the sd array for SlNetSock_select function 702 */ 703 typedef struct SlNetSock_SdSet_t /**< The select socket array manager */ 704 { 705 uint32_t sdSetBitmap[(SLNETSOCK_MAX_CONCURRENT_SOCKETS + (uint8_t)31)/(uint8_t)32]; /* Bitmap of SOCKET Descriptors */ 706 } SlNetSock_SdSet_t; 707 708 709 /*! 710 \brief The SlNetSock_TransceiverRxOverHead_t structure holds the data for Rx transceiver mode using a raw socket when using SlNetSock_recv function 711 */ 712 typedef struct SlNetSock_TransceiverRxOverHead_t 713 { 714 uint8_t rate; /**< Received Rate */ 715 uint8_t channel; /**< The received channel */ 716 int8_t rssi; /**< The computed RSSI value in db of current frame */ 717 uint8_t padding; /**< pad to align to 32 bits */ 718 uint32_t timestamp; /**< Timestamp in microseconds */ 719 } SlNetSock_TransceiverRxOverHead_t; 720 721 722 /*****************************************************************************/ 723 /* Function prototypes */ 724 /*****************************************************************************/ 725 726 /*! 727 728 \brief Initialize the SlNetSock module 729 730 \param[in] flags Reserved 731 732 \return Zero on success, or negative error code on failure 733 734 \par Examples 735 \snippet ti/net/test/snippets/slnetif.c SlNetSock_init snippet 736 737 */ 738 int32_t SlNetSock_init(int32_t flags); 739 740 /*! 741 742 \brief Create an endpoint for communication 743 744 SlNetSock_create() creates a new socket of a certain socket type, 745 identified by an integer number, and allocates system resources to it.\n 746 This function is called by the application layer to obtain a socket descriptor (handle). 747 748 \param[in] domain Specifies the protocol family of the created socket. 749 For example: 750 - #SLNETSOCK_AF_INET for network protocol IPv4 751 - #SLNETSOCK_AF_INET6 for network protocol IPv6 752 - #SLNETSOCK_AF_RF for starting transceiver mode. 753 Notes: 754 - sending and receiving any packet overriding 802.11 header 755 - for optimized power consumption the socket will be started in TX 756 only mode until receive command is activated 757 \param[in] type Specifies the socket type, which determines the semantics of communication over 758 the socket. The socket types supported by the system are implementation-dependent. 759 Possible socket types include: 760 - #SLNETSOCK_SOCK_STREAM (reliable stream-oriented service or Stream Sockets) 761 - #SLNETSOCK_SOCK_DGRAM (datagram service or Datagram Sockets) 762 - #SLNETSOCK_SOCK_RAW (raw protocols atop the network layer) 763 - when used with AF_RF: 764 - #SLNETSOCK_SOCK_RX_MTR 765 - #SLNETSOCK_SOCK_MAC_WITH_CCA 766 - #SLNETSOCK_SOCK_MAC_WITH_NO_CCA 767 - #SLNETSOCK_SOCK_BRIDGE 768 - #SLNETSOCK_SOCK_ROUTER 769 \param[in] protocol Specifies a particular transport to be used with the socket.\n 770 The most common are 771 - #SLNETSOCK_PROTO_TCP 772 - #SLNETSOCK_PROTO_UDP 773 - #SLNETSOCK_PROTO_RAW 774 - #SLNETSOCK_PROTO_SECURE 775 \param[in] ifBitmap Specifies the interface(s) which the socket will be created on 776 according to priority until one of them will return an answer.\n 777 Value 0 is used in order to choose automatic interfaces selection 778 according to the priority interface list. 779 Value can be a combination of interfaces by OR'ing multiple interfaces bit identifiers 780 (SLNETIFC_IDENT_ defined in slnetif.h) 781 Note: interface identifier bit must be configured prior to this socket creation 782 using SlNetIf_add(). 783 \param[in] flags Specifies flags. 784 - #SLNETSOCK_CREATE_IF_STATE_ENABLE - Creation of the socket will be on enabled state 785 - #SLNETSOCK_CREATE_IF_STATUS_CONNECTED - Creation of the socket will be on status connected 786 - #SLNETSOCK_CREATE_ALLOW_PARTIAL_MATCH - Creation of the socket will be on the interface with 787 the highest priority if the other flags will fail 788 The value 0 may be used in order to run the default flags: 789 - #SLNETSOCK_CREATE_IF_STATE_ENABLE 790 - #SLNETSOCK_CREATE_IF_STATUS_CONNECTED 791 792 \return On success, socket descriptor (handle) that is used for consequent socket operations. \n 793 A successful return code should be a positive number\n 794 On error, a negative value will be returned specifying the error code. 795 - #SLNETERR_BSD_EAFNOSUPPORT - illegal domain parameter 796 - #SLNETERR_BSD_EPROTOTYPE - illegal type parameter 797 - #SLNETERR_BSD_EACCES - permission denied 798 - #SLNETERR_BSD_ENSOCK - exceeded maximal number of socket 799 - #SLNETERR_BSD_ENOMEM - memory allocation error 800 - #SLNETERR_BSD_EINVAL - error in socket configuration 801 - #SLNETERR_BSD_EPROTONOSUPPORT - illegal protocol parameter 802 - #SLNETERR_BSD_EOPNOTSUPP - illegal combination of protocol and type parameters 803 804 \slnetsock_init_precondition 805 806 \remark Not all platforms support all options. 807 808 \remark A @c protocol value of zero can be used to select the default protocol from the selected @c domain and @c type. 809 810 \remark SlNetSock_create() uses the highest priority interface from the ifBitmap, subject to the constraints specified 811 in the flags parameter. An interface that does not satisfy the constraints is ignored, without regards to its 812 priority level. 813 814 \par Examples 815 \snippet ti/net/test/snippets/slnetif.c SlNetSock_create TCP IPv4 snippet 816 \snippet ti/net/test/snippets/slnetif.c SlNetSock_create TCP IPv6 snippet 817 \snippet ti/net/test/snippets/slnetif.c SlNetSock_create UDP IPv4 snippet 818 819 \sa SlNetSock_close() 820 */ 821 int16_t SlNetSock_create(int16_t domain, int16_t type, int16_t protocol, uint32_t ifBitmap, int16_t flags); 822 823 824 /*! 825 \brief Gracefully close socket 826 827 Release resources allocated to a socket. 828 829 \param[in] sd Socket descriptor (handle), received in SlNetSock_create() 830 831 \return Zero on success, or negative error code on failure 832 833 \slnetsock_init_precondition 834 835 \remark In the case of TCP, the connection is terminated. 836 837 \remark After this function returns there is no way to access the socket 838 identified by @c sd. The SlNetSock socket is closed regardless 839 of the status of the underlying interface's socket. 840 841 \par Examples 842 \snippet ti/net/test/snippets/slnetif.c SlNetSock_close snippet 843 844 \sa SlNetSock_create() 845 */ 846 int32_t SlNetSock_close(int16_t sd); 847 848 849 /*! 850 \brief Shutting down parts of a full-duplex connection 851 852 Shuts down parts of a full-duplex connection according to how parameter.\n 853 854 \param[in] sd Socket descriptor (handle), received in SlNetSock_create 855 \param[in] how Specifies which part of a full-duplex connection to shutdown. \n 856 The options are 857 - #SLNETSOCK_SHUT_RD - further receptions will be disallowed 858 - #SLNETSOCK_SHUT_WR - further transmissions will be disallowed 859 - #SLNETSOCK_SHUT_RDWR - further receptions and transmissions will be disallowed 860 861 \return Zero on success, or negative error code on failure 862 863 \slnetsock_init_precondition 864 865 \sa SlNetSock_create() 866 \sa SlNetSock_connect() 867 \sa SlNetSock_accept() 868 */ 869 int32_t SlNetSock_shutdown(int16_t sd, int16_t how); 870 871 872 /*! 873 \brief Accept a connection on a socket 874 875 The SlNetSock_accept function is used with connection-based socket types (#SLNETSOCK_SOCK_STREAM). 876 877 It extracts the first connection request on the queue of pending 878 connections, creates a new connected socket, and returns a new file 879 descriptor referring to that socket. 880 881 The newly created socket is not in the listening state. The 882 original socket sd is unaffected by this call. 883 884 The argument sd is a socket that has been created with 885 SlNetSock_create(), bound to a local address with 886 SlNetSock_bind(), and is listening for connections after a 887 SlNetSock_listen(). 888 889 The argument \c addr is a pointer to a sockaddr structure. This 890 structure is filled in with the address of the peer socket, as 891 known to the communications layer. 892 893 The exact format of the address returned \c addr is determined by the socket's address family. 894 895 \c addrlen is a value-result argument: it should initially contain 896 the size of the structure pointed to by addr, on return it will 897 contain the actual length (in bytes) of the address returned. 898 899 \param[in] sd Socket descriptor (handle) 900 \param[out] addr The argument addr is a pointer 901 to a sockaddr structure. This 902 structure is filled in with the 903 address of the peer socket, as 904 known to the communications 905 layer. The exact format of the 906 address returned addr is 907 determined by the socket's 908 address\n 909 sockaddr:\n - code for the 910 address format.\n - 911 socket address, the length 912 depends on the code format 913 \param[out] addrlen The addrlen argument is a value-result 914 argument: it should initially contain the 915 size of the structure pointed to by addr 916 917 \return On success, a socket descriptor.\n 918 On a non-blocking accept a possible negative value is #SLNETERR_BSD_EAGAIN.\n 919 On failure, negative error code.\n 920 #SLNETERR_BSD_ENOMEM may be return in case there are no resources in the system 921 922 \slnetsock_init_precondition 923 924 \sa SlNetSock_create() 925 \sa SlNetSock_bind() 926 \sa SlNetSock_listen() 927 */ 928 int16_t SlNetSock_accept(int16_t sd, SlNetSock_Addr_t *addr, SlNetSocklen_t *addrlen); 929 930 931 /*! 932 \brief Assign a name to a socket 933 934 This SlNetSock_bind function gives the socket the local address 935 addr. addr is addrlen bytes long. 936 937 Traditionally, this is called when a socket is created with 938 socket, it exists in a name space (address family) but has no name 939 assigned. 940 941 It is necessary to assign a local address before a #SLNETSOCK_SOCK_STREAM 942 socket may receive connections. 943 944 \param[in] sd Socket descriptor (handle) 945 \param[in] addr Specifies the destination 946 addrs\n sockaddr:\n - code for 947 the address format.\n - socket address, 948 the length depends on the code 949 format 950 \param[in] addrlen Contains the size of the structure pointed to by addr 951 952 \return Zero on success, or negative error code on failure 953 954 \slnetsock_init_precondition 955 956 \sa SlNetSock_create() 957 \sa SlNetSock_accept() 958 \sa SlNetSock_listen() 959 */ 960 int32_t SlNetSock_bind(int16_t sd, const SlNetSock_Addr_t *addr, int16_t addrlen); 961 962 963 /*! 964 \brief Listen for connections on a socket 965 966 The willingness to accept incoming connections and a queue 967 limit for incoming connections are specified with SlNetSock_listen(), 968 and then the connections are accepted with SlNetSock_accept(). 969 970 \param[in] sd Socket descriptor (handle) 971 \param[in] backlog Specifies the listen queue depth. 972 973 \return Zero on success, or negative error code on failure 974 975 \slnetsock_init_precondition 976 977 \remark The SlNetSock_listen() call applies only to sockets of 978 type #SLNETSOCK_SOCK_STREAM. 979 980 \remark The \c backlog parameter defines the maximum length the queue of 981 pending connections may grow to. 982 983 \sa SlNetSock_create() 984 \sa SlNetSock_accept() 985 \sa SlNetSock_bind() 986 */ 987 int32_t SlNetSock_listen(int16_t sd, int16_t backlog); 988 989 990 /*! 991 \brief Initiate a connection on a socket 992 993 Function connects the socket referred to by the socket 994 descriptor sd, to the address specified by \c addr. 995 996 The format of the address in addr is determined by the address 997 space of the socket. 998 999 If it is of type #SLNETSOCK_SOCK_DGRAM, this call specifies the 1000 peer with which the socket is to be associated; this address is 1001 that to which datagrams are to be sent, and the only address from 1002 which datagrams are to be received. 1003 1004 If the socket is of type #SLNETSOCK_SOCK_STREAM, this call 1005 attempts to make a connection to another socket. 1006 1007 The other socket is specified by address, which is an address in 1008 the communications space of the socket. 1009 1010 \param[in] sd Socket descriptor (handle) 1011 \param[in] addr Specifies the destination addr\n 1012 sockaddr:\n - code for the 1013 address format.\n - 1014 socket address, the length 1015 depends on the code format 1016 \param[in] addrlen Contains the size of the structure pointed 1017 to by addr 1018 1019 \return On success, a socket descriptor (handle).\n 1020 On failure, negative value.\n 1021 On a non-blocking connect a possible negative value is #SLNETERR_BSD_EALREADY. 1022 #SLNETERR_POOL_IS_EMPTY may be returned in case there are no resources in the system 1023 1024 \slnetsock_init_precondition 1025 1026 \sa SlNetSock_create() 1027 */ 1028 int32_t SlNetSock_connect(int16_t sd, const SlNetSock_Addr_t *addr, SlNetSocklen_t addrlen); 1029 1030 /*! 1031 \brief Return address info about the remote side of the connection 1032 1033 Returns a struct SlNetSock_AddrIn_t 1034 filled with information about the peer device that is connected 1035 on the other side of the socket descriptor. 1036 1037 \param[in] sd Socket descriptor (handle) 1038 \param[out] addr returns the struct addr\n 1039 SlNetSockAddrIn filled with information 1040 about the peer device:\n - code for the 1041 address format.\n - 1042 socket address, the length 1043 depends on the code format 1044 \param[out] addrlen Contains the size of the structure pointed 1045 to by addr 1046 1047 \return Zero on success, or negative error code on failure 1048 1049 \slnetsock_init_precondition 1050 1051 \sa SlNetSock_accept() 1052 \sa SlNetSock_connect() 1053 */ 1054 int32_t SlNetSock_getPeerName(int16_t sd, SlNetSock_Addr_t *addr, SlNetSocklen_t *addrlen); 1055 1056 1057 /*! 1058 \brief Get local address info by socket descriptor 1059 1060 Returns the local address info of the socket descriptor. 1061 1062 \param[in] sd Socket descriptor (handle) 1063 \param[out] addr The argument addr is a pointer 1064 to a SlNetSock_Addr_t structure. This 1065 structure is filled in with the 1066 address of the peer socket, as 1067 known to the communications 1068 layer. The exact format of the 1069 address returned addr is 1070 determined by the socket's 1071 address\n 1072 SlNetSock_Addr_t:\n - code for the 1073 address format.\n - 1074 socket address, the length 1075 depends on the code format 1076 \param[out] addrlen The addrlen argument is a value-result 1077 argument: it should initially contain the 1078 size of the structure pointed to by addr 1079 1080 \return Zero on success, or negative on failure. 1081 1082 \slnetsock_init_precondition 1083 1084 \remark If the provided buffer is too small the returned address 1085 will be truncated and \c addrlen will contain the 1086 actual size of the socket address. 1087 1088 \sa SlNetSock_create() 1089 \sa SlNetSock_bind() 1090 */ 1091 int32_t SlNetSock_getSockName(int16_t sd, SlNetSock_Addr_t *addr, SlNetSocklen_t *addrlen); 1092 1093 1094 /*! 1095 \brief Monitor socket activity 1096 1097 SlNetSock_select() allow a program to monitor multiple file descriptors, 1098 waiting until one or more of the file descriptors become 1099 "ready" for some class of I/O operation. 1100 1101 \param[in] nsds The highest-numbered file descriptor in any of the 1102 three sets, plus 1. 1103 \param[in,out] readsds Socket descriptors list for read monitoring and accept monitoring 1104 \param[in,out] writesds Socket descriptors list for connect monitoring only, write monitoring is not supported 1105 \param[in,out] exceptsds Socket descriptors list for exception monitoring, not supported. 1106 \param[in] timeout Is an upper bound on the amount of time elapsed 1107 before SlNetSock_select() returns. Null or above 0xffff seconds means 1108 infinity timeout. The minimum timeout is 10 milliseconds, 1109 less than 10 milliseconds will be set automatically to 10 milliseconds. 1110 Max microseconds supported is 0xfffc00. 1111 In trigger mode the timeout fields must be set to zero. 1112 1113 \return On success, SlNetSock_select() returns the number of 1114 file descriptors contained in the three returned 1115 descriptor sets (that is, the total number of bits that 1116 are set in readsds, writesds, exceptsds) which may be 1117 zero if the timeout expires before anything interesting 1118 happens.\n On error, a negative value is returned. 1119 readsds - return the sockets on which Read request will 1120 return without delay with valid data.\n 1121 writesds - return the sockets on which Write request 1122 will return without delay.\n 1123 exceptsds - return the sockets closed recently. \n 1124 #SLNETERR_BSD_ENOMEM may be return in case there are no resources in the system 1125 1126 \slnetsock_init_precondition 1127 1128 \remark If \c timeout is set to less than 10ms it will 1129 automatically set to 10ms to prevent overload of the 1130 system 1131 1132 \sa SlNetSock_create() 1133 */ 1134 int32_t SlNetSock_select(int16_t nsds, SlNetSock_SdSet_t *readsds, SlNetSock_SdSet_t *writesds, SlNetSock_SdSet_t *exceptsds, SlNetSock_Timeval_t *timeout); 1135 1136 1137 /*! 1138 \brief SlNetSock_select's SlNetSock_SdSet_t SET function 1139 1140 Sets current socket descriptor on SlNetSock_SdSet_t container 1141 */ 1142 int32_t SlNetSock_sdsSet(int16_t sd, SlNetSock_SdSet_t *sdset); 1143 1144 1145 /*! 1146 \brief SlNetSock_select's SlNetSock_SdSet_t CLR function 1147 1148 Clears current socket descriptor on SlNetSock_SdSet_t container 1149 */ 1150 int32_t SlNetSock_sdsClr(int16_t sd, SlNetSock_SdSet_t *sdset); 1151 1152 1153 /*! 1154 \brief SlNetSock_select's SlNetSock_SdSet_t ZERO function 1155 1156 Clears all socket descriptors from SlNetSock_SdSet_t 1157 */ 1158 int32_t SlNetSock_sdsClrAll(SlNetSock_SdSet_t *sdset); 1159 1160 1161 /*! 1162 \brief SlNetSock_select's SlNetSock_SdSet_t ISSET function 1163 1164 Checks if current socket descriptor is set (true/false) 1165 1166 \return Returns true if set, false if unset 1167 1168 */ 1169 int32_t SlNetSock_sdsIsSet(int16_t sd, SlNetSock_SdSet_t *sdset); 1170 1171 1172 /*! 1173 \brief Set socket options 1174 1175 SlNetSock_setOpt() manipulates the options associated with a socket. 1176 1177 Options may exist at multiple protocol levels; they are always 1178 present at the uppermost socket level. 1179 1180 When manipulating socket options the level at which the option resides 1181 and the name of the option must be specified. To manipulate options at 1182 the socket level, level is specified as #SLNETSOCK_LVL_SOCKET. To manipulate 1183 options at any other level the protocol number of the appropriate protocol 1184 controlling the option is supplied. For example, to indicate that an 1185 option is to be interpreted by the TCP protocol, level should be set to 1186 the protocol number of TCP. 1187 1188 \c optval and \c optlen are used to access opt_values 1189 for SlNetSock_setOpt(). For SlNetSock_getOpt() they identify a 1190 buffer in which the value for the requested option(s) are to 1191 be returned. For SlNetSock_getOpt(), \c optlen is a value-result 1192 parameter, initially containing the size of the buffer 1193 pointed to by option_value, and modified on return to 1194 indicate the actual size of the value returned. If no option 1195 value is to be supplied or returned, \c optval may be \c NULL. 1196 1197 \param[in] sd Socket descriptor (handle) 1198 \param[in] level Defines the protocol level for this option 1199 - #SLNETSOCK_LVL_SOCKET - Socket level configurations (L4, transport layer) 1200 - #SLNETSOCK_LVL_IP - IP level configurations (L3, network layer) 1201 - #SLNETSOCK_LVL_PHY - Link level configurations (L2, link layer) 1202 \param[in] optname Defines the option name to interrogate 1203 - #SLNETSOCK_LVL_SOCKET 1204 - #SLNETSOCK_OPSOCK_RCV_BUF\n 1205 Sets tcp max recv window size.\n 1206 This options takes SlNetSock_Winsize_t struct as parameter 1207 - #SLNETSOCK_OPSOCK_RCV_TIMEO\n 1208 Sets the timeout value that specifies the maximum amount of time an input function waits until it completes.\n 1209 Default: No timeout\n 1210 This options takes SlNetSock_Timeval_t struct as parameter 1211 - #SLNETSOCK_OPSOCK_KEEPALIVE\n 1212 Enable or Disable periodic keep alive. 1213 Keeps TCP connections active by enabling the periodic transmission of messages \n 1214 Timeout is 5 minutes.\n 1215 Default: Enabled \n 1216 This options takes SlNetSock_Keepalive_t struct as parameter 1217 - #SLNETSOCK_OPSOCK_KEEPALIVE_TIME\n 1218 Set keep alive timeout. 1219 Value is in seconds \n 1220 Default: 5 minutes \n 1221 - #SLNETSOCK_OPSOCK_LINGER\n 1222 Socket lingers on close pending remaining send/receive packets\n 1223 - #SLNETSOCK_OPSOCK_NON_BLOCKING\n 1224 Sets socket to non-blocking operation Impacts: connect, accept, send, sendto, recv and recvfrom. \n 1225 Default: Blocking. 1226 This options takes SlNetSock_Nonblocking_t struct as parameter 1227 - #SLNETSOCK_OPSOCK_NON_IP_BOUNDARY\n 1228 Enable or Disable rx ip boundary. 1229 In connectionless socket (udp/raw), unread data is dropped (when SlNetSock_recvFrom() len parameter < data size), Enable this option in order to read the left data on the next SlNetSock_recvFrom() iteration\n 1230 Default: Disabled, IP boundary kept\n 1231 This options takes SlNetSock_NonIpBoundary_t struct as parameter 1232 - #SLNETSOCK_LVL_IP 1233 - #SLNETSOCK_OPIP_MULTICAST_TTL\n 1234 Set the time-to-live value of outgoing multicast packets for this socket. \n 1235 This options takes <b>uint8_t</b> as parameter 1236 - #SLNETSOCK_OPIP_ADD_MEMBERSHIP \n 1237 UDP socket, Join a multicast group. \n 1238 This options takes SlNetSock_IpMreq_t struct as parameter 1239 - #SLNETSOCK_OPIP_DROP_MEMBERSHIP \n 1240 UDP socket, Leave a multicast group \n 1241 This options takes SlNetSock_IpMreq_t struct as parameter 1242 - #SLNETSOCK_OPIP_HDRINCL \n 1243 RAW socket only, the IPv4 layer generates an IP header when sending a packet unless \n 1244 the IP_HDRINCL socket option is enabled on the socket. \n 1245 When it is enabled, the packet must contain an IP header. \n 1246 Default: disabled, IPv4 header generated by Network Stack \n 1247 This options takes <b>uint32_t</b> as parameter 1248 - #SLNETSOCK_OPIP_RAW_RX_NO_HEADER \n 1249 Raw socket remove IP header from received data. \n 1250 Default: data includes ip header \n 1251 This options takes <b>uint32_t</b> as parameter 1252 - #SLNETSOCK_OPIP_RAW_IPV6_HDRINCL (inactive) \n 1253 RAW socket only, the IPv6 layer generates an IP header when sending a packet unless \n 1254 the IP_HDRINCL socket option is enabled on the socket. When it is enabled, the packet must contain an IP header \n 1255 Default: disabled, IPv4 header generated by Network Stack \n 1256 This options takes <b>uint32_t</b> as parameter 1257 - #SLNETSOCK_LVL_PHY 1258 - #SLNETSOCK_OPPHY_CHANNEL \n 1259 Sets channel in transceiver mode. 1260 This options takes <b>uint32_t</b> as channel number parameter 1261 - #SLNETSOCK_OPPHY_RATE \n 1262 RAW socket, set WLAN PHY transmit rate \n 1263 The values are based on SlWlanRateIndex_e \n 1264 This options takes <b>uint32_t</b> as parameter 1265 - #SLNETSOCK_OPPHY_TX_POWER \n 1266 RAW socket, set WLAN PHY TX power \n 1267 Valid rage is 1-15 \n 1268 This options takes <b>uint32_t</b> as parameter 1269 - #SLNETSOCK_OPPHY_NUM_FRAMES_TO_TX \n 1270 RAW socket, set number of frames to transmit in transceiver mode. 1271 Default: 1 packet 1272 This options takes <b>uint32_t</b> as parameter 1273 - #SLNETSOCK_OPPHY_PREAMBLE \n 1274 RAW socket, set WLAN PHY preamble for Long/Short\n 1275 This options takes <b>uint32_t</b> as parameter 1276 - #SLNETSOCK_OPPHY_TX_INHIBIT_THRESHOLD \n 1277 RAW socket, set WLAN Tx - Set CCA threshold. \n 1278 The values are based on SlNetSockTxInhibitThreshold_e \n 1279 This options takes <b>uint32_t</b> as parameter 1280 - #SLNETSOCK_OPPHY_TX_TIMEOUT \n 1281 RAW socket, set WLAN Tx - changes the TX timeout (lifetime) of transceiver frames. \n 1282 Value in Ms, maximum value is 10ms \n 1283 This options takes <b>uint32_t</b> as parameter 1284 - #SLNETSOCK_OPPHY_ALLOW_ACKS \n 1285 RAW socket, set WLAN Tx - Enable or Disable sending ACKs in transceiver mode \n 1286 0 = disabled / 1 = enabled \n 1287 This options takes <b>uint32_t</b> as parameter 1288 - #SLNETSOCK_PROTO_TCP 1289 - #SLNETSOCK_TCP_NODELAY \n 1290 Disables TCP send delay/coalesce algorithm. \n 1291 This option takes SLNetSock_NoDelay_t struct as a parameter. 1292 - #SLNETSOCK_TCP_MAXSEG \n 1293 Set the maximum TCP segment size \n 1294 This option takes SLNetSock_MaxSeg_t struct as a parameter. 1295 - #SLNETSOCK_TCP_NOPUSH \n 1296 Do not send data just to finish a data block (attempt to coalesce). \n 1297 This option takes SLNetSock_NoPush_t struct as a parameter 1298 - #SLNETSOCK_TCP_NOOPT \n 1299 Do not use TCP options. \n 1300 This option takes SLNetSock_NoOpt_t struct as a parameter. 1301 - #SLNETSOCK_TCP_SACKPERMITTED \n 1302 Permit RFC-2018 Selective Acknowledgment(SACK) conformant connection 1303 This option takes SLNetSock_SackPermitted_t struct as a parameter 1304 - #SLNETSOCK_TCP_MAXRTT \n 1305 The maximum TCP Round Trip Time value allowed in the determination of the estimated TCP RTT. \n 1306 This option takes SLNetSock_MaxRtt_t struct as a parameter 1307 1308 \param[in] optval Specifies a value for the option 1309 \param[in] optlen Specifies the length of the 1310 option value 1311 1312 \return Zero on success, or negative error code on failure 1313 1314 \par Persistent 1315 All params are <b>Non- Persistent</b> 1316 1317 \slnetsock_init_precondition 1318 1319 \par Examples 1320 1321 - SLNETSOCK_OPSOCK_RCV_BUF: 1322 \code 1323 SlNetSock_Winsize_t size; 1324 size.winsize = 3000; // bytes 1325 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_RCV_BUF, (uint8_t *)&size, sizeof(size)); 1326 \endcode 1327 <br> 1328 1329 - SLNETSOCK_OPSOCK_RCV_TIMEO: 1330 \code 1331 struct SlNetSock_Timeval_t timeVal; 1332 timeVal.tv_sec = 1; // Seconds 1333 timeVal.tv_usec = 0; // Microseconds. 10000 microseconds resolution 1334 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_RCV_TIMEO, (uint8_t *)&timeVal, sizeof(timeVal)); // Enable receive timeout 1335 \endcode 1336 <br> 1337 1338 - SLNETSOCK_OPSOCK_KEEPALIVE: //disable Keepalive 1339 \code 1340 SlNetSock_Keepalive_t enableOption; 1341 enableOption.keepaliveEnabled = 0; 1342 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_KEEPALIVE, (uint8_t *)&enableOption, sizeof(enableOption)); 1343 \endcode 1344 <br> 1345 1346 - SLNETSOCK_OPSOCK_KEEPALIVE_TIME: //Set Keepalive timeout 1347 \code 1348 int16_t Status; 1349 uint32_t TimeOut = 120; 1350 SlNetSock_setOpt(Sd, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_KEEPALIVE_TIME, (uint8_t *)&TimeOut, sizeof(TimeOut)); 1351 \endcode 1352 <br> 1353 1354 - SLNETSOCK_OPSOCK_NON_BLOCKING: //Enable or disable nonblocking mode 1355 \code 1356 SlNetSock_Nonblocking_t enableOption; 1357 enableOption.nonBlockingEnabled = 1; 1358 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_NON_BLOCKING, (uint8_t *)&enableOption, sizeof(enableOption)); 1359 \endcode 1360 <br> 1361 1362 - SLNETSOCK_OPSOCK_NON_IP_BOUNDARY: //disable boundary 1363 \code 1364 SlNetSock_NonIpBoundary_t enableOption; 1365 enableOption.nonIpBoundaryEnabled = 1; 1366 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_NON_IP_BOUNDARY, (uint8_t *)&enableOption, sizeof(enableOption)); 1367 \endcode 1368 <br> 1369 1370 - SLNETSOCK_OPSOCK_LINGER: 1371 \code 1372 SlNetSock_linger_t linger; 1373 linger.l_onoff = 1; 1374 linger.l_linger = 10; 1375 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_LINGER, &linger, sizeof(linger)); 1376 \endcode 1377 <br> 1378 1379 - SLNETSOCK_OPIP_MULTICAST_TTL: 1380 \code 1381 uint8_t ttl = 20; 1382 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_MULTICAST_TTL, &ttl, sizeof(ttl)); 1383 \endcode 1384 <br> 1385 1386 - SLNETSOCK_OPIP_ADD_MEMBERSHIP: 1387 \code 1388 SlNetSock_IpMreq_t mreq; 1389 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); 1390 \endcode 1391 <br> 1392 1393 - SLNETSOCK_OPIP_DROP_MEMBERSHIP: 1394 \code 1395 SlNetSock_IpMreq_t mreq; 1396 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); 1397 \endcode 1398 <br> 1399 1400 - SLNETSOCK_OPIP_RAW_RX_NO_HEADER: 1401 \code 1402 uint32_t header = 1; // remove ip header 1403 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_RAW_RX_NO_HEADER, &header, sizeof(header)); 1404 \endcode 1405 <br> 1406 1407 - SLNETSOCK_OPIP_HDRINCL: 1408 \code 1409 uint32_t header = 1; 1410 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_HDRINCL, &header, sizeof(header)); 1411 \endcode 1412 <br> 1413 1414 - SLNETSOCK_OPIP_RAW_IPV6_HDRINCL: 1415 \code 1416 uint32_t header = 1; 1417 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_RAW_IPV6_HDRINCL, &header, sizeof(header)); 1418 \endcode 1419 <br> 1420 1421 - SLNETSOCK_OPPHY_CHANNEL: 1422 \code 1423 uint32_t newChannel = 6; // range is 1-13 1424 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPPHY_CHANNEL, &newChannel, sizeof(newChannel)); 1425 \endcode 1426 <br> 1427 1428 - SLNETSOCK_OPPHY_RATE: 1429 \code 1430 uint32_t rate = 6; // see wlan.h SlWlanRateIndex_e for values 1431 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_RATE, &rate, sizeof(rate)); 1432 \endcode 1433 <br> 1434 1435 - SLNETSOCK_OPPHY_TX_POWER: 1436 \code 1437 uint32_t txpower = 1; // valid range is 1-15 1438 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_TX_POWER, &txpower, sizeof(txpower)); 1439 \endcode 1440 <br> 1441 1442 - SLNETSOCK_OPPHY_NUM_FRAMES_TO_TX: 1443 \code 1444 uint32_t numframes = 1; 1445 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_NUM_FRAMES_TO_TX, &numframes, sizeof(numframes)); 1446 \endcode 1447 <br> 1448 1449 - SLNETSOCK_OPPHY_PREAMBLE: 1450 \code 1451 uint32_t preamble = 1; 1452 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_PREAMBLE, &preamble, sizeof(preamble)); 1453 \endcode 1454 <br> 1455 1456 - SLNETSOCK_OPPHY_TX_INHIBIT_THRESHOLD: 1457 \code 1458 uint32_t thrshld = SLNETSOCK_TX_INHIBIT_THRESHOLD_MED; 1459 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_TX_INHIBIT_THRESHOLD, &thrshld, sizeof(thrshld)); 1460 \endcode 1461 <br> 1462 1463 - SLNETSOCK_OPPHY_TX_TIMEOUT: 1464 \code 1465 uint32_t timeout = 50; 1466 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_TX_TIMEOUT, &timeout, sizeof(timeout)); 1467 \endcode 1468 <br> 1469 1470 - SLNETSOCK_OPPHY_ALLOW_ACKS: 1471 \code 1472 uint32_t acks = 1; // 0 = disabled / 1 = enabled 1473 SlNetSock_setOpt(SockID, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_ALLOW_ACKS, &acks, sizeof(acks)); 1474 \endcode 1475 1476 \sa slNetSock_create() 1477 \sa SlNetSock_getOpt() 1478 */ 1479 int32_t SlNetSock_setOpt(int16_t sd, int16_t level, int16_t optname, void *optval, SlNetSocklen_t optlen); 1480 1481 1482 /*! 1483 \brief Get socket options 1484 1485 The SlNetSock_getOpt function gets the options associated with a socket. 1486 Options may exist at multiple protocol levels; they are always 1487 present at the uppermost socket level. 1488 1489 The parameters optval and optlen identify a 1490 buffer in which the value for the requested option(s) are to 1491 be returned. \c optlen is a value-result 1492 parameter, initially containing the size of the buffer 1493 pointed to by option_value, and modified on return to 1494 indicate the actual size of the value returned. If no option 1495 value is to be supplied or returned, \c optval may be \c NULL. 1496 1497 1498 \param[in] sd Socket descriptor (handle) 1499 \param[in] level Defines the protocol level for this option 1500 \param[in] optname defines the option name to interrogate 1501 \param[out] optval Specifies a value for the option 1502 \param[out] optlen Specifies the length of the 1503 option value 1504 1505 \return Zero on success, or negative error code on failure 1506 1507 \slnetsock_init_precondition 1508 1509 \sa SlNetSock_create() 1510 \sa SlNetSock_setOpt() 1511 */ 1512 int32_t SlNetSock_getOpt(int16_t sd, int16_t level, int16_t optname, void *optval, SlNetSocklen_t *optlen); 1513 1514 1515 /*! 1516 \brief Read data from TCP socket 1517 1518 The SlNetSock_recv function receives a message from a connection-mode socket 1519 1520 \param[in] sd Socket descriptor (handle) 1521 \param[out] buf Points to the buffer where the 1522 message should be stored. 1523 \param[in] len Specifies the length in bytes of 1524 the buffer pointed to by the buffer argument. 1525 Range: 1-16000 bytes 1526 \param[in] flags Specifies the type of message 1527 reception. On this version, this parameter is not 1528 supported. 1529 1530 \return Return the number of bytes received, 1531 or a negative value if an error occurred.\n 1532 Using a non-blocking recv a possible negative value is #SLNETERR_BSD_EAGAIN.\n 1533 #SLNETERR_BSD_ENOMEM may be return in case there are no resources in the system 1534 1535 \slnetsock_init_precondition 1536 1537 \par Examples 1538 \snippet ti/net/test/snippets/slnetif.c SlNetSock_recv snippet 1539 1540 \sa SlNetSock_create() 1541 \sa SlNetSock_recvFrom() 1542 */ 1543 int32_t SlNetSock_recv(int16_t sd, void *buf, uint32_t len, uint32_t flags); 1544 1545 1546 /*! 1547 \brief Read data from socket 1548 1549 SlNetSock_recvFrom function receives a message from a connection-mode or 1550 connectionless-mode socket 1551 1552 \param[in] sd Socket descriptor (handle) 1553 \param[out] buf Points to the buffer where the message should be stored. 1554 \param[in] len Specifies the length in bytes of the buffer pointed to by the buffer argument. 1555 Range: 1-16000 bytes 1556 \param[in] flags Specifies the type of message 1557 reception. On this version, this parameter is not 1558 supported 1559 \param[in] from Pointer to an address structure 1560 indicating the source 1561 address.\n sockaddr:\n - code 1562 for the address format.\n - socket address, 1563 the length depends on the code 1564 format 1565 \param[in] fromlen Source address structure 1566 size. This parameter MUST be set to the size of the structure pointed to by addr. 1567 1568 1569 \return Return the number of bytes received, 1570 or a negative value if an error occurred.\n 1571 Using a non-blocking recv a possible negative value is #SLNETERR_BSD_EAGAIN. 1572 #SLNETERR_RET_CODE_INVALID_INPUT will be returned if fromlen has incorrect length.\n 1573 #SLNETERR_BSD_ENOMEM may be return in case there are no resources in the system 1574 1575 \slnetsock_init_precondition 1576 1577 \par Example 1578 \snippet ti/net/test/snippets/slnetif.c SlNetSock_recvFrom snippet 1579 1580 \sa SlNetSock_create() 1581 \sa SlNetSock_recv() 1582 */ 1583 int32_t SlNetSock_recvFrom(int16_t sd, void *buf, uint32_t len, uint32_t flags, SlNetSock_Addr_t *from, SlNetSocklen_t *fromlen); 1584 1585 1586 /*! 1587 \brief Write data to TCP socket 1588 1589 Transmits a message to another socket. 1590 Returns immediately after sending data to device. 1591 In case of a RAW socket (transceiver mode), extra 4 bytes should be reserved at the end of the 1592 frame data buffer for WLAN FCS 1593 1594 \param[in] sd Socket descriptor (handle) 1595 \param[in] buf Points to a buffer containing 1596 the message to be sent 1597 \param[in] len Message size in bytes. 1598 \param[in] flags Specifies the type of message 1599 transmission. On this version, this parameter is not 1600 supported for TCP. 1601 1602 \return Return the number of bytes sent, 1603 or a negative value if an error occurred. 1604 1605 \slnetsock_init_precondition 1606 1607 \par Example 1608 \snippet ti/net/test/snippets/slnetif.c SlNetSock_send snippet 1609 1610 \sa SlNetSock_create() 1611 \sa SlNetSock_sendTo() 1612 */ 1613 int32_t SlNetSock_send(int16_t sd, const void *buf, uint32_t len, uint32_t flags); 1614 1615 1616 /*! 1617 \brief Write data to socket 1618 1619 The SlNetSock_sendTo function is used to transmit a message on a connectionless socket 1620 (connection less socket #SLNETSOCK_SOCK_DGRAM, #SLNETSOCK_SOCK_RAW). 1621 1622 Returns immediately after sending data to device. 1623 1624 \param[in] sd Socket descriptor (handle) 1625 \param[in] buf Points to a buffer containing 1626 the message to be sent 1627 \param[in] len message size in bytes. 1628 \param[in] flags Specifies the type of message 1629 transmission. On this version, this parameter is not 1630 supported 1631 \param[in] to Pointer to an address structure 1632 indicating the destination 1633 address.\n sockaddr:\n - code 1634 for the address format.\n - socket address, 1635 the length depends on the code 1636 format 1637 \param[in] tolen Destination address structure size 1638 1639 \return Return the number of bytes sent, 1640 or a negative value if an error occurred.\n 1641 1642 \slnetsock_init_precondition 1643 1644 \par Example 1645 \snippet ti/net/test/snippets/slnetif.c SlNetSock_sendTo snippet 1646 1647 \sa SlNetSock_create() 1648 \sa SlNetSock_send() 1649 */ 1650 int32_t SlNetSock_sendTo(int16_t sd, const void *buf, uint32_t len, uint32_t flags, const SlNetSock_Addr_t *to, SlNetSocklen_t tolen); 1651 1652 1653 /*! 1654 \brief Get interface ID from socket descriptor (sd) 1655 1656 \param[in] sd Specifies the socket descriptor which its 1657 interface identifier needs to be retrieved.\n 1658 1659 \return The interface identifier value of the 1660 interface on success, or negative error code 1661 on failure. The values of the interface 1662 identifier is defined with the prefix 1663 @c SLNETIF_ID_ in slnetif.h. 1664 1665 \slnetsock_init_precondition 1666 1667 \par Examples 1668 \snippet ti/net/test/snippets/slnetif.c SlNetSock_getIfID snippet 1669 1670 \sa SlNetSock_create() 1671 \sa SlNetIf_add() 1672 \sa SlNetIf_getIDByName() 1673 */ 1674 int32_t SlNetSock_getIfID(uint16_t sd); 1675 1676 1677 /*! 1678 \brief Creates a security attributes object 1679 1680 Create a security attribute, which is required in order to start a secure session. 1681 1682 \remark When the security attributes object is no longer needed, call 1683 SlNetSock_secAttribDelete() to destroy it. 1684 1685 \remark A single security object can be used to initiate several secure 1686 sessions (provided they all have the same security attributes). 1687 1688 \slnetsock_init_precondition 1689 1690 \sa SlNetSock_startSec() 1691 \sa SlNetSock_secAttribDelete() 1692 */ 1693 SlNetSockSecAttrib_t *SlNetSock_secAttribCreate(void); 1694 1695 1696 /*! 1697 \brief Deletes a security attributes object 1698 1699 \param[in] secAttrib Secure attribute handle 1700 1701 \return Zero on success, or negative error code 1702 on failure 1703 1704 \slnetsock_init_precondition 1705 1706 \remark \c secAttrib must be created using SlNetSock_secAttribCreate() 1707 1708 \sa SlNetSock_secAttribCreate() 1709 \sa SlNetSock_secAttribSet() 1710 \sa SlNetSock_startSec() 1711 */ 1712 int32_t SlNetSock_secAttribDelete(SlNetSockSecAttrib_t *secAttrib); 1713 1714 1715 /*! 1716 \brief set a security attribute 1717 1718 The SlNetSock_secAttribSet function is used to set a security 1719 attribute of a security attribute object. 1720 1721 \param[in] secAttrib Secure attribute handle 1722 \param[in] attribName Define the actual attribute to set. Applicable values: 1723 - #SLNETSOCK_SEC_ATTRIB_PRIVATE_KEY \n 1724 Sets the private key corresponding to the local certificate \n 1725 This attribute takes the name of security object containing the private key and the name's length (including the NULL terminating character) as parameters \n 1726 - #SLNETSOCK_SEC_ATTRIB_LOCAL_CERT \n 1727 Sets the local certificate chain \n 1728 This attribute takes the name of the security object containing the certificate and the name's length (including the NULL terminating character) as parameters \n 1729 For certificate chains, each certificate in the chain can be added via a separate call to SlNetSock_secAttribSet, starting with the root certificate of the chain \n 1730 - #SLNETSOCK_SEC_ATTRIB_PEER_ROOT_CA \n 1731 Sets the root CA certificate \n 1732 This attribute takes the name of the security object containing the certificate and the name's length (including the NULL terminating character) as parameters \n 1733 - #SLNETSOCK_SEC_ATTRIB_DH_KEY \n 1734 Sets the DH Key \n 1735 This attribute takes the name of the security object containing the DH Key and the name's length (including the NULL terminating character) as parameters \n 1736 - #SLNETSOCK_SEC_ATTRIB_METHOD \n 1737 Sets the TLS protocol version \n 1738 This attribute takes a <b>SLNETSOCK_SEC_METHOD_*</b> option and <b>sizeof(uint8_t)</b> as parameters \n 1739 - #SLNETSOCK_SEC_ATTRIB_CIPHERS \n 1740 Sets the ciphersuites to be used for the connection \n 1741 This attribute takes a bit mask formed using <b>SLNETSOCK_SEC_CIPHER_*</b> options and <b>sizeof(uint32_t)</b> as parameters \n 1742 - #SLNETSOCK_SEC_ATTRIB_ALPN \n 1743 Sets the ALPN \n 1744 This attribute takes a bit mask formed using <b>SLNETSOCK_SEC_ALPN_*</b> options and <b>sizeof(uint32_t)</b> as parameters \n 1745 - #SLNETSOCK_SEC_ATTRIB_EXT_CLIENT_CHLNG_RESP \n 1746 Sets the EXT CLIENT CHLNG RESP \n 1747 Format TBD \n 1748 - #SLNETSOCK_SEC_ATTRIB_DOMAIN_NAME \n 1749 Sets the domain name for verification during connection \n 1750 This attribute takes a string with the domain name and the string's length (including the NULL-terminating character) as parameters \n 1751 - #SLNETSOCK_SEC_ATTRIB_DISABLE_CERT_STORE\n 1752 Sets whether to disable the certificate store \n 1753 This attribute takes <b>1</b> (disable) or <b>0</b> (enable) and <b>sizeof(uint32_t)</b> as parameters \n 1754 1755 \param[in] val 1756 \param[in] len 1757 1758 \return Zero on success, or negative error code 1759 on failure 1760 1761 \slnetsock_init_precondition 1762 1763 \note Once an attribute is set, it cannot be unset or set to something 1764 different. Doing so may result in undefined behavior. 1765 Instead, SlNetSock_secAttribDelete() should be called on the 1766 existing object, and a new security object should be created with 1767 the new attribute set. 1768 1769 \note The #SLNETSOCK_SEC_ATTRIB_DISABLE_CERT_STORE value 1770 is currently being evaluated, and may be removed in a 1771 future release. It is currently only supported on CC3xxx 1772 devices. 1773 1774 \par Examples 1775 1776 - SLNETSOCK_SEC_ATTRIB_PRIVATE_KEY: 1777 \code 1778 #define PRIVATE_KEY_FILE "DummyKey" 1779 SlNetIf_loadSecObj(SLNETIF_SEC_OBJ_TYPE_RSA_PRIVATE_KEY, PRIVATE_KEY_FILE, strlen(PRIVATE_KEY_FILE), srvKeyPem, srvKeyPemLen, SLNETIF_ID_2); 1780 SlNetSock_secAttribSet(secAttrib, SLNETSOCK_SEC_ATTRIB_PRIVATE_KEY, PRIVATE_KEY_FILE, sizeof(PRIVATE_KEY_FILE)); 1781 \endcode 1782 <br> 1783 1784 - SLNETSOCK_SEC_ATTRIB_LOCAL_CERT: 1785 \code 1786 #define ROOT_CA_CERT_FILE "DummyCA" 1787 #define TRUSTED_CERT_FILE "DummyTrustedCert" 1788 1789 // create a local certificate chain 1790 SlNetIf_loadSecObj(SLNETIF_SEC_OBJ_TYPE_CERTIFICATE, ROOT_CA_CERT_FILE, strlen(ROOT_CA_CERT_FILE), srvCAPem, srvCAPemLen, SLNETIF_ID_2); 1791 SlNetIf_loadSecObj(SLNETIF_SEC_OBJ_TYPE_CERTIFICATE, TRUSTED_CERT_FILE, strlen(TRUSTED_CERT_FILE), srvCertPem, srvCertPemLen, SLNETIF_ID_2); 1792 SlNetSock_secAttribSet(secAttrib, SLNETSOCK_SEC_ATTRIB_LOCAL_CERT, ROOT_CA_CERT_FILE, sizeof(ROOT_CA_CERT_FILE)); 1793 SlNetSock_secAttribSet(secAttrib, SLNETSOCK_SEC_ATTRIB_LOCAL_CERT, TRUSTED_CERT_FILE, sizeof(TRUSTED_CERT_FILE)); 1794 \endcode 1795 <br> 1796 1797 - SLNETSOCK_SEC_ATTRIB_PEER_ROOT_CA: 1798 \code 1799 #define ROOT_CA_CERT_FILE "DummyCA" 1800 SlNetIf_loadSecObj(SLNETIF_SEC_OBJ_TYPE_CERTIFICATE, ROOT_CA_CERT_FILE, strlen(ROOT_CA_CERT_FILE), srvCAPem, srvCAPemLen, SLNETIF_ID_2); 1801 SlNetSock_secAttribSet(secAttrib, SLNETSOCK_SEC_ATTRIB_PEER_ROOT_CA, ROOT_CA_CERT_FILE, sizeof(ROOT_CA_CERT_FILE)); 1802 \endcode 1803 <br> 1804 1805 - SLNETSOCK_SEC_ATTRIB_METHOD: 1806 \code 1807 uint8_t SecurityMethod = SLNETSOCK_SEC_METHOD_SSLV3; 1808 SlNetSock_secAttribSet(secAttrib, SLNETSOCK_SEC_ATTRIB_METHOD, (void *)&(SecurityMethod), sizeof(SecurityMethod)); 1809 \endcode 1810 <br> 1811 1812 - SLNETSOCK_SEC_ATTRIB_CIPHERS: 1813 \code 1814 uint32_t SecurityCipher = SLNETSOCK_SEC_CIPHER_SSL_RSA_WITH_RC4_128_SHA | SLNETSOCK_SEC_CIPHER_TLS_RSA_WITH_AES_256_CBC_SHA; 1815 SlNetSock_secAttribSet(secAttrib, SLNETSOCK_SEC_ATTRIB_METHOD, (void *)&(SecurityCipher), sizeof(SecurityCipher)); 1816 \endcode 1817 <br> 1818 1819 - SLNETSOCK_SEC_ATTRIB_DOMAIN_NAME: 1820 \code 1821 char addr[] = "www.ti.com"; 1822 SlNetSock_secAttribSet(secAttrib, SLNETSOCK_SEC_ATTRIB_DOMAIN_NAME, (void *)addr, strlen(addr) + 1); 1823 \endcode 1824 <br> 1825 1826 1827 \sa SlNetSock_secAttribCreate() 1828 */ 1829 int32_t SlNetSock_secAttribSet(SlNetSockSecAttrib_t *secAttrib, SlNetSockSecAttrib_e attribName, void *val, uint16_t len); 1830 1831 1832 /*! 1833 \brief Start a security session on an opened socket 1834 1835 \param[in] sd Socket descriptor (handle) 1836 \param[in] secAttrib Secure attribute handle. This can be NULL only 1837 if the SLNETSOCK_SEC_BIND_CONTEXT_ONLY flag is 1838 not thrown. 1839 \param[in] flags Specifies flags. \n 1840 The available flags are: 1841 - #SLNETSOCK_SEC_START_SECURITY_SESSION_ONLY 1842 - #SLNETSOCK_SEC_BIND_CONTEXT_ONLY 1843 - #SLNETSOCK_SEC_IS_SERVER 1844 1845 \return Zero on success, or negative error code 1846 on failure 1847 1848 \slnetsock_init_precondition 1849 1850 \remark If the return value indicates failure, the socket should be 1851 closed. 1852 1853 \remark If \c secAttrib is \c NULL, the session will be started with 1854 default security settings. 1855 1856 \sa SlNetSock_create() 1857 \sa SlNetSock_secAttribCreate() 1858 */ 1859 int32_t SlNetSock_startSec(int16_t sd, SlNetSockSecAttrib_t *secAttrib, uint8_t flags); 1860 1861 1862 /*! 1863 1864 Close the Doxygen group. 1865 @} 1866 1867 */ 1868 1869 1870 #ifdef __cplusplus 1871 } 1872 #endif /* __cplusplus */ 1873 1874 #endif /* __NET_SOCK_H__ */ 1875