创建mbed

Dependencies:   EthernetInterface SDFileSystem mbed-rtos mbed

Committer:
sunyiming
Date:
Tue Mar 06 08:53:46 2018 +0000
Revision:
1:6465a3f5c58a
??OK

Who changed what in which revision?

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