]> granicus.if.org Git - esp-idf/blob - components/lwip/include/lwip/netif/ethernet.h
Initial public version
[esp-idf] / components / lwip / include / lwip / netif / ethernet.h
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_ETHERNET_H
36 #define LWIP_HDR_NETIF_ETHERNET_H
37
38 #include "lwip/opt.h"
39
40 #include "lwip/pbuf.h"
41 #include "lwip/netif.h"
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47 #ifndef ETH_HWADDR_LEN
48 #ifdef ETHARP_HWADDR_LEN
49 #define ETH_HWADDR_LEN    ETHARP_HWADDR_LEN /* compatibility mode */
50 #else
51 #define ETH_HWADDR_LEN    6
52 #endif
53 #endif
54
55 #ifdef PACK_STRUCT_USE_INCLUDES
56 #  include "arch/bpstruct.h"
57 #endif
58 PACK_STRUCT_BEGIN
59 struct eth_addr {
60   PACK_STRUCT_FLD_8(u8_t addr[ETH_HWADDR_LEN]);
61 } PACK_STRUCT_STRUCT;
62 PACK_STRUCT_END
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
70 PACK_STRUCT_BEGIN
71 /** Ethernet header */
72 struct eth_hdr {
73 #if ETH_PAD_SIZE
74   PACK_STRUCT_FLD_8(u8_t padding[ETH_PAD_SIZE]);
75 #endif
76   PACK_STRUCT_FLD_S(struct eth_addr dest);
77   PACK_STRUCT_FLD_S(struct eth_addr src);
78   PACK_STRUCT_FIELD(u16_t type);
79 } PACK_STRUCT_STRUCT;
80 PACK_STRUCT_END
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
92 PACK_STRUCT_BEGIN
93 /** VLAN header inserted between ethernet header and payload
94  * if 'type' in ethernet header is ETHTYPE_VLAN.
95  * See IEEE802.Q */
96 struct eth_vlan_hdr {
97   PACK_STRUCT_FIELD(u16_t prio_vid);
98   PACK_STRUCT_FIELD(u16_t tpid);
99 } PACK_STRUCT_STRUCT;
100 PACK_STRUCT_END
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
126 /** The 24-bit IANA IPv4-multicast OUI is 01-00-5e: */
127 #define LL_IP4_MULTICAST_ADDR_0 0x01
128 #define LL_IP4_MULTICAST_ADDR_1 0x00
129 #define LL_IP4_MULTICAST_ADDR_2 0x5e
130
131 /** IPv6 multicast uses this prefix */
132 #define LL_IP6_MULTICAST_ADDR_0 0x33
133 #define LL_IP6_MULTICAST_ADDR_1 0x33
134
135 /** MEMCPY-like macro to copy to/from struct eth_addr's that are local variables
136  * or known to be 32-bit aligned within the protocol header. */
137 #ifndef ETHADDR32_COPY
138 #define ETHADDR32_COPY(dst, src)  SMEMCPY(dst, src, ETH_HWADDR_LEN)
139 #endif
140
141 /** MEMCPY-like macro to copy to/from struct eth_addr's that are no local
142  * variables and known to be 16-bit aligned within the protocol header. */
143 #ifndef ETHADDR16_COPY
144 #define ETHADDR16_COPY(dst, src)  SMEMCPY(dst, src, ETH_HWADDR_LEN)
145 #endif
146
147 #if LWIP_ARP || LWIP_ETHERNET
148
149 /** Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type)
150  * to a filter function that returns the correct netif when using multiple
151  * netifs on one hardware interface where the netif's low-level receive
152  * routine cannot decide for the correct netif (e.g. when mapping multiple
153  * IP addresses to one hardware interface).
154  */
155 #ifndef LWIP_ARP_FILTER_NETIF
156 #define LWIP_ARP_FILTER_NETIF 0
157 #endif
158
159 err_t ethernet_input(struct pbuf *p, struct netif *netif);
160
161 #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETH_HWADDR_LEN) == 0)
162
163 extern const struct eth_addr ethbroadcast, ethzero;
164
165 #endif /* LWIP_ARP || LWIP_ETHERNET */
166
167 #ifdef __cplusplus
168 }
169 #endif
170
171 #endif /* LWIP_HDR_NETIF_ETHERNET_H */