diff --git a/src/ap/hw_features.c b/src/ap/hw_features.c index 8b1ed7083..d8accc51a 100644 --- a/src/ap/hw_features.c +++ b/src/ap/hw_features.c @@ -987,7 +987,9 @@ int hostapd_select_hw_mode(struct hostapd_iface *iface) 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, freq)) + if (freq > 0 && !hw_get_chan(mode->mode, freq, + iface->hw_features, + iface->num_hw_features)) continue; iface->current_mode = mode; break; @@ -1051,7 +1053,9 @@ int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq) struct hostapd_hw_modes *mode; if (hapd->iface->current_mode) { - channel = hw_get_chan(hapd->iface->current_mode, freq); + channel = hw_get_chan(hapd->iface->current_mode->mode, freq, + hapd->iface->hw_features, + hapd->iface->num_hw_features); if (channel) return channel; } @@ -1062,7 +1066,9 @@ int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq) return 0; for (i = 0; i < hapd->iface->num_hw_features; i++) { mode = &hapd->iface->hw_features[i]; - channel = hw_get_chan(mode, freq); + channel = hw_get_chan(mode->mode, freq, + hapd->iface->hw_features, + hapd->iface->num_hw_features); if (channel) return channel; } diff --git a/src/common/hw_features_common.c b/src/common/hw_features_common.c index 1ad8d7c3e..706f20415 100644 --- a/src/common/hw_features_common.c +++ b/src/common/hw_features_common.c @@ -40,23 +40,32 @@ struct hostapd_channel_data * hw_get_channel_chan(struct hostapd_hw_modes *mode, } -struct hostapd_channel_data * hw_get_channel_freq(struct hostapd_hw_modes *mode, - int freq, int *chan) +struct hostapd_channel_data * +hw_get_channel_freq(enum hostapd_hw_mode mode, int freq, int *chan, + struct hostapd_hw_modes *hw_features, int num_hw_features) { - int i; + int i, j; if (chan) *chan = 0; - if (!mode) + if (!hw_features) return NULL; - for (i = 0; i < mode->num_channels; i++) { - struct hostapd_channel_data *ch = &mode->channels[i]; - if (ch->freq == freq) { - if (chan) - *chan = ch->chan; - return ch; + for (j = 0; j < num_hw_features; j++) { + struct hostapd_hw_modes *curr_mode = &hw_features[j]; + + if (curr_mode->mode != mode) + continue; + for (i = 0; i < curr_mode->num_channels; i++) { + struct hostapd_channel_data *ch = + &curr_mode->channels[i]; + + if (ch->freq == freq) { + if (chan) + *chan = ch->chan; + return ch; + } } } @@ -74,11 +83,12 @@ int hw_get_freq(struct hostapd_hw_modes *mode, int chan) } -int hw_get_chan(struct hostapd_hw_modes *mode, int freq) +int hw_get_chan(enum hostapd_hw_mode mode, int freq, + struct hostapd_hw_modes *hw_features, int num_hw_features) { int chan; - hw_get_channel_freq(mode, freq, &chan); + hw_get_channel_freq(mode, freq, &chan, hw_features, num_hw_features); return chan; } diff --git a/src/common/hw_features_common.h b/src/common/hw_features_common.h index c86e19559..7eb4ca170 100644 --- a/src/common/hw_features_common.h +++ b/src/common/hw_features_common.h @@ -14,11 +14,13 @@ struct hostapd_channel_data * hw_get_channel_chan(struct hostapd_hw_modes *mode, int chan, int *freq); -struct hostapd_channel_data * hw_get_channel_freq(struct hostapd_hw_modes *mode, - int freq, int *chan); +struct hostapd_channel_data * +hw_get_channel_freq(enum hostapd_hw_mode mode, int freq, int *chan, + struct hostapd_hw_modes *hw_features, int num_hw_features); int hw_get_freq(struct hostapd_hw_modes *mode, int chan); -int hw_get_chan(struct hostapd_hw_modes *mode, int freq); +int hw_get_chan(enum hostapd_hw_mode mode, int freq, + struct hostapd_hw_modes *hw_features, int num_hw_features); int allowed_ht40_channel_pair(struct hostapd_hw_modes *mode, int pri_chan, int sec_chan);