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