本文描述了通过USB Tracker追踪USB设备的Windows XP上的枚举过程,在读该篇文章之前首先阅读USB枚举过程能够对USB枚举过程中的各个概念建立更准确的理解。另外Windows系统上USB枚举的详细过程可以参考“How does USB stack enumerate a device?”(CSDN禁止插入该链接,google吧)
下面图1是USB枚举过程的流程图,图2是通过USBTracker抓取的USB枚举过程中的主要交互数据包。
图1 USB枚举过程
图2 USB tracker数据包
The enumeration interrupt procedure will last until the host finally set a appropriate configuration for the device.
•Step1: Get device descriptor through default address 0 , now the host does not know the descriptor length, so 64 bytes in length is set by default. For the host, the most significant information is the descriptor length returned at the 7th byte. So the host will only read the first 8 bytes. After this step, the host may ask the hub to reset the device again to make sure that the device being into a certain state.
Step2: Set address, address 3 is allocated to our device this time
Step3: Get device descriptor again through settled address. After the first get descriptor request on address 0, the host has retrieved the descriptor length. So this time the device the actual length is configured. After this step, the host will retrieve the configuration num.
•Step4: Get configuration descriptor, 9 bytes length, the host will retrieve the total length of this configuration descriptor, including all interface and endpoint descriptor(s) and exist string descriptor.
•Step5: Get configuration descriptor again, this time the device will return all interface and endpoint descriptors belong to this configurationIn detail(1) .
Step5: Get configuration descriptor in detail(2). Step4-5 will be carried multiple times if there are multiple configurations.
•Step6: Get string Descriptor.(String lang IDs)
•Step7: Get string Descriptor. The string descriptor may including Language ID, Vendor ID, product index, etc. (String iProduct)
Note:Now,on the basis of responds, the host install the appropriate driver, choose driver according to VID and PID. Within the involvment of device driver, the same process will be carried again for accurate device control purpose .•Step8: Get Descriptor(device, configuration) again in order to choose appropriate configuration based on the information acquired before, and the selected configure will be sent to the device next.
•Step9: Set Configuration (1), the device is successfully configured and it can transfer data with the client software. According to the response of Device and Configuration Descriptor, the host can choose the configuration it support and load appropriate driver.
•Step 10: Get string Descriptor (all iInterface descriptions supported by the selected configuration)
•Step11: Get Status (Device)
•Step12: Get Descriptor (String iInterface), return the description of selected interface
After the success enumeration, the Device will interact with the host or suspended for power saving