1 /* 2 * Copyright (c) 2017, 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 /* Include files */ 36 /*****************************************************************************/ 37 #include <ti/drivers/net/wifi/simplelink.h> 38 #include <ti/net/slnetsock.h> 39 #include <ti/net/slnetif.h> 40 #include <ti/net/slneterr.h> 41 #include <ti/net/slnetutils.h> 42 43 #ifndef __SLNETWIFI_SOCKET_H__ 44 #define __SLNETWIFI_SOCKET_H__ 45 46 47 #ifdef __cplusplus 48 extern "C" { 49 #endif 50 51 /*! 52 \defgroup WiFi Socket Stack 53 \short Controls standard client/server sockets programming options and capabilities 54 55 */ 56 /*! 57 58 \addtogroup Socket 59 @{ 60 61 */ 62 63 /*****************************************************************************/ 64 /* Macro declarations */ 65 /*****************************************************************************/ 66 67 /* prototype ifConf */ 68 extern SlNetIf_Config_t SlNetIfConfigWifi; 69 70 71 /*****************************************************************************/ 72 /* Structure/Enum declarations */ 73 /*****************************************************************************/ 74 75 76 /*****************************************************************************/ 77 /* Function prototypes */ 78 /*****************************************************************************/ 79 80 /*! 81 82 \brief Create an endpoint for communication 83 84 The SlNetIfWifi_socket function creates a new socket of a certain socket 85 type, identified by an integer number, and allocates system resources to 86 it.\n 87 This function is called by the application layer to obtain a socket descriptor (handle). 88 89 \param[in] ifContext Stores interface data if CreateContext function 90 supported and implemented. 91 \param[in] domain Specifies the protocol family of the created socket. 92 For example: 93 - SLNETSOCK_AF_INET for network protocol IPv4 94 - SLNETSOCK_AF_INET6 for network protocol IPv6 95 - SLNETSOCK_AF_RF for starting transceiver mode. 96 Notes: 97 - sending and receiving any packet overriding 802.11 header 98 - for optimized power consumption the socket will be started in TX 99 only mode until receive command is activated 100 \param[in] type Specifies the socket type, which determines the semantics of communication over 101 the socket. The socket types supported by the system are implementation-dependent. 102 Possible socket types include: 103 - SLNETSOCK_SOCK_STREAM (reliable stream-oriented service or Stream Sockets) 104 - SLNETSOCK_SOCK_DGRAM (datagram service or Datagram Sockets) 105 - SLNETSOCK_SOCK_RAW (raw protocols atop the network layer) 106 - when used with AF_RF: 107 - SLNETSOCK_SOCK_RX_MTR 108 - SLNETSOCK_SOCK_MAC_WITH_CCA 109 - SLNETSOCK_SOCK_MAC_WITH_NO_CCA 110 - SLNETSOCK_SOCK_BRIDGE 111 - SLNETSOCK_SOCK_ROUTER 112 \param[in] protocol Specifies a particular transport to be used with the socket.\n 113 The most common are 114 - SLNETSOCK_PROTO_TCP 115 - SLNETSOCK_PROTO_UDP 116 - SLNETSOCK_PROTO_RAW 117 - SLNETSOCK_PROTO_SECURE 118 The value 0 may be used to select a default 119 protocol from the selected domain and type 120 \param[in] sdContext Allocate and store socket data if needed for 121 using in other slnetwifi socket functions 122 123 \return On success, socket descriptor (handle) that is used for consequent socket operations. \n 124 A successful return code should be a positive number (int16)\n 125 On error, a negative value will be returned specifying the error code. 126 - SLNETERR_BSD_EAFNOSUPPORT - illegal domain parameter 127 - SLNETERR_BSD_EPROTOTYPE - illegal type parameter 128 - SLNETERR_BSD_EACCES - permission denied 129 - SLNETERR_BSD_ENSOCK - exceeded maximal number of socket 130 - SLNETERR_BSD_ENOMEM - memory allocation error 131 - SLNETERR_BSD_EINVAL - error in socket configuration 132 - SLNETERR_BSD_EPROTONOSUPPORT - illegal protocol parameter 133 - SLNETERR_BSD_EOPNOTSUPP - illegal combination of protocol and type parameters 134 135 \sa SlNetIfWifi_socket 136 \note 137 \warning 138 */ 139 int16_t SlNetIfWifi_socket(void *ifContext, int16_t Domain, int16_t Type, int16_t Protocol, void **sdContext); 140 141 /*! 142 \brief Gracefully close socket 143 144 The SlNetIfWifi_close function causes the system to release resources allocated to a socket. \n 145 In case of TCP, the connection is terminated. 146 147 \param[in] sd Socket descriptor (handle), received in SlNetIfWifi_socket 148 \param[in] sdContext May store socket data if implemented in the 149 SlNetIfWifi_socket function. 150 151 \return Zero on success, or negative error code on failure 152 153 \sa SlNetIfWifi_socket 154 \note 155 \warning 156 */ 157 int32_t SlNetIfWifi_close(int16_t sd, void *sdContext); 158 159 /*! 160 \brief Accept a connection on a socket 161 162 The SlNetIfWifi_accept function is used with connection-based socket types (SOCK_STREAM).\n 163 It extracts the first connection request on the queue of pending 164 connections, creates a new connected socket, and returns a new file 165 descriptor referring to that socket.\n 166 The newly created socket is not in the listening state. The 167 original socket sd is unaffected by this call. \n 168 The argument sd is a socket that has been created with 169 SlNetIfWifi_socket(), bound to a local address with SlNetIfWifi_bind(), and is 170 listening for connections after a SlNetIfWifi_listen(). \n The argument 171 \e <b>addr</b> is a pointer to a sockaddr structure. This structure 172 is filled in with the address of the peer socket, as known to 173 the communications layer. \n The exact format of the address 174 returned addr is determined by the socket's address family. \n 175 The \b \e addrlen argument is a value-result argument: it 176 should initially contain the size of the structure pointed to 177 by addr, on return it will contain the actual length (in 178 bytes) of the address returned. 179 180 \param[in] sd Socket descriptor (handle) 181 \param[in] sdContext May store socket data if implemented in the 182 SlNetIfWifi_socket function. 183 \param[out] addr The argument addr is a pointer 184 to a sockaddr structure. This 185 structure is filled in with the 186 address of the peer socket, as 187 known to the communications 188 layer. The exact format of the 189 address returned addr is 190 determined by the socket's 191 address\n 192 sockaddr:\n - code for the 193 address format.\n - 194 socket address, the length 195 depends on the code format 196 \param[out] addrlen The addrlen argument is a value-result 197 argument: it should initially contain the 198 size of the structure pointed to by addr 199 \param[in] flags Specifies socket descriptor flags. \n 200 The available flags are: 201 - SLNETSOCK_SEC_START_SECURITY_SESSION_ONLY 202 - SLNETSOCK_SEC_BIND_CONTEXT_ONLY 203 Note: This flags can be used in order to start 204 security session if needed 205 \param[in] acceptedSdContext Allocate and store data for the new socket 206 if needed in other to use it in other 207 slnetwifi socket functions 208 209 \return On success, a socket descriptor.\n 210 On a non-blocking accept a possible negative value is SLNETERR_BSD_EAGAIN.\n 211 On failure, negative error code.\n 212 SLNETERR_BSD_ENOMEM may be return in case there are no resources in the system 213 In this case try again later or increase MAX_CONCURRENT_ACTIONS 214 215 \sa SlNetIfWifi_Socket SlNetIfWifi_Bind SlNetIfWifi_Listen 216 \note 217 \warning 218 */ 219 int16_t SlNetIfWifi_accept(int16_t sd, void *sdContext, SlNetSock_Addr_t *addr, SlNetSocklen_t *addrlen, uint8_t flags, void **acceptedSdContext); 220 221 /*! 222 \brief Assign a name to a socket 223 224 This SlNetIfWifi_bind function gives the socket the local address addr. 225 addr is addrlen bytes long. \n Traditionally, this is called 226 When a socket is created with socket, it exists in a name 227 space (address family) but has no name assigned. \n 228 It is necessary to assign a local address before a SOCK_STREAM 229 socket may receive connections. 230 231 \param[in] sd Socket descriptor (handle) 232 \param[in] sdContext May store socket data if implemented in the 233 SlNetIfWifi_socket function. 234 \param[in] addr Specifies the destination 235 addrs\n sockaddr:\n - code for 236 the address format.\n - socket address, 237 the length depends on the code 238 format 239 \param[in] addrlen Contains the size of the structure pointed to by addr 240 241 \return Zero on success, or negative error code on failure 242 243 \sa SlNetIfWifi_Socket SlNetIfWifi_accept SlNetIfWifi_Listen 244 \note 245 \warning 246 */ 247 int32_t SlNetIfWifi_bind(int16_t sd, void *sdContext, const SlNetSock_Addr_t *addr, int16_t addrlen); 248 249 /*! 250 \brief Listen for connections on a socket 251 252 The willingness to accept incoming connections and a queue 253 limit for incoming connections are specified with SlNetIfWifi_listen(), 254 and then the connections are accepted with SlNetIfWifi_accept(). \n 255 The SlNetIfWifi_listen() call applies only to sockets of type SOCK_STREAM 256 The backlog parameter defines the maximum length the queue of 257 pending connections may grow to. 258 259 \param[in] sd Socket descriptor (handle) 260 \param[in] sdContext May store socket data if implemented in the 261 SlNetIfWifi_socket function. 262 \param[in] backlog Specifies the listen queue depth. 263 264 \return Zero on success, or negative error code on failure 265 266 \sa SlNetIfWifi_Socket SlNetIfWifi_accept SlNetIfWifi_bind 267 \note 268 \warning 269 */ 270 int32_t SlNetIfWifi_listen(int16_t sd, void *sdContext, int16_t backlog); 271 272 /*! 273 \brief Initiate a connection on a socket 274 275 Function connects the socket referred to by the socket 276 descriptor sd, to the address specified by addr. \n The addrlen 277 argument specifies the size of addr. \n The format of the 278 address in addr is determined by the address space of the 279 socket. \n If it is of type SLNETSOCK_SOCK_DGRAM, this call 280 specifies the peer with which the socket is to be associated; 281 this address is that to which datagrams are to be sent, and 282 the only address from which datagrams are to be received. \n If 283 the socket is of type SLNETSOCK_SOCK_STREAM, this call 284 attempts to make a connection to another socket. \n The other 285 socket is specified by address, which is an address in the 286 communications space of the socket. 287 288 \param[in] sd Socket descriptor (handle) 289 \param[in] sdContext May store socket data if implemented in the 290 SlNetIfWifi_socket function. 291 \param[in] addr Specifies the destination addr\n 292 sockaddr:\n - code for the 293 address format.\n - 294 socket address, the length 295 depends on the code format 296 \param[in] addrlen Contains the size of the structure pointed 297 to by addr 298 \param[in] flags Specifies socket descriptor flags. \n 299 The available flags are: 300 - SLNETSOCK_SEC_START_SECURITY_SESSION_ONLY 301 - SLNETSOCK_SEC_BIND_CONTEXT_ONLY 302 Note: This flags can be used in order to start 303 security session if needed 304 305 \return On success, a socket descriptor (handle).\n 306 On a non-blocking connect a possible negative value is NETSCOK_EALREADY. 307 On failure, negative value.\n 308 NETSCOK_POOL_IS_EMPTY may be return in case there are no resources in the system 309 In this case try again later or increase MAX_CONCURRENT_ACTIONS 310 311 \sa SlNetIfWifi_socket 312 \note 313 \warning 314 */ 315 int32_t SlNetIfWifi_connect(int16_t sd, void *sdContext, const SlNetSock_Addr_t *addr, SlNetSocklen_t addrlen, uint8_t flags); 316 317 /*! 318 \brief Get local address info by socket descriptor\n 319 Returns the local address info of the socket descriptor. 320 321 \param[in] sd Socket descriptor (handle) 322 \param[in] sdContext May store socket data if implemented in the 323 SlNetIfWifi_socket function. 324 \param[out] addr The argument addr is a pointer 325 to a SlNetSock_Addr_t structure. This 326 structure is filled in with the 327 address of the peer socket, as 328 known to the communications 329 layer. The exact format of the 330 address returned addr is 331 determined by the socket's 332 address\n 333 SlNetSock_Addr_t:\n - code for the 334 address format.\n - 335 socket address, the length 336 depends on the code format 337 \param[out] addrlen The addrlen argument is a value-result 338 argument: it should initially contain the 339 size of the structure pointed to by addr 340 341 \return Zero on success, or negative on failure.\n 342 343 344 \sa SlNetSock_create SlNetSock_bind 345 \note If the provided buffer is too small the returned address will be 346 truncated and the addrlen will contain the actual size of the 347 socket address 348 \warning 349 */ 350 int32_t SlNetIfWifi_getSockName(int16_t sd, void *sdContext, SlNetSock_Addr_t *addr, SlNetSocklen_t *addrlen); 351 352 /*! 353 \brief Monitor socket activity 354 355 SlNetIfWifi_send allow a program to monitor multiple file descriptors, 356 waiting until one or more of the file descriptors become 357 "ready" for some class of I/O operation. 358 If trigger mode is enabled the active sdset is the one that retrieved in the first triggered call. 359 To enable the trigger mode, an handler must be statically registered to the slcb_SocketTriggerEventHandler (user.h) 360 361 \param[in] ifContext Stores interface data if CreateContext function 362 supported and implemented. 363 Can be used in all SlNetIf_Config_t functions 364 \param[in] nsds The highest-numbered file descriptor in any of the 365 three sets, plus 1. 366 \param[in,out] readsds Socket descriptors list for read monitoring and accept monitoring 367 \param[in,out] writesds Socket descriptors list for connect monitoring only, write monitoring is not supported 368 \param[in,out] exceptsds Socket descriptors list for exception monitoring, not supported. 369 \param[in] timeout Is an upper bound on the amount of time elapsed 370 before SlNetIfWifi_send() returns. Null or above 0xffff seconds means 371 infinity timeout. The minimum timeout is 10 milliseconds, 372 less than 10 milliseconds will be set automatically to 10 milliseconds. 373 Max microseconds supported is 0xfffc00. 374 In trigger mode the timeout fields must be set to zero. 375 376 \return On success, SlNetIfWifi_send() returns the number of 377 file descriptors contained in the three returned 378 descriptor sets (that is, the total number of bits that 379 are set in readsds, writesds, exceptsds) which may be 380 zero if the timeout expires before anything interesting 381 happens.\n On error, a negative value is returned. 382 readsds - return the sockets on which Read request will 383 return without delay with valid data.\n 384 writesds - return the sockets on which Write request 385 will return without delay.\n 386 exceptsds - return the sockets closed recently. \n 387 SLNETERR_BSD_ENOMEM may be return in case there are no resources in the system 388 In this case try again later or increase MAX_CONCURRENT_ACTIONS 389 390 \sa SlNetIfWifi_socket 391 \note If the timeout value set to less than 10ms it will automatically set 392 to 10ms to prevent overload of the system\n 393 394 Only one SlNetIfWifi_send can be handled at a time. \b 395 Calling this API while the same command is called from another thread, may result 396 in one of the following scenarios: 397 1. The command will wait (internal) until the previous command finish, and then be executed. 398 2. There are not enough resources and SLNETERR_BSD_ENOMEM error will return. 399 In this case, MAX_CONCURRENT_ACTIONS can be increased (result in memory increase) or try 400 again later to issue the command. 401 3. In case there is already a triggered SlNetIfWifi_send in progress, the following call will return 402 with SLNETSOCK_RET_CODE_SOCKET_SELECT_IN_PROGRESS_ERROR. 403 404 \warning 405 */ 406 int32_t SlNetIfWifi_select(void *ifContext, int16_t nfds, SlNetSock_SdSet_t *readsds, SlNetSock_SdSet_t *writesds, SlNetSock_SdSet_t *exceptsds, SlNetSock_Timeval_t *timeout); 407 408 409 /*! 410 \brief Set socket options- 411 412 The SlNetIfWifi_setSockOpt function manipulate the options associated with a socket.\n 413 Options may exist at multiple protocol levels; they are always 414 present at the uppermost socket level.\n 415 416 When manipulating socket options the level at which the option resides 417 and the name of the option must be specified. To manipulate options at 418 the socket level, level is specified as SOL_SOCKET. To manipulate 419 options at any other level the protocol number of the appropriate protocol 420 controlling the option is supplied. For example, to indicate that an 421 option is to be interpreted by the TCP protocol, level should be set to 422 the protocol number of TCP; \n 423 424 The parameters optval and optlen are used to access opt_values 425 for SlNetIfWifi_setSockOpt(). For SlNetIfWifi_getSockOpt() they identify a 426 buffer in which the value for the requested option(s) are to 427 be returned. For SlNetIfWifi_getSockOpt(), optlen is a value-result 428 parameter, initially containing the size of the buffer 429 pointed to by option_value, and modified on return to 430 indicate the actual size of the value returned. If no option 431 value is to be supplied or returned, option_value may be 432 NULL. 433 434 \param[in] sd Socket descriptor (handle) 435 \param[in] sdContext May store socket data if implemented in the 436 SlNetIfWifi_socket function. 437 \param[in] level Defines the protocol level for this option 438 - <b>SLNETSOCK_LVL_SOCKET</b> Socket level configurations (L4, transport layer) 439 - <b>SLNETSOCK_LVL_IP</b> IP level configurations (L3, network layer) 440 - <b>SLNETSOCK_LVL_PHY</b> Link level configurations (L2, link layer) 441 \param[in] optname Defines the option name to interrogate 442 - <b>SLNETSOCK_LVL_SOCKET</b> 443 - <b>SLNETSOCK_OPSOCK_RCV_BUF</b> \n 444 Sets tcp max recv window size. \n 445 This options takes SlNetSock_Winsize_t struct as parameter 446 - <b>SLNETSOCK_OPSOCK_RCV_TIMEO</b> \n 447 Sets the timeout value that specifies the maximum amount of time an input function waits until it completes. \n 448 Default: No timeout \n 449 This options takes SlNetSock_Timeval_t struct as parameter 450 - <b>SLNETSOCK_OPSOCK_KEEPALIVE</b> \n 451 Enable or Disable periodic keep alive. 452 Keeps TCP connections active by enabling the periodic transmission of messages \n 453 Timeout is 5 minutes.\n 454 Default: Enabled \n 455 This options takes SlNetSock_Keepalive_t struct as parameter 456 - <b>SLNETSOCK_OPSOCK_KEEPALIVE_TIME</b> \n 457 Set keep alive timeout. 458 Value is in seconds \n 459 Default: 5 minutes \n 460 - <b>SLNETSOCK_OPSOCK_LINGER</b> \n 461 Socket lingers on close pending remaining send/receive packets\n 462 - <b>SLNETSOCK_OPSOCK_NON_BLOCKING</b> \n 463 Sets socket to non-blocking operation Impacts: connect, accept, send, sendto, recv and recvfrom. \n 464 Default: Blocking. 465 This options takes SlNetSock_Nonblocking_t struct as parameter 466 - <b>SLNETSOCK_OPSOCK_NON_IP_BOUNDARY</b> \n 467 Enable or Disable rx ip boundary. 468 In connectionless socket (udp/raw), unread data is dropped (when SlNetIfWifi_recvfrom len parameter < data size), Enable this option in order to read the left data on the next SlNetIfWifi_recvfrom iteration 469 Default: Disabled, IP boundary kept, \n 470 This options takes SlNetSock_NonIpBoundary_t struct as parameter 471 - <b>SLNETSOCK_LVL_IP</b> 472 - <b>SLNETSOCK_OPIP_MULTICAST_TTL</b> \n 473 Set the time-to-live value of outgoing multicast packets for this socket. \n 474 This options takes <b>uint8_t</b> as parameter 475 - <b>SLNETSOCK_OPIP_ADD_MEMBERSHIP</b> \n 476 UDP socket, Join a multicast group. \n 477 This options takes SlNetSock_IpMreq_t struct as parameter 478 - <b>SLNETSOCK_OPIP_DROP_MEMBERSHIP</b> \n 479 UDP socket, Leave a multicast group \n 480 This options takes SlNetSock_IpMreq_t struct as parameter 481 - <b>SLNETSOCK_OPIP_HDRINCL</b> \n 482 RAW socket only, the IPv4 layer generates an IP header when sending a packet unless \n 483 the IP_HDRINCL socket option is enabled on the socket. \n 484 When it is enabled, the packet must contain an IP header. \n 485 Default: disabled, IPv4 header generated by Network Stack \n 486 This options takes <b>uint32_t</b> as parameter 487 - <b>SLNETSOCK_OPIP_RAW_RX_NO_HEADER</b> \n 488 Raw socket remove IP header from received data. \n 489 Default: data includes ip header \n 490 This options takes <b>uint32_t</b> as parameter 491 - <b>SLNETSOCK_OPIP_RAW_IPV6_HDRINCL</b> (inactive) \n 492 RAW socket only, the IPv6 layer generates an IP header when sending a packet unless \n 493 the IP_HDRINCL socket option is enabled on the socket. When it is enabled, the packet must contain an IP header \n 494 Default: disabled, IPv4 header generated by Network Stack \n 495 This options takes <b>uint32_t</b> as parameter 496 - <b>SLNETSOCK_LVL_PHY</b> 497 - <b>SLNETSOCK_OPPHY_CHANNEL</b> \n 498 Sets channel in transceiver mode. 499 This options takes <b>uint32_t</b> as channel number parameter 500 - <b>SLNETSOCK_OPPHY_RATE</b> \n 501 RAW socket, set WLAN PHY transmit rate \n 502 The values are based on SlWlanRateIndex_e \n 503 This options takes <b>uint32_t</b> as parameter 504 - <b>SLNETSOCK_OPPHY_TX_POWER</b> \n 505 RAW socket, set WLAN PHY TX power \n 506 Valid rage is 1-15 \n 507 This options takes <b>uint32_t</b> as parameter 508 - <b>SLNETSOCK_OPPHY_NUM_FRAMES_TO_TX</b> \n 509 RAW socket, set number of frames to transmit in transceiver mode. 510 Default: 1 packet 511 This options takes <b>uint32_t</b> as parameter 512 - <b>SLNETSOCK_OPPHY_PREAMBLE</b> \n 513 RAW socket, set WLAN PHY preamble for Long/Short\n 514 This options takes <b>uint32_t</b> as parameter 515 - <b>SLNETSOCK_OPPHY_TX_INHIBIT_THRESHOLD</b> \n 516 RAW socket, set WLAN Tx - Set CCA threshold. \n 517 The values are based on SlNetSockTxInhibitThreshold_e \n 518 This options takes <b>uint32_t</b> as parameter 519 - <b>SLNETSOCK_OPPHY_TX_TIMEOUT</b> \n 520 RAW socket, set WLAN Tx - changes the TX timeout (lifetime) of transceiver frames. \n 521 Value in Ms, maximum value is 10ms \n 522 This options takes <b>uint32_t</b> as parameter 523 - <b>SLNETSOCK_OPPHY_ALLOW_ACKS </b> \n 524 RAW socket, set WLAN Tx - Enable or Disable sending ACKs in transceiver mode \n 525 0 = disabled / 1 = enabled \n 526 This options takes <b>uint32_t</b> as parameter 527 528 529 \param[in] optval Specifies a value for the option 530 \param[in] optlen Specifies the length of the 531 option value 532 533 \return Zero on success, or negative error code on failure 534 535 \par Persistent 536 All params are <b>Non- Persistent</b> 537 \sa SlNetIfWifi_getSockOpt 538 \note 539 \warning 540 \par Examples 541 542 - SLNETSOCK_OPSOCK_RCV_BUF: 543 \code 544 SlNetSock_Winsize_t size; 545 size.winsize = 3000; // bytes 546 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_RCV_BUF, (uint8_t *)&size, sizeof(size)); 547 \endcode 548 <br> 549 550 - SLNETSOCK_OPSOCK_RCV_TIMEO: 551 \code 552 struct SlNetSock_Timeval_t timeVal; 553 timeVal.tv_sec = 1; // Seconds 554 timeVal.tv_usec = 0; // Microseconds. 10000 microseconds resolution 555 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_RCV_TIMEO, (uint8_t *)&timeVal, sizeof(timeVal)); // Enable receive timeout 556 \endcode 557 <br> 558 559 - SLNETSOCK_OPSOCK_KEEPALIVE: //disable Keepalive 560 \code 561 SlNetSock_Keepalive_t enableOption; 562 enableOption.keepaliveEnabled = 0; 563 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_KEEPALIVE, (uint8_t *)&enableOption, sizeof(enableOption)); 564 \endcode 565 <br> 566 567 - SLNETSOCK_OPSOCK_KEEPALIVE_TIME: //Set Keepalive timeout 568 \code 569 int16_t Status; 570 uint32_t TimeOut = 120; 571 SlNetIfWifi_setSockOpt(Sd, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_KEEPALIVE_TIME, (uint8_t *)&TimeOut, sizeof(TimeOut)); 572 \endcode 573 <br> 574 575 - SLNETSOCK_OPSOCK_NON_BLOCKING: //Enable or disable nonblocking mode 576 \code 577 SlNetSock_Nonblocking_t enableOption; 578 enableOption.nonBlockingEnabled = 1; 579 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_NON_BLOCKING, (uint8_t *)&enableOption, sizeof(enableOption)); 580 \endcode 581 <br> 582 583 - SLNETSOCK_OPSOCK_NON_IP_BOUNDARY: //disable boundary 584 \code 585 SlNetSock_NonIpBoundary_t enableOption; 586 enableOption.nonIpBoundaryEnabled = 1; 587 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_NON_IP_BOUNDARY, (uint8_t *)&enableOption, sizeof(enableOption)); 588 \endcode 589 <br> 590 591 - SLNETSOCK_OPSOCK_LINGER: 592 \code 593 SlNetSock_linger_t linger; 594 linger.l_onoff = 1; 595 linger.l_linger = 10; 596 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPSOCK_LINGER, &linger, sizeof(linger)); 597 \endcode 598 <br> 599 600 - SLNETSOCK_OPIP_MULTICAST_TTL: 601 \code 602 uint8_t ttl = 20; 603 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_MULTICAST_TTL, &ttl, sizeof(ttl)); 604 \endcode 605 <br> 606 607 - SLNETSOCK_OPIP_ADD_MEMBERSHIP: 608 \code 609 SlNetSock_IpMreq_t mreq; 610 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); 611 \endcode 612 <br> 613 614 - SLNETSOCK_OPIP_DROP_MEMBERSHIP: 615 \code 616 SlNetSock_IpMreq_t mreq; 617 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_DROP_MEMBERSHIP, &mreq, sizeof(mreq)); 618 \endcode 619 <br> 620 621 - SLNETSOCK_OPIP_RAW_RX_NO_HEADER: 622 \code 623 uint32_t header = 1; // remove ip header 624 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_RAW_RX_NO_HEADER, &header, sizeof(header)); 625 \endcode 626 <br> 627 628 - SLNETSOCK_OPIP_HDRINCL: 629 \code 630 uint32_t header = 1; 631 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_HDRINCL, &header, sizeof(header)); 632 \endcode 633 <br> 634 635 - SLNETSOCK_OPIP_RAW_IPV6_HDRINCL: 636 \code 637 uint32_t header = 1; 638 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_IP, SLNETSOCK_OPIP_RAW_IPV6_HDRINCL, &header, sizeof(header)); 639 \endcode 640 <br> 641 642 - SLNETSOCK_OPPHY_CHANNEL: 643 \code 644 uint32_t newChannel = 6; // range is 1-13 645 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_SOCKET, SLNETSOCK_OPPHY_CHANNEL, &newChannel, sizeof(newChannel)); 646 \endcode 647 <br> 648 649 - SLNETSOCK_OPPHY_RATE: 650 \code 651 uint32_t rate = 6; // see wlan.h SlWlanRateIndex_e for values 652 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_RATE, &rate, sizeof(rate)); 653 \endcode 654 <br> 655 656 - SLNETSOCK_OPPHY_TX_POWER: 657 \code 658 uint32_t txpower = 1; // valid range is 1-15 659 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_TX_POWER, &txpower, sizeof(txpower)); 660 \endcode 661 <br> 662 663 - SLNETSOCK_OPPHY_NUM_FRAMES_TO_TX: 664 \code 665 uint32_t numframes = 1; 666 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_NUM_FRAMES_TO_TX, &numframes, sizeof(numframes)); 667 \endcode 668 <br> 669 670 - SLNETSOCK_OPPHY_PREAMBLE: 671 \code 672 uint32_t preamble = 1; 673 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_PREAMBLE, &preamble, sizeof(preamble)); 674 \endcode 675 <br> 676 677 - SLNETSOCK_OPPHY_TX_INHIBIT_THRESHOLD: 678 \code 679 uint32_t thrshld = SLNETSOCK_TX_INHIBIT_THRESHOLD_MED; 680 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_TX_INHIBIT_THRESHOLD , &thrshld, sizeof(thrshld)); 681 \endcode 682 <br> 683 684 - SLNETSOCK_OPPHY_TX_TIMEOUT: 685 \code 686 uint32_t timeout = 50; 687 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_TX_TIMEOUT , &timeout, sizeof(timeout)); 688 \endcode 689 <br> 690 691 - SLNETSOCK_OPPHY_ALLOW_ACKS: 692 \code 693 uint32_t acks = 1; // 0 = disabled / 1 = enabled 694 SlNetIfWifi_setSockOpt(SockID, sdContext, SLNETSOCK_LVL_PHY, SLNETSOCK_OPPHY_ALLOW_ACKS, &acks, sizeof(acks)); 695 \endcode 696 <br> 697 698 */ 699 int32_t SlNetIfWifi_setSockOpt(int16_t sd, void *sdContext, int16_t level, int16_t optname, void *optval, SlNetSocklen_t optlen); 700 701 /*! 702 \brief Get socket options 703 704 The SlNetIfWifi_getSockOpt function gets the options associated with a socket. 705 Options may exist at multiple protocol levels; they are always 706 present at the uppermost socket level.\n 707 708 The parameters optval and optlen identify a 709 buffer in which the value for the requested option(s) are to 710 be returned. optlen is a value-result 711 parameter, initially containing the size of the buffer 712 pointed to by option_value, and modified on return to 713 indicate the actual size of the value returned. If no option 714 value is to be supplied or returned, option_value may be 715 NULL. 716 717 \param[in] sd Socket descriptor (handle) 718 \param[in] sdContext May store socket data if implemented in the 719 SlNetIfWifi_socket function. 720 \param[in] level Defines the protocol level for this option 721 \param[in] optname defines the option name to interrogate 722 \param[out] optval Specifies a value for the option 723 \param[out] optlen Specifies the length of the 724 option value 725 726 \return Zero on success, or negative error code on failure 727 \sa SlNetIfWifi_setSockOpt 728 \note 729 \warning 730 */ 731 int32_t SlNetIfWifi_getSockOpt(int16_t sd, void *sdContext, int16_t level, int16_t optname, void *optval, SlNetSocklen_t *optlen); 732 733 /*! 734 \brief Read data from TCP socket 735 736 The SlNetIfWifi_recv function receives a message from a connection-mode socket 737 738 \param[in] sd Socket descriptor (handle) 739 \param[in] sdContext May store socket data if implemented in the 740 SlNetIfWifi_socket function. 741 \param[out] buf Points to the buffer where the 742 message should be stored. 743 \param[in] len Specifies the length in bytes of 744 the buffer pointed to by the buffer argument. 745 Range: 1-16000 bytes 746 \param[in] flags Upper 8 bits specifies the security flags 747 Lower 24 bits specifies the type of message 748 reception. On this version, the lower 24 bits are not 749 supported 750 751 \return Return the number of bytes received, 752 or a negative value if an error occurred.\n 753 Using a non-blocking recv a possible negative value is SLNETERR_BSD_EAGAIN.\n 754 SLNETERR_BSD_ENOMEM may be return in case there are no resources in the system 755 In this case try again later or increase MAX_CONCURRENT_ACTIONS 756 757 \sa SlNetIfWifi_recvFrom 758 \note 759 \warning 760 \par Examples 761 762 - Receiving data using TCP socket: 763 \code 764 SlNetSock_AddrIn_t Addr; 765 SlNetSock_AddrIn_t LocalAddr; 766 int16_t AddrSize = sizeof(SlNetSock_AddrIn_t); 767 int16_t SockID, newSockID; 768 int16_t Status; 769 int8_t Buf[RECV_BUF_LEN]; 770 771 LocalAddr.sin_family = SLNETSOCK_AF_INET; 772 LocalAddr.sin_port = SlNetSock_htons(5001); 773 LocalAddr.sin_addr.s_addr = 0; 774 775 Addr.sin_family = SLNETSOCK_AF_INET; 776 Addr.sin_port = SlNetSock_htons(5001); 777 Addr.sin_addr.s_addr = SlNetSock_htonl(SLNETSOCK_IPV4_VAL(10,1,1,200)); 778 779 SockID = SlNetIfWifi_socket(SLNETSOCK_AF_INET, SLNETSOCK_SOCK_STREAM, 0, 0, 0); 780 Status = SlNetIfWifi_bind(SockID, (SlNetSock_Addr_t *)&LocalAddr, AddrSize); 781 Status = SlNetIfWifi_listen(SockID, 0); 782 newSockID = SlNetIfWifi_accept(SockID, (SlNetSock_Addr_t*)&Addr, (SlNetSocklen_t*) &AddrSize); 783 Status = SlNetIfWifi_recv(newSockID, Buf, 1460, 0); 784 \endcode 785 <br> 786 787 - Rx transceiver mode using a raw socket: 788 \code 789 int8_t buffer[1536]; 790 int16_t sd; 791 uint16_t size; 792 SlNetSock_TransceiverRxOverHead_t *transHeader; 793 sd = SlNetIfWifi_socket(SLNETSOCK_AF_RF, SLNETSOCK_SOCK_RAW, 11, 0, 0); // channel 11 794 while(1) 795 { 796 size = SlNetIfWifi_recv(sd,buffer,1536,0); 797 transHeader = (SlNetSock_TransceiverRxOverHead_t *)buffer; 798 printf("RSSI is %d frame type is 0x%x size %d\n",transHeader->rssi,buffer[sizeof(SlNetSock_TransceiverRxOverHead_t)],size); 799 } 800 \endcode 801 */ 802 int32_t SlNetIfWifi_recv(int16_t sd, void *sdContext, void *buf, uint32_t len, uint32_t flags); 803 804 /*! 805 \brief Read data from socket 806 807 SlNetIfWifi_recvFrom function receives a message from a connection-mode or 808 connectionless-mode socket 809 810 \param[in] sd Socket descriptor (handle) 811 \param[in] sdContext May store socket data if implemented in the 812 SlNetIfWifi_socket function. 813 \param[out] buf Points to the buffer where the message should be stored. 814 \param[in] len Specifies the length in bytes of the buffer pointed to by the buffer argument. 815 Range: 1-16000 bytes 816 \param[in] flags Upper 8 bits specifies the security flags 817 Lower 24 bits specifies the type of message 818 reception. On this version, the lower 24 bits are not 819 supported 820 \param[in] from Pointer to an address structure 821 indicating the source 822 address.\n sockaddr:\n - code 823 for the address format.\n - socket address, 824 the length depends on the code 825 format 826 \param[in] fromlen Source address structure 827 size. This parameter MUST be set to the size of the structure pointed to by addr. 828 829 830 \return Return the number of bytes received, 831 or a negative value if an error occurred.\n 832 Using a non-blocking recv a possible negative value is SLNETERR_BSD_EAGAIN. 833 SLNETSOCK_RET_CODE_INVALID_INPUT (-2) will be returned if fromlen has incorrect length. \n 834 SLNETERR_BSD_ENOMEM may be return in case there are no resources in the system 835 In this case try again later or increase MAX_CONCURRENT_ACTIONS 836 837 \sa SlNetIfWifi_recv 838 \note 839 \warning 840 \par Example 841 842 - Receiving data: 843 \code 844 SlNetSock_AddrIn_t Addr; 845 SlNetSock_AddrIn_t LocalAddr; 846 int16_t AddrSize = sizeof(SlNetSock_AddrIn_t); 847 int16_t SockID; 848 int16_t Status; 849 int8_t Buf[RECV_BUF_LEN]; 850 851 LocalAddr.sin_family = SLNETSOCK_AF_INET; 852 LocalAddr.sin_port = SlNetSock_htons(5001); 853 LocalAddr.sin_addr.s_addr = 0; 854 855 SockID = SlNetIfWifi_socket(SLNETSOCK_AF_INET, SLNETSOCK_SOCK_DGRAM, 0, 0, 0); 856 Status = SlNetIfWifi_bind(SockID, (SlNetSock_Addr_t *)&LocalAddr, AddrSize); 857 Status = SlNetIfWifi_recvFrom(SockID, Buf, 1472, 0, (SlNetSock_Addr_t *)&Addr, (SlNetSocklen_t*)&AddrSize); 858 859 \endcode 860 */ 861 int32_t SlNetIfWifi_recvFrom(int16_t sd, void *sdContext, void *buf, uint32_t len, uint32_t flags, SlNetSock_Addr_t *from, SlNetSocklen_t *fromlen); 862 863 /*! 864 \brief Write data to TCP socket 865 866 The SlNetIfWifi_send function is used to transmit a message to another socket. 867 Returns immediately after sending data to device. 868 In case of TCP failure an async event SLNETSOCK_SOCKET_TX_FAILED_EVENT is going to 869 be received.\n 870 In case of a RAW socket (transceiver mode), extra 4 bytes should be reserved at the end of the 871 frame data buffer for WLAN FCS 872 873 \param[in] sd Socket descriptor (handle) 874 \param[in] sdContext May store socket data if implemented in the 875 SlNetIfWifi_socket function. 876 \param[in] buf Points to a buffer containing 877 the message to be sent 878 \param[in] len Message size in bytes. Range: 1-1460 bytes 879 \param[in] flags Upper 8 bits specifies the security flags 880 Lower 24 bits specifies the type of message 881 reception. On this version, the lower 24 bits are not 882 supported for TCP. 883 For transceiver mode, the SLNETSOCK_WLAN_RAW_RF_TX_PARAMS macro can be used to determine 884 transmission parameters (channel,rate,tx_power,preamble) 885 886 \return Zero on success, or negative error code on failure 887 888 \sa SlNetIfWifi_sendTo 889 \note 890 \warning 891 \par Example 892 893 - Sending data: 894 \code 895 SlNetSock_AddrIn_t Addr; 896 int16_t AddrSize = sizeof(SlNetSock_AddrIn_t); 897 int16_t SockID; 898 int16_t Status; 899 int8_t Buf[SEND_BUF_LEN]; 900 901 Addr.sin_family = SLNETSOCK_AF_INET; 902 Addr.sin_port = SlNetSock_htons(5001); 903 Addr.sin_addr.s_addr = SlNetSock_htonl(SLNETSOCK_IPV4_VAL(10,1,1,200)); 904 905 SockID = SlNetIfWifi_socket(SLNETSOCK_AF_INET, SLNETSOCK_SOCK_STREAM, 0, 0, 0); 906 Status = SlNetIfWifi_connect(SockID, (SlNetSock_Addr_t *)&Addr, AddrSize); 907 Status = SlNetIfWifi_send(SockID, Buf, 1460, 0 ); 908 \endcode 909 */ 910 int32_t SlNetIfWifi_send(int16_t sd, void *sdContext, const void *buf, uint32_t len, uint32_t flags); 911 912 /*! 913 \brief Write data to socket 914 915 The SlNetIfWifi_sendTo function is used to transmit a message on a connectionless socket 916 (connection less socket SLNETSOCK_SOCK_DGRAM, SLNETSOCK_SOCK_RAW).\n 917 Returns immediately after sending data to device.\n 918 In case of transmission failure an async event SLNETSOCK_SOCKET_TX_FAILED_EVENT is going to 919 be received. 920 921 \param[in] sd Socket descriptor (handle) 922 \param[in] sdContext May store socket data if implemented in the 923 SlNetIfWifi_socket function. 924 \param[in] buf Points to a buffer containing 925 the message to be sent 926 \param[in] len message size in bytes. Range: 1-1460 bytes 927 \param[in] flags Upper 8 bits specifies the security flags 928 Lower 24 bits specifies the type of message 929 reception. On this version, the lower 24 bits are not 930 supported 931 \param[in] to Pointer to an address structure 932 indicating the destination 933 address.\n sockaddr:\n - code 934 for the address format.\n - socket address, 935 the length depends on the code 936 format 937 \param[in] tolen Destination address structure size 938 939 \return Zero on success, or negative error code on failure 940 941 \sa SlNetIfWifi_send 942 \note 943 \warning 944 \par Example 945 946 - Sending data: 947 \code 948 SlNetSock_AddrIn_t Addr; 949 int16_t AddrSize = sizeof(SlNetSock_AddrIn_t); 950 int16_t SockID; 951 int16_t Status; 952 int8_t Buf[SEND_BUF_LEN]; 953 954 Addr.sin_family = SLNETSOCK_AF_INET; 955 Addr.sin_port = SlNetSock_htons(5001); 956 Addr.sin_addr.s_addr = SlNetSock_htonl(SLNETSOCK_IPV4_VAL(10,1,1,200)); 957 958 SockID = SlNetIfWifi_socket(SLNETSOCK_AF_INET, SLNETSOCK_SOCK_DGRAM, 0, 0, 0); 959 Status = SlNetIfWifi_sendTo(SockID, Buf, 1472, 0, (SlNetSock_Addr_t *)&Addr, AddrSize); 960 \endcode 961 */ 962 int32_t SlNetIfWifi_sendTo(int16_t sd, void *sdContext, const void *buf, uint32_t len, uint32_t flags, const SlNetSock_Addr_t *to, SlNetSocklen_t tolen); 963 964 965 /*! 966 \brief Start a security session on an opened socket 967 968 The SlNetIfWifi_sockstartSec function is used start a security session on 969 an opened socket. If the security handle is NULL the session would 970 be started with the default security settings. 971 972 \param[in] sd Socket descriptor (handle) 973 \param[in] sdContext May store socket data if implemented in the 974 SlNetIfWifi_socket function. 975 \param[in] secAttrib Secure attribute handle 976 \param[in] flags Specifies flags. \n 977 The available flags are: 978 - SLNETSOCK_SEC_START_SECURITY_SESSION_ONLY 979 - SLNETSOCK_SEC_BIND_CONTEXT_ONLY 980 - SLNETSOCK_SEC_IS_SERVER 981 982 \return Zero on success, or negative error code 983 on failure 984 985 \sa 986 \note 987 \warning 988 \par Example 989 990 - start security session on an opened socket: 991 \code 992 993 \endcode 994 */ 995 int32_t SlNetIfWifi_sockstartSec(int16_t sd, void *sdContext, SlNetSockSecAttrib_t *secAttrib, uint8_t flags); 996 997 998 /*! 999 \brief Get host IP by name\n 1000 Obtain the IP Address of machine on network, by machine name. 1001 1002 \param[in] ifContext Stores interface data if CreateContext function 1003 supported and implemented. 1004 Can be used in all SlNetIf_Config_t functions 1005 \param[in] ifBitmap Specifies the interfaces which the host ip 1006 needs to be retrieved from (according to 1007 the priority until one of them will return 1008 an answer).\n 1009 The values of the interface identifiers 1010 is defined with the prefix SLNETIF_ID_ 1011 which defined in slnetif.h 1012 \param[in] name Host name 1013 \param[in] nameLen Name length 1014 \param[out] ipAddr This parameter is filled in with 1015 host IP addresses. In case that host name is not 1016 resolved, out_ip_addr is zero. 1017 \param[in,out] ipAddrLen Holds the size of the ipAddr array, when function 1018 successful, the ipAddrLen parameter will be updated with 1019 the number of the IP addresses found. 1020 \param[in] family Protocol family 1021 1022 \return Zero on success, or negative on failure.\n 1023 SLNETUTIL_POOL_IS_EMPTY may be return in case 1024 there are no resources in the system\n 1025 In this case try again later or increase 1026 MAX_CONCURRENT_ACTIONS 1027 Possible DNS error codes: 1028 - SLNETUTIL_DNS_QUERY_NO_RESPONSE 1029 - SLNETUTIL_DNS_NO_SERVER 1030 - SLNETUTIL_DNS_QUERY_FAILED 1031 - SLNETUTIL_DNS_MALFORMED_PACKET 1032 - SLNETUTIL_DNS_MISMATCHED_RESPONSE 1033 1034 \sa 1035 \note Only one sl_NetAppDnsGetHostByName can be handled at a time.\n 1036 Calling this API while the same command is called from another 1037 thread, may result in one of the two scenarios: 1038 1. The command will wait (internal) until the previous command 1039 finish, and then be executed. 1040 2. There are not enough resources and POOL_IS_EMPTY error will 1041 return.\n 1042 In this case, MAX_CONCURRENT_ACTIONS can be increased (result 1043 in memory increase) or try again later to issue the command. 1044 \warning 1045 In case an IP address in a string format is set as input, without 1046 any prefix (e.g. "1.2.3.4") the device will not try to access the 1047 DNS and it will return the input address on the 'out_ip_addr' field 1048 \par Example 1049 - Getting host by name: 1050 \code 1051 uint16_t DestIPListSize = 1; 1052 uint32_t DestIP[1]; 1053 uint32_t ifID; 1054 int16_t SockId; 1055 SlNetSock_AddrIn_t LocalAddr; //address of the server to connect to 1056 int32_t LocalAddrSize; 1057 1058 SlNetIfWifi_getHostByName(0, "www.google.com", strlen("www.google.com"), (uint32_t *)DestIP, &DestIPListSize, SLNETSOCK_PF_INET); 1059 1060 LocalAddr.sin_family = SLNETSOCK_AF_INET; 1061 LocalAddr.sin_addr.s_addr = SlNetUtil_htonl(DestIP[0]); 1062 LocalAddr.sin_port = SlNetUtil_htons(80); 1063 LocalAddrSize = sizeof(SlNetSock_AddrIn_t); 1064 1065 SockId = SlNetIfWifi_socket(SLNETSOCK_AF_INET, SLNETSOCK_SOCK_STREAM, ifID, 0); 1066 1067 if (SockId >= 0) 1068 { 1069 status = SlNetIfWifi_connect(SockId, (SlNetSock_Addr_t *) &LocalAddr, LocalAddrSize); 1070 } 1071 \endcode 1072 */ 1073 int32_t SlNetIfWifi_getHostByName(void *ifContext, char *name, const uint16_t nameLen, uint32_t *ipAddr, uint16_t *ipAddrLen, const uint8_t family); 1074 1075 1076 /*! 1077 \brief Get IP Address of specific interface 1078 1079 The SlNetIfWifi_getIPAddr function retrieve the IP address of a specific 1080 interface according to the Address Type, IPv4, IPv6 LOCAL 1081 or IPv6 GLOBAL.\n 1082 1083 \n 1084 1085 \param[in] ifContext Stores interface data if CreateContext function 1086 supported and implemented. 1087 Can be used in all SlNetIf_Config_t functions 1088 \param[in] ifID Specifies the interface which its connection 1089 state needs to be retrieved.\n 1090 The values of the interface identifier is 1091 defined with the prefix SLNETIF_ID_ which 1092 defined in slnetif.h 1093 \param[in] addrType Address type: 1094 - SLNETIF_IPV4_ADDR 1095 - SLNETIF_IPV6_ADDR_LOCAL 1096 - SLNETIF_IPV6_ADDR_GLOBAL 1097 \param[out] addrConfig Address config: 1098 - SLNETIF_ADDR_CFG_UNKNOWN 1099 - SLNETIF_ADDR_CFG_DHCP 1100 - SLNETIF_ADDR_CFG_DHCP_LLA 1101 - SLNETIF_ADDR_CFG_STATIC 1102 - SLNETIF_ADDR_CFG_STATELESS 1103 - SLNETIF_ADDR_CFG_STATEFUL 1104 \param[out] ipAddr IP Address according to the Address Type 1105 1106 \return Zero on success, or negative error code on failure 1107 1108 \sa SlNetIfAddressType_e 1109 \note 1110 \warning 1111 \par Examples 1112 1113 \code 1114 SlNetSock_In6Addr_t IPAdd; 1115 uint16_t addressConfig = 0; 1116 SlNetIfWifi_getIPAddr(SLNETIF_ID_1 ,SLNETIF_IPV6_ADDR_LOCAL ,&addressConfig ,(uint8_t *)ipAddr); 1117 \endcode 1118 <br> 1119 */ 1120 int32_t SlNetIfWifi_getIPAddr(void *ifContext, SlNetIfAddressType_e addrType, uint16_t *addrConfig, uint32_t *ipAddr); 1121 1122 1123 /*! 1124 \brief Get interface connection status 1125 1126 The SlNetIfWifi_getConnectionStatus function gets the connection status of the 1127 interface (connected Or disconnected).\n 1128 1129 \param[in] ifContext Stores interface data if CreateContext function 1130 supported and implemented. 1131 Can be used in all SlNetIf_Config_t functions 1132 1133 \return Connection status of the interface on success, 1134 or negative error code on failure 1135 1136 \sa 1137 \note 1138 \warning 1139 \par Examples 1140 1141 \code 1142 int16_t connection_status 1143 connection_status = SlNetIfWifi_getConnectionStatus(); 1144 \endcode 1145 <br> 1146 */ 1147 int32_t SlNetIfWifi_getConnectionStatus(void *ifContext); 1148 1149 1150 /*! 1151 \brief Load secured buffer to the network stack 1152 1153 The SlNetSock_secLoadObj function loads buffer/files into the inputted 1154 network stack for future usage of the socket SSL/TLS connection. 1155 This option is relevant for network stacks with file system and also for 1156 network stacks that lack file system that can store the secured files. 1157 1158 \param[in] ifContext Stores interface data if CreateContext function 1159 supported and implemented. 1160 Can be used in all SlNetIf_Config_t functions 1161 \param[in] objType Specifies the security object type which 1162 could be one of the following:\n 1163 - SLNETIF_SEC_OBJ_TYPE_RSA_PRIVATE_KEY 1164 - SLNETIF_SEC_OBJ_TYPE_CERTIFICATE 1165 - SLNETIF_SEC_OBJ_TYPE_DH_KEY 1166 \param[in] objName Specifies the name/input identifier of the 1167 secured buffer loaded 1168 for file systems - this can be the file name 1169 for plain text buffer loading this can be the 1170 name of the object 1171 \param[in] objNameLen Specifies the buffer name length to be loaded.\n 1172 \param[in] objBuff Specifies the pointer to the secured buffer to 1173 be loaded.\n 1174 \param[in] objBuffLen Specifies the buffer length to be loaded.\n 1175 1176 \return On success, buffer type handler index to be 1177 used when attaching the secured buffer to a 1178 socket.\n 1179 A successful return code should be a positive 1180 number (int16)\n 1181 On error, a negative value will be returned 1182 specifying the error code. 1183 - SLNETERR_STATUS_ERROR - load operation failed 1184 1185 \sa SlNetIfWifi_setSockOpt 1186 \note 1187 \warning 1188 */ 1189 int32_t SlNetIfWifi_loadSecObj(void *ifContext, uint16_t objType, char *objName, int16_t objNameLen, uint8_t *objBuff, int16_t objBuffLen); 1190 1191 1192 /*! 1193 \brief Allocate and store interface data 1194 1195 The SlNetIfWifi_CreateContext function stores interface related data.\n 1196 1197 \param[in] ifContext Allocate and store interface data if needed. 1198 Can be used in all slnetwifi interface functions 1199 1200 \return Zero on success, or negative error code on failure. 1201 1202 \sa 1203 \note 1204 \warning 1205 \par Examples 1206 1207 \code 1208 void *ifContext; 1209 connection_status = SlNetIfWifi_CreateContext(&context); 1210 \endcode 1211 <br> 1212 */ 1213 int32_t SlNetIfWifi_CreateContext(uint16_t ifID, const char *ifName, void **ifContext); 1214 1215 1216 /*! 1217 1218 Close the Doxygen group. 1219 @} 1220 1221 */ 1222 1223 1224 #ifdef __cplusplus 1225 } 1226 #endif /* __cplusplus */ 1227 1228 #endif /* __SOCKET_H__ */ 1229 1230 1231