sl@0
|
1 |
// Copyright (c) 2006-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 |
// USB Mass Storage Application
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
/**
|
sl@0
|
19 |
@file
|
sl@0
|
20 |
*/
|
sl@0
|
21 |
|
sl@0
|
22 |
#include "general.h"
|
sl@0
|
23 |
#include "config.h"
|
sl@0
|
24 |
#include "activecontrol.h"
|
sl@0
|
25 |
|
sl@0
|
26 |
#include <usbmsshared.h>
|
sl@0
|
27 |
#include <massstorage.h>
|
sl@0
|
28 |
|
sl@0
|
29 |
#include "usbms.h"
|
sl@0
|
30 |
|
sl@0
|
31 |
extern CActiveControl* gActiveControl;
|
sl@0
|
32 |
extern RTest test;
|
sl@0
|
33 |
extern TBool gVerbose;
|
sl@0
|
34 |
extern TBool gSkip;
|
sl@0
|
35 |
extern TBool gTempTest;
|
sl@0
|
36 |
|
sl@0
|
37 |
|
sl@0
|
38 |
LOCAL_D RFs fs;
|
sl@0
|
39 |
LOCAL_D TBuf<0x40> mountList;
|
sl@0
|
40 |
|
sl@0
|
41 |
LOCAL_D TFixedArray<TBool, KMaxDrives> msfsMountedList; ///< 'true' entry corresponds to the drive with mounted MSFS.FSY
|
sl@0
|
42 |
LOCAL_D TFixedArray<CFileSystemDescriptor*, KMaxDrives> unmountedFsList; ///< every non-NULL entry corresponds to the unmounted original FS for the drive
|
sl@0
|
43 |
|
sl@0
|
44 |
LOCAL_D RUsbMassStorage UsbMs;
|
sl@0
|
45 |
|
sl@0
|
46 |
LOCAL_D CUsbWatch * usbWatch;
|
sl@0
|
47 |
|
sl@0
|
48 |
static const TUint KNumPropWatch = 4;
|
sl@0
|
49 |
LOCAL_D CPropertyWatch * propWatch[KNumPropWatch];
|
sl@0
|
50 |
|
sl@0
|
51 |
_LIT(KMsFsy, "MSFS.FSY");
|
sl@0
|
52 |
_LIT(KMsFs, "MassStorageFileSystem");
|
sl@0
|
53 |
_LIT(KOk,"OK");
|
sl@0
|
54 |
_LIT(KError,"Error");
|
sl@0
|
55 |
_LIT(KBytesTransferredFmt, "%c:%d/%d \n");
|
sl@0
|
56 |
_LIT(KErrFmt, "Error: %d\r");
|
sl@0
|
57 |
_LIT(KConfigured,"Configured");
|
sl@0
|
58 |
_LIT(KNotConfigured,"NOT Configured");
|
sl@0
|
59 |
|
sl@0
|
60 |
|
sl@0
|
61 |
_LIT8(KDefPwd,"123");
|
sl@0
|
62 |
TMediaPassword password(KDefPwd);
|
sl@0
|
63 |
|
sl@0
|
64 |
//-----------------------------------------------------------------------------
|
sl@0
|
65 |
|
sl@0
|
66 |
CFileSystemDescriptor::~CFileSystemDescriptor()
|
sl@0
|
67 |
{
|
sl@0
|
68 |
iFsName.Close();
|
sl@0
|
69 |
iPrimaryExtName.Close();
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
//-----------------------------------------------------------------------------
|
sl@0
|
73 |
CFileSystemDescriptor* CFileSystemDescriptor::NewL(const TDesC& aFsName, const TDesC& aPrimaryExtName, TBool aDrvSynch)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
CFileSystemDescriptor* pSelf = new (ELeave) CFileSystemDescriptor;
|
sl@0
|
76 |
|
sl@0
|
77 |
CleanupStack::PushL(pSelf);
|
sl@0
|
78 |
|
sl@0
|
79 |
pSelf->iFsName.CreateMaxL(aFsName.Length());
|
sl@0
|
80 |
pSelf->iFsName.Copy(aFsName);
|
sl@0
|
81 |
|
sl@0
|
82 |
pSelf->iPrimaryExtName.CreateMaxL(aPrimaryExtName.Length());
|
sl@0
|
83 |
pSelf->iPrimaryExtName.Copy(aPrimaryExtName);
|
sl@0
|
84 |
|
sl@0
|
85 |
pSelf->iDriveSynch = aDrvSynch;
|
sl@0
|
86 |
|
sl@0
|
87 |
CleanupStack::Pop();
|
sl@0
|
88 |
|
sl@0
|
89 |
return pSelf;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
|
sl@0
|
92 |
//-----------------------------------------------------------------------------
|
sl@0
|
93 |
/**
|
sl@0
|
94 |
Dismounts the originally mounted FS and optional primary extension from the drive and stores
|
sl@0
|
95 |
this information in the FS descriptor
|
sl@0
|
96 |
|
sl@0
|
97 |
@return on success returns a pointer to the instantinated FS descriptor
|
sl@0
|
98 |
*/
|
sl@0
|
99 |
LOCAL_C CFileSystemDescriptor* DoDismountOrginalFS(RFs& aFs, TInt aDrive)
|
sl@0
|
100 |
{
|
sl@0
|
101 |
TInt nRes;
|
sl@0
|
102 |
TBuf<128> fsName;
|
sl@0
|
103 |
TBuf<128> primaryExtName;
|
sl@0
|
104 |
TBool bDrvSync = EFalse;
|
sl@0
|
105 |
|
sl@0
|
106 |
test.Printf(_L("DoDismountOrginalFS drv:%d\n"), aDrive);
|
sl@0
|
107 |
|
sl@0
|
108 |
//-- 1. get file system name
|
sl@0
|
109 |
nRes = aFs.FileSystemName(fsName, aDrive);
|
sl@0
|
110 |
if(nRes != KErrNone)
|
sl@0
|
111 |
{//-- probably no file system installed at all
|
sl@0
|
112 |
return NULL;
|
sl@0
|
113 |
}
|
sl@0
|
114 |
|
sl@0
|
115 |
//-- 2. find out if the drive sync/async
|
sl@0
|
116 |
TPckgBuf<TBool> drvSyncBuf;
|
sl@0
|
117 |
nRes = aFs.QueryVolumeInfoExt(aDrive, EIsDriveSync, drvSyncBuf);
|
sl@0
|
118 |
if(nRes == KErrNone)
|
sl@0
|
119 |
{
|
sl@0
|
120 |
bDrvSync = drvSyncBuf();
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
//-- 3. find out primary extension name if it is present; we will need to add it againt when mounting the FS
|
sl@0
|
124 |
//-- other extensions (non-primary) are not supported yet
|
sl@0
|
125 |
nRes = aFs.ExtensionName(primaryExtName, aDrive, 0);
|
sl@0
|
126 |
if(nRes != KErrNone)
|
sl@0
|
127 |
{
|
sl@0
|
128 |
primaryExtName.SetLength(0);
|
sl@0
|
129 |
}
|
sl@0
|
130 |
|
sl@0
|
131 |
//-- 3.1 check if the drive has non-primary extensions, fail in this case, because this FS can't be mounted back normally
|
sl@0
|
132 |
nRes = aFs.ExtensionName(primaryExtName, aDrive, 1);
|
sl@0
|
133 |
if(nRes == KErrNone)
|
sl@0
|
134 |
{
|
sl@0
|
135 |
test.Printf(_L("DoDismountOrginalFS Non-primary extensions are not supported!\n"));
|
sl@0
|
136 |
return NULL;
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
test.Printf(_L("DoDismountOrginalFS FS:%S, Prim ext:%S, synch:%d\n"), &fsName, &primaryExtName, bDrvSync);
|
sl@0
|
140 |
|
sl@0
|
141 |
//-- create FS descriptor and dismount the FS
|
sl@0
|
142 |
CFileSystemDescriptor* pFsDesc = NULL;
|
sl@0
|
143 |
|
sl@0
|
144 |
TRAP(nRes, pFsDesc = CFileSystemDescriptor::NewL(fsName, primaryExtName, bDrvSync));
|
sl@0
|
145 |
if(nRes != KErrNone)
|
sl@0
|
146 |
return NULL; //-- OOM ?
|
sl@0
|
147 |
|
sl@0
|
148 |
nRes = aFs.DismountFileSystem(fsName, aDrive);
|
sl@0
|
149 |
if(nRes != KErrNone)
|
sl@0
|
150 |
{
|
sl@0
|
151 |
delete pFsDesc;
|
sl@0
|
152 |
pFsDesc = NULL;
|
sl@0
|
153 |
test.Printf(_L("DoDismountOrginalFS Dismounting Err:%d\n"), nRes);
|
sl@0
|
154 |
}
|
sl@0
|
155 |
|
sl@0
|
156 |
return pFsDesc;
|
sl@0
|
157 |
}
|
sl@0
|
158 |
|
sl@0
|
159 |
//-----------------------------------------------------------------------------
|
sl@0
|
160 |
/**
|
sl@0
|
161 |
Tries to restore the original FS on the drive using the FS descriptor provided
|
sl@0
|
162 |
@return standard error code.
|
sl@0
|
163 |
*/
|
sl@0
|
164 |
LOCAL_C TInt DoRestoreFS(RFs& aFs, TInt aDrive, CFileSystemDescriptor* apFsDesc)
|
sl@0
|
165 |
{
|
sl@0
|
166 |
TInt nRes;
|
sl@0
|
167 |
|
sl@0
|
168 |
test.Printf(_L("DoRestoreFS drv:%d\n"), aDrive);
|
sl@0
|
169 |
|
sl@0
|
170 |
//-- 1. check that there is no FS installed
|
sl@0
|
171 |
TBuf<128> fsName;
|
sl@0
|
172 |
nRes = aFs.FileSystemName(fsName, aDrive);
|
sl@0
|
173 |
if(nRes == KErrNone)
|
sl@0
|
174 |
{//-- there is a file system already installed
|
sl@0
|
175 |
test.Printf(_L("DoRestoreFS This drive already has FS intalled:%S \n"), &fsName);
|
sl@0
|
176 |
return KErrAlreadyExists;
|
sl@0
|
177 |
}
|
sl@0
|
178 |
|
sl@0
|
179 |
TPtrC ptrN (apFsDesc->FsName());
|
sl@0
|
180 |
TPtrC ptrExt(apFsDesc->PrimaryExtName());
|
sl@0
|
181 |
test.Printf(_L("DoRestoreFS Mounting FS:%S, Prim ext:%S, synch:%d\n"), &ptrN, &ptrExt, apFsDesc->DriveIsSynch());
|
sl@0
|
182 |
|
sl@0
|
183 |
if(ptrExt.Length() >0)
|
sl@0
|
184 |
{//-- there is a primary extension to be mounted
|
sl@0
|
185 |
nRes = aFs.AddExtension(ptrExt);
|
sl@0
|
186 |
if(nRes != KErrNone && nRes != KErrAlreadyExists)
|
sl@0
|
187 |
{
|
sl@0
|
188 |
return nRes;
|
sl@0
|
189 |
}
|
sl@0
|
190 |
|
sl@0
|
191 |
nRes = aFs.MountFileSystem(ptrN, ptrExt, aDrive, apFsDesc->DriveIsSynch());
|
sl@0
|
192 |
}
|
sl@0
|
193 |
else
|
sl@0
|
194 |
{
|
sl@0
|
195 |
nRes = aFs.MountFileSystem(ptrN, aDrive, apFsDesc->DriveIsSynch());
|
sl@0
|
196 |
}
|
sl@0
|
197 |
|
sl@0
|
198 |
if(nRes != KErrNone)
|
sl@0
|
199 |
{
|
sl@0
|
200 |
test.Printf(_L("DoRestoreFS Mount failed! code:%d\n"),nRes);
|
sl@0
|
201 |
}
|
sl@0
|
202 |
|
sl@0
|
203 |
return nRes;
|
sl@0
|
204 |
}
|
sl@0
|
205 |
|
sl@0
|
206 |
|
sl@0
|
207 |
//-----------------------------------------------------------------------------
|
sl@0
|
208 |
/**
|
sl@0
|
209 |
Dismount the original FS from the drive and mount MsFS instead
|
sl@0
|
210 |
*/
|
sl@0
|
211 |
LOCAL_C void MountMsFs(TInt driveNumber)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
test.Printf(_L("MountMsFs driveNumber=%d\n"), driveNumber);
|
sl@0
|
214 |
|
sl@0
|
215 |
//-- 1. try dismounting the original FS
|
sl@0
|
216 |
CFileSystemDescriptor* fsDesc = DoDismountOrginalFS(fs, driveNumber);
|
sl@0
|
217 |
unmountedFsList[driveNumber] = fsDesc;
|
sl@0
|
218 |
|
sl@0
|
219 |
if(fsDesc)
|
sl@0
|
220 |
{
|
sl@0
|
221 |
TPtrC ptrN(fsDesc->FsName());
|
sl@0
|
222 |
test.Printf(_L("drv:%d FS:%S Dismounted OK\n"),driveNumber, &ptrN);
|
sl@0
|
223 |
}
|
sl@0
|
224 |
else
|
sl@0
|
225 |
{
|
sl@0
|
226 |
test.Printf(_L("drv:%d Dismount FS Failed!\n"),driveNumber);
|
sl@0
|
227 |
}
|
sl@0
|
228 |
|
sl@0
|
229 |
//-- 2. try to mount the "MSFS"
|
sl@0
|
230 |
TInt error;
|
sl@0
|
231 |
error = fs.MountFileSystem(KMsFs, driveNumber);
|
sl@0
|
232 |
test.Printf(_L("MSFS Mount: %S (%d)\n"), (error?&KError:&KOk), error);
|
sl@0
|
233 |
if (!error)
|
sl@0
|
234 |
msfsMountedList[driveNumber] = ETrue;
|
sl@0
|
235 |
|
sl@0
|
236 |
}
|
sl@0
|
237 |
|
sl@0
|
238 |
//-----------------------------------------------------------------------------
|
sl@0
|
239 |
/**
|
sl@0
|
240 |
Dismount MsFS and mount the original FS
|
sl@0
|
241 |
*/
|
sl@0
|
242 |
LOCAL_C TInt RestoreMount(TInt driveNumber)
|
sl@0
|
243 |
{
|
sl@0
|
244 |
TInt err = KErrNone;
|
sl@0
|
245 |
|
sl@0
|
246 |
//-- 1. try dismounting the "MSFS"
|
sl@0
|
247 |
if (msfsMountedList[driveNumber])
|
sl@0
|
248 |
{
|
sl@0
|
249 |
err = fs.DismountFileSystem(KMsFs, driveNumber);
|
sl@0
|
250 |
test.Printf(_L("MSFS Dismount:%S (%d)\n"), (err?&KError:&KOk), err);
|
sl@0
|
251 |
if (err)
|
sl@0
|
252 |
return err;
|
sl@0
|
253 |
|
sl@0
|
254 |
msfsMountedList[driveNumber] = EFalse;
|
sl@0
|
255 |
}
|
sl@0
|
256 |
|
sl@0
|
257 |
//-- 2. try to mount the original FS back
|
sl@0
|
258 |
CFileSystemDescriptor* fsDesc = unmountedFsList[driveNumber];
|
sl@0
|
259 |
if(fsDesc)
|
sl@0
|
260 |
{
|
sl@0
|
261 |
err = DoRestoreFS(fs, driveNumber, fsDesc);
|
sl@0
|
262 |
|
sl@0
|
263 |
TPtrC ptrN(fsDesc->FsName());
|
sl@0
|
264 |
test.Printf(_L("%S Mount: %S (%d)\n"), &ptrN, (err?&KError:&KOk), err);
|
sl@0
|
265 |
|
sl@0
|
266 |
delete fsDesc;
|
sl@0
|
267 |
unmountedFsList[driveNumber] = NULL;
|
sl@0
|
268 |
}
|
sl@0
|
269 |
|
sl@0
|
270 |
return err;
|
sl@0
|
271 |
}
|
sl@0
|
272 |
|
sl@0
|
273 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
274 |
//
|
sl@0
|
275 |
// CPropertyWatch
|
sl@0
|
276 |
// An active object that tracks changes to the KUsbMsDriveState properties
|
sl@0
|
277 |
//
|
sl@0
|
278 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
279 |
|
sl@0
|
280 |
CPropertyWatch* CPropertyWatch::NewLC(TUsbMsDriveState_Subkey aSubkey, PropertyHandlers::THandler aHandler)
|
sl@0
|
281 |
{
|
sl@0
|
282 |
CPropertyWatch* me=new(ELeave) CPropertyWatch(aHandler);
|
sl@0
|
283 |
CleanupStack::PushL (me);
|
sl@0
|
284 |
me->ConstructL(aSubkey);
|
sl@0
|
285 |
CleanupStack::Pop();
|
sl@0
|
286 |
return me;
|
sl@0
|
287 |
}
|
sl@0
|
288 |
|
sl@0
|
289 |
CPropertyWatch::CPropertyWatch(PropertyHandlers::THandler aHandler)
|
sl@0
|
290 |
: CActive(0), iHandler(aHandler)
|
sl@0
|
291 |
{}
|
sl@0
|
292 |
|
sl@0
|
293 |
void CPropertyWatch::ConstructL(TUsbMsDriveState_Subkey aSubkey)
|
sl@0
|
294 |
{
|
sl@0
|
295 |
User::LeaveIfError(iProperty.Attach(KUsbMsDriveState_Category, aSubkey));
|
sl@0
|
296 |
CActiveScheduler::Add(this);
|
sl@0
|
297 |
// initial subscription and process current property value
|
sl@0
|
298 |
RunL();
|
sl@0
|
299 |
}
|
sl@0
|
300 |
|
sl@0
|
301 |
CPropertyWatch::~CPropertyWatch()
|
sl@0
|
302 |
{
|
sl@0
|
303 |
Cancel();
|
sl@0
|
304 |
iProperty.Close();
|
sl@0
|
305 |
}
|
sl@0
|
306 |
|
sl@0
|
307 |
void CPropertyWatch::DoCancel()
|
sl@0
|
308 |
{
|
sl@0
|
309 |
iProperty.Cancel();
|
sl@0
|
310 |
}
|
sl@0
|
311 |
|
sl@0
|
312 |
void CPropertyWatch::RunL()
|
sl@0
|
313 |
{
|
sl@0
|
314 |
// resubscribe before processing new value to prevent missing updates
|
sl@0
|
315 |
iProperty.Subscribe(iStatus);
|
sl@0
|
316 |
SetActive();
|
sl@0
|
317 |
|
sl@0
|
318 |
iHandler(iProperty);
|
sl@0
|
319 |
}
|
sl@0
|
320 |
|
sl@0
|
321 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
322 |
//
|
sl@0
|
323 |
// CUsbWatch
|
sl@0
|
324 |
//
|
sl@0
|
325 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
326 |
|
sl@0
|
327 |
CUsbWatch* CUsbWatch::NewLC(RUsb& aUsb)
|
sl@0
|
328 |
{
|
sl@0
|
329 |
CUsbWatch* me=new(ELeave) CUsbWatch(aUsb);
|
sl@0
|
330 |
CleanupStack::PushL (me);
|
sl@0
|
331 |
me->ConstructL();
|
sl@0
|
332 |
CleanupStack::Pop();
|
sl@0
|
333 |
return me;
|
sl@0
|
334 |
}
|
sl@0
|
335 |
|
sl@0
|
336 |
CUsbWatch::CUsbWatch(RUsb& aUsb)
|
sl@0
|
337 |
:
|
sl@0
|
338 |
CActive(0),
|
sl@0
|
339 |
iUsb(aUsb),
|
sl@0
|
340 |
iUsbDeviceState(EUsbcDeviceStateUndefined),
|
sl@0
|
341 |
iWasConfigured(EFalse)
|
sl@0
|
342 |
{}
|
sl@0
|
343 |
|
sl@0
|
344 |
void CUsbWatch::ConstructL()
|
sl@0
|
345 |
{
|
sl@0
|
346 |
CActiveScheduler::Add(this);
|
sl@0
|
347 |
RunL();
|
sl@0
|
348 |
}
|
sl@0
|
349 |
|
sl@0
|
350 |
CUsbWatch::~CUsbWatch()
|
sl@0
|
351 |
{
|
sl@0
|
352 |
Cancel();
|
sl@0
|
353 |
iUsb.AlternateDeviceStatusNotifyCancel();
|
sl@0
|
354 |
}
|
sl@0
|
355 |
|
sl@0
|
356 |
void CUsbWatch::DoCancel()
|
sl@0
|
357 |
{
|
sl@0
|
358 |
iUsb.AlternateDeviceStatusNotifyCancel();
|
sl@0
|
359 |
}
|
sl@0
|
360 |
|
sl@0
|
361 |
static TBool IsDriveConnected(TInt driveStatusIndex)
|
sl@0
|
362 |
{
|
sl@0
|
363 |
TInt driveStatus = PropertyHandlers::allDrivesStatus[2*driveStatusIndex+1];
|
sl@0
|
364 |
return driveStatus >= EUsbMsDriveState_Connected ? ETrue : EFalse;
|
sl@0
|
365 |
}
|
sl@0
|
366 |
|
sl@0
|
367 |
static TChar DriveNumberToLetter(TInt driveNumber)
|
sl@0
|
368 |
{
|
sl@0
|
369 |
TChar driveLetter = '?';
|
sl@0
|
370 |
fs.DriveToChar(driveNumber, driveLetter);
|
sl@0
|
371 |
return driveLetter;
|
sl@0
|
372 |
}
|
sl@0
|
373 |
|
sl@0
|
374 |
static TBool IsDriveInMountList(TUint driveLetter)
|
sl@0
|
375 |
{
|
sl@0
|
376 |
TUint16 driveLetter16 = static_cast<TUint16>(driveLetter);
|
sl@0
|
377 |
return(!mountList.Length() || KErrNotFound != mountList.Find(&driveLetter16, 1));
|
sl@0
|
378 |
}
|
sl@0
|
379 |
|
sl@0
|
380 |
void CUsbWatch::RunL()
|
sl@0
|
381 |
{
|
sl@0
|
382 |
gActiveControl->SetMSFinished(EFalse);
|
sl@0
|
383 |
if (gVerbose)
|
sl@0
|
384 |
{
|
sl@0
|
385 |
switch (iUsbDeviceState)
|
sl@0
|
386 |
{
|
sl@0
|
387 |
case EUsbcDeviceStateUndefined : // 0
|
sl@0
|
388 |
test.Printf(_L(">> CUSBWatch:Undefined %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
|
sl@0
|
389 |
break;
|
sl@0
|
390 |
|
sl@0
|
391 |
case EUsbcDeviceStateAttached : // 1
|
sl@0
|
392 |
test.Printf(_L(">> CUSBWatch:Attached %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
|
sl@0
|
393 |
break;
|
sl@0
|
394 |
|
sl@0
|
395 |
case EUsbcDeviceStatePowered : // 2
|
sl@0
|
396 |
test.Printf(_L(">> CUSBWatch:Powered %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
|
sl@0
|
397 |
break;
|
sl@0
|
398 |
|
sl@0
|
399 |
case EUsbcDeviceStateDefault : // 3
|
sl@0
|
400 |
test.Printf(_L(">> CUSBWatch:Default %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
|
sl@0
|
401 |
break;
|
sl@0
|
402 |
|
sl@0
|
403 |
case EUsbcDeviceStateAddress : // 4
|
sl@0
|
404 |
test.Printf(_L(">> CUSBWatch:Address %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
|
sl@0
|
405 |
break;
|
sl@0
|
406 |
|
sl@0
|
407 |
case EUsbcDeviceStateConfigured : // 5
|
sl@0
|
408 |
test.Printf(_L(">> CUSBWatch:Configured %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
|
sl@0
|
409 |
break;
|
sl@0
|
410 |
|
sl@0
|
411 |
case EUsbcDeviceStateSuspended : // 6
|
sl@0
|
412 |
test.Printf(_L(">> CUSBWatch:Suspended %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
|
sl@0
|
413 |
break;
|
sl@0
|
414 |
|
sl@0
|
415 |
default :
|
sl@0
|
416 |
test.Printf(_L(">> CUSBWatch:UNKNOWN %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
|
sl@0
|
417 |
break;
|
sl@0
|
418 |
|
sl@0
|
419 |
}
|
sl@0
|
420 |
}
|
sl@0
|
421 |
iUsb.AlternateDeviceStatusNotify(iStatus, iUsbDeviceState);
|
sl@0
|
422 |
SetActive();
|
sl@0
|
423 |
|
sl@0
|
424 |
// If the cable is disconnected, unmount all the connected drives.
|
sl@0
|
425 |
if(iWasConfigured && iUsbDeviceState == EUsbcDeviceStateUndefined)
|
sl@0
|
426 |
{
|
sl@0
|
427 |
for(TInt i=0; i<PropertyHandlers::allDrivesStatus.Length()/2; i++)
|
sl@0
|
428 |
{
|
sl@0
|
429 |
if(IsDriveConnected(i))
|
sl@0
|
430 |
{
|
sl@0
|
431 |
RDebug::Print(_L("CUsbWatch calling RestoreMount"));
|
sl@0
|
432 |
RestoreMount(PropertyHandlers::allDrivesStatus[2*i]);
|
sl@0
|
433 |
}
|
sl@0
|
434 |
}
|
sl@0
|
435 |
|
sl@0
|
436 |
iWasConfigured = EFalse;
|
sl@0
|
437 |
}
|
sl@0
|
438 |
|
sl@0
|
439 |
// If cable is connected, mount all drives in the auto-mount list.
|
sl@0
|
440 |
// This is done for performance, since if this is not done here,
|
sl@0
|
441 |
// mounting will happen later after each drive enters the
|
sl@0
|
442 |
// Connecting state.
|
sl@0
|
443 |
if(iUsbDeviceState == EUsbcDeviceStateConfigured)
|
sl@0
|
444 |
{
|
sl@0
|
445 |
for(TInt i=0; i<PropertyHandlers::allDrivesStatus.Length()/2; i++)
|
sl@0
|
446 |
{
|
sl@0
|
447 |
TInt driveNumber = PropertyHandlers::allDrivesStatus[2*i];
|
sl@0
|
448 |
if(!IsDriveConnected(i) && IsDriveInMountList(DriveNumberToLetter(driveNumber)))
|
sl@0
|
449 |
{
|
sl@0
|
450 |
RDebug::Print(_L("CUsbWatch calling MountMsFs"));
|
sl@0
|
451 |
MountMsFs(driveNumber);
|
sl@0
|
452 |
}
|
sl@0
|
453 |
}
|
sl@0
|
454 |
|
sl@0
|
455 |
iWasConfigured = ETrue;
|
sl@0
|
456 |
}
|
sl@0
|
457 |
}
|
sl@0
|
458 |
|
sl@0
|
459 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
460 |
//
|
sl@0
|
461 |
// PropertyHandlers
|
sl@0
|
462 |
//
|
sl@0
|
463 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
464 |
|
sl@0
|
465 |
TBuf8<16> PropertyHandlers::allDrivesStatus;
|
sl@0
|
466 |
TUsbMsBytesTransferred PropertyHandlers::iKBytesRead;
|
sl@0
|
467 |
TUsbMsBytesTransferred PropertyHandlers::iKBytesWritten;
|
sl@0
|
468 |
TInt PropertyHandlers::iMediaError;
|
sl@0
|
469 |
|
sl@0
|
470 |
void PropertyHandlers::Read(RProperty& aProperty)
|
sl@0
|
471 |
{
|
sl@0
|
472 |
Transferred(aProperty, iKBytesRead);
|
sl@0
|
473 |
}
|
sl@0
|
474 |
|
sl@0
|
475 |
void PropertyHandlers::Written(RProperty& aProperty)
|
sl@0
|
476 |
{
|
sl@0
|
477 |
Transferred(aProperty, iKBytesWritten);
|
sl@0
|
478 |
}
|
sl@0
|
479 |
|
sl@0
|
480 |
void PropertyHandlers::Transferred(RProperty& aProperty, TUsbMsBytesTransferred& aReadOrWritten)
|
sl@0
|
481 |
{
|
sl@0
|
482 |
TInt err = aProperty.Get(aReadOrWritten);
|
sl@0
|
483 |
if(err == KErrNone)
|
sl@0
|
484 |
{
|
sl@0
|
485 |
for(TInt i = 0; i < allDrivesStatus.Length()/2; i++)
|
sl@0
|
486 |
{
|
sl@0
|
487 |
if (gVerbose)
|
sl@0
|
488 |
{
|
sl@0
|
489 |
test.Printf(KBytesTransferredFmt,
|
sl@0
|
490 |
(char)DriveNumberToLetter(allDrivesStatus[2*i]), iKBytesRead[i], iKBytesWritten[i]);
|
sl@0
|
491 |
}
|
sl@0
|
492 |
}
|
sl@0
|
493 |
}
|
sl@0
|
494 |
else
|
sl@0
|
495 |
{
|
sl@0
|
496 |
test.Printf(KErrFmt, err);
|
sl@0
|
497 |
}
|
sl@0
|
498 |
}
|
sl@0
|
499 |
|
sl@0
|
500 |
void PropertyHandlers::DriveStatus(RProperty& aProperty)
|
sl@0
|
501 |
{
|
sl@0
|
502 |
if (gVerbose)
|
sl@0
|
503 |
{
|
sl@0
|
504 |
test.Printf(_L(">> PropertyHandlers::DriveStatus"));
|
sl@0
|
505 |
}
|
sl@0
|
506 |
TInt err = aProperty.Get(allDrivesStatus);
|
sl@0
|
507 |
if(err == KErrNone)
|
sl@0
|
508 |
{
|
sl@0
|
509 |
if (gVerbose)
|
sl@0
|
510 |
{
|
sl@0
|
511 |
test.Printf(_L(" Status: "));
|
sl@0
|
512 |
}
|
sl@0
|
513 |
for(TInt i = 0; i < allDrivesStatus.Length()/2; i++)
|
sl@0
|
514 |
{
|
sl@0
|
515 |
TInt driveNumber = allDrivesStatus[2*i];
|
sl@0
|
516 |
TInt driveStatus = allDrivesStatus[2*i+1];
|
sl@0
|
517 |
TChar driveLetter = DriveNumberToLetter(driveNumber);
|
sl@0
|
518 |
|
sl@0
|
519 |
if (gVerbose)
|
sl@0
|
520 |
{
|
sl@0
|
521 |
switch(driveStatus)
|
sl@0
|
522 |
{
|
sl@0
|
523 |
case EUsbMsDriveState_Disconnected:
|
sl@0
|
524 |
{
|
sl@0
|
525 |
test.Printf(_L("%c:%d:Disconnected\n"), (char)driveLetter, driveStatus);
|
sl@0
|
526 |
break;
|
sl@0
|
527 |
}
|
sl@0
|
528 |
case EUsbMsDriveState_Connecting:
|
sl@0
|
529 |
{
|
sl@0
|
530 |
test.Printf(_L("%c:%d:Connecting\n"), (char)driveLetter, driveStatus);
|
sl@0
|
531 |
break;
|
sl@0
|
532 |
}
|
sl@0
|
533 |
case EUsbMsDriveState_Connected:
|
sl@0
|
534 |
{
|
sl@0
|
535 |
test.Printf(_L("%c:%d:Connected\n"), (char)driveLetter, driveStatus);
|
sl@0
|
536 |
break;
|
sl@0
|
537 |
}
|
sl@0
|
538 |
case EUsbMsDriveState_Disconnecting:
|
sl@0
|
539 |
{
|
sl@0
|
540 |
test.Printf(_L("%c:%d:Disconnecting\n"), (char)driveLetter, driveStatus);
|
sl@0
|
541 |
break;
|
sl@0
|
542 |
}
|
sl@0
|
543 |
case EUsbMsDriveState_Active:
|
sl@0
|
544 |
{
|
sl@0
|
545 |
test.Printf(_L("%c:%d:Active\n"), (char)driveLetter, driveStatus);
|
sl@0
|
546 |
break;
|
sl@0
|
547 |
}
|
sl@0
|
548 |
case EUsbMsDriveState_Locked:
|
sl@0
|
549 |
{
|
sl@0
|
550 |
test.Printf(_L("%c:%d:Locked\n"), (char)driveLetter, driveStatus);
|
sl@0
|
551 |
break;
|
sl@0
|
552 |
}
|
sl@0
|
553 |
case EUsbMsDriveState_MediaNotPresent:
|
sl@0
|
554 |
{
|
sl@0
|
555 |
test.Printf(_L("%c:%d:Not Present\n"), (char)driveLetter, driveStatus);
|
sl@0
|
556 |
break;
|
sl@0
|
557 |
}
|
sl@0
|
558 |
case EUsbMsDriveState_Removed:
|
sl@0
|
559 |
{
|
sl@0
|
560 |
test.Printf(_L("%c:%d:Removed\n"), (char)driveLetter, driveStatus);
|
sl@0
|
561 |
break;
|
sl@0
|
562 |
}
|
sl@0
|
563 |
case EUsbMsDriveState_Error:
|
sl@0
|
564 |
{
|
sl@0
|
565 |
test.Printf(_L("%c:%d:Error\n"), (char)driveLetter, driveStatus);
|
sl@0
|
566 |
break;
|
sl@0
|
567 |
}
|
sl@0
|
568 |
default :
|
sl@0
|
569 |
{
|
sl@0
|
570 |
test.Printf(_L("%c:%d:Unknown\n"), (char)driveLetter, driveStatus);
|
sl@0
|
571 |
break;
|
sl@0
|
572 |
}
|
sl@0
|
573 |
}
|
sl@0
|
574 |
}
|
sl@0
|
575 |
|
sl@0
|
576 |
if (driveStatus == EUsbMsDriveState_Connected)
|
sl@0
|
577 |
{
|
sl@0
|
578 |
gActiveControl->SetMSFinished(EFalse);
|
sl@0
|
579 |
}
|
sl@0
|
580 |
if (driveStatus == EUsbMsDriveState_Disconnected)
|
sl@0
|
581 |
{
|
sl@0
|
582 |
gActiveControl->SetMSFinished(ETrue);
|
sl@0
|
583 |
}
|
sl@0
|
584 |
if(IsDriveInMountList(driveLetter))
|
sl@0
|
585 |
{
|
sl@0
|
586 |
if (driveStatus == EUsbMsDriveState_Connecting)
|
sl@0
|
587 |
{
|
sl@0
|
588 |
MountMsFs(driveNumber);
|
sl@0
|
589 |
}
|
sl@0
|
590 |
else if (driveStatus == EUsbMsDriveState_Disconnecting)
|
sl@0
|
591 |
{
|
sl@0
|
592 |
RestoreMount(driveNumber);
|
sl@0
|
593 |
}
|
sl@0
|
594 |
else
|
sl@0
|
595 |
{
|
sl@0
|
596 |
//RDebug::Print(_L("PropertyHandlers::DriveStatus: nothing to do"));
|
sl@0
|
597 |
}
|
sl@0
|
598 |
}
|
sl@0
|
599 |
else
|
sl@0
|
600 |
{
|
sl@0
|
601 |
//RDebug::Print(_L("PropertyHandlers::DriveStatus: %c: is not in mountList\n"), driveLetter);
|
sl@0
|
602 |
}
|
sl@0
|
603 |
}
|
sl@0
|
604 |
}
|
sl@0
|
605 |
else
|
sl@0
|
606 |
{
|
sl@0
|
607 |
test.Printf(KErrFmt, err);
|
sl@0
|
608 |
}
|
sl@0
|
609 |
|
sl@0
|
610 |
}
|
sl@0
|
611 |
|
sl@0
|
612 |
void PropertyHandlers::MediaError(RProperty& aProperty)
|
sl@0
|
613 |
{
|
sl@0
|
614 |
TInt r = aProperty.Get(iMediaError);
|
sl@0
|
615 |
if(r != KErrNone)
|
sl@0
|
616 |
{
|
sl@0
|
617 |
return;
|
sl@0
|
618 |
}
|
sl@0
|
619 |
|
sl@0
|
620 |
test.Printf(_L("Media Error %x\n"), iMediaError);
|
sl@0
|
621 |
if (iMediaError > 0)
|
sl@0
|
622 |
{
|
sl@0
|
623 |
gActiveControl->SetMSFinished(ETrue);
|
sl@0
|
624 |
}
|
sl@0
|
625 |
}
|
sl@0
|
626 |
|
sl@0
|
627 |
|
sl@0
|
628 |
void StartMassStorage(RDEVCLIENT* aPort)
|
sl@0
|
629 |
{
|
sl@0
|
630 |
TInt r = KErrUnknown;
|
sl@0
|
631 |
|
sl@0
|
632 |
test.Start (_L("Start Mass Storage"));
|
sl@0
|
633 |
|
sl@0
|
634 |
fs.Connect();
|
sl@0
|
635 |
|
sl@0
|
636 |
// Add MS file system
|
sl@0
|
637 |
test.Next (_L("Add MS File System"));
|
sl@0
|
638 |
r = fs.AddFileSystem(KMsFsy);
|
sl@0
|
639 |
test(r == KErrNone || r == KErrAlreadyExists);
|
sl@0
|
640 |
|
sl@0
|
641 |
#ifdef USB_SC
|
sl@0
|
642 |
aPort->FinalizeInterface();
|
sl@0
|
643 |
#endif
|
sl@0
|
644 |
|
sl@0
|
645 |
|
sl@0
|
646 |
test.Next (_L("Create active objects\n"));
|
sl@0
|
647 |
propWatch[0] = CPropertyWatch::NewLC(EUsbMsDriveState_KBytesRead, PropertyHandlers::Read);
|
sl@0
|
648 |
propWatch[1] = CPropertyWatch::NewLC(EUsbMsDriveState_KBytesWritten, PropertyHandlers::Written);
|
sl@0
|
649 |
propWatch[2] = CPropertyWatch::NewLC(EUsbMsDriveState_DriveStatus, PropertyHandlers::DriveStatus);
|
sl@0
|
650 |
propWatch[3] = CPropertyWatch::NewLC(EUsbMsDriveState_MediaError, PropertyHandlers::MediaError);
|
sl@0
|
651 |
usbWatch = CUsbWatch::NewLC(*aPort);
|
sl@0
|
652 |
|
sl@0
|
653 |
TBuf<8> t_vendorId(_L("vendor"));
|
sl@0
|
654 |
TBuf<16> t_productId(_L("product"));
|
sl@0
|
655 |
TBuf<4> t_productRev(_L("1.00"));
|
sl@0
|
656 |
|
sl@0
|
657 |
TMassStorageConfig msConfig;
|
sl@0
|
658 |
msConfig.iVendorId.Copy(t_vendorId);
|
sl@0
|
659 |
msConfig.iProductId.Copy(t_productId);
|
sl@0
|
660 |
msConfig.iProductRev.Copy(t_productRev);
|
sl@0
|
661 |
|
sl@0
|
662 |
test.Next(_L("Connect to Mass Storage"));
|
sl@0
|
663 |
r = UsbMs.Connect();
|
sl@0
|
664 |
test_KErrNone (r);
|
sl@0
|
665 |
|
sl@0
|
666 |
test.Next(_L("Start Mass Storage"));
|
sl@0
|
667 |
r = UsbMs.Start(msConfig);
|
sl@0
|
668 |
test_KErrNone (r);
|
sl@0
|
669 |
|
sl@0
|
670 |
test.End();
|
sl@0
|
671 |
}
|
sl@0
|
672 |
|
sl@0
|
673 |
void StopMassStorage(RDEVCLIENT* aPort)
|
sl@0
|
674 |
{
|
sl@0
|
675 |
TInt r = KErrUnknown;
|
sl@0
|
676 |
|
sl@0
|
677 |
test.Start (_L("Stop Mass Storage"));
|
sl@0
|
678 |
|
sl@0
|
679 |
r = UsbMs.Stop();
|
sl@0
|
680 |
test_KErrNone (r);
|
sl@0
|
681 |
UsbMs.Close();
|
sl@0
|
682 |
|
sl@0
|
683 |
for (TInt driveNumber = 0; driveNumber < KMaxDrives; driveNumber++)
|
sl@0
|
684 |
{
|
sl@0
|
685 |
if (msfsMountedList[driveNumber])
|
sl@0
|
686 |
{
|
sl@0
|
687 |
r = fs.DismountFileSystem(KMsFs, driveNumber);
|
sl@0
|
688 |
test_KErrNone (r);
|
sl@0
|
689 |
|
sl@0
|
690 |
msfsMountedList[driveNumber] = EFalse;
|
sl@0
|
691 |
}
|
sl@0
|
692 |
}
|
sl@0
|
693 |
|
sl@0
|
694 |
r = fs.RemoveFileSystem(KMsFs);
|
sl@0
|
695 |
test_KErrNone (r);
|
sl@0
|
696 |
|
sl@0
|
697 |
fs.Close();
|
sl@0
|
698 |
|
sl@0
|
699 |
delete usbWatch;
|
sl@0
|
700 |
for (TUint i =0; i < KNumPropWatch; i++)
|
sl@0
|
701 |
{
|
sl@0
|
702 |
delete propWatch[i];
|
sl@0
|
703 |
}
|
sl@0
|
704 |
|
sl@0
|
705 |
aPort->Close();
|
sl@0
|
706 |
|
sl@0
|
707 |
test.End();
|
sl@0
|
708 |
}
|
sl@0
|
709 |
|