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