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