Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * mac80211 configuration hooks for cfg80211 |
| 3 | * |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4 | * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | b2eb0ee | 2015-06-01 22:54:13 +0200 | [diff] [blame] | 5 | * Copyright 2013-2015 Intel Mobile Communications GmbH |
Johannes Berg | e8e4f52 | 2017-03-08 11:12:10 +0100 | [diff] [blame] | 6 | * Copyright (C) 2015-2017 Intel Deutschland GmbH |
Haim Dreyfuss | e552af0 | 2018-03-28 13:24:10 +0300 | [diff] [blame] | 7 | * Copyright (C) 2018 Intel Corporation |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 8 | * |
| 9 | * This file is GPLv2 as found in COPYING. |
| 10 | */ |
| 11 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 12 | #include <linux/ieee80211.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 13 | #include <linux/nl80211.h> |
| 14 | #include <linux/rtnetlink.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 15 | #include <linux/slab.h> |
Eric W. Biederman | 881d966 | 2007-09-17 11:56:21 -0700 | [diff] [blame] | 16 | #include <net/net_namespace.h> |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 17 | #include <linux/rcupdate.h> |
Arik Nemtsov | dfe018b | 2011-09-28 14:12:52 +0300 | [diff] [blame] | 18 | #include <linux/if_ether.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 19 | #include <net/cfg80211.h> |
| 20 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 21 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 22 | #include "rate.h" |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 23 | #include "mesh.h" |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 24 | #include "wme.h" |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 25 | |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 26 | static void ieee80211_set_mu_mimo_follow(struct ieee80211_sub_if_data *sdata, |
| 27 | struct vif_params *params) |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 28 | { |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 29 | bool mu_mimo_groups = false; |
| 30 | bool mu_mimo_follow = false; |
| 31 | |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 32 | if (params->vht_mumimo_groups) { |
| 33 | u64 membership; |
| 34 | |
| 35 | BUILD_BUG_ON(sizeof(membership) != WLAN_MEMBERSHIP_LEN); |
| 36 | |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 37 | memcpy(sdata->vif.bss_conf.mu_group.membership, |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 38 | params->vht_mumimo_groups, WLAN_MEMBERSHIP_LEN); |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 39 | memcpy(sdata->vif.bss_conf.mu_group.position, |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 40 | params->vht_mumimo_groups + WLAN_MEMBERSHIP_LEN, |
| 41 | WLAN_USER_POSITION_LEN); |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 42 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MU_GROUPS); |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 43 | /* don't care about endianness - just check for 0 */ |
| 44 | memcpy(&membership, params->vht_mumimo_groups, |
| 45 | WLAN_MEMBERSHIP_LEN); |
| 46 | mu_mimo_groups = membership != 0; |
| 47 | } |
| 48 | |
| 49 | if (params->vht_mumimo_follow_addr) { |
| 50 | mu_mimo_follow = |
| 51 | is_valid_ether_addr(params->vht_mumimo_follow_addr); |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 52 | ether_addr_copy(sdata->u.mntr.mu_follow_addr, |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 53 | params->vht_mumimo_follow_addr); |
| 54 | } |
| 55 | |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 56 | sdata->vif.mu_mimo_owner = mu_mimo_groups || mu_mimo_follow; |
| 57 | } |
| 58 | |
| 59 | static int ieee80211_set_mon_options(struct ieee80211_sub_if_data *sdata, |
| 60 | struct vif_params *params) |
| 61 | { |
| 62 | struct ieee80211_local *local = sdata->local; |
| 63 | struct ieee80211_sub_if_data *monitor_sdata; |
| 64 | |
| 65 | /* check flags first */ |
| 66 | if (params->flags && ieee80211_sdata_running(sdata)) { |
| 67 | u32 mask = MONITOR_FLAG_COOK_FRAMES | MONITOR_FLAG_ACTIVE; |
| 68 | |
| 69 | /* |
| 70 | * Prohibit MONITOR_FLAG_COOK_FRAMES and |
| 71 | * MONITOR_FLAG_ACTIVE to be changed while the |
| 72 | * interface is up. |
| 73 | * Else we would need to add a lot of cruft |
| 74 | * to update everything: |
| 75 | * cooked_mntrs, monitor and all fif_* counters |
| 76 | * reconfigure hardware |
| 77 | */ |
| 78 | if ((params->flags & mask) != (sdata->u.mntr.flags & mask)) |
| 79 | return -EBUSY; |
| 80 | } |
| 81 | |
| 82 | /* also validate MU-MIMO change */ |
| 83 | monitor_sdata = rtnl_dereference(local->monitor_sdata); |
| 84 | |
| 85 | if (!monitor_sdata && |
| 86 | (params->vht_mumimo_groups || params->vht_mumimo_follow_addr)) |
| 87 | return -EOPNOTSUPP; |
| 88 | |
| 89 | /* apply all changes now - no failures allowed */ |
| 90 | |
| 91 | if (monitor_sdata) |
| 92 | ieee80211_set_mu_mimo_follow(monitor_sdata, params); |
| 93 | |
| 94 | if (params->flags) { |
| 95 | if (ieee80211_sdata_running(sdata)) { |
| 96 | ieee80211_adjust_monitor_flags(sdata, -1); |
| 97 | sdata->u.mntr.flags = params->flags; |
| 98 | ieee80211_adjust_monitor_flags(sdata, 1); |
| 99 | |
| 100 | ieee80211_configure_filter(local); |
| 101 | } else { |
| 102 | /* |
| 103 | * Because the interface is down, ieee80211_do_stop |
| 104 | * and ieee80211_do_open take care of "everything" |
| 105 | * mentioned in the comment above. |
| 106 | */ |
| 107 | sdata->u.mntr.flags = params->flags; |
| 108 | } |
| 109 | } |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 110 | |
| 111 | return 0; |
| 112 | } |
| 113 | |
Johannes Berg | 552bff0 | 2012-09-19 09:26:06 +0200 | [diff] [blame] | 114 | static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy, |
| 115 | const char *name, |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 116 | unsigned char name_assign_type, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 117 | enum nl80211_iftype type, |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 118 | struct vif_params *params) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 119 | { |
| 120 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 121 | struct wireless_dev *wdev; |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 122 | struct ieee80211_sub_if_data *sdata; |
| 123 | int err; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 124 | |
Tom Gundersen | 6bab2e19 | 2015-03-18 11:13:39 +0100 | [diff] [blame] | 125 | err = ieee80211_if_add(local, name, name_assign_type, &wdev, type, params); |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 126 | if (err) |
| 127 | return ERR_PTR(err); |
Michael Wu | 8cc9a73 | 2008-01-31 19:48:23 +0100 | [diff] [blame] | 128 | |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 129 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 130 | |
| 131 | if (type == NL80211_IFTYPE_MONITOR) { |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 132 | err = ieee80211_set_mon_options(sdata, params); |
Johannes Berg | 8c5e688 | 2017-04-12 10:46:13 +0200 | [diff] [blame] | 133 | if (err) { |
| 134 | ieee80211_if_remove(sdata); |
| 135 | return NULL; |
| 136 | } |
Johannes Berg | f9e10ce | 2010-12-03 09:20:42 +0100 | [diff] [blame] | 137 | } |
| 138 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 139 | return wdev; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 142 | static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 143 | { |
Johannes Berg | 84efbb8 | 2012-06-16 00:00:26 +0200 | [diff] [blame] | 144 | ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev)); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 145 | |
Johannes Berg | 7563652 | 2008-07-09 14:40:35 +0200 | [diff] [blame] | 146 | return 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Johannes Berg | e36d56b | 2009-06-09 21:04:43 +0200 | [diff] [blame] | 149 | static int ieee80211_change_iface(struct wiphy *wiphy, |
| 150 | struct net_device *dev, |
Johannes Berg | 818a986 | 2017-04-12 11:23:28 +0200 | [diff] [blame] | 151 | enum nl80211_iftype type, |
Luis Carlos Cobo | 2ec600d | 2008-02-23 15:17:06 +0100 | [diff] [blame] | 152 | struct vif_params *params) |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 153 | { |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 154 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 155 | int ret; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 156 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 157 | ret = ieee80211_if_change_type(sdata, type); |
Johannes Berg | f3947e2 | 2008-07-09 14:40:36 +0200 | [diff] [blame] | 158 | if (ret) |
| 159 | return ret; |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 160 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 161 | if (type == NL80211_IFTYPE_AP_VLAN && |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 162 | params && params->use_4addr == 0) { |
Stephen Hemminger | a9b3cd7 | 2011-08-01 16:19:00 +0000 | [diff] [blame] | 163 | RCU_INIT_POINTER(sdata->u.vlan.sta, NULL); |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 164 | ieee80211_check_fast_rx_iface(sdata); |
| 165 | } else if (type == NL80211_IFTYPE_STATION && |
| 166 | params && params->use_4addr >= 0) { |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 167 | sdata->u.mgd.use_4addr = params->use_4addr; |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 168 | } |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 169 | |
Aviya Erenfeld | 42bd20d | 2016-08-29 23:25:16 +0300 | [diff] [blame] | 170 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { |
Johannes Berg | 65f1d60 | 2017-04-12 12:36:31 +0200 | [diff] [blame] | 171 | ret = ieee80211_set_mon_options(sdata, params); |
| 172 | if (ret) |
| 173 | return ret; |
Christian Lamparter | 85416a4 | 2010-10-02 13:17:07 +0200 | [diff] [blame] | 174 | } |
Felix Fietkau | f7917af | 2010-04-27 00:26:34 +0200 | [diff] [blame] | 175 | |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | |
Johannes Berg | f142c6b | 2012-06-18 20:07:15 +0200 | [diff] [blame] | 179 | static int ieee80211_start_p2p_device(struct wiphy *wiphy, |
| 180 | struct wireless_dev *wdev) |
| 181 | { |
Luciano Coelho | b6a5501 | 2014-02-27 11:07:21 +0200 | [diff] [blame] | 182 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 183 | int ret; |
| 184 | |
| 185 | mutex_lock(&sdata->local->chanctx_mtx); |
| 186 | ret = ieee80211_check_combinations(sdata, NULL, 0, 0); |
| 187 | mutex_unlock(&sdata->local->chanctx_mtx); |
| 188 | if (ret < 0) |
| 189 | return ret; |
| 190 | |
Johannes Berg | f142c6b | 2012-06-18 20:07:15 +0200 | [diff] [blame] | 191 | return ieee80211_do_open(wdev, true); |
| 192 | } |
| 193 | |
| 194 | static void ieee80211_stop_p2p_device(struct wiphy *wiphy, |
| 195 | struct wireless_dev *wdev) |
| 196 | { |
| 197 | ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev)); |
| 198 | } |
| 199 | |
Ayala Beker | 708d50e | 2016-09-20 17:31:14 +0300 | [diff] [blame] | 200 | static int ieee80211_start_nan(struct wiphy *wiphy, |
| 201 | struct wireless_dev *wdev, |
| 202 | struct cfg80211_nan_conf *conf) |
| 203 | { |
| 204 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 205 | int ret; |
| 206 | |
| 207 | mutex_lock(&sdata->local->chanctx_mtx); |
| 208 | ret = ieee80211_check_combinations(sdata, NULL, 0, 0); |
| 209 | mutex_unlock(&sdata->local->chanctx_mtx); |
| 210 | if (ret < 0) |
| 211 | return ret; |
| 212 | |
| 213 | ret = ieee80211_do_open(wdev, true); |
| 214 | if (ret) |
| 215 | return ret; |
| 216 | |
| 217 | ret = drv_start_nan(sdata->local, sdata, conf); |
| 218 | if (ret) |
| 219 | ieee80211_sdata_stop(sdata); |
| 220 | |
Ayala Beker | 167e33f | 2016-09-20 17:31:20 +0300 | [diff] [blame] | 221 | sdata->u.nan.conf = *conf; |
| 222 | |
Ayala Beker | 708d50e | 2016-09-20 17:31:14 +0300 | [diff] [blame] | 223 | return ret; |
| 224 | } |
| 225 | |
| 226 | static void ieee80211_stop_nan(struct wiphy *wiphy, |
| 227 | struct wireless_dev *wdev) |
| 228 | { |
| 229 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 230 | |
| 231 | drv_stop_nan(sdata->local, sdata); |
| 232 | ieee80211_sdata_stop(sdata); |
| 233 | } |
| 234 | |
Ayala Beker | 5953ff6 | 2016-09-20 17:31:19 +0300 | [diff] [blame] | 235 | static int ieee80211_nan_change_conf(struct wiphy *wiphy, |
| 236 | struct wireless_dev *wdev, |
| 237 | struct cfg80211_nan_conf *conf, |
| 238 | u32 changes) |
| 239 | { |
| 240 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 241 | struct cfg80211_nan_conf new_conf; |
| 242 | int ret = 0; |
| 243 | |
| 244 | if (sdata->vif.type != NL80211_IFTYPE_NAN) |
| 245 | return -EOPNOTSUPP; |
| 246 | |
| 247 | if (!ieee80211_sdata_running(sdata)) |
| 248 | return -ENETDOWN; |
| 249 | |
| 250 | new_conf = sdata->u.nan.conf; |
| 251 | |
| 252 | if (changes & CFG80211_NAN_CONF_CHANGED_PREF) |
| 253 | new_conf.master_pref = conf->master_pref; |
| 254 | |
Luca Coelho | 8585989 | 2017-02-08 15:00:34 +0200 | [diff] [blame] | 255 | if (changes & CFG80211_NAN_CONF_CHANGED_BANDS) |
| 256 | new_conf.bands = conf->bands; |
Ayala Beker | 5953ff6 | 2016-09-20 17:31:19 +0300 | [diff] [blame] | 257 | |
| 258 | ret = drv_nan_change_conf(sdata->local, sdata, &new_conf, changes); |
| 259 | if (!ret) |
| 260 | sdata->u.nan.conf = new_conf; |
| 261 | |
| 262 | return ret; |
| 263 | } |
| 264 | |
Ayala Beker | 167e33f | 2016-09-20 17:31:20 +0300 | [diff] [blame] | 265 | static int ieee80211_add_nan_func(struct wiphy *wiphy, |
| 266 | struct wireless_dev *wdev, |
| 267 | struct cfg80211_nan_func *nan_func) |
| 268 | { |
| 269 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 270 | int ret; |
| 271 | |
| 272 | if (sdata->vif.type != NL80211_IFTYPE_NAN) |
| 273 | return -EOPNOTSUPP; |
| 274 | |
| 275 | if (!ieee80211_sdata_running(sdata)) |
| 276 | return -ENETDOWN; |
| 277 | |
| 278 | spin_lock_bh(&sdata->u.nan.func_lock); |
| 279 | |
| 280 | ret = idr_alloc(&sdata->u.nan.function_inst_ids, |
| 281 | nan_func, 1, sdata->local->hw.max_nan_de_entries + 1, |
| 282 | GFP_ATOMIC); |
| 283 | spin_unlock_bh(&sdata->u.nan.func_lock); |
| 284 | |
| 285 | if (ret < 0) |
| 286 | return ret; |
| 287 | |
| 288 | nan_func->instance_id = ret; |
| 289 | |
| 290 | WARN_ON(nan_func->instance_id == 0); |
| 291 | |
| 292 | ret = drv_add_nan_func(sdata->local, sdata, nan_func); |
| 293 | if (ret) { |
| 294 | spin_lock_bh(&sdata->u.nan.func_lock); |
| 295 | idr_remove(&sdata->u.nan.function_inst_ids, |
| 296 | nan_func->instance_id); |
| 297 | spin_unlock_bh(&sdata->u.nan.func_lock); |
| 298 | } |
| 299 | |
| 300 | return ret; |
| 301 | } |
| 302 | |
| 303 | static struct cfg80211_nan_func * |
| 304 | ieee80211_find_nan_func_by_cookie(struct ieee80211_sub_if_data *sdata, |
| 305 | u64 cookie) |
| 306 | { |
| 307 | struct cfg80211_nan_func *func; |
| 308 | int id; |
| 309 | |
| 310 | lockdep_assert_held(&sdata->u.nan.func_lock); |
| 311 | |
| 312 | idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id) { |
| 313 | if (func->cookie == cookie) |
| 314 | return func; |
| 315 | } |
| 316 | |
| 317 | return NULL; |
| 318 | } |
| 319 | |
| 320 | static void ieee80211_del_nan_func(struct wiphy *wiphy, |
| 321 | struct wireless_dev *wdev, u64 cookie) |
| 322 | { |
| 323 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 324 | struct cfg80211_nan_func *func; |
| 325 | u8 instance_id = 0; |
| 326 | |
| 327 | if (sdata->vif.type != NL80211_IFTYPE_NAN || |
| 328 | !ieee80211_sdata_running(sdata)) |
| 329 | return; |
| 330 | |
| 331 | spin_lock_bh(&sdata->u.nan.func_lock); |
| 332 | |
| 333 | func = ieee80211_find_nan_func_by_cookie(sdata, cookie); |
| 334 | if (func) |
| 335 | instance_id = func->instance_id; |
| 336 | |
| 337 | spin_unlock_bh(&sdata->u.nan.func_lock); |
| 338 | |
| 339 | if (instance_id) |
| 340 | drv_del_nan_func(sdata->local, sdata, instance_id); |
| 341 | } |
| 342 | |
Simon Wunderlich | b53be79 | 2011-11-18 14:20:44 +0100 | [diff] [blame] | 343 | static int ieee80211_set_noack_map(struct wiphy *wiphy, |
| 344 | struct net_device *dev, |
| 345 | u16 noack_map) |
| 346 | { |
| 347 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 348 | |
| 349 | sdata->noack_map = noack_map; |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 350 | |
| 351 | ieee80211_check_fast_xmit_iface(sdata); |
| 352 | |
Simon Wunderlich | b53be79 | 2011-11-18 14:20:44 +0100 | [diff] [blame] | 353 | return 0; |
| 354 | } |
| 355 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 356 | static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 357 | u8 key_idx, bool pairwise, const u8 *mac_addr, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 358 | struct key_params *params) |
| 359 | { |
Johannes Berg | 26a5845 | 2010-08-27 12:35:55 +0200 | [diff] [blame] | 360 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 361 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 362 | struct sta_info *sta = NULL; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 363 | const struct ieee80211_cipher_scheme *cs = NULL; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 364 | struct ieee80211_key *key; |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 365 | int err; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 366 | |
Johannes Berg | 26a5845 | 2010-08-27 12:35:55 +0200 | [diff] [blame] | 367 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 368 | return -ENETDOWN; |
| 369 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 370 | /* reject WEP and TKIP keys if WEP failed to initialize */ |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 371 | switch (params->cipher) { |
| 372 | case WLAN_CIPHER_SUITE_WEP40: |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 373 | case WLAN_CIPHER_SUITE_TKIP: |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 374 | case WLAN_CIPHER_SUITE_WEP104: |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 375 | if (IS_ERR(local->wep_tx_tfm)) |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 376 | return -EINVAL; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 377 | break; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 378 | case WLAN_CIPHER_SUITE_CCMP: |
Jouni Malinen | 2b2ba0d | 2015-01-24 19:52:07 +0200 | [diff] [blame] | 379 | case WLAN_CIPHER_SUITE_CCMP_256: |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 380 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Jouni Malinen | 56c52da | 2015-01-24 19:52:08 +0200 | [diff] [blame] | 381 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
Jouni Malinen | 8ade538 | 2015-01-24 19:52:09 +0200 | [diff] [blame] | 382 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 383 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 384 | case WLAN_CIPHER_SUITE_GCMP: |
Jouni Malinen | 00b9cfa | 2015-01-24 19:52:06 +0200 | [diff] [blame] | 385 | case WLAN_CIPHER_SUITE_GCMP_256: |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 386 | break; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 387 | default: |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 388 | cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type); |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 389 | break; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 390 | } |
| 391 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 392 | key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len, |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 393 | params->key, params->seq_len, params->seq, |
| 394 | cs); |
Ben Hutchings | 1ac62ba | 2010-08-01 17:37:03 +0100 | [diff] [blame] | 395 | if (IS_ERR(key)) |
| 396 | return PTR_ERR(key); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 397 | |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 398 | if (pairwise) |
| 399 | key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE; |
| 400 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 401 | mutex_lock(&local->sta_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 402 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 403 | if (mac_addr) { |
Johannes Berg | 850092d | 2016-10-04 15:32:16 +0200 | [diff] [blame] | 404 | sta = sta_info_get_bss(sdata, mac_addr); |
Johannes Berg | 1626e0f | 2013-01-11 14:34:25 +0100 | [diff] [blame] | 405 | /* |
| 406 | * The ASSOC test makes sure the driver is ready to |
| 407 | * receive the key. When wpa_supplicant has roamed |
| 408 | * using FT, it attempts to set the key before |
| 409 | * association has completed, this rejects that attempt |
Stephen Hemminger | d070f91 | 2014-10-29 22:55:58 -0700 | [diff] [blame] | 410 | * so it will set the key again after association. |
Johannes Berg | 1626e0f | 2013-01-11 14:34:25 +0100 | [diff] [blame] | 411 | * |
| 412 | * TODO: accept the key if we have a station entry and |
| 413 | * add it to the device after the station. |
| 414 | */ |
| 415 | if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) { |
Johannes Berg | 79cf2df | 2013-03-06 22:53:52 +0100 | [diff] [blame] | 416 | ieee80211_key_free_unused(key); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 417 | err = -ENOENT; |
| 418 | goto out_unlock; |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 419 | } |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 420 | } |
| 421 | |
Johannes Berg | e548c49 | 2012-09-04 17:08:23 +0200 | [diff] [blame] | 422 | switch (sdata->vif.type) { |
| 423 | case NL80211_IFTYPE_STATION: |
| 424 | if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED) |
| 425 | key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT; |
| 426 | break; |
| 427 | case NL80211_IFTYPE_AP: |
| 428 | case NL80211_IFTYPE_AP_VLAN: |
| 429 | /* Keys without a station are used for TX only */ |
| 430 | if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP)) |
| 431 | key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT; |
| 432 | break; |
| 433 | case NL80211_IFTYPE_ADHOC: |
| 434 | /* no MFP (yet) */ |
| 435 | break; |
| 436 | case NL80211_IFTYPE_MESH_POINT: |
| 437 | #ifdef CONFIG_MAC80211_MESH |
| 438 | if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE) |
| 439 | key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT; |
| 440 | break; |
| 441 | #endif |
| 442 | case NL80211_IFTYPE_WDS: |
| 443 | case NL80211_IFTYPE_MONITOR: |
| 444 | case NL80211_IFTYPE_P2P_DEVICE: |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 445 | case NL80211_IFTYPE_NAN: |
Johannes Berg | e548c49 | 2012-09-04 17:08:23 +0200 | [diff] [blame] | 446 | case NL80211_IFTYPE_UNSPECIFIED: |
| 447 | case NUM_NL80211_IFTYPES: |
| 448 | case NL80211_IFTYPE_P2P_CLIENT: |
| 449 | case NL80211_IFTYPE_P2P_GO: |
Rostislav Lisovy | 6e0bd6c | 2014-11-03 10:33:18 +0100 | [diff] [blame] | 450 | case NL80211_IFTYPE_OCB: |
Johannes Berg | e548c49 | 2012-09-04 17:08:23 +0200 | [diff] [blame] | 451 | /* shouldn't happen */ |
| 452 | WARN_ON_ONCE(1); |
| 453 | break; |
| 454 | } |
| 455 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 456 | if (sta) |
| 457 | sta->cipher_scheme = cs; |
| 458 | |
Johannes Berg | 3ffc2a9 | 2010-08-27 14:26:52 +0300 | [diff] [blame] | 459 | err = ieee80211_key_link(key, sdata, sta); |
Johannes Berg | db4d116 | 2008-02-25 16:27:45 +0100 | [diff] [blame] | 460 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 461 | out_unlock: |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 462 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 463 | |
| 464 | return err; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 468 | u8 key_idx, bool pairwise, const u8 *mac_addr) |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 469 | { |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 470 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 471 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 472 | struct sta_info *sta; |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 473 | struct ieee80211_key *key = NULL; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 474 | int ret; |
| 475 | |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 476 | mutex_lock(&local->sta_mtx); |
| 477 | mutex_lock(&local->key_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 478 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 479 | if (mac_addr) { |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 480 | ret = -ENOENT; |
| 481 | |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 482 | sta = sta_info_get_bss(sdata, mac_addr); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 483 | if (!sta) |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 484 | goto out_unlock; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 485 | |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 486 | if (pairwise) |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 487 | key = key_mtx_dereference(local, sta->ptk[key_idx]); |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 488 | else |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 489 | key = key_mtx_dereference(local, sta->gtk[key_idx]); |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 490 | } else |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 491 | key = key_mtx_dereference(local, sdata->keys[key_idx]); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 492 | |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 493 | if (!key) { |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 494 | ret = -ENOENT; |
| 495 | goto out_unlock; |
| 496 | } |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 497 | |
Johannes Berg | 3b8d9c2 | 2013-03-06 22:58:23 +0100 | [diff] [blame] | 498 | ieee80211_key_free(key, true); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 499 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 500 | ret = 0; |
| 501 | out_unlock: |
Johannes Berg | 5c0c364 | 2011-05-12 14:31:49 +0200 | [diff] [blame] | 502 | mutex_unlock(&local->key_mtx); |
| 503 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 504 | |
| 505 | return ret; |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 506 | } |
| 507 | |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 508 | static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 509 | u8 key_idx, bool pairwise, const u8 *mac_addr, |
| 510 | void *cookie, |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 511 | void (*callback)(void *cookie, |
| 512 | struct key_params *params)) |
| 513 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 514 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 515 | struct sta_info *sta = NULL; |
| 516 | u8 seq[6] = {0}; |
| 517 | struct key_params params; |
Johannes Berg | e31b821 | 2010-10-05 19:39:30 +0200 | [diff] [blame] | 518 | struct ieee80211_key *key = NULL; |
Johannes Berg | aba83a0b | 2011-07-06 21:59:39 +0200 | [diff] [blame] | 519 | u64 pn64; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 520 | u32 iv32; |
| 521 | u16 iv16; |
| 522 | int err = -ENOENT; |
Johannes Berg | 9352c19 | 2015-04-20 18:12:41 +0200 | [diff] [blame] | 523 | struct ieee80211_key_seq kseq = {}; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 524 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 525 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 526 | |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 527 | rcu_read_lock(); |
| 528 | |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 529 | if (mac_addr) { |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 530 | sta = sta_info_get_bss(sdata, mac_addr); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 531 | if (!sta) |
| 532 | goto out; |
| 533 | |
Max Stepanov | 354e159 | 2013-12-08 13:30:52 +0200 | [diff] [blame] | 534 | if (pairwise && key_idx < NUM_DEFAULT_KEYS) |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 535 | key = rcu_dereference(sta->ptk[key_idx]); |
Max Stepanov | 31f1f4e | 2013-12-08 13:31:29 +0200 | [diff] [blame] | 536 | else if (!pairwise && |
| 537 | key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS) |
Johannes Berg | a3836e0 | 2011-05-12 15:11:37 +0200 | [diff] [blame] | 538 | key = rcu_dereference(sta->gtk[key_idx]); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 539 | } else |
Johannes Berg | a3836e0 | 2011-05-12 15:11:37 +0200 | [diff] [blame] | 540 | key = rcu_dereference(sdata->keys[key_idx]); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 541 | |
| 542 | if (!key) |
| 543 | goto out; |
| 544 | |
| 545 | memset(¶ms, 0, sizeof(params)); |
| 546 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 547 | params.cipher = key->conf.cipher; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 548 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 549 | switch (key->conf.cipher) { |
| 550 | case WLAN_CIPHER_SUITE_TKIP: |
Eliad Peller | f8079d4 | 2016-02-14 13:56:35 +0200 | [diff] [blame] | 551 | pn64 = atomic64_read(&key->conf.tx_pn); |
| 552 | iv32 = TKIP_PN_TO_IV32(pn64); |
| 553 | iv16 = TKIP_PN_TO_IV16(pn64); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 554 | |
Johannes Berg | 9352c19 | 2015-04-20 18:12:41 +0200 | [diff] [blame] | 555 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && |
| 556 | !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { |
| 557 | drv_get_key_seq(sdata->local, key, &kseq); |
| 558 | iv32 = kseq.tkip.iv32; |
| 559 | iv16 = kseq.tkip.iv16; |
| 560 | } |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 561 | |
| 562 | seq[0] = iv16 & 0xff; |
| 563 | seq[1] = (iv16 >> 8) & 0xff; |
| 564 | seq[2] = iv32 & 0xff; |
| 565 | seq[3] = (iv32 >> 8) & 0xff; |
| 566 | seq[4] = (iv32 >> 16) & 0xff; |
| 567 | seq[5] = (iv32 >> 24) & 0xff; |
| 568 | params.seq = seq; |
| 569 | params.seq_len = 6; |
| 570 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 571 | case WLAN_CIPHER_SUITE_CCMP: |
Jouni Malinen | 2b2ba0d | 2015-01-24 19:52:07 +0200 | [diff] [blame] | 572 | case WLAN_CIPHER_SUITE_CCMP_256: |
Johannes Berg | db388a5 | 2015-06-01 15:36:51 +0200 | [diff] [blame] | 573 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 574 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
| 575 | BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) != |
| 576 | offsetof(typeof(kseq), aes_cmac)); |
Gustavo A. R. Silva | 02049ce | 2017-10-17 18:14:50 -0500 | [diff] [blame] | 577 | /* fall through */ |
Johannes Berg | db388a5 | 2015-06-01 15:36:51 +0200 | [diff] [blame] | 578 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 579 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 580 | BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) != |
| 581 | offsetof(typeof(kseq), aes_gmac)); |
Gustavo A. R. Silva | 02049ce | 2017-10-17 18:14:50 -0500 | [diff] [blame] | 582 | /* fall through */ |
Johannes Berg | db388a5 | 2015-06-01 15:36:51 +0200 | [diff] [blame] | 583 | case WLAN_CIPHER_SUITE_GCMP: |
| 584 | case WLAN_CIPHER_SUITE_GCMP_256: |
| 585 | BUILD_BUG_ON(offsetof(typeof(kseq), ccmp) != |
| 586 | offsetof(typeof(kseq), gcmp)); |
| 587 | |
Johannes Berg | 9352c19 | 2015-04-20 18:12:41 +0200 | [diff] [blame] | 588 | if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE && |
| 589 | !(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) { |
| 590 | drv_get_key_seq(sdata->local, key, &kseq); |
| 591 | memcpy(seq, kseq.ccmp.pn, 6); |
| 592 | } else { |
Johannes Berg | db388a5 | 2015-06-01 15:36:51 +0200 | [diff] [blame] | 593 | pn64 = atomic64_read(&key->conf.tx_pn); |
Johannes Berg | 9352c19 | 2015-04-20 18:12:41 +0200 | [diff] [blame] | 594 | seq[0] = pn64; |
| 595 | seq[1] = pn64 >> 8; |
| 596 | seq[2] = pn64 >> 16; |
| 597 | seq[3] = pn64 >> 24; |
| 598 | seq[4] = pn64 >> 32; |
| 599 | seq[5] = pn64 >> 40; |
| 600 | } |
Jouni Malinen | 00b9cfa | 2015-01-24 19:52:06 +0200 | [diff] [blame] | 601 | params.seq = seq; |
| 602 | params.seq_len = 6; |
| 603 | break; |
Johannes Berg | a31cf1c | 2015-04-20 18:21:58 +0200 | [diff] [blame] | 604 | default: |
| 605 | if (!(key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) |
| 606 | break; |
| 607 | if (WARN_ON(key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) |
| 608 | break; |
| 609 | drv_get_key_seq(sdata->local, key, &kseq); |
| 610 | params.seq = kseq.hw.seq; |
| 611 | params.seq_len = kseq.hw.seq_len; |
| 612 | break; |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | params.key = key->conf.key; |
| 616 | params.key_len = key->conf.keylen; |
| 617 | |
| 618 | callback(cookie, ¶ms); |
| 619 | err = 0; |
| 620 | |
| 621 | out: |
Johannes Berg | 3b96766 | 2008-04-08 17:56:52 +0200 | [diff] [blame] | 622 | rcu_read_unlock(); |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 623 | return err; |
| 624 | } |
| 625 | |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 626 | static int ieee80211_config_default_key(struct wiphy *wiphy, |
| 627 | struct net_device *dev, |
Johannes Berg | dbd2fd6 | 2010-12-09 19:58:59 +0100 | [diff] [blame] | 628 | u8 key_idx, bool uni, |
| 629 | bool multi) |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 630 | { |
Johannes Berg | ad0e2b5 | 2010-06-01 10:19:19 +0200 | [diff] [blame] | 631 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 632 | |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 633 | ieee80211_set_default_key(sdata, key_idx, uni, multi); |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 634 | |
| 635 | return 0; |
| 636 | } |
| 637 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 638 | static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy, |
| 639 | struct net_device *dev, |
| 640 | u8 key_idx) |
| 641 | { |
Johannes Berg | 66c5242 | 2010-07-22 13:58:51 +0200 | [diff] [blame] | 642 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 643 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 644 | ieee80211_set_default_mgmt_key(sdata, key_idx); |
| 645 | |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 646 | return 0; |
| 647 | } |
| 648 | |
Thomas Pedersen | 6b62bf3 | 2012-03-05 15:31:48 -0800 | [diff] [blame] | 649 | void sta_set_rate_info_tx(struct sta_info *sta, |
| 650 | const struct ieee80211_tx_rate *rate, |
| 651 | struct rate_info *rinfo) |
| 652 | { |
| 653 | rinfo->flags = 0; |
Johannes Berg | 8bc83c2 | 2012-11-09 18:38:32 +0100 | [diff] [blame] | 654 | if (rate->flags & IEEE80211_TX_RC_MCS) { |
Thomas Pedersen | 6b62bf3 | 2012-03-05 15:31:48 -0800 | [diff] [blame] | 655 | rinfo->flags |= RATE_INFO_FLAGS_MCS; |
Johannes Berg | 8bc83c2 | 2012-11-09 18:38:32 +0100 | [diff] [blame] | 656 | rinfo->mcs = rate->idx; |
| 657 | } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) { |
| 658 | rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS; |
| 659 | rinfo->mcs = ieee80211_rate_get_vht_mcs(rate); |
| 660 | rinfo->nss = ieee80211_rate_get_vht_nss(rate); |
| 661 | } else { |
| 662 | struct ieee80211_supported_band *sband; |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 663 | int shift = ieee80211_vif_get_shift(&sta->sdata->vif); |
| 664 | u16 brate; |
| 665 | |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 666 | sband = ieee80211_get_sband(sta->sdata); |
| 667 | if (sband) { |
| 668 | brate = sband->bitrates[rate->idx].bitrate; |
| 669 | rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift); |
| 670 | } |
Johannes Berg | 8bc83c2 | 2012-11-09 18:38:32 +0100 | [diff] [blame] | 671 | } |
Thomas Pedersen | 6b62bf3 | 2012-03-05 15:31:48 -0800 | [diff] [blame] | 672 | if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH) |
Johannes Berg | b51f3be | 2015-01-15 16:14:02 +0100 | [diff] [blame] | 673 | rinfo->bw = RATE_INFO_BW_40; |
| 674 | else if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH) |
| 675 | rinfo->bw = RATE_INFO_BW_80; |
| 676 | else if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH) |
| 677 | rinfo->bw = RATE_INFO_BW_160; |
| 678 | else |
| 679 | rinfo->bw = RATE_INFO_BW_20; |
Thomas Pedersen | 6b62bf3 | 2012-03-05 15:31:48 -0800 | [diff] [blame] | 680 | if (rate->flags & IEEE80211_TX_RC_SHORT_GI) |
| 681 | rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI; |
Thomas Pedersen | 6b62bf3 | 2012-03-05 15:31:48 -0800 | [diff] [blame] | 682 | } |
| 683 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 684 | static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 685 | int idx, u8 *mac, struct station_info *sinfo) |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 686 | { |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 687 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Victor Goldenshtein | 66572cf | 2012-06-21 10:56:46 +0300 | [diff] [blame] | 688 | struct ieee80211_local *local = sdata->local; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 689 | struct sta_info *sta; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 690 | int ret = -ENOENT; |
| 691 | |
Victor Goldenshtein | 66572cf | 2012-06-21 10:56:46 +0300 | [diff] [blame] | 692 | mutex_lock(&local->sta_mtx); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 693 | |
Johannes Berg | 3b53fde8 | 2009-11-16 12:00:37 +0100 | [diff] [blame] | 694 | sta = sta_info_get_by_idx(sdata, idx); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 695 | if (sta) { |
| 696 | ret = 0; |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 697 | memcpy(mac, sta->sta.addr, ETH_ALEN); |
Johannes Berg | 0fdf149 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 698 | sta_set_sinfo(sta, sinfo, true); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 699 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 700 | |
Victor Goldenshtein | 66572cf | 2012-06-21 10:56:46 +0300 | [diff] [blame] | 701 | mutex_unlock(&local->sta_mtx); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 702 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 703 | return ret; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 704 | } |
| 705 | |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 706 | static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev, |
| 707 | int idx, struct survey_info *survey) |
| 708 | { |
| 709 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
| 710 | |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 711 | return drv_get_survey(local, idx, survey); |
| 712 | } |
| 713 | |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 714 | static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 715 | const u8 *mac, struct station_info *sinfo) |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 716 | { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 717 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Victor Goldenshtein | 66572cf | 2012-06-21 10:56:46 +0300 | [diff] [blame] | 718 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 719 | struct sta_info *sta; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 720 | int ret = -ENOENT; |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 721 | |
Victor Goldenshtein | 66572cf | 2012-06-21 10:56:46 +0300 | [diff] [blame] | 722 | mutex_lock(&local->sta_mtx); |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 723 | |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 724 | sta = sta_info_get_bss(sdata, mac); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 725 | if (sta) { |
| 726 | ret = 0; |
Johannes Berg | 0fdf149 | 2018-05-18 11:40:44 +0200 | [diff] [blame] | 727 | sta_set_sinfo(sta, sinfo, true); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 728 | } |
| 729 | |
Victor Goldenshtein | 66572cf | 2012-06-21 10:56:46 +0300 | [diff] [blame] | 730 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 731 | |
| 732 | return ret; |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 733 | } |
| 734 | |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 735 | static int ieee80211_set_monitor_channel(struct wiphy *wiphy, |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 736 | struct cfg80211_chan_def *chandef) |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 737 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 738 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 739 | struct ieee80211_sub_if_data *sdata; |
| 740 | int ret = 0; |
| 741 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 742 | if (cfg80211_chandef_identical(&local->monitor_chandef, chandef)) |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 743 | return 0; |
| 744 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 745 | mutex_lock(&local->mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 746 | if (local->use_chanctx) { |
Johannes Berg | 4a19906 | 2017-04-26 10:58:53 +0300 | [diff] [blame] | 747 | sdata = rtnl_dereference(local->monitor_sdata); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 748 | if (sdata) { |
| 749 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 750 | ret = ieee80211_vif_use_channel(sdata, chandef, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 751 | IEEE80211_CHANCTX_EXCLUSIVE); |
| 752 | } |
| 753 | } else if (local->open_count == local->monitors) { |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 754 | local->_oper_chandef = *chandef; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 755 | ieee80211_hw_config(local, 0); |
| 756 | } |
| 757 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 758 | if (ret == 0) |
| 759 | local->monitor_chandef = *chandef; |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 760 | mutex_unlock(&local->mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 761 | |
| 762 | return ret; |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 763 | } |
| 764 | |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 765 | static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata, |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 766 | const u8 *resp, size_t resp_len, |
| 767 | const struct ieee80211_csa_settings *csa) |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 768 | { |
Eyal Shapira | aa7a008 | 2012-08-06 14:26:16 +0300 | [diff] [blame] | 769 | struct probe_resp *new, *old; |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 770 | |
| 771 | if (!resp || !resp_len) |
Sujith Manoharan | aba4e6f | 2012-08-22 14:21:07 +0530 | [diff] [blame] | 772 | return 1; |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 773 | |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 774 | old = sdata_dereference(sdata->u.ap.probe_resp, sdata); |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 775 | |
Eyal Shapira | aa7a008 | 2012-08-06 14:26:16 +0300 | [diff] [blame] | 776 | new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL); |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 777 | if (!new) |
| 778 | return -ENOMEM; |
| 779 | |
Eyal Shapira | aa7a008 | 2012-08-06 14:26:16 +0300 | [diff] [blame] | 780 | new->len = resp_len; |
| 781 | memcpy(new->data, resp, resp_len); |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 782 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 783 | if (csa) |
| 784 | memcpy(new->csa_counter_offsets, csa->counter_offsets_presp, |
| 785 | csa->n_counter_offsets_presp * |
| 786 | sizeof(new->csa_counter_offsets[0])); |
| 787 | |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 788 | rcu_assign_pointer(sdata->u.ap.probe_resp, new); |
Eyal Shapira | aa7a008 | 2012-08-06 14:26:16 +0300 | [diff] [blame] | 789 | if (old) |
| 790 | kfree_rcu(old, rcu_head); |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 791 | |
| 792 | return 0; |
| 793 | } |
| 794 | |
Luciano Coelho | 0ae0796 | 2013-12-08 09:42:25 +0200 | [diff] [blame] | 795 | static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata, |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 796 | struct cfg80211_beacon_data *params, |
| 797 | const struct ieee80211_csa_settings *csa) |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 798 | { |
| 799 | struct beacon_data *new, *old; |
| 800 | int new_head_len, new_tail_len; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 801 | int size, err; |
| 802 | u32 changed = BSS_CHANGED_BEACON; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 803 | |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 804 | old = sdata_dereference(sdata->u.ap.beacon, sdata); |
| 805 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 806 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 807 | /* Need to have a beacon head if we don't have one yet */ |
| 808 | if (!params->head && !old) |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 809 | return -EINVAL; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 810 | |
| 811 | /* new or old head? */ |
| 812 | if (params->head) |
| 813 | new_head_len = params->head_len; |
| 814 | else |
| 815 | new_head_len = old->head_len; |
| 816 | |
| 817 | /* new or old tail? */ |
| 818 | if (params->tail || !old) |
| 819 | /* params->tail_len will be zero for !params->tail */ |
| 820 | new_tail_len = params->tail_len; |
| 821 | else |
| 822 | new_tail_len = old->tail_len; |
| 823 | |
| 824 | size = sizeof(*new) + new_head_len + new_tail_len; |
| 825 | |
| 826 | new = kzalloc(size, GFP_KERNEL); |
| 827 | if (!new) |
| 828 | return -ENOMEM; |
| 829 | |
| 830 | /* start filling the new info now */ |
| 831 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 832 | /* |
| 833 | * pointers go into the block we allocated, |
| 834 | * memory is | beacon_data | head | tail | |
| 835 | */ |
| 836 | new->head = ((u8 *) new) + sizeof(*new); |
| 837 | new->tail = new->head + new_head_len; |
| 838 | new->head_len = new_head_len; |
| 839 | new->tail_len = new_tail_len; |
| 840 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 841 | if (csa) { |
| 842 | new->csa_current_counter = csa->count; |
| 843 | memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon, |
| 844 | csa->n_counter_offsets_beacon * |
| 845 | sizeof(new->csa_counter_offsets[0])); |
| 846 | } |
| 847 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 848 | /* copy in head */ |
| 849 | if (params->head) |
| 850 | memcpy(new->head, params->head, new_head_len); |
| 851 | else |
| 852 | memcpy(new->head, old->head, new_head_len); |
| 853 | |
| 854 | /* copy in optional tail */ |
| 855 | if (params->tail) |
| 856 | memcpy(new->tail, params->tail, new_tail_len); |
| 857 | else |
| 858 | if (old) |
| 859 | memcpy(new->tail, old->tail, new_tail_len); |
| 860 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 861 | err = ieee80211_set_probe_resp(sdata, params->probe_resp, |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 862 | params->probe_resp_len, csa); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 863 | if (err < 0) |
| 864 | return err; |
| 865 | if (err == 0) |
| 866 | changed |= BSS_CHANGED_AP_PROBE_RESP; |
Johannes Berg | 19885c4 | 2010-02-05 11:45:06 +0100 | [diff] [blame] | 867 | |
Eric Dumazet | cf778b0 | 2012-01-12 04:41:32 +0000 | [diff] [blame] | 868 | rcu_assign_pointer(sdata->u.ap.beacon, new); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 869 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 870 | if (old) |
| 871 | kfree_rcu(old, rcu_head); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 872 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 873 | return changed; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 874 | } |
| 875 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 876 | static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev, |
| 877 | struct cfg80211_ap_settings *params) |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 878 | { |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 879 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 880 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 881 | struct beacon_data *old; |
Johannes Berg | 665c93a | 2011-11-04 11:18:11 +0100 | [diff] [blame] | 882 | struct ieee80211_sub_if_data *vlan; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 883 | u32 changed = BSS_CHANGED_BEACON_INT | |
| 884 | BSS_CHANGED_BEACON_ENABLED | |
| 885 | BSS_CHANGED_BEACON | |
Johannes Berg | 339afbf | 2012-11-14 15:21:17 +0100 | [diff] [blame] | 886 | BSS_CHANGED_SSID | |
Johannes Berg | 4bcc56b | 2014-11-13 11:23:53 +0100 | [diff] [blame] | 887 | BSS_CHANGED_P2P_PS | |
| 888 | BSS_CHANGED_TXPOWER; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 889 | int err; |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 890 | |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 891 | old = sdata_dereference(sdata->u.ap.beacon, sdata); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 892 | if (old) |
| 893 | return -EALREADY; |
| 894 | |
Eliad Peller | f699317 | 2014-09-10 14:07:35 +0300 | [diff] [blame] | 895 | switch (params->smps_mode) { |
| 896 | case NL80211_SMPS_OFF: |
| 897 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
| 898 | break; |
| 899 | case NL80211_SMPS_STATIC: |
| 900 | sdata->smps_mode = IEEE80211_SMPS_STATIC; |
| 901 | break; |
| 902 | case NL80211_SMPS_DYNAMIC: |
| 903 | sdata->smps_mode = IEEE80211_SMPS_DYNAMIC; |
| 904 | break; |
| 905 | default: |
| 906 | return -EINVAL; |
| 907 | } |
Emmanuel Grumbach | b3dd827 | 2017-06-10 13:52:45 +0300 | [diff] [blame] | 908 | sdata->u.ap.req_smps = sdata->smps_mode; |
| 909 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 910 | sdata->needed_rx_chains = sdata->local->rx_chains; |
| 911 | |
Johannes Berg | ac668af | 2016-10-21 14:25:14 +0200 | [diff] [blame] | 912 | sdata->vif.bss_conf.beacon_int = params->beacon_interval; |
| 913 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 914 | mutex_lock(&local->mtx); |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 915 | err = ieee80211_vif_use_channel(sdata, ¶ms->chandef, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 916 | IEEE80211_CHANCTX_SHARED); |
Michal Kazior | 4e141da | 2014-03-05 13:14:08 +0100 | [diff] [blame] | 917 | if (!err) |
| 918 | ieee80211_vif_copy_chanctx_to_vlans(sdata, false); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 919 | mutex_unlock(&local->mtx); |
Johannes Berg | aa430da | 2012-05-16 23:50:18 +0200 | [diff] [blame] | 920 | if (err) |
| 921 | return err; |
| 922 | |
Johannes Berg | 665c93a | 2011-11-04 11:18:11 +0100 | [diff] [blame] | 923 | /* |
| 924 | * Apply control port protocol, this allows us to |
| 925 | * not encrypt dynamic WEP control frames. |
| 926 | */ |
| 927 | sdata->control_port_protocol = params->crypto.control_port_ethertype; |
| 928 | sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt; |
Denis Kenzior | 018f6fb | 2018-03-26 12:52:51 -0500 | [diff] [blame] | 929 | sdata->control_port_over_nl80211 = |
| 930 | params->crypto.control_port_over_nl80211; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 931 | sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local, |
| 932 | ¶ms->crypto, |
| 933 | sdata->vif.type); |
| 934 | |
Johannes Berg | 665c93a | 2011-11-04 11:18:11 +0100 | [diff] [blame] | 935 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) { |
| 936 | vlan->control_port_protocol = |
| 937 | params->crypto.control_port_ethertype; |
| 938 | vlan->control_port_no_encrypt = |
| 939 | params->crypto.control_port_no_encrypt; |
Denis Kenzior | 018f6fb | 2018-03-26 12:52:51 -0500 | [diff] [blame] | 940 | vlan->control_port_over_nl80211 = |
| 941 | params->crypto.control_port_over_nl80211; |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 942 | vlan->encrypt_headroom = |
| 943 | ieee80211_cs_headroom(sdata->local, |
| 944 | ¶ms->crypto, |
| 945 | vlan->vif.type); |
Johannes Berg | 665c93a | 2011-11-04 11:18:11 +0100 | [diff] [blame] | 946 | } |
| 947 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 948 | sdata->vif.bss_conf.dtim_period = params->dtim_period; |
Johannes Berg | d6a8322 | 2012-12-14 14:06:28 +0100 | [diff] [blame] | 949 | sdata->vif.bss_conf.enable_beacon = true; |
Ayala Beker | 52cfa1d | 2016-03-17 15:41:39 +0200 | [diff] [blame] | 950 | sdata->vif.bss_conf.allow_p2p_go_ps = sdata->vif.p2p; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 951 | |
| 952 | sdata->vif.bss_conf.ssid_len = params->ssid_len; |
| 953 | if (params->ssid_len) |
| 954 | memcpy(sdata->vif.bss_conf.ssid, params->ssid, |
| 955 | params->ssid_len); |
| 956 | sdata->vif.bss_conf.hidden_ssid = |
| 957 | (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE); |
| 958 | |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 959 | memset(&sdata->vif.bss_conf.p2p_noa_attr, 0, |
| 960 | sizeof(sdata->vif.bss_conf.p2p_noa_attr)); |
| 961 | sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow = |
| 962 | params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK; |
| 963 | if (params->p2p_opp_ps) |
| 964 | sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |= |
| 965 | IEEE80211_P2P_OPPPS_ENABLE_BIT; |
Johannes Berg | 339afbf | 2012-11-14 15:21:17 +0100 | [diff] [blame] | 966 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 967 | err = ieee80211_assign_beacon(sdata, ¶ms->beacon, NULL); |
Emmanuel Grumbach | 0297ea1 | 2014-01-27 11:07:42 +0200 | [diff] [blame] | 968 | if (err < 0) { |
| 969 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 970 | return err; |
Emmanuel Grumbach | 0297ea1 | 2014-01-27 11:07:42 +0200 | [diff] [blame] | 971 | } |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 972 | changed |= err; |
| 973 | |
Johannes Berg | 1041638 | 2012-10-19 15:44:42 +0200 | [diff] [blame] | 974 | err = drv_start_ap(sdata->local, sdata); |
| 975 | if (err) { |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 976 | old = sdata_dereference(sdata->u.ap.beacon, sdata); |
| 977 | |
Johannes Berg | 1041638 | 2012-10-19 15:44:42 +0200 | [diff] [blame] | 978 | if (old) |
| 979 | kfree_rcu(old, rcu_head); |
| 980 | RCU_INIT_POINTER(sdata->u.ap.beacon, NULL); |
Emmanuel Grumbach | 0297ea1 | 2014-01-27 11:07:42 +0200 | [diff] [blame] | 981 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 1041638 | 2012-10-19 15:44:42 +0200 | [diff] [blame] | 982 | return err; |
| 983 | } |
| 984 | |
Thomas Pedersen | 057d5f4 | 2013-12-19 10:25:15 -0800 | [diff] [blame] | 985 | ieee80211_recalc_dtim(local, sdata); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 986 | ieee80211_bss_info_change_notify(sdata, changed); |
| 987 | |
Johannes Berg | 3edaf3e | 2012-04-03 10:24:00 +0200 | [diff] [blame] | 988 | netif_carrier_on(dev); |
| 989 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) |
| 990 | netif_carrier_on(vlan->dev); |
| 991 | |
Johannes Berg | 665c93a | 2011-11-04 11:18:11 +0100 | [diff] [blame] | 992 | return 0; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 993 | } |
| 994 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 995 | static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev, |
| 996 | struct cfg80211_beacon_data *params) |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 997 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 998 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 999 | struct beacon_data *old; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1000 | int err; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1001 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1002 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Michal Kazior | dbd7285 | 2014-01-29 07:56:21 +0100 | [diff] [blame] | 1003 | sdata_assert_lock(sdata); |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1004 | |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 1005 | /* don't allow changing the beacon while CSA is in place - offset |
| 1006 | * of channel switch counter may change |
| 1007 | */ |
| 1008 | if (sdata->vif.csa_active) |
| 1009 | return -EBUSY; |
| 1010 | |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 1011 | old = sdata_dereference(sdata->u.ap.beacon, sdata); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1012 | if (!old) |
| 1013 | return -ENOENT; |
| 1014 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 1015 | err = ieee80211_assign_beacon(sdata, params, NULL); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1016 | if (err < 0) |
| 1017 | return err; |
| 1018 | ieee80211_bss_info_change_notify(sdata, err); |
| 1019 | return 0; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1020 | } |
| 1021 | |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1022 | static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev) |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1023 | { |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1024 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1025 | struct ieee80211_sub_if_data *vlan; |
| 1026 | struct ieee80211_local *local = sdata->local; |
| 1027 | struct beacon_data *old_beacon; |
| 1028 | struct probe_resp *old_probe_resp; |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 1029 | struct cfg80211_chan_def chandef; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1030 | |
Michal Kazior | dbd7285 | 2014-01-29 07:56:21 +0100 | [diff] [blame] | 1031 | sdata_assert_lock(sdata); |
| 1032 | |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 1033 | old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata); |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1034 | if (!old_beacon) |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1035 | return -ENOENT; |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 1036 | old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1037 | |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 1038 | /* abort any running channel switch */ |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1039 | mutex_lock(&local->mtx); |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 1040 | sdata->vif.csa_active = false; |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 1041 | if (sdata->csa_block_tx) { |
| 1042 | ieee80211_wake_vif_queues(local, sdata, |
| 1043 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 1044 | sdata->csa_block_tx = false; |
| 1045 | } |
| 1046 | |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 1047 | mutex_unlock(&local->mtx); |
| 1048 | |
Simon Wunderlich | 1f3b8a2 | 2013-11-21 18:19:53 +0100 | [diff] [blame] | 1049 | kfree(sdata->u.ap.next_beacon); |
| 1050 | sdata->u.ap.next_beacon = NULL; |
| 1051 | |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1052 | /* turn off carrier for this interface and dependent VLANs */ |
Johannes Berg | 3edaf3e | 2012-04-03 10:24:00 +0200 | [diff] [blame] | 1053 | list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) |
| 1054 | netif_carrier_off(vlan->dev); |
| 1055 | netif_carrier_off(dev); |
| 1056 | |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1057 | /* remove beacon and probe response */ |
Stephen Hemminger | a9b3cd7 | 2011-08-01 16:19:00 +0000 | [diff] [blame] | 1058 | RCU_INIT_POINTER(sdata->u.ap.beacon, NULL); |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1059 | RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL); |
| 1060 | kfree_rcu(old_beacon, rcu_head); |
| 1061 | if (old_probe_resp) |
| 1062 | kfree_rcu(old_probe_resp, rcu_head); |
Emmanuel Grumbach | 8ffcc70 | 2014-01-23 14:28:16 +0200 | [diff] [blame] | 1063 | sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1064 | |
Johannes Berg | e716251 | 2013-12-04 23:18:37 +0100 | [diff] [blame] | 1065 | __sta_info_flush(sdata, true); |
Johannes Berg | 7907c7d | 2013-12-04 23:47:09 +0100 | [diff] [blame] | 1066 | ieee80211_free_keys(sdata, true); |
Johannes Berg | 75de911 | 2012-12-14 14:56:03 +0100 | [diff] [blame] | 1067 | |
Johannes Berg | d6a8322 | 2012-12-14 14:06:28 +0100 | [diff] [blame] | 1068 | sdata->vif.bss_conf.enable_beacon = false; |
Marek Puzyniak | 0eabccd | 2013-04-10 13:47:45 +0200 | [diff] [blame] | 1069 | sdata->vif.bss_conf.ssid_len = 0; |
Johannes Berg | d6a8322 | 2012-12-14 14:06:28 +0100 | [diff] [blame] | 1070 | clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state); |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1071 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED); |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 1072 | |
Simon Wunderlich | a6b368f | 2013-06-11 10:44:39 +0200 | [diff] [blame] | 1073 | if (sdata->wdev.cac_started) { |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 1074 | chandef = sdata->vif.bss_conf.chandef; |
Simon Wunderlich | a6b368f | 2013-06-11 10:44:39 +0200 | [diff] [blame] | 1075 | cancel_delayed_work_sync(&sdata->dfs_cac_timer_work); |
Janusz Dziedzic | d2859df | 2013-11-06 13:55:51 +0100 | [diff] [blame] | 1076 | cfg80211_cac_event(sdata->dev, &chandef, |
| 1077 | NL80211_RADAR_CAC_ABORTED, |
Simon Wunderlich | a6b368f | 2013-06-11 10:44:39 +0200 | [diff] [blame] | 1078 | GFP_KERNEL); |
| 1079 | } |
| 1080 | |
Johannes Berg | 1041638 | 2012-10-19 15:44:42 +0200 | [diff] [blame] | 1081 | drv_stop_ap(sdata->local, sdata); |
| 1082 | |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1083 | /* free all potentially still buffered bcast frames */ |
| 1084 | local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf); |
Felix Fietkau | 6b07d9c | 2016-08-02 11:13:41 +0200 | [diff] [blame] | 1085 | ieee80211_purge_tx_queue(&local->hw, &sdata->u.ap.ps.bc_buf); |
Johannes Berg | 7b20b8e | 2012-10-25 19:02:42 +0200 | [diff] [blame] | 1086 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 1087 | mutex_lock(&local->mtx); |
Michal Kazior | 4e141da | 2014-03-05 13:14:08 +0100 | [diff] [blame] | 1088 | ieee80211_vif_copy_chanctx_to_vlans(sdata, true); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1089 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 1090 | mutex_unlock(&local->mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1091 | |
Johannes Berg | 2d0ddec | 2009-04-23 16:13:26 +0200 | [diff] [blame] | 1092 | return 0; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 1093 | } |
| 1094 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1095 | /* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */ |
| 1096 | struct iapp_layer2_update { |
| 1097 | u8 da[ETH_ALEN]; /* broadcast */ |
| 1098 | u8 sa[ETH_ALEN]; /* STA addr */ |
| 1099 | __be16 len; /* 6 */ |
| 1100 | u8 dsap; /* 0 */ |
| 1101 | u8 ssap; /* 0 */ |
| 1102 | u8 control; |
| 1103 | u8 xid_info[3]; |
Eric Dumazet | bc10502 | 2010-06-03 03:21:52 -0700 | [diff] [blame] | 1104 | } __packed; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1105 | |
| 1106 | static void ieee80211_send_layer2_update(struct sta_info *sta) |
| 1107 | { |
| 1108 | struct iapp_layer2_update *msg; |
| 1109 | struct sk_buff *skb; |
| 1110 | |
| 1111 | /* Send Level 2 Update Frame to update forwarding tables in layer 2 |
| 1112 | * bridge devices */ |
| 1113 | |
| 1114 | skb = dev_alloc_skb(sizeof(*msg)); |
| 1115 | if (!skb) |
| 1116 | return; |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 1117 | msg = skb_put(skb, sizeof(*msg)); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1118 | |
| 1119 | /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID) |
| 1120 | * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */ |
| 1121 | |
Johannes Berg | e83e654 | 2012-07-13 16:23:07 +0200 | [diff] [blame] | 1122 | eth_broadcast_addr(msg->da); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 1123 | memcpy(msg->sa, sta->sta.addr, ETH_ALEN); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1124 | msg->len = htons(6); |
| 1125 | msg->dsap = 0; |
| 1126 | msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */ |
| 1127 | msg->control = 0xaf; /* XID response lsb.1111F101. |
| 1128 | * F=0 (no poll command; unsolicited frame) */ |
| 1129 | msg->xid_info[0] = 0x81; /* XID format identifier */ |
| 1130 | msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */ |
| 1131 | msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */ |
| 1132 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1133 | skb->dev = sta->sdata->dev; |
| 1134 | skb->protocol = eth_type_trans(skb, sta->sdata->dev); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1135 | memset(skb->cb, 0, sizeof(skb->cb)); |
John W. Linville | 06ee1c2 | 2010-07-19 11:52:59 -0400 | [diff] [blame] | 1136 | netif_rx_ni(skb); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1137 | } |
| 1138 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 1139 | static int sta_apply_auth_flags(struct ieee80211_local *local, |
| 1140 | struct sta_info *sta, |
| 1141 | u32 mask, u32 set) |
| 1142 | { |
| 1143 | int ret; |
| 1144 | |
| 1145 | if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) && |
| 1146 | set & BIT(NL80211_STA_FLAG_AUTHENTICATED) && |
| 1147 | !test_sta_flag(sta, WLAN_STA_AUTH)) { |
| 1148 | ret = sta_info_move_state(sta, IEEE80211_STA_AUTH); |
| 1149 | if (ret) |
| 1150 | return ret; |
| 1151 | } |
| 1152 | |
| 1153 | if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) && |
| 1154 | set & BIT(NL80211_STA_FLAG_ASSOCIATED) && |
| 1155 | !test_sta_flag(sta, WLAN_STA_ASSOC)) { |
Marek Puzyniak | c23e31c | 2015-03-08 18:04:22 +0200 | [diff] [blame] | 1156 | /* |
| 1157 | * When peer becomes associated, init rate control as |
| 1158 | * well. Some drivers require rate control initialized |
| 1159 | * before drv_sta_state() is called. |
| 1160 | */ |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1161 | if (!test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) |
Marek Puzyniak | c23e31c | 2015-03-08 18:04:22 +0200 | [diff] [blame] | 1162 | rate_control_rate_init(sta); |
| 1163 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 1164 | ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC); |
| 1165 | if (ret) |
| 1166 | return ret; |
| 1167 | } |
| 1168 | |
| 1169 | if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { |
| 1170 | if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) |
| 1171 | ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); |
| 1172 | else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) |
| 1173 | ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC); |
| 1174 | else |
| 1175 | ret = 0; |
| 1176 | if (ret) |
| 1177 | return ret; |
| 1178 | } |
| 1179 | |
| 1180 | if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) && |
| 1181 | !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) && |
| 1182 | test_sta_flag(sta, WLAN_STA_ASSOC)) { |
| 1183 | ret = sta_info_move_state(sta, IEEE80211_STA_AUTH); |
| 1184 | if (ret) |
| 1185 | return ret; |
| 1186 | } |
| 1187 | |
| 1188 | if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) && |
| 1189 | !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) && |
| 1190 | test_sta_flag(sta, WLAN_STA_AUTH)) { |
| 1191 | ret = sta_info_move_state(sta, IEEE80211_STA_NONE); |
| 1192 | if (ret) |
| 1193 | return ret; |
| 1194 | } |
| 1195 | |
| 1196 | return 0; |
| 1197 | } |
| 1198 | |
Johannes Berg | 1365770 | 2015-06-17 10:34:54 +0200 | [diff] [blame] | 1199 | static void sta_apply_mesh_params(struct ieee80211_local *local, |
| 1200 | struct sta_info *sta, |
| 1201 | struct station_parameters *params) |
| 1202 | { |
| 1203 | #ifdef CONFIG_MAC80211_MESH |
| 1204 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 1205 | u32 changed = 0; |
| 1206 | |
| 1207 | if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) { |
| 1208 | switch (params->plink_state) { |
| 1209 | case NL80211_PLINK_ESTAB: |
| 1210 | if (sta->mesh->plink_state != NL80211_PLINK_ESTAB) |
| 1211 | changed = mesh_plink_inc_estab_count(sdata); |
| 1212 | sta->mesh->plink_state = params->plink_state; |
Masashi Honma | 7d27a0b | 2016-07-01 10:19:34 +0900 | [diff] [blame] | 1213 | sta->mesh->aid = params->peer_aid; |
Johannes Berg | 1365770 | 2015-06-17 10:34:54 +0200 | [diff] [blame] | 1214 | |
| 1215 | ieee80211_mps_sta_status_update(sta); |
| 1216 | changed |= ieee80211_mps_set_sta_local_pm(sta, |
| 1217 | sdata->u.mesh.mshcfg.power_mode); |
| 1218 | break; |
| 1219 | case NL80211_PLINK_LISTEN: |
| 1220 | case NL80211_PLINK_BLOCKED: |
| 1221 | case NL80211_PLINK_OPN_SNT: |
| 1222 | case NL80211_PLINK_OPN_RCVD: |
| 1223 | case NL80211_PLINK_CNF_RCVD: |
| 1224 | case NL80211_PLINK_HOLDING: |
| 1225 | if (sta->mesh->plink_state == NL80211_PLINK_ESTAB) |
| 1226 | changed = mesh_plink_dec_estab_count(sdata); |
| 1227 | sta->mesh->plink_state = params->plink_state; |
| 1228 | |
| 1229 | ieee80211_mps_sta_status_update(sta); |
| 1230 | changed |= ieee80211_mps_set_sta_local_pm(sta, |
| 1231 | NL80211_MESH_POWER_UNKNOWN); |
| 1232 | break; |
| 1233 | default: |
| 1234 | /* nothing */ |
| 1235 | break; |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | switch (params->plink_action) { |
| 1240 | case NL80211_PLINK_ACTION_NO_ACTION: |
| 1241 | /* nothing */ |
| 1242 | break; |
| 1243 | case NL80211_PLINK_ACTION_OPEN: |
| 1244 | changed |= mesh_plink_open(sta); |
| 1245 | break; |
| 1246 | case NL80211_PLINK_ACTION_BLOCK: |
| 1247 | changed |= mesh_plink_block(sta); |
| 1248 | break; |
| 1249 | } |
| 1250 | |
| 1251 | if (params->local_pm) |
| 1252 | changed |= ieee80211_mps_set_sta_local_pm(sta, |
| 1253 | params->local_pm); |
| 1254 | |
| 1255 | ieee80211_mbss_info_change_notify(sdata, changed); |
| 1256 | #endif |
| 1257 | } |
| 1258 | |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1259 | static int sta_apply_parameters(struct ieee80211_local *local, |
| 1260 | struct sta_info *sta, |
| 1261 | struct station_parameters *params) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1262 | { |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1263 | int ret = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1264 | struct ieee80211_supported_band *sband; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1265 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1266 | u32 mask, set; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1267 | |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 1268 | sband = ieee80211_get_sband(sdata); |
| 1269 | if (!sband) |
| 1270 | return -EINVAL; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1271 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1272 | mask = params->sta_flags_mask; |
| 1273 | set = params->sta_flags_set; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1274 | |
Johannes Berg | d582cff | 2012-10-26 17:53:44 +0200 | [diff] [blame] | 1275 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
| 1276 | /* |
| 1277 | * In mesh mode, ASSOCIATED isn't part of the nl80211 |
| 1278 | * API but must follow AUTHENTICATED for driver state. |
| 1279 | */ |
| 1280 | if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) |
| 1281 | mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 1282 | if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) |
| 1283 | set |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1284 | } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { |
| 1285 | /* |
| 1286 | * TDLS -- everything follows authorized, but |
| 1287 | * only becoming authorized is possible, not |
| 1288 | * going back |
| 1289 | */ |
| 1290 | if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) { |
| 1291 | set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 1292 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 1293 | mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) | |
| 1294 | BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 1295 | } |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1296 | } |
| 1297 | |
Johannes Berg | 2c44be8 | 2015-03-30 15:09:20 +0200 | [diff] [blame] | 1298 | if (mask & BIT(NL80211_STA_FLAG_WME) && |
| 1299 | local->hw.queues >= IEEE80211_NUM_ACS) |
| 1300 | sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME); |
| 1301 | |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1302 | /* auth flags will be set later for TDLS, |
| 1303 | * and for unassociated stations that move to assocaited */ |
| 1304 | if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) && |
| 1305 | !((mask & BIT(NL80211_STA_FLAG_ASSOCIATED)) && |
| 1306 | (set & BIT(NL80211_STA_FLAG_ASSOCIATED)))) { |
Arik Nemtsov | 68885a5 | 2014-06-11 17:18:19 +0300 | [diff] [blame] | 1307 | ret = sta_apply_auth_flags(local, sta, mask, set); |
| 1308 | if (ret) |
| 1309 | return ret; |
| 1310 | } |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1311 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1312 | if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) { |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1313 | if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1314 | set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE); |
| 1315 | else |
| 1316 | clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE); |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1317 | } |
| 1318 | |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1319 | if (mask & BIT(NL80211_STA_FLAG_MFP)) { |
Tamizh chelvam | 93f0490 | 2015-10-07 10:40:04 +0530 | [diff] [blame] | 1320 | sta->sta.mfp = !!(set & BIT(NL80211_STA_FLAG_MFP)); |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1321 | if (set & BIT(NL80211_STA_FLAG_MFP)) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1322 | set_sta_flag(sta, WLAN_STA_MFP); |
| 1323 | else |
| 1324 | clear_sta_flag(sta, WLAN_STA_MFP); |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1325 | } |
Javier Cardona | b39c48f | 2011-04-07 15:08:30 -0700 | [diff] [blame] | 1326 | |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 1327 | if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) { |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 1328 | if (set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1329 | set_sta_flag(sta, WLAN_STA_TDLS_PEER); |
| 1330 | else |
| 1331 | clear_sta_flag(sta, WLAN_STA_TDLS_PEER); |
Arik Nemtsov | 07ba55d | 2011-09-28 14:12:53 +0300 | [diff] [blame] | 1332 | } |
Johannes Berg | eccb8e8 | 2009-05-11 21:57:56 +0300 | [diff] [blame] | 1333 | |
Arik Nemtsov | 9041c1f | 2014-11-09 18:50:15 +0200 | [diff] [blame] | 1334 | /* mark TDLS channel switch support, if the AP allows it */ |
| 1335 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && |
| 1336 | !sdata->u.mgd.tdls_chan_switch_prohibited && |
| 1337 | params->ext_capab_len >= 4 && |
| 1338 | params->ext_capab[3] & WLAN_EXT_CAPA4_TDLS_CHAN_SWITCH) |
| 1339 | set_sta_flag(sta, WLAN_STA_TDLS_CHAN_SWITCH); |
| 1340 | |
Arik Nemtsov | b98fb44 | 2015-06-10 20:42:59 +0300 | [diff] [blame] | 1341 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && |
Arik Nemtsov | 82c0cc9 | 2015-08-15 22:39:46 +0300 | [diff] [blame] | 1342 | !sdata->u.mgd.tdls_wider_bw_prohibited && |
Arik Nemtsov | b98fb44 | 2015-06-10 20:42:59 +0300 | [diff] [blame] | 1343 | ieee80211_hw_check(&local->hw, TDLS_WIDER_BW) && |
| 1344 | params->ext_capab_len >= 8 && |
| 1345 | params->ext_capab[7] & WLAN_EXT_CAPA8_TDLS_WIDE_BW_ENABLED) |
| 1346 | set_sta_flag(sta, WLAN_STA_TDLS_WIDER_BW); |
| 1347 | |
Johannes Berg | 3b9ce80 | 2011-09-27 20:56:12 +0200 | [diff] [blame] | 1348 | if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) { |
| 1349 | sta->sta.uapsd_queues = params->uapsd_queues; |
| 1350 | sta->sta.max_sp = params->max_sp; |
| 1351 | } |
Eliad Peller | 9533b4a | 2011-08-23 14:37:47 +0300 | [diff] [blame] | 1352 | |
Emmanuel Grumbach | 506bcfa | 2015-12-13 15:41:05 +0200 | [diff] [blame] | 1353 | /* The sender might not have sent the last bit, consider it to be 0 */ |
| 1354 | if (params->ext_capab_len >= 8) { |
| 1355 | u8 val = (params->ext_capab[7] & |
| 1356 | WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB) >> 7; |
| 1357 | |
| 1358 | /* we did get all the bits, take the MSB as well */ |
| 1359 | if (params->ext_capab_len >= 9) { |
| 1360 | u8 val_msb = params->ext_capab[8] & |
| 1361 | WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB; |
| 1362 | val_msb <<= 1; |
| 1363 | val |= val_msb; |
| 1364 | } |
| 1365 | |
| 1366 | switch (val) { |
| 1367 | case 1: |
| 1368 | sta->sta.max_amsdu_subframes = 32; |
| 1369 | break; |
| 1370 | case 2: |
| 1371 | sta->sta.max_amsdu_subframes = 16; |
| 1372 | break; |
| 1373 | case 3: |
| 1374 | sta->sta.max_amsdu_subframes = 8; |
| 1375 | break; |
| 1376 | default: |
| 1377 | sta->sta.max_amsdu_subframes = 0; |
| 1378 | } |
| 1379 | } |
| 1380 | |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1381 | /* |
Johannes Berg | 51b50fb | 2009-05-24 16:42:30 +0200 | [diff] [blame] | 1382 | * cfg80211 validates this (1-2007) and allows setting the AID |
| 1383 | * only when creating a new station entry |
| 1384 | */ |
| 1385 | if (params->aid) |
| 1386 | sta->sta.aid = params->aid; |
| 1387 | |
| 1388 | /* |
Johannes Berg | ba23d20 | 2012-12-27 17:32:09 +0100 | [diff] [blame] | 1389 | * Some of the following updates would be racy if called on an |
| 1390 | * existing station, via ieee80211_change_station(). However, |
| 1391 | * all such changes are rejected by cfg80211 except for updates |
| 1392 | * changing the supported rates on an existing but not yet used |
| 1393 | * TDLS peer. |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1394 | */ |
| 1395 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1396 | if (params->listen_interval >= 0) |
| 1397 | sta->listen_interval = params->listen_interval; |
| 1398 | |
| 1399 | if (params->supported_rates) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 1400 | ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef, |
| 1401 | sband, params->supported_rates, |
| 1402 | params->supported_rates_len, |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 1403 | &sta->sta.supp_rates[sband->band]); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1404 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1405 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 1406 | if (params->ht_capa) |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 1407 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, |
Johannes Berg | e1a0c6b | 2013-02-07 11:47:44 +0100 | [diff] [blame] | 1408 | params->ht_capa, sta); |
Jouni Malinen | 36aedc9 | 2008-08-25 11:58:58 +0300 | [diff] [blame] | 1409 | |
Emmanuel Grumbach | 506bcfa | 2015-12-13 15:41:05 +0200 | [diff] [blame] | 1410 | /* VHT can override some HT caps such as the A-MSDU max length */ |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 1411 | if (params->vht_capa) |
| 1412 | ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, |
Johannes Berg | 4a34215 | 2013-02-07 11:58:58 +0100 | [diff] [blame] | 1413 | params->vht_capa, sta); |
Mahesh Palivela | f461be3e | 2012-10-11 08:04:52 +0000 | [diff] [blame] | 1414 | |
Marek Kwaczynski | b1bce14a | 2014-02-03 14:44:44 +0100 | [diff] [blame] | 1415 | if (params->opmode_notif_used) { |
Marek Kwaczynski | b1bce14a | 2014-02-03 14:44:44 +0100 | [diff] [blame] | 1416 | /* returned value is only needed for rc update, but the |
| 1417 | * rc isn't initialized here yet, so ignore it |
| 1418 | */ |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 1419 | __ieee80211_vht_handle_opmode(sdata, sta, params->opmode_notif, |
| 1420 | sband->band); |
Marek Kwaczynski | b1bce14a | 2014-02-03 14:44:44 +0100 | [diff] [blame] | 1421 | } |
| 1422 | |
Ayala Beker | 52cfa1d | 2016-03-17 15:41:39 +0200 | [diff] [blame] | 1423 | if (params->support_p2p_ps >= 0) |
| 1424 | sta->sta.support_p2p_ps = params->support_p2p_ps; |
| 1425 | |
Johannes Berg | 1365770 | 2015-06-17 10:34:54 +0200 | [diff] [blame] | 1426 | if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 1427 | sta_apply_mesh_params(local, sta, params); |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1428 | |
Arik Nemtsov | 68885a5 | 2014-06-11 17:18:19 +0300 | [diff] [blame] | 1429 | /* set the STA state after all sta info from usermode has been set */ |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1430 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) || |
| 1431 | set & BIT(NL80211_STA_FLAG_ASSOCIATED)) { |
Arik Nemtsov | 68885a5 | 2014-06-11 17:18:19 +0300 | [diff] [blame] | 1432 | ret = sta_apply_auth_flags(local, sta, mask, set); |
| 1433 | if (ret) |
| 1434 | return ret; |
| 1435 | } |
| 1436 | |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1437 | return 0; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 1441 | const u8 *mac, |
| 1442 | struct station_parameters *params) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1443 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1444 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1445 | struct sta_info *sta; |
| 1446 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1447 | int err; |
Jouni Malinen | b8d476c | 2008-12-12 17:08:31 +0200 | [diff] [blame] | 1448 | int layer2_update; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1449 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1450 | if (params->vlan) { |
| 1451 | sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
| 1452 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 1453 | if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && |
| 1454 | sdata->vif.type != NL80211_IFTYPE_AP) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1455 | return -EINVAL; |
| 1456 | } else |
| 1457 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1458 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 1459 | if (ether_addr_equal(mac, sdata->vif.addr)) |
Johannes Berg | 03e4497 | 2008-02-27 09:56:40 +0100 | [diff] [blame] | 1460 | return -EINVAL; |
| 1461 | |
| 1462 | if (is_multicast_ether_addr(mac)) |
| 1463 | return -EINVAL; |
| 1464 | |
| 1465 | sta = sta_info_alloc(sdata, mac, GFP_KERNEL); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1466 | if (!sta) |
| 1467 | return -ENOMEM; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1468 | |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1469 | if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) |
| 1470 | sta->sta.tdls = true; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1471 | |
Johannes Berg | d9a7ddb | 2011-12-14 12:35:30 +0100 | [diff] [blame] | 1472 | err = sta_apply_parameters(local, sta, params); |
| 1473 | if (err) { |
| 1474 | sta_info_free(local, sta); |
| 1475 | return err; |
| 1476 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1477 | |
Arik Nemtsov | d64cf63 | 2011-11-07 23:24:39 +0200 | [diff] [blame] | 1478 | /* |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1479 | * for TDLS and for unassociated station, rate control should be |
| 1480 | * initialized only when rates are known and station is marked |
| 1481 | * authorized/associated |
Arik Nemtsov | d64cf63 | 2011-11-07 23:24:39 +0200 | [diff] [blame] | 1482 | */ |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1483 | if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER) && |
| 1484 | test_sta_flag(sta, WLAN_STA_ASSOC)) |
Arik Nemtsov | d64cf63 | 2011-11-07 23:24:39 +0200 | [diff] [blame] | 1485 | rate_control_rate_init(sta); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1486 | |
Jouni Malinen | b8d476c | 2008-12-12 17:08:31 +0200 | [diff] [blame] | 1487 | layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN || |
| 1488 | sdata->vif.type == NL80211_IFTYPE_AP; |
| 1489 | |
Johannes Berg | 34e8950 | 2010-02-03 13:59:58 +0100 | [diff] [blame] | 1490 | err = sta_info_insert_rcu(sta); |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1491 | if (err) { |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1492 | rcu_read_unlock(); |
| 1493 | return err; |
| 1494 | } |
| 1495 | |
Jouni Malinen | b8d476c | 2008-12-12 17:08:31 +0200 | [diff] [blame] | 1496 | if (layer2_update) |
Johannes Berg | 73651ee | 2008-02-25 16:27:47 +0100 | [diff] [blame] | 1497 | ieee80211_send_layer2_update(sta); |
| 1498 | |
| 1499 | rcu_read_unlock(); |
| 1500 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1501 | return 0; |
| 1502 | } |
| 1503 | |
| 1504 | static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev, |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 1505 | struct station_del_parameters *params) |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1506 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1507 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1508 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1509 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1510 | |
Jouni Malinen | 89c771e | 2014-10-10 20:52:40 +0300 | [diff] [blame] | 1511 | if (params->mac) |
| 1512 | return sta_info_destroy_addr_bss(sdata, params->mac); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 1513 | |
Johannes Berg | b998e8b | 2012-12-13 23:07:46 +0100 | [diff] [blame] | 1514 | sta_info_flush(sdata); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1515 | return 0; |
| 1516 | } |
| 1517 | |
| 1518 | static int ieee80211_change_station(struct wiphy *wiphy, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 1519 | struct net_device *dev, const u8 *mac, |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1520 | struct station_parameters *params) |
| 1521 | { |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 1522 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1523 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1524 | struct sta_info *sta; |
| 1525 | struct ieee80211_sub_if_data *vlansdata; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1526 | enum cfg80211_station_type statype; |
Eliad Peller | 35b8862 | 2011-12-29 14:41:39 +0200 | [diff] [blame] | 1527 | int err; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1528 | |
Johannes Berg | 87be1e1 | 2011-12-14 12:20:29 +0100 | [diff] [blame] | 1529 | mutex_lock(&local->sta_mtx); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 1530 | |
Felix Fietkau | 0e5ded5 | 2010-01-08 18:10:58 +0100 | [diff] [blame] | 1531 | sta = sta_info_get_bss(sdata, mac); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 1532 | if (!sta) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1533 | err = -ENOENT; |
| 1534 | goto out_err; |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 1535 | } |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1536 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1537 | switch (sdata->vif.type) { |
| 1538 | case NL80211_IFTYPE_MESH_POINT: |
Thomas Pedersen | a6dad6a | 2013-03-04 13:06:12 -0800 | [diff] [blame] | 1539 | if (sdata->u.mesh.user_mpm) |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 1540 | statype = CFG80211_STA_MESH_PEER_USER; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1541 | else |
Thomas Pedersen | eef941e | 2013-03-04 13:06:11 -0800 | [diff] [blame] | 1542 | statype = CFG80211_STA_MESH_PEER_KERNEL; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1543 | break; |
| 1544 | case NL80211_IFTYPE_ADHOC: |
| 1545 | statype = CFG80211_STA_IBSS; |
| 1546 | break; |
| 1547 | case NL80211_IFTYPE_STATION: |
| 1548 | if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { |
| 1549 | statype = CFG80211_STA_AP_STA; |
| 1550 | break; |
| 1551 | } |
| 1552 | if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) |
| 1553 | statype = CFG80211_STA_TDLS_PEER_ACTIVE; |
| 1554 | else |
| 1555 | statype = CFG80211_STA_TDLS_PEER_SETUP; |
| 1556 | break; |
| 1557 | case NL80211_IFTYPE_AP: |
| 1558 | case NL80211_IFTYPE_AP_VLAN: |
Ayala Beker | 44674d9 | 2015-09-23 10:41:27 +0200 | [diff] [blame] | 1559 | if (test_sta_flag(sta, WLAN_STA_ASSOC)) |
| 1560 | statype = CFG80211_STA_AP_CLIENT; |
| 1561 | else |
| 1562 | statype = CFG80211_STA_AP_CLIENT_UNASSOC; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1563 | break; |
| 1564 | default: |
| 1565 | err = -EOPNOTSUPP; |
| 1566 | goto out_err; |
Johannes Berg | bdd90d5 | 2011-12-14 12:20:27 +0100 | [diff] [blame] | 1567 | } |
| 1568 | |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1569 | err = cfg80211_check_station_change(wiphy, params, statype); |
| 1570 | if (err) |
| 1571 | goto out_err; |
| 1572 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1573 | if (params->vlan && params->vlan != sta->sdata->dev) { |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1574 | vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan); |
| 1575 | |
Johannes Berg | 9bc383d | 2009-11-19 11:55:19 +0100 | [diff] [blame] | 1576 | if (params->vlan->ieee80211_ptr->use_4addr) { |
Johannes Berg | 3305443 | 2009-11-20 10:09:14 +0100 | [diff] [blame] | 1577 | if (vlansdata->u.vlan.sta) { |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1578 | err = -EBUSY; |
| 1579 | goto out_err; |
Johannes Berg | 3305443 | 2009-11-20 10:09:14 +0100 | [diff] [blame] | 1580 | } |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 1581 | |
Eric Dumazet | cf778b0 | 2012-01-12 04:41:32 +0000 | [diff] [blame] | 1582 | rcu_assign_pointer(vlansdata->u.vlan.sta, sta); |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 1583 | __ieee80211_check_fast_rx_iface(vlansdata); |
Felix Fietkau | 7e3ed02 | 2012-04-23 19:49:03 +0200 | [diff] [blame] | 1584 | } |
| 1585 | |
| 1586 | if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN && |
Michael Braun | 72f15d5 | 2016-10-10 19:12:21 +0200 | [diff] [blame] | 1587 | sta->sdata->u.vlan.sta) |
Monam Agarwal | 0c2bef46 | 2014-03-24 00:51:43 +0530 | [diff] [blame] | 1588 | RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL); |
Michael Braun | 72f15d5 | 2016-10-10 19:12:21 +0200 | [diff] [blame] | 1589 | |
| 1590 | if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) |
| 1591 | ieee80211_vif_dec_num_mcast(sta->sdata); |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 1592 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1593 | sta->sdata = vlansdata; |
Michal Kazior | 464daaf | 2015-05-19 14:13:36 +0200 | [diff] [blame] | 1594 | ieee80211_check_fast_xmit(sta); |
Felix Fietkau | 7e3ed02 | 2012-04-23 19:49:03 +0200 | [diff] [blame] | 1595 | |
Michael Braun | 72f15d5 | 2016-10-10 19:12:21 +0200 | [diff] [blame] | 1596 | if (test_sta_flag(sta, WLAN_STA_AUTHORIZED)) |
| 1597 | ieee80211_vif_inc_num_mcast(sta->sdata); |
Felix Fietkau | 7e3ed02 | 2012-04-23 19:49:03 +0200 | [diff] [blame] | 1598 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1599 | ieee80211_send_layer2_update(sta); |
| 1600 | } |
| 1601 | |
Eliad Peller | 35b8862 | 2011-12-29 14:41:39 +0200 | [diff] [blame] | 1602 | err = sta_apply_parameters(local, sta, params); |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1603 | if (err) |
| 1604 | goto out_err; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1605 | |
Johannes Berg | 87be1e1 | 2011-12-14 12:20:29 +0100 | [diff] [blame] | 1606 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | 98dd6a5 | 2008-04-10 15:36:09 +0200 | [diff] [blame] | 1607 | |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 1608 | if ((sdata->vif.type == NL80211_IFTYPE_AP || |
| 1609 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN) && |
| 1610 | sta->known_smps_mode != sta->sdata->bss->req_smps && |
| 1611 | test_sta_flag(sta, WLAN_STA_AUTHORIZED) && |
| 1612 | sta_info_tx_streams(sta) != 1) { |
| 1613 | ht_dbg(sta->sdata, |
| 1614 | "%pM just authorized and MIMO capable - update SMPS\n", |
| 1615 | sta->sta.addr); |
| 1616 | ieee80211_send_smps_action(sta->sdata, |
| 1617 | sta->sdata->bss->req_smps, |
| 1618 | sta->sta.addr, |
| 1619 | sta->sdata->vif.bss_conf.bssid); |
| 1620 | } |
| 1621 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1622 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 1623 | params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) { |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 1624 | ieee80211_recalc_ps(local); |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 1625 | ieee80211_recalc_ps_vif(sdata); |
| 1626 | } |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1627 | |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1628 | return 0; |
Johannes Berg | 77ee7c8 | 2013-02-15 00:48:33 +0100 | [diff] [blame] | 1629 | out_err: |
| 1630 | mutex_unlock(&local->sta_mtx); |
| 1631 | return err; |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 1632 | } |
| 1633 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1634 | #ifdef CONFIG_MAC80211_MESH |
| 1635 | static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 1636 | const u8 *dst, const u8 *next_hop) |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1637 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1638 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1639 | struct mesh_path *mpath; |
| 1640 | struct sta_info *sta; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1641 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1642 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1643 | |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1644 | rcu_read_lock(); |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 1645 | sta = sta_info_get(sdata, next_hop); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1646 | if (!sta) { |
| 1647 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1648 | return -ENOENT; |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1649 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1650 | |
Bob Copeland | ae76eef | 2013-03-29 09:38:39 -0400 | [diff] [blame] | 1651 | mpath = mesh_path_add(sdata, dst); |
| 1652 | if (IS_ERR(mpath)) { |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1653 | rcu_read_unlock(); |
Bob Copeland | ae76eef | 2013-03-29 09:38:39 -0400 | [diff] [blame] | 1654 | return PTR_ERR(mpath); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1655 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1656 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1657 | mesh_path_fix_nexthop(mpath, sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1658 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1659 | rcu_read_unlock(); |
| 1660 | return 0; |
| 1661 | } |
| 1662 | |
| 1663 | static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 1664 | const u8 *dst) |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1665 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1666 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1667 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1668 | if (dst) |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 1669 | return mesh_path_del(sdata, dst); |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1670 | |
Javier Cardona | ece1a2e | 2011-08-29 13:23:04 -0700 | [diff] [blame] | 1671 | mesh_path_flush_by_iface(sdata); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1672 | return 0; |
| 1673 | } |
| 1674 | |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 1675 | static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 1676 | const u8 *dst, const u8 *next_hop) |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1677 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1678 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1679 | struct mesh_path *mpath; |
| 1680 | struct sta_info *sta; |
| 1681 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1682 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1683 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1684 | rcu_read_lock(); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1685 | |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 1686 | sta = sta_info_get(sdata, next_hop); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1687 | if (!sta) { |
| 1688 | rcu_read_unlock(); |
| 1689 | return -ENOENT; |
| 1690 | } |
| 1691 | |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 1692 | mpath = mesh_path_lookup(sdata, dst); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1693 | if (!mpath) { |
| 1694 | rcu_read_unlock(); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1695 | return -ENOENT; |
| 1696 | } |
| 1697 | |
| 1698 | mesh_path_fix_nexthop(mpath, sta); |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 1699 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1700 | rcu_read_unlock(); |
| 1701 | return 0; |
| 1702 | } |
| 1703 | |
| 1704 | static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop, |
| 1705 | struct mpath_info *pinfo) |
| 1706 | { |
Johannes Berg | a3836e0 | 2011-05-12 15:11:37 +0200 | [diff] [blame] | 1707 | struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop); |
| 1708 | |
| 1709 | if (next_hop_sta) |
| 1710 | memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1711 | else |
Joe Perches | c84a67a | 2015-03-02 19:54:57 -0800 | [diff] [blame] | 1712 | eth_zero_addr(next_hop); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1713 | |
LEO Airwarosu Yoichi Shinoda | 7ce8c7a | 2012-08-27 22:28:16 +0900 | [diff] [blame] | 1714 | memset(pinfo, 0, sizeof(*pinfo)); |
| 1715 | |
Bob Copeland | 2bdaf38 | 2016-02-28 20:03:56 -0500 | [diff] [blame] | 1716 | pinfo->generation = mpath->sdata->u.mesh.mesh_paths_generation; |
Johannes Berg | f5ea912 | 2009-08-07 16:17:38 +0200 | [diff] [blame] | 1717 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1718 | pinfo->filled = MPATH_INFO_FRAME_QLEN | |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 1719 | MPATH_INFO_SN | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1720 | MPATH_INFO_METRIC | |
| 1721 | MPATH_INFO_EXPTIME | |
| 1722 | MPATH_INFO_DISCOVERY_TIMEOUT | |
| 1723 | MPATH_INFO_DISCOVERY_RETRIES | |
| 1724 | MPATH_INFO_FLAGS; |
| 1725 | |
| 1726 | pinfo->frame_qlen = mpath->frame_queue.qlen; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 1727 | pinfo->sn = mpath->sn; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1728 | pinfo->metric = mpath->metric; |
| 1729 | if (time_before(jiffies, mpath->exp_time)) |
| 1730 | pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies); |
| 1731 | pinfo->discovery_timeout = |
| 1732 | jiffies_to_msecs(mpath->discovery_timeout); |
| 1733 | pinfo->discovery_retries = mpath->discovery_retries; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1734 | if (mpath->flags & MESH_PATH_ACTIVE) |
| 1735 | pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE; |
| 1736 | if (mpath->flags & MESH_PATH_RESOLVING) |
| 1737 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING; |
Rui Paulo | d19b3bf | 2009-11-09 23:46:55 +0000 | [diff] [blame] | 1738 | if (mpath->flags & MESH_PATH_SN_VALID) |
| 1739 | pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1740 | if (mpath->flags & MESH_PATH_FIXED) |
| 1741 | pinfo->flags |= NL80211_MPATH_FLAG_FIXED; |
LEO Airwarosu Yoichi Shinoda | 7ce8c7a | 2012-08-27 22:28:16 +0900 | [diff] [blame] | 1742 | if (mpath->flags & MESH_PATH_RESOLVED) |
| 1743 | pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev, |
| 1747 | u8 *dst, u8 *next_hop, struct mpath_info *pinfo) |
| 1748 | |
| 1749 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1750 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1751 | struct mesh_path *mpath; |
| 1752 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1753 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1754 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1755 | rcu_read_lock(); |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 1756 | mpath = mesh_path_lookup(sdata, dst); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1757 | if (!mpath) { |
| 1758 | rcu_read_unlock(); |
| 1759 | return -ENOENT; |
| 1760 | } |
| 1761 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 1762 | mpath_set_pinfo(mpath, next_hop, pinfo); |
| 1763 | rcu_read_unlock(); |
| 1764 | return 0; |
| 1765 | } |
| 1766 | |
| 1767 | static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 3b3a016 | 2014-05-19 17:19:31 +0200 | [diff] [blame] | 1768 | int idx, u8 *dst, u8 *next_hop, |
| 1769 | struct mpath_info *pinfo) |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1770 | { |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1771 | struct ieee80211_sub_if_data *sdata; |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1772 | struct mesh_path *mpath; |
| 1773 | |
Johannes Berg | 14db74b | 2008-07-29 13:22:52 +0200 | [diff] [blame] | 1774 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1775 | |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1776 | rcu_read_lock(); |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 1777 | mpath = mesh_path_lookup_by_idx(sdata, idx); |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 1778 | if (!mpath) { |
| 1779 | rcu_read_unlock(); |
| 1780 | return -ENOENT; |
| 1781 | } |
| 1782 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 1783 | mpath_set_pinfo(mpath, next_hop, pinfo); |
| 1784 | rcu_read_unlock(); |
| 1785 | return 0; |
| 1786 | } |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1787 | |
Henning Rogge | a2db2ed | 2014-09-12 08:58:50 +0200 | [diff] [blame] | 1788 | static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp, |
| 1789 | struct mpath_info *pinfo) |
| 1790 | { |
| 1791 | memset(pinfo, 0, sizeof(*pinfo)); |
| 1792 | memcpy(mpp, mpath->mpp, ETH_ALEN); |
| 1793 | |
Bob Copeland | 2bdaf38 | 2016-02-28 20:03:56 -0500 | [diff] [blame] | 1794 | pinfo->generation = mpath->sdata->u.mesh.mpp_paths_generation; |
Henning Rogge | a2db2ed | 2014-09-12 08:58:50 +0200 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev, |
| 1798 | u8 *dst, u8 *mpp, struct mpath_info *pinfo) |
| 1799 | |
| 1800 | { |
| 1801 | struct ieee80211_sub_if_data *sdata; |
| 1802 | struct mesh_path *mpath; |
| 1803 | |
| 1804 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1805 | |
| 1806 | rcu_read_lock(); |
| 1807 | mpath = mpp_path_lookup(sdata, dst); |
| 1808 | if (!mpath) { |
| 1809 | rcu_read_unlock(); |
| 1810 | return -ENOENT; |
| 1811 | } |
| 1812 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 1813 | mpp_set_pinfo(mpath, mpp, pinfo); |
| 1814 | rcu_read_unlock(); |
| 1815 | return 0; |
| 1816 | } |
| 1817 | |
| 1818 | static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev, |
| 1819 | int idx, u8 *dst, u8 *mpp, |
| 1820 | struct mpath_info *pinfo) |
| 1821 | { |
| 1822 | struct ieee80211_sub_if_data *sdata; |
| 1823 | struct mesh_path *mpath; |
| 1824 | |
| 1825 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1826 | |
| 1827 | rcu_read_lock(); |
| 1828 | mpath = mpp_path_lookup_by_idx(sdata, idx); |
| 1829 | if (!mpath) { |
| 1830 | rcu_read_unlock(); |
| 1831 | return -ENOENT; |
| 1832 | } |
| 1833 | memcpy(dst, mpath->dst, ETH_ALEN); |
| 1834 | mpp_set_pinfo(mpath, mpp, pinfo); |
| 1835 | rcu_read_unlock(); |
| 1836 | return 0; |
| 1837 | } |
| 1838 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 1839 | static int ieee80211_get_mesh_config(struct wiphy *wiphy, |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1840 | struct net_device *dev, |
| 1841 | struct mesh_config *conf) |
| 1842 | { |
| 1843 | struct ieee80211_sub_if_data *sdata; |
| 1844 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 1845 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1846 | memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config)); |
| 1847 | return 0; |
| 1848 | } |
| 1849 | |
| 1850 | static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask) |
| 1851 | { |
| 1852 | return (mask >> (parm-1)) & 0x1; |
| 1853 | } |
| 1854 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 1855 | static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh, |
| 1856 | const struct mesh_setup *setup) |
| 1857 | { |
| 1858 | u8 *new_ie; |
| 1859 | const u8 *old_ie; |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 1860 | struct ieee80211_sub_if_data *sdata = container_of(ifmsh, |
| 1861 | struct ieee80211_sub_if_data, u.mesh); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 1862 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 1863 | /* allocate information elements */ |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 1864 | new_ie = NULL; |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 1865 | old_ie = ifmsh->ie; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 1866 | |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 1867 | if (setup->ie_len) { |
| 1868 | new_ie = kmemdup(setup->ie, setup->ie_len, |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 1869 | GFP_KERNEL); |
| 1870 | if (!new_ie) |
| 1871 | return -ENOMEM; |
| 1872 | } |
Javier Cardona | 581a8b0 | 2011-04-07 15:08:27 -0700 | [diff] [blame] | 1873 | ifmsh->ie_len = setup->ie_len; |
| 1874 | ifmsh->ie = new_ie; |
| 1875 | kfree(old_ie); |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 1876 | |
| 1877 | /* now copy the rest of the setup parameters */ |
| 1878 | ifmsh->mesh_id_len = setup->mesh_id_len; |
| 1879 | memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len); |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 1880 | ifmsh->mesh_sp_id = setup->sync_method; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 1881 | ifmsh->mesh_pp_id = setup->path_sel_proto; |
| 1882 | ifmsh->mesh_pm_id = setup->path_metric; |
Thomas Pedersen | a6dad6a | 2013-03-04 13:06:12 -0800 | [diff] [blame] | 1883 | ifmsh->user_mpm = setup->user_mpm; |
Colleen Twitty | 0d4261a | 2013-05-08 11:46:00 -0700 | [diff] [blame] | 1884 | ifmsh->mesh_auth_id = setup->auth_id; |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 1885 | ifmsh->security = IEEE80211_MESH_SEC_NONE; |
Benjamin Berg | 0ab2e55 | 2017-05-16 11:23:13 +0200 | [diff] [blame] | 1886 | ifmsh->userspace_handles_dfs = setup->userspace_handles_dfs; |
Javier Cardona | b130e5c | 2011-05-03 16:57:07 -0700 | [diff] [blame] | 1887 | if (setup->is_authenticated) |
| 1888 | ifmsh->security |= IEEE80211_MESH_SEC_AUTHED; |
| 1889 | if (setup->is_secure) |
| 1890 | ifmsh->security |= IEEE80211_MESH_SEC_SECURED; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 1891 | |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 1892 | /* mcast rate setting in Mesh Node */ |
| 1893 | memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate, |
| 1894 | sizeof(setup->mcast_rate)); |
Ashok Nagarajan | ffb3cf3 | 2013-06-03 10:33:36 -0700 | [diff] [blame] | 1895 | sdata->vif.bss_conf.basic_rates = setup->basic_rates; |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 1896 | |
Marco Porsch | 9bdbf04 | 2013-01-07 16:04:51 +0100 | [diff] [blame] | 1897 | sdata->vif.bss_conf.beacon_int = setup->beacon_interval; |
| 1898 | sdata->vif.bss_conf.dtim_period = setup->dtim_period; |
| 1899 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 1900 | return 0; |
| 1901 | } |
| 1902 | |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 1903 | static int ieee80211_update_mesh_config(struct wiphy *wiphy, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 1904 | struct net_device *dev, u32 mask, |
| 1905 | const struct mesh_config *nconf) |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1906 | { |
| 1907 | struct mesh_config *conf; |
| 1908 | struct ieee80211_sub_if_data *sdata; |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 1909 | struct ieee80211_if_mesh *ifmsh; |
| 1910 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1911 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 1912 | ifmsh = &sdata->u.mesh; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1913 | |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1914 | /* Set the config options which we are interested in setting */ |
| 1915 | conf = &(sdata->u.mesh.mshcfg); |
| 1916 | if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask)) |
| 1917 | conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout; |
| 1918 | if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask)) |
| 1919 | conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout; |
| 1920 | if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask)) |
| 1921 | conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout; |
| 1922 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask)) |
| 1923 | conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks; |
| 1924 | if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask)) |
| 1925 | conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries; |
| 1926 | if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask)) |
| 1927 | conf->dot11MeshTTL = nconf->dot11MeshTTL; |
Javier Cardona | 45904f2 | 2010-12-03 09:20:40 +0100 | [diff] [blame] | 1928 | if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask)) |
Chun-Yeow Yeoh | 58886a9 | 2012-06-15 00:23:53 +0800 | [diff] [blame] | 1929 | conf->element_ttl = nconf->element_ttl; |
Thomas Pedersen | 146bb48 | 2013-03-04 13:06:14 -0800 | [diff] [blame] | 1930 | if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) { |
| 1931 | if (ifmsh->user_mpm) |
| 1932 | return -EBUSY; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1933 | conf->auto_open_plinks = nconf->auto_open_plinks; |
Thomas Pedersen | 146bb48 | 2013-03-04 13:06:14 -0800 | [diff] [blame] | 1934 | } |
Javier Cardona | d299a1f | 2012-03-31 11:31:33 -0700 | [diff] [blame] | 1935 | if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask)) |
| 1936 | conf->dot11MeshNbrOffsetMaxNeighbor = |
| 1937 | nconf->dot11MeshNbrOffsetMaxNeighbor; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1938 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask)) |
| 1939 | conf->dot11MeshHWMPmaxPREQretries = |
| 1940 | nconf->dot11MeshHWMPmaxPREQretries; |
| 1941 | if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask)) |
| 1942 | conf->path_refresh_time = nconf->path_refresh_time; |
| 1943 | if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask)) |
| 1944 | conf->min_discovery_timeout = nconf->min_discovery_timeout; |
| 1945 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask)) |
| 1946 | conf->dot11MeshHWMPactivePathTimeout = |
| 1947 | nconf->dot11MeshHWMPactivePathTimeout; |
| 1948 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask)) |
| 1949 | conf->dot11MeshHWMPpreqMinInterval = |
| 1950 | nconf->dot11MeshHWMPpreqMinInterval; |
Thomas Pedersen | dca7e94 | 2011-11-24 17:15:24 -0800 | [diff] [blame] | 1951 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask)) |
| 1952 | conf->dot11MeshHWMPperrMinInterval = |
| 1953 | nconf->dot11MeshHWMPperrMinInterval; |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 1954 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME, |
| 1955 | mask)) |
| 1956 | conf->dot11MeshHWMPnetDiameterTraversalTime = |
| 1957 | nconf->dot11MeshHWMPnetDiameterTraversalTime; |
Rui Paulo | 63c5723 | 2009-11-09 23:46:57 +0000 | [diff] [blame] | 1958 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) { |
| 1959 | conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode; |
| 1960 | ieee80211_mesh_root_setup(ifmsh); |
| 1961 | } |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 1962 | if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) { |
Thomas Pedersen | c6133661 | 2011-08-25 10:36:14 -0700 | [diff] [blame] | 1963 | /* our current gate announcement implementation rides on root |
| 1964 | * announcements, so require this ifmsh to also be a root node |
| 1965 | * */ |
| 1966 | if (nconf->dot11MeshGateAnnouncementProtocol && |
Chun-Yeow Yeoh | dbb912c | 2012-06-14 02:06:09 +0800 | [diff] [blame] | 1967 | !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) { |
| 1968 | conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN; |
Thomas Pedersen | c6133661 | 2011-08-25 10:36:14 -0700 | [diff] [blame] | 1969 | ieee80211_mesh_root_setup(ifmsh); |
| 1970 | } |
Javier Cardona | 16dd726 | 2011-08-09 16:45:11 -0700 | [diff] [blame] | 1971 | conf->dot11MeshGateAnnouncementProtocol = |
| 1972 | nconf->dot11MeshGateAnnouncementProtocol; |
| 1973 | } |
Chun-Yeow Yeoh | a4f606e | 2012-06-11 11:59:36 +0800 | [diff] [blame] | 1974 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) |
Javier Cardona | 0507e15 | 2011-08-09 16:45:10 -0700 | [diff] [blame] | 1975 | conf->dot11MeshHWMPRannInterval = |
| 1976 | nconf->dot11MeshHWMPRannInterval; |
Chun-Yeow Yeoh | 94f9065 | 2012-01-21 01:02:16 +0800 | [diff] [blame] | 1977 | if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask)) |
| 1978 | conf->dot11MeshForwarding = nconf->dot11MeshForwarding; |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 1979 | if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) { |
| 1980 | /* our RSSI threshold implementation is supported only for |
| 1981 | * devices that report signal in dBm. |
| 1982 | */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1983 | if (!ieee80211_hw_check(&sdata->local->hw, SIGNAL_DBM)) |
Ashok Nagarajan | 5533513 | 2012-02-28 17:04:08 -0800 | [diff] [blame] | 1984 | return -ENOTSUPP; |
| 1985 | conf->rssi_threshold = nconf->rssi_threshold; |
| 1986 | } |
Ashok Nagarajan | 70c33ea | 2012-04-30 14:20:32 -0700 | [diff] [blame] | 1987 | if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) { |
| 1988 | conf->ht_opmode = nconf->ht_opmode; |
| 1989 | sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode; |
| 1990 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT); |
| 1991 | } |
Chun-Yeow Yeoh | ac1073a | 2012-06-14 02:06:06 +0800 | [diff] [blame] | 1992 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask)) |
| 1993 | conf->dot11MeshHWMPactivePathToRootTimeout = |
| 1994 | nconf->dot11MeshHWMPactivePathToRootTimeout; |
| 1995 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask)) |
| 1996 | conf->dot11MeshHWMProotInterval = |
| 1997 | nconf->dot11MeshHWMProotInterval; |
Chun-Yeow Yeoh | 728b19e | 2012-06-14 02:06:10 +0800 | [diff] [blame] | 1998 | if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask)) |
| 1999 | conf->dot11MeshHWMPconfirmationInterval = |
| 2000 | nconf->dot11MeshHWMPconfirmationInterval; |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 2001 | if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) { |
| 2002 | conf->power_mode = nconf->power_mode; |
| 2003 | ieee80211_mps_local_status_update(sdata); |
| 2004 | } |
Thomas Pedersen | 2b5e196 | 2013-02-14 11:20:13 -0800 | [diff] [blame] | 2005 | if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask)) |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 2006 | conf->dot11MeshAwakeWindowDuration = |
| 2007 | nconf->dot11MeshAwakeWindowDuration; |
Colleen Twitty | 66de671 | 2013-06-03 09:53:40 -0700 | [diff] [blame] | 2008 | if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask)) |
| 2009 | conf->plink_timeout = nconf->plink_timeout; |
Thomas Pedersen | 2b5e196 | 2013-02-14 11:20:13 -0800 | [diff] [blame] | 2010 | ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON); |
colin@cozybit.com | 93da9cc | 2008-10-21 12:03:48 -0700 | [diff] [blame] | 2011 | return 0; |
| 2012 | } |
| 2013 | |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2014 | static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev, |
| 2015 | const struct mesh_config *conf, |
| 2016 | const struct mesh_setup *setup) |
| 2017 | { |
| 2018 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2019 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2020 | int err; |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2021 | |
Javier Cardona | c80d545 | 2010-12-16 17:37:49 -0800 | [diff] [blame] | 2022 | memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config)); |
| 2023 | err = copy_mesh_setup(ifmsh, setup); |
| 2024 | if (err) |
| 2025 | return err; |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2026 | |
Denis Kenzior | 018f6fb | 2018-03-26 12:52:51 -0500 | [diff] [blame] | 2027 | sdata->control_port_over_nl80211 = setup->control_port_over_nl80211; |
| 2028 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 2029 | /* can mesh use other SMPS modes? */ |
| 2030 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
| 2031 | sdata->needed_rx_chains = sdata->local->rx_chains; |
| 2032 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2033 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 2034 | err = ieee80211_vif_use_channel(sdata, &setup->chandef, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2035 | IEEE80211_CHANCTX_SHARED); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2036 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | cc1d280 | 2012-05-16 23:50:20 +0200 | [diff] [blame] | 2037 | if (err) |
| 2038 | return err; |
| 2039 | |
Thomas Pedersen | 2b5e196 | 2013-02-14 11:20:13 -0800 | [diff] [blame] | 2040 | return ieee80211_start_mesh(sdata); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2041 | } |
| 2042 | |
| 2043 | static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev) |
| 2044 | { |
| 2045 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2046 | |
| 2047 | ieee80211_stop_mesh(sdata); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2048 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2049 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2050 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 2051 | |
| 2052 | return 0; |
| 2053 | } |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 2054 | #endif |
| 2055 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2056 | static int ieee80211_change_bss(struct wiphy *wiphy, |
| 2057 | struct net_device *dev, |
| 2058 | struct bss_parameters *params) |
| 2059 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2060 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2061 | struct ieee80211_supported_band *sband; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2062 | u32 changed = 0; |
| 2063 | |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 2064 | if (!sdata_dereference(sdata->u.ap.beacon, sdata)) |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2065 | return -ENOENT; |
| 2066 | |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2067 | sband = ieee80211_get_sband(sdata); |
| 2068 | if (!sband) |
| 2069 | return -EINVAL; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2070 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2071 | if (params->use_cts_prot >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 2072 | sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot; |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2073 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
| 2074 | } |
| 2075 | if (params->use_short_preamble >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 2076 | sdata->vif.bss_conf.use_short_preamble = |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2077 | params->use_short_preamble; |
| 2078 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
| 2079 | } |
Felix Fietkau | 43d3534 | 2010-01-15 03:00:48 +0100 | [diff] [blame] | 2080 | |
| 2081 | if (!sdata->vif.bss_conf.use_short_slot && |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2082 | sband->band == NL80211_BAND_5GHZ) { |
Felix Fietkau | 43d3534 | 2010-01-15 03:00:48 +0100 | [diff] [blame] | 2083 | sdata->vif.bss_conf.use_short_slot = true; |
| 2084 | changed |= BSS_CHANGED_ERP_SLOT; |
| 2085 | } |
| 2086 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2087 | if (params->use_short_slot_time >= 0) { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 2088 | sdata->vif.bss_conf.use_short_slot = |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2089 | params->use_short_slot_time; |
| 2090 | changed |= BSS_CHANGED_ERP_SLOT; |
| 2091 | } |
| 2092 | |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2093 | if (params->basic_rates) { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 2094 | ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef, |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 2095 | wiphy->bands[sband->band], |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 2096 | params->basic_rates, |
| 2097 | params->basic_rates_len, |
| 2098 | &sdata->vif.bss_conf.basic_rates); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2099 | changed |= BSS_CHANGED_BASIC_RATES; |
Johannes Berg | e8e4f52 | 2017-03-08 11:12:10 +0100 | [diff] [blame] | 2100 | ieee80211_check_rate_mask(sdata); |
Jouni Malinen | 90c97a0 | 2008-10-30 16:59:22 +0200 | [diff] [blame] | 2101 | } |
| 2102 | |
Felix Fietkau | 7b7b5e5 | 2010-04-27 01:23:36 +0200 | [diff] [blame] | 2103 | if (params->ap_isolate >= 0) { |
| 2104 | if (params->ap_isolate) |
| 2105 | sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS; |
| 2106 | else |
| 2107 | sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS; |
Johannes Berg | 49ddf8e | 2016-03-31 20:02:10 +0300 | [diff] [blame] | 2108 | ieee80211_check_fast_rx_iface(sdata); |
Felix Fietkau | 7b7b5e5 | 2010-04-27 01:23:36 +0200 | [diff] [blame] | 2109 | } |
| 2110 | |
Helmut Schaa | 80d7e40 | 2010-11-19 12:40:26 +0100 | [diff] [blame] | 2111 | if (params->ht_opmode >= 0) { |
| 2112 | sdata->vif.bss_conf.ht_operation_mode = |
| 2113 | (u16) params->ht_opmode; |
| 2114 | changed |= BSS_CHANGED_HT; |
| 2115 | } |
| 2116 | |
Johannes Berg | 339afbf | 2012-11-14 15:21:17 +0100 | [diff] [blame] | 2117 | if (params->p2p_ctwindow >= 0) { |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2118 | sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &= |
| 2119 | ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK; |
| 2120 | sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |= |
| 2121 | params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK; |
Johannes Berg | 339afbf | 2012-11-14 15:21:17 +0100 | [diff] [blame] | 2122 | changed |= BSS_CHANGED_P2P_PS; |
| 2123 | } |
| 2124 | |
Janusz Dziedzic | 67baf66 | 2013-03-21 15:47:56 +0100 | [diff] [blame] | 2125 | if (params->p2p_opp_ps > 0) { |
| 2126 | sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |= |
| 2127 | IEEE80211_P2P_OPPPS_ENABLE_BIT; |
| 2128 | changed |= BSS_CHANGED_P2P_PS; |
| 2129 | } else if (params->p2p_opp_ps == 0) { |
| 2130 | sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &= |
| 2131 | ~IEEE80211_P2P_OPPPS_ENABLE_BIT; |
Johannes Berg | 339afbf | 2012-11-14 15:21:17 +0100 | [diff] [blame] | 2132 | changed |= BSS_CHANGED_P2P_PS; |
| 2133 | } |
| 2134 | |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 2135 | ieee80211_bss_info_change_notify(sdata, changed); |
| 2136 | |
| 2137 | return 0; |
| 2138 | } |
| 2139 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2140 | static int ieee80211_set_txq_params(struct wiphy *wiphy, |
Eliad Peller | f70f01c | 2011-09-25 20:06:53 +0300 | [diff] [blame] | 2141 | struct net_device *dev, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2142 | struct ieee80211_txq_params *params) |
| 2143 | { |
| 2144 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Eliad Peller | f6f3def | 2011-09-25 20:06:54 +0300 | [diff] [blame] | 2145 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2146 | struct ieee80211_tx_queue_params p; |
| 2147 | |
| 2148 | if (!local->ops->conf_tx) |
| 2149 | return -EOPNOTSUPP; |
| 2150 | |
Johannes Berg | 54bcbc6 | 2012-03-28 11:04:25 +0200 | [diff] [blame] | 2151 | if (local->hw.queues < IEEE80211_NUM_ACS) |
| 2152 | return -EOPNOTSUPP; |
| 2153 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2154 | memset(&p, 0, sizeof(p)); |
| 2155 | p.aifs = params->aifs; |
| 2156 | p.cw_max = params->cwmax; |
| 2157 | p.cw_min = params->cwmin; |
| 2158 | p.txop = params->txop; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2159 | |
| 2160 | /* |
| 2161 | * Setting tx queue params disables u-apsd because it's only |
| 2162 | * called in master mode. |
| 2163 | */ |
| 2164 | p.uapsd = false; |
| 2165 | |
Haim Dreyfuss | e552af0 | 2018-03-28 13:24:10 +0300 | [diff] [blame] | 2166 | ieee80211_regulatory_limit_wmm_params(sdata, &p, params->ac); |
| 2167 | |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2168 | sdata->tx_conf[params->ac] = p; |
| 2169 | if (drv_conf_tx(local, sdata, params->ac, &p)) { |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 2170 | wiphy_debug(local->hw.wiphy, |
Johannes Berg | a3304b0 | 2012-03-28 11:04:24 +0200 | [diff] [blame] | 2171 | "failed to set TX queue parameters for AC %d\n", |
| 2172 | params->ac); |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2173 | return -EINVAL; |
| 2174 | } |
| 2175 | |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2176 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS); |
| 2177 | |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 2178 | return 0; |
| 2179 | } |
| 2180 | |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 2181 | #ifdef CONFIG_PM |
Johannes Berg | ff1b6e6 | 2011-05-04 15:37:28 +0200 | [diff] [blame] | 2182 | static int ieee80211_suspend(struct wiphy *wiphy, |
| 2183 | struct cfg80211_wowlan *wowlan) |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 2184 | { |
Johannes Berg | eecc480 | 2011-05-04 15:37:29 +0200 | [diff] [blame] | 2185 | return __ieee80211_suspend(wiphy_priv(wiphy), wowlan); |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 2186 | } |
| 2187 | |
| 2188 | static int ieee80211_resume(struct wiphy *wiphy) |
| 2189 | { |
| 2190 | return __ieee80211_resume(wiphy_priv(wiphy)); |
| 2191 | } |
| 2192 | #else |
| 2193 | #define ieee80211_suspend NULL |
| 2194 | #define ieee80211_resume NULL |
| 2195 | #endif |
| 2196 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2197 | static int ieee80211_scan(struct wiphy *wiphy, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2198 | struct cfg80211_scan_request *req) |
| 2199 | { |
Johannes Berg | fd01428 | 2012-06-18 19:17:03 +0200 | [diff] [blame] | 2200 | struct ieee80211_sub_if_data *sdata; |
| 2201 | |
| 2202 | sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev); |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2203 | |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 2204 | switch (ieee80211_vif_type_p2p(&sdata->vif)) { |
| 2205 | case NL80211_IFTYPE_STATION: |
| 2206 | case NL80211_IFTYPE_ADHOC: |
| 2207 | case NL80211_IFTYPE_MESH_POINT: |
| 2208 | case NL80211_IFTYPE_P2P_CLIENT: |
Johannes Berg | f142c6b | 2012-06-18 20:07:15 +0200 | [diff] [blame] | 2209 | case NL80211_IFTYPE_P2P_DEVICE: |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 2210 | break; |
| 2211 | case NL80211_IFTYPE_P2P_GO: |
| 2212 | if (sdata->local->ops->hw_scan) |
| 2213 | break; |
Johannes Berg | e9d7732 | 2011-02-01 15:35:36 +0100 | [diff] [blame] | 2214 | /* |
| 2215 | * FIXME: implement NoA while scanning in software, |
| 2216 | * for now fall through to allow scanning only when |
| 2217 | * beaconing hasn't been configured yet |
| 2218 | */ |
Gustavo A. R. Silva | 02049ce | 2017-10-17 18:14:50 -0500 | [diff] [blame] | 2219 | /* fall through */ |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 2220 | case NL80211_IFTYPE_AP: |
Antonio Quartulli | 5c95b94 | 2012-10-16 08:39:22 +0200 | [diff] [blame] | 2221 | /* |
| 2222 | * If the scan has been forced (and the driver supports |
| 2223 | * forcing), don't care about being beaconing already. |
| 2224 | * This will create problems to the attached stations (e.g. all |
| 2225 | * the frames sent while scanning on other channel will be |
| 2226 | * lost) |
| 2227 | */ |
| 2228 | if (sdata->u.ap.beacon && |
| 2229 | (!(wiphy->features & NL80211_FEATURE_AP_SCAN) || |
| 2230 | !(req->flags & NL80211_SCAN_FLAG_AP))) |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 2231 | return -EOPNOTSUPP; |
| 2232 | break; |
Ayala Beker | cb3b7d8 | 2016-09-20 17:31:13 +0300 | [diff] [blame] | 2233 | case NL80211_IFTYPE_NAN: |
Johannes Berg | 2ca27bc | 2010-09-16 14:58:23 +0200 | [diff] [blame] | 2234 | default: |
| 2235 | return -EOPNOTSUPP; |
| 2236 | } |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2237 | |
| 2238 | return ieee80211_request_scan(sdata, req); |
| 2239 | } |
| 2240 | |
Vidyullatha Kanchanapally | 91f123f | 2015-10-30 19:14:50 +0530 | [diff] [blame] | 2241 | static void ieee80211_abort_scan(struct wiphy *wiphy, struct wireless_dev *wdev) |
| 2242 | { |
| 2243 | ieee80211_scan_cancel(wiphy_priv(wiphy)); |
| 2244 | } |
| 2245 | |
Luciano Coelho | 79f460c | 2011-05-11 17:09:36 +0300 | [diff] [blame] | 2246 | static int |
| 2247 | ieee80211_sched_scan_start(struct wiphy *wiphy, |
| 2248 | struct net_device *dev, |
| 2249 | struct cfg80211_sched_scan_request *req) |
| 2250 | { |
| 2251 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2252 | |
| 2253 | if (!sdata->local->ops->sched_scan_start) |
| 2254 | return -EOPNOTSUPP; |
| 2255 | |
| 2256 | return ieee80211_request_sched_scan_start(sdata, req); |
| 2257 | } |
| 2258 | |
| 2259 | static int |
Arend Van Spriel | 3a3ecf1 | 2017-04-21 13:05:02 +0100 | [diff] [blame] | 2260 | ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev, |
| 2261 | u64 reqid) |
Luciano Coelho | 79f460c | 2011-05-11 17:09:36 +0300 | [diff] [blame] | 2262 | { |
Eliad Peller | 0d440ea | 2015-10-25 10:59:33 +0200 | [diff] [blame] | 2263 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Luciano Coelho | 79f460c | 2011-05-11 17:09:36 +0300 | [diff] [blame] | 2264 | |
Eliad Peller | 0d440ea | 2015-10-25 10:59:33 +0200 | [diff] [blame] | 2265 | if (!local->ops->sched_scan_stop) |
Luciano Coelho | 79f460c | 2011-05-11 17:09:36 +0300 | [diff] [blame] | 2266 | return -EOPNOTSUPP; |
| 2267 | |
Eliad Peller | 0d440ea | 2015-10-25 10:59:33 +0200 | [diff] [blame] | 2268 | return ieee80211_request_sched_scan_stop(local); |
Luciano Coelho | 79f460c | 2011-05-11 17:09:36 +0300 | [diff] [blame] | 2269 | } |
| 2270 | |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2271 | static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev, |
| 2272 | struct cfg80211_auth_request *req) |
| 2273 | { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2274 | return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev, |
| 2278 | struct cfg80211_assoc_request *req) |
| 2279 | { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2280 | return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 2284 | struct cfg80211_deauth_request *req) |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2285 | { |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 2286 | return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2287 | } |
| 2288 | |
| 2289 | static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 2290 | struct cfg80211_disassoc_request *req) |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2291 | { |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 2292 | return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req); |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 2293 | } |
| 2294 | |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 2295 | static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev, |
| 2296 | struct cfg80211_ibss_params *params) |
| 2297 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2298 | return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 2299 | } |
| 2300 | |
| 2301 | static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev) |
| 2302 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2303 | return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev)); |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 2304 | } |
| 2305 | |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 2306 | static int ieee80211_join_ocb(struct wiphy *wiphy, struct net_device *dev, |
| 2307 | struct ocb_setup *setup) |
| 2308 | { |
| 2309 | return ieee80211_ocb_join(IEEE80211_DEV_TO_SUB_IF(dev), setup); |
| 2310 | } |
| 2311 | |
| 2312 | static int ieee80211_leave_ocb(struct wiphy *wiphy, struct net_device *dev) |
| 2313 | { |
| 2314 | return ieee80211_ocb_leave(IEEE80211_DEV_TO_SUB_IF(dev)); |
| 2315 | } |
| 2316 | |
Antonio Quartulli | 391e53e | 2012-11-02 13:27:49 +0100 | [diff] [blame] | 2317 | static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2318 | int rate[NUM_NL80211_BANDS]) |
Antonio Quartulli | 391e53e | 2012-11-02 13:27:49 +0100 | [diff] [blame] | 2319 | { |
| 2320 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2321 | |
Cong Ding | 9887dbf | 2013-02-06 17:23:45 +0100 | [diff] [blame] | 2322 | memcpy(sdata->vif.bss_conf.mcast_rate, rate, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2323 | sizeof(int) * NUM_NL80211_BANDS); |
Antonio Quartulli | 391e53e | 2012-11-02 13:27:49 +0100 | [diff] [blame] | 2324 | |
Pradeep Kumar Chitrapu | dcbe73c | 2018-03-22 12:18:03 -0700 | [diff] [blame] | 2325 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_MCAST_RATE); |
| 2326 | |
Antonio Quartulli | 391e53e | 2012-11-02 13:27:49 +0100 | [diff] [blame] | 2327 | return 0; |
| 2328 | } |
| 2329 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2330 | static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed) |
| 2331 | { |
| 2332 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 2333 | int err; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2334 | |
Arik Nemtsov | f23a478 | 2010-11-08 11:51:06 +0200 | [diff] [blame] | 2335 | if (changed & WIPHY_PARAM_FRAG_THRESHOLD) { |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 2336 | ieee80211_check_fast_xmit_all(local); |
| 2337 | |
Arik Nemtsov | f23a478 | 2010-11-08 11:51:06 +0200 | [diff] [blame] | 2338 | err = drv_set_frag_threshold(local, wiphy->frag_threshold); |
| 2339 | |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 2340 | if (err) { |
| 2341 | ieee80211_check_fast_xmit_all(local); |
Arik Nemtsov | f23a478 | 2010-11-08 11:51:06 +0200 | [diff] [blame] | 2342 | return err; |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 2343 | } |
Arik Nemtsov | f23a478 | 2010-11-08 11:51:06 +0200 | [diff] [blame] | 2344 | } |
| 2345 | |
Lorenzo Bianconi | a4bcaf5 | 2014-09-04 23:57:41 +0200 | [diff] [blame] | 2346 | if ((changed & WIPHY_PARAM_COVERAGE_CLASS) || |
| 2347 | (changed & WIPHY_PARAM_DYN_ACK)) { |
| 2348 | s16 coverage_class; |
| 2349 | |
| 2350 | coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ? |
| 2351 | wiphy->coverage_class : -1; |
| 2352 | err = drv_set_coverage_class(local, coverage_class); |
Lukáš Turek | 310bc67 | 2009-12-21 22:50:48 +0100 | [diff] [blame] | 2353 | |
| 2354 | if (err) |
| 2355 | return err; |
| 2356 | } |
| 2357 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2358 | if (changed & WIPHY_PARAM_RTS_THRESHOLD) { |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 2359 | err = drv_set_rts_threshold(local, wiphy->rts_threshold); |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2360 | |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 2361 | if (err) |
| 2362 | return err; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2363 | } |
| 2364 | |
Johannes Berg | 8bc83c2 | 2012-11-09 18:38:32 +0100 | [diff] [blame] | 2365 | if (changed & WIPHY_PARAM_RETRY_SHORT) { |
| 2366 | if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY) |
| 2367 | return -EINVAL; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2368 | local->hw.conf.short_frame_max_tx_count = wiphy->retry_short; |
Johannes Berg | 8bc83c2 | 2012-11-09 18:38:32 +0100 | [diff] [blame] | 2369 | } |
| 2370 | if (changed & WIPHY_PARAM_RETRY_LONG) { |
| 2371 | if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY) |
| 2372 | return -EINVAL; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2373 | local->hw.conf.long_frame_max_tx_count = wiphy->retry_long; |
Johannes Berg | 8bc83c2 | 2012-11-09 18:38:32 +0100 | [diff] [blame] | 2374 | } |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2375 | if (changed & |
| 2376 | (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG)) |
| 2377 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS); |
| 2378 | |
Toke Høiland-Jørgensen | 2fe4a29 | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 2379 | if (changed & (WIPHY_PARAM_TXQ_LIMIT | |
| 2380 | WIPHY_PARAM_TXQ_MEMORY_LIMIT | |
| 2381 | WIPHY_PARAM_TXQ_QUANTUM)) |
| 2382 | ieee80211_txq_set_params(local); |
| 2383 | |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 2384 | return 0; |
| 2385 | } |
| 2386 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2387 | static int ieee80211_set_tx_power(struct wiphy *wiphy, |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2388 | struct wireless_dev *wdev, |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 2389 | enum nl80211_tx_power_setting type, int mbm) |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2390 | { |
| 2391 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2392 | struct ieee80211_sub_if_data *sdata; |
Lorenzo Bianconi | db82d8a | 2015-01-14 12:55:08 +0100 | [diff] [blame] | 2393 | enum nl80211_tx_power_setting txp_type = type; |
| 2394 | bool update_txp_type = false; |
Peter Große | 3a3713e | 2017-12-13 18:29:46 +0100 | [diff] [blame] | 2395 | bool has_monitor = false; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2396 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2397 | if (wdev) { |
| 2398 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 2399 | |
Peter Große | 3a3713e | 2017-12-13 18:29:46 +0100 | [diff] [blame] | 2400 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { |
| 2401 | sdata = rtnl_dereference(local->monitor_sdata); |
| 2402 | if (!sdata) |
| 2403 | return -EOPNOTSUPP; |
| 2404 | } |
| 2405 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2406 | switch (type) { |
| 2407 | case NL80211_TX_POWER_AUTOMATIC: |
| 2408 | sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL; |
Lorenzo Bianconi | db82d8a | 2015-01-14 12:55:08 +0100 | [diff] [blame] | 2409 | txp_type = NL80211_TX_POWER_LIMITED; |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2410 | break; |
| 2411 | case NL80211_TX_POWER_LIMITED: |
| 2412 | case NL80211_TX_POWER_FIXED: |
| 2413 | if (mbm < 0 || (mbm % 100)) |
| 2414 | return -EOPNOTSUPP; |
| 2415 | sdata->user_power_level = MBM_TO_DBM(mbm); |
| 2416 | break; |
| 2417 | } |
| 2418 | |
Lorenzo Bianconi | db82d8a | 2015-01-14 12:55:08 +0100 | [diff] [blame] | 2419 | if (txp_type != sdata->vif.bss_conf.txpower_type) { |
| 2420 | update_txp_type = true; |
| 2421 | sdata->vif.bss_conf.txpower_type = txp_type; |
| 2422 | } |
| 2423 | |
| 2424 | ieee80211_recalc_txpower(sdata, update_txp_type); |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2425 | |
| 2426 | return 0; |
| 2427 | } |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2428 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2429 | switch (type) { |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 2430 | case NL80211_TX_POWER_AUTOMATIC: |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2431 | local->user_power_level = IEEE80211_UNSET_POWER_LEVEL; |
Lorenzo Bianconi | db82d8a | 2015-01-14 12:55:08 +0100 | [diff] [blame] | 2432 | txp_type = NL80211_TX_POWER_LIMITED; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2433 | break; |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 2434 | case NL80211_TX_POWER_LIMITED: |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 2435 | case NL80211_TX_POWER_FIXED: |
| 2436 | if (mbm < 0 || (mbm % 100)) |
| 2437 | return -EOPNOTSUPP; |
Juuso Oikarinen | fa61cf7 | 2010-06-23 12:12:37 +0300 | [diff] [blame] | 2438 | local->user_power_level = MBM_TO_DBM(mbm); |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2439 | break; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2440 | } |
| 2441 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2442 | mutex_lock(&local->iflist_mtx); |
Lorenzo Bianconi | db82d8a | 2015-01-14 12:55:08 +0100 | [diff] [blame] | 2443 | list_for_each_entry(sdata, &local->interfaces, list) { |
Peter Große | 3a3713e | 2017-12-13 18:29:46 +0100 | [diff] [blame] | 2444 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) { |
| 2445 | has_monitor = true; |
| 2446 | continue; |
| 2447 | } |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2448 | sdata->user_power_level = local->user_power_level; |
Lorenzo Bianconi | db82d8a | 2015-01-14 12:55:08 +0100 | [diff] [blame] | 2449 | if (txp_type != sdata->vif.bss_conf.txpower_type) |
| 2450 | update_txp_type = true; |
| 2451 | sdata->vif.bss_conf.txpower_type = txp_type; |
| 2452 | } |
Peter Große | 3a3713e | 2017-12-13 18:29:46 +0100 | [diff] [blame] | 2453 | list_for_each_entry(sdata, &local->interfaces, list) { |
| 2454 | if (sdata->vif.type == NL80211_IFTYPE_MONITOR) |
| 2455 | continue; |
Lorenzo Bianconi | db82d8a | 2015-01-14 12:55:08 +0100 | [diff] [blame] | 2456 | ieee80211_recalc_txpower(sdata, update_txp_type); |
Peter Große | 3a3713e | 2017-12-13 18:29:46 +0100 | [diff] [blame] | 2457 | } |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2458 | mutex_unlock(&local->iflist_mtx); |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2459 | |
Peter Große | 3a3713e | 2017-12-13 18:29:46 +0100 | [diff] [blame] | 2460 | if (has_monitor) { |
| 2461 | sdata = rtnl_dereference(local->monitor_sdata); |
| 2462 | if (sdata) { |
| 2463 | sdata->user_power_level = local->user_power_level; |
| 2464 | if (txp_type != sdata->vif.bss_conf.txpower_type) |
| 2465 | update_txp_type = true; |
| 2466 | sdata->vif.bss_conf.txpower_type = txp_type; |
| 2467 | |
| 2468 | ieee80211_recalc_txpower(sdata, update_txp_type); |
| 2469 | } |
| 2470 | } |
| 2471 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2472 | return 0; |
| 2473 | } |
| 2474 | |
Johannes Berg | c844211 | 2012-10-24 10:17:18 +0200 | [diff] [blame] | 2475 | static int ieee80211_get_tx_power(struct wiphy *wiphy, |
| 2476 | struct wireless_dev *wdev, |
| 2477 | int *dbm) |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2478 | { |
| 2479 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2480 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2481 | |
Felix Fietkau | 5b3dc42 | 2014-10-26 00:32:53 +0200 | [diff] [blame] | 2482 | if (local->ops->get_txpower) |
| 2483 | return drv_get_txpower(local, sdata, dbm); |
| 2484 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2485 | if (!local->use_chanctx) |
| 2486 | *dbm = local->hw.conf.power_level; |
| 2487 | else |
| 2488 | *dbm = sdata->vif.bss_conf.txpower; |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2489 | |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 2490 | return 0; |
| 2491 | } |
| 2492 | |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 2493 | static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev, |
Johannes Berg | 388ac77 | 2010-10-07 13:11:09 +0200 | [diff] [blame] | 2494 | const u8 *addr) |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 2495 | { |
| 2496 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2497 | |
| 2498 | memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN); |
| 2499 | |
| 2500 | return 0; |
| 2501 | } |
| 2502 | |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 2503 | static void ieee80211_rfkill_poll(struct wiphy *wiphy) |
| 2504 | { |
| 2505 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 2506 | |
| 2507 | drv_rfkill_poll(local); |
| 2508 | } |
| 2509 | |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 2510 | #ifdef CONFIG_NL80211_TESTMODE |
David Spinadel | fc73f11 | 2013-07-31 18:04:15 +0300 | [diff] [blame] | 2511 | static int ieee80211_testmode_cmd(struct wiphy *wiphy, |
| 2512 | struct wireless_dev *wdev, |
| 2513 | void *data, int len) |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 2514 | { |
| 2515 | struct ieee80211_local *local = wiphy_priv(wiphy); |
David Spinadel | 52981cd | 2013-07-31 18:06:22 +0300 | [diff] [blame] | 2516 | struct ieee80211_vif *vif = NULL; |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 2517 | |
| 2518 | if (!local->ops->testmode_cmd) |
| 2519 | return -EOPNOTSUPP; |
| 2520 | |
David Spinadel | 52981cd | 2013-07-31 18:06:22 +0300 | [diff] [blame] | 2521 | if (wdev) { |
| 2522 | struct ieee80211_sub_if_data *sdata; |
| 2523 | |
| 2524 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 2525 | if (sdata->flags & IEEE80211_SDATA_IN_DRIVER) |
| 2526 | vif = &sdata->vif; |
| 2527 | } |
| 2528 | |
| 2529 | return local->ops->testmode_cmd(&local->hw, vif, data, len); |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 2530 | } |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 2531 | |
| 2532 | static int ieee80211_testmode_dump(struct wiphy *wiphy, |
| 2533 | struct sk_buff *skb, |
| 2534 | struct netlink_callback *cb, |
| 2535 | void *data, int len) |
| 2536 | { |
| 2537 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 2538 | |
| 2539 | if (!local->ops->testmode_dump) |
| 2540 | return -EOPNOTSUPP; |
| 2541 | |
| 2542 | return local->ops->testmode_dump(&local->hw, skb, cb, data, len); |
| 2543 | } |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 2544 | #endif |
| 2545 | |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 2546 | int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata, |
| 2547 | enum ieee80211_smps_mode smps_mode) |
| 2548 | { |
| 2549 | struct sta_info *sta; |
| 2550 | enum ieee80211_smps_mode old_req; |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 2551 | |
| 2552 | if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP)) |
| 2553 | return -EINVAL; |
| 2554 | |
| 2555 | if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT) |
| 2556 | return 0; |
| 2557 | |
| 2558 | old_req = sdata->u.ap.req_smps; |
| 2559 | sdata->u.ap.req_smps = smps_mode; |
| 2560 | |
| 2561 | /* AUTOMATIC doesn't mean much for AP - don't allow it */ |
| 2562 | if (old_req == smps_mode || |
| 2563 | smps_mode == IEEE80211_SMPS_AUTOMATIC) |
| 2564 | return 0; |
| 2565 | |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 2566 | ht_dbg(sdata, |
Michael Braun | 6a8b4ad | 2015-03-18 07:17:37 +0100 | [diff] [blame] | 2567 | "SMPS %d requested in AP mode, sending Action frame to %d stations\n", |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 2568 | smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta)); |
| 2569 | |
| 2570 | mutex_lock(&sdata->local->sta_mtx); |
Johannes Berg | 7d9bb2f | 2015-02-13 21:31:07 +0100 | [diff] [blame] | 2571 | list_for_each_entry(sta, &sdata->local->sta_list, list) { |
| 2572 | /* |
| 2573 | * Only stations associated to our AP and |
| 2574 | * associated VLANs |
| 2575 | */ |
| 2576 | if (sta->sdata->bss != &sdata->u.ap) |
| 2577 | continue; |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 2578 | |
Johannes Berg | 7d9bb2f | 2015-02-13 21:31:07 +0100 | [diff] [blame] | 2579 | /* This station doesn't support MIMO - skip it */ |
| 2580 | if (sta_info_tx_streams(sta) == 1) |
| 2581 | continue; |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 2582 | |
Johannes Berg | 7d9bb2f | 2015-02-13 21:31:07 +0100 | [diff] [blame] | 2583 | /* |
| 2584 | * Don't wake up a STA just to send the action frame |
| 2585 | * unless we are getting more restrictive. |
| 2586 | */ |
| 2587 | if (test_sta_flag(sta, WLAN_STA_PS_STA) && |
| 2588 | !ieee80211_smps_is_restrictive(sta->known_smps_mode, |
| 2589 | smps_mode)) { |
| 2590 | ht_dbg(sdata, "Won't send SMPS to sleeping STA %pM\n", |
| 2591 | sta->sta.addr); |
| 2592 | continue; |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 2593 | } |
Johannes Berg | 7d9bb2f | 2015-02-13 21:31:07 +0100 | [diff] [blame] | 2594 | |
| 2595 | /* |
| 2596 | * If the STA is not authorized, wait until it gets |
| 2597 | * authorized and the action frame will be sent then. |
| 2598 | */ |
| 2599 | if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED)) |
| 2600 | continue; |
| 2601 | |
| 2602 | ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr); |
| 2603 | ieee80211_send_smps_action(sdata, smps_mode, sta->sta.addr, |
| 2604 | sdata->vif.bss_conf.bssid); |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 2605 | } |
| 2606 | mutex_unlock(&sdata->local->sta_mtx); |
| 2607 | |
| 2608 | sdata->smps_mode = smps_mode; |
| 2609 | ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps); |
| 2610 | |
| 2611 | return 0; |
| 2612 | } |
| 2613 | |
| 2614 | int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata, |
| 2615 | enum ieee80211_smps_mode smps_mode) |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2616 | { |
| 2617 | const u8 *ap; |
| 2618 | enum ieee80211_smps_mode old_req; |
| 2619 | int err; |
Arik Nemtsov | d51c2ea | 2015-06-14 16:53:46 +0300 | [diff] [blame] | 2620 | struct sta_info *sta; |
| 2621 | bool tdls_peer_found = false; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2622 | |
Johannes Berg | 8d61ffa | 2013-05-10 12:32:47 +0200 | [diff] [blame] | 2623 | lockdep_assert_held(&sdata->wdev.mtx); |
Johannes Berg | 243e6df | 2011-04-19 20:44:04 +0200 | [diff] [blame] | 2624 | |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 2625 | if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 2626 | return -EINVAL; |
| 2627 | |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2628 | old_req = sdata->u.mgd.req_smps; |
| 2629 | sdata->u.mgd.req_smps = smps_mode; |
| 2630 | |
| 2631 | if (old_req == smps_mode && |
| 2632 | smps_mode != IEEE80211_SMPS_AUTOMATIC) |
| 2633 | return 0; |
| 2634 | |
| 2635 | /* |
| 2636 | * If not associated, or current association is not an HT |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 2637 | * association, there's no need to do anything, just store |
| 2638 | * the new value until we associate. |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2639 | */ |
| 2640 | if (!sdata->u.mgd.associated || |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 2641 | sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT) |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2642 | return 0; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2643 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2644 | ap = sdata->u.mgd.associated->bssid; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2645 | |
Arik Nemtsov | d51c2ea | 2015-06-14 16:53:46 +0300 | [diff] [blame] | 2646 | rcu_read_lock(); |
| 2647 | list_for_each_entry_rcu(sta, &sdata->local->sta_list, list) { |
| 2648 | if (!sta->sta.tdls || sta->sdata != sdata || !sta->uploaded || |
| 2649 | !test_sta_flag(sta, WLAN_STA_AUTHORIZED)) |
| 2650 | continue; |
| 2651 | |
| 2652 | tdls_peer_found = true; |
| 2653 | break; |
| 2654 | } |
| 2655 | rcu_read_unlock(); |
| 2656 | |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2657 | if (smps_mode == IEEE80211_SMPS_AUTOMATIC) { |
Arik Nemtsov | d51c2ea | 2015-06-14 16:53:46 +0300 | [diff] [blame] | 2658 | if (tdls_peer_found || !sdata->u.mgd.powersave) |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2659 | smps_mode = IEEE80211_SMPS_OFF; |
Arik Nemtsov | d51c2ea | 2015-06-14 16:53:46 +0300 | [diff] [blame] | 2660 | else |
| 2661 | smps_mode = IEEE80211_SMPS_DYNAMIC; |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | /* send SM PS frame to AP */ |
| 2665 | err = ieee80211_send_smps_action(sdata, smps_mode, |
| 2666 | ap, ap); |
| 2667 | if (err) |
| 2668 | sdata->u.mgd.req_smps = old_req; |
Arik Nemtsov | d51c2ea | 2015-06-14 16:53:46 +0300 | [diff] [blame] | 2669 | else if (smps_mode != IEEE80211_SMPS_OFF && tdls_peer_found) |
| 2670 | ieee80211_teardown_tdls_peers(sdata); |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2671 | |
| 2672 | return err; |
| 2673 | } |
| 2674 | |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 2675 | static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev, |
| 2676 | bool enabled, int timeout) |
| 2677 | { |
| 2678 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2679 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 2680 | |
Bob Copeland | 2d3db21 | 2013-10-29 18:11:59 -0400 | [diff] [blame] | 2681 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Benoit Papillault | e5de30c | 2010-01-15 12:21:37 +0100 | [diff] [blame] | 2682 | return -EOPNOTSUPP; |
| 2683 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2684 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 2685 | return -EOPNOTSUPP; |
| 2686 | |
| 2687 | if (enabled == sdata->u.mgd.powersave && |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 2688 | timeout == local->dynamic_ps_forced_timeout) |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 2689 | return 0; |
| 2690 | |
| 2691 | sdata->u.mgd.powersave = enabled; |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 2692 | local->dynamic_ps_forced_timeout = timeout; |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 2693 | |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2694 | /* no change, but if automatic follow powersave */ |
Johannes Berg | ed405be | 2013-06-03 13:51:59 +0200 | [diff] [blame] | 2695 | sdata_lock(sdata); |
Emmanuel Grumbach | 687da13 | 2013-10-01 16:45:43 +0300 | [diff] [blame] | 2696 | __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps); |
Johannes Berg | ed405be | 2013-06-03 13:51:59 +0200 | [diff] [blame] | 2697 | sdata_unlock(sdata); |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2698 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2699 | if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 2700 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 2701 | |
Johannes Berg | 4a733ef | 2015-10-14 18:02:43 +0200 | [diff] [blame] | 2702 | ieee80211_recalc_ps(local); |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 2703 | ieee80211_recalc_ps_vif(sdata); |
Felix Fietkau | 1d87016 | 2018-02-23 10:06:05 +0100 | [diff] [blame] | 2704 | ieee80211_check_fast_rx_iface(sdata); |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 2705 | |
| 2706 | return 0; |
| 2707 | } |
| 2708 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2709 | static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy, |
| 2710 | struct net_device *dev, |
| 2711 | s32 rssi_thold, u32 rssi_hyst) |
| 2712 | { |
| 2713 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2714 | struct ieee80211_vif *vif = &sdata->vif; |
| 2715 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
| 2716 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2717 | if (rssi_thold == bss_conf->cqm_rssi_thold && |
| 2718 | rssi_hyst == bss_conf->cqm_rssi_hyst) |
| 2719 | return 0; |
| 2720 | |
Johannes Berg | ef9be10 | 2015-08-28 10:44:20 +0200 | [diff] [blame] | 2721 | if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER && |
| 2722 | !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) |
| 2723 | return -EOPNOTSUPP; |
| 2724 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2725 | bss_conf->cqm_rssi_thold = rssi_thold; |
| 2726 | bss_conf->cqm_rssi_hyst = rssi_hyst; |
Andrew Zaborowski | 2c3c5f8c | 2017-02-10 04:50:22 +0100 | [diff] [blame] | 2727 | bss_conf->cqm_rssi_low = 0; |
| 2728 | bss_conf->cqm_rssi_high = 0; |
| 2729 | sdata->u.mgd.last_cqm_event_signal = 0; |
| 2730 | |
| 2731 | /* tell the driver upon association, unless already associated */ |
| 2732 | if (sdata->u.mgd.associated && |
| 2733 | sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI) |
| 2734 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM); |
| 2735 | |
| 2736 | return 0; |
| 2737 | } |
| 2738 | |
| 2739 | static int ieee80211_set_cqm_rssi_range_config(struct wiphy *wiphy, |
| 2740 | struct net_device *dev, |
| 2741 | s32 rssi_low, s32 rssi_high) |
| 2742 | { |
| 2743 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2744 | struct ieee80211_vif *vif = &sdata->vif; |
| 2745 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
| 2746 | |
| 2747 | if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER) |
| 2748 | return -EOPNOTSUPP; |
| 2749 | |
| 2750 | bss_conf->cqm_rssi_low = rssi_low; |
| 2751 | bss_conf->cqm_rssi_high = rssi_high; |
| 2752 | bss_conf->cqm_rssi_thold = 0; |
| 2753 | bss_conf->cqm_rssi_hyst = 0; |
Sara Sharon | babc305e2 | 2015-09-21 15:47:40 +0300 | [diff] [blame] | 2754 | sdata->u.mgd.last_cqm_event_signal = 0; |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2755 | |
| 2756 | /* tell the driver upon association, unless already associated */ |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 2757 | if (sdata->u.mgd.associated && |
| 2758 | sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI) |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2759 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM); |
| 2760 | |
| 2761 | return 0; |
| 2762 | } |
| 2763 | |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 2764 | static int ieee80211_set_bitrate_mask(struct wiphy *wiphy, |
| 2765 | struct net_device *dev, |
| 2766 | const u8 *addr, |
| 2767 | const struct cfg80211_bitrate_mask *mask) |
| 2768 | { |
| 2769 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2770 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Sujith Manoharan | bdbfd6b | 2011-04-27 16:56:51 +0530 | [diff] [blame] | 2771 | int i, ret; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 2772 | |
Eliad Peller | 554a43d | 2012-06-12 12:41:15 +0300 | [diff] [blame] | 2773 | if (!ieee80211_sdata_running(sdata)) |
| 2774 | return -ENETDOWN; |
| 2775 | |
Johannes Berg | e8e4f52 | 2017-03-08 11:12:10 +0100 | [diff] [blame] | 2776 | /* |
| 2777 | * If active validate the setting and reject it if it doesn't leave |
| 2778 | * at least one basic rate usable, since we really have to be able |
| 2779 | * to send something, and if we're an AP we have to be able to do |
| 2780 | * so at a basic rate so that all clients can receive it. |
| 2781 | */ |
| 2782 | if (rcu_access_pointer(sdata->vif.chanctx_conf) && |
| 2783 | sdata->vif.bss_conf.chandef.chan) { |
| 2784 | u32 basic_rates = sdata->vif.bss_conf.basic_rates; |
| 2785 | enum nl80211_band band = sdata->vif.bss_conf.chandef.chan->band; |
| 2786 | |
| 2787 | if (!(mask->control[band].legacy & basic_rates)) |
| 2788 | return -EINVAL; |
| 2789 | } |
| 2790 | |
Johannes Berg | e5f5ce3 | 2017-10-18 09:36:51 +0200 | [diff] [blame] | 2791 | if (ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) { |
| 2792 | ret = drv_set_bitrate_mask(local, sdata, mask); |
| 2793 | if (ret) |
| 2794 | return ret; |
| 2795 | } |
| 2796 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2797 | for (i = 0; i < NUM_NL80211_BANDS; i++) { |
Felix Fietkau | 2ffbe6d | 2013-04-16 13:38:42 +0200 | [diff] [blame] | 2798 | struct ieee80211_supported_band *sband = wiphy->bands[i]; |
| 2799 | int j; |
| 2800 | |
Jouni Malinen | 37eb0b1 | 2010-01-06 13:09:08 +0200 | [diff] [blame] | 2801 | sdata->rc_rateidx_mask[i] = mask->control[i].legacy; |
Janusz Dziedzic | d1e33e6 | 2013-12-05 10:02:15 +0100 | [diff] [blame] | 2802 | memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs, |
| 2803 | sizeof(mask->control[i].ht_mcs)); |
Lorenzo Bianconi | b119ad6 | 2015-08-06 23:47:33 +0200 | [diff] [blame] | 2804 | memcpy(sdata->rc_rateidx_vht_mcs_mask[i], |
| 2805 | mask->control[i].vht_mcs, |
| 2806 | sizeof(mask->control[i].vht_mcs)); |
Felix Fietkau | 2ffbe6d | 2013-04-16 13:38:42 +0200 | [diff] [blame] | 2807 | |
| 2808 | sdata->rc_has_mcs_mask[i] = false; |
Lorenzo Bianconi | b119ad6 | 2015-08-06 23:47:33 +0200 | [diff] [blame] | 2809 | sdata->rc_has_vht_mcs_mask[i] = false; |
Felix Fietkau | 2ffbe6d | 2013-04-16 13:38:42 +0200 | [diff] [blame] | 2810 | if (!sband) |
| 2811 | continue; |
| 2812 | |
Lorenzo Bianconi | b119ad6 | 2015-08-06 23:47:33 +0200 | [diff] [blame] | 2813 | for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++) { |
Johannes Berg | 2df1b13 | 2015-08-21 14:07:13 +0200 | [diff] [blame] | 2814 | if (~sdata->rc_rateidx_mcs_mask[i][j]) { |
Felix Fietkau | 2ffbe6d | 2013-04-16 13:38:42 +0200 | [diff] [blame] | 2815 | sdata->rc_has_mcs_mask[i] = true; |
| 2816 | break; |
Johannes Berg | 2df1b13 | 2015-08-21 14:07:13 +0200 | [diff] [blame] | 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | for (j = 0; j < NL80211_VHT_NSS_MAX; j++) { |
| 2821 | if (~sdata->rc_rateidx_vht_mcs_mask[i][j]) { |
| 2822 | sdata->rc_has_vht_mcs_mask[i] = true; |
| 2823 | break; |
| 2824 | } |
Lorenzo Bianconi | b119ad6 | 2015-08-06 23:47:33 +0200 | [diff] [blame] | 2825 | } |
Simon Wunderlich | 1946841 | 2012-01-28 17:25:33 +0100 | [diff] [blame] | 2826 | } |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 2827 | |
Jouni Malinen | 37eb0b1 | 2010-01-06 13:09:08 +0200 | [diff] [blame] | 2828 | return 0; |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 2829 | } |
| 2830 | |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 2831 | static int ieee80211_start_radar_detection(struct wiphy *wiphy, |
| 2832 | struct net_device *dev, |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 2833 | struct cfg80211_chan_def *chandef, |
| 2834 | u32 cac_time_ms) |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 2835 | { |
| 2836 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2837 | struct ieee80211_local *local = sdata->local; |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 2838 | int err; |
| 2839 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2840 | mutex_lock(&local->mtx); |
| 2841 | if (!list_empty(&local->roc_list) || local->scanning) { |
| 2842 | err = -EBUSY; |
| 2843 | goto out_unlock; |
| 2844 | } |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 2845 | |
| 2846 | /* whatever, but channel contexts should not complain about that one */ |
| 2847 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
| 2848 | sdata->needed_rx_chains = local->rx_chains; |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 2849 | |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 2850 | err = ieee80211_vif_use_channel(sdata, chandef, |
| 2851 | IEEE80211_CHANCTX_SHARED); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 2852 | if (err) |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2853 | goto out_unlock; |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 2854 | |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 2855 | ieee80211_queue_delayed_work(&sdata->local->hw, |
Janusz Dziedzic | 31559f3 | 2014-02-21 19:46:13 +0100 | [diff] [blame] | 2856 | &sdata->dfs_cac_timer_work, |
| 2857 | msecs_to_jiffies(cac_time_ms)); |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 2858 | |
Johannes Berg | 34a3740 | 2013-12-18 09:43:33 +0100 | [diff] [blame] | 2859 | out_unlock: |
| 2860 | mutex_unlock(&local->mtx); |
| 2861 | return err; |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 2862 | } |
| 2863 | |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 2864 | static struct cfg80211_beacon_data * |
| 2865 | cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon) |
| 2866 | { |
| 2867 | struct cfg80211_beacon_data *new_beacon; |
| 2868 | u8 *pos; |
| 2869 | int len; |
| 2870 | |
| 2871 | len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len + |
| 2872 | beacon->proberesp_ies_len + beacon->assocresp_ies_len + |
| 2873 | beacon->probe_resp_len; |
| 2874 | |
| 2875 | new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL); |
| 2876 | if (!new_beacon) |
| 2877 | return NULL; |
| 2878 | |
| 2879 | pos = (u8 *)(new_beacon + 1); |
| 2880 | if (beacon->head_len) { |
| 2881 | new_beacon->head_len = beacon->head_len; |
| 2882 | new_beacon->head = pos; |
| 2883 | memcpy(pos, beacon->head, beacon->head_len); |
| 2884 | pos += beacon->head_len; |
| 2885 | } |
| 2886 | if (beacon->tail_len) { |
| 2887 | new_beacon->tail_len = beacon->tail_len; |
| 2888 | new_beacon->tail = pos; |
| 2889 | memcpy(pos, beacon->tail, beacon->tail_len); |
| 2890 | pos += beacon->tail_len; |
| 2891 | } |
| 2892 | if (beacon->beacon_ies_len) { |
| 2893 | new_beacon->beacon_ies_len = beacon->beacon_ies_len; |
| 2894 | new_beacon->beacon_ies = pos; |
| 2895 | memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len); |
| 2896 | pos += beacon->beacon_ies_len; |
| 2897 | } |
| 2898 | if (beacon->proberesp_ies_len) { |
| 2899 | new_beacon->proberesp_ies_len = beacon->proberesp_ies_len; |
| 2900 | new_beacon->proberesp_ies = pos; |
| 2901 | memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len); |
| 2902 | pos += beacon->proberesp_ies_len; |
| 2903 | } |
| 2904 | if (beacon->assocresp_ies_len) { |
| 2905 | new_beacon->assocresp_ies_len = beacon->assocresp_ies_len; |
| 2906 | new_beacon->assocresp_ies = pos; |
| 2907 | memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len); |
| 2908 | pos += beacon->assocresp_ies_len; |
| 2909 | } |
| 2910 | if (beacon->probe_resp_len) { |
| 2911 | new_beacon->probe_resp_len = beacon->probe_resp_len; |
Arnd Bergmann | bee92d0 | 2018-02-02 16:31:23 +0100 | [diff] [blame] | 2912 | new_beacon->probe_resp = pos; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 2913 | memcpy(pos, beacon->probe_resp, beacon->probe_resp_len); |
| 2914 | pos += beacon->probe_resp_len; |
| 2915 | } |
| 2916 | |
| 2917 | return new_beacon; |
| 2918 | } |
| 2919 | |
Luciano Coelho | 66e01cf | 2014-01-13 19:43:00 +0200 | [diff] [blame] | 2920 | void ieee80211_csa_finish(struct ieee80211_vif *vif) |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 2921 | { |
Luciano Coelho | 66e01cf | 2014-01-13 19:43:00 +0200 | [diff] [blame] | 2922 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 2923 | |
| 2924 | ieee80211_queue_work(&sdata->local->hw, |
| 2925 | &sdata->csa_finalize_work); |
| 2926 | } |
| 2927 | EXPORT_SYMBOL(ieee80211_csa_finish); |
| 2928 | |
Michal Kazior | 6619950 | 2014-04-09 15:11:00 +0200 | [diff] [blame] | 2929 | static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata, |
| 2930 | u32 *changed) |
| 2931 | { |
| 2932 | int err; |
| 2933 | |
| 2934 | switch (sdata->vif.type) { |
| 2935 | case NL80211_IFTYPE_AP: |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 2936 | err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon, |
| 2937 | NULL); |
Michal Kazior | 6619950 | 2014-04-09 15:11:00 +0200 | [diff] [blame] | 2938 | kfree(sdata->u.ap.next_beacon); |
| 2939 | sdata->u.ap.next_beacon = NULL; |
| 2940 | |
| 2941 | if (err < 0) |
| 2942 | return err; |
| 2943 | *changed |= err; |
| 2944 | break; |
| 2945 | case NL80211_IFTYPE_ADHOC: |
| 2946 | err = ieee80211_ibss_finish_csa(sdata); |
| 2947 | if (err < 0) |
| 2948 | return err; |
| 2949 | *changed |= err; |
| 2950 | break; |
| 2951 | #ifdef CONFIG_MAC80211_MESH |
| 2952 | case NL80211_IFTYPE_MESH_POINT: |
| 2953 | err = ieee80211_mesh_finish_csa(sdata); |
| 2954 | if (err < 0) |
| 2955 | return err; |
| 2956 | *changed |= err; |
| 2957 | break; |
| 2958 | #endif |
| 2959 | default: |
| 2960 | WARN_ON(1); |
| 2961 | return -EINVAL; |
| 2962 | } |
| 2963 | |
| 2964 | return 0; |
| 2965 | } |
| 2966 | |
Michal Kazior | cf8767d | 2014-05-08 09:10:02 +0200 | [diff] [blame] | 2967 | static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata) |
Luciano Coelho | 66e01cf | 2014-01-13 19:43:00 +0200 | [diff] [blame] | 2968 | { |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 2969 | struct ieee80211_local *local = sdata->local; |
Michal Kazior | 6619950 | 2014-04-09 15:11:00 +0200 | [diff] [blame] | 2970 | u32 changed = 0; |
| 2971 | int err; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 2972 | |
Michal Kazior | dbd7285 | 2014-01-29 07:56:21 +0100 | [diff] [blame] | 2973 | sdata_assert_lock(sdata); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 2974 | lockdep_assert_held(&local->mtx); |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 2975 | lockdep_assert_held(&local->chanctx_mtx); |
Michal Kazior | dbd7285 | 2014-01-29 07:56:21 +0100 | [diff] [blame] | 2976 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 2977 | /* |
| 2978 | * using reservation isn't immediate as it may be deferred until later |
| 2979 | * with multi-vif. once reservation is complete it will re-schedule the |
| 2980 | * work with no reserved_chanctx so verify chandef to check if it |
| 2981 | * completed successfully |
| 2982 | */ |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 2983 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 2984 | if (sdata->reserved_chanctx) { |
| 2985 | /* |
| 2986 | * with multi-vif csa driver may call ieee80211_csa_finish() |
| 2987 | * many times while waiting for other interfaces to use their |
| 2988 | * reservations |
| 2989 | */ |
| 2990 | if (sdata->reserved_ready) |
| 2991 | return 0; |
| 2992 | |
Fabian Frederick | 408b18a | 2014-10-09 20:36:22 +0200 | [diff] [blame] | 2993 | return ieee80211_vif_use_reserved_context(sdata); |
Arik Nemtsov | 7578d57 | 2013-09-01 17:15:51 +0300 | [diff] [blame] | 2994 | } |
| 2995 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 2996 | if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef, |
| 2997 | &sdata->csa_chandef)) |
| 2998 | return -EINVAL; |
| 2999 | |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 3000 | sdata->vif.csa_active = false; |
Michal Kazior | 97518af | 2014-01-29 07:56:18 +0100 | [diff] [blame] | 3001 | |
Michal Kazior | 6619950 | 2014-04-09 15:11:00 +0200 | [diff] [blame] | 3002 | err = ieee80211_set_after_csa_beacon(sdata, &changed); |
| 3003 | if (err) |
Michal Kazior | cf8767d | 2014-05-08 09:10:02 +0200 | [diff] [blame] | 3004 | return err; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3005 | |
Michal Kazior | faf046e | 2014-01-29 07:56:17 +0100 | [diff] [blame] | 3006 | ieee80211_bss_info_change_notify(sdata, changed); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3007 | |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 3008 | if (sdata->csa_block_tx) { |
| 3009 | ieee80211_wake_vif_queues(local, sdata, |
| 3010 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 3011 | sdata->csa_block_tx = false; |
| 3012 | } |
Michal Kazior | cf8767d | 2014-05-08 09:10:02 +0200 | [diff] [blame] | 3013 | |
Luciano Coelho | f1d6558 | 2014-10-08 09:48:38 +0300 | [diff] [blame] | 3014 | err = drv_post_channel_switch(sdata); |
| 3015 | if (err) |
| 3016 | return err; |
| 3017 | |
| 3018 | cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef); |
| 3019 | |
Michal Kazior | cf8767d | 2014-05-08 09:10:02 +0200 | [diff] [blame] | 3020 | return 0; |
| 3021 | } |
| 3022 | |
| 3023 | static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata) |
| 3024 | { |
| 3025 | if (__ieee80211_csa_finalize(sdata)) { |
| 3026 | sdata_info(sdata, "failed to finalize CSA, disconnecting\n"); |
| 3027 | cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev, |
| 3028 | GFP_KERNEL); |
| 3029 | } |
Luciano Coelho | 66e01cf | 2014-01-13 19:43:00 +0200 | [diff] [blame] | 3030 | } |
| 3031 | |
| 3032 | void ieee80211_csa_finalize_work(struct work_struct *work) |
| 3033 | { |
| 3034 | struct ieee80211_sub_if_data *sdata = |
| 3035 | container_of(work, struct ieee80211_sub_if_data, |
| 3036 | csa_finalize_work); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3037 | struct ieee80211_local *local = sdata->local; |
Luciano Coelho | 66e01cf | 2014-01-13 19:43:00 +0200 | [diff] [blame] | 3038 | |
| 3039 | sdata_lock(sdata); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3040 | mutex_lock(&local->mtx); |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3041 | mutex_lock(&local->chanctx_mtx); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3042 | |
Luciano Coelho | 66e01cf | 2014-01-13 19:43:00 +0200 | [diff] [blame] | 3043 | /* AP might have been stopped while waiting for the lock. */ |
| 3044 | if (!sdata->vif.csa_active) |
| 3045 | goto unlock; |
| 3046 | |
| 3047 | if (!ieee80211_sdata_running(sdata)) |
| 3048 | goto unlock; |
| 3049 | |
| 3050 | ieee80211_csa_finalize(sdata); |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 3051 | |
| 3052 | unlock: |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3053 | mutex_unlock(&local->chanctx_mtx); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3054 | mutex_unlock(&local->mtx); |
Simon Wunderlich | e487eae | 2013-11-21 18:19:51 +0100 | [diff] [blame] | 3055 | sdata_unlock(sdata); |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3056 | } |
| 3057 | |
Michal Kazior | 37fa2bd | 2014-02-28 15:59:06 +0100 | [diff] [blame] | 3058 | static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata, |
| 3059 | struct cfg80211_csa_settings *params, |
| 3060 | u32 *changed) |
| 3061 | { |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 3062 | struct ieee80211_csa_settings csa = {}; |
Michal Kazior | 37fa2bd | 2014-02-28 15:59:06 +0100 | [diff] [blame] | 3063 | int err; |
| 3064 | |
| 3065 | switch (sdata->vif.type) { |
| 3066 | case NL80211_IFTYPE_AP: |
| 3067 | sdata->u.ap.next_beacon = |
| 3068 | cfg80211_beacon_dup(¶ms->beacon_after); |
| 3069 | if (!sdata->u.ap.next_beacon) |
| 3070 | return -ENOMEM; |
| 3071 | |
| 3072 | /* |
| 3073 | * With a count of 0, we don't have to wait for any |
| 3074 | * TBTT before switching, so complete the CSA |
| 3075 | * immediately. In theory, with a count == 1 we |
| 3076 | * should delay the switch until just before the next |
| 3077 | * TBTT, but that would complicate things so we switch |
| 3078 | * immediately too. If we would delay the switch |
| 3079 | * until the next TBTT, we would have to set the probe |
| 3080 | * response here. |
| 3081 | * |
| 3082 | * TODO: A channel switch with count <= 1 without |
| 3083 | * sending a CSA action frame is kind of useless, |
| 3084 | * because the clients won't know we're changing |
| 3085 | * channels. The action frame must be implemented |
| 3086 | * either here or in the userspace. |
| 3087 | */ |
| 3088 | if (params->count <= 1) |
| 3089 | break; |
| 3090 | |
Andrei Otcheretianski | 0d06d9b | 2014-05-09 14:11:47 +0300 | [diff] [blame] | 3091 | if ((params->n_counter_offsets_beacon > |
| 3092 | IEEE80211_MAX_CSA_COUNTERS_NUM) || |
| 3093 | (params->n_counter_offsets_presp > |
| 3094 | IEEE80211_MAX_CSA_COUNTERS_NUM)) |
| 3095 | return -EINVAL; |
Andrei Otcheretianski | 9a774c7 | 2014-05-09 14:11:46 +0300 | [diff] [blame] | 3096 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 3097 | csa.counter_offsets_beacon = params->counter_offsets_beacon; |
| 3098 | csa.counter_offsets_presp = params->counter_offsets_presp; |
| 3099 | csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon; |
| 3100 | csa.n_counter_offsets_presp = params->n_counter_offsets_presp; |
| 3101 | csa.count = params->count; |
Andrei Otcheretianski | 0d06d9b | 2014-05-09 14:11:47 +0300 | [diff] [blame] | 3102 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 3103 | err = ieee80211_assign_beacon(sdata, ¶ms->beacon_csa, &csa); |
Michal Kazior | 37fa2bd | 2014-02-28 15:59:06 +0100 | [diff] [blame] | 3104 | if (err < 0) { |
| 3105 | kfree(sdata->u.ap.next_beacon); |
| 3106 | return err; |
| 3107 | } |
| 3108 | *changed |= err; |
| 3109 | |
| 3110 | break; |
| 3111 | case NL80211_IFTYPE_ADHOC: |
| 3112 | if (!sdata->vif.bss_conf.ibss_joined) |
| 3113 | return -EINVAL; |
| 3114 | |
| 3115 | if (params->chandef.width != sdata->u.ibss.chandef.width) |
| 3116 | return -EINVAL; |
| 3117 | |
| 3118 | switch (params->chandef.width) { |
| 3119 | case NL80211_CHAN_WIDTH_40: |
| 3120 | if (cfg80211_get_chandef_type(¶ms->chandef) != |
| 3121 | cfg80211_get_chandef_type(&sdata->u.ibss.chandef)) |
| 3122 | return -EINVAL; |
| 3123 | case NL80211_CHAN_WIDTH_5: |
| 3124 | case NL80211_CHAN_WIDTH_10: |
| 3125 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 3126 | case NL80211_CHAN_WIDTH_20: |
| 3127 | break; |
| 3128 | default: |
| 3129 | return -EINVAL; |
| 3130 | } |
| 3131 | |
| 3132 | /* changes into another band are not supported */ |
| 3133 | if (sdata->u.ibss.chandef.chan->band != |
| 3134 | params->chandef.chan->band) |
| 3135 | return -EINVAL; |
| 3136 | |
| 3137 | /* see comments in the NL80211_IFTYPE_AP block */ |
| 3138 | if (params->count > 1) { |
| 3139 | err = ieee80211_ibss_csa_beacon(sdata, params); |
| 3140 | if (err < 0) |
| 3141 | return err; |
| 3142 | *changed |= err; |
| 3143 | } |
| 3144 | |
| 3145 | ieee80211_send_action_csa(sdata, params); |
| 3146 | |
| 3147 | break; |
| 3148 | #ifdef CONFIG_MAC80211_MESH |
| 3149 | case NL80211_IFTYPE_MESH_POINT: { |
| 3150 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
| 3151 | |
| 3152 | if (params->chandef.width != sdata->vif.bss_conf.chandef.width) |
| 3153 | return -EINVAL; |
| 3154 | |
| 3155 | /* changes into another band are not supported */ |
| 3156 | if (sdata->vif.bss_conf.chandef.chan->band != |
| 3157 | params->chandef.chan->band) |
| 3158 | return -EINVAL; |
| 3159 | |
| 3160 | if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) { |
| 3161 | ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT; |
| 3162 | if (!ifmsh->pre_value) |
| 3163 | ifmsh->pre_value = 1; |
| 3164 | else |
| 3165 | ifmsh->pre_value++; |
| 3166 | } |
| 3167 | |
| 3168 | /* see comments in the NL80211_IFTYPE_AP block */ |
| 3169 | if (params->count > 1) { |
| 3170 | err = ieee80211_mesh_csa_beacon(sdata, params); |
| 3171 | if (err < 0) { |
| 3172 | ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE; |
| 3173 | return err; |
| 3174 | } |
| 3175 | *changed |= err; |
| 3176 | } |
| 3177 | |
| 3178 | if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT) |
| 3179 | ieee80211_send_action_csa(sdata, params); |
| 3180 | |
| 3181 | break; |
| 3182 | } |
| 3183 | #endif |
| 3184 | default: |
| 3185 | return -EOPNOTSUPP; |
| 3186 | } |
| 3187 | |
| 3188 | return 0; |
| 3189 | } |
| 3190 | |
Luciano Coelho | f29f58a | 2014-05-07 20:05:12 +0300 | [diff] [blame] | 3191 | static int |
| 3192 | __ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, |
| 3193 | struct cfg80211_csa_settings *params) |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3194 | { |
| 3195 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3196 | struct ieee80211_local *local = sdata->local; |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 3197 | struct ieee80211_channel_switch ch_switch; |
Michal Kazior | 2b32713 | 2014-04-09 15:29:32 +0200 | [diff] [blame] | 3198 | struct ieee80211_chanctx_conf *conf; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3199 | struct ieee80211_chanctx *chanctx; |
Johannes Berg | b08cc24 | 2014-10-20 21:36:04 +0200 | [diff] [blame] | 3200 | u32 changed = 0; |
| 3201 | int err; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3202 | |
Michal Kazior | dbd7285 | 2014-01-29 07:56:21 +0100 | [diff] [blame] | 3203 | sdata_assert_lock(sdata); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3204 | lockdep_assert_held(&local->mtx); |
Simon Wunderlich | 7ca133b | 2013-11-21 18:19:50 +0100 | [diff] [blame] | 3205 | |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3206 | if (!list_empty(&local->roc_list) || local->scanning) |
| 3207 | return -EBUSY; |
| 3208 | |
| 3209 | if (sdata->wdev.cac_started) |
| 3210 | return -EBUSY; |
| 3211 | |
| 3212 | if (cfg80211_chandef_identical(¶ms->chandef, |
| 3213 | &sdata->vif.bss_conf.chandef)) |
| 3214 | return -EINVAL; |
| 3215 | |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3216 | /* don't allow another channel switch if one is already active. */ |
| 3217 | if (sdata->vif.csa_active) |
| 3218 | return -EBUSY; |
| 3219 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3220 | mutex_lock(&local->chanctx_mtx); |
| 3221 | conf = rcu_dereference_protected(sdata->vif.chanctx_conf, |
| 3222 | lockdep_is_held(&local->chanctx_mtx)); |
| 3223 | if (!conf) { |
| 3224 | err = -EBUSY; |
| 3225 | goto out; |
| 3226 | } |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3227 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3228 | chanctx = container_of(conf, struct ieee80211_chanctx, conf); |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3229 | |
Luciano Coelho | 000baa5 | 2014-11-07 15:28:33 +0200 | [diff] [blame] | 3230 | ch_switch.timestamp = 0; |
| 3231 | ch_switch.device_timestamp = 0; |
| 3232 | ch_switch.block_tx = params->block_tx; |
| 3233 | ch_switch.chandef = params->chandef; |
| 3234 | ch_switch.count = params->count; |
| 3235 | |
Luciano Coelho | 6d027bc | 2014-10-08 09:48:37 +0300 | [diff] [blame] | 3236 | err = drv_pre_channel_switch(sdata, &ch_switch); |
| 3237 | if (err) |
| 3238 | goto out; |
| 3239 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3240 | err = ieee80211_vif_reserve_chanctx(sdata, ¶ms->chandef, |
| 3241 | chanctx->mode, |
| 3242 | params->radar_required); |
| 3243 | if (err) |
| 3244 | goto out; |
| 3245 | |
| 3246 | /* if reservation is invalid then this will fail */ |
| 3247 | err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0); |
| 3248 | if (err) { |
| 3249 | ieee80211_vif_unreserve_chanctx(sdata); |
| 3250 | goto out; |
| 3251 | } |
| 3252 | |
| 3253 | err = ieee80211_set_csa_beacon(sdata, params, &changed); |
| 3254 | if (err) { |
| 3255 | ieee80211_vif_unreserve_chanctx(sdata); |
| 3256 | goto out; |
| 3257 | } |
| 3258 | |
Luciano Coelho | 33787fc | 2013-11-11 20:34:54 +0200 | [diff] [blame] | 3259 | sdata->csa_chandef = params->chandef; |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3260 | sdata->csa_block_tx = params->block_tx; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3261 | sdata->vif.csa_active = true; |
| 3262 | |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3263 | if (sdata->csa_block_tx) |
Luciano Coelho | a46992b | 2014-06-13 16:30:07 +0300 | [diff] [blame] | 3264 | ieee80211_stop_vif_queues(local, sdata, |
| 3265 | IEEE80211_QUEUE_STOP_REASON_CSA); |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3266 | |
Luciano Coelho | 2f45729 | 2014-11-07 14:31:36 +0200 | [diff] [blame] | 3267 | cfg80211_ch_switch_started_notify(sdata->dev, &sdata->csa_chandef, |
| 3268 | params->count); |
| 3269 | |
Luciano Coelho | 66e01cf | 2014-01-13 19:43:00 +0200 | [diff] [blame] | 3270 | if (changed) { |
| 3271 | ieee80211_bss_info_change_notify(sdata, changed); |
| 3272 | drv_channel_switch_beacon(sdata, ¶ms->chandef); |
| 3273 | } else { |
| 3274 | /* if the beacon didn't change, we can finalize immediately */ |
| 3275 | ieee80211_csa_finalize(sdata); |
| 3276 | } |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3277 | |
Michal Kazior | 03078de | 2014-06-25 12:35:08 +0200 | [diff] [blame] | 3278 | out: |
| 3279 | mutex_unlock(&local->chanctx_mtx); |
| 3280 | return err; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3281 | } |
| 3282 | |
Michal Kazior | 59af692 | 2014-04-09 15:10:59 +0200 | [diff] [blame] | 3283 | int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev, |
| 3284 | struct cfg80211_csa_settings *params) |
| 3285 | { |
| 3286 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3287 | struct ieee80211_local *local = sdata->local; |
| 3288 | int err; |
| 3289 | |
| 3290 | mutex_lock(&local->mtx); |
| 3291 | err = __ieee80211_channel_switch(wiphy, dev, params); |
| 3292 | mutex_unlock(&local->mtx); |
| 3293 | |
| 3294 | return err; |
| 3295 | } |
| 3296 | |
Johannes Berg | a2fcfccb | 2015-11-23 17:18:35 +0100 | [diff] [blame] | 3297 | u64 ieee80211_mgmt_tx_cookie(struct ieee80211_local *local) |
| 3298 | { |
| 3299 | lockdep_assert_held(&local->mtx); |
| 3300 | |
| 3301 | local->roc_cookie_counter++; |
| 3302 | |
| 3303 | /* wow, you wrapped 64 bits ... more likely a bug */ |
| 3304 | if (WARN_ON(local->roc_cookie_counter == 0)) |
| 3305 | local->roc_cookie_counter++; |
| 3306 | |
| 3307 | return local->roc_cookie_counter; |
| 3308 | } |
| 3309 | |
Johannes Berg | 5ee00db | 2015-11-24 14:25:49 +0100 | [diff] [blame] | 3310 | int ieee80211_attach_ack_skb(struct ieee80211_local *local, struct sk_buff *skb, |
| 3311 | u64 *cookie, gfp_t gfp) |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3312 | { |
| 3313 | unsigned long spin_flags; |
| 3314 | struct sk_buff *ack_skb; |
| 3315 | int id; |
| 3316 | |
| 3317 | ack_skb = skb_copy(skb, gfp); |
| 3318 | if (!ack_skb) |
Johannes Berg | 5ee00db | 2015-11-24 14:25:49 +0100 | [diff] [blame] | 3319 | return -ENOMEM; |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3320 | |
| 3321 | spin_lock_irqsave(&local->ack_status_lock, spin_flags); |
| 3322 | id = idr_alloc(&local->ack_status_frames, ack_skb, |
| 3323 | 1, 0x10000, GFP_ATOMIC); |
| 3324 | spin_unlock_irqrestore(&local->ack_status_lock, spin_flags); |
| 3325 | |
| 3326 | if (id < 0) { |
| 3327 | kfree_skb(ack_skb); |
Johannes Berg | 5ee00db | 2015-11-24 14:25:49 +0100 | [diff] [blame] | 3328 | return -ENOMEM; |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | IEEE80211_SKB_CB(skb)->ack_frame_id = id; |
| 3332 | |
| 3333 | *cookie = ieee80211_mgmt_tx_cookie(local); |
| 3334 | IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie; |
| 3335 | |
Johannes Berg | 5ee00db | 2015-11-24 14:25:49 +0100 | [diff] [blame] | 3336 | return 0; |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3337 | } |
| 3338 | |
Johannes Berg | 7be5086 | 2010-10-13 12:06:24 +0200 | [diff] [blame] | 3339 | static void ieee80211_mgmt_frame_register(struct wiphy *wiphy, |
Johannes Berg | 71bbc99 | 2012-06-15 15:30:18 +0200 | [diff] [blame] | 3340 | struct wireless_dev *wdev, |
Johannes Berg | 7be5086 | 2010-10-13 12:06:24 +0200 | [diff] [blame] | 3341 | u16 frame_type, bool reg) |
| 3342 | { |
| 3343 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Andrei Otcheretianski | 1b09b55 | 2015-08-15 22:39:50 +0300 | [diff] [blame] | 3344 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
Johannes Berg | 7be5086 | 2010-10-13 12:06:24 +0200 | [diff] [blame] | 3345 | |
Will Hawkins | 6abe056 | 2012-06-20 11:51:14 -0400 | [diff] [blame] | 3346 | switch (frame_type) { |
Will Hawkins | 6abe056 | 2012-06-20 11:51:14 -0400 | [diff] [blame] | 3347 | case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ: |
Andrei Otcheretianski | 1b09b55 | 2015-08-15 22:39:50 +0300 | [diff] [blame] | 3348 | if (reg) { |
Will Hawkins | 6abe056 | 2012-06-20 11:51:14 -0400 | [diff] [blame] | 3349 | local->probe_req_reg++; |
Andrei Otcheretianski | 1b09b55 | 2015-08-15 22:39:50 +0300 | [diff] [blame] | 3350 | sdata->vif.probe_req_reg++; |
| 3351 | } else { |
| 3352 | if (local->probe_req_reg) |
| 3353 | local->probe_req_reg--; |
| 3354 | |
| 3355 | if (sdata->vif.probe_req_reg) |
| 3356 | sdata->vif.probe_req_reg--; |
| 3357 | } |
Johannes Berg | 7be5086 | 2010-10-13 12:06:24 +0200 | [diff] [blame] | 3358 | |
Felix Fietkau | 35f5149 | 2012-10-31 15:50:34 +0100 | [diff] [blame] | 3359 | if (!local->open_count) |
| 3360 | break; |
| 3361 | |
Andrei Otcheretianski | 1b09b55 | 2015-08-15 22:39:50 +0300 | [diff] [blame] | 3362 | if (sdata->vif.probe_req_reg == 1) |
| 3363 | drv_config_iface_filter(local, sdata, FIF_PROBE_REQ, |
| 3364 | FIF_PROBE_REQ); |
| 3365 | else if (sdata->vif.probe_req_reg == 0) |
| 3366 | drv_config_iface_filter(local, sdata, 0, |
| 3367 | FIF_PROBE_REQ); |
| 3368 | |
| 3369 | ieee80211_configure_filter(local); |
Will Hawkins | 6abe056 | 2012-06-20 11:51:14 -0400 | [diff] [blame] | 3370 | break; |
| 3371 | default: |
| 3372 | break; |
| 3373 | } |
Johannes Berg | 7be5086 | 2010-10-13 12:06:24 +0200 | [diff] [blame] | 3374 | } |
| 3375 | |
Bruno Randolf | 15d9675 | 2010-11-10 12:50:56 +0900 | [diff] [blame] | 3376 | static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant) |
| 3377 | { |
| 3378 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 3379 | |
| 3380 | if (local->started) |
| 3381 | return -EOPNOTSUPP; |
| 3382 | |
| 3383 | return drv_set_antenna(local, tx_ant, rx_ant); |
| 3384 | } |
| 3385 | |
| 3386 | static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant) |
| 3387 | { |
| 3388 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 3389 | |
| 3390 | return drv_get_antenna(local, tx_ant, rx_ant); |
| 3391 | } |
| 3392 | |
Johannes Berg | c68f4b8 | 2011-07-05 16:35:41 +0200 | [diff] [blame] | 3393 | static int ieee80211_set_rekey_data(struct wiphy *wiphy, |
| 3394 | struct net_device *dev, |
| 3395 | struct cfg80211_gtk_rekey_data *data) |
| 3396 | { |
| 3397 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 3398 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3399 | |
| 3400 | if (!local->ops->set_rekey_data) |
| 3401 | return -EOPNOTSUPP; |
| 3402 | |
| 3403 | drv_set_rekey_data(local, sdata, data); |
| 3404 | |
| 3405 | return 0; |
| 3406 | } |
| 3407 | |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3408 | static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev, |
| 3409 | const u8 *peer, u64 *cookie) |
| 3410 | { |
| 3411 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3412 | struct ieee80211_local *local = sdata->local; |
| 3413 | struct ieee80211_qos_hdr *nullfunc; |
Johannes Berg | 5ee00db | 2015-11-24 14:25:49 +0100 | [diff] [blame] | 3414 | struct sk_buff *skb; |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3415 | int size = sizeof(*nullfunc); |
| 3416 | __le16 fc; |
| 3417 | bool qos; |
| 3418 | struct ieee80211_tx_info *info; |
| 3419 | struct sta_info *sta; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3420 | struct ieee80211_chanctx_conf *chanctx_conf; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 3421 | enum nl80211_band band; |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3422 | int ret; |
| 3423 | |
| 3424 | /* the lock is needed to assign the cookie later */ |
| 3425 | mutex_lock(&local->mtx); |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3426 | |
| 3427 | rcu_read_lock(); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3428 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 3429 | if (WARN_ON(!chanctx_conf)) { |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3430 | ret = -EINVAL; |
| 3431 | goto unlock; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3432 | } |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 3433 | band = chanctx_conf->def.chan->band; |
Felix Fietkau | 03bb7f4 | 2013-09-29 21:39:33 +0200 | [diff] [blame] | 3434 | sta = sta_info_get_bss(sdata, peer); |
Johannes Berg | b4487c2 | 2011-11-11 20:22:30 +0100 | [diff] [blame] | 3435 | if (sta) { |
Johannes Berg | a74a8c8 | 2014-07-22 14:50:47 +0200 | [diff] [blame] | 3436 | qos = sta->sta.wme; |
Johannes Berg | b4487c2 | 2011-11-11 20:22:30 +0100 | [diff] [blame] | 3437 | } else { |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3438 | ret = -ENOLINK; |
| 3439 | goto unlock; |
Johannes Berg | b4487c2 | 2011-11-11 20:22:30 +0100 | [diff] [blame] | 3440 | } |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3441 | |
| 3442 | if (qos) { |
| 3443 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 3444 | IEEE80211_STYPE_QOS_NULLFUNC | |
| 3445 | IEEE80211_FCTL_FROMDS); |
| 3446 | } else { |
| 3447 | size -= 2; |
| 3448 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 3449 | IEEE80211_STYPE_NULLFUNC | |
| 3450 | IEEE80211_FCTL_FROMDS); |
| 3451 | } |
| 3452 | |
| 3453 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + size); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3454 | if (!skb) { |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3455 | ret = -ENOMEM; |
| 3456 | goto unlock; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3457 | } |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3458 | |
| 3459 | skb->dev = dev; |
| 3460 | |
| 3461 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 3462 | |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 3463 | nullfunc = skb_put(skb, size); |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3464 | nullfunc->frame_control = fc; |
| 3465 | nullfunc->duration_id = 0; |
| 3466 | memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN); |
| 3467 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); |
| 3468 | memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN); |
| 3469 | nullfunc->seq_ctrl = 0; |
| 3470 | |
| 3471 | info = IEEE80211_SKB_CB(skb); |
| 3472 | |
| 3473 | info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS | |
| 3474 | IEEE80211_TX_INTFL_NL80211_FRAME_TX; |
Johannes Berg | 73c4e19 | 2014-11-09 18:50:09 +0200 | [diff] [blame] | 3475 | info->band = band; |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3476 | |
| 3477 | skb_set_queue_mapping(skb, IEEE80211_AC_VO); |
| 3478 | skb->priority = 7; |
| 3479 | if (qos) |
| 3480 | nullfunc->qos_ctrl = cpu_to_le16(7); |
| 3481 | |
Johannes Berg | 5ee00db | 2015-11-24 14:25:49 +0100 | [diff] [blame] | 3482 | ret = ieee80211_attach_ack_skb(local, skb, cookie, GFP_ATOMIC); |
| 3483 | if (ret) { |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3484 | kfree_skb(skb); |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3485 | goto unlock; |
| 3486 | } |
| 3487 | |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3488 | local_bh_disable(); |
Johannes Berg | 7c10770 | 2015-03-20 14:18:27 +0100 | [diff] [blame] | 3489 | ieee80211_xmit(sdata, sta, skb); |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3490 | local_bh_enable(); |
| 3491 | |
Johannes Berg | 3b79af9 | 2015-06-01 23:14:59 +0200 | [diff] [blame] | 3492 | ret = 0; |
| 3493 | unlock: |
| 3494 | rcu_read_unlock(); |
| 3495 | mutex_unlock(&local->mtx); |
| 3496 | |
| 3497 | return ret; |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3498 | } |
| 3499 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3500 | static int ieee80211_cfg_get_channel(struct wiphy *wiphy, |
| 3501 | struct wireless_dev *wdev, |
| 3502 | struct cfg80211_chan_def *chandef) |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3503 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3504 | struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
Felix Fietkau | cb601ff | 2013-02-23 19:02:14 +0100 | [diff] [blame] | 3505 | struct ieee80211_local *local = wiphy_priv(wiphy); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3506 | struct ieee80211_chanctx_conf *chanctx_conf; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3507 | int ret = -ENODATA; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3508 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3509 | rcu_read_lock(); |
Johannes Berg | feda302 | 2013-02-28 09:59:22 +0100 | [diff] [blame] | 3510 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 3511 | if (chanctx_conf) { |
Luciano Coelho | c12bc48 | 2014-09-30 07:08:02 +0300 | [diff] [blame] | 3512 | *chandef = sdata->vif.bss_conf.chandef; |
Johannes Berg | feda302 | 2013-02-28 09:59:22 +0100 | [diff] [blame] | 3513 | ret = 0; |
| 3514 | } else if (local->open_count > 0 && |
| 3515 | local->open_count == local->monitors && |
| 3516 | sdata->vif.type == NL80211_IFTYPE_MONITOR) { |
| 3517 | if (local->use_chanctx) |
| 3518 | *chandef = local->monitor_chandef; |
| 3519 | else |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 3520 | *chandef = local->_oper_chandef; |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3521 | ret = 0; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3522 | } |
| 3523 | rcu_read_unlock(); |
| 3524 | |
Johannes Berg | 683b6d3 | 2012-11-08 21:25:48 +0100 | [diff] [blame] | 3525 | return ret; |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3526 | } |
| 3527 | |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 3528 | #ifdef CONFIG_PM |
| 3529 | static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled) |
| 3530 | { |
| 3531 | drv_set_wakeup(wiphy_priv(wiphy), enabled); |
| 3532 | } |
| 3533 | #endif |
| 3534 | |
Kyeyoon Park | 32db6b5 | 2013-12-16 23:04:43 -0800 | [diff] [blame] | 3535 | static int ieee80211_set_qos_map(struct wiphy *wiphy, |
| 3536 | struct net_device *dev, |
| 3537 | struct cfg80211_qos_map *qos_map) |
| 3538 | { |
| 3539 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3540 | struct mac80211_qos_map *new_qos_map, *old_qos_map; |
| 3541 | |
| 3542 | if (qos_map) { |
| 3543 | new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL); |
| 3544 | if (!new_qos_map) |
| 3545 | return -ENOMEM; |
| 3546 | memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map)); |
| 3547 | } else { |
| 3548 | /* A NULL qos_map was passed to disable QoS mapping */ |
| 3549 | new_qos_map = NULL; |
| 3550 | } |
| 3551 | |
Johannes Berg | 194ff52 | 2013-12-30 23:12:37 +0100 | [diff] [blame] | 3552 | old_qos_map = sdata_dereference(sdata->qos_map, sdata); |
Kyeyoon Park | 32db6b5 | 2013-12-16 23:04:43 -0800 | [diff] [blame] | 3553 | rcu_assign_pointer(sdata->qos_map, new_qos_map); |
| 3554 | if (old_qos_map) |
| 3555 | kfree_rcu(old_qos_map, rcu_head); |
| 3556 | |
| 3557 | return 0; |
| 3558 | } |
| 3559 | |
Jouni Malinen | 3b1700b | 2014-04-28 11:22:25 +0300 | [diff] [blame] | 3560 | static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy, |
| 3561 | struct net_device *dev, |
| 3562 | struct cfg80211_chan_def *chandef) |
| 3563 | { |
| 3564 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3565 | int ret; |
| 3566 | u32 changed = 0; |
| 3567 | |
| 3568 | ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed); |
| 3569 | if (ret == 0) |
| 3570 | ieee80211_bss_info_change_notify(sdata, changed); |
| 3571 | |
| 3572 | return ret; |
| 3573 | } |
| 3574 | |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 3575 | static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev, |
| 3576 | u8 tsid, const u8 *peer, u8 up, |
| 3577 | u16 admitted_time) |
| 3578 | { |
| 3579 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3580 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3581 | int ac = ieee802_1d_to_ac[up]; |
| 3582 | |
| 3583 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 3584 | return -EOPNOTSUPP; |
| 3585 | |
| 3586 | if (!(sdata->wmm_acm & BIT(up))) |
| 3587 | return -EINVAL; |
| 3588 | |
| 3589 | if (ifmgd->tx_tspec[ac].admitted_time) |
| 3590 | return -EBUSY; |
| 3591 | |
| 3592 | if (admitted_time) { |
| 3593 | ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time; |
| 3594 | ifmgd->tx_tspec[ac].tsid = tsid; |
| 3595 | ifmgd->tx_tspec[ac].up = up; |
| 3596 | } |
| 3597 | |
| 3598 | return 0; |
| 3599 | } |
| 3600 | |
| 3601 | static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev, |
| 3602 | u8 tsid, const u8 *peer) |
| 3603 | { |
| 3604 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3605 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3606 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 3607 | int ac; |
| 3608 | |
| 3609 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 3610 | struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac]; |
| 3611 | |
| 3612 | /* skip unused entries */ |
| 3613 | if (!tx_tspec->admitted_time) |
| 3614 | continue; |
| 3615 | |
| 3616 | if (tx_tspec->tsid != tsid) |
| 3617 | continue; |
| 3618 | |
| 3619 | /* due to this new packets will be reassigned to non-ACM ACs */ |
| 3620 | tx_tspec->up = -1; |
| 3621 | |
| 3622 | /* Make sure that all packets have been sent to avoid to |
| 3623 | * restore the QoS params on packets that are still on the |
| 3624 | * queues. |
| 3625 | */ |
| 3626 | synchronize_net(); |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 3627 | ieee80211_flush_queues(local, sdata, false); |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 3628 | |
| 3629 | /* restore the normal QoS parameters |
| 3630 | * (unconditionally to avoid races) |
| 3631 | */ |
| 3632 | tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE; |
| 3633 | tx_tspec->downgraded = false; |
| 3634 | ieee80211_sta_handle_tspec_ac_params(sdata); |
| 3635 | |
| 3636 | /* finally clear all the data */ |
| 3637 | memset(tx_tspec, 0, sizeof(*tx_tspec)); |
| 3638 | |
| 3639 | return 0; |
| 3640 | } |
| 3641 | |
| 3642 | return -ENOENT; |
| 3643 | } |
| 3644 | |
Ayala Beker | 167e33f | 2016-09-20 17:31:20 +0300 | [diff] [blame] | 3645 | void ieee80211_nan_func_terminated(struct ieee80211_vif *vif, |
| 3646 | u8 inst_id, |
| 3647 | enum nl80211_nan_func_term_reason reason, |
| 3648 | gfp_t gfp) |
| 3649 | { |
| 3650 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 3651 | struct cfg80211_nan_func *func; |
| 3652 | u64 cookie; |
| 3653 | |
| 3654 | if (WARN_ON(vif->type != NL80211_IFTYPE_NAN)) |
| 3655 | return; |
| 3656 | |
| 3657 | spin_lock_bh(&sdata->u.nan.func_lock); |
| 3658 | |
| 3659 | func = idr_find(&sdata->u.nan.function_inst_ids, inst_id); |
| 3660 | if (WARN_ON(!func)) { |
| 3661 | spin_unlock_bh(&sdata->u.nan.func_lock); |
| 3662 | return; |
| 3663 | } |
| 3664 | |
| 3665 | cookie = func->cookie; |
| 3666 | idr_remove(&sdata->u.nan.function_inst_ids, inst_id); |
| 3667 | |
| 3668 | spin_unlock_bh(&sdata->u.nan.func_lock); |
| 3669 | |
| 3670 | cfg80211_free_nan_func(func); |
| 3671 | |
| 3672 | cfg80211_nan_func_terminated(ieee80211_vif_to_wdev(vif), inst_id, |
| 3673 | reason, cookie, gfp); |
| 3674 | } |
| 3675 | EXPORT_SYMBOL(ieee80211_nan_func_terminated); |
| 3676 | |
Ayala Beker | 92bc43b | 2016-09-20 17:31:21 +0300 | [diff] [blame] | 3677 | void ieee80211_nan_func_match(struct ieee80211_vif *vif, |
| 3678 | struct cfg80211_nan_match_params *match, |
| 3679 | gfp_t gfp) |
| 3680 | { |
| 3681 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 3682 | struct cfg80211_nan_func *func; |
| 3683 | |
| 3684 | if (WARN_ON(vif->type != NL80211_IFTYPE_NAN)) |
| 3685 | return; |
| 3686 | |
| 3687 | spin_lock_bh(&sdata->u.nan.func_lock); |
| 3688 | |
| 3689 | func = idr_find(&sdata->u.nan.function_inst_ids, match->inst_id); |
| 3690 | if (WARN_ON(!func)) { |
| 3691 | spin_unlock_bh(&sdata->u.nan.func_lock); |
| 3692 | return; |
| 3693 | } |
| 3694 | match->cookie = func->cookie; |
| 3695 | |
| 3696 | spin_unlock_bh(&sdata->u.nan.func_lock); |
| 3697 | |
| 3698 | cfg80211_nan_match(ieee80211_vif_to_wdev(vif), match, gfp); |
| 3699 | } |
| 3700 | EXPORT_SYMBOL(ieee80211_nan_func_match); |
| 3701 | |
Michael Braun | ebceec8 | 2016-11-22 11:52:18 +0100 | [diff] [blame] | 3702 | static int ieee80211_set_multicast_to_unicast(struct wiphy *wiphy, |
| 3703 | struct net_device *dev, |
| 3704 | const bool enabled) |
| 3705 | { |
| 3706 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 3707 | |
| 3708 | sdata->u.ap.multicast_to_unicast = enabled; |
| 3709 | |
| 3710 | return 0; |
| 3711 | } |
| 3712 | |
Toke Høiland-Jørgensen | 2fe4a29 | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3713 | void ieee80211_fill_txq_stats(struct cfg80211_txq_stats *txqstats, |
| 3714 | struct txq_info *txqi) |
| 3715 | { |
| 3716 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_BYTES))) { |
| 3717 | txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_BYTES); |
| 3718 | txqstats->backlog_bytes = txqi->tin.backlog_bytes; |
| 3719 | } |
| 3720 | |
| 3721 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS))) { |
| 3722 | txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS); |
| 3723 | txqstats->backlog_packets = txqi->tin.backlog_packets; |
| 3724 | } |
| 3725 | |
| 3726 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_FLOWS))) { |
| 3727 | txqstats->filled |= BIT(NL80211_TXQ_STATS_FLOWS); |
| 3728 | txqstats->flows = txqi->tin.flows; |
| 3729 | } |
| 3730 | |
| 3731 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_DROPS))) { |
| 3732 | txqstats->filled |= BIT(NL80211_TXQ_STATS_DROPS); |
| 3733 | txqstats->drops = txqi->cstats.drop_count; |
| 3734 | } |
| 3735 | |
| 3736 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_ECN_MARKS))) { |
| 3737 | txqstats->filled |= BIT(NL80211_TXQ_STATS_ECN_MARKS); |
| 3738 | txqstats->ecn_marks = txqi->cstats.ecn_mark; |
| 3739 | } |
| 3740 | |
| 3741 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_OVERLIMIT))) { |
| 3742 | txqstats->filled |= BIT(NL80211_TXQ_STATS_OVERLIMIT); |
| 3743 | txqstats->overlimit = txqi->tin.overlimit; |
| 3744 | } |
| 3745 | |
| 3746 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_COLLISIONS))) { |
| 3747 | txqstats->filled |= BIT(NL80211_TXQ_STATS_COLLISIONS); |
| 3748 | txqstats->collisions = txqi->tin.collisions; |
| 3749 | } |
| 3750 | |
| 3751 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_BYTES))) { |
| 3752 | txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_BYTES); |
| 3753 | txqstats->tx_bytes = txqi->tin.tx_bytes; |
| 3754 | } |
| 3755 | |
| 3756 | if (!(txqstats->filled & BIT(NL80211_TXQ_STATS_TX_PACKETS))) { |
| 3757 | txqstats->filled |= BIT(NL80211_TXQ_STATS_TX_PACKETS); |
| 3758 | txqstats->tx_packets = txqi->tin.tx_packets; |
| 3759 | } |
| 3760 | } |
| 3761 | |
| 3762 | static int ieee80211_get_txq_stats(struct wiphy *wiphy, |
| 3763 | struct wireless_dev *wdev, |
| 3764 | struct cfg80211_txq_stats *txqstats) |
| 3765 | { |
| 3766 | struct ieee80211_local *local = wiphy_priv(wiphy); |
| 3767 | struct ieee80211_sub_if_data *sdata; |
| 3768 | int ret = 0; |
| 3769 | |
| 3770 | if (!local->ops->wake_tx_queue) |
| 3771 | return 1; |
| 3772 | |
| 3773 | spin_lock_bh(&local->fq.lock); |
| 3774 | rcu_read_lock(); |
| 3775 | |
| 3776 | if (wdev) { |
| 3777 | sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); |
| 3778 | if (!sdata->vif.txq) { |
| 3779 | ret = 1; |
| 3780 | goto out; |
| 3781 | } |
| 3782 | ieee80211_fill_txq_stats(txqstats, to_txq_info(sdata->vif.txq)); |
| 3783 | } else { |
| 3784 | /* phy stats */ |
| 3785 | txqstats->filled |= BIT(NL80211_TXQ_STATS_BACKLOG_PACKETS) | |
| 3786 | BIT(NL80211_TXQ_STATS_BACKLOG_BYTES) | |
| 3787 | BIT(NL80211_TXQ_STATS_OVERLIMIT) | |
| 3788 | BIT(NL80211_TXQ_STATS_OVERMEMORY) | |
| 3789 | BIT(NL80211_TXQ_STATS_COLLISIONS) | |
| 3790 | BIT(NL80211_TXQ_STATS_MAX_FLOWS); |
| 3791 | txqstats->backlog_packets = local->fq.backlog; |
| 3792 | txqstats->backlog_bytes = local->fq.memory_usage; |
| 3793 | txqstats->overlimit = local->fq.overlimit; |
| 3794 | txqstats->overmemory = local->fq.overmemory; |
| 3795 | txqstats->collisions = local->fq.collisions; |
| 3796 | txqstats->max_flows = local->fq.flows_cnt; |
| 3797 | } |
| 3798 | |
| 3799 | out: |
| 3800 | rcu_read_unlock(); |
| 3801 | spin_unlock_bh(&local->fq.lock); |
| 3802 | |
| 3803 | return ret; |
| 3804 | } |
| 3805 | |
Johannes Berg | 8a47cea | 2014-01-20 23:55:44 +0100 | [diff] [blame] | 3806 | const struct cfg80211_ops mac80211_config_ops = { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3807 | .add_virtual_intf = ieee80211_add_iface, |
| 3808 | .del_virtual_intf = ieee80211_del_iface, |
Johannes Berg | 42613db | 2007-09-28 21:52:27 +0200 | [diff] [blame] | 3809 | .change_virtual_intf = ieee80211_change_iface, |
Johannes Berg | f142c6b | 2012-06-18 20:07:15 +0200 | [diff] [blame] | 3810 | .start_p2p_device = ieee80211_start_p2p_device, |
| 3811 | .stop_p2p_device = ieee80211_stop_p2p_device, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 3812 | .add_key = ieee80211_add_key, |
| 3813 | .del_key = ieee80211_del_key, |
Johannes Berg | 62da92f | 2007-12-19 02:03:31 +0100 | [diff] [blame] | 3814 | .get_key = ieee80211_get_key, |
Johannes Berg | e8cbb4c | 2007-12-19 02:03:30 +0100 | [diff] [blame] | 3815 | .set_default_key = ieee80211_config_default_key, |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 3816 | .set_default_mgmt_key = ieee80211_config_default_mgmt_key, |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 3817 | .start_ap = ieee80211_start_ap, |
| 3818 | .change_beacon = ieee80211_change_beacon, |
| 3819 | .stop_ap = ieee80211_stop_ap, |
Johannes Berg | 4fd6931 | 2007-12-19 02:03:35 +0100 | [diff] [blame] | 3820 | .add_station = ieee80211_add_station, |
| 3821 | .del_station = ieee80211_del_station, |
| 3822 | .change_station = ieee80211_change_station, |
Johannes Berg | 7bbdd2d | 2007-12-19 02:03:37 +0100 | [diff] [blame] | 3823 | .get_station = ieee80211_get_station, |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 3824 | .dump_station = ieee80211_dump_station, |
Holger Schurig | 1289723 | 2010-04-19 10:23:57 +0200 | [diff] [blame] | 3825 | .dump_survey = ieee80211_dump_survey, |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 3826 | #ifdef CONFIG_MAC80211_MESH |
| 3827 | .add_mpath = ieee80211_add_mpath, |
| 3828 | .del_mpath = ieee80211_del_mpath, |
| 3829 | .change_mpath = ieee80211_change_mpath, |
| 3830 | .get_mpath = ieee80211_get_mpath, |
| 3831 | .dump_mpath = ieee80211_dump_mpath, |
Henning Rogge | a2db2ed | 2014-09-12 08:58:50 +0200 | [diff] [blame] | 3832 | .get_mpp = ieee80211_get_mpp, |
| 3833 | .dump_mpp = ieee80211_dump_mpp, |
Javier Cardona | 24bdd9f | 2010-12-16 17:37:48 -0800 | [diff] [blame] | 3834 | .update_mesh_config = ieee80211_update_mesh_config, |
| 3835 | .get_mesh_config = ieee80211_get_mesh_config, |
Johannes Berg | 29cbe68 | 2010-12-03 09:20:44 +0100 | [diff] [blame] | 3836 | .join_mesh = ieee80211_join_mesh, |
| 3837 | .leave_mesh = ieee80211_leave_mesh, |
Luis Carlos Cobo | c5dd9c2 | 2008-02-23 15:17:17 +0100 | [diff] [blame] | 3838 | #endif |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 3839 | .join_ocb = ieee80211_join_ocb, |
| 3840 | .leave_ocb = ieee80211_leave_ocb, |
Jouni Malinen | 9f1ba90 | 2008-08-07 20:07:01 +0300 | [diff] [blame] | 3841 | .change_bss = ieee80211_change_bss, |
Jouni Malinen | 3188848 | 2008-10-30 16:59:24 +0200 | [diff] [blame] | 3842 | .set_txq_params = ieee80211_set_txq_params, |
Johannes Berg | e8c9bd5 | 2012-06-06 08:18:22 +0200 | [diff] [blame] | 3843 | .set_monitor_channel = ieee80211_set_monitor_channel, |
Bob Copeland | 665af4f | 2009-01-19 11:20:53 -0500 | [diff] [blame] | 3844 | .suspend = ieee80211_suspend, |
| 3845 | .resume = ieee80211_resume, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 3846 | .scan = ieee80211_scan, |
Vidyullatha Kanchanapally | 91f123f | 2015-10-30 19:14:50 +0530 | [diff] [blame] | 3847 | .abort_scan = ieee80211_abort_scan, |
Luciano Coelho | 79f460c | 2011-05-11 17:09:36 +0300 | [diff] [blame] | 3848 | .sched_scan_start = ieee80211_sched_scan_start, |
| 3849 | .sched_scan_stop = ieee80211_sched_scan_stop, |
Jouni Malinen | 636a5d3 | 2009-03-19 13:39:22 +0200 | [diff] [blame] | 3850 | .auth = ieee80211_auth, |
| 3851 | .assoc = ieee80211_assoc, |
| 3852 | .deauth = ieee80211_deauth, |
| 3853 | .disassoc = ieee80211_disassoc, |
Johannes Berg | af8cdcd | 2009-04-19 21:25:43 +0200 | [diff] [blame] | 3854 | .join_ibss = ieee80211_join_ibss, |
| 3855 | .leave_ibss = ieee80211_leave_ibss, |
Antonio Quartulli | 391e53e | 2012-11-02 13:27:49 +0100 | [diff] [blame] | 3856 | .set_mcast_rate = ieee80211_set_mcast_rate, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 3857 | .set_wiphy_params = ieee80211_set_wiphy_params, |
Johannes Berg | 7643a2c | 2009-06-02 13:01:39 +0200 | [diff] [blame] | 3858 | .set_tx_power = ieee80211_set_tx_power, |
| 3859 | .get_tx_power = ieee80211_get_tx_power, |
Johannes Berg | ab737a4 | 2009-07-01 21:26:58 +0200 | [diff] [blame] | 3860 | .set_wds_peer = ieee80211_set_wds_peer, |
Johannes Berg | 1f87f7d | 2009-06-02 13:01:41 +0200 | [diff] [blame] | 3861 | .rfkill_poll = ieee80211_rfkill_poll, |
Johannes Berg | aff89a9 | 2009-07-01 21:26:51 +0200 | [diff] [blame] | 3862 | CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd) |
Wey-Yi Guy | 71063f0 | 2011-05-20 09:05:54 -0700 | [diff] [blame] | 3863 | CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump) |
Johannes Berg | bc92afd | 2009-07-01 21:26:57 +0200 | [diff] [blame] | 3864 | .set_power_mgmt = ieee80211_set_power_mgmt, |
Johannes Berg | 9930380 | 2009-07-01 21:26:59 +0200 | [diff] [blame] | 3865 | .set_bitrate_mask = ieee80211_set_bitrate_mask, |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 3866 | .remain_on_channel = ieee80211_remain_on_channel, |
| 3867 | .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel, |
Johannes Berg | 2e161f7 | 2010-08-12 15:38:38 +0200 | [diff] [blame] | 3868 | .mgmt_tx = ieee80211_mgmt_tx, |
Johannes Berg | f30221e | 2010-11-25 10:02:30 +0100 | [diff] [blame] | 3869 | .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait, |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 3870 | .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config, |
Andrew Zaborowski | 2c3c5f8c | 2017-02-10 04:50:22 +0100 | [diff] [blame] | 3871 | .set_cqm_rssi_range_config = ieee80211_set_cqm_rssi_range_config, |
Johannes Berg | 7be5086 | 2010-10-13 12:06:24 +0200 | [diff] [blame] | 3872 | .mgmt_frame_register = ieee80211_mgmt_frame_register, |
Bruno Randolf | 15d9675 | 2010-11-10 12:50:56 +0900 | [diff] [blame] | 3873 | .set_antenna = ieee80211_set_antenna, |
| 3874 | .get_antenna = ieee80211_get_antenna, |
Johannes Berg | c68f4b8 | 2011-07-05 16:35:41 +0200 | [diff] [blame] | 3875 | .set_rekey_data = ieee80211_set_rekey_data, |
Arik Nemtsov | dfe018b | 2011-09-28 14:12:52 +0300 | [diff] [blame] | 3876 | .tdls_oper = ieee80211_tdls_oper, |
| 3877 | .tdls_mgmt = ieee80211_tdls_mgmt, |
Arik Nemtsov | a7a6bdd | 2014-11-09 18:50:19 +0200 | [diff] [blame] | 3878 | .tdls_channel_switch = ieee80211_tdls_channel_switch, |
| 3879 | .tdls_cancel_channel_switch = ieee80211_tdls_cancel_channel_switch, |
Johannes Berg | 0650073 | 2011-11-04 11:18:16 +0100 | [diff] [blame] | 3880 | .probe_client = ieee80211_probe_client, |
Simon Wunderlich | b53be79 | 2011-11-18 14:20:44 +0100 | [diff] [blame] | 3881 | .set_noack_map = ieee80211_set_noack_map, |
Johannes Berg | 6d52563 | 2012-04-04 15:05:25 +0200 | [diff] [blame] | 3882 | #ifdef CONFIG_PM |
| 3883 | .set_wakeup = ieee80211_set_wakeup, |
| 3884 | #endif |
Johannes Berg | 5b7ccaf | 2012-07-12 19:45:08 +0200 | [diff] [blame] | 3885 | .get_channel = ieee80211_cfg_get_channel, |
Simon Wunderlich | 164eb02 | 2013-02-08 18:16:20 +0100 | [diff] [blame] | 3886 | .start_radar_detection = ieee80211_start_radar_detection, |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 3887 | .channel_switch = ieee80211_channel_switch, |
Kyeyoon Park | 32db6b5 | 2013-12-16 23:04:43 -0800 | [diff] [blame] | 3888 | .set_qos_map = ieee80211_set_qos_map, |
Jouni Malinen | 3b1700b | 2014-04-28 11:22:25 +0300 | [diff] [blame] | 3889 | .set_ap_chanwidth = ieee80211_set_ap_chanwidth, |
Johannes Berg | 02219b3 | 2014-10-07 10:38:50 +0300 | [diff] [blame] | 3890 | .add_tx_ts = ieee80211_add_tx_ts, |
| 3891 | .del_tx_ts = ieee80211_del_tx_ts, |
Ayala Beker | 708d50e | 2016-09-20 17:31:14 +0300 | [diff] [blame] | 3892 | .start_nan = ieee80211_start_nan, |
| 3893 | .stop_nan = ieee80211_stop_nan, |
Ayala Beker | 5953ff6 | 2016-09-20 17:31:19 +0300 | [diff] [blame] | 3894 | .nan_change_conf = ieee80211_nan_change_conf, |
Ayala Beker | 167e33f | 2016-09-20 17:31:20 +0300 | [diff] [blame] | 3895 | .add_nan_func = ieee80211_add_nan_func, |
| 3896 | .del_nan_func = ieee80211_del_nan_func, |
Michael Braun | ebceec8 | 2016-11-22 11:52:18 +0100 | [diff] [blame] | 3897 | .set_multicast_to_unicast = ieee80211_set_multicast_to_unicast, |
Denis Kenzior | 9118064 | 2018-03-26 12:52:50 -0500 | [diff] [blame] | 3898 | .tx_control_port = ieee80211_tx_control_port, |
Toke Høiland-Jørgensen | 2fe4a29 | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 3899 | .get_txq_stats = ieee80211_get_txq_stats, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 3900 | }; |