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