os/kernelhwsrv/userlibandfileserver/fileserver/smassstorage/inc/cbulkonlytransportusbcscldd.h
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/kernelhwsrv/userlibandfileserver/fileserver/smassstorage/inc/cbulkonlytransportusbcscldd.h	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,174 @@
     1.4 +/*
     1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +* Class declaration for CBulkOnlyTransportUsbcScLdd.
    1.19 +*
    1.20 +*/
    1.21 +
    1.22 +
    1.23 +/** 
    1.24 + @file
    1.25 + @internalTechnology
    1.26 +*/
    1.27 +
    1.28 +#ifndef __CBULKONLYTRANSPORTUSBCSCLDD_H__
    1.29 +#define __CBULKONLYTRANSPORTUSBCSCLDD_H__
    1.30 +
    1.31 +#include "cbulkonlytransport.h"
    1.32 +#include "cactivedevicestatenotifierbase.h"
    1.33 +
    1.34 +// This the length of every buffer corresponding to each Bulk endpoint. 
    1.35 +// Length is to support double buffering, maximum size of host transfers(64 for Windows/128 for MAC) + 2K (to send CSW(IN ep's) and to recwive CBW's(OUT ep's))
    1.36 +LOCAL_D const TUint KMaxScBufferSize = 258 * 1024; 
    1.37 +LOCAL_D const TUint KMaxScReadSize = 64 * 1024;
    1.38 +
    1.39 +
    1.40 +//Forward Declaration
    1.41 +class CBulkOnlyTransportUsbcScLdd;
    1.42 +
    1.43 +/**
    1.44 +Represent session with control endpoint (Ep0).
    1.45 +handles the control interface, and responds to the class specific commands (RESET and GET_MAX_LUN).  
    1.46 +*/
    1.47 +
    1.48 +class CControlInterfaceUsbcScLdd : public CActive
    1.49 +	{
    1.50 +public:
    1.51 +	enum TControlState
    1.52 +		{
    1.53 +		ENone,
    1.54 +		EReadEp0Data,
    1.55 +		ESendMaxLun
    1.56 +		};
    1.57 +
    1.58 +public:
    1.59 +	static CControlInterfaceUsbcScLdd* NewL(CBulkOnlyTransportUsbcScLdd& aParent);
    1.60 +	~CControlInterfaceUsbcScLdd();
    1.61 +	TInt Start();
    1.62 +	void Stop();
    1.63 +	virtual void RunL();
    1.64 +	virtual void DoCancel();
    1.65 +	TInt OpenEp0();
    1.66 +
    1.67 +private:
    1.68 +	CControlInterfaceUsbcScLdd(CBulkOnlyTransportUsbcScLdd& aParent);
    1.69 +	void ConstructL();
    1.70 +	TInt ReadEp0Data();
    1.71 +	void DecodeEp0Data();
    1.72 +	TInt ReadUsbEp0();
    1.73 +
    1.74 +private:
    1.75 +	TEndpointBuffer iEp0Buf;
    1.76 +	TAny* iEp0Packet;
    1.77 +	TUint iEp0Size;
    1.78 +	TBool iEp0Zlp;
    1.79 +
    1.80 +	TUsbRequestHdr iRequestHeader;
    1.81 +
    1.82 +	/** reference to the  CBulkOnlyTransport*/
    1.83 +	CBulkOnlyTransportUsbcScLdd& iParent;
    1.84 +
    1.85 +	/** represent carrent state for state mashine */
    1.86 +	TControlState iCurrentState;
    1.87 +	};
    1.88 +
    1.89 +
    1.90 +/** Transport Class that accessess the SC LDD */
    1.91 +class CBulkOnlyTransportUsbcScLdd : public CBulkOnlyTransport, public MLddDeviceStateNotification
    1.92 +	{
    1.93 +public:
    1.94 +	CBulkOnlyTransportUsbcScLdd(TInt aNumDrives,CUsbMassStorageController& aController);
    1.95 +
    1.96 +	~CBulkOnlyTransportUsbcScLdd();
    1.97 +	void ConstructL();
    1.98 +
    1.99 +	RDevUsbcScClient& Ldd();
   1.100 +	TInt BytesAvailable(); // from Mtransport base class
   1.101 +
   1.102 +	TInt SetupConfigurationDescriptor(TBool aUnset = EFalse);
   1.103 +	TInt SetupInterfaceDescriptors();
   1.104 +	void ReleaseInterface();
   1.105 +	void CancelControlInterface();
   1.106 +	TInt StartControlInterface();
   1.107 +	void ActivateDeviceStateNotifier();
   1.108 +	void CancelDeviceStateNotifier();
   1.109 +	void CancelReadWriteRequests();
   1.110 +	void AllocateEndpointResources();
   1.111 +	TInt GetDeviceStatus(TUsbcDeviceState& deviceStatus);
   1.112 +	void FlushData();
   1.113 +	void ReadAndDiscardData(TInt aBytes);
   1.114 +	void ReadCBW();
   1.115 +	void ExpireData(TAny* aAddress = NULL);
   1.116 +	void ProcessCbwEvent();
   1.117 +	void StallEndpointAndWaitForClear();
   1.118 +	void ReadData(TUint aLength = 0);
   1.119 +	void WriteUsb(TRequestStatus& aStatus, TPtrC8& aDes, TUint aLength, TBool aZlpRequired = EFalse);
   1.120 +	void SetCbwPtr();
   1.121 +	TPtr8& SetCommandBufPtr(TUint aLength);
   1.122 +	TPtr8& SetDataBufPtr();
   1.123 +	void SetPaddingBufPtr(TUint aLength);
   1.124 +	void SetCswBufPtr(TUint aLength);
   1.125 +	void ProcessReadingDataEvent();
   1.126 +	void DiscardData(TUint aLength);
   1.127 +	void WriteToClient(TUint aLength);
   1.128 +	void SetReadDataBufPtr( TUint aLength);
   1.129 +
   1.130 +#ifdef MSDC_MULTITHREADED
   1.131 +	virtual void GetBufferPointers(TPtr8& aDes1, TPtr8& aDes2);
   1.132 +#endif
   1.133 +
   1.134 +    void Activate(TRequestStatus& aStatus, TUint& aValue);
   1.135 +    void Cancel();
   1.136 +
   1.137 +private:
   1.138 +	TInt ReadUsb(TUint aLength = 0);
   1.139 +	TInt OpenEndpoints();
   1.140 +	void ProcessDataFromHost(); // As USB Read API can return with KErrCompletion saying there is data already and 
   1.141 +								// that we can process the data without queuong a request, this function effectively does
   1.142 +								// what Runl() did earlier
   1.143 +
   1.144 +private:
   1.145 +	RChunk* iChunk;
   1.146 +	RDevUsbcScClient iLdd;
   1.147 +	CControlInterfaceUsbcScLdd* iControlInterface;
   1.148 +	CActiveDeviceStateNotifierBase* iDeviceStateNotifier;
   1.149 +
   1.150 +	/** To remember chunk specifics one defined, instead of walking it every time something required */
   1.151 +	TUint iInEndpoint;
   1.152 +	TUint iOutEndpoint;
   1.153 +	TEndpointBuffer iSCReadEndpointBuf;
   1.154 +	TEndpointBuffer iSCWriteEndpointBuf;
   1.155 +	
   1.156 +	/** Pointer to the data in chunk which is read from the host */
   1.157 +	TAny* iSCReadData;
   1.158 +
   1.159 +	/** Size of data read from the host in a 'transfer' */
   1.160 +	TUint iSCReadSize;
   1.161 +
   1.162 +	/** If data read from host was termintated with a ZLP or not */
   1.163 +	TBool iReadZlp;
   1.164 +
   1.165 +	/** Pointer to start of IN buffer in chunk which can be written into by protocol/media */
   1.166 +	TAny* iDataPtr; 
   1.167 +
   1.168 +	/** Length of IN buffer */
   1.169 +	TUint iInBufferLength;
   1.170 +	};
   1.171 +
   1.172 +#endif
   1.173 +
   1.174 +
   1.175 +
   1.176 +
   1.177 +