华为ME909S-821 4G模块折腾记录

前言

去年十几块钱收来一枚华为 ME909S-821 4G模块,在Windows 7 中工作正常。后来电脑刷 EndeavourOS 后模块就不工作了,几经折腾终于搞定。

修改 40-usb_modeswitch.rules 文件

华为4G模块存在多种工作模式,需要合理设置才能正常工作。在Linux系统中,这一功能由 usb_modeswitch 实现,4G模块的配置文件为 /lib/udev/rules.d/40-usb_modeswitch.rules,这个配置文件存在陈年BUG导致 ME909S-821 无法正常配置:

1
2
$ cat $(dirname $(grep -l 15c1 /sys/bus/usb/devices/*/idProduct))/bConfigurationValue

上述输出为空,证明模块没有获取到配置值。usb-devices 输出也可见端倪:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ usb-devices

T: Bus=01 Lev=01 Prnt=01 Port=01 Cnt=01 Dev#= 9 Spd=480 MxCh= 0
D: Ver= 2.10 Cls=00(>ifc ) Sub=00 Prot=ff MxPS=64 #Cfgs= 3
P: Vendor=12d1 ProdID=15c1 Rev=01.02
S: Manufacturer=Huawei Technologies Co., Ltd.
S: Product=HUAWEI Mobile
S: SerialNumber=0123456789ABCDEF
C: #Ifs= 0 Cfg#= 0 Atr= MxPwr=
cat: '/sys/bus/usb/devices/usb1/1-2/1-*:?.*/bInterfaceNumber': No such file or directory
cat: '/sys/bus/usb/devices/usb1/1-2/1-*:?.*/bAlternateSetting': No such file or directory
cat: '/sys/bus/usb/devices/usb1/1-2/1-*:?.*/bNumEndpoints': No such file or directory
cat: '/sys/bus/usb/devices/usb1/1-2/1-*:?.*/bInterfaceClass': No such file or directory
cat: '/sys/bus/usb/devices/usb1/1-2/1-*:?.*/bInterfaceSubClass': No such file or directory
cat: '/sys/bus/usb/devices/usb1/1-2/1-*:?.*/bInterfaceProtocol': No such file or directory
/usr/bin/usb-devices: line 79: printf: (none): invalid number
I: If#=0x Alt= 0 #EPs= 0 Cls=() Sub= Prot= Driver=(none)

可以手动为模块的 bConfigurationValue 这一变量赋值,使模块开始工作:(参考:12d1:15c1 Huawei Technologies Co., Ltd. ME906s LTE M.2 Module)

1
sudo echo 3 >> $(dirname $(grep -l 15c1 /sys/bus/usb/devices/*/idProduct))/bConfigurationValue

上述修改只是临时之策,重启后便会失效。更根本的方法是修改**/lib/udev/rules.d/40-usb_modeswitch.rules**,为其打补丁(来源参见udev should not be triggered again in “change” event):

1
sudo patch /lib/udev/rules.d/40-usb_modeswitch.rules < ./0001-Call-usb_modeswitch-only-on-add-event.patch 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
---
40-usb_modeswitch.rules | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/40-usb_modeswitch.rules b/40-usb_modeswitch.rules
index dae3e3a..16f404b 100644
--- a/40-usb_modeswitch.rules
+++ b/40-usb_modeswitch.rules
@@ -3,13 +3,13 @@
# Works with usb_modeswitch versions >= 2.4.0. Slash before %k parameter
# is for compatibility only. Versions >= 2.5.0 don't need it.
#
-ACTION!="add|change", GOTO="modeswitch_rules_end"
+ACTION!="add", GOTO="modeswitch_rules_end"

# Adds a symlink "gsmmodem[n]" to the lowest ttyUSB port with interrupt
# transfer; checked against a list of known modems, or else no action
KERNEL=="ttyUSB*", ATTRS{bNumConfigurations}=="*", PROGRAM="usb_modeswitch --symlink-name %p %s{idVendor} %s{idProduct} %E{PRODUCT}", SYMLINK+="%c"

-SUBSYSTEM!="usb", ACTION!="add",, GOTO="modeswitch_rules_end"
+SUBSYSTEM!="usb", GOTO="modeswitch_rules_end"

# Generic entry for most Huawei devices, excluding Android phones
ATTRS{idVendor}=="12d1", ATTRS{manufacturer}!="Android", ATTR{bInterfaceNumber}=="00", ATTR{bInterfaceClass}=="08", RUN+="usb_modeswitch '%b/%k'"
--
2.35.2

看着虽长,实则只修改了两处。打补丁后,执行以下命令使修改生效。

1
2
sudo udevadm control --reload-rules
sudo udevadm trigger

模块工作模式

默认情况下,ME909S-821工作在 模式3:

1
2
3
4
5
6
7
8
9
10
11
$ sudo usb_modeswitch -v 0x12d1 -p 0x15c1

Look for default devices ...
Found devices in default mode (1)
Access device 008 on bus 001
Get the current device configuration ...
Current configuration number is 3
Use interface number 0
with class 2
Warning: no switching method given. See documentation
-> Run lsusb to note any changes. Bye!

可见configuration number为 3 。也可通过cat直接查看:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ cat $(dirname $(grep -l 15c1 /sys/bus/usb/devices/*/idProduct))/bConfigurationValue
3

$ usb-devices

T: Bus=01 Lev=01 Prnt=03 Port=07 Cnt=01 Dev#= 5 Spd=480 MxCh= 0
D: Ver= 2.10 Cls=00(>ifc ) Sub=00 Prot=ff MxPS=64 #Cfgs= 3
P: Vendor=12d1 ProdID=15c1 Rev=01.02
S: Manufacturer=Huawei Technologies Co., Ltd.
S: Product=HUAWEI Mobile V7R11
S: SerialNumber=0123456789ABCDEF
C: #Ifs= 2 Cfg#= 3 Atr=a0 MxPwr=2mA
I: If#= 0 Alt= 0 #EPs= 1 Cls=02(commc) Sub=0e Prot=00 Driver=cdc_mbim
E: Ad=82(I) Atr=03(Int.) MxPS= 16 Ivl=2ms
I: If#= 1 Alt= 1 #EPs= 2 Cls=0a(data ) Sub=00 Prot=02 Driver=cdc_mbim
E: Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms

usb-devices 输出表明,在 模式3 中,ME909S-821 工作在 mbim 模式,此时 /dev 中存在 cdc-wdm0 这一设备:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$ sudo udevadm info /dev/cdc-wdm0

P: /devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:3.0/usbmisc/cdc-wdm0
M: cdc-wdm0
R: 0
J: c180:176
U: usbmisc
D: c 180:176
N: cdc-wdm0
L: 0
E: DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-8/1-8:3.0/usbmisc/cdc-wdm0
E: DEVNAME=/dev/cdc-wdm0
E: MAJOR=180
E: MINOR=176
E: SUBSYSTEM=usbmisc
E: USEC_INITIALIZED=7215681135
E: ID_MM_CANDIDATE=1

mbim是4G模块所推荐的工作模式。这一模式下,系统能够直接获取到IPv4与IPv6地址。不过有时候我们想连接到模块串口进行操作,这就需要切换4G模块的工作方式了。

切换模块工作方式

可以参照上文直接将 bConfigurationValue 改成 2 ,不过更推荐使用 usb_modeswitch 操作:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
$ sudo usb_modeswitch -v 12d1 -p 15c1 -u 2 -W


Take all parameters from the command line


* usb_modeswitch: handle USB devices with multiple modes
* Version 2.6.1 (C) Josua Dietze 2017
* Based on libusb1/libusbx

! PLEASE REPORT NEW CONFIGURATIONS !

DefaultVendor= 0x12d1
DefaultProduct= 0x15c1
Configuration=0x02

Look for default devices ...
found USB ID 8087:8001
found USB ID 1d6b:0002
found USB ID 1d6b:0003
found USB ID 12d1:15c1
vendor ID matched
product ID matched
found USB ID 24ae:4005
found USB ID 03f0:1f4a
found USB ID 1d6b:0002
Found devices in default mode (1)
Access device 005 on bus 001
Get the current device configuration ...
Current configuration number is 3
Use interface number 0
with class 2

USB description data (for identification)
-------------------------
Manufacturer: Huawei Technologies Co., Ltd.
Product: HUAWEI Mobile V7R11
Serial No.: 0123456789ABCDEF
-------------------------
Change configuration to 2 ...
Looking for active drivers ...
OK, driver detached
Configuration was reset
OK, configuration set
Get the current device configuration ...
The configuration was set successfully
-> Run lsusb to note any changes. Bye!

可见模式值已经被成功修改成2。再用usb-devices检查模块工作情况:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$ usb-devices

T: Bus=01 Lev=01 Prnt=03 Port=07 Cnt=01 Dev#= 5 Spd=480 MxCh= 0
D: Ver= 2.10 Cls=00(>ifc ) Sub=00 Prot=ff MxPS=64 #Cfgs= 3
P: Vendor=12d1 ProdID=15c1 Rev=01.02
S: Manufacturer=Huawei Technologies Co., Ltd.
S: Product=HUAWEI Mobile V7R11
S: SerialNumber=0123456789ABCDEF
C: #Ifs= 7 Cfg#= 2 Atr=a0 MxPwr=2mA
I: If#= 0 Alt= 0 #EPs= 1 Cls=02(commc) Sub=06 Prot=00 Driver=cdc_ether
E: Ad=82(I) Atr=03(Int.) MxPS= 16 Ivl=2ms
I: If#= 1 Alt= 0 #EPs= 2 Cls=0a(data ) Sub=06 Prot=00 Driver=cdc_ether
E: Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=81(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I: If#= 2 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=06 Prot=10 Driver=option
E: Ad=02(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=83(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=84(I) Atr=03(Int.) MxPS= 10 Ivl=32ms
I: If#= 3 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=06 Prot=13 Driver=option
E: Ad=03(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=85(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I: If#= 4 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=06 Prot=12 Driver=option
E: Ad=04(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=86(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I: If#= 5 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=06 Prot=06 Driver=option
E: Ad=05(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=87(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
I: If#= 6 Alt= 0 #EPs= 2 Cls=ff(vend.) Sub=06 Prot=1b Driver=option
E: Ad=06(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=88(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms

在模式2中,ME909S-821加载的驱动变成了cdc_ether,不再是模式3中的cdc_mbim。模式2中,网卡无法获取到IPv6地址,不过此时在**/dev**中出现了串口设备:

1
2
$ ls /dev/ttyUSB*
/dev/ttyUSB0 /dev/ttyUSB1 /dev/ttyUSB2 /dev/ttyUSB3 /dev/ttyUSB4

使用minicom连接到**/dev/ttyUSB0**:

1
sudo minicom -s

Serial port setup中,将Serial Device修改为**/dev/ttyUSB0**即可。

连接到**/dev/ttyUSB0后,可能会遇到屏幕不显示输入,但是盲打命令后执行又有相应输出的情况。可以通过ATE命令解决。盲输入ATE1并按下回车,之后的输入就会显示在屏幕上了。另外ATE0**可以再度关闭输入显示。(参考:Re: minicom shows nothing when i type AT)


华为ME909S-821 4G模块折腾记录
http://xiaofami.github.io/2025/01/22/me909s-821/
作者
tccmu
发布于
2025年1月22日
许可协议