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