mac80211.sh 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. #!/bin/sh
  2. . /lib/netifd/netifd-wireless.sh
  3. . /lib/netifd/hostapd.sh
  4. . /lib/functions/system.sh
  5. init_wireless_driver "$@"
  6. MP_CONFIG_INT="mesh_retry_timeout mesh_confirm_timeout mesh_holding_timeout mesh_max_peer_links
  7. mesh_max_retries mesh_ttl mesh_element_ttl mesh_hwmp_max_preq_retries
  8. mesh_path_refresh_time mesh_min_discovery_timeout mesh_hwmp_active_path_timeout
  9. mesh_hwmp_preq_min_interval mesh_hwmp_net_diameter_traversal_time mesh_hwmp_rootmode
  10. mesh_hwmp_rann_interval mesh_gate_announcements mesh_sync_offset_max_neighor
  11. mesh_rssi_threshold mesh_hwmp_active_path_to_root_timeout mesh_hwmp_root_interval
  12. mesh_hwmp_confirmation_interval mesh_awake_window mesh_plink_timeout"
  13. MP_CONFIG_BOOL="mesh_auto_open_plinks mesh_fwding"
  14. MP_CONFIG_STRING="mesh_power_mode"
  15. wdev_tool() {
  16. ucode /usr/share/hostap/wdev.uc "$@"
  17. }
  18. drv_mac80211_init_device_config() {
  19. hostapd_common_add_device_config
  20. config_add_string path phy 'macaddr:macaddr'
  21. config_add_string tx_burst
  22. config_add_string distance
  23. config_add_int beacon_int chanbw frag rts
  24. config_add_int rxantenna txantenna antenna_gain txpower min_tx_power
  25. config_add_boolean noscan ht_coex acs_exclude_dfs background_radar
  26. config_add_array ht_capab
  27. config_add_array channels
  28. config_add_array scan_list
  29. config_add_boolean \
  30. rxldpc \
  31. short_gi_80 \
  32. short_gi_160 \
  33. tx_stbc_2by1 \
  34. su_beamformer \
  35. su_beamformee \
  36. mu_beamformer \
  37. mu_beamformee \
  38. he_su_beamformer \
  39. he_su_beamformee \
  40. he_mu_beamformer \
  41. vht_txop_ps \
  42. htc_vht \
  43. rx_antenna_pattern \
  44. tx_antenna_pattern \
  45. he_spr_sr_control \
  46. he_spr_psr_enabled \
  47. he_bss_color_enabled \
  48. he_twt_required
  49. config_add_int \
  50. beamformer_antennas \
  51. beamformee_antennas \
  52. vht_max_a_mpdu_len_exp \
  53. vht_max_mpdu \
  54. vht_link_adapt \
  55. vht160 \
  56. rx_stbc \
  57. tx_stbc \
  58. he_bss_color \
  59. he_spr_non_srg_obss_pd_max_offset
  60. config_add_boolean \
  61. ldpc \
  62. greenfield \
  63. short_gi_20 \
  64. short_gi_40 \
  65. max_amsdu \
  66. dsss_cck_40
  67. }
  68. drv_mac80211_init_iface_config() {
  69. hostapd_common_add_bss_config
  70. config_add_string 'macaddr:macaddr' ifname
  71. config_add_boolean wds powersave enable
  72. config_add_string wds_bridge
  73. config_add_int maxassoc
  74. config_add_int max_listen_int
  75. config_add_int dtim_period
  76. config_add_int start_disabled
  77. # mesh
  78. config_add_string mesh_id
  79. config_add_int $MP_CONFIG_INT
  80. config_add_boolean $MP_CONFIG_BOOL
  81. config_add_string $MP_CONFIG_STRING
  82. }
  83. mac80211_add_capabilities() {
  84. local __var="$1"; shift
  85. local __mask="$1"; shift
  86. local __out= oifs
  87. oifs="$IFS"
  88. IFS=:
  89. for capab in "$@"; do
  90. set -- $capab
  91. [ "$(($4))" -gt 0 ] || continue
  92. [ "$(($__mask & $2))" -eq "$((${3:-$2}))" ] || continue
  93. __out="$__out[$1]"
  94. done
  95. IFS="$oifs"
  96. export -n -- "$__var=$__out"
  97. }
  98. mac80211_add_he_capabilities() {
  99. local __out= oifs
  100. oifs="$IFS"
  101. IFS=:
  102. for capab in "$@"; do
  103. set -- $capab
  104. [ "$(($4))" -gt 0 ] || continue
  105. [ "$(((0x$2) & $3))" -gt 0 ] || {
  106. eval "$1=0"
  107. continue
  108. }
  109. append base_cfg "$1=1" "$N"
  110. done
  111. IFS="$oifs"
  112. }
  113. mac80211_hostapd_setup_base() {
  114. local phy="$1"
  115. json_select config
  116. [ "$auto_channel" -gt 0 ] && channel=acs_survey
  117. [ "$auto_channel" -gt 0 ] && json_get_vars acs_exclude_dfs
  118. [ -n "$acs_exclude_dfs" ] && [ "$acs_exclude_dfs" -gt 0 ] &&
  119. append base_cfg "acs_exclude_dfs=1" "$N"
  120. json_get_vars noscan ht_coex min_tx_power:0 tx_burst
  121. json_get_values ht_capab_list ht_capab
  122. json_get_values channel_list channels
  123. [ "$auto_channel" = 0 ] && [ -z "$channel_list" ] && \
  124. channel_list="$channel"
  125. [ "$min_tx_power" -gt 0 ] && append base_cfg "min_tx_power=$min_tx_power"
  126. set_default noscan 0
  127. [ "$noscan" -gt 0 ] && hostapd_noscan=1
  128. [ "$tx_burst" = 0 ] && tx_burst=
  129. chan_ofs=0
  130. [ "$band" = "6g" ] && chan_ofs=1
  131. ieee80211n=1
  132. ht_capab=
  133. case "$htmode" in
  134. VHT20|HT20|HE20) ;;
  135. HT40*|VHT40|VHT80|VHT160|HE40|HE80|HE160)
  136. case "$hwmode" in
  137. a)
  138. case "$(( (($channel / 4) + $chan_ofs) % 2 ))" in
  139. 1) ht_capab="[HT40+]";;
  140. 0) ht_capab="[HT40-]";;
  141. esac
  142. ;;
  143. *)
  144. case "$htmode" in
  145. HT40+) ht_capab="[HT40+]";;
  146. HT40-) ht_capab="[HT40-]";;
  147. *)
  148. if [ "$channel" -lt 7 ]; then
  149. ht_capab="[HT40+]"
  150. else
  151. ht_capab="[HT40-]"
  152. fi
  153. ;;
  154. esac
  155. ;;
  156. esac
  157. [ "$auto_channel" -gt 0 ] && ht_capab="[HT40+]"
  158. ;;
  159. *) ieee80211n= ;;
  160. esac
  161. [ -n "$ieee80211n" ] && {
  162. append base_cfg "ieee80211n=1" "$N"
  163. set_default ht_coex 0
  164. append base_cfg "ht_coex=$ht_coex" "$N"
  165. json_get_vars \
  166. ldpc:1 \
  167. greenfield:0 \
  168. short_gi_20:1 \
  169. short_gi_40:1 \
  170. tx_stbc:1 \
  171. rx_stbc:3 \
  172. max_amsdu:1 \
  173. dsss_cck_40:1
  174. ht_cap_mask=0
  175. for cap in $(iw phy "$phy" info | grep 'Capabilities:' | cut -d: -f2); do
  176. ht_cap_mask="$(($ht_cap_mask | $cap))"
  177. done
  178. cap_rx_stbc=$((($ht_cap_mask >> 8) & 3))
  179. [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc="$rx_stbc"
  180. ht_cap_mask="$(( ($ht_cap_mask & ~(0x300)) | ($cap_rx_stbc << 8) ))"
  181. mac80211_add_capabilities ht_capab_flags $ht_cap_mask \
  182. LDPC:0x1::$ldpc \
  183. GF:0x10::$greenfield \
  184. SHORT-GI-20:0x20::$short_gi_20 \
  185. SHORT-GI-40:0x40::$short_gi_40 \
  186. TX-STBC:0x80::$tx_stbc \
  187. RX-STBC1:0x300:0x100:1 \
  188. RX-STBC12:0x300:0x200:1 \
  189. RX-STBC123:0x300:0x300:1 \
  190. MAX-AMSDU-7935:0x800::$max_amsdu \
  191. DSSS_CCK-40:0x1000::$dsss_cck_40
  192. ht_capab="$ht_capab$ht_capab_flags"
  193. [ -n "$ht_capab" ] && append base_cfg "ht_capab=$ht_capab" "$N"
  194. }
  195. # 802.11ac
  196. enable_ac=0
  197. vht_oper_chwidth=0
  198. vht_center_seg0=
  199. idx="$channel"
  200. case "$htmode" in
  201. VHT20|HE20) enable_ac=1;;
  202. VHT40|HE40)
  203. case "$(( (($channel / 4) + $chan_ofs) % 2 ))" in
  204. 1) idx=$(($channel + 2));;
  205. 0) idx=$(($channel - 2));;
  206. esac
  207. enable_ac=1
  208. vht_center_seg0=$idx
  209. ;;
  210. VHT80|HE80)
  211. case "$(( (($channel / 4) + $chan_ofs) % 4 ))" in
  212. 1) idx=$(($channel + 6));;
  213. 2) idx=$(($channel + 2));;
  214. 3) idx=$(($channel - 2));;
  215. 0) idx=$(($channel - 6));;
  216. esac
  217. enable_ac=1
  218. vht_oper_chwidth=1
  219. vht_center_seg0=$idx
  220. ;;
  221. VHT160|HE160)
  222. if [ "$band" = "6g" ]; then
  223. case "$channel" in
  224. 1|5|9|13|17|21|25|29) idx=15;;
  225. 33|37|41|45|49|53|57|61) idx=47;;
  226. 65|69|73|77|81|85|89|93) idx=79;;
  227. 97|101|105|109|113|117|121|125) idx=111;;
  228. 129|133|137|141|145|149|153|157) idx=143;;
  229. 161|165|169|173|177|181|185|189) idx=175;;
  230. 193|197|201|205|209|213|217|221) idx=207;;
  231. esac
  232. else
  233. case "$channel" in
  234. 36|40|44|48|52|56|60|64) idx=50;;
  235. 100|104|108|112|116|120|124|128) idx=114;;
  236. esac
  237. fi
  238. enable_ac=1
  239. vht_oper_chwidth=2
  240. vht_center_seg0=$idx
  241. ;;
  242. esac
  243. [ "$band" = "5g" ] && {
  244. json_get_vars background_radar:0
  245. [ "$background_radar" -eq 1 ] && append base_cfg "enable_background_radar=1" "$N"
  246. }
  247. [ "$band" = "6g" ] && {
  248. op_class=
  249. case "$htmode" in
  250. HE20) op_class=131;;
  251. HE*) op_class=$((132 + $vht_oper_chwidth))
  252. esac
  253. [ -n "$op_class" ] && append base_cfg "op_class=$op_class" "$N"
  254. }
  255. [ "$hwmode" = "a" ] || enable_ac=0
  256. if [ "$enable_ac" != "0" ]; then
  257. json_get_vars \
  258. rxldpc:1 \
  259. short_gi_80:1 \
  260. short_gi_160:1 \
  261. tx_stbc_2by1:1 \
  262. su_beamformer:1 \
  263. su_beamformee:1 \
  264. mu_beamformer:1 \
  265. mu_beamformee:1 \
  266. vht_txop_ps:1 \
  267. htc_vht:1 \
  268. beamformee_antennas:4 \
  269. beamformer_antennas:4 \
  270. rx_antenna_pattern:1 \
  271. tx_antenna_pattern:1 \
  272. vht_max_a_mpdu_len_exp:7 \
  273. vht_max_mpdu:11454 \
  274. rx_stbc:4 \
  275. vht_link_adapt:3 \
  276. vht160:2
  277. set_default tx_burst 2.0
  278. append base_cfg "ieee80211ac=1" "$N"
  279. vht_cap=0
  280. for cap in $(iw phy "$phy" info | awk -F "[()]" '/VHT Capabilities/ { print $2 }'); do
  281. vht_cap="$(($vht_cap | $cap))"
  282. done
  283. append base_cfg "vht_oper_chwidth=$vht_oper_chwidth" "$N"
  284. append base_cfg "vht_oper_centr_freq_seg0_idx=$vht_center_seg0" "$N"
  285. cap_rx_stbc=$((($vht_cap >> 8) & 7))
  286. [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc="$rx_stbc"
  287. vht_cap="$(( ($vht_cap & ~(0x700)) | ($cap_rx_stbc << 8) ))"
  288. mac80211_add_capabilities vht_capab $vht_cap \
  289. RXLDPC:0x10::$rxldpc \
  290. SHORT-GI-80:0x20::$short_gi_80 \
  291. SHORT-GI-160:0x40::$short_gi_160 \
  292. TX-STBC-2BY1:0x80::$tx_stbc_2by1 \
  293. SU-BEAMFORMER:0x800::$su_beamformer \
  294. SU-BEAMFORMEE:0x1000::$su_beamformee \
  295. MU-BEAMFORMER:0x80000::$mu_beamformer \
  296. MU-BEAMFORMEE:0x100000::$mu_beamformee \
  297. VHT-TXOP-PS:0x200000::$vht_txop_ps \
  298. HTC-VHT:0x400000::$htc_vht \
  299. RX-ANTENNA-PATTERN:0x10000000::$rx_antenna_pattern \
  300. TX-ANTENNA-PATTERN:0x20000000::$tx_antenna_pattern \
  301. RX-STBC-1:0x700:0x100:1 \
  302. RX-STBC-12:0x700:0x200:1 \
  303. RX-STBC-123:0x700:0x300:1 \
  304. RX-STBC-1234:0x700:0x400:1 \
  305. [ "$(($vht_cap & 0x800))" -gt 0 -a "$su_beamformer" -gt 0 ] && {
  306. cap_ant="$(( ( ($vht_cap >> 16) & 3 ) + 1 ))"
  307. [ "$cap_ant" -gt "$beamformer_antennas" ] && cap_ant="$beamformer_antennas"
  308. [ "$cap_ant" -gt 1 ] && vht_capab="$vht_capab[SOUNDING-DIMENSION-$cap_ant]"
  309. }
  310. [ "$(($vht_cap & 0x1000))" -gt 0 -a "$su_beamformee" -gt 0 ] && {
  311. cap_ant="$(( ( ($vht_cap >> 13) & 3 ) + 1 ))"
  312. [ "$cap_ant" -gt "$beamformee_antennas" ] && cap_ant="$beamformee_antennas"
  313. [ "$cap_ant" -gt 1 ] && vht_capab="$vht_capab[BF-ANTENNA-$cap_ant]"
  314. }
  315. # supported Channel widths
  316. vht160_hw=0
  317. [ "$(($vht_cap & 12))" -eq 4 -a 1 -le "$vht160" ] && \
  318. vht160_hw=1
  319. [ "$(($vht_cap & 12))" -eq 8 -a 2 -le "$vht160" ] && \
  320. vht160_hw=2
  321. [ "$vht160_hw" = 1 ] && vht_capab="$vht_capab[VHT160]"
  322. [ "$vht160_hw" = 2 ] && vht_capab="$vht_capab[VHT160-80PLUS80]"
  323. # maximum MPDU length
  324. vht_max_mpdu_hw=3895
  325. [ "$(($vht_cap & 3))" -ge 1 -a 7991 -le "$vht_max_mpdu" ] && \
  326. vht_max_mpdu_hw=7991
  327. [ "$(($vht_cap & 3))" -ge 2 -a 11454 -le "$vht_max_mpdu" ] && \
  328. vht_max_mpdu_hw=11454
  329. [ "$vht_max_mpdu_hw" != 3895 ] && \
  330. vht_capab="$vht_capab[MAX-MPDU-$vht_max_mpdu_hw]"
  331. # maximum A-MPDU length exponent
  332. vht_max_a_mpdu_len_exp_hw=0
  333. [ "$(($vht_cap & 58720256))" -ge 8388608 -a 1 -le "$vht_max_a_mpdu_len_exp" ] && \
  334. vht_max_a_mpdu_len_exp_hw=1
  335. [ "$(($vht_cap & 58720256))" -ge 16777216 -a 2 -le "$vht_max_a_mpdu_len_exp" ] && \
  336. vht_max_a_mpdu_len_exp_hw=2
  337. [ "$(($vht_cap & 58720256))" -ge 25165824 -a 3 -le "$vht_max_a_mpdu_len_exp" ] && \
  338. vht_max_a_mpdu_len_exp_hw=3
  339. [ "$(($vht_cap & 58720256))" -ge 33554432 -a 4 -le "$vht_max_a_mpdu_len_exp" ] && \
  340. vht_max_a_mpdu_len_exp_hw=4
  341. [ "$(($vht_cap & 58720256))" -ge 41943040 -a 5 -le "$vht_max_a_mpdu_len_exp" ] && \
  342. vht_max_a_mpdu_len_exp_hw=5
  343. [ "$(($vht_cap & 58720256))" -ge 50331648 -a 6 -le "$vht_max_a_mpdu_len_exp" ] && \
  344. vht_max_a_mpdu_len_exp_hw=6
  345. [ "$(($vht_cap & 58720256))" -ge 58720256 -a 7 -le "$vht_max_a_mpdu_len_exp" ] && \
  346. vht_max_a_mpdu_len_exp_hw=7
  347. vht_capab="$vht_capab[MAX-A-MPDU-LEN-EXP$vht_max_a_mpdu_len_exp_hw]"
  348. # whether or not the STA supports link adaptation using VHT variant
  349. vht_link_adapt_hw=0
  350. [ "$(($vht_cap & 201326592))" -ge 134217728 -a 2 -le "$vht_link_adapt" ] && \
  351. vht_link_adapt_hw=2
  352. [ "$(($vht_cap & 201326592))" -ge 201326592 -a 3 -le "$vht_link_adapt" ] && \
  353. vht_link_adapt_hw=3
  354. [ "$vht_link_adapt_hw" != 0 ] && \
  355. vht_capab="$vht_capab[VHT-LINK-ADAPT-$vht_link_adapt_hw]"
  356. [ -n "$vht_capab" ] && append base_cfg "vht_capab=$vht_capab" "$N"
  357. fi
  358. # 802.11ax
  359. enable_ax=0
  360. case "$htmode" in
  361. HE*) enable_ax=1 ;;
  362. esac
  363. if [ "$enable_ax" != "0" ]; then
  364. json_get_vars \
  365. he_su_beamformer:1 \
  366. he_su_beamformee:1 \
  367. he_mu_beamformer:1 \
  368. he_twt_required:0 \
  369. he_spr_sr_control:3 \
  370. he_spr_psr_enabled:0 \
  371. he_spr_non_srg_obss_pd_max_offset:0 \
  372. he_bss_color:128 \
  373. he_bss_color_enabled:1
  374. he_phy_cap=$(iw phy "$phy" info | sed -n '/HE Iftypes: AP/,$p' | awk -F "[()]" '/HE PHY Capabilities/ { print $2 }' | head -1)
  375. he_phy_cap=${he_phy_cap:2}
  376. he_mac_cap=$(iw phy "$phy" info | sed -n '/HE Iftypes: AP/,$p' | awk -F "[()]" '/HE MAC Capabilities/ { print $2 }' | head -1)
  377. he_mac_cap=${he_mac_cap:2}
  378. append base_cfg "ieee80211ax=1" "$N"
  379. [ "$hwmode" = "a" ] && {
  380. append base_cfg "he_oper_chwidth=$vht_oper_chwidth" "$N"
  381. append base_cfg "he_oper_centr_freq_seg0_idx=$vht_center_seg0" "$N"
  382. }
  383. mac80211_add_he_capabilities \
  384. he_su_beamformer:${he_phy_cap:6:2}:0x80:$he_su_beamformer \
  385. he_su_beamformee:${he_phy_cap:8:2}:0x1:$he_su_beamformee \
  386. he_mu_beamformer:${he_phy_cap:8:2}:0x2:$he_mu_beamformer \
  387. he_spr_psr_enabled:${he_phy_cap:14:2}:0x1:$he_spr_psr_enabled \
  388. he_twt_required:${he_mac_cap:0:2}:0x6:$he_twt_required
  389. if [ "$he_bss_color_enabled" -gt 0 ]; then
  390. append base_cfg "he_bss_color=$he_bss_color" "$N"
  391. [ "$he_spr_non_srg_obss_pd_max_offset" -gt 0 ] && { \
  392. append base_cfg "he_spr_non_srg_obss_pd_max_offset=$he_spr_non_srg_obss_pd_max_offset" "$N"
  393. he_spr_sr_control=$((he_spr_sr_control | (1 << 2)))
  394. }
  395. [ "$he_spr_psr_enabled" -gt 0 ] || he_spr_sr_control=$((he_spr_sr_control | (1 << 0)))
  396. append base_cfg "he_spr_sr_control=$he_spr_sr_control" "$N"
  397. else
  398. append base_cfg "he_bss_color_disabled=1" "$N"
  399. fi
  400. append base_cfg "he_default_pe_duration=4" "$N"
  401. append base_cfg "he_rts_threshold=1023" "$N"
  402. append base_cfg "he_mu_edca_qos_info_param_count=0" "$N"
  403. append base_cfg "he_mu_edca_qos_info_q_ack=0" "$N"
  404. append base_cfg "he_mu_edca_qos_info_queue_request=0" "$N"
  405. append base_cfg "he_mu_edca_qos_info_txop_request=0" "$N"
  406. append base_cfg "he_mu_edca_ac_be_aifsn=8" "$N"
  407. append base_cfg "he_mu_edca_ac_be_aci=0" "$N"
  408. append base_cfg "he_mu_edca_ac_be_ecwmin=9" "$N"
  409. append base_cfg "he_mu_edca_ac_be_ecwmax=10" "$N"
  410. append base_cfg "he_mu_edca_ac_be_timer=255" "$N"
  411. append base_cfg "he_mu_edca_ac_bk_aifsn=15" "$N"
  412. append base_cfg "he_mu_edca_ac_bk_aci=1" "$N"
  413. append base_cfg "he_mu_edca_ac_bk_ecwmin=9" "$N"
  414. append base_cfg "he_mu_edca_ac_bk_ecwmax=10" "$N"
  415. append base_cfg "he_mu_edca_ac_bk_timer=255" "$N"
  416. append base_cfg "he_mu_edca_ac_vi_ecwmin=5" "$N"
  417. append base_cfg "he_mu_edca_ac_vi_ecwmax=7" "$N"
  418. append base_cfg "he_mu_edca_ac_vi_aifsn=5" "$N"
  419. append base_cfg "he_mu_edca_ac_vi_aci=2" "$N"
  420. append base_cfg "he_mu_edca_ac_vi_timer=255" "$N"
  421. append base_cfg "he_mu_edca_ac_vo_aifsn=5" "$N"
  422. append base_cfg "he_mu_edca_ac_vo_aci=3" "$N"
  423. append base_cfg "he_mu_edca_ac_vo_ecwmin=5" "$N"
  424. append base_cfg "he_mu_edca_ac_vo_ecwmax=7" "$N"
  425. append base_cfg "he_mu_edca_ac_vo_timer=255" "$N"
  426. fi
  427. hostapd_prepare_device_config "$hostapd_conf_file" nl80211
  428. cat >> "$hostapd_conf_file" <<EOF
  429. ${channel:+channel=$channel}
  430. ${channel_list:+chanlist=$channel_list}
  431. ${hostapd_noscan:+noscan=1}
  432. ${tx_burst:+tx_queue_data2_burst=$tx_burst}
  433. $base_cfg
  434. EOF
  435. json_select ..
  436. radio_md5sum=$(md5sum $hostapd_conf_file | cut -d" " -f1)
  437. echo "radio_config_id=${radio_md5sum}" >> $hostapd_conf_file
  438. }
  439. mac80211_hostapd_setup_bss() {
  440. local phy="$1"
  441. local ifname="$2"
  442. local macaddr="$3"
  443. local type="$4"
  444. hostapd_cfg=
  445. append hostapd_cfg "$type=$ifname" "$N"
  446. hostapd_set_bss_options hostapd_cfg "$phy" "$vif" || return 1
  447. json_get_vars wds wds_bridge dtim_period max_listen_int start_disabled
  448. set_default wds 0
  449. set_default start_disabled 0
  450. [ "$wds" -gt 0 ] && {
  451. append hostapd_cfg "wds_sta=1" "$N"
  452. [ -n "$wds_bridge" ] && append hostapd_cfg "wds_bridge=$wds_bridge" "$N"
  453. }
  454. [ "$staidx" -gt 0 -o "$start_disabled" -eq 1 ] && append hostapd_cfg "start_disabled=1" "$N"
  455. cat >> /var/run/hostapd-$phy.conf <<EOF
  456. $hostapd_cfg
  457. bssid=$macaddr
  458. ${dtim_period:+dtim_period=$dtim_period}
  459. ${max_listen_int:+max_listen_interval=$max_listen_int}
  460. EOF
  461. }
  462. mac80211_get_addr() {
  463. local phy="$1"
  464. local idx="$(($2 + 1))"
  465. head -n $idx /sys/class/ieee80211/${phy}/addresses | tail -n1
  466. }
  467. mac80211_generate_mac() {
  468. local phy="$1"
  469. local id="${macidx:-0}"
  470. local ref="$(cat /sys/class/ieee80211/${phy}/macaddress)"
  471. local mask="$(cat /sys/class/ieee80211/${phy}/address_mask)"
  472. [ "$mask" = "00:00:00:00:00:00" ] && {
  473. mask="ff:ff:ff:ff:ff:ff";
  474. [ "$(wc -l < /sys/class/ieee80211/${phy}/addresses)" -gt $id ] && {
  475. addr="$(mac80211_get_addr "$phy" "$id")"
  476. [ -n "$addr" ] && {
  477. echo "$addr"
  478. return
  479. }
  480. }
  481. }
  482. local oIFS="$IFS"; IFS=":"; set -- $mask; IFS="$oIFS"
  483. local mask1=$1
  484. local mask6=$6
  485. local oIFS="$IFS"; IFS=":"; set -- $ref; IFS="$oIFS"
  486. macidx=$(($id + 1))
  487. [ "$((0x$mask1))" -gt 0 ] && {
  488. b1="0x$1"
  489. [ "$id" -gt 0 ] && \
  490. b1=$(($b1 ^ ((($id - !($b1 & 2)) << 2)) | 0x2))
  491. printf "%02x:%s:%s:%s:%s:%s" $b1 $2 $3 $4 $5 $6
  492. return
  493. }
  494. [ "$((0x$mask6))" -lt 255 ] && {
  495. printf "%s:%s:%s:%s:%s:%02x" $1 $2 $3 $4 $5 $(( 0x$6 ^ $id ))
  496. return
  497. }
  498. off2=$(( (0x$6 + $id) / 0x100 ))
  499. printf "%s:%s:%s:%s:%02x:%02x" \
  500. $1 $2 $3 $4 \
  501. $(( (0x$5 + $off2) % 0x100 )) \
  502. $(( (0x$6 + $id) % 0x100 ))
  503. }
  504. get_board_phy_name() (
  505. local path="$1"
  506. local fallback_phy=""
  507. __check_phy() {
  508. local val="$1"
  509. local key="$2"
  510. local ref_path="$3"
  511. json_select "$key"
  512. json_get_values path
  513. json_select ..
  514. [ "${ref_path%+*}" = "$path" ] && fallback_phy=$key
  515. [ "$ref_path" = "$path" ] || return 0
  516. echo "$key"
  517. exit
  518. }
  519. json_load_file /etc/board.json
  520. json_for_each_item __check_phy wlan "$path"
  521. [ -n "$fallback_phy" ] && echo "${fallback_phy}.${path##*+}"
  522. )
  523. rename_board_phy_by_path() {
  524. local path="$1"
  525. local new_phy="$(get_board_phy_name "$path")"
  526. [ -z "$new_phy" -o "$new_phy" = "$phy" ] && return
  527. iw "$phy" set name "$new_phy" && phy="$new_phy"
  528. }
  529. rename_board_phy_by_name() (
  530. local phy="$1"
  531. local suffix="${phy##*.}"
  532. [ "$suffix" = "$phy" ] && suffix=
  533. json_load_file /etc/board.json
  534. json_select wlan
  535. json_select "${phy%.*}" || return 0
  536. json_get_values path
  537. prev_phy="$(iwinfo nl80211 phyname "path=$path${suffix:++$suffix}")"
  538. [ -n "$prev_phy" ] || return 0
  539. [ "$prev_phy" = "$phy" ] && return 0
  540. iw "$prev_phy" set name "$phy"
  541. )
  542. find_phy() {
  543. [ -n "$phy" ] && {
  544. rename_board_phy_by_name "$phy"
  545. [ -d /sys/class/ieee80211/$phy ] && return 0
  546. }
  547. [ -n "$path" ] && {
  548. phy="$(iwinfo nl80211 phyname "path=$path")"
  549. [ -n "$phy" ] && {
  550. rename_board_phy_by_path "$path"
  551. return 0
  552. }
  553. }
  554. [ -n "$macaddr" ] && {
  555. for phy in $(ls /sys/class/ieee80211 2>/dev/null); do
  556. grep -i -q "$macaddr" "/sys/class/ieee80211/${phy}/macaddress" && {
  557. path="$(iwinfo nl80211 path "$phy")"
  558. rename_board_phy_by_path "$path"
  559. return 0
  560. }
  561. done
  562. }
  563. return 1
  564. }
  565. mac80211_check_ap() {
  566. has_ap=1
  567. }
  568. mac80211_set_ifname() {
  569. local phy="$1"
  570. local prefix="$2"
  571. eval "ifname=\"$phy-$prefix\${idx_$prefix:-0}\"; idx_$prefix=\$((\${idx_$prefix:-0 } + 1))"
  572. }
  573. mac80211_prepare_vif() {
  574. json_select config
  575. json_get_vars ifname mode ssid wds powersave macaddr enable wpa_psk_file vlan_file
  576. [ -n "$ifname" ] || {
  577. local prefix;
  578. case "$mode" in
  579. ap|sta|mesh) prefix=$mode;;
  580. adhoc) prefix=ibss;;
  581. monitor) prefix=mon;;
  582. esac
  583. mac80211_set_ifname "$phy" "$prefix"
  584. }
  585. append active_ifnames "$ifname"
  586. set_default wds 0
  587. set_default powersave 0
  588. json_add_string _ifname "$ifname"
  589. if [ -z "$macaddr" ]; then
  590. macaddr="$(mac80211_generate_mac $phy)"
  591. macidx="$(($macidx + 1))"
  592. elif [ "$macaddr" = 'random' ]; then
  593. macaddr="$(macaddr_random)"
  594. fi
  595. json_add_string _macaddr "$macaddr"
  596. json_select ..
  597. [ "$mode" == "ap" ] && {
  598. [ -z "$wpa_psk_file" ] && hostapd_set_psk "$ifname"
  599. [ -z "$vlan_file" ] && hostapd_set_vlan "$ifname"
  600. }
  601. json_select config
  602. # It is far easier to delete and create the desired interface
  603. case "$mode" in
  604. ap)
  605. # Hostapd will handle recreating the interface and
  606. # subsequent virtual APs belonging to the same PHY
  607. if [ -n "$hostapd_ctrl" ]; then
  608. type=bss
  609. else
  610. type=interface
  611. fi
  612. mac80211_hostapd_setup_bss "$phy" "$ifname" "$macaddr" "$type" || return
  613. [ -n "$hostapd_ctrl" ] || {
  614. ap_ifname="${ifname}"
  615. hostapd_ctrl="${hostapd_ctrl:-/var/run/hostapd/$ifname}"
  616. }
  617. ;;
  618. esac
  619. json_select ..
  620. }
  621. mac80211_prepare_iw_htmode() {
  622. case "$htmode" in
  623. VHT20|HT20|HE20) iw_htmode=HT20;;
  624. HT40*|VHT40|VHT160|HE40)
  625. case "$band" in
  626. 2g)
  627. case "$htmode" in
  628. HT40+) iw_htmode="HT40+";;
  629. HT40-) iw_htmode="HT40-";;
  630. *)
  631. if [ "$channel" -lt 7 ]; then
  632. iw_htmode="HT40+"
  633. else
  634. iw_htmode="HT40-"
  635. fi
  636. ;;
  637. esac
  638. ;;
  639. *)
  640. case "$(( ($channel / 4) % 2 ))" in
  641. 1) iw_htmode="HT40+" ;;
  642. 0) iw_htmode="HT40-";;
  643. esac
  644. ;;
  645. esac
  646. [ "$auto_channel" -gt 0 ] && iw_htmode="HT40+"
  647. ;;
  648. VHT80|HE80)
  649. iw_htmode="80MHZ"
  650. ;;
  651. NONE|NOHT)
  652. iw_htmode="NOHT"
  653. ;;
  654. *) iw_htmode="" ;;
  655. esac
  656. }
  657. mac80211_add_mesh_params() {
  658. for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do
  659. eval "mp_val=\"\$var\""
  660. [ -n "$mp_val" ] && json_add_string "$var" "$mp_val"
  661. done
  662. }
  663. mac80211_setup_adhoc() {
  664. local enable=$1
  665. json_get_vars bssid ssid key mcast_rate
  666. NEWUMLIST="${NEWUMLIST}$ifname "
  667. [ "$enable" = 0 ] && {
  668. ip link set dev "$ifname" down
  669. return 0
  670. }
  671. keyspec=
  672. [ "$auth_type" = "wep" ] && {
  673. set_default key 1
  674. case "$key" in
  675. [1234])
  676. local idx
  677. for idx in 1 2 3 4; do
  678. json_get_var ikey "key$idx"
  679. [ -n "$ikey" ] && {
  680. ikey="$(($idx - 1)):$(prepare_key_wep "$ikey")"
  681. [ $idx -eq $key ] && ikey="d:$ikey"
  682. append keyspec "$ikey"
  683. }
  684. done
  685. ;;
  686. *)
  687. append keyspec "d:0:$(prepare_key_wep "$key")"
  688. ;;
  689. esac
  690. }
  691. brstr=
  692. for br in $basic_rate_list; do
  693. wpa_supplicant_add_rate brstr "$br"
  694. done
  695. mcval=
  696. [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
  697. local prev
  698. json_set_namespace wdev_uc prev
  699. json_add_object "$ifname"
  700. json_add_string mode adhoc
  701. json_add_string macaddr "$macaddr"
  702. json_add_string ssid "$ssid"
  703. json_add_string freq "$freq"
  704. json_add_string htmode "$iw_htmode"
  705. [ -n "$bssid" ] && json_add_string bssid "$bssid"
  706. json_add_int beacon-interval "$beacon_int"
  707. [ -n "$brstr" ] && json_add_string basic-rates "$brstr"
  708. [ -n "$mcval" ] && json_add_string mcast-rate "$mcval"
  709. [ -n "$keyspec" ] && json_add_string keys "$keyspec"
  710. json_close_object
  711. json_set_namespace "$prev"
  712. }
  713. mac80211_setup_mesh() {
  714. json_get_vars ssid mesh_id mcast_rate
  715. mcval=
  716. [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
  717. [ -n "$mesh_id" ] && ssid="$mesh_id"
  718. local prev
  719. json_set_namespace wdev_uc prev
  720. json_add_object "$ifname"
  721. json_add_string mode mesh
  722. json_add_string macaddr "$macaddr"
  723. json_add_string ssid "$ssid"
  724. json_add_string freq "$freq"
  725. json_add_string htmode "$iw_htmode"
  726. [ -n "$mcval" ] && json_add_string mcast-rate "$mcval"
  727. json_add_int beacon-interval "$beacon_int"
  728. mac80211_add_mesh_params
  729. json_close_object
  730. json_set_namespace "$prev"
  731. }
  732. mac80211_setup_monitor() {
  733. local prev
  734. json_set_namespace wdev_uc prev
  735. json_add_object "$ifname"
  736. json_add_string mode monitor
  737. [ -n "$freq" ] && json_add_string freq "$freq"
  738. json_add_string htmode "$iw_htmode"
  739. json_close_object
  740. json_set_namespace "$prev"
  741. }
  742. mac80211_set_vif_txpower() {
  743. local name="$1"
  744. json_select config
  745. json_get_var ifname _ifname
  746. json_get_vars vif_txpower
  747. json_select ..
  748. [ -z "$vif_txpower" ] || iw dev "$ifname" set txpower fixed "${vif_txpower%%.*}00"
  749. }
  750. wpa_supplicant_init_config() {
  751. json_set_namespace wpa_supp prev
  752. json_init
  753. json_add_array config
  754. json_set_namespace "$prev"
  755. }
  756. wpa_supplicant_add_interface() {
  757. local ifname="$1"
  758. local mode="$2"
  759. local hostapd_ctrl="$3"
  760. local prev
  761. _wpa_supplicant_common "$ifname"
  762. json_set_namespace wpa_supp prev
  763. json_add_object
  764. json_add_string ctrl "$_rpath"
  765. json_add_string iface "$ifname"
  766. json_add_string mode "$mode"
  767. json_add_string config "$_config"
  768. json_add_string macaddr "$macaddr"
  769. [ -n "$network_bridge" ] && json_add_string bridge "$network_bridge"
  770. [ -n "$hostapd_ctrl" ] && json_add_string hostapd_ctrl "$hostapd_ctrl"
  771. [ -n "$wds" ] && json_add_boolean 4addr "$wds"
  772. json_add_boolean powersave "$powersave"
  773. [ "$mode" = "mesh" ] && mac80211_add_mesh_params
  774. json_close_object
  775. json_set_namespace "$prev"
  776. wpa_supp_init=1
  777. }
  778. wpa_supplicant_set_config() {
  779. local phy="$1"
  780. local prev
  781. json_set_namespace wpa_supp prev
  782. json_close_array
  783. json_add_string phy "$phy"
  784. json_add_boolean defer 1
  785. local data="$(json_dump)"
  786. json_cleanup
  787. json_set_namespace "$prev"
  788. ubus -S -t 0 wait_for wpa_supplicant || {
  789. [ -n "$wpa_supp_init" ] || return 0
  790. ubus wait_for wpa_supplicant
  791. }
  792. local supplicant_res="$(ubus call wpa_supplicant config_set "$data")"
  793. ret="$?"
  794. [ "$ret" != 0 -o -z "$supplicant_res" ] && wireless_setup_vif_failed WPA_SUPPLICANT_FAILED
  795. wireless_add_process "$(jsonfilter -s "$supplicant_res" -l 1 -e @.pid)" "/usr/sbin/wpa_supplicant" 1 1
  796. }
  797. hostapd_set_config() {
  798. [ -n "$hostapd_ctrl" ] || {
  799. ubus call hostapd config_set '{ "phy": "'"$phy"'", "config": "", "prev_config": "'"${hostapd_conf_file}.prev"'" }' > /dev/null
  800. return 0;
  801. }
  802. ubus wait_for hostapd
  803. local hostapd_res="$(ubus call hostapd config_set "{ \"phy\": \"$phy\", \"config\":\"${hostapd_conf_file}\", \"prev_config\": \"${hostapd_conf_file}.prev\"}")"
  804. ret="$?"
  805. [ "$ret" != 0 -o -z "$hostapd_res" ] && {
  806. wireless_setup_failed HOSTAPD_START_FAILED
  807. return
  808. }
  809. wireless_add_process "$(jsonfilter -s "$hostapd_res" -l 1 -e @.pid)" "/usr/sbin/hostapd" 1 1
  810. }
  811. wpa_supplicant_start() {
  812. local phy="$1"
  813. [ -n "$wpa_supp_init" ] || return 0
  814. ubus call wpa_supplicant config_set '{ "phy": "'"$phy"'" }' > /dev/null
  815. }
  816. mac80211_setup_supplicant() {
  817. local enable=$1
  818. local add_sp=0
  819. wpa_supplicant_prepare_interface "$ifname" nl80211 || return 1
  820. if [ "$mode" = "sta" ]; then
  821. wpa_supplicant_add_network "$ifname"
  822. else
  823. wpa_supplicant_add_network "$ifname" "$freq" "$htmode" "$noscan"
  824. fi
  825. wpa_supplicant_add_interface "$ifname" "$mode" "$hostapd_ctrl"
  826. return 0
  827. }
  828. mac80211_setup_vif() {
  829. local name="$1"
  830. local failed
  831. json_select config
  832. json_get_var ifname _ifname
  833. json_get_var macaddr _macaddr
  834. json_get_vars mode wds powersave
  835. set_default powersave 0
  836. set_default wds 0
  837. case "$mode" in
  838. mesh)
  839. json_get_vars $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING
  840. wireless_vif_parse_encryption
  841. [ -z "$htmode" ] && htmode="NOHT";
  842. if wpa_supplicant -vmesh; then
  843. mac80211_setup_supplicant || failed=1
  844. else
  845. mac80211_setup_mesh
  846. fi
  847. ;;
  848. adhoc)
  849. wireless_vif_parse_encryption
  850. if [ "$wpa" -gt 0 -o "$auto_channel" -gt 0 ]; then
  851. mac80211_setup_supplicant || failed=1
  852. else
  853. mac80211_setup_adhoc
  854. fi
  855. ;;
  856. sta)
  857. mac80211_setup_supplicant || failed=1
  858. ;;
  859. monitor)
  860. mac80211_setup_monitor
  861. ;;
  862. esac
  863. json_select ..
  864. [ -n "$failed" ] || wireless_add_vif "$name" "$ifname"
  865. }
  866. get_freq() {
  867. local phy="$1"
  868. local channel="$2"
  869. local band="$3"
  870. case "$band" in
  871. 2g) band="1:";;
  872. 5g) band="2:";;
  873. 60g) band="3:";;
  874. 6g) band="4:";;
  875. esac
  876. iw "$phy" info | awk -v band="$band" -v channel="[$channel]" '
  877. $1 ~ /Band/ {
  878. band_match = band == $2
  879. }
  880. band_match && $3 == "MHz" && $4 == channel {
  881. print $2
  882. exit
  883. }
  884. '
  885. }
  886. chan_is_dfs() {
  887. local phy="$1"
  888. local chan="$2"
  889. iw "$phy" info | grep -E -m1 "(\* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep -q "MHz.*radar detection"
  890. return $!
  891. }
  892. mac80211_set_noscan() {
  893. hostapd_noscan=1
  894. }
  895. drv_mac80211_cleanup() {
  896. hostapd_common_cleanup
  897. }
  898. mac80211_reset_config() {
  899. local phy="$1"
  900. hostapd_conf_file="/var/run/hostapd-$phy.conf"
  901. ubus call hostapd config_set '{ "phy": "'"$phy"'", "config": "", "prev_config": "'"$hostapd_conf_file"'" }' > /dev/null
  902. ubus call wpa_supplicant config_set '{ "phy": "'"$phy"'", "config": [] }' > /dev/null
  903. wdev_tool "$phy" '{}'
  904. }
  905. drv_mac80211_setup() {
  906. json_select config
  907. json_get_vars \
  908. phy macaddr path \
  909. country chanbw distance \
  910. txpower antenna_gain \
  911. rxantenna txantenna \
  912. frag rts beacon_int:100 htmode
  913. json_get_values basic_rate_list basic_rate
  914. json_get_values scan_list scan_list
  915. json_select ..
  916. json_select data && {
  917. json_get_var prev_rxantenna rxantenna
  918. json_get_var prev_txantenna txantenna
  919. json_select ..
  920. }
  921. find_phy || {
  922. echo "Could not find PHY for device '$1'"
  923. wireless_set_retry 0
  924. return 1
  925. }
  926. local wdev
  927. local cwdev
  928. local found
  929. # convert channel to frequency
  930. [ "$auto_channel" -gt 0 ] || freq="$(get_freq "$phy" "$channel" "$band")"
  931. [ -n "$country" ] && {
  932. iw reg get | grep -q "^country $country:" || {
  933. iw reg set "$country"
  934. sleep 1
  935. }
  936. }
  937. hostapd_conf_file="/var/run/hostapd-$phy.conf"
  938. macidx=0
  939. staidx=0
  940. [ -n "$chanbw" ] && {
  941. for file in /sys/kernel/debug/ieee80211/$phy/ath9k*/chanbw /sys/kernel/debug/ieee80211/$phy/ath5k/bwmode; do
  942. [ -f "$file" ] && echo "$chanbw" > "$file"
  943. done
  944. }
  945. set_default rxantenna 0xffffffff
  946. set_default txantenna 0xffffffff
  947. set_default distance 0
  948. set_default antenna_gain 0
  949. [ "$txantenna" = "all" ] && txantenna=0xffffffff
  950. [ "$rxantenna" = "all" ] && rxantenna=0xffffffff
  951. [ "$rxantenna" = "$prev_rxantenna" -a "$txantenna" = "$prev_txantenna" ] || mac80211_reset_config "$phy"
  952. wireless_set_data phy="$phy" txantenna="$txantenna" rxantenna="$rxantenna"
  953. iw phy "$phy" set antenna $txantenna $rxantenna >/dev/null 2>&1
  954. iw phy "$phy" set antenna_gain $antenna_gain >/dev/null 2>&1
  955. iw phy "$phy" set distance "$distance" >/dev/null 2>&1
  956. if [ -n "$txpower" ]; then
  957. iw phy "$phy" set txpower fixed "${txpower%%.*}00"
  958. else
  959. iw phy "$phy" set txpower auto
  960. fi
  961. [ -n "$frag" ] && iw phy "$phy" set frag "${frag%%.*}"
  962. [ -n "$rts" ] && iw phy "$phy" set rts "${rts%%.*}"
  963. has_ap=
  964. hostapd_ctrl=
  965. ap_ifname=
  966. hostapd_noscan=
  967. wpa_supp_init=
  968. for_each_interface "ap" mac80211_check_ap
  969. [ -f "$hostapd_conf_file" ] && mv "$hostapd_conf_file" "$hostapd_conf_file.prev"
  970. for_each_interface "sta adhoc mesh" mac80211_set_noscan
  971. [ -n "$has_ap" ] && mac80211_hostapd_setup_base "$phy"
  972. local prev
  973. json_set_namespace wdev_uc prev
  974. json_init
  975. json_set_namespace "$prev"
  976. wpa_supplicant_init_config
  977. mac80211_prepare_iw_htmode
  978. active_ifnames=
  979. for_each_interface "ap sta adhoc mesh monitor" mac80211_prepare_vif
  980. for_each_interface "ap sta adhoc mesh monitor" mac80211_setup_vif
  981. [ -x /usr/sbin/wpa_supplicant ] && wpa_supplicant_set_config "$phy"
  982. [ -x /usr/sbin/hostapd ] && hostapd_set_config "$phy"
  983. [ -x /usr/sbin/wpa_supplicant ] && wpa_supplicant_start "$phy"
  984. json_set_namespace wdev_uc prev
  985. wdev_tool "$phy" "$(json_dump)" $active_ifnames
  986. json_set_namespace "$prev"
  987. for_each_interface "ap sta adhoc mesh monitor" mac80211_set_vif_txpower
  988. wireless_set_up
  989. }
  990. _list_phy_interfaces() {
  991. local phy="$1"
  992. if [ -d "/sys/class/ieee80211/${phy}/device/net" ]; then
  993. ls "/sys/class/ieee80211/${phy}/device/net" 2>/dev/null;
  994. else
  995. ls "/sys/class/ieee80211/${phy}/device" 2>/dev/null | grep net: | sed -e 's,net:,,g'
  996. fi
  997. }
  998. list_phy_interfaces() {
  999. local phy="$1"
  1000. for dev in $(_list_phy_interfaces "$phy"); do
  1001. readlink "/sys/class/net/${dev}/phy80211" | grep -q "/${phy}\$" || continue
  1002. echo "$dev"
  1003. done
  1004. }
  1005. drv_mac80211_teardown() {
  1006. json_select data
  1007. json_get_vars phy
  1008. json_select ..
  1009. [ -n "$phy" ] || {
  1010. echo "Bug: PHY is undefined for device '$1'"
  1011. return 1
  1012. }
  1013. mac80211_reset_config "$phy"
  1014. for wdev in $(list_phy_interfaces "$phy"); do
  1015. ip link set dev "$wdev" down
  1016. iw dev "$wdev" del
  1017. done
  1018. }
  1019. add_driver mac80211