Add support for 802.11r fast transition to wireless config
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_network / wifi.lua
index 2289ca3..ee92d5e 100644 (file)
@@ -42,6 +42,9 @@ end
 
 -- wireless toggle was requested, commit and reload page
 function m.parse(map)
+       local new_cc = m:formvalue("cbid.wireless.%s.country" % wdev:name())
+       local old_cc = m:get(wdev:name(), "country")
+
        if m:formvalue("cbid.wireless.%s.__toggle" % wdev:name()) then
                if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then
                        wnet:set("disabled", nil)
@@ -56,7 +59,14 @@ function m.parse(map)
                luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", arg[1]))
                return
        end
+
        Map.parse(map)
+
+       if m:get(wdev:name(), "type") == "mac80211" and new_cc and new_cc ~= old_cc then
+               luci.sys.call("iw reg set %q" % new_cc)
+               luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", arg[1]))
+               return
+       end
 end
 
 m.title = luci.util.pcdata(wnet:get_i18n())
@@ -94,7 +104,7 @@ local function txpower_current(pwr, list)
                        end
                end
        end
-       return (list[#list] and list[#list].driver_dbm) or pwr or 0
+       return pwr or ""
 end
 
 local iw = luci.sys.wifi.getiwinfo(arg[1])
@@ -191,7 +201,7 @@ end
 ------------------- MAC80211 Device ------------------
 
 if hwtype == "mac80211" then
-       if #tx_power_list > 1 then
+       if #tx_power_list > 0 then
                tp = s:taboption("general", ListValue,
                        "txpower", translate("Transmit Power"), "dBm")
                tp.rmempty = true
@@ -200,6 +210,7 @@ if hwtype == "mac80211" then
                        return txpower_current(Value.cfgvalue(...), tx_power_list)
                end
 
+               tp:value("", translate("auto"))
                for _, p in ipairs(tx_power_list) do
                        tp:value(p.driver_dbm, "%i dBm (%i mW)"
                                %{ p.display_dbm, p.display_mw })
@@ -251,6 +262,7 @@ if hwtype == "atheros" then
                return txpower_current(Value.cfgvalue(...), tx_power_list)
        end
 
+       tp:value("", translate("auto"))
        for _, p in ipairs(tx_power_list) do
                tp:value(p.driver_dbm, "%i dBm (%i mW)"
                        %{ p.display_dbm, p.display_mw })
@@ -308,6 +320,7 @@ if hwtype == "broadcom" then
                return txpower_current(Value.cfgvalue(...), tx_power_list)
        end
 
+       tp:value("", translate("auto"))
        for _, p in ipairs(tx_power_list) do
                tp:value(p.driver_dbm, "%i dBm (%i mW)"
                        %{ p.display_dbm, p.display_mw })
@@ -505,6 +518,9 @@ if hwtype == "mac80211" then
        wmm:depends({mode="ap"})
        wmm:depends({mode="ap-wds"})
        wmm.default = wmm.enabled
+       
+       ifname = s:taboption("advanced", Value, "ifname", translate("Interface name"), translate("Override default interface name"))
+       ifname.optional = true
 end
 
 
@@ -884,12 +900,73 @@ end
 
 
 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
+
+       -- Probe EAP support as a proxy for determining if 802.11r support is present
+
+       local has_ap_eap  = (os.execute("hostapd -veap >/dev/null 2>/dev/null") == 0)
+
+       ieee80211r = s:taboption("encryption", Flag, "ieee80211r", translate("802.11r Fast Transition"))
+       ieee80211r:depends({mode="ap", encryption="wpa"})
+       ieee80211r:depends({mode="ap", encryption="wpa2"})
+       ieee80211r:depends({mode="ap-wds", encryption="wpa"})
+       ieee80211r:depends({mode="ap-wds", encryption="wpa2"})
+       if has_ap_eap then
+               ieee80211r:depends({mode="ap", encryption="psk"})
+               ieee80211r:depends({mode="ap", encryption="psk2"})
+       end
+       ieee80211r.rmempty = true
+
        nasid = s:taboption("encryption", Value, "nasid", translate("NAS ID"))
+
        nasid:depends({mode="ap", encryption="wpa"})
        nasid:depends({mode="ap", encryption="wpa2"})
        nasid:depends({mode="ap-wds", encryption="wpa"})
        nasid:depends({mode="ap-wds", encryption="wpa2"})
+       nasid:depends({ieee80211r="1"})
        nasid.rmempty = true
+       mobility_domain = s:taboption("encryption", Value, "mobility_domain", translate("Mobility Domain"))
+       mobility_domain:depends({ieee80211r="1"})
+       mobility_domain.placeholder = "4f57"
+       mobility_domain.rmempty = true
+
+       r0_key_lifetime = s:taboption("encryption", Value, "r0_key_lifetime", translate("R0 Key Lifetime"), translate("minutes"))
+       r0_key_lifetime:depends({ieee80211r="1"})
+       r0_key_lifetime.placeholder = "10000"
+       r0_key_lifetime.rmempty = true
+
+       r1_key_holder = s:taboption("encryption", Value, "r1_key_holder", translate("R1 Key Holder"), translate("6-octet identifier as a hex string - no colons"))
+       r1_key_holder:depends({ieee80211r="1"})
+       r1_key_holder.placeholder = "00004f577274"
+       r1_key_holder.rmempty = true
+
+       reassociation_deadline = s:taboption("encryption", Value, "reassociation_deadline", translate("Reassociation Deadline"), translate("time units (TUs / 1.024 ms) [1000-65535]"))
+       reassociation_deadline:depends({ieee80211r="1"})
+       reassociation_deadline.placeholder = "1000"
+       reassociation_deadline.rmempty = true
+
+       pmk_r1_push = s:taboption("encryption", Flag, "pmk_r1_push", translate("PMK R1 Push"))
+       pmk_r1_push:depends({ieee80211r="1"})
+       pmk_r1_push.placeholder = "0"
+       pmk_r1_push.rmempty = true
+
+       r0kh = s:taboption("encryption", DynamicList, "r0kh", translate("External R0 Key Holder List"),
+               translate("List of R0KHs in the same Mobility Domain. "..
+                           "<br>Format: MAC-address,NAS-Identifier,128-bit key as hex string. "..
+                           "<br>This list is used to map R0KH-ID (NAS Identifier) to a destination MAC address "..
+                           "when requesting PMK-R1 key from the R0KH that the STA "..
+                           "used during the Initial Mobility Domain Association."))
+
+       r0kh:depends({ieee80211r="1"})
+       r0kh.rmempty = true
+
+       r1kh = s:taboption("encryption", DynamicList, "r1kh", translate("External R1 Key Holder List"),
+               translate ("List of R1KHs in the same Mobility Domain. "..
+                                       "<br>Format: MAC-address,R1KH-ID as 6 octets with colons,128-bit key as hex string. "..
+                                       "<br>This list is used to map R1KH-ID to a destination MAC address "..
+                                       "when sending PMK-R1 key from the R0KH. This is also the "..
+                                       "list of authorized R1KHs in the MD that can request PMK-R1 keys."))
+       r1kh:depends({ieee80211r="1"})
+       r1kh.rmempty = true
 
        eaptype = s:taboption("encryption", ListValue, "eap_type", translate("EAP-Method"))
        eaptype:value("tls",  "TLS")
@@ -994,6 +1071,24 @@ if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
        identity:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
        identity:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
 
+       anonymous_identity = s:taboption("encryption", Value, "anonymous_identity", translate("Anonymous Identity"))
+       anonymous_identity:depends({mode="sta", eap_type="fast", encryption="wpa2"})
+       anonymous_identity:depends({mode="sta", eap_type="fast", encryption="wpa"})
+       anonymous_identity:depends({mode="sta", eap_type="peap", encryption="wpa2"})
+       anonymous_identity:depends({mode="sta", eap_type="peap", encryption="wpa"})
+       anonymous_identity:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
+       anonymous_identity:depends({mode="sta", eap_type="ttls", encryption="wpa"})
+       anonymous_identity:depends({mode="sta-wds", eap_type="fast", encryption="wpa2"})
+       anonymous_identity:depends({mode="sta-wds", eap_type="fast", encryption="wpa"})
+       anonymous_identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
+       anonymous_identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
+       anonymous_identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
+       anonymous_identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
+       anonymous_identity:depends({mode="sta", eap_type="tls", encryption="wpa2"})
+       anonymous_identity:depends({mode="sta", eap_type="tls", encryption="wpa"})
+       anonymous_identity:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
+       anonymous_identity:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
+
        password = s:taboption("encryption", Value, "password", translate("Password"))
        password:depends({mode="sta", eap_type="fast", encryption="wpa2"})
        password:depends({mode="sta", eap_type="fast", encryption="wpa"})