Advertisement
Guest User

Untitled

a guest
May 13th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. set_3g_led() {
  2. # set on WRT54G3G only
  3. [ -d /proc/diag ] || return 0
  4. grep WRT54G3G /proc/diag/model >/dev/null || return 0
  5. echo "$1" > /proc/diag/led/3g_green
  6. echo "$2" > /proc/diag/led/3g_blue
  7. echo "$3" > /proc/diag/led/3g_blink
  8. }
  9.  
  10. scan_3g() {
  11. local device
  12.  
  13. scan_ppp "$@"
  14. config_get device "$1" device
  15.  
  16. # enable 3G with the 3G button by default
  17. config_get button "$1" button
  18. [ -z "$button" ] && {
  19. config_set "$1" button 1
  20. }
  21. }
  22.  
  23. stop_interface_3g() {
  24. set_3g_led 0 0 0
  25.  
  26. if ifconfig hso0 2>&- >&- ; then
  27. /usr/bin/gcom -d "/dev/ttyHS0" -s /etc/gcom/hso-disconnect.gcom
  28. env -i ACTION="ifdown" INTERFACE="wan" DEVICE="hso0" PROTO=hso /sbin/hotplug-call "iface"
  29. ifconfig hso0 down
  30.  
  31. # remove the interface's network state
  32. uci_revert_state network "wan"
  33. fi
  34. }
  35.  
  36. setup_interface_3g() {
  37. local iface="$1"
  38. local config="$2"
  39.  
  40. config_get device "$config" device
  41. config_get maxwait "$config" maxwait
  42. maxwait=${maxwait:-20}
  43. while [ ! -e "$device" -a $maxwait -gt 0 ];do # wait for driver loading to catch up
  44. maxwait=$(($maxwait - 1))
  45. sleep 1
  46. done
  47.  
  48. config_get apn "$config" apn
  49. config_get service "$config" service
  50. config_get pincode "$config" pincode
  51. config_get mtu "$config" mtu
  52. config_get password "$config" password
  53. config_get username "$config" username
  54.  
  55. case "$service" in
  56. cdma|gprs*) ledcode="1 0";;
  57. evdo|umts*) ledcode="0 1";;
  58. *) ledcode="0 0";; #shouldn't happen
  59. esac
  60.  
  61. set_3g_led $ledcode 1
  62.  
  63. #Check to see if it is an HSO or a regular USB device
  64. if grep "Vendor=0af0" < /proc/bus/usb/devices 2>&- >&- ; then
  65.  
  66. for module in rfkill hso; do
  67. /sbin/insmod $module 2>&- >&-
  68. done
  69.  
  70. RESOLV_CONF="/tmp/resolv.conf.auto"
  71. DATA=$(USE_PASS="$password" USE_USER="$username" USE_APN="$apn" SERVICE="$service" PINCODE="$pincode" /usr/bin/gcom -d "$device" -s /etc/gcom/hso-connect.gcom)
  72. DATA=$(echo $DATA | tr -d " " | grep -v ^$)
  73. IP=$(echo $DATA | cut -d , -f 2)
  74. DNS1=$(echo $DATA | cut -d , -f 4)
  75. DNS2=$(echo $DATA | cut -d , -f 5)
  76. ifconfig hso0 $IP netmask 255.255.255.255 up
  77. route add default dev hso0
  78. uci_set_state network "wan" unit "0"
  79. uci_set_state network "wan" ipaddr "$IP"
  80. echo "#Configured by HSO" > $RESOLV_CONF
  81. [ -n "$DNS1" ] && echo "nameserver $DNS1" >> $RESOLV_CONF
  82. [ -n "$DNS2" ] && echo "nameserver $DNS2" >> $RESOLV_CONF
  83. local dns="$DNS1${DNS2:+ $DNS2}"
  84. [ -n "$dns" ] && uci_set_state network "wan" dns "$dns"
  85. env -i ACTION="ifup" INTERFACE="wan" DEVICE="hso0" PROTO=hso /sbin/hotplug-call "iface"
  86.  
  87. else
  88.  
  89. for module in usbserial option crc-ccitt slhc ppp_generic ppp_async; do
  90. /sbin/insmod $module 2>&- >&-
  91. done
  92.  
  93. config_set "$config" "connect" "USE_APN=$apn SERVICE=$service PINCODE=$pincode /usr/bin/gcom -s -d $device /etc/gcom/3g.gcom"
  94. start_pppd "$config" \
  95. novj \
  96. nobsdcomp \
  97. noauth \
  98. crtscts \
  99. updetach \
  100. ${mtu:+mtu $mtu mru $mtu} \
  101. 460800 "$device"
  102. fi
  103.  
  104. set_3g_led $ledcode 0
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement