|
1 /* |
|
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Class for parsing 802.11 frames |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CORE_FRAME_DOT11_H |
|
20 #define CORE_FRAME_DOT11_H |
|
21 |
|
22 #include "core_types.h" |
|
23 |
|
24 class core_frame_dot11_ie_c; |
|
25 |
|
26 /** |
|
27 * Class for parsing 802.11 frames. |
|
28 * |
|
29 * @since S60 v3.1 |
|
30 */ |
|
31 NONSHARABLE_CLASS( core_frame_dot11_c ) |
|
32 { |
|
33 |
|
34 public: |
|
35 |
|
36 /** |
|
37 * Bit masks for 802.11 Frame Control fields. |
|
38 */ |
|
39 enum core_dot11_frame_control_e |
|
40 { |
|
41 core_dot11_frame_control_version_mask = 0x0003, |
|
42 core_dot11_frame_control_type_mask = 0x000C, |
|
43 core_dot11_frame_control_subtype_mask = 0x00F0, |
|
44 core_dot11_frame_control_type_subtype_mask = 0x00FC, |
|
45 core_dot11_frame_control_to_ds_mask = 0x0100, |
|
46 core_dot11_frame_control_from_ds_mask = 0x0200, |
|
47 core_dot11_frame_control_more_fragments_mask = 0x0400, |
|
48 core_dot11_frame_control_retry_mask = 0x0800, |
|
49 core_dot11_frame_control_power_mgmt_mask = 0x1000, |
|
50 core_dot11_frame_control_more_data_mask = 0x2000, |
|
51 core_dot11_frame_control_privacy_mask = 0x4000, |
|
52 core_dot11_frame_control_order_mask = 0x8000 |
|
53 }; |
|
54 |
|
55 /** |
|
56 * Enumerations for 802.11 Frame Control Type field. |
|
57 */ |
|
58 enum core_dot11_frame_control_type_e |
|
59 { |
|
60 core_dot11_frame_control_type_management = 0x0000, |
|
61 core_dot11_frame_control_type_control = 0x0004, |
|
62 core_dot11_frame_control_type_data = 0x0008 |
|
63 }; |
|
64 |
|
65 /** |
|
66 * Bit masks for 802.11 Frame Control Subtype field. |
|
67 */ |
|
68 enum core_dot11_frame_control_subtype_e |
|
69 { |
|
70 core_dot11_frame_control_subtype_cf_ack_mask = 0x0010, |
|
71 core_dot11_frame_control_subtype_cf_poll_mask = 0x0020, |
|
72 core_dot11_frame_control_subtype_no_body_mask = 0x0040, |
|
73 core_dot11_frame_control_subtype_qos_mask = 0x0080 |
|
74 }; |
|
75 |
|
76 /** |
|
77 * Enumerations for 802.11 Type/Subtype combinations. |
|
78 */ |
|
79 enum core_dot11_type_e |
|
80 { |
|
81 core_dot11_type_association_req = 0x0000, |
|
82 core_dot11_type_association_resp = 0x0010, |
|
83 core_dot11_type_reassociation_req = 0x0020, |
|
84 core_dot11_type_reassociation_resp = 0x0030, |
|
85 core_dot11_type_probe_req = 0x0040, |
|
86 core_dot11_type_probe_resp = 0x0050, |
|
87 core_dot11_type_beacon = 0x0080, |
|
88 core_dot11_type_action = 0x00D0, |
|
89 core_dot11_type_data = 0x0008, |
|
90 core_dot11_type_qos_data = 0x0088 |
|
91 }; |
|
92 |
|
93 /** |
|
94 * Definitions for Capability bitmask in beacons/probe responses. |
|
95 */ |
|
96 enum core_dot11_capability_e |
|
97 { |
|
98 core_dot11_capability_ess = 0x0001, |
|
99 core_dot11_capability_ibss = 0x0002, |
|
100 core_dot11_capability_cf_pollable = 0x0004, |
|
101 core_dot11_capability_cf_poll_request = 0x0008, |
|
102 core_dot11_capability_privacy = 0x0010, |
|
103 core_dot11_capability_preamble = 0x0020, |
|
104 core_dot11_capability_pbcc = 0x0040, |
|
105 core_dot11_capability_channel_agility = 0x0080, |
|
106 core_dot11_capability_spectrum_mgmt = 0x0100, |
|
107 core_dot11_capability_qos = 0x0200, |
|
108 core_dot11_capability_slot_time = 0x0400, |
|
109 core_dot11_capability_apsd = 0x0800, |
|
110 core_dot11_capability_radio_measurement = 0x1000, |
|
111 core_dot11_capability_dsss_ofdm = 0x2000, |
|
112 core_dot11_capability_delayed_block_ack = 0x4000, |
|
113 core_dot11_capability_immediate_block_ack = 0x8000 |
|
114 }; |
|
115 |
|
116 /** |
|
117 * Factory for creating a parser for the given frame. |
|
118 * |
|
119 * @since S60 v3.1 |
|
120 * @param data_length Length of the frame. |
|
121 * @param data Pointer to the frame data. |
|
122 * @param is_copied Whether the object should take a copy of the frame data. |
|
123 * @return Pointer to the created parser instance. |
|
124 */ |
|
125 static core_frame_dot11_c* instance( |
|
126 u16_t data_length, |
|
127 const u8_t* data, |
|
128 bool_t is_copied ); |
|
129 |
|
130 /** |
|
131 * Destructor. |
|
132 */ |
|
133 virtual ~core_frame_dot11_c(); |
|
134 |
|
135 /** |
|
136 * Return the frame control field of the frame. |
|
137 * |
|
138 * @since S60 v3.1 |
|
139 * @return The frame control field of the frame. |
|
140 */ |
|
141 u16_t frame_control() const; |
|
142 |
|
143 /** |
|
144 * Return the type of the frame. |
|
145 * |
|
146 * @since S60 v3.1 |
|
147 * @return type of the frame |
|
148 */ |
|
149 core_frame_dot11_c::core_dot11_type_e type() const; |
|
150 |
|
151 /** |
|
152 * Return the duration field of the frame. |
|
153 * |
|
154 * @since S60 v3.1 |
|
155 * @return The duration field of the frame. |
|
156 */ |
|
157 u16_t duration() const; |
|
158 |
|
159 /** |
|
160 * Return the destination MAC field of the frame. |
|
161 * |
|
162 * @since S60 v3.1 |
|
163 * @return The destination MAC field of the frame. |
|
164 */ |
|
165 core_mac_address_s destination() const; |
|
166 |
|
167 /** |
|
168 * Return the source MAC field of the frame. |
|
169 * |
|
170 * @since S60 v3.1 |
|
171 * @return The source MAC field of the frame. |
|
172 */ |
|
173 core_mac_address_s source() const; |
|
174 |
|
175 /** |
|
176 * Return the BSSID field of the frame. |
|
177 * |
|
178 * @since S60 v3.1 |
|
179 * @return The BSSID field of the frame. |
|
180 */ |
|
181 core_mac_address_s bssid() const; |
|
182 |
|
183 /** |
|
184 * Return the current length of the frame. |
|
185 * |
|
186 * @since S60 v3.1 |
|
187 * @return The current length of the frame. |
|
188 */ |
|
189 u16_t data_length() const; |
|
190 |
|
191 /** |
|
192 * Return a pointer to the frame data. |
|
193 * |
|
194 * @since S60 v3.1 |
|
195 * @return A pointer to the frame data. |
|
196 */ |
|
197 const u8_t* data() const; |
|
198 |
|
199 /** |
|
200 * Return the length of the payload data. |
|
201 * |
|
202 * @since S60 v3.1 |
|
203 * @return The length of the payload data. |
|
204 */ |
|
205 u16_t payload_data_length() const; |
|
206 |
|
207 /** |
|
208 * Return a pointer to the payload data. |
|
209 * |
|
210 * @since S60 v3.1 |
|
211 * @return A pointer to the payload data. |
|
212 */ |
|
213 const u8_t* payload_data() const; |
|
214 |
|
215 /** |
|
216 * Return the first IE of the frame. |
|
217 * |
|
218 * @since S60 v3.1 |
|
219 * @return Pointer to the first IE, NULL if no IEs. |
|
220 */ |
|
221 core_frame_dot11_ie_c* first_ie(); |
|
222 |
|
223 /** |
|
224 * Return the next IE of the frame. |
|
225 * |
|
226 * @since S60 v3.1 |
|
227 * @return Pointer to the next IE, NULL if no more IEs. |
|
228 */ |
|
229 core_frame_dot11_ie_c* next_ie(); |
|
230 |
|
231 /** |
|
232 * Append an IE to frame. |
|
233 * |
|
234 * @since S60 v3.1 |
|
235 * @param ie IE to add to the frame. |
|
236 */ |
|
237 void append_ie( |
|
238 const core_frame_dot11_ie_c* ie ); |
|
239 |
|
240 /** |
|
241 * Set Destination MAC Address of the frame. |
|
242 * |
|
243 * @since S60 v5.2 |
|
244 * @param da Destination Address to set. |
|
245 */ |
|
246 void set_destination( const core_mac_address_s& da ); |
|
247 |
|
248 /** |
|
249 * Set Source MAC Address of the frame. |
|
250 * |
|
251 * @since S60 v5.2 |
|
252 * @param sa Source Address to set. |
|
253 */ |
|
254 void set_source( const core_mac_address_s& sa ); |
|
255 |
|
256 /** |
|
257 * Return the offset of the first fixed element. |
|
258 * |
|
259 * @since S60 v5.2 |
|
260 * @return The offset of the first fixed element. |
|
261 */ |
|
262 u16_t first_fixed_element_offset() const; |
|
263 |
|
264 protected: |
|
265 |
|
266 /** |
|
267 * Return the offset of the first IE. |
|
268 * @return The offset of the first IE. 0 if the frame doesn't support IEs. |
|
269 */ |
|
270 virtual u16_t first_ie_offset() const; |
|
271 |
|
272 /** |
|
273 * Return the MAC address field from the given index. |
|
274 * |
|
275 * @param index Index of the MAC address field. |
|
276 * @return The MAC address field from the given index. |
|
277 */ |
|
278 core_mac_address_s mac_address( |
|
279 u16_t index ) const; |
|
280 |
|
281 /** |
|
282 * Generate a 802.11 header. |
|
283 * |
|
284 * @param type The Type and Subtype field of the header. |
|
285 * @param duration The Duration field of the frame. |
|
286 * @param destination The destination MAC field of the frame. |
|
287 * @param source The source MAC field of the frame. |
|
288 * @param bssid The BSSID field of the frame. |
|
289 * @param sequence_control The Sequence Control field of the frame. |
|
290 */ |
|
291 void generate( |
|
292 u8_t type, |
|
293 u16_t duration, |
|
294 const core_mac_address_s& destination, |
|
295 const core_mac_address_s& source, |
|
296 const core_mac_address_s& bssid, |
|
297 u16_t sequence_control ); |
|
298 |
|
299 /** |
|
300 * Constructor. |
|
301 * |
|
302 * @param data_length Length of the frame. |
|
303 * @param data Pointer to the frame data. |
|
304 * @param max_data_length The maximum size of the frame buffer. |
|
305 */ |
|
306 core_frame_dot11_c( |
|
307 u16_t data_length, |
|
308 const u8_t* data, |
|
309 u16_t max_data_length ); |
|
310 |
|
311 protected: // data |
|
312 |
|
313 /** The length of the frame. */ |
|
314 u16_t data_length_m; |
|
315 |
|
316 /** Pointer to the frame data. */ |
|
317 u8_t* data_m; |
|
318 |
|
319 /** The maximum frame length when generating a frame or copying it. */ |
|
320 const u16_t max_data_length_m; |
|
321 |
|
322 private: // data |
|
323 |
|
324 /** Whether this frame includes QoS Control field. */ |
|
325 bool_t is_qos_m; |
|
326 |
|
327 /** Whether this frame includes HT Control field. */ |
|
328 bool_t is_ht_m; |
|
329 |
|
330 /** Pointer to the start of the current IE data. Not owned by this pointer. */ |
|
331 const u8_t* current_ie_m; |
|
332 |
|
333 /** The maximum length of the current IE. */ |
|
334 u16_t current_ie_max_length_m; |
|
335 |
|
336 }; |
|
337 |
|
338 #endif // CORE_FRAME_DOT11_H |