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 - also used as an improvised boot loader mechanism
|
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 "usbmsapp.h"
|
sl@0
|
23 |
|
sl@0
|
24 |
#include <e32std.h>
|
sl@0
|
25 |
#include <e32std_private.h>
|
sl@0
|
26 |
#include <e32svr.h>
|
sl@0
|
27 |
#include <e32cons.h>
|
sl@0
|
28 |
#include <f32file.h>
|
sl@0
|
29 |
|
sl@0
|
30 |
#include <usbmsshared.h>
|
sl@0
|
31 |
#include <massstorage.h>
|
sl@0
|
32 |
|
sl@0
|
33 |
TBool gSharedChunkLdd = EFalse;
|
sl@0
|
34 |
#include <d32usbcsc.h>
|
sl@0
|
35 |
#include <d32usbc.h>
|
sl@0
|
36 |
|
sl@0
|
37 |
#ifdef BUILD_OTG_USBMSAPP
|
sl@0
|
38 |
#include <d32otgdi.h>
|
sl@0
|
39 |
#endif
|
sl@0
|
40 |
|
sl@0
|
41 |
#include <nkern/nk_trace.h>
|
sl@0
|
42 |
#include <hal.h>
|
sl@0
|
43 |
|
sl@0
|
44 |
#ifdef USB_BOOT_LOADER
|
sl@0
|
45 |
|
sl@0
|
46 |
#include "usbbootvar.h"
|
sl@0
|
47 |
#include <rebootdrv.h>
|
sl@0
|
48 |
#define KNANDLDRLDD_NAME _L("REBOOT.LDD")
|
sl@0
|
49 |
static RReboot* RebootDrv;
|
sl@0
|
50 |
|
sl@0
|
51 |
|
sl@0
|
52 |
/// Global number of seconds to delay before reboot
|
sl@0
|
53 |
static TInt gRebootDelay = 0;
|
sl@0
|
54 |
|
sl@0
|
55 |
#endif
|
sl@0
|
56 |
|
sl@0
|
57 |
enum
|
sl@0
|
58 |
{
|
sl@0
|
59 |
EUsbDeviceStateUndefined = EUsbcDeviceStateUndefined,
|
sl@0
|
60 |
EUsbDeviceStateConfigured = EUsbcDeviceStateConfigured,
|
sl@0
|
61 |
};
|
sl@0
|
62 |
|
sl@0
|
63 |
static CConsoleBase* console = NULL;
|
sl@0
|
64 |
static RFs fs;
|
sl@0
|
65 |
static TInt selectedDriveIndex = 0;
|
sl@0
|
66 |
static TBuf<0x40> mountList;
|
sl@0
|
67 |
|
sl@0
|
68 |
static TFixedArray<TBool, KMaxDrives> msfsMountedList; ///< 'true' entry corresponds to the drive with mounted MSFS.FSY
|
sl@0
|
69 |
static TFixedArray<CFileSystemDescriptor*, KMaxDrives> unmountedFsList; ///< every non-NULL entry corresponds to the unmounted original FS for the drive
|
sl@0
|
70 |
|
sl@0
|
71 |
|
sl@0
|
72 |
_LIT(KMsFsy, "MSFS.FSY");
|
sl@0
|
73 |
_LIT(KMsFs, "MassStorageFileSystem");
|
sl@0
|
74 |
|
sl@0
|
75 |
_LIT(KOk,"OK");
|
sl@0
|
76 |
_LIT(KError,"Error");
|
sl@0
|
77 |
_LIT(KBytesTransferredFmt, "%c:%d/%d ");
|
sl@0
|
78 |
_LIT(KErrFmt, "Error: %d\r");
|
sl@0
|
79 |
|
sl@0
|
80 |
#ifndef USB_BOOT_LOADER
|
sl@0
|
81 |
_LIT(KTxtApp,"USBMSAPP");
|
sl@0
|
82 |
_LIT(KDefPwd,"123");
|
sl@0
|
83 |
#endif
|
sl@0
|
84 |
|
sl@0
|
85 |
//-- if defined, some useful information will be printed out via RDebug interface
|
sl@0
|
86 |
//#define LOGGING_ENABLED
|
sl@0
|
87 |
|
sl@0
|
88 |
//-----------------------------------------------------------------------------
|
sl@0
|
89 |
/**
|
sl@0
|
90 |
prints a line to the console and copies it to the debug log if LOGGING_ENABLED
|
sl@0
|
91 |
*/
|
sl@0
|
92 |
void LogPrint(TRefByValue<const TDesC> aFmt,...)
|
sl@0
|
93 |
{
|
sl@0
|
94 |
VA_LIST list;
|
sl@0
|
95 |
VA_START(list, aFmt);
|
sl@0
|
96 |
|
sl@0
|
97 |
TBuf<0x100> buf;
|
sl@0
|
98 |
// coverity[uninit_use_in_call]
|
sl@0
|
99 |
buf.FormatList(aFmt, list); //-- ignore overflows
|
sl@0
|
100 |
|
sl@0
|
101 |
if(console)
|
sl@0
|
102 |
console->Write(buf);
|
sl@0
|
103 |
|
sl@0
|
104 |
#ifdef LOGGING_ENABLED
|
sl@0
|
105 |
//-- print out the line via RDebug::Print
|
sl@0
|
106 |
const TInt bufLen = buf.Length();
|
sl@0
|
107 |
if(bufLen >0 && buf[bufLen-1] == '\n')
|
sl@0
|
108 |
{
|
sl@0
|
109 |
buf.Insert(bufLen-1, _L("\r"));
|
sl@0
|
110 |
}
|
sl@0
|
111 |
else
|
sl@0
|
112 |
{
|
sl@0
|
113 |
buf.Append(_L("\r\n"));
|
sl@0
|
114 |
}
|
sl@0
|
115 |
|
sl@0
|
116 |
RDebug::RawPrint(buf);
|
sl@0
|
117 |
#endif
|
sl@0
|
118 |
}
|
sl@0
|
119 |
|
sl@0
|
120 |
//-----------------------------------------------------------------------------
|
sl@0
|
121 |
/**
|
sl@0
|
122 |
prints a line to the debug log if LOGGING_ENABLED
|
sl@0
|
123 |
*/
|
sl@0
|
124 |
void Log(TRefByValue<const TDesC> aFmt,...)
|
sl@0
|
125 |
{
|
sl@0
|
126 |
#ifdef LOGGING_ENABLED
|
sl@0
|
127 |
|
sl@0
|
128 |
VA_LIST list;
|
sl@0
|
129 |
VA_START(list, aFmt);
|
sl@0
|
130 |
|
sl@0
|
131 |
TBuf<0x100> buf;
|
sl@0
|
132 |
buf.FormatList(aFmt, list); //-- ignore overflows
|
sl@0
|
133 |
|
sl@0
|
134 |
//-- print out the line via RDebug::Print
|
sl@0
|
135 |
const TInt bufLen = buf.Length();
|
sl@0
|
136 |
if(bufLen >0 && buf[bufLen-1] == '\n')
|
sl@0
|
137 |
{
|
sl@0
|
138 |
buf.Insert(bufLen-1, _L("\r"));
|
sl@0
|
139 |
}
|
sl@0
|
140 |
|
sl@0
|
141 |
RDebug::RawPrint(buf);
|
sl@0
|
142 |
#else
|
sl@0
|
143 |
(void)aFmt;
|
sl@0
|
144 |
#endif
|
sl@0
|
145 |
}
|
sl@0
|
146 |
|
sl@0
|
147 |
|
sl@0
|
148 |
//-----------------------------------------------------------------------------
|
sl@0
|
149 |
|
sl@0
|
150 |
static void Clear(int row, int count=1)
|
sl@0
|
151 |
{
|
sl@0
|
152 |
_LIT(KBlank," ");
|
sl@0
|
153 |
for(TInt i=0; i<count; i++)
|
sl@0
|
154 |
{
|
sl@0
|
155 |
console->SetPos(0,row+i);
|
sl@0
|
156 |
console->Printf(KBlank);
|
sl@0
|
157 |
}
|
sl@0
|
158 |
console->SetPos(0,row);
|
sl@0
|
159 |
}
|
sl@0
|
160 |
|
sl@0
|
161 |
|
sl@0
|
162 |
static void ShowDriveSelection()
|
sl@0
|
163 |
{
|
sl@0
|
164 |
console->SetPos(0,15);
|
sl@0
|
165 |
if(PropertyHandlers::allDrivesStatus.Length()/2 > selectedDriveIndex)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
LogPrint(_L("Selected Drive: %c"), 'A' + PropertyHandlers::allDrivesStatus[selectedDriveIndex*2]);
|
sl@0
|
168 |
}
|
sl@0
|
169 |
else
|
sl@0
|
170 |
{
|
sl@0
|
171 |
LogPrint(_L("Selected Drive: (none)"));
|
sl@0
|
172 |
}
|
sl@0
|
173 |
}
|
sl@0
|
174 |
|
sl@0
|
175 |
|
sl@0
|
176 |
#ifdef USB_BOOT_LOADER
|
sl@0
|
177 |
|
sl@0
|
178 |
static void rebootit()
|
sl@0
|
179 |
{
|
sl@0
|
180 |
TInt r=User::LoadLogicalDevice(KNANDLDRLDD_NAME);
|
sl@0
|
181 |
RebootDrv=new RReboot;
|
sl@0
|
182 |
if(!RebootDrv)
|
sl@0
|
183 |
{
|
sl@0
|
184 |
User::Panic(_L("Loading driver"),1);
|
sl@0
|
185 |
}
|
sl@0
|
186 |
r=RebootDrv->Open();
|
sl@0
|
187 |
if (r!=KErrNone)
|
sl@0
|
188 |
{
|
sl@0
|
189 |
User::Panic(_L("Opening driver"),r);
|
sl@0
|
190 |
}
|
sl@0
|
191 |
|
sl@0
|
192 |
if (gRebootDelay>0)
|
sl@0
|
193 |
{
|
sl@0
|
194 |
_LIT(KMsgRebooting,"*** Reboot in %d secs ***\n");
|
sl@0
|
195 |
TInt delay=gRebootDelay;
|
sl@0
|
196 |
console->SetPos(0,20);
|
sl@0
|
197 |
do
|
sl@0
|
198 |
{
|
sl@0
|
199 |
LogPrint(KMsgRebooting, delay);
|
sl@0
|
200 |
User::After(1000000);
|
sl@0
|
201 |
} while(--delay);
|
sl@0
|
202 |
}
|
sl@0
|
203 |
r=RebootDrv->VariantCtrl(KVariantUsbmsVariantRebootReason, NULL);
|
sl@0
|
204 |
if (r!=KErrNone)
|
sl@0
|
205 |
{
|
sl@0
|
206 |
User::Panic(_L("Rebooting"),r);
|
sl@0
|
207 |
}
|
sl@0
|
208 |
}
|
sl@0
|
209 |
|
sl@0
|
210 |
#endif
|
sl@0
|
211 |
|
sl@0
|
212 |
class CPeriodUpdate : public CActive
|
sl@0
|
213 |
{
|
sl@0
|
214 |
public:
|
sl@0
|
215 |
static CPeriodUpdate* NewLC();
|
sl@0
|
216 |
private:
|
sl@0
|
217 |
CPeriodUpdate();
|
sl@0
|
218 |
void ConstructL();
|
sl@0
|
219 |
~CPeriodUpdate();
|
sl@0
|
220 |
void RunL();
|
sl@0
|
221 |
void DoCancel();
|
sl@0
|
222 |
|
sl@0
|
223 |
RTimer iTimer;
|
sl@0
|
224 |
TUint iUpTime;
|
sl@0
|
225 |
};
|
sl@0
|
226 |
|
sl@0
|
227 |
CPeriodUpdate* CPeriodUpdate::NewLC()
|
sl@0
|
228 |
{
|
sl@0
|
229 |
CPeriodUpdate* me=new(ELeave) CPeriodUpdate();
|
sl@0
|
230 |
CleanupStack::PushL(me);
|
sl@0
|
231 |
me->ConstructL();
|
sl@0
|
232 |
return me;
|
sl@0
|
233 |
}
|
sl@0
|
234 |
|
sl@0
|
235 |
CPeriodUpdate::CPeriodUpdate()
|
sl@0
|
236 |
: CActive(0), iUpTime(0)
|
sl@0
|
237 |
{}
|
sl@0
|
238 |
|
sl@0
|
239 |
void CPeriodUpdate::ConstructL()
|
sl@0
|
240 |
{
|
sl@0
|
241 |
CActiveScheduler::Add(this);
|
sl@0
|
242 |
iTimer.CreateLocal();
|
sl@0
|
243 |
RunL();
|
sl@0
|
244 |
}
|
sl@0
|
245 |
|
sl@0
|
246 |
CPeriodUpdate::~CPeriodUpdate()
|
sl@0
|
247 |
{
|
sl@0
|
248 |
Cancel();
|
sl@0
|
249 |
}
|
sl@0
|
250 |
|
sl@0
|
251 |
void CPeriodUpdate::DoCancel()
|
sl@0
|
252 |
{
|
sl@0
|
253 |
}
|
sl@0
|
254 |
|
sl@0
|
255 |
void CPeriodUpdate::RunL()
|
sl@0
|
256 |
{
|
sl@0
|
257 |
SetActive();
|
sl@0
|
258 |
// Print RAM usage & up time
|
sl@0
|
259 |
|
sl@0
|
260 |
iUpTime++;
|
sl@0
|
261 |
TUint totmins=(iUpTime/60);
|
sl@0
|
262 |
TUint tothrs=(totmins/60);
|
sl@0
|
263 |
TInt mem=0;
|
sl@0
|
264 |
if (HAL::Get(HALData::EMemoryRAMFree, mem)==KErrNone)
|
sl@0
|
265 |
{
|
sl@0
|
266 |
console->SetPos(0,22);
|
sl@0
|
267 |
console->Printf(_L("mem (bytes) : %d\n"), mem);
|
sl@0
|
268 |
console->Printf(_L("up time : %dh:%dm:%ds\n"),
|
sl@0
|
269 |
tothrs, totmins%60, iUpTime%60);
|
sl@0
|
270 |
}
|
sl@0
|
271 |
iTimer.After(iStatus, 1000000);
|
sl@0
|
272 |
}
|
sl@0
|
273 |
|
sl@0
|
274 |
//-----------------------------------------------------------------------------
|
sl@0
|
275 |
/**
|
sl@0
|
276 |
Dismounts the originally mounted FS and optional primary extension from the drive and stores
|
sl@0
|
277 |
this information in the FS descriptor
|
sl@0
|
278 |
|
sl@0
|
279 |
@return on success returns a pointer to the instantinated FS descriptor
|
sl@0
|
280 |
*/
|
sl@0
|
281 |
static CFileSystemDescriptor* DoDismountOrginalFS(RFs& aFs, TInt aDrive)
|
sl@0
|
282 |
{
|
sl@0
|
283 |
TInt nRes;
|
sl@0
|
284 |
TBuf<128> fsName;
|
sl@0
|
285 |
TBuf<128> primaryExtName;
|
sl@0
|
286 |
TBool bDrvSync = EFalse;
|
sl@0
|
287 |
|
sl@0
|
288 |
Log(_L("# DoDismountOrginalFS drv:%d\n"), aDrive);
|
sl@0
|
289 |
|
sl@0
|
290 |
//-- 1. get file system name
|
sl@0
|
291 |
nRes = aFs.FileSystemName(fsName, aDrive);
|
sl@0
|
292 |
if(nRes != KErrNone)
|
sl@0
|
293 |
{//-- probably no file system installed at all
|
sl@0
|
294 |
return NULL;
|
sl@0
|
295 |
}
|
sl@0
|
296 |
|
sl@0
|
297 |
//-- 2. find out if the drive sync/async
|
sl@0
|
298 |
TPckgBuf<TBool> drvSyncBuf;
|
sl@0
|
299 |
nRes = aFs.QueryVolumeInfoExt(aDrive, EIsDriveSync, drvSyncBuf);
|
sl@0
|
300 |
if(nRes == KErrNone)
|
sl@0
|
301 |
{
|
sl@0
|
302 |
bDrvSync = drvSyncBuf();
|
sl@0
|
303 |
}
|
sl@0
|
304 |
|
sl@0
|
305 |
//-- 3. find out primary extension name if it is present; we will need to add it againt when mounting the FS
|
sl@0
|
306 |
//-- other extensions (non-primary) are not supported yet
|
sl@0
|
307 |
nRes = aFs.ExtensionName(primaryExtName, aDrive, 0);
|
sl@0
|
308 |
if(nRes != KErrNone)
|
sl@0
|
309 |
{
|
sl@0
|
310 |
primaryExtName.SetLength(0);
|
sl@0
|
311 |
}
|
sl@0
|
312 |
|
sl@0
|
313 |
//-- 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
|
314 |
nRes = aFs.ExtensionName(primaryExtName, aDrive, 1);
|
sl@0
|
315 |
if(nRes == KErrNone)
|
sl@0
|
316 |
{
|
sl@0
|
317 |
LogPrint(_L("Non-primary extensions are not supported!\n"));
|
sl@0
|
318 |
return NULL;
|
sl@0
|
319 |
}
|
sl@0
|
320 |
|
sl@0
|
321 |
Log(_L("# DoDismountOrginalFS FS:%S, Prim ext:%S, synch:%d\n"), &fsName, &primaryExtName, bDrvSync);
|
sl@0
|
322 |
|
sl@0
|
323 |
//-- create FS descriptor and dismount the FS
|
sl@0
|
324 |
CFileSystemDescriptor* pFsDesc = NULL;
|
sl@0
|
325 |
|
sl@0
|
326 |
TRAP(nRes, pFsDesc = CFileSystemDescriptor::NewL(fsName, primaryExtName, bDrvSync));
|
sl@0
|
327 |
if(nRes != KErrNone)
|
sl@0
|
328 |
return NULL; //-- OOM ?
|
sl@0
|
329 |
|
sl@0
|
330 |
nRes = aFs.DismountFileSystem(fsName, aDrive);
|
sl@0
|
331 |
if(nRes != KErrNone)
|
sl@0
|
332 |
{
|
sl@0
|
333 |
delete pFsDesc;
|
sl@0
|
334 |
pFsDesc = NULL;
|
sl@0
|
335 |
Log(_L("# DoDismountOrginalFS Dismounting Err:%d\n"), nRes);
|
sl@0
|
336 |
}
|
sl@0
|
337 |
|
sl@0
|
338 |
return pFsDesc;
|
sl@0
|
339 |
}
|
sl@0
|
340 |
|
sl@0
|
341 |
//-----------------------------------------------------------------------------
|
sl@0
|
342 |
/**
|
sl@0
|
343 |
Tries to restore the original FS on the drive using the FS descriptor provided
|
sl@0
|
344 |
@return standard error code.
|
sl@0
|
345 |
*/
|
sl@0
|
346 |
static TInt DoRestoreFS(RFs& aFs, TInt aDrive, CFileSystemDescriptor* apFsDesc)
|
sl@0
|
347 |
{
|
sl@0
|
348 |
TInt nRes;
|
sl@0
|
349 |
|
sl@0
|
350 |
Log(_L("# DoRestoreFS drv:%d\n"), aDrive);
|
sl@0
|
351 |
|
sl@0
|
352 |
//-- 1. check that there is no FS installed
|
sl@0
|
353 |
{
|
sl@0
|
354 |
TBuf<128> fsName;
|
sl@0
|
355 |
nRes = aFs.FileSystemName(fsName, aDrive);
|
sl@0
|
356 |
if(nRes == KErrNone)
|
sl@0
|
357 |
{//-- probably no file system installed at all
|
sl@0
|
358 |
Log(_L("# This drive already has FS intalled:%S \n"), &fsName);
|
sl@0
|
359 |
return KErrAlreadyExists;
|
sl@0
|
360 |
}
|
sl@0
|
361 |
}
|
sl@0
|
362 |
|
sl@0
|
363 |
TPtrC ptrN (apFsDesc->FsName());
|
sl@0
|
364 |
TPtrC ptrExt(apFsDesc->PrimaryExtName());
|
sl@0
|
365 |
Log(_L("# Mounting FS:%S, Prim ext:%S, synch:%d\n"), &ptrN, &ptrExt, apFsDesc->DriveIsSynch());
|
sl@0
|
366 |
|
sl@0
|
367 |
if(ptrExt.Length() >0)
|
sl@0
|
368 |
{//-- there is a primary extension to be mounted
|
sl@0
|
369 |
nRes = aFs.AddExtension(ptrExt);
|
sl@0
|
370 |
if(nRes != KErrNone && nRes != KErrAlreadyExists)
|
sl@0
|
371 |
{
|
sl@0
|
372 |
return nRes;
|
sl@0
|
373 |
}
|
sl@0
|
374 |
|
sl@0
|
375 |
nRes = aFs.MountFileSystem(ptrN, ptrExt, aDrive, apFsDesc->DriveIsSynch());
|
sl@0
|
376 |
}
|
sl@0
|
377 |
else
|
sl@0
|
378 |
{
|
sl@0
|
379 |
nRes = aFs.MountFileSystem(ptrN, aDrive, apFsDesc->DriveIsSynch());
|
sl@0
|
380 |
}
|
sl@0
|
381 |
|
sl@0
|
382 |
if(nRes != KErrNone)
|
sl@0
|
383 |
{
|
sl@0
|
384 |
Log(_L("# Mount failed! code:%d\n"),nRes);
|
sl@0
|
385 |
}
|
sl@0
|
386 |
|
sl@0
|
387 |
return nRes;
|
sl@0
|
388 |
}
|
sl@0
|
389 |
|
sl@0
|
390 |
|
sl@0
|
391 |
//-----------------------------------------------------------------------------
|
sl@0
|
392 |
/**
|
sl@0
|
393 |
Dismount the original FS from the drive and mount MsFS instead
|
sl@0
|
394 |
*/
|
sl@0
|
395 |
static void MountMsFs(TInt driveNumber)
|
sl@0
|
396 |
{
|
sl@0
|
397 |
TInt x = console->WhereX();
|
sl@0
|
398 |
TInt y = console->WhereY();
|
sl@0
|
399 |
|
sl@0
|
400 |
//-- 1. try dismounting the original FS
|
sl@0
|
401 |
CFileSystemDescriptor* fsDesc = DoDismountOrginalFS(fs, driveNumber);
|
sl@0
|
402 |
unmountedFsList[driveNumber] = fsDesc;
|
sl@0
|
403 |
|
sl@0
|
404 |
console->SetPos(0, 10);
|
sl@0
|
405 |
|
sl@0
|
406 |
if(fsDesc)
|
sl@0
|
407 |
{
|
sl@0
|
408 |
TPtrC ptrN(fsDesc->FsName());
|
sl@0
|
409 |
LogPrint(_L("drv:%d FS:%S Dismounted OK"),driveNumber, &ptrN);
|
sl@0
|
410 |
}
|
sl@0
|
411 |
else
|
sl@0
|
412 |
{
|
sl@0
|
413 |
LogPrint(_L("drv:%d Dismount FS Failed!"),driveNumber);
|
sl@0
|
414 |
}
|
sl@0
|
415 |
|
sl@0
|
416 |
console->ClearToEndOfLine();
|
sl@0
|
417 |
|
sl@0
|
418 |
//-- 2. try to mount the "MSFS"
|
sl@0
|
419 |
TInt error;
|
sl@0
|
420 |
error = fs.MountFileSystem(KMsFs, driveNumber);
|
sl@0
|
421 |
console->SetPos(0, 11);
|
sl@0
|
422 |
LogPrint(_L("MSFS Mount: %S (%d)"), (error?&KError:&KOk), error);
|
sl@0
|
423 |
console->ClearToEndOfLine();
|
sl@0
|
424 |
|
sl@0
|
425 |
if (!error)
|
sl@0
|
426 |
msfsMountedList[driveNumber] = ETrue;
|
sl@0
|
427 |
|
sl@0
|
428 |
// restore console position
|
sl@0
|
429 |
console->SetPos(x,y);
|
sl@0
|
430 |
}
|
sl@0
|
431 |
|
sl@0
|
432 |
//-----------------------------------------------------------------------------
|
sl@0
|
433 |
/**
|
sl@0
|
434 |
Dismount MsFS and mount the original FS
|
sl@0
|
435 |
*/
|
sl@0
|
436 |
static TInt RestoreMount(TInt driveNumber)
|
sl@0
|
437 |
{
|
sl@0
|
438 |
TInt err = KErrNone;
|
sl@0
|
439 |
|
sl@0
|
440 |
TInt x = console->WhereX();
|
sl@0
|
441 |
TInt y = console->WhereY();
|
sl@0
|
442 |
|
sl@0
|
443 |
//-- 1. try dismounting the "MSFS"
|
sl@0
|
444 |
if (msfsMountedList[driveNumber])
|
sl@0
|
445 |
{
|
sl@0
|
446 |
err = fs.DismountFileSystem(KMsFs, driveNumber);
|
sl@0
|
447 |
console->SetPos(0, 11);
|
sl@0
|
448 |
LogPrint(_L("MSFS Dismount:%S (%d)"), (err?&KError:&KOk), err);
|
sl@0
|
449 |
console->ClearToEndOfLine();
|
sl@0
|
450 |
if (err)
|
sl@0
|
451 |
return err;
|
sl@0
|
452 |
|
sl@0
|
453 |
msfsMountedList[driveNumber] = EFalse;
|
sl@0
|
454 |
}
|
sl@0
|
455 |
|
sl@0
|
456 |
//-- 2. try to mount the original FS back
|
sl@0
|
457 |
CFileSystemDescriptor* fsDesc = unmountedFsList[driveNumber];
|
sl@0
|
458 |
if(fsDesc)
|
sl@0
|
459 |
{
|
sl@0
|
460 |
err = DoRestoreFS(fs, driveNumber, fsDesc);
|
sl@0
|
461 |
|
sl@0
|
462 |
TPtrC ptrN(fsDesc->FsName());
|
sl@0
|
463 |
console->SetPos(0, 10);
|
sl@0
|
464 |
LogPrint(_L("%S Mount: %S (%d)"), &ptrN, (err?&KError:&KOk), err);
|
sl@0
|
465 |
console->ClearToEndOfLine();
|
sl@0
|
466 |
|
sl@0
|
467 |
delete fsDesc;
|
sl@0
|
468 |
unmountedFsList[driveNumber] = NULL;
|
sl@0
|
469 |
}
|
sl@0
|
470 |
|
sl@0
|
471 |
|
sl@0
|
472 |
// restore console position
|
sl@0
|
473 |
console->SetPos(x,y);
|
sl@0
|
474 |
return err;
|
sl@0
|
475 |
}
|
sl@0
|
476 |
|
sl@0
|
477 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
478 |
//
|
sl@0
|
479 |
// CPropertyWatch
|
sl@0
|
480 |
// An active object that tracks changes to the KUsbMsDriveState properties
|
sl@0
|
481 |
//
|
sl@0
|
482 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
483 |
|
sl@0
|
484 |
CPropertyWatch* CPropertyWatch::NewLC(TUsbMsDriveState_Subkey aSubkey, PropertyHandlers::THandler aHandler)
|
sl@0
|
485 |
{
|
sl@0
|
486 |
CPropertyWatch* me=new(ELeave) CPropertyWatch(aHandler);
|
sl@0
|
487 |
CleanupStack::PushL(me);
|
sl@0
|
488 |
me->ConstructL(aSubkey);
|
sl@0
|
489 |
return me;
|
sl@0
|
490 |
}
|
sl@0
|
491 |
|
sl@0
|
492 |
CPropertyWatch::CPropertyWatch(PropertyHandlers::THandler aHandler)
|
sl@0
|
493 |
: CActive(0), iHandler(aHandler)
|
sl@0
|
494 |
{}
|
sl@0
|
495 |
|
sl@0
|
496 |
void CPropertyWatch::ConstructL(TUsbMsDriveState_Subkey aSubkey)
|
sl@0
|
497 |
{
|
sl@0
|
498 |
User::LeaveIfError(iProperty.Attach(KUsbMsDriveState_Category, aSubkey));
|
sl@0
|
499 |
CActiveScheduler::Add(this);
|
sl@0
|
500 |
// initial subscription and process current property value
|
sl@0
|
501 |
RunL();
|
sl@0
|
502 |
}
|
sl@0
|
503 |
|
sl@0
|
504 |
CPropertyWatch::~CPropertyWatch()
|
sl@0
|
505 |
{
|
sl@0
|
506 |
Cancel();
|
sl@0
|
507 |
iProperty.Close();
|
sl@0
|
508 |
}
|
sl@0
|
509 |
|
sl@0
|
510 |
void CPropertyWatch::DoCancel()
|
sl@0
|
511 |
{
|
sl@0
|
512 |
iProperty.Cancel();
|
sl@0
|
513 |
}
|
sl@0
|
514 |
|
sl@0
|
515 |
void CPropertyWatch::RunL()
|
sl@0
|
516 |
{
|
sl@0
|
517 |
// resubscribe before processing new value to prevent missing updates
|
sl@0
|
518 |
iProperty.Subscribe(iStatus);
|
sl@0
|
519 |
SetActive();
|
sl@0
|
520 |
|
sl@0
|
521 |
iHandler(iProperty);
|
sl@0
|
522 |
}
|
sl@0
|
523 |
|
sl@0
|
524 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
525 |
//
|
sl@0
|
526 |
// CUsbWatch
|
sl@0
|
527 |
//
|
sl@0
|
528 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
529 |
|
sl@0
|
530 |
CUsbWatch* CUsbWatch::NewLC(TAny* aUsb)
|
sl@0
|
531 |
{
|
sl@0
|
532 |
CUsbWatch* me=new(ELeave) CUsbWatch(aUsb);
|
sl@0
|
533 |
CleanupStack::PushL(me);
|
sl@0
|
534 |
me->ConstructL();
|
sl@0
|
535 |
return me;
|
sl@0
|
536 |
}
|
sl@0
|
537 |
|
sl@0
|
538 |
CUsbWatch::CUsbWatch(TAny* aUsb)
|
sl@0
|
539 |
:
|
sl@0
|
540 |
CActive(0),
|
sl@0
|
541 |
iUsb(aUsb),
|
sl@0
|
542 |
iUsbDeviceState(EUsbDeviceStateUndefined),
|
sl@0
|
543 |
iWasConfigured(EFalse)
|
sl@0
|
544 |
{}
|
sl@0
|
545 |
|
sl@0
|
546 |
void CUsbWatch::ConstructL()
|
sl@0
|
547 |
{
|
sl@0
|
548 |
CActiveScheduler::Add(this);
|
sl@0
|
549 |
RunL();
|
sl@0
|
550 |
}
|
sl@0
|
551 |
|
sl@0
|
552 |
CUsbWatch::~CUsbWatch()
|
sl@0
|
553 |
{
|
sl@0
|
554 |
Cancel();
|
sl@0
|
555 |
// iUsb.DeviceStateNotificationCancel();
|
sl@0
|
556 |
if (gSharedChunkLdd)
|
sl@0
|
557 |
((RDevUsbcScClient*)iUsb)->AlternateDeviceStatusNotifyCancel();
|
sl@0
|
558 |
else
|
sl@0
|
559 |
((RDevUsbcClient*)iUsb)->AlternateDeviceStatusNotifyCancel();
|
sl@0
|
560 |
}
|
sl@0
|
561 |
|
sl@0
|
562 |
void CUsbWatch::DoCancel()
|
sl@0
|
563 |
{
|
sl@0
|
564 |
// iUsb.DeviceStateNotificationCancel();
|
sl@0
|
565 |
if (gSharedChunkLdd)
|
sl@0
|
566 |
((RDevUsbcScClient*)iUsb)->AlternateDeviceStatusNotifyCancel();
|
sl@0
|
567 |
else
|
sl@0
|
568 |
((RDevUsbcClient*)iUsb)->AlternateDeviceStatusNotifyCancel();
|
sl@0
|
569 |
}
|
sl@0
|
570 |
|
sl@0
|
571 |
static TBool IsDriveConnected(TInt driveStatusIndex)
|
sl@0
|
572 |
{
|
sl@0
|
573 |
TInt driveStatus = PropertyHandlers::allDrivesStatus[2*driveStatusIndex+1];
|
sl@0
|
574 |
return driveStatus >= EUsbMsDriveState_Connected ? ETrue : EFalse;
|
sl@0
|
575 |
}
|
sl@0
|
576 |
|
sl@0
|
577 |
static TChar DriveNumberToLetter(TInt driveNumber)
|
sl@0
|
578 |
{
|
sl@0
|
579 |
TChar driveLetter = '?';
|
sl@0
|
580 |
fs.DriveToChar(driveNumber, driveLetter);
|
sl@0
|
581 |
return driveLetter;
|
sl@0
|
582 |
}
|
sl@0
|
583 |
|
sl@0
|
584 |
static TBool IsDriveInMountList(TUint driveLetter)
|
sl@0
|
585 |
{
|
sl@0
|
586 |
TUint16 driveLetter16 = static_cast<TUint16>(driveLetter);
|
sl@0
|
587 |
return(!mountList.Length() || KErrNotFound != mountList.Find(&driveLetter16, 1));
|
sl@0
|
588 |
}
|
sl@0
|
589 |
|
sl@0
|
590 |
void CUsbWatch::RunL()
|
sl@0
|
591 |
{
|
sl@0
|
592 |
// RDebug::Print(_L(">> CUsbWatch[%d] %d"), iUsbDeviceState, iWasConfigured);
|
sl@0
|
593 |
|
sl@0
|
594 |
// const TUint stateMask = 0xFF;
|
sl@0
|
595 |
// iUsb.DeviceStateNotification(stateMask, iUsbDeviceState, iStatus);
|
sl@0
|
596 |
if (gSharedChunkLdd)
|
sl@0
|
597 |
((RDevUsbcScClient*)iUsb)->AlternateDeviceStatusNotify(iStatus, iUsbDeviceState);
|
sl@0
|
598 |
else
|
sl@0
|
599 |
((RDevUsbcClient*)iUsb)->AlternateDeviceStatusNotify(iStatus, iUsbDeviceState);
|
sl@0
|
600 |
|
sl@0
|
601 |
SetActive();
|
sl@0
|
602 |
|
sl@0
|
603 |
//RDebug::Print(_L("CUsbWatch DeviceStateNotification: iUsbDeviceState=%d"), iUsbDeviceState);
|
sl@0
|
604 |
|
sl@0
|
605 |
// If the cable is disconnected, unmount all the connected drives.
|
sl@0
|
606 |
if(iWasConfigured && iUsbDeviceState == EUsbDeviceStateUndefined)
|
sl@0
|
607 |
{
|
sl@0
|
608 |
for(TInt i=0; i<PropertyHandlers::allDrivesStatus.Length()/2; i++)
|
sl@0
|
609 |
{
|
sl@0
|
610 |
if(IsDriveConnected(i))
|
sl@0
|
611 |
{
|
sl@0
|
612 |
//RDebug::Print(_L("CUsbWatch calling RestoreMount"));
|
sl@0
|
613 |
RestoreMount(PropertyHandlers::allDrivesStatus[2*i]);
|
sl@0
|
614 |
#ifdef USB_BOOT_LOADER
|
sl@0
|
615 |
// exit and reboot
|
sl@0
|
616 |
CActiveScheduler::Stop();
|
sl@0
|
617 |
#endif
|
sl@0
|
618 |
}
|
sl@0
|
619 |
}
|
sl@0
|
620 |
|
sl@0
|
621 |
iWasConfigured = EFalse;
|
sl@0
|
622 |
}
|
sl@0
|
623 |
|
sl@0
|
624 |
// If cable is connected, mount all drives in the auto-mount list.
|
sl@0
|
625 |
// This is done for performance, since if this is not done here,
|
sl@0
|
626 |
// mounting will happen later after each drive enters the
|
sl@0
|
627 |
// Connecting state.
|
sl@0
|
628 |
if(iUsbDeviceState == EUsbDeviceStateConfigured)
|
sl@0
|
629 |
{
|
sl@0
|
630 |
for(TInt i=0; i<PropertyHandlers::allDrivesStatus.Length()/2; i++)
|
sl@0
|
631 |
{
|
sl@0
|
632 |
TInt driveNumber = PropertyHandlers::allDrivesStatus[2*i];
|
sl@0
|
633 |
if(!IsDriveConnected(i) && IsDriveInMountList(DriveNumberToLetter(driveNumber)))
|
sl@0
|
634 |
{
|
sl@0
|
635 |
//RDebug::Print(_L("CUsbWatch calling MountMsFs"));
|
sl@0
|
636 |
MountMsFs(driveNumber);
|
sl@0
|
637 |
}
|
sl@0
|
638 |
}
|
sl@0
|
639 |
|
sl@0
|
640 |
iWasConfigured = ETrue;
|
sl@0
|
641 |
}
|
sl@0
|
642 |
}
|
sl@0
|
643 |
|
sl@0
|
644 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
645 |
//
|
sl@0
|
646 |
// PropertyHandlers
|
sl@0
|
647 |
//
|
sl@0
|
648 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
649 |
|
sl@0
|
650 |
TBuf8<16> PropertyHandlers::allDrivesStatus;
|
sl@0
|
651 |
TUsbMsBytesTransferred PropertyHandlers::iKBytesRead;
|
sl@0
|
652 |
TUsbMsBytesTransferred PropertyHandlers::iKBytesWritten;
|
sl@0
|
653 |
TInt PropertyHandlers::iMediaError;
|
sl@0
|
654 |
|
sl@0
|
655 |
void PropertyHandlers::Read(RProperty& aProperty)
|
sl@0
|
656 |
{
|
sl@0
|
657 |
Transferred(aProperty, iKBytesRead);
|
sl@0
|
658 |
}
|
sl@0
|
659 |
|
sl@0
|
660 |
void PropertyHandlers::Written(RProperty& aProperty)
|
sl@0
|
661 |
{
|
sl@0
|
662 |
Transferred(aProperty, iKBytesWritten);
|
sl@0
|
663 |
}
|
sl@0
|
664 |
|
sl@0
|
665 |
void PropertyHandlers::Transferred(RProperty& aProperty, TUsbMsBytesTransferred& aReadOrWritten)
|
sl@0
|
666 |
{
|
sl@0
|
667 |
console->SetPos(0,1);
|
sl@0
|
668 |
console->Printf(_L("KB R/W: "));
|
sl@0
|
669 |
TInt err = aProperty.Get(aReadOrWritten);
|
sl@0
|
670 |
if(err == KErrNone)
|
sl@0
|
671 |
{
|
sl@0
|
672 |
for(TInt i = 0; i < allDrivesStatus.Length()/2; i++)
|
sl@0
|
673 |
{
|
sl@0
|
674 |
console->Printf(KBytesTransferredFmt, (char)DriveNumberToLetter(allDrivesStatus[2*i]), iKBytesRead[i], iKBytesWritten[i]);
|
sl@0
|
675 |
}
|
sl@0
|
676 |
console->ClearToEndOfLine();
|
sl@0
|
677 |
}
|
sl@0
|
678 |
else
|
sl@0
|
679 |
{
|
sl@0
|
680 |
console->Printf(KErrFmt, err);
|
sl@0
|
681 |
}
|
sl@0
|
682 |
}
|
sl@0
|
683 |
|
sl@0
|
684 |
void PropertyHandlers::DriveStatus(RProperty& aProperty)
|
sl@0
|
685 |
{
|
sl@0
|
686 |
// RDebug::Print(_L(">> PropertyHandlers::DriveStatus"));
|
sl@0
|
687 |
TInt err = aProperty.Get(allDrivesStatus);
|
sl@0
|
688 |
console->SetPos(0,0);
|
sl@0
|
689 |
if(err == KErrNone)
|
sl@0
|
690 |
{
|
sl@0
|
691 |
LogPrint(_L("Status: "));
|
sl@0
|
692 |
for(TInt i = 0; i < allDrivesStatus.Length()/2; i++)
|
sl@0
|
693 |
{
|
sl@0
|
694 |
TInt driveNumber = allDrivesStatus[2*i];
|
sl@0
|
695 |
TInt driveStatus = allDrivesStatus[2*i+1];
|
sl@0
|
696 |
TChar driveLetter = DriveNumberToLetter(driveNumber);
|
sl@0
|
697 |
|
sl@0
|
698 |
// RDebug::Print(_L("%c:%d "), (char)driveLetter, driveStatus);
|
sl@0
|
699 |
|
sl@0
|
700 |
switch(driveStatus)
|
sl@0
|
701 |
{
|
sl@0
|
702 |
case EUsbMsDriveState_Disconnected:
|
sl@0
|
703 |
{
|
sl@0
|
704 |
LogPrint(_L("%c:%d:Disconnected "), (char)driveLetter, driveStatus);
|
sl@0
|
705 |
break;
|
sl@0
|
706 |
}
|
sl@0
|
707 |
case EUsbMsDriveState_Connecting:
|
sl@0
|
708 |
{
|
sl@0
|
709 |
LogPrint(_L("%c:%d:Connecting "), (char)driveLetter, driveStatus);
|
sl@0
|
710 |
break;
|
sl@0
|
711 |
}
|
sl@0
|
712 |
case EUsbMsDriveState_Connected:
|
sl@0
|
713 |
{
|
sl@0
|
714 |
LogPrint(_L("%c:%d:Connected "), (char)driveLetter, driveStatus);
|
sl@0
|
715 |
break;
|
sl@0
|
716 |
}
|
sl@0
|
717 |
case EUsbMsDriveState_Disconnecting:
|
sl@0
|
718 |
{
|
sl@0
|
719 |
LogPrint(_L("%c:%d:Disconnecting"), (char)driveLetter, driveStatus);
|
sl@0
|
720 |
break;
|
sl@0
|
721 |
}
|
sl@0
|
722 |
case EUsbMsDriveState_Active:
|
sl@0
|
723 |
{
|
sl@0
|
724 |
LogPrint(_L("%c:%d:Active "), (char)driveLetter, driveStatus);
|
sl@0
|
725 |
break;
|
sl@0
|
726 |
}
|
sl@0
|
727 |
case EUsbMsDriveState_Locked:
|
sl@0
|
728 |
{
|
sl@0
|
729 |
LogPrint(_L("%c:%d:Locked "), (char)driveLetter, driveStatus);
|
sl@0
|
730 |
break;
|
sl@0
|
731 |
}
|
sl@0
|
732 |
case EUsbMsDriveState_MediaNotPresent:
|
sl@0
|
733 |
{
|
sl@0
|
734 |
LogPrint(_L("%c:%d:Not Present "), (char)driveLetter, driveStatus);
|
sl@0
|
735 |
break;
|
sl@0
|
736 |
}
|
sl@0
|
737 |
case EUsbMsDriveState_Removed:
|
sl@0
|
738 |
{
|
sl@0
|
739 |
LogPrint(_L("%c:%d:Removed "), (char)driveLetter, driveStatus);
|
sl@0
|
740 |
break;
|
sl@0
|
741 |
}
|
sl@0
|
742 |
case EUsbMsDriveState_Error:
|
sl@0
|
743 |
{
|
sl@0
|
744 |
LogPrint(_L("%c:%d:Error "), (char)driveLetter, driveStatus);
|
sl@0
|
745 |
break;
|
sl@0
|
746 |
}
|
sl@0
|
747 |
default :
|
sl@0
|
748 |
{
|
sl@0
|
749 |
LogPrint(_L("%c:%d:Unknown "), (char)driveLetter, driveStatus);
|
sl@0
|
750 |
break;
|
sl@0
|
751 |
}
|
sl@0
|
752 |
}
|
sl@0
|
753 |
|
sl@0
|
754 |
if(IsDriveInMountList(driveLetter))
|
sl@0
|
755 |
{
|
sl@0
|
756 |
#ifndef USB_BOOT_LOADER
|
sl@0
|
757 |
if (driveStatus == EUsbMsDriveState_Connecting)
|
sl@0
|
758 |
{
|
sl@0
|
759 |
MountMsFs(driveNumber);
|
sl@0
|
760 |
}
|
sl@0
|
761 |
else if (driveStatus == EUsbMsDriveState_Disconnected)
|
sl@0
|
762 |
{
|
sl@0
|
763 |
RestoreMount(driveNumber);
|
sl@0
|
764 |
}
|
sl@0
|
765 |
#else
|
sl@0
|
766 |
if (driveStatus == EUsbMsDriveState_Disconnecting)
|
sl@0
|
767 |
{
|
sl@0
|
768 |
RestoreMount(driveNumber);
|
sl@0
|
769 |
}
|
sl@0
|
770 |
else if (driveStatus == EUsbMsDriveState_Disconnected)
|
sl@0
|
771 |
{
|
sl@0
|
772 |
static TBool firstTime = ETrue;
|
sl@0
|
773 |
|
sl@0
|
774 |
if (!firstTime)
|
sl@0
|
775 |
{
|
sl@0
|
776 |
RDebug::Print(_L("Eject..."));
|
sl@0
|
777 |
// Exit and reboot the target upon receipt of an eject
|
sl@0
|
778 |
CActiveScheduler::Stop();
|
sl@0
|
779 |
rebootit();
|
sl@0
|
780 |
}
|
sl@0
|
781 |
|
sl@0
|
782 |
firstTime = EFalse;
|
sl@0
|
783 |
}
|
sl@0
|
784 |
#endif
|
sl@0
|
785 |
else
|
sl@0
|
786 |
{
|
sl@0
|
787 |
//RDebug::Print(_L("PropertyHandlers::DriveStatus: nothing to do"));
|
sl@0
|
788 |
}
|
sl@0
|
789 |
}
|
sl@0
|
790 |
else
|
sl@0
|
791 |
{
|
sl@0
|
792 |
//RDebug::Print(_L("PropertyHandlers::DriveStatus: %c: is not in mountList\n"), driveLetter);
|
sl@0
|
793 |
}
|
sl@0
|
794 |
}
|
sl@0
|
795 |
}
|
sl@0
|
796 |
else
|
sl@0
|
797 |
{
|
sl@0
|
798 |
LogPrint(KErrFmt, err);
|
sl@0
|
799 |
}
|
sl@0
|
800 |
|
sl@0
|
801 |
//RDebug::Print(_L("<< PropertyHandlers::DriveStatus"));
|
sl@0
|
802 |
}
|
sl@0
|
803 |
|
sl@0
|
804 |
void PropertyHandlers::MediaError(RProperty& aProperty)
|
sl@0
|
805 |
{
|
sl@0
|
806 |
TInt err = aProperty.Get(iMediaError);
|
sl@0
|
807 |
if(err != KErrNone)
|
sl@0
|
808 |
{
|
sl@0
|
809 |
// RDebug::Printf("RProperty::Get returned %d", err);
|
sl@0
|
810 |
return;
|
sl@0
|
811 |
}
|
sl@0
|
812 |
|
sl@0
|
813 |
//RDebug::Printf("PropertyHandlers::MediaError %x", iMediaError);
|
sl@0
|
814 |
|
sl@0
|
815 |
TInt x = console->WhereX();
|
sl@0
|
816 |
TInt y = console->WhereY();
|
sl@0
|
817 |
Clear(27,1);
|
sl@0
|
818 |
LogPrint(_L("Media Error %x"), iMediaError);
|
sl@0
|
819 |
// restore console position
|
sl@0
|
820 |
console->SetPos(x,y);
|
sl@0
|
821 |
}
|
sl@0
|
822 |
|
sl@0
|
823 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
824 |
//
|
sl@0
|
825 |
// CMessageKeyProcessor
|
sl@0
|
826 |
//
|
sl@0
|
827 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
828 |
CMessageKeyProcessor::CMessageKeyProcessor(CConsoleBase* aConsole)
|
sl@0
|
829 |
: CActive(CActive::EPriorityUserInput), iConsole(aConsole)
|
sl@0
|
830 |
{
|
sl@0
|
831 |
}
|
sl@0
|
832 |
|
sl@0
|
833 |
CMessageKeyProcessor* CMessageKeyProcessor::NewLC(CConsoleBase* aConsole
|
sl@0
|
834 |
)
|
sl@0
|
835 |
{
|
sl@0
|
836 |
CMessageKeyProcessor* self=new (ELeave) CMessageKeyProcessor(aConsole);
|
sl@0
|
837 |
CleanupStack::PushL(self);
|
sl@0
|
838 |
self->ConstructL();
|
sl@0
|
839 |
return self;
|
sl@0
|
840 |
}
|
sl@0
|
841 |
|
sl@0
|
842 |
CMessageKeyProcessor* CMessageKeyProcessor::NewL(CConsoleBase* aConsole
|
sl@0
|
843 |
)
|
sl@0
|
844 |
{
|
sl@0
|
845 |
CMessageKeyProcessor* self = NewLC(aConsole);
|
sl@0
|
846 |
CleanupStack::Pop();
|
sl@0
|
847 |
return self;
|
sl@0
|
848 |
}
|
sl@0
|
849 |
|
sl@0
|
850 |
void CMessageKeyProcessor::ConstructL()
|
sl@0
|
851 |
{
|
sl@0
|
852 |
// Add to active scheduler
|
sl@0
|
853 |
CActiveScheduler::Add(this);
|
sl@0
|
854 |
RequestCharacter();
|
sl@0
|
855 |
}
|
sl@0
|
856 |
|
sl@0
|
857 |
#ifndef USB_BOOT_LOADER
|
sl@0
|
858 |
void CMessageKeyProcessor::MakePassword(TMediaPassword &aPassword)
|
sl@0
|
859 |
{
|
sl@0
|
860 |
// Create password with same format as eshell and S60
|
sl@0
|
861 |
TBuf<3> password(KDefPwd);
|
sl@0
|
862 |
|
sl@0
|
863 |
// fill aPassword with contents of password, not converting to ASCII
|
sl@0
|
864 |
const TInt byteLen = password.Length() * 2;
|
sl@0
|
865 |
aPassword.Copy(reinterpret_cast<const TUint8 *>(password.Ptr()), byteLen);
|
sl@0
|
866 |
}
|
sl@0
|
867 |
#endif
|
sl@0
|
868 |
|
sl@0
|
869 |
|
sl@0
|
870 |
CMessageKeyProcessor::~CMessageKeyProcessor()
|
sl@0
|
871 |
{
|
sl@0
|
872 |
// Make sure we're cancelled
|
sl@0
|
873 |
Cancel();
|
sl@0
|
874 |
}
|
sl@0
|
875 |
|
sl@0
|
876 |
void CMessageKeyProcessor::DoCancel()
|
sl@0
|
877 |
{
|
sl@0
|
878 |
iConsole->ReadCancel();
|
sl@0
|
879 |
}
|
sl@0
|
880 |
|
sl@0
|
881 |
void CMessageKeyProcessor::RunL()
|
sl@0
|
882 |
{
|
sl@0
|
883 |
// Handle completed request
|
sl@0
|
884 |
ProcessKeyPress(TChar(iConsole->KeyCode()));
|
sl@0
|
885 |
}
|
sl@0
|
886 |
|
sl@0
|
887 |
void CMessageKeyProcessor::RequestCharacter()
|
sl@0
|
888 |
{
|
sl@0
|
889 |
// A request is issued to the CConsoleBase to accept a
|
sl@0
|
890 |
// character from the keyboard.
|
sl@0
|
891 |
iConsole->Read(iStatus);
|
sl@0
|
892 |
SetActive();
|
sl@0
|
893 |
}
|
sl@0
|
894 |
|
sl@0
|
895 |
void CMessageKeyProcessor::ProcessKeyPress(TChar aChar)
|
sl@0
|
896 |
{
|
sl@0
|
897 |
#ifndef USB_BOOT_LOADER
|
sl@0
|
898 |
TInt error = KErrNone;
|
sl@0
|
899 |
#endif
|
sl@0
|
900 |
#if defined(_DEBUG)
|
sl@0
|
901 |
static TBool tracetoggle=EFalse;
|
sl@0
|
902 |
#endif
|
sl@0
|
903 |
|
sl@0
|
904 |
switch(aChar)
|
sl@0
|
905 |
{
|
sl@0
|
906 |
case 'q':
|
sl@0
|
907 |
case 'Q':
|
sl@0
|
908 |
case EKeyEscape:
|
sl@0
|
909 |
{
|
sl@0
|
910 |
TInt err = KErrNone;
|
sl@0
|
911 |
for(TInt j=0; j<KMaxDrives; j++)
|
sl@0
|
912 |
{
|
sl@0
|
913 |
err = RestoreMount(j);
|
sl@0
|
914 |
|
sl@0
|
915 |
if (err)
|
sl@0
|
916 |
{
|
sl@0
|
917 |
// Mount is busy/locked and can not be restored.
|
sl@0
|
918 |
break;
|
sl@0
|
919 |
}
|
sl@0
|
920 |
|
sl@0
|
921 |
}
|
sl@0
|
922 |
|
sl@0
|
923 |
if (err == KErrNone)
|
sl@0
|
924 |
{
|
sl@0
|
925 |
#ifdef USB_BOOT_LOADER
|
sl@0
|
926 |
gRebootDelay=0; // Force reboot to occur immediately
|
sl@0
|
927 |
#endif
|
sl@0
|
928 |
CActiveScheduler::Stop();
|
sl@0
|
929 |
return;
|
sl@0
|
930 |
}
|
sl@0
|
931 |
|
sl@0
|
932 |
}
|
sl@0
|
933 |
break;
|
sl@0
|
934 |
|
sl@0
|
935 |
#if defined(_DEBUG)
|
sl@0
|
936 |
case 't':
|
sl@0
|
937 |
case 'T':
|
sl@0
|
938 |
tracetoggle=!tracetoggle;
|
sl@0
|
939 |
if (tracetoggle) // 0x44008401
|
sl@0
|
940 |
User::SetDebugMask(KHARDWARE|KDLL|KSCRATCH|KPOWER|KMEMTRACE);
|
sl@0
|
941 |
else
|
sl@0
|
942 |
User::SetDebugMask(0);
|
sl@0
|
943 |
break;
|
sl@0
|
944 |
#endif
|
sl@0
|
945 |
|
sl@0
|
946 |
#ifndef USB_BOOT_LOADER
|
sl@0
|
947 |
case 'd':
|
sl@0
|
948 |
case 'D':
|
sl@0
|
949 |
if(++selectedDriveIndex >= PropertyHandlers::allDrivesStatus.Length()/2)
|
sl@0
|
950 |
{
|
sl@0
|
951 |
selectedDriveIndex = 0;
|
sl@0
|
952 |
}
|
sl@0
|
953 |
ShowDriveSelection();
|
sl@0
|
954 |
break;
|
sl@0
|
955 |
|
sl@0
|
956 |
case 'm':
|
sl@0
|
957 |
case 'M':
|
sl@0
|
958 |
if(PropertyHandlers::allDrivesStatus.Length())
|
sl@0
|
959 |
{
|
sl@0
|
960 |
MountMsFs(PropertyHandlers::allDrivesStatus[selectedDriveIndex*2]);
|
sl@0
|
961 |
}
|
sl@0
|
962 |
break;
|
sl@0
|
963 |
|
sl@0
|
964 |
case 'u':
|
sl@0
|
965 |
case 'U':
|
sl@0
|
966 |
if(PropertyHandlers::allDrivesStatus.Length())
|
sl@0
|
967 |
{
|
sl@0
|
968 |
RestoreMount(PropertyHandlers::allDrivesStatus[selectedDriveIndex*2]);
|
sl@0
|
969 |
}
|
sl@0
|
970 |
break;
|
sl@0
|
971 |
|
sl@0
|
972 |
case 'l':
|
sl@0
|
973 |
{
|
sl@0
|
974 |
// lock unprotected drive
|
sl@0
|
975 |
TMediaPassword password;
|
sl@0
|
976 |
MakePassword(password);
|
sl@0
|
977 |
|
sl@0
|
978 |
_LIT(KEmpty, "");
|
sl@0
|
979 |
TMediaPassword nul;
|
sl@0
|
980 |
nul.Copy(KEmpty);
|
sl@0
|
981 |
error = fs.LockDrive(PropertyHandlers::allDrivesStatus[selectedDriveIndex*2],
|
sl@0
|
982 |
nul, password, ETrue);
|
sl@0
|
983 |
console->SetPos(0,9);
|
sl@0
|
984 |
LogPrint(_L("LockDrive %S (%d)"), (error?&KError:&KOk), error);
|
sl@0
|
985 |
break;
|
sl@0
|
986 |
}
|
sl@0
|
987 |
|
sl@0
|
988 |
case 'L':
|
sl@0
|
989 |
{
|
sl@0
|
990 |
// lock password protected drive
|
sl@0
|
991 |
TMediaPassword password;
|
sl@0
|
992 |
MakePassword(password);
|
sl@0
|
993 |
error = fs.LockDrive(PropertyHandlers::allDrivesStatus[selectedDriveIndex*2],
|
sl@0
|
994 |
password, password, ETrue);
|
sl@0
|
995 |
console->SetPos(0,9);
|
sl@0
|
996 |
LogPrint(_L("LockDrive %S (%d)"), (error?&KError:&KOk), error);
|
sl@0
|
997 |
break;
|
sl@0
|
998 |
}
|
sl@0
|
999 |
|
sl@0
|
1000 |
case 'n':
|
sl@0
|
1001 |
case 'N':
|
sl@0
|
1002 |
{
|
sl@0
|
1003 |
TMediaPassword password;
|
sl@0
|
1004 |
MakePassword(password);
|
sl@0
|
1005 |
error = fs.UnlockDrive(PropertyHandlers::allDrivesStatus[selectedDriveIndex*2],
|
sl@0
|
1006 |
password, ETrue);
|
sl@0
|
1007 |
Clear(9);
|
sl@0
|
1008 |
LogPrint(_L("UnlockDrive %S (%d)"), (error?&KError:&KOk), error);
|
sl@0
|
1009 |
}
|
sl@0
|
1010 |
break;
|
sl@0
|
1011 |
|
sl@0
|
1012 |
case 'c':
|
sl@0
|
1013 |
case 'C':
|
sl@0
|
1014 |
{
|
sl@0
|
1015 |
TMediaPassword password;
|
sl@0
|
1016 |
MakePassword(password);
|
sl@0
|
1017 |
error = fs.ClearPassword(PropertyHandlers::allDrivesStatus[selectedDriveIndex*2],
|
sl@0
|
1018 |
password);
|
sl@0
|
1019 |
Clear(9);
|
sl@0
|
1020 |
LogPrint(_L("ClearPassword %S (%d)"), (error?&KError:&KOk), error);
|
sl@0
|
1021 |
}
|
sl@0
|
1022 |
break;
|
sl@0
|
1023 |
#endif
|
sl@0
|
1024 |
|
sl@0
|
1025 |
default:
|
sl@0
|
1026 |
break;
|
sl@0
|
1027 |
}
|
sl@0
|
1028 |
RequestCharacter();
|
sl@0
|
1029 |
}
|
sl@0
|
1030 |
|
sl@0
|
1031 |
#ifdef USB_BOOT_LOADER
|
sl@0
|
1032 |
|
sl@0
|
1033 |
static void RunMode()
|
sl@0
|
1034 |
{
|
sl@0
|
1035 |
RFs fs;
|
sl@0
|
1036 |
|
sl@0
|
1037 |
TInt r=fs.Connect();
|
sl@0
|
1038 |
if (r!=KErrNone)
|
sl@0
|
1039 |
{
|
sl@0
|
1040 |
RDebug::Print(_L("Help\n"));
|
sl@0
|
1041 |
return;
|
sl@0
|
1042 |
}
|
sl@0
|
1043 |
|
sl@0
|
1044 |
TFileName sessionpath = _L("?:\\");
|
sl@0
|
1045 |
|
sl@0
|
1046 |
TDriveList drivelist;
|
sl@0
|
1047 |
fs.DriveList(drivelist);
|
sl@0
|
1048 |
for (TInt driveno=EDriveC; driveno<=EDriveZ; driveno++)
|
sl@0
|
1049 |
{
|
sl@0
|
1050 |
if (!drivelist[driveno])
|
sl@0
|
1051 |
continue;
|
sl@0
|
1052 |
|
sl@0
|
1053 |
sessionpath[0]='A'+driveno;
|
sl@0
|
1054 |
|
sl@0
|
1055 |
/*
|
sl@0
|
1056 |
If a filename with the format EJECTDELAY.nnn is found, delay any reboot
|
sl@0
|
1057 |
action by "nnn" seconds
|
sl@0
|
1058 |
*/
|
sl@0
|
1059 |
CDir* dir;
|
sl@0
|
1060 |
TFindFile finder(fs);
|
sl@0
|
1061 |
r=finder.FindWildByPath(_L("EJECTDELAY.*"),&sessionpath,dir);
|
sl@0
|
1062 |
if (r == KErrNone)
|
sl@0
|
1063 |
{ // Found one or more files
|
sl@0
|
1064 |
TEntry entry;
|
sl@0
|
1065 |
entry=(*dir)[0];
|
sl@0
|
1066 |
|
sl@0
|
1067 |
TParse parser;
|
sl@0
|
1068 |
parser.Set(entry.iName, NULL, NULL);
|
sl@0
|
1069 |
TPtrC tok = parser.Ext();
|
sl@0
|
1070 |
TLex lex(tok);
|
sl@0
|
1071 |
lex.SkipAndMark(1);
|
sl@0
|
1072 |
tok.Set(lex.NextToken());
|
sl@0
|
1073 |
lex.Assign(tok);
|
sl@0
|
1074 |
|
sl@0
|
1075 |
r=lex.Val(gRebootDelay);
|
sl@0
|
1076 |
if (r!=KErrNone)
|
sl@0
|
1077 |
continue;
|
sl@0
|
1078 |
}
|
sl@0
|
1079 |
}
|
sl@0
|
1080 |
}
|
sl@0
|
1081 |
|
sl@0
|
1082 |
#endif
|
sl@0
|
1083 |
|
sl@0
|
1084 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
1085 |
//
|
sl@0
|
1086 |
// Application entry point
|
sl@0
|
1087 |
//
|
sl@0
|
1088 |
//////////////////////////////////////////////////////////////////////////////
|
sl@0
|
1089 |
static void RunAppL()
|
sl@0
|
1090 |
{
|
sl@0
|
1091 |
#ifdef USB_BOOT_LOADER
|
sl@0
|
1092 |
RunMode();
|
sl@0
|
1093 |
#endif
|
sl@0
|
1094 |
|
sl@0
|
1095 |
TInt error = KErrUnknown;
|
sl@0
|
1096 |
|
sl@0
|
1097 |
//RDebug::Print(_L("USBMSAPP: Creating console\n"));
|
sl@0
|
1098 |
|
sl@0
|
1099 |
#ifdef USB_BOOT_LOADER
|
sl@0
|
1100 |
console = Console::NewL(KVariantUsbmsTitle,TSize(KConsFullScreen,KConsFullScreen));
|
sl@0
|
1101 |
#else
|
sl@0
|
1102 |
console = Console::NewL(KTxtApp,TSize(KConsFullScreen,KConsFullScreen));
|
sl@0
|
1103 |
#endif
|
sl@0
|
1104 |
|
sl@0
|
1105 |
CleanupStack::PushL(console);
|
sl@0
|
1106 |
|
sl@0
|
1107 |
console->SetPos(0,2);
|
sl@0
|
1108 |
console->Printf(_L("========================================"));
|
sl@0
|
1109 |
|
sl@0
|
1110 |
CActiveScheduler* sched = new(ELeave) CActiveScheduler;
|
sl@0
|
1111 |
CleanupStack::PushL(sched);
|
sl@0
|
1112 |
CActiveScheduler::Install(sched);
|
sl@0
|
1113 |
|
sl@0
|
1114 |
TBuf<20> KDriverFileName;
|
sl@0
|
1115 |
// Load the logical device
|
sl@0
|
1116 |
RDevUsbcClient usb;
|
sl@0
|
1117 |
RDevUsbcScClient usbsc;
|
sl@0
|
1118 |
RChunk gChunk;
|
sl@0
|
1119 |
|
sl@0
|
1120 |
fs.Connect();
|
sl@0
|
1121 |
CleanupClosePushL(fs);
|
sl@0
|
1122 |
|
sl@0
|
1123 |
_LIT(KMountAllDefault,"(all)");
|
sl@0
|
1124 |
console->SetPos(0,3);
|
sl@0
|
1125 |
LogPrint(_L("Drives to auto-mount: %S"), (mountList.Length() ? &mountList : &KMountAllDefault));
|
sl@0
|
1126 |
|
sl@0
|
1127 |
// Add MS file system
|
sl@0
|
1128 |
error = fs.AddFileSystem(KMsFsy);
|
sl@0
|
1129 |
|
sl@0
|
1130 |
if(error != KErrNone && error != KErrAlreadyExists)
|
sl@0
|
1131 |
{
|
sl@0
|
1132 |
User::Leave(error);
|
sl@0
|
1133 |
}
|
sl@0
|
1134 |
console->SetPos(0,4);
|
sl@0
|
1135 |
LogPrint(_L("MSFS file system:\tAdded OK\n"));
|
sl@0
|
1136 |
|
sl@0
|
1137 |
if (gSharedChunkLdd)
|
sl@0
|
1138 |
{
|
sl@0
|
1139 |
KDriverFileName = _L("EUSBCSC.LDD");
|
sl@0
|
1140 |
error = User::LoadLogicalDevice(KDriverFileName);
|
sl@0
|
1141 |
}
|
sl@0
|
1142 |
else
|
sl@0
|
1143 |
{
|
sl@0
|
1144 |
KDriverFileName = _L("EUSBC.LDD");
|
sl@0
|
1145 |
error = User::LoadLogicalDevice(KDriverFileName);
|
sl@0
|
1146 |
}
|
sl@0
|
1147 |
|
sl@0
|
1148 |
if (error != KErrAlreadyExists)
|
sl@0
|
1149 |
{
|
sl@0
|
1150 |
User::LeaveIfError(error);
|
sl@0
|
1151 |
}
|
sl@0
|
1152 |
|
sl@0
|
1153 |
|
sl@0
|
1154 |
if (gSharedChunkLdd)
|
sl@0
|
1155 |
{
|
sl@0
|
1156 |
error = usbsc.Open(0);
|
sl@0
|
1157 |
}
|
sl@0
|
1158 |
else
|
sl@0
|
1159 |
{
|
sl@0
|
1160 |
error = usb.Open(0);
|
sl@0
|
1161 |
}
|
sl@0
|
1162 |
|
sl@0
|
1163 |
User::LeaveIfError(error);
|
sl@0
|
1164 |
|
sl@0
|
1165 |
#ifdef BUILD_OTG_USBMSAPP
|
sl@0
|
1166 |
|
sl@0
|
1167 |
_LIT(KOtgdiLddFilename, "otgdi");
|
sl@0
|
1168 |
// Check for OTG support
|
sl@0
|
1169 |
TBuf8<KUsbDescSize_Otg> otg_desc;
|
sl@0
|
1170 |
if (gSharedChunkLdd)
|
sl@0
|
1171 |
{
|
sl@0
|
1172 |
error = usbsc.GetOtgDescriptor(otg_desc);
|
sl@0
|
1173 |
}
|
sl@0
|
1174 |
else
|
sl@0
|
1175 |
{
|
sl@0
|
1176 |
error = usb.GetOtgDescriptor(otg_desc);
|
sl@0
|
1177 |
}
|
sl@0
|
1178 |
|
sl@0
|
1179 |
if (!(error == KErrNotSupported || error == KErrNone))
|
sl@0
|
1180 |
{
|
sl@0
|
1181 |
LogPrint(_L("Error %d while fetching OTG descriptor"), error);
|
sl@0
|
1182 |
User::Leave(-1);
|
sl@0
|
1183 |
return;
|
sl@0
|
1184 |
}
|
sl@0
|
1185 |
|
sl@0
|
1186 |
// On an OTG device we have to start the OTG driver, otherwise the Client
|
sl@0
|
1187 |
// stack will remain disabled forever.
|
sl@0
|
1188 |
if (error == KErrNotSupported)
|
sl@0
|
1189 |
{
|
sl@0
|
1190 |
if (gSharedChunkLdd)
|
sl@0
|
1191 |
{
|
sl@0
|
1192 |
CleanupClosePushL(usbsc);
|
sl@0
|
1193 |
}
|
sl@0
|
1194 |
else
|
sl@0
|
1195 |
{
|
sl@0
|
1196 |
CleanupClosePushL(usb);
|
sl@0
|
1197 |
}
|
sl@0
|
1198 |
|
sl@0
|
1199 |
User::Leave(-1);
|
sl@0
|
1200 |
}
|
sl@0
|
1201 |
|
sl@0
|
1202 |
error = User::LoadLogicalDevice(KOtgdiLddFilename);
|
sl@0
|
1203 |
|
sl@0
|
1204 |
if (error != KErrNone)
|
sl@0
|
1205 |
{
|
sl@0
|
1206 |
LogPrint(_L("Error %d on loading OTG LDD"), error);
|
sl@0
|
1207 |
User::Leave(-1);
|
sl@0
|
1208 |
return;
|
sl@0
|
1209 |
}
|
sl@0
|
1210 |
|
sl@0
|
1211 |
RUsbOtgDriver iOtgPort;
|
sl@0
|
1212 |
|
sl@0
|
1213 |
error = iOtgPort.Open();
|
sl@0
|
1214 |
|
sl@0
|
1215 |
if (error != KErrNone)
|
sl@0
|
1216 |
{
|
sl@0
|
1217 |
LogPrint(_L("Error %d on opening OTG port"), error);
|
sl@0
|
1218 |
User::Leave(-1);
|
sl@0
|
1219 |
return;
|
sl@0
|
1220 |
}
|
sl@0
|
1221 |
error = iOtgPort.StartStacks();
|
sl@0
|
1222 |
|
sl@0
|
1223 |
if (error != KErrNone)
|
sl@0
|
1224 |
{
|
sl@0
|
1225 |
LogPrint(_L("Error %d on starting USB stack"), error);
|
sl@0
|
1226 |
User::Leave(-1);
|
sl@0
|
1227 |
return;
|
sl@0
|
1228 |
}
|
sl@0
|
1229 |
|
sl@0
|
1230 |
#endif
|
sl@0
|
1231 |
|
sl@0
|
1232 |
if (gSharedChunkLdd)
|
sl@0
|
1233 |
{
|
sl@0
|
1234 |
CleanupClosePushL(usbsc);
|
sl@0
|
1235 |
RChunk *tChunk = &gChunk;
|
sl@0
|
1236 |
usbsc.FinalizeInterface(tChunk);
|
sl@0
|
1237 |
}
|
sl@0
|
1238 |
else
|
sl@0
|
1239 |
{
|
sl@0
|
1240 |
CleanupClosePushL(usb);
|
sl@0
|
1241 |
}
|
sl@0
|
1242 |
|
sl@0
|
1243 |
|
sl@0
|
1244 |
// RDebug::Print(_L("USBMSAPP: Create active objects\n"));
|
sl@0
|
1245 |
CMessageKeyProcessor::NewLC(console);
|
sl@0
|
1246 |
CPropertyWatch::NewLC(EUsbMsDriveState_KBytesRead, PropertyHandlers::Read);
|
sl@0
|
1247 |
CPropertyWatch::NewLC(EUsbMsDriveState_KBytesWritten, PropertyHandlers::Written);
|
sl@0
|
1248 |
CPropertyWatch::NewLC(EUsbMsDriveState_DriveStatus, PropertyHandlers::DriveStatus);
|
sl@0
|
1249 |
CPropertyWatch::NewLC(EUsbMsDriveState_MediaError, PropertyHandlers::MediaError);
|
sl@0
|
1250 |
if (gSharedChunkLdd)
|
sl@0
|
1251 |
{
|
sl@0
|
1252 |
CUsbWatch::NewLC(&usbsc);
|
sl@0
|
1253 |
}
|
sl@0
|
1254 |
else
|
sl@0
|
1255 |
{
|
sl@0
|
1256 |
CUsbWatch::NewLC(&usb);
|
sl@0
|
1257 |
}
|
sl@0
|
1258 |
|
sl@0
|
1259 |
CPeriodUpdate::NewLC();
|
sl@0
|
1260 |
|
sl@0
|
1261 |
RUsbMassStorage UsbMs;
|
sl@0
|
1262 |
TBuf<8> t_vendorId(_L("vendor"));
|
sl@0
|
1263 |
TBuf<16> t_productId(_L("product"));
|
sl@0
|
1264 |
TBuf<4> t_productRev(_L("1.00"));
|
sl@0
|
1265 |
|
sl@0
|
1266 |
TMassStorageConfig msConfig;
|
sl@0
|
1267 |
msConfig.iVendorId.Copy(t_vendorId);
|
sl@0
|
1268 |
msConfig.iProductId.Copy(t_productId);
|
sl@0
|
1269 |
msConfig.iProductRev.Copy(t_productRev);
|
sl@0
|
1270 |
|
sl@0
|
1271 |
// console->Printf(_L("Connect to Mass Storage"));
|
sl@0
|
1272 |
error = UsbMs.Connect();
|
sl@0
|
1273 |
User::LeaveIfError(error);
|
sl@0
|
1274 |
|
sl@0
|
1275 |
// console->Printf(_L("Start Mass Storage"));
|
sl@0
|
1276 |
error = UsbMs.Start(msConfig);
|
sl@0
|
1277 |
User::LeaveIfError(error);
|
sl@0
|
1278 |
|
sl@0
|
1279 |
TBuf8<KUsbDescSize_Device> deviceDescriptor;
|
sl@0
|
1280 |
if (gSharedChunkLdd)
|
sl@0
|
1281 |
{
|
sl@0
|
1282 |
error = usbsc.GetDeviceDescriptor(deviceDescriptor);
|
sl@0
|
1283 |
}
|
sl@0
|
1284 |
else
|
sl@0
|
1285 |
{
|
sl@0
|
1286 |
error = usb.GetDeviceDescriptor(deviceDescriptor);
|
sl@0
|
1287 |
}
|
sl@0
|
1288 |
|
sl@0
|
1289 |
User::LeaveIfError(error);
|
sl@0
|
1290 |
|
sl@0
|
1291 |
const TInt KUsbSpecOffset = 2;
|
sl@0
|
1292 |
const TInt KUsbDeviceClassOffset = 4;
|
sl@0
|
1293 |
const TInt KUsbVendorIdOffset = 8;
|
sl@0
|
1294 |
const TInt KUsbProductIdOffset = 10;
|
sl@0
|
1295 |
const TInt KUsbDevReleaseOffset = 12;
|
sl@0
|
1296 |
//Change the USB spec number to 2.00
|
sl@0
|
1297 |
deviceDescriptor[KUsbSpecOffset] = 0x00;
|
sl@0
|
1298 |
deviceDescriptor[KUsbSpecOffset+1] = 0x02;
|
sl@0
|
1299 |
//Change the Device Class, Device SubClass and Device Protocol
|
sl@0
|
1300 |
deviceDescriptor[KUsbDeviceClassOffset] = 0x00;
|
sl@0
|
1301 |
deviceDescriptor[KUsbDeviceClassOffset+1] = 0x00;
|
sl@0
|
1302 |
deviceDescriptor[KUsbDeviceClassOffset+2] = 0x00;
|
sl@0
|
1303 |
//Change the device vendor ID (VID) to 0x0E22 (Symbian)
|
sl@0
|
1304 |
deviceDescriptor[KUsbVendorIdOffset] = 0x22; // little endian
|
sl@0
|
1305 |
deviceDescriptor[KUsbVendorIdOffset+1] = 0x0E;
|
sl@0
|
1306 |
//Change the device product ID (PID) to 0x1111
|
sl@0
|
1307 |
deviceDescriptor[KUsbProductIdOffset] = 0x12;
|
sl@0
|
1308 |
deviceDescriptor[KUsbProductIdOffset+1] = 0x11;
|
sl@0
|
1309 |
//Change the device release number to 3.05
|
sl@0
|
1310 |
deviceDescriptor[KUsbDevReleaseOffset] = 0x05;
|
sl@0
|
1311 |
deviceDescriptor[KUsbDevReleaseOffset+1] = 0x03;
|
sl@0
|
1312 |
if (gSharedChunkLdd)
|
sl@0
|
1313 |
{
|
sl@0
|
1314 |
error = usbsc.SetDeviceDescriptor(deviceDescriptor);
|
sl@0
|
1315 |
}
|
sl@0
|
1316 |
else
|
sl@0
|
1317 |
{
|
sl@0
|
1318 |
error = usb.SetDeviceDescriptor(deviceDescriptor);
|
sl@0
|
1319 |
}
|
sl@0
|
1320 |
|
sl@0
|
1321 |
User::LeaveIfError(error);
|
sl@0
|
1322 |
|
sl@0
|
1323 |
// Remove possible Remote-Wakup support in Configuration descriptor,
|
sl@0
|
1324 |
// so that we can use the MSC device also easily for Chapter9 testing.
|
sl@0
|
1325 |
TBuf8<KUsbDescSize_Config> configDescriptor;
|
sl@0
|
1326 |
if (gSharedChunkLdd)
|
sl@0
|
1327 |
{
|
sl@0
|
1328 |
error = usbsc.GetConfigurationDescriptor(configDescriptor);
|
sl@0
|
1329 |
}
|
sl@0
|
1330 |
else
|
sl@0
|
1331 |
{
|
sl@0
|
1332 |
error = usb.GetConfigurationDescriptor(configDescriptor);
|
sl@0
|
1333 |
}
|
sl@0
|
1334 |
|
sl@0
|
1335 |
User::LeaveIfError(error);
|
sl@0
|
1336 |
const TInt KConfDesc_AttribOffset = 7;
|
sl@0
|
1337 |
configDescriptor[KConfDesc_AttribOffset] &= ~KUsbDevAttr_RemoteWakeup;
|
sl@0
|
1338 |
if (gSharedChunkLdd)
|
sl@0
|
1339 |
{
|
sl@0
|
1340 |
error = usbsc.SetConfigurationDescriptor(configDescriptor);
|
sl@0
|
1341 |
}
|
sl@0
|
1342 |
else
|
sl@0
|
1343 |
{
|
sl@0
|
1344 |
error = usb.SetConfigurationDescriptor(configDescriptor);
|
sl@0
|
1345 |
}
|
sl@0
|
1346 |
|
sl@0
|
1347 |
User::LeaveIfError(error);
|
sl@0
|
1348 |
|
sl@0
|
1349 |
_LIT16(productID_L, "Symbian USB Mass Storage Device (Base)");
|
sl@0
|
1350 |
TBuf16<KUsbStringDescStringMaxSize / 2> productID(productID_L);
|
sl@0
|
1351 |
if (gSharedChunkLdd)
|
sl@0
|
1352 |
{
|
sl@0
|
1353 |
error = usbsc.SetProductStringDescriptor(productID);
|
sl@0
|
1354 |
}
|
sl@0
|
1355 |
else
|
sl@0
|
1356 |
{
|
sl@0
|
1357 |
error = usb.SetProductStringDescriptor(productID);
|
sl@0
|
1358 |
}
|
sl@0
|
1359 |
|
sl@0
|
1360 |
User::LeaveIfError(error);
|
sl@0
|
1361 |
|
sl@0
|
1362 |
TRequestStatus enum_status;
|
sl@0
|
1363 |
console->SetPos(0,5);
|
sl@0
|
1364 |
LogPrint(_L("Re-enumerating...\n"));
|
sl@0
|
1365 |
|
sl@0
|
1366 |
#ifdef BUILD_OTG_USBMSAPP
|
sl@0
|
1367 |
// For OTG: The USB stack may not yet in the peripheral role. If it is not,
|
sl@0
|
1368 |
// then ReEnumerate() will not work here as the stack will ignore the call
|
sl@0
|
1369 |
// since the stack is not active. Therefore we simulate device connection to
|
sl@0
|
1370 |
// force the stack into peripheral role by calling DeviceConnectToHost().
|
sl@0
|
1371 |
if (gSharedChunkLdd)
|
sl@0
|
1372 |
{
|
sl@0
|
1373 |
usbsc.DeviceConnectToHost();
|
sl@0
|
1374 |
usbsc.ReEnumerate(enum_status);
|
sl@0
|
1375 |
|
sl@0
|
1376 |
}
|
sl@0
|
1377 |
else
|
sl@0
|
1378 |
{
|
sl@0
|
1379 |
usb.DeviceConnectToHost();
|
sl@0
|
1380 |
usb.ReEnumerate(enum_status);
|
sl@0
|
1381 |
}
|
sl@0
|
1382 |
#else
|
sl@0
|
1383 |
if (gSharedChunkLdd)
|
sl@0
|
1384 |
{
|
sl@0
|
1385 |
usbsc.ReEnumerate(enum_status);
|
sl@0
|
1386 |
}
|
sl@0
|
1387 |
else
|
sl@0
|
1388 |
{
|
sl@0
|
1389 |
usb.ReEnumerate(enum_status);
|
sl@0
|
1390 |
}
|
sl@0
|
1391 |
#endif
|
sl@0
|
1392 |
|
sl@0
|
1393 |
User::LeaveIfError(error);
|
sl@0
|
1394 |
console->SetPos(0,5);
|
sl@0
|
1395 |
User::WaitForRequest(enum_status);
|
sl@0
|
1396 |
if(enum_status.Int() == KErrNone)
|
sl@0
|
1397 |
LogPrint(_L("Re-enumeration Done\n"));
|
sl@0
|
1398 |
else
|
sl@0
|
1399 |
LogPrint(_L("Re-enumeration not successfully done\n"));
|
sl@0
|
1400 |
|
sl@0
|
1401 |
#ifndef USB_BOOT_LOADER
|
sl@0
|
1402 |
console->SetPos(0,14);
|
sl@0
|
1403 |
TBuf<3>password(KDefPwd);
|
sl@0
|
1404 |
LogPrint(_L("Password: %S"), &password);
|
sl@0
|
1405 |
#endif
|
sl@0
|
1406 |
ShowDriveSelection();
|
sl@0
|
1407 |
|
sl@0
|
1408 |
console->SetPos(0,17);
|
sl@0
|
1409 |
#ifdef USB_BOOT_LOADER
|
sl@0
|
1410 |
_LIT(KMsgTitleB,"Menu:\n[Esc,Q]=RESET (boot image)\n");
|
sl@0
|
1411 |
#else
|
sl@0
|
1412 |
_LIT(KMsgTitleB,"Menu: q=quit d=chg drv\n m=mount u=unmount\n l=lock n=unlock\n c=clr pwd");
|
sl@0
|
1413 |
#endif
|
sl@0
|
1414 |
|
sl@0
|
1415 |
//RDebug::Print(_L("USBMSAPP: Start CActiveScheduler\n"));
|
sl@0
|
1416 |
|
sl@0
|
1417 |
console->Printf(KMsgTitleB);
|
sl@0
|
1418 |
|
sl@0
|
1419 |
#ifdef USB_BOOT_LOADER
|
sl@0
|
1420 |
// Mount the mass storage on variant specific drive
|
sl@0
|
1421 |
MountMsFs(KVariantUsbmsRemoveableDrive);
|
sl@0
|
1422 |
#endif
|
sl@0
|
1423 |
|
sl@0
|
1424 |
CActiveScheduler::Start();
|
sl@0
|
1425 |
|
sl@0
|
1426 |
error = UsbMs.Stop();
|
sl@0
|
1427 |
User::LeaveIfError(error);
|
sl@0
|
1428 |
UsbMs.Close();
|
sl@0
|
1429 |
error = fs.RemoveFileSystem(KMsFs);
|
sl@0
|
1430 |
User::LeaveIfError(error);
|
sl@0
|
1431 |
|
sl@0
|
1432 |
//The console object is left on the Cleanup Stack,
|
sl@0
|
1433 |
//which is used in the delay processing logic of rebootit().
|
sl@0
|
1434 |
CleanupStack::PopAndDestroy(10);
|
sl@0
|
1435 |
|
sl@0
|
1436 |
#ifdef BUILD_OTG_USBMSAPP
|
sl@0
|
1437 |
iOtgPort.StopStacks();
|
sl@0
|
1438 |
iOtgPort.Close();
|
sl@0
|
1439 |
error = User::FreeLogicalDevice(RUsbOtgDriver::Name());
|
sl@0
|
1440 |
User::LeaveIfError(error);
|
sl@0
|
1441 |
#endif
|
sl@0
|
1442 |
|
sl@0
|
1443 |
// UnLoad the logical device
|
sl@0
|
1444 |
TBuf<20> KDriverName;
|
sl@0
|
1445 |
if (gSharedChunkLdd)
|
sl@0
|
1446 |
{
|
sl@0
|
1447 |
KDriverName = _L("USBCSC");
|
sl@0
|
1448 |
gChunk.Close();
|
sl@0
|
1449 |
usbsc.Close();
|
sl@0
|
1450 |
User::After(100000);
|
sl@0
|
1451 |
error = User::FreeLogicalDevice(KDriverName);
|
sl@0
|
1452 |
}
|
sl@0
|
1453 |
else
|
sl@0
|
1454 |
{
|
sl@0
|
1455 |
KDriverName = _L("USBC");
|
sl@0
|
1456 |
error = User::FreeLogicalDevice(KDriverName);
|
sl@0
|
1457 |
}
|
sl@0
|
1458 |
|
sl@0
|
1459 |
User::LeaveIfError(error);
|
sl@0
|
1460 |
|
sl@0
|
1461 |
#ifdef USB_BOOT_LOADER
|
sl@0
|
1462 |
rebootit();
|
sl@0
|
1463 |
#endif
|
sl@0
|
1464 |
CleanupStack::PopAndDestroy(1);
|
sl@0
|
1465 |
}
|
sl@0
|
1466 |
|
sl@0
|
1467 |
TInt ParseCommandLine()
|
sl@0
|
1468 |
{
|
sl@0
|
1469 |
TBuf<32> args;
|
sl@0
|
1470 |
User::CommandLine(args);
|
sl@0
|
1471 |
TLex lex(args);
|
sl@0
|
1472 |
TInt err=KErrNone;
|
sl@0
|
1473 |
FOREVER
|
sl@0
|
1474 |
{
|
sl@0
|
1475 |
TPtrC token=lex.NextToken();
|
sl@0
|
1476 |
|
sl@0
|
1477 |
if(token.Length()!=0)
|
sl@0
|
1478 |
{
|
sl@0
|
1479 |
if ((token.MatchF(_L("-sc")) == KErrNone))
|
sl@0
|
1480 |
{
|
sl@0
|
1481 |
gSharedChunkLdd = ETrue;
|
sl@0
|
1482 |
err = KErrNone;
|
sl@0
|
1483 |
}
|
sl@0
|
1484 |
else
|
sl@0
|
1485 |
{
|
sl@0
|
1486 |
// Command line: list of drive letters to auto-mount (all if not specified)
|
sl@0
|
1487 |
mountList.Append(token);
|
sl@0
|
1488 |
mountList.UpperCase();
|
sl@0
|
1489 |
err = KErrNone;
|
sl@0
|
1490 |
} // endif token
|
sl@0
|
1491 |
}
|
sl@0
|
1492 |
else
|
sl@0
|
1493 |
break;
|
sl@0
|
1494 |
}
|
sl@0
|
1495 |
return err;
|
sl@0
|
1496 |
}
|
sl@0
|
1497 |
|
sl@0
|
1498 |
|
sl@0
|
1499 |
|
sl@0
|
1500 |
GLDEF_C TInt E32Main()
|
sl@0
|
1501 |
{
|
sl@0
|
1502 |
__UHEAP_MARK;
|
sl@0
|
1503 |
CTrapCleanup* cleanup=CTrapCleanup::New();
|
sl@0
|
1504 |
|
sl@0
|
1505 |
if (ParseCommandLine())
|
sl@0
|
1506 |
return KErrNone;
|
sl@0
|
1507 |
|
sl@0
|
1508 |
msfsMountedList.Reset();
|
sl@0
|
1509 |
unmountedFsList.Reset();
|
sl@0
|
1510 |
|
sl@0
|
1511 |
|
sl@0
|
1512 |
TRAPD(error,RunAppL());
|
sl@0
|
1513 |
#ifdef USB_BOOT_LOADER
|
sl@0
|
1514 |
__ASSERT_ALWAYS(!error, User::Panic(KVariantUsbmsTitle, error));
|
sl@0
|
1515 |
#else
|
sl@0
|
1516 |
__ASSERT_ALWAYS(!error, User::Panic(KTxtApp, error));
|
sl@0
|
1517 |
#endif
|
sl@0
|
1518 |
|
sl@0
|
1519 |
delete cleanup;
|
sl@0
|
1520 |
__UHEAP_MARKEND;
|
sl@0
|
1521 |
return 0;
|
sl@0
|
1522 |
}
|
sl@0
|
1523 |
|
sl@0
|
1524 |
|
sl@0
|
1525 |
|
sl@0
|
1526 |
|
sl@0
|
1527 |
//-----------------------------------------------------------------------------
|
sl@0
|
1528 |
|
sl@0
|
1529 |
CFileSystemDescriptor::~CFileSystemDescriptor()
|
sl@0
|
1530 |
{
|
sl@0
|
1531 |
iFsName.Close();
|
sl@0
|
1532 |
iPrimaryExtName.Close();
|
sl@0
|
1533 |
}
|
sl@0
|
1534 |
|
sl@0
|
1535 |
//-----------------------------------------------------------------------------
|
sl@0
|
1536 |
CFileSystemDescriptor* CFileSystemDescriptor::NewL(const TDesC& aFsName, const TDesC& aPrimaryExtName, TBool aDrvSynch)
|
sl@0
|
1537 |
{
|
sl@0
|
1538 |
CFileSystemDescriptor* pSelf = new (ELeave) CFileSystemDescriptor;
|
sl@0
|
1539 |
|
sl@0
|
1540 |
CleanupStack::PushL(pSelf);
|
sl@0
|
1541 |
|
sl@0
|
1542 |
pSelf->iFsName.CreateMaxL(aFsName.Length());
|
sl@0
|
1543 |
pSelf->iFsName.Copy(aFsName);
|
sl@0
|
1544 |
|
sl@0
|
1545 |
pSelf->iPrimaryExtName.CreateMaxL(aPrimaryExtName.Length());
|
sl@0
|
1546 |
pSelf->iPrimaryExtName.Copy(aPrimaryExtName);
|
sl@0
|
1547 |
|
sl@0
|
1548 |
pSelf->iDriveSynch = aDrvSynch;
|
sl@0
|
1549 |
|
sl@0
|
1550 |
CleanupStack::Pop();
|
sl@0
|
1551 |
|
sl@0
|
1552 |
return pSelf;
|
sl@0
|
1553 |
}
|
sl@0
|
1554 |
|
sl@0
|
1555 |
|
sl@0
|
1556 |
|
sl@0
|
1557 |
|
sl@0
|
1558 |
|
sl@0
|
1559 |
|
sl@0
|
1560 |
|
sl@0
|
1561 |
|
sl@0
|
1562 |
|
sl@0
|
1563 |
|
sl@0
|
1564 |
|
sl@0
|
1565 |
|
sl@0
|
1566 |
|
sl@0
|
1567 |
|
sl@0
|
1568 |
|
sl@0
|
1569 |
|
sl@0
|
1570 |
|
sl@0
|
1571 |
|
sl@0
|
1572 |
|
sl@0
|
1573 |
|