STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
etharp.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
3  * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
4  * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without modification,
8  * are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  * 3. The name of the author may not be used to endorse or promote products
16  * derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
19  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
21  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
23  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27  * OF SUCH DAMAGE.
28  *
29  * This file is part of the lwIP TCP/IP stack.
30  *
31  * Author: Adam Dunkels <adam@sics.se>
32  *
33  */
34 
35 #ifndef LWIP_HDR_NETIF_ETHARP_H
36 #define LWIP_HDR_NETIF_ETHARP_H
37 
38 #include "lwip/opt.h"
39 
40 #if LWIP_ARP || LWIP_ETHERNET /* don't build if not configured for use in lwipopts.h */
41 
42 #include "lwip/pbuf.h"
43 #include "lwip/ip_addr.h"
44 #include "lwip/netif.h"
45 #include "lwip/ip.h"
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 #ifndef ETHARP_HWADDR_LEN
52 #define ETHARP_HWADDR_LEN 6
53 #endif
54 
55 #ifdef PACK_STRUCT_USE_INCLUDES
56 # include "arch/bpstruct.h"
57 #endif
59 struct eth_addr {
60  PACK_STRUCT_FLD_8(u8_t addr[ETHARP_HWADDR_LEN]);
63 #ifdef PACK_STRUCT_USE_INCLUDES
64 # include "arch/epstruct.h"
65 #endif
66 
67 #ifdef PACK_STRUCT_USE_INCLUDES
68 # include "arch/bpstruct.h"
69 #endif
72 struct eth_hdr {
73 #if ETH_PAD_SIZE
75 #endif
76  PACK_STRUCT_FLD_S(struct eth_addr dest);
77  PACK_STRUCT_FLD_S(struct eth_addr src);
81 #ifdef PACK_STRUCT_USE_INCLUDES
82 # include "arch/epstruct.h"
83 #endif
84 
85 #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
86 
87 #if ETHARP_SUPPORT_VLAN
88 
89 #ifdef PACK_STRUCT_USE_INCLUDES
90 # include "arch/bpstruct.h"
91 #endif
96 struct eth_vlan_hdr {
97  PACK_STRUCT_FIELD(u16_t prio_vid);
101 #ifdef PACK_STRUCT_USE_INCLUDES
102 # include "arch/epstruct.h"
103 #endif
104 
105 #define SIZEOF_VLAN_HDR 4
106 #define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF)
107 
108 #endif /* ETHARP_SUPPORT_VLAN */
109 
110 /* A list of often ethtypes (although lwIP does not use all of them): */
111 #define ETHTYPE_IP 0x0800U /* Internet protocol v4 */
112 #define ETHTYPE_ARP 0x0806U /* Address resolution protocol */
113 #define ETHTYPE_WOL 0x0842U /* Wake on lan */
114 #define ETHTYPE_VLAN 0x8100U /* Virtual local area network */
115 #define ETHTYPE_IPV6 0x86DDU /* Internet protocol v6 */
116 #define ETHTYPE_PPPOEDISC 0x8863U /* PPP Over Ethernet Discovery Stage */
117 #define ETHTYPE_PPPOE 0x8864U /* PPP Over Ethernet Session Stage */
118 #define ETHTYPE_JUMBO 0x8870U /* Jumbo Frames */
119 #define ETHTYPE_PROFINET 0x8892U /* Process field network */
120 #define ETHTYPE_ETHERCAT 0x88A4U /* Ethernet for control automation technology */
121 #define ETHTYPE_LLDP 0x88CCU /* Link layer discovery protocol */
122 #define ETHTYPE_SERCOS 0x88CDU /* Serial real-time communication system */
123 #define ETHTYPE_PTP 0x88F7U /* Precision time protocol */
124 #define ETHTYPE_QINQ 0x9100U /* Q-in-Q, 802.1ad */
125 
132 #ifndef LWIP_ARP_FILTER_NETIF
133 #define LWIP_ARP_FILTER_NETIF 0
134 #endif
135 
136 #if LWIP_IPV4 && LWIP_ARP /* don't build if not configured for use in lwipopts.h */
137 
138 #ifdef PACK_STRUCT_USE_INCLUDES
139 # include "arch/bpstruct.h"
140 #endif
143 struct etharp_hdr {
144  PACK_STRUCT_FIELD(u16_t hwtype);
145  PACK_STRUCT_FIELD(u16_t proto);
146  PACK_STRUCT_FLD_8(u8_t hwlen);
147  PACK_STRUCT_FLD_8(u8_t protolen);
148  PACK_STRUCT_FIELD(u16_t opcode);
149  PACK_STRUCT_FLD_S(struct eth_addr shwaddr);
150  PACK_STRUCT_FLD_S(struct ip4_addr2 sipaddr);
151  PACK_STRUCT_FLD_S(struct eth_addr dhwaddr);
152  PACK_STRUCT_FLD_S(struct ip4_addr2 dipaddr);
155 #ifdef PACK_STRUCT_USE_INCLUDES
156 # include "arch/epstruct.h"
157 #endif
158 
159 #define SIZEOF_ETHARP_HDR 28
160 
161 #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR)
162 #if ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET)
163 #define SIZEOF_ETHARP_PACKET_TX (SIZEOF_ETHARP_PACKET + SIZEOF_VLAN_HDR)
164 #else /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */
165 #define SIZEOF_ETHARP_PACKET_TX SIZEOF_ETHARP_PACKET
166 #endif /* ETHARP_SUPPORT_VLAN && defined(LWIP_HOOK_VLAN_SET) */
167 
169 #define ARP_TMR_INTERVAL 1000
170 
173 #ifndef ETHADDR32_COPY
174 #define ETHADDR32_COPY(dst, src) SMEMCPY(dst, src, ETHARP_HWADDR_LEN)
175 #endif
176 
179 #ifndef ETHADDR16_COPY
180 #define ETHADDR16_COPY(dst, src) SMEMCPY(dst, src, ETHARP_HWADDR_LEN)
181 #endif
182 
184 #define ARP_REQUEST 1
185 #define ARP_REPLY 2
186 
187 #if ARP_QUEUEING
188 
191 struct etharp_q_entry {
192  struct etharp_q_entry *next;
193  struct pbuf *p;
194 };
195 #endif /* ARP_QUEUEING */
196 
197 #define etharp_init() /* Compatibility define, no init needed. */
198 void etharp_tmr(void);
199 s8_t etharp_find_addr(struct netif *netif, const ip4_addr_t *ipaddr,
200  struct eth_addr **eth_ret, const ip4_addr_t **ip_ret);
201 u8_t etharp_get_entry(u8_t i, ip4_addr_t **ipaddr, struct netif **netif, struct eth_addr **eth_ret);
202 err_t etharp_output(struct netif *netif, struct pbuf *q, const ip4_addr_t *ipaddr);
203 err_t etharp_query(struct netif *netif, const ip4_addr_t *ipaddr, struct pbuf *q);
204 err_t etharp_request(struct netif *netif, const ip4_addr_t *ipaddr);
209 #define etharp_gratuitous(netif) etharp_request((netif), netif_ip4_addr(netif))
210 void etharp_cleanup_netif(struct netif *netif);
211 
212 #if ETHARP_SUPPORT_STATIC_ENTRIES
213 err_t etharp_add_static_entry(const ip4_addr_t *ipaddr, struct eth_addr *ethaddr);
214 err_t etharp_remove_static_entry(const ip4_addr_t *ipaddr);
215 #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */
216 
217 #if LWIP_AUTOIP
218 err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
219  const struct eth_addr *ethdst_addr,
220  const struct eth_addr *hwsrc_addr, const ip4_addr_t *ipsrc_addr,
221  const struct eth_addr *hwdst_addr, const ip4_addr_t *ipdst_addr,
222  const u16_t opcode);
223 #endif /* LWIP_AUTOIP */
224 
225 #endif /* LWIP_IPV4 && LWIP_ARP */
226 
227 err_t ethernet_input(struct pbuf *p, struct netif *netif);
228 
229 #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)
230 
231 extern const struct eth_addr ethbroadcast, ethzero;
232 
233 #ifdef __cplusplus
234 }
235 #endif
236 
237 #endif /* LWIP_ARP || LWIP_ETHERNET */
238 
239 #endif /* LWIP_HDR_NETIF_ARP_H */
240 
#define PACK_STRUCT_STRUCT
Definition: arch.h:68
signed char s8_t
Definition: cc.h:39
#define PACK_STRUCT_FLD_8(x)
Definition: arch.h:78
#define PACK_STRUCT_FIELD(x)
Definition: arch.h:72
Definition: pbuf.h:108
s8_t err_t
Definition: err.h:47
Definition: netif.h:182
#define PACK_STRUCT_FLD_S(x)
Definition: arch.h:84
#define PACK_STRUCT_BEGIN
Definition: arch.h:60
#define ETH_PAD_SIZE
Definition: opt.h:522
unsigned char u8_t
Definition: cc.h:38
#define PACK_STRUCT_END
Definition: arch.h:64
unsigned short u16_t
Definition: cc.h:40