0
|
1 |
// Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
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 |
// e32test\usb\t_usb_win\src\t_usb_wintests.cpp
|
|
15 |
// Win32 USB test program performs I/O with a device running the
|
|
16 |
// Symbian OS test program T_USB_DEVICE, using the generic USB device driver USBIO.
|
|
17 |
// === Includes ===
|
|
18 |
//
|
|
19 |
//
|
|
20 |
|
|
21 |
#include "stdafx.h"
|
|
22 |
#include <process.h> /* _beginthread, _endthread */
|
|
23 |
|
|
24 |
#include <sys/timeb.h>
|
|
25 |
|
|
26 |
#include "usbio.h" // USBIO Dev Kit
|
|
27 |
#include "usbiopipe.h" // ditto
|
|
28 |
|
|
29 |
#include "t_usb_win.h"
|
|
30 |
#include "t_usb_winDlg.h"
|
|
31 |
|
|
32 |
#include "global.h"
|
|
33 |
|
|
34 |
#include "UsbcvControl.h"
|
|
35 |
|
|
36 |
#ifdef _DEBUG
|
|
37 |
#define new DEBUG_NEW
|
|
38 |
#undef THIS_FILE
|
|
39 |
static char THIS_FILE[] = __FILE__;
|
|
40 |
#endif
|
|
41 |
|
|
42 |
extern BOOL EjectVolume(char driveLetter);
|
|
43 |
extern BOOL WaitDriveReady (char driveLetter);
|
|
44 |
extern DWORD PerlScript(char * scriptName);
|
|
45 |
|
|
46 |
// === Global Vars ===
|
|
47 |
|
|
48 |
extern char gScriptFileName[];
|
|
49 |
extern char gManufacturerName[];
|
|
50 |
extern char gProductName[];
|
|
51 |
extern char gSerialNumber[];
|
|
52 |
extern char gLogfileName[];
|
|
53 |
extern BOOL gVerboseMode;
|
|
54 |
extern BOOL gKeepOpen;
|
|
55 |
extern BOOL gAbort;
|
|
56 |
extern int gTransferMode;
|
|
57 |
extern CT_usb_winDlg* gMainWindow;
|
|
58 |
extern FILE *logStream;
|
|
59 |
extern int gReadWriteTimeOut;
|
|
60 |
|
|
61 |
// Our own private GUID (also used in the .inf file as 'DriverUserInterfaceGuid')
|
|
62 |
// {55606403-E62D-4707-9F56-40D48C6736D0}
|
|
63 |
GUID gUsbioID =
|
|
64 |
{0x55606403, 0xe62d, 0x4707, {0x9f, 0x56, 0x40, 0xd4, 0x8c, 0x67, 0x36, 0xd0}};
|
|
65 |
|
|
66 |
// Another provate GUID used in the AtenSwitch.inf file
|
|
67 |
// {A6942415-49EE-4ef2-9CE8-D33E888EF133}
|
|
68 |
const GUID gSwitchID =
|
|
69 |
{0xA6942415, 0x49EE, 0x4ef2, {0x9C, 0xE8, 0xD3, 0x3E, 0x88, 0x8E, 0xF1, 0x33}};
|
|
70 |
|
|
71 |
// Handle for USB device list
|
|
72 |
static HDEVINFO gDevList = NULL;
|
|
73 |
|
|
74 |
// USBIO supported device
|
|
75 |
CUsbIo gUsbDev;
|
|
76 |
|
|
77 |
static int gDevNumber = -1;
|
|
78 |
static UCHAR gEndpointMap [MAX_INTERFACES] [MAX_SETTINGS] [MAX_ENDPOINTS];
|
|
79 |
static WORD gPacketSizeMap [MAX_INTERFACES] [MAX_SETTINGS] [MAX_ENDPOINTS];
|
|
80 |
static UCHAR gAlternateSettings [MAX_INTERFACES];
|
|
81 |
static bool gIsoEndpoint [MAX_INTERFACES] [MAX_SETTINGS] [MAX_ENDPOINTS];
|
|
82 |
|
|
83 |
static USHORT vendorId = 0;
|
|
84 |
static USHORT productId = 0;
|
|
85 |
static USHORT productIdMS = 0;
|
|
86 |
|
|
87 |
// endpoints
|
|
88 |
|
|
89 |
// Read/write buffer
|
|
90 |
static const DWORD KMaxTransferSize = 1024*1024;
|
|
91 |
static const DWORD KPreambleLength = 8;
|
|
92 |
|
|
93 |
static bool gFinishAllTests = false;
|
|
94 |
|
|
95 |
static HANDLE gThreadStartedEvent;
|
|
96 |
static HANDLE gThreadEndedEvents[MAX_THREADS];
|
|
97 |
static HANDLE gThreadWaitEvents[MAX_THREADS];
|
|
98 |
|
|
99 |
HANDLE gDeviceConnectEvent;
|
|
100 |
HANDLE gDeviceDisconnectEvent;
|
|
101 |
|
|
102 |
static __int64 gDeviceIdleCount = -1;
|
|
103 |
static struct _timeb gHostTime;
|
|
104 |
|
|
105 |
enum
|
|
106 |
{
|
|
107 |
EXml,
|
|
108 |
ELoop,
|
|
109 |
ECompare,
|
|
110 |
EReceiveOnly,
|
|
111 |
ETransmitOnly,
|
|
112 |
EFileReceive,
|
|
113 |
EFileTransmit,
|
|
114 |
EComment,
|
|
115 |
EConnect,
|
|
116 |
EDisconnect,
|
|
117 |
EWait,
|
|
118 |
EFail,
|
|
119 |
ESwitch,
|
|
120 |
EWaitConnect,
|
|
121 |
EWaitDisconnect,
|
|
122 |
EDo,
|
|
123 |
ERepeat,
|
|
124 |
EUsbcv,
|
|
125 |
EMassStorage,
|
|
126 |
EEject,
|
|
127 |
EPerl,
|
|
128 |
EWaitDrive,
|
|
129 |
};
|
|
130 |
|
|
131 |
enum Ep0Requests
|
|
132 |
{
|
|
133 |
EStop = 0x1,
|
|
134 |
EVersion = 0x10,
|
|
135 |
ETestParam = 0x20,
|
|
136 |
ETestResult = 0x30,
|
|
137 |
ETestFail = 0x40,
|
|
138 |
ETestConnect = 0x50,
|
|
139 |
ETestDisconnect = 0x60,
|
|
140 |
ETestMassStorage = 0x70,
|
|
141 |
ETestIdleCounter = 0x80,
|
|
142 |
};
|
|
143 |
|
|
144 |
struct TestParamHost
|
|
145 |
{
|
|
146 |
WORD displayRate;
|
|
147 |
DWORD outRate;
|
|
148 |
DWORD inRate;
|
|
149 |
BYTE index;
|
|
150 |
bool signalNextSettingThread;
|
|
151 |
};
|
|
152 |
typedef struct TestParamHost TestParamHostType;
|
|
153 |
|
|
154 |
struct TestParam
|
|
155 |
{
|
|
156 |
DWORD minSize;
|
|
157 |
DWORD maxSize;
|
|
158 |
DWORD packetNumber;
|
|
159 |
BYTE interfaceNumber;
|
|
160 |
BYTE alternateSetting;
|
|
161 |
BYTE outPipe;
|
|
162 |
BYTE inPipe;
|
|
163 |
WORD repeat;
|
|
164 |
WORD settingRepeat;
|
|
165 |
BYTE beforeIndex;
|
|
166 |
BYTE afterIndex;
|
|
167 |
TestParamHostType host;
|
|
168 |
TestParam ();
|
|
169 |
};
|
|
170 |
typedef struct TestParam TestParamType;
|
|
171 |
typedef TestParamType* TestParamPtr;
|
|
172 |
|
|
173 |
// The version of T_USB we require (at least)
|
|
174 |
static const DWORD KTusbVersionMajor = 1;
|
|
175 |
static const DWORD KTusbVersionMinor = 0;
|
|
176 |
static const DWORD KTusbVersionMicro = 1;
|
|
177 |
|
|
178 |
static const DWORD KHostLogFileSize = 64*1024;
|
|
179 |
|
|
180 |
#define ERR_SCRIPT_NAME 0xF0000001L
|
|
181 |
|
|
182 |
// use a timeout for a WaitConnect to activate a scan for hardware changes
|
|
183 |
#define CONNECT_RESCAN_TIMEOUT 300000
|
|
184 |
#define RESCAN_APPNAME "C:\\Program Files\\devcon\\i386\\devcon.exe"
|
|
185 |
#define RESCAN_CMDLINE " rescan"
|
|
186 |
|
|
187 |
/////////////////////////////////////////////////////////////////////////////
|
|
188 |
// global functions
|
|
189 |
|
|
190 |
//
|
|
191 |
// print to output window
|
|
192 |
//
|
|
193 |
// Note:
|
|
194 |
// This is a global function that is called from any thread context.
|
|
195 |
// It is not possible to call MFC objects from a thread context that is
|
|
196 |
// created by using non-MFC means.
|
|
197 |
// So we use SendMessage to access the OutputWindow.
|
|
198 |
//
|
|
199 |
void PrintOut(BOOL screenFlag, BOOL logFlag, BOOL timeFlag, const char *format, ...)
|
|
200 |
{
|
|
201 |
if (screenFlag)
|
|
202 |
{
|
|
203 |
const int buffersize = 512;
|
|
204 |
va_list argptr;
|
|
205 |
|
|
206 |
char buffer[buffersize];
|
|
207 |
|
|
208 |
// print to buffer
|
|
209 |
va_start(argptr,format);
|
|
210 |
_vsnprintf(buffer,buffersize-1,format,argptr);
|
|
211 |
buffer[buffersize-1] = 0;
|
|
212 |
|
|
213 |
// with a time stamp and carriage return linefeed
|
|
214 |
if (timeFlag)
|
|
215 |
{
|
|
216 |
SYSTEMTIME localTime;
|
|
217 |
|
|
218 |
GetLocalTime(&localTime);
|
|
219 |
|
|
220 |
unsigned int len = strlen(buffer);
|
|
221 |
|
|
222 |
GetDateFormat(LOCALE_USER_DEFAULT,0,&localTime,"dd MMM yyyy",&buffer[len],buffersize-len);
|
|
223 |
|
|
224 |
len = strlen(buffer);
|
|
225 |
|
|
226 |
GetTimeFormat(LOCALE_USER_DEFAULT,0,&localTime," H:mm:ss"NL,&buffer[len],buffersize-len);
|
|
227 |
}
|
|
228 |
|
|
229 |
// send buffer to output window (synchronous behavior for buffer protection)
|
|
230 |
gMainWindow->SendMessage(WM_USER_PRINTOUT,0,(LPARAM)buffer); \
|
|
231 |
|
|
232 |
if (logStream && logFlag)
|
|
233 |
fputs(buffer,logStream);
|
|
234 |
|
|
235 |
va_end(argptr);
|
|
236 |
}
|
|
237 |
}
|
|
238 |
|
|
239 |
static void Delay(int milliseconds)
|
|
240 |
{
|
|
241 |
PRINT_IF_VERBOSE "* Short wait... ");
|
|
242 |
Sleep(milliseconds);
|
|
243 |
PRINT_IF_VERBOSE "done"NL);
|
|
244 |
}
|
|
245 |
|
|
246 |
TestParam::TestParam()
|
|
247 |
{
|
|
248 |
minSize = 10;
|
|
249 |
maxSize = 100;
|
|
250 |
packetNumber = 0;
|
|
251 |
interfaceNumber = 0;
|
|
252 |
alternateSetting = 0;
|
|
253 |
outPipe = 2;
|
|
254 |
inPipe = 1;
|
|
255 |
repeat = 0;
|
|
256 |
settingRepeat = 0;
|
|
257 |
beforeIndex = 0;
|
|
258 |
host.displayRate = 100;
|
|
259 |
host.outRate = 0;
|
|
260 |
host.inRate = 0;
|
|
261 |
host.index = 0;
|
|
262 |
host.signalNextSettingThread = FALSE;
|
|
263 |
}
|
|
264 |
//
|
|
265 |
// Process a line from the test script file
|
|
266 |
// returns the test type and sets up the test parameter structure
|
|
267 |
//
|
|
268 |
static int ParseTestLine(char* aLine,TestParamPtr aParam, USBIO_CLASS_OR_VENDOR_REQUEST* aRequest)
|
|
269 |
{
|
|
270 |
int testType = EComment;
|
|
271 |
|
|
272 |
struct testKey
|
|
273 |
{
|
|
274 |
int testId;
|
|
275 |
char testString[20];
|
|
276 |
};
|
|
277 |
typedef struct testKey testKeyType;
|
|
278 |
size_t tokenLength = 0;
|
|
279 |
|
|
280 |
testKeyType testKeyTable[] =
|
|
281 |
{
|
|
282 |
EXml,"Xml",
|
|
283 |
ELoop,"Loop",
|
|
284 |
ECompare,"Compare",
|
|
285 |
EReceiveOnly,"Stream",
|
|
286 |
EFileReceive,"File",
|
|
287 |
EConnect,"Connect",
|
|
288 |
EDisconnect,"Disconnect",
|
|
289 |
EWait,"Wait",
|
|
290 |
EFail,"Fail",
|
|
291 |
ESwitch,"Switch",
|
|
292 |
EWaitConnect,"WaitConnect",
|
|
293 |
EWaitDisconnect, "WaitDisconnect",
|
|
294 |
ERepeat, "Repeat",
|
|
295 |
EDo, "Do",
|
|
296 |
EUsbcv, "Usbcv",
|
|
297 |
EMassStorage, "MStore",
|
|
298 |
EEject, "Eject",
|
|
299 |
EPerl, "Perl",
|
|
300 |
EWaitDrive, "WaitDrive",
|
|
301 |
};
|
|
302 |
|
|
303 |
size_t numKeys = sizeof( testKeyTable ) / sizeof( testKeyType );
|
|
304 |
|
|
305 |
char delim[] = " ,\t\n";
|
|
306 |
char stringDelim[] = "\"";
|
|
307 |
char * token = strtok(aLine,delim);
|
|
308 |
if (token == NULL)
|
|
309 |
{
|
|
310 |
return testType;
|
|
311 |
}
|
|
312 |
|
|
313 |
tokenLength = strlen(token);
|
|
314 |
|
|
315 |
memset (aParam,0,sizeof(TestParamType));
|
|
316 |
|
|
317 |
// default display rate
|
|
318 |
aParam->host.displayRate = 100;
|
|
319 |
|
|
320 |
for (int i = 0; i < (int)numKeys; i++)
|
|
321 |
{
|
|
322 |
if (strnicmp (token,testKeyTable[i].testString,tokenLength) == 0)
|
|
323 |
{
|
|
324 |
testType = testKeyTable[i].testId;
|
|
325 |
break;
|
|
326 |
}
|
|
327 |
}
|
|
328 |
|
|
329 |
|
|
330 |
int paramCount = 0;
|
|
331 |
// now set up test type in request setup packet
|
|
332 |
switch (testType)
|
|
333 |
{
|
|
334 |
case EXml:
|
|
335 |
aRequest->Value = 'X';
|
|
336 |
paramCount = 2;
|
|
337 |
break;
|
|
338 |
|
|
339 |
case ELoop:
|
|
340 |
aRequest->Value = 'L';
|
|
341 |
break;
|
|
342 |
|
|
343 |
case ECompare:
|
|
344 |
aRequest->Value = 'C';
|
|
345 |
break;
|
|
346 |
|
|
347 |
case EReceiveOnly:
|
|
348 |
aRequest->Value = 'S';
|
|
349 |
paramCount = 1;
|
|
350 |
break;
|
|
351 |
|
|
352 |
case EFileReceive:
|
|
353 |
aRequest->Value = 'F';
|
|
354 |
paramCount = 1;
|
|
355 |
break;
|
|
356 |
|
|
357 |
case EComment:
|
|
358 |
return testType;
|
|
359 |
break;
|
|
360 |
|
|
361 |
case EConnect:
|
|
362 |
aRequest->Value = 'R';
|
|
363 |
break;
|
|
364 |
|
|
365 |
case EDisconnect:
|
|
366 |
aRequest->Value = 'D';
|
|
367 |
break;
|
|
368 |
|
|
369 |
case EWait:
|
|
370 |
aParam->minSize = INFINITE;
|
|
371 |
break;
|
|
372 |
|
|
373 |
case EWaitConnect:
|
|
374 |
aParam->minSize = INFINITE;
|
|
375 |
break;
|
|
376 |
|
|
377 |
case EWaitDisconnect:
|
|
378 |
aParam->minSize = INFINITE;
|
|
379 |
break;
|
|
380 |
|
|
381 |
case EFail:
|
|
382 |
case ESwitch:
|
|
383 |
case EDo:
|
|
384 |
case ERepeat:
|
|
385 |
case EUsbcv:
|
|
386 |
case EMassStorage:
|
|
387 |
case EEject:
|
|
388 |
case EPerl:
|
|
389 |
case EWaitDrive:
|
|
390 |
break;
|
|
391 |
|
|
392 |
}
|
|
393 |
|
|
394 |
if (testType == EPerl)
|
|
395 |
{
|
|
396 |
// a space at the beginning of the line
|
|
397 |
aLine[0] = ' ';
|
|
398 |
strcpy(&aLine[1],&aLine[tokenLength+1]);
|
|
399 |
// strip off carriage return or line feed
|
|
400 |
if (iscntrl(aLine[strlen(aLine)-1]))
|
|
401 |
{
|
|
402 |
aLine[strlen(aLine)-1] = '\0';
|
|
403 |
if (iscntrl(aLine[strlen(aLine)-1]))
|
|
404 |
aLine[strlen(aLine)-1] = '\0';
|
|
405 |
}
|
|
406 |
return testType;
|
|
407 |
}
|
|
408 |
|
|
409 |
token = strtok(NULL,delim);
|
|
410 |
if (testType == EEject || testType == EWaitDrive)
|
|
411 |
{
|
|
412 |
strcpy(aLine,token);
|
|
413 |
|
|
414 |
return testType;
|
|
415 |
}
|
|
416 |
|
|
417 |
if (testType == EFileReceive)
|
|
418 |
{
|
|
419 |
// The first parameter is the drive letter on the device to use
|
|
420 |
if (token != NULL)
|
|
421 |
aParam->minSize = token[0];
|
|
422 |
else
|
|
423 |
aParam->minSize = 'D';
|
|
424 |
|
|
425 |
token = strtok(NULL,delim);
|
|
426 |
}
|
|
427 |
|
|
428 |
while (token != NULL)
|
|
429 |
{
|
|
430 |
unsigned long ulParam = strtoul (token,NULL,0);
|
|
431 |
switch (paramCount)
|
|
432 |
{
|
|
433 |
case 0 :
|
|
434 |
aParam->minSize = (DWORD)ulParam;
|
|
435 |
break;
|
|
436 |
|
|
437 |
case 1 :
|
|
438 |
aParam->maxSize = (DWORD)ulParam;
|
|
439 |
break;
|
|
440 |
|
|
441 |
case 2 :
|
|
442 |
aParam->packetNumber = (DWORD)ulParam;
|
|
443 |
break;
|
|
444 |
|
|
445 |
case 3 :
|
|
446 |
aParam->interfaceNumber = (BYTE)ulParam;
|
|
447 |
break;
|
|
448 |
|
|
449 |
case 4:
|
|
450 |
aParam->alternateSetting = (BYTE)ulParam;
|
|
451 |
// skip outpipe for Xml IN
|
|
452 |
if (testType == EXml)
|
|
453 |
{
|
|
454 |
paramCount++;
|
|
455 |
}
|
|
456 |
break;
|
|
457 |
|
|
458 |
case 5:
|
|
459 |
aParam->outPipe = (BYTE)ulParam;
|
|
460 |
break;
|
|
461 |
|
|
462 |
case 6 :
|
|
463 |
aParam->inPipe = (BYTE)ulParam;
|
|
464 |
if (aParam->inPipe > 31)
|
|
465 |
{
|
|
466 |
if (testType == EReceiveOnly)
|
|
467 |
testType = ETransmitOnly;
|
|
468 |
if (testType == EFileReceive)
|
|
469 |
testType = EFileTransmit;
|
|
470 |
}
|
|
471 |
break;
|
|
472 |
|
|
473 |
case 7 :
|
|
474 |
aParam->repeat = (WORD)ulParam;
|
|
475 |
break;
|
|
476 |
|
|
477 |
case 8 :
|
|
478 |
aParam->host.displayRate = (WORD)ulParam;
|
|
479 |
break;
|
|
480 |
|
|
481 |
case 9 :
|
|
482 |
aParam->settingRepeat = (WORD)ulParam;
|
|
483 |
break;
|
|
484 |
|
|
485 |
case 10 :
|
|
486 |
aParam->beforeIndex = (BYTE)ulParam;
|
|
487 |
break;
|
|
488 |
|
|
489 |
case 11 :
|
|
490 |
aParam->afterIndex = (BYTE)ulParam;
|
|
491 |
break;
|
|
492 |
|
|
493 |
case 12 :
|
|
494 |
aParam->host.outRate = (DWORD)ulParam;
|
|
495 |
break;
|
|
496 |
|
|
497 |
case 13 :
|
|
498 |
aParam->host.inRate = (DWORD)ulParam;
|
|
499 |
break;
|
|
500 |
}
|
|
501 |
|
|
502 |
paramCount++;
|
|
503 |
token = strtok(NULL,delim);
|
|
504 |
}
|
|
505 |
|
|
506 |
return testType;
|
|
507 |
}
|
|
508 |
|
|
509 |
static void ShowErrorText (DWORD errCode)
|
|
510 |
{
|
|
511 |
char textBuf[80];
|
|
512 |
|
|
513 |
CUsbIo::ErrorText(textBuf,80,errCode);
|
|
514 |
|
|
515 |
PRINT_ALWAYS "%s"NL,textBuf);
|
|
516 |
|
|
517 |
gAbort = true;
|
|
518 |
}
|
|
519 |
|
|
520 |
static DWORD OpenUsbDevice()
|
|
521 |
{
|
|
522 |
DWORD dwRC;
|
|
523 |
USB_DEVICE_DESCRIPTOR DevDesc;
|
|
524 |
// buffer used to store string descriptor
|
|
525 |
unsigned char StrDescBuffer[sizeof(USB_STRING_DESCRIPTOR)+512];
|
|
526 |
// pointer to USB string descriptor
|
|
527 |
USB_STRING_DESCRIPTOR* StrDesc;
|
|
528 |
DWORD StrDescSize;
|
|
529 |
WCHAR * WideString;
|
|
530 |
// helper variables
|
|
531 |
bool deviceFound = false;
|
|
532 |
bool moreDevices = true;
|
|
533 |
|
|
534 |
if (gDevList)
|
|
535 |
{
|
|
536 |
CUsbIo::DestroyDeviceList(gDevList);
|
|
537 |
gDevList = NULL;
|
|
538 |
gDevNumber = -1;
|
|
539 |
gUsbDev.Close();
|
|
540 |
}
|
|
541 |
|
|
542 |
|
|
543 |
// Enumerate attached USB devices supported by USBIO
|
|
544 |
gDevList = CUsbIo::CreateDeviceList(&gUsbioID);
|
|
545 |
|
|
546 |
|
|
547 |
if ( gDevList==NULL )
|
|
548 |
{
|
|
549 |
PRINT_ALWAYS "Unable to build a device list!"NL);
|
|
550 |
return USBIO_ERR_FAILED;
|
|
551 |
}
|
|
552 |
|
|
553 |
// open and query each device (max. 127)
|
|
554 |
for ( int i=0; i < 127 && !deviceFound && moreDevices; i++ )
|
|
555 |
{
|
|
556 |
StrDesc = NULL;
|
|
557 |
|
|
558 |
// open the device, using the global CUsbIo instance
|
|
559 |
dwRC = gUsbDev.Open(i,gDevList,&gUsbioID);
|
|
560 |
if ( dwRC != USBIO_ERR_SUCCESS )
|
|
561 |
{
|
|
562 |
// no more devices, or error leave loop
|
|
563 |
moreDevices = false;
|
|
564 |
break;
|
|
565 |
}
|
|
566 |
|
|
567 |
// we have found a device, query the device descriptor
|
|
568 |
dwRC = gUsbDev.GetDeviceDescriptor(&DevDesc);
|
|
569 |
if ( dwRC == USBIO_ERR_SUCCESS )
|
|
570 |
{
|
|
571 |
deviceFound = true;
|
|
572 |
// Check manufacturer string
|
|
573 |
if (strlen(gManufacturerName))
|
|
574 |
{
|
|
575 |
// Does the device have a manufacturer?
|
|
576 |
if ( DevDesc.iManufacturer != NULL )
|
|
577 |
{
|
|
578 |
WideString = new(WCHAR [strlen(gManufacturerName)+1]);
|
|
579 |
for (unsigned int j = 0; j < strlen(gManufacturerName); j++)
|
|
580 |
{
|
|
581 |
WideString[j] = (WCHAR)gManufacturerName[j];
|
|
582 |
}
|
|
583 |
WideString[strlen(gManufacturerName)] = (WCHAR)0;
|
|
584 |
// query the corresponding string descriptor
|
|
585 |
StrDesc = (USB_STRING_DESCRIPTOR*)StrDescBuffer;
|
|
586 |
StrDescSize = sizeof(StrDescBuffer);
|
|
587 |
dwRC = gUsbDev.GetStringDescriptor(StrDesc,StrDescSize,DevDesc.iManufacturer);
|
|
588 |
if ( dwRC == USBIO_ERR_SUCCESS )
|
|
589 |
{
|
|
590 |
size_t stringSize = wcslen (WideString);
|
|
591 |
if (stringSize != (size_t)(StrDesc->bLength - 2)/2)
|
|
592 |
deviceFound = false;
|
|
593 |
else
|
|
594 |
{
|
|
595 |
if (wcsncmp (WideString,StrDesc->bString,stringSize) != 0)
|
|
596 |
deviceFound = false;
|
|
597 |
}
|
|
598 |
}
|
|
599 |
else
|
|
600 |
{
|
|
601 |
deviceFound = false;
|
|
602 |
}
|
|
603 |
delete WideString;
|
|
604 |
}
|
|
605 |
else
|
|
606 |
{
|
|
607 |
deviceFound = false;
|
|
608 |
}
|
|
609 |
}
|
|
610 |
|
|
611 |
// check product string
|
|
612 |
if (strlen(gProductName))
|
|
613 |
{
|
|
614 |
// Does the device have a manufacturer?
|
|
615 |
if ( DevDesc.iProduct !=0 )
|
|
616 |
{
|
|
617 |
WideString = new(WCHAR [strlen(gProductName)+1]);
|
|
618 |
for (unsigned int j = 0; j < strlen(gProductName); j++)
|
|
619 |
{
|
|
620 |
WideString[j] = (WCHAR)gProductName[j];
|
|
621 |
}
|
|
622 |
WideString[strlen(gProductName)] = (WCHAR)0;
|
|
623 |
// query the corresponding string descriptor
|
|
624 |
StrDesc = (USB_STRING_DESCRIPTOR*)StrDescBuffer;
|
|
625 |
StrDescSize = sizeof(StrDescBuffer);
|
|
626 |
dwRC = gUsbDev.GetStringDescriptor(StrDesc,StrDescSize,DevDesc.iProduct);
|
|
627 |
if ( dwRC == USBIO_ERR_SUCCESS )
|
|
628 |
{
|
|
629 |
size_t stringSize = wcslen (WideString);
|
|
630 |
if (stringSize != (size_t)(StrDesc->bLength - 2)/2)
|
|
631 |
deviceFound = false;
|
|
632 |
else
|
|
633 |
{
|
|
634 |
if (wcsncmp (WideString,StrDesc->bString,stringSize) != 0)
|
|
635 |
deviceFound = false;
|
|
636 |
}
|
|
637 |
}
|
|
638 |
else
|
|
639 |
{
|
|
640 |
deviceFound = false;
|
|
641 |
}
|
|
642 |
delete WideString;
|
|
643 |
}
|
|
644 |
else
|
|
645 |
{
|
|
646 |
deviceFound = false;
|
|
647 |
}
|
|
648 |
}
|
|
649 |
|
|
650 |
// check serial number string
|
|
651 |
if (strlen(gSerialNumber))
|
|
652 |
{
|
|
653 |
// Does the device have a serial number?
|
|
654 |
if ( DevDesc.iSerialNumber !=0 )
|
|
655 |
{
|
|
656 |
WideString = new(WCHAR [strlen(gSerialNumber)+1]);
|
|
657 |
for (unsigned int j = 0; j < strlen(gSerialNumber); j++)
|
|
658 |
{
|
|
659 |
WideString[j] = (WCHAR)gSerialNumber[j];
|
|
660 |
}
|
|
661 |
WideString[strlen(gSerialNumber)] = (WCHAR)0;
|
|
662 |
// query the corresponding string descriptor
|
|
663 |
StrDesc = (USB_STRING_DESCRIPTOR*)StrDescBuffer;
|
|
664 |
StrDescSize = sizeof(StrDescBuffer);
|
|
665 |
dwRC = gUsbDev.GetStringDescriptor(StrDesc,StrDescSize,DevDesc.iSerialNumber);
|
|
666 |
if ( dwRC == USBIO_ERR_SUCCESS )
|
|
667 |
{
|
|
668 |
size_t stringSize = wcslen (WideString);
|
|
669 |
if (stringSize != (size_t)(StrDesc->bLength - 2)/2)
|
|
670 |
deviceFound = false;
|
|
671 |
else
|
|
672 |
{
|
|
673 |
if (wcsncmp (WideString,StrDesc->bString,stringSize) != 0)
|
|
674 |
deviceFound = false;
|
|
675 |
}
|
|
676 |
}
|
|
677 |
else
|
|
678 |
{
|
|
679 |
deviceFound = false;
|
|
680 |
}
|
|
681 |
delete WideString;
|
|
682 |
}
|
|
683 |
else
|
|
684 |
{
|
|
685 |
deviceFound = false;
|
|
686 |
}
|
|
687 |
}
|
|
688 |
if (deviceFound)
|
|
689 |
{
|
|
690 |
gDevNumber = i;
|
|
691 |
}
|
|
692 |
else
|
|
693 |
{
|
|
694 |
// close device
|
|
695 |
gUsbDev.Close();
|
|
696 |
}
|
|
697 |
}
|
|
698 |
else
|
|
699 |
{
|
|
700 |
// close device
|
|
701 |
gUsbDev.Close();
|
|
702 |
}
|
|
703 |
} // for
|
|
704 |
|
|
705 |
|
|
706 |
if (dwRC == USBIO_ERR_VERSION_MISMATCH)
|
|
707 |
{
|
|
708 |
PRINT_ALWAYS "\n* Error: \"The API version reported by the TUSBWIN driver"NL \
|
|
709 |
"* does not match the expected version.\""NL);
|
|
710 |
PRINT_ALWAYS "* The driver will need to be updated as follows:"NL);
|
|
711 |
PRINT_ALWAYS "* 1. Connect the device to the PC & start T_USB,"NL \
|
|
712 |
"* then find the USB device in the Windows Device Manager"NL \
|
|
713 |
"* ('Control Panel'->'System'->'Hardware'->'Device Manager')."NL \
|
|
714 |
"* Right click on the device name and choose 'Uninstall...'."NL);
|
|
715 |
PRINT_ALWAYS "* 2. In c:\\winnt\\inf\\, find (by searching for \"Symbian\") and"NL \
|
|
716 |
"* delete the *.INF file that was used to install the existing"NL \
|
|
717 |
"* version of TUSBWIN.SYS. Make sure to also delete the"NL \
|
|
718 |
"* precompiled version of that file (<samename>.PNF)."NL);
|
|
719 |
PRINT_ALWAYS "* 3. In c:\\winnt\\system32\\drivers\\, delete the file TUSBWIN.SYS."NL);
|
|
720 |
PRINT_ALWAYS "* Then unplug & reconnect the USB device and, when prompted, install"NL \
|
|
721 |
"* the new TUSBWIN.SYS driver using the .INF file from this distribution."NL \
|
|
722 |
"* (All files can be found under e32test\\usb\t_usb_win\\bin_distribution\\.)"NL);
|
|
723 |
}
|
|
724 |
|
|
725 |
return dwRC;
|
|
726 |
}
|
|
727 |
|
|
728 |
static DWORD OpenSwitchDevice()
|
|
729 |
{
|
|
730 |
DWORD dwRC;
|
|
731 |
|
|
732 |
if (gDevList)
|
|
733 |
{
|
|
734 |
CUsbIo::DestroyDeviceList(gDevList);
|
|
735 |
gDevList = NULL;
|
|
736 |
gUsbDev.Close();
|
|
737 |
}
|
|
738 |
|
|
739 |
// Enumerate attached USB devices supported by USBIO
|
|
740 |
gDevList = CUsbIo::CreateDeviceList(&gSwitchID);
|
|
741 |
|
|
742 |
if (gDevList)
|
|
743 |
{
|
|
744 |
// Open first device in list
|
|
745 |
dwRC = gUsbDev.Open(0, gDevList, &gSwitchID);
|
|
746 |
|
|
747 |
PRINT_IF_VERBOSE "\nCUsbIo::Open returned <0x%X>"NL, dwRC);
|
|
748 |
}
|
|
749 |
else
|
|
750 |
{
|
|
751 |
dwRC = USBIO_ERR_DEVICE_NOT_FOUND;
|
|
752 |
}
|
|
753 |
|
|
754 |
return dwRC;
|
|
755 |
}
|
|
756 |
|
|
757 |
static void CloseUsbDevice()
|
|
758 |
{
|
|
759 |
// Close the device
|
|
760 |
gUsbDev.Close();
|
|
761 |
PRINT_IF_VERBOSE "CUsbIo::Close called"NL);
|
|
762 |
}
|
|
763 |
|
|
764 |
static DWORD GetDeviceDescriptor()
|
|
765 |
{
|
|
766 |
DWORD dwRC;
|
|
767 |
USB_DEVICE_DESCRIPTOR DeviceDescriptor;
|
|
768 |
|
|
769 |
memset(&DeviceDescriptor, 0, sizeof(USB_DEVICE_DESCRIPTOR));
|
|
770 |
|
|
771 |
// Get device descriptor
|
|
772 |
dwRC = gUsbDev.GetDeviceDescriptor(&DeviceDescriptor);
|
|
773 |
PRINT_IF_VERBOSE "CUsbIo::GetDeviceDescriptor returned <0x%X>"NL, dwRC);
|
|
774 |
|
|
775 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
776 |
{
|
|
777 |
vendorId = DeviceDescriptor.idVendor;
|
|
778 |
productId = DeviceDescriptor.idProduct;
|
|
779 |
}
|
|
780 |
|
|
781 |
if (gVerboseMode && (dwRC == USBIO_ERR_SUCCESS))
|
|
782 |
{
|
|
783 |
PRINT_ALWAYS "\nDEVICE DESCRIPTOR:"NL
|
|
784 |
"bLength = <%u>"NL
|
|
785 |
"bDescriptorType = <%u>"NL
|
|
786 |
"bcdUSB = <%u>"NL
|
|
787 |
"bDeviceClass = <%u>"NL
|
|
788 |
"bDeviceSubClass = <%u>"NL
|
|
789 |
"bDeviceProtocol = <%u>"NL
|
|
790 |
"bMaxPacketSize0 = <%u>"NL
|
|
791 |
"idVendor = <%u>"NL
|
|
792 |
"idProduct = <%u>"NL
|
|
793 |
"bcdDevice = <%u>"NL
|
|
794 |
"iManufacturer = <%u>"NL
|
|
795 |
"iProduct = <%u>"NL
|
|
796 |
"iSerialNumber = <%u>"NL
|
|
797 |
"bNumConfigurations = <%u>\n"NL,
|
|
798 |
DeviceDescriptor.bLength,
|
|
799 |
DeviceDescriptor.bDescriptorType,
|
|
800 |
DeviceDescriptor.bcdUSB,
|
|
801 |
DeviceDescriptor.bDeviceClass,
|
|
802 |
DeviceDescriptor.bDeviceSubClass,
|
|
803 |
DeviceDescriptor.bDeviceProtocol,
|
|
804 |
DeviceDescriptor.bMaxPacketSize0,
|
|
805 |
DeviceDescriptor.idVendor,
|
|
806 |
DeviceDescriptor.idProduct,
|
|
807 |
DeviceDescriptor.bcdDevice,
|
|
808 |
DeviceDescriptor.iManufacturer,
|
|
809 |
DeviceDescriptor.iProduct,
|
|
810 |
DeviceDescriptor.iSerialNumber,
|
|
811 |
DeviceDescriptor.bNumConfigurations);
|
|
812 |
}
|
|
813 |
|
|
814 |
if (gVerboseMode)
|
|
815 |
{
|
|
816 |
USBIO_BANDWIDTH_INFO bwInfo;
|
|
817 |
|
|
818 |
// Get bandwidth available
|
|
819 |
dwRC = gUsbDev.GetBandwidthInfo (&bwInfo);
|
|
820 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
821 |
{
|
|
822 |
PRINT_ALWAYS "Bandwidth total %d consumed %d"NL,bwInfo.TotalBandwidth,bwInfo.ConsumedBandwidth);
|
|
823 |
}
|
|
824 |
}
|
|
825 |
|
|
826 |
return dwRC;
|
|
827 |
}
|
|
828 |
|
|
829 |
|
|
830 |
static DWORD GetConfigurationDescriptor()
|
|
831 |
{
|
|
832 |
DWORD dwRC;
|
|
833 |
int ifListIndex = 0;
|
|
834 |
|
|
835 |
CHAR szBuffer[MAX_DESCRIPTOR_BUFFER_SIZE] = "";
|
|
836 |
USB_CONFIGURATION_DESCRIPTOR* pConfigDescriptor = NULL;
|
|
837 |
USB_INTERFACE_DESCRIPTOR* pInterfaceDescriptor = NULL;
|
|
838 |
USB_ENDPOINT_DESCRIPTOR* pEndpointDescriptor = NULL;
|
|
839 |
|
|
840 |
DWORD dwByteCount = MAX_DESCRIPTOR_BUFFER_SIZE;
|
|
841 |
|
|
842 |
memset(szBuffer, 0, sizeof(szBuffer));
|
|
843 |
|
|
844 |
memset (gEndpointMap, 0, sizeof(gEndpointMap));
|
|
845 |
memset (gPacketSizeMap, 0, sizeof(gPacketSizeMap));
|
|
846 |
|
|
847 |
// force a set interface
|
|
848 |
memset (gAlternateSettings, 0, sizeof(gAlternateSettings));
|
|
849 |
|
|
850 |
// Get first configuration descriptor
|
|
851 |
dwRC = gUsbDev.GetConfigurationDescriptor((USB_CONFIGURATION_DESCRIPTOR*) szBuffer,
|
|
852 |
dwByteCount, 0);
|
|
853 |
PRINT_IF_VERBOSE "CUsbIo::GetConfigurationDescriptor returned <0x%X>"NL, dwRC);
|
|
854 |
|
|
855 |
USBIO_SET_CONFIGURATION SetConfig;
|
|
856 |
|
|
857 |
memset(&SetConfig, 0, sizeof(USBIO_SET_CONFIGURATION));
|
|
858 |
|
|
859 |
// Set the first configuration as active
|
|
860 |
SetConfig.ConfigurationIndex = 0;
|
|
861 |
|
|
862 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
863 |
{
|
|
864 |
USB_COMMON_DESCRIPTOR* Desc;
|
|
865 |
ULONG rl = dwByteCount;
|
|
866 |
ULONG ulDescLength = 0;
|
|
867 |
CHAR* data = szBuffer;
|
|
868 |
int interfaceNumber = 0;
|
|
869 |
int alternateSetting = 0;
|
|
870 |
int endpointIndex = 0;
|
|
871 |
|
|
872 |
while (rl > 0)
|
|
873 |
{
|
|
874 |
Desc = (USB_COMMON_DESCRIPTOR*) data;
|
|
875 |
ulDescLength = Desc->bLength;
|
|
876 |
if ((ulDescLength > rl) || (ulDescLength == 0))
|
|
877 |
{
|
|
878 |
PRINT_ALWAYS "Length remaining too short!"NL);
|
|
879 |
rl = 0;
|
|
880 |
}
|
|
881 |
else
|
|
882 |
{
|
|
883 |
switch (Desc->bDescriptorType)
|
|
884 |
{
|
|
885 |
case USB_CONFIGURATION_DESCRIPTOR_TYPE:
|
|
886 |
pConfigDescriptor =
|
|
887 |
(USB_CONFIGURATION_DESCRIPTOR*) data;
|
|
888 |
PRINT_IF_VERBOSE "\nCONFIGURATION DESCRIPTOR:"NL
|
|
889 |
"bLength = <%u>"NL
|
|
890 |
"bDescriptorType = <%u>"NL
|
|
891 |
"wTotalLength = <%u>"NL
|
|
892 |
"bNumInterfaces = <%u>"NL
|
|
893 |
"bConfigurationValue = <%u>"NL
|
|
894 |
"iConfiguration = <%u>"NL
|
|
895 |
"bmAttributes = <%u>"NL
|
|
896 |
"MaxPower = <%u>"NL,
|
|
897 |
pConfigDescriptor->bLength,
|
|
898 |
pConfigDescriptor->bDescriptorType,
|
|
899 |
pConfigDescriptor->wTotalLength,
|
|
900 |
pConfigDescriptor->bNumInterfaces,
|
|
901 |
pConfigDescriptor->bConfigurationValue,
|
|
902 |
pConfigDescriptor->iConfiguration,
|
|
903 |
pConfigDescriptor->bmAttributes,
|
|
904 |
pConfigDescriptor->MaxPower);
|
|
905 |
SetConfig.NbOfInterfaces = pConfigDescriptor->bNumInterfaces;
|
|
906 |
break;
|
|
907 |
|
|
908 |
case USB_INTERFACE_DESCRIPTOR_TYPE:
|
|
909 |
pInterfaceDescriptor = (USB_INTERFACE_DESCRIPTOR*) data;
|
|
910 |
interfaceNumber = pInterfaceDescriptor->bInterfaceNumber;
|
|
911 |
alternateSetting = pInterfaceDescriptor->bAlternateSetting;
|
|
912 |
endpointIndex = 0;
|
|
913 |
PRINT_IF_VERBOSE "\nINTERFACE DESCRIPTOR: "NL
|
|
914 |
"bLength = <%u>"NL
|
|
915 |
"bDescriptorType = <%u>"NL
|
|
916 |
"bInterfaceNumber = <%u>"NL
|
|
917 |
"bAlternateSetting = <%u>"NL
|
|
918 |
"bNumEndpoints = <%u>"NL
|
|
919 |
"bInterfaceClass = <%u>"NL
|
|
920 |
"bInterfaceSubClass = <%u>"NL
|
|
921 |
"bInterfaceProtocol = <%u>"NL
|
|
922 |
"iInterface = <%u>"NL,
|
|
923 |
pInterfaceDescriptor->bLength,
|
|
924 |
pInterfaceDescriptor->bDescriptorType,
|
|
925 |
pInterfaceDescriptor->bInterfaceNumber,
|
|
926 |
pInterfaceDescriptor->bAlternateSetting,
|
|
927 |
pInterfaceDescriptor->bNumEndpoints,
|
|
928 |
pInterfaceDescriptor->bInterfaceClass,
|
|
929 |
pInterfaceDescriptor->bInterfaceSubClass,
|
|
930 |
pInterfaceDescriptor->bInterfaceProtocol,
|
|
931 |
pInterfaceDescriptor->iInterface);
|
|
932 |
if (alternateSetting == 0)
|
|
933 |
{
|
|
934 |
SetConfig.InterfaceList[ifListIndex].InterfaceIndex = interfaceNumber;
|
|
935 |
SetConfig.InterfaceList[ifListIndex++].MaximumTransferSize = KMaxTransferSize;
|
|
936 |
}
|
|
937 |
break;
|
|
938 |
|
|
939 |
case USB_ENDPOINT_DESCRIPTOR_TYPE:
|
|
940 |
pEndpointDescriptor =
|
|
941 |
(USB_ENDPOINT_DESCRIPTOR*) data;
|
|
942 |
gEndpointMap[interfaceNumber] [alternateSetting] [endpointIndex] = pEndpointDescriptor->bEndpointAddress;
|
|
943 |
gPacketSizeMap[interfaceNumber] [alternateSetting] [endpointIndex++] = pEndpointDescriptor->wMaxPacketSize;
|
|
944 |
PRINT_IF_VERBOSE "\nENDPOINT DESCRIPTOR: "NL
|
|
945 |
"bLength = <%u>"NL
|
|
946 |
"bDescriptorType = <%u>"NL
|
|
947 |
"bEndpointAddress = <%X>"NL
|
|
948 |
"bmAttributes = <%u>"NL
|
|
949 |
"wMaxPacketSize = <%u>"NL
|
|
950 |
"bInterval = <%u>"NL,
|
|
951 |
pEndpointDescriptor->bLength,
|
|
952 |
pEndpointDescriptor->bDescriptorType,
|
|
953 |
pEndpointDescriptor->bEndpointAddress,
|
|
954 |
pEndpointDescriptor->bmAttributes,
|
|
955 |
pEndpointDescriptor->wMaxPacketSize,
|
|
956 |
pEndpointDescriptor->bInterval);
|
|
957 |
break;
|
|
958 |
default:
|
|
959 |
break;
|
|
960 |
}
|
|
961 |
}
|
|
962 |
data += ulDescLength;
|
|
963 |
rl -= ulDescLength;
|
|
964 |
}
|
|
965 |
}
|
|
966 |
|
|
967 |
dwRC = gUsbDev.SetConfiguration(&SetConfig);
|
|
968 |
PRINT_IF_VERBOSE "CUsbIo::SetConfiguration returned <0x%X>"NL, dwRC);
|
|
969 |
|
|
970 |
|
|
971 |
PRINT_IF_VERBOSE ""NL);
|
|
972 |
|
|
973 |
return dwRC;
|
|
974 |
}
|
|
975 |
|
|
976 |
|
|
977 |
static DWORD GetStringDescriptor()
|
|
978 |
{
|
|
979 |
DWORD dwRC;
|
|
980 |
|
|
981 |
CHAR szBuffer[MAX_DESCRIPTOR_BUFFER_SIZE] = "";
|
|
982 |
USB_STRING_DESCRIPTOR* pStringDescriptor = NULL;
|
|
983 |
DWORD dwByteCount = MAX_DESCRIPTOR_BUFFER_SIZE;
|
|
984 |
|
|
985 |
memset(szBuffer, 0, sizeof(szBuffer));
|
|
986 |
|
|
987 |
// Get string descriptor
|
|
988 |
dwRC = gUsbDev.GetStringDescriptor((USB_STRING_DESCRIPTOR*) szBuffer,
|
|
989 |
dwByteCount, 1, 0);
|
|
990 |
PRINT_IF_VERBOSE "CUsbIo::GetStringDescriptor returned <0x%X>"NL, dwRC);
|
|
991 |
|
|
992 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
993 |
{
|
|
994 |
pStringDescriptor = (USB_STRING_DESCRIPTOR*) szBuffer;
|
|
995 |
PRINT_IF_VERBOSE "\nSTRING DESCRIPTOR:"NL
|
|
996 |
"bLength = <%u>"NL
|
|
997 |
"bDescriptorType = <%u>"NL
|
|
998 |
"bString = <", // output continues below!
|
|
999 |
pStringDescriptor->bLength,
|
|
1000 |
pStringDescriptor->bDescriptorType);
|
|
1001 |
INT i = 0;
|
|
1002 |
CHAR* Ptr = szBuffer;
|
|
1003 |
for (i = 2, Ptr += 2;
|
|
1004 |
i < pStringDescriptor->bLength;
|
|
1005 |
i += 2, Ptr += 2)
|
|
1006 |
{
|
|
1007 |
PRINT_IF_VERBOSE "%c", *Ptr);
|
|
1008 |
}
|
|
1009 |
PRINT_IF_VERBOSE ">\n"NL);
|
|
1010 |
}
|
|
1011 |
|
|
1012 |
return dwRC;
|
|
1013 |
}
|
|
1014 |
|
|
1015 |
|
|
1016 |
static DWORD GetConfigurationInfo()
|
|
1017 |
{
|
|
1018 |
DWORD dwRC;
|
|
1019 |
|
|
1020 |
USBIO_CONFIGURATION_INFO ConfigInfo;
|
|
1021 |
USHORT i = 0;
|
|
1022 |
|
|
1023 |
memset(&ConfigInfo, 0, sizeof(USBIO_CONFIGURATION_INFO));
|
|
1024 |
|
|
1025 |
dwRC = gUsbDev.GetConfigurationInfo(&ConfigInfo);
|
|
1026 |
PRINT_IF_VERBOSE "CUsbIo::GetConfigurationInfo returned <0x%X>"NL, dwRC);
|
|
1027 |
|
|
1028 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
1029 |
{
|
|
1030 |
PRINT_IF_VERBOSE "\nCONFIGURATION INFO:"NL
|
|
1031 |
"NbOfInterfaces = <%lu>"NL
|
|
1032 |
"NbOfPipes = <%lu>"NL,
|
|
1033 |
ConfigInfo.NbOfInterfaces,
|
|
1034 |
ConfigInfo.NbOfPipes);
|
|
1035 |
for (i = 0; i < ConfigInfo.NbOfInterfaces; i++)
|
|
1036 |
{
|
|
1037 |
PRINT_IF_VERBOSE "\nINTERFACE <%u>:"NL, i + 1);
|
|
1038 |
PRINT_IF_VERBOSE "InterfaceNumber = <%u>"NL
|
|
1039 |
"AlternateSetting = <%u>"NL
|
|
1040 |
"Class = <%u>"NL
|
|
1041 |
"SubClass = <%u>"NL
|
|
1042 |
"Protocol = <%u>"NL
|
|
1043 |
"NumberOfPipes = <%u>"NL
|
|
1044 |
"reserved1 = <%u>"NL
|
|
1045 |
"reserved2 = <%u>"NL,
|
|
1046 |
ConfigInfo.InterfaceInfo[i].InterfaceNumber,
|
|
1047 |
ConfigInfo.InterfaceInfo[i].AlternateSetting,
|
|
1048 |
ConfigInfo.InterfaceInfo[i].Class,
|
|
1049 |
ConfigInfo.InterfaceInfo[i].SubClass,
|
|
1050 |
ConfigInfo.InterfaceInfo[i].Protocol,
|
|
1051 |
ConfigInfo.InterfaceInfo[i].NumberOfPipes,
|
|
1052 |
ConfigInfo.InterfaceInfo[i].reserved1,
|
|
1053 |
ConfigInfo.InterfaceInfo[i].reserved2);
|
|
1054 |
}
|
|
1055 |
for (i = 0; i < ConfigInfo.NbOfPipes; i++)
|
|
1056 |
{
|
|
1057 |
PRINT_IF_VERBOSE ""NL);
|
|
1058 |
PRINT_IF_VERBOSE "PIPE <%u>"NL, i + 1);
|
|
1059 |
PRINT_IF_VERBOSE "PipeType = <%d>"NL
|
|
1060 |
"MaximumTransferSize = <%lu>"NL
|
|
1061 |
"MaximumPacketSize = <%u>"NL
|
|
1062 |
"EndpointAddress = <%X>"NL
|
|
1063 |
"Interval = <%u>"NL
|
|
1064 |
"InterfaceNumber = <%u>"NL
|
|
1065 |
"reserved1 = <%u>"NL
|
|
1066 |
"reserved2 = <%u>"NL
|
|
1067 |
"reserved3 = <%u>"NL,
|
|
1068 |
ConfigInfo.PipeInfo[i].PipeType,
|
|
1069 |
ConfigInfo.PipeInfo[i].MaximumTransferSize,
|
|
1070 |
ConfigInfo.PipeInfo[i].MaximumPacketSize,
|
|
1071 |
ConfigInfo.PipeInfo[i].EndpointAddress,
|
|
1072 |
ConfigInfo.PipeInfo[i].Interval,
|
|
1073 |
ConfigInfo.PipeInfo[i].InterfaceNumber,
|
|
1074 |
ConfigInfo.PipeInfo[i].reserved1,
|
|
1075 |
ConfigInfo.PipeInfo[i].reserved2,
|
|
1076 |
ConfigInfo.PipeInfo[i].reserved3);
|
|
1077 |
}
|
|
1078 |
}
|
|
1079 |
PRINT_IF_VERBOSE ""NL);
|
|
1080 |
|
|
1081 |
return dwRC;
|
|
1082 |
}
|
|
1083 |
|
|
1084 |
|
|
1085 |
static DWORD OpenPipes(CUsbIoPipe * inPipePtr, CUsbIoPipe * outPipePtr, TestParamPtr tpPtr)
|
|
1086 |
{
|
|
1087 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
1088 |
UCHAR epAddress;
|
|
1089 |
|
|
1090 |
// Create the bulk OUT pipe
|
|
1091 |
if (outPipePtr)
|
|
1092 |
{
|
|
1093 |
epAddress = gEndpointMap[tpPtr->interfaceNumber][tpPtr->alternateSetting][tpPtr->outPipe-1];
|
|
1094 |
dwRC = outPipePtr->Bind(gDevNumber, epAddress, gDevList, &gUsbioID);
|
|
1095 |
|
|
1096 |
PRINT_IF_VERBOSE "CUsbIoPipe::Bind OUT address <0x%X> returned <0x%X>"NL, epAddress,dwRC);
|
|
1097 |
|
|
1098 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
1099 |
{
|
|
1100 |
// Set up for time statistics on OUT pipe
|
|
1101 |
dwRC = outPipePtr->SetupPipeStatistics(1000L);
|
|
1102 |
PRINT_IF_VERBOSE "CUsbIoPipe::SetupPipeStatistics OUT returned <0x%X>"NL, dwRC);
|
|
1103 |
}
|
|
1104 |
else
|
|
1105 |
ShowErrorText(dwRC);
|
|
1106 |
}
|
|
1107 |
|
|
1108 |
if (inPipePtr && dwRC == USBIO_ERR_SUCCESS)
|
|
1109 |
{
|
|
1110 |
// Create the IN pipe
|
|
1111 |
epAddress = gEndpointMap[tpPtr->interfaceNumber][tpPtr->alternateSetting][tpPtr->inPipe-1];
|
|
1112 |
dwRC = inPipePtr->Bind(gDevNumber, epAddress, gDevList, &gUsbioID);
|
|
1113 |
|
|
1114 |
PRINT_IF_VERBOSE "CUsbIoPipe::Bind IN address <0x%X> returned <0x%X>"NL, epAddress,dwRC);
|
|
1115 |
|
|
1116 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
1117 |
{
|
|
1118 |
// Set up for time statistics on IN pipe
|
|
1119 |
dwRC = inPipePtr->SetupPipeStatistics(1000L);
|
|
1120 |
PRINT_IF_VERBOSE "CUsbIoPipe::SetupPipeStatistics IN returned <0x%X>"NL, dwRC);
|
|
1121 |
}
|
|
1122 |
else
|
|
1123 |
ShowErrorText(dwRC);
|
|
1124 |
|
|
1125 |
}
|
|
1126 |
|
|
1127 |
PRINT_IF_VERBOSE ""NL);
|
|
1128 |
|
|
1129 |
return dwRC;
|
|
1130 |
}
|
|
1131 |
|
|
1132 |
|
|
1133 |
static DWORD ClosePipes(CUsbIoPipe * inPipePtr, CUsbIoPipe * outPipePtr)
|
|
1134 |
{
|
|
1135 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
1136 |
|
|
1137 |
// Close down the OUT pipe
|
|
1138 |
if (outPipePtr)
|
|
1139 |
{
|
|
1140 |
dwRC = outPipePtr->Unbind();
|
|
1141 |
PRINT_IF_VERBOSE "CUsbIoPipe::Unbind OUT returned <0x%X>"NL, dwRC);
|
|
1142 |
}
|
|
1143 |
|
|
1144 |
if (inPipePtr && dwRC == USBIO_ERR_SUCCESS)
|
|
1145 |
{
|
|
1146 |
// Close down the IN pipe
|
|
1147 |
dwRC = inPipePtr->Unbind();
|
|
1148 |
PRINT_IF_VERBOSE "CUsbIoPipe::Unbind IN returned <0x%X>"NL, dwRC);
|
|
1149 |
}
|
|
1150 |
|
|
1151 |
return dwRC;
|
|
1152 |
}
|
|
1153 |
|
|
1154 |
static void SendLogFile()
|
|
1155 |
{
|
|
1156 |
logStream = fopen (gLogfileName, "rb");
|
|
1157 |
if (logStream == NULL)
|
|
1158 |
{
|
|
1159 |
return;
|
|
1160 |
}
|
|
1161 |
|
|
1162 |
char logBuffer[KHostLogFileSize];
|
|
1163 |
CUsbIoPipe* outPipePtr = new CUsbIoPipe();
|
|
1164 |
CUsbIoBuf bufPtr((VOID*) logBuffer, KHostLogFileSize); // the data buffer
|
|
1165 |
int bytesRead;
|
|
1166 |
|
|
1167 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
1168 |
UCHAR epAddress;
|
|
1169 |
|
|
1170 |
// Create the bulk OUT pipe
|
|
1171 |
epAddress = gEndpointMap[0][0][1];
|
|
1172 |
dwRC = outPipePtr->Bind(gDevNumber, epAddress, gDevList, &gUsbioID);
|
|
1173 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
1174 |
{
|
|
1175 |
return;
|
|
1176 |
}
|
|
1177 |
|
|
1178 |
bytesRead = fread ( logBuffer, sizeof(char), KHostLogFileSize, logStream );
|
|
1179 |
if (bytesRead > 0)
|
|
1180 |
{
|
|
1181 |
bufPtr.NumberOfBytesToTransfer = bytesRead;
|
|
1182 |
outPipePtr->Write(&bufPtr);
|
|
1183 |
dwRC = outPipePtr->WaitForCompletion(&bufPtr, gReadWriteTimeOut);
|
|
1184 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
1185 |
{
|
|
1186 |
return;
|
|
1187 |
}
|
|
1188 |
}
|
|
1189 |
|
|
1190 |
|
|
1191 |
bufPtr.NumberOfBytesToTransfer = 0;
|
|
1192 |
outPipePtr->Write(&bufPtr);
|
|
1193 |
dwRC = outPipePtr->WaitForCompletion(&bufPtr, gReadWriteTimeOut);
|
|
1194 |
|
|
1195 |
return;
|
|
1196 |
}
|
|
1197 |
|
|
1198 |
static DWORD ReceiveCounter()
|
|
1199 |
{
|
|
1200 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
1201 |
|
|
1202 |
DWORD bytes_read = sizeof(__int64);
|
|
1203 |
|
|
1204 |
// Here we (hope to) read an 8 byte packet containing a counter value.
|
|
1205 |
PRINT_NOLOG "* Waiting for T_USB counter packet to arrive...");
|
|
1206 |
|
|
1207 |
__int64 counter;
|
|
1208 |
|
|
1209 |
USBIO_CLASS_OR_VENDOR_REQUEST request;
|
|
1210 |
request.Flags = USBIO_SHORT_TRANSFER_OK;
|
|
1211 |
request.Type = RequestTypeClass;
|
|
1212 |
request.Recipient = RecipientDevice;
|
|
1213 |
request.RequestTypeReservedBits = 0;
|
|
1214 |
request.Request = ETestIdleCounter;
|
|
1215 |
request.Value = gDeviceIdleCount < 0 ? 0 : 1;
|
|
1216 |
request.Index = 0;
|
|
1217 |
|
|
1218 |
|
|
1219 |
dwRC = gUsbDev.ClassOrVendorInRequest(&counter,bytes_read,&request);
|
|
1220 |
|
|
1221 |
PRINT_NOLOG " done."NL);
|
|
1222 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
1223 |
{
|
|
1224 |
PRINT_ALWAYS "\n* Error: CUsbIoPipe::Read (version)");
|
|
1225 |
ShowErrorText(dwRC);
|
|
1226 |
return dwRC;
|
|
1227 |
}
|
|
1228 |
|
|
1229 |
if (gDeviceIdleCount < 0)
|
|
1230 |
{
|
|
1231 |
// Initialise counter
|
|
1232 |
gDeviceIdleCount = counter;
|
|
1233 |
_ftime(&gHostTime);
|
|
1234 |
PRINT_TIME " * Start Device Idle Counter"NL);
|
|
1235 |
}
|
|
1236 |
else
|
|
1237 |
{
|
|
1238 |
// if the counter is zero then the tests havent completed on the device
|
|
1239 |
while (counter < gDeviceIdleCount)
|
|
1240 |
{
|
|
1241 |
Delay(WAIT_TEST_COMPLETE);
|
|
1242 |
dwRC = gUsbDev.ClassOrVendorInRequest(&counter,bytes_read,&request);
|
|
1243 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
1244 |
{
|
|
1245 |
PRINT_ALWAYS "\n* Error: CUsbIoPipe::Read (version)");
|
|
1246 |
ShowErrorText(dwRC);
|
|
1247 |
return dwRC;
|
|
1248 |
}
|
|
1249 |
}
|
|
1250 |
__int64 diff = counter - gDeviceIdleCount;
|
|
1251 |
struct _timeb tmp = gHostTime;
|
|
1252 |
_ftime(&gHostTime);
|
|
1253 |
gDeviceIdleCount = counter;
|
|
1254 |
int ms = (gHostTime.time - tmp.time) * 1000 + gHostTime.millitm - tmp.millitm;
|
|
1255 |
PRINT_TIME " * Stop Device Idle Counter: %I64d increments in %dms (%dinc/ms)"NL,
|
|
1256 |
diff, ms, diff / ms);
|
|
1257 |
}
|
|
1258 |
|
|
1259 |
return dwRC;
|
|
1260 |
}
|
|
1261 |
|
|
1262 |
static DWORD ReceiveVersion()
|
|
1263 |
{
|
|
1264 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
1265 |
|
|
1266 |
// Here we (hope to) read an 8 byte packet containing the T_USB version.
|
|
1267 |
PRINT_NOLOG "* Waiting for T_USB version packet to arrive...");
|
|
1268 |
|
|
1269 |
BYTE versionData[VERSION_DATAIN_SIZE];
|
|
1270 |
|
|
1271 |
// The first 3 bytes are interpreted as a version.
|
|
1272 |
DWORD bytes_read = VERSION_DATAIN_SIZE;
|
|
1273 |
|
|
1274 |
USBIO_CLASS_OR_VENDOR_REQUEST request;
|
|
1275 |
request.Flags = USBIO_SHORT_TRANSFER_OK;
|
|
1276 |
request.Type = RequestTypeClass;
|
|
1277 |
request.Recipient = RecipientDevice;
|
|
1278 |
request.RequestTypeReservedBits = 0;
|
|
1279 |
request.Request = EVersion;
|
|
1280 |
request.Value = 0;
|
|
1281 |
request.Index = 0;
|
|
1282 |
|
|
1283 |
|
|
1284 |
dwRC = gUsbDev.ClassOrVendorInRequest(&versionData[0],bytes_read,&request);
|
|
1285 |
|
|
1286 |
PRINT_NOLOG " done."NL);
|
|
1287 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
1288 |
{
|
|
1289 |
PRINT_ALWAYS "\n* Error: CUsbIoPipe::Read (version)");
|
|
1290 |
ShowErrorText(dwRC);
|
|
1291 |
return dwRC;
|
|
1292 |
}
|
|
1293 |
if (versionData[0] < KTusbVersionMajor ||
|
|
1294 |
(versionData[0] == KTusbVersionMajor && versionData[1] < KTusbVersionMinor) ||
|
|
1295 |
(versionData[0] == KTusbVersionMajor && versionData[1] == KTusbVersionMinor && versionData[2] < KTusbVersionMicro))
|
|
1296 |
{
|
|
1297 |
PRINT_ALWAYS "* Inadequate version of T_USB: %d.%d.%d (we need at least %d.%d.%d)"NL,
|
|
1298 |
versionData[0],versionData[1],versionData[2],KTusbVersionMajor,KTusbVersionMinor,KTusbVersionMicro);
|
|
1299 |
dwRC = USBIO_ERR_FAILED;
|
|
1300 |
return dwRC;
|
|
1301 |
}
|
|
1302 |
PRINT_NOLOG "* Suitable version of T_USB_DEVICE found: %d.%d.%d."NL, versionData[0],versionData[1],versionData[2]);
|
|
1303 |
|
|
1304 |
char * scriptFilePtr;
|
|
1305 |
scriptFilePtr = strstr((char *)&versionData[3],"/script=");
|
|
1306 |
|
|
1307 |
if (scriptFilePtr != NULL)
|
|
1308 |
{
|
|
1309 |
* scriptFilePtr = '\0';
|
|
1310 |
scriptFilePtr += 8;
|
|
1311 |
PRINT_ALWAYS "Script file name %s"NL,scriptFilePtr);
|
|
1312 |
if (strstr(gScriptFileName,scriptFilePtr) == NULL)
|
|
1313 |
{
|
|
1314 |
dwRC = ERR_SCRIPT_NAME;
|
|
1315 |
}
|
|
1316 |
}
|
|
1317 |
|
|
1318 |
PRINT_ALWAYS "Device configuration file %s"NL,&versionData[3]);
|
|
1319 |
|
|
1320 |
return dwRC;
|
|
1321 |
}
|
|
1322 |
|
|
1323 |
|
|
1324 |
static DWORD SendVersion()
|
|
1325 |
{
|
|
1326 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
1327 |
|
|
1328 |
// Here we send an 8 byte packet containing T_USB_WIN's + USBIO's versions.
|
|
1329 |
PRINT_NOLOG "* Sending our version packet to T_USB...");
|
|
1330 |
|
|
1331 |
BYTE versionData[VERSION_DATAOUT_SIZE];
|
|
1332 |
versionData[0] = VERSION_MAJOR;
|
|
1333 |
versionData[1] = VERSION_MINOR;
|
|
1334 |
versionData[2] = VERSION_MICRO;
|
|
1335 |
versionData[3] = USBIO_VERSION_MAJOR;
|
|
1336 |
versionData[4] = USBIO_VERSION_MINOR;
|
|
1337 |
|
|
1338 |
USBIO_CLASS_OR_VENDOR_REQUEST request;
|
|
1339 |
request.Flags = USBIO_SHORT_TRANSFER_OK;
|
|
1340 |
request.Type = RequestTypeClass;
|
|
1341 |
request.Recipient = RecipientDevice;
|
|
1342 |
request.RequestTypeReservedBits = 0;
|
|
1343 |
request.Request = EVersion;
|
|
1344 |
request.Value = 0;
|
|
1345 |
request.Index = 0;
|
|
1346 |
|
|
1347 |
DWORD data_bytes = VERSION_DATAOUT_SIZE;
|
|
1348 |
dwRC = gUsbDev.ClassOrVendorOutRequest(&versionData[0],data_bytes,&request);
|
|
1349 |
PRINT_NOLOG " done."NL);
|
|
1350 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
1351 |
{
|
|
1352 |
PRINT_ALWAYS "\n* Error: CUsbIoPipe::Write (version)");
|
|
1353 |
ShowErrorText(dwRC);
|
|
1354 |
}
|
|
1355 |
|
|
1356 |
return dwRC;
|
|
1357 |
}
|
|
1358 |
|
|
1359 |
|
|
1360 |
static DWORD ExchangeVersions()
|
|
1361 |
{
|
|
1362 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
1363 |
|
|
1364 |
|
|
1365 |
dwRC = SendVersion();
|
|
1366 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
1367 |
return dwRC;
|
|
1368 |
dwRC = ReceiveVersion();
|
|
1369 |
|
|
1370 |
return dwRC;
|
|
1371 |
}
|
|
1372 |
|
|
1373 |
|
|
1374 |
static DWORD ChangeInterfaceSetting(BYTE aInterfaceNumber, BYTE aAlternateSetting)
|
|
1375 |
{
|
|
1376 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
1377 |
|
|
1378 |
if (gAlternateSettings[aInterfaceNumber] != aAlternateSetting)
|
|
1379 |
{
|
|
1380 |
gAlternateSettings[aInterfaceNumber] = aAlternateSetting;
|
|
1381 |
USBIO_INTERFACE_SETTING ifSetting = {aInterfaceNumber,aAlternateSetting,4096};
|
|
1382 |
dwRC = gUsbDev.SetInterface(&ifSetting);
|
|
1383 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
1384 |
{
|
|
1385 |
PRINT_NOLOG "Set Interface %d to Alternate Setting %d"NL,aInterfaceNumber,aAlternateSetting);
|
|
1386 |
}
|
|
1387 |
else
|
|
1388 |
{
|
|
1389 |
PRINT_ALWAYS "\n* Error: Setting Interface %d Alternate Setting %d",aInterfaceNumber,aAlternateSetting);
|
|
1390 |
ShowErrorText(dwRC);
|
|
1391 |
}
|
|
1392 |
}
|
|
1393 |
|
|
1394 |
return dwRC;
|
|
1395 |
}
|
|
1396 |
|
|
1397 |
static DWORD ReadData(CUsbIoPipe * inPipePtr,CUsbIoBuf* bufPtr, TestParamPtr tpPtr)
|
|
1398 |
{
|
|
1399 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
1400 |
UCHAR epAddress = gEndpointMap[tpPtr->interfaceNumber][tpPtr->alternateSetting][tpPtr->inPipe-1];
|
|
1401 |
|
|
1402 |
// We have to setup a read for at least one byte in order to get
|
|
1403 |
// the host to issue IN tokens for our zero-byte read:
|
|
1404 |
inPipePtr->Read(bufPtr);
|
|
1405 |
dwRC = inPipePtr->WaitForCompletion(bufPtr, gReadWriteTimeOut);
|
|
1406 |
|
|
1407 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
1408 |
{
|
|
1409 |
PRINT_ALWAYS "\n* Error: EP Number %d Address <0x%X> CUsbIoPipe::Read %d bytes",tpPtr->inPipe,epAddress, bufPtr->NumberOfBytesToTransfer);
|
|
1410 |
ShowErrorText(dwRC);
|
|
1411 |
}
|
|
1412 |
else
|
|
1413 |
{
|
|
1414 |
if (bufPtr->BytesTransferred != bufPtr->NumberOfBytesToTransfer)
|
|
1415 |
{
|
|
1416 |
DWORD pktNum = *(DWORD *)bufPtr->Buffer();
|
|
1417 |
PRINT_ALWAYS "* EP Address <0x%X> Read more/less bytes (%d) than expected (%d) packet number 0x%x"NL,
|
|
1418 |
epAddress, bufPtr->BytesTransferred,bufPtr->NumberOfBytesToTransfer,pktNum);
|
|
1419 |
dwRC = USBIO_ERR_FAILED;
|
|
1420 |
}
|
|
1421 |
else
|
|
1422 |
{
|
|
1423 |
PRINT_IF_VERBOSE "* EP Address <0x%X> Read %d bytes."NL, epAddress,bufPtr->BytesTransferred);
|
|
1424 |
}
|
|
1425 |
}
|
|
1426 |
|
|
1427 |
return dwRC;
|
|
1428 |
}
|
|
1429 |
|
|
1430 |
|
|
1431 |
static DWORD WriteData(CUsbIoPipe * outPipePtr,CUsbIoBuf* bufPtr, TestParamPtr tpPtr)
|
|
1432 |
{
|
|
1433 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
1434 |
UCHAR epAddress = gEndpointMap[tpPtr->interfaceNumber][tpPtr->alternateSetting][tpPtr->outPipe-1];
|
|
1435 |
|
|
1436 |
outPipePtr->Write(bufPtr);
|
|
1437 |
dwRC = outPipePtr->WaitForCompletion(bufPtr, gReadWriteTimeOut);
|
|
1438 |
|
|
1439 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
1440 |
{
|
|
1441 |
PRINT_IF_VERBOSE "* EP Address <0x%X> Wrote %d bytes."NL, epAddress, bufPtr->BytesTransferred);
|
|
1442 |
}
|
|
1443 |
else
|
|
1444 |
{
|
|
1445 |
PRINT_ALWAYS "\n* Error: EP Number %d Address <0x%X> CUsbIoPipe::Write %d bytes",tpPtr->outPipe,epAddress, bufPtr->NumberOfBytesToTransfer);
|
|
1446 |
ShowErrorText(dwRC);
|
|
1447 |
}
|
|
1448 |
|
|
1449 |
return dwRC;
|
|
1450 |
}
|
|
1451 |
|
|
1452 |
|
|
1453 |
static DWORD CheckAndPrintStats(CUsbIoPipe * inPipePtr, CUsbIoPipe * outPipePtr, BYTE testIndex, DWORD loopCount, DWORD * averageInRate, DWORD * averageOutRate, DWORD inRate = 0, DWORD outRate = 0)
|
|
1454 |
{
|
|
1455 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
1456 |
USBIO_PIPE_STATISTICS pipeStats;
|
|
1457 |
|
|
1458 |
PRINT_NOLOG "*** Test Index %d Iteration %d ***"NL,testIndex,loopCount);
|
|
1459 |
if (outPipePtr)
|
|
1460 |
{
|
|
1461 |
dwRC = outPipePtr->QueryPipeStatistics (&pipeStats);
|
|
1462 |
|
|
1463 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
1464 |
{
|
|
1465 |
__int64 byteCount = (((__int64)pipeStats.BytesTransferred_H)<<32) + pipeStats.BytesTransferred_L;
|
|
1466 |
PRINT_NOLOG "OUT %I64u bytes Succeeded %lu Failed %lu Rate %lu bytes/sec."NL,
|
|
1467 |
byteCount,pipeStats.RequestsSucceeded,pipeStats.RequestsFailed,pipeStats.AverageRate);
|
|
1468 |
|
|
1469 |
if (pipeStats.RequestsFailed)
|
|
1470 |
{
|
|
1471 |
PRINT_ALWAYS "%d OUT Requests Failed"NL,pipeStats.RequestsFailed);
|
|
1472 |
dwRC = USBIO_ERR_FAILED;
|
|
1473 |
}
|
|
1474 |
* averageOutRate = pipeStats.AverageRate;
|
|
1475 |
if (pipeStats.AverageRate < outRate)
|
|
1476 |
{
|
|
1477 |
PRINT_ALWAYS "Failure Average OUT Rate %lu < Minimum Rate %lu"NL,pipeStats.AverageRate,outRate);
|
|
1478 |
dwRC = USBIO_ERR_FAILED;
|
|
1479 |
}
|
|
1480 |
}
|
|
1481 |
else
|
|
1482 |
{
|
|
1483 |
PRINT_ALWAYS "\n* Error: CUsbIoPipe::Query OUT Pipe Statistics");
|
|
1484 |
ShowErrorText(dwRC);
|
|
1485 |
}
|
|
1486 |
|
|
1487 |
}
|
|
1488 |
|
|
1489 |
if (inPipePtr && dwRC == USBIO_ERR_SUCCESS)
|
|
1490 |
{
|
|
1491 |
dwRC = inPipePtr->QueryPipeStatistics (&pipeStats);
|
|
1492 |
|
|
1493 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
1494 |
{
|
|
1495 |
__int64 byteCount = (((__int64)pipeStats.BytesTransferred_H)<<32) + pipeStats.BytesTransferred_L;
|
|
1496 |
PRINT_NOLOG "IN %I64u bytes Succeeded %lu Failed %lu Rate %lu bytes/sec."NL,
|
|
1497 |
byteCount,pipeStats.RequestsSucceeded,pipeStats.RequestsFailed,pipeStats.AverageRate);
|
|
1498 |
|
|
1499 |
if (pipeStats.RequestsFailed)
|
|
1500 |
{
|
|
1501 |
PRINT_ALWAYS "%d IN Requests Failed"NL,pipeStats.RequestsFailed);
|
|
1502 |
dwRC = USBIO_ERR_FAILED;
|
|
1503 |
}
|
|
1504 |
* averageInRate = pipeStats.AverageRate;
|
|
1505 |
if (pipeStats.AverageRate < inRate)
|
|
1506 |
{
|
|
1507 |
PRINT_ALWAYS "Failure Average IN Rate %lu < Minimum Rate %lu"NL,pipeStats.AverageRate,inRate);
|
|
1508 |
dwRC = USBIO_ERR_FAILED;
|
|
1509 |
}
|
|
1510 |
|
|
1511 |
}
|
|
1512 |
else
|
|
1513 |
{
|
|
1514 |
PRINT_ALWAYS "\n* Error: CUsbIoPipe::Query IN Pipe Statistics");
|
|
1515 |
ShowErrorText(dwRC);
|
|
1516 |
}
|
|
1517 |
}
|
|
1518 |
|
|
1519 |
return dwRC;
|
|
1520 |
}
|
|
1521 |
|
|
1522 |
|
|
1523 |
UINT LoopTransfer( LPVOID pParam )
|
|
1524 |
{
|
|
1525 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
1526 |
|
|
1527 |
TestParamType testParams = *(TestParamPtr)pParam;
|
|
1528 |
|
|
1529 |
PRINT_NOLOG "* Thread %d Loop Transfers -- reading & writing alternately."NL,testParams.host.index);
|
|
1530 |
|
|
1531 |
ResetEvent (gThreadEndedEvents[testParams.host.index]);
|
|
1532 |
SetEvent (gThreadStartedEvent);
|
|
1533 |
|
|
1534 |
CUsbIoPipe* inPipePtr = new CUsbIoPipe();
|
|
1535 |
CUsbIoPipe* outPipePtr = new CUsbIoPipe();
|
|
1536 |
|
|
1537 |
BYTE* DataPtr = new BYTE[testParams.maxSize];
|
|
1538 |
CUsbIoBuf buf((VOID*) DataPtr, testParams.maxSize); // the data buffer
|
|
1539 |
|
|
1540 |
BYTE* WaitSettingDataPtr = new BYTE[WAIT_SETTING_BUFFER_SIZE];
|
|
1541 |
CUsbIoBuf bufWaitSetting((VOID*) WaitSettingDataPtr, WAIT_SETTING_BUFFER_SIZE); // another data buffer
|
|
1542 |
bufWaitSetting.NumberOfBytesToTransfer = WAIT_SETTING_BUFFER_SIZE;
|
|
1543 |
|
|
1544 |
if (!testParams.settingRepeat)
|
|
1545 |
{
|
|
1546 |
OpenPipes (inPipePtr,outPipePtr,&testParams);
|
|
1547 |
}
|
|
1548 |
|
|
1549 |
DWORD averageInRate;
|
|
1550 |
DWORD averageOutRate;
|
|
1551 |
int repeatCount = 0;
|
|
1552 |
buf.NumberOfBytesToTransfer = testParams.minSize;
|
|
1553 |
while ((dwRC == USBIO_ERR_SUCCESS) && !gFinishAllTests && !gAbort && (!testParams.repeat || repeatCount < testParams.repeat))
|
|
1554 |
{
|
|
1555 |
if (testParams.settingRepeat)
|
|
1556 |
{
|
|
1557 |
if ((repeatCount % testParams.settingRepeat) == 0)
|
|
1558 |
{
|
|
1559 |
if (repeatCount)
|
|
1560 |
{
|
|
1561 |
// Wait for this extra read to ensure that ok to change interface setting
|
|
1562 |
inPipePtr->Read(&bufWaitSetting);
|
|
1563 |
dwRC = inPipePtr->WaitForCompletion(&bufWaitSetting, WAIT_SETTING_TIMEOUT);
|
|
1564 |
// Not necessary if different interfaces used as setting interface closes pipes,
|
|
1565 |
// but if the same interface is used then prevents errors when opening pipes
|
|
1566 |
ClosePipes (inPipePtr,outPipePtr);
|
|
1567 |
PRINT_IF_VERBOSE "Signal for thread %d"NL,testParams.host.index);
|
|
1568 |
SetEvent (gThreadWaitEvents[testParams.host.index]);
|
|
1569 |
}
|
|
1570 |
|
|
1571 |
PRINT_IF_VERBOSE "Wait for thread %d"NL,testParams.beforeIndex);
|
|
1572 |
dwRC = WaitForSingleObject (gThreadWaitEvents[testParams.beforeIndex],WAIT_BEFORETHREAD_TIMEOUT);
|
|
1573 |
if (dwRC != WAIT_OBJECT_0)
|
|
1574 |
{
|
|
1575 |
PRINT_ALWAYS "Error waiting for alternate setting before thread"NL);
|
|
1576 |
return 0;
|
|
1577 |
}
|
|
1578 |
dwRC = ChangeInterfaceSetting (testParams.interfaceNumber,testParams.alternateSetting);
|
|
1579 |
OpenPipes (inPipePtr,outPipePtr,&testParams);
|
|
1580 |
}
|
|
1581 |
}
|
|
1582 |
|
|
1583 |
dwRC = ReadData(inPipePtr,&buf,&testParams);
|
|
1584 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
1585 |
{
|
|
1586 |
// Now we send the received data back to the client.
|
|
1587 |
dwRC = WriteData(outPipePtr,&buf,&testParams);
|
|
1588 |
}
|
|
1589 |
|
|
1590 |
repeatCount++;
|
|
1591 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
1592 |
{
|
|
1593 |
if (repeatCount == testParams.repeat)
|
|
1594 |
{
|
|
1595 |
dwRC = CheckAndPrintStats(inPipePtr,outPipePtr,testParams.host.index,repeatCount,&averageInRate,&averageOutRate,testParams.host.inRate,testParams.host.outRate);
|
|
1596 |
}
|
|
1597 |
else
|
|
1598 |
{
|
|
1599 |
if (testParams.host.displayRate && (repeatCount % testParams.host.displayRate) == 0)
|
|
1600 |
{
|
|
1601 |
dwRC = CheckAndPrintStats(inPipePtr,outPipePtr,testParams.host.index,repeatCount,&averageInRate,&averageOutRate);
|
|
1602 |
}
|
|
1603 |
}
|
|
1604 |
}
|
|
1605 |
|
|
1606 |
if (buf.NumberOfBytesToTransfer == testParams.maxSize)
|
|
1607 |
{
|
|
1608 |
buf.NumberOfBytesToTransfer = testParams.minSize;
|
|
1609 |
}
|
|
1610 |
else
|
|
1611 |
{
|
|
1612 |
buf.NumberOfBytesToTransfer++;
|
|
1613 |
}
|
|
1614 |
}
|
|
1615 |
|
|
1616 |
|
|
1617 |
Delay (WAIT_TEST_COMPLETE);
|
|
1618 |
USBIO_CLASS_OR_VENDOR_REQUEST request;
|
|
1619 |
request.Flags = USBIO_SHORT_TRANSFER_OK;
|
|
1620 |
request.Type = RequestTypeClass;
|
|
1621 |
request.Recipient = RecipientDevice;
|
|
1622 |
request.RequestTypeReservedBits = 0;
|
|
1623 |
request.Request = ETestResult;
|
|
1624 |
request.Index = testParams.host.index;
|
|
1625 |
request.Value = (dwRC == USBIO_ERR_SUCCESS) ? true : false;
|
|
1626 |
DWORD dataBytes = 0;
|
|
1627 |
dwRC = gUsbDev.ClassOrVendorOutRequest(NULL,dataBytes,&request);
|
|
1628 |
|
|
1629 |
PRINT_TIME "Test Index %d IN rate %lu OUT rate %lu Loop %s ",testParams.host.index,averageInRate,averageOutRate,request.Value ? "Passed" : "Failed");
|
|
1630 |
|
|
1631 |
dwRC = ClosePipes (inPipePtr,outPipePtr);
|
|
1632 |
delete DataPtr;
|
|
1633 |
delete inPipePtr;
|
|
1634 |
delete outPipePtr;
|
|
1635 |
|
|
1636 |
if (request.Value)
|
|
1637 |
{
|
|
1638 |
if (testParams.host.signalNextSettingThread)
|
|
1639 |
{
|
|
1640 |
PRINT_IF_VERBOSE "Signal for thread %d"NL,testParams.host.index);
|
|
1641 |
SetEvent (gThreadWaitEvents[testParams.host.index]);
|
|
1642 |
}
|
|
1643 |
}
|
|
1644 |
else
|
|
1645 |
{
|
|
1646 |
gAbort = true;
|
|
1647 |
}
|
|
1648 |
|
|
1649 |
SetEvent (gThreadEndedEvents[testParams.host.index]);
|
|
1650 |
|
|
1651 |
return 0;
|
|
1652 |
}
|
|
1653 |
|
|
1654 |
|
|
1655 |
UINT ReceiveOnlyTransfer(LPVOID pParam)
|
|
1656 |
{
|
|
1657 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
1658 |
BYTE* DataPtr; // the read/write buffer
|
|
1659 |
|
|
1660 |
TestParamType testParams = *(TestParamPtr)pParam;
|
|
1661 |
|
|
1662 |
PRINT_NOLOG "* Receive-only transfers (IN)."NL);
|
|
1663 |
|
|
1664 |
ResetEvent (gThreadEndedEvents[testParams.host.index]);
|
|
1665 |
SetEvent (gThreadStartedEvent);
|
|
1666 |
|
|
1667 |
CUsbIoPipe * inPipePtr = new CUsbIoPipe();
|
|
1668 |
|
|
1669 |
DataPtr = new BYTE[testParams.maxSize];
|
|
1670 |
CUsbIoBuf buf((VOID*) DataPtr, testParams.maxSize); // the data buffer
|
|
1671 |
|
|
1672 |
if (!testParams.settingRepeat)
|
|
1673 |
{
|
|
1674 |
OpenPipes (inPipePtr,NULL,&testParams);
|
|
1675 |
}
|
|
1676 |
|
|
1677 |
buf.NumberOfBytesToTransfer = testParams.maxSize;
|
|
1678 |
DWORD averageInRate;
|
|
1679 |
DWORD averageOutRate;
|
|
1680 |
int repeatCount = 0;
|
|
1681 |
DWORD expected = testParams.packetNumber;
|
|
1682 |
DWORD pktNum = 0;
|
|
1683 |
int saveTimeout = gReadWriteTimeOut;
|
|
1684 |
gReadWriteTimeOut = FIRSTFILEREAD_TIMEOUT;
|
|
1685 |
while ((dwRC == USBIO_ERR_SUCCESS) && !gFinishAllTests && !gAbort && (!testParams.repeat || repeatCount < testParams.repeat))
|
|
1686 |
{
|
|
1687 |
if (testParams.settingRepeat)
|
|
1688 |
{
|
|
1689 |
if ((repeatCount % testParams.settingRepeat) == 0)
|
|
1690 |
{
|
|
1691 |
if (repeatCount)
|
|
1692 |
{
|
|
1693 |
// Wait to ensure that ok to change interface setting
|
|
1694 |
Delay (WAIT_SETTING_DELAY);
|
|
1695 |
// Not necessary if different interfaces used as setting interface closes pipes,
|
|
1696 |
// but if the same interface is used then prevents errors when opening pipes
|
|
1697 |
ClosePipes (inPipePtr,NULL);
|
|
1698 |
PRINT_IF_VERBOSE "Signal for thread %d"NL,testParams.host.index);
|
|
1699 |
SetEvent (gThreadWaitEvents[testParams.host.index]);
|
|
1700 |
}
|
|
1701 |
|
|
1702 |
PRINT_IF_VERBOSE "Wait for thread %d"NL,testParams.beforeIndex);
|
|
1703 |
dwRC = WaitForSingleObject (gThreadWaitEvents[testParams.beforeIndex],WAIT_BEFORETHREAD_TIMEOUT);
|
|
1704 |
if (dwRC != WAIT_OBJECT_0)
|
|
1705 |
{
|
|
1706 |
PRINT_ALWAYS "Error waiting for alternate setting before thread"NL);
|
|
1707 |
return 0;
|
|
1708 |
}
|
|
1709 |
dwRC = ChangeInterfaceSetting(testParams.interfaceNumber,testParams.alternateSetting);
|
|
1710 |
OpenPipes (inPipePtr,NULL,&testParams);
|
|
1711 |
}
|
|
1712 |
}
|
|
1713 |
|
|
1714 |
// Then we read the data bytes
|
|
1715 |
dwRC = ReadData(inPipePtr,&buf,&testParams);
|
|
1716 |
if (gDeviceIdleCount < 0)
|
|
1717 |
{
|
|
1718 |
gReadWriteTimeOut = saveTimeout;
|
|
1719 |
ReceiveCounter();
|
|
1720 |
}
|
|
1721 |
pktNum = *(DWORD *)buf.Buffer();
|
|
1722 |
if (pktNum != expected)
|
|
1723 |
{
|
|
1724 |
PRINT_ALWAYS "\n* Error: rcv'd wrong pkt number: 0x%x (expected: 0x%x)"NL, pktNum, expected);
|
|
1725 |
expected = pktNum;
|
|
1726 |
}
|
|
1727 |
expected++;
|
|
1728 |
// Finally, sometimes we print some statistics
|
|
1729 |
repeatCount++;
|
|
1730 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
1731 |
{
|
|
1732 |
if (repeatCount == testParams.repeat)
|
|
1733 |
{
|
|
1734 |
dwRC = CheckAndPrintStats(inPipePtr,NULL,testParams.host.index,repeatCount,&averageInRate,&averageOutRate,testParams.host.inRate,testParams.host.outRate);
|
|
1735 |
}
|
|
1736 |
else
|
|
1737 |
{
|
|
1738 |
if (testParams.host.displayRate && (repeatCount % testParams.host.displayRate) == 0)
|
|
1739 |
{
|
|
1740 |
dwRC = CheckAndPrintStats(inPipePtr,NULL,testParams.host.index,repeatCount,&averageInRate,&averageOutRate);
|
|
1741 |
}
|
|
1742 |
}
|
|
1743 |
}
|
|
1744 |
else
|
|
1745 |
{
|
|
1746 |
PRINT_ALWAYS "\n* Error: Receive-only transfer::read");
|
|
1747 |
ShowErrorText(dwRC);
|
|
1748 |
}
|
|
1749 |
}
|
|
1750 |
|
|
1751 |
Delay (WAIT_TEST_COMPLETE);
|
|
1752 |
USBIO_CLASS_OR_VENDOR_REQUEST request;
|
|
1753 |
request.Flags = USBIO_SHORT_TRANSFER_OK;
|
|
1754 |
request.Type = RequestTypeClass;
|
|
1755 |
request.Recipient = RecipientDevice;
|
|
1756 |
request.RequestTypeReservedBits = 0;
|
|
1757 |
request.Request = ETestResult;
|
|
1758 |
request.Index = testParams.host.index;
|
|
1759 |
request.Value = (dwRC == USBIO_ERR_SUCCESS) ? true : false;
|
|
1760 |
DWORD dataBytes = 0;
|
|
1761 |
dwRC = gUsbDev.ClassOrVendorOutRequest(NULL,dataBytes,&request);
|
|
1762 |
|
|
1763 |
PRINT_TIME "Test Index %d IN rate %lu Receieve-Only %s ",testParams.host.index,averageInRate,request.Value ? "Passed" : "Failed");
|
|
1764 |
|
|
1765 |
dwRC = ClosePipes (inPipePtr,NULL);
|
|
1766 |
|
|
1767 |
delete DataPtr;
|
|
1768 |
delete inPipePtr;
|
|
1769 |
|
|
1770 |
if (request.Value)
|
|
1771 |
{
|
|
1772 |
if (testParams.host.signalNextSettingThread)
|
|
1773 |
{
|
|
1774 |
PRINT_IF_VERBOSE "Signal for thread %d"NL,testParams.host.index);
|
|
1775 |
SetEvent (gThreadWaitEvents[testParams.host.index]);
|
|
1776 |
}
|
|
1777 |
}
|
|
1778 |
else
|
|
1779 |
{
|
|
1780 |
gAbort = true;
|
|
1781 |
}
|
|
1782 |
|
|
1783 |
SetEvent (gThreadEndedEvents[testParams.host.index]);
|
|
1784 |
|
|
1785 |
return 0;
|
|
1786 |
}
|
|
1787 |
|
|
1788 |
|
|
1789 |
UINT TransmitOnlyTransfer(LPVOID pParam)
|
|
1790 |
{
|
|
1791 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
1792 |
BYTE* DataPtr; // the read/write buffer
|
|
1793 |
|
|
1794 |
PRINT_NOLOG "* Transmit-only transfers (OUT)."NL);
|
|
1795 |
|
|
1796 |
TestParamType testParams = *(TestParamPtr)pParam;
|
|
1797 |
|
|
1798 |
ResetEvent (gThreadEndedEvents[testParams.host.index]);
|
|
1799 |
SetEvent (gThreadStartedEvent);
|
|
1800 |
|
|
1801 |
CUsbIoPipe * outPipePtr = new CUsbIoPipe();
|
|
1802 |
|
|
1803 |
DataPtr = new BYTE[testParams.maxSize];
|
|
1804 |
CUsbIoBuf buf((VOID*) DataPtr, testParams.maxSize); // the data buffer
|
|
1805 |
|
|
1806 |
BYTE* WaitSettingDataPtr = new BYTE[WAIT_SETTING_BUFFER_SIZE];
|
|
1807 |
CUsbIoBuf bufWaitSetting((VOID*) WaitSettingDataPtr, WAIT_SETTING_BUFFER_SIZE); // another data buffer
|
|
1808 |
bufWaitSetting.NumberOfBytesToTransfer = WAIT_SETTING_BUFFER_SIZE;
|
|
1809 |
|
|
1810 |
if (!testParams.settingRepeat)
|
|
1811 |
{
|
|
1812 |
OpenPipes (NULL,outPipePtr,&testParams);
|
|
1813 |
}
|
|
1814 |
|
|
1815 |
buf.NumberOfBytesToTransfer = testParams.maxSize;
|
|
1816 |
DWORD averageInRate;
|
|
1817 |
DWORD averageOutRate;
|
|
1818 |
int repeatCount = 0;
|
|
1819 |
DWORD pktNum = testParams.packetNumber;
|
|
1820 |
while ((dwRC == USBIO_ERR_SUCCESS) && !gFinishAllTests && !gAbort && (!testParams.repeat || repeatCount < testParams.repeat))
|
|
1821 |
{
|
|
1822 |
if (testParams.settingRepeat)
|
|
1823 |
{
|
|
1824 |
if ((repeatCount % testParams.settingRepeat) == 0)
|
|
1825 |
{
|
|
1826 |
if (repeatCount)
|
|
1827 |
{
|
|
1828 |
// Wait to ensure that ok to change interface setting
|
|
1829 |
Delay (WAIT_SETTING_DELAY);
|
|
1830 |
// Not necessary if different interfaces used as setting interface closes pipes,
|
|
1831 |
// but if the same interface is used then prevents errors when opening pipes
|
|
1832 |
ClosePipes (NULL,outPipePtr);
|
|
1833 |
PRINT_IF_VERBOSE "Signal for thread %d"NL,testParams.host.index);
|
|
1834 |
SetEvent (gThreadWaitEvents[testParams.host.index]);
|
|
1835 |
}
|
|
1836 |
|
|
1837 |
PRINT_IF_VERBOSE "Wait for thread %d"NL,testParams.beforeIndex);
|
|
1838 |
dwRC = WaitForSingleObject (gThreadWaitEvents[testParams.beforeIndex],WAIT_BEFORETHREAD_TIMEOUT);
|
|
1839 |
if (dwRC != WAIT_OBJECT_0)
|
|
1840 |
{
|
|
1841 |
PRINT_ALWAYS "Error waiting for alternate setting before thread"NL);
|
|
1842 |
return 0;
|
|
1843 |
}
|
|
1844 |
dwRC = ChangeInterfaceSetting (testParams.interfaceNumber,testParams.alternateSetting);
|
|
1845 |
OpenPipes (NULL,outPipePtr,&testParams);
|
|
1846 |
}
|
|
1847 |
}
|
|
1848 |
|
|
1849 |
|
|
1850 |
// Then we write 'Length' bytes
|
|
1851 |
*(DWORD *)buf.Buffer() = pktNum++;
|
|
1852 |
dwRC = WriteData(outPipePtr,&buf,&testParams);
|
|
1853 |
|
|
1854 |
repeatCount++;
|
|
1855 |
// Finally, sometimes we print some statistics
|
|
1856 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
1857 |
{
|
|
1858 |
if (repeatCount == testParams.repeat)
|
|
1859 |
{
|
|
1860 |
dwRC = CheckAndPrintStats(NULL,outPipePtr,testParams.host.index,repeatCount,&averageInRate,&averageOutRate,testParams.host.inRate,testParams.host.outRate);
|
|
1861 |
}
|
|
1862 |
else
|
|
1863 |
{
|
|
1864 |
if (testParams.host.displayRate && (repeatCount % testParams.host.displayRate) == 0)
|
|
1865 |
{
|
|
1866 |
dwRC = CheckAndPrintStats(NULL,outPipePtr,testParams.host.index,repeatCount,&averageInRate,&averageOutRate);
|
|
1867 |
}
|
|
1868 |
}
|
|
1869 |
}
|
|
1870 |
else
|
|
1871 |
{
|
|
1872 |
PRINT_ALWAYS "\n* Error: Transmit-only transfer::write");
|
|
1873 |
ShowErrorText(dwRC);
|
|
1874 |
}
|
|
1875 |
}
|
|
1876 |
|
|
1877 |
Delay (WAIT_TEST_COMPLETE);
|
|
1878 |
USBIO_CLASS_OR_VENDOR_REQUEST request;
|
|
1879 |
request.Flags = USBIO_SHORT_TRANSFER_OK;
|
|
1880 |
request.Type = RequestTypeClass;
|
|
1881 |
request.Recipient = RecipientDevice;
|
|
1882 |
request.RequestTypeReservedBits = 0;
|
|
1883 |
request.Request = ETestResult;
|
|
1884 |
request.Index = testParams.host.index;
|
|
1885 |
request.Value = (dwRC == USBIO_ERR_SUCCESS) ? true : false;
|
|
1886 |
DWORD dataBytes = 0;
|
|
1887 |
dwRC = gUsbDev.ClassOrVendorOutRequest(NULL,dataBytes,&request);
|
|
1888 |
|
|
1889 |
PRINT_TIME "Test Index %d OUT rate %lu Transmit Only %s ",testParams.host.index,averageOutRate,request.Value ? "Passed" : "Failed");
|
|
1890 |
|
|
1891 |
ClosePipes (NULL,outPipePtr);
|
|
1892 |
delete DataPtr;
|
|
1893 |
delete outPipePtr;
|
|
1894 |
|
|
1895 |
if (request.Value)
|
|
1896 |
{
|
|
1897 |
if (testParams.host.signalNextSettingThread)
|
|
1898 |
{
|
|
1899 |
PRINT_IF_VERBOSE "Signal for thread %d"NL,testParams.host.index);
|
|
1900 |
SetEvent (gThreadWaitEvents[testParams.host.index]);
|
|
1901 |
}
|
|
1902 |
}
|
|
1903 |
else
|
|
1904 |
{
|
|
1905 |
gAbort = true;
|
|
1906 |
}
|
|
1907 |
|
|
1908 |
SetEvent (gThreadEndedEvents[testParams.host.index]);
|
|
1909 |
|
|
1910 |
return 0;
|
|
1911 |
}
|
|
1912 |
|
|
1913 |
|
|
1914 |
static BOOL CreateEvents()
|
|
1915 |
{
|
|
1916 |
// Create a manual-reset event object.
|
|
1917 |
// Any thread sets this to signaled when it has started.
|
|
1918 |
gThreadStartedEvent = CreateEvent(
|
|
1919 |
NULL, // no security attributes
|
|
1920 |
TRUE, // manual-reset event
|
|
1921 |
FALSE, // initial state is non-signaled
|
|
1922 |
"ThreadStarted" // object name
|
|
1923 |
);
|
|
1924 |
if (gThreadStartedEvent == NULL)
|
|
1925 |
{
|
|
1926 |
PRINT_ALWAYS "Error creating thread started event"NL);
|
|
1927 |
// error exit
|
|
1928 |
return FALSE;
|
|
1929 |
}
|
|
1930 |
// Create a manual-reset event object.
|
|
1931 |
// Set to signaled by CT_usb_winDlg when the device is connected.
|
|
1932 |
gDeviceConnectEvent = CreateEvent(
|
|
1933 |
NULL, // no security attributes
|
|
1934 |
TRUE, // manual-reset event
|
|
1935 |
FALSE, // initial state is non-signaled
|
|
1936 |
"DeviceConnected" // object name
|
|
1937 |
);
|
|
1938 |
if (gDeviceConnectEvent == NULL)
|
|
1939 |
{
|
|
1940 |
PRINT_ALWAYS "Error creating device connected event"NL);
|
|
1941 |
// error exit
|
|
1942 |
return FALSE;
|
|
1943 |
}
|
|
1944 |
// Create a manual-reset event object.
|
|
1945 |
// Set to nonsignaled by CT_usb_winDlg when the device is disconnected.
|
|
1946 |
gDeviceDisconnectEvent = CreateEvent(
|
|
1947 |
NULL, // no security attributes
|
|
1948 |
TRUE, // manual-reset event
|
|
1949 |
FALSE, // initial state is non-signaled
|
|
1950 |
"DeviceDisconnected" // object name
|
|
1951 |
);
|
|
1952 |
if (gDeviceDisconnectEvent == NULL)
|
|
1953 |
{
|
|
1954 |
PRINT_ALWAYS "Error creating device disconnected event"NL);
|
|
1955 |
// error exit
|
|
1956 |
return FALSE;
|
|
1957 |
}
|
|
1958 |
|
|
1959 |
for (int i = 0; i < MAX_THREADS; i++)
|
|
1960 |
{
|
|
1961 |
// Create manual-reset event object for each thread. Any thread sets
|
|
1962 |
// this to nonsignaled when it has started.
|
|
1963 |
gThreadEndedEvents[i] = CreateEvent(
|
|
1964 |
NULL, // no security attributes
|
|
1965 |
TRUE, // manual-reset event
|
|
1966 |
FALSE, // initial state is non-signaled
|
|
1967 |
"" // object name
|
|
1968 |
);
|
|
1969 |
if (gThreadEndedEvents[i] == NULL)
|
|
1970 |
{
|
|
1971 |
PRINT_ALWAYS "Error creating thread %d ended event"NL,i);
|
|
1972 |
// error exit
|
|
1973 |
return FALSE;
|
|
1974 |
}
|
|
1975 |
// Create auto-reset event object for each thread. Any thread sets
|
|
1976 |
// this to nonsignaled when it has started.
|
|
1977 |
gThreadWaitEvents[i] = CreateEvent(
|
|
1978 |
NULL, // no security attributes
|
|
1979 |
FALSE, // automatically-reset event
|
|
1980 |
FALSE, // initial state is non-signaled
|
|
1981 |
"" // object name
|
|
1982 |
);
|
|
1983 |
if (gThreadEndedEvents[i] == NULL)
|
|
1984 |
{
|
|
1985 |
PRINT_ALWAYS "Error creating thread %d ended event"NL,i);
|
|
1986 |
// error exit
|
|
1987 |
return FALSE;
|
|
1988 |
}
|
|
1989 |
}
|
|
1990 |
return TRUE;
|
|
1991 |
}
|
|
1992 |
|
|
1993 |
|
|
1994 |
static BOOL GetDeviceInfo()
|
|
1995 |
{
|
|
1996 |
DWORD dwRC;
|
|
1997 |
|
|
1998 |
dwRC = GetDeviceDescriptor();
|
|
1999 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
2000 |
{
|
|
2001 |
dwRC = GetConfigurationDescriptor();
|
|
2002 |
}
|
|
2003 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
2004 |
{
|
|
2005 |
dwRC = GetStringDescriptor();
|
|
2006 |
}
|
|
2007 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
2008 |
{
|
|
2009 |
// In order to give the USB device-side program (t_usb_device)
|
|
2010 |
// enough time after getting configured to carry out
|
|
2011 |
// some device tests, we wait here for a short while
|
|
2012 |
// before proceeding:
|
|
2013 |
Delay(DEVICE_CONFIG_DELAY);
|
|
2014 |
dwRC = GetConfigurationInfo();
|
|
2015 |
}
|
|
2016 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
2017 |
{
|
|
2018 |
dwRC = ExchangeVersions();
|
|
2019 |
}
|
|
2020 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
2021 |
{
|
|
2022 |
if (dwRC == ERR_SCRIPT_NAME)
|
|
2023 |
PRINT_ALWAYS "*** Warning Script Name Mismatch "NL);
|
|
2024 |
else
|
|
2025 |
ShowErrorText(dwRC);
|
|
2026 |
return FALSE;
|
|
2027 |
}
|
|
2028 |
|
|
2029 |
return TRUE;
|
|
2030 |
}
|
|
2031 |
|
|
2032 |
UINT DoTests(LPVOID pParam)
|
|
2033 |
{
|
|
2034 |
DWORD dwRC = USBIO_ERR_SUCCESS;
|
|
2035 |
bool firstSetting = true;
|
|
2036 |
BYTE threadIndex = 0;
|
|
2037 |
BYTE lastSettingThreadIndex = 0;
|
|
2038 |
TestParamType testParams;
|
|
2039 |
USBIO_CLASS_OR_VENDOR_REQUEST request;
|
|
2040 |
DWORD dataBytes;
|
|
2041 |
FILE* inStream;
|
|
2042 |
char line[256];
|
|
2043 |
long repeatPosition = -1;
|
|
2044 |
long repeatCount = -1;
|
|
2045 |
UsbcvControl * usbcv;
|
|
2046 |
bool hostTestFail = false;
|
|
2047 |
bool mstoreDriveReady = false;
|
|
2048 |
DWORD waitConnectTime = 0;
|
|
2049 |
STARTUPINFO si;
|
|
2050 |
PROCESS_INFORMATION pi;
|
|
2051 |
|
|
2052 |
if (!CreateEvents())
|
|
2053 |
{
|
|
2054 |
return FALSE;
|
|
2055 |
}
|
|
2056 |
if( (inStream = fopen( gScriptFileName, "r" )) == NULL )
|
|
2057 |
{
|
|
2058 |
PRINT_ALWAYS "The test script file %s was not opened"NL,gScriptFileName );
|
|
2059 |
return FALSE;
|
|
2060 |
}
|
|
2061 |
else
|
|
2062 |
{
|
|
2063 |
PRINT_IF_VERBOSE "The test script file %s opened"NL,gScriptFileName);
|
|
2064 |
}
|
|
2065 |
|
|
2066 |
PRINT_ALWAYS "Script file %s"NL,gScriptFileName);
|
|
2067 |
|
|
2068 |
// set up the EP 0 request structure
|
|
2069 |
request.Flags = USBIO_SHORT_TRANSFER_OK;
|
|
2070 |
request.Type = RequestTypeClass;
|
|
2071 |
request.Recipient = RecipientDevice;
|
|
2072 |
request.RequestTypeReservedBits = 0;
|
|
2073 |
|
|
2074 |
gTransferMode = EComment;
|
|
2075 |
|
|
2076 |
PRINT_TIME "Tests Started ");
|
|
2077 |
|
|
2078 |
/* Cycle until end of file reached: */
|
|
2079 |
while( !feof( inStream ) && !gAbort)
|
|
2080 |
{
|
|
2081 |
testParams.host.index = threadIndex;
|
|
2082 |
|
|
2083 |
// for loopback tests
|
|
2084 |
if (gTransferMode < EComment)
|
|
2085 |
{
|
|
2086 |
if (testParams.settingRepeat == 0)
|
|
2087 |
{
|
|
2088 |
dwRC = ChangeInterfaceSetting (testParams.interfaceNumber,testParams.alternateSetting);
|
|
2089 |
}
|
|
2090 |
request.Request = ETestParam;
|
|
2091 |
request.Index = testParams.host.index;
|
|
2092 |
if (firstSetting && testParams.settingRepeat)
|
|
2093 |
{
|
|
2094 |
request.Index |= FIRST_SETTING_THREAD_MASK;
|
|
2095 |
PRINT_IF_VERBOSE "Signal for thread %d"NL,testParams.beforeIndex);
|
|
2096 |
lastSettingThreadIndex = testParams.beforeIndex;
|
|
2097 |
SetEvent (gThreadWaitEvents[lastSettingThreadIndex]);
|
|
2098 |
firstSetting = false;
|
|
2099 |
}
|
|
2100 |
if (testParams.settingRepeat && threadIndex == lastSettingThreadIndex)
|
|
2101 |
{
|
|
2102 |
request.Index |= LAST_SETTING_THREAD_MASK;
|
|
2103 |
}
|
|
2104 |
dataBytes = sizeof(testParams) - sizeof(TestParamHostType);
|
|
2105 |
dwRC = gUsbDev.ClassOrVendorOutRequest(&testParams,dataBytes,&request);
|
|
2106 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
2107 |
{
|
|
2108 |
PRINT_ALWAYS "\n* Error: CUsbIo::ClassOrVendorOutRequest ");
|
|
2109 |
ShowErrorText(dwRC);
|
|
2110 |
}
|
|
2111 |
}
|
|
2112 |
|
|
2113 |
testParams.host.signalNextSettingThread = (testParams.settingRepeat && threadIndex != lastSettingThreadIndex);
|
|
2114 |
switch (gTransferMode)
|
|
2115 |
{
|
|
2116 |
case EXml:
|
|
2117 |
break;
|
|
2118 |
|
|
2119 |
case ELoop:
|
|
2120 |
case ECompare:
|
|
2121 |
if (gDeviceIdleCount < 0)
|
|
2122 |
{
|
|
2123 |
ReceiveCounter();
|
|
2124 |
}
|
|
2125 |
AfxBeginThread (LoopTransfer, &testParams);
|
|
2126 |
break;
|
|
2127 |
|
|
2128 |
case EReceiveOnly:
|
|
2129 |
case EFileReceive:
|
|
2130 |
if (gDeviceIdleCount < 0 && gTransferMode != EFileReceive)
|
|
2131 |
{
|
|
2132 |
ReceiveCounter();
|
|
2133 |
}
|
|
2134 |
AfxBeginThread (ReceiveOnlyTransfer, &testParams);
|
|
2135 |
break;
|
|
2136 |
|
|
2137 |
case ETransmitOnly:
|
|
2138 |
case EFileTransmit:
|
|
2139 |
if (gDeviceIdleCount < 0)
|
|
2140 |
{
|
|
2141 |
ReceiveCounter();
|
|
2142 |
}
|
|
2143 |
AfxBeginThread (TransmitOnlyTransfer, &testParams);
|
|
2144 |
break;
|
|
2145 |
|
|
2146 |
case EConnect:
|
|
2147 |
// ensure that connect and disconnect events are reset
|
|
2148 |
ResetEvent (gDeviceConnectEvent);
|
|
2149 |
ResetEvent (gDeviceDisconnectEvent);
|
|
2150 |
request.Request = ETestConnect;
|
|
2151 |
request.Value = (USHORT)testParams.minSize;
|
|
2152 |
dataBytes = 0;
|
|
2153 |
dwRC = gUsbDev.ClassOrVendorOutRequest(NULL,dataBytes,&request);
|
|
2154 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
2155 |
{
|
|
2156 |
PRINT_ALWAYS "\n* Error: CUsbIo::ClassOrVendorOutRequest ");
|
|
2157 |
ShowErrorText(dwRC);
|
|
2158 |
}
|
|
2159 |
break;
|
|
2160 |
|
|
2161 |
case EDisconnect:
|
|
2162 |
if (gUsbDev.IsOpen())
|
|
2163 |
{
|
|
2164 |
CloseUsbDevice();
|
|
2165 |
}
|
|
2166 |
break;
|
|
2167 |
|
|
2168 |
case EComment:
|
|
2169 |
break;
|
|
2170 |
|
|
2171 |
case EWait:
|
|
2172 |
if (testParams.host.index > 0)
|
|
2173 |
{
|
|
2174 |
PRINT_ALWAYS "Waiting for %d tests to complete\n",testParams.host.index);
|
|
2175 |
dwRC = WaitForMultipleObjects (testParams.host.index,gThreadEndedEvents,TRUE,testParams.minSize);
|
|
2176 |
if (dwRC == WAIT_TIMEOUT)
|
|
2177 |
{
|
|
2178 |
PRINT_ALWAYS "Timeout on waiting for test completion\n");
|
|
2179 |
bool anyTestNotCompleted = false;
|
|
2180 |
for (int i = 0; i < testParams.host.index; i++)
|
|
2181 |
{
|
|
2182 |
dwRC = WaitForSingleObject(gThreadEndedEvents[i],0);
|
|
2183 |
if (dwRC != WAIT_OBJECT_0)
|
|
2184 |
{
|
|
2185 |
anyTestNotCompleted = true;
|
|
2186 |
PRINT_ALWAYS "Thread %d not completed\n",i);
|
|
2187 |
}
|
|
2188 |
}
|
|
2189 |
if (anyTestNotCompleted)
|
|
2190 |
{
|
|
2191 |
gFinishAllTests = true;
|
|
2192 |
dwRC = WaitForMultipleObjects (testParams.host.index,gThreadEndedEvents,TRUE,INFINITE);
|
|
2193 |
gFinishAllTests = false;
|
|
2194 |
gAbort = true;
|
|
2195 |
}
|
|
2196 |
}
|
|
2197 |
if (dwRC < WAIT_OBJECT_0 || dwRC >= (WAIT_OBJECT_0 + testParams.host.index))
|
|
2198 |
{
|
|
2199 |
PRINT_ALWAYS "Error waiting for all threads to complete"NL);
|
|
2200 |
gAbort = true;
|
|
2201 |
gFinishAllTests = true;
|
|
2202 |
}
|
|
2203 |
ReceiveCounter();
|
|
2204 |
gDeviceIdleCount = -1;
|
|
2205 |
PRINT_TIME "Test Group Complete ");
|
|
2206 |
}
|
|
2207 |
threadIndex = 0;
|
|
2208 |
firstSetting = true;
|
|
2209 |
break;
|
|
2210 |
|
|
2211 |
case EFail:
|
|
2212 |
request.Request = ETestFail;
|
|
2213 |
dataBytes = 0;
|
|
2214 |
dwRC = gUsbDev.ClassOrVendorOutRequest(NULL,dataBytes,&request);
|
|
2215 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
2216 |
{
|
|
2217 |
PRINT_ALWAYS "\n* Error: CUsbIo::ClassOrVendorOutRequest ");
|
|
2218 |
ShowErrorText(dwRC);
|
|
2219 |
}
|
|
2220 |
gAbort = true;
|
|
2221 |
break;
|
|
2222 |
|
|
2223 |
case ESwitch:
|
|
2224 |
PRINT_NOLOG "Switching USB to %d"NL,testParams.minSize);
|
|
2225 |
dwRC = OpenSwitchDevice ();
|
|
2226 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
2227 |
{
|
|
2228 |
dwRC = GetConfigurationDescriptor();
|
|
2229 |
}
|
|
2230 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
2231 |
{
|
|
2232 |
// Delay to allow the switch to take place
|
|
2233 |
Delay (BEFORE_SWITCH_DELAY);
|
|
2234 |
|
|
2235 |
request.Recipient = RecipientInterface;
|
|
2236 |
request.Request = SWITCH_REQUEST;
|
|
2237 |
request.Index = SWITCH_INDEX;
|
|
2238 |
request.Value = SWITCH_VALUE;
|
|
2239 |
BYTE switchData[] = {SWITCH_DATA0,((BYTE)testParams.minSize << 4) | SWITCH_DATA1};
|
|
2240 |
DWORD dataBytes = sizeof(switchData);
|
|
2241 |
dwRC = gUsbDev.ClassOrVendorOutRequest(&switchData[0],dataBytes,&request);
|
|
2242 |
request.Recipient = RecipientDevice;
|
|
2243 |
CloseUsbDevice();
|
|
2244 |
|
|
2245 |
// Delay to allow the switch to take place
|
|
2246 |
Delay (AFTER_SWITCH_DELAY);
|
|
2247 |
}
|
|
2248 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
2249 |
{
|
|
2250 |
PRINT_ALWAYS "\n* Error: GetConfigurationDescriptor or CUsbIo::ClassOrVendorOutRequest ");
|
|
2251 |
gAbort = true;
|
|
2252 |
}
|
|
2253 |
break;
|
|
2254 |
|
|
2255 |
case EWaitConnect:
|
|
2256 |
PRINT_NOLOG "Waiting for device connection"NL);
|
|
2257 |
waitConnectTime = 0;
|
|
2258 |
while (!gAbort && !gUsbDev.IsOpen())
|
|
2259 |
{
|
|
2260 |
ResetEvent (gDeviceConnectEvent);
|
|
2261 |
ResetEvent (gDeviceDisconnectEvent);
|
|
2262 |
dwRC = OpenUsbDevice();
|
|
2263 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
2264 |
{
|
|
2265 |
if (!GetDeviceInfo())
|
|
2266 |
{
|
|
2267 |
dwRC = USBIO_ERR_FAILED;
|
|
2268 |
PRINT_ALWAYS "\n* Error: GetDeviceInfo"NL);
|
|
2269 |
gAbort = TRUE;
|
|
2270 |
hostTestFail = FALSE;
|
|
2271 |
}
|
|
2272 |
}
|
|
2273 |
else
|
|
2274 |
{
|
|
2275 |
dwRC = WaitForSingleObject (gDeviceConnectEvent,CONNECT_RESCAN_TIMEOUT);
|
|
2276 |
if ((dwRC == WAIT_ABANDONED) || (dwRC == WAIT_FAILED))
|
|
2277 |
{
|
|
2278 |
PRINT_ALWAYS "Error waiting for device connection"NL);
|
|
2279 |
gAbort = TRUE;
|
|
2280 |
hostTestFail = FALSE;
|
|
2281 |
}
|
|
2282 |
if (dwRC == WAIT_TIMEOUT)
|
|
2283 |
{
|
|
2284 |
waitConnectTime += CONNECT_RESCAN_TIMEOUT;
|
|
2285 |
if (testParams.minSize && waitConnectTime >= testParams.minSize)
|
|
2286 |
{
|
|
2287 |
PRINT_ALWAYS "Timeout for device connection"NL);
|
|
2288 |
gAbort = TRUE;
|
|
2289 |
hostTestFail = FALSE;
|
|
2290 |
}
|
|
2291 |
else
|
|
2292 |
{
|
|
2293 |
ZeroMemory( &si, sizeof(si) );
|
|
2294 |
si.cb = sizeof(si);
|
|
2295 |
ZeroMemory( &pi, sizeof(pi) );
|
|
2296 |
|
|
2297 |
dwRC = CreateProcess (RESCAN_APPNAME,RESCAN_CMDLINE,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);
|
|
2298 |
if (dwRC < 0)
|
|
2299 |
PRINT_ALWAYS "Error %d running Devcon Rescan"NL,dwRC);
|
|
2300 |
}
|
|
2301 |
}
|
|
2302 |
}
|
|
2303 |
}
|
|
2304 |
if (hostTestFail)
|
|
2305 |
{
|
|
2306 |
// try to send a test fail to the device
|
|
2307 |
request.Request = ETestResult;
|
|
2308 |
request.Index = HOST_ERROR_INDEX;
|
|
2309 |
request.Value = false;
|
|
2310 |
dataBytes = 0;
|
|
2311 |
dwRC = gUsbDev.ClassOrVendorOutRequest(NULL,dataBytes,&request);
|
|
2312 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
2313 |
{
|
|
2314 |
PRINT_ALWAYS "\n* Error: CUsbIo::ClassOrVendorOutRequest ");
|
|
2315 |
ShowErrorText(dwRC);
|
|
2316 |
}
|
|
2317 |
gAbort = true;
|
|
2318 |
}
|
|
2319 |
break;
|
|
2320 |
|
|
2321 |
case EWaitDisconnect:
|
|
2322 |
PRINT_NOLOG "Waiting for device disconnection"NL);
|
|
2323 |
dwRC = WaitForSingleObject (gDeviceDisconnectEvent,testParams.minSize);
|
|
2324 |
if (dwRC != WAIT_OBJECT_0)
|
|
2325 |
{
|
|
2326 |
PRINT_ALWAYS "Error waiting for device disconnection"NL);
|
|
2327 |
gAbort = true;
|
|
2328 |
}
|
|
2329 |
// ensure that connect and disconnect events are reset
|
|
2330 |
ResetEvent (gDeviceConnectEvent);
|
|
2331 |
ResetEvent (gDeviceDisconnectEvent);
|
|
2332 |
break;
|
|
2333 |
|
|
2334 |
case EDo:
|
|
2335 |
repeatPosition = ftell(inStream);
|
|
2336 |
repeatCount = 0;
|
|
2337 |
PRINT_IF_VERBOSE "Repeating from file position %ld"NL,repeatPosition);
|
|
2338 |
break;
|
|
2339 |
|
|
2340 |
case ERepeat:
|
|
2341 |
if (repeatPosition <= 0)
|
|
2342 |
PRINT_ALWAYS "No REPEAT in file"NL);
|
|
2343 |
else
|
|
2344 |
{
|
|
2345 |
if (repeatCount++ < (long)testParams.minSize)
|
|
2346 |
{
|
|
2347 |
if (!fseek( inStream, repeatPosition, SEEK_SET))
|
|
2348 |
PRINT_ALWAYS "Repeat Iteration %d"NL,repeatCount);
|
|
2349 |
else
|
|
2350 |
PRINT_ALWAYS "ERROR: Repeat Iteration %d"NL,repeatCount);
|
|
2351 |
}
|
|
2352 |
}
|
|
2353 |
break;
|
|
2354 |
|
|
2355 |
case EUsbcv:
|
|
2356 |
CloseUsbDevice();
|
|
2357 |
PRINT_TIME "USBCV Test Started ");
|
|
2358 |
usbcv = new UsbcvControl();
|
|
2359 |
dwRC = usbcv->Create();
|
|
2360 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
2361 |
{
|
|
2362 |
dwRC = usbcv->TestAllDevices(vendorId,productId, productIdMS);
|
|
2363 |
}
|
|
2364 |
delete usbcv;
|
|
2365 |
if (dwRC == USBIO_ERR_SUCCESS)
|
|
2366 |
{
|
|
2367 |
PRINT_TIME "USBCV Test Complete - %s ",gAbort ? "Failed" : "Passed");
|
|
2368 |
}
|
|
2369 |
else
|
|
2370 |
{
|
|
2371 |
gAbort = true;
|
|
2372 |
PRINT_ALWAYS "Error in Running USBCV\n");
|
|
2373 |
}
|
|
2374 |
if (gAbort)
|
|
2375 |
{
|
|
2376 |
// allow further tests to carry on until waitConnect
|
|
2377 |
hostTestFail = true;
|
|
2378 |
gAbort = false;
|
|
2379 |
}
|
|
2380 |
// ensure that connect and disconnect events are reset
|
|
2381 |
ResetEvent (gDeviceConnectEvent);
|
|
2382 |
ResetEvent (gDeviceDisconnectEvent);
|
|
2383 |
break;
|
|
2384 |
|
|
2385 |
case EMassStorage:
|
|
2386 |
mstoreDriveReady = false;
|
|
2387 |
ResetEvent (gDeviceConnectEvent);
|
|
2388 |
ResetEvent (gDeviceDisconnectEvent);
|
|
2389 |
PRINT_TIME "Mass Storage Test Started ");
|
|
2390 |
request.Request = ETestMassStorage;
|
|
2391 |
request.Value = (USHORT)testParams.minSize; // product id
|
|
2392 |
productIdMS = (USHORT)testParams.minSize;
|
|
2393 |
dataBytes = 0;
|
|
2394 |
dwRC = gUsbDev.ClassOrVendorOutRequest(NULL,dataBytes,&request);
|
|
2395 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
2396 |
{
|
|
2397 |
PRINT_ALWAYS "\n* Error: CUsbIo::ClassOrVendorOutRequest ");
|
|
2398 |
ShowErrorText(dwRC);
|
|
2399 |
}
|
|
2400 |
CloseUsbDevice();
|
|
2401 |
if (gAbort)
|
|
2402 |
{
|
|
2403 |
// allow further tests to carry on until waitConnect
|
|
2404 |
hostTestFail = true;
|
|
2405 |
gAbort = false;
|
|
2406 |
}
|
|
2407 |
break;
|
|
2408 |
|
|
2409 |
case EEject:
|
|
2410 |
if (mstoreDriveReady)
|
|
2411 |
{
|
|
2412 |
PRINT_TIME "Mass Storage Test Completed ");
|
|
2413 |
if (strlen(line) == 0)
|
|
2414 |
gAbort = !EjectVolume(' ');
|
|
2415 |
else
|
|
2416 |
gAbort = !EjectVolume(line[0]);
|
|
2417 |
PRINT_TIME "Mass Storage Test Complete - %s ",gAbort || hostTestFail ? "Failed" : "Passed");
|
|
2418 |
if (gAbort)
|
|
2419 |
{
|
|
2420 |
// allow further tests to carry on until waitConnect
|
|
2421 |
hostTestFail = true;
|
|
2422 |
gAbort = false;
|
|
2423 |
}
|
|
2424 |
}
|
|
2425 |
break;
|
|
2426 |
|
|
2427 |
case EPerl:
|
|
2428 |
if (mstoreDriveReady)
|
|
2429 |
{
|
|
2430 |
PRINT_TIME "Starting Perl Script %s ",line);
|
|
2431 |
if (strlen(gLogfileName))
|
|
2432 |
{
|
|
2433 |
strcat (line," --logfile=");
|
|
2434 |
strcat (line,gLogfileName);
|
|
2435 |
fclose (logStream);
|
|
2436 |
}
|
|
2437 |
dwRC = PerlScript (line);
|
|
2438 |
if (strlen(gLogfileName))
|
|
2439 |
{
|
|
2440 |
logStream = fopen (gLogfileName, "a+");
|
|
2441 |
}
|
|
2442 |
PRINT_TIME "Perl Script Complete - %s ",dwRC == 0 ? "Passed" : "Failed");
|
|
2443 |
if (dwRC != 0 || gAbort)
|
|
2444 |
{
|
|
2445 |
ShowErrorText (dwRC);
|
|
2446 |
// allow further tests to carry on until waitConnect
|
|
2447 |
hostTestFail = true;
|
|
2448 |
gAbort = false;
|
|
2449 |
}
|
|
2450 |
}
|
|
2451 |
break;
|
|
2452 |
|
|
2453 |
case EWaitDrive:
|
|
2454 |
if (!hostTestFail)
|
|
2455 |
{
|
|
2456 |
PRINT_TIME "Waiting for removable drive - %c ",line[0]);
|
|
2457 |
gAbort = !WaitDriveReady(line[0]);
|
|
2458 |
PRINT_TIME "Waiting completed - %s ",gAbort ? "Failed" : "Successfully");
|
|
2459 |
if (gAbort)
|
|
2460 |
{
|
|
2461 |
// allow further tests to carry on until waitConnect
|
|
2462 |
hostTestFail = true;
|
|
2463 |
gAbort = false;
|
|
2464 |
}
|
|
2465 |
else
|
|
2466 |
{
|
|
2467 |
mstoreDriveReady = true;
|
|
2468 |
}
|
|
2469 |
}
|
|
2470 |
break;
|
|
2471 |
|
|
2472 |
default:
|
|
2473 |
gAbort = true;
|
|
2474 |
break;
|
|
2475 |
}
|
|
2476 |
if (!gAbort && gTransferMode < EComment)
|
|
2477 |
{
|
|
2478 |
dwRC = WaitForSingleObject (gThreadStartedEvent,1500);
|
|
2479 |
if (dwRC != WAIT_OBJECT_0)
|
|
2480 |
{
|
|
2481 |
PRINT_ALWAYS "Error waiting for thread to become ready"NL);
|
|
2482 |
gAbort = true;
|
|
2483 |
}
|
|
2484 |
threadIndex++;
|
|
2485 |
dwRC = ResetEvent (gThreadStartedEvent);
|
|
2486 |
}
|
|
2487 |
if (!gAbort)
|
|
2488 |
{
|
|
2489 |
if( fgets( line, 100, inStream ) != NULL)
|
|
2490 |
{
|
|
2491 |
gTransferMode = ParseTestLine (line,&testParams,&request);
|
|
2492 |
}
|
|
2493 |
}
|
|
2494 |
}
|
|
2495 |
|
|
2496 |
if (gAbort)
|
|
2497 |
{
|
|
2498 |
PRINT_TIME "Tests Not Completed - Failed ");
|
|
2499 |
}
|
|
2500 |
else
|
|
2501 |
{
|
|
2502 |
request.Request = EStop;
|
|
2503 |
request.Value = (logStream == NULL) ? false : true;
|
|
2504 |
dataBytes = 0;
|
|
2505 |
dwRC = gUsbDev.ClassOrVendorOutRequest(NULL,dataBytes,&request);
|
|
2506 |
if (dwRC != USBIO_ERR_SUCCESS)
|
|
2507 |
{
|
|
2508 |
PRINT_ALWAYS "\n* Error: CUsbIo::ClassOrVendorOutRequest ");
|
|
2509 |
ShowErrorText(dwRC);
|
|
2510 |
}
|
|
2511 |
|
|
2512 |
PRINT_TIME "Tests Completed - All Passed ");
|
|
2513 |
}
|
|
2514 |
|
|
2515 |
|
|
2516 |
PRINT_ALWAYS NL);
|
|
2517 |
|
|
2518 |
if (logStream != NULL)
|
|
2519 |
{
|
|
2520 |
fclose (logStream);
|
|
2521 |
if (!gAbort)
|
|
2522 |
{
|
|
2523 |
SendLogFile();
|
|
2524 |
}
|
|
2525 |
}
|
|
2526 |
|
|
2527 |
PRINT_NOLOG "Waiting for device disconnection"NL);
|
|
2528 |
dwRC = WaitForSingleObject (gDeviceDisconnectEvent,WAITDISCONNECT_TIMEOUT);
|
|
2529 |
if (dwRC != WAIT_OBJECT_0 && !gAbort)
|
|
2530 |
{
|
|
2531 |
PRINT_ALWAYS "Error waiting for device disconnection"NL);
|
|
2532 |
}
|
|
2533 |
|
|
2534 |
CloseUsbDevice();
|
|
2535 |
|
|
2536 |
if (!gKeepOpen)
|
|
2537 |
{
|
|
2538 |
ExitProcess(0);
|
|
2539 |
}
|
|
2540 |
|
|
2541 |
return TRUE;
|
|
2542 |
}
|
|
2543 |
|
|
2544 |
// --eof
|