Ethernetwebsoc

Dependencies:   C12832_lcd LM75B WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip

Committer:
GordonSin
Date:
Fri May 31 04:09:54 2013 +0000
Revision:
0:0ed2a7c7190c
31/5/2013;

Who changed what in which revision?

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