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