sta_info.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2002-2005, Instant802 Networks, Inc.
00003  * Copyright 2006-2007  Jiri Benc <jbenc@suse.cz>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  */
00009 
00010 #include <linux/module.h>
00011 #include <linux/init.h>
00012 #include <linux/etherdevice.h>
00013 #include <linux/netdevice.h>
00014 #include <linux/types.h>
00015 #include <linux/slab.h>
00016 #include <linux/skbuff.h>
00017 #include <linux/if_arp.h>
00018 #include <linux/timer.h>
00019 #include <linux/rtnetlink.h>
00020 
00021 #include <net/mac80211.h>
00022 #include "ieee80211_i.h"
00023 #include "driver-ops.h"
00024 #include "rate.h"
00025 #include "sta_info.h"
00026 #include "debugfs_sta.h"
00027 #include "mesh.h"
00028 #include "wme.h"
00029 
00066 /* Caller must hold local->sta_mtx */
00067 static int sta_info_hash_del(struct ieee80211_local *local,
00068                              struct sta_info *sta)
00069 {
00070         struct sta_info *s;
00071 
00072         s = rcu_dereference_protected(local->sta_hash[STA_HASH(sta->sta.addr)],
00073                                       lockdep_is_held(&local->sta_mtx));
00074         if (!s)
00075                 return -ENOENT;
00076         if (s == sta) {
00077                 rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)],
00078                                    s->hnext);
00079                 return 0;
00080         }
00081 
00082         while (rcu_access_pointer(s->hnext) &&
00083                rcu_access_pointer(s->hnext) != sta)
00084                 s = rcu_dereference_protected(s->hnext,
00085                                         lockdep_is_held(&local->sta_mtx));
00086         if (rcu_access_pointer(s->hnext)) {
00087                 rcu_assign_pointer(s->hnext, sta->hnext);
00088                 return 0;
00089         }
00090 
00091         return -ENOENT;
00092 }
00093 
00094 /* protected by RCU */
00095 struct sta_info *sta_info_get(struct ieee80211_sub_if_data *sdata,
00096                               const u8 *addr)
00097 {
00098         struct ieee80211_local *local = sdata->local;
00099         struct sta_info *sta;
00100 
00101         sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)],
00102                                     lockdep_is_held(&local->sta_mtx));
00103         while (sta) {
00104                 if (sta->sdata == sdata &&
00105                     ether_addr_equal(sta->sta.addr, addr))
00106                         break;
00107                 sta = rcu_dereference_check(sta->hnext,
00108                                             lockdep_is_held(&local->sta_mtx));
00109         }
00110         return sta;
00111 }
00112 
00113 /*
00114  * Get sta info either from the specified interface
00115  * or from one of its vlans
00116  */
00117 struct sta_info *sta_info_get_bss(struct ieee80211_sub_if_data *sdata,
00118                                   const u8 *addr)
00119 {
00120         struct ieee80211_local *local = sdata->local;
00121         struct sta_info *sta;
00122 
00123         sta = rcu_dereference_check(local->sta_hash[STA_HASH(addr)],
00124                                     lockdep_is_held(&local->sta_mtx));
00125         while (sta) {
00126                 if ((sta->sdata == sdata ||
00127                      (sta->sdata->bss && sta->sdata->bss == sdata->bss)) &&
00128                     ether_addr_equal(sta->sta.addr, addr))
00129                         break;
00130                 sta = rcu_dereference_check(sta->hnext,
00131                                             lockdep_is_held(&local->sta_mtx));
00132         }
00133         return sta;
00134 }
00135 
00136 struct sta_info *sta_info_get_by_idx(struct ieee80211_sub_if_data *sdata,
00137                                      int idx)
00138 {
00139         struct ieee80211_local *local = sdata->local;
00140         struct sta_info *sta;
00141         int i = 0;
00142 
00143         list_for_each_entry_rcu(sta, &local->sta_list, list) {
00144                 if (sdata != sta->sdata)
00145                         continue;
00146                 if (i < idx) {
00147                         ++i;
00148                         continue;
00149                 }
00150                 return sta;
00151         }
00152 
00153         return NULL;
00154 }
00155 
00167 void sta_info_free(struct ieee80211_local *local, struct sta_info *sta)
00168 {
00169         if (sta->rate_ctrl)
00170                 rate_control_free_sta(sta);
00171 
00172 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
00173         wiphy_debug(local->hw.wiphy, "Destroyed STA %pM\n", sta->sta.addr);
00174 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
00175 
00176         kfree(sta);
00177 }
00178 
00179 /* Caller must hold local->sta_mtx */
00180 static void sta_info_hash_add(struct ieee80211_local *local,
00181                               struct sta_info *sta)
00182 {
00183         lockdep_assert_held(&local->sta_mtx);
00184         sta->hnext = local->sta_hash[STA_HASH(sta->sta.addr)];
00185         rcu_assign_pointer(local->sta_hash[STA_HASH(sta->sta.addr)], sta);
00186 }
00187 
00188 static void sta_unblock(struct work_struct *wk)
00189 {
00190         struct sta_info *sta;
00191 
00192         sta = container_of(wk, struct sta_info, drv_unblock_wk);
00193 
00194         if (sta->dead)
00195                 return;
00196 
00197         if (!test_sta_flag(sta, WLAN_STA_PS_STA)) {
00198                 local_bh_disable();
00199                 ieee80211_sta_ps_deliver_wakeup(sta);
00200                 local_bh_enable();
00201         } else if (test_and_clear_sta_flag(sta, WLAN_STA_PSPOLL)) {
00202                 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
00203 
00204                 local_bh_disable();
00205                 ieee80211_sta_ps_deliver_poll_response(sta);
00206                 local_bh_enable();
00207         } else if (test_and_clear_sta_flag(sta, WLAN_STA_UAPSD)) {
00208                 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
00209 
00210                 local_bh_disable();
00211                 ieee80211_sta_ps_deliver_uapsd(sta);
00212                 local_bh_enable();
00213         } else
00214                 clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
00215 }
00216 
00217 static int sta_prepare_rate_control(struct ieee80211_local *local,
00218                                     struct sta_info *sta, gfp_t gfp)
00219 {
00220         if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
00221                 return 0;
00222 
00223         sta->rate_ctrl = local->rate_ctrl;
00224         sta->rate_ctrl_priv = rate_control_alloc_sta(sta->rate_ctrl,
00225                                                      &sta->sta, gfp);
00226         if (!sta->rate_ctrl_priv)
00227                 return -ENOMEM;
00228 
00229         return 0;
00230 }
00231 
00232 struct sta_info *sta_info_alloc(struct ieee80211_sub_if_data *sdata,
00233                                 const u8 *addr, gfp_t gfp)
00234 {
00235         struct ieee80211_local *local = sdata->local;
00236         struct sta_info *sta;
00237         struct timespec uptime;
00238         int i;
00239 
00240         sta = kzalloc(sizeof(*sta) + local->hw.sta_data_size, gfp);
00241         if (!sta)
00242                 return NULL;
00243 
00244         spin_lock_init(&sta->lock);
00245         INIT_WORK(&sta->drv_unblock_wk, sta_unblock);
00246         INIT_WORK(&sta->ampdu_mlme.work, ieee80211_ba_session_work);
00247         mutex_init(&sta->ampdu_mlme.mtx);
00248 
00249         memcpy(sta->sta.addr, addr, ETH_ALEN);
00250         sta->local = local;
00251         sta->sdata = sdata;
00252         sta->last_rx = jiffies;
00253 
00254         sta->sta_state = IEEE80211_STA_NONE;
00255 
00256         do_posix_clock_monotonic_gettime(&uptime);
00257         sta->last_connected = uptime.tv_sec;
00258         ewma_init(&sta->avg_signal, 1024, 8);
00259 
00260         if (sta_prepare_rate_control(local, sta, gfp)) {
00261                 kfree(sta);
00262                 return NULL;
00263         }
00264 
00265         for (i = 0; i < STA_TID_NUM; i++) {
00266                 /*
00267                  * timer_to_tid must be initialized with identity mapping
00268                  * to enable session_timer's data differentiation. See
00269                  * sta_rx_agg_session_timer_expired for usage.
00270                  */
00271                 sta->timer_to_tid[i] = i;
00272         }
00273         for (i = 0; i < IEEE80211_NUM_ACS; i++) {
00274                 skb_queue_head_init(&sta->ps_tx_buf[i]);
00275                 skb_queue_head_init(&sta->tx_filtered[i]);
00276         }
00277 
00278         for (i = 0; i < NUM_RX_DATA_QUEUES; i++)
00279                 sta->last_seq_ctrl[i] = cpu_to_le16(USHRT_MAX);
00280 
00281 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
00282         wiphy_debug(local->hw.wiphy, "Allocated STA %pM\n", sta->sta.addr);
00283 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
00284 
00285 #ifdef CONFIG_MAC80211_MESH
00286         sta->plink_state = NL80211_PLINK_LISTEN;
00287         init_timer(&sta->plink_timer);
00288 #endif
00289 
00290         return sta;
00291 }
00292 
00293 static int sta_info_insert_check(struct sta_info *sta)
00294 {
00295         struct ieee80211_sub_if_data *sdata = sta->sdata;
00296 
00297         /*
00298          * Can't be a WARN_ON because it can be triggered through a race:
00299          * something inserts a STA (on one CPU) without holding the RTNL
00300          * and another CPU turns off the net device.
00301          */
00302         if (unlikely(!ieee80211_sdata_running(sdata)))
00303                 return -ENETDOWN;
00304 
00305         if (WARN_ON(ether_addr_equal(sta->sta.addr, sdata->vif.addr) ||
00306                     is_multicast_ether_addr(sta->sta.addr)))
00307                 return -EINVAL;
00308 
00309         return 0;
00310 }
00311 
00312 static int sta_info_insert_drv_state(struct ieee80211_local *local,
00313                                      struct ieee80211_sub_if_data *sdata,
00314                                      struct sta_info *sta)
00315 {
00316         enum ieee80211_sta_state state;
00317         int err = 0;
00318 
00319         for (state = IEEE80211_STA_NOTEXIST; state < sta->sta_state; state++) {
00320                 err = drv_sta_state(local, sdata, sta, state, state + 1);
00321                 if (err)
00322                         break;
00323         }
00324 
00325         if (!err) {
00326                 /*
00327                  * Drivers using legacy sta_add/sta_remove callbacks only
00328                  * get uploaded set to true after sta_add is called.
00329                  */
00330                 if (!local->ops->sta_add)
00331                         sta->uploaded = true;
00332                 return 0;
00333         }
00334 
00335         if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
00336                 printk(KERN_DEBUG
00337                        "%s: failed to move IBSS STA %pM to state %d (%d) - keeping it anyway.\n",
00338                        sdata->name, sta->sta.addr, state + 1, err);
00339                 err = 0;
00340         }
00341 
00342         /* unwind on error */
00343         for (; state > IEEE80211_STA_NOTEXIST; state--)
00344                 WARN_ON(drv_sta_state(local, sdata, sta, state, state - 1));
00345 
00346         return err;
00347 }
00348 
00349 /*
00350  * should be called with sta_mtx locked
00351  * this function replaces the mutex lock
00352  * with a RCU lock
00353  */
00354 static int sta_info_insert_finish(struct sta_info *sta) __acquires(RCU)
00355 {
00356         struct ieee80211_local *local = sta->local;
00357         struct ieee80211_sub_if_data *sdata = sta->sdata;
00358         struct station_info sinfo;
00359         int err = 0;
00360 
00361         lockdep_assert_held(&local->sta_mtx);
00362 
00363         /* check if STA exists already */
00364         if (sta_info_get_bss(sdata, sta->sta.addr)) {
00365                 err = -EEXIST;
00366                 goto out_err;
00367         }
00368 
00369         /* notify driver */
00370         err = sta_info_insert_drv_state(local, sdata, sta);
00371         if (err)
00372                 goto out_err;
00373 
00374         local->num_sta++;
00375         local->sta_generation++;
00376         smp_mb();
00377 
00378         /* make the station visible */
00379         sta_info_hash_add(local, sta);
00380 
00381         list_add_rcu(&sta->list, &local->sta_list);
00382 
00383         set_sta_flag(sta, WLAN_STA_INSERTED);
00384 
00385         ieee80211_sta_debugfs_add(sta);
00386         rate_control_add_sta_debugfs(sta);
00387 
00388         memset(&sinfo, 0, sizeof(sinfo));
00389         sinfo.filled = 0;
00390         sinfo.generation = local->sta_generation;
00391         cfg80211_new_sta(sdata->dev, sta->sta.addr, &sinfo, GFP_KERNEL);
00392 
00393 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
00394         wiphy_debug(local->hw.wiphy, "Inserted STA %pM\n", sta->sta.addr);
00395 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
00396 
00397         /* move reference to rcu-protected */
00398         rcu_read_lock();
00399         mutex_unlock(&local->sta_mtx);
00400 
00401         if (ieee80211_vif_is_mesh(&sdata->vif))
00402                 mesh_accept_plinks_update(sdata);
00403 
00404         return 0;
00405  out_err:
00406         mutex_unlock(&local->sta_mtx);
00407         rcu_read_lock();
00408         return err;
00409 }
00410 
00411 int sta_info_insert_rcu(struct sta_info *sta) __acquires(RCU)
00412 {
00413         struct ieee80211_local *local = sta->local;
00414         int err = 0;
00415 
00416         might_sleep();
00417 
00418         err = sta_info_insert_check(sta);
00419         if (err) {
00420                 rcu_read_lock();
00421                 goto out_free;
00422         }
00423 
00424         mutex_lock(&local->sta_mtx);
00425 
00426         err = sta_info_insert_finish(sta);
00427         if (err)
00428                 goto out_free;
00429 
00430         return 0;
00431  out_free:
00432         BUG_ON(!err);
00433         sta_info_free(local, sta);
00434         return err;
00435 }
00436 
00437 int sta_info_insert(struct sta_info *sta)
00438 {
00439         int err = sta_info_insert_rcu(sta);
00440 
00441         rcu_read_unlock();
00442 
00443         return err;
00444 }
00445 
00446 static inline void __bss_tim_set(struct ieee80211_if_ap *bss, u16 aid)
00447 {
00448         /*
00449          * This format has been mandated by the IEEE specifications,
00450          * so this line may not be changed to use the __set_bit() format.
00451          */
00452         bss->tim[aid / 8] |= (1 << (aid % 8));
00453 }
00454 
00455 static inline void __bss_tim_clear(struct ieee80211_if_ap *bss, u16 aid)
00456 {
00457         /*
00458          * This format has been mandated by the IEEE specifications,
00459          * so this line may not be changed to use the __clear_bit() format.
00460          */
00461         bss->tim[aid / 8] &= ~(1 << (aid % 8));
00462 }
00463 
00464 static unsigned long ieee80211_tids_for_ac(int ac)
00465 {
00466         /* If we ever support TIDs > 7, this obviously needs to be adjusted */
00467         switch (ac) {
00468         case IEEE80211_AC_VO:
00469                 return BIT(6) | BIT(7);
00470         case IEEE80211_AC_VI:
00471                 return BIT(4) | BIT(5);
00472         case IEEE80211_AC_BE:
00473                 return BIT(0) | BIT(3);
00474         case IEEE80211_AC_BK:
00475                 return BIT(1) | BIT(2);
00476         default:
00477                 WARN_ON(1);
00478                 return 0;
00479         }
00480 }
00481 
00482 void sta_info_recalc_tim(struct sta_info *sta)
00483 {
00484         struct ieee80211_local *local = sta->local;
00485         struct ieee80211_if_ap *bss = sta->sdata->bss;
00486         unsigned long flags;
00487         bool indicate_tim = false;
00488         u8 ignore_for_tim = sta->sta.uapsd_queues;
00489         int ac;
00490 
00491         if (WARN_ON_ONCE(!sta->sdata->bss))
00492                 return;
00493 
00494         /* No need to do anything if the driver does all */
00495         if (local->hw.flags & IEEE80211_HW_AP_LINK_PS)
00496                 return;
00497 
00498         if (sta->dead)
00499                 goto done;
00500 
00501         /*
00502          * If all ACs are delivery-enabled then we should build
00503          * the TIM bit for all ACs anyway; if only some are then
00504          * we ignore those and build the TIM bit using only the
00505          * non-enabled ones.
00506          */
00507         if (ignore_for_tim == BIT(IEEE80211_NUM_ACS) - 1)
00508                 ignore_for_tim = 0;
00509 
00510         for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
00511                 unsigned long tids;
00512 
00513                 if (ignore_for_tim & BIT(ac))
00514                         continue;
00515 
00516                 indicate_tim |= !skb_queue_empty(&sta->tx_filtered[ac]) ||
00517                                 !skb_queue_empty(&sta->ps_tx_buf[ac]);
00518                 if (indicate_tim)
00519                         break;
00520 
00521                 tids = ieee80211_tids_for_ac(ac);
00522 
00523                 indicate_tim |=
00524                         sta->driver_buffered_tids & tids;
00525         }
00526 
00527  done:
00528         spin_lock_irqsave(&local->tim_lock, flags);
00529 
00530         if (indicate_tim)
00531                 __bss_tim_set(bss, sta->sta.aid);
00532         else
00533                 __bss_tim_clear(bss, sta->sta.aid);
00534 
00535         if (local->ops->set_tim) {
00536                 local->tim_in_locked_section = true;
00537                 drv_set_tim(local, &sta->sta, indicate_tim);
00538                 local->tim_in_locked_section = false;
00539         }
00540 
00541         spin_unlock_irqrestore(&local->tim_lock, flags);
00542 }
00543 
00544 static bool sta_info_buffer_expired(struct sta_info *sta, struct sk_buff *skb)
00545 {
00546         struct ieee80211_tx_info *info;
00547         int timeout;
00548 
00549         if (!skb)
00550                 return false;
00551 
00552         info = IEEE80211_SKB_CB(skb);
00553 
00554         /* Timeout: (2 * listen_interval * beacon_int * 1024 / 1000000) sec */
00555         timeout = (sta->listen_interval *
00556                    sta->sdata->vif.bss_conf.beacon_int *
00557                    32 / 15625) * HZ;
00558         if (timeout < STA_TX_BUFFER_EXPIRE)
00559                 timeout = STA_TX_BUFFER_EXPIRE;
00560         return time_after(jiffies, info->control.jiffies + timeout);
00561 }
00562 
00563 
00564 static bool sta_info_cleanup_expire_buffered_ac(struct ieee80211_local *local,
00565                                                 struct sta_info *sta, int ac)
00566 {
00567         unsigned long flags;
00568         struct sk_buff *skb;
00569 
00570         /*
00571          * First check for frames that should expire on the filtered
00572          * queue. Frames here were rejected by the driver and are on
00573          * a separate queue to avoid reordering with normal PS-buffered
00574          * frames. They also aren't accounted for right now in the
00575          * total_ps_buffered counter.
00576          */
00577         for (;;) {
00578                 spin_lock_irqsave(&sta->tx_filtered[ac].lock, flags);
00579                 skb = skb_peek(&sta->tx_filtered[ac]);
00580                 if (sta_info_buffer_expired(sta, skb))
00581                         skb = __skb_dequeue(&sta->tx_filtered[ac]);
00582                 else
00583                         skb = NULL;
00584                 spin_unlock_irqrestore(&sta->tx_filtered[ac].lock, flags);
00585 
00586                 /*
00587                  * Frames are queued in order, so if this one
00588                  * hasn't expired yet we can stop testing. If
00589                  * we actually reached the end of the queue we
00590                  * also need to stop, of course.
00591                  */
00592                 if (!skb)
00593                         break;
00594                 dev_kfree_skb(skb);
00595         }
00596 
00597         /*
00598          * Now also check the normal PS-buffered queue, this will
00599          * only find something if the filtered queue was emptied
00600          * since the filtered frames are all before the normal PS
00601          * buffered frames.
00602          */
00603         for (;;) {
00604                 spin_lock_irqsave(&sta->ps_tx_buf[ac].lock, flags);
00605                 skb = skb_peek(&sta->ps_tx_buf[ac]);
00606                 if (sta_info_buffer_expired(sta, skb))
00607                         skb = __skb_dequeue(&sta->ps_tx_buf[ac]);
00608                 else
00609                         skb = NULL;
00610                 spin_unlock_irqrestore(&sta->ps_tx_buf[ac].lock, flags);
00611 
00612                 /*
00613                  * frames are queued in order, so if this one
00614                  * hasn't expired yet (or we reached the end of
00615                  * the queue) we can stop testing
00616                  */
00617                 if (!skb)
00618                         break;
00619 
00620                 local->total_ps_buffered--;
00621 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
00622                 printk(KERN_DEBUG "Buffered frame expired (STA %pM)\n",
00623                        sta->sta.addr);
00624 #endif
00625                 dev_kfree_skb(skb);
00626         }
00627 
00628         /*
00629          * Finally, recalculate the TIM bit for this station -- it might
00630          * now be clear because the station was too slow to retrieve its
00631          * frames.
00632          */
00633         sta_info_recalc_tim(sta);
00634 
00635         /*
00636          * Return whether there are any frames still buffered, this is
00637          * used to check whether the cleanup timer still needs to run,
00638          * if there are no frames we don't need to rearm the timer.
00639          */
00640         return !(skb_queue_empty(&sta->ps_tx_buf[ac]) &&
00641                  skb_queue_empty(&sta->tx_filtered[ac]));
00642 }
00643 
00644 static bool sta_info_cleanup_expire_buffered(struct ieee80211_local *local,
00645                                              struct sta_info *sta)
00646 {
00647         bool have_buffered = false;
00648         int ac;
00649 
00650         /* This is only necessary for stations on BSS interfaces */
00651         if (!sta->sdata->bss)
00652                 return false;
00653 
00654         for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
00655                 have_buffered |=
00656                         sta_info_cleanup_expire_buffered_ac(local, sta, ac);
00657 
00658         return have_buffered;
00659 }
00660 
00661 int __must_check __sta_info_destroy(struct sta_info *sta)
00662 {
00663         struct ieee80211_local *local;
00664         struct ieee80211_sub_if_data *sdata;
00665         int ret, i, ac;
00666         struct tid_ampdu_tx *tid_tx;
00667 
00668         might_sleep();
00669 
00670         if (!sta)
00671                 return -ENOENT;
00672 
00673         local = sta->local;
00674         sdata = sta->sdata;
00675 
00676         lockdep_assert_held(&local->sta_mtx);
00677 
00678         /*
00679          * Before removing the station from the driver and
00680          * rate control, it might still start new aggregation
00681          * sessions -- block that to make sure the tear-down
00682          * will be sufficient.
00683          */
00684         set_sta_flag(sta, WLAN_STA_BLOCK_BA);
00685         ieee80211_sta_tear_down_BA_sessions(sta, true);
00686 
00687         ret = sta_info_hash_del(local, sta);
00688         if (ret)
00689                 return ret;
00690 
00691         list_del_rcu(&sta->list);
00692 
00693         mutex_lock(&local->key_mtx);
00694         for (i = 0; i < NUM_DEFAULT_KEYS; i++)
00695                 __ieee80211_key_free(key_mtx_dereference(local, sta->gtk[i]));
00696         if (sta->ptk)
00697                 __ieee80211_key_free(key_mtx_dereference(local, sta->ptk));
00698         mutex_unlock(&local->key_mtx);
00699 
00700         sta->dead = true;
00701 
00702         local->num_sta--;
00703         local->sta_generation++;
00704 
00705         if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
00706                 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
00707 
00708         while (sta->sta_state > IEEE80211_STA_NONE) {
00709                 ret = sta_info_move_state(sta, sta->sta_state - 1);
00710                 if (ret) {
00711                         WARN_ON_ONCE(1);
00712                         break;
00713                 }
00714         }
00715 
00716         if (sta->uploaded) {
00717                 ret = drv_sta_state(local, sdata, sta, IEEE80211_STA_NONE,
00718                                     IEEE80211_STA_NOTEXIST);
00719                 WARN_ON_ONCE(ret != 0);
00720         }
00721 
00722         /*
00723          * At this point, after we wait for an RCU grace period,
00724          * neither mac80211 nor the driver can reference this
00725          * sta struct any more except by still existing timers
00726          * associated with this station that we clean up below.
00727          */
00728         synchronize_rcu();
00729 
00730         if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
00731                 BUG_ON(!sdata->bss);
00732 
00733                 clear_sta_flag(sta, WLAN_STA_PS_STA);
00734 
00735                 atomic_dec(&sdata->bss->num_sta_ps);
00736                 sta_info_recalc_tim(sta);
00737         }
00738 
00739         for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
00740                 local->total_ps_buffered -= skb_queue_len(&sta->ps_tx_buf[ac]);
00741                 __skb_queue_purge(&sta->ps_tx_buf[ac]);
00742                 __skb_queue_purge(&sta->tx_filtered[ac]);
00743         }
00744 
00745 #ifdef CONFIG_MAC80211_MESH
00746         if (ieee80211_vif_is_mesh(&sdata->vif))
00747                 mesh_accept_plinks_update(sdata);
00748 #endif
00749 
00750 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
00751         wiphy_debug(local->hw.wiphy, "Removed STA %pM\n", sta->sta.addr);
00752 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
00753         cancel_work_sync(&sta->drv_unblock_wk);
00754 
00755         cfg80211_del_sta(sdata->dev, sta->sta.addr, GFP_KERNEL);
00756 
00757         rate_control_remove_sta_debugfs(sta);
00758         ieee80211_sta_debugfs_remove(sta);
00759 
00760 #ifdef CONFIG_MAC80211_MESH
00761         if (ieee80211_vif_is_mesh(&sta->sdata->vif)) {
00762                 mesh_plink_deactivate(sta);
00763                 del_timer_sync(&sta->plink_timer);
00764         }
00765 #endif
00766 
00767         /*
00768          * Destroy aggregation state here. It would be nice to wait for the
00769          * driver to finish aggregation stop and then clean up, but for now
00770          * drivers have to handle aggregation stop being requested, followed
00771          * directly by station destruction.
00772          */
00773         for (i = 0; i < STA_TID_NUM; i++) {
00774                 tid_tx = rcu_dereference_raw(sta->ampdu_mlme.tid_tx[i]);
00775                 if (!tid_tx)
00776                         continue;
00777                 __skb_queue_purge(&tid_tx->pending);
00778                 kfree(tid_tx);
00779         }
00780 
00781         sta_info_free(local, sta);
00782 
00783         return 0;
00784 }
00785 
00786 int sta_info_destroy_addr(struct ieee80211_sub_if_data *sdata, const u8 *addr)
00787 {
00788         struct sta_info *sta;
00789         int ret;
00790 
00791         mutex_lock(&sdata->local->sta_mtx);
00792         sta = sta_info_get(sdata, addr);
00793         ret = __sta_info_destroy(sta);
00794         mutex_unlock(&sdata->local->sta_mtx);
00795 
00796         return ret;
00797 }
00798 
00799 int sta_info_destroy_addr_bss(struct ieee80211_sub_if_data *sdata,
00800                               const u8 *addr)
00801 {
00802         struct sta_info *sta;
00803         int ret;
00804 
00805         mutex_lock(&sdata->local->sta_mtx);
00806         sta = sta_info_get_bss(sdata, addr);
00807         ret = __sta_info_destroy(sta);
00808         mutex_unlock(&sdata->local->sta_mtx);
00809 
00810         return ret;
00811 }
00812 
00813 static void sta_info_cleanup(unsigned long data)
00814 {
00815         struct ieee80211_local *local = (struct ieee80211_local *) data;
00816         struct sta_info *sta;
00817         bool timer_needed = false;
00818 
00819         rcu_read_lock();
00820         list_for_each_entry_rcu(sta, &local->sta_list, list)
00821                 if (sta_info_cleanup_expire_buffered(local, sta))
00822                         timer_needed = true;
00823         rcu_read_unlock();
00824 
00825         if (local->quiescing)
00826                 return;
00827 
00828         if (!timer_needed)
00829                 return;
00830 
00831         mod_timer(&local->sta_cleanup,
00832                   round_jiffies(jiffies + STA_INFO_CLEANUP_INTERVAL));
00833 }
00834 
00835 void sta_info_init(struct ieee80211_local *local)
00836 {
00837         spin_lock_init(&local->tim_lock);
00838         mutex_init(&local->sta_mtx);
00839         INIT_LIST_HEAD(&local->sta_list);
00840 
00841         setup_timer(&local->sta_cleanup, sta_info_cleanup,
00842                     (unsigned long)local);
00843 }
00844 
00845 void sta_info_stop(struct ieee80211_local *local)
00846 {
00847         del_timer(&local->sta_cleanup);
00848         sta_info_flush(local, NULL);
00849 }
00850 
00859 int sta_info_flush(struct ieee80211_local *local,
00860                    struct ieee80211_sub_if_data *sdata)
00861 {
00862         struct sta_info *sta, *tmp;
00863         int ret = 0;
00864 
00865         might_sleep();
00866 
00867         mutex_lock(&local->sta_mtx);
00868         list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
00869                 if (!sdata || sdata == sta->sdata) {
00870                         WARN_ON(__sta_info_destroy(sta));
00871                         ret++;
00872                 }
00873         }
00874         mutex_unlock(&local->sta_mtx);
00875 
00876         return ret;
00877 }
00878 
00879 void ieee80211_sta_expire(struct ieee80211_sub_if_data *sdata,
00880                           unsigned long exp_time)
00881 {
00882         struct ieee80211_local *local = sdata->local;
00883         struct sta_info *sta, *tmp;
00884 
00885         mutex_lock(&local->sta_mtx);
00886 
00887         list_for_each_entry_safe(sta, tmp, &local->sta_list, list) {
00888                 if (sdata != sta->sdata)
00889                         continue;
00890 
00891                 if (time_after(jiffies, sta->last_rx + exp_time)) {
00892 #ifdef CONFIG_MAC80211_IBSS_DEBUG
00893                         printk(KERN_DEBUG "%s: expiring inactive STA %pM\n",
00894                                sdata->name, sta->sta.addr);
00895 #endif
00896                         WARN_ON(__sta_info_destroy(sta));
00897                 }
00898         }
00899 
00900         mutex_unlock(&local->sta_mtx);
00901 }
00902 
00903 struct ieee80211_sta *ieee80211_find_sta_by_ifaddr(struct ieee80211_hw *hw,
00904                                                const u8 *addr,
00905                                                const u8 *localaddr)
00906 {
00907         struct sta_info *sta, *nxt;
00908 
00909         /*
00910          * Just return a random station if localaddr is NULL
00911          * ... first in list.
00912          */
00913         for_each_sta_info(hw_to_local(hw), addr, sta, nxt) {
00914                 if (localaddr &&
00915                     !ether_addr_equal(sta->sdata->vif.addr, localaddr))
00916                         continue;
00917                 if (!sta->uploaded)
00918                         return NULL;
00919                 return &sta->sta;
00920         }
00921 
00922         return NULL;
00923 }
00924 EXPORT_SYMBOL_GPL(ieee80211_find_sta_by_ifaddr);
00925 
00926 struct ieee80211_sta *ieee80211_find_sta(struct ieee80211_vif *vif,
00927                                          const u8 *addr)
00928 {
00929         struct sta_info *sta;
00930 
00931         if (!vif)
00932                 return NULL;
00933 
00934         sta = sta_info_get_bss(vif_to_sdata(vif), addr);
00935         if (!sta)
00936                 return NULL;
00937 
00938         if (!sta->uploaded)
00939                 return NULL;
00940 
00941         return &sta->sta;
00942 }
00943 EXPORT_SYMBOL(ieee80211_find_sta);
00944 
00945 static void clear_sta_ps_flags(void *_sta)
00946 {
00947         struct sta_info *sta = _sta;
00948         struct ieee80211_sub_if_data *sdata = sta->sdata;
00949 
00950         clear_sta_flag(sta, WLAN_STA_PS_DRIVER);
00951         if (test_and_clear_sta_flag(sta, WLAN_STA_PS_STA))
00952                 atomic_dec(&sdata->bss->num_sta_ps);
00953 }
00954 
00955 /* powersave support code */
00956 void ieee80211_sta_ps_deliver_wakeup(struct sta_info *sta)
00957 {
00958         struct ieee80211_sub_if_data *sdata = sta->sdata;
00959         struct ieee80211_local *local = sdata->local;
00960         struct sk_buff_head pending;
00961         int filtered = 0, buffered = 0, ac;
00962 
00963         clear_sta_flag(sta, WLAN_STA_SP);
00964 
00965         BUILD_BUG_ON(BITS_TO_LONGS(STA_TID_NUM) > 1);
00966         sta->driver_buffered_tids = 0;
00967 
00968         if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
00969                 drv_sta_notify(local, sdata, STA_NOTIFY_AWAKE, &sta->sta);
00970 
00971         skb_queue_head_init(&pending);
00972 
00973         /* Send all buffered frames to the station */
00974         for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
00975                 int count = skb_queue_len(&pending), tmp;
00976 
00977                 skb_queue_splice_tail_init(&sta->tx_filtered[ac], &pending);
00978                 tmp = skb_queue_len(&pending);
00979                 filtered += tmp - count;
00980                 count = tmp;
00981 
00982                 skb_queue_splice_tail_init(&sta->ps_tx_buf[ac], &pending);
00983                 tmp = skb_queue_len(&pending);
00984                 buffered += tmp - count;
00985         }
00986 
00987         ieee80211_add_pending_skbs_fn(local, &pending, clear_sta_ps_flags, sta);
00988 
00989         local->total_ps_buffered -= buffered;
00990 
00991         sta_info_recalc_tim(sta);
00992 
00993 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
00994         printk(KERN_DEBUG "%s: STA %pM aid %d sending %d filtered/%d PS frames "
00995                "since STA not sleeping anymore\n", sdata->name,
00996                sta->sta.addr, sta->sta.aid, filtered, buffered);
00997 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
00998 }
00999 
01000 static void ieee80211_send_null_response(struct ieee80211_sub_if_data *sdata,
01001                                          struct sta_info *sta, int tid,
01002                                          enum ieee80211_frame_release_type reason)
01003 {
01004         struct ieee80211_local *local = sdata->local;
01005         struct ieee80211_qos_hdr *nullfunc;
01006         struct sk_buff *skb;
01007         int size = sizeof(*nullfunc);
01008         __le16 fc;
01009         bool qos = test_sta_flag(sta, WLAN_STA_WME);
01010         struct ieee80211_tx_info *info;
01011 
01012         if (qos) {
01013                 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
01014                                  IEEE80211_STYPE_QOS_NULLFUNC |
01015                                  IEEE80211_FCTL_FROMDS);
01016         } else {
01017                 size -= 2;
01018                 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
01019                                  IEEE80211_STYPE_NULLFUNC |
01020                                  IEEE80211_FCTL_FROMDS);
01021         }
01022 
01023         skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
01024         if (!skb)
01025                 return;
01026 
01027         skb_reserve(skb, local->hw.extra_tx_headroom);
01028 
01029         nullfunc = (void *) skb_put(skb, size);
01030         nullfunc->frame_control = fc;
01031         nullfunc->duration_id = 0;
01032         memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
01033         memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
01034         memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
01035 
01036         skb->priority = tid;
01037         skb_set_queue_mapping(skb, ieee802_1d_to_ac[tid]);
01038         if (qos) {
01039                 nullfunc->qos_ctrl = cpu_to_le16(tid);
01040 
01041                 if (reason == IEEE80211_FRAME_RELEASE_UAPSD)
01042                         nullfunc->qos_ctrl |=
01043                                 cpu_to_le16(IEEE80211_QOS_CTL_EOSP);
01044         }
01045 
01046         info = IEEE80211_SKB_CB(skb);
01047 
01048         /*
01049          * Tell TX path to send this frame even though the
01050          * STA may still remain is PS mode after this frame
01051          * exchange. Also set EOSP to indicate this packet
01052          * ends the poll/service period.
01053          */
01054         info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER |
01055                        IEEE80211_TX_STATUS_EOSP |
01056                        IEEE80211_TX_CTL_REQ_TX_STATUS;
01057 
01058         drv_allow_buffered_frames(local, sta, BIT(tid), 1, reason, false);
01059 
01060         ieee80211_xmit(sdata, skb);
01061 }
01062 
01063 static void
01064 ieee80211_sta_ps_deliver_response(struct sta_info *sta,
01065                                   int n_frames, u8 ignored_acs,
01066                                   enum ieee80211_frame_release_type reason)
01067 {
01068         struct ieee80211_sub_if_data *sdata = sta->sdata;
01069         struct ieee80211_local *local = sdata->local;
01070         bool found = false;
01071         bool more_data = false;
01072         int ac;
01073         unsigned long driver_release_tids = 0;
01074         struct sk_buff_head frames;
01075 
01076         /* Service or PS-Poll period starts */
01077         set_sta_flag(sta, WLAN_STA_SP);
01078 
01079         __skb_queue_head_init(&frames);
01080 
01081         /*
01082          * Get response frame(s) and more data bit for it.
01083          */
01084         for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
01085                 unsigned long tids;
01086 
01087                 if (ignored_acs & BIT(ac))
01088                         continue;
01089 
01090                 tids = ieee80211_tids_for_ac(ac);
01091 
01092                 if (!found) {
01093                         driver_release_tids = sta->driver_buffered_tids & tids;
01094                         if (driver_release_tids) {
01095                                 found = true;
01096                         } else {
01097                                 struct sk_buff *skb;
01098 
01099                                 while (n_frames > 0) {
01100                                         skb = skb_dequeue(&sta->tx_filtered[ac]);
01101                                         if (!skb) {
01102                                                 skb = skb_dequeue(
01103                                                         &sta->ps_tx_buf[ac]);
01104                                                 if (skb)
01105                                                         local->total_ps_buffered--;
01106                                         }
01107                                         if (!skb)
01108                                                 break;
01109                                         n_frames--;
01110                                         found = true;
01111                                         __skb_queue_tail(&frames, skb);
01112                                 }
01113                         }
01114 
01115                         /*
01116                          * If the driver has data on more than one TID then
01117                          * certainly there's more data if we release just a
01118                          * single frame now (from a single TID).
01119                          */
01120                         if (reason == IEEE80211_FRAME_RELEASE_PSPOLL &&
01121                             hweight16(driver_release_tids) > 1) {
01122                                 more_data = true;
01123                                 driver_release_tids =
01124                                         BIT(ffs(driver_release_tids) - 1);
01125                                 break;
01126                         }
01127                 }
01128 
01129                 if (!skb_queue_empty(&sta->tx_filtered[ac]) ||
01130                     !skb_queue_empty(&sta->ps_tx_buf[ac])) {
01131                         more_data = true;
01132                         break;
01133                 }
01134         }
01135 
01136         if (!found) {
01137                 int tid;
01138 
01139                 /*
01140                  * For PS-Poll, this can only happen due to a race condition
01141                  * when we set the TIM bit and the station notices it, but
01142                  * before it can poll for the frame we expire it.
01143                  *
01144                  * For uAPSD, this is said in the standard (11.2.1.5 h):
01145                  *      At each unscheduled SP for a non-AP STA, the AP shall
01146                  *      attempt to transmit at least one MSDU or MMPDU, but no
01147                  *      more than the value specified in the Max SP Length field
01148                  *      in the QoS Capability element from delivery-enabled ACs,
01149                  *      that are destined for the non-AP STA.
01150                  *
01151                  * Since we have no other MSDU/MMPDU, transmit a QoS null frame.
01152                  */
01153 
01154                 /* This will evaluate to 1, 3, 5 or 7. */
01155                 tid = 7 - ((ffs(~ignored_acs) - 1) << 1);
01156 
01157                 ieee80211_send_null_response(sdata, sta, tid, reason);
01158                 return;
01159         }
01160 
01161         if (!driver_release_tids) {
01162                 struct sk_buff_head pending;
01163                 struct sk_buff *skb;
01164                 int num = 0;
01165                 u16 tids = 0;
01166 
01167                 skb_queue_head_init(&pending);
01168 
01169                 while ((skb = __skb_dequeue(&frames))) {
01170                         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
01171                         struct ieee80211_hdr *hdr = (void *) skb->data;
01172                         u8 *qoshdr = NULL;
01173 
01174                         num++;
01175 
01176                         /*
01177                          * Tell TX path to send this frame even though the
01178                          * STA may still remain is PS mode after this frame
01179                          * exchange.
01180                          */
01181                         info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
01182 
01183                         /*
01184                          * Use MoreData flag to indicate whether there are
01185                          * more buffered frames for this STA
01186                          */
01187                         if (more_data || !skb_queue_empty(&frames))
01188                                 hdr->frame_control |=
01189                                         cpu_to_le16(IEEE80211_FCTL_MOREDATA);
01190                         else
01191                                 hdr->frame_control &=
01192                                         cpu_to_le16(~IEEE80211_FCTL_MOREDATA);
01193 
01194                         if (ieee80211_is_data_qos(hdr->frame_control) ||
01195                             ieee80211_is_qos_nullfunc(hdr->frame_control))
01196                                 qoshdr = ieee80211_get_qos_ctl(hdr);
01197 
01198                         /* end service period after last frame */
01199                         if (skb_queue_empty(&frames)) {
01200                                 if (reason == IEEE80211_FRAME_RELEASE_UAPSD &&
01201                                     qoshdr)
01202                                         *qoshdr |= IEEE80211_QOS_CTL_EOSP;
01203 
01204                                 info->flags |= IEEE80211_TX_STATUS_EOSP |
01205                                                IEEE80211_TX_CTL_REQ_TX_STATUS;
01206                         }
01207 
01208                         if (qoshdr)
01209                                 tids |= BIT(*qoshdr & IEEE80211_QOS_CTL_TID_MASK);
01210                         else
01211                                 tids |= BIT(0);
01212 
01213                         __skb_queue_tail(&pending, skb);
01214                 }
01215 
01216                 drv_allow_buffered_frames(local, sta, tids, num,
01217                                           reason, more_data);
01218 
01219                 ieee80211_add_pending_skbs(local, &pending);
01220 
01221                 sta_info_recalc_tim(sta);
01222         } else {
01223                 /*
01224                  * We need to release a frame that is buffered somewhere in the
01225                  * driver ... it'll have to handle that.
01226                  * Note that, as per the comment above, it'll also have to see
01227                  * if there is more than just one frame on the specific TID that
01228                  * we're releasing from, and it needs to set the more-data bit
01229                  * accordingly if we tell it that there's no more data. If we do
01230                  * tell it there's more data, then of course the more-data bit
01231                  * needs to be set anyway.
01232                  */
01233                 drv_release_buffered_frames(local, sta, driver_release_tids,
01234                                             n_frames, reason, more_data);
01235 
01236                 /*
01237                  * Note that we don't recalculate the TIM bit here as it would
01238                  * most likely have no effect at all unless the driver told us
01239                  * that the TID became empty before returning here from the
01240                  * release function.
01241                  * Either way, however, when the driver tells us that the TID
01242                  * became empty we'll do the TIM recalculation.
01243                  */
01244         }
01245 }
01246 
01247 void ieee80211_sta_ps_deliver_poll_response(struct sta_info *sta)
01248 {
01249         u8 ignore_for_response = sta->sta.uapsd_queues;
01250 
01251         /*
01252          * If all ACs are delivery-enabled then we should reply
01253          * from any of them, if only some are enabled we reply
01254          * only from the non-enabled ones.
01255          */
01256         if (ignore_for_response == BIT(IEEE80211_NUM_ACS) - 1)
01257                 ignore_for_response = 0;
01258 
01259         ieee80211_sta_ps_deliver_response(sta, 1, ignore_for_response,
01260                                           IEEE80211_FRAME_RELEASE_PSPOLL);
01261 }
01262 
01263 void ieee80211_sta_ps_deliver_uapsd(struct sta_info *sta)
01264 {
01265         int n_frames = sta->sta.max_sp;
01266         u8 delivery_enabled = sta->sta.uapsd_queues;
01267 
01268         /*
01269          * If we ever grow support for TSPEC this might happen if
01270          * the TSPEC update from hostapd comes in between a trigger
01271          * frame setting WLAN_STA_UAPSD in the RX path and this
01272          * actually getting called.
01273          */
01274         if (!delivery_enabled)
01275                 return;
01276 
01277         switch (sta->sta.max_sp) {
01278         case 1:
01279                 n_frames = 2;
01280                 break;
01281         case 2:
01282                 n_frames = 4;
01283                 break;
01284         case 3:
01285                 n_frames = 6;
01286                 break;
01287         case 0:
01288                 /* XXX: what is a good value? */
01289                 n_frames = 8;
01290                 break;
01291         }
01292 
01293         ieee80211_sta_ps_deliver_response(sta, n_frames, ~delivery_enabled,
01294                                           IEEE80211_FRAME_RELEASE_UAPSD);
01295 }
01296 
01297 void ieee80211_sta_block_awake(struct ieee80211_hw *hw,
01298                                struct ieee80211_sta *pubsta, bool block)
01299 {
01300         struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
01301 
01302         trace_api_sta_block_awake(sta->local, pubsta, block);
01303 
01304         if (block)
01305                 set_sta_flag(sta, WLAN_STA_PS_DRIVER);
01306         else if (test_sta_flag(sta, WLAN_STA_PS_DRIVER))
01307                 ieee80211_queue_work(hw, &sta->drv_unblock_wk);
01308 }
01309 EXPORT_SYMBOL(ieee80211_sta_block_awake);
01310 
01311 void ieee80211_sta_eosp_irqsafe(struct ieee80211_sta *pubsta)
01312 {
01313         struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
01314         struct ieee80211_local *local = sta->local;
01315         struct sk_buff *skb;
01316         struct skb_eosp_msg_data *data;
01317 
01318         trace_api_eosp(local, pubsta);
01319 
01320         skb = alloc_skb(0, GFP_ATOMIC);
01321         if (!skb) {
01322                 /* too bad ... but race is better than loss */
01323                 clear_sta_flag(sta, WLAN_STA_SP);
01324                 return;
01325         }
01326 
01327         data = (void *)skb->cb;
01328         memcpy(data->sta, pubsta->addr, ETH_ALEN);
01329         memcpy(data->iface, sta->sdata->vif.addr, ETH_ALEN);
01330         skb->pkt_type = IEEE80211_EOSP_MSG;
01331         skb_queue_tail(&local->skb_queue, skb);
01332         tasklet_schedule(&local->tasklet);
01333 }
01334 EXPORT_SYMBOL(ieee80211_sta_eosp_irqsafe);
01335 
01336 void ieee80211_sta_set_buffered(struct ieee80211_sta *pubsta,
01337                                 u8 tid, bool buffered)
01338 {
01339         struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
01340 
01341         if (WARN_ON(tid >= STA_TID_NUM))
01342                 return;
01343 
01344         if (buffered)
01345                 set_bit(tid, &sta->driver_buffered_tids);
01346         else
01347                 clear_bit(tid, &sta->driver_buffered_tids);
01348 
01349         sta_info_recalc_tim(sta);
01350 }
01351 EXPORT_SYMBOL(ieee80211_sta_set_buffered);
01352 
01353 int sta_info_move_state(struct sta_info *sta,
01354                         enum ieee80211_sta_state new_state)
01355 {
01356         might_sleep();
01357 
01358         if (sta->sta_state == new_state)
01359                 return 0;
01360 
01361         /* check allowed transitions first */
01362 
01363         switch (new_state) {
01364         case IEEE80211_STA_NONE:
01365                 if (sta->sta_state != IEEE80211_STA_AUTH)
01366                         return -EINVAL;
01367                 break;
01368         case IEEE80211_STA_AUTH:
01369                 if (sta->sta_state != IEEE80211_STA_NONE &&
01370                     sta->sta_state != IEEE80211_STA_ASSOC)
01371                         return -EINVAL;
01372                 break;
01373         case IEEE80211_STA_ASSOC:
01374                 if (sta->sta_state != IEEE80211_STA_AUTH &&
01375                     sta->sta_state != IEEE80211_STA_AUTHORIZED)
01376                         return -EINVAL;
01377                 break;
01378         case IEEE80211_STA_AUTHORIZED:
01379                 if (sta->sta_state != IEEE80211_STA_ASSOC)
01380                         return -EINVAL;
01381                 break;
01382         default:
01383                 WARN(1, "invalid state %d", new_state);
01384                 return -EINVAL;
01385         }
01386 
01387 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
01388         printk(KERN_DEBUG "%s: moving STA %pM to state %d\n",
01389                 sta->sdata->name, sta->sta.addr, new_state);
01390 #endif
01391 
01392         /*
01393          * notify the driver before the actual changes so it can
01394          * fail the transition
01395          */
01396         if (test_sta_flag(sta, WLAN_STA_INSERTED)) {
01397                 int err = drv_sta_state(sta->local, sta->sdata, sta,
01398                                         sta->sta_state, new_state);
01399                 if (err)
01400                         return err;
01401         }
01402 
01403         /* reflect the change in all state variables */
01404 
01405         switch (new_state) {
01406         case IEEE80211_STA_NONE:
01407                 if (sta->sta_state == IEEE80211_STA_AUTH)
01408                         clear_bit(WLAN_STA_AUTH, &sta->_flags);
01409                 break;
01410         case IEEE80211_STA_AUTH:
01411                 if (sta->sta_state == IEEE80211_STA_NONE)
01412                         set_bit(WLAN_STA_AUTH, &sta->_flags);
01413                 else if (sta->sta_state == IEEE80211_STA_ASSOC)
01414                         clear_bit(WLAN_STA_ASSOC, &sta->_flags);
01415                 break;
01416         case IEEE80211_STA_ASSOC:
01417                 if (sta->sta_state == IEEE80211_STA_AUTH) {
01418                         set_bit(WLAN_STA_ASSOC, &sta->_flags);
01419                 } else if (sta->sta_state == IEEE80211_STA_AUTHORIZED) {
01420                         if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
01421                             (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
01422                              !sta->sdata->u.vlan.sta))
01423                                 atomic_dec(&sta->sdata->bss->num_mcast_sta);
01424                         clear_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
01425                 }
01426                 break;
01427         case IEEE80211_STA_AUTHORIZED:
01428                 if (sta->sta_state == IEEE80211_STA_ASSOC) {
01429                         if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
01430                             (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
01431                              !sta->sdata->u.vlan.sta))
01432                                 atomic_inc(&sta->sdata->bss->num_mcast_sta);
01433                         set_bit(WLAN_STA_AUTHORIZED, &sta->_flags);
01434                 }
01435                 break;
01436         default:
01437                 break;
01438         }
01439 
01440         sta->sta_state = new_state;
01441 
01442         return 0;
01443 }


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:11