NetTribute library with debug turned on in FShandler Donatien Garner -> Segundo Equipo -> this version

Committer:
hexley
Date:
Fri Nov 19 01:54:45 2010 +0000
Revision:
0:281d6ff68967

        

Who changed what in which revision?

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