sl@0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
/**
|
sl@0
|
17 |
@file
|
sl@0
|
18 |
@internalTechnology
|
sl@0
|
19 |
*/
|
sl@0
|
20 |
|
sl@0
|
21 |
#include <e32base.h>
|
sl@0
|
22 |
#include "debug.h"
|
sl@0
|
23 |
#include "msdebug.h"
|
sl@0
|
24 |
#include "msctypes.h"
|
sl@0
|
25 |
#include "mscutils.h"
|
sl@0
|
26 |
|
sl@0
|
27 |
#include "mtransport.h"
|
sl@0
|
28 |
#include "mprotocol.h"
|
sl@0
|
29 |
#include "tscsiclientreq.h"
|
sl@0
|
30 |
#include "tscsiblockcmds.h"
|
sl@0
|
31 |
|
sl@0
|
32 |
|
sl@0
|
33 |
// **** MODE SENSE (6) ****
|
sl@0
|
34 |
void TScsiClientModeSense6Resp::DecodeL(const TDesC8& aPtr)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
__MSFNSLOG
|
sl@0
|
37 |
__SCSIPRINT(_L("--> SCSI MODE SENSE (6)"));
|
sl@0
|
38 |
__SCSIPRINT1(_L("len=%d"), aPtr.Length());
|
sl@0
|
39 |
// Mode Parameter List
|
sl@0
|
40 |
// SPC-3 7.4.2
|
sl@0
|
41 |
// - Mode Parameter Header
|
sl@0
|
42 |
// - Block Descriptor(s)
|
sl@0
|
43 |
// - Mode Page(s)
|
sl@0
|
44 |
|
sl@0
|
45 |
// Mode Parameter Header
|
sl@0
|
46 |
// SPC-3 7.4.3
|
sl@0
|
47 |
// [0] Mode Data Length
|
sl@0
|
48 |
// [1] Medium Type
|
sl@0
|
49 |
// [2] Device-Specific Paramater
|
sl@0
|
50 |
// [3] Block Descriptor Length
|
sl@0
|
51 |
|
sl@0
|
52 |
|
sl@0
|
53 |
// validate length
|
sl@0
|
54 |
if (aPtr.Length() < KResponseLength)
|
sl@0
|
55 |
{
|
sl@0
|
56 |
User::Leave(KErrGeneral);
|
sl@0
|
57 |
}
|
sl@0
|
58 |
|
sl@0
|
59 |
TInt modeDataLength = aPtr[0];
|
sl@0
|
60 |
if (aPtr.Length() - 1 < modeDataLength)
|
sl@0
|
61 |
{
|
sl@0
|
62 |
User::Leave(KErrGeneral);
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
TInt mediumType = aPtr[1];
|
sl@0
|
66 |
TUint8 deviceSpecificParameter = aPtr[2];
|
sl@0
|
67 |
// TInt blockDescriptorLength = aPtr[3];
|
sl@0
|
68 |
|
sl@0
|
69 |
__SCSIPRINT2(_L("Medium Type=%d DSP=0x%x"), mediumType, deviceSpecificParameter);
|
sl@0
|
70 |
// [1] Medium Type
|
sl@0
|
71 |
// 0x00 for SBC
|
sl@0
|
72 |
if (mediumType == 0)
|
sl@0
|
73 |
{
|
sl@0
|
74 |
// [2] Device specific parameter
|
sl@0
|
75 |
// SBC-3 6.3.1
|
sl@0
|
76 |
// get the WP bit from the Device Specific parameters
|
sl@0
|
77 |
iWriteProtected = (deviceSpecificParameter & 0x80) ? ETrue : EFalse;
|
sl@0
|
78 |
}
|
sl@0
|
79 |
else
|
sl@0
|
80 |
{
|
sl@0
|
81 |
// unsupported medium type
|
sl@0
|
82 |
iWriteProtected = EFalse;
|
sl@0
|
83 |
}
|
sl@0
|
84 |
|
sl@0
|
85 |
// [3] Block Descriptor Length
|
sl@0
|
86 |
// 0x00 for no descriptors
|
sl@0
|
87 |
|
sl@0
|
88 |
// No Block Descriptors
|
sl@0
|
89 |
|
sl@0
|
90 |
// No Mode Pages
|
sl@0
|
91 |
|
sl@0
|
92 |
}
|
sl@0
|
93 |
|
sl@0
|
94 |
|
sl@0
|
95 |
// **** MODE SENSE (10) ****
|
sl@0
|
96 |
void TScsiClientModeSense10Resp::DecodeL(const TDesC8& aPtr)
|
sl@0
|
97 |
{
|
sl@0
|
98 |
__MSFNSLOG
|
sl@0
|
99 |
__SCSIPRINT(_L("--> SCSI MODE SENSE (10)"));
|
sl@0
|
100 |
__SCSIPRINT1(_L("len=%d"), aPtr.Length());
|
sl@0
|
101 |
// Mode Parameter List
|
sl@0
|
102 |
// SPC-3 7.4.2
|
sl@0
|
103 |
// - Mode Parameter Header
|
sl@0
|
104 |
// - Block Descriptor(s)
|
sl@0
|
105 |
// - Mode Page(s)
|
sl@0
|
106 |
|
sl@0
|
107 |
// Mode Parameter Header
|
sl@0
|
108 |
// SPC-3 7.4.3
|
sl@0
|
109 |
// [0] Mode Data Length
|
sl@0
|
110 |
// [1] Mode Data Length
|
sl@0
|
111 |
// [2] Medium Type
|
sl@0
|
112 |
// [3] Device-Specific Paramater
|
sl@0
|
113 |
// [4] Reserved
|
sl@0
|
114 |
// [5] Reserved
|
sl@0
|
115 |
// [6] Block Descriptor Length
|
sl@0
|
116 |
// [7] Block Descriptor Length
|
sl@0
|
117 |
|
sl@0
|
118 |
// validate length
|
sl@0
|
119 |
if (aPtr.Length() < KResponseLength)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
User::Leave(KErrGeneral);
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
TInt modeDataLength = BigEndian::Get32(&aPtr[0]);
|
sl@0
|
125 |
if (aPtr.Length() - 2 < modeDataLength)
|
sl@0
|
126 |
{
|
sl@0
|
127 |
User::Leave(KErrGeneral);
|
sl@0
|
128 |
}
|
sl@0
|
129 |
|
sl@0
|
130 |
TInt mediumType = aPtr[2];
|
sl@0
|
131 |
TUint8 deviceSpecificParameter = aPtr[3];
|
sl@0
|
132 |
// TInt blockDescriptorLength = BigEndian::Get32(&aPtr[6]);;
|
sl@0
|
133 |
|
sl@0
|
134 |
__SCSIPRINT2(_L("Medium Type=%d DSP=0x%x"), mediumType, deviceSpecificParameter);
|
sl@0
|
135 |
// [1] Medium Type
|
sl@0
|
136 |
// 0x00 for SBC
|
sl@0
|
137 |
if (mediumType == 0)
|
sl@0
|
138 |
{
|
sl@0
|
139 |
// [2] Device specific parameter
|
sl@0
|
140 |
// SBC-3 6.3.1
|
sl@0
|
141 |
// get the WP bit from the Device Specific parameters
|
sl@0
|
142 |
iWriteProtected = (deviceSpecificParameter & 0x80) ? ETrue : EFalse;
|
sl@0
|
143 |
}
|
sl@0
|
144 |
else
|
sl@0
|
145 |
{
|
sl@0
|
146 |
// unsupported medium type
|
sl@0
|
147 |
iWriteProtected = EFalse;
|
sl@0
|
148 |
}
|
sl@0
|
149 |
|
sl@0
|
150 |
// [3] Block Descriptor Length
|
sl@0
|
151 |
// 0x00 for no descriptors
|
sl@0
|
152 |
|
sl@0
|
153 |
// No Block Descriptors
|
sl@0
|
154 |
|
sl@0
|
155 |
// No Mode Pages
|
sl@0
|
156 |
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
|
sl@0
|
160 |
|
sl@0
|
161 |
// **** READ CAPACITY (10) ***
|
sl@0
|
162 |
TInt TScsiClientReadCapacity10Req::EncodeRequestL(TDes8& aBuffer) const
|
sl@0
|
163 |
{
|
sl@0
|
164 |
__MSFNSLOG
|
sl@0
|
165 |
__SCSIPRINT(_L("<-- READ CAPACITY 10"));
|
sl@0
|
166 |
TInt length = TScsiClientReq::EncodeRequestL(aBuffer);
|
sl@0
|
167 |
|
sl@0
|
168 |
if (iLba)
|
sl@0
|
169 |
{
|
sl@0
|
170 |
// PMI bit
|
sl@0
|
171 |
aBuffer[8] = 0x01;
|
sl@0
|
172 |
// LBA
|
sl@0
|
173 |
BigEndian::Put32(&aBuffer[2], iLba);
|
sl@0
|
174 |
}
|
sl@0
|
175 |
return length;
|
sl@0
|
176 |
}
|
sl@0
|
177 |
|
sl@0
|
178 |
|
sl@0
|
179 |
void TScsiClientReadCapacity10Resp::DecodeL(const TDesC8& aPtr)
|
sl@0
|
180 |
{
|
sl@0
|
181 |
__MSFNSLOG
|
sl@0
|
182 |
__SCSIPRINT(_L("--> SCSI READ CAPACITY (10)"));
|
sl@0
|
183 |
iLba = BigEndian::Get32(&aPtr[0]);
|
sl@0
|
184 |
iBlockSize = BigEndian::Get32(&aPtr[4]);
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
|
sl@0
|
188 |
// **** RdWr10 ****
|
sl@0
|
189 |
TInt TScsiClientRdWr10Req::EncodeRequestL(TDes8& aBuffer) const
|
sl@0
|
190 |
{
|
sl@0
|
191 |
__MSFNSLOG
|
sl@0
|
192 |
TInt length = TScsiClientReq::EncodeRequestL(aBuffer);
|
sl@0
|
193 |
|
sl@0
|
194 |
// PROTECT
|
sl@0
|
195 |
if (iProtect)
|
sl@0
|
196 |
aBuffer[1] = iProtect << 5;
|
sl@0
|
197 |
|
sl@0
|
198 |
__SCSIPRINT2(_L("LBA=%08x LEN=%08x"), iLogicalBlockAddress, iBlockTransferLength);
|
sl@0
|
199 |
// LOGICAL BLOCK ADDRESS
|
sl@0
|
200 |
BigEndian::Put32(&aBuffer[2], iLogicalBlockAddress);
|
sl@0
|
201 |
// TRANSFER LENGTH
|
sl@0
|
202 |
BigEndian::Put16(&aBuffer[7], iBlockTransferLength);
|
sl@0
|
203 |
return length;
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
// **** READ (10) ****
|
sl@0
|
207 |
TInt TScsiClientRead10Req::EncodeRequestL(TDes8& aBuffer) const
|
sl@0
|
208 |
{
|
sl@0
|
209 |
__MSFNSLOG
|
sl@0
|
210 |
__SCSIPRINT(_L("<-- SCSI READ (10)"));
|
sl@0
|
211 |
TInt length = TScsiClientRdWr10Req::EncodeRequestL(aBuffer);
|
sl@0
|
212 |
return length;
|
sl@0
|
213 |
}
|
sl@0
|
214 |
|
sl@0
|
215 |
|
sl@0
|
216 |
// **** START STOP UNIT ****
|
sl@0
|
217 |
TInt TScsiClientStartStopUnitReq::EncodeRequestL(TDes8& aBuffer) const
|
sl@0
|
218 |
{
|
sl@0
|
219 |
__MSFNSLOG
|
sl@0
|
220 |
__SCSIPRINT(_L("--> SCSI START STOP UNIT"));
|
sl@0
|
221 |
TInt length = TScsiClientReq::EncodeRequestL(aBuffer);
|
sl@0
|
222 |
|
sl@0
|
223 |
// byte 1 mask
|
sl@0
|
224 |
const TUint8 KImmedMask = 0x01;
|
sl@0
|
225 |
|
sl@0
|
226 |
// byte 4 mask
|
sl@0
|
227 |
const TUint8 KStartMask = 0x01;
|
sl@0
|
228 |
const TUint8 KLoejMask = 0x02;
|
sl@0
|
229 |
|
sl@0
|
230 |
if (iImmed)
|
sl@0
|
231 |
aBuffer[1] |= KImmedMask;
|
sl@0
|
232 |
if (iStart)
|
sl@0
|
233 |
aBuffer[4] |= KStartMask;
|
sl@0
|
234 |
if (iLoej)
|
sl@0
|
235 |
aBuffer[4] |= KLoejMask;
|
sl@0
|
236 |
return length;
|
sl@0
|
237 |
}
|
sl@0
|
238 |
|
sl@0
|
239 |
|
sl@0
|
240 |
// **** WRITE (10) ****
|
sl@0
|
241 |
TInt TScsiClientWrite10Req::EncodeRequestL(TDes8& aBuffer) const
|
sl@0
|
242 |
{
|
sl@0
|
243 |
__MSFNSLOG
|
sl@0
|
244 |
__SCSIPRINT(_L("<-- SCSI WRITE 10"));
|
sl@0
|
245 |
|
sl@0
|
246 |
TInt length = TScsiClientRdWr10Req::EncodeRequestL(aBuffer);
|
sl@0
|
247 |
return length;
|
sl@0
|
248 |
}
|
sl@0
|
249 |
|