blob: c80d5899f27903c23080c419e808fddc323d521e [file] [log] [blame]
Johannes Berge2ebc742007-07-27 15:43:22 +02001/*
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>
6 *
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.
10 *
11 *
12 * Transmit and frame generation functions.
13 */
14
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>
Johannes Bergd4e46a32007-09-14 11:10:24 -040020#include <linux/rcupdate.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070021#include <net/net_namespace.h>
Johannes Berge2ebc742007-07-27 15:43:22 +020022#include <net/ieee80211_radiotap.h>
23#include <net/cfg80211.h>
24#include <net/mac80211.h>
25#include <asm/unaligned.h>
26
27#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040028#include "led.h"
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +010029#include "mesh.h"
Johannes Berge2ebc742007-07-27 15:43:22 +020030#include "wep.h"
31#include "wpa.h"
32#include "wme.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040033#include "rate.h"
Johannes Berge2ebc742007-07-27 15:43:22 +020034
35#define IEEE80211_TX_OK 0
36#define IEEE80211_TX_AGAIN 1
37#define IEEE80211_TX_FRAG_AGAIN 2
38
39/* misc utils */
40
41static inline void ieee80211_include_sequence(struct ieee80211_sub_if_data *sdata,
42 struct ieee80211_hdr *hdr)
43{
44 /* Set the sequence number for this frame. */
45 hdr->seq_ctrl = cpu_to_le16(sdata->sequence);
46
47 /* Increase the sequence number. */
48 sdata->sequence = (sdata->sequence + 0x10) & IEEE80211_SCTL_SEQ;
49}
50
51#ifdef CONFIG_MAC80211_LOWTX_FRAME_DUMP
52static void ieee80211_dump_frame(const char *ifname, const char *title,
53 const struct sk_buff *skb)
54{
55 const struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
56 u16 fc;
57 int hdrlen;
Joe Perches0795af52007-10-03 17:59:30 -070058 DECLARE_MAC_BUF(mac);
Johannes Berge2ebc742007-07-27 15:43:22 +020059
60 printk(KERN_DEBUG "%s: %s (len=%d)", ifname, title, skb->len);
61 if (skb->len < 4) {
62 printk("\n");
63 return;
64 }
65
66 fc = le16_to_cpu(hdr->frame_control);
67 hdrlen = ieee80211_get_hdrlen(fc);
68 if (hdrlen > skb->len)
69 hdrlen = skb->len;
70 if (hdrlen >= 4)
71 printk(" FC=0x%04x DUR=0x%04x",
72 fc, le16_to_cpu(hdr->duration_id));
73 if (hdrlen >= 10)
Joe Perches0795af52007-10-03 17:59:30 -070074 printk(" A1=%s", print_mac(mac, hdr->addr1));
Johannes Berge2ebc742007-07-27 15:43:22 +020075 if (hdrlen >= 16)
Joe Perches0795af52007-10-03 17:59:30 -070076 printk(" A2=%s", print_mac(mac, hdr->addr2));
Johannes Berge2ebc742007-07-27 15:43:22 +020077 if (hdrlen >= 24)
Joe Perches0795af52007-10-03 17:59:30 -070078 printk(" A3=%s", print_mac(mac, hdr->addr3));
Johannes Berge2ebc742007-07-27 15:43:22 +020079 if (hdrlen >= 30)
Joe Perches0795af52007-10-03 17:59:30 -070080 printk(" A4=%s", print_mac(mac, hdr->addr4));
Johannes Berge2ebc742007-07-27 15:43:22 +020081 printk("\n");
82}
83#else /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
84static inline void ieee80211_dump_frame(const char *ifname, const char *title,
85 struct sk_buff *skb)
86{
87}
88#endif /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */
89
Johannes Berg5cf121c2008-02-25 16:27:43 +010090static u16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr,
Johannes Berge2ebc742007-07-27 15:43:22 +020091 int next_frag_len)
92{
93 int rate, mrate, erp, dur, i;
Johannes Berg5cf121c2008-02-25 16:27:43 +010094 struct ieee80211_rate *txrate = tx->rate;
Johannes Berge2ebc742007-07-27 15:43:22 +020095 struct ieee80211_local *local = tx->local;
Johannes Berg8318d782008-01-24 19:38:38 +010096 struct ieee80211_supported_band *sband;
Johannes Berge2ebc742007-07-27 15:43:22 +020097
Johannes Berg8318d782008-01-24 19:38:38 +010098 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
99
100 erp = 0;
101 if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
102 erp = txrate->flags & IEEE80211_RATE_ERP_G;
Johannes Berge2ebc742007-07-27 15:43:22 +0200103
104 /*
105 * data and mgmt (except PS Poll):
106 * - during CFP: 32768
107 * - during contention period:
108 * if addr1 is group address: 0
109 * if more fragments = 0 and addr1 is individual address: time to
110 * transmit one ACK plus SIFS
111 * if more fragments = 1 and addr1 is individual address: time to
112 * transmit next fragment plus 2 x ACK plus 3 x SIFS
113 *
114 * IEEE 802.11, 9.6:
115 * - control response frame (CTS or ACK) shall be transmitted using the
116 * same rate as the immediately previous frame in the frame exchange
117 * sequence, if this rate belongs to the PHY mandatory rates, or else
118 * at the highest possible rate belonging to the PHY rates in the
119 * BSSBasicRateSet
120 */
121
122 if ((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) {
123 /* TODO: These control frames are not currently sent by
124 * 80211.o, but should they be implemented, this function
125 * needs to be updated to support duration field calculation.
126 *
127 * RTS: time needed to transmit pending data/mgmt frame plus
128 * one CTS frame plus one ACK frame plus 3 x SIFS
129 * CTS: duration of immediately previous RTS minus time
130 * required to transmit CTS and its SIFS
131 * ACK: 0 if immediately previous directed data/mgmt had
132 * more=0, with more=1 duration in ACK frame is duration
133 * from previous frame minus time needed to transmit ACK
134 * and its SIFS
135 * PS Poll: BIT(15) | BIT(14) | aid
136 */
137 return 0;
138 }
139
140 /* data/mgmt */
141 if (0 /* FIX: data/mgmt during CFP */)
142 return 32768;
143
144 if (group_addr) /* Group address as the destination - no ACK */
145 return 0;
146
147 /* Individual destination address:
148 * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
149 * CTS and ACK frames shall be transmitted using the highest rate in
150 * basic rate set that is less than or equal to the rate of the
151 * immediately previous frame and that is using the same modulation
152 * (CCK or OFDM). If no basic rate set matches with these requirements,
153 * the highest mandatory rate of the PHY that is less than or equal to
154 * the rate of the previous frame is used.
155 * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
156 */
157 rate = -1;
Johannes Berg8318d782008-01-24 19:38:38 +0100158 /* use lowest available if everything fails */
159 mrate = sband->bitrates[0].bitrate;
160 for (i = 0; i < sband->n_bitrates; i++) {
161 struct ieee80211_rate *r = &sband->bitrates[i];
162
163 if (r->bitrate > txrate->bitrate)
Johannes Berge2ebc742007-07-27 15:43:22 +0200164 break;
165
Johannes Berg8318d782008-01-24 19:38:38 +0100166 if (tx->sdata->basic_rates & BIT(i))
167 rate = r->bitrate;
Johannes Berge2ebc742007-07-27 15:43:22 +0200168
Johannes Berg8318d782008-01-24 19:38:38 +0100169 switch (sband->band) {
170 case IEEE80211_BAND_2GHZ: {
171 u32 flag;
172 if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
173 flag = IEEE80211_RATE_MANDATORY_G;
174 else
175 flag = IEEE80211_RATE_MANDATORY_B;
176 if (r->flags & flag)
177 mrate = r->bitrate;
178 break;
179 }
180 case IEEE80211_BAND_5GHZ:
181 if (r->flags & IEEE80211_RATE_MANDATORY_A)
182 mrate = r->bitrate;
183 break;
184 case IEEE80211_NUM_BANDS:
185 WARN_ON(1);
186 break;
187 }
Johannes Berge2ebc742007-07-27 15:43:22 +0200188 }
189 if (rate == -1) {
190 /* No matching basic rate found; use highest suitable mandatory
191 * PHY rate */
192 rate = mrate;
193 }
194
195 /* Time needed to transmit ACK
196 * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
197 * to closest integer */
198
199 dur = ieee80211_frame_duration(local, 10, rate, erp,
Johannes Berg471b3ef2007-12-28 14:32:58 +0100200 tx->sdata->bss_conf.use_short_preamble);
Johannes Berge2ebc742007-07-27 15:43:22 +0200201
202 if (next_frag_len) {
203 /* Frame is fragmented: duration increases with time needed to
204 * transmit next fragment plus ACK and 2 x SIFS. */
205 dur *= 2; /* ACK + SIFS */
206 /* next fragment */
207 dur += ieee80211_frame_duration(local, next_frag_len,
Johannes Berg8318d782008-01-24 19:38:38 +0100208 txrate->bitrate, erp,
Johannes Berg471b3ef2007-12-28 14:32:58 +0100209 tx->sdata->bss_conf.use_short_preamble);
Johannes Berge2ebc742007-07-27 15:43:22 +0200210 }
211
212 return dur;
213}
214
215static inline int __ieee80211_queue_stopped(const struct ieee80211_local *local,
216 int queue)
217{
218 return test_bit(IEEE80211_LINK_STATE_XOFF, &local->state[queue]);
219}
220
221static inline int __ieee80211_queue_pending(const struct ieee80211_local *local,
222 int queue)
223{
224 return test_bit(IEEE80211_LINK_STATE_PENDING, &local->state[queue]);
225}
226
227static int inline is_ieee80211_device(struct net_device *dev,
228 struct net_device *master)
229{
230 return (wdev_priv(dev->ieee80211_ptr) ==
231 wdev_priv(master->ieee80211_ptr));
232}
233
234/* tx handlers */
235
Johannes Berg9ae54c82008-01-31 19:48:20 +0100236static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100237ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200238{
239#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
240 struct sk_buff *skb = tx->skb;
241 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
242#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
243 u32 sta_flags;
244
Johannes Berg5cf121c2008-02-25 16:27:43 +0100245 if (unlikely(tx->flags & IEEE80211_TX_INJECTED))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100246 return TX_CONTINUE;
Johannes Berg58d41852007-09-26 17:53:18 +0200247
Zhu Yiece8edd2007-11-22 10:53:21 +0800248 if (unlikely(tx->local->sta_sw_scanning) &&
Johannes Berge2ebc742007-07-27 15:43:22 +0200249 ((tx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT ||
250 (tx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PROBE_REQ))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100251 return TX_DROP;
Johannes Berge2ebc742007-07-27 15:43:22 +0200252
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +0100253 if (tx->sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT)
254 return TX_CONTINUE;
255
Johannes Berg5cf121c2008-02-25 16:27:43 +0100256 if (tx->flags & IEEE80211_TX_PS_BUFFERED)
Johannes Berg9ae54c82008-01-31 19:48:20 +0100257 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200258
259 sta_flags = tx->sta ? tx->sta->flags : 0;
260
Johannes Berg5cf121c2008-02-25 16:27:43 +0100261 if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
Johannes Berge2ebc742007-07-27 15:43:22 +0200262 if (unlikely(!(sta_flags & WLAN_STA_ASSOC) &&
Johannes Berg51fb61e2007-12-19 01:31:27 +0100263 tx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Johannes Berge2ebc742007-07-27 15:43:22 +0200264 (tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) {
265#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -0700266 DECLARE_MAC_BUF(mac);
Johannes Berge2ebc742007-07-27 15:43:22 +0200267 printk(KERN_DEBUG "%s: dropped data frame to not "
Joe Perches0795af52007-10-03 17:59:30 -0700268 "associated station %s\n",
269 tx->dev->name, print_mac(mac, hdr->addr1));
Johannes Berge2ebc742007-07-27 15:43:22 +0200270#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
271 I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
Johannes Berg9ae54c82008-01-31 19:48:20 +0100272 return TX_DROP;
Johannes Berge2ebc742007-07-27 15:43:22 +0200273 }
274 } else {
275 if (unlikely((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA &&
276 tx->local->num_sta == 0 &&
Johannes Berg51fb61e2007-12-19 01:31:27 +0100277 tx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS)) {
Johannes Berge2ebc742007-07-27 15:43:22 +0200278 /*
279 * No associated STAs - no need to send multicast
280 * frames.
281 */
Johannes Berg9ae54c82008-01-31 19:48:20 +0100282 return TX_DROP;
Johannes Berge2ebc742007-07-27 15:43:22 +0200283 }
Johannes Berg9ae54c82008-01-31 19:48:20 +0100284 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200285 }
286
Johannes Berg9ae54c82008-01-31 19:48:20 +0100287 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200288}
289
Johannes Berg9ae54c82008-01-31 19:48:20 +0100290static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100291ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200292{
293 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
294
295 if (ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control)) >= 24)
296 ieee80211_include_sequence(tx->sdata, hdr);
297
Johannes Berg9ae54c82008-01-31 19:48:20 +0100298 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200299}
300
301/* This function is called whenever the AP is about to exceed the maximum limit
302 * of buffered frames for power saving STAs. This situation should not really
303 * happen often during normal operation, so dropping the oldest buffered packet
304 * from each queue should be OK to make some room for new frames. */
305static void purge_old_ps_buffers(struct ieee80211_local *local)
306{
307 int total = 0, purged = 0;
308 struct sk_buff *skb;
309 struct ieee80211_sub_if_data *sdata;
310 struct sta_info *sta;
311
Johannes Berg79010422007-09-18 17:29:21 -0400312 /*
313 * virtual interfaces are protected by RCU
314 */
315 rcu_read_lock();
316
317 list_for_each_entry_rcu(sdata, &local->interfaces, list) {
Johannes Berge2ebc742007-07-27 15:43:22 +0200318 struct ieee80211_if_ap *ap;
319 if (sdata->dev == local->mdev ||
Johannes Berg51fb61e2007-12-19 01:31:27 +0100320 sdata->vif.type != IEEE80211_IF_TYPE_AP)
Johannes Berge2ebc742007-07-27 15:43:22 +0200321 continue;
322 ap = &sdata->u.ap;
323 skb = skb_dequeue(&ap->ps_bc_buf);
324 if (skb) {
325 purged++;
326 dev_kfree_skb(skb);
327 }
328 total += skb_queue_len(&ap->ps_bc_buf);
329 }
Johannes Berge2ebc742007-07-27 15:43:22 +0200330
Johannes Bergd0709a62008-02-25 16:27:46 +0100331 list_for_each_entry_rcu(sta, &local->sta_list, list) {
Johannes Berge2ebc742007-07-27 15:43:22 +0200332 skb = skb_dequeue(&sta->ps_tx_buf);
333 if (skb) {
334 purged++;
335 dev_kfree_skb(skb);
336 }
337 total += skb_queue_len(&sta->ps_tx_buf);
338 }
Johannes Bergd0709a62008-02-25 16:27:46 +0100339
340 rcu_read_unlock();
Johannes Berge2ebc742007-07-27 15:43:22 +0200341
342 local->total_ps_buffered = total;
343 printk(KERN_DEBUG "%s: PS buffers full - purged %d frames\n",
Johannes Bergdd1cd4c2007-09-18 17:29:20 -0400344 wiphy_name(local->hw.wiphy), purged);
Johannes Berge2ebc742007-07-27 15:43:22 +0200345}
346
Johannes Berg9ae54c82008-01-31 19:48:20 +0100347static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100348ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200349{
Johannes Berg7d54d0dd2007-12-19 01:31:25 +0100350 /*
351 * broadcast/multicast frame
352 *
353 * If any of the associated stations is in power save mode,
354 * the frame is buffered to be sent after DTIM beacon frame.
355 * This is done either by the hardware or us.
356 */
357
358 /* not AP/IBSS or ordered frame */
359 if (!tx->sdata->bss || (tx->fc & IEEE80211_FCTL_ORDER))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100360 return TX_CONTINUE;
Johannes Berg7d54d0dd2007-12-19 01:31:25 +0100361
362 /* no stations in PS mode */
363 if (!atomic_read(&tx->sdata->bss->num_sta_ps))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100364 return TX_CONTINUE;
Johannes Berg7d54d0dd2007-12-19 01:31:25 +0100365
366 /* buffered in mac80211 */
367 if (tx->local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING) {
Johannes Berge2ebc742007-07-27 15:43:22 +0200368 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
369 purge_old_ps_buffers(tx->local);
370 if (skb_queue_len(&tx->sdata->bss->ps_bc_buf) >=
371 AP_MAX_BC_BUFFER) {
372 if (net_ratelimit()) {
373 printk(KERN_DEBUG "%s: BC TX buffer full - "
374 "dropping the oldest frame\n",
375 tx->dev->name);
376 }
377 dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf));
378 } else
379 tx->local->total_ps_buffered++;
380 skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb);
Johannes Berg9ae54c82008-01-31 19:48:20 +0100381 return TX_QUEUED;
Johannes Berge2ebc742007-07-27 15:43:22 +0200382 }
383
Johannes Berg7d54d0dd2007-12-19 01:31:25 +0100384 /* buffered in hardware */
Johannes Berg5cf121c2008-02-25 16:27:43 +0100385 tx->control->flags |= IEEE80211_TXCTL_SEND_AFTER_DTIM;
Johannes Berg7d54d0dd2007-12-19 01:31:25 +0100386
Johannes Berg9ae54c82008-01-31 19:48:20 +0100387 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200388}
389
Johannes Berg9ae54c82008-01-31 19:48:20 +0100390static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100391ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200392{
393 struct sta_info *sta = tx->sta;
Joe Perches0795af52007-10-03 17:59:30 -0700394 DECLARE_MAC_BUF(mac);
Johannes Berge2ebc742007-07-27 15:43:22 +0200395
396 if (unlikely(!sta ||
397 ((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT &&
398 (tx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP)))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100399 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200400
Johannes Berg4a9a66e2008-02-19 11:31:14 +0100401 if (unlikely((sta->flags & WLAN_STA_PS) &&
402 !(sta->flags & WLAN_STA_PSPOLL))) {
Johannes Berge2ebc742007-07-27 15:43:22 +0200403 struct ieee80211_tx_packet_data *pkt_data;
404#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
Joe Perches0795af52007-10-03 17:59:30 -0700405 printk(KERN_DEBUG "STA %s aid %d: PS buffer (entries "
Johannes Berge2ebc742007-07-27 15:43:22 +0200406 "before %d)\n",
Joe Perches0795af52007-10-03 17:59:30 -0700407 print_mac(mac, sta->addr), sta->aid,
Johannes Berge2ebc742007-07-27 15:43:22 +0200408 skb_queue_len(&sta->ps_tx_buf));
409#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
Johannes Berge2ebc742007-07-27 15:43:22 +0200410 if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
411 purge_old_ps_buffers(tx->local);
412 if (skb_queue_len(&sta->ps_tx_buf) >= STA_MAX_TX_BUFFER) {
413 struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf);
414 if (net_ratelimit()) {
Joe Perches0795af52007-10-03 17:59:30 -0700415 printk(KERN_DEBUG "%s: STA %s TX "
Johannes Berge2ebc742007-07-27 15:43:22 +0200416 "buffer full - dropping oldest frame\n",
Joe Perches0795af52007-10-03 17:59:30 -0700417 tx->dev->name, print_mac(mac, sta->addr));
Johannes Berge2ebc742007-07-27 15:43:22 +0200418 }
419 dev_kfree_skb(old);
420 } else
421 tx->local->total_ps_buffered++;
Johannes Berg004c8722008-02-20 11:21:35 +0100422
Johannes Berge2ebc742007-07-27 15:43:22 +0200423 /* Queue frame to be sent after STA sends an PS Poll frame */
Johannes Berg004c8722008-02-20 11:21:35 +0100424 if (skb_queue_empty(&sta->ps_tx_buf))
425 sta_info_set_tim_bit(sta);
426
Johannes Berge2ebc742007-07-27 15:43:22 +0200427 pkt_data = (struct ieee80211_tx_packet_data *)tx->skb->cb;
428 pkt_data->jiffies = jiffies;
429 skb_queue_tail(&sta->ps_tx_buf, tx->skb);
Johannes Berg9ae54c82008-01-31 19:48:20 +0100430 return TX_QUEUED;
Johannes Berge2ebc742007-07-27 15:43:22 +0200431 }
432#ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG
433 else if (unlikely(sta->flags & WLAN_STA_PS)) {
Joe Perches0795af52007-10-03 17:59:30 -0700434 printk(KERN_DEBUG "%s: STA %s in PS mode, but pspoll "
Johannes Berge2ebc742007-07-27 15:43:22 +0200435 "set -> send frame\n", tx->dev->name,
Joe Perches0795af52007-10-03 17:59:30 -0700436 print_mac(mac, sta->addr));
Johannes Berge2ebc742007-07-27 15:43:22 +0200437 }
438#endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */
Johannes Berg4a9a66e2008-02-19 11:31:14 +0100439 sta->flags &= ~WLAN_STA_PSPOLL;
Johannes Berge2ebc742007-07-27 15:43:22 +0200440
Johannes Berg9ae54c82008-01-31 19:48:20 +0100441 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200442}
443
Johannes Berg9ae54c82008-01-31 19:48:20 +0100444static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100445ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200446{
Johannes Berg5cf121c2008-02-25 16:27:43 +0100447 if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100448 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200449
Johannes Berg5cf121c2008-02-25 16:27:43 +0100450 if (tx->flags & IEEE80211_TX_UNICAST)
Johannes Berge2ebc742007-07-27 15:43:22 +0200451 return ieee80211_tx_h_unicast_ps_buf(tx);
452 else
453 return ieee80211_tx_h_multicast_ps_buf(tx);
454}
455
Johannes Berg9ae54c82008-01-31 19:48:20 +0100456static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100457ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200458{
Johannes Bergd4e46a32007-09-14 11:10:24 -0400459 struct ieee80211_key *key;
Johannes Berg176e4f82007-12-18 15:27:47 +0100460 u16 fc = tx->fc;
Johannes Bergd4e46a32007-09-14 11:10:24 -0400461
Johannes Berg5cf121c2008-02-25 16:27:43 +0100462 if (unlikely(tx->control->flags & IEEE80211_TXCTL_DO_NOT_ENCRYPT))
Johannes Berge2ebc742007-07-27 15:43:22 +0200463 tx->key = NULL;
Johannes Bergd4e46a32007-09-14 11:10:24 -0400464 else if (tx->sta && (key = rcu_dereference(tx->sta->key)))
465 tx->key = key;
466 else if ((key = rcu_dereference(tx->sdata->default_key)))
467 tx->key = key;
Johannes Berge2ebc742007-07-27 15:43:22 +0200468 else if (tx->sdata->drop_unencrypted &&
Johannes Berg5cf121c2008-02-25 16:27:43 +0100469 !(tx->control->flags & IEEE80211_TXCTL_EAPOL_FRAME) &&
470 !(tx->flags & IEEE80211_TX_INJECTED)) {
Johannes Berge2ebc742007-07-27 15:43:22 +0200471 I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted);
Johannes Berg9ae54c82008-01-31 19:48:20 +0100472 return TX_DROP;
Johannes Berg176e4f82007-12-18 15:27:47 +0100473 } else
Johannes Berge2ebc742007-07-27 15:43:22 +0200474 tx->key = NULL;
475
476 if (tx->key) {
Johannes Berg176e4f82007-12-18 15:27:47 +0100477 u16 ftype, stype;
478
Johannes Berge2ebc742007-07-27 15:43:22 +0200479 tx->key->tx_rx_count++;
Johannes Berg011bfcc2007-09-17 01:29:25 -0400480 /* TODO: add threshold stuff again */
Johannes Berg176e4f82007-12-18 15:27:47 +0100481
482 switch (tx->key->conf.alg) {
483 case ALG_WEP:
484 ftype = fc & IEEE80211_FCTL_FTYPE;
485 stype = fc & IEEE80211_FCTL_STYPE;
486
487 if (ftype == IEEE80211_FTYPE_MGMT &&
488 stype == IEEE80211_STYPE_AUTH)
489 break;
490 case ALG_TKIP:
491 case ALG_CCMP:
492 if (!WLAN_FC_DATA_PRESENT(fc))
493 tx->key = NULL;
494 break;
495 }
Johannes Berge2ebc742007-07-27 15:43:22 +0200496 }
497
Johannes Berg176e4f82007-12-18 15:27:47 +0100498 if (!tx->key || !(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
Johannes Berg5cf121c2008-02-25 16:27:43 +0100499 tx->control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
Johannes Berg176e4f82007-12-18 15:27:47 +0100500
Johannes Berg9ae54c82008-01-31 19:48:20 +0100501 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200502}
503
Johannes Berg9ae54c82008-01-31 19:48:20 +0100504static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100505ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200506{
507 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
508 size_t hdrlen, per_fragm, num_fragm, payload_len, left;
509 struct sk_buff **frags, *first, *frag;
510 int i;
511 u16 seq;
512 u8 *pos;
513 int frag_threshold = tx->local->fragmentation_threshold;
514
Johannes Berg5cf121c2008-02-25 16:27:43 +0100515 if (!(tx->flags & IEEE80211_TX_FRAGMENTED))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100516 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200517
518 first = tx->skb;
519
520 hdrlen = ieee80211_get_hdrlen(tx->fc);
521 payload_len = first->len - hdrlen;
522 per_fragm = frag_threshold - hdrlen - FCS_LEN;
Ilpo Järvinen172589c2007-08-28 15:50:33 -0700523 num_fragm = DIV_ROUND_UP(payload_len, per_fragm);
Johannes Berge2ebc742007-07-27 15:43:22 +0200524
525 frags = kzalloc(num_fragm * sizeof(struct sk_buff *), GFP_ATOMIC);
526 if (!frags)
527 goto fail;
528
529 hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
530 seq = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ;
531 pos = first->data + hdrlen + per_fragm;
532 left = payload_len - per_fragm;
533 for (i = 0; i < num_fragm - 1; i++) {
534 struct ieee80211_hdr *fhdr;
535 size_t copylen;
536
537 if (left <= 0)
538 goto fail;
539
540 /* reserve enough extra head and tail room for possible
541 * encryption */
542 frag = frags[i] =
543 dev_alloc_skb(tx->local->tx_headroom +
544 frag_threshold +
545 IEEE80211_ENCRYPT_HEADROOM +
546 IEEE80211_ENCRYPT_TAILROOM);
547 if (!frag)
548 goto fail;
549 /* Make sure that all fragments use the same priority so
550 * that they end up using the same TX queue */
551 frag->priority = first->priority;
552 skb_reserve(frag, tx->local->tx_headroom +
553 IEEE80211_ENCRYPT_HEADROOM);
554 fhdr = (struct ieee80211_hdr *) skb_put(frag, hdrlen);
555 memcpy(fhdr, first->data, hdrlen);
556 if (i == num_fragm - 2)
557 fhdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREFRAGS);
558 fhdr->seq_ctrl = cpu_to_le16(seq | ((i + 1) & IEEE80211_SCTL_FRAG));
559 copylen = left > per_fragm ? per_fragm : left;
560 memcpy(skb_put(frag, copylen), pos, copylen);
561
562 pos += copylen;
563 left -= copylen;
564 }
565 skb_trim(first, hdrlen + per_fragm);
566
Johannes Berg5cf121c2008-02-25 16:27:43 +0100567 tx->num_extra_frag = num_fragm - 1;
568 tx->extra_frag = frags;
Johannes Berge2ebc742007-07-27 15:43:22 +0200569
Johannes Berg9ae54c82008-01-31 19:48:20 +0100570 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200571
572 fail:
573 printk(KERN_DEBUG "%s: failed to fragment frame\n", tx->dev->name);
574 if (frags) {
575 for (i = 0; i < num_fragm - 1; i++)
576 if (frags[i])
577 dev_kfree_skb(frags[i]);
578 kfree(frags);
579 }
580 I802_DEBUG_INC(tx->local->tx_handlers_drop_fragment);
Johannes Berg9ae54c82008-01-31 19:48:20 +0100581 return TX_DROP;
Johannes Berge2ebc742007-07-27 15:43:22 +0200582}
583
Johannes Berg9ae54c82008-01-31 19:48:20 +0100584static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100585ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200586{
Johannes Berg6a22a592007-09-26 15:19:41 +0200587 if (!tx->key)
Johannes Berg9ae54c82008-01-31 19:48:20 +0100588 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200589
Johannes Berg6a22a592007-09-26 15:19:41 +0200590 switch (tx->key->conf.alg) {
591 case ALG_WEP:
592 return ieee80211_crypto_wep_encrypt(tx);
593 case ALG_TKIP:
594 return ieee80211_crypto_tkip_encrypt(tx);
595 case ALG_CCMP:
596 return ieee80211_crypto_ccmp_encrypt(tx);
Johannes Berge2ebc742007-07-27 15:43:22 +0200597 }
598
Johannes Berg6a22a592007-09-26 15:19:41 +0200599 /* not reached */
600 WARN_ON(1);
Johannes Berg9ae54c82008-01-31 19:48:20 +0100601 return TX_DROP;
Johannes Berge2ebc742007-07-27 15:43:22 +0200602}
603
Johannes Berg9ae54c82008-01-31 19:48:20 +0100604static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100605ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200606{
Mattias Nissler1abbe492007-12-20 13:50:07 +0100607 struct rate_selection rsel;
Johannes Berg8318d782008-01-24 19:38:38 +0100608 struct ieee80211_supported_band *sband;
609
610 sband = tx->local->hw.wiphy->bands[tx->local->hw.conf.channel->band];
Johannes Berge2ebc742007-07-27 15:43:22 +0200611
Johannes Berg5cf121c2008-02-25 16:27:43 +0100612 if (likely(!tx->rate)) {
Johannes Berg8318d782008-01-24 19:38:38 +0100613 rate_control_get_rate(tx->dev, sband, tx->skb, &rsel);
Johannes Berg5cf121c2008-02-25 16:27:43 +0100614 tx->rate = rsel.rate;
Johannes Berg8318d782008-01-24 19:38:38 +0100615 if (unlikely(rsel.probe)) {
Johannes Berg5cf121c2008-02-25 16:27:43 +0100616 tx->control->flags |=
Johannes Berg58d41852007-09-26 17:53:18 +0200617 IEEE80211_TXCTL_RATE_CTRL_PROBE;
Johannes Berg5cf121c2008-02-25 16:27:43 +0100618 tx->flags |= IEEE80211_TX_PROBE_LAST_FRAG;
619 tx->control->alt_retry_rate = tx->rate;
620 tx->rate = rsel.probe;
Johannes Berg58d41852007-09-26 17:53:18 +0200621 } else
Johannes Berg5cf121c2008-02-25 16:27:43 +0100622 tx->control->alt_retry_rate = NULL;
Johannes Berg58d41852007-09-26 17:53:18 +0200623
Johannes Berg5cf121c2008-02-25 16:27:43 +0100624 if (!tx->rate)
Johannes Berg9ae54c82008-01-31 19:48:20 +0100625 return TX_DROP;
Johannes Berg58d41852007-09-26 17:53:18 +0200626 } else
Johannes Berg5cf121c2008-02-25 16:27:43 +0100627 tx->control->alt_retry_rate = NULL;
Johannes Berg58d41852007-09-26 17:53:18 +0200628
Johannes Berg8318d782008-01-24 19:38:38 +0100629 if (tx->sdata->bss_conf.use_cts_prot &&
Johannes Berg5cf121c2008-02-25 16:27:43 +0100630 (tx->flags & IEEE80211_TX_FRAGMENTED) && rsel.nonerp) {
631 tx->last_frag_rate = tx->rate;
Mattias Nissler1abbe492007-12-20 13:50:07 +0100632 if (rsel.probe)
Johannes Berg5cf121c2008-02-25 16:27:43 +0100633 tx->flags &= ~IEEE80211_TX_PROBE_LAST_FRAG;
Jiri Slabybadffb72007-08-28 17:01:54 -0400634 else
Johannes Berg5cf121c2008-02-25 16:27:43 +0100635 tx->flags |= IEEE80211_TX_PROBE_LAST_FRAG;
636 tx->rate = rsel.nonerp;
637 tx->control->tx_rate = rsel.nonerp;
638 tx->control->flags &= ~IEEE80211_TXCTL_RATE_CTRL_PROBE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200639 } else {
Johannes Berg5cf121c2008-02-25 16:27:43 +0100640 tx->last_frag_rate = tx->rate;
641 tx->control->tx_rate = tx->rate;
Johannes Berge2ebc742007-07-27 15:43:22 +0200642 }
Johannes Berg5cf121c2008-02-25 16:27:43 +0100643 tx->control->tx_rate = tx->rate;
Johannes Berge2ebc742007-07-27 15:43:22 +0200644
Johannes Berg9ae54c82008-01-31 19:48:20 +0100645 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200646}
647
Johannes Berg9ae54c82008-01-31 19:48:20 +0100648static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100649ieee80211_tx_h_misc(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200650{
651 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200652 u16 fc = le16_to_cpu(hdr->frame_control);
Johannes Berge2ebc742007-07-27 15:43:22 +0200653 u16 dur;
Johannes Berg5cf121c2008-02-25 16:27:43 +0100654 struct ieee80211_tx_control *control = tx->control;
Johannes Berge2ebc742007-07-27 15:43:22 +0200655
Johannes Berg58d41852007-09-26 17:53:18 +0200656 if (!control->retry_limit) {
657 if (!is_multicast_ether_addr(hdr->addr1)) {
658 if (tx->skb->len + FCS_LEN > tx->local->rts_threshold
659 && tx->local->rts_threshold <
660 IEEE80211_MAX_RTS_THRESHOLD) {
661 control->flags |=
662 IEEE80211_TXCTL_USE_RTS_CTS;
663 control->flags |=
664 IEEE80211_TXCTL_LONG_RETRY_LIMIT;
665 control->retry_limit =
666 tx->local->long_retry_limit;
667 } else {
668 control->retry_limit =
669 tx->local->short_retry_limit;
670 }
Johannes Berge2ebc742007-07-27 15:43:22 +0200671 } else {
Johannes Berg58d41852007-09-26 17:53:18 +0200672 control->retry_limit = 1;
Johannes Berge2ebc742007-07-27 15:43:22 +0200673 }
Johannes Berge2ebc742007-07-27 15:43:22 +0200674 }
675
Johannes Berg5cf121c2008-02-25 16:27:43 +0100676 if (tx->flags & IEEE80211_TX_FRAGMENTED) {
Johannes Berge2ebc742007-07-27 15:43:22 +0200677 /* Do not use multiple retry rates when sending fragmented
678 * frames.
679 * TODO: The last fragment could still use multiple retry
680 * rates. */
Johannes Berg8318d782008-01-24 19:38:38 +0100681 control->alt_retry_rate = NULL;
Johannes Berge2ebc742007-07-27 15:43:22 +0200682 }
683
684 /* Use CTS protection for unicast frames sent using extended rates if
685 * there are associated non-ERP stations and RTS/CTS is not configured
686 * for the frame. */
Johannes Berg8318d782008-01-24 19:38:38 +0100687 if ((tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) &&
Johannes Berg5cf121c2008-02-25 16:27:43 +0100688 (tx->rate->flags & IEEE80211_RATE_ERP_G) &&
689 (tx->flags & IEEE80211_TX_UNICAST) &&
Johannes Berg471b3ef2007-12-28 14:32:58 +0100690 tx->sdata->bss_conf.use_cts_prot &&
Johannes Berge2ebc742007-07-27 15:43:22 +0200691 !(control->flags & IEEE80211_TXCTL_USE_RTS_CTS))
692 control->flags |= IEEE80211_TXCTL_USE_CTS_PROTECT;
693
Daniel Drake7e9ed182007-07-27 15:43:24 +0200694 /* Transmit data frames using short preambles if the driver supports
695 * short preambles at the selected rate and short preambles are
696 * available on the network at the current point in time. */
697 if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) &&
Johannes Berg5cf121c2008-02-25 16:27:43 +0100698 (tx->rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
Johannes Berg471b3ef2007-12-28 14:32:58 +0100699 tx->sdata->bss_conf.use_short_preamble &&
Daniel Drake7e9ed182007-07-27 15:43:24 +0200700 (!tx->sta || (tx->sta->flags & WLAN_STA_SHORT_PREAMBLE))) {
Johannes Berg5cf121c2008-02-25 16:27:43 +0100701 tx->control->flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
Daniel Drake7e9ed182007-07-27 15:43:24 +0200702 }
703
Johannes Berge2ebc742007-07-27 15:43:22 +0200704 /* Setup duration field for the first fragment of the frame. Duration
705 * for remaining fragments will be updated when they are being sent
706 * to low-level driver in ieee80211_tx(). */
707 dur = ieee80211_duration(tx, is_multicast_ether_addr(hdr->addr1),
Johannes Berg5cf121c2008-02-25 16:27:43 +0100708 (tx->flags & IEEE80211_TX_FRAGMENTED) ?
709 tx->extra_frag[0]->len : 0);
Johannes Berge2ebc742007-07-27 15:43:22 +0200710 hdr->duration_id = cpu_to_le16(dur);
711
712 if ((control->flags & IEEE80211_TXCTL_USE_RTS_CTS) ||
713 (control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)) {
Johannes Berg8318d782008-01-24 19:38:38 +0100714 struct ieee80211_supported_band *sband;
715 struct ieee80211_rate *rate, *baserate;
716 int idx;
717
718 sband = tx->local->hw.wiphy->bands[
719 tx->local->hw.conf.channel->band];
Johannes Berge2ebc742007-07-27 15:43:22 +0200720
721 /* Do not use multiple retry rates when using RTS/CTS */
Johannes Berg8318d782008-01-24 19:38:38 +0100722 control->alt_retry_rate = NULL;
Johannes Berge2ebc742007-07-27 15:43:22 +0200723
724 /* Use min(data rate, max base rate) as CTS/RTS rate */
Johannes Berg5cf121c2008-02-25 16:27:43 +0100725 rate = tx->rate;
Johannes Berg8318d782008-01-24 19:38:38 +0100726 baserate = NULL;
Johannes Berge2ebc742007-07-27 15:43:22 +0200727
Johannes Berg8318d782008-01-24 19:38:38 +0100728 for (idx = 0; idx < sband->n_bitrates; idx++) {
729 if (sband->bitrates[idx].bitrate > rate->bitrate)
730 continue;
731 if (tx->sdata->basic_rates & BIT(idx) &&
732 (!baserate ||
733 (baserate->bitrate < sband->bitrates[idx].bitrate)))
734 baserate = &sband->bitrates[idx];
735 }
736
737 if (baserate)
738 control->rts_cts_rate = baserate;
739 else
740 control->rts_cts_rate = &sband->bitrates[0];
Johannes Berge2ebc742007-07-27 15:43:22 +0200741 }
742
743 if (tx->sta) {
Chrfff77102008-04-01 21:45:18 +0200744 control->aid = tx->sta->aid;
Johannes Berge2ebc742007-07-27 15:43:22 +0200745 tx->sta->tx_packets++;
746 tx->sta->tx_fragments++;
747 tx->sta->tx_bytes += tx->skb->len;
Johannes Berg5cf121c2008-02-25 16:27:43 +0100748 if (tx->extra_frag) {
Johannes Berge2ebc742007-07-27 15:43:22 +0200749 int i;
Johannes Berg5cf121c2008-02-25 16:27:43 +0100750 tx->sta->tx_fragments += tx->num_extra_frag;
751 for (i = 0; i < tx->num_extra_frag; i++) {
Johannes Berge2ebc742007-07-27 15:43:22 +0200752 tx->sta->tx_bytes +=
Johannes Berg5cf121c2008-02-25 16:27:43 +0100753 tx->extra_frag[i]->len;
Johannes Berge2ebc742007-07-27 15:43:22 +0200754 }
755 }
756 }
757
Johannes Berg9ae54c82008-01-31 19:48:20 +0100758 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200759}
760
Johannes Berg9ae54c82008-01-31 19:48:20 +0100761static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100762ieee80211_tx_h_load_stats(struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +0200763{
764 struct ieee80211_local *local = tx->local;
Johannes Berge2ebc742007-07-27 15:43:22 +0200765 struct sk_buff *skb = tx->skb;
766 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
767 u32 load = 0, hdrtime;
Johannes Berg5cf121c2008-02-25 16:27:43 +0100768 struct ieee80211_rate *rate = tx->rate;
Johannes Berge2ebc742007-07-27 15:43:22 +0200769
770 /* TODO: this could be part of tx_status handling, so that the number
771 * of retries would be known; TX rate should in that case be stored
772 * somewhere with the packet */
773
774 /* Estimate total channel use caused by this frame */
775
776 /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values,
777 * 1 usec = 1/8 * (1080 / 10) = 13.5 */
778
Johannes Berg5cf121c2008-02-25 16:27:43 +0100779 if (tx->channel->band == IEEE80211_BAND_5GHZ ||
780 (tx->channel->band == IEEE80211_BAND_2GHZ &&
Johannes Berg8318d782008-01-24 19:38:38 +0100781 rate->flags & IEEE80211_RATE_ERP_G))
Johannes Berge2ebc742007-07-27 15:43:22 +0200782 hdrtime = CHAN_UTIL_HDR_SHORT;
783 else
784 hdrtime = CHAN_UTIL_HDR_LONG;
785
786 load = hdrtime;
787 if (!is_multicast_ether_addr(hdr->addr1))
788 load += hdrtime;
789
Johannes Berg5cf121c2008-02-25 16:27:43 +0100790 if (tx->control->flags & IEEE80211_TXCTL_USE_RTS_CTS)
Johannes Berge2ebc742007-07-27 15:43:22 +0200791 load += 2 * hdrtime;
Johannes Berg5cf121c2008-02-25 16:27:43 +0100792 else if (tx->control->flags & IEEE80211_TXCTL_USE_CTS_PROTECT)
Johannes Berge2ebc742007-07-27 15:43:22 +0200793 load += hdrtime;
794
Johannes Berg8318d782008-01-24 19:38:38 +0100795 /* TODO: optimise again */
796 load += skb->len * CHAN_UTIL_RATE_LCM / rate->bitrate;
Johannes Berge2ebc742007-07-27 15:43:22 +0200797
Johannes Berg5cf121c2008-02-25 16:27:43 +0100798 if (tx->extra_frag) {
Johannes Berge2ebc742007-07-27 15:43:22 +0200799 int i;
Johannes Berg5cf121c2008-02-25 16:27:43 +0100800 for (i = 0; i < tx->num_extra_frag; i++) {
Johannes Berge2ebc742007-07-27 15:43:22 +0200801 load += 2 * hdrtime;
Johannes Berg5cf121c2008-02-25 16:27:43 +0100802 load += tx->extra_frag[i]->len *
803 tx->rate->bitrate;
Johannes Berge2ebc742007-07-27 15:43:22 +0200804 }
805 }
806
807 /* Divide channel_use by 8 to avoid wrapping around the counter */
808 load >>= CHAN_UTIL_SHIFT;
809 local->channel_use_raw += load;
810 if (tx->sta)
811 tx->sta->channel_use_raw += load;
812 tx->sdata->channel_use_raw += load;
813
Johannes Berg9ae54c82008-01-31 19:48:20 +0100814 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200815}
816
Johannes Berge2ebc742007-07-27 15:43:22 +0200817
Johannes Berg5cf121c2008-02-25 16:27:43 +0100818typedef ieee80211_tx_result (*ieee80211_tx_handler)(struct ieee80211_tx_data *);
Johannes Berg58905292008-01-31 19:48:25 +0100819static ieee80211_tx_handler ieee80211_tx_handlers[] =
Johannes Berge2ebc742007-07-27 15:43:22 +0200820{
821 ieee80211_tx_h_check_assoc,
822 ieee80211_tx_h_sequence,
823 ieee80211_tx_h_ps_buf,
824 ieee80211_tx_h_select_key,
825 ieee80211_tx_h_michael_mic_add,
826 ieee80211_tx_h_fragment,
Johannes Berg6a22a592007-09-26 15:19:41 +0200827 ieee80211_tx_h_encrypt,
Johannes Berge2ebc742007-07-27 15:43:22 +0200828 ieee80211_tx_h_rate_ctrl,
829 ieee80211_tx_h_misc,
830 ieee80211_tx_h_load_stats,
831 NULL
832};
833
834/* actual transmit path */
835
836/*
837 * deal with packet injection down monitor interface
838 * with Radiotap Header -- only called for monitor mode interface
839 */
Johannes Berg9ae54c82008-01-31 19:48:20 +0100840static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100841__ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx,
Johannes Berg58d41852007-09-26 17:53:18 +0200842 struct sk_buff *skb)
Johannes Berge2ebc742007-07-27 15:43:22 +0200843{
844 /*
845 * this is the moment to interpret and discard the radiotap header that
846 * must be at the start of the packet injected in Monitor mode
847 *
848 * Need to take some care with endian-ness since radiotap
849 * args are little-endian
850 */
851
852 struct ieee80211_radiotap_iterator iterator;
853 struct ieee80211_radiotap_header *rthdr =
854 (struct ieee80211_radiotap_header *) skb->data;
Johannes Berg8318d782008-01-24 19:38:38 +0100855 struct ieee80211_supported_band *sband;
Johannes Berge2ebc742007-07-27 15:43:22 +0200856 int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len);
Johannes Berg5cf121c2008-02-25 16:27:43 +0100857 struct ieee80211_tx_control *control = tx->control;
Johannes Berge2ebc742007-07-27 15:43:22 +0200858
Johannes Berg8318d782008-01-24 19:38:38 +0100859 sband = tx->local->hw.wiphy->bands[tx->local->hw.conf.channel->band];
860
Johannes Berg58d41852007-09-26 17:53:18 +0200861 control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
Johannes Berg5cf121c2008-02-25 16:27:43 +0100862 tx->flags |= IEEE80211_TX_INJECTED;
863 tx->flags &= ~IEEE80211_TX_FRAGMENTED;
Johannes Berge2ebc742007-07-27 15:43:22 +0200864
865 /*
866 * for every radiotap entry that is present
867 * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
868 * entries present, or -EINVAL on error)
869 */
870
871 while (!ret) {
872 int i, target_rate;
873
874 ret = ieee80211_radiotap_iterator_next(&iterator);
875
876 if (ret)
877 continue;
878
879 /* see if this argument is something we can use */
880 switch (iterator.this_arg_index) {
881 /*
882 * You must take care when dereferencing iterator.this_arg
883 * for multibyte types... the pointer is not aligned. Use
884 * get_unaligned((type *)iterator.this_arg) to dereference
885 * iterator.this_arg for type "type" safely on all arches.
886 */
887 case IEEE80211_RADIOTAP_RATE:
888 /*
889 * radiotap rate u8 is in 500kbps units eg, 0x02=1Mbps
890 * ieee80211 rate int is in 100kbps units eg, 0x0a=1Mbps
891 */
892 target_rate = (*iterator.this_arg) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100893 for (i = 0; i < sband->n_bitrates; i++) {
894 struct ieee80211_rate *r;
Johannes Berge2ebc742007-07-27 15:43:22 +0200895
Johannes Berg8318d782008-01-24 19:38:38 +0100896 r = &sband->bitrates[i];
897
898 if (r->bitrate == target_rate) {
Johannes Berg5cf121c2008-02-25 16:27:43 +0100899 tx->rate = r;
Johannes Berg58d41852007-09-26 17:53:18 +0200900 break;
901 }
Johannes Berge2ebc742007-07-27 15:43:22 +0200902 }
903 break;
904
905 case IEEE80211_RADIOTAP_ANTENNA:
906 /*
907 * radiotap uses 0 for 1st ant, mac80211 is 1 for
908 * 1st ant
909 */
910 control->antenna_sel_tx = (*iterator.this_arg) + 1;
911 break;
912
Johannes Berg8318d782008-01-24 19:38:38 +0100913#if 0
Johannes Berge2ebc742007-07-27 15:43:22 +0200914 case IEEE80211_RADIOTAP_DBM_TX_POWER:
915 control->power_level = *iterator.this_arg;
916 break;
Johannes Berg8318d782008-01-24 19:38:38 +0100917#endif
Johannes Berge2ebc742007-07-27 15:43:22 +0200918
919 case IEEE80211_RADIOTAP_FLAGS:
920 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
921 /*
922 * this indicates that the skb we have been
923 * handed has the 32-bit FCS CRC at the end...
924 * we should react to that by snipping it off
925 * because it will be recomputed and added
926 * on transmission
927 */
928 if (skb->len < (iterator.max_length + FCS_LEN))
Johannes Berg9ae54c82008-01-31 19:48:20 +0100929 return TX_DROP;
Johannes Berge2ebc742007-07-27 15:43:22 +0200930
931 skb_trim(skb, skb->len - FCS_LEN);
932 }
Johannes Berg58d41852007-09-26 17:53:18 +0200933 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
934 control->flags &=
935 ~IEEE80211_TXCTL_DO_NOT_ENCRYPT;
936 if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
Johannes Berg5cf121c2008-02-25 16:27:43 +0100937 tx->flags |= IEEE80211_TX_FRAGMENTED;
Johannes Berge2ebc742007-07-27 15:43:22 +0200938 break;
939
Johannes Berg58d41852007-09-26 17:53:18 +0200940 /*
941 * Please update the file
942 * Documentation/networking/mac80211-injection.txt
943 * when parsing new fields here.
944 */
945
Johannes Berge2ebc742007-07-27 15:43:22 +0200946 default:
947 break;
948 }
949 }
950
951 if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
Johannes Berg9ae54c82008-01-31 19:48:20 +0100952 return TX_DROP;
Johannes Berge2ebc742007-07-27 15:43:22 +0200953
954 /*
955 * remove the radiotap header
956 * iterator->max_length was sanity-checked against
957 * skb->len by iterator init
958 */
959 skb_pull(skb, iterator.max_length);
960
Johannes Berg9ae54c82008-01-31 19:48:20 +0100961 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +0200962}
963
Johannes Berg58d41852007-09-26 17:53:18 +0200964/*
965 * initialises @tx
966 */
Johannes Berg9ae54c82008-01-31 19:48:20 +0100967static ieee80211_tx_result
Johannes Berg5cf121c2008-02-25 16:27:43 +0100968__ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
Johannes Berge2ebc742007-07-27 15:43:22 +0200969 struct sk_buff *skb,
970 struct net_device *dev,
971 struct ieee80211_tx_control *control)
972{
973 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg58d41852007-09-26 17:53:18 +0200974 struct ieee80211_hdr *hdr;
Johannes Berge2ebc742007-07-27 15:43:22 +0200975 struct ieee80211_sub_if_data *sdata;
Johannes Berge2ebc742007-07-27 15:43:22 +0200976
977 int hdrlen;
978
979 memset(tx, 0, sizeof(*tx));
980 tx->skb = skb;
981 tx->dev = dev; /* use original interface */
982 tx->local = local;
983 tx->sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg5cf121c2008-02-25 16:27:43 +0100984 tx->control = control;
Johannes Berge2ebc742007-07-27 15:43:22 +0200985 /*
Johannes Berg58d41852007-09-26 17:53:18 +0200986 * Set this flag (used below to indicate "automatic fragmentation"),
987 * it will be cleared/left by radiotap as desired.
Johannes Berge2ebc742007-07-27 15:43:22 +0200988 */
Johannes Berg5cf121c2008-02-25 16:27:43 +0100989 tx->flags |= IEEE80211_TX_FRAGMENTED;
Johannes Berge2ebc742007-07-27 15:43:22 +0200990
991 /* process and remove the injection radiotap header */
992 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100993 if (unlikely(sdata->vif.type == IEEE80211_IF_TYPE_MNTR)) {
Johannes Berg9ae54c82008-01-31 19:48:20 +0100994 if (__ieee80211_parse_tx_radiotap(tx, skb) == TX_DROP)
995 return TX_DROP;
Johannes Berg58d41852007-09-26 17:53:18 +0200996
Johannes Berge2ebc742007-07-27 15:43:22 +0200997 /*
Johannes Berg58d41852007-09-26 17:53:18 +0200998 * __ieee80211_parse_tx_radiotap has now removed
999 * the radiotap header that was present and pre-filled
1000 * 'tx' with tx control information.
Johannes Berge2ebc742007-07-27 15:43:22 +02001001 */
Johannes Berge2ebc742007-07-27 15:43:22 +02001002 }
1003
Johannes Berg58d41852007-09-26 17:53:18 +02001004 hdr = (struct ieee80211_hdr *) skb->data;
1005
warmcat24338792007-09-14 11:10:25 -04001006 tx->sta = sta_info_get(local, hdr->addr1);
1007 tx->fc = le16_to_cpu(hdr->frame_control);
Johannes Berg58d41852007-09-26 17:53:18 +02001008
Jiri Slabybadffb72007-08-28 17:01:54 -04001009 if (is_multicast_ether_addr(hdr->addr1)) {
Johannes Berg5cf121c2008-02-25 16:27:43 +01001010 tx->flags &= ~IEEE80211_TX_UNICAST;
Johannes Berge2ebc742007-07-27 15:43:22 +02001011 control->flags |= IEEE80211_TXCTL_NO_ACK;
Jiri Slabybadffb72007-08-28 17:01:54 -04001012 } else {
Johannes Berg5cf121c2008-02-25 16:27:43 +01001013 tx->flags |= IEEE80211_TX_UNICAST;
Johannes Berge2ebc742007-07-27 15:43:22 +02001014 control->flags &= ~IEEE80211_TXCTL_NO_ACK;
Jiri Slabybadffb72007-08-28 17:01:54 -04001015 }
Johannes Berg58d41852007-09-26 17:53:18 +02001016
Johannes Berg5cf121c2008-02-25 16:27:43 +01001017 if (tx->flags & IEEE80211_TX_FRAGMENTED) {
1018 if ((tx->flags & IEEE80211_TX_UNICAST) &&
Johannes Berg58d41852007-09-26 17:53:18 +02001019 skb->len + FCS_LEN > local->fragmentation_threshold &&
1020 !local->ops->set_frag_threshold)
Johannes Berg5cf121c2008-02-25 16:27:43 +01001021 tx->flags |= IEEE80211_TX_FRAGMENTED;
Johannes Berg58d41852007-09-26 17:53:18 +02001022 else
Johannes Berg5cf121c2008-02-25 16:27:43 +01001023 tx->flags &= ~IEEE80211_TX_FRAGMENTED;
Johannes Berg58d41852007-09-26 17:53:18 +02001024 }
1025
Johannes Berge2ebc742007-07-27 15:43:22 +02001026 if (!tx->sta)
Johannes Bergd46e1442008-02-20 23:59:33 +01001027 control->flags |= IEEE80211_TXCTL_CLEAR_PS_FILT;
1028 else if (tx->sta->flags & WLAN_STA_CLEAR_PS_FILT) {
1029 control->flags |= IEEE80211_TXCTL_CLEAR_PS_FILT;
1030 tx->sta->flags &= ~WLAN_STA_CLEAR_PS_FILT;
Johannes Berge2ebc742007-07-27 15:43:22 +02001031 }
Johannes Berg58d41852007-09-26 17:53:18 +02001032
Johannes Berge2ebc742007-07-27 15:43:22 +02001033 hdrlen = ieee80211_get_hdrlen(tx->fc);
1034 if (skb->len > hdrlen + sizeof(rfc1042_header) + 2) {
1035 u8 *pos = &skb->data[hdrlen + sizeof(rfc1042_header)];
1036 tx->ethertype = (pos[0] << 8) | pos[1];
1037 }
1038 control->flags |= IEEE80211_TXCTL_FIRST_FRAGMENT;
1039
Johannes Berg9ae54c82008-01-31 19:48:20 +01001040 return TX_CONTINUE;
Johannes Berge2ebc742007-07-27 15:43:22 +02001041}
1042
Johannes Berg32bfd352007-12-19 01:31:26 +01001043/*
Johannes Berg58d41852007-09-26 17:53:18 +02001044 * NB: @tx is uninitialised when passed in here
1045 */
Johannes Berg5cf121c2008-02-25 16:27:43 +01001046static int ieee80211_tx_prepare(struct ieee80211_tx_data *tx,
Johannes Berg58d41852007-09-26 17:53:18 +02001047 struct sk_buff *skb,
1048 struct net_device *mdev,
1049 struct ieee80211_tx_control *control)
Johannes Berge2ebc742007-07-27 15:43:22 +02001050{
1051 struct ieee80211_tx_packet_data *pkt_data;
1052 struct net_device *dev;
1053
1054 pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
Eric W. Biederman881d9662007-09-17 11:56:21 -07001055 dev = dev_get_by_index(&init_net, pkt_data->ifindex);
Johannes Berge2ebc742007-07-27 15:43:22 +02001056 if (unlikely(dev && !is_ieee80211_device(dev, mdev))) {
1057 dev_put(dev);
1058 dev = NULL;
1059 }
1060 if (unlikely(!dev))
1061 return -ENODEV;
Johannes Berg58d41852007-09-26 17:53:18 +02001062 /* initialises tx with control */
Johannes Berge2ebc742007-07-27 15:43:22 +02001063 __ieee80211_tx_prepare(tx, skb, dev, control);
Johannes Berg32bfd352007-12-19 01:31:26 +01001064 dev_put(dev);
Johannes Berge2ebc742007-07-27 15:43:22 +02001065 return 0;
1066}
1067
1068static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb,
Johannes Berg5cf121c2008-02-25 16:27:43 +01001069 struct ieee80211_tx_data *tx)
Johannes Berge2ebc742007-07-27 15:43:22 +02001070{
Johannes Berg5cf121c2008-02-25 16:27:43 +01001071 struct ieee80211_tx_control *control = tx->control;
Johannes Berge2ebc742007-07-27 15:43:22 +02001072 int ret, i;
1073
1074 if (!ieee80211_qdisc_installed(local->mdev) &&
1075 __ieee80211_queue_stopped(local, 0)) {
1076 netif_stop_queue(local->mdev);
1077 return IEEE80211_TX_AGAIN;
1078 }
1079 if (skb) {
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001080 ieee80211_dump_frame(wiphy_name(local->hw.wiphy),
1081 "TX to low-level driver", skb);
Johannes Berge2ebc742007-07-27 15:43:22 +02001082 ret = local->ops->tx(local_to_hw(local), skb, control);
1083 if (ret)
1084 return IEEE80211_TX_AGAIN;
1085 local->mdev->trans_start = jiffies;
1086 ieee80211_led_tx(local, 1);
1087 }
Johannes Berg5cf121c2008-02-25 16:27:43 +01001088 if (tx->extra_frag) {
Johannes Berge2ebc742007-07-27 15:43:22 +02001089 control->flags &= ~(IEEE80211_TXCTL_USE_RTS_CTS |
1090 IEEE80211_TXCTL_USE_CTS_PROTECT |
Johannes Bergd46e1442008-02-20 23:59:33 +01001091 IEEE80211_TXCTL_CLEAR_PS_FILT |
Johannes Berge2ebc742007-07-27 15:43:22 +02001092 IEEE80211_TXCTL_FIRST_FRAGMENT);
Johannes Berg5cf121c2008-02-25 16:27:43 +01001093 for (i = 0; i < tx->num_extra_frag; i++) {
1094 if (!tx->extra_frag[i])
Johannes Berge2ebc742007-07-27 15:43:22 +02001095 continue;
1096 if (__ieee80211_queue_stopped(local, control->queue))
1097 return IEEE80211_TX_FRAG_AGAIN;
Johannes Berg5cf121c2008-02-25 16:27:43 +01001098 if (i == tx->num_extra_frag) {
1099 control->tx_rate = tx->last_frag_rate;
Johannes Berg8318d782008-01-24 19:38:38 +01001100
Johannes Berg5cf121c2008-02-25 16:27:43 +01001101 if (tx->flags & IEEE80211_TX_PROBE_LAST_FRAG)
Johannes Berge2ebc742007-07-27 15:43:22 +02001102 control->flags |=
1103 IEEE80211_TXCTL_RATE_CTRL_PROBE;
1104 else
1105 control->flags &=
1106 ~IEEE80211_TXCTL_RATE_CTRL_PROBE;
1107 }
1108
Johannes Bergdd1cd4c2007-09-18 17:29:20 -04001109 ieee80211_dump_frame(wiphy_name(local->hw.wiphy),
Johannes Berge2ebc742007-07-27 15:43:22 +02001110 "TX to low-level driver",
Johannes Berg5cf121c2008-02-25 16:27:43 +01001111 tx->extra_frag[i]);
Johannes Berge2ebc742007-07-27 15:43:22 +02001112 ret = local->ops->tx(local_to_hw(local),
Johannes Berg5cf121c2008-02-25 16:27:43 +01001113 tx->extra_frag[i],
Johannes Berge2ebc742007-07-27 15:43:22 +02001114 control);
1115 if (ret)
1116 return IEEE80211_TX_FRAG_AGAIN;
1117 local->mdev->trans_start = jiffies;
1118 ieee80211_led_tx(local, 1);
Johannes Berg5cf121c2008-02-25 16:27:43 +01001119 tx->extra_frag[i] = NULL;
Johannes Berge2ebc742007-07-27 15:43:22 +02001120 }
Johannes Berg5cf121c2008-02-25 16:27:43 +01001121 kfree(tx->extra_frag);
1122 tx->extra_frag = NULL;
Johannes Berge2ebc742007-07-27 15:43:22 +02001123 }
1124 return IEEE80211_TX_OK;
1125}
1126
1127static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb,
Johannes Bergf9d540e2007-09-28 14:02:09 +02001128 struct ieee80211_tx_control *control)
Johannes Berge2ebc742007-07-27 15:43:22 +02001129{
1130 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1131 struct sta_info *sta;
1132 ieee80211_tx_handler *handler;
Johannes Berg5cf121c2008-02-25 16:27:43 +01001133 struct ieee80211_tx_data tx;
Johannes Berg9ae54c82008-01-31 19:48:20 +01001134 ieee80211_tx_result res = TX_DROP, res_prepare;
Johannes Bergef3a62d2008-06-18 15:39:48 -07001135 int ret, i, retries = 0;
Johannes Berge2ebc742007-07-27 15:43:22 +02001136
1137 WARN_ON(__ieee80211_queue_pending(local, control->queue));
1138
1139 if (unlikely(skb->len < 10)) {
1140 dev_kfree_skb(skb);
1141 return 0;
1142 }
1143
Johannes Bergd0709a62008-02-25 16:27:46 +01001144 rcu_read_lock();
1145
Johannes Berg58d41852007-09-26 17:53:18 +02001146 /* initialises tx */
Johannes Berge2ebc742007-07-27 15:43:22 +02001147 res_prepare = __ieee80211_tx_prepare(&tx, skb, dev, control);
1148
Johannes Berg9ae54c82008-01-31 19:48:20 +01001149 if (res_prepare == TX_DROP) {
Johannes Berge2ebc742007-07-27 15:43:22 +02001150 dev_kfree_skb(skb);
Johannes Bergd0709a62008-02-25 16:27:46 +01001151 rcu_read_unlock();
Johannes Berge2ebc742007-07-27 15:43:22 +02001152 return 0;
1153 }
1154
1155 sta = tx.sta;
Johannes Berg5cf121c2008-02-25 16:27:43 +01001156 tx.channel = local->hw.conf.channel;
Johannes Berge2ebc742007-07-27 15:43:22 +02001157
Johannes Berg58905292008-01-31 19:48:25 +01001158 for (handler = ieee80211_tx_handlers; *handler != NULL;
Johannes Berg58d41852007-09-26 17:53:18 +02001159 handler++) {
1160 res = (*handler)(&tx);
Johannes Berg9ae54c82008-01-31 19:48:20 +01001161 if (res != TX_CONTINUE)
Johannes Berg58d41852007-09-26 17:53:18 +02001162 break;
Johannes Berge2ebc742007-07-27 15:43:22 +02001163 }
1164
1165 skb = tx.skb; /* handlers are allowed to change skb */
1166
Johannes Berg9ae54c82008-01-31 19:48:20 +01001167 if (unlikely(res == TX_DROP)) {
Johannes Berge2ebc742007-07-27 15:43:22 +02001168 I802_DEBUG_INC(local->tx_handlers_drop);
1169 goto drop;
1170 }
1171
Johannes Berg9ae54c82008-01-31 19:48:20 +01001172 if (unlikely(res == TX_QUEUED)) {
Johannes Berge2ebc742007-07-27 15:43:22 +02001173 I802_DEBUG_INC(local->tx_handlers_queued);
Johannes Bergd4e46a32007-09-14 11:10:24 -04001174 rcu_read_unlock();
Johannes Berge2ebc742007-07-27 15:43:22 +02001175 return 0;
1176 }
1177
Johannes Berg5cf121c2008-02-25 16:27:43 +01001178 if (tx.extra_frag) {
1179 for (i = 0; i < tx.num_extra_frag; i++) {
Johannes Berge2ebc742007-07-27 15:43:22 +02001180 int next_len, dur;
1181 struct ieee80211_hdr *hdr =
1182 (struct ieee80211_hdr *)
Johannes Berg5cf121c2008-02-25 16:27:43 +01001183 tx.extra_frag[i]->data;
Johannes Berge2ebc742007-07-27 15:43:22 +02001184
Johannes Berg5cf121c2008-02-25 16:27:43 +01001185 if (i + 1 < tx.num_extra_frag) {
1186 next_len = tx.extra_frag[i + 1]->len;
Johannes Berge2ebc742007-07-27 15:43:22 +02001187 } else {
1188 next_len = 0;
Johannes Berg5cf121c2008-02-25 16:27:43 +01001189 tx.rate = tx.last_frag_rate;
Johannes Berge2ebc742007-07-27 15:43:22 +02001190 }
1191 dur = ieee80211_duration(&tx, 0, next_len);
1192 hdr->duration_id = cpu_to_le16(dur);
1193 }
1194 }
1195
1196retry:
1197 ret = __ieee80211_tx(local, skb, &tx);
1198 if (ret) {
1199 struct ieee80211_tx_stored_packet *store =
1200 &local->pending_packet[control->queue];
1201
1202 if (ret == IEEE80211_TX_FRAG_AGAIN)
1203 skb = NULL;
1204 set_bit(IEEE80211_LINK_STATE_PENDING,
1205 &local->state[control->queue]);
1206 smp_mb();
1207 /* When the driver gets out of buffers during sending of
1208 * fragments and calls ieee80211_stop_queue, there is
1209 * a small window between IEEE80211_LINK_STATE_XOFF and
1210 * IEEE80211_LINK_STATE_PENDING flags are set. If a buffer
1211 * gets available in that window (i.e. driver calls
1212 * ieee80211_wake_queue), we would end up with ieee80211_tx
1213 * called with IEEE80211_LINK_STATE_PENDING. Prevent this by
1214 * continuing transmitting here when that situation is
1215 * possible to have happened. */
1216 if (!__ieee80211_queue_stopped(local, control->queue)) {
1217 clear_bit(IEEE80211_LINK_STATE_PENDING,
1218 &local->state[control->queue]);
Johannes Bergef3a62d2008-06-18 15:39:48 -07001219 retries++;
1220 /*
1221 * Driver bug, it's rejecting packets but
1222 * not stopping queues.
1223 */
1224 if (WARN_ON_ONCE(retries > 5))
1225 goto drop;
Johannes Berge2ebc742007-07-27 15:43:22 +02001226 goto retry;
1227 }
1228 memcpy(&store->control, control,
1229 sizeof(struct ieee80211_tx_control));
1230 store->skb = skb;
Johannes Berg5cf121c2008-02-25 16:27:43 +01001231 store->extra_frag = tx.extra_frag;
1232 store->num_extra_frag = tx.num_extra_frag;
1233 store->last_frag_rate = tx.last_frag_rate;
Jiri Slabybadffb72007-08-28 17:01:54 -04001234 store->last_frag_rate_ctrl_probe =
Johannes Berg5cf121c2008-02-25 16:27:43 +01001235 !!(tx.flags & IEEE80211_TX_PROBE_LAST_FRAG);
Johannes Berge2ebc742007-07-27 15:43:22 +02001236 }
Johannes Bergd4e46a32007-09-14 11:10:24 -04001237 rcu_read_unlock();
Johannes Berge2ebc742007-07-27 15:43:22 +02001238 return 0;
1239
1240 drop:
1241 if (skb)
1242 dev_kfree_skb(skb);
Johannes Berg5cf121c2008-02-25 16:27:43 +01001243 for (i = 0; i < tx.num_extra_frag; i++)
1244 if (tx.extra_frag[i])
1245 dev_kfree_skb(tx.extra_frag[i]);
1246 kfree(tx.extra_frag);
Johannes Bergd4e46a32007-09-14 11:10:24 -04001247 rcu_read_unlock();
Johannes Berge2ebc742007-07-27 15:43:22 +02001248 return 0;
1249}
1250
1251/* device xmit handlers */
1252
1253int ieee80211_master_start_xmit(struct sk_buff *skb,
1254 struct net_device *dev)
1255{
1256 struct ieee80211_tx_control control;
1257 struct ieee80211_tx_packet_data *pkt_data;
1258 struct net_device *odev = NULL;
1259 struct ieee80211_sub_if_data *osdata;
1260 int headroom;
1261 int ret;
1262
1263 /*
1264 * copy control out of the skb so other people can use skb->cb
1265 */
1266 pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
1267 memset(&control, 0, sizeof(struct ieee80211_tx_control));
1268
1269 if (pkt_data->ifindex)
Eric W. Biederman881d9662007-09-17 11:56:21 -07001270 odev = dev_get_by_index(&init_net, pkt_data->ifindex);
Johannes Berge2ebc742007-07-27 15:43:22 +02001271 if (unlikely(odev && !is_ieee80211_device(odev, dev))) {
1272 dev_put(odev);
1273 odev = NULL;
1274 }
1275 if (unlikely(!odev)) {
1276#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1277 printk(KERN_DEBUG "%s: Discarded packet with nonexistent "
1278 "originating device\n", dev->name);
1279#endif
1280 dev_kfree_skb(skb);
1281 return 0;
1282 }
1283 osdata = IEEE80211_DEV_TO_SUB_IF(odev);
1284
1285 headroom = osdata->local->tx_headroom + IEEE80211_ENCRYPT_HEADROOM;
1286 if (skb_headroom(skb) < headroom) {
1287 if (pskb_expand_head(skb, headroom, 0, GFP_ATOMIC)) {
1288 dev_kfree_skb(skb);
1289 dev_put(odev);
1290 return 0;
1291 }
1292 }
1293
Johannes Berg32bfd352007-12-19 01:31:26 +01001294 control.vif = &osdata->vif;
Johannes Berg51fb61e2007-12-19 01:31:27 +01001295 control.type = osdata->vif.type;
Jiri Slabye8bf9642007-08-28 17:01:54 -04001296 if (pkt_data->flags & IEEE80211_TXPD_REQ_TX_STATUS)
Johannes Berge2ebc742007-07-27 15:43:22 +02001297 control.flags |= IEEE80211_TXCTL_REQ_TX_STATUS;
Jiri Slabye8bf9642007-08-28 17:01:54 -04001298 if (pkt_data->flags & IEEE80211_TXPD_DO_NOT_ENCRYPT)
Johannes Berge2ebc742007-07-27 15:43:22 +02001299 control.flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
Jiri Slabye8bf9642007-08-28 17:01:54 -04001300 if (pkt_data->flags & IEEE80211_TXPD_REQUEUE)
Johannes Berge2ebc742007-07-27 15:43:22 +02001301 control.flags |= IEEE80211_TXCTL_REQUEUE;
Johannes Berg678f5f712007-12-19 01:31:23 +01001302 if (pkt_data->flags & IEEE80211_TXPD_EAPOL_FRAME)
1303 control.flags |= IEEE80211_TXCTL_EAPOL_FRAME;
Ron Rindjunsky9e723492008-01-28 14:07:18 +02001304 if (pkt_data->flags & IEEE80211_TXPD_AMPDU)
1305 control.flags |= IEEE80211_TXCTL_AMPDU;
Johannes Berge2ebc742007-07-27 15:43:22 +02001306 control.queue = pkt_data->queue;
1307
Johannes Bergf9d540e2007-09-28 14:02:09 +02001308 ret = ieee80211_tx(odev, skb, &control);
Johannes Berge2ebc742007-07-27 15:43:22 +02001309 dev_put(odev);
1310
1311 return ret;
1312}
1313
1314int ieee80211_monitor_start_xmit(struct sk_buff *skb,
1315 struct net_device *dev)
1316{
1317 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1318 struct ieee80211_tx_packet_data *pkt_data;
1319 struct ieee80211_radiotap_header *prthdr =
1320 (struct ieee80211_radiotap_header *)skb->data;
Andy Green9b8a74e2007-07-27 15:43:24 +02001321 u16 len_rthdr;
Johannes Berge2ebc742007-07-27 15:43:22 +02001322
Andy Green9b8a74e2007-07-27 15:43:24 +02001323 /* check for not even having the fixed radiotap header part */
1324 if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
1325 goto fail; /* too short to be possibly valid */
1326
1327 /* is it a header version we can trust to find length from? */
1328 if (unlikely(prthdr->it_version))
1329 goto fail; /* only version 0 is supported */
1330
1331 /* then there must be a radiotap header with a length we can use */
1332 len_rthdr = ieee80211_get_radiotap_len(skb->data);
1333
1334 /* does the skb contain enough to deliver on the alleged length? */
1335 if (unlikely(skb->len < len_rthdr))
1336 goto fail; /* skb too short for claimed rt header extent */
Johannes Berge2ebc742007-07-27 15:43:22 +02001337
1338 skb->dev = local->mdev;
1339
1340 pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
1341 memset(pkt_data, 0, sizeof(*pkt_data));
Andy Green9b8a74e2007-07-27 15:43:24 +02001342 /* needed because we set skb device to master */
Johannes Berge2ebc742007-07-27 15:43:22 +02001343 pkt_data->ifindex = dev->ifindex;
Andy Green9b8a74e2007-07-27 15:43:24 +02001344
Jiri Slabye8bf9642007-08-28 17:01:54 -04001345 pkt_data->flags |= IEEE80211_TXPD_DO_NOT_ENCRYPT;
Johannes Berge2ebc742007-07-27 15:43:22 +02001346
Johannes Berge2ebc742007-07-27 15:43:22 +02001347 /*
1348 * fix up the pointers accounting for the radiotap
1349 * header still being in there. We are being given
1350 * a precooked IEEE80211 header so no need for
1351 * normal processing
1352 */
Andy Green9b8a74e2007-07-27 15:43:24 +02001353 skb_set_mac_header(skb, len_rthdr);
Johannes Berge2ebc742007-07-27 15:43:22 +02001354 /*
Andy Green9b8a74e2007-07-27 15:43:24 +02001355 * these are just fixed to the end of the rt area since we
1356 * don't have any better information and at this point, nobody cares
Johannes Berge2ebc742007-07-27 15:43:22 +02001357 */
Andy Green9b8a74e2007-07-27 15:43:24 +02001358 skb_set_network_header(skb, len_rthdr);
1359 skb_set_transport_header(skb, len_rthdr);
Johannes Berge2ebc742007-07-27 15:43:22 +02001360
Andy Green9b8a74e2007-07-27 15:43:24 +02001361 /* pass the radiotap header up to the next stage intact */
1362 dev_queue_xmit(skb);
Johannes Berge2ebc742007-07-27 15:43:22 +02001363 return NETDEV_TX_OK;
Andy Green9b8a74e2007-07-27 15:43:24 +02001364
1365fail:
1366 dev_kfree_skb(skb);
1367 return NETDEV_TX_OK; /* meaning, we dealt with the skb */
Johannes Berge2ebc742007-07-27 15:43:22 +02001368}
1369
1370/**
1371 * ieee80211_subif_start_xmit - netif start_xmit function for Ethernet-type
1372 * subinterfaces (wlan#, WDS, and VLAN interfaces)
1373 * @skb: packet to be sent
1374 * @dev: incoming interface
1375 *
1376 * Returns: 0 on success (and frees skb in this case) or 1 on failure (skb will
1377 * not be freed, and caller is responsible for either retrying later or freeing
1378 * skb).
1379 *
1380 * This function takes in an Ethernet header and encapsulates it with suitable
1381 * IEEE 802.11 header based on which interface the packet is coming in. The
1382 * encapsulated packet will then be passed to master interface, wlan#.11, for
1383 * transmission (through low-level driver).
1384 */
1385int ieee80211_subif_start_xmit(struct sk_buff *skb,
1386 struct net_device *dev)
1387{
1388 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1389 struct ieee80211_tx_packet_data *pkt_data;
1390 struct ieee80211_sub_if_data *sdata;
1391 int ret = 1, head_need;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001392 u16 ethertype, hdrlen, meshhdrlen = 0, fc;
Johannes Berge2ebc742007-07-27 15:43:22 +02001393 struct ieee80211_hdr hdr;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001394 struct ieee80211s_hdr mesh_hdr;
Johannes Berge2ebc742007-07-27 15:43:22 +02001395 const u8 *encaps_data;
1396 int encaps_len, skip_header_bytes;
Jiri Slabye8bf9642007-08-28 17:01:54 -04001397 int nh_pos, h_pos;
Johannes Berge2ebc742007-07-27 15:43:22 +02001398 struct sta_info *sta;
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001399 u32 sta_flags = 0;
Johannes Berge2ebc742007-07-27 15:43:22 +02001400
1401 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1402 if (unlikely(skb->len < ETH_HLEN)) {
1403 printk(KERN_DEBUG "%s: short skb (len=%d)\n",
1404 dev->name, skb->len);
1405 ret = 0;
1406 goto fail;
1407 }
1408
1409 nh_pos = skb_network_header(skb) - skb->data;
1410 h_pos = skb_transport_header(skb) - skb->data;
1411
1412 /* convert Ethernet header to proper 802.11 header (based on
1413 * operation mode) */
1414 ethertype = (skb->data[12] << 8) | skb->data[13];
Johannes Berge2ebc742007-07-27 15:43:22 +02001415 fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA;
1416
Johannes Berg51fb61e2007-12-19 01:31:27 +01001417 switch (sdata->vif.type) {
Johannes Bergcf966832007-08-28 17:01:54 -04001418 case IEEE80211_IF_TYPE_AP:
1419 case IEEE80211_IF_TYPE_VLAN:
Johannes Berge2ebc742007-07-27 15:43:22 +02001420 fc |= IEEE80211_FCTL_FROMDS;
1421 /* DA BSSID SA */
1422 memcpy(hdr.addr1, skb->data, ETH_ALEN);
1423 memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
1424 memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
1425 hdrlen = 24;
Johannes Bergcf966832007-08-28 17:01:54 -04001426 break;
1427 case IEEE80211_IF_TYPE_WDS:
Johannes Berge2ebc742007-07-27 15:43:22 +02001428 fc |= IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS;
1429 /* RA TA DA SA */
1430 memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
1431 memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
1432 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1433 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1434 hdrlen = 30;
Johannes Bergcf966832007-08-28 17:01:54 -04001435 break;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001436#ifdef CONFIG_MAC80211_MESH
1437 case IEEE80211_IF_TYPE_MESH_POINT:
1438 fc |= IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS;
1439 /* RA TA DA SA */
1440 if (is_multicast_ether_addr(skb->data))
1441 memcpy(hdr.addr1, skb->data, ETH_ALEN);
1442 else if (mesh_nexthop_lookup(hdr.addr1, skb, dev))
1443 return 0;
1444 memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN);
1445 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1446 memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
1447 if (skb->pkt_type == PACKET_OTHERHOST) {
1448 /* Forwarded frame, keep mesh ttl and seqnum */
1449 struct ieee80211s_hdr *prev_meshhdr;
1450 prev_meshhdr = ((struct ieee80211s_hdr *)skb->cb);
1451 meshhdrlen = ieee80211_get_mesh_hdrlen(prev_meshhdr);
1452 memcpy(&mesh_hdr, prev_meshhdr, meshhdrlen);
1453 sdata->u.sta.mshstats.fwded_frames++;
1454 } else {
1455 if (!sdata->u.sta.mshcfg.dot11MeshTTL) {
1456 /* Do not send frames with mesh_ttl == 0 */
1457 sdata->u.sta.mshstats.dropped_frames_ttl++;
1458 ret = 0;
1459 goto fail;
1460 }
1461 meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr,
Johannes Berg902acc72008-02-23 15:17:19 +01001462 sdata);
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001463 }
1464 hdrlen = 30;
1465 break;
1466#endif
Johannes Bergcf966832007-08-28 17:01:54 -04001467 case IEEE80211_IF_TYPE_STA:
Johannes Berge2ebc742007-07-27 15:43:22 +02001468 fc |= IEEE80211_FCTL_TODS;
1469 /* BSSID SA DA */
1470 memcpy(hdr.addr1, sdata->u.sta.bssid, ETH_ALEN);
1471 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
1472 memcpy(hdr.addr3, skb->data, ETH_ALEN);
1473 hdrlen = 24;
Johannes Bergcf966832007-08-28 17:01:54 -04001474 break;
1475 case IEEE80211_IF_TYPE_IBSS:
Johannes Berge2ebc742007-07-27 15:43:22 +02001476 /* DA SA BSSID */
1477 memcpy(hdr.addr1, skb->data, ETH_ALEN);
1478 memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
1479 memcpy(hdr.addr3, sdata->u.sta.bssid, ETH_ALEN);
1480 hdrlen = 24;
Johannes Bergcf966832007-08-28 17:01:54 -04001481 break;
1482 default:
Johannes Berge2ebc742007-07-27 15:43:22 +02001483 ret = 0;
1484 goto fail;
1485 }
1486
Johannes Berg7d185b82008-01-28 17:11:43 +01001487 /*
1488 * There's no need to try to look up the destination
1489 * if it is a multicast address (which can only happen
1490 * in AP mode)
1491 */
1492 if (!is_multicast_ether_addr(hdr.addr1)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001493 rcu_read_lock();
Johannes Berg7d185b82008-01-28 17:11:43 +01001494 sta = sta_info_get(local, hdr.addr1);
Johannes Bergd0709a62008-02-25 16:27:46 +01001495 if (sta)
Johannes Berg7d185b82008-01-28 17:11:43 +01001496 sta_flags = sta->flags;
Johannes Bergd0709a62008-02-25 16:27:46 +01001497 rcu_read_unlock();
Johannes Berge2ebc742007-07-27 15:43:22 +02001498 }
1499
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001500 /* receiver is QoS enabled, use a QoS type frame */
1501 if (sta_flags & WLAN_STA_WME) {
1502 fc |= IEEE80211_STYPE_QOS_DATA;
1503 hdrlen += 2;
1504 }
1505
1506 /*
Johannes Berg238814f2008-01-28 17:19:37 +01001507 * Drop unicast frames to unauthorised stations unless they are
1508 * EAPOL frames from the local station.
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001509 */
Johannes Berg238814f2008-01-28 17:19:37 +01001510 if (unlikely(!is_multicast_ether_addr(hdr.addr1) &&
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001511 !(sta_flags & WLAN_STA_AUTHORIZED) &&
1512 !(ethertype == ETH_P_PAE &&
Johannes Bergce3edf6d02007-12-19 01:31:22 +01001513 compare_ether_addr(dev->dev_addr,
1514 skb->data + ETH_ALEN) == 0))) {
1515#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1516 DECLARE_MAC_BUF(mac);
1517
1518 if (net_ratelimit())
1519 printk(KERN_DEBUG "%s: dropped frame to %s"
1520 " (unauthorized port)\n", dev->name,
1521 print_mac(mac, hdr.addr1));
1522#endif
1523
1524 I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
1525
1526 ret = 0;
1527 goto fail;
1528 }
1529
Johannes Berge2ebc742007-07-27 15:43:22 +02001530 hdr.frame_control = cpu_to_le16(fc);
1531 hdr.duration_id = 0;
1532 hdr.seq_ctrl = 0;
1533
1534 skip_header_bytes = ETH_HLEN;
1535 if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
1536 encaps_data = bridge_tunnel_header;
1537 encaps_len = sizeof(bridge_tunnel_header);
1538 skip_header_bytes -= 2;
1539 } else if (ethertype >= 0x600) {
1540 encaps_data = rfc1042_header;
1541 encaps_len = sizeof(rfc1042_header);
1542 skip_header_bytes -= 2;
1543 } else {
1544 encaps_data = NULL;
1545 encaps_len = 0;
1546 }
1547
1548 skb_pull(skb, skip_header_bytes);
1549 nh_pos -= skip_header_bytes;
1550 h_pos -= skip_header_bytes;
1551
1552 /* TODO: implement support for fragments so that there is no need to
1553 * reallocate and copy payload; it might be enough to support one
1554 * extra fragment that would be copied in the beginning of the frame
1555 * data.. anyway, it would be nice to include this into skb structure
1556 * somehow
1557 *
1558 * There are few options for this:
1559 * use skb->cb as an extra space for 802.11 header
1560 * allocate new buffer if not enough headroom
1561 * make sure that there is enough headroom in every skb by increasing
1562 * build in headroom in __dev_alloc_skb() (linux/skbuff.h) and
1563 * alloc_skb() (net/core/skbuff.c)
1564 */
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001565 head_need = hdrlen + encaps_len + meshhdrlen + local->tx_headroom;
Johannes Berge2ebc742007-07-27 15:43:22 +02001566 head_need -= skb_headroom(skb);
1567
1568 /* We are going to modify skb data, so make a copy of it if happens to
1569 * be cloned. This could happen, e.g., with Linux bridge code passing
1570 * us broadcast frames. */
1571
David S. Miller3a5be7d2008-06-18 01:19:51 -07001572 if (head_need > 0 || skb_cloned(skb)) {
Johannes Berge2ebc742007-07-27 15:43:22 +02001573#if 0
1574 printk(KERN_DEBUG "%s: need to reallocate buffer for %d bytes "
1575 "of headroom\n", dev->name, head_need);
1576#endif
1577
David S. Miller3a5be7d2008-06-18 01:19:51 -07001578 if (skb_cloned(skb))
Johannes Berge2ebc742007-07-27 15:43:22 +02001579 I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
1580 else
1581 I802_DEBUG_INC(local->tx_expand_skb_head);
1582 /* Since we have to reallocate the buffer, make sure that there
1583 * is enough room for possible WEP IV/ICV and TKIP (8 bytes
1584 * before payload and 12 after). */
1585 if (pskb_expand_head(skb, (head_need > 0 ? head_need + 8 : 8),
1586 12, GFP_ATOMIC)) {
1587 printk(KERN_DEBUG "%s: failed to reallocate TX buffer"
1588 "\n", dev->name);
1589 goto fail;
1590 }
1591 }
1592
1593 if (encaps_data) {
1594 memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
1595 nh_pos += encaps_len;
1596 h_pos += encaps_len;
1597 }
Johannes Bergc29b9b92007-09-14 11:10:24 -04001598
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001599 if (meshhdrlen > 0) {
1600 memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
1601 nh_pos += meshhdrlen;
1602 h_pos += meshhdrlen;
1603 }
1604
Johannes Bergc29b9b92007-09-14 11:10:24 -04001605 if (fc & IEEE80211_STYPE_QOS_DATA) {
1606 __le16 *qos_control;
1607
1608 qos_control = (__le16*) skb_push(skb, 2);
1609 memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
1610 /*
1611 * Maybe we could actually set some fields here, for now just
1612 * initialise to zero to indicate no special operation.
1613 */
1614 *qos_control = 0;
1615 } else
1616 memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
1617
Johannes Berge2ebc742007-07-27 15:43:22 +02001618 nh_pos += hdrlen;
1619 h_pos += hdrlen;
1620
1621 pkt_data = (struct ieee80211_tx_packet_data *)skb->cb;
1622 memset(pkt_data, 0, sizeof(struct ieee80211_tx_packet_data));
1623 pkt_data->ifindex = dev->ifindex;
Johannes Berg678f5f712007-12-19 01:31:23 +01001624 if (ethertype == ETH_P_PAE)
1625 pkt_data->flags |= IEEE80211_TXPD_EAPOL_FRAME;
Johannes Berge2ebc742007-07-27 15:43:22 +02001626
1627 skb->dev = local->mdev;
Stephen Hemminger68aae112007-08-24 11:29:34 -07001628 dev->stats.tx_packets++;
1629 dev->stats.tx_bytes += skb->len;
Johannes Berge2ebc742007-07-27 15:43:22 +02001630
1631 /* Update skb pointers to various headers since this modified frame
1632 * is going to go through Linux networking code that may potentially
1633 * need things like pointer to IP header. */
1634 skb_set_mac_header(skb, 0);
1635 skb_set_network_header(skb, nh_pos);
1636 skb_set_transport_header(skb, h_pos);
1637
1638 dev->trans_start = jiffies;
1639 dev_queue_xmit(skb);
1640
1641 return 0;
1642
1643 fail:
1644 if (!ret)
1645 dev_kfree_skb(skb);
1646
1647 return ret;
1648}
1649
Johannes Berge2ebc742007-07-27 15:43:22 +02001650/* helper functions for pending packets for when queues are stopped */
1651
1652void ieee80211_clear_tx_pending(struct ieee80211_local *local)
1653{
1654 int i, j;
1655 struct ieee80211_tx_stored_packet *store;
1656
1657 for (i = 0; i < local->hw.queues; i++) {
1658 if (!__ieee80211_queue_pending(local, i))
1659 continue;
1660 store = &local->pending_packet[i];
1661 kfree_skb(store->skb);
1662 for (j = 0; j < store->num_extra_frag; j++)
1663 kfree_skb(store->extra_frag[j]);
1664 kfree(store->extra_frag);
1665 clear_bit(IEEE80211_LINK_STATE_PENDING, &local->state[i]);
1666 }
1667}
1668
1669void ieee80211_tx_pending(unsigned long data)
1670{
1671 struct ieee80211_local *local = (struct ieee80211_local *)data;
1672 struct net_device *dev = local->mdev;
1673 struct ieee80211_tx_stored_packet *store;
Johannes Berg5cf121c2008-02-25 16:27:43 +01001674 struct ieee80211_tx_data tx;
Johannes Berge2ebc742007-07-27 15:43:22 +02001675 int i, ret, reschedule = 0;
1676
1677 netif_tx_lock_bh(dev);
1678 for (i = 0; i < local->hw.queues; i++) {
1679 if (__ieee80211_queue_stopped(local, i))
1680 continue;
1681 if (!__ieee80211_queue_pending(local, i)) {
1682 reschedule = 1;
1683 continue;
1684 }
1685 store = &local->pending_packet[i];
Johannes Berg5cf121c2008-02-25 16:27:43 +01001686 tx.control = &store->control;
1687 tx.extra_frag = store->extra_frag;
1688 tx.num_extra_frag = store->num_extra_frag;
1689 tx.last_frag_rate = store->last_frag_rate;
Jiri Slabybadffb72007-08-28 17:01:54 -04001690 tx.flags = 0;
1691 if (store->last_frag_rate_ctrl_probe)
Johannes Berg5cf121c2008-02-25 16:27:43 +01001692 tx.flags |= IEEE80211_TX_PROBE_LAST_FRAG;
Johannes Berge2ebc742007-07-27 15:43:22 +02001693 ret = __ieee80211_tx(local, store->skb, &tx);
1694 if (ret) {
1695 if (ret == IEEE80211_TX_FRAG_AGAIN)
1696 store->skb = NULL;
1697 } else {
1698 clear_bit(IEEE80211_LINK_STATE_PENDING,
1699 &local->state[i]);
1700 reschedule = 1;
1701 }
1702 }
1703 netif_tx_unlock_bh(dev);
1704 if (reschedule) {
1705 if (!ieee80211_qdisc_installed(dev)) {
1706 if (!__ieee80211_queue_stopped(local, 0))
1707 netif_wake_queue(dev);
1708 } else
1709 netif_schedule(dev);
1710 }
1711}
1712
1713/* functions for drivers to get certain frames */
1714
1715static void ieee80211_beacon_add_tim(struct ieee80211_local *local,
1716 struct ieee80211_if_ap *bss,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001717 struct sk_buff *skb,
1718 struct beacon_data *beacon)
Johannes Berge2ebc742007-07-27 15:43:22 +02001719{
1720 u8 *pos, *tim;
1721 int aid0 = 0;
1722 int i, have_bits = 0, n1, n2;
1723
1724 /* Generate bitmap for TIM only if there are any STAs in power save
1725 * mode. */
Johannes Berge2ebc742007-07-27 15:43:22 +02001726 if (atomic_read(&bss->num_sta_ps) > 0)
1727 /* in the hope that this is faster than
1728 * checking byte-for-byte */
1729 have_bits = !bitmap_empty((unsigned long*)bss->tim,
1730 IEEE80211_MAX_AID+1);
1731
1732 if (bss->dtim_count == 0)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001733 bss->dtim_count = beacon->dtim_period - 1;
Johannes Berge2ebc742007-07-27 15:43:22 +02001734 else
1735 bss->dtim_count--;
1736
1737 tim = pos = (u8 *) skb_put(skb, 6);
1738 *pos++ = WLAN_EID_TIM;
1739 *pos++ = 4;
1740 *pos++ = bss->dtim_count;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001741 *pos++ = beacon->dtim_period;
Johannes Berge2ebc742007-07-27 15:43:22 +02001742
1743 if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf))
1744 aid0 = 1;
1745
1746 if (have_bits) {
1747 /* Find largest even number N1 so that bits numbered 1 through
1748 * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
1749 * (N2 + 1) x 8 through 2007 are 0. */
1750 n1 = 0;
1751 for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
1752 if (bss->tim[i]) {
1753 n1 = i & 0xfe;
1754 break;
1755 }
1756 }
1757 n2 = n1;
1758 for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
1759 if (bss->tim[i]) {
1760 n2 = i;
1761 break;
1762 }
1763 }
1764
1765 /* Bitmap control */
1766 *pos++ = n1 | aid0;
1767 /* Part Virt Bitmap */
1768 memcpy(pos, bss->tim + n1, n2 - n1 + 1);
1769
1770 tim[1] = n2 - n1 + 4;
1771 skb_put(skb, n2 - n1);
1772 } else {
1773 *pos++ = aid0; /* Bitmap control */
1774 *pos++ = 0; /* Part Virt Bitmap */
1775 }
Johannes Berge2ebc742007-07-27 15:43:22 +02001776}
1777
Johannes Berg32bfd352007-12-19 01:31:26 +01001778struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw,
1779 struct ieee80211_vif *vif,
Johannes Berge2ebc742007-07-27 15:43:22 +02001780 struct ieee80211_tx_control *control)
1781{
1782 struct ieee80211_local *local = hw_to_local(hw);
1783 struct sk_buff *skb;
1784 struct net_device *bdev;
1785 struct ieee80211_sub_if_data *sdata = NULL;
1786 struct ieee80211_if_ap *ap = NULL;
Mattias Nissler1abbe492007-12-20 13:50:07 +01001787 struct rate_selection rsel;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001788 struct beacon_data *beacon;
Johannes Berg8318d782008-01-24 19:38:38 +01001789 struct ieee80211_supported_band *sband;
Johannes Berg902acc72008-02-23 15:17:19 +01001790 struct ieee80211_mgmt *mgmt;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001791 int *num_beacons;
Johannes Berg902acc72008-02-23 15:17:19 +01001792 bool err = true;
1793 u8 *pos;
Johannes Berg8318d782008-01-24 19:38:38 +01001794
1795 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001796
1797 rcu_read_lock();
Johannes Berge2ebc742007-07-27 15:43:22 +02001798
Johannes Berg32bfd352007-12-19 01:31:26 +01001799 sdata = vif_to_sdata(vif);
1800 bdev = sdata->dev;
Johannes Berge2ebc742007-07-27 15:43:22 +02001801
Johannes Berg902acc72008-02-23 15:17:19 +01001802 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001803 ap = &sdata->u.ap;
1804 beacon = rcu_dereference(ap->beacon);
Johannes Berg902acc72008-02-23 15:17:19 +01001805 if (ap && beacon) {
1806 /*
1807 * headroom, head length,
1808 * tail length and maximum TIM length
1809 */
1810 skb = dev_alloc_skb(local->tx_headroom +
1811 beacon->head_len +
1812 beacon->tail_len + 256);
1813 if (!skb)
1814 goto out;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001815
Johannes Berg902acc72008-02-23 15:17:19 +01001816 skb_reserve(skb, local->tx_headroom);
1817 memcpy(skb_put(skb, beacon->head_len), beacon->head,
1818 beacon->head_len);
1819
1820 ieee80211_include_sequence(sdata,
1821 (struct ieee80211_hdr *)skb->data);
1822
Johannes Bergd0709a62008-02-25 16:27:46 +01001823 /*
1824 * Not very nice, but we want to allow the driver to call
1825 * ieee80211_beacon_get() as a response to the set_tim()
1826 * callback. That, however, is already invoked under the
1827 * sta_lock to guarantee consistent and race-free update
1828 * of the tim bitmap in mac80211 and the driver.
1829 */
1830 if (local->tim_in_locked_section) {
1831 ieee80211_beacon_add_tim(local, ap, skb, beacon);
1832 } else {
1833 unsigned long flags;
1834
1835 spin_lock_irqsave(&local->sta_lock, flags);
1836 ieee80211_beacon_add_tim(local, ap, skb, beacon);
1837 spin_unlock_irqrestore(&local->sta_lock, flags);
1838 }
Johannes Berg902acc72008-02-23 15:17:19 +01001839
1840 if (beacon->tail)
1841 memcpy(skb_put(skb, beacon->tail_len),
1842 beacon->tail, beacon->tail_len);
1843
1844 num_beacons = &ap->num_beacons;
1845
1846 err = false;
1847 }
1848 } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001849 /* headroom, head length, tail length and maximum TIM length */
Johannes Berg902acc72008-02-23 15:17:19 +01001850 skb = dev_alloc_skb(local->tx_headroom + 400);
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001851 if (!skb)
1852 goto out;
1853
Johannes Berg902acc72008-02-23 15:17:19 +01001854 skb_reserve(skb, local->hw.extra_tx_headroom);
1855 mgmt = (struct ieee80211_mgmt *)
1856 skb_put(skb, 24 + sizeof(mgmt->u.beacon));
1857 memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon));
1858 mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT,
1859 IEEE80211_STYPE_BEACON);
1860 memset(mgmt->da, 0xff, ETH_ALEN);
1861 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
1862 /* BSSID is left zeroed, wildcard value */
1863 mgmt->u.beacon.beacon_int =
1864 cpu_to_le16(local->hw.conf.beacon_int);
1865 mgmt->u.beacon.capab_info = 0x0; /* 0x0 for MPs */
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001866
Johannes Berg902acc72008-02-23 15:17:19 +01001867 pos = skb_put(skb, 2);
1868 *pos++ = WLAN_EID_SSID;
1869 *pos++ = 0x0;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001870
Johannes Berg902acc72008-02-23 15:17:19 +01001871 mesh_mgmt_ies_add(skb, sdata->dev);
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001872
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001873 num_beacons = &sdata->u.sta.num_beacons;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001874
Johannes Berg902acc72008-02-23 15:17:19 +01001875 err = false;
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001876 }
1877
1878 if (err) {
Johannes Berge2ebc742007-07-27 15:43:22 +02001879#ifdef CONFIG_MAC80211_VERBOSE_DEBUG
1880 if (net_ratelimit())
Johannes Berg32bfd352007-12-19 01:31:26 +01001881 printk(KERN_DEBUG "no beacon data avail for %s\n",
1882 bdev->name);
Johannes Berge2ebc742007-07-27 15:43:22 +02001883#endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001884 skb = NULL;
1885 goto out;
Johannes Berge2ebc742007-07-27 15:43:22 +02001886 }
1887
Johannes Berge2ebc742007-07-27 15:43:22 +02001888 if (control) {
Johannes Berg8318d782008-01-24 19:38:38 +01001889 rate_control_get_rate(local->mdev, sband, skb, &rsel);
Mattias Nissler1abbe492007-12-20 13:50:07 +01001890 if (!rsel.rate) {
Johannes Berge2ebc742007-07-27 15:43:22 +02001891 if (net_ratelimit()) {
Mattias Nissler1abbe492007-12-20 13:50:07 +01001892 printk(KERN_DEBUG "%s: ieee80211_beacon_get: "
1893 "no rate found\n",
1894 wiphy_name(local->hw.wiphy));
Johannes Berge2ebc742007-07-27 15:43:22 +02001895 }
1896 dev_kfree_skb(skb);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001897 skb = NULL;
1898 goto out;
Johannes Berge2ebc742007-07-27 15:43:22 +02001899 }
1900
Ivo van Doorn0f7054e2008-01-13 14:16:47 +01001901 control->vif = vif;
Johannes Berg8318d782008-01-24 19:38:38 +01001902 control->tx_rate = rsel.rate;
1903 if (sdata->bss_conf.use_short_preamble &&
1904 rsel.rate->flags & IEEE80211_RATE_SHORT_PREAMBLE)
1905 control->flags |= IEEE80211_TXCTL_SHORT_PREAMBLE;
Johannes Berge2ebc742007-07-27 15:43:22 +02001906 control->antenna_sel_tx = local->hw.conf.antenna_sel_tx;
Johannes Berge2ebc742007-07-27 15:43:22 +02001907 control->flags |= IEEE80211_TXCTL_NO_ACK;
Ivo van Doorndf442052008-05-05 20:40:35 +02001908 control->flags |= IEEE80211_TXCTL_DO_NOT_ENCRYPT;
Johannes Berge2ebc742007-07-27 15:43:22 +02001909 control->retry_limit = 1;
Johannes Bergd46e1442008-02-20 23:59:33 +01001910 control->flags |= IEEE80211_TXCTL_CLEAR_PS_FILT;
Johannes Berge2ebc742007-07-27 15:43:22 +02001911 }
Luis Carlos Cobo33b64eb2008-02-23 15:17:10 +01001912 (*num_beacons)++;
1913out:
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001914 rcu_read_unlock();
Johannes Berge2ebc742007-07-27 15:43:22 +02001915 return skb;
1916}
1917EXPORT_SYMBOL(ieee80211_beacon_get);
1918
Johannes Berg32bfd352007-12-19 01:31:26 +01001919void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Johannes Berge2ebc742007-07-27 15:43:22 +02001920 const void *frame, size_t frame_len,
1921 const struct ieee80211_tx_control *frame_txctl,
1922 struct ieee80211_rts *rts)
1923{
1924 const struct ieee80211_hdr *hdr = frame;
1925 u16 fctl;
1926
1927 fctl = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS;
1928 rts->frame_control = cpu_to_le16(fctl);
Johannes Berg32bfd352007-12-19 01:31:26 +01001929 rts->duration = ieee80211_rts_duration(hw, vif, frame_len,
1930 frame_txctl);
Johannes Berge2ebc742007-07-27 15:43:22 +02001931 memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
1932 memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
1933}
1934EXPORT_SYMBOL(ieee80211_rts_get);
1935
Johannes Berg32bfd352007-12-19 01:31:26 +01001936void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
Johannes Berge2ebc742007-07-27 15:43:22 +02001937 const void *frame, size_t frame_len,
1938 const struct ieee80211_tx_control *frame_txctl,
1939 struct ieee80211_cts *cts)
1940{
1941 const struct ieee80211_hdr *hdr = frame;
1942 u16 fctl;
1943
1944 fctl = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS;
1945 cts->frame_control = cpu_to_le16(fctl);
Johannes Berg32bfd352007-12-19 01:31:26 +01001946 cts->duration = ieee80211_ctstoself_duration(hw, vif,
1947 frame_len, frame_txctl);
Johannes Berge2ebc742007-07-27 15:43:22 +02001948 memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
1949}
1950EXPORT_SYMBOL(ieee80211_ctstoself_get);
1951
1952struct sk_buff *
Johannes Berg32bfd352007-12-19 01:31:26 +01001953ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
1954 struct ieee80211_vif *vif,
Johannes Berge2ebc742007-07-27 15:43:22 +02001955 struct ieee80211_tx_control *control)
1956{
1957 struct ieee80211_local *local = hw_to_local(hw);
1958 struct sk_buff *skb;
1959 struct sta_info *sta;
1960 ieee80211_tx_handler *handler;
Johannes Berg5cf121c2008-02-25 16:27:43 +01001961 struct ieee80211_tx_data tx;
Johannes Berg9ae54c82008-01-31 19:48:20 +01001962 ieee80211_tx_result res = TX_DROP;
Johannes Berge2ebc742007-07-27 15:43:22 +02001963 struct net_device *bdev;
1964 struct ieee80211_sub_if_data *sdata;
1965 struct ieee80211_if_ap *bss = NULL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001966 struct beacon_data *beacon;
Johannes Berge2ebc742007-07-27 15:43:22 +02001967
Johannes Berg32bfd352007-12-19 01:31:26 +01001968 sdata = vif_to_sdata(vif);
1969 bdev = sdata->dev;
1970
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001971
1972 if (!bss)
Johannes Berge2ebc742007-07-27 15:43:22 +02001973 return NULL;
1974
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001975 rcu_read_lock();
1976 beacon = rcu_dereference(bss->beacon);
1977
1978 if (sdata->vif.type != IEEE80211_IF_TYPE_AP || !beacon ||
1979 !beacon->head) {
1980 rcu_read_unlock();
1981 return NULL;
1982 }
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001983
Johannes Berge2ebc742007-07-27 15:43:22 +02001984 if (bss->dtim_count != 0)
1985 return NULL; /* send buffered bc/mc only after DTIM beacon */
1986 memset(control, 0, sizeof(*control));
1987 while (1) {
1988 skb = skb_dequeue(&bss->ps_bc_buf);
1989 if (!skb)
1990 return NULL;
1991 local->total_ps_buffered--;
1992
1993 if (!skb_queue_empty(&bss->ps_bc_buf) && skb->len >= 2) {
1994 struct ieee80211_hdr *hdr =
1995 (struct ieee80211_hdr *) skb->data;
1996 /* more buffered multicast/broadcast frames ==> set
1997 * MoreData flag in IEEE 802.11 header to inform PS
1998 * STAs */
1999 hdr->frame_control |=
2000 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
2001 }
2002
Johannes Berg58d41852007-09-26 17:53:18 +02002003 if (!ieee80211_tx_prepare(&tx, skb, local->mdev, control))
Johannes Berge2ebc742007-07-27 15:43:22 +02002004 break;
2005 dev_kfree_skb_any(skb);
2006 }
2007 sta = tx.sta;
Johannes Berg5cf121c2008-02-25 16:27:43 +01002008 tx.flags |= IEEE80211_TX_PS_BUFFERED;
2009 tx.channel = local->hw.conf.channel;
Johannes Berge2ebc742007-07-27 15:43:22 +02002010
Johannes Berg58905292008-01-31 19:48:25 +01002011 for (handler = ieee80211_tx_handlers; *handler != NULL; handler++) {
Johannes Berge2ebc742007-07-27 15:43:22 +02002012 res = (*handler)(&tx);
Johannes Berg9ae54c82008-01-31 19:48:20 +01002013 if (res == TX_DROP || res == TX_QUEUED)
Johannes Berge2ebc742007-07-27 15:43:22 +02002014 break;
2015 }
Johannes Berge2ebc742007-07-27 15:43:22 +02002016 skb = tx.skb; /* handlers are allowed to change skb */
2017
Johannes Berg9ae54c82008-01-31 19:48:20 +01002018 if (res == TX_DROP) {
Johannes Berge2ebc742007-07-27 15:43:22 +02002019 I802_DEBUG_INC(local->tx_handlers_drop);
2020 dev_kfree_skb(skb);
2021 skb = NULL;
Johannes Berg9ae54c82008-01-31 19:48:20 +01002022 } else if (res == TX_QUEUED) {
Johannes Berge2ebc742007-07-27 15:43:22 +02002023 I802_DEBUG_INC(local->tx_handlers_queued);
2024 skb = NULL;
2025 }
2026
Johannes Bergd0709a62008-02-25 16:27:46 +01002027 rcu_read_unlock();
Johannes Berge2ebc742007-07-27 15:43:22 +02002028
2029 return skb;
2030}
2031EXPORT_SYMBOL(ieee80211_get_buffered_bc);