较早版本的 Renesas USB 3.0 主机控制器存在可能导致问题的问题。为了提醒我的客户注意这些问题,我需要检测过时的版本。为此,我想检索与瑞萨 USB 3.0 主机控制器实用程序相同的运行驱动程序版本。
问问题
502 次
1 回答
0
使用 OSR IrpTracker,我已经确定了 IOCTL 和结构。这是打开每个 Renesas USB 主机控制器的设备接口并查询版本号的示例代码。
#include <initguid.h>
#include <windows.h>
#include <setupapi.h>
#include <stdlib.h>
#include <winioctl.h>
#include <pshpack1.h>
DEFINE_GUID(GUID_DEVINTERFACE_NUSB3XHC, 0xac051b02L, 0x603b, 0x4b3c, 0xb1, 0x4b, 0x95, 0xc9, 0x26, 0x8d, 0xe0, 0x81);
struct NUSB3XHC_DRIVER_VERSION
{
UCHAR Major;
UCHAR Minor;
UCHAR Build;
UCHAR Revision;
UCHAR Unknown[2]; // no idea what this is -- {0, 0} on my machine
};
struct NUSB3XHC_FIRMWARE_VERSION
{
USHORT BcdVersion; // UI displays this as BCD
};
#define IOCTL_NUSB3XHC_GET_DRIVER_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN, 0x800, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_NUSB3XHC_GET_FIRMWARE_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN, 0x808, METHOD_BUFFERED, FILE_ANY_ACCESS)
#include <poppack.h>
BOOL GetVersion(LPCTSTR DevicePath, NUSB3XHC_DRIVER_VERSION* DriverVersion, NUSB3XHC_FIRMWARE_VERSION* FirmwareVersion)
{
HANDLE hDevice = CreateFile(DevicePath, GENERIC_ALL, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (hDevice == NULL)
return FALSE;
BOOL success = FALSE;
DWORD returned;
if (DeviceIoControl(hDevice, IOCTL_NUSB3XHC_GET_DRIVER_VERSION, NULL, 0, DriverVersion, sizeof(NUSB3XHC_DRIVER_VERSION), &returned, NULL))
{
success = (returned == sizeof(NUSB3XHC_DRIVER_VERSION));
}
if (DeviceIoControl(hDevice, IOCTL_NUSB3XHC_GET_FIRMWARE_VERSION, NULL, 0, FirmwareVersion, sizeof(NUSB3XHC_FIRMWARE_VERSION), &returned, NULL))
{
success = success && (returned == sizeof(NUSB3XHC_FIRMWARE_VERSION));
}
CloseHandle(hDevice);
return success;
}
int _tmain(int argc, _TCHAR* argv[])
{
int crap = IOCTL_NUSB3XHC_GET_FIRMWARE_VERSION;
HDEVINFO hDevInfo = SetupDiGetClassDevs(&GUID_DEVINTERFACE_NUSB3XHC, NULL, NULL, DIGCF_DEVICEINTERFACE | DIGCF_PRESENT);
if (hDevInfo != INVALID_HANDLE_VALUE)
{
SP_DEVICE_INTERFACE_DATA devIfaceData;
devIfaceData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
DWORD Index = 0;
do
{
if (!SetupDiEnumDeviceInterfaces(hDevInfo, NULL, &GUID_DEVINTERFACE_NUSB3XHC, Index, &devIfaceData))
break; // hopefully ERROR_NO_MORE_ITEMS
DWORD requiredSize;
SetupDiGetDeviceInterfaceDetail(hDevInfo, &devIfaceData, NULL, NULL, &requiredSize, NULL);
// returns with ERROR_INSUFFICIENT_BUFFER
PSP_DEVICE_INTERFACE_DETAIL_DATA devIfaceDetailData =
(PSP_DEVICE_INTERFACE_DETAIL_DATA) malloc(requiredSize);
devIfaceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
if (SetupDiGetDeviceInterfaceDetail(hDevInfo, &devIfaceData, devIfaceDetailData, requiredSize, NULL, NULL))
{
NUSB3XHC_DRIVER_VERSION driverVersion;
NUSB3XHC_FIRMWARE_VERSION firmwareVersion;
if (GetVersion(devIfaceDetailData->DevicePath, &driverVersion, &firmwareVersion))
{
_tprintf(_T("%s: driver version: %d.%d.%d.%d, firmware version: %x\n"), devIfaceDetailData->DevicePath,
driverVersion.Major,
driverVersion.Minor,
driverVersion.Build,
driverVersion.Revision,
firmwareVersion.BcdVersion);
}
else
{
_tprintf(_T("Failed getting version data from %s.\n"), devIfaceDetailData->DevicePath);
}
}
free(devIfaceDetailData);
++Index;
}
while(1);
}
return 0;
}
于 2012-11-27T20:31:42.070 回答