mac80211.sh 2.7 KB

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