NetBurner 3.1
ieee802.h
1 /*NB_REVISION*/
2 
3 /*NB_COPYRIGHT*/
4 
5 #ifndef _IEEE802_H_
6 #define _IEEE802_H_
7 
8 /*
9  ******************************************************************************
10  *
11  * All structures are in network order (big-endian)
12  *
13  ******************************************************************************
14  */
15 
16 /*
17  ******************************************************************************
18  *
19  * Constant definitions
20  *
21  ******************************************************************************
22  */
23 /* Destination service access point */
24 #define IEEE802_DSAP_SNAP_PACKET_UNNUMBERED (0xAA)
25 
26 /* Source service access point */
27 #define IEEE802_SSAP_SNAP_PACKET_UNNUMBERED (0xAA)
28 
29 /* Source service access point */
30 #define IEEE802_CONTROL_SNAP_PACKET_UNNUMBERED (0x03)
31 
32 /*
33  OUI
34  IEEE802_OUI_ETHERNET_TYPE 00-00-00
35  IEEE801_OUI_DEC 00-00-F8
36 
37  Notes:
38  Only OUI byte 3 changes so far
39 
40  */
41 #define IEEE802_OUI_ETHERNET_TYPE (0x00)
42 #define IEEE801_OUI_DEC (0xF8)
43 
44 /* OUI length */
45 #define IEEE802_P80211_OUI_LEN (3)
46 
47 /*
48  IEEE 802.11 Control Frame
49  Type
50  IEEE80211_TYPE_MANAGEMENT - Management
51  IEEE80211_TYPE_CONTROL - Control
52  IEEE80211_TYPE_DATA - Data
53 
54  Subtype
55  IEEE80211_SUBTYPE_DATA - Data
56  IEEE80211_SUBTYPE_NULL - No data
57  IEEE80211_SUBTYPE_QOS - QOS
58 
59  */
60 #define IEEE80211_TYPE_MANAGEMENT (0x0)
61 #define IEEE80211_TYPE_CONTROL (0x1)
62 #define IEEE80211_TYPE_DATA (0x2)
63 
64 #define IEEE80211_SUBTYPE_DATA (0x0)
65 #define IEEE80211_SUBTYPE_NULL (0x4)
66 #define IEEE80211_SUBTYPE_QOS (0x8)
67 
68 /*
69  ******************************************************************************
70  *
71  * Structures
72  *
73  ******************************************************************************
74  */
75 /*
76  IEEE 802.3 Standard Frame Media Access Control (MAC) Header
77  destination - Destination MAC-48
78  source - Source MAC-48 address
79  typeOrLength - Type or length
80 
81 */
82 typedef struct _Ieee802_3_Header
83 {
84  MACADDRESS_48 destination;
85  MACADDRESS_48 source;
86  beuint16_t typeOrLength;
87 
88 } __attribute__((packed)) Ieee802_3_Header;
89 
90 /*
91  IEEE 802.2 Logical Link Control (LLC) +
92  Subnetwork Access Protocol (SNAP) header
93 
94  dsap - Destination service access point
95  ssap - Source service access point
96  control - Control
97  oui - Organizationally Unique Identfier
98 
99 
100 */
101 typedef struct _Ieee802_2_SnapHeader
102 {
103  /* LLC for SNAP Header 0xAA 0xAA 0x03 */
104  uint8_t dsap;
105  uint8_t ssap;
106  uint8_t control;
107 
108  /* Organizational Unique Identifier */
109  uint8_t oui[IEEE802_P80211_OUI_LEN];
110 
111  /* Typically EtherType IPV4 (0x0800) */
112  beuint16_t protocolType;
113 
114 } __attribute__((packed)) Ieee802_2_SnapHeader;
115 
116 /*
117  ******************************************************************************
118  * IEEE 802.11
119  ******************************************************************************
120  */
121 /*
122  IEEE 802.11 Packet Header Frame Control Field
123  order - 1 frames strictly ordered
124  wep - 1 yes, 0 no
125  more - More data for destination
126  power - 1 power save, 0 no after transmit
127  retry - Retransmission of previous fragment
128  fragmented - 1 more fragment frames to follow, 0 last frame
129  fromDs - Incoming from distribution system
130  toDs - Forward to distribution system
131  subType - Subtype
132  type - Type
133  version - Currently 0
134 
135  */
136 typedef struct _FrameControl
137 {
138  uint16_t order : 1;
139  uint16_t wep : 1;
140  uint16_t more : 1;
141  uint16_t power : 1;
142  uint16_t retry : 1;
143  uint16_t fragmented : 1;
144  uint16_t fromDs : 1;
145  uint16_t toDs : 1;
146  uint16_t subType : 4;
147  uint16_t type : 2;
148  uint16_t version : 2;
149 
150 } __attribute__((packed)) FrameControl;
151 
152 /*
153  IEEE 802.11 Packet Header Format
154  frameControl - Frame control
155  durationId - Data frame duration, control id of transmitter
156  address[1|2|3|4} - MAC-48 address based on control frame from/to DS
157  sequence - sequence control
158 
159  Notes:
160  Precedes data followed by 4 byte frame sequence check defined in P802.11
161  Addresses
162  -------------------------------------------------------------------
163  | To DS | From DS | Address 1 | Address 2 | Address 3 | Address 4 |
164  -------------------------------------------------------------------
165  | 0 | 0 | DA | SA | BSSID | N/A |
166  | 0 | 1 | DA | BSSID | SA | N/A |
167  | 1 | 0 | BSSID | SA | DA | N/A |
168  | 1 | 1 | RA | TA | DA | SA |
169 
170  ONLY defined for 3 addresses, the 4 address header is used AP to AP
171 
172  */
173 typedef struct _Ieee802_11_Header
174 {
175  FrameControl frameControl;
176  beuint16_t durationId;
177  MACADDRESS_48 address1;
178  MACADDRESS_48 address2;
179  MACADDRESS_48 address3;
180  beuint16_t sequence;
181 
182 } __attribute__((packed)) Ieee802_11_Header;
183 
184 #endif /* _IEEE802_H_ */