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