linux USB子系统(一)

本文详细介绍了USB设备在Linux内核中的数据结构表示,包括usb_device结构体及其成员字段的解释,如状态、速度、端点配置等,并进一步解析了设备描述符、配置描述符、接口描述符及端点描述符的具体内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

框架

这里写图片描述

数据结构

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));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值