bluetoothapitest/bluetoothsvs/T_BTSockAPI/src/T_CBluetoothSocketData.cpp
changeset 0 29b1cd4cb562
equal deleted inserted replaced
-1:000000000000 0:29b1cd4cb562
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "T_CBluetoothSocketData.h"
       
    19 #include "T_BTUtil.h"
       
    20 #include "T_TBTSockAddrChild.h"
       
    21 #include "T_BTDevAddrData.h"
       
    22 #include "T_BTSockAddrData.h"
       
    23 
       
    24 //  EPOC includes
       
    25 #include <e32math.h>
       
    26 
       
    27 
       
    28 /*@{*/
       
    29 ///	Constant Literals used.
       
    30 
       
    31 ///	Parameters
       
    32 _LIT(KExpectedReply,							"expectedreply");
       
    33 _LIT(KCBluetoothSocket,							"cbluetoothsocket");
       
    34 _LIT(KConnectData,								"connectdata");
       
    35 _LIT(KData,										"data");
       
    36 _LIT(KDesOption,								"desoption");
       
    37 _LIT(KDisconnectData, 							"disconnectData");
       
    38 _LIT(KEquals,									"equals");
       
    39 _LIT(KExpectNull,								"expectnull");
       
    40 _LIT(KFlags,									"flags");
       
    41 _LIT(KGetDes,									"getdes");
       
    42 _LIT(KIntOption,								"intoption");
       
    43 _LIT(KNamedIntOption,							"namedintoption");
       
    44 _LIT(KNamedProtocol,							"named_protocol");
       
    45 _LIT(KOptionLevel,								"optionlevel");
       
    46 _LIT(KOptionName,								"optionname");
       
    47 _LIT(KPort,										"port");
       
    48 _LIT(KProtocol,									"protocol");
       
    49 _LIT(KQueueSize,								"queuesize");
       
    50 _LIT(KRSocket,									"rsocket");
       
    51 _LIT(KServiceBits,								"servicebits");
       
    52 _LIT(KSockType,									"socktype");
       
    53 _LIT(KTBTSockAddr,								"tbtsockaddr");
       
    54 _LIT(KTSockAddr,								"tsockaddr");
       
    55 _LIT(KUid,										"uid");
       
    56 _LIT(KUseAccept2,								"useaccept2");
       
    57 _LIT(KUseAlternateNotifier,						"usealternatenotifier");
       
    58 _LIT(KUseDeprecated,							"usedeprecated");
       
    59 _LIT(KUseRecv2,									"userecv2");
       
    60 _LIT(KUseSend2,									"usesend2");
       
    61 _LIT(KHexBTAddrL,								"hex_btaddr_l");
       
    62 _LIT(KHexBTAddrR,								"hex_btaddr_r");
       
    63 _LIT(KTBTDevAddr,								"tbtdevaddr");
       
    64 _LIT(KCallTwice,								"calltwice");
       
    65 _LIT(KMTUSize,									"mtusize");
       
    66 _LIT(KState,									"state");
       
    67 _LIT(KConstructorType,							"constructortype");
       
    68 _LIT(KSniffMode,								"sniffmode");
       
    69 _LIT(KSniffDelay,								"sniffdelay");
       
    70 
       
    71 ///	CBluetoothSocket
       
    72 _LIT(KCmdAccept,								"Accept");
       
    73 _LIT(KCmdActivateBasebandEventNotifier,			"ActivateBasebandEventNotifier");
       
    74 _LIT(KCmdActivateParkRequester,					"ActivateParkRequester");
       
    75 _LIT(KCmdActivateSniffRequester,				"ActivateSniffRequester");
       
    76 _LIT(KCmdAllowLowPowerModes,					"AllowLowPowerModes");
       
    77 _LIT(KCmdAllowRoleSwitch,						"AllowRoleSwitch");
       
    78 _LIT(KCmdBind,									"Bind");
       
    79 _LIT(KCmdCancelAccept,							"CancelAccept");
       
    80 _LIT(KCmdCancelAll,								"CancelAll");
       
    81 _LIT(KCmdCancelBasebandEventNotifier,			"CancelBasebandEventNotifier");
       
    82 _LIT(KCmdCancelConnect,							"CancelConnect");
       
    83 _LIT(KCmdCancelIoctl,							"CancelIoctl");
       
    84 _LIT(KCmdCancelLowPowerModeRequester,			"CancelLowPowerModeRequester");
       
    85 _LIT(KCmdCancelRead,							"CancelRead");
       
    86 _LIT(KCmdCancelRecv,							"CancelRecv");
       
    87 _LIT(KCmdCancelSend,							"CancelSend");
       
    88 _LIT(KCmdCancelWrite,							"CancelWrite");
       
    89 _LIT(KCmdConnect,								"Connect");
       
    90 _LIT(KCmdDestructor,							"~");
       
    91 _LIT(KCmdGetDisconnectData,						"GetDisconnectData");
       
    92 _LIT(KCmdGetOpt,								"GetOpt");
       
    93 _LIT(KCmdInfo,									"Info");
       
    94 _LIT(KCmdIoctl,									"Ioctl");
       
    95 _LIT(KCmdListen,								"Listen");
       
    96 _LIT(KCmdLocalName,								"LocalName");
       
    97 _LIT(KCmdLocalPort,								"LocalPort");
       
    98 _LIT(KCmdName,									"Name");
       
    99 _LIT(KCmdNewL, 									"NewL");
       
   100 _LIT(KCmdNewLC, 								"NewLC");
       
   101 _LIT(KCmdPhysicalLinkState,						"PhysicalLinkState");
       
   102 _LIT(KCmdPreventLowPowerModes,					"PreventLowPowerModes");
       
   103 _LIT(KCmdPreventRoleSwitch,						"PreventRoleSwitch");
       
   104 _LIT(KCmdRConnectionClose,						"RConnectionClose");
       
   105 _LIT(KCmdRConnectionStart,						"RConnectionStart");
       
   106 _LIT(KCmdRead,									"Read");
       
   107 _LIT(KCmdRecv,									"Recv");
       
   108 _LIT(KCmdRecvFrom,								"RecvFrom");
       
   109 _LIT(KCmdRecvOneOrMore,							"RecvOneOrMore");
       
   110 _LIT(KCmdRemoteName,							"RemoteName");
       
   111 _LIT(KCmdRequestChangeSupportedPacketTypes,		"RequestChangeSupportedPacketTypes");
       
   112 _LIT(KCmdRequestMasterRole,						"RequestMasterRole");
       
   113 _LIT(KCmdRequestSlaveRole,						"RequestSlaveRole");
       
   114 _LIT(KCmdRSocketServerClose,					"RSocketServerClose");
       
   115 _LIT(KCmdRSocketServerConnect,					"RSocketServerConnect");
       
   116 _LIT(KCmdSend,									"Send");
       
   117 _LIT(KCmdSendTo,								"SendTo");
       
   118 _LIT(KCmdSetAutomaticSniffMode,					"SetAutomaticSniffMode");
       
   119 _LIT(KCmdSetLocalPort,							"SetLocalPort");
       
   120 _LIT(KCmdSetOpt,								"SetOpt");
       
   121 _LIT(KCmdSetOption,								"SetOption");
       
   122 _LIT(KCmdSetRsocketServerFromCBTSocket,			"SetRsocketServerFromCBTSocket");
       
   123 _LIT(KCmdSetTransferAble,						"SetTransferAble");
       
   124 _LIT(KCmdShutdown,								"Shutdown");
       
   125 _LIT(KCmdSetNotifier,							"SetNotifier");
       
   126 _LIT(KCmdTestMBSN_ExtensionInterfaceL,			"TestMBSN_ExtensionInterfaceL");
       
   127 _LIT(KCmdTransfer,								"Transfer");
       
   128 _LIT(KCmdWrite,									"Write");
       
   129 
       
   130 ///	Other
       
   131 _LIT_SECURITY_POLICY_C2(KProcPolicy, ECapabilityNetworkServices, ECapabilityNetworkControl);
       
   132 /*@}*/
       
   133 
       
   134 CT_CBluetoothSocketData* CT_CBluetoothSocketData::NewL()
       
   135 	{
       
   136 	CT_CBluetoothSocketData*	ret=new (ELeave) CT_CBluetoothSocketData();
       
   137 	CleanupStack::PushL(ret);
       
   138 	ret->ConstructL();
       
   139 	CleanupStack::Pop(ret);
       
   140 	return ret;
       
   141 	}
       
   142 
       
   143 /**
       
   144 * First phase construction
       
   145 */
       
   146 CT_CBluetoothSocketData::CT_CBluetoothSocketData()
       
   147 :	iData(NULL)
       
   148 ,	iHasConnectDataToExpect(EFalse)
       
   149 ,	iHasAcceptDataToExpect(EFalse)
       
   150 ,	iHasReceiveDataToExpect(EFalse)
       
   151 ,	iConnectIndex(0)
       
   152 ,	iAcceptIndex(0)
       
   153 ,	iShutdownIndex(0)
       
   154 ,	iIoctlIndex(0)
       
   155 ,	iNotifierIndex(0)
       
   156 ,	iReceiveIndex(0)
       
   157 ,	iSendIndex(0)
       
   158 	{
       
   159 	}
       
   160 
       
   161 /**
       
   162 * Second phase construction
       
   163 */
       
   164 void CT_CBluetoothSocketData::ConstructL()
       
   165 	{
       
   166 	iData=new (ELeave) CT_BluetoothSocketNotifier();
       
   167 	iData->SetServer(this);
       
   168 	}
       
   169 
       
   170 CT_CBluetoothSocketData::~CT_CBluetoothSocketData()
       
   171 	{
       
   172 	}
       
   173 
       
   174 //	Service methods
       
   175 TAny* CT_CBluetoothSocketData::GetObject()
       
   176 	{
       
   177 	return iData;
       
   178 	}
       
   179 
       
   180 void CT_CBluetoothSocketData::SetObjectL(TAny* aObject)
       
   181 	{
       
   182 	//called when loading up persistent data
       
   183 	delete iData;
       
   184 	iData = static_cast<CT_BluetoothSocketNotifier*>(aObject);
       
   185 	iData->SetServer(this);
       
   186 	}
       
   187 
       
   188 void CT_CBluetoothSocketData::DisownObjectL()
       
   189  	{
       
   190 	if ( iData )
       
   191 		{
       
   192 		iData->SetServer(NULL);
       
   193  		iData=NULL;
       
   194 		}
       
   195  	}
       
   196 
       
   197 inline TCleanupOperation CT_CBluetoothSocketData::CleanupOperation()
       
   198 	{
       
   199 	return CleanupOperation;
       
   200 	}
       
   201 
       
   202 void CT_CBluetoothSocketData::CleanupOperation(TAny* aAny)
       
   203 	{
       
   204 	//may be unnecessary
       
   205 	CT_BluetoothSocketNotifier* arg=static_cast<CT_BluetoothSocketNotifier*>(aAny);
       
   206 	delete arg;
       
   207 	}
       
   208 
       
   209 TBool CT_CBluetoothSocketData::DoCommandL(const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt aAsyncErrorIndex)
       
   210 	{
       
   211 	TBool	retVal=ETrue;
       
   212 
       
   213 	//-------------------------------------------------------------------------
       
   214 	// CBluetoothSocket
       
   215 	//-------------------------------------------------------------------------
       
   216 	if (aCommand==KCmdRSocketServerConnect)
       
   217 		{
       
   218 		DoCmdCloseSocketServer();
       
   219 		User::LeaveIfError(iData->iSocketServer.Connect());
       
   220 		iData->iSocketServerConnected=ETrue;
       
   221 		}
       
   222 	else if (aCommand==KCmdRSocketServerClose)
       
   223 		{
       
   224 		DoCmdCloseSocketServer();
       
   225 		}
       
   226 	else if (aCommand==KCmdRConnectionStart)
       
   227 		{
       
   228 		TInt err = iData->iConnection.Open(iData->iSocketServer, KBTAddrFamily);
       
   229 
       
   230 		if( err!=KErrNone )
       
   231 			{
       
   232 			INFO_PRINTF2(_L("RConnection::Open() err=%d" ),err);
       
   233 			SetError(err);
       
   234 			}
       
   235 
       
   236 		err = iData->iConnection.Start();
       
   237 
       
   238 		if( err!=KErrNone )
       
   239 			{
       
   240 			INFO_PRINTF2(_L("RConnection::Start() err=%d" ),err);
       
   241 			SetError(219);
       
   242 			}
       
   243 		}
       
   244 	else if (aCommand==KCmdRConnectionClose)
       
   245 		{
       
   246 		iData->iConnection.Close();
       
   247 		}
       
   248 	else if (aCommand==KCmdDestructor)
       
   249 		{
       
   250 		delete iData->iBluetoothSocket;
       
   251 		iData->iBluetoothSocket=NULL;
       
   252 		}
       
   253 	else if ( aCommand==KCmdNewL )
       
   254 		{
       
   255 		DoCmdNewL(aSection,EFalse);
       
   256 		}
       
   257 	else if ( aCommand==KCmdNewLC )
       
   258 		{
       
   259 		DoCmdNewL(aSection,ETrue);
       
   260 		}
       
   261 	else if ( aCommand==KCmdBind)
       
   262 		{
       
   263 		DoCmdBind(aSection);
       
   264 		}
       
   265 	else if ( aCommand==KCmdListen)
       
   266 		{
       
   267 		DoCmdListen(aSection);
       
   268 		}
       
   269 	else if ( aCommand==KCmdLocalName)
       
   270 		{
       
   271 		DoCmdLocalName(aSection);
       
   272 		}
       
   273 	else if ( aCommand==KCmdLocalPort)
       
   274 		{
       
   275 		DoCmdLocalPort(aSection);
       
   276 		}
       
   277 	else if ( aCommand==KCmdSetLocalPort)
       
   278 		{
       
   279 		DoCmdSetLocalPort(aSection);
       
   280 		}
       
   281 	else if ( aCommand==KCmdSetOpt)
       
   282 		{
       
   283 		DoCmdSetOpt(aSection);
       
   284 		}
       
   285 	else if ( aCommand==KCmdSetOption)
       
   286 		{
       
   287 		DoCmdSetOption(aSection);
       
   288 		}
       
   289 	else if ( aCommand==KCmdGetOpt)
       
   290 		{
       
   291 		DoCmdGetOpt(aSection);
       
   292 		}
       
   293 	else if ( aCommand==KCmdName)
       
   294 		{
       
   295 		DoCmdName();
       
   296 		}
       
   297 	else if ( aCommand==KCmdSetTransferAble)
       
   298 		{
       
   299 		DoCmdSetTransferAble();
       
   300 		}
       
   301 	else if ( aCommand==KCmdTransfer)
       
   302 		{
       
   303 		DoCmdTransfer(aSection);
       
   304 		}
       
   305 	else if ( aCommand==KCmdInfo)
       
   306 		{
       
   307 		DoCmdInfo(aSection);
       
   308 		}
       
   309 	else if ( aCommand==KCmdAccept)
       
   310 		{
       
   311 		DoCmdAccept(aSection,aAsyncErrorIndex);
       
   312 		}
       
   313 	else if ( aCommand==KCmdCancelAccept)
       
   314 		{
       
   315 		DoCmdCancelAccept();
       
   316 		}
       
   317 	else if ( aCommand==KCmdConnect)
       
   318 		{
       
   319 		DoCmdConnect(aSection,aAsyncErrorIndex);
       
   320 		}
       
   321 	else if ( aCommand==KCmdSend)
       
   322 		{
       
   323 		DoCmdSend(aSection,aAsyncErrorIndex);
       
   324 		}
       
   325 	else if ( aCommand==KCmdRecv)
       
   326 		{
       
   327 		DoCmdRecv(aSection,aAsyncErrorIndex);
       
   328 		}
       
   329 	else if ( aCommand==KCmdRecvOneOrMore)
       
   330 		{
       
   331 		DoCmdRecvOneOrMore(aSection,aAsyncErrorIndex);
       
   332 		}
       
   333 	else if ( aCommand==KCmdShutdown)
       
   334 		{
       
   335 		DoCmdShutdown(aSection,aAsyncErrorIndex);
       
   336 		}
       
   337 	else if ( aCommand==KCmdSetNotifier)
       
   338 		{
       
   339 		DoCmdSetNotifierL(aSection);
       
   340 		}
       
   341 	else if ( aCommand==KCmdCancelConnect)
       
   342 		{
       
   343 		DoCmdCancelConnect();
       
   344 		}
       
   345 	else if ( aCommand==KCmdSetRsocketServerFromCBTSocket)
       
   346 		{
       
   347 		DoCmdSetRsocketServerFromCBTSocket(aSection);
       
   348 		}
       
   349 	else if ( aCommand==KCmdIoctl)
       
   350 		{
       
   351 		DoCmdIoctl(aSection,aAsyncErrorIndex);
       
   352 		}
       
   353 	else if ( aCommand==KCmdCancelIoctl)
       
   354 		{
       
   355 		DoCmdCancelIoctl();
       
   356 		}
       
   357 	else if ( aCommand==KCmdAllowLowPowerModes)
       
   358 		{
       
   359 		DoCmdAllowLowPowerModes(aSection);
       
   360 		}
       
   361 	else if ( aCommand==KCmdCancelLowPowerModeRequester)
       
   362 		{
       
   363 		DoCmdCancelLowPowerModeRequester(aSection);
       
   364 		}
       
   365 	else if ( aCommand==KCmdPreventLowPowerModes)
       
   366 		{
       
   367 		DoCmdPreventLowPowerModes(aSection);
       
   368 		}
       
   369 	else if ( aCommand==KCmdActivateBasebandEventNotifier)
       
   370 		{
       
   371 		DoCmdActivateBasebandEventNotifier(aSection, aAsyncErrorIndex);
       
   372 		}
       
   373 	else if ( aCommand==KCmdCancelBasebandEventNotifier)
       
   374 		{
       
   375 		DoCmdCancelBasebandEventNotifier();
       
   376 		}
       
   377 	else if ( aCommand==KCmdPhysicalLinkState)
       
   378 		{
       
   379 		DoCmdPhysicalLinkState(aSection);
       
   380 		}
       
   381 	else if ( aCommand==KCmdPreventRoleSwitch)
       
   382 		{
       
   383 		DoCmdPreventRoleSwitch();
       
   384 		}
       
   385 	else if ( aCommand==KCmdAllowRoleSwitch)
       
   386 		{
       
   387 		DoCmdAllowRoleSwitch();
       
   388 		}
       
   389 	else if ( aCommand==KCmdRequestMasterRole)
       
   390 		{
       
   391 		DoCmdRequestMasterRole();
       
   392 		}
       
   393 	else if ( aCommand==KCmdRequestSlaveRole)
       
   394 		{
       
   395 		DoCmdRequestSlaveRole();
       
   396 		}
       
   397 	else if ( aCommand==KCmdActivateSniffRequester)
       
   398 		{
       
   399 		DoCmdActivateSniffRequester();
       
   400 		}
       
   401 	else if ( aCommand==KCmdActivateParkRequester)
       
   402 		{
       
   403 		DoCmdActivateParkRequester();
       
   404 		}
       
   405 	else if ( aCommand==KCmdCancelSend)
       
   406 		{
       
   407 		DoCmdCancelSend();
       
   408 		}
       
   409 	else if ( aCommand==KCmdCancelAll)
       
   410 		{
       
   411 		DoCmdCancelAll();
       
   412 		}
       
   413 	else if ( aCommand==KCmdWrite)
       
   414 		{
       
   415 		DoCmdWrite(aSection,aAsyncErrorIndex);
       
   416 		}
       
   417 	else if ( aCommand==KCmdCancelWrite)
       
   418 		{
       
   419 		DoCmdCancelWrite();
       
   420 		}
       
   421 	else if ( aCommand==KCmdSendTo)
       
   422 		{
       
   423 		DoCmdSendTo(aSection, aAsyncErrorIndex);
       
   424 		}
       
   425 	else if ( aCommand==KCmdRecvFrom)
       
   426 		{
       
   427 		DoCmdRecvFrom(aSection,aAsyncErrorIndex);
       
   428 		}
       
   429 	else if ( aCommand==KCmdGetDisconnectData)
       
   430 		{
       
   431 		DoCmdGetDisconnectData();
       
   432 		}
       
   433 	else if ( aCommand==KCmdRequestChangeSupportedPacketTypes)
       
   434 		{
       
   435 		DoCmdRequestChangeSupportedPacketTypes(aSection);
       
   436 		}
       
   437 	else if ( aCommand==KCmdCancelRecv)
       
   438 		{
       
   439 		DoCmdCancelRecv();
       
   440 		}
       
   441 	else if ( aCommand==KCmdRead)
       
   442 		{
       
   443 		DoCmdRead(aSection, aAsyncErrorIndex);
       
   444 		}
       
   445 	else if ( aCommand==KCmdCancelRead)
       
   446 		{
       
   447 		DoCmdCancelRead();
       
   448 		}
       
   449 	else if ( aCommand==KCmdRemoteName)
       
   450 		{
       
   451 		DoCmdRemoteName(aSection);
       
   452 		}
       
   453 	else if ( aCommand==KCmdTestMBSN_ExtensionInterfaceL)
       
   454 		{
       
   455 		DoCmdTestMBSN_ExtensionInterfaceL(aSection);
       
   456 		}
       
   457 	else if ( aCommand==KCmdSetAutomaticSniffMode)
       
   458 		{
       
   459 		DoCmdSetAutomaticSniffMode(aSection);
       
   460 		}
       
   461 	else
       
   462 		{
       
   463 		retVal=EFalse;
       
   464 		}
       
   465 	return retVal;
       
   466 	}
       
   467 
       
   468 
       
   469 inline void CT_CBluetoothSocketData::DoCmdAccept(const TDesC& aSection, const TInt aAsyncErrorIndex)
       
   470 	{
       
   471 
       
   472 	TPtrC	expectedReply;
       
   473 	iAcceptFlag = EFalse;
       
   474 	iHasAcceptDataToExpect=GetStringFromConfig(aSection, KExpectedReply(), expectedReply);
       
   475 	if ( iHasAcceptDataToExpect )
       
   476 		{
       
   477 		iAcceptDataToExpect.Copy(expectedReply);
       
   478 		}
       
   479 
       
   480 	TBool	useAccept2 =EFalse;
       
   481 	GetBoolFromConfig(aSection, KUseAccept2(), useAccept2);
       
   482 
       
   483 	// Get the blank session socket
       
   484 	TPtrC	bluetoothSocketName;
       
   485 	CBluetoothSocket*	bluetoothSocket=NULL;
       
   486 	if( GetStringFromConfig(aSection, KCBluetoothSocket(), bluetoothSocketName))
       
   487 		{
       
   488 		bluetoothSocket=(static_cast<CT_BluetoothSocketNotifier*>(GetDataObjectL(bluetoothSocketName))->iBluetoothSocket);
       
   489 		if ( bluetoothSocket!=NULL )
       
   490 			{
       
   491 			TInt	status;
       
   492 			if ( useAccept2 )
       
   493 				{
       
   494 				INFO_PRINTF1(_L("Using Accept 2"));
       
   495 				status = iData->iBluetoothSocket->Accept(*bluetoothSocket, iDataToRead8);
       
   496 				}
       
   497 			else
       
   498 				{
       
   499 				INFO_PRINTF1(_L("Using Accept 1"));
       
   500 				status = iData->iBluetoothSocket->Accept(*bluetoothSocket);
       
   501 				}
       
   502 
       
   503 			if(status==KErrNone)
       
   504 				{
       
   505 				IncOutstanding();
       
   506 				iAcceptFlag = ETrue;
       
   507 				iAcceptIndex = aAsyncErrorIndex;
       
   508 				}
       
   509 			else
       
   510 				{
       
   511 				ERR_PRINTF2(_L("Accept failed: %d"),status);
       
   512 				SetError(status);
       
   513 				}
       
   514 			}
       
   515 		else
       
   516 			{
       
   517 			ERR_PRINTF1(_L("Bind TSockAddr is NULL"));
       
   518 			SetBlockResult(EFail);
       
   519 			}
       
   520 		}
       
   521 	else
       
   522 		{
       
   523 		ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
   524 		SetBlockResult(EFail);
       
   525 		}
       
   526 	}
       
   527 
       
   528 inline void CT_CBluetoothSocketData::DoCmdActivateBasebandEventNotifier(const TDesC& aSection,const TInt aAsyncErrorIndex)
       
   529 	{
       
   530 	// loop through all values in the ini file and add them up
       
   531 	TUint32	flags=0;
       
   532 	CT_BTUtil::GetLinkStateNotifierBits(*this, aSection, flags);
       
   533 
       
   534 	TInt	errCode = iData->iBluetoothSocket->ActivateBasebandEventNotifier(flags);
       
   535 	if ( errCode==KErrNone )
       
   536 		{
       
   537 		IncOutstanding();
       
   538 		iNotifierIndex = aAsyncErrorIndex;
       
   539 		}
       
   540 	else
       
   541 		{
       
   542 		ERR_PRINTF2(_L("ActivateBasebandEventNotifier failed with error code: %d"), errCode);
       
   543 		SetError(errCode);
       
   544 		}
       
   545 	}
       
   546 
       
   547 inline void CT_CBluetoothSocketData::DoCmdActivateParkRequester()
       
   548 	{
       
   549 	TInt errCode = iData->iBluetoothSocket->ActivateParkRequester();
       
   550 	if (errCode != KErrNone)
       
   551 		{
       
   552 		ERR_PRINTF2(_L("ActivateParkRequester failed with error code: %d"),errCode);
       
   553 		SetError(errCode);
       
   554 		}
       
   555 	}
       
   556 
       
   557 inline void CT_CBluetoothSocketData::DoCmdActivateSniffRequester()
       
   558 	{
       
   559 	TInt errCode = iData->iBluetoothSocket->ActivateSniffRequester();
       
   560 	if (errCode != KErrNone)
       
   561 		{
       
   562 		ERR_PRINTF2(_L("ActivateSniffRequester failed with error code: %d"),errCode);
       
   563 		SetError(errCode);
       
   564 		}
       
   565 	}
       
   566 
       
   567 inline void CT_CBluetoothSocketData::DoCmdAllowLowPowerModes(const TDesC& aSection)
       
   568 	{
       
   569 	TUint32	mode=0;
       
   570 	CT_BTUtil::GetLowPowerMode(*this, aSection, mode);
       
   571 
       
   572 	TInt	errCode=iData->iBluetoothSocket->AllowLowPowerModes(mode);
       
   573 	if (errCode != KErrNone)
       
   574 		{
       
   575 		ERR_PRINTF2(_L("Send AllowLowPowerModes failed with error code: %d"),errCode);
       
   576 		SetError(errCode);
       
   577 		}
       
   578 	}
       
   579 
       
   580 inline void CT_CBluetoothSocketData::DoCmdAllowRoleSwitch()
       
   581 	{
       
   582 	TInt	errCode = iData->iBluetoothSocket->AllowRoleSwitch();
       
   583 	if (errCode != KErrNone)
       
   584 		{
       
   585 		ERR_PRINTF2(_L("AllowRoleSwitch failed with error code: %d"),errCode);
       
   586 		SetError(errCode);
       
   587 		}
       
   588 	}
       
   589 
       
   590 inline void CT_CBluetoothSocketData::DoCmdBind(const TDesC& aSection)
       
   591 	{
       
   592 	TPtrC	sockAddrName;
       
   593 	if( GetStringFromConfig(aSection, KTSockAddr(), sockAddrName))
       
   594 		{
       
   595 		INFO_PRINTF2(_L("Binding with: %S TSockAddr"), &sockAddrName);
       
   596 		TBTSockAddr*	sockAddr=static_cast<TBTSockAddr*>(GetDataObjectL(sockAddrName));
       
   597 		if ( sockAddr!=NULL )
       
   598 			{
       
   599 			TInt	errCode = iData->iBluetoothSocket->Bind(*sockAddr);
       
   600 			if(errCode!=KErrNone)
       
   601 				{
       
   602 				ERR_PRINTF2(_L("Bind failed: %d"), errCode);
       
   603 				SetError(errCode);
       
   604 				}
       
   605 			}
       
   606 		else
       
   607 			{
       
   608 			ERR_PRINTF1(_L("Bind TSockAddr is NULL"));
       
   609 			SetBlockResult(EFail);
       
   610 			}
       
   611 		}
       
   612 	else
       
   613 		{
       
   614 		ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
   615 		SetBlockResult(EFail);
       
   616 		}
       
   617 	}
       
   618 
       
   619 inline void CT_CBluetoothSocketData::DoCmdCancelAccept()
       
   620 	{
       
   621 	iData->iBluetoothSocket->CancelAccept();
       
   622 	if(Outstanding() && iAcceptFlag)
       
   623 		{
       
   624 		DecOutstanding();	
       
   625 		}
       
   626 	}
       
   627 
       
   628 inline void CT_CBluetoothSocketData::DoCmdCancelAll()
       
   629 	{
       
   630 	iData->iBluetoothSocket->CancelAll();
       
   631 	}
       
   632 
       
   633 inline void CT_CBluetoothSocketData::DoCmdCancelBasebandEventNotifier()
       
   634 	{
       
   635 	iData->iBluetoothSocket->CancelBasebandEventNotifier();
       
   636 	if(Outstanding() && iNotifierFlag)
       
   637 		{
       
   638 		DecOutstanding();	
       
   639 		}
       
   640 	}
       
   641 
       
   642 inline void CT_CBluetoothSocketData::DoCmdCancelConnect()
       
   643 	{
       
   644 	iData->iBluetoothSocket->CancelConnect();
       
   645 	if(Outstanding() && iConnectFlag)
       
   646 		{
       
   647 		DecOutstanding();	
       
   648 		}
       
   649 	}
       
   650 
       
   651 inline void CT_CBluetoothSocketData::DoCmdCancelIoctl()
       
   652 	{
       
   653 	iData->iBluetoothSocket->CancelIoctl();
       
   654 	if(Outstanding() && iIoctlFlag)
       
   655 		{
       
   656 		DecOutstanding();	
       
   657 		}
       
   658 	}
       
   659 
       
   660 inline void CT_CBluetoothSocketData::DoCmdCancelLowPowerModeRequester(const TDesC& /*aSection*/)
       
   661 	{
       
   662 	TInt	errCode=iData->iBluetoothSocket->CancelLowPowerModeRequester();
       
   663 	if (errCode != KErrNone)
       
   664 		{
       
   665 		ERR_PRINTF2(_L("Send CancelLowPowerModeRequester failed with error code: %d"),errCode);
       
   666 		SetError(errCode);
       
   667 		}
       
   668 	}
       
   669 
       
   670 inline void CT_CBluetoothSocketData::DoCmdCancelRead()
       
   671 	{
       
   672 	iData->iBluetoothSocket->CancelRead();
       
   673 	if (Outstanding() && iReadFlag)
       
   674 		{
       
   675 		DecOutstanding();	
       
   676 		}
       
   677 	}
       
   678 
       
   679 inline void CT_CBluetoothSocketData::DoCmdCancelRecv()
       
   680 	{
       
   681 	iData->iBluetoothSocket->CancelRecv();
       
   682 	if (Outstanding() && iRecvFlag)
       
   683 		{
       
   684 		DecOutstanding();	
       
   685 		}
       
   686 	}
       
   687 
       
   688 inline void CT_CBluetoothSocketData::DoCmdCancelSend()
       
   689 	{
       
   690 	iData->iBluetoothSocket->CancelSend();
       
   691 	if (Outstanding() && iSendFlag)
       
   692 		{
       
   693 		DecOutstanding();
       
   694 		}
       
   695 	}
       
   696 
       
   697 inline void CT_CBluetoothSocketData::DoCmdCancelWrite()
       
   698 	{
       
   699 	iData->iBluetoothSocket->CancelWrite();
       
   700 	if (Outstanding() && iWriteFlag)
       
   701 		{
       
   702 		DecOutstanding();	
       
   703 		}
       
   704 	}
       
   705 
       
   706 inline void CT_CBluetoothSocketData::DoCmdCloseSocketServer()
       
   707 	{
       
   708 	if(iData->iSocketServerConnected)
       
   709 		{
       
   710 		iData->iSocketServer.Close();
       
   711 		}
       
   712 	iData->iSocketServerConnected=EFalse;
       
   713 	}
       
   714 
       
   715 inline void CT_CBluetoothSocketData::DoCmdConnect(const TDesC& aSection, const TInt aAsyncErrorIndex)
       
   716 	{
       
   717 
       
   718 	TPtrC	expectedReply;
       
   719 	iConnectFlag = EFalse;
       
   720 	iHasConnectDataToExpect=GetStringFromConfig(aSection, KExpectedReply(), expectedReply);
       
   721 	if ( iHasConnectDataToExpect )
       
   722 		{
       
   723 		iConnectDataToExpect.Copy(expectedReply);
       
   724 		}
       
   725 
       
   726 	TPtrC	sockAddrName;
       
   727 	if( GetStringFromConfig(aSection, KTBTSockAddr(), sockAddrName))
       
   728 		{
       
   729 		INFO_PRINTF2(_L("Connecting with: %S TBTSockAddr"), &sockAddrName);
       
   730 		TBTSockAddr*	myTBTSockAddr=static_cast<TBTSockAddr*>(GetDataObjectL(sockAddrName));
       
   731 		if ( myTBTSockAddr!=NULL )
       
   732 			{
       
   733 			TInt	errCode=KErrNone;
       
   734 
       
   735 			TInt	serviceBits;
       
   736 			if ( GetIntFromConfig(aSection, KServiceBits(), serviceBits) )
       
   737 				{
       
   738 				INFO_PRINTF1(_L("Using Connect 3"));
       
   739 
       
   740 				TBTDevAddr	tempAddress = myTBTSockAddr->BTAddr();
       
   741 				TBuf<KMaxSockAddrSize> tmpBuf;
       
   742 				tempAddress.GetReadable(tmpBuf);
       
   743 				INFO_PRINTF2(_L("Connecting to address (%S)"), &tmpBuf);
       
   744 
       
   745 				errCode=iData->iBluetoothSocket->Connect(*myTBTSockAddr, serviceBits);
       
   746 				}
       
   747 			else
       
   748 				{
       
   749 				TPtrC	connectData;
       
   750 				if ( GetStringFromConfig(aSection, KConnectData(), connectData) )
       
   751 					{
       
   752 					INFO_PRINTF1(_L("Using Connect 2"));
       
   753 					TBuf8<DATASIZE>	connectData8(_L8(""));
       
   754 					connectData8.Copy(connectData);
       
   755 
       
   756 					TBTDevAddr	tempAddress = myTBTSockAddr->BTAddr();
       
   757 					TBuf<KMaxSockAddrSize> tmpBuf;
       
   758 					tempAddress.GetReadable(tmpBuf);
       
   759 					INFO_PRINTF2(_L("Connecting to address (%S)"), &tmpBuf);
       
   760 
       
   761 					errCode =iData->iBluetoothSocket->Connect(*myTBTSockAddr, iDataToRead8, connectData8);
       
   762 					}
       
   763 				else
       
   764 					{
       
   765 					INFO_PRINTF1(_L("Using Connect 1"));
       
   766 
       
   767 					TBTDevAddr	tempAddress = myTBTSockAddr->BTAddr();
       
   768 					TBuf<KMaxSockAddrSize> tmpBuf;
       
   769 					tempAddress.GetReadable(tmpBuf);
       
   770 					INFO_PRINTF2(_L("Connecting to address (%S)"), &tmpBuf);
       
   771 
       
   772 					errCode =iData->iBluetoothSocket->Connect(*myTBTSockAddr);
       
   773 					}
       
   774 				}
       
   775 			if ( errCode == KErrNone)
       
   776 				{
       
   777         		IncOutstanding();
       
   778         		iConnectFlag = ETrue;
       
   779 		        iConnectIndex = aAsyncErrorIndex;
       
   780 				}
       
   781 			else
       
   782 				{
       
   783 				ERR_PRINTF2(_L("Connect failed: %d"), errCode);
       
   784 				SetError(errCode);
       
   785 				}
       
   786 			}
       
   787 		else
       
   788 			{
       
   789 			ERR_PRINTF1(_L("Connect TBTSockAddr is NULL"));
       
   790 			SetBlockResult(EFail);
       
   791 			}
       
   792 		}
       
   793 	else
       
   794 		{
       
   795 		ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
   796 		SetBlockResult(EFail);
       
   797 		}
       
   798 	}
       
   799 
       
   800 inline void CT_CBluetoothSocketData::DoCmdGetDisconnectData()
       
   801 	{
       
   802 	TInt	errCode = iData->iBluetoothSocket->GetDisconnectData(iDisconnectDes8);
       
   803 	if (errCode != KErrNone)
       
   804 		{
       
   805 		ERR_PRINTF2(_L("GetDisconnectData failed with error code: %d"),errCode);
       
   806 		SetError(errCode);
       
   807 		}
       
   808 	}
       
   809 
       
   810 inline void CT_CBluetoothSocketData::DoCmdGetOpt(const TDesC& aSection)
       
   811 	{
       
   812 	TBool								found;
       
   813 
       
   814 	TBool	equals = ETrue;
       
   815 	GetBoolFromConfig(aSection, KEquals(), equals);
       
   816 	if (equals)
       
   817 		{
       
   818 		INFO_PRINTF1(_L("The comparison is expected to be equal."));
       
   819 		}
       
   820 	else
       
   821 		{
       
   822 		INFO_PRINTF1(_L("The comparison is not expected to be equal."));
       
   823 		}
       
   824 
       
   825 	TBool	dataOk=ETrue;
       
   826 	TPtrC	optionName;
       
   827 	TInt	optionNameValue=0;
       
   828 	if ( GetStringFromConfig(aSection, KOptionName(), optionName) )
       
   829 		{
       
   830 		dataOk=CT_BTUtil::GetIntValue(optionName, optionNameValue);
       
   831 
       
   832 		//Report error but continue as it may still make sense
       
   833 		if (dataOk)
       
   834 			{
       
   835 			INFO_PRINTF3(_L("The name of the option to set: %S , its value: %d" ), &optionName, optionNameValue);
       
   836 			}
       
   837 		else
       
   838 			{
       
   839 			ERR_PRINTF2(_L("Option Level not found in lookup: %S"),&optionName);
       
   840 			SetBlockResult(EFail);
       
   841 			}
       
   842 		}
       
   843 	else
       
   844 		{
       
   845 		dataOk=EFalse;
       
   846 		ERR_PRINTF2(_L("Data %S missing"), &KOptionName());
       
   847 		SetBlockResult(EFail);
       
   848 		}
       
   849 
       
   850 	TPtrC	optionLevel;
       
   851 	TInt	optionLevelValue;
       
   852 	if( GetStringFromConfig(aSection, KOptionLevel(), optionLevel))
       
   853 		{
       
   854 		found=CT_BTUtil::GetIntValue(optionLevel, optionLevelValue);
       
   855 		//Report error but continue as it may still make sense
       
   856 		if (found)
       
   857 			{
       
   858 			INFO_PRINTF3(_L("The name of the option level to set: %S , its value: %d" ),&optionLevel, optionLevelValue);
       
   859 			}
       
   860 		else
       
   861 			{
       
   862 			dataOk=EFalse;
       
   863 			ERR_PRINTF2(_L("Option Level not found in lookup: %S"),&optionLevel);
       
   864 			SetBlockResult(EFail);
       
   865 			}
       
   866 		}
       
   867 	else
       
   868 		{
       
   869 		dataOk=EFalse;
       
   870 		ERR_PRINTF2(_L("Data %S missing"), &KOptionLevel());
       
   871 		SetBlockResult(EFail);
       
   872 		}
       
   873 
       
   874 	if ( dataOk )
       
   875 		{
       
   876 		TBool	getDes=EFalse;
       
   877 		GetBoolFromConfig(aSection, KGetDes(), getDes);
       
   878 
       
   879 		if ( getDes )
       
   880 			{
       
   881 			TBuf8<DATASIZE>	tempData8(_L8(""));
       
   882 			TInt err = iData->iBluetoothSocket->GetOpt(optionNameValue, optionLevelValue, tempData8);
       
   883 			if( err != KErrNone )
       
   884 				{
       
   885 				INFO_PRINTF2(_L("GetOpt() return error %d" ), err);
       
   886 				SetError(err);
       
   887 				}
       
   888 
       
   889 			TBuf<DATASIZE>	tempData;
       
   890 			tempData.Copy(tempData8);
       
   891 			INFO_PRINTF3(_L("The value of the option retrived as des: %S, descriptor length: %d" ), &tempData, tempData.Length());
       
   892 
       
   893 			TPtrC	desOption; // descriptor to compare with if getdes is TRUE
       
   894 			if( GetStringFromConfig(aSection, KDesOption(), desOption))
       
   895 				{
       
   896 				INFO_PRINTF2(_L("The expected descriptor value: %S" ), &desOption);
       
   897 				if ( (desOption==tempData) == equals )
       
   898 					{
       
   899 					INFO_PRINTF1(_L("Option is as expected"));
       
   900 					}
       
   901 				else
       
   902 					{
       
   903 					ERR_PRINTF1(_L("Option is not as expected"));
       
   904 					SetBlockResult(EFail);
       
   905 					}
       
   906 				}
       
   907 			}
       
   908 		else
       
   909 			{
       
   910 			TInt	val;
       
   911 			TInt err = iData->iBluetoothSocket->GetOpt(optionNameValue, optionLevelValue, val);
       
   912 			if( err != KErrNone )
       
   913 				{
       
   914 				INFO_PRINTF2(_L("GetOpt() return error %d" ), err);
       
   915 				SetError(err);
       
   916 				}
       
   917 
       
   918 			INFO_PRINTF2(_L("The value of the option retrived: %d" ),val);
       
   919 
       
   920 			TInt	intOption; // int value to compare with if getdes is FALSE or not defined
       
   921 			if( GetIntFromConfig(aSection, KIntOption(), intOption))
       
   922 				{
       
   923 				INFO_PRINTF1(_L("Comparing results"));
       
   924 				if ( (intOption==val) == equals )
       
   925 					{
       
   926 					INFO_PRINTF1(_L("Option is as expected"));
       
   927 					}
       
   928 				else
       
   929 					{
       
   930 					ERR_PRINTF1(_L("Option is not as expected"));
       
   931 					SetBlockResult(EFail);
       
   932 					}
       
   933 				}
       
   934 			}
       
   935 		}
       
   936 	}
       
   937 
       
   938 inline void CT_CBluetoothSocketData::DoCmdInfo(const TDesC& aSection)
       
   939 	{
       
   940 	TProtocolDesc	protocolDesc;
       
   941 	TInt			err = iData->iBluetoothSocket->Info(protocolDesc);
       
   942 	
       
   943 	if ( err!=KErrNone )
       
   944 		{
       
   945 		ERR_PRINTF2(_L("iBluetoothSocket->Info error: %d"), err);
       
   946 		SetError(err);
       
   947 		}
       
   948 		
       
   949 	INFO_PRINTF2(_L("iBluetoothSocket->Info() = %S"), &protocolDesc.iName);
       
   950 	
       
   951 	TPtrC expectedValue;
       
   952 	if( GetStringFromConfig(aSection, KExpectedReply(), expectedValue) )
       
   953 		{
       
   954 		if( expectedValue != protocolDesc.iName )
       
   955 			{
       
   956 			ERR_PRINTF3(_L("Expected Info (%S) != Actual Info (%S)"), &expectedValue, &protocolDesc.iName);
       
   957 			SetBlockResult(EFail);
       
   958 			}
       
   959 		}
       
   960 	}
       
   961 
       
   962 inline void CT_CBluetoothSocketData::DoCmdIoctl(const TDesC& aSection,const TInt aAsyncErrorIndex)
       
   963 	{
       
   964 	TBool	dataOk = ETrue;
       
   965 	iIoctlFlag = EFalse;
       
   966 	TBool	boolCallTwice = EFalse;
       
   967 	GetBoolFromConfig(aSection, KCallTwice(), boolCallTwice);
       
   968 
       
   969 	TBool	useDeprecated=EFalse;
       
   970 	GetBoolFromConfig(aSection, KUseDeprecated(), useDeprecated);
       
   971 
       
   972 	TBool	found = EFalse;
       
   973 
       
   974 	TPtrC	optionName;
       
   975 	TInt 	optionNameValue=0;
       
   976 	if( GetStringFromConfig(aSection, KOptionName(), optionName))
       
   977 		{
       
   978 		found=CT_BTUtil::GetIntValue(optionName, optionNameValue);
       
   979 		//Report error but continue as it may still make sense
       
   980 		if (found)
       
   981 			{
       
   982 			INFO_PRINTF3(_L("The name of the option to set: %S , its value: %d" ), &optionName, optionNameValue);
       
   983 			}
       
   984 		else
       
   985 			{
       
   986 			dataOk=EFalse;
       
   987 			ERR_PRINTF2(_L("Option not found in lookup: %S"), &optionName);
       
   988 			SetBlockResult(EFail);
       
   989 			}
       
   990 		}
       
   991 	else
       
   992 		{
       
   993 		dataOk=EFalse;
       
   994 		ERR_PRINTF2(_L("Missing: %S"), &KOptionName());
       
   995 		SetBlockResult(EFail);
       
   996 		}
       
   997 
       
   998 	TPtrC	optionLevel;
       
   999 	TInt	optionLevelValue;
       
  1000 	if( GetStringFromConfig(aSection, KOptionLevel(), optionLevel))
       
  1001 		{
       
  1002 		found=CT_BTUtil::GetIntValue(optionLevel, optionLevelValue);
       
  1003 		//Report error but continue as it may still make sense
       
  1004 		if (found)
       
  1005 			{
       
  1006 			INFO_PRINTF3(_L("The name of the option level to set: %S , its value: %d" ), &optionLevel, optionLevelValue);
       
  1007 			}
       
  1008 		else
       
  1009 			{
       
  1010 			ERR_PRINTF2(_L("Option Level not found in lookup: %S"), &optionLevel);
       
  1011 			SetBlockResult(EFail);
       
  1012 			}
       
  1013 		}
       
  1014 	else
       
  1015 		{
       
  1016 		dataOk=EFalse;
       
  1017 		ERR_PRINTF2(_L("Missing: %S"), &KOptionLevel());
       
  1018 		SetBlockResult(EFail);
       
  1019 		}
       
  1020 
       
  1021 	if ( dataOk )
       
  1022 		{
       
  1023 		TInt mtuOptionBufferSize = 0;
       
  1024 		GetIntFromConfig(aSection, KMTUSize(), mtuOptionBufferSize);
       
  1025 
       
  1026 		if( mtuOptionBufferSize > DATASIZE )
       
  1027 			{
       
  1028 			mtuOptionBufferSize = DATASIZE;
       
  1029 			WARN_PRINTF3(_L("mtuOptionBufferSize %d is large, using %d"), mtuOptionBufferSize, DATASIZE);
       
  1030 			}
       
  1031 
       
  1032 		iMTUOptionBuffer = TPckgBuf<TUint16>(mtuOptionBufferSize);
       
  1033 
       
  1034 		TInt	errCode=KErrNone;
       
  1035 		if (useDeprecated)
       
  1036 			{
       
  1037 			errCode=iData->iBluetoothSocket->Ioctl(optionNameValue, &iMTUOptionBuffer, optionLevelValue);
       
  1038 			}
       
  1039 		else
       
  1040 			{
       
  1041 			errCode=iData->iBluetoothSocket->Ioctl(optionLevelValue, optionNameValue, &iMTUOptionBuffer);
       
  1042 			}
       
  1043 
       
  1044 		if (errCode == KErrNone)
       
  1045 			{
       
  1046        		IncOutstanding();
       
  1047        		iIoctlFlag = ETrue;
       
  1048 	        iIoctlIndex = aAsyncErrorIndex;
       
  1049 			}
       
  1050 		else
       
  1051 			{
       
  1052 			ERR_PRINTF2(_L("Send Ioctl failed with error code: %d"), errCode);
       
  1053 			SetError(errCode);
       
  1054 			}
       
  1055 
       
  1056 		if( boolCallTwice )
       
  1057 			{
       
  1058 			if (useDeprecated)
       
  1059 				{
       
  1060 				errCode=iData->iBluetoothSocket->Ioctl(optionNameValue, &iMTUOptionBuffer, optionLevelValue);
       
  1061 				}
       
  1062 			else
       
  1063 				{
       
  1064 				errCode=iData->iBluetoothSocket->Ioctl(optionLevelValue, optionNameValue, &iMTUOptionBuffer);
       
  1065 				}
       
  1066 			if (errCode != KErrNone)
       
  1067 				{
       
  1068 				ERR_PRINTF2(_L("Send Ioctl failed with error code: %d"),errCode);
       
  1069 				SetError(errCode);
       
  1070 				}	
       
  1071 			else
       
  1072 				{
       
  1073            		IncOutstanding();
       
  1074            		iIoctlFlag = ETrue;
       
  1075            		//NB! May be not necessary, because the second call must call panics
       
  1076 	            iIoctlIndex = aAsyncErrorIndex;
       
  1077 				}
       
  1078 			}
       
  1079 		}
       
  1080 	}
       
  1081 
       
  1082 inline void CT_CBluetoothSocketData::DoCmdListen(const TDesC& aSection)
       
  1083 	{
       
  1084 
       
  1085 	TInt	queueSize;
       
  1086 	if ( GetIntFromConfig(aSection, KQueueSize(), queueSize) )
       
  1087 		{
       
  1088 		TInt	errCode=KErrNone;
       
  1089 
       
  1090 		TPtrC	connectData;
       
  1091 		if ( GetStringFromConfig(aSection, KConnectData(), connectData) )
       
  1092 			{
       
  1093 			iConnectData8 = _L8("");
       
  1094 			iConnectData8.Copy(connectData);
       
  1095 			errCode=iData->iBluetoothSocket->Listen(queueSize, iConnectData8);
       
  1096 			}
       
  1097 		else
       
  1098 			{
       
  1099 			TInt serviceBits;
       
  1100 			if ( GetIntFromConfig(aSection, KServiceBits(), serviceBits) )
       
  1101 				{
       
  1102 				INFO_PRINTF2(_L("Using Listen 3 Service bits is: %d"),serviceBits);
       
  1103 				errCode=iData->iBluetoothSocket->Listen(queueSize, serviceBits);
       
  1104 				}
       
  1105 			else
       
  1106 				{
       
  1107 				INFO_PRINTF1(_L("Using Listen 1"));
       
  1108 				errCode=iData->iBluetoothSocket->Listen(queueSize);
       
  1109 				}
       
  1110 			}
       
  1111 		if ( errCode!=KErrNone )
       
  1112 			{
       
  1113 			ERR_PRINTF2(_L("Listen failed: %d"),errCode);
       
  1114 			SetError(errCode);
       
  1115 			}
       
  1116 		}
       
  1117 	else
       
  1118 		{
       
  1119 		ERR_PRINTF2(_L("Missing: %Sfailed"), &KServiceBits());
       
  1120 		SetBlockResult(EFail);
       
  1121 		}
       
  1122 	}
       
  1123 
       
  1124 inline void CT_CBluetoothSocketData::DoCmdLocalName(const TDesC& aSection)
       
  1125 	{
       
  1126 
       
  1127 	T_TBTSockAddrChild	addr;
       
  1128 	iData->iBluetoothSocket->LocalName(addr);
       
  1129 
       
  1130 	TBTDevAddr				currentAddr = addr.BTAddr();
       
  1131 	TBuf<KMaxSockAddrSize>	tmpBuf;
       
  1132 	currentAddr.GetReadable(tmpBuf);
       
  1133 	INFO_PRINTF2(_L("LocalName() = 0x%S"), &tmpBuf);
       
  1134 	TPtrC	myTBTDevAddrName;
       
  1135 	if ( GetStringFromConfig(aSection, KTBTDevAddr(), myTBTDevAddrName) )
       
  1136 		{
       
  1137 		CT_BTDevAddrData* myTBTDevAddrData=static_cast<CT_BTDevAddrData*>(GetDataWrapperL(myTBTDevAddrName));
       
  1138 		TBTDevAddr btDevAddr = *myTBTDevAddrData->GetAddress();
       
  1139 		TBuf<KMaxSockAddrSize> tmpBuf2;
       
  1140 		btDevAddr.GetReadable(tmpBuf2);
       
  1141 		if (tmpBuf2 != tmpBuf)
       
  1142 			{
       
  1143 			ERR_PRINTF3(_L("Expected address (%S) != actual address (%S)"),&tmpBuf2,&tmpBuf);
       
  1144 			SetBlockResult(EFail);
       
  1145 			}
       
  1146 		}
       
  1147 	else
       
  1148 		{
       
  1149 		TInt	lhs;
       
  1150 		TInt	rhs;
       
  1151 		TBool	lhsGiven = EFalse;
       
  1152 		TBool	rhsGiven = EFalse;
       
  1153 		lhsGiven = GetHexFromConfig(aSection, KHexBTAddrL(), lhs );
       
  1154 		rhsGiven = GetHexFromConfig(aSection, KHexBTAddrR(), rhs );
       
  1155 
       
  1156 		if (lhsGiven && rhsGiven)
       
  1157 			{
       
  1158 			TBTDevAddr				btDevAddr (MAKE_TINT64(lhs, rhs));
       
  1159 			TBuf<KMaxSockAddrSize>	tmpBuf2;
       
  1160 			btDevAddr.GetReadable(tmpBuf2);
       
  1161 			if (tmpBuf2 != tmpBuf)
       
  1162 				{
       
  1163 				ERR_PRINTF3(_L("Expected address (%S) != actual address (%S)"),&tmpBuf2,&tmpBuf);
       
  1164 				SetBlockResult(EFail);
       
  1165 				}
       
  1166 			}
       
  1167 		}
       
  1168 
       
  1169 	// Set in TBTSockAddr Data object so that it can be verified
       
  1170 	TPtrC	myTSockAddrName;
       
  1171 	CT_BTSockAddrData* myTSockAddrData=NULL;
       
  1172 	if( GetStringFromConfig(aSection, KTSockAddr(), myTSockAddrName))
       
  1173 		{
       
  1174 		myTSockAddrData=static_cast<CT_BTSockAddrData*>(GetDataWrapperL(myTSockAddrName));
       
  1175 		if ( myTSockAddrData!=NULL )
       
  1176 			{
       
  1177 			myTSockAddrData->SetObject(&addr,EFalse);
       
  1178 			}
       
  1179 		}
       
  1180 	}
       
  1181 
       
  1182 inline void CT_CBluetoothSocketData::DoCmdLocalPort(const TDesC& aSection)
       
  1183 	{
       
  1184 
       
  1185 	TInt	actualPort = iData->iBluetoothSocket->LocalPort();
       
  1186 	INFO_PRINTF2(_L("Actual port is: %d"), actualPort);
       
  1187 
       
  1188 	TInt	port;
       
  1189 	if ( GetIntFromConfig(aSection, KPort(), port) )
       
  1190 		{
       
  1191 		INFO_PRINTF2(_L("Expected port is: %d"), port);
       
  1192 		if ( actualPort!=port )
       
  1193 			{
       
  1194 			ERR_PRINTF1(_L("LocalPort is not as expected"));
       
  1195 			SetBlockResult(EFail);
       
  1196 			}
       
  1197 		}
       
  1198 	}
       
  1199 
       
  1200 inline void CT_CBluetoothSocketData::DoCmdName()
       
  1201 	{
       
  1202 	TName	theName;
       
  1203 	TInt	err=iData->iBluetoothSocket->Name(theName);
       
  1204 	if ( err==KErrNone )
       
  1205 		{
       
  1206 		// good print the name
       
  1207 		INFO_PRINTF2(_L("The socket name is: (%S)" ), &theName);
       
  1208 		}
       
  1209 	else
       
  1210 		{
       
  1211 		ERR_PRINTF2(_L("Failed to get the Name of the Bluetoothsocket, error code %d returned"),err);
       
  1212 		SetError(err);
       
  1213 		}
       
  1214 	}
       
  1215 
       
  1216 inline void CT_CBluetoothSocketData::DoCmdNewL(const TDesC& aSection, TBool aUseLC)
       
  1217 	{
       
  1218 
       
  1219 	TInt constructorType = 0;
       
  1220 	GetIntFromConfig(aSection, KConstructorType(), constructorType);
       
  1221 
       
  1222 	if ((constructorType >0 )&&(constructorType < 6))
       
  1223 		{
       
  1224 		TBool								dataOk=ETrue;
       
  1225 		TBool								found = EFalse;
       
  1226 
       
  1227 		delete iData->iBluetoothSocket;
       
  1228 		iData->iBluetoothSocket = NULL;		
       
  1229 		
       
  1230 		if( constructorType == 1 )
       
  1231 			{
       
  1232 			INFO_PRINTF1(_L("CBluetoothSocket Standard Constructor Call"));
       
  1233 
       
  1234 			TInt 	intSockType=0;
       
  1235 			TPtrC	sockType;
       
  1236 			if( GetStringFromConfig(aSection, KSockType(), sockType) )
       
  1237 				{
       
  1238 				found=CT_BTUtil::GetIntValue(sockType, intSockType);
       
  1239 				if ( !found )
       
  1240 					{
       
  1241 					dataOk=EFalse;
       
  1242 					ERR_PRINTF2(_L("Socket type not found in lookup: %S"),&sockType);
       
  1243 					SetBlockResult(EFail);
       
  1244 					}
       
  1245 				}
       
  1246 			else
       
  1247 				{
       
  1248 				dataOk=EFalse;
       
  1249 				ERR_PRINTF2(_L("Missing :%S"), &KSockType());
       
  1250 				SetBlockResult(EFail);
       
  1251 				}
       
  1252 
       
  1253 			TInt 	intProtocol;
       
  1254 			TPtrC	protocol;
       
  1255 			if ( GetStringFromConfig(aSection, KProtocol(), protocol) )
       
  1256 				{
       
  1257 				found=CT_BTUtil::GetIntValue(protocol, intProtocol);
       
  1258 				if ( !found )
       
  1259 					{
       
  1260 					dataOk=EFalse;
       
  1261 					ERR_PRINTF2(_L("Socket type not found in lookup: %S"),&sockType);
       
  1262 					SetBlockResult(EFail);
       
  1263 					}
       
  1264 				}
       
  1265 			else
       
  1266 				{
       
  1267 				dataOk=EFalse;
       
  1268 				ERR_PRINTF2(_L("Missing :%S"), &KProtocol());
       
  1269 				SetBlockResult(EFail);
       
  1270 				}
       
  1271 
       
  1272 			if ( dataOk )
       
  1273 				{
       
  1274 				if(aUseLC)
       
  1275 					{
       
  1276 					INFO_PRINTF1(_L("CBluetoothSocket Standard Constructor NewLC" ));
       
  1277 					TRAPD(err, iData->iBluetoothSocket = CBluetoothSocket::NewLC(*iData, iData->iSocketServer, intSockType, intProtocol); CleanupStack::Pop(););
       
  1278 
       
  1279 					if( err!=KErrNone )
       
  1280 						{
       
  1281 						INFO_PRINTF2(_L("CBluetoothSocket Standard Constructor NewLC err=%d" ),err);
       
  1282 						SetError(err);
       
  1283 						}
       
  1284 					}
       
  1285 				else	
       
  1286 					{
       
  1287 					INFO_PRINTF1(_L("CBluetoothSocket Standard Constructor NewL" ));
       
  1288 					TRAPD(err, iData->iBluetoothSocket = CBluetoothSocket::NewL(*iData, iData->iSocketServer, intSockType, intProtocol));
       
  1289 
       
  1290 					if( err!=KErrNone )
       
  1291 						{
       
  1292 						INFO_PRINTF2(_L("CBluetoothSocket Standard Constructor NewL err=%d" ),err);
       
  1293 						SetError(err);
       
  1294 						}					
       
  1295 					}	
       
  1296 				}
       
  1297 			}
       
  1298 		else if( constructorType == 2 )
       
  1299 			{
       
  1300 			INFO_PRINTF1(_L("CBluetoothSocket RConnection Constructor Call"));
       
  1301 
       
  1302 			TInt	theSockType=0;
       
  1303 			TPtrC	sockType;
       
  1304 			if ( GetStringFromConfig(aSection, KSockType(), sockType) )
       
  1305 				{
       
  1306 				found=CT_BTUtil::GetIntValue(sockType, theSockType);
       
  1307 				if ( !found )
       
  1308 					{
       
  1309 					dataOk=EFalse;
       
  1310 					ERR_PRINTF2(_L("Socket type not found in lookup: %S"), &sockType);
       
  1311 					SetBlockResult(EFail);
       
  1312 					}
       
  1313 				}
       
  1314 			else
       
  1315 				{
       
  1316 				dataOk=EFalse;
       
  1317 				ERR_PRINTF2(_L("Missing :%S"), &KSockType());
       
  1318 				SetBlockResult(EFail);
       
  1319 				}
       
  1320 
       
  1321 			TInt	theProtocol;
       
  1322 			TPtrC	protocol;
       
  1323 			if ( GetStringFromConfig(aSection, KProtocol(), protocol) )
       
  1324 				{
       
  1325 				found=CT_BTUtil::GetIntValue(protocol, theProtocol);
       
  1326 				if (!found)
       
  1327 					{
       
  1328 					dataOk=EFalse;
       
  1329 					ERR_PRINTF2(_L("Protocol not found in lookup: %S"), &protocol);
       
  1330 					SetBlockResult(EFail);
       
  1331 					}
       
  1332 				}
       
  1333 			else
       
  1334 				{
       
  1335 				dataOk=EFalse;
       
  1336 				ERR_PRINTF2(_L("Missing :%S"), &KProtocol());
       
  1337 				SetBlockResult(EFail);
       
  1338 				}
       
  1339 
       
  1340 			if ( dataOk )
       
  1341 				{
       
  1342 				if ( aUseLC )
       
  1343 					{
       
  1344 					INFO_PRINTF1(_L("CBluetoothSocket RConnection Constructor NewLC" ));
       
  1345 					TRAPD(err, iData->iBluetoothSocket = CBluetoothSocket::NewLC(*iData, iData->iSocketServer, theSockType, theProtocol, iData->iConnection); CleanupStack::Pop(););
       
  1346 					if( err!=KErrNone )
       
  1347 						{
       
  1348 						INFO_PRINTF2(_L("CBluetoothSocket RConnection Constructor NewLC err=%d" ),err);
       
  1349 						SetError(err);
       
  1350 						}
       
  1351 					}				
       
  1352 				else
       
  1353 					{
       
  1354 					INFO_PRINTF1(_L("CBluetoothSocket RConnection Constructor NewL" ));
       
  1355 					TRAPD(err, iData->iBluetoothSocket = CBluetoothSocket::NewL(*iData, iData->iSocketServer, theSockType, theProtocol,iData->iConnection));
       
  1356 
       
  1357 					if( err!=KErrNone )
       
  1358 						{
       
  1359 						INFO_PRINTF2(_L("CBluetoothSocket RConnection Constructor NewL err=%d" ),err);
       
  1360 						SetError(err);
       
  1361 						}					
       
  1362 					}
       
  1363 				}
       
  1364 			}
       
  1365 		else if( constructorType == 3 )
       
  1366 			{
       
  1367 			INFO_PRINTF1(_L("CBluetoothSocket Named Protocol Constructor Call"));
       
  1368 
       
  1369 			TPtrC	namedProtocol;
       
  1370 			if( GetStringFromConfig(aSection, KNamedProtocol(), namedProtocol))
       
  1371 				{
       
  1372 				if (aUseLC)
       
  1373 					{
       
  1374 					INFO_PRINTF1(_L("CBluetoothSocket Named Protocol Constructor NewLC" ));
       
  1375 					TRAPD(err, iData->iBluetoothSocket = CBluetoothSocket::NewLC(*iData, iData->iSocketServer, namedProtocol); CleanupStack::Pop(););
       
  1376 
       
  1377 					if( err!=KErrNone )
       
  1378 						{
       
  1379 						INFO_PRINTF2(_L("CBluetoothSocket Named Protocol Constructor NewLC err=%d" ),err);
       
  1380 						SetError(err);
       
  1381 						}
       
  1382 					}
       
  1383 				
       
  1384 				else
       
  1385 					{
       
  1386 					INFO_PRINTF1(_L("CBluetoothSocket Named Protocol Constructor NewL" ));
       
  1387 					TRAPD(err, iData->iBluetoothSocket = CBluetoothSocket::NewL(*iData, iData->iSocketServer, namedProtocol));
       
  1388 
       
  1389 					if( err!=KErrNone )
       
  1390 						{
       
  1391 						INFO_PRINTF2(_L("CBluetoothSocket Named Protocol Constructor NewL err=%d" ),err);
       
  1392 						SetError(err);
       
  1393 						}				
       
  1394 					}		
       
  1395 				}
       
  1396 			else
       
  1397 				{
       
  1398 				ERR_PRINTF2(_L("Missing :%s"), &KNamedProtocol());
       
  1399 				SetBlockResult(EFail);
       
  1400 				}
       
  1401 			}
       
  1402 		else if( constructorType == 4 )
       
  1403 			{
       
  1404 			if (aUseLC)
       
  1405 				{
       
  1406 				INFO_PRINTF1(_L("CBluetoothSocket Blank Constructor NewLC"));
       
  1407 				TRAPD(err, iData->iBluetoothSocket = CBluetoothSocket::NewLC(*iData, iData->iSocketServer); CleanupStack::Pop(););
       
  1408 		
       
  1409 				if( err!=KErrNone )
       
  1410 					{
       
  1411 					INFO_PRINTF2(_L("CBluetoothSocket Blank Constructor NewLC err=%d" ),err);
       
  1412 					SetError(err);
       
  1413 					}				
       
  1414 				}
       
  1415 			else
       
  1416 				{
       
  1417 				INFO_PRINTF1(_L("CBluetoothSocket Blank Constructor NewL"));
       
  1418 				TRAPD(err, iData->iBluetoothSocket = CBluetoothSocket::NewL(*iData, iData->iSocketServer));
       
  1419 
       
  1420 				if( err!=KErrNone )
       
  1421 					{
       
  1422 					INFO_PRINTF2(_L("CBluetoothSocket Blank Constructor NewL err=%d" ),err);
       
  1423 					SetError(err);
       
  1424 					}				
       
  1425 				}
       
  1426 			}
       
  1427 		else if( constructorType == 5 )
       
  1428 			{
       
  1429 			INFO_PRINTF1(_L("CBluetoothSocket RSocket Constructor Call"));
       
  1430 
       
  1431 			TPtrC		myRSocketName;
       
  1432 			if( GetStringFromConfig(aSection, KRSocket(), myRSocketName))
       
  1433 				{
       
  1434 				RSocket*	myRSocket=static_cast<RSocket*>(GetDataObjectL(myRSocketName));
       
  1435 				if ( myRSocket!=NULL )
       
  1436 					{
       
  1437 					if (aUseLC)
       
  1438 						{
       
  1439 						INFO_PRINTF1(_L("CBluetoothSocket RSocket Constructor NewLC" ));
       
  1440 						TRAPD(err, iData->iBluetoothSocket = CBluetoothSocket::NewLC(*iData, iData->iSocketServer, *myRSocket); CleanupStack::Pop(););
       
  1441 
       
  1442 						if( err!=KErrNone )
       
  1443 							{
       
  1444 							INFO_PRINTF2(_L("CBluetoothSocket RSocket Constructor NewLC err=%d" ),err);
       
  1445 							SetError(err);
       
  1446 							}
       
  1447 						}		
       
  1448 					else
       
  1449 						{
       
  1450 						INFO_PRINTF1(_L("CBluetoothSocket RSocket Constructor NewL" ));
       
  1451 						TRAPD(err, iData->iBluetoothSocket = CBluetoothSocket::NewL(*iData, iData->iSocketServer, *myRSocket));
       
  1452 
       
  1453 						if( err!=KErrNone )
       
  1454 							{
       
  1455 							INFO_PRINTF2(_L("CBluetoothSocket RSocket Constructor NewL err=%d" ),err);
       
  1456 							SetError(err);
       
  1457 							}						
       
  1458 						}
       
  1459 					}
       
  1460 				else
       
  1461 					{
       
  1462 					ERR_PRINTF2(_L("Failed to fetch RSocket named %S"),&myRSocketName);
       
  1463 					SetBlockResult(EFail);
       
  1464 					}
       
  1465 				}
       
  1466 			else
       
  1467 				{
       
  1468 				ERR_PRINTF2(_L("Missing :%S"), &KRSocket());
       
  1469 				SetBlockResult(EFail);
       
  1470 				}
       
  1471 			}
       
  1472 		else
       
  1473 			{
       
  1474 			INFO_PRINTF2(_L("Incorrect constructorType = %d" ),constructorType);
       
  1475 			SetBlockResult(EFail);
       
  1476 			}		
       
  1477 		}
       
  1478 	else
       
  1479 		{
       
  1480 		ERR_PRINTF2(_L("Ilegal value for constructor type value in range 1-5 expected found: %d"),constructorType);
       
  1481 		SetBlockResult(EFail);
       
  1482 		}
       
  1483 	}
       
  1484 
       
  1485 inline void CT_CBluetoothSocketData::DoCmdPhysicalLinkState(const TDesC& aSection)
       
  1486 	{
       
  1487 
       
  1488 	TUint32	tmpstate;
       
  1489 	TInt errCode = iData->iBluetoothSocket->PhysicalLinkState(tmpstate);
       
  1490 	if (errCode != KErrNone)
       
  1491 		{
       
  1492 		ERR_PRINTF2(_L("PhysicalLinkState failed with error code: %d"),errCode);
       
  1493 		SetError(errCode);
       
  1494 		}
       
  1495 		
       
  1496 	TInt state = static_cast<TInt>(tmpstate);	
       
  1497 	//Process the state we can do a nice report here as we know what the bits are
       
  1498 	// See CT_BTUtil as a starting point
       
  1499 	INFO_PRINTF2(_L("PhysicalLinkState: %d" ), state );
       
  1500 	
       
  1501 	TInt expectedState;
       
  1502 	if( GetIntFromConfig(aSection, KState(), expectedState) )
       
  1503 		{
       
  1504 		if( expectedState != state )
       
  1505 			{
       
  1506 			ERR_PRINTF3(_L("Expected PhysicalLinkState (%d) != Actual PhysicalLinkState (%d)"), state, expectedState);
       
  1507 			SetBlockResult(EFail);
       
  1508 			}
       
  1509 		}
       
  1510 	}
       
  1511 
       
  1512 inline void CT_CBluetoothSocketData::DoCmdPreventLowPowerModes(const TDesC& aSection)
       
  1513 	{
       
  1514 	TUint32	mode =0;
       
  1515 	CT_BTUtil::GetLowPowerMode(*this, aSection, mode);
       
  1516 
       
  1517 	TInt	errCode=iData->iBluetoothSocket->PreventLowPowerModes(mode);
       
  1518 	if (errCode != KErrNone)
       
  1519 		{
       
  1520 		ERR_PRINTF2(_L("Send PreventLowPowerModes failed with error code: %d"),errCode);
       
  1521 		SetError(errCode);
       
  1522 		}
       
  1523 	}
       
  1524 
       
  1525 inline void CT_CBluetoothSocketData::DoCmdPreventRoleSwitch()
       
  1526 	{
       
  1527 	TInt errCode = iData->iBluetoothSocket->PreventRoleSwitch();
       
  1528 	if (errCode != KErrNone)
       
  1529 		{
       
  1530 		ERR_PRINTF2(_L("PreventRoleSwitch failed with error code: %d"),errCode);
       
  1531 		SetError(errCode);
       
  1532 		}
       
  1533 	}
       
  1534 
       
  1535 inline void CT_CBluetoothSocketData::DoCmdRead(const TDesC& aSection, const TInt aAsyncErrorIndex)
       
  1536 	{
       
  1537 
       
  1538 	TPtrC	expectedReply;
       
  1539 	iReadFlag = EFalse;
       
  1540 	iHasReceiveDataToExpect=GetStringFromConfig(aSection, KExpectedReply(), expectedReply);
       
  1541 	if ( iHasReceiveDataToExpect )
       
  1542 		{
       
  1543 		iReceiveDataToExpect.Copy(expectedReply);
       
  1544 		}
       
  1545 
       
  1546 	TBool	boolCallTwice = EFalse;
       
  1547 	GetBoolFromConfig(aSection, KCallTwice(), boolCallTwice);
       
  1548 
       
  1549 	TInt	errCode = iData->iBluetoothSocket->Read(iDataToRead8);
       
  1550 	if (errCode == KErrNone)
       
  1551 		{
       
  1552 		IncOutstanding();
       
  1553 		iReadFlag = ETrue;
       
  1554 		iReceiveIndex = aAsyncErrorIndex;
       
  1555 		}
       
  1556 	else
       
  1557 		{
       
  1558 		ERR_PRINTF2(_L("Read failed with error code: %d"),errCode);
       
  1559 		SetError(errCode);
       
  1560 		}
       
  1561 
       
  1562 	if( boolCallTwice )
       
  1563 		{
       
  1564 		errCode = iData->iBluetoothSocket->Read(iDataToRead8);
       
  1565 		if (errCode != KErrNone)
       
  1566 			{
       
  1567 			ERR_PRINTF2(_L("Read failed with error code: %d"),errCode);
       
  1568 			SetError(errCode);	
       
  1569 			}
       
  1570 		else
       
  1571 			{
       
  1572     		IncOutstanding();
       
  1573     		iReadFlag = ETrue;
       
  1574 	    	iReceiveIndex = aAsyncErrorIndex;
       
  1575 			}
       
  1576 		}
       
  1577 	}
       
  1578 
       
  1579 inline void CT_CBluetoothSocketData::DoCmdRecv(const TDesC& aSection, const TInt aAsyncErrorIndex)
       
  1580 	{
       
  1581 
       
  1582 	TPtrC	expectedReply;
       
  1583 	iRecvFlag = EFalse;
       
  1584 	iHasReceiveDataToExpect=GetStringFromConfig(aSection, KExpectedReply(), expectedReply);
       
  1585 	if ( iHasReceiveDataToExpect )
       
  1586 		{
       
  1587 		iReceiveDataToExpect.Copy(expectedReply);
       
  1588 		}
       
  1589 
       
  1590 	TInt	flags=0;
       
  1591 	GetIntFromConfig(aSection, KFlags(), flags);
       
  1592 	TBool	useRecv2 = EFalse;
       
  1593 	GetBoolFromConfig(aSection, KUseRecv2(), useRecv2);
       
  1594 
       
  1595 	TBool	boolCallTwice = EFalse;
       
  1596 	GetBoolFromConfig(aSection, KCallTwice(), boolCallTwice);
       
  1597 
       
  1598 	if (useRecv2)
       
  1599 		{
       
  1600 		INFO_PRINTF1(_L("Using Recv 2"));
       
  1601 		INFO_PRINTF2(_L("Flags: %d"),flags);
       
  1602 		TSockXfrLength	actuallengthSent;
       
  1603 		TInt errCode = iData->iBluetoothSocket->Recv(iDataToRead8, flags, actuallengthSent);
       
  1604 		if (errCode != KErrNone)
       
  1605 			{
       
  1606 			ERR_PRINTF2(_L("Recv failed: %d"),errCode);
       
  1607 			SetError(errCode);
       
  1608 			}
       
  1609 		else
       
  1610 			{
       
  1611        		IncOutstanding();
       
  1612        		iRecvFlag = ETrue;
       
  1613 	        iReceiveIndex = aAsyncErrorIndex;
       
  1614 			}
       
  1615 
       
  1616 		if( boolCallTwice )
       
  1617 			{
       
  1618 			errCode = iData->iBluetoothSocket->Recv(iDataToRead8, flags, actuallengthSent);
       
  1619 			if (errCode != KErrNone)
       
  1620 				{
       
  1621 				ERR_PRINTF2(_L("Recv failed: %d"),errCode);
       
  1622 				SetError(errCode);
       
  1623 				}
       
  1624 			else
       
  1625 				{
       
  1626         		IncOutstanding();
       
  1627         		iRecvFlag = ETrue;
       
  1628 		        iReceiveIndex = aAsyncErrorIndex;
       
  1629 				}
       
  1630 			}
       
  1631 		TInt& lenSentInt=actuallengthSent();
       
  1632 
       
  1633 		INFO_PRINTF2(_L("Returned actual length received: %d"), lenSentInt);
       
  1634 		if ( lenSentInt!=iDataToRead8.Length() )
       
  1635 			{
       
  1636 			ERR_PRINTF3(_L("Returned length received: %d != Actual length received: %d"), lenSentInt, iDataToRead8.Length());
       
  1637 			SetBlockResult(EFail);
       
  1638 			}
       
  1639 		}
       
  1640 	else
       
  1641 		{
       
  1642 		INFO_PRINTF1(_L("Using Recv 1"));
       
  1643 		INFO_PRINTF2(_L("Flags: %d"),flags);
       
  1644 		TInt errCode = iData->iBluetoothSocket->Recv(iDataToRead8, flags);
       
  1645 		if (errCode != KErrNone)
       
  1646 			{
       
  1647 			ERR_PRINTF2(_L("Recv failed: %d"),errCode);
       
  1648 			SetError(errCode);
       
  1649 			}
       
  1650 		else
       
  1651 			{
       
  1652        		IncOutstanding();
       
  1653        		iRecvFlag = ETrue;
       
  1654 	        iReceiveIndex = aAsyncErrorIndex;
       
  1655 			}
       
  1656 		if( boolCallTwice )
       
  1657 			{
       
  1658 			errCode = iData->iBluetoothSocket->Recv(iDataToRead8, flags);
       
  1659 			if (errCode != KErrNone)
       
  1660 				{
       
  1661 				ERR_PRINTF2(_L("Recv failed: %d"),errCode);
       
  1662 				SetError(errCode);
       
  1663 				}
       
  1664 			else
       
  1665 				{
       
  1666         		IncOutstanding();
       
  1667         		iRecvFlag = ETrue;
       
  1668 		        iReceiveIndex = aAsyncErrorIndex;
       
  1669 				}
       
  1670 			}
       
  1671 		}
       
  1672 	}
       
  1673 
       
  1674 inline void CT_CBluetoothSocketData::DoCmdRecvFrom(const TDesC& aSection,const TInt aAsyncErrorIndex)
       
  1675 	{
       
  1676 
       
  1677 	TPtrC	expectedReply;
       
  1678 	iHasReceiveDataToExpect=GetStringFromConfig(aSection, KExpectedReply(), expectedReply);
       
  1679 	if ( iHasReceiveDataToExpect )
       
  1680 		{
       
  1681 		iReceiveDataToExpect.Copy(expectedReply);
       
  1682 		}
       
  1683 
       
  1684 	TBool	useRecv2 = EFalse;
       
  1685 	GetBoolFromConfig(aSection, KUseRecv2(), useRecv2);
       
  1686 
       
  1687 	TInt		flags = 0; // read in, if not found send 0
       
  1688 	GetIntFromConfig(aSection, KFlags(), flags);
       
  1689 	TPtrC	myTSockAddrName;
       
  1690 	TBTSockAddr* myTSockAddr=NULL;
       
  1691 	if( GetStringFromConfig(aSection, KTSockAddr(), myTSockAddrName))
       
  1692 		{
       
  1693 		INFO_PRINTF2(_L("Binding with: %S TSockAddr"), &myTSockAddrName);
       
  1694 		myTSockAddr=static_cast<TBTSockAddr*>(GetDataObjectL(myTSockAddrName));
       
  1695 		if ( myTSockAddr!=NULL )
       
  1696 			{
       
  1697 			if (!useRecv2)
       
  1698 				{
       
  1699 				TInt errCode = iData->iBluetoothSocket->RecvFrom(iDataToRead8, *myTSockAddr, flags);
       
  1700 				if (errCode != KErrNone)
       
  1701 					{
       
  1702 					ERR_PRINTF2(_L("RecvFrom failed with error code: %d"),errCode);
       
  1703 					SetError(errCode);
       
  1704 					}
       
  1705 				else
       
  1706 					{
       
  1707             		IncOutstanding();
       
  1708             	    iReceiveIndex = aAsyncErrorIndex;
       
  1709 					}
       
  1710 				}
       
  1711 			else
       
  1712 				{
       
  1713 				TSockXfrLength lenSent;
       
  1714 				TInt errCode = iData->iBluetoothSocket->RecvFrom(iDataToRead8, *myTSockAddr, flags, lenSent);
       
  1715 				if (errCode != KErrNone)
       
  1716 					{
       
  1717 					ERR_PRINTF2(_L("RecvFrom failed with error code: %d"),errCode);
       
  1718 					SetError(errCode);
       
  1719 					}
       
  1720 				else
       
  1721 					{
       
  1722             		IncOutstanding();
       
  1723             		iReceiveIndex = aAsyncErrorIndex;
       
  1724 					}
       
  1725 				TInt& lenSentInt=lenSent();
       
  1726 
       
  1727 				INFO_PRINTF2(_L("Returned actual length received: %d"), lenSentInt);
       
  1728 				if ( lenSentInt!=iDataToRead8.Length() )
       
  1729 					{
       
  1730 					ERR_PRINTF3(_L("Returned length received: %d != Actual length received: %d"), lenSentInt, iDataToRead8.Length());
       
  1731 					SetBlockResult(EFail);
       
  1732 					}
       
  1733 				}
       
  1734 			}
       
  1735 		else
       
  1736 			{
       
  1737 			ERR_PRINTF1(_L("RecvFrom TBTSockAddr is NULL"));
       
  1738 			SetBlockResult(EFail);
       
  1739 			}
       
  1740 		}
       
  1741 	else
       
  1742 		{
       
  1743 		ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
  1744 		SetBlockResult(EFail);
       
  1745 		}
       
  1746 	}
       
  1747 
       
  1748 inline void CT_CBluetoothSocketData::DoCmdRecvOneOrMore(const TDesC& aSection, const TInt aAsyncErrorIndex)
       
  1749 	{
       
  1750 
       
  1751 	TPtrC	expectedReply;
       
  1752 	iHasReceiveDataToExpect=GetStringFromConfig(aSection, KExpectedReply(), expectedReply);
       
  1753 	if ( iHasReceiveDataToExpect )
       
  1754 		{
       
  1755 		iReceiveDataToExpect.Copy(expectedReply);
       
  1756 		}
       
  1757 
       
  1758 	TInt	flags=0;
       
  1759 	GetIntFromConfig(aSection, KFlags(), flags);
       
  1760 
       
  1761 	TBool	boolCallTwice = EFalse;
       
  1762 	GetBoolFromConfig(aSection, KCallTwice(), boolCallTwice);
       
  1763 
       
  1764 	TSockXfrLength	actuallengthSent;
       
  1765 	TInt errCode = iData->iBluetoothSocket->RecvOneOrMore(iDataToRead8, flags, actuallengthSent);
       
  1766 	if (errCode != KErrNone)
       
  1767 		{
       
  1768 		ERR_PRINTF2(_L("RecvOneOrMore failed: %d"),errCode);
       
  1769 		SetError(errCode);
       
  1770 		}
       
  1771 	else
       
  1772 		{
       
  1773    		IncOutstanding();
       
  1774    		iReceiveIndex = aAsyncErrorIndex;
       
  1775 		}
       
  1776 
       
  1777 	if( boolCallTwice )
       
  1778 		{
       
  1779 		errCode = iData->iBluetoothSocket->RecvOneOrMore(iDataToRead8, flags, actuallengthSent);
       
  1780 		if (errCode != KErrNone)
       
  1781 			{
       
  1782 			ERR_PRINTF2(_L("RecvOneOrMore failed: %d"),errCode);
       
  1783 			SetError(errCode);
       
  1784 			}
       
  1785 		else
       
  1786 			{
       
  1787        		IncOutstanding();
       
  1788        	    iReceiveIndex = aAsyncErrorIndex;
       
  1789 			}
       
  1790 		}
       
  1791 	TInt& lenSentInt=actuallengthSent();
       
  1792 	INFO_PRINTF2(_L("Returned actual length received: %d"), lenSentInt);
       
  1793 	if ( lenSentInt!=iDataToRead8.Length() )
       
  1794 		{
       
  1795 		ERR_PRINTF3(_L("Returned length received: %d != Actual length received: %d"), lenSentInt, iDataToRead8.Length());
       
  1796 		SetBlockResult(EFail);
       
  1797 		}
       
  1798 	}
       
  1799 
       
  1800 inline void CT_CBluetoothSocketData::DoCmdRemoteName(const TDesC& aSection)
       
  1801 	{
       
  1802 	T_TBTSockAddrChild addr;
       
  1803 	iData->iBluetoothSocket->RemoteName(addr);
       
  1804 
       
  1805 	TBTDevAddr currentAddr = addr.BTAddr();
       
  1806 	TBuf<KMaxSockAddrSize> tmpBuf;
       
  1807 	currentAddr.GetReadable(tmpBuf);
       
  1808 	INFO_PRINTF2(_L("RemoteName() = 0x%S"),&tmpBuf);
       
  1809 
       
  1810 
       
  1811 	TPtrC	myTBTDevAddrName;
       
  1812 	if( GetStringFromConfig(aSection, KTBTDevAddr(), myTBTDevAddrName))
       
  1813 		{
       
  1814 		CT_BTDevAddrData* myTBTDevAddrData=static_cast<CT_BTDevAddrData*>(GetDataWrapperL(myTBTDevAddrName));
       
  1815 		TBTDevAddr btDevAddr = *myTBTDevAddrData->GetAddress();
       
  1816 		TBuf<KMaxSockAddrSize> tmpBuf2;
       
  1817 		btDevAddr.GetReadable(tmpBuf2);
       
  1818 		if (tmpBuf2 != tmpBuf)
       
  1819 			{
       
  1820 			ERR_PRINTF3(_L("Expected address (%S) != actual address (%S)"),&tmpBuf2,&tmpBuf);
       
  1821 			SetBlockResult(EFail);
       
  1822 			}
       
  1823 		}
       
  1824 	else
       
  1825 		{
       
  1826 		TInt	lhs;
       
  1827 		TInt	rhs;
       
  1828 		TBool	lhsGiven = EFalse;
       
  1829 		TBool	rhsGiven = EFalse;
       
  1830 		lhsGiven = GetHexFromConfig(aSection, KHexBTAddrL(), lhs );
       
  1831 		rhsGiven = GetHexFromConfig(aSection, KHexBTAddrR(), rhs );
       
  1832 
       
  1833 		if (lhsGiven && rhsGiven)
       
  1834 			{
       
  1835 			TBTDevAddr btDevAddr (MAKE_TINT64(lhs, rhs));
       
  1836 			TBuf<KMaxSockAddrSize> tmpBuf2;
       
  1837 			btDevAddr.GetReadable(tmpBuf2);
       
  1838 			if (tmpBuf2 != tmpBuf)
       
  1839 				{
       
  1840 				ERR_PRINTF3(_L("Expected address (%S) != actual address (%S)"),&tmpBuf2,&tmpBuf);
       
  1841 				SetBlockResult(EFail);
       
  1842 				}
       
  1843 			}
       
  1844 		}
       
  1845 
       
  1846 	// Set in TBTSockAddr Data object so that it can be verified
       
  1847 	TPtrC	myTSockAddrName;
       
  1848 	CT_BTSockAddrData* myTSockAddrData=NULL;
       
  1849 	if( GetStringFromConfig(aSection, KTSockAddr(), myTSockAddrName))
       
  1850 		{
       
  1851 		myTSockAddrData=static_cast<CT_BTSockAddrData*>(GetDataWrapperL(myTSockAddrName));
       
  1852 		if ( myTSockAddrData!=NULL )
       
  1853 			{
       
  1854 			myTSockAddrData->SetObject(&addr,EFalse);
       
  1855 			}
       
  1856 		}
       
  1857 	}
       
  1858 
       
  1859 inline void CT_CBluetoothSocketData::DoCmdRequestChangeSupportedPacketTypes(const TDesC& aSection)
       
  1860 	{
       
  1861 	TInt	mask = 0;
       
  1862 	CT_BTUtil::GetTBTPacketType(*this, aSection, mask);
       
  1863 	TInt	errCode = iData->iBluetoothSocket->RequestChangeSupportedPacketTypes(mask);
       
  1864 	if (errCode != KErrNone)
       
  1865 		{
       
  1866 		ERR_PRINTF2(_L("RequestChangeSupportedPacketTypes failed with error code: %d"),errCode);
       
  1867 		SetError(errCode);
       
  1868 		}
       
  1869 	}
       
  1870 
       
  1871 inline void CT_CBluetoothSocketData::DoCmdRequestMasterRole()
       
  1872 	{
       
  1873 	TInt errCode = iData->iBluetoothSocket->RequestMasterRole();
       
  1874 	if (errCode != KErrNone)
       
  1875 		{
       
  1876 		ERR_PRINTF2(_L("RequestMasterRole failed with error code: %d"),errCode);
       
  1877 		SetError(errCode);
       
  1878 		}
       
  1879 	}
       
  1880 
       
  1881 inline void CT_CBluetoothSocketData::DoCmdRequestSlaveRole()
       
  1882 	{
       
  1883 	TInt errCode = iData->iBluetoothSocket->RequestSlaveRole();
       
  1884 	if (errCode != KErrNone)
       
  1885 		{
       
  1886 		ERR_PRINTF2(_L("RequestSlaveRole failed with error code: %d"),errCode);
       
  1887 		SetError(errCode);
       
  1888 		}
       
  1889 	}
       
  1890 
       
  1891 inline void CT_CBluetoothSocketData::DoCmdSend(const TDesC& aSection, const TInt aAsyncErrorIndex)
       
  1892 	{
       
  1893 	TPtrC dataToSend;
       
  1894 	iSendFlag = EFalse;
       
  1895 	if( GetStringFromConfig(aSection, KData(), dataToSend))
       
  1896 		{
       
  1897 		INFO_PRINTF2(_L("About to send: [%S]"), &dataToSend);
       
  1898 
       
  1899 		TBuf8<DATASIZE> 	dataToSend8(_L8(""));
       
  1900 		dataToSend8.Copy(dataToSend);
       
  1901 
       
  1902 		for ( ;dataToSend8.Length()<DATASIZE;)
       
  1903 			{
       
  1904 			dataToSend8.Append(_L8("#"));
       
  1905 			}
       
  1906 
       
  1907 		TBool boolCallTwice = EFalse;
       
  1908 		GetBoolFromConfig(aSection, KCallTwice(), boolCallTwice);
       
  1909 
       
  1910 		TInt flags=0;
       
  1911 		GetIntFromConfig(aSection, KFlags(), flags);
       
  1912 		TBool useSend2 =EFalse;
       
  1913 		GetBoolFromConfig(aSection, KUseSend2(), useSend2);
       
  1914 		if (useSend2!=EFalse)
       
  1915 			{
       
  1916 			INFO_PRINTF1(_L("Using Send 2"));
       
  1917 			INFO_PRINTF2(_L("Flags: %d"),flags);
       
  1918 			TSockXfrLength actuallengthSent;
       
  1919 
       
  1920 			TInt errCode = iData->iBluetoothSocket->Send(dataToSend8,flags,actuallengthSent);
       
  1921 			if (errCode != KErrNone)
       
  1922 				{
       
  1923 				ERR_PRINTF2(_L("Send failed: %d"),errCode);
       
  1924 				SetError(errCode);
       
  1925 				}
       
  1926 			else
       
  1927 				{
       
  1928         		IncOutstanding();
       
  1929 		        iSendIndex = aAsyncErrorIndex;
       
  1930 				}
       
  1931 			if( boolCallTwice )
       
  1932 				{
       
  1933 				errCode = iData->iBluetoothSocket->Send(dataToSend8,flags,actuallengthSent);
       
  1934 				if (errCode != KErrNone)
       
  1935 					{
       
  1936 					ERR_PRINTF2(_L("Send failed: %d"),errCode);
       
  1937 					SetError(errCode);
       
  1938 					}
       
  1939 				else
       
  1940 					{
       
  1941             		IncOutstanding();
       
  1942             		iSendFlag = ETrue;
       
  1943 	    	        iSendIndex = aAsyncErrorIndex;
       
  1944 					}
       
  1945 				}
       
  1946 			if (errCode == KErrNone)
       
  1947 				{
       
  1948 				TInt& lenSentInt=actuallengthSent();
       
  1949 				INFO_PRINTF2(_L("Returned length actual sent: %d"), lenSentInt);
       
  1950 				if (lenSentInt != dataToSend8.Length())
       
  1951 					{
       
  1952 					INFO_PRINTF3(_L("Returned length sent: %d != Actual length sent: %d"),lenSentInt,dataToSend8.Length());
       
  1953 					SetBlockResult(EFail);
       
  1954 					}	
       
  1955 				}
       
  1956 			}
       
  1957 		else
       
  1958 			{
       
  1959 			INFO_PRINTF1(_L("Using Send 1"));
       
  1960 			INFO_PRINTF2(_L("Flags: %d"),flags);
       
  1961 			TInt errCode = iData->iBluetoothSocket->Send(dataToSend8,flags);
       
  1962 			if (errCode != KErrNone)
       
  1963 				{
       
  1964 				ERR_PRINTF2(_L("Send failed: %d"),errCode);
       
  1965 				SetError(errCode);
       
  1966 				}
       
  1967 			else
       
  1968 				{
       
  1969         		IncOutstanding();
       
  1970         		iSendFlag = ETrue;
       
  1971 		        iSendIndex = aAsyncErrorIndex;
       
  1972 				}
       
  1973 			if( boolCallTwice )
       
  1974 				{
       
  1975 				errCode = iData->iBluetoothSocket->Send(dataToSend8,flags);
       
  1976 				if (errCode != KErrNone)
       
  1977 					{
       
  1978 					ERR_PRINTF2(_L("Send failed: %d"),errCode);
       
  1979 					SetError(errCode);
       
  1980 					}
       
  1981 				else
       
  1982 					{
       
  1983             		IncOutstanding();
       
  1984             		iSendFlag = ETrue;
       
  1985 	    	        iSendIndex = aAsyncErrorIndex;
       
  1986 					}
       
  1987 				}
       
  1988 			}
       
  1989 		}
       
  1990 	else
       
  1991 		{
       
  1992 		ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
  1993 		SetBlockResult(EFail);
       
  1994 		}
       
  1995 	}
       
  1996 
       
  1997 inline void CT_CBluetoothSocketData::DoCmdSendTo(const TDesC& aSection,const TInt aAsyncErrorIndex)
       
  1998 	{
       
  1999 	TBool useSend2 =EFalse;
       
  2000 	GetBoolFromConfig(aSection, KUseSend2(), useSend2);
       
  2001 
       
  2002 	TInt flags = 0; // read in, if not found send 0
       
  2003 	GetIntFromConfig(aSection, KFlags(), flags);
       
  2004 	TPtrC dataToSend;
       
  2005 	if( GetStringFromConfig(aSection, KData(), dataToSend))
       
  2006 		{
       
  2007 		INFO_PRINTF2(_L("About to send: [%S]"), &dataToSend);
       
  2008     	TBool boolCallTwice = EFalse;
       
  2009 		GetBoolFromConfig(aSection, KCallTwice(), boolCallTwice);
       
  2010 
       
  2011 		TBuf8<DATASIZE> 	dataToSend8(_L8(""));
       
  2012 		dataToSend8.Copy(dataToSend);
       
  2013 		TPtrC	myTSockAddrName;
       
  2014 		TBTSockAddr* myTSockAddr=NULL;
       
  2015 		if( GetStringFromConfig(aSection, KTSockAddr(), myTSockAddrName))
       
  2016 			{
       
  2017 			INFO_PRINTF2(_L("Binding with: %S TSockAddr"), &myTSockAddrName);
       
  2018 			myTSockAddr=static_cast<TBTSockAddr*>(GetDataObjectL(myTSockAddrName));
       
  2019 			if ( myTSockAddr!=NULL )
       
  2020 				{
       
  2021 				if (!useSend2)
       
  2022 					{
       
  2023 					TInt errCode = iData->iBluetoothSocket->SendTo(dataToSend8,*myTSockAddr,flags);
       
  2024 					if (errCode != KErrNone)
       
  2025 						{
       
  2026 						ERR_PRINTF2(_L("SendTo failed with error code: %d"),errCode);
       
  2027 						SetError(errCode);
       
  2028 						}
       
  2029 					else
       
  2030 						{
       
  2031                 		IncOutstanding();
       
  2032                 	    iSendIndex = aAsyncErrorIndex;
       
  2033 						}
       
  2034 					if( boolCallTwice )
       
  2035 						{
       
  2036 						errCode = iData->iBluetoothSocket->SendTo(dataToSend8,*myTSockAddr,flags);
       
  2037 						if (errCode != KErrNone)
       
  2038 							{
       
  2039 							ERR_PRINTF2(_L("SendTo failed with error code: %d"),errCode);
       
  2040 							SetError(errCode);
       
  2041 							}
       
  2042 						else
       
  2043 							{
       
  2044                     		IncOutstanding();
       
  2045                     		iSendIndex = aAsyncErrorIndex;
       
  2046 							}
       
  2047 						}
       
  2048 					}
       
  2049 				else
       
  2050 					{
       
  2051 					TSockXfrLength lenSent;
       
  2052 					TInt errCode = iData->iBluetoothSocket->SendTo(dataToSend8,*myTSockAddr,flags,lenSent);
       
  2053 					if (errCode != KErrNone)
       
  2054 						{
       
  2055 						ERR_PRINTF2(_L("SendTo failed with error code: %d"),errCode);
       
  2056 						SetError(errCode);
       
  2057 						}
       
  2058 					else
       
  2059 						{
       
  2060                 		IncOutstanding();
       
  2061                 		iSendIndex = aAsyncErrorIndex;
       
  2062 						}
       
  2063 					if( boolCallTwice )
       
  2064 						{
       
  2065 						errCode = iData->iBluetoothSocket->SendTo(dataToSend8,*myTSockAddr,flags,lenSent);
       
  2066 						if (errCode != KErrNone)
       
  2067 							{
       
  2068 							ERR_PRINTF2(_L("SendTo failed with error code: %d"),errCode);
       
  2069 							SetError(errCode);
       
  2070 							}
       
  2071 						else
       
  2072 							{
       
  2073                     		IncOutstanding();
       
  2074                     	    iSendIndex = aAsyncErrorIndex;
       
  2075 							}
       
  2076 						}
       
  2077 					if (errCode == KErrNone)
       
  2078 						{
       
  2079 						TInt& lenSentInt=lenSent();
       
  2080 						INFO_PRINTF2(_L("Returned actual length sent: %d"), lenSentInt);
       
  2081 						if (lenSentInt != dataToSend8.Length())
       
  2082 							{
       
  2083 							INFO_PRINTF3(_L("Returned length sent: %d != Actual length sent: %d"),lenSentInt,dataToSend8.Length());
       
  2084 							}	
       
  2085 						}
       
  2086 				
       
  2087 					}
       
  2088 				}
       
  2089 			else
       
  2090 				{
       
  2091 				ERR_PRINTF1(_L("SendTo TBTSockAddr is NULL"));
       
  2092 				SetBlockResult(EFail);
       
  2093 				}
       
  2094 			}
       
  2095 		else
       
  2096 			{
       
  2097 			ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
  2098 			SetBlockResult(EFail);
       
  2099 			}
       
  2100 		}
       
  2101 	else
       
  2102 		{
       
  2103 		ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
  2104 		SetBlockResult(EFail);
       
  2105 		}
       
  2106 	}
       
  2107 
       
  2108 inline void CT_CBluetoothSocketData::DoCmdSetAutomaticSniffMode(const TDesC& aSection)
       
  2109 	{
       
  2110 	
       
  2111 	TBool	sniffMode = EFalse;
       
  2112 	GetBoolFromConfig(aSection, KSniffMode(), sniffMode);
       
  2113 
       
  2114 	TInt errCode = KErrNone;
       
  2115 
       
  2116 	TInt	sniffDelay = 0;
       
  2117 	if( GetIntFromConfig(aSection, KSniffDelay(), sniffDelay) )
       
  2118 		{
       
  2119 		INFO_PRINTF3(_L("SetAutomaticSniffMode(%d, %d)"), sniffMode, sniffDelay);
       
  2120 		errCode = iData->iBluetoothSocket->SetAutomaticSniffMode(sniffMode, sniffDelay);
       
  2121 		}
       
  2122 	else
       
  2123 		{
       
  2124 		INFO_PRINTF2(_L("SetAutomaticSniffMode(%d)"), sniffMode);
       
  2125 		errCode = iData->iBluetoothSocket->SetAutomaticSniffMode(sniffMode);
       
  2126 		}
       
  2127 	
       
  2128 	if (errCode!=KErrNone)
       
  2129 		{
       
  2130 		ERR_PRINTF2(_L("SetAutomaticSniffMode failed: %d"),errCode);
       
  2131 		SetError(errCode);
       
  2132 		}
       
  2133 	}
       
  2134 
       
  2135 inline void CT_CBluetoothSocketData::DoCmdSetLocalPort(const TDesC& aSection)
       
  2136 	{
       
  2137 	TInt	port;
       
  2138 
       
  2139 	if( GetIntFromConfig(aSection, KPort(), port))
       
  2140 		{
       
  2141 		INFO_PRINTF2(_L("Port to set is: %d"), port);
       
  2142 		TInt errCode = iData->iBluetoothSocket->SetLocalPort(port);
       
  2143 		if (errCode!=KErrNone)
       
  2144 			{
       
  2145 			ERR_PRINTF2(_L("SetLocalPort failed: %d"),errCode);
       
  2146 			SetError(errCode);
       
  2147 			}
       
  2148 		}
       
  2149 	else
       
  2150 		{
       
  2151 		ERR_PRINTF2(_L("Missing :%S"), &KPort());
       
  2152 		SetBlockResult(EFail);
       
  2153 		}
       
  2154 	}
       
  2155 
       
  2156 inline void CT_CBluetoothSocketData::DoCmdSetNotifierL(const TDesC& aSection)
       
  2157 	{
       
  2158 	MBluetoothSocketNotifier* theNotifier = iData;
       
  2159 
       
  2160 	TBool	useAlternate =EFalse;
       
  2161 	GetBoolFromConfig(aSection, KUseAlternateNotifier(), useAlternate);
       
  2162 	if (useAlternate)
       
  2163 		{
       
  2164 		theNotifier=this;
       
  2165 		}
       
  2166 
       
  2167 	iData->iBluetoothSocket->SetNotifier(*theNotifier);
       
  2168 	}
       
  2169 
       
  2170 inline void CT_CBluetoothSocketData::DoCmdSetOpt(const TDesC& aSection)
       
  2171 	{
       
  2172 	TPtrC optionName;
       
  2173 	TPtrC optionLevel;
       
  2174 	TInt optionNameValue;
       
  2175 	TInt optionLevelValue;
       
  2176 	TBool found = EFalse;
       
  2177 	if( GetStringFromConfig(aSection, KOptionName(), optionName))
       
  2178 		{
       
  2179 		found=CT_BTUtil::GetIntValue(optionName, optionNameValue);
       
  2180 		//Report error but continue as it may still make sense
       
  2181 		if (!found)
       
  2182 			{
       
  2183 			ERR_PRINTF2(_L("Option not found in lookup: %S"),&optionName);
       
  2184 			SetBlockResult(EFail);
       
  2185 			}
       
  2186 		INFO_PRINTF3(_L("The name of the option to set: %S , its value: %d" ),&optionName, optionNameValue);
       
  2187 		if( GetStringFromConfig(aSection, KOptionLevel(), optionLevel))
       
  2188 			{
       
  2189 			found=CT_BTUtil::GetIntValue(optionLevel, optionLevelValue);
       
  2190 			//Report error but continue as it may still make sense
       
  2191 			if (!found)
       
  2192 				{
       
  2193 				ERR_PRINTF2(_L("Option Level not found in lookup: %S"),&optionLevel);
       
  2194 				SetBlockResult(EFail);
       
  2195 				}
       
  2196 			INFO_PRINTF3(_L("The name of the option level to set: %S , its value: %d" ),&optionLevel, optionLevelValue);
       
  2197 			TPtrC intOptionName;
       
  2198 			if( GetStringFromConfig(aSection, KNamedIntOption(), intOptionName))
       
  2199 				{
       
  2200 				INFO_PRINTF1(_L("Using SetOpt1 with named constant value"));
       
  2201 				TInt	intOption;
       
  2202 				found=CT_BTUtil::GetIntValue(intOptionName, intOption);
       
  2203 				//Report error but continue as it may still make sense
       
  2204 				if (!found)
       
  2205 					{
       
  2206 					ERR_PRINTF2(_L("Option not found in lookup: %S"),&optionLevel);
       
  2207 					SetBlockResult(EFail);
       
  2208 					}
       
  2209 				INFO_PRINTF3(_L("The name of the option level to set: %S its value: %d" ),&intOptionName, intOption);
       
  2210 				iData->iBluetoothSocket->SetOpt(optionNameValue,optionLevelValue,intOption);
       
  2211 				}
       
  2212 			else
       
  2213 				{
       
  2214 				TInt intOption;
       
  2215 				if( GetIntFromConfig(aSection, KIntOption(), intOption))
       
  2216 					{
       
  2217 					INFO_PRINTF1(_L("Using SetOpt1 with int value"));
       
  2218 					INFO_PRINTF2(_L("The value of the option level to set: %d" ),intOption);
       
  2219 					iData->iBluetoothSocket->SetOpt(optionNameValue,optionLevelValue,intOption);
       
  2220 					}
       
  2221 				else
       
  2222 					{
       
  2223 					TPtrC desOption;
       
  2224 					if( GetStringFromConfig(aSection, KDesOption(), desOption))
       
  2225 						{
       
  2226 						INFO_PRINTF2(_L("The option level to set: %S" ),&desOption);
       
  2227 						TBuf8<DATASIZE> desOption8(_L8(""));
       
  2228 						desOption8.Copy(desOption);
       
  2229 						INFO_PRINTF3(_L("desOption len %d, desOption8 len %d" ),desOption.Length(), desOption8.Length());
       
  2230 						INFO_PRINTF1(_L("Using Deprecated SetOpt2"));
       
  2231 						iData->iBluetoothSocket->SetOpt(optionNameValue,optionLevelValue,desOption8);
       
  2232 						}
       
  2233 					else
       
  2234 						{
       
  2235 						// Use default parameter for SetOpt i.e. call with two parameters only
       
  2236 						INFO_PRINTF1(_L("Using Deprecated SetOpt2 with default value"));
       
  2237 						iData->iBluetoothSocket->SetOpt(optionNameValue,optionLevelValue);
       
  2238 						}
       
  2239 					}
       
  2240 				}
       
  2241 			}
       
  2242 		else
       
  2243 			{
       
  2244 			ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
  2245 			SetBlockResult(EFail);
       
  2246 			}
       
  2247 		}
       
  2248 	else
       
  2249 		{
       
  2250 		ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
  2251 		SetBlockResult(EFail);
       
  2252 		}
       
  2253 	}
       
  2254 
       
  2255 
       
  2256 inline void CT_CBluetoothSocketData::DoCmdSetOption(const TDesC& aSection)
       
  2257 	{
       
  2258 	TPtrC optionName;
       
  2259 	TPtrC optionLevel;
       
  2260 	TInt optionNameValue;
       
  2261 	TInt optionLevelValue;
       
  2262 	TBool found = EFalse;
       
  2263 	if( GetStringFromConfig(aSection, KOptionName(), optionName))
       
  2264 		{
       
  2265 		found=CT_BTUtil::GetIntValue(optionName, optionNameValue);
       
  2266 		//Report error but continue as it may still make sense
       
  2267 		if (!found)
       
  2268 			{
       
  2269 			ERR_PRINTF2(_L("Option not found in lookup: %S"),&optionName);
       
  2270 			SetBlockResult(EFail);
       
  2271 			}
       
  2272 		INFO_PRINTF3(_L("The name of the option to set: %S , its value: %d" ),&optionName, optionNameValue);
       
  2273 		if( GetStringFromConfig(aSection, KOptionLevel(), optionLevel))
       
  2274 			{
       
  2275 			found=CT_BTUtil::GetIntValue(optionLevel, optionLevelValue);
       
  2276 			//Report error but continue as it may still make sense
       
  2277 			if (!found)
       
  2278 				{
       
  2279 				ERR_PRINTF2(_L("Option Level not found in lookup: %S"),&optionLevel);
       
  2280 				SetBlockResult(EFail);
       
  2281 				}
       
  2282 
       
  2283 			TPtrC desOption;
       
  2284 			if( GetStringFromConfig(aSection, KDesOption(), desOption))
       
  2285 				{
       
  2286 				INFO_PRINTF2(_L("The option level to set: %S" ),&desOption);
       
  2287 				TBuf8<DATASIZE> desOption8(_L8(""));
       
  2288 				desOption8.Copy(desOption);
       
  2289 
       
  2290 				INFO_PRINTF3(_L("desOption len %d, desOption8 len %d" ),desOption.Length(), desOption8.Length());
       
  2291 				INFO_PRINTF1(_L("Using SetOption"));
       
  2292 				iData->iBluetoothSocket->SetOption(optionNameValue,optionLevelValue,desOption8);
       
  2293 				}
       
  2294 			else
       
  2295 				{
       
  2296 				ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
  2297 				SetBlockResult(EFail);
       
  2298 				}
       
  2299 			}
       
  2300 		else
       
  2301 			{
       
  2302 			ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
  2303 			SetBlockResult(EFail);
       
  2304 			}
       
  2305 		}
       
  2306 	else
       
  2307 		{
       
  2308 		ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
  2309 		SetBlockResult(EFail);
       
  2310 		}
       
  2311 	}
       
  2312 
       
  2313 inline void CT_CBluetoothSocketData::DoCmdShutdown(const TDesC& aSection, const TInt aAsyncErrorIndex)
       
  2314 	{
       
  2315 
       
  2316 	TBool	boolCallTwice = EFalse;
       
  2317 	GetBoolFromConfig(aSection, KCallTwice(), boolCallTwice);
       
  2318 
       
  2319     RSocket::TShutdown	shutdown=RSocket::ENormal;
       
  2320 	TBool				dataOk=CT_BTUtil::GetShutdown(*this, aSection, shutdown);
       
  2321 
       
  2322 	if ( dataOk )
       
  2323 		{
       
  2324 		TInt			err=KErrNone;
       
  2325 		TBuf8<DATASIZE>	dataToSend8(_L8(""));
       
  2326 		TPtrC			disconnectData;
       
  2327 		TBool			hasDisconnectData=GetStringFromConfig(aSection, KDisconnectData(), disconnectData);
       
  2328 		if( hasDisconnectData )
       
  2329 			{
       
  2330 			INFO_PRINTF1(_L("Using second shutdown"));
       
  2331 			dataToSend8.Copy(disconnectData);
       
  2332 			err = iData->iBluetoothSocket->Shutdown(shutdown, dataToSend8, iDataAtDisconnect8);
       
  2333 			}
       
  2334 		else
       
  2335 			{
       
  2336 			INFO_PRINTF1(_L("Using standard shutdown"));
       
  2337 			err = iData->iBluetoothSocket->Shutdown(shutdown);
       
  2338 			}
       
  2339 		if ( err==KErrNone )
       
  2340 			{
       
  2341        		IncOutstanding();
       
  2342 	        iShutdownIndex = aAsyncErrorIndex;
       
  2343 			}
       
  2344 		else
       
  2345 			{
       
  2346 			ERR_PRINTF2(_L("Shutdown of iBluetoothSocket failed with error code %d"), err);
       
  2347 			SetError(err);
       
  2348 			}
       
  2349 
       
  2350 		if( boolCallTwice )
       
  2351 			{
       
  2352 			if ( hasDisconnectData )
       
  2353 				{
       
  2354 				err = iData->iBluetoothSocket->Shutdown(shutdown, dataToSend8, iDataAtDisconnect8);
       
  2355 				}
       
  2356 			else
       
  2357 				{
       
  2358 				err = iData->iBluetoothSocket->Shutdown(shutdown);
       
  2359 				}
       
  2360 			if (err != KErrNone )
       
  2361 				{
       
  2362 				ERR_PRINTF2(_L("Shutdown of iBluetoothSocket failed with error code %d"),err);
       
  2363 				SetError(err);
       
  2364 				}
       
  2365 			}
       
  2366 		}
       
  2367 	}
       
  2368 
       
  2369 inline void CT_CBluetoothSocketData::DoCmdTransfer(const TDesC& aSection)
       
  2370 	{
       
  2371 	INFO_PRINTF1(_L("Transfer the Bluetooth socket to this testddata object" ));
       
  2372 
       
  2373 	TPtrC	myRSocketName;
       
  2374 	RSocket* myRSocket=NULL;
       
  2375 	if( GetStringFromConfig(aSection, KRSocket(), myRSocketName))
       
  2376 		{
       
  2377 		INFO_PRINTF2(_L("Transfering: %S to this RSocketServer"), &myRSocketName);
       
  2378 		myRSocket=static_cast<RSocket*>(GetDataObjectL(myRSocketName));
       
  2379 		if ( myRSocket!=NULL )
       
  2380 			{
       
  2381 			TName myRSockName;
       
  2382 			myRSocket->Name(myRSockName);
       
  2383 
       
  2384 			if (myRSockName.Length()>0)
       
  2385 				{
       
  2386 				TInt err = iData->iBluetoothSocket->Transfer(iData->iSocketServer, myRSockName);
       
  2387 				if (err == KErrNone )
       
  2388 					{
       
  2389 					INFO_PRINTF1(_L("Transfer successful" ));
       
  2390 					}
       
  2391 				else
       
  2392 					{
       
  2393 					ERR_PRINTF2(_L("Transfer failed with error code %d"),err);
       
  2394 					SetError(err);
       
  2395 					}
       
  2396 				}
       
  2397 			else
       
  2398 				{
       
  2399 				ERR_PRINTF1(_L("Failed to fetch RSocket name"));
       
  2400 				SetBlockResult(EFail);
       
  2401 				}
       
  2402 			}
       
  2403 		else
       
  2404 			{
       
  2405 			ERR_PRINTF2(_L("Failed to fetch RSocket from %S"),&myRSocketName);
       
  2406 			SetBlockResult(EFail);
       
  2407 			}
       
  2408 		}
       
  2409 	else
       
  2410 		{
       
  2411 		ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
  2412 		SetBlockResult(EFail);
       
  2413 		}
       
  2414 	}
       
  2415 
       
  2416 inline void CT_CBluetoothSocketData::DoCmdWrite(const TDesC& aSection,const TInt aAsyncErrorIndex)
       
  2417 	{
       
  2418 
       
  2419 	TPtrC dataToSend;
       
  2420 	iWriteFlag = EFalse;
       
  2421 	if( GetStringFromConfig(aSection, KData(), dataToSend))
       
  2422 		{
       
  2423 		INFO_PRINTF2(_L("About to write: [%S]"), &dataToSend);
       
  2424 
       
  2425 		TBool boolCallTwice = EFalse;
       
  2426 		GetBoolFromConfig(aSection, KCallTwice(), boolCallTwice);
       
  2427 
       
  2428 		TBuf8<DATASIZE> dataToSend8(_L8(""));
       
  2429 		dataToSend8.Copy(dataToSend);
       
  2430 
       
  2431 		for ( ;dataToSend8.Length()<DATASIZE;)
       
  2432 			{
       
  2433 			dataToSend8.Append(_L8("#"));
       
  2434 			}
       
  2435 		TInt errCode = iData->iBluetoothSocket->Write(dataToSend8);
       
  2436 		if (errCode != KErrNone)
       
  2437 			{
       
  2438 			ERR_PRINTF2(_L("ActivateBasebandEventNotifier failed with error code: %d"),errCode);
       
  2439 			SetError(errCode);
       
  2440 			}
       
  2441 		else
       
  2442 			{
       
  2443       		IncOutstanding();
       
  2444       		iWriteFlag = ETrue;
       
  2445 	        iSendIndex = aAsyncErrorIndex;
       
  2446 			}
       
  2447 		if( boolCallTwice )
       
  2448 			{
       
  2449 			errCode = iData->iBluetoothSocket->Write(dataToSend8);
       
  2450 			if (errCode != KErrNone)
       
  2451 				{
       
  2452 				ERR_PRINTF2(_L("ActivateBasebandEventNotifier failed with error code: %d"),errCode);
       
  2453 				SetError(errCode);
       
  2454 				}
       
  2455 			else
       
  2456 				{
       
  2457         		IncOutstanding();
       
  2458         		iWriteFlag = ETrue;
       
  2459 		        iSendIndex = aAsyncErrorIndex;
       
  2460 				}
       
  2461 			}
       
  2462 		}
       
  2463 	else
       
  2464 		{
       
  2465 		ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
  2466 		SetBlockResult(EFail);
       
  2467 		}
       
  2468 	}
       
  2469 
       
  2470 inline void CT_CBluetoothSocketData::DoCmdTestMBSN_ExtensionInterfaceL(const TDesC& aSection)
       
  2471 	{
       
  2472 	TInt	tmp;
       
  2473 	void* theExtensionObjectPtr;
       
  2474 
       
  2475 	TBool expectNull = EFalse;
       
  2476 	GetBoolFromConfig(aSection, KExpectNull(), expectNull);
       
  2477 
       
  2478 	if( GetIntFromConfig(aSection, KUid(), tmp))
       
  2479 		{
       
  2480 		TUid uid=TUid::Uid(tmp);
       
  2481 		TRAPD(err, iData->MBSN_ExtensionInterfaceL(uid,theExtensionObjectPtr));
       
  2482 		if( err!=KErrNone )
       
  2483 			{
       
  2484 			ERR_PRINTF2(_L("MBSN_ExtensionInterfaceL err=%d"),err);
       
  2485 			SetError(EFail);
       
  2486 			}
       
  2487 
       
  2488 		if (expectNull)
       
  2489 			{
       
  2490 			//Fail if not NULL
       
  2491 			if (theExtensionObjectPtr!=NULL)
       
  2492 				{
       
  2493 				ERR_PRINTF1(_L("Expected Null pointer but object found"));
       
  2494 				SetBlockResult(EFail);
       
  2495 				}
       
  2496 			}
       
  2497 		else
       
  2498 			{
       
  2499 			//Fail if NULL
       
  2500 			if (theExtensionObjectPtr!=NULL)
       
  2501 				{
       
  2502 				}
       
  2503 			else
       
  2504 				{
       
  2505 				ERR_PRINTF1(_L("Expected object but found NULL"));
       
  2506 				SetBlockResult(EFail);
       
  2507 				}
       
  2508 			}
       
  2509 		}
       
  2510 	else
       
  2511 		{
       
  2512 		ERR_PRINTF1(_L("GetIntFromConfig failed"));
       
  2513 		SetBlockResult(EFail);
       
  2514 		}
       
  2515 	}
       
  2516 
       
  2517 inline void CT_CBluetoothSocketData::DoCmdSetRsocketServerFromCBTSocket(const TDesC& aSection)
       
  2518 	{
       
  2519 
       
  2520 	// Get the blank session socket
       
  2521 	TPtrC	myCT_CBluetoothSocketDataName;
       
  2522 	CT_CBluetoothSocketData* myCT_CBluetoothSocketData=NULL;
       
  2523 	if( GetStringFromConfig(aSection, KCBluetoothSocket(), myCT_CBluetoothSocketDataName))
       
  2524 		{
       
  2525 		myCT_CBluetoothSocketData=static_cast<CT_CBluetoothSocketData*>(GetDataWrapperL(myCT_CBluetoothSocketDataName));
       
  2526 		if ( myCT_CBluetoothSocketData!=NULL )
       
  2527 			{
       
  2528 			iData->iSocketServer=myCT_CBluetoothSocketData->GetRServer();
       
  2529 			}
       
  2530 		else
       
  2531 			{
       
  2532 			ERR_PRINTF1(_L("CBluetoothSocket is NULL"));
       
  2533 			SetBlockResult(EFail);
       
  2534 			}
       
  2535 		}
       
  2536 	else
       
  2537 		{
       
  2538 		ERR_PRINTF1(_L("GetStringFromConfig failed"));
       
  2539 		SetBlockResult(EFail);
       
  2540 		}
       
  2541 	}
       
  2542 
       
  2543 inline void CT_CBluetoothSocketData::DoCmdSetTransferAble()
       
  2544 	{
       
  2545 	iData->iBluetoothSocket->SetOpt(KSOEnableTransfer, KSOLSocket, KProcPolicy().Package());
       
  2546 	}
       
  2547 
       
  2548 RSocketServ& CT_CBluetoothSocketData::GetRServer()
       
  2549 	{
       
  2550 	return iData->iSocketServer;
       
  2551 	}
       
  2552 
       
  2553 //	MBluetoothSocketNotifier implementation
       
  2554 void CT_CBluetoothSocketData::HandleConnectCompleteL(TInt aErr)
       
  2555 	{
       
  2556 	INFO_PRINTF2(_L("HandleConnectCompleteL : Status (%d)" ), aErr);
       
  2557 
       
  2558 	if (aErr != KErrNone)
       
  2559 		{
       
  2560 		ERR_PRINTF2(_L("HandleConnectCompleteL called with error code: %d"),aErr);
       
  2561 		SetAsyncError(iConnectIndex, aErr);
       
  2562 		}
       
  2563 	else
       
  2564 		{
       
  2565 		INFO_PRINTF1(_L("HandleConnectCompleteL successful" ));
       
  2566 		}
       
  2567 
       
  2568 	TBuf<DATASIZE>	dataToRead(_L(""));
       
  2569 	dataToRead.Copy(iDataToRead8);
       
  2570 	INFO_PRINTF2(_L("Retrived: [%S]"), &dataToRead);
       
  2571 
       
  2572 	if ( iHasConnectDataToExpect )
       
  2573 		{
       
  2574 		TBuf<DATASIZE>	dataExpected;
       
  2575 		dataExpected.Copy(iConnectDataToExpect);
       
  2576 
       
  2577 		// If dataExpected is shorter add filler chars as we did in send
       
  2578 		// We just need to use a TBuf so that we can change it
       
  2579 		if ( dataExpected.Length()<dataToRead.Length() )
       
  2580 			{
       
  2581 			for ( ;dataExpected.Length()<DATASIZE;)
       
  2582 				{
       
  2583 				dataExpected.Append(_L("#"));
       
  2584 				}
       
  2585 			}
       
  2586 
       
  2587 		//Verify the data
       
  2588 		INFO_PRINTF2(_L("Expected: [%S]"), &dataExpected);
       
  2589 		if ( dataExpected != dataToRead )
       
  2590 			{
       
  2591 			ERR_PRINTF1(_L("Data is not as expected"));
       
  2592 			SetBlockResult(EFail);
       
  2593 			}
       
  2594 		}
       
  2595 	DecOutstanding();
       
  2596 	}
       
  2597 
       
  2598 void CT_CBluetoothSocketData::HandleAcceptCompleteL(TInt aErr)
       
  2599 	{
       
  2600 	if (aErr != KErrNone)
       
  2601 		{
       
  2602 		ERR_PRINTF2(_L("HandleAcceptCompleteL called with error code: %d"),aErr);
       
  2603 		SetAsyncError(iAcceptIndex, aErr);
       
  2604 		}
       
  2605 	else
       
  2606 		{
       
  2607 		INFO_PRINTF1(_L("HandleAcceptCompleteL successful" ));
       
  2608 		}
       
  2609 
       
  2610 	TBuf<DATASIZE>	dataToRead(_L(""));
       
  2611 	dataToRead.Copy(iDataToRead8);
       
  2612 	INFO_PRINTF2(_L("Retrived: [%S]"),&dataToRead);
       
  2613 
       
  2614 	if ( iHasAcceptDataToExpect )
       
  2615 		{
       
  2616 		TBuf<DATASIZE>	dataExpected;
       
  2617 		dataExpected.Copy(iAcceptDataToExpect);
       
  2618 
       
  2619 		// If dataExpected is shorter add filler chars as we did in send
       
  2620 		// We just need to use a TBuf so that we can change it
       
  2621 		if ( dataExpected.Length()<dataToRead.Length() )
       
  2622 			{
       
  2623 			for ( ;dataExpected.Length()<DATASIZE;)
       
  2624 				{
       
  2625 				dataExpected.Append(_L("#"));
       
  2626 				}
       
  2627 			}
       
  2628 
       
  2629 		//Verify the data
       
  2630 		INFO_PRINTF2(_L("Expected: [%S]"),&dataExpected);
       
  2631 		if (dataExpected != dataToRead)
       
  2632 			{
       
  2633 			ERR_PRINTF1(_L("Data is not as expected"));
       
  2634 			SetBlockResult(EFail);
       
  2635 			}
       
  2636 		}
       
  2637 	DecOutstanding();
       
  2638 	}
       
  2639 
       
  2640 void CT_CBluetoothSocketData::HandleShutdownCompleteL(TInt aErr)
       
  2641 	{
       
  2642 	if (aErr != KErrNone)
       
  2643 		{
       
  2644 		ERR_PRINTF2(_L("HandleShutdownCompleteL called with error code: %d"),aErr);
       
  2645 		SetAsyncError(iShutdownIndex, aErr);
       
  2646 		}
       
  2647 	else
       
  2648 		{
       
  2649 		INFO_PRINTF1(_L("HandleShutdownCompleteL successful" ));
       
  2650 		}
       
  2651 	DecOutstanding();
       
  2652 	}
       
  2653 
       
  2654 void CT_CBluetoothSocketData::HandleSendCompleteL(TInt aErr)
       
  2655 	{
       
  2656 	if (aErr != KErrNone)
       
  2657 		{
       
  2658 		ERR_PRINTF2(_L("HandleSendCompleteL called with error code: %d"),aErr);
       
  2659 		SetAsyncError(iSendIndex, aErr);
       
  2660 		}
       
  2661 	else
       
  2662 		{
       
  2663 		INFO_PRINTF1(_L("HandleSendCompleteL successful" ));
       
  2664 		}
       
  2665 	DecOutstanding();
       
  2666 	}
       
  2667 
       
  2668 void CT_CBluetoothSocketData::HandleReceiveCompleteL(TInt aErr)
       
  2669 	{
       
  2670 	if (aErr != KErrNone)
       
  2671 		{
       
  2672 		ERR_PRINTF2(_L("HandleReceiveCompleteL called with error code: %d"),aErr);
       
  2673 		SetAsyncError(iReceiveIndex, aErr);
       
  2674 		}
       
  2675 	else
       
  2676 		{
       
  2677 		INFO_PRINTF1(_L("HandleReceiveCompleteL successful" ));
       
  2678 		}
       
  2679 
       
  2680 	TBuf<DATASIZE>	dataToRead(_L(""));
       
  2681 	dataToRead.Copy(iDataToRead8);
       
  2682 	INFO_PRINTF2(_L("Retrived: [%S]"), &dataToRead);
       
  2683 
       
  2684 	if ( iHasReceiveDataToExpect )
       
  2685 		{
       
  2686 		TBuf<DATASIZE>	dataExpected;
       
  2687 		dataExpected.Copy(iReceiveDataToExpect);
       
  2688 
       
  2689 		// If dataExpected is shorter add filler chars as we did in send
       
  2690 		// We just need to use a TBuf so that we can change it
       
  2691 		if ( dataExpected.Length()<dataToRead.Length() )
       
  2692 			{
       
  2693 			for ( ;dataExpected.Length()<DATASIZE;)
       
  2694 				{
       
  2695 				dataExpected.Append(_L("#"));
       
  2696 				}
       
  2697 			}
       
  2698 
       
  2699 		//	Verify the data
       
  2700 		if (dataExpected != dataToRead)
       
  2701 			{
       
  2702 			ERR_PRINTF1(_L("Data is not as expected"));
       
  2703 			SetBlockResult(EFail);
       
  2704 			}
       
  2705 		INFO_PRINTF2(_L("Expected: [%S]"), &dataExpected);
       
  2706 		}
       
  2707 	DecOutstanding();
       
  2708 	}
       
  2709 
       
  2710 void CT_CBluetoothSocketData::HandleIoctlCompleteL(TInt aErr)
       
  2711 	{
       
  2712 	if (aErr != KErrNone)
       
  2713 		{
       
  2714 		ERR_PRINTF2(_L("HandleIoctlCompleteL called with error code: %d"),aErr);
       
  2715 		SetAsyncError(iIoctlIndex, aErr);
       
  2716 		}
       
  2717 	else
       
  2718 		{
       
  2719 		INFO_PRINTF1(_L("HandleIoctlCompleteL successful" ));
       
  2720 		
       
  2721 		TBuf8<DATASIZE>	tempBuffer(_L8(""));
       
  2722 		tempBuffer.Copy(iMTUOptionBuffer);
       
  2723 		INFO_PRINTF2(_L("HandleIoctlCompleteL = %S" ), &tempBuffer);
       
  2724 		}
       
  2725 	DecOutstanding();
       
  2726 	}
       
  2727 
       
  2728 void CT_CBluetoothSocketData::HandleActivateBasebandEventNotifierCompleteL(TInt aErr, TBTBasebandEventNotification & aEventNotification)
       
  2729 	{
       
  2730 	if (aErr != KErrNone)
       
  2731 		{
       
  2732 		ERR_PRINTF2(_L("HandleActivateBasebandEventNotifierCompleteL called with error code: %d"),aErr);
       
  2733 		SetAsyncError(iNotifierIndex, aErr);
       
  2734 		}
       
  2735 	else
       
  2736 		{
       
  2737 		INFO_PRINTF1(_L("HandleActivateBasebandEventNotifierCompleteL successful" ));
       
  2738 		INFO_PRINTF4(_L("Even type: %d Error code: %d Symbian Error Code: %d"), aEventNotification.EventType(), aEventNotification.ErrorCode(), aEventNotification.SymbianErrorCode());
       
  2739 
       
  2740 
       
  2741 		}
       
  2742 	DecOutstanding();
       
  2743 	}