Changeset 50794 in vbox for trunk/src/VBox/HostDrivers/VBoxUSB
- Timestamp:
- Mar 14, 2014 11:29:38 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxUSB/win/lib/VBoxUsbLib-win.cpp
r44529 r50794 5 5 6 6 /* 7 * Copyright (C) 2011-201 2Oracle Corporation7 * Copyright (C) 2011-2014 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 582 582 static int usbLibDevStrDrEntryGet(HANDLE hHub, ULONG iPort, ULONG iDr, USHORT idLang, PVBOXUSB_STRING_DR_ENTRY *ppList) 583 583 { 584 char Buf[sizeof (USB_DESCRIPTOR_REQUEST) + MAXIMUM_USB_STRING_LENGTH]; 585 PUSB_DESCRIPTOR_REQUEST pRq = (PUSB_DESCRIPTOR_REQUEST)Buf; 586 PUSB_STRING_DESCRIPTOR pDr = (PUSB_STRING_DESCRIPTOR)(Buf + sizeof (*pRq)); 587 memset (&Buf, 0, sizeof (Buf)); 584 char szBuf[sizeof (USB_DESCRIPTOR_REQUEST) + MAXIMUM_USB_STRING_LENGTH]; 585 RT_ZERO(szBuf); 586 587 PUSB_DESCRIPTOR_REQUEST pRq = (PUSB_DESCRIPTOR_REQUEST)szBuf; 588 PUSB_STRING_DESCRIPTOR pDr = (PUSB_STRING_DESCRIPTOR)(szBuf + sizeof (*pRq)); 589 RT_BZERO(pDr, sizeof(USB_STRING_DESCRIPTOR)); 590 588 591 pRq->ConnectionIndex = iPort; 589 592 pRq->SetupPacket.wValue = (USB_STRING_DESCRIPTOR_TYPE << 8) | iDr; 590 593 pRq->SetupPacket.wIndex = idLang; 591 pRq->SetupPacket.wLength = sizeof (Buf) - sizeof (*pRq); 594 pRq->SetupPacket.wLength = sizeof (szBuf) - sizeof (*pRq); 595 592 596 DWORD cbReturned = 0; 593 if (!DeviceIoControl(hHub, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, pRq, sizeof (Buf), 594 pRq, sizeof (Buf), 595 &cbReturned, NULL)) 596 { 597 DWORD winEr = GetLastError(); 598 LogRel((__FUNCTION__": DeviceIoControl 1 fail winEr (%d)\n", winEr)); 599 #ifdef VBOX_WITH_ANNOYING_USB_ASSERTIONS 600 AssertFailed(); 601 #endif 602 return VERR_GENERAL_FAILURE; 603 } 604 605 if (cbReturned < sizeof (*pDr) + 2) 606 { 607 AssertFailed(); 608 return VERR_GENERAL_FAILURE; 609 } 610 611 if (!!(pDr->bLength % 2)) 612 { 613 AssertFailed(); 614 return VERR_GENERAL_FAILURE; 615 } 616 617 if (pDr->bLength != cbReturned - sizeof (*pRq)) 618 { 619 AssertFailed(); 620 return VERR_GENERAL_FAILURE; 621 } 622 597 if (!DeviceIoControl(hHub, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, pRq, sizeof (szBuf), 598 pRq, sizeof(szBuf), 599 &cbReturned, NULL)) 600 { 601 DWORD dwErr = GetLastError(); 602 AssertMsgFailed(("Getting USB descriptor failed with error %ld\n", dwErr)); 603 return RTErrConvertFromWin32(dwErr); 604 } 605 606 /* Wrong descriptor type at the requested port index? Bail out. */ 623 607 if (pDr->bDescriptorType != USB_STRING_DESCRIPTOR_TYPE) 624 { 625 AssertFailed(); 626 return VERR_GENERAL_FAILURE; 627 } 628 629 PVBOXUSB_STRING_DR_ENTRY pEntry = (PVBOXUSB_STRING_DR_ENTRY)RTMemAllocZ(sizeof (*pEntry) + pDr->bLength + 2); 630 Assert(pEntry); 608 return VERR_NOT_FOUND; 609 610 /* Some more sanity checks. */ 611 if ( (cbReturned < sizeof (*pDr) + 2) 612 || (!!(pDr->bLength % 2)) 613 || (pDr->bLength != cbReturned - sizeof(*pRq))) 614 { 615 AssertMsgFailed(("Sanity check failed for string descriptor: cbReturned=%RI32, cbDevReq=%zu, type=%RU8, len=%RU8, port=%RU32, index=%RU32, lang=%RU32\n", 616 cbReturned, sizeof(*pRq), pDr->bDescriptorType, pDr->bLength, iPort, iDr, idLang)); 617 return VERR_INVALID_PARAMETER; 618 } 619 620 PVBOXUSB_STRING_DR_ENTRY pEntry = 621 (PVBOXUSB_STRING_DR_ENTRY)RTMemAllocZ(sizeof(VBOXUSB_STRING_DR_ENTRY) + pDr->bLength + 2); 622 AssertPtr(pEntry); 631 623 if (!pEntry) 632 { 633 return VERR_OUT_OF_RESOURCES; 634 } 624 return VERR_NO_MEMORY; 635 625 636 626 pEntry->pNext = *ppList; … … 638 628 pEntry->idLang = idLang; 639 629 memcpy(&pEntry->StrDr, pDr, pDr->bLength); 630 640 631 *ppList = pEntry; 632 641 633 return VINF_SUCCESS; 642 634 } … … 668 660 static int usbLibDevStrDrEntryGetAll(HANDLE hHub, ULONG iPort, PUSB_DEVICE_DESCRIPTOR pDevDr, PUSB_CONFIGURATION_DESCRIPTOR pCfgDr, PVBOXUSB_STRING_DR_ENTRY *ppList) 669 661 { 662 /* Read string descriptor zero to determine what languages are available. */ 670 663 int rc = usbLibDevStrDrEntryGet(hHub, iPort, 0, 0, ppList); 671 #ifdef VBOX_WITH_ANNOYING_USB_ASSERTIONS672 AssertRC(rc);673 #endif674 664 if (RT_FAILURE(rc)) 675 665 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.