From 7477963b1fe9488727b4c04aa61dd030a2c548b4 Mon Sep 17 00:00:00 2001 From: Marek Kwaczynski Date: Fri, 20 Dec 2024 09:03:51 +0100 Subject: [PATCH] ucentral-event: add channel switch handler Add channel switch handler to update hapd object with new frequency and channel info. Fixes: WIFI-14336 Signed-off-by: Marek Kwaczynski --- .../ucentral-event/files/ucentral-event | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/feeds/ucentral/ucentral-event/files/ucentral-event b/feeds/ucentral/ucentral-event/files/ucentral-event index a39e5538f..cae6b4c2a 100755 --- a/feeds/ucentral/ucentral-event/files/ucentral-event +++ b/feeds/ucentral/ucentral-event/files/ucentral-event @@ -119,6 +119,40 @@ function event(object, verb, payload) { }); } +function freq2chan(freq) { + if (freq == 2484) + return 14; + else if (freq < 2484) + return (freq - 2407) / 5; + else if (freq >= 4910 && freq <= 4980) + return (freq - 4000) / 5; + else if(freq >= 56160 + 2160 * 1 && freq <= 56160 + 2160 * 6) + return (freq - 56160) / 2160; + else if (freq == 5935) + return (freq - 5925) / 5; + else if (freq > 5950 && freq <= 7115) + return (freq - 5950) / 5; + else if (freq >= 5000 && freq < 5900) + return (freq - 5000) / 5; + else + return -1; +} + +/* notify data expected format: + * { "ifname": "wlan1", "freq": 5180, "bssid": "XX:XX:XX:XX:XX:XX" + */ +function handle_channel_switch(hapd, notify) { + if (!notify && !notify?.data && !notify.data?.freq) + return; + + let ch = freq2chan(notify.data.freq); + if (ch < 0) + return; + + hapd.freq = notify.data.freq; + hapd.channel = ch; +} + let handlers; handlers = { 'sta-authorized': function(notify, hapd) { @@ -177,6 +211,10 @@ handlers = { } }, + 'channel-switch' : function(notify, hapd) { + handle_channel_switch(hapd, notify); + }, + disassoc: function(notify, hapd) { if (ratelimit) { let msg = {