Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
3a9c20c
Initial commit: Setup 5G Modem Support project
Mar 1, 2025
cbe25b2
Initial commit with RSA SSH
Mar 1, 2025
634d89c
Merge branch 'main' of github.com:Doanduy09/5G-Modem-Support
Mar 1, 2025
709879e
Merge branch 'Siriling:main' into main
Doanduy09 Mar 1, 2025
52d4225
Delete examples directory
Doanduy09 Mar 1, 2025
5b7e2c4
Delete docs directory
Doanduy09 Mar 1, 2025
7843265
Add auto-detection, band locking, diagnostics, and updated docs
Mar 1, 2025
1a5a1a1
Add band locking script for 4G/5G optimization
Mar 1, 2025
fb00d7f
Add modem auto-detection script for WWAN cards
Mar 1, 2025
3779f37
Format detect_modem.sh for better readability
Mar 1, 2025
c284e13
Update README with new features and instructions
Mar 1, 2025
b321a55
Add band locking script for 4G/5G optimization
Mar 1, 2025
70434a0
Add detailed modem diagnostics with signal and network logging
Mar 1, 2025
efcaf1c
Add multi-protocol support for QMI, MBIM, and PPP connectivity
Mar 1, 2025
a6d2983
Update README with new features and usage instructions
Mar 1, 2025
e3b566b
Add band locking script for 4G/5G optimization
Mar 1, 2025
05e87b2
Add detailed modem diagnostics with logging
Mar 1, 2025
9596a4e
Add multi-protocol support for QMI, MBIM, and PPP
Mar 1, 2025
71e641e
Update README with new features and instructions
Mar 1, 2025
5046748
Update main.sh as central script for all features
Mar 1, 2025
fa034cb
Add multi-modem detection and diagnostics
Mar 1, 2025
fbaea4e
Add signal_monitor.sh to replace Python version
Mar 1, 2025
af6f22e
Improve modem_connect.sh with device check
Mar 1, 2025
b4c77f2
Update README with all features and usage instructions
Mar 1, 2025
c164fdd
Add auto_reconnect.sh for automatic IP recovery
Mar 1, 2025
3a312b2
Update main.sh to include auto-reconnect option
Mar 1, 2025
6f17860
Update README with auto-reconnect feature
Mar 1, 2025
9b3495f
Add auto_reconnect.sh
Mar 1, 2025
9d783bd
Add load_kmod.sh for automatic kernel module loading
Mar 1, 2025
ceaf987
Update detect_modem.sh to integrate kmod loading
Mar 1, 2025
c0dad86
Update README with kmod support for multiple WWAN cards
Mar 1, 2025
2faf908
Enhance load_kmod.sh with dynamic loading, fallback, and logging
Mar 1, 2025
92ec3ad
Add modem_profiles.sh for extensible modem support
Mar 1, 2025
ae0f9d5
Update detect_modem.sh to use modem profiles
Mar 1, 2025
4afd838
Update README with enhanced kmod and profile support
Mar 1, 2025
5ff54aa
Recreate load_kmod.sh
Mar 1, 2025
f2ce9ed
Add smart_kmod.sh for advanced kmod management
Mar 1, 2025
cc44adc
Enhance modem_profiles.sh with detailed modem info
Mar 1, 2025
f388e33
Update detect_modem.sh with smart kmod and profile features
Mar 1, 2025
3fbee6f
Add wwan_service.sh for OpenWrt init.d integration
Mar 1, 2025
69faa44
Optimize modem_connect.sh with auto protocol detection
Mar 1, 2025
a87e214
Add luci_stub.sh as foundation for LuCI integration
Mar 1, 2025
8a19bb9
Add wwan_hotplug.sh for automatic modem handling
Mar 1, 2025
43f87a0
Add firmware_update.sh for modem firmware updates
Mar 1, 2025
0d48641
Add optimize_network.sh for signal-based optimization
Mar 1, 2025
808fada
Add luci_wwan.sh for JSON output to prep LuCI integration
Mar 1, 2025
b0ee7b3
Update main.sh with all advanced features
Mar 1, 2025
90309c7
Update README with ultimate features
Mar 1, 2025
6f0016d
Enhance detect_modem.sh with robust error handling and resource check
Mar 1, 2025
38af8b5
Add load_balance.sh for multi-modem support with mwan3
Mar 1, 2025
a1b697c
Add ai_band_select.sh for AI-driven band optimization
Mar 1, 2025
37188d0
Update main.sh with AI band selection and load balancing
Mar 1, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACDJKZpAbP0hRr9rYvHlEuooUCy/gLflO8FFf2cvpRX9/QAAAKBveJFgb3iR
YAAAAAtzc2gtZWQyNTUxOQAAACDJKZpAbP0hRr9rYvHlEuooUCy/gLflO8FFf2cvpRX9/Q
AAAECQsyTRnkj+LTLq0yris1aL46wib81+M8Ucc3b2o8am18kpmkBs/SFGv2ti8eUS6ihQ
LL+At+U7wUV/Zy+lFf39AAAAF2RvYW5iYW5nZHV5ODZAZ21haWwuY29tAQIDBAUG
-----END OPENSSH PRIVATE KEY-----
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMkpmkBs/SFGv2ti8eUS6ihQLL+At+U7wUV/Zy+lFf39 doanbangduy86@gmail.com
78 changes: 15 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,63 +1,15 @@
# 中文 | [English](https://github.com/Siriling/5G-Modem-Support/blob/main/EngLish.md)

