sysfsでlinuxの下のusbデバイスの記述子を表示する


/sys/bus/usb/devices/下のパス命名規則
 roothub-port[.port]:configuration:interface

一般に、1-0はhub自身の情報であり、hubに挿入装置がある場合、1-1、1-2が現れる.1.ディレクトリの表示:
ls /sys/bus/usb/devices/
1-0:1.0    1-1.1:1.0  2-1        4-0:1.0    usb1       usb4
1-1        1-1:1.0    2-1:1.0    5-0:1.0    usb2       usb5
1-1.1      2-0:1.0    3-0:1.0    6-0:1.0    usb3       usb6

これは何ですか.
[原句]焦らないで、もっと詳しく見てください.
ls /sys/bus/usb/devices/usb1/
1-0:1.0              bcdDevice            manufacturer
1-1                  bmAttributes         maxchild
authorized           busnum               power
authorized_default   configuration        product
avoid_reset_quirk    descriptors          quirks
bConfigurationValue  dev                  removable
bDeviceClass         devnum               remove
bDeviceProtocol      devpath              serial
bDeviceSubClass      driver               speed
bMaxPacketSize0      ep_00                subsystem
bMaxPower            idProduct            uevent
bNumConfigurations   idVendor             urbnum
bNumInterfaces       ltm_capable          version

ディスクリプタが直接見えますか?
3.サブディレクトリは?
ls /sys/bus/usb/devices/usb1/1-0\:1.0/
bAlternateSetting     bNumEndpoints         power
bInterfaceClass       driver                subsystem
bInterfaceNumber      ep_81                 supports_autosuspend
bInterfaceProtocol    modalias              uevent
bInterfaceSubClass    port1


インタフェース記述子?いいやつだ!
4.どんな設備か見てみましょう.
cat /sys/bus/usb/devices/usb1/1-0\:1.0/bInterfaceClass
09


わあ、hubです!
5.その1-1は何ですか.
cat /sys/bus/usb/devices/usb1/1-1/1-1.1/bDeviceClass
00


さっき差し込んだアンドロイドの携帯電話です
次のようになります.
インタフェース記述子:
cat /sys/bus/usb/devices/usb1/1-1/1-1.1/1-1.1\:1.0/
bAlternateSetting     driver/               subsystem/
bInterfaceClass       ep_02/                supports_autosuspend
bInterfaceNumber      ep_81/                uevent
bInterfaceProtocol    interface             usbmisc/
bInterfaceSubClass    modalias              
bNumEndpoints         power/ 

上は構成とデバイス記述子です.
cat /sys/bus/usb/devices/usb1/1-1/1-1.1/           
1-1.1:1.0/           busnum               port/
authorized           configuration        power/
avoid_reset_quirk    descriptors          product
bConfigurationValue  dev                  quirks
bDeviceClass         devnum               removable
bDeviceProtocol      devpath              remove
bDeviceSubClass      driver/              serial
bMaxPacketSize0      ep_00/               speed
bMaxPower            idProduct            subsystem/
bNumConfigurations   idVendor             uevent
bNumInterfaces       ltm_capable          urbnum
bcdDevice            manufacturer         version
bmAttributes         maxchild           

さらに上へ:
 cat /sys/bus/usb/devices/usb1/1-1/
1-1.1/               bmAttributes         port/
1-1:1.0/             busnum               power/
authorized           configuration        product
avoid_reset_quirk    descriptors          quirks
bConfigurationValue  dev                  removable
bDeviceClass         devnum               remove
bDeviceProtocol      devpath              speed
bDeviceSubClass      driver/              subsystem/
bMaxPacketSize0      ep_00/               uevent
bMaxPower            idProduct            urbnum
bNumConfigurations   idVendor             version
bNumInterfaces       ltm_capable          
bcdDevice            maxchild   

