mac80211.sh 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 $(ls /sys/class/ieee80211 2>/dev/null); do
  20. [ "$macaddr" = "$(cat /sys/class/ieee80211/${_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 $(ls /sys/class/ieee80211); do
  60. found=0
  61. config_foreach check_mac80211_device wifi-device
  62. [ "$found" -gt 0 ] && continue
  63. mode_band="g"
  64. channel="11"
  65. htmode=""
  66. ht_capab=""
  67. iw phy "$dev" info | grep -q 'Capabilities:' && htmode=HT20
  68. iw phy "$dev" info | grep -q '2412 MHz' || { mode_band="a"; channel="36"; }
  69. vht_cap=$(iw phy "$dev" info | grep -c 'VHT Capabilities')
  70. [ "$vht_cap" -gt 0 ] && {
  71. mode_band="a";
  72. channel="36"
  73. htmode="VHT80"
  74. }
  75. [ -n $htmode ] && append ht_capab " option htmode $htmode" "$N"
  76. if [ -x /usr/bin/readlink ]; then
  77. path="$(readlink -f /sys/class/ieee80211/${dev}/device)"
  78. path="${path##/sys/devices/}"
  79. dev_id=" option path '$path'"
  80. else
  81. dev_id=" option macaddr $(cat /sys/class/ieee80211/${dev}/macaddress)"
  82. fi
  83. cat <<EOF
  84. config wifi-device radio$devidx
  85. option type mac80211
  86. option channel ${channel}
  87. option hwmode 11${mode_band}
  88. $dev_id
  89. $ht_capab
  90. # REMOVE THIS LINE TO ENABLE WIFI:
  91. option disabled 1
  92. EOF
  93. devidx=$(($devidx + 1))
  94. done
  95. }