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