Ethernet for Nucleo and Disco board STM32F746 works with gcc and arm. IAC is untested

Dependents:   STM32F746_iothub_client_sample_mqtt DISCO-F746NG_Ethernet Nucleo_F746ZG_Ethernet thethingsiO-DISCO_F746NG-mqtt ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sockets.h Source File

sockets.h

00001 /*
00002  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without modification,
00006  * are permitted provided that the following conditions are met:
00007  *
00008  * 1. Redistributions of source code must retain the above copyright notice,
00009  *    this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright notice,
00011  *    this list of conditions and the following disclaimer in the documentation
00012  *    and/or other materials provided with the distribution.
00013  * 3. The name of the author may not be used to endorse or promote products
00014  *    derived from this software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00017  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00018  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00019  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00020  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00021  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00022  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00023  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00024  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00025  * OF SUCH DAMAGE.
00026  *
00027  * This file is part of the lwIP TCP/IP stack.
00028  *
00029  * Author: Adam Dunkels <adam@sics.se>
00030  *
00031  */
00032 
00033 
00034 #ifndef __LWIP_SOCKETS_H__
00035 #define __LWIP_SOCKETS_H__
00036 
00037 #include "lwip/opt.h"
00038 
00039 #if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
00040 
00041 #include <stddef.h> /* for size_t */
00042 
00043 #include "lwip/ip_addr.h"
00044 #include "lwip/inet.h"
00045 
00046 #ifdef __cplusplus
00047 extern "C" {
00048 #endif
00049 
00050 /* members are in network byte order */
00051 struct sockaddr_in {
00052   u8_t sin_len;
00053   u8_t sin_family;
00054   u16_t sin_port;
00055   struct in_addr sin_addr;
00056   char sin_zero[8];
00057 };
00058 
00059 struct sockaddr {
00060   u8_t sa_len;
00061   u8_t sa_family;
00062   char sa_data[14];
00063 };
00064 
00065 /* If your port already typedef's socklen_t, define SOCKLEN_T_DEFINED
00066    to prevent this code from redefining it. */
00067 #if !defined(socklen_t) && !defined(SOCKLEN_T_DEFINED)
00068 typedef u32_t socklen_t;
00069 #endif
00070 
00071 /* Socket protocol types (TCP/UDP/RAW) */
00072 #define SOCK_STREAM     1
00073 #define SOCK_DGRAM      2
00074 #define SOCK_RAW        3
00075 
00076 /*
00077  * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c)
00078  */
00079 #define  SO_DEBUG       0x0001 /* Unimplemented: turn on debugging info recording */
00080 #define  SO_ACCEPTCONN  0x0002 /* socket has had listen() */
00081 #define  SO_REUSEADDR   0x0004 /* Allow local address reuse */
00082 #define  SO_KEEPALIVE   0x0008 /* keep connections alive */
00083 #define  SO_DONTROUTE   0x0010 /* Unimplemented: just use interface addresses */
00084 #define  SO_BROADCAST   0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
00085 #define  SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */
00086 #define  SO_LINGER      0x0080 /* linger on close if data present */
00087 #define  SO_OOBINLINE   0x0100 /* Unimplemented: leave received OOB data in line */
00088 #define  SO_REUSEPORT   0x0200 /* Unimplemented: allow local address & port reuse */
00089 
00090 #define SO_DONTLINGER   ((int)(~SO_LINGER))
00091 
00092 /*
00093  * Additional options, not kept in so_options.
00094  */
00095 #define SO_SNDBUF    0x1001    /* Unimplemented: send buffer size */
00096 #define SO_RCVBUF    0x1002    /* receive buffer size */
00097 #define SO_SNDLOWAT  0x1003    /* Unimplemented: send low-water mark */
00098 #define SO_RCVLOWAT  0x1004    /* Unimplemented: receive low-water mark */
00099 #define SO_SNDTIMEO  0x1005    /* Unimplemented: send timeout */
00100 #define SO_RCVTIMEO  0x1006    /* receive timeout */
00101 #define SO_ERROR     0x1007    /* get error status and clear */
00102 #define SO_TYPE      0x1008    /* get socket type */
00103 #define SO_CONTIMEO  0x1009    /* Unimplemented: connect timeout */
00104 #define SO_NO_CHECK  0x100a    /* don't create UDP checksum */
00105 
00106 
00107 /*
00108  * Structure used for manipulating linger option.
00109  */
00110 struct linger {
00111        int l_onoff;                /* option on/off */
00112        int l_linger;               /* linger time */
00113 };
00114 
00115 /*
00116  * Level number for (get/set)sockopt() to apply to socket itself.
00117  */
00118 #define  SOL_SOCKET  0xfff    /* options for socket level */
00119 
00120 
00121 #define AF_UNSPEC       0
00122 #define AF_INET         2
00123 #define PF_INET         AF_INET
00124 #define PF_UNSPEC       AF_UNSPEC
00125 
00126 #define IPPROTO_IP      0
00127 #define IPPROTO_TCP     6
00128 #define IPPROTO_UDP     17
00129 #define IPPROTO_UDPLITE 136
00130 
00131 /* Flags we can use with send and recv. */
00132 #define MSG_PEEK       0x01    /* Peeks at an incoming message */
00133 #define MSG_WAITALL    0x02    /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */
00134 #define MSG_OOB        0x04    /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
00135 #define MSG_DONTWAIT   0x08    /* Nonblocking i/o for this operation only */
00136 #define MSG_MORE       0x10    /* Sender will send more */
00137 
00138 
00139 /*
00140  * Options for level IPPROTO_IP
00141  */
00142 #define IP_TOS             1
00143 #define IP_TTL             2
00144 
00145 #if LWIP_TCP
00146 /*
00147  * Options for level IPPROTO_TCP
00148  */
00149 #define TCP_NODELAY    0x01    /* don't delay send to coalesce packets */
00150 #define TCP_KEEPALIVE  0x02    /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */
00151 #define TCP_KEEPIDLE   0x03    /* set pcb->keep_idle  - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
00152 #define TCP_KEEPINTVL  0x04    /* set pcb->keep_intvl - Use seconds for get/setsockopt */
00153 #define TCP_KEEPCNT    0x05    /* set pcb->keep_cnt   - Use number of probes sent for get/setsockopt */
00154 #endif /* LWIP_TCP */
00155 
00156 #if LWIP_UDP && LWIP_UDPLITE
00157 /*
00158  * Options for level IPPROTO_UDPLITE
00159  */
00160 #define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
00161 #define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
00162 #endif /* LWIP_UDP && LWIP_UDPLITE*/
00163 
00164 
00165 #if LWIP_IGMP
00166 /*
00167  * Options and types for UDP multicast traffic handling
00168  */
00169 #define IP_ADD_MEMBERSHIP  3
00170 #define IP_DROP_MEMBERSHIP 4
00171 #define IP_MULTICAST_TTL   5
00172 #define IP_MULTICAST_IF    6
00173 #define IP_MULTICAST_LOOP  7
00174 
00175 typedef struct ip_mreq {
00176     struct in_addr imr_multiaddr; /* IP multicast address of group */
00177     struct in_addr imr_interface; /* local IP address of interface */
00178 } ip_mreq;
00179 #endif /* LWIP_IGMP */
00180 
00181 /*
00182  * The Type of Service provides an indication of the abstract
00183  * parameters of the quality of service desired.  These parameters are
00184  * to be used to guide the selection of the actual service parameters
00185  * when transmitting a datagram through a particular network.  Several
00186  * networks offer service precedence, which somehow treats high
00187  * precedence traffic as more important than other traffic (generally
00188  * by accepting only traffic above a certain precedence at time of high
00189  * load).  The major choice is a three way tradeoff between low-delay,
00190  * high-reliability, and high-throughput.
00191  * The use of the Delay, Throughput, and Reliability indications may
00192  * increase the cost (in some sense) of the service.  In many networks
00193  * better performance for one of these parameters is coupled with worse
00194  * performance on another.  Except for very unusual cases at most two
00195  * of these three indications should be set.
00196  */
00197 #define IPTOS_TOS_MASK          0x1E
00198 #define IPTOS_TOS(tos)          ((tos) & IPTOS_TOS_MASK)
00199 #define IPTOS_LOWDELAY          0x10
00200 #define IPTOS_THROUGHPUT        0x08
00201 #define IPTOS_RELIABILITY       0x04
00202 #define IPTOS_LOWCOST           0x02
00203 #define IPTOS_MINCOST           IPTOS_LOWCOST
00204 
00205 /*
00206  * The Network Control precedence designation is intended to be used
00207  * within a network only.  The actual use and control of that
00208  * designation is up to each network. The Internetwork Control
00209  * designation is intended for use by gateway control originators only.
00210  * If the actual use of these precedence designations is of concern to
00211  * a particular network, it is the responsibility of that network to
00212  * control the access to, and use of, those precedence designations.
00213  */
00214 #define IPTOS_PREC_MASK                 0xe0
00215 #define IPTOS_PREC(tos)                ((tos) & IPTOS_PREC_MASK)
00216 #define IPTOS_PREC_NETCONTROL           0xe0
00217 #define IPTOS_PREC_INTERNETCONTROL      0xc0
00218 #define IPTOS_PREC_CRITIC_ECP           0xa0
00219 #define IPTOS_PREC_FLASHOVERRIDE        0x80
00220 #define IPTOS_PREC_FLASH                0x60
00221 #define IPTOS_PREC_IMMEDIATE            0x40
00222 #define IPTOS_PREC_PRIORITY             0x20
00223 #define IPTOS_PREC_ROUTINE              0x00
00224 
00225 
00226 /*
00227  * Commands for ioctlsocket(),  taken from the BSD file fcntl.h.
00228  * lwip_ioctl only supports FIONREAD and FIONBIO, for now
00229  *
00230  * Ioctl's have the command encoded in the lower word,
00231  * and the size of any in or out parameters in the upper
00232  * word.  The high 2 bits of the upper word are used
00233  * to encode the in/out status of the parameter; for now
00234  * we restrict parameters to at most 128 bytes.
00235  */
00236 #if !defined(FIONREAD) || !defined(FIONBIO)
00237 #define IOCPARM_MASK    0x7fU           /* parameters must be < 128 bytes */
00238 #define IOC_VOID        0x20000000UL    /* no parameters */
00239 #define IOC_OUT         0x40000000UL    /* copy out parameters */
00240 #define IOC_IN          0x80000000UL    /* copy in parameters */
00241 #define IOC_INOUT       (IOC_IN|IOC_OUT)
00242                                         /* 0x20000000 distinguishes new &
00243                                            old ioctl's */
00244 #define _IO(x,y)        (IOC_VOID|((x)<<8)|(y))
00245 
00246 #define _IOR(x,y,t)     (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
00247 
00248 #define _IOW(x,y,t)     (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
00249 #endif /* !defined(FIONREAD) || !defined(FIONBIO) */
00250 
00251 #ifndef FIONREAD
00252 #define FIONREAD    _IOR('f', 127, unsigned long) /* get # bytes to read */
00253 #endif
00254 #ifndef FIONBIO
00255 #define FIONBIO     _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
00256 #endif
00257 
00258 /* Socket I/O Controls: unimplemented */
00259 #ifndef SIOCSHIWAT
00260 #define SIOCSHIWAT  _IOW('s',  0, unsigned long)  /* set high watermark */
00261 #define SIOCGHIWAT  _IOR('s',  1, unsigned long)  /* get high watermark */
00262 #define SIOCSLOWAT  _IOW('s',  2, unsigned long)  /* set low watermark */
00263 #define SIOCGLOWAT  _IOR('s',  3, unsigned long)  /* get low watermark */
00264 #define SIOCATMARK  _IOR('s',  7, unsigned long)  /* at oob mark? */
00265 #endif
00266 
00267 /* commands for fnctl */
00268 #ifndef F_GETFL
00269 #define F_GETFL 3
00270 #endif
00271 #ifndef F_SETFL
00272 #define F_SETFL 4
00273 #endif
00274 
00275 /* File status flags and file access modes for fnctl,
00276    these are bits in an int. */
00277 #ifndef O_NONBLOCK
00278 #define O_NONBLOCK  1 /* nonblocking I/O */
00279 #endif
00280 #ifndef O_NDELAY
00281 #define O_NDELAY    1 /* same as O_NONBLOCK, for compatibility */
00282 #endif
00283 
00284 #ifndef SHUT_RD
00285   #define SHUT_RD   0
00286   #define SHUT_WR   1
00287   #define SHUT_RDWR 2
00288 #endif
00289 
00290 /* FD_SET used for lwip_select */
00291 #ifndef FD_SET
00292   #undef  FD_SETSIZE
00293   /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
00294   #define FD_SETSIZE    MEMP_NUM_NETCONN
00295   #define FD_SET(n, p)  ((p)->fd_bits[(n)/8] |=  (1 << ((n) & 7)))
00296   #define FD_CLR(n, p)  ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
00297   #define FD_ISSET(n,p) ((p)->fd_bits[(n)/8] &   (1 << ((n) & 7)))
00298   #define FD_ZERO(p)    memset((void*)(p),0,sizeof(*(p)))
00299 
00300   typedef struct fd_set {
00301           unsigned char fd_bits [(FD_SETSIZE+7)/8];
00302         } fd_set;
00303 
00304 #endif /* FD_SET */
00305 
00306 /** LWIP_TIMEVAL_PRIVATE: if you want to use the struct timeval provided
00307  * by your system, set this to 0 and include <sys/time.h> in cc.h */
00308 #ifndef LWIP_TIMEVAL_PRIVATE
00309 
00310 #if defined(TOOLCHAIN_ARM)
00311 #define LWIP_TIMEVAL_PRIVATE 1
00312 #else
00313 #define LWIP_TIMEVAL_PRIVATE 0
00314 #endif
00315 
00316 #endif
00317 #if LWIP_TIMEVAL_PRIVATE
00318 struct timeval {
00319   long    tv_sec;         /* seconds */
00320   long    tv_usec;        /* and microseconds */
00321 };
00322 #endif /* LWIP_TIMEVAL_PRIVATE */
00323 
00324 void lwip_socket_init(void);
00325 
00326 int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen);
00327 int lwip_bind(int s, const struct sockaddr *name, socklen_t namelen);
00328 int lwip_shutdown(int s, int how);
00329 int lwip_getpeername (int s, struct sockaddr *name, socklen_t *namelen);
00330 int lwip_getsockname (int s, struct sockaddr *name, socklen_t *namelen);
00331 int lwip_getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen);
00332 int lwip_setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen);
00333 int lwip_close(int s);
00334 int lwip_connect(int s, const struct sockaddr *name, socklen_t namelen);
00335 int lwip_listen(int s, int backlog);
00336 int lwip_recv(int s, void *mem, size_t len, int flags);
00337 int lwip_read(int s, void *mem, size_t len);
00338 int lwip_recvfrom(int s, void *mem, size_t len, int flags,
00339       struct sockaddr *from, socklen_t *fromlen);
00340 int lwip_send(int s, const void *dataptr, size_t size, int flags);
00341 int lwip_sendto (int s, const void *dataptr, size_t size, int flags,
00342     const struct sockaddr *to, socklen_t tolen);
00343 int lwip_socket(int domain, int type, int protocol);
00344 int lwip_write(int s, const void *dataptr, size_t size);
00345 int lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset,
00346                 struct timeval *timeout);
00347 int lwip_ioctl(int s, long cmd, void *argp);
00348 int lwip_fcntl(int s, int cmd, int val);
00349 
00350 #if LWIP_COMPAT_SOCKETS
00351 #define accept(a,b,c)         lwip_accept(a,b,c)
00352 #define bind(a,b,c)           lwip_bind(a,b,c)
00353 #define shutdown(a,b)         lwip_shutdown(a,b)
00354 #define closesocket(s)        lwip_close(s)
00355 #define connect(a,b,c)        lwip_connect(a,b,c)
00356 #define getsockname(a,b,c)    lwip_getsockname(a,b,c)
00357 #define getpeername(a,b,c)    lwip_getpeername(a,b,c)
00358 #define setsockopt(a,b,c,d,e) lwip_setsockopt(a,b,c,d,e)
00359 #define getsockopt(a,b,c,d,e) lwip_getsockopt(a,b,c,d,e)
00360 #define listen(a,b)           lwip_listen(a,b)
00361 #define recv(a,b,c,d)         lwip_recv(a,b,c,d)
00362 #define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f)
00363 #define send(a,b,c,d)         lwip_send(a,b,c,d)
00364 #define sendto(a,b,c,d,e,f)   lwip_sendto(a,b,c,d,e,f)
00365 #define socket(a,b,c)         lwip_socket(a,b,c)
00366 #define select(a,b,c,d,e)     lwip_select(a,b,c,d,e)
00367 #define ioctlsocket(a,b,c)    lwip_ioctl(a,b,c)
00368 
00369 #if LWIP_POSIX_SOCKETS_IO_NAMES
00370 #define read(a,b,c)           lwip_read(a,b,c)
00371 #define write(a,b,c)          lwip_write(a,b,c)
00372 #define close(s)              lwip_close(s)
00373 #define fcntl(a,b,c)          lwip_fcntl(a,b,c)
00374 #endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
00375 
00376 #endif /* LWIP_COMPAT_SOCKETS */
00377 
00378 #ifdef __cplusplus
00379 }
00380 #endif
00381 
00382 #endif /* LWIP_SOCKET */
00383 
00384 #endif /* __LWIP_SOCKETS_H__ */