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