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