297
|
1 |
// Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
|
0
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
//
|
|
15 |
|
|
16 |
#include <f32file.h>
|
|
17 |
#include <d32usbdi_hubdriver.h>
|
|
18 |
#include <d32usbdi.h>
|
|
19 |
#include <d32otgdi.h>
|
|
20 |
#include <d32usbdescriptors.h>
|
|
21 |
#include <d32usbtransfers.h>
|
|
22 |
|
|
23 |
#include <shared.h>
|
|
24 |
|
|
25 |
#include "rusbhostmsdevice.h"
|
|
26 |
|
|
27 |
#include "rextfilesystem.h"
|
|
28 |
#include "usbtypes.h"
|
|
29 |
#include "cusbmsmountmanager.h"
|
|
30 |
#include "debug.h"
|
|
31 |
|
|
32 |
|
|
33 |
CDevice* CDevice::NewL()
|
|
34 |
{
|
297
|
35 |
CDevice* r = new (ELeave) CDevice();
|
|
36 |
CleanupStack::PushL(r);
|
0
|
37 |
|
297
|
38 |
r->ConstructL();
|
|
39 |
CleanupStack::Pop();
|
|
40 |
return r;
|
0
|
41 |
}
|
|
42 |
|
|
43 |
|
|
44 |
void CDevice::ConstructL()
|
|
45 |
{
|
|
46 |
}
|
|
47 |
|
|
48 |
|
|
49 |
CDevice::CDevice()
|
|
50 |
{
|
|
51 |
}
|
|
52 |
|
|
53 |
|
|
54 |
CDevice::~CDevice()
|
|
55 |
{
|
|
56 |
__USBHOSTPRINT1(_L("~CDevice Token=%d"), iDeviceToken);
|
|
57 |
}
|
|
58 |
|
|
59 |
|
|
60 |
TToken CDevice::OpenDeviceL(TUint aDeviceHandle, RUsbHubDriver& aHub)
|
|
61 |
{
|
|
62 |
__USBHOSTPRINT1(_L("CDevice::OpenDeviceL Handle=%d"), aDeviceHandle);
|
|
63 |
|
|
64 |
TInt err = iUsbDevice.Open(aHub, aDeviceHandle);
|
|
65 |
__USBHOSTPRINT1(_L(" - returned %d\n"), err);
|
|
66 |
User::LeaveIfError(err);
|
|
67 |
|
|
68 |
/* Retrieve the device descriptor */
|
|
69 |
TUsbDeviceDescriptor devDescriptor;
|
|
70 |
User::LeaveIfError(iUsbDevice.GetDeviceDescriptor(devDescriptor));
|
|
71 |
iUsbPrint.PrintDescriptor(devDescriptor, 0, &iUsbDevice);
|
|
72 |
|
|
73 |
iUsbPrint.PrintTree(devDescriptor);
|
|
74 |
|
|
75 |
/* Retrieve the configuration descriptor */
|
|
76 |
TUsbConfigurationDescriptor configDescriptor;
|
|
77 |
User::LeaveIfError(iUsbDevice.GetConfigurationDescriptor(configDescriptor));
|
|
78 |
iUsbPrint.PrintDescriptor(configDescriptor, 0, &iUsbDevice);
|
|
79 |
|
|
80 |
/* Get the token for interface 0 */
|
|
81 |
TUint32 token;
|
|
82 |
err = iUsbDevice.GetTokenForInterface(0, token);
|
|
83 |
__USBHOSTPRINT2(_L("RUsbDevice::GetTokenForInterface returned error %d, token %08x"), err, token);
|
|
84 |
User::LeaveIfError(err);
|
|
85 |
|
|
86 |
/* open the interface */
|
|
87 |
RUsbInterface interface_ep0;
|
|
88 |
err = interface_ep0.Open(token);
|
|
89 |
__USBHOSTPRINT1(_L("RUsbInterface::Open returned error %d"), err);
|
|
90 |
User::LeaveIfError(err);
|
|
91 |
|
|
92 |
/* Retrieve the interface and device descriptors */
|
|
93 |
TUsbInterfaceDescriptor ifDescriptor;
|
|
94 |
User::LeaveIfError(interface_ep0.GetInterfaceDescriptor(ifDescriptor));
|
|
95 |
iUsbPrint.PrintDescriptor(ifDescriptor);
|
|
96 |
|
|
97 |
if (!IsDeviceMassStorage(ifDescriptor, devDescriptor))
|
|
98 |
{
|
|
99 |
RDebug::Print(_L("ATTACHED DEVICE IS NOT A MASS STORAGE DEVICE!\n"));
|
|
100 |
User::Leave(KErrGeneral);
|
|
101 |
}
|
|
102 |
|
297
|
103 |
TUint8 iProtocolId = ifDescriptor.InterfaceSubClass();
|
|
104 |
TUint8 iTransportId = ifDescriptor.InterfaceProtocol();
|
0
|
105 |
|
|
106 |
interface_ep0.Close();
|
|
107 |
|
|
108 |
THostMassStorageConfig msConfig;
|
|
109 |
msConfig.iInterfaceToken = token;
|
297
|
110 |
msConfig.iProtocolId =iProtocolId;
|
|
111 |
msConfig.iTransportId = iTransportId;
|
|
112 |
msConfig.iStatusPollingInterval = 10; // 10 secs
|
0
|
113 |
|
|
114 |
TUint32 numLun;
|
|
115 |
|
|
116 |
TRequestStatus status;
|
|
117 |
iUsbHostMsDevice.Add(msConfig, status);
|
297
|
118 |
User::WaitForRequest(status);
|
|
119 |
if (status.Int() != KErrNone)
|
0
|
120 |
{
|
297
|
121 |
__USBHOSTPRINT(_L("Add device failed"));
|
|
122 |
User::Leave(status.Int());
|
0
|
123 |
}
|
297
|
124 |
TInt r = iUsbHostMsDevice.GetNumLun(numLun);
|
|
125 |
if (r != KErrNone)
|
0
|
126 |
{
|
297
|
127 |
__USBHOSTPRINT(_L("GetNumLun failed"));
|
|
128 |
User::Leave(r);
|
0
|
129 |
}
|
|
130 |
|
|
131 |
if (numLun > KMaxLun)
|
|
132 |
{
|
|
133 |
__USBHOSTPRINT1(_L("Device MaxLun = %d. Error MaxLun > MAXLUN !"), numLun);
|
|
134 |
User::Leave(KErrGeneral);
|
|
135 |
}
|
|
136 |
|
|
137 |
__USBHOSTPRINT1(_L("MSC registered with %d Luns"), numLun);
|
|
138 |
|
|
139 |
iDeviceToken = token;
|
|
140 |
iNumLuns = numLun;
|
|
141 |
iDeviceHandle = aDeviceHandle;
|
|
142 |
return token;
|
|
143 |
}
|
|
144 |
|
|
145 |
|
|
146 |
void CDevice::CloseDeviceL()
|
|
147 |
{
|
|
148 |
THostMassStorageConfig msConfig;
|
|
149 |
msConfig.iInterfaceToken = iDeviceToken;
|
|
150 |
|
|
151 |
iUsbHostMsDevice.Remove();
|
|
152 |
iUsbDevice.Close();
|
|
153 |
}
|
|
154 |
|
|
155 |
|
|
156 |
void CDevice::MountLogicalUnitsL()
|
|
157 |
{
|
|
158 |
iExt.OpenL();
|
|
159 |
|
|
160 |
for (TInt lun = 0; lun < iNumLuns; lun++)
|
|
161 |
{
|
|
162 |
TDriveNumber driveNumber = iExt.GetDriveL();
|
|
163 |
__PRINT2(_L("Mounting drive=%d lun=%d..."), driveNumber, lun);
|
|
164 |
RDebug::Print(_L("Mounting drive=%d lun=%d..."), driveNumber, lun);
|
|
165 |
TRAPD(err, iExt.MountL(iUsbHostMsDevice, driveNumber, iDeviceToken, lun));
|
|
166 |
if (err == KErrNone || err == KErrNotReady || err == KErrCorrupt)
|
|
167 |
{
|
|
168 |
iLuList.Append(driveNumber);
|
|
169 |
}
|
|
170 |
__PRINT1(_L("%d"), err);
|
|
171 |
RDebug::Print(_L("err=%d"), err);
|
|
172 |
}
|
|
173 |
}
|
|
174 |
|
|
175 |
|
|
176 |
void CDevice::DismountLogicalUnitsL()
|
|
177 |
{
|
|
178 |
for (TInt lun = 0; lun < iLuList.Count(); lun++)
|
|
179 |
{
|
|
180 |
TDriveNumber driveNumber = iLuList[lun];
|
|
181 |
iExt.DismountL(iUsbHostMsDevice, driveNumber);
|
|
182 |
}
|
|
183 |
iLuList.Reset();
|
|
184 |
|
|
185 |
iExt.CloseL();
|
|
186 |
}
|
|
187 |
|
|
188 |
|
|
189 |
TInt CDevice::GetEndpointAddress(RUsbInterface& aUsbInterface,
|
|
190 |
TInt aInterfaceSetting,
|
|
191 |
TUint8 aTransferType,
|
|
192 |
TUint8 aDirection,
|
|
193 |
TInt& aEndpointAddress) const
|
297
|
194 |
{
|
|
195 |
// Get the interface descriptor
|
|
196 |
RDebug::Print(_L("GetEndpointAddress : Getting the interface descriptor for this alternate setting"));
|
0
|
197 |
|
297
|
198 |
TUsbInterfaceDescriptor alternateInterfaceDescriptor;
|
|
199 |
TInt err = aUsbInterface.GetAlternateInterfaceDescriptor(aInterfaceSetting, alternateInterfaceDescriptor);
|
0
|
200 |
|
297
|
201 |
if (err)
|
|
202 |
{
|
|
203 |
RDebug::Print(_L("GetEndpointAddress : <Error %d> Unable to get alternate interface (%d) descriptor"),err,aInterfaceSetting);
|
|
204 |
return err;
|
|
205 |
}
|
|
206 |
|
|
207 |
// Parse the descriptor tree from the interface
|
|
208 |
RDebug::Print(_L("Search the child descriptors for matching endpoint attributes"));
|
0
|
209 |
|
297
|
210 |
TUsbGenericDescriptor* descriptor = alternateInterfaceDescriptor.iFirstChild;
|
0
|
211 |
|
297
|
212 |
while (descriptor)
|
|
213 |
{
|
|
214 |
RDebug::Print(_L("GetEndpointAddress : Check descriptor type for endpoint"));
|
0
|
215 |
|
297
|
216 |
// Cast the descriptor to an endpoint descriptor
|
|
217 |
TUsbEndpointDescriptor* endpoint = TUsbEndpointDescriptor::Cast(descriptor);
|
0
|
218 |
|
297
|
219 |
if (endpoint)
|
|
220 |
{
|
|
221 |
RDebug::Print(_L("GetEndpointAddress : Match attributes for transfer type"));
|
0
|
222 |
|
297
|
223 |
if ( (endpoint->Attributes() & aTransferType) == aTransferType)
|
|
224 |
{
|
|
225 |
RDebug::Print(_L("GetEndpointAddress : Match attributes for endpoint direction"));
|
0
|
226 |
|
297
|
227 |
if ( (endpoint->EndpointAddress() & 0x80) == aDirection)
|
|
228 |
{
|
|
229 |
aEndpointAddress = endpoint->EndpointAddress();
|
|
230 |
RDebug::Print(_L("GetEndpointAddress : Endpoint address found"));
|
|
231 |
return KErrNone;
|
|
232 |
}
|
|
233 |
}
|
|
234 |
}
|
0
|
235 |
|
297
|
236 |
descriptor = descriptor->iNextPeer;
|
|
237 |
}
|
0
|
238 |
|
297
|
239 |
// Unable to find the endpoint address
|
|
240 |
RDebug::Print(_L("GetEndpointAddress : Unable to find endpoint address matching the specified attributes"));
|
0
|
241 |
|
297
|
242 |
return KErrNotFound;
|
|
243 |
}
|
0
|
244 |
|
|
245 |
|
|
246 |
TBool CDevice::IsDeviceMassStorage(const TUsbInterfaceDescriptor& aInterfaceDesc,
|
|
247 |
const TUsbDeviceDescriptor& aDeviceDesc) const
|
|
248 |
{
|
297
|
249 |
/* check the interface descriptor */
|
|
250 |
if(aInterfaceDesc.InterfaceClass() == 0x08 &&
|
|
251 |
aInterfaceDesc.InterfaceSubClass() == 0x06 &&
|
|
252 |
aInterfaceDesc.InterfaceProtocol() == 0x50)
|
0
|
253 |
{
|
297
|
254 |
if(aDeviceDesc.DeviceClass() == 0x00 &&
|
|
255 |
aDeviceDesc.DeviceSubClass() == 0x00 &&
|
|
256 |
aDeviceDesc.DeviceProtocol() == 0x00)
|
|
257 |
return ETrue;
|
0
|
258 |
}
|
|
259 |
|
297
|
260 |
return EFalse;
|
0
|
261 |
|
|
262 |
}
|
|
263 |
|
|
264 |
|
|
265 |
TLun CDevice::DriveMap(TDriveMap& aDriveMap) const
|
|
266 |
{
|
|
267 |
TDriveNumber driveNumber;
|
|
268 |
RDebug::Printf("LuList.Count=%d", iLuList.Count());
|
|
269 |
for (TInt i = 0; i < iLuList.Count(); i++)
|
|
270 |
{
|
|
271 |
driveNumber = iLuList[i];
|
|
272 |
aDriveMap[driveNumber] = iDeviceToken;
|
|
273 |
RDebug::Printf("Device %d token=%d driveNumber=%d", i, iDeviceToken, driveNumber);
|
|
274 |
}
|
|
275 |
|
|
276 |
return iNumLuns;
|
|
277 |
}
|
|
278 |
|
|
279 |
|
|
280 |
TLun CDevice::DeviceMap(TDeviceMap& aDeviceMap) const
|
|
281 |
{
|
|
282 |
TDriveNumber driveNumber;
|
|
283 |
RDebug::Printf("LuList.Count=%d", iLuList.Count());
|
|
284 |
for (TInt i = 0; i < iLuList.Count(); i++)
|
|
285 |
{
|
|
286 |
driveNumber = iLuList[i];
|
|
287 |
aDeviceMap[i] = driveNumber;
|
|
288 |
RDebug::Printf("CDevice LUN=%d driveNumber=%d", i, driveNumber);
|
|
289 |
}
|
|
290 |
|
|
291 |
return iNumLuns;
|
|
292 |
}
|
|
293 |
|
|
294 |
|
|
295 |
CUsbMsMountManager* CUsbMsMountManager::NewL()
|
|
296 |
{
|
297
|
297 |
CUsbMsMountManager* r = new (ELeave) CUsbMsMountManager();
|
|
298 |
CleanupStack::PushL(r);
|
0
|
299 |
|
297
|
300 |
r->ConstructL();
|
|
301 |
CleanupStack::Pop();
|
|
302 |
return r;
|
0
|
303 |
}
|
|
304 |
|
|
305 |
|
|
306 |
void CUsbMsMountManager::ConstructL()
|
|
307 |
{
|
|
308 |
}
|
|
309 |
|
|
310 |
|
|
311 |
CUsbMsMountManager::CUsbMsMountManager()
|
|
312 |
{
|
|
313 |
}
|
|
314 |
|
|
315 |
|
|
316 |
CUsbMsMountManager::~CUsbMsMountManager()
|
|
317 |
{
|
|
318 |
iDeviceList.ResetAndDestroy();
|
|
319 |
}
|
|
320 |
|
|
321 |
|
|
322 |
// adds new entry for this device
|
|
323 |
void CUsbMsMountManager::AddDeviceL(CDevice* aDevice)
|
|
324 |
{
|
|
325 |
iDeviceList.Append(aDevice);
|
|
326 |
}
|
|
327 |
|
|
328 |
|
|
329 |
CDevice* CUsbMsMountManager::RemoveDeviceL(TUint aDeviceHandle)
|
|
330 |
{
|
297
|
331 |
TInt index = GetHandleIndexL(aDeviceHandle);
|
|
332 |
CDevice* device = iDeviceList[index];
|
0
|
333 |
iDeviceList.Remove(index);
|
|
334 |
return device;
|
|
335 |
}
|
|
336 |
|
|
337 |
void CUsbMsMountManager::CloseAllDevicesL()
|
|
338 |
{
|
|
339 |
for (TInt i = 0; i < iDeviceList.Count(); i++)
|
|
340 |
{
|
|
341 |
iDeviceList[i]->CloseDeviceL();
|
|
342 |
}
|
|
343 |
}
|
|
344 |
|
|
345 |
|
|
346 |
TInt CUsbMsMountManager::GetDeviceIndexL(TToken aDeviceToken) const
|
|
347 |
{
|
|
348 |
TInt index;
|
|
349 |
for (index = 0; index < iDeviceList.Count(); index++)
|
|
350 |
{
|
|
351 |
if (aDeviceToken == iDeviceList[index]->DeviceToken())
|
|
352 |
{
|
|
353 |
break;
|
|
354 |
}
|
|
355 |
}
|
|
356 |
|
|
357 |
if (index == iDeviceList.Count())
|
|
358 |
{
|
|
359 |
User::Leave(KErrNotFound);
|
|
360 |
}
|
|
361 |
|
|
362 |
return index;
|
|
363 |
}
|
|
364 |
|
|
365 |
|
|
366 |
TInt CUsbMsMountManager::GetHandleIndexL(TUint aDeviceHandle) const
|
|
367 |
{
|
|
368 |
TInt index;
|
|
369 |
for (index = 0; index < iDeviceList.Count(); index++)
|
|
370 |
{
|
|
371 |
if (aDeviceHandle == iDeviceList[index]->DeviceHandle())
|
|
372 |
{
|
|
373 |
break;
|
|
374 |
}
|
|
375 |
}
|
|
376 |
|
|
377 |
if (index == iDeviceList.Count())
|
|
378 |
{
|
|
379 |
User::Leave(KErrNotFound);
|
|
380 |
}
|
|
381 |
|
|
382 |
return index;
|
|
383 |
}
|
|
384 |
|
|
385 |
|
|
386 |
|
|
387 |
// mounts all LUNs for the device
|
|
388 |
void CUsbMsMountManager::MountDeviceL(TUint aDeviceHandle)
|
|
389 |
{
|
|
390 |
TInt index = GetHandleIndexL(aDeviceHandle);
|
|
391 |
iDeviceList[index]->MountLogicalUnitsL();
|
|
392 |
}
|
|
393 |
|
|
394 |
|
|
395 |
|
|
396 |
// dismount all LUNs for this device
|
|
397 |
void CUsbMsMountManager::DismountDeviceL(TUint aDeviceHandle)
|
|
398 |
{
|
|
399 |
TInt index = GetHandleIndexL(aDeviceHandle);
|
|
400 |
iDeviceList[index]->DismountLogicalUnitsL();
|
|
401 |
}
|
|
402 |
|
|
403 |
|
|
404 |
// dismount all LUNs
|
|
405 |
void CUsbMsMountManager::DismountL()
|
|
406 |
{
|
|
407 |
for (TInt i = 0; i < iDeviceList.Count(); i++)
|
|
408 |
{
|
|
409 |
iDeviceList[i]->DismountLogicalUnitsL();
|
|
410 |
}
|
|
411 |
}
|
|
412 |
|
|
413 |
|
|
414 |
void CUsbMsMountManager::DriveMap(TDriveMap& aDriveMap) const
|
|
415 |
{
|
|
416 |
TInt maxLun = 0;
|
|
417 |
RDebug::Printf("DeviceList.Count=%d", iDeviceList.Count());
|
|
418 |
for (TInt i = 0; i < iDeviceList.Count(); i++)
|
|
419 |
{
|
|
420 |
maxLun = iDeviceList[i]->DriveMap(aDriveMap);
|
|
421 |
RDebug::Printf("%d %d", i, maxLun);
|
|
422 |
}
|
|
423 |
}
|
|
424 |
|
|
425 |
|
|
426 |
void CUsbMsMountManager::DeviceMap(TInt aDeviceIndex, TDeviceMap& aDeviceMap) const
|
|
427 |
{
|
|
428 |
RDebug::Printf("Device=%d", aDeviceIndex);
|
|
429 |
|
|
430 |
__ASSERT_DEBUG(aDeviceIndex < iDeviceList.Count(), User::Invariant());
|
|
431 |
iDeviceList[aDeviceIndex]->DeviceMap(aDeviceMap);
|
|
432 |
}
|
|
433 |
|
|
434 |
|
|
435 |
|
|
436 |
TUsbPrint::TUsbPrint()
|
|
437 |
: iDebug(EFalse)
|
|
438 |
{
|
|
439 |
}
|
|
440 |
|
|
441 |
void TUsbPrint::PrintTree(const TUsbGenericDescriptor& aDesc, TInt aDepth)
|
297
|
442 |
{
|
0
|
443 |
if (!iDebug)
|
|
444 |
{
|
|
445 |
return;
|
|
446 |
}
|
|
447 |
|
297
|
448 |
TBuf<20> buf;
|
|
449 |
for(TInt depth=aDepth;depth>=0;--depth)
|
|
450 |
{
|
|
451 |
buf.Append(_L(" "));
|
|
452 |
}
|
|
453 |
if(aDesc.iRecognisedAndParsed == TUsbGenericDescriptor::ERecognised)
|
|
454 |
{
|
|
455 |
RDebug::Print(_L("%S+0x%08x - %d 0x%02x"), &buf, &aDesc, aDesc.ibLength, aDesc.ibDescriptorType);
|
|
456 |
}
|
|
457 |
else
|
|
458 |
{
|
|
459 |
RDebug::Print(_L("%S-0x%08x - %d 0x%02x"), &buf, &aDesc, aDesc.ibLength, aDesc.ibDescriptorType);
|
|
460 |
}
|
|
461 |
HBufC* blob = HBufC::New(5*aDesc.iBlob.Length()); // 5* for " 0x" + 2*bytes for hex representation
|
|
462 |
if(blob)
|
|
463 |
{
|
|
464 |
for(TInt i=0;i<aDesc.iBlob.Length();++i)
|
|
465 |
{
|
|
466 |
blob->Des().AppendFormat(_L("0x%02x "), aDesc.iBlob[i]);
|
|
467 |
}
|
|
468 |
RDebug::Print(_L("%S >%S"), &buf, blob);
|
|
469 |
delete blob;
|
|
470 |
}
|
|
471 |
if(aDesc.iFirstChild)
|
|
472 |
{
|
|
473 |
RDebug::Print(_L("%S \\ "), &buf);
|
|
474 |
PrintTree(*(aDesc.iFirstChild), aDepth+1);
|
|
475 |
RDebug::Print(_L("%S / "), &buf);
|
|
476 |
}
|
|
477 |
if(aDesc.iNextPeer)
|
|
478 |
{
|
|
479 |
PrintTree(*(aDesc.iNextPeer), aDepth);
|
|
480 |
}
|
|
481 |
}
|
0
|
482 |
|
|
483 |
|
|
484 |
static TUint16 gLangId = 0x0000;
|
|
485 |
|
|
486 |
void TUsbPrint::SetLanguageToPrintL(RUsbDevice& aDevice)
|
297
|
487 |
{
|
0
|
488 |
if (!iDebug) return;
|
|
489 |
|
297
|
490 |
// Try to set language to US Eng, otherwise take the first one listed.
|
|
491 |
if(gLangId == 0x0000) // Only make the request if not been made before.
|
|
492 |
{
|
|
493 |
// Get string descriptor 0.
|
|
494 |
TBuf8<256> stringBuf;
|
|
495 |
TUsbStringDescriptor* stringDesc = NULL;
|
|
496 |
User::LeaveIfError(aDevice.GetStringDescriptor(stringDesc, stringBuf, 0));
|
|
497 |
CleanupStack::PushL(*stringDesc);
|
0
|
498 |
|
297
|
499 |
// Search for US English
|
|
500 |
TBool usEngLang = EFalse;
|
|
501 |
TInt langId = 0;
|
|
502 |
TInt index = 0;
|
|
503 |
const TUint16 KLangIdUsEng = 0x0409;
|
|
504 |
while(!usEngLang && langId != KErrNotFound)
|
|
505 |
{
|
|
506 |
langId = stringDesc->GetLangId(index);
|
|
507 |
usEngLang = (langId == KLangIdUsEng);
|
|
508 |
index++;
|
|
509 |
}
|
0
|
510 |
|
297
|
511 |
// Set the language appropriately
|
|
512 |
if(usEngLang)
|
|
513 |
{
|
|
514 |
gLangId = KLangIdUsEng;
|
|
515 |
}
|
|
516 |
else
|
|
517 |
{
|
|
518 |
gLangId = stringDesc->GetLangId(0);
|
|
519 |
}
|
0
|
520 |
|
297
|
521 |
CleanupStack::PopAndDestroy(); // stringDesc
|
|
522 |
}
|
|
523 |
}
|
0
|
524 |
|
|
525 |
|
|
526 |
void TUsbPrint::PrintStringFromIndex(const TDesC& aFormatString,
|
|
527 |
TInt aIndex,
|
|
528 |
RUsbDevice* aDevice)
|
297
|
529 |
{
|
0
|
530 |
if (!iDebug) return;
|
|
531 |
|
297
|
532 |
// If we have no device handle, we cannot go and get any strings.
|
|
533 |
// If we have index 0, this indicates we don't have a string for this entry.
|
|
534 |
if(aDevice && aIndex != 0)
|
|
535 |
{
|
|
536 |
TRAPD(err, SetLanguageToPrintL(*aDevice));
|
|
537 |
if(err == KErrNone)
|
|
538 |
{
|
|
539 |
TBuf8<255> stringBuf;
|
|
540 |
TUsbStringDescriptor* stringDesc = NULL;
|
|
541 |
err = aDevice->GetStringDescriptor(stringDesc, stringBuf, aIndex, gLangId);
|
|
542 |
if(err == KErrNone)
|
|
543 |
{
|
|
544 |
TBuf<128> buf;
|
|
545 |
stringDesc->StringData(buf);
|
|
546 |
RDebug::Print(aFormatString, &buf);
|
|
547 |
stringDesc->DestroyTree();
|
|
548 |
}
|
|
549 |
delete stringDesc;
|
|
550 |
}
|
|
551 |
else
|
|
552 |
{
|
|
553 |
RDebug::Print(_L("Error while Selecting Langauge %d\n"), err);
|
|
554 |
}
|
|
555 |
}
|
|
556 |
}
|
0
|
557 |
|
|
558 |
|
|
559 |
void TUsbPrint::PrintDescriptor(const TUsbDeviceDescriptor& aDeviceDesc,
|
|
560 |
TInt /*aVariant*/,
|
|
561 |
RUsbDevice* aDevice)
|
297
|
562 |
{
|
0
|
563 |
if (!iDebug) return;
|
|
564 |
|
297
|
565 |
RDebug::Print(_L("USBBcd = 0x%04x\n"), aDeviceDesc.USBBcd());
|
|
566 |
RDebug::Print(_L("DeviceClass = 0x%02x\n"), aDeviceDesc.DeviceClass());
|
|
567 |
RDebug::Print(_L("DeviceSubClass = 0x%02x\n"), aDeviceDesc.DeviceSubClass());
|
|
568 |
RDebug::Print(_L("DeviceProtocol = 0x%02x\n"), aDeviceDesc.DeviceProtocol());
|
|
569 |
RDebug::Print(_L("MaxPacketSize0 = 0x%02x\n"), aDeviceDesc.MaxPacketSize0());
|
|
570 |
RDebug::Print(_L("VendorId = 0x%04x\n"), aDeviceDesc.VendorId());
|
|
571 |
RDebug::Print(_L("ProductId = 0x%04x\n"), aDeviceDesc.ProductId());
|
|
572 |
RDebug::Print(_L("DeviceBcd = 0x%04x\n"), aDeviceDesc.DeviceBcd());
|
|
573 |
RDebug::Print(_L("ManufacturerIndex = 0x%02x\n"), aDeviceDesc.ManufacturerIndex());
|
|
574 |
PrintStringFromIndex(_L("ManufacturerString = %S\n"), aDeviceDesc.ManufacturerIndex(), aDevice);
|
|
575 |
RDebug::Print(_L("ProductIndex = 0x%02x\n"), aDeviceDesc.ProductIndex());
|
|
576 |
PrintStringFromIndex(_L("ProductString = %S\n"), aDeviceDesc.ProductIndex(), aDevice);
|
|
577 |
RDebug::Print(_L("SerialNumberIndex = 0x%02x\n"), aDeviceDesc.SerialNumberIndex());
|
|
578 |
PrintStringFromIndex(_L("SerialNumberString = %S\n"), aDeviceDesc.SerialNumberIndex(), aDevice);
|
|
579 |
RDebug::Print(_L("NumConfigurations = 0x%02x\n"), aDeviceDesc.NumConfigurations());
|
|
580 |
}
|
0
|
581 |
|
|
582 |
|
|
583 |
void TUsbPrint::PrintDescriptor(const TUsbConfigurationDescriptor& aConfigDesc,
|
|
584 |
TInt /*aVariant*/,
|
|
585 |
RUsbDevice* aDevice)
|
297
|
586 |
{
|
0
|
587 |
if (!iDebug) return;
|
297
|
588 |
RDebug::Print(_L("TotalLength = 0x%04x\n"), aConfigDesc.TotalLength());
|
|
589 |
RDebug::Print(_L("NumInterfaces = 0x%02x\n"), aConfigDesc.NumInterfaces());
|
|
590 |
RDebug::Print(_L("ConfigurationValue = 0x%02x\n"), aConfigDesc.ConfigurationValue());
|
|
591 |
RDebug::Print(_L("ConfigurationIndex = 0x%02x\n"), aConfigDesc.ConfigurationIndex());
|
|
592 |
PrintStringFromIndex(_L("ConfigurationString = %S\n"), aConfigDesc.ConfigurationIndex(), aDevice);
|
|
593 |
RDebug::Print(_L("Attributes = 0x%02x\n"), aConfigDesc.Attributes());
|
|
594 |
RDebug::Print(_L("MaxPower = 0x%02x\n"), aConfigDesc.MaxPower());
|
|
595 |
}
|
0
|
596 |
|
|
597 |
|
|
598 |
void TUsbPrint::PrintDescriptor(const TUsbEndpointDescriptor& aEndpointDesc,
|
|
599 |
TInt /*aVariant*/,
|
|
600 |
RUsbDevice* /*aDevice*/)
|
297
|
601 |
{
|
0
|
602 |
if (!iDebug) return;
|
297
|
603 |
RDebug::Print(_L("EndpointAddress = 0x%02x\n"), aEndpointDesc.EndpointAddress());
|
|
604 |
RDebug::Print(_L("Attributes = 0x%02x\n"), aEndpointDesc.Attributes());
|
|
605 |
RDebug::Print(_L("MaxPacketSize = 0x%04x\n"), aEndpointDesc.MaxPacketSize());
|
|
606 |
RDebug::Print(_L("Interval = 0x%02x\n"), aEndpointDesc.Interval());
|
|
607 |
}
|
0
|
608 |
|
|
609 |
|
|
610 |
void TUsbPrint::PrintDescriptor(const TUsbInterfaceDescriptor& aInterfaceDesc,
|
|
611 |
TInt /*aVariant*/,
|
|
612 |
RUsbDevice* /*aDevice*/)
|
297
|
613 |
{
|
0
|
614 |
if (!iDebug) return;
|
297
|
615 |
RDebug::Print(_L("InterfaceNumber = 0x%02x\n"), aInterfaceDesc.InterfaceNumber());
|
|
616 |
RDebug::Print(_L("AlternateSetting = 0x%02x\n"), aInterfaceDesc.AlternateSetting());
|
|
617 |
RDebug::Print(_L("NumEndpoints = 0x%02x\n"), aInterfaceDesc.NumEndpoints());
|
|
618 |
RDebug::Print(_L("InterfaceClass = 0x%02x\n"), aInterfaceDesc.InterfaceClass());
|
|
619 |
RDebug::Print(_L("InterfaceSubClass = 0x%02x\n"), aInterfaceDesc.InterfaceSubClass());
|
|
620 |
RDebug::Print(_L("InterfaceProtocol = 0x%02x\n"), aInterfaceDesc.InterfaceProtocol());
|
|
621 |
RDebug::Print(_L("Interface = 0x%02x\n"), aInterfaceDesc.Interface());
|
|
622 |
}
|
0
|
623 |
|
|
624 |
|
|
625 |
void TUsbPrint::PrintDescriptor(const TUsbStringDescriptor& aStringDesc,
|
|
626 |
TInt aVariant,
|
|
627 |
RUsbDevice* /*aDevice*/)
|
297
|
628 |
{
|
0
|
629 |
if (!iDebug) return;
|
297
|
630 |
if(aVariant == 0)
|
|
631 |
{
|
|
632 |
RDebug::Print(_L("String Descriptor Zero\n"));
|
|
633 |
TInt index = 0;
|
|
634 |
TInt langId = 0;
|
|
635 |
while((langId = aStringDesc.GetLangId(index)) != KErrNotFound)
|
|
636 |
{
|
|
637 |
RDebug::Print(_L(" >0x%04x\n"), langId);
|
|
638 |
++index;
|
|
639 |
}
|
|
640 |
}
|
|
641 |
else
|
|
642 |
{
|
|
643 |
RDebug::Print(_L("Generic String Descriptor\n"));
|
|
644 |
HBufC16* string = HBufC16::New(128);
|
|
645 |
if(string)
|
|
646 |
{
|
|
647 |
TPtr16 stringPtr = string->Des();
|
|
648 |
aStringDesc.StringData(stringPtr);
|
|
649 |
RDebug::Print(_L(" >%S\n"), string);
|
|
650 |
}
|
|
651 |
delete string;
|
|
652 |
}
|
|
653 |
}
|