Dependencies:   mbed

Committer:
robertcook
Date:
Wed Jun 13 18:39:46 2012 +0000
Revision:
0:32a0996dff0f

        

Who changed what in which revision?

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