author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 02:35:35 +0300 | |
changeset 281 | 13fbfa31d2ba |
parent 0 | a41df078684a |
child 271 | dc268b18d709 |
permissions | -rw-r--r-- |
281
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1 |
// Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
||
281
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
protected: |
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
95 |
~CBulkOnlyTransport() = 0; |
0 | 96 |
CBulkOnlyTransport(TInt aNumDrives,CUsbMassStorageController& aController); |
281
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
97 |
|
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
98 |
public: |
0 | 99 |
TInt InitialiseTransportL(TInt aTransportLddFlag); |
281
13fbfa31d2ba
Revision: 201039
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
100 |
|
0 | 101 |
|
102 |
TInt Start(); |
|
103 |
TInt Stop(); |
|
104 |
void RegisterProtocol(MProtocolBase& aProtocol); |
|
105 |
||
106 |
CUsbMassStorageController& Controller(); |
|
107 |
TInt MaxLun(); |
|
108 |
void SetupReadData(TUint aLength); |
|
109 |
void SetupWriteData(TPtrC8& aData); |
|
110 |
||
111 |
void GetCommandBufPtr(TPtr8& aDes, TUint aLength); // Ptr to iCommandBuf to send responses to commands |
|
112 |
void GetReadDataBufPtr(TPtr8& aDes); // Ptr to DataBuf's |
|
113 |
void GetWriteDataBufPtr(TPtrC8& aDes); |
|
114 |
#ifdef MSDC_MULTITHREADED |
|
115 |
void ProcessReadData(TAny* aAddress); |
|
116 |
#endif |
|
117 |
||
118 |
TInt HwStart(TBool aDiscard = EFalse); |
|
119 |
TInt HwStop(); |
|
120 |
void StopBulkOnlyEndpoint(); |
|
121 |
TInt HwSuspend(); |
|
122 |
TInt HwResume(); |
|
123 |
||
124 |
virtual void RunL(); |
|
125 |
virtual void DoCancel(); |
|
126 |
||
127 |
virtual TInt SetupConfigurationDescriptor(TBool aUnset = EFalse) = 0; |
|
128 |
virtual TInt SetupInterfaceDescriptors() = 0; |
|
129 |
virtual void ReleaseInterface() = 0; |
|
130 |
virtual void CancelControlInterface() = 0; |
|
131 |
virtual TInt StartControlInterface() = 0; |
|
132 |
virtual void ActivateDeviceStateNotifier() = 0; |
|
133 |
virtual void CancelDeviceStateNotifier() = 0; |
|
134 |
virtual void CancelReadWriteRequests() = 0; |
|
135 |
virtual void AllocateEndpointResources() = 0; |
|
136 |
virtual TInt GetDeviceStatus(TUsbcDeviceState& deviceStatus) = 0; |
|
137 |
virtual void FlushData() = 0; |
|
138 |
virtual void ReadAndDiscardData(TInt aBytes) = 0; |
|
139 |
virtual void ReadCBW() = 0; |
|
140 |
virtual void ExpireData(TAny* aAddress = NULL) = 0; |
|
141 |
virtual void ProcessCbwEvent() = 0; |
|
142 |
virtual void StallEndpointAndWaitForClear() = 0; |
|
143 |
virtual void ReadData(TUint aLength = 0) = 0; |
|
144 |
virtual void WriteUsb(TRequestStatus& aStatus, TPtrC8& aDes, TUint aLength, TBool aZlpRequired = EFalse) = 0; |
|
145 |
virtual void SetCbwPtr() = 0; |
|
146 |
virtual TPtr8& SetCommandBufPtr(TUint aLength) = 0; // pointer to buf for sending responses to commands |
|
147 |
virtual TPtr8& SetDataBufPtr() = 0; // to swap between the two buffers |
|
148 |
virtual void SetPaddingBufPtr(TUint aLength) = 0; |
|
149 |
virtual void SetCswBufPtr(TUint aLength) = 0; |
|
150 |
virtual void ProcessReadingDataEvent() = 0; |
|
151 |
virtual void DiscardData(TUint aLength) = 0; |
|
152 |
virtual void WriteToClient(TUint aLength) = 0; |
|
153 |
virtual void SetReadDataBufPtr( TUint aLength) = 0; |
|
154 |
||
155 |
#ifdef MSDC_MULTITHREADED |
|
156 |
virtual void GetBufferPointers(TPtr8& aDes1, TPtr8& aDes2) = 0; |
|
157 |
#endif |
|
158 |
||
159 |
protected: |
|
160 |
void DecodeCBW(); |
|
161 |
TBool CheckCBW(); |
|
162 |
void SetPermError(); |
|
163 |
void SendCSW(TUint aTag, TUint aDataResidue, TCswStatus aStatus); |
|
164 |
void WriteData(TRequestStatus& aStatus, TPtrC8& aDes, TUint aLength, TBool aZlpRequired = EFalse); |
|
165 |
||
166 |
void CallReadAndDiscardData(TInt aBytes); |
|
167 |
void Activate(TInt aReason); |
|
168 |
||
169 |
protected: |
|
170 |
/** maximun logic unit number supported (started from 0*/ |
|
171 |
TInt iMaxLun; |
|
172 |
||
173 |
CUsbMassStorageController& iController; |
|
174 |
||
175 |
MProtocolBase* iProtocol; |
|
176 |
||
177 |
TTransportState iCurrentState; |
|
178 |
||
179 |
/** Shows how much data was not send/received */ |
|
180 |
TUint32 iDataResidue; |
|
181 |
TUint32 iCbwTag; |
|
182 |
TCswStatus iCmdStatus; |
|
183 |
||
184 |
/** Indicate if SCSI prot has data to sent */ |
|
185 |
TBool iWriteSetUp; |
|
186 |
||
187 |
/** Indicate if SCSI prot expected additional data */ |
|
188 |
TBool iReadSetUp; |
|
189 |
||
190 |
/** Indicate whether SCSI prot started or not */ |
|
191 |
TBool iStarted; |
|
192 |
||
193 |
TBool iStallAllowed; |
|
194 |
||
195 |
TBool iInterfaceConfigured; |
|
196 |
||
197 |
TPtr8 iCommandBufPtr; // Ptr to buffer to write responses to commands |
|
198 |
TPtr8 iDataBufPtr; |
|
199 |
TPtr8 iCswBufPtr; |
|
200 |
TPtr8 iPaddingBufPtr; |
|
201 |
||
202 |
/** Size of data, Used to tell transport how much protocol/media has to send */ |
|
203 |
TUint iBufSize; |
|
204 |
||
205 |
TPtrC8 iWriteBufPtr; |
|
206 |
||
207 |
TPtr8 iReadBufPtr; |
|
208 |
||
209 |
/** Internal TPtr to check validity of and decode CBW */ |
|
210 |
TPtrC8 iCbwBufPtr; |
|
211 |
}; |
|
212 |
||
213 |
||
214 |
#endif // __CBULKONLYTRANSPORT_H__ |
|
215 |
||
216 |