bluetooth/btexample/test/TestConsole/BTTestHelpers.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "BTTestHelpers.h"
       
    17 #include "BTTestConsole.h"
       
    18 
       
    19 _LIT(KNotDefined,				"-");
       
    20 
       
    21 _LIT(KConnIdle,					"Idle        ");
       
    22 _LIT(KConnListening,			"Listening   ");
       
    23 _LIT(KConnListeningAccept,		"Lstn[Accept]");
       
    24 _LIT(KConnAccepting,			"Accepting   ");
       
    25 _LIT(KConnConnecting,			"Connecting  ");
       
    26 _LIT(KConnConnected,			"Connected   ");
       
    27 _LIT(KConnDisconnected,			"Disconnected");
       
    28 _LIT(KConnServerDisconnected,	"Serv Disc   ");
       
    29 _LIT(KConnFailed,				"Failed      ");
       
    30 
       
    31 _LIT(KRoleMaster,				"M");
       
    32 _LIT(KRoleSlave,				"S");
       
    33 
       
    34 _LIT(KModeActive,				"Active");
       
    35 _LIT(KRoleHold,					"Hold  ");
       
    36 _LIT(KRoleSniff,				"Sniff ");
       
    37 _LIT(KRolePark,					"Park  ");
       
    38 _LIT(KRoleScatter,				"Scatr ");
       
    39 _LIT(KModeExplicitActive,		"ExpAct");
       
    40 
       
    41 _LIT(KDataNone,					" --- ");
       
    42 _LIT(KDataDialog1,				"Rx/Tx");
       
    43 _LIT(KDataDialog2,				"Tx/Rx");
       
    44 _LIT(KDataFailed,				"FAIL ");
       
    45 _LIT(KDataSend,					"Send ");
       
    46 _LIT(KDataRecv,					"Recv ");
       
    47 _LIT(KDataRecvAny,				"RecvA");
       
    48 _LIT(KDataSendReceive,			"BiDi ");
       
    49 _LIT(KDataSendOS,				"Tx OS");
       
    50 _LIT(KDataRecvOS,				"Rx OS");
       
    51 
       
    52 const TDesC& TConnProfile::StateName(TConnState aState)
       
    53 	{
       
    54 	switch(aState)
       
    55 		{
       
    56 		case EConnIdle:
       
    57 			return KConnIdle;
       
    58 			
       
    59 		case EConnListening:
       
    60 			return KConnListening;
       
    61 			
       
    62 		case EConnListeningAccept:
       
    63 			return KConnListeningAccept;
       
    64 			
       
    65 		case EConnAccepting:
       
    66 			return KConnAccepting;
       
    67 			
       
    68 		case EConnConnecting:
       
    69 			return KConnConnecting;
       
    70 			
       
    71 		case EConnConnected:
       
    72 			return KConnConnected;
       
    73 			
       
    74 		case EConnDisconnected:
       
    75 			return KConnDisconnected;
       
    76 			
       
    77 		case EConnServerDisconnected:
       
    78 			return KConnServerDisconnected;
       
    79 			
       
    80 		case EConnFailed:
       
    81 			return KConnFailed;
       
    82 			
       
    83 		default:
       
    84 			break;
       
    85 		};
       
    86 		
       
    87 	return KNullDesC;	
       
    88 	}
       
    89 
       
    90 const TDesC& TConnProfile::RoleName(TConnRole aState)
       
    91 	{
       
    92 	switch(aState)
       
    93 		{
       
    94 		case ENone:
       
    95 			return KNotDefined;
       
    96 			
       
    97 		case EMaster:
       
    98 			return KRoleMaster;
       
    99 			
       
   100 		case ESlave:
       
   101 			return KRoleSlave;
       
   102 			
       
   103 		default:
       
   104 			break;
       
   105 		};
       
   106 		
       
   107 	return KNullDesC;	
       
   108 	}
       
   109 
       
   110 const TDesC& TConnProfile::ModeName(TBTLinkMode aState)
       
   111 	{
       
   112 	switch(aState)
       
   113 		{
       
   114 		case EActiveMode:
       
   115 			return KModeActive;
       
   116 			
       
   117 		case EHoldMode:
       
   118 			return KRoleHold;
       
   119 
       
   120 		case ESniffMode:
       
   121 			return KRoleSniff;
       
   122 			
       
   123 		case EParkMode:
       
   124 			return KRolePark;
       
   125 
       
   126 		case EScatterMode:
       
   127 			return KRoleScatter;
       
   128 			
       
   129 		default:
       
   130 			break;
       
   131 		};
       
   132 		
       
   133 	return KNullDesC;	
       
   134 	}
       
   135 
       
   136 const TDesC& TConnProfile::ModeName(TConnProfile::TConnMode aState)
       
   137 	{
       
   138 	switch(aState)
       
   139 		{
       
   140 		case EActive:
       
   141 			return KModeActive;
       
   142 			
       
   143 		case EHold:
       
   144 			return KRoleHold;
       
   145 
       
   146 		case ESniff:
       
   147 			return KRoleSniff;
       
   148 			
       
   149 		case EPark:
       
   150 			return KRolePark;
       
   151 		
       
   152 		case EExplicitActive:
       
   153 			return KModeExplicitActive;
       
   154 
       
   155 		default:
       
   156 			break;
       
   157 		};
       
   158 		
       
   159 	return KNullDesC;	
       
   160 	}
       
   161 
       
   162 const TDesC& TConnProfile::DataStateName(TDataState aState)
       
   163 	{
       
   164 	switch(aState)
       
   165 		{
       
   166 		case EDataIdle:
       
   167 			return KDataNone;
       
   168 			
       
   169 		case EDataDialog1:
       
   170 			return KDataDialog1;
       
   171 			
       
   172 		case EDataDialog2:
       
   173 			return KDataDialog2;
       
   174 			
       
   175 		case EDataFailed:
       
   176 			return KDataFailed;
       
   177 			
       
   178 		case EDataSend:
       
   179 			return KDataSend;
       
   180 			
       
   181 		case EDataRecv:
       
   182 			return KDataRecv;
       
   183 
       
   184 		case EDataRecvAny:
       
   185 			return KDataRecvAny;
       
   186 			
       
   187 		case EDataSendOneShot:
       
   188 			return KDataSendOS;
       
   189 			
       
   190 		case EDataRecvOneShot:
       
   191 			return KDataRecvOS;
       
   192 
       
   193 		case EDataSendReceive:
       
   194 			return KDataSendReceive;
       
   195 			
       
   196 		default:
       
   197 			break;
       
   198 		};
       
   199 		
       
   200 	return KNullDesC;	
       
   201 	}
       
   202 
       
   203 
       
   204 CBTTestConnectionNotifier* CBTTestConnectionNotifier::NewL(CBTTestConnection & aParent)
       
   205 	{
       
   206 	CBTTestConnectionNotifier* self = NewLC(aParent);
       
   207 	CleanupStack::Pop(); // self
       
   208 	return self;
       
   209 	}
       
   210 
       
   211 CBTTestConnectionNotifier* CBTTestConnectionNotifier::NewLC(CBTTestConnection & aParent)
       
   212 	{
       
   213 	CBTTestConnectionNotifier* self = new (ELeave) CBTTestConnectionNotifier(aParent);
       
   214 	CleanupStack::PushL(self);
       
   215 	return self;
       
   216 	}
       
   217 
       
   218 CBTTestConnectionNotifier::~CBTTestConnectionNotifier()
       
   219 	{
       
   220 	}
       
   221 
       
   222 CBTTestConnectionNotifier::CBTTestConnectionNotifier(CBTTestConnection & aParent)
       
   223   : CActive(CActive::EPriorityStandard), iParent(aParent)
       
   224 	{
       
   225 	CActiveScheduler::Add(this);
       
   226 	}
       
   227 
       
   228 void CBTTestConnectionNotifier::CancelRequests()
       
   229 	{
       
   230 	Cancel();
       
   231 	}
       
   232 
       
   233 void CBTTestConnectionNotifier::DoCancel()
       
   234 	{
       
   235 	iParent.CancelBasebandNotifyRequest();
       
   236 	}
       
   237 
       
   238 void CBTTestConnectionNotifier::RequestNotifications(TUint32 aNotifications, RBTPhysicalLinkAdapter & aPhyAdapter)
       
   239 	{
       
   240 	iEvent = iNotification;
       
   241 	aPhyAdapter.NotifyNextBasebandChangeEvent(iEvent, iStatus, aNotifications);
       
   242 
       
   243 	SetActive();
       
   244 	}
       
   245 
       
   246 
       
   247 void CBTTestConnectionNotifier::RunL()
       
   248 	{
       
   249 	TBTBasebandEventNotification notification = iEvent();
       
   250 	iParent.OutputOneShotEventNotification(notification);
       
   251 	}
       
   252 
       
   253 
       
   254 //
       
   255 //				CBTTestConnection Class Methods					//
       
   256 //
       
   257 //
       
   258 //				Public functions								//
       
   259 //
       
   260 CBTTestConnection* CBTTestConnection::NewL(CBTTestConsole* aConsole, RSocketServ& aSocketServer)
       
   261 	{
       
   262 	CBTTestConnection* self = NewLC(aConsole, aSocketServer);
       
   263 	self->ConstructL();
       
   264 	CleanupStack::Pop(); // self
       
   265 	return self;
       
   266 	}
       
   267 
       
   268 CBTTestConnection* CBTTestConnection::NewLC(CBTTestConsole * aConsole, RSocketServ & aSocketServer)
       
   269 	{
       
   270 	CBTTestConnection* self = new (ELeave) CBTTestConnection(aConsole, aSocketServer);
       
   271 	CleanupStack::PushL(self);
       
   272 	return self;
       
   273 	}
       
   274 
       
   275 CBTTestConnection::CBTTestConnection(CBTTestConsole * aConsole, RSocketServ & aSocketServer)
       
   276 : iParent(aConsole),
       
   277   iSocketServer(aSocketServer),
       
   278   iNotifier(*this),
       
   279   iSyncLinkHandler(*this),
       
   280   iPhyLinkAdapter(),
       
   281   iEventNotificationQueue(_FOFF(TBTQueuedBasebandEventNotification, iLink)),
       
   282   iCurrentIOCTL(EDontCare),
       
   283   iTailDigit(-1),
       
   284   iTotalRecvByte(0),
       
   285   iAutoSniff(EFalse)
       
   286 	{
       
   287 	}
       
   288 
       
   289 void CBTTestConnection::ConstructL()
       
   290 	{
       
   291 	iCustomSendRecvBuffer.CreateL(0);
       
   292 	}
       
   293 
       
   294 CBTTestConnection::~CBTTestConnection()
       
   295 	{
       
   296 	delete iBTSocket;
       
   297 	delete iBTPhyLinks;
       
   298 	delete iBTSyncLink;
       
   299 	iNotifier.CancelRequests();
       
   300 	iPhyLinkAdapter.Close();
       
   301 	delete iMetrics;
       
   302 	delete iMetricsConsole;
       
   303 	ClearEventStore();
       
   304 	}
       
   305 
       
   306 TInt CBTTestConnection::ConfigureLink(TBool aUseIoctl)
       
   307 	{
       
   308 	iConfigPkg() = (iParent->L2CapAPIConfig());
       
   309 	TInt rerr;
       
   310 	if(aUseIoctl)
       
   311 		{
       
   312 		rerr = iBTSocket->Ioctl(KL2CAPUpdateChannelConfigIoctl, &iConfigPkg, KSolBtL2CAP); 
       
   313 		}
       
   314 	else
       
   315 		{
       
   316 		rerr = iBTSocket->SetOpt(KL2CAPUpdateChannelConfig, KSolBtL2CAP, iConfigPkg);
       
   317 		}
       
   318 		
       
   319 	return rerr;
       
   320 	}
       
   321 
       
   322 TInt CBTTestConnection::CreateListeningSocket(TUint16 aPort, TDesC16 const& aProtocolName, TBTServiceSecurity & aSecurity, TBool aUseDefaultConfig)
       
   323 	{
       
   324 	TInt rerr = KErrNone;
       
   325 	
       
   326 	TProtocolDesc iProtocolInfo;
       
   327 
       
   328 	User::LeaveIfError(iSocketServer.FindProtocol(aProtocolName, iProtocolInfo));  //Qualified
       
   329 	TRAP(rerr, iBTSocket = CBluetoothSocket::NewL(*this, iSocketServer, iProtocolInfo.iSockType,iProtocolInfo.iProtocol));
       
   330 
       
   331 	if(rerr == KErrNone)
       
   332 		{
       
   333 		iPeerSocketAddr.SetBTAddr(TBTDevAddr(0));
       
   334 		iPeerSocketAddr.SetPort(aPort);
       
   335 		iPeerSocketAddr.SetSecurity(aSecurity);
       
   336 
       
   337 		rerr = iBTSocket->Bind(iPeerSocketAddr);
       
   338 		if(rerr == KErrNone)
       
   339 			{
       
   340 			rerr = iBTSocket->Listen(5);
       
   341 			if(rerr == KErrNone)
       
   342 				{
       
   343 #ifdef _DEBUG
       
   344 				TInt value = 0;
       
   345 				TInt err = iBTSocket->GetOpt(KL2CAPVersion1_2, KSolBtL2CAP, value);
       
   346 #else
       
   347 				// For non debug build this condition can not be tested.  Assume L2CAP is v1.2
       
   348 				TInt err = KErrNone;
       
   349 #endif
       
   350 				if(!aUseDefaultConfig && err == KErrNone)
       
   351 					{
       
   352 					TL2CapConfigPkg pkg(iParent->L2CapAPIConfig());
       
   353 					rerr = iBTSocket->SetOpt(KL2CAPUpdateChannelConfig, KSolBtL2CAP, pkg);
       
   354 					}
       
   355 				}
       
   356 			}
       
   357 		}
       
   358 	iProfile.iState = (rerr == KErrNone) ? TConnProfile::EConnListening :
       
   359 	                                       TConnProfile::EConnFailed;
       
   360 	iProfile.iErrorCode = rerr;	
       
   361 
       
   362 	return rerr;		
       
   363 	}
       
   364 
       
   365 TInt CBTTestConnection::Accept(CBluetoothSocket& aListeningSocket)
       
   366 	{
       
   367 	TInt rerr = KErrNone;
       
   368 	TRAP(rerr, iBTSocket = CBluetoothSocket::NewL(*this, iSocketServer));
       
   369 	if(rerr == KErrNone)
       
   370 		{
       
   371 		rerr = aListeningSocket.Accept(*iBTSocket);
       
   372 		}
       
   373 
       
   374 	iProfile.iState = (rerr == KErrNone) ? TConnProfile::EConnAccepting :
       
   375 	                                       TConnProfile::EConnFailed;
       
   376 	iProfile.iErrorCode = rerr;
       
   377 
       
   378 	return rerr;
       
   379 	}
       
   380 
       
   381 TInt CBTTestConnection::ConnectToPeer(TBTDevAddr &aAddr, TUint16 aPort, TDesC16 const& aProtocolName, TBTServiceSecurity & aSecurity, TBool aUseDefaultConfig)
       
   382 	{
       
   383 	TInt rerr = KErrNone;
       
   384 	
       
   385 	TProtocolDesc iProtocolInfo;
       
   386 
       
   387 	rerr = iSocketServer.FindProtocol(aProtocolName, iProtocolInfo);
       
   388 	if(rerr == KErrNone)
       
   389 		{
       
   390 		TRAP(rerr, iBTSocket = CBluetoothSocket::NewL(*this, iSocketServer, iProtocolInfo.iSockType,
       
   391 			                                                                 iProtocolInfo.iProtocol));
       
   392 		if(rerr == KErrNone)
       
   393 			{
       
   394 			iPeerSocketAddr.SetBTAddr(aAddr);
       
   395 			iPeerSocketAddr.SetPort(aPort);
       
   396 			iPeerSocketAddr.SetSecurity(aSecurity);
       
   397 
       
   398 #ifdef _DEBUG
       
   399 			TInt value = 0;
       
   400 			TInt err = iBTSocket->GetOpt(KL2CAPVersion1_2, KSolBtL2CAP, value);
       
   401 #else
       
   402 			// For non debug build this condition can not be tested.  Assume L2CAP is v1.2
       
   403 			TInt err = KErrNone;
       
   404 #endif
       
   405 			if(!aUseDefaultConfig && err == KErrNone)
       
   406 				{
       
   407 				TL2CapConfigPkg pkg(iParent->L2CapAPIConfig());
       
   408 				rerr = iBTSocket->SetOpt(KL2CAPUpdateChannelConfig, KSolBtL2CAP, pkg);
       
   409 				}
       
   410 			}
       
   411 		}
       
   412 	if(rerr == KErrNone)
       
   413 		{
       
   414 		rerr = iBTSocket->Connect(iPeerSocketAddr);
       
   415 		}
       
   416 
       
   417 	iProfile.iState = (rerr == KErrNone) ? TConnProfile::EConnConnecting :
       
   418 	                                       TConnProfile::EConnFailed;
       
   419 	iProfile.iErrorCode = rerr;		
       
   420 
       
   421 	return rerr;
       
   422 	}
       
   423 	
       
   424 TInt CBTTestConnection::SendMTUIoctl(TBool aIsIncomingMTU, TUint16 aNewValue)
       
   425 	{
       
   426 	i16bitIoctlBuffer() = aNewValue;
       
   427 	return iBTSocket->Ioctl((aIsIncomingMTU ? KL2CAPIncomingMTUIoctl : KL2CAPOutgoingMTUIoctl), &i16bitIoctlBuffer, KSolBtL2CAP);
       
   428 	}
       
   429 
       
   430 TInt CBTTestConnection::SendPretendIncomingSduQFullIoctl(TBool aPretendIncomingSduQFull)
       
   431 	{
       
   432 	iBoolIoctlBuffer() = aPretendIncomingSduQFull;
       
   433 	return iBTSocket->Ioctl(KL2CAPPretendIncomingSduQFull, &iBoolIoctlBuffer, KSolBtL2CAP);
       
   434 	}
       
   435 
       
   436 TInt CBTTestConnection::GetChannelMode(TL2CapChannelMode& aMode)
       
   437 	{
       
   438 	return iBTSocket->GetOpt(KL2CAPNegotiatedChannelMode, KSolBtL2CAP, reinterpret_cast<TInt&>(aMode));
       
   439 	}
       
   440 
       
   441 TInt CBTTestConnection::GetLocalPSM(TL2CAPPort& aPsm)
       
   442 	{
       
   443 	TPckg<TL2CAPPort> buf(aPsm);
       
   444 	return iBTSocket->GetOpt(KL2CAPLocalPSM, KSolBtL2CAP, buf);
       
   445 	}
       
   446 
       
   447 TInt CBTTestConnection::RecvOneShotData()
       
   448 	{
       
   449 	TInt rerr = KErrNone;
       
   450 	if(iProfile.iIsStreamProtocol)
       
   451 		{
       
   452 		rerr = iBTSocket->RecvOneOrMore(iRecvBuffer, 0, iRecvBufferLength);
       
   453 		}
       
   454 	else
       
   455 		{
       
   456 		rerr = iBTSocket->Read(iRecvBuffer);
       
   457 		}
       
   458 	return rerr;
       
   459 	}
       
   460 	
       
   461 TInt CBTTestConnection::SendOneShotData(TUint16 aDataSize)
       
   462 	{
       
   463 	TInt rerr = KErrNone;
       
   464 	//fill the data with 0123456789012... sequences
       
   465 	iCustomSendRecvBuffer.Zero();	
       
   466 	iCustomSendRecvBuffer.ReAlloc(aDataSize);
       
   467 	for(TInt i =0 ;i<aDataSize;i++)
       
   468 		{
       
   469 		iCustomSendRecvBuffer.Append(i%10);
       
   470 		}
       
   471 	rerr = iBTSocket->Write(iCustomSendRecvBuffer);
       
   472 	return rerr;
       
   473 	}
       
   474 	
       
   475 TInt CBTTestConnection::RecvContinuationData(TUint16 aDataSize)
       
   476 	{
       
   477 	TInt rerr =0;
       
   478 	
       
   479 	iCustomSendRecvBuffer.Zero();	
       
   480 	rerr = iCustomSendRecvBuffer.ReAlloc(aDataSize);
       
   481 	if(rerr == KErrNone)
       
   482 		{
       
   483 		/*
       
   484 		In function Recv(iCustomSendRecvBuffer, KSockReadContinuation, iRecvBufferLength);
       
   485 		iCustomSendRecvBuffer: 	A descriptor for the information being sent to the remote Bluetooth device. 
       
   486 		KSockReadContinuation:	Bluetooth information flags. When it's set to KSockReadContinuation, 
       
   487 								Read from datagram in a stream-like fashion(not discarding tails,continuation).
       
   488 		iRecvBufferLength:		A length indicating how much data is left in the buffer.
       
   489 		*/
       
   490 		rerr = iBTSocket->Recv(iCustomSendRecvBuffer, KSockReadContinuation, iRecvBufferLength);
       
   491 		}
       
   492 	return rerr;
       
   493 	}
       
   494 
       
   495 TInt CBTTestConnection::SetLocalModemStatus(TUint8 aModemStatus)
       
   496 	{
       
   497 	TPckgBuf<TUint8> pkg(aModemStatus);
       
   498 	iParent->test.Printf(_L("\nSetLocalModemStatus: %x"), aModemStatus);
       
   499 	return iBTSocket->SetOpt(KRFCOMMLocalModemStatus, KSolBtRFCOMM, pkg);
       
   500 	}
       
   501 	
       
   502 TInt CBTTestConnection::RequestRFCommConfChgInd()
       
   503 	{
       
   504 	// Cancel any outstanding IOCTLs
       
   505 	__ASSERT_ALWAYS(iBTSocket, Panic(EBTConsoleNoSocketForSocketBasedConnection));
       
   506 	iBTSocket->CancelIoctl();
       
   507 	
       
   508 	TInt rerr = iBTSocket->Ioctl(KRFCOMMConfigChangeIndicationIoctl, NULL, KSolBtRFCOMM); 
       
   509 	if(rerr == KErrNone)
       
   510 		{
       
   511 		iCurrentIOCTL = ERFCOMMConfigInd;
       
   512 		}
       
   513 	return rerr;	
       
   514 	}
       
   515 
       
   516 TInt CBTTestConnection::ConnectUsingBAP(TBTDevAddr &aAddr)
       
   517 	{
       
   518 	TInt rerr = KErrNone;
       
   519 	iProfile.iIsSocketBased = EFalse;
       
   520 	TRAP(rerr, iBTPhyLinks = CBluetoothPhysicalLinks::NewL(*this, iSocketServer));
       
   521 	if(rerr == KErrNone)
       
   522 		{
       
   523 		iProfile.iRemoteBTAddr.SetBTAddr(aAddr);
       
   524 		rerr = iBTPhyLinks->CreateConnection(aAddr);
       
   525 		}
       
   526 		
       
   527 	return rerr;	
       
   528 	}
       
   529 
       
   530 void CBTTestConnection::UpdateProfileAcceptComplete()
       
   531 	{
       
   532 	TInt rerr = KErrNone;
       
   533 	
       
   534 	iBTSocket->RemoteName(iProfile.iRemoteBTAddr);
       
   535 	iProfile.iState = TConnProfile::EConnConnected;
       
   536 	TBTDevAddr addr = iProfile.iRemoteBTAddr.BTAddr();
       
   537 
       
   538 	TInt rValue = 0;
       
   539 	rerr = iBTSocket->GetOpt(KL2CAPOutboundMTUForBestPerformance, KSolBtL2CAP, rValue);
       
   540 	if(rerr == KErrNone)
       
   541 		{
       
   542 		iProfile.iSendingMTUSize = rValue;
       
   543 
       
   544 		rerr = iBTSocket->GetOpt(KL2CAPInboundMTU, KSolBtL2CAP, rValue);
       
   545 		if(rerr == KErrNone)
       
   546 			{
       
   547 			iProfile.iRecvMTUSize = rValue;
       
   548 			
       
   549 			iParent->CreatePhyRecord(addr);
       
   550 			RequestNotification(0xffffffff);
       
   551 			}
       
   552 		}
       
   553 
       
   554 	iProfile.iErrorCode = rerr;	
       
   555 	}
       
   556 
       
   557 
       
   558 void CBTTestConnection::AcceptComplete(TInt result)
       
   559 	{
       
   560 	if(result)
       
   561 		{
       
   562 		iParent->test.Printf(_L("\nAccept Completed with error: %d"), result);
       
   563 		iProfile.iErrorCode = result;	
       
   564 		if(iProfile.iAccepterIx >= 0 && iParent->GetConn(iProfile.iAccepterIx))
       
   565 			{
       
   566 			(iParent->GetConn(iProfile.iAccepterIx))->iProfile.iState = TConnProfile::EConnFailed;
       
   567 			(iParent->GetConn(iProfile.iAccepterIx))->iProfile.iErrorCode = result;
       
   568 			}
       
   569 		}
       
   570 	else
       
   571 		{
       
   572 		if(iProfile.iAccepterIx >= 0 && iParent->GetConn(iProfile.iAccepterIx))
       
   573 			{
       
   574 			(iParent->GetConn(iProfile.iAccepterIx))->UpdateProfileAcceptComplete();
       
   575 			(iParent->GetConn(iProfile.iAccepterIx))->iProfile.iIsStreamProtocol = iProfile.iIsStreamProtocol;
       
   576 			}
       
   577 		}
       
   578 	iProfile.iState = TConnProfile::EConnListening;
       
   579 	iParent->Draw();
       
   580 	}
       
   581 
       
   582 void CBTTestConnection::ConnectComplete(TInt result)
       
   583 	{
       
   584 	TInt rerr = KErrNone;
       
   585 	
       
   586 	if(result)
       
   587 		{
       
   588 		iParent->test.Printf(_L("\nConnect Completed with error: %d"), result);
       
   589 		iProfile.iState = TConnProfile::EConnFailed;
       
   590 		iProfile.iErrorCode = result;	
       
   591 		}
       
   592 	else
       
   593 		{
       
   594 		iProfile.iState = TConnProfile::EConnConnected;
       
   595 		iBTSocket->RemoteName(iProfile.iRemoteBTAddr);
       
   596 		TBTDevAddr addr = iProfile.iRemoteBTAddr.BTAddr();
       
   597 
       
   598 		TInt rValue = 0;
       
   599 		rerr = iBTSocket->GetOpt(KL2CAPOutboundMTUForBestPerformance, KSolBtL2CAP, rValue);
       
   600 		if(rerr == KErrNone)
       
   601 			{
       
   602 			iProfile.iSendingMTUSize = rValue;
       
   603 
       
   604 			rerr = iBTSocket->GetOpt(KL2CAPInboundMTU, KSolBtL2CAP, rValue);
       
   605 			if(rerr == KErrNone)
       
   606 				{
       
   607 				iProfile.iRecvMTUSize = rValue;
       
   608 				TRAP_IGNORE(iMetrics = CBluetoothPhysicalLinkMetrics::NewL(*this, iSocketServer, addr));
       
   609 				iParent->CreatePhyRecord(addr);
       
   610 				RequestNotification(0xffffffff);
       
   611 				}
       
   612 			}
       
   613 		iProfile.iErrorCode = rerr;	
       
   614 		}
       
   615 	iParent->Draw();
       
   616 	}
       
   617 
       
   618 TInt CBTTestConnection::SetupPhysAdapter()
       
   619 	{
       
   620 	TBTDevAddr addr = iProfile.iRemoteBTAddr.BTAddr();
       
   621 	iParent->CreatePhyRecord(addr);
       
   622 	TInt rerr = iPhyLinkAdapter.Open(iSocketServer, addr);
       
   623 	if(rerr == KErrNone)
       
   624 		{
       
   625 		iNotifier.CancelRequests();
       
   626 		iNotifier.RequestNotifications(0xffffffff, iPhyLinkAdapter);
       
   627 		}
       
   628 	return rerr;
       
   629 	}
       
   630 
       
   631 void CBTTestConnection::ConnectBAPComplete(TInt result)
       
   632 	{
       
   633 	if(result)
       
   634 		{
       
   635 		iParent->test.Printf(_L("\nConnect BAP Completed with error: %d"), result);
       
   636 		iProfile.iState = TConnProfile::EConnFailed;
       
   637 		iProfile.iErrorCode = result;
       
   638 		}
       
   639 	else
       
   640 		{
       
   641 		iProfile.iState = TConnProfile::EConnConnected;
       
   642 		TBTDevAddr addr = iProfile.iRemoteBTAddr.BTAddr();
       
   643 		
       
   644 		TInt rerr = SetupPhysAdapter();
       
   645 		if(rerr == KErrNone)
       
   646 			{
       
   647 			TRAP_IGNORE(iMetrics = CBluetoothPhysicalLinkMetrics::NewL(*this, iSocketServer, addr));
       
   648 			}
       
   649 		else
       
   650 			{
       
   651 			iProfile.iErrorCode = rerr;	
       
   652 			}
       
   653 		}
       
   654 	iParent->Draw();
       
   655 	}
       
   656 
       
   657 TInt CBTTestConnection::SendEchoRequest(TInt aPayloadSize)
       
   658 	{
       
   659 	TInt rerr = KErrNone;
       
   660 	if(iProfile.iIsSocketBased)
       
   661 		{
       
   662 		if (aPayloadSize == 0)
       
   663 			{
       
   664 			rerr = iBTSocket->Ioctl(KL2CAPEchoRequestIoctl, NULL, KSolBtL2CAP);
       
   665 			}
       
   666 		else
       
   667 			{
       
   668 			iEchoDataBuffer.Fill(0x28, aPayloadSize);
       
   669 			iEchoDataBuffer.SetLength(aPayloadSize);	
       
   670 			rerr = iBTSocket->Ioctl(KL2CAPEchoRequestIoctl, &iEchoDataBuffer, KSolBtL2CAP);
       
   671 			}
       
   672 		}
       
   673 	return rerr;
       
   674 	}
       
   675 
       
   676 void CBTTestConnection::CancelAccept()
       
   677 	{
       
   678 	if(iProfile.iAccepterIx >= 0 && iParent->GetConn(iProfile.iAccepterIx))
       
   679 		{
       
   680 		(iParent->GetConn(iProfile.iAccepterIx))->iProfile.iState = TConnProfile::EConnFailed;
       
   681 		}
       
   682 	iBTSocket->CancelAccept();
       
   683 	iProfile.iState = TConnProfile::EConnListening;
       
   684 	}
       
   685 
       
   686 void CBTTestConnection::CancelConnect()
       
   687 	{
       
   688 	if(iProfile.iIsSocketBased)
       
   689 		{
       
   690 		iBTSocket->CancelConnect();
       
   691 		}
       
   692 	else
       
   693 		{
       
   694 		iBTPhyLinks->CancelCreateConnection();
       
   695 		}
       
   696 	}
       
   697 
       
   698 TInt CBTTestConnection::ShutdownSocket(RSocket::TShutdown aShutdownType)
       
   699 	{
       
   700 	TInt rerr = KErrNone;
       
   701 	if(iProfile.iIsSocketBased)
       
   702 		{
       
   703 		__ASSERT_ALWAYS(iBTSocket, Panic(EBTConsoleNoSocketForSocketBasedConnection));
       
   704 		rerr = iBTSocket->Shutdown(aShutdownType);
       
   705 		iProfile.iState = (rerr == KErrNone) ? TConnProfile::EConnDisconnected :
       
   706 		                                       TConnProfile::EConnFailed;
       
   707 		iProfile.iErrorCode = rerr;		
       
   708 		}
       
   709 	else
       
   710 		{
       
   711 		Panic(EBTConsoleShutdownCalledOnNonCBluetoothSocket);
       
   712 		}
       
   713 	
       
   714 	return rerr;	
       
   715 	}
       
   716 	
       
   717 TInt CBTTestConnection::IncreaseRTXTimer(TUint aTime)
       
   718 	{
       
   719 	TInt rerr = KErrNone;
       
   720 	if(iProfile.iIsSocketBased)
       
   721 		{
       
   722 		__ASSERT_ALWAYS(iBTSocket, Panic(EBTConsoleNoSocketForSocketBasedConnection));
       
   723 		rerr = iBTSocket->SetOpt(KL2CAPRTXTimer, KSolBtL2CAP, aTime);
       
   724 		iProfile.iErrorCode = rerr;		
       
   725 		}
       
   726 	else
       
   727 		{
       
   728 		Panic(EBTConsoleShutdownCalledOnNonCBluetoothSocket);
       
   729 		}
       
   730 	
       
   731 	return rerr;	
       
   732 	}
       
   733 
       
   734 TInt CBTTestConnection::DisconnectLink()
       
   735 	{
       
   736 	TInt rerr = KErrNone;
       
   737 	if(!iProfile.iIsSocketBased)
       
   738 		{
       
   739 		if(iProfile.iIsSCO)
       
   740 			{
       
   741 			rerr = iBTSyncLink->Disconnect();			
       
   742 			}
       
   743 		else
       
   744 			{
       
   745 			rerr = iBTPhyLinks->Disconnect(iProfile.iRemoteBTAddr.BTAddr());
       
   746 			}
       
   747 
       
   748 		iProfile.iState = (rerr == KErrNone) ? TConnProfile::EConnDisconnected :
       
   749 		                                       TConnProfile::EConnFailed;
       
   750 		iProfile.iErrorCode = rerr;		
       
   751 		}
       
   752 	else
       
   753 		{
       
   754 		Panic(EBTConsoleDisconnectCalledOnCBluetoothSocket);
       
   755 		}
       
   756 	
       
   757 	return rerr;	
       
   758 	}
       
   759 
       
   760 void CBTTestConnection::RequestNotification(TUint32 aNotification)
       
   761 	{
       
   762 	TInt rerr = KErrNone;
       
   763 	if(iProfile.iIsSocketBased)
       
   764 		{
       
   765 		rerr = KErrNotFound;
       
   766 		if(iBTSocket)
       
   767 			{
       
   768 			rerr = iBTSocket->ActivateBasebandEventNotifier(aNotification);
       
   769 			}
       
   770 		}
       
   771 
       
   772 	if(rerr != KErrNone)
       
   773 		{
       
   774 		iParent->test.Printf(_L("Request Notification [%d], Error: %d\n"), aNotification, rerr);
       
   775 		}
       
   776 	}
       
   777 
       
   778 void CBTTestConnection::OutputOneShotEventNotification(TBTBasebandEventNotification & aNotification)
       
   779 	{
       
   780 	iNotifier.RequestNotifications(0xffffffff, iPhyLinkAdapter);
       
   781 	OutputEventNotification(aNotification);
       
   782 	}
       
   783 	
       
   784 void CBTTestConnection::OutputEventNotification(TBTBasebandEventNotification & aNotification)
       
   785 	{
       
   786 	TConnProfile * profile = iParent->FindPhyRecord(iProfile.iRemoteBTAddr.BTAddr());
       
   787 	if(!profile)
       
   788 		{
       
   789 		return;
       
   790 		}
       
   791 
       
   792 	// Store the event.
       
   793 	StoreEvent(aNotification);
       
   794 
       
   795 	// Find associated PHY.
       
   796 	if(ENotifyMaster & aNotification.EventType())
       
   797 		{
       
   798 		profile->iRole = TConnProfile::EMaster;
       
   799 		}
       
   800 	if(ENotifySlave & aNotification.EventType())
       
   801 		{
       
   802 		profile->iRole = TConnProfile::ESlave;
       
   803 		}
       
   804 
       
   805 	if(ENotifyActiveMode & aNotification.EventType())
       
   806 		{
       
   807 		profile->iMode2 = TConnProfile::EActive;
       
   808 
       
   809 		if(iParent->iLPMRequestsIfActive == EFalse )
       
   810 			{
       
   811 			RemoveLPMRequest();	
       
   812 			}
       
   813 		}
       
   814 
       
   815 	if(ENotifySniffMode & aNotification.EventType())
       
   816 		{
       
   817 		profile->iMode2 = TConnProfile::ESniff;
       
   818 		}
       
   819 	if(ENotifyParkMode & aNotification.EventType())
       
   820 		{
       
   821 		profile->iMode2 = TConnProfile::EPark;
       
   822 		}
       
   823 	if(ENotifyHoldMode & aNotification.EventType())
       
   824 		{
       
   825 		profile->iMode2 = TConnProfile::EHold;
       
   826 		}
       
   827 
       
   828 	if(ENotifyMaxSlots1 & aNotification.EventType())
       
   829 		{
       
   830 		profile->iMaxSlots = 1;
       
   831 		}
       
   832 	if(ENotifyMaxSlots3 & aNotification.EventType())
       
   833 		{
       
   834 		profile->iMaxSlots = 3;
       
   835 		}
       
   836 	if(ENotifyMaxSlots5 & aNotification.EventType())
       
   837 		{
       
   838 		profile->iMaxSlots = 5;
       
   839 		}
       
   840 
       
   841 	TUint16 packetTypes = 0;
       
   842 	TBool packetEvent = EFalse;
       
   843 
       
   844 	if(ENotifyPacketsDM1 & aNotification.EventType())
       
   845 		{
       
   846 		packetTypes |= EPacketsDM1;
       
   847 		packetEvent = ETrue;
       
   848 		}
       
   849 	if(ENotifyPacketsDM3 & aNotification.EventType())
       
   850 		{
       
   851 		packetTypes |= EPacketsDM3;
       
   852 		packetEvent = ETrue;
       
   853 		}
       
   854 	if(ENotifyPacketsDM5 & aNotification.EventType())
       
   855 		{
       
   856 		packetTypes |= EPacketsDM5;
       
   857 		packetEvent = ETrue;
       
   858 		}
       
   859 	if(ENotifyPacketsDH1 & aNotification.EventType())
       
   860 		{
       
   861 		packetTypes |= EPacketsDH1;
       
   862 		packetEvent = ETrue;
       
   863 		}
       
   864 	if(ENotifyPacketsDH3 & aNotification.EventType())
       
   865 		{
       
   866 		packetTypes |= EPacketsDH3;
       
   867 		packetEvent = ETrue;
       
   868 		}
       
   869 	if(ENotifyPacketsDH5 & aNotification.EventType())
       
   870 		{
       
   871 		packetTypes |= EPacketsDH5;
       
   872 		packetEvent = ETrue;
       
   873 		}
       
   874 	if(packetEvent)
       
   875 		{
       
   876 		profile->iPackets = packetTypes;
       
   877 		}
       
   878 /*
       
   879 	if(EPacketsTypeHV1 & aNotification.EventType())
       
   880 		{
       
   881 		iParent->test.Printf(_L("SCO HV1 packet type now supported."));
       
   882 		}
       
   883 	if(EPacketsTypeHV2 & aNotification.EventType())
       
   884 		{
       
   885 		iParent->test.Printf(_L("SCO HV2 packet type now supported."));
       
   886 		}
       
   887 	if(EPacketsTypeHV3 & aNotification.EventType())
       
   888 		{
       
   889 		iParent->test.Printf(_L("SCO HV3 packet type now supported."));
       
   890 		}
       
   891 
       
   892 	if(ENotifyAuthenticationComplete & aNotification.EventType())
       
   893 		{
       
   894 		iParent->test.Printf(_L("Authentification complete."));
       
   895 		}
       
   896 */
       
   897 	if(ENotifyEncryptionChangeOn & aNotification.EventType())
       
   898 		{
       
   899 		profile->iEncryption = ETrue;
       
   900 		}
       
   901 	if(ENotifyEncryptionChangeOff & aNotification.EventType())
       
   902 		{
       
   903 		profile->iEncryption = EFalse;
       
   904 		}
       
   905 
       
   906 	if(ENotifyPhysicalLinkUp & aNotification.EventType())
       
   907 		{
       
   908 		profile->iState = TConnProfile::EConnConnected;
       
   909 		}
       
   910 	if(ENotifyPhysicalLinkDown & aNotification.EventType())
       
   911 		{
       
   912 		profile->iState = TConnProfile::EConnDisconnected;
       
   913 		}
       
   914 	if(ENotifyPhysicalLinkError & aNotification.EventType())
       
   915 		{
       
   916 		profile->iState = TConnProfile::EConnFailed;
       
   917 		}
       
   918 	iParent->Draw();
       
   919 	}
       
   920 
       
   921 void CBTTestConnection::CancelBasebandNotifyRequest()
       
   922 	{
       
   923 	iPhyLinkAdapter.CancelNextBasebandChangeEventNotifier();
       
   924 	}
       
   925 
       
   926 
       
   927 TInt CBTTestConnection::ChangeSupportedPacketTypes(TUint16 aPacketTypes)
       
   928 	{
       
   929 	TInt rerr;
       
   930 
       
   931 	if(iProfile.iIsSocketBased)
       
   932 		{
       
   933 		rerr = KErrNotFound;
       
   934 		if(iBTSocket)
       
   935 			{
       
   936 			rerr = iBTSocket->RequestChangeSupportedPacketTypes(aPacketTypes);
       
   937 			}
       
   938 		}
       
   939 	else
       
   940 		{
       
   941 		rerr = iPhyLinkAdapter.RequestChangeSupportedPacketTypes(aPacketTypes);
       
   942 		}
       
   943 
       
   944 	iParent->test.Printf(_L("Change Supported Packet Request [%d], Error: %d\n"), aPacketTypes, rerr);
       
   945 	return rerr;
       
   946 	}
       
   947 
       
   948 
       
   949 TInt CBTTestConnection::RoleChangeAllowed(TBool aAllowed)
       
   950 	{
       
   951 	TInt rerr;
       
   952 	if(aAllowed)
       
   953 		{
       
   954 		iParent->test.Printf(_L("Accept role change requests"));
       
   955 		if(iProfile.iIsSocketBased)
       
   956 			{
       
   957 			rerr = KErrNotFound;
       
   958 			if(iBTSocket)
       
   959 				{
       
   960 				rerr = iBTSocket->AllowRoleSwitch();
       
   961 				}
       
   962 			}
       
   963 		else
       
   964 			{
       
   965 			rerr = iPhyLinkAdapter.AllowRoleSwitch();
       
   966 			}
       
   967 		}
       
   968 	else
       
   969 		{
       
   970 		iParent->test.Printf(_L("Prevent role change requests"));
       
   971 		if(iProfile.iIsSocketBased)
       
   972 			{
       
   973 			rerr = KErrNotFound;
       
   974 			if(iBTSocket)
       
   975 				{
       
   976 				rerr = iBTSocket->PreventRoleSwitch();
       
   977 				}
       
   978 			}
       
   979 		else
       
   980 			{
       
   981 			rerr = iPhyLinkAdapter.PreventRoleSwitch();
       
   982 			}
       
   983 		}
       
   984 	iParent->test.Printf(_L("Role Change Allowed Request, Error: %d\n"), rerr);
       
   985 	return rerr;
       
   986 	}
       
   987 
       
   988 
       
   989 TInt CBTTestConnection::RequestRoleChange(TBTBasebandRole aRole)
       
   990 	{
       
   991 	TInt rerr;
       
   992 	if(aRole == EMaster)
       
   993 		{
       
   994 		iParent->test.Printf(_L("Request Role Change to Master\n"));
       
   995 		if(iProfile.iIsSocketBased)
       
   996 			{
       
   997 			rerr = KErrNotFound;
       
   998 			if(iBTSocket)
       
   999 				{
       
  1000 				rerr = iBTSocket->RequestMasterRole();
       
  1001 				}
       
  1002 			}
       
  1003 		else
       
  1004 			{
       
  1005 			rerr = iPhyLinkAdapter.RequestMasterRole();
       
  1006 			}
       
  1007 		}	
       
  1008 	else
       
  1009 		{
       
  1010 		iParent->test.Printf(_L("Request Role Change to Slave\n"));
       
  1011 		if(iProfile.iIsSocketBased)
       
  1012 			{
       
  1013 			rerr = KErrNotFound;
       
  1014 			if(iBTSocket)
       
  1015 				{
       
  1016 				rerr = iBTSocket->RequestSlaveRole();
       
  1017 				}
       
  1018 			}
       
  1019 		else
       
  1020 			{
       
  1021 			rerr = iPhyLinkAdapter.RequestSlaveRole();
       
  1022 			}
       
  1023 		}
       
  1024 	iParent->test.Printf(_L("Role Change Request, Error: %d\n"), rerr);
       
  1025 	return rerr;
       
  1026 	}
       
  1027  	
       
  1028 TInt CBTTestConnection::RequestAuthentication()
       
  1029  	{
       
  1030  	TInt rerr;
       
  1031  	iParent->test.Printf(_L("Requesting Authentication\n"));
       
  1032  	if(iProfile.iIsSocketBased)
       
  1033  		{
       
  1034  		rerr = KErrNotFound;
       
  1035  		iParent->test.Printf(_L("Can't request authentication on a socket based connection\n"));
       
  1036  		}
       
  1037  	else
       
  1038  		{
       
  1039  		rerr = iPhyLinkAdapter.Authenticate();
       
  1040  		}
       
  1041  	iParent->test.Printf(_L("Authentication Request, Error: %d\n"), rerr);
       
  1042  	return rerr;
       
  1043  	}
       
  1044 
       
  1045 void CBTTestConnection::StartACLData()
       
  1046 	{
       
  1047 	iTime.HomeTime();
       
  1048 	iDataDialogCount = 0;
       
  1049 	ContinueDialog();
       
  1050 	}
       
  1051 	
       
  1052 void CBTTestConnection::StopACLData()
       
  1053 	{
       
  1054 	iBTSocket->CancelSend();
       
  1055 	iBTSocket->CancelRecv();
       
  1056 	}
       
  1057 
       
  1058 
       
  1059 TBool CBTTestConnection::SendComplete(TInt aIndex, TInt aStatus)
       
  1060 	{
       
  1061 	if(aStatus != KErrNone)
       
  1062 		{
       
  1063 		iParent->test.Printf(_L("\nSend[%d] Completed with Error: %d.\n"), aIndex, aStatus);
       
  1064 		return EFalse;
       
  1065 		}
       
  1066 	return ETrue;
       
  1067 	}
       
  1068 
       
  1069 TBool CBTTestConnection::RecvComplete(TInt aIndex, TInt aStatus, TInt aDataErr)
       
  1070 	{
       
  1071 	TBool rCode = ETrue;
       
  1072 	if(aStatus != KErrNone)
       
  1073 		{
       
  1074 		iParent->test.Printf(_L("\nRevc[%d] Completed with Error: %d.\n"), aIndex, aStatus);
       
  1075 		rCode = EFalse;
       
  1076 		}
       
  1077 	else
       
  1078 		{
       
  1079 		if(aDataErr == KErrCompletion)
       
  1080 			{
       
  1081 			iDataDialogCount++;
       
  1082 			}
       
  1083 		else
       
  1084 			{
       
  1085 			if(aDataErr != KErrNone)
       
  1086 				{
       
  1087 				iParent->test.Printf(_L("\nRevc[%d] Completed. Data Error.\n"), aIndex);
       
  1088 				rCode = EFalse;
       
  1089 				}
       
  1090 			}
       
  1091 		}
       
  1092 	return rCode;
       
  1093 	}
       
  1094 
       
  1095 
       
  1096 TInt CBTTestConnection::RequestLPM(TConnProfile::TConnMode aLPM)
       
  1097 	{
       
  1098 	TInt rerr = KErrNone;
       
  1099 
       
  1100 	switch(aLPM)
       
  1101 		{
       
  1102 		case TConnProfile::EActive:
       
  1103 			if(iProfile.iIsSocketBased)
       
  1104 				{
       
  1105 				__ASSERT_DEBUG(iBTSocket, Panic(EBTConsoleNoSocketForSocketBasedConnection));
       
  1106 				rerr = iBTSocket->CancelLowPowerModeRequester();
       
  1107 				}
       
  1108 			else
       
  1109 				{
       
  1110 				rerr = iPhyLinkAdapter.CancelLowPowerModeRequester();
       
  1111 				}
       
  1112 			break;
       
  1113 
       
  1114 		case TConnProfile::ESniff:
       
  1115 			if(iProfile.iIsSocketBased)
       
  1116 				{
       
  1117 				__ASSERT_DEBUG(iBTSocket, Panic(EBTConsoleNoSocketForSocketBasedConnection));
       
  1118 				rerr = iBTSocket->ActivateSniffRequester();
       
  1119 				}
       
  1120 			else
       
  1121 				{
       
  1122 				rerr = iPhyLinkAdapter.ActivateSniffRequester();
       
  1123 				}
       
  1124 			break;
       
  1125 
       
  1126 		case TConnProfile::EPark:
       
  1127 			if(iProfile.iIsSocketBased)
       
  1128 				{
       
  1129 				__ASSERT_DEBUG(iBTSocket, Panic(EBTConsoleNoSocketForSocketBasedConnection));
       
  1130 				rerr = iBTSocket->ActivateParkRequester();
       
  1131 				}
       
  1132 			else
       
  1133 				{
       
  1134 				rerr = iPhyLinkAdapter.ActivateParkRequester();
       
  1135 				}
       
  1136 			break;
       
  1137 
       
  1138 		case TConnProfile::EExplicitActive:
       
  1139 			if(iProfile.iIsSocketBased)
       
  1140 				{
       
  1141 				Panic(EBTConsoleActivateActiveRequesterCalledOnCBluetoothSocket);
       
  1142 				}
       
  1143 			else
       
  1144 				{
       
  1145 				rerr = iPhyLinkAdapter.ActivateActiveRequester();
       
  1146 				}
       
  1147 			break;
       
  1148 
       
  1149 		default:
       
  1150 			iParent->test.Printf(_L("Request for mode %S not handled."), &TConnProfile::ModeName(aLPM));
       
  1151 			break;	
       
  1152 		};
       
  1153 	iParent->test.Printf(_L("%S Request Issued. Error: %d"), &TConnProfile::ModeName(aLPM), rerr);
       
  1154 	return rerr;
       
  1155 	}
       
  1156 
       
  1157 TInt CBTTestConnection::RemoveLPMRequest()
       
  1158 	{
       
  1159 	TInt rerr = KErrNone;
       
  1160 		
       
  1161 	if(iProfile.iIsSocketBased)
       
  1162 		{
       
  1163 		__ASSERT_DEBUG(iBTSocket, Panic(EBTConsoleNoSocketForSocketBasedConnection));
       
  1164 		rerr = iBTSocket->CancelLowPowerModeRequester();
       
  1165 		}
       
  1166 	else
       
  1167 		{
       
  1168 		rerr = iPhyLinkAdapter.CancelLowPowerModeRequester();
       
  1169 		}
       
  1170 		
       
  1171 	if(rerr == KErrNone)
       
  1172 		{
       
  1173 		iProfile.iMode2 = TConnProfile::EActive;
       
  1174 		}
       
  1175 
       
  1176 	iParent->test.Printf(_L("Low Power Mode Request Cleared. Error: %d"), rerr);
       
  1177 	return rerr;
       
  1178 	}
       
  1179 	
       
  1180 	
       
  1181 TInt CBTTestConnection::SupportLPM(TBTLinkMode aLPM) 
       
  1182 	{
       
  1183 	TInt rerr = KErrNone;
       
  1184 	if(iProfile.iIsSocketBased)
       
  1185 		{
       
  1186 		rerr = KErrNotFound;
       
  1187 		if(iBTSocket)
       
  1188 			{
       
  1189 			rerr = iBTSocket->AllowLowPowerModes(aLPM);
       
  1190 			}
       
  1191 		}
       
  1192 	else
       
  1193 		{
       
  1194 		rerr = iPhyLinkAdapter.AllowLowPowerModes(aLPM);
       
  1195 		}
       
  1196 
       
  1197 	iParent->test.Printf(_L("Request to support %S. Error: %d"), &TConnProfile::ModeName(aLPM), rerr);
       
  1198 	return rerr;
       
  1199 	}
       
  1200 
       
  1201 
       
  1202 TInt CBTTestConnection::PreventLPM(TBTLinkMode aLPM) 
       
  1203 	{
       
  1204 	TInt rerr = KErrNone;
       
  1205 	if(iProfile.iIsSocketBased)
       
  1206 		{
       
  1207 		rerr = KErrNotFound;
       
  1208 		if(iBTSocket)
       
  1209 			{
       
  1210 			rerr = iBTSocket->PreventLowPowerModes(aLPM);
       
  1211 			}
       
  1212 		}
       
  1213 	else
       
  1214 		{
       
  1215 		rerr = iPhyLinkAdapter.PreventLowPowerModes(aLPM);
       
  1216 		}
       
  1217 	iParent->test.Printf(_L("Request to prevent %S. Error: %d"), &TConnProfile::ModeName(aLPM), rerr);
       
  1218 	return rerr;
       
  1219 	}
       
  1220 
       
  1221 TInt CBTTestConnection::KillAllLinks(TInt /*aReason*/)
       
  1222 	{
       
  1223 	TInt rerr = KErrNone;
       
  1224 	if(!iBTPhyLinks)
       
  1225 		{
       
  1226 		TRAP(rerr, iBTPhyLinks = CBluetoothPhysicalLinks::NewL(*this, iSocketServer));
       
  1227 		}
       
  1228 
       
  1229 	if(rerr == KErrNone)
       
  1230 		{
       
  1231 		rerr = iBTPhyLinks->DisconnectAll();
       
  1232 		}
       
  1233 		
       
  1234 	return rerr;
       
  1235 	}
       
  1236 
       
  1237 TInt CBTTestConnection::KillLink(TInt /*aReason*/)
       
  1238 	{
       
  1239 	TInt rerr = KErrNone;
       
  1240 	if(!iBTPhyLinks)
       
  1241 		{
       
  1242 		TRAP(rerr, iBTPhyLinks = CBluetoothPhysicalLinks::NewL(*this, iSocketServer));
       
  1243 		}
       
  1244 	if(rerr == KErrNone)
       
  1245 		{
       
  1246 		rerr = iBTPhyLinks->Disconnect(iProfile.iRemoteBTAddr.BTAddr());
       
  1247 		}
       
  1248 		
       
  1249 	return rerr;
       
  1250 	}
       
  1251 
       
  1252 TInt CBTTestConnection::ToggleAutoSniff()
       
  1253 	{
       
  1254 	TInt rerr = KErrNone;
       
  1255 
       
  1256 	iAutoSniff = !iAutoSniff;
       
  1257 	
       
  1258 	rerr = iBTSocket->SetAutomaticSniffMode(iAutoSniff);
       
  1259 	if (!rerr)
       
  1260 		{
       
  1261 		iProfile.iAutoSniffActive = iAutoSniff;
       
  1262 		}
       
  1263 
       
  1264 		
       
  1265 	return rerr;
       
  1266 	}
       
  1267 
       
  1268 TInt CBTTestConnection::PassiveSCO()
       
  1269 	{
       
  1270 	TInt rerr = KErrNone;
       
  1271 	iProfile.iIsSocketBased = EFalse;
       
  1272 	if(!iBTSyncLink)
       
  1273 		{
       
  1274 		TRAP(rerr, iBTSyncLink = CBluetoothSynchronousLink::NewL(iSyncLinkHandler, iSocketServer));
       
  1275 		}
       
  1276 	if(rerr == KErrNone)
       
  1277 		{	                                               
       
  1278 		rerr = iBTSyncLink->AcceptConnection();
       
  1279 		}
       
  1280 
       
  1281 	iProfile.iIsSCO = ETrue;
       
  1282 	iProfile.iState = (rerr == KErrNone) ? TConnProfile::EConnAccepting :
       
  1283 	                                       TConnProfile::EConnFailed;
       
  1284 	iProfile.iErrorCode = rerr;		
       
  1285 
       
  1286 	return rerr;
       
  1287 	}
       
  1288 
       
  1289 TInt CBTTestConnection::ActiveSCO(TBTDevAddr& aAddr)
       
  1290 	{
       
  1291 	TInt rerr = KErrNone;
       
  1292 	iProfile.iIsSocketBased = EFalse;
       
  1293 	if(!iBTSyncLink)
       
  1294 		{
       
  1295 		TRAP(rerr, iBTSyncLink = CBluetoothSynchronousLink::NewL(iSyncLinkHandler, iSocketServer));
       
  1296 		}
       
  1297 	if(rerr == KErrNone)
       
  1298 		{
       
  1299 		rerr = iBTSyncLink->SetupConnection(aAddr);
       
  1300 		iProfile.iRemoteBTAddr.SetBTAddr(aAddr);
       
  1301 		}
       
  1302 
       
  1303 	iProfile.iIsSCO = ETrue;
       
  1304 	iProfile.iState = (rerr == KErrNone) ? TConnProfile::EConnConnecting :
       
  1305 	                                       TConnProfile::EConnFailed;
       
  1306 	iProfile.iErrorCode = rerr;		
       
  1307 
       
  1308 	return rerr;
       
  1309 	}
       
  1310 
       
  1311 TInt CBTTestConnection::PassiveESCO()
       
  1312 	{
       
  1313 	TInt rerr = KErrNone;
       
  1314 	iProfile.iIsSocketBased = EFalse;
       
  1315 	if(!iBTSyncLink)
       
  1316 		{
       
  1317 		TRAP(rerr, iBTSyncLink = CBluetoothSynchronousLink::NewL(iSyncLinkHandler, iSocketServer));
       
  1318 		}
       
  1319 	if(rerr == KErrNone)
       
  1320 		{ 
       
  1321 		rerr = iBTSyncLink->AcceptConnection(TBTSyncPackets(TBTSyncPackets::ESyncAnySCOPacket | 
       
  1322 		                                                    TBTSyncPackets::ESyncAnyESCOPacket));		                                               
       
  1323 		}
       
  1324 
       
  1325 	iProfile.iIsSCO = ETrue;
       
  1326 	iProfile.iState = (rerr == KErrNone) ? TConnProfile::EConnAccepting :
       
  1327 	                                       TConnProfile::EConnFailed;
       
  1328 	iProfile.iErrorCode = rerr;		
       
  1329 
       
  1330 	return rerr;
       
  1331 	}
       
  1332 
       
  1333 TInt CBTTestConnection::ActiveESCO(TBTDevAddr& aAddr)
       
  1334 	{
       
  1335 	TInt rerr = KErrNone;
       
  1336 	iProfile.iIsSocketBased = EFalse;
       
  1337 	if(!iBTSyncLink)
       
  1338 		{
       
  1339 		TRAP(rerr, iBTSyncLink = CBluetoothSynchronousLink::NewL(iSyncLinkHandler, iSocketServer));
       
  1340 		}
       
  1341 	if(rerr == KErrNone)
       
  1342 		{
       
  1343 		iBTSyncLink->SetupConnection(aAddr,TBTSyncPackets(TBTSyncPackets::ESyncAnyESCOPacket));
       
  1344 		iProfile.iRemoteBTAddr.SetBTAddr(aAddr);
       
  1345 		}
       
  1346 
       
  1347 	iProfile.iIsSCO = ETrue;
       
  1348 	iProfile.iState = (rerr == KErrNone) ? TConnProfile::EConnConnecting :
       
  1349 	                                       TConnProfile::EConnFailed;
       
  1350 	iProfile.iErrorCode = rerr;		
       
  1351 
       
  1352 	return rerr;
       
  1353 	}
       
  1354 	
       
  1355 void CBTTestConnection::StoreEvent(TBTBasebandEventNotification & aEvent)
       
  1356 	{
       
  1357 	TBTQueuedBasebandEventNotification * e = new TBTQueuedBasebandEventNotification(aEvent);
       
  1358 	iEventNotificationQueue.AddLast(*e);
       
  1359 	}
       
  1360 
       
  1361 TBool CBTTestConnection::PrintEvents(TInt aCurrentEvent, TInt aNumEvents)
       
  1362 	{
       
  1363 	iParent->DrawConnections();
       
  1364 	iParent->test.Printf(_L("\n\n ----------- Event List -----------\n"));
       
  1365 	
       
  1366 	TInt count = 0;
       
  1367 	
       
  1368 	if(iEventNotificationQueue.IsEmpty())
       
  1369 		{
       
  1370 		return ETrue;
       
  1371 		}
       
  1372 
       
  1373 	TSglQueIter<TBTQueuedBasebandEventNotification> iter(iEventNotificationQueue);
       
  1374 	while (iter && count < (aCurrentEvent + aNumEvents))
       
  1375 		{
       
  1376 		TBTQueuedBasebandEventNotification * e = iter++;
       
  1377 		if(count++ < aCurrentEvent)
       
  1378 			{
       
  1379 			continue;
       
  1380 			}
       
  1381 
       
  1382 		if(ENotifyMaster & e->EventType())
       
  1383 			{
       
  1384 			iParent->test.Printf(_L("Role changed to MASTER."));
       
  1385 			}
       
  1386 		if(ENotifySlave & e->EventType())
       
  1387 			{
       
  1388 			iParent->test.Printf(_L("Role changed to SLAVE."));
       
  1389 			}
       
  1390 
       
  1391 		if(ENotifyActiveMode & e->EventType())
       
  1392 			{
       
  1393 			iParent->test.Printf(_L("Mode changed to ACTIVE."));
       
  1394 			}
       
  1395 		if(ENotifySniffMode & e->EventType())
       
  1396 			{
       
  1397 			iParent->test.Printf(_L("Mode changed to SNIFF."));
       
  1398 			}
       
  1399 		if(ENotifyParkMode & e->EventType())
       
  1400 			{
       
  1401 			iParent->test.Printf(_L("Mode changed to PARK."));
       
  1402 			}
       
  1403 		if(ENotifyHoldMode & e->EventType())
       
  1404 			{
       
  1405 			iParent->test.Printf(_L("Mode changed to HOLD."));
       
  1406 			}
       
  1407 
       
  1408 		if(ENotifyMaxSlots1 & e->EventType())
       
  1409 			{
       
  1410 			iParent->test.Printf(_L("Max Slots changed to 1."));
       
  1411 			}
       
  1412 		if(ENotifyMaxSlots3 & e->EventType())
       
  1413 			{
       
  1414 			iParent->test.Printf(_L("Max Slots changed to 3."));
       
  1415 			}
       
  1416 		if(ENotifyMaxSlots5 & e->EventType())
       
  1417 			{
       
  1418 			iParent->test.Printf(_L("Max Slots changed to 5."));
       
  1419 			}
       
  1420 
       
  1421 		if(ENotifyPacketsDM1 & e->EventType() ||
       
  1422 		   ENotifyPacketsDM3 & e->EventType() ||
       
  1423 		   ENotifyPacketsDM5 & e->EventType() ||	
       
  1424 		   ENotifyPacketsDH1 & e->EventType() ||	
       
  1425 		   ENotifyPacketsDH3 & e->EventType() ||	
       
  1426 		   ENotifyPacketsDH5 & e->EventType())
       
  1427 			{
       
  1428 			iParent->test.Printf(_L("Packet Types now supported: "));
       
  1429 
       
  1430 			if(ENotifyPacketsDM1 & e->EventType())
       
  1431 				{
       
  1432 				iParent->test.Printf(_L("DM1 "));				
       
  1433 				}
       
  1434 			if(ENotifyPacketsDM3 & e->EventType())
       
  1435 				{
       
  1436 				iParent->test.Printf(_L("DM3 "));
       
  1437 				}
       
  1438 			if(ENotifyPacketsDM5 & e->EventType())
       
  1439 				{
       
  1440 				iParent->test.Printf(_L("DM5 "));
       
  1441 				}
       
  1442 			if(ENotifyPacketsDH1 & e->EventType())
       
  1443 				{
       
  1444 				iParent->test.Printf(_L("DH1 "));
       
  1445 				}
       
  1446 			if(ENotifyPacketsDH3 & e->EventType())
       
  1447 				{
       
  1448 				iParent->test.Printf(_L("DH3 "));
       
  1449 				}
       
  1450 			if(ENotifyPacketsDH5 & e->EventType())
       
  1451 				{
       
  1452 				iParent->test.Printf(_L("DH5 "));
       
  1453 				}
       
  1454 			}
       
  1455 
       
  1456 		if(ENotifyAuthenticationComplete & e->EventType())
       
  1457 			{
       
  1458 			iParent->test.Printf(_L("Authentification complete."));
       
  1459 			}
       
  1460 
       
  1461 		if(ENotifyEncryptionChangeOn & e->EventType())
       
  1462 			{
       
  1463 			iParent->test.Printf(_L("Encryption Enabled."));
       
  1464 			}
       
  1465 		if(ENotifyEncryptionChangeOff & e->EventType())
       
  1466 			{
       
  1467 			iParent->test.Printf(_L("Encryption Disabled."));
       
  1468 			}
       
  1469 
       
  1470 		if(ENotifyPhysicalLinkUp & e->EventType())
       
  1471 			{
       
  1472 			iParent->test.Printf(_L("Physical Link Up."));
       
  1473 			}
       
  1474 		if(ENotifyPhysicalLinkDown & e->EventType())
       
  1475 			{
       
  1476 			iParent->test.Printf(_L("Physical Link Down."));
       
  1477 			}
       
  1478 		if(ENotifyPhysicalLinkError & e->EventType())
       
  1479 			{
       
  1480 			iParent->test.Printf(_L("Physical Link Error."));
       
  1481 			}
       
  1482 		
       
  1483  		if(ENotifySynchronousLinkUp & e->EventType())
       
  1484  			{
       
  1485  			iParent->test.Printf(_L("Synchronous Link Up."));
       
  1486  			}
       
  1487  
       
  1488  		if(ENotifySynchronousLinkDown & e->EventType())
       
  1489  			{
       
  1490  			iParent->test.Printf(_L("Synchronous Link Down."));
       
  1491  			}
       
  1492    
       
  1493  		if(ENotifySynchronousLinkError & e->EventType())
       
  1494  			{
       
  1495  			iParent->test.Printf(_L("Synchronous Link Error."));
       
  1496  			}
       
  1497 
       
  1498 		iParent->test.Printf(_L("  - Error Code: %d\n"), e->ErrorCode());
       
  1499 		}
       
  1500 
       
  1501 	if(iter)
       
  1502 		{
       
  1503 		return (count < (aCurrentEvent + aNumEvents));
       
  1504 		}
       
  1505 	else
       
  1506 		{
       
  1507 		return ETrue;
       
  1508 		}
       
  1509 	}
       
  1510 
       
  1511 void CBTTestConnection::ClearEventStore()
       
  1512 	{
       
  1513 	TSglQueIter<TBTQueuedBasebandEventNotification> iter(iEventNotificationQueue);
       
  1514 	while (iter)
       
  1515 		{
       
  1516 		TBTQueuedBasebandEventNotification * e = iter++;
       
  1517 		iEventNotificationQueue.Remove(*e);
       
  1518 		delete e;
       
  1519 		}
       
  1520 	}
       
  1521 
       
  1522 void CBTTestConnection::HandleConnectCompleteL(TInt aErr)
       
  1523 	{
       
  1524 	ConnectComplete(aErr);
       
  1525 	}
       
  1526 
       
  1527 void CBTTestConnection::HandleAcceptCompleteL(TInt aErr)
       
  1528 	{
       
  1529 	AcceptComplete(aErr);
       
  1530 	}
       
  1531 
       
  1532 void CBTTestConnection::HandleShutdownCompleteL(TInt aErr)
       
  1533 	{
       
  1534 	iParent->test.Printf(_L("Shutdown Complete. Error[%d]."), aErr);
       
  1535 	}
       
  1536 
       
  1537 void CBTTestConnection::HandleSendCompleteL(TInt aErr)
       
  1538 	{
       
  1539 	TBool ok = ETrue;
       
  1540 	switch(iProfile.iData)
       
  1541 		{
       
  1542 		case TConnProfile::EDataIdle:
       
  1543 			if(aErr == KErrCancel)
       
  1544 				{
       
  1545 				iParent->test.Printf(_L("Send Cancelled. Data[%d]."), iDataDialogCount);
       
  1546 				}
       
  1547 			else
       
  1548 				{
       
  1549 				__DEBUGGER();
       
  1550 				}
       
  1551 			break;
       
  1552 			
       
  1553 		case TConnProfile::EDataDialog1:
       
  1554 		case TConnProfile::EDataDialog2:
       
  1555 		case TConnProfile::EDataSend:
       
  1556 		case TConnProfile::EDataSendReceive:
       
  1557 
       
  1558 			ok = SendComplete(iDataDialogCount++, aErr);
       
  1559 
       
  1560 			if(aErr == KErrDisconnected)
       
  1561 				{
       
  1562 				iProfile.iState = TConnProfile::EConnServerDisconnected;
       
  1563 				}
       
  1564 
       
  1565 			if(ok) 
       
  1566 				{
       
  1567 				if (iProfile.iData == TConnProfile::EDataSendReceive)
       
  1568 					{
       
  1569 					DoSend(TUint8(iDataDialogCount&0xff));
       
  1570 					}
       
  1571 				else
       
  1572 					{
       
  1573 					ContinueDialog();					
       
  1574 					}
       
  1575 				}
       
  1576 			else
       
  1577 				{
       
  1578 				iProfile.iData = TConnProfile::EDataFailed;
       
  1579 				}
       
  1580 			break;
       
  1581 
       
  1582 		case TConnProfile::EDataSendOneShot:
       
  1583 			iParent->test.Printf(_L("\nOne Shot Send Completed with Error: %d.\n"), aErr);
       
  1584 			iProfile.iData = TConnProfile::EDataIdle;
       
  1585 			break;
       
  1586 					
       
  1587 		case TConnProfile::EDataRecv:
       
  1588 		case TConnProfile::EDataRecvOneShot:
       
  1589 			__DEBUGGER();
       
  1590 			break;
       
  1591 		case TConnProfile::ERecvContinuationData:
       
  1592 			__DEBUGGER();
       
  1593 			break;
       
  1594 		default:
       
  1595 			iParent->test.Printf(_L("\nData Send Completed invalid state [%d], Error [%d]\n"), 
       
  1596 			                     iProfile.iData, aErr);
       
  1597 			break;		
       
  1598 		};
       
  1599 	}
       
  1600 	
       
  1601 void CBTTestConnection::HandleReceiveCompleteL(TInt aErr)
       
  1602 	{
       
  1603 	switch(iProfile.iData)
       
  1604 		{
       
  1605 		case TConnProfile::EDataIdle:
       
  1606 			if(aErr == KErrCancel)
       
  1607 				{
       
  1608 				iParent->test.Printf(_L("Recv Cancelled. Data[%d]."), iDataDialogCount);
       
  1609 				}
       
  1610 			else
       
  1611 				{
       
  1612 				__DEBUGGER();
       
  1613 				}
       
  1614 			break;
       
  1615 			
       
  1616 		case TConnProfile::EDataDialog1:
       
  1617 		case TConnProfile::EDataDialog2:
       
  1618 		case TConnProfile::EDataRecv:
       
  1619 		case TConnProfile::EDataRecvAny:
       
  1620 		case TConnProfile::EDataSendReceive:
       
  1621 			{
       
  1622 			TBool ok = RecvComplete(iDataDialogCount, aErr, CheckRecvData());
       
  1623 			
       
  1624 			if(aErr == KErrDisconnected)
       
  1625 				{
       
  1626 				iProfile.iState = TConnProfile::EConnServerDisconnected;
       
  1627 				}
       
  1628 
       
  1629 			if(ok) 
       
  1630 				{
       
  1631 				TInt len = iRecvBuffer.Length();
       
  1632 //				iParent->test.Printf(_L("\nRecv Completed.  Length[%d], Value[%d]\n"), len, iRecvBuffer[0]);
       
  1633 
       
  1634 				if(!(iDataDialogCount & 0xff))
       
  1635 					{
       
  1636 					TTime temp;
       
  1637 					temp.HomeTime();
       
  1638 					TTimeIntervalMicroSeconds diff = temp.MicroSecondsFrom(iTime);
       
  1639 
       
  1640 					iParent->test.Printf(_L("\nRecv data %d"), diff.Int64());
       
  1641 					iTime.HomeTime();
       
  1642 					}
       
  1643 
       
  1644 				if (iProfile.iData == TConnProfile::EDataSendReceive)
       
  1645 					{
       
  1646 					DoRecv();
       
  1647 					}
       
  1648 				else
       
  1649 					{
       
  1650 					ContinueDialog();					
       
  1651 					}
       
  1652 				}
       
  1653 			else
       
  1654 				{
       
  1655 				iProfile.iData = TConnProfile::EDataFailed;
       
  1656 				}
       
  1657 			}
       
  1658 			break;
       
  1659 
       
  1660 		case TConnProfile::EDataRecvOneShot:
       
  1661 			{
       
  1662 			iParent->test.Printf(_L("\nOne Shot Recv Completed with Error: %d.\n"), aErr);
       
  1663 			if(aErr == KErrNone)
       
  1664 				{
       
  1665 				TInt bufLen = iRecvBuffer.Length();
       
  1666 				if((bufLen - 1)%10 != iRecvBuffer[bufLen - 1])
       
  1667 					{
       
  1668 					iParent->test.Printf(_L("\nData Error: Invalid Data Payload. Recv Byte 0[%d], Recv End %d[%d]\n"),
       
  1669 		                                    iRecvBuffer[0], bufLen, iRecvBuffer[bufLen - 1]);
       
  1670 					}
       
  1671 				else
       
  1672 					{
       
  1673 					iParent->test.Printf(_L("\nOne Shot Recv Completed.  Length[%d], Value[%d]\n"), bufLen, iRecvBuffer[0]);
       
  1674 					}
       
  1675 				iProfile.iData = TConnProfile::EDataIdle;
       
  1676 				}
       
  1677 			}
       
  1678 			break;
       
  1679 						
       
  1680 		case TConnProfile::EDataSend:
       
  1681 		case TConnProfile::EDataSendOneShot:
       
  1682 			__DEBUGGER();
       
  1683 			break;
       
  1684 		case TConnProfile::ERecvContinuationData:
       
  1685 			{
       
  1686 			iParent->test.Printf(_L("\nData Recv Completed with Error: %d."), aErr);
       
  1687 			if(aErr == KErrNone)
       
  1688 				{
       
  1689 				iParent->test.Printf(_L("\nThe Recv Data Sequence is: \n"));
       
  1690 				TInt len = iCustomSendRecvBuffer.Length();
       
  1691 				for(TInt i = 0;i<len;i++)
       
  1692 					{
       
  1693 					iParent->test.Printf(_L("%d"),iCustomSendRecvBuffer[i]);
       
  1694 					}
       
  1695 				iTotalRecvByte += len;
       
  1696 
       
  1697 				iParent->test.Printf(_L("\n\n%x bytes recieved this time.\n"),len);
       
  1698 
       
  1699 				iParent->test.Printf(_L("%x bytes recieved so far.\n"),iTotalRecvByte);
       
  1700 
       
  1701 				iParent->test.Printf(_L("%x bytes left in buffer.\n"),iRecvBufferLength[0]);
       
  1702 
       
  1703 				iParent->test.Printf(_L("%x bytes in total.\n"),iRecvBufferLength[0]+iTotalRecvByte);
       
  1704 				/*
       
  1705 				iTailDigit == -1 when receiving data for the first time,
       
  1706 				Otherwise, it equals to the last digit from previous receive 
       
  1707 				*/
       
  1708 				if(iTailDigit != -1)
       
  1709 					{
       
  1710 					if((iTailDigit+1)%10 == iCustomSendRecvBuffer[0])
       
  1711 						{
       
  1712 						iParent->test.Printf(_L("\nData are continuous.\n"));
       
  1713 						}
       
  1714 					else
       
  1715 						{
       
  1716 						iParent->test.Printf(_L("\nData are lost during transfer.\nContinuation is broken!"));
       
  1717 						}
       
  1718 					}
       
  1719 				if (iRecvBufferLength[0] == 0)
       
  1720 					{
       
  1721 					iTailDigit = -1;
       
  1722 					iTotalRecvByte = 0;
       
  1723 					}
       
  1724 				else
       
  1725 					{
       
  1726 					iTailDigit = iCustomSendRecvBuffer[len - 1];
       
  1727 					}
       
  1728 					
       
  1729 				//if there is anything left in the buffer to receive
       
  1730 				if(iRecvBufferLength[0] != 0)
       
  1731 					RecvContinuationData(len);
       
  1732 				//buffer is empty, stop receiving
       
  1733 				else
       
  1734 					iProfile.iData = TConnProfile::EDataIdle;
       
  1735 				}
       
  1736 			break;
       
  1737 			}
       
  1738 		default:
       
  1739 			iParent->test.Printf(_L("\nData Recv Completed invalid state [%d], Error [%d]\n"), 
       
  1740 			                     iProfile.iData, aErr);
       
  1741 			break;		
       
  1742 		};
       
  1743 	}
       
  1744 
       
  1745 
       
  1746 void CBTTestConnection::HandleIoctlCompleteL(TInt aErr)
       
  1747 	{
       
  1748 	switch(iCurrentIOCTL)
       
  1749 		{
       
  1750 		case ERFCOMMConfigInd:
       
  1751 			{
       
  1752 			iParent->test.Printf(_L("RFCOMM Config Ind Ioctl Complete. Error[%d].\n"), aErr);
       
  1753 
       
  1754 			TUint8 modemStatus = 0;
       
  1755 			TPckgBuf<TUint8> pkg(modemStatus);
       
  1756 			TInt err = iBTSocket->GetOpt(KRFCOMMLocalModemStatus, KSolBtRFCOMM, pkg);
       
  1757 			modemStatus = pkg();
       
  1758 			iParent->test.Printf(_L("\nLocalModemStatus: Err = %d, Status = %x"), err, modemStatus);
       
  1759 			}
       
  1760 			break;
       
  1761 
       
  1762 		default:	
       
  1763 			iParent->test.Printf(_L("Ioctl Complete. Error[%d]."), aErr);
       
  1764 			break;
       
  1765 		};
       
  1766 	}
       
  1767 
       
  1768 void CBTTestConnection::HandleActivateBasebandEventNotifierCompleteL(TInt aErr, TBTBasebandEventNotification& aEventNotification)
       
  1769 	{
       
  1770 	if(aErr == KErrNone)
       
  1771 		{
       
  1772 		OutputEventNotification(aEventNotification);
       
  1773 		}
       
  1774 	else
       
  1775 		{
       
  1776 		iParent->test.Printf(_L("Event Notifier Complete. Error[%d]."), aErr);
       
  1777 		}
       
  1778 	}
       
  1779 
       
  1780 // MBluetoothPhysicalLinksNotifier definitions
       
  1781 void CBTTestConnection::HandleCreateConnectionCompleteL(TInt aErr)
       
  1782 	{
       
  1783 	ConnectBAPComplete(aErr);
       
  1784 	}
       
  1785 
       
  1786 void CBTTestConnection::HandleDisconnectCompleteL(TInt aErr)
       
  1787 	{
       
  1788 	iParent->test.Printf(_L("Disconnect Complete. Error[%d]."), aErr);
       
  1789 	}
       
  1790 
       
  1791 void CBTTestConnection::HandleDisconnectAllCompleteL(TInt aErr)
       
  1792 	{
       
  1793 	iParent->test.Printf(_L("Disconnect All Complete. Error[%d]."), aErr);
       
  1794 	}
       
  1795 
       
  1796 // MBluetoothSynchronousLinkNotifier definitions
       
  1797 void CBTTestConnection::HandleSyncSetupConnectionCompleteL(TInt aErr)
       
  1798 	{
       
  1799 	if(aErr != KErrNone)
       
  1800 		{
       
  1801 		iParent->test.Printf(_L("\nSCO(eSCO) Connection Completed with error: %d"), aErr);
       
  1802 		iProfile.iState = TConnProfile::EConnFailed;
       
  1803 		iProfile.iErrorCode = aErr;
       
  1804 		}
       
  1805 	else
       
  1806 		{
       
  1807 		iProfile.iState = TConnProfile::EConnConnected;
       
  1808 		}
       
  1809 	iParent->Draw();
       
  1810 	}
       
  1811 	
       
  1812 void CBTTestConnection::HandleSyncDisconnectionCompleteL(TInt aErr)
       
  1813 	{
       
  1814 	iParent->test.Printf(_L("HandleSyncDisconnectionCompleteL. Error[%d]."), aErr);
       
  1815 	}
       
  1816 
       
  1817 void CBTTestConnection::HandleSyncAcceptConnectionCompleteL(TInt aErr)
       
  1818 	{
       
  1819 	if(aErr != KErrNone)
       
  1820 		{
       
  1821 		iParent->test.Printf(_L("\nSCO(eSCO) Accept Completed with error: %d"), aErr);
       
  1822 		iProfile.iState = TConnProfile::EConnFailed;
       
  1823 		iProfile.iErrorCode = aErr;
       
  1824 		}
       
  1825 	else
       
  1826 		{
       
  1827 		iBTSyncLink->RemoteName(iProfile.iRemoteBTAddr);
       
  1828 		iProfile.iState = TConnProfile::EConnConnected;
       
  1829 		}
       
  1830 	iParent->Draw();
       
  1831 	}
       
  1832 
       
  1833 void CBTTestConnection::HandleSyncSendCompleteL(TInt aErr)
       
  1834 	{
       
  1835 	iParent->test.Printf(_L("HandleSyncSendCompleteL. Error[%d]."), aErr);	
       
  1836 	}
       
  1837 
       
  1838 void CBTTestConnection::HandleSyncReceiveCompleteL(TInt aErr)
       
  1839 	{
       
  1840 	iParent->test.Printf(_L("HandleSyncReceiveCompleteL. Error[%d]."), aErr);	
       
  1841 	}
       
  1842 
       
  1843 void CBTTestConnection::MbplmoRssiChanged(TInt8 aRssi)
       
  1844 	{
       
  1845 	iMetricsConsole->Printf(_L("RSSI: %d\n"), aRssi);
       
  1846 	}
       
  1847 
       
  1848 void CBTTestConnection::MbplmoLinkQualityChanged(TUint8 aLinkQuality)
       
  1849 	{
       
  1850 	iMetricsConsole->Printf(_L("Link Quality: %d\n"), aLinkQuality);
       
  1851 	}
       
  1852 
       
  1853 void CBTTestConnection::MbplmoFailedContactCounterChanged(TUint16 aFailedContactCounter)
       
  1854 	{
       
  1855 	iMetricsConsole->Printf(_L("Failed Contact Counter: %d\n"), aFailedContactCounter);
       
  1856 	}
       
  1857 
       
  1858 void CBTTestConnection::MbplmoTransmitPowerLevelChanged(TInt8 aTransmitPowerLevel)
       
  1859 	{
       
  1860 	iMetricsConsole->Printf(_L("Transmit Power Level: %d\n"), aTransmitPowerLevel);
       
  1861 	}
       
  1862 
       
  1863 void CBTTestConnection::MbplmoError(TInt aError)
       
  1864 	{
       
  1865 	iMetricsConsole->Printf(_L("Error received: %d\n"), aError);
       
  1866 	}
       
  1867 
       
  1868 TInt CBTTestConnection::CheckRecvData()
       
  1869 	{
       
  1870 	TInt rerr = KErrCompletion;
       
  1871 
       
  1872 	if(iProfile.iIsStreamProtocol)
       
  1873 		{
       
  1874 		TInt newLength = iStreamRecvBuffer.Length() + iRecvBuffer.Length();
       
  1875 		if(newLength > iProfile.iRecvMTUSize)
       
  1876 			{
       
  1877 			iParent->test.Printf(_L("\nData Error: Stream Buffer error. Expected[Actual] Size = %d[%d]"),
       
  1878 			                     iProfile.iRecvMTUSize, newLength);
       
  1879 			iStreamRecvBuffer.Zero();
       
  1880 			rerr = KErrOverflow;
       
  1881 			}
       
  1882 		else
       
  1883 			{
       
  1884 			iStreamRecvBuffer.Append(iRecvBuffer);
       
  1885 
       
  1886 			if(newLength == iProfile.iRecvMTUSize)
       
  1887 				{
       
  1888 				iRecvBuffer = iStreamRecvBuffer;
       
  1889 				iStreamRecvBuffer.Zero();
       
  1890 				}
       
  1891 			else
       
  1892 				{
       
  1893 				rerr = KErrNone;
       
  1894 				}
       
  1895 			}
       
  1896 		}
       
  1897 
       
  1898 	// Skip data checks if we're doing '/dev/null' style receive.
       
  1899 	if (iProfile.iData != TConnProfile::EDataRecvAny && iProfile.iData != TConnProfile::EDataSendReceive)
       
  1900 		{
       
  1901 		// Check that the packet is the expected length,
       
  1902 		// encoded in bytes 1 and 2 of the received packet
       
  1903 		if(rerr == KErrCompletion)
       
  1904 			{
       
  1905 			TUint16 expectedLength = 0;
       
  1906 			expectedLength  = iRecvBuffer[2];        // Lo byte of expected length in byte 2
       
  1907 			expectedLength += iRecvBuffer[1] << 8;   // Hi byte of expected length in byte 1
       
  1908 			if (expectedLength != iRecvBuffer.Length())
       
  1909 				{
       
  1910 				iParent->test.Printf(_L("\nData Error: Invalid Data Payload. Expected length %d received length %d"),
       
  1911 				                        expectedLength, iRecvBuffer.Length());
       
  1912 				if (iRecvBuffer.Length() > expectedLength)
       
  1913 					{
       
  1914 					rerr = KErrOverflow;
       
  1915 					}
       
  1916 				else
       
  1917 					{
       
  1918 					rerr = KErrUnderflow;
       
  1919 					}
       
  1920 				}
       
  1921 		
       
  1922 			// Check that the final byte is same as first byte
       
  1923 			if(iRecvBuffer[0] != iRecvBuffer[iRecvBuffer.Length() - 1])
       
  1924 				{
       
  1925 				iParent->test.Printf(_L("\nData Error: Invalid Data Payload. Expected[Recv Byte 0, Recv End N] %d[%d, %d]"),
       
  1926 				                        (iDataDialogCount&0xff), iRecvBuffer[0], iRecvBuffer[iRecvBuffer.Length() - 1]);
       
  1927 				rerr = KErrCorrupt;
       
  1928 				}
       
  1929 			}
       
  1930 		
       
  1931 		// Check that the packet received is in the correct order
       
  1932 		if(rerr == KErrCompletion)
       
  1933 			{
       
  1934 			if(iRecvBuffer[0] != (iDataDialogCount&0xff))
       
  1935 				{
       
  1936 				switch(iProfile.iData)
       
  1937 					{
       
  1938 					case TConnProfile::EDataDialog1:
       
  1939 					case TConnProfile::EDataDialog2:
       
  1940 						iParent->test.Printf(_L("\nData Error: Packet OOS. Recv[Expected] %d[%d]"), iRecvBuffer[0], (iDataDialogCount&0xff));
       
  1941 						rerr = KErrTotalLossOfPrecision;
       
  1942 						break;
       
  1943 											
       
  1944 					case TConnProfile::EDataRecv:
       
  1945 						iParent->test.Printf(_L("\nData Error: Packet OOS. Recv[Expected] %d[%d]"), iRecvBuffer[0], (iDataDialogCount&0xff));
       
  1946 						iParent->test.Printf(_L("\nPacket [%d] lost/flushed, next expected [%d]"), (iDataDialogCount&0xff), (iRecvBuffer[0] + 1));
       
  1947 						iDataDialogCount = iRecvBuffer[0];
       
  1948 						break;
       
  1949 						
       
  1950 					default:
       
  1951 						__DEBUGGER();
       
  1952 						break;
       
  1953 					};
       
  1954 				}
       
  1955 			}
       
  1956 		} // !TConnProfile::EDataRecvAny
       
  1957 	return rerr;
       
  1958 	}
       
  1959 
       
  1960 
       
  1961 void CBTTestConnection::ContinueDialog()	
       
  1962 	{
       
  1963 	switch(iProfile.iData)
       
  1964 		{
       
  1965 		case TConnProfile::EDataIdle:
       
  1966 			break;
       
  1967 			
       
  1968 		case TConnProfile::EDataDialog1:
       
  1969 		case TConnProfile::EDataDialog2:
       
  1970 			if((iDataDialogCount + iProfile.iData) & 0x1)
       
  1971 				{
       
  1972 				DoRecv();
       
  1973 				}
       
  1974 			else
       
  1975 				{
       
  1976 				DoSend(TUint8(iDataDialogCount&0xff));
       
  1977 				}				
       
  1978 			break;
       
  1979 
       
  1980 		case TConnProfile::EDataSend:
       
  1981 			DoSend(TUint8(iDataDialogCount&0xff));
       
  1982 			if(!(iDataDialogCount & 0xff))
       
  1983 				{
       
  1984 				TTime temp;
       
  1985 				temp.HomeTime();
       
  1986 				TTimeIntervalMicroSeconds diff = temp.MicroSecondsFrom(iTime);	
       
  1987 
       
  1988 				iParent->test.Printf(_L("\nWriting data %d"), diff.Int64());
       
  1989 				iTime.HomeTime();
       
  1990 				}
       
  1991 			break;
       
  1992 			
       
  1993 		case TConnProfile::EDataRecv:
       
  1994 		case TConnProfile::EDataRecvAny:
       
  1995 			DoRecv();
       
  1996 			break;
       
  1997 
       
  1998 		case TConnProfile::EDataSendReceive:
       
  1999 			DoRecv();
       
  2000 			DoSend(TUint8(iDataDialogCount&0xff));
       
  2001 			break;
       
  2002 
       
  2003 		default:
       
  2004 			iParent->test.Printf(_L("\nContinueDialog: Invalid data state [%d]"), iProfile.iData);
       
  2005 			__DEBUGGER();
       
  2006 			break;		
       
  2007 		};
       
  2008 	}	
       
  2009 
       
  2010 void CBTTestConnection::DoSend(TUint8 aVal)
       
  2011 	{
       
  2012 	// Zero-fill the packet. Then set the first and last bytes to a number
       
  2013 	// starting from zero and incrementing with each packet. This enables
       
  2014 	// checking that they arrive in order. The 2nd and 3rd bytes are set
       
  2015 	// to the high and low bytes of the length of the packet, respectively
       
  2016 	//
       
  2017 	iSendBuffer.FillZ(iProfile.iSendingMTUSize);
       
  2018 	iSendBuffer[0] = aVal;
       
  2019 	iSendBuffer[1] = (iProfile.iSendingMTUSize & 0xFF00) >> 8;   // Hi byte of packet size
       
  2020 	iSendBuffer[2] = (iProfile.iSendingMTUSize & 0x00FF);        // Lo byte of packet size
       
  2021 	iSendBuffer[iProfile.iSendingMTUSize - 1] = aVal;
       
  2022 	TInt rerr = iBTSocket->Write(iSendBuffer);
       
  2023 	if(rerr != KErrNone)
       
  2024 		{
       
  2025 		// This is called both on send and receive completion, so if it's actually receive
       
  2026 		// being completed, we may still have a previous outstanding send.
       
  2027 		if (!(iProfile.iData == TConnProfile::EDataSendReceive && rerr == KErrInUse))
       
  2028 			{
       
  2029 			iProfile.iData = TConnProfile::EDataFailed;
       
  2030 			iParent->test.Printf(_L("\nData Send Error: Value[%d], Error[%d]."), aVal, rerr);
       
  2031 			}
       
  2032 		}
       
  2033 	}
       
  2034 
       
  2035 void CBTTestConnection::DoRecv()
       
  2036 	{
       
  2037 	TInt rerr = KErrNone;
       
  2038 	if(iProfile.iIsStreamProtocol)
       
  2039 		{
       
  2040 		rerr = iBTSocket->RecvOneOrMore(iRecvBuffer, 0, iRecvBufferLength);
       
  2041 		}
       
  2042 	else
       
  2043 		{
       
  2044 		rerr = iBTSocket->Read(iRecvBuffer);
       
  2045 		}
       
  2046 	
       
  2047 	if(rerr != KErrNone)
       
  2048 		{
       
  2049 		// This is called both on send and receive completion, so if it's actually send
       
  2050 		// being completed, we may still have a previous outstanding recv.
       
  2051 		if (!(iProfile.iData == TConnProfile::EDataSendReceive && rerr == KErrInUse))
       
  2052 			{
       
  2053 			iProfile.iData = TConnProfile::EDataFailed;
       
  2054 			iParent->test.Printf(_L("\nData Recv Error: Error[%d]."), rerr);
       
  2055 			}
       
  2056 		}
       
  2057 	}
       
  2058 
       
  2059 void CBTTestConnection::Panic(TBTTestConnectionPanic aPanic)
       
  2060 	{
       
  2061 	_LIT(KBTTestConnectionPanicName, "Bluetooth Test Console Panic");
       
  2062 	User::Panic(KBTTestConnectionPanicName, aPanic);
       
  2063 	}
       
  2064 
       
  2065 void CBTTestConnection::StartPlmDisplayL()
       
  2066 	{
       
  2067 	if (iMetricsConsole)
       
  2068 		{
       
  2069 		User::Leave(KErrAlreadyExists);
       
  2070 		}
       
  2071 	if (!iMetrics)
       
  2072 		{
       
  2073 		User::Leave(KErrNotReady);
       
  2074 		}
       
  2075 	iMetricsConsole = Console::NewL(_L("PLM"), TSize(KConsFullScreen, KConsFullScreen));
       
  2076 	iMetrics->SubscribeRssi();
       
  2077 	iMetrics->SubscribeLinkQuality();
       
  2078 	iMetrics->SubscribeFailedContactCounter();
       
  2079 	iMetrics->SubscribeTransmitPowerLevel();
       
  2080 	}
       
  2081 
       
  2082 void CBTTestConnection::StopPlmDisplayL()
       
  2083 	{
       
  2084 	if (!iMetricsConsole)
       
  2085 	{
       
  2086 		User::Leave(KErrArgument);
       
  2087 		}
       
  2088 	iMetrics->Cancel();
       
  2089 	delete iMetricsConsole;
       
  2090 	iMetricsConsole = NULL;
       
  2091 	}
       
  2092 
       
  2093 TInt CBTTestConnection::PrintBTPhyConnections()
       
  2094 	{
       
  2095 	TInt rerr = KErrNone;
       
  2096 	if(!iBTPhyLinks)
       
  2097 		{
       
  2098 		TRAP(rerr, iBTPhyLinks = CBluetoothPhysicalLinks::NewL(*this, iSocketServer));
       
  2099 		}
       
  2100 
       
  2101 	if(rerr == KErrNone)
       
  2102 		{
       
  2103 		TUint aMaxNumber = 10;
       
  2104 		RBTDevAddrArray aBTDevAddrArray(aMaxNumber);
       
  2105 		
       
  2106 		rerr = iBTPhyLinks->Enumerate(aBTDevAddrArray,aMaxNumber);
       
  2107 		TInt arraySize = aBTDevAddrArray.Count();
       
  2108 		iParent->test.Printf(_L("\nNo of Connected Links: %d\nSource Address:\n"),arraySize);
       
  2109 		if(rerr == KErrNone && arraySize)
       
  2110 			{
       
  2111 			// No Error and we have something to print!
       
  2112 			TBuf<20> buf;
       
  2113 			for(TInt i=0;i<arraySize;i++)
       
  2114 				{
       
  2115 				aBTDevAddrArray[i].GetReadable(buf);
       
  2116 				iParent->test.Printf(_L("\n%S"),&buf);
       
  2117 				}
       
  2118 			}
       
  2119 		}
       
  2120 	return rerr;
       
  2121 	}
       
  2122 
       
  2123 TInt CBTTestConnection::GetRemoteName(TNameEntry& aNameEntry)
       
  2124 	{
       
  2125 	
       
  2126 	RHostResolver resolver;
       
  2127 	TInt err = resolver.Open(iSocketServer, KBTAddrFamily, KBTLinkManager);
       
  2128 	if (err==KErrNone)
       
  2129 		{
       
  2130 		TInquirySockAddr address(iPeerSocketAddr);
       
  2131 		address.SetBTAddr(iPeerSocketAddr.BTAddr());
       
  2132 		address.SetAction(KHostResName|KHostResIgnoreCache);
       
  2133 		err = resolver.GetByAddress(address, aNameEntry);
       
  2134 		}
       
  2135 	resolver.Close();	
       
  2136 	return err;
       
  2137 	}
       
  2138 
       
  2139 // ----------------------------------------------------------------------------
       
  2140 //							DEBUG METHODS
       
  2141 // ----------------------------------------------------------------------------
       
  2142 #ifdef _DEBUG
       
  2143 // This is copied from L2Types.h
       
  2144 //enum TL2CapChannelMode
       
  2145 //	{
       
  2146 //	EL2CAPBasicMode 			= 0x00,
       
  2147 //	EL2CAPRetransmissionMode 	= 0x01,
       
  2148 //	EL2CAPFlowControlMode 		= 0x02,
       
  2149 //	};
       
  2150 
       
  2151 class TL2DataPlaneConfig
       
  2152 	{
       
  2153 public:
       
  2154 	TL2CapChannelMode iLinkMode;
       
  2155 	TUint8 iTxWindowSize;
       
  2156 	TUint8 iMaxTransmit;
       
  2157 	TUint16 iRetransmissionTimeout;
       
  2158 	TUint16 iMonitorTimeout;
       
  2159 	TUint16 iMaximumPDUSize;
       
  2160 	TUint8 iPriority;
       
  2161 	TUint8 iOutboundQueueSize;
       
  2162 	TUint16 iFlushTimeout;
       
  2163 	TUint16 iMaxOutgoingMTU;
       
  2164 	TUint16 iMaxIncomingMTU;
       
  2165 	};
       
  2166 
       
  2167 typedef TPckgBuf<TL2DataPlaneConfig> TL2DataPlaneConfigPkg;
       
  2168 
       
  2169 
       
  2170 TInt CBTTestConnection::DataPlaneConfig()
       
  2171 	{
       
  2172 
       
  2173 	TL2DataPlaneConfig conf;
       
  2174 	TL2DataPlaneConfigPkg pckg(conf);
       
  2175 
       
  2176 	TInt rerr = iBTSocket->GetOpt(KL2CAPDataPlaneConfig, KSolBtL2CAP, pckg);
       
  2177 	if(rerr == KErrNone)
       
  2178 		{
       
  2179 		conf = pckg();
       
  2180 		iParent->test.Printf(_L("\n\n ***** Data Plane Configuration *****\n"));
       
  2181 		iParent->test.Printf(_L("Priority            - %d\n"), conf.iPriority);
       
  2182 		iParent->test.Printf(_L("Outbound Queue Size - %d\n"), conf.iOutboundQueueSize);
       
  2183 		iParent->test.Printf(_L("Flush Timeout       - %d\n"), conf.iFlushTimeout);
       
  2184 		iParent->test.Printf(_L("Max Outgoing MTU    - %d\n"), conf.iMaxOutgoingMTU);
       
  2185 		iParent->test.Printf(_L("Max Incoming MTU    - %d\n"), conf.iMaxIncomingMTU);
       
  2186 
       
  2187 		iParent->test.Printf(_L("Link Mode           - %d\n"), conf.iLinkMode);
       
  2188 		iParent->test.Printf(_L("Tx Window Size      - %d\n"), conf.iTxWindowSize);
       
  2189 		iParent->test.Printf(_L("Max # Retransmit    - %d\n"), conf.iMaxTransmit);
       
  2190 		iParent->test.Printf(_L("Retransmit Timeout  - %d\n"), conf.iRetransmissionTimeout);
       
  2191 		iParent->test.Printf(_L("Monitor Timeout     - %d\n"), conf.iMonitorTimeout);
       
  2192 		iParent->test.Printf(_L("Max PDU Size        - %d\n"), conf.iMaximumPDUSize);
       
  2193 		iParent->test.Printf(_L(" ************************************\n\n"));
       
  2194 		}
       
  2195 	
       
  2196 	TPckgBuf<TInt> getOptBuf;
       
  2197 	TInt getOptValue = 0;
       
  2198 	if(rerr == KErrNone)
       
  2199 		{
       
  2200 		rerr = iBTSocket->GetOpt(KL2CAPNegotiatedOutboundMTU, KSolBtL2CAP, getOptBuf);
       
  2201 		if(rerr == KErrNone)
       
  2202 			{
       
  2203 			getOptValue = getOptBuf();
       
  2204 			iParent->test.Printf(_L("GetOpt Outgoing MTU (Negotiated)    - %d\n"), getOptValue);
       
  2205 			}
       
  2206 		}
       
  2207 	
       
  2208 	if(rerr == KErrNone)
       
  2209 		{
       
  2210 		rerr = iBTSocket->GetOpt(KL2CAPOutboundMTUForBestPerformance, KSolBtL2CAP, getOptBuf);
       
  2211 		if(rerr == KErrNone)
       
  2212 			{
       
  2213 			getOptValue = getOptBuf();
       
  2214 			iParent->test.Printf(_L("GetOpt Outgoing MTU (Best Performance)     - %d\n"), getOptValue);
       
  2215 			}
       
  2216 		}
       
  2217 	
       
  2218 	if(rerr == KErrNone)
       
  2219 		{
       
  2220 		rerr = iBTSocket->GetOpt(KL2CAPInboundMTU, KSolBtL2CAP, getOptBuf);
       
  2221 		if(rerr == KErrNone)
       
  2222 			{
       
  2223 			getOptValue = getOptBuf();
       
  2224 			iParent->test.Printf(_L("GetOpt Incoming MTU	 - %d\n"), getOptValue);
       
  2225 			}
       
  2226 		}
       
  2227 
       
  2228 	if(rerr == KErrNone)
       
  2229 		{
       
  2230 		rerr = iBTSocket->GetOpt(KL2CAPGetMaxOutboundMTU, KSolBtL2CAP, getOptBuf);
       
  2231 		if(rerr == KErrNone)
       
  2232 			{
       
  2233 			getOptValue = getOptBuf();
       
  2234 			iParent->test.Printf(_L("GetOpt Max Outgoing MTU - %d\n"), getOptValue);
       
  2235 			}
       
  2236 		}
       
  2237 
       
  2238 	if(rerr == KErrNone)
       
  2239 		{
       
  2240 		rerr = iBTSocket->GetOpt(KL2CAPGetMaxInboundMTU, KSolBtL2CAP, getOptBuf);
       
  2241 		if(rerr == KErrNone)
       
  2242 			{
       
  2243 			getOptValue = getOptBuf();
       
  2244 			iParent->test.Printf(_L("GetOpt Max Incoming MTU - %d\n"), getOptValue);
       
  2245 			}
       
  2246 		}
       
  2247 		
       
  2248 	if(rerr == KErrNone)
       
  2249 		{
       
  2250 		rerr = iBTSocket->GetOpt(KL2CAPRTXTimer, KSolBtL2CAP, getOptBuf);
       
  2251 		if(rerr == KErrNone)
       
  2252 			{
       
  2253 			getOptValue = getOptBuf();
       
  2254 			iParent->test.Printf(_L("GetOpt RTXTimerDuration - %d\n"), getOptValue);
       
  2255 			}
       
  2256 		}
       
  2257 	
       
  2258 	if(rerr == KErrNone)
       
  2259 		{
       
  2260 		rerr = iBTSocket->GetOpt(KL2CAPERTXTimer, KSolBtL2CAP, getOptBuf);
       
  2261 		if(rerr == KErrNone)
       
  2262 			{
       
  2263 			getOptValue = getOptBuf();
       
  2264 			iParent->test.Printf(_L("GetOpt ERTXTimerDuration - %d\n"), getOptValue);
       
  2265 			}
       
  2266 		}
       
  2267 
       
  2268 	return rerr;
       
  2269 	}
       
  2270 
       
  2271 TInt CBTTestConnection::IssueManualFlush()
       
  2272 	{
       
  2273 	TInt msgID = 0;
       
  2274 	TInt rerr = iBTSocket->GetOpt(KL2CAPDebugFlush, KSolBtL2CAP, msgID);
       
  2275 
       
  2276 	iParent->test.Printf(_L("Manual Flush Request: MSG ID[%d], Error[%d]"), msgID, rerr);
       
  2277 	return rerr;			
       
  2278 	}
       
  2279 #endif
       
  2280 
       
  2281 TConnProfile::TConnProfile()
       
  2282 : iPhyLinkIx(-2),
       
  2283   iState(EConnIdle),
       
  2284   iRole(ENone),
       
  2285   iPackets(EPacketsDM1 | EPacketsDM3 | EPacketsDM5 | EPacketsDH1 | EPacketsDH3 | EPacketsDH5),
       
  2286   iMaxSlots(5),
       
  2287   iMode2(TConnProfile::EActive),
       
  2288   iModeAllowed(ESniffMode | EParkMode | EHoldMode),
       
  2289   iSwitchAllowed(ETrue),
       
  2290   iEncryption(EFalse),
       
  2291   iData(EDataIdle),
       
  2292   iAccepterIx(-1),
       
  2293   iIsSocketBased(ETrue),
       
  2294   iErrorCode(KErrNone),
       
  2295   iSendingMTUSize(0),
       
  2296   iRecvMTUSize(0),
       
  2297   iIsStreamProtocol(EFalse),
       
  2298   iIsSCO(EFalse),
       
  2299   iAutoSniffActive(EFalse)
       
  2300 	{}
       
  2301 
       
  2302 
       
  2303