VirtualBox

Ignore:
Timestamp:
Oct 22, 2019 2:05:33 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134170
Message:

USB/win: Continuing enumeration changes, WIP.

File:
1 edited

Legend:

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

    r81058 r81452  
    211211        strncpy(pVuDev->szName, pIfDetailData->DevicePath, sizeof (pVuDev->szName));
    212212
     213#ifdef VBOX_WITH_NEW_USB_ENUM
     214        if (!SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DevInfoData, SPDRP_LOCATION_INFORMATION,
     215#else
    213216        if (!SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DevInfoData, SPDRP_DRIVER,
     217#endif
    214218            NULL, /* OUT PDWORD PropertyRegDataType */
    215219            (PBYTE)pVuDev->szDriverRegName,
     
    302306}
    303307
     308#ifndef VBOX_WITH_NEW_USB_ENUM
    304309static int usbLibDevPopulate(PUSBDEVICE pDev, PUSB_NODE_CONNECTION_INFORMATION_EX pConInfo, ULONG iPort, LPCSTR lpszDrvKeyName, LPCSTR lpszHubName, PVBOXUSB_STRING_DR_ENTRY pDrList)
    305310{
     
    381386    return VINF_SUCCESS;
    382387}
     388#else
     389static int usbLibDevPopulate(PUSBDEVICE pDev, PUSB_NODE_CONNECTION_INFORMATION_EX pConInfo, ULONG iPort, LPCSTR lpszLocation, LPCSTR lpszDrvKeyName, LPCSTR lpszHubName, PVBOXUSB_STRING_DR_ENTRY pDrList)
     390{
     391    pDev->bcdUSB = pConInfo->DeviceDescriptor.bcdUSB;
     392    pDev->bDeviceClass = pConInfo->DeviceDescriptor.bDeviceClass;
     393    pDev->bDeviceSubClass = pConInfo->DeviceDescriptor.bDeviceSubClass;
     394    pDev->bDeviceProtocol = pConInfo->DeviceDescriptor.bDeviceProtocol;
     395    pDev->idVendor = pConInfo->DeviceDescriptor.idVendor;
     396    pDev->idProduct = pConInfo->DeviceDescriptor.idProduct;
     397    pDev->bcdDevice = pConInfo->DeviceDescriptor.bcdDevice;
     398    pDev->bBus = 0; /** @todo figure out bBus on windows... */
     399    pDev->bPort = iPort;
     400    /** @todo check which devices are used for primary input (keyboard & mouse) */
     401    if (!lpszDrvKeyName || *lpszDrvKeyName == 0)
     402        pDev->enmState = USBDEVICESTATE_UNUSED;
     403    else
     404        pDev->enmState = USBDEVICESTATE_USED_BY_HOST_CAPTURABLE;
     405
     406    /* Determine the speed the device is operating at. */
     407    switch (pConInfo->Speed)
     408    {
     409        case UsbLowSpeed:   pDev->enmSpeed = USBDEVICESPEED_LOW;    break;
     410        case UsbFullSpeed:  pDev->enmSpeed = USBDEVICESPEED_FULL;   break;
     411        case UsbHighSpeed:  pDev->enmSpeed = USBDEVICESPEED_HIGH;   break;
     412        default:    /* If we don't know, most likely it's something new. */
     413        case UsbSuperSpeed: pDev->enmSpeed = USBDEVICESPEED_SUPER;  break;
     414    }
     415    /* Unfortunately USB_NODE_CONNECTION_INFORMATION_EX will not report UsbSuperSpeed, and
     416     * it's not even defined in the Win7 DDK we use. So we go by the USB version, and
     417     * luckily we know that USB3 must mean SuperSpeed. The USB3 spec guarantees this (9.6.1).
     418     */
     419    if (pDev->bcdUSB >= 0x0300)
     420        pDev->enmSpeed = USBDEVICESPEED_SUPER;
     421
     422    pDev->pszAddress = RTStrDup(lpszLocation);
     423    if (!pDev->pszAddress)
     424        return VERR_NO_STR_MEMORY;
     425    pDev->pszBackend = RTStrDup("host");
     426    if (!pDev->pszBackend)
     427    {
     428        RTStrFree((char *)pDev->pszAddress);
     429        return VERR_NO_STR_MEMORY;
     430    }
     431    pDev->pszHubName = RTStrDup(lpszHubName);
     432    pDev->bNumConfigurations = 0;
     433    pDev->u64SerialHash = 0;
     434
     435    for (; pDrList; pDrList = pDrList->pNext)
     436    {
     437        char **ppszString = NULL;
     438        if (   pConInfo->DeviceDescriptor.iManufacturer
     439            && pDrList->iDr == pConInfo->DeviceDescriptor.iManufacturer)
     440            ppszString = (char **)&pDev->pszManufacturer;
     441        else if (   pConInfo->DeviceDescriptor.iProduct
     442                 && pDrList->iDr == pConInfo->DeviceDescriptor.iProduct)
     443            ppszString = (char **)&pDev->pszProduct;
     444        else if (   pConInfo->DeviceDescriptor.iSerialNumber
     445                 && pDrList->iDr == pConInfo->DeviceDescriptor.iSerialNumber)
     446            ppszString = (char **)&pDev->pszSerialNumber;
     447        if (ppszString)
     448        {
     449            int rc = RTUtf16ToUtf8((PCRTUTF16)pDrList->StrDr.bString, ppszString);
     450            if (RT_SUCCESS(rc))
     451            {
     452                Assert(*ppszString);
     453                USBLibPurgeEncoding(*ppszString);
     454
     455                if (pDrList->iDr == pConInfo->DeviceDescriptor.iSerialNumber)
     456                    pDev->u64SerialHash = USBLibHashSerial(*ppszString);
     457            }
     458            else
     459            {
     460                AssertMsgFailed(("RTUtf16ToUtf8 failed, rc (%d), resuming\n", rc));
     461                *ppszString = NULL;
     462            }
     463        }
     464    }
     465
     466    return VINF_SUCCESS;
     467}
     468#endif
    383469
    384470static void usbLibDevStrFree(LPSTR lpszName)
     
    10661152
    10671153/* Process a single USB device that's being enumerated and grab its hub-specific data. */
    1068 static int usbLibDevGetDevice(LPCSTR lpcszHubFile, ULONG iPort, LPCSTR Location, PUSBDEVICE *ppDevs, uint32_t *pcDevs)
     1154static int usbLibDevGetDevice(LPCSTR lpcszHubFile, ULONG iPort, LPCSTR lpcszLocation, LPCSTR lpcszDriverKey, PUSBDEVICE *ppDevs, uint32_t *pcDevs)
    10691155{
    10701156    HANDLE                                  HubDevice;
     
    10831169    {
    10841170        LogRelFunc(("Hub path is NULL!\n"));
     1171        return VERR_INVALID_PARAMETER;
     1172    }
     1173    if (!lpcszLocation)
     1174    {
     1175        LogRelFunc(("Location NULL!\n"));
    10851176        return VERR_INVALID_PARAMETER;
    10861177    }
     
    11491240    if (RT_LIKELY(pDev))
    11501241    {
    1151         rc = usbLibDevPopulate(pDev, pConInfo, iPort, Location, lpcszHubFile, pList);
     1242        rc = usbLibDevPopulate(pDev, pConInfo, iPort, lpcszLocation, lpcszDriverKey, lpcszHubFile, pList);
    11521243        if (RT_SUCCESS(rc))
    11531244        {
     
    11961287 * USB IOCTL and PnP Manager data.
    11971288 */
    1198 static int usbLibDevGetDevices(PUSBDEVICE *ppDevs, uint32_t *pcDevs)
     1289static int usbLibEnumDevices(PUSBDEVICE *ppDevs, uint32_t *pcDevs)
    11991290{
    12001291    HDEVINFO            InfoSet;
     
    12051296    LPCSTR              HubPath = NULL;
    12061297    LPCSTR              Location;
     1298    LPCSTR              DriverKey;
    12071299
    12081300    /* Ask for the USB PnP enumerator for all it has. */
     
    12311323            Location = (LPCSTR)usbLibGetRegistryProperty(InfoSet, &DeviceData, SPDRP_LOCATION_INFORMATION);
    12321324
     1325            /* The software key aka DriverKey. This will be NULL for devices with no driver
     1326             * and allows us to distinguish between 'busy' (driver installed) and 'available'
     1327             * (no driver) devices.
     1328             */
     1329            DriverKey = (LPCSTR)usbLibGetRegistryProperty(InfoSet, &DeviceData, SPDRP_DRIVER);
     1330
    12331331            /* The device's PnP Manager "address" is the port number on the parent hub. */
    12341332            Address = (LPDWORD)usbLibGetRegistryProperty(InfoSet, &DeviceData, SPDRP_ADDRESS);
    1235             if (Address && Location)
     1333            if (Address && Location)    /* NB: DriverKey may be NULL! */
    12361334            {
    1237                 usbLibDevGetDevice(HubPath, *Address, Location, ppDevs, pcDevs);
     1335                usbLibDevGetDevice(HubPath, *Address, Location, DriverKey, ppDevs, pcDevs);
    12381336            }
    12391337            RTMemFree((void *)HubPath);
     
    12411339            if (Location)
    12421340                RTMemFree((void *)Location);
     1341            if (DriverKey)
     1342                RTMemFree((void *)DriverKey);
    12431343            if (Address)
    12441344                RTMemFree((void *)Address);
     
    13911491
    13921492    LogRelFunc(("Starting USB device enumeration\n"));
     1493#ifdef VBOX_WITH_NEW_USB_ENUM
     1494    int rc = usbLibEnumDevices(ppDevs, pcDevs);
     1495#else
    13931496    int rc = usbLibDevGetDevices(ppDevs, pcDevs);
     1497#endif
    13941498    AssertRC(rc);
    13951499    if (RT_SUCCESS(rc))
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