#ifndef _SOCKET_H_ #define _SOCKET_H_ #ifdef __cplusplus extern "C" { #endif #include "wizchip_conf.h" #define SOCKET uint8_t #define SOCK_OK 1 #define SOCK_BUSY 0 #define SOCK_FATAL -1000 #define SOCK_ERROR 0 #define SOCKERR_SOCKNUM (SOCK_ERROR - 1) #define SOCKERR_SOCKOPT (SOCK_ERROR - 2) #define SOCKERR_SOCKINIT (SOCK_ERROR - 3) #define SOCKERR_SOCKCLOSED (SOCK_ERROR - 4) #define SOCKERR_SOCKMODE (SOCK_ERROR - 5) #define SOCKERR_SOCKFLAG (SOCK_ERROR - 6) #define SOCKERR_SOCKSTATUS (SOCK_ERROR - 7) #define SOCKERR_ARG (SOCK_ERROR - 10) #define SOCKERR_PORTZERO (SOCK_ERROR - 11) #define SOCKERR_IPINVALID (SOCK_ERROR - 12) #define SOCKERR_TIMEOUT (SOCK_ERROR - 13) #define SOCKERR_DATALEN (SOCK_ERROR - 14) #define SOCKERR_BUFFER (SOCK_ERROR - 15) #define SOCKFATAL_PACKLEN (SOCK_FATAL - 1) #define SF_MULTI_ENABLE (Sn_MR_MULTI) #define SF_ETHER_OWN (Sn_MR_MF) #define SF_BROAD_BLOCK (Sn_MR_BRDB) #define SF_TCP_FPSH (Sn_MR_FPSH) #define SF_TCP_NODELAY (Sn_MR_ND) #define SF_IGMP_VER2 (Sn_MR_MC) #define SF_SOLICIT_BLOCK (Sn_MR_SMB) #define SF_ETHER_MULTI4B (Sn_MR_MMB4) #define SF_UNI_BLOCK (Sn_MR_UNIB) #define SF_ETHER_MULIT6B (Sn_MR_MMB6) #define SF_FORCE_ARP (Sn_MR2_FARP) #define SF_DHA_MANUAL (Sn_MR2_DHAM) #define SF_IO_NONBLOCK (0x01 << 3) #define PACK_IPv6 (1<<7) #define PACK_IPV6_ALLNODE (PACK_IPv6 | (1<<6)) #define PACK_IPV6_MULTI (PACK_IPv6 | (1<<5)) #define PACK_IPV6_LLA (PACK_IPv6 | (1<<4)) #define PACK_COMPLETED (1<<3) #define PACK_REMAINED (1<<2) #define PACK_FIRST (1<<1) #define PACK_NONE (0x00) #define SRCV6_PREFER_AUTO (PSR_AUTO) #define SRCV6_PREFER_LLA (PSR_LLA) #define SRCV6_PREFER_GUA (PSR_GUA) #define TCPSOCK_MODE (Sn_ESR_TCPM) #define TCPSOCK_OP (Sn_ESR_TCPOP) #define TCPSOCK_SIP (Sn_ESR_IP6T) #define SOCK_IO_BLOCK 0 #define SOCK_IO_NONBLOCK 1 int8_t socket(uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag); int8_t close(uint8_t sn); int8_t listen(uint8_t sn); int8_t disconnect(uint8_t sn); int32_t send(uint8_t sn, uint8_t * buf, uint16_t len); int32_t recv(uint8_t sn, uint8_t * buf, uint16_t len); typedef enum { SIK_CONNECTED = (1 << 0), SIK_DISCONNECTED = (1 << 1), SIK_RECEIVED = (1 << 2), SIK_TIMEOUT = (1 << 3), SIK_SENT = (1 << 4), SIK_ALL = 0x1F } sockint_kind; typedef enum { CS_SET_IOMODE, CS_GET_IOMODE, CS_GET_MAXTXBUF, CS_GET_MAXRXBUF, CS_CLR_INTERRUPT, CS_GET_INTERRUPT, CS_SET_PREFER, CS_GET_PREFER, CS_SET_INTMASK, CS_GET_INTMASK } ctlsock_type; typedef enum { SO_FLAG, SO_TTL, SO_TOS, SO_MSS, SO_DESTIP, SO_DESTPORT, SO_KEEPALIVESEND, SO_KEEPALIVEAUTO, SO_SENDBUF, SO_RECVBUF, SO_STATUS, SO_EXTSTATUS, SO_MODE, SO_REMAINSIZE, SO_PACKINFO } sockopt_type; int8_t ctlsocket(uint8_t sn, ctlsock_type cstype, void* arg); int8_t setsockopt(uint8_t sn, sockopt_type sotype, void* arg); int8_t getsockopt(uint8_t sn, sockopt_type sotype, void* arg); int16_t peeksockmsg(uint8_t sn, uint8_t* submsg, uint16_t subsize); int8_t connect_W6x00(uint8_t sn, uint8_t * addr, uint16_t port, uint8_t addrlen); int32_t sendto_W6x00(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port, uint8_t addrlen); int32_t recvfrom_W6x00(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t *port, uint8_t *addrlen); #define connect(sn, addr, port, addrlen) connect_W6x00(sn, addr, port, addrlen) #define sendto(sn, buf, len, addr, port, addrlen) sendto_W6x00(sn, buf, len, addr, port, addrlen) #define recvfrom(sn, buf, len, addr, port, addrlen) recvfrom_W6x00(sn, buf, len, addr, port, addrlen) #ifdef __cplusplus } #endif #endif