. /lib/functions/network.sh . /lib/functions.sh wpa_supplicant_add_rate() { local var="$1" local val="$(($2 / 1000))" local sub="$((($2 / 100) % 10))" append $var "$val" "," [ $sub -gt 0 ] && append $var "." } hostapd_add_rate() { local var="$1" local val="$(($2 / 100))" append $var "$val" " " } hostapd_append_wep_key() { local var="$1" wep_keyidx=0 set_default key 1 case "$key" in [1234]) for idx in 1 2 3 4; do local zidx zidx="$(($idx - 1))" json_get_var ckey "key${idx}" [ -n "$ckey" ] && \ append $var "wep_key${zidx}=$(prepare_key_wep "$ckey")" "$N$T" done wep_keyidx="$((key - 1))" ;; *) append $var "wep_key0=$(prepare_key_wep "$key")" "$N$T" ;; esac } hostapd_append_wpa_key_mgmt() { local auth_type_l="$(echo $auth_type | tr 'a-z' 'A-Z')" case "$auth_type" in psk|eap) append wpa_key_mgmt "WPA-$auth_type_l" [ "${wpa:-2}" -ge 2 ] && [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-${auth_type_l}" [ "${ieee80211w:-0}" -gt 0 ] && append wpa_key_mgmt "WPA-${auth_type_l}-SHA256" ;; eap192) append wpa_key_mgmt "WPA-EAP-SUITE-B-192" [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-EAP-SHA384" ;; eap-eap2) append wpa_key_mgmt "WPA-EAP" append wpa_key_mgmt "WPA-EAP-SHA256" [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-EAP" ;; eap2) [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-EAP" append wpa_key_mgmt "WPA-EAP-SHA256" ;; sae) append wpa_key_mgmt "SAE" [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-SAE" ;; psk-sae) append wpa_key_mgmt "WPA-PSK" [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-PSK" [ "${ieee80211w:-0}" -gt 0 ] && append wpa_key_mgmt "WPA-PSK-SHA256" append wpa_key_mgmt "SAE" [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-SAE" ;; owe) append wpa_key_mgmt "OWE" ;; esac [ "$fils" -gt 0 ] && { case "$auth_type" in eap192) append wpa_key_mgmt FILS-SHA384 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt FT-FILS-SHA384 ;; eap*) append wpa_key_mgmt FILS-SHA256 [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt FT-FILS-SHA256 ;; esac } [ "$auth_osen" = "1" ] && append wpa_key_mgmt "OSEN" } hostapd_add_log_config() { config_add_boolean \ log_80211 \ log_8021x \ log_radius \ log_wpa \ log_driver \ log_iapp \ log_mlme config_add_int log_level } hostapd_common_add_device_config() { config_add_array basic_rate config_add_array supported_rates config_add_string beacon_rate config_add_string country country3 config_add_boolean country_ie doth config_add_boolean spectrum_mgmt_required config_add_int local_pwr_constraint config_add_string require_mode config_add_boolean legacy_rates config_add_int cell_density config_add_int rts_threshold config_add_int rssi_reject_assoc_rssi config_add_int rssi_ignore_probe_request config_add_int maxassoc config_add_string acs_chan_bias config_add_array hostapd_options config_add_int airtime_mode config_add_int mbssid hostapd_add_log_config } hostapd_prepare_device_config() { local config="$1" local driver="$2" local base_cfg= json_get_vars country country3 country_ie beacon_int:100 doth require_mode legacy_rates \ acs_chan_bias local_pwr_constraint spectrum_mgmt_required airtime_mode cell_density \ rts_threshold beacon_rate rssi_reject_assoc_rssi rssi_ignore_probe_request maxassoc \ mbssid:0 hostapd_set_log_options base_cfg set_default country_ie 1 set_default spectrum_mgmt_required 0 set_default doth 1 set_default legacy_rates 0 set_default airtime_mode 0 set_default cell_density 0 [ -n "$country" ] && { append base_cfg "country_code=$country" "$N" [ -n "$country3" ] && append base_cfg "country3=$country3" "$N" [ "$country_ie" -gt 0 ] && { append base_cfg "ieee80211d=1" "$N" [ -n "$local_pwr_constraint" ] && append base_cfg "local_pwr_constraint=$local_pwr_constraint" "$N" [ "$spectrum_mgmt_required" -gt 0 ] && append base_cfg "spectrum_mgmt_required=$spectrum_mgmt_required" "$N" } [ "$hwmode" = "a" -a "$doth" -gt 0 ] && append base_cfg "ieee80211h=1" "$N" } [ -n "$acs_chan_bias" ] && append base_cfg "acs_chan_bias=$acs_chan_bias" "$N" local brlist= br json_get_values basic_rate_list basic_rate local rlist= r json_get_values rate_list supported_rates [ -n "$hwmode" ] && append base_cfg "hw_mode=$hwmode" "$N" if [ "$hwmode" = "g" ] || [ "$hwmode" = "a" ]; then [ -n "$require_mode" ] && legacy_rates=0 case "$require_mode" in n) append base_cfg "require_ht=1" "$N";; ac) append base_cfg "require_vht=1" "$N";; esac fi case "$hwmode" in b) if [ "$cell_density" -eq 1 ]; then set_default rate_list "5500 11000" set_default basic_rate_list "5500 11000" elif [ "$cell_density" -ge 2 ]; then set_default rate_list "11000" set_default basic_rate_list "11000" fi ;; g) if [ "$cell_density" -eq 0 ] || [ "$cell_density" -eq 1 ]; then if [ "$legacy_rates" -eq 0 ]; then set_default rate_list "6000 9000 12000 18000 24000 36000 48000 54000" set_default basic_rate_list "6000 12000 24000" elif [ "$cell_density" -eq 1 ]; then set_default rate_list "5500 6000 9000 11000 12000 18000 24000 36000 48000 54000" set_default basic_rate_list "5500 11000" fi elif [ "$cell_density" -ge 3 ] && [ "$legacy_rates" -ne 0 ] || [ "$cell_density" -eq 2 ]; then if [ "$legacy_rates" -eq 0 ]; then set_default rate_list "12000 18000 24000 36000 48000 54000" set_default basic_rate_list "12000 24000" else set_default rate_list "11000 12000 18000 24000 36000 48000 54000" set_default basic_rate_list "11000" fi elif [ "$cell_density" -ge 3 ]; then set_default rate_list "24000 36000 48000 54000" set_default basic_rate_list "24000" fi ;; a) if [ "$cell_density" -eq 1 ]; then set_default rate_list "6000 9000 12000 18000 24000 36000 48000 54000" set_default basic_rate_list "6000 12000 24000" elif [ "$cell_density" -eq 2 ]; then set_default rate_list "12000 18000 24000 36000 48000 54000" set_default basic_rate_list "12000 24000" elif [ "$cell_density" -ge 3 ]; then set_default rate_list "24000 36000 48000 54000" set_default basic_rate_list "24000" fi ;; esac for r in $rate_list; do hostapd_add_rate rlist "$r" done for br in $basic_rate_list; do hostapd_add_rate brlist "$br" done [ -n "$rssi_reject_assoc_rssi" ] && append base_cfg "rssi_reject_assoc_rssi=$rssi_reject_assoc_rssi" "$N" [ -n "$rssi_ignore_probe_request" ] && append base_cfg "rssi_ignore_probe_request=$rssi_ignore_probe_request" "$N" [ -n "$beacon_rate" ] && append base_cfg "beacon_rate=$beacon_rate" "$N" [ -n "$rlist" ] && append base_cfg "supported_rates=$rlist" "$N" [ -n "$brlist" ] && append base_cfg "basic_rates=$brlist" "$N" append base_cfg "beacon_int=$beacon_int" "$N" [ -n "$rts_threshold" ] && append base_cfg "rts_threshold=$rts_threshold" "$N" [ "$airtime_mode" -gt 0 ] && append base_cfg "airtime_mode=$airtime_mode" "$N" [ -n "$maxassoc" ] && append base_cfg "iface_max_num_sta=$maxassoc" "$N" [ "$mbssid" -gt 0 ] && [ "$mbssid" -le 2 ] && append base_cfg "mbssid=$mbssid" "$N" json_get_values opts hostapd_options for val in $opts; do append base_cfg "$val" "$N" done cat > "$config" <