fdsf

Dependents:   sisk_proj_stat MQTT Hello_FXOS8700Q WireFSHandControl ... more

Committer:
grzemich
Date:
Wed Dec 07 23:47:50 2016 +0000
Revision:
0:d7bd7384a37c
dgd

Who changed what in which revision?

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