Advertisement
jfrog

create_hostless.sh

May 20th, 2022
769
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. ROOTER=/usr/lib/rooter
  4. ROOTER_LINK="/tmp/links"
  5.  
  6. log() {
  7.     logger -t "Create Hostless Connection" "$@"
  8. }
  9.  
  10. ifname1="ifname"
  11. if [ -e /etc/newstyle ]; then
  12.     ifname1="device"
  13. fi
  14.  
  15. handle_timeout(){
  16.     local wget_pid="$1"
  17.     local count=0
  18.     ps | grep -v grep | grep $wget_pid
  19.     res="$?"
  20.     while [ "$res" = 0 -a $count -lt "$((TIMEOUT))" ]; do
  21.         sleep 1
  22.         count=$((count+1))
  23.         ps | grep -v grep | grep $wget_pid
  24.         res="$?"
  25.     done
  26.  
  27.     if [ "$res" = 0 ]; then
  28.         log "Killing process on timeout"
  29.         kill "$wget_pid" 2> /dev/null
  30.         ps | grep -v grep | grep $wget_pid
  31.         res="$?"
  32.         if [ "$res" = 0 ]; then
  33.             log "Killing process on timeout"
  34.             kill -9 $wget_pid 2> /dev/null
  35.         fi
  36.     fi
  37. }
  38.  
  39. check_apn() {
  40.     IPVAR="IP"
  41.     local COMMPORT="/dev/ttyUSB"$CPORT
  42.     if [ -e /etc/nocops ]; then
  43.         echo "0" > /tmp/block
  44.     fi
  45.     ATCMDD="AT+CGDCONT=?"
  46.     OX=$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  47.  
  48.     [ "$PDPT" = "0" ] && PDPT=""
  49.     for PDP in "$PDPT" IPV4V6; do
  50.         if [[ "$(echo $OX | grep -o "$PDP")" ]]; then
  51.             IPVAR="$PDP"
  52.             break
  53.         fi
  54.     done
  55.  
  56.     uci set modem.modem$CURRMODEM.pdptype=$IPVAR
  57.     uci commit modem
  58.  
  59.     log "PDP Type selected in the Connection Profile: \"$PDPT\", active: \"$IPVAR\""
  60.  
  61.     if [ "$idV" = "12d1" ]; then
  62.         CFUNOFF="0"
  63.     else
  64.         CFUNOFF="4"
  65.     fi
  66.     ATCMDD="AT+CGDCONT?;+CFUN?"
  67.     OX=$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  68.     CGDCONT2=$(echo $OX | grep "+CGDCONT: 2,")
  69.     if [ -z "$CGDCONT2" ]; then
  70.         ATCMDD="AT+CGDCONT=2,\"$IPVAR\",\"ims\""
  71.         OXy=$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  72.     fi
  73.     CGDCONT=$(echo $OX | grep -o "$CID,[^,]\+,[^,]\+,[^,]\+,0,0,1")
  74.     IPCG=$(echo $CGDCONT | cut -d, -f4)
  75.     if [ "$CGDCONT" == "$CID,\"$IPVAR\",\"$NAPN\",$IPCG,0,0,1" ]; then
  76.         if [ -z "$(echo $OX | grep -o "+CFUN: 1")" ]; then
  77.             OX=$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "AT+CFUN=1")
  78.         fi
  79.     else
  80.         ATCMDD="AT+CGDCONT=$CID,\"$IPVAR\",\"$NAPN\",,0,0,1"
  81.         OX=$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  82.         OX=$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "AT+CFUN=$CFUNOFF")
  83.         OX=$($ROOTER/gcom/gcom-locked "$COMMPORT" "run-at.gcom" "$CURRMODEM" "AT+CFUN=1")
  84.         sleep 5
  85.     fi
  86. }
  87.  
  88. set_dns() {
  89.     local pDNS1=$(uci -q get modem.modeminfo$CURRMODEM.dns1)
  90.     local pDNS2=$(uci -q get modem.modeminfo$CURRMODEM.dns2)
  91.     local pDNS3=$(uci -q get modem.modeminfo$CURRMODEM.dns3)
  92.     local pDNS4=$(uci -q get modem.modeminfo$CURRMODEM.dns4)
  93.  
  94.     local aDNS="$pDNS1 $pDNS2 $pDNS3 $pDNS4"
  95.     local bDNS=""
  96.  
  97.     echo "$aDNS" | grep -o "[[:graph:]]" &>/dev/null
  98.     if [ $? = 0 ]; then
  99.         log "Using DNS settings from the Connection Profile"
  100.         pdns=1
  101.         for DNSV in $(echo "$aDNS"); do
  102.             if [ "$DNSV" != "0.0.0.0" ] && [ -z "$(echo "$bDNS" | grep -o "$DNSV")" ]; then
  103.                 [ -n "$(echo "$DNSV" | grep -o ":")" ] && continue
  104.                 bDNS="$bDNS $DNSV"
  105.             fi
  106.         done
  107.  
  108.         bDNS=$(echo $bDNS)
  109.         uci set network.wan$INTER.peerdns=0
  110.         uci set network.wan$INTER.dns="$bDNS"
  111.         echo "$bDNS" > /tmp/v4dns$INTER
  112.  
  113.         bDNS=""
  114.         for DNSV in $(echo "$aDNS"); do
  115.             if [ "$DNSV" != "0:0:0:0:0:0:0:0" ] && [ -z "$(echo "$bDNS" | grep -o "$DNSV")" ]; then
  116.                 [ -z "$(echo "$DNSV" | grep -o ":")" ] && continue
  117.                 bDNS="$bDNS $DNSV"
  118.             fi
  119.         done
  120.         echo "$bDNS" > /tmp/v6dns$INTER
  121.     else
  122.         log "Using Hostless Modem as a DNS relay"
  123.         pdns=0
  124.         rm -f /tmp/v[46]dns$INTER
  125.     fi
  126. }
  127.  
  128. set_network() {
  129.     uci delete network.wan$INTER
  130.     uci set network.wan$INTER=interface
  131.     uci set network.wan$INTER.proto=dhcp
  132.     uci set network.wan$INTER.${ifname1}=$1
  133.     uci set network.wan$INTER.metric=$INTER"0"
  134.     set_dns
  135.     uci commit network
  136.     sleep 5
  137. }
  138.  
  139. save_variables() {
  140.     echo 'MODSTART="'"$MODSTART"'"' > /tmp/variable.file
  141.     echo 'WWAN="'"$WWAN"'"' >> /tmp/variable.file
  142.     echo 'USBN="'"$USBN"'"' >> /tmp/variable.file
  143.     echo 'ETHN="'"$ETHN"'"' >> /tmp/variable.file
  144.     echo 'WDMN="'"$WDMN"'"' >> /tmp/variable.file
  145.     echo 'BASEPORT="'"$BASEPORT"'"' >> /tmp/variable.file
  146. }
  147.  
  148. chcklog() {
  149.     OOX=$1
  150.     CLOG=$(uci -q get modem.modeminfo$CURRMODEM.log)
  151.     if [ $CLOG = "1" ]; then
  152.         log "$OOX"
  153.     fi
  154. }
  155.  
  156. get_connect() {
  157.     NAPN=$(uci -q get modem.modeminfo$CURRMODEM.apn)
  158.     PDPT=$(uci -q get modem.modeminfo$CURRMODEM.pdptype)
  159.     uci set modem.modem$CURRMODEM.apn="$NAPN"
  160.     uci commit modem
  161. }
  162.  
  163. get_tty_fix() {
  164. # $1 is fixed ttyUSB or ttyACM port number
  165.     local POS
  166.     POS=`expr 1 + $1`
  167.     CPORT=$(echo "$TTYDEVS" | cut -d' ' -f"$POS" | grep -o "[[:digit:]]\+")
  168. }
  169.  
  170. get_ip() {
  171.     ATCMDD="AT+CGPIAF=1,1,1,0;+CGPADDR"
  172.     OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  173.     OX=$(echo "$OX" | grep "^+CGPADDR: $CID," | cut -d'"' -f2)
  174.     ip4=$(echo $OX | cut -d, -f1 | grep "\.")
  175.     ip6=$(echo $OX | cut -d, -f2 | grep ":")
  176.     log "IP address(es) obtained: $ip4 $ip6"
  177. }
  178.  
  179. check_ip() {
  180.     if [[ $(echo "$ip6" | grep -o "^[23]") ]]; then
  181.     # Global unicast IP acquired
  182.         v6cap=1
  183.     elif [[ $(echo "$ip6" | grep -o "^[0-9a-fA-F]\{1,4\}:") ]]; then
  184.     # non-routable address
  185.         v6cap=2
  186.     else
  187.         v6cap=0
  188.     fi
  189.  
  190.     if [ -n "$ip6" -a -z "$ip4" ]; then
  191.         log "Running IPv6-only mode"
  192.         nat46=1
  193.     fi
  194. }
  195.  
  196. addv6() {
  197.     . /lib/functions.sh
  198.     . /lib/netifd/netifd-proto.sh
  199.     local interface=wan$INTER
  200.     local zone="$(fw3 -q network "$interface" 2>/dev/null)"
  201.  
  202.     log "Adding IPv6 dynamic interface"
  203.     json_init
  204.     json_add_string name "${interface}_6"
  205.     json_add_string ${ifname1} "@$interface"
  206.     json_add_string proto "dhcpv6"
  207.     json_add_string extendprefix 1
  208.     [ -n "$zone" ] && json_add_string zone "$zone"
  209.     [ "$pdns" = 1 ] && json_add_boolean peerdns 0
  210.     [ "$nat46" = 1 ] || json_add_string iface_464xlat 0
  211.     proto_add_dynamic_defaults
  212.     json_close_object
  213.     ubus call network add_dynamic "$(json_dump)"
  214. }
  215.  
  216. CURRMODEM=$1
  217.  
  218. MAN=$(uci get modem.modem$CURRMODEM.manuf)
  219. MOD=$(uci get modem.modem$CURRMODEM.model)
  220. $ROOTER/signal/status.sh $CURRMODEM "$MAN $MOD" "Connecting"
  221. $ROOTER/log/logger "Attempting to Connect Modem #$CURRMODEM ($MAN $MOD)"
  222.  
  223. BASEP=$(uci -q get modem.modem$CURRMODEM.baseport)
  224. idV=$(uci get modem.modem$CURRMODEM.idV)
  225. idP=$(uci get modem.modem$CURRMODEM.idP)
  226. log " "
  227. log "Hostless ID $idV:$idP"
  228. log " "
  229.  
  230. MATCH="$(uci get modem.modem$CURRMODEM.maxcontrol | cut -d/ -f3- | xargs dirname)"
  231. OX=$(for a in /sys/class/tty/*; do readlink $a; done | grep "$MATCH" | tr '\n' ' ' | xargs -r -n1 basename)
  232. TTYDEVS=$(echo "$OX" | grep -o ttyUSB[0-9])
  233. if [ $? -ne 0 ]; then
  234.     TTYDEVS=$(echo "$OX" | grep -o ttyACM[0-9])
  235.     [ $? -eq 0 ] && ACM=1
  236. fi
  237. TTYDEVS=$(echo "$TTYDEVS" | tr '\n' ' ')
  238. TTYDEVS=$(echo $TTYDEVS)
  239. if [ -n "$TTYDEVS" ]; then
  240.     log Modem $CURRMODEM is a parent of $TTYDEVS
  241. else
  242.     log "No ECM Comm Port"
  243. fi
  244.  
  245. if [ $idV = 1546 -a $idP = 1146 ]; then
  246.     SP=1
  247. elif [ $idV = 19d2 -a $idP = 1476 ]; then
  248.     SP=2
  249. elif [ $idV = 1410 -a $idP = 9022 ]; then
  250.     SP=3
  251. elif [ $idV = 1410 -a $idP = 9032 ]; then
  252.     SP=3
  253. elif [ $idV = 2cb7 -o $idV = 1508 ]; then
  254.     log "Fibocom ECM"
  255.     SP=4
  256. elif [ $idV = 2c7c ]; then
  257.     SP=5
  258. elif [ $idV = 12d1 -a $idP = 15c1 ]; then
  259.     SP=6
  260. elif [ $idV = 2cd2 ]; then
  261.     log "MikroTik R11e ECM"
  262.     SP=7
  263. else
  264.     SP=0
  265. fi
  266.  
  267. log " "
  268. log "Modem Type $SP"
  269. log " "
  270. if [ $SP -gt 0 ]; then
  271.     if [ $SP -eq 3 ]; then
  272.         PORTN=0
  273.     elif [ $SP -eq 4 ]; then
  274.         PORTN=2
  275.     elif [ $SP -eq 5 ]; then
  276.         [ $idP = 6026 ] && PORTN=1 || PORTN=2
  277.     elif [ $SP -eq 6 ]; then
  278.         PORTN=2
  279.     elif [ $SP -eq 7 ]; then
  280.         PORTN=0
  281.     else
  282.         PORTN=1
  283.     fi
  284.     get_tty_fix $PORTN
  285.     lua $ROOTER/common/modemchk.lua "$idV" "$idP" "$CPORT" "$CPORT"
  286.     source /tmp/parmpass
  287.  
  288.     if [ "$ACM" = 1 ]; then
  289.         ACMPORT=$CPORT
  290.         CPORT="7$ACMPORT"
  291.         ln -fs /dev/ttyACM$ACMPORT /dev/ttyUSB$CPORT
  292.     fi
  293.  
  294.     log "Modem $CURRMODEM ECM Comm Port : /dev/ttyUSB$CPORT"
  295.     uci set modem.modem$CURRMODEM.commport=$CPORT
  296.     uci commit modem
  297.  
  298.     $ROOTER/sms/check_sms.sh $CURRMODEM &
  299.     $ROOTER/common/gettype.sh $CURRMODEM
  300.  
  301.     if [ -e $ROOTER/connect/preconnect.sh ]; then
  302.         $ROOTER/connect/preconnect.sh $CURRMODEM
  303.     fi
  304.  
  305.     if [ $SP = 5 ]; then
  306.         clck=$(uci -q get custom.bandlock.cenable)
  307.         if [ $clck = "1" ]; then
  308.             ear=$(uci -q get custom.bandlock.earfcn)
  309.             pc=$(uci -q get custom.bandlock.pci)
  310.             ear1=$(uci -q get custom.bandlock.earfcn1)
  311.             pc1=$(uci -q get custom.bandlock.pci1)
  312.             if [ $ear1 = "0" -o $pc1 = "0" ]; then
  313.                 earcnt="1,"$ear","$pc
  314.             else
  315.                 earcnt="2,"$ear","$pc","$ear1","$pc1
  316.             fi
  317.             ATCMDD="at+qnwlock=\"common/4g\""
  318.             OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  319.             if `echo $OX | grep "ERROR" 1>/dev/null 2>&1`
  320.         then
  321.             ATCMDD="at+qnwlock=\"common/lte\",2,$ear,$pc"
  322.         else
  323.             ATCMDD=$ATCMDD","$earcnt
  324.         fi
  325.             OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  326.             log "Cell Lock $OX"
  327.     fi
  328.  
  329.         $ROOTER/connect/bandmask $CURRMODEM 1
  330.         uci commit modem
  331.     fi
  332.     if [ $SP = 4 ]; then
  333.         if [ -e /etc/interwave ]; then
  334.             idP=$(uci -q get modem.modem$CURRMODEM.idP)
  335.             idPP=${idP:1:1}
  336.             if [ "$idPP" = "1" ]; then
  337.                 ATC="AT+GTRAT=17"
  338.             else
  339.                 ATC="AT+XACT=4,2"
  340.             fi
  341.             OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATC")
  342.         fi
  343.         $ROOTER/connect/bandmask $CURRMODEM 2
  344.         uci commit modem
  345.     fi
  346. fi
  347. $ROOTER/connect/get_profile.sh $CURRMODEM
  348. if [ -e $ROOTER/simlockc.sh ]; then
  349.     $ROOTER/simlockc.sh $CURRMODEM
  350. fi
  351. if [ -e /usr/lib/gps/gps.sh ]; then
  352.     /usr/lib/gps/gps.sh $CURRMODEM
  353. fi
  354.  
  355. INTER=$(uci get modem.modeminfo$CURRMODEM.inter)
  356. if [ -z $INTER ]; then
  357.     INTER=$CURRMODEM
  358. else
  359.     if [ $INTER = 0 ]; then
  360.         INTER=$CURRMODEM
  361.     fi
  362. fi
  363. log "Profile for Modem $CURRMODEM sets interface to WAN$INTER"
  364. OTHER=1
  365. if [ $CURRMODEM = 1 ]; then
  366.     OTHER=2
  367. fi
  368. EMPTY=$(uci get modem.modem$OTHER.empty)
  369. if [ $EMPTY = 0 ]; then
  370.     OINTER=$(uci get modem.modem$OTHER.inter)
  371.     if [ ! -z $OINTER ]; then
  372.         if [ $INTER = $OINTER ]; then
  373.             INTER=1
  374.             if [ $OINTER = 1 ]; then
  375.                 INTER=2
  376.             fi
  377.             log "Switched Modem $CURRMODEM to WAN$INTER as Modem $OTHER is using WAN$OINTER"
  378.         fi
  379.     fi
  380. fi
  381. uci set modem.modem$CURRMODEM.inter=$INTER
  382. uci commit modem
  383. log "Modem $CURRMODEM is using WAN$INTER"
  384.  
  385. if [ -s /tmp/wan$INTER.cid ]; then
  386.     CID=$(cat /tmp/wan$INTER.cid 2>/dev/null)
  387.     CID=$(echo $CID | grep -o "[[:digit:]]")
  388.     [ -n "$CID" ] && log "User selected PDP Context $CID"
  389. fi
  390.  
  391. [ -z "$CID" ] && CID=1
  392.  
  393. log "Checking Network Interface"
  394. ifname="$(if [ "$MATCH" ]; then for a in /sys/class/net/*; do readlink $a; done | grep "$MATCH"; fi | xargs -r basename)"
  395.  
  396. if [ "$ifname" ]; then
  397.     log "Modem $CURRMODEM ECM Data Port : $ifname"
  398.     set_network "$ifname"
  399.     uci set modem.modem$CURRMODEM.interface=$ifname
  400.     if [ -e $ROOTER/changedevice.sh ]; then
  401.         $ROOTER/changedevice.sh $ifname
  402.     fi
  403. else
  404.     log "Modem $CURRMODEM - No ECM Data Port found"
  405. fi
  406. uci commit modem
  407.  
  408. ttl=$(uci -q get modem.modeminfo$CURRMODEM.ttl)
  409. if [ -z "$ttl" ]; then
  410.     ttl="0"
  411. fi
  412. hostless=$(uci -q get modem.modeminfo$CURRMODEM.hostless)
  413. if [ "$ttl" != "0" -a "$ttl" != "1" -a "$ttl" != "TTL-INC 1" -a "$hostless" = "1" ]; then
  414.     let "ttl=$ttl+1"
  415. fi
  416. $ROOTER/connect/handlettl.sh $CURRMODEM "$ttl"
  417.  
  418. if [ $SP -eq 2 ]; then
  419.     get_connect
  420.     export SETAPN=$NAPN
  421.     BRK=1
  422.  
  423.     while [ $BRK -eq 1 ]; do
  424.         OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "connect-zecm.gcom" "$CURRMODEM")
  425.         chcklog "$OX"
  426.         ERROR="ERROR"
  427.         if `echo ${OX} | grep "${ERROR}" 1>/dev/null 2>&1`
  428.         then
  429.             $ROOTER/signal/status.sh $CURRMODEM "$MAN $MOD" "Failed to Connect : Retrying"
  430.         else
  431.             BRK=0
  432.         fi
  433.     done
  434. fi
  435.  
  436. if [ $SP -eq 4 ]; then
  437.     get_connect
  438.     export SETAPN=$NAPN
  439.     BRK=1
  440.  
  441.     while [ $BRK -eq 1 ]; do
  442.         OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "connect-fecm.gcom" "$CURRMODEM")
  443.         chcklog "$OX"
  444.         log " "
  445.         log "Fibocom Connect : $OX"
  446.         log " "
  447.         ERROR="ERROR"
  448.         if `echo ${OX} | grep "${ERROR}" 1>/dev/null 2>&1`
  449.         then
  450.             $ROOTER/signal/status.sh $CURRMODEM "$MAN $MOD" "Failed to Connect : Retrying"
  451.         else
  452.             BRK=0
  453.             get_ip
  454.         fi
  455.     done
  456. fi
  457.  
  458. if [ $SP = 5 ]; then
  459.     get_connect
  460.     if [ -n "$NAPN" ]; then
  461.         $ROOTER/common/lockchk.sh $CURRMODEM
  462.         if [ $idP = 6026 ]; then
  463.             IPN=1
  464.             case "$PDPT" in
  465.             "IPV6" )
  466.                 IPN=2
  467.                 ;;
  468.             "IPV4V6" )
  469.                 IPN=3
  470.                 ;;
  471.             esac
  472.             ATCMDD="AT+QICSGP=$CID,$IPN,\"$NAPN\""
  473.             OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  474.             ATCMDD="AT+QNETDEVCTL=2,$CID,1"
  475.             OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  476.         else
  477.             check_apn
  478.         fi
  479.     fi
  480.     ATCMDD="AT+CNMI?"
  481.     OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  482.     if `echo $OX | grep -o "+CNMI: [0-3],2," >/dev/null 2>&1`; then
  483.         ATCMDD="AT+CNMI=0,0,0,0,0"
  484.         OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  485.     fi
  486.     ATCMDD="AT+QINDCFG=\"smsincoming\""
  487.     OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  488.     if `echo $OX | grep -o ",1" >/dev/null 2>&1`; then
  489.         ATCMDD="AT+QINDCFG=\"smsincoming\",0,1"
  490.         OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  491.     fi
  492.     ATCMDD="AT+QINDCFG=\"all\""
  493.     OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  494.     if `echo $OX | grep -o ",1" >/dev/null 2>&1`; then
  495.         ATCMDD="AT+QINDCFG=\"all\",0,1"
  496.         OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  497.     fi
  498.     log "Quectel Unsolicited Responses Disabled"
  499.     $ROOTER/luci/celltype.sh $CURRMODEM
  500.     ATCMDD="AT+QINDCFG=\"all\",1"
  501.     OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  502.  
  503.     get_ip
  504.     if [ -n "$ip6" ]; then
  505.         check_ip
  506.         if [ "$v6cap" -gt 0 ]; then
  507.             addv6
  508.         fi
  509.     fi
  510. fi
  511.  
  512. if [ $SP -eq 6 ]; then
  513.     get_connect
  514.     export SETAPN=$NAPN
  515.     BRK=1
  516.  
  517.     while [ $BRK -eq 1 ]; do
  518.         OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "connect-ncm.gcom" "$CURRMODEM")
  519.         chcklog "$OX"
  520.         ERROR="ERROR"
  521.         if `echo ${OX} | grep "${ERROR}" 1>/dev/null 2>&1`
  522.         then
  523.             $ROOTER/signal/status.sh $CURRMODEM "$MAN $MOD" "Failed to Connect : Retrying"
  524.         else
  525.             BRK=0
  526.         fi
  527.     done
  528. fi
  529.  
  530. if [ $SP -eq 7 ]; then
  531.     get_connect
  532.     export SETAPN=$NAPN
  533.     BRK=1
  534.  
  535.     if [ -n "$NAPN" ]; then
  536.         check_apn
  537.     fi
  538.  
  539.     while [ $BRK -eq 1 ]; do
  540.         ATCMDD="AT\$ECMCALL=1"
  541.         OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  542.         chcklog "$OX"
  543.         ERROR="ERROR"
  544.         if `echo ${OX} | grep "${ERROR}" 1>/dev/null 2>&1`
  545.         then
  546.             $ROOTER/signal/status.sh $CURRMODEM "$MAN $MOD" "Failed to Connect : Retrying"
  547.         else
  548.             BRK=0
  549.             get_ip
  550.             if [ -n "$ip6" ]; then
  551.                 check_ip
  552.                 if [ "$v6cap" -gt 0 ]; then
  553.                     addv6
  554.                 fi
  555.             fi
  556.         fi
  557.     done
  558. fi
  559.  
  560. rm -f /tmp/usbwait
  561.  
  562. ifup wan$INTER
  563. while `ifstatus wan$INTER | grep -q '"up": false\|"pending": true'`; do
  564.     sleep 1
  565. done
  566. wan_ip=$(expr "`ifstatus wan$INTER | grep '"nexthop":'`" : '.*"nexthop": "\(.*\)"')
  567. if [ $? -ne 0 ] ; then
  568.     wan_ip=192.168.0.1
  569. fi
  570. uci set modem.modem$CURRMODEM.ip=$wan_ip
  571. uci commit modem
  572.  
  573. $ROOTER/log/logger "HostlessModem #$CURRMODEM Connected with IP $wan_ip"
  574.  
  575. PROT=5
  576.  
  577. if [ $SP -gt 1 ]; then
  578.     ln -s $ROOTER/signal/modemsignal.sh $ROOTER_LINK/getsignal$CURRMODEM
  579.     $ROOTER_LINK/getsignal$CURRMODEM $CURRMODEM $PROT &
  580. else
  581.     VENDOR=$(uci get modem.modem$CURRMODEM.idV)
  582.     case $VENDOR in
  583.     "19d2" )
  584.         TIMEOUT=3
  585.         wget -O /tmp/connect.file http://$wan_ip/goform/goform_set_cmd_process?goformId=CONNECT_NETWORK &
  586.         handle_timeout "$!"
  587.         ln -s $ROOTER/signal/ztehostless.sh $ROOTER_LINK/getsignal$CURRMODEM
  588.         $ROOTER_LINK/getsignal$CURRMODEM $CURRMODEM $PROT &
  589.         ;;
  590.     "12d1" )
  591.         log "Huawei Hostless"
  592.         ln -s $ROOTER/signal/huaweihostless.sh $ROOTER_LINK/getsignal$CURRMODEM
  593.         $ROOTER_LINK/getsignal$CURRMODEM $CURRMODEM $PROT &
  594.         ;;
  595.     * )
  596.         log "Other Hostless"
  597.         ln -s $ROOTER/signal/otherhostless.sh $ROOTER_LINK/getsignal$CURRMODEM
  598.         $ROOTER_LINK/getsignal$CURRMODEM $CURRMODEM $PROT &
  599.         ;;
  600. esac
  601. fi
  602.  
  603. ln -s $ROOTER/connect/conmon.sh $ROOTER_LINK/con_monitor$CURRMODEM
  604. $ROOTER_LINK/con_monitor$CURRMODEM $CURRMODEM &
  605. uci set modem.modem$CURRMODEM.connected=1
  606. uci commit modem
  607.  
  608. if [ $SP -gt 0 ]; then
  609.     if [ -e $ROOTER/connect/postconnect.sh ]; then
  610.         $ROOTER/connect/postconnect.sh $CURRMODEM
  611.     fi
  612.     if [ $(uci -q get modem.modeminfo$CURRMODEM.at) -eq "1" ]; then
  613.         ATCMDD=$(uci -q get modem.modeminfo$CURRMODEM.atc)
  614.         if [ -n "$ATCMDD" ]; then
  615.             OX=$($ROOTER/gcom/gcom-locked "/dev/ttyUSB$CPORT" "run-at.gcom" "$CURRMODEM" "$ATCMDD")
  616.             OX=$($ROOTER/common/processat.sh "$OX")
  617.             ERROR="ERROR"
  618.             if `echo $OX | grep "$ERROR" 1>/dev/null 2>&1`
  619.             then
  620.                 log "Error sending custom AT command: $ATCMDD with result: $OX"
  621.             else
  622.                 log "Sent custom AT command: $ATCMDD with result: $OX"
  623.             fi
  624.         fi
  625.     fi
  626.  
  627.     if [ -e $ROOTER/timezone.sh ]; then
  628.         TZ=$(uci -q get modem.modeminfo$CURRMODEM.tzone)
  629.         if [ "$TZ" = "1" ]; then
  630.             log "Set TimeZone"
  631.             $ROOTER/timezone.sh &
  632.         fi
  633.     fi
  634. fi
  635.  
  636. CLB=$(uci -q get modem.modeminfo$CURRMODEM.lb)
  637. if [ -e /etc/config/mwan3 ]; then
  638.     ENB=$(uci -q get mwan3.wan$INTER.enabled)
  639.     if [ ! -z $ENB ]; then
  640.         if [ $CLB = "1" ]; then
  641.             uci set mwan3.wan$INTER.enabled=1
  642.         else
  643.             uci set mwan3.wan$INTER.enabled=0
  644.         fi
  645.         uci commit mwan3
  646.         /usr/sbin/mwan3 restart
  647.     fi
  648. fi
Advertisement
RAW Paste Data Copied
Advertisement