Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1 | /* |
| 2 | * mac80211 work implementation |
| 3 | * |
| 4 | * Copyright 2003-2008, Jouni Malinen <j@w1.fi> |
| 5 | * Copyright 2004, Instant802 Networks, Inc. |
| 6 | * Copyright 2005, Devicescape Software, Inc. |
| 7 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 8 | * Copyright 2007, Michael Wu <flamingice@sourmilk.net> |
| 9 | * Copyright 2009, Johannes Berg <johannes@sipsolutions.net> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/if_ether.h> |
| 18 | #include <linux/skbuff.h> |
| 19 | #include <linux/if_arp.h> |
| 20 | #include <linux/etherdevice.h> |
| 21 | #include <linux/crc32.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 23 | #include <net/mac80211.h> |
| 24 | #include <asm/unaligned.h> |
| 25 | |
| 26 | #include "ieee80211_i.h" |
| 27 | #include "rate.h" |
Johannes Berg | b2abb6e | 2011-07-19 10:39:53 +0200 | [diff] [blame] | 28 | #include "driver-ops.h" |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [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 |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 34 | |
| 35 | enum work_action { |
Johannes Berg | b8d92c9 | 2010-05-11 12:42:04 +0200 | [diff] [blame] | 36 | WORK_ACT_MISMATCH, |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 37 | WORK_ACT_NONE, |
| 38 | WORK_ACT_TIMEOUT, |
| 39 | WORK_ACT_DONE, |
| 40 | }; |
| 41 | |
| 42 | |
| 43 | /* utils */ |
| 44 | static inline void ASSERT_WORK_MTX(struct ieee80211_local *local) |
| 45 | { |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 46 | lockdep_assert_held(&local->mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /* |
| 50 | * We can have multiple work items (and connection probing) |
| 51 | * scheduling this timer, but we need to take care to only |
| 52 | * reschedule it when it should fire _earlier_ than it was |
| 53 | * asked for before, or if it's not pending right now. This |
| 54 | * function ensures that. Note that it then is required to |
| 55 | * run this function for all timeouts after the first one |
| 56 | * has happened -- the work that runs from this timer will |
| 57 | * do that. |
| 58 | */ |
| 59 | static void run_again(struct ieee80211_local *local, |
| 60 | unsigned long timeout) |
| 61 | { |
| 62 | ASSERT_WORK_MTX(local); |
| 63 | |
| 64 | if (!timer_pending(&local->work_timer) || |
| 65 | time_before(timeout, local->work_timer.expires)) |
| 66 | mod_timer(&local->work_timer, timeout); |
| 67 | } |
| 68 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 69 | void free_work(struct ieee80211_work *wk) |
| 70 | { |
Lai Jiangshan | a74ce14 | 2011-03-18 12:14:15 +0800 | [diff] [blame] | 71 | kfree_rcu(wk, rcu_head); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | static int ieee80211_compatible_rates(const u8 *supp_rates, int supp_rates_len, |
| 75 | struct ieee80211_supported_band *sband, |
| 76 | u32 *rates) |
| 77 | { |
| 78 | int i, j, count; |
| 79 | *rates = 0; |
| 80 | count = 0; |
| 81 | for (i = 0; i < supp_rates_len; i++) { |
| 82 | int rate = (supp_rates[i] & 0x7F) * 5; |
| 83 | |
| 84 | for (j = 0; j < sband->n_bitrates; j++) |
| 85 | if (sband->bitrates[j].bitrate == rate) { |
| 86 | *rates |= BIT(j); |
| 87 | count++; |
| 88 | break; |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | return count; |
| 93 | } |
| 94 | |
| 95 | /* frame sending functions */ |
| 96 | |
Johannes Berg | 77c8144 | 2009-12-23 13:15:37 +0100 | [diff] [blame] | 97 | static void ieee80211_add_ht_ie(struct sk_buff *skb, const u8 *ht_info_ie, |
| 98 | struct ieee80211_supported_band *sband, |
| 99 | struct ieee80211_channel *channel, |
| 100 | enum ieee80211_smps_mode smps) |
| 101 | { |
| 102 | struct ieee80211_ht_info *ht_info; |
| 103 | u8 *pos; |
| 104 | u32 flags = channel->flags; |
| 105 | u16 cap = sband->ht_cap.cap; |
Johannes Berg | 77c8144 | 2009-12-23 13:15:37 +0100 | [diff] [blame] | 106 | |
| 107 | if (!sband->ht_cap.ht_supported) |
| 108 | return; |
| 109 | |
| 110 | if (!ht_info_ie) |
| 111 | return; |
| 112 | |
| 113 | if (ht_info_ie[1] < sizeof(struct ieee80211_ht_info)) |
| 114 | return; |
| 115 | |
| 116 | ht_info = (struct ieee80211_ht_info *)(ht_info_ie + 2); |
| 117 | |
| 118 | /* determine capability flags */ |
| 119 | |
Johannes Berg | 77c8144 | 2009-12-23 13:15:37 +0100 | [diff] [blame] | 120 | switch (ht_info->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { |
| 121 | case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: |
| 122 | if (flags & IEEE80211_CHAN_NO_HT40PLUS) { |
| 123 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 124 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 125 | } |
| 126 | break; |
| 127 | case IEEE80211_HT_PARAM_CHA_SEC_BELOW: |
| 128 | if (flags & IEEE80211_CHAN_NO_HT40MINUS) { |
| 129 | cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40; |
| 130 | cap &= ~IEEE80211_HT_CAP_SGI_40; |
| 131 | } |
| 132 | break; |
| 133 | } |
| 134 | |
| 135 | /* set SM PS mode properly */ |
| 136 | cap &= ~IEEE80211_HT_CAP_SM_PS; |
| 137 | switch (smps) { |
| 138 | case IEEE80211_SMPS_AUTOMATIC: |
| 139 | case IEEE80211_SMPS_NUM_MODES: |
| 140 | WARN_ON(1); |
| 141 | case IEEE80211_SMPS_OFF: |
| 142 | cap |= WLAN_HT_CAP_SM_PS_DISABLED << |
| 143 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 144 | break; |
| 145 | case IEEE80211_SMPS_STATIC: |
| 146 | cap |= WLAN_HT_CAP_SM_PS_STATIC << |
| 147 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 148 | break; |
| 149 | case IEEE80211_SMPS_DYNAMIC: |
| 150 | cap |= WLAN_HT_CAP_SM_PS_DYNAMIC << |
| 151 | IEEE80211_HT_CAP_SM_PS_SHIFT; |
| 152 | break; |
| 153 | } |
| 154 | |
| 155 | /* reserve and fill IE */ |
Johannes Berg | 77c8144 | 2009-12-23 13:15:37 +0100 | [diff] [blame] | 156 | pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2); |
Alexander Simon | 42e7aa7 | 2011-10-26 14:47:26 -0700 | [diff] [blame] | 157 | ieee80211_ie_build_ht_cap(pos, sband, cap); |
Johannes Berg | 77c8144 | 2009-12-23 13:15:37 +0100 | [diff] [blame] | 158 | } |
| 159 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 160 | static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata, |
| 161 | struct ieee80211_work *wk) |
| 162 | { |
| 163 | struct ieee80211_local *local = sdata->local; |
| 164 | struct sk_buff *skb; |
| 165 | struct ieee80211_mgmt *mgmt; |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 166 | u8 *pos, qos_info; |
Johannes Berg | 8e664fb | 2009-12-23 13:15:38 +0100 | [diff] [blame] | 167 | size_t offset = 0, noffset; |
Rajkumar Manoharan | 0915cba | 2011-04-25 15:56:17 +0530 | [diff] [blame] | 168 | int i, count, rates_len, supp_rates_len; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 169 | u16 capab; |
| 170 | struct ieee80211_supported_band *sband; |
| 171 | u32 rates = 0; |
| 172 | |
Johannes Berg | 77c8144 | 2009-12-23 13:15:37 +0100 | [diff] [blame] | 173 | sband = local->hw.wiphy->bands[wk->chan->band]; |
| 174 | |
Stanislaw Gruszka | 76f2736 | 2010-04-28 17:03:15 +0200 | [diff] [blame] | 175 | if (wk->assoc.supp_rates_len) { |
| 176 | /* |
| 177 | * Get all rates supported by the device and the AP as |
| 178 | * some APs don't like getting a superset of their rates |
| 179 | * in the association request (e.g. D-Link DAP 1353 in |
| 180 | * b-only mode)... |
| 181 | */ |
| 182 | rates_len = ieee80211_compatible_rates(wk->assoc.supp_rates, |
| 183 | wk->assoc.supp_rates_len, |
| 184 | sband, &rates); |
| 185 | } else { |
| 186 | /* |
| 187 | * In case AP not provide any supported rates information |
| 188 | * before association, we send information element(s) with |
| 189 | * all rates that we support. |
| 190 | */ |
| 191 | rates = ~0; |
| 192 | rates_len = sband->n_bitrates; |
| 193 | } |
Johannes Berg | 77c8144 | 2009-12-23 13:15:37 +0100 | [diff] [blame] | 194 | |
| 195 | skb = alloc_skb(local->hw.extra_tx_headroom + |
| 196 | sizeof(*mgmt) + /* bit too much but doesn't matter */ |
| 197 | 2 + wk->assoc.ssid_len + /* SSID */ |
| 198 | 4 + rates_len + /* (extended) rates */ |
| 199 | 4 + /* power capability */ |
| 200 | 2 + 2 * sband->n_channels + /* supported channels */ |
| 201 | 2 + sizeof(struct ieee80211_ht_cap) + /* HT */ |
| 202 | wk->ie_len + /* extra IEs */ |
| 203 | 9, /* WMM */ |
| 204 | GFP_KERNEL); |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 205 | if (!skb) |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 206 | return; |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 207 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 208 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 209 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 210 | capab = WLAN_CAPABILITY_ESS; |
| 211 | |
| 212 | if (sband->band == IEEE80211_BAND_2GHZ) { |
| 213 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE)) |
| 214 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 215 | if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE)) |
| 216 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 217 | } |
| 218 | |
| 219 | if (wk->assoc.capability & WLAN_CAPABILITY_PRIVACY) |
| 220 | capab |= WLAN_CAPABILITY_PRIVACY; |
| 221 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 222 | if ((wk->assoc.capability & WLAN_CAPABILITY_SPECTRUM_MGMT) && |
| 223 | (local->hw.flags & IEEE80211_HW_SPECTRUM_MGMT)) |
| 224 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; |
| 225 | |
| 226 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 227 | memset(mgmt, 0, 24); |
| 228 | memcpy(mgmt->da, wk->filter_ta, ETH_ALEN); |
| 229 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
| 230 | memcpy(mgmt->bssid, wk->filter_ta, ETH_ALEN); |
| 231 | |
| 232 | if (!is_zero_ether_addr(wk->assoc.prev_bssid)) { |
| 233 | skb_put(skb, 10); |
| 234 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 235 | IEEE80211_STYPE_REASSOC_REQ); |
| 236 | mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab); |
| 237 | mgmt->u.reassoc_req.listen_interval = |
| 238 | cpu_to_le16(local->hw.conf.listen_interval); |
| 239 | memcpy(mgmt->u.reassoc_req.current_ap, wk->assoc.prev_bssid, |
| 240 | ETH_ALEN); |
| 241 | } else { |
| 242 | skb_put(skb, 4); |
| 243 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 244 | IEEE80211_STYPE_ASSOC_REQ); |
| 245 | mgmt->u.assoc_req.capab_info = cpu_to_le16(capab); |
| 246 | mgmt->u.assoc_req.listen_interval = |
| 247 | cpu_to_le16(local->hw.conf.listen_interval); |
| 248 | } |
| 249 | |
| 250 | /* SSID */ |
Rajkumar Manoharan | 0915cba | 2011-04-25 15:56:17 +0530 | [diff] [blame] | 251 | pos = skb_put(skb, 2 + wk->assoc.ssid_len); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 252 | *pos++ = WLAN_EID_SSID; |
| 253 | *pos++ = wk->assoc.ssid_len; |
| 254 | memcpy(pos, wk->assoc.ssid, wk->assoc.ssid_len); |
| 255 | |
| 256 | /* add all rates which were marked to be used above */ |
| 257 | supp_rates_len = rates_len; |
| 258 | if (supp_rates_len > 8) |
| 259 | supp_rates_len = 8; |
| 260 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 261 | pos = skb_put(skb, supp_rates_len + 2); |
| 262 | *pos++ = WLAN_EID_SUPP_RATES; |
| 263 | *pos++ = supp_rates_len; |
| 264 | |
| 265 | count = 0; |
| 266 | for (i = 0; i < sband->n_bitrates; i++) { |
| 267 | if (BIT(i) & rates) { |
| 268 | int rate = sband->bitrates[i].bitrate; |
| 269 | *pos++ = (u8) (rate / 5); |
| 270 | if (++count == 8) |
| 271 | break; |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | if (rates_len > count) { |
| 276 | pos = skb_put(skb, rates_len - count + 2); |
| 277 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 278 | *pos++ = rates_len - count; |
| 279 | |
| 280 | for (i++; i < sband->n_bitrates; i++) { |
| 281 | if (BIT(i) & rates) { |
| 282 | int rate = sband->bitrates[i].bitrate; |
| 283 | *pos++ = (u8) (rate / 5); |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) { |
| 289 | /* 1. power capabilities */ |
| 290 | pos = skb_put(skb, 4); |
| 291 | *pos++ = WLAN_EID_PWR_CAPABILITY; |
| 292 | *pos++ = 2; |
| 293 | *pos++ = 0; /* min tx power */ |
Johannes Berg | 77c8144 | 2009-12-23 13:15:37 +0100 | [diff] [blame] | 294 | *pos++ = wk->chan->max_power; /* max tx power */ |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 295 | |
| 296 | /* 2. supported channels */ |
| 297 | /* TODO: get this in reg domain format */ |
| 298 | pos = skb_put(skb, 2 * sband->n_channels + 2); |
| 299 | *pos++ = WLAN_EID_SUPPORTED_CHANNELS; |
| 300 | *pos++ = 2 * sband->n_channels; |
| 301 | for (i = 0; i < sband->n_channels; i++) { |
| 302 | *pos++ = ieee80211_frequency_to_channel( |
| 303 | sband->channels[i].center_freq); |
| 304 | *pos++ = 1; /* one channel in the subband*/ |
| 305 | } |
| 306 | } |
| 307 | |
Johannes Berg | 8e664fb | 2009-12-23 13:15:38 +0100 | [diff] [blame] | 308 | /* if present, add any custom IEs that go before HT */ |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 309 | if (wk->ie_len && wk->ie) { |
Johannes Berg | 8e664fb | 2009-12-23 13:15:38 +0100 | [diff] [blame] | 310 | static const u8 before_ht[] = { |
| 311 | WLAN_EID_SSID, |
| 312 | WLAN_EID_SUPP_RATES, |
| 313 | WLAN_EID_EXT_SUPP_RATES, |
| 314 | WLAN_EID_PWR_CAPABILITY, |
| 315 | WLAN_EID_SUPPORTED_CHANNELS, |
| 316 | WLAN_EID_RSN, |
| 317 | WLAN_EID_QOS_CAPA, |
| 318 | WLAN_EID_RRM_ENABLED_CAPABILITIES, |
| 319 | WLAN_EID_MOBILITY_DOMAIN, |
| 320 | WLAN_EID_SUPPORTED_REGULATORY_CLASSES, |
| 321 | }; |
| 322 | noffset = ieee80211_ie_split(wk->ie, wk->ie_len, |
| 323 | before_ht, ARRAY_SIZE(before_ht), |
| 324 | offset); |
| 325 | pos = skb_put(skb, noffset - offset); |
| 326 | memcpy(pos, wk->ie + offset, noffset - offset); |
| 327 | offset = noffset; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 328 | } |
| 329 | |
Johannes Berg | 77c8144 | 2009-12-23 13:15:37 +0100 | [diff] [blame] | 330 | if (wk->assoc.use_11n && wk->assoc.wmm_used && |
| 331 | local->hw.queues >= 4) |
| 332 | ieee80211_add_ht_ie(skb, wk->assoc.ht_information_ie, |
| 333 | sband, wk->chan, wk->assoc.smps); |
| 334 | |
Johannes Berg | 8e664fb | 2009-12-23 13:15:38 +0100 | [diff] [blame] | 335 | /* if present, add any custom non-vendor IEs that go after HT */ |
| 336 | if (wk->ie_len && wk->ie) { |
| 337 | noffset = ieee80211_ie_split_vendor(wk->ie, wk->ie_len, |
| 338 | offset); |
| 339 | pos = skb_put(skb, noffset - offset); |
| 340 | memcpy(pos, wk->ie + offset, noffset - offset); |
| 341 | offset = noffset; |
| 342 | } |
| 343 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 344 | if (wk->assoc.wmm_used && local->hw.queues >= 4) { |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 345 | if (wk->assoc.uapsd_used) { |
Kalle Valo | 50ae0cf | 2010-01-12 10:42:39 +0200 | [diff] [blame] | 346 | qos_info = local->uapsd_queues; |
| 347 | qos_info |= (local->uapsd_max_sp_len << |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 348 | IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT); |
| 349 | } else { |
| 350 | qos_info = 0; |
| 351 | } |
| 352 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 353 | pos = skb_put(skb, 9); |
| 354 | *pos++ = WLAN_EID_VENDOR_SPECIFIC; |
| 355 | *pos++ = 7; /* len */ |
| 356 | *pos++ = 0x00; /* Microsoft OUI 00:50:F2 */ |
| 357 | *pos++ = 0x50; |
| 358 | *pos++ = 0xf2; |
| 359 | *pos++ = 2; /* WME */ |
| 360 | *pos++ = 0; /* WME info */ |
| 361 | *pos++ = 1; /* WME ver */ |
Kalle Valo | ab13315 | 2010-01-12 10:42:31 +0200 | [diff] [blame] | 362 | *pos++ = qos_info; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 363 | } |
| 364 | |
Johannes Berg | 8e664fb | 2009-12-23 13:15:38 +0100 | [diff] [blame] | 365 | /* add any remaining custom (i.e. vendor specific here) IEs */ |
| 366 | if (wk->ie_len && wk->ie) { |
| 367 | noffset = wk->ie_len; |
| 368 | pos = skb_put(skb, noffset - offset); |
| 369 | memcpy(pos, wk->ie + offset, noffset - offset); |
| 370 | } |
| 371 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 372 | IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 373 | ieee80211_tx_skb(sdata, skb); |
| 374 | } |
| 375 | |
| 376 | static void ieee80211_remove_auth_bss(struct ieee80211_local *local, |
| 377 | struct ieee80211_work *wk) |
| 378 | { |
| 379 | struct cfg80211_bss *cbss; |
| 380 | u16 capa_val = WLAN_CAPABILITY_ESS; |
| 381 | |
| 382 | if (wk->probe_auth.privacy) |
| 383 | capa_val |= WLAN_CAPABILITY_PRIVACY; |
| 384 | |
| 385 | cbss = cfg80211_get_bss(local->hw.wiphy, wk->chan, wk->filter_ta, |
| 386 | wk->probe_auth.ssid, wk->probe_auth.ssid_len, |
| 387 | WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_PRIVACY, |
| 388 | capa_val); |
| 389 | if (!cbss) |
| 390 | return; |
| 391 | |
| 392 | cfg80211_unlink_bss(local->hw.wiphy, cbss); |
| 393 | cfg80211_put_bss(cbss); |
| 394 | } |
| 395 | |
| 396 | static enum work_action __must_check |
| 397 | ieee80211_direct_probe(struct ieee80211_work *wk) |
| 398 | { |
| 399 | struct ieee80211_sub_if_data *sdata = wk->sdata; |
| 400 | struct ieee80211_local *local = sdata->local; |
| 401 | |
Johannes Berg | b2abb6e | 2011-07-19 10:39:53 +0200 | [diff] [blame] | 402 | if (!wk->probe_auth.synced) { |
| 403 | int ret = drv_tx_sync(local, sdata, wk->filter_ta, |
| 404 | IEEE80211_TX_SYNC_AUTH); |
| 405 | if (ret) |
| 406 | return WORK_ACT_TIMEOUT; |
| 407 | } |
| 408 | wk->probe_auth.synced = true; |
| 409 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 410 | wk->probe_auth.tries++; |
| 411 | if (wk->probe_auth.tries > IEEE80211_AUTH_MAX_TRIES) { |
Johannes Berg | 7d3a1c3 | 2009-12-23 13:15:36 +0100 | [diff] [blame] | 412 | printk(KERN_DEBUG "%s: direct probe to %pM timed out\n", |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 413 | sdata->name, wk->filter_ta); |
| 414 | |
| 415 | /* |
| 416 | * Most likely AP is not in the range so remove the |
| 417 | * bss struct for that AP. |
| 418 | */ |
| 419 | ieee80211_remove_auth_bss(local, wk); |
| 420 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 421 | return WORK_ACT_TIMEOUT; |
| 422 | } |
| 423 | |
Ben Greear | 2f88675 | 2010-12-07 11:27:01 -0800 | [diff] [blame] | 424 | printk(KERN_DEBUG "%s: direct probe to %pM (try %d/%i)\n", |
| 425 | sdata->name, wk->filter_ta, wk->probe_auth.tries, |
| 426 | IEEE80211_AUTH_MAX_TRIES); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 427 | |
| 428 | /* |
| 429 | * Direct probe is sent to broadcast address as some APs |
| 430 | * will not answer to direct packet in unassociated state. |
| 431 | */ |
| 432 | ieee80211_send_probe_req(sdata, NULL, wk->probe_auth.ssid, |
Johannes Berg | 85a237f | 2011-07-18 18:08:36 +0200 | [diff] [blame] | 433 | wk->probe_auth.ssid_len, NULL, 0, |
Rajkumar Manoharan | aad14ce | 2011-09-25 14:53:31 +0530 | [diff] [blame] | 434 | (u32) -1, true, false); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 435 | |
| 436 | wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT; |
| 437 | run_again(local, wk->timeout); |
| 438 | |
| 439 | return WORK_ACT_NONE; |
| 440 | } |
| 441 | |
| 442 | |
| 443 | static enum work_action __must_check |
| 444 | ieee80211_authenticate(struct ieee80211_work *wk) |
| 445 | { |
| 446 | struct ieee80211_sub_if_data *sdata = wk->sdata; |
| 447 | struct ieee80211_local *local = sdata->local; |
| 448 | |
Johannes Berg | b2abb6e | 2011-07-19 10:39:53 +0200 | [diff] [blame] | 449 | if (!wk->probe_auth.synced) { |
| 450 | int ret = drv_tx_sync(local, sdata, wk->filter_ta, |
| 451 | IEEE80211_TX_SYNC_AUTH); |
| 452 | if (ret) |
| 453 | return WORK_ACT_TIMEOUT; |
| 454 | } |
| 455 | wk->probe_auth.synced = true; |
| 456 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 457 | wk->probe_auth.tries++; |
| 458 | if (wk->probe_auth.tries > IEEE80211_AUTH_MAX_TRIES) { |
Johannes Berg | 7d3a1c3 | 2009-12-23 13:15:36 +0100 | [diff] [blame] | 459 | printk(KERN_DEBUG "%s: authentication with %pM" |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 460 | " timed out\n", sdata->name, wk->filter_ta); |
| 461 | |
| 462 | /* |
| 463 | * Most likely AP is not in the range so remove the |
| 464 | * bss struct for that AP. |
| 465 | */ |
| 466 | ieee80211_remove_auth_bss(local, wk); |
| 467 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 468 | return WORK_ACT_TIMEOUT; |
| 469 | } |
| 470 | |
Johannes Berg | 7d3a1c3 | 2009-12-23 13:15:36 +0100 | [diff] [blame] | 471 | printk(KERN_DEBUG "%s: authenticate with %pM (try %d)\n", |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 472 | sdata->name, wk->filter_ta, wk->probe_auth.tries); |
| 473 | |
| 474 | ieee80211_send_auth(sdata, 1, wk->probe_auth.algorithm, wk->ie, |
| 475 | wk->ie_len, wk->filter_ta, NULL, 0, 0); |
| 476 | wk->probe_auth.transaction = 2; |
| 477 | |
| 478 | wk->timeout = jiffies + IEEE80211_AUTH_TIMEOUT; |
| 479 | run_again(local, wk->timeout); |
| 480 | |
| 481 | return WORK_ACT_NONE; |
| 482 | } |
| 483 | |
| 484 | static enum work_action __must_check |
| 485 | ieee80211_associate(struct ieee80211_work *wk) |
| 486 | { |
| 487 | struct ieee80211_sub_if_data *sdata = wk->sdata; |
| 488 | struct ieee80211_local *local = sdata->local; |
| 489 | |
Johannes Berg | b2abb6e | 2011-07-19 10:39:53 +0200 | [diff] [blame] | 490 | if (!wk->assoc.synced) { |
| 491 | int ret = drv_tx_sync(local, sdata, wk->filter_ta, |
| 492 | IEEE80211_TX_SYNC_ASSOC); |
| 493 | if (ret) |
| 494 | return WORK_ACT_TIMEOUT; |
| 495 | } |
| 496 | wk->assoc.synced = true; |
| 497 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 498 | wk->assoc.tries++; |
| 499 | if (wk->assoc.tries > IEEE80211_ASSOC_MAX_TRIES) { |
Johannes Berg | 7d3a1c3 | 2009-12-23 13:15:36 +0100 | [diff] [blame] | 500 | printk(KERN_DEBUG "%s: association with %pM" |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 501 | " timed out\n", |
| 502 | sdata->name, wk->filter_ta); |
| 503 | |
| 504 | /* |
| 505 | * Most likely AP is not in the range so remove the |
| 506 | * bss struct for that AP. |
| 507 | */ |
| 508 | if (wk->assoc.bss) |
Johannes Berg | 0c1ad2c | 2009-12-23 13:15:39 +0100 | [diff] [blame] | 509 | cfg80211_unlink_bss(local->hw.wiphy, wk->assoc.bss); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 510 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 511 | return WORK_ACT_TIMEOUT; |
| 512 | } |
| 513 | |
Johannes Berg | 7d3a1c3 | 2009-12-23 13:15:36 +0100 | [diff] [blame] | 514 | printk(KERN_DEBUG "%s: associate with %pM (try %d)\n", |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 515 | sdata->name, wk->filter_ta, wk->assoc.tries); |
| 516 | ieee80211_send_assoc(sdata, wk); |
| 517 | |
| 518 | wk->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT; |
| 519 | run_again(local, wk->timeout); |
| 520 | |
| 521 | return WORK_ACT_NONE; |
| 522 | } |
| 523 | |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 524 | static enum work_action __must_check |
| 525 | ieee80211_remain_on_channel_timeout(struct ieee80211_work *wk) |
| 526 | { |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 527 | /* |
| 528 | * First time we run, do nothing -- the generic code will |
| 529 | * have switched to the right channel etc. |
| 530 | */ |
Johannes Berg | 723bae7 | 2010-01-25 13:36:36 +0100 | [diff] [blame] | 531 | if (!wk->started) { |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 532 | wk->timeout = jiffies + msecs_to_jiffies(wk->remain.duration); |
| 533 | |
Kalle Valo | 1990ca6 | 2009-12-30 14:42:20 +0200 | [diff] [blame] | 534 | cfg80211_ready_on_channel(wk->sdata->dev, (unsigned long) wk, |
| 535 | wk->chan, wk->chan_type, |
| 536 | wk->remain.duration, GFP_KERNEL); |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 537 | |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 538 | return WORK_ACT_NONE; |
| 539 | } |
| 540 | |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 541 | return WORK_ACT_TIMEOUT; |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 542 | } |
| 543 | |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 544 | static enum work_action __must_check |
Johannes Berg | f30221e | 2010-11-25 10:02:30 +0100 | [diff] [blame] | 545 | ieee80211_offchannel_tx(struct ieee80211_work *wk) |
| 546 | { |
| 547 | if (!wk->started) { |
| 548 | wk->timeout = jiffies + msecs_to_jiffies(wk->offchan_tx.wait); |
| 549 | |
| 550 | /* |
| 551 | * After this, offchan_tx.frame remains but now is no |
| 552 | * longer a valid pointer -- we still need it as the |
Johannes Berg | 28a1bcd | 2011-10-04 18:27:10 +0200 | [diff] [blame] | 553 | * cookie for canceling this work/status matching. |
Johannes Berg | f30221e | 2010-11-25 10:02:30 +0100 | [diff] [blame] | 554 | */ |
| 555 | ieee80211_tx_skb(wk->sdata, wk->offchan_tx.frame); |
| 556 | |
| 557 | return WORK_ACT_NONE; |
| 558 | } |
| 559 | |
| 560 | return WORK_ACT_TIMEOUT; |
| 561 | } |
| 562 | |
| 563 | static enum work_action __must_check |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 564 | ieee80211_assoc_beacon_wait(struct ieee80211_work *wk) |
| 565 | { |
| 566 | if (wk->started) |
| 567 | return WORK_ACT_TIMEOUT; |
| 568 | |
| 569 | /* |
| 570 | * Wait up to one beacon interval ... |
| 571 | * should this be more if we miss one? |
| 572 | */ |
| 573 | printk(KERN_DEBUG "%s: waiting for beacon from %pM\n", |
| 574 | wk->sdata->name, wk->filter_ta); |
| 575 | wk->timeout = TU_TO_EXP_TIME(wk->assoc.bss->beacon_interval); |
| 576 | return WORK_ACT_NONE; |
| 577 | } |
| 578 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 579 | static void ieee80211_auth_challenge(struct ieee80211_work *wk, |
| 580 | struct ieee80211_mgmt *mgmt, |
| 581 | size_t len) |
| 582 | { |
| 583 | struct ieee80211_sub_if_data *sdata = wk->sdata; |
| 584 | u8 *pos; |
| 585 | struct ieee802_11_elems elems; |
| 586 | |
| 587 | pos = mgmt->u.auth.variable; |
| 588 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
| 589 | if (!elems.challenge) |
| 590 | return; |
| 591 | ieee80211_send_auth(sdata, 3, wk->probe_auth.algorithm, |
| 592 | elems.challenge - 2, elems.challenge_len + 2, |
| 593 | wk->filter_ta, wk->probe_auth.key, |
| 594 | wk->probe_auth.key_len, wk->probe_auth.key_idx); |
| 595 | wk->probe_auth.transaction = 4; |
| 596 | } |
| 597 | |
| 598 | static enum work_action __must_check |
| 599 | ieee80211_rx_mgmt_auth(struct ieee80211_work *wk, |
| 600 | struct ieee80211_mgmt *mgmt, size_t len) |
| 601 | { |
| 602 | u16 auth_alg, auth_transaction, status_code; |
| 603 | |
| 604 | if (wk->type != IEEE80211_WORK_AUTH) |
Johannes Berg | b8d92c9 | 2010-05-11 12:42:04 +0200 | [diff] [blame] | 605 | return WORK_ACT_MISMATCH; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 606 | |
| 607 | if (len < 24 + 6) |
| 608 | return WORK_ACT_NONE; |
| 609 | |
| 610 | auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg); |
| 611 | auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction); |
| 612 | status_code = le16_to_cpu(mgmt->u.auth.status_code); |
| 613 | |
| 614 | if (auth_alg != wk->probe_auth.algorithm || |
| 615 | auth_transaction != wk->probe_auth.transaction) |
| 616 | return WORK_ACT_NONE; |
| 617 | |
| 618 | if (status_code != WLAN_STATUS_SUCCESS) { |
| 619 | printk(KERN_DEBUG "%s: %pM denied authentication (status %d)\n", |
| 620 | wk->sdata->name, mgmt->sa, status_code); |
| 621 | return WORK_ACT_DONE; |
| 622 | } |
| 623 | |
| 624 | switch (wk->probe_auth.algorithm) { |
| 625 | case WLAN_AUTH_OPEN: |
| 626 | case WLAN_AUTH_LEAP: |
| 627 | case WLAN_AUTH_FT: |
| 628 | break; |
| 629 | case WLAN_AUTH_SHARED_KEY: |
| 630 | if (wk->probe_auth.transaction != 4) { |
| 631 | ieee80211_auth_challenge(wk, mgmt, len); |
| 632 | /* need another frame */ |
| 633 | return WORK_ACT_NONE; |
| 634 | } |
| 635 | break; |
| 636 | default: |
| 637 | WARN_ON(1); |
| 638 | return WORK_ACT_NONE; |
| 639 | } |
| 640 | |
| 641 | printk(KERN_DEBUG "%s: authenticated\n", wk->sdata->name); |
| 642 | return WORK_ACT_DONE; |
| 643 | } |
| 644 | |
| 645 | static enum work_action __must_check |
| 646 | ieee80211_rx_mgmt_assoc_resp(struct ieee80211_work *wk, |
| 647 | struct ieee80211_mgmt *mgmt, size_t len, |
| 648 | bool reassoc) |
| 649 | { |
| 650 | struct ieee80211_sub_if_data *sdata = wk->sdata; |
| 651 | struct ieee80211_local *local = sdata->local; |
| 652 | u16 capab_info, status_code, aid; |
| 653 | struct ieee802_11_elems elems; |
| 654 | u8 *pos; |
| 655 | |
Johannes Berg | b8d92c9 | 2010-05-11 12:42:04 +0200 | [diff] [blame] | 656 | if (wk->type != IEEE80211_WORK_ASSOC) |
| 657 | return WORK_ACT_MISMATCH; |
| 658 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 659 | /* |
| 660 | * AssocResp and ReassocResp have identical structure, so process both |
| 661 | * of them in this function. |
| 662 | */ |
| 663 | |
| 664 | if (len < 24 + 6) |
| 665 | return WORK_ACT_NONE; |
| 666 | |
| 667 | capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info); |
| 668 | status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code); |
| 669 | aid = le16_to_cpu(mgmt->u.assoc_resp.aid); |
| 670 | |
| 671 | printk(KERN_DEBUG "%s: RX %sssocResp from %pM (capab=0x%x " |
| 672 | "status=%d aid=%d)\n", |
| 673 | sdata->name, reassoc ? "Rea" : "A", mgmt->sa, |
| 674 | capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14)))); |
| 675 | |
| 676 | pos = mgmt->u.assoc_resp.variable; |
| 677 | ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems); |
| 678 | |
| 679 | if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY && |
| 680 | elems.timeout_int && elems.timeout_int_len == 5 && |
| 681 | elems.timeout_int[0] == WLAN_TIMEOUT_ASSOC_COMEBACK) { |
| 682 | u32 tu, ms; |
| 683 | tu = get_unaligned_le32(elems.timeout_int + 1); |
| 684 | ms = tu * 1024 / 1000; |
Johannes Berg | 7d3a1c3 | 2009-12-23 13:15:36 +0100 | [diff] [blame] | 685 | printk(KERN_DEBUG "%s: %pM rejected association temporarily; " |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 686 | "comeback duration %u TU (%u ms)\n", |
Johannes Berg | 7d3a1c3 | 2009-12-23 13:15:36 +0100 | [diff] [blame] | 687 | sdata->name, mgmt->sa, tu, ms); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 688 | wk->timeout = jiffies + msecs_to_jiffies(ms); |
| 689 | if (ms > IEEE80211_ASSOC_TIMEOUT) |
| 690 | run_again(local, wk->timeout); |
| 691 | return WORK_ACT_NONE; |
| 692 | } |
| 693 | |
| 694 | if (status_code != WLAN_STATUS_SUCCESS) |
Johannes Berg | 7d3a1c3 | 2009-12-23 13:15:36 +0100 | [diff] [blame] | 695 | printk(KERN_DEBUG "%s: %pM denied association (code=%d)\n", |
| 696 | sdata->name, mgmt->sa, status_code); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 697 | else |
| 698 | printk(KERN_DEBUG "%s: associated\n", sdata->name); |
| 699 | |
| 700 | return WORK_ACT_DONE; |
| 701 | } |
| 702 | |
| 703 | static enum work_action __must_check |
| 704 | ieee80211_rx_mgmt_probe_resp(struct ieee80211_work *wk, |
| 705 | struct ieee80211_mgmt *mgmt, size_t len, |
| 706 | struct ieee80211_rx_status *rx_status) |
| 707 | { |
| 708 | struct ieee80211_sub_if_data *sdata = wk->sdata; |
| 709 | struct ieee80211_local *local = sdata->local; |
| 710 | size_t baselen; |
| 711 | |
| 712 | ASSERT_WORK_MTX(local); |
| 713 | |
Johannes Berg | b8d92c9 | 2010-05-11 12:42:04 +0200 | [diff] [blame] | 714 | if (wk->type != IEEE80211_WORK_DIRECT_PROBE) |
| 715 | return WORK_ACT_MISMATCH; |
| 716 | |
| 717 | if (len < 24 + 12) |
| 718 | return WORK_ACT_NONE; |
| 719 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 720 | baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt; |
| 721 | if (baselen > len) |
| 722 | return WORK_ACT_NONE; |
| 723 | |
| 724 | printk(KERN_DEBUG "%s: direct probe responded\n", sdata->name); |
| 725 | return WORK_ACT_DONE; |
| 726 | } |
| 727 | |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 728 | static enum work_action __must_check |
| 729 | ieee80211_rx_mgmt_beacon(struct ieee80211_work *wk, |
| 730 | struct ieee80211_mgmt *mgmt, size_t len) |
| 731 | { |
| 732 | struct ieee80211_sub_if_data *sdata = wk->sdata; |
| 733 | struct ieee80211_local *local = sdata->local; |
| 734 | |
| 735 | ASSERT_WORK_MTX(local); |
| 736 | |
| 737 | if (wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT) |
| 738 | return WORK_ACT_MISMATCH; |
| 739 | |
| 740 | if (len < 24 + 12) |
| 741 | return WORK_ACT_NONE; |
| 742 | |
| 743 | printk(KERN_DEBUG "%s: beacon received\n", sdata->name); |
| 744 | return WORK_ACT_DONE; |
| 745 | } |
| 746 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 747 | static void ieee80211_work_rx_queued_mgmt(struct ieee80211_local *local, |
| 748 | struct sk_buff *skb) |
| 749 | { |
| 750 | struct ieee80211_rx_status *rx_status; |
| 751 | struct ieee80211_mgmt *mgmt; |
| 752 | struct ieee80211_work *wk; |
Christoph Fritz | 021570e | 2010-06-16 16:37:34 +0200 | [diff] [blame] | 753 | enum work_action rma = WORK_ACT_NONE; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 754 | u16 fc; |
| 755 | |
| 756 | rx_status = (struct ieee80211_rx_status *) skb->cb; |
| 757 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 758 | fc = le16_to_cpu(mgmt->frame_control); |
| 759 | |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 760 | mutex_lock(&local->mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 761 | |
| 762 | list_for_each_entry(wk, &local->work_list, list) { |
| 763 | const u8 *bssid = NULL; |
| 764 | |
| 765 | switch (wk->type) { |
| 766 | case IEEE80211_WORK_DIRECT_PROBE: |
| 767 | case IEEE80211_WORK_AUTH: |
| 768 | case IEEE80211_WORK_ASSOC: |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 769 | case IEEE80211_WORK_ASSOC_BEACON_WAIT: |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 770 | bssid = wk->filter_ta; |
| 771 | break; |
| 772 | default: |
| 773 | continue; |
| 774 | } |
| 775 | |
| 776 | /* |
| 777 | * Before queuing, we already verified mgmt->sa, |
| 778 | * so this is needed just for matching. |
| 779 | */ |
| 780 | if (compare_ether_addr(bssid, mgmt->bssid)) |
| 781 | continue; |
| 782 | |
| 783 | switch (fc & IEEE80211_FCTL_STYPE) { |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 784 | case IEEE80211_STYPE_BEACON: |
| 785 | rma = ieee80211_rx_mgmt_beacon(wk, mgmt, skb->len); |
| 786 | break; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 787 | case IEEE80211_STYPE_PROBE_RESP: |
| 788 | rma = ieee80211_rx_mgmt_probe_resp(wk, mgmt, skb->len, |
| 789 | rx_status); |
| 790 | break; |
| 791 | case IEEE80211_STYPE_AUTH: |
| 792 | rma = ieee80211_rx_mgmt_auth(wk, mgmt, skb->len); |
| 793 | break; |
| 794 | case IEEE80211_STYPE_ASSOC_RESP: |
| 795 | rma = ieee80211_rx_mgmt_assoc_resp(wk, mgmt, |
| 796 | skb->len, false); |
| 797 | break; |
| 798 | case IEEE80211_STYPE_REASSOC_RESP: |
| 799 | rma = ieee80211_rx_mgmt_assoc_resp(wk, mgmt, |
| 800 | skb->len, true); |
| 801 | break; |
| 802 | default: |
| 803 | WARN_ON(1); |
Johannes Berg | b8d92c9 | 2010-05-11 12:42:04 +0200 | [diff] [blame] | 804 | rma = WORK_ACT_NONE; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 805 | } |
Johannes Berg | b8d92c9 | 2010-05-11 12:42:04 +0200 | [diff] [blame] | 806 | |
| 807 | /* |
| 808 | * We've either received an unexpected frame, or we have |
| 809 | * multiple work items and need to match the frame to the |
| 810 | * right one. |
| 811 | */ |
| 812 | if (rma == WORK_ACT_MISMATCH) |
| 813 | continue; |
| 814 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 815 | /* |
| 816 | * We've processed this frame for that work, so it can't |
| 817 | * belong to another work struct. |
| 818 | * NB: this is also required for correctness for 'rma'! |
| 819 | */ |
| 820 | break; |
| 821 | } |
| 822 | |
| 823 | switch (rma) { |
Johannes Berg | b8d92c9 | 2010-05-11 12:42:04 +0200 | [diff] [blame] | 824 | case WORK_ACT_MISMATCH: |
| 825 | /* ignore this unmatched frame */ |
| 826 | break; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 827 | case WORK_ACT_NONE: |
| 828 | break; |
| 829 | case WORK_ACT_DONE: |
| 830 | list_del_rcu(&wk->list); |
| 831 | break; |
| 832 | default: |
| 833 | WARN(1, "unexpected: %d", rma); |
| 834 | } |
| 835 | |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 836 | mutex_unlock(&local->mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 837 | |
| 838 | if (rma != WORK_ACT_DONE) |
| 839 | goto out; |
| 840 | |
| 841 | switch (wk->done(wk, skb)) { |
| 842 | case WORK_DONE_DESTROY: |
| 843 | free_work(wk); |
| 844 | break; |
| 845 | case WORK_DONE_REQUEUE: |
| 846 | synchronize_rcu(); |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 847 | wk->started = false; /* restart */ |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 848 | mutex_lock(&local->mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 849 | list_add_tail(&wk->list, &local->work_list); |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 850 | mutex_unlock(&local->mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | out: |
| 854 | kfree_skb(skb); |
| 855 | } |
| 856 | |
Ben Greear | da2fd1f | 2011-02-07 13:44:36 -0800 | [diff] [blame] | 857 | static bool ieee80211_work_ct_coexists(enum nl80211_channel_type wk_ct, |
| 858 | enum nl80211_channel_type oper_ct) |
| 859 | { |
| 860 | switch (wk_ct) { |
| 861 | case NL80211_CHAN_NO_HT: |
| 862 | return true; |
| 863 | case NL80211_CHAN_HT20: |
| 864 | if (oper_ct != NL80211_CHAN_NO_HT) |
| 865 | return true; |
| 866 | return false; |
| 867 | case NL80211_CHAN_HT40MINUS: |
| 868 | case NL80211_CHAN_HT40PLUS: |
| 869 | return (wk_ct == oper_ct); |
| 870 | } |
| 871 | WARN_ON(1); /* shouldn't get here */ |
| 872 | return false; |
| 873 | } |
| 874 | |
| 875 | static enum nl80211_channel_type |
| 876 | ieee80211_calc_ct(enum nl80211_channel_type wk_ct, |
| 877 | enum nl80211_channel_type oper_ct) |
| 878 | { |
| 879 | switch (wk_ct) { |
| 880 | case NL80211_CHAN_NO_HT: |
| 881 | return oper_ct; |
| 882 | case NL80211_CHAN_HT20: |
| 883 | if (oper_ct != NL80211_CHAN_NO_HT) |
| 884 | return oper_ct; |
| 885 | return wk_ct; |
| 886 | case NL80211_CHAN_HT40MINUS: |
| 887 | case NL80211_CHAN_HT40PLUS: |
| 888 | return wk_ct; |
| 889 | } |
| 890 | WARN_ON(1); /* shouldn't get here */ |
| 891 | return wk_ct; |
| 892 | } |
| 893 | |
| 894 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 895 | static void ieee80211_work_timer(unsigned long data) |
| 896 | { |
| 897 | struct ieee80211_local *local = (void *) data; |
| 898 | |
| 899 | if (local->quiescing) |
| 900 | return; |
| 901 | |
| 902 | ieee80211_queue_work(&local->hw, &local->work_work); |
| 903 | } |
| 904 | |
| 905 | static void ieee80211_work_work(struct work_struct *work) |
| 906 | { |
| 907 | struct ieee80211_local *local = |
| 908 | container_of(work, struct ieee80211_local, work_work); |
| 909 | struct sk_buff *skb; |
| 910 | struct ieee80211_work *wk, *tmp; |
| 911 | LIST_HEAD(free_work); |
| 912 | enum work_action rma; |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 913 | bool remain_off_channel = false; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 914 | |
| 915 | if (local->scanning) |
| 916 | return; |
| 917 | |
| 918 | /* |
| 919 | * ieee80211_queue_work() should have picked up most cases, |
Walter Goldens | 77c2061 | 2010-05-18 04:44:54 -0700 | [diff] [blame] | 920 | * here we'll pick the rest. |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 921 | */ |
| 922 | if (WARN(local->suspended, "work scheduled while going to suspend\n")) |
| 923 | return; |
| 924 | |
| 925 | /* first process frames to avoid timing out while a frame is pending */ |
| 926 | while ((skb = skb_dequeue(&local->work_skb_queue))) |
| 927 | ieee80211_work_rx_queued_mgmt(local, skb); |
| 928 | |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 929 | mutex_lock(&local->mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 930 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 931 | ieee80211_recalc_idle(local); |
| 932 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 933 | list_for_each_entry_safe(wk, tmp, &local->work_list, list) { |
Johannes Berg | 723bae7 | 2010-01-25 13:36:36 +0100 | [diff] [blame] | 934 | bool started = wk->started; |
| 935 | |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 936 | /* mark work as started if it's on the current off-channel */ |
Johannes Berg | 723bae7 | 2010-01-25 13:36:36 +0100 | [diff] [blame] | 937 | if (!started && local->tmp_channel && |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 938 | wk->chan == local->tmp_channel && |
| 939 | wk->chan_type == local->tmp_channel_type) { |
Johannes Berg | 723bae7 | 2010-01-25 13:36:36 +0100 | [diff] [blame] | 940 | started = true; |
Johannes Berg | 81ac346 | 2010-01-06 15:30:58 +0100 | [diff] [blame] | 941 | wk->timeout = jiffies; |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 942 | } |
| 943 | |
Johannes Berg | 723bae7 | 2010-01-25 13:36:36 +0100 | [diff] [blame] | 944 | if (!started && !local->tmp_channel) { |
Stanislaw Gruszka | 4fdbff0 | 2011-11-03 10:40:47 +0100 | [diff] [blame] | 945 | bool on_oper_chan, on_oper_chan2; |
Ben Greear | da2fd1f | 2011-02-07 13:44:36 -0800 | [diff] [blame] | 946 | enum nl80211_channel_type wk_ct; |
Stanislaw Gruszka | 4fdbff0 | 2011-11-03 10:40:47 +0100 | [diff] [blame] | 947 | |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 948 | on_oper_chan = ieee80211_cfg_on_oper_channel(local); |
Ben Greear | da2fd1f | 2011-02-07 13:44:36 -0800 | [diff] [blame] | 949 | |
| 950 | /* Work with existing channel type if possible. */ |
| 951 | wk_ct = wk->chan_type; |
| 952 | if (wk->chan == local->hw.conf.channel) |
| 953 | wk_ct = ieee80211_calc_ct(wk->chan_type, |
| 954 | local->hw.conf.channel_type); |
| 955 | |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 956 | local->tmp_channel = wk->chan; |
Ben Greear | da2fd1f | 2011-02-07 13:44:36 -0800 | [diff] [blame] | 957 | local->tmp_channel_type = wk_ct; |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 958 | /* |
| 959 | * Leave the station vifs in awake mode if they |
| 960 | * happen to be on the same channel as |
| 961 | * the requested channel. |
| 962 | */ |
| 963 | on_oper_chan2 = ieee80211_cfg_on_oper_channel(local); |
| 964 | if (on_oper_chan != on_oper_chan2) { |
| 965 | if (on_oper_chan2) { |
| 966 | /* going off oper channel, PS too */ |
| 967 | ieee80211_offchannel_stop_vifs(local, |
| 968 | true); |
| 969 | ieee80211_hw_config(local, 0); |
| 970 | } else { |
| 971 | /* going on channel, but leave PS |
| 972 | * off-channel. */ |
| 973 | ieee80211_hw_config(local, 0); |
| 974 | ieee80211_offchannel_return(local, |
| 975 | true, |
| 976 | false); |
| 977 | } |
Stanislaw Gruszka | 4fdbff0 | 2011-11-03 10:40:47 +0100 | [diff] [blame] | 978 | } |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 979 | |
Johannes Berg | 723bae7 | 2010-01-25 13:36:36 +0100 | [diff] [blame] | 980 | started = true; |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 981 | wk->timeout = jiffies; |
| 982 | } |
| 983 | |
| 984 | /* don't try to work with items that aren't started */ |
Johannes Berg | 723bae7 | 2010-01-25 13:36:36 +0100 | [diff] [blame] | 985 | if (!started) |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 986 | continue; |
| 987 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 988 | if (time_is_after_jiffies(wk->timeout)) { |
| 989 | /* |
| 990 | * This work item isn't supposed to be worked on |
| 991 | * right now, but take care to adjust the timer |
| 992 | * properly. |
| 993 | */ |
| 994 | run_again(local, wk->timeout); |
| 995 | continue; |
| 996 | } |
| 997 | |
| 998 | switch (wk->type) { |
| 999 | default: |
| 1000 | WARN_ON(1); |
| 1001 | /* nothing */ |
| 1002 | rma = WORK_ACT_NONE; |
| 1003 | break; |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1004 | case IEEE80211_WORK_ABORT: |
| 1005 | rma = WORK_ACT_TIMEOUT; |
Juuso Oikarinen | 0e0a228 | 2010-02-26 08:13:41 +0200 | [diff] [blame] | 1006 | break; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1007 | case IEEE80211_WORK_DIRECT_PROBE: |
| 1008 | rma = ieee80211_direct_probe(wk); |
| 1009 | break; |
| 1010 | case IEEE80211_WORK_AUTH: |
| 1011 | rma = ieee80211_authenticate(wk); |
| 1012 | break; |
| 1013 | case IEEE80211_WORK_ASSOC: |
| 1014 | rma = ieee80211_associate(wk); |
| 1015 | break; |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1016 | case IEEE80211_WORK_REMAIN_ON_CHANNEL: |
| 1017 | rma = ieee80211_remain_on_channel_timeout(wk); |
| 1018 | break; |
Johannes Berg | f30221e | 2010-11-25 10:02:30 +0100 | [diff] [blame] | 1019 | case IEEE80211_WORK_OFFCHANNEL_TX: |
| 1020 | rma = ieee80211_offchannel_tx(wk); |
| 1021 | break; |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 1022 | case IEEE80211_WORK_ASSOC_BEACON_WAIT: |
| 1023 | rma = ieee80211_assoc_beacon_wait(wk); |
| 1024 | break; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1025 | } |
| 1026 | |
Johannes Berg | 723bae7 | 2010-01-25 13:36:36 +0100 | [diff] [blame] | 1027 | wk->started = started; |
| 1028 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1029 | switch (rma) { |
| 1030 | case WORK_ACT_NONE: |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1031 | /* might have changed the timeout */ |
| 1032 | run_again(local, wk->timeout); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1033 | break; |
| 1034 | case WORK_ACT_TIMEOUT: |
| 1035 | list_del_rcu(&wk->list); |
| 1036 | synchronize_rcu(); |
| 1037 | list_add(&wk->list, &free_work); |
| 1038 | break; |
| 1039 | default: |
| 1040 | WARN(1, "unexpected: %d", rma); |
| 1041 | } |
| 1042 | } |
| 1043 | |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1044 | list_for_each_entry(wk, &local->work_list, list) { |
| 1045 | if (!wk->started) |
| 1046 | continue; |
| 1047 | if (wk->chan != local->tmp_channel) |
| 1048 | continue; |
Eliad Peller | eaa7af2 | 2011-10-20 19:05:49 +0200 | [diff] [blame] | 1049 | if (!ieee80211_work_ct_coexists(wk->chan_type, |
| 1050 | local->tmp_channel_type)) |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1051 | continue; |
| 1052 | remain_off_channel = true; |
| 1053 | } |
| 1054 | |
| 1055 | if (!remain_off_channel && local->tmp_channel) { |
| 1056 | local->tmp_channel = NULL; |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 1057 | /* If tmp_channel wasn't operating channel, then |
| 1058 | * we need to go back on-channel. |
| 1059 | * NOTE: If we can ever be here while scannning, |
| 1060 | * or if the hw_config() channel config logic changes, |
| 1061 | * then we may need to do a more thorough check to see if |
| 1062 | * we still need to do a hardware config. Currently, |
| 1063 | * we cannot be here while scanning, however. |
| 1064 | */ |
Eliad Peller | 6911bf0 | 2011-10-20 19:05:50 +0200 | [diff] [blame] | 1065 | if (!ieee80211_cfg_on_oper_channel(local)) |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 1066 | ieee80211_hw_config(local, 0); |
| 1067 | |
| 1068 | /* At the least, we need to disable offchannel_ps, |
| 1069 | * so just go ahead and run the entire offchannel |
| 1070 | * return logic here. We *could* skip enabling |
| 1071 | * beaconing if we were already on-oper-channel |
| 1072 | * as a future optimization. |
| 1073 | */ |
| 1074 | ieee80211_offchannel_return(local, true, true); |
| 1075 | |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1076 | /* give connection some time to breathe */ |
| 1077 | run_again(local, jiffies + HZ/2); |
| 1078 | } |
| 1079 | |
Teemu Paasikivi | 68dd5b7 | 2010-04-09 13:07:55 +0300 | [diff] [blame] | 1080 | if (list_empty(&local->work_list) && local->scan_req && |
| 1081 | !local->scanning) |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1082 | ieee80211_queue_delayed_work(&local->hw, |
| 1083 | &local->scan_work, |
| 1084 | round_jiffies_relative(0)); |
| 1085 | |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1086 | ieee80211_recalc_idle(local); |
| 1087 | |
Johannes Berg | 7da7cc1 | 2010-08-05 17:02:38 +0200 | [diff] [blame] | 1088 | mutex_unlock(&local->mtx); |
| 1089 | |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1090 | list_for_each_entry_safe(wk, tmp, &free_work, list) { |
| 1091 | wk->done(wk, NULL); |
| 1092 | list_del(&wk->list); |
| 1093 | kfree(wk); |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | void ieee80211_add_work(struct ieee80211_work *wk) |
| 1098 | { |
| 1099 | struct ieee80211_local *local; |
| 1100 | |
| 1101 | if (WARN_ON(!wk->chan)) |
| 1102 | return; |
| 1103 | |
| 1104 | if (WARN_ON(!wk->sdata)) |
| 1105 | return; |
| 1106 | |
| 1107 | if (WARN_ON(!wk->done)) |
| 1108 | return; |
| 1109 | |
Johannes Berg | 81ac346 | 2010-01-06 15:30:58 +0100 | [diff] [blame] | 1110 | if (WARN_ON(!ieee80211_sdata_running(wk->sdata))) |
| 1111 | return; |
| 1112 | |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1113 | wk->started = false; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1114 | |
| 1115 | local = wk->sdata->local; |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 1116 | mutex_lock(&local->mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1117 | list_add_tail(&wk->list, &local->work_list); |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 1118 | mutex_unlock(&local->mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1119 | |
| 1120 | ieee80211_queue_work(&local->hw, &local->work_work); |
| 1121 | } |
| 1122 | |
| 1123 | void ieee80211_work_init(struct ieee80211_local *local) |
| 1124 | { |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1125 | INIT_LIST_HEAD(&local->work_list); |
| 1126 | setup_timer(&local->work_timer, ieee80211_work_timer, |
| 1127 | (unsigned long)local); |
| 1128 | INIT_WORK(&local->work_work, ieee80211_work_work); |
| 1129 | skb_queue_head_init(&local->work_skb_queue); |
| 1130 | } |
| 1131 | |
| 1132 | void ieee80211_work_purge(struct ieee80211_sub_if_data *sdata) |
| 1133 | { |
| 1134 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1135 | struct ieee80211_work *wk; |
Herton Ronaldo Krzesinski | 8808f64 | 2010-12-13 11:43:51 -0200 | [diff] [blame] | 1136 | bool cleanup = false; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1137 | |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 1138 | mutex_lock(&local->mtx); |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1139 | list_for_each_entry(wk, &local->work_list, list) { |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1140 | if (wk->sdata != sdata) |
| 1141 | continue; |
Herton Ronaldo Krzesinski | 8808f64 | 2010-12-13 11:43:51 -0200 | [diff] [blame] | 1142 | cleanup = true; |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1143 | wk->type = IEEE80211_WORK_ABORT; |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1144 | wk->started = true; |
| 1145 | wk->timeout = jiffies; |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1146 | } |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 1147 | mutex_unlock(&local->mtx); |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1148 | |
| 1149 | /* run cleanups etc. */ |
Herton Ronaldo Krzesinski | 8808f64 | 2010-12-13 11:43:51 -0200 | [diff] [blame] | 1150 | if (cleanup) |
| 1151 | ieee80211_work_work(&local->work_work); |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1152 | |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 1153 | mutex_lock(&local->mtx); |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1154 | list_for_each_entry(wk, &local->work_list, list) { |
| 1155 | if (wk->sdata != sdata) |
| 1156 | continue; |
| 1157 | WARN_ON(1); |
| 1158 | break; |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1159 | } |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 1160 | mutex_unlock(&local->mtx); |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | ieee80211_rx_result ieee80211_work_rx_mgmt(struct ieee80211_sub_if_data *sdata, |
| 1164 | struct sk_buff *skb) |
| 1165 | { |
| 1166 | struct ieee80211_local *local = sdata->local; |
| 1167 | struct ieee80211_mgmt *mgmt; |
| 1168 | struct ieee80211_work *wk; |
| 1169 | u16 fc; |
| 1170 | |
| 1171 | if (skb->len < 24) |
| 1172 | return RX_DROP_MONITOR; |
| 1173 | |
| 1174 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 1175 | fc = le16_to_cpu(mgmt->frame_control); |
| 1176 | |
| 1177 | list_for_each_entry_rcu(wk, &local->work_list, list) { |
| 1178 | if (sdata != wk->sdata) |
| 1179 | continue; |
| 1180 | if (compare_ether_addr(wk->filter_ta, mgmt->sa)) |
| 1181 | continue; |
| 1182 | if (compare_ether_addr(wk->filter_ta, mgmt->bssid)) |
| 1183 | continue; |
| 1184 | |
| 1185 | switch (fc & IEEE80211_FCTL_STYPE) { |
| 1186 | case IEEE80211_STYPE_AUTH: |
| 1187 | case IEEE80211_STYPE_PROBE_RESP: |
| 1188 | case IEEE80211_STYPE_ASSOC_RESP: |
| 1189 | case IEEE80211_STYPE_REASSOC_RESP: |
Johannes Berg | e5b900d | 2010-07-29 16:08:55 +0200 | [diff] [blame] | 1190 | case IEEE80211_STYPE_BEACON: |
Johannes Berg | af6b637 | 2009-12-23 13:15:35 +0100 | [diff] [blame] | 1191 | skb_queue_tail(&local->work_skb_queue, skb); |
| 1192 | ieee80211_queue_work(&local->hw, &local->work_work); |
| 1193 | return RX_QUEUED; |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | return RX_CONTINUE; |
| 1198 | } |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1199 | |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1200 | static enum work_done_result ieee80211_remain_done(struct ieee80211_work *wk, |
| 1201 | struct sk_buff *skb) |
| 1202 | { |
| 1203 | /* |
| 1204 | * We are done serving the remain-on-channel command. |
| 1205 | */ |
Kalle Valo | 1990ca6 | 2009-12-30 14:42:20 +0200 | [diff] [blame] | 1206 | cfg80211_remain_on_channel_expired(wk->sdata->dev, (unsigned long) wk, |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1207 | wk->chan, wk->chan_type, |
| 1208 | GFP_KERNEL); |
| 1209 | |
| 1210 | return WORK_DONE_DESTROY; |
| 1211 | } |
| 1212 | |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1213 | int ieee80211_wk_remain_on_channel(struct ieee80211_sub_if_data *sdata, |
| 1214 | struct ieee80211_channel *chan, |
| 1215 | enum nl80211_channel_type channel_type, |
| 1216 | unsigned int duration, u64 *cookie) |
| 1217 | { |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1218 | struct ieee80211_work *wk; |
| 1219 | |
| 1220 | wk = kzalloc(sizeof(*wk), GFP_KERNEL); |
| 1221 | if (!wk) |
| 1222 | return -ENOMEM; |
| 1223 | |
| 1224 | wk->type = IEEE80211_WORK_REMAIN_ON_CHANNEL; |
| 1225 | wk->chan = chan; |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1226 | wk->chan_type = channel_type; |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1227 | wk->sdata = sdata; |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1228 | wk->done = ieee80211_remain_done; |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1229 | |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1230 | wk->remain.duration = duration; |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1231 | |
Kalle Valo | 1990ca6 | 2009-12-30 14:42:20 +0200 | [diff] [blame] | 1232 | *cookie = (unsigned long) wk; |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1233 | |
| 1234 | ieee80211_add_work(wk); |
| 1235 | |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1236 | return 0; |
| 1237 | } |
| 1238 | |
| 1239 | int ieee80211_wk_cancel_remain_on_channel(struct ieee80211_sub_if_data *sdata, |
| 1240 | u64 cookie) |
| 1241 | { |
| 1242 | struct ieee80211_local *local = sdata->local; |
| 1243 | struct ieee80211_work *wk, *tmp; |
| 1244 | bool found = false; |
| 1245 | |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 1246 | mutex_lock(&local->mtx); |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1247 | list_for_each_entry_safe(wk, tmp, &local->work_list, list) { |
Kalle Valo | 1990ca6 | 2009-12-30 14:42:20 +0200 | [diff] [blame] | 1248 | if ((unsigned long) wk == cookie) { |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1249 | wk->timeout = jiffies; |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1250 | found = true; |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1251 | break; |
| 1252 | } |
| 1253 | } |
Johannes Berg | a1699b7 | 2010-07-30 16:46:07 +0200 | [diff] [blame] | 1254 | mutex_unlock(&local->mtx); |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1255 | |
| 1256 | if (!found) |
| 1257 | return -ENOENT; |
| 1258 | |
Johannes Berg | e4da8c3 | 2009-12-23 13:15:43 +0100 | [diff] [blame] | 1259 | ieee80211_queue_work(&local->hw, &local->work_work); |
Johannes Berg | b8bc4b0 | 2009-12-23 13:15:42 +0100 | [diff] [blame] | 1260 | |
| 1261 | return 0; |
| 1262 | } |