os/kernelhwsrv/userlibandfileserver/fileserver/shostmassstorage/server/transport/cusbifacehandler.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @internalTechnology
    19 */
    20 
    21 #include <e32base.h>
    22 #include <d32usbdi_hubdriver.h>
    23 #include <d32usbdi.h>
    24 #include <d32otgdi.h>
    25 #include <d32usbdescriptors.h>
    26 #include <d32usbtransfers.h>
    27 #include "botmsctypes.h"
    28 #include "msctypes.h"
    29 #include "mtransport.h"
    30 #include "mprotocol.h"
    31 #include "cusbifacehandler.h"
    32 #include "cbulkonlytransport.h"
    33 #include "debug.h"
    34 #include "msdebug.h"
    35 
    36 CUsbInterfaceHandler* CUsbInterfaceHandler::NewL(RUsbInterface &aInterface)
    37 	{
    38 	return new (ELeave) CUsbInterfaceHandler(aInterface);
    39 	}
    40 
    41 CUsbInterfaceHandler::CUsbInterfaceHandler(RUsbInterface &aInterface)
    42 :	CActive(EPriorityStandard),
    43 	iInterface(aInterface)
    44 	{
    45     __MSFNLOG
    46 	CActiveScheduler::Add(this);
    47 	}
    48 
    49 CUsbInterfaceHandler::~CUsbInterfaceHandler()
    50 	{
    51     __MSFNLOG
    52 	if (iState != ENone)
    53 		{
    54 		iState = ENone;
    55 		iBotGetMaxLun.Complete(KErrCancel);
    56 		Cancel();
    57 		}
    58 	}
    59 
    60 /**
    61 Cancellation of outstanding request
    62 */
    63 void CUsbInterfaceHandler::DoCancel()
    64 	{
    65     __MSFNLOG
    66 	}
    67 
    68 /**
    69 Completion of USB transport request.
    70 */
    71 void CUsbInterfaceHandler::RunL()
    72     {
    73     __MSFNLOG
    74 	TInt error = iStatus.Int();
    75 
    76 	if (error == KErrUsbStalled && iState == EGetMaxLun)
    77         {
    78 		__BOTPRINT(_L("...KErrUsbStalled"));
    79 		iState = EReset;
    80 		Reset();
    81 		return;
    82         }
    83 
    84 	if (error == KErrNone)
    85         {
    86 		__BOTPRINT(_L("...KErrNone"));
    87 
    88 		if (iState == EGetMaxLun)
    89             {
    90 			__BOTPRINT(_L("...sending GetMaxLun response"));
    91 			*ipGetMaxLun = iBuffer[0];
    92             }
    93 		else
    94             {
    95 			__BOTPRINT(_L("...defaulting to 0"));
    96 			*ipGetMaxLun = 0;
    97             }
    98         }
    99     else
   100         {
   101         __BOTPRINT(_L("...completeing with KErrGeneral"));
   102         error = KErrGeneral;
   103         }
   104 
   105     iState = ENone;
   106 	iBotGetMaxLun.Complete(error);
   107     }
   108 
   109 
   110 void CUsbInterfaceHandler::GetMaxLun(TLun* aMaxLun, const RMessage2& aMessage)
   111 	{
   112     __MSFNLOG
   113 
   114 	/* Send the Get max lun command in the ep0 */
   115 	RUsbInterface::TUsbTransferRequestDetails reqDetails;
   116 	_LIT8(KNullDesC8,"");
   117 	iBotGetMaxLun = aMessage;
   118 	iState = EGetMaxLun;
   119 	ipGetMaxLun = aMaxLun;
   120 
   121 	reqDetails.iRequestType = 0xA1;
   122 	reqDetails.iRequest = 0xFE;
   123 	reqDetails.iValue = 0x0000;
   124 	reqDetails.iIndex = 0x0000;
   125 	reqDetails.iFlags = 0x04;		// Short transfer OK
   126 
   127 	iBuffer.SetLength(1);
   128 	iInterface.Ep0Transfer(reqDetails, KNullDesC8, iBuffer, iStatus);
   129 	SetActive();
   130 	}
   131 
   132 
   133 void CUsbInterfaceHandler::Reset()
   134 	{
   135     __MSFNLOG
   136 	RUsbInterface::TUsbTransferRequestDetails reqDetails;
   137 	_LIT8(KNullDesC8,"");
   138 
   139 	reqDetails.iRequestType = 0x21;
   140 	reqDetails.iRequest = 0xFF;
   141 	reqDetails.iValue = 0x0000;
   142 	reqDetails.iIndex = 0x0000;
   143 	reqDetails.iFlags = 0x04;		// Short transfer OK
   144 
   145 	iInterface.Ep0Transfer(reqDetails, KNullDesC8, (TDes8 &) KNullDesC8, iStatus);
   146     SetActive();
   147 	}