From 64c386dd2f9413452721c7d8f53dbad30da6f6a8 Mon Sep 17 00:00:00 2001 From: giovanni Date: Wed, 8 Oct 2008 14:50:16 +0000 Subject: [PATCH] Add support for the Huawei e620 umts card --- backend.spec | 6 ++- backend/96-umts-tools.rules | 2 +- backend/umts | 2 +- backend/umts_backend | 16 ++---- backend/umts_functions | 99 ++++++++++++++++--------------------- frontend.spec | 2 +- frontend/README.PI | 6 +-- frontend/README.User | 4 +- 8 files changed, 60 insertions(+), 77 deletions(-) diff --git a/backend.spec b/backend.spec index 641e542..f08db13 100644 --- a/backend.spec +++ b/backend.spec @@ -2,7 +2,7 @@ %define name planetlab-umts-tools-backend %define version 0.5 -%define release 2 +%define release 3 Summary: Umts-tools for PlanetLab - backend part Name: %{name} @@ -41,9 +41,11 @@ popd %post /sbin/udevadm control reload_rules +/sbin/udevtrigger +/bin/sleep 2 /sbin/chkconfig umts on -/etc/rc.d/init.d/umts start /sbin/service vsys restart +/etc/rc.d/init.d/umts start %preun /sbin/chkconfig umts off diff --git a/backend/96-umts-tools.rules b/backend/96-umts-tools.rules index 6215812..3146fac 100644 --- a/backend/96-umts-tools.rules +++ b/backend/96-umts-tools.rules @@ -1,2 +1,2 @@ KERNEL=="noz0", NAME="umts_modem" - +KERNEL=="ttyUSB*", ATTR{dev}=="188:0", ATTRS{idProduct}=="1001", ATTRS{idVendor}=="12d1", NAME="umts_modem1" diff --git a/backend/umts b/backend/umts index c52ce10..641b001 100755 --- a/backend/umts +++ b/backend/umts @@ -9,7 +9,7 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin case "$1" in start) echo "Initializing the umts component..." - if init ; then echo "Done."; fi + if init_umts; then echo "Done."; fi ;; *) diff --git a/backend/umts_backend b/backend/umts_backend index b695763..29f7a53 100755 --- a/backend/umts_backend +++ b/backend/umts_backend @@ -1,6 +1,6 @@ #!/bin/bash -# Vsys backend of the planetlab-umts-tools +# Vsys backend sliver=$1 @@ -25,10 +25,7 @@ case "$command" in logger "Starting the umts connection for $sliver" start_umts $sliver; - if [[ $? == 0 ]] ; then - #echo "OK" - true - else + if [[ $? != 0 ]] ; then echo "Failed" fi ;; @@ -37,17 +34,14 @@ case "$command" in logger "Stopping umts connection for $sliver" stop_umts $sliver; - if [[ $? == 0 ]] ; then - #echo "OK" - true - else + if [[ $? != 0 ]] ; then echo "Failed" fi ;; add) - logger "Request to add a destination for the umts connection"; + logger "Request to add a destination by $sliver for the umts connection"; if ! valid_dotted_quad "$rest"; then echo "Failed" @@ -63,7 +57,7 @@ case "$command" in ;; del) - logger "Request to del a destination for the umts connection"; + logger "Request to del a destination by $sliver for the umts connection"; if ! valid_dotted_quad "$rest"; then echo "Failed" diff --git a/backend/umts_functions b/backend/umts_functions index c97c321..1d87671 100644 --- a/backend/umts_functions +++ b/backend/umts_functions @@ -1,46 +1,35 @@ #!/bin/bash -PPPD_PIDFILE=/var/run/umts_pppd.pid - -PPPD=pppd STROK="remote IP address" - -PPP_INT=ppp0 - GCOM="" - LOGF="/tmp/umtslogs" - +PPPD_PIDFILE="/var/run/umts_pppd.pid" DESTS_FILE="/tmp/umts_dest_file" - FILE_TEMP_NID="/tmp/umts_temp_nid" - FILE_UMTS_INT="/tmp/umts_dev" +PPP_INT=ppp0 +PPPD=pppd function set_umts_dev(){ - echo $1 > $FILE_UMTS_INT + local umts_dev=$1 + echo $umts_dev > $FILE_UMTS_INT } function get_umts_dev(){ - cat $FILE_UMTS_INT + if [ -e $FILE_UMTS_INT ]; then + cat $FILE_UMTS_INT + fi } - -function start_gcom(){ - if ! $GCOM -d `get_umts_dev`; then - return 1; - fi - - return 0 +function unset_umts_dev(){ + rm -f $FILE_UMTS_INT } -function init(){ - local found=1 - modprobe nozomi - modprobe serial_cs +function init_umts(){ + local found=1 if [ -f /usr/bin/gcom ]; then GCOM=/usr/bin/gcom @@ -51,21 +40,25 @@ function init(){ return 1; fi + unset_umts_dev + for i in /dev/umts_modem /dev/umts_modem1; do echo "Testing if the umts interface is present on the device $i..." - if $GCOM -d $i; then - found=0 - set_umts_dev $i - break + if [ -e $i ]; then + if $GCOM -d $i; then + found=0 + set_umts_dev $i + break + fi fi done if ! [ $found == 0 ]; then - echo "I couldn't find the umts device; make a symlink from it to /dev/umts_modem" + echo "I couldn't find the umts device. Make a symlink from it to /dev/umts_modem." return 1 fi - if ! grep umts_table /etc/iproute2/rt_tables > /dev/null 2>&1; then + if ! grep "umts_table" /etc/iproute2/rt_tables > /dev/null 2>&1; then echo "20 umts_table" >> /etc/iproute2/rt_tables fi @@ -82,11 +75,10 @@ function get_temp_nid(){ #called when the connection is started function conn_on(){ local sliver=$1 - #local sliver_nid=$2 #DESTS_FILE contains added destinations rm -f $DESTS_FILE - touch $DESTS_FILE > /dev/null 2>&1 + touch $DESTS_FILE set_temp_nid $sliver_nid @@ -100,7 +92,6 @@ function conn_on(){ #called when the connection is terminated function conn_off(){ local sliver=$1 - #local sliver_nid=$2 unset_routes $sliver @@ -121,8 +112,14 @@ function start_umts(){ return 0; fi - if ! [ -c `get_umts_dev` ]; then - echo "Umts interface not present" + if [[ `get_umts_dev` == "" ]]; then + if [[ init_umts != 0 ]]; then + return 1 + fi + fi + + if ! [ -e `get_umts_dev` ]; then + echo "Umts interface is not present" return 1 fi @@ -140,10 +137,8 @@ function start_umts(){ echo $! > $PPPD_PIDFILE - sleep 5s; #waiting for the interface to establish the link if grep "$STROK" $LOGF >/dev/null 2>&1; then - conn_on $sliver $sliver_nid else #second try @@ -162,6 +157,7 @@ function start_umts(){ function stop_umts(){ local sliver=$1 + local sliver_nid=`get_nid $sliver` if ! [ -e $PPPD_PIDFILE ]; then echo "Disconnected" @@ -171,10 +167,9 @@ function stop_umts(){ PID=`cat $PPPD_PIDFILE`; if [ -d /proc/$PID ] && grep $PPPD /proc/$PID/cmdline >/dev/null 2>&1; then - #del_interface $1; - conn_off $sliver `get_nid $sliver` + conn_off $sliver $sliver_nid kill $PID; - sleep 5; + sleep 4; fi if status_umts; then @@ -223,16 +218,16 @@ function set_routes(){ local temp_nid=`get_temp_nid` local ppp_addr=`get_ppp_address` - #remarking of packets to trigger rerouting and SNAT + #remarking of packets, to trigger rerouting, and SNAT iptables -t mangle -A OUTPUT -j MARK --copy-xid 0x00 iptables -t mangle -A OUTPUT -m mark --mark $sliver_nid -j MARK --set-mark $temp_nid - iptables -t nat -A POSTROUTING -o $PPP_INT -j SNAT --to-source `get_ppp_address` + iptables -t nat -A POSTROUTING -o $PPP_INT -j SNAT --to-source $ppp_addr iptables -t mangle -I POSTROUTING 1 -m mark --mark $temp_nid -j MARK --set-mark $sliver_nid #enable the explicit bind to the ppp interface ip route flush table umts_table >/dev/null 2>&1 - ip rule add from $ppp_addr fwmark `get_temp_nid` table umts_table >/dev/null 2>&1 - ip route add default dev $PPP_INT src `get_ppp_address` table umts_table >/dev/null 2>&1 + ip rule add from $ppp_addr fwmark $temp_nid table umts_table >/dev/null 2>&1 + ip route add default dev $PPP_INT src $ppp_addr table umts_table >/dev/null 2>&1 ip route flush cache >/dev/null 2>&1 } @@ -245,12 +240,12 @@ function unset_routes(){ #remarking and SNAT removed iptables -t mangle -D OUTPUT -j MARK --copy-xid 0x00 iptables -t mangle -D OUTPUT -m mark --mark $sliver_nid -j MARK --set-mark $temp_nid - iptables -t nat -D POSTROUTING -o $PPP_INT -j SNAT --to-source `get_ppp_address` + iptables -t nat -D POSTROUTING -o $PPP_INT -j SNAT --to-source $ppp_addr iptables -t mangle -D POSTROUTING -m mark --mark $temp_nid -j MARK --set-mark $sliver_nid #disable the explicit bind to the ppp interface - ip rule del from $ppp_addr fwmark `get_temp_nid` table umts_table >/dev/null 2>&1 - ip route del default dev $PPP_INT src `get_ppp_address` table umts_table >/dev/null 2>&1 + ip rule del from $ppp_addr fwmark $temp_nid table umts_table >/dev/null 2>&1 + ip route del default dev $PPP_INT src $ppp_addr table umts_table >/dev/null 2>&1 ip route flush cache >/dev/null 2>&1 } @@ -258,9 +253,7 @@ function unset_routes(){ function add_destination(){ local dest="$1" local sliver=$2 - local sliver_nid=`get_nid $sliver` - local temp_nid=`get_temp_nid` if [[ ! $dest ]]; then return 1; fi @@ -281,13 +274,10 @@ function add_destination(){ function del_destination(){ local dest="$1" local sliver=$2 - local sliver_nid=`get_nid $sliver` - local temp_nid=`get_temp_nid` if [[ ! $dest ]]; then return 1; fi - #old - if ip route del to "$dest" dev $PPP_INT >/dev/null 2>&1; then if ip rule del to "$dest" fwmark $temp_nid table umts_table >/dev/null 2>&1; then return 0; else @@ -305,9 +295,7 @@ function set_temp_nid(){ local sliver_nid=$1 local temp_nid=$((0x20000+$sliver_nid)) - #k=0 - #temp_nid=$sliver_nid - + #k=0 #while grep :$temp_nid: /etc/passwd; do # temp_nid=$((temp_nid+1)) # k=$((k+1)) @@ -317,13 +305,12 @@ function set_temp_nid(){ # exit 1 # fi #done - echo $temp_nid > $FILE_TEMP_NID } - +# checks ip addresses function valid_dotted_quad(){ oldIFS=$IFS IFS=. diff --git a/frontend.spec b/frontend.spec index 9c21c9e..882c555 100644 --- a/frontend.spec +++ b/frontend.spec @@ -2,7 +2,7 @@ %define name planetlab-umts-tools-frontend %define version 0.5 -%define release 2 +%define release 3 Summary: UMTS tools for PlanetLab Name: %{name} diff --git a/frontend/README.PI b/frontend/README.PI index 5fd0d90..614e715 100644 --- a/frontend/README.PI +++ b/frontend/README.PI @@ -23,7 +23,7 @@ add_to_nodegroup.py) that can be used to do this operation automatically. ======================================================================== SUPPORTED CARDS -At present the Globetrotter 3G/HSDPA and MERLIN U530 UMTS PCMCIA are -supported. Every other card supported by the nozomi driver, or by the -serial_cs drivers, should work as well. +At present the Globetrotter 3G/HSDPA and the Huawei e620 are +supported. Any other card supported by the nozomi driver should work as +well. diff --git a/frontend/README.User b/frontend/README.User index c3b30c4..cbbd2a6 100644 --- a/frontend/README.User +++ b/frontend/README.User @@ -52,13 +52,13 @@ The answer is either Connected or Disconnected. To add a destination (packets directed towards this destination will go out of the node through the ppp interface): - umts add network_address/netmask + umts add ip_destination The answer is OK if everything went well. To del a destination previously added: - umts del network_address/netmask + umts del ip_destination The answer is OK if everything went well. -- 2.43.0