Windows下USB驱动基础知识
+ -

模仿USBCCGP对USB复合设备功能分析打印输出

2021-11-16 142 0

源代码如下:


VOID
DumpFunctionDescriptor(
    IN PUSBC_FUNCTION_DESCRIPTOR FunctionDescriptor,
    IN ULONG FunctionDescriptorCount)
{
    ULONG Index, SubIndex;

    DPRINT("FunctionCount %lu\n", FunctionDescriptorCount);
    for (Index = 0; Index < FunctionDescriptorCount; Index++)
    {
        DPRINT("Function %lu\n", Index);
        DPRINT("FunctionNumber %lu\n", FunctionDescriptor[Index].FunctionNumber);
        DPRINT("HardwareId %S\n", FunctionDescriptor[Index].HardwareId.Buffer);
        DPRINT("CompatibleId %S\n", FunctionDescriptor[Index].CompatibleId.Buffer);
        DPRINT("FunctionDescription %wZ\n", &FunctionDescriptor[Index].FunctionDescription);
        DPRINT("NumInterfaces %lu\n", FunctionDescriptor[Index].NumberOfInterfaces);

        for (SubIndex = 0; SubIndex < FunctionDescriptor[Index].NumberOfInterfaces; SubIndex++)
        {
            DPRINT(" Index %lu Interface %p\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]);
            DPRINT(" Index %lu Interface InterfaceNumber %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
            DPRINT(" Index %lu Interface Alternate %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting);
            DPRINT(" Index %lu bLength %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bLength);
            DPRINT(" Index %lu bDescriptorType %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bDescriptorType);
            DPRINT(" Index %lu bInterfaceNumber %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceNumber);
            DPRINT(" Index %lu bAlternateSetting %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bAlternateSetting);
            DPRINT(" Index %lu bNumEndpoints %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bNumEndpoints);
            DPRINT(" Index %lu bInterfaceClass %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceClass);
            DPRINT(" Index %lu bInterfaceSubClass %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceSubClass);
            DPRINT(" Index %lu bInterfaceProtocol %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->bInterfaceProtocol);
            DPRINT(" Index %lu iInterface %x\n", SubIndex, FunctionDescriptor[Index].InterfaceDescriptorList[SubIndex]->iInterface);
        }
    }
}

打印输出结果如下:

3: kd> p
FunctionCount 2
Function 0
FunctionNumber 0
HardwareId USB\VID_1539&PID_0100&Rev_0409&MI_00
CompatibleId USB\Class_03&SubClass_00&Prot_ff
FunctionDescription xxx
NumInterfaces 1
 Index 0 Interface FFFFDF0869505149
 Index 0 Interface InterfaceNumber 0
 Index 0 Interface Alternate 0
 Index 0 bLength 9
 Index 0 bDescriptorType 4
 Index 0 bInterfaceNumber 0
 Index 0 bAlternateSetting 0
 Index 0 bNumEndpoints 2
 Index 0 bInterfaceClass 3
 Index 0 bInterfaceSubClass 0
 Index 0 bInterfaceProtocol ff
 Index 0 iInterface 8
Function 1
FunctionNumber 1
HardwareId USB\VID_1539&PID_0100&Rev_0409&MI_01
CompatibleId USB\Class_0e&SubClass_03&Prot_00
FunctionDescription xxx
NumInterfaces 2
 Index 0 Interface FFFFDF0869505171
 Index 0 Interface InterfaceNumber 1
 Index 0 Interface Alternate 0
 Index 0 bLength 9
 Index 0 bDescriptorType 4
 Index 0 bInterfaceNumber 1
 Index 0 bAlternateSetting 0
 Index 0 bNumEndpoints 1
 Index 0 bInterfaceClass e
 Index 0 bInterfaceSubClass 1
 Index 0 bInterfaceProtocol 0
 Index 0 iInterface a
 Index 1 Interface FFFFDF08695051D5
 Index 1 Interface InterfaceNumber 2
 Index 1 Interface Alternate 0
 Index 1 bLength 9
 Index 1 bDescriptorType 4
 Index 1 bInterfaceNumber 2
 Index 1 bAlternateSetting 0
 Index 1 bNumEndpoints 1
 Index 1 bInterfaceClass e
 Index 1 bInterfaceSubClass 2
 Index 1 bInterfaceProtocol 0
 Index 1 iInterface b
HID人机交互QQ群:564808376    UAC音频QQ群:218581009    UVC相机QQ群:331552032    BOT&UASP大容量存储QQ群:258159197    STC-USB单片机QQ群:315457461    USB技术交流QQ群2:580684376    USB技术交流QQ群:952873936   

0 篇笔记 写笔记

USB兼容驱动Composite层级引起的摄像头灯问题
跌跌撞撞,搞了快一个星期。一个定制厂商用的UVC摄像头指示搞了几天,今天算是可以蒙混过关了。关于调试过程中的一部分细节,可见本人的另一篇文章:关于UVC摄像头指示灯的调试过程总结 http://www.usbzh.com/article/detail-430.html在这里,可能只能算是总结二吧,没......
USB通用父驱动usbccgp.sys的过滤UVC摄像头、UAC麦克风和HID设备硬件ID
激动的心情,无溢言表。。虽然只是一个很简单的东西。。但相于折腾了这么久,还是很开心的了。最近有个需求,功能是这样的:有一个USB复合设备,连接到windows系统中它在windows下的设备树如下:USB Composite Device(usbccgp.sys)UVC CameraUAC ......
USBCCGP 功能简介
许多 USB 设备提供了多个 USB 接口。在 USB 术语中,此类设备被称为USB复合设备。Microsoft Windows 2000 和 Windows 98 操作系统的 USB 总线驱动程序 (Usbhub.sys) 中包含有一个通用父设备,它将复合设备的各接口显示为一台单独的设备。在 M......
USBCCGP 复合USB设备的枚举
当新的 USB 设备连接到主机计算机时,USB 总线驱动程序创建设备的物理设备对象 (PDO),并生成报告新 PDO 的即插即用事件。 操作系统然后,查询的硬件 Id 与 PDO 相关联的总线驱动程序。对于所有 USB 设备、 USB 总线驱动程序报告设备 ID具有以下格式:USBVID_xx......
USBCCGP 复合设备接口设备ID
复合 USB 设备上的接口可分组到集合中或分别代表一个 USB 函数。如果接口未分组在集合中,则通用父驱动程序会为每个接口创建一个 PDO,并为每个 PDO 生成一组硬件 Id。USB设备ID接口 PDO 的设备 ID具有以下格式:USBVID_v(4)&PID_p(4)&MI......
USBCCGP 驱动结构
USBCCGP驱动文件结构USBCCGP驱动位于REACTOS的ReactOS-0.4.0driversusbusbccgp目录下,包含文件descriptor.cfdo.cfunction.cguid.cmisc.cpdo.cusbccgp.cusbccgp.husbccg......
USBCCGP 分发函数
通过上一节知道,USBCCGAP将所有的IRP都会发到USBCCGP_Dispatch函数中。其代码如下:usbccgp.cNTSTATUSNTAPIUSBCCGP_Dispatch( PDEVICE_OBJECT DeviceObject, PIRP Irp){ ......
USBCCGP 功能设备驱动FDO创建
回到入口函数DriverEntry,驱动扩展结构体的AddDevice函数指针被置为USBCCGP_AddDevice。这个函数指针是WDM驱动功能设备创建和扩展数据初始的回调函数。usbccgp.cNTSTATUSNTAPIDriverEntry( PDRIVER_OBJECT D......
USBCCGP FDO的启动
USBCCGP FDO的启动会执行主功能号为IRP_MJ_PNP,次功功能号IRP_MN_START_DEVICE的IRP。其函数调用关系如下:USBCCGP_Dispatch FDO_Dispatch FDO_HandlePnp ......
USBCCGP 获取USB设备描述符
USB设备的描述符是通过函数USBCCGP_GetDescriptors来获取的。descriptor.c /* Get descriptors */ Status = USBCCGP_GetDescriptors(DeviceObject); if (!NT_SUCCESS......
USBCCGP 获取USB设备特性
设备特性在windows下所有设备的通用,其主要包括一些电源特性和热插拨特性。结构定义如下:typedef _Struct_size_bytes_(Size) struct _DEVICE_CAPABILITIES { _Field_range_(==, sizeof(struct _DE......
USBCCGP 配置设备
获取设备的配置描述符通过前面已经知道,其包括的内容比较多,如接口描述符、端点描述符等,其中有很多我们进行数据通讯的信息,所以下来我们就要对设备进行配置。在USBCCGP USB复合设备驱动中,由于其将各个独立的接口会枚举成一个单独的设备,所以一般情况下有几个接口描述符就会被枚举成几个设备(UVC设备......
USBCCGP 总线过滤驱动接口
总线驱动或过滤驱动的接口其实就是一个USBC_DEVICE_CONFIGURATION_INTERFACE_V1的结构体,其用于创建PDO.#define USBC_DEVICE_CONFIGURATION_INTERFACE_VERSION_1 0x0001typedef s......
USBCCGP 设备接口集
USBCCGP是通用复合设备,所以其中一项重要的功能是需要分析USB接口集,并进行解析,然后对应于每一个集口,创建其子设备PDO。所以说USBCCGP既是一个通用的总线驱动程序,也是一个功能设备。在USBCCGP中,每个独立的子设备叫做一个功能,枚举这些子设备是通过函数USBCCGP_Enumer......
USBCCGP 关联接口功能设备枚举
从上节可知,所有的功能设备都存储在FDO_DEVICE_EXTENSION中的FunctionDescriptor中的,而FunctionDescriptorCount成员记录着子功能数量。typedef struct _USBC_FUNCTION_DESCRIPTOR{ // The 0......
关注公众号
取消
感谢您的支持,我会继续努力的!
扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

您的支持,是我们前进的动力!