18 */ |
18 */ |
19 |
19 |
20 /** |
20 /** |
21 @file |
21 @file |
22 */ |
22 */ |
23 |
|
24 #include "CUsbDevice.h" |
|
25 #include "CUsbDeviceStateWatcher.h" |
|
26 #include <cusbclasscontrolleriterator.h> |
23 #include <cusbclasscontrolleriterator.h> |
27 #include "MUsbDeviceNotify.h" |
|
28 #include "UsbSettings.h" |
|
29 #include "CUsbServer.h" |
|
30 #include <cusbclasscontrollerbase.h> |
24 #include <cusbclasscontrollerbase.h> |
31 #include <cusbclasscontrollerplugin.h> |
25 #include <cusbclasscontrollerplugin.h> |
32 #include "UsbUtils.h" |
|
33 #include <cusbmanextensionplugin.h> |
26 #include <cusbmanextensionplugin.h> |
34 |
|
35 #ifdef USE_DUMMY_CLASS_CONTROLLER |
|
36 #include "CUsbDummyClassController.h" |
|
37 #endif |
|
38 |
|
39 #include <bafl/sysutil.h> |
27 #include <bafl/sysutil.h> |
40 #include <usb/usblogger.h> |
28 #include <usb/usblogger.h> |
41 #include <e32svr.h> |
29 #include <e32svr.h> |
42 #include <e32base.h> |
30 #include <e32base.h> |
43 #include <e32std.h> |
31 #include <e32std.h> |
44 #include <usbman.rsg> |
|
45 #include <f32file.h> |
32 #include <f32file.h> |
46 #include <barsc.h> |
33 #include <barsc.h> |
47 #include <barsread.h> |
34 #include <barsread.h> |
48 #include <bautils.h> |
35 #include <bautils.h> |
49 #include <e32property.h> //Publish & Subscribe header |
36 #include <e32property.h> //Publish & Subscribe header |
|
37 #ifdef USE_DUMMY_CLASS_CONTROLLER |
|
38 #include "CUsbDummyClassController.h" |
|
39 #endif |
|
40 #include "MUsbDeviceNotify.h" |
|
41 #include "UsbSettings.h" |
|
42 #include "CUsbServer.h" |
|
43 #include "UsbUtils.h" |
|
44 #include "CUsbDevice.h" |
|
45 #include "CUsbDeviceStateWatcher.h" |
50 #include "CPersonality.h" |
46 #include "CPersonality.h" |
|
47 #include "usbmancenrepmanager.h" |
|
48 #include "usbmanprivatecrkeys.h" |
|
49 |
|
50 #include "OstTraceDefinitions.h" |
|
51 #ifdef OST_TRACE_COMPILER_IN_USE |
|
52 #include "CUsbDeviceTraces.h" |
|
53 #endif |
|
54 |
51 |
55 |
52 _LIT(KUsbLDDName, "eusbc"); //Name used in call to User::LoadLogicalDevice |
56 _LIT(KUsbLDDName, "eusbc"); //Name used in call to User::LoadLogicalDevice |
53 _LIT(KUsbLDDFreeName, "Usbc"); //Name used in call to User::FreeLogicalDevice |
57 _LIT(KUsbLDDFreeName, "Usbc"); //Name used in call to User::FreeLogicalDevice |
54 |
58 |
55 #ifdef __FLOG_ACTIVE |
|
56 _LIT8(KLogComponent, "USBSVR"); |
|
57 #endif |
|
58 |
59 |
59 // Panic category only used in debug builds |
60 // Panic category only used in debug builds |
60 #ifdef _DEBUG |
61 #ifdef _DEBUG |
61 _LIT(KUsbDevicePanicCategory, "UsbDevice"); |
62 _LIT(KUsbDevicePanicCategory, "UsbDevice"); |
62 #endif |
63 #endif |
80 * Constructs a CUsbDevice object. |
81 * Constructs a CUsbDevice object. |
81 * |
82 * |
82 * @return A new CUsbDevice object |
83 * @return A new CUsbDevice object |
83 */ |
84 */ |
84 { |
85 { |
85 LOG_STATIC_FUNC_ENTRY |
86 OstTraceFunctionEntry0( CUSBDEVICE_NEWL_ENTRY ); |
86 |
87 |
87 CUsbDevice* r = new (ELeave) CUsbDevice(aUsbServer); |
88 CUsbDevice* r = new (ELeave) CUsbDevice(aUsbServer); |
88 CleanupStack::PushL(r); |
89 CleanupStack::PushL(r); |
89 r->ConstructL(); |
90 r->ConstructL(); |
90 CleanupStack::Pop(r); |
91 CleanupStack::Pop(r); |
|
92 OstTraceFunctionExit0( CUSBDEVICE_NEWL_EXIT ); |
91 return r; |
93 return r; |
92 } |
94 } |
93 |
95 |
94 |
96 |
95 CUsbDevice::~CUsbDevice() |
97 CUsbDevice::~CUsbDevice() |
96 /** |
98 /** |
97 * Destructor. |
99 * Destructor. |
98 */ |
100 */ |
99 { |
101 { |
100 LOG_FUNC |
102 OstTraceFunctionEntry0( CUSBDEVICE_CUSBDEVICE_DES_ENTRY ); |
101 |
103 |
102 // Cancel any outstanding asynchronous operation. |
104 // Cancel any outstanding asynchronous operation. |
103 Cancel(); |
105 Cancel(); |
104 |
106 |
105 delete iUsbClassControllerIterator; |
107 delete iUsbClassControllerIterator; |
106 iSupportedClasses.ResetAndDestroy(); |
108 iSupportedClasses.ResetAndDestroy(); |
107 iSupportedPersonalities.ResetAndDestroy(); |
109 iSupportedPersonalities.ResetAndDestroy(); |
108 iSupportedClassUids.Close(); |
110 iSupportedClassUids.Close(); |
109 |
111 |
110 iExtensionPlugins.ResetAndDestroy(); |
112 iExtensionPlugins.ResetAndDestroy(); |
|
113 |
|
114 delete iCenRepManager; |
|
115 |
|
116 delete iDeviceConfiguration.iManufacturerName; |
|
117 delete iDeviceConfiguration.iProductName; |
111 |
118 |
112 if(iEcom) |
119 if(iEcom) |
113 iEcom->Close(); |
120 iEcom->Close(); |
114 REComSession::FinalClose(); |
121 REComSession::FinalClose(); |
115 |
122 |
116 // Free any memory allocated to the list of observers. Note that |
123 // Free any memory allocated to the list of observers. Note that |
117 // we don't want to call ResetAndDestroy, because we don't own |
124 // we don't want to call ResetAndDestroy, because we don't own |
118 // the observers themselves. |
125 // the observers themselves. |
119 iObservers.Reset(); |
126 iObservers.Reset(); |
120 |
127 |
|
128 #ifndef __OVER_DUMMYUSBDI__ |
121 #ifndef __WINS__ |
129 #ifndef __WINS__ |
122 LOGTEXT2(_L8("about to delete device state watcher @ %08x"), (TUint32) iDeviceStateWatcher); |
130 OstTrace1( TRACE_NORMAL, CUSBDEVICE_CUSBDEVICE, "CUsbDevice::~CUsbDevice;about to delete device state watcher @ %08x", (TUint32)iDeviceStateWatcher ); |
|
131 |
123 delete iDeviceStateWatcher; |
132 delete iDeviceStateWatcher; |
124 LOGTEXT(_L8("deleted device state watcher")); |
133 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CUSBDEVICE_DUP1, "CUsbDevice::~CUsbDevice;deleted device state watcher" ); |
125 |
134 |
126 iLdd.Close(); |
135 iLdd.Close(); |
127 |
136 |
128 LOGTEXT(_L8("Freeing logical device")); |
137 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CUSBDEVICE_DUP2, "CUsbDevice::~CUsbDevice;Freeing logical device" ); |
|
138 |
129 TInt err = User::FreeLogicalDevice(KUsbLDDFreeName); |
139 TInt err = User::FreeLogicalDevice(KUsbLDDFreeName); |
130 //Putting the LOGTEXT2 inside the if statement prevents a compiler |
140 //Putting the LOGTEXT2 inside the if statement prevents a compiler |
131 //warning about err being unused in UREL builds. |
141 //warning about err being unused in UREL builds. |
132 if(err) |
142 if(err) |
133 { |
143 { |
134 LOGTEXT2(_L8(" User::FreeLogicalDevice returned %d"),err); |
144 OstTrace1( TRACE_NORMAL, CUSBDEVICE_CUSBDEVICE_DUP3, "CUsbDevice::~CUsbDevice; User::FreeLogicalDevice returned err=%d", err ); |
135 } |
145 } |
|
146 #endif |
136 #endif |
147 #endif |
137 |
148 |
138 delete iDefaultSerialNumber; |
149 delete iDefaultSerialNumber; |
|
150 OstTraceFunctionExit0( CUSBDEVICE_CUSBDEVICE_DES_EXIT ); |
139 } |
151 } |
140 |
152 |
141 |
153 |
142 CUsbDevice::CUsbDevice(CUsbServer& aUsbServer) |
154 CUsbDevice::CUsbDevice(CUsbServer& aUsbServer) |
143 : CActive(EPriorityStandard) |
155 : CActive(EPriorityStandard) |
156 void CUsbDevice::ConstructL() |
168 void CUsbDevice::ConstructL() |
157 /** |
169 /** |
158 * Performs 2nd phase construction of the USB device. |
170 * Performs 2nd phase construction of the USB device. |
159 */ |
171 */ |
160 { |
172 { |
161 LOG_FUNC |
173 OstTraceFunctionEntry0( CUSBDEVICE_CONSTRUCTL_ENTRY ); |
162 |
174 |
163 iEcom = &(REComSession::OpenL()); |
175 iEcom = &(REComSession::OpenL()); |
164 |
176 |
165 iUsbClassControllerIterator = new(ELeave) CUsbClassControllerIterator(iSupportedClasses); |
177 iUsbClassControllerIterator = new(ELeave) CUsbClassControllerIterator(iSupportedClasses); |
166 |
178 iCenRepManager = CUsbManCenRepManager::NewL(*this); |
|
179 |
|
180 iDeviceConfiguration.iManufacturerName = HBufC::NewL(KUsbStringDescStringMaxSize); |
|
181 iDeviceConfiguration.iProductName = HBufC::NewL(KUsbStringDescStringMaxSize); |
|
182 #ifndef __OVER_DUMMYUSBDI__ |
167 #ifndef __WINS__ |
183 #ifndef __WINS__ |
168 LOGTEXT(_L8("About to load LDD")); |
184 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL, "CUsbDevice::ConstructL; About to load LDD" ); |
|
185 |
169 TInt err = User::LoadLogicalDevice(KUsbLDDName); |
186 TInt err = User::LoadLogicalDevice(KUsbLDDName); |
170 |
187 |
171 if (err != KErrNone && err != KErrAlreadyExists) |
188 if (err != KErrNone && err != KErrAlreadyExists) |
172 { |
189 { |
173 LEAVEL(err); |
190 OstTrace1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP10, "CUsbDevice::ConstructL;err=%d", err ); |
174 } |
191 User::Leave(err); |
175 |
192 } |
176 LOGTEXT(_L8("About to open LDD")); |
193 |
177 LEAVEIFERRORL(iLdd.Open(0)); |
194 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP1, "CUsbDevice::ConstructL; About to open LDD" ); |
178 LOGTEXT(_L8("LDD opened")); |
195 err = iLdd.Open(0); |
|
196 if(err < 0) |
|
197 { |
|
198 OstTrace1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP9, "CUsbDevice::ConstructL;iLdd.Open(0) with error=%d", err ); |
|
199 User::Leave(err); |
|
200 } |
|
201 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP2, "CUsbDevice::ConstructL; LDD opened" ); |
|
202 |
179 |
203 |
180 // hide bus from host while interfaces are being set up |
204 // hide bus from host while interfaces are being set up |
181 iLdd.DeviceDisconnectFromHost(); |
205 iLdd.DeviceDisconnectFromHost(); |
182 |
206 |
183 // Does the USC support cable detection while powered off? If no, then |
207 // Does the USC support cable detection while powered off? If no, then |
184 // call PowerUpUdc when RUsb::Start finishes, as is obvious. If yes, we |
208 // call PowerUpUdc when RUsb::Start finishes, as is obvious. If yes, we |
185 // delay calling PowerUpUdc until both the service state is 'started' and |
209 // delay calling PowerUpUdc until both the service state is 'started' and |
186 // the device state is not undefined. This is to save power in the UDC |
210 // the device state is not undefined. This is to save power in the UDC |
187 // when there's no point it being powered. |
211 // when there's no point it being powered. |
188 TUsbDeviceCaps devCapsBuf; |
212 TUsbDeviceCaps devCapsBuf; |
189 LEAVEIFERRORL(iLdd.DeviceCaps(devCapsBuf)); |
213 err = iLdd.DeviceCaps(devCapsBuf); |
|
214 if(err < 0) |
|
215 { |
|
216 OstTrace1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP11, "CUsbDevice::ConstructL;iLdd.DeviceCaps(devCapsBuf) with error=%d", err ); |
|
217 User::Leave(err); |
|
218 } |
|
219 |
190 if ( devCapsBuf().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower ) |
220 if ( devCapsBuf().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower ) |
191 { |
221 { |
192 LOGTEXT(_L8("\tUDC supports cable detect when unpowered")); |
222 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP3, "CUsbDevice::ConstructL: UDC supports cable detect when unpowered" ); |
193 iUdcSupportsCableDetectWhenUnpowered = ETrue; |
223 iUdcSupportsCableDetectWhenUnpowered = ETrue; |
194 } |
224 } |
195 else |
225 else |
196 { |
226 { |
197 LOGTEXT(_L8("\tUDC does not support cable detect when unpowered")); |
227 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP4, "CUsbDevice::ConstructL; UDC does not support cable detect when unpowered" ); |
198 } |
228 } |
199 |
229 |
200 TUsbcDeviceState deviceState; |
230 TUsbcDeviceState deviceState; |
201 LEAVEIFERRORL(iLdd.DeviceStatus(deviceState)); |
231 err = iLdd.DeviceStatus(deviceState); |
|
232 if(err < 0) |
|
233 { |
|
234 OstTrace1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP13, "CUsbDevice::ConstructL;iLdd.DeviceStatus(deviceState) with error=%d", err ); |
|
235 User::Leave(err); |
|
236 } |
202 SetDeviceState(deviceState); |
237 SetDeviceState(deviceState); |
203 LOGTEXT(_L8("Got device state")); |
238 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP5, "CUsbDevice::ConstructL; Got device state" ); |
|
239 |
204 |
240 |
205 iDeviceStateWatcher = CUsbDeviceStateWatcher::NewL(*this, iLdd); |
241 iDeviceStateWatcher = CUsbDeviceStateWatcher::NewL(*this, iLdd); |
206 iDeviceStateWatcher->Start(); |
242 iDeviceStateWatcher->Start(); |
207 |
243 |
208 // Get hold of the default serial number in the driver |
244 // Get hold of the default serial number in the driver |
213 err = iLdd.GetSerialNumberStringDescriptor(serNum); |
249 err = iLdd.GetSerialNumberStringDescriptor(serNum); |
214 if (err == KErrNotFound) |
250 if (err == KErrNotFound) |
215 { |
251 { |
216 delete iDefaultSerialNumber; |
252 delete iDefaultSerialNumber; |
217 iDefaultSerialNumber = NULL; |
253 iDefaultSerialNumber = NULL; |
218 LOGTEXT(_L8("No default serial number")); |
254 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP6, "CUsbDevice::ConstructL; No default serial number" ); |
|
255 |
219 } |
256 } |
220 else |
257 else |
221 { |
258 { |
222 LEAVEIFERRORL(err); |
259 if(err < 0) |
223 #ifdef __FLOG_ACTIVE |
260 { |
224 TBuf8<KUsbStringDescStringMaxSize> narrowString; |
261 OstTrace1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP12, "CUsbDevice::ConstructL;error=%d", err ); |
225 narrowString.Copy(serNum); |
262 User::Leave(err); |
226 LOGTEXT2(_L8("Got default serial number %S"), &narrowString); |
263 } |
227 #endif //__FLOG_ACTIVE |
264 #ifdef _DEBUG |
228 } |
265 OstTraceExt1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP7, "CUsbDevice::ConstructL;serNum=%S", serNum ); |
229 |
266 #endif //_DEBUG |
230 LOGTEXT(_L8("UsbDevice::ConstructL() finished")); |
267 } |
|
268 |
|
269 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP8, "CUsbDevice::ConstructL; UsbDevice::ConstructL() finished" ); |
|
270 |
|
271 #endif |
231 #endif |
272 #endif |
232 |
273 |
233 #ifndef __OVER_DUMMYUSBDI__ |
274 #ifndef __OVER_DUMMYUSBDI__ |
234 InstantiateExtensionPluginsL(); |
275 InstantiateExtensionPluginsL(); |
235 #endif |
276 #endif |
|
277 OstTraceFunctionExit0( CUSBDEVICE_CONSTRUCTL_EXIT ); |
236 } |
278 } |
237 |
279 |
238 void CUsbDevice::InstantiateExtensionPluginsL() |
280 void CUsbDevice::InstantiateExtensionPluginsL() |
239 { |
281 { |
240 LOGTEXT(_L8(">>CUsbDevice::InstantiateExtensionPluginsL")); |
282 OstTraceFunctionEntry0( CUSBDEVICE_INSTANTIATEEXTENSIONPLUGINSL_ENTRY ); |
|
283 |
241 const TUid KUidExtensionPluginInterface = TUid::Uid(KUsbmanExtensionPluginInterfaceUid); |
284 const TUid KUidExtensionPluginInterface = TUid::Uid(KUsbmanExtensionPluginInterfaceUid); |
242 RImplInfoPtrArray implementations; |
285 RImplInfoPtrArray implementations; |
243 const TEComResolverParams noResolverParams; |
286 const TEComResolverParams noResolverParams; |
244 REComSession::ListImplementationsL(KUidExtensionPluginInterface, noResolverParams, KRomOnlyResolverUid, implementations); |
287 REComSession::ListImplementationsL(KUidExtensionPluginInterface, noResolverParams, KRomOnlyResolverUid, implementations); |
245 CleanupResetAndDestroyPushL(implementations); |
288 CleanupResetAndDestroyPushL(implementations); |
246 LOGTEXT2(_L8("Number of implementations of extension plugin interface: %d"), implementations.Count()); |
289 OstTrace1( TRACE_FLOW, CUSBDEVICE_INSTANTIATEEXTENSIONPLUGINSL, "CUsbDevice::InstantiateExtensionPluginsL;Number of implementations of extension plugin interface: %d", implementations.Count() ); |
|
290 |
247 |
291 |
248 for (TInt i=0; i<implementations.Count(); i++) |
292 for (TInt i=0; i<implementations.Count(); i++) |
249 { |
293 { |
250 CUsbmanExtensionPlugin* plugin = CUsbmanExtensionPlugin::NewL(implementations[i]->ImplementationUid(), *this); |
294 CUsbmanExtensionPlugin* plugin = CUsbmanExtensionPlugin::NewL(implementations[i]->ImplementationUid(), *this); |
251 CleanupStack::PushL(plugin); |
295 CleanupStack::PushL(plugin); |
252 iExtensionPlugins.AppendL(plugin); // transfer ownership to iExtensionPlugins |
296 iExtensionPlugins.AppendL(plugin); // transfer ownership to iExtensionPlugins |
253 CleanupStack::Pop(plugin); |
297 CleanupStack::Pop(plugin); |
254 LOGTEXT2(_L8("Added extension plugin with UID 0x%08x"), |
298 OstTrace1( TRACE_NORMAL, CUSBDEVICE_INSTANTIATEEXTENSIONPLUGINSL_DUP1, |
255 implementations[i]->ImplementationUid()); |
299 "CUsbDevice::InstantiateExtensionPluginsL;Added extension plugin with UID 0x%08x", |
|
300 implementations[i]->ImplementationUid().iUid ); |
|
301 |
256 } |
302 } |
257 |
303 |
258 CleanupStack::PopAndDestroy(&implementations); |
304 CleanupStack::PopAndDestroy(&implementations); |
259 |
305 OstTraceFunctionExit0( CUSBDEVICE_INSTANTIATEEXTENSIONPLUGINSL_EXIT ); |
260 LOGTEXT(_L8("<<CUsbDevice::InstantiateExtensionPluginsL")); |
|
261 } |
306 } |
262 |
307 |
263 |
308 |
264 |
309 |
265 |
310 |
347 |
401 |
348 if (rc != KErrNone) |
402 if (rc != KErrNone) |
349 { |
403 { |
350 // Avoid memory leak by deleting class controller if the append fails. |
404 // Avoid memory leak by deleting class controller if the append fails. |
351 delete aClassController; |
405 delete aClassController; |
352 LEAVEL(rc); |
406 OstTrace1( TRACE_NORMAL, CUSBDEVICE_ADDCLASSCONTROLLERL, "CUsbDevice::AddClassControllerL;Leave rc=%d", rc ); |
353 } |
407 User::Leave(rc); |
|
408 } |
|
409 OstTraceFunctionExit0( CUSBDEVICE_ADDCLASSCONTROLLERL_EXIT ); |
354 } |
410 } |
355 |
411 |
356 void CUsbDevice::RegisterObserverL(MUsbDeviceNotify& aObserver) |
412 void CUsbDevice::RegisterObserverL(MUsbDeviceNotify& aObserver) |
357 /** |
413 /** |
358 * Register an observer of the device. |
414 * Register an observer of the device. |
359 * Presently, the device supports watching state. |
415 * Presently, the device supports watching state. |
360 * |
416 * |
361 * @param aObserver New Observer of the device |
417 * @param aObserver New Observer of the device |
362 */ |
418 */ |
363 { |
419 { |
364 LOG_FUNC |
420 OstTraceFunctionEntry0( CUSBDEVICE_REGISTEROBSERVERL_ENTRY ); |
365 |
421 TInt err = iObservers.Append(&aObserver); |
366 LEAVEIFERRORL(iObservers.Append(&aObserver)); |
422 if(err < 0) |
|
423 { |
|
424 OstTrace1( TRACE_NORMAL, CUSBDEVICE_REGISTEROBSERVERL, "CUsbDevice::RegisterObserverL;iObservers.Append(&aObserver) with err=%d", err ); |
|
425 User::Leave(err); |
|
426 } |
|
427 OstTraceFunctionExit0( CUSBDEVICE_REGISTEROBSERVERL_EXIT ); |
367 } |
428 } |
368 |
429 |
369 |
430 |
370 void CUsbDevice::DeRegisterObserver(MUsbDeviceNotify& aObserver) |
431 void CUsbDevice::DeRegisterObserver(MUsbDeviceNotify& aObserver) |
371 /** |
432 /** |
372 * De-registers an existing device observer. |
433 * De-registers an existing device observer. |
373 * |
434 * |
374 * @param aObserver The existing device observer to be de-registered |
435 * @param aObserver The existing device observer to be de-registered |
375 */ |
436 */ |
376 { |
437 { |
377 LOG_FUNC |
438 OstTraceFunctionEntry0( CUSBDEVICE_DEREGISTEROBSERVER_ENTRY ); |
378 |
439 |
379 TInt index = iObservers.Find(&aObserver); |
440 TInt index = iObservers.Find(&aObserver); |
380 |
441 |
381 if (index >= 0) |
442 if (index >= 0) |
382 iObservers.Remove(index); |
443 iObservers.Remove(index); |
|
444 OstTraceFunctionExit0( CUSBDEVICE_DEREGISTEROBSERVER_EXIT ); |
383 } |
445 } |
384 |
446 |
385 |
447 |
386 void CUsbDevice::StartL() |
448 void CUsbDevice::StartL() |
387 /** |
449 /** |
388 * Start the USB Device and all its associated USB classes. |
450 * Start the USB Device and all its associated USB classes. |
389 * Reports errors and state changes via observer interface. |
451 * Reports errors and state changes via observer interface. |
390 */ |
452 */ |
391 { |
453 { |
392 LOG_FUNC |
454 OstTraceFunctionEntry0( CUSBDEVICE_STARTL_ENTRY ); |
393 |
455 |
394 Cancel(); |
456 Cancel(); |
395 SetServiceState(EUsbServiceStarting); |
457 SetServiceState(EUsbServiceStarting); |
396 |
458 |
397 TRAPD(err, SetDeviceDescriptorL()); |
459 TRAPD(err, SetDeviceDescriptorL()); |
398 if ( err != KErrNone ) |
460 if ( err != KErrNone ) |
399 { |
461 { |
400 SetServiceState(EUsbServiceIdle); |
462 SetServiceState(EUsbServiceIdle); |
401 LEAVEL(err); |
463 OstTrace1( TRACE_NORMAL, CUSBDEVICE_STARTL, "CUsbDevice::StartL;Leave with error=%d", err ); |
|
464 User::Leave(err); |
402 } |
465 } |
403 |
466 |
404 iLastError = KErrNone; |
467 iLastError = KErrNone; |
405 StartCurrentClassController(); |
468 StartCurrentClassController(); |
|
469 OstTraceFunctionExit0( CUSBDEVICE_STARTL_EXIT ); |
406 } |
470 } |
407 |
471 |
408 void CUsbDevice::Stop() |
472 void CUsbDevice::Stop() |
409 /** |
473 /** |
410 * Stop the USB device and all its associated USB classes. |
474 * Stop the USB device and all its associated USB classes. |
411 */ |
475 */ |
412 { |
476 { |
413 LOG_FUNC |
477 OstTraceFunctionEntry0( CUSBDEVICE_STOP_ENTRY ); |
414 |
478 |
415 Cancel(); |
479 Cancel(); |
416 SetServiceState(EUsbServiceStopping); |
480 SetServiceState(EUsbServiceStopping); |
417 |
481 |
418 iLastError = KErrNone; |
482 iLastError = KErrNone; |
419 StopCurrentClassController(); |
483 StopCurrentClassController(); |
|
484 OstTraceFunctionExit0( CUSBDEVICE_STOP_EXIT ); |
420 } |
485 } |
421 |
486 |
422 void CUsbDevice::SetServiceState(TUsbServiceState aState) |
487 void CUsbDevice::SetServiceState(TUsbServiceState aState) |
423 /** |
488 /** |
424 * Change the device's state and report the change to the observers. |
489 * Change the device's state and report the change to the observers. |
425 * |
490 * |
426 * @param aState New state that the device is moving to |
491 * @param aState New state that the device is moving to |
427 */ |
492 */ |
428 { |
493 { |
429 LOGTEXT3(_L8("Calling: CUsbDevice::SetServiceState [iServiceState=%d,aState=%d]"), |
494 OstTraceFunctionEntry0( CUSBDEVICE_SETSERVICESTATE_ENTRY ); |
430 iServiceState, aState); |
495 |
|
496 OstTraceExt2( TRACE_NORMAL, CUSBDEVICE_SETSERVICESTATE, |
|
497 "CUsbDevice::SetServiceState;iServiceState=%d;aState=%d", iServiceState, aState ); |
|
498 |
431 |
499 |
432 if (iServiceState != aState) |
500 if (iServiceState != aState) |
433 { |
501 { |
434 // Change state straight away in case any of the clients check it |
502 // Change state straight away in case any of the clients check it |
435 TUsbServiceState oldState = iServiceState; |
503 TUsbServiceState oldState = iServiceState; |
500 // now be attached (if it wasn't before). If the UDC supports |
570 // now be attached (if it wasn't before). If the UDC supports |
501 // cable detection when unpowered, NOW is the right time to power |
571 // cable detection when unpowered, NOW is the right time to power |
502 // it up (so long as usbman is fully started). |
572 // it up (so long as usbman is fully started). |
503 (void)PowerUpAndConnect(); // We don't care about any errors here. |
573 (void)PowerUpAndConnect(); // We don't care about any errors here. |
504 } |
574 } |
505 #endif // __WINS__ |
575 #endif |
|
576 #endif // __OVER_DUMMYUSBDI__ |
506 // Change state straight away in case any of the clients check it |
577 // Change state straight away in case any of the clients check it |
507 TUsbDeviceState oldState = iDeviceState; |
578 TUsbDeviceState oldState = iDeviceState; |
508 iDeviceState = state; |
579 iDeviceState = state; |
509 TUint length = iObservers.Count(); |
580 TUint length = iObservers.Count(); |
510 |
581 |
511 for (TUint i = 0; i < length; i++) |
582 for (TUint i = 0; i < length; i++) |
512 { |
583 { |
513 iObservers[i]->UsbDeviceStateChange(LastError(), oldState, iDeviceState); |
584 iObservers[i]->UsbDeviceStateChange(LastError(), oldState, iDeviceState); |
514 } |
585 } |
515 } |
586 } |
|
587 OstTraceFunctionExit0( CUSBDEVICE_SETDEVICESTATE_EXIT ); |
516 } |
588 } |
517 |
589 |
518 /** |
590 /** |
519 * Callback called by CDeviceHandler when the USB bus has sucessfully |
591 * Callback called by CDeviceHandler when the USB bus has sucessfully |
520 * completed a ReEnumeration (restarted all services). |
592 * completed a ReEnumeration (restarted all services). |
521 */ |
593 */ |
522 void CUsbDevice::BusEnumerationCompleted() |
594 void CUsbDevice::BusEnumerationCompleted() |
523 { |
595 { |
524 LOG_FUNC |
596 OstTraceFunctionEntry0( CUSBDEVICE_BUSENUMERATIONCOMPLETED_ENTRY ); |
525 |
597 |
526 // Has the start been cancelled? |
598 // Has the start been cancelled? |
527 if (iServiceState == EUsbServiceStarting) |
599 if (iServiceState == EUsbServiceStarting) |
528 { |
600 { |
529 SetServiceState(EUsbServiceStarted); |
601 SetServiceState(EUsbServiceStarted); |
530 } |
602 } |
531 else |
603 else |
532 { |
604 { |
533 LOGTEXT(_L8(" Start has been cancelled!")); |
605 OstTrace0( TRACE_NORMAL, CUSBDEVICE_BUSENUMERATIONCOMPLETED, |
534 } |
606 "CUsbDevice::BusEnumerationCompleted; Start has been cancelled!" ); |
|
607 } |
|
608 OstTraceFunctionExit0( CUSBDEVICE_BUSENUMERATIONCOMPLETED_EXIT ); |
535 } |
609 } |
536 |
610 |
537 void CUsbDevice::BusEnumerationFailed(TInt aError) |
611 void CUsbDevice::BusEnumerationFailed(TInt aError) |
538 /** |
612 /** |
539 * Callback called by CDeviceHandler when the USB bus has |
613 * Callback called by CDeviceHandler when the USB bus has |
540 * completed an ReEnumeration (Restarted all services) with errors |
614 * completed an ReEnumeration (Restarted all services) with errors |
541 * |
615 * |
542 * @param aError Error that has occurred during Re-enumeration |
616 * @param aError Error that has occurred during Re-enumeration |
543 */ |
617 */ |
544 { |
618 { |
545 LOGTEXT2(_L8("CUsbDevice::BusEnumerationFailed [aError=%d]"), aError); |
619 OstTrace1( TRACE_NORMAL, CUSBDEVICE_BUSENUMERATIONFAILED, "CUsbDevice::BusEnumerationFailed;aError=%d", aError ); |
|
620 |
546 iLastError = aError; |
621 iLastError = aError; |
547 |
622 |
548 if (iServiceState == EUsbServiceStarting) |
623 if (iServiceState == EUsbServiceStarting) |
549 { |
624 { |
550 SetServiceState(EUsbServiceStopping); |
625 SetServiceState(EUsbServiceStopping); |
551 StopCurrentClassController(); |
626 StopCurrentClassController(); |
552 } |
627 } |
553 else |
628 else |
554 { |
629 { |
555 LOGTEXT(_L8(" Start has been cancelled!")); |
630 OstTrace0( TRACE_NORMAL, CUSBDEVICE_BUSENUMERATIONFAILED_DUP1, |
|
631 "CUsbDevice::BusEnumerationFailed; Start has been cancelled!" ); |
556 } |
632 } |
557 } |
633 } |
558 |
634 |
559 |
635 |
560 void CUsbDevice::StartCurrentClassController() |
636 void CUsbDevice::StartCurrentClassController() |
561 /** |
637 /** |
562 * Called numerous times to start all the USB classes. |
638 * Called numerous times to start all the USB classes. |
563 */ |
639 */ |
564 { |
640 { |
565 LOG_FUNC |
641 OstTraceFunctionEntry0( CUSBDEVICE_STARTCURRENTCLASSCONTROLLER_ENTRY ); |
566 |
642 |
567 iUsbClassControllerIterator->Current()->Start(iStatus); |
643 iUsbClassControllerIterator->Current()->Start(iStatus); |
568 SetActive(); |
644 SetActive(); |
|
645 OstTraceFunctionExit0( CUSBDEVICE_STARTCURRENTCLASSCONTROLLER_EXIT ); |
569 } |
646 } |
570 |
647 |
571 void CUsbDevice::StopCurrentClassController() |
648 void CUsbDevice::StopCurrentClassController() |
572 /** |
649 /** |
573 * Called numerous times to stop all the USB classes. |
650 * Called numerous times to stop all the USB classes. |
574 */ |
651 */ |
575 { |
652 { |
576 LOG_FUNC |
653 OstTraceFunctionEntry0( CUSBDEVICE_STOPCURRENTCLASSCONTROLLER_ENTRY ); |
577 |
654 |
578 iUsbClassControllerIterator->Current()->Stop(iStatus); |
655 iUsbClassControllerIterator->Current()->Stop(iStatus); |
579 SetActive(); |
656 SetActive(); |
|
657 OstTraceFunctionExit0( CUSBDEVICE_STOPCURRENTCLASSCONTROLLER_EXIT ); |
580 } |
658 } |
581 |
659 |
582 /** |
660 /** |
583 Utility function to power up the UDC and connect the |
661 Utility function to power up the UDC and connect the |
584 device to the host. |
662 device to the host. |
585 */ |
663 */ |
586 TInt CUsbDevice::PowerUpAndConnect() |
664 TInt CUsbDevice::PowerUpAndConnect() |
587 { |
665 { |
588 LOG_FUNC |
666 OstTraceFunctionEntry0( CUSBDEVICE_POWERUPANDCONNECT_ENTRY ); |
589 LOGTEXT(_L8("\tPowering up UDC...")); |
667 |
|
668 OstTrace0( TRACE_NORMAL, CUSBDEVICE_POWERUPANDCONNECT, "CUsbDevice::PowerUpAndConnect;Powering up UDC..." ); |
|
669 |
590 TInt res = iLdd.PowerUpUdc(); |
670 TInt res = iLdd.PowerUpUdc(); |
591 LOGTEXT2(_L8("\tPowerUpUdc res = %d"), res); |
671 OstTrace1( TRACE_NORMAL, CUSBDEVICE_POWERUPANDCONNECT_DUP1, |
|
672 "CUsbDevice::PowerUpAndConnect;PowerUpUdc res = %d", res ); |
|
673 |
592 res = iLdd.DeviceConnectToHost(); |
674 res = iLdd.DeviceConnectToHost(); |
593 LOGTEXT2(_L8("\tDeviceConnectToHost res = %d"), res); |
675 OstTrace1( TRACE_NORMAL, CUSBDEVICE_POWERUPANDCONNECT_DUP2, |
|
676 "CUsbDevice::PowerUpAndConnect;DeviceConnectToHost res = %d", res ); |
|
677 |
|
678 OstTraceFunctionExit0( CUSBDEVICE_POWERUPANDCONNECT_EXIT ); |
594 return res; |
679 return res; |
595 } |
680 } |
596 |
681 |
597 void CUsbDevice::RunL() |
682 void CUsbDevice::RunL() |
598 /** |
683 /** |
599 * Called when starting or stopping a USB class has completed, successfully or |
684 * Called when starting or stopping a USB class has completed, successfully or |
600 * otherwise. Continues with the process of starting or stopping until all |
685 * otherwise. Continues with the process of starting or stopping until all |
601 * classes have been completed. |
686 * classes have been completed. |
602 */ |
687 */ |
603 { |
688 { |
604 LOGTEXT2(_L8(">>CUsbDevice::RunL [iStatus=%d]"), iStatus.Int()); |
689 OstTraceFunctionEntry0( CUSBDEVICE_RUNL_ENTRY ); |
605 |
690 OstTrace1( TRACE_NORMAL, CUSBDEVICE_RUNL, "CUsbDevice::RunL;iStatus.Int()=%d", iStatus.Int() ); |
606 LEAVEIFERRORL(iStatus.Int()); |
691 |
|
692 TInt err = iStatus.Int(); |
|
693 if(err < 0) |
|
694 { |
|
695 OstTrace1( TRACE_NORMAL, CUSBDEVICE_RUNL_DUP4, "CUsbDevice::RunL;iStatus.Int() with error=%d", err ); |
|
696 User::Leave(err); |
|
697 } |
607 |
698 |
608 switch (iServiceState) |
699 switch (iServiceState) |
609 { |
700 { |
610 case EUsbServiceStarting: |
701 case EUsbServiceStarting: |
611 if (iUsbClassControllerIterator->Next() == KErrNotFound) |
702 if (iUsbClassControllerIterator->Next() == KErrNotFound) |
612 { |
703 { |
|
704 #ifndef __OVER_DUMMYUSBDI__ |
613 #ifndef __WINS__ |
705 #ifndef __WINS__ |
614 if (!iUdcSupportsCableDetectWhenUnpowered || iDeviceState != EUsbDeviceStateUndefined) |
706 if (!iUdcSupportsCableDetectWhenUnpowered || iDeviceState != EUsbDeviceStateUndefined) |
615 { |
707 { |
616 // We've finished starting the classes. We can just power up the UDC |
708 // We've finished starting the classes. We can just power up the UDC |
617 // now: there's no need to re-enumerate, because we soft disconnected |
709 // now: there's no need to re-enumerate, because we soft disconnected |
618 // earlier. This will also do a soft connect. |
710 // earlier. This will also do a soft connect. |
619 LOGTEXT(_L8("Finished starting classes: powering up UDC")); |
711 OstTrace0( TRACE_NORMAL, CUSBDEVICE_RUNL_DUP1, "CUsbDevice::RunL;Finished starting classes: powering up UDC" ); |
|
712 |
620 |
713 |
621 // It isn't an error if this call fails. This will happen, for example, |
714 // It isn't an error if this call fails. This will happen, for example, |
622 // in the case where there are no USB classes defined. |
715 // in the case where there are no USB classes defined. |
623 (void)PowerUpAndConnect(); |
716 (void)PowerUpAndConnect(); |
624 } |
717 } |
|
718 #endif |
625 #endif |
719 #endif |
626 // If we're not running on target, we can just go to "started". |
720 // If we're not running on target, we can just go to "started". |
627 SetServiceState(EUsbServiceStarted); |
721 SetServiceState(EUsbServiceStarted); |
628 } |
722 } |
629 else |
723 else |
634 |
728 |
635 case EUsbServiceStopping: |
729 case EUsbServiceStopping: |
636 if (iUsbClassControllerIterator->Previous() == KErrNotFound) |
730 if (iUsbClassControllerIterator->Previous() == KErrNotFound) |
637 { |
731 { |
638 // if stopping classes, hide the USB interface from the host |
732 // if stopping classes, hide the USB interface from the host |
|
733 #ifndef __OVER_DUMMYUSBDI__ |
639 #ifndef __WINS__ |
734 #ifndef __WINS__ |
640 iLdd.DeviceDisconnectFromHost(); |
735 iLdd.DeviceDisconnectFromHost(); |
641 |
736 |
642 // Restore the default serial number |
737 // Restore the default serial number |
643 if (iDefaultSerialNumber) |
738 if (iDefaultSerialNumber) |
644 { |
739 { |
645 TInt res = iLdd.SetSerialNumberStringDescriptor(*iDefaultSerialNumber); |
740 TInt res = iLdd.SetSerialNumberStringDescriptor(*iDefaultSerialNumber); |
646 LOGTEXT2(_L8("Restore default serial number res = %d"), res); |
741 OstTrace1( TRACE_NORMAL, CUSBDEVICE_RUNL_DUP2, "CUsbDevice::RunL;Restore default serial number res = %d", res ); |
647 } |
742 } |
648 else |
743 else |
649 { |
744 { |
650 TInt res = iLdd.RemoveSerialNumberStringDescriptor(); |
745 TInt res = iLdd.RemoveSerialNumberStringDescriptor(); |
651 LOGTEXT2(_L8("Remove serial number res = %d"), res); |
746 OstTrace1( TRACE_NORMAL, CUSBDEVICE_RUNL_DUP3, "CUsbDevice::RunL;Remove serial number res = %d", res ); |
652 } |
747 } |
653 |
748 |
|
749 #endif |
654 #endif |
750 #endif |
655 SetServiceState(EUsbServiceIdle); |
751 SetServiceState(EUsbServiceIdle); |
656 } |
752 } |
657 else |
753 else |
658 { |
754 { |
659 StopCurrentClassController(); |
755 StopCurrentClassController(); |
660 } |
756 } |
661 break; |
757 break; |
662 |
758 |
663 default: |
759 default: |
664 __ASSERT_DEBUG( EFalse, _USB_PANIC(KUsbDevicePanicCategory, EBadAsynchronousCall) ); |
760 |
665 break; |
761 OstTrace1( TRACE_FATAL, CUSBDEVICE_RUNL_DUP5, "CUsbDevice::RunL;Panic reason=%d", EBadAsynchronousCall ); |
666 } |
762 __ASSERT_DEBUG( EFalse, User::Panic(KUsbDevicePanicCategory, EBadAsynchronousCall) ); |
667 LOGTEXT(_L8("<<CUsbDevice::RunL")); |
763 |
|
764 break; |
|
765 } |
|
766 OstTraceFunctionExit0( CUSBDEVICE_RUNL_EXIT ); |
668 } |
767 } |
669 |
768 |
670 void CUsbDevice::DoCancel() |
769 void CUsbDevice::DoCancel() |
671 /** |
770 /** |
672 * Standard active object cancellation function. If we're starting or stopping |
771 * Standard active object cancellation function. If we're starting or stopping |
673 * a USB class, cancels it. If we're not, then we shouldn't be active and hence |
772 * a USB class, cancels it. If we're not, then we shouldn't be active and hence |
674 * this function being called is a programming error. |
773 * this function being called is a programming error. |
675 */ |
774 */ |
676 { |
775 { |
677 LOG_FUNC |
776 OstTraceFunctionEntry0( CUSBDEVICE_DOCANCEL_ENTRY ); |
678 |
777 |
679 switch (iServiceState) |
778 switch (iServiceState) |
680 { |
779 { |
681 case EUsbServiceStarting: |
780 case EUsbServiceStarting: |
682 case EUsbServiceStopping: |
781 case EUsbServiceStopping: |
683 iUsbClassControllerIterator->Current()->Cancel(); |
782 iUsbClassControllerIterator->Current()->Cancel(); |
684 break; |
783 break; |
685 |
784 |
686 default: |
785 default: |
687 __ASSERT_DEBUG( EFalse, _USB_PANIC(KUsbDevicePanicCategory, EBadAsynchronousCall) ); |
786 |
688 break; |
787 OstTrace1( TRACE_FATAL, CUSBDEVICE_DOCANCEL, "CUsbDevice::DoCancel;Panic reason=%d", EBadAsynchronousCall ); |
689 } |
788 __ASSERT_DEBUG( EFalse, User::Panic(KUsbDevicePanicCategory, EBadAsynchronousCall ) ); |
|
789 break; |
|
790 } |
|
791 OstTraceFunctionExit0( CUSBDEVICE_DOCANCEL_EXIT ); |
690 } |
792 } |
691 |
793 |
692 TInt CUsbDevice::RunError(TInt aError) |
794 TInt CUsbDevice::RunError(TInt aError) |
693 /** |
795 /** |
694 * Standard active object RunError function. Handles errors which occur when |
796 * Standard active object RunError function. Handles errors which occur when |
757 * this situation, we should just stop all the classes we can. |
861 * this situation, we should just stop all the classes we can. |
758 * |
862 * |
759 * @param aError The error that's occurred |
863 * @param aError The error that's occurred |
760 */ |
864 */ |
761 { |
865 { |
762 LOG_FUNC |
866 OstTraceFunctionEntry0( CUSBDEVICE_UCCNERROR_ENTRY ); |
763 |
867 |
764 RunError(aError); |
868 RunError(aError); |
765 } |
869 OstTraceFunctionExit0( CUSBDEVICE_UCCNERROR_EXIT ); |
766 |
870 } |
767 |
871 |
768 #ifdef __FLOG_ACTIVE |
872 |
|
873 #ifdef _DEBUG |
769 void CUsbDevice::PrintDescriptor(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor) |
874 void CUsbDevice::PrintDescriptor(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor) |
770 { |
875 { |
771 LOGTEXT2(_L8("\tiLength is %d"), aDeviceDescriptor.iLength); |
876 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR, "CUsbDevice::PrintDescriptor;iLength=%d", aDeviceDescriptor.iLength ); |
772 LOGTEXT2(_L8("\tiDescriptorType is %d"), aDeviceDescriptor.iDescriptorType); |
877 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP1, "CUsbDevice::PrintDescriptor;iDescriptorType=%d", aDeviceDescriptor.iDescriptorType ); |
773 LOGTEXT2(_L8("\tBcdUsb is: 0x%04x"), aDeviceDescriptor.iBcdUsb); |
878 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP2, "CUsbDevice::PrintDescriptor;iBcdUsb=0x%04x", aDeviceDescriptor.iBcdUsb ); |
774 LOGTEXT2(_L8("\tDeviceClass is: 0x%02x"), aDeviceDescriptor.iDeviceClass); |
879 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP3, "CUsbDevice::PrintDescriptor;iDeviceClass=0x%02x", aDeviceDescriptor.iDeviceClass ); |
775 LOGTEXT2(_L8("\tDeviceSubClass is: 0x%02x"), aDeviceDescriptor.iDeviceSubClass); |
880 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP4, "CUsbDevice::PrintDescriptor;iDeviceSubClass=0x%02x", aDeviceDescriptor.iDeviceSubClass ); |
776 LOGTEXT2(_L8("\tDeviceProtocol is: 0x%02x"), aDeviceDescriptor.iDeviceProtocol); |
881 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP5, "CUsbDevice::PrintDescriptor;iDeviceProtocol=0x%02x", aDeviceDescriptor.iDeviceProtocol ); |
777 LOGTEXT2(_L8("\tiMaxPacketSize is: 0x%02x"), aDeviceDescriptor.iMaxPacketSize); |
882 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP6, "CUsbDevice::PrintDescriptor;iMaxPacketSize=0x%02x", aDeviceDescriptor.iMaxPacketSize ); |
778 |
883 |
779 LOGTEXT2(_L8("\tVendorId is: 0x%04x"), aDeviceDescriptor.iIdVendor); |
884 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP7, "CUsbDevice::PrintDescriptor;iIdVendor=0x%04x", aDeviceDescriptor.iIdVendor ); |
780 LOGTEXT2(_L8("\tProductId is: 0x%04x"), aDeviceDescriptor.iIdProduct); |
885 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP8, "CUsbDevice::PrintDescriptor;iProductId=0x%04x", aDeviceDescriptor.iProductId ); |
781 LOGTEXT2(_L8("\tBcdDevice is: 0x%04x"), aDeviceDescriptor.iBcdDevice); |
886 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP9, "CUsbDevice::PrintDescriptor;iBcdDevice=0x%04x", aDeviceDescriptor.iBcdDevice ); |
782 |
887 |
783 LOGTEXT2(_L8("\tiManufacturer is: 0x%04x"), aDeviceDescriptor.iManufacturer); |
888 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP10, "CUsbDevice::PrintDescriptor;iManufacturer=0x%04x", aDeviceDescriptor.iManufacturer ); |
784 LOGTEXT2(_L8("\tiSerialNumber is: 0x%04x"), aDeviceDescriptor.iSerialNumber); |
889 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP11, "CUsbDevice::PrintDescriptor;iSerialNumber=0x%04x", aDeviceDescriptor.iSerialNumber ); |
785 LOGTEXT2(_L8("\tiNumConfigurations is: 0x%04x"), aDeviceDescriptor.iNumConfigurations); |
890 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP12, "CUsbDevice::PrintDescriptor;iNumConfigurations=0x%04x", aDeviceDescriptor.iNumConfigurations ); |
786 } |
891 } |
787 #endif |
892 #endif |
788 // |
893 // |
789 void CUsbDevice::SetDeviceDescriptorL() |
894 void CUsbDevice::SetDeviceDescriptorL() |
790 /** |
895 /** |
791 * Modifies the USB device descriptor. |
896 * Modifies the USB device descriptor. |
792 */ |
897 */ |
793 { |
898 { |
794 LOG_FUNC |
899 OstTraceFunctionEntry0( CUSBDEVICE_SETDEVICEDESCRIPTORL_ENTRY ); |
795 |
900 |
796 #ifndef __WINS__ |
901 #if !defined(__OVER_DUMMYUSBDI__) && !defined(__WINS__) |
797 |
902 |
798 TInt desSize = 0; |
903 TInt desSize = 0; |
799 iLdd.GetDeviceDescriptorSize(desSize); |
904 iLdd.GetDeviceDescriptorSize(desSize); |
800 LOGTEXT2(_L8("UDeviceDescriptorSize = %d"), desSize); |
905 OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETDEVICEDESCRIPTORL, "CUsbDevice::SetDeviceDescriptorL;UDeviceDescriptorSize = %d", desSize ); |
801 HBufC8* deviceBuf = HBufC8::NewLC(desSize); |
906 HBufC8* deviceBuf = HBufC8::NewLC(desSize); |
802 TPtr8 devicePtr = deviceBuf->Des(); |
907 TPtr8 devicePtr = deviceBuf->Des(); |
803 devicePtr.SetLength(0); |
908 devicePtr.SetLength(0); |
804 |
909 |
805 TInt ret = iLdd.GetDeviceDescriptor(devicePtr); |
910 TInt ret = iLdd.GetDeviceDescriptor(devicePtr); |
806 |
911 |
807 if (ret != KErrNone) |
912 if (ret != KErrNone) |
808 { |
913 { |
809 LOGTEXT2(_L8("Unable to fetch device descriptor. Error: %d"), ret); |
914 OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETDEVICEDESCRIPTORL_DUP1, "CUsbDevice::SetDeviceDescriptorL;Unable to fetch device descriptor. Error: %d", ret ); |
810 LEAVEL(ret); |
915 User::Leave(ret); |
811 } |
916 } |
812 |
917 |
813 TUsbDeviceDescriptor* deviceDescriptor = reinterpret_cast<TUsbDeviceDescriptor*>( |
918 TUsbDeviceDescriptor* deviceDescriptor = reinterpret_cast<TUsbDeviceDescriptor*>( |
814 const_cast<TUint8*>(devicePtr.Ptr())); |
919 const_cast<TUint8*>(devicePtr.Ptr())); |
815 |
920 |
856 { |
966 { |
857 aDeviceDescriptor.iDeviceClass = KUsbDefaultDeviceClass; |
967 aDeviceDescriptor.iDeviceClass = KUsbDefaultDeviceClass; |
858 aDeviceDescriptor.iDeviceSubClass = KUsbDefaultDeviceSubClass; |
968 aDeviceDescriptor.iDeviceSubClass = KUsbDefaultDeviceSubClass; |
859 aDeviceDescriptor.iDeviceProtocol = KUsbDefaultDeviceProtocol; |
969 aDeviceDescriptor.iDeviceProtocol = KUsbDefaultDeviceProtocol; |
860 aDeviceDescriptor.iIdVendor = KUsbDefaultVendorId; |
970 aDeviceDescriptor.iIdVendor = KUsbDefaultVendorId; |
861 aDeviceDescriptor.iIdProduct = KUsbDefaultProductId; |
971 aDeviceDescriptor.iProductId = KUsbDefaultProductId; |
862 } |
972 } |
863 |
973 |
864 void CUsbDevice::SetUsbDeviceSettingsL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor) |
974 void CUsbDevice::SetUsbDeviceSettingsFromPersonalityL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor) |
865 /** |
975 /** |
866 * Configure the USB device, reading in the settings from a |
976 * Configure the USB device from the current personality. |
867 * resource file where possible. |
|
868 * |
977 * |
869 * @param aDeviceDescriptor The device descriptor for the USB device |
978 * @param aDeviceDescriptor The device descriptor for the USB device |
870 */ |
979 */ |
871 { |
980 { |
872 LOG_FUNC |
981 OstTraceFunctionEntry0( CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_ENTRY ); |
873 |
982 |
874 // First, use the default values |
983 // First, use the default values |
875 LOGTEXT(_L8("Setting default values for the configuration")); |
984 OstTrace0( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;Setting default values for the configuration" ); |
876 SetUsbDeviceSettingsDefaultsL(aDeviceDescriptor); |
985 SetUsbDeviceSettingsDefaultsL(aDeviceDescriptor); |
877 |
986 |
878 // Now try to get the configuration from the resource file |
987 // Now try to get the configuration from the current personality |
879 RFs fs; |
988 aDeviceDescriptor.iDeviceClass = iCurrentPersonality->DeviceClass(); |
880 LEAVEIFERRORL(fs.Connect()); |
989 aDeviceDescriptor.iDeviceSubClass = iCurrentPersonality->DeviceSubClass(); |
881 CleanupClosePushL(fs); |
990 aDeviceDescriptor.iDeviceProtocol = iCurrentPersonality->DeviceProtocol(); |
882 |
991 aDeviceDescriptor.iIdVendor = iDeviceConfiguration.iVendorId; |
883 RResourceFile resource; |
992 aDeviceDescriptor.iProductId = iCurrentPersonality->ProductId(); |
884 TRAPD(err, resource.OpenL(fs, KUsbManagerResource)); |
993 aDeviceDescriptor.iBcdDevice = iCurrentPersonality->BcdDevice(); |
885 LOGTEXT2(_L8("Opened resource file with error %d"), err); |
994 aDeviceDescriptor.iNumConfigurations = iCurrentPersonality->NumConfigurations(); |
886 |
995 |
887 if (err != KErrNone) |
996 |
888 { |
997 #ifndef __OVER_DUMMYUSBDI__ |
889 LOGTEXT(_L8("Unable to open resource file: using default settings")); |
|
890 CleanupStack::PopAndDestroy(&fs); |
|
891 return; |
|
892 } |
|
893 |
|
894 CleanupClosePushL(resource); |
|
895 |
|
896 resource.ConfirmSignatureL(KUsbManagerResourceVersion); |
|
897 |
|
898 HBufC8* id = resource.AllocReadLC(USB_CONFIG); |
|
899 |
|
900 // The format of the USB resource structure is: |
|
901 // |
|
902 // STRUCT usb_configuration |
|
903 // { |
|
904 // WORD vendorId = 0x0e22; |
|
905 // WORD productId = 0x000b; |
|
906 // WORD bcdDevice = 0x0000; |
|
907 // LTEXT manufacturer = "Symbian Ltd."; |
|
908 // LTEXT product = "Symbian OS"; |
|
909 // } |
|
910 // |
|
911 // Note that the resource must be read in this order! |
|
912 |
|
913 TResourceReader reader; |
|
914 reader.SetBuffer(id); |
|
915 |
|
916 aDeviceDescriptor.iIdVendor = static_cast<TUint16>(reader.ReadUint16()); |
|
917 aDeviceDescriptor.iIdProduct = static_cast<TUint16>(reader.ReadUint16()); |
|
918 aDeviceDescriptor.iBcdDevice = static_cast<TUint16>(reader.ReadUint16()); |
|
919 |
|
920 // Try to read device and manufacturer name from new SysUtil API |
|
921 TPtrC16 sysUtilModelName; |
|
922 TPtrC16 sysUtilManuName; |
|
923 |
|
924 // This method returns ownership. |
|
925 CDeviceTypeInformation* deviceInfo = SysUtil::GetDeviceTypeInfoL(); |
|
926 CleanupStack::PushL(deviceInfo); |
|
927 TInt gotSysUtilModelName = deviceInfo->GetModelName(sysUtilModelName); |
|
928 TInt gotSysUtilManuName = deviceInfo->GetManufacturerName(sysUtilManuName); |
|
929 |
|
930 TPtrC manufacturerString = reader.ReadTPtrC(); |
|
931 TPtrC productString = reader.ReadTPtrC(); |
|
932 |
|
933 // If we succesfully read the manufacturer or device name from SysUtil API |
|
934 // then set these results, otherwise use the values defined in resource file |
|
935 #ifndef __WINS__ |
998 #ifndef __WINS__ |
936 if (gotSysUtilManuName == KErrNone) |
999 TInt err = iLdd.SetManufacturerStringDescriptor(*(iDeviceConfiguration.iManufacturerName)); |
937 { |
1000 if(err < 0) |
938 LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(sysUtilManuName)); |
1001 { |
939 } |
1002 OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP7, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;iLdd.SetManufacturerStringDescriptor(*(iCurrentPersonality->Manufacturer())) with error=%d", err ); |
940 else |
1003 User::Leave(err); |
941 { |
1004 } |
942 LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(manufacturerString)); |
1005 err = iLdd.SetProductStringDescriptor(*(iDeviceConfiguration.iProductName)); |
943 } |
1006 if(err < 0) |
944 |
1007 { |
945 if (gotSysUtilModelName == KErrNone) |
1008 OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP6, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;iLdd.SetProductStringDescriptor(*(iCurrentPersonality->Product())) with error=%d", err ); |
946 { |
1009 User::Leave(err); |
947 LEAVEIFERRORL(iLdd.SetProductStringDescriptor(sysUtilModelName)); |
1010 } |
948 } |
1011 |
949 else |
1012 |
950 { |
|
951 LEAVEIFERRORL(iLdd.SetProductStringDescriptor(productString)); |
|
952 } |
|
953 #endif // __WINS__ |
|
954 |
|
955 #ifdef __FLOG_ACTIVE |
|
956 PrintDescriptor(aDeviceDescriptor); |
|
957 TBuf8<KUsbStringDescStringMaxSize> narrowString; |
|
958 narrowString.Copy(manufacturerString); |
|
959 LOGTEXT2(_L8("Manufacturer is: '%S'"), &narrowString); |
|
960 narrowString.Copy(productString); |
|
961 LOGTEXT2(_L8("Product is: '%S'"), &narrowString); |
|
962 #endif // __FLOG_ACTIVE |
|
963 |
|
964 #ifndef __WINS__ |
|
965 //Read the published serial number. The key is the UID KUidUsbmanServer = 0x101FE1DB |
1013 //Read the published serial number. The key is the UID KUidUsbmanServer = 0x101FE1DB |
966 TBuf16<KUsbStringDescStringMaxSize> serNum; |
1014 TBuf16<KUsbStringDescStringMaxSize> serNum; |
967 TInt r = RProperty::Get(KUidSystemCategory,0x101FE1DB,serNum); |
1015 TInt r = RProperty::Get(KUidSystemCategory,0x101FE1DB,serNum); |
968 if(r==KErrNone) |
1016 if(r==KErrNone) |
969 { |
1017 { |
970 #ifdef __FLOG_ACTIVE |
1018 #ifdef _DEBUG |
971 TBuf8<KUsbStringDescStringMaxSize> narrowString; |
1019 OstTraceExt1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP1, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;Setting published SerialNumber: %S", serNum ); |
972 narrowString.Copy(serNum); |
1020 #endif//_DEBUG |
973 LOGTEXT2(_L8("Setting published SerialNumber: %S"), &narrowString); |
|
974 #endif // __FLOG_ACTIVE |
|
975 //USB spec doesn't give any constraints on what constitutes a valid serial number. |
1021 //USB spec doesn't give any constraints on what constitutes a valid serial number. |
976 //As long as it is a string descriptor it is valid. |
1022 //As long as it is a string descriptor it is valid. |
977 LEAVEIFERRORL(iLdd.SetSerialNumberStringDescriptor(serNum)); |
1023 err = iLdd.SetSerialNumberStringDescriptor(serNum); |
978 } |
1024 if(err < 0) |
979 #ifdef __FLOG_ACTIVE |
1025 { |
|
1026 OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP3, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;iLdd.SetSerialNumberStringDescriptor(serNum) with error=%d", err ); |
|
1027 User::Leave(err); |
|
1028 } |
|
1029 } |
|
1030 #ifdef _DEBUG |
980 else |
1031 else |
981 { |
1032 { |
982 LOGTEXT(_L8("SerialNumber has not been published")); |
1033 OstTrace0( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP2, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;SerialNumber has not been published" ); |
983 } |
1034 } |
984 #endif // __FLOG_ACTIVE |
1035 #endif // _DEBUG |
985 #endif // __WINS__ |
1036 |
986 |
1037 #endif |
987 |
1038 #endif // __OVER_DUMMYUSBDI__ |
988 CleanupStack::PopAndDestroy(4, &fs); // deviceInfo, id, resource, fs |
1039 |
989 } |
1040 |
990 |
1041 #ifdef _DEBUG |
991 void CUsbDevice::SetUsbDeviceSettingsFromPersonalityL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor) |
|
992 /** |
|
993 * Configure the USB device from the current personality. |
|
994 * |
|
995 * @param aDeviceDescriptor The device descriptor for the USB device |
|
996 */ |
|
997 { |
|
998 LOG_FUNC |
|
999 |
|
1000 // First, use the default values |
|
1001 LOGTEXT(_L8("Setting default values for the configuration")); |
|
1002 SetUsbDeviceSettingsDefaultsL(aDeviceDescriptor); |
|
1003 |
|
1004 // Now try to get the configuration from the current personality |
|
1005 const CUsbDevice::TUsbDeviceDescriptor& deviceDes = iCurrentPersonality->DeviceDescriptor(); |
|
1006 aDeviceDescriptor.iDeviceClass = deviceDes.iDeviceClass; |
|
1007 aDeviceDescriptor.iDeviceSubClass = deviceDes.iDeviceSubClass; |
|
1008 aDeviceDescriptor.iDeviceProtocol = deviceDes.iDeviceProtocol; |
|
1009 aDeviceDescriptor.iIdVendor = deviceDes.iIdVendor; |
|
1010 aDeviceDescriptor.iIdProduct = deviceDes.iIdProduct; |
|
1011 aDeviceDescriptor.iBcdDevice = deviceDes.iBcdDevice; |
|
1012 aDeviceDescriptor.iSerialNumber = deviceDes.iSerialNumber; |
|
1013 aDeviceDescriptor.iNumConfigurations = deviceDes.iNumConfigurations; |
|
1014 |
|
1015 #ifndef __WINS__ |
|
1016 LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(*(iCurrentPersonality->Manufacturer()))); |
|
1017 LEAVEIFERRORL(iLdd.SetProductStringDescriptor(*(iCurrentPersonality->Product()))); |
|
1018 |
|
1019 //Read the published serial number. The key is the UID KUidUsbmanServer = 0x101FE1DB |
|
1020 TBuf16<KUsbStringDescStringMaxSize> serNum; |
|
1021 TInt r = RProperty::Get(KUidSystemCategory,0x101FE1DB,serNum); |
|
1022 if(r==KErrNone) |
|
1023 { |
|
1024 #ifdef __FLOG_ACTIVE |
|
1025 TBuf8<KUsbStringDescStringMaxSize> narrowString; |
|
1026 narrowString.Copy(serNum); |
|
1027 LOGTEXT2(_L8("Setting published SerialNumber: %S"), &narrowString); |
|
1028 #endif // __FLOG_ACTIVE |
|
1029 //USB spec doesn't give any constraints on what constitutes a valid serial number. |
|
1030 //As long as it is a string descriptor it is valid. |
|
1031 LEAVEIFERRORL(iLdd.SetSerialNumberStringDescriptor(serNum)); |
|
1032 } |
|
1033 #ifdef __FLOG_ACTIVE |
|
1034 else |
|
1035 { |
|
1036 LOGTEXT(_L8("SerialNumber has not been published")); |
|
1037 } |
|
1038 #endif // __FLOG_ACTIVE |
|
1039 #endif // __WINS__ |
|
1040 |
|
1041 |
|
1042 #ifdef __FLOG_ACTIVE |
|
1043 PrintDescriptor(aDeviceDescriptor); |
1042 PrintDescriptor(aDeviceDescriptor); |
1044 |
1043 |
|
1044 #ifndef __OVER_DUMMYUSBDI__ |
1045 #ifndef __WINS__ |
1045 #ifndef __WINS__ |
1046 TBuf16<KUsbStringDescStringMaxSize> wideString; |
1046 TBuf16<KUsbStringDescStringMaxSize> wideString; |
1047 TBuf8<KUsbStringDescStringMaxSize> narrowString; |
1047 TInt tmp = iLdd.GetConfigurationStringDescriptor(wideString); |
1048 |
1048 if(tmp < 0) |
1049 LEAVEIFERRORL(iLdd.GetConfigurationStringDescriptor(wideString)); |
1049 { |
1050 narrowString.Copy(wideString); |
1050 OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP5, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;iLdd.GetConfigurationStringDescriptor(wideString) with error=%d", tmp ); |
1051 LOGTEXT2(_L8("Configuration is: '%S'"), &narrowString); |
1051 User::Leave(tmp); |
1052 #endif // __WINS__ |
1052 } |
1053 |
1053 OstTraceExt1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP4, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;Configuration is:%S", wideString ); |
1054 #endif // __FLOG_ACTIVE |
1054 #endif |
|
1055 #endif // __OVER_DUMMYUSBDI__ |
|
1056 |
|
1057 #endif // _DEBUG |
1055 } |
1058 } |
1056 |
1059 |
1057 void CUsbDevice::TryStartL(TInt aPersonalityId) |
1060 void CUsbDevice::TryStartL(TInt aPersonalityId) |
1058 /** |
1061 /** |
1059 * Start all USB classes associated with the personality identified |
1062 * Start all USB classes associated with the personality identified |
1105 * @param aPeraonalityId a personality id |
1110 * @param aPeraonalityId a personality id |
1106 * @return a const pointer to the CPersonality object whose id is aPersonalityId if found |
1111 * @return a const pointer to the CPersonality object whose id is aPersonalityId if found |
1107 * or 0 otherwise. |
1112 * or 0 otherwise. |
1108 */ |
1113 */ |
1109 { |
1114 { |
1110 LOG_FUNC |
1115 OstTraceFunctionEntry0( CUSBDEVICE_GETPERSONALITY_ENTRY ); |
1111 |
1116 |
1112 TInt count = iSupportedPersonalities.Count(); |
1117 TInt count = iSupportedPersonalities.Count(); |
1113 for (TInt i = 0; i < count; i++) |
1118 for (TInt i = 0; i < count; i++) |
1114 { |
1119 { |
1115 if (iSupportedPersonalities[i]->PersonalityId() == aPersonalityId) |
1120 if (iSupportedPersonalities[i]->PersonalityId() == aPersonalityId) |
1116 { |
1121 { |
|
1122 OstTraceFunctionExit0( CUSBDEVICE_GETPERSONALITY_EXIT ); |
1117 return iSupportedPersonalities[i]; |
1123 return iSupportedPersonalities[i]; |
1118 } |
1124 } |
1119 } |
1125 } |
1120 |
1126 |
|
1127 OstTraceFunctionExit0( CUSBDEVICE_GETPERSONALITY_EXIT_DUP1 ); |
1121 return 0; |
1128 return 0; |
1122 } |
1129 } |
1123 |
1130 |
1124 void CUsbDevice::SetCurrentPersonalityL(TInt aPersonalityId) |
1131 void CUsbDevice::SetCurrentPersonalityL(TInt aPersonalityId) |
1125 /** |
1132 /** |
1126 * Sets the current personality to the personality with id aPersonalityId |
1133 * Sets the current personality to the personality with id aPersonalityId |
1127 */ |
1134 */ |
1128 { |
1135 { |
1129 LOG_FUNC |
1136 OstTraceFunctionEntry0( CUSBDEVICE_SETCURRENTPERSONALITYL_ENTRY ); |
1130 const CPersonality* personality = GetPersonality(aPersonalityId); |
1137 const CPersonality* personality = GetPersonality(aPersonalityId); |
1131 if (!personality) |
1138 if (!personality) |
1132 { |
1139 { |
1133 LOGTEXT(_L8("Personality id not found")); |
1140 OstTrace0( TRACE_NORMAL, CUSBDEVICE_SETCURRENTPERSONALITYL, "CUsbDevice::SetCurrentPersonalityL;Personality id not found" ); |
1134 LEAVEL(KErrNotFound); |
1141 User::Leave(KErrNotFound); |
1135 } |
1142 } |
1136 |
1143 |
1137 iCurrentPersonality = personality; |
1144 iCurrentPersonality = personality; |
|
1145 OstTraceFunctionExit0( CUSBDEVICE_SETCURRENTPERSONALITYL_EXIT ); |
1138 } |
1146 } |
1139 |
1147 |
1140 void CUsbDevice::ValidatePersonalitiesL() |
1148 void CUsbDevice::ValidatePersonalitiesL() |
1141 /** |
1149 /** |
1142 * Verifies all class controllers associated with each personality are loaded. |
1150 * Verifies all class controllers associated with each personality are loaded. |
1143 * Leave if validation fails. |
1151 * Leave if validation fails. |
1144 */ |
1152 */ |
1145 { |
1153 { |
1146 LOG_FUNC |
1154 OstTraceFunctionEntry0( CUSBDEVICE_VALIDATEPERSONALITIESL_ENTRY ); |
1147 |
1155 |
1148 TInt personalityCount = iSupportedPersonalities.Count(); |
1156 TInt personalityCount = iSupportedPersonalities.Count(); |
1149 for (TInt i = 0; i < personalityCount; i++) |
1157 for (TInt i = 0; i < personalityCount; i++) |
1150 { |
1158 { |
1151 const RArray<TUid>& classUids = iSupportedPersonalities[i]->SupportedClasses(); |
1159 const RArray<CPersonalityConfigurations::TUsbClasses>& classes = iSupportedPersonalities[i]->SupportedClasses(); |
1152 TInt uidCount = classUids.Count(); |
1160 TInt uidCount = classes.Count(); |
1153 for (TInt j = 0; j < uidCount; j++) |
1161 for (TInt j = 0; j < uidCount; j++) |
1154 { |
1162 { |
1155 TInt ccCount = iSupportedClassUids.Count(); |
1163 TInt ccCount = iSupportedClassUids.Count(); |
1156 TInt k; |
1164 TInt k; |
|
1165 OstTrace1( TRACE_NORMAL, CUSBDEVICE_VALIDATEPERSONALITIESL_DUP1, "CUsbDevice::ValidatePersonalitiesL;iSupportedClassUids Count = %d", ccCount ); |
1157 for (k = 0; k < ccCount; k++) |
1166 for (k = 0; k < ccCount; k++) |
1158 { |
1167 { |
1159 if (iSupportedClassUids[k] == classUids[j]) |
1168 OstTraceExt4( TRACE_NORMAL, CUSBDEVICE_VALIDATEPERSONALITIESL_DUP2, "CUsbDevice::ValidatePersonalitiesL;iSupportedClassUids %d %x classes %d %x", k, iSupportedClassUids[k].iUid, j, classes[j].iClassUid.iUid ); |
|
1169 if (iSupportedClassUids[k] == classes[j].iClassUid) |
1160 { |
1170 { |
1161 break; |
1171 break; |
1162 } |
1172 } |
1163 } |
1173 } |
1164 if (k == ccCount) |
1174 if (k == ccCount) |
1165 { |
1175 { |
1166 LOGTEXT(_L8("personality validation failed")); |
1176 OstTrace0( TRACE_NORMAL, CUSBDEVICE_VALIDATEPERSONALITIESL, "CUsbDevice::ValidatePersonalitiesL;personality validation failed" ); |
1167 LEAVEL(KErrAbort); |
1177 User::Leave(KErrAbort); |
1168 } |
1178 } |
1169 } |
1179 } |
1170 } |
1180 } |
|
1181 OstTraceFunctionExit0( CUSBDEVICE_VALIDATEPERSONALITIESL_EXIT ); |
1171 } |
1182 } |
1172 /** |
1183 /** |
1173 Converts text string with UIDs to array of Uint |
1184 Converts text string with UIDs to array of Uint |
1174 |
1185 |
1175 If there is an error during the conversion, this function will not clean-up, |
1186 If there is an error during the conversion, this function will not clean-up, |
1196 input.Inc(); |
1214 input.Inc(); |
1197 } |
1215 } |
1198 |
1216 |
1199 // Convert and add to array |
1217 // Convert and add to array |
1200 TUint val; |
1218 TUint val; |
1201 LEAVEIFERRORL(input.Val(val,EHex)); |
1219 TInt err = input.Val(val,EHex); |
|
1220 if(err < 0) |
|
1221 { |
|
1222 OstTrace1( TRACE_NORMAL, CUSBDEVICE_CONVERTUIDSL_DUP1, "CUsbDevice::ConvertUidsL;input.Val(val,EHex) with error=%d", err ); |
|
1223 User::Leave(err); |
|
1224 } |
1202 aUidArray.AppendL(val); |
1225 aUidArray.AppendL(val); |
1203 } |
1226 } |
1204 while (!input.Eos()); |
1227 while (!input.Eos()); |
|
1228 OstTraceFunctionExit0( CUSBDEVICE_CONVERTUIDSL_EXIT ); |
1205 } |
1229 } |
1206 |
1230 |
1207 void CUsbDevice::ReadPersonalitiesL() |
1231 void CUsbDevice::ReadPersonalitiesL() |
1208 /** |
1232 { |
1209 * Reads configured personalities from the resource file |
1233 OstTraceFunctionEntry0( CUSBDEVICE_READPERSONALITIESL_ENTRY ); |
1210 */ |
1234 TPtrC16 sysUtilModelName; |
1211 { |
1235 TPtrC16 sysUtilManuName; |
1212 LOG_FUNC |
1236 |
1213 iPersonalityCfged = EFalse; |
1237 iPersonalityCfged = EFalse; |
1214 // Now try to connect to file server |
1238 |
1215 RFs fs; |
1239 iCenRepManager->ReadDeviceConfigurationL(iDeviceConfiguration); |
1216 LEAVEIFERRORL(fs.Connect()); |
1240 |
1217 CleanupClosePushL(fs); |
1241 iCenRepManager->ReadPersonalitiesL(iSupportedPersonalities); |
1218 |
1242 |
1219 TFileName resourceFileName; |
1243 //update info for SetManufacturer & SetProduct |
1220 ResourceFileNameL(resourceFileName); |
1244 CDeviceTypeInformation* deviceInfo = SysUtil::GetDeviceTypeInfoL(); |
1221 RResourceFile resource; |
1245 CleanupStack::PushL(deviceInfo); |
1222 TRAPD(err, resource.OpenL(fs, resourceFileName)); |
1246 TInt gotSysUtilModelName = deviceInfo->GetModelName(sysUtilModelName); |
1223 LOGTEXT2(_L8("Opened resource file with error %d"), err); |
1247 TInt gotSysUtilManuName = deviceInfo->GetManufacturerName(sysUtilManuName); |
1224 |
1248 |
1225 if (err != KErrNone) |
1249 //To overlap info |
1226 { |
1250 if (gotSysUtilManuName == KErrNone) |
1227 LOGTEXT(_L8("Unable to open resource file")); |
1251 { |
1228 CleanupStack::PopAndDestroy(&fs); |
1252 iDeviceConfiguration.iManufacturerName->Des().Copy(sysUtilManuName); |
1229 return; |
1253 } |
1230 } |
1254 |
1231 |
1255 if (gotSysUtilModelName == KErrNone) |
1232 CleanupClosePushL(resource); |
1256 { |
1233 |
1257 iDeviceConfiguration.iProductName->Des().Copy(sysUtilModelName); |
1234 TInt resourceVersion = resource.SignatureL(); |
1258 } |
1235 LOGTEXT2(_L8("Resource file signature is %d"), resourceVersion); |
1259 CleanupStack::PopAndDestroy(deviceInfo); |
1236 // Check for the version is valid(EUsbManagerResourceVersionOne, EUsbManagerResourceVersionTwo |
1260 iPersonalityCfged = ETrue; |
1237 // or EUsbManagerResourceVersionThree). |
1261 OstTraceFunctionExit0( CUSBDEVICE_READPERSONALITIESL_EXIT ); |
1238 if(resourceVersion > EUsbManagerResourceVersionThree) |
1262 } |
1239 { |
|
1240 LOGTEXT2(_L8("Version of resource file is valid (>%d)"), EUsbManagerResourceVersionThree); |
|
1241 User::LeaveIfError(KErrNotSupported); |
|
1242 } |
|
1243 |
|
1244 resource.ConfirmSignatureL(resourceVersion); |
|
1245 |
|
1246 HBufC8* personalityBuf = 0; |
|
1247 TRAPD(ret, personalityBuf = resource.AllocReadL(DEVICE_PERSONALITIES)); |
|
1248 // If personalities resource is not found, swallow the error and return |
|
1249 // as no specified personalities is a valid configuration |
|
1250 if (ret == KErrNotFound) |
|
1251 { |
|
1252 LOGTEXT(_L8("Personalities are not configured")); |
|
1253 CleanupStack::PopAndDestroy(2, &fs); |
|
1254 return; |
|
1255 } |
|
1256 // Otherwise leave noisily if the AllocRead fails |
|
1257 LEAVEIFERRORL(ret); |
|
1258 CleanupStack::PushL(personalityBuf); |
|
1259 |
|
1260 // The format of the USB resource structure is: |
|
1261 // |
|
1262 // STRUCT PERSONALITY |
|
1263 // { |
|
1264 // WORD bcdDeviceClass; |
|
1265 // WORD bcdDeviceSubClass; |
|
1266 // WORD protocol; |
|
1267 // WORD numConfigurations; |
|
1268 // WORD vendorId; |
|
1269 // WORD productId; |
|
1270 // WORD bcdDevice; |
|
1271 // LTEXT manufacturer; |
|
1272 // LTEXT product; |
|
1273 // WORD id; // personality id |
|
1274 // LTEXT class_uids; |
|
1275 // LTEXT description; // personality description |
|
1276 // LTEXT detailedDescription; //detailed description. This is in version 2 |
|
1277 // LONG Property; |
|
1278 // } |
|
1279 // |
|
1280 // Note that the resource must be read in this order! |
|
1281 |
|
1282 TResourceReader reader; |
|
1283 reader.SetBuffer(personalityBuf); |
|
1284 |
|
1285 TUint16 personalityCount = static_cast<TUint16>(reader.ReadUint16()); |
|
1286 |
|
1287 // Read the manufacturer and device name (product) here from SysUtil class |
|
1288 TPtrC16 sysUtilModelName; |
|
1289 TPtrC16 sysUtilManuName; |
|
1290 |
|
1291 // This method returns ownership. |
|
1292 CDeviceTypeInformation* deviceInfo = SysUtil::GetDeviceTypeInfoL(); |
|
1293 CleanupStack::PushL(deviceInfo); |
|
1294 TInt gotSysUtilModelName = deviceInfo->GetModelName(sysUtilModelName); |
|
1295 TInt gotSysUtilManuName = deviceInfo->GetManufacturerName(sysUtilManuName); |
|
1296 |
|
1297 for (TInt idx = 0; idx < personalityCount; idx++) |
|
1298 { |
|
1299 // read a personality |
|
1300 TUint8 bDeviceClass = static_cast<TUint8>(reader.ReadUint8()); |
|
1301 TUint8 bDeviceSubClass = static_cast<TUint8>(reader.ReadUint8()); |
|
1302 TUint8 protocol = static_cast<TUint8>(reader.ReadUint8()); |
|
1303 TUint8 numConfigurations = static_cast<TUint8>(reader.ReadUint8()); |
|
1304 TUint16 vendorId = static_cast<TUint16>(reader.ReadUint16()); |
|
1305 TUint16 productId = static_cast<TUint16>(reader.ReadUint16()); |
|
1306 TUint16 bcdDevice = static_cast<TUint16>(reader.ReadUint16()); |
|
1307 TPtrC manufacturer = reader.ReadTPtrC(); |
|
1308 TPtrC product = reader.ReadTPtrC(); |
|
1309 TUint16 id = static_cast<TUint16>(reader.ReadUint16()); |
|
1310 TPtrC uidsStr = reader.ReadTPtrC(); |
|
1311 TPtrC description = reader.ReadTPtrC(); |
|
1312 |
|
1313 RArray<TUint> uids; |
|
1314 CleanupClosePushL(uids); |
|
1315 ConvertUidsL(uidsStr, uids); |
|
1316 // creates a CPersonality object |
|
1317 CPersonality* personality = CPersonality::NewL(); |
|
1318 CleanupStack::PushL(personality); |
|
1319 |
|
1320 personality->SetVersion(resourceVersion); |
|
1321 |
|
1322 // populates personality object |
|
1323 personality->SetId(id); |
|
1324 |
|
1325 for (TInt uidIdx = 0; uidIdx < uids.Count(); uidIdx++) |
|
1326 { |
|
1327 LEAVEIFERRORL(personality->AddSupportedClasses(TUid::Uid(uids[uidIdx]))); |
|
1328 } |
|
1329 |
|
1330 // gets a handle to iDeviceDescriptor of personality |
|
1331 CUsbDevice::TUsbDeviceDescriptor& dvceDes = personality->DeviceDescriptor(); |
|
1332 if (gotSysUtilManuName == KErrNone) |
|
1333 { |
|
1334 personality->SetManufacturer(&sysUtilManuName); |
|
1335 } |
|
1336 else |
|
1337 { |
|
1338 personality->SetManufacturer(&manufacturer); |
|
1339 } |
|
1340 |
|
1341 if (gotSysUtilModelName == KErrNone) |
|
1342 { |
|
1343 personality->SetProduct(&sysUtilModelName); |
|
1344 } |
|
1345 else |
|
1346 { |
|
1347 personality->SetProduct(&product); |
|
1348 } |
|
1349 |
|
1350 personality->SetDescription(&description); |
|
1351 dvceDes.iDeviceClass = bDeviceClass; |
|
1352 dvceDes.iDeviceSubClass = bDeviceSubClass; |
|
1353 dvceDes.iDeviceProtocol = protocol; |
|
1354 dvceDes.iIdVendor = vendorId; |
|
1355 dvceDes.iIdProduct= productId; |
|
1356 dvceDes.iBcdDevice = bcdDevice; |
|
1357 dvceDes.iNumConfigurations = numConfigurations; |
|
1358 |
|
1359 //detailedDescription is only supported after EUsbManagerResourceVersionTwo |
|
1360 if(resourceVersion >= EUsbManagerResourceVersionTwo) |
|
1361 { |
|
1362 TPtrC detailedDescription = reader.ReadTPtrC(); |
|
1363 personality->SetDetailedDescription(&detailedDescription); |
|
1364 #ifdef __FLOG_ACTIVE |
|
1365 TBuf8<KUsbDescMaxSize_String> narrowLongBuf; |
|
1366 narrowLongBuf.Copy(detailedDescription); |
|
1367 LOGTEXT2(_L8("detailed description = '%S'"), &narrowLongBuf); |
|
1368 #endif // __FLOG_ACTIVE |
|
1369 } |
|
1370 |
|
1371 //Property is only supported after EUsbManagerResourceVersionThree |
|
1372 if(resourceVersion >= EUsbManagerResourceVersionThree) |
|
1373 { |
|
1374 TUint32 property = static_cast<TUint32>(reader.ReadUint32()); |
|
1375 personality->SetProperty(property); |
|
1376 #ifdef __FLOG_ACTIVE |
|
1377 LOGTEXT2(_L8("property = %d\n"), property); |
|
1378 #endif // __FLOG_ACTIVE |
|
1379 } |
|
1380 |
|
1381 // Append personality to iSupportedPersonalities |
|
1382 iSupportedPersonalities.AppendL(personality); |
|
1383 // Now pop off personality |
|
1384 CleanupStack::Pop(personality); |
|
1385 #ifdef __FLOG_ACTIVE |
|
1386 // Debugging |
|
1387 LOGTEXT2(_L8("personalityCount = %d\n"), personalityCount); |
|
1388 LOGTEXT2(_L8("bDeviceClass = %d\n"), bDeviceClass); |
|
1389 LOGTEXT2(_L8("bDeviceSubClass = %d\n"), bDeviceSubClass); |
|
1390 LOGTEXT2(_L8("protocol = %d\n"), protocol); |
|
1391 LOGTEXT2(_L8("numConfigurations = %d\n"), numConfigurations); |
|
1392 LOGTEXT2(_L8("vendorId = %d\n"), vendorId); |
|
1393 LOGTEXT2(_L8("productId = %d\n"), productId); |
|
1394 LOGTEXT2(_L8("bcdDevice = %d\n"), bcdDevice); |
|
1395 TBuf8<KMaxName> narrowBuf; |
|
1396 narrowBuf.Copy(manufacturer); |
|
1397 LOGTEXT2(_L8("manufacturer = '%S'"), &narrowBuf); |
|
1398 narrowBuf.Copy(product); |
|
1399 LOGTEXT2(_L8("product = '%S'"), &narrowBuf); |
|
1400 LOGTEXT2(_L8("id = %d\n"), id); |
|
1401 LOGTEXT(_L8("ClassUids{")); |
|
1402 for (TInt k = 0; k < uids.Count(); k++) |
|
1403 { |
|
1404 LOGTEXT2(_L8("%d"), uids[k]); |
|
1405 } |
|
1406 LOGTEXT(_L8("}")); |
|
1407 narrowBuf.Copy(description); |
|
1408 LOGTEXT2(_L8("description = '%S'"), &narrowBuf); |
|
1409 #endif // __FLOG_ACTIVE |
|
1410 CleanupStack::PopAndDestroy(&uids); // close uid array |
|
1411 } |
|
1412 |
|
1413 CleanupStack::PopAndDestroy(4, &fs); // deviceInfo, personalityBuf, resource, fs |
|
1414 iPersonalityCfged = ETrue; |
|
1415 } |
|
1416 |
1263 |
1417 void CUsbDevice::SelectClassControllersL() |
1264 void CUsbDevice::SelectClassControllersL() |
1418 /** |
1265 /** |
1419 * Selects class controllers for the current personality |
1266 * Selects class controllers for the current personality |
1420 */ |
1267 */ |
1421 { |
1268 { |
1422 LOG_FUNC |
1269 OstTraceFunctionEntry0( CUSBDEVICE_SELECTCLASSCONTROLLERSL_ENTRY ); |
1423 |
1270 const RArray<CPersonalityConfigurations::TUsbClasses>& classes = iCurrentPersonality->SupportedClasses(); |
1424 CreateClassControllersL(iCurrentPersonality->SupportedClasses()); |
1271 RArray<TUid> classUids; |
|
1272 CleanupClosePushL( classUids ); |
|
1273 TInt classCount = classes.Count(); |
|
1274 for(TInt classIndex = 0; classIndex<classCount; ++classIndex) |
|
1275 { |
|
1276 TUid uid = classes[classIndex].iClassUid; |
|
1277 classUids.AppendL(uid); |
|
1278 } |
|
1279 |
|
1280 CreateClassControllersL(classUids); |
|
1281 |
|
1282 CleanupStack::PopAndDestroy( &classUids ); |
|
1283 OstTraceFunctionExit0( CUSBDEVICE_SELECTCLASSCONTROLLERSL_EXIT ); |
1425 } |
1284 } |
1426 #ifdef USE_DUMMY_CLASS_CONTROLLER |
1285 #ifdef USE_DUMMY_CLASS_CONTROLLER |
1427 void CUsbDevice::CreateClassControllersL(const RArray<TUid>& /* aClassUids*/) |
1286 void CUsbDevice::CreateClassControllersL(const RArray<TUid>& /* aClassUids*/) |
1428 #else |
1287 #else |
1429 void CUsbDevice::CreateClassControllersL(const RArray<TUid>& aClassUids) |
1288 void CUsbDevice::CreateClassControllersL(const RArray<TUid>& aClassUids) |
1444 |
1303 |
1445 TInt count = aClassUids.Count(); |
1304 TInt count = aClassUids.Count(); |
1446 |
1305 |
1447 // destroy any class controller objects in iSupportedClasses and reset it for reuse |
1306 // destroy any class controller objects in iSupportedClasses and reset it for reuse |
1448 iSupportedClasses.ResetAndDestroy(); |
1307 iSupportedClasses.ResetAndDestroy(); |
1449 LOGTEXT2(_L8("aClassUids.Count() = %d\n"), count); |
1308 OstTrace1( TRACE_NORMAL, CUSBDEVICE_CREATECLASSCONTROLLERSL, "CUsbDevice::CreateClassControllersL;aClassUids.Count() = %d", count ); |
1450 for (TInt i = 0; i < count; i++) |
1309 for (TInt i = 0; i < count; i++) |
1451 { |
1310 { |
1452 CUsbClassControllerPlugIn* plugIn = CUsbClassControllerPlugIn::NewL(aClassUids[i], *this); |
1311 CUsbClassControllerPlugIn* plugIn = CUsbClassControllerPlugIn::NewL(aClassUids[i], *this); |
1453 AddClassControllerL(reinterpret_cast<CUsbClassControllerBase*>(plugIn), order); |
1312 AddClassControllerL(reinterpret_cast<CUsbClassControllerBase*>(plugIn), order); |
1454 } |
1313 } |
1455 #endif // USE_DUMMY_CLASS_CONTROLLER |
1314 #endif // USE_DUMMY_CLASS_CONTROLLER |
1456 |
1315 TInt err = iUsbClassControllerIterator->First(); |
1457 LEAVEIFERRORL(iUsbClassControllerIterator->First()); |
1316 if(err < 0) |
|
1317 { |
|
1318 OstTrace1( TRACE_NORMAL, CUSBDEVICE_CREATECLASSCONTROLLERSL_DUP1, "CUsbDevice::CreateClassControllersL;iUsbClassControllerIterator->First() with error=%d", err ); |
|
1319 User::Leave(err); |
|
1320 } |
1458 } |
1321 } |
1459 |
1322 |
1460 void CUsbDevice::SetDefaultPersonalityL() |
1323 void CUsbDevice::SetDefaultPersonalityL() |
1461 /** |
1324 /** |
1462 * Sets default personality. Used for Start request. |
1325 * Sets default personality. Used for Start request. |
1463 */ |
1326 */ |
1464 { |
1327 { |
1465 LOG_FUNC |
1328 OstTraceFunctionEntry0( CUSBDEVICE_SETDEFAULTPERSONALITYL_ENTRY ); |
1466 |
1329 |
1467 TInt smallestId = iSupportedPersonalities[0]->PersonalityId(); |
1330 TInt smallestId = iSupportedPersonalities[0]->PersonalityId(); |
1468 TInt count = iSupportedPersonalities.Count(); |
1331 TInt count = iSupportedPersonalities.Count(); |
1469 |
|
1470 for (TInt i = 1; i < count; i++) |
1332 for (TInt i = 1; i < count; i++) |
1471 { |
1333 { |
1472 if(iSupportedPersonalities[i]->PersonalityId() < smallestId) |
1334 if(iSupportedPersonalities[i]->PersonalityId() < smallestId) |
1473 { |
1335 { |
1474 smallestId = iSupportedPersonalities[i]->PersonalityId(); |
1336 smallestId = iSupportedPersonalities[i]->PersonalityId(); |
1475 } |
1337 } |
1476 } |
1338 } |
1477 |
1339 |
1478 SetCurrentPersonalityL(smallestId); |
1340 SetCurrentPersonalityL(smallestId); |
1479 SelectClassControllersL(); |
1341 SelectClassControllersL(); |
|
1342 OstTraceFunctionExit0( CUSBDEVICE_SETDEFAULTPERSONALITYL_EXIT ); |
1480 } |
1343 } |
1481 |
1344 |
1482 void CUsbDevice::LoadFallbackClassControllersL() |
1345 void CUsbDevice::LoadFallbackClassControllersL() |
1483 /** |
1346 /** |
1484 * Load class controllers for fallback situation: |
1347 * Load class controllers for fallback situation: |