os/kernelhwsrv/userlibandfileserver/fileserver/smassstorage/inc/cbulkonlytransportusbcscldd.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 * Class declaration for CBulkOnlyTransportUsbcScLdd.
    16 *
    17 */
    18 
    19 
    20 /** 
    21  @file
    22  @internalTechnology
    23 */
    24 
    25 #ifndef __CBULKONLYTRANSPORTUSBCSCLDD_H__
    26 #define __CBULKONLYTRANSPORTUSBCSCLDD_H__
    27 
    28 #include "cbulkonlytransport.h"
    29 #include "cactivedevicestatenotifierbase.h"
    30 
    31 // This the length of every buffer corresponding to each Bulk endpoint. 
    32 // 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))
    33 LOCAL_D const TUint KMaxScBufferSize = 258 * 1024; 
    34 LOCAL_D const TUint KMaxScReadSize = 64 * 1024;
    35 
    36 
    37 //Forward Declaration
    38 class CBulkOnlyTransportUsbcScLdd;
    39 
    40 /**
    41 Represent session with control endpoint (Ep0).
    42 handles the control interface, and responds to the class specific commands (RESET and GET_MAX_LUN).  
    43 */
    44 
    45 class CControlInterfaceUsbcScLdd : public CActive
    46 	{
    47 public:
    48 	enum TControlState
    49 		{
    50 		ENone,
    51 		EReadEp0Data,
    52 		ESendMaxLun
    53 		};
    54 
    55 public:
    56 	static CControlInterfaceUsbcScLdd* NewL(CBulkOnlyTransportUsbcScLdd& aParent);
    57 	~CControlInterfaceUsbcScLdd();
    58 	TInt Start();
    59 	void Stop();
    60 	virtual void RunL();
    61 	virtual void DoCancel();
    62 	TInt OpenEp0();
    63 
    64 private:
    65 	CControlInterfaceUsbcScLdd(CBulkOnlyTransportUsbcScLdd& aParent);
    66 	void ConstructL();
    67 	TInt ReadEp0Data();
    68 	void DecodeEp0Data();
    69 	TInt ReadUsbEp0();
    70 
    71 private:
    72 	TEndpointBuffer iEp0Buf;
    73 	TAny* iEp0Packet;
    74 	TUint iEp0Size;
    75 	TBool iEp0Zlp;
    76 
    77 	TUsbRequestHdr iRequestHeader;
    78 
    79 	/** reference to the  CBulkOnlyTransport*/
    80 	CBulkOnlyTransportUsbcScLdd& iParent;
    81 
    82 	/** represent carrent state for state mashine */
    83 	TControlState iCurrentState;
    84 	};
    85 
    86 
    87 /** Transport Class that accessess the SC LDD */
    88 class CBulkOnlyTransportUsbcScLdd : public CBulkOnlyTransport, public MLddDeviceStateNotification
    89 	{
    90 public:
    91 	CBulkOnlyTransportUsbcScLdd(TInt aNumDrives,CUsbMassStorageController& aController);
    92 
    93 	~CBulkOnlyTransportUsbcScLdd();
    94 	void ConstructL();
    95 
    96 	RDevUsbcScClient& Ldd();
    97 	TInt BytesAvailable(); // from Mtransport base class
    98 
    99 	TInt SetupConfigurationDescriptor(TBool aUnset = EFalse);
   100 	TInt SetupInterfaceDescriptors();
   101 	void ReleaseInterface();
   102 	void CancelControlInterface();
   103 	TInt StartControlInterface();
   104 	void ActivateDeviceStateNotifier();
   105 	void CancelDeviceStateNotifier();
   106 	void CancelReadWriteRequests();
   107 	void AllocateEndpointResources();
   108 	TInt GetDeviceStatus(TUsbcDeviceState& deviceStatus);
   109 	void FlushData();
   110 	void ReadAndDiscardData(TInt aBytes);
   111 	void ReadCBW();
   112 	void ExpireData(TAny* aAddress = NULL);
   113 	void ProcessCbwEvent();
   114 	void StallEndpointAndWaitForClear();
   115 	void ReadData(TUint aLength = 0);
   116 	void WriteUsb(TRequestStatus& aStatus, TPtrC8& aDes, TUint aLength, TBool aZlpRequired = EFalse);
   117 	void SetCbwPtr();
   118 	TPtr8& SetCommandBufPtr(TUint aLength);
   119 	TPtr8& SetDataBufPtr();
   120 	void SetPaddingBufPtr(TUint aLength);
   121 	void SetCswBufPtr(TUint aLength);
   122 	void ProcessReadingDataEvent();
   123 	void DiscardData(TUint aLength);
   124 	void WriteToClient(TUint aLength);
   125 	void SetReadDataBufPtr( TUint aLength);
   126 
   127 #ifdef MSDC_MULTITHREADED
   128 	virtual void GetBufferPointers(TPtr8& aDes1, TPtr8& aDes2);
   129 #endif
   130 
   131     void Activate(TRequestStatus& aStatus, TUint& aValue);
   132     void Cancel();
   133 
   134 private:
   135 	TInt ReadUsb(TUint aLength = 0);
   136 	TInt OpenEndpoints();
   137 	void ProcessDataFromHost(); // As USB Read API can return with KErrCompletion saying there is data already and 
   138 								// that we can process the data without queuong a request, this function effectively does
   139 								// what Runl() did earlier
   140 
   141 private:
   142 	RChunk* iChunk;
   143 	RDevUsbcScClient iLdd;
   144 	CControlInterfaceUsbcScLdd* iControlInterface;
   145 	CActiveDeviceStateNotifierBase* iDeviceStateNotifier;
   146 
   147 	/** To remember chunk specifics one defined, instead of walking it every time something required */
   148 	TUint iInEndpoint;
   149 	TUint iOutEndpoint;
   150 	TEndpointBuffer iSCReadEndpointBuf;
   151 	TEndpointBuffer iSCWriteEndpointBuf;
   152 	
   153 	/** Pointer to the data in chunk which is read from the host */
   154 	TAny* iSCReadData;
   155 
   156 	/** Size of data read from the host in a 'transfer' */
   157 	TUint iSCReadSize;
   158 
   159 	/** If data read from host was termintated with a ZLP or not */
   160 	TBool iReadZlp;
   161 
   162 	/** Pointer to start of IN buffer in chunk which can be written into by protocol/media */
   163 	TAny* iDataPtr; 
   164 
   165 	/** Length of IN buffer */
   166 	TUint iInBufferLength;
   167 	};
   168 
   169 #endif
   170 
   171 
   172 
   173 
   174