1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
4 local wa = require "luci.tools.webadmin"
5 local nw = require "luci.model.network"
6 local ut = require "luci.util"
7 local nt = require "luci.sys".net
8 local fs = require "nixio.fs"
12 m = Map("wireless", "",
13 translate("The <em>Device Configuration</em> section covers physical settings of the radio " ..
14 "hardware such as channel, transmit power or antenna selection which are shared among all " ..
15 "defined wireless networks (if the radio hardware is multi-SSID capable). Per network settings " ..
16 "like encryption or operation mode are grouped in the <em>Interface Configuration</em>."))
20 m.redirect = luci.dispatcher.build_url("admin/network/wireless")
24 function m.on_commit(map)
25 local wnet = nw:get_wifinet(arg[1])
26 if ifsection and wnet then
27 ifsection.section = wnet.sid
28 m.title = luci.util.pcdata(wnet:get_i18n())
34 local wnet = nw:get_wifinet(arg[1])
35 local wdev = wnet and wnet:get_device()
37 -- redirect to overview page if network does not exist anymore (e.g. after a revert)
38 if not wnet or not wdev then
39 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))
43 -- wireless toggle was requested, commit and reload page
45 local new_cc = m:formvalue("cbid.wireless.%s.country" % wdev:name())
46 local old_cc = m:get(wdev:name(), "country")
48 if m:formvalue("cbid.wireless.%s.__toggle" % wdev:name()) then
49 if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then
50 wnet:set("disabled", nil)
52 wnet:set("disabled", "1")
54 wdev:set("disabled", nil)
57 luci.sys.call("(env -i /bin/ubus call network reload) >/dev/null 2>/dev/null")
59 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", arg[1]))
65 if m:get(wdev:name(), "type") == "mac80211" and new_cc and new_cc ~= old_cc then
66 luci.sys.call("iw reg set %q" % new_cc)
67 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", arg[1]))
72 m.title = luci.util.pcdata(wnet:get_i18n())
75 local function txpower_list(iw)
76 local list = iw.txpwrlist or { }
77 local off = tonumber(iw.txpower_offset) or 0
81 for _, val in ipairs(list) do
82 local dbm = val.dbm + off
83 local mw = math.floor(10 ^ (dbm / 10))
97 local function txpower_current(pwr, list)
101 for _, item in ipairs(list) do
102 if item.driver_dbm >= pwr then
103 return item.driver_dbm
110 local iw = luci.sys.wifi.getiwinfo(arg[1])
111 local hw_modes = iw.hwmodelist or { }
112 local tx_power_list = txpower_list(iw)
113 local tx_power_cur = txpower_current(wdev:get("txpower"), tx_power_list)
115 s = m:section(NamedSection, wdev:name(), "wifi-device", translate("Device Configuration"))
118 s:tab("general", translate("General Setup"))
119 s:tab("macfilter", translate("MAC-Filter"))
120 s:tab("advanced", translate("Advanced Settings"))
123 back = s:option(DummyValue, "_overview", translate("Overview"))
125 back.titleref = luci.dispatcher.build_url("admin", "network", "wireless")
128 st = s:taboption("general", DummyValue, "__status", translate("Status"))
129 st.template = "admin_network/wifi_status"
132 en = s:taboption("general", Button, "__toggle")
134 if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then
135 en.title = translate("Wireless network is disabled")
136 en.inputtitle = translate("Enable")
137 en.inputstyle = "apply"
139 en.title = translate("Wireless network is enabled")
140 en.inputtitle = translate("Disable")
141 en.inputstyle = "reset"
145 local hwtype = wdev:get("type")
148 local nsantenna = wdev:get("antenna")
150 -- Check whether there are client interfaces on the same radio,
151 -- if yes, lock the channel choice as these stations will dicatate the freq
152 local found_sta = nil
154 if wnet:mode() ~= "sta" then
155 for _, net in ipairs(wdev:get_wifinets()) do
156 if net:mode() == "sta" and net:get("disabled") ~= "1" then
157 if not found_sta then
159 found_sta.channel = net:channel()
162 found_sta.names[#found_sta.names+1] = net:shortname()
168 ch = s:taboption("general", DummyValue, "choice", translate("Channel"))
169 ch.value = translatef("Locked to channel %s used by: %s",
170 found_sta.channel or "(auto)", table.concat(found_sta.names, ", "))
172 ch = s:taboption("general", Value, "_mode_freq", '<br />'..translate("Operating frequency"))
173 ch.hwmodes = hw_modes
174 ch.htmodes = iw.htmodelist
175 ch.freqlist = iw.freqlist
176 ch.template = "cbi/wireless_modefreq"
178 function ch.cfgvalue(self, section)
180 m:get(section, "hwmode") or "",
181 m:get(section, "channel") or "auto",
182 m:get(section, "htmode") or ""
186 function ch.formvalue(self, section)
188 m:formvalue(self:cbid(section) .. ".band") or (hw_modes.g and "11g" or "11a"),
189 m:formvalue(self:cbid(section) .. ".channel") or "auto",
190 m:formvalue(self:cbid(section) .. ".htmode") or ""
194 function ch.write(self, section, value)
195 m:set(section, "hwmode", value[1])
196 m:set(section, "channel", value[2])
197 m:set(section, "htmode", value[3])
201 ------------------- MAC80211 Device ------------------
203 if hwtype == "mac80211" then
204 if #tx_power_list > 0 then
205 tp = s:taboption("general", ListValue,
206 "txpower", translate("Transmit Power"), "dBm")
208 tp.default = tx_power_cur
209 function tp.cfgvalue(...)
210 return txpower_current(Value.cfgvalue(...), tx_power_list)
213 tp:value("", translate("auto"))
214 for _, p in ipairs(tx_power_list) do
215 tp:value(p.driver_dbm, "%i dBm (%i mW)"
216 %{ p.display_dbm, p.display_mw })
220 local cl = iw and iw.countrylist
221 if cl and #cl > 0 then
222 cc = s:taboption("advanced", ListValue, "country", translate("Country Code"), translate("Use ISO/IEC 3166 alpha2 country codes."))
223 cc.default = tostring(iw and iw.country or "00")
224 for _, c in ipairs(cl) do
225 cc:value(c.alpha2, "%s - %s" %{ c.alpha2, c.name })
228 s:taboption("advanced", Value, "country", translate("Country Code"), translate("Use ISO/IEC 3166 alpha2 country codes."))
231 s:taboption("advanced", Value, "distance", translate("Distance Optimization"),
232 translate("Distance to farthest network member in meters."))
234 -- external antenna profiles
235 local eal = iw and iw.extant
236 if eal and #eal > 0 then
237 ea = s:taboption("advanced", ListValue, "extant", translate("Antenna Configuration"))
238 for _, eap in ipairs(eal) do
239 ea:value(eap.id, "%s (%s)" %{ eap.name, eap.description })
246 s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
247 s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
251 ------------------- Broadcom Device ------------------
253 if hwtype == "broadcom" then
254 tp = s:taboption("general",
255 (#tx_power_list > 0) and ListValue or Value,
256 "txpower", translate("Transmit Power"), "dBm")
259 tp.default = tx_power_cur
261 function tp.cfgvalue(...)
262 return txpower_current(Value.cfgvalue(...), tx_power_list)
265 tp:value("", translate("auto"))
266 for _, p in ipairs(tx_power_list) do
267 tp:value(p.driver_dbm, "%i dBm (%i mW)"
268 %{ p.display_dbm, p.display_mw })
271 mode = s:taboption("advanced", ListValue, "hwmode", translate("Band"))
273 mode:value("11b", "2.4GHz (802.11b)")
275 mode:value("11bg", "2.4GHz (802.11b+g)")
279 mode:value("11g", "2.4GHz (802.11g)")
280 mode:value("11gst", "2.4GHz (802.11g + Turbo)")
281 mode:value("11lrs", "2.4GHz (802.11g Limited Rate Support)")
283 if hw_modes.a then mode:value("11a", "5GHz (802.11a)") end
286 mode:value("11ng", "2.4GHz (802.11g+n)")
287 mode:value("11n", "2.4GHz (802.11n)")
290 mode:value("11na", "5GHz (802.11a+n)")
291 mode:value("11n", "5GHz (802.11n)")
293 htmode = s:taboption("advanced", ListValue, "htmode", translate("HT mode (802.11n)"))
294 htmode:depends("hwmode", "11ng")
295 htmode:depends("hwmode", "11na")
296 htmode:depends("hwmode", "11n")
297 htmode:value("HT20", "20MHz")
298 htmode:value("HT40", "40MHz")
301 ant1 = s:taboption("advanced", ListValue, "txantenna", translate("Transmitter Antenna"))
302 ant1.widget = "radio"
303 ant1:depends("diversity", "")
304 ant1:value("3", translate("auto"))
305 ant1:value("0", translate("Antenna 1"))
306 ant1:value("1", translate("Antenna 2"))
308 ant2 = s:taboption("advanced", ListValue, "rxantenna", translate("Receiver Antenna"))
309 ant2.widget = "radio"
310 ant2:depends("diversity", "")
311 ant2:value("3", translate("auto"))
312 ant2:value("0", translate("Antenna 1"))
313 ant2:value("1", translate("Antenna 2"))
315 s:taboption("advanced", Flag, "frameburst", translate("Frame Bursting"))
317 s:taboption("advanced", Value, "distance", translate("Distance Optimization"))
318 --s:option(Value, "slottime", translate("Slot time"))
320 s:taboption("advanced", Value, "country", translate("Country Code"))
321 s:taboption("advanced", Value, "maxassoc", translate("Connection Limit"))
325 --------------------- HostAP Device ---------------------
327 if hwtype == "prism2" then
328 s:taboption("advanced", Value, "txpower", translate("Transmit Power"), "att units").rmempty = true
330 s:taboption("advanced", Flag, "diversity", translate("Diversity")).rmempty = false
332 s:taboption("advanced", Value, "txantenna", translate("Transmitter Antenna"))
333 s:taboption("advanced", Value, "rxantenna", translate("Receiver Antenna"))
337 ----------------------- Interface -----------------------
339 s = m:section(NamedSection, wnet.sid, "wifi-iface", translate("Interface Configuration"))
343 s.defaults.device = wdev:name()
345 s:tab("general", translate("General Setup"))
346 s:tab("encryption", translate("Wireless Security"))
347 s:tab("macfilter", translate("MAC-Filter"))
348 s:tab("advanced", translate("Advanced Settings"))
350 mode = s:taboption("general", ListValue, "mode", translate("Mode"))
351 mode.override_values = true
352 mode:value("ap", translate("Access Point"))
353 mode:value("sta", translate("Client"))
354 mode:value("adhoc", translate("Ad-Hoc"))
356 meshid = s:taboption("general", Value, "mesh_id", translate("Mesh Id"))
357 meshid:depends({mode="mesh"})
359 meshfwd = s:taboption("advanced", Flag, "mesh_fwding", translate("internal forwarding of Mesh-peers"))
360 meshfwd.rmempty = false
361 meshfwd.default = "1"
362 meshfwd:depends({mode="mesh"})
364 ssid = s:taboption("general", Value, "ssid", translate("<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
365 ssid.datatype = "maxlength(32)"
366 ssid:depends({mode="ap"})
367 ssid:depends({mode="sta"})
368 ssid:depends({mode="adhoc"})
369 ssid:depends({mode="ahdemo"})
370 ssid:depends({mode="monitor"})
371 ssid:depends({mode="ap-wds"})
372 ssid:depends({mode="sta-wds"})
373 ssid:depends({mode="wds"})
375 bssid = s:taboption("general", Value, "bssid", translate("<abbr title=\"Basic Service Set Identifier\">BSSID</abbr>"))
377 network = s:taboption("general", Value, "network", translate("Network"),
378 translate("Choose the network(s) you want to attach to this wireless interface or " ..
379 "fill out the <em>create</em> field to define a new network."))
381 network.rmempty = true
382 network.template = "cbi/network_netlist"
383 network.widget = "checkbox"
384 network.novirtual = true
386 function network.write(self, section, value)
387 local i = nw:get_interface(section)
390 value = m:formvalue(self:cbid(section) .. ".newnet")
391 if value and #value > 0 then
392 local n = nw:add_network(value, {proto="none"})
393 if n then n:add_interface(i) end
395 local n = i:get_network()
396 if n then n:del_interface(i) end
400 for _, v in ipairs(i:get_networks()) do
403 for v in ut.imatch(value) do
404 local n = nw:get_network(v)
406 if not n:is_empty() then
407 n:set("type", "bridge")
416 -------------------- MAC80211 Interface ----------------------
418 if hwtype == "mac80211" then
419 if fs.access("/usr/sbin/iw") then
420 mode:value("mesh", "802.11s")
423 mode:value("ahdemo", translate("Pseudo Ad-Hoc (ahdemo)"))
424 mode:value("monitor", translate("Monitor"))
425 bssid:depends({mode="adhoc"})
426 bssid:depends({mode="sta"})
427 bssid:depends({mode="sta-wds"})
429 mp = s:taboption("macfilter", ListValue, "macfilter", translate("MAC-Address Filter"))
430 mp:depends({mode="ap"})
431 mp:depends({mode="ap-wds"})
432 mp:value("", translate("disable"))
433 mp:value("allow", translate("Allow listed only"))
434 mp:value("deny", translate("Allow all except listed"))
436 ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List"))
437 ml.datatype = "macaddr"
438 ml:depends({macfilter="allow"})
439 ml:depends({macfilter="deny"})
440 nt.mac_hints(function(mac, name) ml:value(mac, "%s (%s)" %{ mac, name }) end)
442 mode:value("ap-wds", "%s (%s)" % {translate("Access Point"), translate("WDS")})
443 mode:value("sta-wds", "%s (%s)" % {translate("Client"), translate("WDS")})
445 function mode.write(self, section, value)
446 if value == "ap-wds" then
447 ListValue.write(self, section, "ap")
448 m.uci:set("wireless", section, "wds", 1)
449 elseif value == "sta-wds" then
450 ListValue.write(self, section, "sta")
451 m.uci:set("wireless", section, "wds", 1)
453 ListValue.write(self, section, value)
454 m.uci:delete("wireless", section, "wds")
458 function mode.cfgvalue(self, section)
459 local mode = ListValue.cfgvalue(self, section)
460 local wds = m.uci:get("wireless", section, "wds") == "1"
462 if mode == "ap" and wds then
464 elseif mode == "sta" and wds then
471 hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
472 hidden:depends({mode="ap"})
473 hidden:depends({mode="ap-wds"})
475 wmm = s:taboption("general", Flag, "wmm", translate("WMM Mode"))
476 wmm:depends({mode="ap"})
477 wmm:depends({mode="ap-wds"})
478 wmm.default = wmm.enabled
480 isolate = s:taboption("advanced", Flag, "isolate", translate("Isolate Clients"),
481 translate("Prevents client-to-client communication"))
482 isolate:depends({mode="ap"})
483 isolate:depends({mode="ap-wds"})
485 ifname = s:taboption("advanced", Value, "ifname", translate("Interface name"), translate("Override default interface name"))
486 ifname.optional = true
490 -------------------- Broadcom Interface ----------------------
492 if hwtype == "broadcom" then
493 mode:value("wds", translate("WDS"))
494 mode:value("monitor", translate("Monitor"))
496 hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
497 hidden:depends({mode="ap"})
498 hidden:depends({mode="adhoc"})
499 hidden:depends({mode="wds"})
501 isolate = s:taboption("advanced", Flag, "isolate", translate("Separate Clients"),
502 translate("Prevents client-to-client communication"))
503 isolate:depends({mode="ap"})
505 s:taboption("advanced", Flag, "doth", "802.11h")
506 s:taboption("advanced", Flag, "wmm", translate("WMM Mode"))
508 bssid:depends({mode="wds"})
509 bssid:depends({mode="adhoc"})
513 ----------------------- HostAP Interface ---------------------
515 if hwtype == "prism2" then
516 mode:value("wds", translate("WDS"))
517 mode:value("monitor", translate("Monitor"))
519 hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
520 hidden:depends({mode="ap"})
521 hidden:depends({mode="adhoc"})
522 hidden:depends({mode="wds"})
524 bssid:depends({mode="sta"})
526 mp = s:taboption("macfilter", ListValue, "macpolicy", translate("MAC-Address Filter"))
527 mp:value("", translate("disable"))
528 mp:value("allow", translate("Allow listed only"))
529 mp:value("deny", translate("Allow all except listed"))
530 ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List"))
531 ml:depends({macpolicy="allow"})
532 ml:depends({macpolicy="deny"})
533 nt.mac_hints(function(mac, name) ml:value(mac, "%s (%s)" %{ mac, name }) end)
535 s:taboption("advanced", Value, "rate", translate("Transmission Rate"))
536 s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
537 s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
541 ------------------- WiFI-Encryption -------------------
543 encr = s:taboption("encryption", ListValue, "encryption", translate("Encryption"))
544 encr.override_values = true
545 encr.override_depends = true
546 encr:depends({mode="ap"})
547 encr:depends({mode="sta"})
548 encr:depends({mode="adhoc"})
549 encr:depends({mode="ahdemo"})
550 encr:depends({mode="ap-wds"})
551 encr:depends({mode="sta-wds"})
552 encr:depends({mode="mesh"})
554 cipher = s:taboption("encryption", ListValue, "cipher", translate("Cipher"))
555 cipher:depends({encryption="wpa"})
556 cipher:depends({encryption="wpa2"})
557 cipher:depends({encryption="psk"})
558 cipher:depends({encryption="psk2"})
559 cipher:depends({encryption="wpa-mixed"})
560 cipher:depends({encryption="psk-mixed"})
561 cipher:value("auto", translate("auto"))
562 cipher:value("ccmp", translate("Force CCMP (AES)"))
563 cipher:value("tkip", translate("Force TKIP"))
564 cipher:value("tkip+ccmp", translate("Force TKIP and CCMP (AES)"))
566 function encr.cfgvalue(self, section)
567 local v = tostring(ListValue.cfgvalue(self, section))
570 elseif v and v:match("%+") then
571 return (v:gsub("%+.+$", ""))
576 function encr.write(self, section, value)
577 local e = tostring(encr:formvalue(section))
578 local c = tostring(cipher:formvalue(section))
579 if value == "wpa" or value == "wpa2" then
580 self.map.uci:delete("wireless", section, "key")
582 if e and (c == "tkip" or c == "ccmp" or c == "tkip+ccmp") then
585 self.map:set(section, "encryption", e)
588 function cipher.cfgvalue(self, section)
589 local v = tostring(ListValue.cfgvalue(encr, section))
590 if v and v:match("%+") then
591 v = v:gsub("^[^%+]+%+", "")
592 if v == "aes" then v = "ccmp"
593 elseif v == "tkip+aes" then v = "tkip+ccmp"
594 elseif v == "aes+tkip" then v = "tkip+ccmp"
595 elseif v == "ccmp+tkip" then v = "tkip+ccmp"
601 function cipher.write(self, section)
602 return encr:write(section)
606 encr:value("none", "No Encryption")
607 encr:value("wep-open", translate("WEP Open System"), {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}, {mode="adhoc"}, {mode="ahdemo"}, {mode="wds"})
608 encr:value("wep-shared", translate("WEP Shared Key"), {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}, {mode="adhoc"}, {mode="ahdemo"}, {mode="wds"})
610 if hwtype == "mac80211" or hwtype == "prism2" then
611 local supplicant = fs.access("/usr/sbin/wpa_supplicant")
612 local hostapd = fs.access("/usr/sbin/hostapd")
615 local has_ap_eap = (os.execute("hostapd -veap >/dev/null 2>/dev/null") == 0)
616 local has_sta_eap = (os.execute("wpa_supplicant -veap >/dev/null 2>/dev/null") == 0)
618 if hostapd and supplicant then
619 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}, {mode="adhoc"})
620 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}, {mode="adhoc"})
621 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}, {mode="adhoc"})
622 if has_ap_eap and has_sta_eap then
623 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
624 encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
626 elseif hostapd and not supplicant then
627 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="ap-wds"})
628 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="ap-wds"})
629 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="ap-wds"})
631 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="ap-wds"})
632 encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="ap-wds"})
634 encr.description = translate(
635 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
636 "and ad-hoc mode) to be installed."
638 elseif not hostapd and supplicant then
639 encr:value("psk", "WPA-PSK", {mode="sta"}, {mode="sta-wds"}, {mode="adhoc"})
640 encr:value("psk2", "WPA2-PSK", {mode="sta"}, {mode="sta-wds"}, {mode="adhoc"})
641 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"}, {mode="sta-wds"}, {mode="adhoc"})
643 encr:value("wpa", "WPA-EAP", {mode="sta"}, {mode="sta-wds"})
644 encr:value("wpa2", "WPA2-EAP", {mode="sta"}, {mode="sta-wds"})
646 encr.description = translate(
647 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
648 "and ad-hoc mode) to be installed."
651 encr.description = translate(
652 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
653 "and ad-hoc mode) to be installed."
656 elseif hwtype == "broadcom" then
657 encr:value("psk", "WPA-PSK")
658 encr:value("psk2", "WPA2-PSK")
659 encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
662 auth_server = s:taboption("encryption", Value, "auth_server", translate("Radius-Authentication-Server"))
663 auth_server:depends({mode="ap", encryption="wpa"})
664 auth_server:depends({mode="ap", encryption="wpa2"})
665 auth_server:depends({mode="ap-wds", encryption="wpa"})
666 auth_server:depends({mode="ap-wds", encryption="wpa2"})
667 auth_server.rmempty = true
668 auth_server.datatype = "host(0)"
670 auth_port = s:taboption("encryption", Value, "auth_port", translate("Radius-Authentication-Port"), translatef("Default %d", 1812))
671 auth_port:depends({mode="ap", encryption="wpa"})
672 auth_port:depends({mode="ap", encryption="wpa2"})
673 auth_port:depends({mode="ap-wds", encryption="wpa"})
674 auth_port:depends({mode="ap-wds", encryption="wpa2"})
675 auth_port.rmempty = true
676 auth_port.datatype = "port"
678 auth_secret = s:taboption("encryption", Value, "auth_secret", translate("Radius-Authentication-Secret"))
679 auth_secret:depends({mode="ap", encryption="wpa"})
680 auth_secret:depends({mode="ap", encryption="wpa2"})
681 auth_secret:depends({mode="ap-wds", encryption="wpa"})
682 auth_secret:depends({mode="ap-wds", encryption="wpa2"})
683 auth_secret.rmempty = true
684 auth_secret.password = true
686 acct_server = s:taboption("encryption", Value, "acct_server", translate("Radius-Accounting-Server"))
687 acct_server:depends({mode="ap", encryption="wpa"})
688 acct_server:depends({mode="ap", encryption="wpa2"})
689 acct_server:depends({mode="ap-wds", encryption="wpa"})
690 acct_server:depends({mode="ap-wds", encryption="wpa2"})
691 acct_server.rmempty = true
692 acct_server.datatype = "host(0)"
694 acct_port = s:taboption("encryption", Value, "acct_port", translate("Radius-Accounting-Port"), translatef("Default %d", 1813))
695 acct_port:depends({mode="ap", encryption="wpa"})
696 acct_port:depends({mode="ap", encryption="wpa2"})
697 acct_port:depends({mode="ap-wds", encryption="wpa"})
698 acct_port:depends({mode="ap-wds", encryption="wpa2"})
699 acct_port.rmempty = true
700 acct_port.datatype = "port"
702 acct_secret = s:taboption("encryption", Value, "acct_secret", translate("Radius-Accounting-Secret"))
703 acct_secret:depends({mode="ap", encryption="wpa"})
704 acct_secret:depends({mode="ap", encryption="wpa2"})
705 acct_secret:depends({mode="ap-wds", encryption="wpa"})
706 acct_secret:depends({mode="ap-wds", encryption="wpa2"})
707 acct_secret.rmempty = true
708 acct_secret.password = true
710 wpakey = s:taboption("encryption", Value, "_wpa_key", translate("Key"))
711 wpakey:depends("encryption", "psk")
712 wpakey:depends("encryption", "psk2")
713 wpakey:depends("encryption", "psk+psk2")
714 wpakey:depends("encryption", "psk-mixed")
715 wpakey.datatype = "wpakey"
716 wpakey.rmempty = true
717 wpakey.password = true
719 wpakey.cfgvalue = function(self, section, value)
720 local key = m.uci:get("wireless", section, "key")
721 if key == "1" or key == "2" or key == "3" or key == "4" then
727 wpakey.write = function(self, section, value)
728 self.map.uci:set("wireless", section, "key", value)
729 self.map.uci:delete("wireless", section, "key1")
733 wepslot = s:taboption("encryption", ListValue, "_wep_key", translate("Used Key Slot"))
734 wepslot:depends("encryption", "wep-open")
735 wepslot:depends("encryption", "wep-shared")
736 wepslot:value("1", translatef("Key #%d", 1))
737 wepslot:value("2", translatef("Key #%d", 2))
738 wepslot:value("3", translatef("Key #%d", 3))
739 wepslot:value("4", translatef("Key #%d", 4))
741 wepslot.cfgvalue = function(self, section)
742 local slot = tonumber(m.uci:get("wireless", section, "key"))
743 if not slot or slot < 1 or slot > 4 then
749 wepslot.write = function(self, section, value)
750 self.map.uci:set("wireless", section, "key", value)
755 wepkey = s:taboption("encryption", Value, "key" .. slot, translatef("Key #%d", slot))
756 wepkey:depends("encryption", "wep-open")
757 wepkey:depends("encryption", "wep-shared")
758 wepkey.datatype = "wepkey"
759 wepkey.rmempty = true
760 wepkey.password = true
762 function wepkey.write(self, section, value)
763 if value and (#value == 5 or #value == 13) then
764 value = "s:" .. value
766 return Value.write(self, section, value)
771 if hwtype == "mac80211" or hwtype == "prism2" then
773 -- Probe 802.11r support (and EAP support as a proxy for Openwrt)
774 local has_80211r = (os.execute("hostapd -v11r 2>/dev/null || hostapd -veap 2>/dev/null") == 0)
776 ieee80211r = s:taboption("encryption", Flag, "ieee80211r",
777 translate("802.11r Fast Transition"),
778 translate("Enables fast roaming among access points that belong " ..
779 "to the same Mobility Domain"))
780 ieee80211r:depends({mode="ap", encryption="wpa"})
781 ieee80211r:depends({mode="ap", encryption="wpa2"})
782 ieee80211r:depends({mode="ap-wds", encryption="wpa"})
783 ieee80211r:depends({mode="ap-wds", encryption="wpa2"})
785 ieee80211r:depends({mode="ap", encryption="psk"})
786 ieee80211r:depends({mode="ap", encryption="psk2"})
787 ieee80211r:depends({mode="ap", encryption="psk-mixed"})
788 ieee80211r:depends({mode="ap-wds", encryption="psk"})
789 ieee80211r:depends({mode="ap-wds", encryption="psk2"})
790 ieee80211r:depends({mode="ap-wds", encryption="psk-mixed"})
792 ieee80211r.rmempty = true
794 nasid = s:taboption("encryption", Value, "nasid", translate("NAS ID"),
795 translate("Used for two different purposes: RADIUS NAS ID and " ..
796 "802.11r R0KH-ID. Not needed with normal WPA(2)-PSK."))
797 nasid:depends({mode="ap", encryption="wpa"})
798 nasid:depends({mode="ap", encryption="wpa2"})
799 nasid:depends({mode="ap-wds", encryption="wpa"})
800 nasid:depends({mode="ap-wds", encryption="wpa2"})
801 nasid:depends({ieee80211r="1"})
804 mobility_domain = s:taboption("encryption", Value, "mobility_domain",
805 translate("Mobility Domain"),
806 translate("4-character hexadecimal ID"))
807 mobility_domain:depends({ieee80211r="1"})
808 mobility_domain.placeholder = "4f57"
809 mobility_domain.datatype = "and(hexstring,rangelength(4,4))"
810 mobility_domain.rmempty = true
812 reassociation_deadline = s:taboption("encryption", Value, "reassociation_deadline",
813 translate("Reassociation Deadline"),
814 translate("time units (TUs / 1.024 ms) [1000-65535]"))
815 reassociation_deadline:depends({ieee80211r="1"})
816 reassociation_deadline.placeholder = "1000"
817 reassociation_deadline.datatype = "range(1000,65535)"
818 reassociation_deadline.rmempty = true
820 ft_protocol = s:taboption("encryption", ListValue, "ft_over_ds", translate("FT protocol"))
821 ft_protocol:depends({ieee80211r="1"})
822 ft_protocol:value("1", translatef("FT over DS"))
823 ft_protocol:value("0", translatef("FT over the Air"))
824 ft_protocol.rmempty = true
826 ft_psk_generate_local = s:taboption("encryption", Flag, "ft_psk_generate_local",
827 translate("Generate PMK locally"),
828 translate("When using a PSK, the PMK can be generated locally without inter AP communications"))
829 ft_psk_generate_local:depends({ieee80211r="1"})
831 r0_key_lifetime = s:taboption("encryption", Value, "r0_key_lifetime",
832 translate("R0 Key Lifetime"), translate("minutes"))
833 r0_key_lifetime:depends({ieee80211r="1", ft_psk_generate_local=""})
834 r0_key_lifetime.placeholder = "10000"
835 r0_key_lifetime.datatype = "uinteger"
836 r0_key_lifetime.rmempty = true
838 r1_key_holder = s:taboption("encryption", Value, "r1_key_holder",
839 translate("R1 Key Holder"),
840 translate("6-octet identifier as a hex string - no colons"))
841 r1_key_holder:depends({ieee80211r="1", ft_psk_generate_local=""})
842 r1_key_holder.placeholder = "00004f577274"
843 r1_key_holder.datatype = "and(hexstring,rangelength(12,12))"
844 r1_key_holder.rmempty = true
846 pmk_r1_push = s:taboption("encryption", Flag, "pmk_r1_push", translate("PMK R1 Push"))
847 pmk_r1_push:depends({ieee80211r="1", ft_psk_generate_local=""})
848 pmk_r1_push.placeholder = "0"
849 pmk_r1_push.rmempty = true
851 r0kh = s:taboption("encryption", DynamicList, "r0kh", translate("External R0 Key Holder List"),
852 translate("List of R0KHs in the same Mobility Domain. " ..
853 "<br />Format: MAC-address,NAS-Identifier,128-bit key as hex string. " ..
854 "<br />This list is used to map R0KH-ID (NAS Identifier) to a destination " ..
855 "MAC address when requesting PMK-R1 key from the R0KH that the STA " ..
856 "used during the Initial Mobility Domain Association."))
857 r0kh:depends({ieee80211r="1", ft_psk_generate_local=""})
860 r1kh = s:taboption("encryption", DynamicList, "r1kh", translate("External R1 Key Holder List"),
861 translate ("List of R1KHs in the same Mobility Domain. "..
862 "<br />Format: MAC-address,R1KH-ID as 6 octets with colons,128-bit key as hex string. "..
863 "<br />This list is used to map R1KH-ID to a destination MAC address " ..
864 "when sending PMK-R1 key from the R0KH. This is also the " ..
865 "list of authorized R1KHs in the MD that can request PMK-R1 keys."))
866 r1kh:depends({ieee80211r="1", ft_psk_generate_local=""})
868 -- End of 802.11r options
870 eaptype = s:taboption("encryption", ListValue, "eap_type", translate("EAP-Method"))
871 eaptype:value("tls", "TLS")
872 eaptype:value("ttls", "TTLS")
873 eaptype:value("peap", "PEAP")
874 eaptype:value("fast", "FAST")
875 eaptype:depends({mode="sta", encryption="wpa"})
876 eaptype:depends({mode="sta", encryption="wpa2"})
877 eaptype:depends({mode="sta-wds", encryption="wpa"})
878 eaptype:depends({mode="sta-wds", encryption="wpa2"})
880 cacert = s:taboption("encryption", FileUpload, "ca_cert", translate("Path to CA-Certificate"))
881 cacert:depends({mode="sta", encryption="wpa"})
882 cacert:depends({mode="sta", encryption="wpa2"})
883 cacert:depends({mode="sta-wds", encryption="wpa"})
884 cacert:depends({mode="sta-wds", encryption="wpa2"})
885 cacert.rmempty = true
887 clientcert = s:taboption("encryption", FileUpload, "client_cert", translate("Path to Client-Certificate"))
888 clientcert:depends({mode="sta", eap_type="tls", encryption="wpa"})
889 clientcert:depends({mode="sta", eap_type="tls", encryption="wpa2"})
890 clientcert:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
891 clientcert:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
893 privkey = s:taboption("encryption", FileUpload, "priv_key", translate("Path to Private Key"))
894 privkey:depends({mode="sta", eap_type="tls", encryption="wpa2"})
895 privkey:depends({mode="sta", eap_type="tls", encryption="wpa"})
896 privkey:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
897 privkey:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
899 privkeypwd = s:taboption("encryption", Value, "priv_key_pwd", translate("Password of Private Key"))
900 privkeypwd:depends({mode="sta", eap_type="tls", encryption="wpa2"})
901 privkeypwd:depends({mode="sta", eap_type="tls", encryption="wpa"})
902 privkeypwd:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
903 privkeypwd:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
904 privkeypwd.rmempty = true
905 privkeypwd.password = true
907 auth = s:taboption("encryption", ListValue, "auth", translate("Authentication"))
908 auth:value("PAP", "PAP", {eap_type="ttls"})
909 auth:value("CHAP", "CHAP", {eap_type="ttls"})
910 auth:value("MSCHAP", "MSCHAP", {eap_type="ttls"})
911 auth:value("MSCHAPV2", "MSCHAPv2", {eap_type="ttls"})
912 auth:value("EAP-GTC")
913 auth:value("EAP-MD5")
914 auth:value("EAP-MSCHAPV2")
915 auth:value("EAP-TLS")
916 auth:depends({mode="sta", eap_type="fast", encryption="wpa2"})
917 auth:depends({mode="sta", eap_type="fast", encryption="wpa"})
918 auth:depends({mode="sta", eap_type="peap", encryption="wpa2"})
919 auth:depends({mode="sta", eap_type="peap", encryption="wpa"})
920 auth:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
921 auth:depends({mode="sta", eap_type="ttls", encryption="wpa"})
922 auth:depends({mode="sta-wds", eap_type="fast", encryption="wpa2"})
923 auth:depends({mode="sta-wds", eap_type="fast", encryption="wpa"})
924 auth:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
925 auth:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
926 auth:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
927 auth:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
929 cacert2 = s:taboption("encryption", FileUpload, "ca_cert2", translate("Path to inner CA-Certificate"))
930 cacert2:depends({mode="sta", auth="EAP-TLS", encryption="wpa"})
931 cacert2:depends({mode="sta", auth="EAP-TLS", encryption="wpa2"})
932 cacert2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa"})
933 cacert2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa2"})
935 clientcert2 = s:taboption("encryption", FileUpload, "client_cert2", translate("Path to inner Client-Certificate"))
936 clientcert2:depends({mode="sta", auth="EAP-TLS", encryption="wpa"})
937 clientcert2:depends({mode="sta", auth="EAP-TLS", encryption="wpa2"})
938 clientcert2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa"})
939 clientcert2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa2"})
941 privkey2 = s:taboption("encryption", FileUpload, "priv_key2", translate("Path to inner Private Key"))
942 privkey2:depends({mode="sta", auth="EAP-TLS", encryption="wpa"})
943 privkey2:depends({mode="sta", auth="EAP-TLS", encryption="wpa2"})
944 privkey2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa"})
945 privkey2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa2"})
947 privkeypwd2 = s:taboption("encryption", Value, "priv_key2_pwd", translate("Password of inner Private Key"))
948 privkeypwd2:depends({mode="sta", auth="EAP-TLS", encryption="wpa"})
949 privkeypwd2:depends({mode="sta", auth="EAP-TLS", encryption="wpa2"})
950 privkeypwd2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa"})
951 privkeypwd2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa2"})
952 privkeypwd2.rmempty = true
953 privkeypwd2.password = true
955 identity = s:taboption("encryption", Value, "identity", translate("Identity"))
956 identity:depends({mode="sta", eap_type="fast", encryption="wpa2"})
957 identity:depends({mode="sta", eap_type="fast", encryption="wpa"})
958 identity:depends({mode="sta", eap_type="peap", encryption="wpa2"})
959 identity:depends({mode="sta", eap_type="peap", encryption="wpa"})
960 identity:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
961 identity:depends({mode="sta", eap_type="ttls", encryption="wpa"})
962 identity:depends({mode="sta-wds", eap_type="fast", encryption="wpa2"})
963 identity:depends({mode="sta-wds", eap_type="fast", encryption="wpa"})
964 identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
965 identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
966 identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
967 identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
968 identity:depends({mode="sta", eap_type="tls", encryption="wpa2"})
969 identity:depends({mode="sta", eap_type="tls", encryption="wpa"})
970 identity:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
971 identity:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
973 anonymous_identity = s:taboption("encryption", Value, "anonymous_identity", translate("Anonymous Identity"))
974 anonymous_identity:depends({mode="sta", eap_type="fast", encryption="wpa2"})
975 anonymous_identity:depends({mode="sta", eap_type="fast", encryption="wpa"})
976 anonymous_identity:depends({mode="sta", eap_type="peap", encryption="wpa2"})
977 anonymous_identity:depends({mode="sta", eap_type="peap", encryption="wpa"})
978 anonymous_identity:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
979 anonymous_identity:depends({mode="sta", eap_type="ttls", encryption="wpa"})
980 anonymous_identity:depends({mode="sta-wds", eap_type="fast", encryption="wpa2"})
981 anonymous_identity:depends({mode="sta-wds", eap_type="fast", encryption="wpa"})
982 anonymous_identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
983 anonymous_identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
984 anonymous_identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
985 anonymous_identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
986 anonymous_identity:depends({mode="sta", eap_type="tls", encryption="wpa2"})
987 anonymous_identity:depends({mode="sta", eap_type="tls", encryption="wpa"})
988 anonymous_identity:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
989 anonymous_identity:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
991 password = s:taboption("encryption", Value, "password", translate("Password"))
992 password:depends({mode="sta", eap_type="fast", encryption="wpa2"})
993 password:depends({mode="sta", eap_type="fast", encryption="wpa"})
994 password:depends({mode="sta", eap_type="peap", encryption="wpa2"})
995 password:depends({mode="sta", eap_type="peap", encryption="wpa"})
996 password:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
997 password:depends({mode="sta", eap_type="ttls", encryption="wpa"})
998 password:depends({mode="sta-wds", eap_type="fast", encryption="wpa2"})
999 password:depends({mode="sta-wds", eap_type="fast", encryption="wpa"})
1000 password:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
1001 password:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
1002 password:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
1003 password:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
1004 password.rmempty = true
1005 password.password = true
1008 -- ieee802.11w options
1009 if hwtype == "mac80211" then
1010 local has_80211w = (os.execute("hostapd -v11w 2>/dev/null || hostapd -veap 2>/dev/null") == 0)
1012 ieee80211w = s:taboption("encryption", ListValue, "ieee80211w",
1013 translate("802.11w Management Frame Protection"),
1014 translate("Requires the 'full' version of wpad/hostapd " ..
1015 "and support from the wifi driver <br />(as of Feb 2017: " ..
1016 "ath9k and ath10k, in LEDE also mwlwifi and mt76)"))
1017 ieee80211w.default = ""
1018 ieee80211w.rmempty = true
1019 ieee80211w:value("", translate("Disabled (default)"))
1020 ieee80211w:value("1", translate("Optional"))
1021 ieee80211w:value("2", translate("Required"))
1022 ieee80211w:depends({mode="ap", encryption="wpa2"})
1023 ieee80211w:depends({mode="ap-wds", encryption="wpa2"})
1024 ieee80211w:depends({mode="ap", encryption="psk2"})
1025 ieee80211w:depends({mode="ap", encryption="psk-mixed"})
1026 ieee80211w:depends({mode="ap-wds", encryption="psk2"})
1027 ieee80211w:depends({mode="ap-wds", encryption="psk-mixed"})
1029 max_timeout = s:taboption("encryption", Value, "ieee80211w_max_timeout",
1030 translate("802.11w maximum timeout"),
1031 translate("802.11w Association SA Query maximum timeout"))
1032 max_timeout:depends({ieee80211w="1"})
1033 max_timeout:depends({ieee80211w="2"})
1034 max_timeout.datatype = "uinteger"
1035 max_timeout.placeholder = "1000"
1036 max_timeout.rmempty = true
1038 retry_timeout = s:taboption("encryption", Value, "ieee80211w_retry_timeout",
1039 translate("802.11w retry timeout"),
1040 translate("802.11w Association SA Query retry timeout"))
1041 retry_timeout:depends({ieee80211w="1"})
1042 retry_timeout:depends({ieee80211w="2"})
1043 retry_timeout.datatype = "uinteger"
1044 retry_timeout.placeholder = "201"
1045 retry_timeout.rmempty = true
1048 local key_retries = s:taboption("encryption", Flag, "wpa_disable_eapol_key_retries",
1049 translate("Enable key reinstallation (KRACK) countermeasures"),
1050 translate("Complicates key reinstallation attacks on the client side by disabling retransmission of EAPOL-Key frames that are used to install keys. This workaround might cause interoperability issues and reduced robustness of key negotiation especially in environments with heavy traffic load."))
1052 key_retries:depends({mode="ap", encryption="wpa2"})
1053 key_retries:depends({mode="ap", encryption="psk2"})
1054 key_retries:depends({mode="ap", encryption="psk-mixed"})
1055 key_retries:depends({mode="ap-wds", encryption="wpa2"})
1056 key_retries:depends({mode="ap-wds", encryption="psk2"})
1057 key_retries:depends({mode="ap-wds", encryption="psk-mixed"})
1060 if hwtype == "mac80211" or hwtype == "prism2" then
1061 local wpasupplicant = fs.access("/usr/sbin/wpa_supplicant")
1062 local hostcli = fs.access("/usr/sbin/hostapd_cli")
1063 if hostcli and wpasupplicant then
1064 wps = s:taboption("encryption", Flag, "wps_pushbutton", translate("Enable WPS pushbutton, requires WPA(2)-PSK"))
1068 wps:depends("encryption", "psk")
1069 wps:depends("encryption", "psk2")
1070 wps:depends("encryption", "psk-mixed")