Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ethernet.h Source File

ethernet.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * Ethernet protocol definitions
00004  */
00005 
00006 /*
00007  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without modification,
00011  * are permitted provided that the following conditions are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright notice,
00014  *    this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright notice,
00016  *    this list of conditions and the following disclaimer in the documentation
00017  *    and/or other materials provided with the distribution.
00018  * 3. The name of the author may not be used to endorse or promote products
00019  *    derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00023  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00024  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00026  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00029  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00030  * OF SUCH DAMAGE.
00031  *
00032  * This file is part of the lwIP TCP/IP stack.
00033  *
00034  * Author: Adam Dunkels <adam@sics.se>
00035  *
00036  */
00037 #ifndef LWIP_HDR_PROT_ETHERNET_H
00038 #define LWIP_HDR_PROT_ETHERNET_H
00039 
00040 #include "lwip/arch.h"
00041 #include "lwip/prot/ieee.h"
00042 
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046 
00047 #ifndef ETH_HWADDR_LEN
00048 #ifdef ETHARP_HWADDR_LEN
00049 #define ETH_HWADDR_LEN    ETHARP_HWADDR_LEN /* compatibility mode */
00050 #else
00051 #define ETH_HWADDR_LEN    6
00052 #endif
00053 #endif
00054 
00055 #ifdef PACK_STRUCT_USE_INCLUDES
00056 #  include "arch/bpstruct.h"
00057 #endif
00058 PACK_STRUCT_BEGIN
00059 /** An Ethernet MAC address */
00060 struct eth_addr {
00061   PACK_STRUCT_FLD_8(u8_t addr[ETH_HWADDR_LEN]);
00062 } PACK_STRUCT_STRUCT;
00063 PACK_STRUCT_END
00064 #ifdef PACK_STRUCT_USE_INCLUDES
00065 #  include "arch/epstruct.h"
00066 #endif
00067 
00068 /** Initialize a struct eth_addr with its 6 bytes (takes care of correct braces) */
00069 #define ETH_ADDR(b0, b1, b2, b3, b4, b5) {{b0, b1, b2, b3, b4, b5}}
00070 
00071 #ifdef PACK_STRUCT_USE_INCLUDES
00072 #  include "arch/bpstruct.h"
00073 #endif
00074 PACK_STRUCT_BEGIN
00075 /** Ethernet header */
00076 struct eth_hdr {
00077 #if ETH_PAD_SIZE
00078   PACK_STRUCT_FLD_8(u8_t padding[ETH_PAD_SIZE]);
00079 #endif
00080   PACK_STRUCT_FLD_S(struct eth_addr dest);
00081   PACK_STRUCT_FLD_S(struct eth_addr src);
00082   PACK_STRUCT_FIELD(u16_t type);
00083 } PACK_STRUCT_STRUCT;
00084 PACK_STRUCT_END
00085 #ifdef PACK_STRUCT_USE_INCLUDES
00086 #  include "arch/epstruct.h"
00087 #endif
00088 
00089 #define SIZEOF_ETH_HDR (14 + ETH_PAD_SIZE)
00090 
00091 #ifdef PACK_STRUCT_USE_INCLUDES
00092 #  include "arch/bpstruct.h"
00093 #endif
00094 PACK_STRUCT_BEGIN
00095 /** VLAN header inserted between ethernet header and payload
00096  * if 'type' in ethernet header is ETHTYPE_VLAN.
00097  * See IEEE802.Q */
00098 struct eth_vlan_hdr {
00099   PACK_STRUCT_FIELD(u16_t prio_vid);
00100   PACK_STRUCT_FIELD(u16_t tpid);
00101 } PACK_STRUCT_STRUCT;
00102 PACK_STRUCT_END
00103 #ifdef PACK_STRUCT_USE_INCLUDES
00104 #  include "arch/epstruct.h"
00105 #endif
00106 
00107 #define SIZEOF_VLAN_HDR 4
00108 #define VLAN_ID(vlan_hdr) (lwip_htons((vlan_hdr)->prio_vid) & 0xFFF)
00109 
00110 /** The 24-bit IANA IPv4-multicast OUI is 01-00-5e: */
00111 #define LL_IP4_MULTICAST_ADDR_0 0x01
00112 #define LL_IP4_MULTICAST_ADDR_1 0x00
00113 #define LL_IP4_MULTICAST_ADDR_2 0x5e
00114 
00115 /** IPv6 multicast uses this prefix */
00116 #define LL_IP6_MULTICAST_ADDR_0 0x33
00117 #define LL_IP6_MULTICAST_ADDR_1 0x33
00118 
00119 #define eth_addr_cmp(addr1, addr2) (memcmp((addr1)->addr, (addr2)->addr, ETH_HWADDR_LEN) == 0)
00120 
00121 #ifdef __cplusplus
00122 }
00123 #endif
00124 
00125 #endif /* LWIP_HDR_PROT_ETHERNET_H */