http://mbed.org/users/okini3939/notebook/logger/

Dependencies:   mbed

Committer:
okini3939
Date:
Sat Apr 16 15:15:48 2011 +0000
Revision:
0:a3c892f39cc1

        

Who changed what in which revision?

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