Guest User

Untitled

a guest
Mar 1st, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. modem_log()
  4. {
  5. /bin/echo -e "${@}" >> /smodem/ppp.temp.log
  6. }
  7.  
  8. /bin/echo "${$}" > /smodem/setupmodem.pid
  9.  
  10. SLEEPY="1"
  11.  
  12. # Set maximum number of failed attempts here:
  13. MAXFAIL="4"
  14.  
  15. if [ ! -e /smodem/num.loops.log ]; then
  16. /bin/echo "1" > /smodem/num.loops.log
  17. else
  18. NUMLOOPS="`/bin/cat /smodem/num.loops.log`"
  19. /bin/echo "$((NUMLOOPS+1))" > /smodem/num.loops.log
  20. fi
  21.  
  22. APN=`/bin/grep "ppp.apn=" /proc/cmdline | /bin/sed -e "s/^.*ppp\.apn=([^ ]*) .*$/\1/"`
  23.  
  24. if [ ! -e /smodem/ppp.log ]; then
  25. /bin/echo ""
  26. /bin/echo "Initialising Modem:"
  27. /bin/echo "==================="
  28. /bin/echo ""
  29. modem_log "Modem initialization started"
  30. /system/bin/setprop ro.radio.use-ppp no
  31. /system/bin/setprop ro.config.nocheckin yes
  32. PPPUSER=`/bin/grep "ppp.username=.*" /proc/cmdline | /bin/sed -e "s/^.*ppp\.username=([^ ]*) .*$/\1/"`
  33. PPPPASS=`/bin/grep "ppp.password=.*" /proc/cmdline | /bin/sed -e "s/^.*ppp\.password=([^ ]*) .*$/\1/"`
  34. /bin/echo "$PPPUSER * $PPPPASS" > /etc/ppp/pap-secrets
  35. /bin/echo "$PPPUSER * $PPPPASS" > /etc/ppp/chap-secrets
  36. /bin/grep -v "^name " /etc/ppp/options.smd1 | /bin/sed '$a'"name \"$PPPUSER\"" > /etc/ppp/options.smd1
  37. /bin/echo "Username=$PPPUSER"
  38. /bin/echo "Password=$PPPPASS"
  39. /bin/echo "APN=$APN"
  40. /bin/echo ""
  41. /bin/echo "off" > /smodem/ppp.stat
  42. /bin/echo "0" > /smodem/num.fail.log
  43. modem_log "Modem initialization completed"
  44. SLEEPY="1"
  45. elif [ "`/bin/cat /smodem/ppp.stat`" = "on" ]; then
  46. if [ "`/bin/ifconfig | /bin/grep ^ppp0`" = "" ]; then
  47. # Turn on ppp connection
  48. NUMATTEMPT="`/bin/cat /smodem/num.fail.log`"
  49. NUMATTEMPT="$((NUMATTEMPT+1))"
  50. modem_log "Connection attempt ${NUMATTEMPT}..."
  51. if [ -e /sys/class/vogue_hw/gsmphone ] ; then
  52. /bin/echo -e "AT+CGDCONT=1,\"IP\",\"$APN\",,0,0\r" > /dev/smd0
  53. /bin/sleep 2
  54. /bin/echo -e "ATD*99***1#\r" > /dev/smd0
  55. /bin/sleep 4
  56. else
  57. /bin/cat /initmodem1 > /dev/smd0
  58. /bin/sleep 2
  59. /bin/cat /initmodem2 > /dev/smd0
  60. /bin/sleep 4
  61. fi
  62. /bin/pppd /dev/smd1
  63. TIMEOUT=20
  64. while [ "`/bin/ifconfig | /bin/grep ^ppp0`" = "" -a ! "$TIMEOUT" = "0" ] ; do
  65. /bin/echo "Waiting for ppp"
  66. TIMEOUT=`/bin/expr $TIMEOUT - 1`
  67. /bin/sleep 1
  68. done
  69. if [ "`/bin/ifconfig | /bin/grep ^ppp0`" = "" ]; then
  70. modem_log "Connection attempt FAILED!"
  71. NUMFAIL="`/bin/cat /smodem/num.fail.log`"
  72. /bin/echo "$((NUMFAIL+1))" > /smodem/num.fail.log
  73. SLEEPY="0"
  74. else
  75. modem_log "Connection attempt SUCCESSFUL!"
  76. modem_log "Phone IP: `/bin/ifconfig ppp0 | /bin/grep 'inet addr:' | /bin/cut -d':' -f2 | /bin/cut -d' ' -f1`"
  77. modem_log "Subnet : `/bin/ifconfig ppp0 | /bin/grep 'inet addr:' | /bin/cut -d':' -f4 | /bin/cut -d' ' -f1`"
  78. modem_log "P-t-P : `/bin/ifconfig ppp0 | /bin/grep 'inet addr:' | /bin/cut -d':' -f3 | /bin/cut -d' ' -f1`"
  79. /bin/echo "0" > /smodem/num.fail.log
  80. SLEEPY="1"
  81. fi
  82.  
  83. if [ "`/bin/cat /smodem/num.fail.log`" -ge "$MAXFAIL" ]; then
  84. modem_log "Connection attempts have failed too many times!"
  85. modem_log "Giving up on connection..."
  86. /bin/echo "0" > /smodem/num.fail.log
  87. /bin/echo "off" > /smodem/ppp.stat
  88. SLEEPY="1"
  89. fi
  90.  
  91. else
  92. modem_log "Already connected"
  93. modem_log "Stopping further attempts..."
  94. /bin/echo "0" > /smodem/num.fail.log
  95. SLEEPY="1"
  96. fi
  97. elif [ "`/bin/cat /smodem/ppp.stat`" = "off" ]; then
  98. if [ "`/bin/ifconfig | /bin/grep ^ppp0`" = "" ]; then
  99. modem_log "Connection is already terminated!"
  100. modem_log "Stopping further attempts..."
  101. /bin/echo "0" > /smodem/num.fail.log
  102. SLEEPY="1"
  103. else
  104. # Turn off connection
  105. NUMATTEMPT="`/bin/cat /smodem/num.fail.log`"
  106. NUMATTEMPT="$((NUMATTEMPT+1))"
  107. modem_log "Termination attempt ${NUMATTEMPT}..."
  108. /system/bin/ps | /bin/grep "pppd" | /bin/sed "s/ */ /g" | /bin/cut -d' ' -f2 | /bin/xargs /bin/kill
  109. /bin/echo -e "ATH\r" > /dev/smd0
  110. /bin/sleep 2
  111. if [ "`/bin/ifconfig | /bin/grep ^ppp0`" != "" ]; then
  112. modem_log "Termination attempt FAILED!"
  113. NUMFAIL="`/bin/cat /smodem/num.fail.log`"
  114. /bin/echo "$((NUMFAIL+1))" > /smodem/num.fail.log
  115. SLEEPY="0"
  116. else
  117. modem_log "Termination attempt SUCCESSFUL!"
  118. modem_log "ppp0 connection is down"
  119. /bin/echo "0" > /smodem/num.fail.log
  120. SLEEPY="1"
  121. fi
  122.  
  123. if [ "`/bin/cat /smodem/num.fail.log`" -ge "$MAXFAIL" ]; then
  124. modem_log "Termination attempts have failed too many times!"
  125. modem_log "Giving up on terminating connection..."
  126. /bin/echo "0" > /smodem/num.fail.log
  127. /bin/echo "on" > /smodem/ppp.stat
  128. SLEEPY="1"
  129. fi
  130.  
  131. fi
  132. else
  133. modem_log "Invalid ppp.on contents!"
  134. modem_log "Aborting further actions..."
  135. SLEEPY="1"
  136. fi
  137.  
  138. if [ "$SLEEPY" = "1" ]; then
  139. modem_log "Done!"
  140. /bin/cat /smodem/ppp.temp.log >> /smodem/ppp.log
  141. rm /smodem/setupmodem.pid
  142. /smodem/sleep.sh
  143. rm /smodem/sleep.pid
  144. fi
Add Comment
Please, Sign In to add comment