msm-modem: add UIM selection script (MR 2291)

On some devices, primarily with two sim slots, modem doesn't choose
the sim automatically. Add an init script that would detect in which
slot the sim is present and configure the modem to use it.
This commit is contained in:
Nikita Travkin 2021-06-30 09:58:19 +05:00 committed by Alexey Minnekhanov
parent 55dc5819e4
commit 436c544289
No known key found for this signature in database
GPG key ID: EBF5ECFFFEE34DED
3 changed files with 122 additions and 5 deletions

View file

@ -1,5 +1,5 @@
pkgname=msm-modem pkgname=msm-modem
pkgver=3 pkgver=4
pkgrel=0 pkgrel=0
pkgdesc="Common support for Qualcomm MSM modems" pkgdesc="Common support for Qualcomm MSM modems"
url="https://postmarketos.org/" url="https://postmarketos.org/"
@ -7,8 +7,13 @@ arch="armhf armv7 aarch64"
license="GPL-3.0-or-later" license="GPL-3.0-or-later"
depends="rmtfs rmtfs-openrc" depends="rmtfs rmtfs-openrc"
install="$pkgname.post-install" install="$pkgname.post-install"
subpackages="$pkgname-rpmsg $pkgname-downstream" subpackages="$pkgname-rpmsg $pkgname-downstream $pkgname-uim-selection:uim_selection"
source="msm-modem-downstream.initd udev-rpmsg.rules udev-downstream.rules" source="
msm-modem-downstream.initd
msm-modem-uim-selection.initd
udev-rpmsg.rules
udev-downstream.rules
"
options="!check" options="!check"
package() { package() {
@ -22,6 +27,14 @@ rpmsg() {
install -Dm644 "$srcdir/udev-rpmsg.rules" "$subpkgdir/usr/lib/udev/rules.d/55-$pkgname.rules" install -Dm644 "$srcdir/udev-rpmsg.rules" "$subpkgdir/usr/lib/udev/rules.d/55-$pkgname.rules"
} }
uim_selection() {
pkgdesc="$pkgdesc (UIM selection)"
depends="$pkgname libqmi"
install="$subpkgname.post-install"
install -Dm755 "$srcdir/$subpkgname.initd" "$subpkgdir/etc/init.d/$subpkgname"
}
downstream() { downstream() {
pkgdesc="$pkgdesc (downstream)" pkgdesc="$pkgdesc (downstream)"
depends="$pkgname libqipcrtr4msmipc libsmdpkt_wrapper keepfileopen" depends="$pkgname libqipcrtr4msmipc libsmdpkt_wrapper keepfileopen"
@ -31,6 +44,9 @@ downstream() {
install -Dm644 "$srcdir/udev-downstream.rules" "$subpkgdir/usr/lib/udev/rules.d/55-$pkgname.rules" install -Dm644 "$srcdir/udev-downstream.rules" "$subpkgdir/usr/lib/udev/rules.d/55-$pkgname.rules"
} }
sha512sums="3172f8c409f552f13d1da29f14ab6c79072cd6da4acab151a1a0ea1858a416974456852609f14fe29cf97a6a45e60b99d0a57ddcde751da243ee5ac6fa8b672c msm-modem-downstream.initd sha512sums="
3172f8c409f552f13d1da29f14ab6c79072cd6da4acab151a1a0ea1858a416974456852609f14fe29cf97a6a45e60b99d0a57ddcde751da243ee5ac6fa8b672c msm-modem-downstream.initd
a68b3887aa24d88faeb84fa0896e1ebff4a2cbe9e71dd5123a517d6b2aba01576469afdc1817b17b7f010e1d33e50409fab3099993c422c01de94405ef98c176 msm-modem-uim-selection.initd
11437625988fcf57aa0b70f11496c458d4516de16391c2869ae975362f282d21d3af521a41dea00312797d20d52be5112dbf0041986bfb40f3b9fa5948d2c695 udev-rpmsg.rules 11437625988fcf57aa0b70f11496c458d4516de16391c2869ae975362f282d21d3af521a41dea00312797d20d52be5112dbf0041986bfb40f3b9fa5948d2c695 udev-rpmsg.rules
2a511c2e249d0ec5a52f04ffe1ef3d29cf3c4813143b103e54879ff89176ea45b1a5ffe21cb7dc2f1cdd84c3102ba45ef9926ed37e00b1ae12a36d01de35ea5a udev-downstream.rules" 2a511c2e249d0ec5a52f04ffe1ef3d29cf3c4813143b103e54879ff89176ea45b1a5ffe21cb7dc2f1cdd84c3102ba45ef9926ed37e00b1ae12a36d01de35ea5a udev-downstream.rules
"

View file

@ -0,0 +1,99 @@
#!/sbin/openrc-run
# This script tries to automatically configure UIM application for Qualcomm QMI
# modems with more than one sim slot.
name="UIM Slot selection"
description="Select UIM slot and application on the embedded QMI nodem."
depend() {
# FIXME: This service may delay boot for some time, make sure that it
# runs after UI and sshd so preceived boot time isn't affected.
after *
need rmtfs
before ofono
before modemmanager
}
# All of the logic is placed in the service start method as we want to block
# other services while the modem isn't ready yet.
start() {
# libqmi must be present to use this script.
if ! [ -x "$(command -v qmicli)" ]
then
eend 1 'qmicli is not installed.'
return 1
fi
# Prepare a qmicli command with desired modem path.
# The modem may appear after some delay, wait for it.
count=0
while [ -z "$QMICLI_MODEM" ] && [ "$count" -lt "45" ]
do
# Check if legacy rpmsg exported device exists.
if [ -e "/dev/modem" ]
then
QMICLI_MODEM="qmicli --silent -d /dev/modem"
veinfo "Using /dev/modem"
# Check if the qmi device from wwan driver exists.
elif [ -e "/dev/wwan0qmi0" ]
then
# Using --device-open-qmi flag as we may have libqmi
# version that can't automatically detect the type yet.
QMICLI_MODEM="qmicli --silent -d /dev/wwan0qmi0 --device-open-qmi"
veinfo "Using /dev/wwan0qmi0"
# Check if QRTR is available for new devices.
elif qmicli --silent -pd qrtr://0 --uim-noop > /dev/null
then
QMICLI_MODEM="qmicli --silent -pd qrtr://0"
veinfo "Using qrtr://0"
fi
sleep 1
count=$((count+1))
done
veinfo "Waited $count seconds for modem device to appear"
if [ -z "$QMICLI_MODEM" ]
then
eend 2 'No modem available.'
return 2
fi
QMI_CARDS=$($QMICLI_MODEM --uim-get-card-status)
# Fail if all slots are empty but wait a bit for the sim to appear.
count=0
while ! printf "%s" "$QMI_CARDS" | grep -Fq "Card state: 'present'" && [ "$count" -lt "11" ]
do
sleep 1
count=$((count+1))
QMI_CARDS=$($QMICLI_MODEM --uim-get-card-status)
done
if [ "$count" -gt "10" ]
then
eend 4 'No sim present.'
return 4
fi
veinfo "Waited $count seconds for modem to come up"
# Clear the selected application in case the modem is in a bugged state
if ! printf "%s" "$QMI_CARDS" | grep -Fq "Primary GW: session doesn't exist"
then
ewarn 'Application was already selected.'
$QMICLI_MODEM --uim-change-provisioning-session='activate=no,session-type=primary-gw-provisioning' > /dev/null
fi
# Extract first available slot number and AID for usim application
# on it. This should select proper slot out of two if only one UIM is
# present or select the first one if both slots have UIM's in them.
FIRST_PRESENT_SLOT=$(printf "%s" "$QMI_CARDS" | grep "Card state: 'present'" -m1 -B1 | head -n1 | cut -c7-7)
FIRST_PRESENT_AID=$(printf "%s" "$QMI_CARDS" | grep "usim (2)" -m1 -A3 | tail -n1 | awk '{print $1}')
veinfo "Selecting $FIRST_PRESENT_AID on slot $FIRST_PRESENT_SLOT"
# Finally send the new configuration to the modem.
$QMICLI_MODEM --uim-change-provisioning-session="slot=$FIRST_PRESENT_SLOT,activate=yes,session-type=primary-gw-provisioning,aid=$FIRST_PRESENT_AID" > /dev/null
eend $?
}

View file

@ -0,0 +1,2 @@
#!/bin/sh
rc-update add msm-modem-uim-selection default