HID源码DeviceExtension之间关系
2021-09-15
505
1
HidClassAddDevice中创建设备时传递的设备扩展结构体大小:
DeviceExtensionSize = sizeof(HIDCLASS_FDO_EXTENSION) + DriverExtension->DeviceExtensionSize;
/* now create the device */
Status = IoCreateDevice(DriverObject, DeviceExtensionSize, &DeviceName, FILE_DEVICE_UNKNOWN, 0, FALSE, &NewDeviceObject);
if (!NT_SUCCESS(Status))
{
/* failed to create device object */
ASSERT(FALSE);
return Status;
}
而USBHid中设置DriverExtension->DeviceExtensionSize的值为:
Registration.DeviceExtensionSize = sizeof(HID_USB_DEVICE_EXTENSION);
所以最终的扩展结象为 HIDCLASS_FDO_EXTENSION + HID_USB_DEVICE_EXTENSION
- HID_USB_DEVICE_EXTENSION 结构体为MiniPort小端口驱动的私有扩展单元。
- HIDCLASS_FDO_EXTENSION 是HIDClass类驱动维护的数据单元。但类驱动同时承担着两个功能
1.创建PDO,所以每次进行IRP调用时需判断是FDO和PDO
2.提供一个不透时的指针HidUsb.
所以HIDCLASS_FDO_EXTENSION的定义如下:
typedef struct
{
//
// parts shared by fdo and pdo
//
HIDCLASS_COMMON_DEVICE_EXTENSION Common;
//
// device capabilities
//
DEVICE_CAPABILITIES Capabilities;
//
// hid descriptor
//
HID_DESCRIPTOR HidDescriptor;
//
// report descriptor
//
PUCHAR ReportDescriptor;
//
// device relations
//
PDEVICE_RELATIONS DeviceRelations;
} HIDCLASS_FDO_EXTENSION, *PHIDCLASS_FDO_EXTENSION;
可以看到其有一个与PDO其同的数据结构HIDCLASS_COMMON_DEVICE_EXTENSION,其定义如下:
typedef struct
{
//
// hid device extension
//
HID_DEVICE_EXTENSION HidDeviceExtension;
//
// if it is a pdo
//
BOOLEAN IsFDO;
//
// driver extension
//
PHIDCLASS_DRIVER_EXTENSION DriverExtension;
//
// device description
//
HIDP_DEVICE_DESC DeviceDescription;
//
// hid attributes
//
HID_DEVICE_ATTRIBUTES Attributes;
} HIDCLASS_COMMON_DEVICE_EXTENSION, *PHIDCLASS_COMMON_DEVICE_EXTENSION;
而无论是PDO还是FDO,都有2个DeveiObject,只是其含义不同而已,并且为了给HIDBUS提供其各个设备结构,所以又定义了一个结构体HID_DEVICE_EXTENSION
typedef struct _HID_DEVICE_EXTENSION {
PDEVICE_OBJECT PhysicalDeviceObject;
PDEVICE_OBJECT NextDeviceObject;
PVOID MiniDeviceExtension;
} HID_DEVICE_EXTENSION, * PHID_DEVICE_EXTENSION;
所以关系图如下:
- HIDCLASS_FDO_EXTENSION
- HIDCLASS_COMMON_DEVICE_EXTENSION
- HID_DEVICE_EXTENSION
- HIDCLASS_COMMON_DEVICE_EXTENSION
- HID_USB_DEVICE_EXTENSION
HID人机交互QQ群:564808376
UAC音频QQ群:218581009
UVC相机QQ群:331552032
BOT&UASP大容量存储QQ群:258159197
STC-USB单片机QQ群:315457461
USB技术交流QQ群2:580684376
USB技术交流QQ群:952873936