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