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