author | hgs |
Tue, 02 Nov 2010 15:29:23 +0000 | |
changeset 300 | 1d28c8722707 |
parent 33 | 0173bcd7697c |
permissions | -rw-r--r-- |
300 | 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> |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
31
diff
changeset
|
22 |
|
300 | 23 |
#include "OstTraceDefinitions.h" |
24 |
#ifdef OST_TRACE_COMPILER_IN_USE |
|
25 |
#include "tsbcclientinterfaceTraces.h" |
|
26 |
#endif |
|
27 |
||
0 | 28 |
#include "msctypes.h" |
29 |
||
30 |
#include "mtransport.h" |
|
31 |
#include "mprotocol.h" |
|
32 |
#include "tscsiclientreq.h" |
|
33 |
||
34 |
#include "tblocktransfer.h" |
|
35 |
#include "mscutils.h" |
|
36 |
#include "usbmshostpanic.h" |
|
37 |
#include "tscsiblockcmds.h" |
|
38 |
#include "tsbcclientinterface.h" |
|
39 |
||
300 | 40 |
|
0 | 41 |
/** |
42 |
Constructor. |
|
43 |
||
44 |
@param aTransport The Transport interface to be used |
|
45 |
*/ |
|
46 |
TSbcClientInterface::TSbcClientInterface(MTransport& aTransport) |
|
47 |
: iTransport(aTransport) |
|
48 |
{ |
|
49 |
} |
|
50 |
||
51 |
||
52 |
TSbcClientInterface::~TSbcClientInterface() |
|
53 |
{ |
|
54 |
} |
|
55 |
||
56 |
||
57 |
/** |
|
58 |
Constructor to create and send SCSI MODE SENSE (6) request to obtain the |
|
59 |
medium's Write Protect status. The function leaves if the device response is not |
|
60 |
compliant with the protocol standard. |
|
61 |
||
62 |
@param aPageCode The SCSI PAGE CODE value |
|
63 |
@param aWriteProtected The SCSI WP value |
|
64 |
||
65 |
@return TInt KErrNone if successful, KErrCommandFailed to indicate a |
|
66 |
device status error, KErrCommandStalled to indicate device stall |
|
67 |
*/ |
|
68 |
TInt TSbcClientInterface::ModeSense6L(TUint aPageCode, TBool& aWriteProtected) |
|
69 |
{ |
|
70 |
TScsiClientModeSense6Req modeSense6Req(TScsiClientModeSense6Req::ECurrentValues, |
|
71 |
aPageCode); |
|
72 |
TScsiClientModeSense6Resp modeSense6Resp; |
|
73 |
TInt err = iTransport.SendControlCmdL(&modeSense6Req, &modeSense6Resp); |
|
74 |
if (!err) |
|
75 |
{ |
|
300 | 76 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_SCSI, TSBCCLIENTINTERFACE_10, |
77 |
"SCSI MODE SENSE (6) INFO WrProtect=%d", modeSense6Resp.iWriteProtected); |
|
0 | 78 |
aWriteProtected = modeSense6Resp.iWriteProtected; |
79 |
} |
|
80 |
else |
|
81 |
{ |
|
82 |
aWriteProtected = EFalse; |
|
83 |
} |
|
300 | 84 |
return err; |
0 | 85 |
} |
86 |
||
87 |
||
88 |
/** |
|
89 |
Create and send SCSI MODE SENSE (10) request to obtain the mediums Write Protect |
|
90 |
status. The function leaves if the device response is not compliant with the |
|
91 |
protocol standard. |
|
92 |
||
93 |
@param aPageCode The SCSI PAGE CODE value |
|
94 |
@param aWriteProtected The SCSI WP value |
|
95 |
||
96 |
@return TInt KErrNone if successful, KErrCommandFailed to indicate a |
|
97 |
device status error, KErrCommandStalled to indicate a device stall |
|
98 |
*/ |
|
99 |
TInt TSbcClientInterface::ModeSense10L(TUint aPageCode, TBool& aWriteProtected) |
|
100 |
{ |
|
101 |
TScsiClientModeSense10Req modeSense10Req(TScsiClientModeSense10Req::ECurrentValues, |
|
102 |
aPageCode); |
|
103 |
TScsiClientModeSense10Resp modeSense10Resp; |
|
104 |
TInt err = iTransport.SendControlCmdL(&modeSense10Req, &modeSense10Resp); |
|
105 |
||
106 |
if (!err) |
|
107 |
{ |
|
300 | 108 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_SCSI, TSBCCLIENTINTERFACE_11, |
109 |
"SCSI MODE SENSE (10) INFO WrProtect=%d", modeSense10Resp.iWriteProtected); |
|
0 | 110 |
aWriteProtected = modeSense10Resp.iWriteProtected; |
111 |
} |
|
112 |
else |
|
113 |
{ |
|
114 |
aWriteProtected = EFalse; |
|
115 |
} |
|
300 | 116 |
return err; |
0 | 117 |
} |
118 |
||
119 |
||
120 |
/** |
|
121 |
Constructor to create SCSI MODE SENSE (10) request. |
|
122 |
||
123 |
@param aPageControl The SCSI PAGE CODE value |
|
124 |
@param aPageCode The SCSI WP value |
|
125 |
@param aSubPageCode The SCSI SUB PAGE CODE value |
|
126 |
*/ |
|
127 |
TScsiClientModeSense10Req::TScsiClientModeSense10Req(TPageControl aPageControl, |
|
128 |
TUint aPageCode, |
|
129 |
TUint aSubPageCode) |
|
130 |
: |
|
131 |
TScsiClientReq(EModeSense10), |
|
132 |
iPageControl(aPageControl), |
|
133 |
iPageCode(aPageCode), |
|
134 |
iSubPageCode(aSubPageCode), |
|
135 |
iAllocationLength(KResponseLength) |
|
136 |
{ |
|
137 |
} |
|
138 |
||
139 |
||
140 |
TInt TScsiClientModeSense10Req::EncodeRequestL(TDes8& aBuffer) const |
|
141 |
{ |
|
300 | 142 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_SCSI, TSBCCLIENTINTERFACE_12, |
143 |
"<-- SCSI MODE SENSE (10)"); |
|
0 | 144 |
TInt length = TScsiClientReq::EncodeRequestL(aBuffer); |
145 |
||
146 |
// PC |
|
147 |
aBuffer[2] = iPageCode; |
|
148 |
aBuffer[2] |= iPageControl << 6; |
|
149 |
aBuffer[3] = iSubPageCode; |
|
150 |
||
151 |
BigEndian::Put16(&aBuffer[7], iAllocationLength); |
|
152 |
return length; |
|
153 |
} |
|
154 |
||
155 |
/** |
|
156 |
Create READ (10) request and send to the transport layer. This performs a |
|
157 |
logical block read of the device server. The received data is appended into the |
|
158 |
copy buffer. The function leaves if the device response is not compliant with |
|
159 |
the protocol standard. |
|
160 |
Note that TBlockTransfer must be initialised beforehand. |
|
161 |
||
162 |
@param aLba The Logical Block address to read from |
|
163 |
@param aBuffer The buffer to copy data to |
|
164 |
@param aLen The number of bytes to be read (IN) and returns the number of bytes |
|
165 |
actually read (OUT) |
|
166 |
||
167 |
@return TInt KErrNone if successful otherwise KErrCommandFailed to indicate a |
|
168 |
device status error or KErrArgument to indicate that aLen is too large for the |
|
169 |
protocol. |
|
170 |
*/ |
|
171 |
TInt TSbcClientInterface::Read10L(TLba aLba, TDes8& aBuffer, TInt& aLen) |
|
172 |
{ |
|
300 | 173 |
__ASSERT_DEBUG(iBlockTransfer.BlockLength(), User::Panic(KUsbMsHostPanicCat, EBlockLengthNotSet)); |
0 | 174 |
__ASSERT_DEBUG(aLen % iBlockTransfer.BlockLength() == 0, User::Panic(KUsbMsHostPanicCat, EBlockDevice)); |
175 |
||
176 |
TScsiClientRead10Req read10Req; |
|
177 |
||
178 |
read10Req.iLogicalBlockAddress = aLba; |
|
179 |
||
180 |
TInt blockTransferLength = aLen / iBlockTransfer.BlockLength(); |
|
181 |
if (blockTransferLength > static_cast<TInt>(KMaxTUint16)) |
|
182 |
{ |
|
183 |
User::Leave(KErrArgument); |
|
184 |
} |
|
185 |
read10Req.iBlockTransferLength = static_cast<TUint16>(blockTransferLength); |
|
186 |
TInt err = iTransport.SendDataRxCmdL(&read10Req, aBuffer, aLen); |
|
300 | 187 |
return err; |
0 | 188 |
} |
189 |
||
190 |
/** |
|
191 |
Create READ CAPACITY (10) request and send to the transport layer. The request |
|
192 |
returns the device servers capacity information. The device server's response |
|
193 |
values are also used here to initialise the TBlockTransfer values. The function |
|
194 |
leaves if the device response is not compliant with the protocol standard. |
|
195 |
||
196 |
@param aLba The Logical Block Address returned by the LU |
|
197 |
@param aBlockSize The Block Size returned by the LU |
|
198 |
||
199 |
@return TInt KErrNone if successful, KErrCommandFailed to indicate a |
|
200 |
device status error, KErrCommandStalled to indicate a device stall |
|
201 |
*/ |
|
202 |
TInt TSbcClientInterface::ReadCapacity10L(TLba& aLba, TUint32& aBlockSize) |
|
203 |
{ |
|
204 |
TScsiClientReadCapacity10Req capacity10Req; |
|
205 |
TScsiClientReadCapacity10Resp capacity10Resp; |
|
206 |
||
207 |
TInt err = iTransport.SendControlCmdL(&capacity10Req, &capacity10Resp); |
|
208 |
if (!err) |
|
209 |
{ |
|
210 |
aLba = capacity10Resp.iLba; |
|
211 |
aBlockSize = capacity10Resp.iBlockSize; |
|
212 |
||
300 | 213 |
OstTraceExt2(TRACE_SHOSTMASSSTORAGE_SCSI, TSBCCLIENTINTERFACE__, |
214 |
"Capacity LBA=0x%08x SIZE=0x%08x", aLba, aBlockSize); |
|
0 | 215 |
|
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
216 |
iBlockTransfer.SetCapacityL(aBlockSize, aLba); |
0 | 217 |
} |
300 | 218 |
return err; |
0 | 219 |
} |
220 |
||
221 |
||
222 |
/** |
|
223 |
Create START STOP UNIT request. The function leaves if the device response is |
|
224 |
not compliant with the protocol standard. |
|
225 |
||
226 |
@param aStart SCSI START value |
|
227 |
||
228 |
@return TInt KErrNone if successful otherwise KErrCommandFailed to indicate a |
|
229 |
device status error |
|
230 |
*/ |
|
231 |
TInt TSbcClientInterface::StartStopUnitL(TBool aStart) |
|
232 |
{ |
|
233 |
TScsiClientStartStopUnitReq startStopUnitReq; |
|
234 |
||
235 |
startStopUnitReq.iImmed = ETrue; |
|
236 |
startStopUnitReq.iLoej = EFalse; |
|
237 |
startStopUnitReq.iStart = aStart; |
|
238 |
||
239 |
TInt err = iTransport.SendControlCmdL(&startStopUnitReq); |
|
240 |
||
300 | 241 |
return err; |
0 | 242 |
} |
243 |
||
244 |
||
245 |
/** |
|
246 |
Create WRITE (10) request and send to the transport layer. This performs a |
|
247 |
logical block write of the device server. Note that TBlockTransfer must be |
|
248 |
initialised beforehand. The function leaves if the device response is not |
|
249 |
compliant with the protocol standard. |
|
250 |
||
251 |
@param aLba Logical Block Address to write the data to |
|
252 |
@param aBuffer Buffer containing the data |
|
253 |
@param aPos Offset into the buffer to the data |
|
254 |
@param aLen The number of bytes to be written (IN) and returns the bytes |
|
255 |
actually transferred (OUT) |
|
256 |
||
257 |
@return TInt KErrNone if successful otherwise KErrCommandFailed to indicate a |
|
258 |
device status error or KErrArgument to indicate that aLen is too large for the |
|
259 |
protocol. |
|
260 |
*/ |
|
261 |
TInt TSbcClientInterface::Write10L(TLba aLba, TDesC8& aBuffer, TUint aPos, TInt& aLen) |
|
262 |
{ |
|
300 | 263 |
__ASSERT_DEBUG(iBlockTransfer.BlockLength(), User::Panic(KUsbMsHostPanicCat, EBlockLengthNotSet)); |
0 | 264 |
__ASSERT_DEBUG(aLen % iBlockTransfer.BlockLength() == 0, User::Panic(KUsbMsHostPanicCat, EBlockDevice)); |
265 |
||
266 |
// check that buffer size is large enough |
|
300 | 267 |
if (aBuffer.Length() < (aPos + aLen)) |
268 |
{ |
|
0 | 269 |
User::Leave(KErrArgument); |
300 | 270 |
} |
0 | 271 |
|
272 |
TScsiClientWrite10Req write10Req; |
|
273 |
write10Req.iLogicalBlockAddress = aLba; |
|
274 |
||
275 |
TInt blockTransferLength = aLen / iBlockTransfer.BlockLength(); |
|
276 |
if (blockTransferLength > static_cast<TInt>(KMaxTUint16)) |
|
277 |
{ |
|
278 |
User::Leave(KErrArgument); |
|
279 |
} |
|
280 |
write10Req.iBlockTransferLength = static_cast<TUint16>(blockTransferLength); |
|
281 |
||
282 |
TInt err = iTransport.SendDataTxCmdL(&write10Req, aBuffer, aPos, aLen); |
|
300 | 283 |
return err; |
0 | 284 |
} |
285 |