WIZlib Library API  ver 1.0
WIZlib Library API User Menual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions

Socket Interface. More...

Collaboration diagram for Socket:

Macros

#define SOCKSTAT_CLOSED   -1
 Indicate the socket is closed state. More...
 
#define SOCKSTAT_INIT   0
 Indicate the socket is init state. More...
 
#define SOCKSTAT_LISTEN   1
 Indicate the socket is listen state. More...
 
#define SOCKSTAT_SYNSENT   2
 Indicate the socket is syn-sent state (momentary state). More...
 
#define SOCKSTAT_SYNRECV   3
 Indicate the socket is syn-received state (momentary state). More...
 
#define SOCKSTAT_ESTABLISHED   4
 Indicate the socket is established state. More...
 
#define SOCKSTAT_FIN_WAIT   5
 Indicate the socket is finish-wait state (momentary state). More...
 
#define SOCKSTAT_CLOSING   6
 Indicate the socket is closing state (momentary state). More...
 
#define SOCKSTAT_TIME_WAIT   7
 Indicate the socket is time-wait state (momentary state). More...
 
#define SOCKSTAT_CLOSE_WAIT   8
 Indicate the socket is close-wait state (momentary state). More...
 
#define SOCKSTAT_LAST_ACK   9
 Indicate the socket is last-ack state (momentary state). More...
 
#define SOCKSTAT_UDP   10
 Indicate the socket is opened as UDP. More...
 
#define SOCKERR_BUSY   -1
 Error because the socket is busy.
 
#define SOCKERR_NOT_TCP   -2
 Error because the socket is not opened as TCP.
 
#define SOCKERR_NOT_UDP   -3
 Error because the socket is not opened as UDP.
 
#define SOCKERR_WRONG_ARG   -4
 Error because the parameter is wrong.
 
#define SOCKERR_WRONG_STATUS   -5
 Error because the socket is unknown state.
 
#define SOCKERR_CLOSED   -6
 Error because the socket is closed state.
 
#define SOCKERR_CLOSE_WAIT   -7
 Error because the socket is close wait state.
 
#define SOCKERR_FIN_WAIT   -8
 Error because the socket is fin wait state.
 
#define SOCKERR_NOT_ESTABLISHED   -9
 Error because the socket is not established state.
 
#define SOCKERR_WINDOW_FULL   -10
 Error because of network window full.
 
#define SOCKERR_TIME_OUT   -11
 Error because of time out.
 
#define SOCKERR_NULL_SRC_IP   -12
 Error because source IP is wrong.
 
#define SOCKERR_BUF_NOT_ENOUGH   -13
 Error because buffer is not enough.
 
#define SOCKERR_NOT_SPECIFIED   -14
 Error because of not specified reason.
 

Functions

int8 TCPServerOpen (uint8 s, uint16 port)
 Open a TCP server socket. More...
 
int8 TCPClientOpen (uint8 s, uint16 sport, uint8 *dip, uint16 dport)
 Open a TCP client socket. More...
 
int8 TCPCltOpenNB (uint8 s, uint16 sport, uint8 *dip, uint16 dport)
 Open a TCP client socket without blocking. More...
 
int8 TCPConnChk (uint8 s)
 Check if a TCP Socket is connected. More...
 
int8 TCPClose (uint8 s)
 Close a TCP socket. More...
 
int8 TCPCloseNB (uint8 s)
 Close a TCP socket without blocking. More...
 
int8 TCPCloseCHK (uint8 s)
 Check if a TCP Socket is closed. More...
 
int8 TCPClsRcvCHK (uint8 s)
 Check TCP Connection Close which is not intentional. More...
 
int32 TCPSend (uint8 s, const int8 *buf, uint16 len)
 Send the data in TCP mode. More...
 
int8 TCPSendNB (uint8 s, const int8 *buf, uint16 len)
 Send the data in TCP mode without blocking. More...
 
int32 TCPReSend (uint8 s)
 Re-Send the data in TCP mode. More...
 
