| From 3e2fa0f4ab02538c66e61058749272565d94d111 Mon Sep 17 00:00:00 2001 |
| From: Nicolas Escande <nico.escande@gmail.com> |
| Date: Wed, 27 Apr 2022 15:37:00 +0200 |
| Subject: [PATCH 02/50] ACS: Introduce acs_get_bw_center_chan() |
| |
| When using 40/80/160 MHz bandwidth, instead of computing the index of |
| the segment center freq based on the selected channel, lets look it up |
| in the bw_desc[] table. |
| |
| This is preparative work to allow selecting a primary channel which is |
| not the first of the segment. |
| |
| Signed-off-by: Nicolas Escande <nico.escande@gmail.com> |
| --- |
| src/ap/acs.c | 33 +++++++++++++++++++++++++++------ |
| 1 file changed, 27 insertions(+), 6 deletions(-) |
| |
| diff --git a/src/ap/acs.c b/src/ap/acs.c |
| index 60c90e9..511200d 100644 |
| --- a/src/ap/acs.c |
| +++ b/src/ap/acs.c |
| @@ -436,6 +436,21 @@ static bool acs_usable_bw_chan(const struct hostapd_channel_data *chan, |
| } |
| |
| |
| +static int acs_get_bw_center_chan(int freq, enum bw_type bw) |
| +{ |
| + unsigned int i = 0; |
| + |
| + while (bw_desc[bw][i].first != -1) { |
| + if (freq >= bw_desc[bw][i].first && |
| + freq <= bw_desc[bw][i].last) |
| + return bw_desc[bw][i].center_chan; |
| + i++; |
| + } |
| + |
| + return 0; |
| +} |
| + |
| + |
| static int acs_survey_is_sufficient(struct freq_survey *survey) |
| { |
| if (!(survey->filled & SURVEY_HAS_NF)) { |
| @@ -936,19 +951,26 @@ bw_selected: |
| |
| static void acs_adjust_center_freq(struct hostapd_iface *iface) |
| { |
| - int offset; |
| + int center; |
| |
| wpa_printf(MSG_DEBUG, "ACS: Adjusting VHT center frequency"); |
| |
| switch (hostapd_get_oper_chwidth(iface->conf)) { |
| case CONF_OPER_CHWIDTH_USE_HT: |
| - offset = 2 * iface->conf->secondary_channel; |
| + if (iface->conf->secondary_channel && |
| + iface->freq >= 2400 && iface->freq < 2500) |
| + center = iface->conf->channel + |
| + 2 * iface->conf->secondary_channel; |
| + else if (iface->conf->secondary_channel) |
| + center = acs_get_bw_center_chan(iface->freq, ACS_BW40); |
| + else |
| + center = iface->conf->channel; |
| break; |
| case CONF_OPER_CHWIDTH_80MHZ: |
| - offset = 6; |
| + center = acs_get_bw_center_chan(iface->freq, ACS_BW80); |
| break; |
| case CONF_OPER_CHWIDTH_160MHZ: |
| - offset = 14; |
| + center = acs_get_bw_center_chan(iface->freq, ACS_BW160); |
| break; |
| default: |
| /* TODO: How can this be calculated? Adjust |
| @@ -958,8 +980,7 @@ static void acs_adjust_center_freq(struct hostapd_iface *iface) |
| return; |
| } |
| |
| - hostapd_set_oper_centr_freq_seg0_idx(iface->conf, |
| - iface->conf->channel + offset); |
| + hostapd_set_oper_centr_freq_seg0_idx(iface->conf, center); |
| } |
| |
| |
| -- |
| 2.18.0 |
| |