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