#! /bin/sh #------------------------------------------------------------------------------ # /etc/rc.d/rc340.umts - start umts __FLI4LVER__ # # Creation: 2005-07-11 Alexander Heinz # Last Update: $Id$ #------------------------------------------------------------------------------ if [ "$OPT_UMTS" = yes ] ; then begin_script UMTS "starting UMTS ..." umts_tmp="`pwd`" cd /etc/usb_modeswitch.d for idx in *%3A* ; do ### Wandle Sonderzeichen um ### ### %3A -> : ### %3D -> = ### %3F -> ? ln -sf $idx "$(echo $idx | sed -e "s/%3A/:/g;s/%3D/=/g;s/%3F/?/g")" done cd "${umts_tmp}" mkdir -p /etc/modprobe.d echo "options hso disable_net=1" >> /etc/modprobe.d/options if [ "$UMTS_DEBUG" = yes ] ; then debug='debug' chatprg='/usr/sbin/chat -v' else debug='' chatprg='/usr/sbin/chat' fi umts_chat(){ ### mit Adapter kommunizieren ################## eval $chatprg "$*" >/dev/$UMTS_DEV /dev/null [ -e ${umts_dev_path}.0/$umts_tmp ] && cat ${umts_dev_path}.0/$umts_tmp 2>/dev/null done if [ ! -z "$UMTS_SWITCH" ] ; then umts_tmp=$(/usr/sbin/usb_modeswitch -D $UMTS_SWITCH) [ "$UMTS_DEBUG" = yes ] && echo "${umts_tmp}" umts_tmp=$(echo "${umts_tmp}" | grep "^ok:....:....$" | sed -e "s/ok:\(....\):\(....\)/\1.\2/g") [ ! -z "$umts_tmp" ] && umts_device=$umts_tmp : ${UMTS_DRV:=$(grep -i "$umts_device" /lib/modules/$(uname -r)/modules.alias | grep -Eo "(hso|option)")} fi if [ -z "$UMTS_DRV" ] ; then log_info "using 'usbserial' as driver" do_modprobe usbserial vendor=0x$umts_vend product=0x$umts_prod UMTS_DRV='usbserial' else log_info "using '$UMTS_DRV' as driver" do_modprobe $UMTS_DRV fi log_info "initialize device ..." sleep 1 } umts_search() { ### Suche Vendor-/ProduktIDs ################ eval umts_$1='$(grep -Eio "^$1.*($umts_prod|$umts_vend)" ${idx} | sort -r | grep -Eio "($umts_prod|$umts_vend)")' } ### UMTS-Adapter suchen ##################################### if [ "$UMTS_ADAPTER" != usbphone ] ; then do_modprobe_if_exists kernel\drivers\usb\host ohci_hcd sleep 1 for umts_dev in $(grep -HE "^(usb|pcmcia):" /sys/bus/*/devices/*/modalias | grep -Ev "/[0-9]+?\-0:" | sed -e "s#\(.*\)\.[0-9]/.*#\1#g" | sort -u) ; do umts_dev_path=${umts_dev%:*} umts_device=$(cat $umts_dev_path*/modalias| head -n 1 | sed -e "s/.*:.\(....\).\(....\).*/\1.\2/g") umts_vend=${umts_device%.*} umts_prod=${umts_device#*.} if [ -z "$UMTS_IDVENDOR" ] ; then UMTS_SWITCH='' UMTS_DRV='' ## Suche in "/etc/umts/umts_devices" ## umts_dev_found=$(grep -v "^#" /etc/umts/umts_devices | grep -i "^$umts_device") if [ ! -z "$umts_dev_found" ] ; then eval set -- $umts_dev_found UMTS_DRV=$3 umts_init break fi ## Suche usb_modeswitch Defaultdevice ## umts_dev_found=$(ls -1 /etc/usb_modeswitch.d | grep -i "^$umts_device") if [ ! -z "$umts_dev_found" ] ; then UMTS_SWITCH="-c /etc/usb_modeswitch.d/$umts_dev_found" umts_init break fi ## Suche usb_modeswitch Targetdevice (nach Reboot) ## for idx in $(grep -HEi "(prod|vend).*($umts_prod|$umts_vend)" /etc/usb_modeswitch.d/* | grep -v "%3A" | cut -d: -f-2 | sort -u) ; do umts_search target umts_search default umts_dev_found="$(echo $umts_target|grep -i "$umts_device")$(echo $umts_default|grep -i "$umts_device")" if [ ! -z "$(echo $umts_dev_found | grep -i "$umts_device")" ] ; then umts_init break fi umts_dev_found='' done [ -z "$umts_dev_found" ] || break else ## Vergleiche mit Daten aus config/umts.txt ## umts_dev_found=$(echo $UMTS_IDVENDOR $UMTS_IDDEVICE ":" $UMTS_IDVENDOR2 $UMTS_IDDEVICE2 | grep -io "$umts_device") if [ ! -z "$umts_dev_found" ] ; then umts_init break fi fi done fi ### USB-Mobiltelefon Kommunikation? ######################### if [ -z "$umts_dev_found" ] ; then do_modprobe_if_exists kernel\drivers\usb\class cdc-acm sleep 3 : ${UMTS_DEV:=$(find /sys/bus/usb/devices/* -follow -maxdepth 2 -name ttyACM*[0-9] | cut -d/ -f8)} UMTS_ADAPTER=usbphone ### vorzeitiger Programmabruch? ############################# if [ ! "$UMTS_DEV" = ttyACM0 ] ; then log_error "no UMTS hardware found" end_script return fi fi if [ "$UMTS_ADAPTER" != "usbphone" ] ; then case "$UMTS_DRV" in hso*) : ${UMTS_DEV:=$(grep -i modem $umts_dev_path*/tty/*/hsotype | cut -d/ -f8)} : ${UMTS_CTRL:=$(grep -i control $umts_dev_path*/tty/*/hsotype | cut -d/ -f8)} if [ -z "$UMTS_DEV" -a ! -z "UMTS_CTRL" ] ; then log_error "modem port is not enabled - see documentation" fi ;; option*|usbserial*) # usb_modeswitch_dispatcher --symlink-name Pfad v_id p_id # Pfad ok /bus/usb/devices/usb2/2-2/ 2-2 :1.0/ttyUSB0/tty/ttyUSB0 # Pfad nok /bus/usb/devices/usb1/1-1/1-1.3/1-1.3:1.0/ttyUSB0/tty/ttyUSB0 über hub # : ${UMTS_DEV:=$(echo $(grep -i interrupt $umts_dev_path*/ep_*/type | head -n 1 | # sed -e "s#\(.*\)/ep_[0-9][0-9]/.*#\1#g")/ttyUSB* | cut -d/ -f7)} : ${UMTS_DEV:=$(ls -d $(ls -d $umts_dev_path*/* | grep "$(grep -i interrupt $umts_dev_path*/ep_*/type | cut -d/ -f7 | sort | head -n1)" | cut -d/ -f-6)/ttyUSB* | grep ttyUSB | cut -d/ -f7)} : ${UMTS_CTRL:=$(ls -d $umts_dev_path*/ttyUSB* | cut -d/ -f7)} ;; serial_cs*) : ${UMTS_DEV:=$(ls -d $umts_dev_path*/tty/ttyS* | cut -d/ -f8 | sort | head -n1)} : ${UMTS_CTRL:=$(ls -d $umts_dev_path*/tty/ttyS* | cut -d/ -f8)} ;; *) log_error "device for driver '$UMTS_DRV' not found" log_error "please define device in configuration" ;; esac fi : ${UMTS_CTRL:="$UMTS_DEV"} ### vorzeitiger Programmabruch ? kein Modemanschluss ######## if [ -z "$UMTS_DEV" ] ; then log_error "no modem port to UMTS device found" if [ -z "$UMTS_CTRL" ] ; then log_error "no control port to UMTS device found" end_script return fi fi log_info "using device '/dev/$UMTS_DEV' as '/dev/gsmmodem'" for umts_tmp in `seq 1 10` ; do [ -c /dev/$UMTS_DEV ] && break sleep 1 done for j in $UMTS_CTRL ; do chat -t1 '' "AT" OK >/dev/$j >/var/run/umts.ctrl done if [ `grep -c "" /var/run/umts.ctrl` -gt 1 ] ; then grep -v $UMTS_DEV /var/run/umts.ctrl >/var/run/umts.ctrl1 mv /var/run/umts.ctrl1 /var/run/umts.ctrl fi ln -sf /dev/$UMTS_DEV /dev/gsmmodem UMTS_DEV=gsmmodem echo "$UMTS_DEV" >/var/run/umts.dev # ab hier UMTS Modem # if [ ! -z "$UMTS_DEV" ] ; then if [ "$UMTS_DRV" = serial_cs ] ; then if [ -e /sbin/setserial ] ; then /sbin/setserial /dev/$UMTS_DEV baud_base 460800 spd_warp low_latency else log_error "UMTS_ADAPTER='pcmcia' is not set in configuration" end_script return fi fi ### GPRS/UMTS-Modus setzen ################################## if [ "$UMTS_ADAPTER" != usbphone ] ; then if [ $UMTS_PIN != disabled ] ; then umts_chat -t2 "''" "AT+CPIN?" "READY-AT+CPIN=$UMTS_PIN-OK" UMTS_PIN='pin = $UMTS_PIN' else UMTS_PIN='' fi umts_chat -t1 "''" ATZ OK 'at_opsys?' OK umts_tmp=$? echo Status - $umts_tmp case $UMTS_GPRS_UMTS$umts_tmp in gprs0) umts_chat "''" 'at_opsys=0,2' OK ;; umts0) umts_chat "''" 'at_opsys=1,2' OK ;; gprs*) umts_chat "''" 'at\$nwrat=1,2' OK ;; umts*) umts_chat "''" 'at\$nwrat=2,2' OK ;; *) umts_chat -t3 "''" AT OK-AT-OK ;; esac ########################################################################### # Novatel command: # - AT$NWRAT=x,y # Benutze den Befehl, um mit dem Adapter nur GPRS oder UMTS oder Beide zu betreiben. # x = 0 (automatic), 1 (GPRS), 2 (3G/UMTS) mode # y = 0 (CS circuit switched mode), 1 (PS packet switched mode), 2 (automatic CS/PS) # So best is, if you want to set mode... use...: # GPRS only: AT$NWRAT=1,2 # 3G(UMTS) only: AT$NWRAT=2,2 # automatic mode: AT$NWRAT=0,2 ########################################################################### # Option AT_OPSYS? (Status abfragen) # at_opsys=0,2 (nur GPRS), at_opsys=1,2 (nur UMTS), # at_opsys=2,2 (eher GPRS), at_opsys=3,2 (eher UMTS). ########################################################################### fi log_info "sleeping (UMTS detection may take a while)" sleep 4 if [ "$UMTS_DEBUG" = yes ] ; then set | grep -i ^umts_ fi ### pppd einrichten ############################# cat </etc/chatscript_umts ABORT BUSY ABORT 'NO CARRIER' ABORT DELAYED ABORT VOICE ABORT 'NO DIALTONE' ABORT 'NO DIAL TONE' ABORT 'NO ANSWER' ABORT ERROR REPORT CONNECT TIMEOUT 3 '' ATZ OK 'AT+CGDCONT=1,"IP","$UMTS_APN"' SAY 'Calling $UMTS_APN\n' OK 'AT+CSQ' OK ATD$UMTS_DIALOUT TIMEOUT 30 CONNECT \d\c CHATEOF idle='' usepeerdns='' active_filter='' case ${DIALMODE}${UMTS_HUP_TIMEOUT} in autonever) mode=persist ;; *) if [ "$UMTS_FILTER" = yes ] ; then active_filter='precompiled-active-filter /etc/ppp/filter' fi mode=demand idle="idle $UMTS_HUP_TIMEOUT" ;; esac if [ $UMTS_USEPEERDNS = yes ] ; then usepeerdns='usepeerdns' fi echo "\"$UMTS_USER\" * \"$UMTS_PASSWD\" *" >>/etc/ppp/pap-secrets do_modprobe ppp_async do_modprobe ppp_synctty if [ $START_IMOND = yes ] ; then defaultroute='' # imond handles default route echo $DIALMODE >/var/run/pppoe.dialmode else defaultroute='defaultroute' echo auto >/var/run/pppoe.dialmode fi dev=pppoe >/var/run/pppoe.HUP mkdir -p /etc/ppp/peers mkdir -p /var/lock cat </etc/ppp/peers/circuit.$dev $usepeerdns /dev/$UMTS_DEV 460800 modem crtscts noipdefault noauth $defaultroute hide-password nodetach local $debug noaccomp noccp nobsdcomp nodeflate nopcomp novj novjccomp user "$UMTS_USER" holdoff 3 maxfail 0 $mode $idle lock connect '$chatprg -f /etc/chatscript_umts' ktune $active_filter EOF service-restart.sh 2 /usr/sbin/pppd call circuit.$dev & sleep 1 ip route del default dev ppp0 kill -1 `cat /var/run/ppp0.pid` 2>/dev/null times="$UMTS_TIMES" usepeerdns="$UMTS_USEPEERDNS" name="$UMTS_NAME" chargeint="$UMTS_CHARGEINT" case ${UMTS_HUP_TIMEOUT} in never) hup_timeout='0' ;; *) hup_timeout="$UMTS_HUP_TIMEOUT" ;; esac if [ -f /var/run/next_ppp_device ] ; then ppp_idx=`cat /var/run/next_ppp_device` else ppp_idx=0 fi phone='-' bandwidth='-1:-1' route='0.0.0.0/0' ip_up_events='yes' add_imond_entry if [ ! -f /var/run/netaliases.conf ] ; then >/var/run/netaliases.conf fi echo "net_dev_pppoe='ppp$ppp_idx'" >>/var/run/netaliases.conf echo "net_name_ppp$ppp_idx='pppoe'" >>/var/run/netaliases.conf echo $dev >/var/run/circuit-pppoe echo $usepeerdns >/var/run/pppoe.usepeerdns echo ppp$ppp_idx >/var/run/pppoe-device ppp_idx=`/usr/bin/expr $ppp_idx + 1` echo $ppp_idx >/var/run/next_ppp_device fi if [ "$OPT_SMS" = yes ] ; then mkdir -p ${SMS_FOLDER}/checked mkdir -p ${SMS_FOLDER}/incoming mkdir -p ${SMS_FOLDER}/outgoing if [ "$SMS_FOLDER_FAIL" = 'yes' ] ; then mkdir -p ${SMS_FOLDER}/failed SMS_FOLDER_FAIL="failed = ${SMS_FOLDER}/failed" else SMS_FOLDER_FAIL="" fi if [ "$SMS_FOLDER_SENT" = 'yes' ] ; then mkdir -p ${SMS_FOLDER}/sent SMS_FOLDER_SENT="sent = ${SMS_FOLDER}/sent" else SMS_FOLDER_SENT="" fi cat </etc/smsd.conf outgoing = ${SMS_FOLDER}/outgoing checked = ${SMS_FOLDER}/checked $SMS_FOLDER_FAIL incoming = ${SMS_FOLDER}/incoming $SMS_FOLDER_SEND logfile = /var/log/smsd.log loglevel = $SMS_LOGLEVEL EOF case "$UMTS_DRV" in hso*) cat <>/etc/smsd.conf devices = GSM1 [GSM1] device = /dev/$UMTS_CTRL incoming = $SMS_RECEIVER rtscts = off memory_start = 0 $UMTS_PIN EOF ;; *) cat <>/etc/smsd.conf devices = GSM2 [GSM2] device = /dev/`head -n1 /var/run/umts.ctrl` incoming = $SMS_RECEIVER memory_start = 0 rtscts = off $UMTS_PIN EOF ;; esac find /var/spool/sms -name '*.LOCK' -exec rm {} \; /usr/local/bin/smsd & fi set|grep -i -e "opt_sms" -e "^SMS_" >/var/run/sms.conf end_script fi