netifd.sh 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. wpa_supplicant_add_rate() {
  2. local var="$1"
  3. local val="$(($2 / 1000))"
  4. local sub="$((($2 / 100) % 10))"
  5. append $var "$val" ","
  6. [ $sub -gt 0 ] && append $var "."
  7. }
  8. hostapd_add_rate() {
  9. local var="$1"
  10. local val="$(($2 / 100))"
  11. append $var "$val" " "
  12. }
  13. hostapd_append_wep_key() {
  14. local var="$1"
  15. wep_keyidx=0
  16. set_default key 1
  17. case "$key" in
  18. [1234])
  19. for idx in 1 2 3 4; do
  20. local zidx
  21. zidx=$(($idx - 1))
  22. json_get_var ckey "key${idx}"
  23. [ -n "$ckey" ] && \
  24. append $var "wep_key${zidx}=$(prepare_key_wep "$ckey")" "$N$T"
  25. done
  26. wep_keyidx=$((key - 1))
  27. ;;
  28. *)
  29. append $var "wep_key0=$(prepare_key_wep "$key")" "$N$T"
  30. ;;
  31. esac
  32. }
  33. hostapd_add_log_config() {
  34. config_add_boolean \
  35. log_80211 \
  36. log_8021x \
  37. log_radius \
  38. log_wpa \
  39. log_driver \
  40. log_iapp \
  41. log_mlme
  42. config_add_int log_level
  43. }
  44. hostapd_common_add_device_config() {
  45. config_add_array basic_rate
  46. config_add_array supported_rates
  47. config_add_string country
  48. config_add_boolean country_ie doth
  49. config_add_string require_mode
  50. hostapd_add_log_config
  51. }
  52. hostapd_prepare_device_config() {
  53. local config="$1"
  54. local driver="$2"
  55. local base="${config%%.conf}"
  56. local base_cfg=
  57. json_get_vars country country_ie beacon_int doth require_mode
  58. hostapd_set_log_options base_cfg
  59. set_default country_ie 1
  60. set_default doth 1
  61. [ -n "$country" ] && {
  62. append base_cfg "country_code=$country" "$N"
  63. [ "$country_ie" -gt 0 ] && append base_cfg "ieee80211d=1" "$N"
  64. [ "$hwmode" = "a" -a "$doth" -gt 0 ] && append base_cfg "ieee80211h=1" "$N"
  65. }
  66. [ -n "$hwmode" ] && append base_cfg "hw_mode=$hwmode" "$N"
  67. local brlist= br
  68. json_get_values basic_rate_list basic_rate
  69. for br in $basic_rate_list; do
  70. hostapd_add_rate brlist "$br"
  71. done
  72. case "$require_mode" in
  73. g) brlist="60 120 240" ;;
  74. n) append base_cfg "require_ht=1" "$N";;
  75. ac) append base_cfg "require_vht=1" "$N";;
  76. esac
  77. local rlist= r
  78. json_get_values rate_list supported_rates
  79. for r in $rate_list; do
  80. hostapd_add_rate rlist "$r"
  81. done
  82. [ -n "$rlist" ] && append base_cfg "supported_rates=$rlist" "$N"
  83. [ -n "$brlist" ] && append base_cfg "basic_rates=$brlist" "$N"
  84. [ -n "$beacon_int" ] && append base_cfg "beacon_int=$beacon_int" "$N"
  85. cat > "$config" <<EOF
  86. driver=$driver
  87. $base_cfg
  88. EOF
  89. }
  90. hostapd_common_add_bss_config() {
  91. config_add_string 'bssid:macaddr' 'ssid:string'
  92. config_add_boolean wds wmm uapsd hidden
  93. config_add_int maxassoc max_inactivity
  94. config_add_boolean disassoc_low_ack isolate short_preamble
  95. config_add_int \
  96. wep_rekey eap_reauth_period \
  97. wpa_group_rekey wpa_pair_rekey wpa_master_rekey
  98. config_add_boolean rsn_preauth auth_cache
  99. config_add_int ieee80211w
  100. config_add_int eapol_version
  101. config_add_string 'auth_server:host' 'server:host'
  102. config_add_string auth_secret
  103. config_add_int 'auth_port:port' 'port:port'
  104. config_add_string acct_server
  105. config_add_string acct_secret
  106. config_add_int acct_port
  107. config_add_string dae_client
  108. config_add_string dae_secret
  109. config_add_int dae_port
  110. config_add_string nasid
  111. config_add_string ownip
  112. config_add_string iapp_interface
  113. config_add_string eap_type ca_cert client_cert identity auth priv_key priv_key_pwd
  114. config_add_int dynamic_vlan vlan_naming
  115. config_add_string vlan_tagged_interface vlan_bridge
  116. config_add_string 'key1:wepkey' 'key2:wepkey' 'key3:wepkey' 'key4:wepkey' 'password:wpakey'
  117. config_add_string wpa_psk_file
  118. config_add_boolean wps_pushbutton wps_label ext_registrar wps_pbc_in_m1
  119. config_add_string wps_device_type wps_device_name wps_manufacturer wps_pin
  120. config_add_boolean ieee80211r pmk_r1_push
  121. config_add_int r0_key_lifetime reassociation_deadline
  122. config_add_string mobility_domain r1_key_holder
  123. config_add_array r0kh r1kh
  124. config_add_int ieee80211w_max_timeout ieee80211w_retry_timeout
  125. config_add_string macfilter 'macfile:file'
  126. config_add_array 'maclist:list(macaddr)'
  127. config_add_array bssid_blacklist
  128. config_add_array bssid_whitelist
  129. config_add_int mcast_rate
  130. config_add_array basic_rate
  131. config_add_array supported_rates
  132. }
  133. hostapd_set_bss_options() {
  134. local var="$1"
  135. local phy="$2"
  136. local vif="$3"
  137. wireless_vif_parse_encryption
  138. local bss_conf
  139. local wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey wpa_key_mgmt
  140. json_get_vars \
  141. wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey \
  142. maxassoc max_inactivity disassoc_low_ack isolate auth_cache \
  143. wps_pushbutton wps_label ext_registrar wps_pbc_in_m1 \
  144. wps_device_type wps_device_name wps_manufacturer wps_pin \
  145. macfilter ssid wmm uapsd hidden short_preamble rsn_preauth \
  146. iapp_interface eapol_version
  147. set_default isolate 0
  148. set_default maxassoc 0
  149. set_default max_inactivity 0
  150. set_default short_preamble 1
  151. set_default disassoc_low_ack 1
  152. set_default hidden 0
  153. set_default wmm 1
  154. set_default uapsd 1
  155. set_default eapol_version 0
  156. append bss_conf "ctrl_interface=/var/run/hostapd"
  157. if [ "$isolate" -gt 0 ]; then
  158. append bss_conf "ap_isolate=$isolate" "$N"
  159. fi
  160. if [ "$maxassoc" -gt 0 ]; then
  161. append bss_conf "max_num_sta=$maxassoc" "$N"
  162. fi
  163. if [ "$max_inactivity" -gt 0 ]; then
  164. append bss_conf "ap_max_inactivity=$max_inactivity" "$N"
  165. fi
  166. append bss_conf "disassoc_low_ack=$disassoc_low_ack" "$N"
  167. append bss_conf "preamble=$short_preamble" "$N"
  168. append bss_conf "wmm_enabled=$wmm" "$N"
  169. append bss_conf "ignore_broadcast_ssid=$hidden" "$N"
  170. append bss_conf "uapsd_advertisement_enabled=$uapsd" "$N"
  171. [ "$wpa" -gt 0 ] && {
  172. [ -n "$wpa_group_rekey" ] && append bss_conf "wpa_group_rekey=$wpa_group_rekey" "$N"
  173. [ -n "$wpa_pair_rekey" ] && append bss_conf "wpa_ptk_rekey=$wpa_pair_rekey" "$N"
  174. [ -n "$wpa_master_rekey" ] && append bss_conf "wpa_gmk_rekey=$wpa_master_rekey" "$N"
  175. }
  176. case "$auth_type" in
  177. none)
  178. wps_possible=1
  179. # Here we make the assumption that if we're in open mode
  180. # with WPS enabled, we got to be in unconfigured state.
  181. wps_not_configured=1
  182. ;;
  183. psk)
  184. json_get_vars key wpa_psk_file
  185. if [ ${#key} -lt 8 ]; then
  186. wireless_setup_vif_failed INVALID_WPA_PSK
  187. return 1
  188. elif [ ${#key} -eq 64 ]; then
  189. append bss_conf "wpa_psk=$key" "$N"
  190. else
  191. append bss_conf "wpa_passphrase=$key" "$N"
  192. fi
  193. [ -n "$wpa_psk_file" ] && {
  194. [ -e "$wpa_psk_file" ] || touch "$wpa_psk_file"
  195. append bss_conf "wpa_psk_file=$wpa_psk_file" "$N"
  196. }
  197. [ "$eapol_version" -ge "1" -a "$eapol_version" -le "2" ] && append bss_conf "eapol_version=$eapol_version" "$N"
  198. wps_possible=1
  199. append wpa_key_mgmt "WPA-PSK"
  200. ;;
  201. eap)
  202. json_get_vars \
  203. auth_server auth_secret auth_port \
  204. acct_server acct_secret acct_port \
  205. dae_client dae_secret dae_port \
  206. ownip \
  207. eap_reauth_period dynamic_vlan \
  208. vlan_naming vlan_tagged_interface \
  209. vlan_bridge
  210. # legacy compatibility
  211. [ -n "$auth_server" ] || json_get_var auth_server server
  212. [ -n "$auth_port" ] || json_get_var auth_port port
  213. [ -n "$auth_secret" ] || json_get_var auth_secret key
  214. set_default auth_port 1812
  215. set_default acct_port 1813
  216. set_default dae_port 3799
  217. set_default vlan_naming 1
  218. append bss_conf "auth_server_addr=$auth_server" "$N"
  219. append bss_conf "auth_server_port=$auth_port" "$N"
  220. append bss_conf "auth_server_shared_secret=$auth_secret" "$N"
  221. [ -n "$acct_server" ] && {
  222. append bss_conf "acct_server_addr=$acct_server" "$N"
  223. append bss_conf "acct_server_port=$acct_port" "$N"
  224. [ -n "$acct_secret" ] && \
  225. append bss_conf "acct_server_shared_secret=$acct_secret" "$N"
  226. }
  227. [ -n "$eap_reauth_period" ] && append bss_conf "eap_reauth_period=$eap_reauth_period" "$N"
  228. [ -n "$dae_client" -a -n "$dae_secret" ] && {
  229. append bss_conf "radius_das_port=$dae_port" "$N"
  230. append bss_conf "radius_das_client=$dae_client $dae_secret" "$N"
  231. }
  232. [ -n "$ownip" ] && append bss_conf "own_ip_addr=$ownip" "$N"
  233. append bss_conf "eapol_key_index_workaround=1" "$N"
  234. append bss_conf "ieee8021x=1" "$N"
  235. append wpa_key_mgmt "WPA-EAP"
  236. [ -n "$dynamic_vlan" ] && {
  237. append bss_conf "dynamic_vlan=$dynamic_vlan" "$N"
  238. append bss_conf "vlan_naming=$vlan_naming" "$N"
  239. [ -n "$vlan_bridge" ] && \
  240. append bss_conf "vlan_bridge=$vlan_bridge" "$N"
  241. [ -n "$vlan_tagged_interface" ] && \
  242. append bss_conf "vlan_tagged_interface=$vlan_tagged_interface" "$N"
  243. }
  244. [ "$eapol_version" -ge "1" -a "$eapol_version" -le "2" ] && append bss_conf "eapol_version=$eapol_version" "$N"
  245. ;;
  246. wep)
  247. local wep_keyidx=0
  248. json_get_vars key
  249. hostapd_append_wep_key bss_conf
  250. append bss_conf "wep_default_key=$wep_keyidx" "$N"
  251. [ -n "$wep_rekey" ] && append bss_conf "wep_rekey_period=$wep_rekey" "$N"
  252. ;;
  253. esac
  254. local auth_algs=$((($auth_mode_shared << 1) | $auth_mode_open))
  255. append bss_conf "auth_algs=${auth_algs:-1}" "$N"
  256. append bss_conf "wpa=$wpa" "$N"
  257. [ -n "$wpa_pairwise" ] && append bss_conf "wpa_pairwise=$wpa_pairwise" "$N"
  258. set_default wps_pushbutton 0
  259. set_default wps_label 0
  260. set_default wps_pbc_in_m1 0
  261. config_methods=
  262. [ "$wps_pushbutton" -gt 0 ] && append config_methods push_button
  263. [ "$wps_label" -gt 0 ] && append config_methods label
  264. [ -n "$wps_possible" -a -n "$config_methods" ] && {
  265. set_default ext_registrar 0
  266. set_default wps_device_type "6-0050F204-1"
  267. set_default wps_device_name "OpenWrt AP"
  268. set_default wps_manufacturer "openwrt.org"
  269. wps_state=2
  270. [ -n "$wps_configured" ] && wps_state=1
  271. [ "$ext_registrar" -gt 0 -a -n "$network_bridge" ] && append bss_conf "upnp_iface=$network_bridge" "$N"
  272. append bss_conf "eap_server=1" "$N"
  273. [ -n "$wps_pin" ] && append bss_conf "ap_pin=$wps_pin" "$N"
  274. append bss_conf "wps_state=$wps_state" "$N"
  275. append bss_conf "ap_setup_locked=0" "$N"
  276. append bss_conf "device_type=$wps_device_type" "$N"
  277. append bss_conf "device_name=$wps_device_name" "$N"
  278. append bss_conf "manufacturer=$wps_manufacturer" "$N"
  279. append bss_conf "config_methods=$config_methods" "$N"
  280. [ "$wps_pbc_in_m1" -gt 0 ] && append bss_conf "pbc_in_m1=$wps_pbc_in_m1" "$N"
  281. }
  282. append bss_conf "ssid=$ssid" "$N"
  283. [ -n "$network_bridge" ] && append bss_conf "bridge=$network_bridge" "$N"
  284. [ -n "$iapp_interface" ] && {
  285. iapp_interface="$(uci_get_state network "$iapp_interface" ifname "$iapp_interface")"
  286. [ -n "$iapp_interface" ] && append bss_conf "iapp_interface=$iapp_interface" "$N"
  287. }
  288. if [ "$wpa" -ge "1" ]; then
  289. json_get_vars nasid ieee80211r
  290. set_default ieee80211r 0
  291. [ -n "$nasid" ] && append bss_conf "nas_identifier=$nasid" "$N"
  292. if [ "$ieee80211r" -gt "0" ]; then
  293. json_get_vars mobility_domain r0_key_lifetime r1_key_holder \
  294. reassociation_deadline pmk_r1_push
  295. json_get_values r0kh r0kh
  296. json_get_values r1kh r1kh
  297. set_default mobility_domain "4f57"
  298. set_default r0_key_lifetime 10000
  299. set_default r1_key_holder "00004f577274"
  300. set_default reassociation_deadline 1000
  301. set_default pmk_r1_push 0
  302. append bss_conf "mobility_domain=$mobility_domain" "$N"
  303. append bss_conf "r0_key_lifetime=$r0_key_lifetime" "$N"
  304. append bss_conf "r1_key_holder=$r1_key_holder" "$N"
  305. append bss_conf "reassociation_deadline=$reassociation_deadline" "$N"
  306. append bss_conf "pmk_r1_push=$pmk_r1_push" "$N"
  307. for kh in $r0kh; do
  308. append bss_conf "r0kh=${kh//,/ }" "$N"
  309. done
  310. for kh in $r1kh; do
  311. append bss_conf "r1kh=${kh//,/ }" "$N"
  312. done
  313. [ "$wpa_key_mgmt" != "${wpa_key_mgmt/EAP/}" ] && append wpa_key_mgmt "FT-EAP"
  314. [ "$wpa_key_mgmt" != "${wpa_key_mgmt/PSK/}" ] && append wpa_key_mgmt "FT-PSK"
  315. fi
  316. [ -n "$wpa_key_mgmt" ] && append bss_conf "wpa_key_mgmt=$wpa_key_mgmt" "$N"
  317. fi
  318. if [ "$wpa" -ge "2" ]; then
  319. if [ -n "$network_bridge" -a "$rsn_preauth" = 1 ]; then
  320. set_default auth_cache 1
  321. append bss_conf "rsn_preauth=1" "$N"
  322. append bss_conf "rsn_preauth_interfaces=$network_bridge" "$N"
  323. else
  324. set_default auth_cache 0
  325. fi
  326. append bss_conf "okc=$auth_cache" "$N"
  327. [ "$auth_cache" = 0 ] && append bss_conf "disable_pmksa_caching=1" "$N"
  328. # RSN -> allow management frame protection
  329. json_get_var ieee80211w ieee80211w
  330. case "$ieee80211w" in
  331. [012])
  332. json_get_vars ieee80211w_max_timeout ieee80211w_retry_timeout
  333. append bss_conf "ieee80211w=$ieee80211w" "$N"
  334. [ "$ieee80211w" -gt "0" ] && {
  335. [ -n "$ieee80211w_max_timeout" ] && \
  336. append bss_conf "assoc_sa_query_max_timeout=$ieee80211w_max_timeout" "$N"
  337. [ -n "$ieee80211w_retry_timeout" ] && \
  338. append bss_conf "assoc_sa_query_retry_timeout=$ieee80211w_retry_timeout" "$N"
  339. }
  340. ;;
  341. esac
  342. fi
  343. _macfile="/var/run/hostapd-$ifname.maclist"
  344. case "$macfilter" in
  345. allow)
  346. append bss_conf "macaddr_acl=1" "$N"
  347. append bss_conf "accept_mac_file=$_macfile" "$N"
  348. ;;
  349. deny)
  350. append bss_conf "macaddr_acl=0" "$N"
  351. append bss_conf "deny_mac_file=$_macfile" "$N"
  352. ;;
  353. *)
  354. _macfile=""
  355. ;;
  356. esac
  357. [ -n "$_macfile" ] && {
  358. json_get_vars macfile
  359. json_get_values maclist maclist
  360. rm -f "$_macfile"
  361. (
  362. for mac in $maclist; do
  363. echo "$mac"
  364. done
  365. [ -n "$macfile" -a -f "$macfile" ] && cat "$macfile"
  366. ) > "$_macfile"
  367. }
  368. append "$var" "$bss_conf" "$N"
  369. return 0
  370. }
  371. hostapd_set_log_options() {
  372. local var="$1"
  373. local log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme
  374. json_get_vars log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme
  375. set_default log_level 2
  376. set_default log_80211 1
  377. set_default log_8021x 1
  378. set_default log_radius 1
  379. set_default log_wpa 1
  380. set_default log_driver 1
  381. set_default log_iapp 1
  382. set_default log_mlme 1
  383. local log_mask=$(( \
  384. ($log_80211 << 0) | \
  385. ($log_8021x << 1) | \
  386. ($log_radius << 2) | \
  387. ($log_wpa << 3) | \
  388. ($log_driver << 4) | \
  389. ($log_iapp << 5) | \
  390. ($log_mlme << 6) \
  391. ))
  392. append "$var" "logger_syslog=$log_mask" "$N"
  393. append "$var" "logger_syslog_level=$log_level" "$N"
  394. append "$var" "logger_stdout=$log_mask" "$N"
  395. append "$var" "logger_stdout_level=$log_level" "$N"
  396. return 0
  397. }
  398. _wpa_supplicant_common() {
  399. local ifname="$1"
  400. _rpath="/var/run/wpa_supplicant"
  401. _config="${_rpath}-$ifname.conf"
  402. }
  403. wpa_supplicant_teardown_interface() {
  404. _wpa_supplicant_common "$1"
  405. rm -rf "$_rpath/$1" "$_config"
  406. }
  407. wpa_supplicant_prepare_interface() {
  408. local ifname="$1"
  409. _w_driver="$2"
  410. _wpa_supplicant_common "$1"
  411. json_get_vars mode wds
  412. [ -n "$network_bridge" ] && {
  413. fail=
  414. case "$mode" in
  415. adhoc)
  416. fail=1
  417. ;;
  418. sta)
  419. [ "$wds" = 1 ] || fail=1
  420. ;;
  421. esac
  422. [ -n "$fail" ] && {
  423. wireless_setup_vif_failed BRIDGE_NOT_ALLOWED
  424. return 1
  425. }
  426. }
  427. local ap_scan=
  428. _w_mode="$mode"
  429. _w_modestr=
  430. [[ "$mode" = adhoc ]] && {
  431. ap_scan="ap_scan=2"
  432. _w_modestr="mode=1"
  433. }
  434. wpa_supplicant_teardown_interface "$ifname"
  435. cat > "$_config" <<EOF
  436. $ap_scan
  437. EOF
  438. return 0
  439. }
  440. wpa_supplicant_add_network() {
  441. local ifname="$1"
  442. _wpa_supplicant_common "$1"
  443. wireless_vif_parse_encryption
  444. json_get_vars \
  445. ssid bssid key \
  446. basic_rate mcast_rate \
  447. ieee80211w
  448. local key_mgmt='NONE'
  449. local enc_str=
  450. local network_data=
  451. local T=" "
  452. local wpa_key_mgmt="WPA-PSK"
  453. local scan_ssid="scan_ssid=1"
  454. local freq
  455. [[ "$_w_mode" = "adhoc" ]] && {
  456. append network_data "mode=1" "$N$T"
  457. [ -n "$channel" ] && {
  458. freq="$(get_freq "$phy" "$channel")"
  459. append network_data "fixed_freq=1" "$N$T"
  460. append network_data "frequency=$freq" "$N$T"
  461. }
  462. scan_ssid="scan_ssid=0"
  463. [ "$_w_driver" = "nl80211" ] || wpa_key_mgmt="WPA-NONE"
  464. }
  465. [[ "$_w_mode" = "mesh" ]] && {
  466. append network_data "mode=5" "$N$T"
  467. [ -n "$channel" ] && {
  468. freq="$(get_freq "$phy" "$channel")"
  469. append network_data "frequency=$freq" "$N$T"
  470. }
  471. wpa_key_mgmt="SAE"
  472. scan_ssid=""
  473. }
  474. [[ "$_w_mode" = "adhoc" -o "$_w_mode" = "mesh" ]] && append network_data "$_w_modestr" "$N$T"
  475. case "$auth_type" in
  476. none) ;;
  477. wep)
  478. local wep_keyidx=0
  479. hostapd_append_wep_key network_data
  480. append network_data "wep_tx_keyidx=$wep_keyidx" "$N$T"
  481. ;;
  482. psk)
  483. local passphrase
  484. key_mgmt="$wpa_key_mgmt"
  485. if [ ${#key} -eq 64 ]; then
  486. passphrase="psk=${key}"
  487. else
  488. passphrase="psk=\"${key}\""
  489. fi
  490. append network_data "$passphrase" "$N$T"
  491. ;;
  492. eap)
  493. key_mgmt='WPA-EAP'
  494. json_get_vars eap_type identity ca_cert
  495. [ -n "$ca_cert" ] && append network_data "ca_cert=\"$ca_cert\"" "$N$T"
  496. [ -n "$identity" ] && append network_data "identity=\"$identity\"" "$N$T"
  497. case "$eap_type" in
  498. tls)
  499. json_get_vars client_cert priv_key priv_key_pwd
  500. append network_data "client_cert=\"$client_cert\"" "$N$T"
  501. append network_data "private_key=\"$priv_key\"" "$N$T"
  502. append network_data "private_key_passwd=\"$priv_key_pwd\"" "$N$T"
  503. ;;
  504. peap|ttls)
  505. json_get_vars auth password
  506. set_default auth MSCHAPV2
  507. append network_data "phase2=\"$auth\"" "$N$T"
  508. append network_data "password=\"$password\"" "$N$T"
  509. ;;
  510. esac
  511. append network_data "eap=$(echo $eap_type | tr 'a-z' 'A-Z')" "$N$T"
  512. ;;
  513. esac
  514. [ "$mode" = mesh ] || {
  515. case "$wpa" in
  516. 1)
  517. append network_data "proto=WPA" "$N$T"
  518. ;;
  519. 2)
  520. append network_data "proto=RSN" "$N$T"
  521. ;;
  522. esac
  523. case "$ieee80211w" in
  524. [012])
  525. [ "$wpa" -ge 2 ] && append network_data "ieee80211w=$ieee80211w" "$N$T"
  526. ;;
  527. esac
  528. }
  529. local beacon_int brates mrate
  530. [ -n "$bssid" ] && append network_data "bssid=$bssid" "$N$T"
  531. [ -n "$beacon_int" ] && append network_data "beacon_int=$beacon_int" "$N$T"
  532. local bssid_blacklist bssid_whitelist
  533. json_get_values bssid_blacklist bssid_blacklist
  534. json_get_values bssid_whitelist bssid_whitelist
  535. [ -n "$bssid_blacklist" ] && append network_data "bssid_blacklist=$bssid_blacklist" "$N$T"
  536. [ -n "$bssid_whitelist" ] && append network_data "bssid_whitelist=$bssid_whitelist" "$N$T"
  537. [ -n "$basic_rate" ] && {
  538. local br rate_list=
  539. for br in $basic_rate; do
  540. wpa_supplicant_add_rate rate_list "$br"
  541. done
  542. [ -n "$rate_list" ] && append network_data "rates=$rate_list" "$N$T"
  543. }
  544. [ -n "$mcast_rate" ] && {
  545. local mc_rate=
  546. wpa_supplicant_add_rate mc_rate "$mcast_rate"
  547. append network_data "mcast_rate=$mc_rate" "$N$T"
  548. }
  549. local ht_str
  550. [[ "$_w_mode" = adhoc ]] || ibss_htmode=
  551. [ -n "$ibss_htmode" ] && append network_data "htmode=$ibss_htmode" "$N$T"
  552. cat >> "$_config" <<EOF
  553. network={
  554. $scan_ssid
  555. ssid="$ssid"
  556. key_mgmt=$key_mgmt
  557. $network_data
  558. }
  559. EOF
  560. return 0
  561. }
  562. wpa_supplicant_run() {
  563. local ifname="$1"; shift
  564. _wpa_supplicant_common "$ifname"
  565. /usr/sbin/wpa_supplicant -B \
  566. ${network_bridge:+-b $network_bridge} \
  567. -P "/var/run/wpa_supplicant-${ifname}.pid" \
  568. -D ${_w_driver:-wext} \
  569. -i "$ifname" \
  570. -c "$_config" \
  571. -C "$_rpath" \
  572. "$@"
  573. ret="$?"
  574. wireless_add_process "$(cat "/var/run/wpa_supplicant-${ifname}.pid")" /usr/sbin/wpa_supplicant 1
  575. [ "$ret" != 0 ] && wireless_setup_vif_failed WPA_SUPPLICANT_FAILED
  576. return $ret
  577. }
  578. hostapd_common_cleanup() {
  579. killall hostapd wpa_supplicant meshd-nl80211
  580. }