Fix multipart incoming SMS QMI WMS routing and CSMS reassembly
This commit is contained in:
1 parent
1ef9064169
commit
8c2a337c0d
3 files changed
+102
-48
No files matched your search
+2
-2
@@ -31,8 +31,8 @@ Release versions follow the `<year-letter><MM><DD>` format (where `2026` is `a`,
|
||||
- Rewrote `sxmo_soundmonitor.sh` to monitor kernel `udev` `sound` jack events and `/dev/input/event*` `SW_HEADPHONE_INSERT` events (plus initial boot state), automatically switching audio output to `Headphones` (`RX1`/`RX2` HPHL/HPHR DAC) when 3.5mm headphones are plugged in and restoring `Speaker` on unplug.
|
||||
- Added `Earpiece` as a first-class routable audio output device alongside `Speaker` and `Headphones` in `sxmo_audio.sh`, `dmenu` Audio menu, and `xdrawer`.
|
||||
- Made volume controls strictly linear (`1%`–`100%` mapped directly without cubic `wpctl` distortion) across `sxmo_audio.sh`, `xdrawer`, and `dmenu`.
|
||||
- **Incoming SMS regression fix**:
|
||||
- Restored execute permissions (`0755`) on `/usr/share/sxmo/default_hooks/sxmo_hook_smslog.sh`, added active SIM/NV message storage polling (`wms-list-messages`) in `msm-modem-uim-selection dsds-daemon` for modem firmware that suppresses `WMS Event Report` indications, and deduplicated incoming SMS delivery between `dsds-daemon` and `sxmo_modem.sh`.
|
||||
- **Incoming and multipart SMS delivery and reassembly**:
|
||||
- Restored execute permissions (`0755`) on `/usr/share/sxmo/default_hooks/sxmo_hook_smslog.sh`, configured `QMI_WMS_SET_ROUTES` (`0x0032`) on Secondary GW (`SUB 1`) in `msm-modem-uim-selection dsds-daemon` to `STORE_AND_NOTIFY` / `TRANSFER_AND_ACK` so the Qualcomm baseband immediately acknowledges (`RP-ACK`) every incoming segment in hardware, added multi-pass SIM/NV message storage harvesting (`wms-list-messages`), and implemented full 8-bit (`IEI 0x00`) and 16-bit (`IEI 0x08`) concatenated SMS (CSMS) reassembly across both GSM-7 septet and UCS-2 UTF-16BE (including split surrogate pairs) with segment deduplication.
|
||||
- **Battery and idle power optimizations**:
|
||||
- Added VM writeback (`dirty_writeback_centisecs=6000`), `printk` throttling, `sched_autogroup_enabled=0`, Wi-Fi powersave (`iw dev wlan0 set power_save on`), and USB/platform runtime PM (`power/control = auto`) in `/etc/local.d/10-power-save.start` and `/etc/sysctl.d/10-power.conf`.
|
||||
- Increased `conky` desktop clock refresh interval to `15.0s` and froze `conky` (`SIGSTOP`/`SIGCONT`) whenever the screen is off or locked, replaced polling in `sxmo_modemmonitor.sh` with event-driven `dbus-monitor`, skipped redundant `sxmo_hook_statusbar.sh` updates while `screenoff`, and drained queued X11 `UnmapNotify` events in `neoui_hide()` so all 22 resident DWM plugins sleep at `0%` CPU when hidden.
|
||||
|
||||
@@ -235,7 +235,7 @@ checkfornewtexts() {
|
||||
exec 3<> "$XDG_RUNTIME_DIR/sxmo_modem.checkfornewtexts.lock"
|
||||
flock -x 3
|
||||
wait_parts=0
|
||||
while [ "$wait_parts" -lt 10 ]; do
|
||||
while [ "$wait_parts" -lt 25 ]; do
|
||||
SMS_LIST="$(mmcli -m any --messaging-list-sms 2>/dev/null || true)"
|
||||
if printf "%s\n" "$SMS_LIST" | grep -qE '/SMS/[0-9]+ \(receiving\)'; then
|
||||
sleep 1
|
||||
@@ -244,6 +244,9 @@ checkfornewtexts() {
|
||||
break
|
||||
fi
|
||||
done
|
||||
if printf "%s\n" "$SMS_LIST" | grep -qE '/SMS/[0-9]+ \(receiving\)'; then
|
||||
(sleep 10 && sxmo_modem.sh checkfornewtexts) >/dev/null 2>&1 &
|
||||
fi
|
||||
TEXTIDS="$(
|
||||
printf "%s\n" "$SMS_LIST" |
|
||||
grep -Eo '/SMS/[0-9]+ \(received\)' |
|
||||
|
||||
@@ -2251,7 +2251,7 @@ def _parse_deliver_tpdu(pdu, pos):
|
||||
pos += 1
|
||||
oa_digits = pdu[pos]
|
||||
oa_ton_npi = pdu[pos + 1]
|
||||
if oa_digits > 20 or (oa_ton_npi & 0x80) == 0:
|
||||
if oa_digits > 24 or (oa_ton_npi & 0x80) == 0:
|
||||
return None
|
||||
oa_byte_len = (oa_digits + 1) // 2
|
||||
if pos + 2 + oa_byte_len + 10 > len(pdu):
|
||||
@@ -2303,6 +2303,10 @@ def _parse_deliver_tpdu(pdu, pos):
|
||||
elif iei == 0x08 and len(iedata) >= 4:
|
||||
csms_ref = (iedata[0] << 8) | iedata[1]
|
||||
csms_total, csms_seq = iedata[2], iedata[3]
|
||||
if csms_ref is not None and (csms_total < 1 or csms_seq < 1 or csms_seq > csms_total):
|
||||
csms_ref = None
|
||||
csms_total = 1
|
||||
csms_seq = 1
|
||||
|
||||
# Determine alphabet from 3GPP TS 23.038 DCS
|
||||
if (dcs & 0xC0) in (0x00, 0x40):
|
||||
@@ -2323,7 +2327,7 @@ def _parse_deliver_tpdu(pdu, pos):
|
||||
payload = ud[udh_bytes : end_byte]
|
||||
if len(payload) % 2 == 1:
|
||||
payload = payload[:-1]
|
||||
text = payload.decode("utf-16-be", errors="replace")
|
||||
text = payload.decode("utf-16-be", errors="surrogatepass")
|
||||
elif alphabet == 1:
|
||||
end_byte = min(udl, len(ud))
|
||||
payload = ud[udh_bytes : end_byte]
|
||||
@@ -2386,6 +2390,13 @@ def decode_sms_deliver(pdu, only_tpdu=False):
|
||||
return _parse_deliver_tpdu(pdu, 0)
|
||||
|
||||
multipart_buf = {}
|
||||
recent_sms_dedup = {}
|
||||
|
||||
def _normalize_sms_text(s):
|
||||
try:
|
||||
return s.encode("utf-16", "surrogatepass").decode("utf-16", "replace")
|
||||
except Exception:
|
||||
return s
|
||||
|
||||
BLOCK_FILE = "/home/user/.config/sxmo/block.tsv"
|
||||
BLOCK_DIR = "/home/user/.local/share/sxmo/block"
|
||||
@@ -2455,58 +2466,84 @@ def deliver_sms_to_sxmo(sender, iso_ts, text, sim_slot):
|
||||
def handle_decoded_sms(info, sim_slot):
|
||||
if not info:
|
||||
return
|
||||
now = time.time()
|
||||
for k, ts in list(recent_sms_dedup.items()):
|
||||
if now - ts > 120.0:
|
||||
del recent_sms_dedup[k]
|
||||
seg_key = ("seg", info["sender"], info["time"], info["ref"], info["total"], info["seq"], info["text"])
|
||||
if seg_key in recent_sms_dedup and now - recent_sms_dedup[seg_key] < 15.0:
|
||||
return
|
||||
recent_sms_dedup[seg_key] = now
|
||||
if info["ref"] is not None and info["total"] > 1:
|
||||
done_key = ("csms_done", info["sender"], info["ref"], info["total"])
|
||||
if done_key in recent_sms_dedup:
|
||||
return
|
||||
key = (info["sender"], info["ref"], info["total"])
|
||||
parts = multipart_buf.setdefault(key, {"ts": time.time(), "time": info["time"], "slot": sim_slot, "segs": {}})
|
||||
parts["ts"] = time.time()
|
||||
parts["time"] = info["time"]
|
||||
parts = multipart_buf.setdefault(key, {"ts": now, "time": info["time"], "slot": sim_slot, "segs": {}})
|
||||
parts["ts"] = now
|
||||
parts["slot"] = sim_slot
|
||||
parts["segs"][info["seq"]] = info["text"]
|
||||
if len(parts["segs"]) >= info["total"]:
|
||||
full_text = "".join(parts["segs"].get(i, "") for i in range(1, info["total"] + 1))
|
||||
full_text = _normalize_sms_text("".join(parts["segs"].get(i, "") for i in range(1, info["total"] + 1)))
|
||||
msg_time = parts.get("time") or info["time"]
|
||||
del multipart_buf[key]
|
||||
deliver_sms_to_sxmo(info["sender"], info["time"], full_text, sim_slot)
|
||||
recent_sms_dedup[done_key] = now
|
||||
deliver_sms_to_sxmo(info["sender"], msg_time, full_text, sim_slot)
|
||||
else:
|
||||
deliver_sms_to_sxmo(info["sender"], info["time"], info["text"], sim_slot)
|
||||
deliver_sms_to_sxmo(info["sender"], info["time"], _normalize_sms_text(info["text"]), sim_slot)
|
||||
|
||||
def flush_stale_multipart():
|
||||
def flush_stale_multipart(wms_sock=None, wms_addr=None, txn=1, sim_slot=2):
|
||||
now = time.time()
|
||||
has_expired = any(now - parts["ts"] >= 45.0 for parts in multipart_buf.values())
|
||||
if has_expired and wms_sock is not None and wms_addr is not None:
|
||||
txn = poll_stored_sms(wms_sock, wms_addr, txn, sim_slot)
|
||||
now = time.time()
|
||||
for key, parts in list(multipart_buf.items()):
|
||||
if now - parts["ts"] >= 30.0:
|
||||
sender, _, total = key
|
||||
full_text = "".join(parts["segs"].get(i, "") for i in range(1, total + 1))
|
||||
if now - parts["ts"] >= 45.0:
|
||||
sender, ref, total = key
|
||||
full_text = _normalize_sms_text("".join(parts["segs"].get(i, "") for i in range(1, total + 1)))
|
||||
del multipart_buf[key]
|
||||
recent_sms_dedup[("csms_done", sender, ref, total)] = now
|
||||
if full_text:
|
||||
deliver_sms_to_sxmo(sender, parts.get("time", ""), full_text, parts.get("slot", 2))
|
||||
deliver_sms_to_sxmo(sender, parts.get("time", ""), full_text, parts.get("slot", sim_slot))
|
||||
return txn
|
||||
|
||||
def poll_stored_sms(wms_sock, wms_addr, txn, sim_slot):
|
||||
for stype in (0, 1):
|
||||
# WMSListMessages (0x0031): TLV 0x01 = storage_type, TLV 0x11 = message_mode (1 = GW)
|
||||
tlvs = qmi_req(wms_sock, wms_addr, txn, 0x0031, struct.pack("<BHB", 0x01, 1, stype) + struct.pack("<BHB", 0x11, 1, 1))
|
||||
txn = (txn % 60000) + 1
|
||||
raw_list = tlvs.get(0x01, b"")
|
||||
if len(raw_list) < 4:
|
||||
continue
|
||||
cnt = struct.unpack("<I", raw_list[:4])[0]
|
||||
off = 4
|
||||
for _ in range(cnt):
|
||||
if off + 5 > len(raw_list):
|
||||
break
|
||||
idx, tag = struct.unpack("<IB", raw_list[off:off+5])
|
||||
off += 5
|
||||
# tag 0 = MT read, 1 = MT not read
|
||||
if tag in (0, 1):
|
||||
r_tlvs = qmi_req(wms_sock, wms_addr, txn, 0x0022, struct.pack("<BHBI", 0x01, 5, stype, idx) + struct.pack("<BHB", 0x10, 1, 1))
|
||||
txn = (txn % 60000) + 1
|
||||
raw_msg = r_tlvs.get(0x01, b"")
|
||||
if len(raw_msg) >= 4:
|
||||
dlen = struct.unpack("<H", raw_msg[2:4])[0]
|
||||
pdu = raw_msg[4:4+dlen]
|
||||
info = decode_sms_deliver(pdu, only_tpdu=False)
|
||||
if info:
|
||||
handle_decoded_sms(info, sim_slot)
|
||||
qmi_req(wms_sock, wms_addr, txn, 0x0024, struct.pack("<BHB", 0x01, 1, stype) + struct.pack("<BHI", 0x10, 4, idx) + struct.pack("<BHB", 0x12, 1, 1))
|
||||
txn = (txn % 60000) + 1
|
||||
for _pass in range(3):
|
||||
found_any = False
|
||||
decoded_batch = []
|
||||
for stype in (0, 1):
|
||||
# WMSListMessages (0x0031): TLV 0x01 = storage_type, TLV 0x11 = message_mode (1 = GW)
|
||||
tlvs = qmi_req(wms_sock, wms_addr, txn, 0x0031, struct.pack("<BHB", 0x01, 1, stype) + struct.pack("<BHB", 0x11, 1, 1))
|
||||
txn = (txn % 60000) + 1
|
||||
raw_list = tlvs.get(0x01, b"")
|
||||
if len(raw_list) < 4:
|
||||
continue
|
||||
cnt = struct.unpack("<I", raw_list[:4])[0]
|
||||
off = 4
|
||||
for _ in range(cnt):
|
||||
if off + 5 > len(raw_list):
|
||||
break
|
||||
idx, tag = struct.unpack("<IB", raw_list[off:off+5])
|
||||
off += 5
|
||||
# tag 0 = MT read, 1 = MT not read
|
||||
if tag in (0, 1):
|
||||
found_any = True
|
||||
r_tlvs = qmi_req(wms_sock, wms_addr, txn, 0x0022, struct.pack("<BHBI", 0x01, 5, stype, idx) + struct.pack("<BHB", 0x10, 1, 1))
|
||||
txn = (txn % 60000) + 1
|
||||
qmi_req(wms_sock, wms_addr, txn, 0x0024, struct.pack("<BHB", 0x01, 1, stype) + struct.pack("<BHI", 0x10, 4, idx) + struct.pack("<BHB", 0x12, 1, 1))
|
||||
txn = (txn % 60000) + 1
|
||||
raw_msg = r_tlvs.get(0x01, b"")
|
||||
if len(raw_msg) >= 4:
|
||||
dlen = struct.unpack("<H", raw_msg[2:4])[0]
|
||||
pdu = raw_msg[4:4+dlen]
|
||||
info = decode_sms_deliver(pdu, only_tpdu=False)
|
||||
if info:
|
||||
decoded_batch.append(info)
|
||||
for info in decoded_batch:
|
||||
handle_decoded_sms(info, sim_slot)
|
||||
if not found_any:
|
||||
break
|
||||
return txn
|
||||
|
||||
def parse_call_info(tlvs):
|
||||
@@ -2722,6 +2759,13 @@ while True:
|
||||
w_txn += 1
|
||||
qmi_req(ws, wms_addr, w_txn, 0x0001, struct.pack("<BHB", 0x10, 1, 1))
|
||||
w_txn += 1
|
||||
# Configure WMS routes on Secondary GW (sub = 1) to match ModemManager:
|
||||
# Class 0 -> UIM + TRANSFER_AND_ACK (0x03), Class 1/2/3/None -> UIM + STORE_AND_NOTIFY (0x01)
|
||||
# so the baseband sends 3GPP RP-ACK in hardware for every multipart segment immediately.
|
||||
route_list = bytes.fromhex("060000000003000100010002000100030001000400010005ff02")
|
||||
route_tlvs = struct.pack("<BH", 0x01, len(route_list)) + route_list + struct.pack("<BHB", 0x10, 1, 0)
|
||||
qmi_req(ws, wms_addr, w_txn, 0x0032, route_tlvs)
|
||||
w_txn += 1
|
||||
|
||||
qmi_req(vs, voice_addr, v_txn, 0x0044, struct.pack("<BHB", 0x01, 1, 1))
|
||||
v_txn += 1
|
||||
@@ -2734,7 +2778,9 @@ while True:
|
||||
|
||||
try:
|
||||
while True:
|
||||
if active_calls or has_sub1_call_files():
|
||||
if pending_inds:
|
||||
poll_timeout = 0.0
|
||||
elif active_calls or has_sub1_call_files():
|
||||
poll_timeout = 1.0
|
||||
elif multipart_buf:
|
||||
poll_timeout = 2.0
|
||||
@@ -2765,9 +2811,13 @@ while True:
|
||||
dlen = struct.unpack("<H", tr[6:8])[0]
|
||||
pdu = tr[8:8+dlen]
|
||||
if ack_ind == 0:
|
||||
# Send QMI_WMS_SEND_ACK (0x0026): TLV 0x01 = [txn_id(4), protocol=1(WCDMA), success=1]
|
||||
ack_tlv = struct.pack("<BHIBB", 0x01, 6, mt_txn_id, 1, 1)
|
||||
ws.sendto(struct.pack("<BHHH", 0x00, w_txn, 0x0026, len(ack_tlv)) + ack_tlv, wms_addr)
|
||||
# Send QMI_WMS_SEND_ACK (0x0026): TLV 0x01 = [txn_id(4), protocol=1(GW), success=1], TLV 0x10 = 3GPP RP-ACK
|
||||
ack_tlvs = (
|
||||
struct.pack("<BHIBB", 0x01, 6, mt_txn_id, 1, 1)
|
||||
+ struct.pack("<BHBH", 0x10, 5, 0x00, 2)
|
||||
+ b"\x00\x00"
|
||||
)
|
||||
qmi_req(ws, wms_addr, w_txn, 0x0026, ack_tlvs)
|
||||
w_txn = (w_txn % 60000) + 1
|
||||
info = decode_sms_deliver(pdu, only_tpdu=True)
|
||||
if info:
|
||||
@@ -2788,7 +2838,8 @@ while True:
|
||||
sync_sub1_calls(calls, sec_slot)
|
||||
|
||||
if multipart_buf:
|
||||
flush_stale_multipart()
|
||||
w_txn = poll_stored_sms(ws, wms_addr, w_txn, sec_slot)
|
||||
w_txn = flush_stale_multipart(ws, wms_addr, w_txn, sec_slot)
|
||||
|
||||
if not got_voice_ind and (active_calls or has_sub1_call_files()):
|
||||
full_tlvs = qmi_req(vs, voice_addr, v_txn, 0x002F)
|
||||
|
||||
Reference in new issue
Block a user