io6Library
WIZnet Dual Stack TCP/IP Ethernet Controller Driver
socket.h
Go to the documentation of this file.
1 //* ****************************************************************************
31 //*****************************************************************************
32 
74 #ifndef _SOCKET_H_
75 #define _SOCKET_H_
76 
77 #include "stdint.h"
78 #include "wizchip_conf.h"
79 
80 #define SOCKET uint8_t
81 
82 #define SOCK_OK 1
83 #define SOCK_BUSY 0
84 #define SOCK_FATAL (-1000)
85 
86 #define SOCK_ERROR 0
87 #define SOCKERR_SOCKNUM (SOCK_ERROR - 1)
88 #define SOCKERR_SOCKOPT (SOCK_ERROR - 2)
89 #define SOCKERR_SOCKINIT (SOCK_ERROR - 3)
90 #define SOCKERR_SOCKCLOSED (SOCK_ERROR - 4)
91 #define SOCKERR_SOCKMODE (SOCK_ERROR - 5)
92 #define SOCKERR_SOCKFLAG (SOCK_ERROR - 6)
93 #define SOCKERR_SOCKSTATUS (SOCK_ERROR - 7)
94 #define SOCKERR_ARG (SOCK_ERROR - 10)
95 #define SOCKERR_PORTZERO (SOCK_ERROR - 11)
96 #define SOCKERR_IPINVALID (SOCK_ERROR - 12)
97 #define SOCKERR_TIMEOUT (SOCK_ERROR - 13)
98 #define SOCKERR_DATALEN (SOCK_ERROR - 14)
99 #define SOCKERR_BUFFER (SOCK_ERROR - 15)
100 //#define SOCKERR_IPvMISMATCH (SOCK_ERROR - 16)
101 //#define SOCKERR_IPLENINVALID (SOCK_ERROR - 17)
102 
103 #define SOCKFATAL_PACKLEN (SOCK_FATAL - 1)
104 
105 /*
106  * - @ref Sn_MR_MULTI : Support UDP Multicasting
107  * - @ref Sn_MR_MF : Support MAC Filter Enable
108  * - @ref Sn_MR_BRDB : Broadcast Block
109  * - @ref Sn_MR_FPSH : Force PSH flag
110  * - @ref Sn_MR_ND : No Delay ACK flag
111  * - @ref Sn_MR_MC : IGMP ver2, ver1
112  * - @ref Sn_MR_SMB : Solicited Multicast Block
113  * - @ref Sn_MR_MMB : IPv4 Multicast block
114  * - @ref Sn_MR_UNIB : Unicast Block
115  * - @ref Sn_MR_MMB6 : IPv6 UDP Multicast Block </b>
116 
117  * - @ref Sn_MR2_DHAM : @ref Sn_MR2_DHAM_AUTO, @ref Sn_MR2_DHAM_MANUAL
118  * - @ref Sn_MR_FARP
119 */
120 
121 /*
122  * SOCKET FLAG
123  */
127 #define SF_MULTI_ENABLE (Sn_MR_MULTI)
128 #define SF_ETHER_OWN (Sn_MR_MF)
129 
130 
133 #define SF_BROAD_BLOCK (Sn_MR_BRDB)
134 #define SF_TCP_FPSH (Sn_MR_FPSH)
135 
136 #define SF_TCP_NODELAY (Sn_MR_ND)
137 #define SF_IGMP_VER2 (Sn_MR_MC)
138 #define SF_SOLICIT_BLOCK (Sn_MR_SMB)
139 #define SF_ETHER_MULTI4B (Sn_MR_MMB4)
140 
141 #define SF_UNI_BLOCK (Sn_MR_UNIB)
142 #define SF_ETHER_MULIT6B (Sn_MR_MMB6)
143 
144 
152 #define SF_FORCE_ARP (Sn_MR2_FARP)
153 
157 #define SF_DHA_MANUAL (Sn_MR2_DHAM)
158 
159 #define SF_IO_NONBLOCK (0x01 << 3)
160 
161 /*
162  * UDP, IPRAW, MACRAW Packet Infomation
163  */
164 #define PACK_IPv6 (1<<7)
165 #define PACK_IPV6_ALLNODE (PACK_IPv6 | (1<<6))
166 #define PACK_IPV6_MULTI (PACK_IPv6 | (1<<5))
167 #define PACK_IPV6_LLA (PACK_IPv6 | (1<<4))
168 #define PACK_COMPLETED (1<<3)
169 #define PACK_REMAINED (1<<2)
170 #define PACK_FIRST (1<<1)
171 #define PACK_NONE (0x00)
172 
173 #define SRCV6_PREFER_AUTO (PSR_AUTO)
174 #define SRCV6_PREFER_LLA (PSR_LLA)
175 #define SRCV6_PREFER_GUA (PSR_GUA)
176 
177 #define TCPSOCK_MODE (Sn_ESR_TCPM)
178 #define TCPSOCK_OP (Sn_ESR_TCPOP)
179 #define TCPSOCK_SIP (Sn_ESR_IP6T)
180 
181 // SOCKET CONTROL & OPTION //
184 #define SOCK_IO_BLOCK 0
185 #define SOCK_IO_NONBLOCK 1
186 
187 
220 int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag);
221 
230 int8_t close(uint8_t sn);
231 
243 int8_t listen(uint8_t sn);
244 
267 int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port, uint8_t addrlen);
268 
269 
284 int8_t disconnect(uint8_t sn);
285 
304 datasize_t send(uint8_t sn, uint8_t * buf, datasize_t len);
305 
306 
326 datasize_t recv(uint8_t sn, uint8_t * buf, datasize_t len);
327 
328 
356 datasize_t sendto(uint8_t sn, uint8_t * buf, datasize_t len, uint8_t * addr, uint16_t port, uint8_t addrlen);
357 
390 datasize_t recvfrom(uint8_t sn, uint8_t * buf, datasize_t len, uint8_t * addr, uint16_t *port, uint8_t *addrlen);
391 
392 
393 
403 typedef enum
404 {
405  SIK_CONNECTED = (1 << 0),
406  SIK_DISCONNECTED = (1 << 1),
407  SIK_RECEIVED = (1 << 2),
408  SIK_TIMEOUT = (1 << 3),
409  SIK_SENT = (1 << 4),
410  SIK_ALL = 0x1F
411 }sockint_kind;
412 
417 typedef enum
418 {
429 }ctlsock_type;
430 
431 
436 typedef enum
437 {
453 }sockopt_type;
454 
480 int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg);
481 
508 int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg);
509 
541 int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg);
542 
560 int16_t peeksockmsg(uint8_t sn, uint8_t* submsg, uint16_t subsize);
561 
562 #endif // _SOCKET_H_
sendto
datasize_t sendto(uint8_t sn, uint8_t *buf, datasize_t len, uint8_t *addr, uint16_t port, uint8_t addrlen)
Send datagram to the peer specifed by destination IP address and port number passed as parameter.
Definition: socket.c:372
recv
datasize_t recv(uint8_t sn, uint8_t *buf, datasize_t len)
Receive data from the connected peer.
Definition: socket.c:338
socket
int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
Open a socket.
Definition: socket.c:101
SO_SENDBUF
@ SO_SENDBUF
Valid only in getsockopt(). Get the free data size of SOCKETn TX buffer. getSn_TX_FSR()
Definition: socket.h:446
SIK_RECEIVED
@ SIK_RECEIVED
data received
Definition: socket.h:407
connect
int8_t connect(uint8_t sn, uint8_t *addr, uint16_t port, uint8_t addrlen)
Try to connect to a TCP SERVER.
Definition: socket.c:219
SO_DESTPORT
@ SO_DESTPORT
Set/Get the destination Port number. To get it, SOCKETn should be TCP mode.
Definition: socket.h:443
setsockopt
int8_t setsockopt(uint8_t sn, sockopt_type sotype, void *arg)
Set SOCKETn options.
Definition: socket.c:576
SO_DESTIP
@ SO_DESTIP
Set/Get the destination IP address with argument wiz_IPAddress. To get it, SOCKETn should be TCP mode...
Definition: socket.h:442
CS_GET_MAXTXBUF
@ CS_GET_MAXTXBUF
get the size of SOCKET TX buffer allocated in TX memory
Definition: socket.h:421
SO_MSS
@ SO_MSS
Set/Get MSS. ( setSn_MSSR(), getSn_MSSR() )
Definition: socket.h:441
ctlsocket
int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void *arg)
Control SOCKETn.
Definition: socket.c:528
SO_RECVBUF
@ SO_RECVBUF
Valid only in getsockopt(). Get the received data size in SOCKETn RX buffer. getSn_RX_RSR()
Definition: socket.h:447
SO_EXTSTATUS
@ SO_EXTSTATUS
Valid only in getsockopt(). Get the extended TCP SOCKETn status. getSn_ESR()
Definition: socket.h:449
sockint_kind
sockint_kind
The kind of SOCKET Interrupt.
Definition: socket.h:403
CS_GET_INTMASK
@ CS_GET_INTMASK
get the masked interrupt of SOCKET. refer to sockint_kind.
Definition: socket.h:426
SO_MODE
@ SO_MODE
Definition: socket.h:451
sockopt_type
sockopt_type
The type of socket option in setsockopt() or getsockopt()
Definition: socket.h:436
CS_GET_INTERRUPT
@ CS_GET_INTERRUPT
get the SOCKET interrupt. refer to sockint_kind.
Definition: socket.h:424
SIK_ALL
@ SIK_ALL
all interrupt
Definition: socket.h:410
SO_REMAINSIZE
@ SO_REMAINSIZE
Valid only in getsockopt(). Get the remained packet size in non-TCP mode.
Definition: socket.h:450
CS_GET_IOMODE
@ CS_GET_IOMODE
get SOCKET IO mode
Definition: socket.h:420
SO_KEEPALIVESEND
@ SO_KEEPALIVESEND
Valid only in setsockopt(). Manually send keep-alive packet in TCP mode.
Definition: socket.h:444
CS_GET_MAXRXBUF
@ CS_GET_MAXRXBUF
get the size of SOCKET RX buffer allocated in RX memory
Definition: socket.h:422
CS_CLR_INTERRUPT
@ CS_CLR_INTERRUPT
clear the interrupt of SOCKET with sockint_kind.
Definition: socket.h:423
SIK_DISCONNECTED
@ SIK_DISCONNECTED
disconnected
Definition: socket.h:406
CS_SET_INTMASK
@ CS_SET_INTMASK
set the interrupt mask of SOCKET with sockint_kind.
Definition: socket.h:425
listen
int8_t listen(uint8_t sn)
Listen to a connection request from a TCP CLIENT.
Definition: socket.c:204
SO_TTL
@ SO_TTL
Set/Get TTL. ( setSn_TTLR(), getSn_TTLR() ) .
Definition: socket.h:439
CS_SET_PREFER
@ CS_SET_PREFER
set the preferred source IPv6 address of transmission packet. Refer to SRCV6_PREFER_AUTO,...
Definition: socket.h:427
SO_STATUS
@ SO_STATUS
Valid only in getsockopt(). Get the SOCKETn status. getSn_SR()
Definition: socket.h:448
ctlsock_type
ctlsock_type
The type of ctlsocket().
Definition: socket.h:417
SO_FLAG
@ SO_FLAG
Valid only in getsockopt(), For set flag of socket refer to flag in socket(). .
Definition: socket.h:438
CS_SET_IOMODE
@ CS_SET_IOMODE
set SOCKET IO mode with SOCK_IO_BLOCK or SOCK_IO_NONBLOCK
Definition: socket.h:419
SO_PACKINFO
@ SO_PACKINFO
Valid only in getsockopt(). Get the packet information as PACK_FIRST, PACK_REMAINED,...
Definition: socket.h:452
send
datasize_t send(uint8_t sn, uint8_t *buf, datasize_t len)
Send data to the connected peer.
Definition: socket.c:289
SIK_SENT
@ SIK_SENT
send ok
Definition: socket.h:409
close
int8_t close(uint8_t sn)
Close a SOCKET.
Definition: socket.c:186
SIK_CONNECTED
@ SIK_CONNECTED
connected
Definition: socket.h:405
getsockopt
int8_t getsockopt(uint8_t sn, sockopt_type sotype, void *arg)
get SOCKETn options
Definition: socket.c:620
SO_KEEPALIVEAUTO
@ SO_KEEPALIVEAUTO
Set/Get keep-alive auto transmission timer in TCP mode.
Definition: socket.h:445
CS_GET_PREFER
@ CS_GET_PREFER
get the preferred source IPv6 address of transmission packet. Refer to SRCV6_PREFER_AUTO,...
Definition: socket.h:428
SIK_TIMEOUT
@ SIK_TIMEOUT
timeout occurred
Definition: socket.h:408
SO_TOS
@ SO_TOS
Set/Get TOS. ( setSn_TOSR(), getSn_TOSR() )
Definition: socket.h:440
disconnect
int8_t disconnect(uint8_t sn)
Try to disconnect to the connected peer.
Definition: socket.c:266
wizchip_conf.h
WIZCHIP Config Header File.
peeksockmsg
int16_t peeksockmsg(uint8_t sn, uint8_t *submsg, uint16_t subsize)
Peeks a sub-message in SOCKETn RX buffer.
Definition: socket.c:689
recvfrom
datasize_t recvfrom(uint8_t sn, uint8_t *buf, datasize_t len, uint8_t *addr, uint16_t *port, uint8_t *addrlen)
Receive datagram from a peer.
Definition: socket.c:441