diff options
Diffstat (limited to 'recipes-core/multitech/config/chat_wrapper')
-rwxr-xr-x | recipes-core/multitech/config/chat_wrapper | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/recipes-core/multitech/config/chat_wrapper b/recipes-core/multitech/config/chat_wrapper index 04ea17f..8c2edcc 100755 --- a/recipes-core/multitech/config/chat_wrapper +++ b/recipes-core/multitech/config/chat_wrapper @@ -22,11 +22,15 @@ # On entry to this script, file descriptor 0 is the modem. # For ppp to work, stty must work on file descriptor 0. # If stty fails, so will ppp. +. /usr/libexec/ppp/wait_for_reset NAME=chat_wrapper CONFIG=/etc/default/${NAME} CHAT_WRAPPER_RECURSION=/run/chat_wrapper_recursion RQCMD="/usr/bin/radio-query ${RADIOOPTION}" + +: ${LOG:="/usr/bin/logger -t ${NAME} -p daemon.notice"} + function finish { ${LOG} "Launch:" "$@" @@ -48,7 +52,7 @@ function sanity if ! log=$(stty 2>&1) || ! [[ $($RQCMD --iccid) =~ $id ]] ; then ${LOG} "Modem has response issues, so see if we can try again" if ((${#log} > 0)); then - ${LOG} "stty error: $(log)" + ${LOG} "stty error: ${log}" fi array=( ) # our parent is PPID, which is pppd. Get the pppd @@ -80,7 +84,8 @@ function sanity # we will be sent a SIGHUP. Ignore it (:). trap : SIGHUP /usr/sbin/mts-io-sysfs store radio-reset 0 - sleep 5 + wait_for_reset + ${LOG} "Completed wait_for_reset" count=0 while ((count < 60)) ; do # Wait for radio-reset to get the modem responding @@ -89,9 +94,11 @@ function sanity for f in /run/lock/LCK..modem_at0 /run/lock/LCK..modem_at1 ; do if [[ -f $f ]] ; then mypid=$(cat $f) + mypid="${mypid#"${mypid%%[![:space:]]*}"}" + mypid="${mypid%"${mypid##*[![:space:]]}"}" ${LOG} "PPID is $PPID, pid is $mypid" # Remove the lock, if it belongs to our parent, pppd - if [ $mypid = $PPID ] ; then + if ((${#mypid} == 0)) || [[ $mypid = $PPID ]] ; then ${LOG} "match $mypid $PPID" sleep 60 rm -f $f @@ -127,9 +134,13 @@ WAITREG=0 : ${COPSWAIT:=10} : ${CFUNWAIT:=10} -: ${LOG:="/usr/bin/logger -t ${NAME} -p daemon.notice"} -${LOG} Timeout is $REGWAITTIME, execute "$@" +${LOG} Timeout is $REGWAITTIME, execute "$@" + +# Wait for udev to discover modem has been reset. + +wait_for_reset + ((i=$#)) chatscript="${!i}" @@ -150,7 +161,7 @@ if ((${#CONTEXT} == 0)) ; then finish "$@" # NOTREACHED fi -((CONTEXTNUM=${BASH_REMATCH[2]})) +CONTEXTNUM=${BASH_REMATCH[2]} # Make sure CFUN=1, in case the last pppd was aborted with it set to 0. ${LOG} "Verify CFUN=1" @@ -223,10 +234,11 @@ fi # For Quectel, address 0 is expressed as "0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0" Q0ADDR="0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0" +Q1ADDR="0.0.0.0" ADDRMATCH=1 if [[ $MADDR != $ADDR ]] ; then ADDRMATCH=0 - if [[ $MADDR = $Q0ADDR ]] ; then + if [[ $MADDR = $Q0ADDR ]] || [[ $MADDR = $Q1ADDR ]] ; then if [[ -z $ADDR ]] || [[ $ADDR = 0 ]] ; then ADDRMATCH=1 fi |