From ef84a54c434a00b1a96891a46bde7417f6e717e2 Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Fri, 28 Nov 2025 17:46:49 +0100 Subject: [PATCH] supplicant: fix center channel calculation The formula is wrong for channels above 144 because the layout of the 80MHz channels is not regular. Use a lookup table. Fixes: 7bb596177966 ('supplicant: honor the 'wifi.channel-width' property in AP mode') --- src/core/supplicant/nm-supplicant-config.c | 28 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/core/supplicant/nm-supplicant-config.c b/src/core/supplicant/nm-supplicant-config.c index fd360e7238..aad85dad6c 100644 --- a/src/core/supplicant/nm-supplicant-config.c +++ b/src/core/supplicant/nm-supplicant-config.c @@ -521,6 +521,7 @@ get_ap_params(guint freq, case NM_SETTING_WIRELESS_CHANNEL_WIDTH_80MHZ: { guint channel; + guint center_channel = 0; if (freq < 5000) { /* the setting is not valid */ @@ -530,12 +531,29 @@ get_ap_params(guint freq, /* Determine the center channel according to the table at * https://en.wikipedia.org/wiki/List_of_WLAN_channels */ - channel = (freq - 5000) / 5; - channel = ((channel / 4 - 1) / 4) * 16 + 10; - *out_ht40 = 1; - *out_max_oper_chwidth = 1; - *out_center_freq = 5000 + 5 * channel; + channel = (freq - 5000) / 5; + + if (channel >= 36 && channel <= 48) + center_channel = 42; + else if (channel >= 52 && channel <= 64) + center_channel = 58; + else if (channel >= 100 && channel <= 112) + center_channel = 106; + else if (channel >= 116 && channel <= 128) + center_channel = 122; + else if (channel >= 132 && channel <= 144) + center_channel = 138; + else if (channel >= 149 && channel <= 161) + center_channel = 155; + else if (channel >= 165 && channel <= 177) + center_channel = 171; + + if (center_channel) { + *out_ht40 = 1; + *out_max_oper_chwidth = 1; + *out_center_freq = 5000 + 5 * center_channel; + } return; }