Counter

Dependencies:   EthernetInterface NTPClient SDFileSystem TextLCD WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip FATFileSystem

Committer:
Tuxitheone
Date:
Mon Feb 29 18:59:15 2016 +0000
Revision:
0:ecaf3e593122
TankCounter

Who changed what in which revision?

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