modules/admin-full: remove usage of wifi.channels()
[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 s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
231 s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
232 end
233
234
235 ------------------- Madwifi Device ------------------
236
237 if hwtype == "atheros" then
238 tp = s:taboption("general",
239 (#tx_power_list > 0) and ListValue or Value,
240 "txpower", translate("Transmit Power"), "dBm")
241
242 tp.rmempty = true
243 tp.default = tx_power_cur
244
245 function tp.cfgvalue(...)
246 return txpower_current(Value.cfgvalue(...), tx_power_list)
247 end
248
249 for _, p in ipairs(tx_power_list) do
250 tp:value(p.driver_dbm, "%i dBm (%i mW)"
251 %{ p.display_dbm, p.display_mw })
252 end
253
254 mode = s:taboption("advanced", ListValue, "hwmode", translate("Mode"))
255 mode:value("", translate("auto"))
256 if hw_modes.b then mode:value("11b", "802.11b") end
257 if hw_modes.g then mode:value("11g", "802.11g") end
258 if hw_modes.a then mode:value("11a", "802.11a") end
259 if hw_modes.g then mode:value("11bg", "802.11b+g") end
260 if hw_modes.g then mode:value("11gst", "802.11g + Turbo") end
261 if hw_modes.a then mode:value("11ast", "802.11a + Turbo") end
262 mode:value("fh", translate("Frequency Hopping"))
263
264 s:taboption("advanced", Flag, "diversity", translate("Diversity")).rmempty = false
265
266 if not nsantenna then
267 ant1 = s:taboption("advanced", ListValue, "txantenna", translate("Transmitter Antenna"))
268 ant1.widget = "radio"
269 ant1.orientation = "horizontal"
270 ant1:depends("diversity", "")
271 ant1:value("0", translate("auto"))
272 ant1:value("1", translate("Antenna 1"))
273 ant1:value("2", translate("Antenna 2"))
274
275 ant2 = s:taboption("advanced", ListValue, "rxantenna", translate("Receiver Antenna"))
276 ant2.widget = "radio"
277 ant2.orientation = "horizontal"
278 ant2:depends("diversity", "")
279 ant2:value("0", translate("auto"))
280 ant2:value("1", translate("Antenna 1"))
281 ant2:value("2", translate("Antenna 2"))
282
283 else -- NanoFoo
284 local ant = s:taboption("advanced", ListValue, "antenna", translate("Transmitter Antenna"))
285 ant:value("auto")
286 ant:value("vertical")
287 ant:value("horizontal")
288 ant:value("external")
289 end
290
291 s:taboption("advanced", Value, "distance", translate("Distance Optimization"),
292 translate("Distance to farthest network member in meters."))
293 s:taboption("advanced", Value, "regdomain", translate("Regulatory Domain"))
294 s:taboption("advanced", Value, "country", translate("Country Code"))
295 s:taboption("advanced", Flag, "outdoor", translate("Outdoor Channels"))
296
297 --s:option(Flag, "nosbeacon", translate("Disable HW-Beacon timer"))
298 end
299
300
301
302 ------------------- Broadcom Device ------------------
303
304 if hwtype == "broadcom" then
305 tp = s:taboption("general",
306 (#tx_power_list > 0) and ListValue or Value,
307 "txpower", translate("Transmit Power"), "dBm")
308
309 tp.rmempty = true
310 tp.default = tx_power_cur
311
312 function tp.cfgvalue(...)
313 return txpower_current(Value.cfgvalue(...), tx_power_list)
314 end
315
316 for _, p in ipairs(tx_power_list) do
317 tp:value(p.driver_dbm, "%i dBm (%i mW)"
318 %{ p.display_dbm, p.display_mw })
319 end
320
321 mode = s:taboption("advanced", ListValue, "hwmode", translate("Mode"))
322 mode:value("11bg", "802.11b+g")
323 mode:value("11b", "802.11b")
324 mode:value("11g", "802.11g")
325 mode:value("11gst", "802.11g + Turbo")
326
327 ant1 = s:taboption("advanced", ListValue, "txantenna", translate("Transmitter Antenna"))
328 ant1.widget = "radio"
329 ant1:depends("diversity", "")
330 ant1:value("3", translate("auto"))
331 ant1:value("0", translate("Antenna 1"))
332 ant1:value("1", translate("Antenna 2"))
333
334 ant2 = s:taboption("advanced", ListValue, "rxantenna", translate("Receiver Antenna"))
335 ant2.widget = "radio"
336 ant2:depends("diversity", "")
337 ant2:value("3", translate("auto"))
338 ant2:value("0", translate("Antenna 1"))
339 ant2:value("1", translate("Antenna 2"))
340
341 s:taboption("advanced", Flag, "frameburst", translate("Frame Bursting"))
342
343 s:taboption("advanced", Value, "distance", translate("Distance Optimization"))
344 --s:option(Value, "slottime", translate("Slot time"))
345
346 s:taboption("advanced", Value, "country", translate("Country Code"))
347 s:taboption("advanced", Value, "maxassoc", translate("Connection Limit"))
348 end
349
350
351 --------------------- HostAP Device ---------------------
352
353 if hwtype == "prism2" then
354 s:taboption("advanced", Value, "txpower", translate("Transmit Power"), "att units").rmempty = true
355
356 s:taboption("advanced", Flag, "diversity", translate("Diversity")).rmempty = false
357
358 s:taboption("advanced", Value, "txantenna", translate("Transmitter Antenna"))
359 s:taboption("advanced", Value, "rxantenna", translate("Receiver Antenna"))
360 end
361
362
363 ----------------------- Interface -----------------------
364
365 s = m:section(NamedSection, wnet.sid, "wifi-iface", translate("Interface Configuration"))
366 ifsection = s
367 s.addremove = false
368 s.anonymous = true
369 s.defaults.device = wdev:name()
370
371 s:tab("general", translate("General Setup"))
372 s:tab("encryption", translate("Wireless Security"))
373 s:tab("macfilter", translate("MAC-Filter"))
374 s:tab("advanced", translate("Advanced Settings"))
375
376 s:taboption("general", Value, "ssid", translate("<abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
377
378 mode = s:taboption("general", ListValue, "mode", translate("Mode"))
379 mode.override_values = true
380 mode:value("ap", translate("Access Point"))
381 mode:value("sta", translate("Client"))
382 mode:value("adhoc", translate("Ad-Hoc"))
383
384 bssid = s:taboption("general", Value, "bssid", translate("<abbr title=\"Basic Service Set Identifier\">BSSID</abbr>"))
385
386 network = s:taboption("general", Value, "network", translate("Network"),
387 translate("Choose the network you want to attach to this wireless interface. " ..
388 "Select <em>unspecified</em> to not attach any network or fill out the " ..
389 "<em>create</em> field to define a new network."))
390
391 network.rmempty = true
392 network.template = "cbi/network_netlist"
393 network.widget = "checkbox"
394 network.novirtual = true
395
396 function network.write(self, section, value)
397 local i = nw:get_interface(section)
398 if i then
399 if value == '-' then
400 value = m:formvalue(self:cbid(section) .. ".newnet")
401 if value and #value > 0 then
402 local n = nw:add_network(value, {proto="none"})
403 if n then n:add_interface(i) end
404 else
405 local n = i:get_network()
406 if n then n:del_interface(i) end
407 end
408 else
409 local v
410 for _, v in ipairs(i:get_networks()) do
411 v:del_interface(i)
412 end
413 for v in ut.imatch(value) do
414 local n = nw:get_network(v)
415 if n then
416 if not n:is_empty() then
417 n:set("type", "bridge")
418 end
419 n:add_interface(i)
420 end
421 end
422 end
423 end
424 end
425
426 -------------------- MAC80211 Interface ----------------------
427
428 if hwtype == "mac80211" then
429 if fs.access("/usr/sbin/iw") then
430 mode:value("mesh", "802.11s")
431 end
432
433 mode:value("ahdemo", translate("Pseudo Ad-Hoc (ahdemo)"))
434 mode:value("monitor", translate("Monitor"))
435 bssid:depends({mode="adhoc"})
436 bssid:depends({mode="sta"})
437 bssid:depends({mode="sta-wds"})
438
439 mp = s:taboption("macfilter", ListValue, "macfilter", translate("MAC-Address Filter"))
440 mp:depends({mode="ap"})
441 mp:depends({mode="ap-wds"})
442 mp:value("", translate("disable"))
443 mp:value("allow", translate("Allow listed only"))
444 mp:value("deny", translate("Allow all except listed"))
445
446 ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List"))
447 ml.datatype = "macaddr"
448 ml:depends({macfilter="allow"})
449 ml:depends({macfilter="deny"})
450 nt.mac_hints(function(mac, name) ml:value(mac, "%s (%s)" %{ mac, name }) end)
451
452 mode:value("ap-wds", "%s (%s)" % {translate("Access Point"), translate("WDS")})
453 mode:value("sta-wds", "%s (%s)" % {translate("Client"), translate("WDS")})
454
455 function mode.write(self, section, value)
456 if value == "ap-wds" then
457 ListValue.write(self, section, "ap")
458 m.uci:set("wireless", section, "wds", 1)
459 elseif value == "sta-wds" then
460 ListValue.write(self, section, "sta")
461 m.uci:set("wireless", section, "wds", 1)
462 else
463 ListValue.write(self, section, value)
464 m.uci:delete("wireless", section, "wds")
465 end
466 end
467
468 function mode.cfgvalue(self, section)
469 local mode = ListValue.cfgvalue(self, section)
470 local wds = m.uci:get("wireless", section, "wds") == "1"
471
472 if mode == "ap" and wds then
473 return "ap-wds"
474 elseif mode == "sta" and wds then
475 return "sta-wds"
476 else
477 return mode
478 end
479 end
480
481 hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
482 hidden:depends({mode="ap"})
483 hidden:depends({mode="ap-wds"})
484
485 wmm = s:taboption("general", Flag, "wmm", translate("WMM Mode"))
486 wmm:depends({mode="ap"})
487 wmm:depends({mode="ap-wds"})
488 wmm.default = wmm.enabled
489 end
490
491
492
493 -------------------- Madwifi Interface ----------------------
494
495 if hwtype == "atheros" then
496 mode:value("ahdemo", translate("Pseudo Ad-Hoc (ahdemo)"))
497 mode:value("monitor", translate("Monitor"))
498 mode:value("ap-wds", "%s (%s)" % {translate("Access Point"), translate("WDS")})
499 mode:value("sta-wds", "%s (%s)" % {translate("Client"), translate("WDS")})
500 mode:value("wds", translate("Static WDS"))
501
502 function mode.write(self, section, value)
503 if value == "ap-wds" then
504 ListValue.write(self, section, "ap")
505 m.uci:set("wireless", section, "wds", 1)
506 elseif value == "sta-wds" then
507 ListValue.write(self, section, "sta")
508 m.uci:set("wireless", section, "wds", 1)
509 else
510 ListValue.write(self, section, value)
511 m.uci:delete("wireless", section, "wds")
512 end
513 end
514
515 function mode.cfgvalue(self, section)
516 local mode = ListValue.cfgvalue(self, section)
517 local wds = m.uci:get("wireless", section, "wds") == "1"
518
519 if mode == "ap" and wds then
520 return "ap-wds"
521 elseif mode == "sta" and wds then
522 return "sta-wds"
523 else
524 return mode
525 end
526 end
527
528 bssid:depends({mode="adhoc"})
529 bssid:depends({mode="ahdemo"})
530 bssid:depends({mode="wds"})
531
532 wdssep = s:taboption("advanced", Flag, "wdssep", translate("Separate WDS"))
533 wdssep:depends({mode="ap-wds"})
534
535 s:taboption("advanced", Flag, "doth", "802.11h")
536 hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
537 hidden:depends({mode="ap"})
538 hidden:depends({mode="adhoc"})
539 hidden:depends({mode="ap-wds"})
540 hidden:depends({mode="sta-wds"})
541 isolate = s:taboption("advanced", Flag, "isolate", translate("Separate Clients"),
542 translate("Prevents client-to-client communication"))
543 isolate:depends({mode="ap"})
544 s:taboption("advanced", Flag, "bgscan", translate("Background Scan"))
545
546 mp = s:taboption("macfilter", ListValue, "macpolicy", translate("MAC-Address Filter"))
547 mp:value("", translate("disable"))
548 mp:value("allow", translate("Allow listed only"))
549 mp:value("deny", translate("Allow all except listed"))
550
551 ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List"))
552 ml.datatype = "macaddr"
553 ml:depends({macpolicy="allow"})
554 ml:depends({macpolicy="deny"})
555 nt.mac_hints(function(mac, name) ml:value(mac, "%s (%s)" %{ mac, name }) end)
556
557 s:taboption("advanced", Value, "rate", translate("Transmission Rate"))
558 s:taboption("advanced", Value, "mcast_rate", translate("Multicast Rate"))
559 s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
560 s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
561 s:taboption("advanced", Value, "minrate", translate("Minimum Rate"))
562 s:taboption("advanced", Value, "maxrate", translate("Maximum Rate"))
563 s:taboption("advanced", Flag, "compression", translate("Compression"))
564
565 s:taboption("advanced", Flag, "bursting", translate("Frame Bursting"))
566 s:taboption("advanced", Flag, "turbo", translate("Turbo Mode"))
567 s:taboption("advanced", Flag, "ff", translate("Fast Frames"))
568
569 s:taboption("advanced", Flag, "wmm", translate("WMM Mode"))
570 s:taboption("advanced", Flag, "xr", translate("XR Support"))
571 s:taboption("advanced", Flag, "ar", translate("AR Support"))
572
573 local swm = s:taboption("advanced", Flag, "sw_merge", translate("Disable HW-Beacon timer"))
574 swm:depends({mode="adhoc"})
575
576 local nos = s:taboption("advanced", Flag, "nosbeacon", translate("Disable HW-Beacon timer"))
577 nos:depends({mode="sta"})
578 nos:depends({mode="sta-wds"})
579
580 local probereq = s:taboption("advanced", Flag, "probereq", translate("Do not send probe responses"))
581 probereq.enabled = "0"
582 probereq.disabled = "1"
583 end
584
585
586 -------------------- Broadcom Interface ----------------------
587
588 if hwtype == "broadcom" then
589 mode:value("wds", translate("WDS"))
590 mode:value("monitor", translate("Monitor"))
591
592 hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
593 hidden:depends({mode="ap"})
594 hidden:depends({mode="adhoc"})
595 hidden:depends({mode="wds"})
596
597 isolate = s:taboption("advanced", Flag, "isolate", translate("Separate Clients"),
598 translate("Prevents client-to-client communication"))
599 isolate:depends({mode="ap"})
600
601 s:taboption("advanced", Flag, "doth", "802.11h")
602 s:taboption("advanced", Flag, "wmm", translate("WMM Mode"))
603
604 bssid:depends({mode="wds"})
605 bssid:depends({mode="adhoc"})
606 end
607
608
609 ----------------------- HostAP Interface ---------------------
610
611 if hwtype == "prism2" then
612 mode:value("wds", translate("WDS"))
613 mode:value("monitor", translate("Monitor"))
614
615 hidden = s:taboption("general", Flag, "hidden", translate("Hide <abbr title=\"Extended Service Set Identifier\">ESSID</abbr>"))
616 hidden:depends({mode="ap"})
617 hidden:depends({mode="adhoc"})
618 hidden:depends({mode="wds"})
619
620 bssid:depends({mode="sta"})
621
622 mp = s:taboption("macfilter", ListValue, "macpolicy", translate("MAC-Address Filter"))
623 mp:value("", translate("disable"))
624 mp:value("allow", translate("Allow listed only"))
625 mp:value("deny", translate("Allow all except listed"))
626 ml = s:taboption("macfilter", DynamicList, "maclist", translate("MAC-List"))
627 ml:depends({macpolicy="allow"})
628 ml:depends({macpolicy="deny"})
629 nt.mac_hints(function(mac, name) ml:value(mac, "%s (%s)" %{ mac, name }) end)
630
631 s:taboption("advanced", Value, "rate", translate("Transmission Rate"))
632 s:taboption("advanced", Value, "frag", translate("Fragmentation Threshold"))
633 s:taboption("advanced", Value, "rts", translate("RTS/CTS Threshold"))
634 end
635
636
637 ------------------- WiFI-Encryption -------------------
638
639 encr = s:taboption("encryption", ListValue, "encryption", translate("Encryption"))
640 encr.override_values = true
641 encr.override_depends = true
642 encr:depends({mode="ap"})
643 encr:depends({mode="sta"})
644 encr:depends({mode="adhoc"})
645 encr:depends({mode="ahdemo"})
646 encr:depends({mode="ap-wds"})
647 encr:depends({mode="sta-wds"})
648 encr:depends({mode="mesh"})
649
650 cipher = s:taboption("encryption", ListValue, "cipher", translate("Cipher"))
651 cipher:depends({encryption="wpa"})
652 cipher:depends({encryption="wpa2"})
653 cipher:depends({encryption="psk"})
654 cipher:depends({encryption="psk2"})
655 cipher:depends({encryption="wpa-mixed"})
656 cipher:depends({encryption="psk-mixed"})
657 cipher:value("auto", translate("auto"))
658 cipher:value("ccmp", translate("Force CCMP (AES)"))
659 cipher:value("tkip", translate("Force TKIP"))
660 cipher:value("tkip+ccmp", translate("Force TKIP and CCMP (AES)"))
661
662 function encr.cfgvalue(self, section)
663 local v = tostring(ListValue.cfgvalue(self, section))
664 if v == "wep" then
665 return "wep-open"
666 elseif v and v:match("%+") then
667 return (v:gsub("%+.+$", ""))
668 end
669 return v
670 end
671
672 function encr.write(self, section, value)
673 local e = tostring(encr:formvalue(section))
674 local c = tostring(cipher:formvalue(section))
675 if value == "wpa" or value == "wpa2" then
676 self.map.uci:delete("wireless", section, "key")
677 end
678 if e and (c == "tkip" or c == "ccmp" or c == "tkip+ccmp") then
679 e = e .. "+" .. c
680 end
681 self.map:set(section, "encryption", e)
682 end
683
684 function cipher.cfgvalue(self, section)
685 local v = tostring(ListValue.cfgvalue(encr, section))
686 if v and v:match("%+") then
687 v = v:gsub("^[^%+]+%+", "")
688 if v == "aes" then v = "ccmp"
689 elseif v == "tkip+aes" then v = "tkip+ccmp"
690 elseif v == "aes+tkip" then v = "tkip+ccmp"
691 elseif v == "ccmp+tkip" then v = "tkip+ccmp"
692 end
693 end
694 return v
695 end
696
697 function cipher.write(self, section)
698 return encr:write(section)
699 end
700
701
702 encr:value("none", "No Encryption")
703 encr:value("wep-open", translate("WEP Open System"), {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}, {mode="adhoc"}, {mode="ahdemo"}, {mode="wds"})
704 encr:value("wep-shared", translate("WEP Shared Key"), {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"}, {mode="adhoc"}, {mode="ahdemo"}, {mode="wds"})
705
706 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
707 local supplicant = fs.access("/usr/sbin/wpa_supplicant")
708 local hostapd = fs.access("/usr/sbin/hostapd")
709
710 -- Probe EAP support
711 local has_ap_eap = (os.execute("hostapd -veap >/dev/null 2>/dev/null") == 0)
712 local has_sta_eap = (os.execute("wpa_supplicant -veap >/dev/null 2>/dev/null") == 0)
713
714 if hostapd and supplicant then
715 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
716 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
717 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
718 if has_ap_eap and has_sta_eap then
719 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
720 encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="sta"}, {mode="ap-wds"}, {mode="sta-wds"})
721 end
722 elseif hostapd and not supplicant then
723 encr:value("psk", "WPA-PSK", {mode="ap"}, {mode="ap-wds"})
724 encr:value("psk2", "WPA2-PSK", {mode="ap"}, {mode="ap-wds"})
725 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="ap"}, {mode="ap-wds"})
726 if has_ap_eap then
727 encr:value("wpa", "WPA-EAP", {mode="ap"}, {mode="ap-wds"})
728 encr:value("wpa2", "WPA2-EAP", {mode="ap"}, {mode="ap-wds"})
729 end
730 encr.description = translate(
731 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
732 "and ad-hoc mode) to be installed."
733 )
734 elseif not hostapd and supplicant then
735 encr:value("psk", "WPA-PSK", {mode="sta"}, {mode="sta-wds"})
736 encr:value("psk2", "WPA2-PSK", {mode="sta"}, {mode="sta-wds"})
737 encr:value("psk-mixed", "WPA-PSK/WPA2-PSK Mixed Mode", {mode="sta"}, {mode="sta-wds"})
738 if has_sta_eap then
739 encr:value("wpa", "WPA-EAP", {mode="sta"}, {mode="sta-wds"})
740 encr:value("wpa2", "WPA2-EAP", {mode="sta"}, {mode="sta-wds"})
741 end
742 encr.description = translate(
743 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
744 "and ad-hoc mode) to be installed."
745 )
746 else
747 encr.description = translate(
748 "WPA-Encryption requires wpa_supplicant (for client mode) or hostapd (for AP " ..
749 "and ad-hoc mode) to be installed."
750 )
751 end
752 elseif hwtype == "broadcom" then
753 encr:value("psk", "WPA-PSK")
754 encr:value("psk2", "WPA2-PSK")
755 encr:value("psk+psk2", "WPA-PSK/WPA2-PSK Mixed Mode")
756 end
757
758 auth_server = s:taboption("encryption", Value, "auth_server", translate("Radius-Authentication-Server"))
759 auth_server:depends({mode="ap", encryption="wpa"})
760 auth_server:depends({mode="ap", encryption="wpa2"})
761 auth_server:depends({mode="ap-wds", encryption="wpa"})
762 auth_server:depends({mode="ap-wds", encryption="wpa2"})
763 auth_server.rmempty = true
764 auth_server.datatype = "host"
765
766 auth_port = s:taboption("encryption", Value, "auth_port", translate("Radius-Authentication-Port"), translatef("Default %d", 1812))
767 auth_port:depends({mode="ap", encryption="wpa"})
768 auth_port:depends({mode="ap", encryption="wpa2"})
769 auth_port:depends({mode="ap-wds", encryption="wpa"})
770 auth_port:depends({mode="ap-wds", encryption="wpa2"})
771 auth_port.rmempty = true
772 auth_port.datatype = "port"
773
774 auth_secret = s:taboption("encryption", Value, "auth_secret", translate("Radius-Authentication-Secret"))
775 auth_secret:depends({mode="ap", encryption="wpa"})
776 auth_secret:depends({mode="ap", encryption="wpa2"})
777 auth_secret:depends({mode="ap-wds", encryption="wpa"})
778 auth_secret:depends({mode="ap-wds", encryption="wpa2"})
779 auth_secret.rmempty = true
780 auth_secret.password = true
781
782 acct_server = s:taboption("encryption", Value, "acct_server", translate("Radius-Accounting-Server"))
783 acct_server:depends({mode="ap", encryption="wpa"})
784 acct_server:depends({mode="ap", encryption="wpa2"})
785 acct_server:depends({mode="ap-wds", encryption="wpa"})
786 acct_server:depends({mode="ap-wds", encryption="wpa2"})
787 acct_server.rmempty = true
788 acct_server.datatype = "host"
789
790 acct_port = s:taboption("encryption", Value, "acct_port", translate("Radius-Accounting-Port"), translatef("Default %d", 1813))
791 acct_port:depends({mode="ap", encryption="wpa"})
792 acct_port:depends({mode="ap", encryption="wpa2"})
793 acct_port:depends({mode="ap-wds", encryption="wpa"})
794 acct_port:depends({mode="ap-wds", encryption="wpa2"})
795 acct_port.rmempty = true
796 acct_port.datatype = "port"
797
798 acct_secret = s:taboption("encryption", Value, "acct_secret", translate("Radius-Accounting-Secret"))
799 acct_secret:depends({mode="ap", encryption="wpa"})
800 acct_secret:depends({mode="ap", encryption="wpa2"})
801 acct_secret:depends({mode="ap-wds", encryption="wpa"})
802 acct_secret:depends({mode="ap-wds", encryption="wpa2"})
803 acct_secret.rmempty = true
804 acct_secret.password = true
805
806 wpakey = s:taboption("encryption", Value, "_wpa_key", translate("Key"))
807 wpakey:depends("encryption", "psk")
808 wpakey:depends("encryption", "psk2")
809 wpakey:depends("encryption", "psk+psk2")
810 wpakey:depends("encryption", "psk-mixed")
811 wpakey.datatype = "wpakey"
812 wpakey.rmempty = true
813 wpakey.password = true
814
815 wpakey.cfgvalue = function(self, section, value)
816 local key = m.uci:get("wireless", section, "key")
817 if key == "1" or key == "2" or key == "3" or key == "4" then
818 return nil
819 end
820 return key
821 end
822
823 wpakey.write = function(self, section, value)
824 self.map.uci:set("wireless", section, "key", value)
825 self.map.uci:delete("wireless", section, "key1")
826 end
827
828
829 wepslot = s:taboption("encryption", ListValue, "_wep_key", translate("Used Key Slot"))
830 wepslot:depends("encryption", "wep-open")
831 wepslot:depends("encryption", "wep-shared")
832 wepslot:value("1", translatef("Key #%d", 1))
833 wepslot:value("2", translatef("Key #%d", 2))
834 wepslot:value("3", translatef("Key #%d", 3))
835 wepslot:value("4", translatef("Key #%d", 4))
836
837 wepslot.cfgvalue = function(self, section)
838 local slot = tonumber(m.uci:get("wireless", section, "key"))
839 if not slot or slot < 1 or slot > 4 then
840 return 1
841 end
842 return slot
843 end
844
845 wepslot.write = function(self, section, value)
846 self.map.uci:set("wireless", section, "key", value)
847 end
848
849 local slot
850 for slot=1,4 do
851 wepkey = s:taboption("encryption", Value, "key" .. slot, translatef("Key #%d", slot))
852 wepkey:depends("encryption", "wep-open")
853 wepkey:depends("encryption", "wep-shared")
854 wepkey.datatype = "wepkey"
855 wepkey.rmempty = true
856 wepkey.password = true
857
858 function wepkey.write(self, section, value)
859 if value and (#value == 5 or #value == 13) then
860 value = "s:" .. value
861 end
862 return Value.write(self, section, value)
863 end
864 end
865
866
867 if hwtype == "atheros" or hwtype == "mac80211" or hwtype == "prism2" then
868 nasid = s:taboption("encryption", Value, "nasid", translate("NAS ID"))
869 nasid:depends({mode="ap", encryption="wpa"})
870 nasid:depends({mode="ap", encryption="wpa2"})
871 nasid:depends({mode="ap-wds", encryption="wpa"})
872 nasid:depends({mode="ap-wds", encryption="wpa2"})
873 nasid.rmempty = true
874
875 eaptype = s:taboption("encryption", ListValue, "eap_type", translate("EAP-Method"))
876 eaptype:value("tls", "TLS")
877 eaptype:value("ttls", "TTLS")
878 eaptype:value("peap", "PEAP")
879 eaptype:depends({mode="sta", encryption="wpa"})
880 eaptype:depends({mode="sta", encryption="wpa2"})
881 eaptype:depends({mode="sta-wds", encryption="wpa"})
882 eaptype:depends({mode="sta-wds", encryption="wpa2"})
883
884 cacert = s:taboption("encryption", FileUpload, "ca_cert", translate("Path to CA-Certificate"))
885 cacert:depends({mode="sta", encryption="wpa"})
886 cacert:depends({mode="sta", encryption="wpa2"})
887 cacert:depends({mode="sta-wds", encryption="wpa"})
888 cacert:depends({mode="sta-wds", encryption="wpa2"})
889
890 clientcert = s:taboption("encryption", FileUpload, "client_cert", translate("Path to Client-Certificate"))
891 clientcert:depends({mode="sta", encryption="wpa"})
892 clientcert:depends({mode="sta", encryption="wpa2"})
893 clientcert:depends({mode="sta-wds", encryption="wpa"})
894 clientcert:depends({mode="sta-wds", encryption="wpa2"})
895
896 privkey = s:taboption("encryption", FileUpload, "priv_key", translate("Path to Private Key"))
897 privkey:depends({mode="sta", eap_type="tls", encryption="wpa2"})
898 privkey:depends({mode="sta", eap_type="tls", encryption="wpa"})
899 privkey:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
900 privkey:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
901
902 privkeypwd = s:taboption("encryption", Value, "priv_key_pwd", translate("Password of Private Key"))
903 privkeypwd:depends({mode="sta", eap_type="tls", encryption="wpa2"})
904 privkeypwd:depends({mode="sta", eap_type="tls", encryption="wpa"})
905 privkeypwd:depends({mode="sta-wds", eap_type="tls", encryption="wpa2"})
906 privkeypwd:depends({mode="sta-wds", eap_type="tls", encryption="wpa"})
907
908
909 auth = s:taboption("encryption", Value, "auth", translate("Authentication"))
910 auth:value("PAP")
911 auth:value("CHAP")
912 auth:value("MSCHAP")
913 auth:value("MSCHAPV2")
914 auth:depends({mode="sta", eap_type="peap", encryption="wpa2"})
915 auth:depends({mode="sta", eap_type="peap", encryption="wpa"})
916 auth:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
917 auth:depends({mode="sta", eap_type="ttls", encryption="wpa"})
918 auth:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
919 auth:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
920 auth:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
921 auth:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
922
923
924 identity = s:taboption("encryption", Value, "identity", translate("Identity"))
925 identity:depends({mode="sta", eap_type="peap", encryption="wpa2"})
926 identity:depends({mode="sta", eap_type="peap", encryption="wpa"})
927 identity:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
928 identity:depends({mode="sta", eap_type="ttls", encryption="wpa"})
929 identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
930 identity:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
931 identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
932 identity:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
933
934 password = s:taboption("encryption", Value, "password", translate("Password"))
935 password:depends({mode="sta", eap_type="peap", encryption="wpa2"})
936 password:depends({mode="sta", eap_type="peap", encryption="wpa"})
937 password:depends({mode="sta", eap_type="ttls", encryption="wpa2"})
938 password:depends({mode="sta", eap_type="ttls", encryption="wpa"})
939 password:depends({mode="sta-wds", eap_type="peap", encryption="wpa2"})
940 password:depends({mode="sta-wds", eap_type="peap", encryption="wpa"})
941 password:depends({mode="sta-wds", eap_type="ttls", encryption="wpa2"})
942 password:depends({mode="sta-wds", eap_type="ttls", encryption="wpa"})
943 end
944
945 return m