directip.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. cardinfo=$(gcom -d "$device" -s /etc/gcom/getcardinfo.gcom)
  39. [ -n $(echo "$cardinfo" | grep -q "Sierra Wireless") ] || {
  40. proto_notify_error "$interface" BAD_DEVICE
  41. proto_block_restart "$interface"
  42. return 1
  43. }
  44. if [ -n "$pincode" ]; then
  45. PINCODE="$pincode" gcom -d "$device" -s /etc/gcom/setpin.gcom || {
  46. proto_notify_error "$interface" PIN_FAILED
  47. proto_block_restart "$interface"
  48. return 1
  49. }
  50. fi
  51. # wait for carrier to avoid firmware stability bugs
  52. gcom -d "$device" -s /etc/gcom/getcarrier.gcom || return 1
  53. local auth_type=0
  54. case $auth in
  55. pap) auth_type=1;;
  56. chap) auth_type=2;;
  57. esac
  58. USE_APN="$apn" USE_USER="$username" USE_PASS="$password" USE_AUTH="$auth_type" \
  59. gcom -d "$device" -s /etc/gcom/directip.gcom || {
  60. proto_notify_error "$interface" CONNECT_FAILED
  61. proto_block_restart "$interface"
  62. return 1
  63. }
  64. logger -p daemon.info -t "directip[$$]" "Connected, starting DHCP"
  65. proto_init_update "$ifname" 1
  66. proto_send_update "$interface"
  67. json_init
  68. json_add_string name "${interface}_4"
  69. json_add_string ifname "@$interface"
  70. json_add_string proto "dhcp"
  71. proto_add_dynamic_defaults
  72. ubus call network add_dynamic "$(json_dump)"
  73. json_init
  74. json_add_string name "${interface}_6"
  75. json_add_string ifname "@$interface"
  76. json_add_string proto "dhcpv6"
  77. json_add_string extendprefix 1
  78. proto_add_dynamic_defaults
  79. ubus call network add_dynamic "$(json_dump)"
  80. return 0
  81. }
  82. proto_directip_teardown() {
  83. local interface="$1"
  84. local device
  85. json_get_vars device
  86. [ -n "$ctl_device" ] && device=$ctl_device
  87. gcom -d "$device" -s /etc/gcom/directip-stop.gcom || proto_notify_error "$interface" CONNECT_FAILED
  88. proto_init_update "*" 0
  89. proto_send_update "$interface"
  90. }
  91. [ -n "$INCLUDE_ONLY" ] || {
  92. add_protocol directip
  93. }