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