46 #include "CUsbDeviceStateWatcher.h" |
45 #include "CUsbDeviceStateWatcher.h" |
47 #include "CPersonality.h" |
46 #include "CPersonality.h" |
48 #include "usbmancenrepmanager.h" |
47 #include "usbmancenrepmanager.h" |
49 #include "usbmanprivatecrkeys.h" |
48 #include "usbmanprivatecrkeys.h" |
50 |
49 |
|
50 #include "OstTraceDefinitions.h" |
|
51 #ifdef OST_TRACE_COMPILER_IN_USE |
|
52 #include "CUsbDeviceTraces.h" |
|
53 #endif |
|
54 |
|
55 |
51 _LIT(KUsbLDDName, "eusbc"); //Name used in call to User::LoadLogicalDevice |
56 _LIT(KUsbLDDName, "eusbc"); //Name used in call to User::LoadLogicalDevice |
52 _LIT(KUsbLDDFreeName, "Usbc"); //Name used in call to User::FreeLogicalDevice |
57 _LIT(KUsbLDDFreeName, "Usbc"); //Name used in call to User::FreeLogicalDevice |
53 |
58 |
54 #ifdef __FLOG_ACTIVE |
|
55 _LIT8(KLogComponent, "USBSVR"); |
|
56 #endif |
|
57 |
59 |
58 // Panic category only used in debug builds |
60 // Panic category only used in debug builds |
59 #ifdef _DEBUG |
61 #ifdef _DEBUG |
60 _LIT(KUsbDevicePanicCategory, "UsbDevice"); |
62 _LIT(KUsbDevicePanicCategory, "UsbDevice"); |
61 #endif |
63 #endif |
122 // the observers themselves. |
125 // the observers themselves. |
123 iObservers.Reset(); |
126 iObservers.Reset(); |
124 |
127 |
125 #ifndef __OVER_DUMMYUSBDI__ |
128 #ifndef __OVER_DUMMYUSBDI__ |
126 #ifndef __WINS__ |
129 #ifndef __WINS__ |
127 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 |
128 delete iDeviceStateWatcher; |
132 delete iDeviceStateWatcher; |
129 LOGTEXT(_L8("deleted device state watcher")); |
133 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CUSBDEVICE_DUP1, "CUsbDevice::~CUsbDevice;deleted device state watcher" ); |
130 |
134 |
131 iLdd.Close(); |
135 iLdd.Close(); |
132 |
136 |
133 LOGTEXT(_L8("Freeing logical device")); |
137 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CUSBDEVICE_DUP2, "CUsbDevice::~CUsbDevice;Freeing logical device" ); |
|
138 |
134 TInt err = User::FreeLogicalDevice(KUsbLDDFreeName); |
139 TInt err = User::FreeLogicalDevice(KUsbLDDFreeName); |
135 //Putting the LOGTEXT2 inside the if statement prevents a compiler |
140 //Putting the LOGTEXT2 inside the if statement prevents a compiler |
136 //warning about err being unused in UREL builds. |
141 //warning about err being unused in UREL builds. |
137 if(err) |
142 if(err) |
138 { |
143 { |
139 LOGTEXT2(_L8(" User::FreeLogicalDevice returned %d"),err); |
144 OstTrace1( TRACE_NORMAL, CUSBDEVICE_CUSBDEVICE_DUP3, "CUsbDevice::~CUsbDevice; User::FreeLogicalDevice returned err=%d", err ); |
140 } |
145 } |
141 #endif |
146 #endif |
142 #endif |
147 #endif |
143 |
148 |
144 delete iDefaultSerialNumber; |
149 delete iDefaultSerialNumber; |
|
150 OstTraceFunctionExit0( CUSBDEVICE_CUSBDEVICE_DES_EXIT ); |
145 } |
151 } |
146 |
152 |
147 |
153 |
148 CUsbDevice::CUsbDevice(CUsbServer& aUsbServer) |
154 CUsbDevice::CUsbDevice(CUsbServer& aUsbServer) |
149 : CActive(EPriorityStandard) |
155 : CActive(EPriorityStandard) |
162 void CUsbDevice::ConstructL() |
168 void CUsbDevice::ConstructL() |
163 /** |
169 /** |
164 * Performs 2nd phase construction of the USB device. |
170 * Performs 2nd phase construction of the USB device. |
165 */ |
171 */ |
166 { |
172 { |
167 LOG_FUNC |
173 OstTraceFunctionEntry0( CUSBDEVICE_CONSTRUCTL_ENTRY ); |
168 |
174 |
169 iEcom = &(REComSession::OpenL()); |
175 iEcom = &(REComSession::OpenL()); |
170 |
176 |
171 iUsbClassControllerIterator = new(ELeave) CUsbClassControllerIterator(iSupportedClasses); |
177 iUsbClassControllerIterator = new(ELeave) CUsbClassControllerIterator(iSupportedClasses); |
172 iCenRepManager = CUsbManCenRepManager::NewL(*this); |
178 iCenRepManager = CUsbManCenRepManager::NewL(*this); |
173 |
179 |
174 iDeviceConfiguration.iManufacturerName = HBufC::NewL(KUsbStringDescStringMaxSize); |
180 iDeviceConfiguration.iManufacturerName = HBufC::NewL(KUsbStringDescStringMaxSize); |
175 iDeviceConfiguration.iProductName = HBufC::NewL(KUsbStringDescStringMaxSize); |
181 iDeviceConfiguration.iProductName = HBufC::NewL(KUsbStringDescStringMaxSize); |
176 #ifndef __OVER_DUMMYUSBDI__ |
182 #ifndef __OVER_DUMMYUSBDI__ |
177 #ifndef __WINS__ |
183 #ifndef __WINS__ |
178 LOGTEXT(_L8("About to load LDD")); |
184 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL, "CUsbDevice::ConstructL; About to load LDD" ); |
|
185 |
179 TInt err = User::LoadLogicalDevice(KUsbLDDName); |
186 TInt err = User::LoadLogicalDevice(KUsbLDDName); |
180 |
187 |
181 if (err != KErrNone && err != KErrAlreadyExists) |
188 if (err != KErrNone && err != KErrAlreadyExists) |
182 { |
189 { |
183 LEAVEL(err); |
190 OstTrace1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP10, "CUsbDevice::ConstructL;err=%d", err ); |
184 } |
191 User::Leave(err); |
185 |
192 } |
186 LOGTEXT(_L8("About to open LDD")); |
193 |
187 LEAVEIFERRORL(iLdd.Open(0)); |
194 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP1, "CUsbDevice::ConstructL; About to open LDD" ); |
188 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 |
189 |
203 |
190 // hide bus from host while interfaces are being set up |
204 // hide bus from host while interfaces are being set up |
191 iLdd.DeviceDisconnectFromHost(); |
205 iLdd.DeviceDisconnectFromHost(); |
192 |
206 |
193 // 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 |
194 // 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 |
195 // delay calling PowerUpUdc until both the service state is 'started' and |
209 // delay calling PowerUpUdc until both the service state is 'started' and |
196 // 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 |
197 // when there's no point it being powered. |
211 // when there's no point it being powered. |
198 TUsbDeviceCaps devCapsBuf; |
212 TUsbDeviceCaps devCapsBuf; |
199 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 |
200 if ( devCapsBuf().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower ) |
220 if ( devCapsBuf().iFeatureWord1 & KUsbDevCapsFeatureWord1_CableDetectWithoutPower ) |
201 { |
221 { |
202 LOGTEXT(_L8("\tUDC supports cable detect when unpowered")); |
222 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP3, "CUsbDevice::ConstructL: UDC supports cable detect when unpowered" ); |
203 iUdcSupportsCableDetectWhenUnpowered = ETrue; |
223 iUdcSupportsCableDetectWhenUnpowered = ETrue; |
204 } |
224 } |
205 else |
225 else |
206 { |
226 { |
207 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" ); |
208 } |
228 } |
209 |
229 |
210 TUsbcDeviceState deviceState; |
230 TUsbcDeviceState deviceState; |
211 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 } |
212 SetDeviceState(deviceState); |
237 SetDeviceState(deviceState); |
213 LOGTEXT(_L8("Got device state")); |
238 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP5, "CUsbDevice::ConstructL; Got device state" ); |
|
239 |
214 |
240 |
215 iDeviceStateWatcher = CUsbDeviceStateWatcher::NewL(*this, iLdd); |
241 iDeviceStateWatcher = CUsbDeviceStateWatcher::NewL(*this, iLdd); |
216 iDeviceStateWatcher->Start(); |
242 iDeviceStateWatcher->Start(); |
217 |
243 |
218 // Get hold of the default serial number in the driver |
244 // Get hold of the default serial number in the driver |
223 err = iLdd.GetSerialNumberStringDescriptor(serNum); |
249 err = iLdd.GetSerialNumberStringDescriptor(serNum); |
224 if (err == KErrNotFound) |
250 if (err == KErrNotFound) |
225 { |
251 { |
226 delete iDefaultSerialNumber; |
252 delete iDefaultSerialNumber; |
227 iDefaultSerialNumber = NULL; |
253 iDefaultSerialNumber = NULL; |
228 LOGTEXT(_L8("No default serial number")); |
254 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP6, "CUsbDevice::ConstructL; No default serial number" ); |
|
255 |
229 } |
256 } |
230 else |
257 else |
231 { |
258 { |
232 LEAVEIFERRORL(err); |
259 if(err < 0) |
233 #ifdef __FLOG_ACTIVE |
260 { |
234 TBuf8<KUsbStringDescStringMaxSize> narrowString; |
261 OstTrace1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP12, "CUsbDevice::ConstructL;error=%d", err ); |
235 narrowString.Copy(serNum); |
262 User::Leave(err); |
236 LOGTEXT2(_L8("Got default serial number %S"), &narrowString); |
263 } |
237 #endif //__FLOG_ACTIVE |
264 #ifdef _DEBUG |
238 } |
265 OstTraceExt1( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP7, "CUsbDevice::ConstructL;serNum=%S", serNum ); |
239 |
266 #endif //_DEBUG |
240 LOGTEXT(_L8("UsbDevice::ConstructL() finished")); |
267 } |
|
268 |
|
269 OstTrace0( TRACE_NORMAL, CUSBDEVICE_CONSTRUCTL_DUP8, "CUsbDevice::ConstructL; UsbDevice::ConstructL() finished" ); |
|
270 |
241 #endif |
271 #endif |
242 #endif |
272 #endif |
243 |
273 |
244 #ifndef __OVER_DUMMYUSBDI__ |
274 #ifndef __OVER_DUMMYUSBDI__ |
245 InstantiateExtensionPluginsL(); |
275 InstantiateExtensionPluginsL(); |
246 #endif |
276 #endif |
|
277 OstTraceFunctionExit0( CUSBDEVICE_CONSTRUCTL_EXIT ); |
247 } |
278 } |
248 |
279 |
249 void CUsbDevice::InstantiateExtensionPluginsL() |
280 void CUsbDevice::InstantiateExtensionPluginsL() |
250 { |
281 { |
251 LOGTEXT(_L8(">>CUsbDevice::InstantiateExtensionPluginsL")); |
282 OstTraceFunctionEntry0( CUSBDEVICE_INSTANTIATEEXTENSIONPLUGINSL_ENTRY ); |
|
283 |
252 const TUid KUidExtensionPluginInterface = TUid::Uid(KUsbmanExtensionPluginInterfaceUid); |
284 const TUid KUidExtensionPluginInterface = TUid::Uid(KUsbmanExtensionPluginInterfaceUid); |
253 RImplInfoPtrArray implementations; |
285 RImplInfoPtrArray implementations; |
254 const TEComResolverParams noResolverParams; |
286 const TEComResolverParams noResolverParams; |
255 REComSession::ListImplementationsL(KUidExtensionPluginInterface, noResolverParams, KRomOnlyResolverUid, implementations); |
287 REComSession::ListImplementationsL(KUidExtensionPluginInterface, noResolverParams, KRomOnlyResolverUid, implementations); |
256 CleanupResetAndDestroyPushL(implementations); |
288 CleanupResetAndDestroyPushL(implementations); |
257 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 |
258 |
291 |
259 for (TInt i=0; i<implementations.Count(); i++) |
292 for (TInt i=0; i<implementations.Count(); i++) |
260 { |
293 { |
261 CUsbmanExtensionPlugin* plugin = CUsbmanExtensionPlugin::NewL(implementations[i]->ImplementationUid(), *this); |
294 CUsbmanExtensionPlugin* plugin = CUsbmanExtensionPlugin::NewL(implementations[i]->ImplementationUid(), *this); |
262 CleanupStack::PushL(plugin); |
295 CleanupStack::PushL(plugin); |
263 iExtensionPlugins.AppendL(plugin); // transfer ownership to iExtensionPlugins |
296 iExtensionPlugins.AppendL(plugin); // transfer ownership to iExtensionPlugins |
264 CleanupStack::Pop(plugin); |
297 CleanupStack::Pop(plugin); |
265 LOGTEXT2(_L8("Added extension plugin with UID 0x%08x"), |
298 OstTrace1( TRACE_NORMAL, CUSBDEVICE_INSTANTIATEEXTENSIONPLUGINSL_DUP1, |
266 implementations[i]->ImplementationUid()); |
299 "CUsbDevice::InstantiateExtensionPluginsL;Added extension plugin with UID 0x%08x", |
|
300 implementations[i]->ImplementationUid().iUid ); |
|
301 |
267 } |
302 } |
268 |
303 |
269 CleanupStack::PopAndDestroy(&implementations); |
304 CleanupStack::PopAndDestroy(&implementations); |
270 |
305 OstTraceFunctionExit0( CUSBDEVICE_INSTANTIATEEXTENSIONPLUGINSL_EXIT ); |
271 LOGTEXT(_L8("<<CUsbDevice::InstantiateExtensionPluginsL")); |
|
272 } |
306 } |
273 |
307 |
274 |
308 |
275 |
309 |
276 |
310 |
311 |
349 |
312 const TEComResolverParams noResolverParams; |
350 const TEComResolverParams noResolverParams; |
313 REComSession::ListImplementationsL(KUidUsbPlugIns, noResolverParams, KRomOnlyResolverUid, implementations); |
351 REComSession::ListImplementationsL(KUidUsbPlugIns, noResolverParams, KRomOnlyResolverUid, implementations); |
314 CleanupResetAndDestroyPushL(implementations); |
352 CleanupResetAndDestroyPushL(implementations); |
315 |
353 |
316 LOGTEXT2(_L8("Number of implementations to load %d"), implementations.Count()); |
354 OstTrace1( TRACE_NORMAL, CUSBDEVICE_ENUMERATECLASSCONTROLLERSL, "CUsbDevice::EnumerateClassControllersL;Number of implementations to load %d", implementations.Count() ); |
317 |
355 |
318 for (TInt i=0; i<implementations.Count(); i++) |
356 for (TInt i=0; i<implementations.Count(); i++) |
319 { |
357 { |
320 LOGTEXT2(_L8("Adding class controller with UID %x"), |
358 OstTrace1( TRACE_NORMAL, CUSBDEVICE_ENUMERATECLASSCONTROLLERSL_DUP1, "CUsbDevice::EnumerateClassControllersL;Adding class controller with UID %x", implementations[i]->ImplementationUid().iUid ); |
321 implementations[i]->ImplementationUid()); |
359 const TUid uid = implementations[i]->ImplementationUid(); |
322 const TUid uid = implementations[i]->ImplementationUid(); |
360 TInt err = iSupportedClassUids.Append(uid); |
323 LEAVEIFERRORL(iSupportedClassUids.Append(uid)); |
361 if(err < 0) |
|
362 { |
|
363 OstTrace1( TRACE_NORMAL, CUSBDEVICE_ENUMERATECLASSCONTROLLERSL_DUP3, "CUsbDevice::EnumerateClassControllersL;iSupportedClassUids.Append(uid) with error=%d", err ); |
|
364 User::Leave(err); |
|
365 } |
324 } |
366 } |
325 |
367 |
326 CleanupStack::PopAndDestroy(&implementations); |
368 CleanupStack::PopAndDestroy(&implementations); |
327 |
369 |
328 #endif // USE_DUMMY_CLASS_CONTROLLER |
370 #endif // USE_DUMMY_CLASS_CONTROLLER |
|
371 OstTraceFunctionExit0( CUSBDEVICE_ENUMERATECLASSCONTROLLERSL_EXIT ); |
329 } |
372 } |
330 |
373 |
331 void CUsbDevice::AddClassControllerL(CUsbClassControllerBase* aClassController, |
374 void CUsbDevice::AddClassControllerL(CUsbClassControllerBase* aClassController, |
332 TLinearOrder<CUsbClassControllerBase> aOrder) |
375 TLinearOrder<CUsbClassControllerBase> aOrder) |
333 /** |
376 /** |
358 |
401 |
359 if (rc != KErrNone) |
402 if (rc != KErrNone) |
360 { |
403 { |
361 // Avoid memory leak by deleting class controller if the append fails. |
404 // Avoid memory leak by deleting class controller if the append fails. |
362 delete aClassController; |
405 delete aClassController; |
363 LEAVEL(rc); |
406 OstTrace1( TRACE_NORMAL, CUSBDEVICE_ADDCLASSCONTROLLERL, "CUsbDevice::AddClassControllerL;Leave rc=%d", rc ); |
364 } |
407 User::Leave(rc); |
|
408 } |
|
409 OstTraceFunctionExit0( CUSBDEVICE_ADDCLASSCONTROLLERL_EXIT ); |
365 } |
410 } |
366 |
411 |
367 void CUsbDevice::RegisterObserverL(MUsbDeviceNotify& aObserver) |
412 void CUsbDevice::RegisterObserverL(MUsbDeviceNotify& aObserver) |
368 /** |
413 /** |
369 * Register an observer of the device. |
414 * Register an observer of the device. |
370 * Presently, the device supports watching state. |
415 * Presently, the device supports watching state. |
371 * |
416 * |
372 * @param aObserver New Observer of the device |
417 * @param aObserver New Observer of the device |
373 */ |
418 */ |
374 { |
419 { |
375 LOG_FUNC |
420 OstTraceFunctionEntry0( CUSBDEVICE_REGISTEROBSERVERL_ENTRY ); |
376 |
421 TInt err = iObservers.Append(&aObserver); |
377 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 ); |
378 } |
428 } |
379 |
429 |
380 |
430 |
381 void CUsbDevice::DeRegisterObserver(MUsbDeviceNotify& aObserver) |
431 void CUsbDevice::DeRegisterObserver(MUsbDeviceNotify& aObserver) |
382 /** |
432 /** |
383 * De-registers an existing device observer. |
433 * De-registers an existing device observer. |
384 * |
434 * |
385 * @param aObserver The existing device observer to be de-registered |
435 * @param aObserver The existing device observer to be de-registered |
386 */ |
436 */ |
387 { |
437 { |
388 LOG_FUNC |
438 OstTraceFunctionEntry0( CUSBDEVICE_DEREGISTEROBSERVER_ENTRY ); |
389 |
439 |
390 TInt index = iObservers.Find(&aObserver); |
440 TInt index = iObservers.Find(&aObserver); |
391 |
441 |
392 if (index >= 0) |
442 if (index >= 0) |
393 iObservers.Remove(index); |
443 iObservers.Remove(index); |
|
444 OstTraceFunctionExit0( CUSBDEVICE_DEREGISTEROBSERVER_EXIT ); |
394 } |
445 } |
395 |
446 |
396 |
447 |
397 void CUsbDevice::StartL() |
448 void CUsbDevice::StartL() |
398 /** |
449 /** |
399 * Start the USB Device and all its associated USB classes. |
450 * Start the USB Device and all its associated USB classes. |
400 * Reports errors and state changes via observer interface. |
451 * Reports errors and state changes via observer interface. |
401 */ |
452 */ |
402 { |
453 { |
403 LOG_FUNC |
454 OstTraceFunctionEntry0( CUSBDEVICE_STARTL_ENTRY ); |
404 |
455 |
405 Cancel(); |
456 Cancel(); |
406 SetServiceState(EUsbServiceStarting); |
457 SetServiceState(EUsbServiceStarting); |
407 |
458 |
408 TRAPD(err, SetDeviceDescriptorL()); |
459 TRAPD(err, SetDeviceDescriptorL()); |
409 if ( err != KErrNone ) |
460 if ( err != KErrNone ) |
410 { |
461 { |
411 SetServiceState(EUsbServiceIdle); |
462 SetServiceState(EUsbServiceIdle); |
412 LEAVEL(err); |
463 OstTrace1( TRACE_NORMAL, CUSBDEVICE_STARTL, "CUsbDevice::StartL;Leave with error=%d", err ); |
|
464 User::Leave(err); |
413 } |
465 } |
414 |
466 |
415 iLastError = KErrNone; |
467 iLastError = KErrNone; |
416 StartCurrentClassController(); |
468 StartCurrentClassController(); |
|
469 OstTraceFunctionExit0( CUSBDEVICE_STARTL_EXIT ); |
417 } |
470 } |
418 |
471 |
419 void CUsbDevice::Stop() |
472 void CUsbDevice::Stop() |
420 /** |
473 /** |
421 * Stop the USB device and all its associated USB classes. |
474 * Stop the USB device and all its associated USB classes. |
422 */ |
475 */ |
423 { |
476 { |
424 LOG_FUNC |
477 OstTraceFunctionEntry0( CUSBDEVICE_STOP_ENTRY ); |
425 |
478 |
426 Cancel(); |
479 Cancel(); |
427 SetServiceState(EUsbServiceStopping); |
480 SetServiceState(EUsbServiceStopping); |
428 |
481 |
429 iLastError = KErrNone; |
482 iLastError = KErrNone; |
430 StopCurrentClassController(); |
483 StopCurrentClassController(); |
|
484 OstTraceFunctionExit0( CUSBDEVICE_STOP_EXIT ); |
431 } |
485 } |
432 |
486 |
433 void CUsbDevice::SetServiceState(TUsbServiceState aState) |
487 void CUsbDevice::SetServiceState(TUsbServiceState aState) |
434 /** |
488 /** |
435 * 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. |
436 * |
490 * |
437 * @param aState New state that the device is moving to |
491 * @param aState New state that the device is moving to |
438 */ |
492 */ |
439 { |
493 { |
440 LOGTEXT3(_L8("Calling: CUsbDevice::SetServiceState [iServiceState=%d,aState=%d]"), |
494 OstTraceFunctionEntry0( CUSBDEVICE_SETSERVICESTATE_ENTRY ); |
441 iServiceState, aState); |
495 |
|
496 OstTraceExt2( TRACE_NORMAL, CUSBDEVICE_SETSERVICESTATE, |
|
497 "CUsbDevice::SetServiceState;iServiceState=%d;aState=%d", iServiceState, aState ); |
|
498 |
442 |
499 |
443 if (iServiceState != aState) |
500 if (iServiceState != aState) |
444 { |
501 { |
445 // 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 |
446 TUsbServiceState oldState = iServiceState; |
503 TUsbServiceState oldState = iServiceState; |
524 for (TUint i = 0; i < length; i++) |
582 for (TUint i = 0; i < length; i++) |
525 { |
583 { |
526 iObservers[i]->UsbDeviceStateChange(LastError(), oldState, iDeviceState); |
584 iObservers[i]->UsbDeviceStateChange(LastError(), oldState, iDeviceState); |
527 } |
585 } |
528 } |
586 } |
|
587 OstTraceFunctionExit0( CUSBDEVICE_SETDEVICESTATE_EXIT ); |
529 } |
588 } |
530 |
589 |
531 /** |
590 /** |
532 * Callback called by CDeviceHandler when the USB bus has sucessfully |
591 * Callback called by CDeviceHandler when the USB bus has sucessfully |
533 * completed a ReEnumeration (restarted all services). |
592 * completed a ReEnumeration (restarted all services). |
534 */ |
593 */ |
535 void CUsbDevice::BusEnumerationCompleted() |
594 void CUsbDevice::BusEnumerationCompleted() |
536 { |
595 { |
537 LOG_FUNC |
596 OstTraceFunctionEntry0( CUSBDEVICE_BUSENUMERATIONCOMPLETED_ENTRY ); |
538 |
597 |
539 // Has the start been cancelled? |
598 // Has the start been cancelled? |
540 if (iServiceState == EUsbServiceStarting) |
599 if (iServiceState == EUsbServiceStarting) |
541 { |
600 { |
542 SetServiceState(EUsbServiceStarted); |
601 SetServiceState(EUsbServiceStarted); |
543 } |
602 } |
544 else |
603 else |
545 { |
604 { |
546 LOGTEXT(_L8(" Start has been cancelled!")); |
605 OstTrace0( TRACE_NORMAL, CUSBDEVICE_BUSENUMERATIONCOMPLETED, |
547 } |
606 "CUsbDevice::BusEnumerationCompleted; Start has been cancelled!" ); |
|
607 } |
|
608 OstTraceFunctionExit0( CUSBDEVICE_BUSENUMERATIONCOMPLETED_EXIT ); |
548 } |
609 } |
549 |
610 |
550 void CUsbDevice::BusEnumerationFailed(TInt aError) |
611 void CUsbDevice::BusEnumerationFailed(TInt aError) |
551 /** |
612 /** |
552 * Callback called by CDeviceHandler when the USB bus has |
613 * Callback called by CDeviceHandler when the USB bus has |
553 * completed an ReEnumeration (Restarted all services) with errors |
614 * completed an ReEnumeration (Restarted all services) with errors |
554 * |
615 * |
555 * @param aError Error that has occurred during Re-enumeration |
616 * @param aError Error that has occurred during Re-enumeration |
556 */ |
617 */ |
557 { |
618 { |
558 LOGTEXT2(_L8("CUsbDevice::BusEnumerationFailed [aError=%d]"), aError); |
619 OstTrace1( TRACE_NORMAL, CUSBDEVICE_BUSENUMERATIONFAILED, "CUsbDevice::BusEnumerationFailed;aError=%d", aError ); |
|
620 |
559 iLastError = aError; |
621 iLastError = aError; |
560 |
622 |
561 if (iServiceState == EUsbServiceStarting) |
623 if (iServiceState == EUsbServiceStarting) |
562 { |
624 { |
563 SetServiceState(EUsbServiceStopping); |
625 SetServiceState(EUsbServiceStopping); |
564 StopCurrentClassController(); |
626 StopCurrentClassController(); |
565 } |
627 } |
566 else |
628 else |
567 { |
629 { |
568 LOGTEXT(_L8(" Start has been cancelled!")); |
630 OstTrace0( TRACE_NORMAL, CUSBDEVICE_BUSENUMERATIONFAILED_DUP1, |
|
631 "CUsbDevice::BusEnumerationFailed; Start has been cancelled!" ); |
569 } |
632 } |
570 } |
633 } |
571 |
634 |
572 |
635 |
573 void CUsbDevice::StartCurrentClassController() |
636 void CUsbDevice::StartCurrentClassController() |
574 /** |
637 /** |
575 * Called numerous times to start all the USB classes. |
638 * Called numerous times to start all the USB classes. |
576 */ |
639 */ |
577 { |
640 { |
578 LOG_FUNC |
641 OstTraceFunctionEntry0( CUSBDEVICE_STARTCURRENTCLASSCONTROLLER_ENTRY ); |
579 |
642 |
580 iUsbClassControllerIterator->Current()->Start(iStatus); |
643 iUsbClassControllerIterator->Current()->Start(iStatus); |
581 SetActive(); |
644 SetActive(); |
|
645 OstTraceFunctionExit0( CUSBDEVICE_STARTCURRENTCLASSCONTROLLER_EXIT ); |
582 } |
646 } |
583 |
647 |
584 void CUsbDevice::StopCurrentClassController() |
648 void CUsbDevice::StopCurrentClassController() |
585 /** |
649 /** |
586 * Called numerous times to stop all the USB classes. |
650 * Called numerous times to stop all the USB classes. |
587 */ |
651 */ |
588 { |
652 { |
589 LOG_FUNC |
653 OstTraceFunctionEntry0( CUSBDEVICE_STOPCURRENTCLASSCONTROLLER_ENTRY ); |
590 |
654 |
591 iUsbClassControllerIterator->Current()->Stop(iStatus); |
655 iUsbClassControllerIterator->Current()->Stop(iStatus); |
592 SetActive(); |
656 SetActive(); |
|
657 OstTraceFunctionExit0( CUSBDEVICE_STOPCURRENTCLASSCONTROLLER_EXIT ); |
593 } |
658 } |
594 |
659 |
595 /** |
660 /** |
596 Utility function to power up the UDC and connect the |
661 Utility function to power up the UDC and connect the |
597 device to the host. |
662 device to the host. |
598 */ |
663 */ |
599 TInt CUsbDevice::PowerUpAndConnect() |
664 TInt CUsbDevice::PowerUpAndConnect() |
600 { |
665 { |
601 LOG_FUNC |
666 OstTraceFunctionEntry0( CUSBDEVICE_POWERUPANDCONNECT_ENTRY ); |
602 LOGTEXT(_L8("\tPowering up UDC...")); |
667 |
|
668 OstTrace0( TRACE_NORMAL, CUSBDEVICE_POWERUPANDCONNECT, "CUsbDevice::PowerUpAndConnect;Powering up UDC..." ); |
|
669 |
603 TInt res = iLdd.PowerUpUdc(); |
670 TInt res = iLdd.PowerUpUdc(); |
604 LOGTEXT2(_L8("\tPowerUpUdc res = %d"), res); |
671 OstTrace1( TRACE_NORMAL, CUSBDEVICE_POWERUPANDCONNECT_DUP1, |
|
672 "CUsbDevice::PowerUpAndConnect;PowerUpUdc res = %d", res ); |
|
673 |
605 res = iLdd.DeviceConnectToHost(); |
674 res = iLdd.DeviceConnectToHost(); |
606 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 ); |
607 return res; |
679 return res; |
608 } |
680 } |
609 |
681 |
610 void CUsbDevice::RunL() |
682 void CUsbDevice::RunL() |
611 /** |
683 /** |
612 * 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 |
613 * otherwise. Continues with the process of starting or stopping until all |
685 * otherwise. Continues with the process of starting or stopping until all |
614 * classes have been completed. |
686 * classes have been completed. |
615 */ |
687 */ |
616 { |
688 { |
617 LOGTEXT2(_L8(">>CUsbDevice::RunL [iStatus=%d]"), iStatus.Int()); |
689 OstTraceFunctionEntry0( CUSBDEVICE_RUNL_ENTRY ); |
618 |
690 OstTrace1( TRACE_NORMAL, CUSBDEVICE_RUNL, "CUsbDevice::RunL;iStatus.Int()=%d", iStatus.Int() ); |
619 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 } |
620 |
698 |
621 switch (iServiceState) |
699 switch (iServiceState) |
622 { |
700 { |
623 case EUsbServiceStarting: |
701 case EUsbServiceStarting: |
624 if (iUsbClassControllerIterator->Next() == KErrNotFound) |
702 if (iUsbClassControllerIterator->Next() == KErrNotFound) |
676 StopCurrentClassController(); |
755 StopCurrentClassController(); |
677 } |
756 } |
678 break; |
757 break; |
679 |
758 |
680 default: |
759 default: |
681 __ASSERT_DEBUG( EFalse, _USB_PANIC(KUsbDevicePanicCategory, EBadAsynchronousCall) ); |
760 |
682 break; |
761 OstTrace1( TRACE_FATAL, CUSBDEVICE_RUNL_DUP5, "CUsbDevice::RunL;Panic reason=%d", EBadAsynchronousCall ); |
683 } |
762 __ASSERT_DEBUG( EFalse, User::Panic(KUsbDevicePanicCategory, EBadAsynchronousCall) ); |
684 LOGTEXT(_L8("<<CUsbDevice::RunL")); |
763 |
|
764 break; |
|
765 } |
|
766 OstTraceFunctionExit0( CUSBDEVICE_RUNL_EXIT ); |
685 } |
767 } |
686 |
768 |
687 void CUsbDevice::DoCancel() |
769 void CUsbDevice::DoCancel() |
688 /** |
770 /** |
689 * Standard active object cancellation function. If we're starting or stopping |
771 * Standard active object cancellation function. If we're starting or stopping |
690 * 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 |
691 * this function being called is a programming error. |
773 * this function being called is a programming error. |
692 */ |
774 */ |
693 { |
775 { |
694 LOG_FUNC |
776 OstTraceFunctionEntry0( CUSBDEVICE_DOCANCEL_ENTRY ); |
695 |
777 |
696 switch (iServiceState) |
778 switch (iServiceState) |
697 { |
779 { |
698 case EUsbServiceStarting: |
780 case EUsbServiceStarting: |
699 case EUsbServiceStopping: |
781 case EUsbServiceStopping: |
700 iUsbClassControllerIterator->Current()->Cancel(); |
782 iUsbClassControllerIterator->Current()->Cancel(); |
701 break; |
783 break; |
702 |
784 |
703 default: |
785 default: |
704 __ASSERT_DEBUG( EFalse, _USB_PANIC(KUsbDevicePanicCategory, EBadAsynchronousCall) ); |
786 |
705 break; |
787 OstTrace1( TRACE_FATAL, CUSBDEVICE_DOCANCEL, "CUsbDevice::DoCancel;Panic reason=%d", EBadAsynchronousCall ); |
706 } |
788 __ASSERT_DEBUG( EFalse, User::Panic(KUsbDevicePanicCategory, EBadAsynchronousCall ) ); |
|
789 break; |
|
790 } |
|
791 OstTraceFunctionExit0( CUSBDEVICE_DOCANCEL_EXIT ); |
707 } |
792 } |
708 |
793 |
709 TInt CUsbDevice::RunError(TInt aError) |
794 TInt CUsbDevice::RunError(TInt aError) |
710 /** |
795 /** |
711 * Standard active object RunError function. Handles errors which occur when |
796 * Standard active object RunError function. Handles errors which occur when |
774 * this situation, we should just stop all the classes we can. |
861 * this situation, we should just stop all the classes we can. |
775 * |
862 * |
776 * @param aError The error that's occurred |
863 * @param aError The error that's occurred |
777 */ |
864 */ |
778 { |
865 { |
779 LOG_FUNC |
866 OstTraceFunctionEntry0( CUSBDEVICE_UCCNERROR_ENTRY ); |
780 |
867 |
781 RunError(aError); |
868 RunError(aError); |
782 } |
869 OstTraceFunctionExit0( CUSBDEVICE_UCCNERROR_EXIT ); |
783 |
870 } |
784 |
871 |
785 #ifdef __FLOG_ACTIVE |
872 |
|
873 #ifdef _DEBUG |
786 void CUsbDevice::PrintDescriptor(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor) |
874 void CUsbDevice::PrintDescriptor(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor) |
787 { |
875 { |
788 LOGTEXT2(_L8("\tiLength is %d"), aDeviceDescriptor.iLength); |
876 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR, "CUsbDevice::PrintDescriptor;iLength=%d", aDeviceDescriptor.iLength ); |
789 LOGTEXT2(_L8("\tiDescriptorType is %d"), aDeviceDescriptor.iDescriptorType); |
877 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP1, "CUsbDevice::PrintDescriptor;iDescriptorType=%d", aDeviceDescriptor.iDescriptorType ); |
790 LOGTEXT2(_L8("\tBcdUsb is: 0x%04x"), aDeviceDescriptor.iBcdUsb); |
878 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP2, "CUsbDevice::PrintDescriptor;iBcdUsb=0x%04x", aDeviceDescriptor.iBcdUsb ); |
791 LOGTEXT2(_L8("\tDeviceClass is: 0x%02x"), aDeviceDescriptor.iDeviceClass); |
879 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP3, "CUsbDevice::PrintDescriptor;iDeviceClass=0x%02x", aDeviceDescriptor.iDeviceClass ); |
792 LOGTEXT2(_L8("\tDeviceSubClass is: 0x%02x"), aDeviceDescriptor.iDeviceSubClass); |
880 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP4, "CUsbDevice::PrintDescriptor;iDeviceSubClass=0x%02x", aDeviceDescriptor.iDeviceSubClass ); |
793 LOGTEXT2(_L8("\tDeviceProtocol is: 0x%02x"), aDeviceDescriptor.iDeviceProtocol); |
881 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP5, "CUsbDevice::PrintDescriptor;iDeviceProtocol=0x%02x", aDeviceDescriptor.iDeviceProtocol ); |
794 LOGTEXT2(_L8("\tiMaxPacketSize is: 0x%02x"), aDeviceDescriptor.iMaxPacketSize); |
882 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP6, "CUsbDevice::PrintDescriptor;iMaxPacketSize=0x%02x", aDeviceDescriptor.iMaxPacketSize ); |
795 |
883 |
796 LOGTEXT2(_L8("\tVendorId is: 0x%04x"), aDeviceDescriptor.iIdVendor); |
884 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP7, "CUsbDevice::PrintDescriptor;iIdVendor=0x%04x", aDeviceDescriptor.iIdVendor ); |
797 LOGTEXT2(_L8("\tProductId is: 0x%04x"), aDeviceDescriptor.iProductId); |
885 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP8, "CUsbDevice::PrintDescriptor;iProductId=0x%04x", aDeviceDescriptor.iProductId ); |
798 LOGTEXT2(_L8("\tBcdDevice is: 0x%04x"), aDeviceDescriptor.iBcdDevice); |
886 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP9, "CUsbDevice::PrintDescriptor;iBcdDevice=0x%04x", aDeviceDescriptor.iBcdDevice ); |
799 |
887 |
800 LOGTEXT2(_L8("\tiManufacturer is: 0x%04x"), aDeviceDescriptor.iManufacturer); |
888 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP10, "CUsbDevice::PrintDescriptor;iManufacturer=0x%04x", aDeviceDescriptor.iManufacturer ); |
801 LOGTEXT2(_L8("\tiSerialNumber is: 0x%04x"), aDeviceDescriptor.iSerialNumber); |
889 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP11, "CUsbDevice::PrintDescriptor;iSerialNumber=0x%04x", aDeviceDescriptor.iSerialNumber ); |
802 LOGTEXT2(_L8("\tiNumConfigurations is: 0x%04x"), aDeviceDescriptor.iNumConfigurations); |
890 OstTrace1( TRACE_DUMP, CUSBDEVICE_PRINTDESCRIPTOR_DUP12, "CUsbDevice::PrintDescriptor;iNumConfigurations=0x%04x", aDeviceDescriptor.iNumConfigurations ); |
803 } |
891 } |
804 #endif |
892 #endif |
805 // |
893 // |
806 void CUsbDevice::SetDeviceDescriptorL() |
894 void CUsbDevice::SetDeviceDescriptorL() |
807 /** |
895 /** |
808 * Modifies the USB device descriptor. |
896 * Modifies the USB device descriptor. |
809 */ |
897 */ |
810 { |
898 { |
811 LOG_FUNC |
899 OstTraceFunctionEntry0( CUSBDEVICE_SETDEVICEDESCRIPTORL_ENTRY ); |
812 |
900 |
813 #if !defined(__OVER_DUMMYUSBDI__) && !defined(__WINS__) |
901 #if !defined(__OVER_DUMMYUSBDI__) && !defined(__WINS__) |
814 |
902 |
815 TInt desSize = 0; |
903 TInt desSize = 0; |
816 iLdd.GetDeviceDescriptorSize(desSize); |
904 iLdd.GetDeviceDescriptorSize(desSize); |
817 LOGTEXT2(_L8("UDeviceDescriptorSize = %d"), desSize); |
905 OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETDEVICEDESCRIPTORL, "CUsbDevice::SetDeviceDescriptorL;UDeviceDescriptorSize = %d", desSize ); |
818 HBufC8* deviceBuf = HBufC8::NewLC(desSize); |
906 HBufC8* deviceBuf = HBufC8::NewLC(desSize); |
819 TPtr8 devicePtr = deviceBuf->Des(); |
907 TPtr8 devicePtr = deviceBuf->Des(); |
820 devicePtr.SetLength(0); |
908 devicePtr.SetLength(0); |
821 |
909 |
822 TInt ret = iLdd.GetDeviceDescriptor(devicePtr); |
910 TInt ret = iLdd.GetDeviceDescriptor(devicePtr); |
823 |
911 |
824 if (ret != KErrNone) |
912 if (ret != KErrNone) |
825 { |
913 { |
826 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 ); |
827 LEAVEL(ret); |
915 User::Leave(ret); |
828 } |
916 } |
829 |
917 |
830 TUsbDeviceDescriptor* deviceDescriptor = reinterpret_cast<TUsbDeviceDescriptor*>( |
918 TUsbDeviceDescriptor* deviceDescriptor = reinterpret_cast<TUsbDeviceDescriptor*>( |
831 const_cast<TUint8*>(devicePtr.Ptr())); |
919 const_cast<TUint8*>(devicePtr.Ptr())); |
832 |
920 |
844 { |
932 { |
845 SetUsbDeviceSettingsFromPersonalityL(*deviceDescriptor); |
933 SetUsbDeviceSettingsFromPersonalityL(*deviceDescriptor); |
846 } |
934 } |
847 else |
935 else |
848 { |
936 { |
849 LOGTEXT(_L8("USB configuration is not read")); |
937 OstTrace0( TRACE_NORMAL, CUSBDEVICE_SETDEVICEDESCRIPTORL_DUP3, |
850 LEAVEL(KErrNotFound); |
938 "CUsbDevice::SetDeviceDescriptorL;USB configuration is not read" ); |
|
939 User::Leave(KErrNotFound); |
851 } |
940 } |
852 |
941 |
853 #ifndef __OVER_DUMMYUSBDI__ |
942 #ifndef __OVER_DUMMYUSBDI__ |
854 #ifndef __WINS__ |
943 #ifndef __WINS__ |
855 ret = iLdd.SetDeviceDescriptor(devicePtr); |
944 ret = iLdd.SetDeviceDescriptor(devicePtr); |
856 |
945 |
857 if (ret != KErrNone) |
946 if (ret != KErrNone) |
858 { |
947 { |
859 LOGTEXT2(_L8("Unable to set device descriptor. Error: %d"), ret); |
948 OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETDEVICEDESCRIPTORL_DUP2, "CUsbDevice::SetDeviceDescriptorL;Unable to set device descriptor. Error: %d", ret ); |
860 LEAVEL(ret); |
949 User::Leave(ret); |
861 } |
950 } |
862 |
951 |
863 CleanupStack::PopAndDestroy(deviceBuf); |
952 CleanupStack::PopAndDestroy(deviceBuf); |
864 |
953 |
865 #endif |
954 #endif |
866 #endif // __OVER_DUMMYUSBDI__ |
955 #endif // __OVER_DUMMYUSBDI__ |
|
956 OstTraceFunctionExit0( CUSBDEVICE_SETDEVICEDESCRIPTORL_EXIT ); |
867 } |
957 } |
868 |
958 |
869 void CUsbDevice::SetUsbDeviceSettingsDefaultsL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor) |
959 void CUsbDevice::SetUsbDeviceSettingsDefaultsL(CUsbDevice::TUsbDeviceDescriptor& aDeviceDescriptor) |
870 /** |
960 /** |
871 * Set the device settings defaults, as per the non-resource |
961 * Set the device settings defaults, as per the non-resource |
904 aDeviceDescriptor.iNumConfigurations = iCurrentPersonality->NumConfigurations(); |
994 aDeviceDescriptor.iNumConfigurations = iCurrentPersonality->NumConfigurations(); |
905 |
995 |
906 |
996 |
907 #ifndef __OVER_DUMMYUSBDI__ |
997 #ifndef __OVER_DUMMYUSBDI__ |
908 #ifndef __WINS__ |
998 #ifndef __WINS__ |
909 LEAVEIFERRORL(iLdd.SetManufacturerStringDescriptor(*(iDeviceConfiguration.iManufacturerName))); |
999 TInt err = iLdd.SetManufacturerStringDescriptor(*(iDeviceConfiguration.iManufacturerName)); |
910 LEAVEIFERRORL(iLdd.SetProductStringDescriptor(*(iDeviceConfiguration.iProductName))); |
1000 if(err < 0) |
|
1001 { |
|
1002 OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP7, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;iLdd.SetManufacturerStringDescriptor(*(iCurrentPersonality->Manufacturer())) with error=%d", err ); |
|
1003 User::Leave(err); |
|
1004 } |
|
1005 err = iLdd.SetProductStringDescriptor(*(iDeviceConfiguration.iProductName)); |
|
1006 if(err < 0) |
|
1007 { |
|
1008 OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP6, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;iLdd.SetProductStringDescriptor(*(iCurrentPersonality->Product())) with error=%d", err ); |
|
1009 User::Leave(err); |
|
1010 } |
|
1011 |
911 |
1012 |
912 //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 |
913 TBuf16<KUsbStringDescStringMaxSize> serNum; |
1014 TBuf16<KUsbStringDescStringMaxSize> serNum; |
914 TInt r = RProperty::Get(KUidSystemCategory,0x101FE1DB,serNum); |
1015 TInt r = RProperty::Get(KUidSystemCategory,0x101FE1DB,serNum); |
915 if(r==KErrNone) |
1016 if(r==KErrNone) |
916 { |
1017 { |
917 #ifdef __FLOG_ACTIVE |
1018 #ifdef _DEBUG |
918 TBuf8<KUsbStringDescStringMaxSize> narrowString; |
1019 OstTraceExt1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP1, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;Setting published SerialNumber: %S", serNum ); |
919 narrowString.Copy(serNum); |
1020 #endif//_DEBUG |
920 LOGTEXT2(_L8("Setting published SerialNumber: %S"), &narrowString); |
|
921 #endif // __FLOG_ACTIVE |
|
922 //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. |
923 //As long as it is a string descriptor it is valid. |
1022 //As long as it is a string descriptor it is valid. |
924 LEAVEIFERRORL(iLdd.SetSerialNumberStringDescriptor(serNum)); |
1023 err = iLdd.SetSerialNumberStringDescriptor(serNum); |
925 } |
1024 if(err < 0) |
926 #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 |
927 else |
1031 else |
928 { |
1032 { |
929 LOGTEXT(_L8("SerialNumber has not been published")); |
1033 OstTrace0( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP2, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;SerialNumber has not been published" ); |
930 } |
1034 } |
931 #endif // __FLOG_ACTIVE |
1035 #endif // _DEBUG |
932 |
1036 |
933 #endif |
1037 #endif |
934 #endif // __OVER_DUMMYUSBDI__ |
1038 #endif // __OVER_DUMMYUSBDI__ |
935 |
1039 |
936 |
1040 |
937 #ifdef __FLOG_ACTIVE |
1041 #ifdef _DEBUG |
938 PrintDescriptor(aDeviceDescriptor); |
1042 PrintDescriptor(aDeviceDescriptor); |
939 |
1043 |
940 #ifndef __OVER_DUMMYUSBDI__ |
1044 #ifndef __OVER_DUMMYUSBDI__ |
941 #ifndef __WINS__ |
1045 #ifndef __WINS__ |
942 TBuf16<KUsbStringDescStringMaxSize> wideString; |
1046 TBuf16<KUsbStringDescStringMaxSize> wideString; |
943 TBuf8<KUsbStringDescStringMaxSize> narrowString; |
1047 TInt tmp = iLdd.GetConfigurationStringDescriptor(wideString); |
944 |
1048 if(tmp < 0) |
945 LEAVEIFERRORL(iLdd.GetConfigurationStringDescriptor(wideString)); |
1049 { |
946 narrowString.Copy(wideString); |
1050 OstTrace1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP5, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;iLdd.GetConfigurationStringDescriptor(wideString) with error=%d", tmp ); |
947 LOGTEXT2(_L8("Configuration is: '%S'"), &narrowString); |
1051 User::Leave(tmp); |
|
1052 } |
|
1053 OstTraceExt1( TRACE_NORMAL, CUSBDEVICE_SETUSBDEVICESETTINGSFROMPERSONALITYL_DUP4, "CUsbDevice::SetUsbDeviceSettingsFromPersonalityL;Configuration is:%S", wideString ); |
948 #endif |
1054 #endif |
949 #endif // __OVER_DUMMYUSBDI__ |
1055 #endif // __OVER_DUMMYUSBDI__ |
950 |
1056 |
951 #endif // __FLOG_ACTIVE |
1057 #endif // _DEBUG |
952 } |
1058 } |
953 |
1059 |
954 void CUsbDevice::TryStartL(TInt aPersonalityId) |
1060 void CUsbDevice::TryStartL(TInt aPersonalityId) |
955 /** |
1061 /** |
956 * Start all USB classes associated with the personality identified |
1062 * Start all USB classes associated with the personality identified |
958 * interface. |
1064 * interface. |
959 * |
1065 * |
960 * @param aPersonalityId a personality id |
1066 * @param aPersonalityId a personality id |
961 */ |
1067 */ |
962 { |
1068 { |
963 LOG_FUNC |
1069 OstTraceFunctionEntry0( CUSBDEVICE_TRYSTARTL_ENTRY ); |
964 SetCurrentPersonalityL(aPersonalityId); |
1070 SetCurrentPersonalityL(aPersonalityId); |
965 |
1071 |
966 SelectClassControllersL(); |
1072 SelectClassControllersL(); |
967 SetServiceState(EUsbServiceStarting); |
1073 SetServiceState(EUsbServiceStarting); |
968 |
1074 |
969 TRAPD(err, SetDeviceDescriptorL()); |
1075 TRAPD(err, SetDeviceDescriptorL()); |
970 if ( err != KErrNone ) |
1076 if ( err != KErrNone ) |
971 { |
1077 { |
972 SetServiceState(EUsbServiceIdle); |
1078 SetServiceState(EUsbServiceIdle); |
973 LEAVEL(err); |
1079 OstTrace1( TRACE_NORMAL, CUSBDEVICE_TRYSTARTL, "CUsbDevice::TryStartL;leave with error=%d", err ); |
|
1080 User::Leave(err); |
974 } |
1081 } |
975 |
1082 |
976 iLastError = KErrNone; |
1083 iLastError = KErrNone; |
977 StartCurrentClassController(); |
1084 StartCurrentClassController(); |
|
1085 OstTraceFunctionExit0( CUSBDEVICE_TRYSTARTL_EXIT ); |
978 } |
1086 } |
979 |
1087 |
980 TInt CUsbDevice::CurrentPersonalityId() const |
1088 TInt CUsbDevice::CurrentPersonalityId() const |
981 /** |
1089 /** |
982 * @return the current personality id |
1090 * @return the current personality id |
983 */ |
1091 */ |
984 { |
1092 { |
985 LOG_FUNC |
1093 OstTraceFunctionEntry0( CUSBDEVICE_CURRENTPERSONALITYID_ENTRY ); |
986 return iCurrentPersonality->PersonalityId(); |
1094 return iCurrentPersonality->PersonalityId(); |
987 } |
1095 } |
988 |
1096 |
989 const RPointerArray<CPersonality>& CUsbDevice::Personalities() const |
1097 const RPointerArray<CPersonality>& CUsbDevice::Personalities() const |
990 /** |
1098 /** |
991 * @return a const reference to RPointerArray<CPersonality> |
1099 * @return a const reference to RPointerArray<CPersonality> |
992 */ |
1100 */ |
993 { |
1101 { |
994 LOG_FUNC |
1102 OstTraceFunctionEntry0( CUSBDEVICE_PERSONALITIES_ENTRY ); |
995 return iSupportedPersonalities; |
1103 return iSupportedPersonalities; |
996 } |
1104 } |
997 |
1105 |
998 const CPersonality* CUsbDevice::GetPersonality(TInt aPersonalityId) const |
1106 const CPersonality* CUsbDevice::GetPersonality(TInt aPersonalityId) const |
999 /** |
1107 /** |
1002 * @param aPeraonalityId a personality id |
1110 * @param aPeraonalityId a personality id |
1003 * @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 |
1004 * or 0 otherwise. |
1112 * or 0 otherwise. |
1005 */ |
1113 */ |
1006 { |
1114 { |
1007 LOG_FUNC |
1115 OstTraceFunctionEntry0( CUSBDEVICE_GETPERSONALITY_ENTRY ); |
1008 |
1116 |
1009 TInt count = iSupportedPersonalities.Count(); |
1117 TInt count = iSupportedPersonalities.Count(); |
1010 for (TInt i = 0; i < count; i++) |
1118 for (TInt i = 0; i < count; i++) |
1011 { |
1119 { |
1012 if (iSupportedPersonalities[i]->PersonalityId() == aPersonalityId) |
1120 if (iSupportedPersonalities[i]->PersonalityId() == aPersonalityId) |
1013 { |
1121 { |
|
1122 OstTraceFunctionExit0( CUSBDEVICE_GETPERSONALITY_EXIT ); |
1014 return iSupportedPersonalities[i]; |
1123 return iSupportedPersonalities[i]; |
1015 } |
1124 } |
1016 } |
1125 } |
1017 |
1126 |
|
1127 OstTraceFunctionExit0( CUSBDEVICE_GETPERSONALITY_EXIT_DUP1 ); |
1018 return 0; |
1128 return 0; |
1019 } |
1129 } |
1020 |
1130 |
1021 void CUsbDevice::SetCurrentPersonalityL(TInt aPersonalityId) |
1131 void CUsbDevice::SetCurrentPersonalityL(TInt aPersonalityId) |
1022 /** |
1132 /** |
1023 * Sets the current personality to the personality with id aPersonalityId |
1133 * Sets the current personality to the personality with id aPersonalityId |
1024 */ |
1134 */ |
1025 { |
1135 { |
1026 LOG_FUNC |
1136 OstTraceFunctionEntry0( CUSBDEVICE_SETCURRENTPERSONALITYL_ENTRY ); |
1027 const CPersonality* personality = GetPersonality(aPersonalityId); |
1137 const CPersonality* personality = GetPersonality(aPersonalityId); |
1028 if (!personality) |
1138 if (!personality) |
1029 { |
1139 { |
1030 LOGTEXT(_L8("Personality id not found")); |
1140 OstTrace0( TRACE_NORMAL, CUSBDEVICE_SETCURRENTPERSONALITYL, "CUsbDevice::SetCurrentPersonalityL;Personality id not found" ); |
1031 LEAVEL(KErrNotFound); |
1141 User::Leave(KErrNotFound); |
1032 } |
1142 } |
1033 |
1143 |
1034 iCurrentPersonality = personality; |
1144 iCurrentPersonality = personality; |
|
1145 OstTraceFunctionExit0( CUSBDEVICE_SETCURRENTPERSONALITYL_EXIT ); |
1035 } |
1146 } |
1036 |
1147 |
1037 void CUsbDevice::ValidatePersonalitiesL() |
1148 void CUsbDevice::ValidatePersonalitiesL() |
1038 /** |
1149 /** |
1039 * Verifies all class controllers associated with each personality are loaded. |
1150 * Verifies all class controllers associated with each personality are loaded. |
1040 * Leave if validation fails. |
1151 * Leave if validation fails. |
1041 */ |
1152 */ |
1042 { |
1153 { |
1043 LOG_FUNC |
1154 OstTraceFunctionEntry0( CUSBDEVICE_VALIDATEPERSONALITIESL_ENTRY ); |
1044 |
1155 |
1045 TInt personalityCount = iSupportedPersonalities.Count(); |
1156 TInt personalityCount = iSupportedPersonalities.Count(); |
1046 for (TInt i = 0; i < personalityCount; i++) |
1157 for (TInt i = 0; i < personalityCount; i++) |
1047 { |
1158 { |
1048 const RArray<CPersonalityConfigurations::TUsbClasses>& classes = iSupportedPersonalities[i]->SupportedClasses(); |
1159 const RArray<CPersonalityConfigurations::TUsbClasses>& classes = iSupportedPersonalities[i]->SupportedClasses(); |
1049 TInt uidCount = classes.Count(); |
1160 TInt uidCount = classes.Count(); |
1050 for (TInt j = 0; j < uidCount; j++) |
1161 for (TInt j = 0; j < uidCount; j++) |
1051 { |
1162 { |
1052 TInt ccCount = iSupportedClassUids.Count(); |
1163 TInt ccCount = iSupportedClassUids.Count(); |
1053 TInt k; |
1164 TInt k; |
1054 LOGTEXT2(_L8("iSupportedClassUids Count = %d"),ccCount); |
1165 OstTrace1( TRACE_NORMAL, CUSBDEVICE_VALIDATEPERSONALITIESL_DUP1, "CUsbDevice::ValidatePersonalitiesL;iSupportedClassUids Count = %d", ccCount ); |
1055 for (k = 0; k < ccCount; k++) |
1166 for (k = 0; k < ccCount; k++) |
1056 { |
1167 { |
1057 LOGTEXT5(_L8("iSupportedClassUids %d %x classes %d %x"), k, iSupportedClassUids[k].iUid, j, classes[j].iClassUid.iUid); |
1168 OstTraceExt4( TRACE_NORMAL, CUSBDEVICE_VALIDATEPERSONALITIESL_DUP2, "CUsbDevice::ValidatePersonalitiesL;iSupportedClassUids %d %x classes %d %x", k, iSupportedClassUids[k].iUid, j, classes[j].iClassUid.iUid ); |
1058 if (iSupportedClassUids[k] == classes[j].iClassUid) |
1169 if (iSupportedClassUids[k] == classes[j].iClassUid) |
1059 { |
1170 { |
1060 break; |
1171 break; |
1061 } |
1172 } |
1062 } |
1173 } |
1063 if (k == ccCount) |
1174 if (k == ccCount) |
1064 { |
1175 { |
1065 LOGTEXT(_L8("personality validation failed")); |
1176 OstTrace0( TRACE_NORMAL, CUSBDEVICE_VALIDATEPERSONALITIESL, "CUsbDevice::ValidatePersonalitiesL;personality validation failed" ); |
1066 LEAVEL(KErrAbort); |
1177 User::Leave(KErrAbort); |
1067 } |
1178 } |
1068 } |
1179 } |
1069 } |
1180 } |
|
1181 OstTraceFunctionExit0( CUSBDEVICE_VALIDATEPERSONALITIESL_EXIT ); |
1070 } |
1182 } |
1071 /** |
1183 /** |
1072 Converts text string with UIDs to array of Uint |
1184 Converts text string with UIDs to array of Uint |
1073 |
1185 |
1074 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, |
1078 @param aUIDs On return array of UIDs parsed from the input string |
1190 @param aUIDs On return array of UIDs parsed from the input string |
1079 @panic EUidArrayNotEmpty if the RArray passed in is not empty |
1191 @panic EUidArrayNotEmpty if the RArray passed in is not empty |
1080 */ |
1192 */ |
1081 void CUsbDevice::ConvertUidsL(const TDesC& aStr, RArray<TUint>& aUidArray) |
1193 void CUsbDevice::ConvertUidsL(const TDesC& aStr, RArray<TUint>& aUidArray) |
1082 { |
1194 { |
1083 LOG_FUNC |
1195 OstTraceFunctionEntry0( CUSBDEVICE_CONVERTUIDSL_ENTRY ); |
1084 // Function assumes that aUIDs is empty |
1196 // Function assumes that aUIDs is empty |
1085 __ASSERT_DEBUG( aUidArray.Count() == 0, _USB_PANIC(KUsbDevicePanicCategory, EUidArrayNotEmpty) ); |
1197 #ifdef _DEBUG |
|
1198 if(aUidArray.Count() != 0) |
|
1199 { |
|
1200 OstTrace1( TRACE_FATAL, CUSBDEVICE_CONVERTUIDSL, "CUsbDevice::ConvertUidsL;Panic reason=%d", EUidArrayNotEmpty ); |
|
1201 User::Panic(KUsbDevicePanicCategory, EUidArrayNotEmpty); |
|
1202 } |
|
1203 #endif |
1086 |
1204 |
1087 TLex input(aStr); |
1205 TLex input(aStr); |
1088 |
1206 |
1089 // Scan through string to find UIDs |
1207 // Scan through string to find UIDs |
1090 // Need to do this at least once, as no UID in the string is an error |
1208 // Need to do this at least once, as no UID in the string is an error |
1132 { |
1256 { |
1133 iDeviceConfiguration.iProductName->Des().Copy(sysUtilModelName); |
1257 iDeviceConfiguration.iProductName->Des().Copy(sysUtilModelName); |
1134 } |
1258 } |
1135 CleanupStack::PopAndDestroy(deviceInfo); |
1259 CleanupStack::PopAndDestroy(deviceInfo); |
1136 iPersonalityCfged = ETrue; |
1260 iPersonalityCfged = ETrue; |
|
1261 OstTraceFunctionExit0( CUSBDEVICE_READPERSONALITIESL_EXIT ); |
1137 } |
1262 } |
1138 |
1263 |
1139 void CUsbDevice::SelectClassControllersL() |
1264 void CUsbDevice::SelectClassControllersL() |
1140 /** |
1265 /** |
1141 * Selects class controllers for the current personality |
1266 * Selects class controllers for the current personality |
1142 */ |
1267 */ |
1143 { |
1268 { |
1144 LOG_FUNC |
1269 OstTraceFunctionEntry0( CUSBDEVICE_SELECTCLASSCONTROLLERSL_ENTRY ); |
1145 const RArray<CPersonalityConfigurations::TUsbClasses>& classes = iCurrentPersonality->SupportedClasses(); |
1270 const RArray<CPersonalityConfigurations::TUsbClasses>& classes = iCurrentPersonality->SupportedClasses(); |
1146 RArray<TUid> classUids; |
1271 RArray<TUid> classUids; |
1147 CleanupClosePushL( classUids ); |
1272 CleanupClosePushL( classUids ); |
1148 TInt classCount = classes.Count(); |
1273 TInt classCount = classes.Count(); |
1149 for(TInt classIndex = 0; classIndex<classCount; ++classIndex) |
1274 for(TInt classIndex = 0; classIndex<classCount; ++classIndex) |
1177 |
1303 |
1178 TInt count = aClassUids.Count(); |
1304 TInt count = aClassUids.Count(); |
1179 |
1305 |
1180 // 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 |
1181 iSupportedClasses.ResetAndDestroy(); |
1307 iSupportedClasses.ResetAndDestroy(); |
1182 LOGTEXT2(_L8("aClassUids.Count() = %d\n"), count); |
1308 OstTrace1( TRACE_NORMAL, CUSBDEVICE_CREATECLASSCONTROLLERSL, "CUsbDevice::CreateClassControllersL;aClassUids.Count() = %d", count ); |
1183 for (TInt i = 0; i < count; i++) |
1309 for (TInt i = 0; i < count; i++) |
1184 { |
1310 { |
1185 CUsbClassControllerPlugIn* plugIn = CUsbClassControllerPlugIn::NewL(aClassUids[i], *this); |
1311 CUsbClassControllerPlugIn* plugIn = CUsbClassControllerPlugIn::NewL(aClassUids[i], *this); |
1186 AddClassControllerL(reinterpret_cast<CUsbClassControllerBase*>(plugIn), order); |
1312 AddClassControllerL(reinterpret_cast<CUsbClassControllerBase*>(plugIn), order); |
1187 } |
1313 } |
1188 #endif // USE_DUMMY_CLASS_CONTROLLER |
1314 #endif // USE_DUMMY_CLASS_CONTROLLER |
1189 |
1315 TInt err = iUsbClassControllerIterator->First(); |
1190 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 } |
1191 } |
1321 } |
1192 |
1322 |
1193 void CUsbDevice::SetDefaultPersonalityL() |
1323 void CUsbDevice::SetDefaultPersonalityL() |
1194 /** |
1324 /** |
1195 * Sets default personality. Used for Start request. |
1325 * Sets default personality. Used for Start request. |
1196 */ |
1326 */ |
1197 { |
1327 { |
1198 LOG_FUNC |
1328 OstTraceFunctionEntry0( CUSBDEVICE_SETDEFAULTPERSONALITYL_ENTRY ); |
1199 |
1329 |
1200 TInt smallestId = iSupportedPersonalities[0]->PersonalityId(); |
1330 TInt smallestId = iSupportedPersonalities[0]->PersonalityId(); |
1201 TInt count = iSupportedPersonalities.Count(); |
1331 TInt count = iSupportedPersonalities.Count(); |
1202 for (TInt i = 1; i < count; i++) |
1332 for (TInt i = 1; i < count; i++) |
1203 { |
1333 { |