VirtualBox

source: vbox/trunk/src/VBox/Devices/USB/VUSBUrbTrace.cpp@ 59767

Last change on this file since 59767 was 59738, checked in by vboxsync, 9 years ago

VUSB: Some structural cleanup (#7 Move the debug log trace related bits into a separate file)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 36.7 KB
Line 
1/* $Id: VUSBUrbTrace.cpp 59738 2016-02-19 11:55:56Z vboxsync $ */
2/** @file
3 * Virtual USB - URBs.
4 */
5
6/*
7 * Copyright (C) 2006-2016 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#define LOG_GROUP LOG_GROUP_DRV_VUSB
23#include <VBox/vmm/pdm.h>
24#include <VBox/vmm/vmapi.h>
25#include <VBox/err.h>
26#include <iprt/alloc.h>
27#include <VBox/log.h>
28#include <iprt/time.h>
29#include <iprt/thread.h>
30#include <iprt/semaphore.h>
31#include <iprt/string.h>
32#include <iprt/assert.h>
33#include <iprt/asm.h>
34#include <iprt/env.h>
35#include "VUSBInternal.h"
36
37
38
39/*********************************************************************************************************************************
40* Global Variables *
41*********************************************************************************************************************************/
42
43/*********************************************************************************************************************************
44* Internal Functions *
45*********************************************************************************************************************************/
46static PVUSBCTRLEXTRA vusbMsgAllocExtraData(PVUSBURB pUrb);
47
48
49#ifdef LOG_ENABLED
50DECLINLINE(const char *) GetScsiErrCd(uint8_t ScsiErr)
51{
52 switch (ScsiErr)
53 {
54 case 0: return "?";
55 }
56 return "?";
57}
58
59DECLINLINE(const char *) GetScsiKCQ(uint8_t Key, uint8_t ASC, uint8_t ASCQ)
60{
61 switch (Key)
62 {
63 case 0:
64 switch (RT_MAKE_U16(ASC, ASCQ))
65 {
66 case RT_MAKE_U16(0x00, 0x00): return "No error";
67 }
68 break;
69
70 case 1:
71 return "Soft Error";
72
73 case 2:
74 return "Not Ready";
75
76 case 3:
77 return "Medium Error";
78
79 case 4:
80 return "Hard Error";
81
82 case 5:
83 return "Illegal Request";
84
85 case 6:
86 return "Unit Attention";
87
88 case 7:
89 return "Write Protected";
90
91 case 0xb:
92 return "Aborted Command";
93 }
94 return "?";
95}
96
97DECLHIDDEN(const char *) vusbUrbStatusName(VUSBSTATUS enmStatus)
98{
99 /** Strings for the URB statuses. */
100 static const char * const s_apszNames[] =
101 {
102 "OK",
103 "STALL",
104 "ERR_DNR",
105 "ERR_CRC",
106 "DATA_UNDERRUN",
107 "DATA_OVERRUN",
108 "NOT_ACCESSED",
109 "7", "8", "9", "10", "11", "12", "13", "14", "15"
110 };
111
112 return enmStatus < (int)RT_ELEMENTS(s_apszNames)
113 ? s_apszNames[enmStatus]
114 : enmStatus == VUSBSTATUS_INVALID
115 ? "INVALID"
116 : "??";
117}
118
119DECLHIDDEN(const char *) vusbUrbDirName(VUSBDIRECTION enmDir)
120{
121 /** Strings for the URB directions. */
122 static const char * const s_apszNames[] =
123 {
124 "setup",
125 "in",
126 "out"
127 };
128
129 return enmDir < (int)RT_ELEMENTS(s_apszNames)
130 ? s_apszNames[enmDir]
131 : "??";
132}
133
134DECLHIDDEN(const char *) vusbUrbTypeName(VUSBXFERTYPE enmType)
135{
136 /** Strings for the URB types. */
137 static const char * const s_apszName[] =
138 {
139 "control-part",
140 "isochronous",
141 "bulk",
142 "interrupt",
143 "control"
144 };
145
146 return enmType < (int)RT_ELEMENTS(s_apszName)
147 ? s_apszName[enmType]
148 : "??";
149}
150
151/**
152 * Logs an URB.
153 *
154 * Note that pUrb->pVUsb->pDev and pUrb->pVUsb->pDev->pUsbIns can all be NULL.
155 */
156DECLHIDDEN(void) vusbUrbTrace(PVUSBURB pUrb, const char *pszMsg, bool fComplete)
157{
158 PVUSBDEV pDev = pUrb->pVUsb ? pUrb->pVUsb->pDev : NULL; /* Can be NULL when called from usbProxyConstruct and friends. */
159 PVUSBPIPE pPipe = &pDev->aPipes[pUrb->EndPt];
160 const uint8_t *pbData = pUrb->abData;
161 uint32_t cbData = pUrb->cbData;
162 PCVUSBSETUP pSetup = NULL;
163 bool fDescriptors = false;
164 static size_t s_cchMaxMsg = 10;
165 size_t cchMsg = strlen(pszMsg);
166 if (cchMsg > s_cchMaxMsg)
167 s_cchMaxMsg = cchMsg;
168
169 Log(("%s: %*s: pDev=%p[%s] rc=%s a=%i e=%u d=%s t=%s cb=%#x(%d) ts=%RU64 (%RU64 ns ago) %s\n",
170 pUrb->pszDesc, s_cchMaxMsg, pszMsg,
171 pDev,
172 pUrb->pVUsb && pUrb->pVUsb->pDev ? pUrb->pVUsb->pDev->pUsbIns->pszName : "",
173 vusbUrbStatusName(pUrb->enmStatus),
174 pDev ? pDev->u8Address : -1,
175 pUrb->EndPt,
176 vusbUrbDirName(pUrb->enmDir),
177 vusbUrbTypeName(pUrb->enmType),
178 pUrb->cbData,
179 pUrb->cbData,
180 pUrb->pVUsb ? pUrb->pVUsb->u64SubmitTS : 0,
181 pUrb->pVUsb ? RTTimeNanoTS() - pUrb->pVUsb->u64SubmitTS : 0,
182 pUrb->fShortNotOk ? "ShortNotOk" : "ShortOk"));
183
184#ifndef DEBUG_bird
185 if ( pUrb->enmType == VUSBXFERTYPE_CTRL
186 && pUrb->enmStatus == VUSBSTATUS_OK)
187 return;
188#endif
189
190 if ( pUrb->enmType == VUSBXFERTYPE_MSG
191 || ( pUrb->enmDir == VUSBDIRECTION_SETUP
192 && pUrb->enmType == VUSBXFERTYPE_CTRL
193 && cbData))
194 {
195 static const char * const s_apszReqDirs[] = {"host2dev", "dev2host"};
196 static const char * const s_apszReqTypes[] = {"std", "class", "vendor", "reserved"};
197 static const char * const s_apszReqRecipients[] = {"dev", "if", "endpoint", "other"};
198 static const char * const s_apszRequests[] =
199 {
200 "GET_STATUS", "CLEAR_FEATURE", "2?", "SET_FEATURE",
201 "4?", "SET_ADDRESS", "GET_DESCRIPTOR", "SET_DESCRIPTOR",
202 "GET_CONFIGURATION", "SET_CONFIGURATION", "GET_INTERFACE", "SET_INTERFACE",
203 "SYNCH_FRAME"
204 };
205 pSetup = (PVUSBSETUP)pUrb->abData;
206 pbData += sizeof(*pSetup);
207 cbData -= sizeof(*pSetup);
208
209 Log(("%s: %*s: CTRL: bmRequestType=0x%.2x (%s %s %s) bRequest=0x%.2x (%s) wValue=0x%.4x wIndex=0x%.4x wLength=0x%.4x\n",
210 pUrb->pszDesc, s_cchMaxMsg, pszMsg,
211 pSetup->bmRequestType, s_apszReqDirs[pSetup->bmRequestType >> 7], s_apszReqTypes[(pSetup->bmRequestType >> 5) & 0x3],
212 (unsigned)(pSetup->bmRequestType & 0xf) < RT_ELEMENTS(s_apszReqRecipients) ? s_apszReqRecipients[pSetup->bmRequestType & 0xf] : "??",
213 pSetup->bRequest, pSetup->bRequest < RT_ELEMENTS(s_apszRequests) ? s_apszRequests[pSetup->bRequest] : "??",
214 pSetup->wValue, pSetup->wIndex, pSetup->wLength));
215
216 if ( pSetup->bRequest == VUSB_REQ_GET_DESCRIPTOR
217 && fComplete
218 && pUrb->enmStatus == VUSBSTATUS_OK
219 && ((pSetup->bmRequestType >> 5) & 0x3) < 2 /* vendor */)
220 fDescriptors = true;
221 }
222 else if ( fComplete
223 && pUrb->enmDir == VUSBDIRECTION_IN
224 && pUrb->enmType == VUSBXFERTYPE_CTRL
225 && pUrb->enmStatus == VUSBSTATUS_OK
226 && pPipe->pCtrl
227 && pPipe->pCtrl->enmStage == CTLSTAGE_DATA
228 && cbData > 0)
229 {
230 pSetup = pPipe->pCtrl->pMsg;
231 if (pSetup->bRequest == VUSB_REQ_GET_DESCRIPTOR)
232 fDescriptors = true;
233 }
234
235 /*
236 * Dump descriptors.
237 */
238 if (fDescriptors)
239 {
240 const uint8_t *pb = pbData;
241 const uint8_t *pbEnd = pbData + cbData;
242 while (pb + 1 < pbEnd)
243 {
244 const unsigned cbLeft = pbEnd - pb;
245 const unsigned cbLength = *pb;
246 unsigned cb = cbLength;
247 uint8_t bDescriptorType = pb[1];
248
249 /* length out of bounds? */
250 if (cbLength > cbLeft)
251 {
252 cb = cbLeft;
253 if (cbLength != 0xff) /* ignore this */
254 Log(("URB: %*s: DESC: warning descriptor length goes beyond the end of the URB! cbLength=%d cbLeft=%d\n",
255 s_cchMaxMsg, pszMsg, cbLength, cbLeft));
256 }
257
258 if (cb >= 2)
259 {
260 Log(("URB: %*s: DESC: %04x: %25s = %#04x (%d)\n"
261 "URB: %*s: %04x: %25s = %#04x (",
262 s_cchMaxMsg, pszMsg, pb - pbData, "bLength", cbLength, cbLength,
263 s_cchMaxMsg, pszMsg, pb - pbData + 1, "bDescriptorType", bDescriptorType));
264
265 #pragma pack(1)
266 #define BYTE_FIELD(strct, memb) \
267 if ((unsigned)RT_OFFSETOF(strct, memb) < cb) \
268 Log(("URB: %*s: %04x: %25s = %#04x\n", s_cchMaxMsg, pszMsg, \
269 pb + RT_OFFSETOF(strct, memb) - pbData, #memb, pb[RT_OFFSETOF(strct, memb)]))
270 #define BYTE_FIELD_START(strct, memb) do { \
271 if ((unsigned)RT_OFFSETOF(strct, memb) < cb) \
272 { \
273 Log(("URB: %*s: %04x: %25s = %#04x", s_cchMaxMsg, pszMsg, \
274 pb + RT_OFFSETOF(strct, memb) - pbData, #memb, pb[RT_OFFSETOF(strct, memb)]))
275 #define BYTE_FIELD_END(strct, memb) \
276 Log(("\n")); \
277 } } while (0)
278 #define WORD_FIELD(strct, memb) \
279 if ((unsigned)RT_OFFSETOF(strct, memb) + 1 < cb) \
280 Log(("URB: %*s: %04x: %25s = %#06x\n", s_cchMaxMsg, pszMsg, \
281 pb + RT_OFFSETOF(strct, memb) - pbData, #memb, *(uint16_t *)&pb[RT_OFFSETOF(strct, memb)]))
282 #define BCD_FIELD(strct, memb) \
283 if ((unsigned)RT_OFFSETOF(strct, memb) + 1 < cb) \
284 Log(("URB: %*s: %04x: %25s = %#06x (%02x.%02x)\n", s_cchMaxMsg, pszMsg, \
285 pb + RT_OFFSETOF(strct, memb) - pbData, #memb, *(uint16_t *)&pb[RT_OFFSETOF(strct, memb)], \
286 pb[RT_OFFSETOF(strct, memb) + 1], pb[RT_OFFSETOF(strct, memb)]))
287 #define SIZE_CHECK(strct) \
288 if (cb > sizeof(strct)) \
289 Log(("URB: %*s: %04x: WARNING %d extra byte(s) %.*Rhxs\n", s_cchMaxMsg, pszMsg, \
290 pb + sizeof(strct) - pbData, cb - sizeof(strct), cb - sizeof(strct), pb + sizeof(strct))); \
291 else if (cb < sizeof(strct)) \
292 Log(("URB: %*s: %04x: WARNING %d missing byte(s)! Expected size %d.\n", s_cchMaxMsg, pszMsg, \
293 pb + cb - pbData, sizeof(strct) - cb, sizeof(strct)))
294
295 /* on type */
296 switch (bDescriptorType)
297 {
298 case VUSB_DT_DEVICE:
299 {
300 struct dev_desc
301 {
302 uint8_t bLength;
303 uint8_t bDescriptorType;
304 uint16_t bcdUSB;
305 uint8_t bDeviceClass;
306 uint8_t bDeviceSubClass;
307 uint8_t bDeviceProtocol;
308 uint8_t bMaxPacketSize0;
309 uint16_t idVendor;
310 uint16_t idProduct;
311 uint16_t bcdDevice;
312 uint8_t iManufacturer;
313 uint8_t iProduct;
314 uint8_t iSerialNumber;
315 uint8_t bNumConfigurations;
316 } *pDesc = (struct dev_desc *)pb; NOREF(pDesc);
317 Log(("DEV)\n"));
318 BCD_FIELD( struct dev_desc, bcdUSB);
319 BYTE_FIELD(struct dev_desc, bDeviceClass);
320 BYTE_FIELD(struct dev_desc, bDeviceSubClass);
321 BYTE_FIELD(struct dev_desc, bDeviceProtocol);
322 BYTE_FIELD(struct dev_desc, bMaxPacketSize0);
323 WORD_FIELD(struct dev_desc, idVendor);
324 WORD_FIELD(struct dev_desc, idProduct);
325 BCD_FIELD( struct dev_desc, bcdDevice);
326 BYTE_FIELD(struct dev_desc, iManufacturer);
327 BYTE_FIELD(struct dev_desc, iProduct);
328 BYTE_FIELD(struct dev_desc, iSerialNumber);
329 BYTE_FIELD(struct dev_desc, bNumConfigurations);
330 SIZE_CHECK(struct dev_desc);
331 break;
332 }
333
334 case VUSB_DT_CONFIG:
335 {
336 struct cfg_desc
337 {
338 uint8_t bLength;
339 uint8_t bDescriptorType;
340 uint16_t wTotalLength;
341 uint8_t bNumInterfaces;
342 uint8_t bConfigurationValue;
343 uint8_t iConfiguration;
344 uint8_t bmAttributes;
345 uint8_t MaxPower;
346 } *pDesc = (struct cfg_desc *)pb; NOREF(pDesc);
347 Log(("CFG)\n"));
348 WORD_FIELD(struct cfg_desc, wTotalLength);
349 BYTE_FIELD(struct cfg_desc, bNumInterfaces);
350 BYTE_FIELD(struct cfg_desc, bConfigurationValue);
351 BYTE_FIELD(struct cfg_desc, iConfiguration);
352 BYTE_FIELD_START(struct cfg_desc, bmAttributes);
353 static const char * const s_apszTransType[4] = { "Control", "Isochronous", "Bulk", "Interrupt" };
354 static const char * const s_apszSyncType[4] = { "NoSync", "Asynchronous", "Adaptive", "Synchronous" };
355 static const char * const s_apszUsageType[4] = { "Data ep", "Feedback ep.", "Implicit feedback Data ep.", "Reserved" };
356 Log((" %s - %s - %s", s_apszTransType[(pDesc->bmAttributes & 0x3)],
357 s_apszSyncType[((pDesc->bmAttributes >> 2) & 0x3)], s_apszUsageType[((pDesc->bmAttributes >> 4) & 0x3)]));
358 BYTE_FIELD_END(struct cfg_desc, bmAttributes);
359 BYTE_FIELD(struct cfg_desc, MaxPower);
360 SIZE_CHECK(struct cfg_desc);
361 break;
362 }
363
364 case VUSB_DT_STRING:
365 if (!pSetup->wIndex)
366 {
367 /* langid array */
368 uint16_t *pu16 = (uint16_t *)pb + 1;
369 Log(("LANGIDs)\n"));
370 while ((uintptr_t)pu16 + 2 - (uintptr_t)pb <= cb)
371 {
372 Log(("URB: %*s: %04x: wLANGID[%#x] = %#06x\n",
373 s_cchMaxMsg, pszMsg, (uint8_t *)pu16 - pbData, pu16 - (uint16_t *)pb, *pu16));
374 pu16++;
375 }
376 if (cb & 1)
377 Log(("URB: %*s: %04x: WARNING descriptor size is odd! extra byte: %02\n",
378 s_cchMaxMsg, pszMsg, (uint8_t *)pu16 - pbData, *(uint8_t *)pu16));
379 }
380 else
381 {
382 /** a string. */
383 Log(("STRING)\n"));
384 if (cb > 2)
385 Log(("URB: %*s: %04x: Length=%d String=%.*ls\n",
386 s_cchMaxMsg, pszMsg, pb - pbData, cb - 2, cb / 2 - 1, pb + 2));
387 else
388 Log(("URB: %*s: %04x: Length=0!\n", s_cchMaxMsg, pszMsg, pb - pbData));
389 }
390 break;
391
392 case VUSB_DT_INTERFACE:
393 {
394 struct if_desc
395 {
396 uint8_t bLength;
397 uint8_t bDescriptorType;
398 uint8_t bInterfaceNumber;
399 uint8_t bAlternateSetting;
400 uint8_t bNumEndpoints;
401 uint8_t bInterfaceClass;
402 uint8_t bInterfaceSubClass;
403 uint8_t bInterfaceProtocol;
404 uint8_t iInterface;
405 } *pDesc = (struct if_desc *)pb; NOREF(pDesc);
406 Log(("IF)\n"));
407 BYTE_FIELD(struct if_desc, bInterfaceNumber);
408 BYTE_FIELD(struct if_desc, bAlternateSetting);
409 BYTE_FIELD(struct if_desc, bNumEndpoints);
410 BYTE_FIELD(struct if_desc, bInterfaceClass);
411 BYTE_FIELD(struct if_desc, bInterfaceSubClass);
412 BYTE_FIELD(struct if_desc, bInterfaceProtocol);
413 BYTE_FIELD(struct if_desc, iInterface);
414 SIZE_CHECK(struct if_desc);
415 break;
416 }
417
418 case VUSB_DT_ENDPOINT:
419 {
420 struct ep_desc
421 {
422 uint8_t bLength;
423 uint8_t bDescriptorType;
424 uint8_t bEndpointAddress;
425 uint8_t bmAttributes;
426 uint16_t wMaxPacketSize;
427 uint8_t bInterval;
428 } *pDesc = (struct ep_desc *)pb; NOREF(pDesc);
429 Log(("EP)\n"));
430 BYTE_FIELD(struct ep_desc, bEndpointAddress);
431 BYTE_FIELD(struct ep_desc, bmAttributes);
432 WORD_FIELD(struct ep_desc, wMaxPacketSize);
433 BYTE_FIELD(struct ep_desc, bInterval);
434 SIZE_CHECK(struct ep_desc);
435 break;
436 }
437
438 case VUSB_DT_DEVICE_QUALIFIER:
439 {
440 struct dq_desc
441 {
442 uint8_t bLength;
443 uint8_t bDescriptorType;
444 uint16_t bcdUSB;
445 uint8_t bDeviceClass;
446 uint8_t bDeviceSubClass;
447 uint8_t bDeviceProtocol;
448 uint8_t bMaxPacketSize0;
449 uint8_t bNumConfigurations;
450 uint8_t bReserved;
451 } *pDQDesc = (struct dq_desc *)pb; NOREF(pDQDesc);
452 Log(("DEVQ)\n"));
453 BCD_FIELD( struct dq_desc, bcdUSB);
454 BYTE_FIELD(struct dq_desc, bDeviceClass);
455 BYTE_FIELD(struct dq_desc, bDeviceSubClass);
456 BYTE_FIELD(struct dq_desc, bDeviceProtocol);
457 BYTE_FIELD(struct dq_desc, bMaxPacketSize0);
458 BYTE_FIELD(struct dq_desc, bNumConfigurations);
459 BYTE_FIELD(struct dq_desc, bReserved);
460 SIZE_CHECK(struct dq_desc);
461 break;
462 }
463
464 case VUSB_DT_OTHER_SPEED_CFG:
465 {
466 struct oth_cfg_desc
467 {
468 uint8_t bLength;
469 uint8_t bDescriptorType;
470 uint16_t wTotalLength;
471 uint8_t bNumInterfaces;
472 uint8_t bConfigurationValue;
473 uint8_t iConfiguration;
474 uint8_t bmAttributes;
475 uint8_t MaxPower;
476 } *pDesc = (struct oth_cfg_desc *)pb; NOREF(pDesc);
477 Log(("OCFG)\n"));
478 WORD_FIELD(struct oth_cfg_desc, wTotalLength);
479 BYTE_FIELD(struct oth_cfg_desc, bNumInterfaces);
480 BYTE_FIELD(struct oth_cfg_desc, bConfigurationValue);
481 BYTE_FIELD(struct oth_cfg_desc, iConfiguration);
482 BYTE_FIELD_START(struct oth_cfg_desc, bmAttributes);
483 static const char * const s_apszTransType[4] = { "Control", "Isochronous", "Bulk", "Interrupt" };
484 static const char * const s_apszSyncType[4] = { "NoSync", "Asynchronous", "Adaptive", "Synchronous" };
485 static const char * const s_apszUsageType[4] = { "Data ep", "Feedback ep.", "Implicit feedback Data ep.", "Reserved" };
486 Log((" %s - %s - %s", s_apszTransType[(pDesc->bmAttributes & 0x3)],
487 s_apszSyncType[((pDesc->bmAttributes >> 2) & 0x3)], s_apszUsageType[((pDesc->bmAttributes >> 4) & 0x3)]));
488 BYTE_FIELD_END(struct oth_cfg_desc, bmAttributes);
489 BYTE_FIELD(struct oth_cfg_desc, MaxPower);
490 SIZE_CHECK(struct oth_cfg_desc);
491 break;
492 }
493
494 case 0x21:
495 {
496 struct hid_desc
497 {
498 uint8_t bLength;
499 uint8_t bDescriptorType;
500 uint16_t bcdHid;
501 uint8_t bCountry;
502 uint8_t bNumDescriptors;
503 uint8_t bReportType;
504 uint16_t wReportLength;
505 } *pDesc = (struct hid_desc *)pb; NOREF(pDesc);
506 Log(("EP)\n"));
507 BCD_FIELD( struct hid_desc, bcdHid);
508 BYTE_FIELD(struct hid_desc, bCountry);
509 BYTE_FIELD(struct hid_desc, bNumDescriptors);
510 BYTE_FIELD(struct hid_desc, bReportType);
511 WORD_FIELD(struct hid_desc, wReportLength);
512 SIZE_CHECK(struct hid_desc);
513 break;
514 }
515
516 case 0xff:
517 Log(("UNKNOWN-ignore)\n"));
518 break;
519
520 default:
521 Log(("UNKNOWN)!!!\n"));
522 break;
523 }
524
525 #undef BYTE_FIELD
526 #undef WORD_FIELD
527 #undef BCD_FIELD
528 #undef SIZE_CHECK
529 #pragma pack()
530 }
531 else
532 {
533 Log(("URB: %*s: DESC: %04x: bLength=%d bDescriptorType=%d - invalid length\n",
534 s_cchMaxMsg, pszMsg, pb - pbData, cb, bDescriptorType));
535 break;
536 }
537
538 /* next */
539 pb += cb;
540 }
541 }
542
543 /*
544 * SCSI
545 */
546 if ( pUrb->enmType == VUSBXFERTYPE_BULK
547 && pUrb->enmDir == VUSBDIRECTION_OUT
548 && pUrb->cbData >= 12
549 && !memcmp(pUrb->abData, "USBC", 4))
550 {
551 const struct usbc
552 {
553 uint32_t Signature;
554 uint32_t Tag;
555 uint32_t DataTransferLength;
556 uint8_t Flags;
557 uint8_t Lun;
558 uint8_t Length;
559 uint8_t CDB[13];
560 } *pUsbC = (struct usbc *)pUrb->abData;
561 Log(("URB: %*s: SCSI: Tag=%#x DataTransferLength=%#x Flags=%#x Lun=%#x Length=%#x CDB=%.*Rhxs\n",
562 s_cchMaxMsg, pszMsg, pUsbC->Tag, pUsbC->DataTransferLength, pUsbC->Flags, pUsbC->Lun,
563 pUsbC->Length, pUsbC->Length, pUsbC->CDB));
564 const uint8_t *pb = &pUsbC->CDB[0];
565 switch (pb[0])
566 {
567 case 0x00: /* test unit read */
568 Log(("URB: %*s: SCSI: TEST_UNIT_READY LUN=%d Ctrl=%#RX8\n",
569 s_cchMaxMsg, pszMsg, pb[1] >> 5, pb[5]));
570 break;
571 case 0x03: /* Request Sense command */
572 Log(("URB: %*s: SCSI: REQUEST_SENSE LUN=%d AlcLen=%#RX16 Ctrl=%#RX8\n",
573 s_cchMaxMsg, pszMsg, pb[1] >> 5, pb[4], pb[5]));
574 break;
575 case 0x12: /* Inquiry command. */
576 Log(("URB: %*s: SCSI: INQUIRY EVPD=%d LUN=%d PgCd=%#RX8 AlcLen=%#RX8 Ctrl=%#RX8\n",
577 s_cchMaxMsg, pszMsg, pb[1] & 1, pb[1] >> 5, pb[2], pb[4], pb[5]));
578 break;
579 case 0x1a: /* Mode Sense(6) command */
580 Log(("URB: %*s: SCSI: MODE_SENSE6 LUN=%d DBD=%d PC=%d PgCd=%#RX8 AlcLen=%#RX8 Ctrl=%#RX8\n",
581 s_cchMaxMsg, pszMsg, pb[1] >> 5, !!(pb[1] & RT_BIT(3)), pb[2] >> 6, pb[2] & 0x3f, pb[4], pb[5]));
582 break;
583 case 0x5a:
584 Log(("URB: %*s: SCSI: MODE_SENSE10 LUN=%d DBD=%d PC=%d PgCd=%#RX8 AlcLen=%#RX16 Ctrl=%#RX8\n",
585 s_cchMaxMsg, pszMsg, pb[1] >> 5, !!(pb[1] & RT_BIT(3)), pb[2] >> 6, pb[2] & 0x3f,
586 RT_MAKE_U16(pb[8], pb[7]), pb[9]));
587 break;
588 case 0x25: /* Read Capacity(6) command. */
589 Log(("URB: %*s: SCSI: READ_CAPACITY\n",
590 s_cchMaxMsg, pszMsg));
591 break;
592 case 0x28: /* Read(10) command. */
593 Log(("URB: %*s: SCSI: READ10 RelAdr=%d FUA=%d DPO=%d LUN=%d LBA=%#RX32 Len=%#RX16 Ctrl=%#RX8\n",
594 s_cchMaxMsg, pszMsg,
595 pb[1] & 1, !!(pb[1] & RT_BIT(3)), !!(pb[1] & RT_BIT(4)), pb[1] >> 5,
596 RT_MAKE_U32_FROM_U8(pb[5], pb[4], pb[3], pb[2]),
597 RT_MAKE_U16(pb[8], pb[7]), pb[9]));
598 break;
599 case 0xa8: /* Read(12) command. */
600 Log(("URB: %*s: SCSI: READ12 RelAdr=%d FUA=%d DPO=%d LUN=%d LBA=%#RX32 Len=%#RX32 Ctrl=%#RX8\n",
601 s_cchMaxMsg, pszMsg,
602 pb[1] & 1, !!(pb[1] & RT_BIT(3)), !!(pb[1] & RT_BIT(4)), pb[1] >> 5,
603 RT_MAKE_U32_FROM_U8(pb[5], pb[4], pb[3], pb[2]),
604 RT_MAKE_U32_FROM_U8(pb[9], pb[8], pb[7], pb[6]),
605 pb[11]));
606 break;
607 case 0x3e: /* Read Long command. */
608 Log(("URB: %*s: SCSI: READ LONG RelAdr=%d Correct=%d LUN=%d LBA=%#RX16 ByteLen=%#RX16 Ctrl=%#RX8\n",
609 s_cchMaxMsg, pszMsg,
610 pb[1] & 1, !!(pb[1] & RT_BIT(1)), pb[1] >> 5,
611 RT_MAKE_U16(pb[3], pb[2]), RT_MAKE_U16(pb[6], pb[5]),
612 pb[11]));
613 break;
614 case 0x2a: /* Write(10) command. */
615 Log(("URB: %*s: SCSI: WRITE10 RelAdr=%d EBP=%d FUA=%d DPO=%d LUN=%d LBA=%#RX32 Len=%#RX16 Ctrl=%#RX8\n",
616 s_cchMaxMsg, pszMsg,
617 pb[1] & 1, !!(pb[1] & RT_BIT(2)), !!(pb[1] & RT_BIT(3)),
618 !!(pb[1] & RT_BIT(4)), pb[1] >> 5,
619 RT_MAKE_U32_FROM_U8(pb[5], pb[4], pb[3], pb[2]),
620 RT_MAKE_U16(pb[8], pb[7]), pb[9]));
621 break;
622 case 0xaa: /* Write(12) command. */
623 Log(("URB: %*s: SCSI: WRITE12 RelAdr=%d EBP=%d FUA=%d DPO=%d LUN=%d LBA=%#RX32 Len=%#RX32 Ctrl=%#RX8\n",
624 s_cchMaxMsg, pszMsg,
625 pb[1] & 1, !!(pb[1] & RT_BIT(3)), !!(pb[1] & RT_BIT(4)),
626 !!(pb[1] & RT_BIT(4)), pb[1] >> 5,
627 RT_MAKE_U32_FROM_U8(pb[5], pb[4], pb[3], pb[2]),
628 RT_MAKE_U32_FROM_U8(pb[9], pb[8], pb[7], pb[6]),
629 pb[11]));
630 break;
631 case 0x3f: /* Write Long command. */
632 Log(("URB: %*s: SCSI: WRITE LONG RelAdr=%d LUN=%d LBA=%#RX16 ByteLen=%#RX16 Ctrl=%#RX8\n",
633 s_cchMaxMsg, pszMsg,
634 pb[1] & 1, pb[1] >> 5,
635 RT_MAKE_U16(pb[3], pb[2]), RT_MAKE_U16(pb[6], pb[5]),
636 pb[11]));
637 break;
638 case 0x35: /* Synchronize Cache(10) command. */
639 Log(("URB: %*s: SCSI: SYNCHRONIZE_CACHE10\n",
640 s_cchMaxMsg, pszMsg));
641 break;
642 case 0xa0: /* Report LUNs command. */
643 Log(("URB: %*s: SCSI: REPORT_LUNS\n",
644 s_cchMaxMsg, pszMsg));
645 break;
646 default:
647 Log(("URB: %*s: SCSI: cmd=%#x\n",
648 s_cchMaxMsg, pszMsg, pb[0]));
649 break;
650 }
651 if (pDev)
652 pDev->Urb.u8ScsiCmd = pb[0];
653 }
654 else if ( fComplete
655 && pUrb->enmType == VUSBXFERTYPE_BULK
656 && pUrb->enmDir == VUSBDIRECTION_IN
657 && pUrb->cbData >= 12
658 && !memcmp(pUrb->abData, "USBS", 4))
659 {
660 const struct usbs
661 {
662 uint32_t Signature;
663 uint32_t Tag;
664 uint32_t DataResidue;
665 uint8_t Status;
666 uint8_t CDB[3];
667 } *pUsbS = (struct usbs *)pUrb->abData;
668 static const char * const s_apszStatuses[] = { "PASSED", "FAILED", "PHASE ERROR", "RESERVED" };
669 Log(("URB: %*s: SCSI: Tag=%#x DataResidue=%#RX32 Status=%#RX8 %s\n",
670 s_cchMaxMsg, pszMsg, pUsbS->Tag, pUsbS->DataResidue, pUsbS->Status,
671 s_apszStatuses[pUsbS->Status < RT_ELEMENTS(s_apszStatuses) ? pUsbS->Status : RT_ELEMENTS(s_apszStatuses) - 1]));
672 if (pDev)
673 pDev->Urb.u8ScsiCmd = 0xff;
674 }
675 else if ( fComplete
676 && pUrb->enmType == VUSBXFERTYPE_BULK
677 && pUrb->enmDir == VUSBDIRECTION_IN
678 && pDev
679 && pDev->Urb.u8ScsiCmd != 0xff)
680 {
681 const uint8_t *pb = pUrb->abData;
682 switch (pDev->Urb.u8ScsiCmd)
683 {
684 case 0x03: /* REQUEST_SENSE */
685 Log(("URB: %*s: SCSI: RESPONSE: REQUEST_SENSE (%s)\n",
686 s_cchMaxMsg, pszMsg, pb[0] & 7 ? "scsi compliant" : "not scsi compliant"));
687 Log(("URB: %*s: SCSI: ErrCd=%#RX8 (%s) Seg=%#RX8 Filemark=%d EOM=%d ILI=%d\n",
688 s_cchMaxMsg, pszMsg, pb[0] & 0x7f, GetScsiErrCd(pb[0] & 0x7f), pb[1],
689 pb[2] >> 7, !!(pb[2] & RT_BIT(6)), !!(pb[2] & RT_BIT(5))));
690 Log(("URB: %*s: SCSI: SenseKey=%#x ASC=%#RX8 ASCQ=%#RX8 : %s\n",
691 s_cchMaxMsg, pszMsg, pb[2] & 0xf, pb[12], pb[13],
692 GetScsiKCQ(pb[2] & 0xf, pb[12], pb[13])));
693 /** @todo more later */
694 break;
695
696 case 0x12: /* INQUIRY. */
697 {
698 unsigned cb = pb[4] + 5;
699 Log(("URB: %*s: SCSI: RESPONSE: INQUIRY\n"
700 "URB: %*s: SCSI: PeripheralQualifier=%d PeripheralType=%#RX8 RMB=%d DevTypeMod=%#RX8\n",
701 s_cchMaxMsg, pszMsg, s_cchMaxMsg, pszMsg,
702 pb[0] >> 5, pb[0] & 0x1f, pb[1] >> 7, pb[1] & 0x7f));
703 Log(("URB: %*s: SCSI: ISOVer=%d ECMAVer=%d ANSIVer=%d\n",
704 s_cchMaxMsg, pszMsg, pb[2] >> 6, (pb[2] >> 3) & 7, pb[2] & 7));
705 Log(("URB: %*s: SCSI: AENC=%d TrmlOP=%d RespDataFmt=%d (%s) AddLen=%d\n",
706 s_cchMaxMsg, pszMsg, pb[3] >> 7, (pb[3] >> 6) & 1,
707 pb[3] & 0xf, pb[3] & 0xf ? "legacy" : "scsi", pb[4]));
708 if (cb < 8)
709 break;
710 Log(("URB: %*s: SCSI: RelAdr=%d WBus32=%d WBus16=%d Sync=%d Linked=%d CmdQue=%d SftRe=%d\n",
711 s_cchMaxMsg, pszMsg, pb[7] >> 7, !!(pb[7] >> 6), !!(pb[7] >> 5), !!(pb[7] >> 4),
712 !!(pb[7] >> 3), !!(pb[7] >> 1), pb[7] & 1));
713 if (cb < 16)
714 break;
715 Log(("URB: %*s: SCSI: VendorId=%.8s\n", s_cchMaxMsg, pszMsg, &pb[8]));
716 if (cb < 32)
717 break;
718 Log(("URB: %*s: SCSI: ProductId=%.16s\n", s_cchMaxMsg, pszMsg, &pb[16]));
719 if (cb < 36)
720 break;
721 Log(("URB: %*s: SCSI: ProdRevLvl=%.4s\n", s_cchMaxMsg, pszMsg, &pb[32]));
722 if (cb > 36)
723 Log(("URB: %*s: SCSI: VendorSpecific=%.*s\n",
724 s_cchMaxMsg, pszMsg, RT_MIN(cb - 36, 20), &pb[36]));
725 if (cb > 96)
726 Log(("URB: %*s: SCSI: VendorParam=%.*Rhxs\n",
727 s_cchMaxMsg, pszMsg, cb - 96, &pb[96]));
728 break;
729 }
730
731 case 0x25: /* Read Capacity(6) command. */
732 Log(("URB: %*s: SCSI: RESPONSE: READ_CAPACITY\n"
733 "URB: %*s: SCSI: LBA=%#RX32 BlockLen=%#RX32\n",
734 s_cchMaxMsg, pszMsg, s_cchMaxMsg, pszMsg,
735 RT_MAKE_U32_FROM_U8(pb[3], pb[2], pb[1], pb[0]),
736 RT_MAKE_U32_FROM_U8(pb[7], pb[6], pb[5], pb[4])));
737 break;
738 }
739
740 pDev->Urb.u8ScsiCmd = 0xff;
741 }
742
743 /*
744 * The Quickcam control pipe.
745 */
746 if ( pSetup
747 && ((pSetup->bmRequestType >> 5) & 0x3) >= 2 /* vendor */
748 && (fComplete || !(pSetup->bmRequestType >> 7))
749 && pDev
750 && pDev->pDescCache
751 && pDev->pDescCache->pDevice
752 && pDev->pDescCache->pDevice->idVendor == 0x046d
753 && ( pDev->pDescCache->pDevice->idProduct == 0x8f6
754 || pDev->pDescCache->pDevice->idProduct == 0x8f5
755 || pDev->pDescCache->pDevice->idProduct == 0x8f0)
756 )
757 {
758 pbData = (const uint8_t *)(pSetup + 1);
759 cbData = pUrb->cbData - sizeof(*pSetup);
760
761 if ( pSetup->bRequest == 0x04
762 && pSetup->wIndex == 0
763 && (cbData == 1 || cbData == 2))
764 {
765 /* the value */
766 unsigned uVal = pbData[0];
767 if (cbData > 1)
768 uVal |= (unsigned)pbData[1] << 8;
769
770 const char *pszReg = NULL;
771 switch (pSetup->wValue)
772 {
773 case 0: pszReg = "i2c init"; break;
774 case 0x0423: pszReg = "STV_REG23"; break;
775 case 0x0509: pszReg = "RED something"; break;
776 case 0x050a: pszReg = "GREEN something"; break;
777 case 0x050b: pszReg = "BLUE something"; break;
778 case 0x143f: pszReg = "COMMIT? INIT DONE?"; break;
779 case 0x1440: pszReg = "STV_ISO_ENABLE"; break;
780 case 0x1442: pszReg = uVal & (RT_BIT(7)|RT_BIT(5)) ? "BUTTON PRESSED" : "BUTTON" ; break;
781 case 0x1443: pszReg = "STV_SCAN_RATE"; break;
782 case 0x1445: pszReg = "LED?"; break;
783 case 0x1500: pszReg = "STV_REG00"; break;
784 case 0x1501: pszReg = "STV_REG01"; break;
785 case 0x1502: pszReg = "STV_REG02"; break;
786 case 0x1503: pszReg = "STV_REG03"; break;
787 case 0x1504: pszReg = "STV_REG04"; break;
788 case 0x15c1: pszReg = "STV_ISO_SIZE"; break;
789 case 0x15c3: pszReg = "STV_Y_CTRL"; break;
790 case 0x1680: pszReg = "STV_X_CTRL"; break;
791 case 0xe00a: pszReg = "ProductId"; break;
792 default: pszReg = "[no clue]"; break;
793 }
794 if (pszReg)
795 Log(("URB: %*s: QUICKCAM: %s %#x (%d) %s '%s' (%#x)\n",
796 s_cchMaxMsg, pszMsg,
797 (pSetup->bmRequestType >> 7) ? "read" : "write", uVal, uVal, (pSetup->bmRequestType >> 7) ? "from" : "to",
798 pszReg, pSetup->wValue));
799 }
800 else if (cbData)
801 Log(("URB: %*s: QUICKCAM: Unknown request: bRequest=%#x bmRequestType=%#x wValue=%#x wIndex=%#x: %.*Rhxs\n", s_cchMaxMsg, pszMsg,
802 pSetup->bRequest, pSetup->bmRequestType, pSetup->wValue, pSetup->wIndex, cbData, pbData));
803 else
804 Log(("URB: %*s: QUICKCAM: Unknown request: bRequest=%#x bmRequestType=%#x wValue=%#x wIndex=%#x: (no data)\n", s_cchMaxMsg, pszMsg,
805 pSetup->bRequest, pSetup->bmRequestType, pSetup->wValue, pSetup->wIndex));
806 }
807
808#if 1
809 if ( cbData /** @todo Fix RTStrFormatV to communicate .* so formatter doesn't apply defaults when cbData=0. */
810 && (fComplete
811 ? pUrb->enmDir != VUSBDIRECTION_OUT
812 : pUrb->enmDir == VUSBDIRECTION_OUT))
813 Log3(("%16.*Rhxd\n", cbData, pbData));
814#endif
815 if (pUrb->enmType == VUSBXFERTYPE_MSG && pUrb->pVUsb && pUrb->pVUsb->pCtrlUrb)
816 vusbUrbTrace(pUrb->pVUsb->pCtrlUrb, "NESTED MSG", fComplete);
817}
818#endif /* LOG_ENABLED */
819
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette