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