これは違いがないようです.
6.ホームに戻る:
ls /sys/bus/usb/devices/
1-0:1.0    1-1.1:1.0  2-1        4-0:1.0    usb1       usb4
1-1        1-1:1.0    2-1:1.0    5-0:1.0    usb2       usb5
1-1.1      2-0:1.0    3-0:1.0    6-0:1.0    usb3       usb6

全部で3つのインタフェースがありますが、なぜ6つのusbがありますか?ドリルダウン:
 ls -al /sys/bus/usb/devices/
total 0
drwxr-xr-x    2 root     root             0 Jan  1 06:59 .
drwxr-xr-x    4 root     root             0 Jan  1 06:59 ..
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 1-0:1.0 -> ../../../devices/soc/5200000.ehci1-controller/usb1/1-0:1.0
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 1-1 -> ../../../devices/soc/5200000.ehci1-controller/usb1/1-1
lrwxrwxrwx    1 root     root             0 Jan  1 08:46 1-1.1 -> ../../../devices/soc/5200000.ehci1-controller/usb1/1-1/1-1.1
lrwxrwxrwx    1 root     root             0 Jan  1 08:46 1-1.1:1.0 -> ../../../devices/soc/5200000.ehci1-controller/usb1/1-1/1-1.1/1-1.1:1.0
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 1-1:1.0 -> ../../../devices/soc/5200000.ehci1-controller/usb1/1-1/1-1:1.0
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 2-0:1.0 -> ../../../devices/soc/5310000.ehci2-controller/usb2/2-0:1.0
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 2-1 -> ../../../devices/soc/5310000.ehci2-controller/usb2/2-1
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 2-1:1.0 -> ../../../devices/soc/5310000.ehci2-controller/usb2/2-1/2-1:1.0
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 3-0:1.0 -> ../../../devices/soc/5311000.ehci3-controller/usb3/3-0:1.0
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 4-0:1.0 -> ../../../devices/soc/5200000.ohci1-controller/usb4/4-0:1.0
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 5-0:1.0 -> ../../../devices/soc/5310000.ohci2-controller/usb5/5-0:1.0
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 6-0:1.0 -> ../../../devices/soc/5311000.ohci3-controller/usb6/6-0:1.0
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 usb1 -> ../../../devices/soc/5200000.ehci1-controller/usb1
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 usb2 -> ../../../devices/soc/5310000.ehci2-controller/usb2
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 usb3 -> ../../../devices/soc/5311000.ehci3-controller/usb3
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 usb4 -> ../../../devices/soc/5200000.ohci1-controller/usb4
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 usb5 -> ../../../devices/soc/5310000.ohci2-controller/usb5
lrwxrwxrwx    1 root     root             0 Jan  1 06:59 usb6 -> ../../../devices/soc/5311000.ohci3-controller/usb6


見えました.ehciとohciは別々なので、全部で6つのコントローラがあります.

void checkUSBDevice()
{
    bool ret = false;

    #define USB1_PATH "/sys/bus/usb/devices/usb1/1-1/1-1.1/product"
    #define USB2_PATH "/sys/bus/usb/devices/usb1/1-1/1-1.2/product"


    int fd = open(USB1_PATH,O_RDONLY);
    if(fd>0)
    {
        printf("usb 1 is exist!
"); char product[BUF_LEN] = {'\0'}; int seekLen = lseek(fd,0,SEEK_END); lseek(fd,0,SEEK_SET); int ret = read(fd,product,seekLen); close(fd); } else { printf("usb 1 is not exist!
"); } fd = open(USB2_PATH,O_RDONLY); if(fd>0) { printf("usb 2 is exist!
"); char product[BUF_LEN] = {'\0'}; int seekLen = lseek(fd,0,SEEK_END); lseek(fd,0,SEEK_SET); int ret = read(fd,product,seekLen); printf("usb1 name:%s,strlen=%d,seekLen=%d,reedlen=%d
",product,strlen(product),seekLen,ret); close(fd); } else { printf("usb 2 is not exist!
"); } }