297
|
1 |
// Copyright (c) 2009-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 |
#include <e32def.h>
|
|
18 |
#include <e32cmn.h>
|
|
19 |
#include <e32des8.h>
|
|
20 |
#include <e32std.h>
|
|
21 |
|
|
22 |
#include "mstypes.h"
|
|
23 |
#include "msctypes.h"
|
|
24 |
#include "mscutils.h"
|
|
25 |
#include "scsimsctypes.h"
|
|
26 |
|
|
27 |
#include "tscsiserverreq.h"
|
|
28 |
#include "tscsiservercmds.h"
|
|
29 |
#include "debug.h"
|
|
30 |
|
|
31 |
/**
|
|
32 |
Default constructor for TSenseInfo
|
|
33 |
*/
|
|
34 |
TSrvSenseInfo::TSrvSenseInfo()
|
|
35 |
{
|
|
36 |
iSenseCode = ENoSense;
|
|
37 |
iAdditional = 0;
|
297
|
38 |
iQualifier = 0;
|
0
|
39 |
}
|
|
40 |
|
|
41 |
/**
|
|
42 |
Set sense with no additional info.
|
|
43 |
|
|
44 |
@param aSenseCode sense key
|
|
45 |
*/
|
|
46 |
void TSrvSenseInfo::SetSense(TSenseCode aSenseCode)
|
297
|
47 |
{
|
|
48 |
iSenseCode = static_cast<TUint8>(aSenseCode);
|
|
49 |
iAdditional = 0;
|
|
50 |
iQualifier = 0;
|
|
51 |
}
|
0
|
52 |
|
|
53 |
|
|
54 |
/**
|
|
55 |
Set sense with additional info.
|
|
56 |
|
|
57 |
@param aSenseCode sense key
|
|
58 |
@param aAdditional additional sense code (ASC)
|
|
59 |
*/
|
|
60 |
void TSrvSenseInfo::SetSense(TSenseCode aSenseCode,
|
|
61 |
TAdditionalCode aAdditional)
|
|
62 |
|
297
|
63 |
{
|
|
64 |
iSenseCode = static_cast<TUint8>(aSenseCode);
|
|
65 |
iAdditional = static_cast<TUint8>(aAdditional);
|
|
66 |
iQualifier = 0;
|
|
67 |
}
|
0
|
68 |
|
|
69 |
|
|
70 |
/**
|
|
71 |
Set sense with additional info and qualifier.
|
|
72 |
|
|
73 |
@param aSenseCode sense key
|
|
74 |
@param aAdditional additional sense code (ASC)
|
|
75 |
@param aQualifier additional sense code qualifier (ASCQ)
|
|
76 |
*/
|
|
77 |
void TSrvSenseInfo::SetSense(TSenseCode aSenseCode,
|
|
78 |
TAdditionalCode aAdditional,
|
|
79 |
TUint8 aQualifier)
|
297
|
80 |
{
|
|
81 |
iSenseCode = static_cast<TUint8>(aSenseCode);
|
|
82 |
iAdditional = static_cast<TUint8>(aAdditional);
|
|
83 |
iQualifier = aQualifier;
|
|
84 |
}
|
0
|
85 |
|
|
86 |
|
|
87 |
// **** TEST UNIT READY ****
|
|
88 |
// **** REQUEST SENSE ****
|
|
89 |
void TScsiServerRequestSenseResp::Encode(TDes8& aBuffer) const
|
|
90 |
{
|
|
91 |
aBuffer.FillZ(KCommandLength);
|
|
92 |
__PRINT(_L("->PROTOCOL(SCSI) REQUEST SENSE\n"));
|
|
93 |
//additional sense length
|
297
|
94 |
aBuffer[07] = static_cast<TUint8>(KCommandLength - 8);
|
0
|
95 |
|
|
96 |
aBuffer[0] = iResponseCode;
|
297
|
97 |
aBuffer[02] = static_cast<TUint8>(iSensePtr->iSenseCode);
|
|
98 |
aBuffer[12] = iSensePtr->iAdditional;
|
|
99 |
aBuffer[13] = iSensePtr->iQualifier;
|
0
|
100 |
|
|
101 |
//truncate to Allocation Length of the Request
|
|
102 |
TUint length = iAllocationLength < KCommandLength ?
|
|
103 |
iAllocationLength : KCommandLength;
|
|
104 |
aBuffer.SetLength(length);
|
|
105 |
}
|
|
106 |
|
|
107 |
// **** INQUIRY ****
|
|
108 |
void TScsiServerInquiryReq::DecodeL(const TDesC8& aPtr)
|
|
109 |
{
|
297
|
110 |
TScsiServerReq::DecodeL(aPtr);
|
0
|
111 |
iCmdDt = aPtr[1] & 0x2;
|
|
112 |
iEvpd = aPtr[1] & 0x1;
|
|
113 |
iPage = aPtr[2];
|
|
114 |
iAllocationLength = aPtr[4];
|
|
115 |
__PRINT(_L("<-PROTOCOL(SCSI) INQUIRY\n"));
|
|
116 |
}
|
|
117 |
|
|
118 |
|
|
119 |
void TScsiServerInquiryResp::Encode(TDes8& aBuffer) const
|
|
120 |
{
|
|
121 |
__PRINT(_L("->PROTOCOL(SCSI) INQUIRY\n"));
|
|
122 |
|
297
|
123 |
aBuffer.FillZ(KResponseLength);
|
0
|
124 |
|
|
125 |
// MSB: RMB : Removable
|
|
126 |
if (iRemovable)
|
|
127 |
{
|
|
128 |
aBuffer[1] |= 0x80;
|
|
129 |
}
|
|
130 |
|
|
131 |
// AERC, TrmTsk, NormACA, Response Data Format
|
|
132 |
aBuffer[3] |= (iResponseDataFormat & 0x0F);
|
|
133 |
|
|
134 |
// Additional Length
|
297
|
135 |
aBuffer[4] = 0x1F;
|
0
|
136 |
|
|
137 |
// Vendor ID (Vendor Specific/Logged by T10)
|
297
|
138 |
TPtr8 vendorId(&aBuffer[8], 8, 8);
|
|
139 |
vendorId.Fill(' ', 8);
|
|
140 |
vendorId.Copy(iConfig.iVendorId);
|
0
|
141 |
|
|
142 |
// Product ID (Vendor Specific)
|
|
143 |
TPtr8 productId(&aBuffer[16], 16, 16);
|
|
144 |
productId.Fill(' ', 16);
|
|
145 |
productId.Copy(iConfig.iProductId);
|
|
146 |
|
|
147 |
// Product Revision Level (Vendor Specific)
|
|
148 |
TPtr8 productRev(&aBuffer[32], 4, 4);
|
|
149 |
productRev.Fill(' ', 4);
|
|
150 |
productRev.Copy(iConfig.iProductRev);
|
|
151 |
|
|
152 |
// Truncate to Allocation Length of the Request
|
|
153 |
TUint length = iAllocationLength < KResponseLength ?
|
|
154 |
iAllocationLength : KResponseLength;
|
|
155 |
aBuffer.SetLength(length);
|
|
156 |
}
|
|
157 |
|
|
158 |
|
297
|
159 |
// **** MODE SENSE (6) ****
|
0
|
160 |
void TScsiServerModeSense6Req::DecodeL(const TDesC8& aPtr)
|
|
161 |
{
|
297
|
162 |
TScsiServerReq::DecodeL(aPtr);
|
0
|
163 |
iPageCode = aPtr[2] & 0x3F;
|
|
164 |
iPageControl = static_cast<TPageControl>(aPtr[2] >> 6);
|
|
165 |
iAllocationLength = aPtr[4];
|
|
166 |
__PRINT(_L("<-PROTOCOL(SCSI) MODE SENSE (6)\n"));
|
|
167 |
}
|
|
168 |
|
|
169 |
|
|
170 |
void TScsiServerModeSense6Resp::Encode(TDes8& aBuffer) const
|
|
171 |
{
|
|
172 |
__PRINT(_L("->PROTOCOL(SCSI) MODE SENSE (6)\n"));
|
|
173 |
// reserve 4 bytes for Length, Media type, Device-specific parameter and
|
|
174 |
// Block descriptor length
|
|
175 |
aBuffer.FillZ(KCommandLength);
|
|
176 |
|
|
177 |
// Mode Parameter List
|
|
178 |
// SPC-3 7.4.2
|
|
179 |
// - Mode Parameter Header
|
|
180 |
// - Block Descriptor(s)
|
|
181 |
// - Mode Page(s)
|
|
182 |
|
|
183 |
// Mode Parameter Header
|
|
184 |
// SPC-3 7.4.3
|
|
185 |
// [0] Mode Data Length
|
|
186 |
// [1] Medium Type
|
|
187 |
// [2] Device-Specific Paramater
|
|
188 |
// [3] Block Descriptor Length
|
|
189 |
|
|
190 |
// [0] Mode Date Length
|
|
191 |
// Sending only Mode parameter header
|
|
192 |
aBuffer[0] = 3;
|
|
193 |
|
|
194 |
// [1] Medium Type
|
|
195 |
// 0x00 for SBC
|
|
196 |
|
|
197 |
// [2] Device specific parameter
|
|
198 |
// SBC-3 6.3.1
|
|
199 |
// set SWP bit at the Device Specific parameters
|
|
200 |
if (iWp)
|
|
201 |
{
|
|
202 |
aBuffer[2] |= 0x80;
|
|
203 |
}
|
|
204 |
|
|
205 |
// [3] Block Descriptor Length
|
|
206 |
// 0x00 for no descriptors
|
|
207 |
|
|
208 |
// No Block Descriptors
|
|
209 |
|
|
210 |
// No Mode Pages
|
|
211 |
|
|
212 |
// Truncate to Allocation Length of the Request
|
|
213 |
TUint length = iAllocationLength < KCommandLength ?
|
|
214 |
iAllocationLength : KCommandLength;
|
|
215 |
aBuffer.SetLength(length);
|
|
216 |
}
|
|
217 |
|
297
|
218 |
// **** START STOP UNIT ****
|
0
|
219 |
void TScsiServerStartStopUnitReq::DecodeL(const TDesC8& aPtr)
|
|
220 |
{
|
297
|
221 |
TScsiServerReq::DecodeL(aPtr);
|
0
|
222 |
|
|
223 |
const TUint8 KStartMask = 0x01;
|
|
224 |
const TUint8 KImmedMask = 0x01;
|
|
225 |
const TUint8 KLoejMask = 0x02;
|
|
226 |
|
|
227 |
iImmed = aPtr[1] & KImmedMask ? ETrue : EFalse;
|
|
228 |
iStart = aPtr[4] & KStartMask ? ETrue : EFalse;
|
|
229 |
iLoej = aPtr[4] & KLoejMask ? ETrue : EFalse;
|
|
230 |
|
|
231 |
__PRINT2(_L("<-PROTOCOL(SCSI) START STOP UNIT Data %X %X\n"), aPtr[1], aPtr[4]);
|
|
232 |
__PRINT1(_L("IMMED = %d\n"), iImmed);
|
|
233 |
__PRINT1(_L("START = %d\n"), iStart);
|
|
234 |
__PRINT1(_L("LOEJ = %d\n"), iLoej);
|
|
235 |
}
|
|
236 |
|
|
237 |
|
297
|
238 |
// **** PREVENT MEDIA REMOVAL ****
|
0
|
239 |
void TScsiServerPreventMediaRemovalReq::DecodeL(const TDesC8& aPtr)
|
|
240 |
{
|
297
|
241 |
TScsiServerReq::DecodeL(aPtr);
|
|
242 |
iPrevent = aPtr[4] & 0x01;
|
|
243 |
__PRINT1(_L("<-PROTOCOL(SCSI) PREVENT MEDIA REMOVAL prevent = %d\n"), iPrevent);
|
0
|
244 |
}
|
|
245 |
|
|
246 |
|
297
|
247 |
// **** READ FORMAT CAPACITIES ****
|
0
|
248 |
void TScsiServerReadFormatCapacitiesReq::DecodeL(const TDesC8& aPtr)
|
|
249 |
{
|
297
|
250 |
TScsiServerReq::DecodeL(aPtr);
|
0
|
251 |
const TUint8* ptr = aPtr.Ptr();
|
|
252 |
iAllocationLength = BigEndian::Get32(ptr+7);
|
297
|
253 |
__PRINT(_L("<-PROTOCOL(SCSI) READ FORMAT CAPACITIES\n"));
|
0
|
254 |
}
|
|
255 |
|
|
256 |
|
|
257 |
void TScsiServerReadFormatCapacitiesResp::Encode(TDes8& aBuffer) const
|
|
258 |
{
|
297
|
259 |
__PRINT(_L("->PROTOCOL(SCSI) READ FORMAT CAPACITIES\n"));
|
|
260 |
aBuffer.FillZ(KResponseLength);
|
|
261 |
aBuffer[3] = 0x08; // Capacity List Length
|
0
|
262 |
|
297
|
263 |
aBuffer[4] = static_cast<TUint8>(iNumberBlocks >> 24); // Number of blocks
|
|
264 |
aBuffer[5] = static_cast<TUint8>(iNumberBlocks >> 16); //
|
|
265 |
aBuffer[6] = static_cast<TUint8>(iNumberBlocks >> 8); //
|
|
266 |
aBuffer[7] = static_cast<TUint8>(iNumberBlocks); //
|
0
|
267 |
|
297
|
268 |
aBuffer[8] = 0x02; // Formatted size
|
0
|
269 |
|
297
|
270 |
aBuffer[9] = 0x00; // 512 Byte Blocks
|
|
271 |
aBuffer[10] = 0x02; //
|
|
272 |
aBuffer[11] = 0x00; //
|
0
|
273 |
|
|
274 |
// Truncate to Allocation Length of the Request
|
|
275 |
// Truncate to Allocation Length of the Request
|
|
276 |
TUint length = iAllocationLength < KResponseLength ?
|
|
277 |
iAllocationLength : KResponseLength;
|
|
278 |
aBuffer.SetLength(length);
|
|
279 |
}
|
|
280 |
|
|
281 |
|
297
|
282 |
// **** READ CAPACITY (10) ****
|
0
|
283 |
void TScsiServerReadCapacity10Req::DecodeL(const TDesC8& aPtr)
|
|
284 |
{
|
297
|
285 |
TScsiServerReq::DecodeL(aPtr);
|
0
|
286 |
iPmi = aPtr[8] & 0x01;
|
|
287 |
const TUint8* ptr = aPtr.Ptr();
|
297
|
288 |
iLogicalBlockAddress = BigEndian::Get32(ptr+2);
|
0
|
289 |
__PRINT(_L("<-PROTOCOL(SCSI) READ CAPACITY (10)\n"));
|
|
290 |
}
|
|
291 |
|
|
292 |
|
|
293 |
void TScsiServerReadCapacity10Resp::Encode(TDes8& aBuffer) const
|
|
294 |
{
|
|
295 |
aBuffer.FillZ(KCommandLength);
|
|
296 |
|
|
297 |
__PRINT3(_L("->PROTOCOL(SCSI) READ CAPACITY (10) Block size=0x%X, NumBlocks=0x%08X%08X\n"),
|
|
298 |
iBlockSize,
|
|
299 |
I64HIGH(iNumberBlocks),
|
|
300 |
I64LOW(iNumberBlocks));
|
|
301 |
|
|
302 |
if (I64HIGH(iNumberBlocks) == 0)
|
|
303 |
{
|
|
304 |
TUint32 numBlocks = I64LOW(iNumberBlocks);
|
|
305 |
|
|
306 |
// Number of blocks
|
|
307 |
aBuffer[0] = static_cast<TUint8>(numBlocks >> 24);
|
|
308 |
aBuffer[1] = static_cast<TUint8>(numBlocks >> 16);
|
|
309 |
aBuffer[2] = static_cast<TUint8>(numBlocks >> 8);
|
|
310 |
aBuffer[3] = static_cast<TUint8>(numBlocks);
|
|
311 |
}
|
|
312 |
else
|
|
313 |
{
|
|
314 |
// indicate that size more then )0xFFFFFFFF
|
|
315 |
aBuffer[0] = aBuffer[1] = aBuffer[2] = aBuffer[3] = 0xFF;
|
|
316 |
}
|
|
317 |
|
297
|
318 |
// Block Size
|
0
|
319 |
aBuffer[4] = static_cast<TUint8>(iBlockSize >> 24);
|
|
320 |
aBuffer[5] = static_cast<TUint8>(iBlockSize >> 16);
|
|
321 |
aBuffer[6] = static_cast<TUint8>(iBlockSize >> 8);
|
|
322 |
aBuffer[7] = static_cast<TUint8>(iBlockSize);
|
|
323 |
}
|
|
324 |
|
|
325 |
|
297
|
326 |
// **** RdWr10 ****
|
0
|
327 |
void TScsiServerRdWr10Req::DecodeL(const TDesC8& aDes)
|
|
328 |
{
|
297
|
329 |
TScsiServerReq::DecodeL(aDes);
|
0
|
330 |
|
|
331 |
// PROTECT
|
297
|
332 |
iProtect = aDes[1] >> 5;
|
0
|
333 |
|
|
334 |
const TUint8* ptr = aDes.Ptr();
|
|
335 |
// LOGICAL BLOCK ADDRESS
|
297
|
336 |
iLogicalBlockAddress = BigEndian::Get32(ptr+2);
|
0
|
337 |
// TRANSFER LENGTH
|
297
|
338 |
iTransferLength = BigEndian::Get16(ptr+7);
|
0
|
339 |
|
297
|
340 |
__PRINT2(_L("<-PROTOCOL(SCSI) RD/WR (10) : LBA = %x, Length = %x (blocks)\n"),
|
0
|
341 |
iLogicalBlockAddress, iTransferLength);
|
|
342 |
}
|
|
343 |
|
|
344 |
|
297
|
345 |
// **** READ (10) ****
|
|
346 |
// **** WRITE (10) ****
|
|
347 |
// **** VERIFY (10) ****
|
0
|
348 |
void TScsiServerVerify10Req::DecodeL(const TDesC8& aPtr)
|
|
349 |
{
|
297
|
350 |
TScsiServerRdWr10Req::DecodeL(aPtr);
|
|
351 |
iBytchk = aPtr[1] & 0x02 ? ETrue : EFalse;
|
0
|
352 |
}
|