|
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: Implementation of the WlanElementLocator class. |
|
15 * |
|
16 */ |
|
17 |
|
18 /* |
|
19 * %version: 9 % |
|
20 */ |
|
21 |
|
22 #include "config.h" |
|
23 #include "umacelementlocator.h" |
|
24 |
|
25 // offset of the Length field from the beginning of element |
|
26 const TUint KElemLengthOffset = 1; |
|
27 // offset of the Type field from the beginning of element Information |
|
28 const TUint KOuiTypeOffset = 3; |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 WlanElementLocator::WlanElementLocator( const TUint8* aStart, TUint16 aLength ) |
|
35 : iStart ( aStart ), iLength ( aLength ), iIterator( NULL ) |
|
36 { |
|
37 } |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 WlanElementLocator::TWlanLocateStatus WlanElementLocator::InformationElement( |
|
44 TUint8 aIeId, |
|
45 TUint8& aIeLength, |
|
46 const TUint8** aIeData, |
|
47 TBool aValidateLength ) |
|
48 { |
|
49 // The general Information Element format is: |
|
50 // Element id (1 byte) |
|
51 // Length (1 byte) |
|
52 // Information (Length bytes) |
|
53 // |
|
54 |
|
55 TUint8 ie( 0 ); |
|
56 TUint8 len( 0 ); |
|
57 const TUint8* data( NULL ); |
|
58 |
|
59 if ( FirstIE( ie, len, &data ) != EWlanLocateOk ) |
|
60 { |
|
61 aIeLength = 0; |
|
62 *aIeData = NULL; |
|
63 return EWlanLocateElementNotFound; |
|
64 } |
|
65 |
|
66 TWlanLocateStatus ret( EWlanLocateOk ); |
|
67 |
|
68 while ( ie != aIeId && ret == EWlanLocateOk ) |
|
69 { |
|
70 ret = NextIE( ie, len, &data ); |
|
71 } |
|
72 |
|
73 if ( ret == EWlanLocateElementNotFound ) |
|
74 { |
|
75 aIeLength = 0; |
|
76 *aIeData = NULL; |
|
77 return ret; |
|
78 } |
|
79 else |
|
80 { |
|
81 aIeLength = len; |
|
82 *aIeData = data; |
|
83 |
|
84 if ( aValidateLength ) |
|
85 { |
|
86 return ValidIE( aIeId, aIeLength ); |
|
87 } |
|
88 else |
|
89 { |
|
90 return EWlanLocateOk; |
|
91 } |
|
92 } |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 WlanElementLocator::TWlanLocateStatus WlanElementLocator::InformationElement( |
|
100 TUint8 aIeId, |
|
101 const TIeOui& aIeOui, |
|
102 TUint8 aIeOuiType, |
|
103 TUint8& aIeLength, |
|
104 const TUint8** aIeData ) |
|
105 { |
|
106 // Element format is: |
|
107 // ID = Element ID (1 byte) |
|
108 // Len = Length (1 byte) |
|
109 // OUI = OUI (3 bytes) |
|
110 // OUItyp = OUI Type (1 byte) |
|
111 // ... |
|
112 |
|
113 TUint8 ie( aIeId ); |
|
114 TUint8 len( 0 ); |
|
115 const TUint8* data( NULL ); |
|
116 |
|
117 // Find the first element with matching IE id |
|
118 if ( InformationElement( aIeId, len, &data, EFalse ) != |
|
119 EWlanLocateOk ) |
|
120 { // there isn't one |
|
121 aIeLength = 0; |
|
122 *aIeData = NULL; |
|
123 return EWlanLocateElementNotFound; |
|
124 } |
|
125 |
|
126 // The ID is correct but also the OUI, OUI Type and OUI Subtype need to |
|
127 // match |
|
128 TWlanLocateStatus ret( EWlanLocateOk ); |
|
129 |
|
130 const TUint KMinAcceptableIeDataLen = |
|
131 KIeOuiLength + |
|
132 sizeof( KWmmElemOuiType ); |
|
133 |
|
134 while ( ret == EWlanLocateOk && |
|
135 ( len < KMinAcceptableIeDataLen || |
|
136 ie != aIeId || |
|
137 !( data[0] == aIeOui[0] && data[1] == aIeOui[1] && |
|
138 data[2] == aIeOui[2] |
|
139 ) || |
|
140 *( data + KOuiTypeOffset ) != aIeOuiType |
|
141 ) |
|
142 ) |
|
143 { |
|
144 ret = NextIE( ie, len, &data ); |
|
145 } |
|
146 |
|
147 if ( ret == EWlanLocateElementNotFound ) |
|
148 { |
|
149 aIeLength = 0; |
|
150 *aIeData = NULL; |
|
151 return EWlanLocateElementNotFound; |
|
152 } |
|
153 else |
|
154 { |
|
155 aIeLength = len; |
|
156 *aIeData = data; |
|
157 return ValidIE( aIeId, aIeLength, data, aIeOuiType ); |
|
158 } |
|
159 } |
|
160 |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 // ----------------------------------------------------------------------------- |
|
164 // |
|
165 WlanElementLocator::TWlanLocateStatus WlanElementLocator::InformationElement( |
|
166 TUint8 aIeId, |
|
167 const TIeOui& aIeOui, |
|
168 TUint8 aIeOuiType, |
|
169 TUint8 aIeOuiSubtype, |
|
170 TUint8& aIeLength, |
|
171 const TUint8** aIeData ) |
|
172 { |
|
173 // Element format is: |
|
174 // ID = Element ID (1 byte) |
|
175 // Len = Length (1 byte) |
|
176 // OUI = OUI (3 bytes) |
|
177 // OUItyp = OUI Type (1 byte) |
|
178 // OUIsub = OUI Subtype (1 byte) |
|
179 // ... |
|
180 |
|
181 TUint8 ie( aIeId ); |
|
182 TUint8 len( 0 ); |
|
183 const TUint8* data( NULL ); |
|
184 |
|
185 // Find the first element with matching IE id |
|
186 if ( InformationElement( aIeId, len, &data, EFalse ) != |
|
187 EWlanLocateOk ) |
|
188 { // there isn't one |
|
189 aIeLength = 0; |
|
190 *aIeData = NULL; |
|
191 return EWlanLocateElementNotFound; |
|
192 } |
|
193 |
|
194 // The ID is correct but also the OUI, OUI Type and OUI Subtype need to |
|
195 // match |
|
196 TWlanLocateStatus ret( EWlanLocateOk ); |
|
197 |
|
198 const TUint KMinAcceptableIeDataLen = |
|
199 KIeOuiLength + |
|
200 sizeof( KWmmElemOuiType ) + |
|
201 sizeof( KWmmInfoElemOuiSubType ); |
|
202 |
|
203 // offset of the Subtype field from the beginning of element Information |
|
204 const TUint KOuiSubtypeOffset = 4; |
|
205 |
|
206 while ( ret == EWlanLocateOk && |
|
207 ( len < KMinAcceptableIeDataLen || |
|
208 ie != aIeId || |
|
209 !( data[0] == aIeOui[0] && data[1] == aIeOui[1] && |
|
210 data[2] == aIeOui[2] |
|
211 ) || |
|
212 *( data + KOuiTypeOffset ) != aIeOuiType || |
|
213 *( data + KOuiSubtypeOffset ) != aIeOuiSubtype |
|
214 ) |
|
215 ) |
|
216 { |
|
217 ret = NextIE( ie, len, &data ); |
|
218 } |
|
219 |
|
220 if ( ret == EWlanLocateElementNotFound ) |
|
221 { |
|
222 aIeLength = 0; |
|
223 *aIeData = NULL; |
|
224 return EWlanLocateElementNotFound; |
|
225 } |
|
226 else |
|
227 { |
|
228 aIeLength = len; |
|
229 *aIeData = data; |
|
230 return ValidIE( aIeId, aIeLength, data, aIeOuiType, aIeOuiSubtype ); |
|
231 } |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 WlanElementLocator::TWlanLocateStatus WlanElementLocator::FirstIE( |
|
239 TUint8& aIeId, |
|
240 TUint8& aIeLength, |
|
241 const TUint8** aIeData) |
|
242 { |
|
243 iIterator = iStart; |
|
244 return CurrentIE( aIeId, aIeLength, aIeData ); |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 // ----------------------------------------------------------------------------- |
|
250 // |
|
251 WlanElementLocator::TWlanLocateStatus WlanElementLocator::NextIE( |
|
252 TUint8& aIeId, |
|
253 TUint8& aIeLength, |
|
254 const TUint8** aIeData) |
|
255 { |
|
256 iIterator += *( iIterator + KElemLengthOffset ) + KInfoElementHeaderLength; |
|
257 return CurrentIE( aIeId, aIeLength, aIeData ); |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 WlanElementLocator::TWlanLocateStatus WlanElementLocator::CurrentIE( |
|
265 TUint8& aIeId, |
|
266 TUint8& aIeLength, |
|
267 const TUint8** aIeData) const |
|
268 { |
|
269 if ( iIterator >= iStart + iLength ) |
|
270 { |
|
271 aIeId = 0; |
|
272 aIeLength = 0; |
|
273 *aIeData = NULL; |
|
274 return EWlanLocateElementNotFound; |
|
275 } |
|
276 aIeId = *iIterator; |
|
277 aIeLength = *( iIterator + KElemLengthOffset ); |
|
278 *aIeData = iIterator + KInfoElementHeaderLength; |
|
279 return EWlanLocateOk; |
|
280 } |
|
281 |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 // ----------------------------------------------------------------------------- |
|
285 // |
|
286 WlanElementLocator::TWlanLocateStatus WlanElementLocator::ValidIE( |
|
287 TUint8 aIeId, |
|
288 TUint8 aIeLength, |
|
289 const TUint8* aIeData, |
|
290 TUint8 aIeOuiType, |
|
291 TUint8 aIeOuiSubtype ) const |
|
292 { |
|
293 OsTracePrint( KInfoLevel, (TUint8*) |
|
294 ("UMAC: WlanElementLocator::ValidIE: element id: %d"), aIeId ); |
|
295 |
|
296 TWlanLocateStatus status ( EWlanLocateElementNotFound ); |
|
297 |
|
298 switch ( aIeId ) |
|
299 { |
|
300 case E802Dot11SupportedRatesIE: |
|
301 if ( aIeLength >= K802Dot11SupportedRatesIeDataMinLen && |
|
302 // Note! This is not according to 802.11 std, but some |
|
303 // implementations do not follow the standard in this respect |
|
304 aIeLength <= KMaxNumberOfDot11bAndgRates ) |
|
305 { |
|
306 status = EWlanLocateOk; |
|
307 } |
|
308 break; |
|
309 case E802Dot11DsParameterSetIE: |
|
310 if ( aIeLength == K802Dot11DsParameterSetIeDataLen ) |
|
311 { |
|
312 status = EWlanLocateOk; |
|
313 } |
|
314 break; |
|
315 case E802Dot11TimIE: |
|
316 if ( aIeLength >= K802Dot11TimIeDataMinLen && |
|
317 aIeLength <= K802Dot11TimIeDataMaxLen ) |
|
318 { |
|
319 status = EWlanLocateOk; |
|
320 } |
|
321 break; |
|
322 case E802Dot11IbssParameterSetIE: |
|
323 if ( aIeLength == K802Dot11IbssParameterSetIeDataLen ) |
|
324 { |
|
325 status = EWlanLocateOk; |
|
326 } |
|
327 break; |
|
328 case E802Dot11ErpInformationIE: |
|
329 if ( aIeLength == K802Dot11ErpInformationIeDataLen ) |
|
330 { |
|
331 status = EWlanLocateOk; |
|
332 } |
|
333 break; |
|
334 case E802Dot11HtCapabilitiesIE: |
|
335 if ( aIeLength == K802Dot11HtCapabilitiesIeDataLen ) |
|
336 { |
|
337 status = EWlanLocateOk; |
|
338 } |
|
339 break; |
|
340 case E802Dot11ExtendedRatesIE: |
|
341 if ( aIeLength >= K802Dot11ExtendedRatesIeDataMinLen ) |
|
342 { |
|
343 status = EWlanLocateOk; |
|
344 } |
|
345 break; |
|
346 case E802Dot11HtOperationIE: |
|
347 if ( aIeLength == K802Dot11HtOperationIeDataLen ) |
|
348 { |
|
349 status = EWlanLocateOk; |
|
350 } |
|
351 break; |
|
352 case E802Dot11VendorSpecificIE: |
|
353 if ( aIeData ) |
|
354 { |
|
355 if ( !os_memcmp( |
|
356 aIeData, |
|
357 &KWmmElemOui, |
|
358 KIeOuiLength ) && |
|
359 aIeOuiType == KWmmElemOuiType && |
|
360 aIeOuiSubtype == KWmmInfoElemOuiSubType ) |
|
361 { |
|
362 // WMM information element |
|
363 |
|
364 if ( aIeLength == KWmmInfoElemLen ) |
|
365 { |
|
366 status = EWlanLocateOk; |
|
367 } |
|
368 } |
|
369 else if ( !os_memcmp( |
|
370 aIeData, |
|
371 &KWmmElemOui, |
|
372 KIeOuiLength ) && |
|
373 aIeOuiType == KWmmElemOuiType && |
|
374 aIeOuiSubtype == KWmmParamElemOuiSubtype ) |
|
375 { |
|
376 // WMM Parameter Element |
|
377 |
|
378 if ( aIeLength == sizeof( SWmmParamElemData ) ) |
|
379 { |
|
380 status = EWlanLocateOk; |
|
381 } |
|
382 } |
|
383 else |
|
384 { |
|
385 // implementation error |
|
386 OsTracePrint( KErrorLevel, |
|
387 (TUint8*)("UMAC: aIeId: %d"), aIeId ); |
|
388 OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ ); |
|
389 } |
|
390 } |
|
391 else |
|
392 { |
|
393 #ifndef NDEBUG |
|
394 OsTracePrint( KErrorLevel, (TUint8*) |
|
395 ("UMAC: WlanElementLocator::ValidIE: ERROR: aIeData is NULL") ); |
|
396 OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ ); |
|
397 #endif |
|
398 status = EWlanLocateOk; |
|
399 } |
|
400 break; |
|
401 default: |
|
402 // implementation error |
|
403 OsTracePrint( KErrorLevel, |
|
404 (TUint8*)("UMAC: aIeId: %d"), aIeId ); |
|
405 OsAssert( (TUint8*)("UMAC: panic"), (TUint8*)(WLAN_FILE), __LINE__ ); |
|
406 } |
|
407 |
|
408 OsTracePrint( KInfoLevel, (TUint8*) |
|
409 ("UMAC: WlanElementLocator::ValidIE: status: %d"), status ); |
|
410 |
|
411 return status; |
|
412 } |