int8 TCPReSendNB (uint8 s)
 Re-Send the data in TCP mode without blocking. More...
 
int32 TCPSendCHK (uint8 s)
 Check if TCP Send action completed. More...
 
int32 TCPRecv (uint8 s, int8 *buf, uint16 len)
 Receive the data in TCP mode. More...
 
int8 UDPOpen (uint8 s, uint16 port)
 Open a UDP socket. More...
 
int8 UDPClose (uint8 s)
 Close a UDP socket. More...
 
int32 UDPSend (uint8 s, const int8 *buf, uint16 len, uint8 *addr, uint16 port)
 Send the data in UDP mode. More...
 
int32 UDPSendNB (uint8 s, const int8 *buf, uint16 len, uint8 *addr, uint16 port)
 Send the data in UDP mode without blocking. More...
 
int8 UDPSendCHK (uint8 s)
 Check if UDP Send action completed. More...
 
int32 UDPRecv (uint8 s, int8 *buf, uint16 len, uint8 *addr, uint16 *port)
 Receive the data in UDP mode. More...
 
int8 GetTCPSocketStatus (uint8 s)
 Get the TCP socket status. More...
 
int8 GetUDPSocketStatus (uint8 s)
 Get the UDP socket status. More...
 
uint16 GetSocketTxFreeBufferSize (uint8 s)
 Get the TX free buffer size. More...
 
uint16 GetSocketRxRecvBufferSize (uint8 s)
 Get the RX recv buffer size. More...
 
void GetDstInfo (uint8 s, uint8 *dstip, uint16 *dstport)
 Get Destination Information. More...
 
void SetSocketOption (uint8 option_type, uint16 option_value)
 Set the network option. More...
 

Detailed Description

Socket Interface.

Macro Definition Documentation

#define SOCKSTAT_CLOSE_WAIT   8

Indicate the socket is close-wait state (momentary state).

It is the status that disconnect-request (FIN packet) is received
from the peer As TCP connection is half-closed, it is possible
to transfer data packet. In order to complete the TCP disconnection,
DISCON command should be performed.
For SOCKETn close without disconnection-process, CLOSE
command should be just performed.

#define SOCKSTAT_CLOSED   -1

Indicate the socket is closed state.

It is the status that resource of SOCKETn is released.
When DISCON or CLOSE command is performed, or ARPTO, or TCPTO occurs,
it is changed to SOCK_CLOSED regardless of previous value.

#define SOCKSTAT_CLOSING   6

Indicate the socket is closing state (momentary state).

These status shows that Socket n is closed. It is observed
in the disconnect-process of active close or passive close.
It is changed to SOCK_CLOSED, when disconnect-process is
successfully finished or TCPTO occurs (Sn_IR (TIMEOUT) ='1').

#define SOCKSTAT_ESTABLISHED   4

Indicate the socket is established state.

It is shown in case that connection is established.
It is changed to SOCK_ESTABLISHED when SYN packet from
"TCP CLIENT" is successfully processed at the SOCK_LISTEN, or
CONNECTS command is successfully performed. At this status,
DATA packet can be transferred, that is, SEND or RECV command
can be performed.

#define SOCKSTAT_FIN_WAIT   5

Indicate the socket is finish-wait state (momentary state).

These status shows that Socket n is closed. It is observed
in the disconnect-process of active close or passive close.
It is changed to SOCK_CLOSED, when disconnect-process is
successfully finished or TCPTO occurs (Sn_IR (TIMEOUT)='1').

#define SOCKSTAT_INIT   0

Indicate the socket is init state.

It is shown in case that Sn_MR is set as TCP and OPEN
commands are given to Sn_CR. It is changed to SOCK_INIT
when Sn_MR (P3:P0) is Sn_MR_TCP and OPEN command is
performed. It is the initial step of TCP connection establishment.
It is possible to perform LISTEN command at the "TCP SERVER"
mode and CONNECT command at the "TCP CLIENT".
It is the status that SOCKETn operates as "TCP SERVER" and
waits for connect-request (SYN packet) from "TCP CLIENT".

