From fd72c74c99849b26db9a6876ada2e6a0e80bc783 Mon Sep 17 00:00:00 2001 From: John Klug Date: Mon, 12 Aug 2019 12:13:11 -0500 Subject: Update mlinux-set-apn for new chat_wrapper script --- .../mlinux-scripts-1.2/mlinux-switch-apn | 110 +++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-apn (limited to 'recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-apn') 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 new file mode 100755 index 0000000..535ab17 --- /dev/null +++ b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-apn @@ -0,0 +1,110 @@ +#!/bin/bash + +# Copyright (C) 2014, 2017 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 +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: + +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. + +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# 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 + +function setchat { + fw=$1 + silent=$2 + if ((${#lna3_chat_file[$fw]} == 0)) ; then + >&2 echo "Invalid firmware SKU $fw" + 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 { + >&2 echo "$(basename $0) [firmware image SKU]" + >&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-" + exit 1 +} + +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-." + usage + exit 1 +fi + +if (($# > 0)) ; then + fw="$1" + if [[ fw =~ ^[0-9]+$ ]] ; then + if ((fw < 0)) || ((fw > 1)) ; then + usage + fi + else + if ((fw > 1)) || ((fw < 0)) ; then + >&2 echo "Invalid firmware SKU value" + usage + fi + fi + echo "Switching chat script to firmware SKU $fw" + setchat $fw 0 + exit $? +else + if ! /usr/sbin/mlinux-cell-radio-ready ; then + >&2 echo Radio is not ready + >&2 echo Try again later + exit 1 + fi + MODEL=$(radio-query --model) + if (($? != 0)) ; then + >&2echo "Assume 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-." + 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 + else + fw=$(radio-query --active-firmware) + if (($? == 0)) ; then + setchat $fw 0 + fi + fi + fi +fi \ No newline at end of file -- cgit v1.2.3 From bf5b19d94ea22401762a387ea5dd2e043da4e9af Mon Sep 17 00:00:00 2001 From: John Klug Date: Mon, 12 Aug 2019 14:56:39 -0500 Subject: New multiple modem switch APN code --- .../mlinux-scripts-1.2/mlinux-switch-apn | 103 ++++++++++++++------- 1 file changed, 68 insertions(+), 35 deletions(-) (limited to 'recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-apn') 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 -- cgit v1.2.3 From a4704d2afa37fe9d063a33dad83f1398cb924f40 Mon Sep 17 00:00:00 2001 From: John Klug Date: Wed, 14 Aug 2019 18:05:49 -0500 Subject: Firmware switching for L4N1 --- .../mlinux-scripts-1.2/mlinux-switch-apn | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-apn') 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 689b0a4..be056eb 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 @@ -23,6 +23,18 @@ MTMODEMS=(LNA3 L4N1) MODEMS=(LE910-NA1 LE910C4-NF) +function getactivefirmware +{ + /usr/bin/radio-query ${RADIOOPTION} --active-firmware +# FW=$(/usr/bin/radio-cmd ${RADIOOPTION} 'AT#FWSWITCH?' 2>/dev/null) +# if (($? != 0)) ; then +# >&2 echo "FW Query failed" +# return 1 +# fi +# [[ $FW =~ \#FWSWITCH:[[:space:]]*([^,]*) ]] +# echo "${BASH_REMATCH[1]}" +} + # See if string is in array of strings # parm 1 String # parm 2 Arrays of strings @@ -118,8 +130,14 @@ else >&2 echo Try again later exit 1 fi - MODEL=$(radio-query --model) - if (($? != 0)) ; then + MODEL=$(radio-query ${RADIOOPTION} --model 2>&1) + result=$? + if [[ $MODEL =~ [Ee][Rr][Rr][Oo][Rr] ]] ; then + RADIOOPTION="${RADIOOPTION2}" + MODEL=$(radio-query ${RADIOOPTION} --model 2>&1) + result=$? + fi + if ((result != 0)) ; then >&2echo "No radio on this device." usage exit 1 @@ -130,11 +148,11 @@ else 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 + 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 "${mymtmodem}" $fw 0 else - fw=$(radio-query --active-firmware) + fw=$(getactivefirmware) if (($? == 0)) ; then setchat "${mymtmodem}" $fw 0 fi -- cgit v1.2.3