From 0829d31290e7c902743fbd86ea91b06ee90c6e42 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Wed, 9 Jun 2021 09:59:15 +0200 Subject: luci-mod-network: support newer wireless.wifi-device.band option OpenWrt switched from "option hwmode" to "option band" in order to select the frequency band to use for the radio phy. Extend the channel selector to recognize and use an existing "option band" to select the appropriate channel list. When operating upon a wireless configuration still using "option hwmode", then translate it to a band value internally and translate it back to "option hwmode" on save. This should provide forward- and backwards compatibility with both current OpenWrt master and older versions still using hwmode. Fixes: #5106 Signed-off-by: Jo-Philipp Wich --- .../luci-static/resources/view/network/wireless.js | 69 ++++++++++++++++------ 1 file changed, 50 insertions(+), 19 deletions(-) diff --git a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/wireless.js b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/wireless.js index d5ec680780..8f3f7a24ed 100644 --- a/modules/luci-mod-network/htdocs/luci-static/resources/view/network/wireless.js +++ b/modules/luci-mod-network/htdocs/luci-static/resources/view/network/wireless.js @@ -312,16 +312,32 @@ var CBIWifiFrequencyValue = form.Value.extend({ this.callFrequencyList(section_id) ]).then(L.bind(function(data) { this.channels = { - '11g': L.hasSystemFeature('hostapd', 'acs') ? [ 'auto', 'auto', true ] : [], - '11a': L.hasSystemFeature('hostapd', 'acs') ? [ 'auto', 'auto', true ] : [] + '2g': L.hasSystemFeature('hostapd', 'acs') ? [ 'auto', 'auto', true ] : [], + '5g': L.hasSystemFeature('hostapd', 'acs') ? [ 'auto', 'auto', true ] : [], + '6g': [], + '60g': [] }; - for (var i = 0; i < data[1].length; i++) - this.channels[(data[1][i].mhz > 2484) ? '11a' : '11g'].push( + for (var i = 0; i < data[1].length; i++) { + var band; + + if (data[1][i].mhz >= 2412 && data[1][i].mhz <= 2484) + band = '2g'; + else if (data[1][i].mhz >= 5160 && data[1][i].mhz <= 5885) + band = '5g'; + else if (data[1][i].mhz >= 5925 && data[1][i].mhz <= 7125) + band = '6g'; + else if (data[1][i].mhz >= 58329 && data[1][i].mhz <= 69120) + band = '60g'; + else + continue; + + this.channels[band].push( data[1][i].channel, '%d (%d Mhz)'.format(data[1][i].channel, data[1][i].mhz), !data[1][i].restricted ); + } var hwmodelist = L.toArray(data[0] ? data[0].getHWModes() : null) .reduce(function(o, v) { o[v] = true; return o }, {}); @@ -358,19 +374,19 @@ var CBIWifiFrequencyValue = form.Value.extend({ this.bands = { '': [ - '11g', '2.4 GHz', this.channels['11g'].length > 3, - '11a', '5 GHz', this.channels['11a'].length > 3 + '2g', '2.4 GHz', this.channels['2g'].length > 3, + '5g', '5 GHz', this.channels['5g'].length > 3 ], 'n': [ - '11g', '2.4 GHz', this.channels['11g'].length > 3, - '11a', '5 GHz', this.channels['11a'].length > 3 + '2g', '2.4 GHz', this.channels['2g'].length > 3, + '5g', '5 GHz', this.channels['5g'].length > 3 ], 'ac': [ - '11a', '5 GHz', true + '5g', '5 GHz', true ], 'ax': [ - '11g', '2.4 GHz', this.channels['11g'].length > 3, - '11a', '5 GHz', this.channels['11a'].length > 3 + '2g', '2.4 GHz', this.channels['2g'].length > 3, + '5g', '5 GHz', this.channels['5g'].length > 3 ] }; }, this)); @@ -430,7 +446,8 @@ var CBIWifiFrequencyValue = form.Value.extend({ bwdt = elem.querySelector('.htmode'), htval = uci.get('wireless', section_id, 'htmode'), hwval = uci.get('wireless', section_id, 'hwmode'), - chval = uci.get('wireless', section_id, 'channel'); + chval = uci.get('wireless', section_id, 'channel'), + bandval = uci.get('wireless', section_id, 'band'); this.setValues(mode, this.modes); @@ -443,15 +460,24 @@ var CBIWifiFrequencyValue = form.Value.extend({ this.toggleWifiMode(elem); - if (/a/.test(hwval)) - band.value = '11a'; - else - band.value = '11g'; + if (hwval != null) { + this.useBandOption = false; + + if (/a/.test(hwval)) + band.value = '5g'; + else + band.value = '2g'; + } + else { + this.useBandOption = true; + + band.value = bandval; + } this.toggleWifiBand(elem); bwdt.value = htval; - chan.value = chval; + chan.value = chval || chan.options[0].value; return elem; }, @@ -505,7 +531,7 @@ var CBIWifiFrequencyValue = form.Value.extend({ cfgvalue: function(section_id) { return [ uci.get('wireless', section_id, 'htmode'), - uci.get('wireless', section_id, 'hwmode'), + uci.get('wireless', section_id, 'hwmode') || uci.get('wireless', section_id, 'band'), uci.get('wireless', section_id, 'channel') ]; }, @@ -522,7 +548,12 @@ var CBIWifiFrequencyValue = form.Value.extend({ write: function(section_id, value) { uci.set('wireless', section_id, 'htmode', value[0] || null); - uci.set('wireless', section_id, 'hwmode', value[1]); + + if (this.useBandOption) + uci.set('wireless', section_id, 'band', value[1]); + else + uci.set('wireless', section_id, 'hwmode', (value[1] == '2g') ? '11g' : '11a'); + uci.set('wireless', section_id, 'channel', value[2]); } }); -- cgit v1.2.3