EthernetNetIf

Dependents:   XBee_WiFi_EA_LPC4088

Committer:
hmike
Date:
Wed Nov 19 12:00:42 2014 +0000
Revision:
0:62580107d20c
EthernetNetIf

Who changed what in which revision?

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