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.1/mlinux-cell-radio-ready | 34 ----- .../mlinux-scripts-1.1/mlinux-cell-router | 147 ------------------ .../mlinux-scripts/mlinux-scripts-1.1/mlinux-dhcpd | 65 -------- .../mlinux-scripts-1.1/mlinux-firmware-upgrade | 69 --------- .../mlinux-scripts-1.1/mlinux-set-apn | 119 --------------- .../mlinux-scripts-1.1/mlinux-switch-apn | 110 -------------- .../mlinux-scripts-1.1/mlinux-switch-cell-fw | 149 ------------------- .../mlinux-scripts-1.1/mlinux-wifi-ap | 165 --------------------- .../mlinux-scripts-1.2/mlinux-cell-radio-ready | 34 +++++ .../mlinux-scripts-1.2/mlinux-cell-router | 147 ++++++++++++++++++ .../mlinux-scripts/mlinux-scripts-1.2/mlinux-dhcpd | 65 ++++++++ .../mlinux-scripts-1.2/mlinux-firmware-upgrade | 69 +++++++++ .../mlinux-scripts-1.2/mlinux-set-apn | 117 +++++++++++++++ .../mlinux-scripts-1.2/mlinux-switch-apn | 110 ++++++++++++++ .../mlinux-scripts-1.2/mlinux-switch-cell-fw | 149 +++++++++++++++++++ .../mlinux-scripts-1.2/mlinux-wifi-ap | 165 +++++++++++++++++++++ recipes-core/mlinux-scripts/mlinux-scripts_1.1.bb | 7 - recipes-core/mlinux-scripts/mlinux-scripts_1.2.bb | 7 + 18 files changed, 863 insertions(+), 865 deletions(-) delete mode 100644 recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-cell-radio-ready delete mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-cell-router delete mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-dhcpd delete mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-firmware-upgrade delete mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-set-apn delete mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-switch-apn delete mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-switch-cell-fw delete mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-wifi-ap create mode 100644 recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-cell-radio-ready create mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-cell-router create mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-dhcpd create mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-firmware-upgrade create mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-set-apn create mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-apn create mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-cell-fw create mode 100755 recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-wifi-ap delete mode 100644 recipes-core/mlinux-scripts/mlinux-scripts_1.1.bb create mode 100644 recipes-core/mlinux-scripts/mlinux-scripts_1.2.bb (limited to 'recipes-core/mlinux-scripts') diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-cell-radio-ready b/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-cell-radio-ready deleted file mode 100644 index 42c5cdc..0000000 --- a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-cell-radio-ready +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/sh - -# The timeout can be set in the environment or the -# first parameter. - -COUNTER=0 - -if [ $# -gt 1 ]; then - echo "usage: $0 [timeout]" - exit 1 -fi - -[ $# -eq 1 ] && TIMEOUT=$1 - -# Set the default TIMEOUT -: ${TIMEOUT:=60} - -# Wait for the radio to be ready before continuing -while [ $COUNTER -lt $TIMEOUT ]; do - TYPE=$(radio-query --type) - MODEL=$(radio-query --model) - if [ $? == 0 ]; then - echo "Cellular radio is ready." - exit 0 - fi - let COUNTER=COUNTER+1 - - echo "Waiting for radio to come up in order to identify type ..." - - sleep 1 -done - -echo "Cellular radio is not ready." -exit 1 diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-cell-router b/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-cell-router deleted file mode 100755 index 1607c32..0000000 --- a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-cell-router +++ /dev/null @@ -1,147 +0,0 @@ -#!/usr/bin/env bash - -# Copyright (C) 2014 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. - -set -e - -do_start() { - lan_interfaces=$(echo "$lan" | sed "s/,/ /g") - - echo "Configuring firewall rules..." - # Flush all the tables first - iptables -t filter -F - iptables -t nat -F - iptables -t mangle -F - - # Drop all incoming packets by default - iptables -t filter -P INPUT DROP - # Accept all on local loopback - iptables -t filter -A INPUT -i lo -j ACCEPT - # Allow packets in for existing socket connections - iptables -t filter -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT - - # Accept all from LAN interfaces - for i in $lan_interfaces; do - iptables -t filter -A INPUT -i $i -j ACCEPT - - # Accept ssh from the LAN (Wired) - #iptables -t filter -A INPUT -i $i -p tcp --dport 22 -j ACCEPT - # Accept http from the LAN (Wired) - #iptables -t filter -A INPUT -i $i -p tcp --dport 80 -j ACCEPT - # Accept tftp from the LAN (Wired) - #iptables -t filter -A INPUT -i $i -p udp --dport 69 -j ACCEPT - done - - # Accept ssh from the WAN (Wireless) - #iptables -t filter -A INPUT -i $wan -p tcp --dport 22 -j ACCEPT - # Accept http from the WAN (Wireless) - #iptables -t filter -A INPUT -i $wan -p tcp --dport 80 -j ACCEPT - - # Allow packet fowarding from LAN interfaces to WAN (cell router) - iptables -t filter -P FORWARD DROP - iptables -t filter -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT - for i in $lan_interfaces; do - iptables -t filter -A FORWARD -i $i -o $wan -j ACCEPT - done - - # Allow all output packets - iptables -t filter -P OUTPUT ACCEPT - - # enable NAT for cell router - iptables -t nat -A POSTROUTING -o $wan -j MASQUERADE - - echo "Enabling packet forwarding..." - # turn on packet forwarding last - echo 1 > /proc/sys/net/ipv4/ip_forward - echo "Done" -} - -do_stop() { - echo "Clearing firewall rules..." - # clear all tables - iptables -t filter -F - iptables -t nat -F - iptables -t mangle -F - # reset policies to ACCEPT - iptables -t filter -P INPUT ACCEPT - iptables -t filter -P OUTPUT ACCEPT - iptables -t filter -P FORWARD ACCEPT - - # turn off packet forwarding - echo "Disabling packet forwarding..." - echo 0 > /proc/sys/net/ipv4/ip_forward - echo "Done" -} - -usage() { - echo "Usage: $(basename $0) start|stop [options]" - echo " options:" - echo " -l LAN interfaces to allow, comma-separated (defaults to \"eth0\")" - echo " -w WAN interface to route out (defaults to \"ppp0\")" - exit 1 -} - -# main -if [[ $# < 1 ]]; then - usage -fi - -cmd=$1 -shift - -while getopts "l:w:h" opt; do - case "$opt" in - l) - l=$OPTARG - ;; - w) - w=$OPTARG - ;; - h) - usage - ;; - *) - usage - ;; - esac -done - -# default lan to eth0 if not specified -lan=${l-eth0} -# default wan to ppp0 if not specified -wan=${w-ppp0} - -case $cmd in - start) - echo "LAN: $lan" - echo "WAN: $wan" - do_start - ;; - stop) - do_stop - ;; - *) - usage - ;; -esac - -exit 0 - diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-dhcpd b/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-dhcpd deleted file mode 100755 index 976b138..0000000 --- a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-dhcpd +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash - -# Copyright (C) 2014 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. - -do_start() { - echo "starting dhcp daemon" - udhcpd -S /etc/udhcpd.conf -} - -do_stop() { - echo "stopping dhcp daemon" - killall udhcpd -} - -usage() { - echo "Usage: $(basename $0) start|stop|restart" - exit 1 -} - -# main -if [[ $# != 1 ]]; then - usage -fi - -case $1 in - start) - if [[ ! -f "/etc/udhcpd.conf" ]] - then - echo "/etc/udhcpd.conf does not exist" - exit 1 - fi - do_start - ;; - stop) - do_stop - ;; - restart) - do_stop - sleep 1 - do_start - ;; - *) - usage - ;; -esac - -exit 0 diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-firmware-upgrade b/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-firmware-upgrade deleted file mode 100755 index a377309..0000000 --- a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-firmware-upgrade +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/bash -dofile=/var/volatile/do_flash_upgrade - -if [ $# != 1 ]; then - echo "Usage: $0 upgrade.bin" - exit 1 -fi - -set -e -upgrade=$1 - -mkdir -p /var/volatile -cd /var/volatile - -# make sure firmware is for this device -hw_version=$(cat /sys/devices/platform/mts-io/hw-version) -firmware_model=$(tar -xO -f $upgrade model) -shopt -s nocasematch -if [[ ! "$hw_version" =~ ^$firmware_model- ]]; then - logger -s -t firmware_upgrade "Wrong firmware for this hardware" - logger -s -t firmware_upgrade "hw version: $hw_version" - logger -s -t firmware_upgrade "firmware model: $firmware_model" - exit 1 -fi - -files=(bstrap.bin uboot.bin uImage.bin config.jffs2 oem.jffs2 rootfs.jffs2 install.sh) - -tobeflashed=0 -# verify all MD5 sums -for (( i = 0; i < ${#files[@]}; i++ )); do - file=${files[i]} - # if the file is in the tar, md5sum it - if tar -t -f $upgrade | grep -F -q "$file"; then - logger -s -t firmware_upgrade "Checking MD5 for $file..." - if ! tar -x -f $upgrade $file.md5; then - logger -s -t firmware_upgrade "MD5 is not found for the $file, upgrade aborted" - exit 1 - fi - if ! tar -xO -f $upgrade $file | md5sum -c $file.md5; then - logger -s -t firmware_upgrade "MD5 check failed, upgrade aborted" - exit 1 - fi - tobeflashed=1 - fi -done - -if (( $tobeflashed )); then - mkdir -p /var/volatile/flash-upgrade - mv -f $upgrade /var/volatile/flash-upgrade/upgrade.bin - touch "${dofile}" - chown "root:root" "${dofile}" || true - uid=$(stat -c %u "${dofile}") || true - result=$? - if ((result != 0)) ; then - logger -s -t firmware_upgrade "Cannot create ${dofile}" - exit 1 - fi - if ((uid != 0)) ; then - logger -s -t firmware_upgrade "Cannot set ownership of ${dofile} to root" - exit 1 - fi - logger -s -t firmware_upgrade "Rebooting" - sleep 1 - reboot - exit 0 -else - logger -s -t firmware_upgrade "Nothing to be flashed!" - exit 1 -fi diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-set-apn b/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-set-apn deleted file mode 100755 index 317a3d7..0000000 --- a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-set-apn +++ /dev/null @@ -1,119 +0,0 @@ -#!/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. - -gsm_chat_file=/etc/ppp/peers/gsm_chat -lvw2_chat_file=/etc/ppp/peers/lvw2_chat -leu1_chat_file=/etc/ppp/peers/leu1_chat -lna3_chat_file=/etc/ppp/peers/lna3_chat_non_vz -lna3_chat_link=/etc/ppp/peers/lna3_chat -lna3_readme=/etc/ppp/peers/README.lna3 -lap3_chat_file=/etc/ppp/peers/lap3_chat -lsp3_chat_file=/etc/ppp/peers/lsp3_chat - -function usage { - echo "Usage: $(basename $0) [--] APN" - echo "Or $(basename $0) -c to clear the APN line" - echo "-- is requied if the APN begins with -" - exit 1 -} - - -((clear=0)) -if (($# < 1)); then - usage -fi -if [[ $1 == "--" ]] ; then - apn=$2 -elif [[ $1 == "-c" ]] ; then - clear=1 -elif [[ $1 =~ ^- ]] ; then - usage -else - apn=$1 -fi - -radioproduct=$(/usr/sbin/mts-io-sysfs show product-id) # LNA3? - -if (($? != 0)) ; then - echo "Radio is not ready or not found and cannot determine the type" - exit 1 -fi - -# Disable the LNA3 chat script -if ! [[ -L $lna3_chat_link ]] || [[ $(basename $(readlink -f $lna3_chat_link)) != README.lna3 ]] ; then - ln -sf "${lna3_readme}" "${lna3_chat_link}" - echo Disabling LNA3 chat script. -fi - -if ((clear != 1)) ; then - if sed -r -i "s/^(#comment by mlinux-set-apn )*OK\s+'AT\+CGDCONT=([0-9]*),\"([^\"]*)\",\"[^\"]*\"'$/OK 'AT\+CGDCONT=\2,\"\3\",\"${apn}\"'/" $gsm_chat_file ; then - echo "Set APN to \"${apn}\" in $gsm_chat_file" - else - echo "Failed to set APN in $gsm_chat_file" - fi - echo "Not allowed to set APN for $lsp3_chat_file" - echo "Not allowed to set APN for $lvw2_chat_file" - # We cannot set the APN for a Verizon modem - # sed -r -i "s/^(#comment by mlinux-set-apn )*OK\s+'AT\+CGDCONT=3,\"IPV4V6\",\"[^\"]*\"'$/OK 'AT\+CGDCONT=3,\"IPV4V6\",\"${apn}\"'/" $lvw2_chat_file - if sed -r -i "s/^(#comment by mlinux-set-apn )*OK\s+'AT\+CGDCONT=([0-9]*),\"([^\"]*)\",\"[^\"]*\"'$/OK 'AT\+CGDCONT=\2,\"\3\",\"${apn}\"'/" $leu1_chat_file ; then - echo "Set APN to \"${apn}\" in $leu1_chat_file" - else - echo "Failed to set APN in $leu1_chat_file" - fi - if sed -r -i "s/^(#comment by mlinux-set-apn )*OK\s+'AT\+CGDCONT=([0-9]*),\"([^\"]*)\",\"[^\"]*\"'$/OK 'AT\+CGDCONT=\2,\"\3\",\"${apn}\"'/" $lna3_chat_file ; then - echo "Set APN to \"${apn}\" in $lna3_chat_file" - else - echo "Failed to set APN in $lna3_chat_file" - fi - if sed -r -i "s/^(#comment by mlinux-set-apn )*OK\s+'AT\+CGDCONT=([0-9]*),\"([^\"]*)\",\"[^\"]*\"'$/OK 'AT\+CGDCONT=\2,\"\3\",\"${apn}\"'/" $lap3_chat_file ; then - echo "Set APN to \"${apn}\" in $lap3_chat_file" - else - echo "Failed to set APN in $lap3_chat_file" - fi -else - if sed -r -i "s/^(OK\s+'AT\+CGDCONT=[0-9]*,\"[^\"]*\",\"[^\"]*\"'$)/#comment by mlinux-set-apn \1/" $gsm_chat_file ; then - echo "Commented out APN in $gsm_chat_file" - else - echo "Failed to comment out APN in $gsm_chat_file" - fi - # Not setting APN in lvw2 is OK, since Verizon should not have an APN in a chat file. - if sed -r -i "s/^(OK\s+'AT\+CGDCONT=[0-9]*,\"[^\"]*\",\"[^\"]*\"'$)/#comment by mlinux-set-apn \1/" $lvw2_chat_file ; then - echo "Commented out APN in $lvw2_chat_file" - fi - if sed -r -i "s/^(OK\s+'AT\+CGDCONT=[0-9]*,\"[^\"]*\",\"[^\"]*\"'$)/#comment by mlinux-set-apn \1/" $leu1_chat_file ; then - echo "Commented out APN in $leu1_chat_file" - else - echo "Failed to comment out APN in $leu1_chat_file" - fi - if sed -r -i "s/^(OK\s+'AT\+CGDCONT=[0-9]*,\"[^\"]*\",\"[^\"]*\"'$)/#comment by mlinux-set-apn \1/" $lna3_chat_file ; then - echo "Commented out APN in $lna3_chat_file" - else - echo "Failed to comment out APN in $lna3_chat_file" - fi - if sed -r -i "s/^(OK\s+'AT\+CGDCONT=[0-9]*,\"[^\"]*\",\"[^\"]*\"'$)/#comment by mlinux-set-apn \1/" $lap3_chat_file ; then - echo "Commented out APN in $lap3_chat_file" - else - echo "Failed to comment out APN in $lap3_chat_file" - fi -fi - -exit 0 diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-switch-apn b/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-switch-apn deleted file mode 100755 index 535ab17..0000000 --- a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-switch-apn +++ /dev/null @@ -1,110 +0,0 @@ -#!/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 diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-switch-cell-fw b/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-switch-cell-fw deleted file mode 100755 index 9edacac..0000000 --- a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-switch-cell-fw +++ /dev/null @@ -1,149 +0,0 @@ -#!/bin/bash -lna3_chat_link=/etc/ppp/peers/lna3_chat -lna3_readme=/etc/ppp/peers/README.lna3 -function usage { ->&2 echo "\ -Usage: $0 [timeout] - image_id <0|1|-1> : for dual FW image SKU-s, the id of the image to switch to - (LTE910-NA1 is the only supported radio for now). - -1 is based on SIM - timeout : wait time for radio to come up if set (default : 15 sec) - -" - exit 1 -} - -if [ $# -gt 2 ] ; then - usage -fi - -# -# Load args (don't wait for the radio by default) -# -FWIMAGE=$1 -if ((FWIMAGE < -2)) || ((FWIMAGE > 1)) ; then - usage -fi -if ! >&2 /usr/sbin/mlinux-cell-radio-ready ; then - [ "$VERBOSE" ] && >&2 echo Radio is not ready - [ "$VERBOSE" ] && >&2 echo Try again later - exit 1 -fi -if ((FWIMAGE == -1)) ; then - iccid=$(radio-query --iccid) - if (($? == 0)); then - if ((${#iccid} == 0)) ; then - [ "$VERBOSE" ] && >&2 echo "No carrier. Maybe no SIM?" - [ "$VERBOSE" ] && >&2 echo "ERROR: Cannot decide on firmware" - exit 1 - fi - if [[ "$iccid" =~ ^89148.* ]] ; then - ((FWIMAGE=1)) - else - ((FWIMAGE=0)) - fi - else - >&2 echo "Cannot get ICCID from SIM" - >&2 echo "Try again later" - exit 1 - fi -fi - - -TIMEOUT=${2:-15} -if [ "$VERBOSE" != "yes" ]; then - VERBOSE="" -fi - -[ "$VERBOSE" ] && >&2 echo -n "Switching the radio firmware image: " - -# -# Check if the radio present -# -MODEL=$(radio-query --model) -if [ $? -ne 0 ]; then - [ "$VERBOSE" ] && >&2 echo "Assume no radio on this device." - exit 0 -fi - -# -# Applicable for LTE910-NA1 with dual FW images only -# -productid=$(/usr/sbin/mts-io-sysfs show product-id) -if [[ $MODEL != LE910-NA1 ]] || ! [[ $productid =~ -LNA3- ]] ; then - [ "$VERBOSE" ] && >&2 echo "Firmware switch is supported only on LE910-NA1 models with product-id containing -LNA3-." - exit 0 -fi - -# -# Check if firmware switch is required -# -FWACTIVE=$(radio-query --active-firmware) -if [ $? -ne 0 ] || [ "$FWACTIVE" == "" ]; then - [ "$VERBOSE" ] && >&2 echo "The $MODEL radio does not support firmware switching." - exit 0 -fi - -if (( FWACTIVE == FWIMAGE )); then - echo "Cellular radio firmware has already been switched to $FWIMAGE image." - exit 0 -fi - -# Disable the LNA3 chat script in case of failure. -if ! [[ -L $lna3_chat_link ]] || [[ $(basename $(readlink -f $lna3_chat_link)) != README.lna3 ]] ; then - ln -sf "${lna3_readme}" "${lna3_chat_link}" - echo "Chat script is now disabled." -fi - -# -# Switch the firmware -# -RESULT=$(radio-cmd --set-active-firmware "$FWIMAGE") -if [ $? -ne 0 ]; then - [ "$VERBOSE" ] && >&2 echo "$RESULT" - exit 1 -fi - - -# -# Exit if no TIMEOUT set -# -# This is somewhat dangerous in that we assume the radio -# will switch. -if ((TIMEOUT == 0)) ; then - if ((FWIMAGE == 0)) ; then - [ "$VERBOSE" ] && >&2 echo "Use mlinux-switch-apn to switch the APN when the radio is ready, before dialing" - exit 0 - fi -fi -# -# -# Wait for the radio to be ready before continuing -# -COUNTER=0 - -[ "$VERBOSE" ] && echo -n "Wait..." - -# -# Give it some time -# -sleep 5 - -while [ $COUNTER -lt $TIMEOUT ]; do - MODEL=$(radio-query --model) - if [ $? -eq 0 ]; then - echo "Cellular radio firmware has been switched to $FWIMAGE image." - exit 0 - fi - - let COUNTER=COUNTER+1 - - [ "$VERBOSE" ] && echo -n "." - - sleep 1 -done - ->&2 echo "Cellular radio is not ready." ->&2 echo "When it becomes ready, invoke /usr/sbin/mlinux-switch-apn" ->&2 echo "to set the APN" -exit 1 diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-wifi-ap b/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-wifi-ap deleted file mode 100755 index ddbec95..0000000 --- a/recipes-core/mlinux-scripts/mlinux-scripts-1.1/mlinux-wifi-ap +++ /dev/null @@ -1,165 +0,0 @@ -#!/bin/bash - -# Copyright (C) 2014 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. - -dhcpd_file=/etc/udhcpd.conf -hostapd_file=/etc/hostapd.conf -interface=wlan0 -bridge_mode=0 - -do_start() { - if [ "$bridge_mode" = 1 ]; then - interface=$b - if ! grep -E -q "^bridge=$interface\s*$" $hostapd_file; then - echo "Enabling bridge=br0 in $hostapd_file" - sed -r -i "s/^#?bridge=.*$/bridge=$interface/" $hostapd_file - fi - else - if grep -E -q "^bridge=.*$" $hostapd_file; then - echo "Disabling bridge in $hostapd_file" - sed -r -i "s/^bridge=/#bridge=/" $hostapd_file - fi - fi - - echo "Starting hostap daemon" - /etc/init.d/hostapd start - - if [ "$bridge_mode" != 1 ]; then - echo "Setting IP address to $ip" - ifconfig $interface $ip - # strip off end of IP address to get subnet - # assumes subnet of /24 - subnet=${ip%.*} - # escape periods for regex - subnet_regex=${subnet//./\\.} - ip_regex=${ip//./\\.} - # set default address range for dhcpd - addr_start=100 - addr_end=254 - if ! grep -E -q "^start\s+$subnet_regex\." $dhcpd_file; then - echo "Changing dhcpd start to $subnet.$addr_start" - sed -r -i "s/^start\s+.*$/start $subnet.$addr_start/" $dhcpd_file - fi - if ! grep -E -q "^end\s+$subnet_regex\." $dhcpd_file; then - echo "Changing dhcpd end to $subnet.$addr_end" - sed -r -i "s/^end\s+.*$/end $subnet.$addr_end/" $dhcpd_file - fi - # update dhcpd addresses if needed - if ! grep -E -q "^option\s+router\s+$ip_regex" $dhcpd_file; then - echo "Changing dhcpd router to $ip" - sed -r -i "s/^option\s+router\s+.*$/option router $ip/" $dhcpd_file - fi - else - # unset ip address for bridge mode - ifconfig wlan0 0.0.0.0 - fi - - if ! grep -E -q "^interface\s+$interface" $dhcpd_file; then - echo "Changing dhcpd interface to $interface" - sed -r -i "s/^interface\s+.*$/interface $interface/" $dhcpd_file - fi - mlinux-dhcpd start -} - -do_stop() { - echo "Stopping hostap daemon" - /etc/init.d/hostapd stop - mlinux-dhcpd stop -} - -usage() { - echo "Usage: $(basename $0) start|stop|restart [options]" - echo " options:" - echo " -a
Sets AP IP address (defaults to 192.168.3.1)" - echo " -b Add AP to specified bridge interface (conflicts with -a)" - exit 1 -} - -# main -if [[ $# < 1 ]]; then - usage -fi - -cmd=$1 -shift - -while getopts "a:b:h" opt; do - case "$opt" in - a) - a=$OPTARG - ;; - b) - b=$OPTARG - bridge_mode=1 - ;; - h) - usage - ;; - *) - usage - ;; - esac -done - -# can't specify both address and bridge mode -if [ -n "$a" ] && [ -n "$b" ]; then - usage -fi - -if [ -n "$a" ]; then - ret=1 - if [[ $a =~ ^([0-9]{1,3}\.){3,3}[0-9]{1,3}$ ]] - then - OIFS=$IFS - IFS='.' - ip=($a) - IFS=$OFIS - [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] - ret=$? - fi - if [[ ret -ne 0 ]] - then - echo "invalid IP address" - exit 1 - fi - ip=$a -else - ip="192.168.3.1" -fi - -case $cmd in - start) - do_start - ;; - stop) - do_stop - ;; - restart) - do_stop - sleep 1 - do_start - ;; - *) - usage - ;; -esac - -exit 0 diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-cell-radio-ready b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-cell-radio-ready new file mode 100644 index 0000000..42c5cdc --- /dev/null +++ b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-cell-radio-ready @@ -0,0 +1,34 @@ +#!/bin/sh + +# The timeout can be set in the environment or the +# first parameter. + +COUNTER=0 + +if [ $# -gt 1 ]; then + echo "usage: $0 [timeout]" + exit 1 +fi + +[ $# -eq 1 ] && TIMEOUT=$1 + +# Set the default TIMEOUT +: ${TIMEOUT:=60} + +# Wait for the radio to be ready before continuing +while [ $COUNTER -lt $TIMEOUT ]; do + TYPE=$(radio-query --type) + MODEL=$(radio-query --model) + if [ $? == 0 ]; then + echo "Cellular radio is ready." + exit 0 + fi + let COUNTER=COUNTER+1 + + echo "Waiting for radio to come up in order to identify type ..." + + sleep 1 +done + +echo "Cellular radio is not ready." +exit 1 diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-cell-router b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-cell-router new file mode 100755 index 0000000..1607c32 --- /dev/null +++ b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-cell-router @@ -0,0 +1,147 @@ +#!/usr/bin/env bash + +# Copyright (C) 2014 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. + +set -e + +do_start() { + lan_interfaces=$(echo "$lan" | sed "s/,/ /g") + + echo "Configuring firewall rules..." + # Flush all the tables first + iptables -t filter -F + iptables -t nat -F + iptables -t mangle -F + + # Drop all incoming packets by default + iptables -t filter -P INPUT DROP + # Accept all on local loopback + iptables -t filter -A INPUT -i lo -j ACCEPT + # Allow packets in for existing socket connections + iptables -t filter -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT + + # Accept all from LAN interfaces + for i in $lan_interfaces; do + iptables -t filter -A INPUT -i $i -j ACCEPT + + # Accept ssh from the LAN (Wired) + #iptables -t filter -A INPUT -i $i -p tcp --dport 22 -j ACCEPT + # Accept http from the LAN (Wired) + #iptables -t filter -A INPUT -i $i -p tcp --dport 80 -j ACCEPT + # Accept tftp from the LAN (Wired) + #iptables -t filter -A INPUT -i $i -p udp --dport 69 -j ACCEPT + done + + # Accept ssh from the WAN (Wireless) + #iptables -t filter -A INPUT -i $wan -p tcp --dport 22 -j ACCEPT + # Accept http from the WAN (Wireless) + #iptables -t filter -A INPUT -i $wan -p tcp --dport 80 -j ACCEPT + + # Allow packet fowarding from LAN interfaces to WAN (cell router) + iptables -t filter -P FORWARD DROP + iptables -t filter -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT + for i in $lan_interfaces; do + iptables -t filter -A FORWARD -i $i -o $wan -j ACCEPT + done + + # Allow all output packets + iptables -t filter -P OUTPUT ACCEPT + + # enable NAT for cell router + iptables -t nat -A POSTROUTING -o $wan -j MASQUERADE + + echo "Enabling packet forwarding..." + # turn on packet forwarding last + echo 1 > /proc/sys/net/ipv4/ip_forward + echo "Done" +} + +do_stop() { + echo "Clearing firewall rules..." + # clear all tables + iptables -t filter -F + iptables -t nat -F + iptables -t mangle -F + # reset policies to ACCEPT + iptables -t filter -P INPUT ACCEPT + iptables -t filter -P OUTPUT ACCEPT + iptables -t filter -P FORWARD ACCEPT + + # turn off packet forwarding + echo "Disabling packet forwarding..." + echo 0 > /proc/sys/net/ipv4/ip_forward + echo "Done" +} + +usage() { + echo "Usage: $(basename $0) start|stop [options]" + echo " options:" + echo " -l LAN interfaces to allow, comma-separated (defaults to \"eth0\")" + echo " -w WAN interface to route out (defaults to \"ppp0\")" + exit 1 +} + +# main +if [[ $# < 1 ]]; then + usage +fi + +cmd=$1 +shift + +while getopts "l:w:h" opt; do + case "$opt" in + l) + l=$OPTARG + ;; + w) + w=$OPTARG + ;; + h) + usage + ;; + *) + usage + ;; + esac +done + +# default lan to eth0 if not specified +lan=${l-eth0} +# default wan to ppp0 if not specified +wan=${w-ppp0} + +case $cmd in + start) + echo "LAN: $lan" + echo "WAN: $wan" + do_start + ;; + stop) + do_stop + ;; + *) + usage + ;; +esac + +exit 0 + diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-dhcpd b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-dhcpd new file mode 100755 index 0000000..976b138 --- /dev/null +++ b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-dhcpd @@ -0,0 +1,65 @@ +#!/bin/bash + +# Copyright (C) 2014 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. + +do_start() { + echo "starting dhcp daemon" + udhcpd -S /etc/udhcpd.conf +} + +do_stop() { + echo "stopping dhcp daemon" + killall udhcpd +} + +usage() { + echo "Usage: $(basename $0) start|stop|restart" + exit 1 +} + +# main +if [[ $# != 1 ]]; then + usage +fi + +case $1 in + start) + if [[ ! -f "/etc/udhcpd.conf" ]] + then + echo "/etc/udhcpd.conf does not exist" + exit 1 + fi + do_start + ;; + stop) + do_stop + ;; + restart) + do_stop + sleep 1 + do_start + ;; + *) + usage + ;; +esac + +exit 0 diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-firmware-upgrade b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-firmware-upgrade new file mode 100755 index 0000000..a377309 --- /dev/null +++ b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-firmware-upgrade @@ -0,0 +1,69 @@ +#!/bin/bash +dofile=/var/volatile/do_flash_upgrade + +if [ $# != 1 ]; then + echo "Usage: $0 upgrade.bin" + exit 1 +fi + +set -e +upgrade=$1 + +mkdir -p /var/volatile +cd /var/volatile + +# make sure firmware is for this device +hw_version=$(cat /sys/devices/platform/mts-io/hw-version) +firmware_model=$(tar -xO -f $upgrade model) +shopt -s nocasematch +if [[ ! "$hw_version" =~ ^$firmware_model- ]]; then + logger -s -t firmware_upgrade "Wrong firmware for this hardware" + logger -s -t firmware_upgrade "hw version: $hw_version" + logger -s -t firmware_upgrade "firmware model: $firmware_model" + exit 1 +fi + +files=(bstrap.bin uboot.bin uImage.bin config.jffs2 oem.jffs2 rootfs.jffs2 install.sh) + +tobeflashed=0 +# verify all MD5 sums +for (( i = 0; i < ${#files[@]}; i++ )); do + file=${files[i]} + # if the file is in the tar, md5sum it + if tar -t -f $upgrade | grep -F -q "$file"; then + logger -s -t firmware_upgrade "Checking MD5 for $file..." + if ! tar -x -f $upgrade $file.md5; then + logger -s -t firmware_upgrade "MD5 is not found for the $file, upgrade aborted" + exit 1 + fi + if ! tar -xO -f $upgrade $file | md5sum -c $file.md5; then + logger -s -t firmware_upgrade "MD5 check failed, upgrade aborted" + exit 1 + fi + tobeflashed=1 + fi +done + +if (( $tobeflashed )); then + mkdir -p /var/volatile/flash-upgrade + mv -f $upgrade /var/volatile/flash-upgrade/upgrade.bin + touch "${dofile}" + chown "root:root" "${dofile}" || true + uid=$(stat -c %u "${dofile}") || true + result=$? + if ((result != 0)) ; then + logger -s -t firmware_upgrade "Cannot create ${dofile}" + exit 1 + fi + if ((uid != 0)) ; then + logger -s -t firmware_upgrade "Cannot set ownership of ${dofile} to root" + exit 1 + fi + logger -s -t firmware_upgrade "Rebooting" + sleep 1 + reboot + exit 0 +else + logger -s -t firmware_upgrade "Nothing to be flashed!" + exit 1 +fi diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-set-apn b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-set-apn new file mode 100755 index 0000000..ebe8096 --- /dev/null +++ b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-set-apn @@ -0,0 +1,117 @@ +#!/bin/bash + +# 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 +# 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. + +noapn_modems=(lvw2 lsp3 cdma) + +# Comment out AT+CGDCONT= statement +remove_apn_sedcmd="s/^(OK[[:space:]]+'|#MT[[:space:]]+)(AT\+CGDCONT=[0-9]+[^\']*)'*/#comment by mlinux-set-apn \2/" + + + +function usage { + echo "Usage: $(basename $0) [--] APN" + echo "Or $(basename $0) -c to clear the APN line" + echo "-- is requied if the APN begins with -" + exit 1 +} + + +((clear=0)) +if (($# < 1)); then + usage +fi +if [[ $1 == "--" ]] ; then + apn=$2 +elif [[ $1 == "-c" ]] ; then + clear=1 +elif [[ $1 =~ ^- ]] ; then + usage +else + apn=$1 +fi + + +set_apn_sedcmd="s/^(#comment by mlinux-set-apn )*(OK[[:space:]]+'|#MT[[:space:]]+)*AT\+CGDCONT=([0-9]+),\"([^\"]*)\",\"[^\"]*\".*/#MT AT\+CGDCONT=\3,\"\4\",\"${apn}\"/" + + + +getmodem() +{ + radioproduct=$(/usr/sbin/mts-io-sysfs show product-id) # LNA3? + if (($? != 0)) ; then + echo "Radio is not ready or not found and cannot determine the type" + exit 1 + fi + if [[ $radioproduct =~ [^-]*-([^-]*)- ]] ; then + echo "${BASH_REMATCH[1]}" + fi +} +function findItem +{ + local s check="$1" + shift + for s ; do [[ "$s" == "$check" ]] && return 0; done + return 1 +} + + +cd /var/config/ppp/peers +if ((clear != 1)) ; then + for f in $noapn ; do + echo "Not allowed to set APN for $f" + done + + for f in *_chat *_chat_non_vz ; do + if [[ -L $f ]] ; then + continue + fi + [[ $f =~ ([^_]*) ]] + m=${BASH_REMATCH[1]} + if findItem "$m" "${noapn_modems[@]}" ; then + continue + fi + + if sed -r -i "${set_apn_sedcmd}" ${f}; then + echo "Set APN to \"${apn}\" in ${f}" + if ! grep -q /usr/libexec/ppp/chat_wrapper ${m} ; then + sed -i "s?connect '/usr/sbin/chat?connect '/usr/libexec/ppp/chat_wrapper /usr/sbin/chat?" ${m} + fi + else + echo "Failed to set APN in $f_chat" + fi + done +else + for f in *_chat *_chat_non_vz ; do + if sed -i -r "${remove_apn_sedcmd}" $f ; then + echo "Commented out APN in $f" + else + if [[ $f =~ ([^_]*) ]] ; then + m=${BASH_REMATCH[1]} + if ! findItem "$m" "${noapn_modems[@]}" ; then + echo "Failed to remove APN setting in $f" + fi + fi + fi + done +fi + +exit 0 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 diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-cell-fw b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-cell-fw new file mode 100755 index 0000000..9edacac --- /dev/null +++ b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-cell-fw @@ -0,0 +1,149 @@ +#!/bin/bash +lna3_chat_link=/etc/ppp/peers/lna3_chat +lna3_readme=/etc/ppp/peers/README.lna3 +function usage { +>&2 echo "\ +Usage: $0 [timeout] + image_id <0|1|-1> : for dual FW image SKU-s, the id of the image to switch to + (LTE910-NA1 is the only supported radio for now). + -1 is based on SIM + timeout : wait time for radio to come up if set (default : 15 sec) + +" + exit 1 +} + +if [ $# -gt 2 ] ; then + usage +fi + +# +# Load args (don't wait for the radio by default) +# +FWIMAGE=$1 +if ((FWIMAGE < -2)) || ((FWIMAGE > 1)) ; then + usage +fi +if ! >&2 /usr/sbin/mlinux-cell-radio-ready ; then + [ "$VERBOSE" ] && >&2 echo Radio is not ready + [ "$VERBOSE" ] && >&2 echo Try again later + exit 1 +fi +if ((FWIMAGE == -1)) ; then + iccid=$(radio-query --iccid) + if (($? == 0)); then + if ((${#iccid} == 0)) ; then + [ "$VERBOSE" ] && >&2 echo "No carrier. Maybe no SIM?" + [ "$VERBOSE" ] && >&2 echo "ERROR: Cannot decide on firmware" + exit 1 + fi + if [[ "$iccid" =~ ^89148.* ]] ; then + ((FWIMAGE=1)) + else + ((FWIMAGE=0)) + fi + else + >&2 echo "Cannot get ICCID from SIM" + >&2 echo "Try again later" + exit 1 + fi +fi + + +TIMEOUT=${2:-15} +if [ "$VERBOSE" != "yes" ]; then + VERBOSE="" +fi + +[ "$VERBOSE" ] && >&2 echo -n "Switching the radio firmware image: " + +# +# Check if the radio present +# +MODEL=$(radio-query --model) +if [ $? -ne 0 ]; then + [ "$VERBOSE" ] && >&2 echo "Assume no radio on this device." + exit 0 +fi + +# +# Applicable for LTE910-NA1 with dual FW images only +# +productid=$(/usr/sbin/mts-io-sysfs show product-id) +if [[ $MODEL != LE910-NA1 ]] || ! [[ $productid =~ -LNA3- ]] ; then + [ "$VERBOSE" ] && >&2 echo "Firmware switch is supported only on LE910-NA1 models with product-id containing -LNA3-." + exit 0 +fi + +# +# Check if firmware switch is required +# +FWACTIVE=$(radio-query --active-firmware) +if [ $? -ne 0 ] || [ "$FWACTIVE" == "" ]; then + [ "$VERBOSE" ] && >&2 echo "The $MODEL radio does not support firmware switching." + exit 0 +fi + +if (( FWACTIVE == FWIMAGE )); then + echo "Cellular radio firmware has already been switched to $FWIMAGE image." + exit 0 +fi + +# Disable the LNA3 chat script in case of failure. +if ! [[ -L $lna3_chat_link ]] || [[ $(basename $(readlink -f $lna3_chat_link)) != README.lna3 ]] ; then + ln -sf "${lna3_readme}" "${lna3_chat_link}" + echo "Chat script is now disabled." +fi + +# +# Switch the firmware +# +RESULT=$(radio-cmd --set-active-firmware "$FWIMAGE") +if [ $? -ne 0 ]; then + [ "$VERBOSE" ] && >&2 echo "$RESULT" + exit 1 +fi + + +# +# Exit if no TIMEOUT set +# +# This is somewhat dangerous in that we assume the radio +# will switch. +if ((TIMEOUT == 0)) ; then + if ((FWIMAGE == 0)) ; then + [ "$VERBOSE" ] && >&2 echo "Use mlinux-switch-apn to switch the APN when the radio is ready, before dialing" + exit 0 + fi +fi +# +# +# Wait for the radio to be ready before continuing +# +COUNTER=0 + +[ "$VERBOSE" ] && echo -n "Wait..." + +# +# Give it some time +# +sleep 5 + +while [ $COUNTER -lt $TIMEOUT ]; do + MODEL=$(radio-query --model) + if [ $? -eq 0 ]; then + echo "Cellular radio firmware has been switched to $FWIMAGE image." + exit 0 + fi + + let COUNTER=COUNTER+1 + + [ "$VERBOSE" ] && echo -n "." + + sleep 1 +done + +>&2 echo "Cellular radio is not ready." +>&2 echo "When it becomes ready, invoke /usr/sbin/mlinux-switch-apn" +>&2 echo "to set the APN" +exit 1 diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-wifi-ap b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-wifi-ap new file mode 100755 index 0000000..ddbec95 --- /dev/null +++ b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-wifi-ap @@ -0,0 +1,165 @@ +#!/bin/bash + +# Copyright (C) 2014 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. + +dhcpd_file=/etc/udhcpd.conf +hostapd_file=/etc/hostapd.conf +interface=wlan0 +bridge_mode=0 + +do_start() { + if [ "$bridge_mode" = 1 ]; then + interface=$b + if ! grep -E -q "^bridge=$interface\s*$" $hostapd_file; then + echo "Enabling bridge=br0 in $hostapd_file" + sed -r -i "s/^#?bridge=.*$/bridge=$interface/" $hostapd_file + fi + else + if grep -E -q "^bridge=.*$" $hostapd_file; then + echo "Disabling bridge in $hostapd_file" + sed -r -i "s/^bridge=/#bridge=/" $hostapd_file + fi + fi + + echo "Starting hostap daemon" + /etc/init.d/hostapd start + + if [ "$bridge_mode" != 1 ]; then + echo "Setting IP address to $ip" + ifconfig $interface $ip + # strip off end of IP address to get subnet + # assumes subnet of /24 + subnet=${ip%.*} + # escape periods for regex + subnet_regex=${subnet//./\\.} + ip_regex=${ip//./\\.} + # set default address range for dhcpd + addr_start=100 + addr_end=254 + if ! grep -E -q "^start\s+$subnet_regex\." $dhcpd_file; then + echo "Changing dhcpd start to $subnet.$addr_start" + sed -r -i "s/^start\s+.*$/start $subnet.$addr_start/" $dhcpd_file + fi + if ! grep -E -q "^end\s+$subnet_regex\." $dhcpd_file; then + echo "Changing dhcpd end to $subnet.$addr_end" + sed -r -i "s/^end\s+.*$/end $subnet.$addr_end/" $dhcpd_file + fi + # update dhcpd addresses if needed + if ! grep -E -q "^option\s+router\s+$ip_regex" $dhcpd_file; then + echo "Changing dhcpd router to $ip" + sed -r -i "s/^option\s+router\s+.*$/option router $ip/" $dhcpd_file + fi + else + # unset ip address for bridge mode + ifconfig wlan0 0.0.0.0 + fi + + if ! grep -E -q "^interface\s+$interface" $dhcpd_file; then + echo "Changing dhcpd interface to $interface" + sed -r -i "s/^interface\s+.*$/interface $interface/" $dhcpd_file + fi + mlinux-dhcpd start +} + +do_stop() { + echo "Stopping hostap daemon" + /etc/init.d/hostapd stop + mlinux-dhcpd stop +} + +usage() { + echo "Usage: $(basename $0) start|stop|restart [options]" + echo " options:" + echo " -a
Sets AP IP address (defaults to 192.168.3.1)" + echo " -b Add AP to specified bridge interface (conflicts with -a)" + exit 1 +} + +# main +if [[ $# < 1 ]]; then + usage +fi + +cmd=$1 +shift + +while getopts "a:b:h" opt; do + case "$opt" in + a) + a=$OPTARG + ;; + b) + b=$OPTARG + bridge_mode=1 + ;; + h) + usage + ;; + *) + usage + ;; + esac +done + +# can't specify both address and bridge mode +if [ -n "$a" ] && [ -n "$b" ]; then + usage +fi + +if [ -n "$a" ]; then + ret=1 + if [[ $a =~ ^([0-9]{1,3}\.){3,3}[0-9]{1,3}$ ]] + then + OIFS=$IFS + IFS='.' + ip=($a) + IFS=$OFIS + [[ ${ip[0]} -le 255 && ${ip[1]} -le 255 && ${ip[2]} -le 255 && ${ip[3]} -le 255 ]] + ret=$? + fi + if [[ ret -ne 0 ]] + then + echo "invalid IP address" + exit 1 + fi + ip=$a +else + ip="192.168.3.1" +fi + +case $cmd in + start) + do_start + ;; + stop) + do_stop + ;; + restart) + do_stop + sleep 1 + do_start + ;; + *) + usage + ;; +esac + +exit 0 diff --git a/recipes-core/mlinux-scripts/mlinux-scripts_1.1.bb b/recipes-core/mlinux-scripts/mlinux-scripts_1.1.bb deleted file mode 100644 index 0dfd740..0000000 --- a/recipes-core/mlinux-scripts/mlinux-scripts_1.1.bb +++ /dev/null @@ -1,7 +0,0 @@ -DESCRIPTION = "Scripts to easily get started with common mLinux use cases" - -require mlinux-scripts.inc - -PR = "r5" - -S = "${WORKDIR}/mlinux-scripts-${PV}" diff --git a/recipes-core/mlinux-scripts/mlinux-scripts_1.2.bb b/recipes-core/mlinux-scripts/mlinux-scripts_1.2.bb new file mode 100644 index 0000000..05c1b84 --- /dev/null +++ b/recipes-core/mlinux-scripts/mlinux-scripts_1.2.bb @@ -0,0 +1,7 @@ +DESCRIPTION = "Scripts to easily get started with common mLinux use cases" + +require mlinux-scripts.inc + +PR = "r1" + +S = "${WORKDIR}/mlinux-scripts-${PV}" -- 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') 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 ++++- .../mlinux-scripts-1.2/mlinux-switch-cell-fw | 128 +++++++++++++++------ 2 files changed, 117 insertions(+), 37 deletions(-) (limited to 'recipes-core/mlinux-scripts') 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 diff --git a/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-cell-fw b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-cell-fw index 9edacac..4065ccb 100755 --- a/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-cell-fw +++ b/recipes-core/mlinux-scripts/mlinux-scripts-1.2/mlinux-switch-cell-fw @@ -1,11 +1,53 @@ #!/bin/bash -lna3_chat_link=/etc/ppp/peers/lna3_chat -lna3_readme=/etc/ppp/peers/README.lna3 +# This script assumes Verizon SIMS ICCID start with 89148 and is firmware 1. +# This script assumes T-Mobile SIMS start with 8901260 and is firmware 2. + +fwsw_modems=(LE910-NA1 LE910C4-NF) +mt_modems=(lna3 l4n1) +readme=/etc/ppp/peers/README.fwswitch +function setactivefirmware +{ + radio-cmd ${RADIOOPTION} --set-active-firmware $1 +# RESULT=$(radio-cmd ${RADIOOPTION} 'AT#FWSWITCH='$1',1' 2>&1) +# if (($? != 0)) ; then +# >&2 echo "FW Set failed" +# return 1 +# fi +# if [[ $RESULT =~ [Ee][Rr][Rr][Oo][Rr] ]] ; then +# >&2 echo "FW Set failed" +# return 1 +# fi +} + +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 +function findItem { + local s check="$1" + shift + for s ; do + [[ "$s" == "$check" ]] && return 0; + done + return 1 +} + + function usage { ->&2 echo "\ +>&2 echo " Usage: $0 [timeout] - image_id <0|1|-1> : for dual FW image SKU-s, the id of the image to switch to - (LTE910-NA1 is the only supported radio for now). + image_id <0|1|2|-1> : for dual FW image SKU-s, the id of the image to switch to -1 is based on SIM timeout : wait time for radio to come up if set (default : 15 sec) @@ -17,11 +59,27 @@ if [ $# -gt 2 ] ; then usage fi +# +# Check if the radio present +# +MODEL=$(radio-query ${RADIOOPTION} --model 2>&1) +result=$? +if [[ $MCONTEXT =~ [Ee][Rr][Rr][Oo][Rr] ]] ; then + RADIOOPTION="${RADIOOPTION2}" + MODEL=$(radio-query ${RADIOOPTION} --model 2>&1) + result=$? +fi + +if ((result != 0)) ; then + [ "$VERBOSE" ] && >&2 echo "Assume no radio on this device." + exit 0 +fi + # # Load args (don't wait for the radio by default) # FWIMAGE=$1 -if ((FWIMAGE < -2)) || ((FWIMAGE > 1)) ; then +if ((FWIMAGE < -2)) || ((FWIMAGE > 2)) ; then usage fi if ! >&2 /usr/sbin/mlinux-cell-radio-ready ; then @@ -30,16 +88,27 @@ if ! >&2 /usr/sbin/mlinux-cell-radio-ready ; then exit 1 fi if ((FWIMAGE == -1)) ; then - iccid=$(radio-query --iccid) + iccid=$(radio-query ${RADIOOPTION} --iccid) if (($? == 0)); then if ((${#iccid} == 0)) ; then [ "$VERBOSE" ] && >&2 echo "No carrier. Maybe no SIM?" [ "$VERBOSE" ] && >&2 echo "ERROR: Cannot decide on firmware" exit 1 fi - if [[ "$iccid" =~ ^89148.* ]] ; then + if [[ $iccid =~ ^89148.* ]] ; then + # Verizon + logger -s -t mlinux-sw-firmware -p daemon.info "Assuming $iccid is a Verizon SIM ICCID using Firmware 1" ((FWIMAGE=1)) + elif [[ $iccid =~ ^8901260.* ]] ; then + # T-Mobile + logger -s -t mlinux-sw-firmware -p daemon.info "Assuming $iccid is a T-Mobile SIM ICCID using Firmware 2" + ((FWMAGE=2)) + if [[ $MODEL == LE910-NA1 ]] ; then # Assume LNA3 has no firmware image 2 + ((FWIMAGE=0)) + fi else + # Everybody else + logger -s -t mlinux-sw-firmware -p daemon.info "Assuming $iccid is a possibly AT&T SIM using Firmware 0" ((FWIMAGE=0)) fi else @@ -58,47 +127,40 @@ fi [ "$VERBOSE" ] && >&2 echo -n "Switching the radio firmware image: " # -# Check if the radio present +# Applicable for LTE910-NA1 and LE910C4-NF with dual FW images only # -MODEL=$(radio-query --model) -if [ $? -ne 0 ]; then - [ "$VERBOSE" ] && >&2 echo "Assume no radio on this device." - exit 0 -fi - -# -# Applicable for LTE910-NA1 with dual FW images only -# -productid=$(/usr/sbin/mts-io-sysfs show product-id) -if [[ $MODEL != LE910-NA1 ]] || ! [[ $productid =~ -LNA3- ]] ; then - [ "$VERBOSE" ] && >&2 echo "Firmware switch is supported only on LE910-NA1 models with product-id containing -LNA3-." - exit 0 +if ! findItem "$MODEL" "${fwsw_modems[@]}" ; then + echo "Firmware switch is not supported on ${MODEL}." + exit 1 fi # # Check if firmware switch is required # -FWACTIVE=$(radio-query --active-firmware) +FWACTIVE=$(getactivefirmware) if [ $? -ne 0 ] || [ "$FWACTIVE" == "" ]; then - [ "$VERBOSE" ] && >&2 echo "The $MODEL radio does not support firmware switching." - exit 0 + [ "$VERBOSE" ] && >&2 echo "The $MODEL radio does not support firmware switching." + exit 0 fi if (( FWACTIVE == FWIMAGE )); then - echo "Cellular radio firmware has already been switched to $FWIMAGE image." - exit 0 + echo "Cellular radio firmware has already been switched to $FWIMAGE image." + exit 0 fi # Disable the LNA3 chat script in case of failure. -if ! [[ -L $lna3_chat_link ]] || [[ $(basename $(readlink -f $lna3_chat_link)) != README.lna3 ]] ; then - ln -sf "${lna3_readme}" "${lna3_chat_link}" - echo "Chat script is now disabled." -fi +for f in $mt_modems ; do + linkf=/etc/ppp/peers/${f}_chat + if ! [[ -L ${linkf} ]] || [[ $(basename $(readlink -f ${linkf})) != ${readme} ]] ; then + ln -sf "${readme}" "${linkf}" + echo "Chat script is now disabled." + fi +done # # Switch the firmware # -RESULT=$(radio-cmd --set-active-firmware "$FWIMAGE") +RESULT=$(setactivefirmware "$FWIMAGE") if [ $? -ne 0 ]; then [ "$VERBOSE" ] && >&2 echo "$RESULT" exit 1 @@ -130,7 +192,7 @@ COUNTER=0 sleep 5 while [ $COUNTER -lt $TIMEOUT ]; do - MODEL=$(radio-query --model) + MODEL=$(radio-query ${RADIOOPTION} --model) if [ $? -eq 0 ]; then echo "Cellular radio firmware has been switched to $FWIMAGE image." exit 0 -- cgit v1.2.3