File eg25_setup.sh of Package pinephone-helpers
#!/bin/bash
#this script is fork of the one that postmarketOS has
log() {
echo "$@" | logger -t "openSUSE:modem-setup"
}
run_AT_command() {
script -q -c "echo "$@" | timeout 1 atinout - $DEV -" $OF ;
}
get_value_AT_command() {
run_AT_command "$@" | grep $(echo "$@" | sed -e s/"AT+"// -e s/"?"// | cut -f1 -d"=") | cut -f2 -d":" | sed -e s/" "/""/ ;
}
# Current modem routing
#
# 1 - Digital PCM
# 1 - I2S slave
# 0 - Primary mode (short sync)
# 1 - 256kHz clock (256kHz / 16bit = 16k samples/s)
# 0 - 16bit linear format
# 0 - 8k sample/s
# 1 - 1 slot
# 1 - map to first slot (the only slot)
#
QDAI_CONFIG="1,1,0,1,0,0,1,1"
QCFG_RISIGNALTYPE_CONFIG="physical"
QMBNCFG_CONFIG="1"
QCFG_IMS_CONFIG="1"
if [ -z "$1" ]
then
DEV="/dev/EG25.AT"
else
DEV="$1"
fi
if [ -z "$2" ]
then
OF="/dev/null"
else
DEV="$1"
fi
# When running this script from udev the modem might not be fully initialized
# yet, so give it some time to initialize
#
# We'll try to query for the firmware version for 15 seconds after which we'll
# consider the initialization failed
log "Waiting for the modem to initialize"
INITIALIZED=false
for second in $(seq 1 60)
do
if run_AT_command "AT+QDAI?" | grep OK
then
INITIALIZED=true
break
fi
log "Waited for $second seconds..."
sleep 1
done
if $INITIALIZED
then
log "Modem initialized"
else
log "Modem failed to initialize"
exit 1
fi
# Read current config
QDAI_ACTUAL_CONFIG=$(get_value_AT_command AT+QDAI?)
QCFG_RISIGNALTYPE_ACTUAL_CONFIG=$(get_value_AT_command AT+QCFG=\'\"risignaltype\"\' | cut -f2 -d",")
QMBNCFG_ACTUAL_CONFIG=$(get_value_AT_command AT+QMBNCFG=\'\"AutoSel\"\'| cut -f2 -d",")
QCFG_IMS_ACTUAL_CONFIG=$(get_value_AT_command AT+QCFG=\'\"ims\"\' | cut -f2 -d",")
if echo $QDAI_ACTUAL_CONFIG | grep -q $QDAI_CONFIG && \
echo $QCFG_RISIGNALTYPE_ACTUAL_CONFIG | grep -q $QCFG_RISIGNALTYPE_CONFIG && \
echo $QMBNCFG_ACTUAL_CONFIG | grep -q $QMBNCFG_CONFIG && \
echo $QCFG_IMS_ACTUAL_CONFIG | grep -q $QCFG_IMS_CONFIG
then
log "Modem already configured"
exit 0
else
# Modem not configured, we need to send it the digital interface configuration,
# then reboot it
# Configure audio
RET=$(run_AT_command AT+QDAI=$QDAI_CONFIG)
if ! echo $RET | grep -q OK
then
log "Failed to configure audio: $RET"
exit 1
fi
# Configure ring device
RET=$(run_AT_command \'AT+QCFG=\"risignaltype\",\"$QCFG_RISIGNALTYPE_CONFIG\"\')
if ! echo $RET | grep -q OK
then
log "Failed to configure modem ring wakeup: $RET"
exit 1
fi
# Configure VoLTE auto selecting profile
RET=$(run_AT_command \'AT+QMBNCFG=\"AutoSel\",$QMBNCFG_CONFIG\')
if ! echo $RET | grep -q OK
then
log "Failed to enable VoLTE profile auto selecting: $RET"
exit 1
fi
# Enable VoLTE
RET=$(run_AT_command \'AT+QCFG=\"ims\",$QCFG_IMS_CONFIG\')
if ! echo $RET | grep -q OK
then
log "Failed to enable VoLTE: $RET"
exit 1
fi
# Reset module
# 1 Set the mode to full functionality (vs 4: no RF, and 1: min functionality)
# 1 Reset the modem before changing mode (only available with 1 above)
#
RET=$(run_AT_command AT+CFUN=1,1)
if ! echo $RET | grep -q OK
then
log "Failed to reset the module: $RET"
exit 1
fi
fi