author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 26 Jan 2010 13:13:38 +0200 | |
changeset 39 | 5d2844f35677 |
parent 0 | a41df078684a |
child 62 | 4a8fed1c0ef6 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 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 |
// |
|
15 |
||
16 |
||
17 |
||
18 |
/** |
|
19 |
@file |
|
20 |
@internalTechnology |
|
21 |
*/ |
|
22 |
||
23 |
#include <e32base.h> |
|
24 |
#include <d32usbc.h> |
|
25 |
||
26 |
#include "mstypes.h" |
|
27 |
#include "msctypes.h" |
|
28 |
#include "usbmsclientpanic.h" |
|
29 |
#include "botmsctypes.h" |
|
30 |
#include "testman.h" |
|
31 |
#include "botmscserver.h" |
|
32 |
||
33 |
#include "mserverprotocol.h" |
|
34 |
#include "mdevicetransport.h" |
|
35 |
||
36 |
#include "mstypes.h" |
|
37 |
#include "botcontrolinterface.h" |
|
38 |
#include "debug.h" |
|
39 |
#include "msdebug.h" |
|
40 |
#include "cusbmassstorageserver.h" |
|
41 |
#include "cusbmassstoragecontroller.h" |
|
42 |
#include "drivemanager.h" |
|
43 |
#include "cbulkonlytransport.h" |
|
44 |
||
45 |
#define KInEndpoint EEndpoint1 |
|
46 |
#define KOutEndpoint EEndpoint2 |
|
47 |
||
48 |
||
49 |
//------------------------------------- |
|
50 |
/** |
|
51 |
Create CBulkOnlyTransport object |
|
52 |
@param aNumDrives - The number of drives available for MS |
|
53 |
@param aController - reference to the parent |
|
54 |
@return pointer to newly created object |
|
55 |
*/ |
|
56 |
CBulkOnlyTransport* CBulkOnlyTransport::NewL(TInt aNumDrives, |
|
57 |
CUsbMassStorageController& aController) |
|
58 |
{ |
|
59 |
__MSFNSLOG |
|
60 |
if (aNumDrives <=0 || static_cast<TUint>(aNumDrives) > KUsbMsMaxDrives) |
|
61 |
{ |
|
62 |
User::Leave(KErrArgument); |
|
63 |
} |
|
64 |
CBulkOnlyTransport* self = new(ELeave) CBulkOnlyTransport(aNumDrives, aController); |
|
65 |
CleanupStack::PushL(self); |
|
66 |
self->ConstructL(); |
|
67 |
CleanupStack::Pop(self); |
|
68 |
return self; |
|
69 |
} |
|
70 |
||
71 |
#ifdef MSDC_TESTMODE |
|
72 |
CBulkOnlyTransport* CBulkOnlyTransport::NewL(TInt aNumDrives, |
|
73 |
CUsbMassStorageController& aController, |
|
74 |
TTestParser* aTestParser) |
|
75 |
{ |
|
76 |
__MSFNSLOG |
|
77 |
if (aNumDrives <=0 || static_cast<TUint>(aNumDrives) > KUsbMsMaxDrives) |
|
78 |
{ |
|
79 |
User::Leave(KErrArgument); |
|
80 |
} |
|
81 |
CBulkOnlyTransport* self = new(ELeave) CBulkOnlyTransport(aNumDrives, |
|
82 |
aController, |
|
83 |
aTestParser); |
|
84 |
CleanupStack::PushL(self); |
|
85 |
self->ConstructL(); |
|
86 |
CleanupStack::Pop(self); |
|
87 |
return self; |
|
88 |
} |
|
89 |
#endif |
|
90 |
||
91 |
||
92 |
/** |
|
93 |
c'tor |
|
94 |
@param aNumDrives - The number of drives available for MS |
|
95 |
@param aController - reference to the parent |
|
96 |
*/ |
|
97 |
CBulkOnlyTransport::CBulkOnlyTransport(TInt aNumDrives, |
|
98 |
CUsbMassStorageController& aController): |
|
99 |
CActive(EPriorityStandard), |
|
100 |
iMaxLun(aNumDrives-1), |
|
101 |
iController(aController), |
|
102 |
iStallAllowed(ETrue) |
|
103 |
{ |
|
104 |
__MSFNLOG |
|
105 |
} |
|
106 |
||
107 |
#ifdef MSDC_TESTMODE |
|
108 |
CBulkOnlyTransport::CBulkOnlyTransport(TInt aNumDrives, |
|
109 |
CUsbMassStorageController& aController, |
|
110 |
TTestParser* aTestParser) |
|
111 |
: CActive(EPriorityStandard), |
|
112 |
iMaxLun(aNumDrives-1), |
|
113 |
iController(aController), |
|
114 |
iStallAllowed(ETrue), |
|
115 |
iTestParser(aTestParser) |
|
116 |
{ |
|
117 |
__MSFNLOG |
|
118 |
} |
|
119 |
#endif |
|
120 |
||
121 |
||
122 |
/** |
|
123 |
Constructs the CBulkOnlyTranspor object |
|
124 |
*/ |
|
125 |
void CBulkOnlyTransport::ConstructL() |
|
126 |
{ |
|
127 |
__MSFNLOG |
|
128 |
iBotControlInterface = CBotControlInterface::NewL(*this); |
|
129 |
iDeviceStateNotifier = CActiveDeviceStateNotifier::NewL(*this); |
|
130 |
CActiveScheduler::Add(this); |
|
131 |
} |
|
132 |
||
133 |
||
134 |
/** |
|
135 |
Destructor |
|
136 |
*/ |
|
137 |
CBulkOnlyTransport::~CBulkOnlyTransport() |
|
138 |
{ |
|
139 |
__MSFNLOG |
|
140 |
if (iInterfaceConfigured) |
|
141 |
{ |
|
142 |
Stop(); |
|
143 |
} |
|
144 |
delete iBotControlInterface; |
|
145 |
delete iDeviceStateNotifier; |
|
146 |
} |
|
147 |
||
148 |
||
149 |
/** |
|
150 |
Set or unset configuration descriptor for USB MassStorage Bulk Only transport |
|
151 |
||
152 |
@param aUnset indicate whether set or unset descriptor |
|
153 |
@return KErrNone if operation was completed successfully, errorcode otherwise |
|
154 |
*/ |
|
155 |
TInt CBulkOnlyTransport::SetupConfigurationDescriptor(TBool aUnset) |
|
156 |
{ |
|
157 |
__MSFNLOG |
|
158 |
TInt ret(KErrNone); |
|
159 |
TInt configDescriptorSize(0); |
|
160 |
||
161 |
iLdd.GetConfigurationDescriptorSize(configDescriptorSize); |
|
162 |
if (static_cast<TUint>(configDescriptorSize) != KUsbDescSize_Config) |
|
163 |
{ |
|
164 |
return KErrCorrupt; |
|
165 |
} |
|
166 |
||
167 |
TBuf8<KUsbDescSize_Config> configDescriptor; |
|
168 |
ret = iLdd.GetConfigurationDescriptor(configDescriptor); |
|
169 |
if (ret != KErrNone) |
|
170 |
{ |
|
171 |
return ret; |
|
172 |
} |
|
173 |
||
174 |
// I beleive that other fields setted up during LDD initialisation |
|
175 |
if (aUnset) |
|
176 |
{ |
|
177 |
--configDescriptor[KUsbNumInterfacesOffset]; |
|
178 |
} |
|
179 |
else |
|
180 |
{ |
|
181 |
++configDescriptor[KUsbNumInterfacesOffset]; |
|
182 |
} |
|
183 |
ret = iLdd.SetConfigurationDescriptor(configDescriptor); |
|
184 |
||
185 |
return ret; |
|
186 |
} |
|
187 |
||
188 |
||
189 |
/** |
|
190 |
Set up interface descriptor |
|
191 |
||
192 |
@return KErrNone if operation was completed successfully, errorcode otherwise |
|
193 |
*/ |
|
194 |
TInt CBulkOnlyTransport::SetupInterfaceDescriptors() |
|
195 |
{ |
|
196 |
__MSFNLOG |
|
197 |
// Device caps |
|
198 |
TUsbDeviceCaps d_caps; |
|
199 |
TInt ret = iLdd.DeviceCaps(d_caps); |
|
200 |
if (ret != KErrNone) |
|
201 |
{ |
|
202 |
return ret; |
|
203 |
} |
|
204 |
TInt totalEndpoints = d_caps().iTotalEndpoints; |
|
205 |
if (totalEndpoints < KRequiredNumberOfEndpoints) |
|
206 |
{ |
|
207 |
return KErrHardwareNotAvailable; |
|
208 |
} |
|
209 |
||
210 |
// Endpoint caps |
|
211 |
TUsbcEndpointData data[KUsbcMaxEndpoints]; |
|
212 |
TPtr8 dataptr(reinterpret_cast<TUint8*>(data), sizeof(data), sizeof(data)); |
|
213 |
ret = iLdd.EndpointCaps(dataptr); |
|
214 |
if (ret != KErrNone) |
|
215 |
{ |
|
216 |
return ret; |
|
217 |
} |
|
218 |
||
219 |
// Set the active interface |
|
220 |
TUsbcInterfaceInfoBuf ifc; |
|
221 |
TInt ep_found = 0; |
|
222 |
TBool foundBulkIN = EFalse; |
|
223 |
TBool foundBulkOUT = EFalse; |
|
224 |
||
225 |
for (TInt i = 0; i < totalEndpoints ; i++) |
|
226 |
{ |
|
227 |
const TUsbcEndpointCaps* caps = &data[i].iCaps; |
|
228 |
const TInt maxPacketSize = caps->MaxPacketSize(); |
|
229 |
if (!foundBulkIN && |
|
230 |
(caps->iTypesAndDir & (KUsbEpTypeBulk | KUsbEpDirIn)) == (KUsbEpTypeBulk | KUsbEpDirIn)) |
|
231 |
{ |
|
232 |
// KInEndpoint is going to be our TX (IN, write) endpoint |
|
233 |
ifc().iEndpointData[0].iType = KUsbEpTypeBulk; |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
234 |
if((d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) == KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
235 |
ifc().iEndpointData[0].iFeatureWord1 = KUsbcEndpointInfoFeatureWord1_DMA|KUsbcEndpointInfoFeatureWord1_DoubleBuffering; |
0 | 236 |
ifc().iEndpointData[0].iDir = KUsbEpDirIn; |
237 |
ifc().iEndpointData[0].iSize = maxPacketSize; |
|
238 |
ifc().iEndpointData[0].iInterval_Hs = 0; |
|
239 |
foundBulkIN = ETrue; |
|
240 |
if (++ep_found == KRequiredNumberOfEndpoints) |
|
241 |
{ |
|
242 |
break; |
|
243 |
} |
|
244 |
continue; |
|
245 |
} |
|
246 |
if (!foundBulkOUT && |
|
247 |
(caps->iTypesAndDir & (KUsbEpTypeBulk | KUsbEpDirOut)) == (KUsbEpTypeBulk | KUsbEpDirOut)) |
|
248 |
{ |
|
249 |
// KOutEndpoint is going to be our RX (OUT, read) endpoint |
|
250 |
ifc().iEndpointData[1].iType = KUsbEpTypeBulk; |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
251 |
if((d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) == KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
252 |
ifc().iEndpointData[1].iFeatureWord1 = KUsbcEndpointInfoFeatureWord1_DMA|KUsbcEndpointInfoFeatureWord1_DoubleBuffering; |
0 | 253 |
ifc().iEndpointData[1].iDir = KUsbEpDirOut; |
254 |
ifc().iEndpointData[1].iSize = maxPacketSize; |
|
255 |
ifc().iEndpointData[1].iInterval_Hs = 0; |
|
256 |
foundBulkOUT = ETrue; |
|
257 |
if (++ep_found == KRequiredNumberOfEndpoints) |
|
258 |
{ |
|
259 |
break; |
|
260 |
} |
|
261 |
continue; |
|
262 |
} |
|
263 |
} |
|
264 |
if (ep_found != KRequiredNumberOfEndpoints) |
|
265 |
{ |
|
266 |
return KErrHardwareNotAvailable; |
|
267 |
} |
|
268 |
||
269 |
_LIT16(string, "USB Mass Storage Interface"); |
|
270 |
ifc().iString = const_cast<TDesC16*>(&string); |
|
271 |
ifc().iTotalEndpointsUsed = KRequiredNumberOfEndpoints; |
|
272 |
ifc().iClass.iClassNum = 0x08; // Mass Storage |
|
273 |
ifc().iClass.iSubClassNum = 0x06; // SCSI Transparent Command Set |
|
274 |
ifc().iClass.iProtocolNum = 0x50; // Bulk Only Transport |
|
275 |
||
276 |
TUint bandwidth_priority = (EUsbcBandwidthOUTDefault | EUsbcBandwidthINDefault); |
|
277 |
if (d_caps().iHighSpeed) |
|
278 |
{ |
|
279 |
// If this device supports USB High-speed, then we request 64KB buffers |
|
280 |
// (otherwise the default 4KB ones will do). |
|
281 |
bandwidth_priority = (EUsbcBandwidthOUTPlus2 | EUsbcBandwidthINPlus2); |
|
282 |
// Also, tell the Protocol about it, because it might want to do some |
|
283 |
// optimizing too. |
|
284 |
iProtocol->ReportHighSpeedDevice(); |
|
285 |
} |
|
286 |
ret = iLdd.SetInterface(0, ifc, bandwidth_priority); |
|
287 |
return ret; |
|
288 |
} |
|
289 |
||
290 |
||
291 |
/** |
|
292 |
Called by the protocol after processing the packet to indicate that more data is required. |
|
293 |
||
294 |
@param aData reference to the data buffer. |
|
295 |
*/ |
|
296 |
void CBulkOnlyTransport::SetupDataOut(TPtr8& aData) |
|
297 |
{ |
|
298 |
__MSFNLOG |
|
299 |
iDataTransferMan.SetModeDataOut(aData); |
|
300 |
} |
|
301 |
||
302 |
/** |
|
303 |
Called by the protocol after processing the packet to indicate that data should be written to the host. |
|
304 |
||
305 |
@param aData reference to the data buffer. |
|
306 |
*/ |
|
307 |
void CBulkOnlyTransport::SetupDataIn(TPtrC8& aData) |
|
308 |
{ |
|
309 |
iDataTransferMan.SetModeDataIn(aData); |
|
310 |
} |
|
311 |
||
312 |
||
313 |
TInt CBulkOnlyTransport::Start() |
|
314 |
{ |
|
315 |
__MSFNLOG |
|
316 |
TInt err = KErrNone; |
|
317 |
||
318 |
if (!iProtocol) |
|
319 |
{ |
|
320 |
return KErrBadHandle; //protocol should be set up before start |
|
321 |
} |
|
322 |
||
323 |
if (IsActive()) |
|
324 |
{ |
|
325 |
__PRINT(_L("CBulkOnlyTransport::Start - active before start!\n")); |
|
326 |
return KErrInUse; |
|
327 |
} |
|
328 |
||
329 |
if ((err = iLdd.Open(0)) != KErrNone || |
|
330 |
(err = SetupConfigurationDescriptor()) != KErrNone || |
|
331 |
(err = SetupInterfaceDescriptors()) != KErrNone ) |
|
332 |
{ |
|
333 |
__PRINT(_L("CBulkOnlyTransport::Start - Error during descriptors setup!\n")); |
|
334 |
return err; |
|
335 |
} |
|
336 |
||
337 |
iDeviceStateNotifier->Activate(); // activate notifier wich will wait until USB became configured |
|
338 |
TUsbcDeviceState deviceStatus = EUsbcDeviceStateDefault; |
|
339 |
err = iLdd.DeviceStatus(deviceStatus); |
|
340 |
__PRINT1(_L("CBulkOnlyTransport::Start - Device status = %d\n"), deviceStatus); |
|
341 |
if (err == KErrNone && deviceStatus == EUsbcDeviceStateConfigured) |
|
342 |
{ |
|
343 |
__PRINT(_L("CBulkOnlyTransport::Start - Starting bulk only transport\n")); |
|
344 |
err = HwStart(); |
|
345 |
} |
|
346 |
iInterfaceConfigured = ETrue; |
|
347 |
return err; |
|
348 |
} |
|
349 |
||
350 |
TInt CBulkOnlyTransport::HwStart(TBool aDiscard) |
|
351 |
{ |
|
352 |
__MSFNLOG |
|
353 |
||
354 |
TInt lun = MaxLun(); |
|
355 |
do |
|
356 |
{ |
|
357 |
Controller().DriveManager().Connect(lun); |
|
358 |
} |
|
359 |
while(--lun >= 0); |
|
360 |
||
361 |
TInt res = iBotControlInterface->Start() ; |
|
362 |
||
363 |
iCurrentState = ENone; |
|
364 |
iDataTransferMan.Init(); |
|
365 |
iStarted = ETrue; |
|
366 |
||
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
367 |
TUsbDeviceCaps d_caps; |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
368 |
TInt ret = iLdd.DeviceCaps(d_caps); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
369 |
if (ret == KErrNone) |
0 | 370 |
{ |
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
371 |
if((d_caps().iFeatureWord1 & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) != KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
372 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
373 |
// Set up DMA if possible (errors are non-critical) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
374 |
TInt err = iLdd.AllocateEndpointResource(KOutEndpoint, EUsbcEndpointResourceDMA); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
375 |
if (err != KErrNone) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
376 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
377 |
__PRINT1(_L("Set DMA on OUT endpoint failed with error code: %d"), err); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
378 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
379 |
err = iLdd.AllocateEndpointResource(KInEndpoint, EUsbcEndpointResourceDMA); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
380 |
if (err != KErrNone) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
381 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
382 |
__PRINT1(_L("Set DMA on IN endpoint failed with error code: %d"), err); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
383 |
} |
0 | 384 |
|
39
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
385 |
// Set up Double Buffering if possible (errors are non-critical) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
386 |
err = iLdd.AllocateEndpointResource(KOutEndpoint, EUsbcEndpointResourceDoubleBuffering); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
387 |
if (err != KErrNone) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
388 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
389 |
__PRINT1(_L("Set Double Buffering on OUT endpoint failed with error code: %d"), err); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
391 |
err = iLdd.AllocateEndpointResource(KInEndpoint, EUsbcEndpointResourceDoubleBuffering); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
392 |
if (err != KErrNone) |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
393 |
{ |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
394 |
__PRINT1(_L("Set Double Buffering on IN endpoint failed with error code: %d"), err); |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
} |
5d2844f35677
Revision: 201004
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
396 |
} |
0 | 397 |
} |
398 |
||
399 |
if (aDiscard) |
|
400 |
{ |
|
401 |
TInt bytes; |
|
402 |
const TInt err = iLdd.QueryReceiveBuffer(KOutEndpoint, bytes); |
|
403 |
if (err != KErrNone || bytes <= 0) |
|
404 |
{ |
|
405 |
__PRINT1(_L("Error: err=%d bytes=%d"), bytes); |
|
406 |
} |
|
407 |
else |
|
408 |
{ |
|
409 |
__PRINT1(_L("RxBuffer has %d bytes"), bytes); |
|
410 |
FlushDataOut(bytes); |
|
411 |
} |
|
412 |
} |
|
413 |
||
414 |
ClientReadCbw(); |
|
415 |
return res; |
|
416 |
} |
|
417 |
||
418 |
||
419 |
void CBulkOnlyTransport::HwStop() |
|
420 |
{ |
|
421 |
__MSFNLOG |
|
422 |
if (iStarted) |
|
423 |
{ |
|
424 |
iController.DriveManager().Disconnect(); |
|
425 |
Cancel(); |
|
426 |
iBotControlInterface->Cancel(); |
|
427 |
iProtocol->Cancel(); |
|
428 |
iStarted = EFalse; |
|
429 |
} |
|
430 |
} |
|
431 |
||
432 |
||
433 |
void CBulkOnlyTransport::HwSuspend() |
|
434 |
{ |
|
435 |
__MSFNLOG |
|
436 |
iController.DriveManager().Disconnect(); |
|
437 |
} |
|
438 |
||
439 |
||
440 |
void CBulkOnlyTransport::HwResume() |
|
441 |
{ |
|
442 |
__MSFNLOG |
|
443 |
iController.DriveManager().Connect(); |
|
444 |
} |
|
445 |
||
446 |
||
447 |
/** |
|
448 |
Stops the Bulk Only Transport |
|
449 |
*/ |
|
450 |
TInt CBulkOnlyTransport::Stop() |
|
451 |
{ |
|
452 |
__MSFNLOG |
|
453 |
iBotControlInterface->Cancel(); |
|
454 |
iDeviceStateNotifier->Cancel(); |
|
455 |
Cancel(); |
|
456 |
if (iInterfaceConfigured) |
|
457 |
{ |
|
458 |
iLdd.ReleaseInterface(0); |
|
459 |
SetupConfigurationDescriptor(ETrue); |
|
460 |
iLdd.Close(); |
|
461 |
} |
|
462 |
iCurrentState = ENone; |
|
463 |
iInterfaceConfigured = EFalse; |
|
464 |
||
465 |
return KErrNone; |
|
466 |
} |
|
467 |
||
468 |
||
469 |
/** |
|
470 |
Read aLength bytes of data from the host into the read buffer. |
|
471 |
@param aLength The number of bytes to read from the host. |
|
472 |
*/ |
|
473 |
void CBulkOnlyTransport::ClientReadCbw() |
|
474 |
{ |
|
475 |
__MSFNLOG |
|
476 |
if (IsActive()) |
|
477 |
{ |
|
478 |
__PRINT(_L("Still active\n")); |
|
479 |
__ASSERT_DEBUG(EFalse, User::Panic(KUsbMsClientPanicCat, EMsBulkOnlyStillActive)); |
|
480 |
return; |
|
481 |
} |
|
482 |
||
483 |
ReadCbw(); |
|
484 |
} |
|
485 |
||
486 |
||
487 |
void CBulkOnlyTransport::ReadCbw() |
|
488 |
{ |
|
489 |
__MSFNLOG |
|
490 |
iCbwBuf.SetMax(); |
|
491 |
iLdd.ReadUntilShort(iStatus, KOutEndpoint, iCbwBuf, iCbwBuf.Length()); |
|
492 |
iCurrentState = EWaitForCBW; |
|
493 |
SetActive(); |
|
494 |
} |
|
495 |
||
496 |
||
497 |
void CBulkOnlyTransport::DoCancel() |
|
498 |
{ |
|
499 |
__MSFNLOG |
|
500 |
iLdd.WriteCancel(KInEndpoint); |
|
501 |
iLdd.ReadCancel(KOutEndpoint); |
|
502 |
} |
|
503 |
||
504 |
||
505 |
void CBulkOnlyTransport::Activate(TInt aReason) |
|
506 |
{ |
|
507 |
__MSFNLOG |
|
508 |
SetActive(); |
|
509 |
TRequestStatus* r = &iStatus; |
|
510 |
User::RequestComplete(r, aReason); |
|
511 |
} |
|
512 |
||
513 |
||
514 |
void CBulkOnlyTransport::RunL() |
|
515 |
{ |
|
516 |
__MSFNLOG |
|
517 |
if (iStatus != KErrNone) |
|
518 |
{ |
|
519 |
__PRINT1(_L("Error %d in RunL, halt endpoints \n"), iStatus.Int()); |
|
520 |
SetPermError(); //halt endpoints for reset recovery |
|
521 |
return; |
|
522 |
} |
|
523 |
||
524 |
switch (iCurrentState) |
|
525 |
{ |
|
526 |
case EWaitForCBW: |
|
527 |
__PRINT(_L("EWaitForCBW")); |
|
528 |
TRAPD(err, DecodeCbwL()); |
|
529 |
if (err) |
|
530 |
{ |
|
531 |
// CBW not valid or meaningful |
|
532 |
// Specification says: "If the CBW is not valid, the device |
|
533 |
// shall STALL the Bulk-In pipe. Also, the device shall either |
|
534 |
// STALL the Bulk-Out pipe, or the device shall accept and |
|
535 |
// discard any Bulk-Out data. The device shall maintain this |
|
536 |
// state until a Reset Recovery." Here we keep bulk-in ep |
|
537 |
// stalled and ignore bulk-out ep. |
|
538 |
SetPermError(); |
|
539 |
return; |
|
540 |
} |
|
541 |
break; |
|
542 |
||
543 |
case EHandleDataIn: |
|
544 |
{ |
|
545 |
__PRINT(_L("EHandleDataIn")); |
|
546 |
iDataTransferMan.SetModeNoData(); |
|
547 |
||
548 |
if (iDataTransferMan.iDataResidue && iStallAllowed) |
|
549 |
{ |
|
550 |
StallEndpointAndWaitForClear(KInEndpoint); |
|
551 |
} |
|
552 |
#ifdef MSDC_TESTMODE |
|
553 |
if (iTestParser && iTestParser->Enabled()) |
|
554 |
{ |
|
555 |
if (iTestParser->TestCase() == TTestParser::ETestCaseDiStallCsw) |
|
556 |
{ |
|
557 |
iTestParser->ClrTestCase(); |
|
558 |
__TESTMODEPRINT1("CBW Tag=0x%x: Stalling CSW Data-In", iCbwTag); |
|
559 |
StallEndpointAndWaitForClear(KInEndpoint); |
|
560 |
} |
|
561 |
} |
|
562 |
#endif |
|
563 |
SendCsw(iCbwTag, iDataTransferMan.iDataResidue, iCmdStatus); |
|
564 |
} |
|
565 |
break; |
|
566 |
||
567 |
case EHandleDataOut: |
|
568 |
{ |
|
569 |
TUint bytesWritten; |
|
570 |
TInt ret = iProtocol->MediaWritePacket(bytesWritten); |
|
571 |
iDataTransferMan.iDataResidue -= bytesWritten; |
|
572 |
||
573 |
switch(ret) |
|
574 |
{ |
|
575 |
case KErrCompletion: |
|
576 |
{ |
|
577 |
// The protocol has indicated with KErrCompletion that |
|
578 |
// sufficient data is available in the buffer to process the |
|
579 |
// transfer immediately. |
|
580 |
||
581 |
TInt deviceDataLength = iDataTransferMan.iReadBuf.Length(); |
|
582 |
iLdd.Read(iStatus, KOutEndpoint, iDataTransferMan.iReadBuf, deviceDataLength); |
|
583 |
SetActive(); |
|
584 |
} |
|
585 |
break; |
|
586 |
case KErrNotReady: |
|
587 |
{ |
|
588 |
// The protocol has indicated with KErrNotReady that |
|
589 |
// insufficient data is available in the buffer, so should wait |
|
590 |
// for it to arrive. |
|
591 |
TInt deviceDataLength = iDataTransferMan.iReadBuf.Length(); |
|
592 |
iLdd.Read(iStatus, KOutEndpoint, iDataTransferMan.iReadBuf, deviceDataLength); |
|
593 |
SetActive(); |
|
594 |
} |
|
595 |
break; |
|
596 |
case KErrAbort: |
|
597 |
{ |
|
598 |
iDataTransferMan.SetModeNoData(); |
|
599 |
iCmdStatus = TBotCsw::ECommandFailed; |
|
600 |
if (iDataTransferMan.iDataResidue) |
|
601 |
{ |
|
602 |
__PRINT(_L("Discarding residue")); |
|
603 |
FlushDataOut(iDataTransferMan.iTransportResidue); |
|
604 |
} |
|
605 |
SendCsw(iCbwTag, iDataTransferMan.iDataResidue, iCmdStatus); |
|
606 |
} |
|
607 |
break; |
|
608 |
||
609 |
case KErrNone: |
|
610 |
default: |
|
611 |
{ |
|
612 |
// The protocol has indicated that transfer is complete, so |
|
613 |
// send the CSW response to the host. |
|
614 |
iDataTransferMan.SetModeNoData(); |
|
615 |
#ifdef MSDC_TESTMODE |
|
616 |
if (iDataTransferMan.iDataResidue) |
|
617 |
{ |
|
618 |
TBool done = EFalse; |
|
619 |
if (iTestParser && iTestParser->Enabled()) |
|
620 |
{ |
|
621 |
TInt testCase = iTestParser->TestCase(); |
|
622 |
if (testCase == TTestParser::ETestCaseDoStallCsw) |
|
623 |
{ |
|
624 |
iTestParser->ClrTestCase(); |
|
625 |
__TESTMODEPRINT1("CBW Tag=0x%x: Stalling CSW Data-Out", iCbwTag); |
|
626 |
StallEndpointAndWaitForClear(KInEndpoint); |
|
627 |
done = ETrue; |
|
628 |
} |
|
629 |
} |
|
630 |
if (!done) |
|
631 |
{ |
|
632 |
__PRINT(_L("Discarding residue")); |
|
633 |
// we have to read as much data as available that host PC |
|
634 |
// sends; otherwise, bulk-out endpoint will need to keep |
|
635 |
// sending NAK back. |
|
636 |
FlushDataOut(iDataTransferMan.iDataResidue); |
|
637 |
__TESTMODEPRINT2("CBW Tag=0x%x: Residue = x%x", |
|
638 |
iCbwTag, iDataTransferMan.iDataResidue); |
|
639 |
} |
|
640 |
} |
|
641 |
else |
|
642 |
{ |
|
643 |
if (iTestParser && iTestParser->Enabled()) |
|
644 |
{ |
|
645 |
TInt testCase = iTestParser->TestCase(); |
|
646 |
if (testCase == TTestParser::ETestCaseDoStallCsw) |
|
647 |
{ |
|
648 |
iTestParser->ClrTestCase(); |
|
649 |
__TESTMODEPRINT1("CBW Tag=0x%x: Stalling CSW Data-Out", iCbwTag); |
|
650 |
StallEndpointAndWaitForClear(KInEndpoint); |
|
651 |
} |
|
652 |
} |
|
653 |
} |
|
654 |
||
655 |
#else |
|
656 |
if (iDataTransferMan.iDataResidue) |
|
657 |
{ |
|
658 |
__PRINT(_L("Discarding residue")); |
|
659 |
// we have to read as much data as available that host PC |
|
660 |
// sends; otherwise, bulk-out endpoint will need to keep |
|
661 |
// sending NAK back. |
|
662 |
FlushDataOut(iDataTransferMan.iDataResidue); |
|
663 |
} |
|
664 |
#endif |
|
665 |
SendCsw(iCbwTag, iDataTransferMan.iDataResidue, iCmdStatus); |
|
666 |
} |
|
667 |
break; // KErrNone |
|
668 |
} // switch |
|
669 |
} |
|
670 |
break; // EReadingData |
|
671 |
||
672 |
case ESendingCSW: |
|
673 |
__PRINT(_L("ESendingCSW")); |
|
674 |
ReadCbw(); |
|
675 |
break; |
|
676 |
||
677 |
case EPermErr: |
|
678 |
__PRINT(_L("EPermErr")); |
|
679 |
StallEndpointAndWaitForClear(KInEndpoint); |
|
680 |
break; |
|
681 |
||
682 |
default: |
|
683 |
SetPermError(); // unexpected state |
|
684 |
} |
|
685 |
} |
|
686 |
||
687 |
||
688 |
/** |
|
689 |
Decode the CBW received from the host via KOutEndpoint |
|
690 |
||
691 |
- If the header is valid, the data content is passed to the parser. |
|
692 |
- Depending on the command, more data may be transmitted/received. |
|
693 |
- ...or the CSW is sent (if not a data command). |
|
694 |
||
695 |
*/ |
|
696 |
void CBulkOnlyTransport::DecodeCbwL() |
|
697 |
{ |
|
698 |
__MSFNLOG |
|
699 |
TBotServerReq req; |
|
700 |
req.DecodeL(iCbwBuf); |
|
701 |
||
702 |
if (!(req.IsValidCbw() && req.IsMeaningfulCbw(iMaxLun))) |
|
703 |
{ |
|
704 |
User::Leave(KErrGeneral); |
|
705 |
} |
|
706 |
||
707 |
TPtrC8 aData(&iCbwBuf[TBotCbw::KCbwCbOffset], TBotCbw::KMaxCbwcbLength); |
|
708 |
//aData.Set(&iCbwBuf[TBotCbw::KCbwCbOffset], TBotCbw::KMaxCbwcbLength); |
|
709 |
TUint8 lun = req.Lun(); |
|
710 |
||
711 |
iCbwTag = req.Tag(); |
|
712 |
TUint32 hostDataLength = req.DataTransferLength(); |
|
713 |
iDataTransferMan.SetHostDataLen(hostDataLength); |
|
714 |
||
715 |
TBotServerReq::TCbwDirection dataToHost = req.Direction(); |
|
716 |
||
717 |
__PRINT4(_L("lun =%d, hostDataLength=%d, CBWtag = 0x%X\n, dataToHost=%d\n"), |
|
718 |
lun, hostDataLength, iCbwTag, dataToHost); |
|
719 |
||
720 |
////////////////////////////////////////////// |
|
721 |
TBool ret = iProtocol->DecodePacket(aData, lun); |
|
722 |
////////////////////////////////////////////// |
|
723 |
||
724 |
iStallAllowed = ETrue; |
|
725 |
||
726 |
if (!ret) |
|
727 |
{ |
|
728 |
__PRINT(_L("Command Failed\n")); |
|
729 |
iCmdStatus = TBotCsw::ECommandFailed; |
|
730 |
} |
|
731 |
else |
|
732 |
{ |
|
733 |
__PRINT(_L("Command Passed\n")); |
|
734 |
iCmdStatus = TBotCsw::ECommandPassed; |
|
735 |
} |
|
736 |
||
737 |
if (hostDataLength) // Host expected data transfer |
|
738 |
{ |
|
739 |
if (dataToHost == TBotServerReq::EDataIn) // send data to host |
|
740 |
{ |
|
741 |
if (!iDataTransferMan.IsModeDataIn()) |
|
742 |
{ |
|
743 |
__PRINT(_L("Write buffer was not setup\n")); |
|
744 |
||
745 |
if (hostDataLength <= KBOTMaxBufSize) |
|
746 |
{ |
|
747 |
// Case 4 or 8" |
|
748 |
iBuf.FillZ(hostDataLength); |
|
749 |
iLdd.Write(iStatus, KInEndpoint, iBuf, hostDataLength); |
|
750 |
SetActive(); |
|
751 |
iCurrentState = EHandleDataIn; |
|
752 |
iStallAllowed = EFalse; |
|
753 |
if (iDataTransferMan.IsModeDataOut()) |
|
754 |
{ |
|
755 |
//read buffer WAS set up - case (8) |
|
756 |
iCmdStatus = TBotCsw::EPhaseError; |
|
757 |
} |
|
758 |
return; |
|
759 |
} |
|
760 |
else |
|
761 |
{ |
|
762 |
// Use next block instead of StallEndpointAndWaitForClear(KInEndpoint); |
|
763 |
FlushDataIn(hostDataLength); |
|
764 |
} |
|
765 |
||
766 |
if (iDataTransferMan.IsModeDataOut()) |
|
767 |
{ |
|
768 |
//read buffer WAS set up - case (8) |
|
769 |
SendCsw(iCbwTag, hostDataLength, TBotCsw::EPhaseError); |
|
770 |
//don't care to reset any flag - should get reset recovery |
|
771 |
} |
|
772 |
else |
|
773 |
{ |
|
774 |
// case (4) |
|
775 |
SendCsw(iCbwTag, hostDataLength, iCmdStatus); |
|
776 |
} |
|
777 |
return; |
|
778 |
} |
|
779 |
||
780 |
//================== |
|
781 |
TInt deviceDataLength = iDataTransferMan.iWriteBuf.Length(); |
|
782 |
iDataTransferMan.iDataResidue = hostDataLength - deviceDataLength; |
|
783 |
||
784 |
#ifdef MSDC_TESTMODE |
|
785 |
if (iTestParser && iTestParser->Enabled()) |
|
786 |
{ |
|
787 |
TInt testCase = iTestParser->TestCase(); |
|
788 |
if (testCase == TTestParser::ETestCaseDiResidue) |
|
789 |
{ |
|
790 |
__TESTMODEPRINT2("DataIN (Data Residue) %x %x", iTestParser->TestCounter(), hostDataLength); |
|
791 |
||
792 |
const TInt KTransferLength = 0x100; |
|
793 |
const TInt KResidueA = KTransferLength/4 -10; |
|
794 |
const TInt KResidueB = KTransferLength/4 - 10; |
|
795 |
if (hostDataLength > KTransferLength) |
|
796 |
{ |
|
797 |
TInt residue = 0; |
|
798 |
TInt i = iTestParser->TestCounter(); |
|
799 |
switch (i) |
|
800 |
{ |
|
801 |
case 0: |
|
802 |
iTestParser->ClrTestCase(); |
|
803 |
break; |
|
804 |
case 1: |
|
805 |
residue = KResidueA; |
|
806 |
break; |
|
807 |
case 2: |
|
808 |
residue = KResidueB; |
|
809 |
break; |
|
810 |
||
811 |
default: |
|
812 |
break; |
|
813 |
} |
|
814 |
||
815 |
//deviceDataLength -= residue; |
|
816 |
iDataTransferMan.iDataResidue = residue; |
|
817 |
iStallAllowed = EFalse; |
|
818 |
iTestParser->DecTestCounter(); |
|
819 |
||
820 |
__TESTMODEPRINT4("CBW Tag=0x%x: Setting Residue (Data-In) hdl=%x ddl=%x residue=%x", |
|
821 |
iCbwTag, hostDataLength, deviceDataLength, residue); |
|
822 |
} |
|
823 |
} |
|
824 |
} |
|
825 |
#endif |
|
826 |
if (deviceDataLength < hostDataLength && hostDataLength <= KBOTMaxBufSize) |
|
827 |
{ |
|
828 |
// do not pad |
|
829 |
// iStallAllowed = ETrue; |
|
830 |
// __PRINT1(_L("iBuf.Length=%d\n"),iBuf.Length()); |
|
831 |
// iLdd.Write(iStatus, KInEndpoint, iBuf, deviceDataLength); |
|
832 |
// SetActive(); |
|
833 |
//iCurrentState = EWritingData; |
|
834 |
||
835 |
// pad |
|
836 |
iBuf.Zero(); |
|
837 |
iBuf.Append(iDataTransferMan.iWriteBuf); |
|
838 |
iBuf.SetLength(hostDataLength); |
|
839 |
iStallAllowed = EFalse; |
|
840 |
__PRINT1(_L("iBuf.Length=%d\n"),iBuf.Length()); |
|
841 |
iLdd.Write(iStatus, KInEndpoint, iBuf, hostDataLength); |
|
842 |
SetActive(); |
|
843 |
iCurrentState = EHandleDataIn; |
|
844 |
||
845 |
return; |
|
846 |
} |
|
847 |
||
848 |
if (deviceDataLength == hostDataLength) |
|
849 |
{ |
|
850 |
//case (6)[==] |
|
851 |
#ifdef MSDC_TESTMODE |
|
852 |
if (iTestParser && iTestParser->Enabled()) |
|
853 |
{ |
|
854 |
if (iTestParser->TestCase() == TTestParser::ETestCaseDiStallData) |
|
855 |
{ |
|
856 |
iTestParser->ClrTestCase(); |
|
857 |
__TESTMODEPRINT1("CBW Tag=0x%x: Stalling CSW Data-In", iCbwTag); |
|
858 |
StallEndpointAndWaitForClear(KInEndpoint); |
|
859 |
} |
|
860 |
} |
|
861 |
#endif |
|
862 |
||
863 |
DataInWriteRequest(deviceDataLength); |
|
864 |
return; |
|
865 |
} |
|
866 |
else if (deviceDataLength < hostDataLength) |
|
867 |
{ |
|
868 |
//case (5)[<] |
|
869 |
DataInWriteRequest(deviceDataLength, ETrue); // Send ZLP |
|
870 |
return; |
|
871 |
} |
|
872 |
else |
|
873 |
{ |
|
874 |
// deviceDataLength > hostDataLength - case (7) |
|
875 |
iCmdStatus = TBotCsw::EPhaseError; |
|
876 |
iDataTransferMan.iDataResidue = 0; |
|
877 |
DataInWriteRequest(hostDataLength); |
|
878 |
return; |
|
879 |
} |
|
880 |
} |
|
881 |
else // read data from host |
|
882 |
{ |
|
883 |
if (!iDataTransferMan.IsModeDataOut()) |
|
884 |
{ |
|
885 |
__PRINT(_L("Read buffer was not setup\n")); |
|
886 |
||
887 |
// Use next block instead of StallEndpointAndWaitForClear(KOutEndpoint); |
|
888 |
FlushDataOut(hostDataLength); |
|
889 |
if (iDataTransferMan.IsModeDataIn()) |
|
890 |
{ |
|
891 |
//case (10) |
|
892 |
SendCsw(iCbwTag, hostDataLength, TBotCsw::EPhaseError); |
|
893 |
} |
|
894 |
else |
|
895 |
{ |
|
896 |
// case (9) |
|
897 |
SendCsw(iCbwTag, hostDataLength, iCmdStatus); |
|
898 |
} |
|
899 |
return; |
|
900 |
} |
|
901 |
||
902 |
TInt deviceDataLength = iDataTransferMan.iReadBuf.Length(); |
|
903 |
||
904 |
if (deviceDataLength <= hostDataLength) |
|
905 |
{ |
|
906 |
// case (11) and (12) |
|
907 |
#ifdef MSDC_TESTMODE |
|
908 |
TBool done = EFalse; |
|
909 |
if (iTestParser && iTestParser->Enabled()) |
|
910 |
{ |
|
911 |
TInt testCase = iTestParser->TestCase(); |
|
912 |
||
913 |
if (testCase == TTestParser::ETestCaseDoStallData) |
|
914 |
{ |
|
915 |
iTestParser->ClrTestCase(); |
|
916 |
// Stall Data Out |
|
917 |
__TESTMODEPRINT2("CBW Tag=0x%x: Stalling Data (Data-Out) Residue = x%x", |
|
918 |
iCbwTag, iDataTransferMan.iDataResidue); |
|
919 |
StallEndpointAndWaitForClear(KOutEndpoint); |
|
920 |
TInt bytes; |
|
921 |
const TInt err = iLdd.QueryReceiveBuffer(KOutEndpoint, bytes); |
|
922 |
__PRINT1(_L("Error: err=%d bytes=%d"), bytes); |
|
923 |
FlushDataOut(bytes); |
|
924 |
} |
|
925 |
} |
|
926 |
if (!done) |
|
927 |
{ |
|
928 |
DataOutReadRequest(deviceDataLength); |
|
929 |
} |
|
930 |
#else |
|
931 |
DataOutRead(deviceDataLength); |
|
932 |
#endif |
|
933 |
return; |
|
934 |
} |
|
935 |
else |
|
936 |
{ |
|
937 |
// case (13) |
|
938 |
/** |
|
939 |
* Comment following line in order to pass compliant test. |
|
940 |
* As spec said in case 13:"The device may receive data up to a |
|
941 |
* total of dCBWDataTransferLength." |
|
942 |
* Here we choose to ignore incoming data. |
|
943 |
*/ |
|
944 |
//StallEndpointAndWaitForClear(KOutEndpoint); //Stall Out endpoint |
|
945 |
if (iDataTransferMan.IsModeDataOut()) |
|
946 |
{ |
|
947 |
iDataTransferMan.SetModeNoData(); |
|
948 |
iLdd.Read(iStatus, KOutEndpoint, iDataTransferMan.iReadBuf, hostDataLength); |
|
949 |
User::WaitForRequest(iStatus); |
|
950 |
iProtocol->MediaWriteAbort(); |
|
951 |
} |
|
952 |
SendCsw(iCbwTag, hostDataLength, TBotCsw::EPhaseError); |
|
953 |
return; |
|
954 |
} |
|
955 |
} |
|
956 |
} |
|
957 |
else // Host expected no data transfer |
|
958 |
{ |
|
959 |
__PRINT(_L("No data transfer expected\n")); |
|
960 |
iDataTransferMan.iDataResidue = 0; |
|
961 |
if (!iDataTransferMan.IsModeNoData()) |
|
962 |
{ |
|
963 |
// case (2) and (3) |
|
964 |
SendCsw(iCbwTag, 0, TBotCsw::EPhaseError); |
|
965 |
} |
|
966 |
else |
|
967 |
{ |
|
968 |
//case (1) |
|
969 |
#ifdef MSDC_TESTMODE |
|
970 |
if (iTestParser && iTestParser->Enabled()) |
|
971 |
{ |
|
972 |
TInt testCase = iTestParser->TestCase(); |
|
973 |
if (testCase == TTestParser::ETestCaseNoDataStallCsw) |
|
974 |
{ |
|
975 |
__TESTMODEPRINT1("CBW Tag=0x%x: Stalling CSW for Case 1 (Hn=Dn)", iCbwTag); |
|
976 |
iTestParser->ClrTestCase(); |
|
977 |
StallEndpointAndWaitForClear(KInEndpoint); |
|
978 |
} |
|
979 |
||
980 |
if (testCase == TTestParser::ETestCaseNoDataPhaseError) |
|
981 |
{ |
|
982 |
__TESTMODEPRINT1("CBW Tag=0x%x: Enabling phase error (no data)", iCbwTag); |
|
983 |
iTestParser->SetPhaseError(); |
|
984 |
} |
|
985 |
} |
|
986 |
#endif |
|
987 |
SendCsw(iCbwTag, 0, iCmdStatus); |
|
988 |
} |
|
989 |
} |
|
990 |
} |
|
991 |
||
992 |
||
993 |
/** |
|
994 |
Initiate stalling of bulk IN endpoint. |
|
995 |
Used when protocol wants to force host to initiate a reset recovery. |
|
996 |
*/ |
|
997 |
void CBulkOnlyTransport::SetPermError() |
|
998 |
{ |
|
999 |
__MSFNLOG |
|
1000 |
iCurrentState = EPermErr; |
|
1001 |
Activate(KErrNone); |
|
1002 |
} |
|
1003 |
||
1004 |
||
1005 |
/** |
|
1006 |
Send data provided by protocol to the host |
|
1007 |
||
1008 |
@param aLength amount of data (in bytes) to be send to host |
|
1009 |
*/ |
|
1010 |
void CBulkOnlyTransport::DataInWriteRequest(TUint aLength, TBool aZlpRequired) |
|
1011 |
{ |
|
1012 |
__MSFNLOG |
|
1013 |
iLdd.Write(iStatus, KInEndpoint, iDataTransferMan.iWriteBuf, aLength, aZlpRequired); |
|
1014 |
iDataTransferMan.iTransportResidue -= aLength; |
|
1015 |
iCurrentState = EHandleDataIn; |
|
1016 |
SetActive(); |
|
1017 |
} |
|
1018 |
||
1019 |
||
1020 |
/** |
|
1021 |
Request data form the host for the protocol |
|
1022 |
||
1023 |
@param aLength amount of data (in bytes) to be received from the host |
|
1024 |
*/ |
|
1025 |
void CBulkOnlyTransport::DataOutReadRequest(TUint aLength) |
|
1026 |
{ |
|
1027 |
__MSFNLOG |
|
1028 |
iLdd.Read(iStatus, KOutEndpoint, iDataTransferMan.iReadBuf, aLength); |
|
1029 |
iDataTransferMan.iTransportResidue -= aLength; |
|
1030 |
iCurrentState = EHandleDataOut; |
|
1031 |
SetActive(); |
|
1032 |
} |
|
1033 |
||
1034 |
||
1035 |
/** |
|
1036 |
Send Command Status Wrapper to the host |
|
1037 |
||
1038 |
@param aTag Echo of Command Block Tag sent by the host. |
|
1039 |
@param aDataResidue the difference between the amount of data expected by the |
|
1040 |
host, and the actual amount of data processed by the device. |
|
1041 |
@param aStatus indicates the success or failure of the command. |
|
1042 |
*/ |
|
1043 |
void CBulkOnlyTransport::SendCsw(TUint aTag, TUint32 aDataResidue, TBotCsw::TCswStatus aStatus) |
|
1044 |
{ |
|
1045 |
__MSFNLOG |
|
1046 |
__PRINT2(_L("DataResidue = %d, Status = %d \n"), aDataResidue, aStatus); |
|
1047 |
iCsw.SetLength(TBotCsw::KCswLength); |
|
1048 |
TBotServerResp resp(iCbwTag, aDataResidue, aStatus); |
|
1049 |
#ifdef MSDC_TESTMODE |
|
1050 |
resp.EncodeL(iCsw, iTestParser); |
|
1051 |
#else |
|
1052 |
resp.EncodeL(iCsw); |
|
1053 |
#endif |
|
1054 |
iLdd.Write(iStatus, KInEndpoint, iCsw, TBotCsw::KCswLength); |
|
1055 |
iCurrentState = ESendingCSW; |
|
1056 |
SetActive(); |
|
1057 |
} |
|
1058 |
||
1059 |
||
1060 |
/** |
|
1061 |
Associates the transport with the protocol. Called during initialization of the controller. |
|
1062 |
||
1063 |
@param aProtocol reference to the protocol |
|
1064 |
*/ |
|
1065 |
void CBulkOnlyTransport::RegisterProtocol(MServerProtocol& aProtocol) |
|
1066 |
{ |
|
1067 |
__MSFNLOG |
|
1068 |
iProtocol = &aProtocol; |
|
1069 |
} |
|
1070 |
||
1071 |
||
1072 |
/** |
|
1073 |
Used by CControlInterface |
|
1074 |
||
1075 |
@return reference to the controller which instantiate the CBulkOnlyTransport |
|
1076 |
*/ |
|
1077 |
CUsbMassStorageController& CBulkOnlyTransport::Controller() |
|
1078 |
{ |
|
1079 |
return iController; |
|
1080 |
} |
|
1081 |
||
1082 |
||
1083 |
/** |
|
1084 |
@return the number of logical units supported by the device. |
|
1085 |
Logical Unit Numbers on the device shall be numbered contiguously starting from LUN |
|
1086 |
0 to a maximum LUN of 15 (Fh). |
|
1087 |
*/ |
|
1088 |
TInt CBulkOnlyTransport::MaxLun() |
|
1089 |
{ |
|
1090 |
__MSFNLOG |
|
1091 |
return iMaxLun; |
|
1092 |
} |
|
1093 |
||
1094 |
||
1095 |
/** |
|
1096 |
Used by CControlInterface |
|
1097 |
@return reference to USB logical driver |
|
1098 |
*/ |
|
1099 |
RDevUsbcClient& CBulkOnlyTransport::Ldd() |
|
1100 |
{ |
|
1101 |
return iLdd; |
|
1102 |
} |
|
1103 |
||
1104 |
||
1105 |
void CBulkOnlyTransport::StallEndpointAndWaitForClear(TEndpointNumber aEndpoint) |
|
1106 |
{ |
|
1107 |
__MSFNLOG |
|
1108 |
__ASSERT_DEBUG(aEndpoint != EEndpoint0, User::Panic(KUsbMsClientPanicCat, EMsWrongEndpoint)); |
|
1109 |
||
1110 |
// Now stall this endpoint |
|
1111 |
__PRINT1(_L("Stalling endpoint %d"), aEndpoint); |
|
1112 |
__TESTMODEPRINT2("CBW Tag=0x%x: Stalling endpoint %d", iCbwTag, aEndpoint); |
|
1113 |
TInt r = iLdd.HaltEndpoint(aEndpoint); |
|
1114 |
if (r != KErrNone) |
|
1115 |
{ |
|
1116 |
__PRINT2(_L("Error: stalling ep %d failed: %d"), aEndpoint, r); |
|
1117 |
} |
|
1118 |
TEndpointState ep_state; |
|
1119 |
TInt i = 0; |
|
1120 |
do |
|
1121 |
{ |
|
1122 |
// Wait for 10ms before checking the ep status |
|
1123 |
User::After(10000); |
|
1124 |
||
1125 |
if (aEndpoint == KInEndpoint) |
|
1126 |
{ |
|
1127 |
// Discard BULK-OUT data |
|
1128 |
TInt bytes; |
|
1129 |
const TInt err = iLdd.QueryReceiveBuffer(KOutEndpoint, bytes); |
|
1130 |
if (err != KErrNone || bytes <= 0) |
|
1131 |
{ |
|
1132 |
__PRINT1(_L("Error: err=%d bytes=%d"), bytes); |
|
1133 |
} |
|
1134 |
else |
|
1135 |
{ |
|
1136 |
__PRINT1(_L("RxBuffer has %d bytes"), bytes); |
|
1137 |
FlushDataOut(bytes); |
|
1138 |
} |
|
1139 |
} |
|
1140 |
||
1141 |
iLdd.EndpointStatus(aEndpoint, ep_state); |
|
1142 |
if (++i >= 550) |
|
1143 |
{ |
|
1144 |
// 5.5 secs should be enough (see 9.2.6.1 Request Processing Timing) |
|
1145 |
__PRINT1(_L("Error: Checked for ep %d de-stall for 5.5s - giving up now"), aEndpoint); |
|
1146 |
__TESTMODEPRINT1("Error: Checked for ep %d de-stall for 5.5s - giving up now", aEndpoint); |
|
1147 |
// We can now only hope for a Reset Recovery |
|
1148 |
return; |
|
1149 |
} |
|
1150 |
} while ((ep_state == EEndpointStateStalled) && iStarted); |
|
1151 |
__PRINT2(_L("Checked for ep %d de-stall: %d time(s)"), aEndpoint, i); |
|
1152 |
__TESTMODEPRINT2("Checked for ep %d de-stall: %d time(s)", aEndpoint, i); |
|
1153 |
} |
|
1154 |
||
1155 |
||
1156 |
||
1157 |
/** |
|
1158 |
Called by the protocol to determine how many bytes of data are available in the read buffer. |
|
1159 |
||
1160 |
@return The number of bytes available in the read buffer |
|
1161 |
*/ |
|
1162 |
TInt CBulkOnlyTransport::BytesAvailable() |
|
1163 |
{ |
|
1164 |
__MSFNLOG |
|
1165 |
TInt bytes = 0; |
|
1166 |
TInt err = iLdd.QueryReceiveBuffer(KOutEndpoint, bytes); |
|
1167 |
if (err != KErrNone) |
|
1168 |
bytes = 0; |
|
1169 |
return bytes; |
|
1170 |
} |
|
1171 |
||
1172 |
||
1173 |
/** |
|
1174 |
* Read out rest data from KOutEndpoint and discard them |
|
1175 |
*/ |
|
1176 |
void CBulkOnlyTransport::FlushDataOut(TInt aLength) |
|
1177 |
{ |
|
1178 |
__MSFNLOG |
|
1179 |
iBuf.SetMax(); |
|
1180 |
TRequestStatus status; |
|
1181 |
while (aLength > 0) |
|
1182 |
{ |
|
1183 |
iLdd.ReadOneOrMore(status, KOutEndpoint, iBuf, iBuf.Length()); |
|
1184 |
User::WaitForRequest(status); |
|
1185 |
TInt err = status.Int(); |
|
1186 |
if (err != KErrNone) |
|
1187 |
{ |
|
1188 |
// Bad. |
|
1189 |
break; |
|
1190 |
} |
|
1191 |
aLength -= iBuf.Length(); |
|
1192 |
} |
|
1193 |
} |
|
1194 |
||
1195 |
||
1196 |
void CBulkOnlyTransport::FlushDataIn(TInt aLength) |
|
1197 |
{ |
|
1198 |
iBuf.SetMax(); |
|
1199 |
TInt c = 0; |
|
1200 |
TInt len; |
|
1201 |
TRequestStatus status; |
|
1202 |
while (c < aLength) |
|
1203 |
{ |
|
1204 |
len = aLength - c; |
|
1205 |
if (len > KBOTMaxBufSize) |
|
1206 |
{ |
|
1207 |
len = KBOTMaxBufSize; |
|
1208 |
} |
|
1209 |
iLdd.Write(status, KInEndpoint, iBuf, len); |
|
1210 |
User::WaitForRequest(status); |
|
1211 |
c += KBOTMaxBufSize; |
|
1212 |
} |
|
1213 |
} |
|
1214 |
||
1215 |
// |
|
1216 |
// --- class CActiveDeviceStateNotifier --------------------------------------------------------- |
|
1217 |
// |
|
1218 |
CActiveDeviceStateNotifier::CActiveDeviceStateNotifier(CBulkOnlyTransport& aParent) |
|
1219 |
: CActive(EPriorityStandard), |
|
1220 |
iParent(aParent), |
|
1221 |
iDeviceState(EUsbcNoState), |
|
1222 |
iOldDeviceState(EUsbcNoState) |
|
1223 |
{ |
|
1224 |
__MSFNLOG |
|
1225 |
} |
|
1226 |
||
1227 |
||
1228 |
CActiveDeviceStateNotifier* CActiveDeviceStateNotifier::NewL(CBulkOnlyTransport& aParent) |
|
1229 |
{ |
|
1230 |
__MSFNSLOG |
|
1231 |
CActiveDeviceStateNotifier* self = new (ELeave) CActiveDeviceStateNotifier(aParent); |
|
1232 |
CleanupStack::PushL(self); |
|
1233 |
self->ConstructL(); |
|
1234 |
CActiveScheduler::Add(self); |
|
1235 |
CleanupStack::Pop(); // self |
|
1236 |
return (self); |
|
1237 |
} |
|
1238 |
||
1239 |
||
1240 |
void CActiveDeviceStateNotifier::ConstructL() |
|
1241 |
{ |
|
1242 |
__MSFNLOG |
|
1243 |
} |
|
1244 |
||
1245 |
||
1246 |
CActiveDeviceStateNotifier::~CActiveDeviceStateNotifier() |
|
1247 |
{ |
|
1248 |
__MSFNLOG |
|
1249 |
Cancel(); // base class |
|
1250 |
} |
|
1251 |
||
1252 |
||
1253 |
void CActiveDeviceStateNotifier::DoCancel() |
|
1254 |
/** |
|
1255 |
* |
|
1256 |
*/ |
|
1257 |
{ |
|
1258 |
__MSFNLOG |
|
1259 |
iParent.Ldd().AlternateDeviceStatusNotifyCancel(); |
|
1260 |
} |
|
1261 |
||
1262 |
||
1263 |
void CActiveDeviceStateNotifier::RunL() |
|
1264 |
/** |
|
1265 |
* |
|
1266 |
*/ |
|
1267 |
{ |
|
1268 |
__MSFNLOG |
|
1269 |
// This displays the device state. |
|
1270 |
// In a real world program, the user could take here appropriate action (cancel a |
|
1271 |
// transfer request or whatever). |
|
1272 |
if (!(iDeviceState & KUsbAlternateSetting)) |
|
1273 |
{ |
|
1274 |
switch (iDeviceState) |
|
1275 |
{ |
|
1276 |
case EUsbcDeviceStateUndefined: |
|
1277 |
__PRINT(_L("Device State notifier: Undefined\n")); |
|
1278 |
iParent.HwStop(); |
|
1279 |
break; |
|
1280 |
case EUsbcDeviceStateAttached: |
|
1281 |
__PRINT(_L("Device State notifier: Attached\n")); |
|
1282 |
iParent.HwStop(); |
|
1283 |
break; |
|
1284 |
case EUsbcDeviceStatePowered: |
|
1285 |
__PRINT(_L("Device State notifier: Powered\n")); |
|
1286 |
iParent.HwStop(); |
|
1287 |
break; |
|
1288 |
case EUsbcDeviceStateDefault: |
|
1289 |
__PRINT(_L("Device State notifier: Default\n")); |
|
1290 |
iParent.HwStop(); |
|
1291 |
break; |
|
1292 |
case EUsbcDeviceStateAddress: |
|
1293 |
__PRINT(_L("Device State notifier: Address\n")); |
|
1294 |
iParent.HwStop(); |
|
1295 |
break; |
|
1296 |
case EUsbcDeviceStateConfigured: |
|
1297 |
__PRINT(_L("Device State notifier: Configured\n")); |
|
1298 |
if (iOldDeviceState == EUsbcDeviceStateSuspended) |
|
1299 |
{ |
|
1300 |
iParent.HwResume(); |
|
1301 |
} |
|
1302 |
else |
|
1303 |
{ |
|
1304 |
iParent.HwStart(); |
|
1305 |
} |
|
1306 |
break; |
|
1307 |
case EUsbcDeviceStateSuspended: |
|
1308 |
__PRINT(_L("Device State notifier: Suspended\n")); |
|
1309 |
if (iOldDeviceState == EUsbcDeviceStateConfigured) |
|
1310 |
{ |
|
1311 |
iParent.HwSuspend(); |
|
1312 |
} |
|
1313 |
break; |
|
1314 |
default: |
|
1315 |
__PRINT(_L("Device State notifier: ***BAD***\n")); |
|
1316 |
iParent.HwStop(); |
|
1317 |
break; |
|
1318 |
} |
|
1319 |
iOldDeviceState = iDeviceState; |
|
1320 |
} |
|
1321 |
else if (iDeviceState & KUsbAlternateSetting) |
|
1322 |
{ |
|
1323 |
__PRINT1(_L("Device State notifier: Alternate interface setting has changed: now %d\n"), iDeviceState & ~KUsbAlternateSetting); |
|
1324 |
} |
|
1325 |
Activate(); |
|
1326 |
} |
|
1327 |
||
1328 |
||
1329 |
void CActiveDeviceStateNotifier::Activate() |
|
1330 |
/** |
|
1331 |
* |
|
1332 |
*/ |
|
1333 |
{ |
|
1334 |
__MSFNLOG |
|
1335 |
if (IsActive()) |
|
1336 |
{ |
|
1337 |
__PRINT(_L("Still active\n")); |
|
1338 |
return; |
|
1339 |
} |
|
1340 |
iParent.Ldd().AlternateDeviceStatusNotify(iStatus, iDeviceState); |
|
1341 |
SetActive(); |
|
1342 |
} |