Changeset 36941 in vbox
- Timestamp:
- May 3, 2011 2:56:08 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 71528
- Location:
- trunk
- Files:
-
- 5 deleted
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/VBox/VBoxDrvCfg-win.h
r36536 r36941 52 52 VBOXDRVCFG_DECL(void) VBoxDrvCfgPanicSet(PFNVBOXDRVCFG_PANIC pfnPanic, void *pvPanic); 53 53 54 /* Driver package API*/ 54 55 VBOXDRVCFG_DECL(HRESULT) VBoxDrvCfgInfInstall(IN LPCWSTR lpszInfPath); 55 56 VBOXDRVCFG_DECL(HRESULT) VBoxDrvCfgInfUninstall(IN LPCWSTR lpszInfPath, IN DWORD fFlags); … … 57 58 VBOXDRVCFG_DECL(HRESULT) VBoxDrvCfgInfUninstallAllF(IN LPCWSTR lpszClassName, IN LPCWSTR lpszPnPId, IN DWORD fFlags); 58 59 60 /* Service API */ 61 VBOXDRVCFG_DECL(HRESULT) VBoxDrvCfgSvcStart(LPCWSTR lpszSvcName); 62 59 63 RT_C_DECLS_END 60 64 -
trunk/include/VBox/usblib-win.h
r34306 r36941 42 42 #define USBFLT_SYMBOLIC_NAME_STRING L"\\DosDevices\\VBoxUSBFlt" 43 43 44 #define USBMON_SERVICE_NAME 44 #define USBMON_SERVICE_NAME_W L"VBoxUSBMon" 45 45 #define USBMON_DEVICE_NAME "\\\\.\\VBoxUSBMon" 46 46 #define USBMON_DEVICE_NAME_NT L"\\Device\\VBoxUSBMon" … … 74 74 #define USBFLT_MINOR_VERSION 3 75 75 76 #define USBMON_MAJOR_VERSION 177 #define USBMON_MINOR_VERSION 178 79 #define USBDRV_MAJOR_VERSION 380 #define USBDRV_MINOR_VERSION 176 #define USBMON_MAJOR_VERSION 4 77 #define USBMON_MINOR_VERSION 0 78 79 #define USBDRV_MAJOR_VERSION 4 80 #define USBDRV_MINOR_VERSION 0 81 81 82 82 #define SUPUSB_IOCTL_TEST CTL_CODE(FILE_DEVICE_UNKNOWN, 0x601, METHOD_BUFFERED, FILE_WRITE_ACCESS) … … 103 103 #define SUPUSBFLT_IOCTL_CAPTURE_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x613, METHOD_BUFFERED, FILE_WRITE_ACCESS) 104 104 #define SUPUSBFLT_IOCTL_RELEASE_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x614, METHOD_BUFFERED, FILE_WRITE_ACCESS) 105 #define SUPUSBFLT_IOCTL_RUN_FILTERS CTL_CODE(FILE_DEVICE_UNKNOWN, 0x615, METHOD_BUFFERED, FILE_WRITE_ACCESS) 106 #define SUPUSBFLT_IOCTL_SET_NOTIFY_EVENT CTL_CODE(FILE_DEVICE_UNKNOWN, 0x616, METHOD_BUFFERED, FILE_WRITE_ACCESS) 107 #define SUPUSBFLT_IOCTL_GET_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN, 0x617, METHOD_BUFFERED, FILE_WRITE_ACCESS) 105 108 106 109 #pragma pack(4) … … 109 112 #define MAX_USB_SERIAL_STRING 64 110 113 111 typedef struct 112 { 114 /* a user-mode handle that could be used for retriving device information 115 * from the monitor driver */ 116 typedef void* HVBOXUSBDEVUSR; 117 118 typedef struct 119 { 120 HVBOXUSBDEVUSR hDevice; 113 121 uint16_t vid, did, rev; 114 122 char serial_hash[MAX_USB_SERIAL_STRING]; … … 117 125 uint8_t fHiSpeed; 118 126 } USBSUP_GETDEV, *PUSBSUP_GETDEV; 127 128 typedef struct 129 { 130 USBDEVICESTATE enmState; 131 } USBSUP_GETDEV_MON, *PUSBSUP_GETDEV_MON; 119 132 120 133 typedef struct … … 231 244 } USBSUP_URB, *PUSBSUP_URB; 232 245 246 typedef struct 247 { 248 union 249 { 250 /* in: event handle */ 251 void* hEvent; 252 /* out: result */ 253 int rc; 254 } u; 255 } USBSUP_SET_NOTIFY_EVENT, *PUSBSUP_SET_NOTIFY_EVENT; 256 257 typedef struct 258 { 259 uint16_t usVendorId; 260 uint16_t usProductId; 261 uint16_t usRevision; 262 uint16_t usAlignment; 263 char DrvKeyName[512]; 264 } USBSUP_DEVID, *PUSBSUP_DEVID; 265 266 typedef struct 267 { 268 USBSUP_DEVID DevId; 269 char szName[512]; 270 USBDEVICESTATE enmState; 271 bool fHiSpeed; 272 } USBSUP_DEVINFO, *PUSBSUP_DEVINFO; 273 274 typedef struct 275 { 276 int rc; 277 uint32_t cDevices; 278 USBSUP_DEVINFO aDevices[1]; 279 } USBSUP_GET_DEVICES, *PUSBSUP_GET_DEVICES; 280 233 281 #pragma pack() /* paranoia */ 234 282 … … 249 297 * @param pcbNumDevices Number of USB devices in the list 250 298 */ 251 USBLIB_DECL(int) USBLibGetDevices(PUSBDEVICE *ppDevices, uint32_t *pcbNumDevices); 252 253 /** 254 * Check for USB device arrivals or removals 255 * 256 * @returns boolean 257 */ 258 USBLIB_DECL(bool) USBLibHasPendingDeviceChanges(void); 259 260 /** 261 * Capture specified USB device 262 * 263 * @returns VBox status code 264 * @param usVendorId Vendor id 265 * @param usProductId Product id 266 * @param usRevision Revision 267 */ 268 USBLIB_DECL(int) USBLibCaptureDevice(uint16_t usVendorId, uint16_t usProductId, uint16_t usRevision); 269 270 /** 271 * Release specified USB device to the host. 272 * 273 * @returns VBox status code 274 * @param usVendorId Vendor id 275 * @param usProductId Product id 276 * @param usRevision Revision 277 */ 278 USBLIB_DECL(int) USBLibReleaseDevice(uint16_t usVendorId, uint16_t usProductId, uint16_t usRevision); 299 USBLIB_DECL(int) USBLibGetDevices(PUSBDEVICE *ppDevices, uint32_t *pcbNumDevices); 300 301 USBLIB_DECL(int) USBLibWaitChange(RTMSINTERVAL cMillies); 302 303 USBLIB_DECL(int) USBLibInterruptWaitChange(); 304 305 USBLIB_DECL(int) USBLibRunFilters(); 279 306 280 307 /** @} */ -
trunk/src/VBox/Devices/Makefile.kmk
r36912 r36941 84 84 ifdef VBOX_WITH_USB 85 85 VBoxDDU_LIBS += \ 86 $(PATH_LIB)/USBLib$(VBOX_SUFF_LIB) 86 $(PATH_LIB)/USBLib$(VBOX_SUFF_LIB) \ 87 $(PATH_LIB)/VBoxDrvCfg$(VBOX_SUFF_LIB) 87 88 endif 88 89 ifeq ($(KBUILD_TARGET),l4) -
trunk/src/VBox/HostDrivers/VBoxUSB/Makefile.kmk
r35440 r36941 47 47 solaris/USBLib-solaris.cpp 48 48 USBLib_SOURCES.win = \ 49 win/USBLib-win.cpp 50 49 win/lib/VBoxUsbLib-win.cpp 51 50 52 51 # -
trunk/src/VBox/HostDrivers/VBoxUSB/VBoxUSBFilterMgr.cpp
r33540 r36941 79 79 USBFILTER Core; 80 80 /** The filter owner. */ 81 RTPROCESSOwner;81 VBOXUSBFILTER_CONTEXT Owner; 82 82 /** The filter Id. */ 83 83 uintptr_t uId; … … 146 146 { 147 147 USBFilterDelete(&pFilter->Core); 148 pFilter->Owner = NIL_RTPROCESS;148 pFilter->Owner = VBOXUSBFILTER_CONTEXT_NIL; 149 149 pFilter->pNext = NULL; 150 150 RTMemFree(pFilter); … … 189 189 * @param puId Where to store the filter ID. 190 190 */ 191 int VBoxUSBFilterAdd(PCUSBFILTER pFilter, RTPROCESSOwner, uintptr_t *puId)191 int VBoxUSBFilterAdd(PCUSBFILTER pFilter, VBOXUSBFILTER_CONTEXT Owner, uintptr_t *puId) 192 192 { 193 193 /* … … 197 197 if (RT_FAILURE(rc)) 198 198 return rc; 199 if (!Owner || Owner == NIL_RTPROCESS)199 if (!Owner || Owner == VBOXUSBFILTER_CONTEXT_NIL) 200 200 return VERR_INVALID_PARAMETER; 201 201 if (!VALID_PTR(puId)) … … 247 247 * Returned by VBoxUSBFilterAdd(). 248 248 */ 249 int VBoxUSBFilterRemove( RTPROCESSOwner, uintptr_t uId)249 int VBoxUSBFilterRemove(VBOXUSBFILTER_CONTEXT Owner, uintptr_t uId) 250 250 { 251 251 /* … … 254 254 if (!uId) 255 255 return VERR_INVALID_PARAMETER; 256 if (!Owner || Owner == NIL_RTPROCESS)256 if (!Owner || Owner == VBOXUSBFILTER_CONTEXT_NIL) 257 257 return VERR_INVALID_PARAMETER; 258 258 … … 302 302 } 303 303 304 VBOXUSBFILTER_CONTEXT VBoxUSBFilterGetOwner(uintptr_t uId) 305 { 306 Assert(uId); 307 /* 308 * Validate input. 309 */ 310 if (!uId) 311 return VBOXUSBFILTER_CONTEXT_NIL; 312 313 /* 314 * Result. 315 */ 316 VBOXUSBFILTER_CONTEXT Owner = VBOXUSBFILTER_CONTEXT_NIL; 317 318 VBOXUSBFILTERMGR_LOCK(); 319 320 for (unsigned i = USBFILTERTYPE_FIRST; i < RT_ELEMENTS(g_aLists); i++) 321 { 322 for (PVBOXUSBFILTER pCur = g_aLists[i].pHead; pCur; pCur = pCur->pNext) 323 { 324 if (pCur->uId == uId) 325 { 326 Owner = pCur->Owner; 327 Assert(Owner != VBOXUSBFILTER_CONTEXT_NIL); 328 break; 329 } 330 } 331 } 332 333 Assert(Owner != VBOXUSBFILTER_CONTEXT_NIL); 334 335 VBOXUSBFILTERMGR_UNLOCK(); 336 337 return Owner; 338 } 304 339 305 340 /** … … 311 346 * @param Owner The owner 312 347 */ 313 void VBoxUSBFilterRemoveOwner( RTPROCESSOwner)348 void VBoxUSBFilterRemoveOwner(VBOXUSBFILTER_CONTEXT Owner) 314 349 { 315 350 /* … … 362 397 } 363 398 364 365 399 /** 366 400 * Match the specified device against the filters. 367 * 368 * @returns Owner on if matched, NIL_RTPROCESS it not matched. 401 * Unlike the VBoxUSBFilterMatch, returns Owner also if exclude filter is matched 402 * 403 * @returns Owner on if matched, VBOXUSBFILTER_CONTEXT_NIL it not matched. 369 404 * @param pDevice The device data as a filter structure. 370 405 * See USBFilterMatch for how to construct this. 371 406 * @param puId Where to store the filter id (optional). 372 */ 373 RTPROCESS VBoxUSBFilterMatch(PCUSBFILTER pDevice, uintptr_t *puId) 407 * @param pfFilter Where to store whether the device must be filtered or not 408 */ 409 VBOXUSBFILTER_CONTEXT VBoxUSBFilterMatchEx(PCUSBFILTER pDevice, uintptr_t *puId, bool fRemoveFltIfOneShot, bool *pfFilter, bool *pfIsOneShot) 374 410 { 375 411 /* … … 377 413 */ 378 414 int rc = USBFilterValidate(pDevice); 379 AssertRCReturn(rc, NIL_RTPROCESS); 415 AssertRCReturn(rc, VBOXUSBFILTER_CONTEXT_NIL); 416 417 *pfFilter = false; 418 if (puId) 419 *puId = 0; 380 420 381 421 /* … … 403 443 if (puId) 404 444 *puId = pCur->uId; 405 RTPROCESS Owner = i != USBFILTERTYPE_IGNORE 406 && i != USBFILTERTYPE_ONESHOT_IGNORE 407 ? pCur->Owner 408 : NIL_RTPROCESS; 445 VBOXUSBFILTER_CONTEXT Owner = pCur->Owner; 446 *pfFilter = !!(i != USBFILTERTYPE_IGNORE 447 && i != USBFILTERTYPE_ONESHOT_IGNORE); 409 448 410 449 if ( i == USBFILTERTYPE_ONESHOT_IGNORE 411 450 || i == USBFILTERTYPE_ONESHOT_CAPTURE) 412 451 { 413 /* unlink */ 414 PVBOXUSBFILTER pNext = pCur->pNext; 415 if (pPrev) 416 pPrev->pNext = pNext; 417 else 418 g_aLists[i].pHead = pNext; 419 if (!pNext) 420 g_aLists[i].pTail = pPrev; 452 if (fRemoveFltIfOneShot) 453 { 454 /* unlink */ 455 PVBOXUSBFILTER pNext = pCur->pNext; 456 if (pPrev) 457 pPrev->pNext = pNext; 458 else 459 g_aLists[i].pHead = pNext; 460 if (!pNext) 461 g_aLists[i].pTail = pPrev; 462 } 421 463 } 422 464 … … 425 467 if ( i == USBFILTERTYPE_ONESHOT_IGNORE 426 468 || i == USBFILTERTYPE_ONESHOT_CAPTURE) 427 vboxUSBFilterFree(pCur); 469 { 470 if (fRemoveFltIfOneShot) 471 { 472 vboxUSBFilterFree(pCur); 473 } 474 if (pfIsOneShot) 475 *pfIsOneShot = true; 476 } 477 else 478 { 479 if (pfIsOneShot) 480 *pfIsOneShot = false; 481 } 428 482 return Owner; 429 483 } … … 435 489 436 490 VBOXUSBFILTERMGR_UNLOCK(); 437 return NIL_RTPROCESS; 438 } 439 491 return VBOXUSBFILTER_CONTEXT_NIL; 492 } 493 494 /** 495 * Match the specified device against the filters. 496 * 497 * @returns Owner on if matched, VBOXUSBFILTER_CONTEXT_NIL it not matched. 498 * @param pDevice The device data as a filter structure. 499 * See USBFilterMatch for how to construct this. 500 * @param puId Where to store the filter id (optional). 501 */ 502 VBOXUSBFILTER_CONTEXT VBoxUSBFilterMatch(PCUSBFILTER pDevice, uintptr_t *puId) 503 { 504 bool fFilter = false; 505 VBOXUSBFILTER_CONTEXT Owner = VBoxUSBFilterMatchEx(pDevice, puId, 506 true, /* remove filter is it's a one-shot*/ 507 &fFilter, NULL /* bool * fIsOneShot */); 508 if (fFilter) 509 { 510 Assert(Owner != VBOXUSBFILTER_CONTEXT_NIL); 511 return Owner; 512 } 513 return VBOXUSBFILTER_CONTEXT_NIL; 514 } 515 -
trunk/src/VBox/HostDrivers/VBoxUSB/VBoxUSBFilterMgr.h
r31898 r36941 23 23 RT_C_DECLS_BEGIN 24 24 25 #if defined(RT_OS_WINDOWS) 26 typedef struct VBOXUSBFLTCTX *VBOXUSBFILTER_CONTEXT; 27 #define VBOXUSBFILTER_CONTEXT_NIL NULL 28 #else 29 typedef RTPROCESS VBOXUSBFILTER_CONTEXT; 30 #define VBOXUSBFILTER_CONTEXT_NIL NIL_RTPROCESS 31 #endif 32 25 33 int VBoxUSBFilterInit(void); 26 34 void VBoxUSBFilterTerm(void); 27 void VBoxUSBFilterRemoveOwner(RTPROCESS Owner); 28 int VBoxUSBFilterAdd(PCUSBFILTER pFilter, RTPROCESS Owner, uintptr_t *puId); 29 int VBoxUSBFilterRemove(RTPROCESS Owner, uintptr_t uId); 30 RTPROCESS VBoxUSBFilterMatch(PCUSBFILTER pDevice, uintptr_t *puId); 35 void VBoxUSBFilterRemoveOwner(VBOXUSBFILTER_CONTEXT Owner); 36 int VBoxUSBFilterAdd(PCUSBFILTER pFilter, VBOXUSBFILTER_CONTEXT Owner, uintptr_t *puId); 37 int VBoxUSBFilterRemove(VBOXUSBFILTER_CONTEXT Owner, uintptr_t uId); 38 VBOXUSBFILTER_CONTEXT VBoxUSBFilterMatch(PCUSBFILTER pDevice, uintptr_t *puId); 39 VBOXUSBFILTER_CONTEXT VBoxUSBFilterMatchEx(PCUSBFILTER pDevice, uintptr_t *puId, bool fRemoveFltIfOneShot, bool *pfFilter, bool *pfIsOneShot); 40 VBOXUSBFILTER_CONTEXT VBoxUSBFilterGetOwner(uintptr_t uId); 31 41 32 42 RT_C_DECLS_END -
trunk/src/VBox/HostDrivers/VBoxUSB/win/Install/USBInstall.cpp
r31898 r36941 33 33 #include <stdio.h> 34 34 35 #include <VBox/VBoxDrvCfg-win.h> 36 37 static DECLCALLBACK(void) vboxUsbLog(VBOXDRVCFG_LOG_SEVERITY enmSeverity, char * msg, void * pvContext) 38 { 39 switch (enmSeverity) 40 { 41 case VBOXDRVCFG_LOG_SEVERITY_FLOW: 42 case VBOXDRVCFG_LOG_SEVERITY_REGULAR: 43 break; 44 case VBOXDRVCFG_LOG_SEVERITY_REL: 45 RTPrintf("%s", msg); 46 break; 47 default: 48 break; 49 } 50 } 51 52 static DECLCALLBACK(void) vboxUsbPanic(void * pvPanic) 53 { 54 AssertFailed(); 55 } 56 35 57 int usblibOsCreateService(void); 36 58 … … 43 65 } 44 66 67 VBoxDrvCfgLoggerSet(vboxUsbLog, NULL); 68 VBoxDrvCfgPanicSet(vboxUsbPanic, NULL); 69 45 70 RTPrintf("USB installation\n"); 46 71 … … 49 74 if (RT_SUCCESS(rc)) 50 75 { 51 LPSTR lpszFilePart; 52 TCHAR szFullPath[MAX_PATH]; 53 TCHAR szCurDir[MAX_PATH]; 76 LPWSTR lpszFilePart; 77 WCHAR szFullPath[MAX_PATH]; 54 78 DWORD len; 55 79 56 len = GetFullPathName (".\\VBoxUSB.inf", sizeof(szFullPath), szFullPath, &lpszFilePart);80 len = GetFullPathNameW(L".\\VBoxUSB.inf", RT_ELEMENTS(szFullPath), szFullPath, &lpszFilePart); 57 81 Assert(len); 58 82 59 if (GetCurrentDirectory(sizeof(szCurDir), szCurDir) == 0)60 {61 rc = RTErrConvertFromWin32(GetLastError());62 RTPrintf(" GetCurrentDirectory failed with rc=%Rrc\n", rc);83 HRESULT hr = VBoxDrvCfgInfInstall(szFullPath); 84 if (hr == S_OK) 85 { 86 RTPrintf("Installation successful.\n"); 63 87 } 64 88 else 65 89 { 66 /* Copy INF file to Windows\INF, so Windows will automatically install it when our USB device is detected */ 67 BOOL b = SetupCopyOEMInf(szFullPath, NULL, SPOST_PATH, 0, NULL, 0, NULL, NULL); 68 if (b == FALSE) 69 { 70 rc = RTErrConvertFromWin32(GetLastError()); 71 RTPrintf("SetupCopyOEMInf failed with rc=%Rrc\n", rc); 72 } 73 else 74 { 75 RTPrintf("Installation successful.\n"); 76 } 77 } 78 } 90 rc = -1; 91 } 92 } 93 94 if (RT_SUCCESS(rc)) 95 rc = 0; 79 96 80 97 /** @todo RTR3Term(); */ -
trunk/src/VBox/HostDrivers/VBoxUSB/win/Install/USBUninstall.cpp
r31898 r36941 23 23 #include <setupapi.h> 24 24 #include <newdev.h> 25 25 26 #include <iprt/assert.h> 26 27 #include <iprt/err.h> … … 29 30 #include <iprt/string.h> 30 31 #include <VBox/err.h> 32 #include <VBox/VBoxDrvCfg-win.h> 31 33 #include <stdio.h> 32 34 … … 35 37 int usblibOsDeleteService(void); 36 38 39 static DECLCALLBACK(void) vboxUsbLog(VBOXDRVCFG_LOG_SEVERITY enmSeverity, char * msg, void * pvContext) 40 { 41 switch (enmSeverity) 42 { 43 case VBOXDRVCFG_LOG_SEVERITY_FLOW: 44 case VBOXDRVCFG_LOG_SEVERITY_REGULAR: 45 break; 46 case VBOXDRVCFG_LOG_SEVERITY_REL: 47 printf("%s", msg); 48 break; 49 default: 50 break; 51 } 52 } 53 54 static DECLCALLBACK(void) vboxUsbPanic(void * pvPanic) 55 { 56 AssertFailed(); 57 } 58 37 59 38 60 int __cdecl main(int argc, char **argv) 39 61 { 40 BOOL rc; 41 TCHAR szFullPath[MAX_PATH]; 42 CHAR *lpszFilePart; 43 int len; 62 printf("USB uninstallation\n"); 44 63 45 printf("USB uninstallation\n"); 64 VBoxDrvCfgLoggerSet(vboxUsbLog, NULL); 65 VBoxDrvCfgPanicSet(vboxUsbPanic, NULL); 46 66 47 67 usblibOsStopService(); 48 68 usblibOsDeleteService(); 49 69 50 len = GetFullPathName(".\\VBoxUSB.inf", sizeof(szFullPath), szFullPath, &lpszFilePart); 51 Assert(len); 52 53 /* Remove the inf plus all associated files. */ 54 rc = SetupUninstallOEMInf(szFullPath, SUOI_FORCEDELETE, NULL); 55 if (rc == FALSE) 70 HRESULT hr = VBoxDrvCfgInfUninstallAllF(L"USB", L"USB\\VID_80EE&PID_CAFE", SUOI_FORCEDELETE); 71 if (hr != S_OK) 56 72 { 57 printf("SetupUninstallOEMInf failed with rc=%x\n", GetLastError());73 printf("SetupUninstallOEMInf failed with hr=0x%x\n", hr); 58 74 return 1; 59 75 } 76 77 printf("USB uninstallation succeeded!\n"); 78 60 79 return 0; 61 80 } -
trunk/src/VBox/HostDrivers/VBoxUSB/win/Makefile.kmk
r35381 r36941 42 42 VBoxUSB_LDFLAGS.amd64 = -Entry:DriverEntry 43 43 VBoxUSB_SOURCES = \ 44 Device/vboxusb.cpp \ 45 Device/vboxdev.cpp \ 46 Device/vboxpnp.cpp \ 47 Device/vboxpwr.cpp \ 48 Device/vboxrwr.cpp \ 49 Device/vboxusb.rc 44 dev/VBoxUsbDev.cpp \ 45 dev/VBoxUsbRt.cpp \ 46 dev/VBoxUsbPnP.cpp \ 47 dev/VBoxUsbPwr.cpp \ 48 cmn/VBoxUsbTool.cpp \ 49 cmn/VBoxDrvTool.cpp \ 50 dev/VBoxUsbDev.rc 50 51 VBoxUSB_LIBS = \ 51 $(PATH_SDK_W2K3DDK_LIB)/ntoskrnl.lib \52 $(PATH_SDK_W2K3DDK_LIB)/hal.lib \53 $(PATH_LIB)/RuntimeR0Drv$(VBOX_SUFF_LIB) \54 $(TARGET_usbd)55 56 #57 # VBoxUSBFlt58 #59 VBoxUSBFlt_TEMPLATE = VBOXR0DRV60 VBoxUSBFlt_SDKS = W2K3DDK WINPSDKINCS61 VBoxUSBFlt_DEFS = IN_SUP_R0 i386=1 STD_CALL CONDITION_HANDLING=1 NT_INST=0 \62 WIN32=100 _NT1X_=100 WINNT=1 _WIN32_WINNT=0x0501 WINVER=0x0501 _WIN32_IE=0x0600 WIN32_LEAN_AND_MEAN=163 VBoxUSBFlt_LDFLAGS.x86 = -Entry:DriverEntry@864 VBoxUSBFlt_LDFLAGS.amd64 = -Entry:DriverEntry65 VBoxUSBFlt_SOURCES = \66 Filter/USBFilter.c \67 Filter/USBFilt-win32.cpp \68 Filter/USBFilter.rc69 VBoxUSBFlt_LIBS = \70 52 $(PATH_SDK_W2K3DDK_LIB)/ntoskrnl.lib \ 71 53 $(PATH_SDK_W2K3DDK_LIB)/hal.lib \ … … 87 69 VBoxUSBMon_LDFLAGS.x86 = -Entry:DriverEntry@8 88 70 VBoxUSBMon_LDFLAGS.amd64 = -Entry:DriverEntry 71 ifdef VBOX_USBMON_WITH_FILTER_AUTOAPPLY 72 VBoxUSBMon_DEFS += VBOX_USBMON_WITH_FILTER_AUTOAPPLY 73 endif 89 74 VBoxUSBMon_SOURCES = \ 90 Monitor/USBMon.cpp \ 91 Monitor/USBMonFlt.cpp \ 75 mon/VBoxUsbMon.cpp \ 76 mon/VBoxUsbFlt.cpp \ 77 mon/VBoxUsbHook.cpp \ 78 cmn/VBoxUsbTool.cpp \ 79 cmn/VBoxDrvTool.cpp \ 92 80 ../USBFilter.cpp \ 93 81 ../VBoxUSBFilterMgr.cpp \ 94 Monitor/USBMon.rc82 mon/VBoxUsbMon.rc 95 83 VBoxUSBMon_LIBS = \ 96 84 $(PATH_SDK_W2K3DDK_LIB)/ntoskrnl.lib \ … … 112 100 $(PATH_SDK_W2K3DDK_LIB)/newdev.lib \ 113 101 $(LIB_RUNTIME) \ 114 $(PATH_LIB)/SUPR3$(VBOX_SUFF_LIB) 102 $(PATH_LIB)/SUPR3$(VBOX_SUFF_LIB) \ 103 $(TARGET_VBoxDrvCfg) 104 115 105 116 106 # … … 127 117 $(PATH_SDK_W2K3DDK_LIB)/newdev.lib \ 128 118 $(LIB_RUNTIME) \ 129 $(PATH_LIB)/SUPR3$(VBOX_SUFF_LIB) 119 $(PATH_LIB)/SUPR3$(VBOX_SUFF_LIB) \ 120 $(TARGET_VBoxDrvCfg) 130 121 131 122 # … … 142 133 $(PATH_SDK_W2K3DDK_LIB)/newdev.lib \ 143 134 $(LIB_RUNTIME) \ 144 $(PATH_LIB)/SUPR3$(VBOX_SUFF_LIB) 145 135 $(PATH_LIB)/SUPR3$(VBOX_SUFF_LIB) \ 136 $(TARGET_VBoxDrvCfg) 137 146 138 # 147 139 # Install the INF files. … … 157 149 $(PATH_TARGET)/VBoxUSBMonCat.dir 158 150 159 $(PATH_TARGET)/VBoxUSBCat.dir/VBoxUSB.inf: $(PATH_SUB_CURRENT)/ Device/VBoxUSB.inf $(MAKEFILE_CURRENT) | $$(dir $$@)151 $(PATH_TARGET)/VBoxUSBCat.dir/VBoxUSB.inf: $(PATH_SUB_CURRENT)/dev/VBoxUSB.inf $(MAKEFILE_CURRENT) | $$(dir $$@) 160 152 $(call MSG_GENERATE,install-infs,$@,$<) 161 153 $(call VBOX_EDIT_INF_FN,$<,$@) 162 154 163 $(PATH_TARGET)/VBoxUSBMonCat.dir/VBoxUSBMon.inf: $(PATH_SUB_CURRENT)/Monitor/VBoxUSBMon.inf $(MAKEFILE_CURRENT) | $$(dir $$@) 164 $(call MSG_GENERATE,install-infs,$@,$<) 165 $(call VBOX_EDIT_INF_FN,$<,$@) 166 167 $(PATH_TARGET)/VBoxUSBFltCat.dir/VBoxUSBFlt.inf: $(PATH_SUB_CURRENT)/Filter/VBoxUSBFlt.inf $(MAKEFILE_CURRENT) | $$(dir $$@) 155 $(PATH_TARGET)/VBoxUSBMonCat.dir/VBoxUSBMon.inf: $(PATH_SUB_CURRENT)/mon/VBoxUSBMon.inf $(MAKEFILE_CURRENT) | $$(dir $$@) 168 156 $(call MSG_GENERATE,install-infs,$@,$<) 169 157 $(call VBOX_EDIT_INF_FN,$<,$@) -
trunk/src/VBox/HostDrivers/VBoxUSB/win/testcase/USBTest.cpp
r31898 r36941 31 31 #include <stdio.h> 32 32 #include <VBox/usblib.h> 33 #include <VBox/VBoxDrvCfg-win.h> 33 34 34 35 /** Handle to the open device. */ … … 46 47 int usbMonStartService(void) 47 48 { 48 /* 49 * Check if the driver service is there. 50 */ 51 SC_HANDLE hSMgr = OpenSCManager(NULL, NULL, SERVICE_QUERY_STATUS | SERVICE_START); 52 if (hSMgr == NULL) 53 { 54 AssertMsgFailed(("couldn't open service manager in SERVICE_QUERY_CONFIG | SERVICE_QUERY_STATUS mode!\n")); 49 HRESULT hr = VBoxDrvCfgSvcStart(USBMON_SERVICE_NAME_W); 50 if (hr != S_OK) 51 { 52 AssertMsgFailed(("couldn't start service, hr (0x%x)\n", hr)); 55 53 return -1; 56 54 } 57 58 /* 59 * Try open our service to check it's status. 60 */ 61 SC_HANDLE hService = OpenService(hSMgr, USBMON_SERVICE_NAME, SERVICE_QUERY_STATUS | SERVICE_START); 62 if (!hService) 63 return -1; 64 65 /* 66 * Check if open and on demand create succeeded. 67 */ 68 int rc = -1; 69 if (hService) 70 { 71 72 /* 73 * Query service status to see if we need to start it or not. 74 */ 75 SERVICE_STATUS Status; 76 BOOL fRc = QueryServiceStatus(hService, &Status); 77 Assert(fRc); 78 if ( Status.dwCurrentState != SERVICE_RUNNING 79 && Status.dwCurrentState != SERVICE_START_PENDING) 80 { 81 /* 82 * Start it. 83 */ 84 printf("usbMonStartService -> start it\n"); 85 86 fRc = StartService(hService, 0, NULL); 87 DWORD LastError = GetLastError(); NOREF(LastError); 88 AssertMsg(fRc, ("StartService failed with LastError=%Rwa\n", LastError)); 89 if (fRc) 90 g_fStartedService = true; 91 } 92 93 /* 94 * Wait for the service to finish starting. 95 * We'll wait for 10 seconds then we'll give up. 96 */ 97 QueryServiceStatus(hService, &Status); 98 if (Status.dwCurrentState == SERVICE_START_PENDING) 99 { 100 int iWait; 101 for (iWait = 100; iWait > 0 && Status.dwCurrentState == SERVICE_START_PENDING; iWait--) 102 { 103 Sleep(100); 104 QueryServiceStatus(hService, &Status); 105 } 106 DWORD LastError = GetLastError(); NOREF(LastError); 107 AssertMsg(Status.dwCurrentState != SERVICE_RUNNING, 108 ("Failed to start. LastError=%Rwa iWait=%d status=%d\n", 109 LastError, iWait, Status.dwCurrentState)); 110 } 111 112 if (Status.dwCurrentState == SERVICE_RUNNING) 113 rc = 0; 114 115 /* 116 * Close open handles. 117 */ 118 CloseServiceHandle(hService); 119 } 120 else 121 { 122 DWORD LastError = GetLastError(); NOREF(LastError); 123 AssertMsgFailed(("OpenService failed! LastError=%Rwa\n", LastError)); 124 } 125 if (!CloseServiceHandle(hSMgr)) 126 AssertFailed(); 127 128 return rc; 55 return 0; 129 56 } 130 57 … … 147 74 if (hSMgr) 148 75 { 149 SC_HANDLE hService = OpenService (hSMgr, USBMON_SERVICE_NAME, SERVICE_STOP | SERVICE_QUERY_STATUS);76 SC_HANDLE hService = OpenServiceW(hSMgr, USBMON_SERVICE_NAME_W, SERVICE_STOP | SERVICE_QUERY_STATUS); 150 77 if (hService) 151 78 { -
trunk/src/VBox/HostDrivers/win/cfg/VBoxDrvCfg.cpp
r36871 r36941 637 637 { 638 638 winEr = GetLastError(); 639 Assert(winEr == ERROR_CLASS_MISMATCH);639 // Assert(winEr == ERROR_CLASS_MISMATCH); 640 640 if (winEr != ERROR_CLASS_MISMATCH) 641 641 { … … 714 714 } 715 715 716 /* time intervals in milliseconds */ 717 /* max time to wait for the service to startup */ 718 #define VBOXDRVCFG_SVC_WAITSTART_TIME 10000 719 /* sleep time before service status polls */ 720 #define VBOXDRVCFG_SVC_WAITSTART_TIME_PERIOD 100 721 /* number of service start polls */ 722 #define VBOXDRVCFG_SVC_WAITSTART_RETRIES (VBOXDRVCFG_SVC_WAITSTART_TIME/VBOXDRVCFG_SVC_WAITSTART_TIME_PERIOD) 723 724 VBOXDRVCFG_DECL(HRESULT) VBoxDrvCfgSvcStart(LPCWSTR lpszSvcName) 725 { 726 SC_HANDLE hMgr = OpenSCManager(NULL, NULL, SERVICE_QUERY_STATUS | SERVICE_START); 727 if (hMgr == NULL) 728 { 729 DWORD winEr = GetLastError(); 730 LogRel((__FUNCTION__": OpenSCManager failed, winEr (%d)\n", winEr)); 731 return HRESULT_FROM_WIN32(winEr); 732 } 733 734 HRESULT hr = S_OK; 735 SC_HANDLE hSvc = OpenServiceW(hMgr, lpszSvcName, SERVICE_QUERY_STATUS | SERVICE_START); 736 if (hSvc) 737 { 738 do 739 { 740 SERVICE_STATUS Status; 741 BOOL fRc = QueryServiceStatus(hSvc, &Status); 742 if (!fRc) 743 { 744 DWORD winEr = GetLastError(); 745 LogRel((__FUNCTION__": QueryServiceStatus failed winEr (%d)\n", winEr)); 746 hr = HRESULT_FROM_WIN32(winEr); 747 break; 748 } 749 750 if (Status.dwCurrentState != SERVICE_RUNNING && Status.dwCurrentState != SERVICE_START_PENDING) 751 { 752 LogRel(("Starting service (%S)\n", lpszSvcName)); 753 754 fRc = StartService(hSvc, 0, NULL); 755 if (!fRc) 756 { 757 DWORD winEr = GetLastError(); 758 LogRel((__FUNCTION__": StartService failed winEr (%d)\n", winEr)); 759 hr = HRESULT_FROM_WIN32(winEr); 760 break; 761 } 762 } 763 764 fRc = QueryServiceStatus(hSvc, &Status); 765 if (!fRc) 766 { 767 DWORD winEr = GetLastError(); 768 LogRel((__FUNCTION__": QueryServiceStatus failed winEr (%d)\n", winEr)); 769 hr = HRESULT_FROM_WIN32(winEr); 770 break; 771 } 772 773 if (Status.dwCurrentState == SERVICE_START_PENDING) 774 { 775 for (int i = 0; i < VBOXDRVCFG_SVC_WAITSTART_RETRIES; ++i) 776 { 777 Sleep(VBOXDRVCFG_SVC_WAITSTART_TIME_PERIOD); 778 fRc = QueryServiceStatus(hSvc, &Status); 779 if (!fRc) 780 { 781 DWORD winEr = GetLastError(); 782 LogRel((__FUNCTION__": QueryServiceStatus failed winEr (%d)\n", winEr)); 783 hr = HRESULT_FROM_WIN32(winEr); 784 break; 785 } 786 else if (Status.dwCurrentState != SERVICE_START_PENDING) 787 break; 788 } 789 } 790 791 if (hr != S_OK || Status.dwCurrentState != SERVICE_RUNNING) 792 { 793 LogRel((__FUNCTION__": Failed to start the service\n")); 794 hr = E_FAIL; 795 break; 796 } 797 798 } while (0); 799 800 CloseServiceHandle(hSvc); 801 } 802 else 803 { 804 DWORD winEr = GetLastError(); 805 LogRel((__FUNCTION__": OpenServiceW failed, winEr (%d)\n", winEr)); 806 hr = HRESULT_FROM_WIN32(winEr); 807 } 808 809 CloseServiceHandle(hMgr); 810 811 return hr; 812 } -
trunk/src/VBox/Main/Makefile.kmk
r36495 r36941 382 382 $(PATH_TOOL_$(VBOX_VCC_TOOL)_LIB)/comsupp.lib \ 383 383 $(PATH_SDK_WINPSDK_LIB)/WbemUuid.Lib 384 ifdef VBOX_NETFLT_ONDEMAND_BIND385 VBoxSVC_DEFS.win += VBOX_NETFLT_ONDEMAND_BIND386 endif387 384 endif 388 385 VBoxSVC_LDFLAGS.darwin = -framework IOKit -framework SystemConfiguration -
trunk/src/VBox/Main/src-server/win/USBProxyServiceWindows.cpp
r35368 r36941 143 143 int USBProxyServiceWindows::captureDevice(HostUSBDevice *aDevice) 144 144 { 145 AssertReturn(aDevice, VERR_GENERAL_FAILURE); 146 AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 147 Assert(aDevice->getUnistate() == kHostUSBDeviceState_Capturing); 148 149 /** @todo pass up a one-shot filter like on darwin? */ 150 USHORT vendorId, productId, revision; 151 152 HRESULT rc; 153 154 rc = aDevice->COMGETTER(VendorId)(&vendorId); 155 AssertComRCReturn(rc, VERR_INTERNAL_ERROR); 156 157 rc = aDevice->COMGETTER(ProductId)(&productId); 158 AssertComRCReturn(rc, VERR_INTERNAL_ERROR); 159 160 rc = aDevice->COMGETTER(Revision)(&revision); 161 AssertComRCReturn(rc, VERR_INTERNAL_ERROR); 162 163 return USBLibCaptureDevice(vendorId, productId, revision); 145 /* 146 * Create a one-shot ignore filter for the device 147 * and trigger a re-enumeration of it. 148 */ 149 USBFILTER Filter; 150 USBFilterInit(&Filter, USBFILTERTYPE_ONESHOT_CAPTURE); 151 initFilterFromDevice(&Filter, aDevice); 152 Log(("USBFILTERIDX_PORT=%#x\n", USBFilterGetNum(&Filter, USBFILTERIDX_PORT))); 153 Log(("USBFILTERIDX_BUS=%#x\n", USBFilterGetNum(&Filter, USBFILTERIDX_BUS))); 154 155 void *pvId = USBLibAddFilter(&Filter); 156 if (!pvId) 157 { 158 AssertMsgFailed(("Add one-shot Filter failed\n")); 159 return VERR_GENERAL_FAILURE; 160 } 161 162 int rc = USBLibRunFilters(); 163 if (!RT_SUCCESS(rc)) 164 { 165 AssertMsgFailed(("Run Filters failed\n")); 166 USBLibRemoveFilter(pvId); 167 return rc; 168 } 169 170 return VINF_SUCCESS; 164 171 } 165 172 … … 167 174 int USBProxyServiceWindows::releaseDevice(HostUSBDevice *aDevice) 168 175 { 169 AssertReturn(aDevice, VERR_GENERAL_FAILURE); 170 AssertReturn(aDevice->isWriteLockOnCurrentThread(), VERR_GENERAL_FAILURE); 171 Assert(aDevice->getUnistate() == kHostUSBDeviceState_ReleasingToHost); 172 173 /** @todo pass up a one-shot filter like on darwin? */ 174 USHORT vendorId, productId, revision; 175 HRESULT rc; 176 177 rc = aDevice->COMGETTER(VendorId)(&vendorId); 178 AssertComRCReturn(rc, VERR_INTERNAL_ERROR); 179 180 rc = aDevice->COMGETTER(ProductId)(&productId); 181 AssertComRCReturn(rc, VERR_INTERNAL_ERROR); 182 183 rc = aDevice->COMGETTER(Revision)(&revision); 184 AssertComRCReturn(rc, VERR_INTERNAL_ERROR); 185 186 Log(("USBProxyServiceWindows::releaseDevice\n")); 187 return USBLibReleaseDevice(vendorId, productId, revision); 176 /* 177 * Create a one-shot ignore filter for the device 178 * and trigger a re-enumeration of it. 179 */ 180 USBFILTER Filter; 181 USBFilterInit(&Filter, USBFILTERTYPE_ONESHOT_IGNORE); 182 initFilterFromDevice(&Filter, aDevice); 183 Log(("USBFILTERIDX_PORT=%#x\n", USBFilterGetNum(&Filter, USBFILTERIDX_PORT))); 184 Log(("USBFILTERIDX_BUS=%#x\n", USBFilterGetNum(&Filter, USBFILTERIDX_BUS))); 185 186 void *pvId = USBLibAddFilter(&Filter); 187 if (!pvId) 188 { 189 AssertMsgFailed(("Add one-shot Filter failed\n")); 190 return VERR_GENERAL_FAILURE; 191 } 192 193 int rc = USBLibRunFilters(); 194 if (!RT_SUCCESS(rc)) 195 { 196 AssertMsgFailed(("Run Filters failed\n")); 197 USBLibRemoveFilter(pvId); 198 return rc; 199 } 200 201 202 return VINF_SUCCESS; 188 203 } 189 204 … … 223 238 int USBProxyServiceWindows::wait(unsigned aMillies) 224 239 { 225 DWORD rc; 226 227 /* Not going to do something fancy where we block in the filter 228 * driver and are woken up when the state has changed. 229 * Would be better, but this is good enough. 230 */ 231 do 232 { 233 rc = WaitForSingleObject(mhEventInterrupt, RT_MIN(aMillies, 100)); 234 if (rc == WAIT_OBJECT_0) 235 return VINF_SUCCESS; 236 /** @todo handle WAIT_FAILED here */ 237 238 if (USBLibHasPendingDeviceChanges() == true) 239 { 240 Log(("wait thread detected usb change\n")); 241 return VINF_SUCCESS; 242 } 243 244 if (aMillies > 100) 245 aMillies -= 100; 246 } 247 while (aMillies > 100); 248 249 return VERR_TIMEOUT; 240 return USBLibWaitChange(aMillies); 250 241 } 251 242 … … 253 244 int USBProxyServiceWindows::interruptWait(void) 254 245 { 255 SetEvent(mhEventInterrupt); 256 return VINF_SUCCESS; 257 } 258 246 return USBLibInterruptWaitChange(); 247 } 259 248 260 249 /**
Note:
See TracChangeset
for help on using the changeset viewer.