gen_modem_init_string 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. #Barry Kauler LGPL 2007
  3. #called from /usr/sbin/modemtest
  4. #the idea is to probe modem and determine a suitable hayes command init string.
  5. [ ! -e /dev/modem ] && exit
  6. modem_stats_func() {
  7. #modem-stats has a serious bug, if return string not 'OK' then it never terminates.
  8. local CNTLP=1
  9. rm -f /tmp/modemstatsret
  10. modem-stats $@ >/tmp/modemstatsret &
  11. MPID=$!
  12. while [ 1 ];do
  13. sleep 1
  14. [ "`grep '^[A-Z].*' /tmp/modemstatsret`" != "" ] && break
  15. [ $CNTLP -gt 5 ] && break
  16. CNTLP=`expr $CNTLP + 1`
  17. done
  18. #may need a bit more time to receive all returns from modem...
  19. [ "`grep -E '^OK|^ERROR' /tmp/modemstatsret`" = "" ] && sleep 1
  20. kill $MPID > /dev/null 2>&1
  21. cat /tmp/modemstatsret
  22. }
  23. [ "`modem_stats_func -c 'ATZ' /dev/modem | grep '^OK$'`" = "" ] && exit
  24. ALLSTR=""
  25. for ONESTEP in 'Q0V1E1' 'Z' 'S0=0' '&C1' '&D2' 'S11=55' '+FCLASS=0'
  26. do
  27. if [ "`modem_stats_func -c "AT$ONESTEP" /dev/modem | grep '^OK$'`" = "" ];then
  28. modem_stats_func -c 'ATZ' /dev/modem #maybe wise to reset modem.
  29. continue
  30. fi
  31. [ "$ONESTEP" = "Z" ] && continue
  32. ALLSTR="$ALLSTR$ONESTEP"
  33. done
  34. #NO, the problem with country codes is there does not seem to be one standard.
  35. #the codes differ, also Hayes command for querying the current code differs,
  36. #also some modems are hardwired for a particular country and will not accept
  37. #any country code.
  38. ##country code...
  39. SETCOUNTRY=""
  40. #But, some firmware scripts in /etc/init.d/ do write a country string to
  41. #/etc/countryinfo...
  42. if [ -f /etc/countryinfo ];then
  43. . /etc/countryinfo
  44. if [ "$MODEM_COUNTRY_STRING" ];then
  45. SETCOUNTRY="`echo -n "$MODEM_COUNTRY_STRING" | sed -e 's/^AT/ /'`"
  46. fi
  47. fi
  48. echo -n "AT$ALLSTR$SETCOUNTRY" > /tmp/mymodeminitstring
  49. ###END###