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