6

I use a USB Huawei ME906s-158 device as described in Huawei ME906s-158 not working with Ubuntu 16.04. If the module loses the connection it seems to have problems reconnecting to the network. So my idea is to write some script, running in the background checking if the LTE connection is up, and if not release the USB device and reconnect it, using terminal commands. I found helpful information in How to enable/disable mobile broadband from terminal? and on this forum thread, but the code is not running on my Ubuntu 16.04, which may be the problem.

Taking this line for example:

modprobe -r -f uhci_hcd

results in modprobe: FATAL: Module uhci_hcd is builtin. error. The same is true if I use xhci_hcd, which is used for my device. So my question is how to change the modprobe commands to remove/connect my device?

Using dmesg the device is connected as

usb 3-13.1: new high-speed USB device number 117 using xhci_hcd
usb 3-13.1: New USB device found, idVendor=12d1, idProduct=15c1
usb 3-13.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 3-13.1: Product: HUAWEI Mobile
usb 3-13.1: Manufacturer: Huawei Technologies Co., Ltd.
usb 3-13.1: SerialNumber: 0123456789ABCDEF
cdc_ether 3-13.1:2.0 usb0: register 'cdc_ether' at usb-0000:00:14.0-13.1, CDC Ethernet Device, 02:1e:10:1f:00:00

where the device number varies and the usb port depends on the used hardware port. I think I simply don't understand how the device is named or mounted to be addressed with modprobe.

The relevant information of lsusb is Bus 003 Device 028: ID 12d1:15c1 Huawei Technologies Co., Ltd. and lsusb -t delivers

/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/15p, 480M
    |__ Port 12: Dev 11, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 3: Dev 14, If 1, Class=Human Interface Device, Driver=, 1.5M
        |__ Port 3: Dev 14, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 1: Dev 64, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 2: Dev 13, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 2: Dev 13, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
    |__ Port 13: Dev 3, If 0, Class=Hub, Driver=hub/4p, 480M
    |__ Port 14: Dev 29, If 0, Class=Communications, Driver=cdc_ether, 480M
    |__ Port 14: Dev 29, If 1, Class=CDC Data, Driver=cdc_ether, 480M
    |__ Port 14: Dev 29, If 2, Class=Vendor Specific Class, Driver=option, 480M
    |__ Port 14: Dev 29, If 3, Class=Vendor Specific Class, Driver=option, 480M
    |__ Port 14: Dev 29, If 4, Class=Vendor Specific Class, Driver=option, 480M
    |__ Port 14: Dev 29, If 5, Class=Vendor Specific Class, Driver=option, 480M
    |__ Port 14: Dev 29, If 6, Class=Vendor Specific Class, Driver=option, 480M

Thank you very much for your help.

Here is the full dmesg output:

[748010.825136] usb 3-13.1: new high-speed USB device number 79 using xhci_hcd
[748010.926143] usb 3-13.1: New USB device found, idVendor=12d1, idProduct=15c1
[748010.926146] usb 3-13.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[748010.926147] usb 3-13.1: Product: HUAWEI Mobile
[748010.926148] usb 3-13.1: Manufacturer: Huawei Technologies Co., Ltd.
[748010.926149] usb 3-13.1: SerialNumber: 0123456789ABCDEF
[748010.929581] cdc_ether 3-13.1:2.0 usb0: register 'cdc_ether' at usb-0000:00:14.0-13.1, CDC Ethernet Device, 02:1e:10:1f:00:00
[748010.930008] option 3-13.1:2.2: GSM modem (1-port) converter detected
[748010.930178] usb 3-13.1: GSM modem (1-port) converter now attached to ttyUSB0
[748010.930451] option 3-13.1:2.3: GSM modem (1-port) converter detected
[748010.930588] usb 3-13.1: GSM modem (1-port) converter now attached to ttyUSB1
[748010.930829] option 3-13.1:2.4: GSM modem (1-port) converter detected
[748010.930929] usb 3-13.1: GSM modem (1-port) converter now attached to ttyUSB2
[748010.931153] option 3-13.1:2.5: GSM modem (1-port) converter detected
[748010.931254] usb 3-13.1: GSM modem (1-port) converter now attached to ttyUSB3
[748010.931474] option 3-13.1:2.6: GSM modem (1-port) converter detected
[748010.931580] usb 3-13.1: GSM modem (1-port) converter now attached to ttyUSB4
[748010.959172] cdc_ether 3-13.1:2.0 enp0s20u13u1c2: renamed from usb0
[748010.986087] IPv6: ADDRCONF(NETDEV_UP): enp0s20u13u1c2: link is not ready
[748010.986238] cdc_ether 3-13.1:2.0 enp0s20u13u1c2: kevent 12 may have been dropped
[748010.990538] IPv6: ADDRCONF(NETDEV_UP): enp0s20u13u1c2: link is not ready

