usbclasses/usbphoneasmodem/classimplementation/mscfileserver/inc/bulkonlytransport.h
changeset 0 1e05558e2206
child 2 468cfcb53fd1
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     1 // Copyright (c) 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 "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 
       
    18 /** 
       
    19  @file
       
    20  @internalTechnology
       
    21  Class declaration for CBulkOnlyTransport.
       
    22 */
       
    23 
       
    24 #ifndef BULKONLYTRANSPORT_H
       
    25 #define BULKONLYTRANSPORT_H
       
    26 
       
    27 #include <e32std.h> 
       
    28 
       
    29 #include <d32usbc.h>
       
    30 #include "protocol.h"  
       
    31 #include "mscfilecontroller.h"
       
    32 
       
    33 static const TInt KCbwLength = 31;
       
    34 
       
    35 // for control endpoint 
       
    36 static const TUint KRequestHdrSize = 8;
       
    37 
       
    38 
       
    39 /** size of buffer for command padding */
       
    40 static const TUint KBOTMaxBufSize 		= 1024; 
       
    41 
       
    42 /**
       
    43 Represent Endpoint0 request
       
    44 */
       
    45 class TUsbRequestHdr
       
    46 	{
       
    47 public:
       
    48 	enum TEp0Request
       
    49 		{
       
    50 		EReqGetMaxLun = 0xFE,
       
    51 		EReqReset	  = 0xFF
       
    52 		};
       
    53 public:
       
    54 	TInt Decode(const TDesC8& aBuffer);
       
    55 	TBool IsDataResponseRequired() const;
       
    56 
       
    57 public:
       
    58 	TUint8	iRequestType;
       
    59 	TEp0Request	iRequest;
       
    60 	TUint16 iValue;
       
    61 	TUint16 iIndex;
       
    62 	TUint16 iLength;
       
    63 
       
    64 
       
    65 	};
       
    66 
       
    67 
       
    68 //---------------------------------------
       
    69 class CBulkOnlyTransport;  //forward declaration
       
    70 
       
    71 
       
    72 
       
    73 //
       
    74 // --- class CActiveDeviceStateNotifier -----------------------------
       
    75 //
       
    76 
       
    77 class CActiveDeviceStateNotifier : public CActive
       
    78 	{
       
    79 public:
       
    80 	// Construction
       
    81 	static CActiveDeviceStateNotifier* NewL(CBulkOnlyTransport& aParent);
       
    82 
       
    83 	// Destruction
       
    84 	~CActiveDeviceStateNotifier();
       
    85 
       
    86 	void Activate();
       
    87 
       
    88 private:
       
    89 	// Construction
       
    90 	CActiveDeviceStateNotifier(CBulkOnlyTransport& aParent);
       
    91 	void ConstructL();
       
    92 
       
    93 	// Cancel request.
       
    94 	// Defined as pure virtual by CActive;
       
    95 	// implementation provided by this class.
       
    96 	virtual void DoCancel();
       
    97 
       
    98 	// Service completed request.
       
    99 	// Defined as pure virtual by CActive;
       
   100 	// implementation provided by this class,
       
   101 	virtual void RunL();
       
   102 
       
   103 private:
       
   104 	CBulkOnlyTransport& iParent;
       
   105 	TUint iDeviceState;
       
   106 	TUint iOldDeviceState;
       
   107 	
       
   108 	};
       
   109 //=====================
       
   110 
       
   111 
       
   112 
       
   113 
       
   114 /**
       
   115 Represent session with control endpoint (Ep0).
       
   116 handles the control interface, and responds to the class specific commands (RESET and GET_MAX_LUN).  
       
   117 */
       
   118 class CControlInterface : public CActive
       
   119 	{
       
   120 
       
   121 public:
       
   122 	enum TControlState
       
   123 		{
       
   124 		ENone,
       
   125 		EReadEp0Data,
       
   126 		ESendMaxLun
       
   127 
       
   128 		};
       
   129 
       
   130 public:
       
   131 	
       
   132 	static CControlInterface* NewL(CBulkOnlyTransport& aParent);
       
   133 	
       
   134 	~CControlInterface();
       
   135 	TInt Start();
       
   136 	void Stop();
       
   137 	virtual void RunL();
       
   138 	virtual void DoCancel();
       
   139 			
       
   140 
       
   141 private:
       
   142 	CControlInterface(CBulkOnlyTransport& aParent);
       
   143 	void ConstructL();
       
   144 	TInt ReadEp0Data();
       
   145 	void DecodeEp0Data();
       
   146 
       
   147 private:
       
   148 	/** Buffer for request data*/
       
   149 	TBuf8<KRequestHdrSize> iData;
       
   150 	TUsbRequestHdr iRequestHeader;
       
   151 	/** reference to the  CBulkOnlyTransport*/
       
   152 	CBulkOnlyTransport& iParent;
       
   153 	/** represent carrent state for state mashine */
       
   154 	TControlState iCurrentState;
       
   155 	};
       
   156 
       
   157 //----------------------
       
   158 /** handles the data transport and communications with the SCSI protocol */
       
   159 class CBulkOnlyTransport : public CActive, public MTransportBase
       
   160 	{
       
   161 public:
       
   162 	enum TCswStatus
       
   163 		{
       
   164 		ECommandPassed 	= 0,
       
   165 		ECommandFailed	= 1,
       
   166 		EPhaseError		= 2
       
   167 		};
       
   168 	
       
   169 	enum TTransportState
       
   170 		{
       
   171 		ENone,
       
   172 		EWaitForCBW,
       
   173 		ESendingCSW,
       
   174 		EWritingData,
       
   175 		EReadingData,
       
   176         EPermErr
       
   177 		};
       
   178 public:
       
   179 	static CBulkOnlyTransport* NewL(TInt aNumDrives,CMscFileController& aController);
       
   180 
       
   181 	~CBulkOnlyTransport();
       
   182 	void SetupReadData(TPtr8& aData);	
       
   183 	void SetupWriteData(TPtrC8& aData);
       
   184 	TInt Start();
       
   185 	TInt Stop();
       
   186 	void RegisterProtocol(MProtocolBase& aProtocol);
       
   187 	TInt BytesAvailable();
       
   188 
       
   189 	CMscFileController& Controller();
       
   190 	TInt MaxLun();
       
   191 	RDevUsbcClient& Ldd();
       
   192 	TInt HwStart(TBool aDiscard = EFalse);
       
   193 	TInt HwStop();
       
   194 	TInt HwSuspend();
       
   195 	TInt HwResume();
       
   196 	
       
   197 	virtual void RunL();
       
   198 	virtual void DoCancel();
       
   199 
       
   200 private:
       
   201 	CBulkOnlyTransport(TInt aNumDrives,CMscFileController& aController);	
       
   202 	void ConstructL();
       
   203 	TInt SetupConfigurationDescriptor(TBool aUnset = EFalse);
       
   204 	TInt SetupInterfaceDescriptors();	
       
   205 	void ReadCBW();
       
   206 	void DecodeCBW();
       
   207 	TBool CheckCBW();
       
   208 	void SetPermError();
       
   209 	void SendCSW(TUint aTag, TUint aDataResidue, TCswStatus aStatus);
       
   210 	void WriteData(TUint aLength, TBool aZlpRequired = EFalse);
       
   211 	void ReadData(TUint aLength);
       
   212 	void StallEndpointAndWaitForClear(TEndpointNumber aEndpoint);
       
   213 	void ReadAndDiscardData(TInt aBytes);
       
   214 	void Activate(TInt aReason);
       
   215     void PrepareReadFromHost(TUint aHostDataLength);
       
   216     void PrepareWriteToHost(TUint aHostDataLength);
       
   217 	
       
   218 private:
       
   219 	/** maximun logic unit number supported (started from 0) */
       
   220 	TInt iMaxLun;
       
   221 	
       
   222 	CMscFileController& iController;
       
   223 	
       
   224 	CControlInterface* iControlInterface;
       
   225 	MProtocolBase* iProtocol;
       
   226 	RDevUsbcClient iLdd;
       
   227 	TTransportState  iCurrentState;
       
   228 	
       
   229 	/** buffer for Command Block Wrapper */
       
   230 	TBuf8 <KCbwLength+1> iCbwBuf;
       
   231 	
       
   232 	/** Pointer to read buffer (bufer itself provided by protocol) */
       
   233 	TPtr8 iReadBuf; 
       
   234 	
       
   235 	/** Pointer to write buffer (bufer itself provided by protocol) */
       
   236 	TPtrC8 iWriteBuf;
       
   237 
       
   238 	/** Shows how many data was not sent/reseived */
       
   239 	TUint32 iDataResidue;
       
   240 	TUint32 iCbwTag;
       
   241 	TCswStatus iCmdStatus;
       
   242 	
       
   243 	/** Indicate if SCSI protocol has data to sent */
       
   244 	TBool iWriteSetUp;
       
   245 	
       
   246 	/** Indicate if SCSI protocol expected additional data */
       
   247 	TBool iReadSetUp;
       
   248 	
       
   249 	/** Indicate whether SCSI protocol started or not */
       
   250 	
       
   251 	TBool iStarted;
       
   252 	
       
   253 	/** internal buffer for padding */
       
   254 	TBuf8<KBOTMaxBufSize> iBuf;
       
   255 	
       
   256 	TBool iStallAllowed;
       
   257 	
       
   258 	CActiveDeviceStateNotifier* iDeviceStateNotifier;
       
   259 	TBool iInterfaceConfigured;
       
   260 	};
       
   261 	
       
   262 #endif // BULKONLYTRANSPORT_H