Linux下的USB总线、设备

Steven Yang
Email: defeattroy at gmail.com
Date: 2011-04-20

系统的USB设备信息通过usbfs挂载在/proc/bus/usb下面,此目录下面有两种文件/proc/bus/usb/devices和/proc/bus/usb/BBB/DDD。

/proc/bus/usb/BBB/DDD文件

  每一个连接的USB设备都有一个文件,BBB指示bus number,DDD指示设备在这个总线上的地址。这些文件可以当作二进制数据读取,内容包括设备描述和设备配置描述。这些信息在/proc/bus/usb/devices里面也有。

  这些文件可以被用来写用户层的USB设备驱动,可以打开/proc/bus/usb/BBB/DDD进行读写,读到其相关描述确定是不是你期望的设备,如果是,使用ioctl函数把它bind到一个(或几个)接口上。

  注意只有root才能访问BBB/DDD文件,所以也只有root能写这些用户层的驱动。当然可以利用chmod改变权限或者在mount usbfs的时候利用devmode选项,例如"devmode=0666"

/proc/bus/usb/devices文件

  该文件中每个设备的输出占多行,每行的含义如下:

T = Topology (etc.)
B = Bandwidth (applies only to USB host controllers, which are
    virtualized as root hubs)
D = Device descriptor info.
P = Product ID info. (from Device descriptor, but they won't fit
    together on one line)
S = String descriptors.
C = Configuration descriptor info. (* = active configuration)
I = Interface descriptor info.
E = Endpoint descriptor info.

/proc/bus/usb/devices文件的格式如下

=======================================================================

/proc/bus/usb/devices output format:

Legend:
  d = decimal number (may have leading spaces or 0's)
  x = hexadecimal number (may have leading spaces or 0's)
  s = string


Topology info:

T:  Bus=dd Lev=dd Prnt=dd Port=dd Cnt=dd Dev#=ddd Spd=ddd MxCh=dd
|   |      |      |       |       |      |        |       |__MaxChildren
|   |      |      |       |       |      |        |__Device Speed in Mbps
|   |      |      |       |       |      |__DeviceNumber
|   |      |      |       |       |__Count of devices at this level
|   |      |      |       |__Connector/Port on Parent for this device
|   |      |      |__Parent DeviceNumber
|   |      |__Level in topology for this bus
|   |__Bus number
|__Topology info tag

Speed may be:
        1.5    Mbit/s for low speed USB
    12    Mbit/s for full speed USB
    480    Mbit/s for high speed USB (added for USB 2.0)


Bandwidth info:
B:  Alloc=ddd/ddd us (xx%), #Int=ddd, #Iso=ddd
|   |                       |         |__Number of isochronous requests
|   |                       |__Number of interrupt requests
|   |__Total Bandwidth allocated to this bus
|__Bandwidth info tag

Bandwidth allocation is an approximation of how much of one frame
    (millisecond) is in use.  It reflects only periodic transfers, which
    are the only transfers that reserve bandwidth.  Control and bulk
    transfers use all other bandwidth, including reserved bandwidth that
    is not used for transfers (such as for short packets).

The percentage is how much of the "reserved" bandwidth is scheduled by
    those transfers.  For a low or full speed bus (loosely, "USB 1.1"),
    90% of the bus bandwidth is reserved.  For a high speed bus (loosely,
    "USB 2.0") 80% is reserved.


Device descriptor info & Product ID info:

D:  Ver=x.xx Cls=xx(s) Sub=xx Prot=xx MxPS=dd #Cfgs=dd
P:  Vendor=xxxx ProdID=xxxx Rev=xx.xx

where
D:  Ver=x.xx Cls=xx(sssss) Sub=xx Prot=xx MxPS=dd #Cfgs=dd
|   |        |             |      |       |       |__NumberConfigurations
|   |        |             |      |       |__MaxPacketSize of Default Endpoint
|   |        |             |      |__DeviceProtocol
|   |        |             |__DeviceSubClass
|   |        |__DeviceClass
|   |__Device USB version
|__Device info tag #1

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/24321.html