#define SOCKSTAT_LAST_ACK   9

Indicate the socket is last-ack state (momentary state).

These status shows that Socket n is closed. It is observed
in the disconnect-process of active close or passive close.
It is changed to SOCK_CLOSED, when disconnect-process
is successfully finished or TCPTO occurs (Sn_IR (TIMEOUT)='1').

#define SOCKSTAT_LISTEN   1

Indicate the socket is listen state.

Socket n operates in TCP Server Mode and waits for a
connection-request (SYN packet) from a “TCP CLIENT”.
When the LISTEN command is used, the stage changes to SOCK_LISTEN
Once the connection is established, the SOCKET state
changes from SOCK_LISTEN to SOCK_ESTABLISHED; however,
if the connection fails, TCPTO occurs (Sn_IR(TIME_OUT) ='1') and
the state changes to SOCK_CLOSED.

#define SOCKSTAT_SYNRECV   3

Indicate the socket is syn-received state (momentary state).

This status indicate that a connect-request(SYN packet) is
received from a "TCP CLIENT". It is automatically changed
to SOCK_ESTABLISHED when W5200 successfully transmits
connect-accept (SYN/ACK packet) to the "TCP CLIENT".
If it is failed, TCPTO occurs (Sn_IR(TIMEOUT)=‘1’),
and it is changed to SOCK_CLOSED

#define SOCKSTAT_SYNSENT   2

Indicate the socket is syn-sent state (momentary state).


This status indicates that a connect-request (SYN packet) is
sent to a "TCP SERVER". This status shows changing process
from SOCK_INIT to SOCK_ESTABLISHED by CONNECT
command. At this status, if connect-accept (SYN/ACK packet)
is received from "TCP SERVER", it is automatically
changed to SOCK_ ESTBLISHED. If SYN/ACK packet is not
received from the "TCP SERVER" before TCPTO occurs
(Sn_IR(TIMEOUT)=‘1’), it is changed to SOCK_CLOSED.

#define SOCKSTAT_TIME_WAIT   7

Indicate the socket is time-wait state (momentary state).

These status shows that Socket n is closed. It is oserved
in the disconnect-process of active close or passive close. It
is changed to SOCK_CLOSED, when disconnect-process is
successfully finished or TCPTO occurs (Sn_IR (TIMEOUT)='1').

#define SOCKSTAT_UDP   10

Indicate the socket is opened as UDP.

It is the status that SOCKETn is open as UDP mode. It is
changed to SOCK_UDP when Sn_MR(P3:P0) is Sn_MR_UDP
and OPEN command is performed. DATA packet can be
transferred without connection that is necessary to TCP mode SOCKET.

Function Documentation

void GetDstInfo ( uint8  s,
uint8 *  dstip,
uint16 *  dstport 
)

Get Destination Information.

When connected with remote through TCP or received packet through UDP,
You can get the destination IP Address and Port by using this.

Parameters
sThe socket number to get address
dstipThe array pointer in which IP address will enter
dstportThe variable pointer in which Port number will enter

Definition at line 158 of file w5200/socket.c.

uint16 GetSocketRxRecvBufferSize ( uint8  s)

Get the RX recv buffer size.

Parameters
sThe socket number you want to get
Returns
size of RX recv buffer

Definition at line 234 of file w5200/socket.c.

Here is the caller graph for this function:

uint16 GetSocketTxFreeBufferSize ( uint8  s)

Get the TX free buffer size.

Parameters
sThe socket number you want to get
Returns
size of TX free buffer

Definition at line 229 of file w5200/socket.c.

Here is the caller graph for this function:

int8 GetTCPSocketStatus ( uint8  s)

Get the TCP socket status.

Parameters
sThe socket number you want to get
Returns
TCP socket status

Definition at line 181 of file w5200/socket.c.

Here is the caller graph for this function:

int8 GetUDPSocketStatus ( uint8  s)

Get the UDP socket status.

