2ad3d5513e96047351bd3d1147e93ded732ab18e
[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 end
174
175
176 ------------------- Madwifi Device ------------------
177
178 if hwtype == "atheros" then
179 tp = s:taboption("general",
180 (#tx_powers > 0) and ListValue or Value,
181 "txpower", translate("Transmit Power"), "dBm")
182
183 tp.rmempty = true
184 tp.default = tx_power
185 for _, p in ipairs(tx_powers or {}) do
186 tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw })
187 end
188
189 mode = s:taboption("advanced", ListValue, "hwmode", translate("Mode"))
190 mode:value("", translate("auto"))
191 if hw_modes.b then mode:value("11b", "802.11b") end
192 if hw_modes.g then mode:value("11g", "802.11g") end
193 if hw_modes.a then mode:value("11a", "802.11a") end
194 if hw_modes.g then mode:value("11bg", "802.11b+g") end
195 if hw_modes.g then mode:value("11gst", "802.11g + Turbo") end
196 if hw_modes.a then mode:value("11ast", "802.11a + Turbo") end
197 mode:value("fh", translate("Frequency Hopping"))
198
199 s:taboption("advanced", Flag, "diversity", translate("Diversity")).rmempty = false
200
201 if not nsantenna then
202 ant1 = s:taboption("advanced", ListValue, "txantenna", translate("Transmitter Antenna"))
203 ant1.widget = "radio"
204 ant1.orientation = "horizontal"
205 ant1:depends("diversity", "")
206 ant1:value("0", translate("auto"))
207 ant1:value("1", translate("Antenna 1"))
208 ant1:value("2", translate("Antenna 2"))
209
210 ant2 = s:taboption("advanced", ListValue, "rxantenna", translate("Receiver Antenna"))
211 ant2.widget = "radio"
212 ant2.orientation = "horizontal"
213 ant2:depends("diversity", "")
214 ant2:value("0", translate("auto"))
215 ant2:value("1", translate("Antenna 1"))
216 ant2:value("2", translate("Antenna 2"))
217
218 else -- NanoFoo
219 local ant = s:taboption("advanced", ListValue, "antenna", translate("Transmitter Antenna"))
220 ant:value("auto")
221 ant:value("vertical")
222 ant:value("horizontal")
223 ant:value("external")
224 end
225
226 s:taboption("advanced", Value, "distance", translate("Distance Optimization"),
227 translate("Distance to farthest network member in meters."))
228 s:taboption("advanced", Value, "regdomain", translate("Regulatory Domain"))
229 s:taboption("advanced", Value, "country", translate("Country Code"))
230 s:taboption("advanced", Flag, "outdoor", translate("Outdoor Channels"))
231
232 --s:option(Flag, "nosbeacon", translate("Disable HW-Beacon timer"))
233 end
234
235
236
237 ------------------- Broadcom Device ------------------
238
239 if hwtype == "broadcom" then
240 tp = s:taboption("general",
241 (#tx_powers > 0) and ListValue or Value,
242 "txpower", translate("Transmit Power"), "dBm")
243
244 tp.rmempty = true
245 tp.default = tx_power
246 for _, p in ipairs(tx_powers or {}) do
247 tp:value(p.dbm, "%i dBm (%i mW)" %{ p.dbm, p.mw })
248 end
249
250 mode = s:taboption("advanced", ListValue, "hwmode", translate("Mode"))
251 mode:value("11bg", "802.11b+g")
252 mode:value("11b", "802.11b")
253 mode:value("11g", "802.11g")
254 mode:value("11gst", "802.11g + Turbo")
255
256 ant1 = s:taboption("advanced", ListValue, "txantenna", translate("Transmitter Antenna"))
257 ant1.widget = "radio"
258 ant1:depends("diversity", "")
259 ant1:value("3", translate("auto"))
260 ant1:value("0", translate("Antenna 1"))
261 ant1:value("1", translate("Antenna 2"))
262
263 ant2 = s:taboption("advanced", ListValue, "rxantenna", translate("Receiver Antenna"))
264 ant2.widget = "radio"
265 ant2:depends("diversity", "")
266 ant2:value("3", translate("auto"))
267 ant2:value("0", translate("Antenna 1"))
268 ant2:value("1", translate("Antenna 2"))
269
270 s:taboption("advanced", Flag, "frameburst", translate("Frame Bursting"))
271
272 s:taboption("advanced", Value, "distance", translate("Distance Optimization"))
273 --s:option(Value, "slottime", translate("Slot time"))
274
275 s:taboption("advanced", Value, "country", translate("Country Code"))
276 s:taboption("advanced", Value, "maxassoc", translate("Connection Limit"))
277 end
278
279
280 --------------------- HostAP Device ---------------------
281
282 if hwtype == "prism2" then
283 s:taboption("advanced", Value, "txpower", translate("Transmit Power"), "att units").rmempty = true
284
285 s:taboption("advanced", Flag, "diversity", translate("Diversity")).rmempty = false
286
287 s:taboption("advanced", Value, "txantenna", translate("Transmitter Antenna"))
288 s:taboption("advanced", Value, "rxantenna", translate("Receiver Antenna"))
289 end
290
291
292 ----------------------- Interface -----------------------
293
294 s = m:section(NamedSection, wnet.sid, "wifi-iface", translate("Interface Configuration"))
295 ifsection = s
296 s.addremove = false
297 s.anonymous = true
298 s.defaults.device = wdev:name()
299
300 s:tab("general", translate("General Setup"))
301 s:tab("encryption", translate("Wireless Security"))
302 s:tab("macfilter", translate("MAC-Filter"))
303 s:tab("advanced", translate("Advanced Settings"))
304
305 s:taboption("general", Value, "ssid", translate("<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
306
307 mode = s:taboption("general", ListValue, "mode", translate("Mode"))
308 mode.override_values = true
309 mode:value("ap", translate("Access Point"))
310 mode:value("sta", translate("Client"))
311 mode:value("adhoc", translate("Ad-Hoc"))
312
313 bssid = s:taboption("general", Value, "bssid", translate("<abbr title=\"Basic Service Set Identifier\">BSSID</abbr>"))
314
315 network = s:taboption("general", Value, "network", translate("Network"),
316 translate("Choose the network you want to attach to this wireless interface. " ..
317 "Select <em>unspecified</em> to not attach any network or fill out the " ..
318 "<em>create</em> field to define a new network."))
319
320 network.rmempty = true
321 network.template = "cbi/network_netlist"
322 network.widget = "radio"
323
324 function network.write(self, section, value)
325 local i = nw:get_interface(section)
326 if i then
327 if value == '-' then
328 value = m:formvalue(self:cbid(section) .. ".newnet")
329 if value and #value > 0 then
330 local n = nw:add_network(value, {proto="none"})
331 if n then n:add_interface(i) end
332 else
333 local n = i:get_network()
334 if n then n:del_interface(i) end
335 end
336 else
337 local n = nw:get_network(value)
338 if n then
339 n:set("type", "bridge")
340 n:add_interface(i)
341 end
342 end
343 end
344 end
345
346 -------------------- MAC80211 Interface ----------------------
347
348 if hwtype == "mac80211" then
349 if fs.access("/usr/sbin/iw") then
350 mode:value("mesh", "802.11s")
351 end
352
353 mode:value("ahdemo", translate("Pseudo Ad-Hoc (ahdemo)"))
354 mode:value("monitor", translate("Monitor"))
355 bssid:depends({mode="adhoc"})
356
357 s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
358 s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
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