linklayerprotocols/tundriver/te_tundriver/src/te_tundrivertestwrapper.cpp
branchRCL_3
changeset 75 c1029e558ef5
parent 67 bb2423252ea3
child 76 27c54f8619d4
equal deleted inserted replaced
67:bb2423252ea3 75:c1029e558ef5
     1 // Copyright (c) 2010 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 // Contains the implementation of all the commands, which is used by the script file.
       
    15 //
       
    16 
       
    17 /**
       
    18  @file te_tundrivertestwrapper.h
       
    19  @internalTechnology
       
    20  */
       
    21 
       
    22 #include "te_tundrivertestwrapper.h"
       
    23 #include <e32base.h>
       
    24 #include <utf.h>
       
    25 #include <in_sock.h>
       
    26 #include <es_sock.h>
       
    27 
       
    28 #include <metadatabase.h> 
       
    29 #include <commsdattypesv1_1.h> 
       
    30 #include <commsdat.h>
       
    31 #include <commsdattypesv1_1_partner.h>
       
    32 #include <commsdattypeinfov1_1_internal.h>
       
    33 #include <commdb.h>
       
    34 #include <commdbconnpref.h>
       
    35 
       
    36 //Virtual Interface 
       
    37 
       
    38 // Commands
       
    39 
       
    40 _LIT(KRConnTest1_1,         "RConnTest1_1");
       
    41 _LIT(KRConnTest1_2,         "RConnTest1_2");
       
    42 _LIT(KRConnTest1_3,         "RConnTest1_3");
       
    43 _LIT(KRConnTest1_4,         "RConnTest1_4");
       
    44 _LIT(KRConnTest1_5,         "RConnTest1_5");
       
    45 _LIT(KRConnTest1_6,         "RConnTest1_6");
       
    46 _LIT(KRConnTest1_7,         "RConnTest1_7");
       
    47 _LIT(KRConnTest1_8,         "RConnTest1_8");
       
    48 _LIT(KRConnTest1_9,         "RConnTest1_9");
       
    49 _LIT(KRConnTest1_10,        "RConnTest1_10");
       
    50 _LIT(KRConnTest1_11,        "RConnTest1_11");
       
    51 _LIT(KRConnTest1_12,        "RConnTest1_12");
       
    52 _LIT(KRConnTest1_13,        "RConnTest1_13");
       
    53 _LIT(KRConnTest1_14,        "RConnTest1_14");
       
    54 _LIT(KRConnTest1_15,        "RConnTest1_15");
       
    55 _LIT(KRConnTest1_16,        "RConnTest1_16");
       
    56 _LIT(KRConnTest1_17,        "RConnTest1_17");
       
    57 _LIT(KRConnTest1_18,        "RConnTest1_18");
       
    58 _LIT(KRConnTest1_19,        "RConnTest1_19");
       
    59 _LIT(KRConnTest1_20,        "RConnTest1_20");
       
    60 _LIT(KRConnTest1_21,        "RConnTest1_21");
       
    61 _LIT(KRConnTest1_22,        "RConnTest1_22");
       
    62 _LIT(KRConnTest1_23,        "RConnTest1_23");
       
    63 _LIT(KRConnTest1_24,        "RConnTest1_24");
       
    64 _LIT(KRConnTest1_25,        "RConnTest1_25");
       
    65 _LIT(KRConnTest1_26,        "RConnTest1_26");
       
    66 _LIT(KRConnTest1_27,        "RConnTest1_27");
       
    67 _LIT(KRConnTest1_28,        "RConnTest1_28");
       
    68 _LIT(KRConnTest1_29,        "RConnTest1_29");
       
    69 _LIT(KRConnTest1_30,        "RConnTest1_30");
       
    70 _LIT(KRConnTest1_31,        "RConnTest1_31");
       
    71 _LIT(KRConnTest1_32,        "RConnTest1_32");
       
    72 _LIT(KRConnTest1_33,        "RConnTest1_33");
       
    73 
       
    74 // Config file
       
    75 _LIT(KNameDefault, 	    	"default");
       
    76 _LIT(KIpAddr,               "IpAddr");
       
    77 _LIT(KGatewayAddr,          "GatewayAddr");
       
    78 _LIT(KDestAddr, 		    "DestAddr");
       
    79 _LIT(KLocalAddr,            "LocalAddr");
       
    80 _LIT(KLocalPort,            "LocalPort");
       
    81 _LIT(KDestPort,             "DestPort");
       
    82 _LIT(KTcpDestPort,          "TcpDestPort");
       
    83 _LIT(KRealDestAddr,         "RealDestAddr");
       
    84 _LIT(KRealDestPort,         "RealDestPort");
       
    85 
       
    86 //Test code
       
    87 _LIT(KCommand, 			    "aCommand = %S");
       
    88 _LIT(KSection, 			    "aSection = %S");
       
    89 
       
    90 //Test code error
       
    91 _LIT(KInetInputFail,         "TInetAddr Input failed with error: %d");
       
    92 
       
    93 #define TUNDRIVER_IAP   14
       
    94 #define REAL_IAP    9
       
    95 #define LOCAL_PORT 7777
       
    96 
       
    97 // public
       
    98 //LOCAL_D CConsoleBase* console; 
       
    99 
       
   100 
       
   101 /**
       
   102 Constructor.
       
   103 
       
   104 @internalTechnology
       
   105  */
       
   106 CTunDriverTestWrapper::CTunDriverTestWrapper()
       
   107     {
       
   108     }
       
   109 
       
   110 /**
       
   111 Destructor.
       
   112 
       
   113 @internalTechnology
       
   114  */
       
   115 CTunDriverTestWrapper::~CTunDriverTestWrapper()
       
   116     {
       
   117     }
       
   118 
       
   119 /**
       
   120 Function to instantiate TestWrapper.
       
   121 @return Returns constructed TestWrapper instance pointer
       
   122 @internalTechnology
       
   123  */
       
   124 CTunDriverTestWrapper* CTunDriverTestWrapper::NewL()
       
   125     {
       
   126     CTunDriverTestWrapper*	ret = new (ELeave) CTunDriverTestWrapper();
       
   127     CleanupStack::PushL(ret);
       
   128     ret->ConstructL();
       
   129     CleanupStack::Pop(ret);
       
   130     return ret;	
       
   131     }
       
   132 
       
   133 /**
       
   134 Second level constructor, constructs TestWrapper instance.
       
   135 @internalTechnology
       
   136  */
       
   137 void CTunDriverTestWrapper::ConstructL()
       
   138     {
       
   139     iInitNumOfInterfaces    = 0;
       
   140     iCurNumOfInterfaces     = 0;
       
   141     iDestPort               = 0;
       
   142 
       
   143     }
       
   144 
       
   145 /**
       
   146 Function to map the input command to respective function.
       
   147 
       
   148 @return - True Upon successfull command to Function name mapping otherwise False
       
   149 @param aCommand Function name has to be called
       
   150 @param aSection INI file paramenter section name
       
   151 @param aAsyncErrorIndex Error index
       
   152 @see Refer the script file COMMAND section.
       
   153 
       
   154 @internalTechnology
       
   155  */
       
   156 TBool CTunDriverTestWrapper::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/)
       
   157     {
       
   158     TBool ret = ETrue;
       
   159 
       
   160     // Print out the parameters for debugging
       
   161     INFO_PRINTF2( KCommand, &aCommand );
       
   162     INFO_PRINTF2( KSection, &aSection );
       
   163     //INFO_PRINTF2( KAsyncErrorIndex, aAsyncErrorIndex );
       
   164 
       
   165     //RConnection Testcases
       
   166     if(KRConnTest1_1() == aCommand)
       
   167         {
       
   168         DoRConnTest1_1();
       
   169         }
       
   170     else if(KRConnTest1_2() == aCommand)
       
   171         {
       
   172         DoRConnTest1_2();
       
   173         }
       
   174     else if(KRConnTest1_3() == aCommand)
       
   175         {
       
   176         DoRConnTest1_3(aSection);
       
   177         }
       
   178     else if(KRConnTest1_4() == aCommand)
       
   179         {
       
   180         DoRConnTest1_4(aSection);
       
   181         }
       
   182     else if(KRConnTest1_5() == aCommand)
       
   183         {
       
   184         DoRConnTest1_5(aSection);
       
   185         }
       
   186     else if(KRConnTest1_6() == aCommand)
       
   187         {
       
   188         DoRConnTest1_6(aSection);
       
   189         }
       
   190     else if(KRConnTest1_7() == aCommand)
       
   191         {
       
   192         DoRConnTest1_7(aSection);
       
   193         }
       
   194     else if(KRConnTest1_8() == aCommand)
       
   195         {
       
   196         DoRConnTest1_8(aSection);
       
   197         }
       
   198     else if(KRConnTest1_9() == aCommand)
       
   199         {
       
   200         DoRConnTest1_9(aSection);
       
   201         }
       
   202     else if(KRConnTest1_10() == aCommand)
       
   203         {
       
   204         DoRConnTest1_10(aSection);
       
   205         }
       
   206     else if(KRConnTest1_11() == aCommand)
       
   207         {
       
   208         DoRConnTest1_11();
       
   209         }
       
   210     else if(KRConnTest1_12() == aCommand)
       
   211         {
       
   212         DoRConnTest1_12();
       
   213         }
       
   214     else if(KRConnTest1_13() == aCommand)
       
   215         {
       
   216         DoRConnTest1_13(aSection);
       
   217         }
       
   218     else if(KRConnTest1_14() == aCommand)
       
   219         {
       
   220         DoRConnTest1_14(aSection);
       
   221         }
       
   222     else if(KRConnTest1_15() == aCommand)
       
   223         {
       
   224         DoRConnTest1_15();
       
   225         }
       
   226     else if(KRConnTest1_16() == aCommand)
       
   227         {
       
   228         DoRConnTest1_16(aSection);
       
   229         }
       
   230     else if(KRConnTest1_17() == aCommand)
       
   231         {
       
   232         DoRConnTest1_17(aSection);
       
   233         }
       
   234     else if(KRConnTest1_18() == aCommand)
       
   235         {
       
   236         
       
   237         }
       
   238     else if(KRConnTest1_19() == aCommand)
       
   239         {
       
   240     
       
   241         }
       
   242     else if(KRConnTest1_20() == aCommand)
       
   243         {
       
   244         DoRConnTest1_20();
       
   245         }
       
   246     else if(KRConnTest1_21() == aCommand)
       
   247         {
       
   248         DoRConnTest1_21();
       
   249         }
       
   250     else if(KRConnTest1_22() == aCommand)
       
   251         {
       
   252         DoRConnTest1_22();
       
   253         }
       
   254     else if(KRConnTest1_23() == aCommand)
       
   255         {
       
   256         DoRConnTest1_23();
       
   257         }
       
   258     else if(KRConnTest1_24() == aCommand)
       
   259         {
       
   260         DoRConnTest1_24();
       
   261         }
       
   262     else if(KRConnTest1_25() == aCommand)
       
   263         {
       
   264         DoRConnTest1_25();
       
   265         }
       
   266     else if(KRConnTest1_26() == aCommand)
       
   267         {
       
   268         DoRConnTest1_26();
       
   269         }
       
   270     else if(KRConnTest1_27() == aCommand)
       
   271         {
       
   272         DoRConnTest1_27();
       
   273         }
       
   274     else if(KRConnTest1_28() == aCommand)
       
   275         {
       
   276         DoRConnTest1_28();
       
   277         }
       
   278     else if(KRConnTest1_29() == aCommand)
       
   279         {
       
   280         DoRConnTest1_29();
       
   281         }
       
   282     else if(KRConnTest1_30() == aCommand)
       
   283         {
       
   284         DoRConnTest1_30();
       
   285         }
       
   286 	else if(KRConnTest1_31() == aCommand)
       
   287         {
       
   288         DoRConnTest1_31();
       
   289         }
       
   290 	else if(KRConnTest1_32() == aCommand)
       
   291         {
       
   292         DoRConnTest1_32();
       
   293         }
       
   294     else if(KRConnTest1_33() == aCommand)
       
   295         {
       
   296         DoRConnTest1_33();
       
   297         }	
       
   298     else
       
   299         {
       
   300         ret = EFalse;
       
   301         User::LeaveIfError(KErrNone); // just to suppress LeaveScan warning
       
   302         }
       
   303     return ret;
       
   304     }
       
   305 
       
   306 /**
       
   307 Function to open Virtual Socket.
       
   308 @internalTechnology
       
   309  */
       
   310 
       
   311 TBool CTunDriverTestWrapper::FindInterface(TPckgBuf<TSoInet6InterfaceInfo> &info)
       
   312     {
       
   313     TBool success = FALSE;
       
   314     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
   315         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
   316     else
       
   317         {
       
   318         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
   319         SetError(iStatus.Int());
       
   320 
       
   321         return success;
       
   322         }
       
   323 
       
   324     if((iStatus = iConnection1.Open(iSocketServ)) == KErrNone )
       
   325         INFO_PRINTF1(_L("Connection1 opened. \n"));
       
   326     else
       
   327         {
       
   328         ERR_PRINTF2(_L("Error Opening Connection1: %d"), iStatus.Int());
       
   329         SetError(iStatus.Int());
       
   330 
       
   331         return success;
       
   332         }
       
   333 
       
   334     iCommDbPref.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
   335     iCommDbPref.SetBearerSet(KCommDbBearerVirtual);
       
   336     iCommDbPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
   337 
       
   338     iConnection1.Start(iCommDbPref, iStatus);
       
   339 
       
   340 
       
   341     //open socket on interface. 
       
   342     if((iStatus = iSocket1.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection1)) == KErrNone )
       
   343         INFO_PRINTF1(_L("Socket Opened!\n "));
       
   344 
       
   345     User::LeaveIfError( iSocket1.SetOpt( KSoInetEnumInterfaces, KSolInetIfCtrl ) );
       
   346 
       
   347     TProtocolDesc in;
       
   348     User::LeaveIfError( iSocket1.Info( in ) );
       
   349     TInt res = iSocket1.GetOpt( KSoInetNextInterface, KSolInetIfCtrl, info );
       
   350     if (res != KErrNone)
       
   351         {
       
   352         User::Leave( res );
       
   353         }
       
   354     
       
   355     TPckgBuf<TSoInet6InterfaceInfo> next;
       
   356 
       
   357 
       
   358     while (res == KErrNone)
       
   359         {
       
   360         res = iSocket1.GetOpt( KSoInetNextInterface, KSolInetIfCtrl, next );
       
   361         if (res == KErrNone)
       
   362             info = next;
       
   363         //Compare the string with interface name
       
   364         if (info().iName.Mid(1,4).Compare(_L("TunDriver")))
       
   365             //if (info().iName == KIfName)
       
   366             {
       
   367             success = TRUE;
       
   368             break;
       
   369 
       
   370             }
       
   371         else
       
   372             {
       
   373             continue;
       
   374             }
       
   375         }
       
   376 
       
   377     return success;
       
   378 
       
   379 
       
   380     }
       
   381 
       
   382 TInt CTunDriverTestWrapper::StartD3PApp()
       
   383     {
       
   384     TInt err(0);
       
   385     if ((err = p.Create(KDummy3rdPartyApp,KArg)) == KErrNone)
       
   386         {
       
   387         p.Resume();
       
   388         }
       
   389     else
       
   390         {
       
   391         ERR_PRINTF2(_L("Error Opening Dummy3rdPartyApp: %d"), iVTunError);
       
   392         SetError(err);
       
   393         return(err);        
       
   394         }
       
   395     //Wait for Dummy3rdPartyApp to be up and running!
       
   396     User::After(10000000);   //10 Sec
       
   397     return(err);
       
   398     }
       
   399 
       
   400 void CTunDriverTestWrapper::StopD3PApp()
       
   401     {
       
   402     p.Kill(NULL);   //Kill Dummy3rdPartyApp.       
       
   403     }
       
   404 
       
   405 //Gurpreet: RConnection Testcases
       
   406 
       
   407 void CTunDriverTestWrapper::DoRConnTest1_1()
       
   408     {
       
   409     INFO_PRINTF1(_L("********************************************"));
       
   410     INFO_PRINTF1(_L("           Test: DoRConnTest1_1             "));
       
   411     INFO_PRINTF1(_L("********************************************"));
       
   412 
       
   413     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
   414         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
   415     else
       
   416         {
       
   417         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
   418         SetError(iStatus.Int());
       
   419         return;
       
   420         }
       
   421 
       
   422     if((iStatus = iConnection.Open(iSocketServ /*, KAfInet*/)) == KErrNone )
       
   423         INFO_PRINTF1(_L("Connection opened. \n"));
       
   424     else
       
   425         {
       
   426         ERR_PRINTF2(_L("Error Opening Connection: %d"), iStatus.Int());
       
   427         SetError(iStatus.Int());
       
   428         return;
       
   429         }
       
   430 
       
   431     iCommDbPref.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
   432     iCommDbPref.SetBearerSet(KCommDbBearerVirtual);
       
   433     iCommDbPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
   434 
       
   435     iVTunError = iConnection.Start(iCommDbPref);
       
   436     //User::WaitForRequest(iStatus);
       
   437     INFO_PRINTF2(_L("Starting Connection %d.\n"), iVTunError);
       
   438 
       
   439     if(iVTunError!= KErrNone)
       
   440         {
       
   441         SetError(iVTunError);
       
   442         }
       
   443     iConnection.Close();
       
   444     iSocketServ.Close();    
       
   445     }
       
   446 
       
   447 void CTunDriverTestWrapper::DoRConnTest1_2()
       
   448     {
       
   449     INFO_PRINTF1(_L("********************************************"));
       
   450     INFO_PRINTF1(_L("           Test: DoRConnTest1_2             "));
       
   451     INFO_PRINTF1(_L("********************************************"));
       
   452 
       
   453     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
   454         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
   455     else
       
   456         {
       
   457         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
   458         SetError(iStatus.Int());
       
   459         return;
       
   460         }
       
   461 
       
   462     if((iStatus = iConnection.Open(iSocketServ /*, KAfInet*/)) == KErrNone )
       
   463         INFO_PRINTF1(_L("Connection opened. \n"));
       
   464     else
       
   465         {
       
   466         ERR_PRINTF2(_L("Error Opening Connection: %d"), iStatus.Int());
       
   467         SetError(iStatus.Int());
       
   468         return;
       
   469         }
       
   470 
       
   471     iCommDbPref.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
   472     iCommDbPref.SetBearerSet(KCommDbBearerVirtual);
       
   473     iCommDbPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
   474 
       
   475     iConnection.Start(iCommDbPref, iStatus);
       
   476     User::WaitForRequest(iStatus);
       
   477     INFO_PRINTF2(_L("Starting Connection %d.\n"), iStatus.Int());
       
   478 
       
   479     iConnection.Close();
       
   480     iSocketServ.Close();    
       
   481     }
       
   482 
       
   483 void CTunDriverTestWrapper::DoRConnTest1_3(const TDesC& aSection)
       
   484     {
       
   485     INFO_PRINTF1(_L("*********************************************"));
       
   486     INFO_PRINTF1(_L("           Test: DoRConnTest1_3             "));
       
   487     INFO_PRINTF1(_L("********************************************"));
       
   488 
       
   489     //start the dummy3rdpartyapp
       
   490     if ((iVTunError = StartD3PApp()) != KErrNone)
       
   491         {
       
   492         return;
       
   493         }
       
   494 
       
   495     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
   496         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
   497     else
       
   498         {
       
   499         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
   500         SetError(iStatus.Int());
       
   501         StopD3PApp();
       
   502         return;
       
   503         }
       
   504 
       
   505     if((iStatus = iConnection.Open(iSocketServ)) == KErrNone )
       
   506         INFO_PRINTF1(_L("Connection opened. \n"));
       
   507     else
       
   508         {
       
   509         ERR_PRINTF2(_L("Error Opening Connection: %d"), iStatus.Int());
       
   510         SetError(iStatus.Int());
       
   511         StopD3PApp();
       
   512         return;
       
   513         }
       
   514 
       
   515     iCommDbPref.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
   516     iCommDbPref.SetBearerSet(KCommDbBearerVirtual);
       
   517     iCommDbPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
   518 
       
   519     iConnection.Start(iCommDbPref, iStatus);
       
   520 		User::WaitForRequest(iStatus);
       
   521 		if (iStatus.Int() != KErrNone)
       
   522 			{
       
   523 			ERR_PRINTF2(_L("Error starting connection: %d"), iStatus.Int());	
       
   524 			SetError(iStatus.Int());
       
   525 			StopD3PApp();
       
   526 			return;
       
   527 			}
       
   528 	INFO_PRINTF1(_L("Connection started!\n "));
       
   529 
       
   530     //open socket on interface. 
       
   531     if((iStatus = iSocket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection)) == KErrNone )
       
   532         INFO_PRINTF1(_L("Socket Opened!\n "));
       
   533     else   // (iStatus!=KErrNone)
       
   534         {
       
   535         ERR_PRINTF2(_L("Error Opening Socket: %d"), iStatus.Int());    
       
   536         SetError(iStatus.Int());
       
   537         StopD3PApp();
       
   538         return;
       
   539         }
       
   540 
       
   541     iSendBuf.Zero();
       
   542     iSendBuf = (TText8*)"Nokia sues Apple!";
       
   543 
       
   544     // Get destination address from config file   
       
   545     TPtrC ptrToReadFromConfig(KNameDefault);
       
   546     TBool returnValue = GetStringFromConfig(aSection, KDestAddr, ptrToReadFromConfig);
       
   547     if (!returnValue)
       
   548         {
       
   549         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
   550         SetError(KErrUnknown);
       
   551         StopD3PApp();
       
   552         return;
       
   553         }
       
   554     //set destination IP ie. server
       
   555     TInt err = iDestAddr.Input(ptrToReadFromConfig);   
       
   556     if(err != KErrNone)
       
   557         {
       
   558         INFO_PRINTF2(KInetInputFail, err);
       
   559         SetError(err);
       
   560         StopD3PApp();
       
   561         return;
       
   562         }
       
   563 
       
   564     returnValue = GetIntFromConfig(aSection, KDestPort, iDestPort);
       
   565     iDestAddr.SetPort(iDestPort);
       
   566 
       
   567     //bind local port to socket
       
   568     err = iSocket.SetLocalPort(7776);
       
   569 
       
   570     //send data to server
       
   571     iSocket.SendTo(iSendBuf, iDestAddr, NULL, iStatus);
       
   572     User::WaitForRequest(iStatus);
       
   573     if( iStatus == KErrNone)
       
   574         INFO_PRINTF1(_L("\nData Sent"));
       
   575     else
       
   576 	   {
       
   577         ERR_PRINTF1(_L("\nData sending failed"));
       
   578         SetError(iStatus.Int());
       
   579         iSocket.Close();
       
   580         iConnection.Close();
       
   581         iSocketServ.Close();
       
   582         StopD3PApp();
       
   583         return;
       
   584   	    }
       
   585 
       
   586     iRecvBuf.Zero();
       
   587     iSocket.RecvFrom(iRecvBuf, iDestAddr, NULL, iStatus);
       
   588     User::WaitForRequest(iStatus);
       
   589     TBuf<128> temp;
       
   590     if( iStatus == KErrNone)
       
   591         {
       
   592         INFO_PRINTF1(_L("\nData Received : "));
       
   593         temp.Copy(iRecvBuf);
       
   594         INFO_PRINTF1(temp);
       
   595         INFO_PRINTF1(_L("\n"));
       
   596         }
       
   597     else
       
   598         {
       
   599         ERR_PRINTF1(_L("\nData receive failed"));  
       
   600         SetError(iStatus.Int());
       
   601         }
       
   602     iSocket.Close();
       
   603     iSocketServ.Close();
       
   604     
       
   605     StopD3PApp();
       
   606     
       
   607     }
       
   608 
       
   609 void CTunDriverTestWrapper::DoRConnTest1_4(const TDesC& aSection)
       
   610     {
       
   611     INFO_PRINTF1(_L("*********************************************"));
       
   612     INFO_PRINTF1(_L("           Test: DoRConnTest1_4             "));
       
   613     INFO_PRINTF1(_L("********************************************"));
       
   614 
       
   615 		//start the dummy3rdpartyapp
       
   616     if ((iVTunError = StartD3PApp()) != KErrNone)
       
   617         {
       
   618         return;
       
   619         }
       
   620 
       
   621     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
   622         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
   623     else
       
   624         {
       
   625         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
   626         SetError(iStatus.Int());
       
   627         return;
       
   628         }
       
   629 
       
   630     if((iStatus = iConnection.Open(iSocketServ)) == KErrNone )
       
   631         INFO_PRINTF1(_L("Connection opened. \n"));
       
   632     else
       
   633         {
       
   634         ERR_PRINTF2(_L("Error Opening Connection: %d"), iStatus.Int());
       
   635         SetError(iStatus.Int());
       
   636         return;
       
   637         }
       
   638 
       
   639     iCommDbPref.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
   640     iCommDbPref.SetBearerSet(KCommDbBearerVirtual);
       
   641     iCommDbPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
   642 
       
   643     iConnection.Start(iCommDbPref, iStatus);
       
   644     User::WaitForRequest(iStatus);
       
   645     if (iStatus.Int() != KErrNone)
       
   646 		{
       
   647 		ERR_PRINTF2(_L("Error starting connection: %d"), iStatus.Int());	
       
   648 		SetError(iStatus.Int());
       
   649 		iSocketServ.Close();
       
   650 		StopD3PApp();
       
   651 		return;
       
   652 		}
       
   653     INFO_PRINTF2(_L("Starting Connection %d.\n"), iStatus.Int());
       
   654 
       
   655     //open socket on interface. 
       
   656 
       
   657     if((iStatus = iSocket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection)) == KErrNone )
       
   658         INFO_PRINTF1(_L("Socket Opened!\n "));
       
   659     else   // (iStatus!=KErrNone)
       
   660         {
       
   661         ERR_PRINTF2(_L("Error Opening Socket: %d"), iStatus.Int());    
       
   662         SetError(iStatus.Int());
       
   663         iConnection.Close();
       
   664         iSocketServ.Close();
       
   665         StopD3PApp();
       
   666         return;
       
   667         }
       
   668 
       
   669     iSendBuf.Zero();
       
   670     iSendBuf = (TText8*)"Nokia sues Apple!";
       
   671 
       
   672     // Get destination address from config file  
       
   673     TPtrC ptrToReadFromConfig(KNameDefault);
       
   674     TBool returnValue = GetStringFromConfig(aSection, KDestAddr, ptrToReadFromConfig);
       
   675     if (!returnValue)
       
   676         {
       
   677         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
   678         SetError(KErrUnknown);
       
   679         iSocket.Close();
       
   680         iConnection.Close();
       
   681         iSocketServ.Close();
       
   682         StopD3PApp();
       
   683         return;
       
   684         }
       
   685     //set destination IP ie. server
       
   686     TInt err = iDestAddr.Input(ptrToReadFromConfig);   
       
   687     if(err != KErrNone)
       
   688         {
       
   689         INFO_PRINTF2(KInetInputFail, err);
       
   690         SetError(err);
       
   691         iSocket.Close();
       
   692         iConnection.Close();
       
   693         iSocketServ.Close();
       
   694         StopD3PApp();
       
   695         return;
       
   696         }
       
   697 
       
   698     returnValue = GetIntFromConfig(aSection, KDestPort, iDestPort);
       
   699     iDestAddr.SetPort(iDestPort);
       
   700 
       
   701     //bind local port to socket
       
   702     err = iSocket.SetLocalPort(LOCAL_PORT);
       
   703 
       
   704     //send data to server
       
   705     iSocket.SendTo(iSendBuf, iDestAddr, NULL, iStatus);
       
   706     User::WaitForRequest(iStatus);
       
   707     if( iStatus == KErrNone)
       
   708         INFO_PRINTF1(_L("\nData Sent"));
       
   709     else
       
   710 	   {
       
   711         ERR_PRINTF1(_L("\nData sending failed"));
       
   712         SetError(iStatus.Int());
       
   713         iSocket.Close();
       
   714         iConnection.Close();
       
   715         iSocketServ.Close();
       
   716         StopD3PApp();
       
   717         return;
       
   718   	    }
       
   719 
       
   720     iRecvBuf.Zero();
       
   721     iSocket.RecvFrom(iRecvBuf, iDestAddr, NULL, iStatus);
       
   722     User::WaitForRequest(iStatus);
       
   723     TBuf<128> temp;
       
   724     if( iStatus == KErrNone)
       
   725         {
       
   726         INFO_PRINTF1(_L("\nData Received : "));
       
   727         temp.Copy(iRecvBuf);
       
   728         INFO_PRINTF1(temp);
       
   729         INFO_PRINTF1(_L("\n"));
       
   730         }
       
   731     else
       
   732         {
       
   733         ERR_PRINTF1(_L("\nData receive failed"));
       
   734         SetError(iStatus.Int());
       
   735         }
       
   736     iSocket.Close();
       
   737     iConnection.Close();
       
   738     iSocketServ.Close();    
       
   739 
       
   740     StopD3PApp();
       
   741     
       
   742     }
       
   743 
       
   744 void CTunDriverTestWrapper::DoRConnTest1_5(const TDesC& aSection)
       
   745     {
       
   746     INFO_PRINTF1(_L("*********************************************"));
       
   747     INFO_PRINTF1(_L("           Test: DoRConnTest1_5             "));
       
   748     INFO_PRINTF1(_L("********************************************"));
       
   749 
       
   750     //start the dummy3rdpartyapp
       
   751     if ((iVTunError = StartD3PApp()) != KErrNone)
       
   752         {
       
   753         return;
       
   754         }
       
   755 
       
   756     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
   757         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
   758     else
       
   759         {
       
   760         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
   761         SetError(iStatus.Int());
       
   762         StopD3PApp();
       
   763         return;
       
   764         }
       
   765     if((iStatus = iConnection.Open(iSocketServ)) == KErrNone )
       
   766         INFO_PRINTF1(_L("Connection opened. \n"));
       
   767     else
       
   768         {
       
   769         ERR_PRINTF2(_L("Error Opening Connection: %d"), iStatus.Int());
       
   770         SetError(iStatus.Int());
       
   771         StopD3PApp();
       
   772         return;
       
   773         }
       
   774 
       
   775     iCommDbPref.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
   776     iCommDbPref.SetBearerSet(KCommDbBearerVirtual);
       
   777     iCommDbPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
   778 
       
   779     iConnection.Start(iCommDbPref, iStatus);
       
   780     User::WaitForRequest(iStatus);
       
   781     if (iStatus.Int() != KErrNone)
       
   782 		{
       
   783 		ERR_PRINTF2(_L("Error starting connection: %d"), iStatus.Int());	
       
   784 		SetError(iStatus.Int());
       
   785 		iSocketServ.Close();
       
   786 		StopD3PApp();
       
   787 		return;
       
   788 		}
       
   789     INFO_PRINTF2(_L("Starting Connection %d.\n"), iStatus.Int());
       
   790 
       
   791     //open socket on interface. 
       
   792     if((iStatus = iSocket1.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection)) == KErrNone )
       
   793         INFO_PRINTF1(_L("Socket1 Opened!\n "));
       
   794     else   // (iStatus!=KErrNone)
       
   795         {
       
   796         ERR_PRINTF2(_L("Error Opening Socket1: %d"), iStatus.Int());    
       
   797         SetError(iStatus.Int());
       
   798         iConnection.Close();
       
   799         iSocketServ.Close();
       
   800         StopD3PApp();
       
   801         return;
       
   802         }
       
   803 
       
   804     if((iStatus = iSocket2.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection)) == KErrNone )
       
   805         INFO_PRINTF1(_L("Socket2 Opened!\n "));
       
   806     else   // (iStatus!=KErrNone)
       
   807         {
       
   808         ERR_PRINTF2(_L("Error Opening Socket2: %d"), iStatus.Int());    
       
   809         SetError(iStatus.Int());
       
   810         iConnection.Close();
       
   811         iSocketServ.Close();
       
   812         StopD3PApp();
       
   813         return;
       
   814         }
       
   815 
       
   816     // Get destination address from config file 
       
   817     TPtrC ptrToReadFromConfig(KNameDefault);
       
   818     TBool returnValue = GetStringFromConfig(aSection, KDestAddr, ptrToReadFromConfig);
       
   819     if (!returnValue)
       
   820         {
       
   821         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
   822         SetError(KErrUnknown);
       
   823         iSocket1.Close();
       
   824         iSocket2.Close();
       
   825         iConnection.Close();
       
   826         iSocketServ.Close();
       
   827         StopD3PApp();
       
   828         return;
       
   829         }
       
   830     //set destination IP ie. server
       
   831     TInt err = iDestAddr.Input(ptrToReadFromConfig);   
       
   832     if(err != KErrNone)
       
   833         {
       
   834         INFO_PRINTF2(KInetInputFail, err);
       
   835         SetError(err);
       
   836         iSocket1.Close();
       
   837         iSocket2.Close();
       
   838         iConnection.Close();
       
   839         iSocketServ.Close();
       
   840         StopD3PApp();
       
   841         return;
       
   842         }
       
   843 
       
   844     returnValue = GetIntFromConfig(aSection, KDestPort, iDestPort);
       
   845     iDestAddr.SetPort(iDestPort);
       
   846 
       
   847     //bind local port to socket
       
   848     err = iSocket1.SetLocalPort(LOCAL_PORT);
       
   849     if(err != KErrNone)
       
   850     	{
       
   851         ERR_PRINTF2(_L("Error Binding Socket1: %d"), err);    
       
   852         SetError(err);
       
   853         iSocket1.Close();
       
   854         iSocket2.Close();
       
   855         iConnection.Close();
       
   856         iSocketServ.Close();
       
   857         StopD3PApp();
       
   858       	}
       
   859     //bind local port to socket
       
   860     err = iSocket2.SetLocalPort(LOCAL_PORT + 1);
       
   861     if(err != KErrNone)
       
   862     	{
       
   863         ERR_PRINTF2(_L("Error Binding Socket2: %d"), err);
       
   864         SetError(err);
       
   865         iSocket1.Close();
       
   866         iSocket2.Close();
       
   867         iConnection.Close();
       
   868         iSocketServ.Close();
       
   869         StopD3PApp();
       
   870       	}
       
   871 
       
   872     iSendBuf.Zero();
       
   873     iSendBuf = (TText8*)"Nokia sues Apple!";//"Sending Data through Socket1!";
       
   874 
       
   875     //send data to server
       
   876     iSocket1.SendTo(iSendBuf, iDestAddr, NULL, iStatus);
       
   877     User::WaitForRequest(iStatus);
       
   878 
       
   879     if( iStatus == KErrNone)
       
   880         INFO_PRINTF1(_L("\nData Sent thru socket1"));
       
   881     else
       
   882     	{
       
   883         ERR_PRINTF1(_L("\nData sending failed"));
       
   884         SetError(iStatus.Int());
       
   885         iSocket1.Close();
       
   886         iSocket2.Close();
       
   887         iConnection.Close();
       
   888         iSocketServ.Close();
       
   889         StopD3PApp();
       
   890       	}
       
   891 
       
   892     iRecvBuf.Zero();
       
   893     iSocket1.RecvFrom(iRecvBuf, iDestAddr, NULL, iStatus);
       
   894     User::WaitForRequest(iStatus);
       
   895     TBuf<128> temp;
       
   896     if( iStatus == KErrNone)
       
   897         {
       
   898         INFO_PRINTF1(_L("\nData Received from Socket1 : "));
       
   899         temp.Copy(iRecvBuf);
       
   900         INFO_PRINTF1(temp);
       
   901         INFO_PRINTF1(_L("\n"));
       
   902         }
       
   903     else
       
   904     	{
       
   905         ERR_PRINTF1(_L("\nData receive failed on Socket1"));  
       
   906         SetError(iStatus.Int());
       
   907         iSocket1.Close();
       
   908         iSocket2.Close();
       
   909         iConnection.Close();
       
   910         iSocketServ.Close();
       
   911         StopD3PApp();
       
   912       	}
       
   913 
       
   914     iSendBuf.Zero();
       
   915     iSendBuf = (TText8*)" Socket2:Nokia sues Apple!";
       
   916     iSocket2.SendTo(iSendBuf, iDestAddr, NULL, iStatus);
       
   917     User::WaitForRequest(iStatus);
       
   918 
       
   919     if( iStatus == KErrNone)
       
   920         INFO_PRINTF1(_L("\nData Sent thru socket2"));
       
   921     else
       
   922 	    {
       
   923 		ERR_PRINTF1(_L("\nData sending failed"));
       
   924 	    SetError(iStatus.Int());
       
   925 	    iSocket1.Close();
       
   926 	    iSocket2.Close();
       
   927 	    iConnection.Close();
       
   928 	    iSocketServ.Close();
       
   929 	    StopD3PApp();
       
   930 	    }
       
   931 
       
   932     iRecvBuf.Zero();
       
   933     iSocket2.RecvFrom(iRecvBuf, iDestAddr, NULL, iStatus);
       
   934     User::WaitForRequest(iStatus);
       
   935     temp.Zero();
       
   936     if( iStatus == KErrNone)
       
   937         {
       
   938         INFO_PRINTF1(_L("\nData Received from Socket2: "));
       
   939         temp.Copy(iRecvBuf);
       
   940         INFO_PRINTF1(temp);
       
   941         INFO_PRINTF1(_L("\n"));
       
   942         }
       
   943     else
       
   944         {
       
   945         ERR_PRINTF1(_L("\nData receive failed on Socket2"));
       
   946         SetError(iStatus.Int());
       
   947         }
       
   948     iSocket1.Close();
       
   949     iSocket2.Close();
       
   950     iConnection.Close();
       
   951     iSocketServ.Close();
       
   952     
       
   953     StopD3PApp();
       
   954     
       
   955     }
       
   956 
       
   957 void CTunDriverTestWrapper::DoRConnTest1_6(const TDesC& aSection)
       
   958     {
       
   959 
       
   960     INFO_PRINTF1(_L("*********************************************"));
       
   961     INFO_PRINTF1(_L("           Test: DoRConnTest1_6              "));
       
   962     INFO_PRINTF1(_L("*********************************************"));
       
   963 
       
   964     //start the dummy3rdpartyapp
       
   965     if ((iVTunError = StartD3PApp()) != KErrNone)
       
   966         {
       
   967         return;
       
   968         }
       
   969 
       
   970     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
   971         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
   972     else
       
   973         {
       
   974         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
   975         SetError(iStatus.Int());
       
   976         StopD3PApp();
       
   977         return;
       
   978         }
       
   979     if((iStatus = iConnection1.Open(iSocketServ /*, KAfInet*/)) == KErrNone )
       
   980         INFO_PRINTF1(_L("Connection1 opened. \n"));
       
   981     else
       
   982         {
       
   983         ERR_PRINTF2(_L("Error Opening Connection1: %d"), iStatus.Int());
       
   984         SetError(iStatus.Int());
       
   985         StopD3PApp();
       
   986         return;
       
   987         }
       
   988 
       
   989     if((iStatus = iConnection2.Open(iSocketServ /*, KAfInet*/)) == KErrNone )
       
   990         INFO_PRINTF1(_L("Connection2 opened. \n"));
       
   991     else
       
   992         {
       
   993         ERR_PRINTF2(_L("Error Opening Connection2: %d"), iStatus.Int());
       
   994         SetError(iStatus.Int());
       
   995         StopD3PApp();
       
   996         return;
       
   997         }
       
   998 
       
   999     iCommDbPref.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
  1000     iCommDbPref.SetBearerSet(KCommDbBearerVirtual);
       
  1001     iCommDbPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
  1002 
       
  1003     iConnection1.Start(iCommDbPref, iStatus);
       
  1004     User::WaitForRequest(iStatus);
       
  1005    	
       
  1006     if(iStatus.Int()!=KErrNone)
       
  1007 	   	{
       
  1008 	   	ERR_PRINTF2(_L("Error starting connection1: %d"), iStatus.Int());	
       
  1009 		SetError(iStatus.Int());
       
  1010 		iSocketServ.Close();
       
  1011 		StopD3PApp();
       
  1012 		return;
       
  1013 	    }
       
  1014 	    INFO_PRINTF2(_L("Starting Connection1 %d.\n"), iStatus.Int());
       
  1015         	
       
  1016 
       
  1017     iConnection2.Start(iCommDbPref, iStatus);
       
  1018     User::WaitForRequest(iStatus);
       
  1019     if(iStatus.Int()!=KErrNone)
       
  1020 	    {
       
  1021 	    ERR_PRINTF2(_L("Error starting connection2: %d"), iStatus.Int());	
       
  1022 		SetError(iStatus.Int());
       
  1023 		iConnection1.Close();
       
  1024 		iSocketServ.Close();
       
  1025 		StopD3PApp();
       
  1026 		return;
       
  1027 	    }
       
  1028 
       
  1029     INFO_PRINTF2(_L("Starting Connection2 %d.\n"), iStatus.Int());
       
  1030 
       
  1031     //open socket on interface. 
       
  1032     if((iStatus = iSocket1.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection1)) == KErrNone )
       
  1033         INFO_PRINTF1(_L("Socket1 Opened!\n "));
       
  1034     else   // (iStatus!=KErrNone)
       
  1035         {
       
  1036         ERR_PRINTF2(_L("Error Opening Socket1: %d"), iStatus.Int());    
       
  1037         SetError(iStatus.Int());
       
  1038         iConnection1.Close();
       
  1039         iConnection2.Close();
       
  1040         iSocketServ.Close();
       
  1041         StopD3PApp();
       
  1042         return;
       
  1043         }
       
  1044     if((iStatus = iSocket2.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection2)) == KErrNone )
       
  1045         INFO_PRINTF1(_L("Socket2 Opened!\n "));
       
  1046     else   // (iStatus!=KErrNone)
       
  1047         {
       
  1048         ERR_PRINTF2(_L("Error Opening Socket2: %d"), iStatus.Int());    
       
  1049         SetError(iStatus.Int());
       
  1050         iSocket1.Close();
       
  1051         iConnection1.Close();
       
  1052         iConnection2.Close();
       
  1053         iSocketServ.Close();
       
  1054         StopD3PApp();
       
  1055         return;
       
  1056         }
       
  1057 
       
  1058     iSendBuf.Zero();
       
  1059     iSendBuf = (TText8*)"Socket1: Nokia sues Apple!";
       
  1060 
       
  1061     // Get destination address from config file    
       
  1062     TPtrC ptrToReadFromConfig(KNameDefault);
       
  1063     TBool returnValue = GetStringFromConfig(aSection, KDestAddr, ptrToReadFromConfig);
       
  1064     if (!returnValue)
       
  1065         {
       
  1066         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
  1067         SetError(KErrUnknown);
       
  1068         iSocket1.Close();
       
  1069         iSocket2.Close();
       
  1070         iConnection1.Close();
       
  1071         iConnection2.Close();
       
  1072         iSocketServ.Close();
       
  1073         StopD3PApp();
       
  1074         return;
       
  1075         }
       
  1076     //set destination IP ie. server
       
  1077     TInt err = iDestAddr.Input(ptrToReadFromConfig);   
       
  1078     if(err != KErrNone)
       
  1079         {
       
  1080         INFO_PRINTF2(KInetInputFail, err);
       
  1081         SetError(err);
       
  1082         iSocket1.Close();
       
  1083         iSocket2.Close();
       
  1084         iConnection1.Close();
       
  1085         iConnection2.Close();
       
  1086         iSocketServ.Close();
       
  1087         StopD3PApp();
       
  1088         return;
       
  1089         }
       
  1090 
       
  1091     returnValue = GetIntFromConfig(aSection, KDestPort, iDestPort);
       
  1092     iDestAddr.SetPort(iDestPort);
       
  1093     //bind local port to socket
       
  1094     err = iSocket1.SetLocalPort(LOCAL_PORT);
       
  1095     if(err != KErrNone)
       
  1096 		{
       
  1097 	    ERR_PRINTF1(_L("Error in setting local port to socket1"));
       
  1098 	    SetError(err);
       
  1099 	    iSocket1.Close();
       
  1100 	    iSocket2.Close();
       
  1101 	    iConnection1.Close();
       
  1102 	    iConnection2.Close();
       
  1103 	    iSocketServ.Close();
       
  1104 	    StopD3PApp();
       
  1105 	    return;
       
  1106 	    }
       
  1107 
       
  1108     err = iSocket2.SetLocalPort(LOCAL_PORT+1);
       
  1109     if(err != KErrNone)
       
  1110 	    {
       
  1111 		ERR_PRINTF1(_L("Error in setting local port to socket1"));
       
  1112 	    SetError(err);
       
  1113 		iSocket1.Close();
       
  1114 	    iSocket2.Close();
       
  1115 	    iConnection1.Close();
       
  1116 	    iConnection2.Close();
       
  1117 	    iSocketServ.Close();
       
  1118 	    StopD3PApp();
       
  1119 	    return;
       
  1120 	    }
       
  1121 	    //send data to server
       
  1122     iSocket1.SendTo(iSendBuf, iDestAddr, NULL, iStatus);
       
  1123     User::WaitForRequest(iStatus);
       
  1124 	  if( iStatus == KErrNone)
       
  1125         INFO_PRINTF1(_L("\nData Sent for socket1"));
       
  1126     else
       
  1127 	    {
       
  1128 	    ERR_PRINTF1(_L("\nData sending failed for socket1"));
       
  1129 		SetError(iStatus.Int());
       
  1130 		iSocket1.Close();
       
  1131 	    iSocket2.Close();
       
  1132 	    iConnection1.Close();
       
  1133 	    iConnection2.Close();
       
  1134 	    iSocketServ.Close();
       
  1135 	    StopD3PApp();
       
  1136 	    return;
       
  1137 	    }
       
  1138 
       
  1139 
       
  1140     iSendBuf.Zero();
       
  1141     iSendBuf = (TText8*)"Socket2: Nokia sues Apple!";
       
  1142     iSocket2.SendTo(iSendBuf, iDestAddr, NULL, iStatus);
       
  1143     User::WaitForRequest(iStatus);
       
  1144     if( iStatus == KErrNone)
       
  1145         INFO_PRINTF1(_L("\nData Sent for socket2"));
       
  1146     else
       
  1147 	    {
       
  1148 	    ERR_PRINTF1(_L("\nData sending failed for socket2"));
       
  1149 		SetError(iStatus.Int());
       
  1150 		iSocket1.Close();
       
  1151 	    iSocket2.Close();
       
  1152 	    iConnection1.Close();
       
  1153 	    iConnection2.Close();
       
  1154 	    iSocketServ.Close();
       
  1155 	    StopD3PApp();
       
  1156       	return;
       
  1157      	}
       
  1158 
       
  1159     iRecvBuf.Zero();
       
  1160     iSocket1.RecvFrom(iRecvBuf, iDestAddr, NULL, iStatus);
       
  1161     User::WaitForRequest(iStatus);
       
  1162     TBuf<128> temp;
       
  1163     if( iStatus == KErrNone)
       
  1164         {
       
  1165         INFO_PRINTF1(_L("\nData Received from Socket1 : "));
       
  1166         temp.Copy(iRecvBuf);
       
  1167         INFO_PRINTF1(temp);
       
  1168         INFO_PRINTF1(_L("\n"));
       
  1169         }
       
  1170     else
       
  1171 	    {
       
  1172   	    ERR_PRINTF1(_L("\nData receive failed on Socket1"));
       
  1173 		SetError(iStatus.Int());
       
  1174 		iSocket1.Close();
       
  1175 	    iSocket2.Close();
       
  1176   	    iConnection1.Close();
       
  1177     	iConnection2.Close();
       
  1178       	iSocketServ.Close();
       
  1179 	    StopD3PApp();
       
  1180   	    return;
       
  1181     	}
       
  1182 
       
  1183 
       
  1184     iSendBuf.Zero();
       
  1185     iSendBuf = (TText8*)"Sending Data through Socket2!";
       
  1186     iSocket2.SendTo(iSendBuf, iDestAddr, NULL, iStatus);
       
  1187     User::WaitForRequest(iStatus);
       
  1188     if( iStatus == KErrNone)
       
  1189         INFO_PRINTF1(_L("\nData Sent thru socket2"));
       
  1190     else
       
  1191 	    {
       
  1192         ERR_PRINTF1(_L("\nData sending failed through socket2"));
       
  1193 		SetError(iStatus.Int());
       
  1194 		iSocket1.Close();
       
  1195 	    iSocket2.Close();
       
  1196   	    iConnection1.Close();
       
  1197     	iConnection2.Close();
       
  1198       	iSocketServ.Close();
       
  1199 	    StopD3PApp();
       
  1200   	    return;
       
  1201     	}
       
  1202 
       
  1203 
       
  1204     iRecvBuf.Zero();
       
  1205     iSocket2.RecvFrom(iRecvBuf, iDestAddr, NULL, iStatus);
       
  1206     User::WaitForRequest(iStatus);
       
  1207     temp.Zero();
       
  1208     if( iStatus == KErrNone)
       
  1209         {
       
  1210         INFO_PRINTF1(_L("\nData Received from Socket2: "));
       
  1211         temp.Copy(iRecvBuf);
       
  1212         INFO_PRINTF1(temp);
       
  1213         INFO_PRINTF1(_L("\n"));
       
  1214         }
       
  1215     else
       
  1216         {
       
  1217         ERR_PRINTF1(_L("\nData receive failed on Socket2"));
       
  1218         SetError(iStatus.Int());
       
  1219         }
       
  1220     iSocket1.Close();
       
  1221     iSocket2.Close();
       
  1222     iConnection1.Close();
       
  1223     iConnection2.Close();
       
  1224     iSocketServ.Close();
       
  1225     StopD3PApp();
       
  1226     }
       
  1227 
       
  1228 //Sockets sending concurrently over same interface but from different socket servers
       
  1229 //(Connection explicitly created)
       
  1230 void CTunDriverTestWrapper::DoRConnTest1_7(const TDesC& aSection)
       
  1231     {
       
  1232     INFO_PRINTF1(_L("*********************************************"));
       
  1233     INFO_PRINTF1(_L("           Test: DoRConnTest1_7              "));
       
  1234     INFO_PRINTF1(_L("*********************************************"));
       
  1235 
       
  1236 	  //start the dummy3rdpartyapp
       
  1237     if ((iVTunError = StartD3PApp()) != KErrNone)
       
  1238         {
       
  1239         return;
       
  1240         }
       
  1241 
       
  1242     if((iStatus = iSocketServ1.Connect()) == KErrNone )
       
  1243         INFO_PRINTF1(_L("Socket Server1 Opened.\n"));
       
  1244     else
       
  1245         {
       
  1246         ERR_PRINTF2(_L("Error Opening Socket Server1: %d"), iStatus.Int());
       
  1247         SetError(iStatus.Int());
       
  1248         return;
       
  1249         }
       
  1250 
       
  1251     if((iStatus = iSocketServ2.Connect()) == KErrNone )
       
  1252         INFO_PRINTF1(_L("Socket Server2 Opened.\n"));
       
  1253     else
       
  1254         {
       
  1255         ERR_PRINTF2(_L("Error Opening Socket Server2: %d"), iStatus.Int());
       
  1256         SetError(iStatus.Int());
       
  1257         iSocketServ1.Close();
       
  1258         StopD3PApp();
       
  1259         return;
       
  1260         }
       
  1261     if((iStatus = iConnection1.Open(iSocketServ1 /*, KAfInet*/)) == KErrNone )
       
  1262         INFO_PRINTF1(_L("Connection1 opened. \n"));
       
  1263     else
       
  1264         {
       
  1265         ERR_PRINTF2(_L("Error Opening Connection1: %d"), iStatus.Int());
       
  1266         SetError(iStatus.Int());
       
  1267         iSocketServ1.Close();
       
  1268         iSocketServ2.Close();
       
  1269         StopD3PApp();
       
  1270         return;
       
  1271         }
       
  1272 
       
  1273     if((iStatus = iConnection2.Open(iSocketServ2 /*, KAfInet*/)) == KErrNone )
       
  1274         INFO_PRINTF1(_L("Connection2 opened. \n"));
       
  1275     else
       
  1276         {
       
  1277         ERR_PRINTF2(_L("Error Opening Connection2: %d"), iStatus.Int());
       
  1278         SetError(iStatus.Int());
       
  1279         iSocketServ1.Close();
       
  1280         iSocketServ2.Close();
       
  1281         StopD3PApp();
       
  1282         return;
       
  1283         }
       
  1284 
       
  1285     iCommDbPref.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
  1286     iCommDbPref.SetBearerSet(KCommDbBearerVirtual);
       
  1287     iCommDbPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
  1288 
       
  1289     iConnection1.Start(iCommDbPref, iStatus);
       
  1290     User::WaitForRequest(iStatus);
       
  1291 	if(iStatus.Int()!=KErrNone)
       
  1292 	    {
       
  1293 	    ERR_PRINTF2(_L("Error starting connection1: %d"), iStatus.Int());	
       
  1294 		SetError(iStatus.Int());
       
  1295 		iSocketServ1.Close();
       
  1296 		iSocketServ2.Close();
       
  1297 		StopD3PApp();
       
  1298 		return;
       
  1299 	    }
       
  1300     INFO_PRINTF2(_L("Starting Connection1 %d.\n"), iStatus.Int());
       
  1301 
       
  1302     iConnection2.Start(iCommDbPref, iStatus);
       
  1303     User::WaitForRequest(iStatus);
       
  1304 	if(iStatus.Int()!=KErrNone)
       
  1305 		{
       
  1306 	    ERR_PRINTF2(_L("Error starting connection2: %d"), iStatus.Int());	
       
  1307 		SetError(iStatus.Int());
       
  1308 		iConnection1.Close();
       
  1309 		iSocketServ1.Close();
       
  1310 		iSocketServ2.Close();
       
  1311 		StopD3PApp();
       
  1312 		return;
       
  1313 	    }
       
  1314     INFO_PRINTF2(_L("Starting Connection2 %d.\n"), iStatus.Int());
       
  1315 
       
  1316     //Enumerate the number of interfaces
       
  1317     iConnection1.EnumerateConnections(iInitNumOfInterfaces);
       
  1318     INFO_PRINTF2(_L("Number of Interfaces: %d!\n "), iInitNumOfInterfaces);
       
  1319 
       
  1320     //open socket on interface. 
       
  1321     if((iStatus = iSocket1.Open(iSocketServ1, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection1)) == KErrNone )
       
  1322         INFO_PRINTF1(_L("Socket1 Opened!\n "));
       
  1323     else   // (iStatus!=KErrNone)
       
  1324         {
       
  1325         ERR_PRINTF2(_L("Error Opening Socket1: %d"), iStatus.Int());    
       
  1326         SetError(iStatus.Int());
       
  1327         iConnection1.Close();
       
  1328         iConnection2.Close();
       
  1329         iSocketServ1.Close();
       
  1330         iSocketServ2.Close();
       
  1331         StopD3PApp();
       
  1332         return;
       
  1333         }
       
  1334     if((iStatus = iSocket2.Open(iSocketServ2, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection2)) == KErrNone )
       
  1335         INFO_PRINTF1(_L("Socket2 Opened!\n "));
       
  1336     else   // (iStatus!=KErrNone)
       
  1337         {
       
  1338         ERR_PRINTF2(_L("Error Opening Socket2: %d"), iStatus.Int());    
       
  1339         SetError(iStatus.Int());
       
  1340         iSocket1.Close();
       
  1341         iConnection1.Close();
       
  1342         iConnection2.Close();
       
  1343         iSocketServ1.Close();
       
  1344         iSocketServ2.Close();
       
  1345         StopD3PApp();
       
  1346         return;
       
  1347         }
       
  1348 
       
  1349     iSendBuf.Zero();
       
  1350     iSendBuf = (TText8*)"Socket1: Nokia sues Apple!";
       
  1351 
       
  1352     // Get destination address from config file   
       
  1353     TPtrC ptrToReadFromConfig(KNameDefault);
       
  1354     TBool returnValue = GetStringFromConfig(aSection, KDestAddr, ptrToReadFromConfig);
       
  1355     if (!returnValue)
       
  1356         {
       
  1357         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
  1358         SetError(KErrUnknown);
       
  1359         iSocket1.Close();
       
  1360         iSocket2.Close();
       
  1361         iConnection1.Close();
       
  1362         iConnection2.Close();
       
  1363         iSocketServ1.Close();
       
  1364         iSocketServ2.Close();
       
  1365         StopD3PApp();
       
  1366         return;
       
  1367         }
       
  1368     //set destination IP ie. server
       
  1369     TInt err = iDestAddr.Input(ptrToReadFromConfig);   
       
  1370     if(err != KErrNone)
       
  1371         {
       
  1372         INFO_PRINTF2(KInetInputFail, err);
       
  1373         SetError(err);
       
  1374         iSocket1.Close();
       
  1375         iSocket2.Close();
       
  1376         iConnection1.Close();
       
  1377         iConnection2.Close();
       
  1378         iSocketServ1.Close();        
       
  1379         iSocketServ2.Close();
       
  1380         StopD3PApp();
       
  1381         return;
       
  1382         }
       
  1383 
       
  1384     returnValue = GetIntFromConfig(aSection, KDestPort, iDestPort);
       
  1385     if (!returnValue)
       
  1386         {
       
  1387         ERR_PRINTF1(_L("Reading config file failed, while reading DestPort"));   
       
  1388         SetError(KErrUnknown);
       
  1389         iSocket1.Close();
       
  1390         iSocket2.Close();
       
  1391         iConnection1.Close();
       
  1392         iConnection2.Close();
       
  1393         iSocketServ1.Close();
       
  1394         iSocketServ2.Close();
       
  1395         StopD3PApp();
       
  1396         return;
       
  1397         }    
       
  1398     iDestAddr.SetPort(iDestPort);
       
  1399     //bind local port to socket
       
  1400     err = iSocket1.SetLocalPort(LOCAL_PORT);
       
  1401 
       
  1402     if(err != KErrNone)
       
  1403 		{
       
  1404 	    ERR_PRINTF1(_L("Error in setting local port to socket1"));
       
  1405 	    SetError(err);
       
  1406 	    iSocket1.Close();
       
  1407 	    iSocket2.Close();
       
  1408 	    iConnection1.Close();
       
  1409 	    iConnection2.Close();
       
  1410 	    iSocketServ1.Close();
       
  1411 	    iSocketServ2.Close();
       
  1412 	    StopD3PApp();
       
  1413 	    return;
       
  1414 	    }
       
  1415 
       
  1416     err = iSocket2.SetLocalPort(LOCAL_PORT+1);
       
  1417     if(err != KErrNone)
       
  1418 		{
       
  1419 		ERR_PRINTF1(_L("Error in setting local port to socket1"));
       
  1420 	    SetError(err);
       
  1421 		iSocket1.Close();
       
  1422 	    iSocket2.Close();
       
  1423 	    iConnection1.Close();
       
  1424 	    iConnection2.Close();
       
  1425 	    iSocketServ1.Close();
       
  1426 	    iSocketServ2.Close();
       
  1427 	    StopD3PApp();
       
  1428 	    return;
       
  1429 	    }
       
  1430     //send data to server
       
  1431     iSocket1.SendTo(iSendBuf, iDestAddr, NULL, iStatus);
       
  1432 		User::WaitForRequest(iStatus);
       
  1433 	  if( iStatus == KErrNone)
       
  1434         INFO_PRINTF1(_L("\nData Sent for socket1"));
       
  1435     else
       
  1436 	    {
       
  1437 	    ERR_PRINTF1(_L("\nData sending failed for socket1"));
       
  1438 		SetError(iStatus.Int());
       
  1439 		iSocket1.Close();
       
  1440 	    iSocket2.Close();
       
  1441 	    iConnection1.Close();
       
  1442 	    iConnection2.Close();
       
  1443 	    iSocketServ1.Close();
       
  1444 	    iSocketServ2.Close();
       
  1445 	    StopD3PApp();
       
  1446 	    return;
       
  1447 	    }
       
  1448     iRecvBuf.Zero();
       
  1449     iSocket1.RecvFrom(iRecvBuf, iDestAddr, NULL, iStatus);
       
  1450     User::WaitForRequest(iStatus);
       
  1451     TBuf<128> temp;
       
  1452     if( iStatus == KErrNone)
       
  1453         {
       
  1454         INFO_PRINTF1(_L("\nData Received from Socket1 : "));
       
  1455         temp.Copy(iRecvBuf);
       
  1456         INFO_PRINTF1(temp);
       
  1457         INFO_PRINTF1(_L("\n"));
       
  1458         }
       
  1459     else
       
  1460     	{
       
  1461         ERR_PRINTF1(_L("\nData receive failed on Socket1"));
       
  1462         SetError(iStatus.Int());
       
  1463         iSocket1.Close();
       
  1464         iSocket2.Close();
       
  1465         iConnection1.Close();
       
  1466         iConnection2.Close();
       
  1467         iSocketServ1.Close();
       
  1468         iSocketServ2.Close();
       
  1469         StopD3PApp();
       
  1470         return;
       
  1471       	}
       
  1472 
       
  1473     iSendBuf.Zero();
       
  1474     iSendBuf = (TText8*)"Socket2: Nokia sues Apple!";
       
  1475     iSocket2.SendTo(iSendBuf, iDestAddr, NULL, iStatus);
       
  1476     User::WaitForRequest(iStatus);
       
  1477     if( iStatus == KErrNone)
       
  1478         INFO_PRINTF1(_L("\nData Sent for socket2"));
       
  1479     else
       
  1480     	{
       
  1481         ERR_PRINTF1(_L("\nData sending failed for socket2"));
       
  1482         SetError(iStatus.Int());
       
  1483         iSocket1.Close();
       
  1484         iSocket2.Close();
       
  1485         iConnection1.Close();
       
  1486         iConnection2.Close();
       
  1487         iSocketServ1.Close();
       
  1488         iSocketServ2.Close();
       
  1489         StopD3PApp();
       
  1490         return;        
       
  1491       	}
       
  1492 
       
  1493 
       
  1494     iRecvBuf.Zero();
       
  1495     User::After(30000);
       
  1496     iSocket2.RecvFrom(iRecvBuf, iDestAddr, NULL, iStatus);
       
  1497     User::WaitForRequest(iStatus);
       
  1498     temp.Zero();
       
  1499     if( iStatus == KErrNone)
       
  1500         {
       
  1501         INFO_PRINTF1(_L("\nData Received from Socket2: "));
       
  1502         temp.Copy(iRecvBuf);
       
  1503         INFO_PRINTF1(temp);
       
  1504         INFO_PRINTF1(_L("\n"));
       
  1505         }
       
  1506     else
       
  1507         {
       
  1508         ERR_PRINTF1(_L("\nData receive failed on Socket2"));
       
  1509         SetError(iStatus.Int());
       
  1510         }
       
  1511 
       
  1512     iSocket1.Close();
       
  1513     iSocket2.Close();
       
  1514     iConnection1.Close();
       
  1515     iConnection2.Close();
       
  1516     iSocketServ1.Close();      
       
  1517     iSocketServ2.Close();
       
  1518     StopD3PApp();
       
  1519     }
       
  1520 
       
  1521 
       
  1522 //Sockets sending from within different socket servers over different interfaces
       
  1523 //(Connection explicitly created)
       
  1524 void CTunDriverTestWrapper::DoRConnTest1_8(const TDesC& aSection)
       
  1525     {
       
  1526     INFO_PRINTF1(_L("*********************************************"));
       
  1527     INFO_PRINTF1(_L("           Test: DoRConnTest1_8             "));
       
  1528     INFO_PRINTF1(_L("*********************************************"));
       
  1529 
       
  1530     //start the dummy3rdpartyapp
       
  1531     if ((iVTunError = StartD3PApp()) != KErrNone)
       
  1532         {
       
  1533         return;
       
  1534         }
       
  1535 
       
  1536     if((iStatus = iSocketServ1.Connect()) == KErrNone )
       
  1537         INFO_PRINTF1(_L("Socket Server1 Opened.\n"));
       
  1538     else
       
  1539         {
       
  1540         ERR_PRINTF2(_L("Error Opening Socket Server1: %d"), iStatus.Int());
       
  1541         SetError(iStatus.Int());
       
  1542         StopD3PApp();
       
  1543         return;
       
  1544         }
       
  1545 
       
  1546     if((iStatus = iSocketServ2.Connect()) == KErrNone )
       
  1547         INFO_PRINTF1(_L("Socket Server2 Opened.\n"));
       
  1548     else
       
  1549         {
       
  1550         ERR_PRINTF2(_L("Error Opening Socket Server2: %d"), iStatus.Int());
       
  1551         SetError(iStatus.Int());
       
  1552         StopD3PApp();
       
  1553         return;
       
  1554         }
       
  1555     if((iStatus = iConnection1.Open(iSocketServ1)) == KErrNone )
       
  1556         INFO_PRINTF1(_L("Connection1 opened. \n"));
       
  1557     else
       
  1558         {
       
  1559         ERR_PRINTF2(_L("Error Opening Connection1: %d"), iStatus.Int());
       
  1560         SetError(iStatus.Int());
       
  1561         StopD3PApp();
       
  1562         return;
       
  1563         }
       
  1564 
       
  1565     if((iStatus = iConnection2.Open(iSocketServ2)) == KErrNone )
       
  1566         INFO_PRINTF1(_L("Connection2 opened. \n"));
       
  1567     else
       
  1568         {
       
  1569         ERR_PRINTF2(_L("Error Opening Connection2: %d"), iStatus.Int());
       
  1570         SetError(iStatus.Int());
       
  1571         StopD3PApp();
       
  1572         return;
       
  1573         }
       
  1574 
       
  1575     iCommDbPref1.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
  1576     iCommDbPref1.SetBearerSet(KCommDbBearerVirtual);
       
  1577     iCommDbPref1.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
  1578 
       
  1579     iConnection1.Start(iCommDbPref1, iStatus);
       
  1580     User::WaitForRequest(iStatus);
       
  1581 	if(iStatus.Int()!=KErrNone)
       
  1582 		{
       
  1583 	    ERR_PRINTF2(_L("Error starting connection1: %d"), iStatus.Int());	
       
  1584 		SetError(iStatus.Int());
       
  1585 		iSocketServ1.Close();
       
  1586 		iSocketServ2.Close();
       
  1587 		StopD3PApp();
       
  1588 		return;
       
  1589 	    }
       
  1590     INFO_PRINTF2(_L("Starting Connection1 %d.\n"), iStatus.Int());
       
  1591 
       
  1592     iCommDbPref2.SetIapId(REAL_IAP);             // Ethernet Interface
       
  1593     iCommDbPref2.SetBearerSet(KCommDbBearerLAN);
       
  1594     iCommDbPref2.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
  1595 
       
  1596     iConnection2.Start(iCommDbPref2, iStatus);
       
  1597     User::WaitForRequest(iStatus);
       
  1598 	if(iStatus.Int()!=KErrNone)
       
  1599 		{
       
  1600 		ERR_PRINTF2(_L("Error starting connection2: %d"), iStatus.Int());	
       
  1601 		SetError(iStatus.Int());
       
  1602 		iSocketServ1.Close();
       
  1603 		iSocketServ2.Close();
       
  1604 		StopD3PApp();
       
  1605 		return;
       
  1606 	    }
       
  1607 
       
  1608     INFO_PRINTF2(_L("Starting Connection2 %d.\n"), iStatus.Int());
       
  1609 
       
  1610     //open socket on interface. 
       
  1611     if((iStatus = iSocket1.Open(iSocketServ1, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection1)) == KErrNone )
       
  1612         INFO_PRINTF1(_L("Socket1 Opened!\n "));
       
  1613     else   // (iStatus!=KErrNone)
       
  1614         {
       
  1615         ERR_PRINTF2(_L("Error Opening Socket1: %d"), iStatus.Int());    
       
  1616         SetError(iStatus.Int());
       
  1617         iConnection1.Close();
       
  1618         iConnection2.Close();
       
  1619         iSocketServ1.Close();
       
  1620         iSocketServ2.Close();
       
  1621         StopD3PApp();
       
  1622         return;
       
  1623         }
       
  1624     if((iStatus = iSocket2.Open(iSocketServ2, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection2)) == KErrNone )
       
  1625         INFO_PRINTF1(_L("Socket1 Opened!\n "));
       
  1626     else   // (iStatus!=KErrNone)
       
  1627         {
       
  1628         ERR_PRINTF2(_L("Error Opening Socket2: %d"), iStatus.Int());    
       
  1629         SetError(iStatus.Int());
       
  1630         iSocket1.Close();
       
  1631 				iConnection1.Close();
       
  1632         iConnection2.Close();
       
  1633         iSocketServ1.Close();
       
  1634         iSocketServ2.Close();
       
  1635         StopD3PApp();
       
  1636         return;
       
  1637         }
       
  1638 
       
  1639     iSendBuf.Zero();
       
  1640     iSendBuf = (TText8*)"Socket1: Nokia sues Apple!";
       
  1641 
       
  1642     // Get destination address from config file   
       
  1643     TPtrC ptrToReadFromConfig(KNameDefault);
       
  1644     TBool returnValue = GetStringFromConfig(aSection, KDestAddr, ptrToReadFromConfig);
       
  1645     if (!returnValue)
       
  1646         {
       
  1647         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
  1648         SetError(KErrUnknown);
       
  1649 		iSocket1.Close();
       
  1650 		iSocket2.Close();
       
  1651 		iConnection1.Close();
       
  1652         iConnection2.Close();
       
  1653         iSocketServ1.Close();
       
  1654         iSocketServ2.Close();
       
  1655         StopD3PApp();
       
  1656         return;
       
  1657         }
       
  1658     //set destination IP ie. server
       
  1659     TInt err = iDestAddr.Input(ptrToReadFromConfig);   
       
  1660     if(err != KErrNone)
       
  1661         {
       
  1662         INFO_PRINTF2(KInetInputFail, err);
       
  1663         SetError(err);
       
  1664         StopD3PApp();
       
  1665         return;
       
  1666         }
       
  1667 
       
  1668     returnValue = GetIntFromConfig(aSection, KDestPort, iDestPort);
       
  1669     iDestAddr.SetPort(iDestPort);
       
  1670     //bind local port to socket
       
  1671     err = iSocket1.SetLocalPort(LOCAL_PORT);
       
  1672     if(err != KErrNone)
       
  1673 	    {
       
  1674 		ERR_PRINTF1(_L("Error in setting local port to socket1"));
       
  1675 	    SetError(err);
       
  1676 		iSocket1.Close();
       
  1677 	    iSocket2.Close();
       
  1678 	    iConnection1.Close();
       
  1679 	    iConnection2.Close();
       
  1680 	    iSocketServ1.Close();
       
  1681 	    iSocketServ2.Close();
       
  1682 	    StopD3PApp();
       
  1683 	    return;
       
  1684 	    }
       
  1685 
       
  1686     //read Real interface ip addr and port from config file
       
  1687     returnValue = GetStringFromConfig(aSection, KRealDestAddr, ptrToReadFromConfig);
       
  1688     if (!returnValue)
       
  1689         {
       
  1690         ERR_PRINTF1(_L("Reading config file failed, while reading RealDestAddr"));   
       
  1691         SetError(KErrUnknown);
       
  1692 		iSocket1.Close();
       
  1693 	    iSocket2.Close();
       
  1694 	    iConnection1.Close();
       
  1695 	    iConnection2.Close();
       
  1696 	    iSocketServ1.Close();
       
  1697 	    iSocketServ2.Close();
       
  1698         StopD3PApp();
       
  1699         return;
       
  1700         }
       
  1701     //set destination IP ie. server
       
  1702     err = iRealDestAddr.Input(ptrToReadFromConfig);   
       
  1703     if(err != KErrNone)
       
  1704         {
       
  1705         INFO_PRINTF2(KInetInputFail, err);
       
  1706         SetError(err);
       
  1707 				iSocket1.Close();
       
  1708 	      iSocket2.Close();
       
  1709 	      iConnection1.Close();
       
  1710 	      iConnection2.Close();
       
  1711 	      iSocketServ1.Close();
       
  1712 	      iSocketServ2.Close();
       
  1713         StopD3PApp();
       
  1714         return;
       
  1715         }
       
  1716 
       
  1717     returnValue = GetIntFromConfig(aSection, KRealDestPort, iRealDestPort);
       
  1718     if (!returnValue)
       
  1719         {
       
  1720         ERR_PRINTF1(_L("Reading config file failed, while reading RealDestAddr"));   
       
  1721         SetError(KErrUnknown);
       
  1722 				iSocket1.Close();
       
  1723 	      iSocket2.Close();
       
  1724 	      iConnection1.Close();
       
  1725 	      iConnection2.Close();
       
  1726 	      iSocketServ1.Close();
       
  1727 	      iSocketServ2.Close();
       
  1728         StopD3PApp();
       
  1729         return;
       
  1730         }
       
  1731     iRealDestAddr.SetPort(iRealDestPort);
       
  1732     //bind local port to socket
       
  1733     //err = iSocket2.SetLocalPort(LOCAL_PORT);
       
  1734     //send data to server
       
  1735     iSocket1.SendTo(iSendBuf, iDestAddr, NULL, iStatus);
       
  1736     User::WaitForRequest(iStatus);
       
  1737     if( iStatus == KErrNone)
       
  1738         INFO_PRINTF1(_L("\nData Sent thru virtual interface"));
       
  1739     else
       
  1740     		{
       
  1741         ERR_PRINTF1(_L("\nData sending failed through virtual interface"));
       
  1742 				SetError(iStatus.Int());
       
  1743 				iSocket1.Close();
       
  1744 	      iSocket2.Close();
       
  1745 	      iConnection1.Close();
       
  1746 	      iConnection2.Close();
       
  1747 	      iSocketServ1.Close();
       
  1748 	      iSocketServ2.Close();
       
  1749         StopD3PApp();
       
  1750         return;
       
  1751       	}
       
  1752 
       
  1753     iRecvBuf.Zero();
       
  1754     iSocket1.RecvFrom(iRecvBuf, iDestAddr, NULL, iStatus);
       
  1755     User::WaitForRequest(iStatus);
       
  1756     TBuf<128> temp;
       
  1757     if( iStatus == KErrNone)
       
  1758         {
       
  1759         INFO_PRINTF1(_L("\nData Received from Socket1 : "));
       
  1760         temp.Copy(iRecvBuf);
       
  1761         INFO_PRINTF1(temp);
       
  1762         INFO_PRINTF1(_L("\n"));
       
  1763         }
       
  1764     else
       
  1765         {
       
  1766         ERR_PRINTF1(_L("\nData receive failed on Socket1"));
       
  1767         SetError(iStatus.Int());
       
  1768 				iSocket1.Close();
       
  1769 	      iSocket2.Close();
       
  1770 	      iConnection1.Close();
       
  1771 	      iConnection2.Close();
       
  1772 	      iSocketServ1.Close();
       
  1773 	      iSocketServ2.Close();
       
  1774         StopD3PApp();
       
  1775         return;
       
  1776         }
       
  1777 
       
  1778     iSendBuf.Zero();
       
  1779     iSendBuf = (TText8*)"Socket2: Nokia sues Apple!";
       
  1780     iSocket2.SendTo(iSendBuf, iRealDestAddr, NULL, iStatus);
       
  1781     User::WaitForRequest(iStatus);
       
  1782     if( iStatus == KErrNone)
       
  1783         INFO_PRINTF1(_L("\nData Sent thru real interface"));
       
  1784     else
       
  1785     		{
       
  1786         ERR_PRINTF1(_L("\nData sending failed through real interface"));
       
  1787         SetError(iStatus.Int());
       
  1788 				iSocket1.Close();
       
  1789 	      iSocket2.Close();
       
  1790 	      iConnection1.Close();
       
  1791 	      iConnection2.Close();
       
  1792 	      iSocketServ1.Close();
       
  1793 	      iSocketServ2.Close();
       
  1794         StopD3PApp();
       
  1795         return;
       
  1796 
       
  1797 				}
       
  1798     iRecvBuf.Zero();
       
  1799     iSocket2.RecvFrom(iRecvBuf, iRealDestAddr, NULL, iStatus);
       
  1800     User::WaitForRequest(iStatus);
       
  1801     temp.Zero();
       
  1802     if( iStatus == KErrNone)
       
  1803         {
       
  1804         INFO_PRINTF1(_L("\nData Received from Socket2: "));
       
  1805         temp.Copy(iRecvBuf);
       
  1806         INFO_PRINTF1(temp);
       
  1807         INFO_PRINTF1(_L("\n"));
       
  1808         }
       
  1809     else
       
  1810         {
       
  1811         ERR_PRINTF1(_L("\nData receive failed on Socket2"));
       
  1812         SetError(iStatus.Int());
       
  1813         }
       
  1814 
       
  1815     iSocket1.Close();
       
  1816     iSocket2.Close();
       
  1817     iConnection1.Close();
       
  1818     iConnection2.Close();
       
  1819     iSocketServ1.Close();      
       
  1820     iSocketServ2.Close();
       
  1821     StopD3PApp();
       
  1822     }
       
  1823 
       
  1824 void CTunDriverTestWrapper::DoRConnTest1_9(const TDesC& aSection)
       
  1825     {
       
  1826     INFO_PRINTF1(_L("*********************************************"));
       
  1827         INFO_PRINTF1(_L("           Test: DoRConnTest1_9             "));
       
  1828         INFO_PRINTF1(_L("********************************************"));
       
  1829 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY
       
  1830     CMDBSession *cmdbSession = CMDBSession::NewL(KCDVersion1_2);
       
  1831 #else
       
  1832     CMDBSession *cmdbSession = CMDBSession::NewL(KCDVersion1_1);
       
  1833 #endif
       
  1834     CleanupStack::PushL(cmdbSession); 
       
  1835 
       
  1836     CCDIAPRecord *iapRecord = (CCDIAPRecord*)CCDRecordBase::RecordFactoryL(KCDTIdIAPRecord);
       
  1837     CleanupStack::PushL(iapRecord);
       
  1838 
       
  1839     iapRecord->SetRecordId(14);
       
  1840 
       
  1841     iapRecord->LoadL(*cmdbSession);
       
  1842 
       
  1843     //iapRecord->iServiceType;
       
  1844     TUint recid = iapRecord->iService;
       
  1845     CCDLANServiceRecord *lanRecord = (CCDLANServiceRecord*)CCDRecordBase::RecordFactoryL(KCDTIdLANServiceRecord);
       
  1846     CleanupStack::PushL(lanRecord);
       
  1847 
       
  1848     lanRecord->SetRecordId(recid);
       
  1849 
       
  1850     lanRecord->LoadL(*cmdbSession);
       
  1851 
       
  1852     // Get gateway address from config file  
       
  1853     TPtrC ptrToReadFromConfig(KNameDefault);
       
  1854     TBool returnValue = GetStringFromConfig(aSection, KGatewayAddr, ptrToReadFromConfig);
       
  1855     if (!returnValue)
       
  1856         {
       
  1857         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
  1858         SetError(KErrUnknown);
       
  1859         return;
       
  1860         }
       
  1861 
       
  1862     // Create address
       
  1863     TInetAddr gwAddr;
       
  1864     TInt err = gwAddr.Input(ptrToReadFromConfig);   
       
  1865     if(err != KErrNone)
       
  1866         {
       
  1867         INFO_PRINTF2(KInetInputFail, err);
       
  1868         SetError(err);
       
  1869         return;
       
  1870         }
       
  1871     TPtrC displayIpAddr(lanRecord->iIpAddr);
       
  1872     //INFO_PRINTF2(_L("lanRecord ipAddr is %S"), &displayIpAddr); 
       
  1873 
       
  1874     TPtrC ipGateway(_L("10.1.1.100"));
       
  1875     //TPtrC ipGateway(ptrToReadFromConfig);
       
  1876     lanRecord->iIpGateway.SetMaxLengthL(ipGateway.Length());
       
  1877     lanRecord->iIpGateway = ipGateway;
       
  1878 
       
  1879 
       
  1880     // Get gateway address from config file         
       
  1881     returnValue = GetStringFromConfig(aSection, KIpAddr, ptrToReadFromConfig);
       
  1882     if (!returnValue)
       
  1883         {
       
  1884         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
  1885         SetError(KErrUnknown);
       
  1886         return;
       
  1887         }
       
  1888     //TPtrC ipAddr(_L("10.1.1.100"));
       
  1889     TPtrC ipAddr(ptrToReadFromConfig);
       
  1890     lanRecord->iIpAddr.SetMaxLengthL(ipAddr.Length());
       
  1891     lanRecord->iIpAddr = ipAddr;
       
  1892 
       
  1893     TRAPD(modifyErr, lanRecord->ModifyL(*cmdbSession));
       
  1894     INFO_PRINTF2(_L("lanRecord ModifyL result was %d.  Should be 0"), modifyErr);
       
  1895 
       
  1896     TPtrC displayIpAddr2(lanRecord->iIpAddr);
       
  1897     INFO_PRINTF2(_L("lanRecord ipAddr is %S"), &displayIpAddr2);    
       
  1898     CleanupStack::PopAndDestroy(lanRecord);
       
  1899     CleanupStack::PopAndDestroy(iapRecord);
       
  1900     CleanupStack::PopAndDestroy(cmdbSession);
       
  1901 
       
  1902 
       
  1903     }
       
  1904 
       
  1905 //Ensure that Close() effectively pulls down the interface
       
  1906 //when no other subsessions are associated with it.
       
  1907 void CTunDriverTestWrapper::DoRConnTest1_10(const TDesC& aSection)
       
  1908     {
       
  1909     INFO_PRINTF1(_L("*********************************************"));
       
  1910     INFO_PRINTF1(_L("           Test: DoRConnTest1_10             "));
       
  1911     INFO_PRINTF1(_L("********************************************"));
       
  1912 
       
  1913     //start the dummy3rdpartyapp
       
  1914     if ((iVTunError = StartD3PApp()) != KErrNone)
       
  1915         {
       
  1916         return;
       
  1917         }
       
  1918 
       
  1919     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
  1920         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
  1921     else
       
  1922         {
       
  1923         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
  1924         SetError(iStatus.Int());
       
  1925         StopD3PApp();
       
  1926         return;
       
  1927         }
       
  1928     if((iStatus = iConnection.Open(iSocketServ /*, KAfInet*/)) == KErrNone )
       
  1929         INFO_PRINTF1(_L("Connection opened. \n"));
       
  1930     else
       
  1931         {
       
  1932         ERR_PRINTF2(_L("Error Opening Connection: %d"), iStatus.Int());
       
  1933         SetError(iStatus.Int());
       
  1934         StopD3PApp();
       
  1935         return;
       
  1936         }
       
  1937 
       
  1938     iCommDbPref.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
  1939     iCommDbPref.SetBearerSet(KCommDbBearerVirtual);
       
  1940     iCommDbPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
  1941 
       
  1942     iConnection.Start(iCommDbPref, iStatus);
       
  1943     User::WaitForRequest(iStatus);
       
  1944     if (iStatus.Int() != KErrNone)
       
  1945 				{
       
  1946 				ERR_PRINTF2(_L("Error starting connection: %d"), iStatus.Int());	
       
  1947 				SetError(iStatus.Int());
       
  1948 				iSocketServ.Close();
       
  1949 				StopD3PApp();
       
  1950 				return;
       
  1951 				}
       
  1952     INFO_PRINTF2(_L("Starting Connection %d.\n"), iStatus.Int());
       
  1953 
       
  1954     //Enumerate the number of interfaces
       
  1955     iConnection.EnumerateConnections(iInitNumOfInterfaces);
       
  1956     INFO_PRINTF2(_L("Number of Interfaces: %d!\n "), iInitNumOfInterfaces);
       
  1957 
       
  1958     //open socket on interface. 
       
  1959     if((iStatus = iSocket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection)) == KErrNone )
       
  1960         INFO_PRINTF1(_L("Socket Opened!\n "));
       
  1961     else   // (iStatus!=KErrNone)
       
  1962         {
       
  1963         ERR_PRINTF2(_L("Error Opening Socket: %d"), iStatus.Int());    
       
  1964         SetError(iStatus.Int());
       
  1965         iConnection.Close();
       
  1966         iSocketServ.Close();
       
  1967         StopD3PApp();
       
  1968         return;
       
  1969         }
       
  1970 
       
  1971     iSendBuf.Zero();
       
  1972     iSendBuf = (TText8*)"Nokia sues Apple!";
       
  1973 
       
  1974     // Get destination address from config file  
       
  1975     TPtrC ptrToReadFromConfig(KNameDefault);
       
  1976     TBool returnValue = GetStringFromConfig(aSection, KDestAddr, ptrToReadFromConfig);
       
  1977     if (!returnValue)
       
  1978         {
       
  1979         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
  1980         SetError(KErrUnknown);
       
  1981         iSocket.Close();
       
  1982         iConnection.Close();
       
  1983         iSocketServ.Close();
       
  1984         StopD3PApp();
       
  1985         return;
       
  1986         }
       
  1987     //set destination IP ie. server
       
  1988     TInt err = iDestAddr.Input(ptrToReadFromConfig);   
       
  1989     if(err != KErrNone)
       
  1990         {
       
  1991         INFO_PRINTF2(KInetInputFail, err);
       
  1992         SetError(err);
       
  1993         iSocket.Close();
       
  1994         iConnection.Close();
       
  1995         iSocketServ.Close();
       
  1996         StopD3PApp();
       
  1997         return;
       
  1998         }
       
  1999 
       
  2000     returnValue = GetIntFromConfig(aSection, KDestPort, iDestPort);
       
  2001     if (!returnValue)
       
  2002         {
       
  2003         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
  2004         SetError(KErrUnknown);
       
  2005         iSocket.Close();
       
  2006         iConnection.Close();
       
  2007         iSocketServ.Close();
       
  2008         StopD3PApp();
       
  2009         return;
       
  2010         }
       
  2011 
       
  2012     iDestAddr.SetPort(iDestPort);
       
  2013     //bind local port to socket
       
  2014     err = iSocket.SetLocalPort(LOCAL_PORT);
       
  2015     if (err != KErrNone)
       
  2016         {
       
  2017         ERR_PRINTF1(_L("Error setting local port"));   
       
  2018         SetError(err);
       
  2019         iSocket.Close();
       
  2020         iConnection.Close();
       
  2021         iSocketServ.Close();
       
  2022         StopD3PApp();
       
  2023         return;
       
  2024         }
       
  2025 
       
  2026     //send data to server
       
  2027     iSocket.SendTo(iSendBuf, iDestAddr, NULL, iStatus);
       
  2028     User::WaitForRequest(iStatus);
       
  2029     if( iStatus == KErrNone)
       
  2030         INFO_PRINTF1(_L("\nData Sent"));
       
  2031     else
       
  2032     		{
       
  2033         ERR_PRINTF1(_L("\nData sending failed"));
       
  2034         SetError(iStatus.Int());
       
  2035         iSocket.Close();
       
  2036         iConnection.Close();
       
  2037         iSocketServ.Close();
       
  2038         StopD3PApp();
       
  2039         return;
       
  2040 				}
       
  2041     
       
  2042     iRecvBuf.Zero();
       
  2043     iSocket.RecvFrom(iRecvBuf, iDestAddr, NULL, iStatus);
       
  2044     User::WaitForRequest(iStatus);
       
  2045     TBuf<128> temp;
       
  2046     if( iStatus == KErrNone)
       
  2047         {
       
  2048         INFO_PRINTF1(_L("\nData Received : "));
       
  2049         temp.Copy(iRecvBuf);
       
  2050         INFO_PRINTF1(temp);
       
  2051         INFO_PRINTF1(_L("\n"));
       
  2052         }
       
  2053     else
       
  2054         {
       
  2055         ERR_PRINTF1(_L("\nData receive failed."));
       
  2056         SetError(iStatus.Int());
       
  2057         }  
       
  2058 
       
  2059     iSocket.Close();
       
  2060     iConnection.Close();
       
  2061     iSocketServ.Close();
       
  2062     
       
  2063     StopD3PApp();
       
  2064     
       
  2065     }
       
  2066 
       
  2067 //Ensure that Close() does not pull down the interface when there are other 
       
  2068 //connections associated with it.
       
  2069 void CTunDriverTestWrapper::DoRConnTest1_11()
       
  2070     {
       
  2071     INFO_PRINTF1(_L("*********************************************"));
       
  2072     INFO_PRINTF1(_L("           Test: DoRConnTest1_11             "));
       
  2073     INFO_PRINTF1(_L("*********************************************"));
       
  2074 
       
  2075     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
  2076         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
  2077     else
       
  2078         {
       
  2079         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
  2080         SetError(iStatus.Int());
       
  2081         return;
       
  2082         }
       
  2083 
       
  2084     if((iStatus = iConnection1.Open(iSocketServ /*, KAfInet*/)) == KErrNone )
       
  2085         INFO_PRINTF1(_L("Connection1 opened. \n"));
       
  2086     else
       
  2087         {
       
  2088         ERR_PRINTF2(_L("Error Opening Connection1: %d"), iStatus.Int());
       
  2089         SetError(iStatus.Int());
       
  2090         return;
       
  2091         }
       
  2092 
       
  2093     if((iStatus = iConnection2.Open(iSocketServ /*, KAfInet*/)) == KErrNone )
       
  2094         INFO_PRINTF1(_L("Connection2 opened. \n"));
       
  2095     else
       
  2096         {
       
  2097         ERR_PRINTF2(_L("Error Opening Connection2: %d"), iStatus.Int());
       
  2098         SetError(iStatus.Int());
       
  2099         return;
       
  2100         }
       
  2101 
       
  2102     iCommDbPref.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
  2103     iCommDbPref.SetBearerSet(KCommDbBearerVirtual);
       
  2104     iCommDbPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
  2105 
       
  2106     iConnection1.Start(iCommDbPref, iStatus);
       
  2107     User::WaitForRequest(iStatus);
       
  2108 		if(iStatus.Int()!=KErrNone)
       
  2109 	    	{
       
  2110 	    	ERR_PRINTF2(_L("Error starting connection1: %d"), iStatus.Int());	
       
  2111 				SetError(iStatus.Int());
       
  2112 				iSocketServ.Close();
       
  2113 				return;
       
  2114 	    	}
       
  2115     INFO_PRINTF2(_L("Starting Connection1 %d.\n"), iStatus.Int());
       
  2116     iConnection2.Start(iCommDbPref, iStatus);
       
  2117     User::WaitForRequest(iStatus);
       
  2118 		if(iStatus.Int()!=KErrNone)
       
  2119 	    	{
       
  2120 	    	ERR_PRINTF2(_L("Error starting connection2: %d"), iStatus.Int());	
       
  2121 				SetError(iStatus.Int());
       
  2122 				iSocketServ.Close();
       
  2123 				return;
       
  2124 	    	}
       
  2125     INFO_PRINTF2(_L("Starting Connection2 %d.\n"), iStatus.Int());
       
  2126 
       
  2127     //Enumerate the number of interfaces
       
  2128     iConnection2.EnumerateConnections(iInitNumOfInterfaces);
       
  2129     INFO_PRINTF2(_L("Number of Interfaces: %d!\n "), iInitNumOfInterfaces);
       
  2130 
       
  2131     iConnection1.Close();
       
  2132     User::After(30000);
       
  2133 
       
  2134     iConnection2.EnumerateConnections(iCurNumOfInterfaces);
       
  2135     INFO_PRINTF2(_L("Number of Interfaces after closing 1st Connection: %d!\n "), iCurNumOfInterfaces);
       
  2136     if(iCurNumOfInterfaces == iInitNumOfInterfaces)
       
  2137     		INFO_PRINTF1(_L("Number of interfaces before and after closing the connection is same"));
       
  2138  		else
       
  2139         {
       
  2140         ERR_PRINTF1(_L("ERROR: More Number of Interfaces than expected."));    
       
  2141         SetError(KErrGeneral);
       
  2142         return;
       
  2143         }
       
  2144     iConnection2.Stop();
       
  2145     User::After(30000);
       
  2146     iSocketServ.Close();      
       
  2147     }
       
  2148 
       
  2149 //Ensure that Stop() pulls down the interface when there are no subsessions
       
  2150 //other than the connection associated with it.
       
  2151 void CTunDriverTestWrapper::DoRConnTest1_12()
       
  2152     {
       
  2153 
       
  2154     INFO_PRINTF1(_L("*********************************************"));
       
  2155     INFO_PRINTF1(_L("           Test: DoRConnTest1_12             "));
       
  2156     INFO_PRINTF1(_L("*********************************************"));
       
  2157 
       
  2158     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
  2159         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
  2160     else
       
  2161         {
       
  2162         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
  2163         SetError(iStatus.Int());
       
  2164         return;
       
  2165         }
       
  2166 
       
  2167     if((iStatus = iConnection.Open(iSocketServ /*, KAfInet*/)) == KErrNone )
       
  2168         INFO_PRINTF1(_L("Connection opened. \n"));
       
  2169     else
       
  2170         {
       
  2171         ERR_PRINTF2(_L("Error Opening Connection: %d"), iStatus.Int());
       
  2172         SetError(iStatus.Int());
       
  2173         return;
       
  2174         }
       
  2175 
       
  2176 		iCommDbPref1.SetIapId(REAL_IAP);             // Virtual Interface
       
  2177     iCommDbPref1.SetBearerSet(KCommDbBearerLAN);
       
  2178     iCommDbPref1.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
  2179     
       
  2180     iConnection.Start(iCommDbPref1,iStatus);
       
  2181     User::WaitForRequest(iStatus);
       
  2182 		if(iStatus.Int()!=KErrNone)
       
  2183 	    	{
       
  2184 	    	ERR_PRINTF2(_L("Error starting connection: %d"), iStatus.Int());	
       
  2185 				SetError(iStatus.Int());
       
  2186 				iSocketServ.Close();
       
  2187 				return;
       
  2188 	    	}
       
  2189     INFO_PRINTF2(_L("Starting Connection %d.\n"), iStatus.Int());
       
  2190 
       
  2191     //Enumerate the number of interfaces
       
  2192     iConnection.EnumerateConnections(iInitNumOfInterfaces);
       
  2193     INFO_PRINTF2(_L("Number of initial Interfaces: %d!\n "), iInitNumOfInterfaces);
       
  2194 
       
  2195     TInt MyErr = iConnection.Stop();
       
  2196     User::After(30000);
       
  2197     iConnection.EnumerateConnections(iCurNumOfInterfaces);
       
  2198     INFO_PRINTF2(_L("Number of Interfaces after stopping the connection: %d!\n "), iCurNumOfInterfaces);
       
  2199     if(iCurNumOfInterfaces>=iInitNumOfInterfaces)
       
  2200         {
       
  2201         ERR_PRINTF1(_L("ERROR: More Number of Interfaces than expected."));    
       
  2202         SetError(KErrGeneral);
       
  2203         return;
       
  2204         }
       
  2205     iSocketServ.Close();      
       
  2206     }
       
  2207 
       
  2208 //Ensure that Stop() pulls down the interface when 
       
  2209 //there are sockets associated with it.
       
  2210 void CTunDriverTestWrapper::DoRConnTest1_13(const TDesC& aSection)
       
  2211     {
       
  2212     INFO_PRINTF1(_L("*********************************************"));
       
  2213     INFO_PRINTF1(_L("           Test: DoRConnTest1_13             "));
       
  2214     INFO_PRINTF1(_L("*********************************************"));
       
  2215 
       
  2216     //start the dummy3rdpartyapp
       
  2217     if ((iVTunError = StartD3PApp()) != KErrNone)
       
  2218         {
       
  2219         return;
       
  2220         }
       
  2221 
       
  2222     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
  2223         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
  2224     else
       
  2225         {
       
  2226         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
  2227         SetError(iStatus.Int());
       
  2228         StopD3PApp();
       
  2229         return;
       
  2230         }
       
  2231 
       
  2232     if((iStatus = iConnection.Open(iSocketServ /*, KAfInet*/)) == KErrNone )
       
  2233         INFO_PRINTF1(_L("Connection opened. \n"));
       
  2234     else
       
  2235         {
       
  2236         ERR_PRINTF2(_L("Error Opening Connection: %d"), iStatus.Int());
       
  2237         SetError(iStatus.Int());
       
  2238         StopD3PApp();
       
  2239         return;
       
  2240         }
       
  2241 
       
  2242     iCommDbPref.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
  2243     iCommDbPref.SetBearerSet(KCommDbBearerVirtual);
       
  2244     iCommDbPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
  2245     iConnection.Start(iCommDbPref, iStatus);
       
  2246     User::WaitForRequest(iStatus);
       
  2247 		if(iStatus.Int()!=KErrNone)
       
  2248 	    	{
       
  2249 	    	ERR_PRINTF2(_L("Error starting connection: %d"), iStatus.Int());	
       
  2250 				SetError(iStatus.Int());
       
  2251 				iSocketServ.Close();
       
  2252 				StopD3PApp();
       
  2253 				return;
       
  2254 	    	}
       
  2255     INFO_PRINTF2(_L("Starting Connection %d.\n"), iStatus.Int());
       
  2256 
       
  2257     //open socket on interface. 
       
  2258     if((iStatus = iSocket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection)) == KErrNone )
       
  2259         INFO_PRINTF1(_L("Socket Opened!\n "));
       
  2260     else   // (iStatus!=KErrNone)
       
  2261         {
       
  2262         ERR_PRINTF2(_L("Error Opening Socket: %d"), iStatus.Int());    
       
  2263         SetError(iStatus.Int());
       
  2264         iConnection.Close();
       
  2265         iSocketServ.Close();
       
  2266         StopD3PApp();
       
  2267         return;
       
  2268         }
       
  2269 
       
  2270     iSendBuf.Zero();
       
  2271     iSendBuf = (TText8*)"Sending Data through Socket!";
       
  2272 
       
  2273     // Get destination address from config file   
       
  2274     TPtrC ptrToReadFromConfig(KNameDefault);
       
  2275     TBool returnValue = GetStringFromConfig(aSection, KDestAddr, ptrToReadFromConfig);
       
  2276     if (!returnValue)
       
  2277         {
       
  2278         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
  2279         SetError(KErrUnknown);
       
  2280         iSocket.Close();
       
  2281         iConnection.Close();
       
  2282         iSocketServ.Close();
       
  2283         StopD3PApp();
       
  2284         return;
       
  2285         }
       
  2286     //set destination IP ie. server
       
  2287     TInt err = iDestAddr.Input(ptrToReadFromConfig);   
       
  2288     if(err != KErrNone)
       
  2289         {
       
  2290         INFO_PRINTF2(KInetInputFail, err);
       
  2291         SetError(err);
       
  2292         iSocket.Close();
       
  2293         iConnection.Close();
       
  2294         iSocketServ.Close();
       
  2295         StopD3PApp();
       
  2296         return;
       
  2297         }
       
  2298 
       
  2299     returnValue = GetIntFromConfig(aSection, KDestPort, iDestPort);
       
  2300     if (!returnValue)
       
  2301         {
       
  2302         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
  2303         SetError(KErrUnknown);
       
  2304         iSocket.Close();
       
  2305         iConnection.Close();
       
  2306         iSocketServ.Close();
       
  2307         StopD3PApp();
       
  2308         return;
       
  2309         }
       
  2310 
       
  2311     iDestAddr.SetPort(iDestPort);
       
  2312     //bind local port to socket
       
  2313     err = iSocket.SetLocalPort(LOCAL_PORT);
       
  2314     if (err != KErrNone)
       
  2315         {
       
  2316         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
  2317         SetError(err);
       
  2318         iSocket.Close();
       
  2319         iConnection.Close();
       
  2320         iSocketServ.Close();
       
  2321         StopD3PApp();
       
  2322         return;
       
  2323         }
       
  2324 
       
  2325     //send data to server
       
  2326     iSocket.SendTo(iSendBuf, iDestAddr, NULL, iStatus);
       
  2327     User::WaitForRequest(iStatus);
       
  2328     if( iStatus == KErrNone)
       
  2329         INFO_PRINTF1(_L("\nData Sent"));
       
  2330     else
       
  2331     		{
       
  2332         ERR_PRINTF1(_L("\nData sending failed"));
       
  2333         SetError(iStatus.Int());
       
  2334         iSocket.Close();
       
  2335         iConnection.Close();
       
  2336         iSocketServ.Close();
       
  2337         StopD3PApp();
       
  2338         return;        
       
  2339       	}
       
  2340 
       
  2341     iRecvBuf.Zero();
       
  2342     iSocket.RecvFrom(iRecvBuf, iDestAddr, NULL, iStatus);
       
  2343     User::WaitForRequest(iStatus);
       
  2344     TBuf<128> temp;
       
  2345     if( iStatus == KErrNone)
       
  2346         {
       
  2347         INFO_PRINTF1(_L("\nData Received from Socket : "));
       
  2348         temp.Copy(iRecvBuf);
       
  2349         INFO_PRINTF1(temp);
       
  2350         INFO_PRINTF1(_L("\n"));
       
  2351         }
       
  2352     else
       
  2353         {
       
  2354         ERR_PRINTF1(_L("\nData receive failed on Socket"));
       
  2355         SetError(iStatus.Int());
       
  2356         iConnection.Close();
       
  2357         iSocketServ.Close();
       
  2358         StopD3PApp();
       
  2359         return;        
       
  2360         }  
       
  2361 
       
  2362 
       
  2363     //Enumerate the number of interfaces
       
  2364     iConnection.EnumerateConnections(iInitNumOfInterfaces);
       
  2365     INFO_PRINTF2(_L("Number of Init Interfaces: %d!\n "), iInitNumOfInterfaces);
       
  2366 
       
  2367     iConnection.Stop();
       
  2368     User::After(30000);
       
  2369     iConnection.EnumerateConnections(iCurNumOfInterfaces);
       
  2370     INFO_PRINTF2(_L("Number of Interfaces after Stopping the interface: %d!\n "), iCurNumOfInterfaces);
       
  2371     if(iCurNumOfInterfaces>=iInitNumOfInterfaces)
       
  2372         {
       
  2373         ERR_PRINTF1(_L("ERROR: More Number of Interfaces than expected."));    
       
  2374         SetError(KErrGeneral);
       
  2375         }
       
  2376     iSocket.Close();
       
  2377     iSocketServ.Close();    
       
  2378     StopD3PApp();
       
  2379     }
       
  2380 
       
  2381 //Stop() a connection and ensure that other connections over 
       
  2382 //other interfaces are unaffected. 
       
  2383 void CTunDriverTestWrapper::DoRConnTest1_14(const TDesC& aSection)
       
  2384     {
       
  2385 
       
  2386     INFO_PRINTF1(_L("*********************************************"));
       
  2387     INFO_PRINTF1(_L("           Test: DoRConnTest1_14             "));
       
  2388     INFO_PRINTF1(_L("*********************************************"));
       
  2389 
       
  2390     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
  2391         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
  2392     else
       
  2393         {
       
  2394         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
  2395         SetError(iStatus.Int());
       
  2396         
       
  2397         return;
       
  2398         }
       
  2399 
       
  2400     if((iStatus = iConnection1.Open(iSocketServ /*, KAfInet*/)) == KErrNone )
       
  2401         INFO_PRINTF1(_L("Connection1 opened. \n"));
       
  2402     else
       
  2403         {
       
  2404         ERR_PRINTF2(_L("Error Opening Connection1: %d"), iStatus.Int());
       
  2405         SetError(iStatus.Int());
       
  2406         
       
  2407         return;
       
  2408         }
       
  2409     iCommDbPref1.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
  2410     iCommDbPref1.SetBearerSet(KCommDbBearerVirtual);
       
  2411     iCommDbPref1.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
  2412     iConnection1.Start(iCommDbPref1,iStatus);
       
  2413     User::WaitForRequest(iStatus);
       
  2414 		if(iStatus.Int()!=KErrNone)
       
  2415 	    	{
       
  2416 	    	ERR_PRINTF2(_L("Error starting connection1: %d"), iStatus.Int());	
       
  2417 				SetError(iStatus.Int());
       
  2418 				iSocketServ.Close();
       
  2419 				return;
       
  2420 	    	}
       
  2421     INFO_PRINTF2(_L("Starting Connection1 %d.\n"), iStatus.Int());
       
  2422 
       
  2423     if((iStatus = iConnection2.Open(iSocketServ /*, KAfInet*/)) == KErrNone )
       
  2424         INFO_PRINTF1(_L("Connection2 opened. \n"));
       
  2425     else
       
  2426         {
       
  2427         ERR_PRINTF2(_L("Error Opening Connection2: %d"), iStatus.Int());
       
  2428         SetError(iStatus.Int());
       
  2429         iSocketServ.Close();
       
  2430         return;
       
  2431         }
       
  2432     iCommDbPref2.SetIapId(REAL_IAP);             // Virtual Interface
       
  2433     iCommDbPref2.SetBearerSet(KCommDbBearerLAN);
       
  2434     iCommDbPref2.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
  2435     iConnection2.Start(iCommDbPref2, iStatus);
       
  2436     User::WaitForRequest(iStatus);
       
  2437 		if(iStatus.Int()!=KErrNone)
       
  2438 	    	{
       
  2439 	    	ERR_PRINTF2(_L("Error starting connection2: %d"), iStatus.Int());	
       
  2440 				SetError(iStatus.Int());
       
  2441 				iConnection1.Close();
       
  2442 				iSocketServ.Close();
       
  2443 				return;
       
  2444 	    	}
       
  2445     INFO_PRINTF2(_L("Starting Connection2 %d.\n"), iStatus.Int());
       
  2446     //enumnerate the interfaces
       
  2447     iConnection1.EnumerateConnections(iInitNumOfInterfaces);
       
  2448     INFO_PRINTF2(_L("Number of Initial Interfaces: %d!\n "), iInitNumOfInterfaces);
       
  2449 
       
  2450     //Shutdown the first connection.
       
  2451     iConnection1.Stop();
       
  2452  
       
  2453     //enumnerate the interfaces again.
       
  2454     iConnection2.EnumerateConnections(iCurNumOfInterfaces);
       
  2455     INFO_PRINTF2(_L("Number of Interfaces after Stopping the VTun Interface: %d!\n "), iCurNumOfInterfaces);
       
  2456     if(iCurNumOfInterfaces>iInitNumOfInterfaces)
       
  2457         {
       
  2458         ERR_PRINTF1(_L("ERROR: More Number of Interfaces than expected."));    
       
  2459         SetError(KErrGeneral);
       
  2460         iConnection2.Close();
       
  2461         iSocketServ.Close();
       
  2462         return;
       
  2463         }
       
  2464     //open udp socket over second connection and send data over it.
       
  2465 
       
  2466     if((iStatus = iSocket.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp, iConnection2)) == KErrNone )
       
  2467         INFO_PRINTF1(_L("Socket Opened!\n "));
       
  2468     else   // (iStatus!=KErrNone)
       
  2469         {
       
  2470         ERR_PRINTF2(_L("Error Opening Socket: %d"), iStatus.Int());    
       
  2471         SetError(iStatus.Int());
       
  2472         iConnection2.Close();
       
  2473         iSocketServ.Close();
       
  2474         return;
       
  2475         }
       
  2476 
       
  2477     iSendBuf.Zero();
       
  2478     iSendBuf = (TText8*)"Sending Data through Socket!";
       
  2479 
       
  2480     // Get destination address from config file     
       
  2481     TPtrC ptrToReadFromConfig(KNameDefault);
       
  2482     TBool returnValue = GetStringFromConfig(aSection, KRealDestAddr, ptrToReadFromConfig);
       
  2483     if (!returnValue)
       
  2484         {
       
  2485         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
  2486         SetError(KErrUnknown);
       
  2487         iSocket.Close();
       
  2488         iConnection2.Close();
       
  2489         iSocketServ.Close();
       
  2490         return;
       
  2491         }
       
  2492     //set destination IP ie. server
       
  2493     TInt err = iRealDestAddr.Input(ptrToReadFromConfig);   
       
  2494     if(err != KErrNone)
       
  2495         {
       
  2496         INFO_PRINTF2(KInetInputFail, err);
       
  2497         SetError(err);
       
  2498         iConnection2.Close();
       
  2499         iSocketServ.Close();       
       
  2500         return;
       
  2501         }
       
  2502 
       
  2503     returnValue = GetIntFromConfig(aSection, KRealDestPort, iRealDestPort);
       
  2504     iRealDestAddr.SetPort(iRealDestPort);
       
  2505     //bind local port to socket
       
  2506     err = iSocket.SetLocalPort(LOCAL_PORT);
       
  2507 
       
  2508     //send data to server
       
  2509     iSocket.SendTo(iSendBuf, iRealDestAddr, NULL, iStatus);
       
  2510     User::WaitForRequest(iStatus);
       
  2511     if( iStatus == KErrNone)
       
  2512         INFO_PRINTF1(_L("\nData Sent"));
       
  2513     else
       
  2514     		{
       
  2515       	ERR_PRINTF2(_L("\nData sending failed: %d"), iStatus.Int());
       
  2516       	SetError(iStatus.Int());
       
  2517       	iSocket.Close();
       
  2518       	iConnection2.Close();
       
  2519       	iSocketServ.Close();
       
  2520       	return;
       
  2521       	}
       
  2522 
       
  2523     iRecvBuf.Zero();
       
  2524     iSocket.RecvFrom(iRecvBuf, iDestAddr, NULL, iStatus);
       
  2525     User::WaitForRequest(iStatus);
       
  2526     TBuf<128> temp;
       
  2527     if( iStatus == KErrNone )
       
  2528         {
       
  2529         INFO_PRINTF1(_L("\nData Received from Socket : "));
       
  2530         temp.Copy(iRecvBuf);
       
  2531         INFO_PRINTF1(temp);
       
  2532         INFO_PRINTF1(_L("\n"));
       
  2533         }
       
  2534     else
       
  2535         {
       
  2536         ERR_PRINTF1(_L("\nData receive failed on Socket"));
       
  2537         SetError(iStatus.Int());
       
  2538         }  
       
  2539 
       
  2540     iSocket.Close();
       
  2541     iConnection2.Close();
       
  2542     iSocketServ.Close();
       
  2543         
       
  2544     }
       
  2545 
       
  2546 void CTunDriverTestWrapper::DoRConnTest1_15()
       
  2547     {
       
  2548     INFO_PRINTF1(_L("*********************************************"));
       
  2549     INFO_PRINTF1(_L("           Test: DoRConnTest1_15             "));
       
  2550     INFO_PRINTF1(_L("********************************************"));
       
  2551 
       
  2552     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
  2553         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
  2554     else
       
  2555         {
       
  2556         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
  2557         SetError(iStatus.Int());
       
  2558         return;
       
  2559         }
       
  2560 
       
  2561     iSocket.Open(iSocketServ,_L("tun"));
       
  2562 
       
  2563     TUint localPort = 6789;
       
  2564     TPckgC <TUint> portPckg (localPort);
       
  2565 
       
  2566     //Positive case
       
  2567 
       
  2568     if((iStatus = iSocket.SetOpt(KSolInetIp,KSoTunnelPort,portPckg)) == KErrNone )
       
  2569         INFO_PRINTF1(_L("Socket SetOpt Positive scenario succesful Opened.\n"));
       
  2570     else
       
  2571         {
       
  2572         ERR_PRINTF2(_L("Error in Socket SetOpt: %d"), iStatus.Int());
       
  2573         SetError(iStatus.Int());
       
  2574         iSocket.Close();
       
  2575         iSocketServ.Close();
       
  2576         return;
       
  2577         }
       
  2578 
       
  2579     //Negative Case #1
       
  2580     if((iStatus = iSocket.SetOpt(KSolInetUdp,KSoTunnelPort,portPckg)) == KErrNotSupported )
       
  2581         INFO_PRINTF1(_L("Socket SetOpt Negative scenario #1 succesful Opened.\n"));
       
  2582     else
       
  2583         {
       
  2584         ERR_PRINTF2(_L("Error in Socket SetOpt: %d"), iStatus.Int());
       
  2585         SetError(iStatus.Int());
       
  2586         iSocket.Close();
       
  2587         iSocketServ.Close();
       
  2588         return;
       
  2589         }
       
  2590 
       
  2591     //Negative Case #2 
       
  2592     if((iStatus = iSocket.SetOpt(KSolInetUdp,KSoNoSourceAddressSelect,portPckg)) == KErrNotSupported )
       
  2593         INFO_PRINTF1(_L("Socket SetOpt Negative scenario #2 succesful Opened.\n"));
       
  2594     else
       
  2595         {
       
  2596         ERR_PRINTF2(_L("Error in Socket SetOpt: %d"), iStatus.Int());
       
  2597         SetError(iStatus.Int());
       
  2598         }
       
  2599 
       
  2600     iSocket.Close();
       
  2601     iSocketServ.Close();
       
  2602    }
       
  2603 
       
  2604 void CTunDriverTestWrapper::DoRConnTest1_16(const TDesC& aSection)
       
  2605     {
       
  2606     INFO_PRINTF1(_L("*********************************************"));
       
  2607     INFO_PRINTF1(_L("           Test: DoRConnTest1_16            "));
       
  2608     INFO_PRINTF1(_L("********************************************"));
       
  2609 
       
  2610 
       
  2611     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
  2612         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
  2613     else
       
  2614         {
       
  2615         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
  2616         SetError(iStatus.Int());
       
  2617         return;
       
  2618         }
       
  2619     if((iStatus = iConnection.Open(iSocketServ)) == KErrNone )
       
  2620         INFO_PRINTF1(_L("Connection opened. \n"));
       
  2621     else
       
  2622         {
       
  2623         ERR_PRINTF2(_L("Error Opening Connection: %d"), iStatus.Int());
       
  2624         SetError(iStatus.Int());
       
  2625         iSocketServ.Close();
       
  2626         return;
       
  2627         }
       
  2628 
       
  2629     iCommDbPref.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
  2630     iCommDbPref.SetBearerSet(KCommDbBearerVirtual);
       
  2631     iCommDbPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
  2632 
       
  2633     iConnection.Start(iCommDbPref, iStatus);
       
  2634     User::WaitForRequest(iStatus);
       
  2635 		if(iStatus.Int()!=KErrNone)
       
  2636 	    	{
       
  2637 	    	ERR_PRINTF2(_L("Error starting connection: %d"), iStatus.Int());	
       
  2638 				SetError(iStatus.Int());
       
  2639 				iSocketServ.Close();
       
  2640 				return;
       
  2641 	    	}
       
  2642     INFO_PRINTF2(_L("Starting Connection %d.\n"), iStatus.Int());
       
  2643 
       
  2644     iSocket.Open(iSocketServ,_L("tun"));
       
  2645 
       
  2646     TUint localPort = 6789;
       
  2647     TPckgC <TUint> portPckg (localPort);
       
  2648 
       
  2649     //Setting the Port Number into the Stack
       
  2650     if((iStatus = iSocket.SetOpt(KSolInetIp,KSoTunnelPort,portPckg)) == KErrNone )
       
  2651         INFO_PRINTF1(_L("Socket SetOpt Positive scenario succesful Opened.\n"));
       
  2652     else
       
  2653         {
       
  2654         ERR_PRINTF2(_L("Error in Socket SetOpt: %d"), iStatus.Int());
       
  2655         SetError(iStatus.Int());
       
  2656         iConnection.Close();
       
  2657         iSocketServ.Close();
       
  2658         return;
       
  2659         }
       
  2660 
       
  2661     // Get destination address from config file 
       
  2662     TPtrC ptrToReadFromConfig(KNameDefault);
       
  2663     TBool returnValue = GetStringFromConfig(aSection, KDestAddr, ptrToReadFromConfig);
       
  2664     if (!returnValue)
       
  2665         {
       
  2666         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
  2667         SetError(KErrUnknown);
       
  2668 				iSocket.Close();
       
  2669         iConnection.Close();
       
  2670         iSocketServ.Close();
       
  2671         return;
       
  2672         }
       
  2673     
       
  2674     //set destination IP 
       
  2675     TInt err = iDestAddr.Input(ptrToReadFromConfig);   
       
  2676     if(err != KErrNone)
       
  2677         {
       
  2678         INFO_PRINTF2(KInetInputFail, err);
       
  2679         SetError(err);
       
  2680 				iSocket.Close();
       
  2681         iConnection.Close();
       
  2682         iSocketServ.Close();
       
  2683         return;
       
  2684         }
       
  2685 
       
  2686     //set the destination port
       
  2687     returnValue = GetIntFromConfig(aSection, KDestPort, iDestPort);
       
  2688     if (!returnValue)
       
  2689         {
       
  2690         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
  2691         SetError(KErrUnknown);
       
  2692 				iSocket.Close();
       
  2693         iConnection.Close();
       
  2694         iSocketServ.Close();
       
  2695         return;
       
  2696         }
       
  2697     
       
  2698     iDestAddr.SetPort(iDestPort);
       
  2699 
       
  2700     //retrieve the local address
       
  2701     TInetAddr iLocalAddr;
       
  2702     returnValue = GetStringFromConfig(aSection, KLocalAddr, ptrToReadFromConfig);
       
  2703     if (!returnValue)
       
  2704         {
       
  2705         ERR_PRINTF1(_L("Reading config file failed, while reading LocalAddr"));   
       
  2706         SetError(KErrUnknown);
       
  2707 				iSocket.Close();
       
  2708         iConnection.Close();
       
  2709         iSocketServ.Close();
       
  2710         return;
       
  2711         }
       
  2712     
       
  2713     err = iLocalAddr.Input(ptrToReadFromConfig);   
       
  2714     if(err != KErrNone)
       
  2715         {
       
  2716         INFO_PRINTF2(KInetInputFail, err);
       
  2717         SetError(err);
       
  2718 				iSocket.Close();
       
  2719         iConnection.Close();
       
  2720         iSocketServ.Close();
       
  2721         return;
       
  2722         }
       
  2723 
       
  2724     iLocalAddr.SetPort(LOCAL_PORT);
       
  2725 
       
  2726     //open socket on interface.
       
  2727     if((iStatus = iSocket1.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetUdp,iConnection)) == KErrNone )
       
  2728         INFO_PRINTF1(_L("Socket1 Opened!\n "));
       
  2729     else   // (iStatus!=KErrNone)
       
  2730         {
       
  2731         ERR_PRINTF2(_L("Error Opening Socket1: %d"), iStatus.Int());    
       
  2732         SetError(iStatus.Int());
       
  2733 				iSocket.Close();
       
  2734         iConnection.Close();
       
  2735         iSocketServ.Close();
       
  2736         return;
       
  2737         }
       
  2738 
       
  2739     //open socket on interface.
       
  2740     if((iStatus = iSocket2.Open(iSocketServ, KAfInet, KSockDatagram, KProtocolInetIcmp,iConnection)) == KErrNone )
       
  2741         INFO_PRINTF1(_L("Socket2 Opened!\n "));
       
  2742     else   // (iStatus!=KErrNone)
       
  2743         {
       
  2744         ERR_PRINTF2(_L("Error Opening Socket2: %d"), iStatus.Int());    
       
  2745         SetError(iStatus.Int());
       
  2746 				iSocket.Close();
       
  2747 				iSocket1.Close();
       
  2748         iConnection.Close();
       
  2749         iSocketServ.Close();
       
  2750         return;
       
  2751         }
       
  2752 
       
  2753     err = iSocket1.Bind(iLocalAddr);
       
  2754     if(err != KErrNone)
       
  2755     		{
       
  2756         ERR_PRINTF2(_L("Error Binding Socket1: %d"), err);    
       
  2757         SetError(iStatus.Int());
       
  2758  				iSocket.Close();
       
  2759  				iSocket1.Close();
       
  2760  				iSocket2.Close();
       
  2761         iConnection.Close();
       
  2762         iSocketServ.Close();
       
  2763 				return;
       
  2764 				}
       
  2765 
       
  2766     TInt iLocalPort;
       
  2767     returnValue = GetIntFromConfig(aSection, KLocalPort, iLocalPort);
       
  2768     iLocalAddr.SetPort(iLocalPort);
       
  2769 
       
  2770     err = iSocket2.Bind(iLocalAddr);
       
  2771     if(err != KErrNone)
       
  2772 				{
       
  2773         ERR_PRINTF2(_L("Error Binding Socket2: %d"), err);
       
  2774         SetError(iStatus.Int());
       
  2775  				iSocket.Close();
       
  2776  				iSocket1.Close();
       
  2777  				iSocket2.Close();
       
  2778         iConnection.Close();
       
  2779         iSocketServ.Close();
       
  2780 				return;
       
  2781 				}
       
  2782 
       
  2783     iSendBuf.Zero();
       
  2784     iSendBuf = (TText8*)"Test Message";
       
  2785 
       
  2786     //send data to server using the local port = LOCAL_PORT (7777)
       
  2787     iSocket1.SendTo(iSendBuf, iDestAddr, NULL, iStatus);
       
  2788     User::WaitForRequest(iStatus);
       
  2789 
       
  2790     if( iStatus == KErrNone)
       
  2791         INFO_PRINTF1(_L("\nData Sent thru socket1"));
       
  2792     else
       
  2793 				{
       
  2794         ERR_PRINTF1(_L("\nData sending failed"));
       
  2795         SetError(iStatus.Int());
       
  2796  				iSocket.Close();
       
  2797  				iSocket1.Close();
       
  2798  				iSocket2.Close();
       
  2799         iConnection.Close();
       
  2800         iSocketServ.Close();
       
  2801 				return;
       
  2802 				}
       
  2803 				
       
  2804     //send data to server using the local port configured in ini file 
       
  2805     iSocket2.SendTo(iSendBuf, iDestAddr, NULL, iStatus);
       
  2806     User::WaitForRequest(iStatus);
       
  2807 
       
  2808     if( iStatus == KErrNone)
       
  2809         INFO_PRINTF1(_L("\nData Sent thru socket2"));
       
  2810     else
       
  2811     		{
       
  2812         ERR_PRINTF1(_L("\nData sending failed"));
       
  2813         SetError(iStatus.Int());
       
  2814       	}
       
  2815 		iSocket.Close();
       
  2816     iSocket1.Close();
       
  2817     iSocket2.Close();
       
  2818     iConnection.Close();
       
  2819     iSocketServ.Close();
       
  2820     }
       
  2821 
       
  2822 //Simple TCP data transfer.
       
  2823 void CTunDriverTestWrapper::DoRConnTest1_17(const TDesC& aSection)
       
  2824     {
       
  2825     INFO_PRINTF1(_L("*********************************************"));
       
  2826     INFO_PRINTF1(_L("           Test: DoRConnTest1_17             "));
       
  2827     INFO_PRINTF1(_L("*********************************************"));
       
  2828 
       
  2829     //start the dummy3rdpartyapp
       
  2830     if ((iVTunError = StartD3PApp()) != KErrNone)
       
  2831         {
       
  2832         return;
       
  2833         }
       
  2834 
       
  2835     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
  2836         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
  2837     else
       
  2838         {
       
  2839         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
  2840         SetError(iStatus.Int());
       
  2841         StopD3PApp();
       
  2842         return;
       
  2843         }
       
  2844 
       
  2845     if((iStatus = iConnection.Open(iSocketServ /*, KAfInet*/)) == KErrNone )
       
  2846         INFO_PRINTF1(_L("Connection opened. \n"));
       
  2847     else
       
  2848         {
       
  2849         ERR_PRINTF2(_L("Error Opening Connection: %d"), iStatus.Int());
       
  2850         SetError(iStatus.Int());
       
  2851         iSocketServ.Close();
       
  2852         StopD3PApp();
       
  2853         return;
       
  2854         }
       
  2855 
       
  2856     iCommDbPref.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
  2857     iCommDbPref.SetBearerSet(KCommDbBearerVirtual);
       
  2858     iCommDbPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
  2859     iConnection.Start(iCommDbPref, iStatus);
       
  2860     User::WaitForRequest(iStatus);
       
  2861 		if(iStatus.Int()!=KErrNone)
       
  2862 	    	{
       
  2863 	    	ERR_PRINTF2(_L("Error starting connection: %d"), iStatus.Int());	
       
  2864 				SetError(iStatus.Int());
       
  2865 				iSocketServ.Close();
       
  2866 				return;
       
  2867 	    	}
       
  2868     INFO_PRINTF2(_L("Starting Connection %d.\n"), iStatus.Int());
       
  2869 
       
  2870     //open socket on interface. 
       
  2871     if((iStatus = iSocket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp, iConnection)) == KErrNone )
       
  2872         INFO_PRINTF1(_L("Socket Opened!\n "));
       
  2873     else   // (iStatus!=KErrNone)
       
  2874         {
       
  2875         ERR_PRINTF1(_L("Error Opening Socket!"));    
       
  2876         SetError(iStatus.Int());
       
  2877         iConnection.Close();
       
  2878         iSocketServ.Close();
       
  2879         StopD3PApp();
       
  2880         return;
       
  2881         }
       
  2882 
       
  2883     // Get destination address from config file    
       
  2884     TPtrC ptrToReadFromConfig(KNameDefault);
       
  2885     TBool returnValue = GetStringFromConfig(aSection, KDestAddr, ptrToReadFromConfig);
       
  2886     if (!returnValue)
       
  2887         {
       
  2888         ERR_PRINTF1(_L("Reading config file failed, while reading DestAddr"));   
       
  2889         SetError(KErrUnknown);
       
  2890 				iSocket.Close();
       
  2891         iConnection.Close();
       
  2892         iSocketServ.Close();
       
  2893         StopD3PApp();
       
  2894         return;
       
  2895         }
       
  2896     //set destination IP ie. server
       
  2897     TInt err = iDestAddr.Input(ptrToReadFromConfig);   
       
  2898     if(err != KErrNone)
       
  2899         {
       
  2900         INFO_PRINTF2(KInetInputFail, err);
       
  2901         SetError(err);
       
  2902 				iSocket.Close();
       
  2903         iConnection.Close();
       
  2904         iSocketServ.Close();
       
  2905         StopD3PApp();
       
  2906         return;
       
  2907         }
       
  2908 
       
  2909     returnValue = GetIntFromConfig(aSection, KTcpDestPort, iDestPort);
       
  2910     if (!returnValue)
       
  2911         {
       
  2912         ERR_PRINTF1(_L("Reading config file failed, while reading DestPort"));   
       
  2913         SetError(KErrUnknown);
       
  2914 				iSocket.Close();
       
  2915         iConnection.Close();
       
  2916         iSocketServ.Close();
       
  2917         StopD3PApp();
       
  2918         return;
       
  2919         }
       
  2920     iDestAddr.SetPort(iDestPort);
       
  2921     //bind local port to socket
       
  2922     err = iSocket.SetLocalPort(7776);
       
  2923     if (err != KErrNone)
       
  2924         {
       
  2925         ERR_PRINTF1(_L("Error Setting local port"));   
       
  2926         SetError(err);
       
  2927 				iSocket.Close();
       
  2928         iConnection.Close();
       
  2929         iSocketServ.Close();
       
  2930         StopD3PApp();
       
  2931         return;
       
  2932         }
       
  2933 
       
  2934     iSocket.Connect(iDestAddr,iStatus);
       
  2935     User::WaitForRequest(iStatus);
       
  2936     if (iStatus != KErrNone)
       
  2937         {
       
  2938         ERR_PRINTF1(_L("Error Connecting to Server!"));    
       
  2939         SetError(iStatus.Int());
       
  2940 				iSocket.Close();
       
  2941         iConnection.Close();
       
  2942         iSocketServ.Close();
       
  2943         StopD3PApp();
       
  2944         return;
       
  2945         }
       
  2946     else
       
  2947         {
       
  2948         INFO_PRINTF2(_L("tcp Start with = %d\n"), iStatus.Int());
       
  2949         }
       
  2950  	  TBuf8<128> receiveBuffer;
       
  2951     TBuf<128>  temp;
       
  2952 
       
  2953     do
       
  2954         {
       
  2955         TSockXfrLength aLen = 0;
       
  2956         iRecvBuf.FillZ();
       
  2957         iSocket.RecvOneOrMore(receiveBuffer,0,iStatus,aLen);
       
  2958         User::WaitForRequest(iStatus);
       
  2959         temp.Copy(receiveBuffer);
       
  2960 
       
  2961         INFO_PRINTF1(_L("\nData Received from Socket : "));
       
  2962         INFO_PRINTF1(temp);
       
  2963         INFO_PRINTF1(_L("\n"));
       
  2964 
       
  2965         }while(iStatus == KErrNone);      
       
  2966 
       
  2967     //Close the Connection,Socket and socket server.
       
  2968     iSocket.Close();
       
  2969     iConnection.Stop();
       
  2970     iSocketServ.Close();
       
  2971     StopD3PApp();
       
  2972     }
       
  2973 
       
  2974 
       
  2975 //For Code Coverage.
       
  2976 
       
  2977 void CTunDriverTestWrapper::DoRConnTest1_20()
       
  2978 {
       
  2979     INFO_PRINTF1(_L("*********************************************"));
       
  2980     INFO_PRINTF1(_L("           Test: DoRConnTest1_20             "));
       
  2981     INFO_PRINTF1(_L("*********************************************"));
       
  2982 
       
  2983     StartConn();
       
  2984     }
       
  2985 
       
  2986 void CTunDriverTestWrapper::DoRConnTest1_21()
       
  2987     {
       
  2988     INFO_PRINTF1(_L("*********************************************"));
       
  2989     INFO_PRINTF1(_L("           Test: DoRConnTest1_21             "));
       
  2990     INFO_PRINTF1(_L("*********************************************"));
       
  2991 
       
  2992     StartConn();
       
  2993     }
       
  2994 
       
  2995 void CTunDriverTestWrapper::DoRConnTest1_22()
       
  2996     {
       
  2997     INFO_PRINTF1(_L("*********************************************"));
       
  2998     INFO_PRINTF1(_L("           Test: DoRConnTest1_22             "));
       
  2999     INFO_PRINTF1(_L("*********************************************"));
       
  3000 
       
  3001     StartConn();
       
  3002     }
       
  3003 
       
  3004 void CTunDriverTestWrapper::DoRConnTest1_23()
       
  3005     {
       
  3006 
       
  3007     INFO_PRINTF1(_L("*********************************************"));
       
  3008     INFO_PRINTF1(_L("           Test: DoRConnTest1_23             "));
       
  3009     INFO_PRINTF1(_L("*********************************************"));
       
  3010 
       
  3011     StartConn();
       
  3012     }
       
  3013 
       
  3014 
       
  3015 void CTunDriverTestWrapper::DoRConnTest1_24()
       
  3016     {
       
  3017     INFO_PRINTF1(_L("*********************************************"));
       
  3018     INFO_PRINTF1(_L("           Test: DoRConnTest1_24             "));
       
  3019     INFO_PRINTF1(_L("********************************************"));
       
  3020 
       
  3021 		StartConn(); 
       
  3022 
       
  3023 
       
  3024 
       
  3025       
       
  3026         
       
  3027     }
       
  3028 
       
  3029 void CTunDriverTestWrapper::DoRConnTest1_25()
       
  3030     {
       
  3031     INFO_PRINTF1(_L("*********************************************"));
       
  3032     INFO_PRINTF1(_L("           Test: DoRConnTest1_25             "));
       
  3033     INFO_PRINTF1(_L("********************************************"));
       
  3034 
       
  3035 
       
  3036     StartConn();    
       
  3037     }
       
  3038 
       
  3039 void CTunDriverTestWrapper::DoRConnTest1_26()
       
  3040     {
       
  3041     INFO_PRINTF1(_L("*********************************************"));
       
  3042     INFO_PRINTF1(_L("           Test: DoRConnTest1_26             "));
       
  3043     INFO_PRINTF1(_L("********************************************"));
       
  3044 
       
  3045 
       
  3046     StartConn();
       
  3047     }
       
  3048 
       
  3049 
       
  3050 void CTunDriverTestWrapper::DoRConnTest1_27()
       
  3051     {
       
  3052     INFO_PRINTF1(_L("*********************************************"));
       
  3053     INFO_PRINTF1(_L("           Test: DoRConnTest1_27             "));
       
  3054     INFO_PRINTF1(_L("********************************************"));
       
  3055 
       
  3056     StartConn();
       
  3057     }
       
  3058 
       
  3059 
       
  3060 void CTunDriverTestWrapper::DoRConnTest1_28()
       
  3061     {
       
  3062     INFO_PRINTF1(_L("*********************************************"));
       
  3063     INFO_PRINTF1(_L("           Test: DoRConnTest1_28             "));
       
  3064     INFO_PRINTF1(_L("********************************************"));
       
  3065 
       
  3066     StartConn();
       
  3067     }
       
  3068 
       
  3069 void CTunDriverTestWrapper::DoRConnTest1_29()
       
  3070     {
       
  3071     INFO_PRINTF1(_L("*********************************************"));
       
  3072     INFO_PRINTF1(_L("           Test: DoRConnTest1_29             "));
       
  3073     INFO_PRINTF1(_L("*********************************************"));
       
  3074 
       
  3075     StartConn();
       
  3076     }
       
  3077 
       
  3078 void CTunDriverTestWrapper::DoRConnTest1_30()
       
  3079     {
       
  3080     INFO_PRINTF1(_L("*********************************************"));
       
  3081     INFO_PRINTF1(_L("           Test: DoRConnTest1_30             "));
       
  3082     INFO_PRINTF1(_L("*********************************************"));
       
  3083 
       
  3084     StartConn();
       
  3085     }
       
  3086 
       
  3087 void CTunDriverTestWrapper::DoRConnTest1_31()
       
  3088     {
       
  3089     INFO_PRINTF1(_L("*********************************************"));
       
  3090     INFO_PRINTF1(_L("           Test: DoRConnTest1_31             "));
       
  3091     INFO_PRINTF1(_L("*********************************************"));
       
  3092 
       
  3093     StartConn();
       
  3094     }
       
  3095 
       
  3096 
       
  3097 void CTunDriverTestWrapper::DoRConnTest1_32()
       
  3098     {
       
  3099     INFO_PRINTF1(_L("*********************************************"));
       
  3100     INFO_PRINTF1(_L("           Test: DoRConnTest1_32             "));
       
  3101     INFO_PRINTF1(_L("*********************************************"));
       
  3102 
       
  3103     StartConn();
       
  3104     }
       
  3105 
       
  3106 void CTunDriverTestWrapper::DoRConnTest1_33()
       
  3107     {
       
  3108     INFO_PRINTF1(_L("*********************************************"));
       
  3109     INFO_PRINTF1(_L("           Test: DoRConnTest1_33             "));
       
  3110     INFO_PRINTF1(_L("*********************************************"));
       
  3111 
       
  3112     StartConn();
       
  3113     }
       
  3114 
       
  3115 
       
  3116 void CTunDriverTestWrapper::StartConn()
       
  3117     {
       
  3118     if((iStatus = iSocketServ.Connect()) == KErrNone )
       
  3119         INFO_PRINTF1(_L("Socket Server Opened.\n"));
       
  3120     else
       
  3121         {
       
  3122         ERR_PRINTF2(_L("Error Opening Socket Server: %d"), iStatus.Int());
       
  3123         SetError(iStatus.Int());
       
  3124              return;
       
  3125         }
       
  3126 
       
  3127 		if((iStatus = iConnection.Open(iSocketServ)) == KErrNone )
       
  3128     		INFO_PRINTF1(_L("Connection opened. \n"));
       
  3129 		else
       
  3130     		{
       
  3131         ERR_PRINTF2(_L("Error Opening Connection: %d"), iStatus.Int());
       
  3132         SetError(iStatus.Int());
       
  3133         iSocketServ.Close();
       
  3134         return;
       
  3135         }
       
  3136            
       
  3137 		iCommDbPref.SetIapId(TUNDRIVER_IAP);             // Virtual Interface
       
  3138     iCommDbPref.SetBearerSet(KCommDbBearerVirtual);
       
  3139     iCommDbPref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
  3140     iConnection.Start(iCommDbPref, iStatus);
       
  3141     User::WaitForRequest(iStatus);
       
  3142     if(iStatus.Int()!=KErrNone)
       
  3143 	    	{
       
  3144 	    	ERR_PRINTF2(_L("Error starting connection: %d"), iStatus.Int());	
       
  3145 				SetError(iStatus.Int());
       
  3146 				iSocketServ.Close();
       
  3147 				return;
       
  3148 	    	}
       
  3149     INFO_PRINTF2(_L("Starting Connection %d.\n"), iStatus.Int());
       
  3150 
       
  3151     iConnection.Stop();
       
  3152     iSocketServ.Close();
       
  3153     }