mac80211.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. config wifi-iface
  99. option device radio$devidx
  100. $(if [ $devidx -gt 0 ]; then
  101. echo -e "\toption ifname wlan$devidx";
  102. fi)
  103. option network lan
  104. option mode $(if [[ "$devidx" == "0" ]] ; then echo ap ; else echo sta ; fi)
  105. option ssid Pineapple_$(cat /sys/class/ieee80211/${dev}/macaddress|awk -F ":" '{print $5""$6 }'| tr a-z A-Z)
  106. $(if [ $devidx -eq 0 ]; then
  107. echo -e "\toption ifname wlan0";
  108. echo -e "\toption maxassoc 100";
  109. fi)
  110. option encryption none
  111. $(if [[ "$devidx" == "0" ]]; then
  112. echo config wifi-iface
  113. echo -e "\toption device radio$devidx";
  114. echo -e "\toption ifname wlan0-1";
  115. echo -e "\toption network lan";
  116. echo -e "\toption mode ap";
  117. echo -e "\toption ssid Management";
  118. echo -e "\toption encryption psk2+ccmp";
  119. echo -e "\toption key 'pineapplesareyummy'";
  120. echo -e "\toption disabled 1";
  121. echo config wifi-iface
  122. echo -e "\toption device radio$devidx";
  123. echo -e "\toption ifname wlan0-2";
  124. echo -e "\toption network lan";
  125. echo -e "\toption mode ap";
  126. echo -e "\toption ssid PineAP_Enterprise";
  127. echo -e "\toption macaddr 00:11:22:33:44:55";
  128. echo -e "\toption encryption wpa2+ccmp";
  129. echo -e "\toption key 12345678";
  130. echo -e "\toption server 127.0.0.1";
  131. echo -e "\toption disabled 1";
  132. fi)
  133. $(if [[ "$devidx" == "2" ]]; then
  134. echo config wifi-iface
  135. echo -e "\toption device radio$devidx";
  136. echo -e "\toption ifname wlan2";
  137. echo -e "\toption network lan";
  138. echo -e "\toption mode sta";
  139. echo -e "\toption disabled 0";
  140. fi)
  141. EOF
  142. devidx=$(($devidx + 1))
  143. done
  144. }