author | hgs |
Tue, 26 Oct 2010 12:49:20 +0100 | |
changeset 297 | b2826f67641f |
parent 271 | dc268b18d709 |
permissions | -rw-r--r-- |
124 | 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> |
|
22 |
#include <d32usbdi.h> |
|
23 |
||
24 |
#include <d32usbtransfers.h> |
|
25 |
#include "msctypes.h" |
|
26 |
#include "shared.h" |
|
27 |
#include "msgservice.h" |
|
28 |
#include "botmsctypes.h" |
|
29 |
#include "mprotocol.h" |
|
30 |
#include "mtransport.h" |
|
31 |
#include "cbulkonlytransport.h" |
|
32 |
#include "cusbhostmslogicalunit.h" |
|
33 |
#include "cusbhostmsdevice.h" |
|
34 |
#include "cusbmssuspendresume.h" |
|
35 |
||
297 | 36 |
#include "OstTraceDefinitions.h" |
37 |
#ifdef OST_TRACE_COMPILER_IN_USE |
|
38 |
#include "cusbhostmsdeviceTraces.h" |
|
39 |
#endif |
|
0 | 40 |
|
41 |
||
42 |
CUsbHostMsDevice* CUsbHostMsDevice::NewL(THostMassStorageConfig& aConfig) |
|
43 |
{ |
|
297 | 44 |
CUsbHostMsDevice* r = new (ELeave) CUsbHostMsDevice(aConfig); |
45 |
CleanupStack::PushL(r); |
|
46 |
r->ConstructL(); |
|
47 |
CleanupStack::Pop(); |
|
48 |
return r; |
|
49 |
} |
|
0 | 50 |
|
51 |
void CUsbHostMsDevice::ConstructL() |
|
52 |
{ |
|
297 | 53 |
iTimer = CPeriodic::NewL(CActive::EPriorityStandard); |
54 |
iTimerRunning = EFalse; |
|
0 | 55 |
} |
56 |
||
57 |
||
58 |
CUsbHostMsDevice::CUsbHostMsDevice(THostMassStorageConfig& aConfig) |
|
297 | 59 |
: iConfig(aConfig), |
60 |
iState(EReady) |
|
0 | 61 |
{ |
297 | 62 |
} |
0 | 63 |
|
64 |
||
65 |
CUsbHostMsDevice::~CUsbHostMsDevice() |
|
66 |
{ |
|
297 | 67 |
delete iTransport; |
68 |
delete iDeviceSuspendResume; |
|
69 |
if (iTimer && iTimerRunning) |
|
70 |
{ |
|
71 |
iTimer->Cancel(); |
|
72 |
} |
|
73 |
delete iTimer; |
|
74 |
} |
|
0 | 75 |
|
76 |
||
77 |
MTransport* CUsbHostMsDevice::InitialiseTransportL(TTransportType aTransportId) |
|
78 |
{ |
|
297 | 79 |
switch(aTransportId) |
0 | 80 |
{ |
297 | 81 |
case BulkOnlyTransport: |
82 |
return CBulkOnlyTransport::NewL(iConfig.iInterfaceToken); |
|
83 |
default: |
|
84 |
// Panic; |
|
85 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, CUSBHOSTMSDEVICE_10, |
|
86 |
"Unsupported Transport class requested"); |
|
87 |
User::Leave(KErrNotSupported); |
|
88 |
return NULL; |
|
0 | 89 |
} |
90 |
} |
|
91 |
||
92 |
void CUsbHostMsDevice::InitialiseL(const RMessage2& aMessage) |
|
297 | 93 |
{ |
94 |
iTransport = InitialiseTransportL((TTransportType) iConfig.iTransportId); |
|
95 |
TRAPD(r, iDeviceSuspendResume = CUsbMsIfaceSuspendResume::NewL(iTransport, this)); |
|
96 |
if(r != KErrNone) |
|
97 |
{ |
|
98 |
delete iTransport; |
|
99 |
User::Leave(r); |
|
100 |
} |
|
101 |
iTransport->GetMaxLun(&iMaxLun, aMessage); |
|
102 |
} |
|
0 | 103 |
|
104 |
||
105 |
void CUsbHostMsDevice::UnInitialiseL() |
|
106 |
{ |
|
297 | 107 |
StopTimer(); |
0 | 108 |
iLuList.RemoveAllLuL(); |
109 |
} |
|
110 |
||
111 |
||
112 |
TInt CUsbHostMsDevice::AddLunL(TLun aLun) |
|
113 |
{ |
|
114 |
TInt r = KErrNone; |
|
297 | 115 |
StartTimer(); |
0 | 116 |
CUsbHostMsLogicalUnit* lu = CUsbHostMsLogicalUnit::NewL(aLun); |
117 |
CleanupStack::PushL(lu); |
|
118 |
||
119 |
TRAP(r, lu->InitialiseProtocolL(aLun, iConfig, *iTransport)); |
|
120 |
||
297 | 121 |
if (r == KErrNone) |
122 |
{ |
|
123 |
TRAP(r, iLuList.AddLuL(lu)); |
|
124 |
} |
|
0 | 125 |
|
126 |
if (r != KErrNone) |
|
127 |
{ |
|
128 |
CleanupStack::PopAndDestroy(lu); |
|
129 |
} |
|
130 |
else |
|
131 |
{ |
|
132 |
CleanupStack::Pop(lu); |
|
133 |
} |
|
134 |
return r; |
|
135 |
} |
|
136 |
||
137 |
||
138 |
void CUsbHostMsDevice::RemoveLunL(TLun aLun) |
|
139 |
{ |
|
297 | 140 |
if(iLuList.Count() <= 1) |
141 |
StopTimer(); |
|
142 |
iLuList.RemoveLuL(aLun); |
|
0 | 143 |
} |
144 |
||
145 |
||
146 |
void CUsbHostMsDevice::InitLunL(TLun aLun) |
|
297 | 147 |
{ |
148 |
CUsbHostMsLogicalUnit& lu = SetLunL(aLun); |
|
124 | 149 |
lu.InitL(); |
297 | 150 |
} |
0 | 151 |
|
152 |
||
153 |
void CUsbHostMsDevice::SuspendLunL(TLun aLun) |
|
297 | 154 |
{ |
271 | 155 |
if (IsSuspended()) |
156 |
{ |
|
157 |
return; |
|
158 |
} |
|
159 |
||
160 |
iLuList.GetLuL(aLun).ReadyToSuspend(); |
|
0 | 161 |
|
162 |
// check whether all the luns are suspended, if so then request usb |
|
163 |
// interface suspension to the transport layer |
|
297 | 164 |
for (TInt i = 0; i < iLuList.Count(); i++) |
165 |
{ |
|
166 |
CUsbHostMsLogicalUnit& lu = iLuList.GetLu(i); |
|
167 |
if (!lu.IsReadyToSuspend() && lu.IsConnected()) |
|
168 |
return; |
|
169 |
} |
|
0 | 170 |
|
297 | 171 |
for (TInt i = 0; i < iLuList.Count(); i++) |
172 |
{ |
|
173 |
CUsbHostMsLogicalUnit& lu = iLuList.GetLu(i); |
|
174 |
SetLunL(lu); |
|
175 |
lu.SuspendL(); |
|
176 |
} |
|
0 | 177 |
|
297 | 178 |
StopTimer(); |
179 |
iDeviceSuspendResume->Suspend(); |
|
180 |
iState = ESuspended; |
|
181 |
} |
|
0 | 182 |
|
183 |
||
31
56f325a607ea
Revision: 200951
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
184 |
void CUsbHostMsDevice::Resume(TRequestStatus& aStatus) |
297 | 185 |
{ |
186 |
if (iState == ESuspended) |
|
187 |
{ |
|
188 |
StartTimer(); |
|
189 |
iDeviceSuspendResume->Resume(aStatus); |
|
190 |
} |
|
191 |
} |
|
0 | 192 |
|
193 |
||
194 |
TLun CUsbHostMsDevice::GetAndSetLunL(const RMessage2& aMessage) |
|
297 | 195 |
{ |
196 |
// Subssessions need a positive value to store in the handles. We represent Luns as LunId+1 |
|
197 |
// We represent LunId in MSC from 0 to MaxLun-1 as represented in BOT so subtract 1 from the Id |
|
0 | 198 |
// received from RMessage |
199 |
||
200 |
TInt lun = aMessage.Int3() - 1; |
|
201 |
if (lun < 0) |
|
202 |
{ |
|
203 |
User::Leave(KErrArgument); |
|
204 |
} |
|
297 | 205 |
SetLunL(static_cast<TLun>(lun)); |
206 |
return static_cast<TLun>(lun); |
|
207 |
} |
|
0 | 208 |
|
209 |
||
210 |
CUsbHostMsLogicalUnit& CUsbHostMsDevice::GetLuL(TInt aLunNum) const |
|
211 |
{ |
|
212 |
return iLuList.GetLuL(aLunNum); |
|
213 |
} |
|
214 |
||
124 | 215 |
|
216 |
void CUsbHostMsDevice::SetLunL(CUsbHostMsLogicalUnit& aLu) |
|
297 | 217 |
{ |
124 | 218 |
TLun lun = aLu.Lun(); |
297 | 219 |
if (lun <= iMaxLun) |
0 | 220 |
{ |
297 | 221 |
OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, CUSBHOSTMSDEVICE_20, |
222 |
"SetLun %d", lun); |
|
124 | 223 |
iTransport->SetLun(lun); |
297 | 224 |
if (aLu.IsReadyToSuspend()) |
225 |
{ |
|
226 |
aLu.CancelReadyToSuspend(); |
|
227 |
} |
|
228 |
} |
|
229 |
} |
|
0 | 230 |
|
124 | 231 |
|
232 |
CUsbHostMsLogicalUnit& CUsbHostMsDevice::SetLunL(TLun aLun) |
|
297 | 233 |
{ |
124 | 234 |
CUsbHostMsLogicalUnit& lu = iLuList.GetLuL(aLun); |
235 |
SetLunL(lu); |
|
236 |
return lu; |
|
297 | 237 |
} |
124 | 238 |
|
0 | 239 |
/** |
240 |
Starts timer to periodically check LUN. If the timer is not yet running then |
|
241 |
start it. |
|
242 |
*/ |
|
243 |
void CUsbHostMsDevice::StartTimer() |
|
297 | 244 |
{ |
245 |
if (!iTimerRunning) |
|
246 |
{ |
|
247 |
// Period of the LUN Ready check |
|
248 |
const TTimeIntervalMicroSeconds32 KInterval = iConfig.iStatusPollingInterval * 1000 * 1000; |
|
249 |
TCallBack callback(TimerCallback, this); |
|
250 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, CUSBHOSTMSDEVICE_21, |
|
251 |
"Starting timer"); |
|
252 |
iTimer->Start(KInterval, KInterval, callback); |
|
253 |
iTimerRunning = ETrue; |
|
254 |
} |
|
255 |
} |
|
0 | 256 |
|
257 |
||
258 |
/** |
|
259 |
Ensure that the Timer is stopped |
|
260 |
*/ |
|
261 |
void CUsbHostMsDevice::StopTimer() |
|
297 | 262 |
{ |
263 |
if (iTimer && iTimerRunning) |
|
264 |
{ |
|
265 |
OstTrace0(TRACE_SHOSTMASSSTORAGE_HOST, CUSBHOSTMSDEVICE_30, |
|
266 |
"Stopping timer"); |
|
267 |
if (iTimer->IsActive()) |
|
268 |
{ |
|
269 |
iTimer->Cancel(); |
|
270 |
} |
|
271 |
iTimerRunning = EFalse; |
|
272 |
} |
|
273 |
} |
|
0 | 274 |
|
275 |
/** |
|
276 |
A static wrapper for the DoLunReadyCheckEvent member function for use as a timer |
|
277 |
callback function. |
|
278 |
||
279 |
@param obj 'this' pointer |
|
280 |
@return not used in CPeriodic callback (see TCallback) |
|
281 |
*/ |
|
282 |
TInt CUsbHostMsDevice::TimerCallback(TAny* obj) |
|
297 | 283 |
{ |
0 | 284 |
CUsbHostMsDevice* device = static_cast<CUsbHostMsDevice*>(obj); |
297 | 285 |
TRAPD(err, device->DoLunReadyCheckEventL()); |
286 |
return err; |
|
287 |
} |
|
0 | 288 |
|
289 |
void CUsbHostMsDevice::DoLunReadyCheckEventL() |
|
297 | 290 |
{ |
291 |
TInt err; |
|
292 |
for (TInt i = 0; i < iLuList.Count(); i++) |
|
293 |
{ |
|
294 |
CUsbHostMsLogicalUnit& lu = iLuList.GetLu(i); |
|
295 |
SetLunL(lu); |
|
296 |
TRAP(err, lu.DoLunReadyCheckL()); |
|
297 |
} |
|
298 |
} |
|
0 | 299 |
|
300 |
void CUsbHostMsDevice::DoHandleRemoteWakeupL() |
|
297 | 301 |
{ |
302 |
DoResumeLogicalUnitsL(); |
|
303 |
DoLunReadyCheckEventL(); // For remote wakeup we do not wait for timer to expire |
|
0 | 304 |
|
305 |
// check whether all the luns are suspended, if so then request usb |
|
306 |
// interface suspension to the transport layer |
|
297 | 307 |
for (TInt i = 0; i < iLuList.Count(); i++) |
308 |
{ |
|
309 |
CUsbHostMsLogicalUnit& lu = iLuList.GetLu(i); |
|
310 |
// Has any of the logical units have got its state changed? |
|
311 |
if ( (lu.IsReadyToSuspend() && !lu.IsConnected()) || |
|
312 |
(!lu.IsReadyToSuspend() && lu.IsConnected()) ) |
|
313 |
{ |
|
314 |
StartTimer(); // Now start the timer |
|
315 |
return; |
|
316 |
} |
|
317 |
} |
|
0 | 318 |
|
297 | 319 |
for (TInt i = 0; i < iLuList.Count(); i++) |
320 |
{ |
|
321 |
CUsbHostMsLogicalUnit& lu = iLuList.GetLu(i); |
|
322 |
SetLunL(lu); |
|
323 |
lu.SuspendL(); |
|
324 |
} |
|
0 | 325 |
|
297 | 326 |
iDeviceSuspendResume->Suspend(); |
327 |
iState = ESuspended; |
|
328 |
} |
|
0 | 329 |
|
330 |
void CUsbHostMsDevice::DoResumeLogicalUnitsL() |
|
297 | 331 |
{ |
332 |
for (TInt i = 0; i < iLuList.Count(); i++) |
|
333 |
{ |
|
334 |
CUsbHostMsLogicalUnit& lu = iLuList.GetLu(i); |
|
335 |
SetLunL(lu); |
|
336 |
lu.ResumeL(); |
|
337 |
} |
|
338 |
} |
|
0 | 339 |
|
340 |
void CUsbHostMsDevice::ResumeCompletedL() |
|
297 | 341 |
{ |
342 |
iState = EReady; |
|
343 |
DoResumeLogicalUnitsL(); |
|
344 |
} |