io6Library
WIZnet Dual Stack TCP/IP Ethernet Controller Driver
Macros | Functions
socket.c File Reference

SOCKET APIs Implements file. More...

#include <stdio.h>
#include "socket.h"
#include "w6100.h"

Go to the source code of this file.

Macros

#define SOCK_ANY_PORT_NUM   0x0400
 
#define CHECK_SOCKNUM()
 
#define CHECK_SOCKMODE(mode)
 
#define CHECK_TCPMODE()
 
#define CHECK_UDPMODE()
 
#define CHECK_IPMODE()
 
#define CHECK_DGRAMMODE()
 
#define CHECK_SOCKINIT()
 
#define CHECK_SOCKDATA()
 
#define CHECK_IPZERO(addr, addrlen)
 

Functions

int8_t socket (uint8_t sn, uint8_t protocol, uint16_t port, uint8_t flag)
 Open a socket. More...
 
int8_t close (uint8_t sn)
 Close a SOCKET. More...
 
int8_t listen (uint8_t sn)
 Listen to a connection request from a TCP CLIENT. More...
 
int8_t connect (uint8_t sn, uint8_t *addr, uint16_t port, uint8_t addrlen)
 Try to connect to a TCP SERVER. More...
 
int8_t disconnect (uint8_t sn)
 Try to disconnect to the connected peer. More...
 
datasize_t send (uint8_t sn, uint8_t *buf, datasize_t len)
 Send data to the connected peer. More...
 
datasize_t recv (uint8_t sn, uint8_t *buf, datasize_t len)
 Receive data from the connected peer. More...
 
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. More...
 
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. More...
 
int8_t ctlsocket (uint8_t sn, ctlsock_type cstype, void *arg)
 Control SOCKETn. More...
 
int8_t setsockopt (uint8_t sn, sockopt_type sotype, void *arg)
 Set SOCKETn options. More...
 
int8_t getsockopt (uint8_t sn, sockopt_type sotype, void *arg)
 get SOCKETn options More...
 
int16_t peeksockmsg (uint8_t sn, uint8_t *submsg, uint16_t subsize)
 Peeks a sub-message in SOCKETn RX buffer. More...
 

Detailed Description

SOCKET APIs Implements file.

SOCKET APIs like as Berkeley Socket APIs.

Version
1.0.1
Date
2020/04/27
Revision history
<2020/04/27> V1.0.1 Modify default value of tcmd to Sn_CR_SEND to send data in macrawmode and the condition of the if()when setting the destination port number. <2019/01/01> 1st Release
Author
MidnightCow

Copyright (c) 2019, WIZnet Co., LTD.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file socket.c.

Macro Definition Documentation

◆ SOCK_ANY_PORT_NUM

#define SOCK_ANY_PORT_NUM   0x0400

Definition at line 41 of file socket.c.

◆ CHECK_SOCKNUM

#define CHECK_SOCKNUM ( )
Value:
do{ \
if(sn >= _WIZCHIP_SOCK_NUM_) return SOCKERR_SOCKNUM; \
}while(0);

Definition at line 50 of file socket.c.

◆ CHECK_SOCKMODE

#define CHECK_SOCKMODE (   mode)
Value:
do{ \
if((getSn_MR(sn) & 0x0F) != mode) return SOCKERR_SOCKMODE; \
}while(0);

Definition at line 55 of file socket.c.

◆ CHECK_TCPMODE

#define CHECK_TCPMODE ( )
Value:
do{ \
if((getSn_MR(sn) & 0x03) != 0x01) return SOCKERR_SOCKMODE; \
}while(0);

Definition at line 60 of file socket.c.

◆ CHECK_UDPMODE

#define CHECK_UDPMODE ( )
Value:
do{ \
if((getSn_MR(sn) & 0x03) != 0x02) return SOCKERR_SOCKMODE; \
}while(0);

Definition at line 65 of file socket.c.

◆ CHECK_IPMODE

#define CHECK_IPMODE ( )
Value:
do{ \
if((getSn_MR(sn) & 0x07) != 0x03) return SOCKERR_SOCKMODE; \
}while(0);

Definition at line 70 of file socket.c.

◆ CHECK_DGRAMMODE

#define CHECK_DGRAMMODE ( )
Value:
do{ \
if(getSn_MR(sn) == Sn_MR_CLOSED) return SOCKERR_SOCKMODE; \
if((getSn_MR(sn) & 0x03) == 0x01) return SOCKERR_SOCKMODE; \
}while(0);

Definition at line 75 of file socket.c.

◆ CHECK_SOCKINIT

#define CHECK_SOCKINIT ( )
Value:
do{ \
if((getSn_SR(sn) != SOCK_INIT)) return SOCKERR_SOCKINIT; \
}while(0);

Definition at line 82 of file socket.c.

◆ CHECK_SOCKDATA

#define CHECK_SOCKDATA ( )
Value:
do{ \
if(len == 0) return SOCKERR_DATALEN; \
}while(0);

Definition at line 87 of file socket.c.

◆ CHECK_IPZERO

#define CHECK_IPZERO (   addr,
  addrlen 
)
Value:
do{ \
uint16_t ipzero= 0; \
for(uint8_t i=0; i<addrlen; i++) ipzero += (uint16_t)addr[i]; \
if (ipzero == 0) return SOCKERR_IPINVALID; \
}while(0);

Definition at line 92 of file socket.c.

SOCKERR_SOCKINIT
#define SOCKERR_SOCKINIT
Socket is not initialized or SIPR is Zero IP address when Sn_MR_TCP.
Definition: socket.h:89
SOCK_INIT
#define SOCK_INIT
TCP SOCKETn initialized status.
Definition: w6100.h:2767
SOCKERR_IPINVALID
#define SOCKERR_IPINVALID
Invalid source or destination IP address.
Definition: socket.h:96
getSn_MR
#define getSn_MR(sn)
Definition: w6100.h:3812
_WIZCHIP_SOCK_NUM_
#define _WIZCHIP_SOCK_NUM_
Define I/O base address of _WIZCHIP_.
Definition: wizchip_conf.h:157
SOCKERR_DATALEN
#define SOCKERR_DATALEN
Invalid data length.
Definition: socket.h:98
SOCKERR_SOCKMODE
#define SOCKERR_SOCKMODE
Invalid socket mode for socket operation.
Definition: socket.h:91
SOCKERR_SOCKNUM
#define SOCKERR_SOCKNUM
Invalid socket number.
Definition: socket.h:87
getSn_SR
#define getSn_SR(sn)
Definition: w6100.h:3837