#! /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 ### ### %35 -> # ### %3A -> : ### %3D -> = ### %3F -> ? ln -sf $idx "$(echo $idx | sed -e "s/%3A/:/g;s/%3D/=/g;s/%3F/?/g;s/%35/#/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_CTRL /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 fi grep -E "(option|hso|sierra)" /lib/modules/$(uname -r)/modules.alias| sed -e "s/*/.*/g" -e "s/.* \(.*\) \(.*\)/\/\1\/s\/$\/ \2\/p/g" > /tmp/usb_find.$$ : ${UMTS_DRV:=$(sed -n -f /tmp/usb_find.$$ $(grep -lE "^(usb|pcmcia):" /sys/bus/*/devices/*/modalias)| grep -i "$umts_device"|grep -Eo "(hso|option|sierra)" | head -n 1)} rm /tmp/usb_find.$$ if [ -z "$UMTS_DRV" ] then log_info "UMTS: using 'usbserial' as driver" do_modprobe usbserial vendor=0x$umts_vend product=0x$umts_prod UMTS_DRV='usbserial' UMTS_REAL_DRV=$UMTS_DRV else log_info "UMTS: using '$UMTS_DRV' as driver" do_modprobe $UMTS_DRV UMTS_REAL_DRV=$UMTS_DRV # treat sierra and option as usbserial by the remaining code case $UMTS_DRV in option|sierra) UMTS_DRV='usbserial' ;; esac fi log_info "UMTS: 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="-v $umts_vend -p $umts_prod -s 30 -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 | sort | head -n1)} UMTS_ADAPTER=usbphone ### vorzeitiger Programmabruch? ############################# if [ ! "$UMTS_DEV" = ttyACM0 ] then log_error "UMTS: usbphone: no UMTS hardware found as ttyACM0 is missing" UMTS_DEV= 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 | sort | head -n1)} : ${UMTS_CTRL:=$(grep -i control $umts_dev_path*/tty/*/hsotype | cut -d/ -f8)} if [ -z "$UMTS_DEV" -a -n "UMTS_CTRL" ] then log_error "UMTS: hso: modem port is not enabled - see documentation" fi ;; 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)} int_endpoints=$(grep -i interrupt $umts_dev_path*/ep_*/type | cut -d/ -f7) if [ -n "$int_endpoints" ] then for ep in $int_endpoints do : ${UMTS_DEV:=$(ls -d $umts_dev_path*/$ep/../ttyUSB* 2>/dev/null | cut -d/ -f9 | sort | head -n1)} [ -n "$UMTS_DEV" ] && break done else : ${UMTS_DEV:=$(ls -d $umts_dev_path*/ttyUSB* | cut -d/ -f7 | sort | head -n1)} fi : ${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 "UMTS: device for driver '$UMTS_DRV' not found" log_error "UMTS: please define device in configuration" ;; esac fi : ${UMTS_CTRL:="$UMTS_DEV"} # find control port to use >/var/run/umts.ctrl for j in $UMTS_CTRL do chat -t1 '' "AT" OK >/dev/$j >/var/run/umts.ctrl done if [ -n "$UMTS_DEV" -a $(wc -l < /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 # Sierra has the anomality that the _last_ answering device is the control # port, not the _first_ one... case $UMTS_REAL_DRV in sierra) UMTS_CTRL=$(tail -n1 /var/run/umts.ctrl) ;; *) UMTS_CTRL=$(head -n1 /var/run/umts.ctrl) ;; esac ### vorzeitiger Programmabruch ? kein Modemanschluss ######## if [ -z "$UMTS_CTRL" ] then log_error "UMTS: no control port of UMTS device found" else log_info "UMTS: using device '/dev/$UMTS_CTRL' as control port" # ab hier UMTS Modem # if [ -z "$UMTS_DEV" ] then log_error "UMTS: no modem port of UMTS device found" else for umts_tmp in `seq 1 10` do [ -c /dev/$UMTS_DEV ] && break sleep 1 done if [ ! -c /dev/$UMTS_DEV ] then log_error "UMTS: modem port '/dev/$UMTS_DEV' does not exist" elif [ "$UMTS_DRV" = serial_cs ] && ! type -p setserial >/dev/null then log_error "UMTS: UMTS_ADAPTER='pcmcia' is not set in configuration" else log_info "UMTS: using device '/dev/$UMTS_DEV' as modem port" ln -sf /dev/$UMTS_DEV /dev/gsmmodem UMTS_DEV=gsmmodem echo "$UMTS_DEV" >/var/run/umts.dev if [ "$UMTS_DRV" = serial_cs ] then setserial /dev/$UMTS_DEV baud_base 460800 spd_warp low_latency fi ### GPRS/UMTS-Modus setzen ################################## if [ "$UMTS_ADAPTER" != usbphone ] then if [ $UMTS_PIN != disabled ] then # the APU requires to select the SIM slot to use even if only one slot is # available... umts_chat "''" "AT+CFUN=1,0" OK umts_chat -t2 "''" "AT+CPIN?" "READY-AT+CPIN=$UMTS_PIN-OK" fi umts_chat -t1 "''" ATZ OK 'at_opsys?' OK umts_tmp=$? log_info "UMTS: OPSYS 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 "UMTS: sleeping (UMTS detection may take a while)" sleep 4 if [ "$UMTS_DEBUG" = yes ] then set | grep -i ^umts_ | sed "s/^UMTS_PIN=.*/UMTS_PIN='XXXX'/" 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='' local=10.112.112.112 remote=10.112.112.113 case ${DIALMODE}${UMTS_HUP_TIMEOUT} in autonever) mode=persist ;; *) if [ "$UMTS_FILTER" = yes ] then active_filter=$(ppp_filter_get) [ -n "$active_filter" ] && active_filter="active-filter \"$active_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 $local:$remote ipcp-accept-remote ipcp-accept-local $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 fi if [ "$OPT_SMS" = yes ] then map2persistent SMS_FOLDER /sms map2persistent SMS_LOGFILE /smsd.log 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 if [ $UMTS_PIN != disabled ] then UMTS_PIN="pin = $UMTS_PIN" else UMTS_PIN= fi cat </etc/smsd.conf outgoing = ${SMS_FOLDER}/outgoing checked = ${SMS_FOLDER}/checked $SMS_FOLDER_FAIL incoming = ${SMS_FOLDER}/incoming $SMS_FOLDER_SEND logfile = $SMS_LOGFILE loglevel = $SMS_LOGLEVEL devices = GSM [GSM] device = /dev/$UMTS_CTRL incoming = $SMS_RECEIVER rtscts = off memory_start = 0 $UMTS_PIN EOF [ -d /var/spool/sms ] && find /var/spool/sms -name '*.LOCK' -exec rm {} \; smsd & fi set|grep -i -e "opt_sms" -e "^SMS_" >/var/run/sms.conf fi end_script fi