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