kerneltest/e32test/device/t_usbco2.cpp
branchRCL_3
changeset 257 3e88ff8f41d5
parent 256 c1f20ce4abcf
equal deleted inserted replaced
256:c1f20ce4abcf 257:3e88ff8f41d5
     1 // Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    21 #include <e32uid.h>
    21 #include <e32uid.h>
    22 #include <hal.h>
    22 #include <hal.h>
    23 
    23 
    24 #include "t_usb.h"											// CActiveConsole, CActiveRW
    24 #include "t_usb.h"											// CActiveConsole, CActiveRW
    25 #include "t_usblib.h"										// Helpers
    25 #include "t_usblib.h"										// Helpers
    26 #include "OstTraceDefinitions.h"
       
    27 #ifdef OST_TRACE_COMPILER_IN_USE
       
    28 #include "t_usbco2Traces.h"
       
    29 #endif
       
    30 
    26 
    31 
    27 
    32 _LIT(KUsbLddFilename, "eusbc");								// .ldd assumed - it's a filename
    28 _LIT(KUsbLddFilename, "eusbc");								// .ldd assumed - it's a filename
    33 _LIT(KOtgdiLddFilename, "otgdi");
    29 _LIT(KOtgdiLddFilename, "otgdi");
    34 _LIT(KUsbDeviceName, "Usbc");
    30 _LIT(KUsbDeviceName, "Usbc");
    93 	//  was already loaded at boot time.)
    89 	//  was already loaded at boot time.)
    94 	TInt r = User::LoadLogicalDevice(KUsbLddFilename);
    90 	TInt r = User::LoadLogicalDevice(KUsbLddFilename);
    95 	if (r != KErrNone && r != KErrAlreadyExists)
    91 	if (r != KErrNone && r != KErrAlreadyExists)
    96 		{
    92 		{
    97 		TUSB_PRINT1("Error %d on loading USB LDD", r);
    93 		TUSB_PRINT1("Error %d on loading USB LDD", r);
    98 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_CONSTRUCTL, "Error %d on loading USB LDD", r);
       
    99 		User::Leave(-1);
    94 		User::Leave(-1);
   100 		return;
    95 		return;
   101 		}
    96 		}
   102 	TUSB_PRINT("Successfully loaded USB LDD");
    97 	TUSB_PRINT("Successfully loaded USB LDD");
   103 	OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_CONSTRUCTL_DUP01, "Successfully loaded USB LDD");
       
   104 
    98 
   105 	// Open USB channel
    99 	// Open USB channel
   106 	r = iPort.Open(0);
   100 	r = iPort.Open(0);
   107 	if (r != KErrNone)
   101 	if (r != KErrNone)
   108 		{
   102 		{
   109 		TUSB_PRINT1("Error %d on opening USB port", r);
   103 		TUSB_PRINT1("Error %d on opening USB port", r);
   110 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_CONSTRUCTL_DUP02, "Error %d on opening USB port", r);
       
   111 		User::Leave(-1);
   104 		User::Leave(-1);
   112 		return;
   105 		return;
   113 		}
   106 		}
   114 	TUSB_PRINT("Successfully opened USB port");
   107 	TUSB_PRINT("Successfully opened USB port");
   115 	OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_CONSTRUCTL_DUP03, "Successfully opened USB port");
       
   116 
   108 
   117 	// Create Reader/Writer active object
   109 	// Create Reader/Writer active object
   118 	iRW = CActiveRW::NewL(iConsole, &iPort, iVerbose);
   110 	iRW = CActiveRW::NewL(iConsole, &iPort, iVerbose);
   119 	if (!iRW)
   111 	if (!iRW)
   120 		{
   112 		{
   121 		TUSB_PRINT("Failed to create reader/writer");
   113 		TUSB_PRINT("Failed to create reader/writer");
   122 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_CONSTRUCTL_DUP04, "Failed to create reader/writer");
       
   123 		User::Leave(-1);
   114 		User::Leave(-1);
   124 		return;
   115 		return;
   125 		}
   116 		}
   126 	TUSB_PRINT("Created reader/writer");
   117 	TUSB_PRINT("Created reader/writer");
   127 	OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_CONSTRUCTL_DUP05, "Created reader/writer");
       
   128 	
   118 	
   129 	// check for endpoint resource allocation v2 support
   119 	// check for endpoint resource allocation v2 support
   130 	TUsbDeviceCaps d_caps;
   120 	TUsbDeviceCaps d_caps;
   131 	r = iPort.DeviceCaps(d_caps);
   121 	r = iPort.DeviceCaps(d_caps);
   132 	if (r != KErrNone)
   122 	if (r != KErrNone)
   133 		{
   123 		{
   134 		TUSB_PRINT1("Error %d on querying device capabilities", r);
   124 		TUSB_PRINT1("Error %d on querying device capabilities", r);
   135 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_CONSTRUCTL_DUP06, "Error %d on querying device capabilities", r);
       
   136 		User::Leave(-1);
   125 		User::Leave(-1);
   137 		return;
   126 		return;
   138 		}
   127 		}
   139 	iResourceAllocationV2 = ((d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) != 0);
   128 	iResourceAllocationV2 = ((d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) != 0);
   140 		
   129 		
   142 	TBuf8<KUsbDescSize_Otg> otg_desc;
   131 	TBuf8<KUsbDescSize_Otg> otg_desc;
   143 	r = iPort.GetOtgDescriptor(otg_desc);
   132 	r = iPort.GetOtgDescriptor(otg_desc);
   144 	if (!(r == KErrNotSupported || r == KErrNone))
   133 	if (!(r == KErrNotSupported || r == KErrNone))
   145 		{
   134 		{
   146 		TUSB_PRINT1("Error %d while fetching OTG descriptor", r);
   135 		TUSB_PRINT1("Error %d while fetching OTG descriptor", r);
   147 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_CONSTRUCTL_DUP07, "Error %d while fetching OTG descriptor", r);
       
   148 		User::Leave(-1);
   136 		User::Leave(-1);
   149 		return;
   137 		return;
   150 		}
   138 		}
   151 	iOtg = (r != KErrNotSupported) ? ETrue : EFalse;
   139 	iOtg = (r != KErrNotSupported) ? ETrue : EFalse;
   152 
   140 
   153 	// On an OTG device we have to start the OTG driver, otherwise the Client
   141 	// On an OTG device we have to start the OTG driver, otherwise the Client
   154 	// stack will remain disabled forever.
   142 	// stack will remain disabled forever.
   155 	if (iOtg)
   143 	if (iOtg)
   156 		{
   144 		{
   157 		TUSB_PRINT("Running on OTG device: loading OTG driver");
   145 		TUSB_PRINT("Running on OTG device: loading OTG driver");
   158 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_CONSTRUCTL_DUP08, "Running on OTG device: loading OTG driver");
       
   159 		r = User::LoadLogicalDevice(KOtgdiLddFilename);
   146 		r = User::LoadLogicalDevice(KOtgdiLddFilename);
   160 		if (r != KErrNone)
   147 		if (r != KErrNone)
   161 			{
   148 			{
   162 			TUSB_PRINT1("Error %d on loading OTG LDD", r);
   149 			TUSB_PRINT1("Error %d on loading OTG LDD", r);
   163 			OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_CONSTRUCTL_DUP09, "Error %d on loading OTG LDD", r);
       
   164 			User::Leave(-1);
   150 			User::Leave(-1);
   165 			return;
   151 			return;
   166 			}
   152 			}
   167 		r = iOtgPort.Open();
   153 		r = iOtgPort.Open();
   168 		if (r != KErrNone)
   154 		if (r != KErrNone)
   169 			{
   155 			{
   170 			TUSB_PRINT1("Error %d on opening OTG port", r);
   156 			TUSB_PRINT1("Error %d on opening OTG port", r);
   171 			OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_CONSTRUCTL_DUP10, "Error %d on opening OTG port", r);
       
   172 			User::Leave(-1);
   157 			User::Leave(-1);
   173 			return;
   158 			return;
   174 			}
   159 			}
   175 		r = iOtgPort.StartStacks();
   160 		r = iOtgPort.StartStacks();
   176 		if (r != KErrNone)
   161 		if (r != KErrNone)
   177 			{
   162 			{
   178 			TUSB_PRINT1("Error %d on starting USB stack", r);
   163 			TUSB_PRINT1("Error %d on starting USB stack", r);
   179 			OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_CONSTRUCTL_DUP11, "Error %d on starting USB stack", r);
       
   180 			User::Leave(-1);
   164 			User::Leave(-1);
   181 			return;
   165 			return;
   182 			}
   166 			}
   183 		}
   167 		}
   184 	}
   168 	}
   189 	// Query the USB device/Setup the USB interface
   173 	// Query the USB device/Setup the USB interface
   190 	TInt r = QueryUsbClientL();
   174 	TInt r = QueryUsbClientL();
   191 	if (r != KErrNone)
   175 	if (r != KErrNone)
   192 		{
   176 		{
   193 		TUSB_PRINT1("Interface setup failed", r);
   177 		TUSB_PRINT1("Interface setup failed", r);
   194 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_SETUPINTERFACE, "Interface setup failed:%d", r);
       
   195 		return r;
   178 		return r;
   196 		}
   179 		}
   197 	TUSB_PRINT("Interface successfully set up");
   180 	TUSB_PRINT("Interface successfully set up");
   198 	OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_SETUPINTERFACE_DUP01, "Interface successfully set up");
       
   199 
   181 
   200 	// Change some descriptors to contain suitable values
   182 	// Change some descriptors to contain suitable values
   201 	r = SetupDescriptors();
   183 	r = SetupDescriptors();
   202 	if (r != KErrNone)
   184 	if (r != KErrNone)
   203 		{
   185 		{
   204 		TUSB_PRINT1("Descriptor setup failed", r);
   186 		TUSB_PRINT1("Descriptor setup failed", r);
   205 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_SETUPINTERFACE_DUP02, "Descriptor setup failed:%d ", r);
       
   206 		return r;
   187 		return r;
   207 		}
   188 		}
   208 
   189 
   209 	// Create device state active object
   190 	// Create device state active object
   210 	iDeviceStateNotifier = CActiveDeviceStateNotifier::NewL(iConsole, &iPort, iVerbose);
   191 	iDeviceStateNotifier = CActiveDeviceStateNotifier::NewL(iConsole, &iPort, iVerbose);
   211 	if (!iDeviceStateNotifier)
   192 	if (!iDeviceStateNotifier)
   212 		{
   193 		{
   213 		TUSB_PRINT("Failed to create device state notifier");
   194 		TUSB_PRINT("Failed to create device state notifier");
   214 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_SETUPINTERFACE_DUP03, "Failed to create device state notifier");
       
   215 		return r;
   195 		return r;
   216 		}
   196 		}
   217 	iDeviceStateNotifier->Activate();
   197 	iDeviceStateNotifier->Activate();
   218 
   198 
   219 	// Create endpoint stall status active object
   199 	// Create endpoint stall status active object
   220 	iStallNotifier = CActiveStallNotifier::NewL(iConsole, &iPort, iVerbose);
   200 	iStallNotifier = CActiveStallNotifier::NewL(iConsole, &iPort, iVerbose);
   221 	if (!iStallNotifier)
   201 	if (!iStallNotifier)
   222 		{
   202 		{
   223 		TUSB_PRINT("Failed to create stall notifier");
   203 		TUSB_PRINT("Failed to create stall notifier");
   224 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_SETUPINTERFACE_DUP04, "Failed to create stall notifier");
       
   225 		return r;
   204 		return r;
   226 		}
   205 		}
   227 	iStallNotifier->Activate();
   206 	iStallNotifier->Activate();
   228 
   207 
   229 	return r;
   208 	return r;
   231 
   210 
   232 
   211 
   233 CActiveConsole::~CActiveConsole()
   212 CActiveConsole::~CActiveConsole()
   234 	{
   213 	{
   235 	TUSB_VERBOSE_PRINT("CActiveConsole::~CActiveConsole()");
   214 	TUSB_VERBOSE_PRINT("CActiveConsole::~CActiveConsole()");
   236 	if(iVerbose)
       
   237 	    {
       
   238 	    OstTrace0(TRACE_VERBOSE, CACTIVECONSOLE_DCACTIVECONSOLE, "CActiveConsole::~CActiveConsole()");
       
   239 	    }
       
   240 	Cancel();												// base class cancel -> calls our DoCancel
   215 	Cancel();												// base class cancel -> calls our DoCancel
   241 	delete iRW;												// destroy the reader/writer
   216 	delete iRW;												// destroy the reader/writer
   242 	delete iDeviceStateNotifier;
   217 	delete iDeviceStateNotifier;
   243 	delete iStallNotifier;
   218 	delete iStallNotifier;
   244 	TInt r = iPort.RemoveStringDescriptor(stridx1);
   219 	TInt r = iPort.RemoveStringDescriptor(stridx1);
   245 	if (r != KErrNone)
   220 	if (r != KErrNone)
   246 		{
   221 		{
   247 		TUSB_PRINT1("Error %d on string removal", r);
   222 		TUSB_PRINT1("Error %d on string removal", r);
   248 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_DCACTIVECONSOLE_DUP01, "Error %d on string removal", r);
       
   249 		}
   223 		}
   250 	r = iPort.RemoveStringDescriptor(stridx2);
   224 	r = iPort.RemoveStringDescriptor(stridx2);
   251 	if (r != KErrNone)
   225 	if (r != KErrNone)
   252 		{
   226 		{
   253 		TUSB_PRINT1("Error %d on string removal", r);
   227 		TUSB_PRINT1("Error %d on string removal", r);
   254 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_DCACTIVECONSOLE_DUP02, "Error %d on string removal", r);
       
   255 		}
   228 		}
   256 	if (iOtg)
   229 	if (iOtg)
   257 		{
   230 		{
   258 		TUSB_PRINT("Running on OTG device: unloading OTG driver");
   231 		TUSB_PRINT("Running on OTG device: unloading OTG driver");
   259 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_DCACTIVECONSOLE_DUP03, "Running on OTG device: unloading OTG driver");
       
   260 		iOtgPort.StopStacks();
   232 		iOtgPort.StopStacks();
   261 		iOtgPort.Close();
   233 		iOtgPort.Close();
   262 		r = User::FreeLogicalDevice(RUsbOtgDriver::Name());
   234 		r = User::FreeLogicalDevice(RUsbOtgDriver::Name());
   263 		if (r != KErrNone)
   235 		if (r != KErrNone)
   264 			{
   236 			{
   265 			TUSB_PRINT1("Error %d on freeing OTG LDD", r);
   237 			TUSB_PRINT1("Error %d on freeing OTG LDD", r);
   266 			OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_DCACTIVECONSOLE_DUP04, "Error %d on freeing OTG LDD", r);
       
   267 			}
   238 			}
   268 		}
   239 		}
   269 	iPort.Close();											// close USB channel
   240 	iPort.Close();											// close USB channel
   270 	r = User::FreeLogicalDevice(KUsbDeviceName);
   241 	r = User::FreeLogicalDevice(KUsbDeviceName);
   271 	if (r != KErrNone)
   242 	if (r != KErrNone)
   272 		{
   243 		{
   273 		TUSB_PRINT1("Error %d during unloading USB LDD", r);
   244 		TUSB_PRINT1("Error %d during unloading USB LDD", r);
   274 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_DCACTIVECONSOLE_DUP05, "Error %d during unloading USB LDD", r);
       
   275 		User::Leave(-1);
   245 		User::Leave(-1);
   276 		return;
   246 		return;
   277 		}
   247 		}
   278 	TUSB_PRINT("Successfully unloaded USB LDD");	
   248 	TUSB_PRINT("Successfully unloaded USB LDD");	
   279 	OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_DCACTIVECONSOLE_DUP06, "Successfully unloaded USB LDD");	
       
   280 	}
   249 	}
   281 
   250 
   282 
   251 
   283 void CActiveConsole::DoCancel()
   252 void CActiveConsole::DoCancel()
   284 	{
   253 	{
   285 	TUSB_VERBOSE_PRINT("CActiveConsole::DoCancel()");
   254 	TUSB_VERBOSE_PRINT("CActiveConsole::DoCancel()");
   286 	if(iVerbose)
       
   287 	    {
       
   288 	    OstTrace0(TRACE_VERBOSE, CACTIVECONSOLE_DOCANCEL, "CActiveConsole::DoCancel()");
       
   289 	    }
       
   290 	iConsole->ReadCancel();
   255 	iConsole->ReadCancel();
   291 	}
   256 	}
   292 
   257 
   293 
   258 
   294 void CActiveConsole::RunL()
   259 void CActiveConsole::RunL()
   295 	{
   260 	{
   296 	TUSB_VERBOSE_PRINT("CActiveConsole::RunL()");
   261 	TUSB_VERBOSE_PRINT("CActiveConsole::RunL()");
   297 	if(iVerbose)
       
   298 	    {
       
   299 	    OstTrace0(TRACE_VERBOSE, CACTIVECONSOLE_RUNL, "CActiveConsole::RunL()");
       
   300 	    }
       
   301 	ProcessKeyPressL(static_cast<TChar>(iConsole->KeyCode()));
   262 	ProcessKeyPressL(static_cast<TChar>(iConsole->KeyCode()));
   302 	}
   263 	}
   303 
   264 
   304 
   265 
   305 void CActiveConsole::RequestCharacter()
   266 void CActiveConsole::RequestCharacter()
   307 	// A request is issued to the CConsoleBase to accept a character from the keyboard.
   268 	// A request is issued to the CConsoleBase to accept a character from the keyboard.
   308 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666));
   269 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666));
   309 	if (!iBufferSizeChosen)
   270 	if (!iBufferSizeChosen)
   310 		{
   271 		{
   311 		iConsole->Printf(_L("\n"));
   272 		iConsole->Printf(_L("\n"));
   312 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER, "\n");
       
   313 		iConsole->Printf(_L("++++ Choose max. Transfer Size ++++\n"));
   273 		iConsole->Printf(_L("++++ Choose max. Transfer Size ++++\n"));
   314 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP01, "++++ Choose max. Transfer Size ++++\n");
       
   315 		iConsole->Printf(_L("  '0' - Set up USB device for USBCV\n"));
   274 		iConsole->Printf(_L("  '0' - Set up USB device for USBCV\n"));
   316 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP02, "  '0' - Set up USB device for USBCV\n");
       
   317 		iConsole->Printf(_L("  '1' -   32 bytes\n"));
   275 		iConsole->Printf(_L("  '1' -   32 bytes\n"));
   318 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP03, "  '1' -   32 bytes\n");
       
   319 		iConsole->Printf(_L("  '2' - 1024 bytes\n"));
   276 		iConsole->Printf(_L("  '2' - 1024 bytes\n"));
   320 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP04, "  '2' - 1024 bytes\n");
       
   321 		iConsole->Printf(_L("  '3' -   64 kbytes\n"));
   277 		iConsole->Printf(_L("  '3' -   64 kbytes\n"));
   322 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP05, "  '3' -   64 kbytes\n");
       
   323 		iConsole->Printf(_L("  '4' -    1 Mbyte\n"));
   278 		iConsole->Printf(_L("  '4' -    1 Mbyte\n"));
   324 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP06, "  '4' -    1 Mbyte\n");
       
   325 		}
   279 		}
   326 	else if (!iBandwidthPriorityChosen)
   280 	else if (!iBandwidthPriorityChosen)
   327 		{
   281 		{
   328 		iConsole->Printf(_L("\n"));
   282 		iConsole->Printf(_L("\n"));
   329 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP07, "\n");
       
   330 		iConsole->Printf(_L("++++ Choose Bandwidth Priority ++++\n"));
   283 		iConsole->Printf(_L("++++ Choose Bandwidth Priority ++++\n"));
   331 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP08, "++++ Choose Bandwidth Priority ++++\n");
       
   332 		iConsole->Printf(_L("  '1' - Economical buffering - default\n"));
   284 		iConsole->Printf(_L("  '1' - Economical buffering - default\n"));
   333 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP09, "  '1' - Economical buffering - default\n");
       
   334 		iConsole->Printf(_L("  '2' - More memory than default buffering - Plus1\n"));
   285 		iConsole->Printf(_L("  '2' - More memory than default buffering - Plus1\n"));
   335 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP10, "  '2' - More memory than default buffering - Plus1\n");
       
   336 		iConsole->Printf(_L("  '3' - More memory than Plus1 buffering - Plus2\n"));
   286 		iConsole->Printf(_L("  '3' - More memory than Plus1 buffering - Plus2\n"));
   337 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP11, "  '3' - More memory than Plus1 buffering - Plus2\n");
       
   338 		iConsole->Printf(_L("  '4' - Maximum buffering\n"));
   287 		iConsole->Printf(_L("  '4' - Maximum buffering\n"));
   339 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP12, "  '4' - Maximum buffering\n");
       
   340 		}
   288 		}
   341 	else if (!iDMAChosen)
   289 	else if (!iDMAChosen)
   342 		{
   290 		{
   343 		iConsole->Printf(_L("\n"));
   291 		iConsole->Printf(_L("\n"));
   344 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP13, "\n");
       
   345 		iConsole->Printf(_L("++++ Choose Endpoint I/O Transfer Mode ++++\n"));
   292 		iConsole->Printf(_L("++++ Choose Endpoint I/O Transfer Mode ++++\n"));
   346 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP14, "++++ Choose Endpoint I/O Transfer Mode ++++\n");
       
   347 		iConsole->Printf(_L("  '1' - Interrupt Mode\n"));
   293 		iConsole->Printf(_L("  '1' - Interrupt Mode\n"));
   348 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP15, "  '1' - Interrupt Mode\n");
       
   349 		iConsole->Printf(_L("  '2' - DMA Mode (recommended)\n"));
   294 		iConsole->Printf(_L("  '2' - DMA Mode (recommended)\n"));
   350 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP16, "  '2' - DMA Mode (recommended\n");
       
   351 		}
   295 		}
   352 	else if (!iDoubleBufferingChosen)
   296 	else if (!iDoubleBufferingChosen)
   353 		{
   297 		{
   354 		iConsole->Printf(_L("\n"));
   298 		iConsole->Printf(_L("\n"));
   355 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP17, "\n");
       
   356 		iConsole->Printf(_L("++++ Choose Endpoint FIFO Mode ++++\n"));
   299 		iConsole->Printf(_L("++++ Choose Endpoint FIFO Mode ++++\n"));
   357 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP18, "++++ Choose Endpoint FIFO Mode ++++\n");
       
   358 		iConsole->Printf(_L("  '1' - Normal Buffering Mode\n"));
   300 		iConsole->Printf(_L("  '1' - Normal Buffering Mode\n"));
   359 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP19, "  '1' - Normal Buffering Mode\n");
       
   360 		iConsole->Printf(_L("  '2' - Double Buffering Mode (recommended)\n"));
   301 		iConsole->Printf(_L("  '2' - Double Buffering Mode (recommended)\n"));
   361 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP20, "  '2' - Double Buffering Mode (recommended\n");
       
   362 		}
   302 		}
   363 	else
   303 	else
   364 		{
   304 		{
   365 		iConsole->Printf(_L("\n"));
   305 		iConsole->Printf(_L("\n"));
   366 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP21, "\n");
       
   367 		iConsole->Printf(_L("++++ Select Program Option ++++\n"));
   306 		iConsole->Printf(_L("++++ Select Program Option ++++\n"));
   368 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP22, "++++ Select Program Option ++++\n");
       
   369 		iConsole->Printf(_L("  'L'oop test\n"));
   307 		iConsole->Printf(_L("  'L'oop test\n"));
   370 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP23, "  'L'oop test\n");
       
   371 		iConsole->Printf(_L("   Loop test with data 'C'ompare\n"));
   308 		iConsole->Printf(_L("   Loop test with data 'C'ompare\n"));
   372 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP24, "   Loop test with data 'C'ompare\n");
       
   373 		iConsole->Printf(_L("  'R'eceive-only test (we receive, host transmits)\n"));
   309 		iConsole->Printf(_L("  'R'eceive-only test (we receive, host transmits)\n"));
   374 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP25, "  'R'eceive-only test (we receive, host transmits\n");
       
   375 		iConsole->Printf(_L("  'T'ransmit-only test\n"));
   310 		iConsole->Printf(_L("  'T'ransmit-only test\n"));
   376 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP26, "  'T'ransmit-only test\n");
       
   377 		iConsole->Printf(_L("   Receive and 'P'ut (write) to File\n"));
   311 		iConsole->Printf(_L("   Receive and 'P'ut (write) to File\n"));
   378 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP27, "   Receive and 'P'ut (writeto File\n");
       
   379 		iConsole->Printf(_L("   Transmit and 'G'et (read) from File\n"));
   312 		iConsole->Printf(_L("   Transmit and 'G'et (read) from File\n"));
   380 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP28, "   Transmit and 'G'et (readfrom File\n");
       
   381 		iConsole->Printf(_L("   Signal Remote-'W'akeup to the host\n"));
   313 		iConsole->Printf(_L("   Signal Remote-'W'akeup to the host\n"));
   382 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP29, "   Signal Remote-'W'akeup to the host\n");
       
   383 		iConsole->Printf(_L("  'S'top current transfer\n"));
   314 		iConsole->Printf(_L("  'S'top current transfer\n"));
   384 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP30, "  'S'top current transfer\n");
       
   385 #ifdef WITH_DUMP_OPTION
   315 #ifdef WITH_DUMP_OPTION
   386 		iConsole->Printf(_L("  'D'ump USB regs to debugout\n"));
   316 		iConsole->Printf(_L("  'D'ump USB regs to debugout\n"));
   387 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP31, "  'D'ump USB regs to debugout\n");
       
   388 #endif
   317 #endif
   389 		iConsole->Printf(_L("   Re'E'numerate device\n"));
   318 		iConsole->Printf(_L("   Re'E'numerate device\n"));
   390 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP32, "   Re'E'numerate device\n");
       
   391 		iConsole->Printf(_L("  'Q'uit this app\n"));
   319 		iConsole->Printf(_L("  'Q'uit this app\n"));
   392 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REQUESTCHARACTER_DUP33, "  'Q'uit this app\n");
       
   393 		}
   320 		}
   394 	iConsole->Read(iStatus);
   321 	iConsole->Read(iStatus);
   395 	SetActive();
   322 	SetActive();
   396 	}
   323 	}
   397 
   324 
   398 
   325 
   399 void CActiveConsole::ProcessKeyPressL(TChar aChar)
   326 void CActiveConsole::ProcessKeyPressL(TChar aChar)
   400 	{
   327 	{
   401 	if (aChar == EKeyEscape)
   328 	if (aChar == EKeyEscape)
   402 		{
   329 		{
   403 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL, "CActiveConsole: ESC key pressed -> stopping active scheduler...");
   330 		RDebug::Print(_L("CActiveConsole: ESC key pressed -> stopping active scheduler..."));
   404 		CActiveScheduler::Stop();
   331 		CActiveScheduler::Stop();
   405 		return;
   332 		return;
   406 		}
   333 		}
   407 	if (!iBufferSizeChosen)
   334 	if (!iBufferSizeChosen)
   408 		{
   335 		{
   426 		case '4':
   353 		case '4':
   427 			iRW->SetMaxBufSize(KMaxBufSize);
   354 			iRW->SetMaxBufSize(KMaxBufSize);
   428 			break;
   355 			break;
   429 		default:
   356 		default:
   430 			TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint());
   357 			TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint());
   431 			OstTraceExt1(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP01, "Not a valid input character: %c", aChar.operator TUint());
       
   432 			goto request_char;
   358 			goto request_char;
   433 			}
   359 			}
   434 		TUSB_PRINT1("Maximum buffer size set to %d bytes", iRW->MaxBufSize());
   360 		TUSB_PRINT1("Maximum buffer size set to %d bytes", iRW->MaxBufSize());
   435 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP02, "Maximum buffer size set to %d bytes", iRW->MaxBufSize());
       
   436 		iBufferSizeChosen = ETrue;
   361 		iBufferSizeChosen = ETrue;
   437 		}
   362 		}
   438 	else if (!iBandwidthPriorityChosen)
   363 	else if (!iBandwidthPriorityChosen)
   439 		{
   364 		{
   440 		// Set bandwidth priority from keypress
   365 		// Set bandwidth priority from keypress
   441 		switch (aChar)
   366 		switch (aChar)
   442 			{
   367 			{
   443 		case '1':
   368 		case '1':
   444 			iBandwidthPriority = EUsbcBandwidthOUTDefault | EUsbcBandwidthINDefault;
   369 			iBandwidthPriority = EUsbcBandwidthOUTDefault | EUsbcBandwidthINDefault;
   445 			TUSB_PRINT("Bandwith priority set to default");
   370 			TUSB_PRINT("Bandwith priority set to default");
   446 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP03, "Bandwith priority set to default");
       
   447 			break;
   371 			break;
   448 		case '2':
   372 		case '2':
   449 			iBandwidthPriority = EUsbcBandwidthOUTPlus1 | EUsbcBandwidthINPlus1;
   373 			iBandwidthPriority = EUsbcBandwidthOUTPlus1 | EUsbcBandwidthINPlus1;
   450 			TUSB_PRINT("Bandwith priority set to Plus1");
   374 			TUSB_PRINT("Bandwith priority set to Plus1");
   451 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP04, "Bandwith priority set to Plus1");
       
   452 			break;
   375 			break;
   453 		case '3':
   376 		case '3':
   454 			iBandwidthPriority = EUsbcBandwidthOUTPlus2 | EUsbcBandwidthINPlus2;
   377 			iBandwidthPriority = EUsbcBandwidthOUTPlus2 | EUsbcBandwidthINPlus2;
   455 			TUSB_PRINT("Bandwith priority set to Plus2");
   378 			TUSB_PRINT("Bandwith priority set to Plus2");
   456 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP05, "Bandwith priority set to Plus2");
       
   457 			break;
   379 			break;
   458 		case '4':
   380 		case '4':
   459 			iBandwidthPriority = EUsbcBandwidthINMaximum | EUsbcBandwidthOUTMaximum;
   381 			iBandwidthPriority = EUsbcBandwidthINMaximum | EUsbcBandwidthOUTMaximum;
   460 			TUSB_PRINT("Bandwith priority set to maximum");
   382 			TUSB_PRINT("Bandwith priority set to maximum");
   461 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP06, "Bandwith priority set to maximum");
       
   462 			break;
   383 			break;
   463 		default:
   384 		default:
   464 			TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint());
   385 			TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint());
   465 			OstTraceExt1(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP07, "Not a valid input character: %c", aChar.operator TUint());
       
   466 			goto request_char;
   386 			goto request_char;
   467 			}
   387 			}
   468 		TUSB_PRINT1("(Set to 0x%08X)", iBandwidthPriority);
   388 		TUSB_PRINT1("(Set to 0x%08X)", iBandwidthPriority);
   469 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP08, "(Set to 0x%08X)", iBandwidthPriority);
       
   470 		iBandwidthPriorityChosen = ETrue;
   389 		iBandwidthPriorityChosen = ETrue;
   471 		
   390 		
   472 		if (!iResourceAllocationV2)
   391 		if (!iResourceAllocationV2)
   473 			{
   392 			{
   474 			TUSB_PRINT("Configuring interface...");
   393 			TUSB_PRINT("Configuring interface...");
   475 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP09, "Configuring interface...");
       
   476 			TInt r = SetupInterface();
   394 			TInt r = SetupInterface();
   477 			if (r != KErrNone)
   395 			if (r != KErrNone)
   478 				{
   396 				{
   479 				TUSB_PRINT1("Error: %d. Stopping active scheduler...", r);
   397 				TUSB_PRINT1("Error: %d. Stopping active scheduler...", r);
   480 				OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP10, "Error: %d. Stopping active scheduler...", r);
       
   481 				CActiveScheduler::Stop();
   398 				CActiveScheduler::Stop();
   482 				return;
   399 				return;
   483 				}
   400 				}
   484 			}
   401 			}
   485 		}
   402 		}
   489 		switch (aChar)
   406 		switch (aChar)
   490 			{
   407 			{
   491 		case '1':
   408 		case '1':
   492 			{
   409 			{
   493 			TUSB_PRINT("- Trying to deallocate endpoint DMA:\n");
   410 			TUSB_PRINT("- Trying to deallocate endpoint DMA:\n");
   494 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP11, "- Trying to deallocate endpoint DMA:\n");
       
   495 			if (!iResourceAllocationV2)
   411 			if (!iResourceAllocationV2)
   496 				{
   412 				{
   497 				DeAllocateEndpointDMA(EEndpoint1);
   413 				DeAllocateEndpointDMA(EEndpoint1);
   498 				DeAllocateEndpointDMA(EEndpoint2);
   414 				DeAllocateEndpointDMA(EEndpoint2);
   499 				}
   415 				}
   501 			break;
   417 			break;
   502 			}
   418 			}
   503 		case '2':
   419 		case '2':
   504 			{
   420 			{
   505 			TUSB_PRINT("- Trying to allocate endpoint DMA:\n");
   421 			TUSB_PRINT("- Trying to allocate endpoint DMA:\n");
   506 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP12, "- Trying to allocate endpoint DMA:\n");
       
   507 			if (!iResourceAllocationV2)
   422 			if (!iResourceAllocationV2)
   508 				{
   423 				{
   509 				AllocateEndpointDMA(EEndpoint1);
   424 				AllocateEndpointDMA(EEndpoint1);
   510 				AllocateEndpointDMA(EEndpoint2);
   425 				AllocateEndpointDMA(EEndpoint2);
   511 				}
   426 				}
   512 			iAllocateDma = ETrue;
   427 			iAllocateDma = ETrue;
   513 			break;
   428 			break;
   514 			}
   429 			}
   515 		default:
   430 		default:
   516 			TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint());
   431 			TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint());
   517 			OstTraceExt1(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP13, "Not a valid input character: %c", aChar.operator TUint());
       
   518 			goto request_char;
   432 			goto request_char;
   519 			}
   433 			}
   520 		iDMAChosen = ETrue;
   434 		iDMAChosen = ETrue;
   521 		}
   435 		}
   522 	else if (!iDoubleBufferingChosen)
   436 	else if (!iDoubleBufferingChosen)
   525 		switch (aChar)
   439 		switch (aChar)
   526 			{
   440 			{
   527 		case '1':
   441 		case '1':
   528 			{
   442 			{
   529 			TUSB_PRINT("- Trying to deallocate Double Buffering:\n");
   443 			TUSB_PRINT("- Trying to deallocate Double Buffering:\n");
   530 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP14, "- Trying to deallocate Double Buffering:\n");
       
   531 			if (!iResourceAllocationV2)
   444 			if (!iResourceAllocationV2)
   532 				{
   445 				{
   533 				DeAllocateDoubleBuffering(EEndpoint1);
   446 				DeAllocateDoubleBuffering(EEndpoint1);
   534 				DeAllocateDoubleBuffering(EEndpoint2);
   447 				DeAllocateDoubleBuffering(EEndpoint2);
   535 				}
   448 				}
   537 			break;
   450 			break;
   538 			}
   451 			}
   539 		case '2':
   452 		case '2':
   540 			{
   453 			{
   541 			TUSB_PRINT("- Trying to allocate Double Buffering:\n");
   454 			TUSB_PRINT("- Trying to allocate Double Buffering:\n");
   542 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP15, "- Trying to allocate Double Buffering:\n");
       
   543 			if (!iResourceAllocationV2)
   455 			if (!iResourceAllocationV2)
   544 				{
   456 				{
   545 				AllocateDoubleBuffering(EEndpoint1);
   457 				AllocateDoubleBuffering(EEndpoint1);
   546 				AllocateDoubleBuffering(EEndpoint2);
   458 				AllocateDoubleBuffering(EEndpoint2);
   547 				}
   459 				}
   548 			iAllocateDoubleBuffering = ETrue;
   460 			iAllocateDoubleBuffering = ETrue;
   549 			break;
   461 			break;
   550 			}
   462 			}
   551 		default:
   463 		default:
   552 			TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint());
   464 			TUSB_PRINT1("Not a valid input character: %c", aChar.operator TUint());
   553 			OstTraceExt1(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP16, "Not a valid input character: %c", aChar.operator TUint());
       
   554 			goto request_char;
   465 			goto request_char;
   555 			}
   466 			}
   556 		iDoubleBufferingChosen = ETrue;
   467 		iDoubleBufferingChosen = ETrue;
   557 		
   468 		
   558 		if (iResourceAllocationV2)
   469 		if (iResourceAllocationV2)
   559 		{
   470 		{
   560 		TUSB_PRINT("Configuring interface...");
   471 		TUSB_PRINT("Configuring interface...");
   561 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP17, "Configuring interface...");
       
   562 		TInt r = SetupInterface();
   472 		TInt r = SetupInterface();
   563 		if (r != KErrNone)
   473 		if (r != KErrNone)
   564 			{
   474 			{
   565 			TUSB_PRINT1("Error: %d. Stopping active scheduler...", r);
   475 			TUSB_PRINT1("Error: %d. Stopping active scheduler...", r);
   566 			OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP18, "Error: %d. Stopping active scheduler...", r);
       
   567 			CActiveScheduler::Stop();
   476 			CActiveScheduler::Stop();
   568 			return;
   477 			return;
   569 			}
   478 			}
   570 		}
   479 		}
   571 
   480 
   572 		// Everything chosen, so let's re-enumerate...
   481 		// Everything chosen, so let's re-enumerate...
   573 		TUSB_PRINT("Enumeration...");
   482 		TUSB_PRINT("Enumeration...");
   574 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP19, "Enumeration...");
       
   575 		TInt r = ReEnumerate();
   483 		TInt r = ReEnumerate();
   576 		if (r != KErrNone)
   484 		if (r != KErrNone)
   577 			{
   485 			{
   578 			TUSB_PRINT1("Error: %d. Stopping active scheduler...", r);
   486 			TUSB_PRINT1("Error: %d. Stopping active scheduler...", r);
   579 			OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP20, "Error: %d. Stopping active scheduler...", r);
       
   580 			CActiveScheduler::Stop();
   487 			CActiveScheduler::Stop();
   581 			return;
   488 			return;
   582 			}
   489 			}
   583 		TUSB_PRINT("Device successfully re-enumerated\n");
   490 		TUSB_PRINT("Device successfully re-enumerated\n");
   584 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP21, "Device successfully re-enumerated\n");
       
   585 
   491 
   586 		// Make sure program versions match if testing against USBRFLCT
   492 		// Make sure program versions match if testing against USBRFLCT
   587 		if (iRW->MaxBufSize() != 0)
   493 		if (iRW->MaxBufSize() != 0)
   588 			{
   494 			{
   589 			r = iRW->ExchangeVersions();
   495 			r = iRW->ExchangeVersions();
   590 			if (r != KErrNone)
   496 			if (r != KErrNone)
   591 				{
   497 				{
   592 				TUSB_PRINT1("Error: %d. Stopping active scheduler...", r);
   498 				TUSB_PRINT1("Error: %d. Stopping active scheduler...", r);
   593 				OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP22, "Error: %d. Stopping active scheduler...", r);
       
   594 				CActiveScheduler::Stop();
   499 				CActiveScheduler::Stop();
   595 				return;
   500 				return;
   596 				}
   501 				}
   597 			}
   502 			}
   598 		}
   503 		}
   602 		switch (aChar)
   507 		switch (aChar)
   603 			{
   508 			{
   604 		case 'l':					// start loop test
   509 		case 'l':					// start loop test
   605 		case 'L':
   510 		case 'L':
   606 			TUSB_PRINT("-> Loop test selected\n");
   511 			TUSB_PRINT("-> Loop test selected\n");
   607 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP23, "-> Loop test selected\n");
       
   608 			iRW->SetTransferMode(ELoop);
   512 			iRW->SetTransferMode(ELoop);
   609 			iRW->SendPreamble();
   513 			iRW->SendPreamble();
   610 			break;
   514 			break;
   611 		case 'c':					// start loop/compare test
   515 		case 'c':					// start loop/compare test
   612 		case 'C':
   516 		case 'C':
   613 			TUSB_PRINT("-> Loop test with compare selected\n");
   517 			TUSB_PRINT("-> Loop test with compare selected\n");
   614 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP24, "-> Loop test with compare selected\n");
       
   615 			iRW->SetTransferMode(ELoopComp);
   518 			iRW->SetTransferMode(ELoopComp);
   616 			iRW->SendPreamble();
   519 			iRW->SendPreamble();
   617 			break;
   520 			break;
   618 		case 'r':					// start receive-only test
   521 		case 'r':					// start receive-only test
   619 		case 'R':
   522 		case 'R':
   620 			TUSB_PRINT("-> Receive-only test selected\n");
   523 			TUSB_PRINT("-> Receive-only test selected\n");
   621 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP25, "-> Receive-only test selected\n");
       
   622 			iRW->SetTransferMode(EReceiveOnly);
   524 			iRW->SetTransferMode(EReceiveOnly);
   623 			iRW->SendPreamble();
   525 			iRW->SendPreamble();
   624 			break;
   526 			break;
   625 		case 't':					// start transmit-only test
   527 		case 't':					// start transmit-only test
   626 		case 'T':
   528 		case 'T':
   627 			TUSB_PRINT("-> Transmit-only test selected\n");
   529 			TUSB_PRINT("-> Transmit-only test selected\n");
   628 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP26, "-> Transmit-only test selected\n");
       
   629 			iRW->SetTransferMode(ETransmitOnly);
   530 			iRW->SetTransferMode(ETransmitOnly);
   630 			iRW->SendPreamble();
   531 			iRW->SendPreamble();
   631 			break;
   532 			break;
   632 		case 'g':					// start transmit & get-from-file test
   533 		case 'g':					// start transmit & get-from-file test
   633 		case 'G':
   534 		case 'G':
   634 			TUSB_PRINT("-> Transmit from file test selected\n");
   535 			TUSB_PRINT("-> Transmit from file test selected\n");
   635 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP27, "-> Transmit from file test selected\n");
       
   636 			iRW->SetTransferMode(ETransmitOnly);
   536 			iRW->SetTransferMode(ETransmitOnly);
   637 			iRW->ReadFromDisk(ETrue);
   537 			iRW->ReadFromDisk(ETrue);
   638 			iRW->SendPreamble();
   538 			iRW->SendPreamble();
   639 			break;
   539 			break;
   640 		case 'p':					// start receive & put-to-file test
   540 		case 'p':					// start receive & put-to-file test
   641 		case 'P':
   541 		case 'P':
   642 			TUSB_PRINT("-> Receive to file test selected\n");
   542 			TUSB_PRINT("-> Receive to file test selected\n");
   643 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP28, "-> Receive to file test selected\n");
       
   644 			iRW->SetTransferMode(EReceiveOnly);
   543 			iRW->SetTransferMode(EReceiveOnly);
   645 			iRW->WriteToDisk(ETrue);
   544 			iRW->WriteToDisk(ETrue);
   646 			iRW->SendPreamble();
   545 			iRW->SendPreamble();
   647 			break;
   546 			break;
   648 		case 'w':					// remote-wakeup
   547 		case 'w':					// remote-wakeup
   649 		case 'W':
   548 		case 'W':
   650 			TUSB_PRINT("-> Signal Remote-wakeup selected\n");
   549 			TUSB_PRINT("-> Signal Remote-wakeup selected\n");
   651 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP29, "-> Signal Remote-wakeup selected\n");
       
   652 			iPort.SignalRemoteWakeup();
   550 			iPort.SignalRemoteWakeup();
   653 			break;
   551 			break;
   654 		case 's':					// stop either
   552 		case 's':					// stop either
   655 		case 'S':
   553 		case 'S':
   656 			TUSB_PRINT("-> Stop transfer selected\n");
   554 			TUSB_PRINT("-> Stop transfer selected\n");
   657 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP30, "-> Stop transfer selected\n");
       
   658 			iRW->Stop();
   555 			iRW->Stop();
   659 			break;
   556 			break;
   660 #ifdef WITH_DUMP_OPTION
   557 #ifdef WITH_DUMP_OPTION
   661 		case 'd':					// dump controller registers
   558 		case 'd':					// dump controller registers
   662 		case 'D':
   559 		case 'D':
   663 			TUSB_PRINT("-> Dump option selected\n");
   560 			TUSB_PRINT("-> Dump option selected\n");
   664 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP31, "-> Dump option selected\n");
       
   665 			iPort.DumpRegisters();
   561 			iPort.DumpRegisters();
   666 			QueryRxBuffer();
   562 			QueryRxBuffer();
   667 			break;
   563 			break;
   668 #endif
   564 #endif
   669 		case 'e':					// ReEnumerate()
   565 		case 'e':					// ReEnumerate()
   670 		case 'E':
   566 		case 'E':
   671 			TUSB_PRINT("-> Re-enumerate device selected\n");
   567 			TUSB_PRINT("-> Re-enumerate device selected\n");
   672 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP32, "-> Re-enumerate device selected\n");
       
   673 			ReEnumerate();
   568 			ReEnumerate();
   674 			break;
   569 			break;
   675 		case 'q':					// quit
   570 		case 'q':					// quit
   676 		case 'Q':
   571 		case 'Q':
   677 			TUSB_PRINT("-> Quit program selected\n");
   572 			TUSB_PRINT("-> Quit program selected\n");
   678 			OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP33, "-> Quit program selected\n");
       
   679 			TUSB_VERBOSE_PRINT("CActiveConsole: stopping active scheduler...");
   573 			TUSB_VERBOSE_PRINT("CActiveConsole: stopping active scheduler...");
   680 			if(iVerbose)
       
   681 			    {
       
   682 			    OstTrace0(TRACE_VERBOSE, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP34, "CActiveConsole: stopping active scheduler...");
       
   683 			    }
       
   684 			CActiveScheduler::Stop();
   574 			CActiveScheduler::Stop();
   685 			return;
   575 			return;
   686 		default:
   576 		default:
   687 			TUSB_PRINT1("-> Not a valid input character: %c", aChar.operator TUint());
   577 			TUSB_PRINT1("-> Not a valid input character: %c", aChar.operator TUint());
   688 			OstTraceExt1(TRACE_NORMAL, CACTIVECONSOLE_PROCESSKEYPRESSL_DUP35, "-> Not a valid input character: %c", aChar.operator TUint());
       
   689 			goto request_char;
   578 			goto request_char;
   690 			}
   579 			}
   691 		}
   580 		}
   692  request_char:
   581  request_char:
   693 	RequestCharacter();
   582 	RequestCharacter();
   701 	// Let's look whether there's data in the rx buffer
   590 	// Let's look whether there's data in the rx buffer
   702 	TInt bytes = 0;
   591 	TInt bytes = 0;
   703 	TInt r = iPort.QueryReceiveBuffer(EEndpoint2, bytes);
   592 	TInt r = iPort.QueryReceiveBuffer(EEndpoint2, bytes);
   704 	if (r != KErrNone)
   593 	if (r != KErrNone)
   705 		{
   594 		{
   706 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_QUERYRXBUFFER, " Error %d on querying read buffer\n", r);
   595 		RDebug::Print(_L(" Error %d on querying read buffer\n"), r);
   707 		}
   596 		}
   708 	else
   597 	else
   709 		{
   598 		{
   710 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_QUERYRXBUFFER_DUP01, " %d bytes in RX buffer\n", bytes);
   599 		RDebug::Print(_L(" %d bytes in RX buffer\n"), bytes);
   711 		}
   600 		}
   712 	}
   601 	}
   713 #endif
   602 #endif
   714 
   603 
   715 
   604 
   746 	TUsbDeviceCaps d_caps;
   635 	TUsbDeviceCaps d_caps;
   747 	TInt r = iPort.DeviceCaps(d_caps);
   636 	TInt r = iPort.DeviceCaps(d_caps);
   748 	if (r != KErrNone)
   637 	if (r != KErrNone)
   749 		{
   638 		{
   750 		TUSB_PRINT1("Error %d on querying device capabilities", r);
   639 		TUSB_PRINT1("Error %d on querying device capabilities", r);
   751 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL, "Error %d on querying device capabilities", r);
       
   752 		return KErrGeneral;
   640 		return KErrGeneral;
   753 		}
   641 		}
   754 	const TInt n = d_caps().iTotalEndpoints;
   642 	const TInt n = d_caps().iTotalEndpoints;
   755 
   643 
   756 	TUSB_PRINT("###  USB device capabilities:");
   644 	TUSB_PRINT("###  USB device capabilities:");
   757 	OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP01, "###  USB device capabilities:");
       
   758 	TUSB_PRINT1("Number of endpoints:                        %d", n);
   645 	TUSB_PRINT1("Number of endpoints:                        %d", n);
   759 	OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP02, "Number of endpoints:                        %d", n);
       
   760 	TUSB_PRINT1("Supports Software-Connect:                  %s",
   646 	TUSB_PRINT1("Supports Software-Connect:                  %s",
   761 				d_caps().iConnect ? _S("yes") : _S("no"));
   647 				d_caps().iConnect ? _S("yes") : _S("no"));
   762 	OstTraceExt1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP03, "Supports Software-Connect:                  %s",
       
   763 				d_caps().iConnect ? _L("yes") : _L("no"));
       
   764 	TUSB_PRINT1("Device is Self-Powered:                     %s",
   648 	TUSB_PRINT1("Device is Self-Powered:                     %s",
   765 				d_caps().iSelfPowered ? _S("yes") : _S("no"));
   649 				d_caps().iSelfPowered ? _S("yes") : _S("no"));
   766 	OstTraceExt1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP04, "Device is Self-Powered:                     %s",
       
   767 				d_caps().iSelfPowered ? _L("yes") : _L("no"));
       
   768 	TUSB_PRINT1("Supports Remote-Wakeup:                     %s",
   650 	TUSB_PRINT1("Supports Remote-Wakeup:                     %s",
   769 				d_caps().iRemoteWakeup ? _S("yes") : _S("no"));
   651 				d_caps().iRemoteWakeup ? _S("yes") : _S("no"));
   770 	OstTraceExt1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP05, "Supports Remote-Wakeup:                     %s",
       
   771 				d_caps().iRemoteWakeup ? _L("yes") : _L("no"));
       
   772 	TUSB_PRINT1("Supports High-speed:                        %s",
   652 	TUSB_PRINT1("Supports High-speed:                        %s",
   773 				d_caps().iHighSpeed ? _S("yes") : _S("no"));
   653 				d_caps().iHighSpeed ? _S("yes") : _S("no"));
   774 	OstTraceExt1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP06, "Supports High-speed:                        %s",
       
   775 				d_caps().iHighSpeed ? _L("yes") : _L("no"));
       
   776 	TUSB_PRINT1("Supports OTG:                               %s",
   654 	TUSB_PRINT1("Supports OTG:                               %s",
   777 				iOtg ? _S("yes") : _S("no"));
   655 				iOtg ? _S("yes") : _S("no"));
   778 	OstTraceExt1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP07, "Supports OTG:                               %s",
       
   779 				iOtg ? _L("yes") : _L("no"));
       
   780 	TUSB_PRINT1("Supports unpowered cable detection:         %s",
   656 	TUSB_PRINT1("Supports unpowered cable detection:         %s",
   781 				(d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower) ?
   657 				(d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower) ?
   782 				_S("yes") : _S("no"));
   658 				_S("yes") : _S("no"));
   783 	OstTraceExt1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP08, "Supports unpowered cable detection:         %s",
       
   784 				(d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower) ?
       
   785 				_L("yes") : _L("no"));
       
   786 	TUSB_PRINT1("Supports endpoint resource alloc scheme V2: %s\n",
   659 	TUSB_PRINT1("Supports endpoint resource alloc scheme V2: %s\n",
   787 				(d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) ?
   660 				(d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) ?
   788 				_S("yes") : _S("no"));
   661 				_S("yes") : _S("no"));
   789 	OstTraceExt1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP09, "Supports endpoint resource alloc scheme V2: %s\n",
       
   790 				(d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) ?
       
   791 				_L("yes") : _L("no"));
       
   792 	TUSB_PRINT("");
   662 	TUSB_PRINT("");
   793 	OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP10, "");
       
   794 
   663 
   795 	iSoftwareConnect = d_caps().iConnect;					// we need to remember this
   664 	iSoftwareConnect = d_caps().iConnect;					// we need to remember this
   796 
   665 
   797 	if (n < 2)
   666 	if (n < 2)
   798 		{
   667 		{
   799 		TUSB_PRINT1("Error: only %d endpoints available on device", n);
   668 		TUSB_PRINT1("Error: only %d endpoints available on device", n);
   800 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP11, "Error: only %d endpoints available on device", n);
       
   801 		return KErrGeneral;
   669 		return KErrGeneral;
   802 		}
   670 		}
   803 
   671 
   804 	// Endpoints
   672 	// Endpoints
   805 	TUsbcEndpointData data[KUsbcMaxEndpoints];
   673 	TUsbcEndpointData data[KUsbcMaxEndpoints];
   806 	TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
   674 	TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data));
   807 	r = iPort.EndpointCaps(dataptr);
   675 	r = iPort.EndpointCaps(dataptr);
   808 	if (r != KErrNone)
   676 	if (r != KErrNone)
   809 		{
   677 		{
   810 		TUSB_PRINT1("Error %d on querying endpoint capabilities", r);
   678 		TUSB_PRINT1("Error %d on querying endpoint capabilities", r);
   811 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP12, "Error %d on querying endpoint capabilities", r);
       
   812 		return KErrGeneral;
   679 		return KErrGeneral;
   813 		}
   680 		}
   814 	TUSB_PRINT("### USB device endpoint capabilities:");
   681 	TUSB_PRINT("### USB device endpoint capabilities:");
   815 	OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP13, "### USB device endpoint capabilities:");
       
   816 	for (TInt i = 0; i < n; i++)
   682 	for (TInt i = 0; i < n; i++)
   817 		{
   683 		{
   818 		const TUsbcEndpointCaps* caps = &data[i].iCaps;
   684 		const TUsbcEndpointCaps* caps = &data[i].iCaps;
   819 		TUSB_PRINT2("Endpoint: SizeMask = 0x%08x TypeDirMask = 0x%08x",
   685 		TUSB_PRINT2("Endpoint: SizeMask = 0x%08x TypeDirMask = 0x%08x",
   820 					caps->iSizes, caps->iTypesAndDir);
   686 					caps->iSizes, caps->iTypesAndDir);
   821 		OstTraceExt2(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP14, "Endpoint: SizeMask = 0x%08x TypeDirMask = 0x%08x",
       
   822 					caps->iSizes, caps->iTypesAndDir);
       
   823 		}
   687 		}
   824 	TUSB_PRINT("");
   688 	TUSB_PRINT("");
   825 	OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP15, "");
       
   826 
   689 
   827 	// Set up the active interface
   690 	// Set up the active interface
   828 	TUsbcInterfaceInfoBuf ifc;
   691 	TUsbcInterfaceInfoBuf ifc;
   829 	TInt ep_found = 0;
   692 	TInt ep_found = 0;
   830 	TBool foundBulkIN = EFalse;
   693 	TBool foundBulkIN = EFalse;
   838 			(KUsbEpTypeBulk | KUsbEpDirIn))
   701 			(KUsbEpTypeBulk | KUsbEpDirIn))
   839 			{
   702 			{
   840 			if (!(mps == 64 || mps == 512))
   703 			if (!(mps == 64 || mps == 512))
   841 				{
   704 				{
   842 				TUSB_PRINT1("Funny Bulk IN MaxPacketSize: %d - T_USB will probably fail...", mps);
   705 				TUSB_PRINT1("Funny Bulk IN MaxPacketSize: %d - T_USB will probably fail...", mps);
   843 				OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP16, "Funny Bulk IN MaxPacketSize: %d - T_USB will probably fail...", mps);
       
   844 				}
   706 				}
   845 			// EEndpoint1 is going to be our Tx (IN) endpoint
   707 			// EEndpoint1 is going to be our Tx (IN) endpoint
   846 			ifc().iEndpointData[0].iType = KUsbEpTypeBulk;
   708 			ifc().iEndpointData[0].iType = KUsbEpTypeBulk;
   847 			ifc().iEndpointData[0].iDir	 = KUsbEpDirIn;
   709 			ifc().iEndpointData[0].iDir	 = KUsbEpDirIn;
   848 			ifc().iEndpointData[0].iSize = mps;
   710 			ifc().iEndpointData[0].iSize = mps;
   855 			(KUsbEpTypeBulk | KUsbEpDirOut))
   717 			(KUsbEpTypeBulk | KUsbEpDirOut))
   856 			{
   718 			{
   857 			if (!(mps == 64 || mps == 512))
   719 			if (!(mps == 64 || mps == 512))
   858 				{
   720 				{
   859 				TUSB_PRINT1("Funny Bulk OUT MaxPacketSize: %d - T_USB will probably fail...", mps);
   721 				TUSB_PRINT1("Funny Bulk OUT MaxPacketSize: %d - T_USB will probably fail...", mps);
   860 				OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP17, "Funny Bulk OUT MaxPacketSize: %d - T_USB will probably fail...", mps);
       
   861 				}
   722 				}
   862 			// EEndpoint2 is going to be our Rx (OUT) endpoint
   723 			// EEndpoint2 is going to be our Rx (OUT) endpoint
   863 			ifc().iEndpointData[1].iType = KUsbEpTypeBulk;
   724 			ifc().iEndpointData[1].iType = KUsbEpTypeBulk;
   864 			ifc().iEndpointData[1].iDir	 = KUsbEpDirOut;
   725 			ifc().iEndpointData[1].iDir	 = KUsbEpDirOut;
   865 			ifc().iEndpointData[1].iSize = mps;
   726 			ifc().iEndpointData[1].iSize = mps;
   869 			}
   730 			}
   870 		}
   731 		}
   871 	if (ep_found != 2)
   732 	if (ep_found != 2)
   872 		{
   733 		{
   873 		TUSB_PRINT1("No suitable endpoints found", r);
   734 		TUSB_PRINT1("No suitable endpoints found", r);
   874 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP18, "No suitable endpoints found:%d", r);
       
   875 		return KErrGeneral;
   735 		return KErrGeneral;
   876 		}
   736 		}
   877 
   737 
   878 	if (iResourceAllocationV2)
   738 	if (iResourceAllocationV2)
   879 		{
   739 		{
   897 	ifc().iClass.iProtocolNum = 0xff;						// vendor-specific
   757 	ifc().iClass.iProtocolNum = 0xff;						// vendor-specific
   898 	r = iPort.SetInterface(0, ifc, iBandwidthPriority);
   758 	r = iPort.SetInterface(0, ifc, iBandwidthPriority);
   899 	if (r != KErrNone)
   759 	if (r != KErrNone)
   900 		{
   760 		{
   901 		TUSB_PRINT1("Error %d on setting active interface", r);
   761 		TUSB_PRINT1("Error %d on setting active interface", r);
   902 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP19, "Error %d on setting active interface", r);
       
   903 		}
   762 		}
   904 
   763 
   905 	// Find ep's for an alternate ifc setting.
   764 	// Find ep's for an alternate ifc setting.
   906 	// We're not really going to use it, but it gives USBCV et al. more stuff to play with.
   765 	// We're not really going to use it, but it gives USBCV et al. more stuff to play with.
   907 	if (!SupportsAlternateInterfaces())
   766 	if (!SupportsAlternateInterfaces())
   908 		{
   767 		{
   909 		TUSB_PRINT("Alternate Interfaces not supported - skipping alternate setting setup\n");
   768 		TUSB_PRINT("Alternate Interfaces not supported - skipping alternate setting setup\n");
   910 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP20, "Alternate Interfaces not supported - skipping alternate setting setup\n");
       
   911 		return KErrNone;
   769 		return KErrNone;
   912 		}
   770 		}
   913 	ep_found = 0;
   771 	ep_found = 0;
   914 	TBool foundIsoIN  = EFalse;
   772 	TBool foundIsoIN  = EFalse;
   915 	TBool foundIsoOUT = EFalse;
   773 	TBool foundIsoOUT = EFalse;
   974 			}
   832 			}
   975 		}
   833 		}
   976 	if (ep_found == 0)
   834 	if (ep_found == 0)
   977 		{
   835 		{
   978 		TUSB_PRINT("Not enough suitable endpoints found for alt ifc");
   836 		TUSB_PRINT("Not enough suitable endpoints found for alt ifc");
   979 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP21, "Not enough suitable endpoints found for alt ifc");
       
   980 		// not a disaster though
   837 		// not a disaster though
   981 		return KErrNone;
   838 		return KErrNone;
   982 		}
   839 		}
   983 
   840 
   984 	_LIT16(ifcname1, "T_USB Test Interface (Alternate Setting 1)");
   841 	_LIT16(ifcname1, "T_USB Test Interface (Alternate Setting 1)");
   991 	ifc().iFeatureWord |= KUsbcInterfaceInfo_NoEp0RequestsPlease;
   848 	ifc().iFeatureWord |= KUsbcInterfaceInfo_NoEp0RequestsPlease;
   992 	r = iPort.SetInterface(1, ifc);
   849 	r = iPort.SetInterface(1, ifc);
   993 	if (r != KErrNone)
   850 	if (r != KErrNone)
   994 		{
   851 		{
   995 		TUSB_PRINT1("Error %d on setting alternate interface", r);
   852 		TUSB_PRINT1("Error %d on setting alternate interface", r);
   996 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_QUERYUSBCLIENTL_DUP22, "Error %d on setting alternate interface", r);
       
   997 		}
   853 		}
   998 
   854 
   999 	return r;
   855 	return r;
  1000 	}
   856 	}
  1001 
   857 
  1002 
   858 
  1003 void CActiveConsole::AllocateEndpointDMA(TEndpointNumber aEndpoint)
   859 void CActiveConsole::AllocateEndpointDMA(TEndpointNumber aEndpoint)
  1004 	{
   860 	{
  1005 	TInt r = iPort.AllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDMA);
   861 	TInt r = iPort.AllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDMA);
  1006 	if (r == KErrNone)
   862 	if (r == KErrNone)
  1007 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_ALLOCATEENDPOINTDMA, "DMA allocation on endpoint %d: KErrNone", aEndpoint);
   863 		RDebug::Print(_L("DMA allocation on endpoint %d: KErrNone"), aEndpoint);
  1008 	else if (r == KErrInUse)
   864 	else if (r == KErrInUse)
  1009 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_ALLOCATEENDPOINTDMA_DUP01, "DMA allocation on endpoint %d: KErrInUse", aEndpoint);
   865 		RDebug::Print(_L("DMA allocation on endpoint %d: KErrInUse"), aEndpoint);
  1010 	else if (r == KErrNotSupported)
   866 	else if (r == KErrNotSupported)
  1011 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_ALLOCATEENDPOINTDMA_DUP02, "DMA allocation on endpoint %d: KErrNotSupported", aEndpoint);
   867 		RDebug::Print(_L("DMA allocation on endpoint %d: KErrNotSupported"), aEndpoint);
  1012 	else
   868 	else
  1013 		OstTraceExt2(TRACE_NORMAL, CACTIVECONSOLE_ALLOCATEENDPOINTDMA_DUP03, "DMA allocation on endpoint %d: unexpected return value %d",
   869 		RDebug::Print(_L("DMA allocation on endpoint %d: unexpected return value %d"),
  1014 					  aEndpoint, r);
   870 					  aEndpoint, r);
  1015 	TBool res = iPort.QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDMA);
   871 	TBool res = iPort.QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDMA);
  1016 	TUSB_PRINT2("DMA on endpoint %d %s\n",
   872 	TUSB_PRINT2("DMA on endpoint %d %s\n",
  1017 				aEndpoint, res ? _S("allocated") : _S("not allocated"));
   873 				aEndpoint, res ? _S("allocated") : _S("not allocated"));
  1018 	OstTraceExt2(TRACE_NORMAL, CACTIVECONSOLE_ALLOCATEENDPOINTDMA_DUP04, "DMA on endpoint %d %s\n",
       
  1019 				aEndpoint, res ? _L("allocated") : _L("not allocated"));
       
  1020 
   874 
  1021 	if ((r == KErrNone) && !res)
   875 	if ((r == KErrNone) && !res)
  1022 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_ALLOCATEENDPOINTDMA_DUP05, "(Allocation success but negative query result: contradiction!)\n");
   876 		RDebug::Print(_L("(Allocation success but negative query result: contradiction!)\n"));
  1023 	else if ((r != KErrNone) && res)
   877 	else if ((r != KErrNone) && res)
  1024 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_ALLOCATEENDPOINTDMA_DUP06, "(Allocation failure but positive query result: contradiction!)\n");
   878 		RDebug::Print(_L("(Allocation failure but positive query result: contradiction!)\n"));
  1025 	}
   879 	}
  1026 
   880 
  1027 
   881 
  1028 void CActiveConsole::DeAllocateEndpointDMA(TEndpointNumber aEndpoint)
   882 void CActiveConsole::DeAllocateEndpointDMA(TEndpointNumber aEndpoint)
  1029 	{
   883 	{
  1030 	TInt r = iPort.DeAllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDMA);
   884 	TInt r = iPort.DeAllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDMA);
  1031 	if (r == KErrNone)
   885 	if (r == KErrNone)
  1032 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_DEALLOCATEENDPOINTDMA, "DMA deallocation on endpoint %d: KErrNone", aEndpoint);
   886 		RDebug::Print(_L("DMA deallocation on endpoint %d: KErrNone"), aEndpoint);
  1033 	else if (r == KErrNotSupported)
   887 	else if (r == KErrNotSupported)
  1034 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_DEALLOCATEENDPOINTDMA_DUP01, "DMA deallocation on endpoint %d: KErrNotSupported", aEndpoint);
   888 		RDebug::Print(_L("DMA deallocation on endpoint %d: KErrNotSupported"), aEndpoint);
  1035 	else
   889 	else
  1036 		OstTraceExt2(TRACE_NORMAL, CACTIVECONSOLE_DEALLOCATEENDPOINTDMA_DUP02, "DMA deallocation on endpoint %d: unexpected return value %d",
   890 		RDebug::Print(_L("DMA deallocation on endpoint %d: unexpected return value %d"),
  1037 					  aEndpoint, r);
   891 					  aEndpoint, r);
  1038 	TBool res = iPort.QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDMA);
   892 	TBool res = iPort.QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDMA);
  1039 	TUSB_PRINT2("DMA on endpoint %d %s\n",
   893 	TUSB_PRINT2("DMA on endpoint %d %s\n",
  1040 				aEndpoint, res ? _S("allocated") : _S("not allocated"));
   894 				aEndpoint, res ? _S("allocated") : _S("not allocated"));
  1041 	OstTraceExt2(TRACE_NORMAL, CACTIVECONSOLE_DEALLOCATEENDPOINTDMA_DUP03, "DMA on endpoint %d %s\n",
       
  1042 				aEndpoint, res ? _L("allocated") : _L("not allocated"));
       
  1043 	}
   895 	}
  1044 
   896 
  1045 
   897 
  1046 void CActiveConsole::AllocateDoubleBuffering(TEndpointNumber aEndpoint)
   898 void CActiveConsole::AllocateDoubleBuffering(TEndpointNumber aEndpoint)
  1047 	{
   899 	{
  1048 	TInt r = iPort.AllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
   900 	TInt r = iPort.AllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
  1049 	if (r == KErrNone)
   901 	if (r == KErrNone)
  1050 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_ALLOCATEDOUBLEBUFFERING, "Double Buffering allocation on endpoint %d: KErrNone", aEndpoint);
   902 		RDebug::Print(_L("Double Buffering allocation on endpoint %d: KErrNone"), aEndpoint);
  1051 	else if (r == KErrInUse)
   903 	else if (r == KErrInUse)
  1052 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_ALLOCATEDOUBLEBUFFERING_DUP01, "Double Buffering allocation on endpoint %d: KErrInUse", aEndpoint);
   904 		RDebug::Print(_L("Double Buffering allocation on endpoint %d: KErrInUse"), aEndpoint);
  1053 	else if (r == KErrNotSupported)
   905 	else if (r == KErrNotSupported)
  1054 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_ALLOCATEDOUBLEBUFFERING_DUP02, "Double Buffering allocation on endpoint %d: KErrNotSupported", aEndpoint);
   906 		RDebug::Print(_L("Double Buffering allocation on endpoint %d: KErrNotSupported"), aEndpoint);
  1055 	else
   907 	else
  1056 		OstTraceExt2(TRACE_NORMAL, CACTIVECONSOLE_ALLOCATEDOUBLEBUFFERING_DUP03, "Double Buffering allocation on endpoint %d: unexpected return value %d",
   908 		RDebug::Print(_L("Double Buffering allocation on endpoint %d: unexpected return value %d"),
  1057 					  aEndpoint, r);
   909 					  aEndpoint, r);
  1058 	TBool res = iPort.QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
   910 	TBool res = iPort.QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
  1059 	TUSB_PRINT2("Double Buffering on endpoint %d %s\n",
   911 	TUSB_PRINT2("Double Buffering on endpoint %d %s\n",
  1060 				aEndpoint, res ? _S("allocated") : _S("not allocated"));
   912 				aEndpoint, res ? _S("allocated") : _S("not allocated"));
  1061 	OstTraceExt2(TRACE_NORMAL, CACTIVECONSOLE_ALLOCATEDOUBLEBUFFERING_DUP04, "Double Buffering on endpoint %d %s\n",
       
  1062 				aEndpoint, res ? _L("allocated") : _L("not allocated"));
       
  1063 
   913 
  1064 	if ((r == KErrNone) && !res)
   914 	if ((r == KErrNone) && !res)
  1065 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_ALLOCATEDOUBLEBUFFERING_DUP05, "(Allocation success but negative query result: contradiction!)\n");
   915 		RDebug::Print(_L("(Allocation success but negative query result: contradiction!)\n"));
  1066 	else if ((r != KErrNone) && res)
   916 	else if ((r != KErrNone) && res)
  1067 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_ALLOCATEDOUBLEBUFFERING_DUP06, "(Allocation failure but positive query result: contradiction!)\n");
   917 		RDebug::Print(_L("(Allocation failure but positive query result: contradiction!)\n"));
  1068 	}
   918 	}
  1069 
   919 
  1070 
   920 
  1071 void CActiveConsole::DeAllocateDoubleBuffering(TEndpointNumber aEndpoint)
   921 void CActiveConsole::DeAllocateDoubleBuffering(TEndpointNumber aEndpoint)
  1072 	{
   922 	{
  1073 	TInt r = iPort.DeAllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
   923 	TInt r = iPort.DeAllocateEndpointResource(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
  1074 	if (r == KErrNone)
   924 	if (r == KErrNone)
  1075 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_DEALLOCATEDOUBLEBUFFERING, "Double Buffering deallocation on endpoint %d: KErrNone", aEndpoint);
   925 		RDebug::Print(_L("Double Buffering deallocation on endpoint %d: KErrNone"), aEndpoint);
  1076 	else if (r == KErrNotSupported)
   926 	else if (r == KErrNotSupported)
  1077 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_DEALLOCATEDOUBLEBUFFERING_DUP01, "Double Buffering deallocation on endpoint %d: KErrNotSupported", aEndpoint);
   927 		RDebug::Print(_L("Double Buffering deallocation on endpoint %d: KErrNotSupported"), aEndpoint);
  1078 	else
   928 	else
  1079 		OstTraceExt2(TRACE_NORMAL, CACTIVECONSOLE_DEALLOCATEDOUBLEBUFFERING_DUP02, "Double Buffering deallocation on endpoint %d: unexpected return value %d",
   929 		RDebug::Print(_L("Double Buffering deallocation on endpoint %d: unexpected return value %d"),
  1080 					  aEndpoint, r);
   930 					  aEndpoint, r);
  1081 	TBool res = iPort.QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
   931 	TBool res = iPort.QueryEndpointResourceUse(aEndpoint, EUsbcEndpointResourceDoubleBuffering);
  1082 	TUSB_PRINT2("Double Buffering on endpoint %d %s\n",
   932 	TUSB_PRINT2("Double Buffering on endpoint %d %s\n",
  1083 				aEndpoint, res ? _S("allocated") : _S("not allocated"));
   933 				aEndpoint, res ? _S("allocated") : _S("not allocated"));
  1084 	OstTraceExt2(TRACE_NORMAL, CACTIVECONSOLE_DEALLOCATEDOUBLEBUFFERING_DUP03, "Double Buffering on endpoint %d %s\n",
       
  1085 				aEndpoint, res ? _L("allocated") : _L("not allocated"));
       
  1086 	}
   934 	}
  1087 
   935 
  1088 
   936 
  1089 TInt CActiveConsole::ReEnumerate()
   937 TInt CActiveConsole::ReEnumerate()
  1090 	{
   938 	{
  1091 	TRequestStatus enum_status;
   939 	TRequestStatus enum_status;
  1092 	iPort.ReEnumerate(enum_status);
   940 	iPort.ReEnumerate(enum_status);
  1093 	if (!iSoftwareConnect)
   941 	if (!iSoftwareConnect)
  1094 		{
   942 		{
  1095 		iConsole->Printf(_L("This device does not support software\n"));
   943 		iConsole->Printf(_L("This device does not support software\n"));
  1096 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REENUMERATE, "This device does not support software\n");
       
  1097 		iConsole->Printf(_L("disconnect/reconnect\n"));
   944 		iConsole->Printf(_L("disconnect/reconnect\n"));
  1098 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REENUMERATE_DUP01, "disconnect/reconnect\n");
       
  1099 		iConsole->Printf(_L("Please physically unplug and replug\n"));
   945 		iConsole->Printf(_L("Please physically unplug and replug\n"));
  1100 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REENUMERATE_DUP02, "Please physically unplug and replug\n");
       
  1101 		iConsole->Printf(_L("the USB cable NOW... "));
   946 		iConsole->Printf(_L("the USB cable NOW... "));
  1102 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REENUMERATE_DUP03, "the USB cable NOW... ");
       
  1103 		}
   947 		}
  1104 	iConsole->Printf(_L("\n>>> START THE USBRFLCT PROGRAM ON THE HOST SIDE NOW <<<\n"));
   948 	iConsole->Printf(_L("\n>>> START THE USBRFLCT PROGRAM ON THE HOST SIDE NOW <<<\n"));
  1105 	OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REENUMERATE_DUP04, "\n>>> START THE USBRFLCT PROGRAM ON THE HOST SIDE NOW <<<\n");
       
  1106 	User::WaitForRequest(enum_status);
   949 	User::WaitForRequest(enum_status);
  1107 	if (enum_status != KErrNone)
   950 	if (enum_status != KErrNone)
  1108 		{
   951 		{
  1109 		TUSB_PRINT1("Error: Re-enumeration status = %d", enum_status.Int());
   952 		TUSB_PRINT1("Error: Re-enumeration status = %d", enum_status.Int());
  1110 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_REENUMERATE_DUP05, "Error: Re-enumeration status = %d", enum_status.Int());
       
  1111 		return KErrGeneral;
   953 		return KErrGeneral;
  1112 		}
   954 		}
  1113 	TUsbcDeviceState device_state =	EUsbcDeviceStateUndefined;
   955 	TUsbcDeviceState device_state =	EUsbcDeviceStateUndefined;
  1114 	TInt r = iPort.DeviceStatus(device_state);
   956 	TInt r = iPort.DeviceStatus(device_state);
  1115 	if (r != KErrNone)
   957 	if (r != KErrNone)
  1116 		{
   958 		{
  1117 		TUSB_PRINT1("Error %d on querying device state", r);
   959 		TUSB_PRINT1("Error %d on querying device state", r);
  1118 		OstTrace1(TRACE_NORMAL, CACTIVECONSOLE_REENUMERATE_DUP06, "Error %d on querying device state", r);
       
  1119 		}
   960 		}
  1120 	else
   961 	else
  1121 		{
   962 		{
  1122 		TUSB_PRINT1("Current device state: %s",
   963 		TUSB_PRINT1("Current device state: %s",
  1123 					(device_state == EUsbcDeviceStateUndefined) ? _S("Undefined") :
   964 					(device_state == EUsbcDeviceStateUndefined) ? _S("Undefined") :
  1126 					  ((device_state == EUsbcDeviceStateDefault) ? _S("Default") :
   967 					  ((device_state == EUsbcDeviceStateDefault) ? _S("Default") :
  1127 					   ((device_state == EUsbcDeviceStateAddress) ? _S("Address") :
   968 					   ((device_state == EUsbcDeviceStateAddress) ? _S("Address") :
  1128 						((device_state == EUsbcDeviceStateConfigured) ? _S("Configured") :
   969 						((device_state == EUsbcDeviceStateConfigured) ? _S("Configured") :
  1129 						 ((device_state == EUsbcDeviceStateSuspended) ? _S("Suspended") :
   970 						 ((device_state == EUsbcDeviceStateSuspended) ? _S("Suspended") :
  1130 						  _S("Unknown"))))))));
   971 						  _S("Unknown"))))))));
  1131 		OstTraceExt1(TRACE_NORMAL, CACTIVECONSOLE_REENUMERATE_DUP07, "Current device state: %s",
       
  1132 					(device_state == EUsbcDeviceStateUndefined) ? _L("Undefined") :
       
  1133 					((device_state == EUsbcDeviceStateAttached) ? _L("Attached") :
       
  1134 					 ((device_state == EUsbcDeviceStatePowered) ? _L("Powered") :
       
  1135 					  ((device_state == EUsbcDeviceStateDefault) ? _L("Default") :
       
  1136 					   ((device_state == EUsbcDeviceStateAddress) ? _L("Address") :
       
  1137 						((device_state == EUsbcDeviceStateConfigured) ? _L("Configured") :
       
  1138 						 ((device_state == EUsbcDeviceStateSuspended) ? _L("Suspended") :
       
  1139 						  _L("Unknown"))))))));
       
  1140 		}
   972 		}
  1141 
   973 
  1142 	// Check the speed of the established physical USB connection
   974 	// Check the speed of the established physical USB connection
  1143 	iHighSpeed = iPort.CurrentlyUsingHighSpeed();
   975 	iHighSpeed = iPort.CurrentlyUsingHighSpeed();
  1144 	if (iHighSpeed)
   976 	if (iHighSpeed)
  1145 		{
   977 		{
  1146 		TUSB_PRINT("---> USB High-speed Testing\n");
   978 		TUSB_PRINT("---> USB High-speed Testing\n");
  1147 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REENUMERATE_DUP08, "---> USB High-speed Testing\n");
       
  1148 		// It can only be 512 bytes when using high-speed.
   979 		// It can only be 512 bytes when using high-speed.
  1149 		iRW->SetMaxPacketSize(512);							// iRW already exists at this point
   980 		iRW->SetMaxPacketSize(512);							// iRW already exists at this point
  1150 		}
   981 		}
  1151 	else
   982 	else
  1152 		{
   983 		{
  1153 		TUSB_PRINT("---> USB Full-speed Testing\n");
   984 		TUSB_PRINT("---> USB Full-speed Testing\n");
  1154 		OstTrace0(TRACE_NORMAL, CACTIVECONSOLE_REENUMERATE_DUP09, "---> USB Full-speed Testing\n");
       
  1155 		// We only support 64 bytes when using full-speed.
   985 		// We only support 64 bytes when using full-speed.
  1156 		iRW->SetMaxPacketSize(64);							// iRW already exists at this point
   986 		iRW->SetMaxPacketSize(64);							// iRW already exists at this point
  1157 		}
   987 		}
  1158 
   988 
  1159 	return KErrNone;
   989 	return KErrNone;
  1212 	TUSB_PRINT6("\nVID = 0x%04X / PID = 0x%04X / DevRel = %d%d.%d%d\n", Vid, Pid,
  1042 	TUSB_PRINT6("\nVID = 0x%04X / PID = 0x%04X / DevRel = %d%d.%d%d\n", Vid, Pid,
  1213 				((deviceDescriptor[KUsbDevReleaseOffset + 1] >> 4) & 0x0f),
  1043 				((deviceDescriptor[KUsbDevReleaseOffset + 1] >> 4) & 0x0f),
  1214 				(deviceDescriptor[KUsbDevReleaseOffset + 1] & 0x0f),
  1044 				(deviceDescriptor[KUsbDevReleaseOffset + 1] & 0x0f),
  1215 				((deviceDescriptor[KUsbDevReleaseOffset] >> 4) & 0x0f),
  1045 				((deviceDescriptor[KUsbDevReleaseOffset] >> 4) & 0x0f),
  1216 				(deviceDescriptor[KUsbDevReleaseOffset] & 0x0f));
  1046 				(deviceDescriptor[KUsbDevReleaseOffset] & 0x0f));
  1217 	OstTraceExt2(TRACE_NORMAL, CACTIVECONSOLE_SETUPDESCRIPTORS, "\nVID = 0x%04X / PID = 0x%04X / ", Vid, Pid);
       
  1218 	OstTraceExt4(TRACE_NORMAL, CACTIVECONSOLE_SETUPDESCRIPTORS_DUP01, "DevRel = %d%d.%d%d\n", 
       
  1219 				((deviceDescriptor[KUsbDevReleaseOffset + 1] >> 4) & 0x0f),
       
  1220 				(deviceDescriptor[KUsbDevReleaseOffset + 1] & 0x0f),
       
  1221 				((deviceDescriptor[KUsbDevReleaseOffset] >> 4) & 0x0f),
       
  1222 				(deviceDescriptor[KUsbDevReleaseOffset] & 0x0f));
       
  1223 
  1047 
  1224 	// === Configuration Descriptor
  1048 	// === Configuration Descriptor
  1225 
  1049 
  1226 	TInt configDescriptorSize = 0;
  1050 	TInt configDescriptorSize = 0;
  1227 	iPort.GetConfigurationDescriptorSize(configDescriptorSize);
  1051 	iPort.GetConfigurationDescriptorSize(configDescriptorSize);
  1275 	  iDoStop(EFalse),
  1099 	  iDoStop(EFalse),
  1276 	  iPktNum(~0),
  1100 	  iPktNum(~0),
  1277 	  iVerbose(aVerboseOutput)
  1101 	  iVerbose(aVerboseOutput)
  1278 	{
  1102 	{
  1279 	TUSB_VERBOSE_PRINT("CActiveRW::CActiveRW()");
  1103 	TUSB_VERBOSE_PRINT("CActiveRW::CActiveRW()");
  1280 	if(iVerbose)
       
  1281 	    {
       
  1282 	    OstTrace0(TRACE_VERBOSE, CACTIVERW_CACTIVERW, "CActiveRW::CActiveRW()");
       
  1283 	    }
       
  1284 	}
  1104 	}
  1285 
  1105 
  1286 
  1106 
  1287 CActiveRW* CActiveRW::NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput)
  1107 CActiveRW* CActiveRW::NewL(CConsoleBase* aConsole, RDevUsbcClient* aPort, TBool aVerboseOutput)
  1288 	{
  1108 	{
  1296 
  1116 
  1297 
  1117 
  1298 void CActiveRW::ConstructL()
  1118 void CActiveRW::ConstructL()
  1299 	{
  1119 	{
  1300 	TUSB_VERBOSE_PRINT("CActiveRW::ConstructL()");
  1120 	TUSB_VERBOSE_PRINT("CActiveRW::ConstructL()");
  1301 	if(iVerbose)
       
  1302 	    {
       
  1303 	    OstTrace0(TRACE_VERBOSE, CACTIVERW_CONSTRUCTL, "CActiveRW::ConstructL()");
       
  1304 	    }
       
  1305 
  1121 
  1306 	User::LeaveIfError(iFs.Connect());
  1122 	User::LeaveIfError(iFs.Connect());
  1307 
  1123 
  1308 	// Prepare Preamble buffer
  1124 	// Prepare Preamble buffer
  1309 	iPreambleBuf.SetMax();
  1125 	iPreambleBuf.SetMax();
  1322 	// Create read timeout timer active object (but don't activate it yet)
  1138 	// Create read timeout timer active object (but don't activate it yet)
  1323 	iTimeoutTimer = CActiveTimer::NewL(iConsole, iPort, iVerbose);
  1139 	iTimeoutTimer = CActiveTimer::NewL(iConsole, iPort, iVerbose);
  1324 	if (!iTimeoutTimer)
  1140 	if (!iTimeoutTimer)
  1325 		{
  1141 		{
  1326 		TUSB_PRINT("Failed to create timeout timer");
  1142 		TUSB_PRINT("Failed to create timeout timer");
  1327 		OstTrace0(TRACE_NORMAL, CACTIVERW_CONSTRUCTL_DUP01, "Failed to create timeout timer");
       
  1328 		}
  1143 		}
  1329 	}
  1144 	}
  1330 
  1145 
  1331 
  1146 
  1332 CActiveRW::~CActiveRW()
  1147 CActiveRW::~CActiveRW()
  1333 	{
  1148 	{
  1334 	TUSB_VERBOSE_PRINT("CActiveRW::~CActiveRW()");
  1149 	TUSB_VERBOSE_PRINT("CActiveRW::~CActiveRW()");
  1335 	if(iVerbose)
       
  1336 	    {
       
  1337 	    OstTrace0(TRACE_VERBOSE, CACTIVERW_DCACTIVERW, "CActiveRW::~CActiveRW()");
       
  1338 	    }
       
  1339 	Cancel();												// base class
  1150 	Cancel();												// base class
  1340 	delete iTimeoutTimer;
  1151 	delete iTimeoutTimer;
  1341 	iFile.Close();
  1152 	iFile.Close();
  1342 	iFs.Close();
  1153 	iFs.Close();
  1343 	}
  1154 	}
  1346 void CActiveRW::SetMaxBufSize(TInt aBufSz)
  1157 void CActiveRW::SetMaxBufSize(TInt aBufSz)
  1347 	{
  1158 	{
  1348 	if (aBufSz > KMaxBufSize)
  1159 	if (aBufSz > KMaxBufSize)
  1349 		{
  1160 		{
  1350 		TUSB_PRINT2("SetMaxBufSize(): too large: %d! (using %d)", aBufSz, KMaxBufSize);
  1161 		TUSB_PRINT2("SetMaxBufSize(): too large: %d! (using %d)", aBufSz, KMaxBufSize);
  1351 		OstTraceExt2(TRACE_NORMAL, CACTIVERW_SETMAXBUFSIZE, "SetMaxBufSize(): too large: %d! (using %d)", aBufSz, KMaxBufSize);
       
  1352 		aBufSz = KMaxBufSize;
  1162 		aBufSz = KMaxBufSize;
  1353 		}
  1163 		}
  1354 	iMaxBufSz = aBufSz;
  1164 	iMaxBufSz = aBufSz;
  1355 	}
  1165 	}
  1356 
  1166 
  1379 
  1189 
  1380 
  1190 
  1381 void CActiveRW::RunL()
  1191 void CActiveRW::RunL()
  1382 	{
  1192 	{
  1383 	TUSB_VERBOSE_PRINT("CActiveRW::RunL()");
  1193 	TUSB_VERBOSE_PRINT("CActiveRW::RunL()");
  1384 	if(iVerbose)
       
  1385 	    {
       
  1386 	    OstTrace0(TRACE_VERBOSE, CACTIVERW_RUNL, "CActiveRW::RunL()");
       
  1387 	    }
       
  1388 	if (iStatus != KErrNone)
  1194 	if (iStatus != KErrNone)
  1389 		{
  1195 		{
  1390 		TUSB_PRINT1("Error %d in RunL", iStatus.Int());
  1196 		TUSB_PRINT1("Error %d in RunL", iStatus.Int());
  1391 		OstTrace1(TRACE_NORMAL, CACTIVERW_RUNL_DUP01, "Error %d in RunL", iStatus.Int());
       
  1392 		}
  1197 		}
  1393 	if (iDoStop)
  1198 	if (iDoStop)
  1394 		{
  1199 		{
  1395 		TUSB_PRINT("Stopped");
  1200 		TUSB_PRINT("Stopped");
  1396 		OstTrace0(TRACE_NORMAL, CACTIVERW_RUNL_DUP02, "Stopped");
       
  1397 		iDoStop = EFalse;
  1201 		iDoStop = EFalse;
  1398 		return;
  1202 		return;
  1399 		}
  1203 		}
  1400 	switch (iCurrentXfer)
  1204 	switch (iCurrentXfer)
  1401 		{
  1205 		{
  1416 			{
  1220 			{
  1417 			const TUint32 num = *reinterpret_cast<const TUint32*>(iReadBuf.Ptr());
  1221 			const TUint32 num = *reinterpret_cast<const TUint32*>(iReadBuf.Ptr());
  1418 			if (num != ++iPktNum)
  1222 			if (num != ++iPktNum)
  1419 				{
  1223 				{
  1420 				TUSB_PRINT2("*** rcv'd wrong pkt number: 0x%x (expected: 0x%x)", num, iPktNum);
  1224 				TUSB_PRINT2("*** rcv'd wrong pkt number: 0x%x (expected: 0x%x)", num, iPktNum);
  1421 				OstTraceExt2(TRACE_NORMAL, CACTIVERW_RUNL_DUP03, "*** rcv'd wrong pkt number: 0x%x (expected: 0x%x)", num, iPktNum);
       
  1422 				// Update the packet number with the received number, so that
  1225 				// Update the packet number with the received number, so that
  1423 				// if a single packet is duplicated or lost then a single error occurs
  1226 				// if a single packet is duplicated or lost then a single error occurs
  1424 				iPktNum = num;
  1227 				iPktNum = num;
  1425 				}
  1228 				}
  1426 			if (iDiskAccessEnabled)
  1229 			if (iDiskAccessEnabled)
  1427 				{
  1230 				{
  1428 				// Write out to disk previous completed Read
  1231 				// Write out to disk previous completed Read
  1429 				TUSB_VERBOSE_PRINT2("iMaxBufSz = %d (iReadBuf.Size(): %d)",
  1232 				TUSB_VERBOSE_PRINT2("iMaxBufSz = %d (iReadBuf.Size(): %d)",
  1430 									iMaxBufSz, iReadBuf.Size());
  1233 									iMaxBufSz, iReadBuf.Size());
  1431 				if(iVerbose)
       
  1432 				    {
       
  1433 				    OstTraceExt2(TRACE_VERBOSE, CACTIVERW_RUNL_DUP04, "iMaxBufSz = %d (iReadBuf.Size(): %d)",
       
  1434 									iMaxBufSz, iReadBuf.Size());
       
  1435 				    }
       
  1436 				WriteBufferToDisk(iReadBuf, iMaxBufSz);
  1234 				WriteBufferToDisk(iReadBuf, iMaxBufSz);
  1437 				}
  1235 				}
  1438 			ReadData();										// next we read data
  1236 			ReadData();										// next we read data
  1439 			break;
  1237 			break;
  1440 			}
  1238 			}
  1441 		if (iXferMode == ELoopComp)
  1239 		if (iXferMode == ELoopComp)
  1442 			{
  1240 			{
  1443 			if (!CompareBuffers(iBufSz))
  1241 			if (!CompareBuffers(iBufSz))
  1444 				{
  1242 				{
  1445 				TUSB_PRINT1("Error while comparing tx & rx buffers for packet 0x%x", iPktNum);
  1243 				TUSB_PRINT1("Error while comparing tx & rx buffers for packet 0x%x", iPktNum);
  1446 				OstTrace1(TRACE_NORMAL, CACTIVERW_RUNL_DUP05, "Error while comparing tx & rx buffers for packet 0x%x", iPktNum);
       
  1447 				}
  1244 				}
  1448 			}
  1245 			}
  1449 		else if (iBufSz > 3)
  1246 		else if (iBufSz > 3)
  1450 			{
  1247 			{
  1451 			const TUint32 num = *reinterpret_cast<const TUint32*>(iReadBuf.Ptr());
  1248 			const TUint32 num = *reinterpret_cast<const TUint32*>(iReadBuf.Ptr());
  1452 			if (num != iPktNum)
  1249 			if (num != iPktNum)
  1453 				{
  1250 				{
  1454 				TUSB_PRINT2("*** rcv'd wrong pkt number: 0x%x (expected: 0x%x)", num, iPktNum);
  1251 				TUSB_PRINT2("*** rcv'd wrong pkt number: 0x%x (expected: 0x%x)", num, iPktNum);
  1455 				OstTraceExt2(TRACE_NORMAL, CACTIVERW_RUNL_DUP06, "*** rcv'd wrong pkt number: 0x%x (expected: 0x%x)", num, iPktNum);
       
  1456 				}
  1252 				}
  1457 			}
  1253 			}
  1458 		if (iBufSz == iMaxBufSz)
  1254 		if (iBufSz == iMaxBufSz)
  1459 			{
  1255 			{
  1460 			iBufSz = KInitialBufSz;
  1256 			iBufSz = KInitialBufSz;
  1465 			}
  1261 			}
  1466 		SendPreamble();										// next we send the length
  1262 		SendPreamble();										// next we send the length
  1467 		break;
  1263 		break;
  1468 	default:
  1264 	default:
  1469 		TUSB_PRINT("Oops. (Shouldn't end up here...)");
  1265 		TUSB_PRINT("Oops. (Shouldn't end up here...)");
  1470 		OstTrace0(TRACE_NORMAL, CACTIVERW_RUNL_DUP07, "Oops. (Shouldn't end up here...)");
       
  1471 		break;
  1266 		break;
  1472 		}
  1267 		}
  1473 	return;
  1268 	return;
  1474 	}
  1269 	}
  1475 
  1270 
  1476 
  1271 
  1477 TInt CActiveRW::SendVersion()
  1272 TInt CActiveRW::SendVersion()
  1478 	{
  1273 	{
  1479 	TUSB_VERBOSE_PRINT("CActiveRW::SendVersion()");
  1274 	TUSB_VERBOSE_PRINT("CActiveRW::SendVersion()");
  1480 	if(iVerbose)
       
  1481 	    {
       
  1482 	    OstTrace0(TRACE_VERBOSE, CACTIVERW_SENDVERSION, "CActiveRW::SendVersion()");
       
  1483 	    }
       
  1484 	if (iXferMode != ::ENone)
  1275 	if (iXferMode != ::ENone)
  1485 		{
  1276 		{
  1486 		TUSB_PRINT1("Error : wrong state: %d", iXferMode);
  1277 		TUSB_PRINT1("Error : wrong state: %d", iXferMode);
  1487 		OstTrace1(TRACE_NORMAL, CACTIVERW_SENDVERSION_DUP01, "Error : wrong state: %d", iXferMode);
       
  1488 		return KErrGeneral;
  1278 		return KErrGeneral;
  1489 		}
  1279 		}
  1490 	// Here we send our version packet to the host.
  1280 	// Here we send our version packet to the host.
  1491 	// (We can use the preamble buffer because we only need it
  1281 	// (We can use the preamble buffer because we only need it
  1492 	//  once and that's also before the preamble uses.)
  1282 	//  once and that's also before the preamble uses.)
  1493 	TUSB_PRINT1("Sending T_USB version: %d\n", KTusbVersion);
  1283 	TUSB_PRINT1("Sending T_USB version: %d\n", KTusbVersion);
  1494 	OstTrace1(TRACE_NORMAL, CACTIVERW_SENDVERSION_DUP02, "Sending T_USB version: %d\n", KTusbVersion);
       
  1495 	iPreambleBuf.FillZ();
  1284 	iPreambleBuf.FillZ();
  1496 	*reinterpret_cast<TUint32*>(&iPreambleBuf[0]) = SWAP_BYTES_32(KTusbVersion);
  1285 	*reinterpret_cast<TUint32*>(&iPreambleBuf[0]) = SWAP_BYTES_32(KTusbVersion);
  1497 	// A 'magic' string so that USBRFLCT doesn't interpret the first 4 bytes
  1286 	// A 'magic' string so that USBRFLCT doesn't interpret the first 4 bytes
  1498 	// of a data preamble packet of an old T_USB as the version number.
  1287 	// of a data preamble packet of an old T_USB as the version number.
  1499 	iPreambleBuf[4] = 'V';
  1288 	iPreambleBuf[4] = 'V';
  1501 	iPreambleBuf[6] = 'r';
  1290 	iPreambleBuf[6] = 'r';
  1502 	iPreambleBuf[7] = 's';
  1291 	iPreambleBuf[7] = 's';
  1503 	TRequestStatus send_status;
  1292 	TRequestStatus send_status;
  1504 	iPort->Write(send_status, EEndpoint1, iPreambleBuf, KPreambleLength);
  1293 	iPort->Write(send_status, EEndpoint1, iPreambleBuf, KPreambleLength);
  1505 	TUSB_VERBOSE_PRINT("Waiting for write request to complete...");
  1294 	TUSB_VERBOSE_PRINT("Waiting for write request to complete...");
  1506 	if(iVerbose)
       
  1507 	    {
       
  1508 	    OstTrace0(TRACE_VERBOSE, CACTIVERW_SENDVERSION_DUP03, "Waiting for write request to complete...");
       
  1509 	    }
       
  1510 	User::WaitForRequest(send_status);
  1295 	User::WaitForRequest(send_status);
  1511 	TUSB_VERBOSE_PRINT("...done.\n");
  1296 	TUSB_VERBOSE_PRINT("...done.\n");
  1512 	if(iVerbose)
       
  1513 	    {
       
  1514 	    OstTrace0(TRACE_VERBOSE, CACTIVERW_SENDVERSION_DUP04, "...done.\n");
       
  1515 	    }
       
  1516 	return send_status.Int();
  1297 	return send_status.Int();
  1517 	}
  1298 	}
  1518 
  1299 
  1519 
  1300 
  1520 TInt CActiveRW::ReceiveVersion()
  1301 TInt CActiveRW::ReceiveVersion()
  1521 	{
  1302 	{
  1522 	TUSB_VERBOSE_PRINT("CActiveRW::ReceiveVersion()");
  1303 	TUSB_VERBOSE_PRINT("CActiveRW::ReceiveVersion()");
  1523 	if(iVerbose)
       
  1524 	    {
       
  1525 	    OstTrace0(TRACE_VERBOSE, CACTIVERW_RECEIVEVERSION, "CActiveRW::ReceiveVersion()");
       
  1526 	    }
       
  1527 	if (iXferMode != ::ENone)
  1304 	if (iXferMode != ::ENone)
  1528 		{
  1305 		{
  1529 		TUSB_PRINT1("Error : wrong state: %d", iXferMode);
  1306 		TUSB_PRINT1("Error : wrong state: %d", iXferMode);
  1530 		OstTrace1(TRACE_NORMAL, CACTIVERW_RECEIVEVERSION_DUP01, "Error : wrong state: %d", iXferMode);
       
  1531 		return KErrGeneral;
  1307 		return KErrGeneral;
  1532 		}
  1308 		}
  1533 	// Here we try to receive a version packet from the host.
  1309 	// Here we try to receive a version packet from the host.
  1534 	// (We can use the preamble buffer because we only need it
  1310 	// (We can use the preamble buffer because we only need it
  1535 	//  once and that's also before the preamble uses.)
  1311 	//  once and that's also before the preamble uses.)
  1536 	TUSB_PRINT("Getting host program versions...");
  1312 	TUSB_PRINT("Getting host program versions...");
  1537 	OstTrace0(TRACE_NORMAL, CACTIVERW_RECEIVEVERSION_DUP02, "Getting host program versions...");
       
  1538 	iPreambleBuf.FillZ();
  1313 	iPreambleBuf.FillZ();
  1539 	TRequestStatus receive_status;
  1314 	TRequestStatus receive_status;
  1540 	iPort->Read(receive_status, EEndpoint2, iPreambleBuf, KPreambleLength);
  1315 	iPort->Read(receive_status, EEndpoint2, iPreambleBuf, KPreambleLength);
  1541 	TUSB_VERBOSE_PRINT("Waiting for read request to complete...");
  1316 	TUSB_VERBOSE_PRINT("Waiting for read request to complete...");
  1542 	if(iVerbose)
       
  1543 	    {
       
  1544 	    OstTrace0(TRACE_VERBOSE, CACTIVERW_RECEIVEVERSION_DUP03, "Waiting for read request to complete...");
       
  1545 	    }
       
  1546 	iTimeoutTimer->Activate(5000000);						// Host gets 5s
  1317 	iTimeoutTimer->Activate(5000000);						// Host gets 5s
  1547 	User::WaitForRequest(receive_status, iTimeoutTimer->iStatus);
  1318 	User::WaitForRequest(receive_status, iTimeoutTimer->iStatus);
  1548 	if (receive_status == KRequestPending)
  1319 	if (receive_status == KRequestPending)
  1549 		{
  1320 		{
  1550 		// Read() still pending...
  1321 		// Read() still pending...
  1551 		TUSB_PRINT("Cancelling USB Read(): no response from host.\n");
  1322 		TUSB_PRINT("Cancelling USB Read(): no response from host.\n");
  1552 		OstTrace0(TRACE_NORMAL, CACTIVERW_RECEIVEVERSION_DUP04, "Cancelling USB Read(): no response from host.\n");
       
  1553 		iPort->ReadCancel(EEndpoint2);
  1323 		iPort->ReadCancel(EEndpoint2);
  1554 		TUSB_PRINT("THIS COULD BE DUE TO AN OLD VERSION OF USBRFLCT ON THE PC:");
  1324 		TUSB_PRINT("THIS COULD BE DUE TO AN OLD VERSION OF USBRFLCT ON THE PC:");
  1555 		OstTrace0(TRACE_NORMAL, CACTIVERW_RECEIVEVERSION_DUP05, "THIS COULD BE DUE TO AN OLD VERSION OF USBRFLCT ON THE PC:");
       
  1556 		TUSB_PRINT3("PLEASE CHECK THE VERSION THERE - WE NEED AT LEAST V%d.%d.%d!\n",
  1325 		TUSB_PRINT3("PLEASE CHECK THE VERSION THERE - WE NEED AT LEAST V%d.%d.%d!\n",
  1557 					KUsbrflctVersionMajor, KUsbrflctVersionMinor, KUsbrflctVersionMicro);
       
  1558 		OstTraceExt3(TRACE_NORMAL, CACTIVERW_RECEIVEVERSION_DUP06, "PLEASE CHECK THE VERSION THERE - WE NEED AT LEAST V%d.%d.%d!\n",
       
  1559 					KUsbrflctVersionMajor, KUsbrflctVersionMinor, KUsbrflctVersionMicro);
  1326 					KUsbrflctVersionMajor, KUsbrflctVersionMinor, KUsbrflctVersionMicro);
  1560 		TUSB_PRINT("When updating an existing USBRFLCT installation <= v1.3.1,\n" \
  1327 		TUSB_PRINT("When updating an existing USBRFLCT installation <= v1.3.1,\n" \
  1561 				   L"the following three things will need to be done:\n");
  1328 				   L"the following three things will need to be done:\n");
  1562 		OstTrace0(TRACE_NORMAL, CACTIVERW_RECEIVEVERSION_DUP07, "When updating an existing USBRFLCT installation <= v1.3.1,\n" \
       
  1563 				   L"the following three things will need to be done:\n");
       
  1564 		TUSB_PRINT("1. Connect the device to the PC & start T_USB (just as now),\n" \
  1329 		TUSB_PRINT("1. Connect the device to the PC & start T_USB (just as now),\n" \
  1565 				   L"then find the USB device in the Windows Device Manager\n" \
       
  1566 				   L"('Control Panel'->'System'->'Hardware'->'Device Manager').\n" \
       
  1567 				   L"Right click on the device name and choose 'Uninstall...'.\n");
       
  1568 		OstTrace0(TRACE_NORMAL, CACTIVERW_RECEIVEVERSION_DUP08, "1. Connect the device to the PC & start T_USB (just as now),\n" \
       
  1569 				   L"then find the USB device in the Windows Device Manager\n" \
  1330 				   L"then find the USB device in the Windows Device Manager\n" \
  1570 				   L"('Control Panel'->'System'->'Hardware'->'Device Manager').\n" \
  1331 				   L"('Control Panel'->'System'->'Hardware'->'Device Manager').\n" \
  1571 				   L"Right click on the device name and choose 'Uninstall...'.\n");
  1332 				   L"Right click on the device name and choose 'Uninstall...'.\n");
  1572 		TUSB_PRINT("2. In c:\\winnt\\inf\\, find (by searching for \"Symbian\") and\n" \
  1333 		TUSB_PRINT("2. In c:\\winnt\\inf\\, find (by searching for \"Symbian\") and\n" \
  1573 				   L"delete the *.INF file that was used to install the existing\n" \
  1334 				   L"delete the *.INF file that was used to install the existing\n" \
  1574 				   L"version of USBRFLCT.SYS. Make sure to also delete the\n" \
  1335 				   L"version of USBRFLCT.SYS. Make sure to also delete the\n" \
  1575 				   L"precompiled version of that file (<samename>.PNF).\n");
  1336 				   L"precompiled version of that file (<samename>.PNF).\n");
  1576 		OstTrace0(TRACE_NORMAL, CACTIVERW_RECEIVEVERSION_DUP09, "2. In c:\\winnt\\inf\\, find (by searching for \"Symbian\") and\n" \
       
  1577 				   L"delete the *.INF file that was used to install the existing\n" \
       
  1578 				   L"version of USBRFLCT.SYS. Make sure to also delete the\n" \
       
  1579 				   L"precompiled version of that file (<samename>.PNF).\n");
       
  1580 		TUSB_PRINT("3. In c:\\winnt\\system32\\drivers\\, delete the file USBRFLCT.SYS.\n");
  1337 		TUSB_PRINT("3. In c:\\winnt\\system32\\drivers\\, delete the file USBRFLCT.SYS.\n");
  1581 		OstTrace0(TRACE_NORMAL, CACTIVERW_RECEIVEVERSION_DUP10, "3. In c:\\winnt\\system32\\drivers\\, delete the file USBRFLCT.SYS.\n");
       
  1582 		TUSB_PRINT("Then unplug & reconnect the USB device and, when prompted, install\n" \
  1338 		TUSB_PRINT("Then unplug & reconnect the USB device and, when prompted, install\n" \
  1583 				   L"the new USBRFLCT.SYS driver using the .INF file from this distribution.\n" \
  1339 				   L"the new USBRFLCT.SYS driver using the .INF file from this distribution.\n" \
  1584 				   L"(All files can be found under e32test\\win32\\usbrflct_distribution\\.)\n");
  1340 				   L"(All files can be found under e32test\\win32\\usbrflct_distribution\\.)\n");
  1585 		OstTrace0(TRACE_NORMAL, CACTIVERW_RECEIVEVERSION_DUP11, "Then unplug & reconnect the USB device and, when prompted, install\n" \
       
  1586 				   L"the new USBRFLCT.SYS driver using the .INF file from this distribution.\n" \
       
  1587 				   L"(All files can be found under e32test\\win32\\usbrflct_distribution\\.)\n");
       
  1588 		TUSB_PRINT("Use the new USBRFLCT.EXE from this distribution.\n");
  1341 		TUSB_PRINT("Use the new USBRFLCT.EXE from this distribution.\n");
  1589 		OstTrace0(TRACE_NORMAL, CACTIVERW_RECEIVEVERSION_DUP12, "Use the new USBRFLCT.EXE from this distribution.\n");
       
  1590 		}
  1342 		}
  1591 	else
  1343 	else
  1592 		{
  1344 		{
  1593 		TUSB_VERBOSE_PRINT("...done.");
  1345 		TUSB_VERBOSE_PRINT("...done.");
  1594 		if(iVerbose)
       
  1595 		    {
       
  1596 		    OstTrace0(TRACE_VERBOSE, CACTIVERW_RECEIVEVERSION_DUP13, "...done.");
       
  1597 		    }
       
  1598 		// Timeout not needed any longer
  1346 		// Timeout not needed any longer
  1599 		TUSB_VERBOSE_PRINT("Cancelling timeout timer: USB Read() completed.\n");
  1347 		TUSB_VERBOSE_PRINT("Cancelling timeout timer: USB Read() completed.\n");
  1600 		if(iVerbose)
       
  1601 		    {
       
  1602 		    OstTrace0(TRACE_VERBOSE, CACTIVERW_RECEIVEVERSION_DUP14, "Cancelling timeout timer: USB Read() completed.\n");
       
  1603 		    }
       
  1604 		iTimeoutTimer->Cancel();
  1348 		iTimeoutTimer->Cancel();
  1605 		}
  1349 		}
  1606 	return receive_status.Int();
  1350 	return receive_status.Int();
  1607 	}
  1351 	}
  1608 
  1352 
  1609 
  1353 
  1610 TInt CActiveRW::ExchangeVersions()
  1354 TInt CActiveRW::ExchangeVersions()
  1611 	{
  1355 	{
  1612 	TUSB_VERBOSE_PRINT("CActiveRW::ExchangeVersions()");
  1356 	TUSB_VERBOSE_PRINT("CActiveRW::ExchangeVersions()");
  1613 	if(iVerbose)
       
  1614 	    {
       
  1615 	    OstTrace0(TRACE_VERBOSE, CACTIVERW_EXCHANGEVERSIONS, "CActiveRW::ExchangeVersions()");
       
  1616 	    }
       
  1617 	// First check the version of USBRFLCT that's running on the host
  1357 	// First check the version of USBRFLCT that's running on the host
  1618 	TInt r = ReceiveVersion();
  1358 	TInt r = ReceiveVersion();
  1619 	if (r != KErrNone)
  1359 	if (r != KErrNone)
  1620 		{
  1360 		{
  1621 		return KErrGeneral;
  1361 		return KErrGeneral;
  1626 	TUint8 usbio_ver_major = iPreambleBuf[3];
  1366 	TUint8 usbio_ver_major = iPreambleBuf[3];
  1627 	TUint8 usbio_ver_minor = iPreambleBuf[4];
  1367 	TUint8 usbio_ver_minor = iPreambleBuf[4];
  1628 	TUSB_PRINT5("Host-side: USBRFLCT v%d.%d.%d  USBIO v%d.%d\n",
  1368 	TUSB_PRINT5("Host-side: USBRFLCT v%d.%d.%d  USBIO v%d.%d\n",
  1629 				usbrflct_ver_major, usbrflct_ver_minor, usbrflct_ver_micro,
  1369 				usbrflct_ver_major, usbrflct_ver_minor, usbrflct_ver_micro,
  1630 				usbio_ver_major, usbio_ver_minor);
  1370 				usbio_ver_major, usbio_ver_minor);
  1631 	OstTraceExt5(TRACE_NORMAL, CACTIVERW_EXCHANGEVERSIONS_DUP01, "Host-side: USBRFLCT v%d.%d.%d  USBIO v%d.%d\n",
       
  1632 				usbrflct_ver_major, usbrflct_ver_minor, usbrflct_ver_micro,
       
  1633 				usbio_ver_major, usbio_ver_minor);
       
  1634 	if (usbrflct_ver_major < KUsbrflctVersionMajor)
  1371 	if (usbrflct_ver_major < KUsbrflctVersionMajor)
  1635 		{
  1372 		{
  1636 		TUSB_PRINT1("USBRFLCT version not sufficient (need at least v%d.x.x)\n",
  1373 		TUSB_PRINT1("USBRFLCT version not sufficient (need at least v%d.x.x)\n",
  1637 					KUsbrflctVersionMajor);
       
  1638 		OstTrace1(TRACE_NORMAL, CACTIVERW_EXCHANGEVERSIONS_DUP02, "USBRFLCT version not sufficient (need at least v%d.x.x)\n",
       
  1639 					KUsbrflctVersionMajor);
  1374 					KUsbrflctVersionMajor);
  1640 		return KErrGeneral;
  1375 		return KErrGeneral;
  1641 		}
  1376 		}
  1642 	// Just using '<' instead of the seemingly absurd '<= && !==' doesn't work without
  1377 	// Just using '<' instead of the seemingly absurd '<= && !==' doesn't work without
  1643 	// GCC compiler warning because Kxxx can also be zero (in which case there's no '<').
  1378 	// GCC compiler warning because Kxxx can also be zero (in which case there's no '<').
  1644 	else if ((usbrflct_ver_minor <= KUsbrflctVersionMinor) &&
  1379 	else if ((usbrflct_ver_minor <= KUsbrflctVersionMinor) &&
  1645 			 !(usbrflct_ver_minor == KUsbrflctVersionMinor))
  1380 			 !(usbrflct_ver_minor == KUsbrflctVersionMinor))
  1646 		{
  1381 		{
  1647 		TUSB_PRINT2("USBRFLCT version not sufficient (need at least v%d.%d.x)\n",
  1382 		TUSB_PRINT2("USBRFLCT version not sufficient (need at least v%d.%d.x)\n",
  1648 					KUsbrflctVersionMajor, KUsbrflctVersionMinor);
  1383 					KUsbrflctVersionMajor, KUsbrflctVersionMinor);
  1649 		OstTraceExt2(TRACE_NORMAL, CACTIVERW_EXCHANGEVERSIONS_DUP03, "USBRFLCT version not sufficient (need at least v%d.%d.x)\n",
       
  1650 					KUsbrflctVersionMajor, KUsbrflctVersionMinor);
       
  1651 		return KErrGeneral;
  1384 		return KErrGeneral;
  1652 		}
  1385 		}
  1653 	// Just using '<' instead of the seemingly absurd '<= && !==' doesn't work without
  1386 	// Just using '<' instead of the seemingly absurd '<= && !==' doesn't work without
  1654 	// GCC compiler warning because Kxxx can also be zero (in which case there's no '<').
  1387 	// GCC compiler warning because Kxxx can also be zero (in which case there's no '<').
  1655 	else if ((usbrflct_ver_micro <= KUsbrflctVersionMicro) &&
  1388 	else if ((usbrflct_ver_micro <= KUsbrflctVersionMicro) &&
  1656 			 !(usbrflct_ver_micro == KUsbrflctVersionMicro))
  1389 			 !(usbrflct_ver_micro == KUsbrflctVersionMicro))
  1657 		{
  1390 		{
  1658 		TUSB_PRINT3("USBRFLCT version not sufficient (need at least v%d.%d.%d)\n",
  1391 		TUSB_PRINT3("USBRFLCT version not sufficient (need at least v%d.%d.%d)\n",
  1659 					KUsbrflctVersionMajor, KUsbrflctVersionMinor, KUsbrflctVersionMicro);
  1392 					KUsbrflctVersionMajor, KUsbrflctVersionMinor, KUsbrflctVersionMicro);
  1660 		OstTraceExt3(TRACE_NORMAL, CACTIVERW_EXCHANGEVERSIONS_DUP04, "USBRFLCT version not sufficient (need at least v%d.%d.%d)\n",
       
  1661 					KUsbrflctVersionMajor, KUsbrflctVersionMinor, KUsbrflctVersionMicro);
       
  1662 		return KErrGeneral;
  1393 		return KErrGeneral;
  1663 		}
  1394 		}
  1664 	// Now we send T_USB's version to the host
  1395 	// Now we send T_USB's version to the host
  1665 	r = SendVersion();
  1396 	r = SendVersion();
  1666 	if (r != KErrNone)
  1397 	if (r != KErrNone)
  1672 
  1403 
  1673 
  1404 
  1674 void CActiveRW::SendPreamble()
  1405 void CActiveRW::SendPreamble()
  1675 	{
  1406 	{
  1676 	TUSB_VERBOSE_PRINT("CActiveRW::SendPreamble()");
  1407 	TUSB_VERBOSE_PRINT("CActiveRW::SendPreamble()");
  1677 	if(iVerbose)
       
  1678 	    {
       
  1679 	    OstTrace0(TRACE_VERBOSE, CACTIVERW_SENDPREAMBLE, "CActiveRW::SendPreamble()");
       
  1680 	    }
       
  1681 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666));
  1408 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666));
  1682 	TUSB_VERBOSE_PRINT1("Sending data length: %d bytes", iBufSz);
  1409 	TUSB_VERBOSE_PRINT1("Sending data length: %d bytes", iBufSz);
  1683 	if(iVerbose)
       
  1684 	    {
       
  1685 	    OstTrace1(TRACE_VERBOSE, CACTIVERW_SENDPREAMBLE_DUP01, "Sending data length: %d bytes", iBufSz);
       
  1686 	    }
       
  1687 	*reinterpret_cast<TUint32*>(&iPreambleBuf[0]) = SWAP_BYTES_32(iBufSz);
  1410 	*reinterpret_cast<TUint32*>(&iPreambleBuf[0]) = SWAP_BYTES_32(iBufSz);
  1688 	iPort->Write(iStatus, EEndpoint1, iPreambleBuf, KPreambleLength);
  1411 	iPort->Write(iStatus, EEndpoint1, iPreambleBuf, KPreambleLength);
  1689 	iCurrentXfer = EPreamble;
  1412 	iCurrentXfer = EPreamble;
  1690 	SetActive();
  1413 	SetActive();
  1691 	}
  1414 	}
  1692 
  1415 
  1693 
  1416 
  1694 void CActiveRW::SendData()
  1417 void CActiveRW::SendData()
  1695 	{
  1418 	{
  1696 	TUSB_VERBOSE_PRINT("CActiveRW::SendData()");
  1419 	TUSB_VERBOSE_PRINT("CActiveRW::SendData()");
  1697 	if(iVerbose)
       
  1698 	    {
       
  1699 	    OstTrace0(TRACE_VERBOSE, CACTIVERW_SENDDATA, "CActiveRW::SendData()");
       
  1700 	    }
       
  1701 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666));
  1420 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666));
  1702 	if (iDiskAccessEnabled)
  1421 	if (iDiskAccessEnabled)
  1703 		{
  1422 		{
  1704 		ReadBufferFromDisk(iWriteBuf, iBufSz);
  1423 		ReadBufferFromDisk(iWriteBuf, iBufSz);
  1705 		}
  1424 		}
  1714 			{
  1433 			{
  1715 			iWriteBuf[i] = static_cast<TUint8>(iPktNum & 0x000000ff);
  1434 			iWriteBuf[i] = static_cast<TUint8>(iPktNum & 0x000000ff);
  1716 			}
  1435 			}
  1717 		}
  1436 		}
  1718 	TUSB_VERBOSE_PRINT1("Sending data: %d bytes", iBufSz);
  1437 	TUSB_VERBOSE_PRINT1("Sending data: %d bytes", iBufSz);
  1719 	if(iVerbose)
       
  1720 	    {
       
  1721 	    OstTrace1(TRACE_VERBOSE, CACTIVERW_SENDDATA_DUP01, "Sending data: %d bytes", iBufSz);
       
  1722 	    }
       
  1723 	iPort->Write(iStatus, EEndpoint1, iWriteBuf, iBufSz);
  1438 	iPort->Write(iStatus, EEndpoint1, iWriteBuf, iBufSz);
  1724 	iCurrentXfer = EWriteXfer;
  1439 	iCurrentXfer = EWriteXfer;
  1725 	SetActive();
  1440 	SetActive();
  1726 	}
  1441 	}
  1727 
  1442 
  1731 	TDriveList driveList;
  1446 	TDriveList driveList;
  1732 	TInt r = iFs.DriveList(driveList);
  1447 	TInt r = iFs.DriveList(driveList);
  1733 	if (r != KErrNone)
  1448 	if (r != KErrNone)
  1734 		{
  1449 		{
  1735 		TUSB_PRINT1("RFs::DriveList() returned %d", r);
  1450 		TUSB_PRINT1("RFs::DriveList() returned %d", r);
  1736 		OstTrace1(TRACE_NORMAL, CACTIVERW_SELECTDRIVE, "RFs::DriveList() returned %d", r);
       
  1737 		return r;
  1451 		return r;
  1738 		}
  1452 		}
  1739 	TUSB_PRINT("Available drives:");
  1453 	TUSB_PRINT("Available drives:");
  1740 	OstTrace0(TRACE_NORMAL, CACTIVERW_SELECTDRIVE_DUP01, "Available drives:");
       
  1741 	for (TInt n = 0; n < KMaxDrives; n++)
  1454 	for (TInt n = 0; n < KMaxDrives; n++)
  1742 		{
  1455 		{
  1743 		if (driveList[n] != 0)
  1456 		if (driveList[n] != 0)
  1744 			{
  1457 			{
  1745 			TVolumeInfo volumeInfo;
  1458 			TVolumeInfo volumeInfo;
  1746 			r = iFs.Volume(volumeInfo, n);
  1459 			r = iFs.Volume(volumeInfo, n);
  1747 			if (r == KErrNone)
  1460 			if (r == KErrNone)
  1748 				{
  1461 				{
  1749 				TPtr name(volumeInfo.iName.Des());
  1462 				TPtr name(volumeInfo.iName.Des());
  1750 				TUSB_PRINT2("Drive %c: %- 16S", 'A' + n, &name);
  1463 				TUSB_PRINT2("Drive %c: %- 16S", 'A' + n, &name);
  1751 				OstTraceExt2(TRACE_NORMAL, CACTIVERW_SELECTDRIVE_DUP02, "Drive %c: %S", 'A' + n, name);
       
  1752 				if (volumeInfo.iDrive.iMediaAtt & KMediaAttWriteProtected)
  1464 				if (volumeInfo.iDrive.iMediaAtt & KMediaAttWriteProtected)
  1753 					TUSB_PRINT("  (read-only)");
  1465 					TUSB_PRINT("  (read-only)");
  1754 					OstTrace0(TRACE_NORMAL, CACTIVERW_SELECTDRIVE_DUP03, "  (read-only)");
       
  1755 				TUSB_PRINT("");
  1466 				TUSB_PRINT("");
  1756 				OstTrace0(TRACE_NORMAL, CACTIVERW_SELECTDRIVE_DUP04, "");
       
  1757 				}
  1467 				}
  1758 			}
  1468 			}
  1759 		}
  1469 		}
  1760 	iConsole->Printf(_L("Please select a drive letter (or 'Q' to quit)..."));
  1470 	iConsole->Printf(_L("Please select a drive letter (or 'Q' to quit)..."));
  1761 	OstTrace0(TRACE_NORMAL, CACTIVERW_SELECTDRIVE_DUP05, "Please select a drive letter (or 'Q' to quit...");
       
  1762 	TChar driveLetter;
  1471 	TChar driveLetter;
  1763 	TInt driveNumber;
  1472 	TInt driveNumber;
  1764 	TVolumeInfo volumeInfo;
  1473 	TVolumeInfo volumeInfo;
  1765 	do
  1474 	do
  1766 		{
  1475 		{
  1780 		   (volumeInfo.iDrive.iMediaAtt & KMediaAttWriteProtected));
  1489 		   (volumeInfo.iDrive.iMediaAtt & KMediaAttWriteProtected));
  1781 
  1490 
  1782 	iFileName.Format(_L("%c:"), driveLetter.operator TUint());
  1491 	iFileName.Format(_L("%c:"), driveLetter.operator TUint());
  1783 	iFileName.Append(KFileName);
  1492 	iFileName.Append(KFileName);
  1784 	TUSB_PRINT1("\nFilename = %S", &iFileName);
  1493 	TUSB_PRINT1("\nFilename = %S", &iFileName);
  1785 	OstTraceExt1(TRACE_NORMAL, CACTIVERW_SELECTDRIVE_DUP06, "\nFilename = %S", iFileName);
       
  1786 	TUSB_PRINT1("File size: %d", KMaxFileSize);
  1494 	TUSB_PRINT1("File size: %d", KMaxFileSize);
  1787 	OstTrace1(TRACE_NORMAL, CACTIVERW_SELECTDRIVE_DUP07, "File size: %d", KMaxFileSize);
       
  1788 	return r;
  1495 	return r;
  1789 	}
  1496 	}
  1790 
  1497 
  1791 
  1498 
  1792 TInt CActiveRW::WriteToDisk(TBool aEnable)
  1499 TInt CActiveRW::WriteToDisk(TBool aEnable)
  1826 		// First create the file & fill it
  1533 		// First create the file & fill it
  1827 		r = iFile.Replace(iFs, iFileName, EFileWrite);
  1534 		r = iFile.Replace(iFs, iFileName, EFileWrite);
  1828 		if (r != KErrNone)
  1535 		if (r != KErrNone)
  1829 			{
  1536 			{
  1830 			TUSB_PRINT1("RFile::Replace() returned %d", r);
  1537 			TUSB_PRINT1("RFile::Replace() returned %d", r);
  1831 			OstTrace1(TRACE_NORMAL, CACTIVERW_READFROMDISK, "RFile::Replace() returned %d", r);
       
  1832 			iDiskAccessEnabled = EFalse;
  1538 			iDiskAccessEnabled = EFalse;
  1833 			return r;
  1539 			return r;
  1834 			}
  1540 			}
  1835 		const TInt KBufferSize = 4 * 1024;
  1541 		const TInt KBufferSize = 4 * 1024;
  1836 		TBuf8<KBufferSize> buffer;
  1542 		TBuf8<KBufferSize> buffer;
  1838 		for (TInt n = 0; n < KBufferSize; n++)
  1544 		for (TInt n = 0; n < KBufferSize; n++)
  1839 			{
  1545 			{
  1840 			buffer[n] = static_cast<TUint8>(n & 0x000000ff);
  1546 			buffer[n] = static_cast<TUint8>(n & 0x000000ff);
  1841 			}
  1547 			}
  1842 		TUSB_PRINT("Writing data to file (this may take some minutes...)");
  1548 		TUSB_PRINT("Writing data to file (this may take some minutes...)");
  1843 		OstTrace0(TRACE_NORMAL, CACTIVERW_READFROMDISK_DUP01, "Writing data to file (this may take some minutes...)");
       
  1844 		for (TInt n = 0; n < KMaxFileSize; n += KBufferSize)
  1549 		for (TInt n = 0; n < KMaxFileSize; n += KBufferSize)
  1845 			{
  1550 			{
  1846 			r = iFile.Write(buffer, KBufferSize);
  1551 			r = iFile.Write(buffer, KBufferSize);
  1847 			if (r != KErrNone)
  1552 			if (r != KErrNone)
  1848 				{
  1553 				{
  1849 				TUSB_PRINT1("RFile::Write() returned %d (disk full?)", r);
  1554 				TUSB_PRINT1("RFile::Write() returned %d (disk full?)", r);
  1850 				OstTrace1(TRACE_NORMAL, CACTIVERW_READFROMDISK_DUP02, "RFile::Write() returned %d (disk full?)", r);
       
  1851 				iFile.Close();
  1555 				iFile.Close();
  1852 				iDiskAccessEnabled = EFalse;
  1556 				iDiskAccessEnabled = EFalse;
  1853 				return r;
  1557 				return r;
  1854 				}
  1558 				}
  1855 			}
  1559 			}
  1856 		TUSB_PRINT("Done.");
  1560 		TUSB_PRINT("Done.");
  1857 		OstTrace0(TRACE_NORMAL, CACTIVERW_READFROMDISK_DUP03, "Done.");
       
  1858 		iFile.Close();
  1561 		iFile.Close();
  1859 		// Now open the file for reading
  1562 		// Now open the file for reading
  1860 		r = iFile.Open(iFs, iFileName, EFileRead);
  1563 		r = iFile.Open(iFs, iFileName, EFileRead);
  1861 		if (r != KErrNone)
  1564 		if (r != KErrNone)
  1862 			{
  1565 			{
  1863 			TUSB_PRINT1("RFile::Open() returned %d", r);
  1566 			TUSB_PRINT1("RFile::Open() returned %d", r);
  1864 			OstTrace1(TRACE_NORMAL, CACTIVERW_READFROMDISK_DUP04, "RFile::Open() returned %d", r);
       
  1865 			iDiskAccessEnabled = EFalse;
  1567 			iDiskAccessEnabled = EFalse;
  1866 			return r;
  1568 			return r;
  1867 			}
  1569 			}
  1868 		iFileOffset = 0;
  1570 		iFileOffset = 0;
  1869 		}
  1571 		}
  1872 
  1574 
  1873 
  1575 
  1874 void CActiveRW::WriteBufferToDisk(TDes8& aBuffer, TInt aLen)
  1576 void CActiveRW::WriteBufferToDisk(TDes8& aBuffer, TInt aLen)
  1875 	{
  1577 	{
  1876 	TUSB_VERBOSE_PRINT1("CActiveRW::WriteBufferToDisk(), len = %d", aLen);
  1578 	TUSB_VERBOSE_PRINT1("CActiveRW::WriteBufferToDisk(), len = %d", aLen);
  1877 	if(iVerbose)
       
  1878 	    {
       
  1879 	    OstTrace1(TRACE_VERBOSE, CACTIVERW_WRITEBUFFERTODISK, "CActiveRW::WriteBufferToDisk(), len = %d", aLen);
       
  1880 	    }
       
  1881 	TInt r = iFile.Write(aBuffer, aLen);
  1579 	TInt r = iFile.Write(aBuffer, aLen);
  1882 	if (r != KErrNone)
  1580 	if (r != KErrNone)
  1883 		{
  1581 		{
  1884 		TUSB_PRINT2("Error writing to %S (%d)", &iFileName, r);
  1582 		TUSB_PRINT2("Error writing to %S (%d)", &iFileName, r);
  1885 		OstTraceExt2(TRACE_NORMAL, CACTIVERW_WRITEBUFFERTODISK_DUP01, "Error writing to %S (%d)", iFileName, r);
       
  1886 		iDiskAccessEnabled = EFalse;
  1583 		iDiskAccessEnabled = EFalse;
  1887 		return;
  1584 		return;
  1888 		}
  1585 		}
  1889 	iFileOffset += aLen;
  1586 	iFileOffset += aLen;
  1890 	if (iFileOffset >= KMaxFileSize)
  1587 	if (iFileOffset >= KMaxFileSize)
  1904 		}
  1601 		}
  1905 	const TInt r = iFile.Read(aBuffer, aLen);
  1602 	const TInt r = iFile.Read(aBuffer, aLen);
  1906 	if (r != KErrNone)
  1603 	if (r != KErrNone)
  1907 		{
  1604 		{
  1908 		TUSB_PRINT2("Error reading from %S (%d)", &iFileName, r);
  1605 		TUSB_PRINT2("Error reading from %S (%d)", &iFileName, r);
  1909 		OstTraceExt2(TRACE_NORMAL, CACTIVERW_READBUFFERFROMDISK, "Error reading from %S (%d)", iFileName, r);
       
  1910 		iDiskAccessEnabled = EFalse;
  1606 		iDiskAccessEnabled = EFalse;
  1911 		return;
  1607 		return;
  1912 		}
  1608 		}
  1913 	TInt readLen = aBuffer.Length();
  1609 	TInt readLen = aBuffer.Length();
  1914 	TUSB_VERBOSE_PRINT1("CActiveRW::ReadBufferFromDisk(), len = %d\n", readLen);
  1610 	TUSB_VERBOSE_PRINT1("CActiveRW::ReadBufferFromDisk(), len = %d\n", readLen);
  1915 	if(iVerbose)
       
  1916 	    {
       
  1917 	    OstTrace1(TRACE_VERBOSE, CACTIVERW_READBUFFERFROMDISK_DUP01, "CActiveRW::ReadBufferFromDisk(), len = %d\n", readLen);
       
  1918 	    }
       
  1919 	if (readLen < aLen)
  1611 	if (readLen < aLen)
  1920 		{
  1612 		{
  1921 		TUSB_PRINT3("Only %d bytes of %d read from file %S)",
  1613 		TUSB_PRINT3("Only %d bytes of %d read from file %S)",
  1922 					readLen, aLen, &iFileName);
  1614 					readLen, aLen, &iFileName);
  1923 		OstTraceExt3(TRACE_NORMAL, CACTIVERW_READBUFFERFROMDISK_DUP02, "Only %d bytes of %d read from file %S)",
       
  1924 					readLen, aLen, iFileName);
       
  1925 		iDiskAccessEnabled = EFalse;
  1615 		iDiskAccessEnabled = EFalse;
  1926 		return;
  1616 		return;
  1927 		}
  1617 		}
  1928 	iFileOffset += aLen;
  1618 	iFileOffset += aLen;
  1929 	}
  1619 	}
  1930 
  1620 
  1931 
  1621 
  1932 void CActiveRW::ReadData()
  1622 void CActiveRW::ReadData()
  1933 	{
  1623 	{
  1934 	TUSB_VERBOSE_PRINT("CActiveRW::ReadData()");
  1624 	TUSB_VERBOSE_PRINT("CActiveRW::ReadData()");
  1935 	if(iVerbose)
       
  1936 	    {
       
  1937 	    OstTrace0(TRACE_VERBOSE, CACTIVERW_READDATA, "CActiveRW::ReadData()");
       
  1938 	    }
       
  1939 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666));
  1625 	__ASSERT_ALWAYS(!IsActive(), User::Panic(KActivePanic, 666));
  1940 	TUSB_VERBOSE_PRINT1("Reading data: %d bytes", iBufSz);
  1626 	TUSB_VERBOSE_PRINT1("Reading data: %d bytes", iBufSz);
  1941 	if(iVerbose)
       
  1942 	    {
       
  1943 	    OstTrace1(TRACE_VERBOSE, CACTIVERW_READDATA_DUP01, "Reading data: %d bytes", iBufSz);
       
  1944 	    }
       
  1945 	if (iXferMode == EReceiveOnly)
  1627 	if (iXferMode == EReceiveOnly)
  1946 		{
  1628 		{
  1947 		TUSB_VERBOSE_PRINT("  (rx only)");
  1629 		TUSB_VERBOSE_PRINT("  (rx only)");
  1948 		if(iVerbose)
       
  1949 		    {
       
  1950 		    OstTrace0(TRACE_VERBOSE, CACTIVERW_READDATA_DUP02, "  (rx only)");
       
  1951 		    }
       
  1952 		iPort->Read(iStatus, EEndpoint2, iReadBuf, iBufSz);
  1630 		iPort->Read(iStatus, EEndpoint2, iReadBuf, iBufSz);
  1953 		}
  1631 		}
  1954 	else if (iBufSz == iMaxPktSz)
  1632 	else if (iBufSz == iMaxPktSz)
  1955 		{
  1633 		{
  1956 		// we also want to test the packet version of Read()
  1634 		// we also want to test the packet version of Read()
  1957 		TUSB_VERBOSE_PRINT("  (a single packet)");
  1635 		TUSB_VERBOSE_PRINT("  (a single packet)");
  1958 		if(iVerbose)
       
  1959 		    {
       
  1960 		    OstTrace0(TRACE_VERBOSE, CACTIVERW_READDATA_DUP03, "  (a single packet)");
       
  1961 		    }
       
  1962 		iPort->ReadPacket(iStatus, EEndpoint2, iReadBuf, iBufSz);
  1636 		iPort->ReadPacket(iStatus, EEndpoint2, iReadBuf, iBufSz);
  1963 		}
  1637 		}
  1964 	else if (iBufSz == iReadBuf.MaxSize())
  1638 	else if (iBufSz == iReadBuf.MaxSize())
  1965 		{
  1639 		{
  1966 		// or we could perhaps test the three-parameter version
  1640 		// or we could perhaps test the three-parameter version
  1967 		TUSB_VERBOSE_PRINT("  (w/o length)");
  1641 		TUSB_VERBOSE_PRINT("  (w/o length)");
  1968 		if(iVerbose)
       
  1969 		    {
       
  1970 		    OstTrace0(TRACE_VERBOSE, CACTIVERW_READDATA_DUP04, "  (w/o length)");
       
  1971 		    }
       
  1972 		iPort->Read(iStatus, EEndpoint2, iReadBuf);
  1642 		iPort->Read(iStatus, EEndpoint2, iReadBuf);
  1973 		}
  1643 		}
  1974 	else
  1644 	else
  1975 		{
  1645 		{
  1976 		// otherwise, we use the universal default version
  1646 		// otherwise, we use the universal default version
  1977 		TUSB_VERBOSE_PRINT("  (normal)");
  1647 		TUSB_VERBOSE_PRINT("  (normal)");
  1978 		if(iVerbose)
       
  1979 		    {
       
  1980 		    OstTrace0(TRACE_VERBOSE, CACTIVERW_READDATA_DUP05, "  (normal)");
       
  1981 		    }
       
  1982 		iPort->Read(iStatus, EEndpoint2, iReadBuf, iBufSz);
  1648 		iPort->Read(iStatus, EEndpoint2, iReadBuf, iBufSz);
  1983 		}
  1649 		}
  1984 	iCurrentXfer = EReadXfer;
  1650 	iCurrentXfer = EReadXfer;
  1985 	SetActive();
  1651 	SetActive();
  1986 	}
  1652 	}
  1989 void CActiveRW::Stop()
  1655 void CActiveRW::Stop()
  1990 	{
  1656 	{
  1991 	if (!IsActive())
  1657 	if (!IsActive())
  1992 		{
  1658 		{
  1993 		TUSB_PRINT("CActiveRW::Stop(): Not active");
  1659 		TUSB_PRINT("CActiveRW::Stop(): Not active");
  1994 		OstTrace0(TRACE_NORMAL, CACTIVERW_STOP, "CActiveRW::Stop(): Not active");
       
  1995 		return;
  1660 		return;
  1996 		}
  1661 		}
  1997 	TUSB_PRINT("Cancelling outstanding transfer requests\n");
  1662 	TUSB_PRINT("Cancelling outstanding transfer requests\n");
  1998 	OstTrace0(TRACE_NORMAL, CACTIVERW_STOP_DUP01, "Cancelling outstanding transfer requests\n");
       
  1999 	iBufSz = KInitialBufSz;
  1663 	iBufSz = KInitialBufSz;
  2000 	iPktNum = ~0;
  1664 	iPktNum = ~0;
  2001 	iDoStop = ETrue;
  1665 	iDoStop = ETrue;
  2002 	iCurrentXfer = ENone;
  1666 	iCurrentXfer = ENone;
  2003 	Cancel();
  1667 	Cancel();
  2005 
  1669 
  2006 
  1670 
  2007 void CActiveRW::DoCancel()
  1671 void CActiveRW::DoCancel()
  2008 	{
  1672 	{
  2009 	TUSB_VERBOSE_PRINT("CActiveRW::DoCancel()");
  1673 	TUSB_VERBOSE_PRINT("CActiveRW::DoCancel()");
  2010 	if(iVerbose)
       
  2011 	    {
       
  2012 	    OstTrace0(TRACE_VERBOSE, CACTIVERW_DOCANCEL, "CActiveRW::DoCancel()");
       
  2013 	    }
       
  2014 	// Canceling the transfer requests can be done explicitly
  1674 	// Canceling the transfer requests can be done explicitly
  2015 	// for every transfer...
  1675 	// for every transfer...
  2016 	iPort->WriteCancel(EEndpoint1);
  1676 	iPort->WriteCancel(EEndpoint1);
  2017 	iPort->ReadCancel(EEndpoint2);
  1677 	iPort->ReadCancel(EEndpoint2);
  2018 	// or like this:
  1678 	// or like this:
  2021 
  1681 
  2022 
  1682 
  2023 TBool CActiveRW::CompareBuffers(TInt aLen)
  1683 TBool CActiveRW::CompareBuffers(TInt aLen)
  2024 	{
  1684 	{
  2025 	TUSB_VERBOSE_PRINT1("CActiveRW::CompareBuffers(%d)", aLen);
  1685 	TUSB_VERBOSE_PRINT1("CActiveRW::CompareBuffers(%d)", aLen);
  2026 	if(iVerbose)
       
  2027 	    {
       
  2028 	    OstTrace1(TRACE_VERBOSE, CACTIVERW_COMPAREBUFFERS, "CActiveRW::CompareBuffers(%d)", aLen);
       
  2029 	    }
       
  2030 	for (TInt i = 0; i < aLen; i++)
  1686 	for (TInt i = 0; i < aLen; i++)
  2031 		{
  1687 		{
  2032 		if (iReadBuf[i] != iWriteBuf[i])
  1688 		if (iReadBuf[i] != iWriteBuf[i])
  2033 			{
  1689 			{
  2034 			TUSB_VERBOSE_PRINT1("Error: for i = %d:", i);
  1690 			TUSB_VERBOSE_PRINT1("Error: for i = %d:", i);
  2035 			if(iVerbose)
       
  2036 			    {
       
  2037 			    OstTrace1(TRACE_VERBOSE, CACTIVERW_COMPAREBUFFERS_DUP01, "Error: for i = %d:", i);
       
  2038 			    }
       
  2039 			TUSB_VERBOSE_PRINT2("iReadBuf: %d != iWriteBuf: %d",
  1691 			TUSB_VERBOSE_PRINT2("iReadBuf: %d != iWriteBuf: %d",
  2040 								iReadBuf[i], iWriteBuf[i]);
  1692 								iReadBuf[i], iWriteBuf[i]);
  2041 			if(iVerbose)
       
  2042 			    {
       
  2043 			    OstTraceExt2(TRACE_VERBOSE, CACTIVERW_COMPAREBUFFERS_DUP02, "iReadBuf: %d != iWriteBuf: %d",
       
  2044 								iReadBuf[i], iWriteBuf[i]);
       
  2045 			    }
       
  2046 			return EFalse;
  1693 			return EFalse;
  2047 			}
  1694 			}
  2048 		}
  1695 		}
  2049 	return ETrue;
  1696 	return ETrue;
  2050 	}
  1697 	}
  2081 
  1728 
  2082 
  1729 
  2083 CActiveStallNotifier::~CActiveStallNotifier()
  1730 CActiveStallNotifier::~CActiveStallNotifier()
  2084 	{
  1731 	{
  2085 	TUSB_VERBOSE_PRINT("CActiveStallNotifier::~CActiveStallNotifier()");
  1732 	TUSB_VERBOSE_PRINT("CActiveStallNotifier::~CActiveStallNotifier()");
  2086 	if(iVerbose)
       
  2087 	    {
       
  2088 	    OstTrace0(TRACE_VERBOSE, CACTIVESTALLNOTIFIER_DCACTIVESTALLNOTIFIER, "CActiveStallNotifier::~CActiveStallNotifier()");
       
  2089 	    }
       
  2090 	Cancel();												// base class
  1733 	Cancel();												// base class
  2091 	}
  1734 	}
  2092 
  1735 
  2093 
  1736 
  2094 void CActiveStallNotifier::DoCancel()
  1737 void CActiveStallNotifier::DoCancel()
  2095 	{
  1738 	{
  2096 	TUSB_VERBOSE_PRINT("CActiveStallNotifier::DoCancel()");
  1739 	TUSB_VERBOSE_PRINT("CActiveStallNotifier::DoCancel()");
  2097 	if(iVerbose)
       
  2098 	    {
       
  2099 	    OstTrace0(TRACE_VERBOSE, CACTIVESTALLNOTIFIER_DOCANCEL, "CActiveStallNotifier::DoCancel()");
       
  2100 	    }
       
  2101 	iPort->EndpointStatusNotifyCancel();
  1740 	iPort->EndpointStatusNotifyCancel();
  2102 	}
  1741 	}
  2103 
  1742 
  2104 
  1743 
  2105 void CActiveStallNotifier::RunL()
  1744 void CActiveStallNotifier::RunL()
  2106 	{
  1745 	{
  2107 	// This just displays the bitmap, showing which endpoints (if any) are now stalled.
  1746 	// This just displays the bitmap, showing which endpoints (if any) are now stalled.
  2108 	// In a real world program, the user could take here appropriate action (cancel a
  1747 	// In a real world program, the user could take here appropriate action (cancel a
  2109 	// transfer request or whatever).
  1748 	// transfer request or whatever).
  2110 	TUSB_VERBOSE_PRINT1("StallNotifier: Endpointstate 0x%x\n", iEndpointState);
  1749 	TUSB_VERBOSE_PRINT1("StallNotifier: Endpointstate 0x%x\n", iEndpointState);
  2111 	if(iVerbose)
       
  2112 	    {
       
  2113 	    OstTrace1(TRACE_VERBOSE, CACTIVESTALLNOTIFIER_RUNL, "StallNotifier: Endpointstate 0x%x\n", iEndpointState);
       
  2114 	    }
       
  2115 	Activate();
  1750 	Activate();
  2116 	}
  1751 	}
  2117 
  1752 
  2118 
  1753 
  2119 void CActiveStallNotifier::Activate()
  1754 void CActiveStallNotifier::Activate()
  2155 
  1790 
  2156 
  1791 
  2157 CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()
  1792 CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()
  2158 	{
  1793 	{
  2159 	TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()");
  1794 	TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()");
  2160 	if(iVerbose)
       
  2161 	    {
       
  2162 	    OstTrace0(TRACE_VERBOSE, CACTIVEDEVICESTATENOTIFIER_DCACTIVEDEVICESTATENOTIFIER, "CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier()");
       
  2163 	    }
       
  2164 	Cancel();												// base class
  1795 	Cancel();												// base class
  2165 	}
  1796 	}
  2166 
  1797 
  2167 
  1798 
  2168 void CActiveDeviceStateNotifier::DoCancel()
  1799 void CActiveDeviceStateNotifier::DoCancel()
  2169 	{
  1800 	{
  2170 	TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::DoCancel()");
  1801 	TUSB_VERBOSE_PRINT("CActiveDeviceStateNotifier::DoCancel()");
  2171 	if(iVerbose)
       
  2172 	    {
       
  2173 	    OstTrace0(TRACE_VERBOSE, CACTIVEDEVICESTATENOTIFIER_DOCANCEL, "CActiveDeviceStateNotifier::DoCancel()");
       
  2174 	    }
       
  2175 	iPort->AlternateDeviceStatusNotifyCancel();
  1802 	iPort->AlternateDeviceStatusNotifyCancel();
  2176 	}
  1803 	}
  2177 
  1804 
  2178 
  1805 
  2179 void CActiveDeviceStateNotifier::RunL()
  1806 void CActiveDeviceStateNotifier::RunL()
  2185 		{
  1812 		{
  2186 		switch (iDeviceState)
  1813 		switch (iDeviceState)
  2187 			{
  1814 			{
  2188 		case EUsbcDeviceStateUndefined:
  1815 		case EUsbcDeviceStateUndefined:
  2189 			TUSB_PRINT("Device State notifier: Undefined");
  1816 			TUSB_PRINT("Device State notifier: Undefined");
  2190 			OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL, "Device State notifier: Undefined");
       
  2191 			break;
  1817 			break;
  2192 		case EUsbcDeviceStateAttached:
  1818 		case EUsbcDeviceStateAttached:
  2193 			TUSB_PRINT("Device State notifier: Attached");
  1819 			TUSB_PRINT("Device State notifier: Attached");
  2194 			OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP01, "Device State notifier: Attached");
       
  2195 			break;
  1820 			break;
  2196 		case EUsbcDeviceStatePowered:
  1821 		case EUsbcDeviceStatePowered:
  2197 			TUSB_PRINT("Device State notifier: Powered");
  1822 			TUSB_PRINT("Device State notifier: Powered");
  2198 			OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP02, "Device State notifier: Powered");
       
  2199 			break;
  1823 			break;
  2200 		case EUsbcDeviceStateDefault:
  1824 		case EUsbcDeviceStateDefault:
  2201 			TUSB_PRINT("Device State notifier: Default");
  1825 			TUSB_PRINT("Device State notifier: Default");
  2202 			OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP03, "Device State notifier: Default");
       
  2203 			break;
  1826 			break;
  2204 		case EUsbcDeviceStateAddress:
  1827 		case EUsbcDeviceStateAddress:
  2205 			TUSB_PRINT("Device State notifier: Address");
  1828 			TUSB_PRINT("Device State notifier: Address");
  2206 			OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP04, "Device State notifier: Address");
       
  2207 			break;
  1829 			break;
  2208 		case EUsbcDeviceStateConfigured:
  1830 		case EUsbcDeviceStateConfigured:
  2209 			TUSB_PRINT("Device State notifier: Configured");
  1831 			TUSB_PRINT("Device State notifier: Configured");
  2210 			OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP05, "Device State notifier: Configured");
       
  2211 			break;
  1832 			break;
  2212 		case EUsbcDeviceStateSuspended:
  1833 		case EUsbcDeviceStateSuspended:
  2213 			TUSB_PRINT("Device State notifier: Suspended");
  1834 			TUSB_PRINT("Device State notifier: Suspended");
  2214 			OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP06, "Device State notifier: Suspended");
       
  2215 			break;
  1835 			break;
  2216 		default:
  1836 		default:
  2217 			TUSB_PRINT("Device State notifier: ***BAD***");
  1837 			TUSB_PRINT("Device State notifier: ***BAD***");
  2218 			OstTrace0(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP07, "Device State notifier: ***BAD***");
       
  2219 			}
  1838 			}
  2220 		}
  1839 		}
  2221 	else if (iDeviceState & KUsbAlternateSetting)
  1840 	else if (iDeviceState & KUsbAlternateSetting)
  2222 		{
  1841 		{
  2223 		TUSB_PRINT1("Device State notifier: Alternate interface setting has changed: now %d",
  1842 		TUSB_PRINT1("Device State notifier: Alternate interface setting has changed: now %d",
  2224 					iDeviceState & ~KUsbAlternateSetting);
       
  2225 		OstTrace1(TRACE_NORMAL, CACTIVEDEVICESTATENOTIFIER_RUNL_DUP08, "Device State notifier: Alternate interface setting has changed: now %d",
       
  2226 					iDeviceState & ~KUsbAlternateSetting);
  1843 					iDeviceState & ~KUsbAlternateSetting);
  2227 		}
  1844 		}
  2228 
  1845 
  2229 	Activate();
  1846 	Activate();
  2230 	}
  1847 	}
  2271 
  1888 
  2272 
  1889 
  2273 CActiveTimer::~CActiveTimer()
  1890 CActiveTimer::~CActiveTimer()
  2274 	{
  1891 	{
  2275 	TUSB_VERBOSE_PRINT("CActiveTimer::~CActiveTimer()");
  1892 	TUSB_VERBOSE_PRINT("CActiveTimer::~CActiveTimer()");
  2276 	if(iVerbose)
       
  2277 	    {
       
  2278 	    OstTrace0(TRACE_VERBOSE, CACTIVETIMER_DCACTIVETIMER, "CActiveTimer::~CActiveTimer()");
       
  2279 	    }
       
  2280 	Cancel();												// base class
  1893 	Cancel();												// base class
  2281 	iTimer.Close();
  1894 	iTimer.Close();
  2282 	}
  1895 	}
  2283 
  1896 
  2284 
  1897 
  2285 void CActiveTimer::DoCancel()
  1898 void CActiveTimer::DoCancel()
  2286 	{
  1899 	{
  2287 	TUSB_VERBOSE_PRINT("CActiveTimer::DoCancel()");
  1900 	TUSB_VERBOSE_PRINT("CActiveTimer::DoCancel()");
  2288 	if(iVerbose)
       
  2289 	    {
       
  2290 	    OstTrace0(TRACE_VERBOSE, CACTIVETIMER_DOCANCEL, "CActiveTimer::DoCancel()");
       
  2291 	    }
       
  2292 	iTimer.Cancel();
  1901 	iTimer.Cancel();
  2293 	}
  1902 	}
  2294 
  1903 
  2295 
  1904 
  2296 void CActiveTimer::RunL()
  1905 void CActiveTimer::RunL()
  2297 	{
  1906 	{
  2298 	TUSB_VERBOSE_PRINT("CActiveTimer::RunL()");
  1907 	TUSB_VERBOSE_PRINT("CActiveTimer::RunL()");
  2299 	if(iVerbose)
       
  2300 	    {
       
  2301 	    OstTrace0(TRACE_VERBOSE, CACTIVETIMER_RUNL, "CActiveTimer::RunL()");
       
  2302 	    }
       
  2303 	// Nothing to do here, as we call ReadCancel() after a manual WaitForRequest()
  1908 	// Nothing to do here, as we call ReadCancel() after a manual WaitForRequest()
  2304 	// (in CActiveRW::ReceiveVersion()).
  1909 	// (in CActiveRW::ReceiveVersion()).
  2305 	}
  1910 	}
  2306 
  1911 
  2307 
  1912