plugin: shell
id: mobilebroadband/gsm_connection
estimated_duration: 20.0
requires:
    package.name == 'network-manager'
    package.name == 'modemmanager'
    mobilebroadband.gsm == 'supported'
user: root
environ: GSM_CONN_NAME GSM_APN GSM_USERNAME GSM_PASSWORD
command:
  if [ -n "${GSM_APN}" ]; then
      trap "nmcli con delete id $GSM_CONN_NAME" EXIT
      create_connection mobilebroadband gsm \
      `[ -n "${GSM_APN}" ] && echo "--apn=$GSM_APN"` \
      `[ -n "${GSM_CONN_NAME}" ] &&  echo "--name=$GSM_CONN_NAME"` \
      `[ -n "${GSM_USERNAME}" ] && echo "--username=$GSM_USERNAME"` \
      `[ -n "${GSM_PASSWORD}" ] && echo "--password=$GSM_PASSWORD"` || exit 1
  fi
  INTERFACE=`nmcli -t -f GENERAL -m tabular dev list |grep gsm |cut -d ":" -f 13`
  echo "connected GSM interface seems to be $INTERFACE"
  [ -z $INTERFACE ] && exit 1
  curl http://start.ubuntu.com/connectivity-check.html --interface $INTERFACE
  EXIT_CODE=$?
  if [ -n "${GSM_APN}" ] && [ "`nmcli dev status | awk '/gsm/ {print $3}'`" == "connected" ]; then
          nmcli con down id `[ ${GSM_CONN_NAME} ] && echo "$GSM_CONN_NAME" || echo "MobileBB"`
  fi
  exit $EXIT_CODE
_description: Creates a mobile broadband connection for a GSM based modem and checks the connection to ensure it's working. 

plugin: shell
id: mobilebroadband/cdma_connection
estimated_duration: 20.0
requires:
    package.name == 'network-manager'
    package.name == 'modemmanager'
    mobilebroadband.cdma == 'supported'
user: root
environ: CDMA_CONN_NAME CDMA_USERNAME CDMA_PASSWORD
command:
  if [ -n "${CDMA_USERNAME}" ]; then
      trap "nmcli con delete id $CDMA_CONN_NAME" EXIT
      create_connection mobilebroadband cdma \
      `[ -n "${CDMA_CONN_NAME}" ] &&  echo "--name=$CDMA_CONN_NAME"` \
      `[ -n "${CDMA_USERNAME}" ] && echo "--username=$CDMA_USERNAME"` \
      `[ -n "${CDMA_PASSWORD}" ] && echo "--password=$CDMA_PASSWORD"` || exit 1
  fi
  INTERFACE=`nmcli -t -f GENERAL -m tabular dev list |grep cdma |cut -d ":" -f 13`
  echo "connected CDMA interface seems to be $INTERFACE"
  [ -z $INTERFACE ] && exit 1
  curl http://start.ubuntu.com/connectivity-check.html --interface $INTERFACE
  EXIT_CODE=$?
  if [ -n "${CDMA_USERNAME}" ] && [ "`nmcli dev status | awk '/cdma/ {print $3}'`" == "connected" ]; then
          nmcli con down id `[ ${CDMA_CONN_NAME} ] && echo "$CDMA_CONN_NAME" || echo "MobileBB"`
  fi
  exit $EXIT_CODE
_description: Creates a mobile broadband connection for a CDMA based modem and checks the connection to ensure it's working.

plugin: local
id: mobilebroadband/maximum_bandwidth_gsm
requires:
 device.category == 'NETWORK'
 package.name == 'zenity'
 package.name == 'iperf'
depends: mobilebroadband/gsm_connection
command:
 cat <<'EOF' | run_templates -s 'udev_resource | filter_templates -w "category=NETWORK" | awk "/path: / { print \$2 }" | xargs -n 1 sh -c "for i in \`ls /sys\$0/net 2>/dev/null\`; do echo \$0 \$i; done"'
 plugin: user-verify
 user: root
 id: mobilebroadband/maximum_bandwidth_$2
 requires: device.path == "$1"
 environ: TEST_TARGET_FTP TEST_TARGET_IPERF TEST_USER TEST_PASS
 command: network test -i $2 -t iperf 2>&1 | cat - <(echo; echo "Verify the result and click OK to decide on the outcome") | zenity --text-info --title 'mobile broadband max bw $2'
 estimated_duration: 330.0
 _description:
  PURPOSE:
      User verification of whether the observed transfer throughput is acceptable
      for the type and maximum speed of each interface.
  STEPS:
      1. Read the network test summary and confirm that the throughput is acceptable.
      2. If needed, click "Test" again to repeat the transfer test.
  VERIFICATION:
     Was the reported throughput acceptable for the type and maximum speed of this interface?
 EOF
_description:
 This test executes a maximum throughput test against all the devices found on the system.

plugin: local
id: mobilebroadband/maximum_bandwidth_cdma
requires:
 device.category == 'NETWORK'
 package.name == 'zenity'
 package.name == 'iperf'
depends: mobilebroadband/cdma_connection
command:
 cat <<'EOF' | run_templates -s 'udev_resource | filter_templates -w "category=NETWORK" | awk "/path: / { print \$2 }" | xargs -n 1 sh -c "for i in \`ls /sys\$0/net 2>/dev/null\`; do echo \$0 \$i; done"'
 plugin: user-verify
 user: root
 id: mobilebroadband/maximum_bandwidth_$2
 requires: device.path == "$1"
 environ: TEST_TARGET_FTP TEST_TARGET_IPERF TEST_USER TEST_PASS
 command: network test -i $2 -t iperf 2>&1 | cat - <(echo; echo "Verify the result and click OK to decide on the outcome") | zenity --text-info --title 'mobile broadband max bw $2'
 estimated_duration: 330.0
 _description:
  PURPOSE:
      User verification of whether the observed transfer throughput is acceptable
      for the type and maximum speed of each interface.
  STEPS:
      1. Read the network test summary and confirm that the throughput is acceptable.
      2. If needed, click "Test" again to repeat the transfer test.
  VERIFICATION:
     Was the reported throughput acceptable for the type and maximum speed of this interface?
 EOF
_description:
 This test executes a maximum throughput test against all the devices found on the system.


