Changeset 38715 in vbox for trunk/src/VBox/HostDrivers/VBoxUSB/win/lib/VBoxUsbLib-win.cpp
- Timestamp:
- Sep 12, 2011 1:21:04 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxUSB/win/lib/VBoxUsbLib-win.cpp
r38714 r38715 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox USB R3 Driver Interface library3 * VBox USB ring-3 Driver Interface library, Windows. 4 4 */ 5 5 6 /* 6 7 * Copyright (C) 2011 Oracle Corporation … … 14 15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. 15 16 */ 17 18 /******************************************************************************* 19 * Header Files * 20 *******************************************************************************/ 16 21 #define LOG_GROUP LOG_GROUP_DRV_USBPROXY 17 22 #include <windows.h> … … 43 48 #endif 44 49 45 typedef struct _USB_INTERFACE_DESCRIPTOR2 { 50 /******************************************************************************* 51 * Structures and Typedefs * 52 *******************************************************************************/ 53 typedef struct _USB_INTERFACE_DESCRIPTOR2 54 { 46 55 UCHAR bLength; 47 56 UCHAR bDescriptorType; … … 69 78 } VBOXUSBGLOBALSTATE, *PVBOXUSBGLOBALSTATE; 70 79 71 static VBOXUSBGLOBALSTATE g_VBoxUsbGlobal;72 73 80 typedef struct VBOXUSB_STRING_DR_ENTRY 74 81 { … … 79 86 } VBOXUSB_STRING_DR_ENTRY, *PVBOXUSB_STRING_DR_ENTRY; 80 87 81 /* this represents VBoxUsb device instance */ 88 /** 89 * This represents VBoxUsb device instance 90 */ 82 91 typedef struct VBOXUSB_DEV 83 92 { 84 93 struct VBOXUSB_DEV *pNext; 85 char szName[512];86 char szDriverRegName[512];94 char szName[512]; 95 char szDriverRegName[512]; 87 96 } VBOXUSB_DEV, *PVBOXUSB_DEV; 97 98 99 /******************************************************************************* 100 * Global Variables * 101 *******************************************************************************/ 102 static VBOXUSBGLOBALSTATE g_VBoxUsbGlobal; 103 88 104 89 105 int usbLibVuDeviceValidate(PVBOXUSB_DEV pVuDev) … … 1162 1178 #ifdef VBOX_USB_USE_DEVICE_NOTIFICATION 1163 1179 1164 static VOID CALLBACK usbLibTimerCallback( 1165 __in PVOID lpParameter, 1166 __in BOOLEAN TimerOrWaitFired 1167 ) 1180 static VOID CALLBACK usbLibTimerCallback(__in PVOID lpParameter, __in BOOLEAN TimerOrWaitFired) 1168 1181 { 1169 1182 SetEvent(g_VBoxUsbGlobal.hNotifyEvent); … … 1227 1240 } 1228 1241 1242 /** @todo r=bird: Use an IPRT thread? */ 1229 1243 static DWORD WINAPI usbLibMsgThreadProc(__in LPVOID lpParameter) 1230 1244 { 1231 1245 static LPCSTR s_szVBoxUsbWndClassName = "VBoxUsbLibClass"; 1232 HWND hwnd = 0; 1233 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL); 1234 bool bExit = false; 1235 1236 /* Register the Window Class. */ 1237 WNDCLASS wc; 1238 wc.style = 0; 1239 wc.lpfnWndProc = usbLibWndProc; 1240 wc.cbClsExtra = 0; 1241 wc.cbWndExtra = sizeof(void *); 1242 wc.hInstance = hInstance; 1243 wc.hIcon = NULL; 1244 wc.hCursor = NULL; 1245 wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1); 1246 wc.lpszMenuName = NULL; 1247 wc.lpszClassName = s_szVBoxUsbWndClassName; 1248 1249 ATOM atomWindowClass = RegisterClass(&wc); 1250 1251 if (atomWindowClass != 0) 1252 { 1253 /* Create the window. */ 1254 g_VBoxUsbGlobal.hWnd = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST, 1255 s_szVBoxUsbWndClassName, s_szVBoxUsbWndClassName, 1256 WS_POPUPWINDOW, 1257 -200, -200, 100, 100, NULL, NULL, hInstance, NULL); 1258 SetEvent(g_VBoxUsbGlobal.hNotifyEvent); 1259 1260 if (g_VBoxUsbGlobal.hWnd) 1261 { 1262 SetWindowPos(hwnd, HWND_TOPMOST, -200, -200, 0, 0, 1263 SWP_NOACTIVATE | SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_NOSIZE); 1264 1265 MSG msg; 1266 while (GetMessage(&msg, NULL, 0, 0)) 1267 { 1268 TranslateMessage(&msg); 1269 DispatchMessage(&msg); 1270 } 1271 1272 DestroyWindow(hwnd); 1273 1274 bExit = true; 1275 } 1276 1277 UnregisterClass(s_szVBoxUsbWndClassName, hInstance); 1278 } 1279 1280 /** @todo r=bird: Please explain why the USB library needs 1281 * this exit(0) hack! */ 1282 if (bExit) 1283 { 1284 /* no need any accuracy here, in anyway the DHCP server usually gets terminated with TerminateProcess */ 1285 exit(0); 1286 } 1287 1288 return 0; 1289 } 1290 #endif 1246 const HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL); 1247 1248 Assert(g_VBoxUsbGlobal.hWnd == NULL); 1249 g_VBoxUsbGlobal.hWnd = NULL; 1250 1251 /* 1252 * Register the Window Class and the hitten window create. 1253 */ 1254 WNDCLASS wc; 1255 wc.style = 0; 1256 wc.lpfnWndProc = usbLibWndProc; 1257 wc.cbClsExtra = 0; 1258 wc.cbWndExtra = sizeof(void *); 1259 wc.hInstance = hInstance; 1260 wc.hIcon = NULL; 1261 wc.hCursor = NULL; 1262 wc.hbrBackground = (HBRUSH)(COLOR_BACKGROUND + 1); 1263 wc.lpszMenuName = NULL; 1264 wc.lpszClassName = s_szVBoxUsbWndClassName; 1265 ATOM atomWindowClass = RegisterClass(&wc); 1266 if (atomWindowClass != 0) 1267 g_VBoxUsbGlobal.hWnd = CreateWindowEx(WS_EX_TOOLWINDOW | WS_EX_TRANSPARENT | WS_EX_TOPMOST, 1268 s_szVBoxUsbWndClassName, s_szVBoxUsbWndClassName, 1269 WS_POPUPWINDOW, 1270 -200, -200, 100, 100, NULL, NULL, hInstance, NULL); 1271 else 1272 AssertMsgFailed(("RegisterClass failed, last error %u\n", GetLastError())); 1273 1274 /* 1275 * Signal the creator thread. 1276 */ 1277 ASMCompilerBarrier(); 1278 SetEvent(g_VBoxUsbGlobal.hNotifyEvent); 1279 1280 if (g_VBoxUsbGlobal.hWnd) 1281 { 1282 /* Make sure it's really hidden. */ 1283 SetWindowPos(g_VBoxUsbGlobal.hWnd, HWND_TOPMOST, -200, -200, 0, 0, 1284 SWP_NOACTIVATE | SWP_HIDEWINDOW | SWP_NOCOPYBITS | SWP_NOREDRAW | SWP_NOSIZE); 1285 1286 /* 1287 * The message pump. 1288 */ 1289 MSG msg; 1290 while (GetMessage(&msg, NULL, 0, 0)) 1291 { 1292 TranslateMessage(&msg); 1293 DispatchMessage(&msg); 1294 } 1295 1296 /* 1297 * Clean up. 1298 */ 1299 DestroyWindow(g_VBoxUsbGlobal.hWnd); 1300 } 1301 1302 if (atomWindowClass != NULL) 1303 UnregisterClass(s_szVBoxUsbWndClassName, hInstance); 1304 1305 return 0; 1306 } 1307 1308 #endif /* VBOX_USB_USE_DEVICE_NOTIFICATION */ 1291 1309 1292 1310 /** … … 1301 1319 Log(("usbproxy: usbLibInit\n")); 1302 1320 1303 memset(&g_VBoxUsbGlobal, 0, sizeof (g_VBoxUsbGlobal)); 1304 1321 RT_ZERO(g_VBoxUsbGlobal); 1305 1322 g_VBoxUsbGlobal.hMonitor = INVALID_HANDLE_VALUE; 1306 1323 1324 /* 1325 * Create the notification and interrupt event before opening the device. 1326 */ 1307 1327 g_VBoxUsbGlobal.hNotifyEvent = CreateEvent(NULL, /* LPSECURITY_ATTRIBUTES lpEventAttributes */ 1308 1328 FALSE, /* BOOL bManualReset */ … … 1321 1341 if (g_VBoxUsbGlobal.hInterruptEvent) 1322 1342 { 1323 g_VBoxUsbGlobal.hMonitor = CreateFile(USBMON_DEVICE_NAME, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, 1324 OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, NULL); 1343 /* 1344 * Open the USB monitor device, starting if needed. 1345 */ 1346 g_VBoxUsbGlobal.hMonitor = CreateFile(USBMON_DEVICE_NAME, 1347 GENERIC_READ | GENERIC_WRITE, 1348 FILE_SHARE_READ | FILE_SHARE_WRITE, 1349 NULL, 1350 OPEN_EXISTING, 1351 FILE_ATTRIBUTE_SYSTEM, 1352 NULL); 1325 1353 1326 1354 if (g_VBoxUsbGlobal.hMonitor == INVALID_HANDLE_VALUE) … … 1329 1357 if (hr == S_OK) 1330 1358 { 1331 g_VBoxUsbGlobal.hMonitor = CreateFile(USBMON_DEVICE_NAME, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 1332 NULL, OPEN_EXISTING, FILE_ATTRIBUTE_SYSTEM, NULL); 1359 g_VBoxUsbGlobal.hMonitor = CreateFile(USBMON_DEVICE_NAME, 1360 GENERIC_READ | GENERIC_WRITE, 1361 FILE_SHARE_READ | FILE_SHARE_WRITE, 1362 NULL, 1363 OPEN_EXISTING, 1364 FILE_ATTRIBUTE_SYSTEM, 1365 NULL); 1333 1366 if (g_VBoxUsbGlobal.hMonitor == INVALID_HANDLE_VALUE) 1334 1367 { … … 1342 1375 if (g_VBoxUsbGlobal.hMonitor != INVALID_HANDLE_VALUE) 1343 1376 { 1344 USBSUP_VERSION Version = {0}; 1345 DWORD cbReturned = 0; 1346 1347 if (DeviceIoControl(g_VBoxUsbGlobal.hMonitor, SUPUSBFLT_IOCTL_GET_VERSION, NULL, 0, &Version, sizeof (Version), &cbReturned, NULL)) 1377 /* 1378 * Check the USB monitor version. 1379 * 1380 * Drivers are backwards compatible within the same major 1381 * number. We consider the minor version number this library 1382 * is compiled with to be the minimum required by the driver. 1383 * This is by reasoning that the library uses the full feature 1384 * set of the driver it's written for. 1385 */ 1386 USBSUP_VERSION Version = {0}; 1387 DWORD cbReturned = 0; 1388 if (DeviceIoControl(g_VBoxUsbGlobal.hMonitor, SUPUSBFLT_IOCTL_GET_VERSION, 1389 NULL, 0, 1390 &Version, sizeof (Version), 1391 &cbReturned, NULL)) 1348 1392 { 1349 /** @todo r=bird: Explain why we accept any mismatching major1350 * version as long as the minor version is less or equal!1351 * It does not make sense to me... */1352 1393 if ( Version.u32Major == USBMON_MAJOR_VERSION 1353 || Version.u32Minor <= USBMON_MINOR_VERSION)1394 && Version.u32Minor >= USBMON_MINOR_VERSION) 1354 1395 { 1355 1396 #ifndef VBOX_USB_USE_DEVICE_NOTIFICATION 1397 /* 1398 * Tell the monitor driver which event object to use 1399 * for notifications. 1400 */ 1356 1401 USBSUP_SET_NOTIFY_EVENT SetEvent = {0}; 1357 1402 Assert(g_VBoxUsbGlobal.hNotifyEvent); … … 1363 1408 { 1364 1409 rc = SetEvent.u.rc; 1365 AssertRC(rc);1366 1410 if (RT_SUCCESS(rc)) 1367 1411 { … … 1371 1415 return VINF_SUCCESS; 1372 1416 } 1373 AssertMsgFailed(("SetEvent failed, rc (%d)\n", rc)); 1417 1418 AssertMsgFailed(("SetEvent failed, %Rrc (%d)\n", rc, rc)); 1374 1419 } 1375 1420 else … … 1380 1425 } 1381 1426 #else 1427 /* 1428 * ??? Please explain this.... 1429 */ 1382 1430 g_VBoxUsbGlobal.hTimerQueue = CreateTimerQueue(); 1383 1431 if (g_VBoxUsbGlobal.hTimerQueue) … … 1432 1480 else 1433 1481 { 1434 LogRel((__FUNCTION__": Monitor driver version mismatch!!\n")); 1482 LogRel((__FUNCTION__": USB Monitor driver version mismatch! driver=%u.%u library=%u.%u\n", 1483 Version.u32Major, Version.u32Minor, USBMON_MAJOR_VERSION, USBMON_MINOR_VERSION)); 1435 1484 #ifdef VBOX_WITH_ANNOYING_USB_ASSERTIONS 1436 1485 AssertFailed(); … … 1503 1552 #ifdef VBOX_USB_USE_DEVICE_NOTIFICATION 1504 1553 bRc = PostMessage(g_VBoxUsbGlobal.hWnd, WM_QUIT, 0, 0); 1505 if (!bRc) 1506 { 1507 DWORD winEr = GetLastError(); 1508 AssertMsgFailed(("PostMessage for hWnd failed winEr(%d)\n", winEr)); 1509 } 1554 AssertMsg(bRc, ("PostMessage for hWnd failed winEr(%d)\n", GetLastError())); 1510 1555 1511 1556 if (g_VBoxUsbGlobal.hThread != NULL) … … 1546 1591 return VINF_SUCCESS; 1547 1592 } 1593
Note:
See TracChangeset
for help on using the changeset viewer.