#!/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 if ((silent == 0)) ; then echo "Setting chat script to ${lna3_chat_file[$fw]}" fi ln -sf "${lna3_chat_file[$fw]}" "${lna3_chat_link}" 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 [[ $fwreply =~ Cellular[[:space:]]+radio[[:space:]]+firmware[[:space:]]+has[[:space:]]+been[[:space:]]+switched[[:space:]]+to[[:space:]]+([^[:space:]]*)[[:space:]]+image\. ]] fw=${BASH_REMATCH[1]} setchat $fw 0 fi fi