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