1
0

mac80211.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. #!/bin/sh
  2. append DRIVERS "mac80211"
  3. lookup_phy() {
  4. [ -n "$phy" ] && {
  5. [ -d /sys/class/ieee80211/$phy ] && return
  6. }
  7. local devpath
  8. config_get devpath "$device" path
  9. [ -n "$devpath" ] && {
  10. for phy in $(ls /sys/class/ieee80211 2>/dev/null); do
  11. case "$(readlink -f /sys/class/ieee80211/$phy/device)" in
  12. *$devpath) return;;
  13. esac
  14. done
  15. }
  16. local macaddr="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')"
  17. [ -n "$macaddr" ] && {
  18. for _phy in /sys/class/ieee80211/*; do
  19. [ -e "$_phy" ] || continue
  20. [ "$macaddr" = "$(cat ${_phy}/macaddress)" ] || continue
  21. phy="${_phy##*/}"
  22. return
  23. done
  24. }
  25. phy=
  26. return
  27. }
  28. find_mac80211_phy() {
  29. local device="$1"
  30. config_get phy "$device" phy
  31. lookup_phy
  32. [ -n "$phy" -a -d "/sys/class/ieee80211/$phy" ] || {
  33. echo "PHY for wifi device $1 not found"
  34. return 1
  35. }
  36. config_set "$device" phy "$phy"
  37. config_get macaddr "$device" macaddr
  38. [ -z "$macaddr" ] && {
  39. config_set "$device" macaddr "$(cat /sys/class/ieee80211/${phy}/macaddress)"
  40. }
  41. return 0
  42. }
  43. check_mac80211_device() {
  44. config_get phy "$1" phy
  45. [ -z "$phy" ] && {
  46. find_mac80211_phy "$1" >/dev/null || return 0
  47. config_get phy "$1" phy
  48. }
  49. [ "$phy" = "$dev" ] && found=1
  50. }
  51. detect_mac80211() {
  52. devidx=0
  53. config_load wireless
  54. while :; do
  55. config_get type "radio$devidx" type
  56. [ -n "$type" ] || break
  57. devidx=$(($devidx + 1))
  58. done
  59. for _dev in /sys/class/ieee80211/*; do
  60. [ -e "$_dev" ] || continue
  61. dev="${_dev##*/}"
  62. found=0
  63. config_foreach check_mac80211_device wifi-device
  64. [ "$found" -gt 0 ] && continue
  65. mode_band="g"
  66. channel="11"
  67. htmode=""
  68. ht_capab=""
  69. iw phy "$dev" info | grep -q 'Capabilities:' && htmode=HT20
  70. iw phy "$dev" info | grep -q '2412 MHz' || { mode_band="a"; channel="36"; }
  71. vht_cap=$(iw phy "$dev" info | grep -c 'VHT Capabilities')
  72. cap_5ghz=$(iw phy "$dev" info | grep -c "Band 2")
  73. [ "$vht_cap" -gt 0 -a "$cap_5ghz" -gt 0 ] && {
  74. mode_band="a";
  75. channel="36"
  76. htmode="VHT80"
  77. }
  78. [ -n "$htmode" ] && ht_capab="set wireless.radio${devidx}.htmode=$htmode"
  79. if [ -x /usr/bin/readlink -a -h /sys/class/ieee80211/${dev} ]; then
  80. path="$(readlink -f /sys/class/ieee80211/${dev}/device)"
  81. else
  82. path=""
  83. fi
  84. if [ -n "$path" ]; then
  85. path="${path##/sys/devices/}"
  86. case "$path" in
  87. platform*/pci*) path="${path##platform/}";;
  88. esac
  89. dev_id="set wireless.radio${devidx}.path='$path'"
  90. else
  91. dev_id="set wireless.radio${devidx}.macaddr=$(cat /sys/class/ieee80211/${dev}/macaddress)"
  92. fi
  93. uci -q batch <<-EOF
  94. set wireless.radio${devidx}=wifi-device
  95. set wireless.radio${devidx}.type=mac80211
  96. set wireless.radio${devidx}.channel=${channel}
  97. set wireless.radio${devidx}.hwmode=11${mode_band}
  98. ${dev_id}
  99. ${ht_capab}
  100. set wireless.radio${devidx}.disabled=0
  101. set wireless.default_radio${devidx}=wifi-iface
  102. set wireless.default_radio${devidx}.device=radio${devidx}
  103. set wireless.default_radio${devidx}.network=lan
  104. set wireless.default_radio${devidx}.mode=ap
  105. set wireless.default_radio${devidx}.ssid=libreCMC
  106. set wireless.default_radio${devidx}.encryption=psk
  107. set wireless.default_radio${devidx}.key=librecmc
  108. EOF
  109. uci -q commit wireless
  110. devidx=$(($devidx + 1))
  111. done
  112. }