3

I use a USB Huawei ME906s-158 device as described here. If the module looses 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 here and there, 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.

Edit 1: 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 out put 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
4

I would like to comment, but I still do not have enough reputation points to do so.

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 https://unix.stackexchange.com/questions/61917/removing-builtin-modules-in-linux#61918.

If you want to deactivate your USB device and than reactivate it, have a look at his posting here: https://unix.stackexchange.com/questions/234581/disconnect-and-reconnect-usb-port-via-cli.

A much easier way here: https://superuser.com/questions/371068/is-there-a-way-to-power-down-a-usb-device-using-software.

EDIT:I

I do not have a Linux machine atm, so i am unfortunately unable to reproduce but it looks like bind and unbind could also work. Have a look at this https://www.kernel.org/doc/Documentation/usb/power-management.txt. Check the following two Textblocks: one staring with USB Port Power Control the other one right below starting with User Interface for Port Power Control. Make sure, when you unbind to unbind the module / driver of your usb device and not the module that is related to your usb hub.

EDIT II:

Okay, now I am back home and was able to test it on my machine. 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. Somwhere inside /sys/ we will find the driver, that is responsible for our usb device. We want to unbind our device from that driver. Therefor 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

Remeber, 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 lets 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 as root (with sudo it does not seem to work):

echo -n "2-2:1.0" > /sys/bus/usb/drivers/usb-storage/unbind

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

echo -n "2-2:1.0" > /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/

| improve this answer | |
  • 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 7: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 7: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 7: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 8: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 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.