131 @param [in] iapId ID of IAP to fetch. |
145 @param [in] iapId ID of IAP to fetch. |
132 |
146 |
133 @return Found IAP, NULL if not found. |
147 @return Found IAP, NULL if not found. |
134 */ |
148 */ |
135 |
149 |
136 QSharedPointer<WlanQtUtilsIap> WlanQtUtilsIapSettings::fetchIap(int iapId) const |
150 QSharedPointer<WlanQtUtilsIap> WlanQtUtilsIapSettings::fetchIap(uint iapId) const |
137 { |
151 { |
138 OstTraceFunctionEntry0(WLANQTUTILSIAPSETTINGS_FETCHIAP_ENTRY); |
152 OstTraceFunctionEntry0(WLANQTUTILSIAPSETTINGS_FETCHIAP_ENTRY); |
139 |
153 |
140 OstTrace1( |
|
141 TRACE_NORMAL, |
|
142 WLANQTUTILSIAPSETTINGS_FETCHIAP, |
|
143 "WlanQtUtilsIapSettings::fetchIap;iapId=%d", |
|
144 iapId); |
|
145 |
|
146 QSharedPointer<WlanQtUtilsIap> wlanIap; |
154 QSharedPointer<WlanQtUtilsIap> wlanIap; |
147 try { |
155 try { |
148 QScopedPointer<CmConnectionMethodShim> iap( |
156 QScopedPointer<CmConnectionMethodShim> iap( |
149 mCmManager->connectionMethod(iapId)); |
157 mCmManager->connectionMethod(iapId)); |
150 if (iap && iap->getIntAttribute(CMManagerShim::CmBearerType) == |
158 if (iap && iap->getIntAttribute(CMManagerShim::CmBearerType) == |
152 |
160 |
153 // Get WLAN IAP parameters |
161 // Get WLAN IAP parameters |
154 int netId = iap->getIntAttribute(CMManagerShim::CmNetworkId); |
162 int netId = iap->getIntAttribute(CMManagerShim::CmNetworkId); |
155 QString name = iap->getStringAttribute(CMManagerShim::CmName); |
163 QString name = iap->getStringAttribute(CMManagerShim::CmName); |
156 QString ssid = iap->getStringAttribute(CMManagerShim::WlanSSID); |
164 QString ssid = iap->getStringAttribute(CMManagerShim::WlanSSID); |
|
165 int connMode = iap->getIntAttribute(CMManagerShim::WlanConnectionMode); |
157 int secMode = iap->getIntAttribute( |
166 int secMode = iap->getIntAttribute( |
158 CMManagerShim::WlanSecurityMode); |
167 CMManagerShim::WlanSecurityMode); |
159 bool wpaPskUse = iap->getBoolAttribute( |
168 bool wpaPskUse = iap->getBoolAttribute( |
160 CMManagerShim::WlanEnableWpaPsk); |
169 CMManagerShim::WlanEnableWpaPsk); |
161 |
170 |
163 wlanIap = QSharedPointer<WlanQtUtilsIap>(new WlanQtUtilsIap()); |
172 wlanIap = QSharedPointer<WlanQtUtilsIap>(new WlanQtUtilsIap()); |
164 wlanIap->setValue(WlanQtUtilsIap::ConfIdIapId, iapId); |
173 wlanIap->setValue(WlanQtUtilsIap::ConfIdIapId, iapId); |
165 wlanIap->setValue(WlanQtUtilsIap::ConfIdNetworkId, netId); |
174 wlanIap->setValue(WlanQtUtilsIap::ConfIdNetworkId, netId); |
166 wlanIap->setValue(WlanQtUtilsIap::ConfIdName, name); |
175 wlanIap->setValue(WlanQtUtilsIap::ConfIdName, name); |
167 wlanIap->setValue(WlanQtUtilsAp::ConfIdSsid, ssid); |
176 wlanIap->setValue(WlanQtUtilsAp::ConfIdSsid, ssid); |
|
177 wlanIap->setValue(WlanQtUtilsAp::ConfIdConnectionMode, connMode); |
168 wlanIap->setValue(WlanQtUtilsAp::ConfIdSecurityMode, secMode); |
178 wlanIap->setValue(WlanQtUtilsAp::ConfIdSecurityMode, secMode); |
169 wlanIap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, wpaPskUse); |
179 wlanIap->setValue(WlanQtUtilsAp::ConfIdWpaPskUse, wpaPskUse); |
|
180 |
|
181 // Trace the fetched IAP |
|
182 traceIap( |
|
183 wlanIap.data(), |
|
184 WLANQTUTILS_IAP_TRACE_FETCH, |
|
185 iapId); |
170 } |
186 } |
171 } catch (const std::exception &ex) { |
187 } catch (const std::exception &ex) { |
172 int error = qt_symbian_exception2Error(ex); |
188 int error = qt_symbian_exception2Error(ex); |
173 OstTrace1( |
189 OstTrace1( |
174 TRACE_NORMAL, |
190 TRACE_NORMAL, |
199 // Create the new IAP |
215 // Create the new IAP |
200 QScopedPointer<CmConnectionMethodShim> iap( |
216 QScopedPointer<CmConnectionMethodShim> iap( |
201 mCmManager->createConnectionMethod(KUidWlanBearerType)); |
217 mCmManager->createConnectionMethod(KUidWlanBearerType)); |
202 storeSettings(wlanAp, iap.data()); |
218 storeSettings(wlanAp, iap.data()); |
203 iapId = iap->getIntAttribute(CMManagerShim::CmIapId); |
219 iapId = iap->getIntAttribute(CMManagerShim::CmIapId); |
|
220 |
|
221 // Trace the created IAP |
|
222 traceIap( |
|
223 wlanAp, |
|
224 WLANQTUTILS_IAP_TRACE_CREATE, |
|
225 iapId); |
204 } catch (const std::exception &ex) { |
226 } catch (const std::exception &ex) { |
205 // Trace error cause and return failure (default value) to caller. |
227 // Trace error cause and return failure (default value) to caller. |
206 int error = qt_symbian_exception2Error(ex); |
228 int error = qt_symbian_exception2Error(ex); |
207 OstTrace1( |
229 OstTrace1( |
208 TRACE_NORMAL, |
230 TRACE_NORMAL, |
323 |
350 |
324 OstTraceFunctionExit0(WLANQTUTILSIAPSETTINGS_MOVEIAPTOINTERNETSNAP_EXIT); |
351 OstTraceFunctionExit0(WLANQTUTILSIAPSETTINGS_MOVEIAPTOINTERNETSNAP_EXIT); |
325 } |
352 } |
326 |
353 |
327 /*! |
354 /*! |
|
355 Set Hotspot metadata to the Hotspot IAP given as parameter. |
|
356 |
|
357 @param [in] iapId ID of IAP to set. |
|
358 */ |
|
359 |
|
360 void WlanQtUtilsIapSettings::setAsHotspotIap(int iapId) |
|
361 { |
|
362 OstTraceFunctionEntry0(WLANQTUTILSIAPSETTINGS_SETASHOTSPOTIAP_ENTRY); |
|
363 |
|
364 try { |
|
365 QScopedPointer<CmConnectionMethodShim> iap( |
|
366 mCmManager->connectionMethod(iapId)); |
|
367 iap->setBoolAttribute(CMManagerShim::CmMetaHotSpot, true); |
|
368 iap->update(); |
|
369 } catch (const std::exception &ex) { |
|
370 // Just trace error cause. It is not fatal, if we are not able to |
|
371 // set IAP as hotspot IAP. No need to retry, since errors should be very |
|
372 // rare and it does not prevent connection opening of the hotspot IAP. |
|
373 int error = qt_symbian_exception2Error(ex); |
|
374 OstTrace1( |
|
375 TRACE_NORMAL, |
|
376 WLANQTUTILSIAPSETTINGS_SETASHOTSPOTIAP_EXCEPTION, |
|
377 "WlanQtUtilsIapSettings::setAsHotspotIap exception;error=%d", |
|
378 error); |
|
379 } |
|
380 |
|
381 OstTraceFunctionExit0(WLANQTUTILSIAPSETTINGS_SETASHOTSPOTIAP_EXIT); |
|
382 } |
|
383 |
|
384 /*! |
328 Stores the given Wlan AP settings to database using CM Manager Shim. |
385 Stores the given Wlan AP settings to database using CM Manager Shim. |
329 |
386 |
330 @param [in] wlanAp WLAN AP settings to store. |
387 @param [in] wlanAp WLAN AP settings to store. |
331 @param [in] iap WLAN IAP to store to. |
388 @param [in] iap WLAN IAP to store to. |
332 */ |
389 */ |
334 void WlanQtUtilsIapSettings::storeSettings( |
391 void WlanQtUtilsIapSettings::storeSettings( |
335 const WlanQtUtilsAp *wlanAp, |
392 const WlanQtUtilsAp *wlanAp, |
336 CmConnectionMethodShim *iap) |
393 CmConnectionMethodShim *iap) |
337 { |
394 { |
338 OstTraceFunctionEntry0(WLANQTUTILSIAPSETTINGS_STORESETTINGS_ENTRY); |
395 OstTraceFunctionEntry0(WLANQTUTILSIAPSETTINGS_STORESETTINGS_ENTRY); |
339 |
396 |
340 int secMode = wlanAp->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(); |
397 int secMode = wlanAp->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(); |
341 QString ssid = wlanAp->value(WlanQtUtilsAp::ConfIdSsid).toString(); |
398 QString ssid = wlanAp->value(WlanQtUtilsAp::ConfIdSsid).toString(); |
342 |
399 |
343 // Store general values |
400 // Store general settings |
344 iap->setStringAttribute(CMManagerShim::CmName, ssid); |
401 iap->setStringAttribute(CMManagerShim::CmName, ssid); |
345 iap->setStringAttribute(CMManagerShim::WlanSSID, ssid); |
402 iap->setStringAttribute(CMManagerShim::WlanSSID, ssid); |
346 iap->setIntAttribute(CMManagerShim::WlanSecurityMode, secMode); |
403 iap->setIntAttribute(CMManagerShim::WlanSecurityMode, secMode); |
347 iap->setIntAttribute( |
404 iap->setIntAttribute( |
348 CMManagerShim::WlanConnectionMode, |
405 CMManagerShim::WlanConnectionMode, |
349 wlanAp->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt()); |
406 wlanAp->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt()); |
350 |
407 |
351 switch (secMode) { |
408 // Store the WEP settings |
352 case CMManagerShim::WlanSecModeWep: |
409 storeWepKey( |
353 // Store the 4 WEP keys (function does nothing, if a key is not set) |
410 wlanAp->value(WlanQtUtilsAp::ConfIdWepKey1).toString(), |
354 storeWepKey( |
411 1, |
355 wlanAp->value(WlanQtUtilsAp::ConfIdWepKey1).toString(), |
412 iap); |
356 1, |
413 storeWepKey( |
357 iap); |
414 wlanAp->value(WlanQtUtilsAp::ConfIdWepKey2).toString(), |
358 storeWepKey( |
415 2, |
359 wlanAp->value(WlanQtUtilsAp::ConfIdWepKey2).toString(), |
416 iap); |
360 2, |
417 storeWepKey( |
361 iap); |
418 wlanAp->value(WlanQtUtilsAp::ConfIdWepKey3).toString(), |
362 storeWepKey( |
419 3, |
363 wlanAp->value(WlanQtUtilsAp::ConfIdWepKey3).toString(), |
420 iap); |
364 3, |
421 storeWepKey( |
365 iap); |
422 wlanAp->value(WlanQtUtilsAp::ConfIdWepKey4).toString(), |
366 storeWepKey( |
423 4, |
367 wlanAp->value(WlanQtUtilsAp::ConfIdWepKey4).toString(), |
424 iap); |
368 4, |
425 iap->setIntAttribute( |
369 iap); |
426 CMManagerShim::WlanWepKeyIndex, |
370 |
427 wlanAp->value(WlanQtUtilsAp::ConfIdWepDefaultIndex).toInt()); |
371 iap->setIntAttribute( |
428 |
372 CMManagerShim::WlanWepKeyIndex, |
429 // Store WPA PSK settings |
373 wlanAp->value(WlanQtUtilsAp::ConfIdWepDefaultIndex).toInt()); |
430 bool usePsk = wlanAp->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool(); |
374 break; |
431 iap->setBoolAttribute(CMManagerShim::WlanEnableWpaPsk, usePsk); |
375 |
432 QString wpaKey(wlanAp->value(WlanQtUtilsAp::ConfIdWpaPsk).toString()); |
376 case CMManagerShim::WlanSecModeWpa: |
433 iap->setString8Attribute(CMManagerShim::WlanWpaPreSharedKey, wpaKey); |
377 case CMManagerShim::WlanSecModeWpa2: |
434 |
378 // Store WPA PSK values |
435 // Write the settings. |
379 bool usePsk = wlanAp->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool(); |
|
380 iap->setBoolAttribute(CMManagerShim::WlanEnableWpaPsk, usePsk); |
|
381 if (usePsk) { |
|
382 QString wpaKey(wlanAp->value(WlanQtUtilsAp::ConfIdWpaPsk ).toString()); |
|
383 iap->setString8Attribute(CMManagerShim::WlanWpaPreSharedKey, wpaKey); |
|
384 } |
|
385 break; |
|
386 } |
|
387 |
|
388 iap->update(); |
436 iap->update(); |
389 |
437 |
390 OstTraceFunctionExit0(WLANQTUTILSIAPSETTINGS_STORESETTINGS_EXIT); |
438 OstTraceFunctionExit0(WLANQTUTILSIAPSETTINGS_STORESETTINGS_EXIT); |
391 } |
439 } |
392 |
440 |
393 /*! |
441 /*! |
394 Stores the given valid WEP key to database using CM Manager Shim. Ignores |
442 Stores the given valid WEP key to database using CM Manager Shim. If key |
395 keys with zero length. |
443 is not used an empty key must be provided. |
396 |
444 |
397 @note This method MUST not be called for invalid WEP Keys. Wlanwizard |
445 @note This method MUST not be called for invalid WEP Keys and/or indexes. |
398 validates keys, before accepting user input. |
446 Wlanwizard validates keys, before accepting user input. |
399 |
447 |
400 @param [in] key Key to write. |
448 @param [in] key Key to write. |
401 @param [in] index Key index. Valid range is [0,4]. |
449 @param [in] index Key index. Valid range is [0,4]. |
402 @param [in] iap WLAN IAP to store the key into. |
450 @param [in] iap WLAN IAP to store the key into. |
403 */ |
451 */ |
407 int index, |
455 int index, |
408 CmConnectionMethodShim *iap) |
456 CmConnectionMethodShim *iap) |
409 { |
457 { |
410 OstTraceFunctionEntry0(WLANQTUTILSIAPSETTINGS_STOREWEPKEY_ENTRY); |
458 OstTraceFunctionEntry0(WLANQTUTILSIAPSETTINGS_STOREWEPKEY_ENTRY); |
411 |
459 |
412 // Default value is set just to silence compiler, Q_ASSERTs take care |
|
413 // that valid attribute is set below |
|
414 CMManagerShim::ConnectionMethodAttribute attribute = |
|
415 CMManagerShim::WlanWepKey1InHex; |
|
416 |
|
417 int length = key.length(); |
460 int length = key.length(); |
418 if (length == WepHex64BitMaxLength || length == WepHex128BitMaxLength) { |
461 if (length == WepHex64BitMaxLength || length == WepHex128BitMaxLength) { |
419 // HEX |
462 // HEX |
420 switch (index) { |
463 iap->setString8Attribute(mapWepKeyIndexHex(index), key); |
421 case 1: |
|
422 attribute = CMManagerShim::WlanWepKey1InHex; |
|
423 break; |
|
424 |
|
425 case 2: |
|
426 attribute = CMManagerShim::WlanWepKey2InHex; |
|
427 break; |
|
428 |
|
429 case 3: |
|
430 attribute = CMManagerShim::WlanWepKey3InHex; |
|
431 break; |
|
432 |
|
433 case 4: |
|
434 attribute = CMManagerShim::WlanWepKey4InHex; |
|
435 break; |
|
436 |
|
437 #ifndef QT_NO_DEBUG |
|
438 default: |
|
439 // Invalid key index detected |
|
440 Q_ASSERT(0); |
|
441 break; |
|
442 #endif |
|
443 } |
|
444 } else if (length == WepAscii64BitMaxLength || length == WepAscii128BitMaxLength) { |
464 } else if (length == WepAscii64BitMaxLength || length == WepAscii128BitMaxLength) { |
445 // ASCII |
465 // ASCII |
446 switch (index) { |
466 iap->setString8Attribute(mapWepKeyIndexAscii(index), key); |
447 case 1: |
467 } else { |
448 attribute = CMManagerShim::WlanWepKey1InAscii; |
468 // Length must always be a valid one or zero |
449 break; |
469 Q_ASSERT(length == 0); |
450 |
470 |
451 case 2: |
471 // Write default value. Note that the key is stored in the same data |
452 attribute = CMManagerShim::WlanWepKey2InAscii; |
472 // field regardless of the format so writing only one key is enough. |
453 break; |
473 iap->setString8Attribute(mapWepKeyIndexHex(index), key); |
454 |
474 } |
455 case 3: |
475 |
456 attribute = CMManagerShim::WlanWepKey3InAscii; |
476 OstTraceFunctionExit0(WLANQTUTILSIAPSETTINGS_STOREWEPKEY_EXIT); |
457 break; |
477 } |
458 |
478 |
459 case 4: |
479 /*! |
460 attribute = CMManagerShim::WlanWepKey4InAscii; |
480 Maps given Hex WEP key index into the corresponding CM Manager Connection |
461 break; |
481 Method attribute. |
462 |
482 |
|
483 @param [in] index Hex WEP key index [1,4]. |
|
484 |
|
485 @return Connection Method attribute. |
|
486 */ |
|
487 |
|
488 CMManagerShim::ConnectionMethodAttribute WlanQtUtilsIapSettings::mapWepKeyIndexHex( |
|
489 int index) |
|
490 { |
|
491 CMManagerShim::ConnectionMethodAttribute attribute = |
|
492 CMManagerShim::WlanWepKey1InHex; |
|
493 |
|
494 switch (index) { |
|
495 case 1: |
|
496 attribute = CMManagerShim::WlanWepKey1InHex; |
|
497 break; |
|
498 |
|
499 case 2: |
|
500 attribute = CMManagerShim::WlanWepKey2InHex; |
|
501 break; |
|
502 |
|
503 case 3: |
|
504 attribute = CMManagerShim::WlanWepKey3InHex; |
|
505 break; |
|
506 |
|
507 case 4: |
|
508 attribute = CMManagerShim::WlanWepKey4InHex; |
|
509 break; |
|
510 |
463 #ifndef QT_NO_DEBUG |
511 #ifndef QT_NO_DEBUG |
464 default: |
512 default: |
465 // Invalid key index detected |
513 // Invalid key index detected |
466 Q_ASSERT(0); |
514 Q_ASSERT(0); |
467 break; |
515 break; |
|
516 #endif |
|
517 } |
|
518 |
|
519 return attribute; |
|
520 } |
|
521 |
|
522 /*! |
|
523 Maps given Ascii WEP key index into the corresponding CM Manager Connection |
|
524 Method attribute. |
|
525 |
|
526 @param [in] index Ascii WEP key index [1,4]. |
|
527 |
|
528 @return Connection Method attribute. |
|
529 */ |
|
530 |
|
531 CMManagerShim::ConnectionMethodAttribute WlanQtUtilsIapSettings::mapWepKeyIndexAscii( |
|
532 int index) |
|
533 { |
|
534 CMManagerShim::ConnectionMethodAttribute attribute = |
|
535 CMManagerShim::WlanWepKey1InAscii; |
|
536 |
|
537 switch (index) { |
|
538 case 1: |
|
539 attribute = CMManagerShim::WlanWepKey1InAscii; |
|
540 break; |
|
541 |
|
542 case 2: |
|
543 attribute = CMManagerShim::WlanWepKey2InAscii; |
|
544 break; |
|
545 |
|
546 case 3: |
|
547 attribute = CMManagerShim::WlanWepKey3InAscii; |
|
548 break; |
|
549 |
|
550 case 4: |
|
551 attribute = CMManagerShim::WlanWepKey4InAscii; |
|
552 break; |
|
553 |
|
554 #ifndef QT_NO_DEBUG |
|
555 default: |
|
556 // Invalid key index detected |
|
557 Q_ASSERT(0); |
|
558 break; |
468 #endif |
559 #endif |
469 } |
560 } |
470 } |
561 |
471 |
562 return attribute; |
472 if (length > 0) { |
563 } |
473 iap->setString8Attribute(attribute, key); |
564 |
474 } // else: key is not set, ignore |
565 /* |
475 |
566 Traces given IAP (which is taken in as an AP). |
476 OstTraceFunctionExit0(WLANQTUTILSIAPSETTINGS_STOREWEPKEY_EXIT); |
567 |
477 } |
568 @param [in] ap IAP to trace. |
|
569 @param [in] traceType Trace type (WLANQTUTILS_IAP_TRACE_*). |
|
570 @param [in] iapId IAP ID. |
|
571 */ |
|
572 |
|
573 void WlanQtUtilsIapSettings::traceIap( |
|
574 const WlanQtUtilsAp *ap, |
|
575 int traceType, |
|
576 uint iapId) const |
|
577 { |
|
578 #ifndef OST_TRACE_COMPILER_IN_USE |
|
579 Q_UNUSED(ap); |
|
580 Q_UNUSED(traceType); |
|
581 Q_UNUSED(iapId); |
|
582 #else |
|
583 QString ssid_string(ap->value(WlanQtUtilsAp::ConfIdSsid).toString()); |
|
584 TPtrC16 ssid(ssid_string.utf16(), ssid_string.length()); |
|
585 int secMode = ap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(); |
|
586 int connMode = ap->value(WlanQtUtilsAp::ConfIdConnectionMode).toInt(); |
|
587 bool useWpaPsk = ap->value(WlanQtUtilsAp::ConfIdWpaPskUse).toBool(); |
|
588 |
|
589 switch (traceType) { |
|
590 case WLANQTUTILS_IAP_TRACE_FETCH: |
|
591 OstTraceExt5( |
|
592 TRACE_NORMAL, |
|
593 WLANQTUTILSIAPSETTINGS_TRACEIAP_FETCH, |
|
594 "WlanQtUtilsIapSettings::traceIap Fetched;iapId=%u;ssid=%S;secMode=%{WlanSecMode};useWpaPsk=%u;connMode=%{WlanConnMode}", |
|
595 iapId, |
|
596 ssid, |
|
597 secMode, |
|
598 useWpaPsk, |
|
599 connMode); |
|
600 break; |
|
601 |
|
602 case WLANQTUTILS_IAP_TRACE_CREATE: |
|
603 OstTraceExt5( |
|
604 TRACE_NORMAL, |
|
605 WLANQTUTILSIAPSETTINGS_TRACEIAP_CREATE, |
|
606 "WlanQtUtilsIapSettings::traceIap Created;iapId=%u;ssid=%S;secMode=%{WlanSecMode};useWpaPsk=%u;connMode=%{WlanConnMode}", |
|
607 iapId, |
|
608 ssid, |
|
609 secMode, |
|
610 useWpaPsk, |
|
611 connMode); |
|
612 break; |
|
613 |
|
614 case WLANQTUTILS_IAP_TRACE_UPDATE: |
|
615 OstTraceExt5( |
|
616 TRACE_NORMAL, |
|
617 WLANQTUTILSIAPSETTINGS_TRACEIAP_UPDATE, |
|
618 "WlanQtUtilsIapSettings::traceIap Updated;iapId=%u;ssid=%S;secMode=%{WlanSecMode};useWpaPsk=%u;connMode=%{WlanConnMode}", |
|
619 iapId, |
|
620 ssid, |
|
621 secMode, |
|
622 useWpaPsk, |
|
623 connMode); |
|
624 break; |
|
625 } |
|
626 #endif |
|
627 } |