tcpiputils/dhcp/te_dhcp/src/te_dhcpTestServer.cpp
changeset 0 af10295192d8
child 21 abbed5a4b42a
equal deleted inserted replaced
-1:000000000000 0:af10295192d8
       
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // for (WINS && EKA1) versions will be xxxServer.Dll and require a thread to be started
       
    15 // in the process of the client. The client initialises the server by calling the
       
    16 // one and only ordinal.
       
    17 // On EKA2 this is an exe.
       
    18 // 
       
    19 //
       
    20 
       
    21 /**
       
    22  @file te_dhcpTestServer.cpp
       
    23 */
       
    24 
       
    25 #include <in_sock.h>
       
    26 
       
    27 #include "te_dhcpTestServer.h"
       
    28 #include "te_dhcpTestStep1.h"
       
    29 #include "te_dhcpTestStep2.h"
       
    30 #include "te_dhcpTestStep3.h"
       
    31 #include "te_dhcpTestStep4.h"
       
    32 #include "te_dhcpTestStep5.h"
       
    33 #include "te_dhcpTestStep6.h"
       
    34 #include "te_dhcpTestCommandSteps.h"
       
    35 #include "te_dhcpTestStepOOM.h"
       
    36 #include "te_dhcpserverteststep.h"
       
    37 
       
    38 #include <in6_opt.h>
       
    39 #include <commdbconnpref.h>
       
    40 #include <commsdattypesv1_1.h>
       
    41 
       
    42 #define _DEBUG_DHCP_STATE_NAMES
       
    43 #include "../../include/DHCPStatesDebug.h"
       
    44 
       
    45 CDhcpTestServer* CDhcpTestServer::NewL()
       
    46 /**
       
    47 * @return - Instance of the test server
       
    48 * Called inside the MainL() function to create and start the
       
    49 * CTestServer derived server.
       
    50 */
       
    51 	{
       
    52 	CDhcpTestServer * server = new (ELeave) CDhcpTestServer();
       
    53 	CleanupStack::PushL(server);
       
    54 	// CServer base class call
       
    55 	server->StartL(server->ServerName());
       
    56 
       
    57 	CleanupStack::Pop(server);
       
    58 	return server;
       
    59 	}
       
    60 
       
    61 
       
    62 #if (!defined EKA2)
       
    63 LOCAL_C void MainL()
       
    64 /**
       
    65 * REQUIRES semaphore to sync with client as the Rendezvous()
       
    66 * calls are not available
       
    67 */
       
    68 	{
       
    69 	CActiveScheduler* sched=NULL;
       
    70 	sched = new(ELeave) CActiveScheduler;
       
    71 	CleanupStack::PushL(sched);
       
    72 	CActiveScheduler::Install(sched);
       
    73 
       
    74 	CDhcpTestServer* server = NULL;
       
    75 
       
    76 	TRAPD(err,server = CDhcpTestServer::NewL());
       
    77 	// if there is an error, then we don't want to be doing all the
       
    78 	// fancy stuff, just cleanup, adnd the rest is taken care of
       
    79 	// for us...
       
    80 	if(!err)
       
    81 		{
       
    82 		CleanupStack::PushL(server);
       
    83 		RSemaphore sem;
       
    84 		// The client API will already have created the semaphore
       
    85 		User::LeaveIfError(sem.OpenGlobal(KServerName));
       
    86 		CleanupStack::Pop(server);
       
    87 		// Sync with the client then enter the active scheduler
       
    88 		sem.Signal();
       
    89 		sem.Close();
       
    90 		sched->Start();
       
    91 		}
       
    92 	delete server;
       
    93 	CleanupStack::PopAndDestroy(sched);
       
    94 	}
       
    95 #else
       
    96 // EKA2 much simpler
       
    97 // Just an E32Main and a MainL()
       
    98 LOCAL_C void MainL()
       
    99 /**
       
   100 * Much simpler, uses the new Rendezvous() call to sync with the client
       
   101 */
       
   102 	{
       
   103 	// Leave the hooks in for platform security
       
   104 #if (defined __DATA_CAGING__)
       
   105 	RProcess().DataCaging(RProcess::EDataCagingOn);
       
   106 	RProcess().SecureApi(RProcess::ESecureApiOn);
       
   107 #endif
       
   108 	CActiveScheduler* sched=NULL;
       
   109 	sched = new(ELeave) CActiveScheduler;
       
   110 	CleanupStack::PushL(sched);
       
   111 	CActiveScheduler::Install(sched);
       
   112 
       
   113 	CDhcpTestServer* server = NULL;
       
   114 	// Create the CTestServer derived server
       
   115 	TRAPD(err,server = CDhcpTestServer::NewL());
       
   116 	// if there is an error, then we don't want to be doing all the
       
   117 	// fancy stuff, just cleanup, adnd the rest is taken care of
       
   118 	// for us...
       
   119 	if(!err)
       
   120 		{
       
   121 		// Sync with the client and enter the active scheduler
       
   122 		RProcess::Rendezvous(KErrNone);
       
   123 #ifdef _DEBUG
       
   124 		RProperty::Define(KMyPropertyCat, KMyPropertyDestPortv4, RProperty::EInt, TSecurityPolicy(TSecurityPolicy::EAlwaysPass),
       
   125 					TSecurityPolicy(ECapabilityWriteDeviceData));
       
   126 		RProperty::Define(KMyPropertyCat, KMyPropertyDestPortv6, RProperty::EInt, TSecurityPolicy(TSecurityPolicy::EAlwaysPass),
       
   127 					TSecurityPolicy(ECapabilityWriteDeviceData));
       
   128 		RProperty::Set(KMyPropertyCat, KMyPropertyDestPortv4, 67);	// set to default values
       
   129 		RProperty::Set(KMyPropertyCat, KMyPropertyDestPortv6, 547);	// set to default values
       
   130         RProperty::Define(KMyPropertyCat, KMyDefaultLeaseTime, RProperty::EInt, TSecurityPolicy(TSecurityPolicy::EAlwaysPass),
       
   131                     TSecurityPolicy(ECapabilityWriteDeviceData));
       
   132         RProperty::Set(KMyPropertyCat, KMyDefaultLeaseTime, 21600);	// Define and set default values for server lease time
       
   133 #endif
       
   134 		sched->Start();
       
   135 		}
       
   136 	delete server;
       
   137 	CleanupStack::PopAndDestroy(sched);
       
   138 	}
       
   139 #endif
       
   140 
       
   141 // Only a DLL on emulator for typhoon and earlier
       
   142 #if (defined __WINS__ && !defined EKA2)
       
   143 TInt ThreadFunc (TAny* /*aParam*/)	// define the ordinal 1 on eka1
       
   144 #else			
       
   145 GLDEF_C TInt E32Main()	// define 32main if eka2...
       
   146 #endif
       
   147 /**
       
   148 * @return - Standard Epoc error code on exit
       
   149 */
       
   150 	{
       
   151 	CTrapCleanup* cleanup = CTrapCleanup::New();
       
   152 	if(cleanup == NULL)
       
   153 		{
       
   154 		return KErrNoMemory;
       
   155 		}
       
   156 	TInt err = KErrNone;
       
   157 	TRAP(err,MainL());
       
   158 	delete cleanup;
       
   159 	return err;
       
   160     }
       
   161 
       
   162 #if (defined __WINS__ && !defined EKA2)
       
   163 /**
       
   164   * Define this helper function to start a new thread in the client
       
   165   * process for WINS and EKA1...
       
   166   */
       
   167 EXPORT_C TInt NewServer() 
       
   168 /**
       
   169 * @return - Standard Epoc error codes
       
   170 * 1st and only ordinal, called by the client API to initialise the server
       
   171 */
       
   172 	{
       
   173 	RThread thread;
       
   174 	
       
   175 	TBuf<KMaxTestExecuteNameLength> threadName(KServerName);
       
   176 	// Create a hopefully unique thread name and use the ThreadFunc
       
   177 	const TInt KMaxHeapSize = 0x1000000;			//< Allow a 1Mb max heap
       
   178 	TInt err = thread.Create(threadName, ThreadFunc, KDefaultStackSize,
       
   179 								KMinHeapSize, KMaxHeapSize, NULL, EOwnerProcess);
       
   180 	if (err)
       
   181 		{
       
   182 		return err;
       
   183 		}
       
   184 	thread.Resume();
       
   185 	thread.Close();
       
   186 	return KErrNone;
       
   187 	}
       
   188 
       
   189 
       
   190 GLDEF_C TInt E32Dll(enum TDllReason)
       
   191 	{
       
   192 	return 0;
       
   193 	}
       
   194 #endif
       
   195 
       
   196 
       
   197 
       
   198 CTestStep* CDhcpTestServer::CreateTestStep(const TDesC& aStepName)
       
   199 /**
       
   200 * @return - A CTestStep derived instance
       
   201 * Implementation of CTestServer pure virtual
       
   202 */
       
   203 	{
       
   204 	CDhcpTestStepBase* testStep = NULL;
       
   205 	// This server creates just one step but create as many as you want
       
   206 	// They are created "just in time" when the worker thread is created
       
   207 	if(aStepName == KDhcpTestStep1_1)
       
   208 		testStep = new CDhcpTestStep1_1();
       
   209 	else if(aStepName == KDhcpTestStep1_2)
       
   210 		testStep = new CDhcpTestStep1_2();
       
   211 	else if(aStepName == KDhcpTestStep1_3)
       
   212 		testStep = new CDhcpTestStep1_3();
       
   213 	else if(aStepName == KDhcpTestStep1_4)
       
   214 		testStep = new CDhcpTestStep1_4();
       
   215 	else if(aStepName == KDhcpTestStep1_5)
       
   216 		testStep = new CDhcpTestStep1_5();
       
   217 	else if(aStepName == KDhcpTestStep1_6)
       
   218 		testStep = new CDhcpTestStep1_6();
       
   219 	else if(aStepName == KDhcpTestStep1_7)
       
   220 		testStep = new CDhcpTestStep1_7();
       
   221 	else if(aStepName == KDhcpTestStep1_8)
       
   222 		testStep = new CDhcpTestStep1_8();
       
   223 	
       
   224 	else if(aStepName == KDhcpTestStep2_1)
       
   225 		testStep = new CDhcpTestStep2_1();
       
   226 	else if(aStepName == KDhcpTestStep2_2)
       
   227 		testStep = new CDhcpTestStep2_2();
       
   228 	else if(aStepName == KDhcpTestStep2_3)
       
   229 		testStep = new CDhcpTestStep2_3();
       
   230 	else if(aStepName == KDhcpTestStep2_4)
       
   231 		testStep = new CDhcpTestStep2_4();
       
   232 	else if(aStepName == KDhcpTestStep2_5)
       
   233 		testStep = new CDhcpTestStep2_5();
       
   234 	else if(aStepName == KDhcpTestStep2_6)
       
   235 		testStep = new CDhcpTestStep2_6();
       
   236 	else if(aStepName == KDhcpTestStep2_7)
       
   237 		testStep = new CDhcpTestStep2_7();
       
   238 	else if(aStepName == KDhcpTestStep2_8)
       
   239 		testStep = new CDhcpTestStep2_8();
       
   240 	else if(aStepName == KDhcpTestStep2_9)
       
   241 		testStep = new CDhcpTestStep2_9();
       
   242     else if(aStepName == KDhcpTestStep2_GetRaw)
       
   243 		testStep = new CDhcpTestStep2_GetRaw();
       
   244 	else if(aStepName == KDhcpTestStep2_11)
       
   245 		testStep = new CDhcpTestStep2_11();
       
   246     else if(aStepName == KDhcpTestStep2_12)
       
   247 		testStep = new CDhcpTestStep2_12();		
       
   248     else if(aStepName == KDhcpTestStep2_ClearMOFlag)
       
   249         testStep = new CDhcpTestStep2_ClearMOFlag();
       
   250     else if(aStepName == KDhcpTestStep2_NoRAandDHCPServ)
       
   251         testStep = new CDhcpTestStep2_NoRAandDHCPServ(); 
       
   252 	else if(aStepName == KDhcpTestStep2_GetSIPAddrViaDHCP)
       
   253 		testStep = new CDhcpTestStep2_GetSIPAddrViaDHCP();
       
   254 	else if(aStepName == KDhcpTestStep2_GetSIPAddrViaPCOBuffer)
       
   255 		testStep = new CDhcpTestStep2_GetSIPAddrViaPCOBuffer();
       
   256     else if(aStepName == KDhcpTestStep2_GetSIPDomain)
       
   257 		testStep = new CDhcpTestStep2_GetSIPDomain();	
       
   258 	else if(aStepName == KDhcpTestStep2_GetSIPAddrFailure)
       
   259 		testStep = new CDhcpTestStep2_GetSIPAddrFailure();
       
   260 	else if(aStepName == KDhcpTestStep2_GetSIPAddrBufferOverrun)
       
   261 		testStep = new CDhcpTestStep2_GetSIPAddrBufferOverrun();
       
   262 	else if(aStepName == KDhcpTestStep2_GetSIPServerAddrIndexChecker)
       
   263 		testStep = new CDhcpTestStep2_GetSIPServerAddrIndexChecker();
       
   264 	else if(aStepName == KDhcpTestStep2_GetSIPServerAddrNegativeIndexChecker)
       
   265 		testStep = new CDhcpTestStep2_GetSIPServerAddrNegativeIndexChecker();
       
   266     #ifdef SYMBIAN_TCPIPDHCP_UPDATE
       
   267 	/* PREQ1898 DHCPv6 test cases */
       
   268 	else if(aStepName == KDhcpTestStep2_DomainSearchList_Test1)
       
   269 		testStep = new CDhcpTestStep2_DomainSearchList_Test1();	
       
   270 	else if(aStepName == KDhcpTestStep2_DomainSearchList_Test2)
       
   271 		testStep = new CDhcpTestStep2_DomainSearchList_Test2();	
       
   272 	else if(aStepName == KDhcpTestStep2_DomainSearchList_Test3)
       
   273 		testStep = new CDhcpTestStep2_DomainSearchList_Test3();	
       
   274 	else if(aStepName == KDhcpTestStep2_DomainSearchList_Test4)
       
   275 		testStep = new CDhcpTestStep2_DomainSearchList_Test4();	
       
   276 	else if(aStepName == KDhcpTestStep2_DomainSearchList_Test5)
       
   277 		testStep = new CDhcpTestStep2_DomainSearchList_Test5();	
       
   278 	
       
   279 	else if(aStepName == KDhcpTestStep2_DNSServerList_Test1)
       
   280 		testStep = new CDhcpTestStep2_DNSServerList_Test1();	
       
   281 	else if(aStepName == KDhcpTestStep2_DNSServerList_Test2)
       
   282 		testStep = new CDhcpTestStep2_DNSServerList_Test2();	
       
   283 	else if(aStepName == KDhcpTestStep2_DNSServerList_Test3)
       
   284 		testStep = new CDhcpTestStep2_DNSServerList_Test3();	
       
   285 	else if(aStepName == KDhcpTestStep2_DNSServerList_Test4)
       
   286 		testStep = new CDhcpTestStep2_DNSServerList_Test4();	
       
   287 	else if(aStepName == KDhcpTestStep2_DNSServerList_Test5)
       
   288 		testStep = new CDhcpTestStep2_DNSServerList_Test5();		
       
   289 
       
   290 	else if(aStepName == KDhcpTestStep2_MultipleParams_Test1)
       
   291 		testStep = new CDhcpTestStep2_MultipleParams_Test1();
       
   292 	else if(aStepName == KDhcpTestStep2_MultipleParams_Test2)
       
   293 		testStep = new CDhcpTestStep2_MultipleParams_Test2();	
       
   294 	else if(aStepName == KDhcpTestStep2_MultipleParams_Test3)
       
   295 		testStep = new CDhcpTestStep2_MultipleParams_Test3();	
       
   296 	else if(aStepName == KDhcpTestStep2_MultipleParams_Test4)
       
   297 		testStep = new CDhcpTestStep2_MultipleParams_Test4();		
       
   298 	else if(aStepName == KDhcpTestStep2_MultipleParams_Test5)
       
   299 		testStep = new CDhcpTestStep2_MultipleParams_Test5();	
       
   300 	
       
   301 	else if(aStepName == KDhcpTestStep2_GetRaw_Test1)
       
   302 		testStep = new CDhcpTestStep2_GetRaw_Test1();
       
   303 	else if(aStepName == KDhcpTestStep2_GetRaw_Test2)
       
   304 		testStep = new CDhcpTestStep2_GetRaw_Test2();	
       
   305 	/* End of PREQ 1898 test case */
       
   306     #endif //SYMBIAN_TCPIPDHCP_UPDATE 
       
   307 	
       
   308 	else if(aStepName == KDhcpTestStep3_1)
       
   309 		testStep = new CDhcpTestStep3_1();
       
   310 	else if(aStepName == KDhcpTestStep3_2)
       
   311 		testStep = new CDhcpTestStep3_2();
       
   312 	else if(aStepName == KDhcpTestStep3_3)
       
   313 		testStep = new CDhcpTestStep3_3();		
       
   314 	else if(aStepName == KDhcpTestStep3_4)
       
   315 		testStep = new CDhcpTestStep3_4();
       
   316 	
       
   317 	else if(aStepName == KDhcpTestStep4_1)
       
   318 		testStep = new CDhcpTestStep4_1();
       
   319 	else if(aStepName == KDhcpTestStep4_2)
       
   320 		testStep = new CDhcpTestStep4_2();
       
   321 	else if(aStepName == KDhcpTestStep4_3)
       
   322 		testStep = new CDhcpTestStep4_3();
       
   323 
       
   324 	// tests in section 5 cannot be run automatically
       
   325 	// overnight, but may be able to run on hardware
       
   326 	else if(aStepName == KDhcpTestStep5_1)
       
   327 		testStep = new CDhcpTestStep5_1();
       
   328 	else if(aStepName == KDhcpTestStep5_2)
       
   329 		testStep = new CDhcpTestStep5_2();
       
   330 	else if(aStepName == KDhcpTestStep5_3)
       
   331 		testStep = new CDhcpTestStep5_3();
       
   332 	else if(aStepName == KDhcpTestStep5_4)
       
   333 		testStep = new CDhcpTestStep5_4();
       
   334 	else if(aStepName == KDhcpTestStep5_5)
       
   335 		testStep = new CDhcpTestStep5_5();
       
   336 	else if(aStepName == KDhcpTestStep5_6)
       
   337 		testStep = new CDhcpTestStep5_6();
       
   338 	else if(aStepName == KDhcpTestStep5_7)
       
   339 		testStep = new CDhcpTestStep5_7();
       
   340 	else if(aStepName == KDhcpTestStep5_8)
       
   341 		testStep = new CDhcpTestStep5_8();
       
   342 
       
   343 	if(aStepName == KDhcpTestStep12_1)
       
   344 		testStep = new CDhcpTestStep12_1();
       
   345 
       
   346 	else if(aStepName == KDhcpTestStepOOM_1)
       
   347 		testStep = new CDhcpTestStepOOM_1();
       
   348 	
       
   349 #ifdef SYMBIAN_NETWORKING_DHCPSERVER
       
   350 //tests added for the DHCP server implementation and run manually
       
   351 
       
   352 	else if(aStepName == KDhcpTestStep2_23)
       
   353 		testStep = new CDhcpTestStep2_23();
       
   354 	else if(aStepName == KDhcpTestStep2_24)
       
   355 		testStep = new CDhcpTestStep2_24();
       
   356 	else if(aStepName == KDhcpTestStep2_25)
       
   357 		testStep = new CDhcpTestStep2_25();
       
   358 	else if(aStepName == KDhcpTestStepOOM_2)
       
   359 		testStep = new CDhcpTestStepOOM_2();
       
   360 		
       
   361 #endif // SYMBIAN_NETWORKING_DHCPSERVER		
       
   362 		
       
   363 	// commands
       
   364 	else if(aStepName == KDhcpTestCommandSetAddressMode)
       
   365 		testStep = new CDhcpTestCommandSetAddressMode();
       
   366 	else if(aStepName == KDhcpTestCommandSetIAPToUse)
       
   367 		testStep = new CDhcpTestCommandSetIAPToUse();
       
   368 	else if(aStepName == KDhcpTestCommandSetDebugFlags)
       
   369 		testStep = new CDhcpTestCommandSetDebugFlags();
       
   370 	else if(aStepName == KDhcpTestCommandSetIPv4LinkLocal)
       
   371 		testStep = new CDhcpTestCommandSetIPv4LinkLocal();
       
   372 	
       
   373 #ifdef  SYMBIAN_NETWORKING_DHCP_MSG_HEADERS
       
   374 
       
   375 	else if(aStepName == KDhcpTestStep2_26)
       
   376 		testStep = new CDhcpTestStep2_26();
       
   377 	else if(aStepName == KDhcpTestStep2_27)
       
   378 		testStep = new CDhcpTestStep2_27();
       
   379 	else if(aStepName == KDhcpTestStep2_28)
       
   380 		testStep = new CDhcpTestStep2_28();
       
   381 	else if(aStepName == KDhcpTestStep2_29)
       
   382 		testStep = new CDhcpTestStep2_29();
       
   383 	else if(aStepName == KDhcpTestStep2_30)
       
   384 		testStep = new CDhcpTestStep2_30();
       
   385 	else if(aStepName == KDhcpTestStep2_31)
       
   386 		testStep = new CDhcpTestStep2_31();
       
   387 	else if(aStepName == KDhcpTestStep2_32)
       
   388 		testStep = new CDhcpTestStep2_32();
       
   389 	else if(aStepName == KDhcpTestStep2_33)
       
   390 		testStep = new CDhcpTestStep2_33();
       
   391 	else if(aStepName == KDhcpTestStep2_34)
       
   392 		testStep = new CDhcpTestStep2_34();
       
   393 	else if(aStepName == KDhcpTestStep2_35)
       
   394 		testStep = new CDhcpTestStep2_35();
       
   395 	else if(aStepName == KDhcpTestStep2_36)
       
   396 		testStep = new CDhcpTestStep2_36();
       
   397 	else if(aStepName == KDhcpTestStep2_37)
       
   398 		testStep = new CDhcpTestStep2_37();
       
   399 	else if(aStepName == KDhcpTestStep2_38)
       
   400 		testStep = new CDhcpTestStep2_38();
       
   401 	else if(aStepName == KDhcpTestStep2_39)
       
   402 		testStep = new CDhcpTestStep2_39();
       
   403 	else if(aStepName == KDhcpTestStep2_40)
       
   404 		testStep = new CDhcpTestStep2_40();	
       
   405 	else if(aStepName == KDhcpTestStep2_41)
       
   406 		testStep = new CDhcpTestStep2_41();	
       
   407 	else if(aStepName == KDhcpTestStepOOM_3)
       
   408 		testStep = new CDhcpTestStepOOM_3();
       
   409 		
       
   410 #endif //SYMBIAN_NETWORKING_DHCP_MSG_HEADERS  			
       
   411 	
       
   412   /* Added for DHCP testing with Codenomicon tool*/			
       
   413 	else if(aStepName == KDhcpTestStepCodenomicon1)
       
   414 		testStep = new CDhcpTestStepCodenomicon1();	
       
   415 	else if(aStepName == KDhcpTestStepCodenomicon2)
       
   416 		testStep = new CDhcpTestStepCodenomicon2();	
       
   417 	else if(aStepName == KDhcpTestStepServ_1)
       
   418 	    testStep = new CDhcpTestStepServ_1(); 
       
   419 	else if(aStepName == KDhcpTestStepServ_2)
       
   420 	    testStep = new CDhcpTestStepServ_2(); 
       
   421 	else if(aStepName == KDhcpTestStepServ_3)
       
   422 	    testStep = new CDhcpTestStepServ_3(); 
       
   423 	else if(aStepName == KDhcpTestStepServ_4)
       
   424 			testStep = new CDhcpTestStepServ_4(); 
       
   425 	else if(aStepName == KDhcpTestStepServ_5)
       
   426 			testStep = new CDhcpTestStepServ_5(); 
       
   427 	else if(aStepName == KDhcpTestStepServ_6)
       
   428 			testStep = new CDhcpTestStepServ_6(); 
       
   429 	
       
   430 	if(testStep)
       
   431 		{
       
   432 		testStep->SetTestServer(this);
       
   433 		}
       
   434 			
       
   435 	return testStep;
       
   436 	}
       
   437 
       
   438 
       
   439 //----------------------------------------------------------------------------------
       
   440 
       
   441 /**
       
   442  * sets the test server to be used by the test step for storing / accessing
       
   443  *  data which persists across test steps (e.g. IAP to use, IPv6 mode)
       
   444  */   
       
   445 void CDhcpTestStepBase::SetTestServer(CDhcpTestServer* aServ)
       
   446 	{
       
   447 	iTestServer = aServ;
       
   448 	}
       
   449 
       
   450 /**
       
   451  * sets whether we're in IPv6 mode
       
   452 @leave   if the test server is not available.
       
   453  */   
       
   454 void CDhcpTestStepBase::Set_UsingIPv6L(TBool aIP6)
       
   455 	{
       
   456 	User::LeaveIfNull(iTestServer);
       
   457 	iTestServer->iUsingIPv6 = aIP6;
       
   458 
       
   459 	}
       
   460 
       
   461 /**
       
   462  * sets which IAP subsequent test cases should use
       
   463 @leave   if the test server is not available.
       
   464  */   
       
   465 void CDhcpTestStepBase::SetIAPToUseL(TInt aIAP)
       
   466 	{
       
   467 	User::LeaveIfNull(iTestServer);
       
   468 	iTestServer->iIAPToUse = aIAP;
       
   469 	}
       
   470 
       
   471 
       
   472 /**
       
   473 * adds the ECDPrivate attribute to the IAP record - any component trying to access this record will require the ReadDeviceData capability
       
   474 @leave   if the test server is not available or the IAP record with the specified ID cannot be retrieved and modified by commsdat
       
   475 */
       
   476 void CDhcpTestStepBase::MakeIAPPrivateL( TInt id )
       
   477 	{
       
   478 	// Create a session which can view hidden records if necessary.
       
   479 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   480 	CMDBSession* session = CMDBSession::NewLC(KCDVersion1_2);
       
   481 #else
       
   482 	CMDBSession* session = CMDBSession::NewLC(KCDVersion1_1);
       
   483 #endif
       
   484 	session->SetAttributeMask( ECDHidden | ECDPrivate );
       
   485 	
       
   486 	// Load the IAP record.
       
   487 	CCDIAPRecord* iapRecord = static_cast<CCDIAPRecord*>( CCDRecordBase::RecordFactoryL( KCDTIdIAPRecord ) );
       
   488 	CleanupStack::PushL( iapRecord );
       
   489     iapRecord->SetRecordId( id );
       
   490 	iapRecord->LoadL( *session );
       
   491 
       
   492 	// Make it private.
       
   493 	iapRecord->SetAttributes( iapRecord->Attributes() | ECDPrivate );
       
   494 	iapRecord->ModifyL( *session );
       
   495 
       
   496 	// Cleanup.
       
   497 	CleanupStack::Pop();
       
   498 	CleanupStack::Pop();
       
   499 	}
       
   500 
       
   501 
       
   502 /**
       
   503 @return  ETrue if we are using ipv6, and EFalse otherwise.
       
   504 @leave   if the value from test server can't be obtained.
       
   505 */   
       
   506 TBool CDhcpTestStepBase::UsingIPv6L(void) const
       
   507 {
       
   508 	User::LeaveIfNull(iTestServer);
       
   509 	return iTestServer->iUsingIPv6;
       
   510 }
       
   511 
       
   512 /**
       
   513 @return  the IAP we're currently set to use
       
   514 @leave   if the value from test server can't be obtained.
       
   515 */   
       
   516 TInt CDhcpTestStepBase::IAPToUseL(void)
       
   517 	{
       
   518 	User::LeaveIfNull(iTestServer);
       
   519 	TInt iap = iTestServer->iIAPToUse;
       
   520 	if(iap == 0)
       
   521 		{
       
   522 		INFO_PRINTF1(_L("You must use the SetIAPToUse test step before running this test"));
       
   523 		User::Leave(KErrArgument); 
       
   524 		}
       
   525 	return iap;
       
   526 	}
       
   527 
       
   528 /**
       
   529 @leave   if the value from commsdat can't be obtained.
       
   530 */   
       
   531 void CDhcpTestStepBase::InitialServiceLinkL( CMDBSession* aDbSession, CCDIAPRecord* aIapRecord )
       
   532 	{
       
   533 	// This will be made more simple quite soon when commsdat supports linked records
       
   534 	//
       
   535 	if (aIapRecord->iService.iLinkedRecord == 0)
       
   536 		{
       
   537 		const TDesC& servType = aIapRecord->iServiceType;
       
   538 		__CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CCDHCPDb::InitialServiceLinkL() service type = \"%S\""), &servType));
       
   539 		if (servType.CompareF(TPtrC(KCDTypeNameDialOutISP))==0)
       
   540 			{
       
   541 			aIapRecord->iService.iLinkedRecord = static_cast<CCDDialOutISPRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdDialOutISPRecord));
       
   542 			}
       
   543 		else if (servType.CompareF(TPtrC(KCDTypeNameDialInISP))==0)
       
   544 			{
       
   545 			aIapRecord->iService.iLinkedRecord = static_cast<CCDDialInISPRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdDialInISPRecord));
       
   546 			}
       
   547 		else if (servType.CompareF(TPtrC(KCDTypeNameLANService))==0)
       
   548 			{
       
   549 			aIapRecord->iService.iLinkedRecord = static_cast<CCDLANServiceRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdLANServiceRecord));
       
   550 			}
       
   551 		else if (servType.CompareF(TPtrC(KCDTypeNameVPNService))==0)
       
   552 			{
       
   553 			aIapRecord->iService.iLinkedRecord = static_cast<CCDVPNServiceRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdVPNServiceRecord));
       
   554 			}
       
   555 		else
       
   556 			{
       
   557 			__CFLOG_VAR((KLogSubSysDHCP, KLogCode, _L8("CCDHCPDb::InitialServiceLinkL() Invalid Service Type!!!")));
       
   558 			User::Leave(KErrBadName);	
       
   559 			}
       
   560 		
       
   561 		aIapRecord->iService.iLinkedRecord->SetRecordId(aIapRecord->iService);
       
   562 		}
       
   563 
       
   564 	aIapRecord->iService.iLinkedRecord->LoadL(*aDbSession);
       
   565 	}
       
   566 
       
   567 /**
       
   568 @return  ETrue if the IAP we are using or EFalse otherwise
       
   569 @leave   if the value from commsdat can't be obtained.
       
   570 */   
       
   571 TBool CDhcpTestStepBase::IsIAPAddrStaticL()
       
   572 	{
       
   573 	// Create a session which can view hidden records if necessary.
       
   574 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
   575 	CMDBSession* session = CMDBSession::NewLC(KCDVersion1_2);
       
   576 #else
       
   577 	CMDBSession* session = CMDBSession::NewLC(KCDVersion1_1);
       
   578 #endif
       
   579 	
       
   580 	session->SetAttributeMask( ECDHidden | ECDPrivate );
       
   581 	
       
   582 	// Load the IAP record.
       
   583 	CCDIAPRecord* iapRecord = static_cast<CCDIAPRecord*>( CCDRecordBase::RecordFactoryL( KCDTIdIAPRecord ) );
       
   584 	CleanupStack::PushL( iapRecord );
       
   585     iapRecord->SetRecordId( IAPToUseL() );
       
   586 	iapRecord->LoadL( *session );
       
   587 
       
   588 	// Get the service record.
       
   589 	CCDServiceRecordBase* service;
       
   590 	InitialServiceLinkL( session, iapRecord );
       
   591 	service = static_cast<CCDServiceRecordBase*>(iapRecord->iService.iLinkedRecord);
       
   592 
       
   593 	// Read any statically assigned IP address.
       
   594 	TInetAddr addr;
       
   595 	TInt ignoreThis;
       
   596 	CMDBField<TBool>* addrFromServer = static_cast<CMDBField<TBool>*>( service->GetFieldByNameL( KCDTypeNameIpAddrFromServer, ignoreThis ) );
       
   597 	if( !*addrFromServer )
       
   598 		{
       
   599 		CMDBField<TDesC>* cdbAddr = static_cast<CMDBField<TDesC>*>( service->GetFieldByNameL( KCDTypeNameIpAddr, ignoreThis ) );
       
   600 		addr.Input( *cdbAddr );
       
   601 		}
       
   602 
       
   603 	// Cleanup.
       
   604 	CleanupStack::PopAndDestroy();
       
   605 	CleanupStack::PopAndDestroy();
       
   606 	
       
   607 	return !addr.IsUnspecified();
       
   608 	}
       
   609 
       
   610 /**
       
   611 @return Flags listing the currently configured address types.
       
   612 @leave   if any system error occurs.
       
   613 */
       
   614 TUint CDhcpTestStepBase::GetCurrentAddressTypesL( RSocket &socket )
       
   615 {
       
   616 	TUint flags = KCurAddrNone;
       
   617 	TPtr8 empty( NULL, 0 );
       
   618 
       
   619 	// Query the size of the buffer required.
       
   620 	TInt listLength = socket.GetOpt( KSoInetAddressInfo, KSolInetIfQuery, empty );
       
   621 	
       
   622 	if( listLength > 0 )
       
   623 		{
       
   624 		// Allocate the buffer and read the list of addresses.
       
   625 		TInetAddressInfo* addrInfoBuffer = new(ELeave) TInetAddressInfo[listLength];
       
   626 		TPtr8 opt( (TUint8* )addrInfoBuffer, listLength * sizeof( TInetAddressInfo ) );
       
   627 		if( socket.GetOpt( KSoInetAddressInfo, KSolInetIfQuery, opt ) == KErrNone )
       
   628 			{
       
   629 			listLength = opt.Length() / (TInt)sizeof( TInetAddressInfo );
       
   630 
       
   631 			for( TInt count = 0; count < listLength; count ++ )
       
   632 				{
       
   633 				// Check that the address has been assigned.
       
   634 				if( ( addrInfoBuffer[count].iState == TInetAddressInfo::EAssigned ) ||
       
   635 					( addrInfoBuffer[count].iState == TInetAddressInfo::ETentative ) )
       
   636 					{
       
   637 					TIp6Addr& addr( addrInfoBuffer[count].iAddress );
       
   638 					TInetAddr inetAddr = TInetAddr( addr, 0 );
       
   639 
       
   640 					if( !inetAddr.IsUnspecified() && !inetAddr.IsLoopback() )
       
   641 						{
       
   642 						TBuf<39> addrStr;
       
   643 						inetAddr.Output( addrStr );
       
   644 						
       
   645 						 // Some addresses seem to be set to the IPv6 family which causes
       
   646 						 // IsLinkLocal to match using the IPv6 link local mask but not the
       
   647 						 // IPv4 link local mask.  We test manually as well which should be
       
   648 						 // safe as ZEROCONF randomly generated link-locals can only be created
       
   649 						 // during IPv4 testing.
       
   650 						if( inetAddr.IsLinkLocal() ||
       
   651 							( ( INET_ADDR( inetAddr.Ptr()[10], inetAddr.Ptr()[11], inetAddr.Ptr()[12], inetAddr.Ptr()[13] ) & KInetAddrLinkLocalNetMask ) == KInetAddrLinkLocalNet ) )
       
   652 							{
       
   653 							flags |= KCurAddrIPv4LinkLocal;
       
   654 							
       
   655 							INFO_PRINTF2( _L( "Linklocal address %S found on interface"), &addrStr );
       
   656 							}
       
   657 						else
       
   658 							{
       
   659 							flags |= KCurAddrGlobal;
       
   660 
       
   661 							INFO_PRINTF2( _L( "Global address %S found on interface"), &addrStr );
       
   662 							}
       
   663 						}
       
   664 					}
       
   665 				}
       
   666 			}
       
   667 		}
       
   668 		
       
   669 	if( flags == KCurAddrNone )
       
   670 		{
       
   671 		INFO_PRINTF1( _L( "No addresses found on interface") );
       
   672 		}
       
   673 	
       
   674 	return flags;
       
   675 }
       
   676 
       
   677 
       
   678 
       
   679 /**
       
   680 @return KAfInet6 or KAfInet depending on the test configuration (see test .ini file)
       
   681 @leave   if the value from ini file can't be obtained.
       
   682 */
       
   683 TUint   CDhcpTestStepBase::IpAddressFamilyL(void)
       
   684 {
       
   685     return UsingIPv6L() ? KAfInet6 :  KAfInet;
       
   686 }
       
   687 
       
   688 /**
       
   689     Test step preamble. Just prints out which type AddrFamily we use.
       
   690 */
       
   691 TVerdict	CDhcpTestStepBase::doTestStepPreambleL()
       
   692 {
       
   693     if(UsingIPv6L())
       
   694     {
       
   695         INFO_PRINTF1(_L("KAfInet6 Address Family selected"));    
       
   696     }
       
   697     else
       
   698     {
       
   699         INFO_PRINTF1(_L("KAfInet Address Family selected"));    
       
   700     }
       
   701     
       
   702     INFO_PRINTF2(_L("This test step will use IAP %d"), IAPToUseL());
       
   703     
       
   704 	iConnPrefs.SetIapId(IAPToUseL());
       
   705 	iConnPrefs.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
   706 
       
   707     return EPass;
       
   708 }
       
   709 
       
   710 
       
   711 /**
       
   712     Get raw option data either for ip4 of for ip6, depending on the test setting
       
   713     @param  aConn    RConnection object, interface to the DHCP server
       
   714     @param  aBufDes  buffer for option data
       
   715     @param  aOptCode option code   
       
   716     
       
   717     @return IOCTL completion code
       
   718 */
       
   719 TInt CDhcpTestStepBase::DhcpGetRawOptionDataL(RConnection &aConn, TDes8& aBufDes, TUint aOptCode)
       
   720 {
       
   721 	TUint dhcpOptName;
       
   722     TRequestStatus stat;
       
   723     
       
   724 	//-- DHCP option data structure is totally different for DHCPv4 and DHCPv6
       
   725 	//-- so, we need to handle getting raw option data separately for v4 and v6.
       
   726 	if(UsingIPv6L())
       
   727 	{//-- we are dealing with DHCPv6 
       
   728         INFO_PRINTF1(_L("Getting DHCP6 raw option data")); 
       
   729         TDhcp6RawOptionDataPckg pckg6(aBufDes);
       
   730         pckg6.SetOpCode((TUint16)aOptCode);	// OPTION_CLIENTID
       
   731 
       
   732         dhcpOptName = KConnGetDhcp6RawOptionData;
       
   733 	}
       
   734 	else
       
   735 	{//-- we are dealing with DHCPv4 
       
   736     	INFO_PRINTF1(_L("Getting DHCP4 raw option data"));    
       
   737     	TDhcp4RawOptionDataPckg pckg(aBufDes);
       
   738     	pckg.SetOpCode((TUint8)aOptCode);	// the subnet mask
       
   739     	
       
   740     	dhcpOptName = KConnGetDhcp4RawOptionData; // the same as KConnGetDhcpRawOptionData
       
   741 	}
       
   742 	
       
   743 	// Get raw option data either for ip4 of ip6
       
   744 	aConn.Ioctl(KCOLConfiguration, dhcpOptName, stat, &aBufDes);
       
   745     User::WaitForRequest(stat);
       
   746     
       
   747     return stat.Int();
       
   748 }
       
   749 
       
   750 void CDhcpTestStepBase::GetDebugHandleL(RConnection& aConn)
       
   751 	{
       
   752     TRequestStatus stat;
       
   753     TPckgBuf<TInt> pckg;
       
   754 	aConn.Ioctl(KCOLConfiguration, KDHCP_GetPubSubMonitorHandle, stat, &pckg);
       
   755     User::WaitForRequest(stat);
       
   756 	if(stat.Int() != KErrNone)
       
   757 		{
       
   758 		INFO_PRINTF1(_L("Can't fetch debug handle from DHCP. Ensure it was built in debug mode"));
       
   759 		User::Leave(stat.Int());
       
   760 		}
       
   761 	iDebugHandle = pckg();
       
   762 	}
       
   763 
       
   764 void CDhcpTestStepBase::ImmediateCompletionTestL(RConnection& /*aConn*/)
       
   765 {
       
   766 	DHCPDebug::State state;
       
   767 
       
   768 	TBool bExpectImmediateCompletion;
       
   769     if(GetBoolFromConfig(ConfigSection(),_L("ExpectImmediateCompletion"), bExpectImmediateCompletion) == EFalse)
       
   770     	{
       
   771 		INFO_PRINTF1(_L("Couldn't read ExpectImmediateCompletion value from test ini file."));
       
   772 		SetTestStepResult(EFail);
       
   773 		User::Leave(KErrArgument);
       
   774     	}
       
   775 
       
   776     DHCPDebug::Readiness ready=DHCPDebug::EUnknown;
       
   777     QUERY_READYL(ready);
       
   778     
       
   779     if( ready == DHCPDebug::EReady )
       
   780     	{
       
   781     	if( bExpectImmediateCompletion )
       
   782     		{
       
   783 	    	INFO_PRINTF1(_L("DHCP shouldn't be ready so quickly after RConnection::Start completed"));
       
   784 			User::Leave(KErrUnknown);
       
   785 			}
       
   786 		else
       
   787 		    {
       
   788 		    INFO_PRINTF1(_L("As expected, DHCP is ready after RConnection::Start completed."));
       
   789 		    }
       
   790 		}
       
   791 	else if ( ready == DHCPDebug::ENotReady )
       
   792 		{
       
   793 		if( bExpectImmediateCompletion )
       
   794 			{
       
   795 			INFO_PRINTF1(_L("As expected, DHCP isn't yet ready though RConnection::Start completed."));
       
   796 			}
       
   797 		else
       
   798 		    {
       
   799 	    	INFO_PRINTF1(_L("DHCP should be ready after RConnection::Start completed"));
       
   800 			User::Leave(KErrUnknown);
       
   801 			}			
       
   802 		}
       
   803 	else
       
   804     	{
       
   805     	INFO_PRINTF1(_L("Couldn't read readiness state"));
       
   806 		User::Leave(KErrUnknown);
       
   807     	}
       
   808 
       
   809 	LOG_STATEL;
       
   810 }
       
   811 
       
   812 const TPtrC CDhcpTestServer::ServerName() const
       
   813 	{
       
   814 
       
   815 	// On EKA2, test server runs in its own process.
       
   816 	// So we arrive at the server name using the exe from which it is loaded.
       
   817 	// This is useful when doing cap tests, as we create duplicate exe's using setcap then.
       
   818 	TParsePtrC serverName(RProcess().FileName());
       
   819 	return serverName.Name();
       
   820 	}
       
   821 
       
   822 TUint CDhcpTestStepBase::WAIT_FOR_STATE_CHANGE_WITH_TIMEOUTL( TUint aTimeout )
       
   823 /**
       
   824 * Waits for the DHCP state to change or for a timeout to occur.  Not implemented
       
   825 * as macro because it's too complicated.
       
   826 *
       
   827 * Returns aTimeout if the wait times-out or the remainder if the state changed
       
   828 * (guaranteed to be less than aTimeout and at least one microsecond).
       
   829 */
       
   830 	{
       
   831     TAutoClose<RTimer> timer;
       
   832     User::LeaveIfError( timer.iObj.CreateLocal() );
       
   833     timer.PushL();
       
   834 	
       
   835 	TRequestStatus propStatus;
       
   836 	TRequestStatus timerStatus;
       
   837 	
       
   838 	// Attach to the property.
       
   839 	TAutoClose<RProperty> a;
       
   840 	TUid u = TUid::Uid(0x101fd9c5);
       
   841 	User::LeaveIfError( a.iObj.Attach(u, (TUint)(DHCPDebug::EState + iDebugHandle)) );
       
   842 	a.PushL();
       
   843 	
       
   844 	// Subscribe to the property.
       
   845 	TRequestStatus pubStat;
       
   846 	a.iObj.Subscribe(pubStat);
       
   847 	
       
   848 	TTime startTime;
       
   849 	startTime.UniversalTime();
       
   850 	
       
   851 	// Start the timeout timer.
       
   852 	timer.iObj.After( timerStatus, aTimeout );
       
   853 	
       
   854 	// Wait for the property to change or the timer to timeout.
       
   855 	User::WaitForRequest( pubStat, timerStatus );
       
   856 	
       
   857 	a.iObj.Cancel();
       
   858 	timer.iObj.Cancel();
       
   859 
       
   860 	a.Pop();
       
   861 	timer.Pop();
       
   862 	
       
   863 	// Check to see if the property changed or the timer timed-out.
       
   864 	if( timerStatus.Int() == KErrNone )
       
   865 		{
       
   866 		return aTimeout;
       
   867 		}
       
   868 	else
       
   869 		{
       
   870 		User::LeaveIfError( pubStat.Int() );
       
   871 		}
       
   872 	
       
   873 	TTime endTime;
       
   874 	endTime.UniversalTime();
       
   875 		
       
   876 	return Min( Max( TInt( endTime.MicroSecondsFrom( startTime ).Int64() ), 1 ), aTimeout );
       
   877 	}
       
   878 
       
   879 void CDhcpTestStepBase::GetProvisioningMacL(TDesC16& aSectioName, const TDesC16& aKeyName, TDes8& aHwAddress) 
       
   880     {
       
   881     TPtrC macAddressString;
       
   882     TInt macAddressLength = aHwAddress.Length();
       
   883     if (!GetStringFromConfig(aSectioName, aKeyName, macAddressString))
       
   884         {
       
   885         User::Leave(KErrNotFound);
       
   886         }
       
   887     
       
   888     aHwAddress.FillZ();
       
   889     
       
   890     TUint8 bitVal;
       
   891     for (TInt index=0, offset=0; index < macAddressLength; index++)
       
   892         {
       
   893         TLex bitText(macAddressString.Mid(offset,2));
       
   894         bitText.Val(bitVal, EHex);
       
   895         aHwAddress.Append(bitVal);
       
   896         offset+=2;
       
   897         }
       
   898     }
       
   899