Restarting USB?

Hello, and sorry if this is a wrong section to post this.

I am using "MultiWeb_310_2015-03-14 ( OpenWRT r43228 ) / LuCI Branch (git-14.343.56284-0fb85fb)"

And ZTE MF823 modem.

The issue is -

When booting for the first time usb modem is not being detected, only solution I found to work is replugging modem by hand.
Restarting the router does not help.

Only possible dirty solution I can think of is restarting all usb ports when router starts, would that be possible with OpenWRT?

Thank you guys :roll_eyes:

You could try usbreset.

2 Likes

thank you, unfortunately usbreset did not work, and strangely modem shows up correctly when resetting (lights don't blink on it)

No modem is showing up in web UI

Any other ideas would be appreciated , i'm sitting here with 50 of these modems and routers :crazy_face:

I use this script to manually reset USB ports on my OpenSUSE pc (it's a Linux-based OS, same as OpenWrt is, so it should be similar).

When I googled the commands to do this I also found the command needed to do so on devices without PCI bus (if the controller isn't on a pcie lane) like a raspberry Pi.
On my linksys EA4500 running OpenWrt the usb controller isn't on PCI bus, so if I needed to reset its USB I would use that.

I don't know if it actually powers down the port, but on my Linux PC it does unlock any USB device that was frozen.

If you call it on its own it will execute the "for newer kernels", if you call it with "-old" argument will run the first block "for old kernels", and if you call it with "-nopci" argument you will run the commands for devices without PCI bus.

Or you can take the commands and use them in your own script.

#!/bin/sh

if [ "$1" == "-old" ] ; then
echo "for older kernels"
for i in /sys/bus/pci/drivers/[uoex]hci_hcd/*:*; do
  echo "${i##*/}" > "${i%/*}/unbind"
  echo "${i##*/}" > "${i%/*}/bind"
done
exit
fi

if [ "$1" == "-nopci" ] ; then
echo "For devices without PCI bus "
for i in /sys/bus/usb/drivers/*/*:*; do
  echo "${i##*/}" > "${i%/*}/unbind"
  echo "${i##*/}" > "${i%/*}/bind"
done
exit
fi

echo "for newer kernels"
for i in /sys/bus/pci/drivers/[uoex]hci-pci/*:*; do
  echo "${i##*/}" > "${i%/*}/unbind"
  echo "${i##*/}" > "${i%/*}/bind"
done

A hardware-based solution is to get a USB-controlled relay (they are cheap and plentiful on ebay) and use crelay tool (from package feed) to control it (either from a script or from its web interface) and switch power on/off from a custom USB cable where you connected power lines to the relay so you can physically power cycle the thing. See here the wiki article about crelay https://openwrt.org/docs/guide-user/services/automation/crelay

I did something similar in the past to drive a 220V AC latching relay to turn on and off other equipment depending on conditions I set in a script.

3 Likes

Thank you very much for the reply, unfortunately running the script (with -old, or -nopci) is returning
"./hehe.sh: line 6: can't create /sys/bus/pci/drivers/[uoex]hci_hcd/bind: nonexistent directory"
error.
Issuing command '/sys/bus/usb/drivers/usb/usb1 unbind' returns 'Permission Denied' :roll_eyes:

i am using OpenWRT on this small chinese 3g router


If I were using more expensive routers, then maybe a hardware-based workaround would be considered, but since this router costs like 8$ , I would buy new routers instead of a relay.. :frowning:

Try what is suggested here or the answer below it https://stackoverflow.com/questions/4702216/controlling-a-usb-power-supply-on-off-with-linux/12675749#12675749

Resetting usb like this isn't guaranteed to work on other routers, nor to actually reset the modem. That's why I mentioned the relay route.

USB relay boards from china cost like 2$ apiece, a Y-USB cable is also cheap, and it's 100% guaranteed to work because it's a physical switch.

1 Like

To actually know what is the USB number to use in the commands I linked above you should use dmesg command to see what is the number of the USB device.

For example if I wanted to reset the USB connection of my phone (usb tethering to the router), see the dmesg after I connect it (only relevant part shown, at the end of the text)

[335626.455920] usb 1-1.4.4: new high-speed USB device number 38 using orion-ehci
[335629.230934] usb 1-1.4.4: USB disconnect, device number 38
[335629.586051] usb 1-1.4.4: new high-speed USB device number 39 using orion-ehci
[335629.761896] rndis_host 1-1.4.4:1.0 usb0: register 'rndis_host' at usb-f1050000.ehci-1.4.4, RNDIS device, e2:e2:18:fe:3c:5b

its number is 1-1.4.4

I would need to write
echo "1-1.4.4" > /sys/bus/usb/drivers/usb/unbind
echo "1-1.4.4" > /sys/bus/usb/drivers/usb/bind

2 Likes