VirtualBox

Ignore:
Timestamp:
Dec 6, 2019 7:26:34 AM (5 years ago)
Author:
vboxsync
Message:

USB/Win: Another round of USB enumeration updates.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/lib/VBoxUsbLib-win.cpp

    r81664 r82443  
    405405
    406406        /* The location is used as a unique identifier for cross-referencing the two lists. */
    407         Location = (LPCSTR)usbLibGetRegistryProperty(InfoSet, &DeviceData, SPDRP_LOCATION_INFORMATION);
     407        Location = (LPCSTR)usbLibGetRegistryProperty(InfoSet, &DeviceData, SPDRP_DRIVER);
    408408        if (Location)
    409409        {
     
    521521}
    522522
    523 static bool usbLibParseLocation(LPCSTR LocStr, uint16_t *pBus, uint16_t *pPort)
    524 {
    525 #define PORT_PREFIX "Port_#"
    526 #define BUS_PREFIX  ".Hub_#"
    527 
    528     *pBus = *pPort = 0xFFFF;
    529 
    530     /* The Location Information is in the format Port_#xxxx.Hub_#xxxx, with 'xxxx'
    531      * being 16-bit hexadecimal numbers. It should be reliable on Windows Vista and
    532      * later. Note that while the port corresponds to the port number aka address,
    533      * the hub nomber has no discernible relationship to how Windows enumerates hubs.
    534      */
    535 
    536     if (strncmp(LocStr, PORT_PREFIX, strlen(PORT_PREFIX)))
    537         return false;
    538 
    539     /* Point to the start of the port number and parse it. */
    540     LocStr += strlen(PORT_PREFIX);
    541     *pPort = usbLibParseHexNumU16(&LocStr);
    542 
    543     if (strncmp(LocStr, BUS_PREFIX, strlen(BUS_PREFIX)))
    544         return false;
    545 
    546     /* Point to the start of the hub/bus number and parse it. */
    547     LocStr += strlen(BUS_PREFIX);
    548     *pBus = usbLibParseHexNumU16(&LocStr);
    549 
    550     return true;
    551 #undef PORT_PREFIX
    552 #undef BUS_PREFIX
    553 }
    554 
    555523static int usbLibDevPopulate(PUSBDEVICE pDev, PUSB_NODE_CONNECTION_INFORMATION_EX pConInfo, ULONG iPort, LPCSTR lpszLocation, LPCSTR lpszDrvKeyName, LPCSTR lpszHubName, PVBOXUSB_STRING_DR_ENTRY pDrList)
    556524{
    557     uint16_t    uPort;
    558     uint16_t    uBus;
    559 
    560525    pDev->bcdUSB = pConInfo->DeviceDescriptor.bcdUSB;
    561526    pDev->bDeviceClass = pConInfo->DeviceDescriptor.bDeviceClass;
     
    565530    pDev->idProduct = pConInfo->DeviceDescriptor.idProduct;
    566531    pDev->bcdDevice = pConInfo->DeviceDescriptor.bcdDevice;
    567 
    568     /* Parse the bus (hub) and port out of the location. */
    569     if (usbLibParseLocation(lpszLocation, &uBus, &uPort))
    570     {
    571         Assert(uPort == iPort);
    572         pDev->bBus  = uBus;
    573         pDev->bPort = uPort;
    574     }
    575     else
    576     {
    577         /* Shouldn't happen but fall back to semi-sane values. */
    578         pDev->bBus  = 0;
    579         pDev->bPort = iPort;
    580     }
    581 
    582     /** @todo check which devices are used for primary input (keyboard & mouse) */
     532    pDev->bBus = 0; /* The hub numbering is not very useful on Windows. Skip it. */
     533    pDev->bPort = iPort;
     534
     535    /* The port path/location uniquely identifies the port. */
     536    pDev->pszPortPath = RTStrDup(lpszLocation);
     537    if (!pDev->pszPortPath)
     538        return VERR_NO_STR_MEMORY;
     539
     540    /* If there is no DriverKey, the device is unused because there's no driver. */
    583541    if (!lpszDrvKeyName || *lpszDrvKeyName == 0)
    584542        pDev->enmState = USBDEVICESTATE_UNUSED;
     
    602560        pDev->enmSpeed = USBDEVICESPEED_SUPER;
    603561
    604     pDev->pszAddress = RTStrDup(lpszLocation);
    605     if (!pDev->pszAddress)
    606         return VERR_NO_STR_MEMORY;
     562    /* If there's no DriverKey, jam in an empty string to avoid NULL pointers. */
     563    if (!lpszDrvKeyName)
     564        pDev->pszAddress = RTStrDup("");
     565    else
     566        pDev->pszAddress = RTStrDup(lpszDrvKeyName);
     567
    607568    pDev->pszBackend = RTStrDup("host");
    608569    if (!pDev->pszBackend)
     
    15031464        {
    15041465            /* The location information uniquely identifies the USB device, (hub/port). */
    1505             Location = (LPCSTR)usbLibGetRegistryProperty(InfoSet, &DeviceData, SPDRP_LOCATION_INFORMATION);
     1466            Location = (LPCSTR)usbLibGetRegistryProperty(InfoSet, &DeviceData, SPDRP_LOCATION_PATHS);
    15061467
    15071468            /* The software key aka DriverKey. This will be NULL for devices with no driver
Note: See TracChangeset for help on using the changeset viewer.

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