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