2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
5 * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 * Transmit and frame generation functions.
15 #include <linux/kernel.h>
16 #include <linux/slab.h>
17 #include <linux/skbuff.h>
18 #include <linux/etherdevice.h>
19 #include <linux/bitmap.h>
20 #include <linux/rcupdate.h>
21 #include <net/net_namespace.h>
22 #include <net/ieee80211_radiotap.h>
23 #include <net/cfg80211.h>
24 #include <net/mac80211.h>
25 #include <asm/unaligned.h>
27 #include "ieee80211_i.h"
28 #include "driver-ops.h"
36 #define IEEE80211_TX_OK 0
37 #define IEEE80211_TX_AGAIN 1
38 #define IEEE80211_TX_PENDING 2
42 static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
45 int rate, mrate, erp, dur, i;
46 struct ieee80211_rate *txrate;
47 struct ieee80211_local *local = tx->local;
48 struct ieee80211_supported_band *sband;
49 struct ieee80211_hdr *hdr;
50 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
52 /* assume HW handles this */
53 if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
57 if (WARN_ON_ONCE(info->control.rates[0].idx < 0))
60 sband = local->hw.wiphy->bands[tx->channel->band];
61 txrate = &sband->bitrates[info->control.rates[0].idx];
63 erp = txrate->flags & IEEE80211_RATE_ERP_G;
66 * data and mgmt (except PS Poll):
68 * - during contention period:
69 * if addr1 is group address: 0
70 * if more fragments = 0 and addr1 is individual address: time to
71 * transmit one ACK plus SIFS
72 * if more fragments = 1 and addr1 is individual address: time to
73 * transmit next fragment plus 2 x ACK plus 3 x SIFS
76 * - control response frame (CTS or ACK) shall be transmitted using the
77 * same rate as the immediately previous frame in the frame exchange
78 * sequence, if this rate belongs to the PHY mandatory rates, or else
79 * at the highest possible rate belonging to the PHY rates in the
82 hdr = (struct ieee80211_hdr *)tx->skb->data;
83 if (ieee80211_is_ctl(hdr->frame_control)) {
84 /* TODO: These control frames are not currently sent by
85 * mac80211, but should they be implemented, this function
86 * needs to be updated to support duration field calculation.
88 * RTS: time needed to transmit pending data/mgmt frame plus
89 * one CTS frame plus one ACK frame plus 3 x SIFS
90 * CTS: duration of immediately previous RTS minus time
91 * required to transmit CTS and its SIFS
92 * ACK: 0 if immediately previous directed data/mgmt had
93 * more=0, with more=1 duration in ACK frame is duration
94 * from previous frame minus time needed to transmit ACK
96 * PS Poll: BIT(15) | BIT(14) | aid
102 if (0 /* FIX: data/mgmt during CFP */)
103 return cpu_to_le16(32768);
105 if (group_addr) /* Group address as the destination - no ACK */
108 /* Individual destination address:
109 * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
110 * CTS and ACK frames shall be transmitted using the highest rate in
111 * basic rate set that is less than or equal to the rate of the
112 * immediately previous frame and that is using the same modulation
113 * (CCK or OFDM). If no basic rate set matches with these requirements,
114 * the highest mandatory rate of the PHY that is less than or equal to
115 * the rate of the previous frame is used.
116 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
119 /* use lowest available if everything fails */
120 mrate = sband->bitrates[0].bitrate;
121 for (i = 0; i < sband->n_bitrates; i++) {
122 struct ieee80211_rate *r = &sband->bitrates[i];
124 if (r->bitrate > txrate->bitrate)
127 if (tx->sdata->vif.bss_conf.basic_rates & BIT(i))
130 switch (sband->band) {
131 case IEEE80211_BAND_2GHZ: {
133 if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
134 flag = IEEE80211_RATE_MANDATORY_G;
136 flag = IEEE80211_RATE_MANDATORY_B;
141 case IEEE80211_BAND_5GHZ:
142 if (r->flags & IEEE80211_RATE_MANDATORY_A)
145 case IEEE80211_NUM_BANDS:
151 /* No matching basic rate found; use highest suitable mandatory
156 /* Time needed to transmit ACK
157 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
158 * to closest integer */
160 dur = ieee80211_frame_duration(local, 10, rate, erp,
161 tx->sdata->vif.bss_conf.use_short_preamble);
164 /* Frame is fragmented: duration increases with time needed to
165 * transmit next fragment plus ACK and 2 x SIFS. */
166 dur *= 2; /* ACK + SIFS */
168 dur += ieee80211_frame_duration(local, next_frag_len,
169 txrate->bitrate, erp,
170 tx->sdata->vif.bss_conf.use_short_preamble);
173 return cpu_to_le16(dur);
176 static int inline is_ieee80211_device(struct ieee80211_local *local,
177 struct net_device *dev)
179 return local == wdev_priv(dev->ieee80211_ptr);
183 static ieee80211_tx_result debug_noinline
184 ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx)
186 struct ieee80211_local *local = tx->local;
188 /* driver doesn't support power save */
189 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
192 /* hardware does dynamic power save */
193 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
196 /* dynamic power save disabled */
197 if (local->hw.conf.dynamic_ps_timeout <= 0)
200 /* we are scanning, don't enable power save */
204 if (!local->ps_sdata)
207 /* No point if we're going to suspend */
208 if (local->quiescing)
211 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
212 ieee80211_stop_queues_by_reason(&local->hw,
213 IEEE80211_QUEUE_STOP_REASON_PS);
214 ieee80211_queue_work(&local->hw,
215 &local->dynamic_ps_disable_work);
218 mod_timer(&local->dynamic_ps_timer, jiffies +
219 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
224 static ieee80211_tx_result debug_noinline
225 ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
228 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
229 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
232 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED))
235 if (unlikely(test_bit(SCAN_OFF_CHANNEL, &tx->local->scanning)) &&
236 !ieee80211_is_probe_req(hdr->frame_control) &&
237 !ieee80211_is_nullfunc(hdr->frame_control))
239 * When software scanning only nullfunc frames (to notify
240 * the sleep state to the AP) and probe requests (for the
241 * active scan) are allowed, all other frames should not be
242 * sent and we should not get here, but if we do
243 * nonetheless, drop them to avoid sending them
244 * off-channel. See the link below and
245 * ieee80211_start_scan() for more.
247 * http://article.gmane.org/gmane.linux.kernel.wireless.general/30089
251 if (tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
254 if (tx->flags & IEEE80211_TX_PS_BUFFERED)
257 sta_flags = tx->sta ? get_sta_flags(tx->sta) : 0;
259 if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
260 if (unlikely(!(sta_flags & WLAN_STA_ASSOC) &&
261 tx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
262 ieee80211_is_data(hdr->frame_control))) {
263 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
264 printk(KERN_DEBUG "%s: dropped data frame to not "
265 "associated station %pM\n",
266 tx->sdata->name, hdr->addr1);
267 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
268 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
272 if (unlikely(ieee80211_is_data(hdr->frame_control) &&
273 tx->local->num_sta == 0 &&
274 tx->sdata->vif.type != NL80211_IFTYPE_ADHOC)) {
276 * No associated STAs - no need to send multicast
287 /* This function is called whenever the AP is about to exceed the maximum limit
288 * of buffered frames for power saving STAs. This situation should not really
289 * happen often during normal operation, so dropping the oldest buffered packet
290 * from each queue should be OK to make some room for new frames. */
291 static void purge_old_ps_buffers(struct ieee80211_local *local)
293 int total = 0, purged = 0;
295 struct ieee80211_sub_if_data *sdata;
296 struct sta_info *sta;
299 * virtual interfaces are protected by RCU
303 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
304 struct ieee80211_if_ap *ap;
305 if (sdata->vif.type != NL80211_IFTYPE_AP)
308 skb = skb_dequeue(&ap->ps_bc_buf);
313 total += skb_queue_len(&ap->ps_bc_buf);
316 list_for_each_entry_rcu(sta, &local->sta_list, list) {
317 skb = skb_dequeue(&sta->ps_tx_buf);
322 total += skb_queue_len(&sta->ps_tx_buf);
327 local->total_ps_buffered = total;
328 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
329 printk(KERN_DEBUG "%s: PS buffers full - purged %d frames\n",
330 wiphy_name(local->hw.wiphy), purged);
334 static ieee80211_tx_result
335 ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
337 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
338 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
341 * broadcast/multicast frame
343 * If any of the associated stations is in power save mode,
344 * the frame is buffered to be sent after DTIM beacon frame.
345 * This is done either by the hardware or us.
348 /* powersaving STAs only in AP/VLAN mode */
352 /* no buffering for ordered frames */
353 if (ieee80211_has_order(hdr->frame_control))
356 /* no stations in PS mode */
357 if (!atomic_read(&tx->sdata->bss->num_sta_ps))
360 info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM;
362 /* device releases frame after DTIM beacon */
363 if (!(tx->local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING))
366 /* buffered in mac80211 */
367 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
368 purge_old_ps_buffers(tx->local);
370 if (skb_queue_len(&tx->sdata->bss->ps_bc_buf) >= AP_MAX_BC_BUFFER) {
371 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
373 printk(KERN_DEBUG "%s: BC TX buffer full - dropping the oldest frame\n",
376 dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf));
378 tx->local->total_ps_buffered++;
380 skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb);
385 static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta,
388 if (!ieee80211_is_mgmt(fc))
391 if (sta == NULL || !test_sta_flags(sta, WLAN_STA_MFP))
394 if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *)
401 static ieee80211_tx_result
402 ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
404 struct sta_info *sta = tx->sta;
405 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
406 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
410 ieee80211_is_probe_resp(hdr->frame_control) ||
411 ieee80211_is_auth(hdr->frame_control) ||
412 ieee80211_is_assoc_resp(hdr->frame_control) ||
413 ieee80211_is_reassoc_resp(hdr->frame_control)))
416 staflags = get_sta_flags(sta);
418 if (unlikely((staflags & (WLAN_STA_PS_STA | WLAN_STA_PS_DRIVER)) &&
419 !(info->flags & IEEE80211_TX_CTL_PSPOLL_RESPONSE))) {
420 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
421 printk(KERN_DEBUG "STA %pM aid %d: PS buffer (entries "
423 sta->sta.addr, sta->sta.aid,
424 skb_queue_len(&sta->ps_tx_buf));
425 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
426 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
427 purge_old_ps_buffers(tx->local);
428 if (skb_queue_len(&sta->ps_tx_buf) >= STA_MAX_TX_BUFFER) {
429 struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf);
430 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
431 if (net_ratelimit()) {
432 printk(KERN_DEBUG "%s: STA %pM TX "
433 "buffer full - dropping oldest frame\n",
434 tx->sdata->name, sta->sta.addr);
439 tx->local->total_ps_buffered++;
442 * Queue frame to be sent after STA wakes up/polls,
443 * but don't set the TIM bit if the driver is blocking
444 * wakeup or poll response transmissions anyway.
446 if (skb_queue_empty(&sta->ps_tx_buf) &&
447 !(staflags & WLAN_STA_PS_DRIVER))
448 sta_info_set_tim_bit(sta);
450 info->control.jiffies = jiffies;
451 info->control.vif = &tx->sdata->vif;
452 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
453 skb_queue_tail(&sta->ps_tx_buf, tx->skb);
456 #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
457 else if (unlikely(staflags & WLAN_STA_PS_STA)) {
458 printk(KERN_DEBUG "%s: STA %pM in PS mode, but pspoll "
459 "set -> send frame\n", tx->sdata->name,
462 #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
467 static ieee80211_tx_result debug_noinline
468 ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
470 if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED))
473 if (tx->flags & IEEE80211_TX_UNICAST)
474 return ieee80211_tx_h_unicast_ps_buf(tx);
476 return ieee80211_tx_h_multicast_ps_buf(tx);
479 static ieee80211_tx_result debug_noinline
480 ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
482 struct ieee80211_key *key = NULL;
483 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
484 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
486 if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT))
488 else if (tx->sta && (key = rcu_dereference(tx->sta->key)))
490 else if (ieee80211_is_mgmt(hdr->frame_control) &&
491 (key = rcu_dereference(tx->sdata->default_mgmt_key)))
493 else if ((key = rcu_dereference(tx->sdata->default_key)))
495 else if (tx->sdata->drop_unencrypted &&
496 (tx->skb->protocol != cpu_to_be16(ETH_P_PAE)) &&
497 !(info->flags & IEEE80211_TX_CTL_INJECTED) &&
498 (!ieee80211_is_robust_mgmt_frame(hdr) ||
499 (ieee80211_is_action(hdr->frame_control) &&
500 tx->sta && test_sta_flags(tx->sta, WLAN_STA_MFP)))) {
501 I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
507 tx->key->tx_rx_count++;
508 /* TODO: add threshold stuff again */
510 switch (tx->key->conf.alg) {
512 if (ieee80211_is_auth(hdr->frame_control))
515 if (!ieee80211_is_data_present(hdr->frame_control))
519 if (!ieee80211_is_data_present(hdr->frame_control) &&
520 !ieee80211_use_mfp(hdr->frame_control, tx->sta,
525 if (!ieee80211_is_mgmt(hdr->frame_control))
531 if (!tx->key || !(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
532 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
537 static ieee80211_tx_result debug_noinline
538 ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
540 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
541 struct ieee80211_hdr *hdr = (void *)tx->skb->data;
542 struct ieee80211_supported_band *sband;
543 struct ieee80211_rate *rate;
545 bool inval = false, rts = false, short_preamble = false;
546 struct ieee80211_tx_rate_control txrc;
549 memset(&txrc, 0, sizeof(txrc));
551 sband = tx->local->hw.wiphy->bands[tx->channel->band];
553 len = min_t(int, tx->skb->len + FCS_LEN,
554 tx->local->hw.wiphy->frag_threshold);
556 /* set up the tx rate control struct we give the RC algo */
557 txrc.hw = local_to_hw(tx->local);
559 txrc.bss_conf = &tx->sdata->vif.bss_conf;
561 txrc.reported_rate.idx = -1;
562 txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[tx->channel->band];
563 if (txrc.rate_idx_mask == (1 << sband->n_bitrates) - 1)
564 txrc.max_rate_idx = -1;
566 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
567 txrc.ap = tx->sdata->vif.type == NL80211_IFTYPE_AP;
569 /* set up RTS protection if desired */
570 if (len > tx->local->hw.wiphy->rts_threshold) {
571 txrc.rts = rts = true;
575 * Use short preamble if the BSS can handle it, but not for
576 * management frames unless we know the receiver can handle
577 * that -- the management frame might be to a station that
578 * just wants a probe response.
580 if (tx->sdata->vif.bss_conf.use_short_preamble &&
581 (ieee80211_is_data(hdr->frame_control) ||
582 (tx->sta && test_sta_flags(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
583 txrc.short_preamble = short_preamble = true;
585 sta_flags = tx->sta ? get_sta_flags(tx->sta) : 0;
588 * Lets not bother rate control if we're associated and cannot
589 * talk to the sta. This should not happen.
591 if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) &&
592 (sta_flags & WLAN_STA_ASSOC) &&
593 !rate_usable_index_exists(sband, &tx->sta->sta),
594 "%s: Dropped data frame as no usable bitrate found while "
595 "scanning and associated. Target station: "
596 "%pM on %d GHz band\n",
597 tx->sdata->name, hdr->addr1,
598 tx->channel->band ? 5 : 2))
602 * If we're associated with the sta at this point we know we can at
603 * least send the frame at the lowest bit rate.
605 rate_control_get_rate(tx->sdata, tx->sta, &txrc);
607 if (unlikely(info->control.rates[0].idx < 0))
610 if (txrc.reported_rate.idx < 0)
611 txrc.reported_rate = info->control.rates[0];
614 tx->sta->last_tx_rate = txrc.reported_rate;
616 if (unlikely(!info->control.rates[0].count))
617 info->control.rates[0].count = 1;
619 if (WARN_ON_ONCE((info->control.rates[0].count > 1) &&
620 (info->flags & IEEE80211_TX_CTL_NO_ACK)))
621 info->control.rates[0].count = 1;
623 if (is_multicast_ether_addr(hdr->addr1)) {
625 * XXX: verify the rate is in the basic rateset
631 * set up the RTS/CTS rate as the fastest basic rate
632 * that is not faster than the data rate
634 * XXX: Should this check all retry rates?
636 if (!(info->control.rates[0].flags & IEEE80211_TX_RC_MCS)) {
639 rate = &sband->bitrates[info->control.rates[0].idx];
641 for (i = 0; i < sband->n_bitrates; i++) {
642 /* must be a basic rate */
643 if (!(tx->sdata->vif.bss_conf.basic_rates & BIT(i)))
645 /* must not be faster than the data rate */
646 if (sband->bitrates[i].bitrate > rate->bitrate)
649 if (sband->bitrates[baserate].bitrate <
650 sband->bitrates[i].bitrate)
654 info->control.rts_cts_rate_idx = baserate;
657 for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) {
659 * make sure there's no valid rate following
660 * an invalid one, just in case drivers don't
661 * take the API seriously to stop at -1.
664 info->control.rates[i].idx = -1;
667 if (info->control.rates[i].idx < 0) {
673 * For now assume MCS is already set up correctly, this
676 if (info->control.rates[i].flags & IEEE80211_TX_RC_MCS) {
677 WARN_ON(info->control.rates[i].idx > 76);
681 /* set up RTS protection if desired */
683 info->control.rates[i].flags |=
684 IEEE80211_TX_RC_USE_RTS_CTS;
687 if (WARN_ON_ONCE(info->control.rates[i].idx >=
688 sband->n_bitrates)) {
689 info->control.rates[i].idx = -1;
693 rate = &sband->bitrates[info->control.rates[i].idx];
695 /* set up short preamble */
696 if (short_preamble &&
697 rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
698 info->control.rates[i].flags |=
699 IEEE80211_TX_RC_USE_SHORT_PREAMBLE;
701 /* set up G protection */
702 if (!rts && tx->sdata->vif.bss_conf.use_cts_prot &&
703 rate->flags & IEEE80211_RATE_ERP_G)
704 info->control.rates[i].flags |=
705 IEEE80211_TX_RC_USE_CTS_PROTECT;
711 static ieee80211_tx_result debug_noinline
712 ieee80211_tx_h_misc(struct ieee80211_tx_data *tx)
714 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
717 info->control.sta = &tx->sta->sta;
722 static ieee80211_tx_result debug_noinline
723 ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
725 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
726 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
732 * Packet injection may want to control the sequence
733 * number, if we have no matching interface then we
734 * neither assign one ourselves nor ask the driver to.
736 if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR))
739 if (unlikely(ieee80211_is_ctl(hdr->frame_control)))
742 if (ieee80211_hdrlen(hdr->frame_control) < 24)
746 * Anything but QoS data that has a sequence number field
747 * (is long enough) gets a sequence number from the global
750 if (!ieee80211_is_data_qos(hdr->frame_control)) {
751 /* driver should assign sequence number */
752 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
753 /* for pure STA mode without beacons, we can do it */
754 hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number);
755 tx->sdata->sequence_number += 0x10;
760 * This should be true for injected/management frames only, for
761 * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ
762 * above since they are not QoS-data frames.
767 /* include per-STA, per-TID sequence counter */
769 qc = ieee80211_get_qos_ctl(hdr);
770 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
771 seq = &tx->sta->tid_seq[tid];
773 hdr->seq_ctrl = cpu_to_le16(*seq);
775 /* Increase the sequence number. */
776 *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ;
781 static int ieee80211_fragment(struct ieee80211_local *local,
782 struct sk_buff *skb, int hdrlen,
785 struct sk_buff *tail = skb, *tmp;
786 int per_fragm = frag_threshold - hdrlen - FCS_LEN;
787 int pos = hdrlen + per_fragm;
788 int rem = skb->len - hdrlen - per_fragm;
790 if (WARN_ON(rem < 0))
794 int fraglen = per_fragm;
799 tmp = dev_alloc_skb(local->tx_headroom +
801 IEEE80211_ENCRYPT_HEADROOM +
802 IEEE80211_ENCRYPT_TAILROOM);
807 skb_reserve(tmp, local->tx_headroom +
808 IEEE80211_ENCRYPT_HEADROOM);
809 /* copy control information */
810 memcpy(tmp->cb, skb->cb, sizeof(tmp->cb));
811 skb_copy_queue_mapping(tmp, skb);
812 tmp->priority = skb->priority;
815 /* copy header and data */
816 memcpy(skb_put(tmp, hdrlen), skb->data, hdrlen);
817 memcpy(skb_put(tmp, fraglen), skb->data + pos, fraglen);
822 skb->len = hdrlen + per_fragm;
826 static ieee80211_tx_result debug_noinline
827 ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
829 struct sk_buff *skb = tx->skb;
830 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
831 struct ieee80211_hdr *hdr = (void *)skb->data;
832 int frag_threshold = tx->local->hw.wiphy->frag_threshold;
836 if (!(tx->flags & IEEE80211_TX_FRAGMENTED))
840 * Warn when submitting a fragmented A-MPDU frame and drop it.
841 * This scenario is handled in ieee80211_tx_prepare but extra
842 * caution taken here as fragmented ampdu may cause Tx stop.
844 if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
847 hdrlen = ieee80211_hdrlen(hdr->frame_control);
849 /* internal error, why is TX_FRAGMENTED set? */
850 if (WARN_ON(skb->len + FCS_LEN <= frag_threshold))
854 * Now fragment the frame. This will allocate all the fragments and
855 * chain them (using skb as the first fragment) to skb->next.
856 * During transmission, we will remove the successfully transmitted
857 * fragments from this list. When the low-level driver rejects one
858 * of the fragments then we will simply pretend to accept the skb
859 * but store it away as pending.
861 if (ieee80211_fragment(tx->local, skb, hdrlen, frag_threshold))
864 /* update duration/seq/flags of fragments */
868 const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
870 hdr = (void *)skb->data;
871 info = IEEE80211_SKB_CB(skb);
874 hdr->frame_control |= morefrags;
875 next_len = skb->next->len;
877 * No multi-rate retries for fragmented frames, that
878 * would completely throw off the NAV at other STAs.
880 info->control.rates[1].idx = -1;
881 info->control.rates[2].idx = -1;
882 info->control.rates[3].idx = -1;
883 info->control.rates[4].idx = -1;
884 BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 5);
885 info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
887 hdr->frame_control &= ~morefrags;
890 hdr->duration_id = ieee80211_duration(tx, 0, next_len);
891 hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG);
893 } while ((skb = skb->next));
898 static ieee80211_tx_result debug_noinline
899 ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
901 struct sk_buff *skb = tx->skb;
906 tx->sta->tx_packets++;
908 tx->sta->tx_fragments++;
909 tx->sta->tx_bytes += skb->len;
910 } while ((skb = skb->next));
915 static ieee80211_tx_result debug_noinline
916 ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
921 switch (tx->key->conf.alg) {
923 return ieee80211_crypto_wep_encrypt(tx);
925 return ieee80211_crypto_tkip_encrypt(tx);
927 return ieee80211_crypto_ccmp_encrypt(tx);
929 return ieee80211_crypto_aes_cmac_encrypt(tx);
937 static ieee80211_tx_result debug_noinline
938 ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx)
940 struct sk_buff *skb = tx->skb;
941 struct ieee80211_hdr *hdr;
946 hdr = (void *) skb->data;
947 if (unlikely(ieee80211_is_pspoll(hdr->frame_control)))
948 break; /* must not overwrite AID */
949 next_len = skb->next ? skb->next->len : 0;
950 group_addr = is_multicast_ether_addr(hdr->addr1);
953 ieee80211_duration(tx, group_addr, next_len);
954 } while ((skb = skb->next));
959 /* actual transmit path */
962 * deal with packet injection down monitor interface
963 * with Radiotap Header -- only called for monitor mode interface
965 static bool __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
969 * this is the moment to interpret and discard the radiotap header that
970 * must be at the start of the packet injected in Monitor mode
972 * Need to take some care with endian-ness since radiotap
973 * args are little-endian
976 struct ieee80211_radiotap_iterator iterator;
977 struct ieee80211_radiotap_header *rthdr =
978 (struct ieee80211_radiotap_header *) skb->data;
979 struct ieee80211_supported_band *sband;
980 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
981 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len);
983 sband = tx->local->hw.wiphy->bands[tx->channel->band];
985 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
986 tx->flags &= ~IEEE80211_TX_FRAGMENTED;
989 * for every radiotap entry that is present
990 * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
991 * entries present, or -EINVAL on error)
995 ret = ieee80211_radiotap_iterator_next(&iterator);
1000 /* see if this argument is something we can use */
1001 switch (iterator.this_arg_index) {
1003 * You must take care when dereferencing iterator.this_arg
1004 * for multibyte types... the pointer is not aligned. Use
1005 * get_unaligned((type *)iterator.this_arg) to dereference
1006 * iterator.this_arg for type "type" safely on all arches.
1008 case IEEE80211_RADIOTAP_FLAGS:
1009 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
1011 * this indicates that the skb we have been
1012 * handed has the 32-bit FCS CRC at the end...
1013 * we should react to that by snipping it off
1014 * because it will be recomputed and added
1017 if (skb->len < (iterator.max_length + FCS_LEN))
1020 skb_trim(skb, skb->len - FCS_LEN);
1022 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
1023 info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT;
1024 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
1025 tx->flags |= IEEE80211_TX_FRAGMENTED;
1029 * Please update the file
1030 * Documentation/networking/mac80211-injection.txt
1031 * when parsing new fields here.
1039 if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
1043 * remove the radiotap header
1044 * iterator->max_length was sanity-checked against
1045 * skb->len by iterator init
1047 skb_pull(skb, iterator.max_length);
1055 static ieee80211_tx_result
1056 ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
1057 struct ieee80211_tx_data *tx,
1058 struct sk_buff *skb)
1060 struct ieee80211_local *local = sdata->local;
1061 struct ieee80211_hdr *hdr;
1062 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1065 bool queued = false;
1067 memset(tx, 0, sizeof(*tx));
1071 tx->channel = local->hw.conf.channel;
1073 * Set this flag (used below to indicate "automatic fragmentation"),
1074 * it will be cleared/left by radiotap as desired.
1076 tx->flags |= IEEE80211_TX_FRAGMENTED;
1078 /* process and remove the injection radiotap header */
1079 if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) {
1080 if (!__ieee80211_parse_tx_radiotap(tx, skb))
1084 * __ieee80211_parse_tx_radiotap has now removed
1085 * the radiotap header that was present and pre-filled
1086 * 'tx' with tx control information.
1091 * If this flag is set to true anywhere, and we get here,
1092 * we are doing the needed processing, so remove the flag
1095 info->flags &= ~IEEE80211_TX_INTFL_NEED_TXPROCESSING;
1097 hdr = (struct ieee80211_hdr *) skb->data;
1099 if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
1100 tx->sta = rcu_dereference(sdata->u.vlan.sta);
1101 if (!tx->sta && sdata->dev->ieee80211_ptr->use_4addr)
1105 tx->sta = sta_info_get(sdata, hdr->addr1);
1107 if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) &&
1108 (local->hw.flags & IEEE80211_HW_AMPDU_AGGREGATION)) {
1109 unsigned long flags;
1110 struct tid_ampdu_tx *tid_tx;
1112 qc = ieee80211_get_qos_ctl(hdr);
1113 tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
1115 spin_lock_irqsave(&tx->sta->lock, flags);
1117 * XXX: This spinlock could be fairly expensive, but see the
1118 * comment in agg-tx.c:ieee80211_agg_tx_operational().
1119 * One way to solve this would be to do something RCU-like
1120 * for managing the tid_tx struct and using atomic bitops
1121 * for the actual state -- by introducing an actual
1122 * 'operational' bit that would be possible. It would
1123 * require changing ieee80211_agg_tx_operational() to
1124 * set that bit, and changing the way tid_tx is managed
1125 * everywhere, including races between that bit and
1126 * tid_tx going away (tid_tx being added can be easily
1127 * committed to memory before the 'operational' bit).
1129 tid_tx = tx->sta->ampdu_mlme.tid_tx[tid];
1130 state = &tx->sta->ampdu_mlme.tid_state_tx[tid];
1131 if (*state == HT_AGG_STATE_OPERATIONAL) {
1132 info->flags |= IEEE80211_TX_CTL_AMPDU;
1133 } else if (*state != HT_AGG_STATE_IDLE) {
1136 info->control.vif = &sdata->vif;
1137 info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
1138 __skb_queue_tail(&tid_tx->pending, skb);
1140 spin_unlock_irqrestore(&tx->sta->lock, flags);
1142 if (unlikely(queued))
1146 if (is_multicast_ether_addr(hdr->addr1)) {
1147 tx->flags &= ~IEEE80211_TX_UNICAST;
1148 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1150 tx->flags |= IEEE80211_TX_UNICAST;
1151 if (unlikely(local->wifi_wme_noack_test))
1152 info->flags |= IEEE80211_TX_CTL_NO_ACK;
1154 info->flags &= ~IEEE80211_TX_CTL_NO_ACK;
1157 if (tx->flags & IEEE80211_TX_FRAGMENTED) {
1158 if ((tx->flags & IEEE80211_TX_UNICAST) &&
1159 skb->len + FCS_LEN > local->hw.wiphy->frag_threshold &&
1160 !(info->flags & IEEE80211_TX_CTL_AMPDU))
1161 tx->flags |= IEEE80211_TX_FRAGMENTED;
1163 tx->flags &= ~IEEE80211_TX_FRAGMENTED;
1167 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1168 else if (test_and_clear_sta_flags(tx->sta, WLAN_STA_CLEAR_PS_FILT))
1169 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
1171 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1172 if (skb->len > hdrlen + sizeof(rfc1042_header) + 2) {
1173 u8 *pos = &skb->data[hdrlen + sizeof(rfc1042_header)];
1174 tx->ethertype = (pos[0] << 8) | pos[1];
1176 info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT;
1181 static int __ieee80211_tx(struct ieee80211_local *local,
1182 struct sk_buff **skbp,
1183 struct sta_info *sta,
1186 struct sk_buff *skb = *skbp, *next;
1187 struct ieee80211_tx_info *info;
1188 struct ieee80211_sub_if_data *sdata;
1189 unsigned long flags;
1194 int q = skb_get_queue_mapping(skb);
1196 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1197 ret = IEEE80211_TX_OK;
1198 if (local->queue_stop_reasons[q] ||
1199 (!txpending && !skb_queue_empty(&local->pending[q])))
1200 ret = IEEE80211_TX_PENDING;
1201 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1202 if (ret != IEEE80211_TX_OK)
1205 info = IEEE80211_SKB_CB(skb);
1208 info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT |
1209 IEEE80211_TX_CTL_FIRST_FRAGMENT);
1215 info->flags |= IEEE80211_TX_CTL_MORE_FRAMES;
1217 sdata = vif_to_sdata(info->control.vif);
1219 switch (sdata->vif.type) {
1220 case NL80211_IFTYPE_MONITOR:
1221 info->control.vif = NULL;
1223 case NL80211_IFTYPE_AP_VLAN:
1224 info->control.vif = &container_of(sdata->bss,
1225 struct ieee80211_sub_if_data, u.ap)->vif;
1232 ret = drv_tx(local, skb);
1233 if (WARN_ON(ret != NETDEV_TX_OK && skb->len != len)) {
1237 if (ret != NETDEV_TX_OK) {
1238 info->control.vif = &sdata->vif;
1239 return IEEE80211_TX_AGAIN;
1243 ieee80211_led_tx(local, 1);
1247 return IEEE80211_TX_OK;
1251 * Invoke TX handlers, return 0 on success and non-zero if the
1252 * frame was dropped or queued.
1254 static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
1256 struct sk_buff *skb = tx->skb;
1257 ieee80211_tx_result res = TX_DROP;
1259 #define CALL_TXH(txh) \
1262 if (res != TX_CONTINUE) \
1266 CALL_TXH(ieee80211_tx_h_dynamic_ps);
1267 CALL_TXH(ieee80211_tx_h_check_assoc);
1268 CALL_TXH(ieee80211_tx_h_ps_buf);
1269 CALL_TXH(ieee80211_tx_h_select_key);
1270 CALL_TXH(ieee80211_tx_h_michael_mic_add);
1271 if (!(tx->local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL))
1272 CALL_TXH(ieee80211_tx_h_rate_ctrl);
1273 CALL_TXH(ieee80211_tx_h_misc);
1274 CALL_TXH(ieee80211_tx_h_sequence);
1275 CALL_TXH(ieee80211_tx_h_fragment);
1276 /* handlers after fragment must be aware of tx info fragmentation! */
1277 CALL_TXH(ieee80211_tx_h_stats);
1278 CALL_TXH(ieee80211_tx_h_encrypt);
1279 CALL_TXH(ieee80211_tx_h_calculate_duration);
1283 if (unlikely(res == TX_DROP)) {
1284 I802_DEBUG_INC(tx->local->tx_handlers_drop);
1286 struct sk_buff *next;
1293 } else if (unlikely(res == TX_QUEUED)) {
1294 I802_DEBUG_INC(tx->local->tx_handlers_queued);
1301 static void ieee80211_tx(struct ieee80211_sub_if_data *sdata,
1302 struct sk_buff *skb, bool txpending)
1304 struct ieee80211_local *local = sdata->local;
1305 struct ieee80211_tx_data tx;
1306 ieee80211_tx_result res_prepare;
1307 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1308 struct sk_buff *next;
1309 unsigned long flags;
1313 queue = skb_get_queue_mapping(skb);
1315 if (unlikely(skb->len < 10)) {
1322 /* initialises tx */
1323 res_prepare = ieee80211_tx_prepare(sdata, &tx, skb);
1325 if (unlikely(res_prepare == TX_DROP)) {
1329 } else if (unlikely(res_prepare == TX_QUEUED)) {
1334 tx.channel = local->hw.conf.channel;
1335 info->band = tx.channel->band;
1337 if (invoke_tx_handlers(&tx))
1342 ret = __ieee80211_tx(local, &tx.skb, tx.sta, txpending);
1344 case IEEE80211_TX_OK:
1346 case IEEE80211_TX_AGAIN:
1348 * Since there are no fragmented frames on A-MPDU
1349 * queues, there's no reason for a driver to reject
1350 * a frame there, warn and drop it.
1352 if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
1355 case IEEE80211_TX_PENDING:
1358 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1360 if (local->queue_stop_reasons[queue] ||
1361 !skb_queue_empty(&local->pending[queue])) {
1363 * if queue is stopped, queue up frames for later
1364 * transmission from the tasklet
1369 if (unlikely(txpending))
1370 __skb_queue_head(&local->pending[queue],
1373 __skb_queue_tail(&local->pending[queue],
1375 } while ((skb = next));
1377 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1381 * otherwise retry, but this is a race condition or
1382 * a driver bug (which we warn about if it persists)
1384 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1388 if (WARN(retries > 10, "tx refused but queue active\n"))
1408 /* device xmit handlers */
1410 static int ieee80211_skb_resize(struct ieee80211_local *local,
1411 struct sk_buff *skb,
1412 int head_need, bool may_encrypt)
1417 * This could be optimised, devices that do full hardware
1418 * crypto (including TKIP MMIC) need no tailroom... But we
1419 * have no drivers for such devices currently.
1422 tail_need = IEEE80211_ENCRYPT_TAILROOM;
1423 tail_need -= skb_tailroom(skb);
1424 tail_need = max_t(int, tail_need, 0);
1427 if (head_need || tail_need) {
1428 /* Sorry. Can't account for this any more */
1432 if (skb_header_cloned(skb))
1433 I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
1435 I802_DEBUG_INC(local->tx_expand_skb_head);
1437 if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) {
1438 printk(KERN_DEBUG "%s: failed to reallocate TX buffer\n",
1439 wiphy_name(local->hw.wiphy));
1443 /* update truesize too */
1444 skb->truesize += head_need + tail_need;
1449 static void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
1450 struct sk_buff *skb)
1452 struct ieee80211_local *local = sdata->local;
1453 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1454 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
1455 struct ieee80211_sub_if_data *tmp_sdata;
1461 if (unlikely(sdata->vif.type == NL80211_IFTYPE_MONITOR)) {
1465 info->flags |= IEEE80211_TX_CTL_INJECTED;
1467 len_rthdr = ieee80211_get_radiotap_len(skb->data);
1468 hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
1469 hdrlen = ieee80211_hdrlen(hdr->frame_control);
1471 /* check the header is complete in the frame */
1472 if (likely(skb->len >= len_rthdr + hdrlen)) {
1474 * We process outgoing injected frames that have a
1475 * local address we handle as though they are our
1477 * This code here isn't entirely correct, the local
1478 * MAC address is not necessarily enough to find
1479 * the interface to use; for that proper VLAN/WDS
1480 * support we will need a different mechanism.
1483 list_for_each_entry_rcu(tmp_sdata, &local->interfaces,
1485 if (!ieee80211_sdata_running(tmp_sdata))
1487 if (tmp_sdata->vif.type != NL80211_IFTYPE_AP)
1489 if (compare_ether_addr(tmp_sdata->vif.addr,
1498 may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT);
1500 headroom = local->tx_headroom;
1502 headroom += IEEE80211_ENCRYPT_HEADROOM;
1503 headroom -= skb_headroom(skb);
1504 headroom = max_t(int, 0, headroom);
1506 if (ieee80211_skb_resize(local, skb, headroom, may_encrypt)) {
1512 info->control.vif = &sdata->vif;
1514 if (ieee80211_vif_is_mesh(&sdata->vif) &&
1515 ieee80211_is_data(hdr->frame_control) &&
1516 !is_multicast_ether_addr(hdr->addr1))
1517 if (mesh_nexthop_lookup(skb, sdata)) {
1518 /* skb queued: don't free */
1523 ieee80211_set_qos_hdr(local, skb);
1524 ieee80211_tx(sdata, skb, false);
1528 netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
1529 struct net_device *dev)
1531 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1532 struct ieee80211_channel *chan = local->hw.conf.channel;
1533 struct ieee80211_radiotap_header *prthdr =
1534 (struct ieee80211_radiotap_header *)skb->data;
1535 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1539 * Frame injection is not allowed if beaconing is not allowed
1540 * or if we need radar detection. Beaconing is usually not allowed when
1541 * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
1542 * Passive scan is also used in world regulatory domains where
1543 * your country is not known and as such it should be treated as
1544 * NO TX unless the channel is explicitly allowed in which case
1545 * your current regulatory domain would not have the passive scan
1548 * Since AP mode uses monitor interfaces to inject/TX management
1549 * frames we can make AP mode the exception to this rule once it
1550 * supports radar detection as its implementation can deal with
1551 * radar detection by itself. We can do that later by adding a
1552 * monitor flag interfaces used for AP support.
1554 if ((chan->flags & (IEEE80211_CHAN_NO_IBSS | IEEE80211_CHAN_RADAR |
1555 IEEE80211_CHAN_PASSIVE_SCAN)))
1558 /* check for not even having the fixed radiotap header part */
1559 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
1560 goto fail; /* too short to be possibly valid */
1562 /* is it a header version we can trust to find length from? */
1563 if (unlikely(prthdr->it_version))
1564 goto fail; /* only version 0 is supported */
1566 /* then there must be a radiotap header with a length we can use */
1567 len_rthdr = ieee80211_get_radiotap_len(skb->data);
1569 /* does the skb contain enough to deliver on the alleged length? */
1570 if (unlikely(skb->len < len_rthdr))
1571 goto fail; /* skb too short for claimed rt header extent */
1574 * fix up the pointers accounting for the radiotap
1575 * header still being in there. We are being given
1576 * a precooked IEEE80211 header so no need for
1579 skb_set_mac_header(skb, len_rthdr);
1581 * these are just fixed to the end of the rt area since we
1582 * don't have any better information and at this point, nobody cares
1584 skb_set_network_header(skb, len_rthdr);
1585 skb_set_transport_header(skb, len_rthdr);
1587 memset(info, 0, sizeof(*info));
1589 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
1591 /* pass the radiotap header up to xmit */
1592 ieee80211_xmit(IEEE80211_DEV_TO_SUB_IF(dev), skb);
1593 return NETDEV_TX_OK;
1597 return NETDEV_TX_OK; /* meaning, we dealt with the skb */
1601 * ieee80211_subif_start_xmit - netif start_xmit function for Ethernet-type
1602 * subinterfaces (wlan#, WDS, and VLAN interfaces)
1603 * @skb: packet to be sent
1604 * @dev: incoming interface
1606 * Returns: 0 on success (and frees skb in this case) or 1 on failure (skb will
1607 * not be freed, and caller is responsible for either retrying later or freeing
1610 * This function takes in an Ethernet header and encapsulates it with suitable
1611 * IEEE 802.11 header based on which interface the packet is coming in. The
1612 * encapsulated packet will then be passed to master interface, wlan#.11, for
1613 * transmission (through low-level driver).
1615 netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
1616 struct net_device *dev)
1618 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1619 struct ieee80211_local *local = sdata->local;
1620 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1621 int ret = NETDEV_TX_BUSY, head_need;
1622 u16 ethertype, hdrlen, meshhdrlen = 0;
1624 struct ieee80211_hdr hdr;
1625 struct ieee80211s_hdr mesh_hdr;
1626 const u8 *encaps_data;
1627 int encaps_len, skip_header_bytes;
1629 struct sta_info *sta = NULL;
1632 if (unlikely(skb->len < ETH_HLEN)) {
1637 nh_pos = skb_network_header(skb) - skb->data;
1638 h_pos = skb_transport_header(skb) - skb->data;
1640 /* convert Ethernet header to proper 802.11 header (based on
1641 * operation mode) */
1642 ethertype = (skb->data[12] << 8) | skb->data[13];
1643 fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
1645 switch (sdata->vif.type) {
1646 case NL80211_IFTYPE_AP_VLAN:
1648 sta = rcu_dereference(sdata->u.vlan.sta);
1650 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1652 memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN);
1653 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
1654 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1655 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1657 sta_flags = get_sta_flags(sta);
1663 case NL80211_IFTYPE_AP:
1664 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
1666 memcpy(hdr.addr1, skb->data, ETH_ALEN);
1667 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
1668 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
1671 case NL80211_IFTYPE_WDS:
1672 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1674 memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
1675 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
1676 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1677 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1680 #ifdef CONFIG_MAC80211_MESH
1681 case NL80211_IFTYPE_MESH_POINT:
1682 if (!sdata->u.mesh.mshcfg.dot11MeshTTL) {
1683 /* Do not send frames with mesh_ttl == 0 */
1684 sdata->u.mesh.mshstats.dropped_frames_ttl++;
1689 if (compare_ether_addr(sdata->vif.addr,
1690 skb->data + ETH_ALEN) == 0) {
1691 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
1692 skb->data, skb->data + ETH_ALEN);
1693 meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr,
1694 sdata, NULL, NULL, NULL);
1696 /* packet from other interface */
1697 struct mesh_path *mppath;
1698 int is_mesh_mcast = 1;
1702 if (is_multicast_ether_addr(skb->data))
1703 /* DA TA mSA AE:SA */
1704 mesh_da = skb->data;
1706 static const u8 bcast[ETH_ALEN] =
1707 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
1709 mppath = mpp_path_lookup(skb->data, sdata);
1711 /* RA TA mDA mSA AE:DA SA */
1712 mesh_da = mppath->mpp;
1715 /* DA TA mSA AE:SA */
1719 hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
1720 mesh_da, sdata->vif.addr);
1724 ieee80211_new_mesh_header(&mesh_hdr,
1726 skb->data + ETH_ALEN,
1731 ieee80211_new_mesh_header(&mesh_hdr,
1735 skb->data + ETH_ALEN);
1740 case NL80211_IFTYPE_STATION:
1741 memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
1742 if (sdata->u.mgd.use_4addr && ethertype != ETH_P_PAE) {
1743 fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
1745 memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
1746 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1747 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1750 fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
1752 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
1753 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1757 case NL80211_IFTYPE_ADHOC:
1759 memcpy(hdr.addr1, skb->data, ETH_ALEN);
1760 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
1761 memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN);
1770 * There's no need to try to look up the destination
1771 * if it is a multicast address (which can only happen
1774 if (!is_multicast_ether_addr(hdr.addr1)) {
1776 sta = sta_info_get(sdata, hdr.addr1);
1778 sta_flags = get_sta_flags(sta);
1782 /* receiver and we are QoS enabled, use a QoS type frame */
1783 if ((sta_flags & WLAN_STA_WME) && local->hw.queues >= 4) {
1784 fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
1789 * Drop unicast frames to unauthorised stations unless they are
1790 * EAPOL frames from the local station.
1792 if (!ieee80211_vif_is_mesh(&sdata->vif) &&
1793 unlikely(!is_multicast_ether_addr(hdr.addr1) &&
1794 !(sta_flags & WLAN_STA_AUTHORIZED) &&
1795 !(ethertype == ETH_P_PAE &&
1796 compare_ether_addr(sdata->vif.addr,
1797 skb->data + ETH_ALEN) == 0))) {
1798 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1799 if (net_ratelimit())
1800 printk(KERN_DEBUG "%s: dropped frame to %pM"
1801 " (unauthorized port)\n", dev->name,
1805 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
1811 hdr.frame_control = fc;
1812 hdr.duration_id = 0;
1815 skip_header_bytes = ETH_HLEN;
1816 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
1817 encaps_data = bridge_tunnel_header;
1818 encaps_len = sizeof(bridge_tunnel_header);
1819 skip_header_bytes -= 2;
1820 } else if (ethertype >= 0x600) {
1821 encaps_data = rfc1042_header;
1822 encaps_len = sizeof(rfc1042_header);
1823 skip_header_bytes -= 2;
1829 skb_pull(skb, skip_header_bytes);
1830 nh_pos -= skip_header_bytes;
1831 h_pos -= skip_header_bytes;
1833 head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
1836 * So we need to modify the skb header and hence need a copy of
1837 * that. The head_need variable above doesn't, so far, include
1838 * the needed header space that we don't need right away. If we
1839 * can, then we don't reallocate right now but only after the
1840 * frame arrives at the master device (if it does...)
1842 * If we cannot, however, then we will reallocate to include all
1843 * the ever needed space. Also, if we need to reallocate it anyway,
1844 * make it big enough for everything we may ever need.
1847 if (head_need > 0 || skb_cloned(skb)) {
1848 head_need += IEEE80211_ENCRYPT_HEADROOM;
1849 head_need += local->tx_headroom;
1850 head_need = max_t(int, 0, head_need);
1851 if (ieee80211_skb_resize(local, skb, head_need, true))
1856 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
1857 nh_pos += encaps_len;
1858 h_pos += encaps_len;
1861 if (meshhdrlen > 0) {
1862 memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
1863 nh_pos += meshhdrlen;
1864 h_pos += meshhdrlen;
1867 if (ieee80211_is_data_qos(fc)) {
1868 __le16 *qos_control;
1870 qos_control = (__le16*) skb_push(skb, 2);
1871 memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
1873 * Maybe we could actually set some fields here, for now just
1874 * initialise to zero to indicate no special operation.
1878 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
1883 dev->stats.tx_packets++;
1884 dev->stats.tx_bytes += skb->len;
1886 /* Update skb pointers to various headers since this modified frame
1887 * is going to go through Linux networking code that may potentially
1888 * need things like pointer to IP header. */
1889 skb_set_mac_header(skb, 0);
1890 skb_set_network_header(skb, nh_pos);
1891 skb_set_transport_header(skb, h_pos);
1893 memset(info, 0, sizeof(*info));
1895 dev->trans_start = jiffies;
1896 ieee80211_xmit(sdata, skb);
1898 return NETDEV_TX_OK;
1901 if (ret == NETDEV_TX_OK)
1909 * ieee80211_clear_tx_pending may not be called in a context where
1910 * it is possible that it packets could come in again.
1912 void ieee80211_clear_tx_pending(struct ieee80211_local *local)
1916 for (i = 0; i < local->hw.queues; i++)
1917 skb_queue_purge(&local->pending[i]);
1920 static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
1921 struct sk_buff *skb)
1923 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1924 struct ieee80211_sub_if_data *sdata;
1925 struct sta_info *sta;
1926 struct ieee80211_hdr *hdr;
1930 sdata = vif_to_sdata(info->control.vif);
1932 if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) {
1933 ieee80211_tx(sdata, skb, true);
1935 hdr = (struct ieee80211_hdr *)skb->data;
1936 sta = sta_info_get(sdata, hdr->addr1);
1938 ret = __ieee80211_tx(local, &skb, sta, true);
1939 if (ret != IEEE80211_TX_OK)
1947 * Transmit all pending packets. Called from tasklet.
1949 void ieee80211_tx_pending(unsigned long data)
1951 struct ieee80211_local *local = (struct ieee80211_local *)data;
1952 unsigned long flags;
1958 spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
1959 for (i = 0; i < local->hw.queues; i++) {
1961 * If queue is stopped by something other than due to pending
1962 * frames, or we have no pending frames, proceed to next queue.
1964 if (local->queue_stop_reasons[i] ||
1965 skb_queue_empty(&local->pending[i]))
1968 while (!skb_queue_empty(&local->pending[i])) {
1969 struct sk_buff *skb = __skb_dequeue(&local->pending[i]);
1970 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
1971 struct ieee80211_sub_if_data *sdata;
1973 if (WARN_ON(!info->control.vif)) {
1978 sdata = vif_to_sdata(info->control.vif);
1979 spin_unlock_irqrestore(&local->queue_stop_reason_lock,
1982 txok = ieee80211_tx_pending_skb(local, skb);
1984 __skb_queue_head(&local->pending[i], skb);
1985 spin_lock_irqsave(&local->queue_stop_reason_lock,
1991 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
1996 /* functions for drivers to get certain frames */
1998 static void ieee80211_beacon_add_tim(struct ieee80211_if_ap *bss,
1999 struct sk_buff *skb,
2000 struct beacon_data *beacon)
2004 int i, have_bits = 0, n1, n2;
2006 /* Generate bitmap for TIM only if there are any STAs in power save
2008 if (atomic_read(&bss->num_sta_ps) > 0)
2009 /* in the hope that this is faster than
2010 * checking byte-for-byte */
2011 have_bits = !bitmap_empty((unsigned long*)bss->tim,
2012 IEEE80211_MAX_AID+1);
2014 if (bss->dtim_count == 0)
2015 bss->dtim_count = beacon->dtim_period - 1;
2019 tim = pos = (u8 *) skb_put(skb, 6);
2020 *pos++ = WLAN_EID_TIM;
2022 *pos++ = bss->dtim_count;
2023 *pos++ = beacon->dtim_period;
2025 if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf))
2029 /* Find largest even number N1 so that bits numbered 1 through
2030 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
2031 * (N2 + 1) x 8 through 2007 are 0. */
2033 for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
2040 for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
2047 /* Bitmap control */
2049 /* Part Virt Bitmap */
2050 memcpy(pos, bss->tim + n1, n2 - n1 + 1);
2052 tim[1] = n2 - n1 + 4;
2053 skb_put(skb, n2 - n1);
2055 *pos++ = aid0; /* Bitmap control */
2056 *pos++ = 0; /* Part Virt Bitmap */
2060 struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
2061 struct ieee80211_vif *vif,
2062 u16 *tim_offset, u16 *tim_length)
2064 struct ieee80211_local *local = hw_to_local(hw);
2065 struct sk_buff *skb = NULL;
2066 struct ieee80211_tx_info *info;
2067 struct ieee80211_sub_if_data *sdata = NULL;
2068 struct ieee80211_if_ap *ap = NULL;
2069 struct beacon_data *beacon;
2070 struct ieee80211_supported_band *sband;
2071 enum ieee80211_band band = local->hw.conf.channel->band;
2072 struct ieee80211_tx_rate_control txrc;
2074 sband = local->hw.wiphy->bands[band];
2078 sdata = vif_to_sdata(vif);
2085 if (sdata->vif.type == NL80211_IFTYPE_AP) {
2087 beacon = rcu_dereference(ap->beacon);
2090 * headroom, head length,
2091 * tail length and maximum TIM length
2093 skb = dev_alloc_skb(local->tx_headroom +
2095 beacon->tail_len + 256);
2099 skb_reserve(skb, local->tx_headroom);
2100 memcpy(skb_put(skb, beacon->head_len), beacon->head,
2104 * Not very nice, but we want to allow the driver to call
2105 * ieee80211_beacon_get() as a response to the set_tim()
2106 * callback. That, however, is already invoked under the
2107 * sta_lock to guarantee consistent and race-free update
2108 * of the tim bitmap in mac80211 and the driver.
2110 if (local->tim_in_locked_section) {
2111 ieee80211_beacon_add_tim(ap, skb, beacon);
2113 unsigned long flags;
2115 spin_lock_irqsave(&local->sta_lock, flags);
2116 ieee80211_beacon_add_tim(ap, skb, beacon);
2117 spin_unlock_irqrestore(&local->sta_lock, flags);
2121 *tim_offset = beacon->head_len;
2123 *tim_length = skb->len - beacon->head_len;
2126 memcpy(skb_put(skb, beacon->tail_len),
2127 beacon->tail, beacon->tail_len);
2130 } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2131 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
2132 struct ieee80211_hdr *hdr;
2133 struct sk_buff *presp = rcu_dereference(ifibss->presp);
2138 skb = skb_copy(presp, GFP_ATOMIC);
2142 hdr = (struct ieee80211_hdr *) skb->data;
2143 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2144 IEEE80211_STYPE_BEACON);
2145 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
2146 struct ieee80211_mgmt *mgmt;
2149 /* headroom, head length, tail length and maximum TIM length */
2150 skb = dev_alloc_skb(local->tx_headroom + 400);
2154 skb_reserve(skb, local->hw.extra_tx_headroom);
2155 mgmt = (struct ieee80211_mgmt *)
2156 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
2157 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
2158 mgmt->frame_control =
2159 cpu_to_le16(IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON);
2160 memset(mgmt->da, 0xff, ETH_ALEN);
2161 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2162 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
2163 mgmt->u.beacon.beacon_int =
2164 cpu_to_le16(sdata->vif.bss_conf.beacon_int);
2165 mgmt->u.beacon.capab_info = 0x0; /* 0x0 for MPs */
2167 pos = skb_put(skb, 2);
2168 *pos++ = WLAN_EID_SSID;
2171 mesh_mgmt_ies_add(skb, sdata);
2177 info = IEEE80211_SKB_CB(skb);
2179 info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
2180 info->flags |= IEEE80211_TX_CTL_NO_ACK;
2183 memset(&txrc, 0, sizeof(txrc));
2186 txrc.bss_conf = &sdata->vif.bss_conf;
2188 txrc.reported_rate.idx = -1;
2189 txrc.rate_idx_mask = sdata->rc_rateidx_mask[band];
2190 if (txrc.rate_idx_mask == (1 << sband->n_bitrates) - 1)
2191 txrc.max_rate_idx = -1;
2193 txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
2195 rate_control_get_rate(sdata, NULL, &txrc);
2197 info->control.vif = vif;
2199 info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
2200 info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
2205 EXPORT_SYMBOL(ieee80211_beacon_get_tim);
2207 struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw,
2208 struct ieee80211_vif *vif)
2210 struct ieee80211_sub_if_data *sdata;
2211 struct ieee80211_if_managed *ifmgd;
2212 struct ieee80211_pspoll *pspoll;
2213 struct ieee80211_local *local;
2214 struct sk_buff *skb;
2216 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
2219 sdata = vif_to_sdata(vif);
2220 ifmgd = &sdata->u.mgd;
2221 local = sdata->local;
2223 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
2225 printk(KERN_DEBUG "%s: failed to allocate buffer for "
2226 "pspoll template\n", sdata->name);
2229 skb_reserve(skb, local->hw.extra_tx_headroom);
2231 pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
2232 memset(pspoll, 0, sizeof(*pspoll));
2233 pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
2234 IEEE80211_STYPE_PSPOLL);
2235 pspoll->aid = cpu_to_le16(ifmgd->aid);
2237 /* aid in PS-Poll has its two MSBs each set to 1 */
2238 pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
2240 memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
2241 memcpy(pspoll->ta, vif->addr, ETH_ALEN);
2245 EXPORT_SYMBOL(ieee80211_pspoll_get);
2247 struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw,
2248 struct ieee80211_vif *vif)
2250 struct ieee80211_hdr_3addr *nullfunc;
2251 struct ieee80211_sub_if_data *sdata;
2252 struct ieee80211_if_managed *ifmgd;
2253 struct ieee80211_local *local;
2254 struct sk_buff *skb;
2256 if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
2259 sdata = vif_to_sdata(vif);
2260 ifmgd = &sdata->u.mgd;
2261 local = sdata->local;
2263 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*nullfunc));
2265 printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc "
2266 "template\n", sdata->name);
2269 skb_reserve(skb, local->hw.extra_tx_headroom);
2271 nullfunc = (struct ieee80211_hdr_3addr *) skb_put(skb,
2273 memset(nullfunc, 0, sizeof(*nullfunc));
2274 nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
2275 IEEE80211_STYPE_NULLFUNC |
2276 IEEE80211_FCTL_TODS);
2277 memcpy(nullfunc->addr1, ifmgd->bssid, ETH_ALEN);
2278 memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
2279 memcpy(nullfunc->addr3, ifmgd->bssid, ETH_ALEN);
2283 EXPORT_SYMBOL(ieee80211_nullfunc_get);
2285 struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw,
2286 struct ieee80211_vif *vif,
2287 const u8 *ssid, size_t ssid_len,
2288 const u8 *ie, size_t ie_len)
2290 struct ieee80211_sub_if_data *sdata;
2291 struct ieee80211_local *local;
2292 struct ieee80211_hdr_3addr *hdr;
2293 struct sk_buff *skb;
2297 sdata = vif_to_sdata(vif);
2298 local = sdata->local;
2299 ie_ssid_len = 2 + ssid_len;
2301 skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) +
2302 ie_ssid_len + ie_len);
2304 printk(KERN_DEBUG "%s: failed to allocate buffer for probe "
2305 "request template\n", sdata->name);
2309 skb_reserve(skb, local->hw.extra_tx_headroom);
2311 hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
2312 memset(hdr, 0, sizeof(*hdr));
2313 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2314 IEEE80211_STYPE_PROBE_REQ);
2315 memset(hdr->addr1, 0xff, ETH_ALEN);
2316 memcpy(hdr->addr2, vif->addr, ETH_ALEN);
2317 memset(hdr->addr3, 0xff, ETH_ALEN);
2319 pos = skb_put(skb, ie_ssid_len);
2320 *pos++ = WLAN_EID_SSID;
2323 memcpy(pos, ssid, ssid_len);
2327 pos = skb_put(skb, ie_len);
2328 memcpy(pos, ie, ie_len);
2333 EXPORT_SYMBOL(ieee80211_probereq_get);
2335 void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2336 const void *frame, size_t frame_len,
2337 const struct ieee80211_tx_info *frame_txctl,
2338 struct ieee80211_rts *rts)
2340 const struct ieee80211_hdr *hdr = frame;
2342 rts->frame_control =
2343 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
2344 rts->duration = ieee80211_rts_duration(hw, vif, frame_len,
2346 memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
2347 memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
2349 EXPORT_SYMBOL(ieee80211_rts_get);
2351 void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
2352 const void *frame, size_t frame_len,
2353 const struct ieee80211_tx_info *frame_txctl,
2354 struct ieee80211_cts *cts)
2356 const struct ieee80211_hdr *hdr = frame;
2358 cts->frame_control =
2359 cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
2360 cts->duration = ieee80211_ctstoself_duration(hw, vif,
2361 frame_len, frame_txctl);
2362 memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
2364 EXPORT_SYMBOL(ieee80211_ctstoself_get);
2367 ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
2368 struct ieee80211_vif *vif)
2370 struct ieee80211_local *local = hw_to_local(hw);
2371 struct sk_buff *skb = NULL;
2372 struct sta_info *sta;
2373 struct ieee80211_tx_data tx;
2374 struct ieee80211_sub_if_data *sdata;
2375 struct ieee80211_if_ap *bss = NULL;
2376 struct beacon_data *beacon;
2377 struct ieee80211_tx_info *info;
2379 sdata = vif_to_sdata(vif);
2383 beacon = rcu_dereference(bss->beacon);
2385 if (sdata->vif.type != NL80211_IFTYPE_AP || !beacon || !beacon->head)
2388 if (bss->dtim_count != 0)
2389 goto out; /* send buffered bc/mc only after DTIM beacon */
2392 skb = skb_dequeue(&bss->ps_bc_buf);
2395 local->total_ps_buffered--;
2397 if (!skb_queue_empty(&bss->ps_bc_buf) && skb->len >= 2) {
2398 struct ieee80211_hdr *hdr =
2399 (struct ieee80211_hdr *) skb->data;
2400 /* more buffered multicast/broadcast frames ==> set
2401 * MoreData flag in IEEE 802.11 header to inform PS
2403 hdr->frame_control |=
2404 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
2407 if (!ieee80211_tx_prepare(sdata, &tx, skb))
2409 dev_kfree_skb_any(skb);
2412 info = IEEE80211_SKB_CB(skb);
2415 tx.flags |= IEEE80211_TX_PS_BUFFERED;
2416 tx.channel = local->hw.conf.channel;
2417 info->band = tx.channel->band;
2419 if (invoke_tx_handlers(&tx))
2426 EXPORT_SYMBOL(ieee80211_get_buffered_bc);
2428 void ieee80211_tx_skb(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
2430 skb_set_mac_header(skb, 0);
2431 skb_set_network_header(skb, 0);
2432 skb_set_transport_header(skb, 0);
2434 /* send all internal mgmt frames on VO */
2435 skb_set_queue_mapping(skb, 0);
2438 * The other path calling ieee80211_xmit is from the tasklet,
2439 * and while we can handle concurrent transmissions locking
2440 * requirements are that we do not come into tx with bhs on.
2443 ieee80211_xmit(sdata, skb);