框架
数据结构
usb_dev结构体
struct usb_device {
...
enum usb_device_state state;
enum usb_device_speed speed;
....
struct usb_device *parent;
struct usb_bus *bus;
//断点0
struct usb_host_endpoint ep0;
//设备模型
struct device dev;
//设备描述符
struct usb_device_descriptor descriptor;
//所有的配置
struct usb_host_config *config;
//active配置
struct usb_host_config *actconfig;
struct usb_host_endpoint *ep_in[16];
struct usb_host_endpoint *ep_out[16];
char **rawdescriptors;
unsigned short bus_mA;
u8 portnum;
u8 level;
....
//hub
int maxchild;
struct usb_device *children[USB_MAXCHILDREN];
....
};
描述符:
struct usb_device_descriptor {
__u8 bLength;
__u8 bDescriptorType;
__le16 bcdUSB; //1.0 or 2.0
__u8 bDeviceClass; //hid,cdc,etc
__u8 bDeviceSubClass;
__u8 bDeviceProtocol;
__u8 bMaxPacketSize0; //端点0数据大小
__le16 idVendor;//
__le16 idProduct;//
__le16 bcdDevice;
__u8 iManufacturer;
__u8 iProduct;
__u8 iSerialNumber;
__u8 bNumConfigurations;
} __attribute__ ((packed));
struct usb_config_descriptor {
__u8 bLength;
__u8 bDescriptorType;
__le16 wTotalLength;
__u8 bNumInterfaces; //itfa ?
__u8 bConfigurationValue;
__u8 iConfiguration;
__u8 bmAttributes;//供电模式
__u8 bMaxPower;
} __attribute__ ((packed));
struct usb_interface_descriptor {
__u8 bLength;
__u8 bDescriptorType;
__u8 bInterfaceNumber; //what intf
__u8 bAlternateSetting;
__u8 bNumEndpoints;//端点数
__u8 bInterfaceClass;//接口类
__u8 bInterfaceSubClass;
__u8 bInterfaceProtocol;//接口协议
__u8 iInterface;
} __attribute__ ((packed));
struct usb_endpoint_descriptor {
__u8 bLength;
__u8 bDescriptorType;
__u8 bEndpointAddress;//端点地址
__u8 bmAttributes;//端点属性 等时 or blk
__le16 wMaxPacketSize; //数据包大小
__u8 bInterval;//间隔传输时间
/* NOTE: these two are _only_ in audio endpoints. */
/* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */
__u8 bRefresh;
__u8 bSynchAddress;
} __attribute__ ((packed));