237 for (mResults->First(); !mResults->IsDone(); mResults->Next()) { |
237 for (mResults->First(); !mResults->IsDone(); mResults->Next()) { |
238 // Create an access point for each result |
238 // Create an access point for each result |
239 QSharedPointer<WlanQtUtilsAp> ap(new WlanQtUtilsAp()); |
239 QSharedPointer<WlanQtUtilsAp> ap(new WlanQtUtilsAp()); |
240 |
240 |
241 // SSID |
241 // SSID |
242 QString ssid = ExtractSsid(); |
242 QByteArray ssid; |
|
243 QString name; |
|
244 ExtractSsid(ssid, name); |
243 |
245 |
244 // Skip over hidden networks. There is no spec for what |
246 // Skip over hidden networks. There is no spec for what |
245 // their names will contain, but at least names with only |
247 // their names will contain, but at least names with only |
246 // null characters and whitespace characters are seen |
248 // null characters and whitespace characters are seen |
247 // in real life. |
249 // in real life. |
248 if (ssid.trimmed().isEmpty()) { |
250 if (name.trimmed().isEmpty()) { |
249 continue; |
251 continue; |
250 } |
252 } |
251 ap->setValue(WlanQtUtilsAp::ConfIdSsid, ssid); |
253 ap->setValue(WlanQtUtilsAp::ConfIdSsid, ssid); |
252 |
254 ap->setValue(WlanQtUtilsAp::ConfIdName, name); |
|
255 |
253 // BSSID |
256 // BSSID |
254 QByteArray bssid = ExtractBssid(); |
257 QByteArray bssid = ExtractBssid(); |
255 ap->setValue(WlanQtUtilsAp::ConfIdBssid, bssid); |
258 ap->setValue(WlanQtUtilsAp::ConfIdBssid, bssid); |
256 |
259 |
257 // Signal strength |
260 // Signal strength |
288 } |
291 } |
289 |
292 |
290 /*! |
293 /*! |
291 Extracts and cleans up the WLAN SSID from current scan result element. |
294 Extracts and cleans up the WLAN SSID from current scan result element. |
292 |
295 |
293 @return SSID string. |
296 @param [out] ssid SSID in raw byte form (to be used in connect). |
294 */ |
297 @param [out] name SSID in decoded form (to be used in UI). |
295 |
298 */ |
296 QString WlanQtUtilsScanApPrivate::ExtractSsid() |
299 |
|
300 void WlanQtUtilsScanApPrivate::ExtractSsid(QByteArray &ssid, QString &name) |
297 { |
301 { |
298 // Get the SSID in raw data format |
302 // Get the SSID in raw data format |
299 TUint8 ieLen; |
303 TUint8 ieLen; |
300 const TUint8* ieData; |
304 const TUint8 *ieData; |
301 TInt ret = mResults->InformationElement(KWlan802Dot11SsidIE, ieLen, &ieData); |
305 TInt ret = mResults->InformationElement(KWlan802Dot11SsidIE, ieLen, &ieData); |
302 |
306 |
303 // Convert into QString |
307 // Default to empty |
304 QString ssid; |
308 name.clear(); |
|
309 ssid.clear(); |
|
310 |
305 if (ret == KErrNone && ieLen > 0) { |
311 if (ret == KErrNone && ieLen > 0) { |
|
312 // Store the SSID exactly like we get it from the scanning. |
|
313 // This is to make sure the connecting works even if our character |
|
314 // conversion changes how the SSID looks like in UI. |
|
315 ssid = QByteArray((char *)ieData, (int)ieLen); |
|
316 |
306 // Trace the buffer as data to ease low level debugging |
317 // Trace the buffer as data to ease low level debugging |
307 OstTraceData( |
318 OstTraceData( |
308 TRACE_DUMP, |
319 TRACE_DUMP, |
309 WLANQTUTILSSCANAPPRIVATE_EXTRACTSSID_DATA, |
320 WLANQTUTILSSCANAPPRIVATE_EXTRACTSSID_DATA, |
310 "WlanQtUtilsScanApPrivate::ExtractSsid data 0x%{hex8[]}", |
321 "WlanQtUtilsScanApPrivate::ExtractSsid data 0x%{hex8[]}", |
311 ieData, |
322 ssid.data(), |
312 ieLen); |
323 ssid.length()); |
|
324 |
|
325 #ifdef OST_TRACE_COMPILER_IN_USE |
|
326 // Additional trace since one byte hex string tracing has problems |
|
327 // TODO: To be removed when the hex above tracing works OK |
|
328 QString ssidHex(ssid.toHex()); |
|
329 TPtrC16 hexString(ssidHex.utf16(), ssidHex.length()); |
|
330 |
|
331 OstTraceExt1( |
|
332 TRACE_DUMP, |
|
333 WLANQTUTILSSCANAPPRIVATE_EXTRACTSSID_HEX, |
|
334 "WlanQtUtilsScanApPrivate::ExtractSsid;ssid hex=%S", |
|
335 hexString); |
|
336 #endif |
313 |
337 |
314 // The IEEE 802.11-2007 section 7.3.2.1 only specifies that |
338 // 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 |
339 // the SSID is 0-32 octets, leaving the format of the octets |
316 // completely open. |
340 // completely open. This means that there are bound to be WLAN |
|
341 // SSID data handling implementations that can not be supported |
|
342 // all at the same time. |
|
343 |
317 // To support a bit wider character set than 7-bit ASCII, we |
344 // To support a bit wider character set than 7-bit ASCII, we |
318 // treat the raw SSID bytes as the lowest octets of Unicode. |
345 // first try to treat the raw SSID bytes as UTF-8. |
319 for (int i = 0; i < ieLen; i++) { |
346 TPtrC8 ssid_data(ieData, (TInt)ieLen); |
320 ssid.append(QChar((uint)ieData[i])); |
347 TBuf16<CMManagerShim::WlanSSIDLength> ssid_utf8; |
|
348 TInt err = CnvUtfConverter::ConvertToUnicodeFromUtf8( |
|
349 ssid_utf8, |
|
350 ssid_data); |
|
351 if (err == KErrNone) { |
|
352 // UTF-8 conversion succeeded, using it. |
|
353 name = QString( |
|
354 reinterpret_cast<const QChar *>(ssid_utf8.Ptr()), |
|
355 ssid_utf8.Length()); |
|
356 } else { |
|
357 // If UTF-8 conversion fails, we fall back to treating each SSID |
|
358 // data byte as the lowest octet of Unicode (UCS-2). |
|
359 for (int i = 0; i < ieLen; i++) { |
|
360 name.append(QChar((uint)ieData[i])); |
|
361 } |
321 } |
362 } |
322 |
363 |
|
364 // Remove nul characters |
|
365 name.remove(QChar()); |
|
366 |
323 #ifdef OST_TRACE_COMPILER_IN_USE |
367 #ifdef OST_TRACE_COMPILER_IN_USE |
324 TPtrC16 string(ssid.utf16(), ssid.length()); |
368 TPtrC16 string(name.utf16(), name.length()); |
325 OstTraceExt1( |
369 OstTraceExt1( |
326 TRACE_DUMP, |
370 TRACE_DUMP, |
327 WLANQTUTILSSCANAPPRIVATE_EXTRACTSSID_STRING, |
371 WLANQTUTILSSCANAPPRIVATE_EXTRACTSSID_STRING, |
328 "WlanQtUtilsScanApPrivate::ExtractSsid string;ssid=%S", |
372 "WlanQtUtilsScanApPrivate::ExtractSsid string;ssid=%S", |
329 string); |
373 string); |
330 #endif |
374 #endif |
331 } |
375 } |
332 |
|
333 // Remove nul characters |
|
334 ssid.remove(QChar()); |
|
335 |
|
336 return ssid; |
|
337 } |
376 } |
338 |
377 |
339 /*! |
378 /*! |
340 Extracts the WLAN BSSID from current scan result element. |
379 Extracts the WLAN BSSID from current scan result element. |
341 |
380 |
344 |
383 |
345 QByteArray WlanQtUtilsScanApPrivate::ExtractBssid() |
384 QByteArray WlanQtUtilsScanApPrivate::ExtractBssid() |
346 { |
385 { |
347 TWlanBssid wlanBssid; |
386 TWlanBssid wlanBssid; |
348 mResults->Bssid(wlanBssid); |
387 mResults->Bssid(wlanBssid); |
349 QByteArray bssid; |
388 QByteArray bssid( |
350 for (int i = 0; i < (int)wlanBssid.Length(); i++) { |
389 reinterpret_cast<const char *>(wlanBssid.Ptr()), |
351 bssid[i] = (char)wlanBssid[i]; |
390 wlanBssid.Length()); |
352 } |
391 |
353 |
392 OstTraceData( |
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, |
393 TRACE_DUMP, |
360 WLANQTUTILSSCANAPPRIVATE_EXTRACTBSSID, |
394 WLANQTUTILSSCANAPPRIVATE_EXTRACTBSSID_DATA, |
361 "WlanQtUtilsScanApPrivate::ExtractBssid;bssid=%S", |
395 "WlanQtUtilsScanApPrivate::ExtractBssid data 0x%{hex8[]}", |
362 string); |
396 bssid.data(), |
363 #endif |
397 bssid.length()); |
364 |
398 |
365 return bssid; |
399 return bssid; |
366 } |
400 } |
367 |
401 |
368 /*! |
402 /*! |