1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/kernelhwsrv/kerneltest/e32test/usb/t_usb_device/src/usbms.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,709 @@
1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of the License "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// USB Mass Storage Application
1.18 +//
1.19 +//
1.20 +
1.21 +/**
1.22 + @file
1.23 +*/
1.24 +
1.25 +#include "general.h"
1.26 +#include "config.h"
1.27 +#include "activecontrol.h"
1.28 +
1.29 +#include <usbmsshared.h>
1.30 +#include <massstorage.h>
1.31 +
1.32 +#include "usbms.h"
1.33 +
1.34 +extern CActiveControl* gActiveControl;
1.35 +extern RTest test;
1.36 +extern TBool gVerbose;
1.37 +extern TBool gSkip;
1.38 +extern TBool gTempTest;
1.39 +
1.40 +
1.41 +LOCAL_D RFs fs;
1.42 +LOCAL_D TBuf<0x40> mountList;
1.43 +
1.44 +LOCAL_D TFixedArray<TBool, KMaxDrives> msfsMountedList; ///< 'true' entry corresponds to the drive with mounted MSFS.FSY
1.45 +LOCAL_D TFixedArray<CFileSystemDescriptor*, KMaxDrives> unmountedFsList; ///< every non-NULL entry corresponds to the unmounted original FS for the drive
1.46 +
1.47 +LOCAL_D RUsbMassStorage UsbMs;
1.48 +
1.49 +LOCAL_D CUsbWatch * usbWatch;
1.50 +
1.51 +static const TUint KNumPropWatch = 4;
1.52 +LOCAL_D CPropertyWatch * propWatch[KNumPropWatch];
1.53 +
1.54 +_LIT(KMsFsy, "MSFS.FSY");
1.55 +_LIT(KMsFs, "MassStorageFileSystem");
1.56 +_LIT(KOk,"OK");
1.57 +_LIT(KError,"Error");
1.58 +_LIT(KBytesTransferredFmt, "%c:%d/%d \n");
1.59 +_LIT(KErrFmt, "Error: %d\r");
1.60 +_LIT(KConfigured,"Configured");
1.61 +_LIT(KNotConfigured,"NOT Configured");
1.62 +
1.63 +
1.64 +_LIT8(KDefPwd,"123");
1.65 +TMediaPassword password(KDefPwd);
1.66 +
1.67 +//-----------------------------------------------------------------------------
1.68 +
1.69 +CFileSystemDescriptor::~CFileSystemDescriptor()
1.70 + {
1.71 + iFsName.Close();
1.72 + iPrimaryExtName.Close();
1.73 + }
1.74 +
1.75 +//-----------------------------------------------------------------------------
1.76 +CFileSystemDescriptor* CFileSystemDescriptor::NewL(const TDesC& aFsName, const TDesC& aPrimaryExtName, TBool aDrvSynch)
1.77 + {
1.78 + CFileSystemDescriptor* pSelf = new (ELeave) CFileSystemDescriptor;
1.79 +
1.80 + CleanupStack::PushL(pSelf);
1.81 +
1.82 + pSelf->iFsName.CreateMaxL(aFsName.Length());
1.83 + pSelf->iFsName.Copy(aFsName);
1.84 +
1.85 + pSelf->iPrimaryExtName.CreateMaxL(aPrimaryExtName.Length());
1.86 + pSelf->iPrimaryExtName.Copy(aPrimaryExtName);
1.87 +
1.88 + pSelf->iDriveSynch = aDrvSynch;
1.89 +
1.90 + CleanupStack::Pop();
1.91 +
1.92 + return pSelf;
1.93 + }
1.94 +
1.95 +//-----------------------------------------------------------------------------
1.96 +/**
1.97 + Dismounts the originally mounted FS and optional primary extension from the drive and stores
1.98 + this information in the FS descriptor
1.99 +
1.100 + @return on success returns a pointer to the instantinated FS descriptor
1.101 +*/
1.102 +LOCAL_C CFileSystemDescriptor* DoDismountOrginalFS(RFs& aFs, TInt aDrive)
1.103 + {
1.104 + TInt nRes;
1.105 + TBuf<128> fsName;
1.106 + TBuf<128> primaryExtName;
1.107 + TBool bDrvSync = EFalse;
1.108 +
1.109 + test.Printf(_L("DoDismountOrginalFS drv:%d\n"), aDrive);
1.110 +
1.111 + //-- 1. get file system name
1.112 + nRes = aFs.FileSystemName(fsName, aDrive);
1.113 + if(nRes != KErrNone)
1.114 + {//-- probably no file system installed at all
1.115 + return NULL;
1.116 + }
1.117 +
1.118 + //-- 2. find out if the drive sync/async
1.119 + TPckgBuf<TBool> drvSyncBuf;
1.120 + nRes = aFs.QueryVolumeInfoExt(aDrive, EIsDriveSync, drvSyncBuf);
1.121 + if(nRes == KErrNone)
1.122 + {
1.123 + bDrvSync = drvSyncBuf();
1.124 + }
1.125 +
1.126 + //-- 3. find out primary extension name if it is present; we will need to add it againt when mounting the FS
1.127 + //-- other extensions (non-primary) are not supported yet
1.128 + nRes = aFs.ExtensionName(primaryExtName, aDrive, 0);
1.129 + if(nRes != KErrNone)
1.130 + {
1.131 + primaryExtName.SetLength(0);
1.132 + }
1.133 +
1.134 + //-- 3.1 check if the drive has non-primary extensions, fail in this case, because this FS can't be mounted back normally
1.135 + nRes = aFs.ExtensionName(primaryExtName, aDrive, 1);
1.136 + if(nRes == KErrNone)
1.137 + {
1.138 + test.Printf(_L("DoDismountOrginalFS Non-primary extensions are not supported!\n"));
1.139 + return NULL;
1.140 + }
1.141 +
1.142 + test.Printf(_L("DoDismountOrginalFS FS:%S, Prim ext:%S, synch:%d\n"), &fsName, &primaryExtName, bDrvSync);
1.143 +
1.144 + //-- create FS descriptor and dismount the FS
1.145 + CFileSystemDescriptor* pFsDesc = NULL;
1.146 +
1.147 + TRAP(nRes, pFsDesc = CFileSystemDescriptor::NewL(fsName, primaryExtName, bDrvSync));
1.148 + if(nRes != KErrNone)
1.149 + return NULL; //-- OOM ?
1.150 +
1.151 + nRes = aFs.DismountFileSystem(fsName, aDrive);
1.152 + if(nRes != KErrNone)
1.153 + {
1.154 + delete pFsDesc;
1.155 + pFsDesc = NULL;
1.156 + test.Printf(_L("DoDismountOrginalFS Dismounting Err:%d\n"), nRes);
1.157 + }
1.158 +
1.159 + return pFsDesc;
1.160 +}
1.161 +
1.162 +//-----------------------------------------------------------------------------
1.163 +/**
1.164 + Tries to restore the original FS on the drive using the FS descriptor provided
1.165 + @return standard error code.
1.166 +*/
1.167 +LOCAL_C TInt DoRestoreFS(RFs& aFs, TInt aDrive, CFileSystemDescriptor* apFsDesc)
1.168 + {
1.169 + TInt nRes;
1.170 +
1.171 + test.Printf(_L("DoRestoreFS drv:%d\n"), aDrive);
1.172 +
1.173 + //-- 1. check that there is no FS installed
1.174 + TBuf<128> fsName;
1.175 + nRes = aFs.FileSystemName(fsName, aDrive);
1.176 + if(nRes == KErrNone)
1.177 + {//-- there is a file system already installed
1.178 + test.Printf(_L("DoRestoreFS This drive already has FS intalled:%S \n"), &fsName);
1.179 + return KErrAlreadyExists;
1.180 + }
1.181 +
1.182 + TPtrC ptrN (apFsDesc->FsName());
1.183 + TPtrC ptrExt(apFsDesc->PrimaryExtName());
1.184 + test.Printf(_L("DoRestoreFS Mounting FS:%S, Prim ext:%S, synch:%d\n"), &ptrN, &ptrExt, apFsDesc->DriveIsSynch());
1.185 +
1.186 + if(ptrExt.Length() >0)
1.187 + {//-- there is a primary extension to be mounted
1.188 + nRes = aFs.AddExtension(ptrExt);
1.189 + if(nRes != KErrNone && nRes != KErrAlreadyExists)
1.190 + {
1.191 + return nRes;
1.192 + }
1.193 +
1.194 + nRes = aFs.MountFileSystem(ptrN, ptrExt, aDrive, apFsDesc->DriveIsSynch());
1.195 + }
1.196 + else
1.197 + {
1.198 + nRes = aFs.MountFileSystem(ptrN, aDrive, apFsDesc->DriveIsSynch());
1.199 + }
1.200 +
1.201 + if(nRes != KErrNone)
1.202 + {
1.203 + test.Printf(_L("DoRestoreFS Mount failed! code:%d\n"),nRes);
1.204 + }
1.205 +
1.206 + return nRes;
1.207 + }
1.208 +
1.209 +
1.210 +//-----------------------------------------------------------------------------
1.211 +/**
1.212 + Dismount the original FS from the drive and mount MsFS instead
1.213 +*/
1.214 +LOCAL_C void MountMsFs(TInt driveNumber)
1.215 + {
1.216 + test.Printf(_L("MountMsFs driveNumber=%d\n"), driveNumber);
1.217 +
1.218 + //-- 1. try dismounting the original FS
1.219 + CFileSystemDescriptor* fsDesc = DoDismountOrginalFS(fs, driveNumber);
1.220 + unmountedFsList[driveNumber] = fsDesc;
1.221 +
1.222 + if(fsDesc)
1.223 + {
1.224 + TPtrC ptrN(fsDesc->FsName());
1.225 + test.Printf(_L("drv:%d FS:%S Dismounted OK\n"),driveNumber, &ptrN);
1.226 + }
1.227 + else
1.228 + {
1.229 + test.Printf(_L("drv:%d Dismount FS Failed!\n"),driveNumber);
1.230 + }
1.231 +
1.232 + //-- 2. try to mount the "MSFS"
1.233 + TInt error;
1.234 + error = fs.MountFileSystem(KMsFs, driveNumber);
1.235 + test.Printf(_L("MSFS Mount: %S (%d)\n"), (error?&KError:&KOk), error);
1.236 + if (!error)
1.237 + msfsMountedList[driveNumber] = ETrue;
1.238 +
1.239 + }
1.240 +
1.241 +//-----------------------------------------------------------------------------
1.242 +/**
1.243 + Dismount MsFS and mount the original FS
1.244 +*/
1.245 +LOCAL_C TInt RestoreMount(TInt driveNumber)
1.246 + {
1.247 + TInt err = KErrNone;
1.248 +
1.249 + //-- 1. try dismounting the "MSFS"
1.250 + if (msfsMountedList[driveNumber])
1.251 + {
1.252 + err = fs.DismountFileSystem(KMsFs, driveNumber);
1.253 + test.Printf(_L("MSFS Dismount:%S (%d)\n"), (err?&KError:&KOk), err);
1.254 + if (err)
1.255 + return err;
1.256 +
1.257 + msfsMountedList[driveNumber] = EFalse;
1.258 + }
1.259 +
1.260 + //-- 2. try to mount the original FS back
1.261 + CFileSystemDescriptor* fsDesc = unmountedFsList[driveNumber];
1.262 + if(fsDesc)
1.263 + {
1.264 + err = DoRestoreFS(fs, driveNumber, fsDesc);
1.265 +
1.266 + TPtrC ptrN(fsDesc->FsName());
1.267 + test.Printf(_L("%S Mount: %S (%d)\n"), &ptrN, (err?&KError:&KOk), err);
1.268 +
1.269 + delete fsDesc;
1.270 + unmountedFsList[driveNumber] = NULL;
1.271 + }
1.272 +
1.273 + return err;
1.274 + }
1.275 +
1.276 +//////////////////////////////////////////////////////////////////////////////
1.277 +//
1.278 +// CPropertyWatch
1.279 +// An active object that tracks changes to the KUsbMsDriveState properties
1.280 +//
1.281 +//////////////////////////////////////////////////////////////////////////////
1.282 +
1.283 +CPropertyWatch* CPropertyWatch::NewLC(TUsbMsDriveState_Subkey aSubkey, PropertyHandlers::THandler aHandler)
1.284 + {
1.285 + CPropertyWatch* me=new(ELeave) CPropertyWatch(aHandler);
1.286 + CleanupStack::PushL (me);
1.287 + me->ConstructL(aSubkey);
1.288 + CleanupStack::Pop();
1.289 + return me;
1.290 + }
1.291 +
1.292 +CPropertyWatch::CPropertyWatch(PropertyHandlers::THandler aHandler)
1.293 + : CActive(0), iHandler(aHandler)
1.294 + {}
1.295 +
1.296 +void CPropertyWatch::ConstructL(TUsbMsDriveState_Subkey aSubkey)
1.297 + {
1.298 + User::LeaveIfError(iProperty.Attach(KUsbMsDriveState_Category, aSubkey));
1.299 + CActiveScheduler::Add(this);
1.300 + // initial subscription and process current property value
1.301 + RunL();
1.302 + }
1.303 +
1.304 +CPropertyWatch::~CPropertyWatch()
1.305 + {
1.306 + Cancel();
1.307 + iProperty.Close();
1.308 + }
1.309 +
1.310 +void CPropertyWatch::DoCancel()
1.311 + {
1.312 + iProperty.Cancel();
1.313 + }
1.314 +
1.315 +void CPropertyWatch::RunL()
1.316 + {
1.317 + // resubscribe before processing new value to prevent missing updates
1.318 + iProperty.Subscribe(iStatus);
1.319 + SetActive();
1.320 +
1.321 + iHandler(iProperty);
1.322 + }
1.323 +
1.324 +//////////////////////////////////////////////////////////////////////////////
1.325 +//
1.326 +// CUsbWatch
1.327 +//
1.328 +//////////////////////////////////////////////////////////////////////////////
1.329 +
1.330 +CUsbWatch* CUsbWatch::NewLC(RUsb& aUsb)
1.331 + {
1.332 + CUsbWatch* me=new(ELeave) CUsbWatch(aUsb);
1.333 + CleanupStack::PushL (me);
1.334 + me->ConstructL();
1.335 + CleanupStack::Pop();
1.336 + return me;
1.337 + }
1.338 +
1.339 +CUsbWatch::CUsbWatch(RUsb& aUsb)
1.340 + :
1.341 + CActive(0),
1.342 + iUsb(aUsb),
1.343 + iUsbDeviceState(EUsbcDeviceStateUndefined),
1.344 + iWasConfigured(EFalse)
1.345 + {}
1.346 +
1.347 +void CUsbWatch::ConstructL()
1.348 + {
1.349 + CActiveScheduler::Add(this);
1.350 + RunL();
1.351 + }
1.352 +
1.353 +CUsbWatch::~CUsbWatch()
1.354 + {
1.355 + Cancel();
1.356 + iUsb.AlternateDeviceStatusNotifyCancel();
1.357 + }
1.358 +
1.359 +void CUsbWatch::DoCancel()
1.360 + {
1.361 + iUsb.AlternateDeviceStatusNotifyCancel();
1.362 + }
1.363 +
1.364 +static TBool IsDriveConnected(TInt driveStatusIndex)
1.365 + {
1.366 + TInt driveStatus = PropertyHandlers::allDrivesStatus[2*driveStatusIndex+1];
1.367 + return driveStatus >= EUsbMsDriveState_Connected ? ETrue : EFalse;
1.368 + }
1.369 +
1.370 +static TChar DriveNumberToLetter(TInt driveNumber)
1.371 + {
1.372 + TChar driveLetter = '?';
1.373 + fs.DriveToChar(driveNumber, driveLetter);
1.374 + return driveLetter;
1.375 + }
1.376 +
1.377 +static TBool IsDriveInMountList(TUint driveLetter)
1.378 + {
1.379 + TUint16 driveLetter16 = static_cast<TUint16>(driveLetter);
1.380 + return(!mountList.Length() || KErrNotFound != mountList.Find(&driveLetter16, 1));
1.381 + }
1.382 +
1.383 +void CUsbWatch::RunL()
1.384 + {
1.385 + gActiveControl->SetMSFinished(EFalse);
1.386 + if (gVerbose)
1.387 + {
1.388 + switch (iUsbDeviceState)
1.389 + {
1.390 + case EUsbcDeviceStateUndefined : // 0
1.391 + test.Printf(_L(">> CUSBWatch:Undefined %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
1.392 + break;
1.393 +
1.394 + case EUsbcDeviceStateAttached : // 1
1.395 + test.Printf(_L(">> CUSBWatch:Attached %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
1.396 + break;
1.397 +
1.398 + case EUsbcDeviceStatePowered : // 2
1.399 + test.Printf(_L(">> CUSBWatch:Powered %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
1.400 + break;
1.401 +
1.402 + case EUsbcDeviceStateDefault : // 3
1.403 + test.Printf(_L(">> CUSBWatch:Default %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
1.404 + break;
1.405 +
1.406 + case EUsbcDeviceStateAddress : // 4
1.407 + test.Printf(_L(">> CUSBWatch:Address %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
1.408 + break;
1.409 +
1.410 + case EUsbcDeviceStateConfigured : // 5
1.411 + test.Printf(_L(">> CUSBWatch:Configured %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
1.412 + break;
1.413 +
1.414 + case EUsbcDeviceStateSuspended : // 6
1.415 + test.Printf(_L(">> CUSBWatch:Suspended %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
1.416 + break;
1.417 +
1.418 + default :
1.419 + test.Printf(_L(">> CUSBWatch:UNKNOWN %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
1.420 + break;
1.421 +
1.422 + }
1.423 + }
1.424 + iUsb.AlternateDeviceStatusNotify(iStatus, iUsbDeviceState);
1.425 + SetActive();
1.426 +
1.427 + // If the cable is disconnected, unmount all the connected drives.
1.428 + if(iWasConfigured && iUsbDeviceState == EUsbcDeviceStateUndefined)
1.429 + {
1.430 + for(TInt i=0; i<PropertyHandlers::allDrivesStatus.Length()/2; i++)
1.431 + {
1.432 + if(IsDriveConnected(i))
1.433 + {
1.434 + RDebug::Print(_L("CUsbWatch calling RestoreMount"));
1.435 + RestoreMount(PropertyHandlers::allDrivesStatus[2*i]);
1.436 + }
1.437 + }
1.438 +
1.439 + iWasConfigured = EFalse;
1.440 + }
1.441 +
1.442 + // If cable is connected, mount all drives in the auto-mount list.
1.443 + // This is done for performance, since if this is not done here,
1.444 + // mounting will happen later after each drive enters the
1.445 + // Connecting state.
1.446 + if(iUsbDeviceState == EUsbcDeviceStateConfigured)
1.447 + {
1.448 + for(TInt i=0; i<PropertyHandlers::allDrivesStatus.Length()/2; i++)
1.449 + {
1.450 + TInt driveNumber = PropertyHandlers::allDrivesStatus[2*i];
1.451 + if(!IsDriveConnected(i) && IsDriveInMountList(DriveNumberToLetter(driveNumber)))
1.452 + {
1.453 + RDebug::Print(_L("CUsbWatch calling MountMsFs"));
1.454 + MountMsFs(driveNumber);
1.455 + }
1.456 + }
1.457 +
1.458 + iWasConfigured = ETrue;
1.459 + }
1.460 + }
1.461 +
1.462 +//////////////////////////////////////////////////////////////////////////////
1.463 +//
1.464 +// PropertyHandlers
1.465 +//
1.466 +//////////////////////////////////////////////////////////////////////////////
1.467 +
1.468 +TBuf8<16> PropertyHandlers::allDrivesStatus;
1.469 +TUsbMsBytesTransferred PropertyHandlers::iKBytesRead;
1.470 +TUsbMsBytesTransferred PropertyHandlers::iKBytesWritten;
1.471 +TInt PropertyHandlers::iMediaError;
1.472 +
1.473 +void PropertyHandlers::Read(RProperty& aProperty)
1.474 + {
1.475 + Transferred(aProperty, iKBytesRead);
1.476 + }
1.477 +
1.478 +void PropertyHandlers::Written(RProperty& aProperty)
1.479 + {
1.480 + Transferred(aProperty, iKBytesWritten);
1.481 + }
1.482 +
1.483 +void PropertyHandlers::Transferred(RProperty& aProperty, TUsbMsBytesTransferred& aReadOrWritten)
1.484 + {
1.485 + TInt err = aProperty.Get(aReadOrWritten);
1.486 + if(err == KErrNone)
1.487 + {
1.488 + for(TInt i = 0; i < allDrivesStatus.Length()/2; i++)
1.489 + {
1.490 + if (gVerbose)
1.491 + {
1.492 + test.Printf(KBytesTransferredFmt,
1.493 + (char)DriveNumberToLetter(allDrivesStatus[2*i]), iKBytesRead[i], iKBytesWritten[i]);
1.494 + }
1.495 + }
1.496 + }
1.497 + else
1.498 + {
1.499 + test.Printf(KErrFmt, err);
1.500 + }
1.501 + }
1.502 +
1.503 +void PropertyHandlers::DriveStatus(RProperty& aProperty)
1.504 + {
1.505 + if (gVerbose)
1.506 + {
1.507 + test.Printf(_L(">> PropertyHandlers::DriveStatus"));
1.508 + }
1.509 + TInt err = aProperty.Get(allDrivesStatus);
1.510 + if(err == KErrNone)
1.511 + {
1.512 + if (gVerbose)
1.513 + {
1.514 + test.Printf(_L(" Status: "));
1.515 + }
1.516 + for(TInt i = 0; i < allDrivesStatus.Length()/2; i++)
1.517 + {
1.518 + TInt driveNumber = allDrivesStatus[2*i];
1.519 + TInt driveStatus = allDrivesStatus[2*i+1];
1.520 + TChar driveLetter = DriveNumberToLetter(driveNumber);
1.521 +
1.522 + if (gVerbose)
1.523 + {
1.524 + switch(driveStatus)
1.525 + {
1.526 + case EUsbMsDriveState_Disconnected:
1.527 + {
1.528 + test.Printf(_L("%c:%d:Disconnected\n"), (char)driveLetter, driveStatus);
1.529 + break;
1.530 + }
1.531 + case EUsbMsDriveState_Connecting:
1.532 + {
1.533 + test.Printf(_L("%c:%d:Connecting\n"), (char)driveLetter, driveStatus);
1.534 + break;
1.535 + }
1.536 + case EUsbMsDriveState_Connected:
1.537 + {
1.538 + test.Printf(_L("%c:%d:Connected\n"), (char)driveLetter, driveStatus);
1.539 + break;
1.540 + }
1.541 + case EUsbMsDriveState_Disconnecting:
1.542 + {
1.543 + test.Printf(_L("%c:%d:Disconnecting\n"), (char)driveLetter, driveStatus);
1.544 + break;
1.545 + }
1.546 + case EUsbMsDriveState_Active:
1.547 + {
1.548 + test.Printf(_L("%c:%d:Active\n"), (char)driveLetter, driveStatus);
1.549 + break;
1.550 + }
1.551 + case EUsbMsDriveState_Locked:
1.552 + {
1.553 + test.Printf(_L("%c:%d:Locked\n"), (char)driveLetter, driveStatus);
1.554 + break;
1.555 + }
1.556 + case EUsbMsDriveState_MediaNotPresent:
1.557 + {
1.558 + test.Printf(_L("%c:%d:Not Present\n"), (char)driveLetter, driveStatus);
1.559 + break;
1.560 + }
1.561 + case EUsbMsDriveState_Removed:
1.562 + {
1.563 + test.Printf(_L("%c:%d:Removed\n"), (char)driveLetter, driveStatus);
1.564 + break;
1.565 + }
1.566 + case EUsbMsDriveState_Error:
1.567 + {
1.568 + test.Printf(_L("%c:%d:Error\n"), (char)driveLetter, driveStatus);
1.569 + break;
1.570 + }
1.571 + default :
1.572 + {
1.573 + test.Printf(_L("%c:%d:Unknown\n"), (char)driveLetter, driveStatus);
1.574 + break;
1.575 + }
1.576 + }
1.577 + }
1.578 +
1.579 + if (driveStatus == EUsbMsDriveState_Connected)
1.580 + {
1.581 + gActiveControl->SetMSFinished(EFalse);
1.582 + }
1.583 + if (driveStatus == EUsbMsDriveState_Disconnected)
1.584 + {
1.585 + gActiveControl->SetMSFinished(ETrue);
1.586 + }
1.587 + if(IsDriveInMountList(driveLetter))
1.588 + {
1.589 + if (driveStatus == EUsbMsDriveState_Connecting)
1.590 + {
1.591 + MountMsFs(driveNumber);
1.592 + }
1.593 + else if (driveStatus == EUsbMsDriveState_Disconnecting)
1.594 + {
1.595 + RestoreMount(driveNumber);
1.596 + }
1.597 + else
1.598 + {
1.599 + //RDebug::Print(_L("PropertyHandlers::DriveStatus: nothing to do"));
1.600 + }
1.601 + }
1.602 + else
1.603 + {
1.604 + //RDebug::Print(_L("PropertyHandlers::DriveStatus: %c: is not in mountList\n"), driveLetter);
1.605 + }
1.606 + }
1.607 + }
1.608 + else
1.609 + {
1.610 + test.Printf(KErrFmt, err);
1.611 + }
1.612 +
1.613 + }
1.614 +
1.615 +void PropertyHandlers::MediaError(RProperty& aProperty)
1.616 + {
1.617 + TInt r = aProperty.Get(iMediaError);
1.618 + if(r != KErrNone)
1.619 + {
1.620 + return;
1.621 + }
1.622 +
1.623 + test.Printf(_L("Media Error %x\n"), iMediaError);
1.624 + if (iMediaError > 0)
1.625 + {
1.626 + gActiveControl->SetMSFinished(ETrue);
1.627 + }
1.628 + }
1.629 +
1.630 +
1.631 +void StartMassStorage(RDEVCLIENT* aPort)
1.632 + {
1.633 + TInt r = KErrUnknown;
1.634 +
1.635 + test.Start (_L("Start Mass Storage"));
1.636 +
1.637 + fs.Connect();
1.638 +
1.639 + // Add MS file system
1.640 + test.Next (_L("Add MS File System"));
1.641 + r = fs.AddFileSystem(KMsFsy);
1.642 + test(r == KErrNone || r == KErrAlreadyExists);
1.643 +
1.644 +#ifdef USB_SC
1.645 + aPort->FinalizeInterface();
1.646 +#endif
1.647 +
1.648 +
1.649 + test.Next (_L("Create active objects\n"));
1.650 + propWatch[0] = CPropertyWatch::NewLC(EUsbMsDriveState_KBytesRead, PropertyHandlers::Read);
1.651 + propWatch[1] = CPropertyWatch::NewLC(EUsbMsDriveState_KBytesWritten, PropertyHandlers::Written);
1.652 + propWatch[2] = CPropertyWatch::NewLC(EUsbMsDriveState_DriveStatus, PropertyHandlers::DriveStatus);
1.653 + propWatch[3] = CPropertyWatch::NewLC(EUsbMsDriveState_MediaError, PropertyHandlers::MediaError);
1.654 + usbWatch = CUsbWatch::NewLC(*aPort);
1.655 +
1.656 + TBuf<8> t_vendorId(_L("vendor"));
1.657 + TBuf<16> t_productId(_L("product"));
1.658 + TBuf<4> t_productRev(_L("1.00"));
1.659 +
1.660 + TMassStorageConfig msConfig;
1.661 + msConfig.iVendorId.Copy(t_vendorId);
1.662 + msConfig.iProductId.Copy(t_productId);
1.663 + msConfig.iProductRev.Copy(t_productRev);
1.664 +
1.665 + test.Next(_L("Connect to Mass Storage"));
1.666 + r = UsbMs.Connect();
1.667 + test_KErrNone (r);
1.668 +
1.669 + test.Next(_L("Start Mass Storage"));
1.670 + r = UsbMs.Start(msConfig);
1.671 + test_KErrNone (r);
1.672 +
1.673 + test.End();
1.674 + }
1.675 +
1.676 +void StopMassStorage(RDEVCLIENT* aPort)
1.677 + {
1.678 + TInt r = KErrUnknown;
1.679 +
1.680 + test.Start (_L("Stop Mass Storage"));
1.681 +
1.682 + r = UsbMs.Stop();
1.683 + test_KErrNone (r);
1.684 + UsbMs.Close();
1.685 +
1.686 + for (TInt driveNumber = 0; driveNumber < KMaxDrives; driveNumber++)
1.687 + {
1.688 + if (msfsMountedList[driveNumber])
1.689 + {
1.690 + r = fs.DismountFileSystem(KMsFs, driveNumber);
1.691 + test_KErrNone (r);
1.692 +
1.693 + msfsMountedList[driveNumber] = EFalse;
1.694 + }
1.695 + }
1.696 +
1.697 + r = fs.RemoveFileSystem(KMsFs);
1.698 + test_KErrNone (r);
1.699 +
1.700 + fs.Close();
1.701 +
1.702 + delete usbWatch;
1.703 + for (TUint i =0; i < KNumPropWatch; i++)
1.704 + {
1.705 + delete propWatch[i];
1.706 + }
1.707 +
1.708 + aPort->Close();
1.709 +
1.710 + test.End();
1.711 + }
1.712 +