Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: W5500
Fork of Ethernet by
socket.h
00001 //***************************************************************************** 00002 // 00003 //! \file socket.h 00004 //! \brief SOCKET APIs Header file. 00005 //! \details SOCKET APIs like as berkeley socket api. 00006 //! \version 1.0.0 00007 //! \date 2013/10/01 00008 //! \par Revision history 00009 //! <2013/10/01> 1st Release 00010 //! \author MidnightCow 00011 //! \copyright 00012 //! 00013 //! Copyright (c) 2013, WIZnet Co., LTD. 00014 //! All rights reserved. 00015 //! 00016 //! Redistribution and use in source and binary forms, with or without 00017 //! modification, are permitted provided that the following conditions 00018 //! are met: 00019 //! 00020 //! * Redistributions of source code must retain the above copyright 00021 //! notice, this list of conditions and the following disclaimer. 00022 //! * Redistributions in binary form must reproduce the above copyright 00023 //! notice, this list of conditions and the following disclaimer in the 00024 //! documentation and/or other materials provided with the distribution. 00025 //! * Neither the name of the <ORGANIZATION> nor the names of its 00026 //! contributors may be used to endorse or promote products derived 00027 //! from this software without specific prior written permission. 00028 //! 00029 //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00030 //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00031 //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00032 //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00033 //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00034 //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00035 //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00036 //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00037 //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00038 //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 00039 //! THE POSSIBILITY OF SUCH DAMAGE. 00040 // 00041 //***************************************************************************** 00042 /** 00043 * @defgroup WIZnet_socket_APIs 1. WIZnet socket APIs 00044 * @brief WIZnet socket APIs are based on Berkeley socket APIs, thus it has much similar name and interface. 00045 * But there is a little bit of difference. 00046 * @details 00047 * <b> Comparison between WIZnet and Berkeley SOCKET APIs </b> 00048 * <table> 00049 * <tr> <td><b>API</b></td> <td><b>WIZnet</b></td> <td><b>Berkeley</b></td> </tr> 00050 * <tr> <td>socket()</td> <td>O</td> <td>O</td> </tr> 00051 * <tr> <td><b>bind()</b></td> <td>X</td> <td>O</td> </tr> 00052 * <tr> <td><b>listen()</b></td> <td>O</td> <td>O</td> </tr> 00053 * <tr> <td><b>connect()</b></td> <td>O</td> <td>O</td> </tr> 00054 * <tr> <td><b>accept()</b></td> <td>X</td> <td>O</td> </tr> 00055 * <tr> <td><b>recv()</b></td> <td>O</td> <td>O</td> </tr> 00056 * <tr> <td><b>send()</b></td> <td>O</td> <td>O</td> </tr> 00057 * <tr> <td><b>recvfrom()</b></td> <td>O</td> <td>O</td> </tr> 00058 * <tr> <td><b>sendto()</b></td> <td>O</td> <td>O</td> </tr> 00059 * <tr> <td><b>closesocket()</b></td> <td>O<br>close() & disconnect()</td> <td>O</td> </tr> 00060 * </table> 00061 * There are @b bind() and @b accept() functions in @b Berkeley SOCKET API but, 00062 * not in @b WIZnet SOCKET API. Because socket() of WIZnet is not only creating a SOCKET but also binding a local port number, 00063 * and listen() of WIZnet is not only listening to connection request from client but also accepting the connection request. \n 00064 * When you program "TCP SERVER" with Berkeley SOCKET API, you can use only one listen port. 00065 * When the listen SOCKET accepts a connection request from a client, it keeps listening. 00066 * After accepting the connection request, a new SOCKET is created and the new SOCKET is used in communication with the client. \n 00067 * Following figure shows network flow diagram by Berkeley SOCKET API. 00068 * @image html Berkeley_SOCKET.jpg "<Berkeley SOCKET API>" 00069 * But, When you program "TCP SERVER" with WIZnet SOCKET API, you can use as many as 8 listen SOCKET with same port number. \n 00070 * Because there's no accept() in WIZnet SOCKET APIs, when the listen SOCKET accepts a connection request from a client, 00071 * it is changed in order to communicate with the client. 00072 * And the changed SOCKET is not listening any more and is dedicated for communicating with the client. \n 00073 * If there're many listen SOCKET with same listen port number and a client requests a connection, 00074 * the SOCKET which has the smallest SOCKET number accepts the request and is changed as communication SOCKET. \n 00075 * Following figure shows network flow diagram by WIZnet SOCKET API. 00076 * @image html WIZnet_SOCKET.jpg "<WIZnet SOCKET API>" 00077 */ 00078 #ifdef __cplusplus 00079 extern "C" { 00080 #endif 00081 00082 #ifndef _SOCKET_H_ 00083 #define _SOCKET_H_ 00084 00085 #include "Ethernet/wizchip_conf.h" 00086 00087 #define SOCK_OK 1 ///< Result is OK about socket process. 00088 #define SOCK_BUSY 0 ///< Socket is busy on processing the operation. Valid only Non-block IO Mode. 00089 #define SOCK_FATAL -1000 ///< Result is fatal error about socket process. 00090 00091 #define SOCK_ERROR 0 00092 #define SOCKERR_SOCKNUM (SOCK_ERROR - 1) ///< Invalid socket number 00093 #define SOCKERR_SOCKOPT (SOCK_ERROR - 2) ///< Invalid socket option 00094 #define SOCKERR_SOCKINIT (SOCK_ERROR - 3) ///< Socket is not initialized 00095 #define SOCKERR_SOCKCLOSED (SOCK_ERROR - 4) ///< Socket unexpectedly closed. 00096 #define SOCKERR_SOCKMODE (SOCK_ERROR - 5) ///< Invalid socket mode for socket operation. 00097 #define SOCKERR_SOCKFLAG (SOCK_ERROR - 6) ///< Invalid socket flag 00098 #define SOCKERR_SOCKSTATUS (SOCK_ERROR - 7) ///< Invalid socket status for socket operation. 00099 #define SOCKERR_ARG (SOCK_ERROR - 10) ///< Invalid argrument. 00100 #define SOCKERR_PORTZERO (SOCK_ERROR - 11) ///< Port number is zero 00101 #define SOCKERR_IPINVALID (SOCK_ERROR - 12) ///< Invalid IP address 00102 #define SOCKERR_TIMEOUT (SOCK_ERROR - 13) ///< Timeout occurred 00103 #define SOCKERR_DATALEN (SOCK_ERROR - 14) ///< Data length is zero or greater than buffer max size. 00104 #define SOCKERR_BUFFER (SOCK_ERROR - 15) ///< Socket buffer is not enough for data communication. 00105 00106 #define SOCKFATAL_PACKLEN (SOCK_FATAL - 1) ///< Invalid packet length. Fatal Error. 00107 00108 /* 00109 * SOCKET FLAG 00110 */ 00111 #define SF_ETHER_OWN (Sn_MR_MFEN) ///< In \ref Sn_MR_MACRAW, Receive only the packet as broadcast, multicast and own packet 00112 #define SF_IGMP_VER2 (Sn_MR_MC) ///< In \ref Sn_MR_UDP with \ref SF_MULTI_ENABLE, Select IGMP version 2. 00113 #define SF_TCP_NODELAY (Sn_MR_ND) ///< In \ref Sn_MR_TCP, Use to nodelayed ack. 00114 #define SF_MULTI_ENABLE (Sn_MR_MULTI) ///< In \ref Sn_MR_UDP, Enable multicast mode. 00115 00116 #if _WIZCHIP_ == 5500 00117 #define SF_BROAD_BLOCK (Sn_MR_BCASTB) ///< In \ref Sn_MR_UDP or \ref Sn_MR_MACRAW, Block broadcast packet. Valid only in W5500 00118 #define SF_MULTI_BLOCK (Sn_MR_MMB) ///< In \ref Sn_MR_MACRAW, Block multicast packet. Valid only in W5500 00119 #define SF_IPv6_BLOCK (Sn_MR_MIP6B) ///< In \ref Sn_MR_MACRAW, Block IPv6 packet. Valid only in W5500 00120 #define SF_UNI_BLOCK (Sn_MR_UCASTB) ///< In \ref Sn_MR_UDP with \ref SF_MULTI_ENABLE. Valid only in W5500 00121 #endif 00122 00123 #define SF_IO_NONBLOCK 0x01 ///< Socket nonblock io mode. It used parameter in \ref socket(). 00124 00125 /* 00126 * UDP & MACRAW Packet Infomation 00127 */ 00128 #define PACK_FIRST 0x80 ///< In Non-TCP packet, It indicates to start receiving a packet. 00129 #define PACK_REMAINED 0x01 ///< In Non-TCP packet, It indicates to remaine a packet to be received. 00130 #define PACK_COMPLETED 0x00 ///< In Non-TCP packet, It indicates to complete to receive a packet. 00131 00132 /** 00133 * @ingroup WIZnet_socket_APIs 00134 * @brief Open a socket. 00135 * @details Initializes the socket with 'sn' passed as parameter and open. 00136 * 00137 * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>. 00138 * @param protocol Protocol type to operate such as TCP, UDP and MACRAW. 00139 * @param port Port number to be bined. 00140 * @param flag Socket flags as \ref SF_ETHER_OWN, \ref SF_IGMP_VER2, \ref SF_TCP_NODELAY, \ref SF_MULTI_ENABLE, \ref SF_IO_NONBLOCK and so on.\n 00141 * Valid flags only in W5500 : @ref SF_BROAD_BLOCK, @ref SF_MULTI_BLOCK, @ref SF_IPv6_BLOCK, and @ref SF_UNI_BLOCK. 00142 * @sa Sn_MR 00143 * 00144 * @return @b Success : The socket number @b 'sn' passed as parameter\n 00145 * @b Fail :\n @ref SOCKERR_SOCKNUM - Invalid socket number\n 00146 * @ref SOCKERR_SOCKMODE - Not support socket mode as TCP, UDP, and so on. \n 00147 * @ref SOCKERR_SOCKFLAG - Invaild socket flag. 00148 */ 00149 int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag); 00150 00151 /** 00152 * @ingroup WIZnet_socket_APIs 00153 * @brief Close a socket. 00154 * @details It closes the socket with @b'sn' passed as parameter. 00155 * 00156 * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>. 00157 * 00158 * @return @b Success : @ref SOCK_OK \n 00159 * @b Fail : @ref SOCKERR_SOCKNUM - Invalid socket number 00160 */ 00161 int8_t close(uint8_t sn); 00162 00163 /** 00164 * @ingroup WIZnet_socket_APIs 00165 * @brief Listen to a connection request from a client. 00166 * @details It is listening to a connection request from a client. 00167 * If connection request is accepted successfully, the connection is established. Socket sn is used in passive(server) mode. 00168 * 00169 * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>. 00170 * @return @b Success : @ref SOCK_OK \n 00171 * @b Fail :\n @ref SOCKERR_SOCKINIT - Socket is not initialized \n 00172 * @ref SOCKERR_SOCKCLOSED - Socket closed unexpectedly. 00173 */ 00174 int8_t listen(uint8_t sn); 00175 00176 /** 00177 * @ingroup WIZnet_socket_APIs 00178 * @brief Try to connect a server. 00179 * @details It requests connection to the server with destination IP address and port number passed as parameter.\n 00180 * @note It is valid only in TCP client mode. 00181 * In block io mode, it does not return until connection is completed. 00182 * In Non-block io mode, it return @ref SOCK_BUSY immediatly. 00183 * 00184 * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>. 00185 * @param addr Pointer variable of destination IP address. It should be allocated 4 bytes. 00186 * @param port Destination port number. 00187 * 00188 * @return @b Success : @ref SOCK_OK \n 00189 * @b Fail :\n @ref SOCKERR_SOCKNUM - Invalid socket number\n 00190 * @ref SOCKERR_SOCKMODE - Invalid socket mode\n 00191 * @ref SOCKERR_SOCKINIT - Socket is not initialized\n 00192 * @ref SOCKERR_IPINVALID - Wrong server IP address\n 00193 * @ref SOCKERR_PORTZERO - Server port zero\n 00194 * @ref SOCKERR_TIMEOUT - Timeout occurred during request connection\n 00195 * @ref SOCK_BUSY - In non-block io mode, it returned immediatly\n 00196 */ 00197 int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port); 00198 00199 /** 00200 * @ingroup WIZnet_socket_APIs 00201 * @brief Try to disconnect a connection socket. 00202 * @details It sends request message to disconnect the TCP socket 'sn' passed as parameter to the server or client. 00203 * @note It is valid only in TCP server or client mode. \n 00204 * In block io mode, it does not return until disconnection is completed. \n 00205 * In Non-block io mode, it return @ref SOCK_BUSY immediatly. \n 00206 00207 * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>. 00208 * @return @b Success : @ref SOCK_OK \n 00209 * @b Fail :\n @ref SOCKERR_SOCKNUM - Invalid socket number \n 00210 * @ref SOCKERR_SOCKMODE - Invalid operation in the socket \n 00211 * @ref SOCKERR_TIMEOUT - Timeout occurred \n 00212 * @ref SOCK_BUSY - Socket is busy. 00213 */ 00214 int8_t disconnect(uint8_t sn); 00215 00216 /** 00217 * @ingroup WIZnet_socket_APIs 00218 * @brief Send data to the connected peer in TCP socket. 00219 * @details It is used to send outgoing data to the connected socket. 00220 * @note It is valid only in TCP server or client mode. It can't send data greater than socket buffer size. \n 00221 * In block io mode, It doesn't return until data send is completed - socket buffer size is greater than data. \n 00222 * In non-block io mode, It return @ref SOCK_BUSY immediatly when socket buffer is not enough. \n 00223 * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>. 00224 * @param buf Pointer buffer containing data to be sent. 00225 * @param len The byte length of data in buf. 00226 * @return @b Success : The sent data size \n 00227 * @b Fail : \n @ref SOCKERR_SOCKSTATUS - Invalid socket status for socket operation \n 00228 * @ref SOCKERR_TIMEOUT - Timeout occurred \n 00229 * @ref SOCKERR_SOCKMODE - Invalid operation in the socket \n 00230 * @ref SOCKERR_SOCKNUM - Invalid socket number \n 00231 * @ref SOCKERR_DATALEN - zero data length \n 00232 * @ref SOCK_BUSY - Socket is busy. 00233 */ 00234 int32_t send(uint8_t sn, uint8_t * buf, uint16_t len); 00235 00236 /** 00237 * @ingroup WIZnet_socket_APIs 00238 * @brief Receive data from the connected peer. 00239 * @details It is used to read incoming data from the connected socket.\n 00240 * It waits for data as much as the application wants to receive. 00241 * @note It is valid only in TCP server or client mode. It can't receive data greater than socket buffer size. \n 00242 * In block io mode, it doesn't return until data reception is completed - data is filled as <I>len</I> in socket buffer. \n 00243 * In non-block io mode, it return @ref SOCK_BUSY immediatly when <I>len</I> is greater than data size in socket buffer. \n 00244 * 00245 * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>. 00246 * @param buf Pointer buffer to read incoming data. 00247 * @param len The max data length of data in buf. 00248 * @return @b Success : The real received data size \n 00249 * @b Fail :\n 00250 * @ref SOCKERR_SOCKSTATUS - Invalid socket status for socket operation \n 00251 * @ref SOCKERR_SOCKMODE - Invalid operation in the socket \n 00252 * @ref SOCKERR_SOCKNUM - Invalid socket number \n 00253 * @ref SOCKERR_DATALEN - zero data length \n 00254 * @ref SOCK_BUSY - Socket is busy. 00255 */ 00256 int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len); 00257 00258 /** 00259 * @ingroup WIZnet_socket_APIs 00260 * @brief Sends datagram to the peer with destination IP address and port number passed as parameter. 00261 * @details It sends datagram of UDP or MACRAW to the peer with destination IP address and port number passed as parameter.\n 00262 * Even if the connectionless socket has been previously connected to a specific address, 00263 * the address and port number parameters override the destination address for that particular datagram only. 00264 * @note In block io mode, It doesn't return until data send is completed - socket buffer size is greater than <I>len</I>. 00265 * In non-block io mode, It return @ref SOCK_BUSY immediatly when socket buffer is not enough. 00266 * 00267 * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>. 00268 * @param buf Pointer buffer to send outgoing data. 00269 * @param len The byte length of data in buf. 00270 * @param addr Pointer variable of destination IP address. It should be allocated 4 bytes. 00271 * @param port Destination port number. 00272 * 00273 * @return @b Success : The sent data size \n 00274 * @b Fail :\n @ref SOCKERR_SOCKNUM - Invalid socket number \n 00275 * @ref SOCKERR_SOCKMODE - Invalid operation in the socket \n 00276 * @ref SOCKERR_SOCKSTATUS - Invalid socket status for socket operation \n 00277 * @ref SOCKERR_DATALEN - zero data length \n 00278 * @ref SOCKERR_IPINVALID - Wrong server IP address\n 00279 * @ref SOCKERR_PORTZERO - Server port zero\n 00280 * @ref SOCKERR_SOCKCLOSED - Socket unexpectedly closed \n 00281 * @ref SOCKERR_TIMEOUT - Timeout occurred \n 00282 * @ref SOCK_BUSY - Socket is busy. 00283 */ 00284 int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port); 00285 00286 /** 00287 * @ingroup WIZnet_socket_APIs 00288 * @brief Receive datagram of UDP or MACRAW 00289 * @details This function is an application I/F function which is used to receive the data in other then TCP mode. \n 00290 * This function is used to receive UDP and MAC_RAW mode, and handle the header as well. 00291 * This function can divide to recevie the packet data. 00292 * On the MACRAW SOCKET, the addr and port parameters are ignored. 00293 * @note In block io mode, it doesn't return until data reception is completed - data is filled as <I>len</I> in socket buffer 00294 * In non-block io mode, it return @ref SOCK_BUSY immediatly when <I>len</I> is greater than data size in socket buffer. 00295 * 00296 * @param sn Socket number. It should be <b>0 ~ @ref \_WIZCHIP_SOCK_NUM_</b>. 00297 * @param buf Pointer buffer to read incoming data. 00298 * @param len The max data length of data in buf. 00299 * When the received packet size <= len, receives data as packet sized. 00300 * When others, receives data as len. 00301 * @param addr Pointer variable of destination IP address. It should be allocated 4 bytes. 00302 * It is valid only when the first call recvform for receiving the packet. 00303 * When it is valid, packinfo[7] should be set as '1'. 00304 * @param port Pointer variable of destination port number. 00305 * It is valid only when the first call recvform for receiving the packet. 00306 * When it is valid, packinfo[7] should be set as '1'. 00307 * @param packinfo Notify whether the packet is received completely or not. 00308 * When it completed to receive the packet data in socket buffer, packinfo[0] set as '0'. @ref PACK_FIRST 00309 * When it Remained packet data that receives not yet but remained in socket buffer, packinfo[1] set as '1'. @ref PACK_COMPLETED 00310 * 00311 * @return @b Success : This function return real received data size for success.\n 00312 * @b Fail : @ref SOCKERR_DATALEN - zero data length \n 00313 * @ref SOCKERR_SOCKMODE - Invalid operation in the socket \n 00314 * @ref SOCKERR_SOCKNUM - Invalid socket number \n 00315 * @ref SOCKBUSY - Socket is busy. 00316 */ 00317 int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port, uint8_t* packinfo); 00318 00319 00320 ///////////////////////////// 00321 // SOCKET CONTROL & OPTION // 00322 ///////////////////////////// 00323 #define SOCK_IO_BLOCK 0 ///< Socket Block IO Mode in @ref setsockopt(). 00324 #define SOCK_IO_NONBLOCK 1 ///< Socket Non-block IO Mode in @ref setsockopt(). 00325 00326 /** 00327 * @defgroup DATA_TYPE DATA TYPE 00328 */ 00329 00330 /** 00331 * @ingroup DATA_TYPE 00332 * @brief The kind of Socket Interrupt. 00333 * @sa Sn_IR, Sn_IMR, setSn_IR(), getSn_IR(), setSn_IMR(), getSn_IMR() 00334 */ 00335 typedef enum 00336 { 00337 SIK_CONNECTED = (1 << 0), ///< conntected 00338 SIK_DISCONNECTED = (1 << 1), ///< disconnected 00339 SIK_RECEIVED = (1 << 2), ///< data received 00340 SIK_TIMEOUT = (1 << 3), ///< timeout occured 00341 SIK_SENT = (1 << 4), ///< send ok 00342 SIK_ALL = 0x1F, ///< all interrupt 00343 }sockint_kind; 00344 00345 /** 00346 * @ingroup DATA_TYPE 00347 * @brief The type of @ref ctlsocket(). 00348 */ 00349 typedef enum 00350 { 00351 CS_SET_IOMODE, ///< set socket IO mode with @ref SOCK_IO_BLOCK or @ref SOCK_IO_NONBLOCK 00352 CS_GET_IOMODE, ///< get socket IO mode 00353 CS_GET_MAXTXBUF, ///< get the size of socket buffer allocated in TX memory 00354 CS_GET_MAXRXBUF, ///< get the size of socket buffer allocated in RX memory 00355 CS_CLR_INTERRUPT, ///< clear the interrupt of socket with @ref sockint_kind 00356 CS_GET_INTERRUPT, ///< get the socket interrupt. refer to @ref sockint_kind 00357 CS_SET_INTMASK, ///< set the interrupt mask of socket with @ref sockint_kind 00358 CS_GET_INTMASK ///< get the masked interrupt of socket. refer to @ref sockint_kind 00359 }ctlsock_type; 00360 00361 00362 /** 00363 * @ingroup DATA_TYPE 00364 * @brief The type of socket option in @ref setsockopt() or @ref getsockopt() 00365 */ 00366 typedef enum 00367 { 00368 SO_FLAG, ///< Valid only in getsockopt(), For set flag of socket refer to <I>flag</I> in @ref socket(). 00369 SO_TTL, ///< Set/Get TTL. @ref Sn_TTL ( @ref setSn_TTL(), @ref getSn_TTL() ) 00370 SO_TOS, ///< Set/Get TOS. @ref Sn_TOS ( @ref setSn_TOS(), @ref getSn_TOS() ) 00371 SO_MSS, ///< Set/Get MSS. @ref Sn_MSSR ( @ref setSn_MSSR(), @ref getSn_MSSR() ) 00372 SO_DESTIP, ///< Set/Get the destination IP address. @ref Sn_DIPR ( @ref setSn_DIPR(), @ref getSn_DIPR() ) 00373 SO_DESTPORT, ///< Set/Get the destionation Port number. @ref Sn_DPORT ( @ref setSn_DPORT(), @ref getSn_DPORT() ) 00374 #if _WIZCHIP_ != 5100 00375 SO_KEEPALIVESEND, ///< Valid only in setsockopt. Manually send keep-alive packet in TCP mode 00376 #if _WIZCHIP_ > 5200 00377 SO_KEEPALIVEAUTO, ///< Set/Get keep-alive auto transimittion timer in TCP mode 00378 #endif 00379 #endif 00380 SO_SENDBUF, ///< Valid only in getsockopt. Get the free data size of Socekt TX buffer. @ref Sn_TX_FSR, @ref getSn_TX_FSR() 00381 SO_RECVBUF, ///< Valid only in getsockopt. Get the received data size in socket RX buffer. @ref Sn_RX_RSR, @ref getSn_RX_RSR() 00382 SO_STATUS, ///< Valid only in getsockopt. Get the socket status. @ref Sn_SR, @ref getSn_SR() 00383 SO_REMAINSIZE ///< Valid only in getsockopt. Get the remaind packet size in other then TCP mode. 00384 }sockopt_type; 00385 00386 /** 00387 * @ingroup WIZnet_socket_APIs 00388 * @brief Control socket. 00389 * @details Control IO mode, Interrupt & Mask of socket and get the socket buffer information. 00390 * Refer to @ref ctlsock_type. 00391 * @param sn socket number 00392 * @param cstype type of control socket. refer to @ref ctlsock_type. 00393 * @param arg Data type and value is determined according to @ref ctlsock_type. \n 00394 * <table> 00395 * <tr> <td> @b cstype </td> <td> @b data type</td><td>@b value</td></tr> 00396 * <tr> <td> @ref CS_SET_IOMODE \n @ref CS_GET_IOMODE </td> <td> uint8_t </td><td>@ref SOCK_IO_BLOCK @ref SOCK_IO_NONBLOCK</td></tr> 00397 * <tr> <td> @ref CS_GET_MAXTXBUF \n @ref CS_GET_MAXRXBUF </td> <td> uint16_t </td><td> 0 ~ 16K </td></tr> 00398 * <tr> <td> @ref CS_CLR_INTERRUPT \n @ref CS_GET_INTERRUPT </td> <td> @ref sockint_kind </td><td> @ref SIK_CONNECTED, etc. </td></tr> 00399 * <tr> <td> @ref CS_CLR_INTERRUPT \n @ref CS_GET_INTERRUPT \n @ref CS_SET_INTMASK \n @ref CS_GET_INTMASK </td> <td> @ref sockint_kind </td><td> @ref SIK_CONNECTED, etc. </td></tr> 00400 * </table> 00401 * @return @b Success @ref SOCK_OK \n 00402 * @b fail @ref SOCKERR_ARG - Invalid argument\n 00403 */ 00404 int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg); 00405 00406 /** 00407 * @ingroup WIZnet_socket_APIs 00408 * @brief set socket options 00409 * @details Set socket option like as TTL, MSS, TOS, and so on. Refer to @ref sockopt_type. 00410 * 00411 * @param sn socket number 00412 * @param sotype socket option type. refer to @ref sockopt_type 00413 * @param arg Data type and value is determined according to <I>sotype</I>. \n 00414 * <table> 00415 * <tr> <td> @b sotype </td> <td> @b data type</td><td>@b value</td></tr> 00416 * <tr> <td> @ref SO_TTL </td> <td> uint8_t </td><td> 0 ~ 255 </td> </tr> 00417 * <tr> <td> @ref SO_TOS </td> <td> uint8_t </td><td> 0 ~ 255 </td> </tr> 00418 * <tr> <td> @ref SO_MSS </td> <td> uint16_t </td><td> 0 ~ 65535 </td> </tr> 00419 * <tr> <td> @ref SO_DESTIP </td> <td> uint8_t[4] </td><td> </td></tr> 00420 * <tr> <td> @ref SO_DESTPORT </td> <td> uint16_t </td><td> 0 ~ 65535 </td></tr> 00421 * <tr> <td> @ref SO_KEEPALIVESEND </td> <td> null </td><td> null </td></tr> 00422 * <tr> <td> @ref SO_KEEPALIVEAUTO </td> <td> uint8_t </td><td> 0 ~ 255 </td></tr> 00423 * </table> 00424 * @return 00425 * - @b Success : @ref SOCK_OK \n 00426 * - @b Fail 00427 * - @ref SOCKERR_SOCKNUM - Invalid Socket number \n 00428 * - @ref SOCKERR_SOCKMODE - Invalid socket mode \n 00429 * - @ref SOCKERR_SOCKOPT - Invalid socket option or its value \n 00430 * - @ref SOCKERR_TIMEOUT - Timeout occured when sending keep-alive packet \n 00431 */ 00432 int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg); 00433 00434 /** 00435 * @ingroup WIZnet_socket_APIs 00436 * @brief get socket options 00437 * @details Get socket option like as FLAG, TTL, MSS, and so on. Refer to @ref sockopt_type 00438 * @param sn socket number 00439 * @param sotype socket option type. refer to @ref sockopt_type 00440 * @param arg Data type and value is determined according to <I>sotype</I>. \n 00441 * <table> 00442 * <tr> <td> @b sotype </td> <td>@b data type</td><td>@b value</td></tr> 00443 * <tr> <td> @ref SO_FLAG </td> <td> uint8_t </td><td> @ref SF_ETHER_OWN, etc... </td> </tr> 00444 * <tr> <td> @ref SO_TOS </td> <td> uint8_t </td><td> 0 ~ 255 </td> </tr> 00445 * <tr> <td> @ref SO_MSS </td> <td> uint16_t </td><td> 0 ~ 65535 </td> </tr> 00446 * <tr> <td> @ref SO_DESTIP </td> <td> uint8_t[4] </td><td> </td></tr> 00447 * <tr> <td> @ref SO_DESTPORT </td> <td> uint16_t </td><td> </td></tr> 00448 * <tr> <td> @ref SO_KEEPALIVEAUTO </td> <td> uint8_t </td><td> 0 ~ 255 </td></tr> 00449 * <tr> <td> @ref SO_SENDBUF </td> <td> uint16_t </td><td> 0 ~ 65535 </td></tr> 00450 * <tr> <td> @ref SO_RECVBUF </td> <td> uint16_t </td><td> 0 ~ 65535 </td></tr> 00451 * <tr> <td> @ref SO_STATUS </td> <td> uint8_t </td><td> @ref SOCK_ESTABLISHED, etc.. </td></tr> 00452 * <tr> <td> @ref SO_REMAINSIZE </td> <td> uint16_t </td><td> 0~ 65535 </td></tr> 00453 * </table> 00454 * @return 00455 * - @b Success : @ref SOCK_OK \n 00456 * - @b Fail 00457 * - @ref SOCKERR_SOCKNUM - Invalid Socket number \n 00458 * - @ref SOCKERR_SOCKOPT - Invalid socket option or its value \n 00459 * - @ref SOCKERR_SOCKMODE - Invalid socket mode \n 00460 */ 00461 int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg); 00462 00463 #endif // _SOCKET_H_ 00464 00465 #ifdef __cplusplus 00466 } 00467 #endif
Generated on Tue Jul 12 2022 17:16:46 by
1.7.2

WIZ550io
W5500