author | Mike Kinghan <mikek@symbian.org> |
Thu, 25 Nov 2010 14:35:45 +0000 | |
branch | GCC_SURGE |
changeset 305 | 1ba12ef4ef89 |
parent 90 | 947f0dc9f7a8 |
child 297 | b2826f67641f |
permissions | -rw-r--r-- |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
1 |
// Copyright (c) 2008-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 |
// |
|
15 |
||
16 |
/** |
|
17 |
@file |
|
18 |
@internalTechnology |
|
19 |
*/ |
|
20 |
||
21 |
#include <e32base.h> |
|
22 |
#include <d32usbdi_hubdriver.h> |
|
23 |
#include <d32usbdi.h> |
|
24 |
#include <d32otgdi.h> |
|
25 |
#include <d32usbdescriptors.h> |
|
26 |
#include <d32usbtransfers.h> |
|
27 |
#ifdef MASSSTORAGE_PUBLISHER |
|
28 |
#include <e32property.h> |
|
29 |
#endif |
|
30 |
#include "botmsctypes.h" |
|
31 |
#include "msctypes.h" |
|
32 |
#include "mscutils.h" |
|
33 |
#include "mtransport.h" |
|
34 |
#include "mprotocol.h" |
|
35 |
#include "cusbifacehandler.h" |
|
36 |
#include "cbulkonlytransport.h" |
|
37 |
#include "debug.h" |
|
38 |
#include "msdebug.h" |
|
39 |
||
40 |
CBulkOnlyTransport::CBulkOnlyTransport() |
|
41 |
: iBulkOutCbwTd(KCbwPacketSize), |
|
42 |
iBulkDataTd(KResponsePacketSize), |
|
43 |
iBulkInCswTd(KCswPacketSize) |
|
44 |
{ |
|
45 |
__MSFNLOG |
|
46 |
} |
|
47 |
||
48 |
CBulkOnlyTransport::~CBulkOnlyTransport() |
|
49 |
{ |
|
50 |
__MSFNLOG |
|
51 |
delete iUsbInterfaceHandler; |
|
52 |
UnInitialiseTransport(); |
|
53 |
iInterface.Close(); |
|
54 |
} |
|
55 |
||
56 |
/** |
|
57 |
Create CBulkOnlyTransport object. |
|
58 |
||
59 |
@param aInterfaceId The interface ID of the device |
|
60 |
||
61 |
@return CBulkOnlyTransport* Pointer to the created object |
|
62 |
*/ |
|
63 |
CBulkOnlyTransport* CBulkOnlyTransport::NewL(TUint aInterfaceId) |
|
64 |
{ |
|
65 |
__MSFNSLOG |
|
66 |
CBulkOnlyTransport* transport = new (ELeave) CBulkOnlyTransport(); |
|
67 |
CleanupStack::PushL(transport); |
|
68 |
transport->ConstructL(aInterfaceId); |
|
69 |
CleanupStack::Pop(transport); |
|
70 |
return transport; |
|
71 |
} |
|
72 |
||
73 |
||
74 |
void CBulkOnlyTransport::ConstructL(TUint aInterfaceId) |
|
75 |
{ |
|
76 |
__MSFNSLOG |
|
77 |
User::LeaveIfError(iInterface.Open(aInterfaceId)); |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
78 |
iUsbInterfaceHandler = CUsbInterfaceHandler::NewL(iInterface, iBulkPipeIn); |
0 | 79 |
InitialiseTransport(); |
80 |
} |
|
81 |
||
82 |
||
83 |
void CBulkOnlyTransport::Resume() |
|
84 |
{ |
|
85 |
__MSFNSLOG |
|
86 |
__BOTPRINT(_L("BOT RESUME")); |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
|
0 | 88 |
iInterface.CancelPermitSuspend(); |
89 |
} |
|
90 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
91 |
void CBulkOnlyTransport::Suspend(TRequestStatus& aStatus) |
0 | 92 |
{ |
93 |
__MSFNSLOG |
|
94 |
__BOTPRINT(_L("BOT SUSPEND")); |
|
95 |
// iInterface.PermitRemoteWakeup(ETrue); |
|
96 |
iInterface.PermitSuspendAndWaitForResume(aStatus); |
|
97 |
} |
|
98 |
||
99 |
TInt CBulkOnlyTransport::InitialiseTransport() |
|
100 |
{ |
|
101 |
__MSFNLOG |
|
102 |
TInt BulkOutEpAddr; |
|
103 |
TInt BulkInEpAddr; |
|
104 |
const TUint8 KEpDirectionIn = 0x80; |
|
105 |
const TUint8 KEpDirectionOut = 0x00; |
|
106 |
const TUint8 KTransferTypeBulk = 0x02; |
|
107 |
||
108 |
GetEndpointAddress(iInterface,0,KTransferTypeBulk,KEpDirectionOut,BulkOutEpAddr); |
|
109 |
GetEndpointAddress(iInterface,0,KTransferTypeBulk,KEpDirectionIn,BulkInEpAddr); |
|
110 |
iInterface.OpenPipeForEndpoint(iBulkPipeOut, BulkOutEpAddr, EFalse); |
|
111 |
iInterface.OpenPipeForEndpoint(iBulkPipeIn, BulkInEpAddr, EFalse); |
|
112 |
||
113 |
if (iInterface.RegisterTransferDescriptor(iBulkOutCbwTd) != KErrNone || |
|
114 |
iInterface.RegisterTransferDescriptor(iBulkDataTd) != KErrNone || |
|
115 |
iInterface.RegisterTransferDescriptor(iBulkInCswTd) != KErrNone) |
|
116 |
{ |
|
117 |
return KErrGeneral; |
|
118 |
} |
|
119 |
||
120 |
if (iInterface.InitialiseTransferDescriptors() != KErrNone) |
|
121 |
{ |
|
122 |
return KErrGeneral; |
|
123 |
} |
|
124 |
return KErrNone; |
|
125 |
} |
|
126 |
||
127 |
||
128 |
void CBulkOnlyTransport::UnInitialiseTransport() |
|
129 |
{ |
|
130 |
__MSFNLOG |
|
131 |
iBulkPipeOut.Close(); |
|
132 |
iBulkPipeIn.Close(); |
|
133 |
} |
|
134 |
||
135 |
TInt CBulkOnlyTransport::GetEndpointAddress(RUsbInterface& aUsbInterface, |
|
136 |
TInt aInterfaceSetting, |
|
137 |
TUint8 aTransferType, |
|
138 |
TUint8 aDirection, |
|
139 |
TInt& aEndpointAddress) |
|
140 |
{ |
|
141 |
__MSFNLOG |
|
142 |
TUsbInterfaceDescriptor alternateInterfaceDescriptor; |
|
143 |
||
144 |
if (aUsbInterface.GetAlternateInterfaceDescriptor(aInterfaceSetting, alternateInterfaceDescriptor)) |
|
145 |
{ |
|
146 |
__BOTPRINT1(_L("GetEndpointAddress : <Error> Unable to get alternate interface (%x) descriptor"),aInterfaceSetting); |
|
147 |
return KErrGeneral; |
|
148 |
} |
|
149 |
||
150 |
TUsbGenericDescriptor* descriptor = alternateInterfaceDescriptor.iFirstChild; |
|
151 |
||
152 |
while (descriptor) |
|
153 |
{ |
|
154 |
TUsbEndpointDescriptor* endpoint = TUsbEndpointDescriptor::Cast(descriptor); |
|
155 |
if (endpoint) |
|
156 |
{ |
|
157 |
if ((endpoint->Attributes() & aTransferType) == aTransferType) |
|
158 |
{ |
|
159 |
// Found the endpoint address |
|
160 |
if ( (endpoint->EndpointAddress() & 0x80) == aDirection) |
|
161 |
{ |
|
162 |
aEndpointAddress = endpoint->EndpointAddress(); |
|
163 |
__BOTPRINT(_L("GetEndpointAddress : Endpoint address found")); |
|
164 |
return KErrNone; |
|
165 |
} |
|
166 |
} |
|
167 |
} |
|
168 |
descriptor = descriptor->iNextPeer; |
|
169 |
} |
|
170 |
||
171 |
// Unable to find the endpoint address |
|
172 |
__BOTPRINT(_L("GetEndpointAddress : Unable to find endpoint address matching the specified attributes")); |
|
173 |
return KErrNotFound; |
|
174 |
} |
|
175 |
||
176 |
void CBulkOnlyTransport::GetMaxLun(TLun* aMaxLun, const RMessage2& aMessage) |
|
177 |
{ |
|
178 |
__MSFNLOG |
|
179 |
iUsbInterfaceHandler->GetMaxLun(aMaxLun, aMessage); |
|
180 |
} |
|
181 |
||
182 |
TInt CBulkOnlyTransport::Reset() |
|
183 |
{ |
|
184 |
__MSFNLOG |
|
185 |
RUsbInterface::TUsbTransferRequestDetails reqDetails; |
|
186 |
_LIT8(KNullDesC8,""); |
|
187 |
||
188 |
reqDetails.iRequestType = 0x21; |
|
189 |
reqDetails.iRequest = 0xFF; |
|
190 |
reqDetails.iValue = 0x0000; |
|
191 |
reqDetails.iIndex = 0x0000; |
|
192 |
reqDetails.iFlags = 0x04; // Short transfer OK |
|
193 |
||
194 |
iInterface.Ep0Transfer(reqDetails, KNullDesC8, (TDes8 &) KNullDesC8, iStatus); |
|
195 |
User::WaitForRequest(iStatus); |
|
196 |
__BOTPRINT1(_L("BOT RESET[%d]"), iStatus.Int()); |
|
197 |
||
198 |
if (iStatus.Int() != KErrNone) |
|
199 |
{ |
|
200 |
return KErrGeneral; |
|
201 |
} |
|
202 |
||
203 |
return KErrNone; |
|
204 |
} |
|
205 |
||
206 |
void CBulkOnlyTransport::DoResetRecovery() |
|
207 |
{ |
|
208 |
__MSFNLOG |
|
209 |
||
210 |
__BOTPRINT(_L("BOT RESET RECOVERY")); |
|
211 |
#ifdef MASSSTORAGE_PUBLISHER |
|
212 |
TMsPublisher publisher(TMsPublisher::KBotResetProperty); |
|
213 |
#endif |
|
214 |
Reset(); |
|
215 |
iBulkPipeIn.ClearRemoteStall(); |
|
216 |
iBulkPipeOut.ClearRemoteStall(); |
|
217 |
} |
|
218 |
||
219 |
||
220 |
void CBulkOnlyTransport::SendCbwL(const MClientCommandServiceReq* aReq, |
|
221 |
TBotCbw::TCbwDirection aDirection, |
|
222 |
TUint32 aTransferLength) |
|
223 |
{ |
|
224 |
__MSFNLOG |
|
225 |
__BOTPRINT1(_L("Cbw Tag=0x%x"), iCbwTag); |
|
226 |
||
227 |
iCbw.SetTag(iCbwTag++); |
|
228 |
iCbw.SetDataTransferLength(aTransferLength); |
|
229 |
iCbw.SetDataTransferDirection(aDirection); |
|
230 |
iCbw.SetLun(iLun); |
|
231 |
||
232 |
TPtr8 buf = iBulkOutCbwTd.WritableBuffer(); |
|
233 |
iCbw.EncodeL(buf, aReq); |
|
234 |
||
235 |
iBulkOutCbwTd.SaveData(buf.Length()); |
|
236 |
iBulkPipeOut.Transfer(iBulkOutCbwTd, iStatus); |
|
237 |
User::WaitForRequest(iStatus); |
|
238 |
||
239 |
TInt r = iStatus.Int(); |
|
240 |
if (r != KErrNone) |
|
241 |
{ |
|
242 |
if (r == KErrUsbStalled) |
|
243 |
{ |
|
244 |
__BOTPRINT(_L("Cbw: BulkOut stalled")); |
|
245 |
DoResetRecovery(); |
|
246 |
} |
|
247 |
__BOTPRINT1(_L("Usb transfer error %d"),r); |
|
248 |
User::Leave(KErrGeneral); |
|
249 |
} |
|
250 |
} |
|
251 |
||
252 |
||
253 |
void CBulkOnlyTransport::ReceiveCswL() |
|
254 |
{ |
|
255 |
__MSFNLOG |
|
256 |
iBulkInCswTd.SaveData(KCswPacketSize); |
|
257 |
iBulkPipeIn.Transfer(iBulkInCswTd, iStatus); |
|
258 |
User::WaitForRequest(iStatus); |
|
259 |
||
260 |
TInt r = iStatus.Int(); |
|
261 |
if (r != KErrNone) |
|
262 |
{ |
|
263 |
if (r == KErrUsbStalled) |
|
264 |
{ |
|
265 |
__BOTPRINT(_L("Csw: Clearing BulkIn stall")); |
|
266 |
iBulkPipeIn.ClearRemoteStall(); |
|
267 |
iBulkInCswTd.SaveData(KCswPacketSize); |
|
268 |
iBulkPipeIn.Transfer(iBulkInCswTd, iStatus); |
|
269 |
User::WaitForRequest(iStatus); |
|
270 |
#ifdef MASSSTORAGE_PUBLISHER |
|
271 |
TMsPublisher publisher(TMsPublisher::KStallProperty); |
|
272 |
#endif |
|
273 |
r = iStatus.Int(); |
|
274 |
if (r == KErrUsbStalled) |
|
275 |
{ |
|
276 |
__BOTPRINT(_L("Csw: BulkIn stalled")); |
|
277 |
DoResetRecovery(); |
|
278 |
} |
|
279 |
} |
|
280 |
// Handle other usb error and retry failures |
|
281 |
if (r != KErrNone) |
|
282 |
{ |
|
283 |
__BOTPRINT1(_L("Usb transfer error %d"), r); |
|
284 |
User::Leave(KErrGeneral); |
|
285 |
} |
|
286 |
} |
|
287 |
||
288 |
TPtrC8 data = iBulkInCswTd.Buffer(); |
|
289 |
r = iCsw.Decode(data); |
|
290 |
if (r != KErrNone) |
|
291 |
{ |
|
292 |
__BOTPRINT(_L("Csw: Invalid")); |
|
293 |
DoResetRecovery(); |
|
294 |
User::Leave(KErrGeneral); |
|
295 |
} |
|
296 |
} |
|
297 |
||
298 |
||
299 |
TInt CBulkOnlyTransport::SendControlCmdL(const MClientCommandServiceReq* aCommand) |
|
300 |
{ |
|
301 |
__MSFNLOG |
|
302 |
SendCbwL(aCommand, TBotCbw::EDataOut, 0); |
|
303 |
ReceiveCswL(); |
|
304 |
return ProcessZeroTransferL(); |
|
305 |
} |
|
306 |
||
307 |
||
308 |
TInt CBulkOnlyTransport::SendControlCmdL(const MClientCommandServiceReq* aCommand, |
|
309 |
MClientCommandServiceResp* aResp) |
|
310 |
{ |
|
311 |
__MSFNLOG |
|
312 |
||
313 |
SendCbwL(aCommand, TBotCbw::EDataIn, aResp->DataLength()); |
|
314 |
||
315 |
if (aResp->DataLength() > KResponsePacketSize) |
|
316 |
{ |
|
317 |
__BOTPRINT(_L("Control command response length not supported")); |
|
318 |
User::Leave(KErrGeneral); |
|
319 |
} |
|
320 |
||
321 |
iBulkDataTd.SaveData(KResponsePacketSize); |
|
322 |
iBulkPipeIn.Transfer(iBulkDataTd, iStatus); |
|
323 |
User::WaitForRequest(iStatus); |
|
324 |
TInt r = iStatus.Int(); |
|
325 |
if (r != KErrNone) |
|
326 |
{ |
|
327 |
if (r != KErrUsbStalled) |
|
328 |
{ |
|
329 |
__BOTPRINT1(_L("Usb transfer error %d"),r); |
|
330 |
User::Leave(KErrGeneral); |
|
331 |
} |
|
332 |
__BOTPRINT(_L("SendControlCmdL ClearRemoteStall")); |
|
333 |
iBulkPipeIn.ClearRemoteStall(); |
|
334 |
ReceiveCswL(); |
|
335 |
return KErrCommandStalled; |
|
336 |
} |
|
337 |
TPtrC8 data = iBulkDataTd.Buffer(); |
|
338 |
||
339 |
ReceiveCswL(); |
|
340 |
||
341 |
TUint32 dataReceived = 0; |
|
342 |
r = ProcessInTransferL(dataReceived); |
|
343 |
if (!r) |
|
344 |
{ |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
345 |
TRAP(r, aResp->DecodeL(data)); |
0 | 346 |
if (dataReceived == 0) |
347 |
{ |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
348 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
349 |
// Some devices are found not to support DataResidue and return zero |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
350 |
// bytes received. This state is NOT treated as an error condition |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
351 |
// and we assume that all bytes are valid. For SCSI command set |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
352 |
// applicable to Mass Storage a device must always return data so |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
353 |
// the zero byte condition is not possible with compliant devices. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
354 |
// |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
355 |
// List of known non-compliant devices: |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
356 |
// 1 Transcend JetFlashV30 VendorID=JetFlash ProductID=TS#GJFV30 |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
357 |
// (# is device size in G) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
358 |
|
0 | 359 |
__BOTPRINT1(_L("Warning: No data received"), dataReceived); |
360 |
} |
|
361 |
} |
|
362 |
return r; |
|
363 |
} |
|
364 |
||
365 |
||
366 |
TInt CBulkOnlyTransport::SendDataRxCmdL(const MClientCommandServiceReq* aCommand, |
|
367 |
TDes8& aCopyBuf, |
|
368 |
TInt& aLen) |
|
369 |
{ |
|
370 |
__MSFNLOG |
|
371 |
||
372 |
TInt r = KErrNone; |
|
373 |
SendCbwL(aCommand, TBotCbw::EDataIn, aLen); |
|
374 |
||
375 |
// store initial length as data is appended to the buffer |
|
376 |
TInt startPos = aCopyBuf.Length(); |
|
377 |
||
378 |
TInt len = aLen; |
|
379 |
||
380 |
while (len) |
|
381 |
{ |
|
382 |
if(len > KResponsePacketSize) |
|
383 |
iBulkDataTd.SaveData(KResponsePacketSize); |
|
384 |
else |
|
385 |
iBulkDataTd.SaveData(len); |
|
386 |
iBulkPipeIn.Transfer(iBulkDataTd, iStatus); |
|
387 |
User::WaitForRequest(iStatus); |
|
388 |
||
389 |
r = iStatus.Int(); |
|
390 |
if (r != KErrNone) |
|
391 |
{ |
|
392 |
if (r == KErrUsbStalled) |
|
393 |
{ |
|
394 |
__BOTPRINT(_L("SendDataRxCmdL ClearRemoteStall")); |
|
395 |
iBulkPipeIn.ClearRemoteStall(); |
|
396 |
#ifdef MASSSTORAGE_PUBLISHER |
|
397 |
TMsPublisher publisher(TMsPublisher::KStallProperty); |
|
398 |
#endif |
|
399 |
break; |
|
400 |
} |
|
401 |
DoResetRecovery(); |
|
402 |
__BOTPRINT1(_L("Usb transfer error %d"),r); |
|
403 |
User::Leave(KErrGeneral); |
|
404 |
} |
|
405 |
||
406 |
TPtrC8 data = iBulkDataTd.Buffer(); |
|
407 |
aCopyBuf.Append(data.Ptr(), data.Length()); |
|
408 |
if(len > KResponsePacketSize) |
|
409 |
len -= KResponsePacketSize; |
|
410 |
else |
|
411 |
len = 0; |
|
412 |
} |
|
413 |
||
414 |
ReceiveCswL(); |
|
415 |
TUint32 lenReceived = 0; |
|
416 |
||
417 |
r = ProcessInTransferL(lenReceived); |
|
418 |
aLen = lenReceived; |
|
419 |
aCopyBuf.SetLength(startPos + lenReceived); |
|
420 |
||
421 |
return r; |
|
422 |
} |
|
423 |
||
424 |
TInt CBulkOnlyTransport::SendDataTxCmdL(const MClientCommandServiceReq* aCommand, |
|
425 |
TDesC8& aData, |
|
426 |
TUint aPos, |
|
427 |
TInt& aLen) |
|
428 |
{ |
|
429 |
__MSFNLOG |
|
430 |
TInt r = KErrNone; |
|
431 |
||
432 |
SendCbwL(aCommand, TBotCbw::EDataOut, aLen); |
|
433 |
||
434 |
TInt len = aLen; |
|
435 |
TInt length = 0; |
|
436 |
iBulkDataTd.SetZlpStatus(RUsbTransferDescriptor::ESuppressZlp); |
|
437 |
while (len) |
|
438 |
{ |
|
439 |
TPtr8 senddata = iBulkDataTd.WritableBuffer(); |
|
440 |
senddata.Append(aData.Ptr() + length + aPos, len > KResponsePacketSize? KResponsePacketSize : len); |
|
441 |
||
442 |
iBulkDataTd.SaveData(senddata.Length()); |
|
443 |
iBulkPipeOut.Transfer(iBulkDataTd, iStatus); |
|
444 |
User::WaitForRequest(iStatus); |
|
445 |
||
446 |
if (iStatus.Int() != KErrNone) |
|
447 |
{ |
|
448 |
if (iStatus.Int() == KErrUsbStalled) |
|
449 |
{ |
|
450 |
__BOTPRINT(_L("SendDataTxCmdL ClearRemoteStall")); |
|
451 |
iBulkPipeOut.ClearRemoteStall(); |
|
452 |
#ifdef MASSSTORAGE_PUBLISHER |
|
453 |
TMsPublisher publisher(TMsPublisher::KStallProperty); |
|
454 |
#endif |
|
455 |
break; |
|
456 |
} |
|
457 |
DoResetRecovery(); |
|
458 |
__BOTPRINT1(_L("Usb transfer error %d"), r); |
|
459 |
User::Leave(KErrGeneral); |
|
460 |
} |
|
461 |
||
462 |
if(len > KResponsePacketSize) |
|
463 |
{ |
|
464 |
len -= KResponsePacketSize; |
|
465 |
length += KResponsePacketSize; |
|
466 |
} |
|
467 |
else |
|
468 |
{ |
|
469 |
length += len; |
|
470 |
len = 0; |
|
471 |
} |
|
472 |
} |
|
473 |
||
474 |
ReceiveCswL(); |
|
475 |
||
476 |
TUint32 lenSent = 0; |
|
477 |
r = ProcessOutTransferL(lenSent); |
|
478 |
aLen = lenSent; |
|
479 |
||
480 |
return r; |
|
481 |
} |
|
482 |
||
483 |
||
484 |
TInt CBulkOnlyTransport::ProcessZeroTransferL() |
|
485 |
{ |
|
486 |
__MSFNLOG |
|
487 |
// process 13 cases |
|
488 |
||
489 |
__ASSERT_DEBUG(iCbw.iDirection == TBotCbw::EDataOut, User::Invariant()); |
|
490 |
__ASSERT_DEBUG(iCbw.iDataTransferLength == 0, User::Invariant()); |
|
491 |
||
492 |
// Hn - Host expects no data transfers |
|
493 |
if (!iCsw.IsValidCsw(iCbw.iTag)) |
|
494 |
{ |
|
495 |
__BOTPRINT(_L("BOT CSW Invalid")); |
|
496 |
DoResetRecovery(); |
|
497 |
User::Leave(KErrGeneral); |
|
498 |
} |
|
499 |
if (!iCsw.IsMeaningfulCsw(iCbw.iDataTransferLength)) |
|
500 |
{ |
|
501 |
__BOTPRINT(_L("BOT CSW not meaningful")); |
|
502 |
DoResetRecovery(); |
|
503 |
User::Leave(KErrGeneral); |
|
504 |
} |
|
505 |
||
506 |
if (iCsw.iStatus == TBotCsw::EPhaseError) |
|
507 |
{ |
|
508 |
// Case (2) or (3) |
|
509 |
__BOTPRINT(_L("BOT Phase Error")); |
|
510 |
// Reset Recovery |
|
511 |
DoResetRecovery(); |
|
512 |
User::Leave(KErrGeneral); |
|
513 |
} |
|
514 |
||
515 |
if (iCsw.iDataResidue != 0) |
|
516 |
{ |
|
517 |
// should not happen |
|
518 |
__BOTPRINT(_L("BOT Residue is invalid!")); |
|
519 |
// Reset Recovery |
|
520 |
DoResetRecovery(); |
|
521 |
User::Leave(KErrGeneral); |
|
522 |
} |
|
523 |
||
524 |
// all ok if here |
|
525 |
return (iCsw.iStatus == TBotCsw::ECommandPassed) ? KErrNone : KErrCommandFailed; |
|
526 |
} |
|
527 |
||
528 |
||
529 |
TInt CBulkOnlyTransport::ProcessInTransferL(TUint32& aDataReceived) |
|
530 |
{ |
|
531 |
__MSFNLOG |
|
532 |
aDataReceived = 0; |
|
533 |
// process 13 cases |
|
534 |
||
535 |
__ASSERT_DEBUG(iCbw.iDirection == TBotCbw::EDataIn, User::Invariant()); |
|
536 |
||
537 |
// Hi - Host expects to receive data from the device |
|
538 |
if (!iCsw.IsValidCsw(iCbw.iTag)) |
|
539 |
{ |
|
540 |
__BOTPRINT(_L("BOT CSW Invalid")); |
|
541 |
DoResetRecovery(); |
|
542 |
User::Leave(KErrGeneral); |
|
543 |
} |
|
544 |
if (!iCsw.IsMeaningfulCsw(iCbw.iDataTransferLength)) |
|
545 |
{ |
|
546 |
__BOTPRINT(_L("BOT CSW not meaningful")); |
|
547 |
DoResetRecovery(); |
|
548 |
User::Leave(KErrGeneral); |
|
549 |
} |
|
550 |
||
551 |
||
552 |
if (iCsw.iStatus == TBotCsw::EPhaseError) |
|
553 |
{ |
|
554 |
__BOTPRINT(_L("BOT Phase Error")); |
|
555 |
// Case (7) or (8) |
|
556 |
// Reset Recovery |
|
557 |
DoResetRecovery(); |
|
558 |
User::Leave(KErrGeneral); |
|
559 |
} |
|
560 |
||
561 |
// all ok if here |
|
562 |
// Case (4), (5) or (6) |
|
563 |
aDataReceived = iCbw.iDataTransferLength - iCsw.iDataResidue; |
|
564 |
return (iCsw.iStatus == TBotCsw::ECommandPassed) ? KErrNone : KErrCommandFailed; |
|
565 |
} |
|
566 |
||
567 |
||
568 |
TInt CBulkOnlyTransport::ProcessOutTransferL(TUint32& aDataReceived) |
|
569 |
{ |
|
570 |
__MSFNLOG |
|
571 |
aDataReceived = 0; |
|
572 |
// process 13 cases |
|
573 |
||
574 |
__ASSERT_DEBUG(iCbw.iDirection == TBotCbw::EDataOut, User::Invariant()); |
|
575 |
||
576 |
// Ho - Host expects to send data to the device |
|
577 |
if (!iCsw.IsValidCsw(iCbw.iTag)) |
|
578 |
{ |
|
579 |
__BOTPRINT(_L("BOT CSW Invalid")); |
|
580 |
DoResetRecovery(); |
|
581 |
User::Leave(KErrGeneral); |
|
582 |
} |
|
583 |
if (!iCsw.IsMeaningfulCsw(iCbw.iDataTransferLength)) |
|
584 |
{ |
|
585 |
__BOTPRINT(_L("BOT CSW not meaningful")); |
|
586 |
DoResetRecovery(); |
|
587 |
User::Leave(KErrGeneral); |
|
588 |
} |
|
589 |
||
590 |
if (iCsw.iStatus == TBotCsw::EPhaseError) |
|
591 |
{ |
|
592 |
__BOTPRINT(_L("BOT Phase Error")); |
|
593 |
// Case (10) or (13) |
|
594 |
// Reset Recovery |
|
595 |
DoResetRecovery(); |
|
596 |
User::Leave(KErrGeneral); |
|
597 |
} |
|
598 |
||
599 |
// all ok if here |
|
600 |
// Case (9), (11) or (12) |
|
601 |
aDataReceived = iCbw.iDataTransferLength - iCsw.iDataResidue; |
|
602 |
return (iCsw.iStatus == TBotCsw::ECommandPassed) ? KErrNone : KErrCommandFailed; |
|
603 |
} |
|
604 |
||
605 |
||
606 |
void CBulkOnlyTransport::SetLun(TLun aLun) |
|
607 |
{ |
|
608 |
__MSFNLOG |
|
609 |
iLun = aLun; |
|
610 |
__BOTPRINT1(_L("CBulkOnlyTransport::SetLun(%d)"), aLun) |
|
611 |
} |
|
612 |
||
613 |
||
614 |
/** |
|
615 |
Encode CBW into the supplied buffer. The command is also encoded using the |
|
616 |
supplied encoding method of MClientCommandServiceReq. |
|
617 |
||
618 |
@param aBuffer The buffer to copy the encoded stream in to |
|
619 |
@param aCommand The command to be encoded into the Command Block field |
|
620 |
*/ |
|
621 |
void TBotCbw::EncodeL(TPtr8 &aBuffer, const MClientCommandServiceReq* aCommand) const |
|
622 |
{ |
|
623 |
__MSFNSLOG |
|
624 |
aBuffer.SetLength(KCbwLength); |
|
625 |
||
626 |
TPtr8 commandBlock = aBuffer.MidTPtr(TBotCbw::KCbwCbOffset); |
|
627 |
||
628 |
aBuffer.FillZ(); |
|
629 |
||
630 |
TInt cbLength = aCommand->EncodeRequestL(commandBlock); |
|
631 |
||
632 |
TUint8* ptr = (TUint8 *) aBuffer.Ptr(); |
|
633 |
LittleEndian::Put32(&ptr[KCbwSignatureOffset], 0x43425355); |
|
634 |
LittleEndian::Put32(&ptr[KCbwTagOffset], iTag); |
|
635 |
LittleEndian::Put32(&ptr[KCbwDataTransferLengthOffset], iDataTransferLength); |
|
636 |
aBuffer[KCbwFlagOffset] = (iDirection == EDataOut) ? 0x00 : 0x80; |
|
637 |
aBuffer[KCbwLunOffset] = iLun; |
|
638 |
aBuffer[KCbwCbLengthOffset] = cbLength; |
|
639 |
__BOTPRINT1(_L("BOT TBotCbw::Encode Lun=%d"), iLun); |
|
640 |
} |
|
641 |
||
642 |
||
643 |
/** |
|
644 |
Decode stream into TBotCsw. |
|
645 |
||
646 |
@param aPtr A buffer containing CSW stream |
|
647 |
*/ |
|
648 |
TInt TBotCsw::Decode(const TDesC8& aPtr) |
|
649 |
{ |
|
650 |
__MSFNLOG |
|
651 |
if (aPtr.Length() != KCswLength) |
|
652 |
{ |
|
653 |
__BOTPRINT1(_L("Invalid CSW length %d"), aPtr.Length()); |
|
654 |
return KErrGeneral; |
|
655 |
} |
|
656 |
||
657 |
iSignature = LittleEndian::Get32(&aPtr[KCswSignatureOffset]); |
|
658 |
iTag = LittleEndian::Get32(&aPtr[KCswTagOffset]); |
|
659 |
iDataResidue = LittleEndian::Get32(&aPtr[KCswDataResidueOffset]); |
|
660 |
||
661 |
TInt status = aPtr[KCswStatusOffset]; |
|
662 |
iStatus = static_cast<TCswStatus>(status); |
|
663 |
__BOTPRINT1(_L("BOT CSW Status = %d"), iStatus); |
|
664 |
return KErrNone; |
|
665 |
} |
|
666 |
||
667 |
||
668 |
/** |
|
669 |
Checks that CSW contents are valid, USB Mass Storage Class Bulk-Only |
|
670 |
Transport 6.3. |
|
671 |
||
672 |
@param aTag The tag value received from the device |
|
673 |
||
674 |
@return TBool Return ETrue if valid else EFalse |
|
675 |
*/ |
|
676 |
TBool TBotCsw::IsValidCsw(TUint32 aTag) const |
|
677 |
{ |
|
678 |
__MSFNSLOG |
|
679 |
if (iSignature != 0x53425355) |
|
680 |
{ |
|
681 |
return EFalse; |
|
682 |
} |
|
683 |
if (iTag != aTag) |
|
684 |
{ |
|
685 |
return EFalse; |
|
686 |
} |
|
687 |
return ETrue; |
|
688 |
} |
|
689 |
||
690 |
||
691 |
/** |
|
692 |
Checks that CSW contents are meaningful, USB Mass Storage Class Bulk-Only |
|
693 |
Transport 6.3. |
|
694 |
||
695 |
@param aTransferLength Number of bytes transferred |
|
696 |
||
697 |
@return TBool Return ETrue if meaningful else EFalse |
|
698 |
*/ |
|
699 |
TBool TBotCsw::IsMeaningfulCsw(TUint32 aTransferLength) const |
|
700 |
{ |
|
701 |
__MSFNSLOG |
|
702 |
if (iStatus != EPhaseError) |
|
703 |
{ |
|
704 |
if (iDataResidue > aTransferLength) |
|
705 |
{ |
|
706 |
return EFalse; |
|
707 |
} |
|
708 |
} |
|
709 |
return ETrue; |
|
710 |
} |
|
711 |
||
712 |
#ifdef MASSSTORAGE_PUBLISHER |
|
713 |
TMsPublisher::TMsPublisher(TPropertyKeys aKey) |
|
714 |
{ |
|
715 |
RProperty prop; |
|
716 |
||
717 |
const TUid KUidHostMassStorageCategory = {KMyUid}; |
|
718 |
||
719 |
TInt ret = prop.Attach(KUidHostMassStorageCategory, aKey); |
|
720 |
__BOTPRINT2(_L("Property Key[%d] attach ret=%d"), aKey, ret); |
|
721 |
if (ret == KErrNone) |
|
722 |
{ |
|
723 |
TInt flag; |
|
724 |
ret = prop.Get(KUidHostMassStorageCategory, aKey, flag); |
|
725 |
if (ret == KErrNone) |
|
726 |
{ |
|
727 |
flag++; |
|
728 |
ret = prop.Set(KUidHostMassStorageCategory, aKey, flag); |
|
729 |
} |
|
730 |
__BOTPRINT3(_L("Property Set[%d] ret=%d Counter=%d"), aKey, ret, flag); |
|
731 |
prop.Close(); |
|
732 |
} |
|
733 |
} |
|
734 |
||
735 |
#endif |
|
736 |