modem/msm-modem: move service logic to standalone script (MR 6173)
This allows other things to run the logic, like a systemd unit
This commit is contained in:
parent
e2557598d7
commit
49b25396b0
3 changed files with 103 additions and 87 deletions
|
|
@ -1,6 +1,6 @@
|
|||
pkgname=msm-modem
|
||||
pkgver=7
|
||||
pkgrel=4
|
||||
pkgver=8
|
||||
pkgrel=0
|
||||
pkgdesc="Common support for Qualcomm MSM modems"
|
||||
url="https://postmarketos.org/"
|
||||
arch="armhf armv7 aarch64"
|
||||
|
|
@ -16,6 +16,7 @@ subpackages="
|
|||
|
||||
source="
|
||||
msm-modem-downstream.initd
|
||||
msm-modem-uim-selection
|
||||
msm-modem-uim-selection.confd
|
||||
msm-modem-uim-selection.initd
|
||||
udev-downstream.rules
|
||||
|
|
@ -23,7 +24,8 @@ source="
|
|||
options="!check"
|
||||
|
||||
package() {
|
||||
mkdir -p "$pkgdir"
|
||||
install -Dm755 "$srcdir"/msm-modem-uim-selection \
|
||||
-t "$pkgdir"/usr/libexec/
|
||||
}
|
||||
|
||||
uim_selection() {
|
||||
|
|
@ -67,7 +69,8 @@ openrc() {
|
|||
|
||||
sha512sums="
|
||||
3172f8c409f552f13d1da29f14ab6c79072cd6da4acab151a1a0ea1858a416974456852609f14fe29cf97a6a45e60b99d0a57ddcde751da243ee5ac6fa8b672c msm-modem-downstream.initd
|
||||
cea8a74d705a53e0f8a5d5da11f3ffc8ba25410906c4fe048617cb5a0d18b86070129d51fc7d6ec90906abe0d0e1dc2df1b19206824eb106237af2c9737544a6 msm-modem-uim-selection
|
||||
abc985c76170601a22a1d5ab0c68bdf63fa2be2796593048ea3ba0d7e5cd26b2fcee2043703e46c2910c53b01e9e8092b7a8e715d57baf243a5f4612dd595443 msm-modem-uim-selection.confd
|
||||
9c91febb48409e574695bb04c989b361db9f7678321c6935772c19efae7dd16956bd4b91143b475adf898344225d4095448b95ccb824ced305966ea96b9ae32f msm-modem-uim-selection.initd
|
||||
076d6de36527ac853674c2fc94120e711c1f77c4936977cf353a319f73beed21b9b0b81728572c8894e7dface3ecb5686535f0967de19a6bc5356d44e9ea8756 msm-modem-uim-selection.initd
|
||||
2a511c2e249d0ec5a52f04ffe1ef3d29cf3c4813143b103e54879ff89176ea45b1a5ffe21cb7dc2f1cdd84c3102ba45ef9926ed37e00b1ae12a36d01de35ea5a udev-downstream.rules
|
||||
"
|
||||
|
|
|
|||
94
modem/msm-modem/msm-modem-uim-selection
Normal file
94
modem/msm-modem/msm-modem-uim-selection
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
SIM_WAIT_TIME="${SIM_WAIT_TIME:-4}"
|
||||
QMICLI_MODEM=
|
||||
|
||||
if command -v systemd-notify > /dev/null; then
|
||||
trap '[ $? -eq 0 ] && systemd-notify --ready' EXIT
|
||||
fi
|
||||
|
||||
case "$(cat /sys/devices/soc0/machine)" in
|
||||
APQ*)
|
||||
echo 'Skipping SIM configuration on APQ SoC.'
|
||||
exit 0
|
||||
esac
|
||||
|
||||
# libqmi must be present to use this script.
|
||||
if ! [ -x "$(command -v qmicli)" ]
|
||||
then
|
||||
echo 'qmicli is not installed.'
|
||||
exit 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"
|
||||
echo "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"
|
||||
echo "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"
|
||||
echo "Using qrtr://0"
|
||||
fi
|
||||
sleep 1
|
||||
count=$((count+1))
|
||||
done
|
||||
echo "Waited $count seconds for modem device to appear"
|
||||
|
||||
if [ -z "$QMICLI_MODEM" ]
|
||||
then
|
||||
echo 'No modem available.'
|
||||
exit 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'"
|
||||
do
|
||||
if [ "$count" -ge "$SIM_WAIT_TIME" ]
|
||||
then
|
||||
echo "No sim detected after $SIM_WAIT_TIME seconds."
|
||||
exit 4
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
count=$((count+1))
|
||||
QMI_CARDS=$($QMICLI_MODEM --uim-get-card-status)
|
||||
done
|
||||
echo "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
|
||||
echo '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}')
|
||||
|
||||
echo "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
|
||||
|
||||
exit $?
|
||||
|
|
@ -12,90 +12,9 @@ depend() {
|
|||
before modemmanager
|
||||
}
|
||||
|
||||
# All of the logic is placed in the service start method as we want to block
|
||||
# Use the service start method instead of command= because we want to block
|
||||
# other services while the modem isn't ready yet.
|
||||
start() {
|
||||
case "$(cat /sys/devices/soc0/machine)" in
|
||||
APQ*)
|
||||
eend 0 'Skipping SIM configuration on APQ SoC.'
|
||||
return 0
|
||||
esac
|
||||
|
||||
# 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'"
|
||||
do
|
||||
if [ "$count" -ge "$sim_wait_time" ]
|
||||
then
|
||||
eend 4 "No sim detected after $sim_wait_time seconds."
|
||||
return 4
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
count=$((count+1))
|
||||
QMI_CARDS=$($QMICLI_MODEM --uim-get-card-status)
|
||||
done
|
||||
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
|
||||
SIM_WAIT_TIME="$sim_wait_time" /usr/libexec/msm-modem-uim-selection
|
||||
eend $?
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue