1 /* |
|
2 * Copyright (c) 2010 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: |
|
15 * Symbian platform specific implementation of WLAN AP scanning. |
|
16 */ |
|
17 |
|
18 // System includes |
|
19 |
|
20 #include <QList> |
|
21 #include <cmmanagerdefines_shim.h> |
|
22 #include <utf.h> |
|
23 |
|
24 // User includes |
|
25 |
|
26 #include "wlanqtutils.h" |
|
27 #include "wlanqtutilsap.h" |
|
28 #include "wlanqtutilsscan.h" |
|
29 #include "wlanqtutilsscanap_symbian.h" |
|
30 |
|
31 #include "OstTraceDefinitions.h" |
|
32 #ifdef OST_TRACE_COMPILER_IN_USE |
|
33 #include "wlanqtutilsscanap_symbianTraces.h" |
|
34 #endif |
|
35 |
|
36 |
|
37 /*! |
|
38 \class WlanQtUtilsScanApPrivate |
|
39 \brief Symbian platform specific implementation of WLAN AP scanning. |
|
40 |
|
41 Symbian platform specific implementation of WLAN AP scanning. |
|
42 */ |
|
43 |
|
44 |
|
45 // External function prototypes |
|
46 |
|
47 // Local constants |
|
48 |
|
49 // Information Element ID for SSID as specified in 802.11. |
|
50 static const TUint8 KWlan802Dot11SsidIE = 0; |
|
51 |
|
52 // Bit mask for Capability info field to get type (Infra/AdHoc). |
|
53 static const TUint8 KWlan802Dot11CapabilityEssMask = 0x0001; |
|
54 |
|
55 // ======== LOCAL FUNCTIONS ======== |
|
56 |
|
57 // ======== MEMBER FUNCTIONS ======== |
|
58 |
|
59 /*! |
|
60 Static factory constructor. |
|
61 |
|
62 @param [in,out] wrapper Public implementation class reference. |
|
63 |
|
64 @return New instance of the class. |
|
65 */ |
|
66 |
|
67 WlanQtUtilsScanApPrivate *WlanQtUtilsScanApPrivate::NewL(WlanQtUtilsScan *wrapper) |
|
68 { |
|
69 OstTraceFunctionEntry0(WLANQTUTILSSCANAPPRIVATE_NEWL_ENTRY); |
|
70 |
|
71 WlanQtUtilsScanApPrivate *self = new (ELeave) WlanQtUtilsScanApPrivate(wrapper); |
|
72 CleanupStack::PushL(self); |
|
73 self->ConstructL(); |
|
74 CleanupStack::Pop(self); |
|
75 |
|
76 OstTraceFunctionExit0(WLANQTUTILSSCANAPPRIVATE_NEWL_EXIT); |
|
77 return self; |
|
78 } |
|
79 |
|
80 /*! |
|
81 Destructor. |
|
82 */ |
|
83 |
|
84 WlanQtUtilsScanApPrivate::~WlanQtUtilsScanApPrivate() |
|
85 { |
|
86 OstTraceFunctionEntry0(WLANQTUTILSSCANAPPRIVATE_WLANQTUTILSSCANAPPRIVATE_ENTRY); |
|
87 |
|
88 Cancel(); |
|
89 delete mWlanMgmtClient; |
|
90 mWlanMgmtClient = NULL; |
|
91 delete mResults; |
|
92 mResults = NULL; |
|
93 |
|
94 OstTraceFunctionExit0(WLANQTUTILSSCANAPPRIVATE_WLANQTUTILSSCANAPPRIVATE_EXIT); |
|
95 } |
|
96 |
|
97 /*! |
|
98 Starts a broadcast scan of available access points. |
|
99 */ |
|
100 |
|
101 void WlanQtUtilsScanApPrivate::Scan() |
|
102 { |
|
103 OstTraceFunctionEntry0(WLANQTUTILSSCANAPPRIVATE_SCAN_ENTRY); |
|
104 |
|
105 // Scanning while previous scan is not complete is not supported |
|
106 Q_ASSERT(!IsActive()); |
|
107 |
|
108 // Make the scan |
|
109 mWlanMgmtClient->GetScanResults(iStatus, *mResults); |
|
110 SetActive(); |
|
111 |
|
112 OstTraceFunctionExit0(WLANQTUTILSSCANAPPRIVATE_SCAN_EXIT); |
|
113 } |
|
114 |
|
115 /*! |
|
116 Starts a direct scan of available access points having given SSID. |
|
117 |
|
118 @param ssid SSID to scan. |
|
119 */ |
|
120 |
|
121 void WlanQtUtilsScanApPrivate::Scan(const QString &ssid) |
|
122 { |
|
123 OstTraceFunctionEntry0(WLANQTUTILSSCANAPPRIVATE_SCAN_SSID_ENTRY); |
|
124 |
|
125 // Scanning while previous scan is not complete is not supported |
|
126 Q_ASSERT(!IsActive()); |
|
127 |
|
128 // Convert from QString to TBuf8 |
|
129 TBuf<KWlanMaxSsidLength> buffer(ssid.utf16()); |
|
130 TInt error = CnvUtfConverter::ConvertFromUnicodeToUtf8(mWlanSsid, buffer); |
|
131 qt_symbian_throwIfError(error); |
|
132 |
|
133 OstTraceExt1( |
|
134 TRACE_NORMAL, |
|
135 WLANQTUTILSSCANAPPRIVATE_SCAN_SSID, |
|
136 "WlanQtUtilsScanApPrivate::Scan;mWlanSsid=%s", |
|
137 mWlanSsid); |
|
138 |
|
139 // Make the scan |
|
140 mWlanMgmtClient->GetScanResults(mWlanSsid, iStatus, *mResults); |
|
141 SetActive(); |
|
142 |
|
143 OstTraceFunctionExit0(WLANQTUTILSSCANAPPRIVATE_SCAN_SSID_EXIT); |
|
144 } |
|
145 |
|
146 /*! |
|
147 Stops an ongoing scan. |
|
148 */ |
|
149 |
|
150 void WlanQtUtilsScanApPrivate::StopScan() |
|
151 { |
|
152 OstTraceFunctionEntry0(WLANQTUTILSSCANAPPRIVATE_STOPSCAN_ENTRY); |
|
153 |
|
154 Cancel(); |
|
155 |
|
156 OstTraceFunctionExit0(WLANQTUTILSSCANAPPRIVATE_STOPSCAN_EXIT); |
|
157 } |
|
158 |
|
159 /*! |
|
160 Scan results handler. |
|
161 */ |
|
162 |
|
163 void WlanQtUtilsScanApPrivate::RunL() |
|
164 { |
|
165 OstTraceFunctionEntry0(WLANQTUTILSSCANAPPRIVATE_RUNL_ENTRY); |
|
166 |
|
167 QT_TRYCATCH_LEAVING( |
|
168 if (iStatus != KErrNone) { |
|
169 // Scan failed |
|
170 emit q_ptr->scanFailed(WlanQtUtils::ScanStatusError); |
|
171 } else { |
|
172 // Scan succeeded |
|
173 QList< QSharedPointer<WlanQtUtilsAp> > scanResults; |
|
174 ExtractScanResults(scanResults); |
|
175 |
|
176 // Inform about the results |
|
177 emit q_ptr->availableWlanAps(scanResults); |
|
178 } |
|
179 ); |
|
180 |
|
181 OstTraceFunctionExit0(WLANQTUTILSSCANAPPRIVATE_RUNL_EXIT); |
|
182 } |
|
183 |
|
184 /*! |
|
185 Cancels an outstanding request. |
|
186 */ |
|
187 |
|
188 void WlanQtUtilsScanApPrivate::DoCancel() |
|
189 { |
|
190 OstTraceFunctionEntry0(WLANQTUTILSSCANAPPRIVATE_DOCANCEL_ENTRY); |
|
191 |
|
192 mWlanMgmtClient->CancelGetScanResults(); |
|
193 |
|
194 OstTraceFunctionExit0(WLANQTUTILSSCANAPPRIVATE_DOCANCEL_EXIT); |
|
195 } |
|
196 |
|
197 /*! |
|
198 Constructor. |
|
199 |
|
200 @param [in,out] wrapper Public implementation class reference. |
|
201 */ |
|
202 |
|
203 WlanQtUtilsScanApPrivate::WlanQtUtilsScanApPrivate(WlanQtUtilsScan *wrapper) : |
|
204 CActive(EPriorityStandard), |
|
205 q_ptr(wrapper), |
|
206 mWlanMgmtClient(NULL), |
|
207 mResults(NULL) |
|
208 { |
|
209 OstTraceFunctionEntry0(DUP1_WLANQTUTILSSCANAPPRIVATE_WLANQTUTILSSCANAPPRIVATE_ENTRY); |
|
210 OstTraceFunctionExit0(DUP1_WLANQTUTILSSCANAPPRIVATE_WLANQTUTILSSCANAPPRIVATE_EXIT); |
|
211 } |
|
212 |
|
213 /*! |
|
214 Second phase constructor. |
|
215 */ |
|
216 |
|
217 void WlanQtUtilsScanApPrivate::ConstructL() |
|
218 { |
|
219 OstTraceFunctionEntry0(WLANQTUTILSSCANAPPRIVATE_CONSTRUCTL_ENTRY); |
|
220 |
|
221 CActiveScheduler::Add(this); |
|
222 mWlanMgmtClient = CWlanMgmtClient::NewL(); |
|
223 mResults = CWlanScanInfo::NewL(); |
|
224 |
|
225 OstTraceFunctionExit0(WLANQTUTILSSCANAPPRIVATE_CONSTRUCTL_EXIT); |
|
226 } |
|
227 |
|
228 /* |
|
229 Extracts scan results and stores them into the given AP list. |
|
230 |
|
231 @param [out] scanResults Scan result list. |
|
232 */ |
|
233 |
|
234 void WlanQtUtilsScanApPrivate::ExtractScanResults( |
|
235 QList< QSharedPointer<WlanQtUtilsAp> > &scanResults) |
|
236 { |
|
237 for (mResults->First(); !mResults->IsDone(); mResults->Next()) { |
|
238 // Create an access point for each result |
|
239 QSharedPointer<WlanQtUtilsAp> ap(new WlanQtUtilsAp()); |
|
240 |
|
241 // SSID |
|
242 QString ssid = ExtractSsid(); |
|
243 |
|
244 // Skip over hidden networks. There is no spec for what |
|
245 // their names will contain, but at least names with only |
|
246 // null characters and whitespace characters are seen |
|
247 // in real life. |
|
248 if (ssid.trimmed().isEmpty()) { |
|
249 continue; |
|
250 } |
|
251 ap->setValue(WlanQtUtilsAp::ConfIdSsid, ssid); |
|
252 |
|
253 // BSSID |
|
254 QByteArray bssid = ExtractBssid(); |
|
255 ap->setValue(WlanQtUtilsAp::ConfIdBssid, bssid); |
|
256 |
|
257 // Signal strength |
|
258 ap->setValue( |
|
259 WlanQtUtilsAp::ConfIdSignalStrength, |
|
260 (int)mResults->RXLevel()); |
|
261 |
|
262 // Connection Mode |
|
263 CMManagerShim::WlanConnMode connMode; |
|
264 if (mResults->Capability() & KWlan802Dot11CapabilityEssMask) { |
|
265 connMode = CMManagerShim::Infra; |
|
266 } else { |
|
267 connMode = CMManagerShim::Adhoc; |
|
268 } |
|
269 ap->setValue(WlanQtUtilsAp::ConfIdConnectionMode, (int)connMode); |
|
270 |
|
271 // Security Mode parameters |
|
272 StoreSecMode(ap, mResults->ExtendedSecurityMode()); |
|
273 |
|
274 // Hidden attribute |
|
275 // These scan results do not tell if the AP is hidden or not |
|
276 ap->setValue(WlanQtUtilsAp::ConfIdHidden, false); |
|
277 ap->setValue(WlanQtUtilsAp::ConfIdWlanScanSSID, false); |
|
278 |
|
279 // WPS support |
|
280 TBool wpsSupported = mResults->IsProtectedSetupSupported(); |
|
281 ap->setValue( |
|
282 WlanQtUtilsAp::ConfIdWpsSupported, |
|
283 (wpsSupported == EFalse) ? false : true); |
|
284 |
|
285 // Append the AP to scan result list |
|
286 scanResults.append(ap); |
|
287 } |
|
288 } |
|
289 |
|
290 /*! |
|
291 Extracts and cleans up the WLAN SSID from current scan result element. |
|
292 |
|
293 @return SSID string. |
|
294 */ |
|
295 |
|
296 QString WlanQtUtilsScanApPrivate::ExtractSsid() |
|
297 { |
|
298 // Get the SSID in raw data format |
|
299 TUint8 ieLen; |
|
300 const TUint8* ieData; |
|
301 TInt ret = mResults->InformationElement(KWlan802Dot11SsidIE, ieLen, &ieData); |
|
302 |
|
303 // Convert into QString |
|
304 QString ssid; |
|
305 if (ret == KErrNone && ieLen > 0) { |
|
306 // Trace the buffer as data to ease low level debugging |
|
307 OstTraceData( |
|
308 TRACE_DUMP, |
|
309 WLANQTUTILSSCANAPPRIVATE_EXTRACTSSID_DATA, |
|
310 "WlanQtUtilsScanApPrivate::ExtractSsid data 0x%{hex8[]}", |
|
311 ieData, |
|
312 ieLen); |
|
313 |
|
314 // The IEEE 802.11-2007 section 7.3.2.1 only specifies that |
|
315 // the SSID is 0-32 octets, leaving the format of the octets |
|
316 // completely open. |
|
317 // To support a bit wider character set than 7-bit ASCII, we |
|
318 // treat the raw SSID bytes as the lowest octets of Unicode. |
|
319 for (int i = 0; i < ieLen; i++) { |
|
320 ssid.append(QChar((uint)ieData[i])); |
|
321 } |
|
322 |
|
323 #ifdef OST_TRACE_COMPILER_IN_USE |
|
324 TPtrC16 string(ssid.utf16(), ssid.length()); |
|
325 OstTraceExt1( |
|
326 TRACE_DUMP, |
|
327 WLANQTUTILSSCANAPPRIVATE_EXTRACTSSID_STRING, |
|
328 "WlanQtUtilsScanApPrivate::ExtractSsid string;ssid=%S", |
|
329 string); |
|
330 #endif |
|
331 } |
|
332 |
|
333 // Remove nul characters |
|
334 ssid.remove(QChar()); |
|
335 |
|
336 return ssid; |
|
337 } |
|
338 |
|
339 /*! |
|
340 Extracts the WLAN BSSID from current scan result element. |
|
341 |
|
342 @return BSSID array. |
|
343 */ |
|
344 |
|
345 QByteArray WlanQtUtilsScanApPrivate::ExtractBssid() |
|
346 { |
|
347 TWlanBssid wlanBssid; |
|
348 mResults->Bssid(wlanBssid); |
|
349 QByteArray bssid; |
|
350 for (int i = 0; i < (int)wlanBssid.Length(); i++) { |
|
351 bssid[i] = (char)wlanBssid[i]; |
|
352 } |
|
353 |
|
354 #ifdef OST_TRACE_COMPILER_IN_USE |
|
355 QString bssidHex(bssid.toHex()); |
|
356 TPtrC16 string(bssidHex.utf16(), bssidHex.length()); |
|
357 |
|
358 OstTraceExt1( |
|
359 TRACE_DUMP, |
|
360 WLANQTUTILSSCANAPPRIVATE_EXTRACTBSSID, |
|
361 "WlanQtUtilsScanApPrivate::ExtractBssid;bssid=%S", |
|
362 string); |
|
363 #endif |
|
364 |
|
365 return bssid; |
|
366 } |
|
367 |
|
368 /*! |
|
369 Stores Security mode parameters to \a ap class. |
|
370 |
|
371 @param [in,out] ap Access Point object to where the configuration is stored. |
|
372 @param [in] secMode Security mode to store. |
|
373 */ |
|
374 |
|
375 void WlanQtUtilsScanApPrivate::StoreSecMode( |
|
376 QSharedPointer<WlanQtUtilsAp> ap, |
|
377 TUint wlanSecMode) |
|
378 { |
|
379 CMManagerShim::WlanSecMode secMode = CMManagerShim::WlanSecModeOpen; |
|
380 ap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, false); |
|
381 |
|
382 switch (wlanSecMode) { |
|
383 case EWlanConnectionExtentedSecurityModeWepOpen: |
|
384 case EWlanConnectionExtentedSecurityModeWepShared: |
|
385 secMode = CMManagerShim::WlanSecModeWep; |
|
386 break; |
|
387 |
|
388 case EWlanConnectionExtentedSecurityMode802d1x: |
|
389 secMode = CMManagerShim::WlanSecMode802_1x; |
|
390 break; |
|
391 |
|
392 case EWlanConnectionExtentedSecurityModeWpa: |
|
393 secMode = CMManagerShim::WlanSecModeWpa; |
|
394 break; |
|
395 |
|
396 case EWlanConnectionExtentedSecurityModeWpaPsk: |
|
397 secMode = CMManagerShim::WlanSecModeWpa; |
|
398 ap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true); |
|
399 break; |
|
400 |
|
401 case EWlanConnectionExtentedSecurityModeWpa2: |
|
402 secMode = CMManagerShim::WlanSecModeWpa2; |
|
403 break; |
|
404 |
|
405 case EWlanConnectionExtentedSecurityModeWpa2Psk: |
|
406 secMode = CMManagerShim::WlanSecModeWpa2; |
|
407 ap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, true); |
|
408 break; |
|
409 |
|
410 case EWlanConnectionExtentedSecurityModeWapi: |
|
411 case EWlanConnectionExtentedSecurityModeWapiPsk: |
|
412 secMode = CMManagerShim::WlanSecModeWapi; |
|
413 break; |
|
414 |
|
415 case EWlanConnectionExtentedSecurityModeOpen: |
|
416 secMode = CMManagerShim::WlanSecModeOpen; |
|
417 break; |
|
418 |
|
419 #ifndef QT_NO_DEBUG |
|
420 default: |
|
421 // Invalid security mode detected |
|
422 Q_ASSERT(0); |
|
423 break; |
|
424 #endif |
|
425 } |
|
426 |
|
427 ap->setValue(WlanQtUtilsAp::ConfIdSecurityMode, secMode); |
|
428 } |
|