luci-mod-admin-full: rework wifi configuration
[project/luci.git] / modules / luci-mod-admin-full / luasrc / model / cbi / admin_network / wifi.lua
1 -- Copyright 2008 Steven Barth <steven@midlink.org>
2 -- Licensed to the public under the Apache License 2.0.
3
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"
9
10 local acct_port, acct_secret, acct_server, anonymous_identity, ant1, ant2,
11         auth, auth_port, auth_secret, auth_server, bssid, cacert, cacert2,
12         cc, ch, cipher, clientcert, clientcert2, ea, eaptype, en, encr,
13         ft_protocol, ft_psk_generate_local, hidden, htmode, identity,
14         ieee80211r, ieee80211w, ifname, ifsection, isolate, key_retries,
15         legacyrates, max_timeout, meshfwd, meshid, ml, mobility_domain, mode,
16         mp, nasid, network, password, pmk_r1_push, privkey, privkey2, privkeypwd,
17         privkeypwd2, r0_key_lifetime, r0kh, r1_key_holder, r1kh,
18         reassociation_deadline, retry_timeout, ssid, st, tp, wepkey, wepslot,
19         wmm, wpakey, wps
20
21 arg[1] = arg[1] or ""
22
23 m = Map("wireless", "",
24         translate("The <em>Device Configuration</em> section covers physical settings of the radio " ..
25                 "hardware such as channel, transmit power or antenna selection which are shared among all " ..
26                 "defined wireless networks (if the radio hardware is multi-SSID capable). Per network settings " ..
27                 "like encryption or operation mode are grouped in the <em>Interface Configuration</em>."))
28
29 m:chain("network")
30 m:chain("firewall")
31 m.redirect = luci.dispatcher.build_url("admin/network/wireless")
32
33 function m.on_commit(map)
34         local wnet = nw:get_wifinet(arg[1])
35         if ifsection and wnet then
36                 ifsection.section = wnet.sid
37                 m.title = luci.util.pcdata(wnet:get_i18n())
38         end
39 end
40
41 nw.init(m.uci)
42
43 local wnet = nw:get_wifinet(arg[1])
44 local wdev = wnet and wnet:get_device()
45
46 -- redirect to overview page if network does not exist anymore (e.g. after a revert)
47 if not wnet or not wdev then
48         luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))
49         return
50 end
51
52 local function txpower_list(iw)
53         local list = iw.txpwrlist or { }
54         local off  = tonumber(iw.txpower_offset) or 0
55         local new  = { }
56         local prev = -1
57         local _, val
58         for _, val in ipairs(list) do
59                 local dbm = val.dbm + off
60                 local mw  = math.floor(10 ^ (dbm / 10))
61                 if mw ~= prev then
62                         prev = mw
63                         new[#new+1] = {
64                                 display_dbm = dbm,
65                                 display_mw  = mw,
66                                 driver_dbm  = val.dbm,
67                                 driver_mw   = val.mw
68                         }
69                 end
70         end
71         return new
72 end
73
74 local function txpower_current(pwr, list)
75         pwr = tonumber(pwr)
76         if pwr ~= nil then
77                 local _, item
78                 for _, item in ipairs(list) do
79                         if item.driver_dbm >= pwr then
80                                 return item.driver_dbm
81                         end
82                 end
83         end
84         return pwr or ""
85 end
86
87 local iw = luci.sys.wifi.getiwinfo(arg[1])
88 local hw_modes      = iw.hwmodelist or { }
89 local tx_power_list = txpower_list(iw)
90 local tx_power_cur  = txpower_current(wdev:get("txpower"), tx_power_list)
91
92 -- wireless toggle was requested, commit and reload page
93 function m.parse(map)
94         local new_cc = m:formvalue("cbid.wireless.%s.country" % wdev:name())
95         local old_cc = m:get(wdev:name(), "country")
96
97         if m:formvalue("cbid.wireless.%s.__toggle" % wdev:name()) then
98                 if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then
99                         wnet:set("disabled", nil)
100                 else
101                         wnet:set("disabled", "1")
102                 end
103                 wdev:set("disabled", nil)
104                 m.apply_needed = true
105                 m.redirect = nil
106         end
107
108         Map.parse(map)
109
110         if m:get(wdev:name(), "type") == "mac80211" and new_cc and new_cc ~= old_cc then
111                 luci.sys.call("iw reg set %s" % ut.shellquote(new_cc))
112
113                 local old_ch = tonumber(m:formvalue("cbid.wireless.%s._mode_freq.channel" % wdev:name()) or "")
114                 if old_ch then
115                         local _, c, new_ch
116                         for _, c in ipairs(iw.freqlist) do
117                                 if c.channel > old_ch or (old_ch <= 14 and c.channel > 14) then
118                                         break
119                                 end
120                                 new_ch = c.channel
121                         end
122                         if new_ch ~= old_ch then
123                                 wdev:set("channel", new_ch)
124                                 m.message = translatef("Channel %d is not available in the %s regulatory domain and has been auto-adjusted to %d.",
125                                         old_ch, new_cc, new_ch)
126                         end
127                 end
128         end
129
130         if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then
131                 en.title      = translate("Wireless network is disabled")
132                 en.inputtitle = translate("Enable")
133                 en.inputstyle = "apply"
134         else
135                 en.title      = translate("Wireless network is enabled")
136                 en.inputtitle = translate("Disable")
137                 en.inputstyle = "reset"
138         end
139 end
140
141 m.title = luci.util.pcdata(wnet:get_i18n())
142
143 s = m:section(NamedSection, wdev:name(), "wifi-device", translate("Device Configuration"))
144 s.addremove = false
145
146 s:tab("general", translate("General Setup"))
147 s:tab("macfilter", translate("MAC-Filter"))
148 s:tab("advanced", translate("Advanced Settings"))
149
150 st = s:taboption("general", DummyValue, "__status", translate("Status"))
151 st.template = "admin_network/wifi_status"
152 st.ifname   = arg[1]
153
154 en = s:taboption("general", Button, "__toggle")
155
156 local hwtype = wdev:get("type")
157
158 -- NanoFoo
159 local nsantenna = wdev:get("antenna")
160
161 -- Check whether there are client interfaces on the same radio,
162 -- if yes, lock the channel choice as these stations will dicatate the freq
163 local found_sta = nil
164 local _, net
165 if wnet:mode() ~= "sta" then
166         for _, net in ipairs(wdev:get_wifinets()) do
167                 if net:mode() == "sta" and net:get("disabled") ~= "1" then
168                         if not found_sta then
169                                 found_sta = {}
170                                 found_sta.channel = net:channel()
171                                 found_sta.names = {}
172                         end
173                         found_sta.names[#found_sta.names+1] = net:shortname()
174                 end
175         end
176 end
177
178 if found_sta then
179         ch = s:taboption("general", DummyValue, "choice", translate("Channel"))
180         ch.value = translatef("Locked to channel %s used by: %s",
181                 found_sta.channel or "(auto)", table.concat(found_sta.names, ", "))
182 else
183         ch = s:taboption("general", Value, "_mode_freq", '<br />'..translate("Operating frequency"))
184         ch.iwinfo = iw
185         ch.template = "cbi/wireless_modefreq"
186
187         function ch.cfgvalue(self, section)
188                 return {
189                         m:get(section, "hwmode") or "",
190                         m:get(section, "channel") or "auto",
191                         m:get(section, "htmode") or ""
192                 }
193         end
194
195         function ch.formvalue(self, section)
196                 return {
197                         m:formvalue(self:cbid(section) .. ".band") or (hw_modes.g and "11g" or "11a"),
198                         m:formvalue(self:cbid(section) .. ".channel") or "auto",
199                         m:formvalue(self:cbid(section) .. ".htmode") or ""
200                 }
201         end
202
203         function ch.write(self, section, value)
204                 m:set(section, "hwmode", value[1])
205                 m:set(section, "channel", value[2])
206                 m:set(section, "htmode", value[3])
207         end
208 end
209
210 ------------------- MAC80211 Device ------------------
211
212 if hwtype == "mac80211" then
213         if #tx_power_list > 0 then
214                 tp = s:taboption("general", ListValue,
215                         "txpower", translate("Transmit Power"), "dBm")
216                 tp.rmempty = true
217                 tp.default = tx_power_cur
218                 function tp.cfgvalue(...)
219                         return txpower_current(Value.cfgvalue(...), tx_power_list)
220                 end
221
222                 tp:value("", translate("auto"))
223                 for _, p in ipairs(tx_power_list) do
224                         tp:value(p.driver_dbm, "%i dBm (%i mW)"
225                                 %{ p.display_dbm, p.display_mw })
226                 end
227         end
228
229         local cl = iw and iw.countrylist
230         if cl and #cl > 0 then
231                 cc = s:taboption("advanced", ListValue, "country", translate("Country Code"), translate("Use ISO/IEC 3166 alpha2 country codes."))
232                 cc.default = tostring(iw and iw.country or "00")
233                 for _, c in ipairs(cl) do
234                         cc:value(c.alpha2, "%s - %s" %{ c.alpha2, c.name })
235                 end
236         else
237                 s:taboption("advanced", Value, "country", translate("Country Code"), translate("Use ISO/IEC 3166 alpha2 country codes."))
238         end
239
240         legacyrates = s:taboption("advanced", Flag, "legacy_rates", translate("Allow legacy 802.11b rates"))
241         legacyrates.rmempty = false
242         legacyrates.default = "1"
243
244         s:taboption("advanced", Value, "distance", translate("Distance Optimization"),
245                 translate("Distance to farthest network member in meters."))
246
247         -- external antenna profiles
248         local eal = iw and iw.extant
249         if eal and #eal > 0 then
250                 ea = s:taboption("advanced", ListValue, "extant", translate("Antenna Configuration"))
251                 for _, eap in ipairs(eal) do
252                         ea:value(eap.id, "%s (%s)" %{ eap.name, eap.description })
253                         if eap.selected then
254                                 ea.default = eap.id
255                         end
256                 end
257         end
258
259         s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
260         s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
261 end
262
263
264 ------------------- Broadcom Device ------------------
265
266 if hwtype == "broadcom" then
267         tp = s:taboption("general",
268                 (#tx_power_list > 0) and ListValue or Value,
269                 "txpower", translate("Transmit Power"), "dBm")
270
271         tp.rmempty = true
272         tp.default = tx_power_cur
273
274         function tp.cfgvalue(...)
275                 return txpower_current(Value.cfgvalue(...), tx_power_list)
276         end
277
278         tp:value("", translate("auto"))
279         for _, p in ipairs(tx_power_list) do
280                 tp:value(p.driver_dbm, "%i dBm (%i mW)"
281                         %{ p.display_dbm, p.display_mw })
282         end
283
284         mode = s:taboption("advanced", ListValue, "hwmode", translate("Band"))
285         if hw_modes.b then
286                 mode:value("11b", "2.4GHz (802.11b)")
287                 if hw_modes.g then
288                         mode:value("11bg", "2.4GHz (802.11b+g)")
289                 end
290         end
291         if hw_modes.g then
292                 mode:value("11g", "2.4GHz (802.11g)")
293                 mode:value("11gst", "2.4GHz (802.11g + Turbo)")
294                 mode:value("11lrs", "2.4GHz (802.11g Limited Rate Support)")
295         end
296         if hw_modes.a then mode:value("11a", "5GHz (802.11a)") end
297         if hw_modes.n then
298                 if hw_modes.g then
299                         mode:value("11ng", "2.4GHz (802.11g+n)")
300                         mode:value("11n", "2.4GHz (802.11n)")
301                 end
302                 if hw_modes.a then
303                         mode:value("11na", "5GHz (802.11a+n)")
304                         mode:value("11n", "5GHz (802.11n)")
305                 end
306                 htmode = s:taboption("advanced", ListValue, "htmode", translate("HT mode (802.11n)"))
307                 htmode:depends("hwmode", "11ng")
308                 htmode:depends("hwmode", "11na")
309                 htmode:depends("hwmode", "11n")
310                 htmode:value("HT20", "20MHz")
311                 htmode:value("HT40", "40MHz")
312         end
313
314         ant1 = s:taboption("advanced", ListValue, "txantenna", translate("Transmitter Antenna"))
315         ant1.widget = "radio"
316         ant1:depends("diversity", "")
317         ant1:value("3", translate("auto"))
318         ant1:value("0", translate("Antenna 1"))
319         ant1:value("1", translate("Antenna 2"))
320
321         ant2 = s:taboption("advanced", ListValue, "rxantenna", translate("Receiver Antenna"))
322         ant2.widget = "radio"
323         ant2:depends("diversity", "")
324         ant2:value("3", translate("auto"))
325         ant2:value("0", translate("Antenna 1"))
326         ant2:value("1", translate("Antenna 2"))
327
328         s:taboption("advanced", Flag, "frameburst", translate("Frame Bursting"))
329
330         s:taboption("advanced", Value, "distance", translate("Distance Optimization"))
331         --s:option(Value, "slottime", translate("Slot time"))
332
333         s:taboption("advanced", Value, "country", translate("Country Code"))
334         s:taboption("advanced", Value, "maxassoc", translate("Connection Limit"))
335 end
336
337
338 --------------------- HostAP Device ---------------------
339
340 if hwtype == "prism2" then
341         s:taboption("advanced", Value, "txpower", translate("Transmit Power"), "att units").rmempty = true
342
343         s:taboption("advanced", Flag, "diversity", translate("Diversity")).rmempty = false
344
345         s:taboption("advanced", Value, "txantenna", translate("Transmitter Antenna"))
346         s:taboption("advanced", Value, "rxantenna", translate("Receiver Antenna"))
347 end
348
349
350 ----------------------- Interface -----------------------
351
352 s = m:section(NamedSection, wnet.sid, "wifi-iface", translate("Interface Configuration"))
353 ifsection = s
354 s.addremove = false
355 s.anonymous = true
356 s.defaults.device = wdev:name()
357
358 s:tab("general", translate("General Setup"))
359 s:tab("encryption", translate("Wireless Security"))
360 s:tab("macfilter", translate("MAC-Filter"))
361 s:tab("advanced", translate("Advanced Settings"))
362
363 mode = s:taboption("general", ListValue, "mode", translate("Mode"))
364 mode.override_values = true
365 mode:value("ap", translate("Access Point"))
366 mode:value("sta", translate("Client"))
367 mode:value("adhoc", translate("Ad-Hoc"))
368
369 meshid = s:taboption("general", Value, "mesh_id", translate("Mesh Id"))
370 meshid:depends({mode="mesh"})
371
372 meshfwd = s:taboption("advanced", Flag, "mesh_fwding", translate("Forward mesh peer traffic"))
373 meshfwd.rmempty = false
374 meshfwd.default = "1"
375 meshfwd:depends({mode="mesh"})
376
377 ssid = s:taboption("general", Value, "ssid", translate("<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
378 ssid.datatype = "maxlength(32)"
379 ssid:depends({mode="ap"})
380 ssid:depends({mode="sta"})
381 ssid:depends({mode="adhoc"})
382 ssid:depends({mode="ahdemo"})
383 ssid:depends({mode="monitor"})
384 ssid:depends({mode="ap-wds"})
385 ssid:depends({mode="sta-wds"})
386 ssid:depends({mode="wds"})
387
388 bssid = s:taboption("general", Value, "bssid", translate("<abbr title=\"Basic Service Set Identifier\">BSSID</abbr>"))
389
390 network = s:taboption("general", Value, "network", translate("Network"),
391         translate("Choose the network(s) you want to attach to this wireless interface or " ..
392                 "fill out the <em>create</em> field to define a new network."))
393
394 network.rmempty = true
395 network.template = "cbi/network_netlist"
396 network.widget = "checkbox"
397 network.novirtual = true
398
399 function network.write(self, section, value)
400         local i = nw:get_interface(section)
401         if i then
402                 if value == '-' then
403                         value = m:formvalue(self:cbid(section) .. ".newnet")
404                         if value and #value > 0 then
405                                 local n = nw:add_network(value, {proto="none"})
406                                 if n then n:add_interface(i) end
407                         else
408                                 local n = i:get_network()
409                                 if n then n:del_interface(i) end
410                         end
411                 else
412                         local v
413                         for _, v in ipairs(i:get_networks()) do
414                                 v:del_interface(i)
415                         end
416                         for v in ut.imatch(value) do
417                                 local n = nw:get_network(v)
418                                 if n then
419                                         if not n:is_empty() then
420                                                 n:set("type", "bridge")
421                                         end
422                                         n:add_interface(i)
423                                 end
424                         end
425                 end
426         end
427 end
428
429 -------------------- MAC80211 Interface ----------------------
430
431 if hwtype == "mac80211" then
432         if fs.access("/usr/sbin/iw") then
433                 mode:value("mesh", "802.11s")
434         end
435
436         mode:value("ahdemo", translate("Pseudo Ad-Hoc (ahdemo)"))
437         mode:value("monitor", translate("Monitor"))
438         bssid:depends({mode="adhoc"})
439         bssid:depends({mode="sta"})
440         bssid:depends({mode="sta-wds"})
441
442         mp = s:taboption("macfilter", ListValue, "macfilter", translate("MAC-Address Filter"))
443         mp:depends({mode="ap"})
444         mp:depends({mode="ap-wds"})
445         mp:value("", translate("disable"))
446         mp:value("allow", translate("Allow listed only"))
447         mp:value("deny", translate("Allow all except listed"))
448
449         ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List"))
450         ml.datatype = "macaddr"
451         ml:depends({macfilter="allow"})
452         ml:depends({macfilter="deny"})
453         nt.mac_hints(function(mac, name) ml:value(mac, "%s (%s)" %{ mac, name }) end)
454
455         mode:value("ap-wds", "%s (%s)" % {translate("Access Point"), translate("WDS")})
456         mode:value("sta-wds", "%s (%s)" % {translate("Client"), translate("WDS")})
457
458         function mode.write(self, section, value)
459                 if value == "ap-wds" then
460                         ListValue.write(self, section, "ap")
461                         m.uci:set("wireless", section, "wds", 1)
462                 elseif value == "sta-wds" then
463                         ListValue.write(self, section, "sta")
464                         m.uci:set("wireless", section, "wds", 1)
465                 else
466                         ListValue.write(self, section, value)
467                         m.uci:delete("wireless", section, "wds")
468                 end
469         end
470
471         function mode.cfgvalue(self, section)
472                 local mode = ListValue.cfgvalue(self, section)
473                 local wds  = m.uci:get("wireless", section, "wds") == "1"
474
475                 if mode == "ap" and wds then
476                         return "ap-wds"
477                 elseif mode == "sta" and wds then
478                         return "sta-wds"
479                 else
480                         return mode
481                 end
482         end
483
484         hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
485         hidden:depends({mode="ap"})
486         hidden:depends({mode="ap-wds"})
487
488         wmm = s:taboption("general", Flag, "wmm", translate("WMM Mode"))
489         wmm:depends({mode="ap"})
490         wmm:depends({mode="ap-wds"})
491         wmm.default = wmm.enabled
492
493         isolate = s:taboption("advanced", Flag, "isolate", translate("Isolate Clients"),
494          translate("Prevents client-to-client communication"))
495         isolate:depends({mode="ap"})
496         isolate:depends({mode="ap-wds"})
497
498         ifname = s:taboption("advanced", Value, "ifname", translate("Interface name"), translate("Override default interface name"))
499         ifname.optional = true
500 end
501
502
503 -------------------- Broadcom Interface ----------------------
504
505 if hwtype == "broadcom" then
506         mode:value("wds", translate("WDS"))
507         mode:value("monitor", translate("Monitor"))
508
509         hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
510         hidden:depends({mode="ap"})
511         hidden:depends({mode="adhoc"})
512         hidden:depends({mode="wds"})
513
514         isolate = s:taboption("advanced", Flag, "isolate", translate("Separate Clients"),
515          translate("Prevents client-to-client communication"))
516         isolate:depends({mode="ap"})
517
518         s:taboption("advanced", Flag, "doth", "802.11h")
519         s:taboption("advanced", Flag, "wmm", translate("WMM Mode"))
520
521         bssid:depends({mode="wds"})
522         bssid:depends({mode="adhoc"})
523 end
524
525
526 ----------------------- HostAP Interface ---------------------
527
528 if hwtype == "prism2" then
529         mode:value("wds", translate("WDS"))
530         mode:value("monitor", translate("Monitor"))
531
532         hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
533         hidden:depends({mode="ap"})
534         hidden:depends({mode="adhoc"})
535         hidden:depends({mode="wds"})
536
537         bssid:depends({mode="sta"})
538
539         mp = s:taboption("macfilter", ListValue, "macpolicy", translate("MAC-Address Filter"))
540         mp:value("", translate("disable"))
541         mp:value("allow", translate("Allow listed only"))
542         mp:value("deny", translate("Allow all except listed"))
543         ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List"))
544         ml:depends({macpolicy="allow"})
545         ml:depends({macpolicy="deny"})
546         nt.mac_hints(function(mac, name) ml:value(mac, "%s (%s)" %{ mac, name }) end)
547
548         s:taboption("advanced", Value, "rate", translate("Transmission Rate"))
549         s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
550         s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
551 end
552
553
554 ------------------- WiFI-Encryption -------------------
555
556 encr = s:taboption("encryption", ListValue, "encryption", translate("Encryption"))
557 encr.override_values = true
558 encr.override_depends = true
559 encr:depends({mode="ap"})
560 encr:depends({mode="sta"})
561 encr:depends({mode="adhoc"})
562 encr:depends({mode="ahdemo"})
563 encr:depends({mode="ap-wds"})
564 encr:depends({mode="sta-wds"})
565 encr:depends({mode="mesh"})
566
567 cipher = s:taboption("encryption", ListValue, "cipher", translate("Cipher"))
568 cipher:depends({encryption="wpa"})
569 cipher:depends({encryption="wpa2"})
570 cipher:depends({encryption="psk"})
571 cipher:depends({encryption="psk2"})
572 cipher:depends({encryption="wpa-mixed"})
573 cipher:depends({encryption="psk-mixed"})
574 cipher:value("auto", translate("auto"))
575 cipher:value("ccmp", translate("Force CCMP (AES)"))
576 cipher:value("tkip", translate("Force TKIP"))
577 cipher:value("tkip+ccmp", translate("Force TKIP and CCMP (AES)"))
578
579 function encr.cfgvalue(self, section)
580         local v = tostring(ListValue.cfgvalue(self, section))
581         if v == "wep" then
582                 return "wep-open"
583         elseif v and v:match("%+") then
584                 return (v:gsub("%+.+$", ""))
585         end
586         return v
587 end
588
589 function encr.write(self, section, value)
590         local e = tostring(encr:formvalue(section))
591         local c = tostring(cipher:formvalue(section))
592         if value == "wpa" or value == "wpa2"  then
593                 self.map.uci:delete("wireless", section, "key")
594         end
595         if e and (c == "tkip" or c == "ccmp" or c == "tkip+ccmp") then
596                 e = e .. "+" .. c
597         end
598         self.map:set(section, "encryption", e)
599 end
600
601 function cipher.cfgvalue(self, section)
602         local v = tostring(ListValue.cfgvalue(encr, section))
603         if v and v:match("%+") then
604                 v = v:gsub("^[^%+]+%+", "")
605                 if v == "aes" then v = "ccmp"
606                 elseif v == "tkip+aes" then v = "tkip+ccmp"
607                 elseif v == "aes+tkip" then v = "tkip+ccmp"
608                 elseif v == "ccmp+tkip" then v = "tkip+ccmp"
609                 end
610         end
611         return v
612 end
613
614 function cipher.write(self, section)
615         return encr:write(section)
616 end
617
618
619 encr:value("none", "No Encryption")
620 encr:value("wep-open",   translate("WEP Open System"), {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}, {mode="adhoc"}, {mode="ahdemo"}, {mode="wds"})
621 encr:value("wep-shared", translate("WEP Shared Key"),  {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}, {mode="adhoc"}, {mode="ahdemo"}, {mode="wds"})
622
623 if hwtype == "mac80211" or hwtype == "prism2" then
624         local supplicant = fs.access("/usr/sbin/wpa_supplicant")
625         local hostapd = fs.access("/usr/sbin/hostapd")
626
627         -- Probe EAP support
628         local has_ap_eap  = (os.execute("hostapd -veap >/dev/null 2>/dev/null") == 0)
629         local has_sta_eap = (os.execute("wpa_supplicant -veap >/dev/null 2>/dev/null") == 0)
630
631         if hostapd and supplicant then
632                 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}, {mode="adhoc"})
633                 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}, {mode="adhoc"})
634                 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}, {mode="adhoc"})
635                 if has_ap_eap and has_sta_eap then
636                         encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
637                         encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
638                 end
639         elseif hostapd and not supplicant then
640                 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="ap-wds"})
641                 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="ap-wds"})
642                 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="ap-wds"})
643                 if has_ap_eap then
644                         encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="ap-wds"})
645                         encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="ap-wds"})
646                 end
647                 encr.description = translate(
648                         "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
649                         "and ad-hoc mode) to be installed."
650                 )
651         elseif not hostapd and supplicant then
652                 encr:value("psk", "WPA-PSK", {mode="sta"}, {mode="sta-wds"}, {mode="adhoc"})
653                 encr:value("psk2", "WPA2-PSK", {mode="sta"}, {mode="sta-wds"}, {mode="adhoc"})
654                 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"}, {mode="sta-wds"}, {mode="adhoc"})
655                 if has_sta_eap then
656                         encr:value("wpa", "WPA-EAP", {mode="sta"}, {mode="sta-wds"})
657                         encr:value("wpa2", "WPA2-EAP", {mode="sta"}, {mode="sta-wds"})
658                 end
659                 encr.description = translate(
660                         "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
661                         "and ad-hoc mode) to be installed."
662                 )
663         else
664                 encr.description = translate(
665                         "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
666                         "and ad-hoc mode) to be installed."
667                 )
668         end
669 elseif hwtype == "broadcom" then
670         encr:value("psk", "WPA-PSK")
671         encr:value("psk2", "WPA2-PSK")
672         encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
673 end
674
675 auth_server = s:taboption("encryption", Value, "auth_server", translate("Radius-Authentication-Server"))
676 auth_server:depends({mode="ap", encryption="wpa"})
677 auth_server:depends({mode="ap", encryption="wpa2"})
678 auth_server:depends({mode="ap-wds", encryption="wpa"})
679 auth_server:depends({mode="ap-wds", encryption="wpa2"})
680 auth_server.rmempty = true
681 auth_server.datatype = "host(0)"
682
683 auth_port = s:taboption("encryption", Value, "auth_port", translate("Radius-Authentication-Port"), translatef("Default %d", 1812))
684 auth_port:depends({mode="ap", encryption="wpa"})
685 auth_port:depends({mode="ap", encryption="wpa2"})
686 auth_port:depends({mode="ap-wds", encryption="wpa"})
687 auth_port:depends({mode="ap-wds", encryption="wpa2"})
688 auth_port.rmempty = true
689 auth_port.datatype = "port"
690
691 auth_secret = s:taboption("encryption", Value, "auth_secret", translate("Radius-Authentication-Secret"))
692 auth_secret:depends({mode="ap", encryption="wpa"})
693 auth_secret:depends({mode="ap", encryption="wpa2"})
694 auth_secret:depends({mode="ap-wds", encryption="wpa"})
695 auth_secret:depends({mode="ap-wds", encryption="wpa2"})
696 auth_secret.rmempty = true
697 auth_secret.password = true
698
699 acct_server = s:taboption("encryption", Value, "acct_server", translate("Radius-Accounting-Server"))
700 acct_server:depends({mode="ap", encryption="wpa"})
701 acct_server:depends({mode="ap", encryption="wpa2"})
702 acct_server:depends({mode="ap-wds", encryption="wpa"})
703 acct_server:depends({mode="ap-wds", encryption="wpa2"})
704 acct_server.rmempty = true
705 acct_server.datatype = "host(0)"
706
707 acct_port = s:taboption("encryption", Value, "acct_port", translate("Radius-Accounting-Port"), translatef("Default %d", 1813))
708 acct_port:depends({mode="ap", encryption="wpa"})
709 acct_port:depends({mode="ap", encryption="wpa2"})
710 acct_port:depends({mode="ap-wds", encryption="wpa"})
711 acct_port:depends({mode="ap-wds", encryption="wpa2"})
712 acct_port.rmempty = true
713 acct_port.datatype = "port"
714
715 acct_secret = s:taboption("encryption", Value, "acct_secret", translate("Radius-Accounting-Secret"))
716 acct_secret:depends({mode="ap", encryption="wpa"})
717 acct_secret:depends({mode="ap", encryption="wpa2"})
718 acct_secret:depends({mode="ap-wds", encryption="wpa"})
719 acct_secret:depends({mode="ap-wds", encryption="wpa2"})
720 acct_secret.rmempty = true
721 acct_secret.password = true
722
723 wpakey = s:taboption("encryption", Value, "_wpa_key", translate("Key"))
724 wpakey:depends("encryption", "psk")
725 wpakey:depends("encryption", "psk2")
726 wpakey:depends("encryption", "psk+psk2")
727 wpakey:depends("encryption", "psk-mixed")
728 wpakey.datatype = "wpakey"
729 wpakey.rmempty = true
730 wpakey.password = true
731
732 wpakey.cfgvalue = function(self, section, value)
733         local key = m.uci:get("wireless", section, "key")
734         if key == "1" or key == "2" or key == "3" or key == "4" then
735                 return nil
736         end
737         return key
738 end
739
740 wpakey.write = function(self, section, value)
741         self.map.uci:set("wireless", section, "key", value)
742         self.map.uci:delete("wireless", section, "key1")
743 end
744
745
746 wepslot = s:taboption("encryption", ListValue, "_wep_key", translate("Used Key Slot"))
747 wepslot:depends("encryption", "wep-open")
748 wepslot:depends("encryption", "wep-shared")
749 wepslot:value("1", translatef("Key #%d", 1))
750 wepslot:value("2", translatef("Key #%d", 2))
751 wepslot:value("3", translatef("Key #%d", 3))
752 wepslot:value("4", translatef("Key #%d", 4))
753
754 wepslot.cfgvalue = function(self, section)
755         local slot = tonumber(m.uci:get("wireless", section, "key"))
756         if not slot or slot < 1 or slot > 4 then
757                 return 1
758         end
759         return slot
760 end
761
762 wepslot.write = function(self, section, value)
763         self.map.uci:set("wireless", section, "key", value)
764 end
765
766 local slot
767 for slot=1,4 do
768         wepkey = s:taboption("encryption", Value, "key" .. slot, translatef("Key #%d", slot))
769         wepkey:depends("encryption", "wep-open")
770         wepkey:depends("encryption", "wep-shared")
771         wepkey.datatype = "wepkey"
772         wepkey.rmempty = true
773         wepkey.password = true
774
775         function wepkey.write(self, section, value)
776                 if value and (#value == 5 or #value == 13) then
777                         value = "s:" .. value
778                 end
779                 return Value.write(self, section, value)
780         end
781 end
782
783
784 if hwtype == "mac80211" or hwtype == "prism2" then
785
786         -- Probe 802.11r support (and EAP support as a proxy for Openwrt)
787         local has_80211r = (os.execute("hostapd -v11r 2>/dev/null || hostapd -veap 2>/dev/null") == 0)
788
789         ieee80211r = s:taboption("encryption", Flag, "ieee80211r",
790                 translate("802.11r Fast Transition"),
791                 translate("Enables fast roaming among access points that belong " ..
792                         "to the same Mobility Domain"))
793         ieee80211r:depends({mode="ap", encryption="wpa"})
794         ieee80211r:depends({mode="ap", encryption="wpa2"})
795         ieee80211r:depends({mode="ap-wds", encryption="wpa"})
796         ieee80211r:depends({mode="ap-wds", encryption="wpa2"})
797         if has_80211r then
798                 ieee80211r:depends({mode="ap", encryption="psk"})
799                 ieee80211r:depends({mode="ap", encryption="psk2"})
800                 ieee80211r:depends({mode="ap", encryption="psk-mixed"})
801                 ieee80211r:depends({mode="ap-wds", encryption="psk"})
802                 ieee80211r:depends({mode="ap-wds", encryption="psk2"})
803                 ieee80211r:depends({mode="ap-wds", encryption="psk-mixed"})
804         end
805         ieee80211r.rmempty = true
806
807         nasid = s:taboption("encryption", Value, "nasid", translate("NAS ID"),
808                 translate("Used for two different purposes: RADIUS NAS ID and " ..
809                         "802.11r R0KH-ID. Not needed with normal WPA(2)-PSK."))
810         nasid:depends({mode="ap", encryption="wpa"})
811         nasid:depends({mode="ap", encryption="wpa2"})
812         nasid:depends({mode="ap-wds", encryption="wpa"})
813         nasid:depends({mode="ap-wds", encryption="wpa2"})
814         nasid:depends({ieee80211r="1"})
815         nasid.rmempty = true
816
817         mobility_domain = s:taboption("encryption", Value, "mobility_domain",
818                         translate("Mobility Domain"),
819                         translate("4-character hexadecimal ID"))
820         mobility_domain:depends({ieee80211r="1"})
821         mobility_domain.placeholder = "4f57"
822         mobility_domain.datatype = "and(hexstring,rangelength(4,4))"
823         mobility_domain.rmempty = true
824
825         reassociation_deadline = s:taboption("encryption", Value, "reassociation_deadline",
826                 translate("Reassociation Deadline"),
827                 translate("time units (TUs / 1.024 ms) [1000-65535]"))
828         reassociation_deadline:depends({ieee80211r="1"})
829         reassociation_deadline.placeholder = "1000"
830         reassociation_deadline.datatype = "range(1000,65535)"
831         reassociation_deadline.rmempty = true
832
833         ft_protocol = s:taboption("encryption", ListValue, "ft_over_ds", translate("FT protocol"))
834         ft_protocol:depends({ieee80211r="1"})
835         ft_protocol:value("1", translatef("FT over DS"))
836         ft_protocol:value("0", translatef("FT over the Air"))
837         ft_protocol.rmempty = true
838
839         ft_psk_generate_local = s:taboption("encryption", Flag, "ft_psk_generate_local",
840                 translate("Generate PMK locally"),
841                 translate("When using a PSK, the PMK can be generated locally without inter AP communications"))
842         ft_psk_generate_local:depends({ieee80211r="1"})
843
844         r0_key_lifetime = s:taboption("encryption", Value, "r0_key_lifetime",
845                         translate("R0 Key Lifetime"), translate("minutes"))
846         r0_key_lifetime:depends({ieee80211r="1", ft_psk_generate_local=""})
847         r0_key_lifetime.placeholder = "10000"
848         r0_key_lifetime.datatype = "uinteger"
849         r0_key_lifetime.rmempty = true
850
851         r1_key_holder = s:taboption("encryption", Value, "r1_key_holder",
852                         translate("R1 Key Holder"),
853                         translate("6-octet identifier as a hex string - no colons"))
854         r1_key_holder:depends({ieee80211r="1", ft_psk_generate_local=""})
855         r1_key_holder.placeholder = "00004f577274"
856         r1_key_holder.datatype = "and(hexstring,rangelength(12,12))"
857         r1_key_holder.rmempty = true
858
859         pmk_r1_push = s:taboption("encryption", Flag, "pmk_r1_push", translate("PMK R1 Push"))
860         pmk_r1_push:depends({ieee80211r="1", ft_psk_generate_local=""})
861         pmk_r1_push.placeholder = "0"
862         pmk_r1_push.rmempty = true
863
864         r0kh = s:taboption("encryption", DynamicList, "r0kh", translate("External R0 Key Holder List"),
865                 translate("List of R0KHs in the same Mobility Domain. " ..
866                         "<br />Format: MAC-address,NAS-Identifier,128-bit key as hex string. " ..
867                         "<br />This list is used to map R0KH-ID (NAS Identifier) to a destination " ..
868                         "MAC address when requesting PMK-R1 key from the R0KH that the STA " ..
869                         "used during the Initial Mobility Domain Association."))
870         r0kh:depends({ieee80211r="1", ft_psk_generate_local=""})
871         r0kh.rmempty = true
872
873         r1kh = s:taboption("encryption", DynamicList, "r1kh", translate("External R1 Key Holder List"),
874                 translate ("List of R1KHs in the same Mobility Domain. "..
875                         "<br />Format: MAC-address,R1KH-ID as 6 octets with colons,128-bit key as hex string. "..
876                         "<br />This list is used to map R1KH-ID to a destination MAC address " ..
877                         "when sending PMK-R1 key from the R0KH. This is also the " ..
878                         "list of authorized R1KHs in the MD that can request PMK-R1 keys."))
879         r1kh:depends({ieee80211r="1", ft_psk_generate_local=""})
880         r1kh.rmempty = true
881         -- End of 802.11r options
882
883         eaptype = s:taboption("encryption", ListValue, "eap_type", translate("EAP-Method"))
884         eaptype:value("tls",  "TLS")
885         eaptype:value("ttls", "TTLS")
886         eaptype:value("peap", "PEAP")
887         eaptype:value("fast", "FAST")
888         eaptype:depends({mode="sta", encryption="wpa"})
889         eaptype:depends({mode="sta", encryption="wpa2"})
890         eaptype:depends({mode="sta-wds", encryption="wpa"})
891         eaptype:depends({mode="sta-wds", encryption="wpa2"})
892
893         cacert = s:taboption("encryption", FileUpload, "ca_cert", translate("Path to CA-Certificate"))
894         cacert:depends({mode="sta", encryption="wpa"})
895         cacert:depends({mode="sta", encryption="wpa2"})
896         cacert:depends({mode="sta-wds", encryption="wpa"})
897         cacert:depends({mode="sta-wds", encryption="wpa2"})
898         cacert.rmempty = true
899
900         clientcert = s:taboption("encryption", FileUpload, "client_cert", translate("Path to Client-Certificate"))
901         clientcert:depends({mode="sta", eap_type="tls", encryption="wpa"})
902         clientcert:depends({mode="sta", eap_type="tls", encryption="wpa2"})
903         clientcert:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
904         clientcert:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
905
906         privkey = s:taboption("encryption", FileUpload, "priv_key", translate("Path to Private Key"))
907         privkey:depends({mode="sta", eap_type="tls", encryption="wpa2"})
908         privkey:depends({mode="sta", eap_type="tls", encryption="wpa"})
909         privkey:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
910         privkey:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
911
912         privkeypwd = s:taboption("encryption", Value, "priv_key_pwd", translate("Password of Private Key"))
913         privkeypwd:depends({mode="sta", eap_type="tls", encryption="wpa2"})
914         privkeypwd:depends({mode="sta", eap_type="tls", encryption="wpa"})
915         privkeypwd:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
916         privkeypwd:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
917         privkeypwd.rmempty = true
918         privkeypwd.password = true
919
920         auth = s:taboption("encryption", ListValue, "auth", translate("Authentication"))
921         auth:value("PAP", "PAP", {eap_type="ttls"})
922         auth:value("CHAP", "CHAP", {eap_type="ttls"})
923         auth:value("MSCHAP", "MSCHAP", {eap_type="ttls"})
924         auth:value("MSCHAPV2", "MSCHAPv2", {eap_type="ttls"})
925         auth:value("EAP-GTC")
926         auth:value("EAP-MD5")
927         auth:value("EAP-MSCHAPV2")
928         auth:value("EAP-TLS")
929         auth:depends({mode="sta", eap_type="fast", encryption="wpa2"})
930         auth:depends({mode="sta", eap_type="fast", encryption="wpa"})
931         auth:depends({mode="sta", eap_type="peap", encryption="wpa2"})
932         auth:depends({mode="sta", eap_type="peap", encryption="wpa"})
933         auth:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
934         auth:depends({mode="sta", eap_type="ttls", encryption="wpa"})
935         auth:depends({mode="sta-wds", eap_type="fast", encryption="wpa2"})
936         auth:depends({mode="sta-wds", eap_type="fast", encryption="wpa"})
937         auth:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
938         auth:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
939         auth:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
940         auth:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
941
942         cacert2 = s:taboption("encryption", FileUpload, "ca_cert2", translate("Path to inner CA-Certificate"))
943         cacert2:depends({mode="sta", auth="EAP-TLS", encryption="wpa"})
944         cacert2:depends({mode="sta", auth="EAP-TLS", encryption="wpa2"})
945         cacert2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa"})
946         cacert2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa2"})
947
948         clientcert2 = s:taboption("encryption", FileUpload, "client_cert2", translate("Path to inner Client-Certificate"))
949         clientcert2:depends({mode="sta", auth="EAP-TLS", encryption="wpa"})
950         clientcert2:depends({mode="sta", auth="EAP-TLS", encryption="wpa2"})
951         clientcert2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa"})
952         clientcert2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa2"})
953
954         privkey2 = s:taboption("encryption", FileUpload, "priv_key2", translate("Path to inner Private Key"))
955         privkey2:depends({mode="sta", auth="EAP-TLS", encryption="wpa"})
956         privkey2:depends({mode="sta", auth="EAP-TLS", encryption="wpa2"})
957         privkey2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa"})
958         privkey2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa2"})
959
960         privkeypwd2 = s:taboption("encryption", Value, "priv_key2_pwd", translate("Password of inner Private Key"))
961         privkeypwd2:depends({mode="sta", auth="EAP-TLS", encryption="wpa"})
962         privkeypwd2:depends({mode="sta", auth="EAP-TLS", encryption="wpa2"})
963         privkeypwd2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa"})
964         privkeypwd2:depends({mode="sta-wds", auth="EAP-TLS", encryption="wpa2"})
965         privkeypwd2.rmempty = true
966         privkeypwd2.password = true
967
968         identity = s:taboption("encryption", Value, "identity", translate("Identity"))
969         identity:depends({mode="sta", eap_type="fast", encryption="wpa2"})
970         identity:depends({mode="sta", eap_type="fast", encryption="wpa"})
971         identity:depends({mode="sta", eap_type="peap", encryption="wpa2"})
972         identity:depends({mode="sta", eap_type="peap", encryption="wpa"})
973         identity:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
974         identity:depends({mode="sta", eap_type="ttls", encryption="wpa"})
975         identity:depends({mode="sta-wds", eap_type="fast", encryption="wpa2"})
976         identity:depends({mode="sta-wds", eap_type="fast", encryption="wpa"})
977         identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
978         identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
979         identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
980         identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
981         identity:depends({mode="sta", eap_type="tls", encryption="wpa2"})
982         identity:depends({mode="sta", eap_type="tls", encryption="wpa"})
983         identity:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
984         identity:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
985
986         anonymous_identity = s:taboption("encryption", Value, "anonymous_identity", translate("Anonymous Identity"))
987         anonymous_identity:depends({mode="sta", eap_type="fast", encryption="wpa2"})
988         anonymous_identity:depends({mode="sta", eap_type="fast", encryption="wpa"})
989         anonymous_identity:depends({mode="sta", eap_type="peap", encryption="wpa2"})
990         anonymous_identity:depends({mode="sta", eap_type="peap", encryption="wpa"})
991         anonymous_identity:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
992         anonymous_identity:depends({mode="sta", eap_type="ttls", encryption="wpa"})
993         anonymous_identity:depends({mode="sta-wds", eap_type="fast", encryption="wpa2"})
994         anonymous_identity:depends({mode="sta-wds", eap_type="fast", encryption="wpa"})
995         anonymous_identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
996         anonymous_identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
997         anonymous_identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
998         anonymous_identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
999         anonymous_identity:depends({mode="sta", eap_type="tls", encryption="wpa2"})
1000         anonymous_identity:depends({mode="sta", eap_type="tls", encryption="wpa"})
1001         anonymous_identity:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
1002         anonymous_identity:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
1003
1004         password = s:taboption("encryption", Value, "password", translate("Password"))
1005         password:depends({mode="sta", eap_type="fast", encryption="wpa2"})
1006         password:depends({mode="sta", eap_type="fast", encryption="wpa"})
1007         password:depends({mode="sta", eap_type="peap", encryption="wpa2"})
1008         password:depends({mode="sta", eap_type="peap", encryption="wpa"})
1009         password:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
1010         password:depends({mode="sta", eap_type="ttls", encryption="wpa"})
1011         password:depends({mode="sta-wds", eap_type="fast", encryption="wpa2"})
1012         password:depends({mode="sta-wds", eap_type="fast", encryption="wpa"})
1013         password:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
1014         password:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
1015         password:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
1016         password:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
1017         password.rmempty = true
1018         password.password = true
1019 end
1020
1021 -- ieee802.11w options
1022 if hwtype == "mac80211" then
1023         local has_80211w = (os.execute("hostapd -v11w 2>/dev/null || hostapd -veap 2>/dev/null") == 0)
1024         if has_80211w then
1025                 ieee80211w = s:taboption("encryption", ListValue, "ieee80211w",
1026                         translate("802.11w Management Frame Protection"),
1027                         translate("Requires the 'full' version of wpad/hostapd " ..
1028                                 "and support from the wifi driver <br />(as of Feb 2017: " ..
1029                                 "ath9k and ath10k, in LEDE also mwlwifi and mt76)"))
1030                 ieee80211w.default = ""
1031                 ieee80211w.rmempty = true
1032                 ieee80211w:value("", translate("Disabled (default)"))
1033                 ieee80211w:value("1", translate("Optional"))
1034                 ieee80211w:value("2", translate("Required"))
1035                 ieee80211w:depends({mode="ap", encryption="wpa2"})
1036                 ieee80211w:depends({mode="ap-wds", encryption="wpa2"})
1037                 ieee80211w:depends({mode="ap", encryption="psk2"})
1038                 ieee80211w:depends({mode="ap", encryption="psk-mixed"})
1039                 ieee80211w:depends({mode="ap-wds", encryption="psk2"})
1040                 ieee80211w:depends({mode="ap-wds", encryption="psk-mixed"})
1041
1042                 max_timeout = s:taboption("encryption", Value, "ieee80211w_max_timeout",
1043                                 translate("802.11w maximum timeout"),
1044                                 translate("802.11w Association SA Query maximum timeout"))
1045                 max_timeout:depends({ieee80211w="1"})
1046                 max_timeout:depends({ieee80211w="2"})
1047                 max_timeout.datatype = "uinteger"
1048                 max_timeout.placeholder = "1000"
1049                 max_timeout.rmempty = true
1050
1051                 retry_timeout = s:taboption("encryption", Value, "ieee80211w_retry_timeout",
1052                                 translate("802.11w retry timeout"),
1053                                 translate("802.11w Association SA Query retry timeout"))
1054                 retry_timeout:depends({ieee80211w="1"})
1055                 retry_timeout:depends({ieee80211w="2"})
1056                 retry_timeout.datatype = "uinteger"
1057                 retry_timeout.placeholder = "201"
1058                 retry_timeout.rmempty = true
1059         end
1060
1061         key_retries = s:taboption("encryption", Flag, "wpa_disable_eapol_key_retries",
1062                 translate("Enable key reinstallation (KRACK) countermeasures"),
1063                 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."))
1064
1065         key_retries:depends({mode="ap", encryption="wpa2"})
1066         key_retries:depends({mode="ap", encryption="psk2"})
1067         key_retries:depends({mode="ap", encryption="psk-mixed"})
1068         key_retries:depends({mode="ap-wds", encryption="wpa2"})
1069         key_retries:depends({mode="ap-wds", encryption="psk2"})
1070         key_retries:depends({mode="ap-wds", encryption="psk-mixed"})
1071 end
1072
1073 if hwtype == "mac80211" or hwtype == "prism2" then
1074         local wpasupplicant = fs.access("/usr/sbin/wpa_supplicant")
1075         local hostcli = fs.access("/usr/sbin/hostapd_cli")
1076         if hostcli and wpasupplicant then
1077                 wps = s:taboption("encryption", Flag, "wps_pushbutton", translate("Enable WPS pushbutton, requires WPA(2)-PSK"))
1078                 wps.enabled = "1"
1079                 wps.disabled = "0"
1080                 wps.rmempty = false
1081                 wps:depends("encryption", "psk")
1082                 wps:depends("encryption", "psk2")
1083                 wps:depends("encryption", "psk-mixed")
1084         end
1085 end
1086
1087 return m