Sony PlayStation2 Study
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1761 lines
71 KiB

4 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. # _____ ___ ____ ___ ____
  3. # ____| | ____| | | |____|
  4. # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
  5. #-----------------------------------------------------------------------
  6. # Copyright 2001-2004, ps2dev - http://www.ps2dev.org
  7. # Licenced under Academic Free License version 2.0
  8. # Review ps2sdk README & LICENSE files for further details.
  9. */
  10. /**
  11. * @file
  12. * Common definitions file for the LWIP v2.0.0 port.
  13. */
  14. #ifndef __TCPIP_H__
  15. #define __TCPIP_H__
  16. #include <tamtypes.h>
  17. /* Some portions of this header fall under the following copyright. The license
  18. is compatible with that of ps2sdk.
  19. This port of LWIP has LWIP_DHCP defined by default. */
  20. #ifndef PS2IP_DNS
  21. #define PS2IP_DNS
  22. #endif
  23. #ifndef PS2IP_DHCP
  24. #define PS2IP_DHCP 1
  25. #endif
  26. #ifndef LWIP_DHCP
  27. #define LWIP_DHCP 1
  28. #endif
  29. #if (!defined(LWIP_IPV4) && !defined(LWIP_IPV6))
  30. #define LWIP_IPV4 1
  31. #endif
  32. #ifndef LWIP_TCP
  33. #define LWIP_TCP 1
  34. #endif
  35. #ifndef LWIP_UDP
  36. #define LWIP_UDP 1
  37. #endif
  38. /*** Taken from src/include/lwip/opt.h. If changes were made to lwipopts.h, please update this section.
  39. Some settings affect the fields present in structures like struct netif! ****/
  40. #define MEMP_NUM_UDP_PCB 4
  41. #define MEMP_NUM_TCP_PCB 5
  42. #define MEMP_NUM_NETCONN (MEMP_NUM_TCP_PCB+MEMP_NUM_UDP_PCB)
  43. #define LWIP_NETIF_STATUS_CALLBACK 0
  44. #define LWIP_NETIF_LINK_CALLBACK 0
  45. #define LWIP_AUTOIP 0
  46. #define LWIP_NETIF_HOSTNAME 0
  47. #define LWIP_SNMP 0
  48. #define LWIP_IGMP 0
  49. #define LWIP_NETIF_HWADDRHINT 0
  50. #define LWIP_LOOPBACK_MAX_PBUFS 0
  51. #define LWIP_NUM_NETIF_CLIENT_DATA 0
  52. #define LWIP_SOCKET_OFFSET 0
  53. #define LWIP_IPV6_SEND_ROUTER_SOLICIT 1
  54. #define DNS_MAX_SERVERS 2
  55. /*
  56. * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
  57. * All rights reserved.
  58. *
  59. * Redistribution and use in source and binary forms, with or without modification,
  60. * are permitted provided that the following conditions are met:
  61. *
  62. * 1. Redistributions of source code must retain the above copyright notice,
  63. * this list of conditions and the following disclaimer.
  64. * 2. Redistributions in binary form must reproduce the above copyright notice,
  65. * this list of conditions and the following disclaimer in the documentation
  66. * and/or other materials provided with the distribution.
  67. * 3. The name of the author may not be used to endorse or promote products
  68. * derived from this software without specific prior written permission.
  69. *
  70. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  71. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  72. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  73. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  74. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  75. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  76. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  77. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  78. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  79. * OF SUCH DAMAGE.
  80. *
  81. * This file is part of the lwIP TCP/IP stack.
  82. *
  83. * Author: Adam Dunkels <adam@sics.se>
  84. *
  85. */
  86. typedef signed char err_t; /* lwIP error type. */
  87. /* From src/include/lwip/pbuf.h: */
  88. #define PBUF_TRANSPORT_HLEN 20
  89. #if LWIP_IPV6
  90. #define PBUF_IP_HLEN 40
  91. #else
  92. #define PBUF_IP_HLEN 20
  93. #endif
  94. /**
  95. * @ingroup pbuf
  96. * Enumeration of pbuf layers
  97. */
  98. typedef enum {
  99. /** Includes spare room for transport layer header, e.g. UDP header.
  100. * Use this if you intend to pass the pbuf to functions like udp_send().
  101. */
  102. PBUF_TRANSPORT,
  103. /** Includes spare room for IP header.
  104. * Use this if you intend to pass the pbuf to functions like raw_send().
  105. */
  106. PBUF_IP,
  107. /** Includes spare room for link layer header (ethernet header).
  108. * Use this if you intend to pass the pbuf to functions like ethernet_output().
  109. * @see PBUF_LINK_HLEN
  110. */
  111. PBUF_LINK,
  112. /** Includes spare room for additional encapsulation header before ethernet
  113. * headers (e.g. 802.11).
  114. * Use this if you intend to pass the pbuf to functions like netif->linkoutput().
  115. * @see PBUF_LINK_ENCAPSULATION_HLEN
  116. */
  117. PBUF_RAW_TX,
  118. /** Use this for input packets in a netif driver when calling netif->input()
  119. * in the most common case - ethernet-layer netif driver. */
  120. PBUF_RAW
  121. } pbuf_layer;
  122. /**
  123. * @ingroup pbuf
  124. * Enumeration of pbuf types
  125. */
  126. typedef enum {
  127. /** pbuf data is stored in RAM, used for TX mostly, struct pbuf and its payload
  128. are allocated in one piece of contiguous memory (so the first payload byte
  129. can be calculated from struct pbuf).
  130. pbuf_alloc() allocates PBUF_RAM pbufs as unchained pbufs (although that might
  131. change in future versions).
  132. This should be used for all OUTGOING packets (TX).*/
  133. PBUF_RAM,
  134. /** pbuf data is stored in ROM, i.e. struct pbuf and its payload are located in
  135. totally different memory areas. Since it points to ROM, payload does not
  136. have to be copied when queued for transmission. */
  137. PBUF_ROM,
  138. /** pbuf comes from the pbuf pool. Much like PBUF_ROM but payload might change
  139. so it has to be duplicated when queued before transmitting, depending on
  140. who has a 'ref' to it. */
  141. PBUF_REF,
  142. /** pbuf payload refers to RAM. This one comes from a pool and should be used
  143. for RX. Payload can be chained (scatter-gather RX) but like PBUF_RAM, struct
  144. pbuf and its payload are allocated in one piece of contiguous memory (so
  145. the first payload byte can be calculated from struct pbuf).
  146. Don't use this for TX, if the pool becomes empty e.g. because of TCP queuing,
  147. you are unable to receive TCP acks! */
  148. PBUF_POOL
  149. } pbuf_type;
  150. /** Main packet buffer struct */
  151. struct pbuf {
  152. /** next pbuf in singly linked pbuf chain */
  153. struct pbuf *next;
  154. /** pointer to the actual data in the buffer */
  155. void *payload;
  156. /**
  157. * total length of this buffer and all next buffers in chain
  158. * belonging to the same packet.
  159. *
  160. * For non-queue packet chains this is the invariant:
  161. * p->tot_len == p->len + (p->next? p->next->tot_len: 0)
  162. */
  163. u16 tot_len;
  164. /** length of this buffer */
  165. u16 len;
  166. /** pbuf_type as u8 instead of enum to save space */
  167. u8 /*pbuf_type*/ type;
  168. /** misc flags */
  169. u8 flags;
  170. /**
  171. * the reference count always equals the number of pointers
  172. * that refer to this pbuf. This can be pointers from an application,
  173. * the stack itself, or pbuf->next pointers from a chain.
  174. */
  175. u16 ref;
  176. };
  177. /* From include/lwip/ip4_addr.h: */
  178. /** This is the aligned version of ip4_addr_t,
  179. used as local variable, on the stack, etc. */
  180. struct ip4_addr {
  181. u32 addr;
  182. };
  183. /** ip4_addr_t uses a struct for convenience only, so that the same defines can
  184. * operate both on ip4_addr_t as well as on ip4_addr_p_t. */
  185. typedef struct ip4_addr ip4_addr_t;
  186. typedef struct ip4_addr_packed ip4_addr_p_t;
  187. /** 255.255.255.255 */
  188. #define IPADDR_NONE ((u32)0xffffffffUL)
  189. /** 127.0.0.1 */
  190. #define IPADDR_LOOPBACK ((u32)0x7f000001UL)
  191. /** 0.0.0.0 */
  192. #define IPADDR_ANY ((u32)0x00000000UL)
  193. /** 255.255.255.255 */
  194. #define IPADDR_BROADCAST ((u32)0xffffffffUL)
  195. /* Definitions of the bits in an Internet address integer.
  196. On subnets, host and network parts are found according to
  197. the subnet mask, not these masks. */
  198. #define IP_CLASSA(a) ((((u32)(a)) & 0x80000000UL) == 0)
  199. #define IP_CLASSA_NET 0xff000000
  200. #define IP_CLASSA_NSHIFT 24
  201. #define IP_CLASSA_HOST (0xffffffff & ~IP_CLASSA_NET)
  202. #define IP_CLASSA_MAX 128
  203. #define IP_CLASSB(a) ((((u32)(a)) & 0xc0000000UL) == 0x80000000UL)
  204. #define IP_CLASSB_NET 0xffff0000
  205. #define IP_CLASSB_NSHIFT 16
  206. #define IP_CLASSB_HOST (0xffffffff & ~IP_CLASSB_NET)
  207. #define IP_CLASSB_MAX 65536
  208. #define IP_CLASSC(a) ((((u32)(a)) & 0xe0000000UL) == 0xc0000000UL)
  209. #define IP_CLASSC_NET 0xffffff00
  210. #define IP_CLASSC_NSHIFT 8
  211. #define IP_CLASSC_HOST (0xffffffff & ~IP_CLASSC_NET)
  212. #define IP_CLASSD(a) (((u32)(a) & 0xf0000000UL) == 0xe0000000UL)
  213. #define IP_CLASSD_NET 0xf0000000 /* These ones aren't really */
  214. #define IP_CLASSD_NSHIFT 28 /* net and host fields, but */
  215. #define IP_CLASSD_HOST 0x0fffffff /* routing needn't know. */
  216. #define IP_MULTICAST(a) IP_CLASSD(a)
  217. #define IP_EXPERIMENTAL(a) (((u32)(a) & 0xf0000000UL) == 0xf0000000UL)
  218. #define IP_BADCLASS(a) (((u32)(a) & 0xf0000000UL) == 0xf0000000UL)
  219. #define IP_LOOPBACKNET 127 /* official! */
  220. /** Set an IP address given by the four byte-parts.
  221. Little-endian version that prevents the use of lwip_htonl. */
  222. #define IP4_ADDR(ipaddr, a,b,c,d) \
  223. (ipaddr)->addr = ((u32)((d) & 0xff) << 24) | \
  224. ((u32)((c) & 0xff) << 16) | \
  225. ((u32)((b) & 0xff) << 8) | \
  226. (u32)((a) & 0xff)
  227. /** MEMCPY-like copying of IP addresses where addresses are known to be
  228. * 16-bit-aligned if the port is correctly configured (so a port could define
  229. * this to copying 2 u16's) - no NULL-pointer-checking needed. */
  230. #ifndef IPADDR2_COPY
  231. #define IPADDR2_COPY(dest, src) memcpy(dest, src, sizeof(ip4_addr_t))
  232. #endif
  233. /** Copy IP address - faster than ip4_addr_set: no NULL check */
  234. #define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
  235. /** Safely copy one IP address to another (src may be NULL) */
  236. #define ip4_addr_set(dest, src) ((dest)->addr = \
  237. ((src) == NULL ? 0 : \
  238. (src)->addr))
  239. /** Set complete address to zero */
  240. #define ip4_addr_set_zero(ipaddr) ((ipaddr)->addr = 0)
  241. /** Set address to IPADDR_ANY (no need for lwip_htonl()) */
  242. #define ip4_addr_set_any(ipaddr) ((ipaddr)->addr = IPADDR_ANY)
  243. /** Set address to loopback address */
  244. #define ip4_addr_set_loopback(ipaddr) ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK))
  245. /** Check if an address is in the loopback region */
  246. #define ip4_addr_isloopback(ipaddr) (((ipaddr)->addr & PP_HTONL(IP_CLASSA_NET)) == PP_HTONL(((u32)IP_LOOPBACKNET) << 24))
  247. /** Safely copy one IP address to another and change byte order
  248. * from host- to network-order. */
  249. #define ip4_addr_set_hton(dest, src) ((dest)->addr = \
  250. ((src) == NULL ? 0:\
  251. lwip_htonl((src)->addr)))
  252. /** IPv4 only: set the IP address given as an u32 */
  253. #define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32))
  254. /** IPv4 only: get the IP address as an u32 */
  255. #define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr)
  256. /** Get the network address by combining host address with netmask */
  257. #define ip4_addr_get_network(target, host, netmask) do { ((target)->addr = ((host)->addr) & ((netmask)->addr)); } while(0)
  258. /**
  259. * Determine if two address are on the same network.
  260. *
  261. * @arg addr1 IP address 1
  262. * @arg addr2 IP address 2
  263. * @arg mask network identifier mask
  264. * @return !0 if the network identifiers of both address match
  265. */
  266. #define ip4_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
  267. (mask)->addr) == \
  268. ((addr2)->addr & \
  269. (mask)->addr))
  270. #define ip4_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
  271. #define ip4_addr_isany_val(addr1) ((addr1).addr == IPADDR_ANY)
  272. #define ip4_addr_isany(addr1) ((addr1) == NULL || ip4_addr_isany_val(*(addr1)))
  273. #define ip4_addr_isbroadcast(addr1, netif) ip4_addr_isbroadcast_u32((addr1)->addr, netif)
  274. #define ip_addr_netmask_valid(netmask) ip4_addr_netmask_valid((netmask)->addr)
  275. #define ip4_addr_ismulticast(addr1) (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL))
  276. #define ip4_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))
  277. #define ip4_addr_debug_print_parts(debug, a, b, c, d) \
  278. LWIP_DEBUGF(debug, ("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, a, b, c, d))
  279. #define ip4_addr_debug_print(debug, ipaddr) \
  280. ip4_addr_debug_print_parts(debug, \
  281. (u16)((ipaddr) != NULL ? ip4_addr1_16(ipaddr) : 0), \
  282. (u16)((ipaddr) != NULL ? ip4_addr2_16(ipaddr) : 0), \
  283. (u16)((ipaddr) != NULL ? ip4_addr3_16(ipaddr) : 0), \
  284. (u16)((ipaddr) != NULL ? ip4_addr4_16(ipaddr) : 0))
  285. #define ip4_addr_debug_print_val(debug, ipaddr) \
  286. ip4_addr_debug_print_parts(debug, \
  287. ip4_addr1_16(&(ipaddr)), \
  288. ip4_addr2_16(&(ipaddr)), \
  289. ip4_addr3_16(&(ipaddr)), \
  290. ip4_addr4_16(&(ipaddr)))
  291. /* Get one byte from the 4-byte address */
  292. #define ip4_addr1(ipaddr) (((const u8*)(&(ipaddr)->addr))[0])
  293. #define ip4_addr2(ipaddr) (((const u8*)(&(ipaddr)->addr))[1])
  294. #define ip4_addr3(ipaddr) (((const u8*)(&(ipaddr)->addr))[2])
  295. #define ip4_addr4(ipaddr) (((const u8*)(&(ipaddr)->addr))[3])
  296. /* These are cast to u16, with the intent that they are often arguments
  297. * to printf using the U16_F format from cc.h. */
  298. #define ip4_addr1_16(ipaddr) ((u16)ip4_addr1(ipaddr))
  299. #define ip4_addr2_16(ipaddr) ((u16)ip4_addr2(ipaddr))
  300. #define ip4_addr3_16(ipaddr) ((u16)ip4_addr3(ipaddr))
  301. #define ip4_addr4_16(ipaddr) ((u16)ip4_addr4(ipaddr))
  302. #define IP4ADDR_STRLEN_MAX 16
  303. /* From include/lwip/ip6_addr.h: */
  304. /** This is the aligned version of ip6_addr_t,
  305. used as local variable, on the stack, etc. */
  306. struct ip6_addr {
  307. u32 addr[4];
  308. };
  309. /** IPv6 address */
  310. typedef struct ip6_addr ip6_addr_t;
  311. typedef struct ip6_addr_packed ip6_addr_p_t;
  312. /** Set an IPv6 partial address given by byte-parts.
  313. Little-endian version, stored in network order (no lwip_htonl). */
  314. #define IP6_ADDR_PART(ip6addr, index, a,b,c,d) \
  315. (ip6addr)->addr[index] = ((u32)((d) & 0xff) << 24) | \
  316. ((u32)((c) & 0xff) << 16) | \
  317. ((u32)((b) & 0xff) << 8) | \
  318. (u32)((a) & 0xff)
  319. /** Set a full IPv6 address by passing the 4 u32 indices in network byte order
  320. (use PP_HTONL() for constants) */
  321. #define IP6_ADDR(ip6addr, idx0, idx1, idx2, idx3) do { \
  322. (ip6addr)->addr[0] = idx0; \
  323. (ip6addr)->addr[1] = idx1; \
  324. (ip6addr)->addr[2] = idx2; \
  325. (ip6addr)->addr[3] = idx3; } while(0)
  326. /** Access address in 16-bit block */
  327. #define IP6_ADDR_BLOCK1(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xffff))
  328. /** Access address in 16-bit block */
  329. #define IP6_ADDR_BLOCK2(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[0])) & 0xffff))
  330. /** Access address in 16-bit block */
  331. #define IP6_ADDR_BLOCK3(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[1]) >> 16) & 0xffff))
  332. /** Access address in 16-bit block */
  333. #define IP6_ADDR_BLOCK4(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[1])) & 0xffff))
  334. /** Access address in 16-bit block */
  335. #define IP6_ADDR_BLOCK5(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[2]) >> 16) & 0xffff))
  336. /** Access address in 16-bit block */
  337. #define IP6_ADDR_BLOCK6(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[2])) & 0xffff))
  338. /** Access address in 16-bit block */
  339. #define IP6_ADDR_BLOCK7(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[3]) >> 16) & 0xffff))
  340. /** Access address in 16-bit block */
  341. #define IP6_ADDR_BLOCK8(ip6addr) ((u16)((lwip_htonl((ip6addr)->addr[3])) & 0xffff))
  342. /** Copy IPv6 address - faster than ip6_addr_set: no NULL check */
  343. #define ip6_addr_copy(dest, src) do{(dest).addr[0] = (src).addr[0]; \
  344. (dest).addr[1] = (src).addr[1]; \
  345. (dest).addr[2] = (src).addr[2]; \
  346. (dest).addr[3] = (src).addr[3];}while(0)
  347. /** Safely copy one IPv6 address to another (src may be NULL) */
  348. #define ip6_addr_set(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : (src)->addr[0]; \
  349. (dest)->addr[1] = (src) == NULL ? 0 : (src)->addr[1]; \
  350. (dest)->addr[2] = (src) == NULL ? 0 : (src)->addr[2]; \
  351. (dest)->addr[3] = (src) == NULL ? 0 : (src)->addr[3];}while(0)
  352. /** Set complete address to zero */
  353. #define ip6_addr_set_zero(ip6addr) do{(ip6addr)->addr[0] = 0; \
  354. (ip6addr)->addr[1] = 0; \
  355. (ip6addr)->addr[2] = 0; \
  356. (ip6addr)->addr[3] = 0;}while(0)
  357. /** Set address to ipv6 'any' (no need for lwip_htonl()) */
  358. #define ip6_addr_set_any(ip6addr) ip6_addr_set_zero(ip6addr)
  359. /** Set address to ipv6 loopback address */
  360. #define ip6_addr_set_loopback(ip6addr) do{(ip6addr)->addr[0] = 0; \
  361. (ip6addr)->addr[1] = 0; \
  362. (ip6addr)->addr[2] = 0; \
  363. (ip6addr)->addr[3] = PP_HTONL(0x00000001UL);}while(0)
  364. /** Safely copy one IPv6 address to another and change byte order
  365. * from host- to network-order. */
  366. #define ip6_addr_set_hton(dest, src) do{(dest)->addr[0] = (src) == NULL ? 0 : lwip_htonl((src)->addr[0]); \
  367. (dest)->addr[1] = (src) == NULL ? 0 : lwip_htonl((src)->addr[1]); \
  368. (dest)->addr[2] = (src) == NULL ? 0 : lwip_htonl((src)->addr[2]); \
  369. (dest)->addr[3] = (src) == NULL ? 0 : lwip_htonl((src)->addr[3]);}while(0)
  370. /**
  371. * Determine if two IPv6 address are on the same network.
  372. *
  373. * @arg addr1 IPv6 address 1
  374. * @arg addr2 IPv6 address 2
  375. * @return !0 if the network identifiers of both address match
  376. */
  377. #define ip6_addr_netcmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
  378. ((addr1)->addr[1] == (addr2)->addr[1]))
  379. #define ip6_addr_cmp(addr1, addr2) (((addr1)->addr[0] == (addr2)->addr[0]) && \
  380. ((addr1)->addr[1] == (addr2)->addr[1]) && \
  381. ((addr1)->addr[2] == (addr2)->addr[2]) && \
  382. ((addr1)->addr[3] == (addr2)->addr[3]))
  383. #define ip6_get_subnet_id(ip6addr) (lwip_htonl((ip6addr)->addr[2]) & 0x0000ffffUL)
  384. #define ip6_addr_isany_val(ip6addr) (((ip6addr).addr[0] == 0) && \
  385. ((ip6addr).addr[1] == 0) && \
  386. ((ip6addr).addr[2] == 0) && \
  387. ((ip6addr).addr[3] == 0))
  388. #define ip6_addr_isany(ip6addr) (((ip6addr) == NULL) || ip6_addr_isany_val(*(ip6addr)))
  389. #define ip6_addr_isloopback(ip6addr) (((ip6addr)->addr[0] == 0UL) && \
  390. ((ip6addr)->addr[1] == 0UL) && \
  391. ((ip6addr)->addr[2] == 0UL) && \
  392. ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
  393. #define ip6_addr_isglobal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xe0000000UL)) == PP_HTONL(0x20000000UL))
  394. #define ip6_addr_islinklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfe800000UL))
  395. #define ip6_addr_issitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xffc00000UL)) == PP_HTONL(0xfec00000UL))
  396. #define ip6_addr_isuniquelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xfe000000UL)) == PP_HTONL(0xfc000000UL))
  397. #define ip6_addr_isipv6mappedipv4(ip6addr) (((ip6addr)->addr[0] == 0) && ((ip6addr)->addr[1] == 0) && (((ip6addr)->addr[2]) == PP_HTONL(0x0000FFFFUL)))
  398. #define ip6_addr_ismulticast(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL))
  399. #define ip6_addr_multicast_transient_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00100000UL))
  400. #define ip6_addr_multicast_prefix_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00200000UL))
  401. #define ip6_addr_multicast_rendezvous_flag(ip6addr) ((ip6addr)->addr[0] & PP_HTONL(0x00400000UL))
  402. #define ip6_addr_multicast_scope(ip6addr) ((lwip_htonl((ip6addr)->addr[0]) >> 16) & 0xf)
  403. #define IP6_MULTICAST_SCOPE_RESERVED 0x0
  404. #define IP6_MULTICAST_SCOPE_RESERVED0 0x0
  405. #define IP6_MULTICAST_SCOPE_INTERFACE_LOCAL 0x1
  406. #define IP6_MULTICAST_SCOPE_LINK_LOCAL 0x2
  407. #define IP6_MULTICAST_SCOPE_RESERVED3 0x3
  408. #define IP6_MULTICAST_SCOPE_ADMIN_LOCAL 0x4
  409. #define IP6_MULTICAST_SCOPE_SITE_LOCAL 0x5
  410. #define IP6_MULTICAST_SCOPE_ORGANIZATION_LOCAL 0x8
  411. #define IP6_MULTICAST_SCOPE_GLOBAL 0xe
  412. #define IP6_MULTICAST_SCOPE_RESERVEDF 0xf
  413. #define ip6_addr_ismulticast_iflocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff010000UL))
  414. #define ip6_addr_ismulticast_linklocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff020000UL))
  415. #define ip6_addr_ismulticast_adminlocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff040000UL))
  416. #define ip6_addr_ismulticast_sitelocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff050000UL))
  417. #define ip6_addr_ismulticast_orglocal(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff080000UL))
  418. #define ip6_addr_ismulticast_global(ip6addr) (((ip6addr)->addr[0] & PP_HTONL(0xff8f0000UL)) == PP_HTONL(0xff0e0000UL))
  419. /* @todo define get/set for well-know multicast addresses, e.g. ff02::1 */
  420. #define ip6_addr_isallnodes_iflocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff010000UL)) && \
  421. ((ip6addr)->addr[1] == 0UL) && \
  422. ((ip6addr)->addr[2] == 0UL) && \
  423. ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
  424. #define ip6_addr_isallnodes_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
  425. ((ip6addr)->addr[1] == 0UL) && \
  426. ((ip6addr)->addr[2] == 0UL) && \
  427. ((ip6addr)->addr[3] == PP_HTONL(0x00000001UL)))
  428. #define ip6_addr_set_allnodes_linklocal(ip6addr) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
  429. (ip6addr)->addr[1] = 0; \
  430. (ip6addr)->addr[2] = 0; \
  431. (ip6addr)->addr[3] = PP_HTONL(0x00000001UL);}while(0)
  432. #define ip6_addr_isallrouters_linklocal(ip6addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
  433. ((ip6addr)->addr[1] == 0UL) && \
  434. ((ip6addr)->addr[2] == 0UL) && \
  435. ((ip6addr)->addr[3] == PP_HTONL(0x00000002UL)))
  436. #define ip6_addr_set_allrouters_linklocal(ip6addr) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
  437. (ip6addr)->addr[1] = 0; \
  438. (ip6addr)->addr[2] = 0; \
  439. (ip6addr)->addr[3] = PP_HTONL(0x00000002UL);}while(0)
  440. #define ip6_addr_issolicitednode(ip6addr) ( ((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
  441. ((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \
  442. (((ip6addr)->addr[3] & PP_HTONL(0xff000000UL)) == PP_HTONL(0xff000000UL)) )
  443. #define ip6_addr_set_solicitednode(ip6addr, if_id) do{(ip6addr)->addr[0] = PP_HTONL(0xff020000UL); \
  444. (ip6addr)->addr[1] = 0; \
  445. (ip6addr)->addr[2] = PP_HTONL(0x00000001UL); \
  446. (ip6addr)->addr[3] = (PP_HTONL(0xff000000UL) | (if_id));}while(0)
  447. #define ip6_addr_cmp_solicitednode(ip6addr, sn_addr) (((ip6addr)->addr[0] == PP_HTONL(0xff020000UL)) && \
  448. ((ip6addr)->addr[1] == 0) && \
  449. ((ip6addr)->addr[2] == PP_HTONL(0x00000001UL)) && \
  450. ((ip6addr)->addr[3] == (PP_HTONL(0xff000000UL) | (sn_addr)->addr[3])))
  451. /* IPv6 address states. */
  452. #define IP6_ADDR_INVALID 0x00
  453. #define IP6_ADDR_TENTATIVE 0x08
  454. #define IP6_ADDR_TENTATIVE_1 0x09 /* 1 probe sent */
  455. #define IP6_ADDR_TENTATIVE_2 0x0a /* 2 probes sent */
  456. #define IP6_ADDR_TENTATIVE_3 0x0b /* 3 probes sent */
  457. #define IP6_ADDR_TENTATIVE_4 0x0c /* 4 probes sent */
  458. #define IP6_ADDR_TENTATIVE_5 0x0d /* 5 probes sent */
  459. #define IP6_ADDR_TENTATIVE_6 0x0e /* 6 probes sent */
  460. #define IP6_ADDR_TENTATIVE_7 0x0f /* 7 probes sent */
  461. #define IP6_ADDR_VALID 0x10 /* This bit marks an address as valid (preferred or deprecated) */
  462. #define IP6_ADDR_PREFERRED 0x30
  463. #define IP6_ADDR_DEPRECATED 0x10 /* Same as VALID (valid but not preferred) */
  464. #define IP6_ADDR_TENTATIVE_COUNT_MASK 0x07 /* 1-7 probes sent */
  465. #define ip6_addr_isinvalid(addr_state) (addr_state == IP6_ADDR_INVALID)
  466. #define ip6_addr_istentative(addr_state) (addr_state & IP6_ADDR_TENTATIVE)
  467. #define ip6_addr_isvalid(addr_state) (addr_state & IP6_ADDR_VALID) /* Include valid, preferred, and deprecated. */
  468. #define ip6_addr_ispreferred(addr_state) (addr_state == IP6_ADDR_PREFERRED)
  469. #define ip6_addr_isdeprecated(addr_state) (addr_state == IP6_ADDR_DEPRECATED)
  470. #define ip6_addr_debug_print_parts(debug, a, b, c, d, e, f, g, h) \
  471. LWIP_DEBUGF(debug, ("%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F ":%" X16_F, \
  472. a, b, c, d, e, f, g, h))
  473. #define ip6_addr_debug_print(debug, ipaddr) \
  474. ip6_addr_debug_print_parts(debug, \
  475. (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK1(ipaddr) : 0), \
  476. (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK2(ipaddr) : 0), \
  477. (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK3(ipaddr) : 0), \
  478. (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK4(ipaddr) : 0), \
  479. (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK5(ipaddr) : 0), \
  480. (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK6(ipaddr) : 0), \
  481. (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK7(ipaddr) : 0), \
  482. (u16)((ipaddr) != NULL ? IP6_ADDR_BLOCK8(ipaddr) : 0))
  483. #define ip6_addr_debug_print_val(debug, ipaddr) \
  484. ip6_addr_debug_print_parts(debug, \
  485. IP6_ADDR_BLOCK1(&(ipaddr)), \
  486. IP6_ADDR_BLOCK2(&(ipaddr)), \
  487. IP6_ADDR_BLOCK3(&(ipaddr)), \
  488. IP6_ADDR_BLOCK4(&(ipaddr)), \
  489. IP6_ADDR_BLOCK5(&(ipaddr)), \
  490. IP6_ADDR_BLOCK6(&(ipaddr)), \
  491. IP6_ADDR_BLOCK7(&(ipaddr)), \
  492. IP6_ADDR_BLOCK8(&(ipaddr)))
  493. #define IP6ADDR_STRLEN_MAX 46
  494. /* From include/lwip/ip_addr.h: */
  495. /** @ingroup ipaddr
  496. * IP address types for use in ip_addr_t.type member.
  497. * @see tcp_new_ip_type(), udp_new_ip_type(), raw_new_ip_type().
  498. */
  499. enum lwip_ip_addr_type {
  500. /** IPv4 */
  501. IPADDR_TYPE_V4 = 0U,
  502. /** IPv6 */
  503. IPADDR_TYPE_V6 = 6U,
  504. /** IPv4+IPv6 ("dual-stack") */
  505. IPADDR_TYPE_ANY = 46U
  506. };
  507. #if LWIP_IPV4 && LWIP_IPV6
  508. /**
  509. * @ingroup ipaddr
  510. * A union struct for both IP version's addresses.
  511. * ATTENTION: watch out for its size when adding IPv6 address scope!
  512. */
  513. typedef struct _ip_addr {
  514. union {
  515. ip6_addr_t ip6;
  516. ip4_addr_t ip4;
  517. } uaddr;
  518. /** @ref lwip_ip_addr_type */
  519. u8 type;
  520. } ip_addr_t;
  521. extern const ip_addr_t ip_addr_any_type;
  522. /** @ingroup ip4addr */
  523. #define IPADDR4_INIT(u32val) { { { { u32val, 0ul, 0ul, 0ul } } }, IPADDR_TYPE_V4 }
  524. /** @ingroup ip6addr */
  525. #define IPADDR6_INIT(a, b, c, d) { { { { a, b, c, d } } }, IPADDR_TYPE_V6 }
  526. /** @ingroup ipaddr */
  527. #define IP_IS_ANY_TYPE_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_ANY)
  528. /** @ingroup ipaddr */
  529. #define IPADDR_ANY_TYPE_INIT { { { { 0ul, 0ul, 0ul, 0ul } } }, IPADDR_TYPE_ANY }
  530. /** @ingroup ip4addr */
  531. #define IP_IS_V4_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V4)
  532. /** @ingroup ip6addr */
  533. #define IP_IS_V6_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_V6)
  534. /** @ingroup ip4addr */
  535. #define IP_IS_V4(ipaddr) (((ipaddr) == NULL) || IP_IS_V4_VAL(*(ipaddr)))
  536. /** @ingroup ip6addr */
  537. #define IP_IS_V6(ipaddr) (((ipaddr) != NULL) && IP_IS_V6_VAL(*(ipaddr)))
  538. #define IP_SET_TYPE_VAL(ipaddr, iptype) do { (ipaddr).type = (iptype); }while(0)
  539. #define IP_SET_TYPE(ipaddr, iptype) do { if((ipaddr) != NULL) { IP_SET_TYPE_VAL(*(ipaddr), iptype); }}while(0)
  540. #define IP_GET_TYPE(ipaddr) ((ipaddr)->type)
  541. #define IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr) (IP_GET_TYPE(&pcb->local_ip) == IP_GET_TYPE(ipaddr))
  542. #define IP_ADDR_PCB_VERSION_MATCH(pcb, ipaddr) (IP_IS_ANY_TYPE_VAL(pcb->local_ip) || IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr))
  543. /** @ingroup ip6addr
  544. * Convert generic ip address to specific protocol version
  545. */
  546. #define ip_2_ip6(ipaddr) (&((ipaddr)->uaddr.ip6))
  547. /** @ingroup ip4addr
  548. * Convert generic ip address to specific protocol version
  549. */
  550. #define ip_2_ip4(ipaddr) (&((ipaddr)->uaddr.ip4))
  551. /** @ingroup ip4addr */
  552. #define IP_ADDR4(ipaddr,a,b,c,d) do { IP4_ADDR(ip_2_ip4(ipaddr),a,b,c,d); \
  553. IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V4); } while(0)
  554. /** @ingroup ip6addr */
  555. #define IP_ADDR6(ipaddr,i0,i1,i2,i3) do { IP6_ADDR(ip_2_ip6(ipaddr),i0,i1,i2,i3); \
  556. IP_SET_TYPE_VAL(*(ipaddr), IPADDR_TYPE_V6); } while(0)
  557. /** @ingroup ipaddr */
  558. #define ip_addr_copy(dest, src) do{ IP_SET_TYPE_VAL(dest, IP_GET_TYPE(&src)); if(IP_IS_V6_VAL(src)){ \
  559. ip6_addr_copy(*ip_2_ip6(&(dest)), *ip_2_ip6(&(src))); }else{ \
  560. ip4_addr_copy(*ip_2_ip4(&(dest)), *ip_2_ip4(&(src))); }}while(0)
  561. /** @ingroup ip6addr */
  562. #define ip_addr_copy_from_ip6(dest, src) do{ \
  563. ip6_addr_copy(*ip_2_ip6(&(dest)), src); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V6); }while(0)
  564. /** @ingroup ip4addr */
  565. #define ip_addr_copy_from_ip4(dest, src) do{ \
  566. ip4_addr_copy(*ip_2_ip4(&(dest)), src); IP_SET_TYPE_VAL(dest, IPADDR_TYPE_V4); }while(0)
  567. /** @ingroup ip4addr */
  568. #define ip_addr_set_ip4_u32(ipaddr, val) do{if(ipaddr){ip4_addr_set_u32(ip_2_ip4(ipaddr), val); \
  569. IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
  570. /** @ingroup ip4addr */
  571. #define ip_addr_get_ip4_u32(ipaddr) (((ipaddr) && IP_IS_V4(ipaddr)) ? \
  572. ip4_addr_get_u32(ip_2_ip4(ipaddr)) : 0)
  573. /** @ingroup ipaddr */
  574. #define ip_addr_set(dest, src) do{ IP_SET_TYPE(dest, IP_GET_TYPE(src)); if(IP_IS_V6(src)){ \
  575. ip6_addr_set(ip_2_ip6(dest), ip_2_ip6(src)); }else{ \
  576. ip4_addr_set(ip_2_ip4(dest), ip_2_ip4(src)); }}while(0)
  577. /** @ingroup ipaddr */
  578. #define ip_addr_set_ipaddr(dest, src) ip_addr_set(dest, src)
  579. /** @ingroup ipaddr */
  580. #define ip_addr_set_zero(ipaddr) do{ \
  581. ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, 0); }while(0)
  582. /** @ingroup ip5addr */
  583. #define ip_addr_set_zero_ip4(ipaddr) do{ \
  584. ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }while(0)
  585. /** @ingroup ip6addr */
  586. #define ip_addr_set_zero_ip6(ipaddr) do{ \
  587. ip6_addr_set_zero(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }while(0)
  588. /** @ingroup ipaddr */
  589. #define ip_addr_set_any(is_ipv6, ipaddr) do{if(is_ipv6){ \
  590. ip6_addr_set_any(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }else{ \
  591. ip4_addr_set_any(ip_2_ip4(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
  592. /** @ingroup ipaddr */
  593. #define ip_addr_set_loopback(is_ipv6, ipaddr) do{if(is_ipv6){ \
  594. ip6_addr_set_loopback(ip_2_ip6(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V6); }else{ \
  595. ip4_addr_set_loopback(ip_2_ip4(ipaddr)); IP_SET_TYPE(ipaddr, IPADDR_TYPE_V4); }}while(0)
  596. /** @ingroup ipaddr */
  597. #define ip_addr_set_hton(dest, src) do{if(IP_IS_V6(src)){ \
  598. ip6_addr_set_hton(ip_2_ip6(ipaddr), (src)); IP_SET_TYPE(dest, IPADDR_TYPE_V6); }else{ \
  599. ip4_addr_set_hton(ip_2_ip4(ipaddr), (src)); IP_SET_TYPE(dest, IPADDR_TYPE_V4); }}while(0)
  600. /** @ingroup ipaddr */
  601. #define ip_addr_get_network(target, host, netmask) do{if(IP_IS_V6(host)){ \
  602. ip4_addr_set_zero(ip_2_ip4(target)); IP_SET_TYPE(target, IPADDR_TYPE_V6); } else { \
  603. ip4_addr_get_network(ip_2_ip4(target), ip_2_ip4(host), ip_2_ip4(netmask)); IP_SET_TYPE(target, IPADDR_TYPE_V4); }}while(0)
  604. /** @ingroup ipaddr */
  605. #define ip_addr_netcmp(addr1, addr2, mask) ((IP_IS_V6(addr1) && IP_IS_V6(addr2)) ? \
  606. 0 : \
  607. ip4_addr_netcmp(ip_2_ip4(addr1), ip_2_ip4(addr2), mask))
  608. /** @ingroup ipaddr */
  609. #define ip_addr_cmp(addr1, addr2) ((IP_GET_TYPE(addr1) != IP_GET_TYPE(addr2)) ? 0 : (IP_IS_V6_VAL(*(addr1)) ? \
  610. ip6_addr_cmp(ip_2_ip6(addr1), ip_2_ip6(addr2)) : \
  611. ip4_addr_cmp(ip_2_ip4(addr1), ip_2_ip4(addr2))))
  612. /** @ingroup ipaddr */
  613. #define ip_addr_isany(ipaddr) ((IP_IS_V6(ipaddr)) ? \
  614. ip6_addr_isany(ip_2_ip6(ipaddr)) : \
  615. ip4_addr_isany(ip_2_ip4(ipaddr)))
  616. /** @ingroup ipaddr */
  617. #define ip_addr_isany_val(ipaddr) ((IP_IS_V6_VAL(ipaddr)) ? \
  618. ip6_addr_isany_val(*ip_2_ip6(&(ipaddr))) : \
  619. ip4_addr_isany_val(*ip_2_ip4(&(ipaddr))))
  620. /** @ingroup ipaddr */
  621. #define ip_addr_isbroadcast(ipaddr, netif) ((IP_IS_V6(ipaddr)) ? \
  622. 0 : \
  623. ip4_addr_isbroadcast(ip_2_ip4(ipaddr), netif))
  624. /** @ingroup ipaddr */
  625. #define ip_addr_ismulticast(ipaddr) ((IP_IS_V6(ipaddr)) ? \
  626. ip6_addr_ismulticast(ip_2_ip6(ipaddr)) : \
  627. ip4_addr_ismulticast(ip_2_ip4(ipaddr)))
  628. /** @ingroup ipaddr */
  629. #define ip_addr_isloopback(ipaddr) ((IP_IS_V6(ipaddr)) ? \
  630. ip6_addr_isloopback(ip_2_ip6(ipaddr)) : \
  631. ip4_addr_isloopback(ip_2_ip4(ipaddr)))
  632. /** @ingroup ipaddr */
  633. #define ip_addr_islinklocal(ipaddr) ((IP_IS_V6(ipaddr)) ? \
  634. ip6_addr_islinklocal(ip_2_ip6(ipaddr)) : \
  635. ip4_addr_islinklocal(ip_2_ip4(ipaddr)))
  636. #define ip_addr_debug_print(debug, ipaddr) do { if(IP_IS_V6(ipaddr)) { \
  637. ip6_addr_debug_print(debug, ip_2_ip6(ipaddr)); } else { \
  638. ip4_addr_debug_print(debug, ip_2_ip4(ipaddr)); }}while(0)
  639. #define ip_addr_debug_print_val(debug, ipaddr) do { if(IP_IS_V6_VAL(ipaddr)) { \
  640. ip6_addr_debug_print_val(debug, *ip_2_ip6(&(ipaddr))); } else { \
  641. ip4_addr_debug_print_val(debug, *ip_2_ip4(&(ipaddr))); }}while(0)
  642. /** @ingroup ipaddr */
  643. #define ipaddr_ntoa(addr) (((addr) == NULL) ? "NULL" : \
  644. ((IP_IS_V6(addr)) ? ip6addr_ntoa(ip_2_ip6(addr)) : ip4addr_ntoa(ip_2_ip4(addr))))
  645. /** @ingroup ipaddr */
  646. #define ipaddr_ntoa_r(addr, buf, buflen) (((addr) == NULL) ? "NULL" : \
  647. ((IP_IS_V6(addr)) ? ip6addr_ntoa_r(ip_2_ip6(addr), buf, buflen) : ip4addr_ntoa_r(ip_2_ip4(addr), buf, buflen)))
  648. int ipaddr_aton(const char *cp, ip_addr_t *addr);
  649. /** @ingroup ipaddr */
  650. #define IPADDR_STRLEN_MAX IP6ADDR_STRLEN_MAX
  651. #else /* LWIP_IPV4 && LWIP_IPV6 */
  652. #define IP_ADDR_PCB_VERSION_MATCH(addr, pcb) 1
  653. #define IP_ADDR_PCB_VERSION_MATCH_EXACT(pcb, ipaddr) 1
  654. #if LWIP_IPV4
  655. typedef ip4_addr_t ip_addr_t;
  656. #define IPADDR4_INIT(u32val) { u32val }
  657. #define IP_IS_V4_VAL(ipaddr) 1
  658. #define IP_IS_V6_VAL(ipaddr) 0
  659. #define IP_IS_V4(ipaddr) 1
  660. #define IP_IS_V6(ipaddr) 0
  661. #define IP_IS_ANY_TYPE_VAL(ipaddr) 0
  662. #define IP_SET_TYPE_VAL(ipaddr, iptype)
  663. #define IP_SET_TYPE(ipaddr, iptype)
  664. #define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V4
  665. #define ip_2_ip4(ipaddr) (ipaddr)
  666. #define IP_ADDR4(ipaddr,a,b,c,d) IP4_ADDR(ipaddr,a,b,c,d)
  667. #define ip_addr_copy(dest, src) ip4_addr_copy(dest, src)
  668. #define ip_addr_copy_from_ip4(dest, src) ip4_addr_copy(dest, src)
  669. #define ip_addr_set_ip4_u32(ipaddr, val) ip4_addr_set_u32(ip_2_ip4(ipaddr), val)
  670. #define ip_addr_get_ip4_u32(ipaddr) ip4_addr_get_u32(ip_2_ip4(ipaddr))
  671. #define ip_addr_set(dest, src) ip4_addr_set(dest, src)
  672. #define ip_addr_set_ipaddr(dest, src) ip4_addr_set(dest, src)
  673. #define ip_addr_set_zero(ipaddr) ip4_addr_set_zero(ipaddr)
  674. #define ip_addr_set_zero_ip4(ipaddr) ip4_addr_set_zero(ipaddr)
  675. #define ip_addr_set_any(is_ipv6, ipaddr) ip4_addr_set_any(ipaddr)
  676. #define ip_addr_set_loopback(is_ipv6, ipaddr) ip4_addr_set_loopback(ipaddr)
  677. #define ip_addr_set_hton(dest, src) ip4_addr_set_hton(dest, src)
  678. #define ip_addr_get_network(target, host, mask) ip4_addr_get_network(target, host, mask)
  679. #define ip_addr_netcmp(addr1, addr2, mask) ip4_addr_netcmp(addr1, addr2, mask)
  680. #define ip_addr_cmp(addr1, addr2) ip4_addr_cmp(addr1, addr2)
  681. #define ip_addr_isany(ipaddr) ip4_addr_isany(ipaddr)
  682. #define ip_addr_isany_val(ipaddr) ip4_addr_isany_val(ipaddr)
  683. #define ip_addr_isloopback(ipaddr) ip4_addr_isloopback(ipaddr)
  684. #define ip_addr_islinklocal(ipaddr) ip4_addr_islinklocal(ipaddr)
  685. #define ip_addr_isbroadcast(addr, netif) ip4_addr_isbroadcast(addr, netif)
  686. #define ip_addr_ismulticast(ipaddr) ip4_addr_ismulticast(ipaddr)
  687. #define ip_addr_debug_print(debug, ipaddr) ip4_addr_debug_print(debug, ipaddr)
  688. #define ip_addr_debug_print_val(debug, ipaddr) ip4_addr_debug_print_val(debug, ipaddr)
  689. #define ipaddr_ntoa(ipaddr) ip4addr_ntoa(ipaddr)
  690. #define ipaddr_ntoa_r(ipaddr, buf, buflen) ip4addr_ntoa_r(ipaddr, buf, buflen)
  691. #define ipaddr_aton(cp, addr) ip4addr_aton(cp, addr)
  692. #define IPADDR_STRLEN_MAX IP4ADDR_STRLEN_MAX
  693. #else /* LWIP_IPV4 */
  694. typedef ip6_addr_t ip_addr_t;
  695. #define IPADDR6_INIT(a, b, c, d) { { a, b, c, d } }
  696. #define IP_IS_V4_VAL(ipaddr) 0
  697. #define IP_IS_V6_VAL(ipaddr) 1
  698. #define IP_IS_V4(ipaddr) 0
  699. #define IP_IS_V6(ipaddr) 1
  700. #define IP_IS_ANY_TYPE_VAL(ipaddr) 0
  701. #define IP_SET_TYPE_VAL(ipaddr, iptype)
  702. #define IP_SET_TYPE(ipaddr, iptype)
  703. #define IP_GET_TYPE(ipaddr) IPADDR_TYPE_V6
  704. #define ip_2_ip6(ipaddr) (ipaddr)
  705. #define IP_ADDR6(ipaddr,i0,i1,i2,i3) IP6_ADDR(ipaddr,i0,i1,i2,i3)
  706. #define ip_addr_copy(dest, src) ip6_addr_copy(dest, src)
  707. #define ip_addr_copy_from_ip6(dest, src) ip6_addr_copy(dest, src)
  708. #define ip_addr_set(dest, src) ip6_addr_set(dest, src)
  709. #define ip_addr_set_ipaddr(dest, src) ip6_addr_set(dest, src)
  710. #define ip_addr_set_zero(ipaddr) ip6_addr_set_zero(ipaddr)
  711. #define ip_addr_set_zero_ip6(ipaddr) ip6_addr_set_zero(ipaddr)
  712. #define ip_addr_set_any(is_ipv6, ipaddr) ip6_addr_set_any(ipaddr)
  713. #define ip_addr_set_loopback(is_ipv6, ipaddr) ip6_addr_set_loopback(ipaddr)
  714. #define ip_addr_set_hton(dest, src) ip6_addr_set_hton(dest, src)
  715. #define ip_addr_get_network(target, host, mask) ip6_addr_set_zero(target)
  716. #define ip_addr_netcmp(addr1, addr2, mask) 0
  717. #define ip_addr_cmp(addr1, addr2) ip6_addr_cmp(addr1, addr2)
  718. #define ip_addr_isany(ipaddr) ip6_addr_isany(ipaddr)
  719. #define ip_addr_isany_val(ipaddr) ip6_addr_isany_val(ipaddr)
  720. #define ip_addr_isloopback(ipaddr) ip6_addr_isloopback(ipaddr)
  721. #define ip_addr_islinklocal(ipaddr) ip6_addr_islinklocal(ipaddr)
  722. #define ip_addr_isbroadcast(addr, netif) 0
  723. #define ip_addr_ismulticast(ipaddr) ip6_addr_ismulticast(ipaddr)
  724. #define ip_addr_debug_print(debug, ipaddr) ip6_addr_debug_print(debug, ipaddr)
  725. #define ip_addr_debug_print_val(debug, ipaddr) ip6_addr_debug_print_val(debug, ipaddr)
  726. #define ipaddr_ntoa(ipaddr) ip6addr_ntoa(ipaddr)
  727. #define ipaddr_ntoa_r(ipaddr, buf, buflen) ip6addr_ntoa_r(ipaddr, buf, buflen)
  728. #define ipaddr_aton(cp, addr) ip6addr_aton(cp, addr)
  729. #define IPADDR_STRLEN_MAX IP6ADDR_STRLEN_MAX
  730. #endif /* LWIP_IPV4 */
  731. #endif /* LWIP_IPV4 && LWIP_IPV6 */
  732. #if LWIP_IPV4
  733. extern const ip_addr_t ip_addr_any;
  734. extern const ip_addr_t ip_addr_broadcast;
  735. /**
  736. * @ingroup ip4addr
  737. * Provided for compatibility. Use IP4_ADDR_ANY for better readability.
  738. */
  739. #define IP_ADDR_ANY IP4_ADDR_ANY
  740. /**
  741. * @ingroup ip4addr
  742. * Can be used as a fixed/const ip_addr_t
  743. * for the IPv4 wildcard and the broadcast address
  744. */
  745. #define IP4_ADDR_ANY (&ip_addr_any)
  746. /**
  747. * @ingroup ip4addr
  748. * Can be used as a fixed/const ip4_addr_t
  749. * for the wildcard and the broadcast address
  750. */
  751. #define IP4_ADDR_ANY4 (ip_2_ip4(&ip_addr_any))
  752. /** @ingroup ip4addr */
  753. #define IP_ADDR_BROADCAST (&ip_addr_broadcast)
  754. /** @ingroup ip4addr */
  755. #define IP4_ADDR_BROADCAST (ip_2_ip4(&ip_addr_broadcast))
  756. #endif /* LWIP_IPV4*/
  757. #if LWIP_IPV6
  758. extern const ip_addr_t ip6_addr_any;
  759. /**
  760. * @ingroup ip6addr
  761. * IP6_ADDR_ANY can be used as a fixed ip_addr_t
  762. * for the IPv6 wildcard address
  763. */
  764. #define IP6_ADDR_ANY (&ip6_addr_any)
  765. /**
  766. * @ingroup ip6addr
  767. * IP6_ADDR_ANY6 can be used as a fixed ip6_addr_t
  768. * for the IPv6 wildcard address
  769. */
  770. #define IP6_ADDR_ANY6 (ip_2_ip6(&ip6_addr_any))
  771. #if !LWIP_IPV4
  772. /** Just a little upgrade-helper for IPv6-only configurations: */
  773. #define IP_ADDR_ANY IP6_ADDR_ANY
  774. #endif /* !LWIP_IPV4 */
  775. #endif
  776. #if LWIP_IPV4 && LWIP_IPV6
  777. /** @ingroup ipaddr */
  778. #define IP_ANY_TYPE (&ip_addr_any_type)
  779. #else
  780. #define IP_ANY_TYPE IP_ADDR_ANY
  781. #endif
  782. /* From src/include/lwip/netif.h: */
  783. /* Throughout this file, IP addresses are expected to be in
  784. * the same byte order as in IP_PCB. */
  785. /** Must be the maximum of all used hardware address lengths
  786. across all types of interfaces in use.
  787. This does not have to be changed, normally. */
  788. #ifndef NETIF_MAX_HWADDR_LEN
  789. #define NETIF_MAX_HWADDR_LEN 6U
  790. #endif
  791. /**
  792. * @defgroup netif_flags Flags
  793. * @ingroup netif
  794. * @{
  795. */
  796. /** Whether the network interface is 'up'. This is
  797. * a software flag used to control whether this network
  798. * interface is enabled and processes traffic.
  799. * It must be set by the startup code before this netif can be used
  800. * (also for dhcp/autoip).
  801. */
  802. #define NETIF_FLAG_UP 0x01U
  803. /** If set, the netif has broadcast capability.
  804. * Set by the netif driver in its init function. */
  805. #define NETIF_FLAG_BROADCAST 0x02U
  806. /** If set, the interface has an active link
  807. * (set by the network interface driver).
  808. * Either set by the netif driver in its init function (if the link
  809. * is up at that time) or at a later point once the link comes up
  810. * (if link detection is supported by the hardware). */
  811. #define NETIF_FLAG_LINK_UP 0x04U
  812. /** If set, the netif is an ethernet device using ARP.
  813. * Set by the netif driver in its init function.
  814. * Used to check input packet types and use of DHCP. */
  815. #define NETIF_FLAG_ETHARP 0x08U
  816. /** If set, the netif is an ethernet device. It might not use
  817. * ARP or TCP/IP if it is used for PPPoE only.
  818. */
  819. #define NETIF_FLAG_ETHERNET 0x10U
  820. /** If set, the netif has IGMP capability.
  821. * Set by the netif driver in its init function. */
  822. #define NETIF_FLAG_IGMP 0x20U
  823. /** If set, the netif has MLD6 capability.
  824. * Set by the netif driver in its init function. */
  825. #define NETIF_FLAG_MLD6 0x40U
  826. /**
  827. * @}
  828. */
  829. enum lwip_internal_netif_client_data_index
  830. {
  831. #if LWIP_DHCP
  832. LWIP_NETIF_CLIENT_DATA_INDEX_DHCP,
  833. #endif
  834. #if LWIP_AUTOIP
  835. LWIP_NETIF_CLIENT_DATA_INDEX_AUTOIP,
  836. #endif
  837. #if LWIP_IGMP
  838. LWIP_NETIF_CLIENT_DATA_INDEX_IGMP,
  839. #endif
  840. #if LWIP_IPV6_MLD
  841. LWIP_NETIF_CLIENT_DATA_INDEX_MLD6,
  842. #endif
  843. LWIP_NETIF_CLIENT_DATA_INDEX_MAX
  844. };
  845. #if LWIP_CHECKSUM_CTRL_PER_NETIF
  846. #define NETIF_CHECKSUM_GEN_IP 0x0001
  847. #define NETIF_CHECKSUM_GEN_UDP 0x0002
  848. #define NETIF_CHECKSUM_GEN_TCP 0x0004
  849. #define NETIF_CHECKSUM_GEN_ICMP 0x0008
  850. #define NETIF_CHECKSUM_GEN_ICMP6 0x0010
  851. #define NETIF_CHECKSUM_CHECK_IP 0x0100
  852. #define NETIF_CHECKSUM_CHECK_UDP 0x0200
  853. #define NETIF_CHECKSUM_CHECK_TCP 0x0400
  854. #define NETIF_CHECKSUM_CHECK_ICMP 0x0800
  855. #define NETIF_CHECKSUM_CHECK_ICMP6 0x1000
  856. #define NETIF_CHECKSUM_ENABLE_ALL 0xFFFF
  857. #define NETIF_CHECKSUM_DISABLE_ALL 0x0000
  858. #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
  859. struct netif;
  860. /** MAC Filter Actions, these are passed to a netif's igmp_mac_filter or
  861. * mld_mac_filter callback function. */
  862. enum netif_mac_filter_action {
  863. /** Delete a filter entry */
  864. NETIF_DEL_MAC_FILTER = 0,
  865. /** Add a filter entry */
  866. NETIF_ADD_MAC_FILTER = 1
  867. };
  868. /** Function prototype for netif init functions. Set up flags and output/linkoutput
  869. * callback functions in this function.
  870. *
  871. * @param netif The netif to initialize
  872. */
  873. typedef err_t (*netif_init_fn)(struct netif *netif);
  874. /** Function prototype for netif->input functions. This function is saved as 'input'
  875. * callback function in the netif struct. Call it when a packet has been received.
  876. *
  877. * @param p The received packet, copied into a pbuf
  878. * @param inp The netif which received the packet
  879. */
  880. typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
  881. #if LWIP_IPV4
  882. /** Function prototype for netif->output functions. Called by lwIP when a packet
  883. * shall be sent. For ethernet netif, set this to 'etharp_output' and set
  884. * 'linkoutput'.
  885. *
  886. * @param netif The netif which shall send a packet
  887. * @param p The packet to send (p->payload points to IP header)
  888. * @param ipaddr The IP address to which the packet shall be sent
  889. */
  890. typedef err_t (*netif_output_fn)(struct netif *netif, struct pbuf *p,
  891. const ip4_addr_t *ipaddr);
  892. #endif /* LWIP_IPV4*/
  893. #if LWIP_IPV6
  894. /** Function prototype for netif->output_ip6 functions. Called by lwIP when a packet
  895. * shall be sent. For ethernet netif, set this to 'ethip6_output' and set
  896. * 'linkoutput'.
  897. *
  898. * @param netif The netif which shall send a packet
  899. * @param p The packet to send (p->payload points to IP header)
  900. * @param ipaddr The IPv6 address to which the packet shall be sent
  901. */
  902. typedef err_t (*netif_output_ip6_fn)(struct netif *netif, struct pbuf *p,
  903. const ip6_addr_t *ipaddr);
  904. #endif /* LWIP_IPV6 */
  905. /** Function prototype for netif->linkoutput functions. Only used for ethernet
  906. * netifs. This function is called by ARP when a packet shall be sent.
  907. *
  908. * @param netif The netif which shall send a packet
  909. * @param p The packet to send (raw ethernet packet)
  910. */
  911. typedef err_t (*netif_linkoutput_fn)(struct netif *netif, struct pbuf *p);
  912. /** Function prototype for netif status- or link-callback functions. */
  913. typedef void (*netif_status_callback_fn)(struct netif *netif);
  914. #if LWIP_IPV4 && LWIP_IGMP
  915. /** Function prototype for netif igmp_mac_filter functions */
  916. typedef err_t (*netif_igmp_mac_filter_fn)(struct netif *netif,
  917. const ip4_addr_t *group, enum netif_mac_filter_action action);
  918. #endif /* LWIP_IPV4 && LWIP_IGMP */
  919. #if LWIP_IPV6 && LWIP_IPV6_MLD
  920. /** Function prototype for netif mld_mac_filter functions */
  921. typedef err_t (*netif_mld_mac_filter_fn)(struct netif *netif,
  922. const ip6_addr_t *group, enum netif_mac_filter_action action);
  923. #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
  924. #if LWIP_DHCP || LWIP_AUTOIP || LWIP_IGMP || LWIP_IPV6_MLD || (LWIP_NUM_NETIF_CLIENT_DATA > 0)
  925. u8 netif_alloc_client_data_id(void);
  926. /** @ingroup netif_cd
  927. * Set client data. Obtain ID from netif_alloc_client_data_id().
  928. */
  929. #define netif_set_client_data(netif, id, data) netif_get_client_data(netif, id) = (data)
  930. /** @ingroup netif_cd
  931. * Get client data. Obtain ID from netif_alloc_client_data_id().
  932. */
  933. #define netif_get_client_data(netif, id) (netif)->client_data[(id)]
  934. #endif /* LWIP_DHCP || LWIP_AUTOIP || (LWIP_NUM_NETIF_CLIENT_DATA > 0) */
  935. /** Generic data structure used for all lwIP network interfaces.
  936. * The following fields should be filled in by the initialization
  937. * function for the device driver: hwaddr_len, hwaddr[], mtu, flags */
  938. struct netif {
  939. /** pointer to next in linked list */
  940. struct netif *next;
  941. #if LWIP_IPV4
  942. /** IP address configuration in network byte order */
  943. ip_addr_t ip_addr;
  944. ip_addr_t netmask;
  945. ip_addr_t gw;
  946. #endif /* LWIP_IPV4 */
  947. #if LWIP_IPV6
  948. /** Array of IPv6 addresses for this netif. */
  949. ip_addr_t ip6_addr[LWIP_IPV6_NUM_ADDRESSES];
  950. /** The state of each IPv6 address (Tentative, Preferred, etc).
  951. * @see ip6_addr.h */
  952. u8 ip6_addr_state[LWIP_IPV6_NUM_ADDRESSES];
  953. #endif /* LWIP_IPV6 */
  954. /** This function is called by the network device driver
  955. * to pass a packet up the TCP/IP stack. */
  956. netif_input_fn input;
  957. #if LWIP_IPV4
  958. /** This function is called by the IP module when it wants
  959. * to send a packet on the interface. This function typically
  960. * first resolves the hardware address, then sends the packet.
  961. * For ethernet physical layer, this is usually etharp_output() */
  962. netif_output_fn output;
  963. #endif /* LWIP_IPV4 */
  964. /** This function is called by ethernet_output() when it wants
  965. * to send a packet on the interface. This function outputs
  966. * the pbuf as-is on the link medium. */
  967. netif_linkoutput_fn linkoutput;
  968. #if LWIP_IPV6
  969. /** This function is called by the IPv6 module when it wants
  970. * to send a packet on the interface. This function typically
  971. * first resolves the hardware address, then sends the packet.
  972. * For ethernet physical layer, this is usually ethip6_output() */
  973. netif_output_ip6_fn output_ip6;
  974. #endif /* LWIP_IPV6 */
  975. #if LWIP_NETIF_STATUS_CALLBACK
  976. /** This function is called when the netif state is set to up or down
  977. */
  978. netif_status_callback_fn status_callback;
  979. #endif /* LWIP_NETIF_STATUS_CALLBACK */
  980. #if LWIP_NETIF_LINK_CALLBACK
  981. /** This function is called when the netif link is set to up or down
  982. */
  983. netif_status_callback_fn link_callback;
  984. #endif /* LWIP_NETIF_LINK_CALLBACK */
  985. #if LWIP_NETIF_REMOVE_CALLBACK
  986. /** This function is called when the netif has been removed */
  987. netif_status_callback_fn remove_callback;
  988. #endif /* LWIP_NETIF_REMOVE_CALLBACK */
  989. /** This field can be set by the device driver and could point
  990. * to state information for the device. */
  991. void *state;
  992. #ifdef netif_get_client_data
  993. void* client_data[LWIP_NETIF_CLIENT_DATA_INDEX_MAX + LWIP_NUM_NETIF_CLIENT_DATA];
  994. #endif
  995. #if LWIP_IPV6_AUTOCONFIG
  996. /** is this netif enabled for IPv6 autoconfiguration */
  997. u8 ip6_autoconfig_enabled;
  998. #endif /* LWIP_IPV6_AUTOCONFIG */
  999. #if LWIP_IPV6_SEND_ROUTER_SOLICIT
  1000. /** Number of Router Solicitation messages that remain to be sent. */
  1001. u8 rs_count;
  1002. #endif /* LWIP_IPV6_SEND_ROUTER_SOLICIT */
  1003. #if LWIP_NETIF_HOSTNAME
  1004. /* the hostname for this netif, NULL is a valid value */
  1005. const char* hostname;
  1006. #endif /* LWIP_NETIF_HOSTNAME */
  1007. #if LWIP_CHECKSUM_CTRL_PER_NETIF
  1008. u16 chksum_flags;
  1009. #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF*/
  1010. /** maximum transfer unit (in bytes) */
  1011. u16 mtu;
  1012. /** number of bytes used in hwaddr */
  1013. u8 hwaddr_len;
  1014. /** link level hardware address of this interface */
  1015. u8 hwaddr[NETIF_MAX_HWADDR_LEN];
  1016. /** flags (@see @ref netif_flags) */
  1017. u8 flags;
  1018. /** descriptive abbreviation */
  1019. char name[2];
  1020. /** number of this interface */
  1021. u8 num;
  1022. #if MIB2_STATS
  1023. /** link type (from "snmp_ifType" enum from snmp_mib2.h) */
  1024. u8 link_type;
  1025. /** (estimate) link speed */
  1026. u32 link_speed;
  1027. /** timestamp at last change made (up/down) */
  1028. u32 ts;
  1029. /** counters */
  1030. struct stats_mib2_netif_ctrs mib2_counters;
  1031. #endif /* MIB2_STATS */
  1032. #if LWIP_IPV4 && LWIP_IGMP
  1033. /** This function could be called to add or delete an entry in the multicast
  1034. filter table of the ethernet MAC.*/
  1035. netif_igmp_mac_filter_fn igmp_mac_filter;
  1036. #endif /* LWIP_IPV4 && LWIP_IGMP */
  1037. #if LWIP_IPV6 && LWIP_IPV6_MLD
  1038. /** This function could be called to add or delete an entry in the IPv6 multicast
  1039. filter table of the ethernet MAC. */
  1040. netif_mld_mac_filter_fn mld_mac_filter;
  1041. #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
  1042. #if LWIP_NETIF_HWADDRHINT
  1043. u8 *addr_hint;
  1044. #endif /* LWIP_NETIF_HWADDRHINT */
  1045. #if ENABLE_LOOPBACK
  1046. /* List of packets to be queued for ourselves. */
  1047. struct pbuf *loop_first;
  1048. struct pbuf *loop_last;
  1049. #if LWIP_LOOPBACK_MAX_PBUFS
  1050. u16 loop_cnt_current;
  1051. #endif /* LWIP_LOOPBACK_MAX_PBUFS */
  1052. #endif /* ENABLE_LOOPBACK */
  1053. };
  1054. #if LWIP_CHECKSUM_CTRL_PER_NETIF
  1055. #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags) do { \
  1056. (netif)->chksum_flags = chksumflags; } while(0)
  1057. #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag) if (((netif) == NULL) || (((netif)->chksum_flags & (chksumflag)) != 0))
  1058. #else /* LWIP_CHECKSUM_CTRL_PER_NETIF */
  1059. #define NETIF_SET_CHECKSUM_CTRL(netif, chksumflags)
  1060. #define IF__NETIF_CHECKSUM_ENABLED(netif, chksumflag)
  1061. #endif /* LWIP_CHECKSUM_CTRL_PER_NETIF */
  1062. /** The list of network interfaces. */
  1063. extern struct netif *netif_list;
  1064. /** The default network interface. */
  1065. extern struct netif *netif_default;
  1066. #if LWIP_IPV4
  1067. /** @ingroup netif_ip4 */
  1068. #define netif_ip4_addr(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->ip_addr)))
  1069. /** @ingroup netif_ip4 */
  1070. #define netif_ip4_netmask(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->netmask)))
  1071. /** @ingroup netif_ip4 */
  1072. #define netif_ip4_gw(netif) ((const ip4_addr_t*)ip_2_ip4(&((netif)->gw)))
  1073. /** @ingroup netif_ip4 */
  1074. #define netif_ip_addr4(netif) ((const ip_addr_t*)&((netif)->ip_addr))
  1075. /** @ingroup netif_ip4 */
  1076. #define netif_ip_netmask4(netif) ((const ip_addr_t*)&((netif)->netmask))
  1077. /** @ingroup netif_ip4 */
  1078. #define netif_ip_gw4(netif) ((const ip_addr_t*)&((netif)->gw))
  1079. #endif /* LWIP_IPV4 */
  1080. /** @ingroup netif
  1081. * Ask if an interface is up
  1082. */
  1083. #define netif_is_up(netif) (((netif)->flags & NETIF_FLAG_UP) ? (u8)1 : (u8)0)
  1084. /** Ask if a link is up */
  1085. #define netif_is_link_up(netif) (((netif)->flags & NETIF_FLAG_LINK_UP) ? (u8)1 : (u8)0)
  1086. #if LWIP_NETIF_HOSTNAME
  1087. /** @ingroup netif */
  1088. #define netif_set_hostname(netif, name) do { if((netif) != NULL) { (netif)->hostname = name; }}while(0)
  1089. /** @ingroup netif */
  1090. #define netif_get_hostname(netif) (((netif) != NULL) ? ((netif)->hostname) : NULL)
  1091. #endif /* LWIP_NETIF_HOSTNAME */
  1092. #if LWIP_IGMP
  1093. /** @ingroup netif */
  1094. #define netif_set_igmp_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->igmp_mac_filter = function; }}while(0)
  1095. #define netif_get_igmp_mac_filter(netif) (((netif) != NULL) ? ((netif)->igmp_mac_filter) : NULL)
  1096. #endif /* LWIP_IGMP */
  1097. #if LWIP_IPV6 && LWIP_IPV6_MLD
  1098. /** @ingroup netif */
  1099. #define netif_set_mld_mac_filter(netif, function) do { if((netif) != NULL) { (netif)->mld_mac_filter = function; }}while(0)
  1100. #define netif_get_mld_mac_filter(netif) (((netif) != NULL) ? ((netif)->mld_mac_filter) : NULL)
  1101. #define netif_mld_mac_filter(netif, addr, action) do { if((netif) && (netif)->mld_mac_filter) { (netif)->mld_mac_filter((netif), (addr), (action)); }}while(0)
  1102. #endif /* LWIP_IPV6 && LWIP_IPV6_MLD */
  1103. #if LWIP_IPV6
  1104. /** @ingroup netif_ip6 */
  1105. #define netif_ip_addr6(netif, i) ((const ip_addr_t*)(&((netif)->ip6_addr[i])))
  1106. /** @ingroup netif_ip6 */
  1107. #define netif_ip6_addr(netif, i) ((const ip6_addr_t*)ip_2_ip6(&((netif)->ip6_addr[i])))
  1108. void netif_ip6_addr_set(struct netif *netif, s8_t addr_idx, const ip6_addr_t *addr6);
  1109. void netif_ip6_addr_set_parts(struct netif *netif, s8_t addr_idx, u32 i0, u32 i1, u32 i2, u32 i3);
  1110. #define netif_ip6_addr_state(netif, i) ((netif)->ip6_addr_state[i])
  1111. #define netif_set_ip6_autoconfig_enabled(netif, action) do { if(netif) { (netif)->ip6_autoconfig_enabled = (action); }}while(0)
  1112. #endif /* LWIP_IPV6 */
  1113. #if LWIP_NETIF_HWADDRHINT
  1114. #define NETIF_SET_HWADDRHINT(netif, hint) ((netif)->addr_hint = (hint))
  1115. #else /* LWIP_NETIF_HWADDRHINT */
  1116. #define NETIF_SET_HWADDRHINT(netif, hint)
  1117. #endif /* LWIP_NETIF_HWADDRHINT */
  1118. /* From include/lwip/prot/dhcp.h: */
  1119. /* DHCP client states */
  1120. typedef enum {
  1121. DHCP_STATE_OFF = 0,
  1122. DHCP_STATE_REQUESTING = 1,
  1123. DHCP_STATE_INIT = 2,
  1124. DHCP_STATE_REBOOTING = 3,
  1125. DHCP_STATE_REBINDING = 4,
  1126. DHCP_STATE_RENEWING = 5,
  1127. DHCP_STATE_SELECTING = 6,
  1128. DHCP_STATE_INFORMING = 7,
  1129. DHCP_STATE_CHECKING = 8,
  1130. DHCP_STATE_PERMANENT = 9, /* not yet implemented */
  1131. DHCP_STATE_BOUND = 10,
  1132. DHCP_STATE_RELEASING = 11, /* not yet implemented */
  1133. DHCP_STATE_BACKING_OFF = 12
  1134. } dhcp_state_enum_t;
  1135. /* From include/lwip/inet.h: */
  1136. struct in_addr {
  1137. u32 s_addr;
  1138. };
  1139. struct in6_addr {
  1140. union {
  1141. u32 u32_addr[4];
  1142. u8 u8_addr[16];
  1143. } un;
  1144. #define s6_addr un.u8_addr
  1145. };
  1146. /** 255.255.255.255 */
  1147. #define INADDR_NONE IPADDR_NONE
  1148. /** 127.0.0.1 */
  1149. #define INADDR_LOOPBACK IPADDR_LOOPBACK
  1150. /** 0.0.0.0 */
  1151. #define INADDR_ANY IPADDR_ANY
  1152. /** 255.255.255.255 */
  1153. #define INADDR_BROADCAST IPADDR_BROADCAST
  1154. /* If your port already typedef's sa_family_t, define SA_FAMILY_T_DEFINED
  1155. to prevent this code from redefining it. */
  1156. #if !defined(sa_family_t) && !defined(SA_FAMILY_T_DEFINED)
  1157. typedef u8 sa_family_t;
  1158. #endif
  1159. /* If your port already typedef's in_port_t, define IN_PORT_T_DEFINED
  1160. to prevent this code from redefining it. */
  1161. #if !defined(in_port_t) && !defined(IN_PORT_T_DEFINED)
  1162. typedef u16 in_port_t;
  1163. #endif
  1164. #if LWIP_IPV4
  1165. /* members are in network byte order */
  1166. struct sockaddr_in {
  1167. u8 sin_len;
  1168. sa_family_t sin_family;
  1169. in_port_t sin_port;
  1170. struct in_addr sin_addr;
  1171. #define SIN_ZERO_LEN 8
  1172. char sin_zero[SIN_ZERO_LEN];
  1173. };
  1174. #endif /* LWIP_IPV4 */
  1175. #if LWIP_IPV6
  1176. struct sockaddr_in6 {
  1177. u8 sin6_len; /* length of this structure */
  1178. sa_family_t sin6_family; /* AF_INET6 */
  1179. in_port_t sin6_port; /* Transport layer port # */
  1180. u32 sin6_flowinfo; /* IPv6 flow information */
  1181. struct in6_addr sin6_addr; /* IPv6 address */
  1182. u32 sin6_scope_id; /* Set of interfaces for scope */
  1183. };
  1184. #endif /* LWIP_IPV6 */
  1185. struct sockaddr {
  1186. u8 sa_len;
  1187. sa_family_t sa_family;
  1188. char sa_data[14];
  1189. };
  1190. struct sockaddr_storage {
  1191. u8 s2_len;
  1192. sa_family_t ss_family;
  1193. char s2_data1[2];
  1194. u32 s2_data2[3];
  1195. #if LWIP_IPV6
  1196. u32 s2_data3[3];
  1197. #endif /* LWIP_IPV6 */
  1198. };
  1199. /* Define SOCKLEN_T_DEFINED to prevent other code from redefining socklen_t. */
  1200. #define SOCKLEN_T_DEFINED 1
  1201. typedef int socklen_t;
  1202. /* Socket protocol types (TCP/UDP/RAW) */
  1203. #define SOCK_STREAM 1
  1204. #define SOCK_DGRAM 2
  1205. #define SOCK_RAW 3
  1206. /*
  1207. * Option flags per-socket. These must match the SOF_ flags in ip.h (checked in init.c)
  1208. */
  1209. #define SO_REUSEADDR 0x0004 /* Allow local address reuse */
  1210. #define SO_KEEPALIVE 0x0008 /* keep connections alive */
  1211. #define SO_BROADCAST 0x0020 /* permit to send and to receive broadcast messages (see IP_SOF_BROADCAST option) */
  1212. /*
  1213. * Additional options, not kept in so_options.
  1214. */
  1215. #define SO_DEBUG 0x0001 /* Unimplemented: turn on debugging info recording */
  1216. #define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
  1217. #define SO_DONTROUTE 0x0010 /* Unimplemented: just use interface addresses */
  1218. #define SO_USELOOPBACK 0x0040 /* Unimplemented: bypass hardware when possible */
  1219. #define SO_LINGER 0x0080 /* linger on close if data present */
  1220. #define SO_DONTLINGER ((int)(~SO_LINGER))
  1221. #define SO_OOBINLINE 0x0100 /* Unimplemented: leave received OOB data in line */
  1222. #define SO_REUSEPORT 0x0200 /* Unimplemented: allow local address & port reuse */
  1223. #define SO_SNDBUF 0x1001 /* Unimplemented: send buffer size */
  1224. #define SO_RCVBUF 0x1002 /* receive buffer size */
  1225. #define SO_SNDLOWAT 0x1003 /* Unimplemented: send low-water mark */
  1226. #define SO_RCVLOWAT 0x1004 /* Unimplemented: receive low-water mark */
  1227. #define SO_SNDTIMEO 0x1005 /* send timeout */
  1228. #define SO_RCVTIMEO 0x1006 /* receive timeout */
  1229. #define SO_ERROR 0x1007 /* get error status and clear */
  1230. #define SO_TYPE 0x1008 /* get socket type */
  1231. #define SO_CONTIMEO 0x1009 /* Unimplemented: connect timeout */
  1232. #define SO_NO_CHECK 0x100a /* don't create UDP checksum */
  1233. /*
  1234. * Level number for (get/set)sockopt() to apply to socket itself.
  1235. */
  1236. #define SOL_SOCKET 0xfff /* options for socket level */
  1237. #define AF_UNSPEC 0
  1238. #define AF_INET 2
  1239. #if LWIP_IPV6
  1240. #define AF_INET6 10
  1241. #else /* LWIP_IPV6 */
  1242. #define AF_INET6 AF_UNSPEC
  1243. #endif /* LWIP_IPV6 */
  1244. #define PF_INET AF_INET
  1245. #define PF_INET6 AF_INET6
  1246. #define PF_UNSPEC AF_UNSPEC
  1247. #define IPPROTO_IP 0
  1248. #define IPPROTO_ICMP 1
  1249. #define IPPROTO_TCP 6
  1250. #define IPPROTO_UDP 17
  1251. #if LWIP_IPV6
  1252. #define IPPROTO_IPV6 41
  1253. #define IPPROTO_ICMPV6 58
  1254. #endif /* LWIP_IPV6 */
  1255. #define IPPROTO_UDPLITE 136
  1256. #define IPPROTO_RAW 255
  1257. /* Flags we can use with send and recv. */
  1258. #define MSG_PEEK 0x01 /* Peeks at an incoming message */
  1259. #define MSG_WAITALL 0x02 /* Unimplemented: Requests that the function block until the full amount of data requested can be returned */
  1260. #define MSG_OOB 0x04 /* Unimplemented: Requests out-of-band data. The significance and semantics of out-of-band data are protocol-specific */
  1261. #define MSG_DONTWAIT 0x08 /* Nonblocking i/o for this operation only */
  1262. #define MSG_MORE 0x10 /* Sender will send more */
  1263. /*
  1264. * Options for level IPPROTO_IP
  1265. */
  1266. #define IP_TOS 1
  1267. #define IP_TTL 2
  1268. #if LWIP_TCP
  1269. /*
  1270. * Options for level IPPROTO_TCP
  1271. */
  1272. #define TCP_NODELAY 0x01 /* don't delay send to coalesce packets */
  1273. #define TCP_KEEPALIVE 0x02 /* send KEEPALIVE probes when idle for pcb->keep_idle milliseconds */
  1274. #define TCP_KEEPIDLE 0x03 /* set pcb->keep_idle - Same as TCP_KEEPALIVE, but use seconds for get/setsockopt */
  1275. #define TCP_KEEPINTVL 0x04 /* set pcb->keep_intvl - Use seconds for get/setsockopt */
  1276. #define TCP_KEEPCNT 0x05 /* set pcb->keep_cnt - Use number of probes sent for get/setsockopt */
  1277. #endif /* LWIP_TCP */
  1278. #if LWIP_IPV6
  1279. /*
  1280. * Options for level IPPROTO_IPV6
  1281. */
  1282. #define IPV6_CHECKSUM 7 /* RFC3542: calculate and insert the ICMPv6 checksum for raw sockets. */
  1283. #define IPV6_V6ONLY 27 /* RFC3493: boolean control to restrict AF_INET6 sockets to IPv6 communications only. */
  1284. #endif /* LWIP_IPV6 */
  1285. #if LWIP_UDP && LWIP_UDPLITE
  1286. /*
  1287. * Options for level IPPROTO_UDPLITE
  1288. */
  1289. #define UDPLITE_SEND_CSCOV 0x01 /* sender checksum coverage */
  1290. #define UDPLITE_RECV_CSCOV 0x02 /* minimal receiver checksum coverage */
  1291. #endif /* LWIP_UDP && LWIP_UDPLITE*/
  1292. #if LWIP_MULTICAST_TX_OPTIONS
  1293. /*
  1294. * Options and types for UDP multicast traffic handling
  1295. */
  1296. #define IP_MULTICAST_TTL 5
  1297. #define IP_MULTICAST_IF 6
  1298. #define IP_MULTICAST_LOOP 7
  1299. #endif /* LWIP_MULTICAST_TX_OPTIONS */
  1300. #if LWIP_IGMP
  1301. /*
  1302. * Options and types related to multicast membership
  1303. */
  1304. #define IP_ADD_MEMBERSHIP 3
  1305. #define IP_DROP_MEMBERSHIP 4
  1306. typedef struct ip_mreq {
  1307. struct in_addr imr_multiaddr; /* IP multicast address of group */
  1308. struct in_addr imr_interface; /* local IP address of interface */
  1309. } ip_mreq;
  1310. #endif /* LWIP_IGMP */
  1311. /*
  1312. * The Type of Service provides an indication of the abstract
  1313. * parameters of the quality of service desired. These parameters are
  1314. * to be used to guide the selection of the actual service parameters
  1315. * when transmitting a datagram through a particular network. Several
  1316. * networks offer service precedence, which somehow treats high
  1317. * precedence traffic as more important than other traffic (generally
  1318. * by accepting only traffic above a certain precedence at time of high
  1319. * load). The major choice is a three way tradeoff between low-delay,
  1320. * high-reliability, and high-throughput.
  1321. * The use of the Delay, Throughput, and Reliability indications may
  1322. * increase the cost (in some sense) of the service. In many networks
  1323. * better performance for one of these parameters is coupled with worse
  1324. * performance on another. Except for very unusual cases at most two
  1325. * of these three indications should be set.
  1326. */
  1327. #define IPTOS_TOS_MASK 0x1E
  1328. #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
  1329. #define IPTOS_LOWDELAY 0x10
  1330. #define IPTOS_THROUGHPUT 0x08
  1331. #define IPTOS_RELIABILITY 0x04
  1332. #define IPTOS_LOWCOST 0x02
  1333. #define IPTOS_MINCOST IPTOS_LOWCOST
  1334. /*
  1335. * The Network Control precedence designation is intended to be used
  1336. * within a network only. The actual use and control of that
  1337. * designation is up to each network. The Internetwork Control
  1338. * designation is intended for use by gateway control originators only.
  1339. * If the actual use of these precedence designations is of concern to
  1340. * a particular network, it is the responsibility of that network to
  1341. * control the access to, and use of, those precedence designations.
  1342. */
  1343. #define IPTOS_PREC_MASK 0xe0
  1344. #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
  1345. #define IPTOS_PREC_NETCONTROL 0xe0
  1346. #define IPTOS_PREC_INTERNETCONTROL 0xc0
  1347. #define IPTOS_PREC_CRITIC_ECP 0xa0
  1348. #define IPTOS_PREC_FLASHOVERRIDE 0x80
  1349. #define IPTOS_PREC_FLASH 0x60
  1350. #define IPTOS_PREC_IMMEDIATE 0x40
  1351. #define IPTOS_PREC_PRIORITY 0x20
  1352. #define IPTOS_PREC_ROUTINE 0x00
  1353. /*
  1354. * Commands for ioctlsocket(), taken from the BSD file fcntl.h.
  1355. * lwip_ioctl only supports FIONREAD and FIONBIO, for now
  1356. *
  1357. * Ioctl's have the command encoded in the lower word,
  1358. * and the size of any in or out parameters in the upper
  1359. * word. The high 2 bits of the upper word are used
  1360. * to encode the in/out status of the parameter; for now
  1361. * we restrict parameters to at most 128 bytes.
  1362. */
  1363. #if !defined(FIONREAD) || !defined(FIONBIO)
  1364. #define IOCPARM_MASK 0x7fU /* parameters must be < 128 bytes */
  1365. #define IOC_VOID 0x20000000UL /* no parameters */
  1366. #define IOC_OUT 0x40000000UL /* copy out parameters */
  1367. #define IOC_IN 0x80000000UL /* copy in parameters */
  1368. #define IOC_INOUT (IOC_IN|IOC_OUT)
  1369. /* 0x20000000 distinguishes new &
  1370. old ioctl's */
  1371. #define _IO(x,y) (IOC_VOID|((x)<<8)|(y))
  1372. #define _IOR(x,y,t) (IOC_OUT|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
  1373. #define _IOW(x,y,t) (IOC_IN|(((long)sizeof(t)&IOCPARM_MASK)<<16)|((x)<<8)|(y))
  1374. #endif /* !defined(FIONREAD) || !defined(FIONBIO) */
  1375. #ifndef FIONREAD
  1376. #define FIONREAD _IOR('f', 127, unsigned long) /* get # bytes to read */
  1377. #endif
  1378. #ifndef FIONBIO
  1379. #define FIONBIO _IOW('f', 126, unsigned long) /* set/clear non-blocking i/o */
  1380. #endif
  1381. /* Socket I/O Controls: unimplemented */
  1382. #ifndef SIOCSHIWAT
  1383. #define SIOCSHIWAT _IOW('s', 0, unsigned long) /* set high watermark */
  1384. #define SIOCGHIWAT _IOR('s', 1, unsigned long) /* get high watermark */
  1385. #define SIOCSLOWAT _IOW('s', 2, unsigned long) /* set low watermark */
  1386. #define SIOCGLOWAT _IOR('s', 3, unsigned long) /* get low watermark */
  1387. #define SIOCATMARK _IOR('s', 7, unsigned long) /* at oob mark? */
  1388. #endif
  1389. /* commands for fnctl */
  1390. #ifndef F_GETFL
  1391. #define F_GETFL 3
  1392. #endif
  1393. #ifndef F_SETFL
  1394. #define F_SETFL 4
  1395. #endif
  1396. /* File status flags and file access modes for fnctl,
  1397. these are bits in an int. */
  1398. #ifndef O_NONBLOCK
  1399. #define O_NONBLOCK 1 /* nonblocking I/O */
  1400. #endif
  1401. #ifndef O_NDELAY
  1402. #define O_NDELAY 1 /* same as O_NONBLOCK, for compatibility */
  1403. #endif
  1404. #ifndef SHUT_RD
  1405. #define SHUT_RD 0
  1406. #define SHUT_WR 1
  1407. #define SHUT_RDWR 2
  1408. #endif
  1409. /* FD_SET used for lwip_select */
  1410. #ifndef FD_SET
  1411. #undef FD_SETSIZE
  1412. /* Make FD_SETSIZE match NUM_SOCKETS in socket.c */
  1413. #define FD_SETSIZE MEMP_NUM_NETCONN
  1414. #define FDSETSAFESET(n, code) do { \
  1415. if (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0)) { \
  1416. code; }} while(0)
  1417. #define FDSETSAFEGET(n, code) (((n) - LWIP_SOCKET_OFFSET < MEMP_NUM_NETCONN) && (((int)(n) - LWIP_SOCKET_OFFSET) >= 0) ?\
  1418. (code) : 0)
  1419. #define FD_SET(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] |= (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
  1420. #define FD_CLR(n, p) FDSETSAFESET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] &= ~(1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
  1421. #define FD_ISSET(n,p) FDSETSAFEGET(n, (p)->fd_bits[((n)-LWIP_SOCKET_OFFSET)/8] & (1 << (((n)-LWIP_SOCKET_OFFSET) & 7)))
  1422. #define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p)))
  1423. typedef struct fd_set
  1424. {
  1425. unsigned char fd_bits [(FD_SETSIZE+7)/8];
  1426. } fd_set;
  1427. #elif LWIP_SOCKET_OFFSET
  1428. #error LWIP_SOCKET_OFFSET does not work with external FD_SET!
  1429. #elif FD_SETSIZE < MEMP_NUM_NETCONN
  1430. #error "external FD_SETSIZE too small for number of sockets"
  1431. #endif /* FD_SET */
  1432. #ifdef PS2IP_DNS
  1433. /** DNS timer period */
  1434. #define DNS_TMR_INTERVAL 1000
  1435. /* DNS resolve types: */
  1436. #define LWIP_DNS_ADDRTYPE_IPV4 0
  1437. #define LWIP_DNS_ADDRTYPE_IPV6 1
  1438. #define LWIP_DNS_ADDRTYPE_IPV4_IPV6 2 /* try to resolve IPv4 first, try IPv6 if IPv4 fails only */
  1439. #define LWIP_DNS_ADDRTYPE_IPV6_IPV4 3 /* try to resolve IPv6 first, try IPv4 if IPv6 fails only */
  1440. #if LWIP_IPV4 && LWIP_IPV6
  1441. #ifndef LWIP_DNS_ADDRTYPE_DEFAULT
  1442. #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4_IPV6
  1443. #endif
  1444. #elif defined(LWIP_IPV4)
  1445. #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV4
  1446. #else
  1447. #define LWIP_DNS_ADDRTYPE_DEFAULT LWIP_DNS_ADDRTYPE_IPV6
  1448. #endif
  1449. #if DNS_LOCAL_HOSTLIST
  1450. /** struct used for local host-list */
  1451. struct local_hostlist_entry {
  1452. /** static hostname */
  1453. const char *name;
  1454. /** static host address in network byteorder */
  1455. ip_addr_t addr;
  1456. struct local_hostlist_entry *next;
  1457. };
  1458. #if DNS_LOCAL_HOSTLIST_IS_DYNAMIC
  1459. #ifndef DNS_LOCAL_HOSTLIST_MAX_NAMELEN
  1460. #define DNS_LOCAL_HOSTLIST_MAX_NAMELEN DNS_MAX_NAME_LENGTH
  1461. #endif
  1462. #define LOCALHOSTLIST_ELEM_SIZE ((sizeof(struct local_hostlist_entry) + DNS_LOCAL_HOSTLIST_MAX_NAMELEN + 1))
  1463. #endif /* DNS_LOCAL_HOSTLIST_IS_DYNAMIC */
  1464. #endif /* DNS_LOCAL_HOSTLIST */
  1465. /** Callback which is invoked when a hostname is found.
  1466. * A function of this type must be implemented by the application using the DNS resolver.
  1467. * @param name pointer to the name that was looked up.
  1468. * @param ipaddr pointer to an ip_addr_t containing the IP address of the hostname,
  1469. * or NULL if the name could not be found (or on any other error).
  1470. * @param callback_arg a user-specified callback argument passed to dns_gethostbyname
  1471. */
  1472. typedef void (*dns_found_callback)(const char *name, const ip_addr_t *ipaddr, void *callback_arg);
  1473. #endif
  1474. /* From src/include/lwip/netdb.h: */
  1475. /* some rarely used options */
  1476. #ifndef LWIP_DNS_API_DECLARE_H_ERRNO
  1477. #define LWIP_DNS_API_DECLARE_H_ERRNO 1
  1478. #endif
  1479. #ifndef LWIP_DNS_API_DEFINE_ERRORS
  1480. #define LWIP_DNS_API_DEFINE_ERRORS 1
  1481. #endif
  1482. #ifndef LWIP_DNS_API_DEFINE_FLAGS
  1483. #define LWIP_DNS_API_DEFINE_FLAGS 1
  1484. #endif
  1485. #ifndef LWIP_DNS_API_DECLARE_STRUCTS
  1486. #define LWIP_DNS_API_DECLARE_STRUCTS 1
  1487. #endif
  1488. #if LWIP_DNS_API_DEFINE_ERRORS
  1489. /** Errors used by the DNS API functions, h_errno can be one of them */
  1490. #define EAI_NONAME 200
  1491. #define EAI_SERVICE 201
  1492. #define EAI_FAIL 202
  1493. #define EAI_MEMORY 203
  1494. #define EAI_FAMILY 204
  1495. #define HOST_NOT_FOUND 210
  1496. #define NO_DATA 211
  1497. #define NO_RECOVERY 212
  1498. #define TRY_AGAIN 213
  1499. #endif /* LWIP_DNS_API_DEFINE_ERRORS */
  1500. #if LWIP_DNS_API_DEFINE_FLAGS
  1501. /* input flags for struct addrinfo */
  1502. #define AI_PASSIVE 0x01
  1503. #define AI_CANONNAME 0x02
  1504. #define AI_NUMERICHOST 0x04
  1505. #define AI_NUMERICSERV 0x08
  1506. #define AI_V4MAPPED 0x10
  1507. #define AI_ALL 0x20
  1508. #define AI_ADDRCONFIG 0x40
  1509. #endif /* LWIP_DNS_API_DEFINE_FLAGS */
  1510. #if LWIP_DNS_API_DECLARE_STRUCTS
  1511. struct hostent {
  1512. char *h_name; /* Official name of the host. */
  1513. char **h_aliases; /* A pointer to an array of pointers to alternative host names,
  1514. terminated by a null pointer. */
  1515. int h_addrtype; /* Address type. */
  1516. int h_length; /* The length, in bytes, of the address. */
  1517. char **h_addr_list; /* A pointer to an array of pointers to network addresses (in
  1518. network byte order) for the host, terminated by a null pointer. */
  1519. #define h_addr h_addr_list[0] /* for backward compatibility */
  1520. };
  1521. struct addrinfo {
  1522. int ai_flags; /* Input flags. */
  1523. int ai_family; /* Address family of socket. */
  1524. int ai_socktype; /* Socket type. */
  1525. int ai_protocol; /* Protocol of socket. */
  1526. socklen_t ai_addrlen; /* Length of socket address. */
  1527. struct sockaddr *ai_addr; /* Socket address of socket. */
  1528. char *ai_canonname; /* Canonical name of service location. */
  1529. struct addrinfo *ai_next; /* Pointer to next in list. */
  1530. };
  1531. #endif /* LWIP_DNS_API_DECLARE_STRUCTS */
  1532. #define NETDB_ELEM_SIZE (sizeof(struct addrinfo) + sizeof(struct sockaddr_storage) + DNS_MAX_NAME_LENGTH + 1)
  1533. /* From src/include/lwip/def.h: */
  1534. #define htons(x) lwip_htons(x)
  1535. #define ntohs(x) lwip_ntohs(x)
  1536. #define htonl(x) lwip_htonl(x)
  1537. #define ntohl(x) lwip_ntohl(x)
  1538. #define lwip_htons(x) PP_HTONS(x)
  1539. #define lwip_ntohs(x) PP_NTOHS(x)
  1540. #define lwip_htonl(x) PP_HTONL(x)
  1541. #define lwip_ntohl(x) PP_NTOHL(x)
  1542. /* These macros should be calculated by the preprocessor and are used
  1543. with compile-time constants only (so that there is no little-endian
  1544. overhead at runtime). */
  1545. #define PP_HTONS(x) ((((x) & 0xff) << 8) | (((x) & 0xff00) >> 8))
  1546. #define PP_NTOHS(x) PP_HTONS(x)
  1547. #define PP_HTONL(x) ((((x) & 0xff) << 24) | \
  1548. (((x) & 0xff00) << 8) | \
  1549. (((x) & 0xff0000UL) >> 8) | \
  1550. (((x) & 0xff000000UL) >> 24))
  1551. #define PP_NTOHL(x) PP_HTONL(x)
  1552. /** The structure that contains the network interface state ***/
  1553. typedef struct
  1554. {
  1555. char netif_name[4];
  1556. struct in_addr ipaddr;
  1557. struct in_addr netmask;
  1558. struct in_addr gw;
  1559. u32 dhcp_enabled;
  1560. u32 dhcp_status;
  1561. u8 hw_addr[8];
  1562. } t_ip_info;
  1563. #endif /* __TCPIP_H__ */