]> git.sur5r.net Git - freertos/blob - Demo/Common/ethernet/lwIP_130/src/include/netif/etharp.h
Added extra compiler specific structure packing options.
[freertos] / Demo / Common / ethernet / lwIP_130 / src / include / netif / etharp.h
1 /*\r
2  * Copyright (c) 2001-2003 Swedish Institute of Computer Science.\r
3  * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>\r
4  * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.\r
5  * All rights reserved.\r
6  *\r
7  * Redistribution and use in source and binary forms, with or without modification,\r
8  * are permitted provided that the following conditions are met:\r
9  *\r
10  * 1. Redistributions of source code must retain the above copyright notice,\r
11  *    this list of conditions and the following disclaimer.\r
12  * 2. Redistributions in binary form must reproduce the above copyright notice,\r
13  *    this list of conditions and the following disclaimer in the documentation\r
14  *    and/or other materials provided with the distribution.\r
15  * 3. The name of the author may not be used to endorse or promote products\r
16  *    derived from this software without specific prior written permission.\r
17  *\r
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED\r
19  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
20  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT\r
21  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
22  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT\r
23  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\r
26  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY\r
27  * OF SUCH DAMAGE.\r
28  *\r
29  * This file is part of the lwIP TCP/IP stack.\r
30  *\r
31  * Author: Adam Dunkels <adam@sics.se>\r
32  *\r
33  */\r
34 \r
35 #ifndef __NETIF_ETHARP_H__\r
36 #define __NETIF_ETHARP_H__\r
37 \r
38 #include "lwip/opt.h"\r
39 \r
40 #if LWIP_ARP /* don't build if not configured for use in lwipopts.h */\r
41 \r
42 #include "lwip/pbuf.h"\r
43 #include "lwip/ip_addr.h"\r
44 #include "lwip/netif.h"\r
45 #include "lwip/ip.h"\r
46 \r
47 #ifdef __cplusplus\r
48 extern "C" {\r
49 #endif\r
50 \r
51 #ifndef ETH_PAD_SIZE\r
52 #define ETH_PAD_SIZE          0\r
53 #endif\r
54 \r
55 #ifndef ETHARP_HWADDR_LEN\r
56 #define ETHARP_HWADDR_LEN     6\r
57 #endif\r
58 \r
59 #ifdef PACK_STRUCT_USE_INCLUDES\r
60 #  include "arch/bpstruct.h"\r
61 #endif\r
62 PACK_STRUCT_BEGIN\r
63 #if (defined(__MWERKS__)  || defined(__CWCC__))\r
64         #pragma options align= packed\r
65 #endif\r
66 struct eth_addr {\r
67   PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]);\r
68 } PACK_STRUCT_STRUCT;\r
69 PACK_STRUCT_END\r
70 #ifdef PACK_STRUCT_USE_INCLUDES\r
71 #  include "arch/epstruct.h"\r
72 #endif\r
73 \r
74 #ifdef PACK_STRUCT_USE_INCLUDES\r
75 #  include "arch/bpstruct.h"\r
76 #endif\r
77 PACK_STRUCT_BEGIN\r
78 #if (defined(__MWERKS__)  || defined(__CWCC__))\r
79         #pragma options align= packed\r
80 #endif\r
81 struct eth_hdr {\r
82 #if ETH_PAD_SIZE\r
83   PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]);\r
84 #endif\r
85   PACK_STRUCT_FIELD(struct eth_addr dest);\r
86   PACK_STRUCT_FIELD(struct eth_addr src);\r
87   PACK_STRUCT_FIELD(u16_t type);\r
88 } PACK_STRUCT_STRUCT;\r
89 PACK_STRUCT_END\r
90 #ifdef PACK_STRUCT_USE_INCLUDES\r
91 #  include "arch/epstruct.h"\r
92 #endif\r
93 \r
94 #ifdef PACK_STRUCT_USE_INCLUDES\r
95 #  include "arch/bpstruct.h"\r
96 #endif\r
97 PACK_STRUCT_BEGIN\r
98 #if (defined(__MWERKS__)  || defined(__CWCC__))\r
99         #pragma options align= packed\r
100 #endif\r
101 /** the ARP message */\r
102 struct etharp_hdr {\r
103   PACK_STRUCT_FIELD(struct eth_hdr ethhdr);\r
104   PACK_STRUCT_FIELD(u16_t hwtype);\r
105   PACK_STRUCT_FIELD(u16_t proto);\r
106   PACK_STRUCT_FIELD(u16_t _hwlen_protolen);\r
107   PACK_STRUCT_FIELD(u16_t opcode);\r
108   PACK_STRUCT_FIELD(struct eth_addr shwaddr);\r
109   PACK_STRUCT_FIELD(struct ip_addr2 sipaddr);\r
110   PACK_STRUCT_FIELD(struct eth_addr dhwaddr);\r
111   PACK_STRUCT_FIELD(struct ip_addr2 dipaddr);\r
112 } PACK_STRUCT_STRUCT;\r
113 PACK_STRUCT_END\r
114 #ifdef PACK_STRUCT_USE_INCLUDES\r
115 #  include "arch/epstruct.h"\r
116 #endif\r
117 \r
118 #ifdef PACK_STRUCT_USE_INCLUDES\r
119 #  include "arch/bpstruct.h"\r
120 #endif\r
121 PACK_STRUCT_BEGIN\r
122 #if (defined(__MWERKS__)  || defined(__CWCC__))\r
123         #pragma options align= packed\r
124 #endif\r
125 struct ethip_hdr {\r
126   PACK_STRUCT_FIELD(struct eth_hdr eth);\r
127   PACK_STRUCT_FIELD(struct ip_hdr ip);\r
128 } PACK_STRUCT_STRUCT;\r
129 PACK_STRUCT_END\r
130 #ifdef PACK_STRUCT_USE_INCLUDES\r
131 #  include "arch/epstruct.h"\r
132 #endif\r
133 \r
134 /** 5 seconds period */\r
135 #define ARP_TMR_INTERVAL 5000\r
136 \r
137 #define ETHTYPE_ARP       0x0806\r
138 #define ETHTYPE_IP        0x0800\r
139 #define ETHTYPE_PPPOEDISC 0x8863  /* PPP Over Ethernet Discovery Stage */\r
140 #define ETHTYPE_PPPOE     0x8864  /* PPP Over Ethernet Session Stage */\r
141 \r
142 /** ARP message types (opcodes) */\r
143 #define ARP_REQUEST 1\r
144 #define ARP_REPLY   2\r
145 \r
146 #if ARP_QUEUEING\r
147 /** struct for queueing outgoing packets for unknown address\r
148   * defined here to be accessed by memp.h\r
149   */\r
150 struct etharp_q_entry {\r
151   struct etharp_q_entry *next;\r
152   struct pbuf *p;\r
153 };\r
154 #endif /* ARP_QUEUEING */\r
155 \r
156 #define etharp_init() /* Compatibility define, not init needed. */\r
157 void etharp_tmr(void);\r
158 s8_t etharp_find_addr(struct netif *netif, struct ip_addr *ipaddr,\r
159          struct eth_addr **eth_ret, struct ip_addr **ip_ret);\r
160 void etharp_ip_input(struct netif *netif, struct pbuf *p);\r
161 void etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr,\r
162          struct pbuf *p);\r
163 err_t etharp_output(struct netif *netif, struct pbuf *q, struct ip_addr *ipaddr);\r
164 err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q);\r
165 err_t etharp_request(struct netif *netif, struct ip_addr *ipaddr);\r
166 \r
167 err_t ethernet_input(struct pbuf *p, struct netif *netif);\r
168 \r
169 #if LWIP_AUTOIP\r
170 err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,\r
171                  const struct eth_addr *ethdst_addr,\r
172                  const struct eth_addr *hwsrc_addr, const struct ip_addr *ipsrc_addr,\r
173                  const struct eth_addr *hwdst_addr, const struct ip_addr *ipdst_addr,\r
174                  const u16_t opcode);\r
175 #endif /* LWIP_AUTOIP */\r
176 \r
177 #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)\r
178 \r
179 extern const struct eth_addr ethbroadcast, ethzero;\r
180 \r
181 #ifdef __cplusplus\r
182 }\r
183 #endif\r
184 \r
185 #endif /* LWIP_ARP */\r
186 \r
187 #endif /* __NETIF_ARP_H__ */\r