mac80211.sh 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221
  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 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. }
  437. mac80211_hostapd_setup_bss() {
  438. local phy="$1"
  439. local ifname="$2"
  440. local macaddr="$3"
  441. local type="$4"
  442. hostapd_cfg=
  443. append hostapd_cfg "$type=$ifname" "$N"
  444. hostapd_set_bss_options hostapd_cfg "$phy" "$vif" || return 1
  445. json_get_vars wds wds_bridge dtim_period max_listen_int start_disabled
  446. set_default wds 0
  447. set_default start_disabled 0
  448. [ "$wds" -gt 0 ] && {
  449. append hostapd_cfg "wds_sta=1" "$N"
  450. [ -n "$wds_bridge" ] && append hostapd_cfg "wds_bridge=$wds_bridge" "$N"
  451. }
  452. [ "$staidx" -gt 0 -o "$start_disabled" -eq 1 ] && append hostapd_cfg "start_disabled=1" "$N"
  453. cat >> /var/run/hostapd-$phy.conf <<EOF
  454. $hostapd_cfg
  455. bssid=$macaddr
  456. ${dtim_period:+dtim_period=$dtim_period}
  457. ${max_listen_int:+max_listen_interval=$max_listen_int}
  458. EOF
  459. }
  460. mac80211_get_addr() {
  461. local phy="$1"
  462. local idx="$(($2 + 1))"
  463. head -n $idx /sys/class/ieee80211/${phy}/addresses | tail -n1
  464. }
  465. mac80211_generate_mac() {
  466. local phy="$1"
  467. local id="${macidx:-0}"
  468. local ref="$(cat /sys/class/ieee80211/${phy}/macaddress)"
  469. local mask="$(cat /sys/class/ieee80211/${phy}/address_mask)"
  470. [ "$mask" = "00:00:00:00:00:00" ] && {
  471. mask="ff:ff:ff:ff:ff:ff";
  472. [ "$(wc -l < /sys/class/ieee80211/${phy}/addresses)" -gt $id ] && {
  473. addr="$(mac80211_get_addr "$phy" "$id")"
  474. [ -n "$addr" ] && {
  475. echo "$addr"
  476. return
  477. }
  478. }
  479. }
  480. local oIFS="$IFS"; IFS=":"; set -- $mask; IFS="$oIFS"
  481. local mask1=$1
  482. local mask6=$6
  483. local oIFS="$IFS"; IFS=":"; set -- $ref; IFS="$oIFS"
  484. macidx=$(($id + 1))
  485. [ "$((0x$mask1))" -gt 0 ] && {
  486. b1="0x$1"
  487. [ "$id" -gt 0 ] && \
  488. b1=$(($b1 ^ ((($id - !($b1 & 2)) << 2)) | 0x2))
  489. printf "%02x:%s:%s:%s:%s:%s" $b1 $2 $3 $4 $5 $6
  490. return
  491. }
  492. [ "$((0x$mask6))" -lt 255 ] && {
  493. printf "%s:%s:%s:%s:%s:%02x" $1 $2 $3 $4 $5 $(( 0x$6 ^ $id ))
  494. return
  495. }
  496. off2=$(( (0x$6 + $id) / 0x100 ))
  497. printf "%s:%s:%s:%s:%02x:%02x" \
  498. $1 $2 $3 $4 \
  499. $(( (0x$5 + $off2) % 0x100 )) \
  500. $(( (0x$6 + $id) % 0x100 ))
  501. }
  502. get_board_phy_name() (
  503. local path="$1"
  504. local fallback_phy=""
  505. __check_phy() {
  506. local val="$1"
  507. local key="$2"
  508. local ref_path="$3"
  509. json_select "$key"
  510. json_get_values path
  511. json_select ..
  512. [ "${ref_path%+*}" = "$path" ] && fallback_phy=$key
  513. [ "$ref_path" = "$path" ] || return 0
  514. echo "$key"
  515. exit
  516. }
  517. json_load_file /etc/board.json
  518. json_for_each_item __check_phy wlan "$path"
  519. [ -n "$fallback_phy" ] && echo "${fallback_phy}.${path##*+}"
  520. )
  521. rename_board_phy_by_path() {
  522. local path="$1"
  523. local new_phy="$(get_board_phy_name "$path")"
  524. [ -z "$new_phy" -o "$new_phy" = "$phy" ] && return
  525. iw "$phy" set name "$new_phy" && phy="$new_phy"
  526. }
  527. rename_board_phy_by_name() (
  528. local phy="$1"
  529. local suffix="${phy##*.}"
  530. [ "$suffix" = "$phy" ] && suffix=
  531. json_load_file /etc/board.json
  532. json_select wlan
  533. json_select "${phy%.*}" || return 0
  534. json_get_values path
  535. prev_phy="$(iwinfo nl80211 phyname "path=$path${suffix:++$suffix}")"
  536. [ -n "$prev_phy" ] || return 0
  537. [ "$prev_phy" = "$phy" ] && return 0
  538. iw "$prev_phy" set name "$phy"
  539. )
  540. find_phy() {
  541. [ -n "$phy" ] && {
  542. rename_board_phy_by_name "$phy"
  543. [ -d /sys/class/ieee80211/$phy ] && return 0
  544. }
  545. [ -n "$path" ] && {
  546. phy="$(iwinfo nl80211 phyname "path=$path")"
  547. [ -n "$phy" ] && {
  548. rename_board_phy_by_path "$path"
  549. return 0
  550. }
  551. }
  552. [ -n "$macaddr" ] && {
  553. for phy in $(ls /sys/class/ieee80211 2>/dev/null); do
  554. grep -i -q "$macaddr" "/sys/class/ieee80211/${phy}/macaddress" && {
  555. path="$(iwinfo nl80211 path "$phy")"
  556. rename_board_phy_by_path "$path"
  557. return 0
  558. }
  559. done
  560. }
  561. return 1
  562. }
  563. mac80211_check_ap() {
  564. has_ap=1
  565. }
  566. mac80211_set_ifname() {
  567. local phy="$1"
  568. local prefix="$2"
  569. eval "ifname=\"$phy-$prefix\${idx_$prefix:-0}\"; idx_$prefix=\$((\${idx_$prefix:-0 } + 1))"
  570. }
  571. mac80211_prepare_vif() {
  572. json_select config
  573. json_get_vars ifname mode ssid wds powersave macaddr enable wpa_psk_file vlan_file
  574. [ -n "$ifname" ] || {
  575. local prefix;
  576. case "$mode" in
  577. ap|sta|mesh) prefix=$mode;;
  578. adhoc) prefix=ibss;;
  579. monitor) prefix=mon;;
  580. esac
  581. mac80211_set_ifname "$phy" "$prefix"
  582. }
  583. append active_ifnames "$ifname"
  584. set_default wds 0
  585. set_default powersave 0
  586. json_add_string _ifname "$ifname"
  587. if [ -z "$macaddr" ]; then
  588. macaddr="$(mac80211_generate_mac $phy)"
  589. macidx="$(($macidx + 1))"
  590. elif [ "$macaddr" = 'random' ]; then
  591. macaddr="$(macaddr_random)"
  592. fi
  593. json_add_string _macaddr "$macaddr"
  594. json_select ..
  595. [ "$mode" == "ap" ] && {
  596. [ -z "$wpa_psk_file" ] && hostapd_set_psk "$ifname"
  597. [ -z "$vlan_file" ] && hostapd_set_vlan "$ifname"
  598. }
  599. json_select config
  600. # It is far easier to delete and create the desired interface
  601. case "$mode" in
  602. ap)
  603. # Hostapd will handle recreating the interface and
  604. # subsequent virtual APs belonging to the same PHY
  605. if [ -n "$hostapd_ctrl" ]; then
  606. type=bss
  607. else
  608. type=interface
  609. fi
  610. mac80211_hostapd_setup_bss "$phy" "$ifname" "$macaddr" "$type" || return
  611. [ -n "$hostapd_ctrl" ] || {
  612. ap_ifname="${ifname}"
  613. hostapd_ctrl="${hostapd_ctrl:-/var/run/hostapd/$ifname}"
  614. }
  615. ;;
  616. esac
  617. json_select ..
  618. }
  619. mac80211_prepare_iw_htmode() {
  620. case "$htmode" in
  621. VHT20|HT20|HE20) iw_htmode=HT20;;
  622. HT40*|VHT40|VHT160|HE40)
  623. case "$band" in
  624. 2g)
  625. case "$htmode" in
  626. HT40+) iw_htmode="HT40+";;
  627. HT40-) iw_htmode="HT40-";;
  628. *)
  629. if [ "$channel" -lt 7 ]; then
  630. iw_htmode="HT40+"
  631. else
  632. iw_htmode="HT40-"
  633. fi
  634. ;;
  635. esac
  636. ;;
  637. *)
  638. case "$(( ($channel / 4) % 2 ))" in
  639. 1) iw_htmode="HT40+" ;;
  640. 0) iw_htmode="HT40-";;
  641. esac
  642. ;;
  643. esac
  644. [ "$auto_channel" -gt 0 ] && iw_htmode="HT40+"
  645. ;;
  646. VHT80|HE80)
  647. iw_htmode="80MHZ"
  648. ;;
  649. NONE|NOHT)
  650. iw_htmode="NOHT"
  651. ;;
  652. *) iw_htmode="" ;;
  653. esac
  654. }
  655. mac80211_add_mesh_params() {
  656. for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do
  657. eval "mp_val=\"\$$var\""
  658. [ -n "$mp_val" ] && json_add_string "$var" "$mp_val"
  659. done
  660. }
  661. mac80211_setup_adhoc() {
  662. local enable=$1
  663. json_get_vars bssid ssid key mcast_rate
  664. NEWUMLIST="${NEWUMLIST}$ifname "
  665. [ "$enable" = 0 ] && {
  666. ip link set dev "$ifname" down
  667. return 0
  668. }
  669. keyspec=
  670. [ "$auth_type" = "wep" ] && {
  671. set_default key 1
  672. case "$key" in
  673. [1234])
  674. local idx
  675. for idx in 1 2 3 4; do
  676. json_get_var ikey "key$idx"
  677. [ -n "$ikey" ] && {
  678. ikey="$(($idx - 1)):$(prepare_key_wep "$ikey")"
  679. [ $idx -eq $key ] && ikey="d:$ikey"
  680. append keyspec "$ikey"
  681. }
  682. done
  683. ;;
  684. *)
  685. append keyspec "d:0:$(prepare_key_wep "$key")"
  686. ;;
  687. esac
  688. }
  689. brstr=
  690. for br in $basic_rate_list; do
  691. wpa_supplicant_add_rate brstr "$br"
  692. done
  693. mcval=
  694. [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
  695. local prev
  696. json_set_namespace wdev_uc prev
  697. json_add_object "$ifname"
  698. json_add_string mode adhoc
  699. json_add_string macaddr "$macaddr"
  700. json_add_string ssid "$ssid"
  701. json_add_string freq "$freq"
  702. json_add_string htmode "$iw_htmode"
  703. [ -n "$bssid" ] && json_add_string bssid "$bssid"
  704. json_add_int beacon-interval "$beacon_int"
  705. [ -n "$brstr" ] && json_add_string basic-rates "$brstr"
  706. [ -n "$mcval" ] && json_add_string mcast-rate "$mcval"
  707. [ -n "$keyspec" ] && json_add_string keys "$keyspec"
  708. json_close_object
  709. json_set_namespace "$prev"
  710. }
  711. mac80211_setup_mesh() {
  712. json_get_vars ssid mesh_id mcast_rate
  713. mcval=
  714. [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate"
  715. [ -n "$mesh_id" ] && ssid="$mesh_id"
  716. local prev
  717. json_set_namespace wdev_uc prev
  718. json_add_object "$ifname"
  719. json_add_string mode mesh
  720. json_add_string macaddr "$macaddr"
  721. json_add_string ssid "$ssid"
  722. json_add_string freq "$freq"
  723. json_add_string htmode "$iw_htmode"
  724. [ -n "$mcval" ] && json_add_string mcast-rate "$mcval"
  725. json_add_int beacon-interval "$beacon_int"
  726. mac80211_add_mesh_params
  727. json_close_object
  728. json_set_namespace "$prev"
  729. }
  730. mac80211_setup_monitor() {
  731. local prev
  732. json_set_namespace wdev_uc prev
  733. json_add_object "$ifname"
  734. json_add_string mode monitor
  735. [ -n "$freq" ] && json_add_string freq "$freq"
  736. json_add_string htmode "$iw_htmode"
  737. json_close_object
  738. json_set_namespace "$prev"
  739. }
  740. mac80211_set_vif_txpower() {
  741. local name="$1"
  742. json_select config
  743. json_get_var ifname _ifname
  744. json_get_vars vif_txpower
  745. json_select ..
  746. [ -z "$vif_txpower" ] || iw dev "$ifname" set txpower fixed "${vif_txpower%%.*}00"
  747. }
  748. wpa_supplicant_init_config() {
  749. json_set_namespace wpa_supp prev
  750. json_init
  751. json_add_array config
  752. json_set_namespace "$prev"
  753. }
  754. wpa_supplicant_add_interface() {
  755. local ifname="$1"
  756. local mode="$2"
  757. local hostapd_ctrl="$3"
  758. local prev
  759. _wpa_supplicant_common "$ifname"
  760. json_set_namespace wpa_supp prev
  761. json_add_object
  762. json_add_string ctrl "$_rpath"
  763. json_add_string iface "$ifname"
  764. json_add_string mode "$mode"
  765. json_add_string config "$_config"
  766. json_add_string macaddr "$macaddr"
  767. [ -n "$network_bridge" ] && json_add_string bridge "$network_bridge"
  768. [ -n "$hostapd_ctrl" ] && json_add_string hostapd_ctrl "$hostapd_ctrl"
  769. [ -n "$wds" ] && json_add_boolean 4addr "$wds"
  770. json_add_boolean powersave "$powersave"
  771. [ "$mode" = "mesh" ] && mac80211_add_mesh_params
  772. json_close_object
  773. json_set_namespace "$prev"
  774. wpa_supp_init=1
  775. }
  776. wpa_supplicant_set_config() {
  777. local phy="$1"
  778. local prev
  779. json_set_namespace wpa_supp prev
  780. json_close_array
  781. json_add_string phy "$phy"
  782. json_add_boolean defer 1
  783. local data="$(json_dump)"
  784. json_cleanup
  785. json_set_namespace "$prev"
  786. ubus -S -t 0 wait_for wpa_supplicant || {
  787. [ -n "$wpa_supp_init" ] || return 0
  788. ubus wait_for wpa_supplicant
  789. }
  790. local supplicant_res="$(ubus call wpa_supplicant config_set "$data")"
  791. ret="$?"
  792. [ "$ret" != 0 -o -z "$supplicant_res" ] && wireless_setup_vif_failed WPA_SUPPLICANT_FAILED
  793. wireless_add_process "$(jsonfilter -s "$supplicant_res" -l 1 -e @.pid)" "/usr/sbin/wpa_supplicant" 1 1
  794. }
  795. hostapd_set_config() {
  796. [ -n "$hostapd_ctrl" ] || {
  797. ubus call hostapd config_set '{ "phy": "'"$phy"'", "config": "", "prev_config": "'"${hostapd_conf_file}.prev"'" }' > /dev/null
  798. return 0;
  799. }
  800. ubus wait_for hostapd
  801. local hostapd_res="$(ubus call hostapd config_set "{ \"phy\": \"$phy\", \"config\":\"${hostapd_conf_file}\", \"prev_config\": \"${hostapd_conf_file}.prev\"}")"
  802. ret="$?"
  803. [ "$ret" != 0 -o -z "$hostapd_res" ] && {
  804. wireless_setup_failed HOSTAPD_START_FAILED
  805. return
  806. }
  807. wireless_add_process "$(jsonfilter -s "$hostapd_res" -l 1 -e @.pid)" "/usr/sbin/hostapd" 1 1
  808. }
  809. wpa_supplicant_start() {
  810. local phy="$1"
  811. [ -n "$wpa_supp_init" ] || return 0
  812. ubus call wpa_supplicant config_set '{ "phy": "'"$phy"'" }' > /dev/null
  813. }
  814. mac80211_setup_supplicant() {
  815. local enable=$1
  816. local add_sp=0
  817. wpa_supplicant_prepare_interface "$ifname" nl80211 || return 1
  818. if [ "$mode" = "sta" ]; then
  819. wpa_supplicant_add_network "$ifname"
  820. else
  821. wpa_supplicant_add_network "$ifname" "$freq" "$htmode" "$noscan"
  822. fi
  823. wpa_supplicant_add_interface "$ifname" "$mode" "$hostapd_ctrl"
  824. return 0
  825. }
  826. mac80211_setup_vif() {
  827. local name="$1"
  828. local failed
  829. json_select config
  830. json_get_var ifname _ifname
  831. json_get_var macaddr _macaddr
  832. json_get_vars mode wds powersave
  833. set_default powersave 0
  834. set_default wds 0
  835. case "$mode" in
  836. mesh)
  837. json_get_vars $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING
  838. wireless_vif_parse_encryption
  839. [ -z "$htmode" ] && htmode="NOHT";
  840. if wpa_supplicant -vmesh; then
  841. mac80211_setup_supplicant || failed=1
  842. else
  843. mac80211_setup_mesh
  844. fi
  845. ;;
  846. adhoc)
  847. wireless_vif_parse_encryption
  848. if [ "$wpa" -gt 0 -o "$auto_channel" -gt 0 ]; then
  849. mac80211_setup_supplicant || failed=1
  850. else
  851. mac80211_setup_adhoc
  852. fi
  853. ;;
  854. sta)
  855. mac80211_setup_supplicant || failed=1
  856. ;;
  857. monitor)
  858. mac80211_setup_monitor
  859. ;;
  860. esac
  861. json_select ..
  862. [ -n "$failed" ] || wireless_add_vif "$name" "$ifname"
  863. }
  864. get_freq() {
  865. local phy="$1"
  866. local channel="$2"
  867. local band="$3"
  868. case "$band" in
  869. 2g) band="1:";;
  870. 5g) band="2:";;
  871. 60g) band="3:";;
  872. 6g) band="4:";;
  873. esac
  874. iw "$phy" info | awk -v band="$band" -v channel="[$channel]" '
  875. $1 ~ /Band/ {
  876. band_match = band == $2
  877. }
  878. band_match && $3 == "MHz" && $4 == channel {
  879. print $2
  880. exit
  881. }
  882. '
  883. }
  884. chan_is_dfs() {
  885. local phy="$1"
  886. local chan="$2"
  887. iw "$phy" info | grep -E -m1 "(\* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep -q "MHz.*radar detection"
  888. return $!
  889. }
  890. mac80211_set_noscan() {
  891. hostapd_noscan=1
  892. }
  893. drv_mac80211_cleanup() {
  894. hostapd_common_cleanup
  895. }
  896. mac80211_reset_config() {
  897. local phy="$1"
  898. hostapd_conf_file="/var/run/hostapd-$phy.conf"
  899. ubus call hostapd config_set '{ "phy": "'"$phy"'", "config": "", "prev_config": "'"$hostapd_conf_file"'" }' > /dev/null
  900. ubus call wpa_supplicant config_set '{ "phy": "'"$phy"'", "config": [] }' > /dev/null
  901. wdev_tool "$phy" '{}'
  902. }
  903. drv_mac80211_setup() {
  904. json_select config
  905. json_get_vars \
  906. phy macaddr path \
  907. country chanbw distance \
  908. txpower \
  909. rxantenna txantenna \
  910. frag rts beacon_int:100 htmode
  911. json_get_values basic_rate_list basic_rate
  912. json_get_values scan_list scan_list
  913. json_select ..
  914. json_select data && {
  915. json_get_var prev_rxantenna rxantenna
  916. json_get_var prev_txantenna txantenna
  917. json_select ..
  918. }
  919. find_phy || {
  920. echo "Could not find PHY for device '$1'"
  921. wireless_set_retry 0
  922. return 1
  923. }
  924. local wdev
  925. local cwdev
  926. local found
  927. # convert channel to frequency
  928. [ "$auto_channel" -gt 0 ] || freq="$(get_freq "$phy" "$channel" "$band")"
  929. [ -n "$country" ] && {
  930. iw reg get | grep -q "^country $country:" || {
  931. iw reg set "$country"
  932. sleep 1
  933. }
  934. }
  935. hostapd_conf_file="/var/run/hostapd-$phy.conf"
  936. macidx=0
  937. staidx=0
  938. [ -n "$chanbw" ] && {
  939. for file in /sys/kernel/debug/ieee80211/$phy/ath9k*/chanbw /sys/kernel/debug/ieee80211/$phy/ath5k/bwmode; do
  940. [ -f "$file" ] && echo "$chanbw" > "$file"
  941. done
  942. }
  943. set_default rxantenna 0xffffffff
  944. set_default txantenna 0xffffffff
  945. set_default distance 0
  946. [ "$txantenna" = "all" ] && txantenna=0xffffffff
  947. [ "$rxantenna" = "all" ] && rxantenna=0xffffffff
  948. [ "$rxantenna" = "$prev_rxantenna" -a "$txantenna" = "$prev_txantenna" ] || mac80211_reset_config "$phy"
  949. wireless_set_data phy="$phy" txantenna="$txantenna" rxantenna="$rxantenna"
  950. iw phy "$phy" set antenna $txantenna $rxantenna >/dev/null 2>&1
  951. iw phy "$phy" set distance "$distance" >/dev/null 2>&1
  952. if [ -n "$txpower" ]; then
  953. iw phy "$phy" set txpower fixed "${txpower%%.*}00"
  954. else
  955. iw phy "$phy" set txpower auto
  956. fi
  957. [ -n "$frag" ] && iw phy "$phy" set frag "${frag%%.*}"
  958. [ -n "$rts" ] && iw phy "$phy" set rts "${rts%%.*}"
  959. has_ap=
  960. hostapd_ctrl=
  961. ap_ifname=
  962. hostapd_noscan=
  963. wpa_supp_init=
  964. for_each_interface "ap" mac80211_check_ap
  965. [ -f "$hostapd_conf_file" ] && mv "$hostapd_conf_file" "$hostapd_conf_file.prev"
  966. for_each_interface "sta adhoc mesh" mac80211_set_noscan
  967. [ -n "$has_ap" ] && mac80211_hostapd_setup_base "$phy"
  968. local prev
  969. json_set_namespace wdev_uc prev
  970. json_init
  971. json_set_namespace "$prev"
  972. wpa_supplicant_init_config
  973. mac80211_prepare_iw_htmode
  974. active_ifnames=
  975. for_each_interface "ap sta adhoc mesh monitor" mac80211_prepare_vif
  976. for_each_interface "ap sta adhoc mesh monitor" mac80211_setup_vif
  977. [ -x /usr/sbin/wpa_supplicant ] && wpa_supplicant_set_config "$phy"
  978. [ -x /usr/sbin/hostapd ] && hostapd_set_config "$phy"
  979. [ -x /usr/sbin/wpa_supplicant ] && wpa_supplicant_start "$phy"
  980. json_set_namespace wdev_uc prev
  981. wdev_tool "$phy" "$(json_dump)" $active_ifnames
  982. json_set_namespace "$prev"
  983. for_each_interface "ap sta adhoc mesh monitor" mac80211_set_vif_txpower
  984. wireless_set_up
  985. }
  986. _list_phy_interfaces() {
  987. local phy="$1"
  988. if [ -d "/sys/class/ieee80211/${phy}/device/net" ]; then
  989. ls "/sys/class/ieee80211/${phy}/device/net" 2>/dev/null;
  990. else
  991. ls "/sys/class/ieee80211/${phy}/device" 2>/dev/null | grep net: | sed -e 's,net:,,g'
  992. fi
  993. }
  994. list_phy_interfaces() {
  995. local phy="$1"
  996. for dev in $(_list_phy_interfaces "$phy"); do
  997. readlink "/sys/class/net/${dev}/phy80211" | grep -q "/${phy}\$" || continue
  998. echo "$dev"
  999. done
  1000. }
  1001. drv_mac80211_teardown() {
  1002. json_select data
  1003. json_get_vars phy
  1004. json_select ..
  1005. [ -n "$phy" ] || {
  1006. echo "Bug: PHY is undefined for device '$1'"
  1007. return 1
  1008. }
  1009. mac80211_reset_config "$phy"
  1010. for wdev in $(list_phy_interfaces "$phy"); do
  1011. ip link set dev "$wdev" down
  1012. iw dev "$wdev" del
  1013. done
  1014. }
  1015. add_driver mac80211