sl@0: // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @internalTechnology sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "botmsctypes.h" sl@0: #include "msctypes.h" sl@0: #include "mtransport.h" sl@0: #include "mprotocol.h" sl@0: #include "cusbifacehandler.h" sl@0: #include "cbulkonlytransport.h" sl@0: #include "debug.h" sl@0: #include "msdebug.h" sl@0: sl@0: CUsbInterfaceHandler* CUsbInterfaceHandler::NewL(RUsbInterface &aInterface) sl@0: { sl@0: return new (ELeave) CUsbInterfaceHandler(aInterface); sl@0: } sl@0: sl@0: CUsbInterfaceHandler::CUsbInterfaceHandler(RUsbInterface &aInterface) sl@0: : CActive(EPriorityStandard), sl@0: iInterface(aInterface) sl@0: { sl@0: __MSFNLOG sl@0: CActiveScheduler::Add(this); sl@0: } sl@0: sl@0: CUsbInterfaceHandler::~CUsbInterfaceHandler() sl@0: { sl@0: __MSFNLOG sl@0: if (iState != ENone) sl@0: { sl@0: iState = ENone; sl@0: iBotGetMaxLun.Complete(KErrCancel); sl@0: Cancel(); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Cancellation of outstanding request sl@0: */ sl@0: void CUsbInterfaceHandler::DoCancel() sl@0: { sl@0: __MSFNLOG sl@0: } sl@0: sl@0: /** sl@0: Completion of USB transport request. sl@0: */ sl@0: void CUsbInterfaceHandler::RunL() sl@0: { sl@0: __MSFNLOG sl@0: TInt error = iStatus.Int(); sl@0: sl@0: if (error == KErrUsbStalled && iState == EGetMaxLun) sl@0: { sl@0: __BOTPRINT(_L("...KErrUsbStalled")); sl@0: iState = EReset; sl@0: Reset(); sl@0: return; sl@0: } sl@0: sl@0: if (error == KErrNone) sl@0: { sl@0: __BOTPRINT(_L("...KErrNone")); sl@0: sl@0: if (iState == EGetMaxLun) sl@0: { sl@0: __BOTPRINT(_L("...sending GetMaxLun response")); sl@0: *ipGetMaxLun = iBuffer[0]; sl@0: } sl@0: else sl@0: { sl@0: __BOTPRINT(_L("...defaulting to 0")); sl@0: *ipGetMaxLun = 0; sl@0: } sl@0: } sl@0: else sl@0: { sl@0: __BOTPRINT(_L("...completeing with KErrGeneral")); sl@0: error = KErrGeneral; sl@0: } sl@0: sl@0: iState = ENone; sl@0: iBotGetMaxLun.Complete(error); sl@0: } sl@0: sl@0: sl@0: void CUsbInterfaceHandler::GetMaxLun(TLun* aMaxLun, const RMessage2& aMessage) sl@0: { sl@0: __MSFNLOG sl@0: sl@0: /* Send the Get max lun command in the ep0 */ sl@0: RUsbInterface::TUsbTransferRequestDetails reqDetails; sl@0: _LIT8(KNullDesC8,""); sl@0: iBotGetMaxLun = aMessage; sl@0: iState = EGetMaxLun; sl@0: ipGetMaxLun = aMaxLun; sl@0: sl@0: reqDetails.iRequestType = 0xA1; sl@0: reqDetails.iRequest = 0xFE; sl@0: reqDetails.iValue = 0x0000; sl@0: reqDetails.iIndex = 0x0000; sl@0: reqDetails.iFlags = 0x04; // Short transfer OK sl@0: sl@0: iBuffer.SetLength(1); sl@0: iInterface.Ep0Transfer(reqDetails, KNullDesC8, iBuffer, iStatus); sl@0: SetActive(); sl@0: } sl@0: sl@0: sl@0: void CUsbInterfaceHandler::Reset() sl@0: { sl@0: __MSFNLOG sl@0: RUsbInterface::TUsbTransferRequestDetails reqDetails; sl@0: _LIT8(KNullDesC8,""); sl@0: sl@0: reqDetails.iRequestType = 0x21; sl@0: reqDetails.iRequest = 0xFF; sl@0: reqDetails.iValue = 0x0000; sl@0: reqDetails.iIndex = 0x0000; sl@0: reqDetails.iFlags = 0x04; // Short transfer OK sl@0: sl@0: iInterface.Ep0Transfer(reqDetails, KNullDesC8, (TDes8 &) KNullDesC8, iStatus); sl@0: SetActive(); sl@0: }