Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * DFS - Dynamic Frequency Selection |
| 3 | * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4 | * Copyright (c) 2013-2017, Qualcomm Atheros, Inc. |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 5 | * |
| 6 | * This software may be distributed under the terms of the BSD license. |
| 7 | * See README for more details. |
| 8 | */ |
| 9 | |
| 10 | #include "utils/includes.h" |
| 11 | |
| 12 | #include "utils/common.h" |
| 13 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 14 | #include "common/hw_features_common.h" |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 15 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 16 | #include "hostapd.h" |
| 17 | #include "ap_drv_ops.h" |
| 18 | #include "drivers/driver.h" |
| 19 | #include "dfs.h" |
| 20 | |
| 21 | |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 22 | enum dfs_channel_type { |
| 23 | DFS_ANY_CHANNEL, |
| 24 | DFS_AVAILABLE, /* non-radar or radar-available */ |
| 25 | DFS_NO_CAC_YET, /* radar-not-yet-available */ |
| 26 | }; |
| 27 | |
| 28 | static struct hostapd_channel_data * |
| 29 | dfs_downgrade_bandwidth(struct hostapd_iface *iface, int *secondary_channel, |
| 30 | u8 *oper_centr_freq_seg0_idx, |
| 31 | u8 *oper_centr_freq_seg1_idx, |
| 32 | enum dfs_channel_type *channel_type); |
| 33 | |
| 34 | |
| 35 | static bool dfs_use_radar_background(struct hostapd_iface *iface) |
| 36 | { |
| 37 | return (iface->drv_flags2 & WPA_DRIVER_RADAR_BACKGROUND) && |
| 38 | iface->conf->enable_background_radar; |
| 39 | } |
| 40 | |
| 41 | |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 42 | static int dfs_get_used_n_chans(struct hostapd_iface *iface, int *seg1) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 43 | { |
| 44 | int n_chans = 1; |
| 45 | |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 46 | *seg1 = 0; |
| 47 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 48 | if (iface->conf->ieee80211n && iface->conf->secondary_channel) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 49 | n_chans = 2; |
| 50 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 51 | if (iface->conf->ieee80211ac || iface->conf->ieee80211ax) { |
| 52 | switch (hostapd_get_oper_chwidth(iface->conf)) { |
| 53 | case CHANWIDTH_USE_HT: |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 54 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 55 | case CHANWIDTH_80MHZ: |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 56 | n_chans = 4; |
| 57 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 58 | case CHANWIDTH_160MHZ: |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 59 | n_chans = 8; |
| 60 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 61 | case CHANWIDTH_80P80MHZ: |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 62 | n_chans = 4; |
| 63 | *seg1 = 4; |
| 64 | break; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 65 | default: |
| 66 | break; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | return n_chans; |
| 71 | } |
| 72 | |
| 73 | |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 74 | /* dfs_channel_available: select new channel according to type parameter */ |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 75 | static int dfs_channel_available(struct hostapd_channel_data *chan, |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 76 | enum dfs_channel_type type) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 77 | { |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 78 | if (type == DFS_NO_CAC_YET) { |
| 79 | /* Select only radar channel where CAC has not been |
| 80 | * performed yet |
| 81 | */ |
| 82 | if ((chan->flag & HOSTAPD_CHAN_RADAR) && |
| 83 | (chan->flag & HOSTAPD_CHAN_DFS_MASK) == |
| 84 | HOSTAPD_CHAN_DFS_USABLE) |
| 85 | return 1; |
| 86 | return 0; |
| 87 | } |
| 88 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 89 | /* |
| 90 | * When radar detection happens, CSA is performed. However, there's no |
| 91 | * time for CAC, so radar channels must be skipped when finding a new |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 92 | * channel for CSA, unless they are available for immediate use. |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 93 | */ |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 94 | if (type == DFS_AVAILABLE && (chan->flag & HOSTAPD_CHAN_RADAR) && |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 95 | ((chan->flag & HOSTAPD_CHAN_DFS_MASK) != |
| 96 | HOSTAPD_CHAN_DFS_AVAILABLE)) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 97 | return 0; |
| 98 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 99 | if (chan->flag & HOSTAPD_CHAN_DISABLED) |
| 100 | return 0; |
| 101 | if ((chan->flag & HOSTAPD_CHAN_RADAR) && |
| 102 | ((chan->flag & HOSTAPD_CHAN_DFS_MASK) == |
| 103 | HOSTAPD_CHAN_DFS_UNAVAILABLE)) |
| 104 | return 0; |
| 105 | return 1; |
| 106 | } |
| 107 | |
| 108 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 109 | static int dfs_is_chan_allowed(struct hostapd_channel_data *chan, int n_chans) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 110 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 111 | /* |
| 112 | * The tables contain first valid channel number based on channel width. |
| 113 | * We will also choose this first channel as the control one. |
| 114 | */ |
| 115 | int allowed_40[] = { 36, 44, 52, 60, 100, 108, 116, 124, 132, 149, 157, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 116 | 165, 173, 184, 192 }; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 117 | /* |
| 118 | * VHT80, valid channels based on center frequency: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 119 | * 42, 58, 106, 122, 138, 155, 171 |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 120 | */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 121 | int allowed_80[] = { 36, 52, 100, 116, 132, 149, 165 }; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 122 | /* |
| 123 | * VHT160 valid channels based on center frequency: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 124 | * 50, 114, 163 |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 125 | */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 126 | int allowed_160[] = { 36, 100, 149 }; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 127 | int *allowed = allowed_40; |
| 128 | unsigned int i, allowed_no = 0; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 129 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 130 | switch (n_chans) { |
| 131 | case 2: |
| 132 | allowed = allowed_40; |
| 133 | allowed_no = ARRAY_SIZE(allowed_40); |
| 134 | break; |
| 135 | case 4: |
| 136 | allowed = allowed_80; |
| 137 | allowed_no = ARRAY_SIZE(allowed_80); |
| 138 | break; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 139 | case 8: |
| 140 | allowed = allowed_160; |
| 141 | allowed_no = ARRAY_SIZE(allowed_160); |
| 142 | break; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 143 | default: |
| 144 | wpa_printf(MSG_DEBUG, "Unknown width for %d channels", n_chans); |
| 145 | break; |
| 146 | } |
| 147 | |
| 148 | for (i = 0; i < allowed_no; i++) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 149 | if (chan->chan == allowed[i]) |
| 150 | return 1; |
| 151 | } |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 157 | static struct hostapd_channel_data * |
| 158 | dfs_get_chan_data(struct hostapd_hw_modes *mode, int freq, int first_chan_idx) |
| 159 | { |
| 160 | int i; |
| 161 | |
| 162 | for (i = first_chan_idx; i < mode->num_channels; i++) { |
| 163 | if (mode->channels[i].freq == freq) |
| 164 | return &mode->channels[i]; |
| 165 | } |
| 166 | |
| 167 | return NULL; |
| 168 | } |
| 169 | |
| 170 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 171 | static int dfs_chan_range_available(struct hostapd_hw_modes *mode, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 172 | int first_chan_idx, int num_chans, |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 173 | enum dfs_channel_type type) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 174 | { |
| 175 | struct hostapd_channel_data *first_chan, *chan; |
| 176 | int i; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 177 | u32 bw = num_chan_to_bw(num_chans); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 178 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 179 | if (first_chan_idx + num_chans > mode->num_channels) { |
| 180 | wpa_printf(MSG_DEBUG, |
| 181 | "DFS: some channels in range not defined"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 182 | return 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 183 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 184 | |
| 185 | first_chan = &mode->channels[first_chan_idx]; |
| 186 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 187 | /* hostapd DFS implementation assumes the first channel as primary. |
| 188 | * If it's not allowed to use the first channel as primary, decline the |
| 189 | * whole channel range. */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 190 | if (!chan_pri_allowed(first_chan)) { |
| 191 | wpa_printf(MSG_DEBUG, "DFS: primary chanenl not allowed"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 192 | return 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 193 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 194 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 195 | for (i = 0; i < num_chans; i++) { |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 196 | chan = dfs_get_chan_data(mode, first_chan->freq + i * 20, |
| 197 | first_chan_idx); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 198 | if (!chan) { |
| 199 | wpa_printf(MSG_DEBUG, "DFS: no channel data for %d", |
| 200 | first_chan->freq + i * 20); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 201 | return 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 202 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 203 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 204 | /* HT 40 MHz secondary channel availability checked only for |
| 205 | * primary channel */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 206 | if (!chan_bw_allowed(chan, bw, 1, !i)) { |
| 207 | wpa_printf(MSG_DEBUG, "DFS: bw now allowed for %d", |
| 208 | first_chan->freq + i * 20); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 209 | return 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 210 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 211 | |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 212 | if (!dfs_channel_available(chan, type)) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 213 | wpa_printf(MSG_DEBUG, "DFS: channel not available %d", |
| 214 | first_chan->freq + i * 20); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 215 | return 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 216 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | return 1; |
| 220 | } |
| 221 | |
| 222 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 223 | static int is_in_chanlist(struct hostapd_iface *iface, |
| 224 | struct hostapd_channel_data *chan) |
| 225 | { |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 226 | if (!iface->conf->acs_ch_list.num) |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 227 | return 1; |
| 228 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 229 | return freq_range_list_includes(&iface->conf->acs_ch_list, chan->chan); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 233 | /* |
| 234 | * The function assumes HT40+ operation. |
| 235 | * Make sure to adjust the following variables after calling this: |
| 236 | * - hapd->secondary_channel |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 237 | * - hapd->vht/he_oper_centr_freq_seg0_idx |
| 238 | * - hapd->vht/he_oper_centr_freq_seg1_idx |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 239 | */ |
| 240 | static int dfs_find_channel(struct hostapd_iface *iface, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 241 | struct hostapd_channel_data **ret_chan, |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 242 | int idx, enum dfs_channel_type type) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 243 | { |
| 244 | struct hostapd_hw_modes *mode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 245 | struct hostapd_channel_data *chan; |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 246 | int i, channel_idx = 0, n_chans, n_chans1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 247 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 248 | mode = iface->current_mode; |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 249 | n_chans = dfs_get_used_n_chans(iface, &n_chans1); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 250 | |
| 251 | wpa_printf(MSG_DEBUG, "DFS new chan checking %d channels", n_chans); |
| 252 | for (i = 0; i < mode->num_channels; i++) { |
| 253 | chan = &mode->channels[i]; |
| 254 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 255 | /* Skip HT40/VHT incompatible channels */ |
| 256 | if (iface->conf->ieee80211n && |
| 257 | iface->conf->secondary_channel && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 258 | (!dfs_is_chan_allowed(chan, n_chans) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 259 | !(chan->allowed_bw & HOSTAPD_CHAN_WIDTH_40P))) { |
| 260 | wpa_printf(MSG_DEBUG, |
| 261 | "DFS: channel %d (%d) is incompatible", |
| 262 | chan->freq, chan->chan); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 263 | continue; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 264 | } |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 265 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 266 | /* Skip incompatible chandefs */ |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 267 | if (!dfs_chan_range_available(mode, i, n_chans, type)) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 268 | wpa_printf(MSG_DEBUG, |
| 269 | "DFS: range not available for %d (%d)", |
| 270 | chan->freq, chan->chan); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 271 | continue; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 272 | } |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 273 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 274 | if (!is_in_chanlist(iface, chan)) { |
| 275 | wpa_printf(MSG_DEBUG, |
| 276 | "DFS: channel %d (%d) not in chanlist", |
| 277 | chan->freq, chan->chan); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 278 | continue; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 279 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 280 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 281 | if (chan->max_tx_power < iface->conf->min_tx_power) |
| 282 | continue; |
| 283 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 284 | if (ret_chan && idx == channel_idx) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 285 | wpa_printf(MSG_DEBUG, "Selected channel %d (%d)", |
| 286 | chan->freq, chan->chan); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 287 | *ret_chan = chan; |
| 288 | return idx; |
| 289 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 290 | wpa_printf(MSG_DEBUG, "Adding channel %d (%d)", |
| 291 | chan->freq, chan->chan); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 292 | channel_idx++; |
| 293 | } |
| 294 | return channel_idx; |
| 295 | } |
| 296 | |
| 297 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 298 | static void dfs_adjust_center_freq(struct hostapd_iface *iface, |
| 299 | struct hostapd_channel_data *chan, |
| 300 | int secondary_channel, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 301 | int sec_chan_idx_80p80, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 302 | u8 *oper_centr_freq_seg0_idx, |
| 303 | u8 *oper_centr_freq_seg1_idx) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 304 | { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 305 | if (!iface->conf->ieee80211ac && !iface->conf->ieee80211ax) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 306 | return; |
| 307 | |
| 308 | if (!chan) |
| 309 | return; |
| 310 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 311 | *oper_centr_freq_seg1_idx = 0; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 312 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 313 | switch (hostapd_get_oper_chwidth(iface->conf)) { |
| 314 | case CHANWIDTH_USE_HT: |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 315 | if (secondary_channel == 1) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 316 | *oper_centr_freq_seg0_idx = chan->chan + 2; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 317 | else if (secondary_channel == -1) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 318 | *oper_centr_freq_seg0_idx = chan->chan - 2; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 319 | else |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 320 | *oper_centr_freq_seg0_idx = chan->chan; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 321 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 322 | case CHANWIDTH_80MHZ: |
| 323 | *oper_centr_freq_seg0_idx = chan->chan + 6; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 324 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 325 | case CHANWIDTH_160MHZ: |
| 326 | *oper_centr_freq_seg0_idx = chan->chan + 14; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 327 | break; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 328 | case CHANWIDTH_80P80MHZ: |
| 329 | *oper_centr_freq_seg0_idx = chan->chan + 6; |
| 330 | *oper_centr_freq_seg1_idx = sec_chan_idx_80p80 + 6; |
| 331 | break; |
| 332 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 333 | default: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 334 | wpa_printf(MSG_INFO, |
| 335 | "DFS: Unsupported channel width configuration"); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 336 | *oper_centr_freq_seg0_idx = 0; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 337 | break; |
| 338 | } |
| 339 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 340 | wpa_printf(MSG_DEBUG, "DFS adjusting VHT center frequency: %d, %d", |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 341 | *oper_centr_freq_seg0_idx, |
| 342 | *oper_centr_freq_seg1_idx); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | |
| 346 | /* Return start channel idx we will use for mode->channels[idx] */ |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 347 | static int dfs_get_start_chan_idx(struct hostapd_iface *iface, int *seg1_start) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 348 | { |
| 349 | struct hostapd_hw_modes *mode; |
| 350 | struct hostapd_channel_data *chan; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 351 | int channel_no = iface->conf->channel; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 352 | int res = -1, i; |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 353 | int chan_seg1 = -1; |
| 354 | |
| 355 | *seg1_start = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 356 | |
| 357 | /* HT40- */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 358 | if (iface->conf->ieee80211n && iface->conf->secondary_channel == -1) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 359 | channel_no -= 4; |
| 360 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 361 | /* VHT/HE */ |
| 362 | if (iface->conf->ieee80211ac || iface->conf->ieee80211ax) { |
| 363 | switch (hostapd_get_oper_chwidth(iface->conf)) { |
| 364 | case CHANWIDTH_USE_HT: |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 365 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 366 | case CHANWIDTH_80MHZ: |
| 367 | channel_no = hostapd_get_oper_centr_freq_seg0_idx( |
| 368 | iface->conf) - 6; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 369 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 370 | case CHANWIDTH_160MHZ: |
| 371 | channel_no = hostapd_get_oper_centr_freq_seg0_idx( |
| 372 | iface->conf) - 14; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 373 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 374 | case CHANWIDTH_80P80MHZ: |
| 375 | channel_no = hostapd_get_oper_centr_freq_seg0_idx( |
| 376 | iface->conf) - 6; |
| 377 | chan_seg1 = hostapd_get_oper_centr_freq_seg1_idx( |
| 378 | iface->conf) - 6; |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 379 | break; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 380 | default: |
| 381 | wpa_printf(MSG_INFO, |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 382 | "DFS only VHT20/40/80/160/80+80 is supported now"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 383 | channel_no = -1; |
| 384 | break; |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | /* Get idx */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 389 | mode = iface->current_mode; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 390 | for (i = 0; i < mode->num_channels; i++) { |
| 391 | chan = &mode->channels[i]; |
| 392 | if (chan->chan == channel_no) { |
| 393 | res = i; |
| 394 | break; |
| 395 | } |
| 396 | } |
| 397 | |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 398 | if (res != -1 && chan_seg1 > -1) { |
| 399 | int found = 0; |
| 400 | |
| 401 | /* Get idx for seg1 */ |
| 402 | mode = iface->current_mode; |
| 403 | for (i = 0; i < mode->num_channels; i++) { |
| 404 | chan = &mode->channels[i]; |
| 405 | if (chan->chan == chan_seg1) { |
| 406 | *seg1_start = i; |
| 407 | found = 1; |
| 408 | break; |
| 409 | } |
| 410 | } |
| 411 | if (!found) |
| 412 | res = -1; |
| 413 | } |
| 414 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 415 | if (res == -1) { |
| 416 | wpa_printf(MSG_DEBUG, |
| 417 | "DFS chan_idx seems wrong; num-ch: %d ch-no: %d conf-ch-no: %d 11n: %d sec-ch: %d vht-oper-width: %d", |
| 418 | mode->num_channels, channel_no, iface->conf->channel, |
| 419 | iface->conf->ieee80211n, |
| 420 | iface->conf->secondary_channel, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 421 | hostapd_get_oper_chwidth(iface->conf)); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 422 | |
| 423 | for (i = 0; i < mode->num_channels; i++) { |
| 424 | wpa_printf(MSG_DEBUG, "Available channel: %d", |
| 425 | mode->channels[i].chan); |
| 426 | } |
| 427 | } |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 428 | |
| 429 | return res; |
| 430 | } |
| 431 | |
| 432 | |
| 433 | /* At least one channel have radar flag */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 434 | static int dfs_check_chans_radar(struct hostapd_iface *iface, |
| 435 | int start_chan_idx, int n_chans) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 436 | { |
| 437 | struct hostapd_channel_data *channel; |
| 438 | struct hostapd_hw_modes *mode; |
| 439 | int i, res = 0; |
| 440 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 441 | mode = iface->current_mode; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 442 | |
| 443 | for (i = 0; i < n_chans; i++) { |
| 444 | channel = &mode->channels[start_chan_idx + i]; |
| 445 | if (channel->flag & HOSTAPD_CHAN_RADAR) |
| 446 | res++; |
| 447 | } |
| 448 | |
| 449 | return res; |
| 450 | } |
| 451 | |
| 452 | |
| 453 | /* All channels available */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 454 | static int dfs_check_chans_available(struct hostapd_iface *iface, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 455 | int start_chan_idx, int n_chans) |
| 456 | { |
| 457 | struct hostapd_channel_data *channel; |
| 458 | struct hostapd_hw_modes *mode; |
| 459 | int i; |
| 460 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 461 | mode = iface->current_mode; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 462 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 463 | for (i = 0; i < n_chans; i++) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 464 | channel = &mode->channels[start_chan_idx + i]; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 465 | |
| 466 | if (channel->flag & HOSTAPD_CHAN_DISABLED) |
| 467 | break; |
| 468 | |
| 469 | if (!(channel->flag & HOSTAPD_CHAN_RADAR)) |
| 470 | continue; |
| 471 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 472 | if ((channel->flag & HOSTAPD_CHAN_DFS_MASK) != |
| 473 | HOSTAPD_CHAN_DFS_AVAILABLE) |
| 474 | break; |
| 475 | } |
| 476 | |
| 477 | return i == n_chans; |
| 478 | } |
| 479 | |
| 480 | |
| 481 | /* At least one channel unavailable */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 482 | static int dfs_check_chans_unavailable(struct hostapd_iface *iface, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 483 | int start_chan_idx, |
| 484 | int n_chans) |
| 485 | { |
| 486 | struct hostapd_channel_data *channel; |
| 487 | struct hostapd_hw_modes *mode; |
| 488 | int i, res = 0; |
| 489 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 490 | mode = iface->current_mode; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 491 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 492 | for (i = 0; i < n_chans; i++) { |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 493 | channel = &mode->channels[start_chan_idx + i]; |
| 494 | if (channel->flag & HOSTAPD_CHAN_DISABLED) |
| 495 | res++; |
| 496 | if ((channel->flag & HOSTAPD_CHAN_DFS_MASK) == |
| 497 | HOSTAPD_CHAN_DFS_UNAVAILABLE) |
| 498 | res++; |
| 499 | } |
| 500 | |
| 501 | return res; |
| 502 | } |
| 503 | |
| 504 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 505 | static struct hostapd_channel_data * |
| 506 | dfs_get_valid_channel(struct hostapd_iface *iface, |
| 507 | int *secondary_channel, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 508 | u8 *oper_centr_freq_seg0_idx, |
| 509 | u8 *oper_centr_freq_seg1_idx, |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 510 | enum dfs_channel_type type) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 511 | { |
| 512 | struct hostapd_hw_modes *mode; |
| 513 | struct hostapd_channel_data *chan = NULL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 514 | struct hostapd_channel_data *chan2 = NULL; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 515 | int num_available_chandefs; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 516 | int chan_idx, chan_idx2; |
| 517 | int sec_chan_idx_80p80 = -1; |
| 518 | int i; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 519 | u32 _rand; |
| 520 | |
| 521 | wpa_printf(MSG_DEBUG, "DFS: Selecting random channel"); |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 522 | *secondary_channel = 0; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 523 | *oper_centr_freq_seg0_idx = 0; |
| 524 | *oper_centr_freq_seg1_idx = 0; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 525 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 526 | if (iface->current_mode == NULL) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 527 | return NULL; |
| 528 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 529 | mode = iface->current_mode; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 530 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 531 | return NULL; |
| 532 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 533 | /* Get the count first */ |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 534 | num_available_chandefs = dfs_find_channel(iface, NULL, 0, type); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 535 | wpa_printf(MSG_DEBUG, "DFS: num_available_chandefs=%d", |
| 536 | num_available_chandefs); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 537 | if (num_available_chandefs == 0) |
| 538 | return NULL; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 539 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 540 | if (os_get_random((u8 *) &_rand, sizeof(_rand)) < 0) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 541 | return NULL; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 542 | chan_idx = _rand % num_available_chandefs; |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 543 | dfs_find_channel(iface, &chan, chan_idx, type); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 544 | if (!chan) { |
| 545 | wpa_printf(MSG_DEBUG, "DFS: no random channel found"); |
| 546 | return NULL; |
| 547 | } |
| 548 | wpa_printf(MSG_DEBUG, "DFS: got random channel %d (%d)", |
| 549 | chan->freq, chan->chan); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 550 | |
| 551 | /* dfs_find_channel() calculations assume HT40+ */ |
| 552 | if (iface->conf->secondary_channel) |
| 553 | *secondary_channel = 1; |
| 554 | else |
| 555 | *secondary_channel = 0; |
| 556 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 557 | /* Get secondary channel for HT80P80 */ |
| 558 | if (hostapd_get_oper_chwidth(iface->conf) == CHANWIDTH_80P80MHZ) { |
| 559 | if (num_available_chandefs <= 1) { |
| 560 | wpa_printf(MSG_ERROR, |
| 561 | "only 1 valid chan, can't support 80+80"); |
| 562 | return NULL; |
| 563 | } |
| 564 | |
| 565 | /* |
| 566 | * Loop all channels except channel1 to find a valid channel2 |
| 567 | * that is not adjacent to channel1. |
| 568 | */ |
| 569 | for (i = 0; i < num_available_chandefs - 1; i++) { |
| 570 | /* start from chan_idx + 1, end when chan_idx - 1 */ |
| 571 | chan_idx2 = (chan_idx + 1 + i) % num_available_chandefs; |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 572 | dfs_find_channel(iface, &chan2, chan_idx2, type); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 573 | if (chan2 && abs(chan2->chan - chan->chan) > 12) { |
| 574 | /* two channels are not adjacent */ |
| 575 | sec_chan_idx_80p80 = chan2->chan; |
| 576 | wpa_printf(MSG_DEBUG, |
| 577 | "DFS: got second chan: %d (%d)", |
| 578 | chan2->freq, chan2->chan); |
| 579 | break; |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | /* Check if we got a valid secondary channel which is not |
| 584 | * adjacent to the first channel. |
| 585 | */ |
| 586 | if (sec_chan_idx_80p80 == -1) { |
| 587 | wpa_printf(MSG_INFO, |
| 588 | "DFS: failed to get chan2 for 80+80"); |
| 589 | return NULL; |
| 590 | } |
| 591 | } |
| 592 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 593 | dfs_adjust_center_freq(iface, chan, |
| 594 | *secondary_channel, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 595 | sec_chan_idx_80p80, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 596 | oper_centr_freq_seg0_idx, |
| 597 | oper_centr_freq_seg1_idx); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 598 | |
| 599 | return chan; |
| 600 | } |
| 601 | |
| 602 | |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 603 | static int dfs_set_valid_channel(struct hostapd_iface *iface, int skip_radar) |
| 604 | { |
| 605 | struct hostapd_channel_data *channel; |
| 606 | u8 cf1 = 0, cf2 = 0; |
| 607 | int sec = 0; |
| 608 | |
| 609 | channel = dfs_get_valid_channel(iface, &sec, &cf1, &cf2, |
| 610 | skip_radar ? DFS_AVAILABLE : |
| 611 | DFS_ANY_CHANNEL); |
| 612 | if (!channel) { |
| 613 | wpa_printf(MSG_ERROR, "could not get valid channel"); |
| 614 | return -1; |
| 615 | } |
| 616 | |
| 617 | iface->freq = channel->freq; |
| 618 | iface->conf->channel = channel->chan; |
| 619 | iface->conf->secondary_channel = sec; |
| 620 | hostapd_set_oper_centr_freq_seg0_idx(iface->conf, cf1); |
| 621 | hostapd_set_oper_centr_freq_seg1_idx(iface->conf, cf2); |
| 622 | |
| 623 | return 0; |
| 624 | } |
| 625 | |
| 626 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 627 | static int set_dfs_state_freq(struct hostapd_iface *iface, int freq, u32 state) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 628 | { |
| 629 | struct hostapd_hw_modes *mode; |
| 630 | struct hostapd_channel_data *chan = NULL; |
| 631 | int i; |
| 632 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 633 | mode = iface->current_mode; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 634 | if (mode == NULL) |
| 635 | return 0; |
| 636 | |
| 637 | wpa_printf(MSG_DEBUG, "set_dfs_state 0x%X for %d MHz", state, freq); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 638 | for (i = 0; i < iface->current_mode->num_channels; i++) { |
| 639 | chan = &iface->current_mode->channels[i]; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 640 | if (chan->freq == freq) { |
| 641 | if (chan->flag & HOSTAPD_CHAN_RADAR) { |
| 642 | chan->flag &= ~HOSTAPD_CHAN_DFS_MASK; |
| 643 | chan->flag |= state; |
| 644 | return 1; /* Channel found */ |
| 645 | } |
| 646 | } |
| 647 | } |
| 648 | wpa_printf(MSG_WARNING, "Can't set DFS state for freq %d MHz", freq); |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 653 | static int set_dfs_state(struct hostapd_iface *iface, int freq, int ht_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 654 | int chan_offset, int chan_width, int cf1, |
| 655 | int cf2, u32 state) |
| 656 | { |
| 657 | int n_chans = 1, i; |
| 658 | struct hostapd_hw_modes *mode; |
| 659 | int frequency = freq; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 660 | int frequency2 = 0; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 661 | int ret = 0; |
| 662 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 663 | mode = iface->current_mode; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 664 | if (mode == NULL) |
| 665 | return 0; |
| 666 | |
| 667 | if (mode->mode != HOSTAPD_MODE_IEEE80211A) { |
| 668 | wpa_printf(MSG_WARNING, "current_mode != IEEE80211A"); |
| 669 | return 0; |
| 670 | } |
| 671 | |
| 672 | /* Seems cf1 and chan_width is enough here */ |
| 673 | switch (chan_width) { |
| 674 | case CHAN_WIDTH_20_NOHT: |
| 675 | case CHAN_WIDTH_20: |
| 676 | n_chans = 1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 677 | if (frequency == 0) |
| 678 | frequency = cf1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 679 | break; |
| 680 | case CHAN_WIDTH_40: |
| 681 | n_chans = 2; |
| 682 | frequency = cf1 - 10; |
| 683 | break; |
| 684 | case CHAN_WIDTH_80: |
| 685 | n_chans = 4; |
| 686 | frequency = cf1 - 30; |
| 687 | break; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 688 | case CHAN_WIDTH_80P80: |
| 689 | n_chans = 4; |
| 690 | frequency = cf1 - 30; |
| 691 | frequency2 = cf2 - 30; |
| 692 | break; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 693 | case CHAN_WIDTH_160: |
| 694 | n_chans = 8; |
| 695 | frequency = cf1 - 70; |
| 696 | break; |
| 697 | default: |
| 698 | wpa_printf(MSG_INFO, "DFS chan_width %d not supported", |
| 699 | chan_width); |
| 700 | break; |
| 701 | } |
| 702 | |
| 703 | wpa_printf(MSG_DEBUG, "DFS freq: %dMHz, n_chans: %d", frequency, |
| 704 | n_chans); |
| 705 | for (i = 0; i < n_chans; i++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 706 | ret += set_dfs_state_freq(iface, frequency, state); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 707 | frequency = frequency + 20; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 708 | |
| 709 | if (chan_width == CHAN_WIDTH_80P80) { |
| 710 | ret += set_dfs_state_freq(iface, frequency2, state); |
| 711 | frequency2 = frequency2 + 20; |
| 712 | } |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | return ret; |
| 716 | } |
| 717 | |
| 718 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 719 | static int dfs_are_channels_overlapped(struct hostapd_iface *iface, int freq, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 720 | int chan_width, int cf1, int cf2) |
| 721 | { |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 722 | int start_chan_idx, start_chan_idx1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 723 | struct hostapd_hw_modes *mode; |
| 724 | struct hostapd_channel_data *chan; |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 725 | int n_chans, n_chans1, i, j, frequency = freq, radar_n_chans = 1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 726 | u8 radar_chan; |
| 727 | int res = 0; |
| 728 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 729 | /* Our configuration */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 730 | mode = iface->current_mode; |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 731 | start_chan_idx = dfs_get_start_chan_idx(iface, &start_chan_idx1); |
| 732 | n_chans = dfs_get_used_n_chans(iface, &n_chans1); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 733 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 734 | /* Check we are on DFS channel(s) */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 735 | if (!dfs_check_chans_radar(iface, start_chan_idx, n_chans)) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 736 | return 0; |
| 737 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 738 | /* Reported via radar event */ |
| 739 | switch (chan_width) { |
| 740 | case CHAN_WIDTH_20_NOHT: |
| 741 | case CHAN_WIDTH_20: |
| 742 | radar_n_chans = 1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 743 | if (frequency == 0) |
| 744 | frequency = cf1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 745 | break; |
| 746 | case CHAN_WIDTH_40: |
| 747 | radar_n_chans = 2; |
| 748 | frequency = cf1 - 10; |
| 749 | break; |
| 750 | case CHAN_WIDTH_80: |
| 751 | radar_n_chans = 4; |
| 752 | frequency = cf1 - 30; |
| 753 | break; |
| 754 | case CHAN_WIDTH_160: |
| 755 | radar_n_chans = 8; |
| 756 | frequency = cf1 - 70; |
| 757 | break; |
| 758 | default: |
| 759 | wpa_printf(MSG_INFO, "DFS chan_width %d not supported", |
| 760 | chan_width); |
| 761 | break; |
| 762 | } |
| 763 | |
| 764 | ieee80211_freq_to_chan(frequency, &radar_chan); |
| 765 | |
| 766 | for (i = 0; i < n_chans; i++) { |
| 767 | chan = &mode->channels[start_chan_idx + i]; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 768 | if (!(chan->flag & HOSTAPD_CHAN_RADAR)) |
| 769 | continue; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 770 | for (j = 0; j < radar_n_chans; j++) { |
| 771 | wpa_printf(MSG_DEBUG, "checking our: %d, radar: %d", |
| 772 | chan->chan, radar_chan + j * 4); |
| 773 | if (chan->chan == radar_chan + j * 4) |
| 774 | res++; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | wpa_printf(MSG_DEBUG, "overlapped: %d", res); |
| 779 | |
| 780 | return res; |
| 781 | } |
| 782 | |
| 783 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 784 | static unsigned int dfs_get_cac_time(struct hostapd_iface *iface, |
| 785 | int start_chan_idx, int n_chans) |
| 786 | { |
| 787 | struct hostapd_channel_data *channel; |
| 788 | struct hostapd_hw_modes *mode; |
| 789 | int i; |
| 790 | unsigned int cac_time_ms = 0; |
| 791 | |
| 792 | mode = iface->current_mode; |
| 793 | |
| 794 | for (i = 0; i < n_chans; i++) { |
| 795 | channel = &mode->channels[start_chan_idx + i]; |
| 796 | if (!(channel->flag & HOSTAPD_CHAN_RADAR)) |
| 797 | continue; |
| 798 | if (channel->dfs_cac_ms > cac_time_ms) |
| 799 | cac_time_ms = channel->dfs_cac_ms; |
| 800 | } |
| 801 | |
| 802 | return cac_time_ms; |
| 803 | } |
| 804 | |
| 805 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 806 | /* |
| 807 | * Main DFS handler |
| 808 | * 1 - continue channel/ap setup |
| 809 | * 0 - channel/ap setup will be continued after CAC |
| 810 | * -1 - hit critical error |
| 811 | */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 812 | int hostapd_handle_dfs(struct hostapd_iface *iface) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 813 | { |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 814 | int res, n_chans, n_chans1, start_chan_idx, start_chan_idx1; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 815 | int skip_radar = 0; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 816 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 817 | if (is_6ghz_freq(iface->freq)) |
| 818 | return 1; |
| 819 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 820 | if (!iface->current_mode) { |
| 821 | /* |
| 822 | * This can happen with drivers that do not provide mode |
| 823 | * information and as such, cannot really use hostapd for DFS. |
| 824 | */ |
| 825 | wpa_printf(MSG_DEBUG, |
| 826 | "DFS: No current_mode information - assume no need to perform DFS operations by hostapd"); |
| 827 | return 1; |
| 828 | } |
| 829 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 830 | iface->cac_started = 0; |
| 831 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 832 | do { |
| 833 | /* Get start (first) channel for current configuration */ |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 834 | start_chan_idx = dfs_get_start_chan_idx(iface, |
| 835 | &start_chan_idx1); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 836 | if (start_chan_idx == -1) |
| 837 | return -1; |
| 838 | |
| 839 | /* Get number of used channels, depend on width */ |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 840 | n_chans = dfs_get_used_n_chans(iface, &n_chans1); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 841 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 842 | /* Setup CAC time */ |
| 843 | iface->dfs_cac_ms = dfs_get_cac_time(iface, start_chan_idx, |
| 844 | n_chans); |
| 845 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 846 | /* Check if any of configured channels require DFS */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 847 | res = dfs_check_chans_radar(iface, start_chan_idx, n_chans); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 848 | wpa_printf(MSG_DEBUG, |
| 849 | "DFS %d channels required radar detection", |
| 850 | res); |
| 851 | if (!res) |
| 852 | return 1; |
| 853 | |
| 854 | /* Check if all channels are DFS available */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 855 | res = dfs_check_chans_available(iface, start_chan_idx, n_chans); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 856 | wpa_printf(MSG_DEBUG, |
| 857 | "DFS all channels available, (SKIP CAC): %s", |
| 858 | res ? "yes" : "no"); |
| 859 | if (res) |
| 860 | return 1; |
| 861 | |
| 862 | /* Check if any of configured channels is unavailable */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 863 | res = dfs_check_chans_unavailable(iface, start_chan_idx, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 864 | n_chans); |
| 865 | wpa_printf(MSG_DEBUG, "DFS %d chans unavailable - choose other channel: %s", |
| 866 | res, res ? "yes": "no"); |
| 867 | if (res) { |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 868 | if (dfs_set_valid_channel(iface, skip_radar) < 0) { |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 869 | hostapd_set_state(iface, HAPD_IFACE_DFS); |
| 870 | return 0; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 871 | } |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 872 | } |
| 873 | } while (res); |
| 874 | |
| 875 | /* Finally start CAC */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 876 | hostapd_set_state(iface, HAPD_IFACE_DFS); |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 877 | wpa_printf(MSG_DEBUG, "DFS start CAC on %d MHz%s", iface->freq, |
| 878 | dfs_use_radar_background(iface) ? " (background)" : ""); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 879 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_CAC_START |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 880 | "freq=%d chan=%d sec_chan=%d, width=%d, seg0=%d, seg1=%d, cac_time=%ds", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 881 | iface->freq, |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 882 | iface->conf->channel, iface->conf->secondary_channel, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 883 | hostapd_get_oper_chwidth(iface->conf), |
| 884 | hostapd_get_oper_centr_freq_seg0_idx(iface->conf), |
| 885 | hostapd_get_oper_centr_freq_seg1_idx(iface->conf), |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 886 | iface->dfs_cac_ms / 1000); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 887 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 888 | res = hostapd_start_dfs_cac( |
| 889 | iface, iface->conf->hw_mode, iface->freq, iface->conf->channel, |
| 890 | iface->conf->ieee80211n, iface->conf->ieee80211ac, |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 891 | iface->conf->ieee80211ax, iface->conf->ieee80211be, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 892 | iface->conf->secondary_channel, |
| 893 | hostapd_get_oper_chwidth(iface->conf), |
| 894 | hostapd_get_oper_centr_freq_seg0_idx(iface->conf), |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 895 | hostapd_get_oper_centr_freq_seg1_idx(iface->conf), |
| 896 | dfs_use_radar_background(iface)); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 897 | |
| 898 | if (res) { |
| 899 | wpa_printf(MSG_ERROR, "DFS start_dfs_cac() failed, %d", res); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 900 | return -1; |
| 901 | } |
| 902 | |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 903 | if (dfs_use_radar_background(iface)) { |
| 904 | /* Cache background radar parameters. */ |
| 905 | iface->radar_background.channel = iface->conf->channel; |
| 906 | iface->radar_background.secondary_channel = |
| 907 | iface->conf->secondary_channel; |
| 908 | iface->radar_background.freq = iface->freq; |
| 909 | iface->radar_background.centr_freq_seg0_idx = |
| 910 | hostapd_get_oper_centr_freq_seg0_idx(iface->conf); |
| 911 | iface->radar_background.centr_freq_seg1_idx = |
| 912 | hostapd_get_oper_centr_freq_seg1_idx(iface->conf); |
| 913 | |
| 914 | /* |
| 915 | * Let's select a random channel according to the |
| 916 | * regulations and perform CAC on dedicated radar chain. |
| 917 | */ |
| 918 | res = dfs_set_valid_channel(iface, 1); |
| 919 | if (res < 0) |
| 920 | return res; |
| 921 | |
| 922 | iface->radar_background.temp_ch = 1; |
| 923 | return 1; |
| 924 | } |
| 925 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 926 | return 0; |
| 927 | } |
| 928 | |
| 929 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 930 | int hostapd_is_dfs_chan_available(struct hostapd_iface *iface) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 931 | { |
| 932 | int n_chans, n_chans1, start_chan_idx, start_chan_idx1; |
| 933 | |
| 934 | /* Get the start (first) channel for current configuration */ |
| 935 | start_chan_idx = dfs_get_start_chan_idx(iface, &start_chan_idx1); |
| 936 | if (start_chan_idx < 0) |
| 937 | return 0; |
| 938 | |
| 939 | /* Get the number of used channels, depending on width */ |
| 940 | n_chans = dfs_get_used_n_chans(iface, &n_chans1); |
| 941 | |
| 942 | /* Check if all channels are DFS available */ |
| 943 | return dfs_check_chans_available(iface, start_chan_idx, n_chans); |
| 944 | } |
| 945 | |
| 946 | |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 947 | static int hostapd_dfs_request_channel_switch(struct hostapd_iface *iface, |
| 948 | int channel, int freq, |
| 949 | int secondary_channel, |
| 950 | u8 current_vht_oper_chwidth, |
| 951 | u8 oper_centr_freq_seg0_idx, |
| 952 | u8 oper_centr_freq_seg1_idx) |
| 953 | { |
| 954 | struct hostapd_hw_modes *cmode = iface->current_mode; |
| 955 | int ieee80211_mode = IEEE80211_MODE_AP, err; |
| 956 | struct csa_settings csa_settings; |
| 957 | u8 new_vht_oper_chwidth; |
| 958 | unsigned int i; |
| 959 | |
| 960 | wpa_printf(MSG_DEBUG, "DFS will switch to a new channel %d", channel); |
| 961 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_NEW_CHANNEL |
| 962 | "freq=%d chan=%d sec_chan=%d", freq, channel, |
| 963 | secondary_channel); |
| 964 | |
| 965 | new_vht_oper_chwidth = hostapd_get_oper_chwidth(iface->conf); |
| 966 | hostapd_set_oper_chwidth(iface->conf, current_vht_oper_chwidth); |
| 967 | |
| 968 | /* Setup CSA request */ |
| 969 | os_memset(&csa_settings, 0, sizeof(csa_settings)); |
| 970 | csa_settings.cs_count = 5; |
| 971 | csa_settings.block_tx = 1; |
| 972 | #ifdef CONFIG_MESH |
| 973 | if (iface->mconf) |
| 974 | ieee80211_mode = IEEE80211_MODE_MESH; |
| 975 | #endif /* CONFIG_MESH */ |
| 976 | err = hostapd_set_freq_params(&csa_settings.freq_params, |
| 977 | iface->conf->hw_mode, |
| 978 | freq, channel, |
| 979 | iface->conf->enable_edmg, |
| 980 | iface->conf->edmg_channel, |
| 981 | iface->conf->ieee80211n, |
| 982 | iface->conf->ieee80211ac, |
| 983 | iface->conf->ieee80211ax, |
| 984 | iface->conf->ieee80211be, |
| 985 | secondary_channel, |
| 986 | new_vht_oper_chwidth, |
| 987 | oper_centr_freq_seg0_idx, |
| 988 | oper_centr_freq_seg1_idx, |
| 989 | cmode->vht_capab, |
| 990 | &cmode->he_capab[ieee80211_mode], |
| 991 | &cmode->eht_capab[ieee80211_mode]); |
| 992 | |
| 993 | if (err) { |
| 994 | wpa_printf(MSG_ERROR, |
| 995 | "DFS failed to calculate CSA freq params"); |
| 996 | hostapd_disable_iface(iface); |
| 997 | return err; |
| 998 | } |
| 999 | |
| 1000 | for (i = 0; i < iface->num_bss; i++) { |
| 1001 | err = hostapd_switch_channel(iface->bss[i], &csa_settings); |
| 1002 | if (err) |
| 1003 | break; |
| 1004 | } |
| 1005 | |
| 1006 | if (err) { |
| 1007 | wpa_printf(MSG_WARNING, |
| 1008 | "DFS failed to schedule CSA (%d) - trying fallback", |
| 1009 | err); |
| 1010 | iface->freq = freq; |
| 1011 | iface->conf->channel = channel; |
| 1012 | iface->conf->secondary_channel = secondary_channel; |
| 1013 | hostapd_set_oper_chwidth(iface->conf, new_vht_oper_chwidth); |
| 1014 | hostapd_set_oper_centr_freq_seg0_idx(iface->conf, |
| 1015 | oper_centr_freq_seg0_idx); |
| 1016 | hostapd_set_oper_centr_freq_seg1_idx(iface->conf, |
| 1017 | oper_centr_freq_seg1_idx); |
| 1018 | |
| 1019 | hostapd_disable_iface(iface); |
| 1020 | hostapd_enable_iface(iface); |
| 1021 | |
| 1022 | return 0; |
| 1023 | } |
| 1024 | |
| 1025 | /* Channel configuration will be updated once CSA completes and |
| 1026 | * ch_switch_notify event is received */ |
| 1027 | wpa_printf(MSG_DEBUG, "DFS waiting channel switch event"); |
| 1028 | |
| 1029 | return 0; |
| 1030 | } |
| 1031 | |
| 1032 | |
| 1033 | static void hostpad_dfs_update_background_chain(struct hostapd_iface *iface) |
| 1034 | { |
| 1035 | int sec = 0; |
| 1036 | enum dfs_channel_type channel_type = DFS_NO_CAC_YET; |
| 1037 | struct hostapd_channel_data *channel; |
| 1038 | u8 oper_centr_freq_seg0_idx = 0; |
| 1039 | u8 oper_centr_freq_seg1_idx = 0; |
| 1040 | |
| 1041 | /* |
| 1042 | * Allow selection of DFS channel in ETSI to comply with |
| 1043 | * uniform spreading. |
| 1044 | */ |
| 1045 | if (iface->dfs_domain == HOSTAPD_DFS_REGION_ETSI) |
| 1046 | channel_type = DFS_ANY_CHANNEL; |
| 1047 | |
| 1048 | channel = dfs_get_valid_channel(iface, &sec, &oper_centr_freq_seg0_idx, |
| 1049 | &oper_centr_freq_seg1_idx, |
| 1050 | channel_type); |
| 1051 | if (!channel || |
| 1052 | channel->chan == iface->conf->channel || |
| 1053 | channel->chan == iface->radar_background.channel) |
| 1054 | channel = dfs_downgrade_bandwidth(iface, &sec, |
| 1055 | &oper_centr_freq_seg0_idx, |
| 1056 | &oper_centr_freq_seg1_idx, |
| 1057 | &channel_type); |
| 1058 | if (!channel || |
| 1059 | hostapd_start_dfs_cac(iface, iface->conf->hw_mode, |
| 1060 | channel->freq, channel->chan, |
| 1061 | iface->conf->ieee80211n, |
| 1062 | iface->conf->ieee80211ac, |
| 1063 | iface->conf->ieee80211ax, |
| 1064 | iface->conf->ieee80211be, |
| 1065 | sec, hostapd_get_oper_chwidth(iface->conf), |
| 1066 | oper_centr_freq_seg0_idx, |
| 1067 | oper_centr_freq_seg1_idx, true)) { |
| 1068 | wpa_printf(MSG_ERROR, "DFS failed to start CAC offchannel"); |
| 1069 | iface->radar_background.channel = -1; |
| 1070 | return; |
| 1071 | } |
| 1072 | |
| 1073 | iface->radar_background.channel = channel->chan; |
| 1074 | iface->radar_background.freq = channel->freq; |
| 1075 | iface->radar_background.secondary_channel = sec; |
| 1076 | iface->radar_background.centr_freq_seg0_idx = oper_centr_freq_seg0_idx; |
| 1077 | iface->radar_background.centr_freq_seg1_idx = oper_centr_freq_seg1_idx; |
| 1078 | |
| 1079 | wpa_printf(MSG_DEBUG, |
| 1080 | "%s: setting background chain to chan %d (%d MHz)", |
| 1081 | __func__, channel->chan, channel->freq); |
| 1082 | } |
| 1083 | |
| 1084 | |
| 1085 | static bool |
| 1086 | hostapd_dfs_is_background_event(struct hostapd_iface *iface, int freq) |
| 1087 | { |
| 1088 | return dfs_use_radar_background(iface) && |
| 1089 | iface->radar_background.channel != -1 && |
| 1090 | iface->radar_background.freq == freq; |
| 1091 | } |
| 1092 | |
| 1093 | |
| 1094 | static int |
| 1095 | hostapd_dfs_start_channel_switch_background(struct hostapd_iface *iface) |
| 1096 | { |
| 1097 | u8 current_vht_oper_chwidth = hostapd_get_oper_chwidth(iface->conf); |
| 1098 | |
| 1099 | iface->conf->channel = iface->radar_background.channel; |
| 1100 | iface->freq = iface->radar_background.freq; |
| 1101 | iface->conf->secondary_channel = |
| 1102 | iface->radar_background.secondary_channel; |
| 1103 | hostapd_set_oper_centr_freq_seg0_idx( |
| 1104 | iface->conf, iface->radar_background.centr_freq_seg0_idx); |
| 1105 | hostapd_set_oper_centr_freq_seg1_idx( |
| 1106 | iface->conf, iface->radar_background.centr_freq_seg1_idx); |
| 1107 | |
| 1108 | hostpad_dfs_update_background_chain(iface); |
| 1109 | |
| 1110 | return hostapd_dfs_request_channel_switch( |
| 1111 | iface, iface->conf->channel, iface->freq, |
| 1112 | iface->conf->secondary_channel, current_vht_oper_chwidth, |
| 1113 | hostapd_get_oper_centr_freq_seg0_idx(iface->conf), |
| 1114 | hostapd_get_oper_centr_freq_seg1_idx(iface->conf)); |
| 1115 | } |
| 1116 | |
| 1117 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1118 | int hostapd_dfs_complete_cac(struct hostapd_iface *iface, int success, int freq, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1119 | int ht_enabled, int chan_offset, int chan_width, |
| 1120 | int cf1, int cf2) |
| 1121 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1122 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_CAC_COMPLETED |
| 1123 | "success=%d freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d", |
| 1124 | success, freq, ht_enabled, chan_offset, chan_width, cf1, cf2); |
| 1125 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1126 | if (success) { |
| 1127 | /* Complete iface/ap configuration */ |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1128 | if (iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) { |
| 1129 | /* Complete AP configuration for the first bring up. */ |
| 1130 | if (iface->state != HAPD_IFACE_ENABLED) |
| 1131 | hostapd_setup_interface_complete(iface, 0); |
| 1132 | else |
| 1133 | iface->cac_started = 0; |
| 1134 | } else { |
| 1135 | set_dfs_state(iface, freq, ht_enabled, chan_offset, |
| 1136 | chan_width, cf1, cf2, |
| 1137 | HOSTAPD_CHAN_DFS_AVAILABLE); |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1138 | |
| 1139 | /* |
| 1140 | * Radar event from background chain for the selected |
| 1141 | * channel. Perform CSA, move the main chain to the |
| 1142 | * selected channel and configure the background chain |
| 1143 | * to a new DFS channel. |
| 1144 | */ |
| 1145 | if (hostapd_dfs_is_background_event(iface, freq)) { |
| 1146 | iface->radar_background.cac_started = 0; |
| 1147 | if (!iface->radar_background.temp_ch) |
| 1148 | return 0; |
| 1149 | |
| 1150 | iface->radar_background.temp_ch = 0; |
| 1151 | return hostapd_dfs_start_channel_switch_background(iface); |
| 1152 | } |
| 1153 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1154 | /* |
| 1155 | * Just mark the channel available when CAC completion |
| 1156 | * event is received in enabled state. CAC result could |
| 1157 | * have been propagated from another radio having the |
| 1158 | * same regulatory configuration. When CAC completion is |
| 1159 | * received during non-HAPD_IFACE_ENABLED state, make |
| 1160 | * sure the configured channel is available because this |
| 1161 | * CAC completion event could have been propagated from |
| 1162 | * another radio. |
| 1163 | */ |
| 1164 | if (iface->state != HAPD_IFACE_ENABLED && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1165 | hostapd_is_dfs_chan_available(iface)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1166 | hostapd_setup_interface_complete(iface, 0); |
| 1167 | iface->cac_started = 0; |
| 1168 | } |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1169 | } |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1170 | } else if (hostapd_dfs_is_background_event(iface, freq)) { |
| 1171 | iface->radar_background.cac_started = 0; |
| 1172 | hostpad_dfs_update_background_chain(iface); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | return 0; |
| 1176 | } |
| 1177 | |
| 1178 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1179 | int hostapd_dfs_pre_cac_expired(struct hostapd_iface *iface, int freq, |
| 1180 | int ht_enabled, int chan_offset, int chan_width, |
| 1181 | int cf1, int cf2) |
| 1182 | { |
| 1183 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_PRE_CAC_EXPIRED |
| 1184 | "freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d", |
| 1185 | freq, ht_enabled, chan_offset, chan_width, cf1, cf2); |
| 1186 | |
| 1187 | /* Proceed only if DFS is not offloaded to the driver */ |
| 1188 | if (iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) |
| 1189 | return 0; |
| 1190 | |
| 1191 | set_dfs_state(iface, freq, ht_enabled, chan_offset, chan_width, |
| 1192 | cf1, cf2, HOSTAPD_CHAN_DFS_USABLE); |
| 1193 | |
| 1194 | return 0; |
| 1195 | } |
| 1196 | |
| 1197 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1198 | static struct hostapd_channel_data * |
| 1199 | dfs_downgrade_bandwidth(struct hostapd_iface *iface, int *secondary_channel, |
| 1200 | u8 *oper_centr_freq_seg0_idx, |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1201 | u8 *oper_centr_freq_seg1_idx, |
| 1202 | enum dfs_channel_type *channel_type) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1203 | { |
| 1204 | struct hostapd_channel_data *channel; |
| 1205 | |
| 1206 | for (;;) { |
| 1207 | channel = dfs_get_valid_channel(iface, secondary_channel, |
| 1208 | oper_centr_freq_seg0_idx, |
| 1209 | oper_centr_freq_seg1_idx, |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1210 | *channel_type); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1211 | if (channel) { |
| 1212 | wpa_printf(MSG_DEBUG, "DFS: Selected channel: %d", |
| 1213 | channel->chan); |
| 1214 | return channel; |
| 1215 | } |
| 1216 | |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1217 | if (*channel_type != DFS_ANY_CHANNEL) { |
| 1218 | *channel_type = DFS_ANY_CHANNEL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1219 | } else { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1220 | int oper_chwidth; |
| 1221 | |
| 1222 | oper_chwidth = hostapd_get_oper_chwidth(iface->conf); |
| 1223 | if (oper_chwidth == CHANWIDTH_USE_HT) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1224 | break; |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1225 | *channel_type = DFS_AVAILABLE; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1226 | hostapd_set_oper_chwidth(iface->conf, oper_chwidth - 1); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | |
| 1230 | wpa_printf(MSG_INFO, |
| 1231 | "%s: no DFS channels left, waiting for NOP to finish", |
| 1232 | __func__); |
| 1233 | return NULL; |
| 1234 | } |
| 1235 | |
| 1236 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1237 | static int hostapd_dfs_start_channel_switch_cac(struct hostapd_iface *iface) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1238 | { |
| 1239 | struct hostapd_channel_data *channel; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1240 | int secondary_channel; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1241 | u8 oper_centr_freq_seg0_idx = 0; |
| 1242 | u8 oper_centr_freq_seg1_idx = 0; |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1243 | enum dfs_channel_type channel_type = DFS_ANY_CHANNEL; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1244 | int err = 1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1245 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1246 | /* Radar detected during active CAC */ |
| 1247 | iface->cac_started = 0; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1248 | channel = dfs_get_valid_channel(iface, &secondary_channel, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1249 | &oper_centr_freq_seg0_idx, |
| 1250 | &oper_centr_freq_seg1_idx, |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1251 | channel_type); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1252 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1253 | if (!channel) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1254 | channel = dfs_downgrade_bandwidth(iface, &secondary_channel, |
| 1255 | &oper_centr_freq_seg0_idx, |
| 1256 | &oper_centr_freq_seg1_idx, |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1257 | &channel_type); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1258 | if (!channel) { |
| 1259 | wpa_printf(MSG_ERROR, "No valid channel available"); |
| 1260 | return err; |
| 1261 | } |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | wpa_printf(MSG_DEBUG, "DFS will switch to a new channel %d", |
| 1265 | channel->chan); |
| 1266 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_NEW_CHANNEL |
| 1267 | "freq=%d chan=%d sec_chan=%d", channel->freq, |
| 1268 | channel->chan, secondary_channel); |
| 1269 | |
| 1270 | iface->freq = channel->freq; |
| 1271 | iface->conf->channel = channel->chan; |
| 1272 | iface->conf->secondary_channel = secondary_channel; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1273 | hostapd_set_oper_centr_freq_seg0_idx(iface->conf, |
| 1274 | oper_centr_freq_seg0_idx); |
| 1275 | hostapd_set_oper_centr_freq_seg1_idx(iface->conf, |
| 1276 | oper_centr_freq_seg1_idx); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1277 | err = 0; |
| 1278 | |
| 1279 | hostapd_setup_interface_complete(iface, err); |
| 1280 | return err; |
| 1281 | } |
| 1282 | |
| 1283 | |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1284 | static int |
| 1285 | hostapd_dfs_background_start_channel_switch(struct hostapd_iface *iface, |
| 1286 | int freq) |
| 1287 | { |
| 1288 | if (!dfs_use_radar_background(iface)) |
| 1289 | return -1; /* Background radar chain not supported. */ |
| 1290 | |
| 1291 | wpa_printf(MSG_DEBUG, |
| 1292 | "%s called (background CAC active: %s, CSA active: %s)", |
| 1293 | __func__, iface->radar_background.cac_started ? "yes" : "no", |
| 1294 | hostapd_csa_in_progress(iface) ? "yes" : "no"); |
| 1295 | |
| 1296 | /* Check if CSA in progress */ |
| 1297 | if (hostapd_csa_in_progress(iface)) |
| 1298 | return 0; |
| 1299 | |
| 1300 | if (hostapd_dfs_is_background_event(iface, freq)) { |
| 1301 | /* |
| 1302 | * Radar pattern is reported on the background chain. |
| 1303 | * Just select a new random channel according to the |
| 1304 | * regulations for monitoring. |
| 1305 | */ |
| 1306 | hostpad_dfs_update_background_chain(iface); |
| 1307 | return 0; |
| 1308 | } |
| 1309 | |
| 1310 | /* |
| 1311 | * If background radar detection is supported and the radar channel |
| 1312 | * monitored by the background chain is available switch to it without |
| 1313 | * waiting for the CAC. |
| 1314 | */ |
| 1315 | if (iface->radar_background.channel == -1) |
| 1316 | return -1; /* Background radar chain not available. */ |
| 1317 | |
| 1318 | if (iface->radar_background.cac_started) { |
| 1319 | /* |
| 1320 | * Background channel not available yet. Perform CAC on the |
| 1321 | * main chain. |
| 1322 | */ |
| 1323 | iface->radar_background.temp_ch = 1; |
| 1324 | return -1; |
| 1325 | } |
| 1326 | |
| 1327 | return hostapd_dfs_start_channel_switch_background(iface); |
| 1328 | } |
| 1329 | |
| 1330 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1331 | static int hostapd_dfs_start_channel_switch(struct hostapd_iface *iface) |
| 1332 | { |
| 1333 | struct hostapd_channel_data *channel; |
| 1334 | int secondary_channel; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1335 | u8 oper_centr_freq_seg0_idx; |
| 1336 | u8 oper_centr_freq_seg1_idx; |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1337 | enum dfs_channel_type channel_type = DFS_AVAILABLE; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1338 | u8 current_vht_oper_chwidth = hostapd_get_oper_chwidth(iface->conf); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1339 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 1340 | wpa_printf(MSG_DEBUG, "%s called (CAC active: %s, CSA active: %s)", |
| 1341 | __func__, iface->cac_started ? "yes" : "no", |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 1342 | hostapd_csa_in_progress(iface) ? "yes" : "no"); |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 1343 | |
| 1344 | /* Check if CSA in progress */ |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 1345 | if (hostapd_csa_in_progress(iface)) |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 1346 | return 0; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1347 | |
| 1348 | /* Check if active CAC */ |
| 1349 | if (iface->cac_started) |
| 1350 | return hostapd_dfs_start_channel_switch_cac(iface); |
| 1351 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1352 | /* |
| 1353 | * Allow selection of DFS channel in ETSI to comply with |
| 1354 | * uniform spreading. |
| 1355 | */ |
| 1356 | if (iface->dfs_domain == HOSTAPD_DFS_REGION_ETSI) |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1357 | channel_type = DFS_ANY_CHANNEL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1358 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1359 | /* Perform channel switch/CSA */ |
| 1360 | channel = dfs_get_valid_channel(iface, &secondary_channel, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1361 | &oper_centr_freq_seg0_idx, |
| 1362 | &oper_centr_freq_seg1_idx, |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1363 | channel_type); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1364 | |
| 1365 | if (!channel) { |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 1366 | /* |
| 1367 | * If there is no channel to switch immediately to, check if |
| 1368 | * there is another channel where we can switch even if it |
| 1369 | * requires to perform a CAC first. |
| 1370 | */ |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1371 | channel_type = DFS_ANY_CHANNEL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1372 | channel = dfs_downgrade_bandwidth(iface, &secondary_channel, |
| 1373 | &oper_centr_freq_seg0_idx, |
| 1374 | &oper_centr_freq_seg1_idx, |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1375 | &channel_type); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1376 | if (!channel) { |
| 1377 | /* |
| 1378 | * Toggle interface state to enter DFS state |
| 1379 | * until NOP is finished. |
| 1380 | */ |
| 1381 | hostapd_disable_iface(iface); |
| 1382 | hostapd_enable_iface(iface); |
| 1383 | return 0; |
| 1384 | } |
| 1385 | |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1386 | if (channel_type == DFS_ANY_CHANNEL) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1387 | iface->freq = channel->freq; |
| 1388 | iface->conf->channel = channel->chan; |
| 1389 | iface->conf->secondary_channel = secondary_channel; |
| 1390 | hostapd_set_oper_centr_freq_seg0_idx( |
| 1391 | iface->conf, oper_centr_freq_seg0_idx); |
| 1392 | hostapd_set_oper_centr_freq_seg1_idx( |
| 1393 | iface->conf, oper_centr_freq_seg1_idx); |
| 1394 | |
| 1395 | hostapd_disable_iface(iface); |
| 1396 | hostapd_enable_iface(iface); |
| 1397 | return 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 1398 | } |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 1399 | } |
| 1400 | |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1401 | return hostapd_dfs_request_channel_switch(iface, channel->chan, |
| 1402 | channel->freq, |
| 1403 | secondary_channel, |
| 1404 | current_vht_oper_chwidth, |
| 1405 | oper_centr_freq_seg0_idx, |
| 1406 | oper_centr_freq_seg1_idx); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1410 | int hostapd_dfs_radar_detected(struct hostapd_iface *iface, int freq, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1411 | int ht_enabled, int chan_offset, int chan_width, |
| 1412 | int cf1, int cf2) |
| 1413 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1414 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_RADAR_DETECTED |
| 1415 | "freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d", |
| 1416 | freq, ht_enabled, chan_offset, chan_width, cf1, cf2); |
| 1417 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1418 | /* Proceed only if DFS is not offloaded to the driver */ |
| 1419 | if (iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) |
| 1420 | return 0; |
| 1421 | |
| 1422 | if (!iface->conf->ieee80211h) |
| 1423 | return 0; |
| 1424 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1425 | /* mark radar frequency as invalid */ |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1426 | if (!set_dfs_state(iface, freq, ht_enabled, chan_offset, chan_width, |
| 1427 | cf1, cf2, HOSTAPD_CHAN_DFS_UNAVAILABLE)) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1428 | return 0; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1429 | |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1430 | if (!hostapd_dfs_is_background_event(iface, freq)) { |
| 1431 | /* Skip if reported radar event not overlapped our channels */ |
| 1432 | if (!dfs_are_channels_overlapped(iface, freq, chan_width, |
| 1433 | cf1, cf2)) |
| 1434 | return 0; |
| 1435 | } |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1436 | |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1437 | if (hostapd_dfs_background_start_channel_switch(iface, freq)) { |
| 1438 | /* Radar detected while operating, switch the channel. */ |
| 1439 | return hostapd_dfs_start_channel_switch(iface); |
| 1440 | } |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1441 | |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1442 | return 0; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
| 1445 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1446 | int hostapd_dfs_nop_finished(struct hostapd_iface *iface, int freq, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1447 | int ht_enabled, int chan_offset, int chan_width, |
| 1448 | int cf1, int cf2) |
| 1449 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1450 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_NOP_FINISHED |
| 1451 | "freq=%d ht_enabled=%d chan_offset=%d chan_width=%d cf1=%d cf2=%d", |
| 1452 | freq, ht_enabled, chan_offset, chan_width, cf1, cf2); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1453 | |
| 1454 | /* Proceed only if DFS is not offloaded to the driver */ |
| 1455 | if (iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) |
| 1456 | return 0; |
| 1457 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1458 | /* TODO add correct implementation here */ |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1459 | set_dfs_state(iface, freq, ht_enabled, chan_offset, chan_width, |
| 1460 | cf1, cf2, HOSTAPD_CHAN_DFS_USABLE); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 1461 | |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1462 | if (iface->state == HAPD_IFACE_DFS && !iface->cac_started) { |
| 1463 | /* Handle cases where all channels were initially unavailable */ |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 1464 | hostapd_handle_dfs(iface); |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1465 | } else if (dfs_use_radar_background(iface) && |
| 1466 | iface->radar_background.channel == -1) { |
| 1467 | /* Reset radar background chain if disabled */ |
| 1468 | hostpad_dfs_update_background_chain(iface); |
| 1469 | } |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 1470 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1471 | return 0; |
| 1472 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1473 | |
| 1474 | |
| 1475 | int hostapd_is_dfs_required(struct hostapd_iface *iface) |
| 1476 | { |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 1477 | int n_chans, n_chans1, start_chan_idx, start_chan_idx1, res; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1478 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1479 | if ((!(iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) && |
| 1480 | !iface->conf->ieee80211h) || |
| 1481 | !iface->current_mode || |
Dmitry Shmidt | 61593f0 | 2014-04-21 16:27:35 -0700 | [diff] [blame] | 1482 | iface->current_mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 1483 | return 0; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1484 | |
| 1485 | /* Get start (first) channel for current configuration */ |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 1486 | start_chan_idx = dfs_get_start_chan_idx(iface, &start_chan_idx1); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1487 | if (start_chan_idx == -1) |
| 1488 | return -1; |
| 1489 | |
| 1490 | /* Get number of used channels, depend on width */ |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 1491 | n_chans = dfs_get_used_n_chans(iface, &n_chans1); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1492 | |
| 1493 | /* Check if any of configured channels require DFS */ |
Dmitry Shmidt | a7b06fa | 2014-10-09 12:56:52 -0700 | [diff] [blame] | 1494 | res = dfs_check_chans_radar(iface, start_chan_idx, n_chans); |
| 1495 | if (res) |
| 1496 | return res; |
| 1497 | if (start_chan_idx1 >= 0 && n_chans1 > 0) |
| 1498 | res = dfs_check_chans_radar(iface, start_chan_idx1, n_chans1); |
| 1499 | return res; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1500 | } |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1501 | |
| 1502 | |
| 1503 | int hostapd_dfs_start_cac(struct hostapd_iface *iface, int freq, |
| 1504 | int ht_enabled, int chan_offset, int chan_width, |
| 1505 | int cf1, int cf2) |
| 1506 | { |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1507 | if (hostapd_dfs_is_background_event(iface, freq)) { |
| 1508 | iface->radar_background.cac_started = 1; |
| 1509 | } else { |
| 1510 | /* This is called when the driver indicates that an offloaded |
| 1511 | * DFS has started CAC. */ |
| 1512 | hostapd_set_state(iface, HAPD_IFACE_DFS); |
| 1513 | iface->cac_started = 1; |
| 1514 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1515 | /* TODO: How to check CAC time for ETSI weather channels? */ |
| 1516 | iface->dfs_cac_ms = 60000; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1517 | wpa_msg(iface->bss[0]->msg_ctx, MSG_INFO, DFS_EVENT_CAC_START |
| 1518 | "freq=%d chan=%d chan_offset=%d width=%d seg0=%d " |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1519 | "seg1=%d cac_time=%ds%s", |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1520 | freq, (freq - 5000) / 5, chan_offset, chan_width, cf1, cf2, |
Sunil Ravi | 59fa4b4 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1521 | iface->dfs_cac_ms / 1000, |
| 1522 | hostapd_dfs_is_background_event(iface, freq) ? |
| 1523 | " (background)" : ""); |
| 1524 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1525 | os_get_reltime(&iface->dfs_cac_start); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1526 | return 0; |
| 1527 | } |
| 1528 | |
| 1529 | |
| 1530 | /* |
| 1531 | * Main DFS handler for offloaded case. |
| 1532 | * 2 - continue channel/AP setup for non-DFS channel |
| 1533 | * 1 - continue channel/AP setup for DFS channel |
| 1534 | * 0 - channel/AP setup will be continued after CAC |
| 1535 | * -1 - hit critical error |
| 1536 | */ |
| 1537 | int hostapd_handle_dfs_offload(struct hostapd_iface *iface) |
| 1538 | { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1539 | int dfs_res; |
| 1540 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1541 | wpa_printf(MSG_DEBUG, "%s: iface->cac_started: %d", |
| 1542 | __func__, iface->cac_started); |
| 1543 | |
| 1544 | /* |
| 1545 | * If DFS has already been started, then we are being called from a |
| 1546 | * callback to continue AP/channel setup. Reset the CAC start flag and |
| 1547 | * return. |
| 1548 | */ |
| 1549 | if (iface->cac_started) { |
| 1550 | wpa_printf(MSG_DEBUG, "%s: iface->cac_started: %d", |
| 1551 | __func__, iface->cac_started); |
| 1552 | iface->cac_started = 0; |
| 1553 | return 1; |
| 1554 | } |
| 1555 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1556 | dfs_res = hostapd_is_dfs_required(iface); |
| 1557 | if (dfs_res > 0) { |
| 1558 | wpa_printf(MSG_DEBUG, |
| 1559 | "%s: freq %d MHz requires DFS for %d chans", |
| 1560 | __func__, iface->freq, dfs_res); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1561 | return 0; |
| 1562 | } |
| 1563 | |
| 1564 | wpa_printf(MSG_DEBUG, |
| 1565 | "%s: freq %d MHz does not require DFS. Continue channel/AP setup", |
| 1566 | __func__, iface->freq); |
| 1567 | return 2; |
| 1568 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1569 | |
| 1570 | |
| 1571 | int hostapd_is_dfs_overlap(struct hostapd_iface *iface, enum chan_width width, |
| 1572 | int center_freq) |
| 1573 | { |
| 1574 | struct hostapd_channel_data *chan; |
| 1575 | struct hostapd_hw_modes *mode = iface->current_mode; |
| 1576 | int half_width; |
| 1577 | int res = 0; |
| 1578 | int i; |
| 1579 | |
| 1580 | if (!iface->conf->ieee80211h || !mode || |
| 1581 | mode->mode != HOSTAPD_MODE_IEEE80211A) |
| 1582 | return 0; |
| 1583 | |
| 1584 | switch (width) { |
| 1585 | case CHAN_WIDTH_20_NOHT: |
| 1586 | case CHAN_WIDTH_20: |
| 1587 | half_width = 10; |
| 1588 | break; |
| 1589 | case CHAN_WIDTH_40: |
| 1590 | half_width = 20; |
| 1591 | break; |
| 1592 | case CHAN_WIDTH_80: |
| 1593 | case CHAN_WIDTH_80P80: |
| 1594 | half_width = 40; |
| 1595 | break; |
| 1596 | case CHAN_WIDTH_160: |
| 1597 | half_width = 80; |
| 1598 | break; |
| 1599 | default: |
| 1600 | wpa_printf(MSG_WARNING, "DFS chanwidth %d not supported", |
| 1601 | width); |
| 1602 | return 0; |
| 1603 | } |
| 1604 | |
| 1605 | for (i = 0; i < mode->num_channels; i++) { |
| 1606 | chan = &mode->channels[i]; |
| 1607 | |
| 1608 | if (!(chan->flag & HOSTAPD_CHAN_RADAR)) |
| 1609 | continue; |
| 1610 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1611 | if ((chan->flag & HOSTAPD_CHAN_DFS_MASK) == |
| 1612 | HOSTAPD_CHAN_DFS_AVAILABLE) |
| 1613 | continue; |
| 1614 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1615 | if (center_freq - chan->freq < half_width && |
| 1616 | chan->freq - center_freq < half_width) |
| 1617 | res++; |
| 1618 | } |
| 1619 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1620 | wpa_printf(MSG_DEBUG, "DFS CAC required: (%d, %d): in range: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1621 | center_freq - half_width, center_freq + half_width, |
| 1622 | res ? "yes" : "no"); |
| 1623 | |
| 1624 | return res; |
| 1625 | } |