4 STROK="remote IP address"
6 GCOM="/usr/bin/"${GCOMP}
8 PPPD_PIDFILE="/var/run/umts_pppd.pid"
9 DESTS_FILE="/tmp/umts_dest_file"
10 FILE_TEMP_NID="/tmp/umts_temp_nid"
11 FILE_UMTS_INT="/tmp/umts_dev"
12 LOCK_DIR="/tmp/umts_lock_d"
13 FILE_LOCK_SLIVER="/tmp/umts_locking_sliver"
16 CHAT_SCRIPTS="/etc/chatscripts"
17 UMTS_CONF="/etc/umts.conf"
21 function get_umts_dev(){
22 echo "/dev/umts_modem"
28 if [ -e $LOCK_DIR ]; then
32 # the routing table is now managed by sliceip
33 #if ! grep "umts_table" /etc/iproute2/rt_tables > /dev/null 2>&1; then
34 # echo "20 umts_table" >> /etc/iproute2/rt_tables
42 function get_temp_nid(){
47 #called when the connection is started
51 #DESTS_FILE contains added destinations
54 cat $LOGF | grep "local"
59 #called when the connection is terminated to remove the rules
60 #on the destinations reachable thorugh the UMTS device
65 # Not needed anymore as the killing of the PPP connection
66 # makes the rules pointing to it automatically disappear.
68 # for i in `cat $DESTS_FILE`; do
69 # del_destination $i $sliver > /dev/null 2>&1
72 rm $DESTS_FILE >/dev/null 2>&1
75 function start_umts(){
77 local sliver_nid=`get_nid $sliver`
79 if ! lock $sliver; then
84 echo "Already connected"
88 echo "Starting GCOM..."
89 if ! $GCOM -d `get_umts_dev`; then
96 if [ -e $UMTS_CONF ]; then
100 if ! [[ $APN ]]; then
103 if ! [[ $NUM ]]; then
108 exec /usr/sbin/pppd nodetach `get_umts_dev` 460800 \
110 connect "/usr/sbin/chat -v \
113 ABORT '\nNO ANSWER\r' \
114 ABORT '\nRINGING\r\n\r\nRINGING\r' \
115 '' ATZ OK 'ATQ0 V1 E1 S0=0 &C1 &D2 +FCLASS=0' OK \
116 'AT+CGDCONT=1,\"IP\",\"$APN\"' OK \
117 ATD$NUM CONNECT ''" > $LOGF &
120 echo $! > $PPPD_PIDFILE
122 sleep 5s; #waiting for the interface to establish the link
123 if grep "$STROK" $LOGF >/dev/null 2>&1; then
124 conn_on $sliver $sliver_nid
128 if grep "$STROK" $LOGF >/dev/null 2>&1; then
129 conn_on $sliver $sliver_nid
138 # stop the UMTS connection by killing the pppd daemon and
139 # then by calling conn_off
140 function stop_umts(){
142 local sliver_nid=`get_nid $sliver`
145 if ! [ -e $PPPD_PIDFILE ]; then
150 ppp_addr=`get_ppp_address`
152 if ! check_who_locked $sliver; then
156 PID=`cat $PPPD_PIDFILE`;
158 if [ -d /proc/$PID ] && grep $PPPD /proc/$PID/cmdline >/dev/null 2>&1; then
167 conn_off $sliver $ppp_addr
168 cat $LOGF | grep "time"
175 # check the status of the umts connection by looking at then
176 # state of pppd daemon
177 function status_umts(){
180 if ! [ -e $PPPD_PIDFILE ]; then return 1; fi
181 PID=`cat $PPPD_PIDFILE`
183 if [ -d /proc/$PID ] && grep $PPPD /proc/$PID/cmdline >/dev/null 2>&1; then
190 #add the ppp interface to the slice - not used at the moment
191 function add_interface(){
192 local nid=`get_nid $1`
193 $NADDRESS --add --nid $nid --ip $PPP_INT >>$LOGFILE 2>&1;
196 #remove the ppp interface from the slice - not used at the moment
197 function del_interface(){
198 local nid=`get_nid $1`
199 #$NADDRESS --remove --nid $NID --ip $PPP_INT >>$LOGFILE 2>&1;
202 #get slice network id
208 # check if sliceip is activated for the slice
209 function check_sliceip(){
211 if ! [ -e /vsys/sliceip ]; then
212 echo "Sliceip is not installed. Exiting."
218 # Deliver a command to sliceip (basically to set the destinations to be
219 # reached through the UMTS device)
220 function sliceip_cmd(){
225 echo "$command" | /vsys/sliceip $sliver
229 # Add a destination to be reached through the UMTS device
230 function add_destination(){
234 if [[ ! $dest ]]; then return 1; fi
236 if ! status_umts; then
240 if ! check_who_locked $sliver; then
244 sliceip_cmd $sliver "route add $dest dev ${PPP_INT}"
248 # Delete a destination that was previously reached through the UMTS device.
249 function del_destination(){
253 if [[ ! $dest ]]; then return 1; fi
255 if ! check_who_locked $sliver; then
259 sliceip_cmd $sliver "route del $dest dev ${PPP_INT}";
264 function get_ppp_address(){
265 ifconfig $PPP_INT | grep inet\ addr | cut -d ":" -f 2 | cut -d " " -f 1
269 function check_who_locked(){
271 local sliver_nid=`get_nid $sliver`
274 if [ -e $LOCK_DIR ]; then
275 if [[ `cat $FILE_LOCK_SLIVER` != $sliver_nid ]]; then
276 echo "Interface in use by another slice.";
287 # kill the gcom daemon
288 function kill_gcom(){
292 if ! ps -C $GCOMP >/dev/null 2>&1; then
293 echo "$GCOMP terminated."
295 echo "$GCOMP still alive. Try kill -9"
300 if ! ps -C $GCOMP >/dev/null 2>&1; then
301 echo "$GCOMP terminated."
303 echo "Couldn't stop $GCOMP. Please contact administrators for assistance."
308 # lock the umts connection to a specific sliver.
309 # only one sliver at a given time can use the UMTS device
312 # local sliver_nid=`get_nid $sliver`
315 if [ -e $LOCK_DIR ]; then
316 if ! check_who_locked $sliver; then
320 if mkdir $LOCK_DIR >/dev/null 2>&1; then
321 echo "$sliver_nid" > $FILE_LOCK_SLIVER
332 local sliver_nid=`get_nid $sliver`
335 if ! [ -e $LOCK_DIR ]; then
338 if ! check_who_locked $sliver; then
341 if ! rmdir $LOCK_DIR; then
353 # checks an ip addresse for validity
354 function valid_dotted_quad(){
364 ""|*[!0-9]*) return 1; break ;; ## Segment empty or non-numeric char
365 *) [ $seg -gt 255 ] && return 2 ;;
369 return 3 ## Not 4 segments