Socket APIs
socket.h
Go to the documentation of this file.
1 //*****************************************************************************
2 //
43 //
44 //*****************************************************************************
81 #ifndef _SOCKET_H_
82 #define _SOCKET_H_
83 
84 #include "Ethernet/wizchip_conf.h"
85 
86 #define SOCKET uint8_t
87 
88 #define SOCK_OK 1
89 #define SOCK_BUSY 0
90 #define SOCK_FATAL -1000
91 
92 #define SOCK_ERROR 0
93 #define SOCKERR_SOCKNUM (SOCK_ERROR - 1)
94 #define SOCKERR_SOCKOPT (SOCK_ERROR - 2)
95 #define SOCKERR_SOCKINIT (SOCK_ERROR - 3)
96 #define SOCKERR_SOCKCLOSED (SOCK_ERROR - 4)
97 #define SOCKERR_SOCKMODE (SOCK_ERROR - 5)
98 #define SOCKERR_SOCKFLAG (SOCK_ERROR - 6)
99 #define SOCKERR_SOCKSTATUS (SOCK_ERROR - 7)
100 #define SOCKERR_ARG (SOCK_ERROR - 10)
101 #define SOCKERR_PORTZERO (SOCK_ERROR - 11)
102 #define SOCKERR_IPINVALID (SOCK_ERROR - 12)
103 #define SOCKERR_TIMEOUT (SOCK_ERROR - 13)
104 #define SOCKERR_DATALEN (SOCK_ERROR - 14)
105 #define SOCKERR_BUFFER (SOCK_ERROR - 15)
106 
107 #define SOCKFATAL_PACKLEN (SOCK_FATAL - 1)
108 
109 /*
110  * SOCKET FLAG
111  */
112 #define SF_ETHER_OWN (Sn_MR_MFEN)
113 #define SF_IGMP_VER2 (Sn_MR_MC)
114 #define SF_TCP_NODELAY (Sn_MR_ND)
115 #define SF_MULTI_ENABLE (Sn_MR_MULTI)
116 
117 #if _WIZCHIP_ == 5500
118  #define SF_BROAD_BLOCK (Sn_MR_BCASTB)
119  #define SF_MULTI_BLOCK (Sn_MR_MMB)
120  #define SF_IPv6_BLOCK (Sn_MR_MIP6B)
121  #define SF_UNI_BLOCK (Sn_MR_UCASTB)
122 #endif
123 
124 #define SF_IO_NONBLOCK 0x01
125 
126 /*
127  * UDP & MACRAW Packet Infomation
128  */
129 #define PACK_FIRST 0x80
130 #define PACK_REMAINED 0x01
131 #define PACK_COMPLETED 0x00
132 
133 
150 int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag);
151 
162 int8_t close(uint8_t sn);
163 
175 int8_t listen(uint8_t sn);
176 
198 int8_t connect(uint8_t sn, uint8_t * addr, uint16_t port);
199 
215 int8_t disconnect(uint8_t sn);
216 
235 int32_t send(uint8_t sn, uint8_t * buf, uint16_t len);
236 
257 int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len);
258 
285 int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port);
286 
315 int32_t recvfrom(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port);
316 
317 
319 // SOCKET CONTROL & OPTION //
321 #define SOCK_IO_BLOCK 0
322 #define SOCK_IO_NONBLOCK 1
323 
324 
333 typedef enum
334 {
335  SIK_CONNECTED = (1 << 0),
336  SIK_DISCONNECTED = (1 << 1),
337  SIK_RECEIVED = (1 << 2),
338  SIK_TIMEOUT = (1 << 3),
339  SIK_SENT = (1 << 4),
340  SIK_ALL = 0x1F,
341 }sockint_kind;
342 
347 typedef enum
348 {
357 }ctlsock_type;
358 
359 
364 typedef enum
365 {
372 #if _WIZCHIP_ != 5100
374  #if _WIZCHIP_ > 5200
375  SO_KEEPALIVEAUTO,
376  #endif
377 #endif
383 }sockopt_type;
384 
402 int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg);
403 
430 int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg);
431 
464 int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg);
465 
466 #endif // _SOCKET_H_