174 LOG_ENTERFN( "CWsfWlanScanner::RunL" ); |
175 LOG_ENTERFN( "CWsfWlanScanner::RunL" ); |
175 |
176 |
176 /* |
177 /* |
177 * Scan logic |
178 * Scan logic |
178 * 1. Get available IAPs - state = EIdle |
179 * 1. Get available IAPs - state = EIdle |
179 * 2. Do broadcast scan - state = EIdle |
180 * 2. Do broadcast scan - state = EBroadcastScan |
180 * 3. Process broadcast scan results - state = EBroadcastScan |
181 * 3. Process broadcast scan results - state = EProcessBroadcastScan |
181 * 4. Do direct scans for remaining known networks |
182 * 4. Do direct scans for remaining known networks |
182 * from step 2. Get available IAPs - state = EDirectScan |
183 * from step 2. Get available IAPs - state = EDirectScan |
183 * 5. Add connected network - state = EFinished |
184 * 5. Add connected network - state = EFinished |
184 * 6. Set names and priorities for known networks - state = EFinished |
185 * 6. Set names and priorities for known networks - state = EFinished |
185 */ |
186 */ |
186 |
187 |
187 if ( iScanState == EIdle ) |
188 if ( iScanState == EIdle ) |
188 { |
189 { |
189 LOG_WRITE( "broadcast scan phase" ); |
190 LOG_WRITE( "Get available IAPs scan phase" ); |
190 |
191 |
191 // prepare things for direct scans |
192 // prepare things for direct scans |
192 PrepareDirectScan(); |
193 PrepareDirectScan(); |
193 |
194 |
194 // notify clients |
195 // notify clients |
195 if ( iObserver ) |
196 if ( iObserver ) |
196 { |
197 { |
197 iObserver->WlanScanStarted(); |
198 iObserver->WlanScanStarted(); |
198 } |
199 } |
199 |
|
200 |
200 |
201 #ifndef __WINS__ |
201 #ifndef __WINS__ |
202 // get available iaps |
202 // get available iaps |
203 // (this only shows iaps with security mode matching to scan results |
203 // (this only shows iaps with security mode matching to scan results |
204 // and also finds hidden wlans for which an iap has been configured) |
204 // and also finds hidden wlans for which an iap has been configured) |
205 iAvailableIaps.Reset(); |
205 iAvailableIaps.Reset(); |
206 iWlanMgmtClient->GetAvailableIaps( iAvailableIaps ); |
206 iWlanMgmtClient->GetAvailableIaps( iCacheLifetime, |
207 |
207 iMaxDelay, |
208 // do broadcast scan |
208 EFalse, |
|
209 iStatus, |
|
210 iAvailableIaps ); |
|
211 SetActive(); |
|
212 #else |
|
213 // for testing |
|
214 SetActive(); |
|
215 TRequestStatus* status = &iStatus; |
|
216 User::RequestComplete( status, KErrNone ); |
|
217 #endif |
|
218 iScanState = EBroadcastScan; |
|
219 } |
|
220 |
|
221 else if ( iScanState == EBroadcastScan ) |
|
222 { |
|
223 LOG_WRITEF( "GetAvailableIaps returned iStatus=%d", iStatus.Int() ); |
|
224 if ( iStatus.Int() ) |
|
225 { |
|
226 LOG_WRITE( "Error in getting available IAPs - leave" ); |
|
227 User::Leave( iStatus.Int() ); |
|
228 } |
|
229 |
|
230 #ifdef _DEBUG |
|
231 for ( TInt i = 0; i < iAvailableIaps.Count(); ++i ) |
|
232 { |
|
233 LOG_WRITEF( "iAvailableIaps array index[%d] IapId[%d] rssi[%d]", i, |
|
234 iAvailableIaps[i].iIapId, iAvailableIaps[i].iRssi ); |
|
235 } |
|
236 #endif |
|
237 |
|
238 #ifndef __WINS__ |
|
239 // do broadcast scan |
209 iWlanMgmtClient->GetScanResults( iStatus, *iScanInfo ); |
240 iWlanMgmtClient->GetScanResults( iStatus, *iScanInfo ); |
210 SetActive(); |
241 SetActive(); |
211 #else |
242 #else |
212 // for testing |
243 // for testing |
213 SetActive(); |
244 SetActive(); |
214 TRequestStatus* status = &iStatus; |
245 TRequestStatus* status = &iStatus; |
215 User::RequestComplete( status, KErrNone ); |
246 User::RequestComplete( status, KErrNone ); |
216 #endif |
247 #endif |
217 |
248 iScanState = EProcessBroadcastScan; |
218 iScanState = EBroadcastScan; |
249 } |
219 } |
250 |
220 |
251 else if ( iScanState == EProcessBroadcastScan ) |
221 else if ( iScanState == EBroadcastScan ) |
|
222 { |
252 { |
223 // process broadcast scan results |
253 // process broadcast scan results |
224 DoScanForNetworksL(); |
254 DoScanForNetworksL(); |
225 |
255 |
226 // now it's time to initiate direct scan |
256 // now it's time to initiate direct scan |
528 wi->iSecurityMode == EWlanSecModeWpa || |
561 wi->iSecurityMode == EWlanSecModeWpa || |
529 wi->iSecurityMode == EWlanSecModeWpa2 )? |
562 wi->iSecurityMode == EWlanSecModeWpa2 )? |
530 &Keap: &KNullDesC ); |
563 &Keap: &KNullDesC ); |
531 HBufC16 *ssid = TWsfWlanInfo::GetSsidAsUnicodeLC( wi->iSsid ); |
564 HBufC16 *ssid = TWsfWlanInfo::GetSsidAsUnicodeLC( wi->iSsid ); |
532 |
565 |
533 LOG_WRITEF( "[%S] %S %S %S", ssid, sm, psk, |
566 LOG_WRITEF( "[%S] IapId=%d %S %S %S", ssid, wi->iIapId, sm, psk, |
534 wi->iVisibility? &KNullDesC: &Khidden ); |
567 wi->iVisibility? &KNullDesC: &Khidden ); |
535 CleanupStack::PopAndDestroy( ssid ); |
568 CleanupStack::PopAndDestroy( ssid ); |
536 } |
569 } |
537 |
570 |
538 } |
571 } |
708 void CWsfWlanScanner::BssidChanged( TWlanBssid& /*aNewBSsid*/ ) |
748 void CWsfWlanScanner::BssidChanged( TWlanBssid& /*aNewBSsid*/ ) |
709 { |
749 { |
710 LOG_ENTERFN( "CWsfWlanScanner::BssidChanged" ); |
750 LOG_ENTERFN( "CWsfWlanScanner::BssidChanged" ); |
711 if ( iScanState == EIdle && !IsActive() ) |
751 if ( iScanState == EIdle && !IsActive() ) |
712 { |
752 { |
|
753 iCacheLifetime = -1; |
|
754 iMaxDelay = 0; |
713 // complete ourselves |
755 // complete ourselves |
714 SetActive(); |
756 SetActive(); |
715 TRequestStatus* status = &iStatus; |
757 TRequestStatus* status = &iStatus; |
716 User::RequestComplete( status, KErrNone ); |
758 User::RequestComplete( status, KErrNone ); |
717 } |
759 } |
793 void CWsfWlanScanner::TransmitPowerChanged( TUint /*aPower*/ ) |
843 void CWsfWlanScanner::TransmitPowerChanged( TUint /*aPower*/ ) |
794 { |
844 { |
795 LOG_ENTERFN( "CWsfWlanScanner::TransmitPowerChanged" ); |
845 LOG_ENTERFN( "CWsfWlanScanner::TransmitPowerChanged" ); |
796 if ( iScanState == EIdle && !IsActive() ) |
846 if ( iScanState == EIdle && !IsActive() ) |
797 { |
847 { |
|
848 iCacheLifetime = -1; |
|
849 iMaxDelay = 0; |
798 // complete ourselves |
850 // complete ourselves |
799 SetActive(); |
851 SetActive(); |
800 TRequestStatus* status = &iStatus; |
852 TRequestStatus* status = &iStatus; |
801 User::RequestComplete( status, KErrNone ); |
853 User::RequestComplete( status, KErrNone ); |
802 } |
854 } |
810 void CWsfWlanScanner::RssChanged( TWlanRssClass /*aRssClass*/, TUint /*aRss*/ ) |
862 void CWsfWlanScanner::RssChanged( TWlanRssClass /*aRssClass*/, TUint /*aRss*/ ) |
811 { |
863 { |
812 LOG_ENTERFN( "CWsfWlanScanner::RssChanged" ); |
864 LOG_ENTERFN( "CWsfWlanScanner::RssChanged" ); |
813 if ( iScanState == EIdle && !IsActive() ) |
865 if ( iScanState == EIdle && !IsActive() ) |
814 { |
866 { |
|
867 iCacheLifetime = -1; |
|
868 iMaxDelay = 0; |
815 // complete ourselves |
869 // complete ourselves |
816 SetActive(); |
870 SetActive(); |
817 TRequestStatus* status = &iStatus; |
871 TRequestStatus* status = &iStatus; |
818 User::RequestComplete( status, KErrNone ); |
872 User::RequestComplete( status, KErrNone ); |
819 } |
873 } |
955 LOG_ENTERFN( "CWsfWlanScanner::DoScanForNetworksL" ); |
1009 LOG_ENTERFN( "CWsfWlanScanner::DoScanForNetworksL" ); |
956 |
1010 |
957 // start by making sure the scan array is empty |
1011 // start by making sure the scan array is empty |
958 iScanArray->Reset(); |
1012 iScanArray->Reset(); |
959 |
1013 |
960 LOG_WRITEF( "GetScanResults returned %d", iStatus.Int() ); |
1014 LOG_WRITEF( "GetScanResults returned iStatus=%d", iStatus.Int() ); |
961 |
1015 |
962 if ( iStatus.Int() ) |
1016 if ( iStatus.Int() ) |
963 { |
1017 { |
964 // if the status is not KErrNone, we cannot be sure that iScanInfo |
1018 // if the status is not KErrNone, we cannot be sure that iScanInfo |
965 // doesn't cause a crash, so it's better to leave |
1019 // doesn't cause a crash, so it's better to leave |
|
1020 LOG_WRITE( "Error in getting scan result - leave" ); |
966 User::Leave( iStatus.Int() ); |
1021 User::Leave( iStatus.Int() ); |
967 } |
1022 } |
968 |
1023 |
969 TInt nElem = 0; |
1024 TInt nElem = 0; |
970 TBool isHidden( EFalse ); |
1025 TBool isHidden( EFalse ); |
976 for( TInt i(0); i < avIapCount; i++ ) |
1031 for( TInt i(0); i < avIapCount; i++ ) |
977 { |
1032 { |
978 TBool addToArray( ETrue ); |
1033 TBool addToArray( ETrue ); |
979 TWsfWlanInfo* availableInfo = new ( ELeave ) TWsfWlanInfo(); |
1034 TWsfWlanInfo* availableInfo = new ( ELeave ) TWsfWlanInfo(); |
980 CleanupStack::PushL( availableInfo ); |
1035 CleanupStack::PushL( availableInfo ); |
981 availableInfo->iIapId = iAvailableIaps[i]; |
1036 availableInfo->iIapId = iAvailableIaps[i].iIapId; |
982 TRAPD( error, GetWlanInfoFromIapL( *availableInfo ) ); |
1037 TRAPD( error, GetWlanInfoFromIapL( *availableInfo ) ); |
983 |
1038 |
984 if ( error == KErrNotFound ) |
1039 if ( error == KErrNotFound ) |
985 { |
1040 { |
986 LOG_WRITEF( "Iap id = %d does not exist", availableInfo->iIapId ); |
1041 LOG_WRITEF( "Iap id = %d does not exist", availableInfo->iIapId ); |
995 if( addToArray ) |
1050 if( addToArray ) |
996 { |
1051 { |
997 LOG_WRITE( "Add to array" ); |
1052 LOG_WRITE( "Add to array" ); |
998 availableInfo->iCoverage = 0; |
1053 availableInfo->iCoverage = 0; |
999 availableInfo->iVisibility = 1; |
1054 availableInfo->iVisibility = 1; |
1000 availableInfo->iStrengthLevel = EWlanSignalUnavailable; |
1055 availableInfo->iStrengthLevel = iAvailableIaps[i].iRssi; |
1001 availableInfo->iTransferRate = 0; |
1056 availableInfo->iTransferRate = 0; |
1002 availableInfo->iConnectionState = ENotConnected; |
1057 availableInfo->iConnectionState = ENotConnected; |
1003 iScanArray->AppendL(availableInfo); |
1058 iScanArray->AppendL(availableInfo); |
1004 nElem++; |
1059 nElem++; |
1005 |
1060 |
1006 if ( availableInfo->iIapId ) |
1061 if ( availableInfo->iIapId ) |
1007 { |
1062 { |
1008 LOG_WRITEF( "Append available iap [%d] for direct scan", availableInfo->iIapId ); |
1063 LOG_WRITEF( "Append available iap[%d] rssi[%d] for direct scan", |
|
1064 availableInfo->iIapId, availableInfo->iStrengthLevel ); |
1009 iDirectScanIapIDs.Append( availableInfo->iIapId ); |
1065 iDirectScanIapIDs.Append( availableInfo->iIapId ); |
1010 iDirectScanSsids.Append( availableInfo->iSsid ); |
1066 iDirectScanSsids.Append( availableInfo->iSsid ); |
1011 } |
1067 } |
1012 |
1068 |
1013 CleanupStack::Pop( availableInfo ); |
1069 CleanupStack::Pop( availableInfo ); |
1351 // --------------------------------------------------------------------------- |
1412 // --------------------------------------------------------------------------- |
1352 // |
1413 // |
1353 void CWsfWlanScanner::GetWlanInfoFromIapL( TWsfWlanInfo& aWlanInfo ) |
1414 void CWsfWlanScanner::GetWlanInfoFromIapL( TWsfWlanInfo& aWlanInfo ) |
1354 { |
1415 { |
1355 LOG_ENTERFN( "CWsfWlanScanner::GetWlanInfoFromIapL" ); |
1416 LOG_ENTERFN( "CWsfWlanScanner::GetWlanInfoFromIapL" ); |
|
1417 LOG_WRITEF( "Iap Id = %d", aWlanInfo.iIapId ); |
1356 |
1418 |
1357 CCommsDatabase* commsDb = CCommsDatabase::NewL(); |
1419 CCommsDatabase* commsDb = CCommsDatabase::NewL(); |
1358 CleanupStack::PushL( commsDb ); |
1420 CleanupStack::PushL( commsDb ); |
1359 |
1421 |
1360 CCommsDbTableView* commsDbIapTableView = commsDb->OpenViewMatchingUintLC( |
1422 CCommsDbTableView* commsDbIapTableView = commsDb->OpenViewMatchingUintLC( |
1389 TUint32 secMode(0); |
1451 TUint32 secMode(0); |
1390 wlanTableView->ReadUintL(TPtrC( WLAN_SECURITY_MODE), secMode); |
1452 wlanTableView->ReadUintL(TPtrC( WLAN_SECURITY_MODE), secMode); |
1391 // Map Wpa2 to Wpa |
1453 // Map Wpa2 to Wpa |
1392 secMode = ( secMode == EWlanSecModeWpa2 )? EWlanSecModeWpa : secMode; |
1454 secMode = ( secMode == EWlanSecModeWpa2 )? EWlanSecModeWpa : secMode; |
1393 aWlanInfo.iSecurityMode = static_cast<TWlanSecMode>(secMode); |
1455 aWlanInfo.iSecurityMode = static_cast<TWlanSecMode>(secMode); |
|
1456 |
|
1457 TUint32 usePsk(0); |
|
1458 TRAP_IGNORE( wlanTableView->ReadUintL(TPtrC( WLAN_ENABLE_WPA_PSK ), |
|
1459 usePsk ) ); |
|
1460 |
|
1461 aWlanInfo.SetUsesPreSharedKey( usePsk ); |
1394 |
1462 |
1395 // net mode |
1463 // net mode |
1396 TUint32 netMode(0); |
1464 TUint32 netMode(0); |
1397 wlanTableView->ReadUintL(TPtrC( WLAN_CONNECTION_MODE), netMode); |
1465 wlanTableView->ReadUintL(TPtrC( WLAN_CONNECTION_MODE), netMode); |
1398 aWlanInfo.iNetMode = static_cast<TWlanNetMode>(netMode); |
1466 aWlanInfo.iNetMode = static_cast<TWlanNetMode>(netMode); |