VirtualBox

Changeset 36941 in vbox


Ignore:
Timestamp:
May 3, 2011 2:56:08 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
71528
Message:

usb rework

Location:
trunk
Files:
5 deleted
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/VBoxDrvCfg-win.h

    r36536 r36941  
    5252VBOXDRVCFG_DECL(void) VBoxDrvCfgPanicSet(PFNVBOXDRVCFG_PANIC pfnPanic, void *pvPanic);
    5353
     54/* Driver package API*/
    5455VBOXDRVCFG_DECL(HRESULT) VBoxDrvCfgInfInstall(IN LPCWSTR lpszInfPath);
    5556VBOXDRVCFG_DECL(HRESULT) VBoxDrvCfgInfUninstall(IN LPCWSTR lpszInfPath, IN DWORD fFlags);
     
    5758VBOXDRVCFG_DECL(HRESULT) VBoxDrvCfgInfUninstallAllF(IN LPCWSTR lpszClassName, IN LPCWSTR lpszPnPId, IN DWORD fFlags);
    5859
     60/* Service API */
     61VBOXDRVCFG_DECL(HRESULT) VBoxDrvCfgSvcStart(LPCWSTR lpszSvcName);
     62
    5963RT_C_DECLS_END
    6064
  • trunk/include/VBox/usblib-win.h

    r34306 r36941  
    4242#define USBFLT_SYMBOLIC_NAME_STRING      L"\\DosDevices\\VBoxUSBFlt"
    4343
    44 #define USBMON_SERVICE_NAME              "VBoxUSBMon"
     44#define USBMON_SERVICE_NAME_W              L"VBoxUSBMon"
    4545#define USBMON_DEVICE_NAME               "\\\\.\\VBoxUSBMon"
    4646#define USBMON_DEVICE_NAME_NT            L"\\Device\\VBoxUSBMon"
     
    7474#define USBFLT_MINOR_VERSION              3
    7575
    76 #define USBMON_MAJOR_VERSION              1
    77 #define USBMON_MINOR_VERSION              1
    78 
    79 #define USBDRV_MAJOR_VERSION              3
    80 #define USBDRV_MINOR_VERSION              1
     76#define USBMON_MAJOR_VERSION              4
     77#define USBMON_MINOR_VERSION              0
     78
     79#define USBDRV_MAJOR_VERSION              4
     80#define USBDRV_MINOR_VERSION              0
    8181
    8282#define SUPUSB_IOCTL_TEST                 CTL_CODE(FILE_DEVICE_UNKNOWN, 0x601, METHOD_BUFFERED, FILE_WRITE_ACCESS)
     
    103103#define SUPUSBFLT_IOCTL_CAPTURE_DEVICE    CTL_CODE(FILE_DEVICE_UNKNOWN, 0x613, METHOD_BUFFERED, FILE_WRITE_ACCESS)
    104104#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)
    105108
    106109#pragma pack(4)
     
    109112#define MAX_USB_SERIAL_STRING           64
    110113
    111 typedef struct
    112 {
     114/* a user-mode handle that could be used for retriving device information
     115 * from the monitor driver */
     116typedef void* HVBOXUSBDEVUSR;
     117
     118typedef struct
     119{
     120    HVBOXUSBDEVUSR  hDevice;
    113121    uint16_t        vid, did, rev;
    114122    char            serial_hash[MAX_USB_SERIAL_STRING];
     
    117125    uint8_t         fHiSpeed;
    118126} USBSUP_GETDEV, *PUSBSUP_GETDEV;
     127
     128typedef struct
     129{
     130    USBDEVICESTATE enmState;
     131} USBSUP_GETDEV_MON, *PUSBSUP_GETDEV_MON;
    119132
    120133typedef struct
     
    231244} USBSUP_URB, *PUSBSUP_URB;
    232245
     246typedef 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
     257typedef 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
     266typedef struct
     267{
     268        USBSUP_DEVID DevId;
     269        char szName[512];
     270        USBDEVICESTATE enmState;
     271    bool fHiSpeed;
     272} USBSUP_DEVINFO, *PUSBSUP_DEVINFO;
     273
     274typedef struct
     275{
     276    int rc;
     277    uint32_t cDevices;
     278    USBSUP_DEVINFO aDevices[1];
     279} USBSUP_GET_DEVICES, *PUSBSUP_GET_DEVICES;
     280
    233281#pragma pack()                          /* paranoia */
    234282
     
    249297 * @param pcbNumDevices     Number of USB devices in the list
    250298 */
    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);
     299USBLIB_DECL(int) USBLibGetDevices(PUSBDEVICE *ppDevices, uint32_t *pcbNumDevices);
     300
     301USBLIB_DECL(int) USBLibWaitChange(RTMSINTERVAL cMillies);
     302
     303USBLIB_DECL(int) USBLibInterruptWaitChange();
     304
     305USBLIB_DECL(int) USBLibRunFilters();
    279306
    280307/** @} */
  • trunk/src/VBox/Devices/Makefile.kmk

    r36912 r36941  
    8484 ifdef VBOX_WITH_USB
    8585  VBoxDDU_LIBS           += \
    86         $(PATH_LIB)/USBLib$(VBOX_SUFF_LIB)
     86        $(PATH_LIB)/USBLib$(VBOX_SUFF_LIB) \
     87        $(PATH_LIB)/VBoxDrvCfg$(VBOX_SUFF_LIB)
    8788 endif
    8889 ifeq ($(KBUILD_TARGET),l4)
  • trunk/src/VBox/HostDrivers/VBoxUSB/Makefile.kmk

    r35440 r36941  
    4747        solaris/USBLib-solaris.cpp
    4848USBLib_SOURCES.win = \
    49         win/USBLib-win.cpp
    50 
     49        win/lib/VBoxUsbLib-win.cpp
    5150
    5251#
  • trunk/src/VBox/HostDrivers/VBoxUSB/VBoxUSBFilterMgr.cpp

    r33540 r36941  
    7979    USBFILTER       Core;
    8080    /** The filter owner. */
    81     RTPROCESS       Owner;
     81    VBOXUSBFILTER_CONTEXT       Owner;
    8282    /** The filter Id. */
    8383    uintptr_t       uId;
     
    146146{
    147147    USBFilterDelete(&pFilter->Core);
    148     pFilter->Owner = NIL_RTPROCESS;
     148    pFilter->Owner = VBOXUSBFILTER_CONTEXT_NIL;
    149149    pFilter->pNext = NULL;
    150150    RTMemFree(pFilter);
     
    189189 * @param   puId        Where to store the filter ID.
    190190 */
    191 int VBoxUSBFilterAdd(PCUSBFILTER pFilter, RTPROCESS Owner, uintptr_t *puId)
     191int VBoxUSBFilterAdd(PCUSBFILTER pFilter, VBOXUSBFILTER_CONTEXT Owner, uintptr_t *puId)
    192192{
    193193    /*
     
    197197    if (RT_FAILURE(rc))
    198198        return rc;
    199     if (!Owner || Owner == NIL_RTPROCESS)
     199    if (!Owner || Owner == VBOXUSBFILTER_CONTEXT_NIL)
    200200        return VERR_INVALID_PARAMETER;
    201201    if (!VALID_PTR(puId))
     
    247247 *                      Returned by VBoxUSBFilterAdd().
    248248 */
    249 int VBoxUSBFilterRemove(RTPROCESS Owner, uintptr_t uId)
     249int VBoxUSBFilterRemove(VBOXUSBFILTER_CONTEXT Owner, uintptr_t uId)
    250250{
    251251    /*
     
    254254    if (!uId)
    255255        return VERR_INVALID_PARAMETER;
    256     if (!Owner || Owner == NIL_RTPROCESS)
     256    if (!Owner || Owner == VBOXUSBFILTER_CONTEXT_NIL)
    257257        return VERR_INVALID_PARAMETER;
    258258
     
    302302}
    303303
     304VBOXUSBFILTER_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}
    304339
    305340/**
     
    311346 * @param   Owner       The owner
    312347 */
    313 void VBoxUSBFilterRemoveOwner(RTPROCESS Owner)
     348void VBoxUSBFilterRemoveOwner(VBOXUSBFILTER_CONTEXT Owner)
    314349{
    315350    /*
     
    362397}
    363398
    364 
    365399/**
    366400 * 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.
    369404 * @param   pDevice     The device data as a filter structure.
    370405 *                      See USBFilterMatch for how to construct this.
    371406 * @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 */
     409VBOXUSBFILTER_CONTEXT VBoxUSBFilterMatchEx(PCUSBFILTER pDevice, uintptr_t *puId, bool fRemoveFltIfOneShot, bool *pfFilter, bool *pfIsOneShot)
    374410{
    375411    /*
     
    377413     */
    378414    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;
    380420
    381421    /*
     
    403443                if (puId)
    404444                    *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);
    409448
    410449                if (    i == USBFILTERTYPE_ONESHOT_IGNORE
    411450                    ||  i == USBFILTERTYPE_ONESHOT_CAPTURE)
    412451                {
    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                    }
    421463                }
    422464
     
    425467                if (    i == USBFILTERTYPE_ONESHOT_IGNORE
    426468                    ||  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                }
    428482                return Owner;
    429483            }
     
    435489
    436490    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 */
     502VBOXUSBFILTER_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  
    2323RT_C_DECLS_BEGIN
    2424
     25#if defined(RT_OS_WINDOWS)
     26typedef struct VBOXUSBFLTCTX *VBOXUSBFILTER_CONTEXT;
     27#define VBOXUSBFILTER_CONTEXT_NIL NULL
     28#else
     29typedef RTPROCESS VBOXUSBFILTER_CONTEXT;
     30#define VBOXUSBFILTER_CONTEXT_NIL NIL_RTPROCESS
     31#endif
     32
    2533int     VBoxUSBFilterInit(void);
    2634void    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);
     35void    VBoxUSBFilterRemoveOwner(VBOXUSBFILTER_CONTEXT Owner);
     36int     VBoxUSBFilterAdd(PCUSBFILTER pFilter, VBOXUSBFILTER_CONTEXT Owner, uintptr_t *puId);
     37int     VBoxUSBFilterRemove(VBOXUSBFILTER_CONTEXT Owner, uintptr_t uId);
     38VBOXUSBFILTER_CONTEXT VBoxUSBFilterMatch(PCUSBFILTER pDevice, uintptr_t *puId);
     39VBOXUSBFILTER_CONTEXT VBoxUSBFilterMatchEx(PCUSBFILTER pDevice, uintptr_t *puId, bool fRemoveFltIfOneShot, bool *pfFilter, bool *pfIsOneShot);
     40VBOXUSBFILTER_CONTEXT VBoxUSBFilterGetOwner(uintptr_t uId);
    3141
    3242RT_C_DECLS_END
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/Install/USBInstall.cpp

    r31898 r36941  
    3333#include <stdio.h>
    3434
     35#include <VBox/VBoxDrvCfg-win.h>
     36
     37static 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
     52static DECLCALLBACK(void) vboxUsbPanic(void * pvPanic)
     53{
     54    AssertFailed();
     55}
     56
    3557int usblibOsCreateService(void);
    3658
     
    4365    }
    4466
     67    VBoxDrvCfgLoggerSet(vboxUsbLog, NULL);
     68    VBoxDrvCfgPanicSet(vboxUsbPanic, NULL);
     69
    4570    RTPrintf("USB installation\n");
    4671
     
    4974    if (RT_SUCCESS(rc))
    5075    {
    51         LPSTR  lpszFilePart;
    52         TCHAR  szFullPath[MAX_PATH];
    53         TCHAR  szCurDir[MAX_PATH];
     76        LPWSTR  lpszFilePart;
     77        WCHAR  szFullPath[MAX_PATH];
    5478        DWORD  len;
    5579
    56         len = GetFullPathName(".\\VBoxUSB.inf", sizeof(szFullPath), szFullPath, &lpszFilePart);
     80        len = GetFullPathNameW(L".\\VBoxUSB.inf", RT_ELEMENTS(szFullPath), szFullPath, &lpszFilePart);
    5781        Assert(len);
    5882
    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");
    6387        }
    6488        else
    6589        {
    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;
    7996
    8097    /** @todo RTR3Term(); */
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/Install/USBUninstall.cpp

    r31898 r36941  
    2323#include <setupapi.h>
    2424#include <newdev.h>
     25
    2526#include <iprt/assert.h>
    2627#include <iprt/err.h>
     
    2930#include <iprt/string.h>
    3031#include <VBox/err.h>
     32#include <VBox/VBoxDrvCfg-win.h>
    3133#include <stdio.h>
    3234
     
    3537int usblibOsDeleteService(void);
    3638
     39static 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
     54static DECLCALLBACK(void) vboxUsbPanic(void * pvPanic)
     55{
     56    AssertFailed();
     57}
     58
    3759
    3860int __cdecl main(int argc, char **argv)
    3961{
    40     BOOL   rc;
    41     TCHAR  szFullPath[MAX_PATH];
    42     CHAR  *lpszFilePart;
    43     int    len;
     62    printf("USB uninstallation\n");
    4463
    45     printf("USB uninstallation\n");
     64    VBoxDrvCfgLoggerSet(vboxUsbLog, NULL);
     65    VBoxDrvCfgPanicSet(vboxUsbPanic, NULL);
    4666
    4767    usblibOsStopService();
    4868    usblibOsDeleteService();
    4969
    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)
    5672    {
    57         printf("SetupUninstallOEMInf failed with rc=%x\n", GetLastError());
     73        printf("SetupUninstallOEMInf failed with hr=0x%x\n", hr);
    5874        return 1;
    5975    }
     76
     77    printf("USB uninstallation succeeded!\n");
     78
    6079    return 0;
    6180}
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/Makefile.kmk

    r35381 r36941  
    4242VBoxUSB_LDFLAGS.amd64 = -Entry:DriverEntry
    4343VBoxUSB_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
    5051VBoxUSB_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 # VBoxUSBFlt
    58 #
    59 VBoxUSBFlt_TEMPLATE    = VBOXR0DRV
    60 VBoxUSBFlt_SDKS        = W2K3DDK WINPSDKINCS
    61 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=1
    63 VBoxUSBFlt_LDFLAGS.x86 = -Entry:DriverEntry@8
    64 VBoxUSBFlt_LDFLAGS.amd64 = -Entry:DriverEntry
    65 VBoxUSBFlt_SOURCES     = \
    66         Filter/USBFilter.c  \
    67         Filter/USBFilt-win32.cpp  \
    68         Filter/USBFilter.rc
    69 VBoxUSBFlt_LIBS        = \
    7052        $(PATH_SDK_W2K3DDK_LIB)/ntoskrnl.lib \
    7153        $(PATH_SDK_W2K3DDK_LIB)/hal.lib \
     
    8769VBoxUSBMon_LDFLAGS.x86 = -Entry:DriverEntry@8
    8870VBoxUSBMon_LDFLAGS.amd64 = -Entry:DriverEntry
     71ifdef VBOX_USBMON_WITH_FILTER_AUTOAPPLY
     72 VBoxUSBMon_DEFS      += VBOX_USBMON_WITH_FILTER_AUTOAPPLY
     73endif
    8974VBoxUSBMon_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 \
    9280        ../USBFilter.cpp \
    9381        ../VBoxUSBFilterMgr.cpp \
    94         Monitor/USBMon.rc
     82        mon/VBoxUsbMon.rc
    9583VBoxUSBMon_LIBS        = \
    9684        $(PATH_SDK_W2K3DDK_LIB)/ntoskrnl.lib \
     
    112100        $(PATH_SDK_W2K3DDK_LIB)/newdev.lib \
    113101        $(LIB_RUNTIME) \
    114         $(PATH_LIB)/SUPR3$(VBOX_SUFF_LIB)
     102        $(PATH_LIB)/SUPR3$(VBOX_SUFF_LIB) \
     103        $(TARGET_VBoxDrvCfg)
     104       
    115105
    116106#
     
    127117        $(PATH_SDK_W2K3DDK_LIB)/newdev.lib \
    128118        $(LIB_RUNTIME) \
    129         $(PATH_LIB)/SUPR3$(VBOX_SUFF_LIB)
     119        $(PATH_LIB)/SUPR3$(VBOX_SUFF_LIB) \
     120    $(TARGET_VBoxDrvCfg)
    130121
    131122#
     
    142133        $(PATH_SDK_W2K3DDK_LIB)/newdev.lib \
    143134        $(LIB_RUNTIME) \
    144         $(PATH_LIB)/SUPR3$(VBOX_SUFF_LIB)
    145 
     135        $(PATH_LIB)/SUPR3$(VBOX_SUFF_LIB) \
     136        $(TARGET_VBoxDrvCfg)
     137       
    146138#
    147139# Install the INF files.
     
    157149        $(PATH_TARGET)/VBoxUSBMonCat.dir
    158150
    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 $$@)
    160152        $(call MSG_GENERATE,install-infs,$@,$<)
    161153        $(call VBOX_EDIT_INF_FN,$<,$@)
    162154
    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 $$@)
    168156        $(call MSG_GENERATE,install-infs,$@,$<)
    169157        $(call VBOX_EDIT_INF_FN,$<,$@)
  • trunk/src/VBox/HostDrivers/VBoxUSB/win/testcase/USBTest.cpp

    r31898 r36941  
    3131#include <stdio.h>
    3232#include <VBox/usblib.h>
     33#include <VBox/VBoxDrvCfg-win.h>
    3334
    3435/** Handle to the open device. */
     
    4647int usbMonStartService(void)
    4748{
    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));
    5553        return -1;
    5654    }
    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;
    12956}
    13057
     
    14774    if (hSMgr)
    14875    {
    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);
    15077        if (hService)
    15178        {
  • trunk/src/VBox/HostDrivers/win/cfg/VBoxDrvCfg.cpp

    r36871 r36941  
    637637    {
    638638        winEr = GetLastError();
    639         Assert(winEr == ERROR_CLASS_MISMATCH);
     639//        Assert(winEr == ERROR_CLASS_MISMATCH);
    640640        if (winEr != ERROR_CLASS_MISMATCH)
    641641        {
     
    714714}
    715715
     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
     724VBOXDRVCFG_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  
    382382        $(PATH_TOOL_$(VBOX_VCC_TOOL)_LIB)/comsupp.lib \
    383383        $(PATH_SDK_WINPSDK_LIB)/WbemUuid.Lib
    384  ifdef VBOX_NETFLT_ONDEMAND_BIND
    385   VBoxSVC_DEFS.win += VBOX_NETFLT_ONDEMAND_BIND
    386  endif
    387384endif
    388385VBoxSVC_LDFLAGS.darwin    = -framework IOKit -framework SystemConfiguration
  • trunk/src/VBox/Main/src-server/win/USBProxyServiceWindows.cpp

    r35368 r36941  
    143143int USBProxyServiceWindows::captureDevice(HostUSBDevice *aDevice)
    144144{
    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;
    164171}
    165172
     
    167174int USBProxyServiceWindows::releaseDevice(HostUSBDevice *aDevice)
    168175{
    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;
    188203}
    189204
     
    223238int USBProxyServiceWindows::wait(unsigned aMillies)
    224239{
    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);
    250241}
    251242
     
    253244int USBProxyServiceWindows::interruptWait(void)
    254245{
    255     SetEvent(mhEventInterrupt);
    256     return VINF_SUCCESS;
    257 }
    258 
     246    return USBLibInterruptWaitChange();
     247}
    259248
    260249/**
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette