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