Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

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