2008-02-27 20:34:43 -05:00
|
|
|
/*
|
|
|
|
* hostapd / Hardware feature query and different modes
|
|
|
|
* Copyright 2002-2003, Instant802 Networks, Inc.
|
|
|
|
* Copyright 2005-2006, Devicescape Software, Inc.
|
2012-04-08 05:12:32 -04:00
|
|
|
* Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
|
2008-02-27 20:34:43 -05:00
|
|
|
*
|
2013-12-24 15:59:52 -05:00
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
2008-02-27 20:34:43 -05:00
|
|
|
*/
|
|
|
|
|
2009-12-24 18:12:50 -05:00
|
|
|
#include "utils/includes.h"
|
2008-02-27 20:34:43 -05:00
|
|
|
|
2009-12-24 18:12:50 -05:00
|
|
|
#include "utils/common.h"
|
|
|
|
#include "utils/eloop.h"
|
2009-11-29 10:51:55 -05:00
|
|
|
#include "common/ieee802_11_defs.h"
|
|
|
|
#include "common/ieee802_11_common.h"
|
2013-11-03 08:59:53 -05:00
|
|
|
#include "common/wpa_ctrl.h"
|
2015-01-08 06:48:30 -05:00
|
|
|
#include "common/hw_features_common.h"
|
2009-12-25 17:05:40 -05:00
|
|
|
#include "hostapd.h"
|
|
|
|
#include "ap_config.h"
|
2009-12-25 17:21:22 -05:00
|
|
|
#include "ap_drv_ops.h"
|
2013-08-31 04:49:51 -04:00
|
|
|
#include "acs.h"
|
2014-04-14 13:40:56 -04:00
|
|
|
#include "ieee802_11.h"
|
|
|
|
#include "beacon.h"
|
2009-12-25 17:05:40 -05:00
|
|
|
#include "hw_features.h"
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
|
|
|
|
void hostapd_free_hw_features(struct hostapd_hw_modes *hw_features,
|
|
|
|
size_t num_hw_features)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (hw_features == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < num_hw_features; i++) {
|
|
|
|
os_free(hw_features[i].channels);
|
|
|
|
os_free(hw_features[i].rates);
|
|
|
|
}
|
|
|
|
|
|
|
|
os_free(hw_features);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-15 13:27:25 -04:00
|
|
|
#ifndef CONFIG_NO_STDOUT_DEBUG
|
|
|
|
static char * dfs_info(struct hostapd_channel_data *chan)
|
|
|
|
{
|
|
|
|
static char info[256];
|
|
|
|
char *state;
|
|
|
|
|
|
|
|
switch (chan->flag & HOSTAPD_CHAN_DFS_MASK) {
|
|
|
|
case HOSTAPD_CHAN_DFS_UNKNOWN:
|
|
|
|
state = "unknown";
|
|
|
|
break;
|
|
|
|
case HOSTAPD_CHAN_DFS_USABLE:
|
|
|
|
state = "usable";
|
|
|
|
break;
|
|
|
|
case HOSTAPD_CHAN_DFS_UNAVAILABLE:
|
|
|
|
state = "unavailable";
|
|
|
|
break;
|
|
|
|
case HOSTAPD_CHAN_DFS_AVAILABLE:
|
|
|
|
state = "available";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
os_snprintf(info, sizeof(info), " (DFS state = %s)", state);
|
|
|
|
info[sizeof(info) - 1] = '\0';
|
|
|
|
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_NO_STDOUT_DEBUG */
|
|
|
|
|
|
|
|
|
2008-02-27 20:34:43 -05:00
|
|
|
int hostapd_get_hw_features(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
struct hostapd_data *hapd = iface->bss[0];
|
|
|
|
int ret = 0, i, j;
|
|
|
|
u16 num_modes, flags;
|
|
|
|
struct hostapd_hw_modes *modes;
|
|
|
|
|
2008-10-01 07:17:35 -04:00
|
|
|
if (hostapd_drv_none(hapd))
|
|
|
|
return -1;
|
2008-02-27 20:34:43 -05:00
|
|
|
modes = hostapd_get_hw_feature_data(hapd, &num_modes, &flags);
|
|
|
|
if (modes == NULL) {
|
|
|
|
hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_DEBUG,
|
|
|
|
"Fetching hardware channel/rate support not "
|
|
|
|
"supported.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface->hw_flags = flags;
|
|
|
|
|
|
|
|
hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
|
|
|
|
iface->hw_features = modes;
|
|
|
|
iface->num_hw_features = num_modes;
|
|
|
|
|
|
|
|
for (i = 0; i < num_modes; i++) {
|
|
|
|
struct hostapd_hw_modes *feature = &modes[i];
|
2013-10-15 13:27:25 -04:00
|
|
|
int dfs_enabled = hapd->iconf->ieee80211h &&
|
|
|
|
(iface->drv_flags & WPA_DRIVER_FLAGS_RADAR);
|
|
|
|
|
2008-02-27 20:34:43 -05:00
|
|
|
/* set flag for channels we can use in current regulatory
|
|
|
|
* domain */
|
|
|
|
for (j = 0; j < feature->num_channels; j++) {
|
2013-10-15 13:27:25 -04:00
|
|
|
int dfs = 0;
|
|
|
|
|
2008-11-18 07:51:43 -05:00
|
|
|
/*
|
|
|
|
* Disable all channels that are marked not to allow
|
2014-07-07 07:20:54 -04:00
|
|
|
* to initiate radiation (a.k.a. passive scan and no
|
|
|
|
* IBSS).
|
2013-10-15 13:27:25 -04:00
|
|
|
* Use radar channels only if the driver supports DFS.
|
2008-11-18 07:51:43 -05:00
|
|
|
*/
|
2013-10-15 13:27:25 -04:00
|
|
|
if ((feature->channels[j].flag &
|
|
|
|
HOSTAPD_CHAN_RADAR) && dfs_enabled) {
|
|
|
|
dfs = 1;
|
2014-03-22 15:31:15 -04:00
|
|
|
} else if (((feature->channels[j].flag &
|
|
|
|
HOSTAPD_CHAN_RADAR) &&
|
|
|
|
!(iface->drv_flags &
|
|
|
|
WPA_DRIVER_FLAGS_DFS_OFFLOAD)) ||
|
|
|
|
(feature->channels[j].flag &
|
2014-07-07 07:20:54 -04:00
|
|
|
HOSTAPD_CHAN_NO_IR)) {
|
2008-02-27 20:34:43 -05:00
|
|
|
feature->channels[j].flag |=
|
2008-11-18 07:51:43 -05:00
|
|
|
HOSTAPD_CHAN_DISABLED;
|
2013-10-15 13:27:25 -04:00
|
|
|
}
|
|
|
|
|
2008-11-18 07:51:43 -05:00
|
|
|
if (feature->channels[j].flag & HOSTAPD_CHAN_DISABLED)
|
|
|
|
continue;
|
2013-10-15 13:27:25 -04:00
|
|
|
|
2008-11-18 07:51:43 -05:00
|
|
|
wpa_printf(MSG_MSGDUMP, "Allowed channel: mode=%d "
|
2013-10-15 13:27:25 -04:00
|
|
|
"chan=%d freq=%d MHz max_tx_power=%d dBm%s",
|
2008-11-18 07:51:43 -05:00
|
|
|
feature->mode,
|
|
|
|
feature->channels[j].chan,
|
2008-11-25 04:11:50 -05:00
|
|
|
feature->channels[j].freq,
|
2013-10-15 13:27:25 -04:00
|
|
|
feature->channels[j].max_tx_power,
|
|
|
|
dfs ? dfs_info(&feature->channels[j]) : "");
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-03 05:20:17 -05:00
|
|
|
int hostapd_prepare_rates(struct hostapd_iface *iface,
|
2010-11-09 09:17:50 -05:00
|
|
|
struct hostapd_hw_modes *mode)
|
2008-02-27 20:34:43 -05:00
|
|
|
{
|
|
|
|
int i, num_basic_rates = 0;
|
|
|
|
int basic_rates_a[] = { 60, 120, 240, -1 };
|
|
|
|
int basic_rates_b[] = { 10, 20, -1 };
|
|
|
|
int basic_rates_g[] = { 10, 20, 55, 110, -1 };
|
|
|
|
int *basic_rates;
|
|
|
|
|
2011-12-03 05:20:17 -05:00
|
|
|
if (iface->conf->basic_rates)
|
|
|
|
basic_rates = iface->conf->basic_rates;
|
2008-02-27 20:34:43 -05:00
|
|
|
else switch (mode->mode) {
|
|
|
|
case HOSTAPD_MODE_IEEE80211A:
|
|
|
|
basic_rates = basic_rates_a;
|
|
|
|
break;
|
|
|
|
case HOSTAPD_MODE_IEEE80211B:
|
|
|
|
basic_rates = basic_rates_b;
|
|
|
|
break;
|
|
|
|
case HOSTAPD_MODE_IEEE80211G:
|
|
|
|
basic_rates = basic_rates_g;
|
|
|
|
break;
|
2012-12-18 04:50:35 -05:00
|
|
|
case HOSTAPD_MODE_IEEE80211AD:
|
|
|
|
return 0; /* No basic rates for 11ad */
|
2008-02-27 20:34:43 -05:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-12-03 05:16:03 -05:00
|
|
|
i = 0;
|
|
|
|
while (basic_rates[i] >= 0)
|
|
|
|
i++;
|
2012-09-06 17:15:53 -04:00
|
|
|
if (i)
|
|
|
|
i++; /* -1 termination */
|
2011-12-03 05:20:17 -05:00
|
|
|
os_free(iface->basic_rates);
|
2011-12-04 06:12:30 -05:00
|
|
|
iface->basic_rates = os_malloc(i * sizeof(int));
|
2011-12-03 05:20:17 -05:00
|
|
|
if (iface->basic_rates)
|
2011-12-04 06:12:30 -05:00
|
|
|
os_memcpy(iface->basic_rates, basic_rates, i * sizeof(int));
|
2008-02-27 20:34:43 -05:00
|
|
|
|
2011-12-03 05:20:17 -05:00
|
|
|
os_free(iface->current_rates);
|
|
|
|
iface->num_rates = 0;
|
2008-02-27 20:34:43 -05:00
|
|
|
|
2011-12-03 05:20:17 -05:00
|
|
|
iface->current_rates =
|
2012-08-13 13:44:21 -04:00
|
|
|
os_calloc(mode->num_rates, sizeof(struct hostapd_rate_data));
|
2011-12-03 05:20:17 -05:00
|
|
|
if (!iface->current_rates) {
|
2008-02-27 20:34:43 -05:00
|
|
|
wpa_printf(MSG_ERROR, "Failed to allocate memory for rate "
|
|
|
|
"table.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < mode->num_rates; i++) {
|
|
|
|
struct hostapd_rate_data *rate;
|
|
|
|
|
2011-12-03 05:20:17 -05:00
|
|
|
if (iface->conf->supported_rates &&
|
|
|
|
!hostapd_rate_found(iface->conf->supported_rates,
|
2009-12-09 14:57:50 -05:00
|
|
|
mode->rates[i]))
|
2008-02-27 20:34:43 -05:00
|
|
|
continue;
|
|
|
|
|
2011-12-03 05:20:17 -05:00
|
|
|
rate = &iface->current_rates[iface->num_rates];
|
2009-12-09 14:57:50 -05:00
|
|
|
rate->rate = mode->rates[i];
|
2008-02-27 20:34:43 -05:00
|
|
|
if (hostapd_rate_found(basic_rates, rate->rate)) {
|
|
|
|
rate->flags |= HOSTAPD_RATE_BASIC;
|
|
|
|
num_basic_rates++;
|
2009-12-09 14:57:50 -05:00
|
|
|
}
|
2008-02-27 20:34:43 -05:00
|
|
|
wpa_printf(MSG_DEBUG, "RATE[%d] rate=%d flags=0x%x",
|
2011-12-03 05:20:17 -05:00
|
|
|
iface->num_rates, rate->rate, rate->flags);
|
|
|
|
iface->num_rates++;
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
|
|
|
|
2011-12-03 05:20:17 -05:00
|
|
|
if ((iface->num_rates == 0 || num_basic_rates == 0) &&
|
|
|
|
(!iface->conf->ieee80211n || !iface->conf->require_ht)) {
|
2008-02-27 20:34:43 -05:00
|
|
|
wpa_printf(MSG_ERROR, "No rates remaining in supported/basic "
|
|
|
|
"rate sets (%d,%d).",
|
2011-12-03 05:20:17 -05:00
|
|
|
iface->num_rates, num_basic_rates);
|
2008-02-27 20:34:43 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-25 05:51:03 -05:00
|
|
|
#ifdef CONFIG_IEEE80211N
|
|
|
|
static int ieee80211n_allowed_ht40_channel_pair(struct hostapd_iface *iface)
|
|
|
|
{
|
2015-01-08 06:48:31 -05:00
|
|
|
int pri_chan, sec_chan;
|
2008-11-25 05:51:03 -05:00
|
|
|
|
|
|
|
if (!iface->conf->secondary_channel)
|
|
|
|
return 1; /* HT40 not used */
|
|
|
|
|
2015-01-08 06:48:31 -05:00
|
|
|
pri_chan = iface->conf->channel;
|
|
|
|
sec_chan = pri_chan + iface->conf->secondary_channel * 4;
|
2008-11-25 05:51:03 -05:00
|
|
|
|
2015-01-08 06:48:31 -05:00
|
|
|
return allowed_ht40_channel_pair(iface->current_mode, pri_chan,
|
|
|
|
sec_chan);
|
2008-11-25 05:51:03 -05:00
|
|
|
}
|
2009-02-04 05:49:23 -05:00
|
|
|
|
|
|
|
|
2009-02-04 14:19:54 -05:00
|
|
|
static void ieee80211n_switch_pri_sec(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
if (iface->conf->secondary_channel > 0) {
|
|
|
|
iface->conf->channel += 4;
|
|
|
|
iface->conf->secondary_channel = -1;
|
|
|
|
} else {
|
|
|
|
iface->conf->channel -= 4;
|
|
|
|
iface->conf->secondary_channel = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 09:22:40 -04:00
|
|
|
static void ieee80211n_get_pri_sec_chan(struct wpa_scan_res *bss,
|
|
|
|
int *pri_chan, int *sec_chan)
|
|
|
|
{
|
|
|
|
struct ieee80211_ht_operation *oper;
|
|
|
|
struct ieee802_11_elems elems;
|
|
|
|
|
|
|
|
*pri_chan = *sec_chan = 0;
|
|
|
|
|
|
|
|
ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0);
|
|
|
|
if (elems.ht_operation &&
|
|
|
|
elems.ht_operation_len >= sizeof(*oper)) {
|
|
|
|
oper = (struct ieee80211_ht_operation *) elems.ht_operation;
|
2014-04-07 15:45:11 -04:00
|
|
|
*pri_chan = oper->primary_chan;
|
|
|
|
if (oper->ht_param & HT_INFO_HT_PARAM_STA_CHNL_WIDTH) {
|
2010-10-06 07:09:44 -04:00
|
|
|
int sec = oper->ht_param &
|
|
|
|
HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
|
|
|
|
if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
|
2009-04-16 09:22:40 -04:00
|
|
|
*sec_chan = *pri_chan + 4;
|
2010-10-06 07:09:44 -04:00
|
|
|
else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
|
2009-04-16 09:22:40 -04:00
|
|
|
*sec_chan = *pri_chan - 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int ieee80211n_check_40mhz_5g(struct hostapd_iface *iface,
|
|
|
|
struct wpa_scan_results *scan_res)
|
2009-02-04 14:19:54 -05:00
|
|
|
{
|
|
|
|
int pri_chan, sec_chan, pri_freq, sec_freq, pri_bss, sec_bss;
|
2009-04-16 09:22:40 -04:00
|
|
|
int bss_pri_chan, bss_sec_chan;
|
|
|
|
size_t i;
|
2009-02-04 14:19:54 -05:00
|
|
|
int match;
|
|
|
|
|
|
|
|
pri_chan = iface->conf->channel;
|
2014-03-15 10:42:29 -04:00
|
|
|
sec_chan = pri_chan + iface->conf->secondary_channel * 4;
|
2009-02-04 14:19:54 -05:00
|
|
|
pri_freq = hostapd_hw_get_freq(iface->bss[0], pri_chan);
|
|
|
|
if (iface->conf->secondary_channel > 0)
|
|
|
|
sec_freq = pri_freq + 20;
|
|
|
|
else
|
|
|
|
sec_freq = pri_freq - 20;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Switch PRI/SEC channels if Beacons were detected on selected SEC
|
|
|
|
* channel, but not on selected PRI channel.
|
|
|
|
*/
|
|
|
|
pri_bss = sec_bss = 0;
|
2009-04-16 09:22:40 -04:00
|
|
|
for (i = 0; i < scan_res->num; i++) {
|
|
|
|
struct wpa_scan_res *bss = scan_res->res[i];
|
|
|
|
if (bss->freq == pri_freq)
|
2009-02-04 14:19:54 -05:00
|
|
|
pri_bss++;
|
2009-04-16 09:22:40 -04:00
|
|
|
else if (bss->freq == sec_freq)
|
2009-02-04 14:19:54 -05:00
|
|
|
sec_bss++;
|
|
|
|
}
|
|
|
|
if (sec_bss && !pri_bss) {
|
|
|
|
wpa_printf(MSG_INFO, "Switch own primary and secondary "
|
|
|
|
"channel to get secondary channel with no Beacons "
|
|
|
|
"from other BSSes");
|
|
|
|
ieee80211n_switch_pri_sec(iface);
|
2014-03-15 10:42:29 -04:00
|
|
|
return 1;
|
2009-02-04 14:19:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Match PRI/SEC channel with any existing HT40 BSS on the same
|
|
|
|
* channels that we are about to use (if already mixed order in
|
|
|
|
* existing BSSes, use own preference).
|
|
|
|
*/
|
|
|
|
match = 0;
|
2009-04-16 09:22:40 -04:00
|
|
|
for (i = 0; i < scan_res->num; i++) {
|
|
|
|
struct wpa_scan_res *bss = scan_res->res[i];
|
|
|
|
ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan, &bss_sec_chan);
|
|
|
|
if (pri_chan == bss_pri_chan &&
|
|
|
|
sec_chan == bss_sec_chan) {
|
2009-02-04 14:19:54 -05:00
|
|
|
match = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!match) {
|
2009-04-16 09:22:40 -04:00
|
|
|
for (i = 0; i < scan_res->num; i++) {
|
|
|
|
struct wpa_scan_res *bss = scan_res->res[i];
|
2009-11-16 06:52:12 -05:00
|
|
|
ieee80211n_get_pri_sec_chan(bss, &bss_pri_chan,
|
|
|
|
&bss_sec_chan);
|
2009-04-16 09:22:40 -04:00
|
|
|
if (pri_chan == bss_sec_chan &&
|
|
|
|
sec_chan == bss_pri_chan) {
|
2009-02-04 14:19:54 -05:00
|
|
|
wpa_printf(MSG_INFO, "Switch own primary and "
|
|
|
|
"secondary channel due to BSS "
|
|
|
|
"overlap with " MACSTR,
|
2009-04-16 09:22:40 -04:00
|
|
|
MAC2STR(bss->bssid));
|
2009-02-04 14:19:54 -05:00
|
|
|
ieee80211n_switch_pri_sec(iface);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-14 03:41:44 -04:00
|
|
|
static int ieee80211n_check_20mhz_bss(struct wpa_scan_res *bss, int pri_freq,
|
|
|
|
int start, int end)
|
|
|
|
{
|
|
|
|
struct ieee802_11_elems elems;
|
|
|
|
struct ieee80211_ht_operation *oper;
|
|
|
|
|
|
|
|
if (bss->freq < start || bss->freq > end || bss->freq == pri_freq)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems, 0);
|
|
|
|
if (!elems.ht_capabilities) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Found overlapping legacy BSS: "
|
|
|
|
MACSTR " freq=%d", MAC2STR(bss->bssid), bss->freq);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (elems.ht_operation &&
|
|
|
|
elems.ht_operation_len >= sizeof(*oper)) {
|
|
|
|
oper = (struct ieee80211_ht_operation *) elems.ht_operation;
|
|
|
|
if (oper->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "Found overlapping 20 MHz HT BSS: "
|
|
|
|
MACSTR " freq=%d", MAC2STR(bss->bssid), bss->freq);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 09:22:40 -04:00
|
|
|
static int ieee80211n_check_40mhz_2g4(struct hostapd_iface *iface,
|
|
|
|
struct wpa_scan_results *scan_res)
|
2009-02-04 14:19:54 -05:00
|
|
|
{
|
|
|
|
int pri_freq, sec_freq;
|
|
|
|
int affected_start, affected_end;
|
2009-04-16 09:22:40 -04:00
|
|
|
size_t i;
|
2009-02-04 14:19:54 -05:00
|
|
|
|
|
|
|
pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
|
|
|
|
if (iface->conf->secondary_channel > 0)
|
|
|
|
sec_freq = pri_freq + 20;
|
|
|
|
else
|
|
|
|
sec_freq = pri_freq - 20;
|
|
|
|
affected_start = (pri_freq + sec_freq) / 2 - 25;
|
|
|
|
affected_end = (pri_freq + sec_freq) / 2 + 25;
|
|
|
|
wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
|
|
|
|
affected_start, affected_end);
|
2009-04-16 09:22:40 -04:00
|
|
|
for (i = 0; i < scan_res->num; i++) {
|
|
|
|
struct wpa_scan_res *bss = scan_res->res[i];
|
|
|
|
int pri = bss->freq;
|
2009-02-04 14:19:54 -05:00
|
|
|
int sec = pri;
|
2009-04-16 09:22:40 -04:00
|
|
|
int sec_chan, pri_chan;
|
2014-04-14 13:40:56 -04:00
|
|
|
struct ieee802_11_elems elems;
|
2009-04-16 09:22:40 -04:00
|
|
|
|
2014-05-14 03:41:44 -04:00
|
|
|
/* Check for overlapping 20 MHz BSS */
|
|
|
|
if (ieee80211n_check_20mhz_bss(bss, pri_freq, affected_start,
|
|
|
|
affected_end)) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"Overlapping 20 MHz BSS is found");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-16 09:22:40 -04:00
|
|
|
ieee80211n_get_pri_sec_chan(bss, &pri_chan, &sec_chan);
|
|
|
|
|
|
|
|
if (sec_chan) {
|
|
|
|
if (sec_chan < pri_chan)
|
2009-02-04 14:19:54 -05:00
|
|
|
sec = pri - 20;
|
|
|
|
else
|
|
|
|
sec = pri + 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((pri < affected_start || pri > affected_end) &&
|
|
|
|
(sec < affected_start || sec > affected_end))
|
|
|
|
continue; /* not within affected channel range */
|
|
|
|
|
2009-04-16 09:22:40 -04:00
|
|
|
wpa_printf(MSG_DEBUG, "Neighboring BSS: " MACSTR
|
|
|
|
" freq=%d pri=%d sec=%d",
|
|
|
|
MAC2STR(bss->bssid), bss->freq, pri_chan, sec_chan);
|
|
|
|
|
|
|
|
if (sec_chan) {
|
2009-02-04 14:19:54 -05:00
|
|
|
if (pri_freq != pri || sec_freq != sec) {
|
|
|
|
wpa_printf(MSG_DEBUG, "40 MHz pri/sec "
|
|
|
|
"mismatch with BSS " MACSTR
|
|
|
|
" <%d,%d> (chan=%d%c) vs. <%d,%d>",
|
2009-04-16 09:22:40 -04:00
|
|
|
MAC2STR(bss->bssid),
|
|
|
|
pri, sec, pri_chan,
|
2009-02-04 14:19:54 -05:00
|
|
|
sec > pri ? '+' : '-',
|
|
|
|
pri_freq, sec_freq);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-14 13:40:56 -04:00
|
|
|
ieee802_11_parse_elems((u8 *) (bss + 1), bss->ie_len, &elems,
|
|
|
|
0);
|
|
|
|
if (elems.ht_capabilities &&
|
|
|
|
elems.ht_capabilities_len >=
|
|
|
|
sizeof(struct ieee80211_ht_capabilities)) {
|
|
|
|
struct ieee80211_ht_capabilities *ht_cap =
|
|
|
|
(struct ieee80211_ht_capabilities *)
|
|
|
|
elems.ht_capabilities;
|
|
|
|
|
|
|
|
if (le_to_host16(ht_cap->ht_capabilities_info) &
|
|
|
|
HT_CAP_INFO_40MHZ_INTOLERANT) {
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"40 MHz Intolerant is set on channel %d in BSS "
|
|
|
|
MACSTR, pri, MAC2STR(bss->bssid));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2009-02-04 14:19:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 09:22:40 -04:00
|
|
|
static void ieee80211n_check_scan(struct hostapd_iface *iface)
|
2009-02-04 14:19:54 -05:00
|
|
|
{
|
2009-04-16 09:22:40 -04:00
|
|
|
struct wpa_scan_results *scan_res;
|
2009-02-04 14:19:54 -05:00
|
|
|
int oper40;
|
2011-02-01 09:09:26 -05:00
|
|
|
int res;
|
2009-02-04 14:19:54 -05:00
|
|
|
|
|
|
|
/* Check list of neighboring BSSes (from scan) to see whether 40 MHz is
|
2012-04-08 05:12:32 -04:00
|
|
|
* allowed per IEEE Std 802.11-2012, 10.15.3.2 */
|
2009-02-04 14:19:54 -05:00
|
|
|
|
2009-04-16 09:22:40 -04:00
|
|
|
iface->scan_cb = NULL;
|
|
|
|
|
|
|
|
scan_res = hostapd_driver_get_scan_results(iface->bss[0]);
|
|
|
|
if (scan_res == NULL) {
|
|
|
|
hostapd_setup_interface_complete(iface, 1);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-02-04 14:19:54 -05:00
|
|
|
if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A)
|
2009-04-16 09:22:40 -04:00
|
|
|
oper40 = ieee80211n_check_40mhz_5g(iface, scan_res);
|
2009-02-04 14:19:54 -05:00
|
|
|
else
|
2009-04-16 09:22:40 -04:00
|
|
|
oper40 = ieee80211n_check_40mhz_2g4(iface, scan_res);
|
|
|
|
wpa_scan_results_free(scan_res);
|
2009-02-04 14:19:54 -05:00
|
|
|
|
2014-04-14 13:40:56 -04:00
|
|
|
iface->secondary_ch = iface->conf->secondary_channel;
|
2009-02-04 14:19:54 -05:00
|
|
|
if (!oper40) {
|
|
|
|
wpa_printf(MSG_INFO, "20/40 MHz operation not permitted on "
|
|
|
|
"channel pri=%d sec=%d based on overlapping BSSes",
|
|
|
|
iface->conf->channel,
|
|
|
|
iface->conf->channel +
|
|
|
|
iface->conf->secondary_channel * 4);
|
|
|
|
iface->conf->secondary_channel = 0;
|
2014-04-14 13:40:56 -04:00
|
|
|
if (iface->drv_flags & WPA_DRIVER_FLAGS_HT_2040_COEX) {
|
|
|
|
/*
|
|
|
|
* TODO: Could consider scheduling another scan to check
|
|
|
|
* if channel width can be changed if no coex reports
|
|
|
|
* are received from associating stations.
|
|
|
|
*/
|
|
|
|
}
|
2009-02-04 14:19:54 -05:00
|
|
|
}
|
2009-04-16 09:22:40 -04:00
|
|
|
|
2011-02-01 09:09:26 -05:00
|
|
|
res = ieee80211n_allowed_ht40_channel_pair(iface);
|
2014-04-14 13:40:56 -04:00
|
|
|
if (!res) {
|
|
|
|
iface->conf->secondary_channel = 0;
|
|
|
|
wpa_printf(MSG_INFO, "Fallback to 20 MHz");
|
|
|
|
}
|
|
|
|
|
2011-02-01 09:09:26 -05:00
|
|
|
hostapd_setup_interface_complete(iface, !res);
|
2009-04-16 09:22:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-08 05:12:32 -04:00
|
|
|
static void ieee80211n_scan_channels_2g4(struct hostapd_iface *iface,
|
|
|
|
struct wpa_driver_scan_params *params)
|
|
|
|
{
|
|
|
|
/* Scan only the affected frequency range */
|
|
|
|
int pri_freq, sec_freq;
|
|
|
|
int affected_start, affected_end;
|
|
|
|
int i, pos;
|
|
|
|
struct hostapd_hw_modes *mode;
|
|
|
|
|
|
|
|
if (iface->current_mode == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
|
|
|
|
if (iface->conf->secondary_channel > 0)
|
|
|
|
sec_freq = pri_freq + 20;
|
|
|
|
else
|
|
|
|
sec_freq = pri_freq - 20;
|
|
|
|
affected_start = (pri_freq + sec_freq) / 2 - 25;
|
|
|
|
affected_end = (pri_freq + sec_freq) / 2 + 25;
|
|
|
|
wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
|
|
|
|
affected_start, affected_end);
|
|
|
|
|
|
|
|
mode = iface->current_mode;
|
2012-08-13 13:44:21 -04:00
|
|
|
params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
|
2012-04-08 05:12:32 -04:00
|
|
|
if (params->freqs == NULL)
|
|
|
|
return;
|
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < mode->num_channels; i++) {
|
|
|
|
struct hostapd_channel_data *chan = &mode->channels[i];
|
|
|
|
if (chan->flag & HOSTAPD_CHAN_DISABLED)
|
|
|
|
continue;
|
|
|
|
if (chan->freq < affected_start ||
|
|
|
|
chan->freq > affected_end)
|
|
|
|
continue;
|
|
|
|
params->freqs[pos++] = chan->freq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-03 10:43:40 -05:00
|
|
|
static void ieee80211n_scan_channels_5g(struct hostapd_iface *iface,
|
|
|
|
struct wpa_driver_scan_params *params)
|
|
|
|
{
|
|
|
|
/* Scan only the affected frequency range */
|
|
|
|
int pri_freq;
|
|
|
|
int affected_start, affected_end;
|
|
|
|
int i, pos;
|
|
|
|
struct hostapd_hw_modes *mode;
|
|
|
|
|
|
|
|
if (iface->current_mode == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pri_freq = hostapd_hw_get_freq(iface->bss[0], iface->conf->channel);
|
|
|
|
if (iface->conf->secondary_channel > 0) {
|
|
|
|
affected_start = pri_freq - 10;
|
|
|
|
affected_end = pri_freq + 30;
|
|
|
|
} else {
|
|
|
|
affected_start = pri_freq - 30;
|
|
|
|
affected_end = pri_freq + 10;
|
|
|
|
}
|
|
|
|
wpa_printf(MSG_DEBUG, "40 MHz affected channel range: [%d,%d] MHz",
|
|
|
|
affected_start, affected_end);
|
|
|
|
|
|
|
|
mode = iface->current_mode;
|
|
|
|
params->freqs = os_calloc(mode->num_channels + 1, sizeof(int));
|
|
|
|
if (params->freqs == NULL)
|
|
|
|
return;
|
|
|
|
pos = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < mode->num_channels; i++) {
|
|
|
|
struct hostapd_channel_data *chan = &mode->channels[i];
|
|
|
|
if (chan->flag & HOSTAPD_CHAN_DISABLED)
|
|
|
|
continue;
|
|
|
|
if (chan->freq < affected_start ||
|
|
|
|
chan->freq > affected_end)
|
|
|
|
continue;
|
|
|
|
params->freqs[pos++] = chan->freq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-16 11:45:53 -04:00
|
|
|
static void ap_ht40_scan_retry(void *eloop_data, void *user_data)
|
|
|
|
{
|
|
|
|
#define HT2040_COEX_SCAN_RETRY 15
|
|
|
|
struct hostapd_iface *iface = eloop_data;
|
|
|
|
struct wpa_driver_scan_params params;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
os_memset(¶ms, 0, sizeof(params));
|
|
|
|
if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
|
|
|
|
ieee80211n_scan_channels_2g4(iface, ¶ms);
|
|
|
|
else
|
|
|
|
ieee80211n_scan_channels_5g(iface, ¶ms);
|
|
|
|
|
|
|
|
ret = hostapd_driver_scan(iface->bss[0], ¶ms);
|
|
|
|
iface->num_ht40_scan_tries++;
|
|
|
|
os_free(params.freqs);
|
|
|
|
|
|
|
|
if (ret == -EBUSY &&
|
|
|
|
iface->num_ht40_scan_tries < HT2040_COEX_SCAN_RETRY) {
|
|
|
|
wpa_printf(MSG_ERROR,
|
|
|
|
"Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again (attempt %d)",
|
|
|
|
ret, strerror(-ret), iface->num_ht40_scan_tries);
|
|
|
|
eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == 0) {
|
|
|
|
iface->scan_cb = ieee80211n_check_scan;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"Failed to request a scan in device, bringing up in HT20 mode");
|
|
|
|
iface->conf->secondary_channel = 0;
|
|
|
|
iface->conf->ht_capab &= ~HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET;
|
|
|
|
hostapd_setup_interface_complete(iface, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void hostapd_stop_setup_timers(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-16 09:22:40 -04:00
|
|
|
static int ieee80211n_check_40mhz(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
struct wpa_driver_scan_params params;
|
2014-04-16 11:45:53 -04:00
|
|
|
int ret;
|
2009-04-16 09:22:40 -04:00
|
|
|
|
|
|
|
if (!iface->conf->secondary_channel)
|
|
|
|
return 0; /* HT40 not used */
|
|
|
|
|
2013-11-03 10:25:05 -05:00
|
|
|
hostapd_set_state(iface, HAPD_IFACE_HT_SCAN);
|
2009-04-16 09:22:40 -04:00
|
|
|
wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling "
|
|
|
|
"40 MHz channel");
|
|
|
|
os_memset(¶ms, 0, sizeof(params));
|
2012-04-08 05:12:32 -04:00
|
|
|
if (iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G)
|
|
|
|
ieee80211n_scan_channels_2g4(iface, ¶ms);
|
2013-11-03 10:43:40 -05:00
|
|
|
else
|
|
|
|
ieee80211n_scan_channels_5g(iface, ¶ms);
|
2014-04-16 11:45:53 -04:00
|
|
|
|
|
|
|
ret = hostapd_driver_scan(iface->bss[0], ¶ms);
|
|
|
|
os_free(params.freqs);
|
|
|
|
|
|
|
|
if (ret == -EBUSY) {
|
|
|
|
wpa_printf(MSG_ERROR,
|
|
|
|
"Failed to request a scan of neighboring BSSes ret=%d (%s) - try to scan again",
|
|
|
|
ret, strerror(-ret));
|
|
|
|
iface->num_ht40_scan_tries = 1;
|
|
|
|
eloop_cancel_timeout(ap_ht40_scan_retry, iface, NULL);
|
|
|
|
eloop_register_timeout(1, 0, ap_ht40_scan_retry, iface, NULL);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
wpa_printf(MSG_ERROR,
|
|
|
|
"Failed to request a scan of neighboring BSSes ret=%d (%s)",
|
|
|
|
ret, strerror(-ret));
|
2009-04-16 09:22:40 -04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface->scan_cb = ieee80211n_check_scan;
|
|
|
|
return 1;
|
2009-02-04 14:19:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-04 05:49:23 -05:00
|
|
|
static int ieee80211n_supported_ht_capab(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
u16 hw = iface->current_mode->ht_capab;
|
|
|
|
u16 conf = iface->conf->ht_capab;
|
|
|
|
|
|
|
|
if ((conf & HT_CAP_INFO_LDPC_CODING_CAP) &&
|
|
|
|
!(hw & HT_CAP_INFO_LDPC_CODING_CAP)) {
|
|
|
|
wpa_printf(MSG_ERROR, "Driver does not support configured "
|
|
|
|
"HT capability [LDPC]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) &&
|
|
|
|
!(hw & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
|
|
|
|
wpa_printf(MSG_ERROR, "Driver does not support configured "
|
|
|
|
"HT capability [HT40*]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-10-19 23:21:39 -04:00
|
|
|
switch (conf & HT_CAP_INFO_SMPS_MASK) {
|
|
|
|
case HT_CAP_INFO_SMPS_STATIC:
|
|
|
|
if (!(iface->smps_modes & WPA_DRIVER_SMPS_MODE_STATIC)) {
|
|
|
|
wpa_printf(MSG_ERROR,
|
|
|
|
"Driver does not support configured HT capability [SMPS-STATIC]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case HT_CAP_INFO_SMPS_DYNAMIC:
|
|
|
|
if (!(iface->smps_modes & WPA_DRIVER_SMPS_MODE_DYNAMIC)) {
|
|
|
|
wpa_printf(MSG_ERROR,
|
|
|
|
"Driver does not support configured HT capability [SMPS-DYNAMIC]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case HT_CAP_INFO_SMPS_DISABLED:
|
|
|
|
default:
|
|
|
|
break;
|
2009-02-04 05:49:23 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf & HT_CAP_INFO_GREEN_FIELD) &&
|
|
|
|
!(hw & HT_CAP_INFO_GREEN_FIELD)) {
|
|
|
|
wpa_printf(MSG_ERROR, "Driver does not support configured "
|
|
|
|
"HT capability [GF]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf & HT_CAP_INFO_SHORT_GI20MHZ) &&
|
|
|
|
!(hw & HT_CAP_INFO_SHORT_GI20MHZ)) {
|
|
|
|
wpa_printf(MSG_ERROR, "Driver does not support configured "
|
|
|
|
"HT capability [SHORT-GI-20]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf & HT_CAP_INFO_SHORT_GI40MHZ) &&
|
|
|
|
!(hw & HT_CAP_INFO_SHORT_GI40MHZ)) {
|
|
|
|
wpa_printf(MSG_ERROR, "Driver does not support configured "
|
|
|
|
"HT capability [SHORT-GI-40]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf & HT_CAP_INFO_TX_STBC) && !(hw & HT_CAP_INFO_TX_STBC)) {
|
|
|
|
wpa_printf(MSG_ERROR, "Driver does not support configured "
|
|
|
|
"HT capability [TX-STBC]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf & HT_CAP_INFO_RX_STBC_MASK) >
|
|
|
|
(hw & HT_CAP_INFO_RX_STBC_MASK)) {
|
|
|
|
wpa_printf(MSG_ERROR, "Driver does not support configured "
|
|
|
|
"HT capability [RX-STBC*]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf & HT_CAP_INFO_DELAYED_BA) &&
|
|
|
|
!(hw & HT_CAP_INFO_DELAYED_BA)) {
|
|
|
|
wpa_printf(MSG_ERROR, "Driver does not support configured "
|
|
|
|
"HT capability [DELAYED-BA]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf & HT_CAP_INFO_MAX_AMSDU_SIZE) &&
|
|
|
|
!(hw & HT_CAP_INFO_MAX_AMSDU_SIZE)) {
|
|
|
|
wpa_printf(MSG_ERROR, "Driver does not support configured "
|
|
|
|
"HT capability [MAX-AMSDU-7935]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf & HT_CAP_INFO_DSSS_CCK40MHZ) &&
|
|
|
|
!(hw & HT_CAP_INFO_DSSS_CCK40MHZ)) {
|
|
|
|
wpa_printf(MSG_ERROR, "Driver does not support configured "
|
|
|
|
"HT capability [DSSS_CCK-40]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((conf & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT) &&
|
|
|
|
!(hw & HT_CAP_INFO_LSIG_TXOP_PROTECT_SUPPORT)) {
|
|
|
|
wpa_printf(MSG_ERROR, "Driver does not support configured "
|
|
|
|
"HT capability [LSIG-TXOP-PROT]");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
2009-04-16 09:22:40 -04:00
|
|
|
|
2013-10-27 13:11:29 -04:00
|
|
|
|
|
|
|
#ifdef CONFIG_IEEE80211AC
|
|
|
|
|
|
|
|
static int ieee80211ac_cap_check(u32 hw, u32 conf, u32 cap, const char *name)
|
|
|
|
{
|
|
|
|
u32 req_cap = conf & cap;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure we support all requested capabilities.
|
|
|
|
* NOTE: We assume that 'cap' represents a capability mask,
|
|
|
|
* not a discrete value.
|
|
|
|
*/
|
|
|
|
if ((hw & req_cap) != req_cap) {
|
|
|
|
wpa_printf(MSG_ERROR, "Driver does not support configured VHT capability [%s]",
|
|
|
|
name);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-14 12:00:38 -05:00
|
|
|
static int ieee80211ac_cap_check_max(u32 hw, u32 conf, u32 mask,
|
|
|
|
unsigned int shift,
|
2013-10-27 13:11:29 -04:00
|
|
|
const char *name)
|
|
|
|
{
|
2014-12-14 12:00:38 -05:00
|
|
|
u32 hw_max = hw & mask;
|
|
|
|
u32 conf_val = conf & mask;
|
2013-10-27 13:11:29 -04:00
|
|
|
|
|
|
|
if (conf_val > hw_max) {
|
|
|
|
wpa_printf(MSG_ERROR, "Configured VHT capability [%s] exceeds max value supported by the driver (%d > %d)",
|
2014-12-14 12:00:38 -05:00
|
|
|
name, conf_val >> shift, hw_max >> shift);
|
2013-10-27 13:11:29 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int ieee80211ac_supported_vht_capab(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
u32 hw = iface->current_mode->vht_capab;
|
|
|
|
u32 conf = iface->conf->vht_capab;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "hw vht capab: 0x%x, conf vht capab: 0x%x",
|
|
|
|
hw, conf);
|
|
|
|
|
|
|
|
#define VHT_CAP_CHECK(cap) \
|
|
|
|
do { \
|
|
|
|
if (!ieee80211ac_cap_check(hw, conf, cap, #cap)) \
|
|
|
|
return 0; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define VHT_CAP_CHECK_MAX(cap) \
|
|
|
|
do { \
|
2014-12-14 12:00:38 -05:00
|
|
|
if (!ieee80211ac_cap_check_max(hw, conf, cap, cap ## _SHIFT, \
|
|
|
|
#cap)) \
|
2013-10-27 13:11:29 -04:00
|
|
|
return 0; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
VHT_CAP_CHECK_MAX(VHT_CAP_MAX_MPDU_LENGTH_MASK);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160MHZ);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_RXLDPC);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_SHORT_GI_80);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_SHORT_GI_160);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_TXSTBC);
|
|
|
|
VHT_CAP_CHECK_MAX(VHT_CAP_RXSTBC_MASK);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMER_CAPABLE);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_SU_BEAMFORMEE_CAPABLE);
|
|
|
|
VHT_CAP_CHECK_MAX(VHT_CAP_BEAMFORMEE_STS_MAX);
|
|
|
|
VHT_CAP_CHECK_MAX(VHT_CAP_SOUNDING_DIMENSION_MAX);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMER_CAPABLE);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_MU_BEAMFORMEE_CAPABLE);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_VHT_TXOP_PS);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_HTC_VHT);
|
2014-02-26 04:39:47 -05:00
|
|
|
VHT_CAP_CHECK_MAX(VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MAX);
|
2013-10-27 13:11:29 -04:00
|
|
|
VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_UNSOL_MFB);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_VHT_LINK_ADAPTATION_VHT_MRQ_MFB);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_RX_ANTENNA_PATTERN);
|
|
|
|
VHT_CAP_CHECK(VHT_CAP_TX_ANTENNA_PATTERN);
|
|
|
|
|
|
|
|
#undef VHT_CAP_CHECK
|
|
|
|
#undef VHT_CAP_CHECK_MAX
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_IEEE80211AC */
|
|
|
|
|
2009-04-16 09:22:40 -04:00
|
|
|
#endif /* CONFIG_IEEE80211N */
|
|
|
|
|
|
|
|
|
|
|
|
int hostapd_check_ht_capab(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_IEEE80211N
|
|
|
|
int ret;
|
2011-03-16 05:22:40 -04:00
|
|
|
if (!iface->conf->ieee80211n)
|
|
|
|
return 0;
|
2011-02-01 09:04:59 -05:00
|
|
|
if (!ieee80211n_supported_ht_capab(iface))
|
|
|
|
return -1;
|
2013-10-27 13:11:29 -04:00
|
|
|
#ifdef CONFIG_IEEE80211AC
|
|
|
|
if (!ieee80211ac_supported_vht_capab(iface))
|
|
|
|
return -1;
|
|
|
|
#endif /* CONFIG_IEEE80211AC */
|
2009-04-16 09:22:40 -04:00
|
|
|
ret = ieee80211n_check_40mhz(iface);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
if (!ieee80211n_allowed_ht40_channel_pair(iface))
|
|
|
|
return -1;
|
2008-11-25 05:51:03 -05:00
|
|
|
#endif /* CONFIG_IEEE80211N */
|
|
|
|
|
2009-04-16 09:22:40 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-11-25 05:51:03 -05:00
|
|
|
|
2013-07-18 03:17:06 -04:00
|
|
|
static int hostapd_is_usable_chan(struct hostapd_iface *iface,
|
|
|
|
int channel, int primary)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct hostapd_channel_data *chan;
|
|
|
|
|
|
|
|
for (i = 0; i < iface->current_mode->num_channels; i++) {
|
|
|
|
chan = &iface->current_mode->channels[i];
|
|
|
|
if (chan->chan != channel)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!(chan->flag & HOSTAPD_CHAN_DISABLED))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG,
|
2014-07-07 07:20:54 -04:00
|
|
|
"%schannel [%i] (%i) is disabled for use in AP mode, flags: 0x%x%s%s",
|
2013-07-18 03:17:06 -04:00
|
|
|
primary ? "" : "Configured HT40 secondary ",
|
|
|
|
i, chan->chan, chan->flag,
|
2014-07-07 07:20:54 -04:00
|
|
|
chan->flag & HOSTAPD_CHAN_NO_IR ? " NO-IR" : "",
|
2013-07-18 03:17:06 -04:00
|
|
|
chan->flag & HOSTAPD_CHAN_RADAR ? " RADAR" : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int hostapd_is_usable_chans(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
if (!hostapd_is_usable_chan(iface, iface->conf->channel, 1))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!iface->conf->secondary_channel)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return hostapd_is_usable_chan(iface, iface->conf->channel +
|
|
|
|
iface->conf->secondary_channel * 4, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static enum hostapd_chan_status
|
|
|
|
hostapd_check_chans(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
if (iface->conf->channel) {
|
|
|
|
if (hostapd_is_usable_chans(iface))
|
|
|
|
return HOSTAPD_CHAN_VALID;
|
|
|
|
else
|
|
|
|
return HOSTAPD_CHAN_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-08-31 04:49:51 -04:00
|
|
|
* The user set channel=0 or channel=acs_survey
|
|
|
|
* which is used to trigger ACS.
|
2013-07-18 03:17:06 -04:00
|
|
|
*/
|
2013-08-31 04:49:51 -04:00
|
|
|
|
|
|
|
switch (acs_init(iface)) {
|
|
|
|
case HOSTAPD_CHAN_ACS:
|
|
|
|
return HOSTAPD_CHAN_ACS;
|
|
|
|
case HOSTAPD_CHAN_VALID:
|
|
|
|
case HOSTAPD_CHAN_INVALID:
|
|
|
|
default:
|
|
|
|
return HOSTAPD_CHAN_INVALID;
|
|
|
|
}
|
2013-07-18 03:17:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void hostapd_notify_bad_chans(struct hostapd_iface *iface)
|
|
|
|
{
|
|
|
|
hostapd_logger(iface->bss[0], NULL,
|
|
|
|
HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_WARNING,
|
|
|
|
"Configured channel (%d) not found from the "
|
|
|
|
"channel list of current mode (%d) %s",
|
|
|
|
iface->conf->channel,
|
|
|
|
iface->current_mode->mode,
|
|
|
|
hostapd_hw_mode_txt(iface->current_mode->mode));
|
|
|
|
hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_WARNING,
|
|
|
|
"Hardware does not support configured channel");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-22 17:18:41 -04:00
|
|
|
int hostapd_acs_completed(struct hostapd_iface *iface, int err)
|
2013-08-31 04:49:51 -04:00
|
|
|
{
|
2013-10-22 17:15:57 -04:00
|
|
|
int ret = -1;
|
2013-08-31 04:49:51 -04:00
|
|
|
|
2013-10-22 17:18:41 -04:00
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
2013-08-31 04:49:51 -04:00
|
|
|
switch (hostapd_check_chans(iface)) {
|
|
|
|
case HOSTAPD_CHAN_VALID:
|
2013-11-03 08:59:53 -05:00
|
|
|
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);
|
2013-08-31 04:49:51 -04:00
|
|
|
break;
|
|
|
|
case HOSTAPD_CHAN_ACS:
|
|
|
|
wpa_printf(MSG_ERROR, "ACS error - reported complete, but no result available");
|
2013-11-03 08:59:53 -05:00
|
|
|
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
|
2013-08-31 04:49:51 -04:00
|
|
|
hostapd_notify_bad_chans(iface);
|
2013-10-22 17:15:57 -04:00
|
|
|
goto out;
|
2013-08-31 04:49:51 -04:00
|
|
|
case HOSTAPD_CHAN_INVALID:
|
|
|
|
default:
|
|
|
|
wpa_printf(MSG_ERROR, "ACS picked unusable channels");
|
2013-11-03 08:59:53 -05:00
|
|
|
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, ACS_EVENT_FAILED);
|
2013-08-31 04:49:51 -04:00
|
|
|
hostapd_notify_bad_chans(iface);
|
2013-10-22 17:15:57 -04:00
|
|
|
goto out;
|
2013-08-31 04:49:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = hostapd_check_ht_capab(iface);
|
|
|
|
if (ret < 0)
|
2013-10-22 17:15:57 -04:00
|
|
|
goto out;
|
2013-08-31 04:49:51 -04:00
|
|
|
if (ret == 1) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Interface initialization will be completed in a callback");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-22 17:15:57 -04:00
|
|
|
ret = 0;
|
|
|
|
out:
|
|
|
|
return hostapd_setup_interface_complete(iface, ret);
|
2013-08-31 04:49:51 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:34:43 -05:00
|
|
|
/**
|
2008-11-21 13:39:33 -05:00
|
|
|
* hostapd_select_hw_mode - Select the hardware mode
|
2008-02-27 20:34:43 -05:00
|
|
|
* @iface: Pointer to interface data.
|
2011-05-16 15:01:11 -04:00
|
|
|
* Returns: 0 on success, < 0 on failure
|
2008-02-27 20:34:43 -05:00
|
|
|
*
|
2008-11-21 13:39:33 -05:00
|
|
|
* Sets up the hardware mode, channel, rates, and passive scanning
|
|
|
|
* based on the configuration.
|
2008-02-27 20:34:43 -05:00
|
|
|
*/
|
2008-11-21 13:39:33 -05:00
|
|
|
int hostapd_select_hw_mode(struct hostapd_iface *iface)
|
2008-02-27 20:34:43 -05:00
|
|
|
{
|
2013-07-18 03:17:06 -04:00
|
|
|
int i;
|
2008-02-27 20:34:43 -05:00
|
|
|
|
|
|
|
if (iface->num_hw_features < 1)
|
|
|
|
return -1;
|
|
|
|
|
2014-02-25 06:52:26 -05:00
|
|
|
if ((iface->conf->hw_mode == HOSTAPD_MODE_IEEE80211G ||
|
|
|
|
iface->conf->ieee80211n || iface->conf->ieee80211ac) &&
|
|
|
|
iface->conf->channel == 14) {
|
|
|
|
wpa_printf(MSG_INFO, "Disable OFDM/HT/VHT on channel 14");
|
|
|
|
iface->conf->hw_mode = HOSTAPD_MODE_IEEE80211B;
|
|
|
|
iface->conf->ieee80211n = 0;
|
|
|
|
iface->conf->ieee80211ac = 0;
|
|
|
|
}
|
|
|
|
|
2008-02-27 20:34:43 -05:00
|
|
|
iface->current_mode = NULL;
|
|
|
|
for (i = 0; i < iface->num_hw_features; i++) {
|
|
|
|
struct hostapd_hw_modes *mode = &iface->hw_features[i];
|
2009-04-03 12:04:20 -04:00
|
|
|
if (mode->mode == iface->conf->hw_mode) {
|
2008-02-27 20:34:43 -05:00
|
|
|
iface->current_mode = mode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iface->current_mode == NULL) {
|
|
|
|
wpa_printf(MSG_ERROR, "Hardware does not support configured "
|
|
|
|
"mode");
|
|
|
|
hostapd_logger(iface->bss[0], NULL, HOSTAPD_MODULE_IEEE80211,
|
|
|
|
HOSTAPD_LEVEL_WARNING,
|
|
|
|
"Hardware does not support configured mode "
|
2011-07-30 17:51:34 -04:00
|
|
|
"(%d) (hw_mode in hostapd.conf)",
|
|
|
|
(int) iface->conf->hw_mode);
|
2011-05-16 15:01:11 -04:00
|
|
|
return -2;
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
|
|
|
|
2013-07-18 03:17:06 -04:00
|
|
|
switch (hostapd_check_chans(iface)) {
|
|
|
|
case HOSTAPD_CHAN_VALID:
|
|
|
|
return 0;
|
2013-08-31 04:49:51 -04:00
|
|
|
case HOSTAPD_CHAN_ACS: /* ACS will run and later complete */
|
|
|
|
return 1;
|
2013-07-18 03:17:06 -04:00
|
|
|
case HOSTAPD_CHAN_INVALID:
|
|
|
|
default:
|
|
|
|
hostapd_notify_bad_chans(iface);
|
2011-05-16 15:01:11 -04:00
|
|
|
return -3;
|
2009-05-06 09:07:43 -04:00
|
|
|
}
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char * hostapd_hw_mode_txt(int mode)
|
|
|
|
{
|
|
|
|
switch (mode) {
|
|
|
|
case HOSTAPD_MODE_IEEE80211A:
|
|
|
|
return "IEEE 802.11a";
|
|
|
|
case HOSTAPD_MODE_IEEE80211B:
|
|
|
|
return "IEEE 802.11b";
|
|
|
|
case HOSTAPD_MODE_IEEE80211G:
|
|
|
|
return "IEEE 802.11g";
|
2012-12-18 04:50:35 -05:00
|
|
|
case HOSTAPD_MODE_IEEE80211AD:
|
|
|
|
return "IEEE 802.11ad";
|
2008-02-27 20:34:43 -05:00
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int hostapd_hw_get_freq(struct hostapd_data *hapd, int chan)
|
|
|
|
{
|
2015-01-08 06:48:30 -05:00
|
|
|
return hw_get_freq(hapd->iface->current_mode, chan);
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int hostapd_hw_get_channel(struct hostapd_data *hapd, int freq)
|
|
|
|
{
|
2015-01-08 06:48:30 -05:00
|
|
|
return hw_get_chan(hapd->iface->current_mode, freq);
|
2008-02-27 20:34:43 -05:00
|
|
|
}
|