1/* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License as 4 * published by the Free Software Foundation; either version 2 of 5 * the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 15 * MA 02111-1307 USA 16 */ 17/******************************************************************************* 18 * $Id: ethernet.h,v 1.1 2007/06/08 10:20:42 arthur Exp $ 19 * Copyright 2001-2003, ASUSTeK Inc. 20 * All Rights Reserved. 21 * 22 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY 23 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM 24 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 25 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE. 26 * From FreeBSD 2.2.7: Fundamental constants relating to ethernet. 27 ******************************************************************************/ 28 29#ifndef _NET_ETHERNET_H_ /* use native BSD ethernet.h when available */ 30#define _NET_ETHERNET_H_ 31 32/* 33 * The number of bytes in an ethernet (MAC) address. 34 */ 35#ifndef ETHER_ADDR_LEN 36#define ETHER_ADDR_LEN 6 37#endif 38 39/* 40 * The number of bytes in the type field. 41 */ 42#define ETHER_TYPE_LEN 2 43 44/* 45 * The number of bytes in the trailing CRC field. 46 */ 47#define ETHER_CRC_LEN 4 48 49/* 50 * The length of the combined header. 51 */ 52#ifndef ETHER_HDR_LEN 53#define ETHER_HDR_LEN (ETHER_ADDR_LEN*2+ETHER_TYPE_LEN) 54#endif 55 56/* 57 * The minimum packet length. 58 */ 59#ifndef ETHER_MIN_LEN 60#define ETHER_MIN_LEN 64 61#endif 62 63/* 64 * The minimum packet user data length. 65 */ 66#define ETHER_MIN_DATA 46 67 68/* 69 * The maximum packet length. 70 */ 71#ifndef ETHER_MAX_LEN 72#define ETHER_MAX_LEN 1518 73#endif 74 75/* 76 * The maximum packet user data length. 77 */ 78#define ETHER_MAX_DATA 1500 79 80/* 81 * Used to uniquely identify a 802.1q VLAN-tagged header. 82 */ 83#define VLAN_TAG 0x8100 84 85/* 86 * Located after dest & src address in ether header. 87 */ 88#define VLAN_FIELDS_OFFSET (ETHER_ADDR_LEN * 2) 89 90/* 91 * 4 bytes of vlan field info. 92 */ 93#define VLAN_FIELDS_SIZE 4 94 95/* location of pri bits in 16-bit vlan fields */ 96#define VLAN_PRI_SHIFT 13 97 98/* 3 bits of priority */ 99#define VLAN_PRI_MASK 7 100 101/* 802.1X ethertype */ 102 103#define ETHER_TYPE_IP 0x0800 /* IP */ 104#define ETHER_TYPE_BRCM 0x886c /* Broadcom Corp. */ 105#define ETHER_TYPE_802_1X 0x888e /* 802.1x */ 106 107#define ETHER_BRCM_SUBTYPE_LEN 4 /* Broadcom 4byte subtype follows ethertype */ 108#define ETHER_BRCM_CRAM 0x1 /* Broadcom subtype cram protocol */ 109 110/* 111 * A macro to validate a length with 112 */ 113#define ETHER_IS_VALID_LEN(foo) \ 114 ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN) 115 116 117/* 118 * Takes a pointer, returns true if a 48-bit multicast address 119 * (including broadcast, since it is all ones) 120 */ 121#define ETHER_ISMULTI(ea) (((uint8 *)(ea))[0] & 1) 122 123/* 124 * Takes a pointer, returns true if a 48-bit broadcast (all ones) 125 */ 126#define ETHER_ISBCAST(ea) ((((uint8 *)(ea))[0] & \ 127 ((uint8 *)(ea))[1] & \ 128 ((uint8 *)(ea))[2] & \ 129 ((uint8 *)(ea))[3] & \ 130 ((uint8 *)(ea))[4] & \ 131 ((uint8 *)(ea))[5]) == 0xff) 132 133static const struct ether_addr ether_bcast = {{255, 255, 255, 255, 255, 255}}; 134 135/* 136 * Takes a pointer, returns true if a 48-bit null address (all zeros) 137 */ 138#define ETHER_ISNULLADDR(ea) ((((uint8 *)(ea))[0] | \ 139 ((uint8 *)(ea))[1] | \ 140 ((uint8 *)(ea))[2] | \ 141 ((uint8 *)(ea))[3] | \ 142 ((uint8 *)(ea))[4] | \ 143 ((uint8 *)(ea))[5]) == 0) 144 145#endif /* _NET_ETHERNET_H_ */ 146