kerneltest/e32test/usb/t_usb_device/src/usbms.cpp
changeset 259 57b9594f5772
parent 0 a41df078684a
child 257 3e88ff8f41d5
child 271 dc268b18d709
equal deleted inserted replaced
247:d8d70de2bd36 259:57b9594f5772
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of the License "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    10 //
    10 //
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 // USB Mass Storage Application
    14 // USB Mass Storage Application
    15 // 
    15 //
    16 //
    16 //
    17 
    17 
    18 /**
    18 /**
    19  @file
    19  @file
    20 */
    20 */
    25 
    25 
    26 #include <usbmsshared.h>
    26 #include <usbmsshared.h>
    27 #include <massstorage.h>
    27 #include <massstorage.h>
    28 
    28 
    29 #include "usbms.h"
    29 #include "usbms.h"
       
    30 #include "OstTraceDefinitions.h"
       
    31 #ifdef OST_TRACE_COMPILER_IN_USE
       
    32 #include "usbmsTraces.h"
       
    33 #endif
       
    34 
    30 
    35 
    31 extern CActiveControl* gActiveControl;
    36 extern CActiveControl* gActiveControl;
    32 extern RTest test;
    37 extern RTest test;
    33 extern TBool gVerbose;
    38 extern TBool gVerbose;
    34 extern TBool gSkip;
    39 extern TBool gSkip;
    73 CFileSystemDescriptor* CFileSystemDescriptor::NewL(const TDesC& aFsName, const TDesC& aPrimaryExtName, TBool aDrvSynch)
    78 CFileSystemDescriptor* CFileSystemDescriptor::NewL(const TDesC& aFsName, const TDesC& aPrimaryExtName, TBool aDrvSynch)
    74     {
    79     {
    75     CFileSystemDescriptor* pSelf = new (ELeave) CFileSystemDescriptor;
    80     CFileSystemDescriptor* pSelf = new (ELeave) CFileSystemDescriptor;
    76 
    81 
    77     CleanupStack::PushL(pSelf);
    82     CleanupStack::PushL(pSelf);
    78     
    83 
    79     pSelf->iFsName.CreateMaxL(aFsName.Length());
    84     pSelf->iFsName.CreateMaxL(aFsName.Length());
    80     pSelf->iFsName.Copy(aFsName);
    85     pSelf->iFsName.Copy(aFsName);
    81     
    86 
    82     pSelf->iPrimaryExtName.CreateMaxL(aPrimaryExtName.Length());
    87     pSelf->iPrimaryExtName.CreateMaxL(aPrimaryExtName.Length());
    83     pSelf->iPrimaryExtName.Copy(aPrimaryExtName);
    88     pSelf->iPrimaryExtName.Copy(aPrimaryExtName);
    84 
    89 
    85     pSelf->iDriveSynch = aDrvSynch;
    90     pSelf->iDriveSynch = aDrvSynch;
    86 
    91 
    89     return pSelf;
    94     return pSelf;
    90     }
    95     }
    91 
    96 
    92 //-----------------------------------------------------------------------------
    97 //-----------------------------------------------------------------------------
    93 /**
    98 /**
    94     Dismounts the originally mounted FS and optional primary extension from the drive and stores 
    99     Dismounts the originally mounted FS and optional primary extension from the drive and stores
    95     this information in the FS descriptor
   100     this information in the FS descriptor
    96 
   101 
    97     @return on success returns a pointer to the instantinated FS descriptor
   102     @return on success returns a pointer to the instantinated FS descriptor
    98 */
   103 */
    99 LOCAL_C CFileSystemDescriptor* DoDismountOrginalFS(RFs& aFs, TInt aDrive)
   104 LOCAL_C CFileSystemDescriptor* DoDismountOrginalFS(RFs& aFs, TInt aDrive)
   102     TBuf<128>   fsName;
   107     TBuf<128>   fsName;
   103     TBuf<128>   primaryExtName;
   108     TBuf<128>   primaryExtName;
   104     TBool       bDrvSync = EFalse;
   109     TBool       bDrvSync = EFalse;
   105 
   110 
   106     test.Printf(_L("DoDismountOrginalFS drv:%d\n"), aDrive);
   111     test.Printf(_L("DoDismountOrginalFS drv:%d\n"), aDrive);
       
   112     OstTrace1(TRACE_NORMAL, CFILESYSTEMDESCRIPTOR_NEWL, "DoDismountOrginalFS drv:%d\n", aDrive);
   107 
   113 
   108     //-- 1. get file system name
   114     //-- 1. get file system name
   109     nRes = aFs.FileSystemName(fsName, aDrive);
   115     nRes = aFs.FileSystemName(fsName, aDrive);
   110     if(nRes != KErrNone)
   116     if(nRes != KErrNone)
   111         {//-- probably no file system installed at all
   117         {//-- probably no file system installed at all
   122 
   128 
   123     //-- 3. find out primary extension name if it is present; we will need to add it againt when mounting the FS
   129     //-- 3. find out primary extension name if it is present; we will need to add it againt when mounting the FS
   124     //-- other extensions (non-primary) are not supported yet
   130     //-- other extensions (non-primary) are not supported yet
   125     nRes = aFs.ExtensionName(primaryExtName, aDrive, 0);
   131     nRes = aFs.ExtensionName(primaryExtName, aDrive, 0);
   126     if(nRes != KErrNone)
   132     if(nRes != KErrNone)
   127         {   
   133         {
   128         primaryExtName.SetLength(0);
   134         primaryExtName.SetLength(0);
   129         }
   135         }
   130 
   136 
   131     //-- 3.1 check if the drive has non-primary extensions, fail in this case, because this FS can't be mounted back normally
   137     //-- 3.1 check if the drive has non-primary extensions, fail in this case, because this FS can't be mounted back normally
   132     nRes = aFs.ExtensionName(primaryExtName, aDrive, 1);
   138     nRes = aFs.ExtensionName(primaryExtName, aDrive, 1);
   133     if(nRes == KErrNone)
   139     if(nRes == KErrNone)
   134         {   
   140         {
   135         test.Printf(_L("DoDismountOrginalFS Non-primary extensions are not supported!\n"));
   141         test.Printf(_L("DoDismountOrginalFS Non-primary extensions are not supported!\n"));
       
   142         OstTrace0(TRACE_NORMAL, CFILESYSTEMDESCRIPTOR_NEWL_DUP01, "DoDismountOrginalFS Non-primary extensions are not supported!\n");
   136         return NULL;
   143         return NULL;
   137         }
   144         }
   138 
   145 
   139     test.Printf(_L("DoDismountOrginalFS FS:%S, Prim ext:%S, synch:%d\n"), &fsName, &primaryExtName, bDrvSync);
   146     test.Printf(_L("DoDismountOrginalFS FS:%S, Prim ext:%S, synch:%d\n"), &fsName, &primaryExtName, bDrvSync);
       
   147     OstTraceExt3(TRACE_NORMAL, CFILESYSTEMDESCRIPTOR_NEWL_DUP02, "DoDismountOrginalFS FS:%S, Prim ext:%S, synch:%d\n", fsName, primaryExtName, bDrvSync);
   140 
   148 
   141     //-- create FS descriptor and dismount the FS
   149     //-- create FS descriptor and dismount the FS
   142     CFileSystemDescriptor* pFsDesc = NULL; 
   150     CFileSystemDescriptor* pFsDesc = NULL;
   143     
   151 
   144     TRAP(nRes, pFsDesc = CFileSystemDescriptor::NewL(fsName, primaryExtName, bDrvSync));
   152     TRAP(nRes, pFsDesc = CFileSystemDescriptor::NewL(fsName, primaryExtName, bDrvSync));
   145     if(nRes != KErrNone)
   153     if(nRes != KErrNone)
   146         return NULL; //-- OOM ?
   154         return NULL; //-- OOM ?
   147 
   155 
   148     nRes = aFs.DismountFileSystem(fsName, aDrive);
   156     nRes = aFs.DismountFileSystem(fsName, aDrive);
   149     if(nRes != KErrNone)
   157     if(nRes != KErrNone)
   150         {
   158         {
   151         delete pFsDesc;
   159         delete pFsDesc;
   152         pFsDesc = NULL;
   160         pFsDesc = NULL;
   153         test.Printf(_L("DoDismountOrginalFS Dismounting Err:%d\n"), nRes);
   161         test.Printf(_L("DoDismountOrginalFS Dismounting Err:%d\n"), nRes);
   154         }
   162         OstTrace1(TRACE_NORMAL, CFILESYSTEMDESCRIPTOR_NEWL_DUP03, "DoDismountOrginalFS Dismounting Err:%d\n", nRes);
   155     
   163         }
       
   164 
   156     return pFsDesc;
   165     return pFsDesc;
   157 }
   166 }
   158 
   167 
   159 //-----------------------------------------------------------------------------
   168 //-----------------------------------------------------------------------------
   160 /**
   169 /**
   164 LOCAL_C TInt DoRestoreFS(RFs& aFs, TInt aDrive, CFileSystemDescriptor* apFsDesc)
   173 LOCAL_C TInt DoRestoreFS(RFs& aFs, TInt aDrive, CFileSystemDescriptor* apFsDesc)
   165     {
   174     {
   166     TInt nRes;
   175     TInt nRes;
   167 
   176 
   168     test.Printf(_L("DoRestoreFS drv:%d\n"), aDrive);
   177     test.Printf(_L("DoRestoreFS drv:%d\n"), aDrive);
       
   178     OstTrace1(TRACE_NORMAL, DORESTOREFS_DORESTOREFS, "DoRestoreFS drv:%d\n", aDrive);
   169 
   179 
   170     //-- 1. check that there is no FS installed
   180     //-- 1. check that there is no FS installed
   171     TBuf<128>   fsName;
   181     TBuf<128>   fsName;
   172     nRes = aFs.FileSystemName(fsName, aDrive);
   182     nRes = aFs.FileSystemName(fsName, aDrive);
   173     if(nRes == KErrNone)
   183     if(nRes == KErrNone)
   174         {//-- there is a file system already installed
   184         {//-- there is a file system already installed
   175 		test.Printf(_L("DoRestoreFS This drive already has FS intalled:%S \n"), &fsName);
   185 		test.Printf(_L("DoRestoreFS This drive already has FS intalled:%S \n"), &fsName);
       
   186 		OstTraceExt1(TRACE_NORMAL, DORESTOREFS_DORESTOREFS_DUP01, "DoRestoreFS This drive already has FS intalled:%S \n", fsName);
   176         return KErrAlreadyExists;
   187         return KErrAlreadyExists;
   177         }
   188         }
   178  
   189 
   179     TPtrC ptrN  (apFsDesc->FsName());
   190     TPtrC ptrN  (apFsDesc->FsName());
   180     TPtrC ptrExt(apFsDesc->PrimaryExtName());
   191     TPtrC ptrExt(apFsDesc->PrimaryExtName());
   181     test.Printf(_L("DoRestoreFS Mounting FS:%S, Prim ext:%S, synch:%d\n"), &ptrN, &ptrExt, apFsDesc->DriveIsSynch());
   192     test.Printf(_L("DoRestoreFS Mounting FS:%S, Prim ext:%S, synch:%d\n"), &ptrN, &ptrExt, apFsDesc->DriveIsSynch());
       
   193     OstTraceExt3(TRACE_NORMAL, DORESTOREFS_DORESTOREFS_DUP02, "DoRestoreFS Mounting FS:%S, Prim ext:%S, synch:%d\n", ptrN, ptrExt, apFsDesc->DriveIsSynch());
   182 
   194 
   183     if(ptrExt.Length() >0)
   195     if(ptrExt.Length() >0)
   184         {//-- there is a primary extension to be mounted
   196         {//-- there is a primary extension to be mounted
   185         nRes = aFs.AddExtension(ptrExt);
   197         nRes = aFs.AddExtension(ptrExt);
   186         if(nRes != KErrNone && nRes != KErrAlreadyExists)
   198         if(nRes != KErrNone && nRes != KErrAlreadyExists)
   195         nRes = aFs.MountFileSystem(ptrN, aDrive, apFsDesc->DriveIsSynch());
   207         nRes = aFs.MountFileSystem(ptrN, aDrive, apFsDesc->DriveIsSynch());
   196         }
   208         }
   197 
   209 
   198     if(nRes != KErrNone)
   210     if(nRes != KErrNone)
   199         {
   211         {
   200         test.Printf(_L("DoRestoreFS Mount failed! code:%d\n"),nRes);    
   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);
   201         }
   214         }
   202 
   215 
   203     return nRes;
   216     return nRes;
   204     }
   217     }
   205 
   218 
   208 /**
   221 /**
   209     Dismount the original FS from the drive and mount MsFS instead
   222     Dismount the original FS from the drive and mount MsFS instead
   210 */
   223 */
   211 LOCAL_C void MountMsFs(TInt driveNumber)
   224 LOCAL_C void MountMsFs(TInt driveNumber)
   212 	{
   225 	{
   213 	test.Printf(_L("MountMsFs driveNumber=%d\n"), driveNumber); 
   226 	test.Printf(_L("MountMsFs driveNumber=%d\n"), driveNumber);
       
   227 	OstTrace1(TRACE_NORMAL, MOUNTMSFS_MOUNTMSFS, "MountMsFs driveNumber=%d\n", driveNumber);
   214 
   228 
   215     //-- 1. try dismounting the original FS
   229     //-- 1. try dismounting the original FS
   216     CFileSystemDescriptor* fsDesc = DoDismountOrginalFS(fs, driveNumber);
   230     CFileSystemDescriptor* fsDesc = DoDismountOrginalFS(fs, driveNumber);
   217     unmountedFsList[driveNumber] = fsDesc;
   231     unmountedFsList[driveNumber] = fsDesc;
   218 
   232 
   219     if(fsDesc)
   233     if(fsDesc)
   220         {
   234         {
   221         TPtrC ptrN(fsDesc->FsName());
   235         TPtrC ptrN(fsDesc->FsName());
   222         test.Printf(_L("drv:%d FS:%S Dismounted OK\n"),driveNumber, &ptrN);
   236         test.Printf(_L("drv:%d FS:%S Dismounted OK\n"),driveNumber, &ptrN);
       
   237         OstTraceExt2(TRACE_NORMAL, MOUNTMSFS_MOUNTMSFS_DUP01, "drv:%d FS:%S Dismounted OK\n",driveNumber, ptrN);
   223         }
   238         }
   224     else
   239     else
   225         {
   240         {
   226         test.Printf(_L("drv:%d Dismount FS Failed!\n"),driveNumber);
   241         test.Printf(_L("drv:%d Dismount FS Failed!\n"),driveNumber);
       
   242         OstTrace1(TRACE_NORMAL, MOUNTMSFS_MOUNTMSFS_DUP02, "drv:%d Dismount FS Failed!\n",driveNumber);
   227         }
   243         }
   228 
   244 
   229     //-- 2. try to mount the "MSFS"
   245     //-- 2. try to mount the "MSFS"
   230     TInt error;
   246     TInt error;
   231     error = fs.MountFileSystem(KMsFs, driveNumber);
   247     error = fs.MountFileSystem(KMsFs, driveNumber);
   232 	test.Printf(_L("MSFS Mount:   %S (%d)\n"), (error?&KError:&KOk), error);
   248 	test.Printf(_L("MSFS Mount:   %S (%d)\n"), (error?&KError:&KOk), error);
       
   249 	OstTraceExt2(TRACE_NORMAL, MOUNTMSFS_MOUNTMSFS_DUP03, "MSFS Mount:   %S (%d)\n", (error?KError():KOk()), error);
   233 	if (!error)
   250 	if (!error)
   234 		msfsMountedList[driveNumber] = ETrue;
   251 		msfsMountedList[driveNumber] = ETrue;
   235 
   252 
   236 	}
   253 	}
   237 
   254 
   238 //-----------------------------------------------------------------------------
   255 //-----------------------------------------------------------------------------
   239 /**
   256 /**
   240     Dismount MsFS and mount the original FS 
   257     Dismount MsFS and mount the original FS
   241 */
   258 */
   242 LOCAL_C TInt RestoreMount(TInt driveNumber)
   259 LOCAL_C TInt RestoreMount(TInt driveNumber)
   243 	{
   260 	{
   244 	TInt err = KErrNone;
   261 	TInt err = KErrNone;
   245 
   262 
   246     //-- 1. try dismounting the "MSFS"
   263     //-- 1. try dismounting the "MSFS"
   247 	if (msfsMountedList[driveNumber])
   264 	if (msfsMountedList[driveNumber])
   248 		{
   265 		{
   249 		err = fs.DismountFileSystem(KMsFs, driveNumber);
   266 		err = fs.DismountFileSystem(KMsFs, driveNumber);
   250 		test.Printf(_L("MSFS Dismount:%S (%d)\n"), (err?&KError:&KOk), err);
   267 		test.Printf(_L("MSFS Dismount:%S (%d)\n"), (err?&KError:&KOk), err);
       
   268 		OstTraceExt2(TRACE_NORMAL, RESTOREMOUNT_RESTOREMOUNT, "MSFS Dismount:%S (%d)\n", (err?KError():KOk()), err);
   251 		if (err)
   269 		if (err)
   252 			return err;
   270 			return err;
   253 
   271 
   254 		msfsMountedList[driveNumber] = EFalse;
   272 		msfsMountedList[driveNumber] = EFalse;
   255         }
   273         }
   260         {
   278         {
   261         err = DoRestoreFS(fs, driveNumber, fsDesc);
   279         err = DoRestoreFS(fs, driveNumber, fsDesc);
   262 
   280 
   263         TPtrC ptrN(fsDesc->FsName());
   281         TPtrC ptrN(fsDesc->FsName());
   264         test.Printf(_L("%S Mount:    %S (%d)\n"), &ptrN, (err?&KError:&KOk), err);
   282         test.Printf(_L("%S Mount:    %S (%d)\n"), &ptrN, (err?&KError:&KOk), err);
   265         
   283         OstTraceExt3(TRACE_NORMAL, RESTOREMOUNT_RESTOREMOUNT_DUP01, "%S Mount:    %S (%d)\n", ptrN, (err?KError():KOk()), err);
   266         delete fsDesc;
   284         delete fsDesc;
   267         unmountedFsList[driveNumber] = NULL;
   285         unmountedFsList[driveNumber] = NULL;
   268         }
   286         }
   269 
   287 
   270 	return err;
   288 	return err;
   332 	CleanupStack::Pop();
   350 	CleanupStack::Pop();
   333 	return me;
   351 	return me;
   334 	}
   352 	}
   335 
   353 
   336 CUsbWatch::CUsbWatch(RUsb& aUsb)
   354 CUsbWatch::CUsbWatch(RUsb& aUsb)
   337 	: 
   355 	:
   338 	CActive(0), 
   356 	CActive(0),
   339 	iUsb(aUsb),
   357 	iUsb(aUsb),
   340 	iUsbDeviceState(EUsbcDeviceStateUndefined),
   358 	iUsbDeviceState(EUsbcDeviceStateUndefined),
   341 	iWasConfigured(EFalse)
   359 	iWasConfigured(EFalse)
   342 	{}
   360 	{}
   343 
   361 
   368 	{
   386 	{
   369 	TChar driveLetter = '?';
   387 	TChar driveLetter = '?';
   370 	fs.DriveToChar(driveNumber, driveLetter);
   388 	fs.DriveToChar(driveNumber, driveLetter);
   371 	return driveLetter;
   389 	return driveLetter;
   372 	}
   390 	}
   373 	
   391 
   374 static TBool IsDriveInMountList(TUint driveLetter)
   392 static TBool IsDriveInMountList(TUint driveLetter)
   375 	{
   393 	{
   376 	TUint16 driveLetter16 = static_cast<TUint16>(driveLetter);
   394 	TUint16 driveLetter16 = static_cast<TUint16>(driveLetter);
   377 	return(!mountList.Length() || KErrNotFound != mountList.Find(&driveLetter16, 1));
   395 	return(!mountList.Length() || KErrNotFound != mountList.Find(&driveLetter16, 1));
   378 	}
   396 	}
   384 		{
   402 		{
   385 		switch (iUsbDeviceState)
   403 		switch (iUsbDeviceState)
   386 			{
   404 			{
   387 			case EUsbcDeviceStateUndefined : 					// 0
   405 			case EUsbcDeviceStateUndefined : 					// 0
   388 				test.Printf(_L(">> CUSBWatch:Undefined %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
   406 				test.Printf(_L(">> CUSBWatch:Undefined %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
       
   407 				OstTraceExt1(TRACE_NORMAL, CUSBWATCH_RUNL, ">> CUSBWatch:Undefined %S\n", iWasConfigured ? KConfigured() : KNotConfigured());
   389 				break;
   408 				break;
   390 			
   409 
   391 			case EUsbcDeviceStateAttached :						// 1
   410 			case EUsbcDeviceStateAttached :						// 1
   392 				test.Printf(_L(">> CUSBWatch:Attached %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
   411 				test.Printf(_L(">> CUSBWatch:Attached %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
       
   412 				OstTraceExt1(TRACE_NORMAL, CUSBWATCH_RUNL_DUP01, ">> CUSBWatch:Attached %S\n", iWasConfigured ? KConfigured() : KNotConfigured());
   393 				break;
   413 				break;
   394 			
   414 
   395 			case EUsbcDeviceStatePowered :						// 2
   415 			case EUsbcDeviceStatePowered :						// 2
   396 				test.Printf(_L(">> CUSBWatch:Powered %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
   416 				test.Printf(_L(">> CUSBWatch:Powered %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
       
   417 				OstTraceExt1(TRACE_NORMAL, CUSBWATCH_RUNL_DUP02, ">> CUSBWatch:Powered %S\n", iWasConfigured ? KConfigured() : KNotConfigured());
   397 				break;
   418 				break;
   398 	
   419 
   399 			case EUsbcDeviceStateDefault :						// 3
   420 			case EUsbcDeviceStateDefault :						// 3
   400 				test.Printf(_L(">> CUSBWatch:Default %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
   421 				test.Printf(_L(">> CUSBWatch:Default %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
       
   422 				OstTraceExt1(TRACE_NORMAL, CUSBWATCH_RUNL_DUP03, ">> CUSBWatch:Default %S\n", iWasConfigured ? KConfigured() : KNotConfigured());
   401 				break;
   423 				break;
   402 			
   424 
   403 			case EUsbcDeviceStateAddress :						// 4
   425 			case EUsbcDeviceStateAddress :						// 4
   404 				test.Printf(_L(">> CUSBWatch:Address %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
   426 				test.Printf(_L(">> CUSBWatch:Address %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
       
   427 				OstTraceExt1(TRACE_NORMAL, CUSBWATCH_RUNL_DUP04, ">> CUSBWatch:Address %S\n", iWasConfigured ? KConfigured() : KNotConfigured());
   405 				break;
   428 				break;
   406 			
   429 
   407 			case EUsbcDeviceStateConfigured :					// 5
   430 			case EUsbcDeviceStateConfigured :					// 5
   408 				test.Printf(_L(">> CUSBWatch:Configured %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
   431 				test.Printf(_L(">> CUSBWatch:Configured %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
       
   432 				OstTraceExt1(TRACE_NORMAL, CUSBWATCH_RUNL_DUP05, ">> CUSBWatch:Configured %S\n", iWasConfigured ? KConfigured() : KNotConfigured());
   409 				break;
   433 				break;
   410 			
   434 
   411 			case EUsbcDeviceStateSuspended : 					// 6
   435 			case EUsbcDeviceStateSuspended : 					// 6
   412 				test.Printf(_L(">> CUSBWatch:Suspended %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
   436 				test.Printf(_L(">> CUSBWatch:Suspended %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
       
   437 				OstTraceExt1(TRACE_NORMAL, CUSBWATCH_RUNL_DUP06, ">> CUSBWatch:Suspended %S\n", iWasConfigured ? KConfigured() : KNotConfigured());
   413 				break;
   438 				break;
   414 			
   439 
   415 			default :
   440 			default :
   416 				test.Printf(_L(">> CUSBWatch:UNKNOWN %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
   441 				test.Printf(_L(">> CUSBWatch:UNKNOWN %S\n"), iWasConfigured ? &KConfigured : &KNotConfigured);
       
   442 				OstTraceExt1(TRACE_NORMAL, CUSBWATCH_RUNL_DUP07, ">> CUSBWatch:UNKNOWN %S\n", iWasConfigured ? KConfigured() : KNotConfigured());
   417 				break;
   443 				break;
   418 		
   444 
   419 			}
   445 			}
   420 		}
   446 		}
   421 	iUsb.AlternateDeviceStatusNotify(iStatus, iUsbDeviceState);
   447 	iUsb.AlternateDeviceStatusNotify(iStatus, iUsbDeviceState);
   422 	SetActive();
   448 	SetActive();
   423 
   449 
   426 		{
   452 		{
   427 		for(TInt i=0; i<PropertyHandlers::allDrivesStatus.Length()/2; i++)
   453 		for(TInt i=0; i<PropertyHandlers::allDrivesStatus.Length()/2; i++)
   428 			{
   454 			{
   429 			if(IsDriveConnected(i))
   455 			if(IsDriveConnected(i))
   430 				{
   456 				{
   431 				RDebug::Print(_L("CUsbWatch calling RestoreMount"));
   457 				OstTrace0(TRACE_NORMAL, CUSBWATCH_RUNL_DUP08, "CUsbWatch calling RestoreMount");
   432 				RestoreMount(PropertyHandlers::allDrivesStatus[2*i]);
   458 				RestoreMount(PropertyHandlers::allDrivesStatus[2*i]);
   433 				}
   459 				}
   434 			}
   460 			}
   435 
   461 
   436 		iWasConfigured = EFalse;
   462 		iWasConfigured = EFalse;
   437 		}
   463 		}
   438 
   464 
   439 	// If cable is connected, mount all drives in the auto-mount list.
   465 	// If cable is connected, mount all drives in the auto-mount list.
   440 	// This is done for performance, since if this is not done here,
   466 	// This is done for performance, since if this is not done here,
   441 	// mounting will happen later after each drive enters the 
   467 	// mounting will happen later after each drive enters the
   442 	// Connecting state.
   468 	// Connecting state.
   443 	if(iUsbDeviceState == EUsbcDeviceStateConfigured)
   469 	if(iUsbDeviceState == EUsbcDeviceStateConfigured)
   444 		{
   470 		{
   445 		for(TInt i=0; i<PropertyHandlers::allDrivesStatus.Length()/2; i++)
   471 		for(TInt i=0; i<PropertyHandlers::allDrivesStatus.Length()/2; i++)
   446 			{
   472 			{
   447 			TInt driveNumber = PropertyHandlers::allDrivesStatus[2*i];
   473 			TInt driveNumber = PropertyHandlers::allDrivesStatus[2*i];
   448 			if(!IsDriveConnected(i) && IsDriveInMountList(DriveNumberToLetter(driveNumber)))
   474 			if(!IsDriveConnected(i) && IsDriveInMountList(DriveNumberToLetter(driveNumber)))
   449 				{
   475 				{
   450 				RDebug::Print(_L("CUsbWatch calling MountMsFs"));
   476 				OstTrace0(TRACE_NORMAL, CUSBWATCH_RUNL_DUP09, "CUsbWatch calling MountMsFs");
   451 				MountMsFs(driveNumber);
   477 				MountMsFs(driveNumber);
   452 				}
   478 				}
   453 			}
   479 			}
   454 
   480 
   455 		iWasConfigured = ETrue;
   481 		iWasConfigured = ETrue;
   484 		{
   510 		{
   485 		for(TInt i = 0; i < allDrivesStatus.Length()/2; i++)
   511 		for(TInt i = 0; i < allDrivesStatus.Length()/2; i++)
   486 			{
   512 			{
   487 			if (gVerbose)
   513 			if (gVerbose)
   488 				{
   514 				{
   489 				test.Printf(KBytesTransferredFmt, 
   515 				test.Printf(KBytesTransferredFmt,
       
   516 						(char)DriveNumberToLetter(allDrivesStatus[2*i]), iKBytesRead[i], iKBytesWritten[i]);
       
   517 				OstTraceExt3(TRACE_NORMAL, PROPERTYHANDLERS_TRANSFERRED, "%c:%d/%d \n",
   490 						(char)DriveNumberToLetter(allDrivesStatus[2*i]), iKBytesRead[i], iKBytesWritten[i]);
   518 						(char)DriveNumberToLetter(allDrivesStatus[2*i]), iKBytesRead[i], iKBytesWritten[i]);
   491 				}
   519 				}
   492 			}
   520 			}
   493 		}
   521 		}
   494 	else
   522 	else
   495 		{
   523 		{
   496 		test.Printf(KErrFmt, err);
   524 		test.Printf(KErrFmt, err);
   497 		}
   525 		OstTrace1(TRACE_NORMAL, PROPERTYHANDLERS_TRANSFERRED_DUP01, "Error: %d\r", err);
   498 	}
   526 		}
   499 	
   527 	}
       
   528 
   500 void PropertyHandlers::DriveStatus(RProperty& aProperty)
   529 void PropertyHandlers::DriveStatus(RProperty& aProperty)
   501 	{
   530 	{
   502 	if (gVerbose)
   531 	if (gVerbose)
   503 		{
   532 		{
   504 		test.Printf(_L(">> PropertyHandlers::DriveStatus"));
   533 		test.Printf(_L(">> PropertyHandlers::DriveStatus"));
       
   534 		OstTrace0(TRACE_NORMAL, PROPERTYHANDLERS_DRIVESTATUS, ">> PropertyHandlers::DriveStatus");
   505 		}
   535 		}
   506 	TInt err = aProperty.Get(allDrivesStatus);
   536 	TInt err = aProperty.Get(allDrivesStatus);
   507 	if(err == KErrNone)
   537 	if(err == KErrNone)
   508 		{
   538 		{
   509 		if (gVerbose)
   539 		if (gVerbose)
   510 			{
   540 			{
   511 			test.Printf(_L(" Status:  "));
   541 			test.Printf(_L(" Status:  "));
       
   542 			OstTrace0(TRACE_NORMAL, PROPERTYHANDLERS_DRIVESTATUS_DUP01, " Status:  ");
   512 			}
   543 			}
   513 		for(TInt i = 0; i < allDrivesStatus.Length()/2; i++)
   544 		for(TInt i = 0; i < allDrivesStatus.Length()/2; i++)
   514 			{
   545 			{
   515 			TInt driveNumber = allDrivesStatus[2*i];
   546 			TInt driveNumber = allDrivesStatus[2*i];
   516 			TInt driveStatus = allDrivesStatus[2*i+1];
   547 			TInt driveStatus = allDrivesStatus[2*i+1];
   521 				switch(driveStatus)
   552 				switch(driveStatus)
   522 					{
   553 					{
   523 					case EUsbMsDriveState_Disconnected:
   554 					case EUsbMsDriveState_Disconnected:
   524 						{
   555 						{
   525 						test.Printf(_L("%c:%d:Disconnected\n"), (char)driveLetter, driveStatus);
   556 						test.Printf(_L("%c:%d:Disconnected\n"), (char)driveLetter, driveStatus);
       
   557 						OstTraceExt2(TRACE_NORMAL, PROPERTYHANDLERS_DRIVESTATUS_DUP02, "%c:%d:Disconnected\n", (char)driveLetter, driveStatus);
   526 						break;
   558 						break;
   527 						}
   559 						}
   528 					case EUsbMsDriveState_Connecting:
   560 					case EUsbMsDriveState_Connecting:
   529 						{
   561 						{
   530 						test.Printf(_L("%c:%d:Connecting\n"), (char)driveLetter, driveStatus);
   562 						test.Printf(_L("%c:%d:Connecting\n"), (char)driveLetter, driveStatus);
       
   563 						OstTraceExt2(TRACE_NORMAL, PROPERTYHANDLERS_DRIVESTATUS_DUP03, "%c:%d:Connecting\n", (char)driveLetter, driveStatus);
   531 						break;
   564 						break;
   532 						}
   565 						}
   533 					case EUsbMsDriveState_Connected:
   566 					case EUsbMsDriveState_Connected:
   534 						{
   567 						{
   535 						test.Printf(_L("%c:%d:Connected\n"), (char)driveLetter, driveStatus);
   568 						test.Printf(_L("%c:%d:Connected\n"), (char)driveLetter, driveStatus);
       
   569 						OstTraceExt2(TRACE_NORMAL, PROPERTYHANDLERS_DRIVESTATUS_DUP04, "%c:%d:Connected\n", (char)driveLetter, driveStatus);
   536 						break;
   570 						break;
   537 						}
   571 						}
   538 					case EUsbMsDriveState_Disconnecting:
   572 					case EUsbMsDriveState_Disconnecting:
   539 						{
   573 						{
   540 						test.Printf(_L("%c:%d:Disconnecting\n"), (char)driveLetter, driveStatus);
   574 						test.Printf(_L("%c:%d:Disconnecting\n"), (char)driveLetter, driveStatus);
       
   575 						OstTraceExt2(TRACE_NORMAL, PROPERTYHANDLERS_DRIVESTATUS_DUP05, "%c:%d:Disconnecting\n", (char)driveLetter, driveStatus);
   541 						break;
   576 						break;
   542 						}
   577 						}
   543 					case EUsbMsDriveState_Active:
   578 					case EUsbMsDriveState_Active:
   544 						{
   579 						{
   545 						test.Printf(_L("%c:%d:Active\n"), (char)driveLetter, driveStatus);
   580 						test.Printf(_L("%c:%d:Active\n"), (char)driveLetter, driveStatus);
       
   581 						OstTraceExt2(TRACE_NORMAL, PROPERTYHANDLERS_DRIVESTATUS_DUP06, "%c:%d:Active\n", (char)driveLetter, driveStatus);
   546 						break;
   582 						break;
   547 						}
   583 						}
   548 					case EUsbMsDriveState_Locked:
   584 					case EUsbMsDriveState_Locked:
   549 						{
   585 						{
   550 						test.Printf(_L("%c:%d:Locked\n"), (char)driveLetter, driveStatus);
   586 						test.Printf(_L("%c:%d:Locked\n"), (char)driveLetter, driveStatus);
       
   587 						OstTraceExt2(TRACE_NORMAL, PROPERTYHANDLERS_DRIVESTATUS_DUP07, "%c:%d:Locked\n", (char)driveLetter, driveStatus);
   551 						break;
   588 						break;
   552 						}
   589 						}
   553 					case EUsbMsDriveState_MediaNotPresent:
   590 					case EUsbMsDriveState_MediaNotPresent:
   554 						{
   591 						{
   555 						test.Printf(_L("%c:%d:Not Present\n"), (char)driveLetter, driveStatus);
   592 						test.Printf(_L("%c:%d:Not Present\n"), (char)driveLetter, driveStatus);
       
   593 						OstTraceExt2(TRACE_NORMAL, PROPERTYHANDLERS_DRIVESTATUS_DUP08, "%c:%d:Not Present\n", (char)driveLetter, driveStatus);
   556 						break;
   594 						break;
   557 						}
   595 						}
   558 					case EUsbMsDriveState_Removed:
   596 					case EUsbMsDriveState_Removed:
   559 						{
   597 						{
   560 						test.Printf(_L("%c:%d:Removed\n"), (char)driveLetter, driveStatus);
   598 						test.Printf(_L("%c:%d:Removed\n"), (char)driveLetter, driveStatus);
       
   599 						OstTraceExt2(TRACE_NORMAL, PROPERTYHANDLERS_DRIVESTATUS_DUP09, "%c:%d:Removed\n", (char)driveLetter, driveStatus);
   561 						break;
   600 						break;
   562 						}
   601 						}
   563 					case EUsbMsDriveState_Error:
   602 					case EUsbMsDriveState_Error:
   564 						{
   603 						{
   565 						test.Printf(_L("%c:%d:Error\n"), (char)driveLetter, driveStatus);
   604 						test.Printf(_L("%c:%d:Error\n"), (char)driveLetter, driveStatus);
       
   605 						OstTraceExt2(TRACE_NORMAL, PROPERTYHANDLERS_DRIVESTATUS_DUP10, "%c:%d:Error\n", (char)driveLetter, driveStatus);
   566 						break;
   606 						break;
   567 						}
   607 						}
   568 					default :
   608 					default :
   569 						{
   609 						{
   570 						test.Printf(_L("%c:%d:Unknown\n"), (char)driveLetter, driveStatus);
   610 						test.Printf(_L("%c:%d:Unknown\n"), (char)driveLetter, driveStatus);
       
   611 						OstTraceExt2(TRACE_NORMAL, PROPERTYHANDLERS_DRIVESTATUS_DUP11, "%c:%d:Unknown\n", (char)driveLetter, driveStatus);
   571 						break;
   612 						break;
   572 						}
   613 						}
   573 					}
   614 					}
   574 				}
   615 				}
   575 
   616 
   576 			if (driveStatus == EUsbMsDriveState_Connected)
   617 			if (driveStatus == EUsbMsDriveState_Connected)
   577 				{
   618 				{
   578 				gActiveControl->SetMSFinished(EFalse);				
   619 				gActiveControl->SetMSFinished(EFalse);
   579 				}
   620 				}
   580 			if (driveStatus == EUsbMsDriveState_Disconnected)
   621 			if (driveStatus == EUsbMsDriveState_Disconnected)
   581 				{
   622 				{
   582 				gActiveControl->SetMSFinished(ETrue);				
   623 				gActiveControl->SetMSFinished(ETrue);
   583 				}
   624 				}
   584 			if(IsDriveInMountList(driveLetter))
   625 			if(IsDriveInMountList(driveLetter))
   585 				{
   626 				{
   586 				if (driveStatus == EUsbMsDriveState_Connecting)
   627 				if (driveStatus == EUsbMsDriveState_Connecting)
   587 					{
   628 					{
   589 					}
   630 					}
   590 				else if (driveStatus == EUsbMsDriveState_Disconnecting)
   631 				else if (driveStatus == EUsbMsDriveState_Disconnecting)
   591 					{
   632 					{
   592 					RestoreMount(driveNumber);
   633 					RestoreMount(driveNumber);
   593 					}
   634 					}
   594 				else
   635     			}
   595 					{
       
   596 					//RDebug::Print(_L("PropertyHandlers::DriveStatus: nothing to do"));
       
   597 					}
       
   598 				}
       
   599 			else
       
   600 				{
       
   601 				//RDebug::Print(_L("PropertyHandlers::DriveStatus: %c: is not in mountList\n"), driveLetter);
       
   602 				}
       
   603 			}
   636 			}
   604 		}
   637 		}
   605 	else
   638 	else
   606 		{
   639 		{
   607 		test.Printf(KErrFmt, err);
   640 		test.Printf(KErrFmt, err);
       
   641 		OstTrace1(TRACE_NORMAL, PROPERTYHANDLERS_DRIVESTATUS_DUP14, "Error: %d\r", err);
   608 		}
   642 		}
   609 
   643 
   610 	}
   644 	}
   611 
   645 
   612 void PropertyHandlers::MediaError(RProperty& aProperty)
   646 void PropertyHandlers::MediaError(RProperty& aProperty)
   616 		{
   650 		{
   617 		return;
   651 		return;
   618 		}
   652 		}
   619 
   653 
   620 	test.Printf(_L("Media Error %x\n"), iMediaError);
   654 	test.Printf(_L("Media Error %x\n"), iMediaError);
       
   655 	OstTrace1(TRACE_NORMAL, PROPERTYHANDLERS_MEDIAERROR, "Media Error %x\n", iMediaError);
   621 	if (iMediaError > 0)
   656 	if (iMediaError > 0)
   622 		{
   657 		{
   623 		gActiveControl->SetMSFinished(ETrue);
   658 		gActiveControl->SetMSFinished(ETrue);
   624 		}
   659 		}
   625 	}
   660 	}
   667 	r = UsbMs.Start(msConfig);
   702 	r = UsbMs.Start(msConfig);
   668 	test_KErrNone (r);
   703 	test_KErrNone (r);
   669 
   704 
   670 	test.End();
   705 	test.End();
   671 	}
   706 	}
   672 	
   707 
   673 void StopMassStorage(RDEVCLIENT* aPort)
   708 void StopMassStorage(RDEVCLIENT* aPort)
   674 	{
   709 	{
   675     TInt r = KErrUnknown;
   710     TInt r = KErrUnknown;
   676 	
   711 
   677 	test.Start (_L("Stop Mass Storage"));
   712 	test.Start (_L("Stop Mass Storage"));
   678 
   713 
   679 	r = UsbMs.Stop();
   714 	r = UsbMs.Stop();
   680 	test_KErrNone (r);
   715 	test_KErrNone (r);
   681 	UsbMs.Close();
   716 	UsbMs.Close();
   693 
   728 
   694 	r = fs.RemoveFileSystem(KMsFs);
   729 	r = fs.RemoveFileSystem(KMsFs);
   695 	test_KErrNone (r);
   730 	test_KErrNone (r);
   696 
   731 
   697 	fs.Close();
   732 	fs.Close();
   698 	
   733 
   699 	delete usbWatch;
   734 	delete usbWatch;
   700 	for (TUint i =0; i < KNumPropWatch; i++)
   735 	for (TUint i =0; i < KNumPropWatch; i++)
   701 		{
   736 		{
   702 		delete propWatch[i];
   737 		delete propWatch[i];
   703 		}
   738 		}
   704 	
   739 
   705 	aPort->Close();
   740 	aPort->Close();
   706 		
   741 
   707 	test.End();
   742 	test.End();
   708 	}
   743 	}
   709 
   744