ON Semiconductor / mbed-os

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers lwip_ethernet.h Source File

lwip_ethernet.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * Ethernet input function - handles INCOMING ethernet level traffic
00004  * To be used in most low-level netif implementations
00005  */
00006 
00007 /*
00008  * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
00009  * Copyright (c) 2003-2004 Leon Woestenberg <leon.woestenberg@axon.tv>
00010  * Copyright (c) 2003-2004 Axon Digital Design B.V., The Netherlands.
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without modification,
00014  * are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  * 2. Redistributions in binary form must reproduce the above copyright notice,
00019  *    this list of conditions and the following disclaimer in the documentation
00020  *    and/or other materials provided with the distribution.
00021  * 3. The name of the author may not be used to endorse or promote products
00022  *    derived from this software without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00025  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00026  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00027  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00028  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00029  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00030  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00031  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00032  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00033  * OF SUCH DAMAGE.
00034  *
00035  * This file is part of the lwIP TCP/IP stack.
00036  *
00037  * Author: Adam Dunkels <adam@sics.se>
00038  *
00039  */
00040 
00041 #ifndef LWIP_HDR_NETIF_ETHERNET_H
00042 #define LWIP_HDR_NETIF_ETHERNET_H
00043 
00044 #include "lwip/opt.h"
00045 
00046 #include "lwip/pbuf.h"
00047 #include "lwip/netif.h"
00048 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00053 #ifndef ETH_HWADDR_LEN
00054 #ifdef ETHARP_HWADDR_LEN
00055 #define ETH_HWADDR_LEN    ETHARP_HWADDR_LEN /* compatibility mode */
00056 #else
00057 #define ETH_HWADDR_LEN    6
00058 #endif
00059 #endif
00060 
00061 #ifdef PACK_STRUCT_USE_INCLUDES
00062 #  include "arch/bpstruct.h"
00063 #endif
00064 PACK_STRUCT_BEGIN
00065 struct eth_addr {
00066   PACK_STRUCT_FLD_8(u8_t addr[ETH_HWADDR_LEN]);
00067 } PACK_STRUCT_STRUCT;
00068 PACK_STRUCT_END
00069 #ifdef PACK_STRUCT_USE_INCLUDES
00070 #  include "arch/epstruct.h"
00071 #endif
00072 
00073 #ifdef PACK_STRUCT_USE_INCLUDES
00074 #  include "arch/bpstruct.h"
00075 #endif
00076 PACK_STRUCT_BEGIN
00077 /** Ethernet header */
00078 struct eth_hdr {
00079 #if ETH_PAD_SIZE
00080   PACK_STRUCT_FLD_8(u8_t padding[ETH_PAD_SIZE]);
00081 #endif
00082   PACK_STRUCT_FLD_S(struct eth_addr dest);
00083   PACK_STRUCT_FLD_S(struct eth_addr src);
00084   PACK_STRUCT_FIELD(u16_t type);
00085 } PACK_STRUCT_STRUCT;
00086 PACK_STRUCT_END
00087 #ifdef PACK_STRUCT_USE_INCLUDES
00088 #  include "arch/epstruct.h"
00089 #endif
00090 
00091 #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
00092 
00093 #if ETHARP_SUPPORT_VLAN
00094 
00095 #ifdef PACK_STRUCT_USE_INCLUDES
00096 #  include "arch/bpstruct.h"
00097 #endif
00098 PACK_STRUCT_BEGIN
00099 /** VLAN header inserted between ethernet header and payload
00100  * if 'type' in ethernet header is ETHTYPE_VLAN.
00101  * See IEEE802.Q */
00102 struct eth_vlan_hdr {
00103   PACK_STRUCT_FIELD(u16_t prio_vid);
00104   PACK_STRUCT_FIELD(u16_t tpid);
00105 } PACK_STRUCT_STRUCT;
00106 PACK_STRUCT_END
00107 #ifdef PACK_STRUCT_USE_INCLUDES
00108 #  include "arch/epstruct.h"
00109 #endif
00110 
00111 #define SIZEOF_VLAN_HDR 4
00112 #define VLAN_ID(vlan_hdr) (htons((vlan_hdr)->prio_vid) & 0xFFF)
00113 
00114 #endif /* ETHARP_SUPPORT_VLAN */
00115 
00116 /* A list of often ethtypes (although lwIP does not use all of them): */
00117 #define ETHTYPE_IP        0x0800U  /* Internet protocol v4 */
00118 #define ETHTYPE_ARP       0x0806U  /* Address resolution protocol */
00119 #define ETHTYPE_WOL       0x0842U  /* Wake on lan */
00120 #define ETHTYPE_VLAN      0x8100U  /* Virtual local area network */
00121 #define ETHTYPE_IPV6      0x86DDU  /* Internet protocol v6 */
00122 #define ETHTYPE_PPPOEDISC 0x8863U  /* PPP Over Ethernet Discovery Stage */
00123 #define ETHTYPE_PPPOE     0x8864U  /* PPP Over Ethernet Session Stage */
00124 #define ETHTYPE_JUMBO     0x8870U  /* Jumbo Frames */
00125 #define ETHTYPE_PROFINET  0x8892U  /* Process field network */
00126 #define ETHTYPE_ETHERCAT  0x88A4U  /* Ethernet for control automation technology */
00127 #define ETHTYPE_LLDP      0x88CCU  /* Link layer discovery protocol */
00128 #define ETHTYPE_SERCOS    0x88CDU  /* Serial real-time communication system */
00129 #define ETHTYPE_PTP       0x88F7U  /* Precision time protocol */
00130 #define ETHTYPE_QINQ      0x9100U  /* Q-in-Q, 802.1ad */
00131 
00132 /** The 24-bit IANA IPv4-multicast OUI is 01-00-5e: */
00133 #define LL_IP4_MULTICAST_ADDR_0 0x01
00134 #define LL_IP4_MULTICAST_ADDR_1 0x00
00135 #define LL_IP4_MULTICAST_ADDR_2 0x5e
00136 
00137 /** IPv6 multicast uses this prefix */
00138 #define LL_IP6_MULTICAST_ADDR_0 0x33
00139 #define LL_IP6_MULTICAST_ADDR_1 0x33
00140 
00141 /** MEMCPY-like macro to copy to/from struct eth_addr's that are local variables
00142  * or known to be 32-bit aligned within the protocol header. */
00143 #ifndef ETHADDR32_COPY
00144 #define ETHADDR32_COPY(dst, src)  SMEMCPY(dst, src, ETH_HWADDR_LEN)
00145 #endif
00146 
00147 /** MEMCPY-like macro to copy to/from struct eth_addr's that are no local
00148  * variables and known to be 16-bit aligned within the protocol header. */
00149 #ifndef ETHADDR16_COPY
00150 #define ETHADDR16_COPY(dst, src)  SMEMCPY(dst, src, ETH_HWADDR_LEN)
00151 #endif
00152 
00153 #if LWIP_ARP || LWIP_ETHERNET
00154 
00155 /** Define this to 1 and define LWIP_ARP_FILTER_NETIF_FN(pbuf, netif, type)
00156  * to a filter function that returns the correct netif when using multiple
00157  * netifs on one hardware interface where the netif's low-level receive
00158  * routine cannot decide for the correct netif (e.g. when mapping multiple
00159  * IP addresses to one hardware interface).
00160  */
00161 #ifndef LWIP_ARP_FILTER_NETIF
00162 #define LWIP_ARP_FILTER_NETIF 0
00163 #endif
00164 
00165 err_t ethernet_input(struct pbuf *p, struct netif *netif);
00166 
00167 #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETH_HWADDR_LEN) == 0)
00168 
00169 extern const struct eth_addr ethbroadcast, ethzero;
00170 
00171 #endif /* LWIP_ARP || LWIP_ETHERNET */
00172 
00173 #ifdef __cplusplus
00174 }
00175 #endif
00176 
00177 #endif /* LWIP_HDR_NETIF_ETHERNET_H */