/** @file
*
* VBox host drivers - USB drivers - Filter & driver installation
*
* Installation code
*
* Copyright (C) 2006-2011 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <windows.h>
#include <setupapi.h>
#include <newdev.h>
#include <stdio.h>
#include <VBox/VBoxDrvCfg-win.h>
/** Handle to the open device. */
/** Flags whether or not we started the service. */
static bool g_fStartedService = false;
/**
* Attempts to start the service, creating it if necessary.
*
* @returns 0 on success.
* @returns -1 on failure.
* @param fRetry Indicates retry call.
*/
int usbMonStartService(void)
{
{
return -1;
}
return 0;
}
/**
* Stops a possibly running service.
*
* @returns 0 on success.
* @returns -1 on failure.
*/
int usbMonStopService(void)
{
printf("usbMonStopService\n");
/*
* Assume it didn't exist, so we'll create the service.
*/
if (hSMgr)
{
SC_HANDLE hService = OpenServiceW(hSMgr, USBMON_SERVICE_NAME_W, SERVICE_STOP | SERVICE_QUERY_STATUS);
if (hService)
{
/*
* Stop the service.
*/
rc = 0;
{
{
Sleep(100);
}
rc = 0;
else
}
else
{
AssertMsgFailed(("ControlService failed with LastError=%Rwa. status=%d\n", LastError, Status.dwCurrentState));
}
}
else if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST)
rc = 0;
else
{
}
}
return rc;
}
/**
* Release specified USB device to the host.
*
* @returns VBox status code
* @param usVendorId Vendor id
* @param usProductId Product id
* @param usRevision Revision
*/
{
if (!DeviceIoControl(g_hUSBMonitor, SUPUSBFLT_IOCTL_RELEASE_DEVICE, &release, sizeof(release), NULL, 0, &cbReturned, NULL))
{
return RTErrConvertFromWin32(GetLastError());
}
return VINF_SUCCESS;
}
/**
* Add USB device filter
*
* @returns VBox status code.
* @param pszVendor Vendor filter string
* @param pszProduct Product filter string
* @param pszRevision Revision filter string
* @param ppID Pointer to filter id
*/
int usbMonInsertFilter(const char *pszVendor, const char *pszProduct, const char *pszRevision, void **ppID)
{
if (!DeviceIoControl(g_hUSBMonitor, SUPUSBFLT_IOCTL_ADD_FILTER, &filter, sizeof(filter), &flt_add, sizeof(flt_add), &cbReturned, NULL))
{
return RTErrConvertFromWin32(GetLastError());
}
return VINF_SUCCESS;
}
/**
* Remove USB device filter
*
* @returns VBox status code.
* @param aID Filter id
*/
{
if (!DeviceIoControl(g_hUSBMonitor, SUPUSBFLT_IOCTL_REMOVE_FILTER, &uId, sizeof(uId), NULL, 0,&cbReturned, NULL))
{
return RTErrConvertFromWin32(GetLastError());
}
return VINF_SUCCESS;
}
/**
* Initialize the USB monitor
*
* @returns VBox status code.
*/
int usbMonitorInit()
{
int rc;
printf("usbproxy: usbLibInit\n");
NULL, // no SECURITY_ATTRIBUTES structure
OPEN_EXISTING, // No special create flags
NULL); // No template file
if (g_hUSBMonitor == INVALID_HANDLE_VALUE)
{
NULL, // no SECURITY_ATTRIBUTES structure
OPEN_EXISTING, // No special create flags
NULL); // No template file
if (g_hUSBMonitor == INVALID_HANDLE_VALUE)
{
/* AssertFailed(); */
goto failure;
}
}
/*
* Check the version
*/
cbReturned = 0;
if (!DeviceIoControl(g_hUSBMonitor, SUPUSBFLT_IOCTL_GET_VERSION, NULL, 0,&version, sizeof(version), &cbReturned, NULL))
{
goto failure;
}
{
printf("usbproxy: Filter driver version mismatch!!\n");
goto failure;
}
return VINF_SUCCESS;
if (g_hUSBMonitor != INVALID_HANDLE_VALUE)
{
}
return rc;
}
/**
* Terminate the USB monitor
*
* @returns VBox status code.
*/
int usbMonitorTerm()
{
if (g_hUSBMonitor != INVALID_HANDLE_VALUE)
{
}
/*
* If we started the service we might consider stopping it too.
*
* Since this won't work unless the process starting it is the
* last user we might wanna skip this...
*/
if (g_fStartedService)
{
g_fStartedService = false;
}
return VINF_SUCCESS;
}
{
int rc;
printf("USB test\n");
rc = usbMonitorInit();
printf("Waiting to capture device\n");
getchar();
printf("Releasing device\n");
rc = usbMonitorTerm();
return 0;
}