Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * BSS client mode implementation |
Jouni Malinen | 5394af4 | 2009-01-08 13:31:59 +0200 | [diff] [blame] | 3 | * Copyright 2003-2008, Jouni Malinen <j@w1.fi> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 4 | * Copyright 2004, Instant802 Networks, Inc. |
| 5 | * Copyright 2005, Devicescape Software, Inc. |
| 6 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 7 | * Copyright 2007, Michael Wu <flamingice@sourmilk.net> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
Geert Uytterhoeven | 5b323ed | 2007-05-08 18:40:27 -0700 | [diff] [blame] | 14 | #include <linux/delay.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 15 | #include <linux/if_ether.h> |
| 16 | #include <linux/skbuff.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 17 | #include <linux/if_arp.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 18 | #include <linux/etherdevice.h> |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 19 | #include <linux/rtnetlink.h> |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 20 | #include <linux/pm_qos_params.h> |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 21 | #include <linux/crc32.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 23 | #include <net/mac80211.h> |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 24 | #include <asm/unaligned.h> |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 25 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 26 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 27 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 28 | #include "rate.h" |
| 29 | #include "led.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 30 | |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 31 | #define IEEE80211_MAX_NULLFUNC_TRIES 2 |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 32 | #define IEEE80211_MAX_PROBE_TRIES 5 |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 33 | |
| 34 | /* |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 35 | * Beacon loss timeout is calculated as N frames times the |
| 36 | * advertised beacon interval. This may need to be somewhat |
| 37 | * higher than what hardware might detect to account for |
| 38 | * delays in the host processing frames. But since we also |
| 39 | * probe on beacon miss before declaring the connection lost |
| 40 | * default to what we want. |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 41 | */ |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 42 | #define IEEE80211_BEACON_LOSS_COUNT 7 |
| 43 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 44 | /* |
| 45 | * Time the connection can be idle before we probe |
| 46 | * it to see if we can still talk to the AP. |
| 47 | */ |
Maxim Levitsky | d1c5091 | 2009-07-31 18:54:23 +0300 | [diff] [blame] | 48 | #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 49 | /* |
| 50 | * Time we wait for a probe response after sending |
| 51 | * a probe request because of beacon loss or for |
| 52 | * checking the connection still works. |
| 53 | */ |
Maxim Levitsky | d1c5091 | 2009-07-31 18:54:23 +0300 | [diff] [blame] | 54 | #define IEEE80211_PROBE_WAIT (HZ / 2) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 55 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 56 | /* |
| 57 | * Weight given to the latest Beacon frame when calculating average signal |
| 58 | * strength for Beacon frames received in the current BSS. This must be |
| 59 | * between 1 and 15. |
| 60 | */ |
| 61 | #define IEEE80211_SIGNAL_AVE_WEIGHT 3 |
| 62 | |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 63 | /* |
| 64 | * How many Beacon frames need to have been used in average signal strength |
| 65 | * before starting to indicate signal change events. |
| 66 | */ |
| 67 | #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4 |
| 68 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 69 | #define TMR_RUNNING_TIMER 0 |
| 70 | #define TMR_RUNNING_CHANSW 1 |
| 71 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 72 | /* |
| 73 | * All cfg80211 functions have to be called outside a locked |
| 74 | * section so that they can acquire a lock themselves... This |
| 75 | * is much simpler than queuing up things in cfg80211, but we |
| 76 | * do need some indirection for that here. |
| 77 | */ |
| 78 | enum rx_mgmt_action { |
| 79 | /* no action required */ |
| 80 | RX_MGMT_NONE, |
| 81 | |
| 82 | /* caller must call cfg80211_send_rx_auth() */ |
| 83 | RX_MGMT_CFG80211_AUTH, |
| 84 | |
| 85 | /* caller must call cfg80211_send_rx_assoc() */ |
| 86 | RX_MGMT_CFG80211_ASSOC, |
| 87 | |
| 88 | /* caller must call cfg80211_send_deauth() */ |
| 89 | RX_MGMT_CFG80211_DEAUTH, |
| 90 | |
| 91 | /* caller must call cfg80211_send_disassoc() */ |
| 92 | RX_MGMT_CFG80211_DISASSOC, |
| 93 | |
Johannes Berg | 5d1ec85 | 2009-12-02 12:43:43 +0100 | [diff] [blame] | 94 | /* caller must tell cfg80211 about internal error */ |
| 95 | RX_MGMT_CFG80211_ASSOC_ERROR, |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 96 | }; |
| 97 | |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 98 | /* utils */ |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 99 | static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd) |
| 100 | { |
Johannes Berg | 46a5eba | 2010-09-15 13:28:15 +0200 | [diff] [blame] | 101 | lockdep_assert_held(&ifmgd->mtx); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 102 | } |
| 103 | |
Johannes Berg | ca386f3 | 2009-07-10 02:39:48 +0200 | [diff] [blame] | 104 | /* |
| 105 | * We can have multiple work items (and connection probing) |
| 106 | * scheduling this timer, but we need to take care to only |
| 107 | * reschedule it when it should fire _earlier_ than it was |
| 108 | * asked for before, or if it's not pending right now. This |
| 109 | * function ensures that. Note that it then is required to |
| 110 | * run this function for all timeouts after the first one |
| 111 | * has happened -- the work that runs from this timer will |
| 112 | * do that. |
| 113 | */ |
| 114 | static void run_again(struct ieee80211_if_managed *ifmgd, |
| 115 | unsigned long timeout) |
| 116 | { |
| 117 | ASSERT_MGD_MTX(ifmgd); |
| 118 | |
| 119 | if (!timer_pending(&ifmgd->timer) || |
| 120 | time_before(timeout, ifmgd->timer.expires)) |
| 121 | mod_timer(&ifmgd->timer, timeout); |
| 122 | } |
| 123 | |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 124 | void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 125 | { |
| 126 | if (sdata->local->hw.flags & IEEE80211_HW_BEACON_FILTER) |
| 127 | return; |
| 128 | |
| 129 | mod_timer(&sdata->u.mgd.bcn_mon_timer, |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 130 | round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout)); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 131 | } |
| 132 | |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 133 | void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata) |
| 134 | { |
Luis R. Rodriguez | 0c699c3 | 2010-09-16 15:12:30 -0400 | [diff] [blame] | 135 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 136 | |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 137 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
| 138 | return; |
| 139 | |
| 140 | mod_timer(&sdata->u.mgd.conn_mon_timer, |
| 141 | round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME)); |
Luis R. Rodriguez | 0c699c3 | 2010-09-16 15:12:30 -0400 | [diff] [blame] | 142 | |
| 143 | ifmgd->probe_send_count = 0; |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 144 | } |
| 145 | |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 146 | static int ecw2cw(int ecw) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 147 | { |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 148 | return (1 << ecw) - 1; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 149 | } |
| 150 | |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 151 | /* |
| 152 | * ieee80211_enable_ht should be called only after the operating band |
| 153 | * has been determined as ht configuration depends on the hw's |
| 154 | * HT abilities for a specific band. |
| 155 | */ |
| 156 | static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata, |
| 157 | struct ieee80211_ht_info *hti, |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 158 | const u8 *bssid, u16 ap_ht_cap_flags) |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 159 | { |
| 160 | struct ieee80211_local *local = sdata->local; |
| 161 | struct ieee80211_supported_band *sband; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 162 | struct sta_info *sta; |
| 163 | u32 changed = 0; |
Ben Greear | 172710b | 2011-01-28 17:05:43 -0800 | [diff] [blame^] | 164 | int hti_cfreq; |
Johannes Berg | 9ed6bcc | 2009-05-08 20:47:39 +0200 | [diff] [blame] | 165 | u16 ht_opmode; |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 166 | bool enable_ht = true; |
| 167 | enum nl80211_channel_type prev_chantype; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 168 | enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT; |
| 169 | |
| 170 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 171 | |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 172 | prev_chantype = sdata->vif.bss_conf.channel_type; |
| 173 | |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 174 | /* HT is not supported */ |
| 175 | if (!sband->ht_cap.ht_supported) |
| 176 | enable_ht = false; |
| 177 | |
Ben Greear | 172710b | 2011-01-28 17:05:43 -0800 | [diff] [blame^] | 178 | if (enable_ht) { |
| 179 | hti_cfreq = ieee80211_channel_to_frequency(hti->control_chan, |
| 180 | sband->band); |
| 181 | /* check that channel matches the right operating channel */ |
| 182 | if (local->hw.conf.channel->center_freq != hti_cfreq) { |
| 183 | /* Some APs mess this up, evidently. |
| 184 | * Netgear WNDR3700 sometimes reports 4 higher than |
| 185 | * the actual channel, for instance. |
| 186 | */ |
| 187 | printk(KERN_DEBUG |
| 188 | "%s: Wrong control channel in association" |
| 189 | " response: configured center-freq: %d" |
| 190 | " hti-cfreq: %d hti->control_chan: %d" |
| 191 | " band: %d. Disabling HT.\n", |
| 192 | sdata->name, |
| 193 | local->hw.conf.channel->center_freq, |
| 194 | hti_cfreq, hti->control_chan, |
| 195 | sband->band); |
| 196 | enable_ht = false; |
| 197 | } |
| 198 | } |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 199 | |
| 200 | if (enable_ht) { |
| 201 | channel_type = NL80211_CHAN_HT20; |
| 202 | |
| 203 | if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) && |
| 204 | (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) && |
| 205 | (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) { |
| 206 | switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { |
| 207 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
Luis R. Rodriguez | 768777e | 2009-05-02 00:37:19 -0400 | [diff] [blame] | 208 | if (!(local->hw.conf.channel->flags & |
| 209 | IEEE80211_CHAN_NO_HT40PLUS)) |
| 210 | channel_type = NL80211_CHAN_HT40PLUS; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 211 | break; |
| 212 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
Luis R. Rodriguez | 768777e | 2009-05-02 00:37:19 -0400 | [diff] [blame] | 213 | if (!(local->hw.conf.channel->flags & |
| 214 | IEEE80211_CHAN_NO_HT40MINUS)) |
| 215 | channel_type = NL80211_CHAN_HT40MINUS; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 216 | break; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
Reinette Chatre | fe6f212 | 2010-04-19 10:46:31 -0700 | [diff] [blame] | 221 | if (local->tmp_channel) |
| 222 | local->tmp_channel_type = channel_type; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 223 | |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 224 | if (!ieee80211_set_channel_type(local, sdata, channel_type)) { |
| 225 | /* can only fail due to HT40+/- mismatch */ |
| 226 | channel_type = NL80211_CHAN_HT20; |
| 227 | WARN_ON(!ieee80211_set_channel_type(local, sdata, channel_type)); |
| 228 | } |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 229 | |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 230 | /* channel_type change automatically detected */ |
| 231 | ieee80211_hw_config(local, 0); |
| 232 | |
| 233 | if (prev_chantype != channel_type) { |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 234 | rcu_read_lock(); |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 235 | sta = sta_info_get(sdata, bssid); |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 236 | if (sta) |
| 237 | rate_control_rate_update(local, sband, sta, |
Sujith | 4fa0043 | 2010-03-01 14:42:57 +0530 | [diff] [blame] | 238 | IEEE80211_RC_HT_CHANGED, |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 239 | channel_type); |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 240 | rcu_read_unlock(); |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 241 | } |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 242 | |
Johannes Berg | 9ed6bcc | 2009-05-08 20:47:39 +0200 | [diff] [blame] | 243 | ht_opmode = le16_to_cpu(hti->operation_mode); |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 244 | |
| 245 | /* if bss configuration changed store the new one */ |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 246 | if (sdata->ht_opmode_valid != enable_ht || |
| 247 | sdata->vif.bss_conf.ht_operation_mode != ht_opmode || |
| 248 | prev_chantype != channel_type) { |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 249 | changed |= BSS_CHANGED_HT; |
Johannes Berg | 9ed6bcc | 2009-05-08 20:47:39 +0200 | [diff] [blame] | 250 | sdata->vif.bss_conf.ht_operation_mode = ht_opmode; |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 251 | sdata->ht_opmode_valid = enable_ht; |
Johannes Berg | d5522e0 | 2009-03-30 13:23:35 +0200 | [diff] [blame] | 252 | } |
| 253 | |
| 254 | return changed; |
| 255 | } |
| 256 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 257 | /* frame sending functions */ |
| 258 | |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 259 | static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 260 | const u8 *bssid, u16 stype, u16 reason, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 261 | void *cookie, bool send_frame) |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 262 | { |
| 263 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 264 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 265 | struct sk_buff *skb; |
| 266 | struct ieee80211_mgmt *mgmt; |
| 267 | |
Jouni Malinen | 65fc73a | 2009-03-20 21:21:16 +0200 | [diff] [blame] | 268 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt)); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 269 | if (!skb) { |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 270 | printk(KERN_DEBUG "%s: failed to allocate buffer for " |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 271 | "deauth/disassoc frame\n", sdata->name); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 272 | return; |
| 273 | } |
| 274 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 275 | |
| 276 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 277 | memset(mgmt, 0, 24); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 278 | memcpy(mgmt->da, bssid, ETH_ALEN); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 279 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 280 | memcpy(mgmt->bssid, bssid, ETH_ALEN); |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 281 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 282 | skb_put(skb, 2); |
Johannes Berg | ef422bc | 2008-09-09 10:58:25 +0200 | [diff] [blame] | 283 | /* u.deauth.reason_code == u.disassoc.reason_code */ |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 284 | mgmt->u.deauth.reason_code = cpu_to_le16(reason); |
| 285 | |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 286 | if (stype == IEEE80211_STYPE_DEAUTH) |
Holger Schurig | ce47061 | 2009-10-13 13:28:13 +0200 | [diff] [blame] | 287 | if (cookie) |
| 288 | __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); |
| 289 | else |
| 290 | cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); |
Jouni Malinen | 53b46b8 | 2009-03-27 20:53:56 +0200 | [diff] [blame] | 291 | else |
Holger Schurig | ce47061 | 2009-10-13 13:28:13 +0200 | [diff] [blame] | 292 | if (cookie) |
| 293 | __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len); |
| 294 | else |
| 295 | cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len); |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 296 | if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED)) |
| 297 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 298 | |
| 299 | if (send_frame) |
| 300 | ieee80211_tx_skb(sdata, skb); |
| 301 | else |
| 302 | kfree_skb(skb); |
Johannes Berg | 9ac19a9 | 2008-09-09 10:57:09 +0200 | [diff] [blame] | 303 | } |
| 304 | |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 305 | void ieee80211_send_pspoll(struct ieee80211_local *local, |
| 306 | struct ieee80211_sub_if_data *sdata) |
| 307 | { |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 308 | struct ieee80211_pspoll *pspoll; |
| 309 | struct sk_buff *skb; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 310 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 311 | skb = ieee80211_pspoll_get(&local->hw, &sdata->vif); |
| 312 | if (!skb) |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 313 | return; |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 314 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 315 | pspoll = (struct ieee80211_pspoll *) skb->data; |
| 316 | pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 317 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 318 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 319 | ieee80211_tx_skb(sdata, skb); |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 320 | } |
| 321 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 322 | void ieee80211_send_nullfunc(struct ieee80211_local *local, |
| 323 | struct ieee80211_sub_if_data *sdata, |
| 324 | int powersave) |
| 325 | { |
| 326 | struct sk_buff *skb; |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 327 | struct ieee80211_hdr_3addr *nullfunc; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 328 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 329 | skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif); |
| 330 | if (!skb) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 331 | return; |
| 332 | |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 333 | nullfunc = (struct ieee80211_hdr_3addr *) skb->data; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 334 | if (powersave) |
Kalle Valo | d8cd189 | 2010-01-05 20:16:26 +0200 | [diff] [blame] | 335 | nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 336 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 337 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 338 | ieee80211_tx_skb(sdata, skb); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 339 | } |
| 340 | |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 341 | static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local, |
| 342 | struct ieee80211_sub_if_data *sdata) |
| 343 | { |
| 344 | struct sk_buff *skb; |
| 345 | struct ieee80211_hdr *nullfunc; |
| 346 | __le16 fc; |
| 347 | |
| 348 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 349 | return; |
| 350 | |
| 351 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30); |
| 352 | if (!skb) { |
| 353 | printk(KERN_DEBUG "%s: failed to allocate buffer for 4addr " |
| 354 | "nullfunc frame\n", sdata->name); |
| 355 | return; |
| 356 | } |
| 357 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 358 | |
| 359 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30); |
| 360 | memset(nullfunc, 0, 30); |
| 361 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | |
| 362 | IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); |
| 363 | nullfunc->frame_control = fc; |
| 364 | memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN); |
| 365 | memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN); |
| 366 | memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN); |
| 367 | memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN); |
| 368 | |
| 369 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 370 | ieee80211_tx_skb(sdata, skb); |
| 371 | } |
| 372 | |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 373 | /* spectrum management related things */ |
| 374 | static void ieee80211_chswitch_work(struct work_struct *work) |
| 375 | { |
| 376 | struct ieee80211_sub_if_data *sdata = |
| 377 | container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 378 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 379 | |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 380 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 381 | return; |
| 382 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 383 | mutex_lock(&ifmgd->mtx); |
| 384 | if (!ifmgd->associated) |
| 385 | goto out; |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 386 | |
| 387 | sdata->local->oper_channel = sdata->local->csa_channel; |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 388 | if (!sdata->local->ops->channel_switch) { |
| 389 | /* call "hw_config" only if doing sw channel switch */ |
| 390 | ieee80211_hw_config(sdata->local, |
| 391 | IEEE80211_CONF_CHANGE_CHANNEL); |
| 392 | } |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 393 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 394 | /* XXX: shouldn't really modify cfg80211-owned data! */ |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 395 | ifmgd->associated->channel = sdata->local->oper_channel; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 396 | |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 397 | ieee80211_wake_queues_by_reason(&sdata->local->hw, |
| 398 | IEEE80211_QUEUE_STOP_REASON_CSA); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 399 | out: |
| 400 | ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED; |
| 401 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 402 | } |
| 403 | |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 404 | void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success) |
| 405 | { |
| 406 | struct ieee80211_sub_if_data *sdata; |
| 407 | struct ieee80211_if_managed *ifmgd; |
| 408 | |
| 409 | sdata = vif_to_sdata(vif); |
| 410 | ifmgd = &sdata->u.mgd; |
| 411 | |
| 412 | trace_api_chswitch_done(sdata, success); |
| 413 | if (!success) { |
| 414 | /* |
| 415 | * If the channel switch was not successful, stay |
| 416 | * around on the old channel. We currently lack |
| 417 | * good handling of this situation, possibly we |
| 418 | * should just drop the association. |
| 419 | */ |
| 420 | sdata->local->csa_channel = sdata->local->oper_channel; |
| 421 | } |
| 422 | |
| 423 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
| 424 | } |
| 425 | EXPORT_SYMBOL(ieee80211_chswitch_done); |
| 426 | |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 427 | static void ieee80211_chswitch_timer(unsigned long data) |
| 428 | { |
| 429 | struct ieee80211_sub_if_data *sdata = |
| 430 | (struct ieee80211_sub_if_data *) data; |
| 431 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 432 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 433 | if (sdata->local->quiescing) { |
| 434 | set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running); |
| 435 | return; |
| 436 | } |
| 437 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 438 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, |
| 442 | struct ieee80211_channel_sw_ie *sw_elem, |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 443 | struct ieee80211_bss *bss, |
| 444 | u64 timestamp) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 445 | { |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 446 | struct cfg80211_bss *cbss = |
| 447 | container_of((void *)bss, struct cfg80211_bss, priv); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 448 | struct ieee80211_channel *new_ch; |
| 449 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 450 | int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num, |
| 451 | cbss->channel->band); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 452 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 453 | ASSERT_MGD_MTX(ifmgd); |
| 454 | |
| 455 | if (!ifmgd->associated) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 456 | return; |
| 457 | |
Helmut Schaa | fbe9c42 | 2009-07-23 12:14:04 +0200 | [diff] [blame] | 458 | if (sdata->local->scanning) |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 459 | return; |
| 460 | |
| 461 | /* Disregard subsequent beacons if we are already running a timer |
| 462 | processing a CSA */ |
| 463 | |
| 464 | if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED) |
| 465 | return; |
| 466 | |
| 467 | new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq); |
| 468 | if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED) |
| 469 | return; |
| 470 | |
| 471 | sdata->local->csa_channel = new_ch; |
| 472 | |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 473 | if (sdata->local->ops->channel_switch) { |
| 474 | /* use driver's channel switch callback */ |
| 475 | struct ieee80211_channel_switch ch_switch; |
| 476 | memset(&ch_switch, 0, sizeof(ch_switch)); |
| 477 | ch_switch.timestamp = timestamp; |
| 478 | if (sw_elem->mode) { |
| 479 | ch_switch.block_tx = true; |
| 480 | ieee80211_stop_queues_by_reason(&sdata->local->hw, |
| 481 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 482 | } |
| 483 | ch_switch.channel = new_ch; |
| 484 | ch_switch.count = sw_elem->count; |
| 485 | ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED; |
| 486 | drv_channel_switch(sdata->local, &ch_switch); |
| 487 | return; |
| 488 | } |
| 489 | |
| 490 | /* channel switch handled in software */ |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 491 | if (sw_elem->count <= 1) { |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 492 | ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 493 | } else { |
Wey-Yi Guy | 9feaddc | 2010-05-05 20:34:02 -0700 | [diff] [blame] | 494 | if (sw_elem->mode) |
| 495 | ieee80211_stop_queues_by_reason(&sdata->local->hw, |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 496 | IEEE80211_QUEUE_STOP_REASON_CSA); |
| 497 | ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED; |
| 498 | mod_timer(&ifmgd->chswitch_timer, |
| 499 | jiffies + |
| 500 | msecs_to_jiffies(sw_elem->count * |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 501 | cbss->beacon_interval)); |
Johannes Berg | cc32abd | 2009-05-15 11:52:31 +0200 | [diff] [blame] | 502 | } |
| 503 | } |
| 504 | |
| 505 | static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata, |
| 506 | u16 capab_info, u8 *pwr_constr_elem, |
| 507 | u8 pwr_constr_elem_len) |
| 508 | { |
| 509 | struct ieee80211_conf *conf = &sdata->local->hw.conf; |
| 510 | |
| 511 | if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT)) |
| 512 | return; |
| 513 | |
| 514 | /* Power constraint IE length should be 1 octet */ |
| 515 | if (pwr_constr_elem_len != 1) |
| 516 | return; |
| 517 | |
| 518 | if ((*pwr_constr_elem <= conf->channel->max_power) && |
| 519 | (*pwr_constr_elem != sdata->local->power_constr_level)) { |
| 520 | sdata->local->power_constr_level = *pwr_constr_elem; |
| 521 | ieee80211_hw_config(sdata->local, 0); |
| 522 | } |
| 523 | } |
| 524 | |
Juuso Oikarinen | f90754c | 2010-06-21 08:59:39 +0300 | [diff] [blame] | 525 | void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif) |
| 526 | { |
| 527 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 528 | struct ieee80211_local *local = sdata->local; |
| 529 | struct ieee80211_conf *conf = &local->hw.conf; |
| 530 | |
| 531 | WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION || |
| 532 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) || |
| 533 | (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)); |
| 534 | |
| 535 | local->disable_dynamic_ps = false; |
| 536 | conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout; |
| 537 | } |
| 538 | EXPORT_SYMBOL(ieee80211_enable_dyn_ps); |
| 539 | |
| 540 | void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif) |
| 541 | { |
| 542 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 543 | struct ieee80211_local *local = sdata->local; |
| 544 | struct ieee80211_conf *conf = &local->hw.conf; |
| 545 | |
| 546 | WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION || |
| 547 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) || |
| 548 | (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)); |
| 549 | |
| 550 | local->disable_dynamic_ps = true; |
| 551 | conf->dynamic_ps_timeout = 0; |
| 552 | del_timer_sync(&local->dynamic_ps_timer); |
| 553 | ieee80211_queue_work(&local->hw, |
| 554 | &local->dynamic_ps_enable_work); |
| 555 | } |
| 556 | EXPORT_SYMBOL(ieee80211_disable_dyn_ps); |
| 557 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 558 | /* powersave */ |
| 559 | static void ieee80211_enable_ps(struct ieee80211_local *local, |
| 560 | struct ieee80211_sub_if_data *sdata) |
| 561 | { |
| 562 | struct ieee80211_conf *conf = &local->hw.conf; |
| 563 | |
Johannes Berg | d5edaed | 2009-04-22 23:02:51 +0200 | [diff] [blame] | 564 | /* |
| 565 | * If we are scanning right now then the parameters will |
| 566 | * take effect when scan finishes. |
| 567 | */ |
Helmut Schaa | fbe9c42 | 2009-07-23 12:14:04 +0200 | [diff] [blame] | 568 | if (local->scanning) |
Johannes Berg | d5edaed | 2009-04-22 23:02:51 +0200 | [diff] [blame] | 569 | return; |
| 570 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 571 | if (conf->dynamic_ps_timeout > 0 && |
| 572 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) { |
| 573 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 574 | msecs_to_jiffies(conf->dynamic_ps_timeout)); |
| 575 | } else { |
| 576 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
| 577 | ieee80211_send_nullfunc(local, sdata, 1); |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 578 | |
Juuso Oikarinen | 2a13052 | 2010-03-09 14:25:02 +0200 | [diff] [blame] | 579 | if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) && |
| 580 | (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)) |
| 581 | return; |
| 582 | |
| 583 | conf->flags |= IEEE80211_CONF_PS; |
| 584 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 585 | } |
| 586 | } |
| 587 | |
| 588 | static void ieee80211_change_ps(struct ieee80211_local *local) |
| 589 | { |
| 590 | struct ieee80211_conf *conf = &local->hw.conf; |
| 591 | |
| 592 | if (local->ps_sdata) { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 593 | ieee80211_enable_ps(local, local->ps_sdata); |
| 594 | } else if (conf->flags & IEEE80211_CONF_PS) { |
| 595 | conf->flags &= ~IEEE80211_CONF_PS; |
| 596 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 597 | del_timer_sync(&local->dynamic_ps_timer); |
| 598 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | /* need to hold RTNL or interface lock */ |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 603 | void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 604 | { |
| 605 | struct ieee80211_sub_if_data *sdata, *found = NULL; |
| 606 | int count = 0; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 607 | int timeout; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 608 | |
| 609 | if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) { |
| 610 | local->ps_sdata = NULL; |
| 611 | return; |
| 612 | } |
| 613 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 614 | if (!list_empty(&local->work_list)) { |
| 615 | local->ps_sdata = NULL; |
| 616 | goto change; |
| 617 | } |
| 618 | |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 619 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 620 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 621 | continue; |
Rajkumar Manoharan | 8c7914d | 2011-02-01 00:28:59 +0530 | [diff] [blame] | 622 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
| 623 | /* If an AP vif is found, then disable PS |
| 624 | * by setting the count to zero thereby setting |
| 625 | * ps_sdata to NULL. |
| 626 | */ |
| 627 | count = 0; |
| 628 | break; |
| 629 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 630 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
| 631 | continue; |
| 632 | found = sdata; |
| 633 | count++; |
| 634 | } |
| 635 | |
Luis R. Rodriguez | 43f7853 | 2009-06-10 15:16:15 +0200 | [diff] [blame] | 636 | if (count == 1 && found->u.mgd.powersave && |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 637 | found->u.mgd.associated && |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 638 | found->u.mgd.associated->beacon_ies && |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 639 | !(found->u.mgd.flags & (IEEE80211_STA_BEACON_POLL | |
| 640 | IEEE80211_STA_CONNECTION_POLL))) { |
Juuso Oikarinen | f90754c | 2010-06-21 08:59:39 +0300 | [diff] [blame] | 641 | struct ieee80211_conf *conf = &local->hw.conf; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 642 | s32 beaconint_us; |
| 643 | |
| 644 | if (latency < 0) |
Mark Gross | ed77134 | 2010-05-06 01:59:26 +0200 | [diff] [blame] | 645 | latency = pm_qos_request(PM_QOS_NETWORK_LATENCY); |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 646 | |
| 647 | beaconint_us = ieee80211_tu_to_usec( |
| 648 | found->vif.bss_conf.beacon_int); |
| 649 | |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 650 | timeout = local->dynamic_ps_forced_timeout; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 651 | if (timeout < 0) { |
| 652 | /* |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 653 | * Go to full PSM if the user configures a very low |
| 654 | * latency requirement. |
Eliad Peller | 0ab82b0 | 2010-12-03 02:16:23 +0200 | [diff] [blame] | 655 | * The 2000 second value is there for compatibility |
| 656 | * until the PM_QOS_NETWORK_LATENCY is configured |
| 657 | * with real values. |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 658 | */ |
Eliad Peller | 0ab82b0 | 2010-12-03 02:16:23 +0200 | [diff] [blame] | 659 | if (latency > (1900 * USEC_PER_MSEC) && |
| 660 | latency != (2000 * USEC_PER_SEC)) |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 661 | timeout = 0; |
Juuso Oikarinen | ff61638 | 2010-06-09 09:51:52 +0300 | [diff] [blame] | 662 | else |
| 663 | timeout = 100; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 664 | } |
Juuso Oikarinen | f90754c | 2010-06-21 08:59:39 +0300 | [diff] [blame] | 665 | local->dynamic_ps_user_timeout = timeout; |
| 666 | if (!local->disable_dynamic_ps) |
| 667 | conf->dynamic_ps_timeout = |
| 668 | local->dynamic_ps_user_timeout; |
Juuso Oikarinen | 195e294 | 2010-04-27 12:47:40 +0300 | [diff] [blame] | 669 | |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 670 | if (beaconint_us > latency) { |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 671 | local->ps_sdata = NULL; |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 672 | } else { |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 673 | struct ieee80211_bss *bss; |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 674 | int maxslp = 1; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 675 | u8 dtimper; |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 676 | |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 677 | bss = (void *)found->u.mgd.associated->priv; |
| 678 | dtimper = bss->dtim_period; |
| 679 | |
| 680 | /* If the TIM IE is invalid, pretend the value is 1 */ |
| 681 | if (!dtimper) |
| 682 | dtimper = 1; |
| 683 | else if (dtimper > 1) |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 684 | maxslp = min_t(int, dtimper, |
| 685 | latency / beaconint_us); |
| 686 | |
Johannes Berg | 9ccebe6 | 2009-04-23 10:32:36 +0200 | [diff] [blame] | 687 | local->hw.conf.max_sleep_period = maxslp; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 688 | local->hw.conf.ps_dtim_period = dtimper; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 689 | local->ps_sdata = found; |
Johannes Berg | 04fe203 | 2009-04-22 18:44:37 +0200 | [diff] [blame] | 690 | } |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 691 | } else { |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 692 | local->ps_sdata = NULL; |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 693 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 694 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 695 | change: |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 696 | ieee80211_change_ps(local); |
| 697 | } |
| 698 | |
| 699 | void ieee80211_dynamic_ps_disable_work(struct work_struct *work) |
| 700 | { |
| 701 | struct ieee80211_local *local = |
| 702 | container_of(work, struct ieee80211_local, |
| 703 | dynamic_ps_disable_work); |
| 704 | |
| 705 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 706 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 707 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 708 | } |
| 709 | |
| 710 | ieee80211_wake_queues_by_reason(&local->hw, |
| 711 | IEEE80211_QUEUE_STOP_REASON_PS); |
| 712 | } |
| 713 | |
| 714 | void ieee80211_dynamic_ps_enable_work(struct work_struct *work) |
| 715 | { |
| 716 | struct ieee80211_local *local = |
| 717 | container_of(work, struct ieee80211_local, |
| 718 | dynamic_ps_enable_work); |
| 719 | struct ieee80211_sub_if_data *sdata = local->ps_sdata; |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 720 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 721 | |
| 722 | /* can only happen when PS was just disabled anyway */ |
| 723 | if (!sdata) |
| 724 | return; |
| 725 | |
| 726 | if (local->hw.conf.flags & IEEE80211_CONF_PS) |
| 727 | return; |
| 728 | |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 729 | if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) && |
| 730 | (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED))) |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 731 | ieee80211_send_nullfunc(local, sdata, 1); |
| 732 | |
Juuso Oikarinen | 2a13052 | 2010-03-09 14:25:02 +0200 | [diff] [blame] | 733 | if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) && |
| 734 | (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) || |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 735 | (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) { |
| 736 | ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; |
| 737 | local->hw.conf.flags |= IEEE80211_CONF_PS; |
| 738 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); |
| 739 | } |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | void ieee80211_dynamic_ps_timer(unsigned long data) |
| 743 | { |
| 744 | struct ieee80211_local *local = (void *) data; |
| 745 | |
Luis R. Rodriguez | 78f1a8b | 2009-07-27 08:38:25 -0700 | [diff] [blame] | 746 | if (local->quiescing || local->suspended) |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 747 | return; |
| 748 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 749 | ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work); |
Johannes Berg | 965beda | 2009-04-16 13:17:24 +0200 | [diff] [blame] | 750 | } |
| 751 | |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 752 | /* MLME */ |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 753 | static void ieee80211_sta_wmm_params(struct ieee80211_local *local, |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 754 | struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 755 | u8 *wmm_param, size_t wmm_param_len) |
| 756 | { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 757 | struct ieee80211_tx_queue_params params; |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 758 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 759 | size_t left; |
| 760 | int count; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 761 | u8 *pos, uapsd_queues = 0; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 762 | |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 763 | if (!local->ops->conf_tx) |
| 764 | return; |
| 765 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 766 | if (local->hw.queues < 4) |
Johannes Berg | 3434fbd | 2008-05-03 00:59:37 +0200 | [diff] [blame] | 767 | return; |
| 768 | |
| 769 | if (!wmm_param) |
| 770 | return; |
| 771 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 772 | if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1) |
| 773 | return; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 774 | |
| 775 | if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) |
Kalle Valo | 50ae0cf | 2010-01-12 10:42:39 +0200 | [diff] [blame] | 776 | uapsd_queues = local->uapsd_queues; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 777 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 778 | count = wmm_param[6] & 0x0f; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 779 | if (count == ifmgd->wmm_last_param_set) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 780 | return; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 781 | ifmgd->wmm_last_param_set = count; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 782 | |
| 783 | pos = wmm_param + 8; |
| 784 | left = wmm_param_len - 8; |
| 785 | |
| 786 | memset(¶ms, 0, sizeof(params)); |
| 787 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 788 | local->wmm_acm = 0; |
| 789 | for (; left >= 4; left -= 4, pos += 4) { |
| 790 | int aci = (pos[0] >> 5) & 0x03; |
| 791 | int acm = (pos[0] >> 4) & 0x01; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 792 | bool uapsd = false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 793 | int queue; |
| 794 | |
| 795 | switch (aci) { |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 796 | case 1: /* AC_BK */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 797 | queue = 3; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 798 | if (acm) |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 799 | local->wmm_acm |= BIT(1) | BIT(2); /* BK/- */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 800 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
| 801 | uapsd = true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 802 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 803 | case 2: /* AC_VI */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 804 | queue = 1; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 805 | if (acm) |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 806 | local->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 807 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
| 808 | uapsd = true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 809 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 810 | case 3: /* AC_VO */ |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 811 | queue = 0; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 812 | if (acm) |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 813 | local->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 814 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
| 815 | uapsd = true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 816 | break; |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 817 | case 0: /* AC_BE */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 818 | default: |
Johannes Berg | e100bb6 | 2008-04-30 18:51:21 +0200 | [diff] [blame] | 819 | queue = 2; |
Johannes Berg | 988c0f7 | 2008-04-17 19:21:22 +0200 | [diff] [blame] | 820 | if (acm) |
Jouni Malinen | 0eeb59f | 2009-03-05 17:23:46 +0200 | [diff] [blame] | 821 | local->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 822 | if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
| 823 | uapsd = true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 824 | break; |
| 825 | } |
| 826 | |
| 827 | params.aifs = pos[0] & 0x0f; |
| 828 | params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4); |
| 829 | params.cw_min = ecw2cw(pos[1] & 0x0f); |
Johannes Berg | f434b2d | 2008-07-10 11:22:31 +0200 | [diff] [blame] | 830 | params.txop = get_unaligned_le16(pos + 2); |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 831 | params.uapsd = uapsd; |
| 832 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 833 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 834 | wiphy_debug(local->hw.wiphy, |
| 835 | "WMM queue=%d aci=%d acm=%d aifs=%d " |
| 836 | "cWmin=%d cWmax=%d txop=%d uapsd=%d\n", |
| 837 | queue, aci, acm, |
| 838 | params.aifs, params.cw_min, params.cw_max, |
| 839 | params.txop, params.uapsd); |
Johannes Berg | 3330d7b | 2008-02-10 16:49:38 +0100 | [diff] [blame] | 840 | #endif |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 841 | if (drv_conf_tx(local, queue, ¶ms)) |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 842 | wiphy_debug(local->hw.wiphy, |
| 843 | "failed to set TX queue parameters for queue %d\n", |
| 844 | queue); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 845 | } |
Stanislaw Gruszka | e1b3ec1 | 2010-03-29 12:18:34 +0200 | [diff] [blame] | 846 | |
| 847 | /* enable WMM or activate new settings */ |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 848 | sdata->vif.bss_conf.qos = true; |
| 849 | ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 850 | } |
| 851 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 852 | static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, |
| 853 | u16 capab, bool erp_valid, u8 erp) |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 854 | { |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 855 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 856 | u32 changed = 0; |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 857 | bool use_protection; |
| 858 | bool use_short_preamble; |
| 859 | bool use_short_slot; |
| 860 | |
| 861 | if (erp_valid) { |
| 862 | use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0; |
| 863 | use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0; |
| 864 | } else { |
| 865 | use_protection = false; |
| 866 | use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE); |
| 867 | } |
| 868 | |
| 869 | use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME); |
Felix Fietkau | 43d3534 | 2010-01-15 03:00:48 +0100 | [diff] [blame] | 870 | if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) |
| 871 | use_short_slot = true; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 872 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 873 | if (use_protection != bss_conf->use_cts_prot) { |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 874 | bss_conf->use_cts_prot = use_protection; |
| 875 | changed |= BSS_CHANGED_ERP_CTS_PROT; |
Daniel Drake | 5628221 | 2007-07-10 19:32:10 +0200 | [diff] [blame] | 876 | } |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 877 | |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 878 | if (use_short_preamble != bss_conf->use_short_preamble) { |
Vladimir Koutny | d43c7b3 | 2008-03-31 17:05:03 +0200 | [diff] [blame] | 879 | bss_conf->use_short_preamble = use_short_preamble; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 880 | changed |= BSS_CHANGED_ERP_PREAMBLE; |
Daniel Drake | 7e9ed18 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 881 | } |
Daniel Drake | d9430a3 | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 882 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 883 | if (use_short_slot != bss_conf->use_short_slot) { |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 884 | bss_conf->use_short_slot = use_short_slot; |
| 885 | changed |= BSS_CHANGED_ERP_SLOT; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | return changed; |
| 889 | } |
| 890 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 891 | static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 892 | struct cfg80211_bss *cbss, |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 893 | u32 bss_info_changed) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 894 | { |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 895 | struct ieee80211_bss *bss = (void *)cbss->priv; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 896 | struct ieee80211_local *local = sdata->local; |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 897 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 898 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 899 | bss_info_changed |= BSS_CHANGED_ASSOC; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 900 | /* set timing information */ |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 901 | bss_conf->beacon_int = cbss->beacon_interval; |
| 902 | bss_conf->timestamp = cbss->tsf; |
Jiri Slaby | d6f2da5 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 903 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 904 | bss_info_changed |= BSS_CHANGED_BEACON_INT; |
| 905 | bss_info_changed |= ieee80211_handle_bss_capability(sdata, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 906 | cbss->capability, bss->has_erp_value, bss->erp_value); |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 907 | |
Felix Fietkau | 7ccc8bd | 2010-11-19 22:55:38 +0100 | [diff] [blame] | 908 | sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec( |
| 909 | IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int)); |
| 910 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 911 | sdata->u.mgd.associated = cbss; |
| 912 | memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN); |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 913 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 914 | sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE; |
| 915 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 916 | /* just to be sure */ |
| 917 | sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL | |
| 918 | IEEE80211_STA_BEACON_POLL); |
| 919 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 920 | ieee80211_led_assoc(local, 1); |
| 921 | |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 922 | if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD) |
| 923 | bss_conf->dtim_period = bss->dtim_period; |
| 924 | else |
| 925 | bss_conf->dtim_period = 0; |
| 926 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 927 | bss_conf->assoc = 1; |
Johannes Berg | 96dd22a | 2008-09-11 00:01:57 +0200 | [diff] [blame] | 928 | /* |
| 929 | * For now just always ask the driver to update the basic rateset |
| 930 | * when we have associated, we aren't checking whether it actually |
| 931 | * changed or not. |
| 932 | */ |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 933 | bss_info_changed |= BSS_CHANGED_BASIC_RATES; |
Johannes Berg | 9cef873 | 2009-05-14 13:10:14 +0200 | [diff] [blame] | 934 | |
| 935 | /* And the BSSID changed - we're associated now */ |
| 936 | bss_info_changed |= BSS_CHANGED_BSSID; |
| 937 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 938 | /* Tell the driver to monitor connection quality (if supported) */ |
| 939 | if ((local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI) && |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 940 | bss_conf->cqm_rssi_thold) |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 941 | bss_info_changed |= BSS_CHANGED_CQM; |
| 942 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 943 | /* Enable ARP filtering */ |
| 944 | if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) { |
| 945 | bss_conf->arp_filter_enabled = sdata->arp_filter_state; |
| 946 | bss_info_changed |= BSS_CHANGED_ARP_FILTER; |
| 947 | } |
| 948 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 949 | ieee80211_bss_info_change_notify(sdata, bss_info_changed); |
Guy Cohen | 8db9369 | 2008-07-03 19:56:13 +0300 | [diff] [blame] | 950 | |
Johannes Berg | 056508d | 2009-07-30 21:43:55 +0200 | [diff] [blame] | 951 | mutex_lock(&local->iflist_mtx); |
| 952 | ieee80211_recalc_ps(local, -1); |
Johannes Berg | 025e6be | 2010-10-05 10:41:47 +0200 | [diff] [blame] | 953 | ieee80211_recalc_smps(local); |
Johannes Berg | 056508d | 2009-07-30 21:43:55 +0200 | [diff] [blame] | 954 | mutex_unlock(&local->iflist_mtx); |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 955 | |
John W. Linville | 8a5b33f | 2010-01-06 15:39:39 -0500 | [diff] [blame] | 956 | netif_tx_start_all_queues(sdata->dev); |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 957 | netif_carrier_on(sdata->dev); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 958 | } |
| 959 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 960 | static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 53f73c0 | 2010-10-05 19:37:40 +0200 | [diff] [blame] | 961 | bool remove_sta, bool tx) |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 962 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 963 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 964 | struct ieee80211_local *local = sdata->local; |
| 965 | struct sta_info *sta; |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 966 | u32 changed = 0, config_changed = 0; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 967 | u8 bssid[ETH_ALEN]; |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 968 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 969 | ASSERT_MGD_MTX(ifmgd); |
| 970 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 971 | if (WARN_ON(!ifmgd->associated)) |
| 972 | return; |
| 973 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 974 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 975 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 976 | ifmgd->associated = NULL; |
| 977 | memset(ifmgd->bssid, 0, ETH_ALEN); |
| 978 | |
| 979 | /* |
| 980 | * we need to commit the associated = NULL change because the |
| 981 | * scan code uses that to determine whether this iface should |
| 982 | * go to/wake up from powersave or not -- and could otherwise |
| 983 | * wake the queues erroneously. |
| 984 | */ |
| 985 | smp_mb(); |
| 986 | |
| 987 | /* |
| 988 | * Thus, we can only afterwards stop the queues -- to account |
| 989 | * for the case where another CPU is finishing a scan at this |
| 990 | * time -- we don't want the scan code to enable queues. |
| 991 | */ |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 992 | |
John W. Linville | 8a5b33f | 2010-01-06 15:39:39 -0500 | [diff] [blame] | 993 | netif_tx_stop_all_queues(sdata->dev); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 994 | netif_carrier_off(sdata->dev); |
| 995 | |
Johannes Berg | 2a41905 | 2010-06-10 10:21:29 +0200 | [diff] [blame] | 996 | mutex_lock(&local->sta_mtx); |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 997 | sta = sta_info_get(sdata, bssid); |
Sujith | 4cad6c7 | 2010-02-10 14:52:21 +0530 | [diff] [blame] | 998 | if (sta) { |
Johannes Berg | 2a41905 | 2010-06-10 10:21:29 +0200 | [diff] [blame] | 999 | set_sta_flags(sta, WLAN_STA_BLOCK_BA); |
Johannes Berg | 53f73c0 | 2010-10-05 19:37:40 +0200 | [diff] [blame] | 1000 | ieee80211_sta_tear_down_BA_sessions(sta, tx); |
Sujith | 4cad6c7 | 2010-02-10 14:52:21 +0530 | [diff] [blame] | 1001 | } |
Johannes Berg | 2a41905 | 2010-06-10 10:21:29 +0200 | [diff] [blame] | 1002 | mutex_unlock(&local->sta_mtx); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1003 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1004 | changed |= ieee80211_reset_erp_info(sdata); |
| 1005 | |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1006 | ieee80211_led_assoc(local, 0); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1007 | changed |= BSS_CHANGED_ASSOC; |
| 1008 | sdata->vif.bss_conf.assoc = false; |
Tomas Winkler | f5e5bf2 | 2008-09-08 17:33:39 +0200 | [diff] [blame] | 1009 | |
Johannes Berg | aa837e1 | 2009-05-07 16:16:24 +0200 | [diff] [blame] | 1010 | ieee80211_set_wmm_default(sdata); |
| 1011 | |
Johannes Berg | 4797938 | 2009-01-07 10:13:27 +0100 | [diff] [blame] | 1012 | /* channel(_type) changes are handled by ieee80211_hw_config */ |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 1013 | WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT)); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1014 | |
Johannes Berg | 413ad50 | 2009-05-08 21:21:06 +0200 | [diff] [blame] | 1015 | /* on the next assoc, re-program HT parameters */ |
| 1016 | sdata->ht_opmode_valid = false; |
| 1017 | |
Vasanthakumar Thiagarajan | a8302de | 2009-01-09 18:14:15 +0530 | [diff] [blame] | 1018 | local->power_constr_level = 0; |
| 1019 | |
Kalle Valo | 520eb82 | 2008-12-18 23:35:27 +0200 | [diff] [blame] | 1020 | del_timer_sync(&local->dynamic_ps_timer); |
| 1021 | cancel_work_sync(&local->dynamic_ps_enable_work); |
| 1022 | |
Kalle Valo | e0cb686 | 2008-12-18 23:35:13 +0200 | [diff] [blame] | 1023 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 1024 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 1025 | config_changed |= IEEE80211_CONF_CHANGE_PS; |
| 1026 | } |
| 1027 | |
| 1028 | ieee80211_hw_config(local, config_changed); |
Johannes Berg | 9cef873 | 2009-05-14 13:10:14 +0200 | [diff] [blame] | 1029 | |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 1030 | /* Disable ARP filtering */ |
| 1031 | if (sdata->vif.bss_conf.arp_filter_enabled) { |
| 1032 | sdata->vif.bss_conf.arp_filter_enabled = false; |
| 1033 | changed |= BSS_CHANGED_ARP_FILTER; |
| 1034 | } |
| 1035 | |
Johannes Berg | 0aaffa9 | 2010-05-05 15:28:27 +0200 | [diff] [blame] | 1036 | /* The BSSID (not really interesting) and HT changed */ |
| 1037 | changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1038 | ieee80211_bss_info_change_notify(sdata, changed); |
Tomas Winkler | 8e268e4 | 2008-11-25 13:05:44 +0200 | [diff] [blame] | 1039 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 1040 | if (remove_sta) |
| 1041 | sta_info_destroy_addr(sdata, bssid); |
Johannes Berg | b9dcf71 | 2010-08-27 12:35:54 +0200 | [diff] [blame] | 1042 | |
| 1043 | del_timer_sync(&sdata->u.mgd.conn_mon_timer); |
| 1044 | del_timer_sync(&sdata->u.mgd.bcn_mon_timer); |
| 1045 | del_timer_sync(&sdata->u.mgd.timer); |
| 1046 | del_timer_sync(&sdata->u.mgd.chswitch_timer); |
Tomas Winkler | aa458d1 | 2008-09-09 00:32:12 +0300 | [diff] [blame] | 1047 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1048 | |
Kalle Valo | 3cf335d | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 1049 | void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata, |
| 1050 | struct ieee80211_hdr *hdr) |
| 1051 | { |
| 1052 | /* |
| 1053 | * We can postpone the mgd.timer whenever receiving unicast frames |
| 1054 | * from AP because we know that the connection is working both ways |
| 1055 | * at that time. But multicast frames (and hence also beacons) must |
| 1056 | * be ignored here, because we need to trigger the timer during |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1057 | * data idle periods for sending the periodic probe request to the |
| 1058 | * AP we're connected to. |
Kalle Valo | 3cf335d | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 1059 | */ |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1060 | if (is_multicast_ether_addr(hdr->addr1)) |
| 1061 | return; |
| 1062 | |
Luis R. Rodriguez | be099e8 | 2010-09-16 15:12:29 -0400 | [diff] [blame] | 1063 | ieee80211_sta_reset_conn_monitor(sdata); |
Kalle Valo | 3cf335d | 2009-03-22 21:57:06 +0200 | [diff] [blame] | 1064 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1065 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1066 | static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata) |
| 1067 | { |
| 1068 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1069 | |
| 1070 | if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
| 1071 | IEEE80211_STA_CONNECTION_POLL))) |
| 1072 | return; |
| 1073 | |
| 1074 | ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL | |
| 1075 | IEEE80211_STA_BEACON_POLL); |
| 1076 | mutex_lock(&sdata->local->iflist_mtx); |
| 1077 | ieee80211_recalc_ps(sdata->local, -1); |
| 1078 | mutex_unlock(&sdata->local->iflist_mtx); |
| 1079 | |
| 1080 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
| 1081 | return; |
| 1082 | |
| 1083 | /* |
| 1084 | * We've received a probe response, but are not sure whether |
| 1085 | * we have or will be receiving any beacons or data, so let's |
| 1086 | * schedule the timers again, just in case. |
| 1087 | */ |
| 1088 | ieee80211_sta_reset_beacon_monitor(sdata); |
| 1089 | |
| 1090 | mod_timer(&ifmgd->conn_mon_timer, |
| 1091 | round_jiffies_up(jiffies + |
| 1092 | IEEE80211_CONNECTION_IDLE_TIME)); |
| 1093 | } |
| 1094 | |
| 1095 | void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata, |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1096 | struct ieee80211_hdr *hdr, bool ack) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1097 | { |
Felix Fietkau | 75706d0 | 2010-12-02 21:01:07 +0100 | [diff] [blame] | 1098 | if (!ieee80211_is_data(hdr->frame_control)) |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1099 | return; |
| 1100 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1101 | if (ack) |
| 1102 | ieee80211_sta_reset_conn_monitor(sdata); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1103 | |
| 1104 | if (ieee80211_is_nullfunc(hdr->frame_control) && |
| 1105 | sdata->u.mgd.probe_send_count > 0) { |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1106 | if (ack) |
| 1107 | sdata->u.mgd.probe_send_count = 0; |
| 1108 | else |
| 1109 | sdata->u.mgd.nullfunc_failed = true; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1110 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
| 1111 | } |
| 1112 | } |
| 1113 | |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1114 | static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata) |
| 1115 | { |
| 1116 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1117 | const u8 *ssid; |
Luis R. Rodriguez | f01a067 | 2010-09-16 15:12:34 -0400 | [diff] [blame] | 1118 | u8 *dst = ifmgd->associated->bssid; |
| 1119 | u8 unicast_limit = max(1, IEEE80211_MAX_PROBE_TRIES - 3); |
| 1120 | |
| 1121 | /* |
| 1122 | * Try sending broadcast probe requests for the last three |
| 1123 | * probe requests after the first ones failed since some |
| 1124 | * buggy APs only support broadcast probe requests. |
| 1125 | */ |
| 1126 | if (ifmgd->probe_send_count >= unicast_limit) |
| 1127 | dst = NULL; |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1128 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1129 | /* |
| 1130 | * When the hardware reports an accurate Tx ACK status, it's |
| 1131 | * better to send a nullfunc frame instead of a probe request, |
| 1132 | * as it will kick us off the AP quickly if we aren't associated |
| 1133 | * anymore. The timeout will be reset if the frame is ACKed by |
| 1134 | * the AP. |
| 1135 | */ |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1136 | if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) { |
| 1137 | ifmgd->nullfunc_failed = false; |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1138 | ieee80211_send_nullfunc(sdata->local, sdata, 0); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1139 | } else { |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1140 | ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID); |
| 1141 | ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid[1], NULL, 0); |
| 1142 | } |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1143 | |
| 1144 | ifmgd->probe_send_count++; |
| 1145 | ifmgd->probe_timeout = jiffies + IEEE80211_PROBE_WAIT; |
| 1146 | run_again(ifmgd, ifmgd->probe_timeout); |
| 1147 | } |
| 1148 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1149 | static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata, |
| 1150 | bool beacon) |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1151 | { |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1152 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1153 | bool already = false; |
Johannes Berg | 34bfc41 | 2009-05-12 19:58:12 +0200 | [diff] [blame] | 1154 | |
Johannes Berg | 9607e6b | 2009-12-23 13:15:31 +0100 | [diff] [blame] | 1155 | if (!ieee80211_sdata_running(sdata)) |
Johannes Berg | 0e2b628 | 2009-07-13 13:23:39 +0200 | [diff] [blame] | 1156 | return; |
| 1157 | |
Luis R. Rodriguez | 91a3bd7 | 2009-07-23 16:37:47 -0700 | [diff] [blame] | 1158 | if (sdata->local->scanning) |
| 1159 | return; |
| 1160 | |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1161 | if (sdata->local->tmp_channel) |
| 1162 | return; |
| 1163 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1164 | mutex_lock(&ifmgd->mtx); |
| 1165 | |
| 1166 | if (!ifmgd->associated) |
| 1167 | goto out; |
| 1168 | |
Michael Buesch | a860402 | 2009-04-15 14:41:22 -0400 | [diff] [blame] | 1169 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1170 | if (beacon && net_ratelimit()) |
| 1171 | printk(KERN_DEBUG "%s: detected beacon loss from AP " |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 1172 | "- sending probe request\n", sdata->name); |
Michael Buesch | a860402 | 2009-04-15 14:41:22 -0400 | [diff] [blame] | 1173 | #endif |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1174 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1175 | /* |
| 1176 | * The driver/our work has already reported this event or the |
| 1177 | * connection monitoring has kicked in and we have already sent |
| 1178 | * a probe request. Or maybe the AP died and the driver keeps |
| 1179 | * reporting until we disassociate... |
| 1180 | * |
| 1181 | * In either case we have to ignore the current call to this |
| 1182 | * function (except for setting the correct probe reason bit) |
| 1183 | * because otherwise we would reset the timer every time and |
| 1184 | * never check whether we received a probe response! |
| 1185 | */ |
| 1186 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
| 1187 | IEEE80211_STA_CONNECTION_POLL)) |
| 1188 | already = true; |
| 1189 | |
| 1190 | if (beacon) |
| 1191 | ifmgd->flags |= IEEE80211_STA_BEACON_POLL; |
| 1192 | else |
| 1193 | ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL; |
| 1194 | |
| 1195 | if (already) |
| 1196 | goto out; |
| 1197 | |
Johannes Berg | 4e75184 | 2009-06-10 15:16:52 +0200 | [diff] [blame] | 1198 | mutex_lock(&sdata->local->iflist_mtx); |
| 1199 | ieee80211_recalc_ps(sdata->local, -1); |
| 1200 | mutex_unlock(&sdata->local->iflist_mtx); |
| 1201 | |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1202 | ifmgd->probe_send_count = 0; |
| 1203 | ieee80211_mgd_probe_ap_send(sdata); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1204 | out: |
| 1205 | mutex_unlock(&ifmgd->mtx); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1206 | } |
| 1207 | |
Juuso Oikarinen | a619a4c | 2010-11-11 08:50:18 +0200 | [diff] [blame] | 1208 | struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw, |
| 1209 | struct ieee80211_vif *vif) |
| 1210 | { |
| 1211 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1212 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1213 | struct sk_buff *skb; |
| 1214 | const u8 *ssid; |
| 1215 | |
| 1216 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) |
| 1217 | return NULL; |
| 1218 | |
| 1219 | ASSERT_MGD_MTX(ifmgd); |
| 1220 | |
| 1221 | if (!ifmgd->associated) |
| 1222 | return NULL; |
| 1223 | |
| 1224 | ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID); |
| 1225 | skb = ieee80211_build_probe_req(sdata, ifmgd->associated->bssid, |
| 1226 | ssid + 2, ssid[1], NULL, 0); |
| 1227 | |
| 1228 | return skb; |
| 1229 | } |
| 1230 | EXPORT_SYMBOL(ieee80211_ap_probereq_get); |
| 1231 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1232 | static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata) |
| 1233 | { |
| 1234 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1235 | struct ieee80211_local *local = sdata->local; |
| 1236 | u8 bssid[ETH_ALEN]; |
| 1237 | |
| 1238 | mutex_lock(&ifmgd->mtx); |
| 1239 | if (!ifmgd->associated) { |
| 1240 | mutex_unlock(&ifmgd->mtx); |
| 1241 | return; |
| 1242 | } |
| 1243 | |
| 1244 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
| 1245 | |
| 1246 | printk(KERN_DEBUG "Connection to AP %pM lost.\n", bssid); |
| 1247 | |
Johannes Berg | 53f73c0 | 2010-10-05 19:37:40 +0200 | [diff] [blame] | 1248 | ieee80211_set_disassoc(sdata, true, true); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1249 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1250 | |
| 1251 | mutex_lock(&local->mtx); |
| 1252 | ieee80211_recalc_idle(local); |
| 1253 | mutex_unlock(&local->mtx); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1254 | /* |
| 1255 | * must be outside lock due to cfg80211, |
| 1256 | * but that's not a problem. |
| 1257 | */ |
| 1258 | ieee80211_send_deauth_disassoc(sdata, bssid, |
| 1259 | IEEE80211_STYPE_DEAUTH, |
| 1260 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 1261 | NULL, true); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | void ieee80211_beacon_connection_loss_work(struct work_struct *work) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1265 | { |
| 1266 | struct ieee80211_sub_if_data *sdata = |
| 1267 | container_of(work, struct ieee80211_sub_if_data, |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1268 | u.mgd.beacon_connection_loss_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1269 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1270 | if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR) |
| 1271 | __ieee80211_connection_loss(sdata); |
| 1272 | else |
| 1273 | ieee80211_mgd_probe_ap(sdata, true); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1274 | } |
| 1275 | |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1276 | void ieee80211_beacon_loss(struct ieee80211_vif *vif) |
| 1277 | { |
| 1278 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1279 | struct ieee80211_hw *hw = &sdata->local->hw; |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1280 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 1281 | trace_api_beacon_loss(sdata); |
| 1282 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1283 | WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR); |
| 1284 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
Kalle Valo | 04de838 | 2009-03-22 21:57:35 +0200 | [diff] [blame] | 1285 | } |
| 1286 | EXPORT_SYMBOL(ieee80211_beacon_loss); |
| 1287 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1288 | void ieee80211_connection_loss(struct ieee80211_vif *vif) |
| 1289 | { |
| 1290 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1291 | struct ieee80211_hw *hw = &sdata->local->hw; |
| 1292 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 1293 | trace_api_connection_loss(sdata); |
| 1294 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 1295 | WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR)); |
| 1296 | ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work); |
| 1297 | } |
| 1298 | EXPORT_SYMBOL(ieee80211_connection_loss); |
| 1299 | |
| 1300 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1301 | static enum rx_mgmt_action __must_check |
| 1302 | ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1303 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1304 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1305 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1306 | const u8 *bssid = NULL; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1307 | u16 reason_code; |
| 1308 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1309 | if (len < 24 + 2) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1310 | return RX_MGMT_NONE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1311 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1312 | ASSERT_MGD_MTX(ifmgd); |
| 1313 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1314 | bssid = ifmgd->associated->bssid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1315 | |
| 1316 | reason_code = le16_to_cpu(mgmt->u.deauth.reason_code); |
| 1317 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1318 | printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 1319 | sdata->name, bssid, reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1320 | |
Johannes Berg | 53f73c0 | 2010-10-05 19:37:40 +0200 | [diff] [blame] | 1321 | ieee80211_set_disassoc(sdata, true, false); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1322 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 1323 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1324 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1325 | |
| 1326 | return RX_MGMT_CFG80211_DEAUTH; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1330 | static enum rx_mgmt_action __must_check |
| 1331 | ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata, |
| 1332 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1333 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1334 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1335 | u16 reason_code; |
| 1336 | |
Johannes Berg | f4ea83d | 2008-06-30 15:10:46 +0200 | [diff] [blame] | 1337 | if (len < 24 + 2) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1338 | return RX_MGMT_NONE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1339 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1340 | ASSERT_MGD_MTX(ifmgd); |
| 1341 | |
| 1342 | if (WARN_ON(!ifmgd->associated)) |
| 1343 | return RX_MGMT_NONE; |
| 1344 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1345 | if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN))) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1346 | return RX_MGMT_NONE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1347 | |
| 1348 | reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code); |
| 1349 | |
Johannes Berg | 0ff7161 | 2009-09-26 14:45:41 +0200 | [diff] [blame] | 1350 | printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 1351 | sdata->name, mgmt->sa, reason_code); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1352 | |
Johannes Berg | 53f73c0 | 2010-10-05 19:37:40 +0200 | [diff] [blame] | 1353 | ieee80211_set_disassoc(sdata, true, false); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1354 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 1355 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1356 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1357 | return RX_MGMT_CFG80211_DISASSOC; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1358 | } |
| 1359 | |
| 1360 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1361 | static bool ieee80211_assoc_success(struct ieee80211_work *wk, |
| 1362 | struct ieee80211_mgmt *mgmt, size_t len) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1363 | { |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1364 | struct ieee80211_sub_if_data *sdata = wk->sdata; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1365 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1366 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1367 | struct ieee80211_supported_band *sband; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1368 | struct sta_info *sta; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1369 | struct cfg80211_bss *cbss = wk->assoc.bss; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1370 | u8 *pos; |
Johannes Berg | 881d948 | 2009-01-21 15:13:48 +0100 | [diff] [blame] | 1371 | u32 rates, basic_rates; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1372 | u16 capab_info, aid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1373 | struct ieee802_11_elems elems; |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1374 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1375 | u32 changed = 0; |
Johannes Berg | 5d1ec85 | 2009-12-02 12:43:43 +0100 | [diff] [blame] | 1376 | int i, j, err; |
| 1377 | bool have_higher_than_11mbit = false; |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1378 | u16 ap_ht_cap_flags; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1379 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1380 | /* AssocResp and ReassocResp have identical structure */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1381 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1382 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1383 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1384 | |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 1385 | if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14))) |
| 1386 | printk(KERN_DEBUG "%s: invalid aid value %d; bits 15:14 not " |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 1387 | "set\n", sdata->name, aid); |
Johannes Berg | 1dd84aa | 2007-10-10 12:03:41 +0200 | [diff] [blame] | 1388 | aid &= ~(BIT(15) | BIT(14)); |
| 1389 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1390 | pos = mgmt->u.assoc_resp.variable; |
| 1391 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
| 1392 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1393 | if (!elems.supp_rates) { |
| 1394 | printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 1395 | sdata->name); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1396 | return false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1397 | } |
| 1398 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1399 | ifmgd->aid = aid; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1400 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1401 | sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1402 | if (!sta) { |
Johannes Berg | 5d1ec85 | 2009-12-02 12:43:43 +0100 | [diff] [blame] | 1403 | printk(KERN_DEBUG "%s: failed to alloc STA entry for" |
| 1404 | " the AP\n", sdata->name); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1405 | return false; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
Johannes Berg | 5d1ec85 | 2009-12-02 12:43:43 +0100 | [diff] [blame] | 1408 | set_sta_flags(sta, WLAN_STA_AUTH | WLAN_STA_ASSOC | |
| 1409 | WLAN_STA_ASSOC_AP); |
| 1410 | if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT)) |
| 1411 | set_sta_flags(sta, WLAN_STA_AUTHORIZED); |
| 1412 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1413 | rates = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1414 | basic_rates = 0; |
Luis R. Rodriguez | e7480bb | 2010-10-01 17:05:19 -0400 | [diff] [blame] | 1415 | sband = local->hw.wiphy->bands[wk->chan->band]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1416 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1417 | for (i = 0; i < elems.supp_rates_len; i++) { |
| 1418 | int rate = (elems.supp_rates[i] & 0x7f) * 5; |
Tomas Winkler | d61272c | 2008-10-30 17:08:08 +0200 | [diff] [blame] | 1419 | bool is_basic = !!(elems.supp_rates[i] & 0x80); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1420 | |
| 1421 | if (rate > 110) |
| 1422 | have_higher_than_11mbit = true; |
| 1423 | |
| 1424 | for (j = 0; j < sband->n_bitrates; j++) { |
Tomas Winkler | d61272c | 2008-10-30 17:08:08 +0200 | [diff] [blame] | 1425 | if (sband->bitrates[j].bitrate == rate) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1426 | rates |= BIT(j); |
Tomas Winkler | d61272c | 2008-10-30 17:08:08 +0200 | [diff] [blame] | 1427 | if (is_basic) |
| 1428 | basic_rates |= BIT(j); |
| 1429 | break; |
| 1430 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1431 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1432 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1433 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1434 | for (i = 0; i < elems.ext_supp_rates_len; i++) { |
| 1435 | int rate = (elems.ext_supp_rates[i] & 0x7f) * 5; |
Johannes Berg | 7e0986c | 2009-04-19 13:22:11 +0200 | [diff] [blame] | 1436 | bool is_basic = !!(elems.ext_supp_rates[i] & 0x80); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1437 | |
| 1438 | if (rate > 110) |
| 1439 | have_higher_than_11mbit = true; |
| 1440 | |
| 1441 | for (j = 0; j < sband->n_bitrates; j++) { |
Tomas Winkler | d61272c | 2008-10-30 17:08:08 +0200 | [diff] [blame] | 1442 | if (sband->bitrates[j].bitrate == rate) { |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1443 | rates |= BIT(j); |
Tomas Winkler | d61272c | 2008-10-30 17:08:08 +0200 | [diff] [blame] | 1444 | if (is_basic) |
| 1445 | basic_rates |= BIT(j); |
| 1446 | break; |
| 1447 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1448 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1449 | } |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1450 | |
Luis R. Rodriguez | e7480bb | 2010-10-01 17:05:19 -0400 | [diff] [blame] | 1451 | sta->sta.supp_rates[wk->chan->band] = rates; |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 1452 | sdata->vif.bss_conf.basic_rates = basic_rates; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1453 | |
| 1454 | /* cf. IEEE 802.11 9.2.12 */ |
Luis R. Rodriguez | e7480bb | 2010-10-01 17:05:19 -0400 | [diff] [blame] | 1455 | if (wk->chan->band == IEEE80211_BAND_2GHZ && |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1456 | have_higher_than_11mbit) |
| 1457 | sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE; |
| 1458 | else |
| 1459 | sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1460 | |
Johannes Berg | ab1faea | 2009-07-01 21:41:17 +0200 | [diff] [blame] | 1461 | if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1462 | ieee80211_ht_cap_ie_to_sta_ht_cap(sband, |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame] | 1463 | elems.ht_cap_elem, &sta->sta.ht_cap); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1464 | |
| 1465 | ap_ht_cap_flags = sta->sta.ht_cap.cap; |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1466 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 1467 | rate_control_rate_init(sta); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1468 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1469 | if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) |
Jouni Malinen | 5394af4 | 2009-01-08 13:31:59 +0200 | [diff] [blame] | 1470 | set_sta_flags(sta, WLAN_STA_MFP); |
| 1471 | |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 1472 | if (elems.wmm_param) |
Johannes Berg | 07346f81 | 2008-05-03 01:02:02 +0200 | [diff] [blame] | 1473 | set_sta_flags(sta, WLAN_STA_WME); |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 1474 | |
Johannes Berg | 5d1ec85 | 2009-12-02 12:43:43 +0100 | [diff] [blame] | 1475 | err = sta_info_insert(sta); |
| 1476 | sta = NULL; |
| 1477 | if (err) { |
| 1478 | printk(KERN_DEBUG "%s: failed to insert STA entry for" |
| 1479 | " the AP (error %d)\n", sdata->name, err); |
Johannes Berg | 90be561 | 2010-01-08 19:01:07 +0100 | [diff] [blame] | 1480 | return false; |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 1481 | } |
| 1482 | |
Juuso Oikarinen | f2176d7 | 2010-09-28 14:39:32 +0300 | [diff] [blame] | 1483 | /* |
| 1484 | * Always handle WMM once after association regardless |
| 1485 | * of the first value the AP uses. Setting -1 here has |
| 1486 | * that effect because the AP values is an unsigned |
| 1487 | * 4-bit value. |
| 1488 | */ |
| 1489 | ifmgd->wmm_last_param_set = -1; |
| 1490 | |
Johannes Berg | ddf4ac5 | 2008-10-22 11:41:38 +0200 | [diff] [blame] | 1491 | if (elems.wmm_param) |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 1492 | ieee80211_sta_wmm_params(local, sdata, elems.wmm_param, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1493 | elems.wmm_param_len); |
Johannes Berg | aa837e1 | 2009-05-07 16:16:24 +0200 | [diff] [blame] | 1494 | else |
| 1495 | ieee80211_set_wmm_default(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1496 | |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1497 | local->oper_channel = wk->chan; |
| 1498 | |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1499 | if (elems.ht_info_elem && elems.wmm_param && |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1500 | (sdata->local->hw.queues >= 4) && |
Johannes Berg | ab1faea | 2009-07-01 21:41:17 +0200 | [diff] [blame] | 1501 | !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1502 | changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1503 | cbss->bssid, ap_ht_cap_flags); |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1504 | |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 1505 | /* set AID and assoc capability, |
| 1506 | * ieee80211_set_associated() will tell the driver */ |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 1507 | bss_conf->aid = aid; |
Tomas Winkler | 21c0cbe | 2008-03-28 16:33:34 -0700 | [diff] [blame] | 1508 | bss_conf->assoc_capability = capab_info; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1509 | ieee80211_set_associated(sdata, cbss, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1510 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 1511 | /* |
Felix Fietkau | d524215 | 2010-01-08 18:06:26 +0100 | [diff] [blame] | 1512 | * If we're using 4-addr mode, let the AP know that we're |
| 1513 | * doing so, so that it can create the STA VLAN on its side |
| 1514 | */ |
| 1515 | if (ifmgd->use_4addr) |
| 1516 | ieee80211_send_4addr_nullfunc(local, sdata); |
| 1517 | |
| 1518 | /* |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1519 | * Start timer to probe the connection to the AP now. |
| 1520 | * Also start the timer that will detect beacon loss. |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 1521 | */ |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1522 | ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt); |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 1523 | ieee80211_sta_reset_beacon_monitor(sdata); |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 1524 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1525 | return true; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1529 | static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1530 | struct ieee80211_mgmt *mgmt, |
| 1531 | size_t len, |
| 1532 | struct ieee80211_rx_status *rx_status, |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1533 | struct ieee802_11_elems *elems, |
| 1534 | bool beacon) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1535 | { |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1536 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1537 | int freq; |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 1538 | struct ieee80211_bss *bss; |
Johannes Berg | fab7d4a | 2008-03-16 18:42:44 +0100 | [diff] [blame] | 1539 | struct ieee80211_channel *channel; |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 1540 | bool need_ps = false; |
| 1541 | |
| 1542 | if (sdata->u.mgd.associated) { |
| 1543 | bss = (void *)sdata->u.mgd.associated->priv; |
| 1544 | /* not previously set so we may need to recalc */ |
| 1545 | need_ps = !bss->dtim_period; |
| 1546 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1547 | |
Johannes Berg | 5bda617 | 2008-09-08 11:05:10 +0200 | [diff] [blame] | 1548 | if (elems->ds_params && elems->ds_params_len == 1) |
Bruno Randolf | 59eb21a | 2011-01-17 13:37:28 +0900 | [diff] [blame] | 1549 | freq = ieee80211_channel_to_frequency(elems->ds_params[0], |
| 1550 | rx_status->band); |
Johannes Berg | 5bda617 | 2008-09-08 11:05:10 +0200 | [diff] [blame] | 1551 | else |
| 1552 | freq = rx_status->freq; |
| 1553 | |
| 1554 | channel = ieee80211_get_channel(local->hw.wiphy, freq); |
| 1555 | |
| 1556 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) |
| 1557 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1558 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1559 | bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 1560 | channel, beacon); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1561 | if (bss) |
| 1562 | ieee80211_rx_bss_put(local, bss); |
| 1563 | |
| 1564 | if (!sdata->u.mgd.associated) |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1565 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1566 | |
Johannes Berg | 56007a0 | 2010-01-26 14:19:52 +0100 | [diff] [blame] | 1567 | if (need_ps) { |
| 1568 | mutex_lock(&local->iflist_mtx); |
| 1569 | ieee80211_recalc_ps(local, -1); |
| 1570 | mutex_unlock(&local->iflist_mtx); |
| 1571 | } |
| 1572 | |
Sujith | c481ec9 | 2009-01-06 09:28:37 +0530 | [diff] [blame] | 1573 | if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) && |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1574 | (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid, |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1575 | ETH_ALEN) == 0)) { |
Sujith | c481ec9 | 2009-01-06 09:28:37 +0530 | [diff] [blame] | 1576 | struct ieee80211_channel_sw_ie *sw_elem = |
| 1577 | (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem; |
Johannes Berg | 5ce6e43 | 2010-05-11 16:20:57 +0200 | [diff] [blame] | 1578 | ieee80211_sta_process_chanswitch(sdata, sw_elem, |
| 1579 | bss, rx_status->mactime); |
Sujith | c481ec9 | 2009-01-06 09:28:37 +0530 | [diff] [blame] | 1580 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1584 | 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] | 1585 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1586 | { |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1587 | struct ieee80211_mgmt *mgmt = (void *)skb->data; |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 1588 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1589 | struct ieee80211_rx_status *rx_status = (void *) skb->cb; |
| 1590 | size_t baselen, len = skb->len; |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 1591 | struct ieee802_11_elems elems; |
| 1592 | |
Kalle Valo | 15b7b06 | 2009-03-22 21:57:14 +0200 | [diff] [blame] | 1593 | ifmgd = &sdata->u.mgd; |
| 1594 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1595 | ASSERT_MGD_MTX(ifmgd); |
| 1596 | |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 1597 | if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN)) |
Tomas Winkler | 8e7cdbb | 2008-08-03 14:32:01 +0300 | [diff] [blame] | 1598 | return; /* ignore ProbeResp to foreign address */ |
| 1599 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 1600 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
| 1601 | if (baselen > len) |
| 1602 | return; |
| 1603 | |
| 1604 | ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen, |
| 1605 | &elems); |
| 1606 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 1607 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false); |
Ron Rindjunsky | 9859b81 | 2008-08-09 03:02:19 +0300 | [diff] [blame] | 1608 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1609 | if (ifmgd->associated && |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1610 | memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0) |
| 1611 | ieee80211_reset_ap_probe(sdata); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1612 | } |
| 1613 | |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 1614 | /* |
| 1615 | * This is the canonical list of information elements we care about, |
| 1616 | * the filter code also gives us all changes to the Microsoft OUI |
| 1617 | * (00:50:F2) vendor IE which is used for WMM which we need to track. |
| 1618 | * |
| 1619 | * We implement beacon filtering in software since that means we can |
| 1620 | * avoid processing the frame here and in cfg80211, and userspace |
| 1621 | * will not be able to tell whether the hardware supports it or not. |
| 1622 | * |
| 1623 | * XXX: This list needs to be dynamic -- userspace needs to be able to |
| 1624 | * add items it requires. It also needs to be able to tell us to |
| 1625 | * look out for other vendor IEs. |
| 1626 | */ |
| 1627 | static const u64 care_about_ies = |
Johannes Berg | 1d4df3a | 2009-04-22 11:25:43 +0200 | [diff] [blame] | 1628 | (1ULL << WLAN_EID_COUNTRY) | |
| 1629 | (1ULL << WLAN_EID_ERP_INFO) | |
| 1630 | (1ULL << WLAN_EID_CHANNEL_SWITCH) | |
| 1631 | (1ULL << WLAN_EID_PWR_CONSTRAINT) | |
| 1632 | (1ULL << WLAN_EID_HT_CAPABILITY) | |
| 1633 | (1ULL << WLAN_EID_HT_INFORMATION); |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 1634 | |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1635 | static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata, |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1636 | struct ieee80211_mgmt *mgmt, |
| 1637 | size_t len, |
| 1638 | struct ieee80211_rx_status *rx_status) |
| 1639 | { |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 1640 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 1641 | struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1642 | size_t baselen; |
| 1643 | struct ieee802_11_elems elems; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1644 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1645 | u32 changed = 0; |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 1646 | bool erp_valid, directed_tim = false; |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1647 | u8 erp_value = 0; |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 1648 | u32 ncrc; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1649 | u8 *bssid; |
| 1650 | |
| 1651 | ASSERT_MGD_MTX(ifmgd); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1652 | |
Ester Kummer | ae6a44e | 2008-06-27 18:54:48 +0300 | [diff] [blame] | 1653 | /* Process beacon from the current BSS */ |
| 1654 | baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt; |
| 1655 | if (baselen > len) |
| 1656 | return; |
| 1657 | |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 1658 | if (rx_status->freq != local->hw.conf.channel->center_freq) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1659 | return; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1660 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1661 | /* |
| 1662 | * We might have received a number of frames, among them a |
| 1663 | * disassoc frame and a beacon... |
| 1664 | */ |
| 1665 | if (!ifmgd->associated) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1666 | return; |
| 1667 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1668 | bssid = ifmgd->associated->bssid; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1669 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1670 | /* |
| 1671 | * And in theory even frames from a different AP we were just |
| 1672 | * associated to a split-second ago! |
| 1673 | */ |
| 1674 | if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1675 | return; |
| 1676 | |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 1677 | /* Track average RSSI from the Beacon frames of the current AP */ |
| 1678 | ifmgd->last_beacon_signal = rx_status->signal; |
| 1679 | if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) { |
| 1680 | ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE; |
Jouni Malinen | 3ba06c6 | 2010-08-27 22:21:13 +0300 | [diff] [blame] | 1681 | ifmgd->ave_beacon_signal = rx_status->signal * 16; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 1682 | ifmgd->last_cqm_event_signal = 0; |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 1683 | ifmgd->count_beacon_signal = 1; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 1684 | } else { |
| 1685 | ifmgd->ave_beacon_signal = |
| 1686 | (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 + |
| 1687 | (16 - IEEE80211_SIGNAL_AVE_WEIGHT) * |
| 1688 | ifmgd->ave_beacon_signal) / 16; |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 1689 | ifmgd->count_beacon_signal++; |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 1690 | } |
| 1691 | if (bss_conf->cqm_rssi_thold && |
Jouni Malinen | 391a200 | 2010-08-27 22:22:00 +0300 | [diff] [blame] | 1692 | ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT && |
Jouni Malinen | 17e4ec1 | 2010-03-29 23:28:30 -0700 | [diff] [blame] | 1693 | !(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) { |
| 1694 | int sig = ifmgd->ave_beacon_signal / 16; |
| 1695 | int last_event = ifmgd->last_cqm_event_signal; |
| 1696 | int thold = bss_conf->cqm_rssi_thold; |
| 1697 | int hyst = bss_conf->cqm_rssi_hyst; |
| 1698 | if (sig < thold && |
| 1699 | (last_event == 0 || sig < last_event - hyst)) { |
| 1700 | ifmgd->last_cqm_event_signal = sig; |
| 1701 | ieee80211_cqm_rssi_notify( |
| 1702 | &sdata->vif, |
| 1703 | NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW, |
| 1704 | GFP_KERNEL); |
| 1705 | } else if (sig > thold && |
| 1706 | (last_event == 0 || sig > last_event + hyst)) { |
| 1707 | ifmgd->last_cqm_event_signal = sig; |
| 1708 | ieee80211_cqm_rssi_notify( |
| 1709 | &sdata->vif, |
| 1710 | NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH, |
| 1711 | GFP_KERNEL); |
| 1712 | } |
| 1713 | } |
| 1714 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1715 | if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) { |
Jouni Malinen | 9277818 | 2009-05-14 21:15:36 +0300 | [diff] [blame] | 1716 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 1717 | if (net_ratelimit()) { |
| 1718 | printk(KERN_DEBUG "%s: cancelling probereq poll due " |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 1719 | "to a received beacon\n", sdata->name); |
Jouni Malinen | 9277818 | 2009-05-14 21:15:36 +0300 | [diff] [blame] | 1720 | } |
| 1721 | #endif |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1722 | ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL; |
Johannes Berg | 4e75184 | 2009-06-10 15:16:52 +0200 | [diff] [blame] | 1723 | mutex_lock(&local->iflist_mtx); |
| 1724 | ieee80211_recalc_ps(local, -1); |
| 1725 | mutex_unlock(&local->iflist_mtx); |
Jouni Malinen | 9277818 | 2009-05-14 21:15:36 +0300 | [diff] [blame] | 1726 | } |
| 1727 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1728 | /* |
| 1729 | * Push the beacon loss detection into the future since |
| 1730 | * we are processing a beacon from the AP just now. |
| 1731 | */ |
Luis R. Rodriguez | d3a910a | 2010-09-16 15:12:32 -0400 | [diff] [blame] | 1732 | ieee80211_sta_reset_beacon_monitor(sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1733 | |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 1734 | ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4); |
| 1735 | ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable, |
| 1736 | len - baselen, &elems, |
| 1737 | care_about_ies, ncrc); |
| 1738 | |
| 1739 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) |
Johannes Berg | e7ec86f | 2009-04-18 17:33:24 +0200 | [diff] [blame] | 1740 | directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len, |
| 1741 | ifmgd->aid); |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 1742 | |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 1743 | if (ncrc != ifmgd->beacon_crc || !ifmgd->beacon_crc_valid) { |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 1744 | ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, |
| 1745 | true); |
Johannes Berg | d91f36d | 2009-04-16 13:17:26 +0200 | [diff] [blame] | 1746 | |
Johannes Berg | 4ced3f7 | 2010-07-19 16:39:04 +0200 | [diff] [blame] | 1747 | ieee80211_sta_wmm_params(local, sdata, elems.wmm_param, |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 1748 | elems.wmm_param_len); |
| 1749 | } |
Johannes Berg | fe3fa82 | 2008-09-08 11:05:09 +0200 | [diff] [blame] | 1750 | |
Vivek Natarajan | 25c9c87 | 2009-03-02 20:20:30 +0530 | [diff] [blame] | 1751 | if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) { |
Kalle Valo | 1fb3606 | 2009-02-10 17:09:24 +0200 | [diff] [blame] | 1752 | if (directed_tim) { |
Kalle Valo | 572e001 | 2009-02-10 17:09:31 +0200 | [diff] [blame] | 1753 | if (local->hw.conf.dynamic_ps_timeout > 0) { |
| 1754 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; |
| 1755 | ieee80211_hw_config(local, |
| 1756 | IEEE80211_CONF_CHANGE_PS); |
| 1757 | ieee80211_send_nullfunc(local, sdata, 0); |
| 1758 | } else { |
| 1759 | local->pspolling = true; |
| 1760 | |
| 1761 | /* |
| 1762 | * Here is assumed that the driver will be |
| 1763 | * able to send ps-poll frame and receive a |
| 1764 | * response even though power save mode is |
| 1765 | * enabled, but some drivers might require |
| 1766 | * to disable power save here. This needs |
| 1767 | * to be investigated. |
| 1768 | */ |
| 1769 | ieee80211_send_pspoll(local, sdata); |
| 1770 | } |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 1771 | } |
| 1772 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1773 | |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 1774 | if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid) |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 1775 | return; |
| 1776 | ifmgd->beacon_crc = ncrc; |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 1777 | ifmgd->beacon_crc_valid = true; |
Jouni Malinen | 3019667 | 2009-05-19 17:01:43 +0300 | [diff] [blame] | 1778 | |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1779 | if (elems.erp_info && elems.erp_info_len >= 1) { |
| 1780 | erp_valid = true; |
| 1781 | erp_value = elems.erp_info[0]; |
| 1782 | } else { |
| 1783 | erp_valid = false; |
John W. Linville | 50c4afb | 2008-04-15 14:09:27 -0400 | [diff] [blame] | 1784 | } |
Johannes Berg | 7a5158e | 2008-10-08 10:59:33 +0200 | [diff] [blame] | 1785 | changed |= ieee80211_handle_bss_capability(sdata, |
| 1786 | le16_to_cpu(mgmt->u.beacon.capab_info), |
| 1787 | erp_valid, erp_value); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1788 | |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1789 | |
Vasanthakumar Thiagarajan | 53d6f81c | 2009-02-11 22:18:49 +0530 | [diff] [blame] | 1790 | if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param && |
Johannes Berg | ab1faea | 2009-07-01 21:41:17 +0200 | [diff] [blame] | 1791 | !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) { |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1792 | struct sta_info *sta; |
| 1793 | struct ieee80211_supported_band *sband; |
| 1794 | u16 ap_ht_cap_flags; |
| 1795 | |
| 1796 | rcu_read_lock(); |
| 1797 | |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 1798 | sta = sta_info_get(sdata, bssid); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1799 | if (WARN_ON(!sta)) { |
Johannes Berg | ae5eb02 | 2008-10-14 16:58:37 +0200 | [diff] [blame] | 1800 | rcu_read_unlock(); |
| 1801 | return; |
| 1802 | } |
| 1803 | |
| 1804 | sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; |
| 1805 | |
| 1806 | ieee80211_ht_cap_ie_to_sta_ht_cap(sband, |
| 1807 | elems.ht_cap_elem, &sta->sta.ht_cap); |
| 1808 | |
| 1809 | ap_ht_cap_flags = sta->sta.ht_cap.cap; |
| 1810 | |
| 1811 | rcu_read_unlock(); |
| 1812 | |
| 1813 | changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem, |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1814 | bssid, ap_ht_cap_flags); |
Ron Rindjunsky | d3c990f | 2007-11-26 16:14:34 +0200 | [diff] [blame] | 1815 | } |
| 1816 | |
Luis R. Rodriguez | 8b19e6c | 2009-07-30 17:38:09 -0700 | [diff] [blame] | 1817 | /* Note: country IE parsing is done for us by cfg80211 */ |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1818 | if (elems.country_elem) { |
Vasanthakumar Thiagarajan | a8302de | 2009-01-09 18:14:15 +0530 | [diff] [blame] | 1819 | /* TODO: IBSS also needs this */ |
| 1820 | if (elems.pwr_constr_elem) |
| 1821 | ieee80211_handle_pwr_constr(sdata, |
| 1822 | le16_to_cpu(mgmt->u.probe_resp.capab_info), |
| 1823 | elems.pwr_constr_elem, |
| 1824 | elems.pwr_constr_elem_len); |
Luis R. Rodriguez | 3f2355c | 2008-11-12 14:22:02 -0800 | [diff] [blame] | 1825 | } |
| 1826 | |
Johannes Berg | 471b3ef | 2007-12-28 14:32:58 +0100 | [diff] [blame] | 1827 | ieee80211_bss_info_change_notify(sdata, changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1828 | } |
| 1829 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 1830 | void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata, |
| 1831 | struct sk_buff *skb) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1832 | { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1833 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1834 | struct ieee80211_rx_status *rx_status; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1835 | struct ieee80211_mgmt *mgmt; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1836 | enum rx_mgmt_action rma = RX_MGMT_NONE; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1837 | u16 fc; |
| 1838 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1839 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
| 1840 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 1841 | fc = le16_to_cpu(mgmt->frame_control); |
| 1842 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1843 | mutex_lock(&ifmgd->mtx); |
| 1844 | |
| 1845 | if (ifmgd->associated && |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1846 | memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1847 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 1848 | case IEEE80211_STYPE_BEACON: |
| 1849 | ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, |
| 1850 | rx_status); |
| 1851 | break; |
| 1852 | case IEEE80211_STYPE_PROBE_RESP: |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1853 | ieee80211_rx_mgmt_probe_resp(sdata, skb); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1854 | break; |
| 1855 | case IEEE80211_STYPE_DEAUTH: |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 1856 | rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1857 | break; |
| 1858 | case IEEE80211_STYPE_DISASSOC: |
| 1859 | rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len); |
| 1860 | break; |
| 1861 | case IEEE80211_STYPE_ACTION: |
Johannes Berg | 8b9a4e6 | 2010-05-28 15:22:58 +0200 | [diff] [blame] | 1862 | switch (mgmt->u.action.category) { |
Johannes Berg | 8b9a4e6 | 2010-05-28 15:22:58 +0200 | [diff] [blame] | 1863 | case WLAN_CATEGORY_SPECTRUM_MGMT: |
| 1864 | ieee80211_sta_process_chanswitch(sdata, |
| 1865 | &mgmt->u.action.u.chan_switch.sw_elem, |
| 1866 | (void *)ifmgd->associated->priv, |
| 1867 | rx_status->mactime); |
| 1868 | break; |
| 1869 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1870 | } |
| 1871 | mutex_unlock(&ifmgd->mtx); |
| 1872 | |
| 1873 | switch (rma) { |
| 1874 | case RX_MGMT_NONE: |
| 1875 | /* no action */ |
| 1876 | break; |
| 1877 | case RX_MGMT_CFG80211_DEAUTH: |
Holger Schurig | ce47061 | 2009-10-13 13:28:13 +0200 | [diff] [blame] | 1878 | cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1879 | break; |
| 1880 | case RX_MGMT_CFG80211_DISASSOC: |
Holger Schurig | ce47061 | 2009-10-13 13:28:13 +0200 | [diff] [blame] | 1881 | cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1882 | break; |
| 1883 | default: |
| 1884 | WARN(1, "unexpected: %d", rma); |
| 1885 | } |
Johannes Berg | 36b3a62 | 2010-06-10 10:21:33 +0200 | [diff] [blame] | 1886 | return; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1887 | } |
| 1888 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1889 | mutex_unlock(&ifmgd->mtx); |
| 1890 | |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 1891 | if (skb->len >= 24 + 2 /* mgmt + deauth reason */ && |
Johannes Berg | b054b74 | 2010-06-07 21:50:07 +0200 | [diff] [blame] | 1892 | (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH) { |
| 1893 | struct ieee80211_local *local = sdata->local; |
| 1894 | struct ieee80211_work *wk; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1895 | |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 1896 | mutex_lock(&local->mtx); |
Johannes Berg | b054b74 | 2010-06-07 21:50:07 +0200 | [diff] [blame] | 1897 | list_for_each_entry(wk, &local->work_list, list) { |
| 1898 | if (wk->sdata != sdata) |
| 1899 | continue; |
| 1900 | |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 1901 | if (wk->type != IEEE80211_WORK_ASSOC && |
| 1902 | wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT) |
Johannes Berg | b054b74 | 2010-06-07 21:50:07 +0200 | [diff] [blame] | 1903 | continue; |
| 1904 | |
| 1905 | if (memcmp(mgmt->bssid, wk->filter_ta, ETH_ALEN)) |
| 1906 | continue; |
| 1907 | if (memcmp(mgmt->sa, wk->filter_ta, ETH_ALEN)) |
| 1908 | continue; |
| 1909 | |
| 1910 | /* |
| 1911 | * Printing the message only here means we can't |
| 1912 | * spuriously print it, but it also means that it |
| 1913 | * won't be printed when the frame comes in before |
| 1914 | * we even tried to associate or in similar cases. |
| 1915 | * |
| 1916 | * Ultimately, I suspect cfg80211 should print the |
| 1917 | * messages instead. |
| 1918 | */ |
| 1919 | printk(KERN_DEBUG |
| 1920 | "%s: deauthenticated from %pM (Reason: %u)\n", |
| 1921 | sdata->name, mgmt->bssid, |
| 1922 | le16_to_cpu(mgmt->u.deauth.reason_code)); |
| 1923 | |
| 1924 | list_del_rcu(&wk->list); |
| 1925 | free_work(wk); |
| 1926 | break; |
| 1927 | } |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 1928 | mutex_unlock(&local->mtx); |
Johannes Berg | b054b74 | 2010-06-07 21:50:07 +0200 | [diff] [blame] | 1929 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1930 | cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len); |
Johannes Berg | b054b74 | 2010-06-07 21:50:07 +0200 | [diff] [blame] | 1931 | } |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 1934 | static void ieee80211_sta_timer(unsigned long data) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1935 | { |
| 1936 | struct ieee80211_sub_if_data *sdata = |
| 1937 | (struct ieee80211_sub_if_data *) data; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 1938 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jasper Bryant-Greene | f698d85 | 2008-08-03 12:04:37 +1200 | [diff] [blame] | 1939 | struct ieee80211_local *local = sdata->local; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1940 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 1941 | if (local->quiescing) { |
| 1942 | set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running); |
| 1943 | return; |
| 1944 | } |
| 1945 | |
Johannes Berg | 64592c8 | 2010-06-10 10:21:31 +0200 | [diff] [blame] | 1946 | ieee80211_queue_work(&local->hw, &sdata->work); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1949 | static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata, |
| 1950 | u8 *bssid) |
| 1951 | { |
| 1952 | struct ieee80211_local *local = sdata->local; |
| 1953 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 1954 | |
| 1955 | ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL | |
| 1956 | IEEE80211_STA_BEACON_POLL); |
| 1957 | |
| 1958 | ieee80211_set_disassoc(sdata, true, true); |
| 1959 | mutex_unlock(&ifmgd->mtx); |
| 1960 | mutex_lock(&local->mtx); |
| 1961 | ieee80211_recalc_idle(local); |
| 1962 | mutex_unlock(&local->mtx); |
| 1963 | /* |
| 1964 | * must be outside lock due to cfg80211, |
| 1965 | * but that's not a problem. |
| 1966 | */ |
| 1967 | ieee80211_send_deauth_disassoc(sdata, bssid, |
| 1968 | IEEE80211_STYPE_DEAUTH, |
| 1969 | WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, |
| 1970 | NULL, true); |
| 1971 | mutex_lock(&ifmgd->mtx); |
| 1972 | } |
| 1973 | |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 1974 | void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata) |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1975 | { |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1976 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 1fa57d0 | 2010-06-10 10:21:32 +0200 | [diff] [blame] | 1977 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1978 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 1979 | /* then process the rest of the work */ |
| 1980 | mutex_lock(&ifmgd->mtx); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 1981 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 1982 | if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL | |
| 1983 | IEEE80211_STA_CONNECTION_POLL) && |
| 1984 | ifmgd->associated) { |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1985 | u8 bssid[ETH_ALEN]; |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 1986 | int max_tries; |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 1987 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 1988 | memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN); |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1989 | |
Felix Fietkau | 72a8a3e | 2010-11-23 03:10:32 +0100 | [diff] [blame] | 1990 | if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) |
| 1991 | max_tries = IEEE80211_MAX_NULLFUNC_TRIES; |
| 1992 | else |
| 1993 | max_tries = IEEE80211_MAX_PROBE_TRIES; |
| 1994 | |
Felix Fietkau | 4e5ff37 | 2010-11-23 03:10:31 +0100 | [diff] [blame] | 1995 | /* ACK received for nullfunc probing frame */ |
| 1996 | if (!ifmgd->probe_send_count) |
| 1997 | ieee80211_reset_ap_probe(sdata); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 1998 | else if (ifmgd->nullfunc_failed) { |
| 1999 | if (ifmgd->probe_send_count < max_tries) { |
| 2000 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 2001 | wiphy_debug(local->hw.wiphy, |
| 2002 | "%s: No ack for nullfunc frame to" |
Ben Greear | bfc31df | 2011-01-14 09:32:18 -0800 | [diff] [blame] | 2003 | " AP %pM, try %d/%i\n", |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2004 | sdata->name, bssid, |
Ben Greear | bfc31df | 2011-01-14 09:32:18 -0800 | [diff] [blame] | 2005 | ifmgd->probe_send_count, max_tries); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2006 | #endif |
| 2007 | ieee80211_mgd_probe_ap_send(sdata); |
| 2008 | } else { |
| 2009 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 2010 | wiphy_debug(local->hw.wiphy, |
| 2011 | "%s: No ack for nullfunc frame to" |
| 2012 | " AP %pM, disconnecting.\n", |
Felix Fietkau | c658e5d | 2010-12-07 04:40:18 +0100 | [diff] [blame] | 2013 | sdata->name, bssid); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2014 | #endif |
| 2015 | ieee80211_sta_connection_lost(sdata, bssid); |
| 2016 | } |
| 2017 | } else if (time_is_after_jiffies(ifmgd->probe_timeout)) |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2018 | run_again(ifmgd, ifmgd->probe_timeout); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2019 | else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) { |
| 2020 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 2021 | wiphy_debug(local->hw.wiphy, |
| 2022 | "%s: Failed to send nullfunc to AP %pM" |
| 2023 | " after %dms, disconnecting.\n", |
| 2024 | sdata->name, |
| 2025 | bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ); |
| 2026 | #endif |
| 2027 | ieee80211_sta_connection_lost(sdata, bssid); |
| 2028 | } else if (ifmgd->probe_send_count < max_tries) { |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2029 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Ben Greear | b38afa8 | 2010-10-07 16:12:06 -0700 | [diff] [blame] | 2030 | wiphy_debug(local->hw.wiphy, |
| 2031 | "%s: No probe response from AP %pM" |
Ben Greear | bfc31df | 2011-01-14 09:32:18 -0800 | [diff] [blame] | 2032 | " after %dms, try %d/%i\n", |
Ben Greear | b38afa8 | 2010-10-07 16:12:06 -0700 | [diff] [blame] | 2033 | sdata->name, |
| 2034 | bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ, |
Ben Greear | bfc31df | 2011-01-14 09:32:18 -0800 | [diff] [blame] | 2035 | ifmgd->probe_send_count, max_tries); |
Maxim Levitsky | a43abf2 | 2009-07-31 18:54:12 +0300 | [diff] [blame] | 2036 | #endif |
| 2037 | ieee80211_mgd_probe_ap_send(sdata); |
| 2038 | } else { |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2039 | /* |
| 2040 | * We actually lost the connection ... or did we? |
| 2041 | * Let's make sure! |
| 2042 | */ |
Ben Greear | b38afa8 | 2010-10-07 16:12:06 -0700 | [diff] [blame] | 2043 | wiphy_debug(local->hw.wiphy, |
| 2044 | "%s: No probe response from AP %pM" |
| 2045 | " after %dms, disconnecting.\n", |
| 2046 | sdata->name, |
| 2047 | bssid, (1000 * IEEE80211_PROBE_WAIT)/HZ); |
Felix Fietkau | 04ac3c0 | 2010-12-02 21:01:08 +0100 | [diff] [blame] | 2048 | |
| 2049 | ieee80211_sta_connection_lost(sdata, bssid); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2050 | } |
| 2051 | } |
| 2052 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2053 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | 60f8b39 | 2008-09-08 17:44:22 +0200 | [diff] [blame] | 2054 | } |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 2055 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2056 | static void ieee80211_sta_bcn_mon_timer(unsigned long data) |
| 2057 | { |
| 2058 | struct ieee80211_sub_if_data *sdata = |
| 2059 | (struct ieee80211_sub_if_data *) data; |
| 2060 | struct ieee80211_local *local = sdata->local; |
| 2061 | |
| 2062 | if (local->quiescing) |
| 2063 | return; |
| 2064 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2065 | ieee80211_queue_work(&sdata->local->hw, |
| 2066 | &sdata->u.mgd.beacon_connection_loss_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | static void ieee80211_sta_conn_mon_timer(unsigned long data) |
| 2070 | { |
| 2071 | struct ieee80211_sub_if_data *sdata = |
| 2072 | (struct ieee80211_sub_if_data *) data; |
| 2073 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2074 | struct ieee80211_local *local = sdata->local; |
| 2075 | |
| 2076 | if (local->quiescing) |
| 2077 | return; |
| 2078 | |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 2079 | ieee80211_queue_work(&local->hw, &ifmgd->monitor_work); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2080 | } |
| 2081 | |
| 2082 | static void ieee80211_sta_monitor_work(struct work_struct *work) |
| 2083 | { |
| 2084 | struct ieee80211_sub_if_data *sdata = |
| 2085 | container_of(work, struct ieee80211_sub_if_data, |
| 2086 | u.mgd.monitor_work); |
| 2087 | |
| 2088 | ieee80211_mgd_probe_ap(sdata, false); |
| 2089 | } |
| 2090 | |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 2091 | static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata) |
| 2092 | { |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 2093 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2094 | sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL | |
| 2095 | IEEE80211_STA_CONNECTION_POLL); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 2096 | |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2097 | /* let's probe the connection once */ |
Luis R. Rodriguez | 42935ec | 2009-07-29 20:08:07 -0400 | [diff] [blame] | 2098 | ieee80211_queue_work(&sdata->local->hw, |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2099 | &sdata->u.mgd.monitor_work); |
| 2100 | /* and do all the other regular work too */ |
Johannes Berg | 64592c8 | 2010-06-10 10:21:31 +0200 | [diff] [blame] | 2101 | ieee80211_queue_work(&sdata->local->hw, &sdata->work); |
Kalle Valo | ad93568 | 2009-04-19 08:47:19 +0300 | [diff] [blame] | 2102 | } |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 2103 | } |
| 2104 | |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 2105 | #ifdef CONFIG_PM |
| 2106 | void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata) |
| 2107 | { |
| 2108 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2109 | |
| 2110 | /* |
| 2111 | * we need to use atomic bitops for the running bits |
| 2112 | * only because both timers might fire at the same |
| 2113 | * time -- the code here is properly synchronised. |
| 2114 | */ |
| 2115 | |
Johannes Berg | d1f5b7a | 2010-08-05 17:05:55 +0200 | [diff] [blame] | 2116 | cancel_work_sync(&ifmgd->request_smps_work); |
| 2117 | |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2118 | cancel_work_sync(&ifmgd->beacon_connection_loss_work); |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 2119 | if (del_timer_sync(&ifmgd->timer)) |
| 2120 | set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running); |
| 2121 | |
| 2122 | cancel_work_sync(&ifmgd->chswitch_work); |
| 2123 | if (del_timer_sync(&ifmgd->chswitch_timer)) |
| 2124 | set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2125 | |
| 2126 | cancel_work_sync(&ifmgd->monitor_work); |
| 2127 | /* these will just be re-established on connection */ |
| 2128 | del_timer_sync(&ifmgd->conn_mon_timer); |
| 2129 | del_timer_sync(&ifmgd->bcn_mon_timer); |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata) |
| 2133 | { |
| 2134 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
| 2135 | |
| 2136 | if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running)) |
| 2137 | add_timer(&ifmgd->timer); |
| 2138 | if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running)) |
| 2139 | add_timer(&ifmgd->chswitch_timer); |
Felix Fietkau | c8a7972 | 2010-11-19 22:55:37 +0100 | [diff] [blame] | 2140 | ieee80211_sta_reset_beacon_monitor(sdata); |
Felix Fietkau | 4609097 | 2010-11-23 20:28:03 +0100 | [diff] [blame] | 2141 | ieee80211_restart_sta_timer(sdata); |
Johannes Berg | 5bb644a | 2009-05-17 11:40:42 +0200 | [diff] [blame] | 2142 | } |
| 2143 | #endif |
| 2144 | |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2145 | /* interface setup */ |
| 2146 | void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata) |
| 2147 | { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2148 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2149 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2150 | ifmgd = &sdata->u.mgd; |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2151 | INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2152 | INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work); |
Juuso Oikarinen | 1e4dcd0 | 2010-03-19 07:14:53 +0200 | [diff] [blame] | 2153 | INIT_WORK(&ifmgd->beacon_connection_loss_work, |
| 2154 | ieee80211_beacon_connection_loss_work); |
Johannes Berg | d1f5b7a | 2010-08-05 17:05:55 +0200 | [diff] [blame] | 2155 | INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2156 | setup_timer(&ifmgd->timer, ieee80211_sta_timer, |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2157 | (unsigned long) sdata); |
Johannes Berg | b291ba1 | 2009-07-10 15:29:03 +0200 | [diff] [blame] | 2158 | setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, |
| 2159 | (unsigned long) sdata); |
| 2160 | setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, |
| 2161 | (unsigned long) sdata); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2162 | setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, |
Sujith | c481ec9 | 2009-01-06 09:28:37 +0530 | [diff] [blame] | 2163 | (unsigned long) sdata); |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2164 | |
Johannes Berg | ab1faea | 2009-07-01 21:41:17 +0200 | [diff] [blame] | 2165 | ifmgd->flags = 0; |
Johannes Berg | bbbdff9 | 2009-04-16 13:27:42 +0200 | [diff] [blame] | 2166 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2167 | mutex_init(&ifmgd->mtx); |
Johannes Berg | 0f78231 | 2009-12-01 13:37:02 +0100 | [diff] [blame] | 2168 | |
| 2169 | if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS) |
| 2170 | ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC; |
| 2171 | else |
| 2172 | ifmgd->req_smps = IEEE80211_SMPS_OFF; |
Johannes Berg | 9c6bd79 | 2008-09-11 00:01:52 +0200 | [diff] [blame] | 2173 | } |
| 2174 | |
| 2175 | /* scan finished notification */ |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 2176 | void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local) |
| 2177 | { |
| 2178 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; |
Johannes Berg | a1678f8 | 2008-09-11 00:01:47 +0200 | [diff] [blame] | 2179 | |
| 2180 | /* Restart STA timers */ |
| 2181 | rcu_read_lock(); |
| 2182 | list_for_each_entry_rcu(sdata, &local->interfaces, list) |
| 2183 | ieee80211_restart_sta_timer(sdata); |
| 2184 | rcu_read_unlock(); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 2185 | } |
Johannes Berg | 10f644a | 2009-04-16 13:17:25 +0200 | [diff] [blame] | 2186 | |
| 2187 | int ieee80211_max_network_latency(struct notifier_block *nb, |
| 2188 | unsigned long data, void *dummy) |
| 2189 | { |
| 2190 | s32 latency_usec = (s32) data; |
| 2191 | struct ieee80211_local *local = |
| 2192 | container_of(nb, struct ieee80211_local, |
| 2193 | network_latency_notifier); |
| 2194 | |
| 2195 | mutex_lock(&local->iflist_mtx); |
| 2196 | ieee80211_recalc_ps(local, latency_usec); |
| 2197 | mutex_unlock(&local->iflist_mtx); |
| 2198 | |
| 2199 | return 0; |
| 2200 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2201 | |
| 2202 | /* config hooks */ |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2203 | static enum work_done_result |
| 2204 | ieee80211_probe_auth_done(struct ieee80211_work *wk, |
| 2205 | struct sk_buff *skb) |
| 2206 | { |
| 2207 | if (!skb) { |
| 2208 | cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta); |
| 2209 | return WORK_DONE_DESTROY; |
| 2210 | } |
| 2211 | |
| 2212 | if (wk->type == IEEE80211_WORK_AUTH) { |
| 2213 | cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len); |
| 2214 | return WORK_DONE_DESTROY; |
| 2215 | } |
| 2216 | |
| 2217 | mutex_lock(&wk->sdata->u.mgd.mtx); |
| 2218 | ieee80211_rx_mgmt_probe_resp(wk->sdata, skb); |
| 2219 | mutex_unlock(&wk->sdata->u.mgd.mtx); |
| 2220 | |
| 2221 | wk->type = IEEE80211_WORK_AUTH; |
| 2222 | wk->probe_auth.tries = 0; |
| 2223 | return WORK_DONE_REQUEUE; |
| 2224 | } |
| 2225 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2226 | int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata, |
| 2227 | struct cfg80211_auth_request *req) |
| 2228 | { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2229 | const u8 *ssid; |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 2230 | struct ieee80211_work *wk; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2231 | u16 auth_alg; |
| 2232 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 2233 | if (req->local_state_change) |
| 2234 | return 0; /* no need to update mac80211 state */ |
| 2235 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2236 | switch (req->auth_type) { |
| 2237 | case NL80211_AUTHTYPE_OPEN_SYSTEM: |
| 2238 | auth_alg = WLAN_AUTH_OPEN; |
| 2239 | break; |
| 2240 | case NL80211_AUTHTYPE_SHARED_KEY: |
Johannes Berg | 9dca9c4 | 2010-07-21 10:09:25 +0200 | [diff] [blame] | 2241 | if (IS_ERR(sdata->local->wep_tx_tfm)) |
| 2242 | return -EOPNOTSUPP; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2243 | auth_alg = WLAN_AUTH_SHARED_KEY; |
| 2244 | break; |
| 2245 | case NL80211_AUTHTYPE_FT: |
| 2246 | auth_alg = WLAN_AUTH_FT; |
| 2247 | break; |
| 2248 | case NL80211_AUTHTYPE_NETWORK_EAP: |
| 2249 | auth_alg = WLAN_AUTH_LEAP; |
| 2250 | break; |
| 2251 | default: |
| 2252 | return -EOPNOTSUPP; |
| 2253 | } |
| 2254 | |
| 2255 | wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL); |
| 2256 | if (!wk) |
| 2257 | return -ENOMEM; |
| 2258 | |
Joe Perches | 5e124bd | 2010-01-08 22:33:38 -0800 | [diff] [blame] | 2259 | memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2260 | |
| 2261 | if (req->ie && req->ie_len) { |
| 2262 | memcpy(wk->ie, req->ie, req->ie_len); |
| 2263 | wk->ie_len = req->ie_len; |
| 2264 | } |
| 2265 | |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2266 | if (req->key && req->key_len) { |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2267 | wk->probe_auth.key_len = req->key_len; |
| 2268 | wk->probe_auth.key_idx = req->key_idx; |
| 2269 | memcpy(wk->probe_auth.key, req->key, req->key_len); |
Johannes Berg | fffd093 | 2009-07-08 14:22:54 +0200 | [diff] [blame] | 2270 | } |
| 2271 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2272 | ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2273 | memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]); |
| 2274 | wk->probe_auth.ssid_len = ssid[1]; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2275 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2276 | wk->probe_auth.algorithm = auth_alg; |
| 2277 | wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY; |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 2278 | |
Johannes Berg | 070bb54 | 2010-02-03 13:57:46 +0100 | [diff] [blame] | 2279 | /* if we already have a probe, don't probe again */ |
| 2280 | if (req->bss->proberesp_ies) |
| 2281 | wk->type = IEEE80211_WORK_AUTH; |
| 2282 | else |
| 2283 | wk->type = IEEE80211_WORK_DIRECT_PROBE; |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 2284 | wk->chan = req->bss->channel; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2285 | wk->sdata = sdata; |
| 2286 | wk->done = ieee80211_probe_auth_done; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2287 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2288 | ieee80211_add_work(wk); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2289 | return 0; |
| 2290 | } |
| 2291 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2292 | static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk, |
| 2293 | struct sk_buff *skb) |
| 2294 | { |
| 2295 | struct ieee80211_mgmt *mgmt; |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 2296 | struct ieee80211_rx_status *rx_status; |
| 2297 | struct ieee802_11_elems elems; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2298 | u16 status; |
| 2299 | |
| 2300 | if (!skb) { |
| 2301 | cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta); |
| 2302 | return WORK_DONE_DESTROY; |
| 2303 | } |
| 2304 | |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 2305 | if (wk->type == IEEE80211_WORK_ASSOC_BEACON_WAIT) { |
| 2306 | mutex_lock(&wk->sdata->u.mgd.mtx); |
| 2307 | rx_status = (void *) skb->cb; |
| 2308 | ieee802_11_parse_elems(skb->data + 24 + 12, skb->len - 24 - 12, &elems); |
| 2309 | ieee80211_rx_bss_info(wk->sdata, (void *)skb->data, skb->len, rx_status, |
| 2310 | &elems, true); |
| 2311 | mutex_unlock(&wk->sdata->u.mgd.mtx); |
| 2312 | |
| 2313 | wk->type = IEEE80211_WORK_ASSOC; |
| 2314 | /* not really done yet */ |
| 2315 | return WORK_DONE_REQUEUE; |
| 2316 | } |
| 2317 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2318 | mgmt = (void *)skb->data; |
| 2319 | status = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
| 2320 | |
| 2321 | if (status == WLAN_STATUS_SUCCESS) { |
| 2322 | mutex_lock(&wk->sdata->u.mgd.mtx); |
| 2323 | if (!ieee80211_assoc_success(wk, mgmt, skb->len)) { |
| 2324 | mutex_unlock(&wk->sdata->u.mgd.mtx); |
| 2325 | /* oops -- internal error -- send timeout for now */ |
| 2326 | cfg80211_send_assoc_timeout(wk->sdata->dev, |
| 2327 | wk->filter_ta); |
| 2328 | return WORK_DONE_DESTROY; |
| 2329 | } |
Juuso Oikarinen | 6854296 | 2010-06-09 13:43:26 +0300 | [diff] [blame] | 2330 | |
| 2331 | mutex_unlock(&wk->sdata->u.mgd.mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2332 | } |
| 2333 | |
| 2334 | cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len); |
| 2335 | return WORK_DONE_DESTROY; |
| 2336 | } |
| 2337 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2338 | int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata, |
| 2339 | struct cfg80211_assoc_request *req) |
| 2340 | { |
| 2341 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2342 | struct ieee80211_bss *bss = (void *)req->bss->priv; |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 2343 | struct ieee80211_work *wk; |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 2344 | const u8 *ssid; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2345 | int i; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2346 | |
| 2347 | mutex_lock(&ifmgd->mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2348 | if (ifmgd->associated) { |
Jouni Malinen | 9c87ba6 | 2010-02-28 12:13:46 +0200 | [diff] [blame] | 2349 | if (!req->prev_bssid || |
| 2350 | memcmp(req->prev_bssid, ifmgd->associated->bssid, |
| 2351 | ETH_ALEN)) { |
| 2352 | /* |
| 2353 | * We are already associated and the request was not a |
| 2354 | * reassociation request from the current BSS, so |
| 2355 | * reject it. |
| 2356 | */ |
| 2357 | mutex_unlock(&ifmgd->mtx); |
| 2358 | return -EALREADY; |
| 2359 | } |
| 2360 | |
| 2361 | /* Trying to reassociate - clear previous association state */ |
Johannes Berg | 53f73c0 | 2010-10-05 19:37:40 +0200 | [diff] [blame] | 2362 | ieee80211_set_disassoc(sdata, true, false); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2363 | } |
| 2364 | mutex_unlock(&ifmgd->mtx); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2365 | |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 2366 | wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2367 | if (!wk) |
| 2368 | return -ENOMEM; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2369 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2370 | ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N; |
Vivek Natarajan | 375177b | 2010-02-09 14:50:28 +0530 | [diff] [blame] | 2371 | ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2372 | |
Juuso Oikarinen | d8ec443 | 2010-10-01 16:02:31 +0300 | [diff] [blame] | 2373 | ifmgd->beacon_crc_valid = false; |
| 2374 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2375 | for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) |
| 2376 | if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 || |
| 2377 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP || |
| 2378 | req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) |
| 2379 | ifmgd->flags |= IEEE80211_STA_DISABLE_11N; |
| 2380 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2381 | |
| 2382 | if (req->ie && req->ie_len) { |
| 2383 | memcpy(wk->ie, req->ie, req->ie_len); |
| 2384 | wk->ie_len = req->ie_len; |
| 2385 | } else |
| 2386 | wk->ie_len = 0; |
| 2387 | |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2388 | wk->assoc.bss = req->bss; |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 2389 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2390 | memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN); |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 2391 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2392 | /* new association always uses requested smps mode */ |
| 2393 | if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) { |
| 2394 | if (ifmgd->powersave) |
| 2395 | ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC; |
| 2396 | else |
| 2397 | ifmgd->ap_smps = IEEE80211_SMPS_OFF; |
| 2398 | } else |
| 2399 | ifmgd->ap_smps = ifmgd->req_smps; |
| 2400 | |
| 2401 | wk->assoc.smps = ifmgd->ap_smps; |
Johannes Berg | 77c8144 | 2009-12-23 13:15:37 +0100 | [diff] [blame] | 2402 | /* |
| 2403 | * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode. |
| 2404 | * We still associate in non-HT mode (11a/b/g) if any one of these |
| 2405 | * ciphers is configured as pairwise. |
| 2406 | * We can set this to true for non-11n hardware, that'll be checked |
| 2407 | * separately along with the peer capabilities. |
| 2408 | */ |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2409 | wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N); |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 2410 | wk->assoc.capability = req->bss->capability; |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2411 | wk->assoc.wmm_used = bss->wmm_used; |
| 2412 | wk->assoc.supp_rates = bss->supp_rates; |
| 2413 | wk->assoc.supp_rates_len = bss->supp_rates_len; |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 2414 | wk->assoc.ht_information_ie = |
| 2415 | ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION); |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 2416 | |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 2417 | if (bss->wmm_used && bss->uapsd_supported && |
| 2418 | (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) { |
| 2419 | wk->assoc.uapsd_used = true; |
| 2420 | ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED; |
| 2421 | } else { |
| 2422 | wk->assoc.uapsd_used = false; |
| 2423 | ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED; |
| 2424 | } |
| 2425 | |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 2426 | ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID); |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 2427 | memcpy(wk->assoc.ssid, ssid + 2, ssid[1]); |
| 2428 | wk->assoc.ssid_len = ssid[1]; |
Johannes Berg | 63f170e | 2009-12-23 13:15:33 +0100 | [diff] [blame] | 2429 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2430 | if (req->prev_bssid) |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 2431 | memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2432 | |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 2433 | wk->chan = req->bss->channel; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2434 | wk->sdata = sdata; |
| 2435 | wk->done = ieee80211_assoc_done; |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 2436 | if (!bss->dtim_period && |
| 2437 | sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD) |
| 2438 | wk->type = IEEE80211_WORK_ASSOC_BEACON_WAIT; |
| 2439 | else |
| 2440 | wk->type = IEEE80211_WORK_ASSOC; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2441 | |
| 2442 | if (req->use_mfp) { |
| 2443 | ifmgd->mfp = IEEE80211_MFP_REQUIRED; |
| 2444 | ifmgd->flags |= IEEE80211_STA_MFP_ENABLED; |
| 2445 | } else { |
| 2446 | ifmgd->mfp = IEEE80211_MFP_DISABLED; |
| 2447 | ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED; |
| 2448 | } |
| 2449 | |
| 2450 | if (req->crypto.control_port) |
| 2451 | ifmgd->flags |= IEEE80211_STA_CONTROL_PORT; |
| 2452 | else |
| 2453 | ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT; |
| 2454 | |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 2455 | sdata->control_port_protocol = req->crypto.control_port_ethertype; |
| 2456 | sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt; |
| 2457 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2458 | ieee80211_add_work(wk); |
| 2459 | return 0; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2460 | } |
| 2461 | |
| 2462 | int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 2463 | struct cfg80211_deauth_request *req, |
| 2464 | void *cookie) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2465 | { |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2466 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2467 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Johannes Berg | f679f65 | 2009-12-23 13:15:34 +0100 | [diff] [blame] | 2468 | struct ieee80211_work *wk; |
Jouni Malinen | 05e48e8 | 2010-06-14 11:55:56 -0700 | [diff] [blame] | 2469 | u8 bssid[ETH_ALEN]; |
| 2470 | bool assoc_bss = false; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2471 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2472 | mutex_lock(&ifmgd->mtx); |
| 2473 | |
Jouni Malinen | 05e48e8 | 2010-06-14 11:55:56 -0700 | [diff] [blame] | 2474 | memcpy(bssid, req->bss->bssid, ETH_ALEN); |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2475 | if (ifmgd->associated == req->bss) { |
Johannes Berg | 53f73c0 | 2010-10-05 19:37:40 +0200 | [diff] [blame] | 2476 | ieee80211_set_disassoc(sdata, false, true); |
Johannes Berg | a58ce43 | 2009-11-19 12:45:42 +0100 | [diff] [blame] | 2477 | mutex_unlock(&ifmgd->mtx); |
Jouni Malinen | 05e48e8 | 2010-06-14 11:55:56 -0700 | [diff] [blame] | 2478 | assoc_bss = true; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2479 | } else { |
| 2480 | bool not_auth_yet = false; |
Johannes Berg | a58ce43 | 2009-11-19 12:45:42 +0100 | [diff] [blame] | 2481 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2482 | mutex_unlock(&ifmgd->mtx); |
| 2483 | |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 2484 | mutex_lock(&local->mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2485 | list_for_each_entry(wk, &local->work_list, list) { |
Johannes Berg | 29165e4 | 2010-02-06 15:20:13 +0100 | [diff] [blame] | 2486 | if (wk->sdata != sdata) |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2487 | continue; |
Johannes Berg | 29165e4 | 2010-02-06 15:20:13 +0100 | [diff] [blame] | 2488 | |
| 2489 | if (wk->type != IEEE80211_WORK_DIRECT_PROBE && |
Reinette Chatre | 79733a8 | 2010-05-04 16:04:49 -0700 | [diff] [blame] | 2490 | wk->type != IEEE80211_WORK_AUTH && |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 2491 | wk->type != IEEE80211_WORK_ASSOC && |
| 2492 | wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT) |
Johannes Berg | 29165e4 | 2010-02-06 15:20:13 +0100 | [diff] [blame] | 2493 | continue; |
| 2494 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2495 | if (memcmp(req->bss->bssid, wk->filter_ta, ETH_ALEN)) |
| 2496 | continue; |
Johannes Berg | 29165e4 | 2010-02-06 15:20:13 +0100 | [diff] [blame] | 2497 | |
| 2498 | not_auth_yet = wk->type == IEEE80211_WORK_DIRECT_PROBE; |
| 2499 | list_del_rcu(&wk->list); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2500 | free_work(wk); |
| 2501 | break; |
| 2502 | } |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 2503 | mutex_unlock(&local->mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 2504 | |
| 2505 | /* |
| 2506 | * If somebody requests authentication and we haven't |
| 2507 | * sent out an auth frame yet there's no need to send |
| 2508 | * out a deauth frame either. If the state was PROBE, |
| 2509 | * then this is the case. If it's AUTH we have sent a |
| 2510 | * frame, and if it's IDLE we have completed the auth |
| 2511 | * process already. |
| 2512 | */ |
| 2513 | if (not_auth_yet) { |
| 2514 | __cfg80211_auth_canceled(sdata->dev, bssid); |
| 2515 | return 0; |
| 2516 | } |
| 2517 | } |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2518 | |
Johannes Berg | 0ff7161 | 2009-09-26 14:45:41 +0200 | [diff] [blame] | 2519 | printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 2520 | sdata->name, bssid, req->reason_code); |
Johannes Berg | 0ff7161 | 2009-09-26 14:45:41 +0200 | [diff] [blame] | 2521 | |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 2522 | ieee80211_send_deauth_disassoc(sdata, bssid, IEEE80211_STYPE_DEAUTH, |
| 2523 | req->reason_code, cookie, |
| 2524 | !req->local_state_change); |
Jouni Malinen | 05e48e8 | 2010-06-14 11:55:56 -0700 | [diff] [blame] | 2525 | if (assoc_bss) |
| 2526 | sta_info_destroy_addr(sdata, bssid); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2527 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2528 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 2529 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2530 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 2531 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2532 | return 0; |
| 2533 | } |
| 2534 | |
| 2535 | int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 2536 | struct cfg80211_disassoc_request *req, |
| 2537 | void *cookie) |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2538 | { |
| 2539 | struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 2540 | u8 bssid[ETH_ALEN]; |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2541 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2542 | mutex_lock(&ifmgd->mtx); |
| 2543 | |
Johannes Berg | 8d8b261 | 2009-07-25 11:58:36 +0200 | [diff] [blame] | 2544 | /* |
| 2545 | * cfg80211 should catch this ... but it's racy since |
| 2546 | * we can receive a disassoc frame, process it, hand it |
| 2547 | * to cfg80211 while that's in a locked section already |
| 2548 | * trying to tell us that the user wants to disconnect. |
| 2549 | */ |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 2550 | if (ifmgd->associated != req->bss) { |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2551 | mutex_unlock(&ifmgd->mtx); |
| 2552 | return -ENOLINK; |
| 2553 | } |
| 2554 | |
Johannes Berg | 0ff7161 | 2009-09-26 14:45:41 +0200 | [diff] [blame] | 2555 | 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] | 2556 | sdata->name, req->bss->bssid, req->reason_code); |
Johannes Berg | 0ff7161 | 2009-09-26 14:45:41 +0200 | [diff] [blame] | 2557 | |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 2558 | memcpy(bssid, req->bss->bssid, ETH_ALEN); |
Johannes Berg | 53f73c0 | 2010-10-05 19:37:40 +0200 | [diff] [blame] | 2559 | ieee80211_set_disassoc(sdata, false, true); |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2560 | |
| 2561 | mutex_unlock(&ifmgd->mtx); |
| 2562 | |
| 2563 | ieee80211_send_deauth_disassoc(sdata, req->bss->bssid, |
Johannes Berg | 667503d | 2009-07-07 03:56:11 +0200 | [diff] [blame] | 2564 | IEEE80211_STYPE_DISASSOC, req->reason_code, |
Jouni Malinen | d5cdfac | 2010-04-04 09:37:19 +0300 | [diff] [blame] | 2565 | cookie, !req->local_state_change); |
Jouni Malinen | e69e95d | 2010-03-29 23:29:31 -0700 | [diff] [blame] | 2566 | sta_info_destroy_addr(sdata, bssid); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 2567 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2568 | mutex_lock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 2569 | ieee80211_recalc_idle(sdata->local); |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 2570 | mutex_unlock(&sdata->local->mtx); |
Johannes Berg | bc83b68 | 2009-11-29 12:19:06 +0100 | [diff] [blame] | 2571 | |
Johannes Berg | 77fdaa1 | 2009-07-07 03:45:17 +0200 | [diff] [blame] | 2572 | return 0; |
| 2573 | } |
Jouni Malinen | 026331c | 2010-02-15 12:53:10 +0200 | [diff] [blame] | 2574 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2575 | void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif, |
| 2576 | enum nl80211_cqm_rssi_threshold_event rssi_event, |
| 2577 | gfp_t gfp) |
| 2578 | { |
| 2579 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 2580 | |
Johannes Berg | b5878a2 | 2010-04-07 16:48:40 +0200 | [diff] [blame] | 2581 | trace_api_cqm_rssi_notify(sdata, rssi_event); |
| 2582 | |
Juuso Oikarinen | a97c13c | 2010-03-23 09:02:34 +0200 | [diff] [blame] | 2583 | cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp); |
| 2584 | } |
| 2585 | EXPORT_SYMBOL(ieee80211_cqm_rssi_notify); |