1 /* 2 * From FreeBSD 2.2.7: Fundamental constants relating to ethernet. 3 * 4 * Copyright (C) 1999-2012, Broadcom Corporation 5 * 6 * Permission to use, copy, modify, and/or distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 * 18 * $Id: ethernet.h 309193 2012-01-19 00:03:57Z $ 19 */ 20 21 22 #ifndef _NET_ETHERNET_H_ 23 #define _NET_ETHERNET_H_ 24 25 #ifndef _TYPEDEFS_H_ 26 #include "typedefs.h" 27 #endif 28 29 30 #include <packed_section_start.h> 31 32 33 34 #define ETHER_ADDR_LEN 6 35 36 37 #define ETHER_TYPE_LEN 2 38 39 40 #define ETHER_CRC_LEN 4 41 42 43 #define ETHER_HDR_LEN (ETHER_ADDR_LEN * 2 + ETHER_TYPE_LEN) 44 45 46 #define ETHER_MIN_LEN 64 47 48 49 #define ETHER_MIN_DATA 46 50 51 52 #define ETHER_MAX_LEN 1518 53 54 55 #define ETHER_MAX_DATA 1500 56 57 58 #define ETHER_TYPE_MIN 0x0600 59 #define ETHER_TYPE_IP 0x0800 60 #define ETHER_TYPE_ARP 0x0806 61 #define ETHER_TYPE_8021Q 0x8100 62 #define ETHER_TYPE_IPV6 0x86dd 63 #define ETHER_TYPE_BRCM 0x886c 64 #define ETHER_TYPE_802_1X 0x888e 65 #define ETHER_TYPE_802_1X_PREAUTH 0x88c7 66 #define ETHER_TYPE_WAI 0x88b4 67 #define ETHER_TYPE_89_0D 0x890d 68 69 #define ETHER_TYPE_IPV6 0x86dd 70 71 72 #define ETHER_BRCM_SUBTYPE_LEN 4 73 74 75 #define ETHER_DEST_OFFSET (0 * ETHER_ADDR_LEN) 76 #define ETHER_SRC_OFFSET (1 * ETHER_ADDR_LEN) 77 #define ETHER_TYPE_OFFSET (2 * ETHER_ADDR_LEN) 78 79 80 #define ETHER_IS_VALID_LEN(foo) \ 81 ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN) 82 83 #define ETHER_FILL_MCAST_ADDR_FROM_IP(ea, mgrp_ip) { \ 84 ((uint8 *)ea)[0] = 0x01; \ 85 ((uint8 *)ea)[1] = 0x00; \ 86 ((uint8 *)ea)[2] = 0x5e; \ 87 ((uint8 *)ea)[3] = ((mgrp_ip) >> 16) & 0x7f; \ 88 ((uint8 *)ea)[4] = ((mgrp_ip) >> 8) & 0xff; \ 89 ((uint8 *)ea)[5] = ((mgrp_ip) >> 0) & 0xff; \ 90 } 91 92 #ifndef __INCif_etherh 93 94 BWL_PRE_PACKED_STRUCT struct ether_header { 95 uint8 ether_dhost[ETHER_ADDR_LEN]; 96 uint8 ether_shost[ETHER_ADDR_LEN]; 97 uint16 ether_type; 98 } BWL_POST_PACKED_STRUCT; 99 100 101 BWL_PRE_PACKED_STRUCT struct ether_addr { 102 uint8 octet[ETHER_ADDR_LEN]; 103 } BWL_POST_PACKED_STRUCT; 104 #endif 105 106 107 #define ETHER_SET_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] | 2)) 108 #define ETHER_IS_LOCALADDR(ea) (((uint8 *)(ea))[0] & 2) 109 #define ETHER_CLR_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] & 0xfd)) 110 #define ETHER_TOGGLE_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] ^ 2)) 111 112 113 #define ETHER_SET_UNICAST(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] & ~1)) 114 115 116 #define ETHER_ISMULTI(ea) (((const uint8 *)(ea))[0] & 1) 117 118 119 120 #define ether_cmp(a, b) (!(((short*)(a))[0] == ((short*)(b))[0]) | \ 121 !(((short*)(a))[1] == ((short*)(b))[1]) | \ 122 !(((short*)(a))[2] == ((short*)(b))[2])) 123 124 125 #define ether_copy(s, d) { \ 126 ((short*)(d))[0] = ((const short*)(s))[0]; \ 127 ((short*)(d))[1] = ((const short*)(s))[1]; \ 128 ((short*)(d))[2] = ((const short*)(s))[2]; } 129 130 131 static const struct ether_addr ether_bcast = {{255, 255, 255, 255, 255, 255}}; 132 static const struct ether_addr ether_null = {{0, 0, 0, 0, 0, 0}}; 133 134 #define ETHER_ISBCAST(ea) ((((uint8 *)(ea))[0] & \ 135 ((uint8 *)(ea))[1] & \ 136 ((uint8 *)(ea))[2] & \ 137 ((uint8 *)(ea))[3] & \ 138 ((uint8 *)(ea))[4] & \ 139 ((uint8 *)(ea))[5]) == 0xff) 140 #define ETHER_ISNULLADDR(ea) ((((uint8 *)(ea))[0] | \ 141 ((uint8 *)(ea))[1] | \ 142 ((uint8 *)(ea))[2] | \ 143 ((uint8 *)(ea))[3] | \ 144 ((uint8 *)(ea))[4] | \ 145 ((uint8 *)(ea))[5]) == 0) 146 147 148 #define ETHER_MOVE_HDR(d, s) \ 149 do { \ 150 struct ether_header t; \ 151 t = *(struct ether_header *)(s); \ 152 *(struct ether_header *)(d) = t; \ 153 } while (0) 154 155 156 #include <packed_section_end.h> 157 158 #endif 159