directip.sh 3.0 KB

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