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