Home | History | Annotate | Download | only in proto
      1 /*
      2  * From FreeBSD 2.2.7: Fundamental constants relating to ethernet.
      3  *
      4  * Copyright (C) 1999-2011, 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,v 9.56 2009-10-15 22:54:58 Exp $
     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_BRCM		0x886c
     63 #define	ETHER_TYPE_802_1X	0x888e
     64 #define	ETHER_TYPE_802_1X_PREAUTH 0x88c7
     65 #define ETHER_TYPE_WAI		0x88b4
     66 
     67 
     68 
     69 #define	ETHER_BRCM_SUBTYPE_LEN	4
     70 #define	ETHER_BRCM_CRAM		1
     71 
     72 
     73 #define ETHER_DEST_OFFSET	(0 * ETHER_ADDR_LEN)
     74 #define ETHER_SRC_OFFSET	(1 * ETHER_ADDR_LEN)
     75 #define ETHER_TYPE_OFFSET	(2 * ETHER_ADDR_LEN)
     76 
     77 
     78 #define	ETHER_IS_VALID_LEN(foo)	\
     79 	((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
     80 
     81 #define ETHER_FILL_MCAST_ADDR_FROM_IP(ea, mgrp_ip) {		\
     82 		((uint8 *)ea)[0] = 0x01;			\
     83 		((uint8 *)ea)[1] = 0x00;			\
     84 		((uint8 *)ea)[2] = 0x5e;			\
     85 		((uint8 *)ea)[3] = ((mgrp_ip) >> 16) & 0x7f;	\
     86 		((uint8 *)ea)[4] = ((mgrp_ip) >>  8) & 0xff;	\
     87 		((uint8 *)ea)[5] = ((mgrp_ip) >>  0) & 0xff;	\
     88 }
     89 
     90 #ifndef __INCif_etherh
     91 
     92 BWL_PRE_PACKED_STRUCT struct ether_header {
     93 	uint8	ether_dhost[ETHER_ADDR_LEN];
     94 	uint8	ether_shost[ETHER_ADDR_LEN];
     95 	uint16	ether_type;
     96 } BWL_POST_PACKED_STRUCT;
     97 
     98 
     99 BWL_PRE_PACKED_STRUCT struct	ether_addr {
    100 	uint8 octet[ETHER_ADDR_LEN];
    101 } BWL_POST_PACKED_STRUCT;
    102 #endif
    103 
    104 
    105 #define ETHER_SET_LOCALADDR(ea)	(((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] | 2))
    106 #define ETHER_IS_LOCALADDR(ea) 	(((uint8 *)(ea))[0] & 2)
    107 #define ETHER_CLR_LOCALADDR(ea)	(((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] & 0xd))
    108 #define ETHER_TOGGLE_LOCALADDR(ea)	(((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] ^ 2))
    109 
    110 
    111 #define ETHER_SET_UNICAST(ea)	(((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] & ~1))
    112 
    113 
    114 #define ETHER_ISMULTI(ea) (((const uint8 *)(ea))[0] & 1)
    115 
    116 
    117 
    118 #define	ether_cmp(a, b)	(!(((short*)a)[0] == ((short*)b)[0]) | \
    119 			 !(((short*)a)[1] == ((short*)b)[1]) | \
    120 			 !(((short*)a)[2] == ((short*)b)[2]))
    121 
    122 
    123 #define	ether_copy(s, d) { \
    124 		((short*)d)[0] = ((short*)s)[0]; \
    125 		((short*)d)[1] = ((short*)s)[1]; \
    126 		((short*)d)[2] = ((short*)s)[2]; }
    127 
    128 
    129 static const struct ether_addr ether_bcast = {{255, 255, 255, 255, 255, 255}};
    130 static const struct ether_addr ether_null = {{0, 0, 0, 0, 0, 0}};
    131 
    132 #define ETHER_ISBCAST(ea)	((((uint8 *)(ea))[0] &		\
    133 	                          ((uint8 *)(ea))[1] &		\
    134 				  ((uint8 *)(ea))[2] &		\
    135 				  ((uint8 *)(ea))[3] &		\
    136 				  ((uint8 *)(ea))[4] &		\
    137 				  ((uint8 *)(ea))[5]) == 0xff)
    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 
    146 #define ETHER_MOVE_HDR(d, s) \
    147 do { \
    148 	struct ether_header t; \
    149 	t = *(struct ether_header *)(s); \
    150 	*(struct ether_header *)(d) = t; \
    151 } while (0)
    152 
    153 
    154 #include <packed_section_end.h>
    155 
    156 #endif
    157