Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/netif/etharp.h need to be fixed.

0001 /*
0002  * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
0003  * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
0004  * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
0005  * All rights reserved. 
0006  * 
0007  * Redistribution and use in source and binary forms, with or without modification, 
0008  * are permitted provided that the following conditions are met:
0009  *
0010  * 1. Redistributions of source code must retain the above copyright notice,
0011  *    this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright notice,
0013  *    this list of conditions and the following disclaimer in the documentation
0014  *    and/or other materials provided with the distribution.
0015  * 3. The name of the author may not be used to endorse or promote products
0016  *    derived from this software without specific prior written permission. 
0017  *
0018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 
0019  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
0020  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 
0021  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
0022  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 
0023  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
0024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
0025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
0026  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
0027  * OF SUCH DAMAGE.
0028  *
0029  * This file is part of the lwIP TCP/IP stack.
0030  * 
0031  * Author: Adam Dunkels <adam@sics.se>
0032  *
0033  */
0034 
0035 #ifndef __NETIF_ETHARP_H__
0036 #define __NETIF_ETHARP_H__
0037 
0038 #include "lwip/opt.h"
0039 
0040 #if LWIP_ARP /* don't build if not configured for use in lwipopts.h */
0041 
0042 #include "lwip/pbuf.h"
0043 #include "lwip/ip_addr.h"
0044 #include "lwip/netif.h"
0045 #include "lwip/ip.h"
0046 
0047 #ifdef __cplusplus
0048 extern "C" {
0049 #endif
0050 
0051 #ifndef ETH_PAD_SIZE
0052 #define ETH_PAD_SIZE          0
0053 #endif
0054 
0055 #ifndef ETHARP_HWADDR_LEN
0056 #define ETHARP_HWADDR_LEN     6
0057 #endif
0058 
0059 #ifdef PACK_STRUCT_USE_INCLUDES
0060 #  include "arch/bpstruct.h"
0061 #endif
0062 PACK_STRUCT_BEGIN
0063 struct eth_addr {
0064   PACK_STRUCT_FIELD(u8_t addr[ETHARP_HWADDR_LEN]);
0065 } PACK_STRUCT_STRUCT;
0066 PACK_STRUCT_END
0067 #ifdef PACK_STRUCT_USE_INCLUDES
0068 #  include "arch/epstruct.h"
0069 #endif
0070 
0071 #ifdef PACK_STRUCT_USE_INCLUDES
0072 #  include "arch/bpstruct.h"
0073 #endif
0074 PACK_STRUCT_BEGIN
0075 struct eth_hdr {
0076 #if ETH_PAD_SIZE
0077   PACK_STRUCT_FIELD(u8_t padding[ETH_PAD_SIZE]);
0078 #endif
0079   PACK_STRUCT_FIELD(struct eth_addr dest);
0080   PACK_STRUCT_FIELD(struct eth_addr src);
0081   PACK_STRUCT_FIELD(u16_t type);
0082 } PACK_STRUCT_STRUCT;
0083 PACK_STRUCT_END
0084 #ifdef PACK_STRUCT_USE_INCLUDES
0085 #  include "arch/epstruct.h"
0086 #endif
0087 
0088 #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
0089 
0090 #if ETHARP_SUPPORT_VLAN
0091 
0092 #ifdef PACK_STRUCT_USE_INCLUDES
0093 #  include "arch/bpstruct.h"
0094 #endif
0095 PACK_STRUCT_BEGIN
0096 struct eth_vlan_hdr {
0097   PACK_STRUCT_FIELD(u16_t tpid);
0098   PACK_STRUCT_FIELD(u16_t prio_vid);
0099 } PACK_STRUCT_STRUCT;
0100 PACK_STRUCT_END
0101 #ifdef PACK_STRUCT_USE_INCLUDES
0102 #  include "arch/epstruct.h"
0103 #endif
0104 
0105 #define SIZEOF_VLAN_HDR 4
0106 #define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF)
0107 
0108 #endif /* ETHARP_SUPPORT_VLAN */
0109 
0110 #ifdef PACK_STRUCT_USE_INCLUDES
0111 #  include "arch/bpstruct.h"
0112 #endif
0113 PACK_STRUCT_BEGIN
0114 /** the ARP message */
0115 struct etharp_hdr {
0116   PACK_STRUCT_FIELD(u16_t hwtype);
0117   PACK_STRUCT_FIELD(u16_t proto);
0118   PACK_STRUCT_FIELD(u16_t _hwlen_protolen);
0119   PACK_STRUCT_FIELD(u16_t opcode);
0120   PACK_STRUCT_FIELD(struct eth_addr shwaddr);
0121   PACK_STRUCT_FIELD(struct ip_addr2 sipaddr);
0122   PACK_STRUCT_FIELD(struct eth_addr dhwaddr);
0123   PACK_STRUCT_FIELD(struct ip_addr2 dipaddr);
0124 } PACK_STRUCT_STRUCT;
0125 PACK_STRUCT_END
0126 #ifdef PACK_STRUCT_USE_INCLUDES
0127 #  include "arch/epstruct.h"
0128 #endif
0129 
0130 #define SIZEOF_ETHARP_HDR 28
0131 #define SIZEOF_ETHARP_PACKET (SIZEOF_ETH_HDR + SIZEOF_ETHARP_HDR)
0132 
0133 /** 5 seconds period */
0134 #define ARP_TMR_INTERVAL 5000
0135 
0136 #define ETHTYPE_ARP       0x0806
0137 #define ETHTYPE_IP        0x0800
0138 #define ETHTYPE_VLAN      0x8100
0139 #define ETHTYPE_PPPOEDISC 0x8863  /* PPP Over Ethernet Discovery Stage */
0140 #define ETHTYPE_PPPOE     0x8864  /* PPP Over Ethernet Session Stage */
0141 
0142 /** ARP message types (opcodes) */
0143 #define ARP_REQUEST 1
0144 #define ARP_REPLY   2
0145 
0146 #if ARP_QUEUEING
0147 /** struct for queueing outgoing packets for unknown address
0148   * defined here to be accessed by memp.h
0149   */
0150 struct etharp_q_entry {
0151   struct etharp_q_entry *next;
0152   struct pbuf *p;
0153 };
0154 #endif /* ARP_QUEUEING */
0155 
0156 #define etharp_init() /* Compatibility define, not init needed. */
0157 void etharp_tmr(void);
0158 s8_t etharp_find_addr(struct netif *netif, struct ip_addr *ipaddr,
0159          struct eth_addr **eth_ret, struct ip_addr **ip_ret);
0160 void etharp_ip_input(struct netif *netif, struct pbuf *p);
0161 void etharp_arp_input(struct netif *netif, struct eth_addr *ethaddr,
0162          struct pbuf *p);
0163 err_t etharp_output(struct netif *netif, struct pbuf *q, struct ip_addr *ipaddr);
0164 err_t etharp_query(struct netif *netif, struct ip_addr *ipaddr, struct pbuf *q);
0165 err_t etharp_request(struct netif *netif, struct ip_addr *ipaddr);
0166 /** For Ethernet network interfaces, we might want to send "gratuitous ARP";
0167  *  this is an ARP packet sent by a node in order to spontaneously cause other
0168  *  nodes to update an entry in their ARP cache.
0169  *  From RFC 3220 "IP Mobility Support for IPv4" section 4.6. */
0170 #define etharp_gratuitous(netif) etharp_request((netif), &(netif)->ip_addr)
0171 
0172 err_t ethernet_input(struct pbuf *p, struct netif *netif);
0173 
0174 #if LWIP_AUTOIP
0175 err_t etharp_raw(struct netif *netif, const struct eth_addr *ethsrc_addr,
0176                  const struct eth_addr *ethdst_addr,
0177                  const struct eth_addr *hwsrc_addr, const struct ip_addr *ipsrc_addr,
0178                  const struct eth_addr *hwdst_addr, const struct ip_addr *ipdst_addr,
0179                  const u16_t opcode);
0180 #endif /* LWIP_AUTOIP */
0181 
0182 #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETHARP_HWADDR_LEN) == 0)
0183 
0184 extern const struct eth_addr ethbroadcast, ethzero;
0185 
0186 #ifdef __cplusplus
0187 }
0188 #endif
0189 
0190 #endif /* LWIP_ARP */
0191 
0192 #endif /* __NETIF_ARP_H__ */