W5500
Macros | Functions
socket.h File Reference

SOCKET APIs Header file. SOCKET APIs like as berkeley socket api. More...

#include "wizchip_conf.h"
Include dependency graph for socket.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SOCKOK_SUCC   0
 
#define SOCKERR_ERROR   -1
 
#define SOCKERR_FATAL   -1000
 
#define SOCKERR_SOCKNUM   (SOCKERR_ERROR - 1)
 
#define SOCKERR_SOCKOPT   (SOCKERR_ERROR - 2)
 
#define SOCKERR_SOCKINIT   (SOCKERR_ERROR - 3)
 
#define SOCKERR_SOCKCLOSED   (SOCKERR_ERROR - 4)
 
#define SOCKERR_SOCKMODE   (SOCKERR_ERROR - 5)
 
#define SOCKERR_SOCKSTATUS   (SOCKERR_ERROR - 6)
 
#define SOCKERR_PORTZERO   (SOCKERR_ERROR - 10)
 
#define SOCKERR_IPINVALID   (SOCKERR_ERROR - 11)
 
#define SOCKERR_TIMEOUT   (SOCKERR_ERROR - 12)
 
#define SOCKERR_DATALEN   (SOCKERR_ERROR - 13)
 
#define SOCKERR_BUFFER   (SOCKERR_ERROR - 14)
 
#define SOCKERR_BUSY   (SOCKERR_ERROR - 20)
 
#define SOCKFATAL_PACKLEN   (SOCKERR_FATAL - 1)
 

Functions

