# Automatic usb_modeswitch

## Unb0rn

I have a Huawei E3372h stick LTE modem and it has zerocd image by default. 

I've installed usb_modeswitch, downloaded usb_modeswitch-data from draisberghof.de (as it's recommended by wiki) and installed its' config files. 

I even added config for my modem to /etc/usb_modeswitch.conf and now I can switch to CDC manually by issuing usb_modeswitch -c /etc/usb_modeswitch.conf or usb_modeswitch -v 12d1 -p 1f01 -M"<convert message here> but the system won't autoswitch modem for me. I have 40-usb_modeswitch.rule in /lib/udev/rules.d (tried to copy it in /etc/udev/rules.d/) this config has Huawei devices by default but I added my specifically. It still won't work in automatic mode.

I am running systemd, so udev should be no problem.

Any ideas? Or is this a bug?

Upd. It works after reboot-if I had my device plugged in while booting, it would autoswitch, but if I re-plug it while system is running, it still won't autoswitch.

If it helps, here are logs of usb_modeswitch on boot and dmesg on stick replug:pastebin.com/YaFXFjEH (modeswitch), pastebin.com/ytfpdLQJ(dmesg)

----------

## Unb0rn

Up.d First, tried to update usb_modeswitch to latest testing version, then, updated systemd to 231(232 has a regression and is masked) Nothing helps. Autoswitching works only on boot. Any ideas at all?

----------

## Logicien

It may depend on how you have compiled the support for your Huawei stick. If you have put it in the kernel image you cannot unload/reload the support unless you reboot. I ever had a Huawei stick. Only one string passing to the Usb stick with usb_modeswitch was working. The string can be put in /etc/usb_modeswitch.conf instead of being pass at command line.

If I remember well, sometimes I had to unplug the stick, unload and reload the option module and after had replug the stick, executing usb_modeswitch was switching the stick to modem mode. The modem was working but with tricky manipulations in some cases.

I am not sure if a Udev rule is the best way to switch the stick to modem mode. Is there a usb_modeswitch service you can enable at boot time who can do it?

----------

## borbor

You could try:

1. comment out the line

#exec 1<&- 2<&- 5<&- 7<&-

in /lib/udev/usb_modeswitch for /usb_modeswitch-2.4.0

2. downgrade to usb_modeswitch-2.3.0

or (not tested yet)

3. change the end of /lib/udev/usb_modeswitch file to:

systemctl --no-block start usb_modeswitch@$p1'_'$p2.service

(without if's; for gentoo with systemd only)

http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?f=2&t=2329

----------

## Unb0rn

 *Logicien wrote:*   

> It may depend on how you have compiled the support for your Huawei stick. If you have put it in the kernel image you cannot unload/reload the support unless you reboot. I ever had a Huawei stick. Only one string passing to the Usb stick with usb_modeswitch was working. The string can be put in /etc/usb_modeswitch.conf instead of being pass at command line.
> 
> If I remember well, sometimes I had to unplug the stick, unload and reload the option module and after had replug the stick, executing usb_modeswitch was switching the stick to modem mode. The modem was working but with tricky manipulations in some cases.
> 
> I am not sure if a Udev rule is the best way to switch the stick to modem mode. Is there a usb_modeswitch service you can enable at boot time who can do it?

 

Support for usb_xhci is built-in kernel, support for cdc is built as module. Re-plugging does not help. It autoswitches only if stick is plugged in while system is booting... 

usb_modeswitch.conf is already edited to include default and target vendors and products, also it has a string with MessaeContent. I can manually issue usb_modeswitch -c /etc/usb_modeswitch.conf and stick will switch to CDC...

----------

## Unb0rn

 *borbor wrote:*   

> You could try:
> 
> 1. comment out the line
> 
> #exec 1<&- 2<&- 5<&- 7<&-
> ...

 

Tried first method-nothing.

Tried to install testing 2.3.0(now i've tried every version on portage tree-2.2.6, 2.3.0 and 2.4.0)-still nothing...

And about third-is it okay that manually issuing systemctl start usb_modeswitch returns an error "no such file.."?

----------

## borbor

udevadm control --log-priority=debug

systemctl start ModemManager

systemctl start NetworkManager

Using 2.4.0 and "method 1" I have in journalctl -f :

...

kernel: usb-storage 3-1:1.0: USB Mass Storage device detected

.....

kernel: usb 3-1: new high-speed USB device number 13 using xhci_hcd

.....

kernel: option 3-1:1.3: GSM modem (1-port) converter detected

......

usb_modeswitch: switched to 12d1:1506 on 003/013

......

ModemManager[836]: <warn>  (ttyUSB2): port attributes not fully set

.....

and I have network connection.

----------

## borbor

Using "method 3" for 2.4.0 with very last lines

of  /lib/udev/usb_modeswitch:

IFS='/' read -r p1 p2 <<EOF

$1

EOF

PATH=/bin:/sbin:/usr/bin:/usr/sbin

        systemctl --no-block start usb_modeswitch@$p1'_'$p2.service

exit 0

also all looks ok.

=====

Logicien: "Is there a usb_modeswitch service you can enable at boot ...?"

I do not have enabled or started  usb_modeswitch.service .

----------

## Unb0rn

 *borbor wrote:*   

> udevadm control --log-priority=debug
> 
> systemctl start ModemManager
> 
> systemctl start NetworkManager
> ...

 

And now this is really weird. It really works after I issue udevam control command to set debug loglevel. If I don't-it still does not autoswitch. What it may be? User rights conflict?

----------

## borbor

That the log-priority=debug was the cause looks extremely unlikely.

It would be pure mysticism ( any timeouts  in the systemd ...).

ModemManager and NetworkManager could be causing the problems.

I'am very glad it works   :Very Happy: 

----------

## Unb0rn

 *borbor wrote:*   

> That the log-priority=debug was the cause looks extremely unlikely.
> 
> It would be pure mysticism ( any timeouts  in the systemd ...).
> 
> ModemManager and NetworkManager could be causing the problems.
> ...

 

Now I have to call it every boot... Anyway, thank you!=)

----------

## borbor

maybe kernel command line: udev.log-priority

(maybe /etc/udev/udev.conf)

I have installed (no changes in configuration files no kernel parameters connected to udev):

virtual/udev-217

udev-init-scripts-32

systemd-232

and no need to set debug level

----------

