2013-10-15 19:27:25 +02:00
|
|
|
/*
|
|
|
|
* DFS - Dynamic Frequency Selection
|
|
|
|
* Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
|
2013-10-16 11:18:52 +02:00
|
|
|
* Copyright (c) 2013, Qualcomm Atheros, Inc.
|
2013-10-15 19:27:25 +02:00
|
|
|
*
|
|
|
|
* This software may be distributed under the terms of the BSD license.
|
|
|
|
* See README for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "utils/includes.h"
|
|
|
|
|
|
|
|
#include "utils/common.h"
|
|
|
|
#include "common/ieee802_11_defs.h"
|
2013-11-02 20:01:47 +01:00
|
|
|
#include "common/wpa_ctrl.h"
|
2013-10-15 19:27:25 +02:00
|
|
|
#include "hostapd.h"
|
|
|
|
#include "ap_drv_ops.h"
|
|
|
|
#include "drivers/driver.h"
|
|
|
|
#include "dfs.h"
|
|
|
|
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
static int dfs_get_used_n_chans(struct hostapd_iface *iface)
|
2013-10-16 11:18:52 +02:00
|
|
|
{
|
|
|
|
int n_chans = 1;
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
if (iface->conf->ieee80211n && iface->conf->secondary_channel)
|
2013-10-16 11:18:52 +02:00
|
|
|
n_chans = 2;
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
if (iface->conf->ieee80211ac) {
|
|
|
|
switch (iface->conf->vht_oper_chwidth) {
|
2013-10-16 11:18:52 +02:00
|
|
|
case VHT_CHANWIDTH_USE_HT:
|
|
|
|
break;
|
|
|
|
case VHT_CHANWIDTH_80MHZ:
|
|
|
|
n_chans = 4;
|
|
|
|
break;
|
2013-10-16 17:42:57 +02:00
|
|
|
case VHT_CHANWIDTH_160MHZ:
|
|
|
|
n_chans = 8;
|
|
|
|
break;
|
2013-10-16 11:18:52 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return n_chans;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-25 20:16:13 +01:00
|
|
|
static int dfs_channel_available(struct hostapd_channel_data *chan,
|
|
|
|
int skip_radar)
|
2013-10-16 11:18:52 +02:00
|
|
|
{
|
2013-11-25 20:16:13 +01:00
|
|
|
/*
|
|
|
|
* When radar detection happens, CSA is performed. However, there's no
|
|
|
|
* time for CAC, so radar channels must be skipped when finding a new
|
|
|
|
* channel for CSA.
|
|
|
|
*/
|
|
|
|
if (skip_radar && chan->flag & HOSTAPD_CHAN_RADAR)
|
|
|
|
return 0;
|
|
|
|
|
2013-10-16 11:18:52 +02:00
|
|
|
if (chan->flag & HOSTAPD_CHAN_DISABLED)
|
|
|
|
return 0;
|
|
|
|
if ((chan->flag & HOSTAPD_CHAN_RADAR) &&
|
|
|
|
((chan->flag & HOSTAPD_CHAN_DFS_MASK) ==
|
|
|
|
HOSTAPD_CHAN_DFS_UNAVAILABLE))
|
|
|
|
return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-26 15:25:41 +02:00
|
|
|
static int dfs_is_chan_allowed(struct hostapd_channel_data *chan, int n_chans)
|
2013-10-16 11:18:52 +02:00
|
|
|
{
|
2013-10-26 15:25:41 +02:00
|
|
|
/*
|
|
|
|
* The tables contain first valid channel number based on channel width.
|
|
|
|
* We will also choose this first channel as the control one.
|
|
|
|
*/
|
|
|
|
int allowed_40[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157,
|
|
|
|
184, 192 };
|
|
|
|
/*
|
|
|
|
* VHT80, valid channels based on center frequency:
|
|
|
|
* 42, 58, 106, 122, 138, 155
|
|
|
|
*/
|
|
|
|
int allowed_80[] = { 36, 52, 100, 116, 132, 149 };
|
|
|
|
int *allowed = allowed_40;
|
|
|
|
unsigned int i, allowed_no = 0;
|
|
|
|
|
|
|
|
switch (n_chans) {
|
|
|
|
case 2:
|
|
|
|
allowed = allowed_40;
|
2013-10-26 16:00:57 +02:00
|
|
|
allowed_no = ARRAY_SIZE(allowed_40);
|
2013-10-26 15:25:41 +02:00
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
allowed = allowed_80;
|
2013-10-26 16:00:57 +02:00
|
|
|
allowed_no = ARRAY_SIZE(allowed_80);
|
2013-10-26 15:25:41 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wpa_printf(MSG_DEBUG, "Unknown width for %d channels", n_chans);
|
|
|
|
break;
|
|
|
|
}
|
2013-10-16 11:18:52 +02:00
|
|
|
|
2013-10-26 15:25:41 +02:00
|
|
|
for (i = 0; i < allowed_no; i++) {
|
2013-10-16 11:18:52 +02:00
|
|
|
if (chan->chan == allowed[i])
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-31 13:48:34 +01:00
|
|
|
static int dfs_chan_range_available(struct hostapd_hw_modes *mode,
|
2013-11-25 20:16:13 +01:00
|
|
|
int first_chan_idx, int num_chans,
|
|
|
|
int skip_radar)
|
2013-10-31 13:48:34 +01:00
|
|
|
{
|
|
|
|
struct hostapd_channel_data *first_chan, *chan;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (first_chan_idx + num_chans >= mode->num_channels)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
first_chan = &mode->channels[first_chan_idx];
|
|
|
|
|
|
|
|
for (i = 0; i < num_chans; i++) {
|
|
|
|
chan = &mode->channels[first_chan_idx + i];
|
|
|
|
|
|
|
|
if (first_chan->freq + i * 20 != chan->freq)
|
|
|
|
return 0;
|
|
|
|
|
2013-11-25 20:16:13 +01:00
|
|
|
if (!dfs_channel_available(chan, skip_radar))
|
2013-10-31 13:48:34 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-31 13:46:09 +01:00
|
|
|
/*
|
|
|
|
* The function assumes HT40+ operation.
|
|
|
|
* Make sure to adjust the following variables after calling this:
|
|
|
|
* - hapd->secondary_channel
|
|
|
|
* - hapd->vht_oper_centr_freq_seg0_idx
|
|
|
|
* - hapd->vht_oper_centr_freq_seg1_idx
|
|
|
|
*/
|
2013-11-03 17:48:03 +01:00
|
|
|
static int dfs_find_channel(struct hostapd_iface *iface,
|
2013-10-16 13:15:06 +02:00
|
|
|
struct hostapd_channel_data **ret_chan,
|
2013-11-25 20:16:13 +01:00
|
|
|
int idx, int skip_radar)
|
2013-10-15 19:27:25 +02:00
|
|
|
{
|
|
|
|
struct hostapd_hw_modes *mode;
|
2013-10-31 13:48:34 +01:00
|
|
|
struct hostapd_channel_data *chan;
|
|
|
|
int i, channel_idx = 0, n_chans;
|
2013-10-15 19:27:25 +02:00
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
mode = iface->current_mode;
|
|
|
|
n_chans = dfs_get_used_n_chans(iface);
|
2013-10-15 19:27:25 +02:00
|
|
|
|
2013-10-16 11:18:52 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "DFS new chan checking %d channels", n_chans);
|
2013-10-15 19:27:25 +02:00
|
|
|
for (i = 0; i < mode->num_channels; i++) {
|
|
|
|
chan = &mode->channels[i];
|
|
|
|
|
2013-10-31 13:48:34 +01:00
|
|
|
/* Skip HT40/VHT incompatible channels */
|
2013-11-03 17:48:03 +01:00
|
|
|
if (iface->conf->ieee80211n &&
|
|
|
|
iface->conf->secondary_channel &&
|
2013-10-31 13:48:34 +01:00
|
|
|
!dfs_is_chan_allowed(chan, n_chans))
|
2013-10-15 19:27:25 +02:00
|
|
|
continue;
|
|
|
|
|
2013-10-31 13:48:34 +01:00
|
|
|
/* Skip incompatible chandefs */
|
2013-11-25 20:16:13 +01:00
|
|
|
if (!dfs_chan_range_available(mode, i, n_chans, skip_radar))
|
2013-10-31 13:48:34 +01:00
|
|
|
continue;
|
2013-10-15 19:27:25 +02:00
|
|
|
|
|
|
|
if (ret_chan && idx == channel_idx) {
|
|
|
|
wpa_printf(MSG_DEBUG, "Selected ch. #%d", chan->chan);
|
|
|
|
*ret_chan = chan;
|
|
|
|
return idx;
|
|
|
|
}
|
2013-10-16 11:18:52 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "Adding channel: %d", chan->chan);
|
2013-10-15 19:27:25 +02:00
|
|
|
channel_idx++;
|
|
|
|
}
|
|
|
|
return channel_idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
static void dfs_adjust_vht_center_freq(struct hostapd_iface *iface,
|
2013-10-31 13:46:09 +01:00
|
|
|
struct hostapd_channel_data *chan,
|
|
|
|
u8 *vht_oper_centr_freq_seg0_idx,
|
|
|
|
u8 *vht_oper_centr_freq_seg1_idx)
|
2013-10-16 11:18:52 +02:00
|
|
|
{
|
2013-11-03 17:48:03 +01:00
|
|
|
if (!iface->conf->ieee80211ac)
|
2013-10-16 11:18:52 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (!chan)
|
|
|
|
return;
|
|
|
|
|
2013-10-31 13:46:09 +01:00
|
|
|
*vht_oper_centr_freq_seg1_idx = 0;
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
switch (iface->conf->vht_oper_chwidth) {
|
2013-10-16 11:18:52 +02:00
|
|
|
case VHT_CHANWIDTH_USE_HT:
|
2013-11-03 17:48:03 +01:00
|
|
|
if (iface->conf->secondary_channel == 1)
|
2013-10-31 13:46:09 +01:00
|
|
|
*vht_oper_centr_freq_seg0_idx = chan->chan + 2;
|
2013-11-03 17:48:03 +01:00
|
|
|
else if (iface->conf->secondary_channel == -1)
|
2013-10-31 13:46:09 +01:00
|
|
|
*vht_oper_centr_freq_seg0_idx = chan->chan - 2;
|
2013-10-26 15:28:45 +02:00
|
|
|
else
|
2013-10-31 13:46:09 +01:00
|
|
|
*vht_oper_centr_freq_seg0_idx = chan->chan;
|
2013-10-16 11:18:52 +02:00
|
|
|
break;
|
|
|
|
case VHT_CHANWIDTH_80MHZ:
|
2013-10-31 13:46:09 +01:00
|
|
|
*vht_oper_centr_freq_seg0_idx = chan->chan + 6;
|
2013-10-16 11:18:52 +02:00
|
|
|
break;
|
2013-10-16 17:42:57 +02:00
|
|
|
case VHT_CHANWIDTH_160MHZ:
|
2013-10-31 13:46:09 +01:00
|
|
|
*vht_oper_centr_freq_seg0_idx = chan->chan + 14;
|
2013-10-26 10:49:46 +02:00
|
|
|
break;
|
2013-10-16 11:18:52 +02:00
|
|
|
default:
|
2013-10-16 17:42:57 +02:00
|
|
|
wpa_printf(MSG_INFO, "DFS only VHT20/40/80/160 is supported now");
|
2013-10-16 11:18:52 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-10-31 13:46:09 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "DFS adjusting VHT center frequency: %d, %d",
|
|
|
|
*vht_oper_centr_freq_seg0_idx,
|
|
|
|
*vht_oper_centr_freq_seg1_idx);
|
2013-10-16 11:18:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Return start channel idx we will use for mode->channels[idx] */
|
2013-11-03 17:48:03 +01:00
|
|
|
static int dfs_get_start_chan_idx(struct hostapd_iface *iface)
|
2013-10-16 11:18:52 +02:00
|
|
|
{
|
|
|
|
struct hostapd_hw_modes *mode;
|
|
|
|
struct hostapd_channel_data *chan;
|
2013-11-03 17:48:03 +01:00
|
|
|
int channel_no = iface->conf->channel;
|
2013-10-16 11:18:52 +02:00
|
|
|
int res = -1, i;
|
|
|
|
|
|
|
|
/* HT40- */
|
2013-11-03 17:48:03 +01:00
|
|
|
if (iface->conf->ieee80211n && iface->conf->secondary_channel == -1)
|
2013-10-16 11:18:52 +02:00
|
|
|
channel_no -= 4;
|
|
|
|
|
|
|
|
/* VHT */
|
2013-11-03 17:48:03 +01:00
|
|
|
if (iface->conf->ieee80211ac) {
|
|
|
|
switch (iface->conf->vht_oper_chwidth) {
|
2013-10-16 11:18:52 +02:00
|
|
|
case VHT_CHANWIDTH_USE_HT:
|
|
|
|
break;
|
|
|
|
case VHT_CHANWIDTH_80MHZ:
|
|
|
|
channel_no =
|
2013-11-03 17:48:03 +01:00
|
|
|
iface->conf->vht_oper_centr_freq_seg0_idx - 6;
|
2013-10-16 11:18:52 +02:00
|
|
|
break;
|
2013-10-16 17:42:57 +02:00
|
|
|
case VHT_CHANWIDTH_160MHZ:
|
|
|
|
channel_no =
|
2013-11-03 17:48:03 +01:00
|
|
|
iface->conf->vht_oper_centr_freq_seg0_idx - 14;
|
2013-10-16 17:42:57 +02:00
|
|
|
break;
|
2013-10-16 11:18:52 +02:00
|
|
|
default:
|
|
|
|
wpa_printf(MSG_INFO,
|
2013-10-16 17:42:57 +02:00
|
|
|
"DFS only VHT20/40/80/160 is supported now");
|
2013-10-16 11:18:52 +02:00
|
|
|
channel_no = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get idx */
|
2013-11-03 17:48:03 +01:00
|
|
|
mode = iface->current_mode;
|
2013-10-16 11:18:52 +02:00
|
|
|
for (i = 0; i < mode->num_channels; i++) {
|
|
|
|
chan = &mode->channels[i];
|
|
|
|
if (chan->chan == channel_no) {
|
|
|
|
res = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (res == -1)
|
|
|
|
wpa_printf(MSG_DEBUG, "DFS chan_idx seems wrong: -1");
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* At least one channel have radar flag */
|
2013-11-03 17:48:03 +01:00
|
|
|
static int dfs_check_chans_radar(struct hostapd_iface *iface,
|
|
|
|
int start_chan_idx, int n_chans)
|
2013-10-16 11:18:52 +02:00
|
|
|
{
|
|
|
|
struct hostapd_channel_data *channel;
|
|
|
|
struct hostapd_hw_modes *mode;
|
|
|
|
int i, res = 0;
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
mode = iface->current_mode;
|
2013-10-16 11:18:52 +02:00
|
|
|
|
|
|
|
for (i = 0; i < n_chans; i++) {
|
|
|
|
channel = &mode->channels[start_chan_idx + i];
|
|
|
|
if (channel->flag & HOSTAPD_CHAN_RADAR)
|
|
|
|
res++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* All channels available */
|
2013-11-03 17:48:03 +01:00
|
|
|
static int dfs_check_chans_available(struct hostapd_iface *iface,
|
2013-10-16 11:18:52 +02:00
|
|
|
int start_chan_idx, int n_chans)
|
|
|
|
{
|
|
|
|
struct hostapd_channel_data *channel;
|
|
|
|
struct hostapd_hw_modes *mode;
|
|
|
|
int i;
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
mode = iface->current_mode;
|
2013-10-16 11:18:52 +02:00
|
|
|
|
|
|
|
for(i = 0; i < n_chans; i++) {
|
|
|
|
channel = &mode->channels[start_chan_idx + i];
|
|
|
|
if ((channel->flag & HOSTAPD_CHAN_DFS_MASK) !=
|
|
|
|
HOSTAPD_CHAN_DFS_AVAILABLE)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return i == n_chans;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* At least one channel unavailable */
|
2013-11-03 17:48:03 +01:00
|
|
|
static int dfs_check_chans_unavailable(struct hostapd_iface *iface,
|
2013-10-16 11:18:52 +02:00
|
|
|
int start_chan_idx,
|
|
|
|
int n_chans)
|
|
|
|
{
|
|
|
|
struct hostapd_channel_data *channel;
|
|
|
|
struct hostapd_hw_modes *mode;
|
|
|
|
int i, res = 0;
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
mode = iface->current_mode;
|
2013-10-16 11:18:52 +02:00
|
|
|
|
|
|
|
for(i = 0; i < n_chans; i++) {
|
|
|
|
channel = &mode->channels[start_chan_idx + i];
|
|
|
|
if (channel->flag & HOSTAPD_CHAN_DISABLED)
|
|
|
|
res++;
|
|
|
|
if ((channel->flag & HOSTAPD_CHAN_DFS_MASK) ==
|
|
|
|
HOSTAPD_CHAN_DFS_UNAVAILABLE)
|
|
|
|
res++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-31 13:46:09 +01:00
|
|
|
static struct hostapd_channel_data *
|
2013-11-03 17:48:03 +01:00
|
|
|
dfs_get_valid_channel(struct hostapd_iface *iface,
|
2013-10-31 13:46:09 +01:00
|
|
|
int *secondary_channel,
|
|
|
|
u8 *vht_oper_centr_freq_seg0_idx,
|
2013-11-25 20:16:13 +01:00
|
|
|
u8 *vht_oper_centr_freq_seg1_idx,
|
|
|
|
int skip_radar)
|
2013-10-15 19:27:25 +02:00
|
|
|
{
|
|
|
|
struct hostapd_hw_modes *mode;
|
|
|
|
struct hostapd_channel_data *chan = NULL;
|
2013-10-31 13:46:09 +01:00
|
|
|
int num_available_chandefs;
|
|
|
|
int chan_idx;
|
2013-10-15 19:27:25 +02:00
|
|
|
u32 _rand;
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "DFS: Selecting random channel");
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
if (iface->current_mode == NULL)
|
2013-10-15 19:27:25 +02:00
|
|
|
return NULL;
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
mode = iface->current_mode;
|
2013-10-15 19:27:25 +02:00
|
|
|
if (mode->mode != HOSTAPD_MODE_IEEE80211A)
|
|
|
|
return NULL;
|
|
|
|
|
2013-10-31 13:46:09 +01:00
|
|
|
/* Get the count first */
|
2013-11-25 20:16:13 +01:00
|
|
|
num_available_chandefs = dfs_find_channel(iface, NULL, 0, skip_radar);
|
2013-10-31 13:46:09 +01:00
|
|
|
if (num_available_chandefs == 0)
|
|
|
|
return NULL;
|
2013-10-15 19:27:25 +02:00
|
|
|
|
2013-10-31 13:46:09 +01:00
|
|
|
os_get_random((u8 *) &_rand, sizeof(_rand));
|
|
|
|
chan_idx = _rand % num_available_chandefs;
|
2013-11-25 20:16:13 +01:00
|
|
|
dfs_find_channel(iface, &chan, chan_idx, skip_radar);
|
2013-10-31 13:46:09 +01:00
|
|
|
|
|
|
|
/* dfs_find_channel() calculations assume HT40+ */
|
2013-11-03 17:48:03 +01:00
|
|
|
if (iface->conf->secondary_channel)
|
2013-10-31 13:46:09 +01:00
|
|
|
*secondary_channel = 1;
|
|
|
|
else
|
|
|
|
*secondary_channel = 0;
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
dfs_adjust_vht_center_freq(iface, chan,
|
2013-10-31 13:46:09 +01:00
|
|
|
vht_oper_centr_freq_seg0_idx,
|
|
|
|
vht_oper_centr_freq_seg1_idx);
|
2013-10-16 11:18:52 +02:00
|
|
|
|
2013-10-15 19:27:25 +02:00
|
|
|
return chan;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
static int set_dfs_state_freq(struct hostapd_iface *iface, int freq, u32 state)
|
2013-10-15 19:27:25 +02:00
|
|
|
{
|
|
|
|
struct hostapd_hw_modes *mode;
|
|
|
|
struct hostapd_channel_data *chan = NULL;
|
|
|
|
int i;
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
mode = iface->current_mode;
|
2013-10-15 19:27:25 +02:00
|
|
|
if (mode == NULL)
|
|
|
|
return 0;
|
|
|
|
|
2013-10-16 11:18:52 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "set_dfs_state 0x%X for %d MHz", state, freq);
|
2013-11-03 17:48:03 +01:00
|
|
|
for (i = 0; i < iface->current_mode->num_channels; i++) {
|
|
|
|
chan = &iface->current_mode->channels[i];
|
2013-10-15 19:27:25 +02:00
|
|
|
if (chan->freq == freq) {
|
|
|
|
if (chan->flag & HOSTAPD_CHAN_RADAR) {
|
|
|
|
chan->flag &= ~HOSTAPD_CHAN_DFS_MASK;
|
|
|
|
chan->flag |= state;
|
|
|
|
return 1; /* Channel found */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
wpa_printf(MSG_WARNING, "Can't set DFS state for freq %d MHz", freq);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
static int set_dfs_state(struct hostapd_iface *iface, int freq, int ht_enabled,
|
2013-10-16 11:18:52 +02:00
|
|
|
int chan_offset, int chan_width, int cf1,
|
|
|
|
int cf2, u32 state)
|
|
|
|
{
|
|
|
|
int n_chans = 1, i;
|
|
|
|
struct hostapd_hw_modes *mode;
|
|
|
|
int frequency = freq;
|
|
|
|
int ret = 0;
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
mode = iface->current_mode;
|
2013-10-16 11:18:52 +02:00
|
|
|
if (mode == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (mode->mode != HOSTAPD_MODE_IEEE80211A) {
|
|
|
|
wpa_printf(MSG_WARNING, "current_mode != IEEE80211A");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Seems cf1 and chan_width is enough here */
|
|
|
|
switch (chan_width) {
|
|
|
|
case CHAN_WIDTH_20_NOHT:
|
|
|
|
case CHAN_WIDTH_20:
|
|
|
|
n_chans = 1;
|
2013-11-03 20:50:48 +01:00
|
|
|
if (frequency == 0)
|
|
|
|
frequency = cf1;
|
2013-10-16 11:18:52 +02:00
|
|
|
break;
|
|
|
|
case CHAN_WIDTH_40:
|
|
|
|
n_chans = 2;
|
|
|
|
frequency = cf1 - 10;
|
|
|
|
break;
|
|
|
|
case CHAN_WIDTH_80:
|
|
|
|
n_chans = 4;
|
|
|
|
frequency = cf1 - 30;
|
|
|
|
break;
|
2013-10-16 17:42:57 +02:00
|
|
|
case CHAN_WIDTH_160:
|
|
|
|
n_chans = 8;
|
|
|
|
frequency = cf1 - 70;
|
|
|
|
break;
|
2013-10-16 11:18:52 +02:00
|
|
|
default:
|
|
|
|
wpa_printf(MSG_INFO, "DFS chan_width %d not supported",
|
|
|
|
chan_width);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "DFS freq: %dMHz, n_chans: %d", frequency,
|
|
|
|
n_chans);
|
|
|
|
for (i = 0; i < n_chans; i++) {
|
2013-11-03 17:48:03 +01:00
|
|
|
ret += set_dfs_state_freq(iface, frequency, state);
|
2013-10-16 11:18:52 +02:00
|
|
|
frequency = frequency + 20;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
static int dfs_are_channels_overlapped(struct hostapd_iface *iface, int freq,
|
2013-10-16 11:18:52 +02:00
|
|
|
int chan_width, int cf1, int cf2)
|
|
|
|
{
|
|
|
|
int start_chan_idx;
|
|
|
|
struct hostapd_hw_modes *mode;
|
|
|
|
struct hostapd_channel_data *chan;
|
|
|
|
int n_chans, i, j, frequency = freq, radar_n_chans = 1;
|
|
|
|
u8 radar_chan;
|
|
|
|
int res = 0;
|
|
|
|
|
|
|
|
/* Our configuration */
|
2013-11-03 17:48:03 +01:00
|
|
|
mode = iface->current_mode;
|
|
|
|
start_chan_idx = dfs_get_start_chan_idx(iface);
|
|
|
|
n_chans = dfs_get_used_n_chans(iface);
|
2013-10-16 11:18:52 +02:00
|
|
|
|
2013-10-26 15:30:42 +02:00
|
|
|
/* Check we are on DFS channel(s) */
|
2013-11-03 17:48:03 +01:00
|
|
|
if (!dfs_check_chans_radar(iface, start_chan_idx, n_chans))
|
2013-10-26 15:30:42 +02:00
|
|
|
return 0;
|
|
|
|
|
2013-10-16 11:18:52 +02:00
|
|
|
/* Reported via radar event */
|
|
|
|
switch (chan_width) {
|
|
|
|
case CHAN_WIDTH_20_NOHT:
|
|
|
|
case CHAN_WIDTH_20:
|
|
|
|
radar_n_chans = 1;
|
2013-11-03 20:50:48 +01:00
|
|
|
if (frequency == 0)
|
|
|
|
frequency = cf1;
|
2013-10-16 11:18:52 +02:00
|
|
|
break;
|
|
|
|
case CHAN_WIDTH_40:
|
|
|
|
radar_n_chans = 2;
|
|
|
|
frequency = cf1 - 10;
|
|
|
|
break;
|
|
|
|
case CHAN_WIDTH_80:
|
|
|
|
radar_n_chans = 4;
|
|
|
|
frequency = cf1 - 30;
|
|
|
|
break;
|
2013-10-16 17:42:57 +02:00
|
|
|
case CHAN_WIDTH_160:
|
|
|
|
radar_n_chans = 8;
|
|
|
|
frequency = cf1 - 70;
|
|
|
|
break;
|
2013-10-16 11:18:52 +02:00
|
|
|
default:
|
|
|
|
wpa_printf(MSG_INFO, "DFS chan_width %d not supported",
|
|
|
|
chan_width);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ieee80211_freq_to_chan(frequency, &radar_chan);
|
|
|
|
|
|
|
|
for (i = 0; i < n_chans; i++) {
|
|
|
|
chan = &mode->channels[start_chan_idx + i];
|
2013-10-26 15:30:42 +02:00
|
|
|
if (!(chan->flag & HOSTAPD_CHAN_RADAR))
|
|
|
|
continue;
|
2013-10-16 11:18:52 +02:00
|
|
|
for (j = 0; j < radar_n_chans; j++) {
|
|
|
|
wpa_printf(MSG_DEBUG, "checking our: %d, radar: %d",
|
|
|
|
chan->chan, radar_chan + j * 4);
|
|
|
|
if (chan->chan == radar_chan + j * 4)
|
|
|
|
res++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "overlapped: %d", res);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-15 19:27:25 +02:00
|
|
|
/*
|
|
|
|
* Main DFS handler
|
|
|
|
* 1 - continue channel/ap setup
|
|
|
|
* 0 - channel/ap setup will be continued after CAC
|
|
|
|
* -1 - hit critical error
|
|
|
|
*/
|
2013-11-03 17:48:03 +01:00
|
|
|
int hostapd_handle_dfs(struct hostapd_iface *iface)
|
2013-10-15 19:27:25 +02:00
|
|
|
{
|
|
|
|
struct hostapd_channel_data *channel;
|
2013-10-16 11:18:52 +02:00
|
|
|
int res, n_chans, start_chan_idx;
|
2013-11-25 20:16:13 +01:00
|
|
|
int skip_radar = 0;
|
2013-10-16 11:18:52 +02:00
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
iface->cac_started = 0;
|
2013-10-31 13:49:38 +01:00
|
|
|
|
2013-10-16 11:18:52 +02:00
|
|
|
do {
|
|
|
|
/* Get start (first) channel for current configuration */
|
2013-11-03 17:48:03 +01:00
|
|
|
start_chan_idx = dfs_get_start_chan_idx(iface);
|
2013-10-16 11:18:52 +02:00
|
|
|
if (start_chan_idx == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Get number of used channels, depend on width */
|
2013-11-03 17:48:03 +01:00
|
|
|
n_chans = dfs_get_used_n_chans(iface);
|
2013-10-16 11:18:52 +02:00
|
|
|
|
|
|
|
/* Check if any of configured channels require DFS */
|
2013-11-03 17:48:03 +01:00
|
|
|
res = dfs_check_chans_radar(iface, start_chan_idx, n_chans);
|
2013-10-16 11:18:52 +02:00
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"DFS %d channels required radar detection",
|
|
|
|
res);
|
|
|
|
if (!res)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Check if all channels are DFS available */
|
2013-11-03 17:48:03 +01:00
|
|
|
res = dfs_check_chans_available(iface, start_chan_idx, n_chans);
|
2013-10-16 11:18:52 +02:00
|
|
|
wpa_printf(MSG_DEBUG,
|
|
|
|
"DFS all channels available, (SKIP CAC): %s",
|
|
|
|
res ? "yes" : "no");
|
|
|
|
if (res)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Check if any of configured channels is unavailable */
|
2013-11-03 17:48:03 +01:00
|
|
|
res = dfs_check_chans_unavailable(iface, start_chan_idx,
|
2013-10-16 11:18:52 +02:00
|
|
|
n_chans);
|
|
|
|
wpa_printf(MSG_DEBUG, "DFS %d chans unavailable - choose other channel: %s",
|
|
|
|
res, res ? "yes": "no");
|
|
|
|
if (res) {
|
2013-10-31 13:46:09 +01:00
|
|
|
int sec;
|
|
|
|
u8 cf1, cf2;
|
|
|
|
|
2013-11-25 20:16:13 +01:00
|
|
|
channel = dfs_get_valid_channel(iface, &sec, &cf1, &cf2,
|
|
|
|
skip_radar);
|
2013-10-15 19:27:25 +02:00
|
|
|
if (!channel) {
|
|
|
|
wpa_printf(MSG_ERROR, "could not get valid channel");
|
|
|
|
return -1;
|
|
|
|
}
|
2013-10-31 13:46:09 +01:00
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
iface->freq = channel->freq;
|
|
|
|
iface->conf->channel = channel->chan;
|
|
|
|
iface->conf->secondary_channel = sec;
|
|
|
|
iface->conf->vht_oper_centr_freq_seg0_idx = cf1;
|
|
|
|
iface->conf->vht_oper_centr_freq_seg1_idx = cf2;
|
2013-10-15 19:27:25 +02:00
|
|
|
}
|
2013-10-16 11:18:52 +02:00
|
|
|
} while (res);
|
|
|
|
|
|
|
|
/* Finally start CAC */
|
2013-11-03 17:48:03 +01:00
|
|
|
hostapd_set_state(iface, HAPD_IFACE_DFS);
|
|
|
|
wpa_printf(MSG_DEBUG, "DFS start CAC on %d MHz", iface->freq);
|
|
|
|
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_CAC_START
|
2013-11-02 20:01:47 +01:00
|
|
|
"freq=%d chan=%d sec_chan=%d",
|
2013-11-03 17:48:03 +01:00
|
|
|
iface->freq,
|
|
|
|
iface->conf->channel, iface->conf->secondary_channel);
|
|
|
|
if (hostapd_start_dfs_cac(iface, iface->conf->hw_mode,
|
|
|
|
iface->freq,
|
|
|
|
iface->conf->channel,
|
|
|
|
iface->conf->ieee80211n,
|
|
|
|
iface->conf->ieee80211ac,
|
|
|
|
iface->conf->secondary_channel,
|
|
|
|
iface->conf->vht_oper_chwidth,
|
|
|
|
iface->conf->vht_oper_centr_freq_seg0_idx,
|
|
|
|
iface->conf->vht_oper_centr_freq_seg1_idx)) {
|
2013-10-16 11:18:52 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "DFS start_dfs_cac() failed");
|
|
|
|
return -1;
|
2013-10-15 19:27:25 +02:00
|
|
|
}
|
|
|
|
|
2013-10-16 11:18:52 +02:00
|
|
|
return 0;
|
2013-10-15 19:27:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
int hostapd_dfs_complete_cac(struct hostapd_iface *iface, int success, int freq,
|
2013-10-16 11:18:52 +02:00
|
|
|
int ht_enabled, int chan_offset, int chan_width,
|
|
|
|
int cf1, int cf2)
|
2013-10-15 19:27:25 +02:00
|
|
|
{
|
2013-11-03 17:48:03 +01:00
|
|
|
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_CAC_COMPLETED
|
2013-11-02 20:01:47 +01:00
|
|
|
"success=%d freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d",
|
|
|
|
success, freq, ht_enabled, chan_offset, chan_width, cf1, cf2);
|
|
|
|
|
2013-10-15 19:27:25 +02:00
|
|
|
if (success) {
|
|
|
|
/* Complete iface/ap configuration */
|
2013-11-03 17:48:03 +01:00
|
|
|
set_dfs_state(iface, freq, ht_enabled, chan_offset,
|
2013-10-16 11:18:52 +02:00
|
|
|
chan_width, cf1, cf2,
|
|
|
|
HOSTAPD_CHAN_DFS_AVAILABLE);
|
2013-11-03 17:48:03 +01:00
|
|
|
iface->cac_started = 0;
|
|
|
|
hostapd_setup_interface_complete(iface, 0);
|
2013-10-15 19:27:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
static int hostapd_dfs_start_channel_switch(struct hostapd_iface *iface)
|
2013-10-15 19:27:25 +02:00
|
|
|
{
|
|
|
|
struct hostapd_channel_data *channel;
|
|
|
|
int err = 1;
|
2013-10-31 13:46:09 +01:00
|
|
|
int secondary_channel;
|
|
|
|
u8 vht_oper_centr_freq_seg0_idx;
|
|
|
|
u8 vht_oper_centr_freq_seg1_idx;
|
2013-11-25 20:16:13 +01:00
|
|
|
int skip_radar = 1;
|
2013-10-15 19:27:25 +02:00
|
|
|
|
|
|
|
wpa_printf(MSG_DEBUG, "%s called", __func__);
|
2013-11-03 17:48:03 +01:00
|
|
|
channel = dfs_get_valid_channel(iface, &secondary_channel,
|
2013-10-31 13:46:09 +01:00
|
|
|
&vht_oper_centr_freq_seg0_idx,
|
2013-11-25 20:16:13 +01:00
|
|
|
&vht_oper_centr_freq_seg1_idx,
|
|
|
|
skip_radar);
|
2013-10-15 19:27:25 +02:00
|
|
|
if (channel) {
|
2013-10-31 13:51:44 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "DFS will switch to a new channel %d",
|
|
|
|
channel->chan);
|
2013-11-03 17:48:03 +01:00
|
|
|
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_NEW_CHANNEL
|
2013-11-02 20:01:47 +01:00
|
|
|
"freq=%d chan=%d sec_chan=%d", channel->freq,
|
|
|
|
channel->chan, secondary_channel);
|
2013-10-31 13:51:44 +01:00
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
iface->freq = channel->freq;
|
|
|
|
iface->conf->channel = channel->chan;
|
|
|
|
iface->conf->secondary_channel = secondary_channel;
|
|
|
|
iface->conf->vht_oper_centr_freq_seg0_idx =
|
|
|
|
vht_oper_centr_freq_seg0_idx;
|
|
|
|
iface->conf->vht_oper_centr_freq_seg1_idx =
|
|
|
|
vht_oper_centr_freq_seg1_idx;
|
2013-10-15 19:27:25 +02:00
|
|
|
err = 0;
|
2013-10-31 13:46:09 +01:00
|
|
|
} else {
|
|
|
|
wpa_printf(MSG_ERROR, "No valid channel available");
|
2013-10-15 19:27:25 +02:00
|
|
|
}
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
if (iface->cac_started) {
|
2013-10-26 15:36:00 +02:00
|
|
|
wpa_printf(MSG_DEBUG, "DFS radar detected during CAC");
|
2013-11-03 17:48:03 +01:00
|
|
|
iface->cac_started = 0;
|
2013-10-31 13:51:44 +01:00
|
|
|
/* FIXME: Wait for channel(s) to become available if no channel
|
|
|
|
* has been found */
|
2013-11-03 17:48:03 +01:00
|
|
|
hostapd_setup_interface_complete(iface, err);
|
2013-10-31 13:51:44 +01:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
/* FIXME: Wait for channel(s) to become available */
|
2013-11-03 17:48:03 +01:00
|
|
|
hostapd_disable_iface(iface);
|
2013-10-31 13:51:44 +01:00
|
|
|
return err;
|
2013-10-26 15:36:00 +02:00
|
|
|
}
|
2013-10-15 19:27:25 +02:00
|
|
|
|
2013-10-31 13:51:44 +01:00
|
|
|
wpa_printf(MSG_DEBUG, "DFS radar detected");
|
2013-11-03 17:48:03 +01:00
|
|
|
hostapd_disable_iface(iface);
|
|
|
|
hostapd_enable_iface(iface);
|
2013-10-15 19:27:25 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-10-16 11:18:52 +02:00
|
|
|
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
int hostapd_dfs_radar_detected(struct hostapd_iface *iface, int freq,
|
2013-10-16 11:18:52 +02:00
|
|
|
int ht_enabled, int chan_offset, int chan_width,
|
|
|
|
int cf1, int cf2)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
if (!iface->conf->ieee80211h)
|
2013-10-16 11:18:52 +02:00
|
|
|
return 0;
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_RADAR_DETECTED
|
2013-11-02 20:01:47 +01:00
|
|
|
"freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d",
|
|
|
|
freq, ht_enabled, chan_offset, chan_width, cf1, cf2);
|
|
|
|
|
2013-10-16 11:18:52 +02:00
|
|
|
/* mark radar frequency as invalid */
|
2013-11-03 17:48:03 +01:00
|
|
|
res = set_dfs_state(iface, freq, ht_enabled, chan_offset,
|
2013-10-16 11:18:52 +02:00
|
|
|
chan_width, cf1, cf2,
|
|
|
|
HOSTAPD_CHAN_DFS_UNAVAILABLE);
|
|
|
|
|
|
|
|
/* Skip if reported radar event not overlapped our channels */
|
2013-11-03 17:48:03 +01:00
|
|
|
res = dfs_are_channels_overlapped(iface, freq, chan_width, cf1, cf2);
|
2013-10-16 11:18:52 +02:00
|
|
|
if (!res)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* radar detected while operating, switch the channel. */
|
2013-11-03 17:48:03 +01:00
|
|
|
res = hostapd_dfs_start_channel_switch(iface);
|
2013-10-16 11:18:52 +02:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-03 17:48:03 +01:00
|
|
|
int hostapd_dfs_nop_finished(struct hostapd_iface *iface, int freq,
|
2013-10-16 11:18:52 +02:00
|
|
|
int ht_enabled, int chan_offset, int chan_width,
|
|
|
|
int cf1, int cf2)
|
|
|
|
{
|
2013-11-03 17:48:03 +01:00
|
|
|
wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_NOP_FINISHED
|
2013-11-02 20:01:47 +01:00
|
|
|
"freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d",
|
|
|
|
freq, ht_enabled, chan_offset, chan_width, cf1, cf2);
|
2013-10-16 11:18:52 +02:00
|
|
|
/* TODO add correct implementation here */
|
2013-11-03 17:48:03 +01:00
|
|
|
set_dfs_state(iface, freq, ht_enabled, chan_offset, chan_width,
|
|
|
|
cf1, cf2, HOSTAPD_CHAN_DFS_USABLE);
|
2013-10-16 11:18:52 +02:00
|
|
|
return 0;
|
|
|
|
}
|