X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fopenwrt.git;a=blobdiff_plain;f=package%2Fnetwork%2Fservices%2Fhostapd%2Ffiles%2Fhostapd.sh;h=5af9a50bfa287331161c880fe47024c174aa2a66;hp=393233b8b46c689f522664bf7a2e1be42c77d040;hb=796bc21023a5f1e98bdff44800c122f8855cf6b2;hpb=047f9ef8eb31ef5992225f1c6e4eb22ae196d225 diff --git a/package/network/services/hostapd/files/hostapd.sh b/package/network/services/hostapd/files/hostapd.sh index 393233b8b4..5af9a50bfa 100644 --- a/package/network/services/hostapd/files/hostapd.sh +++ b/package/network/services/hostapd/files/hostapd.sh @@ -1,357 +1,513 @@ . /lib/functions/network.sh -hostapd_set_bss_options() { +wpa_supplicant_add_rate() { local var="$1" - local vif="$2" - local enc wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey wps_possible wpa_key_mgmt - - config_get enc "$vif" encryption "none" - config_get wep_rekey "$vif" wep_rekey # 300 - config_get wpa_group_rekey "$vif" wpa_group_rekey # 300 - config_get wpa_pair_rekey "$vif" wpa_pair_rekey # 300 - config_get wpa_master_rekey "$vif" wpa_master_rekey # 640 - config_get_bool ap_isolate "$vif" isolate 0 - config_get_bool disassoc_low_ack "$vif" disassoc_low_ack 1 - config_get max_num_sta "$vif" max_num_sta 0 - config_get max_inactivity "$vif" max_inactivity 0 - config_get_bool preamble "$vif" short_preamble 1 - - config_get device "$vif" device - config_get hwmode "$device" hwmode - config_get phy "$device" phy - - append "$var" "ctrl_interface=/var/run/hostapd-$phy" "$N" - - if [ "$ap_isolate" -gt 0 ]; then - append "$var" "ap_isolate=$ap_isolate" "$N" - fi - if [ "$max_num_sta" -gt 0 ]; then - append "$var" "max_num_sta=$max_num_sta" "$N" - fi - if [ "$max_inactivity" -gt 0 ]; then - append "$var" "ap_max_inactivity=$max_inactivity" "$N" - fi - append "$var" "disassoc_low_ack=$disassoc_low_ack" "$N" - if [ "$preamble" -gt 0 ]; then - append "$var" "preamble=$preamble" "$N" - fi + local val="$(($2 / 1000))" + local sub="$((($2 / 100) % 10))" + append $var "$val" "," + [ $sub -gt 0 ] && append $var "." +} - # Examples: - # psk-mixed/tkip => WPA1+2 PSK, TKIP - # wpa-psk2/tkip+aes => WPA2 PSK, CCMP+TKIP - # wpa2/tkip+aes => WPA2 RADIUS, CCMP+TKIP - # ... +hostapd_add_rate() { + local var="$1" + local val="$(($2 / 100))" + append $var "$val" " " +} - # TODO: move this parsing function somewhere generic, so that - # later it can be reused by drivers that don't use hostapd +hostapd_append_wep_key() { + local var="$1" - # crypto defaults: WPA2 vs WPA1 - case "$enc" in - wpa2*|*psk2*) - wpa=2 - crypto="CCMP" - ;; - *mixed*) - wpa=3 - crypto="CCMP TKIP" + 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)) ;; *) - wpa=1 - crypto="TKIP" + append $var "wep_key0=$(prepare_key_wep "$key")" "$N$T" ;; esac +} - # explicit override for crypto setting - case "$enc" in - *tkip+aes|*tkip+ccmp|*aes+tkip|*ccmp+tkip) crypto="CCMP TKIP";; - *aes|*ccmp) crypto="CCMP";; - *tkip) crypto="TKIP";; - esac +hostapd_append_wpa_key_mgmt() { + local auth_type="$(echo $auth_type | tr 'a-z' 'A-Z')" + + append wpa_key_mgmt "WPA-$auth_type" + [ "${ieee80211r:-0}" -gt 0 ] && append wpa_key_mgmt "FT-${auth_type}" + [ "${ieee80211w:-0}" -gt 0 ] && append wpa_key_mgmt "WPA-${auth_type}-SHA256" +} + +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 country + config_add_boolean country_ie doth + config_add_string require_mode + config_add_boolean legacy_rates + + hostapd_add_log_config +} + +hostapd_prepare_device_config() { + local config="$1" + local driver="$2" + + local base="${config%%.conf}" + local base_cfg= + + json_get_vars country country_ie beacon_int:100 doth require_mode legacy_rates - # enforce CCMP for 11ng and 11na - case "$hwmode:$crypto" in - *ng:TKIP|*na:TKIP) crypto="CCMP TKIP";; + hostapd_set_log_options base_cfg + + set_default country_ie 1 + set_default doth 1 + set_default legacy_rates 1 + + [ "$hwmode" = "b" ] && legacy_rates=1 + + [ -n "$country" ] && { + append base_cfg "country_code=$country" "$N" + + [ "$country_ie" -gt 0 ] && append base_cfg "ieee80211d=1" "$N" + [ "$hwmode" = "a" -a "$doth" -gt 0 ] && append base_cfg "ieee80211h=1" "$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" + [ "$legacy_rates" -eq 0 ] && set_default require_mode g + + [ "$hwmode" = "g" ] && { + [ "$legacy_rates" -eq 0 ] && set_default rate_list "6000 9000 12000 18000 24000 36000 48000 54000" + [ -n "$require_mode" ] && set_default basic_rate_list "6000 12000 24000" + } + + case "$require_mode" in + n) append base_cfg "require_ht=1" "$N";; + ac) append base_cfg "require_vht=1" "$N";; esac - # use crypto/auth settings for building the hostapd config - case "$enc" in + 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 "$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" + + cat > "$config" <