1
0

wwan.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/sh
  2. . /lib/functions.sh
  3. . ../netifd-proto.sh
  4. init_proto "$@"
  5. INCLUDE_ONLY=1
  6. ctl_device=""
  7. dat_device=""
  8. proto_mbim_setup() { echo "wwan[$$] mbim proto is missing"; }
  9. proto_qmi_setup() { echo "wwan[$$] qmi proto is missing"; }
  10. proto_ncm_setup() { echo "wwan[$$] ncm proto is missing"; }
  11. proto_3g_setup() { echo "wwan[$$] 3g proto is missing"; }
  12. proto_directip_setup() { echo "wwan[$$] directip proto is missing"; }
  13. [ -f ./mbim.sh ] && . ./mbim.sh
  14. [ -f ./ncm.sh ] && . ./ncm.sh
  15. [ -f ./qmi.sh ] && . ./qmi.sh
  16. [ -f ./3g.sh ] && { . ./ppp.sh; . ./3g.sh; }
  17. [ -f ./directip.sh ] && . ./directip.sh
  18. proto_wwan_init_config() {
  19. available=1
  20. no_device=1
  21. proto_config_add_string apn
  22. proto_config_add_string auth
  23. proto_config_add_string username
  24. proto_config_add_string password
  25. proto_config_add_string pincode
  26. proto_config_add_string delay
  27. proto_config_add_string modes
  28. }
  29. proto_wwan_setup() {
  30. local driver usb devicename desc
  31. for a in `ls /sys/bus/usb/devices`; do
  32. local vendor product
  33. [ -z "$usb" -a -f /sys/bus/usb/devices/$a/idVendor -a -f /sys/bus/usb/devices/$a/idProduct ] || continue
  34. vendor=$(cat /sys/bus/usb/devices/$a/idVendor)
  35. product=$(cat /sys/bus/usb/devices/$a/idProduct)
  36. [ -f /lib/network/wwan/$vendor:$product ] && {
  37. usb=/lib/network/wwan/$vendor:$product
  38. devicename=$a
  39. }
  40. done
  41. [ -n "$usb" ] && {
  42. local old_cb control data
  43. json_set_namespace wwan old_cb
  44. json_init
  45. json_load "$(cat $usb)"
  46. json_select
  47. json_get_vars desc control data
  48. json_set_namespace $old_cb
  49. [ -n "$control" -a -n "$data" ] && {
  50. ttys=$(ls -d /sys/bus/usb/devices/$devicename/${devicename}*/tty* | sed "s/.*\///g" | tr "\n" " ")
  51. ctl_device=/dev/$(echo $ttys | cut -d" " -f $((control + 1)))
  52. dat_device=/dev/$(echo $ttys | cut -d" " -f $((data + 1)))
  53. driver=comgt
  54. }
  55. }
  56. [ -z "$ctl_device" ] && for net in $(ls /sys/class/net/ | grep wwan); do
  57. [ -z "$ctl_device" ] || continue
  58. driver=$(grep DRIVER /sys/class/net/$net/device/uevent | cut -d= -f2)
  59. case "$driver" in
  60. qmi_wwan|cdc_mbim)
  61. ctl_device=/dev/$(ls /sys/class/net/$net/device/usbmisc)
  62. ;;
  63. sierra_net|*cdc_ncm)
  64. ctl_device=/dev/$(cd /sys/class/net/$net/; find ../../../ -name ttyUSB* |xargs basename | head -n1)
  65. ;;
  66. *) continue;;
  67. esac
  68. echo "wwan[$$]" "Using proto:$proto device:$ctl_device iface:$net desc:$desc"
  69. done
  70. [ -n "$ctl_device" ] || {
  71. echo "wwan[$$]" "No valid device was found"
  72. proto_notify_error "$interface" NO_DEVICE
  73. proto_block_restart "$interface"
  74. return 1
  75. }
  76. uci_set_state network $interface driver "$driver"
  77. uci_set_state network $interface ctl_device "$ctl_device"
  78. uci_set_state network $interface dat_device "$dat_device"
  79. case $driver in
  80. qmi_wwan) proto_qmi_setup $@ ;;
  81. cdc_mbim) proto_mbim_setup $@ ;;
  82. sierra_net) proto_directip_setup $@ ;;
  83. comgt) proto_3g_setup $@ ;;
  84. *cdc_ncm) proto_ncm_setup $@ ;;
  85. esac
  86. }
  87. proto_wwan_teardown() {
  88. local interface=$1
  89. local driver=$(uci_get_state network $interface driver)
  90. ctl_device=$(uci_get_state network $interface ctl_device)
  91. dat_device=$(uci_get_state network $interface dat_device)
  92. case $driver in
  93. qmi_wwan) proto_qmi_teardown $@ ;;
  94. cdc_mbim) proto_mbim_teardown $@ ;;
  95. sierra_net) proto_mbim_teardown $@ ;;
  96. comgt) proto_3g_teardown $@ ;;
  97. *cdc_ncm) proto_ncm_teardown $@ ;;
  98. esac
  99. }
  100. add_protocol wwan