From aa61f7e07dac9f23418453d50e78d9f1f3e2f25f Mon Sep 17 00:00:00 2001
From: Janusz Dziedzic <janusz.dziedzic@iopsys.eu>
Date: Wed, 23 Apr 2025 17:40:24 +0200
Subject: [PATCH] fix chan_switch when real mld netdev

---
 wifimngr.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/wifimngr.c b/wifimngr.c
index 64c33a3..9643d75 100644
--- a/wifimngr.c
+++ b/wifimngr.c
@@ -2107,6 +2107,8 @@ int ap_chan_switch(struct ubus_context *ctx, struct ubus_object *obj,
 			  struct ubus_request_data *req, const char *method,
 			  struct blob_attr *msg)
 {
+	struct wifi_ubus_object *wo = container_of(obj, struct wifi_ubus_object, obj);
+	struct wifimngr_iface *iface = (struct wifimngr_iface *)wo->priv;
 	struct blob_attr *tb[__CHAN_SWITCH_MAX];
 	struct chan_switch_param param = {
 				.count = 5,	/* after these many beacons */
@@ -2118,7 +2120,10 @@ int ap_chan_switch(struct ubus_context *ctx, struct ubus_object *obj,
 	blobmsg_parse(chan_switch_policy, __CHAN_SWITCH_MAX, tb, blob_data(msg),
 		      blob_len(msg));
 
-	ifname = ubus_ap_to_ifname(obj);
+	if (strlen(iface->mld_netdev) && if_nametoindex(iface->mld_netdev) != 0)
+		ifname = iface->mld_netdev;
+	else
+		ifname = ubus_ap_to_ifname(obj);
 
 	if (!tb[CHAN_SWITCH_FREQ] && !tb[CHAN_SWITCH_CHANNEL])
 		return UBUS_STATUS_INVALID_ARGUMENT;
@@ -2126,14 +2131,9 @@ int ap_chan_switch(struct ubus_context *ctx, struct ubus_object *obj,
 	if (tb[CHAN_SWITCH_FREQ]) {
 		param.freq = blobmsg_get_u32(tb[CHAN_SWITCH_FREQ]);
 	} else {
-		enum wifi_band band = BAND_5;
 		uint32_t channel = blobmsg_get_u32(tb[CHAN_SWITCH_CHANNEL]);
 
-		ret = wifi_get_oper_band(ifname, &band);
-		if (ret)
-			return UBUS_STATUS_UNKNOWN_ERROR;
-
-		param.freq = wifi_channel_to_freq_ex(channel, band);
+		param.freq = wifi_channel_to_freq_ex(channel, iface->band);
 		if (param.freq < 0)
 			return UBUS_STATUS_INVALID_ARGUMENT;
 	}
-- 
GitLab