Parameters
sThe socket number you want to get
Returns
UDP socket status

Definition at line 207 of file w5200/socket.c.

void SetSocketOption ( uint8  option_type,
uint16  option_value 
)

Set the network option.

Parameters
option_type
  • 0: RTR(Retry Time Register)
  • 1: RCR(Retry Count Register)
  • 2: IMR(Interrupt Mask Register)
option_valueThe value you want to set

Definition at line 164 of file w5200/socket.c.

int8 TCPClientOpen ( uint8  s,
uint16  sport,
uint8 *  dip,
uint16  dport 
)

Open a TCP client socket.

Parameters
sThe socket number you want to open
sportThe source port number you want to open
dipDestination IP Address
dportDestination Port Number
Returns
RET_OK: Success
<0: Error

Definition at line 271 of file w5200/socket.c.

Here is the caller graph for this function:

int8 TCPClose ( uint8  s)

Close a TCP socket.

Parameters
sThe socket number you want to close
Returns
RET_OK: Success
<0: Error

Definition at line 366 of file w5200/socket.c.

Here is the caller graph for this function:

int8 TCPCloseCHK ( uint8  s)

Check if a TCP Socket is closed.

  • This is used for check when using None-Blocking functions.
  • Wait for a few seconds to be closed after TCPCloseNB is called.
    If not closed after wait, close the connection by force.
Parameters
sThe socket number you want to check
Returns
RET_OK: Closed
SOCKERR_BUSY: Not Closed yet
<0: Error

Definition at line 400 of file w5200/socket.c.

Here is the caller graph for this function:

int8 TCPCloseNB ( uint8  s)

Close a TCP socket without blocking.

  • None-Blocking function.
  • To use this, sockwatch_run should be run in main loop.
Parameters
sThe socket number you want to close
Returns
RET_OK: Success
<0: Error

Definition at line 381 of file w5200/socket.c.

Here is the caller graph for this function:

int8 TCPClsRcvCHK ( uint8  s)

Check TCP Connection Close which is not intentional.

  • This is used for check when using None-Blocking functions.
Parameters
sThe socket number you want to check
Returns
RET_OK: Closed
SOCKERR_BUSY: Not Closed
<0: Error

Definition at line 423 of file w5200/socket.c.

Here is the caller graph for this function:

int8 TCPCltOpenNB ( uint8  s,
uint16  sport,
uint8 *  dip,
uint16  dport 
)

Open a TCP client socket without blocking.

  • None-Blocking function.
  • To use this, sockwatch_run should be run in main loop.
Parameters
sThe socket number you want to open
sportThe source port number you want to open
dipDestination IP Address
dportDestination Port Number
Returns
RET_OK: Success
<0: Error

Definition at line 286 of file w5200/socket.c.

Here is the caller graph for this function:

int8 TCPConnChk ( uint8  s)

Check if a TCP Socket is connected.

  • This is used for check when using None-Blocking functions.
Parameters
sThe socket number you want to check
Returns
RET_OK: Connected
SOCKERR_BUSY: Not Connected yet
<0: Error

Definition at line 346 of file w5200/socket.c.

Here is the caller graph for this function:

int32 TCPRecv ( uint8  s,
int8 *  buf,
uint16  len 
)

Receive the data in TCP mode.

Parameters
sThe socket number you want to receive
bufThe data you want to receive
lenbuf size
Returns
>=0: Sent data length
<0: Error

Definition at line 564 of file w5200/socket.c.

Here is the caller graph for this function:

int32 TCPReSend ( uint8  s)

Re-Send the data in TCP mode.

You can use this when TCPSend could not send all of data.

Parameters
sThe socket number you want to send
Returns
>=0: Sent data length
<0: Error

Definition at line 496 of file w5200/socket.c.

Here is the caller graph for this function:

int8 TCPReSendNB ( uint8  s)

Re-Send the data in TCP mode without blocking.

You can use this when TCPSend could not send all of data.

  • None-Blocking function.
  • To use this, sockwatch_run should be run in main loop.
