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