Dependencies:   mbed

Committer:
gbeardall
Date:
Mon Oct 17 10:39:17 2011 +0000
Revision:
0:715023d993d6

        

Who changed what in which revision?

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