|
1 /* |
|
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "fdftest.h" |
|
19 #include "testmanager.h" |
|
20 #include <usb/usblogger.h> |
|
21 #include <e32cmn.h> |
|
22 |
|
23 #include <d32usbdi_hubdriver.h> |
|
24 |
|
25 #ifdef __FLOG_ACTIVE |
|
26 _LIT8(KLogComponent, "fdftest "); |
|
27 #endif |
|
28 //-------------------------------- |
|
29 |
|
30 CActiveNotifyDeviceEvent::CActiveNotifyDeviceEvent(RUsbHostStack& aUsbHostStack, |
|
31 MNotifyDeviceEventObserver& aObserver, |
|
32 TDeviceEventInformation& aDeviceEventInformation) |
|
33 : CActive(CActive::EPriorityStandard), |
|
34 iUsbHostStack(aUsbHostStack), |
|
35 iObserver(aObserver), |
|
36 iDeviceEventInformation(aDeviceEventInformation) |
|
37 { |
|
38 CActiveScheduler::Add(this); |
|
39 } |
|
40 |
|
41 CActiveNotifyDeviceEvent::~CActiveNotifyDeviceEvent() |
|
42 { |
|
43 Cancel(); |
|
44 } |
|
45 |
|
46 CActiveNotifyDeviceEvent* CActiveNotifyDeviceEvent::NewL(RUsbHostStack& aUsbHostStack, |
|
47 MNotifyDeviceEventObserver& aObserver, |
|
48 TDeviceEventInformation& aDeviceEventInformation) |
|
49 { |
|
50 CActiveNotifyDeviceEvent* self = new(ELeave) CActiveNotifyDeviceEvent(aUsbHostStack, |
|
51 aObserver, |
|
52 aDeviceEventInformation); |
|
53 return self; |
|
54 } |
|
55 |
|
56 void CActiveNotifyDeviceEvent::Post() |
|
57 { |
|
58 iUsbHostStack.NotifyDeviceEvent(iStatus, iDeviceEventInformation); |
|
59 SetActive(); |
|
60 } |
|
61 |
|
62 void CActiveNotifyDeviceEvent::RunL() |
|
63 { |
|
64 iObserver.MndeoDeviceEvent(); |
|
65 |
|
66 // We don't want to get into an infinite loop if the FDF dies. |
|
67 if ( iStatus.Int() != KErrServerTerminated ) |
|
68 { |
|
69 Post(); |
|
70 } |
|
71 } |
|
72 |
|
73 void CActiveNotifyDeviceEvent::DoCancel() |
|
74 { |
|
75 iUsbHostStack.NotifyDeviceEventCancel(); |
|
76 } |
|
77 |
|
78 //-------------------------------- |
|
79 |
|
80 CActiveNotifyDevmonEvent::CActiveNotifyDevmonEvent(RUsbHostStack& aUsbHostStack, |
|
81 MNotifyDevmonEventObserver& aObserver, |
|
82 TInt& aEvent) |
|
83 : CActive(CActive::EPriorityStandard), |
|
84 iUsbHostStack(aUsbHostStack), |
|
85 iObserver(aObserver), |
|
86 iEvent(aEvent) |
|
87 { |
|
88 CActiveScheduler::Add(this); |
|
89 } |
|
90 |
|
91 CActiveNotifyDevmonEvent::~CActiveNotifyDevmonEvent() |
|
92 { |
|
93 Cancel(); |
|
94 } |
|
95 |
|
96 CActiveNotifyDevmonEvent* CActiveNotifyDevmonEvent::NewL(RUsbHostStack& aUsbHostStack, |
|
97 MNotifyDevmonEventObserver& aObserver, |
|
98 TInt& aEvent) |
|
99 { |
|
100 CActiveNotifyDevmonEvent* self = new(ELeave) CActiveNotifyDevmonEvent(aUsbHostStack, |
|
101 aObserver, |
|
102 aEvent); |
|
103 return self; |
|
104 } |
|
105 |
|
106 void CActiveNotifyDevmonEvent::Post() |
|
107 { |
|
108 iUsbHostStack.NotifyDevmonEvent(iStatus, iEvent); |
|
109 SetActive(); |
|
110 } |
|
111 |
|
112 void CActiveNotifyDevmonEvent::RunL() |
|
113 { |
|
114 iObserver.MndeoDevmonEvent(); |
|
115 |
|
116 // We don't want to get into an infinite loop if the FDF dies. |
|
117 if ( iStatus.Int() != KErrServerTerminated ) |
|
118 { |
|
119 Post(); |
|
120 } |
|
121 } |
|
122 |
|
123 void CActiveNotifyDevmonEvent::DoCancel() |
|
124 { |
|
125 iUsbHostStack.NotifyDevmonEventCancel(); |
|
126 } |
|
127 |
|
128 //-------------------------------- |
|
129 |
|
130 CFdfTest::CFdfTest(MTestManager& aManager) |
|
131 : CTestBase(aManager) |
|
132 { |
|
133 } |
|
134 |
|
135 CTestBase* CFdfTest::NewL(MTestManager& aManager) |
|
136 { |
|
137 CFdfTest* self = new(ELeave) CFdfTest(aManager); |
|
138 CleanupStack::PushL(self); |
|
139 self->ConstructL(); |
|
140 CleanupStack::Pop(self); |
|
141 return self; |
|
142 } |
|
143 |
|
144 void CFdfTest::ConstructL() |
|
145 { |
|
146 iNotifyDeviceEvent = CActiveNotifyDeviceEvent::NewL(iUsbHostStack, |
|
147 *this, |
|
148 iDeviceEventInformation); |
|
149 iNotifyDevmonEvent = CActiveNotifyDevmonEvent::NewL(iUsbHostStack, |
|
150 *this, |
|
151 iDevmonEvent); |
|
152 } |
|
153 |
|
154 CFdfTest::~CFdfTest() |
|
155 { |
|
156 iManager.Write(_L8("CFdfTest::~CFdfTest")); |
|
157 |
|
158 delete iNotifyDeviceEvent; |
|
159 delete iNotifyDevmonEvent; |
|
160 iOtgDriver.Close(); |
|
161 iUsbHostStack.Close(); |
|
162 } |
|
163 |
|
164 void CFdfTest::ProcessKeyL(TKeyCode aKeyCode) |
|
165 { |
|
166 iManager.Write(_L8("CFdfTest::ProcessKeyL")); |
|
167 |
|
168 switch ( aKeyCode ) |
|
169 { |
|
170 case '0': |
|
171 { |
|
172 if ( iUsbHostStack.Handle() ) |
|
173 { |
|
174 iManager.Write(_L8("\talready connected")); |
|
175 } |
|
176 else |
|
177 { |
|
178 |
|
179 iManager.Write(_L8("About to open LDD")); |
|
180 _LIT(KUsbOtgLDDName,"otgdi"); |
|
181 TInt err = User::LoadLogicalDevice(KUsbOtgLDDName); |
|
182 if ( (err != KErrNone) && (err != KErrAlreadyExists) ) |
|
183 { |
|
184 iManager.Write(_L8("Error %d: Unable to load driver: %S"), err, &KUsbOtgLDDName); |
|
185 LEAVEIFERRORL(err); |
|
186 } |
|
187 |
|
188 iManager.Write(_L8("About to open RUsbOtgDriver")); |
|
189 err = iOtgDriver.Open(); |
|
190 if (err != KErrNone && err != KErrAlreadyExists) |
|
191 { |
|
192 iManager.Write(_L8("Error %d: Unable to open RUsbOtgDriver session"), err); |
|
193 LEAVEIFERRORL(err); |
|
194 } |
|
195 |
|
196 iManager.Write(_L8("About to start OTG stacks")); |
|
197 TInt iLastError = iOtgDriver.StartStacks(); |
|
198 if (iLastError != KErrNone) |
|
199 { |
|
200 iManager.Write(_L8("Error %d: Unable to open start OTG stacks"), iLastError); |
|
201 LEAVEIFERRORL(err); |
|
202 } |
|
203 |
|
204 TInt errorBus = iOtgDriver.BusRequest(); |
|
205 iManager.Write(_L8("Error %d: iOtgDriver.BusRequest()"), errorBus); |
|
206 if (errorBus == KErrNone) |
|
207 { |
|
208 iBusRequested = 1; |
|
209 } |
|
210 |
|
211 |
|
212 TInt error = iUsbHostStack.Connect(); |
|
213 iManager.Write(_L8("\terror = %d"), error); |
|
214 if ( !error ) |
|
215 { |
|
216 iManager.Write(_L8("\t Post() to wait for event ")); |
|
217 iNotifyDeviceEvent->Post(); |
|
218 iNotifyDevmonEvent->Post(); |
|
219 iManager.Write(_L8("\t After Post() to wait for event ")); |
|
220 } |
|
221 } |
|
222 } |
|
223 break; |
|
224 |
|
225 case '1': |
|
226 { |
|
227 TInt err = iUsbHostStack.EnableDriverLoading(); |
|
228 iManager.Write(_L8("\terr = %d"), err); |
|
229 } |
|
230 break; |
|
231 |
|
232 case '2': |
|
233 iUsbHostStack.DisableDriverLoading(); |
|
234 break; |
|
235 |
|
236 case '3': |
|
237 iNotifyDeviceEvent->Cancel(); |
|
238 iNotifyDevmonEvent->Cancel(); |
|
239 iUsbHostStack.Close(); |
|
240 break; |
|
241 case '4': |
|
242 if(iBusRequested) |
|
243 { |
|
244 iManager.Write(_L8("Call BusDrop()")); |
|
245 TInt err = iOtgDriver.BusDrop(); |
|
246 iManager.Write(_L8("Call BusDrop() err = %d "),err); |
|
247 } |
|
248 else |
|
249 { |
|
250 iManager.Write(_L8("Cannot Call BusDrop() as the bus has not been Requested()")); |
|
251 } |
|
252 break; |
|
253 |
|
254 default: |
|
255 iManager.Write(_L8("Unknown selection")); |
|
256 break; |
|
257 } |
|
258 } |
|
259 |
|
260 void CFdfTest::DisplayTestSpecificMenu() |
|
261 { |
|
262 iManager.Write(_L8("0 - RUsbHostStack::Connect")); |
|
263 iManager.Write(_L8("1 - RUsbHostStack::EnableDriverLoading")); |
|
264 iManager.Write(_L8("2 - RUsbHostStack::DisableDriverLoading")); |
|
265 iManager.Write(_L8("3 - RUsbHostStack::Close")); |
|
266 iManager.Write(_L8("4 - RUsbHostStack::StopBus")); |
|
267 |
|
268 } |
|
269 |
|
270 void CFdfTest::MndeoDeviceEvent() |
|
271 { |
|
272 iManager.Write(_L8("CFdfTest::MndeoDeviceEvent")); |
|
273 iManager.Write(KNullDesC8()); |
|
274 iManager.Write(_L8("CFdfTest::MndeoDeviceEvent")); |
|
275 |
|
276 // Apologies for the squashed-up output this gives, but this text is no |
|
277 // good if it scrolls off the top of the target board's screen. |
|
278 iManager.Write(_L8("Raw data:")); |
|
279 iManager.Write(_L8("device ID = %d, event type = %d, error = %d, driver load status = %d, vid = 0x%04x, pid = 0x%04x"), |
|
280 iDeviceEventInformation.iDeviceId, |
|
281 iDeviceEventInformation.iEventType, |
|
282 iDeviceEventInformation.iError, |
|
283 iDeviceEventInformation.iDriverLoadStatus, |
|
284 iDeviceEventInformation.iVid, |
|
285 iDeviceEventInformation.iPid); |
|
286 |
|
287 iManager.Write(_L8("Interpretation:")); |
|
288 |
|
289 _LIT8(KAttachment, "Attachment"); |
|
290 _LIT8(KDriverLoad, "Driver load"); |
|
291 _LIT8(KDetachment, "Detachment"); |
|
292 TFixedArray<const TDesC8*, 3> eventType; |
|
293 eventType[EDeviceAttachment] = &KAttachment(); |
|
294 eventType[EDriverLoad] = &KDriverLoad(); |
|
295 eventType[EDeviceDetachment] = &KDetachment(); |
|
296 |
|
297 _LIT8(KSuccess, "Success"); |
|
298 _LIT8(KPartialSuccess, "Partial success"); |
|
299 _LIT8(KFailure, "Failure"); |
|
300 TFixedArray<const TDesC8*, 3> driverLoadStatus; |
|
301 driverLoadStatus[EDriverLoadSuccess] = &KSuccess(); |
|
302 driverLoadStatus[EDriverLoadPartialSuccess] = &KPartialSuccess(); |
|
303 driverLoadStatus[EDriverLoadFailure] = &KFailure(); |
|
304 |
|
305 switch ( iDeviceEventInformation.iEventType ) |
|
306 { |
|
307 case EDeviceAttachment: |
|
308 { |
|
309 iManager.Write(_L8("%S | device %d | error %d"), |
|
310 eventType[iDeviceEventInformation.iEventType], |
|
311 iDeviceEventInformation.iDeviceId, |
|
312 iDeviceEventInformation.iError); |
|
313 } |
|
314 break; |
|
315 case EDriverLoad: |
|
316 iManager.Write(_L8("%S | device %d | %S | error %d"), |
|
317 eventType[iDeviceEventInformation.iEventType], |
|
318 iDeviceEventInformation.iDeviceId, |
|
319 driverLoadStatus[iDeviceEventInformation.iDriverLoadStatus], |
|
320 iDeviceEventInformation.iError); |
|
321 break; |
|
322 case EDeviceDetachment: |
|
323 iManager.Write(_L8("%S | device %d"), |
|
324 eventType[iDeviceEventInformation.iEventType], |
|
325 iDeviceEventInformation.iDeviceId); |
|
326 break; |
|
327 default: |
|
328 iManager.Write(_L8("INVALID iEventType")); |
|
329 return; |
|
330 } |
|
331 |
|
332 if ( iDeviceEventInformation.iEventType == EDeviceAttachment && iDeviceEventInformation.iError == KErrNone ) |
|
333 { |
|
334 iManager.Write(_L8("VID: 0x%04x, PID: 0x%04x"), |
|
335 iDeviceEventInformation.iVid, |
|
336 iDeviceEventInformation.iPid); |
|
337 |
|
338 RArray<TUint> langIds; |
|
339 TInt err = iUsbHostStack.GetSupportedLanguages(iDeviceEventInformation.iDeviceId, langIds); |
|
340 if ( err == KErrNone ) |
|
341 { |
|
342 const TUint count = langIds.Count(); |
|
343 iManager.Write(_L8("there is/are %d supported language(s)"), count); |
|
344 for ( TUint ii = 0 ; ii < count ; ++ii ) |
|
345 { |
|
346 iManager.Write(_L8("using langid %d (index %d)"), langIds[ii], ii); |
|
347 |
|
348 TName string; |
|
349 |
|
350 TInt err = iUsbHostStack.GetManufacturerStringDescriptor(iDeviceEventInformation.iDeviceId, langIds[ii], string); |
|
351 if ( err == KErrNone ) |
|
352 { |
|
353 TBuf8<256> buf; |
|
354 buf.Copy(string); |
|
355 iManager.Write(_L8("manufacturer string descriptor = \"%S\""), &buf); |
|
356 } |
|
357 else |
|
358 { |
|
359 iManager.Write(_L8("GetManufacturerStringDescriptor returned %d"), err); |
|
360 } |
|
361 |
|
362 err = iUsbHostStack.GetProductStringDescriptor(iDeviceEventInformation.iDeviceId, langIds[ii], string); |
|
363 if ( err == KErrNone ) |
|
364 { |
|
365 TBuf8<256> buf; |
|
366 buf.Copy(string); |
|
367 iManager.Write(_L8("product string descriptor = \"%S\""), &buf); |
|
368 } |
|
369 else |
|
370 { |
|
371 iManager.Write(_L8("GetProductStringDescriptor returned %d"), err); |
|
372 } |
|
373 } |
|
374 } |
|
375 else |
|
376 { |
|
377 iManager.Write(_L8("GetSupportedLanguages returned %d"), err); |
|
378 } |
|
379 langIds.Close(); |
|
380 |
|
381 } |
|
382 } |
|
383 |
|
384 void CFdfTest::MndeoDevmonEvent() |
|
385 { |
|
386 iManager.Write(_L8("CFdfTest::MndeoDevmonEvent")); |
|
387 iManager.Write(KNullDesC8()); |
|
388 iManager.Write(_L8("CFdfTest::MndeoDevmonEvent")); |
|
389 |
|
390 iManager.Write(_L8("\tdevmon event: %d"), iDevmonEvent); |
|
391 } |