summaryrefslogtreecommitdiff
path: root/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-apn
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-apn')
-rwxr-xr-xrecipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-apn103
1 files changed, 68 insertions, 35 deletions
diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-apn b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-apn
index 535ab17..689b0a4 100755
--- a/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-apn
+++ b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-apn
@@ -1,6 +1,6 @@
#!/bin/bash
-# Copyright (C) 2014, 2017 Multi-Tech Systems
+# Copyright (C) 2014, 2017, 2019 Multi-Tech Systems
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -20,26 +20,19 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
-lna3_chat_file[0]=/etc/ppp/peers/lna3_chat_non_vz
-lna3_chat_file[1]=/etc/ppp/peers/lna3_chat_vz
-lna3_chat_link=/etc/ppp/peers/lna3_chat
+MTMODEMS=(LNA3 L4N1)
+MODEMS=(LE910-NA1 LE910C4-NF)
-function setchat {
- fw=$1
- silent=$2
- if ((${#lna3_chat_file[$fw]} == 0)) ; then
- >&2 echo "Invalid firmware SKU $fw"
+# See if string is in array of strings
+# parm 1 String
+# parm 2 Arrays of strings
+function findItem {
+ local s check="$1"
+ shift
+ for s ; do
+ [[ "$s" == "$check" ]] && return 0;
+ done
return 1
- else
- canon_src=$(readlink -f "${lna3_chat_file[$fw]}")
- canon_dest=$(readlink -f "${lna3_chat_link}")
- if [[ ${canon_src} != ${canon_dest} ]] ; then
- if ((silent == 0)) ; then
- echo "Setting chat script to ${lna3_chat_file[$fw]}"
- fi
- ln -sf "${lna3_chat_file[$fw]}" "${lna3_chat_link}"
- fi
- fi
}
function usage {
@@ -47,37 +40,77 @@ function usage {
>&2 echo "The firmware image SKU is optional."
>&2 echo "If not specified, the image SKU will be determined"
>&2 echo "from the SIM, and automatically switched with the"
- >&2 echo "APN. Current valid SKU's are 0 and 1"
- >&2 echo "Only LE910-NA1 is supported on product-ids containing string -LNA3-"
+ >&2 echo "APN. Current valid SKU's are 0, 1 and 2"
exit 1
}
+function setchat {
+ m=$1
+ m=${m,,}
+ fw=$2
+ silent=$3
+ case $fw in
+ 0)
+ ending="non_vz"
+ ;;
+ 1)
+ ending="vz"
+ ;;
+ 2)
+ # Currently L4N1 only
+ ending="non_vz"
+ ;;
+ *)
+ >&2 echo 'Invalid firmware number $fw'
+ usage
+ exit 1
+ ;;
+ esac
+ source="/etc/ppp/peers/${m}_chat_${ending}"
+ target="/etc/ppp/peers/${m}_chat"
+ canon_src=$(readlink -f "${source}")
+ canon_target=$(readlink -f "${target}")
+ if [[ ${canon_src} != ${canon_target} ]] ; then
+ if ((silent == 0)) ; then
+ echo "Setting chat script to ${source}"
+ fi
+ ln -sf "${source}" "${target}"
+ fi
+}
+
function not_ready {
>&2 echo "Radio is not ready"
>&2 echo "Try executing mlinux-switch-apn once the radio is ready"
exit 1
}
+
productid=$(/usr/sbin/mts-io-sysfs show product-id)
-if ! [[ $productid =~ -LNA3- ]] ; then
- echo "Firmware switch is supported only on LE910-NA1 models with product-id containing -LNA3-."
+if [[ $productid =~ [^-]*-([^-]*)- ]] ; then
+ mymtmodem="${BASH_REMATCH[1],,}"
+else
+ >&2 echo "Cannot find the modem in the $productid string"
+ exit 1
+fi
+
+if ! findItem "${mymtmodem^^}" "${MTMODEMS[@]}" ; then
+ echo "Firmware switch is not supported on ${mymtmodem}."
usage
exit 1
fi
if (($# > 0)) ; then
fw="$1"
- if [[ fw =~ ^[0-9]+$ ]] ; then
- if ((fw < 0)) || ((fw > 1)) ; then
+ if [[ $fw =~ ^[0-9]+$ ]] ; then
+ echo fw is $fw
+ if ((fw < 0)) || ((fw > 2)) ; then
usage
fi
else
- if ((fw > 1)) || ((fw < 0)) ; then
- >&2 echo "Invalid firmware SKU value"
- usage
- fi
+ >&2 echo "Invalid firmware SKU value"
+ usage
fi
echo "Switching chat script to firmware SKU $fw"
- setchat $fw 0
+ setchat $mymtmodem $fw 0
exit $?
else
if ! /usr/sbin/mlinux-cell-radio-ready ; then
@@ -87,23 +120,23 @@ else
fi
MODEL=$(radio-query --model)
if (($? != 0)) ; then
- >&2echo "Assume no radio on this device."
+ >&2echo "No radio on this device."
usage
exit 1
fi
- if [[ $MODEL != LE910-NA1 ]] ; then
- >&2 echo "Firmware switch is supported only on LE910-NA1 models with product-id containing -LNA3-."
+ if ! findItem $MODEL "${MODEMS[@]}" ; then
+ >&2 echo "Firmware switch is supported only on ${MODEMS[@]} and this modem is $MODEL"
usage
fi
if fwreply=$(/usr/sbin/mlinux-switch-cell-fw -1); then
if [[ $fwreply =~ Cellular[[:space:]]+radio[[:space:]]+firmware[[:space:]]+has[[:space:]]+(already[[:space:]]+)been[[:space:]]+switched[[:space:]]+to[[:space:]]+([^[:space:]]*)[[:space:]]+image\. ]] ; then
fw=${BASH_REMATCH[2]}
- setchat $fw 0
+ setchat "${mymtmodem}" $fw 0
else
fw=$(radio-query --active-firmware)
if (($? == 0)) ; then
- setchat $fw 0
+ setchat "${mymtmodem}" $fw 0
fi
fi
fi