1 /****************************************************************************
2 **+-----------------------------------------------------------------------+**
3 **| |**
4 **| Copyright(c) 1998 - 2008 Texas Instruments. All rights reserved. |**
5 **| All rights reserved. |**
6 **| |**
7 **| Redistribution and use in source and binary forms, with or without |**
8 **| modification, are permitted provided that the following conditions |**
9 **| are met: |**
10 **| |**
11 **| * Redistributions of source code must retain the above copyright |**
12 **| notice, this list of conditions and the following disclaimer. |**
13 **| * Redistributions in binary form must reproduce the above copyright |**
14 **| notice, this list of conditions and the following disclaimer in |**
15 **| the documentation and/or other materials provided with the |**
16 **| distribution. |**
17 **| * Neither the name Texas Instruments nor the names of its |**
18 **| contributors may be used to endorse or promote products derived |**
19 **| from this software without specific prior written permission. |**
20 **| |**
21 **| THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |**
22 **| "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |**
23 **| LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |**
24 **| A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |**
25 **| OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |**
26 **| SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |**
27 **| LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |**
28 **| DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |**
29 **| THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |**
30 **| (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |**
31 **| OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |**
32 **| |**
33 **+-----------------------------------------------------------------------+**
34 ****************************************************************************/
35
36 /***************************************************************************/
37 /* */
38 /* MODULE: Ethernet.h */
39 /* PURPOSE: */
40 /* */
41 /***************************************************************************/
42 #ifndef _ETHERNET_H_
43 #define _ETHERNET_H_
44
45 #pragma pack(1)
46 typedef struct
47 {
48 macAddress_t DstAddr;
49 macAddress_t SrcAddr;
50 UINT16 TypeLength;
51 } EthernetHeader_t;
52 #pragma pack()
53
54 #define ETHERTYPE_802_1D 0x8100
55
56 typedef struct
57 {
58 macAddress_t DstAddr;
59 macAddress_t SrcAddr;
60 UINT16 Length;
61 UINT8 DSAP;
62 UINT8 SSAP;
63 UINT8 Control;
64 UINT8 OUI[3];
65 UINT16 Type;
66 } LlcSnapHeader_t;
67 #pragma pack()
68
69 #define MAC_ADDRESS_GROUP_BIT ( 0x01 ) /* in byte [ 0 ] of the MAC Address*/
70
71
72 #define ETHERNET_HDR_LEN 14
73 #define IEEE802_3_HDR_LEN 14
74 #define LLC_SNAP_HDR_LEN 20
75
76 #define SNAP_CHANNEL_ID 0xAA
77 #define LLC_CONTROL_UNNUMBERED_INFORMATION 0x03
78 #define ETHERNET_MAX_PAYLOAD_SIZE 1500
79
80 #define SNAP_OUI_802_1H_BYTE0 0x00
81 #define SNAP_OUI_802_1H_BYTE1 0x00
82 #define SNAP_OUI_802_1H_BYTE2 0xf8
83 #define SNAP_OUI_802_1H_BYTES { SNAP_OUI_802_1H_BYTE0, SNAP_OUI_802_1H_BYTE1, SNAP_OUI_802_1H_BYTE2 }
84
85 #define SNAP_OUI_RFC1042_BYTE0 0x00
86 #define SNAP_OUI_RFC1042_BYTE1 0x00
87 #define SNAP_OUI_RFC1042_BYTE2 0x00
88 #define SNAP_OUI_RFC1042_LEN 3
89 #define SNAP_OUI_RFC1042_BYTES { SNAP_OUI_RFC1042_BYTE0, SNAP_OUI_RFC1042_BYTE1, SNAP_OUI_RFC1042_BYTE2 }
90
91
92 typedef enum tETHERTYPES
93 {
94 ETHERTYPE_APPLE_AARP = 0x80f3,
95 ETHERTYPE_DIX_II_IPX = 0x8137
96
97 } ETHERTYPES, *PETHERTYPES;
98
99
IsMacAddressZero(macAddress_t * pMacAddr)100 static __inline BOOL IsMacAddressZero( macAddress_t *pMacAddr )
101 {
102 return( (BOOL)( ( 0 == * (unsigned long *)pMacAddr ) &&
103 ( 0 == *(unsigned short *)( ( (unsigned long *)pMacAddr ) + 1 ) ) ) );
104
105 }
106
107
ClearMacAddress(macAddress_t * pMacAddr)108 static __inline void ClearMacAddress( macAddress_t *pMacAddr )
109 {
110 * (unsigned long *)pMacAddr = 0;
111 *(unsigned short *)( ( (unsigned long *)pMacAddr ) + 1 ) = 0;
112 }
113
114
IsMacAddressEqual(macAddress_t * pMacAddr1,macAddress_t * pMacAddr2)115 static __inline BOOL IsMacAddressEqual( macAddress_t *pMacAddr1, macAddress_t *pMacAddr2 )
116 {
117 return( (BOOL)(
118 ( * (unsigned long *)pMacAddr1 ==
119 * (unsigned long *)pMacAddr2 ) &&
120
121 ( *( (unsigned short *)( ( (unsigned long *)pMacAddr1 ) + 1 ) ) ==
122 *( (unsigned short *)( ( (unsigned long *)pMacAddr2 ) + 1 ) ) ) ) );
123 }
124
SetMacAddressBroadcast(macAddress_t * pMacAddr)125 static __inline void SetMacAddressBroadcast( macAddress_t *pMacAddr )
126 {
127 * (unsigned long *)pMacAddr = 0xffffffff;
128 *(unsigned short *)( ( (unsigned long *)pMacAddr ) + 1 ) = 0xffff;
129
130 }
131
132
IsMacAddressGroup(macAddress_t * pMACAddr)133 static __inline BOOL IsMacAddressGroup( macAddress_t *pMACAddr )
134 {
135 return( pMACAddr->addr[ 0 ] & MAC_ADDRESS_GROUP_BIT );
136 }
137
138
IsMacAddressDirected(macAddress_t * pMACAddr)139 static __inline BOOL IsMacAddressDirected( macAddress_t *pMACAddr )
140 {
141 return( !IsMacAddressGroup( pMACAddr ) );
142 }
143
144
145
IsMacAddressBroadcast(macAddress_t * pMacAddr)146 static __inline BOOL IsMacAddressBroadcast( macAddress_t *pMacAddr )
147 {
148 /* In WinCE an adrress that is not divided by 4 causes exception here */
149 return( (BOOL)( ( 0xffff == *(unsigned short *)pMacAddr ) &&
150 ( 0xffff == *(((unsigned short *)pMacAddr) + 1 ) ) &&
151 ( 0xffff == *(((unsigned short *)pMacAddr) + 2 ) )));
152 /* return( (BOOL)( ( 0xffffffff == * (unsigned long *)pMacAddr ) &&
153 ( 0xffff == *(unsigned short *)( ( (unsigned long *)pMacAddr ) + 1 ) ) ) );*/
154
155 }
156
157
IsMacAddressMulticast(macAddress_t * pMACAddr)158 static __inline BOOL IsMacAddressMulticast( macAddress_t *pMACAddr )
159 {
160 return( IsMacAddressGroup( pMACAddr ) && !IsMacAddressBroadcast( pMACAddr ) );
161 }
162
163
164
165 #endif
166