Socket APIs
socket.h
Go to the documentation of this file.
1 //*****************************************************************************
2 //
40 //
41 //*****************************************************************************
78 #ifndef _SOCKET_H_
79 #define _SOCKET_H_
80 
81 #include "Ethernet/wizchip_conf.h"
82 
83 #define SOCKET uint8_t
84 
85 #define SOCK_OK 1
86 #define SOCK_BUSY 0
87 #define SOCK_FATAL -1000
88 
89 #define SOCK_ERROR 0
90 #define SOCKERR_SOCKNUM (SOCK_ERROR - 1)
91 #define SOCKERR_SOCKOPT (SOCK_ERROR - 2)
92 #define SOCKERR_SOCKINIT (SOCK_ERROR - 3)
93 #define SOCKERR_SOCKCLOSED (SOCK_ERROR - 4)
94 #define SOCKERR_SOCKMODE (SOCK_ERROR - 5)
95 #define SOCKERR_SOCKFLAG (SOCK_ERROR - 6)
96 #define SOCKERR_SOCKSTATUS (SOCK_ERROR - 7)
97 #define SOCKERR_ARG (SOCK_ERROR - 10)
98 #define SOCKERR_PORTZERO (SOCK_ERROR - 11)
99 #define SOCKERR_IPINVALID (SOCK_ERROR - 12)
100 #define SOCKERR_TIMEOUT (SOCK_ERROR - 13)
101 #define SOCKERR_DATALEN (SOCK_ERROR - 14)
102 #define SOCKERR_BUFFER (SOCK_ERROR - 15)
103 
104 #define SOCKFATAL_PACKLEN (SOCK_FATAL - 1)
105 
106 /*
107  * SOCKET FLAG
108  */
109 #define SF_ETHER_OWN (Sn_MR_MFEN)
110 #define SF_IGMP_VER2 (Sn_MR_MC)
111 #define SF_TCP_NODELAY (Sn_MR_ND)
112 #define SF_MULTI_ENABLE (Sn_MR_MULTI)
113 
114 #if _WIZCHIP_ == 5500
115  #define SF_BROAD_BLOCK (Sn_MR_BCASTB)
116  #define SF_MULTI_BLOCK (Sn_MR_MMB)
117  #define SF_IPv6_BLOCK (Sn_MR_MIP6B)
118  #define SF_UNI_BLOCK (Sn_MR_UCASTB)
119 #endif
120 
121 #define SF_IO_NONBLOCK 0x01
122 
123 /*
124  * UDP & MACRAW Packet Infomation
125  */
126 #define PACK_FIRST 0x80
127 #define PACK_REMAINED 0x01
128 #define PACK_COMPLETED 0x00
129 
130 
147 int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag);
148 
159 int8_t close(uint8_t sn);
160 
172 int8_t listen(uint8_t sn);
173 
195 int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port);
196 
212 int8_t disconnect(uint8_t sn);
213 
232 int32_t send(uint8_t sn, uint8_t * buf, uint16_t len);
233 
254 int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len);
255 
282 int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port);
283 
312 int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port);
313 
314 
316 // SOCKET CONTROL & OPTION //
318 #define SOCK_IO_BLOCK 0
319 #define SOCK_IO_NONBLOCK 1
320 
321 
330 typedef enum
331 {
332  SIK_CONNECTED = (1 << 0),
333  SIK_DISCONNECTED = (1 << 1),
334  SIK_RECEIVED = (1 << 2),
335  SIK_TIMEOUT = (1 << 3),
336  SIK_SENT = (1 << 4),
337  SIK_ALL = 0x1F,
338 }sockint_kind;
339 
344 typedef enum
345 {
354 }ctlsock_type;
355 
356 
361 typedef enum
362 {
369 #if _WIZCHIP_ != 5100
371  #if _WIZCHIP_ > 5200
372  SO_KEEPALIVEAUTO,
373  #endif
374 #endif
380 }sockopt_type;
381 
399 int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg);
400 
427 int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg);
428 
459 int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg);
460 
461 #endif // _SOCKET_H_