modules/admin-full: move RTS/CTS and Frag settings to device for mac80211
[project/luci.git] / modules / admin-full / luasrc / model / cbi / admin_network / wifi.lua
1 --[[
2 LuCI - Lua Configuration Interface
3
4 Copyright 2008 Steven Barth <steven@midlink.org>
5
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 $Id$
13 ]]--
14
15 local wa = require "luci.tools.webadmin"
16 local nw = require "luci.model.network"
17 local fs = require "nixio.fs"
18
19 arg[1] = arg[1] or ""
20
21 m = Map("wireless", "",
22 translate("The <em>Device Configuration</em> section covers physical settings of the radio " ..
23 "hardware such as channel, transmit power or antenna selection which is shared among all " ..
24 "defined wireless networks (if the radio hardware is multi-SSID capable). Per network settings " ..
25 "like encryption or operation mode are grouped in the <em>Interface Configuration</em>."))
26
27 m:chain("network")
28
29 local ifsection
30
31 function m.on_commit(map)
32 local wnet = nw:get_wifinet(arg[1])
33 if ifsection and wnet then
34 ifsection.section = wnet.sid
35 m.title = luci.util.pcdata(wnet:get_i18n())
36 end
37 end
38
39 nw.init(m.uci)
40
41 local wnet = nw:get_wifinet(arg[1])
42 local wdev = wnet and wnet:get_device()
43
44 -- redirect to overview page if network does not exist anymore (e.g. after a revert)
45 if not wnet or not wdev then
46 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))
47 return
48 end
49
50 -- wireless toggle was requested, commit and reload page
51 function m.parse(map)
52 if m:formvalue("cbid.wireless.%s.__toggle" % wdev:name()) then
53 if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then
54 wnet:set("disabled", nil)
55 else
56 wnet:set("disabled", "1")
57 end
58 wdev:set("disabled", nil)
59
60 nw:commit("wireless")
61 luci.sys.call("(env -i /sbin/wifi down; env -i /sbin/wifi up) >/dev/null 2>/dev/null")
62
63 luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless", arg[1]))
64 return
65 end
66 Map.parse(map)
67 end
68
69 m.title = luci.util.pcdata(wnet:get_i18n())
70
71
72 local iw = luci.sys.wifi.getiwinfo(arg[1])
73 local hw_modes = iw.hwmodelist or { }
74 local tx_powers = iw.txpwrlist or { }
75 local tx_power = tostring(
76 (iw.txpower and iw.txpower > 0 and iw.txpower) or
77 (#tx_powers > 0 and tx_powers[#tx_powers].dbm)
78 )
79
80 s = m:section(NamedSection, wdev:name(), "wifi-device", translate("Device Configuration"))
81 s.addremove = false
82
83 s:tab("general", translate("General Setup"))
84 s:tab("macfilter", translate("MAC-Filter"))
85 s:tab("advanced", translate("Advanced Settings"))
86
87 --[[
88 back = s:option(DummyValue, "_overview", translate("Overview"))
89 back.value = ""
90 back.titleref = luci.dispatcher.build_url("admin", "network", "wireless")
91 ]]
92
93 st = s:taboption("general", DummyValue, "__status", translate("Status"))
94 st.template = "admin_network/wifi_status"
95 st.ifname = arg[1]
96
97 en = s:taboption("general", Button, "__toggle")
98
99 if wdev:get("disabled") == "1" or wnet:get("disabled") == "1" then
100 en.title = translate("Wireless network is disabled")
101 en.inputtitle = translate("Enable")
102 en.inputstyle = "apply"
103 else
104 en.title = translate("Wireless network is enabled")
105 en.inputtitle = translate("Disable")
106 en.inputstyle = "reset"
107 end
108
109
110 local hwtype = wdev:get("type")
111 local htcaps = wdev:get("ht_capab") and true or false
112
113 -- NanoFoo
114 local nsantenna = wdev:get("antenna")
115
116 ch = s:taboption("general", Value, "channel", translate("Channel"))
117 ch:value("auto", translate("auto"))
118 for _, f in ipairs(iw and iw.freqlist or luci.sys.wifi.channels()) do
119 if not f.restricted then
120 ch:value(f.channel, "%i (%.3f GHz)" %{ f.channel, f.mhz / 1000 })
121 end
122 end
123
124
125 ------------------- MAC80211 Device ------------------
126
127 if hwtype == "mac80211" then
128 tp = s:taboption("general",
129 (tx_powers and #tx_powers > 0) and ListValue or Value,
130 "txpower", translate("Transmit Power"), "dBm")
131
132 tp.rmempty = true
133 tp.default = tx_power
134 for _, p in ipairs(tx_powers or {}) do
135 tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw })
136 end
137
138 mode = s:taboption("advanced", ListValue, "hwmode", translate("Mode"))
139 mode:value("", translate("auto"))
140 if hw_modes.b then mode:value("11b", "802.11b") end
141 if hw_modes.g then mode:value("11g", "802.11g") end
142 if hw_modes.a then mode:value("11a", "802.11a") end
143
144 if htcaps then
145 if hw_modes.g and hw_modes.n then mode:value("11ng", "802.11g+n") end
146 if hw_modes.a and hw_modes.n then mode:value("11na", "802.11a+n") end
147
148 htmode = s:taboption("advanced", ListValue, "htmode", translate("HT mode"))
149 htmode:depends("hwmode", "11na")
150 htmode:depends("hwmode", "11ng")
151 htmode:value("HT20", "20MHz")
152 htmode:value("HT40-", translate("40MHz 2nd channel below"))
153 htmode:value("HT40+", translate("40MHz 2nd channel above"))
154
155 --htcapab = s:taboption("advanced", DynamicList, "ht_capab", translate("HT capabilities"))
156 --htcapab:depends("hwmode", "11na")
157 --htcapab:depends("hwmode", "11ng")
158 end
159
160 local cl = iw and iw.countrylist
161 if cl and #cl > 0 then
162 cc = s:taboption("advanced", ListValue, "country", translate("Country Code"), translate("Use ISO/IEC 3166 alpha2 country codes."))
163 cc.default = tostring(iw and iw.country or "00")
164 for _, c in ipairs(cl) do
165 cc:value(c.alpha2, "%s - %s" %{ c.alpha2, c.name })
166 end
167 else
168 s:taboption("advanced", Value, "country", translate("Country Code"), translate("Use ISO/IEC 3166 alpha2 country codes."))
169 end
170
171 s:taboption("advanced", Value, "distance", translate("Distance Optimization"),
172 translate("Distance to farthest network member in meters."))
173
174 s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
175 s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
176 end
177
178
179 ------------------- Madwifi Device ------------------
180
181 if hwtype == "atheros" then
182 tp = s:taboption("general",
183 (#tx_powers > 0) and ListValue or Value,
184 "txpower", translate("Transmit Power"), "dBm")
185
186 tp.rmempty = true
187 tp.default = tx_power
188 for _, p in ipairs(tx_powers or {}) do
189 tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw })
190 end
191
192 mode = s:taboption("advanced", ListValue, "hwmode", translate("Mode"))
193 mode:value("", translate("auto"))
194 if hw_modes.b then mode:value("11b", "802.11b") end
195 if hw_modes.g then mode:value("11g", "802.11g") end
196 if hw_modes.a then mode:value("11a", "802.11a") end
197 if hw_modes.g then mode:value("11bg", "802.11b+g") end
198 if hw_modes.g then mode:value("11gst", "802.11g + Turbo") end
199 if hw_modes.a then mode:value("11ast", "802.11a + Turbo") end
200 mode:value("fh", translate("Frequency Hopping"))
201
202 s:taboption("advanced", Flag, "diversity", translate("Diversity")).rmempty = false
203
204 if not nsantenna then
205 ant1 = s:taboption("advanced", ListValue, "txantenna", translate("Transmitter Antenna"))
206 ant1.widget = "radio"
207 ant1.orientation = "horizontal"
208 ant1:depends("diversity", "")
209 ant1:value("0", translate("auto"))
210 ant1:value("1", translate("Antenna 1"))
211 ant1:value("2", translate("Antenna 2"))
212
213 ant2 = s:taboption("advanced", ListValue, "rxantenna", translate("Receiver Antenna"))
214 ant2.widget = "radio"
215 ant2.orientation = "horizontal"
216 ant2:depends("diversity", "")
217 ant2:value("0", translate("auto"))
218 ant2:value("1", translate("Antenna 1"))
219 ant2:value("2", translate("Antenna 2"))
220
221 else -- NanoFoo
222 local ant = s:taboption("advanced", ListValue, "antenna", translate("Transmitter Antenna"))
223 ant:value("auto")
224 ant:value("vertical")
225 ant:value("horizontal")
226 ant:value("external")
227 end
228
229 s:taboption("advanced", Value, "distance", translate("Distance Optimization"),
230 translate("Distance to farthest network member in meters."))
231 s:taboption("advanced", Value, "regdomain", translate("Regulatory Domain"))
232 s:taboption("advanced", Value, "country", translate("Country Code"))
233 s:taboption("advanced", Flag, "outdoor", translate("Outdoor Channels"))
234
235 --s:option(Flag, "nosbeacon", translate("Disable HW-Beacon timer"))
236 end
237
238
239
240 ------------------- Broadcom Device ------------------
241
242 if hwtype == "broadcom" then
243 tp = s:taboption("general",
244 (#tx_powers > 0) and ListValue or Value,
245 "txpower", translate("Transmit Power"), "dBm")
246
247 tp.rmempty = true
248 tp.default = tx_power
249 for _, p in ipairs(tx_powers or {}) do
250 tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw })
251 end
252
253 mode = s:taboption("advanced", ListValue, "hwmode", translate("Mode"))
254 mode:value("11bg", "802.11b+g")
255 mode:value("11b", "802.11b")
256 mode:value("11g", "802.11g")
257 mode:value("11gst", "802.11g + Turbo")
258
259 ant1 = s:taboption("advanced", ListValue, "txantenna", translate("Transmitter Antenna"))
260 ant1.widget = "radio"
261 ant1:depends("diversity", "")
262 ant1:value("3", translate("auto"))
263 ant1:value("0", translate("Antenna 1"))
264 ant1:value("1", translate("Antenna 2"))
265
266 ant2 = s:taboption("advanced", ListValue, "rxantenna", translate("Receiver Antenna"))
267 ant2.widget = "radio"
268 ant2:depends("diversity", "")
269 ant2:value("3", translate("auto"))
270 ant2:value("0", translate("Antenna 1"))
271 ant2:value("1", translate("Antenna 2"))
272
273 s:taboption("advanced", Flag, "frameburst", translate("Frame Bursting"))
274
275 s:taboption("advanced", Value, "distance", translate("Distance Optimization"))
276 --s:option(Value, "slottime", translate("Slot time"))
277
278 s:taboption("advanced", Value, "country", translate("Country Code"))
279 s:taboption("advanced", Value, "maxassoc", translate("Connection Limit"))
280 end
281
282
283 --------------------- HostAP Device ---------------------
284
285 if hwtype == "prism2" then
286 s:taboption("advanced", Value, "txpower", translate("Transmit Power"), "att units").rmempty = true
287
288 s:taboption("advanced", Flag, "diversity", translate("Diversity")).rmempty = false
289
290 s:taboption("advanced", Value, "txantenna", translate("Transmitter Antenna"))
291 s:taboption("advanced", Value, "rxantenna", translate("Receiver Antenna"))
292 end
293
294
295 ----------------------- Interface -----------------------
296
297 s = m:section(NamedSection, wnet.sid, "wifi-iface", translate("Interface Configuration"))
298 ifsection = s
299 s.addremove = false
300 s.anonymous = true
301 s.defaults.device = wdev:name()
302
303 s:tab("general", translate("General Setup"))
304 s:tab("encryption", translate("Wireless Security"))
305 s:tab("macfilter", translate("MAC-Filter"))
306 s:tab("advanced", translate("Advanced Settings"))
307
308 s:taboption("general", Value, "ssid", translate("<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
309
310 mode = s:taboption("general", ListValue, "mode", translate("Mode"))
311 mode.override_values = true
312 mode:value("ap", translate("Access Point"))
313 mode:value("sta", translate("Client"))
314 mode:value("adhoc", translate("Ad-Hoc"))
315
316 bssid = s:taboption("general", Value, "bssid", translate("<abbr title=\"Basic Service Set Identifier\">BSSID</abbr>"))
317
318 network = s:taboption("general", Value, "network", translate("Network"),
319 translate("Choose the network you want to attach to this wireless interface. " ..
320 "Select <em>unspecified</em> to not attach any network or fill out the " ..
321 "<em>create</em> field to define a new network."))
322
323 network.rmempty = true
324 network.template = "cbi/network_netlist"
325 network.widget = "radio"
326
327 function network.write(self, section, value)
328 local i = nw:get_interface(section)
329 if i then
330 if value == '-' then
331 value = m:formvalue(self:cbid(section) .. ".newnet")
332 if value and #value > 0 then
333 local n = nw:add_network(value, {proto="none"})
334 if n then n:add_interface(i) end
335 else
336 local n = i:get_network()
337 if n then n:del_interface(i) end
338 end
339 else
340 local n = nw:get_network(value)
341 if n then
342 n:set("type", "bridge")
343 n:add_interface(i)
344 end
345 end
346 end
347 end
348
349 -------------------- MAC80211 Interface ----------------------
350
351 if hwtype == "mac80211" then
352 if fs.access("/usr/sbin/iw") then
353 mode:value("mesh", "802.11s")
354 end
355
356 mode:value("ahdemo", translate("Pseudo Ad-Hoc (ahdemo)"))
357 mode:value("monitor", translate("Monitor"))
358 bssid:depends({mode="adhoc"})
359
360 mp = s:taboption("macfilter", ListValue, "macfilter", translate("MAC-Address Filter"))
361 mp:depends({mode="ap"})
362 mp:depends({mode="ap-wds"})
363 mp:value("", translate("disable"))
364 mp:value("allow", translate("Allow listed only"))
365 mp:value("deny", translate("Allow all except listed"))
366
367 ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List"))
368 ml.datatype = "macaddr"
369 ml:depends({macfilter="allow"})
370 ml:depends({macfilter="deny"})
371
372 mode:value("ap-wds", "%s (%s)" % {translate("Access Point"), translate("WDS")})
373 mode:value("sta-wds", "%s (%s)" % {translate("Client"), translate("WDS")})
374
375 function mode.write(self, section, value)
376 if value == "ap-wds" then
377 ListValue.write(self, section, "ap")
378 m.uci:set("wireless", section, "wds", 1)
379 elseif value == "sta-wds" then
380 ListValue.write(self, section, "sta")
381 m.uci:set("wireless", section, "wds", 1)
382 else
383 ListValue.write(self, section, value)
384 m.uci:delete("wireless", section, "wds")
385 end
386 end
387
388 function mode.cfgvalue(self, section)
389 local mode = ListValue.cfgvalue(self, section)
390 local wds = m.uci:get("wireless", section, "wds") == "1"
391
392 if mode == "ap" and wds then
393 return "ap-wds"
394 elseif mode == "sta" and wds then
395 return "sta-wds"
396 else
397 return mode
398 end
399 end
400
401 hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
402 hidden:depends({mode="ap"})
403 hidden:depends({mode="ap-wds"})
404 end
405
406
407
408 -------------------- Madwifi Interface ----------------------
409
410 if hwtype == "atheros" then
411 mode:value("ahdemo", translate("Pseudo Ad-Hoc (ahdemo)"))
412 mode:value("monitor", translate("Monitor"))
413 mode:value("ap-wds", "%s (%s)" % {translate("Access Point"), translate("WDS")})
414 mode:value("sta-wds", "%s (%s)" % {translate("Client"), translate("WDS")})
415 mode:value("wds", translate("Static WDS"))
416
417 function mode.write(self, section, value)
418 if value == "ap-wds" then
419 ListValue.write(self, section, "ap")
420 m.uci:set("wireless", section, "wds", 1)
421 elseif value == "sta-wds" then
422 ListValue.write(self, section, "sta")
423 m.uci:set("wireless", section, "wds", 1)
424 else
425 ListValue.write(self, section, value)
426 m.uci:delete("wireless", section, "wds")
427 end
428 end
429
430 function mode.cfgvalue(self, section)
431 local mode = ListValue.cfgvalue(self, section)
432 local wds = m.uci:get("wireless", section, "wds") == "1"
433
434 if mode == "ap" and wds then
435 return "ap-wds"
436 elseif mode == "sta" and wds then
437 return "sta-wds"
438 else
439 return mode
440 end
441 end
442
443 bssid:depends({mode="adhoc"})
444 bssid:depends({mode="ahdemo"})
445 bssid:depends({mode="wds"})
446
447 wdssep = s:taboption("advanced", Flag, "wdssep", translate("Separate WDS"))
448 wdssep:depends({mode="ap-wds"})
449
450 s:taboption("advanced", Flag, "doth", "802.11h")
451 hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
452 hidden:depends({mode="ap"})
453 hidden:depends({mode="adhoc"})
454 hidden:depends({mode="ap-wds"})
455 hidden:depends({mode="sta-wds"})
456 isolate = s:taboption("advanced", Flag, "isolate", translate("Separate Clients"),
457 translate("Prevents client-to-client communication"))
458 isolate:depends({mode="ap"})
459 s:taboption("advanced", Flag, "bgscan", translate("Background Scan"))
460
461 mp = s:taboption("macfilter", ListValue, "macpolicy", translate("MAC-Address Filter"))
462 mp:value("", translate("disable"))
463 mp:value("allow", translate("Allow listed only"))
464 mp:value("deny", translate("Allow all except listed"))
465
466 ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List"))
467 ml.datatype = "macaddr"
468 ml:depends({macpolicy="allow"})
469 ml:depends({macpolicy="deny"})
470
471 s:taboption("advanced", Value, "rate", translate("Transmission Rate"))
472 s:taboption("advanced", Value, "mcast_rate", translate("Multicast Rate"))
473 s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
474 s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
475 s:taboption("advanced", Value, "minrate", translate("Minimum Rate"))
476 s:taboption("advanced", Value, "maxrate", translate("Maximum Rate"))
477 s:taboption("advanced", Flag, "compression", translate("Compression"))
478
479 s:taboption("advanced", Flag, "bursting", translate("Frame Bursting"))
480 s:taboption("advanced", Flag, "turbo", translate("Turbo Mode"))
481 s:taboption("advanced", Flag, "ff", translate("Fast Frames"))
482
483 s:taboption("advanced", Flag, "wmm", translate("WMM Mode"))
484 s:taboption("advanced", Flag, "xr", translate("XR Support"))
485 s:taboption("advanced", Flag, "ar", translate("AR Support"))
486
487 local swm = s:taboption("advanced", Flag, "sw_merge", translate("Disable HW-Beacon timer"))
488 swm:depends({mode="adhoc"})
489
490 local nos = s:taboption("advanced", Flag, "nosbeacon", translate("Disable HW-Beacon timer"))
491 nos:depends({mode="sta"})
492 nos:depends({mode="sta-wds"})
493
494 local probereq = s:taboption("advanced", Flag, "probereq", translate("Do not send probe responses"))
495 probereq.enabled = "0"
496 probereq.disabled = "1"
497 end
498
499
500 -------------------- Broadcom Interface ----------------------
501
502 if hwtype == "broadcom" then
503 mode:value("wds", translate("WDS"))
504 mode:value("monitor", translate("Monitor"))
505
506 hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
507 hidden:depends({mode="ap"})
508 hidden:depends({mode="adhoc"})
509 hidden:depends({mode="wds"})
510
511 isolate = s:taboption("advanced", Flag, "isolate", translate("Separate Clients"),
512 translate("Prevents client-to-client communication"))
513 isolate:depends({mode="ap"})
514
515 s:taboption("advanced", Flag, "doth", "802.11h")
516 s:taboption("advanced", Flag, "wmm", translate("WMM Mode"))
517
518 bssid:depends({mode="wds"})
519 bssid:depends({mode="adhoc"})
520 end
521
522
523 ----------------------- HostAP Interface ---------------------
524
525 if hwtype == "prism2" then
526 mode:value("wds", translate("WDS"))
527 mode:value("monitor", translate("Monitor"))
528
529 hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
530 hidden:depends({mode="ap"})
531 hidden:depends({mode="adhoc"})
532 hidden:depends({mode="wds"})
533
534 bssid:depends({mode="sta"})
535
536 mp = s:taboption("macfilter", ListValue, "macpolicy", translate("MAC-Address Filter"))
537 mp:value("", translate("disable"))
538 mp:value("allow", translate("Allow listed only"))
539 mp:value("deny", translate("Allow all except listed"))
540 ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List"))
541 ml:depends({macpolicy="allow"})
542 ml:depends({macpolicy="deny"})
543
544 s:taboption("advanced", Value, "rate", translate("Transmission Rate"))
545 s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
546 s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
547 end
548
549
550 ------------------- WiFI-Encryption -------------------
551
552 encr = s:taboption("encryption", ListValue, "encryption", translate("Encryption"))
553 encr.override_values = true
554 encr.override_depends = true
555 encr:depends({mode="ap"})
556 encr:depends({mode="sta"})
557 encr:depends({mode="adhoc"})
558 encr:depends({mode="ahdemo"})
559 encr:depends({mode="ap-wds"})
560 encr:depends({mode="sta-wds"})
561 encr:depends({mode="mesh"})
562
563 function encr.write(self, section, value)
564 if value == "wpa" or value == "wpa2" then
565 self.map.uci:delete("wireless", section, "key")
566 end
567 self.map.uci:set("wireless", section, "encryption", value)
568 end
569
570
571 encr:value("none", "No Encryption")
572 encr:value("wep-open", translate("WEP Open System"), {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
573 encr:value("wep-shared", translate("WEP Shared Key"), {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
574
575 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
576 local supplicant = fs.access("/usr/sbin/wpa_supplicant")
577 local hostapd = fs.access("/usr/sbin/hostapd")
578
579 if hostapd and supplicant then
580 encr:value("psk", "WPA-PSK")
581 encr:value("psk2", "WPA2-PSK")
582 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode")
583 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
584 encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
585 elseif hostapd and not supplicant then
586 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="ap-wds"}, {mode="adhoc"}, {mode="ahdemo"})
587 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="ap-wds"}, {mode="adhoc"}, {mode="ahdemo"})
588 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="ap-wds"}, {mode="adhoc"}, {mode="ahdemo"})
589 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="ap-wds"})
590 encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="ap-wds"})
591 encr.description = translate(
592 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
593 "and ad-hoc mode) to be installed."
594 )
595 elseif not hostapd and supplicant then
596 encr:value("psk", "WPA-PSK", {mode="sta"}, {mode="sta-wds"})
597 encr:value("psk2", "WPA2-PSK", {mode="sta"}, {mode="sta-wds"})
598 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"}, {mode="sta-wds"})
599 encr:value("wpa", "WPA-EAP", {mode="sta"}, {mode="sta-wds"})
600 encr:value("wpa2", "WPA2-EAP", {mode="sta"}, {mode="sta-wds"})
601 encr.description = translate(
602 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
603 "and ad-hoc mode) to be installed."
604 )
605 else
606 encr.description = translate(
607 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
608 "and ad-hoc mode) to be installed."
609 )
610 end
611 elseif hwtype == "broadcom" then
612 encr:value("psk", "WPA-PSK")
613 encr:value("psk2", "WPA2-PSK")
614 encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
615 end
616
617 auth_server = s:taboption("encryption", Value, "auth_server", translate("Radius-Authentication-Server"))
618 auth_server:depends({mode="ap", encryption="wpa"})
619 auth_server:depends({mode="ap", encryption="wpa2"})
620 auth_server:depends({mode="ap-wds", encryption="wpa"})
621 auth_server:depends({mode="ap-wds", encryption="wpa2"})
622 auth_server.rmempty = true
623 auth_server.datatype = "host"
624
625 auth_port = s:taboption("encryption", Value, "auth_port", translate("Radius-Authentication-Port"), translatef("Default %d", 1812))
626 auth_port:depends({mode="ap", encryption="wpa"})
627 auth_port:depends({mode="ap", encryption="wpa2"})
628 auth_port:depends({mode="ap-wds", encryption="wpa"})
629 auth_port:depends({mode="ap-wds", encryption="wpa2"})
630 auth_port.rmempty = true
631 auth_port.datatype = "port"
632
633 auth_secret = s:taboption("encryption", Value, "auth_secret", translate("Radius-Authentication-Secret"))
634 auth_secret:depends({mode="ap", encryption="wpa"})
635 auth_secret:depends({mode="ap", encryption="wpa2"})
636 auth_secret:depends({mode="ap-wds", encryption="wpa"})
637 auth_secret:depends({mode="ap-wds", encryption="wpa2"})
638 auth_secret.rmempty = true
639 auth_secret.password = true
640
641 acct_server = s:taboption("encryption", Value, "acct_server", translate("Radius-Accounting-Server"))
642 acct_server:depends({mode="ap", encryption="wpa"})
643 acct_server:depends({mode="ap", encryption="wpa2"})
644 acct_server:depends({mode="ap-wds", encryption="wpa"})
645 acct_server:depends({mode="ap-wds", encryption="wpa2"})
646 acct_server.rmempty = true
647 acct_server.datatype = "host"
648
649 acct_port = s:taboption("encryption", Value, "acct_port", translate("Radius-Accounting-Port"), translatef("Default %d", 1813))
650 acct_port:depends({mode="ap", encryption="wpa"})
651 acct_port:depends({mode="ap", encryption="wpa2"})
652 acct_port:depends({mode="ap-wds", encryption="wpa"})
653 acct_port:depends({mode="ap-wds", encryption="wpa2"})
654 acct_port.rmempty = true
655 acct_port.datatype = "port"
656
657 acct_secret = s:taboption("encryption", Value, "acct_secret", translate("Radius-Accounting-Secret"))
658 acct_secret:depends({mode="ap", encryption="wpa"})
659 acct_secret:depends({mode="ap", encryption="wpa2"})
660 acct_secret:depends({mode="ap-wds", encryption="wpa"})
661 acct_secret:depends({mode="ap-wds", encryption="wpa2"})
662 acct_secret.rmempty = true
663 acct_secret.password = true
664
665 wpakey = s:taboption("encryption", Value, "_wpa_key", translate("Key"))
666 wpakey:depends("encryption", "psk")
667 wpakey:depends("encryption", "psk2")
668 wpakey:depends("encryption", "psk+psk2")
669 wpakey:depends("encryption", "psk-mixed")
670 wpakey.datatype = "wpakey"
671 wpakey.rmempty = true
672 wpakey.password = true
673
674 wpakey.cfgvalue = function(self, section, value)
675 local key = m.uci:get("wireless", section, "key")
676 if key == "1" or key == "2" or key == "3" or key == "4" then
677 return nil
678 end
679 return key
680 end
681
682 wpakey.write = function(self, section, value)
683 self.map.uci:set("wireless", section, "key", value)
684 self.map.uci:delete("wireless", section, "key1")
685 end
686
687
688 wepslot = s:taboption("encryption", ListValue, "_wep_key", translate("Used Key Slot"))
689 wepslot:depends("encryption", "wep-open")
690 wepslot:depends("encryption", "wep-shared")
691 wepslot:value("1", translatef("Key #%d", 1))
692 wepslot:value("2", translatef("Key #%d", 2))
693 wepslot:value("3", translatef("Key #%d", 3))
694 wepslot:value("4", translatef("Key #%d", 4))
695
696 wepslot.cfgvalue = function(self, section)
697 local slot = tonumber(m.uci:get("wireless", section, "key"))
698 if not slot or slot < 1 or slot > 4 then
699 return 1
700 end
701 return slot
702 end
703
704 wepslot.write = function(self, section, value)
705 self.map.uci:set("wireless", section, "key", value)
706 end
707
708 local slot
709 for slot=1,4 do
710 wepkey = s:taboption("encryption", Value, "key" .. slot, translatef("Key #%d", slot))
711 wepkey:depends("encryption", "wep-open")
712 wepkey:depends("encryption", "wep-shared")
713 wepkey.datatype = "wepkey"
714 wepkey.rmempty = true
715 wepkey.password = true
716
717 function wepkey.write(self, section, value)
718 if value and (#value == 5 or #value == 13) then
719 value = "s:" .. value
720 end
721 return Value.write(self, section, value)
722 end
723 end
724
725
726 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
727 nasid = s:taboption("encryption", Value, "nasid", translate("NAS ID"))
728 nasid:depends({mode="ap", encryption="wpa"})
729 nasid:depends({mode="ap", encryption="wpa2"})
730 nasid:depends({mode="ap-wds", encryption="wpa"})
731 nasid:depends({mode="ap-wds", encryption="wpa2"})
732 nasid.rmempty = true
733
734 eaptype = s:taboption("encryption", ListValue, "eap_type", translate("EAP-Method"))
735 eaptype:value("tls", "TLS")
736 eaptype:value("ttls", "TTLS")
737 eaptype:value("peap", "PEAP")
738 eaptype:depends({mode="sta", encryption="wpa"})
739 eaptype:depends({mode="sta", encryption="wpa2"})
740 eaptype:depends({mode="sta-wds", encryption="wpa"})
741 eaptype:depends({mode="sta-wds", encryption="wpa2"})
742
743 cacert = s:taboption("encryption", FileUpload, "ca_cert", translate("Path to CA-Certificate"))
744 cacert:depends({mode="sta", encryption="wpa"})
745 cacert:depends({mode="sta", encryption="wpa2"})
746 cacert:depends({mode="sta-wds", encryption="wpa"})
747 cacert:depends({mode="sta-wds", encryption="wpa2"})
748
749 privkey = s:taboption("encryption", FileUpload, "priv_key", translate("Path to Private Key"))
750 privkey:depends({mode="sta", eap_type="tls", encryption="wpa2"})
751 privkey:depends({mode="sta", eap_type="tls", encryption="wpa"})
752 privkey:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
753 privkey:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
754
755 privkeypwd = s:taboption("encryption", Value, "priv_key_pwd", translate("Password of Private Key"))
756 privkeypwd:depends({mode="sta", eap_type="tls", encryption="wpa2"})
757 privkeypwd:depends({mode="sta", eap_type="tls", encryption="wpa"})
758 privkeypwd:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
759 privkeypwd:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
760
761
762 auth = s:taboption("encryption", Value, "auth", translate("Authentication"))
763 auth:value("PAP")
764 auth:value("CHAP")
765 auth:value("MSCHAP")
766 auth:value("MSCHAPV2")
767 auth:depends({mode="sta", eap_type="peap", encryption="wpa2"})
768 auth:depends({mode="sta", eap_type="peap", encryption="wpa"})
769 auth:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
770 auth:depends({mode="sta", eap_type="ttls", encryption="wpa"})
771 auth:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
772 auth:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
773 auth:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
774 auth:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
775
776
777 identity = s:taboption("encryption", Value, "identity", translate("Identity"))
778 identity:depends({mode="sta", eap_type="peap", encryption="wpa2"})
779 identity:depends({mode="sta", eap_type="peap", encryption="wpa"})
780 identity:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
781 identity:depends({mode="sta", eap_type="ttls", encryption="wpa"})
782 identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
783 identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
784 identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
785 identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
786
787 password = s:taboption("encryption", Value, "password", translate("Password"))
788 password:depends({mode="sta", eap_type="peap", encryption="wpa2"})
789 password:depends({mode="sta", eap_type="peap", encryption="wpa"})
790 password:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
791 password:depends({mode="sta", eap_type="ttls", encryption="wpa"})
792 password:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
793 password:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
794 password:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
795 password:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
796 end
797
798 return m