UsbDk: Make device enumeration return more generic structure
This patch makes device enumeration API return array of device info structures instead of array of device IDs. This change is needed to return per-device information in addition to device ID. Signed-off-by: Dmitry Fleytman <dfleytma@redhat.com>
This commit is contained in:
parent
0e0f2fde51
commit
8a0311f624
8 changed files with 28 additions and 19 deletions
|
|
@ -110,7 +110,7 @@ void CUsbDkControlDeviceQueue::CountDevices(CWdfRequest &Request, WDFQUEUE Queue
|
|||
|
||||
void CUsbDkControlDeviceQueue::EnumerateDevices(CWdfRequest &Request, WDFQUEUE Queue)
|
||||
{
|
||||
USB_DK_DEVICE_ID *existingDevices;
|
||||
USB_DK_DEVICE_INFO *existingDevices;
|
||||
size_t numberExistingDevices = 0;
|
||||
size_t numberAllocatedDevices;
|
||||
|
||||
|
|
@ -128,7 +128,7 @@ void CUsbDkControlDeviceQueue::EnumerateDevices(CWdfRequest &Request, WDFQUEUE Q
|
|||
|
||||
if (res)
|
||||
{
|
||||
Request.SetOutputDataLen(numberExistingDevices * sizeof(USB_DK_DEVICE_ID));
|
||||
Request.SetOutputDataLen(numberExistingDevices * sizeof(USB_DK_DEVICE_INFO));
|
||||
Request.SetStatus(STATUS_SUCCESS);
|
||||
}
|
||||
else
|
||||
|
|
@ -183,7 +183,7 @@ ULONG CUsbDkControlDevice::CountDevices()
|
|||
}
|
||||
//------------------------------------------------------------------------------------------------------------
|
||||
|
||||
bool CUsbDkControlDevice::EnumerateDevices(USB_DK_DEVICE_ID *outBuff, size_t numberAllocatedDevices, size_t &numberExistingDevices)
|
||||
bool CUsbDkControlDevice::EnumerateDevices(USB_DK_DEVICE_INFO *outBuff, size_t numberAllocatedDevices, size_t &numberExistingDevices)
|
||||
{
|
||||
numberExistingDevices = 0;
|
||||
|
||||
|
|
@ -196,8 +196,8 @@ bool CUsbDkControlDevice::EnumerateDevices(USB_DK_DEVICE_ID *outBuff, size_t num
|
|||
return false;
|
||||
}
|
||||
|
||||
wcsncpy(outBuff->DeviceID, Child->DeviceID(), MAX_DEVICE_ID_LEN);
|
||||
wcsncpy(outBuff->InstanceID, Child->InstanceID(), MAX_DEVICE_ID_LEN);
|
||||
wcsncpy(outBuff->ID.DeviceID, Child->DeviceID(), MAX_DEVICE_ID_LEN);
|
||||
wcsncpy(outBuff->ID.InstanceID, Child->InstanceID(), MAX_DEVICE_ID_LEN);
|
||||
outBuff++;
|
||||
numberExistingDevices++;
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
#include "FilterDevice.h"
|
||||
|
||||
typedef struct tag_USB_DK_DEVICE_ID USB_DK_DEVICE_ID;
|
||||
typedef struct tag_USB_DK_DEVICE_INFO USB_DK_DEVICE_INFO;
|
||||
class CUsbDkFilterDevice;
|
||||
class CWdfRequest;
|
||||
|
||||
|
|
@ -72,7 +73,7 @@ public:
|
|||
{ m_FilterDevices.Remove(&FilterDevice); }
|
||||
|
||||
ULONG CountDevices();
|
||||
bool EnumerateDevices(USB_DK_DEVICE_ID *outBuff, size_t numberAllocatedDevices, size_t &numberExistingDevices);
|
||||
bool EnumerateDevices(USB_DK_DEVICE_INFO *outBuff, size_t numberAllocatedDevices, size_t &numberExistingDevices);
|
||||
NTSTATUS ResetUsbDevice(const USB_DK_DEVICE_ID &DeviceId);
|
||||
NTSTATUS AddRedirect(const USB_DK_DEVICE_ID &DeviceId);
|
||||
NTSTATUS RemoveRedirect(const USB_DK_DEVICE_ID &DeviceId);
|
||||
|
|
|
|||
|
|
@ -15,3 +15,8 @@ typedef struct tag_USB_DK_DEVICE_ID
|
|||
WCHAR DeviceID[MAX_DEVICE_ID_LEN];
|
||||
WCHAR InstanceID[MAX_DEVICE_ID_LEN];
|
||||
} USB_DK_DEVICE_ID, *PUSB_DK_DEVICE_ID;
|
||||
|
||||
typedef struct tag_USB_DK_DEVICE_INFO
|
||||
{
|
||||
USB_DK_DEVICE_ID ID;
|
||||
} USB_DK_DEVICE_INFO, *PUSB_DK_DEVICE_INFO;
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ void Controller_UninstallDriver()
|
|||
|
||||
void Controller_EnumerateDevices()
|
||||
{
|
||||
PUSB_DK_DEVICE_ID devicesArray;
|
||||
PUSB_DK_DEVICE_INFO devicesArray;
|
||||
ULONG numberDevices;
|
||||
tcout << TEXT("Enumerate USB devices") << endl;
|
||||
if (GetDevicesList(&devicesArray, &numberDevices))
|
||||
|
|
@ -68,7 +68,10 @@ void Controller_EnumerateDevices()
|
|||
|
||||
for (ULONG deviceIndex = 0; deviceIndex < numberDevices; ++deviceIndex)
|
||||
{
|
||||
tcout << to_tstring(deviceIndex) + TEXT(". ") + devicesArray[deviceIndex].DeviceID + TEXT(" ") + devicesArray[deviceIndex].InstanceID << endl;
|
||||
tcout << to_tstring(deviceIndex) << TEXT(". ")
|
||||
<< devicesArray[deviceIndex].ID.DeviceID << TEXT(" ")
|
||||
<< devicesArray[deviceIndex].ID.InstanceID
|
||||
<< endl;
|
||||
}
|
||||
|
||||
ReleaseDeviceList(devicesArray);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
|
||||
void UsbDkDriverAccess::GetDevicesList(PUSB_DK_DEVICE_ID &DevicesArray, ULONG &NumberDevice)
|
||||
void UsbDkDriverAccess::GetDevicesList(PUSB_DK_DEVICE_INFO &DevicesArray, ULONG &NumberDevice)
|
||||
{
|
||||
DevicesArray = nullptr;
|
||||
for (;;)
|
||||
|
|
@ -26,14 +26,14 @@ void UsbDkDriverAccess::GetDevicesList(PUSB_DK_DEVICE_ID &DevicesArray, ULONG &N
|
|||
|
||||
// get list of devices
|
||||
delete DevicesArray;
|
||||
DevicesArray = new USB_DK_DEVICE_ID[NumberDevice];
|
||||
DevicesArray = new USB_DK_DEVICE_INFO[NumberDevice];
|
||||
|
||||
if (!DeviceIoControl(m_hDriver,
|
||||
IOCTL_USBDK_ENUM_DEVICES,
|
||||
nullptr,
|
||||
0,
|
||||
DevicesArray,
|
||||
NumberDevice * sizeof(USB_DK_DEVICE_ID),
|
||||
NumberDevice * sizeof(USB_DK_DEVICE_INFO),
|
||||
&bytesReturned,
|
||||
nullptr))
|
||||
{
|
||||
|
|
@ -47,12 +47,12 @@ void UsbDkDriverAccess::GetDevicesList(PUSB_DK_DEVICE_ID &DevicesArray, ULONG &N
|
|||
UsbDkDriverAccessException(TEXT("Enumeration failed in IOCTL_USBDK_ENUM_DEVICES."), err);
|
||||
}
|
||||
}
|
||||
NumberDevice = bytesReturned / sizeof(USB_DK_DEVICE_ID);
|
||||
NumberDevice = bytesReturned / sizeof(USB_DK_DEVICE_INFO);
|
||||
break;
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void UsbDkDriverAccess::ReleaseDeviceList(PUSB_DK_DEVICE_ID DevicesArray)
|
||||
void UsbDkDriverAccess::ReleaseDeviceList(PUSB_DK_DEVICE_INFO DevicesArray)
|
||||
{
|
||||
delete[] DevicesArray;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ public:
|
|||
: UsbDkDriverFile(USBDK_USERMODE_NAME)
|
||||
{}
|
||||
|
||||
void GetDevicesList(PUSB_DK_DEVICE_ID &DevicesArray, ULONG &NumberDevice);
|
||||
static void ReleaseDeviceList(PUSB_DK_DEVICE_ID DevicesArray);
|
||||
void GetDevicesList(PUSB_DK_DEVICE_INFO &DevicesArray, ULONG &NumberDevice);
|
||||
static void ReleaseDeviceList(PUSB_DK_DEVICE_INFO DevicesArray);
|
||||
|
||||
void AddRedirect(USB_DK_DEVICE_ID &DeviceID);
|
||||
void RemoveRedirect(USB_DK_DEVICE_ID &DeviceID);
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ BOOL UninstallDriver(void)
|
|||
}
|
||||
//-------------------------------------------------------------------------------------------
|
||||
|
||||
BOOL GetDevicesList(PUSB_DK_DEVICE_ID *DevicesArray, ULONG *NumberDevices)
|
||||
BOOL GetDevicesList(PUSB_DK_DEVICE_INFO *DevicesArray, ULONG *NumberDevices)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -70,7 +70,7 @@ BOOL GetDevicesList(PUSB_DK_DEVICE_ID *DevicesArray, ULONG *NumberDevices)
|
|||
}
|
||||
//-------------------------------------------------------------------------------------------
|
||||
|
||||
void ReleaseDeviceList(PUSB_DK_DEVICE_ID DevicesArray)
|
||||
void ReleaseDeviceList(PUSB_DK_DEVICE_INFO DevicesArray)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ extern "C" {
|
|||
#endif
|
||||
DLL InstallResult InstallDriver(void);
|
||||
DLL BOOL UninstallDriver(void);
|
||||
DLL BOOL GetDevicesList(PUSB_DK_DEVICE_ID *DevicesArray, ULONG *NumberDevices);
|
||||
DLL void ReleaseDeviceList(PUSB_DK_DEVICE_ID DevicesArray);
|
||||
DLL BOOL GetDevicesList(PUSB_DK_DEVICE_INFO *DevicesArray, ULONG *NumberDevices);
|
||||
DLL void ReleaseDeviceList(PUSB_DK_DEVICE_INFO DevicesArray);
|
||||
|
||||
DLL HANDLE StartRedirect(PUSB_DK_DEVICE_ID DeviceID);
|
||||
DLL BOOL StopRedirect(HANDLE DeviceHandle);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue