0
|
1 |
// Copyright (c) 2008-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 |
@file
|
|
18 |
@internalTechnology
|
|
19 |
*/
|
|
20 |
|
|
21 |
#include <e32base.h>
|
|
22 |
|
|
23 |
#include "shared.h"
|
|
24 |
#include "msgservice.h"
|
|
25 |
#include "msctypes.h"
|
|
26 |
|
|
27 |
#include "mprotocol.h"
|
|
28 |
#include "mblocktransferprotocol.h"
|
|
29 |
#include "tspcclientinterface.h"
|
|
30 |
#include "cscsiprotocol.h"
|
|
31 |
|
|
32 |
#include "cusbhostmslogicalunit.h"
|
|
33 |
#include "usbmshostpanic.h"
|
|
34 |
#include "msdebug.h"
|
|
35 |
#include "debug.h"
|
|
36 |
|
|
37 |
|
|
38 |
CUsbHostMsLogicalUnit* CUsbHostMsLogicalUnit::NewL(TLun aLun)
|
|
39 |
{
|
|
40 |
__MSFNSLOG
|
|
41 |
CUsbHostMsLogicalUnit* r = new (ELeave) CUsbHostMsLogicalUnit(aLun);
|
|
42 |
CleanupStack::PushL(r);
|
|
43 |
r->ConstructL();
|
|
44 |
CleanupStack::Pop();
|
|
45 |
return r;
|
|
46 |
}
|
|
47 |
|
|
48 |
|
|
49 |
void CUsbHostMsLogicalUnit::ConstructL()
|
|
50 |
{
|
|
51 |
__MSFNLOG
|
|
52 |
const TInt KInitialDataBufSize = 0x200;
|
|
53 |
iDataBuf.CreateL(KInitialDataBufSize);
|
|
54 |
}
|
|
55 |
|
|
56 |
|
|
57 |
CUsbHostMsLogicalUnit::CUsbHostMsLogicalUnit(TLun aLun)
|
|
58 |
: iProtocol(NULL),
|
|
59 |
iLun(aLun),
|
|
60 |
iSuspendRequest(EFalse)
|
|
61 |
{
|
|
62 |
__MSFNLOG
|
|
63 |
}
|
|
64 |
|
|
65 |
CUsbHostMsLogicalUnit::~CUsbHostMsLogicalUnit()
|
|
66 |
{
|
|
67 |
__MSFNLOG
|
|
68 |
iDataBuf.Close();
|
|
69 |
delete iProtocol;
|
|
70 |
}
|
|
71 |
|
|
72 |
|
|
73 |
void CUsbHostMsLogicalUnit::InitL()
|
|
74 |
{
|
|
75 |
__MSFNLOG
|
|
76 |
iProtocol->InitialiseUnitL();
|
|
77 |
}
|
|
78 |
|
|
79 |
void CUsbHostMsLogicalUnit::UnInitL()
|
|
80 |
{
|
|
81 |
__MSFNLOG
|
|
82 |
iProtocol->UninitialiseUnitL();
|
|
83 |
}
|
|
84 |
|
|
85 |
void CUsbHostMsLogicalUnit::ReadL(const RMessage2& aMessage)
|
|
86 |
{
|
|
87 |
__MSFNLOG
|
|
88 |
TReadWrite p;
|
|
89 |
TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
|
|
90 |
aMessage.ReadL(0, pReadWrite);
|
|
91 |
__HOSTPRINT2(_L("pos = 0x%lx len = %08x"), p.iPos, p.iLen);
|
|
92 |
|
|
93 |
User::LeaveIfError(CheckPosition(p));
|
|
94 |
|
|
95 |
// check if buffer can hold requested data and resize if not
|
|
96 |
if (iDataBuf.MaxLength() < p.iLen)
|
|
97 |
iDataBuf.ReAllocL(p.iLen);
|
|
98 |
|
|
99 |
iProtocol->ReadL(p.iPos, iDataBuf, p.iLen);
|
|
100 |
aMessage.WriteL(1, iDataBuf);
|
|
101 |
}
|
|
102 |
|
|
103 |
|
|
104 |
void CUsbHostMsLogicalUnit::WriteL(const RMessage2& aMessage)
|
|
105 |
{
|
|
106 |
__MSFNLOG
|
|
107 |
TReadWrite p;
|
|
108 |
TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
|
|
109 |
aMessage.ReadL(1, pReadWrite);
|
|
110 |
__HOSTPRINT2(_L("pos = 0x%lx len = %08x"), p.iPos, p.iLen);
|
|
111 |
|
|
112 |
User::LeaveIfError(CheckPosition(p));
|
|
113 |
|
|
114 |
// check if buffer can hold requested data and resize if not
|
|
115 |
if (iDataBuf.MaxLength() < p.iLen)
|
|
116 |
iDataBuf.ReAllocL(p.iLen);
|
|
117 |
|
|
118 |
aMessage.ReadL(0, iDataBuf);
|
|
119 |
iProtocol->WriteL(p.iPos, iDataBuf, p.iLen);
|
|
120 |
}
|
|
121 |
|
|
122 |
|
|
123 |
void CUsbHostMsLogicalUnit::EraseL(const RMessage2& aMessage)
|
|
124 |
{
|
|
125 |
__MSFNLOG
|
|
126 |
TReadWrite p;
|
|
127 |
TPtr8 pReadWrite((TUint8*)&p,sizeof(TReadWrite));
|
|
128 |
aMessage.ReadL(0, pReadWrite);
|
|
129 |
__HOSTPRINT2(_L("pos = 0x%lx len = %08x"), p.iPos, p.iLen);
|
|
130 |
|
|
131 |
User::LeaveIfError(CheckPosition(p));
|
|
132 |
|
|
133 |
// check if buffer can hold requested data and resize if not
|
|
134 |
if (iDataBuf.MaxLength() < p.iLen)
|
|
135 |
iDataBuf.ReAllocL(p.iLen);
|
|
136 |
|
|
137 |
iDataBuf.FillZ(p.iLen);
|
|
138 |
iProtocol->WriteL(p.iPos, iDataBuf, p.iLen);
|
|
139 |
}
|
|
140 |
|
|
141 |
|
|
142 |
void CUsbHostMsLogicalUnit::CapsL(const RMessage2& aMessage)
|
|
143 |
{
|
|
144 |
__MSFNLOG
|
|
145 |
|
|
146 |
TCapsInfo capsInfo;
|
|
147 |
TPckg<TCapsInfo> pckg(capsInfo);
|
|
148 |
iProtocol->GetCapacityL(capsInfo);
|
|
149 |
iSize = static_cast<TInt64>(capsInfo.iNumberOfBlocks) * capsInfo.iBlockLength;
|
|
150 |
aMessage.WriteL(0, pckg);
|
|
151 |
}
|
|
152 |
|
|
153 |
void CUsbHostMsLogicalUnit::NotifyChange(const RMessage2& aMessage)
|
|
154 |
{
|
|
155 |
__MSFNLOG
|
|
156 |
iProtocol->NotifyChange(aMessage);
|
|
157 |
}
|
|
158 |
|
|
159 |
|
|
160 |
void CUsbHostMsLogicalUnit::ForceCompleteNotifyChangeL()
|
|
161 |
{
|
|
162 |
__MSFNLOG
|
|
163 |
iProtocol->ForceCompleteNotifyChangeL();
|
|
164 |
}
|
|
165 |
|
|
166 |
void CUsbHostMsLogicalUnit::CancelChangeNotifierL()
|
|
167 |
{
|
|
168 |
__MSFNLOG
|
|
169 |
iProtocol->CancelChangeNotifierL();
|
|
170 |
}
|
|
171 |
|
|
172 |
TBool CUsbHostMsLogicalUnit::IsConnected()
|
|
173 |
{
|
|
174 |
return iProtocol->IsConnected() ? ETrue : EFalse;
|
|
175 |
}
|
|
176 |
|
|
177 |
TBool CUsbHostMsLogicalUnit::IsReadyToSuspend()
|
|
178 |
{
|
|
179 |
__MSFNLOG
|
|
180 |
return iSuspendRequest ? ETrue : EFalse;
|
|
181 |
}
|
|
182 |
|
|
183 |
void CUsbHostMsLogicalUnit::ReadyToSuspend()
|
|
184 |
{
|
|
185 |
__MSFNLOG
|
|
186 |
iSuspendRequest = ETrue;
|
|
187 |
}
|
|
188 |
|
|
189 |
void CUsbHostMsLogicalUnit::CancelReadyToSuspend()
|
|
190 |
{
|
|
191 |
__MSFNLOG
|
|
192 |
iSuspendRequest = EFalse;
|
|
193 |
}
|
|
194 |
|
|
195 |
void CUsbHostMsLogicalUnit::SuspendL()
|
|
196 |
{
|
|
197 |
__MSFNLOG
|
|
198 |
iProtocol->SuspendL();
|
|
199 |
}
|
|
200 |
|
|
201 |
void CUsbHostMsLogicalUnit::ResumeL()
|
|
202 |
{
|
|
203 |
__MSFNLOG
|
|
204 |
// We do not cancel iSuspendRequest here
|
|
205 |
iProtocol->ResumeL();
|
|
206 |
}
|
|
207 |
|
|
208 |
void CUsbHostMsLogicalUnit::DoLunReadyCheckL()
|
|
209 |
{
|
|
210 |
__MSFNLOG
|
|
211 |
iProtocol->DoScsiReadyCheckEventL();
|
|
212 |
}
|
|
213 |
|
|
214 |
TInt CUsbHostMsLogicalUnit::InitialiseProtocolL(TLun aLun,
|
|
215 |
THostMassStorageConfig& aConfig,
|
|
216 |
MTransport& aTransport)
|
|
217 |
{
|
|
218 |
__MSFNLOG
|
|
219 |
__ASSERT_DEBUG(iProtocol == NULL, User::Panic(KUsbMsHostPanicCat, EProtocolNotFree));
|
|
220 |
switch(aConfig.iProtocolId)
|
|
221 |
{
|
|
222 |
case ScsiProtocol:
|
|
223 |
iProtocol = CScsiProtocol::NewL(aLun, aTransport);
|
|
224 |
break;
|
|
225 |
default:
|
|
226 |
__HOSTPRINT(_L("Unsupported Transport class requested"));
|
|
227 |
iProtocol = NULL;
|
|
228 |
return KErrNotSupported;
|
|
229 |
}
|
|
230 |
return KErrNone;
|
|
231 |
}
|
|
232 |
|
|
233 |
TInt CUsbHostMsLogicalUnit::CheckPosition(const TReadWrite& aReadWrite)
|
|
234 |
{
|
|
235 |
if (aReadWrite.iLen == 0)
|
|
236 |
{
|
|
237 |
if (aReadWrite.iPos == iSize)
|
|
238 |
return KErrEof;
|
|
239 |
else
|
|
240 |
return KErrArgument;
|
|
241 |
}
|
|
242 |
|
|
243 |
// detect drive not present
|
|
244 |
if (iSize == 0)
|
|
245 |
return KErrNotReady;
|
|
246 |
|
|
247 |
if (aReadWrite.iPos >= iSize)
|
|
248 |
return KErrArgument;
|
|
249 |
return KErrNone;
|
|
250 |
}
|