The full output of tree /sys/devices/pci0000:00/0000:00:14.0/usb3/3-13/ | grep driver is:

│   │   ├── driver -> ../../../../../../../bus/usb/drivers/cdc_ether
│   │   ├── driver -> ../../../../../../../bus/usb/drivers/cdc_ether
│   │   ├── driver -> ../../../../../../../bus/usb/drivers/option
│   │   │   ├── driver -> ../../../../../../../../bus/usb-serial/drivers/option1
│   │   ├── driver -> ../../../../../../../bus/usb/drivers/option
│   │   │   ├── driver -> ../../../../../../../../bus/usb-serial/drivers/option1
│   │   ├── driver -> ../../../../../../../bus/usb/drivers/option
│   │   │   ├── driver -> ../../../../../../../../bus/usb-serial/drivers/option1
│   │   ├── driver -> ../../../../../../../bus/usb/drivers/option
│   │   │   ├── driver -> ../../../../../../../../bus/usb-serial/drivers/option1
│   │   ├── driver -> ../../../../../../../bus/usb/drivers/option
│   │   │   ├── driver -> ../../../../../../../../bus/usb-serial/drivers/option1
│   ├── driver -> ../../../../../../bus/usb/drivers/usb
│   ├── driver -> ../../../../../../bus/usb/drivers/hub
├── driver -> ../../../../../bus/usb/drivers/usb
Zanna
  • 69,223
  • 56
  • 216
  • 327
Martin Herrmann
  • 133
  • 2
  • 2
  • 9

1 Answers1

4

As far as I know modprobe is used to add/remove modules / drivers. With the command modprobe -r -f uhci_hcd you are trying to remove a module built in the kernel see this post on Unix & Linux.

If you want to deactivate your USB device and than reactivate it, have a look at his posting here: Disconnect and reconnect USB post via CLI.

Or try the much easier way here: Is there a way to power down a USB device using software?.

Some useful information can be found on this kernel.org page on power management. under USB Port Power Control and below that at User Interface for Port Power Control.

I am running Lubuntu 16.04. My USB device for testing was a 8GB USB stick.

First of all open a terminal and type dmesg -w. Next, plug in your USB device.

[ 1897.772736] usb 2-2: new high-speed USB device number 7 using ehci-pci
[ 1897.907178] usb 2-2: New USB device found, idVendor=13fe, idProduct=5500
[ 1897.907185] usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[ 1897.907189] usb 2-2: Product: Silicon-Power8G
[ 1897.907193] usb 2-2: Manufacturer: UFD 3.0
[ 1897.907196] usb 2-2: SerialNumber: P1602059070C691668B63659
[ 1897.907802] usb-storage 2-2:1.0: USB Mass Storage device detected
[ 1897.909153] scsi host22: usb-storage 2-2:1.0
[ 1898.910257] scsi 22:0:0:0: Direct-Access     UFD 3.0  Silicon-Power8G  PMAP PQ: 0 ANSI: 6
[ 1898.910896] sd 22:0:0:0: Attached scsi generic sg4 type 0
[ 1898.911521] sd 22:0:0:0: [sdd] 15126528 512-byte logical blocks: (7.74 GB/7.21 GiB)
[ 1898.912261] sd 22:0:0:0: [sdd] Write Protect is off
[ 1898.912266] sd 22:0:0:0: [sdd] Mode Sense: 45 00 00 00
[ 1898.912982] sd 22:0:0:0: [sdd] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 1898.950371]  sdd:
[ 1898.953487] sd 22:0:0:0: [sdd] Attached SCSI removable disk
[ 1899.243793] FAT-fs (sdd): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.

Here we can see that a new ehci-pci device at usb 2-2 has been recognized. After a few lines usb 2-2 changes to usb-storage 2-2:1.0 to scsi 22:0:0:0 and finally to sd 22:0:0:0 What these numbers exactly mean is beyond my knowledge. It has something to do with the USB-Port, but that is not everything. At least it is an identifier.

Anyway, now we go for the /sys/ folder. Somewhere inside /sys/ we will find the driver that is responsible for our usb device. We want to unbind our device from that driver. Therefore we need to find out the path to the driver and its unbind command. We are going to use the tree command.

We type tree /sys/ | grep 22:0:0:0

