wlan_bearer/wlanengine/wlan_symbian/wlanengine_symbian_3.1/src/wlmserver.cpp
branchRCL_3
changeset 17 a828660c511c
parent 14 13838cf40350
child 18 d3d7683d16f5
--- a/wlan_bearer/wlanengine/wlan_symbian/wlanengine_symbian_3.1/src/wlmserver.cpp	Thu Aug 19 11:40:48 2010 +0300
+++ b/wlan_bearer/wlanengine/wlan_symbian/wlanengine_symbian_3.1/src/wlmserver.cpp	Tue Aug 31 17:02:06 2010 +0300
@@ -16,7 +16,7 @@
 */
 
 /*
-* %version: 105.1.3 %
+* %version: 111 %
 */
 
 #include <e32def.h>
@@ -476,6 +476,19 @@
     {
     DEBUG( "CWlmServer::Connect()" );
 
+    // Check that WLAN is ON
+    TWlanOnOffState wlanState( iPlatform->GetWlanOnOffState() );
+	if( wlanState != EWlanOn )
+	    {
+		// WLAN is OFF
+		DEBUG1( "CWlmServer::Connect() - refused due to WLAN is OFF (%d)",
+		    wlanState );
+		// WLAN state enumerations map one to one to WLAN error code
+		aMessage.Complete( wlanState );
+		
+		return;
+		}
+
     // Get WlanSettings and secondarySSID list
     // (lanServiceId specifies the table row in wlansettings)
     SWLANSettings iapData;
@@ -1843,9 +1856,11 @@
                         iAggressiveScanningAfterLinkLoss = EFalse;
                         }
                     
-                    // If background scan is on, this call will cause a background scan to occur.
-					// The icon is updated after the background scan is completed.
-                    iBgScanProvider->WlanStateChanged( MWlanBgScanProvider::EWlanStateDisconnected );
+					// If WLAN is ON, enable background scanning
+					if( iPlatform->GetWlanOnOffState() == EWlanOn )
+					    {
+                        iBgScanProvider->SetBgScanState( MWlanBgScanProvider::EWlanBgScanOn );
+                        }
                     
                     break;
                 case EWlanStateInfrastructure:
@@ -2377,7 +2392,7 @@
                 // If background scan is currently on, background scan
                 // will be disabled and it's request will be removed
                 // from the request map.
-                iBgScanProvider->WlanStateChanged( MWlanBgScanProvider::EWlanStateConnected );
+                iBgScanProvider->SetBgScanState( MWlanBgScanProvider::EWlanBgScanOff );
                 
                 }
             }
@@ -2431,7 +2446,7 @@
         if( IsSessionActive( completedMapEntry ) )
             {
             TPckg<TWlmProtectedSetupCredentials> outPckg( tmp );
-            completedMapEntry.iMessage.Write( 1, outPckg );
+            completedMapEntry.iMessage.Write( 2, outPckg );
             }
 
         if( status == core_error_ok && IsSessionActive( completedMapEntry ) )
@@ -3617,12 +3632,15 @@
     DEBUG1( "CWlmServer::ScanSchedulingTimerExpired() - iRequestId %u", self->iRequestMap[index].iRequestId );
     
     TUint indexNextScan( 0 );
