Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * BSS client mode implementation |
Jouni Malinen | 5394af4 | 2009-01-08 13:31:59 +0200 | [diff] [blame] | 3 | * Copyright 2003-2008, Jouni Malinen <j@w1.fi> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4 | * Copyright 2004, Instant802 Networks, Inc. |
| 5 | * Copyright 2005, Devicescape Software, Inc. |
| 6 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 7 | * Copyright 2007, Michael Wu <flamingice@sourmilk.net> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
Geert Uytterhoeven | 5b323ed | 2007-05-08 18:40:27 -0700 | [diff] [blame] | 14 | #include <linux/delay.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 15 | #include <linux/if_ether.h> |
| 16 | #include <linux/skbuff.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 17 | #include <linux/if_arp.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 18 | #include <linux/etherdevice.h> |
Paul Gortmaker | d9b9384 | 2011-09-18 13:21:27 -0400 | [diff] [blame] | 19 | #include <linux/moduleparam.h> |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 20 | #include <linux/rtnetlink.h> |
Jean Pihet | e8db0be | 2011-08-25 15:35:03 +0200 | [diff] [blame] | 21 | #include <linux/pm_qos.h> |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 22 | #include <linux/crc32.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 24 | #include <linux/export.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 25 | #include <net/mac80211.h> |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 26 | #include <asm/unaligned.h> |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 27 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 28 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 29 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 30 | #include "rate.h" |
| 31 | #include "led.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 32 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 33 | #define IEEE80211_AUTH_TIMEOUT (HZ / 5) |
| 34 | #define IEEE80211_AUTH_MAX_TRIES 3 |
| 35 | #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5) |
| 36 | #define IEEE80211_ASSOC_TIMEOUT (HZ / 5) |
| 37 | #define IEEE80211_ASSOC_MAX_TRIES 3 |
| 38 | |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 39 | static int max_nullfunc_tries = 2; |
| 40 | module_param(max_nullfunc_tries, int, 0644); |
| 41 | MODULE_PARM_DESC(max_nullfunc_tries, |
| 42 | "Maximum nullfunc tx tries before disconnecting (reason 4)."); |
| 43 | |
| 44 | static int max_probe_tries = 5; |
| 45 | module_param(max_probe_tries, int, 0644); |
| 46 | MODULE_PARM_DESC(max_probe_tries, |
| 47 | "Maximum probe tries before disconnecting (reason 4)."); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 48 | |
| 49 | /* |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 50 | * Beacon loss timeout is calculated as N frames times the |
| 51 | * advertised beacon interval. This may need to be somewhat |
| 52 | * higher than what hardware might detect to account for |
| 53 | * delays in the host processing frames. But since we also |
| 54 | * probe on beacon miss before declaring the connection lost |
| 55 | * default to what we want. |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 56 | */ |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 57 | #define IEEE80211_BEACON_LOSS_COUNT 7 |
| 58 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 59 | /* |
| 60 | * Time the connection can be idle before we probe |
| 61 | * it to see if we can still talk to the AP. |
| 62 | */ |
Maxim Levitsky | d1c5091 | 2009-07-31 18:54:23 +0300 | [diff] [blame] | 63 | #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 64 | /* |
| 65 | * Time we wait for a probe response after sending |
| 66 | * a probe request because of beacon loss or for |
| 67 | * checking the connection still works. |
| 68 | */ |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 69 | static int probe_wait_ms = 500; |
| 70 | module_param(probe_wait_ms, int, 0644); |
| 71 | MODULE_PARM_DESC(probe_wait_ms, |
| 72 | "Maximum time(ms) to wait for probe response" |
| 73 | " before disconnecting (reason 4)."); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 74 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 75 | /* |
| 76 | * Weight given to the latest Beacon frame when calculating average signal |
| 77 | * strength for Beacon frames received in the current BSS. This must be |
| 78 | * between 1 and 15. |
| 79 | */ |
| 80 | #define IEEE80211_SIGNAL_AVE_WEIGHT 3 |
| 81 | |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 82 | /* |
| 83 | * How many Beacon frames need to have been used in average signal strength |
| 84 | * before starting to indicate signal change events. |
| 85 | */ |
| 86 | #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4 |
| 87 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 88 | #define TMR_RUNNING_TIMER 0 |
| 89 | #define TMR_RUNNING_CHANSW 1 |
| 90 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 91 | /* |
| 92 | * All cfg80211 functions have to be called outside a locked |
| 93 | * section so that they can acquire a lock themselves... This |
| 94 | * is much simpler than queuing up things in cfg80211, but we |
| 95 | * do need some indirection for that here. |
| 96 | */ |
| 97 | enum rx_mgmt_action { |
| 98 | /* no action required */ |
| 99 | RX_MGMT_NONE, |
| 100 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 101 | /* caller must call cfg80211_send_deauth() */ |
| 102 | RX_MGMT_CFG80211_DEAUTH, |
| 103 | |
| 104 | /* caller must call cfg80211_send_disassoc() */ |
| 105 | RX_MGMT_CFG80211_DISASSOC, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 106 | |
| 107 | /* caller must call cfg80211_send_rx_auth() */ |
| 108 | RX_MGMT_CFG80211_RX_AUTH, |
| 109 | |
| 110 | /* caller must call cfg80211_send_rx_assoc() */ |
| 111 | RX_MGMT_CFG80211_RX_ASSOC, |
| 112 | |
| 113 | /* caller must call cfg80211_send_assoc_timeout() */ |
| 114 | RX_MGMT_CFG80211_ASSOC_TIMEOUT, |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 115 | }; |
| 116 | |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 117 | /* utils */ |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 118 | static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd) |
| 119 | { |
Johannes Berg | 46a5eba | 2010-09-15 13:28:15 +0200 | [diff] [blame] | 120 | lockdep_assert_held(&ifmgd->mtx); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 121 | } |
| 122 | |
Johannes Berg | ca386f3 | 2009-07-10 02:39:48 +0200 | [diff] [blame] | 123 | /* |
| 124 | * We can have multiple work items (and connection probing) |
| 125 | * scheduling this timer, but we need to take care to only |
| 126 | * reschedule it when it should fire _earlier_ than it was |
| 127 | * asked for before, or if it's not pending right now. This |
| 128 | * function ensures that. Note that it then is required to |
| 129 | * run this function for all timeouts after the first one |
| 130 | * has happened -- the work that runs from this timer will |
| 131 | * do that. |
| 132 | */ |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 133 | static void run_again(struct ieee80211_if_managed *ifmgd, unsigned long timeout) |
Johannes Berg | ca386f3 | 2009-07-10 02:39:48 +0200 | [diff] [blame] | 134 | { |
| 135 | ASSERT_MGD_MTX(ifmgd); |
| 136 | |
| 137 | if (!timer_pending(&ifmgd->timer) || |
| 138 | time_before(timeout, ifmgd->timer.expires)) |
| 139 | mod_timer(&ifmgd->timer, timeout); |
| 140 | } |
| 141 | |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 142 | void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 143 | { |
Johannes Berg | c1288b1 | 2012-01-19 09:29:57 +0100 | [diff] [blame] | 144 | if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 145 | return; |
| 146 | |
Johannes Berg | 7eeff74 | 2012-07-18 10:27:27 +0200 | [diff] [blame] | 147 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
| 148 | return; |
| 149 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 150 | mod_timer(&sdata->u.mgd.bcn_mon_timer, |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 151 | round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout)); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 152 | } |
| 153 | |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 154 | void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata) |
| 155 | { |
Luis R. Rodriguez | 0c699c3 | 2010-09-16 15:12:30 -0400 | [diff] [blame] | 156 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 157 | |
Stanislaw Gruszka | 8628172 | 2011-02-25 14:46:02 +0100 | [diff] [blame] | 158 | if (unlikely(!sdata->u.mgd.associated)) |
| 159 | return; |
| 160 | |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 161 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
| 162 | return; |
| 163 | |
| 164 | mod_timer(&sdata->u.mgd.conn_mon_timer, |
| 165 | round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME)); |
Luis R. Rodriguez | 0c699c3 | 2010-09-16 15:12:30 -0400 | [diff] [blame] | 166 | |
| 167 | ifmgd->probe_send_count = 0; |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 168 | } |
| 169 | |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 170 | static int ecw2cw(int ecw) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 171 | { |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 172 | return (1 << ecw) - 1; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 173 | } |
| 174 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 175 | static u32 ieee80211_config_ht_tx(struct ieee80211_sub_if_data *sdata, |
| 176 | struct ieee80211_ht_operation *ht_oper, |
| 177 | const u8 *bssid, bool reconfig) |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 178 | { |
| 179 | struct ieee80211_local *local = sdata->local; |
| 180 | struct ieee80211_supported_band *sband; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 181 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 182 | struct ieee80211_channel *chan; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 183 | struct sta_info *sta; |
| 184 | u32 changed = 0; |
Johannes Berg | 9ed6bcc | 2009-05-08 20:47:39 +0200 | [diff] [blame] | 185 | u16 ht_opmode; |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 186 | bool disable_40 = false; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 187 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 188 | rcu_read_lock(); |
| 189 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 190 | if (WARN_ON(!chanctx_conf)) { |
| 191 | rcu_read_unlock(); |
| 192 | return 0; |
| 193 | } |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 194 | chan = chanctx_conf->def.chan; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 195 | rcu_read_unlock(); |
| 196 | sband = local->hw.wiphy->bands[chan->band]; |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 197 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 198 | switch (sdata->vif.bss_conf.chandef.width) { |
| 199 | case NL80211_CHAN_WIDTH_40: |
| 200 | if (sdata->vif.bss_conf.chandef.chan->center_freq > |
| 201 | sdata->vif.bss_conf.chandef.center_freq1 && |
| 202 | chan->flags & IEEE80211_CHAN_NO_HT40PLUS) |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 203 | disable_40 = true; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 204 | if (sdata->vif.bss_conf.chandef.chan->center_freq < |
| 205 | sdata->vif.bss_conf.chandef.center_freq1 && |
| 206 | chan->flags & IEEE80211_CHAN_NO_HT40MINUS) |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 207 | disable_40 = true; |
| 208 | break; |
| 209 | default: |
| 210 | break; |
| 211 | } |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 212 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 213 | /* This can change during the lifetime of the BSS */ |
| 214 | if (!(ht_oper->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 215 | disable_40 = true; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 216 | |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 217 | mutex_lock(&local->sta_mtx); |
| 218 | sta = sta_info_get(sdata, bssid); |
| 219 | |
| 220 | WARN_ON_ONCE(!sta); |
| 221 | |
| 222 | if (sta && !sta->supports_40mhz) |
| 223 | disable_40 = true; |
| 224 | |
| 225 | if (sta && (!reconfig || |
Rajkumar Manoharan | 91a0099 | 2012-04-25 20:24:24 +0530 | [diff] [blame] | 226 | (disable_40 != !(sta->sta.ht_cap.cap & |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 227 | IEEE80211_HT_CAP_SUP_WIDTH_20_40)))) { |
Rajkumar Manoharan | 7cc44ed | 2011-09-16 15:32:34 +0530 | [diff] [blame] | 228 | |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 229 | if (disable_40) |
| 230 | sta->sta.ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 231 | else |
| 232 | sta->sta.ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
Rajkumar Manoharan | 7cc44ed | 2011-09-16 15:32:34 +0530 | [diff] [blame] | 233 | |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 234 | rate_control_rate_update(local, sband, sta, |
Johannes Berg | 8f727ef | 2012-03-30 08:43:32 +0200 | [diff] [blame] | 235 | IEEE80211_RC_BW_CHANGED); |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 236 | } |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 237 | mutex_unlock(&local->sta_mtx); |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 238 | |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 239 | ht_opmode = le16_to_cpu(ht_oper->operation_mode); |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 240 | |
| 241 | /* if bss configuration changed store the new one */ |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 242 | if (!reconfig || (sdata->vif.bss_conf.ht_operation_mode != ht_opmode)) { |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 243 | changed |= BSS_CHANGED_HT; |
Johannes Berg | 9ed6bcc | 2009-05-08 20:47:39 +0200 | [diff] [blame] | 244 | sdata->vif.bss_conf.ht_operation_mode = ht_opmode; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | return changed; |
| 248 | } |
| 249 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 250 | /* frame sending functions */ |
| 251 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 252 | static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len, |
| 253 | struct ieee80211_supported_band *sband, |
| 254 | u32 *rates) |
| 255 | { |
| 256 | int i, j, count; |
| 257 | *rates = 0; |
| 258 | count = 0; |
| 259 | for (i = 0; i < supp_rates_len; i++) { |
| 260 | int rate = (supp_rates[i] & 0x7F) * 5; |
| 261 | |
| 262 | for (j = 0; j < sband->n_bitrates; j++) |
| 263 | if (sband->bitrates[j].bitrate == rate) { |
| 264 | *rates |= BIT(j); |
| 265 | count++; |
| 266 | break; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | return count; |
| 271 | } |
| 272 | |
| 273 | static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 274 | struct sk_buff *skb, u8 ap_ht_param, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 275 | struct ieee80211_supported_band *sband, |
| 276 | struct ieee80211_channel *channel, |
| 277 | enum ieee80211_smps_mode smps) |
| 278 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 279 | u8 *pos; |
| 280 | u32 flags = channel->flags; |
| 281 | u16 cap; |
| 282 | struct ieee80211_sta_ht_cap ht_cap; |
| 283 | |
| 284 | BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap)); |
| 285 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 286 | memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap)); |
| 287 | ieee80211_apply_htcap_overrides(sdata, &ht_cap); |
| 288 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 289 | /* determine capability flags */ |
| 290 | cap = ht_cap.cap; |
| 291 | |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 292 | switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 293 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 294 | if (flags & IEEE80211_CHAN_NO_HT40PLUS) { |
| 295 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 296 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 297 | } |
| 298 | break; |
| 299 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 300 | if (flags & IEEE80211_CHAN_NO_HT40MINUS) { |
| 301 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 302 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 303 | } |
| 304 | break; |
| 305 | } |
| 306 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 307 | /* |
| 308 | * If 40 MHz was disabled associate as though we weren't |
| 309 | * capable of 40 MHz -- some broken APs will never fall |
| 310 | * back to trying to transmit in 20 MHz. |
| 311 | */ |
| 312 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) { |
| 313 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 314 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 315 | } |
| 316 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 317 | /* set SM PS mode properly */ |
| 318 | cap &= ~IEEE80211_HT_CAP_SM_PS; |
| 319 | switch (smps) { |
| 320 | case IEEE80211_SMPS_AUTOMATIC: |
| 321 | case IEEE80211_SMPS_NUM_MODES: |
| 322 | WARN_ON(1); |
| 323 | case IEEE80211_SMPS_OFF: |
| 324 | cap |= WLAN_HT_CAP_SM_PS_DISABLED << |
| 325 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 326 | break; |
| 327 | case IEEE80211_SMPS_STATIC: |
| 328 | cap |= WLAN_HT_CAP_SM_PS_STATIC << |
| 329 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 330 | break; |
| 331 | case IEEE80211_SMPS_DYNAMIC: |
| 332 | cap |= WLAN_HT_CAP_SM_PS_DYNAMIC << |
| 333 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 334 | break; |
| 335 | } |
| 336 | |
| 337 | /* reserve and fill IE */ |
| 338 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2); |
| 339 | ieee80211_ie_build_ht_cap(pos, &ht_cap, cap); |
| 340 | } |
| 341 | |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 342 | static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata, |
| 343 | struct sk_buff *skb, |
| 344 | struct ieee80211_supported_band *sband) |
| 345 | { |
| 346 | u8 *pos; |
| 347 | u32 cap; |
| 348 | struct ieee80211_sta_vht_cap vht_cap; |
| 349 | |
| 350 | BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap)); |
| 351 | |
| 352 | memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap)); |
| 353 | |
| 354 | /* determine capability flags */ |
| 355 | cap = vht_cap.cap; |
| 356 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 357 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) { |
| 358 | cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ; |
| 359 | cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
| 360 | } |
| 361 | |
| 362 | if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) { |
| 363 | cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160; |
| 364 | cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ; |
| 365 | } |
| 366 | |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 367 | /* reserve and fill IE */ |
Mahesh Palivela | d495028 | 2012-10-10 11:25:40 +0000 | [diff] [blame] | 368 | pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 369 | ieee80211_ie_build_vht_cap(pos, &vht_cap, cap); |
| 370 | } |
| 371 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 372 | static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata) |
| 373 | { |
| 374 | struct ieee80211_local *local = sdata->local; |
| 375 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 376 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
| 377 | struct sk_buff *skb; |
| 378 | struct ieee80211_mgmt *mgmt; |
| 379 | u8 *pos, qos_info; |
| 380 | size_t offset = 0, noffset; |
| 381 | int i, count, rates_len, supp_rates_len; |
| 382 | u16 capab; |
| 383 | struct ieee80211_supported_band *sband; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 384 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 385 | struct ieee80211_channel *chan; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 386 | u32 rates = 0; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 387 | |
| 388 | lockdep_assert_held(&ifmgd->mtx); |
| 389 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 390 | rcu_read_lock(); |
| 391 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 392 | if (WARN_ON(!chanctx_conf)) { |
| 393 | rcu_read_unlock(); |
| 394 | return; |
| 395 | } |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 396 | chan = chanctx_conf->def.chan; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 397 | rcu_read_unlock(); |
| 398 | sband = local->hw.wiphy->bands[chan->band]; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 399 | |
| 400 | if (assoc_data->supp_rates_len) { |
| 401 | /* |
| 402 | * Get all rates supported by the device and the AP as |
| 403 | * some APs don't like getting a superset of their rates |
| 404 | * in the association request (e.g. D-Link DAP 1353 in |
| 405 | * b-only mode)... |
| 406 | */ |
| 407 | rates_len = ieee80211_compatible_rates(assoc_data->supp_rates, |
| 408 | assoc_data->supp_rates_len, |
| 409 | sband, &rates); |
| 410 | } else { |
| 411 | /* |
| 412 | * In case AP not provide any supported rates information |
| 413 | * before association, we send information element(s) with |
| 414 | * all rates that we support. |
| 415 | */ |
| 416 | rates = ~0; |
| 417 | rates_len = sband->n_bitrates; |
| 418 | } |
| 419 | |
| 420 | skb = alloc_skb(local->hw.extra_tx_headroom + |
| 421 | sizeof(*mgmt) + /* bit too much but doesn't matter */ |
| 422 | 2 + assoc_data->ssid_len + /* SSID */ |
| 423 | 4 + rates_len + /* (extended) rates */ |
| 424 | 4 + /* power capability */ |
| 425 | 2 + 2 * sband->n_channels + /* supported channels */ |
| 426 | 2 + sizeof(struct ieee80211_ht_cap) + /* HT */ |
Mahesh Palivela | d495028 | 2012-10-10 11:25:40 +0000 | [diff] [blame] | 427 | 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */ |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 428 | assoc_data->ie_len + /* extra IEs */ |
| 429 | 9, /* WMM */ |
| 430 | GFP_KERNEL); |
| 431 | if (!skb) |
| 432 | return; |
| 433 | |
| 434 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 435 | |
| 436 | capab = WLAN_CAPABILITY_ESS; |
| 437 | |
| 438 | if (sband->band == IEEE80211_BAND_2GHZ) { |
| 439 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)) |
| 440 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 441 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)) |
| 442 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 443 | } |
| 444 | |
| 445 | if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY) |
| 446 | capab |= WLAN_CAPABILITY_PRIVACY; |
| 447 | |
| 448 | if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && |
| 449 | (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)) |
| 450 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; |
| 451 | |
| 452 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 453 | memset(mgmt, 0, 24); |
| 454 | memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN); |
| 455 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
| 456 | memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN); |
| 457 | |
| 458 | if (!is_zero_ether_addr(assoc_data->prev_bssid)) { |
| 459 | skb_put(skb, 10); |
| 460 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 461 | IEEE80211_STYPE_REASSOC_REQ); |
| 462 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); |
| 463 | mgmt->u.reassoc_req.listen_interval = |
| 464 | cpu_to_le16(local->hw.conf.listen_interval); |
| 465 | memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid, |
| 466 | ETH_ALEN); |
| 467 | } else { |
| 468 | skb_put(skb, 4); |
| 469 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 470 | IEEE80211_STYPE_ASSOC_REQ); |
| 471 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); |
| 472 | mgmt->u.assoc_req.listen_interval = |
| 473 | cpu_to_le16(local->hw.conf.listen_interval); |
| 474 | } |
| 475 | |
| 476 | /* SSID */ |
| 477 | pos = skb_put(skb, 2 + assoc_data->ssid_len); |
| 478 | *pos++ = WLAN_EID_SSID; |
| 479 | *pos++ = assoc_data->ssid_len; |
| 480 | memcpy(pos, assoc_data->ssid, assoc_data->ssid_len); |
| 481 | |
| 482 | /* add all rates which were marked to be used above */ |
| 483 | supp_rates_len = rates_len; |
| 484 | if (supp_rates_len > 8) |
| 485 | supp_rates_len = 8; |
| 486 | |
| 487 | pos = skb_put(skb, supp_rates_len + 2); |
| 488 | *pos++ = WLAN_EID_SUPP_RATES; |
| 489 | *pos++ = supp_rates_len; |
| 490 | |
| 491 | count = 0; |
| 492 | for (i = 0; i < sband->n_bitrates; i++) { |
| 493 | if (BIT(i) & rates) { |
| 494 | int rate = sband->bitrates[i].bitrate; |
| 495 | *pos++ = (u8) (rate / 5); |
| 496 | if (++count == 8) |
| 497 | break; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | if (rates_len > count) { |
| 502 | pos = skb_put(skb, rates_len - count + 2); |
| 503 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 504 | *pos++ = rates_len - count; |
| 505 | |
| 506 | for (i++; i < sband->n_bitrates; i++) { |
| 507 | if (BIT(i) & rates) { |
| 508 | int rate = sband->bitrates[i].bitrate; |
| 509 | *pos++ = (u8) (rate / 5); |
| 510 | } |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) { |
| 515 | /* 1. power capabilities */ |
| 516 | pos = skb_put(skb, 4); |
| 517 | *pos++ = WLAN_EID_PWR_CAPABILITY; |
| 518 | *pos++ = 2; |
| 519 | *pos++ = 0; /* min tx power */ |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 520 | *pos++ = chan->max_power; /* max tx power */ |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 521 | |
| 522 | /* 2. supported channels */ |
| 523 | /* TODO: get this in reg domain format */ |
| 524 | pos = skb_put(skb, 2 * sband->n_channels + 2); |
| 525 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; |
| 526 | *pos++ = 2 * sband->n_channels; |
| 527 | for (i = 0; i < sband->n_channels; i++) { |
| 528 | *pos++ = ieee80211_frequency_to_channel( |
| 529 | sband->channels[i].center_freq); |
| 530 | *pos++ = 1; /* one channel in the subband*/ |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | /* if present, add any custom IEs that go before HT */ |
| 535 | if (assoc_data->ie_len && assoc_data->ie) { |
| 536 | static const u8 before_ht[] = { |
| 537 | WLAN_EID_SSID, |
| 538 | WLAN_EID_SUPP_RATES, |
| 539 | WLAN_EID_EXT_SUPP_RATES, |
| 540 | WLAN_EID_PWR_CAPABILITY, |
| 541 | WLAN_EID_SUPPORTED_CHANNELS, |
| 542 | WLAN_EID_RSN, |
| 543 | WLAN_EID_QOS_CAPA, |
| 544 | WLAN_EID_RRM_ENABLED_CAPABILITIES, |
| 545 | WLAN_EID_MOBILITY_DOMAIN, |
| 546 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 547 | }; |
| 548 | noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len, |
| 549 | before_ht, ARRAY_SIZE(before_ht), |
| 550 | offset); |
| 551 | pos = skb_put(skb, noffset - offset); |
| 552 | memcpy(pos, assoc_data->ie + offset, noffset - offset); |
| 553 | offset = noffset; |
| 554 | } |
| 555 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 556 | if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) && |
| 557 | !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))) |
| 558 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 559 | |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 560 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 561 | ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param, |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 562 | sband, chan, sdata->smps_mode); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 563 | |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 564 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
| 565 | ieee80211_add_vht_ie(sdata, skb, sband); |
| 566 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 567 | /* if present, add any custom non-vendor IEs that go after HT */ |
| 568 | if (assoc_data->ie_len && assoc_data->ie) { |
| 569 | noffset = ieee80211_ie_split_vendor(assoc_data->ie, |
| 570 | assoc_data->ie_len, |
| 571 | offset); |
| 572 | pos = skb_put(skb, noffset - offset); |
| 573 | memcpy(pos, assoc_data->ie + offset, noffset - offset); |
| 574 | offset = noffset; |
| 575 | } |
| 576 | |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 577 | if (assoc_data->wmm) { |
| 578 | if (assoc_data->uapsd) { |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 579 | qos_info = ifmgd->uapsd_queues; |
| 580 | qos_info |= (ifmgd->uapsd_max_sp_len << |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 581 | IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT); |
| 582 | } else { |
| 583 | qos_info = 0; |
| 584 | } |
| 585 | |
| 586 | pos = skb_put(skb, 9); |
| 587 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; |
| 588 | *pos++ = 7; /* len */ |
| 589 | *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ |
| 590 | *pos++ = 0x50; |
| 591 | *pos++ = 0xf2; |
| 592 | *pos++ = 2; /* WME */ |
| 593 | *pos++ = 0; /* WME info */ |
| 594 | *pos++ = 1; /* WME ver */ |
| 595 | *pos++ = qos_info; |
| 596 | } |
| 597 | |
| 598 | /* add any remaining custom (i.e. vendor specific here) IEs */ |
| 599 | if (assoc_data->ie_len && assoc_data->ie) { |
| 600 | noffset = assoc_data->ie_len; |
| 601 | pos = skb_put(skb, noffset - offset); |
| 602 | memcpy(pos, assoc_data->ie + offset, noffset - offset); |
| 603 | } |
| 604 | |
Johannes Berg | a1845fc | 2012-06-27 13:18:36 +0200 | [diff] [blame] | 605 | drv_mgd_prepare_tx(local, sdata); |
| 606 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 607 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 608 | ieee80211_tx_skb(sdata, skb); |
| 609 | } |
| 610 | |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 611 | void ieee80211_send_pspoll(struct ieee80211_local *local, |
| 612 | struct ieee80211_sub_if_data *sdata) |
| 613 | { |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 614 | struct ieee80211_pspoll *pspoll; |
| 615 | struct sk_buff *skb; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 616 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 617 | skb = ieee80211_pspoll_get(&local->hw, &sdata->vif); |
| 618 | if (!skb) |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 619 | return; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 620 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 621 | pspoll = (struct ieee80211_pspoll *) skb->data; |
| 622 | pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 623 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 624 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 625 | ieee80211_tx_skb(sdata, skb); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 626 | } |
| 627 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 628 | void ieee80211_send_nullfunc(struct ieee80211_local *local, |
| 629 | struct ieee80211_sub_if_data *sdata, |
| 630 | int powersave) |
| 631 | { |
| 632 | struct sk_buff *skb; |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 633 | struct ieee80211_hdr_3addr *nullfunc; |
Rajkumar Manoharan | b6f3530 | 2011-09-29 20:34:04 +0530 | [diff] [blame] | 634 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 635 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 636 | skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif); |
| 637 | if (!skb) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 638 | return; |
| 639 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 640 | nullfunc = (struct ieee80211_hdr_3addr *) skb->data; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 641 | if (powersave) |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 642 | nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 643 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 644 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
Rajkumar Manoharan | b6f3530 | 2011-09-29 20:34:04 +0530 | [diff] [blame] | 645 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
| 646 | IEEE80211_STA_CONNECTION_POLL)) |
| 647 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE; |
| 648 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 649 | ieee80211_tx_skb(sdata, skb); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 650 | } |
| 651 | |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 652 | static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local, |
| 653 | struct ieee80211_sub_if_data *sdata) |
| 654 | { |
| 655 | struct sk_buff *skb; |
| 656 | struct ieee80211_hdr *nullfunc; |
| 657 | __le16 fc; |
| 658 | |
| 659 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 660 | return; |
| 661 | |
| 662 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30); |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 663 | if (!skb) |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 664 | return; |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 665 | |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 666 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 667 | |
| 668 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30); |
| 669 | memset(nullfunc, 0, 30); |
| 670 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | |
| 671 | IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); |
| 672 | nullfunc->frame_control = fc; |
| 673 | memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN); |
| 674 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); |
| 675 | memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN); |
| 676 | memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN); |
| 677 | |
| 678 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 679 | ieee80211_tx_skb(sdata, skb); |
| 680 | } |
| 681 | |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 682 | /* spectrum management related things */ |
| 683 | static void ieee80211_chswitch_work(struct work_struct *work) |
| 684 | { |
| 685 | struct ieee80211_sub_if_data *sdata = |
| 686 | container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 687 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 688 | |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 689 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 690 | return; |
| 691 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 692 | mutex_lock(&ifmgd->mtx); |
| 693 | if (!ifmgd->associated) |
| 694 | goto out; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 695 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 696 | sdata->local->_oper_channel = sdata->local->csa_channel; |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 697 | if (!sdata->local->ops->channel_switch) { |
| 698 | /* call "hw_config" only if doing sw channel switch */ |
| 699 | ieee80211_hw_config(sdata->local, |
| 700 | IEEE80211_CONF_CHANGE_CHANNEL); |
Shahar Levi | 1ea57b1 | 2011-09-08 08:44:05 +0300 | [diff] [blame] | 701 | } else { |
| 702 | /* update the device channel directly */ |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 703 | sdata->local->hw.conf.channel = sdata->local->_oper_channel; |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 704 | } |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 705 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 706 | /* XXX: shouldn't really modify cfg80211-owned data! */ |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 707 | ifmgd->associated->channel = sdata->local->_oper_channel; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 708 | |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 709 | /* XXX: wait for a beacon first? */ |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 710 | ieee80211_wake_queues_by_reason(&sdata->local->hw, |
| 711 | IEEE80211_QUEUE_STOP_REASON_CSA); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 712 | out: |
| 713 | ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; |
| 714 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 715 | } |
| 716 | |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 717 | void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success) |
| 718 | { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 719 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 720 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 721 | |
| 722 | trace_api_chswitch_done(sdata, success); |
| 723 | if (!success) { |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 724 | sdata_info(sdata, |
| 725 | "driver channel switch failed, disconnecting\n"); |
| 726 | ieee80211_queue_work(&sdata->local->hw, |
| 727 | &ifmgd->csa_connection_drop_work); |
| 728 | } else { |
| 729 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 730 | } |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 731 | } |
| 732 | EXPORT_SYMBOL(ieee80211_chswitch_done); |
| 733 | |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 734 | static void ieee80211_chswitch_timer(unsigned long data) |
| 735 | { |
| 736 | struct ieee80211_sub_if_data *sdata = |
| 737 | (struct ieee80211_sub_if_data *) data; |
| 738 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 739 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 740 | if (sdata->local->quiescing) { |
| 741 | set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running); |
| 742 | return; |
| 743 | } |
| 744 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 745 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, |
| 749 | struct ieee80211_channel_sw_ie *sw_elem, |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 750 | struct ieee80211_bss *bss, |
| 751 | u64 timestamp) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 752 | { |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 753 | struct cfg80211_bss *cbss = |
| 754 | container_of((void *)bss, struct cfg80211_bss, priv); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 755 | struct ieee80211_channel *new_ch; |
| 756 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 757 | int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num, |
| 758 | cbss->channel->band); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 759 | struct ieee80211_chanctx *chanctx; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 760 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 761 | ASSERT_MGD_MTX(ifmgd); |
| 762 | |
| 763 | if (!ifmgd->associated) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 764 | return; |
| 765 | |
Helmut Schaa | fbe9c42 | 2009-07-23 12:14:04 +0200 | [diff] [blame] | 766 | if (sdata->local->scanning) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 767 | return; |
| 768 | |
| 769 | /* Disregard subsequent beacons if we are already running a timer |
| 770 | processing a CSA */ |
| 771 | |
| 772 | if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED) |
| 773 | return; |
| 774 | |
| 775 | new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 776 | if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED) { |
| 777 | sdata_info(sdata, |
| 778 | "AP %pM switches to unsupported channel (%d MHz), disconnecting\n", |
| 779 | ifmgd->associated->bssid, new_freq); |
| 780 | ieee80211_queue_work(&sdata->local->hw, |
| 781 | &ifmgd->csa_connection_drop_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 782 | return; |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 783 | } |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 784 | |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 785 | ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED; |
| 786 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 787 | if (sdata->local->use_chanctx) { |
| 788 | sdata_info(sdata, |
| 789 | "not handling channel switch with channel contexts\n"); |
| 790 | ieee80211_queue_work(&sdata->local->hw, |
| 791 | &ifmgd->csa_connection_drop_work); |
| 792 | } |
| 793 | |
| 794 | mutex_lock(&sdata->local->chanctx_mtx); |
| 795 | if (WARN_ON(!rcu_access_pointer(sdata->vif.chanctx_conf))) { |
| 796 | mutex_unlock(&sdata->local->chanctx_mtx); |
| 797 | return; |
| 798 | } |
| 799 | chanctx = container_of(rcu_access_pointer(sdata->vif.chanctx_conf), |
| 800 | struct ieee80211_chanctx, conf); |
| 801 | if (chanctx->refcount > 1) { |
| 802 | sdata_info(sdata, |
| 803 | "channel switch with multiple interfaces on the same channel, disconnecting\n"); |
| 804 | ieee80211_queue_work(&sdata->local->hw, |
| 805 | &ifmgd->csa_connection_drop_work); |
| 806 | mutex_unlock(&sdata->local->chanctx_mtx); |
| 807 | return; |
| 808 | } |
| 809 | mutex_unlock(&sdata->local->chanctx_mtx); |
| 810 | |
| 811 | sdata->local->csa_channel = new_ch; |
| 812 | |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 813 | if (sw_elem->mode) |
| 814 | ieee80211_stop_queues_by_reason(&sdata->local->hw, |
| 815 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 816 | |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 817 | if (sdata->local->ops->channel_switch) { |
| 818 | /* use driver's channel switch callback */ |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 819 | struct ieee80211_channel_switch ch_switch = { |
| 820 | .timestamp = timestamp, |
| 821 | .block_tx = sw_elem->mode, |
| 822 | .channel = new_ch, |
| 823 | .count = sw_elem->count, |
| 824 | }; |
| 825 | |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 826 | drv_channel_switch(sdata->local, &ch_switch); |
| 827 | return; |
| 828 | } |
| 829 | |
| 830 | /* channel switch handled in software */ |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 831 | if (sw_elem->count <= 1) |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 832 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
Johannes Berg | 57eebdf | 2012-08-01 15:50:46 +0200 | [diff] [blame] | 833 | else |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 834 | mod_timer(&ifmgd->chswitch_timer, |
Johannes Berg | 3049000 | 2012-08-01 15:53:45 +0200 | [diff] [blame] | 835 | TU_TO_EXP_TIME(sw_elem->count * |
| 836 | cbss->beacon_interval)); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 837 | } |
| 838 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 839 | static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata, |
| 840 | struct ieee80211_channel *channel, |
| 841 | const u8 *country_ie, u8 country_ie_len, |
| 842 | const u8 *pwr_constr_elem) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 843 | { |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 844 | struct ieee80211_country_ie_triplet *triplet; |
| 845 | int chan = ieee80211_frequency_to_channel(channel->center_freq); |
| 846 | int i, chan_pwr, chan_increment, new_ap_level; |
| 847 | bool have_chan_pwr = false; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 848 | |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 849 | /* Invalid IE */ |
| 850 | if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN) |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 851 | return 0; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 852 | |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 853 | triplet = (void *)(country_ie + 3); |
| 854 | country_ie_len -= 3; |
| 855 | |
| 856 | switch (channel->band) { |
| 857 | default: |
| 858 | WARN_ON_ONCE(1); |
| 859 | /* fall through */ |
| 860 | case IEEE80211_BAND_2GHZ: |
| 861 | case IEEE80211_BAND_60GHZ: |
| 862 | chan_increment = 1; |
| 863 | break; |
| 864 | case IEEE80211_BAND_5GHZ: |
| 865 | chan_increment = 4; |
| 866 | break; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 867 | } |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 868 | |
| 869 | /* find channel */ |
| 870 | while (country_ie_len >= 3) { |
| 871 | u8 first_channel = triplet->chans.first_channel; |
| 872 | |
| 873 | if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID) |
| 874 | goto next; |
| 875 | |
| 876 | for (i = 0; i < triplet->chans.num_channels; i++) { |
| 877 | if (first_channel + i * chan_increment == chan) { |
| 878 | have_chan_pwr = true; |
| 879 | chan_pwr = triplet->chans.max_power; |
| 880 | break; |
| 881 | } |
| 882 | } |
| 883 | if (have_chan_pwr) |
| 884 | break; |
| 885 | |
| 886 | next: |
| 887 | triplet++; |
| 888 | country_ie_len -= 3; |
| 889 | } |
| 890 | |
| 891 | if (!have_chan_pwr) |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 892 | return 0; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 893 | |
| 894 | new_ap_level = max_t(int, 0, chan_pwr - *pwr_constr_elem); |
| 895 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 896 | if (sdata->ap_power_level == new_ap_level) |
| 897 | return 0; |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 898 | |
| 899 | sdata_info(sdata, |
| 900 | "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n", |
| 901 | new_ap_level, chan_pwr, *pwr_constr_elem, |
| 902 | sdata->u.mgd.bssid); |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 903 | sdata->ap_power_level = new_ap_level; |
| 904 | if (__ieee80211_recalc_txpower(sdata)) |
| 905 | return BSS_CHANGED_TXPOWER; |
| 906 | return 0; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 907 | } |
| 908 | |
Juuso Oikarinen | f90754c | 2010-06-21 08:59:39 +0300 | [diff] [blame] | 909 | void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif) |
| 910 | { |
| 911 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 912 | struct ieee80211_local *local = sdata->local; |
| 913 | struct ieee80211_conf *conf = &local->hw.conf; |
| 914 | |
| 915 | WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION || |
| 916 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) || |
| 917 | (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)); |
| 918 | |
| 919 | local->disable_dynamic_ps = false; |
| 920 | conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout; |
| 921 | } |
| 922 | EXPORT_SYMBOL(ieee80211_enable_dyn_ps); |
| 923 | |
| 924 | void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif) |
| 925 | { |
| 926 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 927 | struct ieee80211_local *local = sdata->local; |
| 928 | struct ieee80211_conf *conf = &local->hw.conf; |
| 929 | |
| 930 | WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION || |
| 931 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) || |
| 932 | (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)); |
| 933 | |
| 934 | local->disable_dynamic_ps = true; |
| 935 | conf->dynamic_ps_timeout = 0; |
| 936 | del_timer_sync(&local->dynamic_ps_timer); |
| 937 | ieee80211_queue_work(&local->hw, |
| 938 | &local->dynamic_ps_enable_work); |
| 939 | } |
| 940 | EXPORT_SYMBOL(ieee80211_disable_dyn_ps); |
| 941 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 942 | /* powersave */ |
| 943 | static void ieee80211_enable_ps(struct ieee80211_local *local, |
| 944 | struct ieee80211_sub_if_data *sdata) |
| 945 | { |
| 946 | struct ieee80211_conf *conf = &local->hw.conf; |
| 947 | |
Johannes Berg | d5edaed | 2009-04-22 23:02:51 +0200 | [diff] [blame] | 948 | /* |
| 949 | * If we are scanning right now then the parameters will |
| 950 | * take effect when scan finishes. |
| 951 | */ |
Helmut Schaa | fbe9c42 | 2009-07-23 12:14:04 +0200 | [diff] [blame] | 952 | if (local->scanning) |
Johannes Berg | d5edaed | 2009-04-22 23:02:51 +0200 | [diff] [blame] | 953 | return; |
| 954 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 955 | if (conf->dynamic_ps_timeout > 0 && |
| 956 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) { |
| 957 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 958 | msecs_to_jiffies(conf->dynamic_ps_timeout)); |
| 959 | } else { |
| 960 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
| 961 | ieee80211_send_nullfunc(local, sdata, 1); |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 962 | |
Juuso Oikarinen | 2a13052 | 2010-03-09 14:25:02 +0200 | [diff] [blame] | 963 | if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) && |
| 964 | (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) |
| 965 | return; |
| 966 | |
| 967 | conf->flags |= IEEE80211_CONF_PS; |
| 968 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 969 | } |
| 970 | } |
| 971 | |
| 972 | static void ieee80211_change_ps(struct ieee80211_local *local) |
| 973 | { |
| 974 | struct ieee80211_conf *conf = &local->hw.conf; |
| 975 | |
| 976 | if (local->ps_sdata) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 977 | ieee80211_enable_ps(local, local->ps_sdata); |
| 978 | } else if (conf->flags & IEEE80211_CONF_PS) { |
| 979 | conf->flags &= ~IEEE80211_CONF_PS; |
| 980 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 981 | del_timer_sync(&local->dynamic_ps_timer); |
| 982 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 983 | } |
| 984 | } |
| 985 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 986 | static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata) |
| 987 | { |
| 988 | struct ieee80211_if_managed *mgd = &sdata->u.mgd; |
| 989 | struct sta_info *sta = NULL; |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 990 | bool authorized = false; |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 991 | |
| 992 | if (!mgd->powersave) |
| 993 | return false; |
| 994 | |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 995 | if (mgd->broken_ap) |
| 996 | return false; |
| 997 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 998 | if (!mgd->associated) |
| 999 | return false; |
| 1000 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1001 | if (mgd->flags & (IEEE80211_STA_BEACON_POLL | |
| 1002 | IEEE80211_STA_CONNECTION_POLL)) |
| 1003 | return false; |
| 1004 | |
| 1005 | rcu_read_lock(); |
| 1006 | sta = sta_info_get(sdata, mgd->bssid); |
| 1007 | if (sta) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1008 | authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1009 | rcu_read_unlock(); |
| 1010 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1011 | return authorized; |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1012 | } |
| 1013 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1014 | /* need to hold RTNL or interface lock */ |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1015 | void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1016 | { |
| 1017 | struct ieee80211_sub_if_data *sdata, *found = NULL; |
| 1018 | int count = 0; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1019 | int timeout; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1020 | |
| 1021 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) { |
| 1022 | local->ps_sdata = NULL; |
| 1023 | return; |
| 1024 | } |
| 1025 | |
| 1026 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1027 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1028 | continue; |
Rajkumar Manoharan | 8c7914d | 2011-02-01 00:28:59 +0530 | [diff] [blame] | 1029 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
| 1030 | /* If an AP vif is found, then disable PS |
| 1031 | * by setting the count to zero thereby setting |
| 1032 | * ps_sdata to NULL. |
| 1033 | */ |
| 1034 | count = 0; |
| 1035 | break; |
| 1036 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1037 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 1038 | continue; |
| 1039 | found = sdata; |
| 1040 | count++; |
| 1041 | } |
| 1042 | |
Jason Young | 808118c | 2011-03-10 16:43:19 -0800 | [diff] [blame] | 1043 | if (count == 1 && ieee80211_powersave_allowed(found)) { |
Juuso Oikarinen | f90754c | 2010-06-21 08:59:39 +0300 | [diff] [blame] | 1044 | struct ieee80211_conf *conf = &local->hw.conf; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1045 | s32 beaconint_us; |
| 1046 | |
| 1047 | if (latency < 0) |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 1048 | latency = pm_qos_request(PM_QOS_NETWORK_LATENCY); |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1049 | |
| 1050 | beaconint_us = ieee80211_tu_to_usec( |
| 1051 | found->vif.bss_conf.beacon_int); |
| 1052 | |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 1053 | timeout = local->dynamic_ps_forced_timeout; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1054 | if (timeout < 0) { |
| 1055 | /* |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 1056 | * Go to full PSM if the user configures a very low |
| 1057 | * latency requirement. |
Eliad Peller | 0ab82b0 | 2010-12-03 02:16:23 +0200 | [diff] [blame] | 1058 | * The 2000 second value is there for compatibility |
| 1059 | * until the PM_QOS_NETWORK_LATENCY is configured |
| 1060 | * with real values. |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1061 | */ |
Eliad Peller | 0ab82b0 | 2010-12-03 02:16:23 +0200 | [diff] [blame] | 1062 | if (latency > (1900 * USEC_PER_MSEC) && |
| 1063 | latency != (2000 * USEC_PER_SEC)) |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1064 | timeout = 0; |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 1065 | else |
| 1066 | timeout = 100; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1067 | } |
Juuso Oikarinen | f90754c | 2010-06-21 08:59:39 +0300 | [diff] [blame] | 1068 | local->dynamic_ps_user_timeout = timeout; |
| 1069 | if (!local->disable_dynamic_ps) |
| 1070 | conf->dynamic_ps_timeout = |
| 1071 | local->dynamic_ps_user_timeout; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 1072 | |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 1073 | if (beaconint_us > latency) { |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1074 | local->ps_sdata = NULL; |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 1075 | } else { |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 1076 | struct ieee80211_bss *bss; |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 1077 | int maxslp = 1; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 1078 | u8 dtimper; |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 1079 | |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 1080 | bss = (void *)found->u.mgd.associated->priv; |
| 1081 | dtimper = bss->dtim_period; |
| 1082 | |
| 1083 | /* If the TIM IE is invalid, pretend the value is 1 */ |
| 1084 | if (!dtimper) |
| 1085 | dtimper = 1; |
| 1086 | else if (dtimper > 1) |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 1087 | maxslp = min_t(int, dtimper, |
| 1088 | latency / beaconint_us); |
| 1089 | |
Johannes Berg | 9ccebe6 | 2009-04-23 10:32:36 +0200 | [diff] [blame] | 1090 | local->hw.conf.max_sleep_period = maxslp; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 1091 | local->hw.conf.ps_dtim_period = dtimper; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1092 | local->ps_sdata = found; |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 1093 | } |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1094 | } else { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1095 | local->ps_sdata = NULL; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 1096 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1097 | |
| 1098 | ieee80211_change_ps(local); |
| 1099 | } |
| 1100 | |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 1101 | void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata) |
| 1102 | { |
| 1103 | bool ps_allowed = ieee80211_powersave_allowed(sdata); |
| 1104 | |
| 1105 | if (sdata->vif.bss_conf.ps != ps_allowed) { |
| 1106 | sdata->vif.bss_conf.ps = ps_allowed; |
| 1107 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS); |
| 1108 | } |
| 1109 | } |
| 1110 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1111 | void ieee80211_dynamic_ps_disable_work(struct work_struct *work) |
| 1112 | { |
| 1113 | struct ieee80211_local *local = |
| 1114 | container_of(work, struct ieee80211_local, |
| 1115 | dynamic_ps_disable_work); |
| 1116 | |
| 1117 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 1118 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 1119 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1120 | } |
| 1121 | |
| 1122 | ieee80211_wake_queues_by_reason(&local->hw, |
| 1123 | IEEE80211_QUEUE_STOP_REASON_PS); |
| 1124 | } |
| 1125 | |
| 1126 | void ieee80211_dynamic_ps_enable_work(struct work_struct *work) |
| 1127 | { |
| 1128 | struct ieee80211_local *local = |
| 1129 | container_of(work, struct ieee80211_local, |
| 1130 | dynamic_ps_enable_work); |
| 1131 | struct ieee80211_sub_if_data *sdata = local->ps_sdata; |
Christian Lamparter | 5e34069 | 2011-06-30 21:08:43 +0200 | [diff] [blame] | 1132 | struct ieee80211_if_managed *ifmgd; |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1133 | unsigned long flags; |
| 1134 | int q; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1135 | |
| 1136 | /* can only happen when PS was just disabled anyway */ |
| 1137 | if (!sdata) |
| 1138 | return; |
| 1139 | |
Christian Lamparter | 5e34069 | 2011-06-30 21:08:43 +0200 | [diff] [blame] | 1140 | ifmgd = &sdata->u.mgd; |
| 1141 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1142 | if (local->hw.conf.flags & IEEE80211_CONF_PS) |
| 1143 | return; |
| 1144 | |
Arik Nemtsov | 77b7023 | 2011-06-26 12:06:54 +0300 | [diff] [blame] | 1145 | if (!local->disable_dynamic_ps && |
| 1146 | local->hw.conf.dynamic_ps_timeout > 0) { |
| 1147 | /* don't enter PS if TX frames are pending */ |
| 1148 | if (drv_tx_frames_pending(local)) { |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1149 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1150 | msecs_to_jiffies( |
| 1151 | local->hw.conf.dynamic_ps_timeout)); |
| 1152 | return; |
| 1153 | } |
Arik Nemtsov | 77b7023 | 2011-06-26 12:06:54 +0300 | [diff] [blame] | 1154 | |
| 1155 | /* |
| 1156 | * transmission can be stopped by others which leads to |
| 1157 | * dynamic_ps_timer expiry. Postpone the ps timer if it |
| 1158 | * is not the actual idle state. |
| 1159 | */ |
| 1160 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 1161 | for (q = 0; q < local->hw.queues; q++) { |
| 1162 | if (local->queue_stop_reasons[q]) { |
| 1163 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, |
| 1164 | flags); |
| 1165 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1166 | msecs_to_jiffies( |
| 1167 | local->hw.conf.dynamic_ps_timeout)); |
| 1168 | return; |
| 1169 | } |
| 1170 | } |
| 1171 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1172 | } |
Rajkumar Manoharan | 1ddc286 | 2011-05-03 17:03:59 +0530 | [diff] [blame] | 1173 | |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 1174 | if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) && |
Mohammed Shafi Shajakhan | 9c38a8b | 2011-12-14 19:46:07 +0530 | [diff] [blame] | 1175 | !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
Vivek Natarajan | f3e85b9 | 2011-02-23 13:04:32 +0530 | [diff] [blame] | 1176 | netif_tx_stop_all_queues(sdata->dev); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1177 | |
Vivek Natarajan | e8306f9 | 2011-04-06 11:41:10 +0530 | [diff] [blame] | 1178 | if (drv_tx_frames_pending(local)) |
| 1179 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 1180 | msecs_to_jiffies( |
| 1181 | local->hw.conf.dynamic_ps_timeout)); |
| 1182 | else { |
| 1183 | ieee80211_send_nullfunc(local, sdata, 1); |
| 1184 | /* Flush to get the tx status of nullfunc frame */ |
| 1185 | drv_flush(local, false); |
| 1186 | } |
Vivek Natarajan | f3e85b9 | 2011-02-23 13:04:32 +0530 | [diff] [blame] | 1187 | } |
| 1188 | |
Juuso Oikarinen | 2a13052 | 2010-03-09 14:25:02 +0200 | [diff] [blame] | 1189 | if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) && |
| 1190 | (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) || |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 1191 | (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
| 1192 | ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; |
| 1193 | local->hw.conf.flags |= IEEE80211_CONF_PS; |
| 1194 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1195 | } |
Vivek Natarajan | f3e85b9 | 2011-02-23 13:04:32 +0530 | [diff] [blame] | 1196 | |
Arik Nemtsov | 77b7023 | 2011-06-26 12:06:54 +0300 | [diff] [blame] | 1197 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
| 1198 | netif_tx_wake_all_queues(sdata->dev); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | void ieee80211_dynamic_ps_timer(unsigned long data) |
| 1202 | { |
| 1203 | struct ieee80211_local *local = (void *) data; |
| 1204 | |
Luis R. Rodriguez | 78f1a8b | 2009-07-27 08:38:25 -0700 | [diff] [blame] | 1205 | if (local->quiescing || local->suspended) |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 1206 | return; |
| 1207 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 1208 | ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 1209 | } |
| 1210 | |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1211 | /* MLME */ |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1212 | static bool ieee80211_sta_wmm_params(struct ieee80211_local *local, |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 1213 | struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1214 | u8 *wmm_param, size_t wmm_param_len) |
| 1215 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1216 | struct ieee80211_tx_queue_params params; |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 1217 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1218 | size_t left; |
| 1219 | int count; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1220 | u8 *pos, uapsd_queues = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1221 | |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 1222 | if (!local->ops->conf_tx) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1223 | return false; |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 1224 | |
Johannes Berg | 32c5057 | 2012-03-28 11:04:29 +0200 | [diff] [blame] | 1225 | if (local->hw.queues < IEEE80211_NUM_ACS) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1226 | return false; |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 1227 | |
| 1228 | if (!wmm_param) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1229 | return false; |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 1230 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1231 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1232 | return false; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1233 | |
| 1234 | if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 1235 | uapsd_queues = ifmgd->uapsd_queues; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1236 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1237 | count = wmm_param[6] & 0x0f; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1238 | if (count == ifmgd->wmm_last_param_set) |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1239 | return false; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1240 | ifmgd->wmm_last_param_set = count; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1241 | |
| 1242 | pos = wmm_param + 8; |
| 1243 | left = wmm_param_len - 8; |
| 1244 | |
| 1245 | memset(¶ms, 0, sizeof(params)); |
| 1246 | |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 1247 | sdata->wmm_acm = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1248 | for (; left >= 4; left -= 4, pos += 4) { |
| 1249 | int aci = (pos[0] >> 5) & 0x03; |
| 1250 | int acm = (pos[0] >> 4) & 0x01; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1251 | bool uapsd = false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1252 | int queue; |
| 1253 | |
| 1254 | switch (aci) { |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 1255 | case 1: /* AC_BK */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 1256 | queue = 3; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 1257 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 1258 | sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1259 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
| 1260 | uapsd = true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1261 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 1262 | case 2: /* AC_VI */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 1263 | queue = 1; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 1264 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 1265 | sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1266 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
| 1267 | uapsd = true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1268 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 1269 | case 3: /* AC_VO */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 1270 | queue = 0; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 1271 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 1272 | sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1273 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
| 1274 | uapsd = true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1275 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 1276 | case 0: /* AC_BE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1277 | default: |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 1278 | queue = 2; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 1279 | if (acm) |
Yoni Divinsky | 00e96de | 2012-06-20 15:39:13 +0300 | [diff] [blame] | 1280 | sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1281 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
| 1282 | uapsd = true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1283 | break; |
| 1284 | } |
| 1285 | |
| 1286 | params.aifs = pos[0] & 0x0f; |
| 1287 | params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); |
| 1288 | params.cw_min = ecw2cw(pos[1] & 0x0f); |
Johannes Berg | f434b2d | 2008-07-10 11:22:31 +0200 | [diff] [blame] | 1289 | params.txop = get_unaligned_le16(pos + 2); |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 1290 | params.uapsd = uapsd; |
| 1291 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1292 | mlme_dbg(sdata, |
| 1293 | "WMM queue=%d aci=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d\n", |
| 1294 | queue, aci, acm, |
| 1295 | params.aifs, params.cw_min, params.cw_max, |
| 1296 | params.txop, params.uapsd); |
Eliad Peller | f6f3def | 2011-09-25 20:06:54 +0300 | [diff] [blame] | 1297 | sdata->tx_conf[queue] = params; |
| 1298 | if (drv_conf_tx(local, sdata, queue, ¶ms)) |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1299 | sdata_err(sdata, |
| 1300 | "failed to set TX queue parameters for queue %d\n", |
| 1301 | queue); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1302 | } |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 1303 | |
| 1304 | /* enable WMM or activate new settings */ |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 1305 | sdata->vif.bss_conf.qos = true; |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 1306 | return true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 1309 | static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) |
| 1310 | { |
| 1311 | lockdep_assert_held(&sdata->local->mtx); |
| 1312 | |
| 1313 | sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL | |
| 1314 | IEEE80211_STA_BEACON_POLL); |
| 1315 | ieee80211_run_deferred_scan(sdata->local); |
| 1316 | } |
| 1317 | |
| 1318 | static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata) |
| 1319 | { |
| 1320 | mutex_lock(&sdata->local->mtx); |
| 1321 | __ieee80211_stop_poll(sdata); |
| 1322 | mutex_unlock(&sdata->local->mtx); |
| 1323 | } |
| 1324 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1325 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, |
| 1326 | u16 capab, bool erp_valid, u8 erp) |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1327 | { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1328 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1329 | u32 changed = 0; |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1330 | bool use_protection; |
| 1331 | bool use_short_preamble; |
| 1332 | bool use_short_slot; |
| 1333 | |
| 1334 | if (erp_valid) { |
| 1335 | use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0; |
| 1336 | use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0; |
| 1337 | } else { |
| 1338 | use_protection = false; |
| 1339 | use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE); |
| 1340 | } |
| 1341 | |
| 1342 | use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1343 | if (ieee80211_get_sdata_band(sdata) == IEEE80211_BAND_5GHZ) |
Felix Fietkau | 43d3534 | 2010-01-15 03:00:48 +0100 | [diff] [blame] | 1344 | use_short_slot = true; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1345 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1346 | if (use_protection != bss_conf->use_cts_prot) { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1347 | bss_conf->use_cts_prot = use_protection; |
| 1348 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 1349 | } |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1350 | |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 1351 | if (use_short_preamble != bss_conf->use_short_preamble) { |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 1352 | bss_conf->use_short_preamble = use_short_preamble; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1353 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1354 | } |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 1355 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1356 | if (use_short_slot != bss_conf->use_short_slot) { |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1357 | bss_conf->use_short_slot = use_short_slot; |
| 1358 | changed |= BSS_CHANGED_ERP_SLOT; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | return changed; |
| 1362 | } |
| 1363 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1364 | static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1365 | struct cfg80211_bss *cbss, |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1366 | u32 bss_info_changed) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1367 | { |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1368 | struct ieee80211_bss *bss = (void *)cbss->priv; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1369 | struct ieee80211_local *local = sdata->local; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 1370 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1371 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1372 | bss_info_changed |= BSS_CHANGED_ASSOC; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1373 | bss_info_changed |= ieee80211_handle_bss_capability(sdata, |
Luciano Coelho | 50ae34a | 2012-06-20 17:23:24 +0300 | [diff] [blame] | 1374 | bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value); |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 1375 | |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 1376 | sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec( |
| 1377 | IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int)); |
| 1378 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1379 | sdata->u.mgd.associated = cbss; |
| 1380 | memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1381 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 1382 | sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE; |
| 1383 | |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 1384 | if (sdata->vif.p2p) { |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 1385 | const struct cfg80211_bss_ies *ies; |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 1386 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 1387 | rcu_read_lock(); |
| 1388 | ies = rcu_dereference(cbss->ies); |
| 1389 | if (ies) { |
| 1390 | u8 noa[2]; |
| 1391 | int ret; |
| 1392 | |
| 1393 | ret = cfg80211_get_p2p_attr( |
| 1394 | ies->data, ies->len, |
| 1395 | IEEE80211_P2P_ATTR_ABSENCE_NOTICE, |
| 1396 | noa, sizeof(noa)); |
| 1397 | if (ret >= 2) { |
| 1398 | bss_conf->p2p_oppps = noa[1] & 0x80; |
| 1399 | bss_conf->p2p_ctwindow = noa[1] & 0x7f; |
| 1400 | bss_info_changed |= BSS_CHANGED_P2P_PS; |
| 1401 | sdata->u.mgd.p2p_noa_index = noa[0]; |
| 1402 | } |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 1403 | } |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 1404 | rcu_read_unlock(); |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 1405 | } |
| 1406 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1407 | /* just to be sure */ |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 1408 | ieee80211_stop_poll(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1409 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1410 | ieee80211_led_assoc(local, 1); |
| 1411 | |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 1412 | if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD) |
| 1413 | bss_conf->dtim_period = bss->dtim_period; |
| 1414 | else |
| 1415 | bss_conf->dtim_period = 0; |
| 1416 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 1417 | bss_conf->assoc = 1; |
Johannes Berg | 9cef873 | 2009-05-14 13:10:14 +0200 | [diff] [blame] | 1418 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 1419 | /* Tell the driver to monitor connection quality (if supported) */ |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 1420 | if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI && |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 1421 | bss_conf->cqm_rssi_thold) |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 1422 | bss_info_changed |= BSS_CHANGED_CQM; |
| 1423 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 1424 | /* Enable ARP filtering */ |
| 1425 | if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) { |
| 1426 | bss_conf->arp_filter_enabled = sdata->arp_filter_state; |
| 1427 | bss_info_changed |= BSS_CHANGED_ARP_FILTER; |
| 1428 | } |
| 1429 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1430 | ieee80211_bss_info_change_notify(sdata, bss_info_changed); |
Guy Cohen | 8db9369 | 2008-07-03 19:56:13 +0300 | [diff] [blame] | 1431 | |
Johannes Berg | 056508d | 2009-07-30 21:43:55 +0200 | [diff] [blame] | 1432 | mutex_lock(&local->iflist_mtx); |
| 1433 | ieee80211_recalc_ps(local, -1); |
| 1434 | mutex_unlock(&local->iflist_mtx); |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 1435 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 1436 | ieee80211_recalc_smps(sdata); |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 1437 | ieee80211_recalc_ps_vif(sdata); |
| 1438 | |
John W. Linville | 8a5b33f | 2010-01-06 15:39:39 -0500 | [diff] [blame] | 1439 | netif_tx_start_all_queues(sdata->dev); |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1440 | netif_carrier_on(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1441 | } |
| 1442 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 1443 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 1444 | u16 stype, u16 reason, bool tx, |
| 1445 | u8 *frame_buf) |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1446 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1447 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1448 | struct ieee80211_local *local = sdata->local; |
| 1449 | struct sta_info *sta; |
Johannes Berg | 3cc5240 | 2012-03-09 13:12:35 +0100 | [diff] [blame] | 1450 | u32 changed = 0; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1451 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1452 | ASSERT_MGD_MTX(ifmgd); |
| 1453 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 1454 | if (WARN_ON_ONCE(tx && !frame_buf)) |
| 1455 | return; |
| 1456 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1457 | if (WARN_ON(!ifmgd->associated)) |
| 1458 | return; |
| 1459 | |
David Spinadel | 79543d8 | 2012-06-12 09:59:45 +0300 | [diff] [blame] | 1460 | ieee80211_stop_poll(sdata); |
| 1461 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1462 | ifmgd->associated = NULL; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1463 | |
| 1464 | /* |
| 1465 | * we need to commit the associated = NULL change because the |
| 1466 | * scan code uses that to determine whether this iface should |
| 1467 | * go to/wake up from powersave or not -- and could otherwise |
| 1468 | * wake the queues erroneously. |
| 1469 | */ |
| 1470 | smp_mb(); |
| 1471 | |
| 1472 | /* |
| 1473 | * Thus, we can only afterwards stop the queues -- to account |
| 1474 | * for the case where another CPU is finishing a scan at this |
| 1475 | * time -- we don't want the scan code to enable queues. |
| 1476 | */ |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1477 | |
John W. Linville | 8a5b33f | 2010-01-06 15:39:39 -0500 | [diff] [blame] | 1478 | netif_tx_stop_all_queues(sdata->dev); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1479 | netif_carrier_off(sdata->dev); |
| 1480 | |
Johannes Berg | 2a41905 | 2010-06-10 10:21:29 +0200 | [diff] [blame] | 1481 | mutex_lock(&local->sta_mtx); |
Eliad Peller | 88a9e31 | 2012-06-01 11:14:03 +0300 | [diff] [blame] | 1482 | sta = sta_info_get(sdata, ifmgd->bssid); |
Sujith | 4cad6c7 | 2010-02-10 14:52:21 +0530 | [diff] [blame] | 1483 | if (sta) { |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 1484 | set_sta_flag(sta, WLAN_STA_BLOCK_BA); |
Johannes Berg | 7f16114 | 2012-07-18 12:53:34 +0200 | [diff] [blame] | 1485 | ieee80211_sta_tear_down_BA_sessions(sta, false); |
Sujith | 4cad6c7 | 2010-02-10 14:52:21 +0530 | [diff] [blame] | 1486 | } |
Johannes Berg | 2a41905 | 2010-06-10 10:21:29 +0200 | [diff] [blame] | 1487 | mutex_unlock(&local->sta_mtx); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1488 | |
Eliad Peller | 88bc40e | 2012-07-12 17:35:33 +0300 | [diff] [blame] | 1489 | /* |
| 1490 | * if we want to get out of ps before disassoc (why?) we have |
| 1491 | * to do it before sending disassoc, as otherwise the null-packet |
| 1492 | * won't be valid. |
| 1493 | */ |
| 1494 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 1495 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 1496 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 1497 | } |
| 1498 | local->ps_sdata = NULL; |
| 1499 | |
Eliad Peller | ab09587 | 2012-07-27 12:33:22 +0300 | [diff] [blame] | 1500 | /* disable per-vif ps */ |
| 1501 | ieee80211_recalc_ps_vif(sdata); |
| 1502 | |
Eliad Peller | f823981 | 2012-06-27 14:18:22 +0300 | [diff] [blame] | 1503 | /* flush out any pending frame (e.g. DELBA) before deauth/disassoc */ |
| 1504 | if (tx) |
| 1505 | drv_flush(local, false); |
| 1506 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 1507 | /* deauthenticate/disassociate now */ |
| 1508 | if (tx || frame_buf) |
Eliad Peller | 88a9e31 | 2012-06-01 11:14:03 +0300 | [diff] [blame] | 1509 | ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype, |
| 1510 | reason, tx, frame_buf); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 1511 | |
| 1512 | /* flush out frame */ |
| 1513 | if (tx) |
| 1514 | drv_flush(local, false); |
| 1515 | |
Eliad Peller | 88a9e31 | 2012-06-01 11:14:03 +0300 | [diff] [blame] | 1516 | /* clear bssid only after building the needed mgmt frames */ |
| 1517 | memset(ifmgd->bssid, 0, ETH_ALEN); |
| 1518 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 1519 | /* remove AP and TDLS peers */ |
| 1520 | sta_info_flush(local, sdata); |
| 1521 | |
| 1522 | /* finally reset all BSS / config parameters */ |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1523 | changed |= ieee80211_reset_erp_info(sdata); |
| 1524 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1525 | ieee80211_led_assoc(local, 0); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1526 | changed |= BSS_CHANGED_ASSOC; |
| 1527 | sdata->vif.bss_conf.assoc = false; |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1528 | |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 1529 | sdata->vif.bss_conf.p2p_ctwindow = 0; |
| 1530 | sdata->vif.bss_conf.p2p_oppps = false; |
| 1531 | |
Johannes Berg | 413ad50 | 2009-05-08 21:21:06 +0200 | [diff] [blame] | 1532 | /* on the next assoc, re-program HT parameters */ |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 1533 | memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa)); |
| 1534 | memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask)); |
Johannes Berg | 413ad50 | 2009-05-08 21:21:06 +0200 | [diff] [blame] | 1535 | |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 1536 | sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL; |
Vasanthakumar Thiagarajan | a8302de | 2009-01-09 18:14:15 +0530 | [diff] [blame] | 1537 | |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 1538 | del_timer_sync(&local->dynamic_ps_timer); |
| 1539 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 1540 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 1541 | /* Disable ARP filtering */ |
| 1542 | if (sdata->vif.bss_conf.arp_filter_enabled) { |
| 1543 | sdata->vif.bss_conf.arp_filter_enabled = false; |
| 1544 | changed |= BSS_CHANGED_ARP_FILTER; |
| 1545 | } |
| 1546 | |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 1547 | sdata->vif.bss_conf.qos = false; |
| 1548 | changed |= BSS_CHANGED_QOS; |
| 1549 | |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 1550 | /* The BSSID (not really interesting) and HT changed */ |
| 1551 | changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1552 | ieee80211_bss_info_change_notify(sdata, changed); |
Tomas Winkler | 8e268e4 | 2008-11-25 13:05:44 +0200 | [diff] [blame] | 1553 | |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 1554 | /* disassociated - set to defaults now */ |
| 1555 | ieee80211_set_wmm_default(sdata, false); |
| 1556 | |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 1557 | del_timer_sync(&sdata->u.mgd.conn_mon_timer); |
| 1558 | del_timer_sync(&sdata->u.mgd.bcn_mon_timer); |
| 1559 | del_timer_sync(&sdata->u.mgd.timer); |
| 1560 | del_timer_sync(&sdata->u.mgd.chswitch_timer); |
Johannes Berg | 2d9957c | 2012-08-01 20:54:52 +0200 | [diff] [blame] | 1561 | |
| 1562 | sdata->u.mgd.timers_running = 0; |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 1563 | |
| 1564 | ifmgd->flags = 0; |
| 1565 | ieee80211_vif_release_channel(sdata); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1566 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1567 | |
Kalle Valo | 3cf335d | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 1568 | void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, |
| 1569 | struct ieee80211_hdr *hdr) |
| 1570 | { |
| 1571 | /* |
| 1572 | * We can postpone the mgd.timer whenever receiving unicast frames |
| 1573 | * from AP because we know that the connection is working both ways |
| 1574 | * at that time. But multicast frames (and hence also beacons) must |
| 1575 | * be ignored here, because we need to trigger the timer during |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1576 | * data idle periods for sending the periodic probe request to the |
| 1577 | * AP we're connected to. |
Kalle Valo | 3cf335d | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 1578 | */ |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1579 | if (is_multicast_ether_addr(hdr->addr1)) |
| 1580 | return; |
| 1581 | |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 1582 | ieee80211_sta_reset_conn_monitor(sdata); |
Kalle Valo | 3cf335d | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 1583 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1584 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1585 | static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata) |
| 1586 | { |
| 1587 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1588 | struct ieee80211_local *local = sdata->local; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1589 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1590 | mutex_lock(&local->mtx); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1591 | if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1592 | IEEE80211_STA_CONNECTION_POLL))) { |
| 1593 | mutex_unlock(&local->mtx); |
| 1594 | return; |
| 1595 | } |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1596 | |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 1597 | __ieee80211_stop_poll(sdata); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1598 | |
| 1599 | mutex_lock(&local->iflist_mtx); |
| 1600 | ieee80211_recalc_ps(local, -1); |
| 1601 | mutex_unlock(&local->iflist_mtx); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1602 | |
| 1603 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1604 | goto out; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1605 | |
| 1606 | /* |
| 1607 | * We've received a probe response, but are not sure whether |
| 1608 | * we have or will be receiving any beacons or data, so let's |
| 1609 | * schedule the timers again, just in case. |
| 1610 | */ |
| 1611 | ieee80211_sta_reset_beacon_monitor(sdata); |
| 1612 | |
| 1613 | mod_timer(&ifmgd->conn_mon_timer, |
| 1614 | round_jiffies_up(jiffies + |
| 1615 | IEEE80211_CONNECTION_IDLE_TIME)); |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1616 | out: |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1617 | mutex_unlock(&local->mtx); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata, |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1621 | struct ieee80211_hdr *hdr, bool ack) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1622 | { |
Felix Fietkau | 75706d0 | 2010-12-02 21:01:07 +0100 | [diff] [blame] | 1623 | if (!ieee80211_is_data(hdr->frame_control)) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1624 | return; |
| 1625 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1626 | if (ack) |
| 1627 | ieee80211_sta_reset_conn_monitor(sdata); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1628 | |
| 1629 | if (ieee80211_is_nullfunc(hdr->frame_control) && |
| 1630 | sdata->u.mgd.probe_send_count > 0) { |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1631 | if (ack) |
| 1632 | sdata->u.mgd.probe_send_count = 0; |
| 1633 | else |
| 1634 | sdata->u.mgd.nullfunc_failed = true; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1635 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
| 1636 | } |
| 1637 | } |
| 1638 | |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1639 | static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata) |
| 1640 | { |
| 1641 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1642 | const u8 *ssid; |
Luis R. Rodriguez | f01a067 | 2010-09-16 15:12:34 -0400 | [diff] [blame] | 1643 | u8 *dst = ifmgd->associated->bssid; |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 1644 | u8 unicast_limit = max(1, max_probe_tries - 3); |
Luis R. Rodriguez | f01a067 | 2010-09-16 15:12:34 -0400 | [diff] [blame] | 1645 | |
| 1646 | /* |
| 1647 | * Try sending broadcast probe requests for the last three |
| 1648 | * probe requests after the first ones failed since some |
| 1649 | * buggy APs only support broadcast probe requests. |
| 1650 | */ |
| 1651 | if (ifmgd->probe_send_count >= unicast_limit) |
| 1652 | dst = NULL; |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1653 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1654 | /* |
| 1655 | * When the hardware reports an accurate Tx ACK status, it's |
| 1656 | * better to send a nullfunc frame instead of a probe request, |
| 1657 | * as it will kick us off the AP quickly if we aren't associated |
| 1658 | * anymore. The timeout will be reset if the frame is ACKed by |
| 1659 | * the AP. |
| 1660 | */ |
Soumik Das | 992e68b | 2012-05-20 15:31:13 +0530 | [diff] [blame] | 1661 | ifmgd->probe_send_count++; |
| 1662 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1663 | if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) { |
| 1664 | ifmgd->nullfunc_failed = false; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1665 | ieee80211_send_nullfunc(sdata->local, sdata, 0); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1666 | } else { |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 1667 | int ssid_len; |
| 1668 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 1669 | rcu_read_lock(); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1670 | ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID); |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 1671 | if (WARN_ON_ONCE(ssid == NULL)) |
| 1672 | ssid_len = 0; |
| 1673 | else |
| 1674 | ssid_len = ssid[1]; |
| 1675 | |
| 1676 | ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid_len, NULL, |
Johannes Berg | fe94fe0 | 2012-07-30 12:26:34 +0200 | [diff] [blame] | 1677 | 0, (u32) -1, true, false, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1678 | ifmgd->associated->channel, false); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 1679 | rcu_read_unlock(); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1680 | } |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1681 | |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 1682 | ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1683 | run_again(ifmgd, ifmgd->probe_timeout); |
Rajkumar Manoharan | f69b9c7 | 2012-03-15 06:15:26 +0530 | [diff] [blame] | 1684 | if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) |
| 1685 | drv_flush(sdata->local, false); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1686 | } |
| 1687 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1688 | static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata, |
| 1689 | bool beacon) |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1690 | { |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1691 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1692 | bool already = false; |
Johannes Berg | 34bfc41 | 2009-05-12 19:58:12 +0200 | [diff] [blame] | 1693 | |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1694 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 0e2b628 | 2009-07-13 13:23:39 +0200 | [diff] [blame] | 1695 | return; |
| 1696 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1697 | mutex_lock(&ifmgd->mtx); |
| 1698 | |
| 1699 | if (!ifmgd->associated) |
| 1700 | goto out; |
| 1701 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1702 | mutex_lock(&sdata->local->mtx); |
| 1703 | |
| 1704 | if (sdata->local->tmp_channel || sdata->local->scanning) { |
| 1705 | mutex_unlock(&sdata->local->mtx); |
| 1706 | goto out; |
| 1707 | } |
| 1708 | |
Joe Perches | e87cc47 | 2012-05-13 21:56:26 +0000 | [diff] [blame] | 1709 | if (beacon) |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1710 | mlme_dbg_ratelimited(sdata, |
| 1711 | "detected beacon loss from AP - sending probe request\n"); |
| 1712 | |
Holger Schurig | 6efb71b | 2012-05-15 15:38:59 +0200 | [diff] [blame] | 1713 | ieee80211_cqm_rssi_notify(&sdata->vif, |
| 1714 | NL80211_CQM_RSSI_BEACON_LOSS_EVENT, GFP_KERNEL); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1715 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1716 | /* |
| 1717 | * The driver/our work has already reported this event or the |
| 1718 | * connection monitoring has kicked in and we have already sent |
| 1719 | * a probe request. Or maybe the AP died and the driver keeps |
| 1720 | * reporting until we disassociate... |
| 1721 | * |
| 1722 | * In either case we have to ignore the current call to this |
| 1723 | * function (except for setting the correct probe reason bit) |
| 1724 | * because otherwise we would reset the timer every time and |
| 1725 | * never check whether we received a probe response! |
| 1726 | */ |
| 1727 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
| 1728 | IEEE80211_STA_CONNECTION_POLL)) |
| 1729 | already = true; |
| 1730 | |
| 1731 | if (beacon) |
| 1732 | ifmgd->flags |= IEEE80211_STA_BEACON_POLL; |
| 1733 | else |
| 1734 | ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL; |
| 1735 | |
Stanislaw Gruszka | 133d40f | 2012-03-28 16:01:19 +0200 | [diff] [blame] | 1736 | mutex_unlock(&sdata->local->mtx); |
| 1737 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1738 | if (already) |
| 1739 | goto out; |
| 1740 | |
Johannes Berg | 4e75184 | 2009-06-10 15:16:52 +0200 | [diff] [blame] | 1741 | mutex_lock(&sdata->local->iflist_mtx); |
| 1742 | ieee80211_recalc_ps(sdata->local, -1); |
| 1743 | mutex_unlock(&sdata->local->iflist_mtx); |
| 1744 | |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1745 | ifmgd->probe_send_count = 0; |
| 1746 | ieee80211_mgd_probe_ap_send(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1747 | out: |
| 1748 | mutex_unlock(&ifmgd->mtx); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1749 | } |
| 1750 | |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 1751 | struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw, |
| 1752 | struct ieee80211_vif *vif) |
| 1753 | { |
| 1754 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1755 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 1756 | struct cfg80211_bss *cbss; |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 1757 | struct sk_buff *skb; |
| 1758 | const u8 *ssid; |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 1759 | int ssid_len; |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 1760 | |
| 1761 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 1762 | return NULL; |
| 1763 | |
| 1764 | ASSERT_MGD_MTX(ifmgd); |
| 1765 | |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 1766 | if (ifmgd->associated) |
| 1767 | cbss = ifmgd->associated; |
| 1768 | else if (ifmgd->auth_data) |
| 1769 | cbss = ifmgd->auth_data->bss; |
| 1770 | else if (ifmgd->assoc_data) |
| 1771 | cbss = ifmgd->assoc_data->bss; |
| 1772 | else |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 1773 | return NULL; |
| 1774 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 1775 | rcu_read_lock(); |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 1776 | ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID); |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 1777 | if (WARN_ON_ONCE(ssid == NULL)) |
| 1778 | ssid_len = 0; |
| 1779 | else |
| 1780 | ssid_len = ssid[1]; |
| 1781 | |
Eliad Peller | d9b3b28 | 2012-06-28 15:03:13 +0300 | [diff] [blame] | 1782 | skb = ieee80211_build_probe_req(sdata, cbss->bssid, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1783 | (u32) -1, cbss->channel, |
Johannes Berg | 6b77863 | 2012-07-23 14:53:27 +0200 | [diff] [blame] | 1784 | ssid + 2, ssid_len, |
Johannes Berg | 85a237f | 2011-07-18 18:08:36 +0200 | [diff] [blame] | 1785 | NULL, 0, true); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 1786 | rcu_read_unlock(); |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 1787 | |
| 1788 | return skb; |
| 1789 | } |
| 1790 | EXPORT_SYMBOL(ieee80211_ap_probereq_get); |
| 1791 | |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1792 | static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata, |
| 1793 | bool transmit_frame) |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1794 | { |
| 1795 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1796 | struct ieee80211_local *local = sdata->local; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 1797 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1798 | |
| 1799 | mutex_lock(&ifmgd->mtx); |
| 1800 | if (!ifmgd->associated) { |
| 1801 | mutex_unlock(&ifmgd->mtx); |
| 1802 | return; |
| 1803 | } |
| 1804 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 1805 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 1806 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1807 | transmit_frame, frame_buf); |
| 1808 | ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1809 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1810 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1811 | /* |
| 1812 | * must be outside lock due to cfg80211, |
| 1813 | * but that's not a problem. |
| 1814 | */ |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 1815 | cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN); |
Felix Fietkau | fcac4fb | 2011-11-16 13:34:55 +0100 | [diff] [blame] | 1816 | |
| 1817 | mutex_lock(&local->mtx); |
| 1818 | ieee80211_recalc_idle(local); |
| 1819 | mutex_unlock(&local->mtx); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1820 | } |
| 1821 | |
Johannes Berg | cc74c0c | 2012-08-01 16:49:34 +0200 | [diff] [blame] | 1822 | static void ieee80211_beacon_connection_loss_work(struct work_struct *work) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1823 | { |
| 1824 | struct ieee80211_sub_if_data *sdata = |
| 1825 | container_of(work, struct ieee80211_sub_if_data, |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1826 | u.mgd.beacon_connection_loss_work); |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 1827 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1828 | struct sta_info *sta; |
| 1829 | |
| 1830 | if (ifmgd->associated) { |
Mohammed Shafi Shajakhan | 30fa904 | 2011-12-27 18:54:07 +0530 | [diff] [blame] | 1831 | rcu_read_lock(); |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 1832 | sta = sta_info_get(sdata, ifmgd->bssid); |
| 1833 | if (sta) |
| 1834 | sta->beacon_loss_count++; |
Mohammed Shafi Shajakhan | 30fa904 | 2011-12-27 18:54:07 +0530 | [diff] [blame] | 1835 | rcu_read_unlock(); |
Paul Stewart | a85e1d5 | 2011-12-09 11:01:49 -0800 | [diff] [blame] | 1836 | } |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1837 | |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1838 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) { |
| 1839 | sdata_info(sdata, "Connection to AP %pM lost\n", |
| 1840 | ifmgd->bssid); |
| 1841 | __ieee80211_disconnect(sdata, false); |
| 1842 | } else { |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1843 | ieee80211_mgd_probe_ap(sdata, true); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 1844 | } |
| 1845 | } |
| 1846 | |
| 1847 | static void ieee80211_csa_connection_drop_work(struct work_struct *work) |
| 1848 | { |
| 1849 | struct ieee80211_sub_if_data *sdata = |
| 1850 | container_of(work, struct ieee80211_sub_if_data, |
| 1851 | u.mgd.csa_connection_drop_work); |
| 1852 | |
| 1853 | ieee80211_wake_queues_by_reason(&sdata->local->hw, |
| 1854 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 1855 | __ieee80211_disconnect(sdata, true); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1856 | } |
| 1857 | |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1858 | void ieee80211_beacon_loss(struct ieee80211_vif *vif) |
| 1859 | { |
| 1860 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1861 | struct ieee80211_hw *hw = &sdata->local->hw; |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1862 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 1863 | trace_api_beacon_loss(sdata); |
| 1864 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1865 | WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR); |
| 1866 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1867 | } |
| 1868 | EXPORT_SYMBOL(ieee80211_beacon_loss); |
| 1869 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1870 | void ieee80211_connection_loss(struct ieee80211_vif *vif) |
| 1871 | { |
| 1872 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1873 | struct ieee80211_hw *hw = &sdata->local->hw; |
| 1874 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 1875 | trace_api_connection_loss(sdata); |
| 1876 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1877 | WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR)); |
| 1878 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
| 1879 | } |
| 1880 | EXPORT_SYMBOL(ieee80211_connection_loss); |
| 1881 | |
| 1882 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1883 | static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata, |
| 1884 | bool assoc) |
| 1885 | { |
| 1886 | struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; |
| 1887 | |
| 1888 | lockdep_assert_held(&sdata->u.mgd.mtx); |
| 1889 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1890 | if (!assoc) { |
| 1891 | sta_info_destroy_addr(sdata, auth_data->bss->bssid); |
| 1892 | |
| 1893 | memset(sdata->u.mgd.bssid, 0, ETH_ALEN); |
| 1894 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 1895 | sdata->u.mgd.flags = 0; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1896 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1897 | } |
| 1898 | |
| 1899 | cfg80211_put_bss(auth_data->bss); |
| 1900 | kfree(auth_data); |
| 1901 | sdata->u.mgd.auth_data = NULL; |
| 1902 | } |
| 1903 | |
| 1904 | static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata, |
| 1905 | struct ieee80211_mgmt *mgmt, size_t len) |
| 1906 | { |
| 1907 | struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data; |
| 1908 | u8 *pos; |
| 1909 | struct ieee802_11_elems elems; |
| 1910 | |
| 1911 | pos = mgmt->u.auth.variable; |
| 1912 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
| 1913 | if (!elems.challenge) |
| 1914 | return; |
| 1915 | auth_data->expected_transaction = 4; |
Johannes Berg | a1845fc | 2012-06-27 13:18:36 +0200 | [diff] [blame] | 1916 | drv_mgd_prepare_tx(sdata->local, sdata); |
Jouni Malinen | 700e8ea | 2012-09-30 19:29:37 +0300 | [diff] [blame] | 1917 | ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1918 | elems.challenge - 2, elems.challenge_len + 2, |
| 1919 | auth_data->bss->bssid, auth_data->bss->bssid, |
| 1920 | auth_data->key, auth_data->key_len, |
| 1921 | auth_data->key_idx); |
| 1922 | } |
| 1923 | |
| 1924 | static enum rx_mgmt_action __must_check |
| 1925 | ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata, |
| 1926 | struct ieee80211_mgmt *mgmt, size_t len) |
| 1927 | { |
| 1928 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1929 | u8 bssid[ETH_ALEN]; |
| 1930 | u16 auth_alg, auth_transaction, status_code; |
| 1931 | struct sta_info *sta; |
| 1932 | |
| 1933 | lockdep_assert_held(&ifmgd->mtx); |
| 1934 | |
| 1935 | if (len < 24 + 6) |
| 1936 | return RX_MGMT_NONE; |
| 1937 | |
| 1938 | if (!ifmgd->auth_data || ifmgd->auth_data->done) |
| 1939 | return RX_MGMT_NONE; |
| 1940 | |
| 1941 | memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN); |
| 1942 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 1943 | if (!ether_addr_equal(bssid, mgmt->bssid)) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1944 | return RX_MGMT_NONE; |
| 1945 | |
| 1946 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 1947 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
| 1948 | status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 1949 | |
| 1950 | if (auth_alg != ifmgd->auth_data->algorithm || |
Jouni Malinen | 0f4126e | 2012-09-30 19:29:38 +0300 | [diff] [blame] | 1951 | auth_transaction != ifmgd->auth_data->expected_transaction) { |
| 1952 | sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n", |
| 1953 | mgmt->sa, auth_alg, ifmgd->auth_data->algorithm, |
| 1954 | auth_transaction, |
| 1955 | ifmgd->auth_data->expected_transaction); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1956 | return RX_MGMT_NONE; |
Jouni Malinen | 0f4126e | 2012-09-30 19:29:38 +0300 | [diff] [blame] | 1957 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1958 | |
| 1959 | if (status_code != WLAN_STATUS_SUCCESS) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1960 | sdata_info(sdata, "%pM denied authentication (status %d)\n", |
| 1961 | mgmt->sa, status_code); |
Eliad Peller | dac211e | 2012-05-13 18:07:04 +0300 | [diff] [blame] | 1962 | ieee80211_destroy_auth_data(sdata, false); |
| 1963 | return RX_MGMT_CFG80211_RX_AUTH; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | switch (ifmgd->auth_data->algorithm) { |
| 1967 | case WLAN_AUTH_OPEN: |
| 1968 | case WLAN_AUTH_LEAP: |
| 1969 | case WLAN_AUTH_FT: |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 1970 | case WLAN_AUTH_SAE: |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1971 | break; |
| 1972 | case WLAN_AUTH_SHARED_KEY: |
| 1973 | if (ifmgd->auth_data->expected_transaction != 4) { |
| 1974 | ieee80211_auth_challenge(sdata, mgmt, len); |
| 1975 | /* need another frame */ |
| 1976 | return RX_MGMT_NONE; |
| 1977 | } |
| 1978 | break; |
| 1979 | default: |
| 1980 | WARN_ONCE(1, "invalid auth alg %d", |
| 1981 | ifmgd->auth_data->algorithm); |
| 1982 | return RX_MGMT_NONE; |
| 1983 | } |
| 1984 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 1985 | sdata_info(sdata, "authenticated\n"); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1986 | ifmgd->auth_data->done = true; |
| 1987 | ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC; |
| 1988 | run_again(ifmgd, ifmgd->auth_data->timeout); |
| 1989 | |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 1990 | if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE && |
| 1991 | ifmgd->auth_data->expected_transaction != 2) { |
| 1992 | /* |
| 1993 | * Report auth frame to user space for processing since another |
| 1994 | * round of Authentication frames is still needed. |
| 1995 | */ |
| 1996 | return RX_MGMT_CFG80211_RX_AUTH; |
| 1997 | } |
| 1998 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 1999 | /* move station state to auth */ |
| 2000 | mutex_lock(&sdata->local->sta_mtx); |
| 2001 | sta = sta_info_get(sdata, bssid); |
| 2002 | if (!sta) { |
| 2003 | WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid); |
| 2004 | goto out_err; |
| 2005 | } |
| 2006 | if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2007 | sdata_info(sdata, "failed moving %pM to auth\n", bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2008 | goto out_err; |
| 2009 | } |
| 2010 | mutex_unlock(&sdata->local->sta_mtx); |
| 2011 | |
| 2012 | return RX_MGMT_CFG80211_RX_AUTH; |
| 2013 | out_err: |
| 2014 | mutex_unlock(&sdata->local->sta_mtx); |
| 2015 | /* ignore frame -- wait for timeout */ |
| 2016 | return RX_MGMT_NONE; |
| 2017 | } |
| 2018 | |
| 2019 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2020 | static enum rx_mgmt_action __must_check |
| 2021 | ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2022 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2023 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2024 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2025 | const u8 *bssid = NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2026 | u16 reason_code; |
| 2027 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2028 | lockdep_assert_held(&ifmgd->mtx); |
| 2029 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2030 | if (len < 24 + 2) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2031 | return RX_MGMT_NONE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2032 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2033 | if (!ifmgd->associated || |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2034 | !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2035 | return RX_MGMT_NONE; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2036 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2037 | bssid = ifmgd->associated->bssid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2038 | |
| 2039 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
| 2040 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2041 | sdata_info(sdata, "deauthenticated from %pM (Reason: %u)\n", |
| 2042 | bssid, reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2043 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2044 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
| 2045 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2046 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 2047 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2048 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2049 | |
| 2050 | return RX_MGMT_CFG80211_DEAUTH; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2051 | } |
| 2052 | |
| 2053 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2054 | static enum rx_mgmt_action __must_check |
| 2055 | ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, |
| 2056 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2057 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2058 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2059 | u16 reason_code; |
| 2060 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2061 | lockdep_assert_held(&ifmgd->mtx); |
| 2062 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 2063 | if (len < 24 + 2) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2064 | return RX_MGMT_NONE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2065 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2066 | if (!ifmgd->associated || |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2067 | !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2068 | return RX_MGMT_NONE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2069 | |
| 2070 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 2071 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2072 | sdata_info(sdata, "disassociated from %pM (Reason: %u)\n", |
| 2073 | mgmt->sa, reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2074 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2075 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
| 2076 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2077 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 2078 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2079 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2080 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2081 | return RX_MGMT_CFG80211_DISASSOC; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2082 | } |
| 2083 | |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 2084 | static void ieee80211_get_rates(struct ieee80211_supported_band *sband, |
| 2085 | u8 *supp_rates, unsigned int supp_rates_len, |
| 2086 | u32 *rates, u32 *basic_rates, |
| 2087 | bool *have_higher_than_11mbit, |
| 2088 | int *min_rate, int *min_rate_index) |
| 2089 | { |
| 2090 | int i, j; |
| 2091 | |
| 2092 | for (i = 0; i < supp_rates_len; i++) { |
| 2093 | int rate = (supp_rates[i] & 0x7f) * 5; |
| 2094 | bool is_basic = !!(supp_rates[i] & 0x80); |
| 2095 | |
| 2096 | if (rate > 110) |
| 2097 | *have_higher_than_11mbit = true; |
| 2098 | |
| 2099 | /* |
| 2100 | * BSS_MEMBERSHIP_SELECTOR_HT_PHY is defined in 802.11n-2009 |
| 2101 | * 7.3.2.2 as a magic value instead of a rate. Hence, skip it. |
| 2102 | * |
| 2103 | * Note: Even through the membership selector and the basic |
| 2104 | * rate flag share the same bit, they are not exactly |
| 2105 | * the same. |
| 2106 | */ |
| 2107 | if (!!(supp_rates[i] & 0x80) && |
| 2108 | (supp_rates[i] & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY) |
| 2109 | continue; |
| 2110 | |
| 2111 | for (j = 0; j < sband->n_bitrates; j++) { |
| 2112 | if (sband->bitrates[j].bitrate == rate) { |
| 2113 | *rates |= BIT(j); |
| 2114 | if (is_basic) |
| 2115 | *basic_rates |= BIT(j); |
| 2116 | if (rate < *min_rate) { |
| 2117 | *min_rate = rate; |
| 2118 | *min_rate_index = j; |
| 2119 | } |
| 2120 | break; |
| 2121 | } |
| 2122 | } |
| 2123 | } |
| 2124 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2125 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2126 | static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata, |
| 2127 | bool assoc) |
| 2128 | { |
| 2129 | struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; |
| 2130 | |
| 2131 | lockdep_assert_held(&sdata->u.mgd.mtx); |
| 2132 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2133 | if (!assoc) { |
| 2134 | sta_info_destroy_addr(sdata, assoc_data->bss->bssid); |
| 2135 | |
| 2136 | memset(sdata->u.mgd.bssid, 0, ETH_ALEN); |
| 2137 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 028e8da0 | 2012-11-26 11:57:41 +0100 | [diff] [blame] | 2138 | sdata->u.mgd.flags = 0; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2139 | ieee80211_vif_release_channel(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2140 | } |
| 2141 | |
| 2142 | kfree(assoc_data); |
| 2143 | sdata->u.mgd.assoc_data = NULL; |
| 2144 | } |
| 2145 | |
| 2146 | static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata, |
| 2147 | struct cfg80211_bss *cbss, |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2148 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2149 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2150 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2151 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2152 | struct ieee80211_supported_band *sband; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2153 | struct sta_info *sta; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2154 | u8 *pos; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2155 | u16 capab_info, aid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2156 | struct ieee802_11_elems elems; |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 2157 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2158 | u32 changed = 0; |
Christian Lamparter | c74d084 | 2011-10-15 00:14:49 +0200 | [diff] [blame] | 2159 | int err; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2160 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2161 | /* AssocResp and ReassocResp have identical structure */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2162 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2163 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2164 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2165 | |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 2166 | if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2167 | sdata_info(sdata, "invalid AID value 0x%x; bits 15:14 not set\n", |
| 2168 | aid); |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 2169 | aid &= ~(BIT(15) | BIT(14)); |
| 2170 | |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 2171 | ifmgd->broken_ap = false; |
| 2172 | |
| 2173 | if (aid == 0 || aid > IEEE80211_MAX_AID) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2174 | sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n", |
| 2175 | aid); |
Johannes Berg | 05cb910 | 2011-10-28 11:59:47 +0200 | [diff] [blame] | 2176 | aid = 0; |
| 2177 | ifmgd->broken_ap = true; |
| 2178 | } |
| 2179 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2180 | pos = mgmt->u.assoc_resp.variable; |
| 2181 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
| 2182 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2183 | if (!elems.supp_rates) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2184 | sdata_info(sdata, "no SuppRates element in AssocResp\n"); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2185 | return false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2186 | } |
| 2187 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2188 | ifmgd->aid = aid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2189 | |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 2190 | mutex_lock(&sdata->local->sta_mtx); |
| 2191 | /* |
| 2192 | * station info was already allocated and inserted before |
| 2193 | * the association and should be available to us |
| 2194 | */ |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 2195 | sta = sta_info_get(sdata, cbss->bssid); |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 2196 | if (WARN_ON(!sta)) { |
| 2197 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2198 | return false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2199 | } |
| 2200 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2201 | sband = local->hw.wiphy->bands[ieee80211_get_sdata_band(sdata)]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2202 | |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 2203 | if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 2204 | ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband, |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 2205 | elems.ht_cap_elem, &sta->sta.ht_cap); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2206 | |
Johannes Berg | 64f68e5 | 2012-03-28 10:58:37 +0200 | [diff] [blame] | 2207 | sta->supports_40mhz = |
| 2208 | sta->sta.ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 2209 | |
Mahesh Palivela | 818255e | 2012-10-10 11:33:04 +0000 | [diff] [blame] | 2210 | if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) |
| 2211 | ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband, |
| 2212 | elems.vht_cap_elem, |
| 2213 | &sta->sta.vht_cap); |
| 2214 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 2215 | rate_control_rate_init(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2216 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2217 | if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 2218 | set_sta_flag(sta, WLAN_STA_MFP); |
Jouni Malinen | 5394af4 | 2009-01-08 13:31:59 +0200 | [diff] [blame] | 2219 | |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 2220 | if (elems.wmm_param) |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 2221 | set_sta_flag(sta, WLAN_STA_WME); |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 2222 | |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 2223 | err = sta_info_move_state(sta, IEEE80211_STA_AUTH); |
| 2224 | if (!err) |
| 2225 | err = sta_info_move_state(sta, IEEE80211_STA_ASSOC); |
| 2226 | if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT)) |
| 2227 | err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED); |
| 2228 | if (err) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2229 | sdata_info(sdata, |
| 2230 | "failed to move station %pM to desired state\n", |
| 2231 | sta->sta.addr); |
Johannes Berg | c898787 | 2012-01-20 13:55:17 +0100 | [diff] [blame] | 2232 | WARN_ON(__sta_info_destroy(sta)); |
| 2233 | mutex_unlock(&sdata->local->sta_mtx); |
| 2234 | return false; |
| 2235 | } |
| 2236 | |
Johannes Berg | 7852e36 | 2012-01-20 13:55:24 +0100 | [diff] [blame] | 2237 | mutex_unlock(&sdata->local->sta_mtx); |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 2238 | |
Juuso Oikarinen | f2176d7 | 2010-09-28 14:39:32 +0300 | [diff] [blame] | 2239 | /* |
| 2240 | * Always handle WMM once after association regardless |
| 2241 | * of the first value the AP uses. Setting -1 here has |
| 2242 | * that effect because the AP values is an unsigned |
| 2243 | * 4-bit value. |
| 2244 | */ |
| 2245 | ifmgd->wmm_last_param_set = -1; |
| 2246 | |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 2247 | if (elems.wmm_param) |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 2248 | ieee80211_sta_wmm_params(local, sdata, elems.wmm_param, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2249 | elems.wmm_param_len); |
Johannes Berg | aa837e1 | 2009-05-07 16:16:24 +0200 | [diff] [blame] | 2250 | else |
Johannes Berg | 3abead5 | 2012-03-02 15:56:59 +0100 | [diff] [blame] | 2251 | ieee80211_set_wmm_default(sdata, false); |
| 2252 | changed |= BSS_CHANGED_QOS; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2253 | |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 2254 | if (elems.ht_operation && elems.wmm_param && |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 2255 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 2256 | changed |= ieee80211_config_ht_tx(sdata, elems.ht_operation, |
| 2257 | cbss->bssid, false); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 2258 | |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 2259 | /* set AID and assoc capability, |
| 2260 | * ieee80211_set_associated() will tell the driver */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 2261 | bss_conf->aid = aid; |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 2262 | bss_conf->assoc_capability = capab_info; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2263 | ieee80211_set_associated(sdata, cbss, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2264 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 2265 | /* |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 2266 | * If we're using 4-addr mode, let the AP know that we're |
| 2267 | * doing so, so that it can create the STA VLAN on its side |
| 2268 | */ |
| 2269 | if (ifmgd->use_4addr) |
| 2270 | ieee80211_send_4addr_nullfunc(local, sdata); |
| 2271 | |
| 2272 | /* |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2273 | * Start timer to probe the connection to the AP now. |
| 2274 | * Also start the timer that will detect beacon loss. |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 2275 | */ |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2276 | ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt); |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 2277 | ieee80211_sta_reset_beacon_monitor(sdata); |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 2278 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2279 | return true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2280 | } |
| 2281 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2282 | static enum rx_mgmt_action __must_check |
| 2283 | ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata, |
| 2284 | struct ieee80211_mgmt *mgmt, size_t len, |
| 2285 | struct cfg80211_bss **bss) |
| 2286 | { |
| 2287 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2288 | struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data; |
| 2289 | u16 capab_info, status_code, aid; |
| 2290 | struct ieee802_11_elems elems; |
| 2291 | u8 *pos; |
| 2292 | bool reassoc; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2293 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2294 | lockdep_assert_held(&ifmgd->mtx); |
| 2295 | |
| 2296 | if (!assoc_data) |
| 2297 | return RX_MGMT_NONE; |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2298 | if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid)) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2299 | return RX_MGMT_NONE; |
| 2300 | |
| 2301 | /* |
| 2302 | * AssocResp and ReassocResp have identical structure, so process both |
| 2303 | * of them in this function. |
| 2304 | */ |
| 2305 | |
| 2306 | if (len < 24 + 6) |
| 2307 | return RX_MGMT_NONE; |
| 2308 | |
| 2309 | reassoc = ieee80211_is_reassoc_req(mgmt->frame_control); |
| 2310 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
| 2311 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
| 2312 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
| 2313 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2314 | sdata_info(sdata, |
| 2315 | "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n", |
| 2316 | reassoc ? "Rea" : "A", mgmt->sa, |
| 2317 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2318 | |
| 2319 | pos = mgmt->u.assoc_resp.variable; |
| 2320 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
| 2321 | |
| 2322 | if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY && |
| 2323 | elems.timeout_int && elems.timeout_int_len == 5 && |
| 2324 | elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) { |
| 2325 | u32 tu, ms; |
| 2326 | tu = get_unaligned_le32(elems.timeout_int + 1); |
| 2327 | ms = tu * 1024 / 1000; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2328 | sdata_info(sdata, |
| 2329 | "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n", |
| 2330 | mgmt->sa, tu, ms); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2331 | assoc_data->timeout = jiffies + msecs_to_jiffies(ms); |
| 2332 | if (ms > IEEE80211_ASSOC_TIMEOUT) |
| 2333 | run_again(ifmgd, assoc_data->timeout); |
| 2334 | return RX_MGMT_NONE; |
| 2335 | } |
| 2336 | |
| 2337 | *bss = assoc_data->bss; |
| 2338 | |
| 2339 | if (status_code != WLAN_STATUS_SUCCESS) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2340 | sdata_info(sdata, "%pM denied association (code=%d)\n", |
| 2341 | mgmt->sa, status_code); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2342 | ieee80211_destroy_assoc_data(sdata, false); |
| 2343 | } else { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2344 | if (!ieee80211_assoc_success(sdata, *bss, mgmt, len)) { |
| 2345 | /* oops -- internal error -- send timeout for now */ |
Eliad Peller | 10a9109 | 2012-07-02 14:42:03 +0300 | [diff] [blame] | 2346 | ieee80211_destroy_assoc_data(sdata, false); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2347 | cfg80211_put_bss(*bss); |
| 2348 | return RX_MGMT_CFG80211_ASSOC_TIMEOUT; |
| 2349 | } |
John W. Linville | 635d999 | 2012-07-09 16:34:34 -0400 | [diff] [blame] | 2350 | sdata_info(sdata, "associated\n"); |
Johannes Berg | 79ebfb8 | 2012-02-20 14:19:58 +0100 | [diff] [blame] | 2351 | |
| 2352 | /* |
| 2353 | * destroy assoc_data afterwards, as otherwise an idle |
| 2354 | * recalc after assoc_data is NULL but before associated |
| 2355 | * is set can cause the interface to go idle |
| 2356 | */ |
| 2357 | ieee80211_destroy_assoc_data(sdata, true); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | return RX_MGMT_CFG80211_RX_ASSOC; |
| 2361 | } |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2362 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2363 | struct ieee80211_mgmt *mgmt, |
| 2364 | size_t len, |
| 2365 | struct ieee80211_rx_status *rx_status, |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 2366 | struct ieee802_11_elems *elems, |
| 2367 | bool beacon) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2368 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2369 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 2370 | int freq; |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 2371 | struct ieee80211_bss *bss; |
Johannes Berg | fab7d4a | 2008-03-16 18:42:44 +0100 | [diff] [blame] | 2372 | struct ieee80211_channel *channel; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 2373 | bool need_ps = false; |
| 2374 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2375 | if (sdata->u.mgd.associated && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2376 | ether_addr_equal(mgmt->bssid, sdata->u.mgd.associated->bssid)) { |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 2377 | bss = (void *)sdata->u.mgd.associated->priv; |
| 2378 | /* not previously set so we may need to recalc */ |
| 2379 | need_ps = !bss->dtim_period; |
| 2380 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2381 | |
Johannes Berg | 5bda617 | 2008-09-08 11:05:10 +0200 | [diff] [blame] | 2382 | if (elems->ds_params && elems->ds_params_len == 1) |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 2383 | freq = ieee80211_channel_to_frequency(elems->ds_params[0], |
| 2384 | rx_status->band); |
Johannes Berg | 5bda617 | 2008-09-08 11:05:10 +0200 | [diff] [blame] | 2385 | else |
| 2386 | freq = rx_status->freq; |
| 2387 | |
| 2388 | channel = ieee80211_get_channel(local->hw.wiphy, freq); |
| 2389 | |
| 2390 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) |
| 2391 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2392 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 2393 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 2394 | channel, beacon); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2395 | if (bss) |
| 2396 | ieee80211_rx_bss_put(local, bss); |
| 2397 | |
| 2398 | if (!sdata->u.mgd.associated) |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 2399 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2400 | |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 2401 | if (need_ps) { |
| 2402 | mutex_lock(&local->iflist_mtx); |
| 2403 | ieee80211_recalc_ps(local, -1); |
| 2404 | mutex_unlock(&local->iflist_mtx); |
| 2405 | } |
| 2406 | |
Johannes Berg | 5bc1420 | 2012-08-01 16:13:02 +0200 | [diff] [blame] | 2407 | if (elems->ch_switch_ie && |
| 2408 | memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid, ETH_ALEN) == 0) |
| 2409 | ieee80211_sta_process_chanswitch(sdata, elems->ch_switch_ie, |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 2410 | bss, rx_status->mactime); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2414 | static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2415 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2416 | { |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2417 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 2418 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2419 | struct ieee80211_rx_status *rx_status = (void *) skb->cb; |
| 2420 | size_t baselen, len = skb->len; |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2421 | struct ieee802_11_elems elems; |
| 2422 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 2423 | ifmgd = &sdata->u.mgd; |
| 2424 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2425 | ASSERT_MGD_MTX(ifmgd); |
| 2426 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2427 | if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) |
Tomas Winkler | 8e7cdbb | 2008-08-03 14:32:01 +0300 | [diff] [blame] | 2428 | return; /* ignore ProbeResp to foreign address */ |
| 2429 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2430 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
| 2431 | if (baselen > len) |
| 2432 | return; |
| 2433 | |
| 2434 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, |
| 2435 | &elems); |
| 2436 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 2437 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 2438 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2439 | if (ifmgd->associated && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2440 | ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2441 | ieee80211_reset_ap_probe(sdata); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2442 | |
| 2443 | if (ifmgd->auth_data && !ifmgd->auth_data->bss->proberesp_ies && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2444 | ether_addr_equal(mgmt->bssid, ifmgd->auth_data->bss->bssid)) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2445 | /* got probe response, continue with auth */ |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2446 | sdata_info(sdata, "direct probe responded\n"); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2447 | ifmgd->auth_data->tries = 0; |
| 2448 | ifmgd->auth_data->timeout = jiffies; |
| 2449 | run_again(ifmgd, ifmgd->auth_data->timeout); |
| 2450 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2451 | } |
| 2452 | |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 2453 | /* |
| 2454 | * This is the canonical list of information elements we care about, |
| 2455 | * the filter code also gives us all changes to the Microsoft OUI |
| 2456 | * (00:50:F2) vendor IE which is used for WMM which we need to track. |
| 2457 | * |
| 2458 | * We implement beacon filtering in software since that means we can |
| 2459 | * avoid processing the frame here and in cfg80211, and userspace |
| 2460 | * will not be able to tell whether the hardware supports it or not. |
| 2461 | * |
| 2462 | * XXX: This list needs to be dynamic -- userspace needs to be able to |
| 2463 | * add items it requires. It also needs to be able to tell us to |
| 2464 | * look out for other vendor IEs. |
| 2465 | */ |
| 2466 | static const u64 care_about_ies = |
Johannes Berg | 1d4df3a | 2009-04-22 11:25:43 +0200 | [diff] [blame] | 2467 | (1ULL << WLAN_EID_COUNTRY) | |
| 2468 | (1ULL << WLAN_EID_ERP_INFO) | |
| 2469 | (1ULL << WLAN_EID_CHANNEL_SWITCH) | |
| 2470 | (1ULL << WLAN_EID_PWR_CONSTRAINT) | |
| 2471 | (1ULL << WLAN_EID_HT_CAPABILITY) | |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 2472 | (1ULL << WLAN_EID_HT_OPERATION); |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 2473 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2474 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2475 | struct ieee80211_mgmt *mgmt, |
| 2476 | size_t len, |
| 2477 | struct ieee80211_rx_status *rx_status) |
| 2478 | { |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 2479 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2480 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2481 | size_t baselen; |
| 2482 | struct ieee802_11_elems elems; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2483 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2484 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 2485 | struct ieee80211_channel *chan; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2486 | u32 changed = 0; |
Rami Rosen | f87ad63 | 2012-10-25 10:16:23 +0200 | [diff] [blame] | 2487 | bool erp_valid; |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2488 | u8 erp_value = 0; |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 2489 | u32 ncrc; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2490 | u8 *bssid; |
| 2491 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2492 | lockdep_assert_held(&ifmgd->mtx); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2493 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 2494 | /* Process beacon from the current BSS */ |
| 2495 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 2496 | if (baselen > len) |
| 2497 | return; |
| 2498 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2499 | rcu_read_lock(); |
| 2500 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 2501 | if (!chanctx_conf) { |
| 2502 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2503 | return; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2504 | } |
| 2505 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 2506 | if (rx_status->freq != chanctx_conf->def.chan->center_freq) { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2507 | rcu_read_unlock(); |
| 2508 | return; |
| 2509 | } |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 2510 | chan = chanctx_conf->def.chan; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2511 | rcu_read_unlock(); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2512 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2513 | if (ifmgd->assoc_data && !ifmgd->assoc_data->have_beacon && |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2514 | ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2515 | ieee802_11_parse_elems(mgmt->u.beacon.variable, |
| 2516 | len - baselen, &elems); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2517 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2518 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, |
| 2519 | false); |
| 2520 | ifmgd->assoc_data->have_beacon = true; |
| 2521 | ifmgd->assoc_data->sent_assoc = false; |
| 2522 | /* continue assoc process */ |
| 2523 | ifmgd->assoc_data->timeout = jiffies; |
| 2524 | run_again(ifmgd, ifmgd->assoc_data->timeout); |
| 2525 | return; |
| 2526 | } |
| 2527 | |
| 2528 | if (!ifmgd->associated || |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2529 | !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2530 | return; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2531 | bssid = ifmgd->associated->bssid; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2532 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2533 | /* Track average RSSI from the Beacon frames of the current AP */ |
| 2534 | ifmgd->last_beacon_signal = rx_status->signal; |
| 2535 | if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) { |
| 2536 | ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE; |
Jouni Malinen | 3ba06c6 | 2010-08-27 22:21:13 +0300 | [diff] [blame] | 2537 | ifmgd->ave_beacon_signal = rx_status->signal * 16; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2538 | ifmgd->last_cqm_event_signal = 0; |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 2539 | ifmgd->count_beacon_signal = 1; |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 2540 | ifmgd->last_ave_beacon_signal = 0; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2541 | } else { |
| 2542 | ifmgd->ave_beacon_signal = |
| 2543 | (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 + |
| 2544 | (16 - IEEE80211_SIGNAL_AVE_WEIGHT) * |
| 2545 | ifmgd->ave_beacon_signal) / 16; |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 2546 | ifmgd->count_beacon_signal++; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2547 | } |
Meenakshi Venkataraman | 615f7b9 | 2011-07-08 08:46:22 -0700 | [diff] [blame] | 2548 | |
| 2549 | if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold && |
| 2550 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) { |
| 2551 | int sig = ifmgd->ave_beacon_signal; |
| 2552 | int last_sig = ifmgd->last_ave_beacon_signal; |
| 2553 | |
| 2554 | /* |
| 2555 | * if signal crosses either of the boundaries, invoke callback |
| 2556 | * with appropriate parameters |
| 2557 | */ |
| 2558 | if (sig > ifmgd->rssi_max_thold && |
| 2559 | (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) { |
| 2560 | ifmgd->last_ave_beacon_signal = sig; |
| 2561 | drv_rssi_callback(local, RSSI_EVENT_HIGH); |
| 2562 | } else if (sig < ifmgd->rssi_min_thold && |
| 2563 | (last_sig >= ifmgd->rssi_max_thold || |
| 2564 | last_sig == 0)) { |
| 2565 | ifmgd->last_ave_beacon_signal = sig; |
| 2566 | drv_rssi_callback(local, RSSI_EVENT_LOW); |
| 2567 | } |
| 2568 | } |
| 2569 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2570 | if (bss_conf->cqm_rssi_thold && |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 2571 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT && |
Johannes Berg | ea08635 | 2012-01-19 09:29:58 +0100 | [diff] [blame] | 2572 | !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) { |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 2573 | int sig = ifmgd->ave_beacon_signal / 16; |
| 2574 | int last_event = ifmgd->last_cqm_event_signal; |
| 2575 | int thold = bss_conf->cqm_rssi_thold; |
| 2576 | int hyst = bss_conf->cqm_rssi_hyst; |
| 2577 | if (sig < thold && |
| 2578 | (last_event == 0 || sig < last_event - hyst)) { |
| 2579 | ifmgd->last_cqm_event_signal = sig; |
| 2580 | ieee80211_cqm_rssi_notify( |
| 2581 | &sdata->vif, |
| 2582 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, |
| 2583 | GFP_KERNEL); |
| 2584 | } else if (sig > thold && |
| 2585 | (last_event == 0 || sig > last_event + hyst)) { |
| 2586 | ifmgd->last_cqm_event_signal = sig; |
| 2587 | ieee80211_cqm_rssi_notify( |
| 2588 | &sdata->vif, |
| 2589 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, |
| 2590 | GFP_KERNEL); |
| 2591 | } |
| 2592 | } |
| 2593 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2594 | if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2595 | mlme_dbg_ratelimited(sdata, |
| 2596 | "cancelling probereq poll due to a received beacon\n"); |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2597 | mutex_lock(&local->mtx); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2598 | ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL; |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 2599 | ieee80211_run_deferred_scan(local); |
| 2600 | mutex_unlock(&local->mtx); |
| 2601 | |
Johannes Berg | 4e75184 | 2009-06-10 15:16:52 +0200 | [diff] [blame] | 2602 | mutex_lock(&local->iflist_mtx); |
| 2603 | ieee80211_recalc_ps(local, -1); |
| 2604 | mutex_unlock(&local->iflist_mtx); |
Jouni Malinen | 9277818 | 2009-05-14 21:15:36 +0300 | [diff] [blame] | 2605 | } |
| 2606 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2607 | /* |
| 2608 | * Push the beacon loss detection into the future since |
| 2609 | * we are processing a beacon from the AP just now. |
| 2610 | */ |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 2611 | ieee80211_sta_reset_beacon_monitor(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2612 | |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 2613 | ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4); |
| 2614 | ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable, |
| 2615 | len - baselen, &elems, |
| 2616 | care_about_ies, ncrc); |
| 2617 | |
Vivek Natarajan | 25c9c87 | 2009-03-02 20:20:30 +0530 | [diff] [blame] | 2618 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) { |
Rami Rosen | f87ad63 | 2012-10-25 10:16:23 +0200 | [diff] [blame] | 2619 | bool directed_tim = ieee80211_check_tim(elems.tim, |
| 2620 | elems.tim_len, |
| 2621 | ifmgd->aid); |
Kalle Valo | 1fb3606 | 2009-02-10 17:09:24 +0200 | [diff] [blame] | 2622 | if (directed_tim) { |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 2623 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
Ronald Wahl | 70b12f2 | 2012-03-19 14:37:20 +0100 | [diff] [blame] | 2624 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 2625 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 2626 | ieee80211_hw_config(local, |
| 2627 | IEEE80211_CONF_CHANGE_PS); |
| 2628 | } |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 2629 | ieee80211_send_nullfunc(local, sdata, 0); |
Rajkumar Manoharan | 6f0756a | 2012-03-15 05:50:36 +0530 | [diff] [blame] | 2630 | } else if (!local->pspolling && sdata->u.mgd.powersave) { |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 2631 | local->pspolling = true; |
| 2632 | |
| 2633 | /* |
| 2634 | * Here is assumed that the driver will be |
| 2635 | * able to send ps-poll frame and receive a |
| 2636 | * response even though power save mode is |
| 2637 | * enabled, but some drivers might require |
| 2638 | * to disable power save here. This needs |
| 2639 | * to be investigated. |
| 2640 | */ |
| 2641 | ieee80211_send_pspoll(local, sdata); |
| 2642 | } |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 2643 | } |
| 2644 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2645 | |
Johannes Berg | 488dd7b | 2012-10-29 20:08:01 +0100 | [diff] [blame] | 2646 | if (sdata->vif.p2p) { |
| 2647 | u8 noa[2]; |
| 2648 | int ret; |
| 2649 | |
| 2650 | ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable, |
| 2651 | len - baselen, |
| 2652 | IEEE80211_P2P_ATTR_ABSENCE_NOTICE, |
| 2653 | noa, sizeof(noa)); |
| 2654 | if (ret >= 2 && sdata->u.mgd.p2p_noa_index != noa[0]) { |
| 2655 | bss_conf->p2p_oppps = noa[1] & 0x80; |
| 2656 | bss_conf->p2p_ctwindow = noa[1] & 0x7f; |
| 2657 | changed |= BSS_CHANGED_P2P_PS; |
| 2658 | sdata->u.mgd.p2p_noa_index = noa[0]; |
| 2659 | /* |
| 2660 | * make sure we update all information, the CRC |
| 2661 | * mechanism doesn't look at P2P attributes. |
| 2662 | */ |
| 2663 | ifmgd->beacon_crc_valid = false; |
| 2664 | } |
| 2665 | } |
| 2666 | |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 2667 | if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 2668 | return; |
| 2669 | ifmgd->beacon_crc = ncrc; |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 2670 | ifmgd->beacon_crc_valid = true; |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 2671 | |
Johannes Berg | 7d25745 | 2012-07-06 17:37:43 +0200 | [diff] [blame] | 2672 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, |
| 2673 | true); |
| 2674 | |
| 2675 | if (ieee80211_sta_wmm_params(local, sdata, elems.wmm_param, |
| 2676 | elems.wmm_param_len)) |
| 2677 | changed |= BSS_CHANGED_QOS; |
| 2678 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2679 | if (elems.erp_info && elems.erp_info_len >= 1) { |
| 2680 | erp_valid = true; |
| 2681 | erp_value = elems.erp_info[0]; |
| 2682 | } else { |
| 2683 | erp_valid = false; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 2684 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 2685 | changed |= ieee80211_handle_bss_capability(sdata, |
| 2686 | le16_to_cpu(mgmt->u.beacon.capab_info), |
| 2687 | erp_valid, erp_value); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2688 | |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 2689 | |
Johannes Berg | 074d46d | 2012-03-15 19:45:16 +0100 | [diff] [blame] | 2690 | if (elems.ht_cap_elem && elems.ht_operation && elems.wmm_param && |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 2691 | !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 2692 | changed |= ieee80211_config_ht_tx(sdata, elems.ht_operation, |
| 2693 | bssid, true); |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 2694 | |
Johannes Berg | 04b7b2f | 2012-09-05 13:41:37 +0200 | [diff] [blame] | 2695 | if (elems.country_elem && elems.pwr_constr_elem && |
| 2696 | mgmt->u.probe_resp.capab_info & |
| 2697 | cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT)) |
Johannes Berg | 1ea6f9c | 2012-10-24 10:59:25 +0200 | [diff] [blame] | 2698 | changed |= ieee80211_handle_pwr_constr(sdata, chan, |
| 2699 | elems.country_elem, |
| 2700 | elems.country_elem_len, |
| 2701 | elems.pwr_constr_elem); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 2702 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 2703 | ieee80211_bss_info_change_notify(sdata, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 2706 | void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
| 2707 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2708 | { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2709 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2710 | struct ieee80211_rx_status *rx_status; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2711 | struct ieee80211_mgmt *mgmt; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2712 | struct cfg80211_bss *bss = NULL; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2713 | enum rx_mgmt_action rma = RX_MGMT_NONE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2714 | u16 fc; |
| 2715 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2716 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
| 2717 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 2718 | fc = le16_to_cpu(mgmt->frame_control); |
| 2719 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2720 | mutex_lock(&ifmgd->mtx); |
| 2721 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2722 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 2723 | case IEEE80211_STYPE_BEACON: |
| 2724 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status); |
| 2725 | break; |
| 2726 | case IEEE80211_STYPE_PROBE_RESP: |
| 2727 | ieee80211_rx_mgmt_probe_resp(sdata, skb); |
| 2728 | break; |
| 2729 | case IEEE80211_STYPE_AUTH: |
| 2730 | rma = ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len); |
| 2731 | break; |
| 2732 | case IEEE80211_STYPE_DEAUTH: |
| 2733 | rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); |
| 2734 | break; |
| 2735 | case IEEE80211_STYPE_DISASSOC: |
| 2736 | rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); |
| 2737 | break; |
| 2738 | case IEEE80211_STYPE_ASSOC_RESP: |
| 2739 | case IEEE80211_STYPE_REASSOC_RESP: |
| 2740 | rma = ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len, &bss); |
| 2741 | break; |
| 2742 | case IEEE80211_STYPE_ACTION: |
| 2743 | switch (mgmt->u.action.category) { |
| 2744 | case WLAN_CATEGORY_SPECTRUM_MGMT: |
| 2745 | ieee80211_sta_process_chanswitch(sdata, |
| 2746 | &mgmt->u.action.u.chan_switch.sw_elem, |
| 2747 | (void *)ifmgd->associated->priv, |
| 2748 | rx_status->mactime); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2749 | break; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2750 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2751 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2752 | mutex_unlock(&ifmgd->mtx); |
| 2753 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2754 | switch (rma) { |
| 2755 | case RX_MGMT_NONE: |
| 2756 | /* no action */ |
| 2757 | break; |
| 2758 | case RX_MGMT_CFG80211_DEAUTH: |
Holger Schurig | ce47061 | 2009-10-13 13:28:13 +0200 | [diff] [blame] | 2759 | cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2760 | break; |
| 2761 | case RX_MGMT_CFG80211_DISASSOC: |
| 2762 | cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len); |
| 2763 | break; |
| 2764 | case RX_MGMT_CFG80211_RX_AUTH: |
| 2765 | cfg80211_send_rx_auth(sdata->dev, (u8 *)mgmt, skb->len); |
| 2766 | break; |
| 2767 | case RX_MGMT_CFG80211_RX_ASSOC: |
| 2768 | cfg80211_send_rx_assoc(sdata->dev, bss, (u8 *)mgmt, skb->len); |
| 2769 | break; |
| 2770 | case RX_MGMT_CFG80211_ASSOC_TIMEOUT: |
| 2771 | cfg80211_send_assoc_timeout(sdata->dev, mgmt->bssid); |
| 2772 | break; |
| 2773 | default: |
| 2774 | WARN(1, "unexpected: %d", rma); |
Johannes Berg | b054b74 | 2010-06-07 21:50:07 +0200 | [diff] [blame] | 2775 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2776 | } |
| 2777 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2778 | static void ieee80211_sta_timer(unsigned long data) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2779 | { |
| 2780 | struct ieee80211_sub_if_data *sdata = |
| 2781 | (struct ieee80211_sub_if_data *) data; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2782 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 2783 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2784 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 2785 | if (local->quiescing) { |
| 2786 | set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running); |
| 2787 | return; |
| 2788 | } |
| 2789 | |
Johannes Berg | 64592c8 | 2010-06-10 10:21:31 +0200 | [diff] [blame] | 2790 | ieee80211_queue_work(&local->hw, &sdata->work); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2791 | } |
| 2792 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2793 | static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 2794 | u8 *bssid, u8 reason) |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2795 | { |
| 2796 | struct ieee80211_local *local = sdata->local; |
| 2797 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 2798 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2799 | |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2800 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason, |
| 2801 | false, frame_buf); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2802 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 2803 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2804 | /* |
| 2805 | * must be outside lock due to cfg80211, |
| 2806 | * but that's not a problem. |
| 2807 | */ |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 2808 | cfg80211_send_deauth(sdata->dev, frame_buf, IEEE80211_DEAUTH_FRAME_LEN); |
Felix Fietkau | fcac4fb | 2011-11-16 13:34:55 +0100 | [diff] [blame] | 2809 | |
| 2810 | mutex_lock(&local->mtx); |
| 2811 | ieee80211_recalc_idle(local); |
| 2812 | mutex_unlock(&local->mtx); |
| 2813 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2814 | mutex_lock(&ifmgd->mtx); |
| 2815 | } |
| 2816 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2817 | static int ieee80211_probe_auth(struct ieee80211_sub_if_data *sdata) |
| 2818 | { |
| 2819 | struct ieee80211_local *local = sdata->local; |
| 2820 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2821 | struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data; |
| 2822 | |
| 2823 | lockdep_assert_held(&ifmgd->mtx); |
| 2824 | |
| 2825 | if (WARN_ON_ONCE(!auth_data)) |
| 2826 | return -EINVAL; |
| 2827 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2828 | auth_data->tries++; |
| 2829 | |
| 2830 | if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2831 | sdata_info(sdata, "authentication with %pM timed out\n", |
| 2832 | auth_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2833 | |
| 2834 | /* |
| 2835 | * Most likely AP is not in the range so remove the |
| 2836 | * bss struct for that AP. |
| 2837 | */ |
| 2838 | cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss); |
| 2839 | |
| 2840 | return -ETIMEDOUT; |
| 2841 | } |
| 2842 | |
Johannes Berg | a1845fc | 2012-06-27 13:18:36 +0200 | [diff] [blame] | 2843 | drv_mgd_prepare_tx(local, sdata); |
| 2844 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2845 | if (auth_data->bss->proberesp_ies) { |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 2846 | u16 trans = 1; |
| 2847 | u16 status = 0; |
| 2848 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2849 | sdata_info(sdata, "send auth to %pM (try %d/%d)\n", |
| 2850 | auth_data->bss->bssid, auth_data->tries, |
| 2851 | IEEE80211_AUTH_MAX_TRIES); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2852 | |
| 2853 | auth_data->expected_transaction = 2; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 2854 | |
| 2855 | if (auth_data->algorithm == WLAN_AUTH_SAE) { |
| 2856 | trans = auth_data->sae_trans; |
| 2857 | status = auth_data->sae_status; |
| 2858 | auth_data->expected_transaction = trans; |
| 2859 | } |
| 2860 | |
| 2861 | ieee80211_send_auth(sdata, trans, auth_data->algorithm, status, |
| 2862 | auth_data->data, auth_data->data_len, |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2863 | auth_data->bss->bssid, |
| 2864 | auth_data->bss->bssid, NULL, 0, 0); |
| 2865 | } else { |
| 2866 | const u8 *ssidie; |
| 2867 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2868 | sdata_info(sdata, "direct probe to %pM (try %d/%i)\n", |
| 2869 | auth_data->bss->bssid, auth_data->tries, |
| 2870 | IEEE80211_AUTH_MAX_TRIES); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2871 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 2872 | rcu_read_lock(); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2873 | ssidie = ieee80211_bss_get_ie(auth_data->bss, WLAN_EID_SSID); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 2874 | if (!ssidie) { |
| 2875 | rcu_read_unlock(); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2876 | return -EINVAL; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 2877 | } |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2878 | /* |
| 2879 | * Direct probe is sent to broadcast address as some APs |
| 2880 | * will not answer to direct packet in unassociated state. |
| 2881 | */ |
| 2882 | ieee80211_send_probe_req(sdata, NULL, ssidie + 2, ssidie[1], |
Johannes Berg | fe94fe0 | 2012-07-30 12:26:34 +0200 | [diff] [blame] | 2883 | NULL, 0, (u32) -1, true, false, |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2884 | auth_data->bss->channel, false); |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 2885 | rcu_read_unlock(); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2886 | } |
| 2887 | |
| 2888 | auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT; |
| 2889 | run_again(ifmgd, auth_data->timeout); |
| 2890 | |
| 2891 | return 0; |
| 2892 | } |
| 2893 | |
| 2894 | static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata) |
| 2895 | { |
| 2896 | struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data; |
| 2897 | struct ieee80211_local *local = sdata->local; |
| 2898 | |
| 2899 | lockdep_assert_held(&sdata->u.mgd.mtx); |
| 2900 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2901 | assoc_data->tries++; |
| 2902 | if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2903 | sdata_info(sdata, "association with %pM timed out\n", |
| 2904 | assoc_data->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2905 | |
| 2906 | /* |
| 2907 | * Most likely AP is not in the range so remove the |
| 2908 | * bss struct for that AP. |
| 2909 | */ |
| 2910 | cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss); |
| 2911 | |
| 2912 | return -ETIMEDOUT; |
| 2913 | } |
| 2914 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2915 | sdata_info(sdata, "associate with %pM (try %d/%d)\n", |
| 2916 | assoc_data->bss->bssid, assoc_data->tries, |
| 2917 | IEEE80211_ASSOC_MAX_TRIES); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2918 | ieee80211_send_assoc(sdata); |
| 2919 | |
| 2920 | assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT; |
| 2921 | run_again(&sdata->u.mgd, assoc_data->timeout); |
| 2922 | |
| 2923 | return 0; |
| 2924 | } |
| 2925 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 2926 | void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 2927 | { |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 2928 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 2929 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 2930 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2931 | mutex_lock(&ifmgd->mtx); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 2932 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 2933 | if (ifmgd->auth_data && |
| 2934 | time_after(jiffies, ifmgd->auth_data->timeout)) { |
| 2935 | if (ifmgd->auth_data->done) { |
| 2936 | /* |
| 2937 | * ok ... we waited for assoc but userspace didn't, |
| 2938 | * so let's just kill the auth data |
| 2939 | */ |
| 2940 | ieee80211_destroy_auth_data(sdata, false); |
| 2941 | } else if (ieee80211_probe_auth(sdata)) { |
| 2942 | u8 bssid[ETH_ALEN]; |
| 2943 | |
| 2944 | memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN); |
| 2945 | |
| 2946 | ieee80211_destroy_auth_data(sdata, false); |
| 2947 | |
| 2948 | mutex_unlock(&ifmgd->mtx); |
| 2949 | cfg80211_send_auth_timeout(sdata->dev, bssid); |
| 2950 | mutex_lock(&ifmgd->mtx); |
| 2951 | } |
| 2952 | } else if (ifmgd->auth_data) |
| 2953 | run_again(ifmgd, ifmgd->auth_data->timeout); |
| 2954 | |
| 2955 | if (ifmgd->assoc_data && |
| 2956 | time_after(jiffies, ifmgd->assoc_data->timeout)) { |
| 2957 | if (!ifmgd->assoc_data->have_beacon || |
| 2958 | ieee80211_do_assoc(sdata)) { |
| 2959 | u8 bssid[ETH_ALEN]; |
| 2960 | |
| 2961 | memcpy(bssid, ifmgd->assoc_data->bss->bssid, ETH_ALEN); |
| 2962 | |
| 2963 | ieee80211_destroy_assoc_data(sdata, false); |
| 2964 | |
| 2965 | mutex_unlock(&ifmgd->mtx); |
| 2966 | cfg80211_send_assoc_timeout(sdata->dev, bssid); |
| 2967 | mutex_lock(&ifmgd->mtx); |
| 2968 | } |
| 2969 | } else if (ifmgd->assoc_data) |
| 2970 | run_again(ifmgd, ifmgd->assoc_data->timeout); |
| 2971 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2972 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
| 2973 | IEEE80211_STA_CONNECTION_POLL) && |
| 2974 | ifmgd->associated) { |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2975 | u8 bssid[ETH_ALEN]; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 2976 | int max_tries; |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2977 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2978 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2979 | |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 2980 | if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 2981 | max_tries = max_nullfunc_tries; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 2982 | else |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 2983 | max_tries = max_probe_tries; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 2984 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 2985 | /* ACK received for nullfunc probing frame */ |
| 2986 | if (!ifmgd->probe_send_count) |
| 2987 | ieee80211_reset_ap_probe(sdata); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2988 | else if (ifmgd->nullfunc_failed) { |
| 2989 | if (ifmgd->probe_send_count < max_tries) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2990 | mlme_dbg(sdata, |
| 2991 | "No ack for nullfunc frame to AP %pM, try %d/%i\n", |
| 2992 | bssid, ifmgd->probe_send_count, |
| 2993 | max_tries); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2994 | ieee80211_mgd_probe_ap_send(sdata); |
| 2995 | } else { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2996 | mlme_dbg(sdata, |
| 2997 | "No ack for nullfunc frame to AP %pM, disconnecting.\n", |
| 2998 | bssid); |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 2999 | ieee80211_sta_connection_lost(sdata, bssid, |
| 3000 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 3001 | } |
| 3002 | } else if (time_is_after_jiffies(ifmgd->probe_timeout)) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3003 | run_again(ifmgd, ifmgd->probe_timeout); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 3004 | else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3005 | mlme_dbg(sdata, |
| 3006 | "Failed to send nullfunc to AP %pM after %dms, disconnecting\n", |
| 3007 | bssid, probe_wait_ms); |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 3008 | ieee80211_sta_connection_lost(sdata, bssid, |
| 3009 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 3010 | } else if (ifmgd->probe_send_count < max_tries) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3011 | mlme_dbg(sdata, |
| 3012 | "No probe response from AP %pM after %dms, try %d/%i\n", |
| 3013 | bssid, probe_wait_ms, |
| 3014 | ifmgd->probe_send_count, max_tries); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 3015 | ieee80211_mgd_probe_ap_send(sdata); |
| 3016 | } else { |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3017 | /* |
| 3018 | * We actually lost the connection ... or did we? |
| 3019 | * Let's make sure! |
| 3020 | */ |
Ben Greear | b38afa8 | 2010-10-07 16:12:06 -0700 | [diff] [blame] | 3021 | wiphy_debug(local->hw.wiphy, |
| 3022 | "%s: No probe response from AP %pM" |
| 3023 | " after %dms, disconnecting.\n", |
| 3024 | sdata->name, |
Ben Greear | 180205b | 2011-02-04 15:30:24 -0800 | [diff] [blame] | 3025 | bssid, probe_wait_ms); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 3026 | |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 3027 | ieee80211_sta_connection_lost(sdata, bssid, |
| 3028 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3029 | } |
| 3030 | } |
| 3031 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3032 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3033 | |
| 3034 | mutex_lock(&local->mtx); |
| 3035 | ieee80211_recalc_idle(local); |
| 3036 | mutex_unlock(&local->mtx); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 3037 | } |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 3038 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3039 | static void ieee80211_sta_bcn_mon_timer(unsigned long data) |
| 3040 | { |
| 3041 | struct ieee80211_sub_if_data *sdata = |
| 3042 | (struct ieee80211_sub_if_data *) data; |
| 3043 | struct ieee80211_local *local = sdata->local; |
| 3044 | |
| 3045 | if (local->quiescing) |
| 3046 | return; |
| 3047 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 3048 | ieee80211_queue_work(&sdata->local->hw, |
| 3049 | &sdata->u.mgd.beacon_connection_loss_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3050 | } |
| 3051 | |
| 3052 | static void ieee80211_sta_conn_mon_timer(unsigned long data) |
| 3053 | { |
| 3054 | struct ieee80211_sub_if_data *sdata = |
| 3055 | (struct ieee80211_sub_if_data *) data; |
| 3056 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3057 | struct ieee80211_local *local = sdata->local; |
| 3058 | |
| 3059 | if (local->quiescing) |
| 3060 | return; |
| 3061 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 3062 | ieee80211_queue_work(&local->hw, &ifmgd->monitor_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3063 | } |
| 3064 | |
| 3065 | static void ieee80211_sta_monitor_work(struct work_struct *work) |
| 3066 | { |
| 3067 | struct ieee80211_sub_if_data *sdata = |
| 3068 | container_of(work, struct ieee80211_sub_if_data, |
| 3069 | u.mgd.monitor_work); |
| 3070 | |
| 3071 | ieee80211_mgd_probe_ap(sdata, false); |
| 3072 | } |
| 3073 | |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 3074 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) |
| 3075 | { |
Eliad Peller | 494f1fe | 2012-02-19 15:26:09 +0200 | [diff] [blame] | 3076 | u32 flags; |
| 3077 | |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 3078 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 3079 | __ieee80211_stop_poll(sdata); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 3080 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3081 | /* let's probe the connection once */ |
Eliad Peller | 494f1fe | 2012-02-19 15:26:09 +0200 | [diff] [blame] | 3082 | flags = sdata->local->hw.flags; |
| 3083 | if (!(flags & IEEE80211_HW_CONNECTION_MONITOR)) |
| 3084 | ieee80211_queue_work(&sdata->local->hw, |
| 3085 | &sdata->u.mgd.monitor_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3086 | /* and do all the other regular work too */ |
Johannes Berg | 64592c8 | 2010-06-10 10:21:31 +0200 | [diff] [blame] | 3087 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 3088 | } |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 3089 | } |
| 3090 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 3091 | #ifdef CONFIG_PM |
| 3092 | void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata) |
| 3093 | { |
| 3094 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3095 | |
| 3096 | /* |
| 3097 | * we need to use atomic bitops for the running bits |
| 3098 | * only because both timers might fire at the same |
| 3099 | * time -- the code here is properly synchronised. |
| 3100 | */ |
| 3101 | |
Johannes Berg | d1f5b7a | 2010-08-05 17:05:55 +0200 | [diff] [blame] | 3102 | cancel_work_sync(&ifmgd->request_smps_work); |
| 3103 | |
Johannes Berg | 0ecfe80 | 2011-11-09 12:14:16 +0100 | [diff] [blame] | 3104 | cancel_work_sync(&ifmgd->monitor_work); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 3105 | cancel_work_sync(&ifmgd->beacon_connection_loss_work); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 3106 | cancel_work_sync(&ifmgd->csa_connection_drop_work); |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 3107 | if (del_timer_sync(&ifmgd->timer)) |
| 3108 | set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running); |
| 3109 | |
| 3110 | cancel_work_sync(&ifmgd->chswitch_work); |
| 3111 | if (del_timer_sync(&ifmgd->chswitch_timer)) |
| 3112 | set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3113 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3114 | /* these will just be re-established on connection */ |
| 3115 | del_timer_sync(&ifmgd->conn_mon_timer); |
| 3116 | del_timer_sync(&ifmgd->bcn_mon_timer); |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 3117 | } |
| 3118 | |
| 3119 | void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata) |
| 3120 | { |
| 3121 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3122 | |
Rajkumar Manoharan | 676b58c | 2011-07-07 23:33:39 +0530 | [diff] [blame] | 3123 | if (!ifmgd->associated) |
| 3124 | return; |
| 3125 | |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 3126 | if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) { |
| 3127 | sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME; |
| 3128 | mutex_lock(&ifmgd->mtx); |
| 3129 | if (ifmgd->associated) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3130 | mlme_dbg(sdata, |
| 3131 | "driver requested disconnect after resume\n"); |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 3132 | ieee80211_sta_connection_lost(sdata, |
| 3133 | ifmgd->associated->bssid, |
| 3134 | WLAN_REASON_UNSPECIFIED); |
| 3135 | mutex_unlock(&ifmgd->mtx); |
| 3136 | return; |
| 3137 | } |
| 3138 | mutex_unlock(&ifmgd->mtx); |
| 3139 | } |
| 3140 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 3141 | if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running)) |
| 3142 | add_timer(&ifmgd->timer); |
| 3143 | if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running)) |
| 3144 | add_timer(&ifmgd->chswitch_timer); |
Felix Fietkau | c8a7972 | 2010-11-19 22:55:37 +0100 | [diff] [blame] | 3145 | ieee80211_sta_reset_beacon_monitor(sdata); |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 3146 | |
| 3147 | mutex_lock(&sdata->local->mtx); |
Felix Fietkau | 4609097 | 2010-11-23 20:28:03 +0100 | [diff] [blame] | 3148 | ieee80211_restart_sta_timer(sdata); |
Stanislaw Gruszka | 925e64c | 2012-05-16 15:27:20 +0200 | [diff] [blame] | 3149 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 3150 | } |
| 3151 | #endif |
| 3152 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 3153 | /* interface setup */ |
| 3154 | void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) |
| 3155 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3156 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 3157 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3158 | ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3159 | INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3160 | INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 3161 | INIT_WORK(&ifmgd->beacon_connection_loss_work, |
| 3162 | ieee80211_beacon_connection_loss_work); |
Johannes Berg | 882a7c6 | 2012-08-01 22:32:45 +0200 | [diff] [blame] | 3163 | INIT_WORK(&ifmgd->csa_connection_drop_work, |
| 3164 | ieee80211_csa_connection_drop_work); |
Johannes Berg | d1f5b7a | 2010-08-05 17:05:55 +0200 | [diff] [blame] | 3165 | INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3166 | setup_timer(&ifmgd->timer, ieee80211_sta_timer, |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 3167 | (unsigned long) sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 3168 | setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, |
| 3169 | (unsigned long) sdata); |
| 3170 | setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, |
| 3171 | (unsigned long) sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 3172 | setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, |
Sujith | c481ec9 | 2009-01-06 09:28:37 +0530 | [diff] [blame] | 3173 | (unsigned long) sdata); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 3174 | |
Johannes Berg | ab1faea | 2009-07-01 21:41:17 +0200 | [diff] [blame] | 3175 | ifmgd->flags = 0; |
Mohammed Shafi Shajakhan | 1478acb | 2011-12-14 19:46:08 +0530 | [diff] [blame] | 3176 | ifmgd->powersave = sdata->wdev.ps; |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 3177 | ifmgd->uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES; |
| 3178 | ifmgd->uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN; |
Johannes Berg | bbbdff9 | 2009-04-16 13:27:42 +0200 | [diff] [blame] | 3179 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3180 | mutex_init(&ifmgd->mtx); |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 3181 | |
| 3182 | if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS) |
| 3183 | ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC; |
| 3184 | else |
| 3185 | ifmgd->req_smps = IEEE80211_SMPS_OFF; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | /* scan finished notification */ |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 3189 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) |
| 3190 | { |
Johannes Berg | 31ee67a | 2012-07-06 21:18:24 +0200 | [diff] [blame] | 3191 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 3192 | |
| 3193 | /* Restart STA timers */ |
| 3194 | rcu_read_lock(); |
| 3195 | list_for_each_entry_rcu(sdata, &local->interfaces, list) |
| 3196 | ieee80211_restart_sta_timer(sdata); |
| 3197 | rcu_read_unlock(); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 3198 | } |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 3199 | |
| 3200 | int ieee80211_max_network_latency(struct notifier_block *nb, |
| 3201 | unsigned long data, void *dummy) |
| 3202 | { |
| 3203 | s32 latency_usec = (s32) data; |
| 3204 | struct ieee80211_local *local = |
| 3205 | container_of(nb, struct ieee80211_local, |
| 3206 | network_latency_notifier); |
| 3207 | |
| 3208 | mutex_lock(&local->iflist_mtx); |
| 3209 | ieee80211_recalc_ps(local, latency_usec); |
| 3210 | mutex_unlock(&local->iflist_mtx); |
| 3211 | |
| 3212 | return 0; |
| 3213 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3214 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 3215 | static u32 chandef_downgrade(struct cfg80211_chan_def *c) |
| 3216 | { |
| 3217 | u32 ret; |
| 3218 | int tmp; |
| 3219 | |
| 3220 | switch (c->width) { |
| 3221 | case NL80211_CHAN_WIDTH_20: |
| 3222 | c->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 3223 | ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT; |
| 3224 | break; |
| 3225 | case NL80211_CHAN_WIDTH_40: |
| 3226 | c->width = NL80211_CHAN_WIDTH_20; |
| 3227 | c->center_freq1 = c->chan->center_freq; |
| 3228 | ret = IEEE80211_STA_DISABLE_40MHZ | |
| 3229 | IEEE80211_STA_DISABLE_VHT; |
| 3230 | break; |
| 3231 | case NL80211_CHAN_WIDTH_80: |
| 3232 | tmp = (30 + c->chan->center_freq - c->center_freq1)/20; |
| 3233 | /* n_P40 */ |
| 3234 | tmp /= 2; |
| 3235 | /* freq_P40 */ |
| 3236 | c->center_freq1 = c->center_freq1 - 20 + 40 * tmp; |
| 3237 | c->width = NL80211_CHAN_WIDTH_40; |
| 3238 | ret = IEEE80211_STA_DISABLE_VHT; |
| 3239 | break; |
| 3240 | case NL80211_CHAN_WIDTH_80P80: |
| 3241 | c->center_freq2 = 0; |
| 3242 | c->width = NL80211_CHAN_WIDTH_80; |
| 3243 | ret = IEEE80211_STA_DISABLE_80P80MHZ | |
| 3244 | IEEE80211_STA_DISABLE_160MHZ; |
| 3245 | break; |
| 3246 | case NL80211_CHAN_WIDTH_160: |
| 3247 | /* n_P20 */ |
| 3248 | tmp = (70 + c->chan->center_freq - c->center_freq1)/20; |
| 3249 | /* n_P80 */ |
| 3250 | tmp /= 4; |
| 3251 | c->center_freq1 = c->center_freq1 - 40 + 80 * tmp; |
| 3252 | c->width = NL80211_CHAN_WIDTH_80; |
| 3253 | ret = IEEE80211_STA_DISABLE_80P80MHZ | |
| 3254 | IEEE80211_STA_DISABLE_160MHZ; |
| 3255 | break; |
| 3256 | default: |
| 3257 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 3258 | WARN_ON_ONCE(1); |
| 3259 | c->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 3260 | ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT; |
| 3261 | break; |
| 3262 | } |
| 3263 | |
| 3264 | WARN_ON_ONCE(!cfg80211_chandef_valid(c)); |
| 3265 | |
| 3266 | return ret; |
| 3267 | } |
| 3268 | |
| 3269 | static u32 |
| 3270 | ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata, |
| 3271 | struct ieee80211_supported_band *sband, |
| 3272 | struct ieee80211_channel *channel, |
| 3273 | const struct ieee80211_ht_operation *ht_oper, |
| 3274 | const struct ieee80211_vht_operation *vht_oper, |
| 3275 | struct cfg80211_chan_def *chandef) |
| 3276 | { |
| 3277 | struct cfg80211_chan_def vht_chandef; |
| 3278 | u32 ht_cfreq, ret; |
| 3279 | |
| 3280 | chandef->chan = channel; |
| 3281 | chandef->width = NL80211_CHAN_WIDTH_20_NOHT; |
| 3282 | chandef->center_freq1 = channel->center_freq; |
| 3283 | chandef->center_freq2 = 0; |
| 3284 | |
| 3285 | if (!ht_oper || !sband->ht_cap.ht_supported) { |
| 3286 | ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT; |
| 3287 | goto out; |
| 3288 | } |
| 3289 | |
| 3290 | chandef->width = NL80211_CHAN_WIDTH_20; |
| 3291 | |
| 3292 | ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan, |
| 3293 | channel->band); |
| 3294 | /* check that channel matches the right operating channel */ |
| 3295 | if (channel->center_freq != ht_cfreq) { |
| 3296 | /* |
| 3297 | * It's possible that some APs are confused here; |
| 3298 | * Netgear WNDR3700 sometimes reports 4 higher than |
| 3299 | * the actual channel in association responses, but |
| 3300 | * since we look at probe response/beacon data here |
| 3301 | * it should be OK. |
| 3302 | */ |
| 3303 | sdata_info(sdata, |
| 3304 | "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n", |
| 3305 | channel->center_freq, ht_cfreq, |
| 3306 | ht_oper->primary_chan, channel->band); |
| 3307 | ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT; |
| 3308 | goto out; |
| 3309 | } |
| 3310 | |
| 3311 | /* check 40 MHz support, if we have it */ |
| 3312 | if (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) { |
| 3313 | switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { |
| 3314 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 3315 | chandef->width = NL80211_CHAN_WIDTH_40; |
| 3316 | chandef->center_freq1 += 10; |
| 3317 | break; |
| 3318 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 3319 | chandef->width = NL80211_CHAN_WIDTH_40; |
| 3320 | chandef->center_freq1 -= 10; |
| 3321 | break; |
| 3322 | } |
| 3323 | } else { |
| 3324 | /* 40 MHz (and 80 MHz) must be supported for VHT */ |
| 3325 | ret = IEEE80211_STA_DISABLE_VHT; |
| 3326 | goto out; |
| 3327 | } |
| 3328 | |
| 3329 | if (!vht_oper || !sband->vht_cap.vht_supported) { |
| 3330 | ret = IEEE80211_STA_DISABLE_VHT; |
| 3331 | goto out; |
| 3332 | } |
| 3333 | |
| 3334 | vht_chandef.chan = channel; |
| 3335 | vht_chandef.center_freq1 = |
| 3336 | ieee80211_channel_to_frequency(vht_oper->center_freq_seg1_idx, |
| 3337 | channel->band); |
| 3338 | vht_chandef.center_freq2 = 0; |
| 3339 | |
| 3340 | if (vht_oper->center_freq_seg2_idx) |
| 3341 | vht_chandef.center_freq2 = |
| 3342 | ieee80211_channel_to_frequency( |
| 3343 | vht_oper->center_freq_seg2_idx, |
| 3344 | channel->band); |
| 3345 | |
| 3346 | switch (vht_oper->chan_width) { |
| 3347 | case IEEE80211_VHT_CHANWIDTH_USE_HT: |
| 3348 | vht_chandef.width = chandef->width; |
| 3349 | break; |
| 3350 | case IEEE80211_VHT_CHANWIDTH_80MHZ: |
| 3351 | vht_chandef.width = NL80211_CHAN_WIDTH_80; |
| 3352 | break; |
| 3353 | case IEEE80211_VHT_CHANWIDTH_160MHZ: |
| 3354 | vht_chandef.width = NL80211_CHAN_WIDTH_160; |
| 3355 | break; |
| 3356 | case IEEE80211_VHT_CHANWIDTH_80P80MHZ: |
| 3357 | vht_chandef.width = NL80211_CHAN_WIDTH_80P80; |
| 3358 | break; |
| 3359 | default: |
| 3360 | sdata_info(sdata, |
| 3361 | "AP VHT operation IE has invalid channel width (%d), disable VHT\n", |
| 3362 | vht_oper->chan_width); |
| 3363 | ret = IEEE80211_STA_DISABLE_VHT; |
| 3364 | goto out; |
| 3365 | } |
| 3366 | |
| 3367 | if (!cfg80211_chandef_valid(&vht_chandef)) { |
| 3368 | sdata_info(sdata, |
| 3369 | "AP VHT information is invalid, disable VHT\n"); |
| 3370 | ret = IEEE80211_STA_DISABLE_VHT; |
| 3371 | goto out; |
| 3372 | } |
| 3373 | |
| 3374 | if (cfg80211_chandef_identical(chandef, &vht_chandef)) { |
| 3375 | ret = 0; |
| 3376 | goto out; |
| 3377 | } |
| 3378 | |
| 3379 | if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) { |
| 3380 | sdata_info(sdata, |
| 3381 | "AP VHT information doesn't match HT, disable VHT\n"); |
| 3382 | ret = IEEE80211_STA_DISABLE_VHT; |
| 3383 | goto out; |
| 3384 | } |
| 3385 | |
| 3386 | *chandef = vht_chandef; |
| 3387 | |
| 3388 | ret = 0; |
| 3389 | |
| 3390 | while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef, |
| 3391 | IEEE80211_CHAN_DISABLED)) { |
| 3392 | if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) { |
| 3393 | ret = IEEE80211_STA_DISABLE_HT | |
| 3394 | IEEE80211_STA_DISABLE_VHT; |
| 3395 | goto out; |
| 3396 | } |
| 3397 | |
| 3398 | ret = chandef_downgrade(chandef); |
| 3399 | } |
| 3400 | |
| 3401 | if (chandef->width != vht_chandef.width) |
| 3402 | sdata_info(sdata, |
| 3403 | "local regulatory prevented using AP HT/VHT configuration, downgraded\n"); |
| 3404 | |
| 3405 | out: |
| 3406 | WARN_ON_ONCE(!cfg80211_chandef_valid(chandef)); |
| 3407 | return ret; |
| 3408 | } |
| 3409 | |
| 3410 | static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata, |
| 3411 | struct cfg80211_bss *cbss) |
| 3412 | { |
| 3413 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3414 | const u8 *ht_cap_ie, *vht_cap_ie; |
| 3415 | const struct ieee80211_ht_cap *ht_cap; |
| 3416 | const struct ieee80211_vht_cap *vht_cap; |
| 3417 | u8 chains = 1; |
| 3418 | |
| 3419 | if (ifmgd->flags & IEEE80211_STA_DISABLE_HT) |
| 3420 | return chains; |
| 3421 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 3422 | ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 3423 | if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) { |
| 3424 | ht_cap = (void *)(ht_cap_ie + 2); |
| 3425 | chains = ieee80211_mcs_to_chains(&ht_cap->mcs); |
| 3426 | /* |
| 3427 | * TODO: use "Tx Maximum Number Spatial Streams Supported" and |
| 3428 | * "Tx Unequal Modulation Supported" fields. |
| 3429 | */ |
| 3430 | } |
| 3431 | |
| 3432 | if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT) |
| 3433 | return chains; |
| 3434 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 3435 | vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 3436 | if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) { |
| 3437 | u8 nss; |
| 3438 | u16 tx_mcs_map; |
| 3439 | |
| 3440 | vht_cap = (void *)(vht_cap_ie + 2); |
| 3441 | tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map); |
| 3442 | for (nss = 8; nss > 0; nss--) { |
| 3443 | if (((tx_mcs_map >> (2 * (nss - 1))) & 3) != |
| 3444 | IEEE80211_VHT_MCS_NOT_SUPPORTED) |
| 3445 | break; |
| 3446 | } |
| 3447 | /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */ |
| 3448 | chains = max(chains, nss); |
| 3449 | } |
| 3450 | |
| 3451 | return chains; |
| 3452 | } |
| 3453 | |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 3454 | static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata, |
| 3455 | struct cfg80211_bss *cbss) |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3456 | { |
| 3457 | struct ieee80211_local *local = sdata->local; |
| 3458 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3459 | const struct ieee80211_ht_operation *ht_oper = NULL; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 3460 | const struct ieee80211_vht_operation *vht_oper = NULL; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3461 | struct ieee80211_supported_band *sband; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 3462 | struct cfg80211_chan_def chandef; |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 3463 | int ret; |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3464 | |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3465 | sband = local->hw.wiphy->bands[cbss->channel->band]; |
| 3466 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 3467 | ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ | |
| 3468 | IEEE80211_STA_DISABLE_80P80MHZ | |
| 3469 | IEEE80211_STA_DISABLE_160MHZ); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3470 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 3471 | rcu_read_lock(); |
| 3472 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 3473 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) && |
| 3474 | sband->ht_cap.ht_supported) { |
| 3475 | const u8 *ht_oper_ie; |
| 3476 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 3477 | ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3478 | if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper)) |
| 3479 | ht_oper = (void *)(ht_oper_ie + 2); |
| 3480 | } |
| 3481 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 3482 | if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) && |
| 3483 | sband->vht_cap.vht_supported) { |
| 3484 | const u8 *vht_oper_ie; |
| 3485 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 3486 | vht_oper_ie = ieee80211_bss_get_ie(cbss, |
| 3487 | WLAN_EID_VHT_OPERATION); |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 3488 | if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper)) |
| 3489 | vht_oper = (void *)(vht_oper_ie + 2); |
| 3490 | if (vht_oper && !ht_oper) { |
| 3491 | vht_oper = NULL; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3492 | sdata_info(sdata, |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 3493 | "AP advertised VHT without HT, disabling both\n"); |
| 3494 | sdata->flags |= IEEE80211_STA_DISABLE_HT; |
| 3495 | sdata->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3496 | } |
| 3497 | } |
| 3498 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 3499 | ifmgd->flags |= ieee80211_determine_chantype(sdata, sband, |
| 3500 | cbss->channel, |
| 3501 | ht_oper, vht_oper, |
| 3502 | &chandef); |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 3503 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 3504 | sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss), |
| 3505 | local->rx_chains); |
Johannes Berg | 24398e3 | 2012-03-28 10:58:36 +0200 | [diff] [blame] | 3506 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 3507 | rcu_read_unlock(); |
| 3508 | |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 3509 | /* will change later if needed */ |
| 3510 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
| 3511 | |
Johannes Berg | f2d9d27 | 2012-11-22 14:11:39 +0100 | [diff] [blame] | 3512 | /* |
| 3513 | * If this fails (possibly due to channel context sharing |
| 3514 | * on incompatible channels, e.g. 80+80 and 160 sharing the |
| 3515 | * same control channel) try to use a smaller bandwidth. |
| 3516 | */ |
| 3517 | ret = ieee80211_vif_use_channel(sdata, &chandef, |
| 3518 | IEEE80211_CHANCTX_SHARED); |
| 3519 | while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) |
| 3520 | ifmgd->flags |= chandef_downgrade(&chandef); |
| 3521 | return ret; |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata, |
| 3525 | struct cfg80211_bss *cbss, bool assoc) |
| 3526 | { |
| 3527 | struct ieee80211_local *local = sdata->local; |
| 3528 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3529 | struct ieee80211_bss *bss = (void *)cbss->priv; |
| 3530 | struct sta_info *new_sta = NULL; |
| 3531 | bool have_sta = false; |
| 3532 | int err; |
| 3533 | |
| 3534 | if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) |
| 3535 | return -EINVAL; |
| 3536 | |
| 3537 | if (assoc) { |
| 3538 | rcu_read_lock(); |
| 3539 | have_sta = sta_info_get(sdata, cbss->bssid); |
| 3540 | rcu_read_unlock(); |
| 3541 | } |
| 3542 | |
| 3543 | if (!have_sta) { |
| 3544 | new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL); |
| 3545 | if (!new_sta) |
| 3546 | return -ENOMEM; |
| 3547 | } |
| 3548 | |
| 3549 | mutex_lock(&local->mtx); |
| 3550 | ieee80211_recalc_idle(sdata->local); |
| 3551 | mutex_unlock(&local->mtx); |
| 3552 | |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 3553 | if (new_sta) { |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 3554 | u32 rates = 0, basic_rates = 0; |
| 3555 | bool have_higher_than_11mbit; |
| 3556 | int min_rate = INT_MAX, min_rate_index = -1; |
Johannes Berg | b17166a | 2012-07-27 11:41:27 +0200 | [diff] [blame] | 3557 | struct ieee80211_supported_band *sband; |
| 3558 | |
| 3559 | sband = local->hw.wiphy->bands[cbss->channel->band]; |
| 3560 | |
| 3561 | err = ieee80211_prep_channel(sdata, cbss); |
| 3562 | if (err) { |
| 3563 | sta_info_free(local, new_sta); |
| 3564 | return err; |
| 3565 | } |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 3566 | |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 3567 | ieee80211_get_rates(sband, bss->supp_rates, |
| 3568 | bss->supp_rates_len, |
| 3569 | &rates, &basic_rates, |
| 3570 | &have_higher_than_11mbit, |
| 3571 | &min_rate, &min_rate_index); |
| 3572 | |
| 3573 | /* |
| 3574 | * This used to be a workaround for basic rates missing |
| 3575 | * in the association response frame. Now that we no |
| 3576 | * longer use the basic rates from there, it probably |
| 3577 | * doesn't happen any more, but keep the workaround so |
| 3578 | * in case some *other* APs are buggy in different ways |
| 3579 | * we can connect -- with a warning. |
| 3580 | */ |
| 3581 | if (!basic_rates && min_rate_index >= 0) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3582 | sdata_info(sdata, |
| 3583 | "No basic rates, using min rate instead\n"); |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 3584 | basic_rates = BIT(min_rate_index); |
| 3585 | } |
| 3586 | |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 3587 | new_sta->sta.supp_rates[cbss->channel->band] = rates; |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 3588 | sdata->vif.bss_conf.basic_rates = basic_rates; |
| 3589 | |
| 3590 | /* cf. IEEE 802.11 9.2.12 */ |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 3591 | if (cbss->channel->band == IEEE80211_BAND_2GHZ && |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 3592 | have_higher_than_11mbit) |
| 3593 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; |
| 3594 | else |
| 3595 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; |
| 3596 | |
| 3597 | memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN); |
| 3598 | |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 3599 | /* set timing information */ |
| 3600 | sdata->vif.bss_conf.beacon_int = cbss->beacon_interval; |
| 3601 | sdata->vif.bss_conf.sync_tsf = cbss->tsf; |
| 3602 | sdata->vif.bss_conf.sync_device_ts = bss->device_ts; |
| 3603 | |
| 3604 | /* tell driver about BSSID, basic rates and timing */ |
Johannes Berg | 5d6a1b0 | 2012-03-08 15:02:08 +0100 | [diff] [blame] | 3605 | ieee80211_bss_info_change_notify(sdata, |
Johannes Berg | 8c358bc | 2012-05-22 22:13:05 +0200 | [diff] [blame] | 3606 | BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES | |
| 3607 | BSS_CHANGED_BEACON_INT); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3608 | |
| 3609 | if (assoc) |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 3610 | sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3611 | |
Johannes Berg | 13e0c8e | 2012-07-27 10:43:16 +0200 | [diff] [blame] | 3612 | err = sta_info_insert(new_sta); |
| 3613 | new_sta = NULL; |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3614 | if (err) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3615 | sdata_info(sdata, |
| 3616 | "failed to insert STA entry for the AP (error %d)\n", |
| 3617 | err); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3618 | return err; |
| 3619 | } |
| 3620 | } else |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3621 | WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid)); |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3622 | |
| 3623 | return 0; |
| 3624 | } |
| 3625 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3626 | /* config hooks */ |
| 3627 | int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, |
| 3628 | struct cfg80211_auth_request *req) |
| 3629 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3630 | struct ieee80211_local *local = sdata->local; |
| 3631 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 3632 | struct ieee80211_mgd_auth_data *auth_data; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3633 | u16 auth_alg; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3634 | int err; |
| 3635 | |
| 3636 | /* prepare auth data structure */ |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3637 | |
| 3638 | switch (req->auth_type) { |
| 3639 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 3640 | auth_alg = WLAN_AUTH_OPEN; |
| 3641 | break; |
| 3642 | case NL80211_AUTHTYPE_SHARED_KEY: |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3643 | if (IS_ERR(local->wep_tx_tfm)) |
Johannes Berg | 9dca9c4 | 2010-07-21 10:09:25 +0200 | [diff] [blame] | 3644 | return -EOPNOTSUPP; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3645 | auth_alg = WLAN_AUTH_SHARED_KEY; |
| 3646 | break; |
| 3647 | case NL80211_AUTHTYPE_FT: |
| 3648 | auth_alg = WLAN_AUTH_FT; |
| 3649 | break; |
| 3650 | case NL80211_AUTHTYPE_NETWORK_EAP: |
| 3651 | auth_alg = WLAN_AUTH_LEAP; |
| 3652 | break; |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 3653 | case NL80211_AUTHTYPE_SAE: |
| 3654 | auth_alg = WLAN_AUTH_SAE; |
| 3655 | break; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3656 | default: |
| 3657 | return -EOPNOTSUPP; |
| 3658 | } |
| 3659 | |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 3660 | auth_data = kzalloc(sizeof(*auth_data) + req->sae_data_len + |
| 3661 | req->ie_len, GFP_KERNEL); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3662 | if (!auth_data) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3663 | return -ENOMEM; |
| 3664 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3665 | auth_data->bss = req->bss; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3666 | |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 3667 | if (req->sae_data_len >= 4) { |
| 3668 | __le16 *pos = (__le16 *) req->sae_data; |
| 3669 | auth_data->sae_trans = le16_to_cpu(pos[0]); |
| 3670 | auth_data->sae_status = le16_to_cpu(pos[1]); |
| 3671 | memcpy(auth_data->data, req->sae_data + 4, |
| 3672 | req->sae_data_len - 4); |
| 3673 | auth_data->data_len += req->sae_data_len - 4; |
| 3674 | } |
| 3675 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3676 | if (req->ie && req->ie_len) { |
Jouni Malinen | 6b8ece3 | 2012-09-30 19:29:40 +0300 | [diff] [blame] | 3677 | memcpy(&auth_data->data[auth_data->data_len], |
| 3678 | req->ie, req->ie_len); |
| 3679 | auth_data->data_len += req->ie_len; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3680 | } |
| 3681 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3682 | if (req->key && req->key_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3683 | auth_data->key_len = req->key_len; |
| 3684 | auth_data->key_idx = req->key_idx; |
| 3685 | memcpy(auth_data->key, req->key, req->key_len); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 3686 | } |
| 3687 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3688 | auth_data->algorithm = auth_alg; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3689 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3690 | /* try to authenticate/probe */ |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 3691 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3692 | mutex_lock(&ifmgd->mtx); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3693 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3694 | if ((ifmgd->auth_data && !ifmgd->auth_data->done) || |
| 3695 | ifmgd->assoc_data) { |
| 3696 | err = -EBUSY; |
| 3697 | goto err_free; |
| 3698 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3699 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3700 | if (ifmgd->auth_data) |
| 3701 | ieee80211_destroy_auth_data(sdata, false); |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3702 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3703 | /* prep auth_data so we don't go into idle on disassoc */ |
| 3704 | ifmgd->auth_data = auth_data; |
| 3705 | |
| 3706 | if (ifmgd->associated) |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3707 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3708 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3709 | sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3710 | |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3711 | err = ieee80211_prep_connection(sdata, req->bss, false); |
| 3712 | if (err) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3713 | goto err_clear; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3714 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3715 | err = ieee80211_probe_auth(sdata); |
| 3716 | if (err) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3717 | sta_info_destroy_addr(sdata, req->bss->bssid); |
| 3718 | goto err_clear; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3719 | } |
| 3720 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3721 | /* hold our own reference */ |
| 3722 | cfg80211_ref_bss(auth_data->bss); |
| 3723 | err = 0; |
| 3724 | goto out_unlock; |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 3725 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3726 | err_clear: |
Eliad Peller | 3d2abdf | 2012-09-04 17:44:45 +0300 | [diff] [blame] | 3727 | memset(ifmgd->bssid, 0, ETH_ALEN); |
| 3728 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3729 | ifmgd->auth_data = NULL; |
| 3730 | err_free: |
| 3731 | kfree(auth_data); |
| 3732 | out_unlock: |
| 3733 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 3734 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3735 | return err; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3736 | } |
| 3737 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3738 | int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, |
| 3739 | struct cfg80211_assoc_request *req) |
| 3740 | { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3741 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3742 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 3743 | struct ieee80211_bss *bss = (void *)req->bss->priv; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3744 | struct ieee80211_mgd_assoc_data *assoc_data; |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 3745 | struct ieee80211_supported_band *sband; |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 3746 | const u8 *ssidie, *ht_ie; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3747 | int i, err; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3748 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3749 | assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL); |
| 3750 | if (!assoc_data) |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3751 | return -ENOMEM; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3752 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 3753 | rcu_read_lock(); |
| 3754 | ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); |
| 3755 | if (!ssidie) { |
| 3756 | rcu_read_unlock(); |
| 3757 | kfree(assoc_data); |
| 3758 | return -EINVAL; |
| 3759 | } |
| 3760 | memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]); |
| 3761 | assoc_data->ssid_len = ssidie[1]; |
| 3762 | rcu_read_unlock(); |
| 3763 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3764 | mutex_lock(&ifmgd->mtx); |
| 3765 | |
| 3766 | if (ifmgd->associated) |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3767 | ieee80211_set_disassoc(sdata, 0, 0, false, NULL); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3768 | |
| 3769 | if (ifmgd->auth_data && !ifmgd->auth_data->done) { |
| 3770 | err = -EBUSY; |
| 3771 | goto err_free; |
Guy Eilam | 2a33bee | 2011-08-17 15:18:15 +0300 | [diff] [blame] | 3772 | } |
| 3773 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3774 | if (ifmgd->assoc_data) { |
| 3775 | err = -EBUSY; |
| 3776 | goto err_free; |
| 3777 | } |
| 3778 | |
| 3779 | if (ifmgd->auth_data) { |
| 3780 | bool match; |
| 3781 | |
| 3782 | /* keep sta info, bssid if matching */ |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 3783 | match = ether_addr_equal(ifmgd->bssid, req->bss->bssid); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3784 | ieee80211_destroy_auth_data(sdata, match); |
| 3785 | } |
| 3786 | |
| 3787 | /* prepare assoc data */ |
Johannes Berg | 19c3b83 | 2012-08-01 20:13:36 +0200 | [diff] [blame] | 3788 | |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 3789 | ifmgd->beacon_crc_valid = false; |
| 3790 | |
Johannes Berg | de5036a | 2012-03-08 15:02:03 +0100 | [diff] [blame] | 3791 | /* |
| 3792 | * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode. |
| 3793 | * We still associate in non-HT mode (11a/b/g) if any one of these |
| 3794 | * ciphers is configured as pairwise. |
| 3795 | * We can set this to true for non-11n hardware, that'll be checked |
| 3796 | * separately along with the peer capabilities. |
| 3797 | */ |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 3798 | for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3799 | if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || |
| 3800 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP || |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 3801 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) { |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 3802 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 3803 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 3804 | netdev_info(sdata->dev, |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 3805 | "disabling HT/VHT due to WEP/TKIP use\n"); |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 3806 | } |
| 3807 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3808 | |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 3809 | if (req->flags & ASSOC_REQ_DISABLE_HT) { |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 3810 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 3811 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
| 3812 | } |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 3813 | |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 3814 | /* Also disable HT if we don't support it or the AP doesn't use WMM */ |
| 3815 | sband = local->hw.wiphy->bands[req->bss->channel->band]; |
| 3816 | if (!sband->ht_cap.ht_supported || |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 3817 | local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) { |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 3818 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Johannes Berg | 1b49de2 | 2012-07-27 10:29:14 +0200 | [diff] [blame] | 3819 | if (!bss->wmm_used) |
| 3820 | netdev_info(sdata->dev, |
| 3821 | "disabling HT as WMM/QoS is not supported by the AP\n"); |
Johannes Berg | 1c4cb92 | 2012-05-30 15:57:00 +0200 | [diff] [blame] | 3822 | } |
Johannes Berg | 4e74bfd | 2012-03-08 15:02:04 +0100 | [diff] [blame] | 3823 | |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 3824 | /* disable VHT if we don't support it or the AP doesn't use WMM */ |
| 3825 | if (!sband->vht_cap.vht_supported || |
| 3826 | local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used) { |
| 3827 | ifmgd->flags |= IEEE80211_STA_DISABLE_VHT; |
Johannes Berg | 1b49de2 | 2012-07-27 10:29:14 +0200 | [diff] [blame] | 3828 | if (!bss->wmm_used) |
| 3829 | netdev_info(sdata->dev, |
| 3830 | "disabling VHT as WMM/QoS is not supported by the AP\n"); |
Mahesh Palivela | d545dab | 2012-07-24 03:33:10 +0000 | [diff] [blame] | 3831 | } |
| 3832 | |
Ben Greear | ef96a842 | 2011-11-18 11:32:00 -0800 | [diff] [blame] | 3833 | memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa)); |
| 3834 | memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask, |
| 3835 | sizeof(ifmgd->ht_capa_mask)); |
| 3836 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3837 | if (req->ie && req->ie_len) { |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3838 | memcpy(assoc_data->ie, req->ie, req->ie_len); |
| 3839 | assoc_data->ie_len = req->ie_len; |
| 3840 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3841 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3842 | assoc_data->bss = req->bss; |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 3843 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3844 | if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) { |
| 3845 | if (ifmgd->powersave) |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 3846 | sdata->smps_mode = IEEE80211_SMPS_DYNAMIC; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3847 | else |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 3848 | sdata->smps_mode = IEEE80211_SMPS_OFF; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3849 | } else |
Johannes Berg | 04ecd25 | 2012-09-11 14:34:12 +0200 | [diff] [blame] | 3850 | sdata->smps_mode = ifmgd->req_smps; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 3851 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3852 | assoc_data->capability = req->bss->capability; |
Johannes Berg | 32c5057 | 2012-03-28 11:04:29 +0200 | [diff] [blame] | 3853 | assoc_data->wmm = bss->wmm_used && |
| 3854 | (local->hw.queues >= IEEE80211_NUM_ACS); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3855 | assoc_data->supp_rates = bss->supp_rates; |
| 3856 | assoc_data->supp_rates_len = bss->supp_rates_len; |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 3857 | |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 3858 | rcu_read_lock(); |
Johannes Berg | 9dde642 | 2012-05-16 23:43:19 +0200 | [diff] [blame] | 3859 | ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION); |
| 3860 | if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation)) |
| 3861 | assoc_data->ap_ht_param = |
| 3862 | ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param; |
| 3863 | else |
Johannes Berg | a8243b7 | 2012-11-22 14:32:09 +0100 | [diff] [blame] | 3864 | ifmgd->flags |= IEEE80211_STA_DISABLE_HT; |
Johannes Berg | 9caf036 | 2012-11-29 01:25:20 +0100 | [diff] [blame^] | 3865 | rcu_read_unlock(); |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 3866 | |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 3867 | if (bss->wmm_used && bss->uapsd_supported && |
| 3868 | (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) { |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 3869 | assoc_data->uapsd = true; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 3870 | ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED; |
| 3871 | } else { |
Johannes Berg | 76f0303 | 2012-03-08 15:02:05 +0100 | [diff] [blame] | 3872 | assoc_data->uapsd = false; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 3873 | ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED; |
| 3874 | } |
| 3875 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3876 | if (req->prev_bssid) |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3877 | memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3878 | |
| 3879 | if (req->use_mfp) { |
| 3880 | ifmgd->mfp = IEEE80211_MFP_REQUIRED; |
| 3881 | ifmgd->flags |= IEEE80211_STA_MFP_ENABLED; |
| 3882 | } else { |
| 3883 | ifmgd->mfp = IEEE80211_MFP_DISABLED; |
| 3884 | ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED; |
| 3885 | } |
| 3886 | |
| 3887 | if (req->crypto.control_port) |
| 3888 | ifmgd->flags |= IEEE80211_STA_CONTROL_PORT; |
| 3889 | else |
| 3890 | ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; |
| 3891 | |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 3892 | sdata->control_port_protocol = req->crypto.control_port_ethertype; |
| 3893 | sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt; |
| 3894 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3895 | /* kick off associate process */ |
| 3896 | |
| 3897 | ifmgd->assoc_data = assoc_data; |
| 3898 | |
Johannes Berg | a1cf775 | 2012-03-08 15:02:07 +0100 | [diff] [blame] | 3899 | err = ieee80211_prep_connection(sdata, req->bss, true); |
| 3900 | if (err) |
| 3901 | goto err_clear; |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3902 | |
| 3903 | if (!bss->dtim_period && |
| 3904 | sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD) { |
| 3905 | /* |
| 3906 | * Wait up to one beacon interval ... |
| 3907 | * should this be more if we miss one? |
| 3908 | */ |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3909 | sdata_info(sdata, "waiting for beacon from %pM\n", |
| 3910 | ifmgd->bssid); |
Johannes Berg | 3f9768a | 2012-03-28 21:02:46 +0200 | [diff] [blame] | 3911 | assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3912 | } else { |
| 3913 | assoc_data->have_beacon = true; |
| 3914 | assoc_data->sent_assoc = false; |
| 3915 | assoc_data->timeout = jiffies; |
| 3916 | } |
| 3917 | run_again(ifmgd, assoc_data->timeout); |
| 3918 | |
Paul Stewart | fcff4f1 | 2012-02-23 17:59:53 -0800 | [diff] [blame] | 3919 | if (bss->corrupt_data) { |
| 3920 | char *corrupt_type = "data"; |
| 3921 | if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) { |
| 3922 | if (bss->corrupt_data & |
| 3923 | IEEE80211_BSS_CORRUPT_PROBE_RESP) |
| 3924 | corrupt_type = "beacon and probe response"; |
| 3925 | else |
| 3926 | corrupt_type = "beacon"; |
| 3927 | } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) |
| 3928 | corrupt_type = "probe response"; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3929 | sdata_info(sdata, "associating with AP with corrupt %s\n", |
| 3930 | corrupt_type); |
Paul Stewart | fcff4f1 | 2012-02-23 17:59:53 -0800 | [diff] [blame] | 3931 | } |
| 3932 | |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3933 | err = 0; |
| 3934 | goto out; |
| 3935 | err_clear: |
Eliad Peller | 3d2abdf | 2012-09-04 17:44:45 +0300 | [diff] [blame] | 3936 | memset(ifmgd->bssid, 0, ETH_ALEN); |
| 3937 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID); |
Johannes Berg | 66e67e4 | 2012-01-20 13:55:27 +0100 | [diff] [blame] | 3938 | ifmgd->assoc_data = NULL; |
| 3939 | err_free: |
| 3940 | kfree(assoc_data); |
| 3941 | out: |
| 3942 | mutex_unlock(&ifmgd->mtx); |
| 3943 | |
| 3944 | return err; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3945 | } |
| 3946 | |
| 3947 | int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 3948 | struct cfg80211_deauth_request *req) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3949 | { |
| 3950 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 3951 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 3952 | bool tx = !req->local_state_change; |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 3953 | bool sent_frame = false; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3954 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3955 | mutex_lock(&ifmgd->mtx); |
| 3956 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 3957 | sdata_info(sdata, |
| 3958 | "deauthenticating from %pM by local choice (reason=%d)\n", |
| 3959 | req->bssid, req->reason_code); |
Johannes Berg | 0ff7161 | 2009-09-26 14:45:41 +0200 | [diff] [blame] | 3960 | |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 3961 | if (ifmgd->auth_data) { |
Emmanuel Grumbach | 8c7d857 | 2012-07-25 01:42:36 +0300 | [diff] [blame] | 3962 | drv_mgd_prepare_tx(sdata->local, sdata); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3963 | ieee80211_send_deauth_disassoc(sdata, req->bssid, |
| 3964 | IEEE80211_STYPE_DEAUTH, |
Stanislaw Gruszka | 6863255 | 2012-10-15 14:52:41 +0200 | [diff] [blame] | 3965 | req->reason_code, tx, |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3966 | frame_buf); |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 3967 | ieee80211_destroy_auth_data(sdata, false); |
| 3968 | mutex_unlock(&ifmgd->mtx); |
| 3969 | |
| 3970 | sent_frame = tx; |
| 3971 | goto out; |
Emmanuel Grumbach | 8c7d857 | 2012-07-25 01:42:36 +0300 | [diff] [blame] | 3972 | } |
| 3973 | |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 3974 | if (ifmgd->associated && |
| 3975 | ether_addr_equal(ifmgd->associated->bssid, req->bssid)) { |
| 3976 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, |
| 3977 | req->reason_code, tx, frame_buf); |
| 3978 | sent_frame = tx; |
| 3979 | } |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 3980 | mutex_unlock(&ifmgd->mtx); |
| 3981 | |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 3982 | out: |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 3983 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 3984 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 3985 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 3986 | |
Johannes Berg | 8655201 | 2012-10-29 09:46:31 +0100 | [diff] [blame] | 3987 | if (sent_frame) |
| 3988 | __cfg80211_send_deauth(sdata->dev, frame_buf, |
| 3989 | IEEE80211_DEAUTH_FRAME_LEN); |
| 3990 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3991 | return 0; |
| 3992 | } |
| 3993 | |
| 3994 | int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 63c9c5e | 2012-02-24 13:50:51 +0100 | [diff] [blame] | 3995 | struct cfg80211_disassoc_request *req) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 3996 | { |
| 3997 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 3998 | u8 bssid[ETH_ALEN]; |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 3999 | u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN]; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4000 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4001 | mutex_lock(&ifmgd->mtx); |
| 4002 | |
Johannes Berg | 8d8b261 | 2009-07-25 11:58:36 +0200 | [diff] [blame] | 4003 | /* |
| 4004 | * cfg80211 should catch this ... but it's racy since |
| 4005 | * we can receive a disassoc frame, process it, hand it |
| 4006 | * to cfg80211 while that's in a locked section already |
| 4007 | * trying to tell us that the user wants to disconnect. |
| 4008 | */ |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 4009 | if (ifmgd->associated != req->bss) { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4010 | mutex_unlock(&ifmgd->mtx); |
| 4011 | return -ENOLINK; |
| 4012 | } |
| 4013 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 4014 | sdata_info(sdata, |
| 4015 | "disassociating from %pM by local choice (reason=%d)\n", |
| 4016 | req->bss->bssid, req->reason_code); |
Johannes Berg | 0ff7161 | 2009-09-26 14:45:41 +0200 | [diff] [blame] | 4017 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 4018 | memcpy(bssid, req->bss->bssid, ETH_ALEN); |
Johannes Berg | 37ad388 | 2012-02-24 13:50:54 +0100 | [diff] [blame] | 4019 | ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC, |
| 4020 | req->reason_code, !req->local_state_change, |
| 4021 | frame_buf); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4022 | mutex_unlock(&ifmgd->mtx); |
| 4023 | |
Antonio Quartulli | 6ae1677 | 2012-09-07 13:28:52 +0200 | [diff] [blame] | 4024 | __cfg80211_send_disassoc(sdata->dev, frame_buf, |
| 4025 | IEEE80211_DEAUTH_FRAME_LEN); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 4026 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 4027 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 4028 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 4029 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 4030 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 4031 | return 0; |
| 4032 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 4033 | |
Eliad Peller | afa762f | 2012-04-23 14:45:15 +0300 | [diff] [blame] | 4034 | void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 54e4ffb | 2012-02-25 21:48:08 +0100 | [diff] [blame] | 4035 | { |
| 4036 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 4037 | |
| 4038 | mutex_lock(&ifmgd->mtx); |
| 4039 | if (ifmgd->assoc_data) |
| 4040 | ieee80211_destroy_assoc_data(sdata, false); |
| 4041 | if (ifmgd->auth_data) |
| 4042 | ieee80211_destroy_auth_data(sdata, false); |
| 4043 | del_timer_sync(&ifmgd->timer); |
| 4044 | mutex_unlock(&ifmgd->mtx); |
| 4045 | } |
| 4046 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 4047 | void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif, |
| 4048 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 4049 | gfp_t gfp) |
| 4050 | { |
| 4051 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 4052 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 4053 | trace_api_cqm_rssi_notify(sdata, rssi_event); |
| 4054 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 4055 | cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp); |
| 4056 | } |
| 4057 | EXPORT_SYMBOL(ieee80211_cqm_rssi_notify); |