Onenet
Dependents: K64F_eCompass_OneNET_JW
lwip/include/netif/etharp.h@0:b2805b6888dc, 2016-06-20 (annotated)
- Committer:
- robert_jw
- Date:
- Mon Jun 20 01:40:20 2016 +0000
- Revision:
- 0:b2805b6888dc
ADS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
robert_jw | 0:b2805b6888dc | 1 | /* |
robert_jw | 0:b2805b6888dc | 2 | * Copyright (c) 2001-2003 Swedish Institute of Computer Science. |
robert_jw | 0:b2805b6888dc | 3 | * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv> |
robert_jw | 0:b2805b6888dc | 4 | * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands. |
robert_jw | 0:b2805b6888dc | 5 | * All rights reserved. |
robert_jw | 0:b2805b6888dc | 6 | * |
robert_jw | 0:b2805b6888dc | 7 | * Redistribution and use in source and binary forms, with or without modification, |
robert_jw | 0:b2805b6888dc | 8 | * are permitted provided that the following conditions are met: |
robert_jw | 0:b2805b6888dc | 9 | * |
robert_jw | 0:b2805b6888dc | 10 | * 1. Redistributions of source code must retain the above copyright notice, |
robert_jw | 0:b2805b6888dc | 11 | * this list of conditions and the following disclaimer. |
robert_jw | 0:b2805b6888dc | 12 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
robert_jw | 0:b2805b6888dc | 13 | * this list of conditions and the following disclaimer in the documentation |
robert_jw | 0:b2805b6888dc | 14 | * and/or other materials provided with the distribution. |
robert_jw | 0:b2805b6888dc | 15 | * 3. The name of the author may not be used to endorse or promote products |
robert_jw | 0:b2805b6888dc | 16 | * derived from this software without specific prior written permission. |
robert_jw | 0:b2805b6888dc | 17 | * |
robert_jw | 0:b2805b6888dc | 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
robert_jw | 0:b2805b6888dc | 19 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
robert_jw | 0:b2805b6888dc | 20 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
robert_jw | 0:b2805b6888dc | 21 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
robert_jw | 0:b2805b6888dc | 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
robert_jw | 0:b2805b6888dc | 23 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
robert_jw | 0:b2805b6888dc | 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
robert_jw | 0:b2805b6888dc | 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
robert_jw | 0:b2805b6888dc | 26 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
robert_jw | 0:b2805b6888dc | 27 | * OF SUCH DAMAGE. |
robert_jw | 0:b2805b6888dc | 28 | * |
robert_jw | 0:b2805b6888dc | 29 | * This file is part of the lwIP TCP/IP stack. |
robert_jw | 0:b2805b6888dc | 30 | * |
robert_jw | 0:b2805b6888dc | 31 | * Author: Adam Dunkels <adam@sics.se> |
robert_jw | 0:b2805b6888dc | 32 | * |
robert_jw | 0:b2805b6888dc | 33 | */ |
robert_jw | 0:b2805b6888dc | 34 | |
robert_jw | 0:b2805b6888dc | 35 | #ifndef __NETIF_ETHARP_H__ |
robert_jw | 0:b2805b6888dc | 36 | #define __NETIF_ETHARP_H__ |
robert_jw | 0:b2805b6888dc | 37 | |
robert_jw | 0:b2805b6888dc | 38 | #include "lwip/opt.h" |
robert_jw | 0:b2805b6888dc | 39 | |
robert_jw | 0:b2805b6888dc | 40 | #if LWIP_ARP || LWIP_ETHERNET /* don't build if not configured for use in lwipopts.h */ |
robert_jw | 0:b2805b6888dc | 41 | |
robert_jw | 0:b2805b6888dc | 42 | #include "lwip/pbuf.h" |
robert_jw | 0:b2805b6888dc | 43 | #include "lwip/ip_addr.h" |
robert_jw | 0:b2805b6888dc | 44 | #include "lwip/netif.h" |
robert_jw | 0:b2805b6888dc | 45 | #include "lwip/ip.h" |
robert_jw | 0:b2805b6888dc | 46 | |
robert_jw | 0:b2805b6888dc | 47 | #ifdef __cplusplus |
robert_jw | 0:b2805b6888dc | 48 | extern "C" { |
robert_jw | 0:b2805b6888dc | 49 | #endif |
robert_jw | 0:b2805b6888dc | 50 | |
robert_jw | 0:b2805b6888dc | 51 | #ifndef ETHARP_HWADDR_LEN |
robert_jw | 0:b2805b6888dc | 52 | #define ETHARP_HWADDR_LEN 6 |
robert_jw | 0:b2805b6888dc | 53 | #endif |
robert_jw | 0:b2805b6888dc | 54 | |
robert_jw | 0:b2805b6888dc | 55 | #ifdef PACK_STRUCT_USE_INCLUDES |
robert_jw | 0:b2805b6888dc | 56 | # include "arch/bpstruct.h" |
robert_jw | 0:b2805b6888dc | 57 | #endif |
robert_jw | 0:b2805b6888dc | 58 | PACK_STRUCT_BEGIN |
robert_jw | 0:b2805b6888dc | 59 | struct eth_addr { |
robert_jw | 0:b2805b6888dc | 60 | PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]); |
robert_jw | 0:b2805b6888dc | 61 | } PACK_STRUCT_STRUCT; |
robert_jw | 0:b2805b6888dc | 62 | PACK_STRUCT_END |
robert_jw | 0:b2805b6888dc | 63 | #ifdef PACK_STRUCT_USE_INCLUDES |
robert_jw | 0:b2805b6888dc | 64 | # include "arch/epstruct.h" |
robert_jw | 0:b2805b6888dc | 65 | #endif |
robert_jw | 0:b2805b6888dc | 66 | |
robert_jw | 0:b2805b6888dc | 67 | #ifdef PACK_STRUCT_USE_INCLUDES |
robert_jw | 0:b2805b6888dc | 68 | # include "arch/bpstruct.h" |
robert_jw | 0:b2805b6888dc | 69 | #endif |
robert_jw | 0:b2805b6888dc | 70 | PACK_STRUCT_BEGIN |
robert_jw | 0:b2805b6888dc | 71 | /** Ethernet header */ |
robert_jw | 0:b2805b6888dc | 72 | struct eth_hdr { |
robert_jw | 0:b2805b6888dc | 73 | #if ETH_PAD_SIZE |
robert_jw | 0:b2805b6888dc | 74 | PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]); |
robert_jw | 0:b2805b6888dc | 75 | #endif |
robert_jw | 0:b2805b6888dc | 76 | PACK_STRUCT_FIELD(struct eth_addr dest); |
robert_jw | 0:b2805b6888dc | 77 | PACK_STRUCT_FIELD(struct eth_addr src); |
robert_jw | 0:b2805b6888dc | 78 | PACK_STRUCT_FIELD(u16_t type); |
robert_jw | 0:b2805b6888dc | 79 | } PACK_STRUCT_STRUCT; |
robert_jw | 0:b2805b6888dc | 80 | PACK_STRUCT_END |
robert_jw | 0:b2805b6888dc | 81 | #ifdef PACK_STRUCT_USE_INCLUDES |
robert_jw | 0:b2805b6888dc | 82 | # include "arch/epstruct.h" |
robert_jw | 0:b2805b6888dc | 83 | #endif |
robert_jw | 0:b2805b6888dc | 84 | |
robert_jw | 0:b2805b6888dc | 85 | #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE) |
robert_jw | 0:b2805b6888dc | 86 | |
robert_jw | 0:b2805b6888dc | 87 | #if ETHARP_SUPPORT_VLAN |
robert_jw | 0:b2805b6888dc | 88 | |
robert_jw | 0:b2805b6888dc | 89 | #ifdef PACK_STRUCT_USE_INCLUDES |
robert_jw | 0:b2805b6888dc | 90 | # include "arch/bpstruct.h" |
robert_jw | 0:b2805b6888dc | 91 | #endif |
robert_jw | 0:b2805b6888dc | 92 | PACK_STRUCT_BEGIN |
robert_jw | 0:b2805b6888dc | 93 | /** VLAN header inserted between ethernet header and payload |
robert_jw | 0:b2805b6888dc | 94 | * if 'type' in ethernet header is ETHTYPE_VLAN. |
robert_jw | 0:b2805b6888dc | 95 | * See IEEE802.Q */ |
robert_jw | 0:b2805b6888dc | 96 | struct eth_vlan_hdr { |
robert_jw | 0:b2805b6888dc | 97 | PACK_STRUCT_FIELD(u16_t prio_vid); |
robert_jw | 0:b2805b6888dc | 98 | PACK_STRUCT_FIELD(u16_t tpid); |
robert_jw | 0:b2805b6888dc | 99 | } PACK_STRUCT_STRUCT; |
robert_jw | 0:b2805b6888dc | 100 | PACK_STRUCT_END |
robert_jw | 0:b2805b6888dc | 101 | #ifdef PACK_STRUCT_USE_INCLUDES |
robert_jw | 0:b2805b6888dc | 102 | # include "arch/epstruct.h" |
robert_jw | 0:b2805b6888dc | 103 | #endif |
robert_jw | 0:b2805b6888dc | 104 | |
robert_jw | 0:b2805b6888dc | 105 | #define SIZEOF_VLAN_HDR 4 |
robert_jw | 0:b2805b6888dc | 106 | #define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF) |
robert_jw | 0:b2805b6888dc | 107 | |
robert_jw | 0:b2805b6888dc | 108 | #endif /* ETHARP_SUPPORT_VLAN */ |
robert_jw | 0:b2805b6888dc | 109 | |
robert_jw | 0:b2805b6888dc | 110 | #ifdef PACK_STRUCT_USE_INCLUDES |
robert_jw | 0:b2805b6888dc | 111 | # include "arch/bpstruct.h" |
robert_jw | 0:b2805b6888dc | 112 | #endif |
robert_jw | 0:b2805b6888dc | 113 | PACK_STRUCT_BEGIN |
robert_jw | 0:b2805b6888dc | 114 | /** the ARP message, see RFC 826 ("Packet format") */ |
robert_jw | 0:b2805b6888dc | 115 | struct etharp_hdr { |
robert_jw | 0:b2805b6888dc | 116 | PACK_STRUCT_FIELD(u16_t hwtype); |
robert_jw | 0:b2805b6888dc | 117 | PACK_STRUCT_FIELD(u16_t proto); |
robert_jw | 0:b2805b6888dc | 118 | PACK_STRUCT_FIELD(u8_t hwlen); |
robert_jw | 0:b2805b6888dc | 119 | PACK_STRUCT_FIELD(u8_t protolen); |
robert_jw | 0:b2805b6888dc | 120 | PACK_STRUCT_FIELD(u16_t opcode); |
robert_jw | 0:b2805b6888dc | 121 | PACK_STRUCT_FIELD(struct eth_addr shwaddr); |
robert_jw | 0:b2805b6888dc | 122 | PACK_STRUCT_FIELD(struct ip_addr2 sipaddr); |
robert_jw | 0:b2805b6888dc | 123 | PACK_STRUCT_FIELD(struct eth_addr dhwaddr); |
robert_jw | 0:b2805b6888dc | 124 | PACK_STRUCT_FIELD(struct ip_addr2 dipaddr); |
robert_jw | 0:b2805b6888dc | 125 | } PACK_STRUCT_STRUCT; |
robert_jw | 0:b2805b6888dc | 126 | PACK_STRUCT_END |
robert_jw | 0:b2805b6888dc | 127 | #ifdef PACK_STRUCT_USE_INCLUDES |
robert_jw | 0:b2805b6888dc | 128 | # include "arch/epstruct.h" |
robert_jw | 0:b2805b6888dc | 129 | #endif |
robert_jw | 0:b2805b6888dc | 130 | |
robert_jw | 0:b2805b6888dc | 131 | #define SIZEOF_ETHARP_HDR 28 |
robert_jw | 0:b2805b6888dc | 132 | #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR) |
robert_jw | 0:b2805b6888dc | 133 | |
robert_jw | 0:b2805b6888dc | 134 | /** 5 seconds period */ |
robert_jw | 0:b2805b6888dc | 135 | #define ARP_TMR_INTERVAL 5000 |
robert_jw | 0:b2805b6888dc | 136 | |
robert_jw | 0:b2805b6888dc | 137 | #define ETHTYPE_ARP 0x0806U |
robert_jw | 0:b2805b6888dc | 138 | #define ETHTYPE_IP 0x0800U |
robert_jw | 0:b2805b6888dc | 139 | #define ETHTYPE_VLAN 0x8100U |
robert_jw | 0:b2805b6888dc | 140 | #define ETHTYPE_PPPOEDISC 0x8863U /* PPP Over Ethernet Discovery Stage */ |
robert_jw | 0:b2805b6888dc | 141 | #define ETHTYPE_PPPOE 0x8864U /* PPP Over Ethernet Session Stage */ |
robert_jw | 0:b2805b6888dc | 142 | |
robert_jw | 0:b2805b6888dc | 143 | /** MEMCPY-like macro to copy to/from struct eth_addr's that are local variables |
robert_jw | 0:b2805b6888dc | 144 | * or known to be 32-bit aligned within the protocol header. */ |
robert_jw | 0:b2805b6888dc | 145 | #ifndef ETHADDR32_COPY |
robert_jw | 0:b2805b6888dc | 146 | #define ETHADDR32_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN) |
robert_jw | 0:b2805b6888dc | 147 | #endif |
robert_jw | 0:b2805b6888dc | 148 | |
robert_jw | 0:b2805b6888dc | 149 | /** MEMCPY-like macro to copy to/from struct eth_addr's that are no local |
robert_jw | 0:b2805b6888dc | 150 | * variables and known to be 16-bit aligned within the protocol header. */ |
robert_jw | 0:b2805b6888dc | 151 | #ifndef ETHADDR16_COPY |
robert_jw | 0:b2805b6888dc | 152 | #define ETHADDR16_COPY(src, dst) SMEMCPY(src, dst, ETHARP_HWADDR_LEN) |
robert_jw | 0:b2805b6888dc | 153 | #endif |
robert_jw | 0:b2805b6888dc | 154 | |
robert_jw | 0:b2805b6888dc | 155 | #if LWIP_ARP /* don't build if not configured for use in lwipopts.h */ |
robert_jw | 0:b2805b6888dc | 156 | |
robert_jw | 0:b2805b6888dc | 157 | /** ARP message types (opcodes) */ |
robert_jw | 0:b2805b6888dc | 158 | #define ARP_REQUEST 1 |
robert_jw | 0:b2805b6888dc | 159 | #define ARP_REPLY 2 |
robert_jw | 0:b2805b6888dc | 160 | |
robert_jw | 0:b2805b6888dc | 161 | /** Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type) |
robert_jw | 0:b2805b6888dc | 162 | * to a filter function that returns the correct netif when using multiple |
robert_jw | 0:b2805b6888dc | 163 | * netifs on one hardware interface where the netif's low-level receive |
robert_jw | 0:b2805b6888dc | 164 | * routine cannot decide for the correct netif (e.g. when mapping multiple |
robert_jw | 0:b2805b6888dc | 165 | * IP addresses to one hardware interface). |
robert_jw | 0:b2805b6888dc | 166 | */ |
robert_jw | 0:b2805b6888dc | 167 | #ifndef LWIP_ARP_FILTER_NETIF |
robert_jw | 0:b2805b6888dc | 168 | #define LWIP_ARP_FILTER_NETIF 0 |
robert_jw | 0:b2805b6888dc | 169 | #endif |
robert_jw | 0:b2805b6888dc | 170 | |
robert_jw | 0:b2805b6888dc | 171 | #if ARP_QUEUEING |
robert_jw | 0:b2805b6888dc | 172 | /** struct for queueing outgoing packets for unknown address |
robert_jw | 0:b2805b6888dc | 173 | * defined here to be accessed by memp.h |
robert_jw | 0:b2805b6888dc | 174 | */ |
robert_jw | 0:b2805b6888dc | 175 | struct etharp_q_entry { |
robert_jw | 0:b2805b6888dc | 176 | struct etharp_q_entry *next; |
robert_jw | 0:b2805b6888dc | 177 | struct pbuf *p; |
robert_jw | 0:b2805b6888dc | 178 | }; |
robert_jw | 0:b2805b6888dc | 179 | #endif /* ARP_QUEUEING */ |
robert_jw | 0:b2805b6888dc | 180 | |
robert_jw | 0:b2805b6888dc | 181 | #define etharp_init() /* Compatibility define, not init needed. */ |
robert_jw | 0:b2805b6888dc | 182 | void etharp_tmr(void); |
robert_jw | 0:b2805b6888dc | 183 | s8_t etharp_find_addr(struct netif *netif, ip_addr_t *ipaddr, |
robert_jw | 0:b2805b6888dc | 184 | struct eth_addr **eth_ret, ip_addr_t **ip_ret); |
robert_jw | 0:b2805b6888dc | 185 | err_t etharp_output(struct netif *netif, struct pbuf *q, ip_addr_t *ipaddr); |
robert_jw | 0:b2805b6888dc | 186 | err_t etharp_query(struct netif *netif, ip_addr_t *ipaddr, struct pbuf *q); |
robert_jw | 0:b2805b6888dc | 187 | err_t etharp_request(struct netif *netif, ip_addr_t *ipaddr); |
robert_jw | 0:b2805b6888dc | 188 | /** For Ethernet network interfaces, we might want to send "gratuitous ARP"; |
robert_jw | 0:b2805b6888dc | 189 | * this is an ARP packet sent by a node in order to spontaneously cause other |
robert_jw | 0:b2805b6888dc | 190 | * nodes to update an entry in their ARP cache. |
robert_jw | 0:b2805b6888dc | 191 | * From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */ |
robert_jw | 0:b2805b6888dc | 192 | #define etharp_gratuitous(netif) etharp_request((netif), &(netif)->ip_addr) |
robert_jw | 0:b2805b6888dc | 193 | |
robert_jw | 0:b2805b6888dc | 194 | #if ETHARP_SUPPORT_STATIC_ENTRIES |
robert_jw | 0:b2805b6888dc | 195 | err_t etharp_add_static_entry(ip_addr_t *ipaddr, struct eth_addr *ethaddr); |
robert_jw | 0:b2805b6888dc | 196 | err_t etharp_remove_static_entry(ip_addr_t *ipaddr); |
robert_jw | 0:b2805b6888dc | 197 | #endif /* ETHARP_SUPPORT_STATIC_ENTRIES */ |
robert_jw | 0:b2805b6888dc | 198 | |
robert_jw | 0:b2805b6888dc | 199 | #if LWIP_AUTOIP |
robert_jw | 0:b2805b6888dc | 200 | err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr, |
robert_jw | 0:b2805b6888dc | 201 | const struct eth_addr *ethdst_addr, |
robert_jw | 0:b2805b6888dc | 202 | const struct eth_addr *hwsrc_addr, const ip_addr_t *ipsrc_addr, |
robert_jw | 0:b2805b6888dc | 203 | const struct eth_addr *hwdst_addr, const ip_addr_t *ipdst_addr, |
robert_jw | 0:b2805b6888dc | 204 | const u16_t opcode); |
robert_jw | 0:b2805b6888dc | 205 | #endif /* LWIP_AUTOIP */ |
robert_jw | 0:b2805b6888dc | 206 | |
robert_jw | 0:b2805b6888dc | 207 | #endif /* LWIP_ARP */ |
robert_jw | 0:b2805b6888dc | 208 | |
robert_jw | 0:b2805b6888dc | 209 | err_t ethernet_input(struct pbuf *p, struct netif *netif); |
robert_jw | 0:b2805b6888dc | 210 | |
robert_jw | 0:b2805b6888dc | 211 | #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0) |
robert_jw | 0:b2805b6888dc | 212 | |
robert_jw | 0:b2805b6888dc | 213 | extern const struct eth_addr ethbroadcast, ethzero; |
robert_jw | 0:b2805b6888dc | 214 | |
robert_jw | 0:b2805b6888dc | 215 | #ifdef __cplusplus |
robert_jw | 0:b2805b6888dc | 216 | } |
robert_jw | 0:b2805b6888dc | 217 | #endif |
robert_jw | 0:b2805b6888dc | 218 | |
robert_jw | 0:b2805b6888dc | 219 | #endif /* LWIP_ARP || LWIP_ETHERNET */ |
robert_jw | 0:b2805b6888dc | 220 | |
robert_jw | 0:b2805b6888dc | 221 | #endif /* __NETIF_ARP_H__ */ |