mac80211.sh 30 KB

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