diff -r 000000000000 -r c9bc50fca66e usbmgmt/usbmgr/usbman/server/SRC/cusbotgwatcher.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/usbman/server/SRC/cusbotgwatcher.cpp Tue Feb 02 02:02:59 2010 +0200 @@ -0,0 +1,927 @@ +/* +* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Talks directly to the USB Logical Device Driver (LDD) and +* watches any state changes +* +*/ + +/** + @file +*/ + +#include +#include "CUsbScheduler.h" +#include "cusbotgwatcher.h" +#include "CUsbOtg.h" +#include + +#ifdef __FLOG_ACTIVE +_LIT8(KLogComponent, "USBSVR-OTGWATCHER"); +#endif + +static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy); +static _LIT_SECURITY_POLICY_S1(KNetworkControlPolicy,KUsbmanSvrSid,ECapabilityNetworkControl); +static _LIT_SECURITY_POLICY_C1(KRequestSessionPolicy,ECapabilityCommDD); + +//----------------------------------------------------------------------------- +//------------------------------ Helper watchers ------------------------------ +//----------------------------------------------------------------------------- +//--------------------- Base class for all helper watchers -------------------- +/** + * The CUsbOtgBaseWatcher::CUsbOtgBaseWatcher method + * + * Constructor + * + * @param aOwner The device that owns the state watcher + * @param aLdd A reference to the USB Logical Device Driver + */ +CUsbOtgBaseWatcher::CUsbOtgBaseWatcher(RUsbOtgDriver& aLdd) + : CActive(CActive::EPriorityStandard), iLdd(aLdd) + { + LOG_FUNC + CActiveScheduler::Add(this); + } + +/** + * The CUsbOtgBaseWatcher::~CUsbOtgBaseWatcher method + * + * Destructor + * + * @internalComponent + */ +CUsbOtgBaseWatcher::~CUsbOtgBaseWatcher() + { + LOG_FUNC + Cancel(); + } + +/** + * Instructs the state watcher to start watching. + */ +void CUsbOtgBaseWatcher::Start() + { + LOG_FUNC + Post(); + } + +//---------------------------- Id-Pin watcher class --------------------------- +/** + * The CUsbOtgIdPinWatcher::NewL method + * + * Constructs a new CUsbOtgWatcher object + * + * @internalComponent + * @param aLdd A reference to the USB Logical Device Driver + * + * @return A new CUsbOtgWatcher object + */ +CUsbOtgIdPinWatcher* CUsbOtgIdPinWatcher::NewL(RUsbOtgDriver& aLdd) + { + LOG_STATIC_FUNC_ENTRY + + CUsbOtgIdPinWatcher* self = new (ELeave) CUsbOtgIdPinWatcher(aLdd); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } + + +/** + * The CUsbOtgIdPinWatcher::~CUsbOtgIdPinWatcher method + * + * Destructor + * + * @internalComponent + */ +CUsbOtgIdPinWatcher::~CUsbOtgIdPinWatcher() + { + LOG_FUNC + Cancel(); + RProperty::Delete(KUsbOtgIdPinPresentProperty); + } + +void CUsbOtgIdPinWatcher::ConstructL() +/** + * Performs 2nd phase construction of the OTG object. + */ + { + LOG_FUNC + + TInt err = RProperty::Define(KUsbOtgIdPinPresentProperty, RProperty::EInt, KAllowAllPolicy, KNetworkControlPolicy); + if ( err != KErrNone && err != KErrAlreadyExists ) + { + User::LeaveIfError(err); + } + err = RProperty::Set(KUidUsbManCategory,KUsbOtgIdPinPresentProperty,EFalse); + if ( err != KErrNone ) + { + User::LeaveIfError(err); + } + } + +/** + * The CUsbOtgIdPinWatcher::CUsbOtgIdPinWatcher method + * + * Constructor + * + * @param aLdd A reference to the USB Logical Device Driver + */ + +CUsbOtgIdPinWatcher::CUsbOtgIdPinWatcher(RUsbOtgDriver& aLdd) + : CUsbOtgBaseWatcher(aLdd) + { + LOG_FUNC + } + +/** + * Called when the ID-Pin status change is reported + */ +void CUsbOtgIdPinWatcher::RunL() + { + LOG_FUNC + LOGTEXT2(_L8(">>CUsbOtgIdPinWatcher::RunL [iStatus=%d]"), iStatus.Int()); + + LEAVEIFERRORL(iStatus.Int()); + + Post(); + + LOGTEXT(_L8("<>CUsbOtgIdPinWatcher::Post [iOtgIdPin=%d] - failed to set the property value"), iOtgIdPin); + } + else + { + LOGTEXT2(_L8(">>CUsbOtgIdPinWatcher::Post [iOtgIdPin=%d] - property is set to 1"), iOtgIdPin); + } + break; + case RUsbOtgDriver::EIdPinBPlug: + case RUsbOtgDriver::EIdPinUnknown: + if (RProperty::Set(KUidUsbManCategory,KUsbOtgIdPinPresentProperty,EFalse) != KErrNone) + { + LOGTEXT2(_L8(">>CUsbOtgIdPinWatcher::Post [iOtgIdPin=%d] - failed to set the property value"), iOtgIdPin); + } + else + { + LOGTEXT2(_L8(">>CUsbOtgIdPinWatcher::Post [iOtgIdPin=%d] - property is set to 0"), iOtgIdPin); + } + break; + default: + LOGTEXT2(_L8(">>CUsbOtgIdPinWatcher::Post [iOtgIdPin=%d] is unrecognized, re-request QueueOtgIdPinNotification"), iOtgIdPin); + break; + } + SetActive(); + } + +//----------------------------- VBus watcher class ---------------------------- +/** + * The CUsbOtgVbusWatcher::NewL method + * + * Constructs a new CUsbOtgVbusWatcher object + * + * @internalComponent + * @param aLdd A reference to the USB OTG Logical Device Driver + * + * @return A new CUsbOtgVbusWatcher object + */ +CUsbOtgVbusWatcher* CUsbOtgVbusWatcher::NewL(RUsbOtgDriver& aLdd) + { + LOG_STATIC_FUNC_ENTRY + + CUsbOtgVbusWatcher* self = new (ELeave) CUsbOtgVbusWatcher(aLdd); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } + + +/** + * The CUsbOtgVbusWatcher::~CUsbOtgVbusWatcher method + * + * Destructor + * + * @internalComponent + */ +CUsbOtgVbusWatcher::~CUsbOtgVbusWatcher() + { + LOG_FUNC + Cancel(); + + RProperty::Delete(KUsbOtgVBusPoweredProperty); + } + +void CUsbOtgVbusWatcher::ConstructL() +/** + * Performs 2nd phase construction of the OTG object. + */ + { + LOG_FUNC + + TInt err = RProperty::Define(KUsbOtgVBusPoweredProperty, RProperty::EInt, KAllowAllPolicy, KNetworkControlPolicy); + if ( err != KErrNone && err != KErrAlreadyExists ) + { + User::LeaveIfError(err); + } + err = RProperty::Set(KUidUsbManCategory,KUsbOtgVBusPoweredProperty,EFalse); + if ( err != KErrNone ) + { + User::LeaveIfError(err); + } + } + +/** + * The CUsbOtgVbusWatcher::CUsbOtgVbusWatcher method + * + * Constructor + * + * @param aLdd A reference to the USB OTG Logical Device Driver + */ +CUsbOtgVbusWatcher::CUsbOtgVbusWatcher(RUsbOtgDriver& aLdd) + : CUsbOtgBaseWatcher(aLdd) + { + LOG_FUNC + } + +/** + * Called when the Vbus status is changed + */ +void CUsbOtgVbusWatcher::RunL() + { + LOG_FUNC + LOGTEXT2(_L8(">>CUsbOtgVbusWatcher::RunL [iStatus=%d]"), iStatus.Int()); + + LEAVEIFERRORL(iStatus.Int()); + + Post(); + + LOGTEXT(_L8("<>CUsbOtgVbusWatcher::Post [iOtgVbus=%d](EVbusHigh) - failed to set the property value"), iOtgVbus); + } + else + { + LOGTEXT2(_L8(">>CUsbOtgVbusWatcher::Post [iOtgVbus=%d](EVbusHigh) - property is set to ETrue"), iOtgVbus); + } + break; + case RUsbOtgDriver::EVbusLow: + case RUsbOtgDriver::EVbusUnknown: + if (RProperty::Set(KUidUsbManCategory,KUsbOtgVBusPoweredProperty,EFalse) != KErrNone) + { + LOGTEXT2(_L8(">>CUsbOtgVbusWatcher::Post [iOtgVbus=%d](1 - EVbusLow, 2 - EVbusUnknown) - failed to set the property value"), iOtgVbus); + } + else + { + LOGTEXT2(_L8(">>CUsbOtgVbusWatcher::Post [iOtgVbus=%d](1 - EVbusLow, 2 - EVbusUnknown) - property is set to EFalse"), iOtgVbus); + } + break; + default: + LOGTEXT2(_L8(">>CUsbOtgVbusWatcher::RunL [iOtgVbus=%d] is unrecognized, re-request QueueOtgVbusNotification"), iOtgVbus); + break; + } + SetActive(); + } + + +//-------------------------- OTG State watcher class -------------------------- +/** + * The CUsbOtgStateWatcher::NewL method + * + * Constructs a new CUsbOtgWatcher object + * + * @internalComponent + * @param aLdd A reference to the USB Logical Device Driver + * + * @return A new CUsbOtgWatcher object + */ +CUsbOtgStateWatcher* CUsbOtgStateWatcher::NewL(RUsbOtgDriver& aLdd) + { + LOG_STATIC_FUNC_ENTRY + + CUsbOtgStateWatcher* self = new (ELeave) CUsbOtgStateWatcher(aLdd); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } + + +/** + * The CUsbOtgStateWatcher::~CUsbOtgStateWatcher method + * + * Destructor + * + * @internalComponent + */ +CUsbOtgStateWatcher::~CUsbOtgStateWatcher() + { + LOG_FUNC + Cancel(); + RProperty::Delete(KUsbOtgStateProperty); + } + +void CUsbOtgStateWatcher::ConstructL() +/** + * Performs 2nd phase construction of the OTG object. + */ + { + LOG_FUNC + + TInt err = RProperty::Define(KUsbOtgStateProperty, RProperty::EInt, KAllowAllPolicy, KNetworkControlPolicy); + if ( err != KErrNone && err != KErrAlreadyExists ) + { + User::LeaveIfError(err); + } + err = RProperty::Set(KUidUsbManCategory,KUsbOtgStateProperty,RUsbOtgDriver::EStateReset); + if ( err != KErrNone ) + { + User::LeaveIfError(err); + } + } + +/** + * The CUsbOtgIdPinWatcher::CUsbOtgIdPinWatcher method + * + * Constructor + * + * @param aLdd A reference to the USB Logical Device Driver + */ + +CUsbOtgStateWatcher::CUsbOtgStateWatcher(RUsbOtgDriver& aLdd) + : CUsbOtgBaseWatcher(aLdd) + { + LOG_FUNC + iOtgState = RUsbOtgDriver::EStateReset; + } + +/** + * Called when the OTG State change is reported + */ +void CUsbOtgStateWatcher::RunL() + { + LOG_FUNC + LOGTEXT2(_L8(">>CUsbOtgStateWatcher::RunL [iStatus=%d]"), iStatus.Int()); + + LEAVEIFERRORL(iStatus.Int()); + + Post(); + + LOGTEXT(_L8("<>CUsbOtgStateWatcher::RunL [iStatus=%d], iOtgState = %d"), iStatus.Int(), iOtgState); + if (RProperty::Set(KUidUsbManCategory,KUsbOtgStateProperty,(TInt)iOtgState) != KErrNone) + { + LOGTEXT3(_L8(">>CUsbOtgStateWatcher::RunL [iStatus=%d], iOtgState = %d - failed to set the property"), iStatus.Int(), iOtgState); + } + + SetActive(); + } + +//-------------------------- OTG Events watcher class ------------------------- +/** + * The CUsbOtgEventWatcher::NewL method + * + * Constructs a new CUsbOtgEventWatcher object + * + * @internalComponent + * @param aOwner The CUsbOtg that owns the state watcher + * @param aLdd A reference to the USB Logical Device Driver + * @param aOtgEvent A reference to the OTG Event + * + * @return A new CUsbOtgEventWatcher object + */ +CUsbOtgEventWatcher* CUsbOtgEventWatcher::NewL(CUsbOtg& aOwner, RUsbOtgDriver& aLdd, + RUsbOtgDriver::TOtgEvent& aOtgEvent) + { + LOG_STATIC_FUNC_ENTRY + + CUsbOtgEventWatcher* self = new (ELeave) CUsbOtgEventWatcher(aOwner, aLdd, aOtgEvent); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } + + +/** + * The CUsbOtgEventWatcher::~CUsbOtgEventWatcher method + * + * Destructor + * + * @internalComponent + */ +CUsbOtgEventWatcher::~CUsbOtgEventWatcher() + { + LOG_FUNC + Cancel(); + } + +void CUsbOtgEventWatcher::ConstructL() +/** + * Performs 2nd phase construction of the OTG object. + */ + { + LOG_FUNC + } + +/** + * The CUsbOtgEventWatcher::CUsbOtgEventWatcher method + * + * Constructor + * + * @param aOwner A reference to the CUsbOtg object that owns the state watcher + * @param aLdd A reference to the USB Logical Device Driver + * @param aOtgEvent A reference to the OTG Event + */ +CUsbOtgEventWatcher::CUsbOtgEventWatcher(CUsbOtg& aOwner, RUsbOtgDriver& aLdd, + RUsbOtgDriver::TOtgEvent& aOtgEvent) + : CUsbOtgBaseWatcher(aLdd), iOwner(aOwner), iOtgEvent(aOtgEvent) + { + LOG_FUNC + } + +/** + * Called when the OTG Event is reported + */ +void CUsbOtgEventWatcher::RunL() + { + LOG_FUNC + LOGTEXT2(_L8(">>CUsbOtgEventWatcher::RunL [iStatus=%d]"), iStatus.Int()); + + LEAVEIFERRORL(iStatus.Int()); + LOGTEXT2(_L8("CUsbOtgEventWatcher::RunL() - Otg Event reported: %d"), (TInt)iOtgEvent); + if ( ( iOtgEvent == RUsbOtgDriver::EEventHnpDisabled ) + ||( iOtgEvent == RUsbOtgDriver::EEventHnpEnabled ) + ||( iOtgEvent == RUsbOtgDriver::EEventSrpInitiated ) + ||( iOtgEvent == RUsbOtgDriver::EEventSrpReceived ) + ||( iOtgEvent == RUsbOtgDriver::EEventVbusRaised ) + ||( iOtgEvent == RUsbOtgDriver::EEventVbusDropped ) + ) + { + iOwner.NotifyOtgEvent(); + LOGTEXT2(_L8("CUsbOtgEventWatcher::RunL() - The owner is notified about Otg Event = %d"), (TInt)iOtgEvent); + } + Post(); + LOGTEXT(_L8("<CUsbOtgWatcher::~CUsbOtgWatcher (0x%08x)"), (TUint32) this); + Cancel(); + } + + +/** + * The CUsbOtgWatcher::CUsbOtgWatcher method + * + * Constructor + * + * @param aOwner The device that owns the state watcher + * @param aLdd A reference to the USB Logical Device Driver + */ +CUsbOtgWatcher::CUsbOtgWatcher(MUsbOtgObserver& aOwner, RUsbOtgDriver& aLdd, TUint& aOtgMessage) + : CActive(CActive::EPriorityStandard), iOwner(aOwner), iLdd(aLdd), iOtgMessage(aOtgMessage) + { + LOG_FUNC + CActiveScheduler::Add(this); + } + +/** + * Called when the OTG component changes its state. + */ +void CUsbOtgWatcher::RunL() + { + LOG_FUNC + if (iStatus.Int() != KErrNone) + { + LOGTEXT2(_L8("CUsbOtgWatcher::RunL() - Error = %d"), iStatus.Int()); + return; + } + + LOGTEXT2(_L8("CUsbOtgWatcher::RunL() - Otg Message reported: %d"), iOtgMessage); + iOwner.NotifyMessage(); + + Post(); + } + + +/** + * Automatically called when the state watcher is cancelled. + */ +void CUsbOtgWatcher::DoCancel() + { + LOG_FUNC + iLdd.CancelOtgMessageRequest(); + } + + +/** + * Instructs the state watcher to start watching. + */ +void CUsbOtgWatcher::Start() + { + LOG_FUNC + Post(); + } + +/** + * Sets state watcher in active state + */ +void CUsbOtgWatcher::Post() + { + LOG_FUNC + + LOGTEXT(_L8("CUsbOtgWatcher::Post() - About to call QueueOtgMessageRequest")); + iLdd.QueueOtgMessageRequest((RUsbOtgDriver::TOtgMessage&)iOtgMessage, iStatus); + SetActive(); + } + + + + +//----------------------------------------------------------------------------- +//------ A watcher class to monitor the P&S property for VBus marshalling ----- +//----------------------------------------------------------------------------- + +CRequestSessionWatcher* CRequestSessionWatcher::NewL(MUsbOtgObserver& aOwner) + { + CRequestSessionWatcher* self = new(ELeave) CRequestSessionWatcher(aOwner); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } + +CRequestSessionWatcher::~CRequestSessionWatcher() + { + Cancel(); + iProp.Close(); + } + +void CRequestSessionWatcher::ConstructL() +/** + * Performs 2nd phase construction of the OTG object. + */ + { + LOG_FUNC + + TInt err = RProperty::Define(KUsbRequestSessionProperty, RProperty::EInt, KAllowAllPolicy, KRequestSessionPolicy); + if ( err != KErrNone && err != KErrAlreadyExists ) + { + User::LeaveIfError(err); + } + err = RProperty::Set(KUidUsbManCategory,KUsbRequestSessionProperty,0); + if ( err != KErrNone ) + { + User::LeaveIfError(err); + } + User::LeaveIfError(iProp.Attach(KUidUsbManCategory, KUsbRequestSessionProperty)); + iProp.Subscribe(iStatus); + SetActive(); + } + +CRequestSessionWatcher::CRequestSessionWatcher(MUsbOtgObserver& aOwner) + : CActive(CActive::EPriorityStandard), iOwner(aOwner) + { + LOG_FUNC + CActiveScheduler::Add(this); + } + +/** + * Called when the OTG Event is reported + */ +void CRequestSessionWatcher::RunL() + { + LOG_FUNC + LOGTEXT2(_L8(">>CRequestSessionWatcher::RunL [iStatus=%d]"), iStatus.Int()); + RDebug::Printf(">>CRequestSessionWatcher::RunL [iStatus=%d]", iStatus.Int()); + + iProp.Subscribe(iStatus); + SetActive(); + + TInt val; + User::LeaveIfError(iProp.Get(val)); + RDebug::Printf(">>value=%d", val); + + iOwner.NotifyMessage(KUsbMessageRequestSession); + + LOGTEXT(_L8("<ConstructL(); + CleanupStack::Pop(self); + return self; + } + + +/** + * The CUsbOtgConnectionIdleWatcher::~CUsbOtgConnectionIdleWatcher method + * + * Destructor + * + * @internalComponent + */ +CUsbOtgConnectionIdleWatcher::~CUsbOtgConnectionIdleWatcher() + { + LOG_FUNC + Cancel(); + RProperty::Delete(KUsbOtgConnectionIdleProperty); + } + +/** + * Performs 2nd phase construction of the OTG object. + */ +void CUsbOtgConnectionIdleWatcher::ConstructL() + { + LOG_FUNC + + TInt err = RProperty::Define(KUsbOtgConnectionIdleProperty, RProperty::EInt, KAllowAllPolicy, KNetworkControlPolicy); + if ( err != KErrNone && err != KErrAlreadyExists ) + { + User::LeaveIfError(err); + } + err = RProperty::Set(KUidUsbManCategory,KUsbOtgConnectionIdleProperty,ETrue); + if ( err != KErrNone ) + { + User::LeaveIfError(err); + } + } + +/** + * The CUsbOtgConnectionIdleWatcher::CUsbOtgConnectionIdleWatcher method + * + * Constructor + * + * @param aLdd A reference to the USB Logical Device Driver + */ + +CUsbOtgConnectionIdleWatcher::CUsbOtgConnectionIdleWatcher(RUsbOtgDriver& aLdd) + : CUsbOtgBaseWatcher(aLdd) + { + LOG_FUNC + } + +/** + * Called when the Connection Idle status change is reported + */ +void CUsbOtgConnectionIdleWatcher::RunL() + { + LOG_FUNC + LOGTEXT2(_L8(">>CUsbOtgConnectionIdleWatcher::RunL [iStatus=%d]"), iStatus.Int()); + + LEAVEIFERRORL(iStatus.Int()); + + Post(); + + LOGTEXT(_L8("<>CUsbOtgConnectionIdleWatcher::Post [iConnectionIdle=%d] - property is set to 1"), iConnectionIdle); + break; + case RUsbOtgDriver::EConnectionBusy: + RProperty::Set(KUidUsbManCategory,KUsbOtgConnectionIdleProperty,EFalse); + LOGTEXT2(_L8(">>CUsbOtgConnectionIdleWatcher::Post [iConnectionIdle=%d] - property is set to 0"), iConnectionIdle); + break; + default: + LOGTEXT2(_L8(">>CUsbOtgConnectionIdleWatcher::Post [iConnectionIdle=%d] is unrecognized, re-request QueueOtgIdPinNotification"), iConnectionIdle); + break; + } + SetActive(); + } + +