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