Socket APIs: Ethernet/socket.h Source File

Wiznet Socket API

socket.h
Go to the documentation of this file.
1 //*****************************************************************************
2 //
47 //
48 //*****************************************************************************
85 #ifndef _SOCKET_H_
86 #define _SOCKET_H_
87 
88 #include "wizchip_conf.h"
89 
90 #define SOCKET uint8_t
91 
92 #define SOCK_OK 1
93 #define SOCK_BUSY 0
94 #define SOCK_FATAL -1000
95 
96 #define SOCK_ERROR 0
97 #define SOCKERR_SOCKNUM (SOCK_ERROR - 1)
98 #define SOCKERR_SOCKOPT (SOCK_ERROR - 2)
99 #define SOCKERR_SOCKINIT (SOCK_ERROR - 3)
100 #define SOCKERR_SOCKCLOSED (SOCK_ERROR - 4)
101 #define SOCKERR_SOCKMODE (SOCK_ERROR - 5)
102 #define SOCKERR_SOCKFLAG (SOCK_ERROR - 6)
103 #define SOCKERR_SOCKSTATUS (SOCK_ERROR - 7)
104 #define SOCKERR_ARG (SOCK_ERROR - 10)
105 #define SOCKERR_PORTZERO (SOCK_ERROR - 11)
106 #define SOCKERR_IPINVALID (SOCK_ERROR - 12)
107 #define SOCKERR_TIMEOUT (SOCK_ERROR - 13)
108 #define SOCKERR_DATALEN (SOCK_ERROR - 14)
109 #define SOCKERR_BUFFER (SOCK_ERROR - 15)
110 
111 #define SOCKFATAL_PACKLEN (SOCK_FATAL - 1)
112 
113 /*
114  * SOCKET FLAG
115  */
116 #define SF_ETHER_OWN (Sn_MR_MFEN)
117 #define SF_IGMP_VER2 (Sn_MR_MC)
118 #define SF_TCP_NODELAY (Sn_MR_ND)
119 #define SF_MULTI_ENABLE (Sn_MR_MULTI)
120 
121 #if _WIZCHIP_ == 5500
122  #define SF_BROAD_BLOCK (Sn_MR_BCASTB)
123  #define SF_MULTI_BLOCK (Sn_MR_MMB)
124  #define SF_IPv6_BLOCK (Sn_MR_MIP6B)
125  #define SF_UNI_BLOCK (Sn_MR_UCASTB)
126 #endif
127 
128 //A201505 : For W5300
129 #if _WIZCHIP_ == 5300
130  #define SF_TCP_ALIGN 0x02
131 #endif
132 
133 #define SF_IO_NONBLOCK 0x01
134 
135 /*
136  * UDP & MACRAW Packet Infomation
137  */
138 #define PACK_FIRST 0x80
139 #define PACK_REMAINED 0x01
140 #define PACK_COMPLETED 0x00
141 //A20150601 : For Integrating with W5300
142 #define PACK_FIFOBYTE 0x02
143 //
144 
162 int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag);
163 
174 int8_t close(uint8_t sn);
175 
187 int8_t listen(uint8_t sn);
188 
210 int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port);
211 
227 int8_t disconnect(uint8_t sn);
228 
247 int32_t send(uint8_t sn, uint8_t * buf, uint16_t len);
248 
269 int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len);
270 
297 int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port);
298 
327 int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port);
328 
329 
331 // SOCKET CONTROL & OPTION //
333 #define SOCK_IO_BLOCK 0
334 #define SOCK_IO_NONBLOCK 1
335 
336 
345 typedef enum
346 {
347  SIK_CONNECTED = (1 << 0),
348  SIK_DISCONNECTED = (1 << 1),
349  SIK_RECEIVED = (1 << 2),
350  SIK_TIMEOUT = (1 << 3),
351  SIK_SENT = (1 << 4),
352  //M20150410 : Remove the comma of last member
353  //SIK_ALL = 0x1F, ///< all interrupt
354  SIK_ALL = 0x1F
355 }sockint_kind;
356 
361 typedef enum
362 {
369 #if _WIZCHIP_ > 5100
372 #endif
373 }ctlsock_type;
374 
375 
380 typedef enum
381 {
388 #if _WIZCHIP_ != 5100
390  #if _WIZCHIP_ > 5200
392  #endif
393 #endif
399 }sockopt_type;
400 
418 int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg);
419 
446 int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg);
447 
480 int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg);
481 
482 #endif // _SOCKET_H_
Set/Get keep-alive auto transmission timer in TCP mode, Not supported in W5100, W5200.
Definition: socket.h:391
Valid only in getsockopt. Get the socket status. Sn_SR, getSn_SR()
Definition: socket.h:396
Set TTL. Sn_TTL ( setSn_TTL(), getSn_TTL() )
Definition: socket.h:383
int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void *arg)
Control socket.
Definition: socket.c:764
Valid only in getsockopt. Get the remained packet size in other then TCP mode.
Definition: socket.h:397
get the size of socket buffer allocated in TX memory
Definition: socket.h:365
connected
Definition: socket.h:347
send ok
Definition: socket.h:351
sockint_kind
The kind of Socket Interrupt.
Definition: socket.h:345
data received
Definition: socket.h:349
Valid only in setsockopt. Manually send keep-alive packet in TCP mode, Not supported in W5100...
Definition: socket.h:389
int8_t getsockopt(uint8_t sn, sockopt_type sotype, void *arg)
get socket options
Definition: socket.c:863
ctlsock_type
The type of ctlsocket().
Definition: socket.h:361
int8_t close(uint8_t sn)
Close a socket.
Definition: socket.c:197
Set MSS. Sn_MSSR ( setSn_MSSR(), getSn_MSSR() )
Definition: socket.h:385
get the masked interrupt of socket. refer to sockint_kind, Not supported in W5100 ...
Definition: socket.h:371
all interrupt
Definition: socket.h:354
get the socket interrupt. refer to sockint_kind
Definition: socket.h:368
disconnected
Definition: socket.h:348
int32_t recv(uint8_t sn, uint8_t *buf, uint16_t len)
Receive data from the connected peer.
Definition: socket.c:387
Valid only in getsockopt. Get the free data size of Socekt TX buffer. Sn_TX_FSR, getSn_TX_FSR() ...
Definition: socket.h:394
Set the destination Port number. Sn_DPORT ( setSn_DPORT(), getSn_DPORT() )
Definition: socket.h:387
clear the interrupt of socket with sockint_kind
Definition: socket.h:367
Valid only in getsockopt(), For set flag of socket refer to flag in socket().
Definition: socket.h:382
Set TOS. Sn_TOS ( setSn_TOS(), getSn_TOS() )
Definition: socket.h:384
sockopt_type
The type of socket option in setsockopt() or getsockopt()
Definition: socket.h:380
int32_t sendto(uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t port)
Sends datagram to the peer with destination IP address and port number passed as parameter.
Definition: socket.c:492
set socket IO mode with SOCK_IO_BLOCK or SOCK_IO_NONBLOCK
Definition: socket.h:363
int8_t setsockopt(uint8_t sn, sockopt_type sotype, void *arg)
set socket options
Definition: socket.c:810
int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
Open a socket.
Definition: socket.c:105
int8_t disconnect(uint8_t sn)
Try to disconnect a connection socket.
Definition: socket.c:299
int32_t recvfrom(uint8_t sn, uint8_t *buf, uint16_t len, uint8_t *addr, uint16_t *port)
Receive datagram of UDP or MACRAW.
Definition: socket.c:588
Valid only in getsockopt. Get the packet information as PACK_FIRST, PACK_REMAINED, and PACK_COMPLETED in other then TCP mode.
Definition: socket.h:398
set the interrupt mask of socket with sockint_kind, Not supported in W5100
Definition: socket.h:370
int8_t listen(uint8_t sn)
Listen to a connection request from a client.
Definition: socket.c:240
get the size of socket buffer allocated in RX memory
Definition: socket.h:366
Valid only in getsockopt. Get the received data size in socket RX buffer. Sn_RX_RSR, getSn_RX_RSR()
Definition: socket.h:395
int8_t connect(uint8_t sn, uint8_t *addr, uint16_t port)
Try to connect a server.
Definition: socket.c:259
get socket IO mode
Definition: socket.h:364
WIZCHIP Config Header File.
timeout occurred
Definition: socket.h:350
int32_t send(uint8_t sn, uint8_t *buf, uint16_t len)
Send data to the connected peer in TCP socket.
Definition: socket.c:319
Set the destination IP address. Sn_DIPR ( setSn_DIPR(), getSn_DIPR() )
Definition: socket.h:386
Generated on Wed May 4 2016 16:43:58 for Socket APIs by   doxygen 1.8.9.1