Changeset 34257 in vbox
- Timestamp:
- Nov 22, 2010 4:57:23 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxUSB/win/USBLib-win.cpp
r33540 r34257 56 56 } USBDEV, *PUSBDEV; 57 57 58 static PUSBDEV pUSBDev = NULL;59 static uint32_t cMaxDevices = 0;58 static PUSBDEV g_pUSBDev = NULL; 59 static uint32_t g_cMaxDevices = 0; 60 60 static uint32_t g_cUSBStateChange = 0; 61 61 … … 85 85 OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, NULL); 86 86 87 if (INVALID_HANDLE_VALUE == hOut) { 87 if (INVALID_HANDLE_VALUE == hOut) 88 { 88 89 Log(( "USB: FAILED to open %s\n", pszName)); 89 90 goto failure; … … 218 219 int j = 0, i = 0; 219 220 220 while (true)221 while (true) 221 222 { 222 223 // SetupDiEnumDeviceInterfaces() returns information about device interfaces … … 235 236 { 236 237 uint32_t z; 237 for (z =0;z<cMaxDevices;z++)238 for (z = 0; z < g_cMaxDevices; z++) 238 239 { 239 if ( pUSBDev[z].szName[0] == 0)240 if (g_pUSBDev[z].szName[0] == 0) 240 241 { 241 memcpy(& pUSBDev[z], &usbDev, sizeof(usbDev));242 Log(("Captured device %s\n", pUSBDev[z].szName));242 memcpy(&g_pUSBDev[z], &usbDev, sizeof(usbDev)); 243 Log(("Captured device %s\n", g_pUSBDev[z].szName)); 243 244 j++; 244 245 break; 245 246 } 246 247 } 247 AssertMsg(z < cMaxDevices, ("z=%d cMaxDevices=%d\n", z,cMaxDevices));248 AssertMsg(z < g_cMaxDevices, ("z=%d g_cMaxDevices=%d\n", z, g_cMaxDevices)); 248 249 } 249 250 } … … 279 280 static int usblibEnumDevices(uint32_t cNumNewDevices, uint32_t *pcNumDevices) 280 281 { 281 if ( pUSBDev)282 RTMemFree( pUSBDev);283 pUSBDev = NULL;284 cMaxDevices = 0;282 if (g_pUSBDev) 283 RTMemFree(g_pUSBDev); 284 g_pUSBDev = NULL; 285 g_cMaxDevices = 0; 285 286 *pcNumDevices = 0; 286 287 … … 288 289 return 0; /* nothing to do */ 289 290 290 pUSBDev = (PUSBDEV)RTMemAllocZ(cNumNewDevices*sizeof(USBDEV));291 if (! pUSBDev)291 g_pUSBDev = (PUSBDEV)RTMemAllocZ(cNumNewDevices*sizeof(USBDEV)); 292 if (!g_pUSBDev) 292 293 { 293 294 AssertFailed(); 294 295 return VERR_NO_MEMORY; 295 296 } 296 cMaxDevices = cNumNewDevices;297 g_cMaxDevices = cNumNewDevices; 297 298 298 299 if (OpenUsbDevices((LPGUID)&GUID_CLASS_VBOXUSB, pcNumDevices) == false) … … 314 315 int j=0; 315 316 316 Assert(idxDev < cMaxDevices);317 for (uint32_t i=0;i<cMaxDevices;i++)318 { 319 if ( pUSBDev[i].szName[0])317 Assert(idxDev < g_cMaxDevices); 318 for (uint32_t i=0; i<g_cMaxDevices; i++) 319 { 320 if (g_pUSBDev[i].szName[0]) 320 321 { 321 322 if (j == idxDev) 322 return pUSBDev[i].szName;323 return g_pUSBDev[i].szName; 323 324 j++; 324 325 } 325 326 } 326 327 327 Log(("USB: usblibQueryHandle returned -1; cMaxDevices = %d\n",cMaxDevices));328 Log(("USB: usblibQueryHandle returned -1; g_cMaxDevices = %d\n", g_cMaxDevices)); 328 329 return NULL; 329 330 } … … 338 339 int j=0; 339 340 340 Assert(idxDev < cMaxDevices);341 for (uint32_t i=0;i<cMaxDevices;i++)342 { 343 if ( pUSBDev[i].szName[0])341 Assert(idxDev < g_cMaxDevices); 342 for (uint32_t i=0; i<g_cMaxDevices; i++) 343 { 344 if (g_pUSBDev[i].szName[0]) 344 345 { 345 346 if (j == idxDev) 346 return pUSBDev[i].szDriverRegName;347 return g_pUSBDev[i].szDriverRegName; 347 348 j++; 348 349 } 349 350 } 350 351 351 Log(("USB: usblibQueryHandle returned -1; cMaxDevices = %d\n",cMaxDevices));352 Log(("USB: usblibQueryHandle returned -1; g_cMaxDevices = %d\n", g_cMaxDevices)); 352 353 return NULL; 353 354 } … … 982 983 // Port indices are 1 based, not 0 based. 983 984 // 984 for (index =1; index <= NumPorts; index++)985 for (index = 1; index <= NumPorts; index++) 985 986 { 986 987 ULONG nBytes; … … 1784 1785 { 1785 1786 #ifdef VBOX_WITH_ANNOYING_USB_ASSERTIONS 1786 AssertMsgFailed(("DeviceIoControl IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION %d != %d\n", configDesc->wTotalLength, (nBytes - sizeof(USB_DESCRIPTOR_REQUEST))) ;1787 AssertMsgFailed(("DeviceIoControl IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION %d != %d\n", configDesc->wTotalLength, (nBytes - sizeof(USB_DESCRIPTOR_REQUEST)))); 1787 1788 #else 1788 1789 LogRel(("DeviceIoControl IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION %d != %d\n", configDesc->wTotalLength, (nBytes - sizeof(USB_DESCRIPTOR_REQUEST)) )); … … 2206 2207 ULONG i; 2207 2208 2208 for (i =0; i<NumLanguageIDs; i++)2209 for (i = 0; i < NumLanguageIDs; i++) 2209 2210 { 2210 2211 StringDescNodeTail->Next = GetStringDescriptor(hHubDevice, … … 2703 2704 USBLIB_DECL(int) USBLibGetDevices(PUSBDEVICE *ppDevices, uint32_t *pcDevices) 2704 2705 { 2705 DWORD cbReturned;2706 2706 USBSUP_GETNUMDEV numdev; 2707 char *pszDevname = NULL;2708 2707 PUSBDEVICE pDevice = NULL; 2709 2708 PUSBDEVICE pCaptured = NULL; 2710 2709 PUSBDEVICE pList = NULL; 2710 Log(("usbLibGetDevices: enter\n")); 2711 2712 if (g_hUSBMonitor == INVALID_HANDLE_VALUE) 2713 return VERR_NOT_SUPPORTED; 2714 2715 /* 1: Enumerate all usb devices attached to the host */ 2711 2716 PUSBDEVICE pHostDevices = NULL; 2712 2717 uint32_t cHostDevices = 0; 2713 Log(("usbLibGetDevices: enter\n"));2714 2715 if (g_hUSBMonitor == INVALID_HANDLE_VALUE)2716 return VERR_NOT_SUPPORTED;2717 2718 /* 1: Enumerate all usb devices attached to the host */2719 2718 usbLibEnumerateHostControllers(&pHostDevices, &cHostDevices); 2720 2719 #ifdef LOG_ENABLED … … 2722 2721 pDevice = pHostDevices; 2723 2722 int iDevice = 0; 2724 while (pDevice)2723 while (pDevice) 2725 2724 { 2726 2725 iDevice++; … … 2772 2771 */ 2773 2772 2774 for (int i =0;i<100;i++)2773 for (int i = 0; i < 100; i++) 2775 2774 { 2776 2775 /* 2777 2776 * Get the number of USB devices. 2778 2777 */ 2779 cbReturned = 0;2778 DWORD cbReturned = 0; 2780 2779 if (!DeviceIoControl(g_hUSBMonitor, SUPUSBFLT_IOCTL_GET_NUM_DEVICES, NULL, 0, &numdev, sizeof(numdev), &cbReturned, NULL)) 2781 2780 { … … 2790 2789 Log(("Monitor detected %d captured devices\n", numdev.cUSBDevices)); 2791 2790 2792 usblibEnumDevices(numdev.cUSBDevices, (uint32_t *)pcDevices);2791 usblibEnumDevices(numdev.cUSBDevices, pcDevices); 2793 2792 Log(("usblibEnumDevices detected %d devices\n", *pcDevices)); 2794 2793 … … 2817 2816 HANDLE hDev; 2818 2817 2819 pszDevname = usblibQueryDeviceName(i);2818 char *pszDevname = usblibQueryDeviceName(i); 2820 2819 hDev = CreateFile(pszDevname, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_WRITE | FILE_SHARE_READ, NULL, 2821 2820 OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, NULL); … … 2823 2822 if (hDev != INVALID_HANDLE_VALUE) 2824 2823 { 2825 cbReturned = 0;2824 DWORD cbReturned = 0; 2826 2825 if (!DeviceIoControl(hDev, SUPUSB_IOCTL_GET_DEVICE, &dev, sizeof(dev), &dev, sizeof(dev), &cbReturned, NULL)) 2827 2826 { … … 2874 2873 /* 3: Add all host devices to array of captured devices; obviously making sure there are no duplicates */ 2875 2874 Assert(pHostDevices && pCaptured); 2876 pList 2877 for (uint32_t i =0;i<numdev.cUSBDevices;i++)2875 pList = pCaptured; 2876 for (uint32_t i = 0; i < numdev.cUSBDevices; i++) 2878 2877 { 2879 2878 uint32_t j; … … 2882 2881 Assert(pDevice); 2883 2882 2884 for (j =0;j<cHostDevices;j++)2883 for (j = 0; j < cHostDevices; j++) 2885 2884 { 2886 2885 char *pszDeviceRegPath = usblibQueryDeviceRegPath(i); … … 2948 2947 pDevice = pHostDevices; 2949 2948 iDevice = 0; 2950 while (pDevice)2949 while (pDevice) 2951 2950 { 2952 2951 iDevice++;
Note:
See TracChangeset
for help on using the changeset viewer.