wlan_bearer/wlanengine/wlan_symbian/wlanengine_symbian_3.1/src/wlmserver.cpp
changeset 39 3d23268b50f6
parent 36 1c425781161e
equal deleted inserted replaced
36:1c425781161e 39:3d23268b50f6
    14 * Description:  Server class of wlan engine
    14 * Description:  Server class of wlan engine
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 /*
    18 /*
    19 * %version: 109 %
    19 * %version: 111 %
    20 */
    20 */
    21 
    21 
    22 #include <e32def.h>
    22 #include <e32def.h>
    23 #include <e32std.h>
    23 #include <e32std.h>
    24 #include <featmgr.h>
    24 #include <featmgr.h>
   205         }
   205         }
   206     core_mac_address_s core_mac( ZERO_MAC_ADDR );
   206     core_mac_address_s core_mac( ZERO_MAC_ADDR );
   207     TWlanConversionUtil::ConvertMacAddress( core_mac, mac );
   207     TWlanConversionUtil::ConvertMacAddress( core_mac, mac );
   208 
   208 
   209     // Get Device Settings
   209     // Get Device Settings
   210     CWlanDeviceSettings::SWlanDeviceSettings deviceSettings;
   210     GetWlanSettingsL( iDeviceSettings );
   211     GetWlanSettingsL( deviceSettings );
   211     SetCachedRegion(iDeviceSettings.region, iDeviceSettings.regionTimestamp);    
   212     SetCachedRegion(deviceSettings.region, deviceSettings.regionTimestamp);    
       
   213     core_device_settings_s coreSettings; // core needs the settings here
   212     core_device_settings_s coreSettings; // core needs the settings here
   214     TWlanConversionUtil::ConvertDeviceSettings( coreSettings, deviceSettings );
   213     TWlanConversionUtil::ConvertDeviceSettings( coreSettings, iDeviceSettings );
   215 
   214 
   216     // Create core server    
   215     // Create core server    
   217     User::LeaveIfNull( iCoreServer = core_server_factory_c::instance(
   216     User::LeaveIfNull( iCoreServer = core_server_factory_c::instance(
   218         *this,
   217         *this,
   219         *iDriverIf,
   218         *iDriverIf,
   220         coreSettings,
   219         coreSettings,
   221         core_mac,
   220         core_mac,
   222         TWlanConversionUtil::ConvertFeatureFlags(
   221         TWlanConversionUtil::ConvertFeatureFlags(
   223             iSupportedFeatures,
   222             iSupportedFeatures,
   224             deviceSettings.enabledFeatures ) ) );
   223             iDeviceSettings.enabledFeatures ) ) );
   225     iCoreServer->disable_wlan( KWlanIntCmdDisableWlan );
   224     iCoreServer->disable_wlan( KWlanIntCmdDisableWlan );
   226 
   225 
   227     // Create scan timer
   226     // Create scan timer
   228     DEBUG( "CWlmServer::ConstructL() - create backgroundscan timer" );
   227     DEBUG( "CWlmServer::ConstructL() - create backgroundscan timer" );
   229     TCallBack expiredCb( ScanSchedulingTimerExpired, this );
   228     TCallBack expiredCb( ScanSchedulingTimerExpired, this );
   234         canceledCb,
   233         canceledCb,
   235         emptyCb );
   234         emptyCb );
   236 
   235 
   237     // Create scan cache
   236     // Create scan cache
   238     iCache = CWlanScanResultCache::NewL();
   237     iCache = CWlanScanResultCache::NewL();
   239     iConfiguredCacheLifetime = deviceSettings.scanExpirationTimer;
   238     iConfiguredCacheLifetime = iDeviceSettings.scanExpirationTimer;
   240 
   239 
   241     // Create a callback for asynchronous core requests
   240     // Create a callback for asynchronous core requests
   242     TCallBack callback( HandleCoreAsynchCb, this );
   241     TCallBack callback( HandleCoreAsynchCb, this );
   243     iCoreAsynchCb = new (ELeave) CAsyncCallBack(
   242     iCoreAsynchCb = new (ELeave) CAsyncCallBack(
   244         callback, CActive::EPriorityStandard );
   243         callback, CActive::EPriorityStandard );
   293         }
   292         }
   294 
   293 
   295     // Stop all plugins
   294     // Stop all plugins
   296     iGenericWlanPlugin.StopPlugins();
   295     iGenericWlanPlugin.StopPlugins();
   297 
   296 
       
   297     iIapWeakList.Close();
   298     delete iCoreServer;
   298     delete iCoreServer;
   299     delete iDriverIf;
   299     delete iDriverIf;
   300     iNotificationArray.Close();
   300     iNotificationArray.Close();
   301     delete iCache;
   301     delete iCache;
   302     delete iPlatform;
   302     delete iPlatform;
   658     *connectionStatus = core_connect_undefined;
   658     *connectionStatus = core_connect_undefined;
   659     
   659     
   660     TInt ret = GetCurrentIapId(
   660     TInt ret = GetCurrentIapId(
   661         static_cast<TUint>(lanServiceId), 
   661         static_cast<TUint>(lanServiceId), 
   662         *coreIapData );
   662         *coreIapData );
   663         
   663     iConnectionIapId = coreIapData->iap_id;
       
   664 
   664     if (  ret != KErrNone )
   665     if (  ret != KErrNone )
   665         {
   666         {
   666         secondarySsidList.Close();
   667         secondarySsidList.Close();
   667         delete coreIapData;
   668         delete coreIapData;
   668         delete coreSsidList;
   669         delete coreSsidList;
  1221     DEBUG( "CWlmServer::GetAvailableIaps()" );
  1222     DEBUG( "CWlmServer::GetAvailableIaps()" );
  1222 
  1223 
  1223     // Read cacheLifetime and maxDelay arguments
  1224     // Read cacheLifetime and maxDelay arguments
  1224     TPckgBuf<TInt> cacheLifetimePckg( KWlmDefaultScanCacheLifetime );
  1225     TPckgBuf<TInt> cacheLifetimePckg( KWlmDefaultScanCacheLifetime );
  1225     TPckgBuf<TUint> maxDelayPckg( 0 );
  1226     TPckgBuf<TUint> maxDelayPckg( 0 );
       
  1227     TBool isFiltered(
       
  1228         aMessage.Int3() );
       
  1229     DEBUG1( "CWlmServer::GetAvailableIaps() - isFiltered: %u",
       
  1230         isFiltered );
  1226     if( aMessage.Read( 1, cacheLifetimePckg ) != KErrNone )
  1231     if( aMessage.Read( 1, cacheLifetimePckg ) != KErrNone )
  1227         {
  1232         {
  1228         DEBUG( "CWlmServer::GetAvailableIaps() - unable to read lifetime parameter" );
  1233         DEBUG( "CWlmServer::GetAvailableIaps() - unable to read lifetime parameter" );
  1229 
  1234 
  1230         aMessage.Complete( KErrArgument );
  1235         aMessage.Complete( KErrArgument );
  1252 
  1257 
  1253     /**
  1258     /**
  1254      * See if cached IAP availability information is available.
  1259      * See if cached IAP availability information is available.
  1255      */
  1260      */
  1256     RArray<TWlanLimitedIapData> iapList;
  1261     RArray<TWlanLimitedIapData> iapList;
  1257     RArray<TUint>* list = iCache->AvailableIaps(
  1262     RArray<TWlmAvailabilityData>* list = iCache->AvailableIaps(
  1258                                             iapList,
  1263         iapList,
  1259                                             ( cacheLifetimePckg() == 0 ? 1 : cacheLifetimePckg() ) );
  1264         ( cacheLifetimePckg() == 0 ? 1 : cacheLifetimePckg() ) );
  1260     
       
  1261     // Only complete with valid cache if maxDelay is zero
  1265     // Only complete with valid cache if maxDelay is zero
  1262     if( list && maxDelayPckg() == 0 )
  1266     if( list && maxDelayPckg() == 0 )
  1263         {
  1267         {
  1264 
  1268         TWlmAvailableIaps tmp = { 0 };
  1265         TWlmAvailableIaps tmp;
  1269         if( isFiltered )
  1266         const TInt listCount(
  1270             {            
  1267             Min( list->Count(), KWlmMaxAvailableIaps ) );
  1271             DEBUG1( "CWlmServer::GetAvailableIaps() - using filtered cached IAP list, list contains %d IAP(s)",
  1268         
  1272                 list->Count() );
  1269         DEBUG1( "CWlmServer::GetAvailableIaps() - using cached IAP list, list contains %d IAP(s)", listCount );
  1273 
  1270         
  1274             for( TInt idx( 0 ); idx < list->Count() && tmp.count < KWlmMaxAvailableIaps; ++idx )
  1271         TInt listIdx( 0 );
  1275                 {
  1272 
  1276                 if( (*list)[idx].rcpi >= iDeviceSettings.minRcpiForIapAvailability &&
  1273         while( listIdx < listCount )
  1277                     iIapWeakList.Find( (*list)[idx].iapId ) == KErrNotFound )
  1274             {
  1278                     {
  1275             tmp.iaps[ listIdx ] = (*list)[listIdx];
  1279                     DEBUG2( "CWlmServer::GetAvailableIaps() - IAP %u is available, RCPI is %u",
  1276             ++listIdx;
  1280                         (*list)[idx].iapId, (*list)[idx].rcpi );
  1277             }
  1281                     tmp.iaps[tmp.count++] = (*list)[idx];
  1278         tmp.count = listCount;
  1282                     }
       
  1283                 else
       
  1284                     {
       
  1285                     DEBUG2( "CWlmServer::GetAvailableIaps() - IAP %u filtered, RCPI is %u",
       
  1286                         (*list)[idx].iapId, (*list)[idx].rcpi );
       
  1287                     }
       
  1288                 }
       
  1289             }
       
  1290         else
       
  1291             {
       
  1292             DEBUG1( "CWlmServer::GetAvailableIaps() - using cached IAP list, list contains %d IAP(s)",
       
  1293                 list->Count() );
       
  1294 
       
  1295             for( TInt idx( 0 ); idx < list->Count() && tmp.count < KWlmMaxAvailableIaps; ++idx )
       
  1296                 {
       
  1297                 DEBUG2( "CWlmServer::GetAvailableIaps() - IAP %u is available, RCPI is %u",
       
  1298                     (*list)[idx].iapId, (*list)[idx].rcpi );
       
  1299                 tmp.iaps[tmp.count++] = (*list)[idx];                
       
  1300                 }
       
  1301             }
       
  1302 
  1279         TPckg<TWlmAvailableIaps> outPckg( tmp );
  1303         TPckg<TWlmAvailableIaps> outPckg( tmp );
  1280         aMessage.Write( 0, outPckg );
  1304         aMessage.Write( 0, outPckg );
  1281         aMessage.Complete( KErrNone );
  1305         aMessage.Complete( KErrNone );
  1282         iapList.Close();
  1306         iapList.Close();
  1283 
  1307 
  1328         }
  1352         }
  1329 
  1353 
  1330     iapList.Close();
  1354     iapList.Close();
  1331 
  1355 
  1332     // Create output list
  1356     // Create output list
  1333     core_type_list_c<u32_t>* iapIdList = new core_type_list_c<u32_t>;
  1357     core_type_list_c<core_iap_availability_data_s>* iapAvailabilityList =
  1334     if( iapIdList == NULL )
  1358         new core_type_list_c<core_iap_availability_data_s>;
       
  1359     if( iapAvailabilityList == NULL )
  1335         {
  1360         {
  1336         aMessage.Complete( KErrNoMemory );
  1361         aMessage.Complete( KErrNoMemory );
  1337         delete iapDataList;
  1362         delete iapDataList;
  1338         delete iapSsidList;
  1363         delete iapSsidList;
  1339         return;
  1364         return;
  1344     if( scanList == NULL )
  1369     if( scanList == NULL )
  1345         {
  1370         {
  1346         aMessage.Complete( KErrNoMemory );        
  1371         aMessage.Complete( KErrNoMemory );        
  1347         delete iapDataList;
  1372         delete iapDataList;
  1348         delete iapSsidList;
  1373         delete iapSsidList;
  1349         delete iapIdList;
  1374         delete iapAvailabilityList;
  1350         return;
  1375         return;
  1351         }
  1376         }
  1352 
  1377 
  1353     TUint* scanTime( NULL );
  1378     TUint* scanTime( NULL );
  1354     if( maxDelayPckg() != KWlmInfiniteScanDelay )
  1379     if( maxDelayPckg() != KWlmInfiniteScanDelay )
  1360             DEBUG( "CWlmServer::GetAvailableIaps() - unable to instantiate TUint" );
  1385             DEBUG( "CWlmServer::GetAvailableIaps() - unable to instantiate TUint" );
  1361     
  1386     
  1362             aMessage.Complete( KErrNoMemory );
  1387             aMessage.Complete( KErrNoMemory );
  1363             delete iapDataList;
  1388             delete iapDataList;
  1364             delete iapSsidList;
  1389             delete iapSsidList;
  1365             delete iapIdList;
  1390             delete iapAvailabilityList;
  1366             delete scanList;
  1391             delete scanList;
  1367     
  1392     
  1368             return;
  1393             return;
  1369             }
  1394             }
  1370         }
  1395         }
  1380     mapEntry.iMessage = aMessage;
  1405     mapEntry.iMessage = aMessage;
  1381     mapEntry.iFunction = EGetAvailableIaps;
  1406     mapEntry.iFunction = EGetAvailableIaps;
  1382     mapEntry.iRequestId = iRequestIdCounter++;
  1407     mapEntry.iRequestId = iRequestIdCounter++;
  1383     mapEntry.iSessionId = aSessionId;    
  1408     mapEntry.iSessionId = aSessionId;    
  1384     mapEntry.iParam0 = iapDataList;
  1409     mapEntry.iParam0 = iapDataList;
  1385     mapEntry.iParam1 = iapIdList;
  1410     mapEntry.iParam1 = iapAvailabilityList;
  1386     mapEntry.iParam2 = scanList;
  1411     mapEntry.iParam2 = scanList;
  1387     mapEntry.iParam3 = iapSsidList;
  1412     mapEntry.iParam3 = iapSsidList;
       
  1413     mapEntry.iParam4 = reinterpret_cast<TAny*>( isFiltered );
  1388     mapEntry.iTime = scanTime;
  1414     mapEntry.iTime = scanTime;
  1389     iRequestMap.Append( mapEntry );
  1415     iRequestMap.Append( mapEntry );
  1390 
  1416 
  1391     // Scan scheduling timer needs to be set again if this request needs the results earlier or 
  1417     // Scan scheduling timer needs to be set again if this request needs the results earlier or 
  1392     // if this is the only timed pending request
  1418     // if this is the only timed pending request
  1508         {
  1534         {
  1509         DEBUG1( "CWlmServer::UpdateWlanSettings() - GetWlanSettingsL leaved with code %d", err );
  1535         DEBUG1( "CWlmServer::UpdateWlanSettings() - GetWlanSettingsL leaved with code %d", err );
  1510 
  1536 
  1511         return err;
  1537         return err;
  1512         }
  1538         }
  1513         
  1539     iDeviceSettings = settings;
       
  1540 
  1514     // Only if startup is complete, inform current settings to BgScan
  1541     // Only if startup is complete, inform current settings to BgScan
  1515     if( iIsStartupComplete )
  1542     if( iIsStartupComplete )
  1516         {
  1543         {
  1517         DEBUG( "CWlmServer::UpdateWlanSettings() - notifying settings to BgScan provider" );
  1544         DEBUG( "CWlmServer::UpdateWlanSettings() - notifying settings to BgScan provider" );
  1518         iBgScanProviderSettings = MWlanBgScanProvider::TWlanBgScanSettings( settings.backgroundScanInterval,
  1545         iBgScanProviderSettings = MWlanBgScanProvider::TWlanBgScanSettings( settings.backgroundScanInterval,
  1643 // CWlmServer::NotifyBackgroundScanDone
  1670 // CWlmServer::NotifyBackgroundScanDone
  1644 // ---------------------------------------------------------
  1671 // ---------------------------------------------------------
  1645 //
  1672 //
  1646 void CWlmServer::NotifyBackgroundScanDone(
  1673 void CWlmServer::NotifyBackgroundScanDone(
  1647     ScanList* aScanList, 
  1674     ScanList* aScanList, 
  1648     core_type_list_c<u32_t>* aIapIdList )
  1675     core_type_list_c<core_iap_availability_data_s>& aIapAvailabilityData )
  1649     {
  1676     {
  1650     DEBUG( "CWlmServer::NotifyBackgroundScanDone()" );
  1677     DEBUG( "CWlmServer::NotifyBackgroundScanDone()" );
  1651     ASSERT( aScanList != NULL );
  1678     ASSERT( aScanList != NULL );
  1652     ASSERT( aIapIdList != NULL );
  1679 
  1653     
       
  1654     // Unload the drivers immediately to conserve power.
  1680     // Unload the drivers immediately to conserve power.
  1655     if( !iPlatform->IsWlanDisabled() &&
  1681     if( !iPlatform->IsWlanDisabled() &&
  1656         iConnectionState == EWlanStateNotConnected )
  1682         iConnectionState == EWlanStateNotConnected )
  1657         {
  1683         {
  1658         iCoreServer->unload_drivers();
  1684         iCoreServer->unload_drivers();
  1664     // Update Cached results
  1690     // Update Cached results
  1665     iCache->UpdateScanList( aScanList );
  1691     iCache->UpdateScanList( aScanList );
  1666     TBool newIaps( EFalse );
  1692     TBool newIaps( EFalse );
  1667     TBool lostIaps( EFalse );
  1693     TBool lostIaps( EFalse );
  1668     iCache->UpdateAvailableNetworksList(
  1694     iCache->UpdateAvailableNetworksList(
  1669         *aIapIdList,
  1695         aIapAvailabilityData,
  1670         networkList,
  1696         networkList,
  1671         newIaps,
  1697         newIaps,
  1672         lostIaps );
  1698         lostIaps );
  1673     
  1699     
  1674     networkList.Close();
  1700     networkList.Close();
  1811             switch ( iConnectionState )
  1837             switch ( iConnectionState )
  1812                 {
  1838                 {
  1813                 case EWlanStateNotConnected:
  1839                 case EWlanStateNotConnected:
  1814                     DEBUG( "CWlmServer::notify() - STATE: EWlanStateNotConnected" );
  1840                     DEBUG( "CWlmServer::notify() - STATE: EWlanStateNotConnected" );
  1815                     iIsRoaming = EFalse;
  1841                     iIsRoaming = EFalse;
       
  1842                     iConnectionIapId = 0;
  1816 
  1843 
  1817                     // set icon to "not available"
  1844                     // set icon to "not available"
  1818                     SetIconState( EWlmIconStatusNotAvailable );
  1845                     SetIconState( EWlmIconStatusNotAvailable );
  1819                     
  1846                     
  1820                     // if link was unintentionally lost, scan aggressively
  1847                     // if link was unintentionally lost, scan aggressively
  1895             DEBUG( "CWlmServer::notify() - STATE: EWlmNotifyAcTrafficModeChanged<ind>" );
  1922             DEBUG( "CWlmServer::notify() - STATE: EWlmNotifyAcTrafficModeChanged<ind>" );
  1896             break;
  1923             break;
  1897         case EWlmNotifyAcTrafficStatusChanged:
  1924         case EWlmNotifyAcTrafficStatusChanged:
  1898             DEBUG( "CWlmServer::notify() - STATE: EWlmNotifyAcTrafficStatusChanged<ind>" );
  1925             DEBUG( "CWlmServer::notify() - STATE: EWlmNotifyAcTrafficStatusChanged<ind>" );
  1899             break;
  1926             break;
       
  1927         case EWlmNotifyRcpChanged:
       
  1928             DEBUG( "CWlmServer::notify() - STATE: EWlmNotifyRcpChanged<ind>" );
       
  1929             if( static_cast<core_rcp_class_e>( data[0] ) == core_rcp_normal )
       
  1930                 {
       
  1931                 TInt idx = iIapWeakList.Find( iConnectionIapId );
       
  1932                 if( idx >= 0 )
       
  1933                     {
       
  1934                     DEBUG1( "CWlmServer::notify() - removing IAP %u from weak list",
       
  1935                         iConnectionIapId );
       
  1936                     iIapWeakList.Remove( idx );
       
  1937                     }
       
  1938                 }
       
  1939             else
       
  1940                 {
       
  1941                 TInt idx = iIapWeakList.Find( iConnectionIapId );
       
  1942                 if( idx == KErrNotFound )
       
  1943                     {
       
  1944                     DEBUG1( "CWlmServer::notify() - adding IAP %u to weak list",
       
  1945                         iConnectionIapId );
       
  1946                     iIapWeakList.Append( iConnectionIapId );                    
       
  1947                     }
       
  1948                 }
       
  1949             break;
  1900         default:
  1950         default:
  1901             break;
  1951             break;
  1902         }
  1952         }
  1903     }
  1953     }
  1904 
  1954 
  2620             delete iapSsidList;
  2670             delete iapSsidList;
  2621             iapSsidList = NULL;
  2671             iapSsidList = NULL;
  2622             
  2672             
  2623             ScanList* scanList = 
  2673             ScanList* scanList = 
  2624                 reinterpret_cast<ScanList*>( aRequest.iParam2 );
  2674                 reinterpret_cast<ScanList*>( aRequest.iParam2 );
  2625             core_type_list_c<u32_t>* idList = 
  2675             core_type_list_c<core_iap_availability_data_s>* iapAvailabilityList = 
  2626                 reinterpret_cast<core_type_list_c<u32_t>*>( aRequest.iParam1 );
  2676                 reinterpret_cast<core_type_list_c<core_iap_availability_data_s>*>( aRequest.iParam1 );
  2627                 
       
  2628             core_type_list_c<core_iap_data_s>* iapDataList =
  2677             core_type_list_c<core_iap_data_s>* iapDataList =
  2629                 reinterpret_cast<core_type_list_c<core_iap_data_s>*>( aRequest.iParam0 );
  2678                 reinterpret_cast<core_type_list_c<core_iap_data_s>*>( aRequest.iParam0 );
  2630             delete iapDataList;
  2679             delete iapDataList;
  2631             iapDataList = NULL;
  2680             iapDataList = NULL;
  2632             
  2681             
  2638                 {
  2687                 {
  2639                 DEBUG( "CWlmServer::CompleteInternalRequest() - this request was handled by core" );
  2688                 DEBUG( "CWlmServer::CompleteInternalRequest() - this request was handled by core" );
  2640 
  2689 
  2641                 if( aStatus == core_error_ok )
  2690                 if( aStatus == core_error_ok )
  2642                     {
  2691                     {
  2643                     NotifyBackgroundScanDone( scanList, idList );
  2692                     NotifyBackgroundScanDone( scanList, *iapAvailabilityList );
  2644                     // cache takes the ownership of the scanList
  2693                     // cache takes the ownership of the scanList
  2645                     scanList = NULL;
  2694                     scanList = NULL;
  2646                     }
  2695                     }
  2647             	}
  2696             	}
  2648             else
  2697             else
  2650                 DEBUG( "CWlmServer::CompleteInternalRequest() - this request was not handled by core" );
  2699                 DEBUG( "CWlmServer::CompleteInternalRequest() - this request was not handled by core" );
  2651                 }
  2700                 }
  2652             
  2701             
  2653             delete scanList;
  2702             delete scanList;
  2654             scanList = NULL;
  2703             scanList = NULL;
  2655             delete idList;
  2704             delete iapAvailabilityList;
  2656             idList = NULL;
  2705             iapAvailabilityList = NULL;
  2657                         
  2706                         
  2658             break;
  2707             break;
  2659             }
  2708             }
  2660         case KWlanIntCmdNull: // Fall through on purpose
  2709         case KWlanIntCmdNull: // Fall through on purpose
  2661         default:
  2710         default:
  2787         case EGetAvailableIaps:
  2836         case EGetAvailableIaps:
  2788             {
  2837             {
  2789             // Create pointers to parameters
  2838             // Create pointers to parameters
  2790             core_type_list_c<core_ssid_entry_s>* iapSsidList;
  2839             core_type_list_c<core_ssid_entry_s>* iapSsidList;
  2791             ScanList* scanList;
  2840             ScanList* scanList;
  2792             core_type_list_c<u32_t>* coreIdList;
  2841             core_type_list_c<core_iap_availability_data_s>* coreAvailabilityList;
  2793             core_type_list_c<core_iap_data_s>* iapDataList;
  2842             core_type_list_c<core_iap_data_s>* iapDataList;
       
  2843             TBool isFiltered( reinterpret_cast<TBool>( aRequest.iParam4 ) );
       
  2844             DEBUG1( "CWlmServer::CompleteExternalRequest() - isFiltered: %u",
       
  2845                 isFiltered );
  2794 
  2846 
  2795             iapSsidList = reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( aRequest.iParam3 );
  2847             iapSsidList = reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( aRequest.iParam3 );
  2796             iapDataList = reinterpret_cast<core_type_list_c<core_iap_data_s>*>( aRequest.iParam0 );
  2848             iapDataList = reinterpret_cast<core_type_list_c<core_iap_data_s>*>( aRequest.iParam0 );
  2797             
  2849             
  2798             TUint* completedScanTime = reinterpret_cast<TUint*>( aRequest.iTime );
  2850             TUint* completedScanTime = reinterpret_cast<TUint*>( aRequest.iTime );
  2799             ScanList* completedScanList = reinterpret_cast<ScanList*>( aRequest.iParam2);
  2851             ScanList* completedScanList = reinterpret_cast<ScanList*>( aRequest.iParam2);
  2800             core_type_list_c<u32_t>* completedIdList = reinterpret_cast<core_type_list_c<u32_t>*>( aRequest.iParam1 );
  2852             core_type_list_c<core_iap_availability_data_s>* completedAvailabilityList =
       
  2853                 reinterpret_cast<core_type_list_c<core_iap_availability_data_s>*>( aRequest.iParam1 );
  2801             
  2854             
  2802             if( aTriggerRequest == NULL )
  2855             if( aTriggerRequest == NULL )
  2803                 {
  2856                 {
  2804                 DEBUG( "CWlmServer::CompleteExternalRequest() - GetAvailableIaps request handled by core" );    
  2857                 DEBUG( "CWlmServer::CompleteExternalRequest() - GetAvailableIaps request handled by core" );    
  2805 
  2858 
  2806                 scanList = reinterpret_cast<ScanList*>( aRequest.iParam2);
  2859                 scanList = reinterpret_cast<ScanList*>( aRequest.iParam2);
  2807                 coreIdList = reinterpret_cast<core_type_list_c<u32_t>*>( aRequest.iParam1 );
  2860                 coreAvailabilityList = reinterpret_cast<core_type_list_c<core_iap_availability_data_s>*>( aRequest.iParam1 );
  2808                 }
  2861                 }
  2809             else
  2862             else
  2810                 {
  2863                 {
  2811                 DEBUG( "CWlmServer::CompleteExternalRequest() - GetAvailableIaps request not handled by core" );    
  2864                 DEBUG( "CWlmServer::CompleteExternalRequest() - GetAvailableIaps request not handled by core" );    
  2812                 //Use the results of the triggering request to complete also this other request
  2865                 //Use the results of the triggering request to complete also this other request
  2813                 scanList = reinterpret_cast<ScanList*>( aTriggerRequest->iParam2);
  2866                 scanList = reinterpret_cast<ScanList*>( aTriggerRequest->iParam2);
  2814                 coreIdList = reinterpret_cast<core_type_list_c<u32_t>*>( aTriggerRequest->iParam1 );                
  2867                 coreAvailabilityList = reinterpret_cast<core_type_list_c<core_iap_availability_data_s>*>( aTriggerRequest->iParam1 );                
  2815                 }
  2868                 }
  2816 
  2869 
  2817             delete iapSsidList;
  2870             delete iapSsidList;
  2818             iapSsidList = NULL;
  2871             iapSsidList = NULL;
  2819             delete iapDataList;
  2872             delete iapDataList;
  2829                 TBool lostIaps( EFalse );
  2882                 TBool lostIaps( EFalse );
  2830                 
  2883                 
  2831                 if( aTriggerRequest == NULL )
  2884                 if( aTriggerRequest == NULL )
  2832                     {
  2885                     {
  2833                     iCache->UpdateAvailableNetworksList(
  2886                     iCache->UpdateAvailableNetworksList(
  2834                         *coreIdList,
  2887                         *coreAvailabilityList,
  2835                         networkList,
  2888                         networkList,
  2836                         newIaps,
  2889                         newIaps,
  2837                         lostIaps );
  2890                         lostIaps );
  2838                     }
  2891                     }
  2839                 networkList.Close();                
  2892                 networkList.Close();                
  2840 
  2893 
  2841                 TWlmAvailableIaps tmp;                
  2894                 TWlmAvailableIaps tmp = { 0 };
  2842                 TUint32* pInt = coreIdList->first();
  2895                 core_iap_availability_data_s* pInt = coreAvailabilityList->first();
  2843                 TInt idx = 0;
  2896                 if( isFiltered )
  2844                 while( pInt )
       
  2845                     {
  2897                     {
  2846                     DEBUG1( "CWlmServer::CompleteExternalRequest() - IAP %u is available",
  2898                     while( pInt && tmp.count < KWlmMaxAvailableIaps )
  2847                         *pInt );
  2899                         {
  2848                     tmp.iaps[ idx ] = *pInt;
  2900                         if( pInt->rcpi < iDeviceSettings.minRcpiForIapAvailability )
  2849                     idx++;
  2901                             {
  2850                     pInt = coreIdList->next();
  2902                             DEBUG3( "CWlmServer::CompleteExternalRequest() - IAP %u filtered, RCPI is too weak (%u vs %u)",
       
  2903                                 pInt->id, pInt->rcpi, iDeviceSettings.minRcpiForIapAvailability );
       
  2904                             }
       
  2905                         else if( iIapWeakList.Find( pInt->id ) != KErrNotFound )
       
  2906                             {
       
  2907                             if( pInt->rcpi < iDeviceSettings.rcpiTrigger )
       
  2908                                 {
       
  2909                                 DEBUG3( "CWlmServer::CompleteExternalRequest() - IAP %u filtered, in weak list and RCPI is too weak (%u vs %u)",
       
  2910                                     pInt->id, pInt->rcpi, iDeviceSettings.rcpiTrigger );                            
       
  2911                                 }
       
  2912                             else
       
  2913                                 {
       
  2914                                 DEBUG2( "CWlmServer::CompleteExternalRequest() - IAP %u is available, RCPI is %u, removed from weak list",
       
  2915                                     pInt->id, pInt->rcpi );
       
  2916                                 tmp.iaps[tmp.count].iapId = pInt->id;
       
  2917                                 tmp.iaps[tmp.count++].rcpi = pInt->rcpi;
       
  2918                                 iIapWeakList.Remove(
       
  2919                                     iIapWeakList.Find( pInt->id ) );
       
  2920                                 }
       
  2921                             }
       
  2922                         else
       
  2923                             {
       
  2924                             DEBUG2( "CWlmServer::CompleteExternalRequest() - IAP %u is available, RCPI is %u",
       
  2925                                 pInt->id, pInt->rcpi );
       
  2926                             tmp.iaps[tmp.count].iapId = pInt->id;
       
  2927                             tmp.iaps[tmp.count++].rcpi = pInt->rcpi;
       
  2928                             }
       
  2929                         pInt = coreAvailabilityList->next();
       
  2930                         }
  2851                     }
  2931                     }
  2852 
  2932                 else
  2853                 tmp.count = idx;
  2933                     {
  2854                 
  2934                     while( pInt && tmp.count < KWlmMaxAvailableIaps )
       
  2935                         {
       
  2936                         if( pInt->rcpi >= iDeviceSettings.rcpiTrigger &&
       
  2937                             iIapWeakList.Find( pInt->id ) != KErrNotFound )
       
  2938                             {                            
       
  2939                             DEBUG2( "CWlmServer::CompleteExternalRequest() - IAP %u is available, RCPI is %u, removed from weak list",
       
  2940                                 pInt->id, pInt->rcpi );
       
  2941                             iIapWeakList.Remove(
       
  2942                                 iIapWeakList.Find( pInt->id ) );
       
  2943                             }
       
  2944                         else
       
  2945                             {
       
  2946                             DEBUG2( "CWlmServer::CompleteExternalRequest() - IAP %u is available, RCPI is %u",
       
  2947                                 pInt->id, pInt->rcpi );
       
  2948                             }
       
  2949 
       
  2950                         tmp.iaps[tmp.count].iapId = pInt->id;
       
  2951                         tmp.iaps[tmp.count++].rcpi = pInt->rcpi;
       
  2952                         pInt = coreAvailabilityList->next();                        
       
  2953                         }
       
  2954                     }
       
  2955 
  2855                 if( IsSessionActive( aRequest ) )
  2956                 if( IsSessionActive( aRequest ) )
  2856                     {
  2957                     {
  2857                     TPckg<TWlmAvailableIaps> outPckg( tmp );
  2958                     TPckg<TWlmAvailableIaps> outPckg( tmp );
  2858                     aRequest.iMessage.Write( 0, outPckg );
  2959                     aRequest.iMessage.Write( 0, outPckg );
  2859                     }
  2960                     }
  2860                 if( aTriggerRequest == NULL )
  2961                 if( aTriggerRequest == NULL )
  2861                     {
  2962                     {
  2862                     DEBUG("CWlmServer::CompleteExternalRequest() - delete iapIdList" );
  2963                     DEBUG("CWlmServer::CompleteExternalRequest() - delete coreAvailabilityList" );
  2863                     delete coreIdList;	
  2964                     delete coreAvailabilityList;	
  2864                     }
  2965                     }
  2865                 else
  2966                 else
  2866                     {
  2967                     {
  2867                     // If this completed request was not the triggering request then there is no need
  2968                     // If this completed request was not the triggering request then there is no need
  2868                     // to cache anything. The triggering request results will be cached.
  2969                     // to cache anything. The triggering request results will be cached.
  2869                     delete completedIdList;
  2970                     delete completedAvailabilityList;
  2870                     delete completedScanList;
  2971                     delete completedScanList;
  2871                     }
  2972                     }
  2872 
  2973 
  2873                 // handle scan list
  2974                 // handle scan list
  2874                 if( aTriggerRequest == NULL )
  2975                 if( aTriggerRequest == NULL )
  2885             else
  2986             else
  2886                 {
  2987                 {
  2887                 // scan failed due to some reason: not caching anything
  2988                 // scan failed due to some reason: not caching anything
  2888                 if( aTriggerRequest == NULL )
  2989                 if( aTriggerRequest == NULL )
  2889                     {
  2990                     {
  2890                     delete coreIdList;
  2991                     delete coreAvailabilityList;
  2891                     delete scanList;
  2992                     delete scanList;
  2892                     }
  2993                     }
  2893                 else
  2994                 else
  2894                     {
  2995                     {
  2895                     // Delete only the lists of the completed request. Triggering request lists are
  2996                     // Delete only the lists of the completed request. Triggering request lists are
  2896                     // deleted later on when that request is actually handled.
  2997                     // deleted later on when that request is actually handled.
  2897                     delete completedIdList;
  2998                     delete completedAvailabilityList;
  2898                     delete completedScanList; 
  2999                     delete completedScanList; 
  2899                     }
  3000                     }
  2900                 }
  3001                 }
  2901             delete completedScanTime;
  3002             delete completedScanTime;
  2902             break;
  3003             break;
  3024              ieLength <= KMaxSSIDLength )
  3125              ieLength <= KMaxSSIDLength )
  3025             {
  3126             {
  3026             TWlanAvailableNetwork network;
  3127             TWlanAvailableNetwork network;
  3027             network.ssid.Copy( ieData, ieLength );
  3128             network.ssid.Copy( ieData, ieLength );
  3028             network.securityMode = info.SecurityMode();
  3129             network.securityMode = info.SecurityMode();
       
  3130             network.rcpi = info.RXLevel();
  3029             if( info.OperatingMode() == WlanOperatingModeInfra )
  3131             if( info.OperatingMode() == WlanOperatingModeInfra )
  3030                 {
  3132                 {
  3031                 network.networkType = Infrastructure;                
  3133                 network.networkType = Infrastructure;                
  3032                 }
  3134                 }
  3033             else
  3135             else
  3034                 {
  3136                 {
  3035                 network.networkType = Adhoc;
  3137                 network.networkType = Adhoc;
  3036                 }
  3138                 }
  3037 
  3139 
  3038             if ( aNetworkList.Find( network, isEqual ) == KErrNotFound )
  3140             TInt idx = aNetworkList.Find( network, isEqual ); 
       
  3141             if ( idx == KErrNotFound )
  3039                 {
  3142                 {
  3040                 DEBUG1S( "CWlmServer::GetNetworkList() - appending SSID ",
  3143                 DEBUG1S( "CWlmServer::GetNetworkList() - appending SSID ",
  3041                     ieLength, ieData );
  3144                     ieLength, ieData );
  3042                 aNetworkList.Append( network );
  3145                 aNetworkList.Append( network );
       
  3146                 }
       
  3147             else if( idx >= 0 &&
       
  3148                      aNetworkList[idx].rcpi < network.rcpi )
       
  3149                 {
       
  3150                 aNetworkList[idx].rcpi = network.rcpi;            
  3043                 }
  3151                 }
  3044             }
  3152             }
  3045         }
  3153         }
  3046 
  3154 
  3047     return KErrNone;
  3155     return KErrNone;
  3431         }
  3539         }
  3432 
  3540 
  3433     iapList.Close();
  3541     iapList.Close();
  3434 
  3542 
  3435     // Create output list
  3543     // Create output list
  3436     core_type_list_c<u32_t>* iapIdList = new core_type_list_c<u32_t>;
  3544     core_type_list_c<core_iap_availability_data_s>* iapAvailabilityList =
  3437     if( iapIdList == NULL )
  3545         new core_type_list_c<core_iap_availability_data_s>;
       
  3546     if( iapAvailabilityList == NULL )
  3438         {
  3547         {
  3439         DEBUG( "ERROR: Out of memory" );
  3548         DEBUG( "ERROR: Out of memory" );
  3440         delete iapDataList;
  3549         delete iapDataList;
  3441         delete iapSsidList;
  3550         delete iapSsidList;
  3442         return KErrNoMemory;
  3551         return KErrNoMemory;
  3447     if( scanList == NULL )
  3556     if( scanList == NULL )
  3448         {
  3557         {
  3449         DEBUG( "CWlmServer::BackgroundScanRequest() - Out of memory when instantiating ScanList" );
  3558         DEBUG( "CWlmServer::BackgroundScanRequest() - Out of memory when instantiating ScanList" );
  3450         delete iapDataList;
  3559         delete iapDataList;
  3451         delete iapSsidList;
  3560         delete iapSsidList;
  3452         delete iapIdList;
  3561         delete iapAvailabilityList;
  3453         return KErrNoMemory;
  3562         return KErrNoMemory;
  3454         }
  3563         }
  3455 
  3564 
  3456     TUint* scanTime = new TUint(
  3565     TUint* scanTime = new TUint(
  3457         CalculateScanStartTime( aScanStartInterval ) );
  3566         CalculateScanStartTime( aScanStartInterval ) );
  3459         {
  3568         {
  3460         DEBUG( "CWlmServer::BackgroundScanRequest() - unable to instantiate TUint" );
  3569         DEBUG( "CWlmServer::BackgroundScanRequest() - unable to instantiate TUint" );
  3461 
  3570 
  3462         delete iapDataList;
  3571         delete iapDataList;
  3463         delete iapSsidList;
  3572         delete iapSsidList;
  3464         delete iapIdList;
  3573         delete iapAvailabilityList;
  3465         delete scanList;
  3574         delete scanList;
  3466         return KErrNoMemory;
  3575         return KErrNoMemory;
  3467         }
  3576         }
  3468     
  3577     
  3469     // create mapping
  3578     // create mapping
  3470     SRequestMapEntry mapEntry;
  3579     SRequestMapEntry mapEntry;
  3471     mapEntry.iFunction = EGetAvailableIaps;
  3580     mapEntry.iFunction = EGetAvailableIaps;
  3472     mapEntry.iRequestId = KWlanIntCmdBackgroundScan;
  3581     mapEntry.iRequestId = KWlanIntCmdBackgroundScan;
  3473     mapEntry.iSessionId = 0;
  3582     mapEntry.iSessionId = 0;
  3474     mapEntry.iParam0 = iapDataList;
  3583     mapEntry.iParam0 = iapDataList;
  3475     mapEntry.iParam1 = iapIdList;
  3584     mapEntry.iParam1 = iapAvailabilityList;
  3476     mapEntry.iParam2 = scanList;
  3585     mapEntry.iParam2 = scanList;
  3477     mapEntry.iParam3 = iapSsidList;
  3586     mapEntry.iParam3 = iapSsidList;
       
  3587     mapEntry.iParam4 = reinterpret_cast<TAny*>( EFalse );
  3478     mapEntry.iTime = scanTime;
  3588     mapEntry.iTime = scanTime;
  3479     iRequestMap.Append( mapEntry );
  3589     iRequestMap.Append( mapEntry );
  3480     
  3590 
  3481     if( IsOnlyTimedScanRequestInRequestMap( mapEntry ) || *scanTime < iScanSchedulingTimerExpiration )
  3591     if( IsOnlyTimedScanRequestInRequestMap( mapEntry ) || *scanTime < iScanSchedulingTimerExpiration )
  3482         {
  3592         {
  3483         // Scan scheduling timer needs to be set again because this request needs the results earlier
  3593         // Scan scheduling timer needs to be set again because this request needs the results earlier
  3484         UpdateScanSchedulingTimer( *scanTime, mapEntry.iRequestId );
  3594         UpdateScanSchedulingTimer( *scanTime, mapEntry.iRequestId );
  3485         }
  3595         }
  3545         pckgDynamicScanList().size = 0;
  3655         pckgDynamicScanList().size = 0;
  3546 
  3656 
  3547         if( self->IsSessionActive( self->iRequestMap[index] ) )
  3657         if( self->IsSessionActive( self->iRequestMap[index] ) )
  3548             {
  3658             {
  3549             self->iRequestMap[index].iMessage.Write( 2, pckgDynamicScanList );
  3659             self->iRequestMap[index].iMessage.Write( 2, pckgDynamicScanList );
  3550             self->iRequestMap[index].iMessage.Complete( KErrNone );
  3660 
       
  3661             if( self->iPlatform->GetWlanOnOffState() != EWlanOn )
       
  3662                 {
       
  3663                 self->iRequestMap[index].iMessage.Complete( self->iPlatform->GetWlanOnOffState() );
       
  3664                 }
       
  3665             else
       
  3666                 {
       
  3667                 self->iRequestMap[index].iMessage.Complete( KErrServerBusy );
       
  3668                 }
  3551             }
  3669             }
  3552 
  3670 
  3553         delete completedScanList;
  3671         delete completedScanList;
  3554         completedScanList = NULL;
  3672         completedScanList = NULL;
  3555         delete completedSsid;
  3673         delete completedSsid;
  3574          self->iRequestMap[index].iFunction == EGetAvailableIaps )
  3692          self->iRequestMap[index].iFunction == EGetAvailableIaps )
  3575         {
  3693         {
  3576         DEBUG( "CWlmServer::ScanSchedulingTimerExpired() - GetAvailableIaps" );
  3694         DEBUG( "CWlmServer::ScanSchedulingTimerExpired() - GetAvailableIaps" );
  3577             
  3695             
  3578         core_type_list_c<core_iap_data_s>* iapDataList = reinterpret_cast<core_type_list_c<core_iap_data_s>*>( self->iRequestMap[index].iParam0 );
  3696         core_type_list_c<core_iap_data_s>* iapDataList = reinterpret_cast<core_type_list_c<core_iap_data_s>*>( self->iRequestMap[index].iParam0 );
  3579         core_type_list_c<u32_t>* iapIdList =  reinterpret_cast<core_type_list_c<u32_t>*>( self->iRequestMap[index].iParam1 );
  3697         core_type_list_c<core_iap_availability_data_s>* iapAvailabilityList =
       
  3698             reinterpret_cast<core_type_list_c<core_iap_availability_data_s>*>( self->iRequestMap[index].iParam1 );
  3580         ScanList* scanList =  reinterpret_cast<ScanList*>( self->iRequestMap[index].iParam2 );
  3699         ScanList* scanList =  reinterpret_cast<ScanList*>( self->iRequestMap[index].iParam2 );
  3581         core_type_list_c<core_ssid_entry_s>* iapSsidList =  reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( self->iRequestMap[index].iParam3 );
  3700         core_type_list_c<core_ssid_entry_s>* iapSsidList =  reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( self->iRequestMap[index].iParam3 );
  3582         TUint* scanTime =  reinterpret_cast<TUint*>( self->iRequestMap[index].iTime );        
  3701         TUint* scanTime =  reinterpret_cast<TUint*>( self->iRequestMap[index].iTime );        
  3583 
  3702 
  3584         // If the device is roaming OR
  3703         // If the device is roaming OR
  3598             if( self->IsSessionActive( self->iRequestMap[index] ) )
  3717             if( self->IsSessionActive( self->iRequestMap[index] ) )
  3599                 {
  3718                 {
  3600                 TWlmAvailableIaps tmp = { 0 };
  3719                 TWlmAvailableIaps tmp = { 0 };
  3601                 TPckg<TWlmAvailableIaps> outPckg( tmp );
  3720                 TPckg<TWlmAvailableIaps> outPckg( tmp );
  3602                 self->iRequestMap[index].iMessage.Write( 0, outPckg );
  3721                 self->iRequestMap[index].iMessage.Write( 0, outPckg );
  3603                 self->iRequestMap[index].iMessage.Complete( KErrNone );
  3722 
       
  3723                 if( self->iPlatform->GetWlanOnOffState() != EWlanOn )
       
  3724                     {
       
  3725                     self->iRequestMap[index].iMessage.Complete( self->iPlatform->GetWlanOnOffState() );
       
  3726                     }
       
  3727                 else if( iapDataList->count() == 0 )
       
  3728                     {
       
  3729                     self->iRequestMap[index].iMessage.Complete( KErrNone );
       
  3730                     }
       
  3731                 else
       
  3732                     {
       
  3733                     self->iRequestMap[index].iMessage.Complete( KErrServerBusy );
       
  3734                     }
  3604                 }
  3735                 }
  3605 
  3736 
  3606             delete iapDataList;
  3737             delete iapDataList;
  3607             iapDataList = NULL;
  3738             iapDataList = NULL;
  3608             delete iapIdList;
  3739             delete iapAvailabilityList;
  3609             iapIdList = NULL;
  3740             iapAvailabilityList = NULL;
  3610             delete scanList;
  3741             delete scanList;
  3611             scanList = NULL;
  3742             scanList = NULL;
  3612             delete iapSsidList;
  3743             delete iapSsidList;
  3613             iapSsidList = NULL;
  3744             iapSsidList = NULL;
  3614             delete scanTime;
  3745             delete scanTime;
  3653         {
  3784         {
  3654         DEBUG( "CWlmServer::ScanSchedulingTimerExpired() - starting background scan, cancel timer" );
  3785         DEBUG( "CWlmServer::ScanSchedulingTimerExpired() - starting background scan, cancel timer" );
  3655         // pass request to core
  3786         // pass request to core
  3656         core_type_list_c<core_iap_data_s>* iapDataList = reinterpret_cast<core_type_list_c<core_iap_data_s>*>( self->iRequestMap[index].iParam0 );
  3787         core_type_list_c<core_iap_data_s>* iapDataList = reinterpret_cast<core_type_list_c<core_iap_data_s>*>( self->iRequestMap[index].iParam0 );
  3657         core_type_list_c<core_ssid_entry_s>* iapSsidList = reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( self->iRequestMap[index].iParam3 );
  3788         core_type_list_c<core_ssid_entry_s>* iapSsidList = reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( self->iRequestMap[index].iParam3 );
  3658         core_type_list_c<u32_t>* iapIdList = reinterpret_cast<core_type_list_c<u32_t>*>( self->iRequestMap[index].iParam1 );
  3789         core_type_list_c<core_iap_availability_data_s>* iapAvailabilityList =
       
  3790             reinterpret_cast<core_type_list_c<core_iap_availability_data_s>*>( self->iRequestMap[index].iParam1 );
  3659         ScanList* scanList = reinterpret_cast<ScanList*>( self->iRequestMap[index].iParam2 );
  3791         ScanList* scanList = reinterpret_cast<ScanList*>( self->iRequestMap[index].iParam2 );
  3660         
  3792         
  3661         self->iCoreServer->get_available_iaps(
  3793         self->iCoreServer->get_available_iaps(
  3662             self->iRequestMap[index].iRequestId,
  3794             self->iRequestMap[index].iRequestId,
  3663             isActiveScanAllowed,
  3795             isActiveScanAllowed,
  3664             *iapDataList,
  3796             *iapDataList,
  3665             *iapIdList,
  3797             *iapAvailabilityList,
  3666             iapSsidList,
  3798             iapSsidList,
  3667             *scanList );
  3799             *scanList );
  3668         
  3800         
  3669         self->iScanSchedulingTimer->Cancel();
  3801         self->iScanSchedulingTimer->Cancel();
  3670         }
  3802         }
  3692         DEBUG( "CWlmServer::ScanSchedulingTimerExpired() - starting GetAvailableIaps, cancel timer" );
  3824         DEBUG( "CWlmServer::ScanSchedulingTimerExpired() - starting GetAvailableIaps, cancel timer" );
  3693             
  3825             
  3694         // pass request to core
  3826         // pass request to core
  3695         core_type_list_c<core_iap_data_s>* iapDataList = reinterpret_cast<core_type_list_c<core_iap_data_s>*>( self->iRequestMap[index].iParam0 );
  3827         core_type_list_c<core_iap_data_s>* iapDataList = reinterpret_cast<core_type_list_c<core_iap_data_s>*>( self->iRequestMap[index].iParam0 );
  3696         core_type_list_c<core_ssid_entry_s>* iapSsidList = reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( self->iRequestMap[index].iParam3 );
  3828         core_type_list_c<core_ssid_entry_s>* iapSsidList = reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( self->iRequestMap[index].iParam3 );
  3697         core_type_list_c<u32_t>* iapIdList = reinterpret_cast<core_type_list_c<u32_t>*>( self->iRequestMap[index].iParam1 );
  3829         core_type_list_c<core_iap_availability_data_s>* iapAvailabilityList =
       
  3830             reinterpret_cast<core_type_list_c<core_iap_availability_data_s>*>( self->iRequestMap[index].iParam1 );
  3698         ScanList* scanList = reinterpret_cast<ScanList*>( self->iRequestMap[index].iParam2 );
  3831         ScanList* scanList = reinterpret_cast<ScanList*>( self->iRequestMap[index].iParam2 );
  3699         
  3832         
  3700         self->iCoreServer->get_available_iaps(
  3833         self->iCoreServer->get_available_iaps(
  3701             self->iRequestMap[index].iRequestId,
  3834             self->iRequestMap[index].iRequestId,
  3702             isActiveScanAllowed,
  3835             isActiveScanAllowed,
  3703             *iapDataList,
  3836             *iapDataList,
  3704             *iapIdList,
  3837             *iapAvailabilityList,
  3705             iapSsidList,
  3838             iapSsidList,
  3706             *scanList );
  3839             *scanList );
  3707         
  3840         
  3708         self->iScanSchedulingTimer->Cancel();
  3841         self->iScanSchedulingTimer->Cancel();
  3709         }
  3842         }
  4101             iScanSchedulingTimer->Cancel();
  4234             iScanSchedulingTimer->Cancel();
  4102 
  4235 
  4103             DEBUG( "CWlmServer::CancelScan() - remove entry from request map" );
  4236             DEBUG( "CWlmServer::CancelScan() - remove entry from request map" );
  4104             SRequestMapEntry entry = iRequestMap[index];
  4237             SRequestMapEntry entry = iRequestMap[index];
  4105             delete reinterpret_cast<core_type_list_c<core_iap_data_s>*>( entry.iParam0 );
  4238             delete reinterpret_cast<core_type_list_c<core_iap_data_s>*>( entry.iParam0 );
  4106             delete reinterpret_cast<core_type_list_c<u32_t>*>( entry.iParam1 );
  4239             delete reinterpret_cast<core_type_list_c<core_iap_availability_data_s>*>( entry.iParam1 );
  4107             delete reinterpret_cast<ScanList*>( entry.iParam2);
  4240             delete reinterpret_cast<ScanList*>( entry.iParam2);
  4108             delete reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( entry.iParam3 );
  4241             delete reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( entry.iParam3 );
  4109             delete reinterpret_cast<TUint*>( entry.iTime );
  4242             delete reinterpret_cast<TUint*>( entry.iTime );
  4110             iRequestMap.Remove( index );
  4243             iRequestMap.Remove( index );
  4111 
  4244 
  4138                 DEBUG( "CWlmServer::CancelScan() - just remove the entry from the request map" );
  4271                 DEBUG( "CWlmServer::CancelScan() - just remove the entry from the request map" );
  4139                 
  4272                 
  4140                 DEBUG( "CWlmServer::CancelScan() - remove entry from request map" );
  4273                 DEBUG( "CWlmServer::CancelScan() - remove entry from request map" );
  4141                 SRequestMapEntry entry = iRequestMap[index];
  4274                 SRequestMapEntry entry = iRequestMap[index];
  4142                 delete reinterpret_cast<core_type_list_c<core_iap_data_s>*>( entry.iParam0 );
  4275                 delete reinterpret_cast<core_type_list_c<core_iap_data_s>*>( entry.iParam0 );
  4143                 delete reinterpret_cast<core_type_list_c<u32_t>*>( entry.iParam1 );
  4276                 delete reinterpret_cast<core_type_list_c<core_iap_availability_data_s>*>( entry.iParam1 );
  4144                 delete reinterpret_cast<ScanList*>( entry.iParam2);
  4277                 delete reinterpret_cast<ScanList*>( entry.iParam2);
  4145                 delete reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( entry.iParam3 );
  4278                 delete reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( entry.iParam3 );
  4146                 delete reinterpret_cast<TUint*>( entry.iTime );                
  4279                 delete reinterpret_cast<TUint*>( entry.iTime );                
  4147                 iRequestMap.Remove( index );
  4280                 iRequestMap.Remove( index );
  4148                 }
  4281                 }
  5065     {   
  5198     {   
  5066     DEBUG( "CWlmServer::HandleSsidListAvailabilityL()" );
  5199     DEBUG( "CWlmServer::HandleSsidListAvailabilityL()" );
  5067 
  5200 
  5068     ScanList* scanList =
  5201     ScanList* scanList =
  5069         reinterpret_cast<ScanList*>( aMapEntry.iParam2 );
  5202         reinterpret_cast<ScanList*>( aMapEntry.iParam2 );
  5070     core_type_list_c<u32_t>* iapIdList = 
  5203     core_type_list_c<core_iap_availability_data_s>* iapAvailabilityList = 
  5071         reinterpret_cast<core_type_list_c<u32_t>*>( aMapEntry.iParam1 );
  5204         reinterpret_cast<core_type_list_c<core_iap_availability_data_s>*>( aMapEntry.iParam1 );
  5072 
  5205 
  5073     /**
  5206     /**
  5074      * Go through the IAP list and find IAPs that haven't been found
  5207      * Go through the IAP list and find IAPs that haven't been found
  5075      * during GetAvailableIaps and have an SSID list attached.  
  5208      * during GetAvailableIaps and have an SSID list attached.  
  5076      */
  5209      */
  5077     RArray<TWlanLimitedIapData> attachedIapList;
  5210     RArray<TWlanLimitedIapData> attachedIapList;
  5078     CleanupClosePushL( attachedIapList );
  5211     CleanupClosePushL( attachedIapList );
  5079     const RArray<TWlanLimitedIapData>& cachedIapList(
  5212     const RArray<TWlanLimitedIapData>& cachedIapList(
  5080         iCache->CachedIapDataList() );    
  5213         iCache->CachedIapDataList() );
  5081     core_type_list_iterator_c<u32_t> iter( *iapIdList );
  5214     core_type_list_iterator_c<core_iap_availability_data_s> iter( *iapAvailabilityList );    
  5082     for( TInt idx( 0 ); idx < cachedIapList.Count(); ++idx )
  5215     for( TInt idx( 0 ); idx < cachedIapList.Count(); ++idx )
  5083         {
  5216         {
  5084         TBool isFound( EFalse );
  5217         TBool isFound( EFalse );
  5085         for( u32_t* item = iter.first(); !isFound && item; item = iter.next() )
  5218         for( core_iap_availability_data_s* item = iter.first(); !isFound && item; item = iter.next() )
  5086             {
  5219             {
  5087             if( *item == cachedIapList[idx].iapId )
  5220             if( item->id == cachedIapList[idx].iapId )
  5088                 {                
  5221                 {                
  5089                 isFound = ETrue;
  5222                 isFound = ETrue;
  5090                 }
  5223                 }
  5091             }
  5224             }
  5092         if( !isFound )
  5225         if( !isFound )
  5129         CleanupStack::PushL( ssidList );
  5262         CleanupStack::PushL( ssidList );
  5130         iSsidListDb->ReadListL(
  5263         iSsidListDb->ReadListL(
  5131             attachedIapList[idx].iapId,
  5264             attachedIapList[idx].iapId,
  5132             *ssidList );
  5265             *ssidList );
  5133         TBool isMatch( EFalse );
  5266         TBool isMatch( EFalse );
       
  5267         TUint rcpi( 0 );
  5134         for( TInt iidx( 0 ); !isMatch && iidx < networkList.Count(); ++iidx )
  5268         for( TInt iidx( 0 ); !isMatch && iidx < networkList.Count(); ++iidx )
  5135             {
  5269             {
  5136             if( attachedIapList[idx].networkType == networkList[iidx].networkType &&
  5270             if( attachedIapList[idx].networkType == networkList[iidx].networkType &&
  5137                 ssidList->IsInList( networkList[iidx].ssid ) )
  5271                 ssidList->IsInList( networkList[iidx].ssid ) )
  5138                 {
  5272                 {
       
  5273                 rcpi = networkList[iidx].rcpi;
  5139                 isMatch = ETrue;
  5274                 isMatch = ETrue;
  5140                 }
  5275                 }
  5141             }
  5276             }
  5142 
  5277 
  5143         if( isMatch )
  5278         if( isMatch )
  5145             DEBUG( "CWlmServer::HandleSsidListAvailabilityL() - matching SSID found" );
  5280             DEBUG( "CWlmServer::HandleSsidListAvailabilityL() - matching SSID found" );
  5146                 
  5281                 
  5147             /**
  5282             /**
  5148              * A match has been found, mark the IAP as available.
  5283              * A match has been found, mark the IAP as available.
  5149              */
  5284              */
  5150             u32_t* iapId = new (ELeave) u32_t(
  5285             core_iap_availability_data_s* data = new (ELeave) core_iap_availability_data_s;
  5151                 attachedIapList[idx].iapId );
  5286             data->id = attachedIapList[idx].iapId;
  5152             iapIdList->append(
  5287             data->rcpi = rcpi;
  5153                 iapId );
  5288             core_error_e ret = iapAvailabilityList->append(
       
  5289                 data );
       
  5290             if( ret != core_error_ok )
       
  5291                 {
       
  5292                 delete data;
       
  5293                 }
       
  5294             data = NULL;
  5154             }
  5295             }
  5155         else
  5296         else
  5156             {
  5297             {
  5157             DEBUG( "CWlmServer::HandleSsidListAvailabilityL() - no matching SSIDs found for IAP" );
  5298             DEBUG( "CWlmServer::HandleSsidListAvailabilityL() - no matching SSIDs found for IAP" );
  5158             }
  5299             }