How to find related /dev/ device file given DEVPATH in event handler

EB0

New Member
Joined
Jul 28, 2023
Messages
4
Reaction score
0
Credits
48
I am running openwrt, have minimum software installed.
When I plug keyboard device into the router, it launches hotplug event, executing the script for add/bind. I can know usbhid device is being attached, and its DEVPATH. The keyboard must have /dev/hidraw* device for it, which then I can access for identifying what is being pressed on the keyboard.
My problem is I can't find how to reliably match DEVPATH to the device file. Of course device file name is buried within the directory DEVPATH points to in /sys, but what is the logic? I may work backwards by taking major/minor of the device file and identify device paths and compare to current one being reported, but again there's another problem getting major/minor reliably.
Any help would be appreciated.
 


i've not used openwrt and couldn't tell exactly from a quick search of their website if it uses udev or what commands might be available if it does. that being said, in case it might work, this is an excerpt of udevadm monitor -kup output from an mx linux 21 (based on debian 11) system gathered after plugging in a usb keyboard:
Code:
udevadm monitor -kup
...
KERNEL[202481.122018] add      /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/0003:1A2C:0E24.0003/hidraw/hidraw0 (hidraw)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/0003:1A2C:0E24.0003/hidraw/hidraw0
SUBSYSTEM=hidraw
DEVNAME=/dev/hidraw0
SEQNUM=11077
MAJOR=243
MINOR=0
 
i've not used openwrt and couldn't tell exactly from a quick search of their website if it uses udev or what commands might be available if it does. that being said, in case it might work, this is an excerpt of udevadm monitor -kup output from an mx linux 21 (based on debian 11) system gathered after plugging in a usb keyboard:
Code:
udevadm monitor -kup
...
KERNEL[202481.122018] add      /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/0003:1A2C:0E24.0003/hidraw/hidraw0 (hidraw)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/0003:1A2C:0E24.0003/hidraw/hidraw0
SUBSYSTEM=hidraw
DEVNAME=/dev/hidraw0
SEQNUM=11077
MAJOR=243
MINOR=0
Thank you, that would be super, what I see in the environment (displayed using set in the hotplug event handler)
Code:
ACTION='bind'
DEVICENAME='2-1:1.0'
DEVPATH='/devices/soc0/80080000.ahb/80080000.usb/ci_hdrc.0/usb2/2-1/2-1:1.0'
DEVTYPE='usb_interface'
DRIVER='usbhid'
MODALIAS='usb:v046DpC050d2720dc00dsc00dp00ic03isc01ip02in00'
PRODUCT='46d/c050/2720'
I think I can add udev to the image, if it is necessary and solves the issue.
 
you are welcome. are there any more files or directories in the listed DEVPATH?
DEVPATH='/devices/soc0/80080000.ahb/80080000.usb/ci_hdrc.0/usb2/2-1/2-1:1.0'
when comparing yours with what my system showed:
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/0003:1A2C:0E24.0003/hidraw/hidraw0
yours ends with /usb2/2-1/2-1:1.0 like mine. in mine this part /0003:1A2C:0E24.0003 seems to refer to the usb vendor and product id numbers. i got this from dmesg when plugging the keyboard in:
Code:
dmesg -w
...
[202156.950926] usb 2-1: New USB device found, idVendor=1a2c, idProduct=0e24, bcdDevice= 1.10
you should also be able to see these numbers on any other linux system with lsusb. those id's should be static so they wouldn't change between system or boots.
 
Last edited:
you are welcome. are there any more files in the listed DEVPATH?

when comparing yours with what my system showed:

