wlan_bearer/wlanengine/wlan_symbian/wlanengine_symbian_3.1/src/wlmserver.cpp
changeset 22 c6a1762761b8
parent 19 629e60dfa279
child 36 1c425781161e
equal deleted inserted replaced
19:629e60dfa279 22:c6a1762761b8
    14 * Description:  Server class of wlan engine
    14 * Description:  Server class of wlan engine
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 /*
    18 /*
    19 * %version: 106 %
    19 * %version: 108 %
    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>
    25 #include <in_sock.h>
    25 #include <in_sock.h>
    26 #include <bldvariant.hrh> // for feature definitions
    26 #include <bldvariant.hrh> // for feature definitions
       
    27 #include <hal.h>
    27 
    28 
    28 #include "wlmserver.h"
    29 #include "wlmserver.h"
    29 #include "wlmdriverif.h"
    30 #include "wlmdriverif.h"
    30 #include "wlmsession.h"
    31 #include "wlmsession.h"
    31 #include "wlanconversionutil.h"
    32 #include "wlanconversionutil.h"
    36 #include "wlangenericplugin.h"
    37 #include "wlangenericplugin.h"
    37 #include "wlanssidlistdb.h"
    38 #include "wlanssidlistdb.h"
    38 #include "wlandevicesettingsinternalcrkeys.h"
    39 #include "wlandevicesettingsinternalcrkeys.h"
    39 #include "wlanbgscan.h"
    40 #include "wlanbgscan.h"
    40 #include "wlantimerservices.h"
    41 #include "wlantimerservices.h"
       
    42 #include "wlanticktimer.h"
    41 #include "am_debug.h"
    43 #include "am_debug.h"
    42 
    44 
    43 /** Panic codes for WlanEngine */
    45 /** Panic codes for WlanEngine */
    44 const TInt KWlmPanicCleanupStackCreationFailed  = 1;
    46 const TInt KWlmPanicCleanupStackCreationFailed  = 1;
    45 const TInt KWlmPanicOpenSemaforeFailed          = 2;
    47 const TInt KWlmPanicOpenSemaforeFailed          = 2;
    86 
    88 
    87 /** Bitmask of WLAN features enabled at compile-time. */
    89 /** Bitmask of WLAN features enabled at compile-time. */
    88 const TUint KWlanStaticFeatures =
    90 const TUint KWlanStaticFeatures =
    89     CWlmServer::EWlanStaticFeature802dot11k |
    91     CWlmServer::EWlanStaticFeature802dot11k |
    90     CWlmServer::EWlanStaticFeature802dot11n;
    92     CWlmServer::EWlanStaticFeature802dot11n;
    91 
       
    92 /** Multiplier for converting seconds into microseconds */
       
    93 const TUint KWlanSecsToMicrosecsMultiplier( 1000000 );
       
    94 
    93 
    95 /** Minimum value for aggressive background scan interval, in seconds */
    94 /** Minimum value for aggressive background scan interval, in seconds */
    96 const TUint KWlanAggressiveBgScanMinInterval( 1 );
    95 const TUint KWlanAggressiveBgScanMinInterval( 1 );
    97 
    96 
    98 /** Maximum value for aggressive background scan interval, in seconds */
    97 /** Maximum value for aggressive background scan interval, in seconds */
   139     iCoreAsynchCbId( 0 ),
   138     iCoreAsynchCbId( 0 ),
   140     iCoreAsynchCbStatus( core_error_ok ),
   139     iCoreAsynchCbStatus( core_error_ok ),
   141     iIsStartupComplete( EFalse ),
   140     iIsStartupComplete( EFalse ),
   142     iEapolClient( NULL ),
   141     iEapolClient( NULL ),
   143     iEapolHandler( NULL ),
   142     iEapolHandler( NULL ),
       
   143     iSystemTickPeriod( 0 ),
   144     iScanSchedulingTimerExpiration( 0 ),
   144     iScanSchedulingTimerExpiration( 0 ),
   145     iRequestTriggeringScanning( 0 ),
   145     iRequestTriggeringScanning( 0 ),
   146     iCoreHandlingScanRequest( EFalse ),
   146     iCoreHandlingScanRequest( EFalse ),
   147     iPowerSaveMode( EWlanPowerSaveAutomatic ),
   147     iPowerSaveMode( EWlanPowerSaveAutomatic ),
   148     iPowerSaveEnabled( EFalse ),
   148     iPowerSaveEnabled( EFalse ),
   161 void CWlmServer::ConstructL()
   161 void CWlmServer::ConstructL()
   162     {
   162     {
   163     DEBUG( "CWlmServer::ConstructL()" );
   163     DEBUG( "CWlmServer::ConstructL()" );
   164     User::LeaveIfError( User::RenameThread( KWLMDataServerName ) );
   164     User::LeaveIfError( User::RenameThread( KWLMDataServerName ) );
   165     StartL( KWLMDataServerName );    
   165     StartL( KWLMDataServerName );    
       
   166 
       
   167     HAL::Get( HAL::ESystemTickPeriod, iSystemTickPeriod );
       
   168     DEBUG1( "CWlmServer::ConstructL() - system tick period is %d",
       
   169         iSystemTickPeriod );
       
   170     DEBUG1( "CWlmServer::ConstructL() - current system tick count is %u",
       
   171         User::TickCount( ) );
   166 
   172 
   167     // Consult FeatureManager whether startup is allowed
   173     // Consult FeatureManager whether startup is allowed
   168     FeatureManager::InitializeLibL();
   174     FeatureManager::InitializeLibL();
   169     if( !FeatureManager::FeatureSupported( KFeatureIdProtocolWlan ) )
   175     if( !FeatureManager::FeatureSupported( KFeatureIdProtocolWlan ) )
   170         {
   176         {
   218             deviceSettings.enabledFeatures ) ) );
   224             deviceSettings.enabledFeatures ) ) );
   219     iCoreServer->disable_wlan( KWlanIntCmdDisableWlan );
   225     iCoreServer->disable_wlan( KWlanIntCmdDisableWlan );
   220 
   226 
   221     // Create scan timer
   227     // Create scan timer
   222     DEBUG( "CWlmServer::ConstructL() - create backgroundscan timer" );
   228     DEBUG( "CWlmServer::ConstructL() - create backgroundscan timer" );
   223     iScanSchedulingTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   229     TCallBack expiredCb( ScanSchedulingTimerExpired, this );
       
   230     TCallBack canceledCb( ScanSchedulingTimerCanceled, this );
       
   231     TCallBack emptyCb( EmptyCb, NULL );
       
   232     iScanSchedulingTimer = CWlanTickTimer::NewL(
       
   233         expiredCb,
       
   234         canceledCb,
       
   235         emptyCb );
   224 
   236 
   225     // Create scan cache
   237     // Create scan cache
   226     iCache = CWlanScanResultCache::NewL();
   238     iCache = CWlanScanResultCache::NewL();
   227     iConfiguredCacheLifetime = deviceSettings.scanExpirationTimer;
   239     iConfiguredCacheLifetime = deviceSettings.scanExpirationTimer;
   228 
   240 
   467     // Check that WLAN is ON
   479     // Check that WLAN is ON
   468     TWlanOnOffState wlanState( iPlatform->GetWlanOnOffState() );
   480     TWlanOnOffState wlanState( iPlatform->GetWlanOnOffState() );
   469 	if( wlanState != EWlanOn )
   481 	if( wlanState != EWlanOn )
   470 	    {
   482 	    {
   471 		// WLAN is OFF
   483 		// WLAN is OFF
   472 		DEBUG1( "CWlmServer::Connect() refused due to WLAN is OFF (%d)",
   484 		DEBUG1( "CWlmServer::Connect() - refused due to WLAN is OFF (%d)",
   473 		    wlanState );
   485 		    wlanState );
   474 		// WLAN state enumerations map one to one to WLAN error code
   486 		// WLAN state enumerations map one to one to WLAN error code
   475 		aMessage.Complete( wlanState );
   487 		aMessage.Complete( wlanState );
   476 		
   488 		
   477 		return;
   489 		return;
  1098         aMessage.Complete( KErrNoMemory );
  1110         aMessage.Complete( KErrNoMemory );
  1099 
  1111 
  1100         return;
  1112         return;
  1101         }    
  1113         }    
  1102 
  1114 
  1103     TTime* scanTime( NULL );
  1115     TUint* scanTime( NULL );
  1104     if( scanScheduling.maxDelay != KWlmInfiniteScanDelay )
  1116     if( scanScheduling.maxDelay != KWlmInfiniteScanDelay )
  1105         {
  1117         {
  1106         scanTime = new TTime(
  1118         scanTime = new TUint(
  1107             CalculateScanStartTime( scanScheduling.maxDelay ).Int64() );
  1119             CalculateScanStartTime( scanScheduling.maxDelay ) );
  1108         if( !scanTime )
  1120         if( !scanTime )
  1109             {
  1121             {
  1110             DEBUG( "CWlmServer::GetScanResult() - unable to instantiate TTime" );
  1122             DEBUG( "CWlmServer::GetScanResult() - unable to instantiate TUint" );
  1111     
  1123 
  1112             delete coreSsid;
  1124             delete coreSsid;
  1113             delete scanList;
  1125             delete scanList;
  1114             aMessage.Complete( KErrNoMemory );
  1126             aMessage.Complete( KErrNoMemory );
  1115     
  1127     
  1116             return;
  1128             return;
  1336         delete iapSsidList;
  1348         delete iapSsidList;
  1337         delete iapIdList;
  1349         delete iapIdList;
  1338         return;
  1350         return;
  1339         }
  1351         }
  1340 
  1352 
  1341     TTime* scanTime( NULL );
  1353     TUint* scanTime( NULL );
  1342     if( maxDelayPckg() != KWlmInfiniteScanDelay )
  1354     if( maxDelayPckg() != KWlmInfiniteScanDelay )
  1343         {
  1355         {
  1344         scanTime = new TTime(
  1356         scanTime = new TUint(
  1345             CalculateScanStartTime( maxDelayPckg() ).Int64() );
  1357             CalculateScanStartTime( maxDelayPckg() ) );
  1346         if( !scanTime )
  1358         if( !scanTime )
  1347             {
  1359             {
  1348             DEBUG( "CWlmServer::GetAvailableIaps() - unable to instantiate TTime" );
  1360             DEBUG( "CWlmServer::GetAvailableIaps() - unable to instantiate TUint" );
  1349     
  1361     
  1350             aMessage.Complete( KErrNoMemory );
  1362             aMessage.Complete( KErrNoMemory );
  1351             delete iapDataList;
  1363             delete iapDataList;
  1352             delete iapSsidList;
  1364             delete iapSsidList;
  1353             delete iapIdList;
  1365             delete iapIdList;
  1553 // ---------------------------------------------------------
  1565 // ---------------------------------------------------------
  1554 // CWlmServer::UpdateScanSchedulingTimer
  1566 // CWlmServer::UpdateScanSchedulingTimer
  1555 // ---------------------------------------------------------
  1567 // ---------------------------------------------------------
  1556 //
  1568 //
  1557 void CWlmServer::UpdateScanSchedulingTimer( 
  1569 void CWlmServer::UpdateScanSchedulingTimer( 
  1558 	TTime aScanTime, 
  1570     TUint aScanTime, 
  1559 	TUint aTriggeringRequestId )
  1571 	TUint aTriggeringRequestId )
  1560     {
  1572     {
  1561     DEBUG1( "CWlmServer::UpdateScanSchedulingTimer() - aTriggeringRequestId = %u ", aTriggeringRequestId );
  1573     DEBUG1( "CWlmServer::UpdateScanSchedulingTimer() - aTriggeringRequestId = %u ", aTriggeringRequestId );
  1562 
  1574 
  1563     if( iCoreHandlingScanRequest )
  1575     if( iCoreHandlingScanRequest )
  1566 		DEBUG( "CWlmServer::UpdateScanSchedulingTimer() - core is currently handling scanning, do not set the timer" );
  1578 		DEBUG( "CWlmServer::UpdateScanSchedulingTimer() - core is currently handling scanning, do not set the timer" );
  1567 
  1579 
  1568         return;
  1580         return;
  1569         }
  1581         }
  1570 
  1582 
  1571     TTime timeNow;
  1583     TUint currentTickCount(
  1572     timeNow.UniversalTime();
  1584         User::TickCount() );
  1573 
  1585     TUint difference( 0 );
  1574     TTimeIntervalMicroSeconds difference( aScanTime.MicroSecondsFrom( timeNow ) );
  1586     if( aScanTime > currentTickCount )
  1575     if( difference.Int64() < 0 )
  1587         {
  1576         {
  1588         difference = aScanTime - currentTickCount;  
  1577         difference = TTimeIntervalMicroSeconds( 0 );
  1589         }
  1578         }
       
  1579     TTimeIntervalMicroSeconds32 differenceMicroseconds(
       
  1580         difference.Int64() );
       
  1581 
  1590 
  1582     iScanSchedulingTimer->Cancel();
  1591     iScanSchedulingTimer->Cancel();
  1583     iScanSchedulingTimerExpiration = aScanTime;
  1592     iScanSchedulingTimerExpiration = aScanTime;
  1584     iRequestTriggeringScanning = aTriggeringRequestId;
  1593     iRequestTriggeringScanning = aTriggeringRequestId;
  1585     TCallBack callback( ScanSchedulingTimerExpired, this );
  1594     
  1586 
  1595     DEBUG2( "CWlmServer::UpdateScanSchedulingTimer() - scheduling the timer to %u system ticks(s) [%u s]",
  1587 	DEBUG1( "CWlmServer::UpdateScanSchedulingTimer() - scheduling the timer to %u second(s)",
  1596         difference, difference * iSystemTickPeriod / KWlanSecsToMicrosecsMultiplier );
  1588 	    differenceMicroseconds.Int() / SECONDS_FROM_MICROSECONDS );
  1597 
  1589 	
  1598     iScanSchedulingTimer->After( difference );
  1590 	TTimeIntervalMicroSeconds32 intervalMicroseconds( KWlmMaxScanDelay * SECONDS_FROM_MICROSECONDS );
       
  1591 
       
  1592     iScanSchedulingTimer->Start(
       
  1593             differenceMicroseconds,
       
  1594             intervalMicroseconds,
       
  1595             callback );
       
  1596     
       
  1597     }
  1599     }
  1598 
  1600 
  1599 // ---------------------------------------------------------
  1601 // ---------------------------------------------------------
  1600 // CWlmServer::FindNextTimedScanSchedulingRequest
  1602 // CWlmServer::FindNextTimedScanSchedulingRequest
  1601 // ---------------------------------------------------------
  1603 // ---------------------------------------------------------
  1604 	TUint& aTriggeringRequestIndex )
  1606 	TUint& aTriggeringRequestIndex )
  1605     {
  1607     {
  1606     DEBUG( "CWlmServer::FindNextTimedScanSchedulingRequest()" );
  1608     DEBUG( "CWlmServer::FindNextTimedScanSchedulingRequest()" );
  1607     
  1609     
  1608     TBool pendingScanRequestsFound( EFalse );
  1610     TBool pendingScanRequestsFound( EFalse );
  1609     TTime closestTime = TTime( 0 );
  1611     TUint closestTime( 0 );
  1610     aTriggeringRequestIndex = 0;
  1612     aTriggeringRequestIndex = 0;
  1611     
  1613     
  1612     for(TInt i=0; i < iRequestMap.Count(); i++)
  1614     for(TInt i=0; i < iRequestMap.Count(); i++)
  1613         {
  1615         {
  1614         if( IsPendingTimedScanRequest( i ) )
  1616         if( IsPendingTimedScanRequest( i ) )
  1615             {
  1617             {
  1616             TTime* checkedTime = reinterpret_cast<TTime*>( iRequestMap[i].iTime );
  1618             TUint* checkedTime = reinterpret_cast<TUint*>( iRequestMap[i].iTime );
  1617             if( pendingScanRequestsFound == EFalse || closestTime > *checkedTime )
  1619             if( pendingScanRequestsFound == EFalse || closestTime > *checkedTime )
  1618                 {
  1620                 {
  1619                 closestTime = *checkedTime;
  1621                 closestTime = *checkedTime;
  1620                 aTriggeringRequestIndex = i;
  1622                 aTriggeringRequestIndex = i;
  1621                 pendingScanRequestsFound = ETrue;
  1623                 pendingScanRequestsFound = ETrue;
  1625     
  1627     
  1626     if( pendingScanRequestsFound == EFalse )
  1628     if( pendingScanRequestsFound == EFalse )
  1627         {
  1629         {
  1628         // clear the scan scheduling related variables
  1630         // clear the scan scheduling related variables
  1629         iRequestTriggeringScanning = KWlanIntCmdNull;
  1631         iRequestTriggeringScanning = KWlanIntCmdNull;
  1630         iScanSchedulingTimerExpiration = TTime( 0 );
  1632         iScanSchedulingTimerExpiration = 0;
  1631         }
  1633         }
  1632     else
  1634     else
  1633         {
  1635         {
  1634         DEBUG1( "CWlmServer::FindNextTimedScanSchedulingRequest() - RequestIndex %u ", aTriggeringRequestIndex );
  1636         DEBUG1( "CWlmServer::FindNextTimedScanSchedulingRequest() - RequestIndex %u ", aTriggeringRequestIndex );
  1635         }
  1637         }
  1828                         }
  1830                         }
  1829                     
  1831                     
  1830 					// If WLAN is ON, enable background scanning
  1832 					// If WLAN is ON, enable background scanning
  1831 					if( iPlatform->GetWlanOnOffState() == EWlanOn )
  1833 					if( iPlatform->GetWlanOnOffState() == EWlanOn )
  1832 					    {
  1834 					    {
  1833                         iBgScanProvider->WlanSetBgScanState( MWlanBgScanProvider::EWlanBgScanOn );
  1835                         iBgScanProvider->SetBgScanState( MWlanBgScanProvider::EWlanBgScanOn );
  1834                         }
  1836                         }
  1835                     
  1837                     
  1836                     break;
  1838                     break;
  1837                 case EWlanStateInfrastructure:
  1839                 case EWlanStateInfrastructure:
  1838                     DEBUG( "CWlmServer::notify() - STATE: EWlanStateInfrastructure" );
  1840                     DEBUG( "CWlmServer::notify() - STATE: EWlanStateInfrastructure" );
  2338                 
  2340                 
  2339                 // Inform BgScan provider about successful connection.
  2341                 // Inform BgScan provider about successful connection.
  2340                 // If background scan is currently on, background scan
  2342                 // If background scan is currently on, background scan
  2341                 // will be disabled and it's request will be removed
  2343                 // will be disabled and it's request will be removed
  2342                 // from the request map.
  2344                 // from the request map.
  2343                 iBgScanProvider->WlanSetBgScanState( MWlanBgScanProvider::EWlanBgScanOff );
  2345                 iBgScanProvider->SetBgScanState( MWlanBgScanProvider::EWlanBgScanOff );
  2344                 
  2346                 
  2345                 }
  2347                 }
  2346             }
  2348             }
  2347         else if ( IsSessionActive( completedMapEntry ) )
  2349         else if ( IsSessionActive( completedMapEntry ) )
  2348             {
  2350             {
  2456     	{
  2458     	{
  2457         iCoreHandlingScanRequest = EFalse;
  2459         iCoreHandlingScanRequest = EFalse;
  2458 
  2460 
  2459     	if( FindNextTimedScanSchedulingRequest( indexNextScan ) )
  2461     	if( FindNextTimedScanSchedulingRequest( indexNextScan ) )
  2460             {
  2462             {
  2461             TTime* nextScanTime = reinterpret_cast<TTime*>( iRequestMap[indexNextScan].iTime );
  2463             TUint* nextScanTime = reinterpret_cast<TUint*>( iRequestMap[indexNextScan].iTime );
  2462             UpdateScanSchedulingTimer( *nextScanTime, iRequestMap[indexNextScan].iRequestId );
  2464             UpdateScanSchedulingTimer( *nextScanTime, iRequestMap[indexNextScan].iRequestId );
  2463             }
  2465             }
  2464         }
  2466         }
  2465 
  2467 
  2466 #ifdef _DEBUG
  2468 #ifdef _DEBUG
  2626             core_type_list_c<core_iap_data_s>* iapDataList =
  2628             core_type_list_c<core_iap_data_s>* iapDataList =
  2627                 reinterpret_cast<core_type_list_c<core_iap_data_s>*>( aRequest.iParam0 );
  2629                 reinterpret_cast<core_type_list_c<core_iap_data_s>*>( aRequest.iParam0 );
  2628             delete iapDataList;
  2630             delete iapDataList;
  2629             iapDataList = NULL;
  2631             iapDataList = NULL;
  2630             
  2632             
  2631             TTime* completedScanTime = reinterpret_cast<TTime*>( aRequest.iTime );
  2633             TUint* completedScanTime = reinterpret_cast<TUint*>( aRequest.iTime );
  2632             delete completedScanTime;
  2634             delete completedScanTime;
  2633             completedScanTime = NULL;
  2635             completedScanTime = NULL;
  2634 
  2636 
  2635             if( aCompletedWasTriggering )
  2637             if( aCompletedWasTriggering )
  2636                 {
  2638                 {
  2691         {
  2693         {
  2692         case EGetScanResults:
  2694         case EGetScanResults:
  2693             {
  2695             {
  2694             ScanList* tmp( NULL );
  2696             ScanList* tmp( NULL );
  2695             core_ssid_s* ssid = reinterpret_cast<core_ssid_s*>( aRequest.iParam1 );
  2697             core_ssid_s* ssid = reinterpret_cast<core_ssid_s*>( aRequest.iParam1 );
  2696             TTime* completedScanTime = reinterpret_cast<TTime*>( aRequest.iTime );
  2698             TUint* completedScanTime = reinterpret_cast<TUint*>( aRequest.iTime );
  2697             ScanList* completedScanList = reinterpret_cast<ScanList*>( aRequest.iParam0 );
  2699             ScanList* completedScanList = reinterpret_cast<ScanList*>( aRequest.iParam0 );
  2698 
  2700 
  2699             if( aTriggerRequest == NULL )
  2701             if( aTriggerRequest == NULL )
  2700                 {
  2702                 {
  2701                 DEBUG( "CWlmServer::CompleteExternalRequest() - GetScanResults request handled by core" );    
  2703                 DEBUG( "CWlmServer::CompleteExternalRequest() - GetScanResults request handled by core" );    
  2791             core_type_list_c<core_iap_data_s>* iapDataList;
  2793             core_type_list_c<core_iap_data_s>* iapDataList;
  2792 
  2794 
  2793             iapSsidList = reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( aRequest.iParam3 );
  2795             iapSsidList = reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( aRequest.iParam3 );
  2794             iapDataList = reinterpret_cast<core_type_list_c<core_iap_data_s>*>( aRequest.iParam0 );
  2796             iapDataList = reinterpret_cast<core_type_list_c<core_iap_data_s>*>( aRequest.iParam0 );
  2795             
  2797             
  2796             TTime* completedScanTime = reinterpret_cast<TTime*>( aRequest.iTime );
  2798             TUint* completedScanTime = reinterpret_cast<TUint*>( aRequest.iTime );
  2797             ScanList* completedScanList = reinterpret_cast<ScanList*>( aRequest.iParam2);
  2799             ScanList* completedScanList = reinterpret_cast<ScanList*>( aRequest.iParam2);
  2798             core_type_list_c<u32_t>* completedIdList = reinterpret_cast<core_type_list_c<u32_t>*>( aRequest.iParam1 );
  2800             core_type_list_c<u32_t>* completedIdList = reinterpret_cast<core_type_list_c<u32_t>*>( aRequest.iParam1 );
  2799             
  2801             
  2800             if( aTriggerRequest == NULL )
  2802             if( aTriggerRequest == NULL )
  2801                 {
  2803                 {
  3449         delete iapSsidList;
  3451         delete iapSsidList;
  3450         delete iapIdList;
  3452         delete iapIdList;
  3451         return KErrNoMemory;
  3453         return KErrNoMemory;
  3452         }
  3454         }
  3453 
  3455 
  3454     TTime* scanTime = new TTime(
  3456     TUint* scanTime = new TUint(
  3455         CalculateScanStartTime( aScanStartInterval ).Int64() );
  3457         CalculateScanStartTime( aScanStartInterval ) );
  3456     if( !scanTime )
  3458     if( !scanTime )
  3457         {
  3459         {
  3458         DEBUG( "CWlmServer::BackgroundScanRequest() - unable to instantiate TTime" );
  3460         DEBUG( "CWlmServer::BackgroundScanRequest() - unable to instantiate TUint" );
  3459 
  3461 
  3460         delete iapDataList;
  3462         delete iapDataList;
  3461         delete iapSsidList;
  3463         delete iapSsidList;
  3462         delete iapIdList;
  3464         delete iapIdList;
  3463         delete scanList;
  3465         delete scanList;
  3530             self->IsRoaming(),
  3532             self->IsRoaming(),
  3531             self->iPlatform->GetWlanOnOffState() );
  3533             self->iPlatform->GetWlanOnOffState() );
  3532 
  3534 
  3533         ScanList* completedScanList = reinterpret_cast<ScanList*>( self->iRequestMap[index].iParam0 );
  3535         ScanList* completedScanList = reinterpret_cast<ScanList*>( self->iRequestMap[index].iParam0 );
  3534         core_ssid_s* completedSsid =  reinterpret_cast<core_ssid_s*>( self->iRequestMap[index].iParam1 );
  3536         core_ssid_s* completedSsid =  reinterpret_cast<core_ssid_s*>( self->iRequestMap[index].iParam1 );
  3535         TTime* completedScanTime = reinterpret_cast<TTime*>( self->iRequestMap[index].iTime );
  3537         TUint* completedScanTime = reinterpret_cast<TUint*>( self->iRequestMap[index].iTime );
  3536         
  3538         
  3537         // Only the triggering request is completed and then scan scheduling timer is set again 
  3539         // Only the triggering request is completed and then scan scheduling timer is set again 
  3538         TPckgBuf<TUint32> pckgCount( 0 );
  3540         TPckgBuf<TUint32> pckgCount( 0 );
  3539         TPckgBuf<TUint32> pckgSize( 0 );
  3541         TPckgBuf<TUint32> pckgSize( 0 );
  3540         
  3542         
  3557         
  3559         
  3558         self->iRequestMap.Remove( index );
  3560         self->iRequestMap.Remove( index );
  3559 
  3561 
  3560         if( self->FindNextTimedScanSchedulingRequest( indexNextScan ) )
  3562         if( self->FindNextTimedScanSchedulingRequest( indexNextScan ) )
  3561             {
  3563             {
  3562             TTime* nextScanTime = reinterpret_cast<TTime*>( self->iRequestMap[indexNextScan].iTime );
  3564             TUint* nextScanTime = reinterpret_cast<TUint*>( self->iRequestMap[indexNextScan].iTime );
  3563         	self->UpdateScanSchedulingTimer( *nextScanTime, self->iRequestMap[indexNextScan].iRequestId );
  3565         	self->UpdateScanSchedulingTimer( *nextScanTime, self->iRequestMap[indexNextScan].iRequestId );
  3564             }
  3566             }
  3565         
  3567         
  3566         DEBUG( "CWlmServer::ScanSchedulingTimerExpired() - message completed with empty scan results" );
  3568         DEBUG( "CWlmServer::ScanSchedulingTimerExpired() - message completed with empty scan results" );
  3567         return KErrNone;        
  3569         return KErrNone;        
  3575             
  3577             
  3576         core_type_list_c<core_iap_data_s>* iapDataList = reinterpret_cast<core_type_list_c<core_iap_data_s>*>( self->iRequestMap[index].iParam0 );
  3578         core_type_list_c<core_iap_data_s>* iapDataList = reinterpret_cast<core_type_list_c<core_iap_data_s>*>( self->iRequestMap[index].iParam0 );
  3577         core_type_list_c<u32_t>* iapIdList =  reinterpret_cast<core_type_list_c<u32_t>*>( self->iRequestMap[index].iParam1 );
  3579         core_type_list_c<u32_t>* iapIdList =  reinterpret_cast<core_type_list_c<u32_t>*>( self->iRequestMap[index].iParam1 );
  3578         ScanList* scanList =  reinterpret_cast<ScanList*>( self->iRequestMap[index].iParam2 );
  3580         ScanList* scanList =  reinterpret_cast<ScanList*>( self->iRequestMap[index].iParam2 );
  3579         core_type_list_c<core_ssid_entry_s>* iapSsidList =  reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( self->iRequestMap[index].iParam3 );
  3581         core_type_list_c<core_ssid_entry_s>* iapSsidList =  reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( self->iRequestMap[index].iParam3 );
  3580         TTime* scanTime =  reinterpret_cast<TTime*>( self->iRequestMap[index].iTime );        
  3582         TUint* scanTime =  reinterpret_cast<TUint*>( self->iRequestMap[index].iTime );        
  3581 
  3583 
  3582         // If the device is roaming OR
  3584         // If the device is roaming OR
  3583         // there are not WLAN IAPs defined in the device OR
  3585         // there are not WLAN IAPs defined in the device OR
  3584         // WLAN is OFF
  3586         // WLAN is OFF
  3585         // --> return empty list
  3587         // --> return empty list
  3614         
  3616         
  3615             self->iRequestMap.Remove( index );
  3617             self->iRequestMap.Remove( index );
  3616 
  3618 
  3617             if( self->FindNextTimedScanSchedulingRequest( indexNextScan ) )
  3619             if( self->FindNextTimedScanSchedulingRequest( indexNextScan ) )
  3618                 {
  3620                 {
  3619                 TTime* nextScanTime = reinterpret_cast<TTime*>( self->iRequestMap[indexNextScan].iTime );
  3621                 TUint* nextScanTime = reinterpret_cast<TUint*>( self->iRequestMap[indexNextScan].iTime );
  3620                 self->UpdateScanSchedulingTimer( *nextScanTime, self->iRequestMap[indexNextScan].iRequestId );
  3622                 self->UpdateScanSchedulingTimer( *nextScanTime, self->iRequestMap[indexNextScan].iRequestId );
  3621                 }
  3623                 }
  3622         
  3624         
  3623             DEBUG( "CWlmServer::ScanSchedulingTimerExpired() - message completed with empty iap list" );
  3625             DEBUG( "CWlmServer::ScanSchedulingTimerExpired() - message completed with empty iap list" );
  3624             return KErrNone;        
  3626             return KErrNone;        
  3705         
  3707         
  3706         self->iScanSchedulingTimer->Cancel();
  3708         self->iScanSchedulingTimer->Cancel();
  3707         }
  3709         }
  3708     self->iCoreHandlingScanRequest = ETrue;
  3710     self->iCoreHandlingScanRequest = ETrue;
  3709     return KErrNone;
  3711     return KErrNone;
  3710     }
  3712    }
       
  3713 
       
  3714 // ---------------------------------------------------------
       
  3715 // CWlmServer::ScanSchedulingTimerCanceled()
       
  3716 // ---------------------------------------------------------
       
  3717 //
       
  3718 TInt CWlmServer::ScanSchedulingTimerCanceled(
       
  3719     TAny* aThisPtr )
       
  3720     {
       
  3721     DEBUG( "CWlmServer::ScanSchedulingTimerCanceled()" );
       
  3722 
       
  3723     CWlmServer* self = reinterpret_cast<CWlmServer*>( aThisPtr );
       
  3724 
       
  3725     /**
       
  3726      * Scan scheduling timer was canceled, re-arm the timer. 
       
  3727      */
       
  3728     TUint indexNextScan( 0 );
       
  3729     if( self->FindNextTimedScanSchedulingRequest( indexNextScan ) )
       
  3730         {
       
  3731         self->UpdateScanSchedulingTimer(
       
  3732             *(self->iRequestMap[indexNextScan].iTime),
       
  3733             self->iRequestMap[indexNextScan].iRequestId );
       
  3734         }
       
  3735 
       
  3736     return 0;
       
  3737     }
       
  3738 
       
  3739 // ---------------------------------------------------------
       
  3740 // CWlmServer::EmptyCb()
       
  3741 // ---------------------------------------------------------
       
  3742 //
       
  3743 TInt CWlmServer::EmptyCb(
       
  3744     TAny* /* aThisPtr */ )
       
  3745     {
       
  3746     return 0;
       
  3747     }
       
  3748 
  3711     
  3749     
  3712 // ---------------------------------------------------------
  3750 // ---------------------------------------------------------
  3713 // CWlmServer::GetIapDataList()
  3751 // CWlmServer::GetIapDataList()
  3714 // ---------------------------------------------------------
  3752 // ---------------------------------------------------------
  3715 //
  3753 //
  3921     	
  3959     	
  3922         DEBUG("CWlmServer::SystemTimeChanged() - inform timer services about system time change");
  3960         DEBUG("CWlmServer::SystemTimeChanged() - inform timer services about system time change");
  3923     	iTimerServices->HandleTimeout();
  3961     	iTimerServices->HandleTimeout();
  3924         DEBUG("CWlmServer::SystemTimeChanged() - refreshing settings to BgScan provider");
  3962         DEBUG("CWlmServer::SystemTimeChanged() - refreshing settings to BgScan provider");
  3925         iBgScanProvider->NotifyChangedSettings( iBgScanProviderSettings );
  3963         iBgScanProvider->NotifyChangedSettings( iBgScanProviderSettings );
  3926     	
       
  3927     	// Pending scan requests should be handled because after the system time change all the
       
  3928     	// timestamps are invalid. Change the scan start times to start immediately
       
  3929 
       
  3930         DEBUG("CWlmServer::SystemTimeChanged() - set all pending requests to expire immediately");
       
  3931         
       
  3932     	TInt i( 0 );
       
  3933     	for( i = 0; i < iRequestMap.Count(); i++ )
       
  3934     	    {
       
  3935     	    if( IsPendingTimedScanRequest(i) )
       
  3936     	        {
       
  3937                 DEBUG1( "CWlmServer::SystemTimeChanged() - setting iTime to current time for request %i",
       
  3938                         iRequestMap[i].iRequestId );
       
  3939                 
       
  3940     	        TTime* requestedScanTime = reinterpret_cast<TTime*>( iRequestMap[i].iTime );
       
  3941                 requestedScanTime->UniversalTime();              
       
  3942     	        }
       
  3943     	    }
       
  3944         if( !iCoreHandlingScanRequest )
       
  3945             {
       
  3946             // Core is not handling any scan request so update the timer
       
  3947             DEBUG("CWlmServer::SystemTimeChanged() - Core is not currently handling any scan requests");
       
  3948             DEBUG("CWlmServer::SystemTimeChanged() - Cancel timer and set it again to new value");
       
  3949 
       
  3950             iScanSchedulingTimer->Cancel();
       
  3951             TUint indexNextScan;
       
  3952             if( FindNextTimedScanSchedulingRequest( indexNextScan ) )
       
  3953                 {
       
  3954                 TTime* nextScanTime = reinterpret_cast<TTime*>( iRequestMap[indexNextScan].iTime );
       
  3955                 UpdateScanSchedulingTimer( *nextScanTime, iRequestMap[indexNextScan].iRequestId );
       
  3956                 }
       
  3957             }
       
  3958     	}
  3964     	}
  3959     }
  3965     }
  3960 
  3966 
  3961 // ---------------------------------------------------------
  3967 // ---------------------------------------------------------
  3962 // CWlmServer::ClearRegionCache
  3968 // CWlmServer::ClearRegionCache
  4098             SRequestMapEntry entry = iRequestMap[index];
  4104             SRequestMapEntry entry = iRequestMap[index];
  4099             delete reinterpret_cast<core_type_list_c<core_iap_data_s>*>( entry.iParam0 );
  4105             delete reinterpret_cast<core_type_list_c<core_iap_data_s>*>( entry.iParam0 );
  4100             delete reinterpret_cast<core_type_list_c<u32_t>*>( entry.iParam1 );
  4106             delete reinterpret_cast<core_type_list_c<u32_t>*>( entry.iParam1 );
  4101             delete reinterpret_cast<ScanList*>( entry.iParam2);
  4107             delete reinterpret_cast<ScanList*>( entry.iParam2);
  4102             delete reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( entry.iParam3 );
  4108             delete reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( entry.iParam3 );
  4103             delete reinterpret_cast<TTime*>( entry.iTime );
  4109             delete reinterpret_cast<TUint*>( entry.iTime );
  4104             iRequestMap.Remove( index );
  4110             iRequestMap.Remove( index );
  4105 
  4111 
  4106             DEBUG( "CWlmServer::CancelScan() - find next possible timed scan scheduling request" );
  4112             DEBUG( "CWlmServer::CancelScan() - find next possible timed scan scheduling request" );
  4107             TUint indexNextScan;
  4113             TUint indexNextScan;
  4108             if( FindNextTimedScanSchedulingRequest( indexNextScan ) )
  4114             if( FindNextTimedScanSchedulingRequest( indexNextScan ) )
  4135                 SRequestMapEntry entry = iRequestMap[index];
  4141                 SRequestMapEntry entry = iRequestMap[index];
  4136                 delete reinterpret_cast<core_type_list_c<core_iap_data_s>*>( entry.iParam0 );
  4142                 delete reinterpret_cast<core_type_list_c<core_iap_data_s>*>( entry.iParam0 );
  4137                 delete reinterpret_cast<core_type_list_c<u32_t>*>( entry.iParam1 );
  4143                 delete reinterpret_cast<core_type_list_c<u32_t>*>( entry.iParam1 );
  4138                 delete reinterpret_cast<ScanList*>( entry.iParam2);
  4144                 delete reinterpret_cast<ScanList*>( entry.iParam2);
  4139                 delete reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( entry.iParam3 );
  4145                 delete reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( entry.iParam3 );
  4140                 delete reinterpret_cast<TTime*>( entry.iTime );                
  4146                 delete reinterpret_cast<TUint*>( entry.iTime );                
  4141                 iRequestMap.Remove( index );
  4147                 iRequestMap.Remove( index );
  4142                 }
  4148                 }
  4143             }
  4149             }
  4144         }
  4150         }
  4145     DEBUG( "CWlmServer::CancelScan() - returning" );
  4151     DEBUG( "CWlmServer::CancelScan() - returning" );
  4380     // Check that WLAN is ON
  4386     // Check that WLAN is ON
  4381 	TWlanOnOffState wlanState( iPlatform->GetWlanOnOffState() );
  4387 	TWlanOnOffState wlanState( iPlatform->GetWlanOnOffState() );
  4382 	if( wlanState != EWlanOn )
  4388 	if( wlanState != EWlanOn )
  4383 	    {
  4389 	    {
  4384 		// WLAN is OFF and therefore request is not served.
  4390 		// WLAN is OFF and therefore request is not served.
  4385 		DEBUG1( "CWlmServer::RunProtectedSetup() rejected due to WLAN is OFF (%d)",
  4391 		DEBUG1( "CWlmServer::RunProtectedSetup() - rejected due to WLAN is OFF (%d)",
  4386 		    wlanState );
  4392 		    wlanState );
  4387 		// WLAN states map one to one to WLAN error codes.
  4393 		// WLAN states map one to one to WLAN error codes.
  4388 		aMessage.Complete( wlanState );
  4394 		aMessage.Complete( wlanState );
  4389 		return;
  4395 		return;
  4390 		}
  4396 		}
  5011     UpdateWlanSettings();
  5017     UpdateWlanSettings();
  5012 
  5018 
  5013     // If WLAN is set ON, enable background scanning
  5019     // If WLAN is set ON, enable background scanning
  5014     if( iPlatform->GetWlanOnOffState() == EWlanOn )
  5020     if( iPlatform->GetWlanOnOffState() == EWlanOn )
  5015         {
  5021         {
  5016         iBgScanProvider->WlanSetBgScanState( MWlanBgScanProvider::EWlanBgScanOn );
  5022         iBgScanProvider->SetBgScanState( MWlanBgScanProvider::EWlanBgScanOn );
  5017         }
  5023         }
  5018 
  5024 
  5019     iPlatform->InitializeSystemTimeHandler();
  5025     iPlatform->InitializeSystemTimeHandler();
  5020     }
  5026     }
  5021 
  5027 
  5230 	// set and that does not happen until startup has been
  5236 	// set and that does not happen until startup has been
  5231 	// completed.
  5237 	// completed.
  5232 	if( iIsStartupComplete )
  5238 	if( iIsStartupComplete )
  5233 	    {
  5239 	    {
  5234 	    // Enable background scanning
  5240 	    // Enable background scanning
  5235 	    iBgScanProvider->WlanSetBgScanState( MWlanBgScanProvider::EWlanBgScanOn );
  5241 	    iBgScanProvider->SetBgScanState( MWlanBgScanProvider::EWlanBgScanOn );
  5236 	    }
  5242 	    }
  5237 	}
  5243 	}
  5238 
  5244 
  5239 // ---------------------------------------------------------
  5245 // ---------------------------------------------------------
  5240 // CWlmServer::WlanOff
  5246 // CWlmServer::WlanOff
  5241 // ---------------------------------------------------------
  5247 // ---------------------------------------------------------
  5242 //
  5248 //
  5243 void CWlmServer::WlanOff()
  5249 void CWlmServer::WlanOff()
  5244     {
  5250     {
  5245 	DEBUG( "CWlmServer::WlanOff()" );
  5251 	DEBUG1( "CWlmServer::WlanOff() - ConnectionState=%d",
       
  5252 	    iConnectionState );
  5246 	
  5253 	
  5247 	// Disable background scanning
  5254 	// Disable background scanning
  5248 	iBgScanProvider->WlanSetBgScanState( MWlanBgScanProvider::EWlanBgScanOff );
  5255 	iBgScanProvider->SetBgScanState( MWlanBgScanProvider::EWlanBgScanOff );
  5249 	
  5256 	
  5250 	// Cancel all running operations that are forbidden in WLAN OFF
  5257 	// Cancel all running operations that are forbidden in WLAN OFF
  5251     CancelExternalRequestsByType( ERunProtectedSetup );
  5258     CancelExternalRequestsByType( ERunProtectedSetup );
  5252     CancelExternalRequestsByType( EJoinByProfileId );
  5259     CancelExternalRequestsByType( EJoinByProfileId );
  5253     
  5260