alex@ga-P55A-UD5:~$ tree /sys/ | grep 22:0:0:0
│   ├── sdd -> ../devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host22/target22:0:0/22:0:0:0/block/sdd
│   │   │   ├── 22:0:0:0 -> ../../../devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host22/target22:0:0/22:0:0:0
│   │   │   │   ├── 22:0:0:0 -> ../../../../devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host22/target22:0:0/22:0:0:0
│   │   ├── sdd -> ../../devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host22/target22:0:0/22:0:0:0/block/sdd
│   │   ├── 22:0:0:0 -> ../../devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host22/target22:0:0/22:0:0:0/bsg/22:0:0:0
│   │   ├── 22:0:0:0 -> ../../devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host22/target22:0:0/22:0:0:0/scsi_device/22:0:0:0
│   │   ├── 22:0:0:0 -> ../../devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host22/target22:0:0/22:0:0:0/scsi_disk/22:0:0:0
│   │   └── sg4 -> ../../devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host22/target22:0:0/22:0:0:0/scsi_generic/sg4
│   │   ├── 8:48 -> ../../devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host22/target22:0:0/22:0:0:0/block/sdd
│       ├── 21:4 -> ../../devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host22/target22:0:0/22:0:0:0/scsi_generic/sg4
│       ├── 249:4 -> ../../devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host22/target22:0:0/22:0:0:0/bsg/22:0:0:0
│   │   │   │   │   │   │   │   ├── 22:0:0:0
│   │   │   │   │   │   │   │   │   │       ├── device -> ../../../22:0:0:0
│   │   │   │   │   │   │   │   │   │   └── 22:0:0:0
│   │   │   │   │   │   │   │   │   │       ├── device -> ../../../22:0:0:0
│   │   │   │   │   │   │   │   │   │   └── 22:0:0:0
│   │   │   │   │   │   │   │   │   │       ├── device -> ../../../22:0:0:0
│   │   │   │   │   │   │   │   │   │   └── 22:0:0:0
│   │   │   │   │   │   │   │   │   │       ├── device -> ../../../22:0:0:0
│   │   │   │   │   │   │   │   │   │       ├── device -> ../../../22:0:0:0

The very first line is already telling us where to go:

../devices/pci0000:00/0000:00:1d.7/usb2/2-2/2-2:1.0/host22/target22:0:0/22:0:0:0/block/sdd

Remember, we are still searching for the unbind command somewhere in a driver folder, that is somehow attached to our device. Our device, regarding to dmesg was also called 2-2:1.0, so we use that as parent folder for tree:

tree /sys/devices/pci0000\:00/0000\:00\:1d.7/usb2/2-2/2-2\:1.0/ | grep driver
alex@ga-P55A-UD5:~$ tree /sys/devices/pci0000\:00/0000\:00\:1d.7/usb2/2-2/2-2\:1.0/ | grep driver
├── driver -> ../../../../../../bus/usb/drivers/usb-storage
│   │   │   ├── driver -> ../../../../../../../../../bus/scsi/drivers/sd

Now we have found the path to the driver that is attached to the usb device.

So let's ls /sys/bus/usb/drivers/usb-storage/

alex@ga-P55A-UD5:~$ ls /sys/bus/usb/drivers/usb-storage/
2-2:1.0  bind  module  new_id  remove_id  uevent  unbind

Now we have all the information we need, so we type the following:

