mirror of
https://github.com/dikeckaan/mu300-linux.git
synced 2026-12-05 08:02:40 +00:00
fix(dashboard): refresh own number outside identity cache
Query CNUM and the IMS fallback on full collection rounds, migrate legacy cached numbers, and keep fast polling and static identity caching unchanged. Add startup recovery and stale-number regression tests, update the changelog, and refresh both r4 package checksums. Verified on F50 with IMS number available.
This commit is contained in:
6 files changed
+98
-30
No files matched your search
@@ -12,6 +12,7 @@
|
||||
- 无线客户端和 DHCP 租约在设备信息下方左右并排,手机窄屏自动上下排列;长设备名自动换行,不再把旁边撑出大片空白。
|
||||
- 「系统」版本移动到「LAN 地址」下方。
|
||||
- ICCID 下方增加本机号码;兼容更多号码读取方式。SIM 卡或基带未提供号码时仍显示 `--`,不会猜测号码。
|
||||
- 本机号码不再写入 6 小时身份缓存,每轮慢速采集重新查询,修复开机首次未读到号码后一直显示 `--` 的问题;不增加快速信号轮询和并发任务。
|
||||
- 修正 4G、5G 邻区频段识别,避免把频率重叠的频段直接误判为另一个频段。
|
||||
- 优化上下行速率曲线的上下留白,减少曲线边缘被裁切的情况。
|
||||
- 减少读取系统信息时启动的短命进程,保持原有字段含义和刷新频率。
|
||||
|
||||
@@ -1 +1 @@
|
||||
74085191aade9af7247ea6c4a935b7a1cca04b2d286db77aa883e7eaf1cb69e1 mu300-linux-openwrt-tf-6.18-20261008-r4.zip
|
||||
d23ccad4bb20dd36cfefebd8e162d97ee5c720f03ce75b14b2e6c6f0e2718106 mu300-linux-openwrt-tf-6.18-20261008-r4.zip
|
||||
@@ -1 +1 @@
|
||||
0554c2028de3fe6f081671988d9c78debc9dfc6fbb3318653de2e24f71d4c191 mu300-linux-openwrt-tf-7.2-20261008-r4.zip
|
||||
d3fab024e7cb19b93593c899472010241a789b30f3683967f94ded8fa7ec0d9c mu300-linux-openwrt-tf-7.2-20261008-r4.zip
|
||||
@@ -17,6 +17,13 @@ The package does not start or own the modem. Platform-specific access is behind
|
||||
small command adapters, so the LuCI and RPC code does not need to change for a
|
||||
different Unisoc OpenWrt firmware.
|
||||
|
||||
The own-number field is queried on every full cellular collection (normally
|
||||
every five seconds while the dashboard is active), first with CNUM and then
|
||||
with the IMS public identity if needed. It is not stored in the six-hour static
|
||||
SIM identity cache: a missing startup value can recover on the next full
|
||||
round. The existing serialized AT adapter is used; fast signal-only rounds
|
||||
never query the number and no additional polling worker is started.
|
||||
|
||||
## AT adapters
|
||||
|
||||
Configure `/etc/config/unisoc_modem`:
|
||||
|
||||
@@ -28,9 +28,11 @@
|
||||
# kills the channel until the next reboot (V50 archive; blacklisted in the rpcd
|
||||
# AT terminal too).
|
||||
#
|
||||
# SIM/module identity (IMEI/IMSI/ICCID/phone number/model/firmware) changes only when the SIM
|
||||
# SIM/module identity (IMEI/IMSI/ICCID/model/firmware) changes only when the SIM
|
||||
# or the firmware changes, so it lives in the configured state directory and is re-read
|
||||
# once per boot and at most every 6 hours thereafter, never inside a page request.
|
||||
# The own number can become available later through IMS. Query it on every
|
||||
# full round, not from the persistent identity cache or the fast signal tier.
|
||||
|
||||
# Two rounds share this script:
|
||||
# mu300-dash-cell full: everything below, ~11 commands, neighbours included
|
||||
@@ -394,7 +396,7 @@ if [ "$MODE" = full ]; then
|
||||
[ -s "$IDENT" ] && IDENT_AGE=$(( $(now) - $(date -r "$IDENT" +%s 2>/dev/null || echo 0) ))
|
||||
if [ "$IDENT_AGE" -ge 0 ] && [ "$IDENT_AGE" -le "$IDENT_MAXAGE" ] &&
|
||||
[ -n "$BOOT_ID" ] && grep -Fq "\"boot_id\":\"$BOOT_ID\"" "$IDENT" &&
|
||||
grep -q '"msisdn"[[:space:]]*:' "$IDENT"; then
|
||||
! grep -q '"msisdn"[[:space:]]*:' "$IDENT"; then
|
||||
IDENT_JSON=$(cat "$IDENT" 2>/dev/null || echo null)
|
||||
else
|
||||
i_mfg=$(at 'AT+CGMI' 2 | grep -v '^OK' | head -n1)
|
||||
@@ -404,21 +406,30 @@ if [ "$MODE" = full ]; then
|
||||
i_imsi=$(at 'AT+CIMI' 2 | tr -cd '0-9' | cut -c1-15)
|
||||
i_iccid=$(at 'AT+CCID' 2 | tr -cd '0-9' | cut -c1-20)
|
||||
if [ -n "$i_imei$i_imsi$i_iccid" ]; then
|
||||
# Keep this optional query out of the live signal polling path.
|
||||
# Cache a null too, so a SIM without a number is not queried again
|
||||
# on every full refresh. Older identity caches migrate once.
|
||||
i_msisdn=$(at 'AT+CNUM' 2 | cnum_number)
|
||||
i_msisdn_source=sim
|
||||
if [ -z "$i_msisdn" ]; then
|
||||
i_msisdn=$(at 'AT+SPPAURI?' 2 | ims_number)
|
||||
i_msisdn_source=ims
|
||||
fi
|
||||
[ -n "$i_msisdn" ] || i_msisdn_source=
|
||||
IDENT_JSON=$(printf '{"ts":%d,"boot_id":%s,"mfg":%s,"model":%s,"fw":%s,"imei":%s,"imsi":%s,"iccid":%s,"msisdn":%s,"msisdn_source":%s}' \
|
||||
"$(now)" "$(qs "$BOOT_ID")" "$(qs "$i_mfg")" "$(qs "$i_model")" "$(qs "$i_fw")" "$(qs "$i_imei")" "$(qs "$i_imsi")" "$(qs "$i_iccid")" "$(qs "$i_msisdn")" "$(qs "$i_msisdn_source")")
|
||||
# Persist static identity only; legacy caches with an own-number
|
||||
# field are rebuilt once so they cannot leak a stale number.
|
||||
IDENT_JSON=$(printf '{"ts":%d,"boot_id":%s,"mfg":%s,"model":%s,"fw":%s,"imei":%s,"imsi":%s,"iccid":%s}' \
|
||||
"$(now)" "$(qs "$BOOT_ID")" "$(qs "$i_mfg")" "$(qs "$i_model")" "$(qs "$i_fw")" "$(qs "$i_imei")" "$(qs "$i_imsi")" "$(qs "$i_iccid")")
|
||||
printf '%s\n' "$IDENT_JSON" > "$IDENT.part" 2>/dev/null && mv "$IDENT.part" "$IDENT"
|
||||
elif [ -s "$IDENT" ]; then IDENT_JSON=$(cat "$IDENT"); fi
|
||||
elif [ -s "$IDENT" ] && ! grep -q '"msisdn"[[:space:]]*:' "$IDENT"; then
|
||||
IDENT_JSON=$(cat "$IDENT")
|
||||
fi
|
||||
fi
|
||||
# Fresh lookup, even after an empty startup response. Use the existing
|
||||
# serialized AT adapter; no new worker, disk write or fast-tier query.
|
||||
i_msisdn=$(at 'AT+CNUM' 2 | cnum_number)
|
||||
i_msisdn_source=sim
|
||||
if [ -z "$i_msisdn" ]; then
|
||||
i_msisdn=$(at 'AT+SPPAURI?' 2 | ims_number)
|
||||
i_msisdn_source=ims
|
||||
fi
|
||||
[ -n "$i_msisdn" ] || i_msisdn_source=
|
||||
case "$IDENT_JSON" in
|
||||
null|'{}') IDENT_JSON='{' ;;
|
||||
*) IDENT_JSON="${IDENT_JSON%?}," ;;
|
||||
esac
|
||||
IDENT_JSON=$(printf '%s"msisdn":%s,"msisdn_source":%s}' \
|
||||
"$IDENT_JSON" "$(qs "$i_msisdn")" "$(qs "$i_msisdn_source")")
|
||||
fi
|
||||
|
||||
# "no answer at all" is a modem/daemon problem, not "no signal".
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""Optional own-number lookup stays in the infrequent SIM identity tier."""
|
||||
"""Own-number lookup is fresh on full rounds, while static identity stays cached."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from helpers import ShellTest, TOP
|
||||
|
||||
@@ -45,7 +46,7 @@ class DashboardIdentity(ShellTest):
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(result.stdout.strip(), expected)
|
||||
|
||||
def test_empty_number_is_cached_and_old_cache_migrates_once(self):
|
||||
def test_empty_number_retries_without_requerying_static_identity(self):
|
||||
self.stub('uci', 'exit 1')
|
||||
self.stub('fake-at', '''printf '%s\\n' "$*" >> "$STUBLOG/at-commands"
|
||||
case "$*" in
|
||||
@@ -65,10 +66,11 @@ esac''')
|
||||
result = self.script(shell, CELL, mode, **env)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
cached = json.loads((ident / 'sim.json').read_text())
|
||||
self.assertIn('msisdn', cached)
|
||||
self.assertIsNone(cached['msisdn'])
|
||||
self.assertEqual(log.read_text().count('AT+CNUM'), 1)
|
||||
self.assertEqual(log.read_text().count('AT+SPPAURI?'), 1)
|
||||
self.assertNotIn('msisdn', cached)
|
||||
self.assertNotIn('msisdn_source', cached)
|
||||
self.assertEqual(log.read_text().count('AT+CNUM'), 2)
|
||||
self.assertEqual(log.read_text().count('AT+SPPAURI?'), 2)
|
||||
self.assertEqual(log.read_text().count('AT+CIMI'), 1)
|
||||
data = json.loads((self.tmp / f'cache-{i}' / 'cell.json').read_text())
|
||||
self.assertIsNone(data['ident']['msisdn'])
|
||||
|
||||
@@ -95,19 +97,66 @@ esac''')
|
||||
result = self.script(shell, CELL, 'full', **env)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
cached = json.loads(cache.read_text())
|
||||
self.assertEqual(cached['msisdn'], '+8613800000000')
|
||||
self.assertEqual(cached['msisdn_source'], 'ims')
|
||||
data = json.loads((env['MU300_DASH_DIR'] / 'cell.json').read_text())
|
||||
self.assertEqual(data['ident']['msisdn'], '+8613800000000')
|
||||
self.assertEqual(data['ident']['msisdn_source'], 'ims')
|
||||
self.assertNotIn('msisdn', cached)
|
||||
self.assertNotEqual(cached['boot_id'], 'previous-boot')
|
||||
# Same boot serves the cache; no extra IMS request per refresh.
|
||||
# Same boot reuses static identity, but always queries the number.
|
||||
result = self.script(shell, CELL, 'full', **env)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(log.read_text().count('AT+SPPAURI?'), 1)
|
||||
self.assertEqual(log.read_text().count('AT+SPPAURI?'), 2)
|
||||
self.assertEqual(log.read_text().count('AT+CIMI'), 1)
|
||||
cached['boot_id'] = 'previous-boot'
|
||||
cache.write_text(json.dumps(cached))
|
||||
env['CNUM_REPLY'] = '+CNUM: "","+905551234567",145\nOK'
|
||||
result = self.script(shell, CELL, 'full', **env)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
cached = json.loads(cache.read_text())
|
||||
self.assertEqual(cached['msisdn'], '+905551234567')
|
||||
self.assertEqual(cached['msisdn_source'], 'sim')
|
||||
self.assertEqual(log.read_text().count('AT+SPPAURI?'), 1)
|
||||
data = json.loads((env['MU300_DASH_DIR'] / 'cell.json').read_text())
|
||||
self.assertEqual(data['ident']['msisdn'], '+905551234567')
|
||||
self.assertEqual(data['ident']['msisdn_source'], 'sim')
|
||||
self.assertNotIn('msisdn', cached)
|
||||
self.assertEqual(log.read_text().count('AT+SPPAURI?'), 2)
|
||||
self.assertEqual(log.read_text().count('AT+CIMI'), 2)
|
||||
|
||||
def test_live_number_recovers_after_startup_and_never_reuses_old_value(self):
|
||||
self.stub('uci', 'exit 1')
|
||||
self.stub('fake-at', '''printf '%s\\n' "$*" >> "$STUBLOG/at-commands"
|
||||
case "$*" in
|
||||
*AT+CFUN?*) printf '+CFUN: 1\\nOK\\n' ;;
|
||||
*AT+CIMI*) printf '460011234567890\\nOK\\n' ;;
|
||||
*AT+CNUM*) printf '%s\\n' "$CNUM_REPLY" ;;
|
||||
*AT+SPPAURI?*) printf '%s\\n' "$IMS_REPLY" ;;
|
||||
*) printf 'OK\\n' ;;
|
||||
esac''')
|
||||
for i, shell in enumerate(self.each_shell()):
|
||||
ident = self.tmp / f'live-ident-{i}'
|
||||
ident.mkdir()
|
||||
cache = ident / 'sim.json'
|
||||
# A fresh legacy cache containing a stale number must migrate too.
|
||||
boot = Path('/proc/sys/kernel/random/boot_id').read_text().strip()
|
||||
cache.write_text(json.dumps({'msisdn': '+905550000000', 'boot_id': boot}, separators=(',', ':')))
|
||||
log = self.tmp / 'at-commands'
|
||||
log.unlink(missing_ok=True)
|
||||
env = dict(MU300_AT=self.stubs / 'fake-at', MU300_DASH_IDENT_DIR=ident,
|
||||
MU300_DASH_DIR=self.tmp / f'live-cache-{i}', MU300_DASH_POOL_DIR=self.tmp / f'live-pool-{i}')
|
||||
previous = None
|
||||
for cnum, ims, number, source in [
|
||||
('ERROR', 'OK', None, None),
|
||||
('ERROR', '+SPPAURI: tel:+8613800000000\nOK', '+8613800000000', 'ims'),
|
||||
('+CNUM: "","+905551234567",145\nOK', 'ERROR', '+905551234567', 'sim'),
|
||||
('ERROR', 'ERROR', None, None),
|
||||
]:
|
||||
result = self.script(shell, CELL, 'full', CNUM_REPLY=cnum, IMS_REPLY=ims, **env)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
data = json.loads((env['MU300_DASH_DIR'] / 'cell.json').read_text())
|
||||
self.assertEqual(data['ident']['msisdn'], number)
|
||||
self.assertEqual(data['ident']['msisdn_source'], source)
|
||||
self.assertNotIn('msisdn', json.loads(cache.read_text()))
|
||||
if previous is not None:
|
||||
self.assertEqual((cache.read_bytes(), cache.stat().st_mtime_ns), previous)
|
||||
previous = (cache.read_bytes(), cache.stat().st_mtime_ns)
|
||||
self.assertEqual(log.read_text().count('AT+CIMI'), 1)
|
||||
self.assertEqual(log.read_text().count('AT+CNUM'), 4)
|
||||
self.assertEqual(log.read_text().count('AT+SPPAURI?'), 3)
|
||||
Reference in new issue
Block a user