linux usb device 枚举代码 及 不同系统枚举差异
USB 枚举是host 发起 requst,device 返回 response
每次收到 requst,都会调用函数 composite_setup,它负责处理 USB 控制传输中的 SETUP 包(如设备描述符、配置描述符请求),所以如果不同系统枚举流程不一样,可以在这里判断

苹果设备获取某个字符串描述符,分两个步骤,先读取字符串长度,期望长度是0x0002,再读取字符串
其他系统不先读取字符串长度,默认按最大长度0x00ff读取字符串
--------------composite_setup, bRequestType: 0x80, bRequest: 0x06, wValue: 0x0302, wIndex: 0x0409, wLength: 0x0002 apple device --------------composite_setup, bRequestType: 0x80, bRequest: 0x06, wValue: 0x0302, wIndex: 0x0409, wLength: 0x001c
--------------composite_setup, bRequestType: 0x80, bRequest: 0x06, wValue: 0x0302, wIndex: 0x0409, wLength: 0x00ff not apple device
读取配置描述符分两个步骤,先读取配置描述符头,再读取配置描述符内容,windows系统读取配置描述符头的期望长度是0x00ff,其他系统是0x0009(配置描述符头固定是9字节)
--------------composite_setup, bRequestType: 0x80, bRequest: 0x06, wValue: 0x0200, wIndex: 0x0000, wLength: 0x00ff windows device --------------composite_setup, bRequestType: 0x80, bRequest: 0x06, wValue: 0x0200, wIndex: 0x0000, wLength: 0x03bd
--------------composite_setup, bRequestType: 0x80, bRequest: 0x06, wValue: 0x0200, wIndex: 0x0000, wLength: 0x0009 not windows device --------------composite_setup, bRequestType: 0x80, bRequest: 0x06, wValue: 0x0200, wIndex: 0x0000, wLength: 0x03bd
苹果设备不读取语言 ID 列表(wValue: 0x0300),windows读取语言ID列表的期望长度是0x00ff,安卓系统第一次读取语言ID列表的期望长度先是0x00ff,后面是0x00fe
--------------composite_setup, bRequestType: 0x80, bRequest: 0x06, wValue: 0x0300, wIndex: 0x0000, wLength: 0x00fe android device
如果前面三个都不是,就是linux系统

浙公网安备 33010602011771号