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