35 iCurrentState(EUsbcDeviceStateUndefined), |
39 iCurrentState(EUsbcDeviceStateUndefined), |
36 iDeviceEp0(NULL), |
40 iDeviceEp0(NULL), |
37 iConnectTimer(NULL), iWakeupTimer(NULL), |
41 iConnectTimer(NULL), iWakeupTimer(NULL), |
38 iAuxBuffer(NULL) |
42 iAuxBuffer(NULL) |
39 { |
43 { |
|
44 OstTraceFunctionEntry1( RUSBTESTDEVICE_RUSBTESTDEVICE_ENTRY, this ); |
|
45 OstTraceFunctionExit1( RUSBTESTDEVICE_RUSBTESTDEVICE_EXIT, this ); |
40 } |
46 } |
41 |
47 |
42 RUsbTestDevice::RUsbTestDevice(CBaseTestCase* aTestCase) |
48 RUsbTestDevice::RUsbTestDevice(CBaseTestCase* aTestCase) |
43 : iStateWatcher(NULL), |
49 : iStateWatcher(NULL), |
44 iCurrentState(EUsbcDeviceStateUndefined), |
50 iCurrentState(EUsbcDeviceStateUndefined), |
45 iDeviceEp0(NULL), |
51 iDeviceEp0(NULL), |
46 iConnectTimer(NULL), iWakeupTimer(NULL), |
52 iConnectTimer(NULL), iWakeupTimer(NULL), |
47 iAuxBuffer(NULL) |
53 iAuxBuffer(NULL) |
48 { |
54 { |
49 LOG_FUNC |
55 OstTraceFunctionEntryExt( RUSBTESTDEVICE_RUSBTESTDEVICE_ENTRY_DUP01, this ); |
50 iTestCase = aTestCase; |
56 iTestCase = aTestCase; |
51 RDebug::Printf("iTestCase = %d", iTestCase); |
57 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_RUSBTESTDEVICE, "iTestCase = %d", iTestCase); |
|
58 OstTraceFunctionExit1( RUSBTESTDEVICE_RUSBTESTDEVICE_EXIT_DUP01, this ); |
52 } |
59 } |
53 |
60 |
54 void RUsbTestDevice::ResetState() |
61 void RUsbTestDevice::ResetState() |
55 { |
62 { |
|
63 OstTraceFunctionEntry1( RUSBTESTDEVICE_RESETSTATE_ENTRY, this ); |
56 iCurrentState = EUsbcDeviceStateUndefined; |
64 iCurrentState = EUsbcDeviceStateUndefined; |
|
65 OstTraceFunctionExit1( RUSBTESTDEVICE_RESETSTATE_EXIT, this ); |
57 } |
66 } |
58 |
67 |
59 RUsbTestDevice::~RUsbTestDevice() |
68 RUsbTestDevice::~RUsbTestDevice() |
60 { |
69 { |
61 LOG_FUNC |
70 OstTraceFunctionEntry1( RUSBTESTDEVICE_RUSBTESTDEVICE_ENTRY_DUP02, this ); |
62 |
71 |
|
72 OstTraceFunctionExit1( RUSBTESTDEVICE_RUSBTESTDEVICE_EXIT_DUP02, this ); |
63 } |
73 } |
64 |
74 |
65 void RUsbTestDevice::Close() |
75 void RUsbTestDevice::Close() |
66 { |
76 { |
67 LOG_FUNC |
77 OstTraceFunctionEntry1( RUSBTESTDEVICE_CLOSE_ENTRY, this ); |
68 |
78 |
69 delete iWakeupTimer; |
79 delete iWakeupTimer; |
70 delete iConnectTimer; |
80 delete iConnectTimer; |
71 delete iDeviceEp0; |
81 delete iDeviceEp0; |
72 delete iStateWatcher; |
82 delete iStateWatcher; |
83 static const TInt KWordOfDeathKey = 0x01066601; |
93 static const TInt KWordOfDeathKey = 0x01066601; |
84 static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy); |
94 static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy); |
85 TInt r = RProperty::Define(KWordOfDeathCat, KWordOfDeathKey, RProperty::EInt,KAllowAllPolicy, KAllowAllPolicy, 0); |
95 TInt r = RProperty::Define(KWordOfDeathCat, KWordOfDeathKey, RProperty::EInt,KAllowAllPolicy, KAllowAllPolicy, 0); |
86 if(r != KErrNone) |
96 if(r != KErrNone) |
87 { |
97 { |
88 RDebug::Print(_L("Could not create the WordOfDeath P&S (%d)"), r); |
98 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_CLOSE, "Could not create the WordOfDeath P&S (%d)", r); |
89 } |
99 } |
90 RDebug::Printf("killing t_usbhost_usbman.exe"); |
100 OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_CLOSE_DUP01, "killing t_usbhost_usbman.exe"); |
91 RProperty::Set(KWordOfDeathCat, KWordOfDeathKey, KErrAbort); // Send the word of death |
101 RProperty::Set(KWordOfDeathCat, KWordOfDeathKey, KErrAbort); // Send the word of death |
92 User::After(1000000); //allow time for t_usbhost_usbman.exe to clean up |
102 User::After(1000000); //allow time for t_usbhost_usbman.exe to clean up |
93 } |
103 } |
|
104 OstTraceFunctionExit1( RUSBTESTDEVICE_CLOSE_EXIT, this ); |
94 } |
105 } |
95 |
106 |
96 |
107 |
97 void RUsbTestDevice::SubscribeToReports(TRequestStatus& aObserverStatus) |
108 void RUsbTestDevice::SubscribeToReports(TRequestStatus& aObserverStatus) |
98 { |
109 { |
99 LOG_FUNC |
110 OstTraceFunctionEntryExt( RUSBTESTDEVICE_SUBSCRIBETOREPORTS_ENTRY, this ); |
100 |
111 |
101 // Signal the request as pending |
112 // Signal the request as pending |
102 |
113 |
103 iObserverStatus = &aObserverStatus; |
114 iObserverStatus = &aObserverStatus; |
104 *iObserverStatus = KRequestPending; |
115 *iObserverStatus = KRequestPending; |
|
116 OstTraceFunctionExit1( RUSBTESTDEVICE_SUBSCRIBETOREPORTS_EXIT, this ); |
105 } |
117 } |
106 |
118 |
107 |
119 |
108 void RUsbTestDevice::CancelSubscriptionToReports() |
120 void RUsbTestDevice::CancelSubscriptionToReports() |
109 { |
121 { |
110 LOG_FUNC |
122 OstTraceFunctionEntry1( RUSBTESTDEVICE_CANCELSUBSCRIPTIONTOREPORTS_ENTRY, this ); |
111 |
123 |
112 // Signal the request as cancelled |
124 // Signal the request as cancelled |
113 User::RequestComplete(iObserverStatus,KErrCancel); |
125 User::RequestComplete(iObserverStatus,KErrCancel); |
|
126 OstTraceFunctionExit1( RUSBTESTDEVICE_CANCELSUBSCRIPTIONTOREPORTS_EXIT, this ); |
114 } |
127 } |
115 |
128 |
116 |
129 |
117 void RUsbTestDevice::OpenL() |
130 void RUsbTestDevice::OpenL() |
118 { |
131 { |
119 LOG_FUNC |
132 OstTraceFunctionEntry1( RUSBTESTDEVICE_OPENL_ENTRY, this ); |
120 TInt err = KErrNone; |
133 TInt err = KErrNone; |
121 |
134 |
122 RDebug::Printf("starting t_usbhost_usbman.exe"); |
135 OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_OPENL, "starting t_usbhost_usbman.exe"); |
123 TInt r = iOtgUsbMan.Create(_L("t_usbhost_usbman.exe"), _L("client")); |
136 TInt r = iOtgUsbMan.Create(_L("t_usbhost_usbman.exe"), _L("client")); |
124 gtest(r == KErrNone); |
137 gtest(r == KErrNone); |
125 iOtgUsbMan.Resume(); |
138 iOtgUsbMan.Resume(); |
126 |
139 |
127 User::After(1500000); |
140 User::After(1500000); |
128 |
141 |
129 // Open channel to driver |
142 // Open channel to driver |
130 err = iClientDriver.Open(0); |
143 err = iClientDriver.Open(0); |
131 if(err != KErrNone) |
144 if(err != KErrNone) |
132 { |
145 { |
133 RDebug::Printf("<Error %d> Unable to open a channel to USB client driver",err); |
146 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP01, "<Error %d> Unable to open a channel to USB client driver",err); |
134 User::Leave(err); |
147 User::Leave(err); |
135 } |
148 } |
136 |
149 |
137 // Hide bus from host while interfaces are being set up |
150 // Hide bus from host while interfaces are being set up |
138 err = iClientDriver.DeviceDisconnectFromHost(); |
151 err = iClientDriver.DeviceDisconnectFromHost(); |
139 if(err != KErrNone) |
152 if(err != KErrNone) |
140 { |
153 { |
141 RDebug::Printf("<Error %d> unable to disconnect device from host",err); |
154 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP02, "<Error %d> unable to disconnect device from host",err); |
142 User::Leave(err); |
155 User::Leave(err); |
143 } |
156 } |
144 |
157 |
145 // Create the client usb state watcher |
158 // Create the client usb state watcher |
146 iStateWatcher = CUsbClientStateWatcher::NewL(iClientDriver,*this); |
159 iStateWatcher = CUsbClientStateWatcher::NewL(iClientDriver,*this); |
154 // Create the timer for remote wakeup events |
167 // Create the timer for remote wakeup events |
155 iWakeupTimer = CRemoteWakeupTimer::NewL(*this); |
168 iWakeupTimer = CRemoteWakeupTimer::NewL(*this); |
156 _LIT8(KYes, "yes"); |
169 _LIT8(KYes, "yes"); |
157 _LIT8(KNo, "no"); |
170 _LIT8(KNo, "no"); |
158 User::LeaveIfError(iClientDriver.DeviceCaps(iDeviceCaps)); |
171 User::LeaveIfError(iClientDriver.DeviceCaps(iDeviceCaps)); |
159 RDebug::Printf("------ USB device capabilities -------"); |
172 OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP03, "------ USB device capabilities -------"); |
160 RDebug::Printf("Number of endpoints: %d",iDeviceCaps().iTotalEndpoints); |
173 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP04, "Number of endpoints: %d",iDeviceCaps().iTotalEndpoints); |
161 RDebug::Printf("Supports Software-Connect: %S",iDeviceCaps().iConnect ? &KYes() : &KNo()); |
174 OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP05, "Supports Software-Connect: %s",iDeviceCaps().iConnect ? KYes() : KNo()); |
162 RDebug::Printf("Device is Self-Powered: %S",iDeviceCaps().iSelfPowered ? &KYes() : &KNo()); |
175 OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP06, "Device is Self-Powered: %S",iDeviceCaps().iSelfPowered ? KYes() : KNo()); |
163 RDebug::Printf("Supports Remote-Wakeup: %S",iDeviceCaps().iRemoteWakeup ? &KYes() : &KNo()); |
176 OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP07, "Supports Remote-Wakeup: %S",iDeviceCaps().iRemoteWakeup ? KYes() : KNo()); |
164 RDebug::Printf("Supports High-speed: %S",iDeviceCaps().iHighSpeed ? &KYes() : &KNo()); |
177 OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP08, "Supports High-speed: %S",iDeviceCaps().iHighSpeed ? KYes() : KNo()); |
165 RDebug::Printf("Supports unpowered cable detection: %S",(iDeviceCaps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower) ? &KYes() : &KNo()); |
178 OstTraceExt1(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP09, "Supports unpowered cable detection: %S",(iDeviceCaps().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower) ? KYes() : KNo()); |
166 RDebug::Printf("--------------------------------------"); |
179 OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_OPENL_DUP10, "--------------------------------------"); |
167 |
180 |
|
181 OstTraceFunctionExit1( RUSBTESTDEVICE_OPENL_EXIT, this ); |
168 } |
182 } |
169 |
183 |
170 |
184 |
171 TInt RUsbTestDevice::SetClassCode(TUint8 aClassCode,TUint8 aSubClassCode,TUint8 aDeviceProtocol) |
185 TInt RUsbTestDevice::SetClassCode(TUint8 aClassCode,TUint8 aSubClassCode,TUint8 aDeviceProtocol) |
172 { |
186 { |
173 LOG_FUNC |
187 OstTraceFunctionEntryExt( RUSBTESTDEVICE_SETCLASSCODE_ENTRY, this ); |
174 |
188 |
175 // Get Device descriptor |
189 // Get Device descriptor |
176 TBuf8<KUsbDescSize_Device> deviceDescriptor; |
190 TBuf8<KUsbDescSize_Device> deviceDescriptor; |
177 TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor)); |
191 TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor)); |
178 if(err != KErrNone) |
192 if(err != KErrNone) |
179 { |
193 { |
180 RDebug::Printf("<Error %d> Unable to obtain device descriptor",err); |
194 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETCLASSCODE, "<Error %d> Unable to obtain device descriptor",err); |
181 } |
195 } |
182 else |
196 else |
183 { |
197 { |
184 deviceDescriptor[KDevDescOffset_bDeviceClass] = aClassCode; |
198 deviceDescriptor[KDevDescOffset_bDeviceClass] = aClassCode; |
185 deviceDescriptor[KDevDescOffset_bDeviceSubClass] = aSubClassCode; |
199 deviceDescriptor[KDevDescOffset_bDeviceSubClass] = aSubClassCode; |
186 deviceDescriptor[KDevDescOffset_bDeviceProtocol] = aDeviceProtocol; |
200 deviceDescriptor[KDevDescOffset_bDeviceProtocol] = aDeviceProtocol; |
187 |
201 |
188 err = iClientDriver.SetDeviceDescriptor(deviceDescriptor); |
202 err = iClientDriver.SetDeviceDescriptor(deviceDescriptor); |
189 if(err != KErrNone) |
203 if(err != KErrNone) |
190 { |
204 { |
191 RDebug::Printf("<Error %d> Unable to set the device dsecriptor",err); |
205 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETCLASSCODE_DUP01, "<Error %d> Unable to set the device dsecriptor",err); |
192 } |
206 } |
193 } |
207 } |
|
208 OstTraceFunctionExitExt( RUSBTESTDEVICE_SETCLASSCODE_EXIT, this, err ); |
194 return err; |
209 return err; |
195 } |
210 } |
196 |
211 |
197 |
212 |
198 TInt RUsbTestDevice::SetUsbSpecification(TUint16 aSpecification) |
213 TInt RUsbTestDevice::SetUsbSpecification(TUint16 aSpecification) |
199 { |
214 { |
200 LOG_FUNC |
215 OstTraceFunctionEntryExt( RUSBTESTDEVICE_SETUSBSPECIFICATION_ENTRY, this ); |
201 |
216 |
202 // Get Device descriptor |
217 // Get Device descriptor |
203 TBuf8<KUsbDescSize_Device> deviceDescriptor; |
218 TBuf8<KUsbDescSize_Device> deviceDescriptor; |
204 TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor)); |
219 TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor)); |
205 if(err != KErrNone) |
220 if(err != KErrNone) |
206 { |
221 { |
207 RDebug::Printf("<Error %d> Unable to obtain device descriptor",err); |
222 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETUSBSPECIFICATION, "<Error %d> Unable to obtain device descriptor",err); |
208 } |
223 } |
209 else |
224 else |
210 { |
225 { |
211 // Set bcdUSB |
226 // Set bcdUSB |
212 TUint8* p = reinterpret_cast<TUint8*>(&aSpecification); |
227 TUint8* p = reinterpret_cast<TUint8*>(&aSpecification); |
247 deviceDescriptor[KDevDescOffset_idVendor+1] = *(p+1); |
263 deviceDescriptor[KDevDescOffset_idVendor+1] = *(p+1); |
248 |
264 |
249 err = iClientDriver.SetDeviceDescriptor(deviceDescriptor); |
265 err = iClientDriver.SetDeviceDescriptor(deviceDescriptor); |
250 if(err != KErrNone) |
266 if(err != KErrNone) |
251 { |
267 { |
252 RDebug::Printf("<Error %d> Unable to set the device descriptor",err); |
268 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETVENDOR_DUP01, "<Error %d> Unable to set the device descriptor",err); |
253 } |
269 } |
254 } |
270 } |
|
271 OstTraceFunctionExitExt( RUSBTESTDEVICE_SETVENDOR_EXIT, this, err ); |
255 return err; |
272 return err; |
256 } |
273 } |
257 |
274 |
258 |
275 |
259 TInt RUsbTestDevice::SetProduct(TUint16 aProductId,const TDesC16& aProductString, |
276 TInt RUsbTestDevice::SetProduct(TUint16 aProductId,const TDesC16& aProductString, |
260 const TDesC16& aManufacturerString,const TDesC16& aSerialNumberString) |
277 const TDesC16& aManufacturerString,const TDesC16& aSerialNumberString) |
261 { |
278 { |
262 LOG_FUNC |
279 OstTraceFunctionEntryExt( RUSBTESTDEVICE_SETPRODUCT_ENTRY, this ); |
263 |
280 |
264 // Get Device descriptor |
281 // Get Device descriptor |
265 TBuf8<KUsbDescSize_Device> deviceDescriptor; |
282 TBuf8<KUsbDescSize_Device> deviceDescriptor; |
266 TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor)); |
283 TInt err(iClientDriver.GetDeviceDescriptor(deviceDescriptor)); |
267 if(err != KErrNone) |
284 if(err != KErrNone) |
268 { |
285 { |
269 RDebug::Printf("<Error %d> Unable to obtain device descriptor",err); |
286 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT, "<Error %d> Unable to obtain device descriptor",err); |
270 } |
287 } |
271 else |
288 else |
272 { |
289 { |
273 // Set PID |
290 // Set PID |
274 TUint8* p = reinterpret_cast<TUint8*>(&aProductId); |
291 TUint8* p = reinterpret_cast<TUint8*>(&aProductId); |
276 deviceDescriptor[KDevDescOffset_idProduct+1] = *(p+1); |
293 deviceDescriptor[KDevDescOffset_idProduct+1] = *(p+1); |
277 |
294 |
278 err = iClientDriver.SetDeviceDescriptor(deviceDescriptor); |
295 err = iClientDriver.SetDeviceDescriptor(deviceDescriptor); |
279 if(err != KErrNone) |
296 if(err != KErrNone) |
280 { |
297 { |
281 RDebug::Printf("<Error %d> Unable to set the device dsecriptor",err); |
298 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT_DUP01, "<Error %d> Unable to set the device dsecriptor",err); |
|
299 OstTraceFunctionExitExt( RUSBTESTDEVICE_SETPRODUCT_EXIT, this, err ); |
282 return err; |
300 return err; |
283 } |
301 } |
284 |
302 |
285 RDebug::Printf("Product Identity set"); |
303 OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT_DUP02, "Product Identity set"); |
286 |
304 |
287 // Product string |
305 // Product string |
288 err = iClientDriver.SetProductStringDescriptor(aProductString); |
306 err = iClientDriver.SetProductStringDescriptor(aProductString); |
289 if(err != KErrNone) |
307 if(err != KErrNone) |
290 { |
308 { |
291 RDebug::Printf("<Error %d> Unable to set product string descriptor",err); |
309 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETPRODUCT_DUP03, "<Error %d> Unable to set product string descriptor",err); |
|
310 OstTraceFunctionExitExt( RUSBTESTDEVICE_SETPRODUCT_EXIT_DUP01, this, err ); |
292 return err; |
311 return err; |
293 } |
312 } |
294 |
313 |
295 // Manufacturer string |
314 // Manufacturer string |
296 err = iClientDriver.SetManufacturerStringDescriptor(aManufacturerString); |
315 err = iClientDriver.SetManufacturerStringDescriptor(aManufacturerString); |
297 if(err != KErrNone) |
316 if(err != KErrNone) |
298 { |
317 { |
299 RDebug::Printf("<Error %d> Unable to set the manufacturer string descriptor",err); |
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 ); |
300 return err; |
320 return err; |
301 } |
321 } |
302 |
322 |
303 // Serial number string |
323 // Serial number string |
304 err = iClientDriver.SetSerialNumberStringDescriptor(aSerialNumberString); |
324 err = iClientDriver.SetSerialNumberStringDescriptor(aSerialNumberString); |
305 if(err != KErrNone) |
325 if(err != KErrNone) |
306 { |
326 { |
307 RDebug::Printf("<Error %d> Unable to set the serial number string descriptor",err); |
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 ); |
308 return err; |
329 return err; |
309 } |
330 } |
310 } |
331 } |
|
332 OstTraceFunctionExitExt( RUSBTESTDEVICE_SETPRODUCT_EXIT_DUP04, this, KErrNone ); |
311 return KErrNone; |
333 return KErrNone; |
312 } |
334 } |
313 |
335 |
314 |
336 |
315 TInt RUsbTestDevice::SetConfigurationString(const TDesC16& aConfigString) |
337 TInt RUsbTestDevice::SetConfigurationString(const TDesC16& aConfigString) |
316 { |
338 { |
317 LOG_FUNC |
339 OstTraceFunctionEntryExt( RUSBTESTDEVICE_SETCONFIGURATIONSTRING_ENTRY, this ); |
318 |
340 |
319 TInt err(iClientDriver.SetConfigurationStringDescriptor(aConfigString)); |
341 TInt err(iClientDriver.SetConfigurationStringDescriptor(aConfigString)); |
320 if(err != KErrNone) |
342 if(err != KErrNone) |
321 { |
343 { |
322 RDebug::Printf("<Error %d> Unable to set configuration string descriptor",err); |
344 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SETCONFIGURATIONSTRING, "<Error %d> Unable to set configuration string descriptor",err); |
323 } |
345 } |
|
346 OstTraceFunctionExitExt( RUSBTESTDEVICE_SETCONFIGURATIONSTRING_EXIT, this, err ); |
324 return err; |
347 return err; |
325 } |
348 } |
326 |
349 |
327 |
350 |
328 void RUsbTestDevice::AddInterface(CInterfaceBase* aInterface) |
351 void RUsbTestDevice::AddInterface(CInterfaceBase* aInterface) |
329 { |
352 { |
330 LOG_FUNC |
353 OstTraceFunctionEntryExt( RUSBTESTDEVICE_ADDINTERFACE_ENTRY, this ); |
331 |
354 |
332 // Add the interface to the device |
355 // Add the interface to the device |
333 TInt err = iInterfaces.Append(aInterface); |
356 TInt err = iInterfaces.Append(aInterface); |
334 |
357 |
335 if(err != KErrNone) |
358 if(err != KErrNone) |
336 { |
359 { |
337 RDebug::Printf("<Error %d> Unable to add interface",err); |
360 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_ADDINTERFACE, "<Error %d> Unable to add interface",err); |
338 return ReportError(err); |
361 return ReportError(err); |
339 } |
362 } |
|
363 OstTraceFunctionExit1( RUSBTESTDEVICE_ADDINTERFACE_EXIT, this ); |
340 } |
364 } |
341 |
365 |
342 |
366 |
343 CInterfaceBase& RUsbTestDevice::Interface(TInt aIndex) |
367 CInterfaceBase& RUsbTestDevice::Interface(TInt aIndex) |
344 { |
368 { |
|
369 OstTraceFunctionEntryExt( RUSBTESTDEVICE_INTERFACE_ENTRY, this ); |
|
370 OstTraceFunctionExit1( RUSBTESTDEVICE_INTERFACE_EXIT, this ); |
345 return *iInterfaces[aIndex]; |
371 return *iInterfaces[aIndex]; |
346 } |
372 } |
347 |
373 |
348 |
374 |
349 void RUsbTestDevice::SoftwareConnect() |
375 void RUsbTestDevice::SoftwareConnect() |
350 { |
376 { |
351 LOG_FUNC |
377 OstTraceFunctionEntry1( RUSBTESTDEVICE_SOFTWARECONNECT_ENTRY, this ); |
352 TInt err(iClientDriver.PowerUpUdc()); |
378 TInt err(iClientDriver.PowerUpUdc()); |
353 if((err != KErrNone) && (err != KErrNotReady)) |
379 if((err != KErrNone) && (err != KErrNotReady)) |
354 { |
380 { |
355 RDebug::Printf("<Error %d> Power Up Udc",err); |
381 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWARECONNECT, "<Error %d> Power Up Udc",err); |
356 ReportError(err); |
382 ReportError(err); |
357 } |
383 } |
358 |
384 |
359 if(iDeviceCaps().iConnect) |
385 if(iDeviceCaps().iConnect) |
360 { |
386 { |
361 err = iClientDriver.DeviceConnectToHost(); |
387 err = iClientDriver.DeviceConnectToHost(); |
362 if(err != KErrNone) |
388 if(err != KErrNone) |
363 { |
389 { |
364 RDebug::Printf("<Error %d> Unable to connect to the host",err); |
390 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWARECONNECT_DUP01, "<Error %d> Unable to connect to the host",err); |
365 ReportError(err); |
391 ReportError(err); |
366 } |
392 } |
367 } |
393 } |
368 else |
394 else |
369 { |
395 { |
370 RDebug::Printf("Please connect device to Host"); |
396 OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWARECONNECT_DUP02, "Please connect device to Host"); |
371 } |
397 } |
|
398 OstTraceFunctionExit1( RUSBTESTDEVICE_SOFTWARECONNECT_EXIT, this ); |
372 } |
399 } |
373 |
400 |
374 void RUsbTestDevice::SoftwareDisconnect() |
401 void RUsbTestDevice::SoftwareDisconnect() |
375 { |
402 { |
376 LOG_FUNC |
403 OstTraceFunctionEntry1( RUSBTESTDEVICE_SOFTWAREDISCONNECT_ENTRY, this ); |
377 |
404 |
378 if(iDeviceCaps().iConnect) |
405 if(iDeviceCaps().iConnect) |
379 { |
406 { |
380 TInt err(iClientDriver.DeviceDisconnectFromHost()); |
407 TInt err(iClientDriver.DeviceDisconnectFromHost()); |
381 if(err != KErrNone) |
408 if(err != KErrNone) |
382 { |
409 { |
383 RDebug::Printf("<Error %d> Unable to disconnect from the host",err); |
410 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWAREDISCONNECT, "<Error %d> Unable to disconnect from the host",err); |
384 ReportError(err); |
411 ReportError(err); |
385 } |
412 } |
386 } |
413 } |
387 else |
414 else |
388 { |
415 { |
389 RDebug::Printf("Please disconnect device from Host"); |
416 OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_SOFTWAREDISCONNECT_DUP01, "Please disconnect device from Host"); |
390 } |
417 } |
391 |
418 |
|
419 OstTraceFunctionExit1( RUSBTESTDEVICE_SOFTWAREDISCONNECT_EXIT, this ); |
392 } |
420 } |
393 |
421 |
394 |
422 |
395 void RUsbTestDevice::RemoteWakeup() |
423 void RUsbTestDevice::RemoteWakeup() |
396 { |
424 { |
397 LOG_FUNC |
425 OstTraceFunctionEntry1( RUSBTESTDEVICE_REMOTEWAKEUP_ENTRY, this ); |
398 if(iDeviceCaps().iConnect) |
426 if(iDeviceCaps().iConnect) |
399 { |
427 { |
400 TInt err(iClientDriver.SignalRemoteWakeup()); |
428 TInt err(iClientDriver.SignalRemoteWakeup()); |
401 if(err != KErrNone) |
429 if(err != KErrNone) |
402 { |
430 { |
403 RDebug::Printf("<Error %d> Unable to perform a remote wakeup",err); |
431 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_REMOTEWAKEUP, "<Error %d> Unable to perform a remote wakeup",err); |
404 ReportError(err); |
432 ReportError(err); |
405 } |
433 } |
406 } |
434 } |
407 else |
435 else |
408 { |
436 { |
409 RDebug::Printf("remote wakeup not supported"); |
437 OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_REMOTEWAKEUP_DUP01, "remote wakeup not supported"); |
410 } |
438 } |
|
439 OstTraceFunctionExit1( RUSBTESTDEVICE_REMOTEWAKEUP_EXIT, this ); |
411 } |
440 } |
412 |
441 |
413 |
442 |
414 TInt RUsbTestDevice::ProcessRequestL(TUint8 aRequest,TUint16 aValue,TUint16 aIndex, |
443 TInt RUsbTestDevice::ProcessRequestL(TUint8 aRequest,TUint16 aValue,TUint16 aIndex, |
415 TUint16 aDataReqLength,const TDesC8& aPayload) |
444 TUint16 aDataReqLength,const TDesC8& aPayload) |
416 { |
445 { |
417 LOG_FUNC |
446 OstTraceFunctionEntryExt( RUSBTESTDEVICE_PROCESSREQUESTL_ENTRY, this ); |
418 |
447 |
419 if(aRequest == KVendorEmptyRequest) |
448 if(aRequest == KVendorEmptyRequest) |
420 { |
449 { |
421 // Handle an empty request (i.e. do nothing) |
450 // Handle an empty request (i.e. do nothing) |
422 |
451 |
502 else if(aRequest == KVendorPutPayloadRequest) |
533 else if(aRequest == KVendorPutPayloadRequest) |
503 { |
534 { |
504 // Handle a payload request from the host |
535 // Handle a payload request from the host |
505 |
536 |
506 AcknowledgeRequestReceived(); |
537 AcknowledgeRequestReceived(); |
507 RDebug::Printf("Put payload"); |
538 OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP03, "Put payload"); |
508 if(aPayload.Compare(_L8("DEADBEEF")) != 0) |
539 if(aPayload.Compare(_L8("DEADBEEF")) != 0) |
509 { |
540 { |
510 RDebug::Printf("<Error %d> Payload not as expected",KErrCorrupt); |
541 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP04, "<Error %d> Payload not as expected",KErrCorrupt); |
511 ReportError(KErrCorrupt); |
542 ReportError(KErrCorrupt); |
512 } |
543 } |
513 } |
544 } |
514 else if(aRequest == KVendorGetPayloadRequest) |
545 else if(aRequest == KVendorGetPayloadRequest) |
515 { |
546 { |
516 // Handle a payload request to the host |
547 // Handle a payload request to the host |
517 |
548 |
518 RDebug::Printf("Get payload"); |
549 OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP05, "Get payload"); |
519 __ASSERT_DEBUG(iAuxBuffer, User::Panic(_L("Trying to write non-allocated buffer"), KErrGeneral)); |
550 __ASSERT_DEBUG(iAuxBuffer, User::Panic(_L("Trying to write non-allocated buffer"), KErrGeneral)); |
520 RDebug::Printf("iAuxBuffer = ...."); |
551 OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP06, "iAuxBuffer = ...."); |
521 RDebug::RawPrint(*iAuxBuffer); |
552 OstTraceData(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP56, "", iAuxBuffer->Ptr(), iAuxBuffer->Length()); |
522 RDebug::Printf("\n"); |
553 OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP07, "\n"); |
523 |
554 |
524 //Perform synchronous write to EP0 |
555 //Perform synchronous write to EP0 |
525 //This allows the subsequent 'Read' request to |
556 //This allows the subsequent 'Read' request to |
526 //take place |
557 //take place |
527 TInt ret = iDeviceEp0->SendDataSynchronous(*iAuxBuffer); |
558 TInt ret = iDeviceEp0->SendDataSynchronous(*iAuxBuffer); |
528 RDebug::Printf("Write (from device callback) executed with error %d", ret); |
559 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP08, "Write (from device callback) executed with error %d", ret); |
529 } |
560 } |
530 else if(aRequest == KVendorUnrespondRequest) |
561 else if(aRequest == KVendorUnrespondRequest) |
531 { |
562 { |
532 // Do not acknowledge this request |
563 // Do not acknowledge this request |
533 |
564 |
534 RDebug::Printf("Unrespond request: continually NAK the host"); |
565 OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP09, "Unrespond request: continually NAK the host"); |
535 } |
566 } |
536 else if(aRequest == KVendorStallRequest) |
567 else if(aRequest == KVendorStallRequest) |
537 { |
568 { |
538 // Stall the specified endpoint |
569 // Stall the specified endpoint |
539 |
570 |
540 AcknowledgeRequestReceived(); |
571 AcknowledgeRequestReceived(); |
541 RDebug::Printf("Stalling endpoint %d",aValue); |
572 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_PROCESSREQUESTL_DUP10, "Stalling endpoint %d",aValue); |
542 |
573 |
543 } |
574 } |
544 else |
575 else |
545 { |
576 { |
546 // Maybe forward to derived classes |
577 // Maybe forward to derived classes |
547 } |
578 } |
|
579 OstTraceFunctionExitExt( RUSBTESTDEVICE_PROCESSREQUESTL_EXIT_DUP02, this, KErrNone ); |
548 return KErrNone; |
580 return KErrNone; |
549 } |
581 } |
550 |
582 |
551 |
583 |
552 void RUsbTestDevice::StateChangeL(TUsbcDeviceState aNewState,TInt aChangeCompletionCode) |
584 void RUsbTestDevice::StateChangeL(TUsbcDeviceState aNewState,TInt aChangeCompletionCode) |
553 { |
585 { |
554 LOG_FUNC |
586 OstTraceFunctionEntryExt( RUSBTESTDEVICE_STATECHANGEL_ENTRY, this ); |
555 |
587 |
556 RDebug::Printf("Client state change to %d err=%d",aNewState,aChangeCompletionCode); |
588 OstTraceExt2(TRACE_NORMAL, RUSBTESTDEVICE_STATECHANGEL, "Client state change to %d err=%d",aNewState,aChangeCompletionCode); |
557 |
589 |
558 // Notify the test case of failed state change notification |
590 // Notify the test case of failed state change notification |
559 |
591 |
560 if(aChangeCompletionCode != KErrNone) |
592 if(aChangeCompletionCode != KErrNone) |
561 { |
593 { |
660 TInt err(iDeviceEp0->Stop()); |
694 TInt err(iDeviceEp0->Stop()); |
661 if(err != KErrNone) |
695 if(err != KErrNone) |
662 { |
696 { |
663 return ReportError(err); |
697 return ReportError(err); |
664 } |
698 } |
|
699 OstTraceFunctionExit1( RUSBTESTDEVICE_STOPEP0READING_EXIT, this ); |
665 } |
700 } |
666 |
701 |
667 |
702 |
668 void RUsbTestDevice::AcknowledgeRequestReceived() |
703 void RUsbTestDevice::AcknowledgeRequestReceived() |
669 { |
704 { |
670 LOG_FUNC |
705 OstTraceFunctionEntry1( RUSBTESTDEVICE_ACKNOWLEDGEREQUESTRECEIVED_ENTRY, this ); |
671 |
706 |
672 TInt err(iDeviceEp0->Reader().Acknowledge()); |
707 TInt err(iDeviceEp0->Reader().Acknowledge()); |
673 RDebug::Printf("err = %d",err); |
708 OstTrace1(TRACE_NORMAL, RUSBTESTDEVICE_ACKNOWLEDGEREQUESTRECEIVED, "err = %d",err); |
674 if(err != KErrNone) |
709 if(err != KErrNone) |
675 { |
710 { |
676 ReportError(err); |
711 ReportError(err); |
677 } |
712 } |
|
713 OstTraceFunctionExit1( RUSBTESTDEVICE_ACKNOWLEDGEREQUESTRECEIVED_EXIT, this ); |
678 } |
714 } |
679 |
715 |
680 |
716 |
681 |
717 |
682 void RUsbTestDevice::ReportError(TInt aCompletionCode) |
718 void RUsbTestDevice::ReportError(TInt aCompletionCode) |
683 { |
719 { |
684 LOG_FUNC |
720 OstTraceFunctionEntryExt( RUSBTESTDEVICE_REPORTERROR_ENTRY, this ); |
685 RDebug::Printf("err or aCompletionCode = %d, observer status = %d, KRequestPending = %d", |
721 OstTraceExt3(TRACE_NORMAL, RUSBTESTDEVICE_REPORTERROR, "err or aCompletionCode = %d, observer status = %d, KRequestPending = %d", |
686 aCompletionCode, iObserverStatus->Int(), KRequestPending); |
722 aCompletionCode, iObserverStatus->Int(), KRequestPending); |
687 if(*iObserverStatus == KRequestPending) |
723 if(*iObserverStatus == KRequestPending) |
688 { |
724 { |
689 RDebug::Printf("In complete request"); |
725 OstTrace0(TRACE_NORMAL, RUSBTESTDEVICE_REPORTERROR_DUP01, "In complete request"); |
690 User::RequestComplete(iObserverStatus,aCompletionCode); |
726 User::RequestComplete(iObserverStatus,aCompletionCode); |
691 } |
727 } |
692 } |
728 OstTraceFunctionExit1( RUSBTESTDEVICE_REPORTERROR_EXIT, this ); |
693 |
729 } |
694 |
730 |
695 } |
731 |
696 |
732 } |
|
733 |