|
1 /* |
|
2 * Copyright (c) 2002-2005 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 "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 to dig information of scan results. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "hssscaninfo.h" |
|
22 #include "hssscaninfoie.h" |
|
23 #include <e32std.h> |
|
24 |
|
25 // Default values for information element IDs. |
|
26 const TUint8 WPA_IE_ID = 221; |
|
27 const TUint32 SCAN_WPA_OUI_LENGTH = 4; |
|
28 const TUint8 SCAN_WPA_OUI[] = { 0x00, 0x50, 0xF2, 0x01 }; |
|
29 |
|
30 const TUint8 SCAN_OUI_TYPE_OFFSET = 3; |
|
31 const TUint8 SCAN_OUI_SUBTYPE_OFFSET = 4; |
|
32 |
|
33 // ================= MEMBER FUNCTIONS ======================= |
|
34 |
|
35 // --------------------------------------------------------------------------- |
|
36 // |
|
37 // --------------------------------------------------------------------------- |
|
38 // |
|
39 HssScanInfo::HssScanInfo( const HssScanList& scan_list ) |
|
40 : HssScanListIterator( scan_list ), |
|
41 ie_iter_m( current_m + BODY_OFFSET ) |
|
42 { |
|
43 } |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 HssSecurityMode HssScanInfo::SecurityMode() |
|
50 { |
|
51 HssScanInfoIe ie; |
|
52 return ie.SecurityMode( *this ); |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 // --------------------------------------------------------------------------- |
|
58 // |
|
59 HssScanError HssScanInfo::InformationElement( TUint8 ie_id, |
|
60 TUint8& ie_length, |
|
61 const TUint8** ie_data ) |
|
62 { |
|
63 // IE is not found when the whole scan info element is gone through. |
|
64 // |
|
65 // The Element format is: |
|
66 // +----+----+--...--+ |
|
67 // | a | b | c | |
|
68 // +----+----+--...--+ |
|
69 // where |
|
70 // a) Element id (1 byte) |
|
71 // b) Length (1 byte) |
|
72 // c) Information (length bytes) |
|
73 // |
|
74 |
|
75 TUint8 ie, len; |
|
76 const TUint8* data; |
|
77 |
|
78 if ( FirstIE( ie, len, &data ) != HssScanError_Ok ) |
|
79 { |
|
80 ie_length = 0; |
|
81 *ie_data = NULL; |
|
82 return HssScanError_IeNotFound; |
|
83 } |
|
84 |
|
85 HssScanError ret( HssScanError_Ok ); |
|
86 |
|
87 while ( ie != ie_id && ret == HssScanError_Ok ) |
|
88 { |
|
89 ret = NextIE( ie, len, &data ); |
|
90 } |
|
91 |
|
92 ie_length = len; |
|
93 *ie_data = data; |
|
94 return ret; |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // |
|
99 // --------------------------------------------------------------------------- |
|
100 // |
|
101 HssScanError HssScanInfo::WpaIE( TUint8& ie_length, |
|
102 const TUint8** ie_data ) |
|
103 { |
|
104 // Element format is: |
|
105 // +----+-----+-----+-----+------+-------+--...--+-------+--...--+--------+ |
|
106 // | ID | Len | OUI | Ver | GKCS | PKCSC | PKSCL | AKMSC | AKMSL | RSNCap | |
|
107 // +----+-----+-----+-----+------+-------+--...--+-------+--...--+--------+ |
|
108 // where |
|
109 // ID = Element ID = 221 (1 octet) |
|
110 // Len = Length (1 octet) |
|
111 // OUI = 00:50:F2:01 (4 octets) |
|
112 // Ver = Version (2 octets) |
|
113 // GKCS = Group Key Cipher Suite (4 octets) |
|
114 // PKCSC = Pairwise Key Cipher Suite Count (2 octets) |
|
115 // PKCSL = Pairwise Key Cipher Suite List (4*m octets) |
|
116 // AKMSC = Authenticated Key Management Suite Count (2 octets) |
|
117 // AKMSL = Authenticated Key Management Suite List (4*n octets) |
|
118 // RSNCap = RSN Capabilities |
|
119 |
|
120 TUint8 ie( WPA_IE_ID ), len; |
|
121 const TUint8* data; |
|
122 |
|
123 // Find out the first element |
|
124 if ( InformationElement( WPA_IE_ID, len, &data ) != HssScanError_Ok ) |
|
125 { // Okay, it didn't exist. |
|
126 ie_length = 0; |
|
127 *ie_data = NULL; |
|
128 return HssScanError_IeNotFound; |
|
129 } |
|
130 |
|
131 // The ID is correct but check also the UID. |
|
132 HssScanError ret( HssScanError_Ok ); |
|
133 |
|
134 while ( ie == WPA_IE_ID && |
|
135 ret == HssScanError_Ok && |
|
136 ( len < SCAN_WPA_OUI_LENGTH || |
|
137 !( data[0] == SCAN_WPA_OUI[0] && data[1] == SCAN_WPA_OUI[1] && |
|
138 data[2] == SCAN_WPA_OUI[2] && data[3] == SCAN_WPA_OUI[3] ) ) ) |
|
139 { |
|
140 ret = NextIE( ie, len, &data ); |
|
141 } |
|
142 |
|
143 // Check is the element was corrupted |
|
144 if ( ie != WPA_IE_ID ) |
|
145 { |
|
146 ie_length = 0; |
|
147 *ie_data = NULL; |
|
148 return HssScanError_IeNotFound; |
|
149 } |
|
150 |
|
151 ie_length = len; |
|
152 *ie_data = data; |
|
153 return ret; |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 // --------------------------------------------------------------------------- |
|
159 // |
|
160 HssScanError HssScanInfo::InformationElement( TUint8 ie_id, |
|
161 const HssIeOui& ie_oui, |
|
162 TUint8 ie_oui_type, |
|
163 TUint8& ie_length, |
|
164 const TUint8** ie_data ) |
|
165 { |
|
166 // Element format is: |
|
167 // +----+-----+-----+-----+------+-------+--...--+-------+--...--+--------+ |
|
168 // | ID | Len | OUI | | | | | | | | |
|
169 // +----+-----+-----+-----+------+-------+--...--+-------+--...--+--------+ |
|
170 // where |
|
171 // ID = Element ID (1 octet) |
|
172 // Len = Length (1 octet) |
|
173 // OUI = OUI (3 octets) |
|
174 // OUItyp = OUI Type (1 octet) |
|
175 |
|
176 TUint8 ie( ie_id ); |
|
177 TUint8 len( 0 ); |
|
178 const TUint8* data; |
|
179 |
|
180 // Find the first element |
|
181 if ( InformationElement( ie_id, len, &data ) |
|
182 != HssScanError_Ok ) |
|
183 { // Okay, it didn't exist. |
|
184 ie_length = 0; |
|
185 *ie_data = NULL; |
|
186 return HssScanError_IeNotFound; |
|
187 } |
|
188 |
|
189 // The ID is correct but also the OUI and OUI Type need to match |
|
190 HssScanError ret( HssScanError_Ok ); |
|
191 |
|
192 while ( ret == HssScanError_Ok && |
|
193 ( ie != ie_id || |
|
194 !( data[0] == ie_oui[0] && |
|
195 data[1] == ie_oui[1] && |
|
196 data[2] == ie_oui[2] |
|
197 ) || |
|
198 *( data + SCAN_OUI_TYPE_OFFSET ) != ie_oui_type |
|
199 ) |
|
200 ) |
|
201 { |
|
202 ret = NextIE( ie, len, &data ); |
|
203 } |
|
204 |
|
205 // Check if the element is corrupted |
|
206 if ( ie != ie_id ) |
|
207 { |
|
208 ie_length = 0; |
|
209 *ie_data = NULL; |
|
210 return HssScanError_IeNotFound; |
|
211 } |
|
212 |
|
213 ie_length = len; |
|
214 *ie_data = data; |
|
215 return ret; |
|
216 } |
|
217 |
|
218 // --------------------------------------------------------------------------- |
|
219 // |
|
220 // --------------------------------------------------------------------------- |
|
221 // |
|
222 HssScanError HssScanInfo::InformationElement( TUint8 ie_id, |
|
223 const HssIeOui& ie_oui, |
|
224 TUint8 ie_oui_type, |
|
225 TUint8 ie_oui_subtype, |
|
226 TUint8& ie_length, |
|
227 const TUint8** ie_data ) |
|
228 { |
|
229 // Element format is: |
|
230 // +----+-----+-----+-----+------+-------+--...--+-------+--...--+--------+ |
|
231 // | ID | Len | OUI | | | | | | | | |
|
232 // +----+-----+-----+-----+------+-------+--...--+-------+--...--+--------+ |
|
233 // where |
|
234 // ID = Element ID (1 octet) |
|
235 // Len = Length (1 octet) |
|
236 // OUI = OUI (3 octets) |
|
237 // OUItyp = OUI Type (1 octet) |
|
238 |
|
239 TUint8 ie( ie_id ); |
|
240 TUint8 len( 0 ); |
|
241 const TUint8* data; |
|
242 |
|
243 // Find the first element |
|
244 if ( InformationElement( ie_id, len, &data ) |
|
245 != HssScanError_Ok ) |
|
246 { // Okay, it didn't exist. |
|
247 ie_length = 0; |
|
248 *ie_data = NULL; |
|
249 return HssScanError_IeNotFound; |
|
250 } |
|
251 |
|
252 // The ID is correct but also the OUI and OUI Type need to match |
|
253 HssScanError ret( HssScanError_Ok ); |
|
254 |
|
255 while ( ret == HssScanError_Ok && |
|
256 ( ie != ie_id || |
|
257 !( data[0] == ie_oui[0] && |
|
258 data[1] == ie_oui[1] && |
|
259 data[2] == ie_oui[2] |
|
260 ) || |
|
261 *( data + SCAN_OUI_TYPE_OFFSET ) != ie_oui_type || |
|
262 *( data + SCAN_OUI_SUBTYPE_OFFSET ) != ie_oui_subtype |
|
263 ) |
|
264 ) |
|
265 { |
|
266 ret = NextIE( ie, len, &data ); |
|
267 } |
|
268 |
|
269 // Check if the element is corrupted |
|
270 if ( ie != ie_id ) |
|
271 { |
|
272 ie_length = 0; |
|
273 *ie_data = NULL; |
|
274 return HssScanError_IeNotFound; |
|
275 } |
|
276 |
|
277 ie_length = len; |
|
278 *ie_data = data; |
|
279 return ret; |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------------------------- |
|
283 // |
|
284 // --------------------------------------------------------------------------- |
|
285 // |
|
286 HssScanError HssScanInfo::FirstIE( |
|
287 TUint8& ie, |
|
288 TUint8& length, |
|
289 const TUint8** data) |
|
290 { |
|
291 ie_iter_m = current_m + BODY_OFFSET; |
|
292 return CurrentIE( ie, length, data ); |
|
293 } |
|
294 |
|
295 // --------------------------------------------------------------------------- |
|
296 // |
|
297 // --------------------------------------------------------------------------- |
|
298 // |
|
299 HssScanError HssScanInfo::NextIE( |
|
300 TUint8& ie, |
|
301 TUint8& length, |
|
302 const TUint8** data) |
|
303 { |
|
304 ie_iter_m += *( ie_iter_m+1 ) + 2; |
|
305 return CurrentIE( ie, length, data ); |
|
306 } |
|
307 |
|
308 // --------------------------------------------------------------------------- |
|
309 // |
|
310 // --------------------------------------------------------------------------- |
|
311 // |
|
312 HssScanError HssScanInfo::CurrentIE( |
|
313 TUint8& ie, |
|
314 TUint8& length, |
|
315 const TUint8** data) const |
|
316 { |
|
317 if ( ie_iter_m >= current_m + Size() ) |
|
318 { |
|
319 ie = 0; |
|
320 length = 0; |
|
321 *data = NULL; |
|
322 return HssScanError_IeNotFound; |
|
323 } |
|
324 ie = *ie_iter_m; |
|
325 length = *( ie_iter_m+1 ); |
|
326 *data = ie_iter_m+2; |
|
327 return HssScanError_Ok; |
|
328 } |