sipplugins/sippwlanplugin/Src/CWLanBearerMonitor.cpp
changeset 0 307788aac0a8
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 #include "CWLanBearerMonitor.h"
       
    19 #include "sipbearerowner.h"
       
    20 #include "CWLanConnUsagePermissionMonitor.h"
       
    21 #include "sipwlanlog.h"
       
    22 #include <wlanerrorcodes.h>
       
    23 
       
    24 const TInt KCompletionTime = 1;
       
    25 
       
    26 // -----------------------------------------------------------------------------
       
    27 // CWLanBearerMonitor::NewL
       
    28 // -----------------------------------------------------------------------------
       
    29 //
       
    30 CWLanBearerMonitor* CWLanBearerMonitor::NewL( TAny* aParams )
       
    31 	{
       
    32 	CWLanBearerMonitor* self = new( ELeave ) CWLanBearerMonitor( aParams );
       
    33 	CleanupClosePushL( *self );
       
    34 	self->ConstructL();
       
    35 	CleanupStack::Pop(); // self
       
    36 	return self;
       
    37 	}
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CWLanBearerMonitor::~CWLanBearerMonitor
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 CWLanBearerMonitor::~CWLanBearerMonitor()
       
    44 	{
       
    45 	if( iAsyncCompletionTimer )
       
    46 	    {
       
    47     	iAsyncCompletionTimer->Remove( iTimerEntry );
       
    48 	    }
       
    49     delete iAsyncCompletionTimer;
       
    50     
       
    51 	delete iUsagePermissionMonitor;
       
    52 	
       
    53 	// Cancel notifications and close connection monitor session
       
    54 	iConnMon.CancelNotifications();
       
    55 	iConnMon.Close();
       
    56 	}
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // CWLanBearerMonitor::RefreshL
       
    60 // -----------------------------------------------------------------------------
       
    61 //	
       
    62 void CWLanBearerMonitor::RefreshL( TInt aError )
       
    63     {  
       
    64 
       
    65     SIPWLAN_LOG("CWLanBearerMonitor::RefreshL, calling SetCurrentAvailabilityL()")
       
    66     SetCurrentAvailabilityL();
       
    67 	if(!aError)
       
    68 	{
       
    69     SIPWLAN_LOG("CWLanBearerMonitor::RefreshL, calling IssueActivityNotification()")
       
    70     IssueActivityNotification();
       
    71 	}
       
    72 	
       
    73     }
       
    74 // -----------------------------------------------------------------------------
       
    75 // CWLanBearerMonitor::ContinueMonitoring
       
    76 // -----------------------------------------------------------------------------
       
    77 //        
       
    78 TBool CWLanBearerMonitor::ContinueMonitoring( TInt aError )
       
    79     {
       
    80     SIPWLAN_INTLOG("CWLanBearerMonitor::ContinueMonitoring", aError)
       
    81     return !IapSettingsInvalid( aError );
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CWLanBearerMonitor::EventL
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CWLanBearerMonitor::EventL( const CConnMonEventBase& aConnMonEvent )
       
    89     {
       
    90     SIPWLAN_LOG("CWLanBearerMonitor::EventL")
       
    91     
       
    92 	// We're interested only on iap availability notifications
       
    93 	if( ( aConnMonEvent.EventType() == EConnMonIapAvailabilityChange ) &&
       
    94 		( aConnMonEvent.ConnectionId() == EBearerIdAll ) )
       
    95 	    {	    
       
    96 	    // Typecast event to appropriate event type
       
    97 		const CConnMonIapAvailabilityChange& event =
       
    98 			static_cast< const CConnMonIapAvailabilityChange& >( aConnMonEvent );
       
    99 			
       
   100 		// Check availability and report to our owner
       
   101 		MSIPNetworkObserver::TNetworkState newState = 
       
   102 		    IsAvailable( event.IapAvailability(), iIapId ) ? 
       
   103             	    MSIPNetworkObserver::ENetworkActive : 
       
   104             	    MSIPNetworkObserver::ENetworkInactive;
       
   105 
       
   106         SIPWLAN_INTLOG("CWLanBearerMonitor::EventL: new state", newState)
       
   107 
       
   108         // Report only if state of monitored iap changed
       
   109 	    if ( iState != newState )
       
   110 	        {
       
   111 	        iState = newState;
       
   112 	        iParent.BearerStateChanged( this, KErrNone );
       
   113 	        }
       
   114 	    }
       
   115 	}
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CWLanBearerMonitor::UsagePermissionChanged
       
   119 // -----------------------------------------------------------------------------
       
   120 //	
       
   121 void CWLanBearerMonitor::UsagePermissionChanged( 
       
   122     TBool aPermissionToUse, 
       
   123     TInt aError )
       
   124     {
       
   125     iUsagePermission = aPermissionToUse;
       
   126     
       
   127     if ( !aError )
       
   128         {
       
   129         // Don't wait for availability changed event if not necessary since
       
   130         // it may take several minutes (even if IAP is already available).
       
   131         TRAP( aError, SetCurrentAvailabilityL() );
       
   132         }
       
   133 
       
   134     IssueActivityNotification( aError );
       
   135     }
       
   136     
       
   137 // -----------------------------------------------------------------------------
       
   138 // CWLanBearerMonitor::CompletionCallback
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 TInt CWLanBearerMonitor::CompletionCallback( TAny* aAny )
       
   142 	{
       
   143 	CWLanBearerMonitor* self = 
       
   144 	    reinterpret_cast< CWLanBearerMonitor* >( aAny );
       
   145 
       
   146     if ( self )
       
   147         {
       
   148         self->InformActivity();
       
   149         }
       
   150     
       
   151 	return KErrNone;
       
   152 	}
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CWLanBearerMonitor::CWLanBearerMonitor
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 CWLanBearerMonitor::CWLanBearerMonitor( TAny* aParams )	: 
       
   159     CSIPBearerMonitor( aParams ),
       
   160 	iCallBack( CompletionCallback, this ),
       
   161 	iTimerEntry( iCallBack ),
       
   162 	iLastError( KErrNone )
       
   163 	{
       
   164 	}
       
   165 
       
   166 // -----------------------------------------------------------------------------
       
   167 // CWLanBearerMonitor::ConstructL
       
   168 // -----------------------------------------------------------------------------
       
   169 //
       
   170 void CWLanBearerMonitor::ConstructL()
       
   171 	{
       
   172 	// These are really very peculiar functions. They can
       
   173 	// both leave AND return an error code..
       
   174 	User::LeaveIfError( iConnMon.ConnectL() );
       
   175 	User::LeaveIfError( iConnMon.NotifyEventL( *this ) );
       
   176 	
       
   177 	iUsagePermissionMonitor = CWLanConnUsagePermissionMonitor::NewL( *this );
       
   178 	
       
   179 	iAsyncCompletionTimer = CDeltaTimer::NewL( CActive::EPriorityStandard );
       
   180     
       
   181     SetCurrentAvailabilityL();
       
   182     
       
   183     iUsagePermission = iUsagePermissionMonitor->CurrentUsagePermissionL();
       
   184             	    
       
   185     IssueActivityNotification();
       
   186 	}
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CWLanBearerMonitor::SetCurrentAvailabilityL
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CWLanBearerMonitor::SetCurrentAvailabilityL()
       
   193     {                         
       
   194     // Get current availability of this monitor owner's wlan access point
       
   195     // and set current network state according it
       
   196     //
       
   197     TConnMonIapInfoBuf iapInfo;
       
   198 	TRequestStatus status;
       
   199 	iConnMon.GetPckgAttribute( EBearerIdWLAN, 0, KIapAvailability,
       
   200 							   iapInfo, status );
       
   201 	User::WaitForRequest( status );
       
   202 	User::LeaveIfError( status.Int() );
       
   203 	
       
   204 	iState = IsAvailable( iapInfo(), iIapId ) ? 
       
   205             	    MSIPNetworkObserver::ENetworkActive : 
       
   206             	    MSIPNetworkObserver::ENetworkInactive;
       
   207     SIPWLAN_INTLOG("CWLanBearerMonitor::SetCurrentAvailabilityL", iState)        	    
       
   208     }
       
   209     
       
   210 // -----------------------------------------------------------------------------
       
   211 // CWLanBearerMonitor::IsAvailable
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 TBool CWLanBearerMonitor::IsAvailable( 
       
   215     const TConnMonIapInfo& aIapInfo, 
       
   216     TInt aIapId )
       
   217     {
       
   218     // Check if aIapId is in the list of available access points
       
   219     TInt count = aIapInfo.iCount;
       
   220     for ( TInt i = 0; i < count; i++ )
       
   221         {
       
   222         if ( aIapInfo.iIap[ i ].iIapId == aIapId )
       
   223             {
       
   224             return ETrue;
       
   225             }
       
   226         }
       
   227     return EFalse;
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // CWLanBearerMonitor::IssueActivityNotification
       
   232 // -----------------------------------------------------------------------------
       
   233 //    
       
   234 void CWLanBearerMonitor::IssueActivityNotification( TInt aError )
       
   235     {
       
   236     // Notify activity asynchronously
       
   237     iAsyncCompletionTimer->Remove( iTimerEntry );
       
   238     iAsyncCompletionTimer->Queue( KCompletionTime, iTimerEntry );
       
   239     iLastError = aError;
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CWLanBearerMonitor::InformActivity
       
   244 // -----------------------------------------------------------------------------
       
   245 //    
       
   246 void CWLanBearerMonitor::InformActivity()
       
   247     {
       
   248     if ( iLastError ||
       
   249        ( iState == MSIPNetworkObserver::ENetworkActive && iUsagePermission ) )
       
   250         {
       
   251         iParent.BearerStateChanged( this, iLastError );
       
   252         }
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // CWLanBearerMonitor::IapSettingsInvalid
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 TBool CWLanBearerMonitor::IapSettingsInvalid( TInt aError ) const
       
   260     {
       
   261     if ( aError == KErrNotFound || 
       
   262          aError == KErrBadName ||
       
   263          aError == KErrNotSupported ||
       
   264          aError == KErrWlanOpenAuthFailed ||
       
   265          aError == KErrWlanSharedKeyAuthRequired ||
       
   266          aError == KErrWlanSharedKeyAuthFailed ||
       
   267          aError == KErrWlanWpaAuthRequired ||
       
   268          aError == KErrWlanIllegalEncryptionKeys ||
       
   269          aError == KErrWlanPskModeRequired ||
       
   270          aError == KErrWlanEapModeRequired ||
       
   271          aError == KErrWlanSimNotInstalled ||
       
   272          aError == KErrWlanNotSubscribed ||
       
   273          aError == KErrWlanAccessBarred ||
       
   274          aError == KErrWlanPasswordExpired ||
       
   275          aError == KErrWlanNoDialinPermissions ||
       
   276          aError == KErrWlanAccountDisabled ||
       
   277          aError == KErrWlanRestrictedLogonHours ||
       
   278          aError == KErrWlanServerCertificateExpired ||
       
   279          aError == KErrWlanCerficateVerifyFailed ||
       
   280          aError == KErrWlanNoUserCertificate ||
       
   281          aError == KErrWlanNoCipherSuite ||
       
   282          aError == KErrWlanUserRejected ||
       
   283          aError == KErrWlanUserCertificateExpired)
       
   284         {
       
   285 	SIPWLAN_INTLOG("CWLanBearerMonitor::IapSettingsInvalid, Fatal", aError)
       
   286         return ETrue;
       
   287         }
       
   288 		
       
   289 	else if(
       
   290 		aError == KErrWlanWpaAuthFailed ||
       
   291 		aError == KErrWlan802dot1xAuthFailed ||
       
   292 		aError == KErrWlanIllegalWpaPskKey ||
       
   293 		aError == KErrWlanEapSimFailed ||
       
   294 		aError == KErrWlanEapTlsFailed ||
       
   295         aError == KErrWlanEapPeapFailed ||
       
   296 		aError == KErrWlanEapMsChapv2 ||
       
   297         aError == KErrWlanEapAkaFailed ||
       
   298         aError == KErrWlanEapTtlsFailed ||
       
   299 		aError == KErrWlanLeapFailed ||
       
   300 		aError == KErrWlanEapGtcFailed )
       
   301 		{
       
   302 	SIPWLAN_INTLOG("CWLanBearerMonitor::IapSettingsInvalid, Less Fatal", aError)
       
   303 		return EFalse;
       
   304 		}
       
   305 		 
       
   306 		 
       
   307     return EFalse;
       
   308     }
       
   309 
       
   310 // End of File