|
1 // Copyright (c) 2004-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 // Class declaration for CBulkOnlyTransport. |
|
15 // |
|
16 // |
|
17 |
|
18 /** |
|
19 @file |
|
20 @internalTechnology |
|
21 */ |
|
22 |
|
23 #ifndef __CBULKONLYTRANSPORT_H__ |
|
24 #define __CBULKONLYTRANSPORT_H__ |
|
25 |
|
26 #include <e32std.h> |
|
27 #include <d32usbcsc.h> |
|
28 #include <d32usbc.h> |
|
29 #include "protocol.h" |
|
30 #include "cusbmassstoragecontroller.h" |
|
31 #include "mldddevicestatenotification.h" |
|
32 |
|
33 static const TUint KCbwLength = 31; |
|
34 static const TUint KCommandBufferLength = 36; |
|
35 // for control endpoint |
|
36 static const TUint KRequestHdrSize = 8; |
|
37 |
|
38 |
|
39 /** size of buffer for command padding */ |
|
40 static const TUint KBOTMaxBufSize = 512; |
|
41 |
|
42 /** size of csw */ |
|
43 LOCAL_D const TInt KCswLength = 13; |
|
44 |
|
45 |
|
46 /** |
|
47 Represent Endpoint0 request |
|
48 */ |
|
49 class TUsbRequestHdr |
|
50 { |
|
51 public: |
|
52 enum TEp0Request |
|
53 { |
|
54 EReqGetMaxLun = 0xFE, |
|
55 EReqReset = 0xFF |
|
56 }; |
|
57 public: |
|
58 TInt Decode(const TDesC8& aBuffer); |
|
59 TBool IsDataResponseRequired() const; |
|
60 |
|
61 public: |
|
62 TUint8 iRequestType; |
|
63 TEp0Request iRequest; |
|
64 TUint16 iValue; |
|
65 TUint16 iIndex; |
|
66 TUint16 iLength; |
|
67 }; |
|
68 |
|
69 |
|
70 /** handles the data transport and communications with the SCSI protocol */ |
|
71 class CBulkOnlyTransport : public CActive, public MTransportBase |
|
72 { |
|
73 public: |
|
74 enum TCswStatus |
|
75 { |
|
76 ECommandPassed = 0, |
|
77 ECommandFailed = 1, |
|
78 EPhaseError = 2 |
|
79 }; |
|
80 |
|
81 enum TTransportState |
|
82 { |
|
83 ENone, |
|
84 EWaitForCBW, |
|
85 ESendingCSW, |
|
86 EWritingData, |
|
87 EReadingData, |
|
88 EPermErr |
|
89 }; |
|
90 public: |
|
91 static CBulkOnlyTransport* NewL(TInt aNumDrives,CUsbMassStorageController& aController, CUsbMassStorageController::TTransportldd aTransportLddFlag); |
|
92 static CBulkOnlyTransport* NewL(TInt aNumDrives,CUsbMassStorageController& aController); |
|
93 |
|
94 CBulkOnlyTransport(TInt aNumDrives,CUsbMassStorageController& aController); |
|
95 TInt InitialiseTransportL(TInt aTransportLddFlag); |
|
96 ~CBulkOnlyTransport(); |
|
97 |
|
98 TInt Start(); |
|
99 TInt Stop(); |
|
100 void RegisterProtocol(MProtocolBase& aProtocol); |
|
101 |
|
102 CUsbMassStorageController& Controller(); |
|
103 TInt MaxLun(); |
|
104 void SetupReadData(TUint aLength); |
|
105 void SetupWriteData(TPtrC8& aData); |
|
106 |
|
107 void GetCommandBufPtr(TPtr8& aDes, TUint aLength); // Ptr to iCommandBuf to send responses to commands |
|
108 void GetReadDataBufPtr(TPtr8& aDes); // Ptr to DataBuf's |
|
109 void GetWriteDataBufPtr(TPtrC8& aDes); |
|
110 #ifdef MSDC_MULTITHREADED |
|
111 void ProcessReadData(TAny* aAddress); |
|
112 #endif |
|
113 |
|
114 TInt HwStart(TBool aDiscard = EFalse); |
|
115 TInt HwStop(); |
|
116 void StopBulkOnlyEndpoint(); |
|
117 TInt HwSuspend(); |
|
118 TInt HwResume(); |
|
119 |
|
120 virtual void RunL(); |
|
121 virtual void DoCancel(); |
|
122 |
|
123 virtual TInt SetupConfigurationDescriptor(TBool aUnset = EFalse) = 0; |
|
124 virtual TInt SetupInterfaceDescriptors() = 0; |
|
125 virtual void ReleaseInterface() = 0; |
|
126 virtual void CancelControlInterface() = 0; |
|
127 virtual TInt StartControlInterface() = 0; |
|
128 virtual void ActivateDeviceStateNotifier() = 0; |
|
129 virtual void CancelDeviceStateNotifier() = 0; |
|
130 virtual void CancelReadWriteRequests() = 0; |
|
131 virtual void AllocateEndpointResources() = 0; |
|
132 virtual TInt GetDeviceStatus(TUsbcDeviceState& deviceStatus) = 0; |
|
133 virtual void FlushData() = 0; |
|
134 virtual void ReadAndDiscardData(TInt aBytes) = 0; |
|
135 virtual void ReadCBW() = 0; |
|
136 virtual void ExpireData(TAny* aAddress = NULL) = 0; |
|
137 virtual void ProcessCbwEvent() = 0; |
|
138 virtual void StallEndpointAndWaitForClear() = 0; |
|
139 virtual void ReadData(TUint aLength = 0) = 0; |
|
140 virtual void WriteUsb(TRequestStatus& aStatus, TPtrC8& aDes, TUint aLength, TBool aZlpRequired = EFalse) = 0; |
|
141 virtual void SetCbwPtr() = 0; |
|
142 virtual TPtr8& SetCommandBufPtr(TUint aLength) = 0; // pointer to buf for sending responses to commands |
|
143 virtual TPtr8& SetDataBufPtr() = 0; // to swap between the two buffers |
|
144 virtual void SetPaddingBufPtr(TUint aLength) = 0; |
|
145 virtual void SetCswBufPtr(TUint aLength) = 0; |
|
146 virtual void ProcessReadingDataEvent() = 0; |
|
147 virtual void DiscardData(TUint aLength) = 0; |
|
148 virtual void WriteToClient(TUint aLength) = 0; |
|
149 virtual void SetReadDataBufPtr( TUint aLength) = 0; |
|
150 |
|
151 #ifdef MSDC_MULTITHREADED |
|
152 virtual void GetBufferPointers(TPtr8& aDes1, TPtr8& aDes2) = 0; |
|
153 #endif |
|
154 |
|
155 protected: |
|
156 void DecodeCBW(); |
|
157 TBool CheckCBW(); |
|
158 void SetPermError(); |
|
159 void SendCSW(TUint aTag, TUint aDataResidue, TCswStatus aStatus); |
|
160 void WriteData(TRequestStatus& aStatus, TPtrC8& aDes, TUint aLength, TBool aZlpRequired = EFalse); |
|
161 |
|
162 void CallReadAndDiscardData(TInt aBytes); |
|
163 void Activate(TInt aReason); |
|
164 |
|
165 protected: |
|
166 /** maximun logic unit number supported (started from 0*/ |
|
167 TInt iMaxLun; |
|
168 |
|
169 CUsbMassStorageController& iController; |
|
170 |
|
171 MProtocolBase* iProtocol; |
|
172 |
|
173 TTransportState iCurrentState; |
|
174 |
|
175 /** Shows how much data was not send/received */ |
|
176 TUint32 iDataResidue; |
|
177 TUint32 iCbwTag; |
|
178 TCswStatus iCmdStatus; |
|
179 |
|
180 /** Indicate if SCSI prot has data to sent */ |
|
181 TBool iWriteSetUp; |
|
182 |
|
183 /** Indicate if SCSI prot expected additional data */ |
|
184 TBool iReadSetUp; |
|
185 |
|
186 /** Indicate whether SCSI prot started or not */ |
|
187 TBool iStarted; |
|
188 |
|
189 TBool iStallAllowed; |
|
190 |
|
191 TBool iInterfaceConfigured; |
|
192 |
|
193 TPtr8 iCommandBufPtr; // Ptr to buffer to write responses to commands |
|
194 TPtr8 iDataBufPtr; |
|
195 TPtr8 iCswBufPtr; |
|
196 TPtr8 iPaddingBufPtr; |
|
197 |
|
198 /** Size of data, Used to tell transport how much protocol/media has to send */ |
|
199 TUint iBufSize; |
|
200 |
|
201 TPtrC8 iWriteBufPtr; |
|
202 |
|
203 TPtr8 iReadBufPtr; |
|
204 |
|
205 /** Internal TPtr to check validity of and decode CBW */ |
|
206 TPtrC8 iCbwBufPtr; |
|
207 }; |
|
208 |
|
209 |
|
210 #endif // __CBULKONLYTRANSPORT_H__ |
|
211 |
|
212 |