diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2014-10-26 17:44:50 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2014-10-26 17:46:05 +0100 |
commit | 89f270466c8ecaf38a36174883abb1f11bcbadf6 (patch) | |
tree | d67dd4d238c4193eb6c2fb704c258d42f0ea3b69 /modules | |
parent | 636fb470e796e325fa1d9f404d7e8077288635e9 (diff) |
modules/admin-full: rework hwmode/htmode/channel selection
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua | 101 | ||||
-rw-r--r-- | modules/admin-full/luasrc/view/cbi/wireless_modefreq.htm | 167 |
2 files changed, 192 insertions, 76 deletions
diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua b/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua index 7d84d2961..f61fda373 100644 --- a/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua +++ b/modules/admin-full/luasrc/model/cbi/admin_network/wifi.lua @@ -169,12 +169,31 @@ if found_sta then ch.value = translatef("Locked to channel %d used by: %s", found_sta.channel, table.concat(found_sta.names, ", ")) else - ch = s:taboption("general", Value, "channel", translate("Channel")) - ch:value("auto", translate("auto")) - for _, f in ipairs(iw and iw.freqlist or { }) do - if not f.restricted then - ch:value(f.channel, "%i (%.3f GHz)" %{ f.channel, f.mhz / 1000 }) - end + ch = s:taboption("general", Value, "_mode_freq", '<br />'..translate("Operating frequency")) + ch.hwmodes = iw.hwmodelist + ch.freqlist = iw.freqlist + ch.template = "cbi/wireless_modefreq" + + function ch.cfgvalue(self, section) + return { + m:get(section, "hwmode") or "", + m:get(section, "channel") or "auto", + m:get(section, "htmode") or "" + } + end + + function ch.formvalue(self, section) + return { + m:formvalue(self:cbid(section) .. ".band") or (iw.hwmodelist.g and "11g" or "11a"), + m:formvalue(self:cbid(section) .. ".channel") or "auto", + m:formvalue(self:cbid(section) .. ".htmode") or "" + } + end + + function ch.write(self, section, value) + m:set(section, "hwmode", value[1]) + m:set(section, "channel", value[2]) + m:set(section, "htmode", value[3]) end end @@ -196,45 +215,6 @@ if hwtype == "mac80211" then end end - mode = s:taboption("advanced", ListValue, "hwmode", translate("Band")) - - if hw_modes.ac then - if hw_modes.ac then mode:value("11a", "5GHz (802.11n+ac)") end - - htmode = s:taboption("advanced", ListValue, "htmode", translate("VHT mode (802.11ac)")) - htmode:value("", translate("disabled")) - htmode:value("VHT20", "20MHz") - htmode:value("VHT40", "40MHz") - htmode:value("VHT80", "80MHz") - - elseif hw_modes.n then - if hw_modes.g then mode:value("11g", "2.4GHz (802.11g+n)") end - if hw_modes.a then mode:value("11a", "5GHz (802.11a+n)") end - - htmode = s:taboption("advanced", ListValue, "htmode", translate("HT mode (802.11n)")) - htmode:value("", translate("disabled")) - htmode:value("HT20", "20MHz") - htmode:value("HT40", "40MHz") - - function mode.cfgvalue(...) - local v = Value.cfgvalue(...) - if v == "11na" then - return "11a" - elseif v == "11ng" then - return "11g" - end - return v - end - - noscan = s:taboption("advanced", Flag, "noscan", translate("Force 40MHz mode"), - translate("Always use 40MHz channels even if the secondary channel overlaps. Using this option does not comply with IEEE 802.11n-2009!")) - noscan:depends("htmode", "HT40") - noscan.default = noscan.disabled - else - if hw_modes.g then mode:value("11g", "2.4GHz (802.11g)") end - if hw_modes.a then mode:value("11a", "5GHz (802.11a)") end - end - local cl = iw and iw.countrylist if cl and #cl > 0 then cc = s:taboption("advanced", ListValue, "country", translate("Country Code"), translate("Use ISO/IEC 3166 alpha2 country codes.")) @@ -285,16 +265,6 @@ if hwtype == "atheros" then %{ p.display_dbm, p.display_mw }) end - mode = s:taboption("advanced", ListValue, "hwmode", translate("Mode")) - mode:value("", translate("auto")) - if hw_modes.b then mode:value("11b", "802.11b") end - if hw_modes.g then mode:value("11g", "802.11g") end - if hw_modes.a then mode:value("11a", "802.11a") end - if hw_modes.g then mode:value("11bg", "802.11b+g") end - if hw_modes.g then mode:value("11gst", "802.11g + Turbo") end - if hw_modes.a then mode:value("11ast", "802.11a + Turbo") end - mode:value("fh", translate("Frequency Hopping")) - s:taboption("advanced", Flag, "diversity", translate("Diversity")).rmempty = false if not nsantenna then @@ -352,27 +322,6 @@ if hwtype == "broadcom" then %{ p.display_dbm, p.display_mw }) end - mode = s:taboption("advanced", ListValue, "hwmode", translate("Mode")) - if hw_modes.n then - if hw_modes.g then mode:value("11ng", "802.11g+n") end - if hw_modes.a then mode:value("11na", "802.11a+n") end - mode:value("11n", "802.11n") - - htmode = s:taboption("advanced", ListValue, "htmode", translate("HT mode (802.11n)")) - htmode:depends("hwmode", "11n") - htmode:depends("hwmode", "11ng") - htmode:depends("hwmode", "11na") - htmode:value("HT20", "20MHz") - htmode:value("HT40-", translate("40MHz 2nd channel below")) - htmode:value("HT40+", translate("40MHz 2nd channel above")) - end - if hw_modes.a then mode:value("11a", "802.11a") end - if hw_modes.b and hw_modes.g then mode:value("11bg", "802.11b+g") end - if hw_modes.b then mode:value("11b", "802.11b") end - if hw_modes.g then mode:value("11g", "802.11g") end - if hw_modes.g then mode:value("11gst", "802.11g Turbo") end - if hw_modes.g then mode:value("11lrs", "802.11g Limited Rate Support") end - ant1 = s:taboption("advanced", ListValue, "txantenna", translate("Transmitter Antenna")) ant1.widget = "radio" ant1:depends("diversity", "") diff --git a/modules/admin-full/luasrc/view/cbi/wireless_modefreq.htm b/modules/admin-full/luasrc/view/cbi/wireless_modefreq.htm new file mode 100644 index 000000000..39db482dd --- /dev/null +++ b/modules/admin-full/luasrc/view/cbi/wireless_modefreq.htm @@ -0,0 +1,167 @@ +<%+cbi/valueheader%> + +<script type="text/javascript"> + var freqlist = <%= luci.http.write_json(self.freqlist) %>; + var hwmodes = <%= luci.http.write_json(self.hwmodes) %>; + + var channels = { + '11g': [ + 'auto', 'auto', true + ], + '11a': [ + 'auto', 'auto', true + ] + }; + + for (var i = 0; i < freqlist.length; i++) + channels[(freqlist[i].mhz > 2484) ? '11a' : '11g'].push( + freqlist[i].channel, + '%d (%d MHz)'.format(freqlist[i].channel, freqlist[i].mhz), + !freqlist[i].restricted + ); + + var modes = [ + '', 'Legacy', true, + 'n', 'N', hwmodes.n, + 'ac', 'AC', hwmodes.ac + ]; + + var htmodes = { + '': [ + '', '-', true + ], + 'n': [ + 'HT20', '20 MHz', true, + 'HT40', '40 MHz', true + ], + 'ac': [ + 'VHT20', '20 MHz', true, + 'VHT40', '40 MHz', true, + 'VHT80', '80 MHz', true, + 'VHT160', '160 MHz', true + ] + }; + + var bands = { + '': [ + '11g', '2.4 GHz', (channels['11g'].length > 3), + '11a', '5 GHz', (channels['11a'].length > 3) + ], + 'n': [ + '11g', '2.4 GHz', (channels['11g'].length > 3), + '11a', '5 GHz', (channels['11a'].length > 3) + ], + 'ac': [ + '11a', '5 GHz', true + ] + }; + + function cbi_set_values(sel, vals) + { + if (sel.vals) + sel.vals.selected = sel.selectedIndex; + + while (sel.options[0]) + sel.remove(0); + + for (var i = 0; vals && i < vals.length; i += 3) + { + if (!vals[i+2]) + continue; + + var opt = document.createElement('option'); + opt.value = vals[i+0]; + opt.text = vals[i+1]; + + sel.add(opt); + } + + if (!isNaN(vals.selected)) + sel.selectedIndex = vals.selected; + + sel.parentNode.style.display = (sel.options.length <= 1) ? 'none' : ''; + sel.vals = vals; + } + + function cbi_toggle_wifi_mode(id) + { + cbi_toggle_wifi_htmode(id); + cbi_toggle_wifi_band(id); + } + + function cbi_toggle_wifi_htmode(id) + { + var mode = document.getElementById(id + '.mode'); + var bwdt = document.getElementById(id + '.htmode'); + + cbi_set_values(bwdt, htmodes[mode.value]); + } + + function cbi_toggle_wifi_band(id) + { + var mode = document.getElementById(id + '.mode'); + var band = document.getElementById(id + '.band'); + + cbi_set_values(band, bands[mode.value]); + cbi_toggle_wifi_channel(id); + } + + function cbi_toggle_wifi_channel(id) + { + var band = document.getElementById(id + '.band'); + var chan = document.getElementById(id + '.channel'); + + cbi_set_values(chan, channels[band.value]); + } + + function cbi_init_wifi(id) + { + var mode = document.getElementById(id + '.mode'); + var band = document.getElementById(id + '.band'); + var chan = document.getElementById(id + '.channel'); + var bwdt = document.getElementById(id + '.htmode'); + + cbi_set_values(mode, modes); + + if (/VHT20|VHT40|VHT80|VHT160/.test(<%= luci.http.write_json(self.map:get(section, "htmode")) %>)) + mode.value = 'ac'; + else if (/HT20|HT40/.test(<%= luci.http.write_json(self.map:get(section, "htmode")) %>)) + mode.value = 'n'; + else + mode.value = ''; + + cbi_toggle_wifi_mode(id); + + if (/a/.test(<%= luci.http.write_json(self.map:get(section, "hwmode")) %>)) + band.value = '11a'; + else + band.value = '11g'; + + cbi_toggle_wifi_band(id); + + bwdt.value = <%= luci.http.write_json(self.map:get(section, "htmode")) %>; + chan.value = <%= luci.http.write_json(self.map:get(section, "channel")) %>; + } +</script> + +<label style="float:left; margin-right:3px"> + <%:Mode%><br /> + <select style="width:auto" id="<%= cbid %>.mode" name="<%= cbid %>.mode" onchange="cbi_toggle_wifi_mode('<%= cbid %>')"></select> +</label> +<label style="float:left; margin-right:3px"> + <%:Band%><br /> + <select style="width:auto" id="<%= cbid %>.band" name="<%= cbid %>.band" onchange="cbi_toggle_wifi_band('<%= cbid %>')"></select> +</label> +<label style="float:left; margin-right:3px"> + <%:Channel%><br /> + <select style="width:auto" id="<%= cbid %>.channel" name="<%= cbid %>.channel"></select> +</label> +<label style="float:left; margin-right:3px"> + <%:Width%><br /> + <select style="width:auto" id="<%= cbid %>.htmode" name="<%= cbid %>.htmode"></select> +</label> +<br style="clear:left" /> + +<script type="text/javascript">cbi_init_wifi('<%= cbid %>');</script> + +<%+cbi/valuefooter%> |