Commit | Line | Data |
---|---|---|
e2ebc74d JB |
1 | /* |
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> | |
d4e46a3d | 20 | #include <linux/rcupdate.h> |
881d966b | 21 | #include <net/net_namespace.h> |
e2ebc74d JB |
22 | #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" | |
2c8dccc7 | 28 | #include "led.h" |
33b64eb2 | 29 | #include "mesh.h" |
e2ebc74d JB |
30 | #include "wep.h" |
31 | #include "wpa.h" | |
32 | #include "wme.h" | |
2c8dccc7 | 33 | #include "rate.h" |
e2ebc74d JB |
34 | |
35 | #define IEEE80211_TX_OK 0 | |
36 | #define IEEE80211_TX_AGAIN 1 | |
37 | #define IEEE80211_TX_FRAG_AGAIN 2 | |
38 | ||
39 | /* misc utils */ | |
40 | ||
41 | static 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 | |
52 | static 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; | |
0795af57 | 58 | DECLARE_MAC_BUF(mac); |
e2ebc74d JB |
59 | |
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) | |
0795af57 | 74 | printk(" A1=%s", print_mac(mac, hdr->addr1)); |
e2ebc74d | 75 | if (hdrlen >= 16) |
0795af57 | 76 | printk(" A2=%s", print_mac(mac, hdr->addr2)); |
e2ebc74d | 77 | if (hdrlen >= 24) |
0795af57 | 78 | printk(" A3=%s", print_mac(mac, hdr->addr3)); |
e2ebc74d | 79 | if (hdrlen >= 30) |
0795af57 | 80 | printk(" A4=%s", print_mac(mac, hdr->addr4)); |
e2ebc74d JB |
81 | printk("\n"); |
82 | } | |
83 | #else /* CONFIG_MAC80211_LOWTX_FRAME_DUMP */ | |
84 | static 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 | ||
5cf121c3 | 90 | static u16 ieee80211_duration(struct ieee80211_tx_data *tx, int group_addr, |
e2ebc74d JB |
91 | int next_frag_len) |
92 | { | |
93 | int rate, mrate, erp, dur, i; | |
2e92e6f2 | 94 | struct ieee80211_rate *txrate; |
e2ebc74d | 95 | struct ieee80211_local *local = tx->local; |
8318d78a | 96 | struct ieee80211_supported_band *sband; |
e2ebc74d | 97 | |
2e92e6f2 JB |
98 | sband = local->hw.wiphy->bands[tx->channel->band]; |
99 | txrate = &sband->bitrates[tx->rate_idx]; | |
8318d78a JB |
100 | |
101 | erp = 0; | |
102 | if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) | |
103 | erp = txrate->flags & IEEE80211_RATE_ERP_G; | |
e2ebc74d JB |
104 | |
105 | /* | |
106 | * data and mgmt (except PS Poll): | |
107 | * - during CFP: 32768 | |
108 | * - during contention period: | |
109 | * if addr1 is group address: 0 | |
110 | * if more fragments = 0 and addr1 is individual address: time to | |
111 | * transmit one ACK plus SIFS | |
112 | * if more fragments = 1 and addr1 is individual address: time to | |
113 | * transmit next fragment plus 2 x ACK plus 3 x SIFS | |
114 | * | |
115 | * IEEE 802.11, 9.6: | |
116 | * - control response frame (CTS or ACK) shall be transmitted using the | |
117 | * same rate as the immediately previous frame in the frame exchange | |
118 | * sequence, if this rate belongs to the PHY mandatory rates, or else | |
119 | * at the highest possible rate belonging to the PHY rates in the | |
120 | * BSSBasicRateSet | |
121 | */ | |
122 | ||
123 | if ((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_CTL) { | |
124 | /* TODO: These control frames are not currently sent by | |
125 | * 80211.o, but should they be implemented, this function | |
126 | * needs to be updated to support duration field calculation. | |
127 | * | |
128 | * RTS: time needed to transmit pending data/mgmt frame plus | |
129 | * one CTS frame plus one ACK frame plus 3 x SIFS | |
130 | * CTS: duration of immediately previous RTS minus time | |
131 | * required to transmit CTS and its SIFS | |
132 | * ACK: 0 if immediately previous directed data/mgmt had | |
133 | * more=0, with more=1 duration in ACK frame is duration | |
134 | * from previous frame minus time needed to transmit ACK | |
135 | * and its SIFS | |
136 | * PS Poll: BIT(15) | BIT(14) | aid | |
137 | */ | |
138 | return 0; | |
139 | } | |
140 | ||
141 | /* data/mgmt */ | |
142 | if (0 /* FIX: data/mgmt during CFP */) | |
143 | return 32768; | |
144 | ||
145 | if (group_addr) /* Group address as the destination - no ACK */ | |
146 | return 0; | |
147 | ||
148 | /* Individual destination address: | |
149 | * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes) | |
150 | * CTS and ACK frames shall be transmitted using the highest rate in | |
151 | * basic rate set that is less than or equal to the rate of the | |
152 | * immediately previous frame and that is using the same modulation | |
153 | * (CCK or OFDM). If no basic rate set matches with these requirements, | |
154 | * the highest mandatory rate of the PHY that is less than or equal to | |
155 | * the rate of the previous frame is used. | |
156 | * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps | |
157 | */ | |
158 | rate = -1; | |
8318d78a JB |
159 | /* use lowest available if everything fails */ |
160 | mrate = sband->bitrates[0].bitrate; | |
161 | for (i = 0; i < sband->n_bitrates; i++) { | |
162 | struct ieee80211_rate *r = &sband->bitrates[i]; | |
e2ebc74d | 163 | |
8318d78a JB |
164 | if (r->bitrate > txrate->bitrate) |
165 | break; | |
e2ebc74d | 166 | |
8318d78a JB |
167 | if (tx->sdata->basic_rates & BIT(i)) |
168 | rate = r->bitrate; | |
169 | ||
170 | switch (sband->band) { | |
171 | case IEEE80211_BAND_2GHZ: { | |
172 | u32 flag; | |
173 | if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) | |
174 | flag = IEEE80211_RATE_MANDATORY_G; | |
175 | else | |
176 | flag = IEEE80211_RATE_MANDATORY_B; | |
177 | if (r->flags & flag) | |
178 | mrate = r->bitrate; | |
179 | break; | |
180 | } | |
181 | case IEEE80211_BAND_5GHZ: | |
182 | if (r->flags & IEEE80211_RATE_MANDATORY_A) | |
183 | mrate = r->bitrate; | |
184 | break; | |
185 | case IEEE80211_NUM_BANDS: | |
186 | WARN_ON(1); | |
187 | break; | |
188 | } | |
e2ebc74d JB |
189 | } |
190 | if (rate == -1) { | |
191 | /* No matching basic rate found; use highest suitable mandatory | |
192 | * PHY rate */ | |
193 | rate = mrate; | |
194 | } | |
195 | ||
196 | /* Time needed to transmit ACK | |
197 | * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up | |
198 | * to closest integer */ | |
199 | ||
200 | dur = ieee80211_frame_duration(local, 10, rate, erp, | |
471b3efd | 201 | tx->sdata->bss_conf.use_short_preamble); |
e2ebc74d JB |
202 | |
203 | if (next_frag_len) { | |
204 | /* Frame is fragmented: duration increases with time needed to | |
205 | * transmit next fragment plus ACK and 2 x SIFS. */ | |
206 | dur *= 2; /* ACK + SIFS */ | |
207 | /* next fragment */ | |
208 | dur += ieee80211_frame_duration(local, next_frag_len, | |
8318d78a | 209 | txrate->bitrate, erp, |
471b3efd | 210 | tx->sdata->bss_conf.use_short_preamble); |
e2ebc74d JB |
211 | } |
212 | ||
213 | return dur; | |
214 | } | |
215 | ||
e2ebc74d JB |
216 | static int inline is_ieee80211_device(struct net_device *dev, |
217 | struct net_device *master) | |
218 | { | |
219 | return (wdev_priv(dev->ieee80211_ptr) == | |
220 | wdev_priv(master->ieee80211_ptr)); | |
221 | } | |
222 | ||
223 | /* tx handlers */ | |
224 | ||
9ae54c84 | 225 | static ieee80211_tx_result |
5cf121c3 | 226 | ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx) |
e2ebc74d JB |
227 | { |
228 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | |
e039fa4a | 229 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; |
e2ebc74d | 230 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
e039fa4a | 231 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
e2ebc74d JB |
232 | u32 sta_flags; |
233 | ||
e039fa4a | 234 | if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) |
9ae54c84 | 235 | return TX_CONTINUE; |
58d4185e | 236 | |
ece8eddd | 237 | if (unlikely(tx->local->sta_sw_scanning) && |
e2ebc74d JB |
238 | ((tx->fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_MGMT || |
239 | (tx->fc & IEEE80211_FCTL_STYPE) != IEEE80211_STYPE_PROBE_REQ)) | |
9ae54c84 | 240 | return TX_DROP; |
e2ebc74d | 241 | |
33b64eb2 LCC |
242 | if (tx->sdata->vif.type == IEEE80211_IF_TYPE_MESH_POINT) |
243 | return TX_CONTINUE; | |
244 | ||
5cf121c3 | 245 | if (tx->flags & IEEE80211_TX_PS_BUFFERED) |
9ae54c84 | 246 | return TX_CONTINUE; |
e2ebc74d | 247 | |
07346f81 | 248 | sta_flags = tx->sta ? get_sta_flags(tx->sta) : 0; |
e2ebc74d | 249 | |
5cf121c3 | 250 | if (likely(tx->flags & IEEE80211_TX_UNICAST)) { |
e2ebc74d | 251 | if (unlikely(!(sta_flags & WLAN_STA_ASSOC) && |
51fb61e7 | 252 | tx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS && |
e2ebc74d JB |
253 | (tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA)) { |
254 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | |
0795af57 | 255 | DECLARE_MAC_BUF(mac); |
e2ebc74d | 256 | printk(KERN_DEBUG "%s: dropped data frame to not " |
0795af57 JP |
257 | "associated station %s\n", |
258 | tx->dev->name, print_mac(mac, hdr->addr1)); | |
e2ebc74d JB |
259 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
260 | I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc); | |
9ae54c84 | 261 | return TX_DROP; |
e2ebc74d JB |
262 | } |
263 | } else { | |
264 | if (unlikely((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA && | |
265 | tx->local->num_sta == 0 && | |
51fb61e7 | 266 | tx->sdata->vif.type != IEEE80211_IF_TYPE_IBSS)) { |
e2ebc74d JB |
267 | /* |
268 | * No associated STAs - no need to send multicast | |
269 | * frames. | |
270 | */ | |
9ae54c84 | 271 | return TX_DROP; |
e2ebc74d | 272 | } |
9ae54c84 | 273 | return TX_CONTINUE; |
e2ebc74d JB |
274 | } |
275 | ||
9ae54c84 | 276 | return TX_CONTINUE; |
e2ebc74d JB |
277 | } |
278 | ||
9ae54c84 | 279 | static ieee80211_tx_result |
5cf121c3 | 280 | ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx) |
e2ebc74d JB |
281 | { |
282 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; | |
283 | ||
284 | if (ieee80211_get_hdrlen(le16_to_cpu(hdr->frame_control)) >= 24) | |
285 | ieee80211_include_sequence(tx->sdata, hdr); | |
286 | ||
9ae54c84 | 287 | return TX_CONTINUE; |
e2ebc74d JB |
288 | } |
289 | ||
290 | /* This function is called whenever the AP is about to exceed the maximum limit | |
291 | * of buffered frames for power saving STAs. This situation should not really | |
292 | * happen often during normal operation, so dropping the oldest buffered packet | |
293 | * from each queue should be OK to make some room for new frames. */ | |
294 | static void purge_old_ps_buffers(struct ieee80211_local *local) | |
295 | { | |
296 | int total = 0, purged = 0; | |
297 | struct sk_buff *skb; | |
298 | struct ieee80211_sub_if_data *sdata; | |
299 | struct sta_info *sta; | |
300 | ||
79010420 JB |
301 | /* |
302 | * virtual interfaces are protected by RCU | |
303 | */ | |
304 | rcu_read_lock(); | |
305 | ||
306 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { | |
e2ebc74d JB |
307 | struct ieee80211_if_ap *ap; |
308 | if (sdata->dev == local->mdev || | |
51fb61e7 | 309 | sdata->vif.type != IEEE80211_IF_TYPE_AP) |
e2ebc74d JB |
310 | continue; |
311 | ap = &sdata->u.ap; | |
312 | skb = skb_dequeue(&ap->ps_bc_buf); | |
313 | if (skb) { | |
314 | purged++; | |
315 | dev_kfree_skb(skb); | |
316 | } | |
317 | total += skb_queue_len(&ap->ps_bc_buf); | |
318 | } | |
e2ebc74d | 319 | |
d0709a65 | 320 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
e2ebc74d JB |
321 | skb = skb_dequeue(&sta->ps_tx_buf); |
322 | if (skb) { | |
323 | purged++; | |
324 | dev_kfree_skb(skb); | |
325 | } | |
326 | total += skb_queue_len(&sta->ps_tx_buf); | |
327 | } | |
d0709a65 JB |
328 | |
329 | rcu_read_unlock(); | |
e2ebc74d JB |
330 | |
331 | local->total_ps_buffered = total; | |
332 | printk(KERN_DEBUG "%s: PS buffers full - purged %d frames\n", | |
dd1cd4c6 | 333 | wiphy_name(local->hw.wiphy), purged); |
e2ebc74d JB |
334 | } |
335 | ||
9ae54c84 | 336 | static ieee80211_tx_result |
5cf121c3 | 337 | ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx) |
e2ebc74d | 338 | { |
e039fa4a JB |
339 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
340 | ||
7d54d0dd JB |
341 | /* |
342 | * broadcast/multicast frame | |
343 | * | |
344 | * If any of the associated stations is in power save mode, | |
345 | * the frame is buffered to be sent after DTIM beacon frame. | |
346 | * This is done either by the hardware or us. | |
347 | */ | |
348 | ||
349 | /* not AP/IBSS or ordered frame */ | |
350 | if (!tx->sdata->bss || (tx->fc & IEEE80211_FCTL_ORDER)) | |
9ae54c84 | 351 | return TX_CONTINUE; |
7d54d0dd JB |
352 | |
353 | /* no stations in PS mode */ | |
354 | if (!atomic_read(&tx->sdata->bss->num_sta_ps)) | |
9ae54c84 | 355 | return TX_CONTINUE; |
7d54d0dd JB |
356 | |
357 | /* buffered in mac80211 */ | |
358 | if (tx->local->hw.flags & IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING) { | |
e2ebc74d JB |
359 | if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) |
360 | purge_old_ps_buffers(tx->local); | |
361 | if (skb_queue_len(&tx->sdata->bss->ps_bc_buf) >= | |
362 | AP_MAX_BC_BUFFER) { | |
363 | if (net_ratelimit()) { | |
364 | printk(KERN_DEBUG "%s: BC TX buffer full - " | |
365 | "dropping the oldest frame\n", | |
366 | tx->dev->name); | |
367 | } | |
368 | dev_kfree_skb(skb_dequeue(&tx->sdata->bss->ps_bc_buf)); | |
369 | } else | |
370 | tx->local->total_ps_buffered++; | |
371 | skb_queue_tail(&tx->sdata->bss->ps_bc_buf, tx->skb); | |
9ae54c84 | 372 | return TX_QUEUED; |
e2ebc74d JB |
373 | } |
374 | ||
7d54d0dd | 375 | /* buffered in hardware */ |
e039fa4a | 376 | info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM; |
7d54d0dd | 377 | |
9ae54c84 | 378 | return TX_CONTINUE; |
e2ebc74d JB |
379 | } |
380 | ||
9ae54c84 | 381 | static ieee80211_tx_result |
5cf121c3 | 382 | ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx) |
e2ebc74d JB |
383 | { |
384 | struct sta_info *sta = tx->sta; | |
e039fa4a | 385 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
07346f81 | 386 | u32 staflags; |
0795af57 | 387 | DECLARE_MAC_BUF(mac); |
e2ebc74d JB |
388 | |
389 | if (unlikely(!sta || | |
390 | ((tx->fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT && | |
391 | (tx->fc & IEEE80211_FCTL_STYPE) == IEEE80211_STYPE_PROBE_RESP))) | |
9ae54c84 | 392 | return TX_CONTINUE; |
e2ebc74d | 393 | |
07346f81 JB |
394 | staflags = get_sta_flags(sta); |
395 | ||
396 | if (unlikely((staflags & WLAN_STA_PS) && | |
397 | !(staflags & WLAN_STA_PSPOLL))) { | |
e2ebc74d | 398 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG |
0795af57 | 399 | printk(KERN_DEBUG "STA %s aid %d: PS buffer (entries " |
e2ebc74d | 400 | "before %d)\n", |
0795af57 | 401 | print_mac(mac, sta->addr), sta->aid, |
e2ebc74d JB |
402 | skb_queue_len(&sta->ps_tx_buf)); |
403 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ | |
e2ebc74d JB |
404 | if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) |
405 | purge_old_ps_buffers(tx->local); | |
406 | if (skb_queue_len(&sta->ps_tx_buf) >= STA_MAX_TX_BUFFER) { | |
407 | struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf); | |
408 | if (net_ratelimit()) { | |
0795af57 | 409 | printk(KERN_DEBUG "%s: STA %s TX " |
e2ebc74d | 410 | "buffer full - dropping oldest frame\n", |
0795af57 | 411 | tx->dev->name, print_mac(mac, sta->addr)); |
e2ebc74d JB |
412 | } |
413 | dev_kfree_skb(old); | |
414 | } else | |
415 | tx->local->total_ps_buffered++; | |
004c872e | 416 | |
e2ebc74d | 417 | /* Queue frame to be sent after STA sends an PS Poll frame */ |
004c872e JB |
418 | if (skb_queue_empty(&sta->ps_tx_buf)) |
419 | sta_info_set_tim_bit(sta); | |
420 | ||
e039fa4a | 421 | info->control.jiffies = jiffies; |
e2ebc74d | 422 | skb_queue_tail(&sta->ps_tx_buf, tx->skb); |
9ae54c84 | 423 | return TX_QUEUED; |
e2ebc74d JB |
424 | } |
425 | #ifdef CONFIG_MAC80211_VERBOSE_PS_DEBUG | |
07346f81 | 426 | else if (unlikely(test_sta_flags(sta, WLAN_STA_PS))) { |
0795af57 | 427 | printk(KERN_DEBUG "%s: STA %s in PS mode, but pspoll " |
e2ebc74d | 428 | "set -> send frame\n", tx->dev->name, |
0795af57 | 429 | print_mac(mac, sta->addr)); |
e2ebc74d JB |
430 | } |
431 | #endif /* CONFIG_MAC80211_VERBOSE_PS_DEBUG */ | |
07346f81 | 432 | clear_sta_flags(sta, WLAN_STA_PSPOLL); |
e2ebc74d | 433 | |
9ae54c84 | 434 | return TX_CONTINUE; |
e2ebc74d JB |
435 | } |
436 | ||
9ae54c84 | 437 | static ieee80211_tx_result |
5cf121c3 | 438 | ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx) |
e2ebc74d | 439 | { |
5cf121c3 | 440 | if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED)) |
9ae54c84 | 441 | return TX_CONTINUE; |
e2ebc74d | 442 | |
5cf121c3 | 443 | if (tx->flags & IEEE80211_TX_UNICAST) |
e2ebc74d JB |
444 | return ieee80211_tx_h_unicast_ps_buf(tx); |
445 | else | |
446 | return ieee80211_tx_h_multicast_ps_buf(tx); | |
447 | } | |
448 | ||
9ae54c84 | 449 | static ieee80211_tx_result |
5cf121c3 | 450 | ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) |
e2ebc74d | 451 | { |
d4e46a3d | 452 | struct ieee80211_key *key; |
e039fa4a | 453 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
176e4f84 | 454 | u16 fc = tx->fc; |
d4e46a3d | 455 | |
e039fa4a | 456 | if (unlikely(info->flags & IEEE80211_TX_CTL_DO_NOT_ENCRYPT)) |
e2ebc74d | 457 | tx->key = NULL; |
d4e46a3d JB |
458 | else if (tx->sta && (key = rcu_dereference(tx->sta->key))) |
459 | tx->key = key; | |
460 | else if ((key = rcu_dereference(tx->sdata->default_key))) | |
461 | tx->key = key; | |
e2ebc74d | 462 | else if (tx->sdata->drop_unencrypted && |
e039fa4a JB |
463 | !(info->flags & IEEE80211_TX_CTL_EAPOL_FRAME) && |
464 | !(info->flags & IEEE80211_TX_CTL_INJECTED)) { | |
e2ebc74d | 465 | I802_DEBUG_INC(tx->local->tx_handlers_drop_unencrypted); |
9ae54c84 | 466 | return TX_DROP; |
176e4f84 | 467 | } else |
e2ebc74d JB |
468 | tx->key = NULL; |
469 | ||
470 | if (tx->key) { | |
176e4f84 JB |
471 | u16 ftype, stype; |
472 | ||
e2ebc74d | 473 | tx->key->tx_rx_count++; |
011bfcc4 | 474 | /* TODO: add threshold stuff again */ |
176e4f84 JB |
475 | |
476 | switch (tx->key->conf.alg) { | |
477 | case ALG_WEP: | |
478 | ftype = fc & IEEE80211_FCTL_FTYPE; | |
479 | stype = fc & IEEE80211_FCTL_STYPE; | |
480 | ||
481 | if (ftype == IEEE80211_FTYPE_MGMT && | |
482 | stype == IEEE80211_STYPE_AUTH) | |
483 | break; | |
484 | case ALG_TKIP: | |
485 | case ALG_CCMP: | |
486 | if (!WLAN_FC_DATA_PRESENT(fc)) | |
487 | tx->key = NULL; | |
488 | break; | |
489 | } | |
e2ebc74d JB |
490 | } |
491 | ||
176e4f84 | 492 | if (!tx->key || !(tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) |
e039fa4a | 493 | info->flags |= IEEE80211_TX_CTL_DO_NOT_ENCRYPT; |
176e4f84 | 494 | |
9ae54c84 | 495 | return TX_CONTINUE; |
e2ebc74d JB |
496 | } |
497 | ||
9ae54c84 | 498 | static ieee80211_tx_result |
5cf121c3 | 499 | ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx) |
e2ebc74d | 500 | { |
1abbe498 | 501 | struct rate_selection rsel; |
8318d78a | 502 | struct ieee80211_supported_band *sband; |
e039fa4a | 503 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
8318d78a | 504 | |
2e92e6f2 | 505 | sband = tx->local->hw.wiphy->bands[tx->channel->band]; |
e2ebc74d | 506 | |
2e92e6f2 | 507 | if (likely(tx->rate_idx < 0)) { |
8318d78a | 508 | rate_control_get_rate(tx->dev, sband, tx->skb, &rsel); |
2e92e6f2 JB |
509 | tx->rate_idx = rsel.rate_idx; |
510 | if (unlikely(rsel.probe_idx >= 0)) { | |
e039fa4a | 511 | info->flags |= IEEE80211_TX_CTL_RATE_CTRL_PROBE; |
5cf121c3 | 512 | tx->flags |= IEEE80211_TX_PROBE_LAST_FRAG; |
e039fa4a | 513 | info->control.alt_retry_rate_idx = tx->rate_idx; |
2e92e6f2 | 514 | tx->rate_idx = rsel.probe_idx; |
58d4185e | 515 | } else |
e039fa4a | 516 | info->control.alt_retry_rate_idx = -1; |
58d4185e | 517 | |
2e92e6f2 | 518 | if (unlikely(tx->rate_idx < 0)) |
9ae54c84 | 519 | return TX_DROP; |
58d4185e | 520 | } else |
e039fa4a | 521 | info->control.alt_retry_rate_idx = -1; |
58d4185e | 522 | |
8318d78a | 523 | if (tx->sdata->bss_conf.use_cts_prot && |
2e92e6f2 JB |
524 | (tx->flags & IEEE80211_TX_FRAGMENTED) && (rsel.nonerp_idx >= 0)) { |
525 | tx->last_frag_rate_idx = tx->rate_idx; | |
526 | if (rsel.probe_idx >= 0) | |
5cf121c3 | 527 | tx->flags &= ~IEEE80211_TX_PROBE_LAST_FRAG; |
badffb72 | 528 | else |
5cf121c3 | 529 | tx->flags |= IEEE80211_TX_PROBE_LAST_FRAG; |
2e92e6f2 | 530 | tx->rate_idx = rsel.nonerp_idx; |
e039fa4a JB |
531 | info->tx_rate_idx = rsel.nonerp_idx; |
532 | info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE; | |
e2ebc74d | 533 | } else { |
2e92e6f2 | 534 | tx->last_frag_rate_idx = tx->rate_idx; |
e039fa4a | 535 | info->tx_rate_idx = tx->rate_idx; |
e2ebc74d | 536 | } |
e039fa4a | 537 | info->tx_rate_idx = tx->rate_idx; |
e2ebc74d | 538 | |
9ae54c84 | 539 | return TX_CONTINUE; |
e2ebc74d JB |
540 | } |
541 | ||
9ae54c84 | 542 | static ieee80211_tx_result |
5cf121c3 | 543 | ieee80211_tx_h_misc(struct ieee80211_tx_data *tx) |
e2ebc74d JB |
544 | { |
545 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data; | |
7e9ed188 | 546 | u16 fc = le16_to_cpu(hdr->frame_control); |
e2ebc74d | 547 | u16 dur; |
e039fa4a | 548 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
2e92e6f2 JB |
549 | struct ieee80211_supported_band *sband; |
550 | ||
551 | sband = tx->local->hw.wiphy->bands[tx->channel->band]; | |
e2ebc74d | 552 | |
e039fa4a JB |
553 | if (tx->sta) |
554 | info->control.aid = tx->sta->aid; | |
555 | ||
556 | if (!info->control.retry_limit) { | |
58d4185e | 557 | if (!is_multicast_ether_addr(hdr->addr1)) { |
e039fa4a JB |
558 | int len = min_t(int, tx->skb->len + FCS_LEN, |
559 | tx->local->fragmentation_threshold); | |
560 | if (len > tx->local->rts_threshold | |
58d4185e | 561 | && tx->local->rts_threshold < |
e039fa4a JB |
562 | IEEE80211_MAX_RTS_THRESHOLD) { |
563 | info->flags |= IEEE80211_TX_CTL_USE_RTS_CTS; | |
564 | info->flags |= | |
565 | IEEE80211_TX_CTL_LONG_RETRY_LIMIT; | |
566 | info->control.retry_limit = | |
58d4185e JB |
567 | tx->local->long_retry_limit; |
568 | } else { | |
e039fa4a | 569 | info->control.retry_limit = |
58d4185e JB |
570 | tx->local->short_retry_limit; |
571 | } | |
e2ebc74d | 572 | } else { |
e039fa4a | 573 | info->control.retry_limit = 1; |
e2ebc74d | 574 | } |
e2ebc74d JB |
575 | } |
576 | ||
5cf121c3 | 577 | if (tx->flags & IEEE80211_TX_FRAGMENTED) { |
e2ebc74d JB |
578 | /* Do not use multiple retry rates when sending fragmented |
579 | * frames. | |
580 | * TODO: The last fragment could still use multiple retry | |
581 | * rates. */ | |
e039fa4a | 582 | info->control.alt_retry_rate_idx = -1; |
e2ebc74d JB |
583 | } |
584 | ||
585 | /* Use CTS protection for unicast frames sent using extended rates if | |
586 | * there are associated non-ERP stations and RTS/CTS is not configured | |
587 | * for the frame. */ | |
8318d78a | 588 | if ((tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) && |
2e92e6f2 | 589 | (sband->bitrates[tx->rate_idx].flags & IEEE80211_RATE_ERP_G) && |
5cf121c3 | 590 | (tx->flags & IEEE80211_TX_UNICAST) && |
471b3efd | 591 | tx->sdata->bss_conf.use_cts_prot && |
e039fa4a JB |
592 | !(info->flags & IEEE80211_TX_CTL_USE_RTS_CTS)) |
593 | info->flags |= IEEE80211_TX_CTL_USE_CTS_PROTECT; | |
e2ebc74d | 594 | |
7e9ed188 DD |
595 | /* Transmit data frames using short preambles if the driver supports |
596 | * short preambles at the selected rate and short preambles are | |
597 | * available on the network at the current point in time. */ | |
598 | if (((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_DATA) && | |
2e92e6f2 | 599 | (sband->bitrates[tx->rate_idx].flags & IEEE80211_RATE_SHORT_PREAMBLE) && |
471b3efd | 600 | tx->sdata->bss_conf.use_short_preamble && |
07346f81 | 601 | (!tx->sta || test_sta_flags(tx->sta, WLAN_STA_SHORT_PREAMBLE))) { |
e039fa4a | 602 | info->flags |= IEEE80211_TX_CTL_SHORT_PREAMBLE; |
7e9ed188 DD |
603 | } |
604 | ||
e2ebc74d JB |
605 | /* Setup duration field for the first fragment of the frame. Duration |
606 | * for remaining fragments will be updated when they are being sent | |
607 | * to low-level driver in ieee80211_tx(). */ | |
608 | dur = ieee80211_duration(tx, is_multicast_ether_addr(hdr->addr1), | |
5cf121c3 JB |
609 | (tx->flags & IEEE80211_TX_FRAGMENTED) ? |
610 | tx->extra_frag[0]->len : 0); | |
e2ebc74d JB |
611 | hdr->duration_id = cpu_to_le16(dur); |
612 | ||
e039fa4a JB |
613 | if ((info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) || |
614 | (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT)) { | |
8318d78a | 615 | struct ieee80211_supported_band *sband; |
2e92e6f2 JB |
616 | struct ieee80211_rate *rate; |
617 | s8 baserate = -1; | |
8318d78a JB |
618 | int idx; |
619 | ||
2e92e6f2 | 620 | sband = tx->local->hw.wiphy->bands[tx->channel->band]; |
e2ebc74d JB |
621 | |
622 | /* Do not use multiple retry rates when using RTS/CTS */ | |
e039fa4a | 623 | info->control.alt_retry_rate_idx = -1; |
e2ebc74d JB |
624 | |
625 | /* Use min(data rate, max base rate) as CTS/RTS rate */ | |
2e92e6f2 | 626 | rate = &sband->bitrates[tx->rate_idx]; |
8318d78a JB |
627 | |
628 | for (idx = 0; idx < sband->n_bitrates; idx++) { | |
629 | if (sband->bitrates[idx].bitrate > rate->bitrate) | |
630 | continue; | |
631 | if (tx->sdata->basic_rates & BIT(idx) && | |
2e92e6f2 JB |
632 | (baserate < 0 || |
633 | (sband->bitrates[baserate].bitrate | |
634 | < sband->bitrates[idx].bitrate))) | |
635 | baserate = idx; | |
8318d78a | 636 | } |
e2ebc74d | 637 | |
2e92e6f2 | 638 | if (baserate >= 0) |
e039fa4a | 639 | info->control.rts_cts_rate_idx = baserate; |
8318d78a | 640 | else |
e039fa4a | 641 | info->control.rts_cts_rate_idx = 0; |
e2ebc74d JB |
642 | } |
643 | ||
e2454948 | 644 | if (tx->sta) |
e039fa4a | 645 | info->control.aid = tx->sta->aid; |
e2454948 JB |
646 | |
647 | return TX_CONTINUE; | |
648 | } | |
649 | ||
650 | static ieee80211_tx_result | |
651 | ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx) | |
652 | { | |
653 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx->skb->data; | |
654 | size_t hdrlen, per_fragm, num_fragm, payload_len, left; | |
655 | struct sk_buff **frags, *first, *frag; | |
656 | int i; | |
657 | u16 seq; | |
658 | u8 *pos; | |
659 | int frag_threshold = tx->local->fragmentation_threshold; | |
660 | ||
661 | if (!(tx->flags & IEEE80211_TX_FRAGMENTED)) | |
662 | return TX_CONTINUE; | |
663 | ||
eefce91a JB |
664 | /* |
665 | * Warn when submitting a fragmented A-MPDU frame and drop it. | |
666 | * This is an error and needs to be fixed elsewhere, but when | |
667 | * done needs to take care of monitor interfaces (injection) | |
668 | * etc. | |
669 | */ | |
670 | if (WARN_ON(tx->flags & IEEE80211_TX_CTL_AMPDU || | |
e2530083 JB |
671 | skb_get_queue_mapping(tx->skb) >= |
672 | ieee80211_num_regular_queues(&tx->local->hw))) | |
eefce91a JB |
673 | return TX_DROP; |
674 | ||
e2454948 JB |
675 | first = tx->skb; |
676 | ||
677 | hdrlen = ieee80211_get_hdrlen(tx->fc); | |
678 | payload_len = first->len - hdrlen; | |
679 | per_fragm = frag_threshold - hdrlen - FCS_LEN; | |
680 | num_fragm = DIV_ROUND_UP(payload_len, per_fragm); | |
681 | ||
682 | frags = kzalloc(num_fragm * sizeof(struct sk_buff *), GFP_ATOMIC); | |
683 | if (!frags) | |
684 | goto fail; | |
685 | ||
686 | hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_MOREFRAGS); | |
687 | seq = le16_to_cpu(hdr->seq_ctrl) & IEEE80211_SCTL_SEQ; | |
688 | pos = first->data + hdrlen + per_fragm; | |
689 | left = payload_len - per_fragm; | |
690 | for (i = 0; i < num_fragm - 1; i++) { | |
691 | struct ieee80211_hdr *fhdr; | |
692 | size_t copylen; | |
693 | ||
694 | if (left <= 0) | |
695 | goto fail; | |
696 | ||
697 | /* reserve enough extra head and tail room for possible | |
698 | * encryption */ | |
699 | frag = frags[i] = | |
700 | dev_alloc_skb(tx->local->tx_headroom + | |
701 | frag_threshold + | |
702 | IEEE80211_ENCRYPT_HEADROOM + | |
703 | IEEE80211_ENCRYPT_TAILROOM); | |
704 | if (!frag) | |
705 | goto fail; | |
706 | /* Make sure that all fragments use the same priority so | |
707 | * that they end up using the same TX queue */ | |
708 | frag->priority = first->priority; | |
709 | skb_reserve(frag, tx->local->tx_headroom + | |
710 | IEEE80211_ENCRYPT_HEADROOM); | |
711 | fhdr = (struct ieee80211_hdr *) skb_put(frag, hdrlen); | |
712 | memcpy(fhdr, first->data, hdrlen); | |
713 | if (i == num_fragm - 2) | |
714 | fhdr->frame_control &= cpu_to_le16(~IEEE80211_FCTL_MOREFRAGS); | |
715 | fhdr->seq_ctrl = cpu_to_le16(seq | ((i + 1) & IEEE80211_SCTL_FRAG)); | |
716 | copylen = left > per_fragm ? per_fragm : left; | |
717 | memcpy(skb_put(frag, copylen), pos, copylen); | |
718 | ||
719 | pos += copylen; | |
720 | left -= copylen; | |
e2ebc74d | 721 | } |
e2454948 JB |
722 | skb_trim(first, hdrlen + per_fragm); |
723 | ||
724 | tx->num_extra_frag = num_fragm - 1; | |
725 | tx->extra_frag = frags; | |
e2ebc74d | 726 | |
9ae54c84 | 727 | return TX_CONTINUE; |
e2454948 JB |
728 | |
729 | fail: | |
730 | printk(KERN_DEBUG "%s: failed to fragment frame\n", tx->dev->name); | |
731 | if (frags) { | |
732 | for (i = 0; i < num_fragm - 1; i++) | |
733 | if (frags[i]) | |
734 | dev_kfree_skb(frags[i]); | |
735 | kfree(frags); | |
736 | } | |
737 | I802_DEBUG_INC(tx->local->tx_handlers_drop_fragment); | |
738 | return TX_DROP; | |
e2ebc74d JB |
739 | } |
740 | ||
9ae54c84 | 741 | static ieee80211_tx_result |
e2454948 JB |
742 | ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx) |
743 | { | |
744 | if (!tx->key) | |
745 | return TX_CONTINUE; | |
746 | ||
747 | switch (tx->key->conf.alg) { | |
748 | case ALG_WEP: | |
749 | return ieee80211_crypto_wep_encrypt(tx); | |
750 | case ALG_TKIP: | |
751 | return ieee80211_crypto_tkip_encrypt(tx); | |
752 | case ALG_CCMP: | |
753 | return ieee80211_crypto_ccmp_encrypt(tx); | |
754 | } | |
755 | ||
756 | /* not reached */ | |
757 | WARN_ON(1); | |
758 | return TX_DROP; | |
759 | } | |
760 | ||
761 | static ieee80211_tx_result | |
762 | ieee80211_tx_h_stats(struct ieee80211_tx_data *tx) | |
e2ebc74d JB |
763 | { |
764 | struct ieee80211_local *local = tx->local; | |
e2ebc74d JB |
765 | struct sk_buff *skb = tx->skb; |
766 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; | |
767 | u32 load = 0, hdrtime; | |
2e92e6f2 JB |
768 | struct ieee80211_rate *rate; |
769 | struct ieee80211_supported_band *sband; | |
e039fa4a | 770 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
2e92e6f2 JB |
771 | |
772 | sband = tx->local->hw.wiphy->bands[tx->channel->band]; | |
773 | rate = &sband->bitrates[tx->rate_idx]; | |
e2ebc74d JB |
774 | |
775 | /* TODO: this could be part of tx_status handling, so that the number | |
776 | * of retries would be known; TX rate should in that case be stored | |
777 | * somewhere with the packet */ | |
778 | ||
779 | /* Estimate total channel use caused by this frame */ | |
780 | ||
781 | /* 1 bit at 1 Mbit/s takes 1 usec; in channel_use values, | |
782 | * 1 usec = 1/8 * (1080 / 10) = 13.5 */ | |
783 | ||
5cf121c3 JB |
784 | if (tx->channel->band == IEEE80211_BAND_5GHZ || |
785 | (tx->channel->band == IEEE80211_BAND_2GHZ && | |
8318d78a | 786 | rate->flags & IEEE80211_RATE_ERP_G)) |
e2ebc74d JB |
787 | hdrtime = CHAN_UTIL_HDR_SHORT; |
788 | else | |
789 | hdrtime = CHAN_UTIL_HDR_LONG; | |
790 | ||
791 | load = hdrtime; | |
792 | if (!is_multicast_ether_addr(hdr->addr1)) | |
793 | load += hdrtime; | |
794 | ||
e039fa4a | 795 | if (info->flags & IEEE80211_TX_CTL_USE_RTS_CTS) |
e2ebc74d | 796 | load += 2 * hdrtime; |
e039fa4a | 797 | else if (info->flags & IEEE80211_TX_CTL_USE_CTS_PROTECT) |
e2ebc74d JB |
798 | load += hdrtime; |
799 | ||
8318d78a JB |
800 | /* TODO: optimise again */ |
801 | load += skb->len * CHAN_UTIL_RATE_LCM / rate->bitrate; | |
e2ebc74d | 802 | |
5cf121c3 | 803 | if (tx->extra_frag) { |
e2ebc74d | 804 | int i; |
5cf121c3 | 805 | for (i = 0; i < tx->num_extra_frag; i++) { |
e2ebc74d | 806 | load += 2 * hdrtime; |
5cf121c3 | 807 | load += tx->extra_frag[i]->len * |
2e92e6f2 | 808 | rate->bitrate; |
e2ebc74d JB |
809 | } |
810 | } | |
811 | ||
812 | /* Divide channel_use by 8 to avoid wrapping around the counter */ | |
813 | load >>= CHAN_UTIL_SHIFT; | |
814 | local->channel_use_raw += load; | |
815 | if (tx->sta) | |
816 | tx->sta->channel_use_raw += load; | |
817 | tx->sdata->channel_use_raw += load; | |
818 | ||
e2454948 JB |
819 | if (tx->sta) { |
820 | tx->sta->tx_packets++; | |
821 | tx->sta->tx_fragments++; | |
822 | tx->sta->tx_bytes += tx->skb->len; | |
823 | if (tx->extra_frag) { | |
824 | int i; | |
825 | tx->sta->tx_fragments += tx->num_extra_frag; | |
826 | for (i = 0; i < tx->num_extra_frag; i++) { | |
827 | tx->sta->tx_bytes += | |
828 | tx->extra_frag[i]->len; | |
829 | } | |
830 | } | |
831 | } | |
832 | ||
9ae54c84 | 833 | return TX_CONTINUE; |
e2ebc74d JB |
834 | } |
835 | ||
e2ebc74d | 836 | |
5cf121c3 | 837 | typedef ieee80211_tx_result (*ieee80211_tx_handler)(struct ieee80211_tx_data *); |
58905290 | 838 | static ieee80211_tx_handler ieee80211_tx_handlers[] = |
e2ebc74d JB |
839 | { |
840 | ieee80211_tx_h_check_assoc, | |
841 | ieee80211_tx_h_sequence, | |
842 | ieee80211_tx_h_ps_buf, | |
843 | ieee80211_tx_h_select_key, | |
844 | ieee80211_tx_h_michael_mic_add, | |
e2ebc74d JB |
845 | ieee80211_tx_h_rate_ctrl, |
846 | ieee80211_tx_h_misc, | |
e2454948 | 847 | ieee80211_tx_h_fragment, |
e039fa4a | 848 | /* handlers after fragment must be aware of tx info fragmentation! */ |
e2454948 JB |
849 | ieee80211_tx_h_encrypt, |
850 | ieee80211_tx_h_stats, | |
e2ebc74d JB |
851 | NULL |
852 | }; | |
853 | ||
854 | /* actual transmit path */ | |
855 | ||
856 | /* | |
857 | * deal with packet injection down monitor interface | |
858 | * with Radiotap Header -- only called for monitor mode interface | |
859 | */ | |
9ae54c84 | 860 | static ieee80211_tx_result |
5cf121c3 | 861 | __ieee80211_parse_tx_radiotap(struct ieee80211_tx_data *tx, |
58d4185e | 862 | struct sk_buff *skb) |
e2ebc74d JB |
863 | { |
864 | /* | |
865 | * this is the moment to interpret and discard the radiotap header that | |
866 | * must be at the start of the packet injected in Monitor mode | |
867 | * | |
868 | * Need to take some care with endian-ness since radiotap | |
869 | * args are little-endian | |
870 | */ | |
871 | ||
872 | struct ieee80211_radiotap_iterator iterator; | |
873 | struct ieee80211_radiotap_header *rthdr = | |
874 | (struct ieee80211_radiotap_header *) skb->data; | |
8318d78a | 875 | struct ieee80211_supported_band *sband; |
e2ebc74d | 876 | int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len); |
e039fa4a | 877 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
e2ebc74d | 878 | |
2e92e6f2 | 879 | sband = tx->local->hw.wiphy->bands[tx->channel->band]; |
8318d78a | 880 | |
e039fa4a JB |
881 | info->flags |= IEEE80211_TX_CTL_DO_NOT_ENCRYPT; |
882 | info->flags |= IEEE80211_TX_CTL_INJECTED; | |
5cf121c3 | 883 | tx->flags &= ~IEEE80211_TX_FRAGMENTED; |
e2ebc74d JB |
884 | |
885 | /* | |
886 | * for every radiotap entry that is present | |
887 | * (ieee80211_radiotap_iterator_next returns -ENOENT when no more | |
888 | * entries present, or -EINVAL on error) | |
889 | */ | |
890 | ||
891 | while (!ret) { | |
892 | int i, target_rate; | |
893 | ||
894 | ret = ieee80211_radiotap_iterator_next(&iterator); | |
895 | ||
896 | if (ret) | |
897 | continue; | |
898 | ||
899 | /* see if this argument is something we can use */ | |
900 | switch (iterator.this_arg_index) { | |
901 | /* | |
902 | * You must take care when dereferencing iterator.this_arg | |
903 | * for multibyte types... the pointer is not aligned. Use | |
904 | * get_unaligned((type *)iterator.this_arg) to dereference | |
905 | * iterator.this_arg for type "type" safely on all arches. | |
906 | */ | |
907 | case IEEE80211_RADIOTAP_RATE: | |
908 | /* | |
909 | * radiotap rate u8 is in 500kbps units eg, 0x02=1Mbps | |
910 | * ieee80211 rate int is in 100kbps units eg, 0x0a=1Mbps | |
911 | */ | |
912 | target_rate = (*iterator.this_arg) * 5; | |
8318d78a JB |
913 | for (i = 0; i < sband->n_bitrates; i++) { |
914 | struct ieee80211_rate *r; | |
e2ebc74d | 915 | |
8318d78a JB |
916 | r = &sband->bitrates[i]; |
917 | ||
918 | if (r->bitrate == target_rate) { | |
2e92e6f2 | 919 | tx->rate_idx = i; |
58d4185e JB |
920 | break; |
921 | } | |
e2ebc74d JB |
922 | } |
923 | break; | |
924 | ||
925 | case IEEE80211_RADIOTAP_ANTENNA: | |
926 | /* | |
927 | * radiotap uses 0 for 1st ant, mac80211 is 1 for | |
928 | * 1st ant | |
929 | */ | |
e039fa4a | 930 | info->antenna_sel_tx = (*iterator.this_arg) + 1; |
e2ebc74d JB |
931 | break; |
932 | ||
8318d78a | 933 | #if 0 |
e2ebc74d JB |
934 | case IEEE80211_RADIOTAP_DBM_TX_POWER: |
935 | control->power_level = *iterator.this_arg; | |
936 | break; | |
8318d78a | 937 | #endif |
e2ebc74d JB |
938 | |
939 | case IEEE80211_RADIOTAP_FLAGS: | |
940 | if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) { | |
941 | /* | |
942 | * this indicates that the skb we have been | |
943 | * handed has the 32-bit FCS CRC at the end... | |
944 | * we should react to that by snipping it off | |
945 | * because it will be recomputed and added | |
946 | * on transmission | |
947 | */ | |
948 | if (skb->len < (iterator.max_length + FCS_LEN)) | |
9ae54c84 | 949 | return TX_DROP; |
e2ebc74d JB |
950 | |
951 | skb_trim(skb, skb->len - FCS_LEN); | |
952 | } | |
58d4185e | 953 | if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP) |
e039fa4a JB |
954 | info->flags &= |
955 | ~IEEE80211_TX_CTL_DO_NOT_ENCRYPT; | |
58d4185e | 956 | if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG) |
5cf121c3 | 957 | tx->flags |= IEEE80211_TX_FRAGMENTED; |
e2ebc74d JB |
958 | break; |
959 | ||
58d4185e JB |
960 | /* |
961 | * Please update the file | |
962 | * Documentation/networking/mac80211-injection.txt | |
963 | * when parsing new fields here. | |
964 | */ | |
965 | ||
e2ebc74d JB |
966 | default: |
967 | break; | |
968 | } | |
969 | } | |
970 | ||
971 | if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */ | |
9ae54c84 | 972 | return TX_DROP; |
e2ebc74d JB |
973 | |
974 | /* | |
975 | * remove the radiotap header | |
976 | * iterator->max_length was sanity-checked against | |
977 | * skb->len by iterator init | |
978 | */ | |
979 | skb_pull(skb, iterator.max_length); | |
980 | ||
9ae54c84 | 981 | return TX_CONTINUE; |
e2ebc74d JB |
982 | } |
983 | ||
58d4185e JB |
984 | /* |
985 | * initialises @tx | |
986 | */ | |
9ae54c84 | 987 | static ieee80211_tx_result |
5cf121c3 | 988 | __ieee80211_tx_prepare(struct ieee80211_tx_data *tx, |
e2ebc74d | 989 | struct sk_buff *skb, |
e039fa4a | 990 | struct net_device *dev) |
e2ebc74d JB |
991 | { |
992 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
58d4185e | 993 | struct ieee80211_hdr *hdr; |
e2ebc74d | 994 | struct ieee80211_sub_if_data *sdata; |
e039fa4a | 995 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
e2ebc74d JB |
996 | |
997 | int hdrlen; | |
998 | ||
999 | memset(tx, 0, sizeof(*tx)); | |
1000 | tx->skb = skb; | |
1001 | tx->dev = dev; /* use original interface */ | |
1002 | tx->local = local; | |
1003 | tx->sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
e039fa4a | 1004 | tx->channel = local->hw.conf.channel; |
e2ebc74d | 1005 | /* |
58d4185e JB |
1006 | * Set this flag (used below to indicate "automatic fragmentation"), |
1007 | * it will be cleared/left by radiotap as desired. | |
e2ebc74d | 1008 | */ |
5cf121c3 | 1009 | tx->flags |= IEEE80211_TX_FRAGMENTED; |
e2ebc74d JB |
1010 | |
1011 | /* process and remove the injection radiotap header */ | |
1012 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
51fb61e7 | 1013 | if (unlikely(sdata->vif.type == IEEE80211_IF_TYPE_MNTR)) { |
9ae54c84 JB |
1014 | if (__ieee80211_parse_tx_radiotap(tx, skb) == TX_DROP) |
1015 | return TX_DROP; | |
58d4185e | 1016 | |
e2ebc74d | 1017 | /* |
58d4185e JB |
1018 | * __ieee80211_parse_tx_radiotap has now removed |
1019 | * the radiotap header that was present and pre-filled | |
1020 | * 'tx' with tx control information. | |
e2ebc74d | 1021 | */ |
e2ebc74d JB |
1022 | } |
1023 | ||
58d4185e JB |
1024 | hdr = (struct ieee80211_hdr *) skb->data; |
1025 | ||
24338793 | 1026 | tx->sta = sta_info_get(local, hdr->addr1); |
1027 | tx->fc = le16_to_cpu(hdr->frame_control); | |
58d4185e | 1028 | |
badffb72 | 1029 | if (is_multicast_ether_addr(hdr->addr1)) { |
5cf121c3 | 1030 | tx->flags &= ~IEEE80211_TX_UNICAST; |
e039fa4a | 1031 | info->flags |= IEEE80211_TX_CTL_NO_ACK; |
badffb72 | 1032 | } else { |
5cf121c3 | 1033 | tx->flags |= IEEE80211_TX_UNICAST; |
e039fa4a | 1034 | info->flags &= ~IEEE80211_TX_CTL_NO_ACK; |
badffb72 | 1035 | } |
58d4185e | 1036 | |
5cf121c3 JB |
1037 | if (tx->flags & IEEE80211_TX_FRAGMENTED) { |
1038 | if ((tx->flags & IEEE80211_TX_UNICAST) && | |
58d4185e JB |
1039 | skb->len + FCS_LEN > local->fragmentation_threshold && |
1040 | !local->ops->set_frag_threshold) | |
5cf121c3 | 1041 | tx->flags |= IEEE80211_TX_FRAGMENTED; |
58d4185e | 1042 | else |
5cf121c3 | 1043 | tx->flags &= ~IEEE80211_TX_FRAGMENTED; |
58d4185e JB |
1044 | } |
1045 | ||
e2ebc74d | 1046 | if (!tx->sta) |
e039fa4a | 1047 | info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; |
07346f81 | 1048 | else if (test_and_clear_sta_flags(tx->sta, WLAN_STA_CLEAR_PS_FILT)) |
e039fa4a | 1049 | info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; |
58d4185e | 1050 | |
e2ebc74d JB |
1051 | hdrlen = ieee80211_get_hdrlen(tx->fc); |
1052 | if (skb->len > hdrlen + sizeof(rfc1042_header) + 2) { | |
1053 | u8 *pos = &skb->data[hdrlen + sizeof(rfc1042_header)]; | |
1054 | tx->ethertype = (pos[0] << 8) | pos[1]; | |
1055 | } | |
e039fa4a | 1056 | info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT; |
e2ebc74d | 1057 | |
9ae54c84 | 1058 | return TX_CONTINUE; |
e2ebc74d JB |
1059 | } |
1060 | ||
32bfd35d | 1061 | /* |
58d4185e JB |
1062 | * NB: @tx is uninitialised when passed in here |
1063 | */ | |
5cf121c3 | 1064 | static int ieee80211_tx_prepare(struct ieee80211_tx_data *tx, |
58d4185e | 1065 | struct sk_buff *skb, |
e039fa4a | 1066 | struct net_device *mdev) |
e2ebc74d | 1067 | { |
e039fa4a | 1068 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
e2ebc74d JB |
1069 | struct net_device *dev; |
1070 | ||
e039fa4a | 1071 | dev = dev_get_by_index(&init_net, info->control.ifindex); |
e2ebc74d JB |
1072 | if (unlikely(dev && !is_ieee80211_device(dev, mdev))) { |
1073 | dev_put(dev); | |
1074 | dev = NULL; | |
1075 | } | |
1076 | if (unlikely(!dev)) | |
1077 | return -ENODEV; | |
58d4185e | 1078 | /* initialises tx with control */ |
e039fa4a | 1079 | __ieee80211_tx_prepare(tx, skb, dev); |
32bfd35d | 1080 | dev_put(dev); |
e2ebc74d JB |
1081 | return 0; |
1082 | } | |
1083 | ||
1084 | static int __ieee80211_tx(struct ieee80211_local *local, struct sk_buff *skb, | |
5cf121c3 | 1085 | struct ieee80211_tx_data *tx) |
e2ebc74d | 1086 | { |
e039fa4a | 1087 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
e2ebc74d JB |
1088 | int ret, i; |
1089 | ||
e2530083 | 1090 | if (netif_subqueue_stopped(local->mdev, skb)) |
e2ebc74d | 1091 | return IEEE80211_TX_AGAIN; |
e2530083 | 1092 | |
e2ebc74d | 1093 | if (skb) { |
dd1cd4c6 JB |
1094 | ieee80211_dump_frame(wiphy_name(local->hw.wiphy), |
1095 | "TX to low-level driver", skb); | |
e039fa4a | 1096 | ret = local->ops->tx(local_to_hw(local), skb); |
e2ebc74d JB |
1097 | if (ret) |
1098 | return IEEE80211_TX_AGAIN; | |
1099 | local->mdev->trans_start = jiffies; | |
1100 | ieee80211_led_tx(local, 1); | |
1101 | } | |
5cf121c3 | 1102 | if (tx->extra_frag) { |
5cf121c3 JB |
1103 | for (i = 0; i < tx->num_extra_frag; i++) { |
1104 | if (!tx->extra_frag[i]) | |
e2ebc74d | 1105 | continue; |
e039fa4a JB |
1106 | info = IEEE80211_SKB_CB(tx->extra_frag[i]); |
1107 | info->flags &= ~(IEEE80211_TX_CTL_USE_RTS_CTS | | |
1108 | IEEE80211_TX_CTL_USE_CTS_PROTECT | | |
1109 | IEEE80211_TX_CTL_CLEAR_PS_FILT | | |
1110 | IEEE80211_TX_CTL_FIRST_FRAGMENT); | |
e2530083 JB |
1111 | if (netif_subqueue_stopped(local->mdev, |
1112 | tx->extra_frag[i])) | |
e2ebc74d | 1113 | return IEEE80211_TX_FRAG_AGAIN; |
5cf121c3 | 1114 | if (i == tx->num_extra_frag) { |
e039fa4a | 1115 | info->tx_rate_idx = tx->last_frag_rate_idx; |
8318d78a | 1116 | |
5cf121c3 | 1117 | if (tx->flags & IEEE80211_TX_PROBE_LAST_FRAG) |
e039fa4a JB |
1118 | info->flags |= |
1119 | IEEE80211_TX_CTL_RATE_CTRL_PROBE; | |
e2ebc74d | 1120 | else |
e039fa4a JB |
1121 | info->flags &= |
1122 | ~IEEE80211_TX_CTL_RATE_CTRL_PROBE; | |
e2ebc74d JB |
1123 | } |
1124 | ||
dd1cd4c6 | 1125 | ieee80211_dump_frame(wiphy_name(local->hw.wiphy), |
e2ebc74d | 1126 | "TX to low-level driver", |
5cf121c3 | 1127 | tx->extra_frag[i]); |
e2ebc74d | 1128 | ret = local->ops->tx(local_to_hw(local), |
e039fa4a | 1129 | tx->extra_frag[i]); |
e2ebc74d JB |
1130 | if (ret) |
1131 | return IEEE80211_TX_FRAG_AGAIN; | |
1132 | local->mdev->trans_start = jiffies; | |
1133 | ieee80211_led_tx(local, 1); | |
5cf121c3 | 1134 | tx->extra_frag[i] = NULL; |
e2ebc74d | 1135 | } |
5cf121c3 JB |
1136 | kfree(tx->extra_frag); |
1137 | tx->extra_frag = NULL; | |
e2ebc74d JB |
1138 | } |
1139 | return IEEE80211_TX_OK; | |
1140 | } | |
1141 | ||
e039fa4a | 1142 | static int ieee80211_tx(struct net_device *dev, struct sk_buff *skb) |
e2ebc74d JB |
1143 | { |
1144 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
1145 | struct sta_info *sta; | |
1146 | ieee80211_tx_handler *handler; | |
5cf121c3 | 1147 | struct ieee80211_tx_data tx; |
9ae54c84 | 1148 | ieee80211_tx_result res = TX_DROP, res_prepare; |
e039fa4a | 1149 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
e2ebc74d | 1150 | int ret, i; |
e2530083 | 1151 | u16 queue; |
e2ebc74d | 1152 | |
e2530083 JB |
1153 | queue = skb_get_queue_mapping(skb); |
1154 | ||
1155 | WARN_ON(test_bit(queue, local->queues_pending)); | |
e2ebc74d JB |
1156 | |
1157 | if (unlikely(skb->len < 10)) { | |
1158 | dev_kfree_skb(skb); | |
1159 | return 0; | |
1160 | } | |
1161 | ||
d0709a65 JB |
1162 | rcu_read_lock(); |
1163 | ||
58d4185e | 1164 | /* initialises tx */ |
e039fa4a | 1165 | res_prepare = __ieee80211_tx_prepare(&tx, skb, dev); |
e2ebc74d | 1166 | |
9ae54c84 | 1167 | if (res_prepare == TX_DROP) { |
e2ebc74d | 1168 | dev_kfree_skb(skb); |
d0709a65 | 1169 | rcu_read_unlock(); |
e2ebc74d JB |
1170 | return 0; |
1171 | } | |
1172 | ||
1173 | sta = tx.sta; | |
5cf121c3 | 1174 | tx.channel = local->hw.conf.channel; |
e039fa4a | 1175 | info->band = tx.channel->band; |
e2ebc74d | 1176 | |
58905290 | 1177 | for (handler = ieee80211_tx_handlers; *handler != NULL; |
58d4185e JB |
1178 | handler++) { |
1179 | res = (*handler)(&tx); | |
9ae54c84 | 1180 | if (res != TX_CONTINUE) |
58d4185e | 1181 | break; |
e2ebc74d JB |
1182 | } |
1183 | ||
e039fa4a JB |
1184 | if (WARN_ON(tx.skb != skb)) |
1185 | goto drop; | |
e2ebc74d | 1186 | |
9ae54c84 | 1187 | if (unlikely(res == TX_DROP)) { |
e2ebc74d JB |
1188 | I802_DEBUG_INC(local->tx_handlers_drop); |
1189 | goto drop; | |
1190 | } | |
1191 | ||
9ae54c84 | 1192 | if (unlikely(res == TX_QUEUED)) { |
e2ebc74d | 1193 | I802_DEBUG_INC(local->tx_handlers_queued); |
d4e46a3d | 1194 | rcu_read_unlock(); |
e2ebc74d JB |
1195 | return 0; |
1196 | } | |
1197 | ||
5cf121c3 JB |
1198 | if (tx.extra_frag) { |
1199 | for (i = 0; i < tx.num_extra_frag; i++) { | |
e2ebc74d JB |
1200 | int next_len, dur; |
1201 | struct ieee80211_hdr *hdr = | |
1202 | (struct ieee80211_hdr *) | |
5cf121c3 | 1203 | tx.extra_frag[i]->data; |
e2ebc74d | 1204 | |
5cf121c3 JB |
1205 | if (i + 1 < tx.num_extra_frag) { |
1206 | next_len = tx.extra_frag[i + 1]->len; | |
e2ebc74d JB |
1207 | } else { |
1208 | next_len = 0; | |
2e92e6f2 | 1209 | tx.rate_idx = tx.last_frag_rate_idx; |
e2ebc74d JB |
1210 | } |
1211 | dur = ieee80211_duration(&tx, 0, next_len); | |
1212 | hdr->duration_id = cpu_to_le16(dur); | |
1213 | } | |
1214 | } | |
1215 | ||
1216 | retry: | |
1217 | ret = __ieee80211_tx(local, skb, &tx); | |
1218 | if (ret) { | |
eefce91a JB |
1219 | struct ieee80211_tx_stored_packet *store; |
1220 | ||
1221 | /* | |
1222 | * Since there are no fragmented frames on A-MPDU | |
1223 | * queues, there's no reason for a driver to reject | |
1224 | * a frame there, warn and drop it. | |
1225 | */ | |
e2530083 | 1226 | if (WARN_ON(queue >= ieee80211_num_regular_queues(&local->hw))) |
eefce91a JB |
1227 | goto drop; |
1228 | ||
1229 | store = &local->pending_packet[queue]; | |
e2ebc74d JB |
1230 | |
1231 | if (ret == IEEE80211_TX_FRAG_AGAIN) | |
1232 | skb = NULL; | |
e2530083 | 1233 | set_bit(queue, local->queues_pending); |
e2ebc74d | 1234 | smp_mb(); |
e2530083 JB |
1235 | /* |
1236 | * When the driver gets out of buffers during sending of | |
1237 | * fragments and calls ieee80211_stop_queue, the netif | |
1238 | * subqueue is stopped. There is, however, a small window | |
1239 | * in which the PENDING bit is not yet set. If a buffer | |
e2ebc74d JB |
1240 | * gets available in that window (i.e. driver calls |
1241 | * ieee80211_wake_queue), we would end up with ieee80211_tx | |
e2530083 | 1242 | * called with the PENDING bit still set. Prevent this by |
e2ebc74d | 1243 | * continuing transmitting here when that situation is |
e2530083 JB |
1244 | * possible to have happened. |
1245 | */ | |
1246 | if (!__netif_subqueue_stopped(local->mdev, queue)) { | |
1247 | clear_bit(queue, local->queues_pending); | |
e2ebc74d JB |
1248 | goto retry; |
1249 | } | |
e2ebc74d | 1250 | store->skb = skb; |
5cf121c3 JB |
1251 | store->extra_frag = tx.extra_frag; |
1252 | store->num_extra_frag = tx.num_extra_frag; | |
2e92e6f2 | 1253 | store->last_frag_rate_idx = tx.last_frag_rate_idx; |
badffb72 | 1254 | store->last_frag_rate_ctrl_probe = |
5cf121c3 | 1255 | !!(tx.flags & IEEE80211_TX_PROBE_LAST_FRAG); |
e2ebc74d | 1256 | } |
d4e46a3d | 1257 | rcu_read_unlock(); |
e2ebc74d JB |
1258 | return 0; |
1259 | ||
1260 | drop: | |
1261 | if (skb) | |
1262 | dev_kfree_skb(skb); | |
5cf121c3 JB |
1263 | for (i = 0; i < tx.num_extra_frag; i++) |
1264 | if (tx.extra_frag[i]) | |
1265 | dev_kfree_skb(tx.extra_frag[i]); | |
1266 | kfree(tx.extra_frag); | |
d4e46a3d | 1267 | rcu_read_unlock(); |
e2ebc74d JB |
1268 | return 0; |
1269 | } | |
1270 | ||
1271 | /* device xmit handlers */ | |
1272 | ||
1273 | int ieee80211_master_start_xmit(struct sk_buff *skb, | |
1274 | struct net_device *dev) | |
1275 | { | |
e039fa4a | 1276 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
e2ebc74d JB |
1277 | struct net_device *odev = NULL; |
1278 | struct ieee80211_sub_if_data *osdata; | |
1279 | int headroom; | |
1280 | int ret; | |
1281 | ||
e039fa4a JB |
1282 | if (info->control.ifindex) |
1283 | odev = dev_get_by_index(&init_net, info->control.ifindex); | |
e2ebc74d JB |
1284 | if (unlikely(odev && !is_ieee80211_device(odev, dev))) { |
1285 | dev_put(odev); | |
1286 | odev = NULL; | |
1287 | } | |
1288 | if (unlikely(!odev)) { | |
1289 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | |
1290 | printk(KERN_DEBUG "%s: Discarded packet with nonexistent " | |
1291 | "originating device\n", dev->name); | |
1292 | #endif | |
1293 | dev_kfree_skb(skb); | |
1294 | return 0; | |
1295 | } | |
e039fa4a | 1296 | |
e2ebc74d JB |
1297 | osdata = IEEE80211_DEV_TO_SUB_IF(odev); |
1298 | ||
1299 | headroom = osdata->local->tx_headroom + IEEE80211_ENCRYPT_HEADROOM; | |
1300 | if (skb_headroom(skb) < headroom) { | |
1301 | if (pskb_expand_head(skb, headroom, 0, GFP_ATOMIC)) { | |
1302 | dev_kfree_skb(skb); | |
1303 | dev_put(odev); | |
1304 | return 0; | |
1305 | } | |
1306 | } | |
1307 | ||
e039fa4a JB |
1308 | info->control.vif = &osdata->vif; |
1309 | ret = ieee80211_tx(odev, skb); | |
e2ebc74d JB |
1310 | dev_put(odev); |
1311 | ||
1312 | return ret; | |
1313 | } | |
1314 | ||
1315 | int ieee80211_monitor_start_xmit(struct sk_buff *skb, | |
1316 | struct net_device *dev) | |
1317 | { | |
1318 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
e039fa4a | 1319 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
e2ebc74d JB |
1320 | struct ieee80211_radiotap_header *prthdr = |
1321 | (struct ieee80211_radiotap_header *)skb->data; | |
9b8a74e3 | 1322 | u16 len_rthdr; |
e2ebc74d | 1323 | |
9b8a74e3 AG |
1324 | /* check for not even having the fixed radiotap header part */ |
1325 | if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header))) | |
1326 | goto fail; /* too short to be possibly valid */ | |
1327 | ||
1328 | /* is it a header version we can trust to find length from? */ | |
1329 | if (unlikely(prthdr->it_version)) | |
1330 | goto fail; /* only version 0 is supported */ | |
1331 | ||
1332 | /* then there must be a radiotap header with a length we can use */ | |
1333 | len_rthdr = ieee80211_get_radiotap_len(skb->data); | |
1334 | ||
1335 | /* does the skb contain enough to deliver on the alleged length? */ | |
1336 | if (unlikely(skb->len < len_rthdr)) | |
1337 | goto fail; /* skb too short for claimed rt header extent */ | |
e2ebc74d JB |
1338 | |
1339 | skb->dev = local->mdev; | |
1340 | ||
9b8a74e3 | 1341 | /* needed because we set skb device to master */ |
e039fa4a | 1342 | info->control.ifindex = dev->ifindex; |
9b8a74e3 | 1343 | |
e039fa4a | 1344 | info->flags |= IEEE80211_TX_CTL_DO_NOT_ENCRYPT; |
b0a67179 | 1345 | /* Interfaces should always request a status report */ |
e039fa4a | 1346 | info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; |
e2ebc74d | 1347 | |
e2ebc74d JB |
1348 | /* |
1349 | * fix up the pointers accounting for the radiotap | |
1350 | * header still being in there. We are being given | |
1351 | * a precooked IEEE80211 header so no need for | |
1352 | * normal processing | |
1353 | */ | |
9b8a74e3 | 1354 | skb_set_mac_header(skb, len_rthdr); |
e2ebc74d | 1355 | /* |
9b8a74e3 AG |
1356 | * these are just fixed to the end of the rt area since we |
1357 | * don't have any better information and at this point, nobody cares | |
e2ebc74d | 1358 | */ |
9b8a74e3 AG |
1359 | skb_set_network_header(skb, len_rthdr); |
1360 | skb_set_transport_header(skb, len_rthdr); | |
e2ebc74d | 1361 | |
9b8a74e3 AG |
1362 | /* pass the radiotap header up to the next stage intact */ |
1363 | dev_queue_xmit(skb); | |
e2ebc74d | 1364 | return NETDEV_TX_OK; |
9b8a74e3 AG |
1365 | |
1366 | fail: | |
1367 | dev_kfree_skb(skb); | |
1368 | return NETDEV_TX_OK; /* meaning, we dealt with the skb */ | |
e2ebc74d JB |
1369 | } |
1370 | ||
1371 | /** | |
1372 | * ieee80211_subif_start_xmit - netif start_xmit function for Ethernet-type | |
1373 | * subinterfaces (wlan#, WDS, and VLAN interfaces) | |
1374 | * @skb: packet to be sent | |
1375 | * @dev: incoming interface | |
1376 | * | |
1377 | * Returns: 0 on success (and frees skb in this case) or 1 on failure (skb will | |
1378 | * not be freed, and caller is responsible for either retrying later or freeing | |
1379 | * skb). | |
1380 | * | |
1381 | * This function takes in an Ethernet header and encapsulates it with suitable | |
1382 | * IEEE 802.11 header based on which interface the packet is coming in. The | |
1383 | * encapsulated packet will then be passed to master interface, wlan#.11, for | |
1384 | * transmission (through low-level driver). | |
1385 | */ | |
1386 | int ieee80211_subif_start_xmit(struct sk_buff *skb, | |
1387 | struct net_device *dev) | |
1388 | { | |
1389 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); | |
e039fa4a | 1390 | struct ieee80211_tx_info *info; |
e2ebc74d JB |
1391 | struct ieee80211_sub_if_data *sdata; |
1392 | int ret = 1, head_need; | |
33b64eb2 | 1393 | u16 ethertype, hdrlen, meshhdrlen = 0, fc; |
e2ebc74d | 1394 | struct ieee80211_hdr hdr; |
33b64eb2 | 1395 | struct ieee80211s_hdr mesh_hdr; |
e2ebc74d JB |
1396 | const u8 *encaps_data; |
1397 | int encaps_len, skip_header_bytes; | |
e8bf9649 | 1398 | int nh_pos, h_pos; |
e2ebc74d | 1399 | struct sta_info *sta; |
ce3edf6d | 1400 | u32 sta_flags = 0; |
e2ebc74d JB |
1401 | |
1402 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); | |
1403 | if (unlikely(skb->len < ETH_HLEN)) { | |
1404 | printk(KERN_DEBUG "%s: short skb (len=%d)\n", | |
1405 | dev->name, skb->len); | |
1406 | ret = 0; | |
1407 | goto fail; | |
1408 | } | |
1409 | ||
1410 | nh_pos = skb_network_header(skb) - skb->data; | |
1411 | h_pos = skb_transport_header(skb) - skb->data; | |
1412 | ||
1413 | /* convert Ethernet header to proper 802.11 header (based on | |
1414 | * operation mode) */ | |
1415 | ethertype = (skb->data[12] << 8) | skb->data[13]; | |
e2ebc74d JB |
1416 | fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA; |
1417 | ||
51fb61e7 | 1418 | switch (sdata->vif.type) { |
cf966838 JB |
1419 | case IEEE80211_IF_TYPE_AP: |
1420 | case IEEE80211_IF_TYPE_VLAN: | |
e2ebc74d JB |
1421 | fc |= IEEE80211_FCTL_FROMDS; |
1422 | /* DA BSSID SA */ | |
1423 | memcpy(hdr.addr1, skb->data, ETH_ALEN); | |
1424 | memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN); | |
1425 | memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN); | |
1426 | hdrlen = 24; | |
cf966838 JB |
1427 | break; |
1428 | case IEEE80211_IF_TYPE_WDS: | |
e2ebc74d JB |
1429 | fc |= IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS; |
1430 | /* RA TA DA SA */ | |
1431 | memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN); | |
1432 | memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN); | |
1433 | memcpy(hdr.addr3, skb->data, ETH_ALEN); | |
1434 | memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); | |
1435 | hdrlen = 30; | |
cf966838 | 1436 | break; |
33b64eb2 LCC |
1437 | #ifdef CONFIG_MAC80211_MESH |
1438 | case IEEE80211_IF_TYPE_MESH_POINT: | |
1439 | fc |= IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS; | |
1440 | /* RA TA DA SA */ | |
1441 | if (is_multicast_ether_addr(skb->data)) | |
1442 | memcpy(hdr.addr1, skb->data, ETH_ALEN); | |
1443 | else if (mesh_nexthop_lookup(hdr.addr1, skb, dev)) | |
1444 | return 0; | |
1445 | memcpy(hdr.addr2, dev->dev_addr, ETH_ALEN); | |
1446 | memcpy(hdr.addr3, skb->data, ETH_ALEN); | |
1447 | memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); | |
1448 | if (skb->pkt_type == PACKET_OTHERHOST) { | |
1449 | /* Forwarded frame, keep mesh ttl and seqnum */ | |
1450 | struct ieee80211s_hdr *prev_meshhdr; | |
1451 | prev_meshhdr = ((struct ieee80211s_hdr *)skb->cb); | |
1452 | meshhdrlen = ieee80211_get_mesh_hdrlen(prev_meshhdr); | |
1453 | memcpy(&mesh_hdr, prev_meshhdr, meshhdrlen); | |
1454 | sdata->u.sta.mshstats.fwded_frames++; | |
1455 | } else { | |
1456 | if (!sdata->u.sta.mshcfg.dot11MeshTTL) { | |
1457 | /* Do not send frames with mesh_ttl == 0 */ | |
1458 | sdata->u.sta.mshstats.dropped_frames_ttl++; | |
1459 | ret = 0; | |
1460 | goto fail; | |
1461 | } | |
1462 | meshhdrlen = ieee80211_new_mesh_header(&mesh_hdr, | |
902acc78 | 1463 | sdata); |
33b64eb2 LCC |
1464 | } |
1465 | hdrlen = 30; | |
1466 | break; | |
1467 | #endif | |
cf966838 | 1468 | case IEEE80211_IF_TYPE_STA: |
e2ebc74d JB |
1469 | fc |= IEEE80211_FCTL_TODS; |
1470 | /* BSSID SA DA */ | |
1471 | memcpy(hdr.addr1, sdata->u.sta.bssid, ETH_ALEN); | |
1472 | memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); | |
1473 | memcpy(hdr.addr3, skb->data, ETH_ALEN); | |
1474 | hdrlen = 24; | |
cf966838 JB |
1475 | break; |
1476 | case IEEE80211_IF_TYPE_IBSS: | |
e2ebc74d JB |
1477 | /* DA SA BSSID */ |
1478 | memcpy(hdr.addr1, skb->data, ETH_ALEN); | |
1479 | memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); | |
1480 | memcpy(hdr.addr3, sdata->u.sta.bssid, ETH_ALEN); | |
1481 | hdrlen = 24; | |
cf966838 JB |
1482 | break; |
1483 | default: | |
e2ebc74d JB |
1484 | ret = 0; |
1485 | goto fail; | |
1486 | } | |
1487 | ||
7d185b8b JB |
1488 | /* |
1489 | * There's no need to try to look up the destination | |
1490 | * if it is a multicast address (which can only happen | |
1491 | * in AP mode) | |
1492 | */ | |
1493 | if (!is_multicast_ether_addr(hdr.addr1)) { | |
d0709a65 | 1494 | rcu_read_lock(); |
7d185b8b | 1495 | sta = sta_info_get(local, hdr.addr1); |
d0709a65 | 1496 | if (sta) |
07346f81 | 1497 | sta_flags = get_sta_flags(sta); |
d0709a65 | 1498 | rcu_read_unlock(); |
e2ebc74d JB |
1499 | } |
1500 | ||
3434fbd3 | 1501 | /* receiver and we are QoS enabled, use a QoS type frame */ |
e2530083 JB |
1502 | if (sta_flags & WLAN_STA_WME && |
1503 | ieee80211_num_regular_queues(&local->hw) >= 4) { | |
ce3edf6d JB |
1504 | fc |= IEEE80211_STYPE_QOS_DATA; |
1505 | hdrlen += 2; | |
1506 | } | |
1507 | ||
1508 | /* | |
238814fd JB |
1509 | * Drop unicast frames to unauthorised stations unless they are |
1510 | * EAPOL frames from the local station. | |
ce3edf6d | 1511 | */ |
238814fd | 1512 | if (unlikely(!is_multicast_ether_addr(hdr.addr1) && |
33b64eb2 LCC |
1513 | !(sta_flags & WLAN_STA_AUTHORIZED) && |
1514 | !(ethertype == ETH_P_PAE && | |
ce3edf6d JB |
1515 | compare_ether_addr(dev->dev_addr, |
1516 | skb->data + ETH_ALEN) == 0))) { | |
1517 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG | |
1518 | DECLARE_MAC_BUF(mac); | |
1519 | ||
1520 | if (net_ratelimit()) | |
1521 | printk(KERN_DEBUG "%s: dropped frame to %s" | |
1522 | " (unauthorized port)\n", dev->name, | |
1523 | print_mac(mac, hdr.addr1)); | |
1524 | #endif | |
1525 | ||
1526 | I802_DEBUG_INC(local->tx_handlers_drop_unauth_port); | |
1527 | ||
1528 | ret = 0; | |
1529 | goto fail; | |
1530 | } | |
1531 | ||
e2ebc74d JB |
1532 | hdr.frame_control = cpu_to_le16(fc); |
1533 | hdr.duration_id = 0; | |
1534 | hdr.seq_ctrl = 0; | |
1535 | ||
1536 | skip_header_bytes = ETH_HLEN; | |
1537 | if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) { | |
1538 | encaps_data = bridge_tunnel_header; | |
1539 | encaps_len = sizeof(bridge_tunnel_header); | |
1540 | skip_header_bytes -= 2; | |
1541 | } else if (ethertype >= 0x600) { | |
1542 | encaps_data = rfc1042_header; | |
1543 | encaps_len = sizeof(rfc1042_header); | |
1544 | skip_header_bytes -= 2; | |
1545 | } else { | |
1546 | encaps_data = NULL; | |
1547 | encaps_len = 0; | |
1548 | } | |
1549 | ||
1550 | skb_pull(skb, skip_header_bytes); | |
1551 | nh_pos -= skip_header_bytes; | |
1552 | h_pos -= skip_header_bytes; | |
1553 | ||
1554 | /* TODO: implement support for fragments so that there is no need to | |
1555 | * reallocate and copy payload; it might be enough to support one | |
1556 | * extra fragment that would be copied in the beginning of the frame | |
1557 | * data.. anyway, it would be nice to include this into skb structure | |
1558 | * somehow | |
1559 | * | |
1560 | * There are few options for this: | |
1561 | * use skb->cb as an extra space for 802.11 header | |
1562 | * allocate new buffer if not enough headroom | |
1563 | * make sure that there is enough headroom in every skb by increasing | |
1564 | * build in headroom in __dev_alloc_skb() (linux/skbuff.h) and | |
1565 | * alloc_skb() (net/core/skbuff.c) | |
1566 | */ | |
33b64eb2 | 1567 | head_need = hdrlen + encaps_len + meshhdrlen + local->tx_headroom; |
e2ebc74d JB |
1568 | head_need -= skb_headroom(skb); |
1569 | ||
1570 | /* We are going to modify skb data, so make a copy of it if happens to | |
1571 | * be cloned. This could happen, e.g., with Linux bridge code passing | |
1572 | * us broadcast frames. */ | |
1573 | ||
608961a5 | 1574 | if (head_need > 0 || skb_header_cloned(skb)) { |
e2ebc74d JB |
1575 | #if 0 |
1576 | printk(KERN_DEBUG "%s: need to reallocate buffer for %d bytes " | |
1577 | "of headroom\n", dev->name, head_need); | |
1578 | #endif | |
1579 | ||
608961a5 | 1580 | if (skb_header_cloned(skb)) |
e2ebc74d JB |
1581 | I802_DEBUG_INC(local->tx_expand_skb_head_cloned); |
1582 | else | |
1583 | I802_DEBUG_INC(local->tx_expand_skb_head); | |
1584 | /* Since we have to reallocate the buffer, make sure that there | |
1585 | * is enough room for possible WEP IV/ICV and TKIP (8 bytes | |
1586 | * before payload and 12 after). */ | |
1587 | if (pskb_expand_head(skb, (head_need > 0 ? head_need + 8 : 8), | |
1588 | 12, GFP_ATOMIC)) { | |
1589 | printk(KERN_DEBUG "%s: failed to reallocate TX buffer" | |
1590 | "\n", dev->name); | |
1591 | goto fail; | |
1592 | } | |
1593 | } | |
1594 | ||
1595 | if (encaps_data) { | |
1596 | memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len); | |
1597 | nh_pos += encaps_len; | |
1598 | h_pos += encaps_len; | |
1599 | } | |
c29b9b9b | 1600 | |
33b64eb2 LCC |
1601 | if (meshhdrlen > 0) { |
1602 | memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen); | |
1603 | nh_pos += meshhdrlen; | |
1604 | h_pos += meshhdrlen; | |
1605 | } | |
1606 | ||
c29b9b9b JB |
1607 | if (fc & IEEE80211_STYPE_QOS_DATA) { |
1608 | __le16 *qos_control; | |
1609 | ||
1610 | qos_control = (__le16*) skb_push(skb, 2); | |
1611 | memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2); | |
1612 | /* | |
1613 | * Maybe we could actually set some fields here, for now just | |
1614 | * initialise to zero to indicate no special operation. | |
1615 | */ | |
1616 | *qos_control = 0; | |
1617 | } else | |
1618 | memcpy(skb_push(skb, hdrlen), &hdr, hdrlen); | |
1619 | ||
e2ebc74d JB |
1620 | nh_pos += hdrlen; |
1621 | h_pos += hdrlen; | |
1622 | ||
e039fa4a JB |
1623 | info = IEEE80211_SKB_CB(skb); |
1624 | memset(info, 0, sizeof(*info)); | |
1625 | info->control.ifindex = dev->ifindex; | |
678f5f71 | 1626 | if (ethertype == ETH_P_PAE) |
e039fa4a | 1627 | info->flags |= IEEE80211_TX_CTL_EAPOL_FRAME; |
e2ebc74d | 1628 | |
b0a67179 | 1629 | /* Interfaces should always request a status report */ |
e039fa4a | 1630 | info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; |
b0a67179 | 1631 | |
e2ebc74d | 1632 | skb->dev = local->mdev; |
68aae116 SH |
1633 | dev->stats.tx_packets++; |
1634 | dev->stats.tx_bytes += skb->len; | |
e2ebc74d JB |
1635 | |
1636 | /* Update skb pointers to various headers since this modified frame | |
1637 | * is going to go through Linux networking code that may potentially | |
1638 | * need things like pointer to IP header. */ | |
1639 | skb_set_mac_header(skb, 0); | |
1640 | skb_set_network_header(skb, nh_pos); | |
1641 | skb_set_transport_header(skb, h_pos); | |
1642 | ||
1643 | dev->trans_start = jiffies; | |
1644 | dev_queue_xmit(skb); | |
1645 | ||
1646 | return 0; | |
1647 | ||
1648 | fail: | |
1649 | if (!ret) | |
1650 | dev_kfree_skb(skb); | |
1651 | ||
1652 | return ret; | |
1653 | } | |
1654 | ||
e2ebc74d | 1655 | |
e2530083 JB |
1656 | /* |
1657 | * ieee80211_clear_tx_pending may not be called in a context where | |
1658 | * it is possible that it packets could come in again. | |
1659 | */ | |
e2ebc74d JB |
1660 | void ieee80211_clear_tx_pending(struct ieee80211_local *local) |
1661 | { | |
1662 | int i, j; | |
1663 | struct ieee80211_tx_stored_packet *store; | |
1664 | ||
e2530083 JB |
1665 | for (i = 0; i < ieee80211_num_regular_queues(&local->hw); i++) { |
1666 | if (!test_bit(i, local->queues_pending)) | |
e2ebc74d JB |
1667 | continue; |
1668 | store = &local->pending_packet[i]; | |
1669 | kfree_skb(store->skb); | |
1670 | for (j = 0; j < store->num_extra_frag; j++) | |
1671 | kfree_skb(store->extra_frag[j]); | |
1672 | kfree(store->extra_frag); | |
e2530083 | 1673 | clear_bit(i, local->queues_pending); |
e2ebc74d JB |
1674 | } |
1675 | } | |
1676 | ||
e2530083 JB |
1677 | /* |
1678 | * Transmit all pending packets. Called from tasklet, locks master device | |
1679 | * TX lock so that no new packets can come in. | |
1680 | */ | |
e2ebc74d JB |
1681 | void ieee80211_tx_pending(unsigned long data) |
1682 | { | |
1683 | struct ieee80211_local *local = (struct ieee80211_local *)data; | |
1684 | struct net_device *dev = local->mdev; | |
1685 | struct ieee80211_tx_stored_packet *store; | |
5cf121c3 | 1686 | struct ieee80211_tx_data tx; |
e2530083 | 1687 | int i, ret; |
e2ebc74d JB |
1688 | |
1689 | netif_tx_lock_bh(dev); | |
e2530083 JB |
1690 | for (i = 0; i < ieee80211_num_regular_queues(&local->hw); i++) { |
1691 | /* Check that this queue is ok */ | |
1692 | if (__netif_subqueue_stopped(local->mdev, i)) | |
e2ebc74d | 1693 | continue; |
e2530083 JB |
1694 | |
1695 | if (!test_bit(i, local->queues_pending)) { | |
1696 | ieee80211_wake_queue(&local->hw, i); | |
e2ebc74d JB |
1697 | continue; |
1698 | } | |
e2530083 | 1699 | |
e2ebc74d | 1700 | store = &local->pending_packet[i]; |
5cf121c3 JB |
1701 | tx.extra_frag = store->extra_frag; |
1702 | tx.num_extra_frag = store->num_extra_frag; | |
2e92e6f2 | 1703 | tx.last_frag_rate_idx = store->last_frag_rate_idx; |
badffb72 JS |
1704 | tx.flags = 0; |
1705 | if (store->last_frag_rate_ctrl_probe) | |
5cf121c3 | 1706 | tx.flags |= IEEE80211_TX_PROBE_LAST_FRAG; |
e2ebc74d JB |
1707 | ret = __ieee80211_tx(local, store->skb, &tx); |
1708 | if (ret) { | |
1709 | if (ret == IEEE80211_TX_FRAG_AGAIN) | |
1710 | store->skb = NULL; | |
1711 | } else { | |
e2530083 JB |
1712 | clear_bit(i, local->queues_pending); |
1713 | ieee80211_wake_queue(&local->hw, i); | |
e2ebc74d JB |
1714 | } |
1715 | } | |
1716 | netif_tx_unlock_bh(dev); | |
e2ebc74d JB |
1717 | } |
1718 | ||
1719 | /* functions for drivers to get certain frames */ | |
1720 | ||
1721 | static void ieee80211_beacon_add_tim(struct ieee80211_local *local, | |
1722 | struct ieee80211_if_ap *bss, | |
5dfdaf58 JB |
1723 | struct sk_buff *skb, |
1724 | struct beacon_data *beacon) | |
e2ebc74d JB |
1725 | { |
1726 | u8 *pos, *tim; | |
1727 | int aid0 = 0; | |
1728 | int i, have_bits = 0, n1, n2; | |
1729 | ||
1730 | /* Generate bitmap for TIM only if there are any STAs in power save | |
1731 | * mode. */ | |
e2ebc74d JB |
1732 | if (atomic_read(&bss->num_sta_ps) > 0) |
1733 | /* in the hope that this is faster than | |
1734 | * checking byte-for-byte */ | |
1735 | have_bits = !bitmap_empty((unsigned long*)bss->tim, | |
1736 | IEEE80211_MAX_AID+1); | |
1737 | ||
1738 | if (bss->dtim_count == 0) | |
5dfdaf58 | 1739 | bss->dtim_count = beacon->dtim_period - 1; |
e2ebc74d JB |
1740 | else |
1741 | bss->dtim_count--; | |
1742 | ||
1743 | tim = pos = (u8 *) skb_put(skb, 6); | |
1744 | *pos++ = WLAN_EID_TIM; | |
1745 | *pos++ = 4; | |
1746 | *pos++ = bss->dtim_count; | |
5dfdaf58 | 1747 | *pos++ = beacon->dtim_period; |
e2ebc74d JB |
1748 | |
1749 | if (bss->dtim_count == 0 && !skb_queue_empty(&bss->ps_bc_buf)) | |
1750 | aid0 = 1; | |
1751 | ||
1752 | if (have_bits) { | |
1753 | /* Find largest even number N1 so that bits numbered 1 through | |
1754 | * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits | |
1755 | * (N2 + 1) x 8 through 2007 are 0. */ | |
1756 | n1 = 0; | |
1757 | for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) { | |
1758 | if (bss->tim[i]) { | |
1759 | n1 = i & 0xfe; | |
1760 | break; | |
1761 | } | |
1762 | } | |
1763 | n2 = n1; | |
1764 | for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) { | |
1765 | if (bss->tim[i]) { | |
1766 | n2 = i; | |
1767 | break; | |
1768 | } | |
1769 | } | |
1770 | ||
1771 | /* Bitmap control */ | |
1772 | *pos++ = n1 | aid0; | |
1773 | /* Part Virt Bitmap */ | |
1774 | memcpy(pos, bss->tim + n1, n2 - n1 + 1); | |
1775 | ||
1776 | tim[1] = n2 - n1 + 4; | |
1777 | skb_put(skb, n2 - n1); | |
1778 | } else { | |
1779 | *pos++ = aid0; /* Bitmap control */ | |
1780 | *pos++ = 0; /* Part Virt Bitmap */ | |
1781 | } | |
e2ebc74d JB |
1782 | } |
1783 | ||
32bfd35d | 1784 | struct sk_buff *ieee80211_beacon_get(struct ieee80211_hw *hw, |
e039fa4a | 1785 | struct ieee80211_vif *vif) |
e2ebc74d JB |
1786 | { |
1787 | struct ieee80211_local *local = hw_to_local(hw); | |
1788 | struct sk_buff *skb; | |
e039fa4a | 1789 | struct ieee80211_tx_info *info; |
e2ebc74d JB |
1790 | struct net_device *bdev; |
1791 | struct ieee80211_sub_if_data *sdata = NULL; | |
1792 | struct ieee80211_if_ap *ap = NULL; | |
1abbe498 | 1793 | struct rate_selection rsel; |
5dfdaf58 | 1794 | struct beacon_data *beacon; |
8318d78a | 1795 | struct ieee80211_supported_band *sband; |
902acc78 | 1796 | struct ieee80211_mgmt *mgmt; |
33b64eb2 | 1797 | int *num_beacons; |
902acc78 | 1798 | bool err = true; |
2e92e6f2 | 1799 | enum ieee80211_band band = local->hw.conf.channel->band; |
902acc78 | 1800 | u8 *pos; |
8318d78a | 1801 | |
2e92e6f2 | 1802 | sband = local->hw.wiphy->bands[band]; |
5dfdaf58 JB |
1803 | |
1804 | rcu_read_lock(); | |
e2ebc74d | 1805 | |
32bfd35d JB |
1806 | sdata = vif_to_sdata(vif); |
1807 | bdev = sdata->dev; | |
e2ebc74d | 1808 | |
902acc78 | 1809 | if (sdata->vif.type == IEEE80211_IF_TYPE_AP) { |
33b64eb2 LCC |
1810 | ap = &sdata->u.ap; |
1811 | beacon = rcu_dereference(ap->beacon); | |
902acc78 JB |
1812 | if (ap && beacon) { |
1813 | /* | |
1814 | * headroom, head length, | |
1815 | * tail length and maximum TIM length | |
1816 | */ | |
1817 | skb = dev_alloc_skb(local->tx_headroom + | |
1818 | beacon->head_len + | |
1819 | beacon->tail_len + 256); | |
1820 | if (!skb) | |
1821 | goto out; | |
33b64eb2 | 1822 | |
902acc78 JB |
1823 | skb_reserve(skb, local->tx_headroom); |
1824 | memcpy(skb_put(skb, beacon->head_len), beacon->head, | |
1825 | beacon->head_len); | |
33b64eb2 | 1826 | |
902acc78 JB |
1827 | ieee80211_include_sequence(sdata, |
1828 | (struct ieee80211_hdr *)skb->data); | |
33b64eb2 | 1829 | |
d0709a65 JB |
1830 | /* |
1831 | * Not very nice, but we want to allow the driver to call | |
1832 | * ieee80211_beacon_get() as a response to the set_tim() | |
1833 | * callback. That, however, is already invoked under the | |
1834 | * sta_lock to guarantee consistent and race-free update | |
1835 | * of the tim bitmap in mac80211 and the driver. | |
1836 | */ | |
1837 | if (local->tim_in_locked_section) { | |
1838 | ieee80211_beacon_add_tim(local, ap, skb, beacon); | |
1839 | } else { | |
1840 | unsigned long flags; | |
1841 | ||
1842 | spin_lock_irqsave(&local->sta_lock, flags); | |
1843 | ieee80211_beacon_add_tim(local, ap, skb, beacon); | |
1844 | spin_unlock_irqrestore(&local->sta_lock, flags); | |
1845 | } | |
33b64eb2 | 1846 | |
902acc78 JB |
1847 | if (beacon->tail) |
1848 | memcpy(skb_put(skb, beacon->tail_len), | |
1849 | beacon->tail, beacon->tail_len); | |
33b64eb2 | 1850 | |
902acc78 | 1851 | num_beacons = &ap->num_beacons; |
33b64eb2 | 1852 | |
902acc78 JB |
1853 | err = false; |
1854 | } | |
1855 | } else if (ieee80211_vif_is_mesh(&sdata->vif)) { | |
1856 | /* headroom, head length, tail length and maximum TIM length */ | |
1857 | skb = dev_alloc_skb(local->tx_headroom + 400); | |
1858 | if (!skb) | |
1859 | goto out; | |
1860 | ||
1861 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
1862 | mgmt = (struct ieee80211_mgmt *) | |
1863 | skb_put(skb, 24 + sizeof(mgmt->u.beacon)); | |
1864 | memset(mgmt, 0, 24 + sizeof(mgmt->u.beacon)); | |
1865 | mgmt->frame_control = IEEE80211_FC(IEEE80211_FTYPE_MGMT, | |
1866 | IEEE80211_STYPE_BEACON); | |
1867 | memset(mgmt->da, 0xff, ETH_ALEN); | |
1868 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); | |
1869 | /* BSSID is left zeroed, wildcard value */ | |
1870 | mgmt->u.beacon.beacon_int = | |
1871 | cpu_to_le16(local->hw.conf.beacon_int); | |
1872 | mgmt->u.beacon.capab_info = 0x0; /* 0x0 for MPs */ | |
1873 | ||
1874 | pos = skb_put(skb, 2); | |
1875 | *pos++ = WLAN_EID_SSID; | |
1876 | *pos++ = 0x0; | |
1877 | ||
1878 | mesh_mgmt_ies_add(skb, sdata->dev); | |
33b64eb2 | 1879 | |
33b64eb2 | 1880 | num_beacons = &sdata->u.sta.num_beacons; |
33b64eb2 | 1881 | |
902acc78 | 1882 | err = false; |
33b64eb2 | 1883 | } |
5dfdaf58 | 1884 | |
33b64eb2 | 1885 | if (err) { |
e2ebc74d JB |
1886 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
1887 | if (net_ratelimit()) | |
32bfd35d JB |
1888 | printk(KERN_DEBUG "no beacon data avail for %s\n", |
1889 | bdev->name); | |
e2ebc74d | 1890 | #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */ |
5dfdaf58 JB |
1891 | skb = NULL; |
1892 | goto out; | |
e2ebc74d JB |
1893 | } |
1894 | ||
e039fa4a JB |
1895 | info = IEEE80211_SKB_CB(skb); |
1896 | ||
1897 | info->band = band; | |
1898 | rate_control_get_rate(local->mdev, sband, skb, &rsel); | |
e2ebc74d | 1899 | |
e039fa4a JB |
1900 | if (unlikely(rsel.rate_idx < 0)) { |
1901 | if (net_ratelimit()) { | |
1902 | printk(KERN_DEBUG "%s: ieee80211_beacon_get: " | |
1903 | "no rate found\n", | |
1904 | wiphy_name(local->hw.wiphy)); | |
1905 | } | |
1906 | dev_kfree_skb(skb); | |
1907 | skb = NULL; | |
1908 | goto out; | |
e2ebc74d | 1909 | } |
e039fa4a JB |
1910 | |
1911 | info->control.vif = vif; | |
1912 | info->tx_rate_idx = rsel.rate_idx; | |
1913 | if (sdata->bss_conf.use_short_preamble && | |
1914 | sband->bitrates[rsel.rate_idx].flags & IEEE80211_RATE_SHORT_PREAMBLE) | |
1915 | info->flags |= IEEE80211_TX_CTL_SHORT_PREAMBLE; | |
1916 | info->antenna_sel_tx = local->hw.conf.antenna_sel_tx; | |
1917 | info->flags |= IEEE80211_TX_CTL_NO_ACK; | |
1918 | info->flags |= IEEE80211_TX_CTL_DO_NOT_ENCRYPT; | |
1919 | info->control.retry_limit = 1; | |
1920 | info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; | |
33b64eb2 LCC |
1921 | (*num_beacons)++; |
1922 | out: | |
5dfdaf58 | 1923 | rcu_read_unlock(); |
e2ebc74d JB |
1924 | return skb; |
1925 | } | |
1926 | EXPORT_SYMBOL(ieee80211_beacon_get); | |
1927 | ||
32bfd35d | 1928 | void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
e2ebc74d | 1929 | const void *frame, size_t frame_len, |
e039fa4a | 1930 | const struct ieee80211_tx_info *frame_txctl, |
e2ebc74d JB |
1931 | struct ieee80211_rts *rts) |
1932 | { | |
1933 | const struct ieee80211_hdr *hdr = frame; | |
1934 | u16 fctl; | |
1935 | ||
1936 | fctl = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS; | |
1937 | rts->frame_control = cpu_to_le16(fctl); | |
32bfd35d JB |
1938 | rts->duration = ieee80211_rts_duration(hw, vif, frame_len, |
1939 | frame_txctl); | |
e2ebc74d JB |
1940 | memcpy(rts->ra, hdr->addr1, sizeof(rts->ra)); |
1941 | memcpy(rts->ta, hdr->addr2, sizeof(rts->ta)); | |
1942 | } | |
1943 | EXPORT_SYMBOL(ieee80211_rts_get); | |
1944 | ||
32bfd35d | 1945 | void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
e2ebc74d | 1946 | const void *frame, size_t frame_len, |
e039fa4a | 1947 | const struct ieee80211_tx_info *frame_txctl, |
e2ebc74d JB |
1948 | struct ieee80211_cts *cts) |
1949 | { | |
1950 | const struct ieee80211_hdr *hdr = frame; | |
1951 | u16 fctl; | |
1952 | ||
1953 | fctl = IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS; | |
1954 | cts->frame_control = cpu_to_le16(fctl); | |
32bfd35d JB |
1955 | cts->duration = ieee80211_ctstoself_duration(hw, vif, |
1956 | frame_len, frame_txctl); | |
e2ebc74d JB |
1957 | memcpy(cts->ra, hdr->addr1, sizeof(cts->ra)); |
1958 | } | |
1959 | EXPORT_SYMBOL(ieee80211_ctstoself_get); | |
1960 | ||
1961 | struct sk_buff * | |
32bfd35d | 1962 | ieee80211_get_buffered_bc(struct ieee80211_hw *hw, |
e039fa4a | 1963 | struct ieee80211_vif *vif) |
e2ebc74d JB |
1964 | { |
1965 | struct ieee80211_local *local = hw_to_local(hw); | |
1966 | struct sk_buff *skb; | |
1967 | struct sta_info *sta; | |
1968 | ieee80211_tx_handler *handler; | |
5cf121c3 | 1969 | struct ieee80211_tx_data tx; |
9ae54c84 | 1970 | ieee80211_tx_result res = TX_DROP; |
e2ebc74d JB |
1971 | struct net_device *bdev; |
1972 | struct ieee80211_sub_if_data *sdata; | |
1973 | struct ieee80211_if_ap *bss = NULL; | |
5dfdaf58 | 1974 | struct beacon_data *beacon; |
e039fa4a | 1975 | struct ieee80211_tx_info *info; |
e2ebc74d | 1976 | |
32bfd35d JB |
1977 | sdata = vif_to_sdata(vif); |
1978 | bdev = sdata->dev; | |
1979 | ||
5dfdaf58 JB |
1980 | |
1981 | if (!bss) | |
e2ebc74d JB |
1982 | return NULL; |
1983 | ||
5dfdaf58 JB |
1984 | rcu_read_lock(); |
1985 | beacon = rcu_dereference(bss->beacon); | |
1986 | ||
1987 | if (sdata->vif.type != IEEE80211_IF_TYPE_AP || !beacon || | |
1988 | !beacon->head) { | |
1989 | rcu_read_unlock(); | |
1990 | return NULL; | |
1991 | } | |
5dfdaf58 | 1992 | |
e2ebc74d JB |
1993 | if (bss->dtim_count != 0) |
1994 | return NULL; /* send buffered bc/mc only after DTIM beacon */ | |
e039fa4a | 1995 | |
e2ebc74d JB |
1996 | while (1) { |
1997 | skb = skb_dequeue(&bss->ps_bc_buf); | |
1998 | if (!skb) | |
1999 | return NULL; | |
2000 | local->total_ps_buffered--; | |
2001 | ||
2002 | if (!skb_queue_empty(&bss->ps_bc_buf) && skb->len >= 2) { | |
2003 | struct ieee80211_hdr *hdr = | |
2004 | (struct ieee80211_hdr *) skb->data; | |
2005 | /* more buffered multicast/broadcast frames ==> set | |
2006 | * MoreData flag in IEEE 802.11 header to inform PS | |
2007 | * STAs */ | |
2008 | hdr->frame_control |= | |
2009 | cpu_to_le16(IEEE80211_FCTL_MOREDATA); | |
2010 | } | |
2011 | ||
e039fa4a | 2012 | if (!ieee80211_tx_prepare(&tx, skb, local->mdev)) |
e2ebc74d JB |
2013 | break; |
2014 | dev_kfree_skb_any(skb); | |
2015 | } | |
e039fa4a JB |
2016 | |
2017 | info = IEEE80211_SKB_CB(skb); | |
2018 | ||
e2ebc74d | 2019 | sta = tx.sta; |
5cf121c3 JB |
2020 | tx.flags |= IEEE80211_TX_PS_BUFFERED; |
2021 | tx.channel = local->hw.conf.channel; | |
e039fa4a | 2022 | info->band = tx.channel->band; |
e2ebc74d | 2023 | |
58905290 | 2024 | for (handler = ieee80211_tx_handlers; *handler != NULL; handler++) { |
e2ebc74d | 2025 | res = (*handler)(&tx); |
9ae54c84 | 2026 | if (res == TX_DROP || res == TX_QUEUED) |
e2ebc74d JB |
2027 | break; |
2028 | } | |
e039fa4a JB |
2029 | |
2030 | if (WARN_ON(tx.skb != skb)) | |
2031 | return NULL; | |
e2ebc74d | 2032 | |
9ae54c84 | 2033 | if (res == TX_DROP) { |
e2ebc74d JB |
2034 | I802_DEBUG_INC(local->tx_handlers_drop); |
2035 | dev_kfree_skb(skb); | |
2036 | skb = NULL; | |
9ae54c84 | 2037 | } else if (res == TX_QUEUED) { |
e2ebc74d JB |
2038 | I802_DEBUG_INC(local->tx_handlers_queued); |
2039 | skb = NULL; | |
2040 | } | |
2041 | ||
d0709a65 | 2042 | rcu_read_unlock(); |
e2ebc74d JB |
2043 | |
2044 | return skb; | |
2045 | } | |
2046 | EXPORT_SYMBOL(ieee80211_get_buffered_bc); |