wlanutilities/wlansniffer/engine/server/src/wsfserver.cpp
branchRCL_3
changeset 25 f28ada11abbf
parent 0 56b72877c1cb
equal deleted inserted replaced
24:63be7eb3fc78 25:f28ada11abbf
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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 of CWsfServer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  CLASS HEADER
       
    20 #include "wsfserver.h"
       
    21 
       
    22 //  INTERNAL INCLUDES
       
    23 #include "wsfengine.h"
       
    24 #include "wsfsession.h"
       
    25 #include "wsfservercommon.h"
       
    26 #include "wsflogger.h"
       
    27 
       
    28 
       
    29 //  LOCAL DEFINITIONS
       
    30 /**
       
    31 * Number of security ranges
       
    32 */
       
    33 static const TInt KRangeCount = 1;
       
    34 
       
    35 
       
    36 /**
       
    37 * Security ranges
       
    38 */
       
    39 static const TInt KSecurityRanges[KRangeCount] = 
       
    40 	{
       
    41 	0,
       
    42 	};
       
    43 
       
    44 
       
    45 /**
       
    46 * Policy for the security ranges
       
    47 */	
       
    48 static const TUint8 KSecurityRangesPolicy[KRangeCount] =
       
    49 	{
       
    50 	CPolicyServer::ECustomCheck
       
    51 	};
       
    52 
       
    53 
       
    54 /**
       
    55 * The complete policy structure
       
    56 */
       
    57 static const CPolicyServer::TPolicy KPolicy =
       
    58 	{
       
    59 	CPolicyServer::EAlwaysPass,
       
    60 	KRangeCount,
       
    61 	KSecurityRanges,
       
    62 	KSecurityRangesPolicy,
       
    63 	NULL,
       
    64 	};
       
    65 	
       
    66 
       
    67 /**
       
    68 * Secure ID of the Active Idle (ailaunch.exe)
       
    69 */
       
    70 static _LIT_SECURE_ID( KSidActiveIdle, 0x102750F0 );
       
    71 
       
    72 	
       
    73 	
       
    74 // ---------------------------------------------------------------------------
       
    75 // CWsfServer::NewLC
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 CWsfServer* CWsfServer::NewLC()
       
    79 	{
       
    80 	CWsfServer* snifferServer = new (ELeave) CWsfServer( 
       
    81 	                                                  CActive::EPriorityHigh );
       
    82 	CleanupStack::PushL( snifferServer );
       
    83 	snifferServer->ConstructL();
       
    84 	snifferServer->StartL( KWlanSnifferServerName );
       
    85 	
       
    86 	return snifferServer;
       
    87 	}
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // CWsfServer::NewSessionL
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 CSession2* CWsfServer::NewSessionL( const TVersion& aVersion, 
       
    95                                     const RMessage2& /*aMessage*/) const
       
    96 	{
       
    97 	LOG_ENTERFN( "CWsfServer::NewSessionL" );
       
    98 	// check we're the right version
       
    99 	TVersion v( KWlanSnifferServerMajor, 
       
   100 	            KWlanSnifferServerMinor, 
       
   101 	            KWlanSnifferServerBuild );
       
   102 	
       
   103 	if ( !User::QueryVersionSupported( v, aVersion ) )
       
   104 	    {
       
   105 	    User::Leave( KErrNotSupported );
       
   106 	    }
       
   107 	
       
   108 	// make new session
       
   109 	CSession2* newSession = CWsfSession::NewL( 
       
   110 	                                        const_cast<CWsfServer&>( *this ) );
       
   111 	
       
   112 	return newSession;
       
   113 	}
       
   114 	
       
   115 	
       
   116 // ---------------------------------------------------------------------------
       
   117 // CWsfServer::CWsfServer
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 CWsfServer::CWsfServer( TInt aPriority ): 
       
   121     CPolicyServer( aPriority, KPolicy ),
       
   122 	iClientCount( 0 )
       
   123 	{
       
   124 	}
       
   125 
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CWsfServer::~CWsfServer
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 CWsfServer::~CWsfServer()
       
   132 	{
       
   133 	delete iCloser;
       
   134 	delete iEngine;
       
   135 	}	
       
   136 
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CWsfServer::ConstructL
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CWsfServer::ConstructL()
       
   143 	{
       
   144 	iCloser = CWsfServerCloser::NewL();
       
   145 
       
   146 	iEngine = CWsfEngine::NewL( *iCloser );
       
   147 
       
   148 	// start the closing up procedure
       
   149 	// so we won't be left running if no clients would appear
       
   150 	iCloser->WaitForClients( EFalse );
       
   151 	
       
   152 	}
       
   153 
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // CWsfServer::ClientRelease
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 void CWsfServer::ClientRelease()
       
   160 	{
       
   161 	LOG_ENTERFN( "CWsfServer::ClientRelease" );
       
   162 	--iClientCount;
       
   163 	
       
   164 	// even if there are no clients, we might need to keep the server alive
       
   165 	// to maintain the connection or clean up IAPs properly
       
   166 	if ( !iClientCount )
       
   167 		{
       
   168 		
       
   169 		// The last client is released.
       
   170         // Iap deletion must not suppress anymore. Make sure the flag is off.
       
   171         iEngine->ResetSuppressIapDeletion();
       
   172         
       
   173 		// From this point on, the server is kept alive to wait for connection notifications if necessary. 
       
   174 		// E.g. browser could be launched by sniffer and WLAN connection still exists after sniffer shut down, 
       
   175 		// server waits for connection lost callback and cleans up temporary IAPs when connection is closed. 
       
   176 		
       
   177 	    // If no connections are available, make sure the the server is NOT kept alive to wait
       
   178 	    // browser exit, because the server is not set to monitor those notifications directly. 
       
   179 		if( !iEngine->IsConnected() )
       
   180 		    {
       
   181 		    iCloser->WaitForBrowserExit( EFalse );
       
   182 		    }
       
   183 		
       
   184 		iCloser->WaitForClients( EFalse );
       
   185 		}
       
   186 	}
       
   187 
       
   188 
       
   189 // ---------------------------------------------------------------------------
       
   190 // CWsfServer::ClientAttach
       
   191 // ---------------------------------------------------------------------------
       
   192 //
       
   193 void CWsfServer::ClientAttach()
       
   194 	{
       
   195 	LOG_ENTERFN( "CWsfServer::ClientAttach" );
       
   196 	iCloser->Cancel();
       
   197 	++iClientCount;
       
   198 	
       
   199 	iCloser->WaitForClients( ETrue );
       
   200 	}
       
   201 
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CWsfServer::Engine
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 CWsfEngine* CWsfServer::Engine()
       
   208 	{
       
   209 	return iEngine;
       
   210 	}	
       
   211 	
       
   212 
       
   213 // ---------------------------------------------------------------------------
       
   214 // CWsfServer::RunServer
       
   215 // ---------------------------------------------------------------------------
       
   216 //
       
   217 TInt CWsfServer::RunServer()
       
   218 	{
       
   219 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   220 	TInt ret = KErrNoMemory;
       
   221 	if ( cleanup )
       
   222 		{
       
   223 		TRAP( ret, CWsfServer::RunServerL() );
       
   224 		delete cleanup;
       
   225 		}
       
   226 
       
   227 	if ( ret != KErrNone )
       
   228 		{
       
   229 		// Signal the client that server creation failed
       
   230 		RProcess::Rendezvous( ret );
       
   231 		}
       
   232 
       
   233 	return KErrNone;
       
   234 	}
       
   235 
       
   236 
       
   237 // ---------------------------------------------------------------------------
       
   238 // CWsfServer::RunServerL
       
   239 // ---------------------------------------------------------------------------
       
   240 //
       
   241 void CWsfServer::RunServerL()
       
   242 	{
       
   243 	// Create and install the active scheduler we need
       
   244 	CActiveScheduler *as = new (ELeave) CActiveScheduler;
       
   245 	CleanupStack::PushL( as );
       
   246 	CActiveScheduler::Install( as );
       
   247 
       
   248 	// Create server
       
   249 	CWsfServer::NewLC();
       
   250 
       
   251 	// Initialisation complete, now signal the client
       
   252 	User::LeaveIfError( RThread().RenameMe( KWlanSnifferServerName ) );
       
   253 	RProcess::Rendezvous( KErrNone );
       
   254 
       
   255 	// Ready to run
       
   256 	CActiveScheduler::Start();
       
   257 
       
   258 	// Cleanup the server and scheduler
       
   259 	CleanupStack::PopAndDestroy( 2, as );
       
   260 	}
       
   261 
       
   262 
       
   263 // ---------------------------------------------------------------------------
       
   264 // CWsfServer::RunError
       
   265 // ---------------------------------------------------------------------------
       
   266 //
       
   267 TInt CWsfServer::RunError( TInt /*aError*/ )
       
   268 	{
       
   269 	return KErrNone;
       
   270 	}
       
   271 	
       
   272 
       
   273 // ---------------------------------------------------------------------------
       
   274 // CWsfServer::E32Main
       
   275 // ---------------------------------------------------------------------------
       
   276 //
       
   277 TInt E32Main()
       
   278 	{
       
   279 	TInt error( KErrNone );
       
   280 	error = CWsfServer::RunServer();
       
   281 	return error;
       
   282 	}
       
   283 
       
   284 	
       
   285 // ---------------------------------------------------------------------------
       
   286 // CWsfServer::CustomSecurityCheckL
       
   287 // ---------------------------------------------------------------------------
       
   288 //
       
   289 CPolicyServer::TCustomResult CWsfServer::CustomSecurityCheckL( 
       
   290                                                 const RMessage2& aMsg, 
       
   291                                                 TInt& /*aAction*/, 
       
   292                                                 TSecurityInfo& /*aMissing*/ )
       
   293 	{	
       
   294 	TCustomResult ret = EFail;
       
   295 
       
   296 	switch ( aMsg.Function() )
       
   297         {
       
   298         // NULL CAPABILITIES
       
   299         case ESnifferCmdNotifyEvents:
       
   300         case ESnifferCmdCancelNotifyEvents:
       
   301         case ESnifferCmdIsScanEnabled:
       
   302         case ESnifferCmdCancelAll:
       
   303         case ESnifferCmdConnectionName:	
       
   304         case ESnifferCmdIsConnected:
       
   305         case ESnifferCmdMonitorAp:
       
   306             {
       
   307         	ret = EPass;
       
   308         	break;
       
   309             }        	
       
   310         	
       
   311         // CAPABILITY NEEDED
       
   312         case ESnifferCmdActivateScan:
       
   313         case ESnifferCmdDisableScan:
       
   314         case ESnifferCmdWlanDataSize:
       
   315         case ESnifferCmdGetWlanInfo:
       
   316         case ESnifferCmdConnectedDetails:
       
   317         case ESnifferCmdConnect:
       
   318         case ESnifferCmdDisconnect:
       
   319         case ESnifferCmdRequestScan:
       
   320         case ESnifferCmdAbortScanning:
       
   321         case ESnifferCmdAbortConnecting:
       
   322         case ESnifferCmdSetIapPersistence:
       
   323         case ESnifferCmdControlDisconnectTimer:
       
   324             {
       
   325         	// if it is called from ailaunch.exe
       
   326         	// disgusting workaround
       
   327             if ( aMsg.SecureId() == KSidActiveIdle )
       
   328             	{
       
   329             	ret = EPass;
       
   330             	}
       
   331             else
       
   332             	{
       
   333            		ret = ( aMsg.HasCapability( ECapabilityNetworkServices ) && 
       
   334            		        aMsg.HasCapability( ECapabilityNetworkControl ) )? 
       
   335         			        EPass : EFail;
       
   336         		}
       
   337         	break;
       
   338             }
       
   339 
       
   340         default:
       
   341             {
       
   342         	ret = EPass;
       
   343         	break;
       
   344             }
       
   345 
       
   346         }
       
   347 	
       
   348 	
       
   349 	return ret;
       
   350 	}
       
   351