diff --git a/modem/msm-modem/APKBUILD b/modem/msm-modem/APKBUILD index 5f5cd8ce3..a88bb538b 100644 --- a/modem/msm-modem/APKBUILD +++ b/modem/msm-modem/APKBUILD @@ -1,5 +1,5 @@ pkgname=msm-modem -pkgver=3 +pkgver=4 pkgrel=0 pkgdesc="Common support for Qualcomm MSM modems" url="https://postmarketos.org/" @@ -7,8 +7,13 @@ arch="armhf armv7 aarch64" license="GPL-3.0-or-later" depends="rmtfs rmtfs-openrc" install="$pkgname.post-install" -subpackages="$pkgname-rpmsg $pkgname-downstream" -source="msm-modem-downstream.initd udev-rpmsg.rules udev-downstream.rules" +subpackages="$pkgname-rpmsg $pkgname-downstream $pkgname-uim-selection:uim_selection" +source=" + msm-modem-downstream.initd + msm-modem-uim-selection.initd + udev-rpmsg.rules + udev-downstream.rules +" options="!check" package() { @@ -22,6 +27,14 @@ rpmsg() { 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() { pkgdesc="$pkgdesc (downstream)" 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" } -sha512sums="3172f8c409f552f13d1da29f14ab6c79072cd6da4acab151a1a0ea1858a416974456852609f14fe29cf97a6a45e60b99d0a57ddcde751da243ee5ac6fa8b672c msm-modem-downstream.initd +sha512sums=" +3172f8c409f552f13d1da29f14ab6c79072cd6da4acab151a1a0ea1858a416974456852609f14fe29cf97a6a45e60b99d0a57ddcde751da243ee5ac6fa8b672c msm-modem-downstream.initd +a68b3887aa24d88faeb84fa0896e1ebff4a2cbe9e71dd5123a517d6b2aba01576469afdc1817b17b7f010e1d33e50409fab3099993c422c01de94405ef98c176 msm-modem-uim-selection.initd 11437625988fcf57aa0b70f11496c458d4516de16391c2869ae975362f282d21d3af521a41dea00312797d20d52be5112dbf0041986bfb40f3b9fa5948d2c695 udev-rpmsg.rules -2a511c2e249d0ec5a52f04ffe1ef3d29cf3c4813143b103e54879ff89176ea45b1a5ffe21cb7dc2f1cdd84c3102ba45ef9926ed37e00b1ae12a36d01de35ea5a udev-downstream.rules" +2a511c2e249d0ec5a52f04ffe1ef3d29cf3c4813143b103e54879ff89176ea45b1a5ffe21cb7dc2f1cdd84c3102ba45ef9926ed37e00b1ae12a36d01de35ea5a udev-downstream.rules +" diff --git a/modem/msm-modem/msm-modem-uim-selection.initd b/modem/msm-modem/msm-modem-uim-selection.initd new file mode 100644 index 000000000..5076e6dc4 --- /dev/null +++ b/modem/msm-modem/msm-modem-uim-selection.initd @@ -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 $? +} diff --git a/modem/msm-modem/msm-modem-uim-selection.post-install b/modem/msm-modem/msm-modem-uim-selection.post-install new file mode 100644 index 000000000..eae6ed92c --- /dev/null +++ b/modem/msm-modem/msm-modem-uim-selection.post-install @@ -0,0 +1,2 @@ +#!/bin/sh +rc-update add msm-modem-uim-selection default