tx.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  *
00012  * Transmit and frame generation functions.
00013  */
00014 
00015 #include <linux/kernel.h>
00016 #include <linux/slab.h>
00017 #include <linux/skbuff.h>
00018 #include <linux/etherdevice.h>
00019 #include <linux/bitmap.h>
00020 #include <linux/rcupdate.h>
00021 #include <linux/export.h>
00022 #include <net/net_namespace.h>
00023 #include <net/ieee80211_radiotap.h>
00024 #include <net/cfg80211.h>
00025 #include <net/mac80211.h>
00026 #include <asm/unaligned.h>
00027 
00028 #include "ieee80211_i.h"
00029 #include "driver-ops.h"
00030 #include "led.h"
00031 #include "mesh.h"
00032 #include "wep.h"
00033 #include "wpa.h"
00034 #include "wme.h"
00035 #include "rate.h"
00036 
00037 /* misc utils */
00038 
00039 static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
00040                                  int next_frag_len)
00041 {
00042         int rate, mrate, erp, dur, i;
00043         struct ieee80211_rate *txrate;
00044         struct ieee80211_local *local = tx->local;
00045         struct ieee80211_supported_band *sband;
00046         struct ieee80211_hdr *hdr;
00047         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00048 
00049         /* assume HW handles this */
00050         if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
00051                 return 0;
00052 
00053         /* uh huh? */
00054         if (WARN_ON_ONCE(info->control.rates[0].idx < 0))
00055                 return 0;
00056 
00057         sband = local->hw.wiphy->bands[tx->channel->band];
00058         txrate = &sband->bitrates[info->control.rates[0].idx];
00059 
00060         erp = txrate->flags & IEEE80211_RATE_ERP_G;
00061 
00062         /*
00063          * data and mgmt (except PS Poll):
00064          * - during CFP: 32768
00065          * - during contention period:
00066          *   if addr1 is group address: 0
00067          *   if more fragments = 0 and addr1 is individual address: time to
00068          *      transmit one ACK plus SIFS
00069          *   if more fragments = 1 and addr1 is individual address: time to
00070          *      transmit next fragment plus 2 x ACK plus 3 x SIFS
00071          *
00072          * IEEE 802.11, 9.6:
00073          * - control response frame (CTS or ACK) shall be transmitted using the
00074          *   same rate as the immediately previous frame in the frame exchange
00075          *   sequence, if this rate belongs to the PHY mandatory rates, or else
00076          *   at the highest possible rate belonging to the PHY rates in the
00077          *   BSSBasicRateSet
00078          */
00079         hdr = (struct ieee80211_hdr *)tx->skb->data;
00080         if (ieee80211_is_ctl(hdr->frame_control)) {
00081                 /* TODO: These control frames are not currently sent by
00082                  * mac80211, but should they be implemented, this function
00083                  * needs to be updated to support duration field calculation.
00084                  *
00085                  * RTS: time needed to transmit pending data/mgmt frame plus
00086                  *    one CTS frame plus one ACK frame plus 3 x SIFS
00087                  * CTS: duration of immediately previous RTS minus time
00088                  *    required to transmit CTS and its SIFS
00089                  * ACK: 0 if immediately previous directed data/mgmt had
00090                  *    more=0, with more=1 duration in ACK frame is duration
00091                  *    from previous frame minus time needed to transmit ACK
00092                  *    and its SIFS
00093                  * PS Poll: BIT(15) | BIT(14) | aid
00094                  */
00095                 return 0;
00096         }
00097 
00098         /* data/mgmt */
00099         if (0 /* FIX: data/mgmt during CFP */)
00100                 return cpu_to_le16(32768);
00101 
00102         if (group_addr) /* Group address as the destination - no ACK */
00103                 return 0;
00104 
00105         /* Individual destination address:
00106          * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
00107          * CTS and ACK frames shall be transmitted using the highest rate in
00108          * basic rate set that is less than or equal to the rate of the
00109          * immediately previous frame and that is using the same modulation
00110          * (CCK or OFDM). If no basic rate set matches with these requirements,
00111          * the highest mandatory rate of the PHY that is less than or equal to
00112          * the rate of the previous frame is used.
00113          * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
00114          */
00115         rate = -1;
00116         /* use lowest available if everything fails */
00117         mrate = sband->bitrates[0].bitrate;
00118         for (i = 0; i < sband->n_bitrates; i++) {
00119                 struct ieee80211_rate *r = &sband->bitrates[i];
00120 
00121                 if (r->bitrate > txrate->bitrate)
00122                         break;
00123 
00124                 if (tx->sdata->vif.bss_conf.basic_rates & BIT(i))
00125                         rate = r->bitrate;
00126 
00127                 switch (sband->band) {
00128                 case IEEE80211_BAND_2GHZ: {
00129                         u32 flag;
00130                         if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
00131                                 flag = IEEE80211_RATE_MANDATORY_G;
00132                         else
00133                                 flag = IEEE80211_RATE_MANDATORY_B;
00134                         if (r->flags & flag)
00135                                 mrate = r->bitrate;
00136                         break;
00137                 }
00138                 case IEEE80211_BAND_5GHZ:
00139                         if (r->flags & IEEE80211_RATE_MANDATORY_A)
00140                                 mrate = r->bitrate;
00141                         break;
00142                 case IEEE80211_NUM_BANDS:
00143                         WARN_ON(1);
00144                         break;
00145                 }
00146         }
00147         if (rate == -1) {
00148                 /* No matching basic rate found; use highest suitable mandatory
00149                  * PHY rate */
00150                 rate = mrate;
00151         }
00152 
00153         /* Time needed to transmit ACK
00154          * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
00155          * to closest integer */
00156 
00157         dur = ieee80211_frame_duration(local, 10, rate, erp,
00158                                 tx->sdata->vif.bss_conf.use_short_preamble);
00159 
00160         if (next_frag_len) {
00161                 /* Frame is fragmented: duration increases with time needed to
00162                  * transmit next fragment plus ACK and 2 x SIFS. */
00163                 dur *= 2; /* ACK + SIFS */
00164                 /* next fragment */
00165                 dur += ieee80211_frame_duration(local, next_frag_len,
00166                                 txrate->bitrate, erp,
00167                                 tx->sdata->vif.bss_conf.use_short_preamble);
00168         }
00169 
00170         return cpu_to_le16(dur);
00171 }
00172 
00173 static inline int is_ieee80211_device(struct ieee80211_local *local,
00174                                       struct net_device *dev)
00175 {
00176         return local == wdev_priv(dev->ieee80211_ptr);
00177 }
00178 
00179 /* tx handlers */
00180 static ieee80211_tx_result debug_noinline
00181 ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx)
00182 {
00183         struct ieee80211_local *local = tx->local;
00184         struct ieee80211_if_managed *ifmgd;
00185 
00186         /* driver doesn't support power save */
00187         if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
00188                 return TX_CONTINUE;
00189 
00190         /* hardware does dynamic power save */
00191         if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
00192                 return TX_CONTINUE;
00193 
00194         /* dynamic power save disabled */
00195         if (local->hw.conf.dynamic_ps_timeout <= 0)
00196                 return TX_CONTINUE;
00197 
00198         /* we are scanning, don't enable power save */
00199         if (local->scanning)
00200                 return TX_CONTINUE;
00201 
00202         if (!local->ps_sdata)
00203                 return TX_CONTINUE;
00204 
00205         /* No point if we're going to suspend */
00206         if (local->quiescing)
00207                 return TX_CONTINUE;
00208 
00209         /* dynamic ps is supported only in managed mode */
00210         if (tx->sdata->vif.type != NL80211_IFTYPE_STATION)
00211                 return TX_CONTINUE;
00212 
00213         ifmgd = &tx->sdata->u.mgd;
00214 
00215         /*
00216          * Don't wakeup from power save if u-apsd is enabled, voip ac has
00217          * u-apsd enabled and the frame is in voip class. This effectively
00218          * means that even if all access categories have u-apsd enabled, in
00219          * practise u-apsd is only used with the voip ac. This is a
00220          * workaround for the case when received voip class packets do not
00221          * have correct qos tag for some reason, due the network or the
00222          * peer application.
00223          *
00224          * Note: local->uapsd_queues access is racy here. If the value is
00225          * changed via debugfs, user needs to reassociate manually to have
00226          * everything in sync.
00227          */
00228         if ((ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
00229             && (local->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
00230             && skb_get_queue_mapping(tx->skb) == 0)
00231                 return TX_CONTINUE;
00232 
00233         if (local->hw.conf.flags & IEEE80211_CONF_PS) {
00234                 ieee80211_stop_queues_by_reason(&local->hw,
00235                                                 IEEE80211_QUEUE_STOP_REASON_PS);
00236                 ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
00237                 ieee80211_queue_work(&local->hw,
00238                                      &local->dynamic_ps_disable_work);
00239         }
00240 
00241         /* Don't restart the timer if we're not disassociated */
00242         if (!ifmgd->associated)
00243                 return TX_CONTINUE;
00244 
00245         mod_timer(&local->dynamic_ps_timer, jiffies +
00246                   msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
00247 
00248         return TX_CONTINUE;
00249 }
00250 
00251 static ieee80211_tx_result debug_noinline
00252 ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
00253 {
00254 
00255         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
00256         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00257         bool assoc = false;
00258 
00259         if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED))
00260                 return TX_CONTINUE;
00261 
00262         if (unlikely(test_bit(SCAN_OFF_CHANNEL, &tx->local->scanning)) &&
00263             !ieee80211_is_probe_req(hdr->frame_control) &&
00264             !ieee80211_is_nullfunc(hdr->frame_control))
00265                 /*
00266                  * When software scanning only nullfunc frames (to notify
00267                  * the sleep state to the AP) and probe requests (for the
00268                  * active scan) are allowed, all other frames should not be
00269                  * sent and we should not get here, but if we do
00270                  * nonetheless, drop them to avoid sending them
00271                  * off-channel. See the link below and
00272                  * ieee80211_start_scan() for more.
00273                  *
00274                  * http://article.gmane.org/gmane.linux.kernel.wireless.general/30089
00275                  */
00276                 return TX_DROP;
00277 
00278         if (tx->sdata->vif.type == NL80211_IFTYPE_WDS)
00279                 return TX_CONTINUE;
00280 
00281         if (tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
00282                 return TX_CONTINUE;
00283 
00284         if (tx->flags & IEEE80211_TX_PS_BUFFERED)
00285                 return TX_CONTINUE;
00286 
00287         if (tx->sta)
00288                 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
00289 
00290         if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
00291                 if (unlikely(!assoc &&
00292                              tx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
00293                              ieee80211_is_data(hdr->frame_control))) {
00294 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
00295                         printk(KERN_DEBUG "%s: dropped data frame to not "
00296                                "associated station %pM\n",
00297                                tx->sdata->name, hdr->addr1);
00298 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
00299                         I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
00300                         return TX_DROP;
00301                 }
00302         } else {
00303                 if (unlikely(ieee80211_is_data(hdr->frame_control) &&
00304                              tx->local->num_sta == 0 &&
00305                              tx->sdata->vif.type != NL80211_IFTYPE_ADHOC)) {
00306                         /*
00307                          * No associated STAs - no need to send multicast
00308                          * frames.
00309                          */
00310                         return TX_DROP;
00311                 }
00312                 return TX_CONTINUE;
00313         }
00314 
00315         return TX_CONTINUE;
00316 }
00317 
00318 /* This function is called whenever the AP is about to exceed the maximum limit
00319  * of buffered frames for power saving STAs. This situation should not really
00320  * happen often during normal operation, so dropping the oldest buffered packet
00321  * from each queue should be OK to make some room for new frames. */
00322 static void purge_old_ps_buffers(struct ieee80211_local *local)
00323 {
00324         int total = 0, purged = 0;
00325         struct sk_buff *skb;
00326         struct ieee80211_sub_if_data *sdata;
00327         struct sta_info *sta;
00328 
00329         /*
00330          * virtual interfaces are protected by RCU
00331          */
00332         rcu_read_lock();
00333 
00334         list_for_each_entry_rcu(sdata, &local->interfaces, list) {
00335                 struct ieee80211_if_ap *ap;
00336                 if (sdata->vif.type != NL80211_IFTYPE_AP)
00337                         continue;
00338                 ap = &sdata->u.ap;
00339                 skb = skb_dequeue(&ap->ps_bc_buf);
00340                 if (skb) {
00341                         purged++;
00342                         dev_kfree_skb(skb);
00343                 }
00344                 total += skb_queue_len(&ap->ps_bc_buf);
00345         }
00346 
00347         /*
00348          * Drop one frame from each station from the lowest-priority
00349          * AC that has frames at all.
00350          */
00351         list_for_each_entry_rcu(sta, &local->sta_list, list) {
00352                 int ac;
00353 
00354                 for (ac = IEEE80211_AC_BK; ac >= IEEE80211_AC_VO; ac--) {
00355                         skb = skb_dequeue(&sta->ps_tx_buf[ac]);
00356                         total += skb_queue_len(&sta->ps_tx_buf[ac]);
00357                         if (skb) {
00358                                 purged++;
00359                                 dev_kfree_skb(skb);
00360                                 break;
00361                         }
00362                 }
00363         }
00364 
00365         rcu_read_unlock();
00366 
00367         local->total_ps_buffered = total;
00368 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
00369         wiphy_debug(local->hw.wiphy, "PS buffers full - purged %d frames\n",
00370                     purged);
00371 #endif
00372 }
00373 
00374 static ieee80211_tx_result
00375 ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
00376 {
00377         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00378         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
00379 
00380         /*
00381          * broadcast/multicast frame
00382          *
00383          * If any of the associated stations is in power save mode,
00384          * the frame is buffered to be sent after DTIM beacon frame.
00385          * This is done either by the hardware or us.
00386          */
00387 
00388         /* powersaving STAs only in AP/VLAN mode */
00389         if (!tx->sdata->bss)
00390                 return TX_CONTINUE;
00391 
00392         /* no buffering for ordered frames */
00393         if (ieee80211_has_order(hdr->frame_control))
00394                 return TX_CONTINUE;
00395 
00396         /* no stations in PS mode */
00397         if (!atomic_read(&tx->sdata->bss->num_sta_ps))
00398                 return TX_CONTINUE;
00399 
00400         info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM;
00401 
00402         /* device releases frame after DTIM beacon */
00403         if (!(tx->local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING))
00404                 return TX_CONTINUE;
00405 
00406         /* buffered in mac80211 */
00407         if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
00408                 purge_old_ps_buffers(tx->local);
00409 
00410         if (skb_queue_len(&tx->sdata->bss->ps_bc_buf) >= AP_MAX_BC_BUFFER) {
00411 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
00412                 if (net_ratelimit())
00413                         printk(KERN_DEBUG "%s: BC TX buffer full - dropping the oldest frame\n",
00414                                tx->sdata->name);
00415 #endif
00416                 dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf));
00417         } else
00418                 tx->local->total_ps_buffered++;
00419 
00420         skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb);
00421 
00422         return TX_QUEUED;
00423 }
00424 
00425 static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta,
00426                              struct sk_buff *skb)
00427 {
00428         if (!ieee80211_is_mgmt(fc))
00429                 return 0;
00430 
00431         if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP))
00432                 return 0;
00433 
00434         if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *)
00435                                             skb->data))
00436                 return 0;
00437 
00438         return 1;
00439 }
00440 
00441 static ieee80211_tx_result
00442 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
00443 {
00444         struct sta_info *sta = tx->sta;
00445         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00446         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
00447         struct ieee80211_local *local = tx->local;
00448 
00449         if (unlikely(!sta ||
00450                      ieee80211_is_probe_resp(hdr->frame_control) ||
00451                      ieee80211_is_auth(hdr->frame_control) ||
00452                      ieee80211_is_assoc_resp(hdr->frame_control) ||
00453                      ieee80211_is_reassoc_resp(hdr->frame_control)))
00454                 return TX_CONTINUE;
00455 
00456         if (unlikely((test_sta_flag(sta, WLAN_STA_PS_STA) ||
00457                       test_sta_flag(sta, WLAN_STA_PS_DRIVER)) &&
00458                      !(info->flags & IEEE80211_TX_CTL_POLL_RESPONSE))) {
00459                 int ac = skb_get_queue_mapping(tx->skb);
00460 
00461 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
00462                 printk(KERN_DEBUG "STA %pM aid %d: PS buffer for AC %d\n",
00463                        sta->sta.addr, sta->sta.aid, ac);
00464 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
00465                 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
00466                         purge_old_ps_buffers(tx->local);
00467                 if (skb_queue_len(&sta->ps_tx_buf[ac]) >= STA_MAX_TX_BUFFER) {
00468                         struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf[ac]);
00469 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
00470                         if (net_ratelimit())
00471                                 printk(KERN_DEBUG "%s: STA %pM TX buffer for "
00472                                        "AC %d full - dropping oldest frame\n",
00473                                        tx->sdata->name, sta->sta.addr, ac);
00474 #endif
00475                         dev_kfree_skb(old);
00476                 } else
00477                         tx->local->total_ps_buffered++;
00478 
00479                 info->control.jiffies = jiffies;
00480                 info->control.vif = &tx->sdata->vif;
00481                 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
00482                 skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb);
00483 
00484                 if (!timer_pending(&local->sta_cleanup))
00485                         mod_timer(&local->sta_cleanup,
00486                                   round_jiffies(jiffies +
00487                                                 STA_INFO_CLEANUP_INTERVAL));
00488 
00489                 /*
00490                  * We queued up some frames, so the TIM bit might
00491                  * need to be set, recalculate it.
00492                  */
00493                 sta_info_recalc_tim(sta);
00494 
00495                 return TX_QUEUED;
00496         }
00497 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
00498         else if (unlikely(test_sta_flag(sta, WLAN_STA_PS_STA))) {
00499                 printk(KERN_DEBUG
00500                        "%s: STA %pM in PS mode, but polling/in SP -> send frame\n",
00501                        tx->sdata->name, sta->sta.addr);
00502         }
00503 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
00504 
00505         return TX_CONTINUE;
00506 }
00507 
00508 static ieee80211_tx_result debug_noinline
00509 ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
00510 {
00511         if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED))
00512                 return TX_CONTINUE;
00513 
00514         if (tx->flags & IEEE80211_TX_UNICAST)
00515                 return ieee80211_tx_h_unicast_ps_buf(tx);
00516         else
00517                 return ieee80211_tx_h_multicast_ps_buf(tx);
00518 }
00519 
00520 static ieee80211_tx_result debug_noinline
00521 ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data *tx)
00522 {
00523         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00524 
00525         if (unlikely(tx->sdata->control_port_protocol == tx->skb->protocol &&
00526                      tx->sdata->control_port_no_encrypt))
00527                 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
00528 
00529         return TX_CONTINUE;
00530 }
00531 
00532 static ieee80211_tx_result debug_noinline
00533 ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
00534 {
00535         struct ieee80211_key *key = NULL;
00536         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00537         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
00538 
00539         if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT))
00540                 tx->key = NULL;
00541         else if (tx->sta && (key = rcu_dereference(tx->sta->ptk)))
00542                 tx->key = key;
00543         else if (ieee80211_is_mgmt(hdr->frame_control) &&
00544                  is_multicast_ether_addr(hdr->addr1) &&
00545                  ieee80211_is_robust_mgmt_frame(hdr) &&
00546                  (key = rcu_dereference(tx->sdata->default_mgmt_key)))
00547                 tx->key = key;
00548         else if (is_multicast_ether_addr(hdr->addr1) &&
00549                  (key = rcu_dereference(tx->sdata->default_multicast_key)))
00550                 tx->key = key;
00551         else if (!is_multicast_ether_addr(hdr->addr1) &&
00552                  (key = rcu_dereference(tx->sdata->default_unicast_key)))
00553                 tx->key = key;
00554         else if (tx->sdata->drop_unencrypted &&
00555                  (tx->skb->protocol != tx->sdata->control_port_protocol) &&
00556                  !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
00557                  (!ieee80211_is_robust_mgmt_frame(hdr) ||
00558                   (ieee80211_is_action(hdr->frame_control) &&
00559                    tx->sta && test_sta_flag(tx->sta, WLAN_STA_MFP)))) {
00560                 I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
00561                 return TX_DROP;
00562         } else
00563                 tx->key = NULL;
00564 
00565         if (tx->key) {
00566                 bool skip_hw = false;
00567 
00568                 tx->key->tx_rx_count++;
00569                 /* TODO: add threshold stuff again */
00570 
00571                 switch (tx->key->conf.cipher) {
00572                 case WLAN_CIPHER_SUITE_WEP40:
00573                 case WLAN_CIPHER_SUITE_WEP104:
00574                         if (ieee80211_is_auth(hdr->frame_control))
00575                                 break;
00576                 case WLAN_CIPHER_SUITE_TKIP:
00577                         if (!ieee80211_is_data_present(hdr->frame_control))
00578                                 tx->key = NULL;
00579                         break;
00580                 case WLAN_CIPHER_SUITE_CCMP:
00581                         if (!ieee80211_is_data_present(hdr->frame_control) &&
00582                             !ieee80211_use_mfp(hdr->frame_control, tx->sta,
00583                                                tx->skb))
00584                                 tx->key = NULL;
00585                         else
00586                                 skip_hw = (tx->key->conf.flags &
00587                                            IEEE80211_KEY_FLAG_SW_MGMT) &&
00588                                         ieee80211_is_mgmt(hdr->frame_control);
00589                         break;
00590                 case WLAN_CIPHER_SUITE_AES_CMAC:
00591                         if (!ieee80211_is_mgmt(hdr->frame_control))
00592                                 tx->key = NULL;
00593                         break;
00594                 }
00595 
00596                 if (unlikely(tx->key && tx->key->flags & KEY_FLAG_TAINTED))
00597                         return TX_DROP;
00598 
00599                 if (!skip_hw && tx->key &&
00600                     tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
00601                         info->control.hw_key = &tx->key->conf;
00602         }
00603 
00604         return TX_CONTINUE;
00605 }
00606 
00607 static ieee80211_tx_result debug_noinline
00608 ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
00609 {
00610         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00611         struct ieee80211_hdr *hdr = (void *)tx->skb->data;
00612         struct ieee80211_supported_band *sband;
00613         struct ieee80211_rate *rate;
00614         int i;
00615         u32 len;
00616         bool inval = false, rts = false, short_preamble = false;
00617         struct ieee80211_tx_rate_control txrc;
00618         bool assoc = false;
00619 
00620         memset(&txrc, 0, sizeof(txrc));
00621 
00622         sband = tx->local->hw.wiphy->bands[tx->channel->band];
00623 
00624         len = min_t(u32, tx->skb->len + FCS_LEN,
00625                          tx->local->hw.wiphy->frag_threshold);
00626 
00627         /* set up the tx rate control struct we give the RC algo */
00628         txrc.hw = local_to_hw(tx->local);
00629         txrc.sband = sband;
00630         txrc.bss_conf = &tx->sdata->vif.bss_conf;
00631         txrc.skb = tx->skb;
00632         txrc.reported_rate.idx = -1;
00633         txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[tx->channel->band];
00634         if (txrc.rate_idx_mask == (1 << sband->n_bitrates) - 1)
00635                 txrc.max_rate_idx = -1;
00636         else
00637                 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
00638         txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
00639                     tx->sdata->vif.type == NL80211_IFTYPE_ADHOC);
00640 
00641         /* set up RTS protection if desired */
00642         if (len > tx->local->hw.wiphy->rts_threshold) {
00643                 txrc.rts = rts = true;
00644         }
00645 
00646         /*
00647          * Use short preamble if the BSS can handle it, but not for
00648          * management frames unless we know the receiver can handle
00649          * that -- the management frame might be to a station that
00650          * just wants a probe response.
00651          */
00652         if (tx->sdata->vif.bss_conf.use_short_preamble &&
00653             (ieee80211_is_data(hdr->frame_control) ||
00654              (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
00655                 txrc.short_preamble = short_preamble = true;
00656 
00657         if (tx->sta)
00658                 assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
00659 
00660         /*
00661          * Lets not bother rate control if we're associated and cannot
00662          * talk to the sta. This should not happen.
00663          */
00664         if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc &&
00665                  !rate_usable_index_exists(sband, &tx->sta->sta),
00666                  "%s: Dropped data frame as no usable bitrate found while "
00667                  "scanning and associated. Target station: "
00668                  "%pM on %d GHz band\n",
00669                  tx->sdata->name, hdr->addr1,
00670                  tx->channel->band ? 5 : 2))
00671                 return TX_DROP;
00672 
00673         /*
00674          * If we're associated with the sta at this point we know we can at
00675          * least send the frame at the lowest bit rate.
00676          */
00677         rate_control_get_rate(tx->sdata, tx->sta, &txrc);
00678 
00679         if (unlikely(info->control.rates[0].idx < 0))
00680                 return TX_DROP;
00681 
00682         if (txrc.reported_rate.idx < 0) {
00683                 txrc.reported_rate = info->control.rates[0];
00684                 if (tx->sta && ieee80211_is_data(hdr->frame_control))
00685                         tx->sta->last_tx_rate = txrc.reported_rate;
00686         } else if (tx->sta)
00687                 tx->sta->last_tx_rate = txrc.reported_rate;
00688 
00689         if (unlikely(!info->control.rates[0].count))
00690                 info->control.rates[0].count = 1;
00691 
00692         if (WARN_ON_ONCE((info->control.rates[0].count > 1) &&
00693                          (info->flags & IEEE80211_TX_CTL_NO_ACK)))
00694                 info->control.rates[0].count = 1;
00695 
00696         if (is_multicast_ether_addr(hdr->addr1)) {
00697                 /*
00698                  * XXX: verify the rate is in the basic rateset
00699                  */
00700                 return TX_CONTINUE;
00701         }
00702 
00703         /*
00704          * set up the RTS/CTS rate as the fastest basic rate
00705          * that is not faster than the data rate
00706          *
00707          * XXX: Should this check all retry rates?
00708          */
00709         if (!(info->control.rates[0].flags & IEEE80211_TX_RC_MCS)) {
00710                 s8 baserate = 0;
00711 
00712                 rate = &sband->bitrates[info->control.rates[0].idx];
00713 
00714                 for (i = 0; i < sband->n_bitrates; i++) {
00715                         /* must be a basic rate */
00716                         if (!(tx->sdata->vif.bss_conf.basic_rates & BIT(i)))
00717                                 continue;
00718                         /* must not be faster than the data rate */
00719                         if (sband->bitrates[i].bitrate > rate->bitrate)
00720                                 continue;
00721                         /* maximum */
00722                         if (sband->bitrates[baserate].bitrate <
00723                              sband->bitrates[i].bitrate)
00724                                 baserate = i;
00725                 }
00726 
00727                 info->control.rts_cts_rate_idx = baserate;
00728         }
00729 
00730         for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
00731                 /*
00732                  * make sure there's no valid rate following
00733                  * an invalid one, just in case drivers don't
00734                  * take the API seriously to stop at -1.
00735                  */
00736                 if (inval) {
00737                         info->control.rates[i].idx = -1;
00738                         continue;
00739                 }
00740                 if (info->control.rates[i].idx < 0) {
00741                         inval = true;
00742                         continue;
00743                 }
00744 
00745                 /*
00746                  * For now assume MCS is already set up correctly, this
00747                  * needs to be fixed.
00748                  */
00749                 if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) {
00750                         WARN_ON(info->control.rates[i].idx > 76);
00751                         continue;
00752                 }
00753 
00754                 /* set up RTS protection if desired */
00755                 if (rts)
00756                         info->control.rates[i].flags |=
00757                                 IEEE80211_TX_RC_USE_RTS_CTS;
00758 
00759                 /* RC is busted */
00760                 if (WARN_ON_ONCE(info->control.rates[i].idx >=
00761                                  sband->n_bitrates)) {
00762                         info->control.rates[i].idx = -1;
00763                         continue;
00764                 }
00765 
00766                 rate = &sband->bitrates[info->control.rates[i].idx];
00767 
00768                 /* set up short preamble */
00769                 if (short_preamble &&
00770                     rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
00771                         info->control.rates[i].flags |=
00772                                 IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
00773 
00774                 /* set up G protection */
00775                 if (!rts && tx->sdata->vif.bss_conf.use_cts_prot &&
00776                     rate->flags & IEEE80211_RATE_ERP_G)
00777                         info->control.rates[i].flags |=
00778                                 IEEE80211_TX_RC_USE_CTS_PROTECT;
00779         }
00780 
00781         return TX_CONTINUE;
00782 }
00783 
00784 static ieee80211_tx_result debug_noinline
00785 ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
00786 {
00787         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00788         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
00789         u16 *seq;
00790         u8 *qc;
00791         int tid;
00792 
00793         /*
00794          * Packet injection may want to control the sequence
00795          * number, if we have no matching interface then we
00796          * neither assign one ourselves nor ask the driver to.
00797          */
00798         if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR))
00799                 return TX_CONTINUE;
00800 
00801         if (unlikely(ieee80211_is_ctl(hdr->frame_control)))
00802                 return TX_CONTINUE;
00803 
00804         if (ieee80211_hdrlen(hdr->frame_control) < 24)
00805                 return TX_CONTINUE;
00806 
00807         if (ieee80211_is_qos_nullfunc(hdr->frame_control))
00808                 return TX_CONTINUE;
00809 
00810         /*
00811          * Anything but QoS data that has a sequence number field
00812          * (is long enough) gets a sequence number from the global
00813          * counter.
00814          */
00815         if (!ieee80211_is_data_qos(hdr->frame_control)) {
00816                 /* driver should assign sequence number */
00817                 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
00818                 /* for pure STA mode without beacons, we can do it */
00819                 hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number);
00820                 tx->sdata->sequence_number += 0x10;
00821                 return TX_CONTINUE;
00822         }
00823 
00824         /*
00825          * This should be true for injected/management frames only, for
00826          * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ
00827          * above since they are not QoS-data frames.
00828          */
00829         if (!tx->sta)
00830                 return TX_CONTINUE;
00831 
00832         /* include per-STA, per-TID sequence counter */
00833 
00834         qc = ieee80211_get_qos_ctl(hdr);
00835         tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
00836         seq = &tx->sta->tid_seq[tid];
00837 
00838         hdr->seq_ctrl = cpu_to_le16(*seq);
00839 
00840         /* Increase the sequence number. */
00841         *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ;
00842 
00843         return TX_CONTINUE;
00844 }
00845 
00846 static int ieee80211_fragment(struct ieee80211_local *local,
00847                               struct sk_buff *skb, int hdrlen,
00848                               int frag_threshold)
00849 {
00850         struct sk_buff *tail = skb, *tmp;
00851         int per_fragm = frag_threshold - hdrlen - FCS_LEN;
00852         int pos = hdrlen + per_fragm;
00853         int rem = skb->len - hdrlen - per_fragm;
00854 
00855         if (WARN_ON(rem < 0))
00856                 return -EINVAL;
00857 
00858         while (rem) {
00859                 int fraglen = per_fragm;
00860 
00861                 if (fraglen > rem)
00862                         fraglen = rem;
00863                 rem -= fraglen;
00864                 tmp = dev_alloc_skb(local->tx_headroom +
00865                                     frag_threshold +
00866                                     IEEE80211_ENCRYPT_HEADROOM +
00867                                     IEEE80211_ENCRYPT_TAILROOM);
00868                 if (!tmp)
00869                         return -ENOMEM;
00870                 tail->next = tmp;
00871                 tail = tmp;
00872                 skb_reserve(tmp, local->tx_headroom +
00873                                  IEEE80211_ENCRYPT_HEADROOM);
00874                 /* copy control information */
00875                 memcpy(tmp->cb, skb->cb, sizeof(tmp->cb));
00876                 skb_copy_queue_mapping(tmp, skb);
00877                 tmp->priority = skb->priority;
00878                 tmp->dev = skb->dev;
00879 
00880                 /* copy header and data */
00881                 memcpy(skb_put(tmp, hdrlen), skb->data, hdrlen);
00882                 memcpy(skb_put(tmp, fraglen), skb->data + pos, fraglen);
00883 
00884                 pos += fraglen;
00885         }
00886 
00887         skb->len = hdrlen + per_fragm;
00888         return 0;
00889 }
00890 
00891 static ieee80211_tx_result debug_noinline
00892 ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
00893 {
00894         struct sk_buff *skb = tx->skb;
00895         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
00896         struct ieee80211_hdr *hdr = (void *)skb->data;
00897         int frag_threshold = tx->local->hw.wiphy->frag_threshold;
00898         int hdrlen;
00899         int fragnum;
00900 
00901         if (info->flags & IEEE80211_TX_CTL_DONTFRAG)
00902                 return TX_CONTINUE;
00903 
00904         if (tx->local->ops->set_frag_threshold)
00905                 return TX_CONTINUE;
00906 
00907         /*
00908          * Warn when submitting a fragmented A-MPDU frame and drop it.
00909          * This scenario is handled in ieee80211_tx_prepare but extra
00910          * caution taken here as fragmented ampdu may cause Tx stop.
00911          */
00912         if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
00913                 return TX_DROP;
00914 
00915         hdrlen = ieee80211_hdrlen(hdr->frame_control);
00916 
00917         /* internal error, why isn't DONTFRAG set? */
00918         if (WARN_ON(skb->len + FCS_LEN <= frag_threshold))
00919                 return TX_DROP;
00920 
00921         /*
00922          * Now fragment the frame. This will allocate all the fragments and
00923          * chain them (using skb as the first fragment) to skb->next.
00924          * During transmission, we will remove the successfully transmitted
00925          * fragments from this list. When the low-level driver rejects one
00926          * of the fragments then we will simply pretend to accept the skb
00927          * but store it away as pending.
00928          */
00929         if (ieee80211_fragment(tx->local, skb, hdrlen, frag_threshold))
00930                 return TX_DROP;
00931 
00932         /* update duration/seq/flags of fragments */
00933         fragnum = 0;
00934         do {
00935                 int next_len;
00936                 const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
00937 
00938                 hdr = (void *)skb->data;
00939                 info = IEEE80211_SKB_CB(skb);
00940 
00941                 if (skb->next) {
00942                         hdr->frame_control |= morefrags;
00943                         next_len = skb->next->len;
00944                         /*
00945                          * No multi-rate retries for fragmented frames, that
00946                          * would completely throw off the NAV at other STAs.
00947                          */
00948                         info->control.rates[1].idx = -1;
00949                         info->control.rates[2].idx = -1;
00950                         info->control.rates[3].idx = -1;
00951                         info->control.rates[4].idx = -1;
00952                         BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 5);
00953                         info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
00954                 } else {
00955                         hdr->frame_control &= ~morefrags;
00956                         next_len = 0;
00957                 }
00958                 hdr->duration_id = ieee80211_duration(tx, 0, next_len);
00959                 hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG);
00960                 fragnum++;
00961         } while ((skb = skb->next));
00962 
00963         return TX_CONTINUE;
00964 }
00965 
00966 static ieee80211_tx_result debug_noinline
00967 ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
00968 {
00969         struct sk_buff *skb = tx->skb;
00970 
00971         if (!tx->sta)
00972                 return TX_CONTINUE;
00973 
00974         tx->sta->tx_packets++;
00975         do {
00976                 tx->sta->tx_fragments++;
00977                 tx->sta->tx_bytes += skb->len;
00978         } while ((skb = skb->next));
00979 
00980         return TX_CONTINUE;
00981 }
00982 
00983 static ieee80211_tx_result debug_noinline
00984 ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
00985 {
00986         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
00987 
00988         if (!tx->key)
00989                 return TX_CONTINUE;
00990 
00991         switch (tx->key->conf.cipher) {
00992         case WLAN_CIPHER_SUITE_WEP40:
00993         case WLAN_CIPHER_SUITE_WEP104:
00994                 return ieee80211_crypto_wep_encrypt(tx);
00995         case WLAN_CIPHER_SUITE_TKIP:
00996                 return ieee80211_crypto_tkip_encrypt(tx);
00997         case WLAN_CIPHER_SUITE_CCMP:
00998                 return ieee80211_crypto_ccmp_encrypt(tx);
00999         case WLAN_CIPHER_SUITE_AES_CMAC:
01000                 return ieee80211_crypto_aes_cmac_encrypt(tx);
01001         default:
01002                 /* handle hw-only algorithm */
01003                 if (info->control.hw_key) {
01004                         ieee80211_tx_set_protected(tx);
01005                         return TX_CONTINUE;
01006                 }
01007                 break;
01008 
01009         }
01010 
01011         return TX_DROP;
01012 }
01013 
01014 static ieee80211_tx_result debug_noinline
01015 ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx)
01016 {
01017         struct sk_buff *skb = tx->skb;
01018         struct ieee80211_hdr *hdr;
01019         int next_len;
01020         bool group_addr;
01021 
01022         do {
01023                 hdr = (void *) skb->data;
01024                 if (unlikely(ieee80211_is_pspoll(hdr->frame_control)))
01025                         break; /* must not overwrite AID */
01026                 next_len = skb->next ? skb->next->len : 0;
01027                 group_addr = is_multicast_ether_addr(hdr->addr1);
01028 
01029                 hdr->duration_id =
01030                         ieee80211_duration(tx, group_addr, next_len);
01031         } while ((skb = skb->next));
01032 
01033         return TX_CONTINUE;
01034 }
01035 
01036 /* actual transmit path */
01037 
01038 static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx,
01039                                   struct sk_buff *skb,
01040                                   struct ieee80211_tx_info *info,
01041                                   struct tid_ampdu_tx *tid_tx,
01042                                   int tid)
01043 {
01044         bool queued = false;
01045 
01046         if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
01047                 info->flags |= IEEE80211_TX_CTL_AMPDU;
01048         } else if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
01049                 /*
01050                  * nothing -- this aggregation session is being started
01051                  * but that might still fail with the driver
01052                  */
01053         } else {
01054                 spin_lock(&tx->sta->lock);
01055                 /*
01056                  * Need to re-check now, because we may get here
01057                  *
01058                  *  1) in the window during which the setup is actually
01059                  *     already done, but not marked yet because not all
01060                  *     packets are spliced over to the driver pending
01061                  *     queue yet -- if this happened we acquire the lock
01062                  *     either before or after the splice happens, but
01063                  *     need to recheck which of these cases happened.
01064                  *
01065                  *  2) during session teardown, if the OPERATIONAL bit
01066                  *     was cleared due to the teardown but the pointer
01067                  *     hasn't been assigned NULL yet (or we loaded it
01068                  *     before it was assigned) -- in this case it may
01069                  *     now be NULL which means we should just let the
01070                  *     packet pass through because splicing the frames
01071                  *     back is already done.
01072                  */
01073                 tid_tx = rcu_dereference_protected_tid_tx(tx->sta, tid);
01074 
01075                 if (!tid_tx) {
01076                         /* do nothing, let packet pass through */
01077                 } else if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
01078                         info->flags |= IEEE80211_TX_CTL_AMPDU;
01079                 } else {
01080                         queued = true;
01081                         info->control.vif = &tx->sdata->vif;
01082                         info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
01083                         __skb_queue_tail(&tid_tx->pending, skb);
01084                 }
01085                 spin_unlock(&tx->sta->lock);
01086         }
01087 
01088         return queued;
01089 }
01090 
01091 /*
01092  * initialises @tx
01093  */
01094 static ieee80211_tx_result
01095 ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
01096                      struct ieee80211_tx_data *tx,
01097                      struct sk_buff *skb)
01098 {
01099         struct ieee80211_local *local = sdata->local;
01100         struct ieee80211_hdr *hdr;
01101         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
01102         int tid;
01103         u8 *qc;
01104 
01105         memset(tx, 0, sizeof(*tx));
01106         tx->skb = skb;
01107         tx->local = local;
01108         tx->sdata = sdata;
01109         tx->channel = local->hw.conf.channel;
01110 
01111         /*
01112          * If this flag is set to true anywhere, and we get here,
01113          * we are doing the needed processing, so remove the flag
01114          * now.
01115          */
01116         info->flags &= ~IEEE80211_TX_INTFL_NEED_TXPROCESSING;
01117 
01118         hdr = (struct ieee80211_hdr *) skb->data;
01119 
01120         if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
01121                 tx->sta = rcu_dereference(sdata->u.vlan.sta);
01122                 if (!tx->sta && sdata->dev->ieee80211_ptr->use_4addr)
01123                         return TX_DROP;
01124         } else if (info->flags & IEEE80211_TX_CTL_INJECTED ||
01125                    tx->sdata->control_port_protocol == tx->skb->protocol) {
01126                 tx->sta = sta_info_get_bss(sdata, hdr->addr1);
01127         }
01128         if (!tx->sta)
01129                 tx->sta = sta_info_get(sdata, hdr->addr1);
01130 
01131         if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) &&
01132             !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
01133             (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION) &&
01134             !(local->hw.flags & IEEE80211_HW_TX_AMPDU_SETUP_IN_HW)) {
01135                 struct tid_ampdu_tx *tid_tx;
01136 
01137                 qc = ieee80211_get_qos_ctl(hdr);
01138                 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
01139 
01140                 tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]);
01141                 if (tid_tx) {
01142                         bool queued;
01143 
01144                         queued = ieee80211_tx_prep_agg(tx, skb, info,
01145                                                        tid_tx, tid);
01146 
01147                         if (unlikely(queued))
01148                                 return TX_QUEUED;
01149                 }
01150         }
01151 
01152         if (is_multicast_ether_addr(hdr->addr1)) {
01153                 tx->flags &= ~IEEE80211_TX_UNICAST;
01154                 info->flags |= IEEE80211_TX_CTL_NO_ACK;
01155         } else {
01156                 tx->flags |= IEEE80211_TX_UNICAST;
01157                 if (unlikely(local->wifi_wme_noack_test))
01158                         info->flags |= IEEE80211_TX_CTL_NO_ACK;
01159                 /*
01160                  * Flags are initialized to 0. Hence, no need to
01161                  * explicitly unset IEEE80211_TX_CTL_NO_ACK since
01162                  * it might already be set for injected frames.
01163                  */
01164         }
01165 
01166         if (!(info->flags & IEEE80211_TX_CTL_DONTFRAG)) {
01167                 if (!(tx->flags & IEEE80211_TX_UNICAST) ||
01168                     skb->len + FCS_LEN <= local->hw.wiphy->frag_threshold ||
01169                     info->flags & IEEE80211_TX_CTL_AMPDU)
01170                         info->flags |= IEEE80211_TX_CTL_DONTFRAG;
01171         }
01172 
01173         if (!tx->sta)
01174                 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
01175         else if (test_and_clear_sta_flag(tx->sta, WLAN_STA_CLEAR_PS_FILT))
01176                 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
01177 
01178         info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT;
01179 
01180         return TX_CONTINUE;
01181 }
01182 
01183 /*
01184  * Returns false if the frame couldn't be transmitted but was queued instead.
01185  */
01186 static bool __ieee80211_tx(struct ieee80211_local *local, struct sk_buff **skbp,
01187                            struct sta_info *sta, bool txpending)
01188 {
01189         struct sk_buff *skb = *skbp, *next;
01190         struct ieee80211_tx_info *info;
01191         struct ieee80211_sub_if_data *sdata;
01192         unsigned long flags;
01193         int len;
01194         bool fragm = false;
01195 
01196         while (skb) {
01197                 int q = skb_get_queue_mapping(skb);
01198                 __le16 fc;
01199 
01200                 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
01201                 if (local->queue_stop_reasons[q] ||
01202                     (!txpending && !skb_queue_empty(&local->pending[q]))) {
01203                         /*
01204                          * Since queue is stopped, queue up frames for later
01205                          * transmission from the tx-pending tasklet when the
01206                          * queue is woken again.
01207                          */
01208 
01209                         do {
01210                                 next = skb->next;
01211                                 skb->next = NULL;
01212                                 /*
01213                                  * NB: If txpending is true, next must already
01214                                  * be NULL since we must've gone through this
01215                                  * loop before already; therefore we can just
01216                                  * queue the frame to the head without worrying
01217                                  * about reordering of fragments.
01218                                  */
01219                                 if (unlikely(txpending))
01220                                         __skb_queue_head(&local->pending[q],
01221                                                          skb);
01222                                 else
01223                                         __skb_queue_tail(&local->pending[q],
01224                                                          skb);
01225                         } while ((skb = next));
01226 
01227                         spin_unlock_irqrestore(&local->queue_stop_reason_lock,
01228                                                flags);
01229                         return false;
01230                 }
01231                 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
01232 
01233                 info = IEEE80211_SKB_CB(skb);
01234 
01235                 if (fragm)
01236                         info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT |
01237                                          IEEE80211_TX_CTL_FIRST_FRAGMENT);
01238 
01239                 next = skb->next;
01240                 len = skb->len;
01241 
01242                 if (next)
01243                         info->flags |= IEEE80211_TX_CTL_MORE_FRAMES;
01244 
01245                 sdata = vif_to_sdata(info->control.vif);
01246 
01247                 switch (sdata->vif.type) {
01248                 case NL80211_IFTYPE_MONITOR:
01249                         info->control.vif = NULL;
01250                         break;
01251                 case NL80211_IFTYPE_AP_VLAN:
01252                         info->control.vif = &container_of(sdata->bss,
01253                                 struct ieee80211_sub_if_data, u.ap)->vif;
01254                         break;
01255                 default:
01256                         /* keep */
01257                         break;
01258                 }
01259 
01260                 if (sta && sta->uploaded)
01261                         info->control.sta = &sta->sta;
01262                 else
01263                         info->control.sta = NULL;
01264 //DANI  ((struct ieee80211_hdr *)skb->data)->frame_control;  = 0x0850;
01265                 fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
01266                 drv_tx(local, skb);
01267 
01268                 ieee80211_tpt_led_trig_tx(local, fc, len);
01269                 *skbp = skb = next;
01270                 ieee80211_led_tx(local, 1);
01271                 fragm = true;
01272         }
01273 
01274         return true;
01275 }
01276 
01277 /*
01278  * Invoke TX handlers, return 0 on success and non-zero if the
01279  * frame was dropped or queued.
01280  */
01281 static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
01282 {
01283         struct sk_buff *skb = tx->skb;
01284         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
01285         ieee80211_tx_result res = TX_DROP;
01286 
01287 #define CALL_TXH(txh) \
01288         do {                            \
01289                 res = txh(tx);          \
01290                 if (res != TX_CONTINUE) \
01291                         goto txh_done;  \
01292         } while (0)
01293 
01294         CALL_TXH(ieee80211_tx_h_dynamic_ps);
01295         CALL_TXH(ieee80211_tx_h_check_assoc);
01296         CALL_TXH(ieee80211_tx_h_ps_buf);
01297         CALL_TXH(ieee80211_tx_h_check_control_port_protocol);
01298         CALL_TXH(ieee80211_tx_h_select_key);
01299         if (!(tx->local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL))
01300                 CALL_TXH(ieee80211_tx_h_rate_ctrl);
01301 
01302         if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION))
01303                 goto txh_done;
01304 
01305         CALL_TXH(ieee80211_tx_h_michael_mic_add);
01306         CALL_TXH(ieee80211_tx_h_sequence);
01307         CALL_TXH(ieee80211_tx_h_fragment);
01308         /* handlers after fragment must be aware of tx info fragmentation! */
01309         CALL_TXH(ieee80211_tx_h_stats);
01310         CALL_TXH(ieee80211_tx_h_encrypt);
01311         if (!(tx->local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL))
01312                 CALL_TXH(ieee80211_tx_h_calculate_duration);
01313 #undef CALL_TXH
01314 
01315  txh_done:
01316         if (unlikely(res == TX_DROP)) {
01317                 I802_DEBUG_INC(tx->local->tx_handlers_drop);
01318                 while (skb) {
01319                         struct sk_buff *next;
01320 
01321                         next = skb->next;
01322                         dev_kfree_skb(skb);
01323                         skb = next;
01324                 }
01325                 return -1;
01326         } else if (unlikely(res == TX_QUEUED)) {
01327                 I802_DEBUG_INC(tx->local->tx_handlers_queued);
01328                 return -1;
01329         }
01330 
01331         return 0;
01332 }
01333 
01334 /*
01335  * Returns false if the frame couldn't be transmitted but was queued instead.
01336  */
01337 static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
01338                          struct sk_buff *skb, bool txpending)
01339 {
01340         struct ieee80211_local *local = sdata->local;
01341         struct ieee80211_tx_data tx;
01342         ieee80211_tx_result res_prepare;
01343         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
01344         bool result = true;
01345 
01346         if (unlikely(skb->len < 10)) {
01347                 dev_kfree_skb(skb);
01348                 return true;
01349         }
01350 
01351         rcu_read_lock();
01352 
01353         /* initialises tx */
01354         res_prepare = ieee80211_tx_prepare(sdata, &tx, skb);
01355 
01356         if (unlikely(res_prepare == TX_DROP)) {
01357                 dev_kfree_skb(skb);
01358                 goto out;
01359         } else if (unlikely(res_prepare == TX_QUEUED)) {
01360                 goto out;
01361         }
01362 
01363         tx.channel = local->hw.conf.channel;
01364         info->band = tx.channel->band;
01365 
01366         if (!invoke_tx_handlers(&tx))
01367                 result = __ieee80211_tx(local, &tx.skb, tx.sta, txpending);
01368  out:
01369         rcu_read_unlock();
01370         return result;
01371 }
01372 
01373 /* device xmit handlers */
01374 
01375 static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata,
01376                                 struct sk_buff *skb,
01377                                 int head_need, bool may_encrypt)
01378 {
01379         struct ieee80211_local *local = sdata->local;
01380         int tail_need = 0;
01381 
01382         if (may_encrypt && sdata->crypto_tx_tailroom_needed_cnt) {
01383                 tail_need = IEEE80211_ENCRYPT_TAILROOM;
01384                 tail_need -= skb_tailroom(skb);
01385                 tail_need = max_t(int, tail_need, 0);
01386         }
01387 
01388         if (skb_cloned(skb))
01389                 I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
01390         else if (head_need || tail_need)
01391                 I802_DEBUG_INC(local->tx_expand_skb_head);
01392         else
01393                 return 0;
01394 
01395         if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) {
01396                 wiphy_debug(local->hw.wiphy,
01397                             "failed to reallocate TX buffer\n");
01398                 return -ENOMEM;
01399         }
01400 
01401         return 0;
01402 }
01403 
01404 void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
01405 {
01406         struct ieee80211_local *local = sdata->local;
01407         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
01408         struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
01409         int headroom;
01410         bool may_encrypt;
01411 
01412         rcu_read_lock();
01413 
01414         may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT);
01415 
01416         headroom = local->tx_headroom;
01417         if (may_encrypt)
01418                 headroom += IEEE80211_ENCRYPT_HEADROOM;
01419         headroom -= skb_headroom(skb);
01420         headroom = max_t(int, 0, headroom);
01421 
01422         if (ieee80211_skb_resize(sdata, skb, headroom, may_encrypt)) {
01423                 dev_kfree_skb(skb);
01424                 rcu_read_unlock();
01425                 return;
01426         }
01427 
01428         hdr = (struct ieee80211_hdr *) skb->data;
01429         info->control.vif = &sdata->vif;
01430 
01431         if (ieee80211_vif_is_mesh(&sdata->vif) &&
01432             ieee80211_is_data(hdr->frame_control) &&
01433                 !is_multicast_ether_addr(hdr->addr1))
01434                         if (mesh_nexthop_lookup(skb, sdata)) {
01435                                 /* skb queued: don't free */
01436                                 rcu_read_unlock();
01437                                 return;
01438                         }
01439 
01440         ieee80211_set_qos_hdr(sdata, skb);
01441         ieee80211_tx(sdata, skb, false);
01442         rcu_read_unlock();
01443 }
01444 
01445 static bool ieee80211_parse_tx_radiotap(struct sk_buff *skb)
01446 {
01447         struct ieee80211_radiotap_iterator iterator;
01448         struct ieee80211_radiotap_header *rthdr =
01449                 (struct ieee80211_radiotap_header *) skb->data;
01450         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
01451         int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len,
01452                                                    NULL);
01453         u16 txflags;
01454 
01455         info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
01456                        IEEE80211_TX_CTL_DONTFRAG;
01457 
01458         /*
01459          * for every radiotap entry that is present
01460          * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
01461          * entries present, or -EINVAL on error)
01462          */
01463 
01464         while (!ret) {
01465                 ret = ieee80211_radiotap_iterator_next(&iterator);
01466 
01467                 if (ret)
01468                         continue;
01469 
01470                 /* see if this argument is something we can use */
01471                 switch (iterator.this_arg_index) {
01472                 /*
01473                  * You must take care when dereferencing iterator.this_arg
01474                  * for multibyte types... the pointer is not aligned.  Use
01475                  * get_unaligned((type *)iterator.this_arg) to dereference
01476                  * iterator.this_arg for type "type" safely on all arches.
01477                 */
01478                 case IEEE80211_RADIOTAP_FLAGS:
01479                         if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
01480                                 /*
01481                                  * this indicates that the skb we have been
01482                                  * handed has the 32-bit FCS CRC at the end...
01483                                  * we should react to that by snipping it off
01484                                  * because it will be recomputed and added
01485                                  * on transmission
01486                                  */
01487                                 if (skb->len < (iterator._max_length + FCS_LEN))
01488                                         return false;
01489 
01490                                 skb_trim(skb, skb->len - FCS_LEN);
01491                         }
01492                         if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
01493                                 info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT;
01494                         if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
01495                                 info->flags &= ~IEEE80211_TX_CTL_DONTFRAG;
01496                         break;
01497 
01498                 case IEEE80211_RADIOTAP_TX_FLAGS:
01499                         txflags = get_unaligned_le16(iterator.this_arg);
01500                         if (txflags & IEEE80211_RADIOTAP_F_TX_NOACK)
01501                                 info->flags |= IEEE80211_TX_CTL_NO_ACK;
01502                         break;
01503 
01504                 /*
01505                  * Please update the file
01506                  * Documentation/networking/mac80211-injection.txt
01507                  * when parsing new fields here.
01508                  */
01509 
01510                 default:
01511                         break;
01512                 }
01513         }
01514 
01515         if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
01516                 return false;
01517 
01518         /*
01519          * remove the radiotap header
01520          * iterator->_max_length was sanity-checked against
01521          * skb->len by iterator init
01522          */
01523         skb_pull(skb, iterator._max_length);
01524 
01525         return true;
01526 }
01527 
01528 netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
01529                                          struct net_device *dev)
01530 {
01531         struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
01532         struct ieee80211_channel *chan = local->hw.conf.channel;
01533         struct ieee80211_radiotap_header *prthdr =
01534                 (struct ieee80211_radiotap_header *)skb->data;
01535         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
01536         struct ieee80211_hdr *hdr;
01537         struct ieee80211_sub_if_data *tmp_sdata, *sdata;
01538         u16 len_rthdr;
01539         int hdrlen;
01540 
01541         /*
01542          * Frame injection is not allowed if beaconing is not allowed
01543          * or if we need radar detection. Beaconing is usually not allowed when
01544          * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
01545          * Passive scan is also used in world regulatory domains where
01546          * your country is not known and as such it should be treated as
01547          * NO TX unless the channel is explicitly allowed in which case
01548          * your current regulatory domain would not have the passive scan
01549          * flag.
01550          *
01551          * Since AP mode uses monitor interfaces to inject/TX management
01552          * frames we can make AP mode the exception to this rule once it
01553          * supports radar detection as its implementation can deal with
01554          * radar detection by itself. We can do that later by adding a
01555          * monitor flag interfaces used for AP support.
01556          */
01557         if ((chan->flags & (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_RADAR |
01558              IEEE80211_CHAN_PASSIVE_SCAN)))
01559                 goto fail;
01560 
01561         /* check for not even having the fixed radiotap header part */
01562         if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
01563                 goto fail; /* too short to be possibly valid */
01564 
01565         /* is it a header version we can trust to find length from? */
01566         if (unlikely(prthdr->it_version))
01567                 goto fail; /* only version 0 is supported */
01568 
01569         /* then there must be a radiotap header with a length we can use */
01570         len_rthdr = ieee80211_get_radiotap_len(skb->data);
01571 
01572         /* does the skb contain enough to deliver on the alleged length? */
01573         if (unlikely(skb->len < len_rthdr))
01574                 goto fail; /* skb too short for claimed rt header extent */
01575 
01576         /*
01577          * fix up the pointers accounting for the radiotap
01578          * header still being in there.  We are being given
01579          * a precooked IEEE80211 header so no need for
01580          * normal processing
01581          */
01582         skb_set_mac_header(skb, len_rthdr);
01583         /*
01584          * these are just fixed to the end of the rt area since we
01585          * don't have any better information and at this point, nobody cares
01586          */
01587         skb_set_network_header(skb, len_rthdr);
01588         skb_set_transport_header(skb, len_rthdr);
01589 
01590         if (skb->len < len_rthdr + 2)
01591                 goto fail;
01592 
01593         hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
01594         hdrlen = ieee80211_hdrlen(hdr->frame_control);
01595 
01596         if (skb->len < len_rthdr + hdrlen)
01597                 goto fail;
01598 
01599         /*
01600          * Initialize skb->protocol if the injected frame is a data frame
01601          * carrying a rfc1042 header
01602          */
01603         if (ieee80211_is_data(hdr->frame_control) &&
01604             skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) {
01605                 u8 *payload = (u8 *)hdr + hdrlen;
01606 
01607                 if (compare_ether_addr(payload, rfc1042_header) == 0)
01608                         skb->protocol = cpu_to_be16((payload[6] << 8) |
01609                                                     payload[7]);
01610         }
01611 
01612         memset(info, 0, sizeof(*info));
01613 
01614         info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
01615                       IEEE80211_TX_CTL_INJECTED;
01616 
01617         /* process and remove the injection radiotap header */
01618         if (!ieee80211_parse_tx_radiotap(skb))
01619                 goto fail;
01620 
01621         rcu_read_lock();
01622 
01623         /*
01624          * We process outgoing injected frames that have a local address
01625          * we handle as though they are non-injected frames.
01626          * This code here isn't entirely correct, the local MAC address
01627          * isn't always enough to find the interface to use; for proper
01628          * VLAN/WDS support we will need a different mechanism (which
01629          * likely isn't going to be monitor interfaces).
01630          */
01631         sdata = IEEE80211_DEV_TO_SUB_IF(dev);
01632 
01633         list_for_each_entry_rcu(tmp_sdata, &local->interfaces, list) {
01634                 if (!ieee80211_sdata_running(tmp_sdata))
01635                         continue;
01636                 if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR ||
01637                     tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
01638                     tmp_sdata->vif.type == NL80211_IFTYPE_WDS)
01639                         continue;
01640                 if (compare_ether_addr(tmp_sdata->vif.addr, hdr->addr2) == 0) {
01641                         sdata = tmp_sdata;
01642                         break;
01643                 }
01644         }
01645 
01646         ieee80211_xmit(sdata, skb);
01647         rcu_read_unlock();
01648 
01649         return NETDEV_TX_OK;
01650 
01651 fail:
01652         dev_kfree_skb(skb);
01653         return NETDEV_TX_OK; /* meaning, we dealt with the skb */
01654 }
01655 
01671 netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
01672                                     struct net_device *dev)
01673 {
01674         struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
01675         struct ieee80211_local *local = sdata->local;
01676         struct ieee80211_tx_info *info;
01677         int ret = NETDEV_TX_BUSY, head_need;
01678         u16 ethertype, hdrlen,  meshhdrlen = 0;
01679         __le16 fc;
01680         struct ieee80211_hdr hdr;
01681         struct ieee80211s_hdr mesh_hdr __maybe_unused;
01682         struct mesh_path __maybe_unused *mppath = NULL;
01683         const u8 *encaps_data;
01684         int encaps_len, skip_header_bytes;
01685         int nh_pos, h_pos;
01686         struct sta_info *sta = NULL;
01687         bool wme_sta = false, authorized = false, tdls_auth = false;
01688         struct sk_buff *tmp_skb;
01689         bool tdls_direct = false;
01690 
01691         if (unlikely(skb->len < ETH_HLEN)) {
01692                 ret = NETDEV_TX_OK;
01693                 goto fail;
01694         }
01695 
01696         /* convert Ethernet header to proper 802.11 header (based on
01697          * operation mode) */
01698         ethertype = (skb->data[12] << 8) | skb->data[13];
01699         fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
01700 
01701         switch (sdata->vif.type) {
01702         case NL80211_IFTYPE_AP_VLAN:
01703                 rcu_read_lock();
01704                 sta = rcu_dereference(sdata->u.vlan.sta);
01705                 if (sta) {
01706                         fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
01707                         /* RA TA DA SA */
01708                         memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN);
01709                         memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
01710                         memcpy(hdr.addr3, skb->data, ETH_ALEN);
01711                         memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
01712                         hdrlen = 30;
01713                         authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
01714                         wme_sta = test_sta_flag(sta, WLAN_STA_WME);
01715                 }
01716                 rcu_read_unlock();
01717                 if (sta)
01718                         break;
01719                 /* fall through */
01720         case NL80211_IFTYPE_AP:
01721                 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
01722                 /* DA BSSID SA */
01723                 memcpy(hdr.addr1, skb->data, ETH_ALEN);
01724                 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
01725                 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
01726                 hdrlen = 24;
01727                 break;
01728         case NL80211_IFTYPE_WDS:
01729                 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
01730                 /* RA TA DA SA */
01731                 memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
01732                 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
01733                 memcpy(hdr.addr3, skb->data, ETH_ALEN);
01734                 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
01735                 hdrlen = 30;
01736                 break;
01737 #ifdef CONFIG_MAC80211_MESH
01738         case NL80211_IFTYPE_MESH_POINT:
01739                 if (!sdata->u.mesh.mshcfg.dot11MeshTTL) {
01740                         /* Do not send frames with mesh_ttl == 0 */
01741                         sdata->u.mesh.mshstats.dropped_frames_ttl++;
01742                         ret = NETDEV_TX_OK;
01743                         goto fail;
01744                 }
01745                 rcu_read_lock();
01746                 if (!is_multicast_ether_addr(skb->data))
01747                         mppath = mpp_path_lookup(skb->data, sdata);
01748 
01749                 /*
01750                  * Use address extension if it is a packet from
01751                  * another interface or if we know the destination
01752                  * is being proxied by a portal (i.e. portal address
01753                  * differs from proxied address)
01754                  */
01755                 if (compare_ether_addr(sdata->vif.addr,
01756                                        skb->data + ETH_ALEN) == 0 &&
01757                     !(mppath && compare_ether_addr(mppath->mpp, skb->data))) {
01758                         hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
01759                                         skb->data, skb->data + ETH_ALEN);
01760                         rcu_read_unlock();
01761                         meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr,
01762                                         sdata, NULL, NULL);
01763                 } else {
01764                         int is_mesh_mcast = 1;
01765                         const u8 *mesh_da;
01766 
01767                         if (is_multicast_ether_addr(skb->data))
01768                                 /* DA TA mSA AE:SA */
01769                                 mesh_da = skb->data;
01770                         else {
01771                                 static const u8 bcast[ETH_ALEN] =
01772                                         { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
01773                                 if (mppath) {
01774                                         /* RA TA mDA mSA AE:DA SA */
01775                                         mesh_da = mppath->mpp;
01776                                         is_mesh_mcast = 0;
01777                                 } else {
01778                                         /* DA TA mSA AE:SA */
01779                                         mesh_da = bcast;
01780                                 }
01781                         }
01782                         hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
01783                                         mesh_da, sdata->vif.addr);
01784                         rcu_read_unlock();
01785                         if (is_mesh_mcast)
01786                                 meshhdrlen =
01787                                         ieee80211_new_mesh_header(&mesh_hdr,
01788                                                         sdata,
01789                                                         skb->data + ETH_ALEN,
01790                                                         NULL);
01791                         else
01792                                 meshhdrlen =
01793                                         ieee80211_new_mesh_header(&mesh_hdr,
01794                                                         sdata,
01795                                                         skb->data,
01796                                                         skb->data + ETH_ALEN);
01797 
01798                 }
01799                 break;
01800 #endif
01801         case NL80211_IFTYPE_STATION:
01802                 if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
01803                         bool tdls_peer = false;
01804 
01805                         rcu_read_lock();
01806                         sta = sta_info_get(sdata, skb->data);
01807                         if (sta) {
01808                                 authorized = test_sta_flag(sta,
01809                                                         WLAN_STA_AUTHORIZED);
01810                                 wme_sta = test_sta_flag(sta, WLAN_STA_WME);
01811                                 tdls_peer = test_sta_flag(sta,
01812                                                          WLAN_STA_TDLS_PEER);
01813                                 tdls_auth = test_sta_flag(sta,
01814                                                 WLAN_STA_TDLS_PEER_AUTH);
01815                         }
01816                         rcu_read_unlock();
01817 
01818                         /*
01819                          * If the TDLS link is enabled, send everything
01820                          * directly. Otherwise, allow TDLS setup frames
01821                          * to be transmitted indirectly.
01822                          */
01823                         tdls_direct = tdls_peer && (tdls_auth ||
01824                                  !(ethertype == ETH_P_TDLS && skb->len > 14 &&
01825                                    skb->data[14] == WLAN_TDLS_SNAP_RFTYPE));
01826                 }
01827 
01828                 if (tdls_direct) {
01829                         /* link during setup - throw out frames to peer */
01830                         if (!tdls_auth) {
01831                                 ret = NETDEV_TX_OK;
01832                                 goto fail;
01833                         }
01834 
01835                         /* DA SA BSSID */
01836                         memcpy(hdr.addr1, skb->data, ETH_ALEN);
01837                         memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
01838                         memcpy(hdr.addr3, sdata->u.mgd.bssid, ETH_ALEN);
01839                         hdrlen = 24;
01840                 }  else if (sdata->u.mgd.use_4addr &&
01841                             cpu_to_be16(ethertype) != sdata->control_port_protocol) {
01842                         fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
01843                                           IEEE80211_FCTL_TODS);
01844                         /* RA TA DA SA */
01845                         memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
01846                         memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
01847                         memcpy(hdr.addr3, skb->data, ETH_ALEN);
01848                         memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
01849                         hdrlen = 30;
01850                 } else {
01851                         fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
01852                         /* BSSID SA DA */
01853                         memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
01854                         memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
01855                         memcpy(hdr.addr3, skb->data, ETH_ALEN);
01856                         hdrlen = 24;
01857                 }
01858                 break;
01859         case NL80211_IFTYPE_ADHOC:
01860                 /* DA SA BSSID */
01861                 memcpy(hdr.addr1, skb->data, ETH_ALEN);
01862                 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
01863                 memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN);
01864                 hdrlen = 24;
01865                 break;
01866         default:
01867                 ret = NETDEV_TX_OK;
01868                 goto fail;
01869         }
01870 
01871         /*
01872          * There's no need to try to look up the destination
01873          * if it is a multicast address (which can only happen
01874          * in AP mode)
01875          */
01876         if (!is_multicast_ether_addr(hdr.addr1)) {
01877                 rcu_read_lock();
01878                 sta = sta_info_get(sdata, hdr.addr1);
01879                 if (sta) {
01880                         authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
01881                         wme_sta = test_sta_flag(sta, WLAN_STA_WME);
01882                 }
01883                 rcu_read_unlock();
01884         }
01885 
01886         /* For mesh, the use of the QoS header is mandatory */
01887         if (ieee80211_vif_is_mesh(&sdata->vif))
01888                 wme_sta = true;
01889 
01890         /* receiver and we are QoS enabled, use a QoS type frame */
01891         if (wme_sta && local->hw.queues >= 4) {
01892                 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
01893                 hdrlen += 2;
01894         }
01895 
01896         /*
01897          * Drop unicast frames to unauthorised stations unless they are
01898          * EAPOL frames from the local station.
01899          */
01900         if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) &&
01901                      !is_multicast_ether_addr(hdr.addr1) && !authorized &&
01902                      (cpu_to_be16(ethertype) != sdata->control_port_protocol ||
01903                       compare_ether_addr(sdata->vif.addr, skb->data + ETH_ALEN)))) {
01904 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
01905                 if (net_ratelimit())
01906                         printk(KERN_DEBUG "%s: dropped frame to %pM"
01907                                " (unauthorized port)\n", dev->name,
01908                                hdr.addr1);
01909 #endif
01910 
01911                 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
01912 
01913                 ret = NETDEV_TX_OK;
01914                 goto fail;
01915         }
01916 
01917         /*
01918          * If the skb is shared we need to obtain our own copy.
01919          */
01920         if (skb_shared(skb)) {
01921                 tmp_skb = skb;
01922                 skb = skb_clone(skb, GFP_ATOMIC);
01923                 kfree_skb(tmp_skb);
01924 
01925                 if (!skb) {
01926                         ret = NETDEV_TX_OK;
01927                         goto fail;
01928                 }
01929         }
01930 
01931         hdr.frame_control = fc;
01932         hdr.duration_id = 0;
01933         hdr.seq_ctrl = 0;
01934 
01935         skip_header_bytes = ETH_HLEN;
01936         if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
01937                 encaps_data = bridge_tunnel_header;
01938                 encaps_len = sizeof(bridge_tunnel_header);
01939                 skip_header_bytes -= 2;
01940         } else if (ethertype >= 0x600) {
01941                 encaps_data = rfc1042_header;
01942                 encaps_len = sizeof(rfc1042_header);
01943                 skip_header_bytes -= 2;
01944         } else {
01945                 encaps_data = NULL;
01946                 encaps_len = 0;
01947         }
01948 
01949         nh_pos = skb_network_header(skb) - skb->data;
01950         h_pos = skb_transport_header(skb) - skb->data;
01951 
01952         skb_pull(skb, skip_header_bytes);
01953         nh_pos -= skip_header_bytes;
01954         h_pos -= skip_header_bytes;
01955 
01956         head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
01957 
01958         /*
01959          * So we need to modify the skb header and hence need a copy of
01960          * that. The head_need variable above doesn't, so far, include
01961          * the needed header space that we don't need right away. If we
01962          * can, then we don't reallocate right now but only after the
01963          * frame arrives at the master device (if it does...)
01964          *
01965          * If we cannot, however, then we will reallocate to include all
01966          * the ever needed space. Also, if we need to reallocate it anyway,
01967          * make it big enough for everything we may ever need.
01968          */
01969 
01970         if (head_need > 0 || skb_cloned(skb)) {
01971                 head_need += IEEE80211_ENCRYPT_HEADROOM;
01972                 head_need += local->tx_headroom;
01973                 head_need = max_t(int, 0, head_need);
01974                 if (ieee80211_skb_resize(sdata, skb, head_need, true))
01975                         goto fail;
01976         }
01977 
01978         if (encaps_data) {
01979                 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
01980                 nh_pos += encaps_len;
01981                 h_pos += encaps_len;
01982         }
01983 
01984 #ifdef CONFIG_MAC80211_MESH
01985         if (meshhdrlen > 0) {
01986                 memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
01987                 nh_pos += meshhdrlen;
01988                 h_pos += meshhdrlen;
01989         }
01990 #endif
01991 
01992         if (ieee80211_is_data_qos(fc)) {
01993                 __le16 *qos_control;
01994 
01995                 qos_control = (__le16*) skb_push(skb, 2);
01996                 memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
01997                 /*
01998                  * Maybe we could actually set some fields here, for now just
01999                  * initialise to zero to indicate no special operation.
02000                  */
02001                 *qos_control = 0;
02002         } else
02003                 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
02004 
02005         nh_pos += hdrlen;
02006         h_pos += hdrlen;
02007 
02008         dev->stats.tx_packets++;
02009         dev->stats.tx_bytes += skb->len;
02010 
02011         /* Update skb pointers to various headers since this modified frame
02012          * is going to go through Linux networking code that may potentially
02013          * need things like pointer to IP header. */
02014         skb_set_mac_header(skb, 0);
02015         skb_set_network_header(skb, nh_pos);
02016         skb_set_transport_header(skb, h_pos);
02017 
02018         info = IEEE80211_SKB_CB(skb);
02019         memset(info, 0, sizeof(*info));
02020 
02021         dev->trans_start = jiffies;
02022         ieee80211_xmit(sdata, skb);
02023 
02024         return NETDEV_TX_OK;
02025 
02026  fail:
02027         if (ret == NETDEV_TX_OK)
02028                 dev_kfree_skb(skb);
02029 
02030         return ret;
02031 }
02032 
02033 
02034 /*
02035  * ieee80211_clear_tx_pending may not be called in a context where
02036  * it is possible that it packets could come in again.
02037  */
02038 void ieee80211_clear_tx_pending(struct ieee80211_local *local)
02039 {
02040         int i;
02041 
02042         for (i = 0; i < local->hw.queues; i++)
02043                 skb_queue_purge(&local->pending[i]);
02044 }
02045 
02046 /*
02047  * Returns false if the frame couldn't be transmitted but was queued instead,
02048  * which in this case means re-queued -- take as an indication to stop sending
02049  * more pending frames.
02050  */
02051 static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
02052                                      struct sk_buff *skb)
02053 {
02054         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
02055         struct ieee80211_sub_if_data *sdata;
02056         struct sta_info *sta;
02057         struct ieee80211_hdr *hdr;
02058         bool result;
02059 
02060         sdata = vif_to_sdata(info->control.vif);
02061 
02062         if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) {
02063                 result = ieee80211_tx(sdata, skb, true);
02064         } else {
02065                 hdr = (struct ieee80211_hdr *)skb->data;
02066                 sta = sta_info_get(sdata, hdr->addr1);
02067 
02068                 result = __ieee80211_tx(local, &skb, sta, true);
02069         }
02070 
02071         return result;
02072 }
02073 
02074 /*
02075  * Transmit all pending packets. Called from tasklet.
02076  */
02077 void ieee80211_tx_pending(unsigned long data)
02078 {
02079         struct ieee80211_local *local = (struct ieee80211_local *)data;
02080         struct ieee80211_sub_if_data *sdata;
02081         unsigned long flags;
02082         int i;
02083         bool txok;
02084 
02085         rcu_read_lock();
02086 
02087         spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
02088         for (i = 0; i < local->hw.queues; i++) {
02089                 /*
02090                  * If queue is stopped by something other than due to pending
02091                  * frames, or we have no pending frames, proceed to next queue.
02092                  */
02093                 if (local->queue_stop_reasons[i] ||
02094                     skb_queue_empty(&local->pending[i]))
02095                         continue;
02096 
02097                 while (!skb_queue_empty(&local->pending[i])) {
02098                         struct sk_buff *skb = __skb_dequeue(&local->pending[i]);
02099                         struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
02100 
02101                         if (WARN_ON(!info->control.vif)) {
02102                                 kfree_skb(skb);
02103                                 continue;
02104                         }
02105 
02106                         spin_unlock_irqrestore(&local->queue_stop_reason_lock,
02107                                                 flags);
02108 
02109                         txok = ieee80211_tx_pending_skb(local, skb);
02110                         spin_lock_irqsave(&local->queue_stop_reason_lock,
02111                                           flags);
02112                         if (!txok)
02113                                 break;
02114                 }
02115 
02116                 if (skb_queue_empty(&local->pending[i]))
02117                         list_for_each_entry_rcu(sdata, &local->interfaces, list)
02118                                 netif_wake_subqueue(sdata->dev, i);
02119         }
02120         spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
02121 
02122         rcu_read_unlock();
02123 }
02124 
02125 /* functions for drivers to get certain frames */
02126 
02127 static void ieee80211_beacon_add_tim(struct ieee80211_if_ap *bss,
02128                                      struct sk_buff *skb,
02129                                      struct beacon_data *beacon)
02130 {
02131         u8 *pos, *tim;
02132         int aid0 = 0;
02133         int i, have_bits = 0, n1, n2;
02134 
02135         /* Generate bitmap for TIM only if there are any STAs in power save
02136          * mode. */
02137         if (atomic_read(&bss->num_sta_ps) > 0)
02138                 /* in the hope that this is faster than
02139                  * checking byte-for-byte */
02140                 have_bits = !bitmap_empty((unsigned long*)bss->tim,
02141                                           IEEE80211_MAX_AID+1);
02142 
02143         if (bss->dtim_count == 0)
02144                 bss->dtim_count = beacon->dtim_period - 1;
02145         else
02146                 bss->dtim_count--;
02147 
02148         tim = pos = (u8 *) skb_put(skb, 6);
02149         *pos++ = WLAN_EID_TIM;
02150         *pos++ = 4;
02151         *pos++ = bss->dtim_count;
02152         *pos++ = beacon->dtim_period;
02153 
02154         if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf))
02155                 aid0 = 1;
02156 
02157         bss->dtim_bc_mc = aid0 == 1;
02158 
02159         if (have_bits) {
02160                 /* Find largest even number N1 so that bits numbered 1 through
02161                  * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
02162                  * (N2 + 1) x 8 through 2007 are 0. */
02163                 n1 = 0;
02164                 for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
02165                         if (bss->tim[i]) {
02166                                 n1 = i & 0xfe;
02167                                 break;
02168                         }
02169                 }
02170                 n2 = n1;
02171                 for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
02172                         if (bss->tim[i]) {
02173                                 n2 = i;
02174                                 break;
02175                         }
02176                 }
02177 
02178                 /* Bitmap control */
02179                 *pos++ = n1 | aid0;
02180                 /* Part Virt Bitmap */
02181                 memcpy(pos, bss->tim + n1, n2 - n1 + 1);
02182 
02183                 tim[1] = n2 - n1 + 4;
02184                 skb_put(skb, n2 - n1);
02185         } else {
02186                 *pos++ = aid0; /* Bitmap control */
02187                 *pos++ = 0; /* Part Virt Bitmap */
02188         }
02189 }
02190 
02191 struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
02192                                          struct ieee80211_vif *vif,
02193                                          u16 *tim_offset, u16 *tim_length)
02194 {
02195         struct ieee80211_local *local = hw_to_local(hw);
02196         struct sk_buff *skb = NULL;
02197         struct ieee80211_tx_info *info;
02198         struct ieee80211_sub_if_data *sdata = NULL;
02199         struct ieee80211_if_ap *ap = NULL;
02200         struct beacon_data *beacon;
02201         struct ieee80211_supported_band *sband;
02202         enum ieee80211_band band = local->hw.conf.channel->band;
02203         struct ieee80211_tx_rate_control txrc;
02204 
02205         sband = local->hw.wiphy->bands[band];
02206 
02207         rcu_read_lock();
02208 
02209         sdata = vif_to_sdata(vif);
02210 
02211         if (!ieee80211_sdata_running(sdata))
02212                 goto out;
02213 
02214         if (tim_offset)
02215                 *tim_offset = 0;
02216         if (tim_length)
02217                 *tim_length = 0;
02218 
02219         if (sdata->vif.type == NL80211_IFTYPE_AP) {
02220                 ap = &sdata->u.ap;
02221                 beacon = rcu_dereference(ap->beacon);
02222                 if (beacon) {
02223                         /*
02224                          * headroom, head length,
02225                          * tail length and maximum TIM length
02226                          */
02227                         skb = dev_alloc_skb(local->tx_headroom +
02228                                             beacon->head_len +
02229                                             beacon->tail_len + 256);
02230                         if (!skb)
02231                                 goto out;
02232 
02233                         skb_reserve(skb, local->tx_headroom);
02234                         memcpy(skb_put(skb, beacon->head_len), beacon->head,
02235                                beacon->head_len);
02236 
02237                         /*
02238                          * Not very nice, but we want to allow the driver to call
02239                          * ieee80211_beacon_get() as a response to the set_tim()
02240                          * callback. That, however, is already invoked under the
02241                          * sta_lock to guarantee consistent and race-free update
02242                          * of the tim bitmap in mac80211 and the driver.
02243                          */
02244                         if (local->tim_in_locked_section) {
02245                                 ieee80211_beacon_add_tim(ap, skb, beacon);
02246                         } else {
02247                                 unsigned long flags;
02248 
02249                                 spin_lock_irqsave(&local->sta_lock, flags);
02250                                 ieee80211_beacon_add_tim(ap, skb, beacon);
02251                                 spin_unlock_irqrestore(&local->sta_lock, flags);
02252                         }
02253 
02254                         if (tim_offset)
02255                                 *tim_offset = beacon->head_len;
02256                         if (tim_length)
02257                                 *tim_length = skb->len - beacon->head_len;
02258 
02259                         if (beacon->tail)
02260                                 memcpy(skb_put(skb, beacon->tail_len),
02261                                        beacon->tail, beacon->tail_len);
02262                 } else
02263                         goto out;
02264         } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
02265                 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
02266                 struct ieee80211_hdr *hdr;
02267                 struct sk_buff *presp = rcu_dereference(ifibss->presp);
02268 
02269                 if (!presp)
02270                         goto out;
02271 
02272                 skb = skb_copy(presp, GFP_ATOMIC);
02273                 if (!skb)
02274                         goto out;
02275 
02276                 hdr = (struct ieee80211_hdr *) skb->data;
02277                 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
02278                                                  IEEE80211_STYPE_BEACON);
02279         } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
02280                 struct ieee80211_mgmt *mgmt;
02281                 u8 *pos;
02282 
02283 #ifdef CONFIG_MAC80211_MESH
02284                 if (!sdata->u.mesh.mesh_id_len)
02285                         goto out;
02286 #endif
02287 
02288                 /* headroom, head length, tail length and maximum TIM length */
02289                 skb = dev_alloc_skb(local->tx_headroom + 400 +
02290                                 sdata->u.mesh.ie_len);
02291                 if (!skb)
02292                         goto out;
02293 
02294                 skb_reserve(skb, local->hw.extra_tx_headroom);
02295                 mgmt = (struct ieee80211_mgmt *)
02296                         skb_put(skb, 24 + sizeof(mgmt->u.beacon));
02297                 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
02298                 mgmt->frame_control =
02299                     cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
02300                 memset(mgmt->da, 0xff, ETH_ALEN);
02301                 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
02302                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
02303                 mgmt->u.beacon.beacon_int =
02304                         cpu_to_le16(sdata->vif.bss_conf.beacon_int);
02305                 mgmt->u.beacon.capab_info |= cpu_to_le16(
02306                         sdata->u.mesh.security ? WLAN_CAPABILITY_PRIVACY : 0);
02307 
02308                 pos = skb_put(skb, 2);
02309                 *pos++ = WLAN_EID_SSID;
02310                 *pos++ = 0x0;
02311 
02312                 if (ieee80211_add_srates_ie(&sdata->vif, skb) ||
02313                     mesh_add_ds_params_ie(skb, sdata) ||
02314                     ieee80211_add_ext_srates_ie(&sdata->vif, skb) ||
02315                     mesh_add_rsn_ie(skb, sdata) ||
02316                     mesh_add_meshid_ie(skb, sdata) ||
02317                     mesh_add_meshconf_ie(skb, sdata) ||
02318                     mesh_add_vendor_ies(skb, sdata)) {
02319                         pr_err("o11s: couldn't add ies!\n");
02320                         goto out;
02321                 }
02322         } else {
02323                 WARN_ON(1);
02324                 goto out;
02325         }
02326 
02327         info = IEEE80211_SKB_CB(skb);
02328 
02329         info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
02330         info->flags |= IEEE80211_TX_CTL_NO_ACK;
02331         info->band = band;
02332 
02333         memset(&txrc, 0, sizeof(txrc));
02334         txrc.hw = hw;
02335         txrc.sband = sband;
02336         txrc.bss_conf = &sdata->vif.bss_conf;
02337         txrc.skb = skb;
02338         txrc.reported_rate.idx = -1;
02339         txrc.rate_idx_mask = sdata->rc_rateidx_mask[band];
02340         if (txrc.rate_idx_mask == (1 << sband->n_bitrates) - 1)
02341                 txrc.max_rate_idx = -1;
02342         else
02343                 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
02344         txrc.bss = true;
02345         rate_control_get_rate(sdata, NULL, &txrc);
02346 
02347         info->control.vif = vif;
02348 
02349         info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT |
02350                         IEEE80211_TX_CTL_ASSIGN_SEQ |
02351                         IEEE80211_TX_CTL_FIRST_FRAGMENT;
02352  out:
02353         rcu_read_unlock();
02354         return skb;
02355 }
02356 EXPORT_SYMBOL(ieee80211_beacon_get_tim);
02357 
02358 struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw,
02359                                      struct ieee80211_vif *vif)
02360 {
02361         struct ieee80211_sub_if_data *sdata;
02362         struct ieee80211_if_managed *ifmgd;
02363         struct ieee80211_pspoll *pspoll;
02364         struct ieee80211_local *local;
02365         struct sk_buff *skb;
02366 
02367         if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
02368                 return NULL;
02369 
02370         sdata = vif_to_sdata(vif);
02371         ifmgd = &sdata->u.mgd;
02372         local = sdata->local;
02373 
02374         skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
02375         if (!skb)
02376                 return NULL;
02377 
02378         skb_reserve(skb, local->hw.extra_tx_headroom);
02379 
02380         pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
02381         memset(pspoll, 0, sizeof(*pspoll));
02382         pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
02383                                             IEEE80211_STYPE_PSPOLL);
02384         pspoll->aid = cpu_to_le16(ifmgd->aid);
02385 
02386         /* aid in PS-Poll has its two MSBs each set to 1 */
02387         pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
02388 
02389         memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
02390         memcpy(pspoll->ta, vif->addr, ETH_ALEN);
02391 
02392         return skb;
02393 }
02394 EXPORT_SYMBOL(ieee80211_pspoll_get);
02395 
02396 struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw,
02397                                        struct ieee80211_vif *vif)
02398 {
02399         struct ieee80211_hdr_3addr *nullfunc;
02400         struct ieee80211_sub_if_data *sdata;
02401         struct ieee80211_if_managed *ifmgd;
02402         struct ieee80211_local *local;
02403         struct sk_buff *skb;
02404 
02405         if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
02406                 return NULL;
02407 
02408         sdata = vif_to_sdata(vif);
02409         ifmgd = &sdata->u.mgd;
02410         local = sdata->local;
02411 
02412         skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*nullfunc));
02413         if (!skb)
02414                 return NULL;
02415 
02416         skb_reserve(skb, local->hw.extra_tx_headroom);
02417 
02418         nullfunc = (struct ieee80211_hdr_3addr *) skb_put(skb,
02419                                                           sizeof(*nullfunc));
02420         memset(nullfunc, 0, sizeof(*nullfunc));
02421         nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
02422                                               IEEE80211_STYPE_NULLFUNC |
02423                                               IEEE80211_FCTL_TODS);
02424         memcpy(nullfunc->addr1, ifmgd->bssid, ETH_ALEN);
02425         memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
02426         memcpy(nullfunc->addr3, ifmgd->bssid, ETH_ALEN);
02427 
02428         return skb;
02429 }
02430 EXPORT_SYMBOL(ieee80211_nullfunc_get);
02431 
02432 struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw,
02433                                        struct ieee80211_vif *vif,
02434                                        const u8 *ssid, size_t ssid_len,
02435                                        const u8 *ie, size_t ie_len)
02436 {
02437         struct ieee80211_sub_if_data *sdata;
02438         struct ieee80211_local *local;
02439         struct ieee80211_hdr_3addr *hdr;
02440         struct sk_buff *skb;
02441         size_t ie_ssid_len;
02442         u8 *pos;
02443 
02444         sdata = vif_to_sdata(vif);
02445         local = sdata->local;
02446         ie_ssid_len = 2 + ssid_len;
02447 
02448         skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) +
02449                             ie_ssid_len + ie_len);
02450         if (!skb)
02451                 return NULL;
02452 
02453         skb_reserve(skb, local->hw.extra_tx_headroom);
02454 
02455         hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
02456         memset(hdr, 0, sizeof(*hdr));
02457         hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
02458                                          IEEE80211_STYPE_PROBE_REQ);
02459         memset(hdr->addr1, 0xff, ETH_ALEN);
02460         memcpy(hdr->addr2, vif->addr, ETH_ALEN);
02461         memset(hdr->addr3, 0xff, ETH_ALEN);
02462 
02463         pos = skb_put(skb, ie_ssid_len);
02464         *pos++ = WLAN_EID_SSID;
02465         *pos++ = ssid_len;
02466         if (ssid)
02467                 memcpy(pos, ssid, ssid_len);
02468         pos += ssid_len;
02469 
02470         if (ie) {
02471                 pos = skb_put(skb, ie_len);
02472                 memcpy(pos, ie, ie_len);
02473         }
02474 
02475         return skb;
02476 }
02477 EXPORT_SYMBOL(ieee80211_probereq_get);
02478 
02479 void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
02480                        const void *frame, size_t frame_len,
02481                        const struct ieee80211_tx_info *frame_txctl,
02482                        struct ieee80211_rts *rts)
02483 {
02484         const struct ieee80211_hdr *hdr = frame;
02485 
02486         rts->frame_control =
02487             cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
02488         rts->duration = ieee80211_rts_duration(hw, vif, frame_len,
02489                                                frame_txctl);
02490         memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
02491         memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
02492 }
02493 EXPORT_SYMBOL(ieee80211_rts_get);
02494 
02495 void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
02496                              const void *frame, size_t frame_len,
02497                              const struct ieee80211_tx_info *frame_txctl,
02498                              struct ieee80211_cts *cts)
02499 {
02500         const struct ieee80211_hdr *hdr = frame;
02501 
02502         cts->frame_control =
02503             cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
02504         cts->duration = ieee80211_ctstoself_duration(hw, vif,
02505                                                      frame_len, frame_txctl);
02506         memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
02507 }
02508 EXPORT_SYMBOL(ieee80211_ctstoself_get);
02509 
02510 struct sk_buff *
02511 ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
02512                           struct ieee80211_vif *vif)
02513 {
02514         struct ieee80211_local *local = hw_to_local(hw);
02515         struct sk_buff *skb = NULL;
02516         struct ieee80211_tx_data tx;
02517         struct ieee80211_sub_if_data *sdata;
02518         struct ieee80211_if_ap *bss = NULL;
02519         struct beacon_data *beacon;
02520         struct ieee80211_tx_info *info;
02521 
02522         sdata = vif_to_sdata(vif);
02523         bss = &sdata->u.ap;
02524 
02525         rcu_read_lock();
02526         beacon = rcu_dereference(bss->beacon);
02527 
02528         if (sdata->vif.type != NL80211_IFTYPE_AP || !beacon || !beacon->head)
02529                 goto out;
02530 
02531         if (bss->dtim_count != 0 || !bss->dtim_bc_mc)
02532                 goto out; /* send buffered bc/mc only after DTIM beacon */
02533 
02534         while (1) {
02535                 skb = skb_dequeue(&bss->ps_bc_buf);
02536                 if (!skb)
02537                         goto out;
02538                 local->total_ps_buffered--;
02539 
02540                 if (!skb_queue_empty(&bss->ps_bc_buf) && skb->len >= 2) {
02541                         struct ieee80211_hdr *hdr =
02542                                 (struct ieee80211_hdr *) skb->data;
02543                         /* more buffered multicast/broadcast frames ==> set
02544                          * MoreData flag in IEEE 802.11 header to inform PS
02545                          * STAs */
02546                         hdr->frame_control |=
02547                                 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
02548                 }
02549 
02550                 if (!ieee80211_tx_prepare(sdata, &tx, skb))
02551                         break;
02552                 dev_kfree_skb_any(skb);
02553         }
02554 
02555         info = IEEE80211_SKB_CB(skb);
02556 
02557         tx.flags |= IEEE80211_TX_PS_BUFFERED;
02558         tx.channel = local->hw.conf.channel;
02559         info->band = tx.channel->band;
02560 
02561         if (invoke_tx_handlers(&tx))
02562                 skb = NULL;
02563  out:
02564         rcu_read_unlock();
02565 
02566         return skb;
02567 }
02568 EXPORT_SYMBOL(ieee80211_get_buffered_bc);
02569 
02570 void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
02571 {
02572         skb_set_mac_header(skb, 0);
02573         skb_set_network_header(skb, 0);
02574         skb_set_transport_header(skb, 0);
02575 
02576         /* Send all internal mgmt frames on VO. Accordingly set TID to 7. */
02577         skb_set_queue_mapping(skb, IEEE80211_AC_VO);
02578         skb->priority = 7;
02579 
02580         /*
02581          * The other path calling ieee80211_xmit is from the tasklet,
02582          * and while we can handle concurrent transmissions locking
02583          * requirements are that we do not come into tx with bhs on.
02584          */
02585         local_bh_disable();
02586         ieee80211_xmit(sdata, skb);
02587         local_bh_enable();
02588 }


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