Skip to content

Instantly share code, notes, and snippets.

@TravMurav

TravMurav/msm-uim-init Secret

Last active Feb 15, 2021
Embed
What would you like to do?
#!/sbin/openrc-run
# This hacky script tries to automatically configure UIM application
# for Qualcomm QMI modems with two sim slots. See [1] for more.
# [1] https://wiki.postmarketos.org/wiki/User:TravMurav/Dual-Sim_QMI_draft
#
# Installation:
#
# sudo apk add libqmi
# wget https://gist.githubusercontent.com/TravMurav/90bdd89f492bc39004d8ffb3d722f771/raw/msm-uim-init
# chmod +x msm-uim-init
# sudo mv msm-uim-init /etc/init.d/
# sudo rc-update add msm-uim-init
#
# See also:
# Service that configures SMS storage, may be needed to receive sms messages:
# https://gist.github.com/JonnyMe/3503f89ebbd98288e4630d1682f6a1c5
depend() {
before ofono
before modemmanager
# We don't want to block the ui or sshd for 10 seconds just
# because it wants to start last >:(
need tinydm
need sshd
}
start() {
# Sometimes we need to select application on SIM
if ! [ -x "$(command -v qmicli)" ]; then
echo 'Error: qmicli is not installed.' >&2
exit 1
fi
# FIXME: For some reason modem becoomes sad if the script
# runs too early.
sleep 10
# FIXME: Yes, this command is invoked a lot of times
QMI_CARDS="qmicli -d /dev/modem --uim-get-card-status"
# No action needed if application is already selected
# Or so I thought but some motorolla fw is very weird with this
# So we will reset the application and select it again
if ! [ "$($QMI_CARDS | grep -c "Primary GW: session doesn't exist")" ]
then
echo 'Warning: Application was already selected.' >&2
# exit 1
qmicli -d /dev/modem --uim-change-provisioning-session='activate=no,session-type=primary-gw-provisioning'
fi
if ! [ "$($QMI_CARDS | grep -c "Card state: 'present'")" ]
then
echo 'Error: No sim present.' >&2
exit 1
fi
FIRST_PRESENT_SLOT=$($QMI_CARDS | grep "Card state: 'present'" -m1 -B1 | head -n1 | cut -c7-7)
FIRST_PRESENT_AID=$($QMI_CARDS | grep "usim (2)" -m1 -A3 | tail -n1 | awk '{print $1}')
echo Selecting $FIRST_PRESENT_AID on slot $FIRST_PRESENT_SLOT
qmicli -d /dev/modem --uim-change-provisioning-session="slot=$FIRST_PRESENT_SLOT,activate=yes,session-type=primary-gw-provisioning,aid=$FIRST_PRESENT_AID"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment