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