#!/bin/bash # openAircard320U.sh # written by bob fulton BRAEWORKS Nov 2012 # script to connect a Telstra Bigpond Sierra Wireless Aircard 320U 4G USB dongle # BTW the host OS is CentOS 6.4 server and provides internet access (see firewall note) # to local machines on the LAN and WLAN including iPads and iPods. No desktop nor NetworkManager is required. # after a few requests added the read back from the modem # provided AS IS, no warranties, etc. are provided VERSION=V1.11 PROG="$(basename $0)" BASEDIR="/custom/broadband" . ${BASEDIR}/commonAircard320U.inc echo "Start $PROG $VERSION on $(date '+%Y/%m/%d %H:%M:%S')" if [ ! -z "$USER" -a "$USER" != "root" ]; then echo "Must be root (not $USER) user to execute $PROG." exit 1 fi # wait for dongle to find the signal at power on (optional) sleep 5 # echo "check its there" TST=$(usb-devices 2> /dev/null | grep "Product=AirCard 320U") # echo $TST # test if [ -z "$TST" ]; then echo "Sierra Wireless AirCard 320U not found" exit 1 fi # TTY_USBS=$(ls /dev/ttyUSB*) # echo $TTY_USBS # echo "check $NET_ETH is up" TST=$(ifconfig | awk ' { print $1 } ' | grep $NET_ETH) if [ -z "$TST" ]; then # echo "Bring up $NET_ETH" # test ifconfig $NET_ETH up TST=$(ifconfig | awk ' { print $1 } ' | grep $NET_ETH) if [ -z "$TST" ]; then echo "Failed to bring up $NET_ETH" exit 1 fi fi USBTERM_RESPONSE="" # sometimes the doggle provides erronenous responses (typically trying to use part of a previous command) function usbTermCmd() { # $1=outCmd, [$2=-v (verbose)] USBTERM_RESPONSE="" echo -e "${1}\r" > "$MODEM_PORT" while read -t $READ_TOUT R do if [ "${#R}" -lt 1 ]; then continue; fi # forget blank lines USBTERM_RESPONSE="$R" # save the last line (usually OK or ERROR) if [ ! -z "$2" -a "$2" == "-v" ]; then echo "$R"; fi done < "$MODEM_PORT" return 0 } # usbTermCmd() # NOTE: the following lines are stored in the Aircard 320U after the device has been initialized # and are not needed here # # usbTermCmd "ATZ" # ??? # # usbTermCmd "ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0" # ??? # usbTermCmd "ATD*99**#" # usbTermCmd "AT+CGDCONT=1,\"IP\",\"telstra.bigpond\"" # usbTermCmd "AT\$QCPDPP=1,1,\"bigpond.password\",\"username@bigpond.com\"" # # disconnect first # usbTermCmd "AT!SCACT=0,$MPPID" # sleep 5 # connect usbTermCmd "AT!SCACT=1,$MPPID" > /dev/null if [ "$USBTERM_RESPONSE" != "OK" ]; then echo "Failed to connect" else echo "Connected" # echo "get IP address, etc." # NOTE: that the dhclient.conf file will need to setup on a server type machine, # otherwise the dhcp will rewrite many settings for DNS etc. TST=$(ps ax | grep 'dhclient' | grep $NET_ETH | grep -v 'grep') if [ -z "$TST" ]; then # echo "Start dhclient on $NET_ETH" # test # should only need to start once dhclient -cf ${BASEDIR}/dhclient-Aircard320U.conf -nw -nc -v $NET_ETH # fi # not needed as dhclient should do this # # check default route is set up # USB0_IP=$(ip addr show dev $NET_ETH | grep inet | grep -v inet6 | awk '{ print $2 }') # if [ ! -z "$USB0_IP" ]; then # TST=$(route -n | grep $USB0_IP | awk '{ print $1 }') # if [ "$TST" != "default" ]; then # echo "Adding default gateway $USB0_IP" # route del default # delete other defaults # route add default gw $USB0_IP # fi # fi fi echo "Finish $PROG $VERSION on $(date '+%Y/%m/%d %H:%M:%S')" echo "" exit 0 # done # EOF