int8_t socket (uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
 Initializes the socket with 'sn' passed as parameter. More...
 
int8_t close (uint8_t sn)
 Closes the socket with 'sn' passed as parameter. More...
 
int8_t listen (uint8_t sn)
 Listens to a connection request from client. If connection request is accepted succesfully, the connection is established. Socket sn is used in passive(server) mode. More...
 
int8_t connect (uint8_t sn, uint8_t *addr, uint16_t port)
 Request to connection to the server has addr & port passed as parameter Socket sn is used in active (client) mode. More...
 
int8_t disconnect (uint8_t sn)
 Disconnects the tcp socket 'sn' passed as parameter. More...
 
int32_t send (uint8_t sn, uint8_t *buf, uint16_t len)
 Send data to the connected peer in TCP socket. More...
 
int32_t recv (uint8_t sn, uint8_t *buf, uint16_t len)
 Receive data from the connected peer. It waits for data as much as the application wants to receive. More...
 
int32_t sendto (uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t port)
 Sends datagram to the peer has ip & port passed as parameter. return Success : The sent data size Fail : SOCKERR_SOCKNUM SOCKERR_SOCKMODE SOCKERR_SOCKSTATUS SOCKERR_DATALEN SOCKERR_IPINVALID SOCKERR_PORTZERO SOCKERR_SOCKCLOSED SOCKERR_TIMEOUT. More...
 
int32_t recvfrom (uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t *port)
 This function is an application I/F function which is used to receive the data in other then TCP mode. This function is used to receive UDP, IP_RAW and MAC_RAW mode, and handle the header as well. More...
 

Detailed Description

SOCKET APIs Header file. SOCKET APIs like as berkeley socket api.

Version
1.0.0.0
Date
09/01/2013
Revision history
<09-01-2013> 1st Release
Author
MidnightCow

Copyright (c) 2013, WIZnet Co., LTD. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright 

notice, this list of conditions and the following disclaimer.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition in file socket.h.

Macro Definition Documentation

#define SOCKOK_SUCC   0

Definition at line 47 of file socket.h.

Referenced by close(), connect(), disconnect(), and listen().

#define SOCKERR_ERROR   -1

Definition at line 48 of file socket.h.

#define SOCKERR_FATAL   -1000

Definition at line 49 of file socket.h.

#define SOCKERR_SOCKNUM   (SOCKERR_ERROR - 1)

Definition at line 51 of file socket.h.

#define SOCKERR_SOCKOPT   (SOCKERR_ERROR - 2)

Definition at line 52 of file socket.h.

#define SOCKERR_SOCKINIT   (SOCKERR_ERROR - 3)

Definition at line 53 of file socket.h.

#define SOCKERR_SOCKCLOSED   (SOCKERR_ERROR - 4)

Definition at line 54 of file socket.h.

Referenced by listen(), recvfrom(), and sendto().

#define SOCKERR_SOCKMODE   (SOCKERR_ERROR - 5)

Definition at line 55 of file socket.h.

Referenced by recvfrom(), sendto(), and socket().

#define SOCKERR_SOCKSTATUS   (SOCKERR_ERROR - 6)

Definition at line 56 of file socket.h.

Referenced by recv(), send(), and sendto().

#define SOCKERR_PORTZERO   (SOCKERR_ERROR - 10)

Definition at line 57 of file socket.h.

Referenced by connect(), and sendto().

#define SOCKERR_IPINVALID   (SOCKERR_ERROR - 11)

Definition at line 58 of file socket.h.

Referenced by connect(), and sendto().

#define SOCKERR_TIMEOUT   (SOCKERR_ERROR - 12)

Definition at line 59 of file socket.h.

Referenced by connect(), disconnect(), send(), and sendto().

#define SOCKERR_DATALEN   (SOCKERR_ERROR - 13)

Definition at line 60 of file socket.h.

#define SOCKERR_BUFFER   (SOCKERR_ERROR - 14)

Definition at line 61 of file socket.h.

#define SOCKERR_BUSY   (SOCKERR_ERROR - 20)

Definition at line 62 of file socket.h.

#define SOCKFATAL_PACKLEN   (SOCKERR_FATAL - 1)

Definition at line 64 of file socket.h.

Referenced by recvfrom().

Function Documentation

int8_t socket ( uint8_t  sn,
uint8_t  protocol,
uint16_t  port,
uint8_t  flag 
)

Initializes the socket with 'sn' passed as parameter.

Returns
Success : The socket number passed param sn Fail : SOCKERR_SOCKNUM - Invalid socket number SOCKERR_SOCKMODE - Not support socket mode as TCP, UDP, and so on.

Definition at line 75 of file socket.c.

References CHECK_SOCKNUM, close(), getSn_CR(), setSn_CR(), setSn_MR(), setSn_PORT(), Sn_CR_OPEN, Sn_MR_MACRAW, Sn_MR_TCP, Sn_MR_UDP, SOCK_ANY_PORT_NUM, and SOCKERR_SOCKMODE.

int8_t close ( uint8_t  sn)

Closes the socket with 'sn' passed as parameter.

Returns
Success : SOCKOK_SUCCESS Fail : SOCKERR_SOCKNUM

Definition at line 110 of file socket.c.

References CHECK_SOCKNUM, getSn_CR(), setSn_CR(), setSn_IR(), Sn_CR_CLOSE, and SOCKOK_SUCC.

Referenced by disconnect(), listen(), recv(), recvfrom(), send(), and socket().

int8_t listen ( uint8_t  sn)

Listens to a connection request from client. If connection request is accepted succesfully, the connection is established. Socket sn is used in passive(server) mode.

Returns
Success : SOCKOK_SUCC Fail : SOCKERR_SOCKINIT - Socket is not initialized SOCKERR_SOCKCLOSED - Socket closed unexpectly.

Definition at line 131 of file socket.c.

References CHECK_SOCKINIT, CHECK_SOCKMODE, CHECK_SOCKNUM, close(), getSn_CR(), getSn_SR(), setSn_CR(), Sn_CR_LISTEN, Sn_MR_TCP, SOCK_CLOSED, SOCK_LISTEN, SOCKERR_SOCKCLOSED, and SOCKOK_SUCC.

int8_t connect ( uint8_t  sn,
uint8_t *  addr,
uint16_t  port 
)

Request to connection to the server has addr & port passed as parameter Socket sn is used in active (client) mode.

Returns
success : SOCKOK_SUCC Fail : SOCKERR_SOCKNUM - Invalid socket number SOCKERR_SOCKMODE - Invalid socket mode SOCKERR_SOCKINIT - Socket is not initialized SOCKERR_IPINVALID - Wrong server ip address SOCKERR_PORTZERO - Server port zero SOCKERR_TIMEOUT - Timeout occurred during request connection

Definition at line 161 of file socket.c.

References CHECK_SOCKINIT, CHECK_SOCKMODE, CHECK_SOCKNUM, getSn_CR(), getSn_IR(), getSn_SR(), setSn_CR(), setSn_DIPR(), setSn_DPORT(), setSn_IR(), Sn_CR_CONNECT, Sn_IR_TIMEOUT, Sn_MR_TCP, SOCK_ESTABLISHED, SOCKERR_IPINVALID, SOCKERR_PORTZERO, SOCKERR_TIMEOUT, and SOCKOK_SUCC.

int8_t disconnect ( uint8_t  sn)

Disconnects the tcp socket 'sn' passed as parameter.

Returns
Success : SOCKOK_SUCC Fail : SOCKERR_NUM - Invalid socket number SOCKERR_SOCKMODE - Invalid operation in the socket SOCKERR_TIMEOUT - Timeout occurred

Definition at line 194 of file socket.c.

References CHECK_SOCKMODE, CHECK_SOCKNUM, close(), getSn_CR(), getSn_IR(), getSn_SR(), setSn_CR(), Sn_CR_DISCON, Sn_IR_TIMEOUT, Sn_MR_TCP, SOCK_CLOSED, SOCKERR_TIMEOUT, and SOCKOK_SUCC.

int32_t send ( uint8_t  sn,
uint8_t *  buf,
uint16_t  len 
)

Send data to the connected peer in TCP socket.

Returns
Success : The sent data size Fail : SOCKERR_NUM SOCKERR_SOCKMODE SOCKERR_DATALEN - zero data length SOCKERR_TIMEOUT

Definition at line 221 of file socket.c.

References CHECK_SOCKDATA, CHECK_SOCKMODE, CHECK_SOCKNUM, close(), getSn_CR(), getSn_IR(), getSn_SR(), getSn_TX_FSR(), getSn_TXBUF_SIZE(), setSn_CR(), setSn_IR(), Sn_CR_SEND, Sn_IR_SENDOK, Sn_IR_TIMEOUT, Sn_MR_TCP, SOCK_CLOSE_WAIT, SOCK_ESTABLISHED, SOCKERR_SOCKSTATUS, SOCKERR_TIMEOUT, and wiz_send_data().

int32_t recv ( uint8_t  sn,
uint8_t *  buf,
uint16_t  len 
)

Receive data from the connected peer. It waits for data as much as the application wants to receive.

Returns
Success : The received data size

Definition at line 267 of file socket.c.

References CHECK_SOCKDATA, CHECK_SOCKMODE, CHECK_SOCKNUM, close(), getSn_CR(), getSn_RX_RSR(), getSn_RXBUF_SIZE(), getSn_SR(), setSn_CR(), Sn_CR_RECV, Sn_MR_TCP, SOCK_CLOSE_WAIT, SOCK_ESTABLISHED, SOCKERR_SOCKSTATUS, and wiz_recv_data().

int32_t sendto ( uint8_t  sn,
uint8_t *  buf,
uint16_t  len,
uint8_t *  addr,
uint16_t  port 
)

Sends datagram to the peer has ip & port passed as parameter. return Success : The sent data size Fail : SOCKERR_SOCKNUM SOCKERR_SOCKMODE SOCKERR_SOCKSTATUS SOCKERR_DATALEN SOCKERR_IPINVALID SOCKERR_PORTZERO SOCKERR_SOCKCLOSED SOCKERR_TIMEOUT.

Definition at line 305 of file socket.c.

References CHECK_SOCKDATA, CHECK_SOCKNUM, getSn_CR(), getSn_IR(), getSn_MR(), getSn_SR(), getSn_TX_FSR(), getSn_TXBUF_SIZE(), setSn_CR(), setSn_DIPR(), setSn_DPORT(), setSn_IR(), Sn_CR_SEND, Sn_IR_SENDOK, Sn_IR_TIMEOUT, Sn_MR_MACRAW, Sn_MR_UDP, SOCK_CLOSED, SOCK_INIT, SOCK_UDP, SOCKERR_IPINVALID, SOCKERR_PORTZERO, SOCKERR_SOCKCLOSED, SOCKERR_SOCKMODE, SOCKERR_SOCKSTATUS, SOCKERR_TIMEOUT, and wiz_send_data().

int32_t recvfrom ( uint8_t  sn,
uint8_t *  buf,
uint16_t  len,
uint8_t *  addr,
uint16_t *  port 
)

This function is an application I/F function which is used to receive the data in other then TCP mode. This function is used to receive UDP, IP_RAW and MAC_RAW mode, and handle the header as well.

Returns
This function return received data size for success else -1.

Definition at line 360 of file socket.c.

References CHECK_SOCKDATA, CHECK_SOCKNUM, close(), getSn_CR(), getSn_MR(), getSn_RX_RSR(), getSn_SR(), setSn_CR(), Sn_CR_RECV, Sn_MR_MACRAW, Sn_MR_UDP, SOCK_CLOSED, SOCKERR_SOCKCLOSED, SOCKERR_SOCKMODE, SOCKFATAL_PACKLEN, and wiz_recv_data().