Changeset 81547 in vbox for trunk/src/VBox/HostDrivers/VBoxUSB/win/lib
- Timestamp:
- Oct 25, 2019 2:35:50 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxUSB/win/lib/VBoxUsbLib-win.cpp
r81452 r81547 114 114 115 115 116 static void usbLibVuFreeDevices(PVBOXUSB_DEV pDevInfos) 117 { 118 while (pDevInfos) 119 { 120 PVBOXUSB_DEV pNext = pDevInfos->pNext; 121 RTMemFree(pDevInfos); 122 pDevInfos = pNext; 123 } 124 } 125 126 /* Check that a proxied device responds the way we expect it to. */ 116 127 static int usbLibVuDeviceValidate(PVBOXUSB_DEV pVuDev) 117 128 { … … 125 136 { 126 137 dwErr = GetLastError(); 127 Assert MsgFailed(("CreateFile FAILED to open %s, dwErr=%u\n", pVuDev->szName, dwErr));138 AssertFailed(); 128 139 LogRelFunc(("Failed to open `%s' (dwErr=%u)!\n", pVuDev->szName, dwErr)); 129 140 return VERR_GENERAL_FAILURE; … … 139 150 { 140 151 dwErr = GetLastError(); 141 Assert MsgFailed(("DeviceIoControl SUPUSB_IOCTL_GET_VERSION failed with LastError=%Rwa\n", dwErr));152 AssertFailed(); 142 153 LogRelFunc(("SUPUSB_IOCTL_GET_VERSION failed on `%s' (dwErr=%u)!\n", pVuDev->szName, dwErr)); 143 154 break; … … 150 161 ) 151 162 { 152 Assert MsgFailed(("Invalid version %d:%d vs %d:%d\n", version.u32Major, version.u32Minor, USBDRV_MAJOR_VERSION, USBDRV_MINOR_VERSION));163 AssertFailed(); 153 164 LogRelFunc(("Invalid version %d:%d (%s) vs %d:%d (library)!\n", version.u32Major, version.u32Minor, pVuDev->szName, USBDRV_MAJOR_VERSION, USBDRV_MINOR_VERSION)); 154 165 break; … … 158 169 { 159 170 dwErr = GetLastError(); 160 Assert MsgFailed(("DeviceIoControl SUPUSB_IOCTL_IS_OPERATIONAL failed with LastError=%Rwa\n", dwErr));171 AssertFailed(); 161 172 LogRelFunc(("SUPUSB_IOCTL_IS_OPERATIONAL failed on `%s' (dwErr=%u)!\n", pVuDev->szName, dwErr)); 162 173 break; … … 170 181 } 171 182 183 #ifndef VBOX_WITH_NEW_USB_ENUM 172 184 static int usbLibVuDevicePopulate(PVBOXUSB_DEV pVuDev, HDEVINFO hDevInfo, PSP_DEVICE_INTERFACE_DATA pIfData) 173 185 { … … 211 223 strncpy(pVuDev->szName, pIfDetailData->DevicePath, sizeof (pVuDev->szName)); 212 224 213 #ifdef VBOX_WITH_NEW_USB_ENUM214 if (!SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DevInfoData, SPDRP_LOCATION_INFORMATION,215 #else216 225 if (!SetupDiGetDeviceRegistryPropertyA(hDevInfo, &DevInfoData, SPDRP_DRIVER, 217 #endif218 226 NULL, /* OUT PDWORD PropertyRegDataType */ 219 227 (PBYTE)pVuDev->szDriverRegName, … … 234 242 RTMemFree(pIfDetailData); 235 243 return rc; 236 }237 238 static void usbLibVuFreeDevices(PVBOXUSB_DEV pDevInfos)239 {240 while (pDevInfos)241 {242 PVBOXUSB_DEV pNext = pDevInfos->pNext;243 RTMemFree(pDevInfos);244 pDevInfos = pNext;245 }246 244 } 247 245 … … 306 304 } 307 305 308 #ifndef VBOX_WITH_NEW_USB_ENUM309 306 static int usbLibDevPopulate(PUSBDEVICE pDev, PUSB_NODE_CONNECTION_INFORMATION_EX pConInfo, ULONG iPort, LPCSTR lpszDrvKeyName, LPCSTR lpszHubName, PVBOXUSB_STRING_DR_ENTRY pDrList) 310 307 { … … 387 384 } 388 385 #else 386 387 static PSP_DEVICE_INTERFACE_DETAIL_DATA usbLibGetDevDetail(HDEVINFO InfoSet, PSP_DEVICE_INTERFACE_DATA InterfaceData, PSP_DEVINFO_DATA DevInfoData); 388 static void *usbLibGetRegistryProperty(HDEVINFO InfoSet, const PSP_DEVINFO_DATA DevData, DWORD Property); 389 390 /* Populate the data for a single proxied USB device. */ 391 static int usbLibVUsbDevicePopulate(PVBOXUSB_DEV pVuDev, HDEVINFO InfoSet, PSP_DEVICE_INTERFACE_DATA InterfaceData) 392 { 393 PSP_DEVICE_INTERFACE_DETAIL_DATA DetailData = NULL; 394 SP_DEVINFO_DATA DeviceData; 395 LPCSTR Location; 396 int rc = VINF_SUCCESS; 397 398 memset(&DeviceData, 0, sizeof(DeviceData)); 399 DeviceData.cbSize = sizeof(DeviceData); 400 /* The interface detail includes the device path. */ 401 DetailData = usbLibGetDevDetail(InfoSet, InterfaceData, &DeviceData); 402 if (DetailData) 403 { 404 strncpy(pVuDev->szName, DetailData->DevicePath, sizeof(pVuDev->szName)); 405 406 /* The location is used as a unique identifier for cross-referencing the two lists. */ 407 Location = (LPCSTR)usbLibGetRegistryProperty(InfoSet, &DeviceData, SPDRP_LOCATION_INFORMATION); 408 if (Location) 409 { 410 strncpy(pVuDev->szDriverRegName, Location, sizeof(pVuDev->szDriverRegName)); 411 rc = usbLibVuDeviceValidate(pVuDev); 412 LogRelFunc(("Found VBoxUSB on `%s' (rc=%d)\n", pVuDev->szName, rc)); 413 AssertRC(rc); 414 415 RTMemFree((void *)Location); 416 } 417 else 418 { 419 /* Errors will be logged by usbLibGetRegistryProperty(). */ 420 rc = VERR_GENERAL_FAILURE; 421 } 422 423 RTMemFree(DetailData); 424 } 425 else 426 { 427 /* Errors will be logged by usbLibGetDevDetail(). */ 428 rc = VERR_GENERAL_FAILURE; 429 } 430 431 432 return rc; 433 } 434 435 /* Enumerate proxied USB devices (with VBoxUSB.sys loaded). */ 436 static int usbLibEnumVUsbDevices(PVBOXUSB_DEV *ppVuDevs, uint32_t *pcVuDevs) 437 { 438 SP_DEVICE_INTERFACE_DATA InterfaceData; 439 HDEVINFO InfoSet; 440 DWORD DeviceIndex; 441 DWORD dwErr; 442 443 *ppVuDevs = NULL; 444 *pcVuDevs = 0; 445 446 /* Enumerate all present devices which support the GUID_CLASS_VBOXUSB interface. */ 447 InfoSet = SetupDiGetClassDevs(&GUID_CLASS_VBOXUSB, NULL, NULL, 448 (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)); 449 if (InfoSet == INVALID_HANDLE_VALUE) 450 { 451 DWORD dwErr = GetLastError(); 452 LogRelFunc(("SetupDiGetClassDevs for GUID_CLASS_VBOXUSB failed (dwErr=%u)\n", dwErr)); 453 AssertFailed(); 454 return VERR_GENERAL_FAILURE; 455 } 456 457 memset(&InterfaceData, 0, sizeof(InterfaceData)); 458 InterfaceData.cbSize = sizeof(InterfaceData); 459 DeviceIndex = 0; 460 461 /* Loop over the enumerated list. */ 462 while (SetupDiEnumDeviceInterfaces(InfoSet, NULL, &GUID_CLASS_VBOXUSB, DeviceIndex, &InterfaceData)) 463 { 464 /* we've now got the IfData */ 465 PVBOXUSB_DEV pVuDev = (PVBOXUSB_DEV)RTMemAllocZ(sizeof (*pVuDev)); 466 if (!pVuDev) 467 { 468 AssertFailed(); 469 LogRelFunc(("RTMemAllocZ failed\n")); 470 break; 471 } 472 473 int rc = usbLibVUsbDevicePopulate(pVuDev, InfoSet, &InterfaceData); 474 if (RT_SUCCESS(rc)) 475 { 476 pVuDev->pNext = *ppVuDevs; 477 *ppVuDevs = pVuDev; 478 ++*pcVuDevs; 479 } 480 else /* Skip this device but continue enumerating. */ 481 AssertMsgFailed(("usbLibVuDevicePopulate failed, rc=%d\n", rc)); 482 483 memset(&InterfaceData, 0, sizeof(InterfaceData)); 484 InterfaceData.cbSize = sizeof(InterfaceData); 485 ++DeviceIndex; 486 } 487 488 /* Paranoia. */ 489 dwErr = GetLastError(); 490 if (dwErr != ERROR_NO_MORE_ITEMS) 491 { 492 LogRelFunc(("SetupDiEnumDeviceInterfaces failed (dwErr=%u)\n", dwErr)); 493 AssertFailed(); 494 } 495 496 SetupDiDestroyDeviceInfoList(InfoSet); 497 498 return VINF_SUCCESS; 499 } 500 389 501 static int usbLibDevPopulate(PUSBDEVICE pDev, PUSB_NODE_CONNECTION_INFORMATION_EX pConInfo, ULONG iPort, LPCSTR lpszLocation, LPCSTR lpszDrvKeyName, LPCSTR lpszHubName, PVBOXUSB_STRING_DR_ENTRY pDrList) 390 502 { … … 1028 1140 } 1029 1141 1030 /* Given a HDEVINFO and SP_DEVICE_INTERFACE_DATA, get the interface detail data . */1031 static PSP_DEVICE_INTERFACE_DETAIL_DATA usbLibGetDevDetail(HDEVINFO InfoSet, PSP_DEVICE_INTERFACE_DATA InterfaceData )1142 /* Given a HDEVINFO and SP_DEVICE_INTERFACE_DATA, get the interface detail data and optionally device info data. */ 1143 static PSP_DEVICE_INTERFACE_DETAIL_DATA usbLibGetDevDetail(HDEVINFO InfoSet, PSP_DEVICE_INTERFACE_DATA InterfaceData, PSP_DEVINFO_DATA DevInfoData) 1032 1144 { 1033 1145 BOOL rc; … … 1035 1147 PSP_DEVICE_INTERFACE_DETAIL_DATA DetailData; 1036 1148 1037 rc = SetupDiGetDeviceInterfaceDetail(InfoSet, InterfaceData, NULL, 0, &dwReqLen, NULL);1149 rc = SetupDiGetDeviceInterfaceDetail(InfoSet, InterfaceData, NULL, 0, &dwReqLen, DevInfoData); 1038 1150 if (!rc && (GetLastError() != ERROR_INSUFFICIENT_BUFFER)) 1039 1151 { … … 1049 1161 DetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA); 1050 1162 1051 rc = SetupDiGetDeviceInterfaceDetail(InfoSet, InterfaceData, DetailData, dwReqLen, &dwReqLen, NULL);1163 rc = SetupDiGetDeviceInterfaceDetail(InfoSet, InterfaceData, DetailData, dwReqLen, &dwReqLen, DevInfoData); 1052 1164 if (!rc) 1053 1165 { … … 1091 1203 } 1092 1204 1093 DetailData = usbLibGetDevDetail(InfoSet, &InterfaceData );1205 DetailData = usbLibGetDevDetail(InfoSet, &InterfaceData, NULL); 1094 1206 if (!DetailData) 1095 1207 { … … 1298 1410 LPCSTR DriverKey; 1299 1411 1300 /* Ask forthe USB PnP enumerator for all it has. */1412 /* Ask the USB PnP enumerator for all it has. */ 1301 1413 InfoSet = SetupDiGetClassDevs(NULL, "USB", NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT); 1302 1414 … … 1429 1541 #ifdef VBOX_WITH_ANNOYING_USB_ASSERTIONS 1430 1542 /* ERROR_DEVICE_NOT_CONNECTED -> device was removed just now */ 1431 Asser tMsg(dwErr == ERROR_DEVICE_NOT_CONNECTED, (__FUNCTION__": DeviceIoControl failed dwErr (%u)\n", dwErr));1543 AsserFailed(); 1432 1544 #endif 1433 1545 LogRelFunc(("SUPUSB_IOCTL_GET_DEVICE failed on '%s' (dwErr=%u)!\n", pDevInfos->szName, dwErr)); … … 1445 1557 DWORD dwErr = GetLastError(); 1446 1558 /* ERROR_DEVICE_NOT_CONNECTED -> device was removed just now */ 1447 Assert MsgFailed(("Monitor DeviceIoControl failed dwErr (%u)\n", dwErr));1559 AssertFailed(); 1448 1560 LogRelFunc(("SUPUSBFLT_IOCTL_GET_DEVICE failed for '%s' (hDevice=%p, dwErr=%u)!\n", pDevInfos->szName, hDevice, dwErr)); 1449 1561 CloseHandle(hDev); … … 1501 1613 PVBOXUSB_DEV pDevInfos = NULL; 1502 1614 uint32_t cDevInfos = 0; 1615 #ifdef VBOX_WITH_NEW_USB_ENUM 1616 rc = usbLibEnumVUsbDevices(&pDevInfos, &cDevInfos); 1617 #else 1503 1618 rc = usbLibVuGetDevices(&pDevInfos, &cDevInfos); 1619 #endif 1504 1620 AssertRC(rc); 1505 1621 if (RT_SUCCESS(rc)) … … 1603 1719 { 1604 1720 DWORD dwErr = GetLastError(); 1605 Assert MsgFailed(("DeviceIoControl failed with dwErr (%u)\n", dwErr));1721 AssertFailed(); 1606 1722 LogRelFunc(("SUPUSBFLT_IOCTL_ADD_FILTER failed (dwErr=%u)!\n", dwErr)); 1607 1723 return NULL; … … 1610 1726 if (RT_FAILURE(FltAddRc.rc)) 1611 1727 { 1612 Assert MsgFailed(("Adding filter failed with %d\n", FltAddRc.rc));1728 AssertFailed(); 1613 1729 LogRelFunc(("Adding a USB filter failed with rc=%d!\n", FltAddRc.rc)); 1614 1730 return NULL; … … 1645 1761 { 1646 1762 DWORD dwErr = GetLastError(); 1647 Assert MsgFailed(("DeviceIoControl failed with LastError=%Rwa\n", dwErr));1763 AssertFailed(); 1648 1764 LogRelFunc(("SUPUSBFLT_IOCTL_REMOVE_FILTER failed (dwErr=%u)!\n", dwErr)); 1649 1765 } … … 1664 1780 { 1665 1781 DWORD dwErr = GetLastError(); 1666 Assert MsgFailed(("DeviceIoControl failed with dwErr (%u)\n", dwErr));1782 AssertFailed(); 1667 1783 LogRelFunc(("SUPUSBFLT_IOCTL_RUN_FILTERS failed (dwErr=%u)!\n", dwErr)); 1668 1784 return RTErrConvertFromWin32(dwErr);
Note:
See TracChangeset
for help on using the changeset viewer.