3

I have a Linux box which runs Busybox. There are two card reader build in. How can I get the type of the card readers?

I tried lshw, hwinfo and lspci but these commands are not implemented on Busybox.


Hello Stéphane Chazelas,

Thank you very much for your detailed answer. I tried it. However grep doesn't find anything.

# l `find /sys/devices -path '*/usb*/configuration'`
-r--r--r--    1 root     root          4096 Oct  2 19:14 /sys/devices/rdb.3/f0470300.ehci_v2/usb3/configuration
-r--r--r--    1 root     root          4096 Oct  2 19:14 /sys/devices/rdb.3/f0470400.ohci_v2/usb7/configuration
-r--r--r--    1 root     root          4096 Oct  2 19:14 /sys/devices/rdb.3/f0470500.ehci_v2/usb4/configuration
-r--r--r--    1 root     root          4096 Oct  2 19:14 /sys/devices/rdb.3/f0470600.ohci_v2/usb8/configuration
-r--r--r--    1 root     root          4096 Oct  2 19:14 /sys/devices/rdb.3/f0471000.xhci_v2/usb1/configuration
-r--r--r--    1 root     root          4096 Oct  2 19:14 /sys/devices/rdb.3/f0471000.xhci_v2/usb2/configuration
-r--r--r--    1 root     root          4096 Oct  2 19:14 /sys/devices/rdb.3/f0480300.ehci_v2/usb5/5-1/5-1.1/configuration
-r--r--r--    1 root     root          4096 Oct  2 19:14 /sys/devices/rdb.3/f0480300.ehci_v2/usb5/5-1/5-1.2/configuration
-r--r--r--    1 root     root          4096 Oct  2 19:14 /sys/devices/rdb.3/f0480300.ehci_v2/usb5/5-1/configuration
-r--r--r--    1 root     root          4096 Oct  2 19:14 /sys/devices/rdb.3/f0480300.ehci_v2/usb5/configuration
-r--r--r--    1 root     root          4096 Oct  2 19:14 /sys/devices/rdb.3/f0480400.ohci_v2/usb9/configuration
-r--r--r--    1 root     root          4096 Oct  2 19:14 /sys/devices/rdb.3/f0480500.ehci_v2/usb6/configuration
-r--r--r--    1 root     root          4096 Oct  2 19:14 /sys/devices/rdb.3/f0480600.ohci_v2/usb10/configuration
# l `find /sys/devices -path '*/pci*/driver'`
dr-xr-xr-x    2 root     root             0 Oct  2 19:20 .
dr-xr-xr-x    4 root     root             0 Oct  2 19:20 ..
-r--r--r--    1 root     root             0 Oct  2 19:31 devices
# l /proc/bus/pci/devices
-r--r--r--    1 root     root             0 Oct  2 19:31 /proc/bus/pci/devices
musbach
  • 321

1 Answers1

4

Card readers are often USB devices. If so, you could do something like:

find /sys/devices -path '*/usb*/configuration' -exec \
   grep -lx 'CARD READER'  {} + | awk -F/ -vOFS=/ '{
     NF--
     getline idv < ($0 "/idVendor")
     getline idp < ($0 "/idProduct")
     getline v < ($0 "/manufacturer")
     getline p < ($0 "/product")
     print idv":"idp" "v" "p}'

To get vendor/product IDs and names (as reported by the kernel). That is look for USB devices whose configuration is set to CARD READER and extract the content of the vendorID, productID, manufacturer and product files located in the parent directory of the one containing the configuration file.

For PCI devices, this would catch at least the devices using the drivers below. busybox find doesn't support GNU find's -lname predicate, so we'd need something like:

find /sys/devices -path '*/pci*/driver' -type l -exec readlink {} \; -print |
  awk -F/ -v OFS=/ '
    BEGIN{d["cb710"]d["r592"]d["r852"]d["rts5208"]d["rtsx_pci"]}
    $NF in d {
      getline
      NF--
      getline v < ($0 "/vendor")
      getline p < ($0 "/device")
      print substr(v, 3) ":" substr(p, 3)
    }'

There's no configuration file that we can use this time to determine the class of device (actually, there is a class file for the PCI device class, but I can see it being 0xff00 (Misc) for a Realtek device here, there is no PCI device class dedicate to "card readers" so we can't rely on it). So instead we look for drivers symlinks that point to any of the drivers known to be drivers for PCI card readers, and get the vendor/product IDs in paths relative to that.

A simpler approach is to use /proc/bus/pci/devices:

awk '
  BEGIN{d["cb710"]d["r592"]d["r852"]d["rts5208"]d["rtsx_pci"]}
  $NF in d {print substr($2, 1, 4) ":" substr($2, 5)}
' < /proc/bus/pci/devices