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: 7bb5961779 ('supplicant: honor the 'wifi.channel-width' property in AP mode')
This commit is contained in:
Beniamino Galvani 2025-11-28 17:46:49 +01:00
parent a31a644f8b
commit ef84a54c43

View file

@ -521,6 +521,7 @@ get_ap_params(guint freq,
case NM_SETTING_WIRELESS_CHANNEL_WIDTH_80MHZ: case NM_SETTING_WIRELESS_CHANNEL_WIDTH_80MHZ:
{ {
guint channel; guint channel;
guint center_channel = 0;
if (freq < 5000) { if (freq < 5000) {
/* the setting is not valid */ /* the setting is not valid */
@ -530,12 +531,29 @@ get_ap_params(guint freq,
/* Determine the center channel according to the table at /* Determine the center channel according to the table at
* https://en.wikipedia.org/wiki/List_of_WLAN_channels */ * https://en.wikipedia.org/wiki/List_of_WLAN_channels */
channel = (freq - 5000) / 5;
channel = ((channel / 4 - 1) / 4) * 16 + 10;
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_ht40 = 1;
*out_max_oper_chwidth = 1; *out_max_oper_chwidth = 1;
*out_center_freq = 5000 + 5 * channel; *out_center_freq = 5000 + 5 * center_channel;
}
return; return;
} }