Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file contains helper code to handle channel |
| 3 | * settings and keeping track of what is possible at |
| 4 | * any point in time. |
| 5 | * |
| 6 | * Copyright 2009 Johannes Berg <johannes@sipsolutions.net> |
| 7 | */ |
| 8 | |
Alexander Simon | 54858ee5b | 2011-11-30 16:56:32 +0100 | [diff] [blame] | 9 | #include <linux/export.h> |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 10 | #include <net/cfg80211.h> |
| 11 | #include "core.h" |
Hila Gonen | e35e4d2 | 2012-06-27 17:19:42 +0300 | [diff] [blame] | 12 | #include "rdev-ops.h" |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 13 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 14 | void cfg80211_chandef_create(struct cfg80211_chan_def *chandef, |
| 15 | struct ieee80211_channel *chan, |
| 16 | enum nl80211_channel_type chan_type) |
| 17 | { |
| 18 | if (WARN_ON(!chan)) |
| 19 | return; |
| 20 | |
| 21 | chandef->chan = chan; |
| 22 | chandef->center_freq2 = 0; |
| 23 | |
| 24 | switch (chan_type) { |
| 25 | case NL80211_CHAN_NO_HT: |
| 26 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 27 | chandef->center_freq1 = chan->center_freq; |
| 28 | break; |
| 29 | case NL80211_CHAN_HT20: |
| 30 | chandef->width = NL80211_CHAN_WIDTH_20; |
| 31 | chandef->center_freq1 = chan->center_freq; |
| 32 | break; |
| 33 | case NL80211_CHAN_HT40PLUS: |
| 34 | chandef->width = NL80211_CHAN_WIDTH_40; |
| 35 | chandef->center_freq1 = chan->center_freq + 10; |
| 36 | break; |
| 37 | case NL80211_CHAN_HT40MINUS: |
| 38 | chandef->width = NL80211_CHAN_WIDTH_40; |
| 39 | chandef->center_freq1 = chan->center_freq - 10; |
| 40 | break; |
| 41 | default: |
| 42 | WARN_ON(1); |
| 43 | } |
| 44 | } |
| 45 | EXPORT_SYMBOL(cfg80211_chandef_create); |
| 46 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 47 | bool cfg80211_chandef_valid(const struct cfg80211_chan_def *chandef) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 48 | { |
| 49 | u32 control_freq; |
| 50 | |
| 51 | if (!chandef->chan) |
| 52 | return false; |
| 53 | |
| 54 | control_freq = chandef->chan->center_freq; |
| 55 | |
| 56 | switch (chandef->width) { |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 57 | case NL80211_CHAN_WIDTH_5: |
| 58 | case NL80211_CHAN_WIDTH_10: |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 59 | case NL80211_CHAN_WIDTH_20: |
| 60 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 61 | if (chandef->center_freq1 != control_freq) |
| 62 | return false; |
| 63 | if (chandef->center_freq2) |
| 64 | return false; |
| 65 | break; |
| 66 | case NL80211_CHAN_WIDTH_40: |
| 67 | if (chandef->center_freq1 != control_freq + 10 && |
| 68 | chandef->center_freq1 != control_freq - 10) |
| 69 | return false; |
| 70 | if (chandef->center_freq2) |
| 71 | return false; |
| 72 | break; |
| 73 | case NL80211_CHAN_WIDTH_80P80: |
| 74 | if (chandef->center_freq1 != control_freq + 30 && |
| 75 | chandef->center_freq1 != control_freq + 10 && |
| 76 | chandef->center_freq1 != control_freq - 10 && |
| 77 | chandef->center_freq1 != control_freq - 30) |
| 78 | return false; |
| 79 | if (!chandef->center_freq2) |
| 80 | return false; |
Johannes Berg | 9cab315 | 2012-12-14 00:19:08 +0100 | [diff] [blame] | 81 | /* adjacent is not allowed -- that's a 160 MHz channel */ |
| 82 | if (chandef->center_freq1 - chandef->center_freq2 == 80 || |
| 83 | chandef->center_freq2 - chandef->center_freq1 == 80) |
| 84 | return false; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 85 | break; |
| 86 | case NL80211_CHAN_WIDTH_80: |
| 87 | if (chandef->center_freq1 != control_freq + 30 && |
| 88 | chandef->center_freq1 != control_freq + 10 && |
| 89 | chandef->center_freq1 != control_freq - 10 && |
| 90 | chandef->center_freq1 != control_freq - 30) |
| 91 | return false; |
| 92 | if (chandef->center_freq2) |
| 93 | return false; |
| 94 | break; |
| 95 | case NL80211_CHAN_WIDTH_160: |
| 96 | if (chandef->center_freq1 != control_freq + 70 && |
| 97 | chandef->center_freq1 != control_freq + 50 && |
| 98 | chandef->center_freq1 != control_freq + 30 && |
| 99 | chandef->center_freq1 != control_freq + 10 && |
| 100 | chandef->center_freq1 != control_freq - 10 && |
| 101 | chandef->center_freq1 != control_freq - 30 && |
| 102 | chandef->center_freq1 != control_freq - 50 && |
| 103 | chandef->center_freq1 != control_freq - 70) |
| 104 | return false; |
| 105 | if (chandef->center_freq2) |
| 106 | return false; |
| 107 | break; |
| 108 | default: |
| 109 | return false; |
| 110 | } |
| 111 | |
| 112 | return true; |
| 113 | } |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 114 | EXPORT_SYMBOL(cfg80211_chandef_valid); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 115 | |
| 116 | static void chandef_primary_freqs(const struct cfg80211_chan_def *c, |
| 117 | int *pri40, int *pri80) |
| 118 | { |
| 119 | int tmp; |
| 120 | |
| 121 | switch (c->width) { |
| 122 | case NL80211_CHAN_WIDTH_40: |
| 123 | *pri40 = c->center_freq1; |
| 124 | *pri80 = 0; |
| 125 | break; |
| 126 | case NL80211_CHAN_WIDTH_80: |
| 127 | case NL80211_CHAN_WIDTH_80P80: |
| 128 | *pri80 = c->center_freq1; |
| 129 | /* n_P20 */ |
| 130 | tmp = (30 + c->chan->center_freq - c->center_freq1)/20; |
| 131 | /* n_P40 */ |
| 132 | tmp /= 2; |
| 133 | /* freq_P40 */ |
| 134 | *pri40 = c->center_freq1 - 20 + 40 * tmp; |
| 135 | break; |
| 136 | case NL80211_CHAN_WIDTH_160: |
| 137 | /* n_P20 */ |
| 138 | tmp = (70 + c->chan->center_freq - c->center_freq1)/20; |
| 139 | /* n_P40 */ |
| 140 | tmp /= 2; |
| 141 | /* freq_P40 */ |
| 142 | *pri40 = c->center_freq1 - 60 + 40 * tmp; |
| 143 | /* n_P80 */ |
| 144 | tmp /= 2; |
| 145 | *pri80 = c->center_freq1 - 40 + 80 * tmp; |
| 146 | break; |
| 147 | default: |
| 148 | WARN_ON_ONCE(1); |
| 149 | } |
| 150 | } |
| 151 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 152 | static int cfg80211_chandef_get_width(const struct cfg80211_chan_def *c) |
| 153 | { |
| 154 | int width; |
| 155 | |
| 156 | switch (c->width) { |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 157 | case NL80211_CHAN_WIDTH_5: |
| 158 | width = 5; |
| 159 | break; |
| 160 | case NL80211_CHAN_WIDTH_10: |
| 161 | width = 10; |
| 162 | break; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 163 | case NL80211_CHAN_WIDTH_20: |
| 164 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 165 | width = 20; |
| 166 | break; |
| 167 | case NL80211_CHAN_WIDTH_40: |
| 168 | width = 40; |
| 169 | break; |
| 170 | case NL80211_CHAN_WIDTH_80P80: |
| 171 | case NL80211_CHAN_WIDTH_80: |
| 172 | width = 80; |
| 173 | break; |
| 174 | case NL80211_CHAN_WIDTH_160: |
| 175 | width = 160; |
| 176 | break; |
| 177 | default: |
| 178 | WARN_ON_ONCE(1); |
| 179 | return -1; |
| 180 | } |
| 181 | return width; |
| 182 | } |
| 183 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 184 | const struct cfg80211_chan_def * |
| 185 | cfg80211_chandef_compatible(const struct cfg80211_chan_def *c1, |
| 186 | const struct cfg80211_chan_def *c2) |
| 187 | { |
| 188 | u32 c1_pri40, c1_pri80, c2_pri40, c2_pri80; |
| 189 | |
| 190 | /* If they are identical, return */ |
| 191 | if (cfg80211_chandef_identical(c1, c2)) |
| 192 | return c1; |
| 193 | |
| 194 | /* otherwise, must have same control channel */ |
| 195 | if (c1->chan != c2->chan) |
| 196 | return NULL; |
| 197 | |
| 198 | /* |
| 199 | * If they have the same width, but aren't identical, |
| 200 | * then they can't be compatible. |
| 201 | */ |
| 202 | if (c1->width == c2->width) |
| 203 | return NULL; |
| 204 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 205 | /* |
| 206 | * can't be compatible if one of them is 5 or 10 MHz, |
| 207 | * but they don't have the same width. |
| 208 | */ |
| 209 | if (c1->width == NL80211_CHAN_WIDTH_5 || |
| 210 | c1->width == NL80211_CHAN_WIDTH_10 || |
| 211 | c2->width == NL80211_CHAN_WIDTH_5 || |
| 212 | c2->width == NL80211_CHAN_WIDTH_10) |
| 213 | return NULL; |
| 214 | |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 215 | if (c1->width == NL80211_CHAN_WIDTH_20_NOHT || |
| 216 | c1->width == NL80211_CHAN_WIDTH_20) |
| 217 | return c2; |
| 218 | |
| 219 | if (c2->width == NL80211_CHAN_WIDTH_20_NOHT || |
| 220 | c2->width == NL80211_CHAN_WIDTH_20) |
| 221 | return c1; |
| 222 | |
| 223 | chandef_primary_freqs(c1, &c1_pri40, &c1_pri80); |
| 224 | chandef_primary_freqs(c2, &c2_pri40, &c2_pri80); |
| 225 | |
| 226 | if (c1_pri40 != c2_pri40) |
| 227 | return NULL; |
| 228 | |
| 229 | WARN_ON(!c1_pri80 && !c2_pri80); |
| 230 | if (c1_pri80 && c2_pri80 && c1_pri80 != c2_pri80) |
| 231 | return NULL; |
| 232 | |
| 233 | if (c1->width > c2->width) |
| 234 | return c1; |
| 235 | return c2; |
| 236 | } |
| 237 | EXPORT_SYMBOL(cfg80211_chandef_compatible); |
| 238 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 239 | static void cfg80211_set_chans_dfs_state(struct wiphy *wiphy, u32 center_freq, |
| 240 | u32 bandwidth, |
| 241 | enum nl80211_dfs_state dfs_state) |
| 242 | { |
| 243 | struct ieee80211_channel *c; |
| 244 | u32 freq; |
| 245 | |
| 246 | for (freq = center_freq - bandwidth/2 + 10; |
| 247 | freq <= center_freq + bandwidth/2 - 10; |
| 248 | freq += 20) { |
| 249 | c = ieee80211_get_channel(wiphy, freq); |
| 250 | if (!c || !(c->flags & IEEE80211_CHAN_RADAR)) |
| 251 | continue; |
| 252 | |
| 253 | c->dfs_state = dfs_state; |
| 254 | c->dfs_state_entered = jiffies; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | void cfg80211_set_dfs_state(struct wiphy *wiphy, |
| 259 | const struct cfg80211_chan_def *chandef, |
| 260 | enum nl80211_dfs_state dfs_state) |
| 261 | { |
| 262 | int width; |
| 263 | |
| 264 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 265 | return; |
| 266 | |
| 267 | width = cfg80211_chandef_get_width(chandef); |
| 268 | if (width < 0) |
| 269 | return; |
| 270 | |
| 271 | cfg80211_set_chans_dfs_state(wiphy, chandef->center_freq1, |
| 272 | width, dfs_state); |
| 273 | |
| 274 | if (!chandef->center_freq2) |
| 275 | return; |
| 276 | cfg80211_set_chans_dfs_state(wiphy, chandef->center_freq2, |
| 277 | width, dfs_state); |
| 278 | } |
| 279 | |
Janusz Dziedzic | 40d1ba6 | 2013-11-05 14:48:47 +0100 | [diff] [blame] | 280 | static u32 cfg80211_get_start_freq(u32 center_freq, |
| 281 | u32 bandwidth) |
| 282 | { |
| 283 | u32 start_freq; |
| 284 | |
| 285 | if (bandwidth <= 20) |
| 286 | start_freq = center_freq; |
| 287 | else |
| 288 | start_freq = center_freq - bandwidth/2 + 10; |
| 289 | |
| 290 | return start_freq; |
| 291 | } |
| 292 | |
| 293 | static u32 cfg80211_get_end_freq(u32 center_freq, |
| 294 | u32 bandwidth) |
| 295 | { |
| 296 | u32 end_freq; |
| 297 | |
| 298 | if (bandwidth <= 20) |
| 299 | end_freq = center_freq; |
| 300 | else |
| 301 | end_freq = center_freq + bandwidth/2 - 10; |
| 302 | |
| 303 | return end_freq; |
| 304 | } |
| 305 | |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 306 | static int cfg80211_get_chans_dfs_required(struct wiphy *wiphy, |
| 307 | u32 center_freq, |
| 308 | u32 bandwidth) |
| 309 | { |
| 310 | struct ieee80211_channel *c; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 311 | u32 freq, start_freq, end_freq; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 312 | |
Janusz Dziedzic | 40d1ba6 | 2013-11-05 14:48:47 +0100 | [diff] [blame] | 313 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); |
| 314 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 315 | |
| 316 | for (freq = start_freq; freq <= end_freq; freq += 20) { |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 317 | c = ieee80211_get_channel(wiphy, freq); |
| 318 | if (!c) |
| 319 | return -EINVAL; |
| 320 | |
| 321 | if (c->flags & IEEE80211_CHAN_RADAR) |
| 322 | return 1; |
| 323 | } |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | |
| 328 | int cfg80211_chandef_dfs_required(struct wiphy *wiphy, |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 329 | const struct cfg80211_chan_def *chandef, |
| 330 | enum nl80211_iftype iftype) |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 331 | { |
| 332 | int width; |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 333 | int ret; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 334 | |
| 335 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 336 | return -EINVAL; |
| 337 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 338 | switch (iftype) { |
| 339 | case NL80211_IFTYPE_ADHOC: |
| 340 | case NL80211_IFTYPE_AP: |
| 341 | case NL80211_IFTYPE_P2P_GO: |
| 342 | case NL80211_IFTYPE_MESH_POINT: |
| 343 | width = cfg80211_chandef_get_width(chandef); |
| 344 | if (width < 0) |
| 345 | return -EINVAL; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 346 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 347 | ret = cfg80211_get_chans_dfs_required(wiphy, |
| 348 | chandef->center_freq1, |
| 349 | width); |
| 350 | if (ret < 0) |
| 351 | return ret; |
| 352 | else if (ret > 0) |
| 353 | return BIT(chandef->width); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 354 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 355 | if (!chandef->center_freq2) |
| 356 | return 0; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 357 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 358 | ret = cfg80211_get_chans_dfs_required(wiphy, |
| 359 | chandef->center_freq2, |
| 360 | width); |
| 361 | if (ret < 0) |
| 362 | return ret; |
| 363 | else if (ret > 0) |
| 364 | return BIT(chandef->width); |
| 365 | |
| 366 | break; |
| 367 | case NL80211_IFTYPE_STATION: |
| 368 | case NL80211_IFTYPE_P2P_CLIENT: |
| 369 | case NL80211_IFTYPE_MONITOR: |
| 370 | case NL80211_IFTYPE_AP_VLAN: |
| 371 | case NL80211_IFTYPE_WDS: |
| 372 | case NL80211_IFTYPE_P2P_DEVICE: |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 373 | break; |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 374 | case NL80211_IFTYPE_UNSPECIFIED: |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 375 | case NUM_NL80211_IFTYPES: |
| 376 | WARN_ON(1); |
| 377 | } |
| 378 | |
| 379 | return 0; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 380 | } |
Simon Wunderlich | 774f073 | 2013-08-28 13:41:28 +0200 | [diff] [blame] | 381 | EXPORT_SYMBOL(cfg80211_chandef_dfs_required); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 382 | |
Janusz Dziedzic | fe7c3a1 | 2013-11-05 14:48:48 +0100 | [diff] [blame] | 383 | static int cfg80211_get_chans_dfs_usable(struct wiphy *wiphy, |
| 384 | u32 center_freq, |
| 385 | u32 bandwidth) |
| 386 | { |
| 387 | struct ieee80211_channel *c; |
| 388 | u32 freq, start_freq, end_freq; |
| 389 | int count = 0; |
| 390 | |
| 391 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); |
| 392 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); |
| 393 | |
| 394 | /* |
| 395 | * Check entire range of channels for the bandwidth. |
| 396 | * Check all channels are DFS channels (DFS_USABLE or |
| 397 | * DFS_AVAILABLE). Return number of usable channels |
| 398 | * (require CAC). Allow DFS and non-DFS channel mix. |
| 399 | */ |
| 400 | for (freq = start_freq; freq <= end_freq; freq += 20) { |
| 401 | c = ieee80211_get_channel(wiphy, freq); |
| 402 | if (!c) |
| 403 | return -EINVAL; |
| 404 | |
| 405 | if (c->flags & IEEE80211_CHAN_DISABLED) |
| 406 | return -EINVAL; |
| 407 | |
| 408 | if (c->flags & IEEE80211_CHAN_RADAR) { |
| 409 | if (c->dfs_state == NL80211_DFS_UNAVAILABLE) |
| 410 | return -EINVAL; |
| 411 | |
| 412 | if (c->dfs_state == NL80211_DFS_USABLE) |
| 413 | count++; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | return count; |
| 418 | } |
| 419 | |
| 420 | bool cfg80211_chandef_dfs_usable(struct wiphy *wiphy, |
| 421 | const struct cfg80211_chan_def *chandef) |
| 422 | { |
| 423 | int width; |
| 424 | int r1, r2 = 0; |
| 425 | |
| 426 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 427 | return false; |
| 428 | |
| 429 | width = cfg80211_chandef_get_width(chandef); |
| 430 | if (width < 0) |
| 431 | return false; |
| 432 | |
| 433 | r1 = cfg80211_get_chans_dfs_usable(wiphy, chandef->center_freq1, |
| 434 | width); |
| 435 | |
| 436 | if (r1 < 0) |
| 437 | return false; |
| 438 | |
| 439 | switch (chandef->width) { |
| 440 | case NL80211_CHAN_WIDTH_80P80: |
| 441 | WARN_ON(!chandef->center_freq2); |
| 442 | r2 = cfg80211_get_chans_dfs_usable(wiphy, |
| 443 | chandef->center_freq2, |
| 444 | width); |
| 445 | if (r2 < 0) |
| 446 | return false; |
| 447 | break; |
| 448 | default: |
| 449 | WARN_ON(chandef->center_freq2); |
| 450 | break; |
| 451 | } |
| 452 | |
| 453 | return (r1 + r2 > 0); |
| 454 | } |
| 455 | |
| 456 | |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 457 | static bool cfg80211_get_chans_dfs_available(struct wiphy *wiphy, |
| 458 | u32 center_freq, |
| 459 | u32 bandwidth) |
| 460 | { |
| 461 | struct ieee80211_channel *c; |
| 462 | u32 freq, start_freq, end_freq; |
| 463 | |
| 464 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); |
| 465 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); |
| 466 | |
| 467 | /* |
| 468 | * Check entire range of channels for the bandwidth. |
| 469 | * If any channel in between is disabled or has not |
| 470 | * had gone through CAC return false |
| 471 | */ |
| 472 | for (freq = start_freq; freq <= end_freq; freq += 20) { |
| 473 | c = ieee80211_get_channel(wiphy, freq); |
| 474 | if (!c) |
| 475 | return false; |
| 476 | |
| 477 | if (c->flags & IEEE80211_CHAN_DISABLED) |
| 478 | return false; |
| 479 | |
| 480 | if ((c->flags & IEEE80211_CHAN_RADAR) && |
| 481 | (c->dfs_state != NL80211_DFS_AVAILABLE)) |
| 482 | return false; |
| 483 | } |
| 484 | |
| 485 | return true; |
| 486 | } |
| 487 | |
| 488 | static bool cfg80211_chandef_dfs_available(struct wiphy *wiphy, |
| 489 | const struct cfg80211_chan_def *chandef) |
| 490 | { |
| 491 | int width; |
| 492 | int r; |
| 493 | |
| 494 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 495 | return false; |
| 496 | |
| 497 | width = cfg80211_chandef_get_width(chandef); |
| 498 | if (width < 0) |
| 499 | return false; |
| 500 | |
| 501 | r = cfg80211_get_chans_dfs_available(wiphy, chandef->center_freq1, |
| 502 | width); |
| 503 | |
| 504 | /* If any of channels unavailable for cf1 just return */ |
| 505 | if (!r) |
| 506 | return r; |
| 507 | |
| 508 | switch (chandef->width) { |
| 509 | case NL80211_CHAN_WIDTH_80P80: |
| 510 | WARN_ON(!chandef->center_freq2); |
| 511 | r = cfg80211_get_chans_dfs_available(wiphy, |
| 512 | chandef->center_freq2, |
| 513 | width); |
| 514 | default: |
| 515 | WARN_ON(chandef->center_freq2); |
| 516 | break; |
| 517 | } |
| 518 | |
| 519 | return r; |
| 520 | } |
| 521 | |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 522 | static unsigned int cfg80211_get_chans_dfs_cac_time(struct wiphy *wiphy, |
| 523 | u32 center_freq, |
| 524 | u32 bandwidth) |
| 525 | { |
| 526 | struct ieee80211_channel *c; |
| 527 | u32 start_freq, end_freq, freq; |
| 528 | unsigned int dfs_cac_ms = 0; |
| 529 | |
| 530 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); |
| 531 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); |
| 532 | |
| 533 | for (freq = start_freq; freq <= end_freq; freq += 20) { |
| 534 | c = ieee80211_get_channel(wiphy, freq); |
| 535 | if (!c) |
| 536 | return 0; |
| 537 | |
| 538 | if (c->flags & IEEE80211_CHAN_DISABLED) |
| 539 | return 0; |
| 540 | |
| 541 | if (!(c->flags & IEEE80211_CHAN_RADAR)) |
| 542 | continue; |
| 543 | |
| 544 | if (c->dfs_cac_ms > dfs_cac_ms) |
| 545 | dfs_cac_ms = c->dfs_cac_ms; |
| 546 | } |
| 547 | |
| 548 | return dfs_cac_ms; |
| 549 | } |
| 550 | |
| 551 | unsigned int |
| 552 | cfg80211_chandef_dfs_cac_time(struct wiphy *wiphy, |
| 553 | const struct cfg80211_chan_def *chandef) |
| 554 | { |
| 555 | int width; |
| 556 | unsigned int t1 = 0, t2 = 0; |
| 557 | |
| 558 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
| 559 | return 0; |
| 560 | |
| 561 | width = cfg80211_chandef_get_width(chandef); |
| 562 | if (width < 0) |
| 563 | return 0; |
| 564 | |
| 565 | t1 = cfg80211_get_chans_dfs_cac_time(wiphy, |
| 566 | chandef->center_freq1, |
| 567 | width); |
| 568 | |
| 569 | if (!chandef->center_freq2) |
| 570 | return t1; |
| 571 | |
| 572 | t2 = cfg80211_get_chans_dfs_cac_time(wiphy, |
| 573 | chandef->center_freq2, |
| 574 | width); |
| 575 | |
| 576 | return max(t1, t2); |
| 577 | } |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 578 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 579 | static bool cfg80211_secondary_chans_ok(struct wiphy *wiphy, |
| 580 | u32 center_freq, u32 bandwidth, |
| 581 | u32 prohibited_flags) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 582 | { |
| 583 | struct ieee80211_channel *c; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 584 | u32 freq, start_freq, end_freq; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 585 | |
Janusz Dziedzic | 40d1ba6 | 2013-11-05 14:48:47 +0100 | [diff] [blame] | 586 | start_freq = cfg80211_get_start_freq(center_freq, bandwidth); |
| 587 | end_freq = cfg80211_get_end_freq(center_freq, bandwidth); |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 588 | |
| 589 | for (freq = start_freq; freq <= end_freq; freq += 20) { |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 590 | c = ieee80211_get_channel(wiphy, freq); |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 591 | if (!c || c->flags & prohibited_flags) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 592 | return false; |
| 593 | } |
| 594 | |
| 595 | return true; |
| 596 | } |
| 597 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 598 | bool cfg80211_chandef_usable(struct wiphy *wiphy, |
| 599 | const struct cfg80211_chan_def *chandef, |
| 600 | u32 prohibited_flags) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 601 | { |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 602 | struct ieee80211_sta_ht_cap *ht_cap; |
| 603 | struct ieee80211_sta_vht_cap *vht_cap; |
| 604 | u32 width, control_freq; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 605 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 606 | if (WARN_ON(!cfg80211_chandef_valid(chandef))) |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 607 | return false; |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 608 | |
| 609 | ht_cap = &wiphy->bands[chandef->chan->band]->ht_cap; |
| 610 | vht_cap = &wiphy->bands[chandef->chan->band]->vht_cap; |
| 611 | |
| 612 | control_freq = chandef->chan->center_freq; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 613 | |
| 614 | switch (chandef->width) { |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 615 | case NL80211_CHAN_WIDTH_5: |
| 616 | width = 5; |
| 617 | break; |
| 618 | case NL80211_CHAN_WIDTH_10: |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 619 | prohibited_flags |= IEEE80211_CHAN_NO_10MHZ; |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 620 | width = 10; |
| 621 | break; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 622 | case NL80211_CHAN_WIDTH_20: |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 623 | if (!ht_cap->ht_supported) |
| 624 | return false; |
| 625 | case NL80211_CHAN_WIDTH_20_NOHT: |
Rostislav Lisovy | ea077c1 | 2014-04-15 14:37:55 +0200 | [diff] [blame] | 626 | prohibited_flags |= IEEE80211_CHAN_NO_20MHZ; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 627 | width = 20; |
Mark Mentovai | 09a02fd | 2010-11-17 16:34:37 -0500 | [diff] [blame] | 628 | break; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 629 | case NL80211_CHAN_WIDTH_40: |
| 630 | width = 40; |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 631 | if (!ht_cap->ht_supported) |
| 632 | return false; |
| 633 | if (!(ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) || |
| 634 | ht_cap->cap & IEEE80211_HT_CAP_40MHZ_INTOLERANT) |
| 635 | return false; |
| 636 | if (chandef->center_freq1 < control_freq && |
| 637 | chandef->chan->flags & IEEE80211_CHAN_NO_HT40MINUS) |
| 638 | return false; |
| 639 | if (chandef->center_freq1 > control_freq && |
| 640 | chandef->chan->flags & IEEE80211_CHAN_NO_HT40PLUS) |
| 641 | return false; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 642 | break; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 643 | case NL80211_CHAN_WIDTH_80P80: |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 644 | if (!(vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)) |
| 645 | return false; |
| 646 | case NL80211_CHAN_WIDTH_80: |
| 647 | if (!vht_cap->vht_supported) |
| 648 | return false; |
Johannes Berg | c7a6ee2 | 2012-12-12 17:50:39 +0100 | [diff] [blame] | 649 | prohibited_flags |= IEEE80211_CHAN_NO_80MHZ; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 650 | width = 80; |
| 651 | break; |
| 652 | case NL80211_CHAN_WIDTH_160: |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 653 | if (!vht_cap->vht_supported) |
| 654 | return false; |
| 655 | if (!(vht_cap->cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ)) |
| 656 | return false; |
Johannes Berg | c7a6ee2 | 2012-12-12 17:50:39 +0100 | [diff] [blame] | 657 | prohibited_flags |= IEEE80211_CHAN_NO_160MHZ; |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 658 | width = 160; |
Mark Mentovai | 09a02fd | 2010-11-17 16:34:37 -0500 | [diff] [blame] | 659 | break; |
Luis R. Rodriguez | 9236d83 | 2010-11-12 16:31:23 -0800 | [diff] [blame] | 660 | default: |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 661 | WARN_ON_ONCE(1); |
Luis R. Rodriguez | 9236d83 | 2010-11-12 16:31:23 -0800 | [diff] [blame] | 662 | return false; |
Beni Lev | 4ee3e06 | 2012-08-27 12:49:39 +0300 | [diff] [blame] | 663 | } |
Luis R. Rodriguez | 9236d83 | 2010-11-12 16:31:23 -0800 | [diff] [blame] | 664 | |
Johannes Berg | c7a6ee2 | 2012-12-12 17:50:39 +0100 | [diff] [blame] | 665 | /* |
| 666 | * TODO: What if there are only certain 80/160/80+80 MHz channels |
| 667 | * allowed by the driver, or only certain combinations? |
| 668 | * For 40 MHz the driver can set the NO_HT40 flags, but for |
| 669 | * 80/160 MHz and in particular 80+80 MHz this isn't really |
| 670 | * feasible and we only have NO_80MHZ/NO_160MHZ so far but |
| 671 | * no way to cover 80+80 MHz or more complex restrictions. |
| 672 | * Note that such restrictions also need to be advertised to |
| 673 | * userspace, for example for P2P channel selection. |
| 674 | */ |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 675 | |
Johannes Berg | a6662db | 2012-12-04 20:49:42 +0100 | [diff] [blame] | 676 | if (width > 20) |
| 677 | prohibited_flags |= IEEE80211_CHAN_NO_OFDM; |
| 678 | |
Simon Wunderlich | 2f301ab | 2013-05-16 13:00:28 +0200 | [diff] [blame] | 679 | /* 5 and 10 MHz are only defined for the OFDM PHY */ |
| 680 | if (width < 20) |
| 681 | prohibited_flags |= IEEE80211_CHAN_NO_OFDM; |
| 682 | |
| 683 | |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 684 | if (!cfg80211_secondary_chans_ok(wiphy, chandef->center_freq1, |
| 685 | width, prohibited_flags)) |
| 686 | return false; |
| 687 | |
| 688 | if (!chandef->center_freq2) |
| 689 | return true; |
| 690 | return cfg80211_secondary_chans_ok(wiphy, chandef->center_freq2, |
| 691 | width, prohibited_flags); |
| 692 | } |
| 693 | EXPORT_SYMBOL(cfg80211_chandef_usable); |
| 694 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 695 | /* |
| 696 | * For GO only, check if the channel can be used under permissive conditions |
| 697 | * mandated by the some regulatory bodies, i.e., the channel is marked with |
| 698 | * IEEE80211_CHAN_GO_CONCURRENT and there is an additional station interface |
| 699 | * associated to an AP on the same channel or on the same UNII band |
| 700 | * (assuming that the AP is an authorized master). |
Ilan Peer | c8866e5 | 2014-02-23 09:13:03 +0200 | [diff] [blame] | 701 | * In addition allow the GO to operate on a channel on which indoor operation is |
| 702 | * allowed, iff we are currently operating in an indoor environment. |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 703 | */ |
| 704 | static bool cfg80211_go_permissive_chan(struct cfg80211_registered_device *rdev, |
| 705 | struct ieee80211_channel *chan) |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 706 | { |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 707 | struct wireless_dev *wdev_iter; |
| 708 | struct wiphy *wiphy = wiphy_idx_to_wiphy(rdev->wiphy_idx); |
| 709 | |
| 710 | ASSERT_RTNL(); |
| 711 | |
| 712 | if (!config_enabled(CONFIG_CFG80211_REG_RELAX_NO_IR) || |
Ilan Peer | c8866e5 | 2014-02-23 09:13:03 +0200 | [diff] [blame] | 713 | !(wiphy->regulatory_flags & REGULATORY_ENABLE_RELAX_NO_IR)) |
| 714 | return false; |
| 715 | |
| 716 | if (regulatory_indoor_allowed() && |
| 717 | (chan->flags & IEEE80211_CHAN_INDOOR_ONLY)) |
| 718 | return true; |
| 719 | |
| 720 | if (!(chan->flags & IEEE80211_CHAN_GO_CONCURRENT)) |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 721 | return false; |
| 722 | |
| 723 | /* |
| 724 | * Generally, it is possible to rely on another device/driver to allow |
| 725 | * the GO concurrent relaxation, however, since the device can further |
| 726 | * enforce the relaxation (by doing a similar verifications as this), |
| 727 | * and thus fail the GO instantiation, consider only the interfaces of |
| 728 | * the current registered device. |
| 729 | */ |
| 730 | list_for_each_entry(wdev_iter, &rdev->wdev_list, list) { |
| 731 | struct ieee80211_channel *other_chan = NULL; |
| 732 | int r1, r2; |
| 733 | |
| 734 | if (wdev_iter->iftype != NL80211_IFTYPE_STATION || |
| 735 | !netif_running(wdev_iter->netdev)) |
| 736 | continue; |
| 737 | |
| 738 | wdev_lock(wdev_iter); |
| 739 | if (wdev_iter->current_bss) |
| 740 | other_chan = wdev_iter->current_bss->pub.channel; |
| 741 | wdev_unlock(wdev_iter); |
| 742 | |
| 743 | if (!other_chan) |
| 744 | continue; |
| 745 | |
| 746 | if (chan == other_chan) |
| 747 | return true; |
| 748 | |
| 749 | if (chan->band != IEEE80211_BAND_5GHZ) |
| 750 | continue; |
| 751 | |
| 752 | r1 = cfg80211_get_unii(chan->center_freq); |
| 753 | r2 = cfg80211_get_unii(other_chan->center_freq); |
| 754 | |
Ilan Peer | 46d5372 | 2014-04-23 09:22:58 +0300 | [diff] [blame] | 755 | if (r1 != -EINVAL && r1 == r2) { |
| 756 | /* |
| 757 | * At some locations channels 149-165 are considered a |
| 758 | * bundle, but at other locations, e.g., Indonesia, |
| 759 | * channels 149-161 are considered a bundle while |
| 760 | * channel 165 is left out and considered to be in a |
| 761 | * different bundle. Thus, in case that there is a |
| 762 | * station interface connected to an AP on channel 165, |
| 763 | * it is assumed that channels 149-161 are allowed for |
| 764 | * GO operations. However, having a station interface |
| 765 | * connected to an AP on channels 149-161, does not |
| 766 | * allow GO operation on channel 165. |
| 767 | */ |
| 768 | if (chan->center_freq == 5825 && |
| 769 | other_chan->center_freq != 5825) |
| 770 | continue; |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 771 | return true; |
Ilan Peer | 46d5372 | 2014-04-23 09:22:58 +0300 | [diff] [blame] | 772 | } |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | return false; |
| 776 | } |
| 777 | |
| 778 | bool cfg80211_reg_can_beacon(struct wiphy *wiphy, |
| 779 | struct cfg80211_chan_def *chandef, |
| 780 | enum nl80211_iftype iftype) |
| 781 | { |
Zhao, Gang | f26cbf4 | 2014-04-21 12:53:03 +0800 | [diff] [blame] | 782 | struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy); |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 783 | bool res; |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 784 | u32 prohibited_flags = IEEE80211_CHAN_DISABLED | |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 785 | IEEE80211_CHAN_RADAR; |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 786 | |
Ilan Peer | 174e0cd | 2014-02-23 09:13:01 +0200 | [diff] [blame] | 787 | trace_cfg80211_reg_can_beacon(wiphy, chandef, iftype); |
| 788 | |
| 789 | /* |
| 790 | * Under certain conditions suggested by the some regulatory bodies |
| 791 | * a GO can operate on channels marked with IEEE80211_NO_IR |
| 792 | * so set this flag only if such relaxations are not enabled and |
| 793 | * the conditions are not met. |
| 794 | */ |
| 795 | if (iftype != NL80211_IFTYPE_P2P_GO || |
| 796 | !cfg80211_go_permissive_chan(rdev, chandef->chan)) |
| 797 | prohibited_flags |= IEEE80211_CHAN_NO_IR; |
Johannes Berg | 9f5e8f6 | 2012-11-22 16:59:45 +0100 | [diff] [blame] | 798 | |
Luciano Coelho | 00ec75f | 2014-05-15 13:05:39 +0300 | [diff] [blame] | 799 | if (cfg80211_chandef_dfs_required(wiphy, chandef, iftype) > 0 && |
Janusz Dziedzic | 6bc54fb | 2013-11-06 13:55:53 +0100 | [diff] [blame] | 800 | cfg80211_chandef_dfs_available(wiphy, chandef)) { |
| 801 | /* We can skip IEEE80211_CHAN_NO_IR if chandef dfs available */ |
| 802 | prohibited_flags = IEEE80211_CHAN_DISABLED; |
| 803 | } |
| 804 | |
| 805 | res = cfg80211_chandef_usable(wiphy, chandef, prohibited_flags); |
Johannes Berg | 3d9d1d6 | 2012-11-08 23:14:50 +0100 | [diff] [blame] | 806 | |
| 807 | trace_cfg80211_return_bool(res); |
| 808 | return res; |
Luis R. Rodriguez | 9236d83 | 2010-11-12 16:31:23 -0800 | [diff] [blame] | 809 | } |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 810 | EXPORT_SYMBOL(cfg80211_reg_can_beacon); |
Luis R. Rodriguez | 9236d83 | 2010-11-12 16:31:23 -0800 | [diff] [blame] | 811 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 812 | int cfg80211_set_monitor_channel(struct cfg80211_registered_device *rdev, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 813 | struct cfg80211_chan_def *chandef) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 814 | { |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 815 | if (!rdev->ops->set_monitor_channel) |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 816 | return -EOPNOTSUPP; |
Michal Kazior | 4f03c1e | 2012-06-29 12:47:03 +0200 | [diff] [blame] | 817 | if (!cfg80211_has_monitors_only(rdev)) |
| 818 | return -EBUSY; |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 819 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 820 | return rdev_set_monitor_channel(rdev, chandef); |
Johannes Berg | 59bbb6f | 2009-08-07 17:22:35 +0200 | [diff] [blame] | 821 | } |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 822 | |
| 823 | void |
Johannes Berg | 8e95ea4 | 2012-07-10 19:39:02 +0200 | [diff] [blame] | 824 | cfg80211_get_chan_state(struct wireless_dev *wdev, |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 825 | struct ieee80211_channel **chan, |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 826 | enum cfg80211_chan_mode *chanmode, |
| 827 | u8 *radar_detect) |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 828 | { |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 829 | int ret; |
| 830 | |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 831 | *chan = NULL; |
| 832 | *chanmode = CHAN_MODE_UNDEFINED; |
| 833 | |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 834 | ASSERT_WDEV_LOCK(wdev); |
| 835 | |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 836 | if (wdev->netdev && !netif_running(wdev->netdev)) |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 837 | return; |
| 838 | |
| 839 | switch (wdev->iftype) { |
| 840 | case NL80211_IFTYPE_ADHOC: |
| 841 | if (wdev->current_bss) { |
| 842 | *chan = wdev->current_bss->pub.channel; |
Simon Wunderlich | 5336fa8 | 2013-10-07 18:41:05 +0200 | [diff] [blame] | 843 | *chanmode = (wdev->ibss_fixed && |
| 844 | !wdev->ibss_dfs_possible) |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 845 | ? CHAN_MODE_SHARED |
| 846 | : CHAN_MODE_EXCLUSIVE; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 847 | |
| 848 | /* consider worst-case - IBSS can try to return to the |
| 849 | * original user-specified channel as creator */ |
| 850 | if (wdev->ibss_dfs_possible) |
| 851 | *radar_detect |= BIT(wdev->chandef.width); |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 852 | return; |
| 853 | } |
Johannes Berg | 0f0094b | 2013-10-25 12:46:44 +0200 | [diff] [blame] | 854 | break; |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 855 | case NL80211_IFTYPE_STATION: |
| 856 | case NL80211_IFTYPE_P2P_CLIENT: |
| 857 | if (wdev->current_bss) { |
| 858 | *chan = wdev->current_bss->pub.channel; |
| 859 | *chanmode = CHAN_MODE_SHARED; |
| 860 | return; |
| 861 | } |
| 862 | break; |
| 863 | case NL80211_IFTYPE_AP: |
| 864 | case NL80211_IFTYPE_P2P_GO: |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 865 | if (wdev->cac_started) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 866 | *chan = wdev->chandef.chan; |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 867 | *chanmode = CHAN_MODE_SHARED; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 868 | *radar_detect |= BIT(wdev->chandef.width); |
Simon Wunderlich | 04f3904 | 2013-02-08 18:16:19 +0100 | [diff] [blame] | 869 | } else if (wdev->beacon_interval) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 870 | *chan = wdev->chandef.chan; |
Felix Fietkau | f53594a | 2012-07-12 16:10:02 +0200 | [diff] [blame] | 871 | *chanmode = CHAN_MODE_SHARED; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 872 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 873 | ret = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 874 | &wdev->chandef, |
| 875 | wdev->iftype); |
| 876 | WARN_ON(ret < 0); |
| 877 | if (ret > 0) |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 878 | *radar_detect |= BIT(wdev->chandef.width); |
Felix Fietkau | f53594a | 2012-07-12 16:10:02 +0200 | [diff] [blame] | 879 | } |
| 880 | return; |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 881 | case NL80211_IFTYPE_MESH_POINT: |
Felix Fietkau | f53594a | 2012-07-12 16:10:02 +0200 | [diff] [blame] | 882 | if (wdev->mesh_id_len) { |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 883 | *chan = wdev->chandef.chan; |
Felix Fietkau | f53594a | 2012-07-12 16:10:02 +0200 | [diff] [blame] | 884 | *chanmode = CHAN_MODE_SHARED; |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 885 | |
Luciano Coelho | 2beb6dab | 2014-02-18 11:40:36 +0200 | [diff] [blame] | 886 | ret = cfg80211_chandef_dfs_required(wdev->wiphy, |
| 887 | &wdev->chandef, |
| 888 | wdev->iftype); |
| 889 | WARN_ON(ret < 0); |
| 890 | if (ret > 0) |
Michal Kazior | 9e0e296 | 2014-01-29 14:22:27 +0100 | [diff] [blame] | 891 | *radar_detect |= BIT(wdev->chandef.width); |
Felix Fietkau | f53594a | 2012-07-12 16:10:02 +0200 | [diff] [blame] | 892 | } |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 893 | return; |
| 894 | case NL80211_IFTYPE_MONITOR: |
| 895 | case NL80211_IFTYPE_AP_VLAN: |
| 896 | case NL80211_IFTYPE_WDS: |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 897 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | e7aceef | 2014-02-12 14:21:15 +0100 | [diff] [blame] | 898 | /* these interface types don't really have a channel */ |
Johannes Berg | 98104fde | 2012-06-16 00:19:54 +0200 | [diff] [blame] | 899 | return; |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 900 | case NL80211_IFTYPE_UNSPECIFIED: |
| 901 | case NUM_NL80211_IFTYPES: |
| 902 | WARN_ON(1); |
| 903 | } |
Michal Kazior | 26ab9a0 | 2012-06-29 12:47:00 +0200 | [diff] [blame] | 904 | } |