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