Skip to content

Instantly share code, notes, and snippets.


TravMurav/msm-uim-init Secret

Last active Feb 15, 2021
What would you like to do?
# This hacky script tries to automatically configure UIM application
# for Qualcomm QMI modems with two sim slots. See [1] for more.
# [1]
# Installation:
# sudo apk add libqmi
# wget
# 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:
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
# 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")" ]
echo 'Warning: Application was already selected.' >&2
# exit 1
qmicli -d /dev/modem --uim-change-provisioning-session='activate=no,session-type=primary-gw-provisioning'
if ! [ "$($QMI_CARDS | grep -c "Card state: 'present'")" ]
echo 'Error: No sim present.' >&2
exit 1
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}')
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