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