-    // If roaming is ongoing, scanning is not started for GetScanResults. 
-    if ( self->iRequestMap[index].iRequestId >= KWlanExtCmdBase && 
-         self->iRequestMap[index].iFunction == EGetScanResults && 
-    	 self->IsRoaming() )
+    // If roaming is ongoing or WLAN is OFF, scanning is not started for
+    // GetScanResults but instead empty scan list is returned. 
+    if ( ( self->iRequestMap[index].iRequestId >= KWlanExtCmdBase && 
+           self->iRequestMap[index].iFunction == EGetScanResults ) && 
+    	 ( self->IsRoaming() || self->iPlatform->GetWlanOnOffState() != EWlanOn ) )
         {
-        DEBUG( "CWlmServer::ScanSchedulingTimerExpired() - GetScanResults, roam in progress, returning empty scan results" );
+        DEBUG2( "CWlmServer::ScanSchedulingTimerExpired() - GetScanResults, returning empty list; roaming: %d, WLAN on/off: %d",
+            self->IsRoaming(),
+            self->iPlatform->GetWlanOnOffState() );
 
         ScanList* completedScanList = reinterpret_cast<ScanList*>( self->iRequestMap[index].iParam0 );
         core_ssid_s* completedSsid =  reinterpret_cast<core_ssid_s*>( self->iRequestMap[index].iParam1 );
@@ -3639,7 +3657,15 @@
         if( self->IsSessionActive( self->iRequestMap[index] ) )
             {
             self->iRequestMap[index].iMessage.Write( 2, pckgDynamicScanList );
-            self->iRequestMap[index].iMessage.Complete( KErrNone );
+
+            if( self->iPlatform->GetWlanOnOffState() != EWlanOn )
+                {
+                self->iRequestMap[index].iMessage.Complete( self->iPlatform->GetWlanOnOffState() );
+                }
+            else
+                {
+                self->iRequestMap[index].iMessage.Complete( KErrServerBusy );
+                }
             }
 
         delete completedScanList;
@@ -3665,27 +3691,47 @@
     if ( self->iRequestMap[index].iRequestId >= KWlanExtCmdBase && 
          self->iRequestMap[index].iFunction == EGetAvailableIaps )
         {
-        DEBUG( "CWlmServer::ScanSchedulingTimerExpired() - GetAvailableIaps requested" );
-
+        DEBUG( "CWlmServer::ScanSchedulingTimerExpired() - GetAvailableIaps" );
+            
         core_type_list_c<core_iap_data_s>* iapDataList = reinterpret_cast<core_type_list_c<core_iap_data_s>*>( self->iRequestMap[index].iParam0 );
         core_type_list_c<core_iap_availability_data_s>* iapAvailabilityList =
             reinterpret_cast<core_type_list_c<core_iap_availability_data_s>*>( self->iRequestMap[index].iParam1 );
         ScanList* scanList =  reinterpret_cast<ScanList*>( self->iRequestMap[index].iParam2 );
         core_type_list_c<core_ssid_entry_s>* iapSsidList =  reinterpret_cast<core_type_list_c<core_ssid_entry_s>*>( self->iRequestMap[index].iParam3 );
         TUint* scanTime =  reinterpret_cast<TUint*>( self->iRequestMap[index].iTime );        
-        
-        // If the device is roaming OR there are not WLAN IAPs defined in the device
+
+        // If the device is roaming OR
+        // there are not WLAN IAPs defined in the device OR
+        // WLAN is OFF
         // --> return empty list
-        if( self->IsRoaming() || iapDataList->count() == 0 )
+        if( self->IsRoaming() ||
+            iapDataList->count() == 0 ||
+            self->iPlatform->GetWlanOnOffState() != EWlanOn )
             {
-            DEBUG( "CWlmServer::ScanSchedulingTimerExpired() - Device is roaming or no IAPs defined, returning empty list" );
+            DEBUG3( "CWlmServer::ScanSchedulingTimerExpired() - GetAvailableIaps, returning empty list; roaming: %d, iaps: %d, WLAN on/off: %d",
+                self->IsRoaming(),
+                iapDataList->count(),
+                self->iPlatform->GetWlanOnOffState() );    
+            
             // Only the triggering request is completed and then scan scheduling timer is set again 
             if( self->IsSessionActive( self->iRequestMap[index] ) )
                 {
                 TWlmAvailableIaps tmp = { 0 };
                 TPckg<TWlmAvailableIaps> outPckg( tmp );
                 self->iRequestMap[index].iMessage.Write( 0, outPckg );
-                self->iRequestMap[index].iMessage.Complete( KErrNone );
+
+                if( self->iPlatform->GetWlanOnOffState() != EWlanOn )
+                    {
+                    self->iRequestMap[index].iMessage.Complete( self->iPlatform->GetWlanOnOffState() );
+                    }
+                else if( iapDataList->count() == 0 )
+                    {
+                    self->iRequestMap[index].iMessage.Complete( KErrNone );
+                    }
+                else
+                    {
+                    self->iRequestMap[index].iMessage.Complete( KErrServerBusy );
+                    }
                 }
 
             delete iapDataList;
@@ -4470,39 +4516,58 @@
     {
     DEBUG( "CWlmServer::RunProtectedSetup()" );
     
-    // Get WlanSettings and secondarySSID list
-    // (lanServiceId specifies the table row in wlansettings)
-    SWLANSettings iapData;
-    RArray<TWlanSecondarySsid> secondarySsidList;
-    TInt lanServiceId = aMessage.Int0();
-    TRAPD( err, GetIapSettingsL( lanServiceId, iapData, secondarySsidList ) ) ;
-    if( err != KErrNone )
+    // Check that WLAN is ON
+	TWlanOnOffState wlanState( iPlatform->GetWlanOnOffState() );
+	if( wlanState != EWlanOn )
+	    {
+		// WLAN is OFF and therefore request is not served.
+		DEBUG1( "CWlmServer::RunProtectedSetup() - rejected due to WLAN is OFF (%d)",
+		    wlanState );
+		// WLAN states map one to one to WLAN error codes.
+		aMessage.Complete( wlanState );
+		return;
+		}
+        
+    TPckgBuf<TWlanSsid> ssidPckg;
+    TInt ret( aMessage.Read( 0, ssidPckg ) );
+    if( ret != KErrNone )
         {
-        DEBUG1( "CWlmServer::RunProtectedSetup() - GetIapSettingsL leaved with %d",
-            err );
-        secondarySsidList.Close();
-        aMessage.Complete( err );
+        aMessage.Complete( ret );
         return;
         }
-    secondarySsidList.Close();
-
-    // Type conversion
+    
+    TPckgBuf<TWlanWpsPin> wpsPinPckg;
+    ret = aMessage.Read( 1, wpsPinPckg );
+    if( ret != KErrNone )
+        {
+        aMessage.Complete( ret );
+        return;
+        }
+    
     core_iap_data_s* coreIapData = new core_iap_data_s;
     if( !coreIapData )
         {
         aMessage.Complete( KErrNoMemory );
         return;
         }
-
-    TWLMOverrideSettings override = { 0 };
-    TWlanConversionUtil::ConvertIapSettings(
-        *coreIapData, 
-        iapData, 
-        ETrue, // dhcp usage is not important here
-        override );
-
-
-    // Create a list for the results.
+    
+    coreIapData->id = 0;
+    coreIapData->op_mode = core_operating_mode_infrastructure;
+    coreIapData->security_mode = core_security_mode_protected_setup;
+    coreIapData->wpa_preshared_key_in_use = ETrue; 
+    coreIapData->is_wpa_overriden = ETrue;
+    
+    // Type conversion
+    TWlanConversionUtil::ConvertSSID(
+         coreIapData->ssid,
+         ssidPckg() );
+    
+    // Type conversion
+    TWlanConversionUtil::ConvertWpaPreSharedKey(
+         coreIapData->wpa_preshared_key,
+         wpsPinPckg() );
+    
+    // Create a list for the results.  
     core_type_list_c<core_iap_data_s>* iapDataList = new core_type_list_c<core_iap_data_s>;
     if( iapDataList == NULL )
         {
@@ -5091,6 +5156,12 @@
      */
     UpdateWlanSettings();
 
+    // If WLAN is set ON, enable background scanning
+    if( iPlatform->GetWlanOnOffState() == EWlanOn )
+        {
+        iBgScanProvider->SetBgScanState( MWlanBgScanProvider::EWlanBgScanOn );
+        }
+
     iPlatform->InitializeSystemTimeHandler();
     }
 
@@ -5301,3 +5372,88 @@
     iPlatform->PublishBgScanInterval( aInterval );
     }
     
+// ---------------------------------------------------------
+// CWlmServer::WlanOn
+// ---------------------------------------------------------
+//
+void CWlmServer::WlanOn()
+    {
+	DEBUG( "CWlmServer::WlanOn()" );
+	
+	// BG scan can be set ON only after BG scan interval has been
+	// set and that does not happen until startup has been
+	// completed.
+	if( iIsStartupComplete )
+	    {
+	    // Enable background scanning
+	    iBgScanProvider->SetBgScanState( MWlanBgScanProvider::EWlanBgScanOn );
+	    }
+	}
+
+// ---------------------------------------------------------
+// CWlmServer::WlanOff
+// ---------------------------------------------------------
+//
+void CWlmServer::WlanOff()
+    {
+	DEBUG1( "CWlmServer::WlanOff() - ConnectionState=%d",
+	    iConnectionState );
+	
+	// Disable background scanning
+	iBgScanProvider->SetBgScanState( MWlanBgScanProvider::EWlanBgScanOff );
+	
+	// Cancel all running operations that are forbidden in WLAN OFF
+    CancelExternalRequestsByType( ERunProtectedSetup );
+    CancelExternalRequestsByType( EJoinByProfileId );
+    
+	// If WLAN is connected...
+    if( iConnectionState != EWlanStateNotConnected )
+        {
+        //...send out disconnected indication, which brings down
+        // the connection gracefully
+        TBuf8<KMaxNotificationLength> buf;
+        buf.Append( static_cast<u8_t>( EWlanStateNotConnected ) );
+        SendNotification( EWlmNotifyConnectionStateChanged, buf );
+        }
+	}
+    
+// ---------------------------------------------------------
+// CWlmServer::CancelRequestsByType
+// ---------------------------------------------------------
+//
+void CWlmServer::CancelExternalRequestsByType(
+    const TWLMCommands aCommand )
+    {
+    DEBUG1( "CWlmServer::CancelExternalRequestsByType( aCommand=%u )", aCommand );
+
+    // Go through request map and cancel the command given as a parameter
+    for( TInt i( 0 ); i < iRequestMap.Count(); i++ )
+        {
+        if( iRequestMap[i].iFunction == aCommand )
+            {
+            DEBUG1( "CWlmServer::CancelExternalRequestsByType() - request found (id=%u), cancelling",
+                iRequestMap[i].iRequestId );
+            
+            iCoreServer->cancel_request( iRequestMap[i].iRequestId );
+            }
+        }
+    }
+
+// ---------------------------------------------------------
+// CWlmServer::SendNotification
+// ---------------------------------------------------------
+//
+void CWlmServer::SendNotification(
+    TWlmNotify amNotification,
+    TBuf8<KMaxNotificationLength>& aParams )
+    {
+    DEBUG1( "CWlmServer::SendNotification( notification=%u )",
+        amNotification );
+    
+    // Notify subscribees
+    for ( TInt i = 0; i < iNotificationArray.Count(); i++ )
+        {
+        iNotificationArray[i]->AddNotification( amNotification, aParams );
+        }
+    }
+