conn

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

gobi-x201-init (2777B)


      1 #!/bin/sh
      2 
      3 #
      4 # My rule for udev is:
      5 # SUBSYSTEM=="tty", DRIVERS=="qcserial", ATTRS{bInterfaceNumber}=="02", \
      6 #	SYMLINK+="gobimodem"
      7 # The other ttyUSB0 can be symlinked with "01" and "03" respectively,
      8 # where "03" is "gobigps" and "01" is "gobidiag".
      9 #
     10 CONTROL_DEVICE="/dev/gobimodem"
     11 #
     12 # Change the PIN to your SIM PIN.
     13 #
     14 PIN="7471"
     15 #
     16 # Your provider's APN.
     17 #
     18 APN="surfo2"
     19 #
     20 # The user, which is used. It shouldn't matter anyway.
     21 #
     22 USER="o2"
     23 #
     24 # The number to dial to start the link.
     25 #
     26 NUMBER="*99#"
     27 
     28 case "$1" in
     29 	-s)
     30 		if [ -z "$(lsmod | grep qcserial)" ];
     31 		then
     32 			modprobe qcserial
     33 		fi
     34 
     35 		echo -n "Powering up Gobi card.."
     36 		rfkill unblock wwan
     37 		while [ ! -c $CONTROL_DEVICE ];
     38 		do
     39 			sleep 0.5;
     40 			echo -n ".";
     41 		done
     42 		echo "done"
     43 
     44 		echo -n "Turning on Gobi card..."
     45 		sleep 2
     46 		chat -t 2 -v "ABORT" "NO CARRIER" "" "AT+CFUN=1" "OK" > \
     47 			$CONTROL_DEVICE < $CONTROL_DEVICE
     48 		if [ $? -eq 4 ];
     49 		then
     50 			logger -s -t "gobi-init" "AT+CFUN=1 failed. This" \
     51 				"could be because of no carrier found. Try" \
     52 				"restarting the connection."
     53 			exit 1
     54 		fi
     55 
     56 		sleep 2
     57 		if [ -n "$PIN" ];
     58 		then
     59 			echo -n "PIN..."
     60 	    		/usr/sbin/chat -t 2 -v "" "AT+CPIN?" "SIM PIN" \
     61 				"AT" "OK" "AT+CPIN=\"$PIN\"" "OK" \
     62 				> $CONTROL_DEVICE < $CONTROL_DEVICE
     63 		fi
     64 		sleep 1
     65 		echo -n "COM..."
     66 		i=0
     67 		while [ $i -lt 11 ];
     68 		do
     69 			chat -t 2 -v "" "AT+CPIN?" "READY" \
     70 				> $CONTROL_DEVICE < $CONTROL_DEVICE
     71 			[ $? -eq 0 ] && break
     72 
     73 			i=`expr $i + 1`
     74 			if [ $i -eq 10 ];
     75 			then
     76 				logger -s -t "gobi-init" "Gobi modem" \
     77 					"needed more than 10 seconds" \
     78 					"to be SIM ready. Please" \
     79 					"restart the connection."
     80 				exit 1
     81 			fi
     82 			sleep 1
     83 		done
     84 		sleep 1
     85 		chat -t 2 -v "" "AT+CPIN?" "READY" "AT" "OK" \
     86 			"AT+CGDCONT=1,\"IP\",\"$APN\"" "OK" \
     87 			"ATDT${NUMBER}" "CONNECT" \
     88 			> $CONTROL_DEVICE < $CONTROL_DEVICE
     89 		if [ $? -gt 0 ];
     90 		then
     91 			logger -s -t "gobi-init" "Dialing the carrier failed." \
     92 				"See syslog for details."
     93 			exit 1
     94 		fi
     95 		echo "done"
     96 
     97 		echo -n "Starting pppd ..."
     98 		if [ "$(ip route | grep default)" != "" ];
     99 		then
    100 			ip route del default
    101 		fi
    102 		pppd $CONTROL_DEVICE 9600 modem crtscts defaultroute \
    103 			usehostname user $USER noipdefault usepeerdns noauth \
    104 			nolock nolog
    105 		echo "done"
    106 		;;
    107 	-o)
    108 		if [ -n "$(pgrep -f "pppd $CONTROL_DEVICE")" ];
    109 		then
    110 			return 1
    111 		else
    112 			return 0
    113 		fi
    114 		;;
    115 	-k)
    116 		echo -n "Killing pppd ..."
    117 		pkill -KILL -f "pppd $CONTROL_DEVICE"
    118 		echo "done"
    119 
    120 		if [ -e $CONTROL_DEVICE ];
    121 		then
    122 			echo -n "Powering down Gobi card..."
    123 			chat -t 2 -v "" "AT+CFUN=0" "OK" > $CONTROL_DEVICE \
    124 				< $CONTROL_DEVICE
    125 			echo "done"
    126 		fi
    127 
    128 		#echo -n "Removing qcserial driver ..."
    129 		#rmmod qcserial 2>/dev/null
    130 		#echo "done"
    131 		;;
    132 	-r)
    133 		$0 -k
    134 		$0 -s
    135 		;;
    136 	*)
    137 		echo "usage: $0 [-s|-k|-r]"
    138 		;;
    139 esac
    140 exit 0
    141