wifi 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/bin/sh
  2. # Copyright (C) 2006 OpenWrt.org
  3. . /lib/functions.sh
  4. . /usr/share/libubox/jshn.sh
  5. usage() {
  6. cat <<EOF
  7. Usage: $0 [config|up|down|reconf|reload|status|isup]
  8. enables (default), disables or configures devices not yet configured.
  9. EOF
  10. exit 1
  11. }
  12. ubus_wifi_cmd() {
  13. local cmd="$1"
  14. local dev="$2"
  15. json_init
  16. [ -n "$dev" ] && json_add_string device "$dev"
  17. ubus call network.wireless "$cmd" "$(json_dump)"
  18. }
  19. wifi_isup() {
  20. local dev="$1"
  21. json_load "$(ubus_wifi_cmd "status" "$dev")"
  22. json_get_keys devices
  23. for device in $devices; do
  24. json_select "$device"
  25. json_get_var up up
  26. [ $up -eq 0 ] && return 1
  27. json_select ..
  28. done
  29. return 0
  30. }
  31. wifi_updown() {
  32. cmd=down
  33. [ enable = "$1" ] && {
  34. ubus_wifi_cmd "$cmd" "$2"
  35. ubus call network reload
  36. cmd=up
  37. }
  38. [ reconf = "$1" ] && {
  39. ubus call network reload
  40. cmd=reconf
  41. }
  42. ubus_wifi_cmd "$cmd" "$2"
  43. }
  44. wifi_reload() {
  45. ubus call network reload
  46. }
  47. wifi_detect_notice() {
  48. >&2 echo "WARNING: Wifi detect is deprecated. Use wifi config instead"
  49. >&2 echo "For more information, see commit 5f8f8a366136a07df661e31decce2458357c167a"
  50. exit 1
  51. }
  52. wifi_config() {
  53. [ -e /tmp/.config_pending ] && return
  54. ucode /usr/share/hostap/wifi-detect.uc
  55. [ ! -f /etc/config/wireless ] && touch /etc/config/wireless
  56. ucode /lib/wifi/mac80211.uc | uci -q batch
  57. for driver in $DRIVERS; do (
  58. if eval "type detect_$driver" 2>/dev/null >/dev/null; then
  59. eval "detect_$driver" || echo "$driver: Detect failed" >&2
  60. else
  61. echo "$driver: Hardware detection not supported" >&2
  62. fi
  63. ); done
  64. }
  65. DEVICES=
  66. DRIVERS=
  67. include /lib/wifi
  68. case "$1" in
  69. down) wifi_updown "disable" "$2";;
  70. detect) wifi_detect_notice ;;
  71. config) wifi_config ;;
  72. status) ubus_wifi_cmd "status" "$2";;
  73. isup) wifi_isup "$2"; exit $?;;
  74. reload) wifi_reload "$2";;
  75. --help|help) usage;;
  76. reconf) wifi_updown "reconf" "$2";;
  77. ''|up) wifi_updown "enable" "$2";;
  78. *) usage; exit 1;;
  79. esac