util.c
Go to the documentation of this file.
00001 /*
00002  * Copyright 2002-2005, Instant802 Networks, Inc.
00003  * Copyright 2005-2006, Devicescape Software, Inc.
00004  * Copyright 2006-2007  Jiri Benc <jbenc@suse.cz>
00005  * Copyright 2007       Johannes Berg <johannes@sipsolutions.net>
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License version 2 as
00009  * published by the Free Software Foundation.
00010  *
00011  * utilities for mac80211
00012  */
00013 
00014 #include <net/mac80211.h>
00015 #include <linux/netdevice.h>
00016 #include <linux/export.h>
00017 #include <linux/types.h>
00018 #include <linux/slab.h>
00019 #include <linux/skbuff.h>
00020 #include <linux/etherdevice.h>
00021 #include <linux/if_arp.h>
00022 #include <linux/bitmap.h>
00023 #include <net/net_namespace.h>
00024 #include <net/cfg80211.h>
00025 #include <net/rtnetlink.h>
00026 
00027 #include "ieee80211_i.h"
00028 #include "driver-ops.h"
00029 #include "rate.h"
00030 #include "mesh.h"
00031 #include "wme.h"
00032 #include "led.h"
00033 #include "wep.h"
00034 
00035 /* privid for wiphys to determine whether they belong to us or not */
00036 void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
00037 
00038 struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy)
00039 {
00040         struct ieee80211_local *local;
00041         BUG_ON(!wiphy);
00042 
00043         local = wiphy_priv(wiphy);
00044         return &local->hw;
00045 }
00046 EXPORT_SYMBOL(wiphy_to_ieee80211_hw);
00047 
00048 u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
00049                         enum nl80211_iftype type)
00050 {
00051         __le16 fc = hdr->frame_control;
00052 
00053          /* drop ACK/CTS frames and incorrect hdr len (ctrl) */
00054         if (len < 16)
00055                 return NULL;
00056 
00057         if (ieee80211_is_data(fc)) {
00058                 if (len < 24) /* drop incorrect hdr len (data) */
00059                         return NULL;
00060 
00061                 if (ieee80211_has_a4(fc))
00062                         return NULL;
00063                 if (ieee80211_has_tods(fc))
00064                         return hdr->addr1;
00065                 if (ieee80211_has_fromds(fc))
00066                         return hdr->addr2;
00067 
00068                 return hdr->addr3;
00069         }
00070 
00071         if (ieee80211_is_mgmt(fc)) {
00072                 if (len < 24) /* drop incorrect hdr len (mgmt) */
00073                         return NULL;
00074                 return hdr->addr3;
00075         }
00076 
00077         if (ieee80211_is_ctl(fc)) {
00078                 if(ieee80211_is_pspoll(fc))
00079                         return hdr->addr1;
00080 
00081                 if (ieee80211_is_back_req(fc)) {
00082                         switch (type) {
00083                         case NL80211_IFTYPE_STATION:
00084                                 return hdr->addr2;
00085                         case NL80211_IFTYPE_AP:
00086                         case NL80211_IFTYPE_AP_VLAN:
00087                                 return hdr->addr1;
00088                         default:
00089                                 break; /* fall through to the return */
00090                         }
00091                 }
00092         }
00093 
00094         return NULL;
00095 }
00096 
00097 void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
00098 {
00099         struct sk_buff *skb = tx->skb;
00100         struct ieee80211_hdr *hdr;
00101 
00102         do {
00103                 hdr = (struct ieee80211_hdr *) skb->data;
00104                 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
00105         } while ((skb = skb->next));
00106 }
00107 
00108 int ieee80211_frame_duration(struct ieee80211_local *local, size_t len,
00109                              int rate, int erp, int short_preamble)
00110 {
00111         int dur;
00112 
00113         /* calculate duration (in microseconds, rounded up to next higher
00114          * integer if it includes a fractional microsecond) to send frame of
00115          * len bytes (does not include FCS) at the given rate. Duration will
00116          * also include SIFS.
00117          *
00118          * rate is in 100 kbps, so divident is multiplied by 10 in the
00119          * DIV_ROUND_UP() operations.
00120          */
00121 
00122         if (local->hw.conf.channel->band == IEEE80211_BAND_5GHZ || erp) {
00123                 /*
00124                  * OFDM:
00125                  *
00126                  * N_DBPS = DATARATE x 4
00127                  * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
00128                  *      (16 = SIGNAL time, 6 = tail bits)
00129                  * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
00130                  *
00131                  * T_SYM = 4 usec
00132                  * 802.11a - 17.5.2: aSIFSTime = 16 usec
00133                  * 802.11g - 19.8.4: aSIFSTime = 10 usec +
00134                  *      signal ext = 6 usec
00135                  */
00136                 dur = 16; /* SIFS + signal ext */
00137                 dur += 16; /* 17.3.2.3: T_PREAMBLE = 16 usec */
00138                 dur += 4; /* 17.3.2.3: T_SIGNAL = 4 usec */
00139                 dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
00140                                         4 * rate); /* T_SYM x N_SYM */
00141         } else {
00142                 /*
00143                  * 802.11b or 802.11g with 802.11b compatibility:
00144                  * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
00145                  * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
00146                  *
00147                  * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
00148                  * aSIFSTime = 10 usec
00149                  * aPreambleLength = 144 usec or 72 usec with short preamble
00150                  * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
00151                  */
00152                 dur = 10; /* aSIFSTime = 10 usec */
00153                 dur += short_preamble ? (72 + 24) : (144 + 48);
00154 
00155                 dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
00156         }
00157 
00158         return dur;
00159 }
00160 
00161 /* Exported duration function for driver use */
00162 __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
00163                                         struct ieee80211_vif *vif,
00164                                         size_t frame_len,
00165                                         struct ieee80211_rate *rate)
00166 {
00167         struct ieee80211_local *local = hw_to_local(hw);
00168         struct ieee80211_sub_if_data *sdata;
00169         u16 dur;
00170         int erp;
00171         bool short_preamble = false;
00172 
00173         erp = 0;
00174         if (vif) {
00175                 sdata = vif_to_sdata(vif);
00176                 short_preamble = sdata->vif.bss_conf.use_short_preamble;
00177                 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
00178                         erp = rate->flags & IEEE80211_RATE_ERP_G;
00179         }
00180 
00181         dur = ieee80211_frame_duration(local, frame_len, rate->bitrate, erp,
00182                                        short_preamble);
00183 
00184         return cpu_to_le16(dur);
00185 }
00186 EXPORT_SYMBOL(ieee80211_generic_frame_duration);
00187 
00188 __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
00189                               struct ieee80211_vif *vif, size_t frame_len,
00190                               const struct ieee80211_tx_info *frame_txctl)
00191 {
00192         struct ieee80211_local *local = hw_to_local(hw);
00193         struct ieee80211_rate *rate;
00194         struct ieee80211_sub_if_data *sdata;
00195         bool short_preamble;
00196         int erp;
00197         u16 dur;
00198         struct ieee80211_supported_band *sband;
00199 
00200         sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
00201 
00202         short_preamble = false;
00203 
00204         rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
00205 
00206         erp = 0;
00207         if (vif) {
00208                 sdata = vif_to_sdata(vif);
00209                 short_preamble = sdata->vif.bss_conf.use_short_preamble;
00210                 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
00211                         erp = rate->flags & IEEE80211_RATE_ERP_G;
00212         }
00213 
00214         /* CTS duration */
00215         dur = ieee80211_frame_duration(local, 10, rate->bitrate,
00216                                        erp, short_preamble);
00217         /* Data frame duration */
00218         dur += ieee80211_frame_duration(local, frame_len, rate->bitrate,
00219                                         erp, short_preamble);
00220         /* ACK duration */
00221         dur += ieee80211_frame_duration(local, 10, rate->bitrate,
00222                                         erp, short_preamble);
00223 
00224         return cpu_to_le16(dur);
00225 }
00226 EXPORT_SYMBOL(ieee80211_rts_duration);
00227 
00228 __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
00229                                     struct ieee80211_vif *vif,
00230                                     size_t frame_len,
00231                                     const struct ieee80211_tx_info *frame_txctl)
00232 {
00233         struct ieee80211_local *local = hw_to_local(hw);
00234         struct ieee80211_rate *rate;
00235         struct ieee80211_sub_if_data *sdata;
00236         bool short_preamble;
00237         int erp;
00238         u16 dur;
00239         struct ieee80211_supported_band *sband;
00240 
00241         sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
00242 
00243         short_preamble = false;
00244 
00245         rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
00246         erp = 0;
00247         if (vif) {
00248                 sdata = vif_to_sdata(vif);
00249                 short_preamble = sdata->vif.bss_conf.use_short_preamble;
00250                 if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
00251                         erp = rate->flags & IEEE80211_RATE_ERP_G;
00252         }
00253 
00254         /* Data frame duration */
00255         dur = ieee80211_frame_duration(local, frame_len, rate->bitrate,
00256                                        erp, short_preamble);
00257         if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
00258                 /* ACK duration */
00259                 dur += ieee80211_frame_duration(local, 10, rate->bitrate,
00260                                                 erp, short_preamble);
00261         }
00262 
00263         return cpu_to_le16(dur);
00264 }
00265 EXPORT_SYMBOL(ieee80211_ctstoself_duration);
00266 
00267 static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
00268                                    enum queue_stop_reason reason)
00269 {
00270         struct ieee80211_local *local = hw_to_local(hw);
00271         struct ieee80211_sub_if_data *sdata;
00272 
00273         trace_wake_queue(local, queue, reason);
00274 
00275         if (WARN_ON(queue >= hw->queues))
00276                 return;
00277 
00278         __clear_bit(reason, &local->queue_stop_reasons[queue]);
00279 
00280         if (local->queue_stop_reasons[queue] != 0)
00281                 /* someone still has this queue stopped */
00282                 return;
00283 
00284         if (skb_queue_empty(&local->pending[queue])) {
00285                 rcu_read_lock();
00286                 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
00287                         if (test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))
00288                                 continue;
00289                         netif_wake_subqueue(sdata->dev, queue);
00290                 }
00291                 rcu_read_unlock();
00292         } else
00293                 tasklet_schedule(&local->tx_pending_tasklet);
00294 }
00295 
00296 void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
00297                                     enum queue_stop_reason reason)
00298 {
00299         struct ieee80211_local *local = hw_to_local(hw);
00300         unsigned long flags;
00301 
00302         spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
00303         __ieee80211_wake_queue(hw, queue, reason);
00304         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
00305 }
00306 
00307 void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
00308 {
00309         ieee80211_wake_queue_by_reason(hw, queue,
00310                                        IEEE80211_QUEUE_STOP_REASON_DRIVER);
00311 }
00312 EXPORT_SYMBOL(ieee80211_wake_queue);
00313 
00314 static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
00315                                    enum queue_stop_reason reason)
00316 {
00317         struct ieee80211_local *local = hw_to_local(hw);
00318         struct ieee80211_sub_if_data *sdata;
00319 
00320         trace_stop_queue(local, queue, reason);
00321 
00322         if (WARN_ON(queue >= hw->queues))
00323                 return;
00324 
00325         __set_bit(reason, &local->queue_stop_reasons[queue]);
00326 
00327         rcu_read_lock();
00328         list_for_each_entry_rcu(sdata, &local->interfaces, list)
00329                 netif_stop_subqueue(sdata->dev, queue);
00330         rcu_read_unlock();
00331 }
00332 
00333 void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
00334                                     enum queue_stop_reason reason)
00335 {
00336         struct ieee80211_local *local = hw_to_local(hw);
00337         unsigned long flags;
00338 
00339         spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
00340         __ieee80211_stop_queue(hw, queue, reason);
00341         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
00342 }
00343 
00344 void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
00345 {
00346         ieee80211_stop_queue_by_reason(hw, queue,
00347                                        IEEE80211_QUEUE_STOP_REASON_DRIVER);
00348 }
00349 EXPORT_SYMBOL(ieee80211_stop_queue);
00350 
00351 void ieee80211_add_pending_skb(struct ieee80211_local *local,
00352                                struct sk_buff *skb)
00353 {
00354         struct ieee80211_hw *hw = &local->hw;
00355         unsigned long flags;
00356         int queue = skb_get_queue_mapping(skb);
00357         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
00358 
00359         if (WARN_ON(!info->control.vif)) {
00360                 kfree_skb(skb);
00361                 return;
00362         }
00363 
00364         spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
00365         __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
00366         __skb_queue_tail(&local->pending[queue], skb);
00367         __ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
00368         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
00369 }
00370 
00371 void ieee80211_add_pending_skbs_fn(struct ieee80211_local *local,
00372                                    struct sk_buff_head *skbs,
00373                                    void (*fn)(void *data), void *data)
00374 {
00375         struct ieee80211_hw *hw = &local->hw;
00376         struct sk_buff *skb;
00377         unsigned long flags;
00378         int queue, i;
00379 
00380         spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
00381         for (i = 0; i < hw->queues; i++)
00382                 __ieee80211_stop_queue(hw, i,
00383                         IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
00384 
00385         while ((skb = skb_dequeue(skbs))) {
00386                 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
00387 
00388                 if (WARN_ON(!info->control.vif)) {
00389                         kfree_skb(skb);
00390                         continue;
00391                 }
00392 
00393                 queue = skb_get_queue_mapping(skb);
00394                 __skb_queue_tail(&local->pending[queue], skb);
00395         }
00396 
00397         if (fn)
00398                 fn(data);
00399 
00400         for (i = 0; i < hw->queues; i++)
00401                 __ieee80211_wake_queue(hw, i,
00402                         IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
00403         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
00404 }
00405 
00406 void ieee80211_add_pending_skbs(struct ieee80211_local *local,
00407                                 struct sk_buff_head *skbs)
00408 {
00409         ieee80211_add_pending_skbs_fn(local, skbs, NULL, NULL);
00410 }
00411 
00412 void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
00413                                     enum queue_stop_reason reason)
00414 {
00415         struct ieee80211_local *local = hw_to_local(hw);
00416         unsigned long flags;
00417         int i;
00418 
00419         spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
00420 
00421         for (i = 0; i < hw->queues; i++)
00422                 __ieee80211_stop_queue(hw, i, reason);
00423 
00424         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
00425 }
00426 
00427 void ieee80211_stop_queues(struct ieee80211_hw *hw)
00428 {
00429         ieee80211_stop_queues_by_reason(hw,
00430                                         IEEE80211_QUEUE_STOP_REASON_DRIVER);
00431 }
00432 EXPORT_SYMBOL(ieee80211_stop_queues);
00433 
00434 int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
00435 {
00436         struct ieee80211_local *local = hw_to_local(hw);
00437         unsigned long flags;
00438         int ret;
00439 
00440         if (WARN_ON(queue >= hw->queues))
00441                 return true;
00442 
00443         spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
00444         ret = !!local->queue_stop_reasons[queue];
00445         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
00446         return ret;
00447 }
00448 EXPORT_SYMBOL(ieee80211_queue_stopped);
00449 
00450 void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
00451                                      enum queue_stop_reason reason)
00452 {
00453         struct ieee80211_local *local = hw_to_local(hw);
00454         unsigned long flags;
00455         int i;
00456 
00457         spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
00458 
00459         for (i = 0; i < hw->queues; i++)
00460                 __ieee80211_wake_queue(hw, i, reason);
00461 
00462         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
00463 }
00464 
00465 void ieee80211_wake_queues(struct ieee80211_hw *hw)
00466 {
00467         ieee80211_wake_queues_by_reason(hw, IEEE80211_QUEUE_STOP_REASON_DRIVER);
00468 }
00469 EXPORT_SYMBOL(ieee80211_wake_queues);
00470 
00471 void ieee80211_iterate_active_interfaces(
00472         struct ieee80211_hw *hw,
00473         void (*iterator)(void *data, u8 *mac,
00474                          struct ieee80211_vif *vif),
00475         void *data)
00476 {
00477         struct ieee80211_local *local = hw_to_local(hw);
00478         struct ieee80211_sub_if_data *sdata;
00479 
00480         mutex_lock(&local->iflist_mtx);
00481 
00482         list_for_each_entry(sdata, &local->interfaces, list) {
00483                 switch (sdata->vif.type) {
00484                 case NL80211_IFTYPE_MONITOR:
00485                 case NL80211_IFTYPE_AP_VLAN:
00486                         continue;
00487                 default:
00488                         break;
00489                 }
00490                 if (ieee80211_sdata_running(sdata))
00491                         iterator(data, sdata->vif.addr,
00492                                  &sdata->vif);
00493         }
00494 
00495         mutex_unlock(&local->iflist_mtx);
00496 }
00497 EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces);
00498 
00499 void ieee80211_iterate_active_interfaces_atomic(
00500         struct ieee80211_hw *hw,
00501         void (*iterator)(void *data, u8 *mac,
00502                          struct ieee80211_vif *vif),
00503         void *data)
00504 {
00505         struct ieee80211_local *local = hw_to_local(hw);
00506         struct ieee80211_sub_if_data *sdata;
00507 
00508         rcu_read_lock();
00509 
00510         list_for_each_entry_rcu(sdata, &local->interfaces, list) {
00511                 switch (sdata->vif.type) {
00512                 case NL80211_IFTYPE_MONITOR:
00513                 case NL80211_IFTYPE_AP_VLAN:
00514                         continue;
00515                 default:
00516                         break;
00517                 }
00518                 if (ieee80211_sdata_running(sdata))
00519                         iterator(data, sdata->vif.addr,
00520                                  &sdata->vif);
00521         }
00522 
00523         rcu_read_unlock();
00524 }
00525 EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
00526 
00527 /*
00528  * Nothing should have been stuffed into the workqueue during
00529  * the suspend->resume cycle. If this WARN is seen then there
00530  * is a bug with either the driver suspend or something in
00531  * mac80211 stuffing into the workqueue which we haven't yet
00532  * cleared during mac80211's suspend cycle.
00533  */
00534 static bool ieee80211_can_queue_work(struct ieee80211_local *local)
00535 {
00536         if (WARN(local->suspended && !local->resuming,
00537                  "queueing ieee80211 work while going to suspend\n"))
00538                 return false;
00539 
00540         return true;
00541 }
00542 
00543 void ieee80211_queue_work(struct ieee80211_hw *hw, struct work_struct *work)
00544 {
00545         struct ieee80211_local *local = hw_to_local(hw);
00546 
00547         if (!ieee80211_can_queue_work(local))
00548                 return;
00549 
00550         queue_work(local->workqueue, work);
00551 }
00552 EXPORT_SYMBOL(ieee80211_queue_work);
00553 
00554 void ieee80211_queue_delayed_work(struct ieee80211_hw *hw,
00555                                   struct delayed_work *dwork,
00556                                   unsigned long delay)
00557 {
00558         struct ieee80211_local *local = hw_to_local(hw);
00559 
00560         if (!ieee80211_can_queue_work(local))
00561                 return;
00562 
00563         queue_delayed_work(local->workqueue, dwork, delay);
00564 }
00565 EXPORT_SYMBOL(ieee80211_queue_delayed_work);
00566 
00567 void ieee802_11_parse_elems(u8 *start, size_t len,
00568                             struct ieee802_11_elems *elems)
00569 {
00570         ieee802_11_parse_elems_crc(start, len, elems, 0, 0);
00571 }
00572 
00573 void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata)
00574 {
00575         struct ieee80211_local *local = sdata->local;
00576         struct ieee80211_tx_queue_params qparam;
00577         int queue;
00578         bool use_11b;
00579         int aCWmin, aCWmax;
00580 
00581         if (!local->ops->conf_tx)
00582                 return;
00583 
00584         memset(&qparam, 0, sizeof(qparam));
00585 
00586         use_11b = (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ) &&
00587                  !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE);
00588 
00589         for (queue = 0; queue < local_to_hw(local)->queues; queue++) {
00590                 /* Set defaults according to 802.11-2007 Table 7-37 */
00591                 aCWmax = 1023;
00592                 if (use_11b)
00593                         aCWmin = 31;
00594                 else
00595                         aCWmin = 15;
00596 
00597                 switch (queue) {
00598                 case 3: /* AC_BK */
00599                         qparam.cw_max = aCWmax;
00600                         qparam.cw_min = aCWmin;
00601                         qparam.txop = 0;
00602                         qparam.aifs = 7;
00603                         break;
00604                 default: /* never happens but let's not leave undefined */
00605                 case 2: /* AC_BE */
00606                         qparam.cw_max = aCWmax;
00607                         qparam.cw_min = aCWmin;
00608                         qparam.txop = 0;
00609                         qparam.aifs = 3;
00610                         break;
00611                 case 1: /* AC_VI */
00612                         qparam.cw_max = aCWmin;
00613                         qparam.cw_min = (aCWmin + 1) / 2 - 1;
00614                         if (use_11b)
00615                                 qparam.txop = 6016/32;
00616                         else
00617                                 qparam.txop = 3008/32;
00618                         qparam.aifs = 2;
00619                         break;
00620                 case 0: /* AC_VO */
00621                         qparam.cw_max = (aCWmin + 1) / 2 - 1;
00622                         qparam.cw_min = (aCWmin + 1) / 4 - 1;
00623                         if (use_11b)
00624                                 qparam.txop = 3264/32;
00625                         else
00626                                 qparam.txop = 1504/32;
00627                         qparam.aifs = 2;
00628                         break;
00629                 }
00630 
00631                 qparam.uapsd = false;
00632 
00633                 sdata->tx_conf[queue] = qparam;
00634                 drv_conf_tx(local, sdata, queue, &qparam);
00635         }
00636 
00637         /* after reinitialize QoS TX queues setting to default,
00638          * disable QoS at all */
00639 
00640         if (sdata->vif.type != NL80211_IFTYPE_MONITOR) {
00641                 sdata->vif.bss_conf.qos =
00642                         sdata->vif.type != NL80211_IFTYPE_STATION;
00643                 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
00644         }
00645 }
00646 
00647 void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata,
00648                                   const size_t supp_rates_len,
00649                                   const u8 *supp_rates)
00650 {
00651         struct ieee80211_local *local = sdata->local;
00652         int i, have_higher_than_11mbit = 0;
00653 
00654         /* cf. IEEE 802.11 9.2.12 */
00655         for (i = 0; i < supp_rates_len; i++)
00656                 if ((supp_rates[i] & 0x7f) * 5 > 110)
00657                         have_higher_than_11mbit = 1;
00658 
00659         if (local->hw.conf.channel->band == IEEE80211_BAND_2GHZ &&
00660             have_higher_than_11mbit)
00661                 sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
00662         else
00663                 sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
00664 
00665         ieee80211_set_wmm_default(sdata);
00666 }
00667 
00668 u32 ieee80211_mandatory_rates(struct ieee80211_local *local,
00669                               enum ieee80211_band band)
00670 {
00671         struct ieee80211_supported_band *sband;
00672         struct ieee80211_rate *bitrates;
00673         u32 mandatory_rates;
00674         enum ieee80211_rate_flags mandatory_flag;
00675         int i;
00676 
00677         sband = local->hw.wiphy->bands[band];
00678         if (!sband) {
00679                 WARN_ON(1);
00680                 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
00681         }
00682 
00683         if (band == IEEE80211_BAND_2GHZ)
00684                 mandatory_flag = IEEE80211_RATE_MANDATORY_B;
00685         else
00686                 mandatory_flag = IEEE80211_RATE_MANDATORY_A;
00687 
00688         bitrates = sband->bitrates;
00689         mandatory_rates = 0;
00690         for (i = 0; i < sband->n_bitrates; i++)
00691                 if (bitrates[i].flags & mandatory_flag)
00692                         mandatory_rates |= BIT(i);
00693         return mandatory_rates;
00694 }
00695 
00696 void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
00697                          u16 transaction, u16 auth_alg,
00698                          u8 *extra, size_t extra_len, const u8 *bssid,
00699                          const u8 *key, u8 key_len, u8 key_idx)
00700 {
00701         struct ieee80211_local *local = sdata->local;
00702         struct sk_buff *skb;
00703         struct ieee80211_mgmt *mgmt;
00704         int err;
00705 
00706         skb = dev_alloc_skb(local->hw.extra_tx_headroom +
00707                             sizeof(*mgmt) + 6 + extra_len);
00708         if (!skb)
00709                 return;
00710 
00711         skb_reserve(skb, local->hw.extra_tx_headroom);
00712 
00713         mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
00714         memset(mgmt, 0, 24 + 6);
00715         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
00716                                           IEEE80211_STYPE_AUTH);
00717         memcpy(mgmt->da, bssid, ETH_ALEN);
00718         memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
00719         memcpy(mgmt->bssid, bssid, ETH_ALEN);
00720         mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg);
00721         mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
00722         mgmt->u.auth.status_code = cpu_to_le16(0);
00723         if (extra)
00724                 memcpy(skb_put(skb, extra_len), extra, extra_len);
00725 
00726         if (auth_alg == WLAN_AUTH_SHARED_KEY && transaction == 3) {
00727                 mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
00728                 err = ieee80211_wep_encrypt(local, skb, key, key_len, key_idx);
00729                 WARN_ON(err);
00730         }
00731 
00732         IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
00733         ieee80211_tx_skb(sdata, skb);
00734 }
00735 
00736 int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
00737                              const u8 *ie, size_t ie_len,
00738                              enum ieee80211_band band, u32 rate_mask,
00739                              u8 channel)
00740 {
00741         struct ieee80211_supported_band *sband;
00742         u8 *pos;
00743         size_t offset = 0, noffset;
00744         int supp_rates_len, i;
00745         u8 rates[32];
00746         int num_rates;
00747         int ext_rates_len;
00748 
00749         sband = local->hw.wiphy->bands[band];
00750 
00751         pos = buffer;
00752 
00753         num_rates = 0;
00754         for (i = 0; i < sband->n_bitrates; i++) {
00755                 if ((BIT(i) & rate_mask) == 0)
00756                         continue; /* skip rate */
00757                 rates[num_rates++] = (u8) (sband->bitrates[i].bitrate / 5);
00758         }
00759 
00760         supp_rates_len = min_t(int, num_rates, 8);
00761 
00762         *pos++ = WLAN_EID_SUPP_RATES;
00763         *pos++ = supp_rates_len;
00764         memcpy(pos, rates, supp_rates_len);
00765         pos += supp_rates_len;
00766 
00767         /* insert "request information" if in custom IEs */
00768         if (ie && ie_len) {
00769                 static const u8 before_extrates[] = {
00770                         WLAN_EID_SSID,
00771                         WLAN_EID_SUPP_RATES,
00772                         WLAN_EID_REQUEST,
00773                 };
00774                 noffset = ieee80211_ie_split(ie, ie_len,
00775                                              before_extrates,
00776                                              ARRAY_SIZE(before_extrates),
00777                                              offset);
00778                 memcpy(pos, ie + offset, noffset - offset);
00779                 pos += noffset - offset;
00780                 offset = noffset;
00781         }
00782 
00783         ext_rates_len = num_rates - supp_rates_len;
00784         if (ext_rates_len > 0) {
00785                 *pos++ = WLAN_EID_EXT_SUPP_RATES;
00786                 *pos++ = ext_rates_len;
00787                 memcpy(pos, rates + supp_rates_len, ext_rates_len);
00788                 pos += ext_rates_len;
00789         }
00790 
00791         if (channel && sband->band == IEEE80211_BAND_2GHZ) {
00792                 *pos++ = WLAN_EID_DS_PARAMS;
00793                 *pos++ = 1;
00794                 *pos++ = channel;
00795         }
00796 
00797         /* insert custom IEs that go before HT */
00798         if (ie && ie_len) {
00799                 static const u8 before_ht[] = {
00800                         WLAN_EID_SSID,
00801                         WLAN_EID_SUPP_RATES,
00802                         WLAN_EID_REQUEST,
00803                         WLAN_EID_EXT_SUPP_RATES,
00804                         WLAN_EID_DS_PARAMS,
00805                         WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
00806                 };
00807                 noffset = ieee80211_ie_split(ie, ie_len,
00808                                              before_ht, ARRAY_SIZE(before_ht),
00809                                              offset);
00810                 memcpy(pos, ie + offset, noffset - offset);
00811                 pos += noffset - offset;
00812                 offset = noffset;
00813         }
00814 
00815         if (sband->ht_cap.ht_supported) {
00816                 u16 cap = sband->ht_cap.cap;
00817                 __le16 tmp;
00818 
00819                 *pos++ = WLAN_EID_HT_CAPABILITY;
00820                 *pos++ = sizeof(struct ieee80211_ht_cap);
00821                 memset(pos, 0, sizeof(struct ieee80211_ht_cap));
00822                 tmp = cpu_to_le16(cap);
00823                 memcpy(pos, &tmp, sizeof(u16));
00824                 pos += sizeof(u16);
00825                 *pos++ = sband->ht_cap.ampdu_factor |
00826                          (sband->ht_cap.ampdu_density <<
00827                                 IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
00828                 memcpy(pos, &sband->ht_cap.mcs, sizeof(sband->ht_cap.mcs));
00829                 pos += sizeof(sband->ht_cap.mcs);
00830                 pos += 2 + 4 + 1; /* ext info, BF cap, antsel */
00831         }
00832 
00833         /*
00834          * If adding more here, adjust code in main.c
00835          * that calculates local->scan_ies_len.
00836          */
00837 
00838         /* add any remaining custom IEs */
00839         if (ie && ie_len) {
00840                 noffset = ie_len;
00841                 memcpy(pos, ie + offset, noffset - offset);
00842                 pos += noffset - offset;
00843         }
00844 
00845         return pos - buffer;
00846 }
00847 
00848 struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata,
00849                                           u8 *dst, u32 ratemask,
00850                                           const u8 *ssid, size_t ssid_len,
00851                                           const u8 *ie, size_t ie_len,
00852                                           bool directed)
00853 {
00854         struct ieee80211_local *local = sdata->local;
00855         struct sk_buff *skb;
00856         struct ieee80211_mgmt *mgmt;
00857         size_t buf_len;
00858         u8 *buf;
00859         u8 chan;
00860 
00861         /* FIXME: come up with a proper value */
00862         buf = kmalloc(200 + ie_len, GFP_KERNEL);
00863         if (!buf)
00864                 return NULL;
00865 
00866         /*
00867          * Do not send DS Channel parameter for directed probe requests
00868          * in order to maximize the chance that we get a response.  Some
00869          * badly-behaved APs don't respond when this parameter is included.
00870          */
00871         if (directed)
00872                 chan = 0;
00873         else
00874                 chan = ieee80211_frequency_to_channel(
00875                         local->hw.conf.channel->center_freq);
00876 
00877         buf_len = ieee80211_build_preq_ies(local, buf, ie, ie_len,
00878                                            local->hw.conf.channel->band,
00879                                            ratemask, chan);
00880 
00881         skb = ieee80211_probereq_get(&local->hw, &sdata->vif,
00882                                      ssid, ssid_len,
00883                                      buf, buf_len);
00884         if (!skb)
00885                 goto out;
00886 
00887         if (dst) {
00888                 mgmt = (struct ieee80211_mgmt *) skb->data;
00889                 memcpy(mgmt->da, dst, ETH_ALEN);
00890                 memcpy(mgmt->bssid, dst, ETH_ALEN);
00891         }
00892 
00893         IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
00894 
00895  out:
00896         kfree(buf);
00897 
00898         return skb;
00899 }
00900 
00901 void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
00902                               const u8 *ssid, size_t ssid_len,
00903                               const u8 *ie, size_t ie_len,
00904                               u32 ratemask, bool directed, bool no_cck)
00905 {
00906         struct sk_buff *skb;
00907 
00908         skb = ieee80211_build_probe_req(sdata, dst, ratemask, ssid, ssid_len,
00909                                         ie, ie_len, directed);
00910         if (skb) {
00911                 if (no_cck)
00912                         IEEE80211_SKB_CB(skb)->flags |=
00913                                 IEEE80211_TX_CTL_NO_CCK_RATE;
00914                 ieee80211_tx_skb(sdata, skb);
00915         }
00916 }
00917 
00918 u32 ieee80211_sta_get_rates(struct ieee80211_local *local,
00919                             struct ieee802_11_elems *elems,
00920                             enum ieee80211_band band)
00921 {
00922         struct ieee80211_supported_band *sband;
00923         struct ieee80211_rate *bitrates;
00924         size_t num_rates;
00925         u32 supp_rates;
00926         int i, j;
00927         sband = local->hw.wiphy->bands[band];
00928 
00929         if (!sband) {
00930                 WARN_ON(1);
00931                 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
00932         }
00933 
00934         bitrates = sband->bitrates;
00935         num_rates = sband->n_bitrates;
00936         supp_rates = 0;
00937         for (i = 0; i < elems->supp_rates_len +
00938                      elems->ext_supp_rates_len; i++) {
00939                 u8 rate = 0;
00940                 int own_rate;
00941                 if (i < elems->supp_rates_len)
00942                         rate = elems->supp_rates[i];
00943                 else if (elems->ext_supp_rates)
00944                         rate = elems->ext_supp_rates
00945                                 [i - elems->supp_rates_len];
00946                 own_rate = 5 * (rate & 0x7f);
00947                 for (j = 0; j < num_rates; j++)
00948                         if (bitrates[j].bitrate == own_rate)
00949                                 supp_rates |= BIT(j);
00950         }
00951         return supp_rates;
00952 }
00953 
00954 void ieee80211_stop_device(struct ieee80211_local *local)
00955 {
00956         ieee80211_led_radio(local, false);
00957         ieee80211_mod_tpt_led_trig(local, 0, IEEE80211_TPT_LEDTRIG_FL_RADIO);
00958 
00959         cancel_work_sync(&local->reconfig_filter);
00960 
00961         flush_workqueue(local->workqueue);
00962         drv_stop(local);
00963 }
00964 
00965 int ieee80211_reconfig(struct ieee80211_local *local)
00966 {
00967         struct ieee80211_hw *hw = &local->hw;
00968         struct ieee80211_sub_if_data *sdata;
00969         struct sta_info *sta;
00970         int res, i;
00971 
00972 #ifdef CONFIG_PM
00973         if (local->suspended)
00974                 local->resuming = true;
00975 
00976         if (local->wowlan) {
00977                 local->wowlan = false;
00978                 res = drv_resume(local);
00979                 if (res < 0) {
00980                         local->resuming = false;
00981                         return res;
00982                 }
00983                 if (res == 0)
00984                         goto wake_up;
00985                 WARN_ON(res > 1);
00986                 /*
00987                  * res is 1, which means the driver requested
00988                  * to go through a regular reset on wakeup.
00989                  */
00990         }
00991 #endif
00992 
00993         /* setup fragmentation threshold */
00994         drv_set_frag_threshold(local, hw->wiphy->frag_threshold);
00995 
00996         /* setup RTS threshold */
00997         drv_set_rts_threshold(local, hw->wiphy->rts_threshold);
00998 
00999         /* reset coverage class */
01000         drv_set_coverage_class(local, hw->wiphy->coverage_class);
01001 
01002         /* everything else happens only if HW was up & running */
01003         if (!local->open_count)
01004                 goto wake_up;
01005 
01006         /*
01007          * Upon resume hardware can sometimes be goofy due to
01008          * various platform / driver / bus issues, so restarting
01009          * the device may at times not work immediately. Propagate
01010          * the error.
01011          */
01012         res = drv_start(local);
01013         if (res) {
01014                 WARN(local->suspended, "Hardware became unavailable "
01015                      "upon resume. This could be a software issue "
01016                      "prior to suspend or a hardware issue.\n");
01017                 return res;
01018         }
01019 
01020         ieee80211_led_radio(local, true);
01021         ieee80211_mod_tpt_led_trig(local,
01022                                    IEEE80211_TPT_LEDTRIG_FL_RADIO, 0);
01023 
01024         /* add interfaces */
01025         list_for_each_entry(sdata, &local->interfaces, list) {
01026                 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
01027                     sdata->vif.type != NL80211_IFTYPE_MONITOR &&
01028                     ieee80211_sdata_running(sdata))
01029                         res = drv_add_interface(local, &sdata->vif);
01030         }
01031 
01032         /* add STAs back */
01033         mutex_lock(&local->sta_mtx);
01034         list_for_each_entry(sta, &local->sta_list, list) {
01035                 if (sta->uploaded) {
01036                         sdata = sta->sdata;
01037                         if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
01038                                 sdata = container_of(sdata->bss,
01039                                              struct ieee80211_sub_if_data,
01040                                              u.ap);
01041 
01042                         WARN_ON(drv_sta_add(local, sdata, &sta->sta));
01043                 }
01044         }
01045         mutex_unlock(&local->sta_mtx);
01046 
01047         /* reconfigure tx conf */
01048         list_for_each_entry(sdata, &local->interfaces, list) {
01049                 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
01050                     sdata->vif.type == NL80211_IFTYPE_MONITOR ||
01051                     !ieee80211_sdata_running(sdata))
01052                         continue;
01053 
01054                 for (i = 0; i < hw->queues; i++)
01055                         drv_conf_tx(local, sdata, i, &sdata->tx_conf[i]);
01056         }
01057 
01058         /* reconfigure hardware */
01059         ieee80211_hw_config(local, ~0);
01060 
01061         ieee80211_configure_filter(local);
01062 
01063         /* Finally also reconfigure all the BSS information */
01064         list_for_each_entry(sdata, &local->interfaces, list) {
01065                 u32 changed;
01066 
01067                 if (!ieee80211_sdata_running(sdata))
01068                         continue;
01069 
01070                 /* common change flags for all interface types */
01071                 changed = BSS_CHANGED_ERP_CTS_PROT |
01072                           BSS_CHANGED_ERP_PREAMBLE |
01073                           BSS_CHANGED_ERP_SLOT |
01074                           BSS_CHANGED_HT |
01075                           BSS_CHANGED_BASIC_RATES |
01076                           BSS_CHANGED_BEACON_INT |
01077                           BSS_CHANGED_BSSID |
01078                           BSS_CHANGED_CQM |
01079                           BSS_CHANGED_QOS;
01080 
01081                 switch (sdata->vif.type) {
01082                 case NL80211_IFTYPE_STATION:
01083                         changed |= BSS_CHANGED_ASSOC;
01084                         mutex_lock(&sdata->u.mgd.mtx);
01085                         ieee80211_bss_info_change_notify(sdata, changed);
01086                         mutex_unlock(&sdata->u.mgd.mtx);
01087                         break;
01088                 case NL80211_IFTYPE_ADHOC:
01089                         changed |= BSS_CHANGED_IBSS;
01090                         /* fall through */
01091                 case NL80211_IFTYPE_AP:
01092                         changed |= BSS_CHANGED_SSID;
01093                         /* fall through */
01094                 case NL80211_IFTYPE_MESH_POINT:
01095                         changed |= BSS_CHANGED_BEACON |
01096                                    BSS_CHANGED_BEACON_ENABLED;
01097                         ieee80211_bss_info_change_notify(sdata, changed);
01098                         break;
01099                 case NL80211_IFTYPE_WDS:
01100                         break;
01101                 case NL80211_IFTYPE_AP_VLAN:
01102                 case NL80211_IFTYPE_MONITOR:
01103                         /* ignore virtual */
01104                         break;
01105                 case NL80211_IFTYPE_UNSPECIFIED:
01106                 case NUM_NL80211_IFTYPES:
01107                 case NL80211_IFTYPE_P2P_CLIENT:
01108                 case NL80211_IFTYPE_P2P_GO:
01109                         WARN_ON(1);
01110                         break;
01111                 }
01112         }
01113 
01114         /* add back keys */
01115         list_for_each_entry(sdata, &local->interfaces, list)
01116                 if (ieee80211_sdata_running(sdata))
01117                         ieee80211_enable_keys(sdata);
01118 
01119  wake_up:
01120         /*
01121          * Clear the WLAN_STA_BLOCK_BA flag so new aggregation
01122          * sessions can be established after a resume.
01123          *
01124          * Also tear down aggregation sessions since reconfiguring
01125          * them in a hardware restart scenario is not easily done
01126          * right now, and the hardware will have lost information
01127          * about the sessions, but we and the AP still think they
01128          * are active. This is really a workaround though.
01129          */
01130         if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
01131                 mutex_lock(&local->sta_mtx);
01132 
01133                 list_for_each_entry(sta, &local->sta_list, list) {
01134                         ieee80211_sta_tear_down_BA_sessions(sta, true);
01135                         clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
01136                 }
01137 
01138                 mutex_unlock(&local->sta_mtx);
01139         }
01140 
01141         ieee80211_wake_queues_by_reason(hw,
01142                         IEEE80211_QUEUE_STOP_REASON_SUSPEND);
01143 
01144         /*
01145          * If this is for hw restart things are still running.
01146          * We may want to change that later, however.
01147          */
01148         if (!local->suspended)
01149                 return 0;
01150 
01151 #ifdef CONFIG_PM
01152         /* first set suspended false, then resuming */
01153         local->suspended = false;
01154         mb();
01155         local->resuming = false;
01156 
01157         list_for_each_entry(sdata, &local->interfaces, list) {
01158                 switch(sdata->vif.type) {
01159                 case NL80211_IFTYPE_STATION:
01160                         ieee80211_sta_restart(sdata);
01161                         break;
01162                 case NL80211_IFTYPE_ADHOC:
01163                         ieee80211_ibss_restart(sdata);
01164                         break;
01165                 case NL80211_IFTYPE_MESH_POINT:
01166                         ieee80211_mesh_restart(sdata);
01167                         break;
01168                 default:
01169                         break;
01170                 }
01171         }
01172 
01173         mod_timer(&local->sta_cleanup, jiffies + 1);
01174 
01175         mutex_lock(&local->sta_mtx);
01176         list_for_each_entry(sta, &local->sta_list, list)
01177                 mesh_plink_restart(sta);
01178         mutex_unlock(&local->sta_mtx);
01179 #else
01180         WARN_ON(1);
01181 #endif
01182         return 0;
01183 }
01184 
01185 void ieee80211_resume_disconnect(struct ieee80211_vif *vif)
01186 {
01187         struct ieee80211_sub_if_data *sdata;
01188         struct ieee80211_local *local;
01189         struct ieee80211_key *key;
01190 
01191         if (WARN_ON(!vif))
01192                 return;
01193 
01194         sdata = vif_to_sdata(vif);
01195         local = sdata->local;
01196 
01197         if (WARN_ON(!local->resuming))
01198                 return;
01199 
01200         if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
01201                 return;
01202 
01203         sdata->flags |= IEEE80211_SDATA_DISCONNECT_RESUME;
01204 
01205         mutex_lock(&local->key_mtx);
01206         list_for_each_entry(key, &sdata->key_list, list)
01207                 key->flags |= KEY_FLAG_TAINTED;
01208         mutex_unlock(&local->key_mtx);
01209 }
01210 EXPORT_SYMBOL_GPL(ieee80211_resume_disconnect);
01211 
01212 static int check_mgd_smps(struct ieee80211_if_managed *ifmgd,
01213                           enum ieee80211_smps_mode *smps_mode)
01214 {
01215         if (ifmgd->associated) {
01216                 *smps_mode = ifmgd->ap_smps;
01217 
01218                 if (*smps_mode == IEEE80211_SMPS_AUTOMATIC) {
01219                         if (ifmgd->powersave)
01220                                 *smps_mode = IEEE80211_SMPS_DYNAMIC;
01221                         else
01222                                 *smps_mode = IEEE80211_SMPS_OFF;
01223                 }
01224 
01225                 return 1;
01226         }
01227 
01228         return 0;
01229 }
01230 
01231 /* must hold iflist_mtx */
01232 void ieee80211_recalc_smps(struct ieee80211_local *local)
01233 {
01234         struct ieee80211_sub_if_data *sdata;
01235         enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_OFF;
01236         int count = 0;
01237 
01238         lockdep_assert_held(&local->iflist_mtx);
01239 
01240         /*
01241          * This function could be improved to handle multiple
01242          * interfaces better, but right now it makes any
01243          * non-station interfaces force SM PS to be turned
01244          * off. If there are multiple station interfaces it
01245          * could also use the best possible mode, e.g. if
01246          * one is in static and the other in dynamic then
01247          * dynamic is ok.
01248          */
01249 
01250         list_for_each_entry(sdata, &local->interfaces, list) {
01251                 if (!ieee80211_sdata_running(sdata))
01252                         continue;
01253                 if (sdata->vif.type != NL80211_IFTYPE_STATION)
01254                         goto set;
01255 
01256                 count += check_mgd_smps(&sdata->u.mgd, &smps_mode);
01257 
01258                 if (count > 1) {
01259                         smps_mode = IEEE80211_SMPS_OFF;
01260                         break;
01261                 }
01262         }
01263 
01264         if (smps_mode == local->smps_mode)
01265                 return;
01266 
01267  set:
01268         local->smps_mode = smps_mode;
01269         /* changed flag is auto-detected for this */
01270         ieee80211_hw_config(local, 0);
01271 }
01272 
01273 static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id)
01274 {
01275         int i;
01276 
01277         for (i = 0; i < n_ids; i++)
01278                 if (ids[i] == id)
01279                         return true;
01280         return false;
01281 }
01282 
01308 size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
01309                           const u8 *ids, int n_ids, size_t offset)
01310 {
01311         size_t pos = offset;
01312 
01313         while (pos < ielen && ieee80211_id_in_list(ids, n_ids, ies[pos]))
01314                 pos += 2 + ies[pos + 1];
01315 
01316         return pos;
01317 }
01318 
01319 size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset)
01320 {
01321         size_t pos = offset;
01322 
01323         while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC)
01324                 pos += 2 + ies[pos + 1];
01325 
01326         return pos;
01327 }
01328 
01329 static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
01330                                             int rssi_min_thold,
01331                                             int rssi_max_thold)
01332 {
01333         trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
01334 
01335         if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
01336                 return;
01337 
01338         /*
01339          * Scale up threshold values before storing it, as the RSSI averaging
01340          * algorithm uses a scaled up value as well. Change this scaling
01341          * factor if the RSSI averaging algorithm changes.
01342          */
01343         sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
01344         sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
01345 }
01346 
01347 void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
01348                                     int rssi_min_thold,
01349                                     int rssi_max_thold)
01350 {
01351         struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
01352 
01353         WARN_ON(rssi_min_thold == rssi_max_thold ||
01354                 rssi_min_thold > rssi_max_thold);
01355 
01356         _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
01357                                        rssi_max_thold);
01358 }
01359 EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
01360 
01361 void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
01362 {
01363         struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
01364 
01365         _ieee80211_enable_rssi_reports(sdata, 0, 0);
01366 }
01367 EXPORT_SYMBOL(ieee80211_disable_rssi_reports);
01368 
01369 int ieee80211_add_srates_ie(struct ieee80211_vif *vif, struct sk_buff *skb)
01370 {
01371         struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
01372         struct ieee80211_local *local = sdata->local;
01373         struct ieee80211_supported_band *sband;
01374         int rate;
01375         u8 i, rates, *pos;
01376 
01377         sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
01378         rates = sband->n_bitrates;
01379         if (rates > 8)
01380                 rates = 8;
01381 
01382         if (skb_tailroom(skb) < rates + 2)
01383                 return -ENOMEM;
01384 
01385         pos = skb_put(skb, rates + 2);
01386         *pos++ = WLAN_EID_SUPP_RATES;
01387         *pos++ = rates;
01388         for (i = 0; i < rates; i++) {
01389                 rate = sband->bitrates[i].bitrate;
01390                 *pos++ = (u8) (rate / 5);
01391         }
01392 
01393         return 0;
01394 }
01395 
01396 int ieee80211_add_ext_srates_ie(struct ieee80211_vif *vif, struct sk_buff *skb)
01397 {
01398         struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
01399         struct ieee80211_local *local = sdata->local;
01400         struct ieee80211_supported_band *sband;
01401         int rate;
01402         u8 i, exrates, *pos;
01403 
01404         sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
01405         exrates = sband->n_bitrates;
01406         if (exrates > 8)
01407                 exrates -= 8;
01408         else
01409                 exrates = 0;
01410 
01411         if (skb_tailroom(skb) < exrates + 2)
01412                 return -ENOMEM;
01413 
01414         if (exrates) {
01415                 pos = skb_put(skb, exrates + 2);
01416                 *pos++ = WLAN_EID_EXT_SUPP_RATES;
01417                 *pos++ = exrates;
01418                 for (i = 8; i < sband->n_bitrates; i++) {
01419                         rate = sband->bitrates[i].bitrate;
01420                         *pos++ = (u8) (rate / 5);
01421                 }
01422         }
01423         return 0;
01424 }


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Fri Jan 3 2014 12:07:56