echo -n "2-2:1.0" | sudo tee /sys/bus/usb/drivers/usb-storage/unbind`

and right after that, because you wanted the reconnect effect:

echo -n "2-2:1.0" | sudo tee /sys/bus/usb/drivers/usb-storage/bind

Output of dmesg -w:

[ 3516.792135] usb-storage 2-2:1.0: USB Mass Storage device detected
[ 3516.792406] scsi host23: usb-storage 2-2:1.0
[ 3517.792201] scsi 23:0:0:0: Direct-Access     UFD 3.0  Silicon-Power8G  PMAP PQ: 0 ANSI: 6
[ 3517.792879] sd 23:0:0:0: Attached scsi generic sg4 type 0
[ 3517.793592] sd 23:0:0:0: [sdd] 15126528 512-byte logical blocks: (7.74 GB/7.21 GiB)
[ 3517.794340] sd 23:0:0:0: [sdd] Write Protect is off
[ 3517.794346] sd 23:0:0:0: [sdd] Mode Sense: 45 00 00 00
[ 3517.796083] sd 23:0:0:0: [sdd] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA
[ 3517.801135]  sdd:
[ 3517.803788] sd 23:0:0:0: [sdd] Attached SCSI removable disk
[ 3518.096593] FAT-fs (sdd): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.

I hope this will help you to find a solution.

If you want to read more about the topic: https://lwn.net/Articles/143397/

Zanna
  • 69,223
  • 56
  • 216
  • 327
AlexOnLinux
  • 922
  • 7
  • 19
  • Hi, thanks for your comprehensive answer. Unfortunately I have a few questions. First regards the calling as root: I tried with `sudo -i` and then typed the commands, think that should do the job, right? – Martin Herrmann Jan 11 '18 at 07:42
  • Second: Calling the unbind command at the end results in `write error: No such device`. My problem is, I can't find the correct name of the device. I tried `usb 3-13.1`, `3-13.1`, `usb-0000:00:14.0-13.1`, `cdc_ether 3-13.1:2.0`, and others. Nothing works. Third looking for the used driver results in a tree showing several links to a driver at `bus/usb/drivers/cdc_ether` and several to `bus/usb-serial/drivers/option1`. – Martin Herrmann Jan 11 '18 at 07:50
  • Also thank you for the link to the c++ program. I found that, too, but have the same problem, I don't know the name or destination of the usb device, I can't find the assigned name, or don't understand how Ubuntu names these devices – Martin Herrmann Jan 11 '18 at 07:55
  • Thank you, and you are welcome. Unfortunately i am not a Linux guru too. I suppose `cdc_ether` is going to be the driver of your usb device with the identifier `3-13.1:2.0`. So try the following: `tree /sys/ | grep 3-13.1:2.0` or `tree /sys/ | grep cdc_ether`. And yes, i ment `sudo -i`. And when you have found the position of the `unbind` command in the `cdc_ether` directory type somethinkg like `echo -n "3-13.1:2.0" > /sys/bus/drivers/cdc_ether/unbind` – AlexOnLinux Jan 11 '18 at 08:26
  • What is the output of `ls /sys/bus/drivers/cdc_ether/` ? The Output should contain `bind`, `unbind` and the identifier that you have to put inside the brackets `echo -n "identifier" > /sys/bus/drivers/cdc_ether/unbind` – AlexOnLinux Jan 11 '18 at 08:41
  • Using `tree /sys/ | grep 3-13.1:2.0` results in a list with several lines on different stages. In principle all point to `3-13.1:2.0 -> ../../../devices/pci0000:00/0000:00:14.0/usb3/3-13/3-13.1/` and then some subdirectories, as `3-13.1:2.0` or `3-13.1:2.0/net/enp0s20u13u1c2`. If I grep for `3-13.1:2.2` e.g. it points to the appropriate subdirectories of this name and it shows me names as ttyUSB0, ttyUSB1 or enp0s20u13u1c2. These names relate to the output of `dmesg`. – Martin Herrmann Jan 12 '18 at 07:24
  • The echo command always results in `-bash: /sys/bus/drivers/cdc_ether/unbind: No such file or directory` error, no matter which identifier I try, and I tested all I can think of now: ttyUSB1 to ttyUSB4, 3-13.1:2.0 to 3-13.1:2.6, all combinations with cdc_ether and option1 and enp0s20u13u1c2. Always the same result :-( – Martin Herrmann Jan 12 '18 at 07:27
  • `ls /sys/bus/usb/drivers/cdc_ether/` results in `3-13.1:2.0@ 3-13.1:2.1@ bind module@ new_id remove_id uevent unbind`. Here the 3-13.1:2.1@ are symbolic links pointing to `../../../../devices/pci0000:00/0000:00:14.0/usb3/3-13/3-13.1/3-13.1:2.0/` and `..../3-13.1:2.0/` respectively. – Martin Herrmann Jan 12 '18 at 07:29
  • Sorry I am in hurry. The `dmesg` output that you did post in your question, is this the whole output of the plug in and plug out procedure? If not, please unplug your device, type `dmesg -w` and plug your device in, wait a few seconds and plug it out again and edit your question. The output of `ls` tells that you have two devices binded to the same driver `3-.1:2.0` and `3-13.1.2` that and the `@` symbol are confusing me. What is the output of: `tree /sys/devices/pci0000:00/0000:00:14.0/usb3/3-13/ | grep driver` ? – AlexOnLinux Jan 12 '18 at 07:54
  • Hi, no problem, I am very happy that you are helping me, and time may not be a problem :-) I edited my original question and added the complete dmesg output and the output of the tree command. – Martin Herrmann Jan 12 '18 at 08:38
  • just found this link, maybe his procedure works? https://loginroot.com/power-off-and-on-usb-device-in-linux-ubuntu/ First he tried to turn of the device, later he tries to turn off the whole hub instead. Atm i am lacking ideas... – AlexOnLinux Jan 12 '18 at 12:58
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/71591/discussion-between-alexonlinux-and-martin-herrmann). – AlexOnLinux Jan 12 '18 at 17:00