[Solved] Usb-modeswitch for Telit LN940A not working

I'm setting up OpenWRT x86_64 VM with a Telit LN940A connected via M.2 to USB3 adapter. I used to have the same setup working with Ubuntu Desktop instead of OpenWRT.

One of things that needed to be done is to configure usb-modeswitch. On Ubuntu I had the udev rule added as such which switches the device to config 1:

# Telit LN940
ATTR{idVendor}=="1bc7", ATTR{idProduct}=="1900", RUN+="/usr/sbin/usb_modeswitch -v 1bc7 -p 1900 -u 1"

This results with the following output in /sys/kernel/debug/usb/devices when connected to Ubuntu Desktop:

output
T:  Bus=04 Lev=02 Prnt=07 Port=03 Cnt=02 Dev#= 15 Spd=5000 MxCh= 0
D:  Ver= 3.00 Cls=ef(misc ) Sub=02 Prot=01 MxPS= 9 #Cfgs=  3
P:  Vendor=1bc7 ProdID=1900 Rev= 3.10
S:  Manufacturer=Telit
S:  Product=Telit LN940 Mobile Broadband
S:  SerialNumber=0123456789ABCDEF
C:* #Ifs= 5 Cfg#= 1 Atr=a0 MxPwr=504mA
I:* If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=option
E:  Ad=81(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=01(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
I:* If#= 1 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=qmi_wwan
E:  Ad=83(I) Atr=03(Int.) MxPS=   8 Ivl=32ms
E:  Ad=82(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=02(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
I:* If#= 2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
E:  Ad=85(I) Atr=03(Int.) MxPS=  10 Ivl=32ms
E:  Ad=84(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=03(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
I:* If#= 3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
E:  Ad=87(I) Atr=03(Int.) MxPS=  10 Ivl=32ms
E:  Ad=86(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=04(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
I:* If#= 4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=option
E:  Ad=89(I) Atr=03(Int.) MxPS=  10 Ivl=32ms
E:  Ad=88(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=05(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
C:  #Ifs= 2 Cfg#= 2 Atr=a0 MxPwr=504mA
I:  If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=06 Prot=00 Driver=
E:  Ad=82(I) Atr=03(Int.) MxPS=  16 Ivl=32ms
I:  If#= 1 Alt= 0 #EPs= 0 Cls=0a(data ) Sub=00 Prot=00 Driver=
I:  If#= 1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=
E:  Ad=81(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=01(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
C:  #Ifs= 3 Cfg#= 3 Atr=a0 MxPwr=504mA
A:  FirstIf#= 0 IfCount= 2 Cls=02(comm.) Sub=0e Prot=00
I:  If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=0e Prot=00 Driver=
E:  Ad=82(I) Atr=03(Int.) MxPS=  64 Ivl=32ms
I:  If#= 1 Alt= 0 #EPs= 0 Cls=0a(data ) Sub=00 Prot=02 Driver=
I:  If#= 1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=02 Driver=
E:  Ad=81(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=01(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
I:  If#= 2 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=ff Prot=ff Driver=
E:  Ad=83(I) Atr=03(Int.) MxPS=  64 Ivl=32ms

In OpenWRT, I was able to figure out the change needed in /etc/usb-mode.json and basically added the below in the file and then performed /etc/init.d/usbmode restart:

        ,
		"1bc7:1900": {
			"*": {
				"config": 1
			}
		}

However it does not seem to perform the switch and the device sticks to config 2 instead:

output
T:  Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#=  4 Spd=5000 MxCh= 0
D:  Ver= 3.00 Cls=ef(misc ) Sub=02 Prot=01 MxPS= 9 #Cfgs=  3
P:  Vendor=1bc7 ProdID=1900 Rev= 3.10
S:  Manufacturer=Telit
S:  Product=Telit LN940 Mobile Broadband
S:  SerialNumber=0123456789ABCDEF
C:  #Ifs= 5 Cfg#= 1 Atr=a0 MxPwr=504mA
I:  If#= 0 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=ff Prot=ff Driver=
E:  Ad=81(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=01(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
I:  If#= 1 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=ff Prot=ff Driver=
E:  Ad=83(I) Atr=03(Int.) MxPS=   8 Ivl=32ms
E:  Ad=82(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=02(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
I:  If#= 2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=
E:  Ad=85(I) Atr=03(Int.) MxPS=  10 Ivl=32ms
E:  Ad=84(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=03(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
I:  If#= 3 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=
E:  Ad=87(I) Atr=03(Int.) MxPS=  10 Ivl=32ms
E:  Ad=86(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=04(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
I:  If#= 4 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=00 Prot=00 Driver=
E:  Ad=89(I) Atr=03(Int.) MxPS=  10 Ivl=32ms
E:  Ad=88(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=05(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
C:* #Ifs= 2 Cfg#= 2 Atr=a0 MxPwr=504mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=06 Prot=00 Driver=(none)
E:  Ad=82(I) Atr=03(Int.) MxPS=  16 Ivl=32ms
I:* If#= 1 Alt= 0 #EPs= 0 Cls=0a(data ) Sub=00 Prot=00 Driver=(none)
I:  If#= 1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=00 Driver=(none)
E:  Ad=81(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=01(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
C:  #Ifs= 3 Cfg#= 3 Atr=a0 MxPwr=504mA
A:  FirstIf#= 0 IfCount= 2 Cls=02(comm.) Sub=0e Prot=00
I:  If#= 0 Alt= 0 #EPs= 1 Cls=02(comm.) Sub=0e Prot=00 Driver=
E:  Ad=82(I) Atr=03(Int.) MxPS=  64 Ivl=32ms
I:  If#= 1 Alt= 0 #EPs= 0 Cls=0a(data ) Sub=00 Prot=02 Driver=
I:  If#= 1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=02 Driver=
E:  Ad=81(I) Atr=02(Bulk) MxPS=1024 Ivl=0ms
E:  Ad=01(O) Atr=02(Bulk) MxPS=1024 Ivl=0ms
I:  If#= 2 Alt= 0 #EPs= 1 Cls=ff(vend.) Sub=ff Prot=ff Driver=
E:  Ad=83(I) Atr=03(Int.) MxPS=  64 Ivl=32ms

I even tried running the usbmode manually and still the device did not switch:

root@OpenWrt:/sys/bus/usb/devices# usbmode -l -v -c /etc/usb-mode.json
Found device: 1bc7:1900 (Manufacturer: "Telit", Product: "Telit LN940 Mobile Broadband", Serial: "0123456789ABCDEF")
root@OpenWrt:/sys/bus/usb/devices#
root@OpenWrt:/sys/bus/usb/devices# usbmode -l -v -c /etc/usb-mode.json  -s
root@OpenWrt:/sys/bus/usb/devices#

From logread I see the following lines whenever I unplug and plug back the usb device which shows that usb-modeswitch is running automatically:

Sat Oct  2 11:44:37 2021 kern.info kernel: [ 1718.782797] usb 2-1: new SuperSpeed Gen 1 USB device number 8 using xhci_hcd
Sat Oct  2 11:44:37 2021 kern.info kernel: [ 1718.827846] option 2-1:2.0: GSM modem (1-port) converter detected
Sat Oct  2 11:44:37 2021 kern.info kernel: [ 1718.837642] option 2-1:2.0: device disconnected
Sat Oct  2 11:44:37 2021 kern.warn kernel: [ 1718.838131] usb 2-1: usbfs: process 15010 (usbmode) did not claim interface 1 before use
Sat Oct  2 11:44:38 2021 kern.warn kernel: [ 1719.039868] usb 2-1: usbfs: interface 1 claimed by usbfs while 'usbmode' sets config #1

I even tried adding "msg": [ ] in usb-mode.json as I saw that for other devices in the file but the end result is the device still not switching.

Is there anything I'm missing?

usb_modeswitch is not really needed here
1bc7:1900 corresponds to either "MBIM only" or "QMI + serial interfaces".
In the 2nd case to action is needed at all.
If your modem is currently in MBIM only mode in OpenWrt, then just plug it back in Ubuntu and send a command to switch it to the mode you need - AT^SETMODE=1 for "MBIM + serial interfaces" or AT^SETMODE=2 for "QMI + serial interfaces". The next time the modem will appear in the mode you set.

Thanks for the reply. I'll check the current AT^SETMODE and will tell what its set to now while its connected to Ubuntu.

So if I understood you correctly, then additions in the usb-mode.json are not needed, right? A follow up question is why ModemManager not detecting the device (I stopped the service and ran ModemManager --debug to check for logs of detection)? Is it because Driver=(none)?

Thanks for the info you provided. I was able to configure Telit to AT^SETMODE=2 which is the same as doing usb_modeswitch to config 1 on Ubuntu for switching to "QMI + serial interfaces". Now the modem is being detected properly by ModemManager and has connected successfully.

For anyone looking for more details, I found the following link which helped in understanding:
https://techship.com/faq/how-to-configure-telit-ln94-series-cellular-modules-to-qmi-mode-used-by-linux-systems-with-qmi-wwan-or-gobinet-driver/
First I opened a screen to one of the AT ports and queried the current AT^SETMODE (which was 0 that is "MBIM Only") and then set it to 2:

sudo screen /dev/ttyUSB1

In the screen:

AT
AT^SETMODE?
AT^SETMODE=2

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.