diff --git a/# Press Enter to accept default file location and no passphrase (or set one if you prefer) b/# Press Enter to accept default file location and no passphrase (or set one if you prefer) new file mode 100644 index 0000000..6f2ec56 --- /dev/null +++ b/# Press Enter to accept default file location and no passphrase (or set one if you prefer) @@ -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----- diff --git a/# Press Enter to accept default file location and no passphrase (or set one if you prefer).pub b/# Press Enter to accept default file location and no passphrase (or set one if you prefer).pub new file mode 100644 index 0000000..b8cb2ce --- /dev/null +++ b/# Press Enter to accept default file location and no passphrase (or set one if you prefer).pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMkpmkBs/SFGv2ti8eUS6ihQLL+At+U7wUV/Zy+lFf39 doanbangduy86@gmail.com diff --git a/README.md b/README.md index 9454492..c6bf30d 100644 --- a/README.md +++ b/README.md @@ -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 |diag|connect|auto|update |optimize|luci}` +- Example: `sh /usr/bin/main.sh optimize` diff --git a/scripts/ai_band_select.sh b/scripts/ai_band_select.sh new file mode 100755 index 0000000..fa301aa --- /dev/null +++ b/scripts/ai_band_select.sh @@ -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 diff --git a/scripts/auto_reconnect.sh b/scripts/auto_reconnect.sh new file mode 100755 index 0000000..9e6e549 --- /dev/null +++ b/scripts/auto_reconnect.sh @@ -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 diff --git a/scripts/band_lock.sh b/scripts/band_lock.sh new file mode 100755 index 0000000..f6edab5 --- /dev/null +++ b/scripts/band_lock.sh @@ -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 diff --git a/scripts/check_modem.sh b/scripts/check_modem.sh new file mode 100755 index 0000000..c8740f6 --- /dev/null +++ b/scripts/check_modem.sh @@ -0,0 +1,5 @@ +#!/bin/bash +echo "Detecting modem..." +lsusb +echo "Checking modem status..." +mmcli -m 0 diff --git a/scripts/detect_modem.sh b/scripts/detect_modem.sh new file mode 100755 index 0000000..06aae6f --- /dev/null +++ b/scripts/detect_modem.sh @@ -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}")%" diff --git a/scripts/firmware_update.sh b/scripts/firmware_update.sh new file mode 100755 index 0000000..a7729d3 --- /dev/null +++ b/scripts/firmware_update.sh @@ -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 diff --git a/scripts/load_balance.sh b/scripts/load_balance.sh new file mode 100755 index 0000000..6b698fa --- /dev/null +++ b/scripts/load_balance.sh @@ -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 diff --git a/scripts/load_kmod.sh b/scripts/load_kmod.sh new file mode 100755 index 0000000..6a518d1 --- /dev/null +++ b/scripts/load_kmod.sh @@ -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 diff --git a/scripts/luci_stub.sh b/scripts/luci_stub.sh new file mode 100755 index 0000000..1c16182 --- /dev/null +++ b/scripts/luci_stub.sh @@ -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 diff --git a/scripts/luci_wwan.sh b/scripts/luci_wwan.sh new file mode 100755 index 0000000..80c4afd --- /dev/null +++ b/scripts/luci_wwan.sh @@ -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 "}" diff --git a/scripts/main.sh b/scripts/main.sh new file mode 100755 index 0000000..73886d9 --- /dev/null +++ b/scripts/main.sh @@ -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 |diag|connect|auto|update |optimize|ai|balance|luci}" ;; +esac diff --git a/scripts/modem_connect.sh b/scripts/modem_connect.sh new file mode 100755 index 0000000..8bc0cff --- /dev/null +++ b/scripts/modem_connect.sh @@ -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 diff --git a/scripts/modem_diag.sh b/scripts/modem_diag.sh new file mode 100755 index 0000000..20df8f8 --- /dev/null +++ b/scripts/modem_diag.sh @@ -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" diff --git a/scripts/modem_profiles.sh b/scripts/modem_profiles.sh new file mode 100755 index 0000000..b4f6d7c --- /dev/null +++ b/scripts/modem_profiles.sh @@ -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 +} diff --git a/scripts/multi_modem.sh b/scripts/multi_modem.sh new file mode 100755 index 0000000..060625a --- /dev/null +++ b/scripts/multi_modem.sh @@ -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 diff --git a/scripts/optimize_network.sh b/scripts/optimize_network.sh new file mode 100755 index 0000000..e8e6b7c --- /dev/null +++ b/scripts/optimize_network.sh @@ -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 diff --git a/scripts/signal_monitor.py b/scripts/signal_monitor.py new file mode 100755 index 0000000..947bd7f --- /dev/null +++ b/scripts/signal_monitor.py @@ -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()) diff --git a/scripts/signal_monitor.sh b/scripts/signal_monitor.sh new file mode 100755 index 0000000..8d0f1e1 --- /dev/null +++ b/scripts/signal_monitor.sh @@ -0,0 +1,6 @@ +#!/bin/sh +# Monitor modem signal continuously +while true; do + sh /usr/bin/modem_diag.sh + sleep 10 +done diff --git a/scripts/smart_kmod.sh b/scripts/smart_kmod.sh new file mode 100755 index 0000000..f32c760 --- /dev/null +++ b/scripts/smart_kmod.sh @@ -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" diff --git a/scripts/wwan_hotplug.sh b/scripts/wwan_hotplug.sh new file mode 100755 index 0000000..8c82d25 --- /dev/null +++ b/scripts/wwan_hotplug.sh @@ -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 diff --git a/scripts/wwan_service.sh b/scripts/wwan_service.sh new file mode 100755 index 0000000..be3259b --- /dev/null +++ b/scripts/wwan_service.sh @@ -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 +}