conn

A script repository to manage connections in Linux.
git clone git://r-36.net/conn
Log | Files | Refs | LICENSE

commit 8e662e9eff176faeb2cdc009849bf9bdd369f5ce
parent 8640c2005c501799fd8f0d4f29ca7046f315f600
Author: Christoph Lohmann <20h@r-36.net>
Date:   Fri,  8 Apr 2011 20:21:56 +0200

Better rfkill and wwan example support.

Diffstat:
etc/conn/common.sh | 33+++++++++++++++++++++++++++++++++
etc/conn/config.sh | 5+++++
etc/conn/run.sh | 24+++++++++++++++++++-----
examples/wifi/run.sh | 13+++++++++++++
examples/wwan/f3507g-x201-init | 12++----------
examples/wwan/gobi-x201-init | 35+++++++++++++++++++++++++++--------
examples/wwan/ppp0-run.sh | 32+++++++++++++++++++++++++++++---
examples/wwan/run.sh | 15++++++++++++++-
examples/wwan/wwan0-run.sh | 2+-
9 files changed, 143 insertions(+), 28 deletions(-)

diff --git a/etc/conn/common.sh b/etc/conn/common.sh @@ -23,10 +23,18 @@ lock() { [ -e $LOCKF ] && lock=1 + i=0 while [ $lock -eq 1 ] do [ ! -e $LOCKF ] && lock=0 sleep 0.5; + + i=`expr $i + 1` + if [ $i -gt 100 ]; + then + echo "It took too long to aquire lock $1" + exit 1 + fi done touch $LOCKF @@ -183,3 +191,28 @@ islinkup() { fi } +## Rfkill handling +isblocked() { + res=`rfkill list $1 | grep ' yes'` + if [ "$res" == "" ]; + then + return 1 + else + return 0 + fi +} + +doblock() { + if ! isblocked $1; + then + rfkill block $1 + fi +} + +dounblock() { + if isblocked $1; + then + rfkill unblock $1 + fi +} + diff --git a/etc/conn/config.sh b/etc/conn/config.sh @@ -92,3 +92,8 @@ DHCPKILLCMD="dhcpcd -x" # PINGHOST="8.8.8.8" +# +# If a connection type is blocked by rfkill, should it be unblocked? +# +DOUNBLOCK=0 + diff --git a/etc/conn/run.sh b/etc/conn/run.sh @@ -137,19 +137,29 @@ then exit $? fi -if [ ! $doforce -eq 1 ]; +if [ $doforce -eq 0 ]; then if [ $dostart -eq 1 ]; then if isset "open" $connection $profile; then - echo "Connection $connection $profile is already open" - echo "Use -k or -f for killing it." + echo "Connection $connection $profile is already open." + echo "Use -f for forcing the closing." exit 1 fi - addstate "open" $connection $profile fi - [ $dokill -eq 1 ] && delstate "open" $connection $profile + + if [ $dokill -eq 1 ]; + then + if ! isset "open" $connection $profile; + then + echo "Connection $connection $profile is already" \ + "closed." + echo "Use -f for forcing the closing." + exit 1 + fi + delstate "open" $connection $profile + fi fi if [ $# -lt 2 ]; @@ -160,6 +170,10 @@ else fi runconnection $connection $cmdarg $profile $* +if [ $? -gt 1 ] && [ $dostart -eq 1 ] && [ $doforce -eq 1 ]; +then + addstate "open" $connection $profile +fi exit $? diff --git a/examples/wifi/run.sh b/examples/wifi/run.sh @@ -2,6 +2,18 @@ . ../common.sh +if isblocked "wifi"; +then + if [ $DOUNBLOCK -eq 1 ]; + then + dounblock "wifi" + else + echo "Your wifi device seems to be blocked. Please use rfkill" \ + "to unblock it." + exit 1 + fi +fi + interface=$2 [ "$2" == "" ] && interface="wlan0" @@ -33,4 +45,5 @@ case "$1" in exit 1 ;; esac +exit 0 diff --git a/examples/wwan/f3507g-x201-init b/examples/wwan/f3507g-x201-init @@ -7,7 +7,7 @@ CONTROL_DEVICE="/dev/ttyACM1" # # Your SIM card PIN. # -PIN="XXXX" +PIN="7471" # # The APN of your provider. # @@ -18,7 +18,6 @@ case "$1" in modprobe zaurus echo -n "Powering up F3507g card.." - echo enable > /proc/acpi/ibm/wan rfkill unblock wwan while [ ! -c $CONTROL_DEVICE ]; do @@ -47,16 +46,9 @@ case "$1" in echo -n "Powering down F3507g card.." rfkill block wwan - echo disable > /proc/acpi/ibm/wan - while [ -c $CONTROL_DEVICE ]; - do - sleep 0.5 - echo -n "." - done - echo "done" - rmmod zaurus rmmod cdc_ether + echo "done" ;; -r) $0 -k diff --git a/examples/wwan/gobi-x201-init b/examples/wwan/gobi-x201-init @@ -43,7 +43,7 @@ case "$1" in sleep 5 chat -t 2 -v "" "AT+CFUN=1" "OK" > $CONTROL_DEVICE \ < $CONTROL_DEVICE - [ ! $? -eq 0 ] && exit 1 + [ ! $? -eq 0 ] && exit 1 if [ -n "$PIN" ]; then @@ -53,11 +53,28 @@ case "$1" in > $CONTROL_DEVICE < $CONTROL_DEVICE fi echo -n "COM..." + i=0 + while [ $i -lt 11 ]; + do + chat -t 2 -v "" "AT+CPIN?" "SIM busy" \ + > $CONTROL_DEVICE < $CONTROL_DEVICE + [ $? -gt 0 ] && break + + i=`expr $i + 1` + if [ $i -eq 10 ]; + then + echo "Gobi modem needed more than 10 seconds" \ + "to be SIM ready. Please restart the" \ + "connection, if this isn't an error." + exit 1 + fi + sleep 1 + done chat -t 2 -v "" "AT+CPIN?" "READY" "AT" "OK" \ "AT+CGDCONT=1,\"IP\",\"$APN\"" "OK" \ "ATDT${NUMBER}" "CONNECT" \ > $CONTROL_DEVICE < $CONTROL_DEVICE - [ ! $? -eq 0 ] && exit 1 + [ ! $? -eq 0 ] && exit 1 echo "done" echo -n "Starting pppd ..." @@ -75,15 +92,17 @@ case "$1" in pkill -KILL -f "pppd $CONTROL_DEVICE" echo "done" - echo -n "Powering down Gobi card..." - chat -t 2 -v "" "AT+CFUN=0" "OK" > $CONTROL_DEVICE \ - < $CONTROL_DEVICE rfkill block wwan - echo disable > /proc/acpi/ibm/wan - echo "done" + if [ -e $CONTROL_DEVICE ]; + then + echo -n "Powering down Gobi card..." + chat -t 2 -v "" "AT+CFUN=0" "OK" > $CONTROL_DEVICE \ + < $CONTROL_DEVICE + echo "done" + fi echo -n "Removing qcserial driver ..." - rmmod qcserial + rmmod qcserial 2>/dev/null echo "done" ;; -r) diff --git a/examples/wwan/ppp0-run.sh b/examples/wwan/ppp0-run.sh @@ -13,9 +13,34 @@ case "$1" in exit 1 fi - echo -n "Waiting for ppp0 to be online ..." - while [ "`ip addr show dev $interface | grep inet`" == "" ]; + echo -n "Waiting for $interface to exist ... " + ip link show $interface 2>&1 >/dev/null + i=0 + while [ $? -gt 0 ]; do + i=`expr $i + 1` + if [ $i -gt 10 ]; + then + echo "pppd is taking too long to setup" \ + "$interface" + exit 1 + fi + sleep 0.5 + ip link show $interface 2>&1 >/dev/null + done + + echo -n "Waiting for $interface to be online ..." + i=0 + while [ "`ip addr show dev $interface 2>/dev/null \ + | grep inet`" == "" ]; + do + i=`expr $i + 1` + if [ $i -gt 100 ]; + then + echo "$interface is taking too long to" \ + "get online" + exit 1 + fi sleep 0.5; echo -n "." done @@ -29,7 +54,7 @@ case "$1" in exit $? ;; -u) - exit 0 + break; ;; -r) $0 -k $interface; @@ -40,4 +65,5 @@ case "$1" in exit 1 ;; esac +exit 0 diff --git a/examples/wwan/run.sh b/examples/wwan/run.sh @@ -2,12 +2,25 @@ . ../common.sh +if isblocked "wwan"; +then + if [ $DOUNBLOCK -eq 1 ]; + then + dounblock "wwan" + else + echo "Your wwan device(s) seem to be blocked. Please use rfkill" \ + "to unblock them." + exit 1 + fi +fi + inteface=$2 -[ "$2" == "" ] && interface="wwan0" +[ "$2" == "" ] && interface="ppp0" iffile="${WWANDIR}/${interface}-run.sh" [ ! -e $iffile ] && exit 1 $iffile $1 +exit $? diff --git a/examples/wwan/wwan0-run.sh b/examples/wwan/wwan0-run.sh @@ -20,7 +20,6 @@ case "$1" in exit $? ;; -u) - exit 0 ;; -r) $0 -k $interface; @@ -31,4 +30,5 @@ case "$1" in exit 1 ;; esac +exit 0