~ubuntu-branches/ubuntu/saucy/bcmwl/saucy

« back to all changes in this revision

Viewing changes to src/src/include/proto/ethernet.h

  • Committer: Bazaar Package Importer
  • Author(s): Tim Gardner
  • Date: 2009-05-11 16:04:29 UTC
  • Revision ID: james.westby@ubuntu.com-20090511160429-lciigiqnpp0fpu2k
Tags: 5.10.91.9-2
Add src/lib/LICENSE.txt to copyright notice. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * From FreeBSD 2.2.7: Fundamental constants relating to ethernet.
 
3
 *
 
4
 * Copyright 2008, Broadcom Corporation
 
5
 * All Rights Reserved.
 
6
 * 
 
7
 *      Unless you and Broadcom execute a separate written software license
 
8
 * agreement governing use of this software, this software is licensed to you
 
9
 * under the terms of the GNU General Public License version 2, available at
 
10
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL"), with the
 
11
 * following added to such license:
 
12
 *      As a special exception, the copyright holders of this software give you
 
13
 * permission to link this software with independent modules, regardless of the
 
14
 * license terms of these independent modules, and to copy and distribute the
 
15
 * resulting executable under terms of your choice, provided that you also meet,
 
16
 * for each linked independent module, the terms and conditions of the license
 
17
 * of that module. An independent module is a module which is not derived from
 
18
 * this software.
 
19
 *
 
20
 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
 
21
 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
 
22
 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
 
23
 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
 
24
 *
 
25
 * $Id: ethernet.h,v 9.45.12.1 2008/08/13 02:24:19 Exp $
 
26
 */
 
27
 
 
28
#ifndef _NET_ETHERNET_H_          
 
29
#define _NET_ETHERNET_H_
 
30
 
 
31
#ifndef _TYPEDEFS_H_
 
32
#include "typedefs.h"
 
33
#endif
 
34
 
 
35
#if defined(__GNUC__)
 
36
#define PACKED  __attribute__((packed))
 
37
#else
 
38
#pragma pack(1)
 
39
#define PACKED
 
40
#endif
 
41
 
 
42
#define ETHER_ADDR_LEN          6
 
43
 
 
44
#define ETHER_TYPE_LEN          2
 
45
 
 
46
#define ETHER_CRC_LEN           4
 
47
 
 
48
#define ETHER_HDR_LEN           (ETHER_ADDR_LEN * 2 + ETHER_TYPE_LEN)
 
49
 
 
50
#define ETHER_MIN_LEN           64
 
51
 
 
52
#define ETHER_MIN_DATA          46
 
53
 
 
54
#define ETHER_MAX_LEN           1518
 
55
 
 
56
#define ETHER_MAX_DATA          1500
 
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
 
 
66
#define ETHER_BRCM_SUBTYPE_LEN  4       
 
67
#define ETHER_BRCM_CRAM         1       
 
68
 
 
69
#define ETHER_DEST_OFFSET       (0 * ETHER_ADDR_LEN)    
 
70
#define ETHER_SRC_OFFSET        (1 * ETHER_ADDR_LEN)    
 
71
#define ETHER_TYPE_OFFSET       (2 * ETHER_ADDR_LEN)    
 
72
 
 
73
#define ETHER_IS_VALID_LEN(foo) \
 
74
        ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)
 
75
 
 
76
#define ETHER_FILL_MCAST_ADDR_FROM_IP(eaddr, mgrp_ip) \
 
77
                eaddr[0] = 0x01;        \
 
78
                eaddr[1] = 0x00;        \
 
79
                eaddr[2] = 0x5e;        \
 
80
                eaddr[5] = mgrp_ip & 0xff; mgrp_ip >>= 8; \
 
81
                eaddr[4] = mgrp_ip & 0xff; mgrp_ip >>= 8; \
 
82
                eaddr[3] = mgrp_ip & 0x7f
 
83
 
 
84
#ifndef __INCif_etherh   
 
85
 
 
86
struct  ether_header {
 
87
        uint8   ether_dhost[ETHER_ADDR_LEN];
 
88
        uint8   ether_shost[ETHER_ADDR_LEN];
 
89
        uint16  ether_type;
 
90
} PACKED;
 
91
 
 
92
struct  ether_addr {
 
93
        uint8 octet[ETHER_ADDR_LEN];
 
94
} PACKED;
 
95
#endif  
 
96
 
 
97
#define ETHER_SET_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] | 2))
 
98
#define ETHER_IS_LOCALADDR(ea)  (((uint8 *)(ea))[0] & 2)
 
99
#define ETHER_CLR_LOCALADDR(ea) (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] & 0xd))
 
100
#define ETHER_TOGGLE_LOCALADDR(ea)      (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] ^ 2))
 
101
 
 
102
#define ETHER_SET_UNICAST(ea)   (((uint8 *)(ea))[0] = (((uint8 *)(ea))[0] & ~1))
 
103
 
 
104
#define ETHER_ISMULTI(ea) (((const uint8 *)(ea))[0] & 1)
 
105
 
 
106
#define ether_cmp(a, b) (!(((short*)a)[0] == ((short*)b)[0]) | \
 
107
                         !(((short*)a)[1] == ((short*)b)[1]) | \
 
108
                         !(((short*)a)[2] == ((short*)b)[2]))
 
109
 
 
110
#define ether_copy(s, d) { \
 
111
                ((short*)d)[0] = ((short*)s)[0]; \
 
112
                ((short*)d)[1] = ((short*)s)[1]; \
 
113
                ((short*)d)[2] = ((short*)s)[2]; }
 
114
 
 
115
#define ETHER_ISBCAST(ea) ((((uint8 *)(ea))[0] &                \
 
116
                            ((uint8 *)(ea))[1] &                \
 
117
                            ((uint8 *)(ea))[2] &                \
 
118
                            ((uint8 *)(ea))[3] &                \
 
119
                            ((uint8 *)(ea))[4] &                \
 
120
                            ((uint8 *)(ea))[5]) == 0xff)
 
121
 
 
122
static const struct ether_addr ether_bcast = {{255, 255, 255, 255, 255, 255}};
 
123
static const struct ether_addr ether_null = {{0, 0, 0, 0, 0, 0}};
 
124
 
 
125
#define ETHER_ISNULLADDR(ea) ((((uint8 *)(ea))[0] |             \
 
126
                            ((uint8 *)(ea))[1] |                \
 
127
                            ((uint8 *)(ea))[2] |                \
 
128
                            ((uint8 *)(ea))[3] |                \
 
129
                            ((uint8 *)(ea))[4] |                \
 
130
                            ((uint8 *)(ea))[5]) == 0)
 
131
 
 
132
#undef PACKED
 
133
#if !defined(__GNUC__)
 
134
#pragma pack()
 
135
#endif
 
136
 
 
137
#endif