253
|
1 |
// Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// @file testdevicebase.cpp
|
|
15 |
// @internalComponent
|
|
16 |
//
|
|
17 |
//
|
|
18 |
|
|
19 |
#include "TestDeviceBase.h"
|
|
20 |
#include "UsbDescriptorOffsets.h"
|
|
21 |
#include "testdebug.h"
|
|
22 |
#include <e32test.h>
|
|
23 |
#include "softwareconnecttimer.h"
|
|
24 |
#include "wakeuptimer.h"
|
|
25 |
#include "controltransferrequests.h"
|
|
26 |
#include "testinterfacebase.h"
|
|
27 |
#include "PBASE-T_USBDI-0486.h"
|
253
|
28 |
#include "OstTraceDefinitions.h"
|
|
29 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
30 |
#include "TestDeviceBaseTraces.h"
|
|
31 |
#endif
|
0
|
32 |
#include <e32property.h>
|
|
33 |
|
|
34 |
namespace NUnitTesting_USBDI
|
|
35 |
{
|
|
36 |
|
|
37 |
RUsbTestDevice::RUsbTestDevice()
|
|
38 |
: iStateWatcher(NULL),
|
|
39 |
iCurrentState(EUsbcDeviceStateUndefined),
|
|
40 |
iDeviceEp0(NULL),
|
|
41 |
iConnectTimer(NULL), iWakeupTimer(NULL),
|
|
42 |
iAuxBuffer(NULL)
|
|
43 |
{
|
253
|
44 |
OstTraceFunctionEntry1( RUSBTESTDEVICE_RUSBTESTDEVICE_ENTRY, this );
|
|
45 |
OstTraceFunctionExit1( RUSBTESTDEVICE_RUSBTESTDEVICE_EXIT, this );
|
0
|
46 |
}
|
|
47 |
|
|
48 |
RUsbTestDevice::RUsbTestDevice(CBaseTestCase* aTestCase)
|
|
49 |
: iStateWatcher(NULL),
|
|
50 |
iCurrentState(EUsbcDeviceStateUndefined),
|
|
51 |
iDeviceEp0(NULL),
|
|
52 |
iConnectTimer(NULL), iWakeupTimer(NULL),
|
|
53 |
iAuxBuffer(NULL)
|
|
54 |
{
|
253
|
55 |
OstTraceFunctionEntryExt( RUSBTESTDEVICE_RUSBTESTDEVICE_ENTRY_DUP01, this );
|
0
|
56 |
iTestCase = aTestCase;
|
253
|
57 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_RUSBTESTDEVICE, "iTestCase = %d", iTestCase);
|
|
58 |
OstTraceFunctionExit1( RUSBTESTDEVICE_RUSBTESTDEVICE_EXIT_DUP01, this );
|
0
|
59 |
}
|
|
60 |
|
|
61 |
void RUsbTestDevice::ResetState()
|
|
62 |
{
|
253
|
63 |
OstTraceFunctionEntry1( RUSBTESTDEVICE_RESETSTATE_ENTRY, this );
|
0
|
64 |
iCurrentState = EUsbcDeviceStateUndefined;
|
253
|
65 |
OstTraceFunctionExit1( RUSBTESTDEVICE_RESETSTATE_EXIT, this );
|
0
|
66 |
}
|
|
67 |
|
|
68 |
RUsbTestDevice::~RUsbTestDevice()
|
|
69 |
{
|
253
|
70 |
OstTraceFunctionEntry1( RUSBTESTDEVICE_RUSBTESTDEVICE_ENTRY_DUP02, this );
|
0
|
71 |
|
253
|
72 |
OstTraceFunctionExit1( RUSBTESTDEVICE_RUSBTESTDEVICE_EXIT_DUP02, this );
|
0
|
73 |
}
|
|
74 |
|
|
75 |
void RUsbTestDevice::Close()
|
|
76 |
{
|
253
|
77 |
OstTraceFunctionEntry1( RUSBTESTDEVICE_CLOSE_ENTRY, this );
|
0
|
78 |
|
|
79 |
delete iWakeupTimer;
|
|
80 |
delete iConnectTimer;
|
|
81 |
delete iDeviceEp0;
|
|
82 |
delete iStateWatcher;
|
|
83 |
|
|
84 |
iInterfaces.ResetAndDestroy();
|
|
85 |
|
|
86 |
iClientDriver.Close();
|
|
87 |
|
|
88 |
if(!iTestCase->IsHost()) // process only started in client rom
|
|
89 |
{
|
|
90 |
// create a publish/subscribe key to allow usbhost_usbman to be killed
|
|
91 |
// cleanly
|
|
92 |
static const TUid KWordOfDeathCat = {0x01066600};
|
|
93 |
static const TInt KWordOfDeathKey = 0x01066601;
|
|
94 |
static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy);
|
|
95 |
TInt r = RProperty::Define(KWordOfDeathCat, KWordOfDeathKey, RProperty::EInt,KAllowAllPolicy, KAllowAllPolicy, 0);
|
|
96 |
if(r != KErrNone)
|
|
97 |
{
|
253
|
98 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_CLOSE, "Could not create the WordOfDeath P&S (%d)", r);
|
0
|
99 |
}
|
253
|
100 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_CLOSE_DUP01, "killing t_usbhost_usbman.exe");
|
0
|
101 |
RProperty::Set(KWordOfDeathCat, KWordOfDeathKey, KErrAbort); // Send the word of death
|
|
102 |
User::After(1000000); //allow time for t_usbhost_usbman.exe to clean up
|
|
103 |
}
|
253
|
104 |
OstTraceFunctionExit1( RUSBTESTDEVICE_CLOSE_EXIT, this );
|
0
|
105 |
}
|
|
106 |
|
|
107 |
|
|
108 |
void RUsbTestDevice::SubscribeToReports(TRequestStatus& aObserverStatus)
|
|
109 |
{
|
253
|
110 |
OstTraceFunctionEntryExt( RUSBTESTDEVICE_SUBSCRIBETOREPORTS_ENTRY, this );
|
0
|
111 |
|
|
112 |
// Signal the request as pending
|
|
113 |
|
|
114 |
iObserverStatus = &aObserverStatus;
|
|
115 |
*iObserverStatus = KRequestPending;
|
253
|
116 |
OstTraceFunctionExit1( RUSBTESTDEVICE_SUBSCRIBETOREPORTS_EXIT, this );
|
0
|
117 |
}
|
|
118 |
|
|
119 |
|
|
120 |
void RUsbTestDevice::CancelSubscriptionToReports()
|
|
121 |
{
|
253
|
122 |
OstTraceFunctionEntry1( RUSBTESTDEVICE_CANCELSUBSCRIPTIONTOREPORTS_ENTRY, this );
|
0
|
123 |
|
|
124 |
// Signal the request as cancelled
|
|
125 |
User::RequestComplete(iObserverStatus,KErrCancel);
|
253
|
126 |
OstTraceFunctionExit1( RUSBTESTDEVICE_CANCELSUBSCRIPTIONTOREPORTS_EXIT, this );
|
0
|
127 |
}
|
|
128 |
|
|
129 |
|
|
130 |
void RUsbTestDevice::OpenL()
|
|
131 |
{
|
253
|
132 |
OstTraceFunctionEntry1( RUSBTESTDEVICE_OPENL_ENTRY, this );
|
0
|
133 |
TInt err = KErrNone;
|
|
134 |
|
253
|
135 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_OPENL, "starting t_usbhost_usbman.exe");
|
0
|
136 |
TInt r = iOtgUsbMan.Create(_L("t_usbhost_usbman.exe"), _L("client"));
|
|
137 |
gtest(r == KErrNone);
|
|
138 |
iOtgUsbMan.Resume();
|
|
139 |
|
|
140 |
User::After(1500000);
|
|
141 |
|
|
142 |
// Open channel to driver
|
|
143 |
err = iClientDriver.Open(0);
|
|
144 |
if(err != KErrNone)
|
|
145 |
{
|
253
|
146 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP01, "<Error %d> Unable to open a channel to USB client driver",err);
|
0
|
147 |
User::Leave(err);
|
|
148 |
}
|
|
149 |
|
|
150 |
// Hide bus from host while interfaces are being set up
|
|
151 |
err = iClientDriver.DeviceDisconnectFromHost();
|
|
152 |
if(err != KErrNone)
|
|
153 |
{
|
253
|
154 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP02, "<Error %d> unable to disconnect device from host",err);
|
0
|
155 |
User::Leave(err);
|
|
156 |
}
|
|
157 |
|
|
158 |
// Create the client usb state watcher
|
|
159 |
iStateWatcher = CUsbClientStateWatcher::NewL(iClientDriver,*this);
|
|
160 |
|
|
161 |
// Create the Ep0 reader
|
|
162 |
iDeviceEp0 = CDeviceEndpoint0::NewL(*this);
|
|
163 |
|
|
164 |
// Create the timer for software connection/disconnection
|
|
165 |
iConnectTimer = CSoftwareConnectTimer::NewL(*this);
|
|
166 |
|
|
167 |
// Create the timer for remote wakeup events
|
|
168 |
iWakeupTimer = CRemoteWakeupTimer::NewL(*this);
|
|
169 |
_LIT8(KYes, "yes");
|
|
170 |
_LIT8(KNo, "no");
|
|
171 |
User::LeaveIfError(iClientDriver.DeviceCaps(iDeviceCaps));
|
253
|
172 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP03, "------ USB device capabilities -------");
|
|
173 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP04, "Number of endpoints: %d",iDeviceCaps().iTotalEndpoints);
|
|
174 |
OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP05, "Supports Software-Connect: %s",iDeviceCaps().iConnect ? KYes() : KNo());
|
|
175 |
OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP06, "Device is Self-Powered: %S",iDeviceCaps().iSelfPowered ? KYes() : KNo());
|
|
176 |
OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP07, "Supports Remote-Wakeup: %S",iDeviceCaps().iRemoteWakeup ? KYes() : KNo());
|
|
177 |
OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP08, "Supports High-speed: %S",iDeviceCaps().iHighSpeed ? KYes() : KNo());
|
|
178 |
OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP09, "Supports unpowered cable detection: %S",(iDeviceCaps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower) ? KYes() : KNo());
|
|
179 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP10, "--------------------------------------");
|
0
|
180 |
|
253
|
181 |
OstTraceFunctionExit1( RUSBTESTDEVICE_OPENL_EXIT, this );
|
0
|
182 |
}
|
|
183 |
|
|
184 |
|
|
185 |
TInt RUsbTestDevice::SetClassCode(TUint8 aClassCode,TUint8 aSubClassCode,TUint8 aDeviceProtocol)
|
|
186 |
{
|
253
|
187 |
OstTraceFunctionEntryExt( RUSBTESTDEVICE_SETCLASSCODE_ENTRY, this );
|
0
|
188 |
|
|
189 |
// Get Device descriptor
|
|
190 |
TBuf8<KUsbDescSize_Device> deviceDescriptor;
|
|
191 |
TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor));
|
|
192 |
if(err != KErrNone)
|
|
193 |
{
|
253
|
194 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETCLASSCODE, "<Error %d> Unable to obtain device descriptor",err);
|
0
|
195 |
}
|
|
196 |
else
|
|
197 |
{
|
|
198 |
deviceDescriptor[KDevDescOffset_bDeviceClass] = aClassCode;
|
|
199 |
deviceDescriptor[KDevDescOffset_bDeviceSubClass] = aSubClassCode;
|
|
200 |
deviceDescriptor[KDevDescOffset_bDeviceProtocol] = aDeviceProtocol;
|
|
201 |
|
|
202 |
err = iClientDriver.SetDeviceDescriptor(deviceDescriptor);
|
|
203 |
if(err != KErrNone)
|
|
204 |
{
|
253
|
205 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETCLASSCODE_DUP01, "<Error %d> Unable to set the device dsecriptor",err);
|
0
|
206 |
}
|
|
207 |
}
|
253
|
208 |
OstTraceFunctionExitExt( RUSBTESTDEVICE_SETCLASSCODE_EXIT, this, err );
|
0
|
209 |
return err;
|
|
210 |
}
|
|
211 |
|
|
212 |
|
|
213 |
TInt RUsbTestDevice::SetUsbSpecification(TUint16 aSpecification)
|
|
214 |
{
|
253
|
215 |
OstTraceFunctionEntryExt( RUSBTESTDEVICE_SETUSBSPECIFICATION_ENTRY, this );
|
0
|
216 |
|
|
217 |
// Get Device descriptor
|
|
218 |
TBuf8<KUsbDescSize_Device> deviceDescriptor;
|
|
219 |
TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor));
|
|
220 |
if(err != KErrNone)
|
|
221 |
{
|
253
|
222 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETUSBSPECIFICATION, "<Error %d> Unable to obtain device descriptor",err);
|
0
|
223 |
}
|
|
224 |
else
|
|
225 |
{
|
|
226 |
// Set bcdUSB
|
|
227 |
TUint8* p = reinterpret_cast<TUint8*>(&aSpecification);
|
|
228 |
deviceDescriptor[KDevDescOffset_bcdUSB] = *p;
|
|
229 |
deviceDescriptor[KDevDescOffset_bcdUSB+1] = *(p+1);
|
|
230 |
|
|
231 |
// Symbian currently supports only devices with one configuration by selecting the configurations
|
|
232 |
// that has the lowest power consumption
|
|
233 |
|
|
234 |
deviceDescriptor[KDevDescOffset_bNumConfigurations] = 0x01;
|
|
235 |
|
|
236 |
err = iClientDriver.SetDeviceDescriptor(deviceDescriptor);
|
|
237 |
if(err != KErrNone)
|
|
238 |
{
|
253
|
239 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETUSBSPECIFICATION_DUP01, "<Error %d> Unable to set the device dsecriptor",err);
|
0
|
240 |
}
|
|
241 |
}
|
253
|
242 |
OstTraceFunctionExitExt( RUSBTESTDEVICE_SETUSBSPECIFICATION_EXIT, this, err );
|
0
|
243 |
return err;
|
|
244 |
}
|
|
245 |
|
|
246 |
|
|
247 |
TInt RUsbTestDevice::SetVendor(TUint16 aVendorId)
|
|
248 |
{
|
253
|
249 |
OstTraceFunctionEntryExt( RUSBTESTDEVICE_SETVENDOR_ENTRY, this );
|
0
|
250 |
|
|
251 |
// Get Device descriptor
|
|
252 |
TBuf8<KUsbDescSize_Device> deviceDescriptor;
|
|
253 |
TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor));
|
|
254 |
if(err != KErrNone)
|
|
255 |
{
|
253
|
256 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETVENDOR, "<Error %d> Unable to obtain device descriptor",err);
|
0
|
257 |
}
|
|
258 |
else
|
|
259 |
{
|
|
260 |
// Set VID
|
|
261 |
TUint8* p = reinterpret_cast<TUint8*>(&aVendorId);
|
|
262 |
deviceDescriptor[KDevDescOffset_idVendor] = *p;
|
|
263 |
deviceDescriptor[KDevDescOffset_idVendor+1] = *(p+1);
|
|
264 |
|
|
265 |
err = iClientDriver.SetDeviceDescriptor(deviceDescriptor);
|
|
266 |
if(err != KErrNone)
|
|
267 |
{
|
253
|
268 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETVENDOR_DUP01, "<Error %d> Unable to set the device descriptor",err);
|
0
|
269 |
}
|
|
270 |
}
|
253
|
271 |
OstTraceFunctionExitExt( RUSBTESTDEVICE_SETVENDOR_EXIT, this, err );
|
0
|
272 |
return err;
|
|
273 |
}
|
|
274 |
|
|
275 |
|
|
276 |
TInt RUsbTestDevice::SetProduct(TUint16 aProductId,const TDesC16& aProductString,
|
|
277 |
const TDesC16& aManufacturerString,const TDesC16& aSerialNumberString)
|
|
278 |
{
|
253
|
279 |
OstTraceFunctionEntryExt( RUSBTESTDEVICE_SETPRODUCT_ENTRY, this );
|
0
|
280 |
|
|
281 |
// Get Device descriptor
|
|
282 |
TBuf8<KUsbDescSize_Device> deviceDescriptor;
|
|
283 |
TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor));
|
|
284 |
if(err != KErrNone)
|
|
285 |
{
|
253
|
286 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT, "<Error %d> Unable to obtain device descriptor",err);
|
0
|
287 |
}
|
|
288 |
else
|
|
289 |
{
|
|
290 |
// Set PID
|
|
291 |
TUint8* p = reinterpret_cast<TUint8*>(&aProductId);
|
|
292 |
deviceDescriptor[KDevDescOffset_idProduct] = *p;
|
|
293 |
deviceDescriptor[KDevDescOffset_idProduct+1] = *(p+1);
|
|
294 |
|
|
295 |
err = iClientDriver.SetDeviceDescriptor(deviceDescriptor);
|
|
296 |
if(err != KErrNone)
|
|
297 |
{
|
253
|
298 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT_DUP01, "<Error %d> Unable to set the device dsecriptor",err);
|
|
299 |
OstTraceFunctionExitExt( RUSBTESTDEVICE_SETPRODUCT_EXIT, this, err );
|
0
|
300 |
return err;
|
|
301 |
}
|
|
302 |
|
253
|
303 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT_DUP02, "Product Identity set");
|
0
|
304 |
|
|
305 |
// Product string
|
|
306 |
err = iClientDriver.SetProductStringDescriptor(aProductString);
|
|
307 |
if(err != KErrNone)
|
|
308 |
{
|
253
|
309 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT_DUP03, "<Error %d> Unable to set product string descriptor",err);
|
|
310 |
OstTraceFunctionExitExt( RUSBTESTDEVICE_SETPRODUCT_EXIT_DUP01, this, err );
|
0
|
311 |
return err;
|
|
312 |
}
|
|
313 |
|
|
314 |
// Manufacturer string
|
|
315 |
err = iClientDriver.SetManufacturerStringDescriptor(aManufacturerString);
|
|
316 |
if(err != KErrNone)
|
|
317 |
{
|
253
|
318 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT_DUP04, "<Error %d> Unable to set the manufacturer string descriptor",err);
|
|
319 |
OstTraceFunctionExitExt( RUSBTESTDEVICE_SETPRODUCT_EXIT_DUP02, this, err );
|
0
|
320 |
return err;
|
|
321 |
}
|
|
322 |
|
|
323 |
// Serial number string
|
|
324 |
err = iClientDriver.SetSerialNumberStringDescriptor(aSerialNumberString);
|
|
325 |
if(err != KErrNone)
|
|
326 |
{
|
253
|
327 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT_DUP05, "<Error %d> Unable to set the serial number string descriptor",err);
|
|
328 |
OstTraceFunctionExitExt( RUSBTESTDEVICE_SETPRODUCT_EXIT_DUP03, this, err );
|
0
|
329 |
return err;
|
|
330 |
}
|
|
331 |
}
|
253
|
332 |
OstTraceFunctionExitExt( RUSBTESTDEVICE_SETPRODUCT_EXIT_DUP04, this, KErrNone );
|
0
|
333 |
return KErrNone;
|
|
334 |
}
|
|
335 |
|
|
336 |
|
|
337 |
TInt RUsbTestDevice::SetConfigurationString(const TDesC16& aConfigString)
|
|
338 |
{
|
253
|
339 |
OstTraceFunctionEntryExt( RUSBTESTDEVICE_SETCONFIGURATIONSTRING_ENTRY, this );
|
0
|
340 |
|
|
341 |
TInt err(iClientDriver.SetConfigurationStringDescriptor(aConfigString));
|
|
342 |
if(err != KErrNone)
|
|
343 |
{
|
253
|
344 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETCONFIGURATIONSTRING, "<Error %d> Unable to set configuration string descriptor",err);
|
0
|
345 |
}
|
253
|
346 |
OstTraceFunctionExitExt( RUSBTESTDEVICE_SETCONFIGURATIONSTRING_EXIT, this, err );
|
0
|
347 |
return err;
|
|
348 |
}
|
|
349 |
|
|
350 |
|
|
351 |
void RUsbTestDevice::AddInterface(CInterfaceBase* aInterface)
|
|
352 |
{
|
253
|
353 |
OstTraceFunctionEntryExt( RUSBTESTDEVICE_ADDINTERFACE_ENTRY, this );
|
0
|
354 |
|
|
355 |
// Add the interface to the device
|
|
356 |
TInt err = iInterfaces.Append(aInterface);
|
|
357 |
|
|
358 |
if(err != KErrNone)
|
|
359 |
{
|
253
|
360 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_ADDINTERFACE, "<Error %d> Unable to add interface",err);
|
0
|
361 |
return ReportError(err);
|
|
362 |
}
|
253
|
363 |
OstTraceFunctionExit1( RUSBTESTDEVICE_ADDINTERFACE_EXIT, this );
|
0
|
364 |
}
|
|
365 |
|
|
366 |
|
|
367 |
CInterfaceBase& RUsbTestDevice::Interface(TInt aIndex)
|
|
368 |
{
|
253
|
369 |
OstTraceFunctionEntryExt( RUSBTESTDEVICE_INTERFACE_ENTRY, this );
|
|
370 |
OstTraceFunctionExit1( RUSBTESTDEVICE_INTERFACE_EXIT, this );
|
0
|
371 |
return *iInterfaces[aIndex];
|
|
372 |
}
|
|
373 |
|
|
374 |
|
|
375 |
void RUsbTestDevice::SoftwareConnect()
|
|
376 |
{
|
253
|
377 |
OstTraceFunctionEntry1( RUSBTESTDEVICE_SOFTWARECONNECT_ENTRY, this );
|
0
|
378 |
TInt err(iClientDriver.PowerUpUdc());
|
|
379 |
if((err != KErrNone) && (err != KErrNotReady))
|
|
380 |
{
|
253
|
381 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWARECONNECT, "<Error %d> Power Up Udc",err);
|
0
|
382 |
ReportError(err);
|
|
383 |
}
|
|
384 |
|
|
385 |
if(iDeviceCaps().iConnect)
|
|
386 |
{
|
|
387 |
err = iClientDriver.DeviceConnectToHost();
|
|
388 |
if(err != KErrNone)
|
|
389 |
{
|
253
|
390 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWARECONNECT_DUP01, "<Error %d> Unable to connect to the host",err);
|
0
|
391 |
ReportError(err);
|
|
392 |
}
|
|
393 |
}
|
|
394 |
else
|
|
395 |
{
|
253
|
396 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWARECONNECT_DUP02, "Please connect device to Host");
|
0
|
397 |
}
|
253
|
398 |
OstTraceFunctionExit1( RUSBTESTDEVICE_SOFTWARECONNECT_EXIT, this );
|
0
|
399 |
}
|
|
400 |
|
|
401 |
void RUsbTestDevice::SoftwareDisconnect()
|
|
402 |
{
|
253
|
403 |
OstTraceFunctionEntry1( RUSBTESTDEVICE_SOFTWAREDISCONNECT_ENTRY, this );
|
0
|
404 |
|
|
405 |
if(iDeviceCaps().iConnect)
|
|
406 |
{
|
|
407 |
TInt err(iClientDriver.DeviceDisconnectFromHost());
|
|
408 |
if(err != KErrNone)
|
|
409 |
{
|
253
|
410 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWAREDISCONNECT, "<Error %d> Unable to disconnect from the host",err);
|
0
|
411 |
ReportError(err);
|
|
412 |
}
|
|
413 |
}
|
|
414 |
else
|
|
415 |
{
|
253
|
416 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWAREDISCONNECT_DUP01, "Please disconnect device from Host");
|
0
|
417 |
}
|
|
418 |
|
253
|
419 |
OstTraceFunctionExit1( RUSBTESTDEVICE_SOFTWAREDISCONNECT_EXIT, this );
|
0
|
420 |
}
|
|
421 |
|
|
422 |
|
|
423 |
void RUsbTestDevice::RemoteWakeup()
|
|
424 |
{
|
253
|
425 |
OstTraceFunctionEntry1( RUSBTESTDEVICE_REMOTEWAKEUP_ENTRY, this );
|
0
|
426 |
if(iDeviceCaps().iConnect)
|
|
427 |
{
|
|
428 |
TInt err(iClientDriver.SignalRemoteWakeup());
|
|
429 |
if(err != KErrNone)
|
|
430 |
{
|
253
|
431 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_REMOTEWAKEUP, "<Error %d> Unable to perform a remote wakeup",err);
|
0
|
432 |
ReportError(err);
|
|
433 |
}
|
|
434 |
}
|
|
435 |
else
|
|
436 |
{
|
253
|
437 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_REMOTEWAKEUP_DUP01, "remote wakeup not supported");
|
0
|
438 |
}
|
253
|
439 |
OstTraceFunctionExit1( RUSBTESTDEVICE_REMOTEWAKEUP_EXIT, this );
|
0
|
440 |
}
|
|
441 |
|
|
442 |
|
|
443 |
TInt RUsbTestDevice::ProcessRequestL(TUint8 aRequest,TUint16 aValue,TUint16 aIndex,
|
|
444 |
TUint16 aDataReqLength,const TDesC8& aPayload)
|
|
445 |
{
|
253
|
446 |
OstTraceFunctionEntryExt( RUSBTESTDEVICE_PROCESSREQUESTL_ENTRY, this );
|
0
|
447 |
|
|
448 |
if(aRequest == KVendorEmptyRequest)
|
|
449 |
{
|
|
450 |
// Handle an empty request (i.e. do nothing)
|
|
451 |
|
|
452 |
AcknowledgeRequestReceived();
|
|
453 |
}
|
|
454 |
else if(aRequest == KVendorReconnectRequest)
|
|
455 |
{
|
|
456 |
// Handle a reconnect requests from the host
|
|
457 |
|
|
458 |
AcknowledgeRequestReceived();
|
|
459 |
iConnectTimer->SoftwareReConnect(aValue);
|
|
460 |
}
|
|
461 |
else if(aRequest == KVendorDisconnectDeviceAThenConnectDeviceCRequest)
|
|
462 |
{
|
253
|
463 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL, "**aRequest == KVendorDisconnectDeviceAThenConnectDeviceCRequest, this = 0x%08x", this);
|
0
|
464 |
// Handle a reconnect requests from the host
|
|
465 |
AcknowledgeRequestReceived();
|
|
466 |
|
|
467 |
SoftwareDisconnect();
|
|
468 |
User::After(1000000);
|
|
469 |
// connect device C now
|
|
470 |
CUT_PBASE_T_USBDI_0486* iTestCaseT_USBDI_0486 = reinterpret_cast<CUT_PBASE_T_USBDI_0486*>(iTestCase);
|
|
471 |
Close();
|
|
472 |
|
|
473 |
User::After(3000000);
|
|
474 |
iTestCaseT_USBDI_0486->TestDeviceC()->OpenL(KTestDeviceC_SN);
|
|
475 |
// Connect the device to the host
|
|
476 |
iTestCaseT_USBDI_0486->TestDeviceC()->SoftwareConnect();
|
253
|
477 |
OstTraceFunctionExitExt( RUSBTESTDEVICE_PROCESSREQUESTL_EXIT, this, KErrAbort );
|
0
|
478 |
return KErrAbort;
|
|
479 |
}
|
|
480 |
else if(aRequest == KVendorDisconnectDeviceCThenConnectDeviceARequest)
|
|
481 |
{
|
253
|
482 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP01, "**aRequest == KVendorDisconnectDeviceCThenConnectDeviceARequest, this = 0x%08x", this);
|
0
|
483 |
// Handle a reconnect requests from the host
|
|
484 |
AcknowledgeRequestReceived();
|
|
485 |
|
|
486 |
SoftwareDisconnect();
|
|
487 |
User::After(1000000);
|
|
488 |
|
|
489 |
// connect device A now
|
|
490 |
CUT_PBASE_T_USBDI_0486* iTestCaseT_USBDI_0486 = reinterpret_cast<CUT_PBASE_T_USBDI_0486*>(iTestCase);
|
|
491 |
|
|
492 |
|
|
493 |
Close();
|
|
494 |
User::After(3000000);
|
|
495 |
iTestCaseT_USBDI_0486->Cancel();
|
|
496 |
iTestCaseT_USBDI_0486->HandleDeviceDConnection();
|
|
497 |
iTestCaseT_USBDI_0486->TestDeviceD()->OpenL(iTestCaseT_USBDI_0486->TestCaseId());
|
|
498 |
|
|
499 |
// Connect the device to the host
|
|
500 |
iTestCaseT_USBDI_0486->TestDeviceD()->SoftwareConnect();
|
253
|
501 |
OstTraceFunctionExitExt( RUSBTESTDEVICE_PROCESSREQUESTL_EXIT_DUP01, this, KErrAbort );
|
0
|
502 |
return KErrAbort;
|
|
503 |
}
|
|
504 |
else if(aRequest == KVendorTestCasePassed)
|
|
505 |
{
|
|
506 |
// Test case has completed successfully
|
|
507 |
// so report to client test case that host is happy
|
|
508 |
|
|
509 |
AcknowledgeRequestReceived();
|
|
510 |
ReportError(KErrNone);
|
|
511 |
}
|
|
512 |
else if(aRequest == KVendorTestCaseFailed)
|
|
513 |
{
|
|
514 |
// The test case has failed, so report to client test case
|
|
515 |
// and display/log the error message
|
|
516 |
|
|
517 |
AcknowledgeRequestReceived();
|
|
518 |
|
|
519 |
HBufC16* msg = HBufC16::NewL(aPayload.Length());
|
|
520 |
msg->Des().Copy(aPayload);
|
253
|
521 |
OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP02, "<Host> Test case failed: %S",*msg);
|
0
|
522 |
delete msg;
|
|
523 |
msg = 0;
|
|
524 |
ReportError(-aValue);
|
|
525 |
}
|
|
526 |
else if(aRequest == KVendorRemoteWakeupRequest)
|
|
527 |
{
|
|
528 |
// Handle a remote wakeup request
|
|
529 |
|
|
530 |
AcknowledgeRequestReceived();
|
|
531 |
iWakeupTimer->WakeUp(aValue);
|
|
532 |
}
|
|
533 |
else if(aRequest == KVendorPutPayloadRequest)
|
|
534 |
{
|
|
535 |
// Handle a payload request from the host
|
|
536 |
|
|
537 |
AcknowledgeRequestReceived();
|
253
|
538 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP03, "Put payload");
|
0
|
539 |
if(aPayload.Compare(_L8("DEADBEEF")) != 0)
|
|
540 |
{
|
253
|
541 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP04, "<Error %d> Payload not as expected",KErrCorrupt);
|
0
|
542 |
ReportError(KErrCorrupt);
|
|
543 |
}
|
|
544 |
}
|
|
545 |
else if(aRequest == KVendorGetPayloadRequest)
|
|
546 |
{
|
|
547 |
// Handle a payload request to the host
|
|
548 |
|
253
|
549 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP05, "Get payload");
|
0
|
550 |
__ASSERT_DEBUG(iAuxBuffer, User::Panic(_L("Trying to write non-allocated buffer"), KErrGeneral));
|
253
|
551 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP06, "iAuxBuffer = ....");
|
|
552 |
OstTraceData(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP56, "", iAuxBuffer->Ptr(), iAuxBuffer->Length());
|
|
553 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP07, "\n");
|
0
|
554 |
|
|
555 |
//Perform synchronous write to EP0
|
|
556 |
//This allows the subsequent 'Read' request to
|
|
557 |
//take place
|
|
558 |
TInt ret = iDeviceEp0->SendDataSynchronous(*iAuxBuffer);
|
253
|
559 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP08, "Write (from device callback) executed with error %d", ret);
|
0
|
560 |
}
|
|
561 |
else if(aRequest == KVendorUnrespondRequest)
|
|
562 |
{
|
|
563 |
// Do not acknowledge this request
|
|
564 |
|
253
|
565 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP09, "Unrespond request: continually NAK the host");
|
0
|
566 |
}
|
|
567 |
else if(aRequest == KVendorStallRequest)
|
|
568 |
{
|
|
569 |
// Stall the specified endpoint
|
|
570 |
|
|
571 |
AcknowledgeRequestReceived();
|
253
|
572 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP10, "Stalling endpoint %d",aValue);
|
0
|
573 |
|
|
574 |
}
|
|
575 |
else
|
|
576 |
{
|
|
577 |
// Maybe forward to derived classes
|
|
578 |
}
|
253
|
579 |
OstTraceFunctionExitExt( RUSBTESTDEVICE_PROCESSREQUESTL_EXIT_DUP02, this, KErrNone );
|
0
|
580 |
return KErrNone;
|
|
581 |
}
|
|
582 |
|
|
583 |
|
|
584 |
void RUsbTestDevice::StateChangeL(TUsbcDeviceState aNewState,TInt aChangeCompletionCode)
|
|
585 |
{
|
253
|
586 |
OstTraceFunctionEntryExt( RUSBTESTDEVICE_STATECHANGEL_ENTRY, this );
|
0
|
587 |
|
253
|
588 |
OstTraceExt2(TRACE_NORMAL, RUSBTESTDEVICE_STATECHANGEL, "Client state change to %d err=%d",aNewState,aChangeCompletionCode);
|
0
|
589 |
|
|
590 |
// Notify the test case of failed state change notification
|
|
591 |
|
|
592 |
if(aChangeCompletionCode != KErrNone)
|
|
593 |
{
|
|
594 |
return ReportError(aChangeCompletionCode);
|
|
595 |
}
|
|
596 |
|
|
597 |
// Check the state change
|
|
598 |
|
|
599 |
if(iCurrentState == EUsbcDeviceStateConfigured)
|
|
600 |
{
|
|
601 |
// Device is already in a fully configured state
|
|
602 |
|
|
603 |
if(aNewState == EUsbcDeviceStateConfigured)
|
|
604 |
{
|
|
605 |
// Do nothing as this is the current state anyway
|
|
606 |
}
|
|
607 |
else
|
|
608 |
{
|
|
609 |
// The is a state change from EUsbcDeviceStateConfigured to aNewState
|
|
610 |
// so stop reading from control ep0
|
|
611 |
|
253
|
612 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_STATECHANGEL_DUP01, "Ignoring control ep0");
|
0
|
613 |
|
|
614 |
// Stop reading ep0 directed requests
|
|
615 |
|
|
616 |
StopEp0Reading();
|
|
617 |
|
|
618 |
// Update state
|
|
619 |
|
|
620 |
iCurrentState = aNewState;
|
|
621 |
}
|
|
622 |
}
|
|
623 |
else
|
|
624 |
{
|
|
625 |
// Device is not in a fully configured state
|
|
626 |
|
|
627 |
if(aNewState == EUsbcDeviceStateConfigured)
|
|
628 |
{
|
|
629 |
// Device has now been placed into a fully configured state by the host
|
|
630 |
// so start reading from control ep0
|
|
631 |
|
253
|
632 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_STATECHANGEL_DUP02, "Reading from control ep0");
|
0
|
633 |
|
|
634 |
// Start reading ep0 directed requests
|
|
635 |
|
|
636 |
StartEp0Reading();
|
|
637 |
|
|
638 |
// Update state
|
|
639 |
|
|
640 |
iCurrentState = aNewState;
|
|
641 |
}
|
|
642 |
else
|
|
643 |
{
|
|
644 |
// Just update the state
|
|
645 |
|
|
646 |
iCurrentState = aNewState;
|
|
647 |
}
|
|
648 |
}
|
|
649 |
|
|
650 |
// Forward the state change notification to derived classes
|
|
651 |
|
|
652 |
OnStateChangeL(aNewState);
|
253
|
653 |
OstTraceFunctionExit1( RUSBTESTDEVICE_STATECHANGEL_EXIT, this );
|
0
|
654 |
}
|
|
655 |
|
|
656 |
|
|
657 |
void RUsbTestDevice::StartEp0Reading()
|
|
658 |
{
|
253
|
659 |
OstTraceFunctionEntry1( RUSBTESTDEVICE_STARTEP0READING_ENTRY, this );
|
0
|
660 |
|
|
661 |
// Start reading device directed ep0 requests
|
|
662 |
|
|
663 |
TInt err(iDeviceEp0->Start());
|
|
664 |
if(err != KErrNone)
|
|
665 |
{
|
|
666 |
return ReportError(err);
|
|
667 |
}
|
|
668 |
|
|
669 |
// Start reading interface directed requests
|
|
670 |
|
|
671 |
TInt interfaceCount(iInterfaces.Count());
|
|
672 |
for(TInt i=0; i<interfaceCount; i++)
|
|
673 |
{
|
|
674 |
iInterfaces[i]->StartEp0Reading();
|
|
675 |
}
|
253
|
676 |
OstTraceFunctionExit1( RUSBTESTDEVICE_STARTEP0READING_EXIT, this );
|
0
|
677 |
}
|
|
678 |
|
|
679 |
|
|
680 |
void RUsbTestDevice::StopEp0Reading()
|
|
681 |
{
|
253
|
682 |
OstTraceFunctionEntry1( RUSBTESTDEVICE_STOPEP0READING_ENTRY, this );
|
0
|
683 |
|
|
684 |
// Stop reading interface directed requests
|
|
685 |
|
|
686 |
TInt interfaceCount(iInterfaces.Count());
|
|
687 |
for(TInt i=0; i<interfaceCount; i++)
|
|
688 |
{
|
|
689 |
iInterfaces[i]->StopEp0Reading();
|
|
690 |
}
|
|
691 |
|
|
692 |
// Stop reading device directed requests from ep0
|
|
693 |
|
|
694 |
TInt err(iDeviceEp0->Stop());
|
|
695 |
if(err != KErrNone)
|
|
696 |
{
|
|
697 |
return ReportError(err);
|
|
698 |
}
|
253
|
699 |
OstTraceFunctionExit1( RUSBTESTDEVICE_STOPEP0READING_EXIT, this );
|
0
|
700 |
}
|
|
701 |
|
|
702 |
|
|
703 |
void RUsbTestDevice::AcknowledgeRequestReceived()
|
|
704 |
{
|
253
|
705 |
OstTraceFunctionEntry1( RUSBTESTDEVICE_ACKNOWLEDGEREQUESTRECEIVED_ENTRY, this );
|
0
|
706 |
|
|
707 |
TInt err(iDeviceEp0->Reader().Acknowledge());
|
253
|
708 |
OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_ACKNOWLEDGEREQUESTRECEIVED, "err = %d",err);
|
0
|
709 |
if(err != KErrNone)
|
|
710 |
{
|
|
711 |
ReportError(err);
|
|
712 |
}
|
253
|
713 |
OstTraceFunctionExit1( RUSBTESTDEVICE_ACKNOWLEDGEREQUESTRECEIVED_EXIT, this );
|
0
|
714 |
}
|
|
715 |
|
|
716 |
|
|
717 |
|
|
718 |
void RUsbTestDevice::ReportError(TInt aCompletionCode)
|
|
719 |
{
|
253
|
720 |
OstTraceFunctionEntryExt( RUSBTESTDEVICE_REPORTERROR_ENTRY, this );
|
|
721 |
OstTraceExt3(TRACE_NORMAL, RUSBTESTDEVICE_REPORTERROR, "err or aCompletionCode = %d, observer status = %d, KRequestPending = %d",
|
0
|
722 |
aCompletionCode, iObserverStatus->Int(), KRequestPending);
|
|
723 |
if(*iObserverStatus == KRequestPending)
|
|
724 |
{
|
253
|
725 |
OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_REPORTERROR_DUP01, "In complete request");
|
0
|
726 |
User::RequestComplete(iObserverStatus,aCompletionCode);
|
|
727 |
}
|
253
|
728 |
OstTraceFunctionExit1( RUSBTESTDEVICE_REPORTERROR_EXIT, this );
|
0
|
729 |
}
|
|
730 |
|
|
731 |
|
|
732 |
}
|
|
733 |
|