I dug into it with the help of AI. The problem is related to Incorrect SMS reassembly including stale fragments . When staled part(s) with the same 8bit reference number from the same sender to the same SIM card exist, ofono looks at the number of parts. If it is the same, then SMS will be assembled, but some parts may be replaced by staled parts. If it is different, however, no SMS will be assembled at all.
The problem should be, that the function sms_assembly_expire from smsutil.c is never called from the code, so staled parts will last in storage forever. Proposed patch removes staled SMS after 24 hours.
ofono-patches.targz (1.3 KB)
I made it also propose hotfix, that cleans the messages and restarts ofono every day at 4 AM:
/usr/local/sbin/ofono-sms-assembly-cleanup
#!/bin/sh
BASE=/var/lib/ofono
AGE_MIN=1440
TAG=ofono-sms-assembly-cleanup
logger -t "$TAG" "Starting SMS assembly cleanup"
find "$BASE"/*/sms_assembly \
-mindepth 1 -maxdepth 1 \
-type d \
-mmin +"$AGE_MIN" \
-print |
while IFS= read -r dir; do
logger -t "$TAG" "Removing stale SMS assembly: $dir"
rm -rf -- "$dir"
done
logger -t "$TAG" "Restarting oFono"
if systemctl restart ofono; then
logger -t "$TAG" "oFono restarted successfully"
else
logger -t "$TAG" "ERROR: failed to restart oFono"
exit 1
fi
/etc/systemd/system/ofono-sms-assembly-cleanup.service
[Unit]
Description=Clean stale oFono SMS assemblies and restart oFono
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/ofono-sms-assembly-cleanup
/etc/systemd/system/ofono-sms-assembly-cleanup.timer
[Unit]
Description=Daily oFono SMS assembly cleanup
[Timer]
OnCalendar=*-*-* 04:00:00
Persistent=true
[Install]
WantedBy=timers.target
After creating these files, execute
systemctl daemon-reload
systemctl enable --now ofono-sms-assembly-cleanup.timer
I applied the hotfix to my phone today, and since I’m not very familiar with systemd services, I just hope it will work. If you think it should be done in a different way, feel free to comment.