yours ends with /usb2/2-1/2-1:1.0 like mine. in mine this part /0003:1A2C:0E24.0003 seems to refer to the usb vendor and product id numbers. i got this from dmesg when plugging the keyboard in:
Code:
dmesg -w
...
[202156.950926] usb 2-1: New USB device found, idVendor=1a2c, idProduct=0e24, bcdDevice= 1.10
you should also be able to see these numbers on any other linux system with lsusb. those id's should be static so they wouldn't change between system or boots.
When keyboard is installed and system issues events, there're two devices being discovered:
Code:
ACTION='add'
DEVICENAME='2-1'
DEVNAME='bus/usb/002/006'
DEVNUM='006'
DEVPATH='/devices/soc0/80080000.ahb/80080000.usb/ci_hdrc.0/usb2/2-1'
DEVTYPE='usb_device'
MAJOR='189'
MINOR='133'
PRODUCT='4f3/103/107'
then
Code:
ACTION='add'
DEVICENAME='2-1:1.0'
DEVPATH='/devices/soc0/80080000.ahb/80080000.usb/ci_hdrc.0/usb2/2-1/2-1:1.0'
DEVTYPE='usb_interface'
HOTPLUG_TYPE='usb'
INTERFACE='3/1/1'
PRODUCT='4f3/103/107'
then
Code:
ACTION='bind'
DEVICENAME='2-1:1.0'
DEVPATH='/devices/soc0/80080000.ahb/80080000.usb/ci_hdrc.0/usb2/2-1/2-1:1.0'
DEVTYPE='usb_interface'
[B]DRIVER='usbhid'[/B]
INTERFACE='3/1/1'
PRODUCT='4f3/103/107'
then
Code:
ACTION='add'
DEVICENAME='2-1:1.1'
DEVPATH='/devices/soc0/80080000.ahb/80080000.usb/ci_hdrc.0/usb2/2-1/2-1:1.1'
DEVTYPE='usb_interface'
HOTPLUG_TYPE='usb'
INTERFACE='3/0/0'
PRODUCT='4f3/103/107'
then
Code:
ACTION='bind'
DEVICENAME='2-1:1.1'
DEVPATH='/devices/soc0/80080000.ahb/80080000.usb/ci_hdrc.0/usb2/2-1/2-1:1.1'
DEVTYPE='usb_interface'
DRIVER='usbhid'
HOTPLUG_TYPE='usb'
INTERFACE='3/0/0'
PRODUCT='4f3/103/107'
then
Code:
ACTION='bind'
BUSNUM='002'
DEVICENAME='2-1'
DEVNAME='bus/usb/002/006'
DEVNUM='006'
DEVPATH='/devices/soc0/80080000.ahb/80080000.usb/ci_hdrc.0/usb2/2-1'
DEVTYPE='usb_device'
DRIVER='usb'
HOTPLUG_TYPE='usb'
MAJOR='189'
MINOR='133'
PRODUCT='4f3/103/107'
So first it reports device 2-1, then 2-1:1.0 (the one tagged 'usbhid'), then 2-1:1.1.
I suspect '2-1:1.0' is the one I need.

