1
0

directip.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/sh
  2. [ -n "$INCLUDE_ONLY" ] || {
  3. . /lib/functions.sh
  4. . ../netifd-proto.sh
  5. init_proto "$@"
  6. }
  7. proto_directip_init_config() {
  8. available=1
  9. no_device=1
  10. proto_config_add_string "device:device"
  11. proto_config_add_string "apn"
  12. proto_config_add_string "pincode"
  13. proto_config_add_string "auth"
  14. proto_config_add_string "username"
  15. proto_config_add_string "password"
  16. proto_config_add_defaults
  17. }
  18. proto_directip_setup() {
  19. local interface="$1"
  20. local chat devpath devname
  21. local device apn pincode ifname auth username password $PROTO_DEFAULT_OPTIONS
  22. json_get_vars device apn pincode auth username password $PROTO_DEFAULT_OPTIONS
  23. [ -n "$ctl_device" ] && device=$ctl_device
  24. device="$(readlink -f $device)"
  25. [ -e "$device" ] || {
  26. proto_notify_error "$interface" NO_DEVICE
  27. proto_set_available "$interface" 0
  28. return 1
  29. }
  30. devname="$(basename "$device")"
  31. devpath="$(readlink -f /sys/class/tty/$devname/device)"
  32. ifname="$( ls "$devpath"/../../*/net )"
  33. [ -n "$ifname" ] || {
  34. proto_notify_error "$interface" NO_IFNAME
  35. proto_set_available "$interface" 0
  36. return 1
  37. }
  38. gcom -d "$device" -s /etc/gcom/getcardinfo.gcom | grep -q "Sierra Wireless" || {
  39. proto_notify_error "$interface" BAD_DEVICE
  40. proto_block_restart "$interface"
  41. return 1
  42. }
  43. if [ -n "$pincode" ]; then
  44. PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || {
  45. proto_notify_error "$interface" PIN_FAILED
  46. proto_block_restart "$interface"
  47. return 1
  48. }
  49. fi
  50. # wait for carrier to avoid firmware stability bugs
  51. gcom -d "$device" -s /etc/gcom/getcarrier.gcom || return 1
  52. local auth_type=0
  53. case $auth in
  54. pap) auth_type=1;;
  55. chap) auth_type=2;;
  56. esac
  57. USE_APN="$apn" USE_USER="$username" USE_PASS="$password" USE_AUTH="$auth_type" \
  58. gcom -d "$device" -s /etc/gcom/directip.gcom || {
  59. proto_notify_error "$interface" CONNECT_FAILED
  60. proto_block_restart "$interface"
  61. return 1
  62. }
  63. logger -p daemon.info -t "directip[$$]" "Connected, starting DHCP"
  64. proto_init_update "$ifname" 1
  65. proto_send_update "$interface"
  66. json_init
  67. json_add_string name "${interface}_4"
  68. json_add_string ifname "@$interface"
  69. json_add_string proto "dhcp"
  70. proto_add_dynamic_defaults
  71. ubus call network add_dynamic "$(json_dump)"
  72. json_init
  73. json_add_string name "${interface}_6"
  74. json_add_string ifname "@$interface"
  75. json_add_string proto "dhcpv6"
  76. json_add_string extendprefix 1
  77. proto_add_dynamic_defaults
  78. ubus call network add_dynamic "$(json_dump)"
  79. return 0
  80. }
  81. proto_directip_teardown() {
  82. local interface="$1"
  83. local device
  84. json_get_vars device
  85. [ -n "$ctl_device" ] && device=$ctl_device
  86. gcom -d "$device" -s /etc/gcom/directip-stop.gcom || proto_notify_error "$interface" CONNECT_FAILED
  87. proto_init_update "*" 0
  88. proto_send_update "$interface"
  89. }
  90. [ -n "$INCLUDE_ONLY" ] || {
  91. add_protocol directip
  92. }