# 5G模块支持

# 目录

[一、说明](#一说明)

[二、源代码地址 ](#二源代码地址)

# 一、说明

## 5G驱动

- quectel_Gobinet
- quectel_MHI
- quectel_QMI_WWAN
- quectel_SRPD_PCIE
- fibocom_MHI
- fibocom_QMI_WWAN

## 拨号工具

- quectel_cm_5G
- fibocom-dial

## 图形化界面设置

### 拨号

- luci-app-modem(新)

- luci-app-hypermodem
- luci-app-usbmodem
- luci-app-pcimodem
- luci-app-gobinetmodem
- luci-app-spdmodem

### 信息插件

- rooter

### 简化版信息插件

- luci-app-cpe

### AT命令工具

- sendat
- sms-tool

### 短信工具

- luci-app-sms-tool

# 二、源代码地址

- luci-app-hypermodem:https://github.com/momokind/luci-app-hypermodem

- sendat:https://github.com/ouyangzq/sendat
- luci-app-cpe:https://github.com/ouyangzq/luci-app-cpe
- sms-tool:https://github.com/obsy/sms_tool

# 5G-Modem-Support Enhanced
## Features
- Hotplug support for auto-detection
- Firmware updates for modems
- Network optimization based on signal
- LuCI-ready JSON output
- Full WWAN automation
## Installation
1. Clone: `git clone git@github.com:Doanduy09/5G-Modem-Support.git`
2. Copy: `scp scripts/* root@192.168.1.1:/usr/bin/`
3. Hotplug: `scp scripts/wwan_hotplug.sh root@192.168.1.1:/etc/hotplug.d/usb/20-wwan`
4. Install deps: `opkg install atinout qmi-utils libmbim ip-full`
## Usage
- Run: `sh /usr/bin/main.sh {detect|install|lock <bands>|diag|connect|auto|update <firmware>|optimize|luci}`
- Example: `sh /usr/bin/main.sh optimize`
28 changes: 28 additions & 0 deletions scripts/ai_band_select.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh
# AI-based band selection
DATA_FILE="/var/log/band_data.log"
DEVICE="/dev/ttyUSB2"
BANDS="1,3,7,20,28,38,40,41,77,78,79" # Common 4G/5G bands
collect_data() {
for band in $(echo $BANDS | tr "," " "); do
sh /usr/bin/band_lock.sh "$band"
sleep 5
signal=$(echo "AT+CSQ" | atinout - $DEVICE - | grep "+CSQ" | awk "{print \$2}" | cut -d"," -f1)
[ -z "$signal" ] && signal=0
echo "$(date),$band,$signal" >> $DATA_FILE
done
}
select_best_band() {
best_band=""
best_signal=0
while IFS="," read -r timestamp band signal; do
[ "$signal" -gt "$best_signal" ] && { best_signal="$signal"; best_band="$band"; }
done < $DATA_FILE
echo "Best band: $best_band (Signal: $best_signal)"
sh /usr/bin/band_lock.sh "$best_band"
}
if [ ! -f "$DATA_FILE" ]; then
echo "Collecting initial band data..."
collect_data
fi
select_best_band
4 changes: 4 additions & 0 deletions scripts/auto_reconnect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
INTERFACE="wwan0"
PROTOCOL="qmi"
while true; do if ! ip addr show $INTERFACE | grep -q "inet "; then echo "No IP detected, reconnecting..."; sh /usr/bin/modem_connect.sh $PROTOCOL; sleep 5; else echo "IP present"; fi; sleep 30; done
9 changes: 9 additions & 0 deletions scripts/band_lock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
# Usage: ./band_lock.sh "1,3,41"
BANDS="$1"
if [ -z "$BANDS" ]; then
echo "Error: Please provide band list (e.g., 1,3,41)"
exit 1
fi
echo "AT+QNWPREFCFG=\"nr5g_band\",$BANDS" | atinout - /dev/ttyUSB2 /tmp/band_result
cat /tmp/band_result
5 changes: 5 additions & 0 deletions scripts/check_modem.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
echo "Detecting modem..."
lsusb
echo "Checking modem status..."
mmcli -m 0
19 changes: 19 additions & 0 deletions scripts/detect_modem.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
# Advanced WWAN detection with error handling
source /usr/bin/modem_profiles.sh
LOGFILE="/var/log/wwan_detect.log"
sh /usr/bin/smart_kmod.sh || { echo "kmod loading failed" >> $LOGFILE; exit 1; }
for dev in $(lsusb | awk "{print \$6}" | grep -v "^$"); do
vid=$(echo $dev | cut -d: -f1)
pid=$(echo $dev | cut -d: -f2)
profile=$(get_profile $vid)
name=$(echo $profile | cut -d"|" -f1)
if [ -z "$vid" ] || [ -z "$pid" ]; then
echo "Invalid device info, skipping..." >> $LOGFILE
continue
fi
echo "Detected $name (VID:$vid PID:$pid)"
[ -e /dev/ttyUSB2 ] || { echo "No ttyUSB2 for $name" >> $LOGFILE; continue; }
timeout 5 echo "AT" | atinout - /dev/ttyUSB2 - || echo "Modem $name unresponsive" >> $LOGFILE
done
echo "Detection finished, CPU usage: $(top -bn1 | grep "Cpu(s)" | awk "{print \$2}")%"
15 changes: 15 additions & 0 deletions scripts/firmware_update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
# Update WWAN modem firmware
DEVICE="/dev/ttyUSB2"
FIRMWARE_PATH="$1"
if [ ! -e "$DEVICE" ]; then echo "Error: $DEVICE not found"; exit 1; fi
if [ -z "$FIRMWARE_PATH" ] || [ ! -f "$FIRMWARE_PATH" ]; then
echo "Error: Provide valid firmware file path"; exit 1
fi
VID=$(lsusb | grep "$(dmesg | grep ttyUSB | tail -1 | awk "{print \$NF}")" | awk "{print \$6}" | cut -d: -f1)
case $VID in
"05c6") # Quectel
qmi-firmware-update --update -d "$DEVICE" "$FIRMWARE_PATH"
;;
*) echo "Firmware update not supported for VID:$VID yet"; exit 1 ;;
esac
22 changes: 22 additions & 0 deletions scripts/load_balance.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# Multi-modem load balancing with mwan3
MOD EMS=()
i=1
for dev in /dev/ttyUSB*; do
[ -e "$dev" ] || continue
sh /usr/bin/detect_modem.sh
sh /usr/bin/modem_connect.sh
uci set network.wwan$i=interface
uci set network.wwan$i.proto="qmi"
uci set network.wwan$i.device="/dev/cdc-wdm$((i-1))"
uci commit network
MODEMS+=("wwan$i")
i=$((i+1))
done
opkg update && opkg install mwan3
for modem in "${MODEMS[@]}"; do
uci set mwan3.$modem=interface
uci set mwan3.$modem.enabled="1"
done
uci commit mwan3
/etc/init.d/mwan3 restart
6 changes: 6 additions & 0 deletions scripts/load_kmod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
# Enhanced kmod loading
LOGFILE="/var/log/wwan_kmod.log"
echo "$(date): Starting kmod loading..." >> $LOGFILE
load_module() { MODULE="$1"; if lsmod | grep -q "$MODULE"; then echo "Module $MODULE already loaded"; else modprobe $MODULE && echo "Loaded $MODULE" || echo "Failed to load $MODULE"; fi; }
for dev in $(lsusb | awk "{print \$6}"); do vid=$(echo $dev | cut -d: -f1); pid=$(echo $dev | cut -d: -f2); case $vid in "05c6") echo "Quectel modem"; load_module "qmi_wwan"; load_module "option"; echo "$vid $pid" > /sys/bus/usb-serial/drivers/option1/new_id ;; "1199" | "0f3d") echo "Sierra Wireless"; load_module "sierra"; load_module "option" ;; *) echo "Unknown device"; esac; done
9 changes: 9 additions & 0 deletions scripts/luci_stub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
# LuCI stub for WWAN status
echo "WWAN Status Report"
sh /usr/bin/detect_modem.sh
if [ -e /dev/ttyUSB2 ]; then
signal=$(echo "AT+CSQ" | atinout - /dev/ttyUSB2 -)
echo "Signal Strength: $signal"
fi
ip addr show wwan0
15 changes: 15 additions & 0 deletions scripts/luci_wwan.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
# WWAN status for LuCI integration
echo "{"
sh /usr/bin/detect_modem.sh > /tmp/wwan_detect
DETECT=$(cat /tmp/wwan_detect | grep "Detected" | sed "s/Detected /\\"/; s/ (VID:/\\", \\"vid\\": \\"/; s/ PID:/\\", \\"pid\\": \\"/; s/)$/\\"}/")
if [ -e /dev/ttyUSB2 ]; then
SIGNAL=$(echo "AT+CSQ" | atinout - /dev/ttyUSB2 - | grep "+CSQ" | awk "{print \$2}" | cut -d"," -f1)
FIRMWARE=$(echo "AT+CGMR" | atinout - /dev/ttyUSB2 - | grep -v "AT+CGMR")
echo "\\"modems\\": [$DETECT],"
echo "\\"signal\\": \\"$SIGNAL\\","
echo "\\"firmware\\": \\"$FIRMWARE\\""
else
echo "\\"modems\\": [], \\"signal\\": \\"N/A\\", \\"firmware\\": \\"N/A\\""
fi
echo "}"
17 changes: 17 additions & 0 deletions scripts/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
# Main script for 5G-Modem-Support
ACTION="$1"
case $ACTION in
"detect") sh /usr/bin/detect_modem.sh ;;
"install") sh /usr/bin/smart_kmod.sh ;;
"lock") sh /usr/bin/band_lock.sh "$2" ;;
"diag") sh /usr/bin/modem_diag.sh ;;
"connect") sh /usr/bin/modem_connect.sh ;;
"auto") sh /usr/bin/auto_reconnect.sh ;;
"update") sh /usr/bin/firmware_update.sh "$2" ;;
"optimize") sh /usr/bin/optimize_network.sh ;;
"ai") sh /usr/bin/ai_band_select.sh ;;
"balance") sh /usr/bin/load_balance.sh ;;
"luci") sh /usr/bin/luci_wwan.sh ;;
*) echo "Usage: $0 {detect|install|lock <bands>|diag|connect|auto|update <firmware>|optimize|ai|balance|luci}" ;;
esac
19 changes: 19 additions & 0 deletions scripts/modem_connect.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
# Auto-detect and connect modem
source /usr/bin/modem_profiles.sh
DEVICE="/dev/ttyUSB2"
if [ ! -e "$DEVICE" ]; then echo "Error: $DEVICE not found"; exit 1; fi
VID=$(lsusb | grep "$(dmesg | grep ttyUSB | tail -1 | awk "{print \$NF}")" | awk "{print \$6}" | cut -d: -f1)
PROFILE=$(get_profile $VID)
PROTOCOL=$(echo $PROFILE | cut -d"|" -f5)
echo "Using protocol: $PROTOCOL for $(echo $PROFILE | cut -d"|" -f1)"
for i in 1 2 3; do
case $PROTOCOL in
"QMI") qmicli -d /dev/cdc-wdm0 --wda-set-data-format && break ;;
"MBIM") mbimcli -d /dev/cdc-wdm0 --query-device-caps && break ;;
"PPP") echo "ATDT*99#" | atinout - $DEVICE - && break ;;
*) echo "Falling back to QMI"; qmicli -d /dev/cdc-wdm0 --wda-set-data-format && break ;;
esac
echo "Attempt $i failed, retrying..."
sleep 5
done
6 changes: 6 additions & 0 deletions scripts/modem_diag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
# Diagnostics for modem
echo "AT+CMEE=1;+CSQ;+QNWINFO" | atinout - /dev/ttyUSB2 /tmp/diag_result
cat /tmp/diag_result
echo "$(date): $(cat /tmp/diag_result)" >> /var/log/modem_diag.log
echo "Logged to /var/log/modem_diag.log"
13 changes: 13 additions & 0 deletions scripts/modem_profiles.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh
# Advanced modem profile database
get_profile() {
VID="$1"
case $VID in
"05c6") echo "Quectel|qmi_wwan,option|AT+CGMR,AT+CSQ|nr5g_band|QMI" ;;
"1199" | "0f3d") echo "Sierra Wireless|sierra,option|AT+CGMR,AT!GSTATUS?|band|MBIM" ;;
"1bc7") echo "Telit|qmi_wwan,option|AT+CGMR,AT#CSQ|band|QMI" ;;
"12d1") echo "Huawei|cdc_ether,option|AT+CGMR,AT+CSQ|band|PPP" ;;
"1e0e") echo "Fibocom|qmi_wwan,option|AT+CGMR,AT+CSQ|nr5g_band|QMI" ;;
*) echo "Unknown|qmi_wwan,option|AT+CGMR,AT+CSQ|band|QMI" ;;
esac
}
9 changes: 9 additions & 0 deletions scripts/multi_modem.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
# Detect and manage multiple modems
for dev in /dev/ttyUSB*; do
if [ -e "$dev" ]; then
echo "Found modem at $dev"
sh /usr/bin/detect_modem.sh
sh /usr/bin/modem_diag.sh
fi
done
16 changes: 16 additions & 0 deletions scripts/optimize_network.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/sh
# Optimize WWAN network settings
source /usr/bin/modem_profiles.sh
VID=$(lsusb | grep "$(dmesg | grep ttyUSB | tail -1 | awk "{print \$NF}")" | awk "{print \$6}" | cut -d: -f1)
PROFILE=$(get_profile $VID)
BAND_PARAM=$(echo $PROFILE | cut -d"|" -f4)
if [ -e "$DEVICE" ]; then
signal=$(echo "AT+CSQ" | atinout - /dev/ttyUSB2 - | grep "+CSQ" | awk "{print \$2}" | cut -d"," -f1)
if [ "$signal" -lt 10 ]; then
echo "Weak signal ($signal), optimizing bands..."
sh /usr/bin/band_lock.sh "1,3,41" # Example strong bands
else
echo "Signal strength OK ($signal)"
fi
fi
sh /usr/bin/modem_connect.sh
12 changes: 12 additions & 0 deletions scripts/signal_monitor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import asyncio
import serial

async def monitor_signal(port="/dev/ttyUSB0"):
ser = serial.Serial(port, 115200, timeout=1)
while True:
ser.write(b"AT+CSQ\r")
response = await asyncio.to_thread(ser.readline)
print(f"Signal: {response.decode().strip()}")
await asyncio.sleep(0.5)

asyncio.run(monitor_signal())
6 changes: 6 additions & 0 deletions scripts/signal_monitor.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh
# Monitor modem signal continuously
while true; do
sh /usr/bin/modem_diag.sh
sleep 10
done
22 changes: 22 additions & 0 deletions scripts/smart_kmod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# Smart kmod management for WWAN cards
LOGFILE="/var/log/wwan_kmod.log"
KERNEL_VERSION=$(uname -r)
check_and_install() {
MODULE="$1"
if lsmod | grep -q "$MODULE"; then
echo "Module $MODULE already loaded"
elif opkg list-installed | grep -q "$MODULE"; then
modprobe $MODULE && echo "Loaded $MODULE" || echo "Failed to load $MODULE"
else
echo "Installing $MODULE for kernel $KERNEL_VERSION..."
opkg update
opkg install $MODULE
modprobe $MODULE && echo "Loaded $MODULE" || echo "Failed, check kernel compatibility"
fi
echo "$(date): $MODULE status: $(lsmod | grep $MODULE)" >> $LOGFILE
}
for mod in kmod-usb-serial kmod-qmi-wwan kmod-cdc-mbim kmod-sierra kmod-cdc-ether; do
check_and_install $mod
done
echo "Smart kmod management complete"
12 changes: 12 additions & 0 deletions scripts/wwan_hotplug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh
# Hotplug script for WWAN devices
ACTION="$1"
DEVICENAME="$2"
if [ "$ACTION" = "add" ] && echo "$DEVICENAME" | grep -q "usb"; then
logger "WWAN device added: $DEVICENAME"
sh /usr/bin/detect_modem.sh
sh /usr/bin/modem_connect.sh
elif [ "$ACTION" = "remove" ]; then
logger "WWAN device removed: $DEVICENAME"
killall auto_reconnect.sh 2>/dev/null
fi
13 changes: 13 additions & 0 deletions scripts/wwan_service.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh /etc/rc.common
# WWAN service for OpenWrt
START=90
STOP=10
start() {
echo "Starting WWAN service..."
sh /usr/bin/detect_modem.sh
sh /usr/bin/auto_reconnect.sh &
}
stop() {
echo "Stopping WWAN service..."
killall auto_reconnect.sh
}