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