usb devices and sleeping
RNode interfaces for reticulum have reminded me of this problem. Putting a laptop to sleep while it's using USB serial devices has a tendency to wake up and use a different device name when the laptop resumes.
For the RNode interface I can use a stupid hack to work around the problem by creating duplicate RNode interfaces with the same settings but using both T383838/dev/ttyUSB0 and T383838/dev/ttyUSB1. The end result is it will cheerfully flip flop between those two on this system and restore my network connection on waking up, but it will also create a lot of notice and failure messages for whichever interface is currently defunct.
Not related to reticulum, but some bread crumbs about a usb device coming back up: https://bbs.archlinux.org/viewtopic.php?id=253584
Related, persisting devices through sleep: https://www.kernel.org/doc/html//v4.12/driver-api/usb/persist.html
Unfortunaely that's not something I can just enable:
ls /sys/bus/usb/devices/ > all
# unplug device
ls /sys/bus/usb/devices/ > minus
sort -u all > all.sort
sort -u minus > minus.sort
diff all.sort minus.sort
15,16d14
< 2-1.2
< 2-1.2:1.0
cat /sys/bus/usb/devices/2-1.2/power/persist
1
It should already be persisting it. Increasing the debug for it:
echo 'module usbcore +pflm' | sudo tee /sys/kernel/debug/dynamic_debug/control
I see a few messages about T383838usb 2 and it disconnecting. I clearly see the same device that was on T383838/dev/ttyUSB0 wake up and not reconnect in time, and while that is happening a new device with all the same info being attached to T383838/dev/ttyUSB1.
Furthermore:
echo 0 | sudo tee /sys/bus/usb/devices/2-1.2/power/persist
This will reset back to 1 upon wake, and have to be set again, but two oddities here:
1. The device took longer to power off after going to sleep
2. The device reclaims the first available name, T383838/dev/ttyUSB0 and everything is as it should be
I probably need a udev rule to make this the default for the device.
There are problems with this approach, too. Devices could end up in a weird order if I have more than one radio plugged in.
But I'll try it anyway.
First, what's the device product and vendor id?
cat /sys/bus/usb/devices/2-1.2/idProduct
ea60
cat /sys/bus/usb/devices/2-1.2/idVendor
10c4
What would such a udev rule look like?
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="10c4", ATTR{idProduct}=="ea60", RUN+="sh -c 'echo 0 > /sys$env{DEVPATH}/power/persist'"
That didn't work.
Oh, hey, there's an ATTR for it! From an arch page: https://wiki.archlinux.org/title/Udev
SUBSYSTEM=="usb" ATTR{manufacturer}=="Foo" ATTR{product}=="Bar" ATTR{power/persist}="0"
So:
ACTION=="add", SUBSYSTEM=="usb", ATTR{idVendor}=="10c4", ATTR{idProduct}=="ea60", ATTR{power/persist}="0"
Update: I swear it worked, but the most frequent outcome now upon waking the machine I have to replug the cable.
Navigation