My system log:
Code:
Fri Jul 28 14:41:16 2023 kern.info kernel: [551401.928360] usb 2-1: USB disconnect, device number 5
Fri Jul 28 14:41:28 2023 kern.info kernel: [551414.292065] usb 2-1: new low-speed USB device number 6 using ci_hdrc
Fri Jul 28 14:41:28 2023 kern.info kernel: [551414.546483] input: HID 04f3:0103 as /devices/soc0/80080000.ahb/80080000.usb/ci_hdrc.0/usb2/2-1/[B]2-1:1.0[/B]/0003:04F3:0103.0005/input/input5
Fri Jul 28 14:41:28 2023 kern.info kernel: [551414.559882] hid-generic [B]0003:04F3:0103.0005[/B]: input,hidraw0: USB HID v1.11 Keyboard [HID 04f3:0103] on usb-ci_hdrc.0-1/input0
Fri Jul 28 14:41:28 2023 kern.info kernel: [551414.668786] input: HID 04f3:0103 Consumer Control as /devices/soc0/80080000.ahb/80080000.usb/ci_hdrc.0/usb2/2-1/2-1:1.1/0003:04F3:0103.0006/input/input6
Fri Jul 28 14:41:28 2023 kern.info kernel: [551414.683759] input: HID 04f3:0103 System Control as /devices/soc0/80080000.ahb/80080000.usb/ci_hdrc.0/usb2/2-1/2-1:1.1/0003:04F3:0103.0006/input/input7
Fri Jul 28 14:41:28 2023 kern.info kernel: [551414.698392] hid-generic 0003:04F3:0103.0006: input,hidraw1: USB HID v1.11 Device [HID 04f3:0103] on usb-ci_hdrc.0-1/input1
I just figured out that list of environmental variables I gave in previous replies are wrong, '46d/c050/2720' is related to mouse I was connecting earlier. The keyboard identification is '4f3/103/107' so you are perfectly correct that directory name 0003:04F3:0103.0005 corresponds to it, the question is what 0003 before (bus name from INTERFACE='3/1/1'?) and 0005 after (I suspect 0005 corresponds to 'bus/usb/002/005' I have seen somewhere else earlier, but not sure).
Code:
# ls -l
drwxr-xr-x    5 root     root             0 Jul 28 15:15 0003:04F3:0103.0005
-rw-r--r--    1 root     root          4096 Jul 28 15:20 authorized
-r--r--r--    1 root     root          4096 Jul 28 15:20 bAlternateSetting
-r--r--r--    1 root     root          4096 Jul 28 15:20 bInterfaceClass
-r--r--r--    1 root     root          4096 Jul 28 15:20 bInterfaceNumber
-r--r--r--    1 root     root          4096 Jul 28 15:20 bInterfaceProtocol
-r--r--r--    1 root     root          4096 Jul 28 15:20 bInterfaceSubClass
-r--r--r--    1 root     root          4096 Jul 28 15:20 bNumEndpoints
lrwxrwxrwx    1 root     root             0 Jul 28 15:20 driver -> ../../../../../../../../bus/usb/drivers/usbhid
drwxr-xr-x    3 root     root             0 Jul 28 15:20 ep_81
-r--r--r--    1 root     root          4096 Jul 28 15:20 modalias
drwxr-xr-x    2 root     root             0 Jul 28 15:20 power
lrwxrwxrwx    1 root     root             0 Jul 28 15:20 subsystem -> ../../../../../../../../bus/usb
-r--r--r--    1 root     root          4096 Jul 28 15:20 supports_autosuspend
-rw-r--r--    1 root     root          4096 Jul 28 15:20 uevent
The '0003:04F3:0103.0005' directory contains
Code:
-r--r--r--    1 root     root          4096 Jul 28 15:20 country
lrwxrwxrwx    1 root     root             0 Jul 28 15:20 driver -> ../../../../../../../../../bus/hid/drivers/hid-generic
drwxr-xr-x    3 root     root             0 Jul 28 15:15 hidraw
drwxr-xr-x    3 root     root             0 Jul 28 15:20 input
-r--r--r--    1 root     root          4096 Jul 28 15:20 modalias
drwxr-xr-x    2 root     root             0 Jul 28 15:20 power
-r--r--r--    1 root     root          4096 Jul 28 15:20 report_descriptor
lrwxrwxrwx    1 root     root             0 Jul 28 15:20 subsystem -> ../../../../../../../../../bus/hid
-rw-r--r--    1 root     root          4096 Jul 28 15:20 uevent
where we can see 'hidraw' which in its turn contains
Code:
drwxr-xr-x    3 root     root             0 Jul 28 15:15 hidraw0
But to be honest it is very complicated, most probably there must be much simpler way to reach device file behind the '/devices/soc0/80080000.ahb/80080000.usb/ci_hdrc.0/usb2/2-1/2-1:1.0' device...
 
the question is what 0003 before (bus name from INTERFACE='3/1/1'?) and 0005 after
again, i can't say where you would find this info without udev. for my usb keyboard. from lsusb:
Code:
Bus 002 Device 010: ID 1a2c:0e24 China Resource Semico Co., Ltd USB Keyboard
then from udevadm monitor -kup
Code:
KERNEL[202481.061943] add      /devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/0003:1A2C:0E24.0003 (hid)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb2/2-1/2-1:1.0/0003:1A2C:0E24.0003
SUBSYSTEM=hid
HID_ID=0003:00001A2C:00000E24
HID_NAME=SEM USB Keyboard
HID_PHYS=usb-0000:00:14.0-1/input0
HID_UNIQ=
MODALIAS=hid:b0003g0001v00001A2Cp00000E24
SEQNUM=11067
so at least for mine, that 0003 appears to be part of the HID_ID. i have unplugged and plugged the same keyboard back in a few times. that number is consistent. on the other hand the number at the end (0005 in your question quoted here) seems to increment each time i plug the keyboard in. in my initial dmesg output it was 0001 and 0002. after a few trials, those are up to 0009 and 000A.
 

Members online


Top