00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <linux/delay.h>
00015 #include <linux/if_ether.h>
00016 #include <linux/skbuff.h>
00017 #include <linux/if_arp.h>
00018 #include <linux/etherdevice.h>
00019 #include <linux/moduleparam.h>
00020 #include <linux/rtnetlink.h>
00021 #include <linux/pm_qos.h>
00022 #include <linux/crc32.h>
00023 #include <linux/slab.h>
00024 #include <linux/export.h>
00025 #include <net/mac80211.h>
00026 #include <asm/unaligned.h>
00027
00028 #include "ieee80211_i.h"
00029 #include "driver-ops.h"
00030 #include "rate.h"
00031 #include "led.h"
00032
00033 static int max_nullfunc_tries = 2;
00034 module_param(max_nullfunc_tries, int, 0644);
00035 MODULE_PARM_DESC(max_nullfunc_tries,
00036 "Maximum nullfunc tx tries before disconnecting (reason 4).");
00037
00038 static int max_probe_tries = 5;
00039 module_param(max_probe_tries, int, 0644);
00040 MODULE_PARM_DESC(max_probe_tries,
00041 "Maximum probe tries before disconnecting (reason 4).");
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051 #define IEEE80211_BEACON_LOSS_COUNT 7
00052
00053
00054
00055
00056
00057 #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
00058
00059
00060
00061
00062
00063 static int probe_wait_ms = 500;
00064 module_param(probe_wait_ms, int, 0644);
00065 MODULE_PARM_DESC(probe_wait_ms,
00066 "Maximum time(ms) to wait for probe response"
00067 " before disconnecting (reason 4).");
00068
00069
00070
00071
00072
00073
00074 #define IEEE80211_SIGNAL_AVE_WEIGHT 3
00075
00076
00077
00078
00079
00080 #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
00081
00082 #define TMR_RUNNING_TIMER 0
00083 #define TMR_RUNNING_CHANSW 1
00084
00085
00086
00087
00088
00089
00090
00091 enum rx_mgmt_action {
00092
00093 RX_MGMT_NONE,
00094
00095
00096 RX_MGMT_CFG80211_DEAUTH,
00097
00098
00099 RX_MGMT_CFG80211_DISASSOC,
00100 };
00101
00102
00103 static inline void ASSERT_MGD_MTX(struct ieee80211_if_managed *ifmgd)
00104 {
00105 lockdep_assert_held(&ifmgd->mtx);
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118 static void run_again(struct ieee80211_if_managed *ifmgd,
00119 unsigned long timeout)
00120 {
00121 ASSERT_MGD_MTX(ifmgd);
00122
00123 if (!timer_pending(&ifmgd->timer) ||
00124 time_before(timeout, ifmgd->timer.expires))
00125 mod_timer(&ifmgd->timer, timeout);
00126 }
00127
00128 void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
00129 {
00130 if (sdata->local->hw.flags & IEEE80211_HW_BEACON_FILTER)
00131 return;
00132
00133 mod_timer(&sdata->u.mgd.bcn_mon_timer,
00134 round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
00135 }
00136
00137 void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
00138 {
00139 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
00140
00141 if (unlikely(!sdata->u.mgd.associated))
00142 return;
00143
00144 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
00145 return;
00146
00147 mod_timer(&sdata->u.mgd.conn_mon_timer,
00148 round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
00149
00150 ifmgd->probe_send_count = 0;
00151 }
00152
00153 static int ecw2cw(int ecw)
00154 {
00155 return (1 << ecw) - 1;
00156 }
00157
00158
00159
00160
00161
00162
00163 static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
00164 struct ieee80211_ht_info *hti,
00165 const u8 *bssid, u16 ap_ht_cap_flags,
00166 bool beacon_htcap_ie)
00167 {
00168 struct ieee80211_local *local = sdata->local;
00169 struct ieee80211_supported_band *sband;
00170 struct sta_info *sta;
00171 u32 changed = 0;
00172 int hti_cfreq;
00173 u16 ht_opmode;
00174 bool enable_ht = true;
00175 enum nl80211_channel_type prev_chantype;
00176 enum nl80211_channel_type channel_type = NL80211_CHAN_NO_HT;
00177
00178 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
00179
00180 prev_chantype = sdata->vif.bss_conf.channel_type;
00181
00182
00183 if (!sband->ht_cap.ht_supported)
00184 enable_ht = false;
00185
00186 if (enable_ht) {
00187 hti_cfreq = ieee80211_channel_to_frequency(hti->control_chan,
00188 sband->band);
00189
00190 if (local->hw.conf.channel->center_freq != hti_cfreq) {
00191
00192
00193
00194
00195 printk(KERN_DEBUG
00196 "%s: Wrong control channel in association"
00197 " response: configured center-freq: %d"
00198 " hti-cfreq: %d hti->control_chan: %d"
00199 " band: %d. Disabling HT.\n",
00200 sdata->name,
00201 local->hw.conf.channel->center_freq,
00202 hti_cfreq, hti->control_chan,
00203 sband->band);
00204 enable_ht = false;
00205 }
00206 }
00207
00208 if (enable_ht) {
00209 channel_type = NL80211_CHAN_HT20;
00210
00211 if (!(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
00212 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
00213 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY)) {
00214 switch(hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
00215 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
00216 if (!(local->hw.conf.channel->flags &
00217 IEEE80211_CHAN_NO_HT40PLUS))
00218 channel_type = NL80211_CHAN_HT40PLUS;
00219 break;
00220 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
00221 if (!(local->hw.conf.channel->flags &
00222 IEEE80211_CHAN_NO_HT40MINUS))
00223 channel_type = NL80211_CHAN_HT40MINUS;
00224 break;
00225 }
00226 }
00227 }
00228
00229 if (local->tmp_channel)
00230 local->tmp_channel_type = channel_type;
00231
00232 if (!ieee80211_set_channel_type(local, sdata, channel_type)) {
00233
00234 channel_type = NL80211_CHAN_HT20;
00235 WARN_ON(!ieee80211_set_channel_type(local, sdata, channel_type));
00236 }
00237
00238 if (beacon_htcap_ie && (prev_chantype != channel_type)) {
00239
00240
00241
00242
00243
00244 ieee80211_stop_queues_by_reason(&sdata->local->hw,
00245 IEEE80211_QUEUE_STOP_REASON_CHTYPE_CHANGE);
00246
00247
00248 synchronize_net();
00249
00250 drv_flush(local, false);
00251 }
00252
00253
00254 ieee80211_hw_config(local, 0);
00255
00256 if (prev_chantype != channel_type) {
00257 rcu_read_lock();
00258 sta = sta_info_get(sdata, bssid);
00259 if (sta)
00260 rate_control_rate_update(local, sband, sta,
00261 IEEE80211_RC_HT_CHANGED,
00262 channel_type);
00263 rcu_read_unlock();
00264
00265 if (beacon_htcap_ie)
00266 ieee80211_wake_queues_by_reason(&sdata->local->hw,
00267 IEEE80211_QUEUE_STOP_REASON_CHTYPE_CHANGE);
00268 }
00269
00270 ht_opmode = le16_to_cpu(hti->operation_mode);
00271
00272
00273 if (sdata->ht_opmode_valid != enable_ht ||
00274 sdata->vif.bss_conf.ht_operation_mode != ht_opmode ||
00275 prev_chantype != channel_type) {
00276 changed |= BSS_CHANGED_HT;
00277 sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
00278 sdata->ht_opmode_valid = enable_ht;
00279 }
00280
00281 return changed;
00282 }
00283
00284
00285
00286 static void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
00287 const u8 *bssid, u16 stype, u16 reason,
00288 void *cookie, bool send_frame)
00289 {
00290 struct ieee80211_local *local = sdata->local;
00291 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
00292 struct sk_buff *skb;
00293 struct ieee80211_mgmt *mgmt;
00294
00295 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*mgmt));
00296 if (!skb)
00297 return;
00298
00299 skb_reserve(skb, local->hw.extra_tx_headroom);
00300
00301 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
00302 memset(mgmt, 0, 24);
00303 memcpy(mgmt->da, bssid, ETH_ALEN);
00304 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
00305 memcpy(mgmt->bssid, bssid, ETH_ALEN);
00306 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
00307 skb_put(skb, 2);
00308
00309 mgmt->u.deauth.reason_code = cpu_to_le16(reason);
00310
00311 if (stype == IEEE80211_STYPE_DEAUTH)
00312 if (cookie)
00313 __cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
00314 else
00315 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
00316 else
00317 if (cookie)
00318 __cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
00319 else
00320 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
00321 if (!(ifmgd->flags & IEEE80211_STA_MFP_ENABLED))
00322 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
00323
00324 if (send_frame)
00325 ieee80211_tx_skb(sdata, skb);
00326 else
00327 kfree_skb(skb);
00328 }
00329
00330 void ieee80211_send_pspoll(struct ieee80211_local *local,
00331 struct ieee80211_sub_if_data *sdata)
00332 {
00333 struct ieee80211_pspoll *pspoll;
00334 struct sk_buff *skb;
00335
00336 skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
00337 if (!skb)
00338 return;
00339
00340 pspoll = (struct ieee80211_pspoll *) skb->data;
00341 pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
00342
00343 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
00344 ieee80211_tx_skb(sdata, skb);
00345 }
00346
00347 void ieee80211_send_nullfunc(struct ieee80211_local *local,
00348 struct ieee80211_sub_if_data *sdata,
00349 int powersave)
00350 {
00351 struct sk_buff *skb;
00352 struct ieee80211_hdr_3addr *nullfunc;
00353 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
00354
00355 skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif);
00356 if (!skb)
00357 return;
00358
00359 nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
00360 if (powersave)
00361 nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
00362
00363 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
00364 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
00365 IEEE80211_STA_CONNECTION_POLL))
00366 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
00367
00368 ieee80211_tx_skb(sdata, skb);
00369 }
00370
00371 static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
00372 struct ieee80211_sub_if_data *sdata)
00373 {
00374 struct sk_buff *skb;
00375 struct ieee80211_hdr *nullfunc;
00376 __le16 fc;
00377
00378 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
00379 return;
00380
00381 skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
00382 if (!skb)
00383 return;
00384
00385 skb_reserve(skb, local->hw.extra_tx_headroom);
00386
00387 nullfunc = (struct ieee80211_hdr *) skb_put(skb, 30);
00388 memset(nullfunc, 0, 30);
00389 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
00390 IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
00391 nullfunc->frame_control = fc;
00392 memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
00393 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
00394 memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
00395 memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
00396
00397 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
00398 ieee80211_tx_skb(sdata, skb);
00399 }
00400
00401
00402 static void ieee80211_chswitch_work(struct work_struct *work)
00403 {
00404 struct ieee80211_sub_if_data *sdata =
00405 container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
00406 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
00407
00408 if (!ieee80211_sdata_running(sdata))
00409 return;
00410
00411 mutex_lock(&ifmgd->mtx);
00412 if (!ifmgd->associated)
00413 goto out;
00414
00415 sdata->local->oper_channel = sdata->local->csa_channel;
00416 if (!sdata->local->ops->channel_switch) {
00417
00418 ieee80211_hw_config(sdata->local,
00419 IEEE80211_CONF_CHANGE_CHANNEL);
00420 } else {
00421
00422 sdata->local->hw.conf.channel = sdata->local->oper_channel;
00423 }
00424
00425
00426 ifmgd->associated->channel = sdata->local->oper_channel;
00427
00428 ieee80211_wake_queues_by_reason(&sdata->local->hw,
00429 IEEE80211_QUEUE_STOP_REASON_CSA);
00430 out:
00431 ifmgd->flags &= ~IEEE80211_STA_CSA_RECEIVED;
00432 mutex_unlock(&ifmgd->mtx);
00433 }
00434
00435 void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
00436 {
00437 struct ieee80211_sub_if_data *sdata;
00438 struct ieee80211_if_managed *ifmgd;
00439
00440 sdata = vif_to_sdata(vif);
00441 ifmgd = &sdata->u.mgd;
00442
00443 trace_api_chswitch_done(sdata, success);
00444 if (!success) {
00445
00446
00447
00448
00449
00450
00451 sdata->local->csa_channel = sdata->local->oper_channel;
00452 }
00453
00454 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
00455 }
00456 EXPORT_SYMBOL(ieee80211_chswitch_done);
00457
00458 static void ieee80211_chswitch_timer(unsigned long data)
00459 {
00460 struct ieee80211_sub_if_data *sdata =
00461 (struct ieee80211_sub_if_data *) data;
00462 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
00463
00464 if (sdata->local->quiescing) {
00465 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
00466 return;
00467 }
00468
00469 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
00470 }
00471
00472 void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
00473 struct ieee80211_channel_sw_ie *sw_elem,
00474 struct ieee80211_bss *bss,
00475 u64 timestamp)
00476 {
00477 struct cfg80211_bss *cbss =
00478 container_of((void *)bss, struct cfg80211_bss, priv);
00479 struct ieee80211_channel *new_ch;
00480 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
00481 int new_freq = ieee80211_channel_to_frequency(sw_elem->new_ch_num,
00482 cbss->channel->band);
00483
00484 ASSERT_MGD_MTX(ifmgd);
00485
00486 if (!ifmgd->associated)
00487 return;
00488
00489 if (sdata->local->scanning)
00490 return;
00491
00492
00493
00494
00495 if (ifmgd->flags & IEEE80211_STA_CSA_RECEIVED)
00496 return;
00497
00498 new_ch = ieee80211_get_channel(sdata->local->hw.wiphy, new_freq);
00499 if (!new_ch || new_ch->flags & IEEE80211_CHAN_DISABLED)
00500 return;
00501
00502 sdata->local->csa_channel = new_ch;
00503
00504 if (sdata->local->ops->channel_switch) {
00505
00506 struct ieee80211_channel_switch ch_switch;
00507 memset(&ch_switch, 0, sizeof(ch_switch));
00508 ch_switch.timestamp = timestamp;
00509 if (sw_elem->mode) {
00510 ch_switch.block_tx = true;
00511 ieee80211_stop_queues_by_reason(&sdata->local->hw,
00512 IEEE80211_QUEUE_STOP_REASON_CSA);
00513 }
00514 ch_switch.channel = new_ch;
00515 ch_switch.count = sw_elem->count;
00516 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
00517 drv_channel_switch(sdata->local, &ch_switch);
00518 return;
00519 }
00520
00521
00522 if (sw_elem->count <= 1) {
00523 ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
00524 } else {
00525 if (sw_elem->mode)
00526 ieee80211_stop_queues_by_reason(&sdata->local->hw,
00527 IEEE80211_QUEUE_STOP_REASON_CSA);
00528 ifmgd->flags |= IEEE80211_STA_CSA_RECEIVED;
00529 mod_timer(&ifmgd->chswitch_timer,
00530 jiffies +
00531 msecs_to_jiffies(sw_elem->count *
00532 cbss->beacon_interval));
00533 }
00534 }
00535
00536 static void ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
00537 u16 capab_info, u8 *pwr_constr_elem,
00538 u8 pwr_constr_elem_len)
00539 {
00540 struct ieee80211_conf *conf = &sdata->local->hw.conf;
00541
00542 if (!(capab_info & WLAN_CAPABILITY_SPECTRUM_MGMT))
00543 return;
00544
00545
00546 if (pwr_constr_elem_len != 1)
00547 return;
00548
00549 if ((*pwr_constr_elem <= conf->channel->max_power) &&
00550 (*pwr_constr_elem != sdata->local->power_constr_level)) {
00551 sdata->local->power_constr_level = *pwr_constr_elem;
00552 ieee80211_hw_config(sdata->local, 0);
00553 }
00554 }
00555
00556 void ieee80211_enable_dyn_ps(struct ieee80211_vif *vif)
00557 {
00558 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
00559 struct ieee80211_local *local = sdata->local;
00560 struct ieee80211_conf *conf = &local->hw.conf;
00561
00562 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
00563 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
00564 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
00565
00566 local->disable_dynamic_ps = false;
00567 conf->dynamic_ps_timeout = local->dynamic_ps_user_timeout;
00568 }
00569 EXPORT_SYMBOL(ieee80211_enable_dyn_ps);
00570
00571 void ieee80211_disable_dyn_ps(struct ieee80211_vif *vif)
00572 {
00573 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
00574 struct ieee80211_local *local = sdata->local;
00575 struct ieee80211_conf *conf = &local->hw.conf;
00576
00577 WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
00578 !(local->hw.flags & IEEE80211_HW_SUPPORTS_PS) ||
00579 (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS));
00580
00581 local->disable_dynamic_ps = true;
00582 conf->dynamic_ps_timeout = 0;
00583 del_timer_sync(&local->dynamic_ps_timer);
00584 ieee80211_queue_work(&local->hw,
00585 &local->dynamic_ps_enable_work);
00586 }
00587 EXPORT_SYMBOL(ieee80211_disable_dyn_ps);
00588
00589
00590 static void ieee80211_enable_ps(struct ieee80211_local *local,
00591 struct ieee80211_sub_if_data *sdata)
00592 {
00593 struct ieee80211_conf *conf = &local->hw.conf;
00594
00595
00596
00597
00598
00599 if (local->scanning)
00600 return;
00601
00602 if (conf->dynamic_ps_timeout > 0 &&
00603 !(local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)) {
00604 mod_timer(&local->dynamic_ps_timer, jiffies +
00605 msecs_to_jiffies(conf->dynamic_ps_timeout));
00606 } else {
00607 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
00608 ieee80211_send_nullfunc(local, sdata, 1);
00609
00610 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
00611 (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS))
00612 return;
00613
00614 conf->flags |= IEEE80211_CONF_PS;
00615 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
00616 }
00617 }
00618
00619 static void ieee80211_change_ps(struct ieee80211_local *local)
00620 {
00621 struct ieee80211_conf *conf = &local->hw.conf;
00622
00623 if (local->ps_sdata) {
00624 ieee80211_enable_ps(local, local->ps_sdata);
00625 } else if (conf->flags & IEEE80211_CONF_PS) {
00626 conf->flags &= ~IEEE80211_CONF_PS;
00627 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
00628 del_timer_sync(&local->dynamic_ps_timer);
00629 cancel_work_sync(&local->dynamic_ps_enable_work);
00630 }
00631 }
00632
00633 static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
00634 {
00635 struct ieee80211_if_managed *mgd = &sdata->u.mgd;
00636 struct sta_info *sta = NULL;
00637 bool authorized = false;
00638
00639 if (!mgd->powersave)
00640 return false;
00641
00642 if (mgd->broken_ap)
00643 return false;
00644
00645 if (!mgd->associated)
00646 return false;
00647
00648 if (!mgd->associated->beacon_ies)
00649 return false;
00650
00651 if (mgd->flags & (IEEE80211_STA_BEACON_POLL |
00652 IEEE80211_STA_CONNECTION_POLL))
00653 return false;
00654
00655 rcu_read_lock();
00656 sta = sta_info_get(sdata, mgd->bssid);
00657 if (sta)
00658 authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
00659 rcu_read_unlock();
00660
00661 return authorized;
00662 }
00663
00664
00665 void ieee80211_recalc_ps(struct ieee80211_local *local, s32 latency)
00666 {
00667 struct ieee80211_sub_if_data *sdata, *found = NULL;
00668 int count = 0;
00669 int timeout;
00670
00671 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS)) {
00672 local->ps_sdata = NULL;
00673 return;
00674 }
00675
00676 if (!list_empty(&local->work_list)) {
00677 local->ps_sdata = NULL;
00678 goto change;
00679 }
00680
00681 list_for_each_entry(sdata, &local->interfaces, list) {
00682 if (!ieee80211_sdata_running(sdata))
00683 continue;
00684 if (sdata->vif.type == NL80211_IFTYPE_AP) {
00685
00686
00687
00688
00689 count = 0;
00690 break;
00691 }
00692 if (sdata->vif.type != NL80211_IFTYPE_STATION)
00693 continue;
00694 found = sdata;
00695 count++;
00696 }
00697
00698 if (count == 1 && ieee80211_powersave_allowed(found)) {
00699 struct ieee80211_conf *conf = &local->hw.conf;
00700 s32 beaconint_us;
00701
00702 if (latency < 0)
00703 latency = pm_qos_request(PM_QOS_NETWORK_LATENCY);
00704
00705 beaconint_us = ieee80211_tu_to_usec(
00706 found->vif.bss_conf.beacon_int);
00707
00708 timeout = local->dynamic_ps_forced_timeout;
00709 if (timeout < 0) {
00710
00711
00712
00713
00714
00715
00716
00717 if (latency > (1900 * USEC_PER_MSEC) &&
00718 latency != (2000 * USEC_PER_SEC))
00719 timeout = 0;
00720 else
00721 timeout = 100;
00722 }
00723 local->dynamic_ps_user_timeout = timeout;
00724 if (!local->disable_dynamic_ps)
00725 conf->dynamic_ps_timeout =
00726 local->dynamic_ps_user_timeout;
00727
00728 if (beaconint_us > latency) {
00729 local->ps_sdata = NULL;
00730 } else {
00731 struct ieee80211_bss *bss;
00732 int maxslp = 1;
00733 u8 dtimper;
00734
00735 bss = (void *)found->u.mgd.associated->priv;
00736 dtimper = bss->dtim_period;
00737
00738
00739 if (!dtimper)
00740 dtimper = 1;
00741 else if (dtimper > 1)
00742 maxslp = min_t(int, dtimper,
00743 latency / beaconint_us);
00744
00745 local->hw.conf.max_sleep_period = maxslp;
00746 local->hw.conf.ps_dtim_period = dtimper;
00747 local->ps_sdata = found;
00748 }
00749 } else {
00750 local->ps_sdata = NULL;
00751 }
00752
00753 change:
00754 ieee80211_change_ps(local);
00755 }
00756
00757 void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
00758 {
00759 struct ieee80211_local *local =
00760 container_of(work, struct ieee80211_local,
00761 dynamic_ps_disable_work);
00762
00763 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
00764 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
00765 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
00766 }
00767
00768 ieee80211_wake_queues_by_reason(&local->hw,
00769 IEEE80211_QUEUE_STOP_REASON_PS);
00770 }
00771
00772 void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
00773 {
00774 struct ieee80211_local *local =
00775 container_of(work, struct ieee80211_local,
00776 dynamic_ps_enable_work);
00777 struct ieee80211_sub_if_data *sdata = local->ps_sdata;
00778 struct ieee80211_if_managed *ifmgd;
00779 unsigned long flags;
00780 int q;
00781
00782
00783 if (!sdata)
00784 return;
00785
00786 ifmgd = &sdata->u.mgd;
00787
00788 if (local->hw.conf.flags & IEEE80211_CONF_PS)
00789 return;
00790
00791 if (!local->disable_dynamic_ps &&
00792 local->hw.conf.dynamic_ps_timeout > 0) {
00793
00794 if (drv_tx_frames_pending(local)) {
00795 mod_timer(&local->dynamic_ps_timer, jiffies +
00796 msecs_to_jiffies(
00797 local->hw.conf.dynamic_ps_timeout));
00798 return;
00799 }
00800
00801
00802
00803
00804
00805
00806 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
00807 for (q = 0; q < local->hw.queues; q++) {
00808 if (local->queue_stop_reasons[q]) {
00809 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
00810 flags);
00811 mod_timer(&local->dynamic_ps_timer, jiffies +
00812 msecs_to_jiffies(
00813 local->hw.conf.dynamic_ps_timeout));
00814 return;
00815 }
00816 }
00817 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
00818 }
00819
00820 if ((local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) &&
00821 (!(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED))) {
00822 netif_tx_stop_all_queues(sdata->dev);
00823
00824 if (drv_tx_frames_pending(local))
00825 mod_timer(&local->dynamic_ps_timer, jiffies +
00826 msecs_to_jiffies(
00827 local->hw.conf.dynamic_ps_timeout));
00828 else {
00829 ieee80211_send_nullfunc(local, sdata, 1);
00830
00831 drv_flush(local, false);
00832 }
00833 }
00834
00835 if (!((local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) &&
00836 (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) ||
00837 (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
00838 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
00839 local->hw.conf.flags |= IEEE80211_CONF_PS;
00840 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
00841 }
00842
00843 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
00844 netif_tx_wake_all_queues(sdata->dev);
00845 }
00846
00847 void ieee80211_dynamic_ps_timer(unsigned long data)
00848 {
00849 struct ieee80211_local *local = (void *) data;
00850
00851 if (local->quiescing || local->suspended)
00852 return;
00853
00854 ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
00855 }
00856
00857
00858 static void ieee80211_sta_wmm_params(struct ieee80211_local *local,
00859 struct ieee80211_sub_if_data *sdata,
00860 u8 *wmm_param, size_t wmm_param_len)
00861 {
00862 struct ieee80211_tx_queue_params params;
00863 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
00864 size_t left;
00865 int count;
00866 u8 *pos, uapsd_queues = 0;
00867
00868 if (!local->ops->conf_tx)
00869 return;
00870
00871 if (local->hw.queues < 4)
00872 return;
00873
00874 if (!wmm_param)
00875 return;
00876
00877 if (wmm_param_len < 8 || wmm_param[5] != 1)
00878 return;
00879
00880 if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
00881 uapsd_queues = local->uapsd_queues;
00882
00883 count = wmm_param[6] & 0x0f;
00884 if (count == ifmgd->wmm_last_param_set)
00885 return;
00886 ifmgd->wmm_last_param_set = count;
00887
00888 pos = wmm_param + 8;
00889 left = wmm_param_len - 8;
00890
00891 memset(¶ms, 0, sizeof(params));
00892
00893 local->wmm_acm = 0;
00894 for (; left >= 4; left -= 4, pos += 4) {
00895 int aci = (pos[0] >> 5) & 0x03;
00896 int acm = (pos[0] >> 4) & 0x01;
00897 bool uapsd = false;
00898 int queue;
00899
00900 switch (aci) {
00901 case 1:
00902 queue = 3;
00903 if (acm)
00904 local->wmm_acm |= BIT(1) | BIT(2);
00905 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
00906 uapsd = true;
00907 break;
00908 case 2:
00909 queue = 1;
00910 if (acm)
00911 local->wmm_acm |= BIT(4) | BIT(5);
00912 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
00913 uapsd = true;
00914 break;
00915 case 3:
00916 queue = 0;
00917 if (acm)
00918 local->wmm_acm |= BIT(6) | BIT(7);
00919 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
00920 uapsd = true;
00921 break;
00922 case 0:
00923 default:
00924 queue = 2;
00925 if (acm)
00926 local->wmm_acm |= BIT(0) | BIT(3);
00927 if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
00928 uapsd = true;
00929 break;
00930 }
00931
00932 params.aifs = pos[0] & 0x0f;
00933 params.cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
00934 params.cw_min = ecw2cw(pos[1] & 0x0f);
00935 params.txop = get_unaligned_le16(pos + 2);
00936 params.uapsd = uapsd;
00937
00938 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
00939 wiphy_debug(local->hw.wiphy,
00940 "WMM queue=%d aci=%d acm=%d aifs=%d "
00941 "cWmin=%d cWmax=%d txop=%d uapsd=%d\n",
00942 queue, aci, acm,
00943 params.aifs, params.cw_min, params.cw_max,
00944 params.txop, params.uapsd);
00945 #endif
00946 sdata->tx_conf[queue] = params;
00947 if (drv_conf_tx(local, sdata, queue, ¶ms))
00948 wiphy_debug(local->hw.wiphy,
00949 "failed to set TX queue parameters for queue %d\n",
00950 queue);
00951 }
00952
00953
00954 sdata->vif.bss_conf.qos = true;
00955 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
00956 }
00957
00958 static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
00959 u16 capab, bool erp_valid, u8 erp)
00960 {
00961 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
00962 u32 changed = 0;
00963 bool use_protection;
00964 bool use_short_preamble;
00965 bool use_short_slot;
00966
00967 if (erp_valid) {
00968 use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
00969 use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
00970 } else {
00971 use_protection = false;
00972 use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
00973 }
00974
00975 use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
00976 if (sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ)
00977 use_short_slot = true;
00978
00979 if (use_protection != bss_conf->use_cts_prot) {
00980 bss_conf->use_cts_prot = use_protection;
00981 changed |= BSS_CHANGED_ERP_CTS_PROT;
00982 }
00983
00984 if (use_short_preamble != bss_conf->use_short_preamble) {
00985 bss_conf->use_short_preamble = use_short_preamble;
00986 changed |= BSS_CHANGED_ERP_PREAMBLE;
00987 }
00988
00989 if (use_short_slot != bss_conf->use_short_slot) {
00990 bss_conf->use_short_slot = use_short_slot;
00991 changed |= BSS_CHANGED_ERP_SLOT;
00992 }
00993
00994 return changed;
00995 }
00996
00997 static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
00998 struct cfg80211_bss *cbss,
00999 u32 bss_info_changed)
01000 {
01001 struct ieee80211_bss *bss = (void *)cbss->priv;
01002 struct ieee80211_local *local = sdata->local;
01003 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
01004
01005 bss_info_changed |= BSS_CHANGED_ASSOC;
01006
01007 bss_conf->beacon_int = cbss->beacon_interval;
01008 bss_conf->timestamp = cbss->tsf;
01009
01010 bss_info_changed |= BSS_CHANGED_BEACON_INT;
01011 bss_info_changed |= ieee80211_handle_bss_capability(sdata,
01012 cbss->capability, bss->has_erp_value, bss->erp_value);
01013
01014 sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
01015 IEEE80211_BEACON_LOSS_COUNT * bss_conf->beacon_int));
01016
01017 sdata->u.mgd.associated = cbss;
01018 memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
01019
01020 sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
01021
01022
01023 sdata->u.mgd.flags &= ~(IEEE80211_STA_CONNECTION_POLL |
01024 IEEE80211_STA_BEACON_POLL);
01025
01026 ieee80211_led_assoc(local, 1);
01027
01028 if (local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
01029 bss_conf->dtim_period = bss->dtim_period;
01030 else
01031 bss_conf->dtim_period = 0;
01032
01033 bss_conf->assoc = 1;
01034
01035
01036
01037
01038
01039 bss_info_changed |= BSS_CHANGED_BASIC_RATES;
01040
01041
01042 bss_info_changed |= BSS_CHANGED_BSSID;
01043
01044
01045 if ((local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI) &&
01046 bss_conf->cqm_rssi_thold)
01047 bss_info_changed |= BSS_CHANGED_CQM;
01048
01049
01050 if (bss_conf->arp_filter_enabled != sdata->arp_filter_state) {
01051 bss_conf->arp_filter_enabled = sdata->arp_filter_state;
01052 bss_info_changed |= BSS_CHANGED_ARP_FILTER;
01053 }
01054
01055 ieee80211_bss_info_change_notify(sdata, bss_info_changed);
01056
01057 mutex_lock(&local->iflist_mtx);
01058 ieee80211_recalc_ps(local, -1);
01059 ieee80211_recalc_smps(local);
01060 mutex_unlock(&local->iflist_mtx);
01061
01062 netif_tx_start_all_queues(sdata->dev);
01063 netif_carrier_on(sdata->dev);
01064 }
01065
01066 static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
01067 bool remove_sta, bool tx)
01068 {
01069 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
01070 struct ieee80211_local *local = sdata->local;
01071 struct sta_info *sta;
01072 u32 changed = 0, config_changed = 0;
01073 u8 bssid[ETH_ALEN];
01074
01075 ASSERT_MGD_MTX(ifmgd);
01076
01077 if (WARN_ON(!ifmgd->associated))
01078 return;
01079
01080 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
01081
01082 ifmgd->associated = NULL;
01083 memset(ifmgd->bssid, 0, ETH_ALEN);
01084
01085
01086
01087
01088
01089
01090
01091 smp_mb();
01092
01093
01094
01095
01096
01097
01098
01099 netif_tx_stop_all_queues(sdata->dev);
01100 netif_carrier_off(sdata->dev);
01101
01102 mutex_lock(&local->sta_mtx);
01103 sta = sta_info_get(sdata, bssid);
01104 if (sta) {
01105 set_sta_flag(sta, WLAN_STA_BLOCK_BA);
01106 ieee80211_sta_tear_down_BA_sessions(sta, tx);
01107 }
01108 mutex_unlock(&local->sta_mtx);
01109
01110 changed |= ieee80211_reset_erp_info(sdata);
01111
01112 ieee80211_led_assoc(local, 0);
01113 changed |= BSS_CHANGED_ASSOC;
01114 sdata->vif.bss_conf.assoc = false;
01115
01116 ieee80211_set_wmm_default(sdata);
01117
01118
01119 WARN_ON(!ieee80211_set_channel_type(local, sdata, NL80211_CHAN_NO_HT));
01120
01121
01122 sdata->ht_opmode_valid = false;
01123
01124 local->power_constr_level = 0;
01125
01126 del_timer_sync(&local->dynamic_ps_timer);
01127 cancel_work_sync(&local->dynamic_ps_enable_work);
01128
01129 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
01130 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
01131 config_changed |= IEEE80211_CONF_CHANGE_PS;
01132 }
01133 local->ps_sdata = NULL;
01134
01135 ieee80211_hw_config(local, config_changed);
01136
01137
01138 if (sdata->vif.bss_conf.arp_filter_enabled) {
01139 sdata->vif.bss_conf.arp_filter_enabled = false;
01140 changed |= BSS_CHANGED_ARP_FILTER;
01141 }
01142
01143
01144 changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
01145 ieee80211_bss_info_change_notify(sdata, changed);
01146
01147
01148 if (remove_sta)
01149 sta_info_flush(local, sdata);
01150
01151 del_timer_sync(&sdata->u.mgd.conn_mon_timer);
01152 del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
01153 del_timer_sync(&sdata->u.mgd.timer);
01154 del_timer_sync(&sdata->u.mgd.chswitch_timer);
01155 }
01156
01157 void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
01158 struct ieee80211_hdr *hdr)
01159 {
01160
01161
01162
01163
01164
01165
01166
01167
01168 if (is_multicast_ether_addr(hdr->addr1))
01169 return;
01170
01171 ieee80211_sta_reset_conn_monitor(sdata);
01172 }
01173
01174 static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
01175 {
01176 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
01177
01178 if (!(ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
01179 IEEE80211_STA_CONNECTION_POLL)))
01180 return;
01181
01182 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
01183 IEEE80211_STA_BEACON_POLL);
01184 mutex_lock(&sdata->local->iflist_mtx);
01185 ieee80211_recalc_ps(sdata->local, -1);
01186 mutex_unlock(&sdata->local->iflist_mtx);
01187
01188 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
01189 return;
01190
01191
01192
01193
01194
01195
01196 ieee80211_sta_reset_beacon_monitor(sdata);
01197
01198 mod_timer(&ifmgd->conn_mon_timer,
01199 round_jiffies_up(jiffies +
01200 IEEE80211_CONNECTION_IDLE_TIME));
01201 }
01202
01203 void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
01204 struct ieee80211_hdr *hdr, bool ack)
01205 {
01206 if (!ieee80211_is_data(hdr->frame_control))
01207 return;
01208
01209 if (ack)
01210 ieee80211_sta_reset_conn_monitor(sdata);
01211
01212 if (ieee80211_is_nullfunc(hdr->frame_control) &&
01213 sdata->u.mgd.probe_send_count > 0) {
01214 if (ack)
01215 sdata->u.mgd.probe_send_count = 0;
01216 else
01217 sdata->u.mgd.nullfunc_failed = true;
01218 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
01219 }
01220 }
01221
01222 static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
01223 {
01224 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
01225 const u8 *ssid;
01226 u8 *dst = ifmgd->associated->bssid;
01227 u8 unicast_limit = max(1, max_probe_tries - 3);
01228
01229
01230
01231
01232
01233
01234 if (ifmgd->probe_send_count >= unicast_limit)
01235 dst = NULL;
01236
01237
01238
01239
01240
01241
01242
01243
01244 if (sdata->local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
01245 ifmgd->nullfunc_failed = false;
01246 ieee80211_send_nullfunc(sdata->local, sdata, 0);
01247 } else {
01248 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
01249 ieee80211_send_probe_req(sdata, dst, ssid + 2, ssid[1], NULL, 0,
01250 (u32) -1, true, false);
01251 }
01252
01253 ifmgd->probe_send_count++;
01254 ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
01255 run_again(ifmgd, ifmgd->probe_timeout);
01256 }
01257
01258 static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
01259 bool beacon)
01260 {
01261 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
01262 bool already = false;
01263
01264 if (!ieee80211_sdata_running(sdata))
01265 return;
01266
01267 if (sdata->local->scanning)
01268 return;
01269
01270 if (sdata->local->tmp_channel)
01271 return;
01272
01273 mutex_lock(&ifmgd->mtx);
01274
01275 if (!ifmgd->associated)
01276 goto out;
01277
01278 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
01279 if (beacon && net_ratelimit())
01280 printk(KERN_DEBUG "%s: detected beacon loss from AP "
01281 "- sending probe request\n", sdata->name);
01282 #endif
01283
01284
01285
01286
01287
01288
01289
01290
01291
01292
01293
01294
01295 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
01296 IEEE80211_STA_CONNECTION_POLL))
01297 already = true;
01298
01299 if (beacon)
01300 ifmgd->flags |= IEEE80211_STA_BEACON_POLL;
01301 else
01302 ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
01303
01304 if (already)
01305 goto out;
01306
01307 mutex_lock(&sdata->local->iflist_mtx);
01308 ieee80211_recalc_ps(sdata->local, -1);
01309 mutex_unlock(&sdata->local->iflist_mtx);
01310
01311 ifmgd->probe_send_count = 0;
01312 ieee80211_mgd_probe_ap_send(sdata);
01313 out:
01314 mutex_unlock(&ifmgd->mtx);
01315 }
01316
01317 struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
01318 struct ieee80211_vif *vif)
01319 {
01320 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
01321 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
01322 struct sk_buff *skb;
01323 const u8 *ssid;
01324
01325 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
01326 return NULL;
01327
01328 ASSERT_MGD_MTX(ifmgd);
01329
01330 if (!ifmgd->associated)
01331 return NULL;
01332
01333 ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
01334 skb = ieee80211_build_probe_req(sdata, ifmgd->associated->bssid,
01335 (u32) -1, ssid + 2, ssid[1],
01336 NULL, 0, true);
01337
01338 return skb;
01339 }
01340 EXPORT_SYMBOL(ieee80211_ap_probereq_get);
01341
01342 static void __ieee80211_connection_loss(struct ieee80211_sub_if_data *sdata)
01343 {
01344 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
01345 struct ieee80211_local *local = sdata->local;
01346 u8 bssid[ETH_ALEN];
01347
01348 mutex_lock(&ifmgd->mtx);
01349 if (!ifmgd->associated) {
01350 mutex_unlock(&ifmgd->mtx);
01351 return;
01352 }
01353
01354 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
01355
01356 printk(KERN_DEBUG "%s: Connection to AP %pM lost.\n",
01357 sdata->name, bssid);
01358
01359 ieee80211_set_disassoc(sdata, true, true);
01360 mutex_unlock(&ifmgd->mtx);
01361
01362 mutex_lock(&local->mtx);
01363 ieee80211_recalc_idle(local);
01364 mutex_unlock(&local->mtx);
01365
01366
01367
01368
01369 ieee80211_send_deauth_disassoc(sdata, bssid,
01370 IEEE80211_STYPE_DEAUTH,
01371 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
01372 NULL, true);
01373 }
01374
01375 void ieee80211_beacon_connection_loss_work(struct work_struct *work)
01376 {
01377 struct ieee80211_sub_if_data *sdata =
01378 container_of(work, struct ieee80211_sub_if_data,
01379 u.mgd.beacon_connection_loss_work);
01380
01381 if (sdata->local->hw.flags & IEEE80211_HW_CONNECTION_MONITOR)
01382 __ieee80211_connection_loss(sdata);
01383 else
01384 ieee80211_mgd_probe_ap(sdata, true);
01385 }
01386
01387 void ieee80211_beacon_loss(struct ieee80211_vif *vif)
01388 {
01389 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
01390 struct ieee80211_hw *hw = &sdata->local->hw;
01391
01392 trace_api_beacon_loss(sdata);
01393
01394 WARN_ON(hw->flags & IEEE80211_HW_CONNECTION_MONITOR);
01395 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
01396 }
01397 EXPORT_SYMBOL(ieee80211_beacon_loss);
01398
01399 void ieee80211_connection_loss(struct ieee80211_vif *vif)
01400 {
01401 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
01402 struct ieee80211_hw *hw = &sdata->local->hw;
01403
01404 trace_api_connection_loss(sdata);
01405
01406 WARN_ON(!(hw->flags & IEEE80211_HW_CONNECTION_MONITOR));
01407 ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
01408 }
01409 EXPORT_SYMBOL(ieee80211_connection_loss);
01410
01411
01412 static enum rx_mgmt_action __must_check
01413 ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
01414 struct ieee80211_mgmt *mgmt, size_t len)
01415 {
01416 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
01417 const u8 *bssid = NULL;
01418 u16 reason_code;
01419
01420 if (len < 24 + 2)
01421 return RX_MGMT_NONE;
01422
01423 ASSERT_MGD_MTX(ifmgd);
01424
01425 bssid = ifmgd->associated->bssid;
01426
01427 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
01428
01429 printk(KERN_DEBUG "%s: deauthenticated from %pM (Reason: %u)\n",
01430 sdata->name, bssid, reason_code);
01431
01432 ieee80211_set_disassoc(sdata, true, false);
01433 mutex_lock(&sdata->local->mtx);
01434 ieee80211_recalc_idle(sdata->local);
01435 mutex_unlock(&sdata->local->mtx);
01436
01437 return RX_MGMT_CFG80211_DEAUTH;
01438 }
01439
01440
01441 static enum rx_mgmt_action __must_check
01442 ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
01443 struct ieee80211_mgmt *mgmt, size_t len)
01444 {
01445 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
01446 u16 reason_code;
01447
01448 if (len < 24 + 2)
01449 return RX_MGMT_NONE;
01450
01451 ASSERT_MGD_MTX(ifmgd);
01452
01453 if (WARN_ON(!ifmgd->associated))
01454 return RX_MGMT_NONE;
01455
01456 if (WARN_ON(memcmp(ifmgd->associated->bssid, mgmt->sa, ETH_ALEN)))
01457 return RX_MGMT_NONE;
01458
01459 reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
01460
01461 printk(KERN_DEBUG "%s: disassociated from %pM (Reason: %u)\n",
01462 sdata->name, mgmt->sa, reason_code);
01463
01464 ieee80211_set_disassoc(sdata, true, false);
01465 mutex_lock(&sdata->local->mtx);
01466 ieee80211_recalc_idle(sdata->local);
01467 mutex_unlock(&sdata->local->mtx);
01468 return RX_MGMT_CFG80211_DISASSOC;
01469 }
01470
01471
01472 static bool ieee80211_assoc_success(struct ieee80211_work *wk,
01473 struct ieee80211_mgmt *mgmt, size_t len)
01474 {
01475 struct ieee80211_sub_if_data *sdata = wk->sdata;
01476 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
01477 struct ieee80211_local *local = sdata->local;
01478 struct ieee80211_supported_band *sband;
01479 struct sta_info *sta;
01480 struct cfg80211_bss *cbss = wk->assoc.bss;
01481 u8 *pos;
01482 u32 rates, basic_rates;
01483 u16 capab_info, aid;
01484 struct ieee802_11_elems elems;
01485 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
01486 u32 changed = 0;
01487 int i, j, err;
01488 bool have_higher_than_11mbit = false;
01489 u16 ap_ht_cap_flags;
01490 int min_rate = INT_MAX, min_rate_index = -1;
01491
01492
01493
01494 aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
01495 capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
01496
01497 if ((aid & (BIT(15) | BIT(14))) != (BIT(15) | BIT(14)))
01498 printk(KERN_DEBUG
01499 "%s: invalid AID value 0x%x; bits 15:14 not set\n",
01500 sdata->name, aid);
01501 aid &= ~(BIT(15) | BIT(14));
01502
01503 ifmgd->broken_ap = false;
01504
01505 if (aid == 0 || aid > IEEE80211_MAX_AID) {
01506 printk(KERN_DEBUG
01507 "%s: invalid AID value %d (out of range), turn off PS\n",
01508 sdata->name, aid);
01509 aid = 0;
01510 ifmgd->broken_ap = true;
01511 }
01512
01513 pos = mgmt->u.assoc_resp.variable;
01514 ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), &elems);
01515
01516 if (!elems.supp_rates) {
01517 printk(KERN_DEBUG "%s: no SuppRates element in AssocResp\n",
01518 sdata->name);
01519 return false;
01520 }
01521
01522 ifmgd->aid = aid;
01523
01524 mutex_lock(&sdata->local->sta_mtx);
01525
01526
01527
01528
01529 sta = sta_info_get_rx(sdata, cbss->bssid);
01530 if (WARN_ON(!sta)) {
01531 mutex_unlock(&sdata->local->sta_mtx);
01532 return false;
01533 }
01534
01535 set_sta_flag(sta, WLAN_STA_AUTH);
01536 set_sta_flag(sta, WLAN_STA_ASSOC);
01537 set_sta_flag(sta, WLAN_STA_ASSOC_AP);
01538 if (!(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
01539 set_sta_flag(sta, WLAN_STA_AUTHORIZED);
01540
01541 rates = 0;
01542 basic_rates = 0;
01543 sband = local->hw.wiphy->bands[wk->chan->band];
01544
01545 for (i = 0; i < elems.supp_rates_len; i++) {
01546 int rate = (elems.supp_rates[i] & 0x7f) * 5;
01547 bool is_basic = !!(elems.supp_rates[i] & 0x80);
01548
01549 if (rate > 110)
01550 have_higher_than_11mbit = true;
01551
01552 for (j = 0; j < sband->n_bitrates; j++) {
01553 if (sband->bitrates[j].bitrate == rate) {
01554 rates |= BIT(j);
01555 if (is_basic)
01556 basic_rates |= BIT(j);
01557 if (rate < min_rate) {
01558 min_rate = rate;
01559 min_rate_index = j;
01560 }
01561 break;
01562 }
01563 }
01564 }
01565
01566 for (i = 0; i < elems.ext_supp_rates_len; i++) {
01567 int rate = (elems.ext_supp_rates[i] & 0x7f) * 5;
01568 bool is_basic = !!(elems.ext_supp_rates[i] & 0x80);
01569
01570 if (rate > 110)
01571 have_higher_than_11mbit = true;
01572
01573 for (j = 0; j < sband->n_bitrates; j++) {
01574 if (sband->bitrates[j].bitrate == rate) {
01575 rates |= BIT(j);
01576 if (is_basic)
01577 basic_rates |= BIT(j);
01578 if (rate < min_rate) {
01579 min_rate = rate;
01580 min_rate_index = j;
01581 }
01582 break;
01583 }
01584 }
01585 }
01586
01587
01588
01589
01590
01591 if (unlikely(!basic_rates) && min_rate_index >= 0) {
01592 printk(KERN_DEBUG "%s: No basic rates in AssocResp. "
01593 "Using min supported rate instead.\n", sdata->name);
01594 basic_rates = BIT(min_rate_index);
01595 }
01596
01597 sta->sta.supp_rates[wk->chan->band] = rates;
01598 sdata->vif.bss_conf.basic_rates = basic_rates;
01599
01600
01601 if (wk->chan->band == IEEE80211_BAND_2GHZ &&
01602 have_higher_than_11mbit)
01603 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
01604 else
01605 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
01606
01607 if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
01608 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
01609 elems.ht_cap_elem, &sta->sta.ht_cap);
01610
01611 ap_ht_cap_flags = sta->sta.ht_cap.cap;
01612
01613 rate_control_rate_init(sta);
01614
01615 if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED)
01616 set_sta_flag(sta, WLAN_STA_MFP);
01617
01618 if (elems.wmm_param)
01619 set_sta_flag(sta, WLAN_STA_WME);
01620
01621
01622 err = sta_info_reinsert(sta);
01623 sta = NULL;
01624 if (err) {
01625 printk(KERN_DEBUG "%s: failed to insert STA entry for"
01626 " the AP (error %d)\n", sdata->name, err);
01627 return false;
01628 }
01629
01630
01631
01632
01633
01634
01635
01636 ifmgd->wmm_last_param_set = -1;
01637
01638 if (elems.wmm_param)
01639 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
01640 elems.wmm_param_len);
01641 else
01642 ieee80211_set_wmm_default(sdata);
01643
01644 local->oper_channel = wk->chan;
01645
01646 if (elems.ht_info_elem && elems.wmm_param &&
01647 (sdata->local->hw.queues >= 4) &&
01648 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N))
01649 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
01650 cbss->bssid, ap_ht_cap_flags,
01651 false);
01652
01653
01654
01655 bss_conf->aid = aid;
01656 bss_conf->assoc_capability = capab_info;
01657 ieee80211_set_associated(sdata, cbss, changed);
01658
01659
01660
01661
01662
01663 if (ifmgd->use_4addr)
01664 ieee80211_send_4addr_nullfunc(local, sdata);
01665
01666
01667
01668
01669
01670 ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
01671 ieee80211_sta_reset_beacon_monitor(sdata);
01672
01673 return true;
01674 }
01675
01676
01677 static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
01678 struct ieee80211_mgmt *mgmt,
01679 size_t len,
01680 struct ieee80211_rx_status *rx_status,
01681 struct ieee802_11_elems *elems,
01682 bool beacon)
01683 {
01684 struct ieee80211_local *local = sdata->local;
01685 int freq;
01686 struct ieee80211_bss *bss;
01687 struct ieee80211_channel *channel;
01688 bool need_ps = false;
01689
01690 if (sdata->u.mgd.associated) {
01691 bss = (void *)sdata->u.mgd.associated->priv;
01692
01693 need_ps = !bss->dtim_period;
01694 }
01695
01696 if (elems->ds_params && elems->ds_params_len == 1)
01697 freq = ieee80211_channel_to_frequency(elems->ds_params[0],
01698 rx_status->band);
01699 else
01700 freq = rx_status->freq;
01701
01702 channel = ieee80211_get_channel(local->hw.wiphy, freq);
01703
01704 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
01705 return;
01706
01707 bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
01708 channel, beacon);
01709 if (bss)
01710 ieee80211_rx_bss_put(local, bss);
01711
01712 if (!sdata->u.mgd.associated)
01713 return;
01714
01715 if (need_ps) {
01716 mutex_lock(&local->iflist_mtx);
01717 ieee80211_recalc_ps(local, -1);
01718 mutex_unlock(&local->iflist_mtx);
01719 }
01720
01721 if (elems->ch_switch_elem && (elems->ch_switch_elem_len == 3) &&
01722 (memcmp(mgmt->bssid, sdata->u.mgd.associated->bssid,
01723 ETH_ALEN) == 0)) {
01724 struct ieee80211_channel_sw_ie *sw_elem =
01725 (struct ieee80211_channel_sw_ie *)elems->ch_switch_elem;
01726 ieee80211_sta_process_chanswitch(sdata, sw_elem,
01727 bss, rx_status->mactime);
01728 }
01729 }
01730
01731
01732 static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
01733 struct sk_buff *skb)
01734 {
01735 struct ieee80211_mgmt *mgmt = (void *)skb->data;
01736 struct ieee80211_if_managed *ifmgd;
01737 struct ieee80211_rx_status *rx_status = (void *) skb->cb;
01738 size_t baselen, len = skb->len;
01739 struct ieee802_11_elems elems;
01740
01741 ifmgd = &sdata->u.mgd;
01742
01743 ASSERT_MGD_MTX(ifmgd);
01744
01745 if (memcmp(mgmt->da, sdata->vif.addr, ETH_ALEN))
01746 return;
01747
01748 baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
01749 if (baselen > len)
01750 return;
01751
01752 ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
01753 &elems);
01754
01755 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems, false);
01756
01757 if (ifmgd->associated &&
01758 memcmp(mgmt->bssid, ifmgd->associated->bssid, ETH_ALEN) == 0)
01759 ieee80211_reset_ap_probe(sdata);
01760 }
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773
01774
01775 static const u64 care_about_ies =
01776 (1ULL << WLAN_EID_COUNTRY) |
01777 (1ULL << WLAN_EID_ERP_INFO) |
01778 (1ULL << WLAN_EID_CHANNEL_SWITCH) |
01779 (1ULL << WLAN_EID_PWR_CONSTRAINT) |
01780 (1ULL << WLAN_EID_HT_CAPABILITY) |
01781 (1ULL << WLAN_EID_HT_INFORMATION);
01782
01783 static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
01784 struct ieee80211_mgmt *mgmt,
01785 size_t len,
01786 struct ieee80211_rx_status *rx_status)
01787 {
01788 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
01789 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
01790 size_t baselen;
01791 struct ieee802_11_elems elems;
01792 struct ieee80211_local *local = sdata->local;
01793 u32 changed = 0;
01794 bool erp_valid, directed_tim = false;
01795 u8 erp_value = 0;
01796 u32 ncrc;
01797 u8 *bssid;
01798
01799 ASSERT_MGD_MTX(ifmgd);
01800
01801
01802 baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
01803 if (baselen > len)
01804 return;
01805
01806 if (rx_status->freq != local->hw.conf.channel->center_freq)
01807 return;
01808
01809
01810
01811
01812
01813 if (!ifmgd->associated)
01814 return;
01815
01816 bssid = ifmgd->associated->bssid;
01817
01818
01819
01820
01821
01822 if (memcmp(bssid, mgmt->bssid, ETH_ALEN) != 0)
01823 return;
01824
01825
01826 ifmgd->last_beacon_signal = rx_status->signal;
01827 if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
01828 ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
01829 ifmgd->ave_beacon_signal = rx_status->signal * 16;
01830 ifmgd->last_cqm_event_signal = 0;
01831 ifmgd->count_beacon_signal = 1;
01832 ifmgd->last_ave_beacon_signal = 0;
01833 } else {
01834 ifmgd->ave_beacon_signal =
01835 (IEEE80211_SIGNAL_AVE_WEIGHT * rx_status->signal * 16 +
01836 (16 - IEEE80211_SIGNAL_AVE_WEIGHT) *
01837 ifmgd->ave_beacon_signal) / 16;
01838 ifmgd->count_beacon_signal++;
01839 }
01840
01841 if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
01842 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
01843 int sig = ifmgd->ave_beacon_signal;
01844 int last_sig = ifmgd->last_ave_beacon_signal;
01845
01846
01847
01848
01849
01850 if (sig > ifmgd->rssi_max_thold &&
01851 (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
01852 ifmgd->last_ave_beacon_signal = sig;
01853 drv_rssi_callback(local, RSSI_EVENT_HIGH);
01854 } else if (sig < ifmgd->rssi_min_thold &&
01855 (last_sig >= ifmgd->rssi_max_thold ||
01856 last_sig == 0)) {
01857 ifmgd->last_ave_beacon_signal = sig;
01858 drv_rssi_callback(local, RSSI_EVENT_LOW);
01859 }
01860 }
01861
01862 if (bss_conf->cqm_rssi_thold &&
01863 ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
01864 !(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
01865 int sig = ifmgd->ave_beacon_signal / 16;
01866 int last_event = ifmgd->last_cqm_event_signal;
01867 int thold = bss_conf->cqm_rssi_thold;
01868 int hyst = bss_conf->cqm_rssi_hyst;
01869 if (sig < thold &&
01870 (last_event == 0 || sig < last_event - hyst)) {
01871 ifmgd->last_cqm_event_signal = sig;
01872 ieee80211_cqm_rssi_notify(
01873 &sdata->vif,
01874 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
01875 GFP_KERNEL);
01876 } else if (sig > thold &&
01877 (last_event == 0 || sig > last_event + hyst)) {
01878 ifmgd->last_cqm_event_signal = sig;
01879 ieee80211_cqm_rssi_notify(
01880 &sdata->vif,
01881 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
01882 GFP_KERNEL);
01883 }
01884 }
01885
01886 if (ifmgd->flags & IEEE80211_STA_BEACON_POLL) {
01887 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
01888 if (net_ratelimit()) {
01889 printk(KERN_DEBUG "%s: cancelling probereq poll due "
01890 "to a received beacon\n", sdata->name);
01891 }
01892 #endif
01893 ifmgd->flags &= ~IEEE80211_STA_BEACON_POLL;
01894 mutex_lock(&local->iflist_mtx);
01895 ieee80211_recalc_ps(local, -1);
01896 mutex_unlock(&local->iflist_mtx);
01897 }
01898
01899
01900
01901
01902
01903 ieee80211_sta_reset_beacon_monitor(sdata);
01904
01905 ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
01906 ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
01907 len - baselen, &elems,
01908 care_about_ies, ncrc);
01909
01910 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)
01911 directed_tim = ieee80211_check_tim(elems.tim, elems.tim_len,
01912 ifmgd->aid);
01913
01914 if (ncrc != ifmgd->beacon_crc || !ifmgd->beacon_crc_valid) {
01915 ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems,
01916 true);
01917
01918 ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
01919 elems.wmm_param_len);
01920 }
01921
01922 if (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK) {
01923 if (directed_tim) {
01924 if (local->hw.conf.dynamic_ps_timeout > 0) {
01925 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
01926 ieee80211_hw_config(local,
01927 IEEE80211_CONF_CHANGE_PS);
01928 ieee80211_send_nullfunc(local, sdata, 0);
01929 } else {
01930 local->pspolling = true;
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940 ieee80211_send_pspoll(local, sdata);
01941 }
01942 }
01943 }
01944
01945 if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
01946 return;
01947 ifmgd->beacon_crc = ncrc;
01948 ifmgd->beacon_crc_valid = true;
01949
01950 if (elems.erp_info && elems.erp_info_len >= 1) {
01951 erp_valid = true;
01952 erp_value = elems.erp_info[0];
01953 } else {
01954 erp_valid = false;
01955 }
01956 changed |= ieee80211_handle_bss_capability(sdata,
01957 le16_to_cpu(mgmt->u.beacon.capab_info),
01958 erp_valid, erp_value);
01959
01960
01961 if (elems.ht_cap_elem && elems.ht_info_elem && elems.wmm_param &&
01962 !(ifmgd->flags & IEEE80211_STA_DISABLE_11N)) {
01963 struct sta_info *sta;
01964 struct ieee80211_supported_band *sband;
01965 u16 ap_ht_cap_flags;
01966
01967 rcu_read_lock();
01968
01969 sta = sta_info_get(sdata, bssid);
01970 if (WARN_ON(!sta)) {
01971 rcu_read_unlock();
01972 return;
01973 }
01974
01975 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
01976
01977 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
01978 elems.ht_cap_elem, &sta->sta.ht_cap);
01979
01980 ap_ht_cap_flags = sta->sta.ht_cap.cap;
01981
01982 rcu_read_unlock();
01983
01984 changed |= ieee80211_enable_ht(sdata, elems.ht_info_elem,
01985 bssid, ap_ht_cap_flags, true);
01986 }
01987
01988
01989 if (elems.country_elem) {
01990
01991 if (elems.pwr_constr_elem)
01992 ieee80211_handle_pwr_constr(sdata,
01993 le16_to_cpu(mgmt->u.probe_resp.capab_info),
01994 elems.pwr_constr_elem,
01995 elems.pwr_constr_elem_len);
01996 }
01997
01998 ieee80211_bss_info_change_notify(sdata, changed);
01999 }
02000
02001 void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
02002 struct sk_buff *skb)
02003 {
02004 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
02005 struct ieee80211_rx_status *rx_status;
02006 struct ieee80211_mgmt *mgmt;
02007 enum rx_mgmt_action rma = RX_MGMT_NONE;
02008 u16 fc;
02009
02010 rx_status = (struct ieee80211_rx_status *) skb->cb;
02011 mgmt = (struct ieee80211_mgmt *) skb->data;
02012 fc = le16_to_cpu(mgmt->frame_control);
02013
02014 mutex_lock(&ifmgd->mtx);
02015
02016 if (ifmgd->associated &&
02017 memcmp(ifmgd->associated->bssid, mgmt->bssid, ETH_ALEN) == 0) {
02018 switch (fc & IEEE80211_FCTL_STYPE) {
02019 case IEEE80211_STYPE_BEACON:
02020 ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len,
02021 rx_status);
02022 break;
02023 case IEEE80211_STYPE_PROBE_RESP:
02024 ieee80211_rx_mgmt_probe_resp(sdata, skb);
02025 break;
02026 case IEEE80211_STYPE_DEAUTH:
02027 rma = ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
02028 break;
02029 case IEEE80211_STYPE_DISASSOC:
02030 rma = ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
02031 break;
02032 case IEEE80211_STYPE_ACTION:
02033 switch (mgmt->u.action.category) {
02034 case WLAN_CATEGORY_SPECTRUM_MGMT:
02035 ieee80211_sta_process_chanswitch(sdata,
02036 &mgmt->u.action.u.chan_switch.sw_elem,
02037 (void *)ifmgd->associated->priv,
02038 rx_status->mactime);
02039 break;
02040 }
02041 }
02042 mutex_unlock(&ifmgd->mtx);
02043
02044 switch (rma) {
02045 case RX_MGMT_NONE:
02046
02047 break;
02048 case RX_MGMT_CFG80211_DEAUTH:
02049 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
02050 break;
02051 case RX_MGMT_CFG80211_DISASSOC:
02052 cfg80211_send_disassoc(sdata->dev, (u8 *)mgmt, skb->len);
02053 break;
02054 default:
02055 WARN(1, "unexpected: %d", rma);
02056 }
02057 return;
02058 }
02059
02060 mutex_unlock(&ifmgd->mtx);
02061
02062 if (skb->len >= 24 + 2 &&
02063 (fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_DEAUTH) {
02064 struct ieee80211_local *local = sdata->local;
02065 struct ieee80211_work *wk;
02066
02067 mutex_lock(&local->mtx);
02068 list_for_each_entry(wk, &local->work_list, list) {
02069 if (wk->sdata != sdata)
02070 continue;
02071
02072 if (wk->type != IEEE80211_WORK_ASSOC &&
02073 wk->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
02074 continue;
02075
02076 if (memcmp(mgmt->bssid, wk->filter_ta, ETH_ALEN))
02077 continue;
02078 if (memcmp(mgmt->sa, wk->filter_ta, ETH_ALEN))
02079 continue;
02080
02081
02082
02083
02084
02085
02086
02087
02088
02089
02090 printk(KERN_DEBUG
02091 "%s: deauthenticated from %pM (Reason: %u)\n",
02092 sdata->name, mgmt->bssid,
02093 le16_to_cpu(mgmt->u.deauth.reason_code));
02094
02095 list_del_rcu(&wk->list);
02096 free_work(wk);
02097 break;
02098 }
02099 mutex_unlock(&local->mtx);
02100
02101 cfg80211_send_deauth(sdata->dev, (u8 *)mgmt, skb->len);
02102 }
02103 }
02104
02105 static void ieee80211_sta_timer(unsigned long data)
02106 {
02107 struct ieee80211_sub_if_data *sdata =
02108 (struct ieee80211_sub_if_data *) data;
02109 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
02110 struct ieee80211_local *local = sdata->local;
02111
02112 if (local->quiescing) {
02113 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
02114 return;
02115 }
02116
02117 ieee80211_queue_work(&local->hw, &sdata->work);
02118 }
02119
02120 static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
02121 u8 *bssid, u8 reason)
02122 {
02123 struct ieee80211_local *local = sdata->local;
02124 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
02125
02126 ifmgd->flags &= ~(IEEE80211_STA_CONNECTION_POLL |
02127 IEEE80211_STA_BEACON_POLL);
02128
02129 ieee80211_set_disassoc(sdata, true, true);
02130 mutex_unlock(&ifmgd->mtx);
02131 mutex_lock(&local->mtx);
02132 ieee80211_recalc_idle(local);
02133 mutex_unlock(&local->mtx);
02134
02135
02136
02137
02138 ieee80211_send_deauth_disassoc(sdata, bssid,
02139 IEEE80211_STYPE_DEAUTH, reason,
02140 NULL, true);
02141 mutex_lock(&ifmgd->mtx);
02142 }
02143
02144 void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
02145 {
02146 struct ieee80211_local *local = sdata->local;
02147 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
02148
02149
02150 mutex_lock(&ifmgd->mtx);
02151
02152 if (ifmgd->flags & (IEEE80211_STA_BEACON_POLL |
02153 IEEE80211_STA_CONNECTION_POLL) &&
02154 ifmgd->associated) {
02155 u8 bssid[ETH_ALEN];
02156 int max_tries;
02157
02158 memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
02159
02160 if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS)
02161 max_tries = max_nullfunc_tries;
02162 else
02163 max_tries = max_probe_tries;
02164
02165
02166 if (!ifmgd->probe_send_count)
02167 ieee80211_reset_ap_probe(sdata);
02168 else if (ifmgd->nullfunc_failed) {
02169 if (ifmgd->probe_send_count < max_tries) {
02170 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
02171 wiphy_debug(local->hw.wiphy,
02172 "%s: No ack for nullfunc frame to"
02173 " AP %pM, try %d/%i\n",
02174 sdata->name, bssid,
02175 ifmgd->probe_send_count, max_tries);
02176 #endif
02177 ieee80211_mgd_probe_ap_send(sdata);
02178 } else {
02179 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
02180 wiphy_debug(local->hw.wiphy,
02181 "%s: No ack for nullfunc frame to"
02182 " AP %pM, disconnecting.\n",
02183 sdata->name, bssid);
02184 #endif
02185 ieee80211_sta_connection_lost(sdata, bssid,
02186 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
02187 }
02188 } else if (time_is_after_jiffies(ifmgd->probe_timeout))
02189 run_again(ifmgd, ifmgd->probe_timeout);
02190 else if (local->hw.flags & IEEE80211_HW_REPORTS_TX_ACK_STATUS) {
02191 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
02192 wiphy_debug(local->hw.wiphy,
02193 "%s: Failed to send nullfunc to AP %pM"
02194 " after %dms, disconnecting.\n",
02195 sdata->name,
02196 bssid, probe_wait_ms);
02197 #endif
02198 ieee80211_sta_connection_lost(sdata, bssid,
02199 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
02200 } else if (ifmgd->probe_send_count < max_tries) {
02201 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
02202 wiphy_debug(local->hw.wiphy,
02203 "%s: No probe response from AP %pM"
02204 " after %dms, try %d/%i\n",
02205 sdata->name,
02206 bssid, probe_wait_ms,
02207 ifmgd->probe_send_count, max_tries);
02208 #endif
02209 ieee80211_mgd_probe_ap_send(sdata);
02210 } else {
02211
02212
02213
02214
02215 wiphy_debug(local->hw.wiphy,
02216 "%s: No probe response from AP %pM"
02217 " after %dms, disconnecting.\n",
02218 sdata->name,
02219 bssid, probe_wait_ms);
02220
02221 ieee80211_sta_connection_lost(sdata, bssid,
02222 WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
02223 }
02224 }
02225
02226 mutex_unlock(&ifmgd->mtx);
02227 }
02228
02229 static void ieee80211_sta_bcn_mon_timer(unsigned long data)
02230 {
02231 struct ieee80211_sub_if_data *sdata =
02232 (struct ieee80211_sub_if_data *) data;
02233 struct ieee80211_local *local = sdata->local;
02234
02235 if (local->quiescing)
02236 return;
02237
02238 ieee80211_queue_work(&sdata->local->hw,
02239 &sdata->u.mgd.beacon_connection_loss_work);
02240 }
02241
02242 static void ieee80211_sta_conn_mon_timer(unsigned long data)
02243 {
02244 struct ieee80211_sub_if_data *sdata =
02245 (struct ieee80211_sub_if_data *) data;
02246 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
02247 struct ieee80211_local *local = sdata->local;
02248
02249 if (local->quiescing)
02250 return;
02251
02252 ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
02253 }
02254
02255 static void ieee80211_sta_monitor_work(struct work_struct *work)
02256 {
02257 struct ieee80211_sub_if_data *sdata =
02258 container_of(work, struct ieee80211_sub_if_data,
02259 u.mgd.monitor_work);
02260
02261 ieee80211_mgd_probe_ap(sdata, false);
02262 }
02263
02264 static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
02265 {
02266 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
02267 sdata->u.mgd.flags &= ~(IEEE80211_STA_BEACON_POLL |
02268 IEEE80211_STA_CONNECTION_POLL);
02269
02270
02271 ieee80211_queue_work(&sdata->local->hw,
02272 &sdata->u.mgd.monitor_work);
02273
02274 ieee80211_queue_work(&sdata->local->hw, &sdata->work);
02275 }
02276 }
02277
02278 #ifdef CONFIG_PM
02279 void ieee80211_sta_quiesce(struct ieee80211_sub_if_data *sdata)
02280 {
02281 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
02282
02283
02284
02285
02286
02287
02288
02289 cancel_work_sync(&ifmgd->request_smps_work);
02290
02291 cancel_work_sync(&ifmgd->monitor_work);
02292 cancel_work_sync(&ifmgd->beacon_connection_loss_work);
02293 if (del_timer_sync(&ifmgd->timer))
02294 set_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running);
02295
02296 cancel_work_sync(&ifmgd->chswitch_work);
02297 if (del_timer_sync(&ifmgd->chswitch_timer))
02298 set_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running);
02299
02300
02301 del_timer_sync(&ifmgd->conn_mon_timer);
02302 del_timer_sync(&ifmgd->bcn_mon_timer);
02303 }
02304
02305 void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
02306 {
02307 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
02308
02309 if (!ifmgd->associated)
02310 return;
02311
02312 if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
02313 sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
02314 mutex_lock(&ifmgd->mtx);
02315 if (ifmgd->associated) {
02316 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
02317 wiphy_debug(sdata->local->hw.wiphy,
02318 "%s: driver requested disconnect after resume.\n",
02319 sdata->name);
02320 #endif
02321 ieee80211_sta_connection_lost(sdata,
02322 ifmgd->associated->bssid,
02323 WLAN_REASON_UNSPECIFIED);
02324 mutex_unlock(&ifmgd->mtx);
02325 return;
02326 }
02327 mutex_unlock(&ifmgd->mtx);
02328 }
02329
02330 if (test_and_clear_bit(TMR_RUNNING_TIMER, &ifmgd->timers_running))
02331 add_timer(&ifmgd->timer);
02332 if (test_and_clear_bit(TMR_RUNNING_CHANSW, &ifmgd->timers_running))
02333 add_timer(&ifmgd->chswitch_timer);
02334 ieee80211_sta_reset_beacon_monitor(sdata);
02335 ieee80211_restart_sta_timer(sdata);
02336 ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.monitor_work);
02337 }
02338 #endif
02339
02340
02341 void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
02342 {
02343 struct ieee80211_if_managed *ifmgd;
02344
02345 ifmgd = &sdata->u.mgd;
02346 INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
02347 INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
02348 INIT_WORK(&ifmgd->beacon_connection_loss_work,
02349 ieee80211_beacon_connection_loss_work);
02350 INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_work);
02351 setup_timer(&ifmgd->timer, ieee80211_sta_timer,
02352 (unsigned long) sdata);
02353 setup_timer(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer,
02354 (unsigned long) sdata);
02355 setup_timer(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer,
02356 (unsigned long) sdata);
02357 setup_timer(&ifmgd->chswitch_timer, ieee80211_chswitch_timer,
02358 (unsigned long) sdata);
02359
02360 ifmgd->flags = 0;
02361
02362 mutex_init(&ifmgd->mtx);
02363
02364 if (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS)
02365 ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
02366 else
02367 ifmgd->req_smps = IEEE80211_SMPS_OFF;
02368 }
02369
02370
02371 void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
02372 {
02373 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
02374
02375
02376 rcu_read_lock();
02377 list_for_each_entry_rcu(sdata, &local->interfaces, list)
02378 ieee80211_restart_sta_timer(sdata);
02379 rcu_read_unlock();
02380 }
02381
02382 int ieee80211_max_network_latency(struct notifier_block *nb,
02383 unsigned long data, void *dummy)
02384 {
02385 s32 latency_usec = (s32) data;
02386 struct ieee80211_local *local =
02387 container_of(nb, struct ieee80211_local,
02388 network_latency_notifier);
02389
02390 mutex_lock(&local->iflist_mtx);
02391 ieee80211_recalc_ps(local, latency_usec);
02392 mutex_unlock(&local->iflist_mtx);
02393
02394 return 0;
02395 }
02396
02397
02398 static enum work_done_result
02399 ieee80211_probe_auth_done(struct ieee80211_work *wk,
02400 struct sk_buff *skb)
02401 {
02402 struct ieee80211_local *local = wk->sdata->local;
02403
02404 if (!skb) {
02405 cfg80211_send_auth_timeout(wk->sdata->dev, wk->filter_ta);
02406 goto destroy;
02407 }
02408
02409 if (wk->type == IEEE80211_WORK_AUTH) {
02410 cfg80211_send_rx_auth(wk->sdata->dev, skb->data, skb->len);
02411 goto destroy;
02412 }
02413
02414 mutex_lock(&wk->sdata->u.mgd.mtx);
02415 ieee80211_rx_mgmt_probe_resp(wk->sdata, skb);
02416 mutex_unlock(&wk->sdata->u.mgd.mtx);
02417
02418 wk->type = IEEE80211_WORK_AUTH;
02419 wk->probe_auth.tries = 0;
02420 return WORK_DONE_REQUEUE;
02421 destroy:
02422 if (wk->probe_auth.synced)
02423 drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
02424 IEEE80211_TX_SYNC_AUTH);
02425
02426 return WORK_DONE_DESTROY;
02427 }
02428
02429 int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
02430 struct cfg80211_auth_request *req)
02431 {
02432 const u8 *ssid;
02433 struct ieee80211_work *wk;
02434 u16 auth_alg;
02435
02436 if (req->local_state_change)
02437 return 0;
02438
02439 switch (req->auth_type) {
02440 case NL80211_AUTHTYPE_OPEN_SYSTEM:
02441 auth_alg = WLAN_AUTH_OPEN;
02442 break;
02443 case NL80211_AUTHTYPE_SHARED_KEY:
02444 if (IS_ERR(sdata->local->wep_tx_tfm))
02445 return -EOPNOTSUPP;
02446 auth_alg = WLAN_AUTH_SHARED_KEY;
02447 break;
02448 case NL80211_AUTHTYPE_FT:
02449 auth_alg = WLAN_AUTH_FT;
02450 break;
02451 case NL80211_AUTHTYPE_NETWORK_EAP:
02452 auth_alg = WLAN_AUTH_LEAP;
02453 break;
02454 default:
02455 return -EOPNOTSUPP;
02456 }
02457
02458 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
02459 if (!wk)
02460 return -ENOMEM;
02461
02462 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
02463
02464 if (req->ie && req->ie_len) {
02465 memcpy(wk->ie, req->ie, req->ie_len);
02466 wk->ie_len = req->ie_len;
02467 }
02468
02469 if (req->key && req->key_len) {
02470 wk->probe_auth.key_len = req->key_len;
02471 wk->probe_auth.key_idx = req->key_idx;
02472 memcpy(wk->probe_auth.key, req->key, req->key_len);
02473 }
02474
02475 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
02476 memcpy(wk->probe_auth.ssid, ssid + 2, ssid[1]);
02477 wk->probe_auth.ssid_len = ssid[1];
02478
02479 wk->probe_auth.algorithm = auth_alg;
02480 wk->probe_auth.privacy = req->bss->capability & WLAN_CAPABILITY_PRIVACY;
02481
02482
02483 if (req->bss->proberesp_ies)
02484 wk->type = IEEE80211_WORK_AUTH;
02485 else
02486 wk->type = IEEE80211_WORK_DIRECT_PROBE;
02487 wk->chan = req->bss->channel;
02488 wk->chan_type = NL80211_CHAN_NO_HT;
02489 wk->sdata = sdata;
02490 wk->done = ieee80211_probe_auth_done;
02491
02492 ieee80211_add_work(wk);
02493 return 0;
02494 }
02495
02496
02497 static int ieee80211_pre_assoc(struct ieee80211_sub_if_data *sdata,
02498 u8 *bssid) {
02499 struct sta_info *sta;
02500 int err;
02501
02502 sta = sta_info_alloc(sdata, bssid, GFP_KERNEL);
02503 if (!sta)
02504 return -ENOMEM;
02505
02506 sta->dummy = true;
02507
02508 err = sta_info_insert(sta);
02509 sta = NULL;
02510 if (err) {
02511 printk(KERN_DEBUG "%s: failed to insert Dummy STA entry for"
02512 " the AP (error %d)\n", sdata->name, err);
02513 return err;
02514 }
02515
02516 return 0;
02517 }
02518
02519 static enum work_done_result ieee80211_assoc_done(struct ieee80211_work *wk,
02520 struct sk_buff *skb)
02521 {
02522 struct ieee80211_local *local = wk->sdata->local;
02523 struct ieee80211_mgmt *mgmt;
02524 struct ieee80211_rx_status *rx_status;
02525 struct ieee802_11_elems elems;
02526 struct cfg80211_bss *cbss = wk->assoc.bss;
02527 u16 status;
02528
02529 if (!skb) {
02530 sta_info_destroy_addr(wk->sdata, cbss->bssid);
02531 cfg80211_send_assoc_timeout(wk->sdata->dev, wk->filter_ta);
02532 goto destroy;
02533 }
02534
02535 if (wk->type == IEEE80211_WORK_ASSOC_BEACON_WAIT) {
02536 mutex_lock(&wk->sdata->u.mgd.mtx);
02537 rx_status = (void *) skb->cb;
02538 ieee802_11_parse_elems(skb->data + 24 + 12, skb->len - 24 - 12, &elems);
02539 ieee80211_rx_bss_info(wk->sdata, (void *)skb->data, skb->len, rx_status,
02540 &elems, true);
02541 mutex_unlock(&wk->sdata->u.mgd.mtx);
02542
02543 wk->type = IEEE80211_WORK_ASSOC;
02544
02545 return WORK_DONE_REQUEUE;
02546 }
02547
02548 mgmt = (void *)skb->data;
02549 status = le16_to_cpu(mgmt->u.assoc_resp.status_code);
02550
02551 if (status == WLAN_STATUS_SUCCESS) {
02552 if (wk->assoc.synced)
02553 drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
02554 IEEE80211_TX_SYNC_ASSOC);
02555
02556 mutex_lock(&wk->sdata->u.mgd.mtx);
02557 if (!ieee80211_assoc_success(wk, mgmt, skb->len)) {
02558 mutex_unlock(&wk->sdata->u.mgd.mtx);
02559
02560 sta_info_destroy_addr(wk->sdata, cbss->bssid);
02561 cfg80211_send_assoc_timeout(wk->sdata->dev,
02562 wk->filter_ta);
02563 return WORK_DONE_DESTROY;
02564 }
02565
02566 mutex_unlock(&wk->sdata->u.mgd.mtx);
02567 } else {
02568
02569 sta_info_destroy_addr(wk->sdata, cbss->bssid);
02570 }
02571
02572 cfg80211_send_rx_assoc(wk->sdata->dev, skb->data, skb->len);
02573 destroy:
02574 if (wk->assoc.synced)
02575 drv_finish_tx_sync(local, wk->sdata, wk->filter_ta,
02576 IEEE80211_TX_SYNC_ASSOC);
02577
02578 return WORK_DONE_DESTROY;
02579 }
02580
02581 int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
02582 struct cfg80211_assoc_request *req)
02583 {
02584 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
02585 struct ieee80211_bss *bss = (void *)req->bss->priv;
02586 struct ieee80211_work *wk;
02587 const u8 *ssid;
02588 int i, err;
02589
02590 mutex_lock(&ifmgd->mtx);
02591 if (ifmgd->associated) {
02592 if (!req->prev_bssid ||
02593 memcmp(req->prev_bssid, ifmgd->associated->bssid,
02594 ETH_ALEN)) {
02595
02596
02597
02598
02599
02600 mutex_unlock(&ifmgd->mtx);
02601 return -EALREADY;
02602 }
02603
02604
02605 ieee80211_set_disassoc(sdata, true, false);
02606 }
02607 mutex_unlock(&ifmgd->mtx);
02608
02609 wk = kzalloc(sizeof(*wk) + req->ie_len, GFP_KERNEL);
02610 if (!wk)
02611 return -ENOMEM;
02612
02613
02614
02615
02616
02617 err = ieee80211_pre_assoc(sdata, req->bss->bssid);
02618 if (err) {
02619 kfree(wk);
02620 return err;
02621 }
02622
02623 ifmgd->flags &= ~IEEE80211_STA_DISABLE_11N;
02624 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
02625
02626 ifmgd->beacon_crc_valid = false;
02627
02628 for (i = 0; i < req->crypto.n_ciphers_pairwise; i++)
02629 if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
02630 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
02631 req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104)
02632 ifmgd->flags |= IEEE80211_STA_DISABLE_11N;
02633
02634
02635 if (req->ie && req->ie_len) {
02636 memcpy(wk->ie, req->ie, req->ie_len);
02637 wk->ie_len = req->ie_len;
02638 } else
02639 wk->ie_len = 0;
02640
02641 wk->assoc.bss = req->bss;
02642
02643 memcpy(wk->filter_ta, req->bss->bssid, ETH_ALEN);
02644
02645
02646 if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
02647 if (ifmgd->powersave)
02648 ifmgd->ap_smps = IEEE80211_SMPS_DYNAMIC;
02649 else
02650 ifmgd->ap_smps = IEEE80211_SMPS_OFF;
02651 } else
02652 ifmgd->ap_smps = ifmgd->req_smps;
02653
02654 wk->assoc.smps = ifmgd->ap_smps;
02655
02656
02657
02658
02659
02660
02661
02662 wk->assoc.use_11n = !(ifmgd->flags & IEEE80211_STA_DISABLE_11N);
02663 wk->assoc.capability = req->bss->capability;
02664 wk->assoc.wmm_used = bss->wmm_used;
02665 wk->assoc.supp_rates = bss->supp_rates;
02666 wk->assoc.supp_rates_len = bss->supp_rates_len;
02667 wk->assoc.ht_information_ie =
02668 ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_INFORMATION);
02669
02670 if (bss->wmm_used && bss->uapsd_supported &&
02671 (sdata->local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)) {
02672 wk->assoc.uapsd_used = true;
02673 ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
02674 } else {
02675 wk->assoc.uapsd_used = false;
02676 ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
02677 }
02678
02679 ssid = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
02680 memcpy(wk->assoc.ssid, ssid + 2, ssid[1]);
02681 wk->assoc.ssid_len = ssid[1];
02682
02683 if (req->prev_bssid)
02684 memcpy(wk->assoc.prev_bssid, req->prev_bssid, ETH_ALEN);
02685
02686 wk->chan = req->bss->channel;
02687 wk->chan_type = NL80211_CHAN_NO_HT;
02688 wk->sdata = sdata;
02689 wk->done = ieee80211_assoc_done;
02690 if (!bss->dtim_period &&
02691 sdata->local->hw.flags & IEEE80211_HW_NEED_DTIM_PERIOD)
02692 wk->type = IEEE80211_WORK_ASSOC_BEACON_WAIT;
02693 else
02694 wk->type = IEEE80211_WORK_ASSOC;
02695
02696 if (req->use_mfp) {
02697 ifmgd->mfp = IEEE80211_MFP_REQUIRED;
02698 ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
02699 } else {
02700 ifmgd->mfp = IEEE80211_MFP_DISABLED;
02701 ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
02702 }
02703
02704 if (req->crypto.control_port)
02705 ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
02706 else
02707 ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
02708
02709 sdata->control_port_protocol = req->crypto.control_port_ethertype;
02710 sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
02711
02712 ieee80211_add_work(wk);
02713 return 0;
02714 }
02715
02716 int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
02717 struct cfg80211_deauth_request *req,
02718 void *cookie)
02719 {
02720 struct ieee80211_local *local = sdata->local;
02721 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
02722 u8 bssid[ETH_ALEN];
02723 bool assoc_bss = false;
02724
02725 mutex_lock(&ifmgd->mtx);
02726
02727 memcpy(bssid, req->bss->bssid, ETH_ALEN);
02728 if (ifmgd->associated == req->bss) {
02729 ieee80211_set_disassoc(sdata, false, true);
02730 mutex_unlock(&ifmgd->mtx);
02731 assoc_bss = true;
02732 } else {
02733 bool not_auth_yet = false;
02734 struct ieee80211_work *tmp, *wk = NULL;
02735
02736 mutex_unlock(&ifmgd->mtx);
02737
02738 mutex_lock(&local->mtx);
02739 list_for_each_entry(tmp, &local->work_list, list) {
02740 if (tmp->sdata != sdata)
02741 continue;
02742
02743 if (tmp->type != IEEE80211_WORK_DIRECT_PROBE &&
02744 tmp->type != IEEE80211_WORK_AUTH &&
02745 tmp->type != IEEE80211_WORK_ASSOC &&
02746 tmp->type != IEEE80211_WORK_ASSOC_BEACON_WAIT)
02747 continue;
02748
02749 if (memcmp(req->bss->bssid, tmp->filter_ta, ETH_ALEN))
02750 continue;
02751
02752 not_auth_yet = tmp->type == IEEE80211_WORK_DIRECT_PROBE;
02753 list_del_rcu(&tmp->list);
02754 synchronize_rcu();
02755 wk = tmp;
02756 break;
02757 }
02758 mutex_unlock(&local->mtx);
02759
02760 if (wk && wk->type == IEEE80211_WORK_ASSOC) {
02761
02762 sta_info_destroy_addr(wk->sdata, wk->filter_ta);
02763 if (wk->assoc.synced)
02764 drv_finish_tx_sync(local, wk->sdata,
02765 wk->filter_ta,
02766 IEEE80211_TX_SYNC_ASSOC);
02767 } else if (wk && wk->type == IEEE80211_WORK_AUTH) {
02768 if (wk->probe_auth.synced)
02769 drv_finish_tx_sync(local, wk->sdata,
02770 wk->filter_ta,
02771 IEEE80211_TX_SYNC_AUTH);
02772 }
02773 kfree(wk);
02774
02775
02776
02777
02778
02779
02780
02781
02782
02783 if (not_auth_yet) {
02784 __cfg80211_auth_canceled(sdata->dev, bssid);
02785 return 0;
02786 }
02787 }
02788
02789 printk(KERN_DEBUG "%s: deauthenticating from %pM by local choice (reason=%d)\n",
02790 sdata->name, bssid, req->reason_code);
02791
02792 ieee80211_send_deauth_disassoc(sdata, bssid, IEEE80211_STYPE_DEAUTH,
02793 req->reason_code, cookie,
02794 !req->local_state_change);
02795 if (assoc_bss)
02796 sta_info_flush(sdata->local, sdata);
02797
02798 mutex_lock(&sdata->local->mtx);
02799 ieee80211_recalc_idle(sdata->local);
02800 mutex_unlock(&sdata->local->mtx);
02801
02802 return 0;
02803 }
02804
02805 int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
02806 struct cfg80211_disassoc_request *req,
02807 void *cookie)
02808 {
02809 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
02810 u8 bssid[ETH_ALEN];
02811
02812 mutex_lock(&ifmgd->mtx);
02813
02814
02815
02816
02817
02818
02819
02820 if (ifmgd->associated != req->bss) {
02821 mutex_unlock(&ifmgd->mtx);
02822 return -ENOLINK;
02823 }
02824
02825 printk(KERN_DEBUG "%s: disassociating from %pM by local choice (reason=%d)\n",
02826 sdata->name, req->bss->bssid, req->reason_code);
02827
02828 memcpy(bssid, req->bss->bssid, ETH_ALEN);
02829 ieee80211_set_disassoc(sdata, false, true);
02830
02831 mutex_unlock(&ifmgd->mtx);
02832
02833 ieee80211_send_deauth_disassoc(sdata, req->bss->bssid,
02834 IEEE80211_STYPE_DISASSOC, req->reason_code,
02835 cookie, !req->local_state_change);
02836 sta_info_flush(sdata->local, sdata);
02837
02838 mutex_lock(&sdata->local->mtx);
02839 ieee80211_recalc_idle(sdata->local);
02840 mutex_unlock(&sdata->local->mtx);
02841
02842 return 0;
02843 }
02844
02845 void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
02846 enum nl80211_cqm_rssi_threshold_event rssi_event,
02847 gfp_t gfp)
02848 {
02849 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
02850
02851 trace_api_cqm_rssi_notify(sdata, rssi_event);
02852
02853 cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, gfp);
02854 }
02855 EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
02856
02857 unsigned char ieee80211_get_operstate(struct ieee80211_vif *vif)
02858 {
02859 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
02860 return sdata->dev->operstate;
02861 }
02862 EXPORT_SYMBOL(ieee80211_get_operstate);