Parameters
sThe socket number you want to send
Returns
RET_OK: Success
<0: Error

Definition at line 514 of file w5200/socket.c.

Here is the caller graph for this function:

int32 TCPSend ( uint8  s,
const int8 *  buf,
uint16  len 
)

Send the data in TCP mode.

Parameters
sThe socket number you want to send
bufThe data you want to send
lenLength of the data to send
Returns
>=0: Sent data length
<0: Error

Definition at line 445 of file w5200/socket.c.

Here is the caller graph for this function:

int32 TCPSendCHK ( uint8  s)

Check if TCP Send action completed.

  • This is used for check when using None-Blocking functions.
Parameters
sThe socket number you want to check
Returns
SOCKERR_BUSY: Not Sent yet
>=0: Sent data length
<0: Error

Definition at line 544 of file w5200/socket.c.

Here is the caller graph for this function:

int8 TCPSendNB ( uint8  s,
const int8 *  buf,
uint16  len 
)

Send the data in TCP mode without blocking.

  • None-Blocking function.
  • To use this, sockwatch_run should be run in main loop.
Parameters
sThe socket number you want to send
bufThe data you want to send
lenLength of the data to send
Returns
RET_OK: Success
<0: Error

Definition at line 463 of file w5200/socket.c.

Here is the caller graph for this function:

int8 TCPServerOpen ( uint8  s,
uint16  port 
)

Open a TCP server socket.

Parameters
sThe socket number you want to open
portThe port number you want to open
Returns
RET_OK: Success
<0: Error

Definition at line 239 of file w5200/socket.c.

Here is the caller graph for this function:

int8 UDPClose ( uint8  s)

Close a UDP socket.

Parameters
sThe socket number you want to close
Returns
RET_OK: Success
<0: Error

Definition at line 618 of file w5200/socket.c.

Here is the caller graph for this function:

int8 UDPOpen ( uint8  s,
uint16  port 
)

Open a UDP socket.

Parameters
sThe socket number you want to open
portThe port number you want to open
Returns
RET_OK: Success
<0: Error

Definition at line 594 of file w5200/socket.c.

Here is the caller graph for this function:

int32 UDPRecv ( uint8  s,
int8 *  buf,
uint16  len,
uint8 *  addr,
uint16 *  port 
)

Receive the data in UDP mode.

Parameters
sThe socket number you want to receive
bufThe data you want to receive
lenbuf size
addrThe IP Address of peer
portThe Port Number of peer
Returns
>=0: Received data length
<0: Error

Definition at line 718 of file w5200/socket.c.

Here is the caller graph for this function:

int32 UDPSend ( uint8  s,
const int8 *  buf,
uint16  len,
uint8 *  addr,
uint16  port 
)

Send the data in UDP mode.

Parameters
sThe socket number you want to send
bufThe data you want to send
lenLength of the data to send
addrThe IP Address of peer
portThe Port Number of peer
Returns
>=0: Sent data length
<0: Error

Definition at line 632 of file w5200/socket.c.

Here is the caller graph for this function:

int8 UDPSendCHK ( uint8  s)

Check if UDP Send action completed.

  • This is used for check when using None-Blocking functions.
Parameters
sThe socket number you want to check
Returns
RET_OK: Sent
SOCKERR_BUSY: Not Sent yet
<0: Error

Definition at line 701 of file w5200/socket.c.

Here is the caller graph for this function:

int32 UDPSendNB ( uint8  s,
const int8 *  buf,
uint16  len,
uint8 *  addr,
uint16  port 
)

Send the data in UDP mode without blocking.

  • None-Blocking function.
  • To use this, sockwatch_run should be run in main loop.
Parameters
sThe socket number you want to send
bufThe data you want to send
lenLength of the data to send
addrThe IP Address of peer
portThe Port Number of peer
Returns
>=0: Sent data length
<0: Error

Definition at line 647 of file w5200/socket.c.

Here is the caller graph for this function: