diff --git a/src/ap/acs.c b/src/ap/acs.c index f12539fcd..232afa890 100644 --- a/src/ap/acs.c +++ b/src/ap/acs.c @@ -862,6 +862,7 @@ static void acs_study(struct hostapd_iface *iface) } iface->conf->channel = ideal_chan->chan; + iface->freq = ideal_chan->freq; if (iface->conf->ieee80211ac || iface->conf->ieee80211ax) acs_adjust_center_freq(iface); diff --git a/src/ap/hostapd.c b/src/ap/hostapd.c index 368643867..b428bb163 100644 --- a/src/ap/hostapd.c +++ b/src/ap/hostapd.c @@ -1572,6 +1572,51 @@ static int setup_interface(struct hostapd_iface *iface) } +static int configured_fixed_chan_to_freq(struct hostapd_iface *iface) +{ + int freq, i, j; + + if (!iface->conf->channel) + return 0; + if (iface->conf->op_class) { + freq = ieee80211_chan_to_freq(NULL, iface->conf->op_class, + iface->conf->channel); + if (freq < 0) { + wpa_printf(MSG_INFO, + "Could not convert op_class %u channel %u to operating frequency", + iface->conf->op_class, iface->conf->channel); + return -1; + } + iface->freq = freq; + return 0; + } + + /* Old configurations using only 2.4/5/60 GHz bands may not specify the + * op_class parameter. Select a matching channel from the configured + * mode using the channel parameter for these cases. + */ + for (j = 0; j < iface->num_hw_features; j++) { + struct hostapd_hw_modes *mode = &iface->hw_features[j]; + + if (iface->conf->hw_mode != HOSTAPD_MODE_IEEE80211ANY && + iface->conf->hw_mode != mode->mode) + continue; + for (i = 0; i < mode->num_channels; i++) { + struct hostapd_channel_data *chan = &mode->channels[i]; + + if (chan->chan == iface->conf->channel && + !is_6ghz_freq(chan->freq)) { + iface->freq = chan->freq; + return 0; + } + } + } + + wpa_printf(MSG_INFO, "Could not determine operating frequency"); + return -1; +} + + static int setup_interface2(struct hostapd_iface *iface) { iface->wait_channel_update = 0; @@ -1580,7 +1625,13 @@ static int setup_interface2(struct hostapd_iface *iface) /* Not all drivers support this yet, so continue without hw * feature data. */ } else { - int ret = hostapd_select_hw_mode(iface); + int ret; + + ret = configured_fixed_chan_to_freq(iface); + if (ret < 0) + goto fail; + + ret = hostapd_select_hw_mode(iface); if (ret < 0) { wpa_printf(MSG_ERROR, "Could not select hw_mode and " "channel. (%d)", ret); @@ -1869,7 +1920,6 @@ static int hostapd_setup_interface_complete_sync(struct hostapd_iface *iface, int res; #endif /* NEED_AP_MLME */ - iface->freq = hostapd_hw_get_freq(hapd, iface->conf->channel); wpa_printf(MSG_DEBUG, "Mode: %s Channel: %d " "Frequency: %d MHz", hostapd_hw_mode_txt(iface->conf->hw_mode), diff --git a/src/ap/hw_features.c b/src/ap/hw_features.c index d8accc51a..a8bec4fcd 100644 --- a/src/ap/hw_features.c +++ b/src/ap/hw_features.c @@ -922,9 +922,7 @@ int hostapd_acs_completed(struct hostapd_iface *iface, int err) case HOSTAPD_CHAN_VALID: wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_COMPLETED "freq=%d channel=%d", - hostapd_hw_get_freq(iface->bss[0], - iface->conf->channel), - iface->conf->channel); + iface->freq, iface->conf->channel); break; case HOSTAPD_CHAN_ACS: wpa_printf(MSG_ERROR, "ACS error - reported complete, but no result available"); @@ -964,7 +962,6 @@ out: int hostapd_select_hw_mode(struct hostapd_iface *iface) { int i; - int freq = -1; if (iface->num_hw_features < 1) return -1; @@ -981,15 +978,13 @@ int hostapd_select_hw_mode(struct hostapd_iface *iface) } iface->current_mode = NULL; - if (iface->conf->channel && iface->conf->op_class) - freq = ieee80211_chan_to_freq(NULL, iface->conf->op_class, - iface->conf->channel); for (i = 0; i < iface->num_hw_features; i++) { struct hostapd_hw_modes *mode = &iface->hw_features[i]; if (mode->mode == iface->conf->hw_mode) { - if (freq > 0 && !hw_get_chan(mode->mode, freq, - iface->hw_features, - iface->num_hw_features)) + if (iface->freq > 0 && + !hw_get_chan(mode->mode, iface->freq, + iface->hw_features, + iface->num_hw_features)) continue; iface->current_mode = mode; break;