| #!/bin/sh |
| |
| # Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| # This is a wrapper around a lot of different DBus calls, written in sh; this is |
| # meant to replace parts of flimflam-test, and also to be callable from crosh. |
| |
| . /usr/lib/mm.sh |
| . /usr/lib/connectivity-common.sh |
| . /usr/lib/modem-common.sh |
| |
| # Wait for a modem to reset itself and come back with a new dbus name |
| # args: |
| # $1 - dbus name of the modem before reset |
| # $2 - timeout in seconds |
| wait_for_modem_reset () { |
| local modem |
| local oldmodem=$1 |
| local timeout=$2 |
| local status="Timed out" |
| echo -n "Waiting..." |
| while test $timeout -gt 0 ; do |
| modem=$(modems | head -1) |
| if [ -n "$modem" -a "$modem" != "$oldmodem" ] ; then |
| status="Done" |
| break |
| fi |
| sleep 1 |
| timeout=$((timeout - 1)) |
| echo -n "." |
| done |
| echo $status |
| } |
| |
| # Wait for a modem to reset itself and come back with a new dbus name, |
| # or for the activation state to change from "1" |
| # MM_MODEM_ACTIVATION_STATE_ACTIVATING to something else |
| # Success is deteremined by the activation state changing or by having |
| # the newly assigned mdn. |
| # |
| # args: |
| # $1 - dbus name of the modem before activation |
| # $2 - activation state of modem before activation call |
| # $3 - timeout in seconds |
| # $4 - new mdn |
| # |
| wait_for_activation_change () { |
| local modem |
| local oldmodem=$1 |
| local oldstate=$2 |
| local timeout=$3 |
| local expected_mdn=$4 |
| local status="Timed out" |
| local activation_state |
| echo -n "Waiting..." |
| while test $timeout -gt 0 ; do |
| modem=$(modems | head -1) |
| if [ -n "$modem" -a "$modem" != "$oldmodem" ] ; then |
| status="Done" |
| break |
| fi |
| if [ -n "$modem" ] ; then |
| activation_state=$(modem_activation_state $modem) |
| if [ -n "$activation_state" ]; then |
| if [ $activation_state -gt 1 ]; then |
| status="Done" |
| break |
| fi |
| fi |
| fi |
| sleep 1 |
| timeout=$((timeout - 1)) |
| echo -n "." |
| done |
| activation_state=$(modem_activation_state $modem) |
| if [ -z "$activation_state" ] ; then |
| status="Failed" |
| elif [ $activation_state -le $oldstate ] ; then |
| status="Failed" |
| fi |
| if [ -n "$expected_mdn" ]; then |
| mdn=$(modem_status $modem mdn) |
| if [ "$expected_mdn" = "$mdn" ] ; then |
| status="Done" |
| fi |
| fi |
| echo $status |
| } |
| |
| activate_manual () { |
| $(arg_or_default modem $(modems | head -1)) |
| [ -z "$modem" ] && echo "no modem found" && exit 1 |
| args=$(echo "$@" | sed -e 's/ /,/g') |
| args=$(require "$args" min) |
| args=$(require "$args" mdn) |
| args=$(require "$args" spc) |
| args=$(require "$args" system_id) |
| local oldstate=$(modem_activation_state $modem) |
| dbus "$modem" $IMODEM_CDMA.ActivateManualDebug \ |
| "dict:string:string:$args" |
| mdn=$(echo $args | sed -e s'/.*mdn,\([^,]*\).*/\1/g') |
| wait_for_activation_change $modem $oldstate 40 $mdn |
| } |
| |
| activate () { |
| $(arg_or_default modem $(modems | head -1)) |
| [ -z "$modem" ] && echo "no modem found" && exit 1 |
| # Work around braindead crosh quoting semantics (i.e., there are none, |
| # arguments are tokenized on spaces). Sigh. |
| carrier=$(echo "$@") |
| # TODO(jglasgow): verify that we can pass an empty string |
| local oldstate=$(modem_activation_state $modem) |
| local status=$(dbus "$modem" $IMODEM_CDMA.Activate "string:$carrier") |
| if [ $status != 0 ] ; then |
| echo "Error $status while activating" |
| else |
| wait_for_activation_change $modem $oldstate 40 |
| fi |
| } |
| |
| connect () { |
| $(arg_or_default modem $(modems | head -1)) |
| [ -z "$modem" ] && echo "no modem found" && exit 1 |
| # Work around braindead quoting again... |
| args=$(echo "$@") |
| [ -z "$args" ] && args='ignored' |
| dbus "$modem" $IMODEM.Connect "string:$args" |
| } |
| |
| factory_reset () { |
| $(arg_or_default modem $(modems | head -1)) |
| [ -z "$modem" ] && echo "no modem found" && exit 1 |
| $(arg_or_prompt spc 000000) |
| |
| technology=$(modem_status $modem technology) |
| if [ "$technology" = "CDMA" ] ; then |
| cat <<-EOF |
| |
| WARNING: Unless you have been instructed to do so by a Verizon |
| Wireless customer service representative, factory resetting your |
| modem will prevent you from re-connecting to the Verizon Wireless. |
| |
| If you have been instructed to issue the 'modem factory-reset' |
| command, please make sure to issue the 'modem activate' |
| command afterwards to re-activate your modem. Do not use the |
| graphic user interface to do so. |
| |
| EOF |
| $(arg_or_prompt continue n) |
| if [ "$continue" != "y" -a "$continue" != "Y" ] ; then |
| echo "Factory reset cancelled." |
| return |
| fi |
| fi |
| dbus "$modem" $IMODEM.FactoryReset "string:$spc" |
| wait_for_modem_reset $modem 40 |
| } |
| |
| status () { |
| all_modem_status 2>/dev/null |
| } |
| |
| status_feedback () { |
| all_modem_status 2>/dev/null | mask_modem_properties |
| } |
| |
| update_prl () { |
| local modem |
| local mdn |
| local min |
| $(arg_or_default modem $(modems | head -1)) |
| [ -z "$modem" ] && echo "no modem found" && exit 1 |
| $(needarg prlfile) |
| mdn=$(modem_status $modem mdn) |
| min=$(modem_status $modem min) |
| if [ -z "$mdn" -o -z "$min" ]; then |
| echo "Cannot update PRL: MDN/MIN are unknown" |
| exit 1 |
| fi |
| if [ ! -r "$prlfile" ]; then |
| echo "Cannot read PRL file \"$prlfile\"" |
| exit 1 |
| fi |
| # Because cromo runs as a different user than this script, |
| # it may not have access to the specified file, even when |
| # the script does. A specific example is the Downloads folder, |
| # which only the "chronos" user has access to. To work |
| # around this problem, we copy the PRL file to /tmp. |
| local tmpfile=$(mktemp --tmpdir prl.XXXXXXXXXX) |
| trap "rm -f $tmpfile" 1 2 13 15 |
| cp $prlfile $tmpfile |
| if [ $? -ne 0 ]; then |
| echo "Cannot copy \"$prlfile\" to \"$tmpfile\" directory" |
| rm -f $tmpfile |
| exit 1 |
| fi |
| chmod 644 $tmpfile |
| local oldstate=$(modem_activation_state $modem) |
| args="mdn,$mdn,min,$min,prlfile,$tmpfile" |
| dbus "$modem" $IMODEM_CDMA.ActivateManualDebug \ |
| "dict:string:string:$args" |
| wait_for_modem_reset $modem 40 |
| rm -f $tmpfile |
| } |
| |
| set_carrier () { |
| local modem |
| local mm |
| mm=$(modemmanagers | grep chromium) |
| [ -z "$mm" ] && echo "no compatible modem found" && exit 1 |
| $(arg_or_default modem $(modems | head -1)) |
| [ -z "$modem" ] && echo "no modem found" && exit 1 |
| if [ $# -eq 0 ]; then echo 'Missing arg: carrier' && usage; fi |
| carrier="$*" |
| |
| echo Setting carrier to "$carrier". This could take up to two minutes. |
| echo Using modem "$modem" |
| |
| dbus-send \ |
| --reply-timeout=120000 \ |
| --system \ |
| --print-reply \ |
| --dest=$DEST \ |
| "$modem" \ |
| org.chromium.ModemManager.Modem.Gobi.SetCarrier \ |
| "string:$carrier" |
| } |
| |
| MADISON_CONFIG_GROUP_LOCATION=/var/lib/cromo/madison-config-group; |
| |
| set_madison_config () { |
| group="$*"; |
| |
| if [ -z "$group" ] ; then |
| echo "No config group specified." |
| echo "Usage: modem set-madison-config <config-group-name>" |
| return |
| fi |
| |
| if [ ! -w $MADISON_CONFIG_GROUP_LOCATION ] ; then |
| echo "$MADISON_CONFIG_GROUP_LOCATION is not a writable file." |
| echo "Please reboot (or restart cromo) and try again."; |
| return |
| fi |
| |
| if [ "$(readlink -f $MADISON_CONFIG_GROUP_LOCATION)" != \ |
| "$MADISON_CONFIG_GROUP_LOCATION" ] ; then |
| echo "$MADISON_CONFIG_GROUP_LOCATION points somewhere strange." |
| echo "Please reboot (or restart cromo) and try again." |
| return |
| fi |
| |
| echo Setting madison config group to "$group". |
| |
| echo "$group" > $MADISON_CONFIG_GROUP_LOCATION; |
| |
| echo "Please reboot (or restart cromo) to use the new config group." |
| } |
| |
| usage () { |
| echo "Usage: $0 <command> [args...]" |
| echo " activate [-modem <modem>] [<carrier>] Activate modem" |
| echo " activate-manual [-modem <modem>] [args...] Activate modem manually" |
| echo " connect [-modem <modem>] [phone number] Connect modem" |
| echo " factory-reset [-modem <modem>] [<spc>] Factory-reset the modem" |
| echo " status Display modem status" |
| echo " update-prl [-modem <modem>] <prl-file-name> Install a PRL file" |
| echo " set-carrier [-modem <modem>] <carrier-name> Set modem carrier firmware" |
| echo " set-madison-config <config-group-name> Set Madison config group" |
| exit 0 |
| } |
| |
| $(needarg cmd) |
| case "$cmd" in |
| activate) |
| activate "$@" |
| ;; |
| activate-manual) |
| activate_manual "$@" |
| ;; |
| connect) |
| connect "$@" |
| ;; |
| factory-reset) |
| factory_reset "$@" |
| ;; |
| status) |
| status "$@" |
| ;; |
| status-feedback) |
| status_feedback "$@" |
| ;; |
| update-prl) |
| update_prl "$@" |
| ;; |
| set-carrier) |
| set_carrier "$@" |
| ;; |
| set-madison-config) |
| set_madison_config "$@" |
| ;; |
| *) |
| usage |
| ;; |
| esac |