openwisp/openwrt-openwisp-monitoring

[bug/change] Do not add wireless interface information if channel is not available

nemesifier opened this issue · 0 comments

This is an issue I have been observing for a few months.
If a device has some misconfigured wifi interfaces or radios, even though the WiFI interface is not completely brought up and hence not working, the system will report its presence with some important information like channel omitted, eg:

wlan1     ESSID: unknown
          Access Point: 46:D1:FA:D2:29:7C
          Mode: Client  Channel: unknown (unknown)
          Center Channel 1: unknown 2: unknown
          Tx-Power: 20 dBm  Link Quality: unknown/70
          Signal: unknown  Noise: -92 dBm
          Bit Rate: unknown
          Encryption: unknown
          Type: nl80211  HW Mode(s): 802.11nacax
          Hardware: 14C3:7915 14C3:7915 [MediaTek MT7915E]
          TX power offset: none
          Frequency offset: none
          Supports VAPs: yes  PHY name: phy1

The result is a JSON payload which will be rejected by OpenWISP Monitoring.

For this reason, I think we should change this block of code as follows:

wireless = {
ssid = iwinfo.ssid,
mode = monitoring.wifi.iwinfo_modes[iwinfo.mode] or iwinfo.mode,
channel = iwinfo.channel,
frequency = iwinfo.frequency,
tx_power = iwinfo.txpower,
signal = iwinfo.signal,
noise = iwinfo.noise,
country = iwinfo.country
}
}
if iwinfo.mode == 'Ad-Hoc' or iwinfo.mode == 'Mesh Point' then
clients = ubus:call('iwinfo', 'assoclist', {device = name}).results
is_mesh = true
else
local hostapd_output = ubus:call('hostapd.' .. name, 'get_clients', {})
if hostapd_output then clients = hostapd_output.clients end
end
if not monitoring.utils.is_table_empty(clients) then
netjson_interface.wireless.clients =
monitoring.wifi.netjson_clients(clients, is_mesh)
end

We should check whether the channel information is present (iwinfo.channel is nil) and if it's not present we should not add the wireless key to the netjson_interface dictionary (lua table) nor look for wifi clients.

I think the whole block shown above could be moved to a separate utility function which is called only after we check that iwinfo.channel is not nil.

We will need to add a test for this in test_wifi.lua.