Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 4 | * Copyright 2005-2006, Devicescape Software, Inc. |
| 5 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 6 | * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> |
Johannes Berg | d98ad83 | 2014-09-03 15:24:57 +0300 | [diff] [blame] | 7 | * Copyright 2013-2014 Intel Mobile Communications GmbH |
Johannes Berg | ca98c47 | 2020-02-21 10:45:45 +0100 | [diff] [blame] | 8 | * Copyright (C) 2018-2020 Intel Corporation |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 9 | * |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 10 | * Transmit and frame generation functions. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/kernel.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/skbuff.h> |
Michael Braun | ebceec8 | 2016-11-22 11:52:18 +0100 | [diff] [blame] | 16 | #include <linux/if_vlan.h> |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 17 | #include <linux/etherdevice.h> |
| 18 | #include <linux/bitmap.h> |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 19 | #include <linux/rcupdate.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 20 | #include <linux/export.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> |
Michal Kazior | 5caa328 | 2016-05-19 10:37:51 +0200 | [diff] [blame] | 25 | #include <net/codel.h> |
| 26 | #include <net/codel_impl.h> |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 27 | #include <asm/unaligned.h> |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 28 | #include <net/fq_impl.h> |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 29 | |
| 30 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 31 | #include "driver-ops.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 32 | #include "led.h" |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 33 | #include "mesh.h" |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 34 | #include "wep.h" |
| 35 | #include "wpa.h" |
| 36 | #include "wme.h" |
Johannes Berg | 2c8dccc | 2008-04-08 15:14:40 -0400 | [diff] [blame] | 37 | #include "rate.h" |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 38 | |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 39 | /* misc utils */ |
| 40 | |
Johannes Berg | 5a49051 | 2015-04-22 17:10:38 +0200 | [diff] [blame] | 41 | static inline void ieee80211_tx_stats(struct net_device *dev, u32 len) |
| 42 | { |
| 43 | struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats); |
| 44 | |
| 45 | u64_stats_update_begin(&tstats->syncp); |
| 46 | tstats->tx_packets++; |
| 47 | tstats->tx_bytes += len; |
| 48 | u64_stats_update_end(&tstats->syncp); |
| 49 | } |
| 50 | |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 51 | static __le16 ieee80211_duration(struct ieee80211_tx_data *tx, |
| 52 | struct sk_buff *skb, int group_addr, |
Johannes Berg | 03f93c3 | 2008-06-25 14:36:27 +0300 | [diff] [blame] | 53 | int next_frag_len) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 54 | { |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 55 | int rate, mrate, erp, dur, i, shift = 0; |
Johannes Berg | 2e92e6f | 2008-05-15 12:55:27 +0200 | [diff] [blame] | 56 | struct ieee80211_rate *txrate; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 57 | struct ieee80211_local *local = tx->local; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 58 | struct ieee80211_supported_band *sband; |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 59 | struct ieee80211_hdr *hdr; |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 60 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 61 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 62 | u32 rate_flags = 0; |
| 63 | |
Felix Fietkau | 95cd470 | 2016-12-14 20:46:57 +0100 | [diff] [blame] | 64 | /* assume HW handles this */ |
| 65 | if (tx->rate.flags & (IEEE80211_TX_RC_MCS | IEEE80211_TX_RC_VHT_MCS)) |
| 66 | return 0; |
| 67 | |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 68 | rcu_read_lock(); |
| 69 | chanctx_conf = rcu_dereference(tx->sdata->vif.chanctx_conf); |
| 70 | if (chanctx_conf) { |
| 71 | shift = ieee80211_chandef_get_shift(&chanctx_conf->def); |
| 72 | rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def); |
| 73 | } |
| 74 | rcu_read_unlock(); |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 75 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 76 | /* uh huh? */ |
Felix Fietkau | 0d528d8 | 2013-04-22 16:14:41 +0200 | [diff] [blame] | 77 | if (WARN_ON_ONCE(tx->rate.idx < 0)) |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 78 | return 0; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 79 | |
Johannes Berg | 2d56577 | 2012-07-23 15:12:51 +0200 | [diff] [blame] | 80 | sband = local->hw.wiphy->bands[info->band]; |
Felix Fietkau | 0d528d8 | 2013-04-22 16:14:41 +0200 | [diff] [blame] | 81 | txrate = &sband->bitrates[tx->rate.idx]; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 82 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 83 | erp = txrate->flags & IEEE80211_RATE_ERP_G; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 84 | |
| 85 | /* |
| 86 | * data and mgmt (except PS Poll): |
| 87 | * - during CFP: 32768 |
| 88 | * - during contention period: |
| 89 | * if addr1 is group address: 0 |
| 90 | * if more fragments = 0 and addr1 is individual address: time to |
| 91 | * transmit one ACK plus SIFS |
| 92 | * if more fragments = 1 and addr1 is individual address: time to |
| 93 | * transmit next fragment plus 2 x ACK plus 3 x SIFS |
| 94 | * |
| 95 | * IEEE 802.11, 9.6: |
| 96 | * - control response frame (CTS or ACK) shall be transmitted using the |
| 97 | * same rate as the immediately previous frame in the frame exchange |
| 98 | * sequence, if this rate belongs to the PHY mandatory rates, or else |
| 99 | * at the highest possible rate belonging to the PHY rates in the |
| 100 | * BSSBasicRateSet |
| 101 | */ |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 102 | hdr = (struct ieee80211_hdr *)skb->data; |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 103 | if (ieee80211_is_ctl(hdr->frame_control)) { |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 104 | /* TODO: These control frames are not currently sent by |
Johannes Berg | ccd7b36 | 2008-09-11 00:01:56 +0200 | [diff] [blame] | 105 | * mac80211, but should they be implemented, this function |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 106 | * needs to be updated to support duration field calculation. |
| 107 | * |
| 108 | * RTS: time needed to transmit pending data/mgmt frame plus |
| 109 | * one CTS frame plus one ACK frame plus 3 x SIFS |
| 110 | * CTS: duration of immediately previous RTS minus time |
| 111 | * required to transmit CTS and its SIFS |
| 112 | * ACK: 0 if immediately previous directed data/mgmt had |
| 113 | * more=0, with more=1 duration in ACK frame is duration |
| 114 | * from previous frame minus time needed to transmit ACK |
| 115 | * and its SIFS |
| 116 | * PS Poll: BIT(15) | BIT(14) | aid |
| 117 | */ |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | /* data/mgmt */ |
| 122 | if (0 /* FIX: data/mgmt during CFP */) |
Johannes Berg | 03f93c3 | 2008-06-25 14:36:27 +0300 | [diff] [blame] | 123 | return cpu_to_le16(32768); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 124 | |
| 125 | if (group_addr) /* Group address as the destination - no ACK */ |
| 126 | return 0; |
| 127 | |
| 128 | /* Individual destination address: |
| 129 | * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes) |
| 130 | * CTS and ACK frames shall be transmitted using the highest rate in |
| 131 | * basic rate set that is less than or equal to the rate of the |
| 132 | * immediately previous frame and that is using the same modulation |
| 133 | * (CCK or OFDM). If no basic rate set matches with these requirements, |
| 134 | * the highest mandatory rate of the PHY that is less than or equal to |
| 135 | * the rate of the previous frame is used. |
| 136 | * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps |
| 137 | */ |
| 138 | rate = -1; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 139 | /* use lowest available if everything fails */ |
| 140 | mrate = sband->bitrates[0].bitrate; |
| 141 | for (i = 0; i < sband->n_bitrates; i++) { |
| 142 | struct ieee80211_rate *r = &sband->bitrates[i]; |
| 143 | |
| 144 | if (r->bitrate > txrate->bitrate) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 145 | break; |
| 146 | |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 147 | if ((rate_flags & r->flags) != rate_flags) |
| 148 | continue; |
| 149 | |
Johannes Berg | bda3933 | 2008-10-11 01:51:51 +0200 | [diff] [blame] | 150 | if (tx->sdata->vif.bss_conf.basic_rates & BIT(i)) |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 151 | rate = DIV_ROUND_UP(r->bitrate, 1 << shift); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 152 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 153 | switch (sband->band) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 154 | case NL80211_BAND_2GHZ: { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 155 | u32 flag; |
| 156 | if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) |
| 157 | flag = IEEE80211_RATE_MANDATORY_G; |
| 158 | else |
| 159 | flag = IEEE80211_RATE_MANDATORY_B; |
| 160 | if (r->flags & flag) |
| 161 | mrate = r->bitrate; |
| 162 | break; |
| 163 | } |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 164 | case NL80211_BAND_5GHZ: |
Arend van Spriel | c5b9a7f | 2019-08-02 13:30:58 +0200 | [diff] [blame] | 165 | case NL80211_BAND_6GHZ: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 166 | if (r->flags & IEEE80211_RATE_MANDATORY_A) |
| 167 | mrate = r->bitrate; |
| 168 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 169 | case NL80211_BAND_60GHZ: |
Vladimir Kondratiev | 3a0c52a | 2012-07-02 09:32:32 +0300 | [diff] [blame] | 170 | /* TODO, for now fall through */ |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 171 | case NUM_NL80211_BANDS: |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 172 | WARN_ON(1); |
| 173 | break; |
| 174 | } |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 175 | } |
| 176 | if (rate == -1) { |
| 177 | /* No matching basic rate found; use highest suitable mandatory |
| 178 | * PHY rate */ |
Simon Wunderlich | 2103dec | 2013-07-08 16:55:53 +0200 | [diff] [blame] | 179 | rate = DIV_ROUND_UP(mrate, 1 << shift); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 180 | } |
| 181 | |
Simon Wunderlich | 6674f21 | 2011-11-21 21:34:30 +0100 | [diff] [blame] | 182 | /* Don't calculate ACKs for QoS Frames with NoAck Policy set */ |
| 183 | if (ieee80211_is_data_qos(hdr->frame_control) && |
Claudio Pisa | c26a0e1 | 2012-05-28 13:06:25 +0100 | [diff] [blame] | 184 | *(ieee80211_get_qos_ctl(hdr)) & IEEE80211_QOS_CTL_ACK_POLICY_NOACK) |
Simon Wunderlich | 6674f21 | 2011-11-21 21:34:30 +0100 | [diff] [blame] | 185 | dur = 0; |
| 186 | else |
| 187 | /* Time needed to transmit ACK |
| 188 | * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up |
| 189 | * to closest integer */ |
Michal Kazior | 4ee73f3 | 2012-04-11 08:47:56 +0200 | [diff] [blame] | 190 | dur = ieee80211_frame_duration(sband->band, 10, rate, erp, |
Simon Wunderlich | 438b61b | 2013-07-08 16:55:51 +0200 | [diff] [blame] | 191 | tx->sdata->vif.bss_conf.use_short_preamble, |
| 192 | shift); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 193 | |
| 194 | if (next_frag_len) { |
| 195 | /* Frame is fragmented: duration increases with time needed to |
| 196 | * transmit next fragment plus ACK and 2 x SIFS. */ |
| 197 | dur *= 2; /* ACK + SIFS */ |
| 198 | /* next fragment */ |
Michal Kazior | 4ee73f3 | 2012-04-11 08:47:56 +0200 | [diff] [blame] | 199 | dur += ieee80211_frame_duration(sband->band, next_frag_len, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 200 | txrate->bitrate, erp, |
Simon Wunderlich | 438b61b | 2013-07-08 16:55:51 +0200 | [diff] [blame] | 201 | tx->sdata->vif.bss_conf.use_short_preamble, |
| 202 | shift); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 203 | } |
| 204 | |
Johannes Berg | 03f93c3 | 2008-06-25 14:36:27 +0300 | [diff] [blame] | 205 | return cpu_to_le16(dur); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 206 | } |
| 207 | |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 208 | /* tx handlers */ |
Kalle Valo | 5c1b98a | 2010-01-12 10:42:46 +0200 | [diff] [blame] | 209 | static ieee80211_tx_result debug_noinline |
| 210 | ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx) |
| 211 | { |
| 212 | struct ieee80211_local *local = tx->local; |
Kalle Valo | 0c74211 | 2010-01-12 10:42:53 +0200 | [diff] [blame] | 213 | struct ieee80211_if_managed *ifmgd; |
Andrei Otcheretianski | 94a5b3a | 2018-09-05 08:06:14 +0300 | [diff] [blame] | 214 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
Kalle Valo | 5c1b98a | 2010-01-12 10:42:46 +0200 | [diff] [blame] | 215 | |
| 216 | /* driver doesn't support power save */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 217 | if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) |
Kalle Valo | 5c1b98a | 2010-01-12 10:42:46 +0200 | [diff] [blame] | 218 | return TX_CONTINUE; |
| 219 | |
| 220 | /* hardware does dynamic power save */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 221 | if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) |
Kalle Valo | 5c1b98a | 2010-01-12 10:42:46 +0200 | [diff] [blame] | 222 | return TX_CONTINUE; |
| 223 | |
| 224 | /* dynamic power save disabled */ |
| 225 | if (local->hw.conf.dynamic_ps_timeout <= 0) |
| 226 | return TX_CONTINUE; |
| 227 | |
| 228 | /* we are scanning, don't enable power save */ |
| 229 | if (local->scanning) |
| 230 | return TX_CONTINUE; |
| 231 | |
| 232 | if (!local->ps_sdata) |
| 233 | return TX_CONTINUE; |
| 234 | |
| 235 | /* No point if we're going to suspend */ |
| 236 | if (local->quiescing) |
| 237 | return TX_CONTINUE; |
| 238 | |
Kalle Valo | 0c74211 | 2010-01-12 10:42:53 +0200 | [diff] [blame] | 239 | /* dynamic ps is supported only in managed mode */ |
| 240 | if (tx->sdata->vif.type != NL80211_IFTYPE_STATION) |
| 241 | return TX_CONTINUE; |
| 242 | |
Andrei Otcheretianski | 94a5b3a | 2018-09-05 08:06:14 +0300 | [diff] [blame] | 243 | if (unlikely(info->flags & IEEE80211_TX_INTFL_OFFCHAN_TX_OK)) |
| 244 | return TX_CONTINUE; |
| 245 | |
Kalle Valo | 0c74211 | 2010-01-12 10:42:53 +0200 | [diff] [blame] | 246 | ifmgd = &tx->sdata->u.mgd; |
| 247 | |
| 248 | /* |
| 249 | * Don't wakeup from power save if u-apsd is enabled, voip ac has |
| 250 | * u-apsd enabled and the frame is in voip class. This effectively |
| 251 | * means that even if all access categories have u-apsd enabled, in |
| 252 | * practise u-apsd is only used with the voip ac. This is a |
| 253 | * workaround for the case when received voip class packets do not |
| 254 | * have correct qos tag for some reason, due the network or the |
| 255 | * peer application. |
| 256 | * |
Eliad Peller | dc41e4d | 2012-03-14 16:15:03 +0200 | [diff] [blame] | 257 | * Note: ifmgd->uapsd_queues access is racy here. If the value is |
Kalle Valo | 0c74211 | 2010-01-12 10:42:53 +0200 | [diff] [blame] | 258 | * changed via debugfs, user needs to reassociate manually to have |
| 259 | * everything in sync. |
| 260 | */ |
Johannes Berg | 4875d30d | 2012-03-27 14:18:37 +0200 | [diff] [blame] | 261 | if ((ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) && |
| 262 | (ifmgd->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) && |
| 263 | skb_get_queue_mapping(tx->skb) == IEEE80211_AC_VO) |
Kalle Valo | 0c74211 | 2010-01-12 10:42:53 +0200 | [diff] [blame] | 264 | return TX_CONTINUE; |
| 265 | |
Kalle Valo | 5c1b98a | 2010-01-12 10:42:46 +0200 | [diff] [blame] | 266 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { |
| 267 | ieee80211_stop_queues_by_reason(&local->hw, |
Johannes Berg | 445ea4e | 2013-02-13 12:25:28 +0100 | [diff] [blame] | 268 | IEEE80211_MAX_QUEUE_MAP, |
Luciano Coelho | cca07b0 | 2014-06-13 16:30:05 +0300 | [diff] [blame] | 269 | IEEE80211_QUEUE_STOP_REASON_PS, |
| 270 | false); |
Vivek Natarajan | db28569 | 2011-02-18 17:18:03 +0530 | [diff] [blame] | 271 | ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED; |
Kalle Valo | 5c1b98a | 2010-01-12 10:42:46 +0200 | [diff] [blame] | 272 | ieee80211_queue_work(&local->hw, |
| 273 | &local->dynamic_ps_disable_work); |
| 274 | } |
| 275 | |
Luciano Coelho | 5db1c07 | 2011-05-03 21:40:08 +0300 | [diff] [blame] | 276 | /* Don't restart the timer if we're not disassociated */ |
| 277 | if (!ifmgd->associated) |
| 278 | return TX_CONTINUE; |
| 279 | |
Kalle Valo | 5c1b98a | 2010-01-12 10:42:46 +0200 | [diff] [blame] | 280 | mod_timer(&local->dynamic_ps_timer, jiffies + |
| 281 | msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout)); |
| 282 | |
| 283 | return TX_CONTINUE; |
| 284 | } |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 285 | |
Johannes Berg | d9e8a70 | 2008-06-30 15:10:44 +0200 | [diff] [blame] | 286 | static ieee80211_tx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 287 | ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 288 | { |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 289 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 290 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 291 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 292 | bool assoc = false; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 293 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 294 | if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 295 | return TX_CONTINUE; |
Johannes Berg | 58d4185 | 2007-09-26 17:53:18 +0200 | [diff] [blame] | 296 | |
Ben Greear | b23b025 | 2011-02-04 11:54:17 -0800 | [diff] [blame] | 297 | if (unlikely(test_bit(SCAN_SW_SCANNING, &tx->local->scanning)) && |
| 298 | test_bit(SDATA_STATE_OFFCHANNEL, &tx->sdata->state) && |
Kalle Valo | a9a6fff | 2009-03-18 14:06:44 +0200 | [diff] [blame] | 299 | !ieee80211_is_probe_req(hdr->frame_control) && |
Thomas Pedersen | 30b2f0b | 2020-01-13 21:59:40 -0800 | [diff] [blame] | 300 | !ieee80211_is_any_nullfunc(hdr->frame_control)) |
Kalle Valo | a9a6fff | 2009-03-18 14:06:44 +0200 | [diff] [blame] | 301 | /* |
| 302 | * When software scanning only nullfunc frames (to notify |
| 303 | * the sleep state to the AP) and probe requests (for the |
| 304 | * active scan) are allowed, all other frames should not be |
| 305 | * sent and we should not get here, but if we do |
| 306 | * nonetheless, drop them to avoid sending them |
| 307 | * off-channel. See the link below and |
| 308 | * ieee80211_start_scan() for more. |
| 309 | * |
| 310 | * http://article.gmane.org/gmane.linux.kernel.wireless.general/30089 |
| 311 | */ |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 312 | return TX_DROP; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 313 | |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 314 | if (tx->sdata->vif.type == NL80211_IFTYPE_OCB) |
| 315 | return TX_CONTINUE; |
| 316 | |
Bill Jordan | 1be7fe8 | 2010-10-01 11:20:41 -0400 | [diff] [blame] | 317 | if (tx->sdata->vif.type == NL80211_IFTYPE_WDS) |
| 318 | return TX_CONTINUE; |
| 319 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 320 | if (tx->flags & IEEE80211_TX_PS_BUFFERED) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 321 | return TX_CONTINUE; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 322 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 323 | if (tx->sta) |
| 324 | assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 325 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 326 | if (likely(tx->flags & IEEE80211_TX_UNICAST)) { |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 327 | if (unlikely(!assoc && |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 328 | ieee80211_is_data(hdr->frame_control))) { |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 329 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 330 | sdata_info(tx->sdata, |
| 331 | "dropped data frame to not associated station %pM\n", |
| 332 | hdr->addr1); |
| 333 | #endif |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 334 | I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc); |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 335 | return TX_DROP; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 336 | } |
Michael Braun | 72f15d5 | 2016-10-10 19:12:21 +0200 | [diff] [blame] | 337 | } else if (unlikely(ieee80211_is_data(hdr->frame_control) && |
| 338 | ieee80211_vif_get_num_mcast_if(tx->sdata) == 0)) { |
Johannes Berg | 2962389 | 2011-12-14 12:20:31 +0100 | [diff] [blame] | 339 | /* |
| 340 | * No associated STAs - no need to send multicast |
| 341 | * frames. |
| 342 | */ |
| 343 | return TX_DROP; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 344 | } |
| 345 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 346 | return TX_CONTINUE; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 347 | } |
| 348 | |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 349 | /* This function is called whenever the AP is about to exceed the maximum limit |
| 350 | * of buffered frames for power saving STAs. This situation should not really |
| 351 | * happen often during normal operation, so dropping the oldest buffered packet |
| 352 | * from each queue should be OK to make some room for new frames. */ |
| 353 | static void purge_old_ps_buffers(struct ieee80211_local *local) |
| 354 | { |
| 355 | int total = 0, purged = 0; |
| 356 | struct sk_buff *skb; |
| 357 | struct ieee80211_sub_if_data *sdata; |
| 358 | struct sta_info *sta; |
| 359 | |
Johannes Berg | 7901042 | 2007-09-18 17:29:21 -0400 | [diff] [blame] | 360 | list_for_each_entry_rcu(sdata, &local->interfaces, list) { |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 361 | struct ps_data *ps; |
| 362 | |
| 363 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
| 364 | ps = &sdata->u.ap.ps; |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 365 | else if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 366 | ps = &sdata->u.mesh.ps; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 367 | else |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 368 | continue; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 369 | |
| 370 | skb = skb_dequeue(&ps->bc_buf); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 371 | if (skb) { |
| 372 | purged++; |
Felix Fietkau | 6b07d9c | 2016-08-02 11:13:41 +0200 | [diff] [blame] | 373 | ieee80211_free_txskb(&local->hw, skb); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 374 | } |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 375 | total += skb_queue_len(&ps->bc_buf); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 376 | } |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 377 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 378 | /* |
| 379 | * Drop one frame from each station from the lowest-priority |
| 380 | * AC that has frames at all. |
| 381 | */ |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 382 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 383 | int ac; |
| 384 | |
| 385 | for (ac = IEEE80211_AC_BK; ac >= IEEE80211_AC_VO; ac--) { |
| 386 | skb = skb_dequeue(&sta->ps_tx_buf[ac]); |
| 387 | total += skb_queue_len(&sta->ps_tx_buf[ac]); |
| 388 | if (skb) { |
| 389 | purged++; |
Felix Fietkau | c3e7724 | 2012-10-08 14:39:33 +0200 | [diff] [blame] | 390 | ieee80211_free_txskb(&local->hw, skb); |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 391 | break; |
| 392 | } |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 393 | } |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 394 | } |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 395 | |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 396 | local->total_ps_buffered = total; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 397 | ps_dbg_hw(&local->hw, "PS buffers full - purged %d frames\n", purged); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 398 | } |
| 399 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 400 | static ieee80211_tx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 401 | ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 402 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 403 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 404 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 405 | struct ps_data *ps; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 406 | |
Johannes Berg | 7d54d0dd | 2007-12-19 01:31:25 +0100 | [diff] [blame] | 407 | /* |
| 408 | * broadcast/multicast frame |
| 409 | * |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 410 | * If any of the associated/peer stations is in power save mode, |
Johannes Berg | 7d54d0dd | 2007-12-19 01:31:25 +0100 | [diff] [blame] | 411 | * the frame is buffered to be sent after DTIM beacon frame. |
| 412 | * This is done either by the hardware or us. |
| 413 | */ |
| 414 | |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 415 | /* powersaving STAs currently only in AP/VLAN/mesh mode */ |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 416 | if (tx->sdata->vif.type == NL80211_IFTYPE_AP || |
| 417 | tx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { |
| 418 | if (!tx->sdata->bss) |
| 419 | return TX_CONTINUE; |
| 420 | |
| 421 | ps = &tx->sdata->bss->ps; |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 422 | } else if (ieee80211_vif_is_mesh(&tx->sdata->vif)) { |
| 423 | ps = &tx->sdata->u.mesh.ps; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 424 | } else { |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 425 | return TX_CONTINUE; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 426 | } |
| 427 | |
Johannes Berg | 3e122be | 2008-07-09 14:40:34 +0200 | [diff] [blame] | 428 | |
| 429 | /* no buffering for ordered frames */ |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 430 | if (ieee80211_has_order(hdr->frame_control)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 431 | return TX_CONTINUE; |
Johannes Berg | 7d54d0dd | 2007-12-19 01:31:25 +0100 | [diff] [blame] | 432 | |
Johannes Berg | 08b9939 | 2014-07-07 12:01:11 +0200 | [diff] [blame] | 433 | if (ieee80211_is_probe_req(hdr->frame_control)) |
| 434 | return TX_CONTINUE; |
| 435 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 436 | if (ieee80211_hw_check(&tx->local->hw, QUEUE_CONTROL)) |
Johannes Berg | f4d5794 | 2013-05-28 17:24:15 +0200 | [diff] [blame] | 437 | info->hw_queue = tx->sdata->vif.cab_queue; |
| 438 | |
Felix Fietkau | 9ec1190 | 2018-11-28 22:39:16 +0100 | [diff] [blame] | 439 | /* no stations in PS mode and no buffered packets */ |
| 440 | if (!atomic_read(&ps->num_sta_ps) && skb_queue_empty(&ps->bc_buf)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 441 | return TX_CONTINUE; |
Johannes Berg | 7d54d0dd | 2007-12-19 01:31:25 +0100 | [diff] [blame] | 442 | |
Johannes Berg | 62b517c | 2009-10-29 12:19:21 +0100 | [diff] [blame] | 443 | info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM; |
Johannes Berg | 62b1208 | 2009-08-10 16:04:15 +0200 | [diff] [blame] | 444 | |
Johannes Berg | 62b517c | 2009-10-29 12:19:21 +0100 | [diff] [blame] | 445 | /* device releases frame after DTIM beacon */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 446 | if (!ieee80211_hw_check(&tx->local->hw, HOST_BROADCAST_PS_BUFFERING)) |
Johannes Berg | 62b1208 | 2009-08-10 16:04:15 +0200 | [diff] [blame] | 447 | return TX_CONTINUE; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 448 | |
Johannes Berg | 62b1208 | 2009-08-10 16:04:15 +0200 | [diff] [blame] | 449 | /* buffered in mac80211 */ |
| 450 | if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) |
| 451 | purge_old_ps_buffers(tx->local); |
Johannes Berg | 7d54d0dd | 2007-12-19 01:31:25 +0100 | [diff] [blame] | 452 | |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 453 | if (skb_queue_len(&ps->bc_buf) >= AP_MAX_BC_BUFFER) { |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 454 | ps_dbg(tx->sdata, |
| 455 | "BC TX buffer full - dropping the oldest frame\n"); |
Felix Fietkau | 6b07d9c | 2016-08-02 11:13:41 +0200 | [diff] [blame] | 456 | ieee80211_free_txskb(&tx->local->hw, skb_dequeue(&ps->bc_buf)); |
Johannes Berg | 62b1208 | 2009-08-10 16:04:15 +0200 | [diff] [blame] | 457 | } else |
| 458 | tx->local->total_ps_buffered++; |
| 459 | |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 460 | skb_queue_tail(&ps->bc_buf, tx->skb); |
Johannes Berg | 62b1208 | 2009-08-10 16:04:15 +0200 | [diff] [blame] | 461 | |
| 462 | return TX_QUEUED; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 463 | } |
| 464 | |
Jouni Malinen | fb73333 | 2009-01-08 13:32:00 +0200 | [diff] [blame] | 465 | static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta, |
| 466 | struct sk_buff *skb) |
| 467 | { |
| 468 | if (!ieee80211_is_mgmt(fc)) |
| 469 | return 0; |
| 470 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 471 | if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP)) |
Jouni Malinen | fb73333 | 2009-01-08 13:32:00 +0200 | [diff] [blame] | 472 | return 0; |
| 473 | |
Johannes Berg | d8ca16d | 2014-01-23 16:20:29 +0100 | [diff] [blame] | 474 | if (!ieee80211_is_robust_mgmt_frame(skb)) |
Jouni Malinen | fb73333 | 2009-01-08 13:32:00 +0200 | [diff] [blame] | 475 | return 0; |
| 476 | |
| 477 | return 1; |
| 478 | } |
| 479 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 480 | static ieee80211_tx_result |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 481 | ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 482 | { |
| 483 | struct sta_info *sta = tx->sta; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 484 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
Johannes Berg | 08b9939 | 2014-07-07 12:01:11 +0200 | [diff] [blame] | 485 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 486 | struct ieee80211_local *local = tx->local; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 487 | |
Johannes Berg | 02f2f1a | 2012-02-27 12:18:30 +0100 | [diff] [blame] | 488 | if (unlikely(!sta)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 489 | return TX_CONTINUE; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 490 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 491 | if (unlikely((test_sta_flag(sta, WLAN_STA_PS_STA) || |
Johannes Berg | 5ac2e35 | 2014-05-27 16:32:27 +0200 | [diff] [blame] | 492 | test_sta_flag(sta, WLAN_STA_PS_DRIVER) || |
| 493 | test_sta_flag(sta, WLAN_STA_PS_DELIVER)) && |
Johannes Berg | 02f2f1a | 2012-02-27 12:18:30 +0100 | [diff] [blame] | 494 | !(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER))) { |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 495 | int ac = skb_get_queue_mapping(tx->skb); |
| 496 | |
Johannes Berg | 08b9939 | 2014-07-07 12:01:11 +0200 | [diff] [blame] | 497 | if (ieee80211_is_mgmt(hdr->frame_control) && |
| 498 | !ieee80211_is_bufferable_mmpdu(hdr->frame_control)) { |
| 499 | info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER; |
| 500 | return TX_CONTINUE; |
| 501 | } |
| 502 | |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 503 | ps_dbg(sta->sdata, "STA %pM aid %d: PS buffer for AC %d\n", |
| 504 | sta->sta.addr, sta->sta.aid, ac); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 505 | if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER) |
| 506 | purge_old_ps_buffers(tx->local); |
Emmanuel Grumbach | 1d147bf | 2014-02-20 09:22:11 +0200 | [diff] [blame] | 507 | |
| 508 | /* sync with ieee80211_sta_ps_deliver_wakeup */ |
| 509 | spin_lock(&sta->ps_lock); |
| 510 | /* |
| 511 | * STA woke up the meantime and all the frames on ps_tx_buf have |
| 512 | * been queued to pending queue. No reordering can happen, go |
| 513 | * ahead and Tx the packet. |
| 514 | */ |
| 515 | if (!test_sta_flag(sta, WLAN_STA_PS_STA) && |
Johannes Berg | 5ac2e35 | 2014-05-27 16:32:27 +0200 | [diff] [blame] | 516 | !test_sta_flag(sta, WLAN_STA_PS_DRIVER) && |
| 517 | !test_sta_flag(sta, WLAN_STA_PS_DELIVER)) { |
Emmanuel Grumbach | 1d147bf | 2014-02-20 09:22:11 +0200 | [diff] [blame] | 518 | spin_unlock(&sta->ps_lock); |
| 519 | return TX_CONTINUE; |
| 520 | } |
| 521 | |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 522 | if (skb_queue_len(&sta->ps_tx_buf[ac]) >= STA_MAX_TX_BUFFER) { |
| 523 | struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf[ac]); |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 524 | ps_dbg(tx->sdata, |
| 525 | "STA %pM TX buffer for AC %d full - dropping oldest frame\n", |
| 526 | sta->sta.addr, ac); |
Felix Fietkau | c3e7724 | 2012-10-08 14:39:33 +0200 | [diff] [blame] | 527 | ieee80211_free_txskb(&local->hw, old); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 528 | } else |
| 529 | tx->local->total_ps_buffered++; |
Johannes Berg | 004c872 | 2008-02-20 11:21:35 +0100 | [diff] [blame] | 530 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 531 | info->control.jiffies = jiffies; |
Johannes Berg | 5061b0c | 2009-07-14 00:33:34 +0200 | [diff] [blame] | 532 | info->control.vif = &tx->sdata->vif; |
Johannes Berg | 8f77f38 | 2009-06-07 21:58:37 +0200 | [diff] [blame] | 533 | info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; |
Johannes Berg | 03c8c06 | 2014-01-09 01:45:28 +0100 | [diff] [blame] | 534 | info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS; |
Johannes Berg | 948d887 | 2011-09-29 16:04:29 +0200 | [diff] [blame] | 535 | skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb); |
Emmanuel Grumbach | 1d147bf | 2014-02-20 09:22:11 +0200 | [diff] [blame] | 536 | spin_unlock(&sta->ps_lock); |
Juuso Oikarinen | 3393a60 | 2010-04-19 10:12:52 +0300 | [diff] [blame] | 537 | |
| 538 | if (!timer_pending(&local->sta_cleanup)) |
| 539 | mod_timer(&local->sta_cleanup, |
| 540 | round_jiffies(jiffies + |
| 541 | STA_INFO_CLEANUP_INTERVAL)); |
| 542 | |
Johannes Berg | c868cb35 | 2011-09-29 16:04:27 +0200 | [diff] [blame] | 543 | /* |
| 544 | * We queued up some frames, so the TIM bit might |
| 545 | * need to be set, recalculate it. |
| 546 | */ |
| 547 | sta_info_recalc_tim(sta); |
| 548 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 549 | return TX_QUEUED; |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 550 | } else if (unlikely(test_sta_flag(sta, WLAN_STA_PS_STA))) { |
| 551 | ps_dbg(tx->sdata, |
| 552 | "STA %pM in PS mode, but polling/in SP -> send frame\n", |
| 553 | sta->sta.addr); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 554 | } |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 555 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 556 | return TX_CONTINUE; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 557 | } |
| 558 | |
Johannes Berg | d9e8a70 | 2008-06-30 15:10:44 +0200 | [diff] [blame] | 559 | static ieee80211_tx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 560 | ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 561 | { |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 562 | if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED)) |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 563 | return TX_CONTINUE; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 564 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 565 | if (tx->flags & IEEE80211_TX_UNICAST) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 566 | return ieee80211_tx_h_unicast_ps_buf(tx); |
| 567 | else |
| 568 | return ieee80211_tx_h_multicast_ps_buf(tx); |
| 569 | } |
| 570 | |
Johannes Berg | d9e8a70 | 2008-06-30 15:10:44 +0200 | [diff] [blame] | 571 | static ieee80211_tx_result debug_noinline |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 572 | ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data *tx) |
| 573 | { |
| 574 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
| 575 | |
Johannes Berg | af61a16 | 2013-07-02 18:09:12 +0200 | [diff] [blame] | 576 | if (unlikely(tx->sdata->control_port_protocol == tx->skb->protocol)) { |
| 577 | if (tx->sdata->control_port_no_encrypt) |
| 578 | info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 579 | info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO; |
Jouni Malinen | 9c1c98a | 2015-02-26 15:50:50 +0200 | [diff] [blame] | 580 | info->flags |= IEEE80211_TX_CTL_USE_MINRATE; |
Johannes Berg | af61a16 | 2013-07-02 18:09:12 +0200 | [diff] [blame] | 581 | } |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 582 | |
| 583 | return TX_CONTINUE; |
| 584 | } |
| 585 | |
| 586 | static ieee80211_tx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 587 | ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 588 | { |
Johannes Berg | 46e6de1 | 2012-07-04 18:10:07 +0200 | [diff] [blame] | 589 | struct ieee80211_key *key; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 590 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 591 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 592 | |
Johannes Berg | a0761a3 | 2020-03-26 15:09:42 +0200 | [diff] [blame] | 593 | if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT)) { |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 594 | tx->key = NULL; |
Johannes Berg | a0761a3 | 2020-03-26 15:09:42 +0200 | [diff] [blame] | 595 | return TX_CONTINUE; |
| 596 | } |
| 597 | |
| 598 | if (tx->sta && |
| 599 | (key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx]))) |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 600 | tx->key = key; |
Masashi Honma | 46f6b06 | 2016-06-22 19:55:20 +0900 | [diff] [blame] | 601 | else if (ieee80211_is_group_privacy_action(tx->skb) && |
| 602 | (key = rcu_dereference(tx->sdata->default_multicast_key))) |
| 603 | tx->key = key; |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 604 | else if (ieee80211_is_mgmt(hdr->frame_control) && |
Jouni Malinen | ecbcd32 | 2010-03-29 23:35:23 -0700 | [diff] [blame] | 605 | is_multicast_ether_addr(hdr->addr1) && |
Johannes Berg | d8ca16d | 2014-01-23 16:20:29 +0100 | [diff] [blame] | 606 | ieee80211_is_robust_mgmt_frame(tx->skb) && |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 607 | (key = rcu_dereference(tx->sdata->default_mgmt_key))) |
| 608 | tx->key = key; |
Johannes Berg | f7e0104 | 2010-12-09 19:49:02 +0100 | [diff] [blame] | 609 | else if (is_multicast_ether_addr(hdr->addr1) && |
| 610 | (key = rcu_dereference(tx->sdata->default_multicast_key))) |
| 611 | tx->key = key; |
| 612 | else if (!is_multicast_ether_addr(hdr->addr1) && |
| 613 | (key = rcu_dereference(tx->sdata->default_unicast_key))) |
Johannes Berg | d4e46a3 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 614 | tx->key = key; |
Johannes Berg | e8f4fb7 | 2015-03-20 11:37:36 +0100 | [diff] [blame] | 615 | else |
Johannes Berg | 46e6de1 | 2012-07-04 18:10:07 +0200 | [diff] [blame] | 616 | tx->key = NULL; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 617 | |
| 618 | if (tx->key) { |
Johannes Berg | 813d766 | 2010-01-17 01:47:58 +0100 | [diff] [blame] | 619 | bool skip_hw = false; |
| 620 | |
Johannes Berg | 011bfcc | 2007-09-17 01:29:25 -0400 | [diff] [blame] | 621 | /* TODO: add threshold stuff again */ |
Johannes Berg | 176e4f8 | 2007-12-18 15:27:47 +0100 | [diff] [blame] | 622 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 623 | switch (tx->key->conf.cipher) { |
| 624 | case WLAN_CIPHER_SUITE_WEP40: |
| 625 | case WLAN_CIPHER_SUITE_WEP104: |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 626 | case WLAN_CIPHER_SUITE_TKIP: |
Harvey Harrison | 358c8d9 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 627 | if (!ieee80211_is_data_present(hdr->frame_control)) |
Johannes Berg | 176e4f8 | 2007-12-18 15:27:47 +0100 | [diff] [blame] | 628 | tx->key = NULL; |
| 629 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 630 | case WLAN_CIPHER_SUITE_CCMP: |
Jouni Malinen | 2b2ba0d | 2015-01-24 19:52:07 +0200 | [diff] [blame] | 631 | case WLAN_CIPHER_SUITE_CCMP_256: |
Jouni Malinen | 00b9cfa | 2015-01-24 19:52:06 +0200 | [diff] [blame] | 632 | case WLAN_CIPHER_SUITE_GCMP: |
| 633 | case WLAN_CIPHER_SUITE_GCMP_256: |
Jouni Malinen | fb73333 | 2009-01-08 13:32:00 +0200 | [diff] [blame] | 634 | if (!ieee80211_is_data_present(hdr->frame_control) && |
| 635 | !ieee80211_use_mfp(hdr->frame_control, tx->sta, |
Masashi Honma | 46f6b06 | 2016-06-22 19:55:20 +0900 | [diff] [blame] | 636 | tx->skb) && |
| 637 | !ieee80211_is_group_privacy_action(tx->skb)) |
Jouni Malinen | fb73333 | 2009-01-08 13:32:00 +0200 | [diff] [blame] | 638 | tx->key = NULL; |
Kalle Valo | 3b43a18 | 2010-01-23 20:27:14 +0200 | [diff] [blame] | 639 | else |
| 640 | skip_hw = (tx->key->conf.flags & |
Johannes Berg | e548c49 | 2012-09-04 17:08:23 +0200 | [diff] [blame] | 641 | IEEE80211_KEY_FLAG_SW_MGMT_TX) && |
Kalle Valo | 3b43a18 | 2010-01-23 20:27:14 +0200 | [diff] [blame] | 642 | ieee80211_is_mgmt(hdr->frame_control); |
Jouni Malinen | fb73333 | 2009-01-08 13:32:00 +0200 | [diff] [blame] | 643 | break; |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 644 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Jouni Malinen | 56c52da | 2015-01-24 19:52:08 +0200 | [diff] [blame] | 645 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
Jouni Malinen | 8ade538 | 2015-01-24 19:52:09 +0200 | [diff] [blame] | 646 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 647 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 648 | if (!ieee80211_is_mgmt(hdr->frame_control)) |
| 649 | tx->key = NULL; |
| 650 | break; |
Johannes Berg | 176e4f8 | 2007-12-18 15:27:47 +0100 | [diff] [blame] | 651 | } |
Johannes Berg | 813d766 | 2010-01-17 01:47:58 +0100 | [diff] [blame] | 652 | |
Johannes Berg | e54faf2 | 2013-01-29 11:41:38 +0100 | [diff] [blame] | 653 | if (unlikely(tx->key && tx->key->flags & KEY_FLAG_TAINTED && |
| 654 | !ieee80211_is_deauth(hdr->frame_control))) |
Johannes Berg | 95acac6 | 2011-07-12 12:30:59 +0200 | [diff] [blame] | 655 | return TX_DROP; |
| 656 | |
Johannes Berg | f12553e | 2010-01-22 22:07:59 +0100 | [diff] [blame] | 657 | if (!skip_hw && tx->key && |
Johannes Berg | 382b165 | 2010-01-25 11:36:16 +0100 | [diff] [blame] | 658 | tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE) |
Johannes Berg | 813d766 | 2010-01-17 01:47:58 +0100 | [diff] [blame] | 659 | info->control.hw_key = &tx->key->conf; |
Johannes Berg | a0761a3 | 2020-03-26 15:09:42 +0200 | [diff] [blame] | 660 | } else if (!ieee80211_is_mgmt(hdr->frame_control) && tx->sta && |
| 661 | test_sta_flag(tx->sta, WLAN_STA_USES_ENCRYPTION)) { |
| 662 | return TX_DROP; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 663 | } |
| 664 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 665 | return TX_CONTINUE; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 666 | } |
| 667 | |
Johannes Berg | d9e8a70 | 2008-06-30 15:10:44 +0200 | [diff] [blame] | 668 | static ieee80211_tx_result debug_noinline |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 669 | ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 670 | { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 671 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 672 | struct ieee80211_hdr *hdr = (void *)tx->skb->data; |
| 673 | struct ieee80211_supported_band *sband; |
Shanyu Zhao | a2c4024 | 2010-04-27 11:15:12 -0700 | [diff] [blame] | 674 | u32 len; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 675 | struct ieee80211_tx_rate_control txrc; |
Felix Fietkau | 0d528d8 | 2013-04-22 16:14:41 +0200 | [diff] [blame] | 676 | struct ieee80211_sta_rates *ratetbl = NULL; |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 677 | bool assoc = false; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 678 | |
| 679 | memset(&txrc, 0, sizeof(txrc)); |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 680 | |
Johannes Berg | 2d56577 | 2012-07-23 15:12:51 +0200 | [diff] [blame] | 681 | sband = tx->local->hw.wiphy->bands[info->band]; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 682 | |
Shanyu Zhao | a2c4024 | 2010-04-27 11:15:12 -0700 | [diff] [blame] | 683 | len = min_t(u32, tx->skb->len + FCS_LEN, |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 684 | tx->local->hw.wiphy->frag_threshold); |
Johannes Berg | 58d4185 | 2007-09-26 17:53:18 +0200 | [diff] [blame] | 685 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 686 | /* set up the tx rate control struct we give the RC algo */ |
Johannes Berg | 005e472 | 2012-02-26 11:24:35 +0100 | [diff] [blame] | 687 | txrc.hw = &tx->local->hw; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 688 | txrc.sband = sband; |
| 689 | txrc.bss_conf = &tx->sdata->vif.bss_conf; |
| 690 | txrc.skb = tx->skb; |
| 691 | txrc.reported_rate.idx = -1; |
Johannes Berg | 2d56577 | 2012-07-23 15:12:51 +0200 | [diff] [blame] | 692 | txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[info->band]; |
Felix Fietkau | 2ffbe6d | 2013-04-16 13:38:42 +0200 | [diff] [blame] | 693 | |
| 694 | if (tx->sdata->rc_has_mcs_mask[info->band]) |
| 695 | txrc.rate_idx_mcs_mask = |
| 696 | tx->sdata->rc_rateidx_mcs_mask[info->band]; |
| 697 | |
Felix Fietkau | 8f0729b | 2010-11-11 15:07:23 +0100 | [diff] [blame] | 698 | txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP || |
Chun-Yeow Yeoh | 4bb6234 | 2011-11-24 17:15:20 -0800 | [diff] [blame] | 699 | tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT || |
Bertold Van den Bergh | 5765f9f | 2015-08-05 16:02:28 +0200 | [diff] [blame] | 700 | tx->sdata->vif.type == NL80211_IFTYPE_ADHOC || |
| 701 | tx->sdata->vif.type == NL80211_IFTYPE_OCB); |
Johannes Berg | 58d4185 | 2007-09-26 17:53:18 +0200 | [diff] [blame] | 702 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 703 | /* set up RTS protection if desired */ |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 704 | if (len > tx->local->hw.wiphy->rts_threshold) { |
Felix Fietkau | 0d528d8 | 2013-04-22 16:14:41 +0200 | [diff] [blame] | 705 | txrc.rts = true; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 706 | } |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 707 | |
Felix Fietkau | 0d528d8 | 2013-04-22 16:14:41 +0200 | [diff] [blame] | 708 | info->control.use_rts = txrc.rts; |
Felix Fietkau | 991fec0 | 2013-04-16 13:38:43 +0200 | [diff] [blame] | 709 | info->control.use_cts_prot = tx->sdata->vif.bss_conf.use_cts_prot; |
| 710 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 711 | /* |
| 712 | * Use short preamble if the BSS can handle it, but not for |
| 713 | * management frames unless we know the receiver can handle |
| 714 | * that -- the management frame might be to a station that |
| 715 | * just wants a probe response. |
| 716 | */ |
| 717 | if (tx->sdata->vif.bss_conf.use_short_preamble && |
| 718 | (ieee80211_is_data(hdr->frame_control) || |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 719 | (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE)))) |
Felix Fietkau | 0d528d8 | 2013-04-22 16:14:41 +0200 | [diff] [blame] | 720 | txrc.short_preamble = true; |
| 721 | |
| 722 | info->control.short_preamble = txrc.short_preamble; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 723 | |
Sven Eckelmann | dfdfc2b | 2016-01-26 17:11:13 +0100 | [diff] [blame] | 724 | /* don't ask rate control when rate already injected via radiotap */ |
| 725 | if (info->control.flags & IEEE80211_TX_CTRL_RATE_INJECT) |
| 726 | return TX_CONTINUE; |
| 727 | |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 728 | if (tx->sta) |
| 729 | assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC); |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 730 | |
Luis R. Rodriguez | b770b43 | 2009-07-16 10:15:09 -0700 | [diff] [blame] | 731 | /* |
| 732 | * Lets not bother rate control if we're associated and cannot |
| 733 | * talk to the sta. This should not happen. |
| 734 | */ |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 735 | if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc && |
Luis R. Rodriguez | b770b43 | 2009-07-16 10:15:09 -0700 | [diff] [blame] | 736 | !rate_usable_index_exists(sband, &tx->sta->sta), |
| 737 | "%s: Dropped data frame as no usable bitrate found while " |
| 738 | "scanning and associated. Target station: " |
| 739 | "%pM on %d GHz band\n", |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 740 | tx->sdata->name, hdr->addr1, |
Johannes Berg | 2d56577 | 2012-07-23 15:12:51 +0200 | [diff] [blame] | 741 | info->band ? 5 : 2)) |
Luis R. Rodriguez | b770b43 | 2009-07-16 10:15:09 -0700 | [diff] [blame] | 742 | return TX_DROP; |
| 743 | |
| 744 | /* |
| 745 | * If we're associated with the sta at this point we know we can at |
| 746 | * least send the frame at the lowest bit rate. |
| 747 | */ |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 748 | rate_control_get_rate(tx->sdata, tx->sta, &txrc); |
| 749 | |
Felix Fietkau | 0d528d8 | 2013-04-22 16:14:41 +0200 | [diff] [blame] | 750 | if (tx->sta && !info->control.skip_table) |
| 751 | ratetbl = rcu_dereference(tx->sta->sta.rates); |
| 752 | |
| 753 | if (unlikely(info->control.rates[0].idx < 0)) { |
| 754 | if (ratetbl) { |
| 755 | struct ieee80211_tx_rate rate = { |
| 756 | .idx = ratetbl->rate[0].idx, |
| 757 | .flags = ratetbl->rate[0].flags, |
| 758 | .count = ratetbl->rate[0].count |
| 759 | }; |
| 760 | |
| 761 | if (ratetbl->rate[0].idx < 0) |
| 762 | return TX_DROP; |
| 763 | |
| 764 | tx->rate = rate; |
| 765 | } else { |
| 766 | return TX_DROP; |
| 767 | } |
| 768 | } else { |
| 769 | tx->rate = info->control.rates[0]; |
| 770 | } |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 771 | |
Helmut Schaa | c1ce5a7 | 2010-12-01 16:34:45 +0100 | [diff] [blame] | 772 | if (txrc.reported_rate.idx < 0) { |
Felix Fietkau | 0d528d8 | 2013-04-22 16:14:41 +0200 | [diff] [blame] | 773 | txrc.reported_rate = tx->rate; |
Helmut Schaa | c1ce5a7 | 2010-12-01 16:34:45 +0100 | [diff] [blame] | 774 | if (tx->sta && ieee80211_is_data(hdr->frame_control)) |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 775 | tx->sta->tx_stats.last_rate = txrc.reported_rate; |
Helmut Schaa | c1ce5a7 | 2010-12-01 16:34:45 +0100 | [diff] [blame] | 776 | } else if (tx->sta) |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 777 | tx->sta->tx_stats.last_rate = txrc.reported_rate; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 778 | |
Felix Fietkau | 0d528d8 | 2013-04-22 16:14:41 +0200 | [diff] [blame] | 779 | if (ratetbl) |
| 780 | return TX_CONTINUE; |
| 781 | |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 782 | if (unlikely(!info->control.rates[0].count)) |
| 783 | info->control.rates[0].count = 1; |
| 784 | |
Gábor Stefanik | 9955151 | 2009-04-23 19:36:14 +0200 | [diff] [blame] | 785 | if (WARN_ON_ONCE((info->control.rates[0].count > 1) && |
| 786 | (info->flags & IEEE80211_TX_CTL_NO_ACK))) |
| 787 | info->control.rates[0].count = 1; |
| 788 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 789 | return TX_CONTINUE; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 790 | } |
| 791 | |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 792 | static __le16 ieee80211_tx_next_seq(struct sta_info *sta, int tid) |
| 793 | { |
| 794 | u16 *seq = &sta->tid_seq[tid]; |
| 795 | __le16 ret = cpu_to_le16(*seq); |
| 796 | |
| 797 | /* Increase the sequence number. */ |
| 798 | *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ; |
| 799 | |
| 800 | return ret; |
| 801 | } |
| 802 | |
Johannes Berg | d9e8a70 | 2008-06-30 15:10:44 +0200 | [diff] [blame] | 803 | static ieee80211_tx_result debug_noinline |
Johannes Berg | f591fa5 | 2008-07-10 11:21:26 +0200 | [diff] [blame] | 804 | ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx) |
| 805 | { |
| 806 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
| 807 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data; |
Johannes Berg | f591fa5 | 2008-07-10 11:21:26 +0200 | [diff] [blame] | 808 | int tid; |
| 809 | |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 810 | /* |
| 811 | * Packet injection may want to control the sequence |
| 812 | * number, if we have no matching interface then we |
| 813 | * neither assign one ourselves nor ask the driver to. |
| 814 | */ |
Johannes Berg | 5061b0c | 2009-07-14 00:33:34 +0200 | [diff] [blame] | 815 | if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR)) |
Johannes Berg | 25d834e | 2008-09-12 22:52:47 +0200 | [diff] [blame] | 816 | return TX_CONTINUE; |
| 817 | |
Johannes Berg | f591fa5 | 2008-07-10 11:21:26 +0200 | [diff] [blame] | 818 | if (unlikely(ieee80211_is_ctl(hdr->frame_control))) |
| 819 | return TX_CONTINUE; |
| 820 | |
| 821 | if (ieee80211_hdrlen(hdr->frame_control) < 24) |
| 822 | return TX_CONTINUE; |
| 823 | |
Johannes Berg | 49a5954 | 2011-09-29 16:04:41 +0200 | [diff] [blame] | 824 | if (ieee80211_is_qos_nullfunc(hdr->frame_control)) |
| 825 | return TX_CONTINUE; |
| 826 | |
Johannes Berg | 9477828 | 2008-10-10 13:21:59 +0200 | [diff] [blame] | 827 | /* |
| 828 | * Anything but QoS data that has a sequence number field |
| 829 | * (is long enough) gets a sequence number from the global |
Bob Copeland | c4c205f | 2013-08-23 09:35:38 -0400 | [diff] [blame] | 830 | * counter. QoS data frames with a multicast destination |
| 831 | * also use the global counter (802.11-2012 9.3.2.10). |
Johannes Berg | 9477828 | 2008-10-10 13:21:59 +0200 | [diff] [blame] | 832 | */ |
Bob Copeland | c4c205f | 2013-08-23 09:35:38 -0400 | [diff] [blame] | 833 | if (!ieee80211_is_data_qos(hdr->frame_control) || |
| 834 | is_multicast_ether_addr(hdr->addr1)) { |
Johannes Berg | b9771d4 | 2018-05-28 15:47:41 +0200 | [diff] [blame] | 835 | if (tx->flags & IEEE80211_TX_NO_SEQNO) |
| 836 | return TX_CONTINUE; |
Johannes Berg | 9477828 | 2008-10-10 13:21:59 +0200 | [diff] [blame] | 837 | /* driver should assign sequence number */ |
Johannes Berg | f591fa5 | 2008-07-10 11:21:26 +0200 | [diff] [blame] | 838 | info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ; |
Johannes Berg | 9477828 | 2008-10-10 13:21:59 +0200 | [diff] [blame] | 839 | /* for pure STA mode without beacons, we can do it */ |
| 840 | hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number); |
| 841 | tx->sdata->sequence_number += 0x10; |
Johannes Berg | 79c892b | 2014-11-21 14:26:31 +0100 | [diff] [blame] | 842 | if (tx->sta) |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 843 | tx->sta->tx_stats.msdu[IEEE80211_NUM_TIDS]++; |
Johannes Berg | f591fa5 | 2008-07-10 11:21:26 +0200 | [diff] [blame] | 844 | return TX_CONTINUE; |
| 845 | } |
| 846 | |
| 847 | /* |
| 848 | * This should be true for injected/management frames only, for |
| 849 | * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ |
| 850 | * above since they are not QoS-data frames. |
| 851 | */ |
| 852 | if (!tx->sta) |
| 853 | return TX_CONTINUE; |
| 854 | |
| 855 | /* include per-STA, per-TID sequence counter */ |
Sara Sharon | a1f2ba04c | 2018-02-19 14:48:40 +0200 | [diff] [blame] | 856 | tid = ieee80211_get_tid(hdr); |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 857 | tx->sta->tx_stats.msdu[tid]++; |
Johannes Berg | f591fa5 | 2008-07-10 11:21:26 +0200 | [diff] [blame] | 858 | |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 859 | hdr->seq_ctrl = ieee80211_tx_next_seq(tx->sta, tid); |
Johannes Berg | f591fa5 | 2008-07-10 11:21:26 +0200 | [diff] [blame] | 860 | |
| 861 | return TX_CONTINUE; |
| 862 | } |
| 863 | |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 864 | static int ieee80211_fragment(struct ieee80211_tx_data *tx, |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 865 | struct sk_buff *skb, int hdrlen, |
| 866 | int frag_threshold) |
| 867 | { |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 868 | struct ieee80211_local *local = tx->local; |
Johannes Berg | a1a3fce | 2011-11-16 15:28:56 +0100 | [diff] [blame] | 869 | struct ieee80211_tx_info *info; |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 870 | struct sk_buff *tmp; |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 871 | int per_fragm = frag_threshold - hdrlen - FCS_LEN; |
| 872 | int pos = hdrlen + per_fragm; |
| 873 | int rem = skb->len - hdrlen - per_fragm; |
| 874 | |
| 875 | if (WARN_ON(rem < 0)) |
| 876 | return -EINVAL; |
| 877 | |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 878 | /* first fragment was already added to queue by caller */ |
| 879 | |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 880 | while (rem) { |
| 881 | int fraglen = per_fragm; |
| 882 | |
| 883 | if (fraglen > rem) |
| 884 | fraglen = rem; |
| 885 | rem -= fraglen; |
| 886 | tmp = dev_alloc_skb(local->tx_headroom + |
| 887 | frag_threshold + |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 888 | tx->sdata->encrypt_headroom + |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 889 | IEEE80211_ENCRYPT_TAILROOM); |
| 890 | if (!tmp) |
| 891 | return -ENOMEM; |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 892 | |
| 893 | __skb_queue_tail(&tx->skbs, tmp); |
| 894 | |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 895 | skb_reserve(tmp, |
| 896 | local->tx_headroom + tx->sdata->encrypt_headroom); |
| 897 | |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 898 | /* copy control information */ |
| 899 | memcpy(tmp->cb, skb->cb, sizeof(tmp->cb)); |
Johannes Berg | a1a3fce | 2011-11-16 15:28:56 +0100 | [diff] [blame] | 900 | |
| 901 | info = IEEE80211_SKB_CB(tmp); |
| 902 | info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT | |
| 903 | IEEE80211_TX_CTL_FIRST_FRAGMENT); |
| 904 | |
| 905 | if (rem) |
| 906 | info->flags |= IEEE80211_TX_CTL_MORE_FRAMES; |
| 907 | |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 908 | skb_copy_queue_mapping(tmp, skb); |
| 909 | tmp->priority = skb->priority; |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 910 | tmp->dev = skb->dev; |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 911 | |
| 912 | /* copy header and data */ |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 913 | skb_put_data(tmp, skb->data, hdrlen); |
| 914 | skb_put_data(tmp, skb->data + pos, fraglen); |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 915 | |
| 916 | pos += fraglen; |
| 917 | } |
| 918 | |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 919 | /* adjust first fragment's length */ |
Johannes Berg | 338f977 | 2014-02-01 00:16:23 +0100 | [diff] [blame] | 920 | skb_trim(skb, hdrlen + per_fragm); |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 921 | return 0; |
| 922 | } |
| 923 | |
Johannes Berg | f591fa5 | 2008-07-10 11:21:26 +0200 | [diff] [blame] | 924 | static ieee80211_tx_result debug_noinline |
Johannes Berg | e245494 | 2008-05-15 12:55:28 +0200 | [diff] [blame] | 925 | ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx) |
| 926 | { |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 927 | struct sk_buff *skb = tx->skb; |
| 928 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 929 | struct ieee80211_hdr *hdr = (void *)skb->data; |
Jouni Malinen | b9a5f8ca | 2009-04-20 18:39:05 +0200 | [diff] [blame] | 930 | int frag_threshold = tx->local->hw.wiphy->frag_threshold; |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 931 | int hdrlen; |
| 932 | int fragnum; |
Johannes Berg | e245494 | 2008-05-15 12:55:28 +0200 | [diff] [blame] | 933 | |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 934 | /* no matter what happens, tx->skb moves to tx->skbs */ |
| 935 | __skb_queue_tail(&tx->skbs, skb); |
| 936 | tx->skb = NULL; |
| 937 | |
Johannes Berg | a26eb27 | 2011-10-07 14:01:25 +0200 | [diff] [blame] | 938 | if (info->flags & IEEE80211_TX_CTL_DONTFRAG) |
| 939 | return TX_CONTINUE; |
| 940 | |
Sara Sharon | f3fe4e9 | 2016-10-18 23:12:11 +0300 | [diff] [blame] | 941 | if (ieee80211_hw_check(&tx->local->hw, SUPPORTS_TX_FRAG)) |
Johannes Berg | e245494 | 2008-05-15 12:55:28 +0200 | [diff] [blame] | 942 | return TX_CONTINUE; |
| 943 | |
Johannes Berg | eefce91 | 2008-05-17 00:57:13 +0200 | [diff] [blame] | 944 | /* |
| 945 | * Warn when submitting a fragmented A-MPDU frame and drop it. |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 946 | * This scenario is handled in ieee80211_tx_prepare but extra |
Ron Rindjunsky | 8d5e0d5 | 2008-06-12 15:42:29 +0300 | [diff] [blame] | 947 | * caution taken here as fragmented ampdu may cause Tx stop. |
Johannes Berg | eefce91 | 2008-05-17 00:57:13 +0200 | [diff] [blame] | 948 | */ |
Sujith | 8b30b1f | 2008-10-24 09:55:27 +0530 | [diff] [blame] | 949 | if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU)) |
Johannes Berg | eefce91 | 2008-05-17 00:57:13 +0200 | [diff] [blame] | 950 | return TX_DROP; |
| 951 | |
Harvey Harrison | 065e9605 | 2008-06-22 16:45:27 -0700 | [diff] [blame] | 952 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
Johannes Berg | e245494 | 2008-05-15 12:55:28 +0200 | [diff] [blame] | 953 | |
Johannes Berg | a26eb27 | 2011-10-07 14:01:25 +0200 | [diff] [blame] | 954 | /* internal error, why isn't DONTFRAG set? */ |
Johannes Berg | 8ccd8f2 | 2009-04-29 23:35:56 +0200 | [diff] [blame] | 955 | if (WARN_ON(skb->len + FCS_LEN <= frag_threshold)) |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 956 | return TX_DROP; |
Johannes Berg | e245494 | 2008-05-15 12:55:28 +0200 | [diff] [blame] | 957 | |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 958 | /* |
| 959 | * Now fragment the frame. This will allocate all the fragments and |
| 960 | * chain them (using skb as the first fragment) to skb->next. |
| 961 | * During transmission, we will remove the successfully transmitted |
| 962 | * fragments from this list. When the low-level driver rejects one |
| 963 | * of the fragments then we will simply pretend to accept the skb |
| 964 | * but store it away as pending. |
| 965 | */ |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 966 | if (ieee80211_fragment(tx, skb, hdrlen, frag_threshold)) |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 967 | return TX_DROP; |
Johannes Berg | e245494 | 2008-05-15 12:55:28 +0200 | [diff] [blame] | 968 | |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 969 | /* update duration/seq/flags of fragments */ |
| 970 | fragnum = 0; |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 971 | |
| 972 | skb_queue_walk(&tx->skbs, skb) { |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 973 | const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS); |
Johannes Berg | e245494 | 2008-05-15 12:55:28 +0200 | [diff] [blame] | 974 | |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 975 | hdr = (void *)skb->data; |
| 976 | info = IEEE80211_SKB_CB(skb); |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 977 | |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 978 | if (!skb_queue_is_last(&tx->skbs, skb)) { |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 979 | hdr->frame_control |= morefrags; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 980 | /* |
| 981 | * No multi-rate retries for fragmented frames, that |
| 982 | * would completely throw off the NAV at other STAs. |
| 983 | */ |
| 984 | info->control.rates[1].idx = -1; |
| 985 | info->control.rates[2].idx = -1; |
| 986 | info->control.rates[3].idx = -1; |
Thomas Huehn | e3e1a0b | 2012-07-02 19:46:16 +0200 | [diff] [blame] | 987 | BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 4); |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 988 | info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE; |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 989 | } else { |
| 990 | hdr->frame_control &= ~morefrags; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 991 | } |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 992 | hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG); |
| 993 | fragnum++; |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 994 | } |
Johannes Berg | e245494 | 2008-05-15 12:55:28 +0200 | [diff] [blame] | 995 | |
| 996 | return TX_CONTINUE; |
Johannes Berg | e245494 | 2008-05-15 12:55:28 +0200 | [diff] [blame] | 997 | } |
| 998 | |
Johannes Berg | d9e8a70 | 2008-06-30 15:10:44 +0200 | [diff] [blame] | 999 | static ieee80211_tx_result debug_noinline |
Johannes Berg | feff1f2 | 2009-08-10 16:01:54 +0200 | [diff] [blame] | 1000 | ieee80211_tx_h_stats(struct ieee80211_tx_data *tx) |
| 1001 | { |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 1002 | struct sk_buff *skb; |
Johannes Berg | 560d268 | 2013-02-05 10:55:21 +0100 | [diff] [blame] | 1003 | int ac = -1; |
Johannes Berg | feff1f2 | 2009-08-10 16:01:54 +0200 | [diff] [blame] | 1004 | |
| 1005 | if (!tx->sta) |
| 1006 | return TX_CONTINUE; |
| 1007 | |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 1008 | skb_queue_walk(&tx->skbs, skb) { |
Johannes Berg | 560d268 | 2013-02-05 10:55:21 +0100 | [diff] [blame] | 1009 | ac = skb_get_queue_mapping(skb); |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 1010 | tx->sta->tx_stats.bytes[ac] += skb->len; |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 1011 | } |
Johannes Berg | 560d268 | 2013-02-05 10:55:21 +0100 | [diff] [blame] | 1012 | if (ac >= 0) |
Johannes Berg | e5a9f8d | 2015-10-16 17:54:47 +0200 | [diff] [blame] | 1013 | tx->sta->tx_stats.packets[ac]++; |
Johannes Berg | feff1f2 | 2009-08-10 16:01:54 +0200 | [diff] [blame] | 1014 | |
| 1015 | return TX_CONTINUE; |
| 1016 | } |
| 1017 | |
| 1018 | static ieee80211_tx_result debug_noinline |
Johannes Berg | e245494 | 2008-05-15 12:55:28 +0200 | [diff] [blame] | 1019 | ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx) |
| 1020 | { |
| 1021 | if (!tx->key) |
| 1022 | return TX_CONTINUE; |
| 1023 | |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1024 | switch (tx->key->conf.cipher) { |
| 1025 | case WLAN_CIPHER_SUITE_WEP40: |
| 1026 | case WLAN_CIPHER_SUITE_WEP104: |
Johannes Berg | e245494 | 2008-05-15 12:55:28 +0200 | [diff] [blame] | 1027 | return ieee80211_crypto_wep_encrypt(tx); |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1028 | case WLAN_CIPHER_SUITE_TKIP: |
Johannes Berg | e245494 | 2008-05-15 12:55:28 +0200 | [diff] [blame] | 1029 | return ieee80211_crypto_tkip_encrypt(tx); |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1030 | case WLAN_CIPHER_SUITE_CCMP: |
Jouni Malinen | 2b2ba0d | 2015-01-24 19:52:07 +0200 | [diff] [blame] | 1031 | return ieee80211_crypto_ccmp_encrypt( |
| 1032 | tx, IEEE80211_CCMP_MIC_LEN); |
| 1033 | case WLAN_CIPHER_SUITE_CCMP_256: |
| 1034 | return ieee80211_crypto_ccmp_encrypt( |
| 1035 | tx, IEEE80211_CCMP_256_MIC_LEN); |
Johannes Berg | 97359d1 | 2010-08-10 09:46:38 +0200 | [diff] [blame] | 1036 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Jouni Malinen | 3cfcf6ac | 2009-01-08 13:32:02 +0200 | [diff] [blame] | 1037 | return ieee80211_crypto_aes_cmac_encrypt(tx); |
Jouni Malinen | 56c52da | 2015-01-24 19:52:08 +0200 | [diff] [blame] | 1038 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
| 1039 | return ieee80211_crypto_aes_cmac_256_encrypt(tx); |
Jouni Malinen | 8ade538 | 2015-01-24 19:52:09 +0200 | [diff] [blame] | 1040 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 1041 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 1042 | return ieee80211_crypto_aes_gmac_encrypt(tx); |
Jouni Malinen | 00b9cfa | 2015-01-24 19:52:06 +0200 | [diff] [blame] | 1043 | case WLAN_CIPHER_SUITE_GCMP: |
| 1044 | case WLAN_CIPHER_SUITE_GCMP_256: |
| 1045 | return ieee80211_crypto_gcmp_encrypt(tx); |
Johannes Berg | 3ffc2a9 | 2010-08-27 14:26:52 +0300 | [diff] [blame] | 1046 | default: |
Yoni Divinsky | d32a102 | 2012-01-16 15:18:59 +0200 | [diff] [blame] | 1047 | return ieee80211_crypto_hw_encrypt(tx); |
Johannes Berg | e245494 | 2008-05-15 12:55:28 +0200 | [diff] [blame] | 1048 | } |
| 1049 | |
Johannes Berg | e245494 | 2008-05-15 12:55:28 +0200 | [diff] [blame] | 1050 | return TX_DROP; |
| 1051 | } |
| 1052 | |
Johannes Berg | d9e8a70 | 2008-06-30 15:10:44 +0200 | [diff] [blame] | 1053 | static ieee80211_tx_result debug_noinline |
Johannes Berg | 03f93c3 | 2008-06-25 14:36:27 +0300 | [diff] [blame] | 1054 | ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx) |
| 1055 | { |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 1056 | struct sk_buff *skb; |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 1057 | struct ieee80211_hdr *hdr; |
| 1058 | int next_len; |
| 1059 | bool group_addr; |
Johannes Berg | 03f93c3 | 2008-06-25 14:36:27 +0300 | [diff] [blame] | 1060 | |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 1061 | skb_queue_walk(&tx->skbs, skb) { |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 1062 | hdr = (void *) skb->data; |
Jouni Malinen | 7e0aae4 | 2009-05-19 19:25:58 +0300 | [diff] [blame] | 1063 | if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) |
| 1064 | break; /* must not overwrite AID */ |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 1065 | if (!skb_queue_is_last(&tx->skbs, skb)) { |
| 1066 | struct sk_buff *next = skb_queue_next(&tx->skbs, skb); |
| 1067 | next_len = next->len; |
| 1068 | } else |
| 1069 | next_len = 0; |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 1070 | group_addr = is_multicast_ether_addr(hdr->addr1); |
Johannes Berg | 03f93c3 | 2008-06-25 14:36:27 +0300 | [diff] [blame] | 1071 | |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 1072 | hdr->duration_id = |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 1073 | ieee80211_duration(tx, skb, group_addr, next_len); |
| 1074 | } |
Johannes Berg | 03f93c3 | 2008-06-25 14:36:27 +0300 | [diff] [blame] | 1075 | |
| 1076 | return TX_CONTINUE; |
| 1077 | } |
| 1078 | |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1079 | /* actual transmit path */ |
| 1080 | |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 1081 | static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx, |
| 1082 | struct sk_buff *skb, |
| 1083 | struct ieee80211_tx_info *info, |
| 1084 | struct tid_ampdu_tx *tid_tx, |
| 1085 | int tid) |
| 1086 | { |
| 1087 | bool queued = false; |
Nikolay Martynov | 285fa69 | 2011-11-22 21:50:28 -0500 | [diff] [blame] | 1088 | bool reset_agg_timer = false; |
Helmut Schaa | aa45458 | 2012-03-07 17:20:30 +0100 | [diff] [blame] | 1089 | struct sk_buff *purge_skb = NULL; |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 1090 | |
| 1091 | if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) { |
| 1092 | info->flags |= IEEE80211_TX_CTL_AMPDU; |
Nikolay Martynov | 285fa69 | 2011-11-22 21:50:28 -0500 | [diff] [blame] | 1093 | reset_agg_timer = true; |
Johannes Berg | 0ab3370 | 2010-06-10 10:21:42 +0200 | [diff] [blame] | 1094 | } else if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) { |
| 1095 | /* |
| 1096 | * nothing -- this aggregation session is being started |
| 1097 | * but that might still fail with the driver |
| 1098 | */ |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 1099 | } else if (!tx->sta->sta.txq[tid]) { |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 1100 | spin_lock(&tx->sta->lock); |
| 1101 | /* |
| 1102 | * Need to re-check now, because we may get here |
| 1103 | * |
| 1104 | * 1) in the window during which the setup is actually |
| 1105 | * already done, but not marked yet because not all |
| 1106 | * packets are spliced over to the driver pending |
| 1107 | * queue yet -- if this happened we acquire the lock |
| 1108 | * either before or after the splice happens, but |
| 1109 | * need to recheck which of these cases happened. |
| 1110 | * |
| 1111 | * 2) during session teardown, if the OPERATIONAL bit |
| 1112 | * was cleared due to the teardown but the pointer |
| 1113 | * hasn't been assigned NULL yet (or we loaded it |
| 1114 | * before it was assigned) -- in this case it may |
| 1115 | * now be NULL which means we should just let the |
| 1116 | * packet pass through because splicing the frames |
| 1117 | * back is already done. |
| 1118 | */ |
Johannes Berg | 40b275b | 2011-05-13 14:15:49 +0200 | [diff] [blame] | 1119 | tid_tx = rcu_dereference_protected_tid_tx(tx->sta, tid); |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 1120 | |
| 1121 | if (!tid_tx) { |
| 1122 | /* do nothing, let packet pass through */ |
| 1123 | } else if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) { |
| 1124 | info->flags |= IEEE80211_TX_CTL_AMPDU; |
Nikolay Martynov | 285fa69 | 2011-11-22 21:50:28 -0500 | [diff] [blame] | 1125 | reset_agg_timer = true; |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 1126 | } else { |
| 1127 | queued = true; |
Emmanuel Grumbach | f6d4671 | 2016-03-17 16:51:42 +0200 | [diff] [blame] | 1128 | if (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER) { |
| 1129 | clear_sta_flag(tx->sta, WLAN_STA_SP); |
| 1130 | ps_dbg(tx->sta->sdata, |
| 1131 | "STA %pM aid %d: SP frame queued, close the SP w/o telling the peer\n", |
| 1132 | tx->sta->sta.addr, tx->sta->sta.aid); |
| 1133 | } |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 1134 | info->control.vif = &tx->sdata->vif; |
| 1135 | info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING; |
Emmanuel Grumbach | facde7f | 2016-03-17 16:51:41 +0200 | [diff] [blame] | 1136 | info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS; |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 1137 | __skb_queue_tail(&tid_tx->pending, skb); |
Helmut Schaa | aa45458 | 2012-03-07 17:20:30 +0100 | [diff] [blame] | 1138 | if (skb_queue_len(&tid_tx->pending) > STA_MAX_TX_BUFFER) |
| 1139 | purge_skb = __skb_dequeue(&tid_tx->pending); |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 1140 | } |
| 1141 | spin_unlock(&tx->sta->lock); |
Helmut Schaa | aa45458 | 2012-03-07 17:20:30 +0100 | [diff] [blame] | 1142 | |
| 1143 | if (purge_skb) |
Felix Fietkau | c3e7724 | 2012-10-08 14:39:33 +0200 | [diff] [blame] | 1144 | ieee80211_free_txskb(&tx->local->hw, purge_skb); |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 1145 | } |
| 1146 | |
Nikolay Martynov | 285fa69 | 2011-11-22 21:50:28 -0500 | [diff] [blame] | 1147 | /* reset session timer */ |
Sara Sharon | 914eac2 | 2018-04-20 13:49:19 +0300 | [diff] [blame] | 1148 | if (reset_agg_timer) |
Felix Fietkau | 12d3952f | 2012-03-18 22:58:06 +0100 | [diff] [blame] | 1149 | tid_tx->last_tx = jiffies; |
Nikolay Martynov | 285fa69 | 2011-11-22 21:50:28 -0500 | [diff] [blame] | 1150 | |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 1151 | return queued; |
| 1152 | } |
| 1153 | |
Johannes Berg | 58d4185 | 2007-09-26 17:53:18 +0200 | [diff] [blame] | 1154 | /* |
| 1155 | * initialises @tx |
Johannes Berg | 7c10770 | 2015-03-20 14:18:27 +0100 | [diff] [blame] | 1156 | * pass %NULL for the station if unknown, a valid pointer if known |
| 1157 | * or an ERR_PTR() if the station is known not to exist |
Johannes Berg | 58d4185 | 2007-09-26 17:53:18 +0200 | [diff] [blame] | 1158 | */ |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1159 | static ieee80211_tx_result |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1160 | ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata, |
| 1161 | struct ieee80211_tx_data *tx, |
Johannes Berg | 7c10770 | 2015-03-20 14:18:27 +0100 | [diff] [blame] | 1162 | struct sta_info *sta, struct sk_buff *skb) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1163 | { |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1164 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 58d4185 | 2007-09-26 17:53:18 +0200 | [diff] [blame] | 1165 | struct ieee80211_hdr *hdr; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1166 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Johannes Berg | 68f2b51 | 2011-10-07 14:01:24 +0200 | [diff] [blame] | 1167 | int tid; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1168 | |
| 1169 | memset(tx, 0, sizeof(*tx)); |
| 1170 | tx->skb = skb; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1171 | tx->local = local; |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1172 | tx->sdata = sdata; |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 1173 | __skb_queue_head_init(&tx->skbs); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1174 | |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 1175 | /* |
| 1176 | * If this flag is set to true anywhere, and we get here, |
| 1177 | * we are doing the needed processing, so remove the flag |
| 1178 | * now. |
| 1179 | */ |
| 1180 | info->flags &= ~IEEE80211_TX_INTFL_NEED_TXPROCESSING; |
| 1181 | |
Johannes Berg | 58d4185 | 2007-09-26 17:53:18 +0200 | [diff] [blame] | 1182 | hdr = (struct ieee80211_hdr *) skb->data; |
| 1183 | |
Johannes Berg | 7c10770 | 2015-03-20 14:18:27 +0100 | [diff] [blame] | 1184 | if (likely(sta)) { |
| 1185 | if (!IS_ERR(sta)) |
| 1186 | tx->sta = sta; |
| 1187 | } else { |
| 1188 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { |
| 1189 | tx->sta = rcu_dereference(sdata->u.vlan.sta); |
| 1190 | if (!tx->sta && sdata->wdev.use_4addr) |
| 1191 | return TX_DROP; |
| 1192 | } else if (info->flags & (IEEE80211_TX_INTFL_NL80211_FRAME_TX | |
| 1193 | IEEE80211_TX_CTL_INJECTED) || |
| 1194 | tx->sdata->control_port_protocol == tx->skb->protocol) { |
| 1195 | tx->sta = sta_info_get_bss(sdata, hdr->addr1); |
| 1196 | } |
| 1197 | if (!tx->sta && !is_multicast_ether_addr(hdr->addr1)) |
| 1198 | tx->sta = sta_info_get(sdata, hdr->addr1); |
Felix Fietkau | 3f0e0b2 | 2010-01-08 18:15:13 +0100 | [diff] [blame] | 1199 | } |
Johannes Berg | 58d4185 | 2007-09-26 17:53:18 +0200 | [diff] [blame] | 1200 | |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 1201 | if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) && |
Johannes Berg | 49a5954 | 2011-09-29 16:04:41 +0200 | [diff] [blame] | 1202 | !ieee80211_is_qos_nullfunc(hdr->frame_control) && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1203 | ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) && |
| 1204 | !ieee80211_hw_check(&local->hw, TX_AMPDU_SETUP_IN_HW)) { |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 1205 | struct tid_ampdu_tx *tid_tx; |
| 1206 | |
Sara Sharon | a1f2ba04c | 2018-02-19 14:48:40 +0200 | [diff] [blame] | 1207 | tid = ieee80211_get_tid(hdr); |
Sujith | 8b30b1f | 2008-10-24 09:55:27 +0530 | [diff] [blame] | 1208 | |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 1209 | tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]); |
| 1210 | if (tid_tx) { |
| 1211 | bool queued; |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 1212 | |
Johannes Berg | a622ab7 | 2010-06-10 10:21:39 +0200 | [diff] [blame] | 1213 | queued = ieee80211_tx_prep_agg(tx, skb, info, |
| 1214 | tid_tx, tid); |
| 1215 | |
| 1216 | if (unlikely(queued)) |
| 1217 | return TX_QUEUED; |
| 1218 | } |
Sujith | 8b30b1f | 2008-10-24 09:55:27 +0530 | [diff] [blame] | 1219 | } |
| 1220 | |
Jiri Slaby | badffb7 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 1221 | if (is_multicast_ether_addr(hdr->addr1)) { |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1222 | tx->flags &= ~IEEE80211_TX_UNICAST; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1223 | info->flags |= IEEE80211_TX_CTL_NO_ACK; |
Simon Wunderlich | 6fd67e9 | 2011-11-18 14:20:42 +0100 | [diff] [blame] | 1224 | } else |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1225 | tx->flags |= IEEE80211_TX_UNICAST; |
Johannes Berg | 58d4185 | 2007-09-26 17:53:18 +0200 | [diff] [blame] | 1226 | |
Johannes Berg | a26eb27 | 2011-10-07 14:01:25 +0200 | [diff] [blame] | 1227 | if (!(info->flags & IEEE80211_TX_CTL_DONTFRAG)) { |
| 1228 | if (!(tx->flags & IEEE80211_TX_UNICAST) || |
| 1229 | skb->len + FCS_LEN <= local->hw.wiphy->frag_threshold || |
| 1230 | info->flags & IEEE80211_TX_CTL_AMPDU) |
| 1231 | info->flags |= IEEE80211_TX_CTL_DONTFRAG; |
Johannes Berg | 58d4185 | 2007-09-26 17:53:18 +0200 | [diff] [blame] | 1232 | } |
| 1233 | |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1234 | if (!tx->sta) |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1235 | info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; |
Felix Fietkau | f7418bc | 2015-09-24 14:59:49 +0200 | [diff] [blame] | 1236 | else if (test_and_clear_sta_flag(tx->sta, WLAN_STA_CLEAR_PS_FILT)) { |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1237 | info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT; |
Felix Fietkau | f7418bc | 2015-09-24 14:59:49 +0200 | [diff] [blame] | 1238 | ieee80211_check_fast_xmit(tx->sta); |
| 1239 | } |
Johannes Berg | 58d4185 | 2007-09-26 17:53:18 +0200 | [diff] [blame] | 1240 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1241 | info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1242 | |
Johannes Berg | 9ae54c8 | 2008-01-31 19:48:20 +0100 | [diff] [blame] | 1243 | return TX_CONTINUE; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1244 | } |
| 1245 | |
Michal Kazior | 80a83cf | 2016-05-19 10:37:48 +0200 | [diff] [blame] | 1246 | static struct txq_info *ieee80211_get_txq(struct ieee80211_local *local, |
| 1247 | struct ieee80211_vif *vif, |
Michal Kazior | dbef536 | 2017-01-13 13:32:51 +0100 | [diff] [blame] | 1248 | struct sta_info *sta, |
Michal Kazior | 80a83cf | 2016-05-19 10:37:48 +0200 | [diff] [blame] | 1249 | struct sk_buff *skb) |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 1250 | { |
| 1251 | struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 1252 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 1253 | struct ieee80211_txq *txq = NULL; |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 1254 | |
Felix Fietkau | c3732a7 | 2016-02-28 15:19:53 +0100 | [diff] [blame] | 1255 | if ((info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) || |
| 1256 | (info->control.flags & IEEE80211_TX_CTRL_PS_RESPONSE)) |
Michal Kazior | 80a83cf | 2016-05-19 10:37:48 +0200 | [diff] [blame] | 1257 | return NULL; |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 1258 | |
John Crispin | 50ff477 | 2019-11-25 11:04:37 +0100 | [diff] [blame] | 1259 | if (!(info->control.flags & IEEE80211_TX_CTRL_HW_80211_ENCAP) && |
| 1260 | unlikely(!ieee80211_is_data_present(hdr->frame_control))) { |
Johannes Berg | adf8ed0 | 2018-08-31 11:31:08 +0300 | [diff] [blame] | 1261 | if ((!ieee80211_is_mgmt(hdr->frame_control) || |
Sara Sharon | 0eeb2b6 | 2018-09-05 08:06:09 +0300 | [diff] [blame] | 1262 | ieee80211_is_bufferable_mmpdu(hdr->frame_control) || |
| 1263 | vif->type == NL80211_IFTYPE_STATION) && |
Johannes Berg | adf8ed0 | 2018-08-31 11:31:08 +0300 | [diff] [blame] | 1264 | sta && sta->uploaded) { |
| 1265 | /* |
| 1266 | * This will be NULL if the driver didn't set the |
| 1267 | * opt-in hardware flag. |
| 1268 | */ |
| 1269 | txq = sta->sta.txq[IEEE80211_NUM_TIDS]; |
| 1270 | } |
| 1271 | } else if (sta) { |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 1272 | u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK; |
| 1273 | |
Michal Kazior | dbef536 | 2017-01-13 13:32:51 +0100 | [diff] [blame] | 1274 | if (!sta->uploaded) |
| 1275 | return NULL; |
| 1276 | |
| 1277 | txq = sta->sta.txq[tid]; |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 1278 | } else if (vif) { |
| 1279 | txq = vif->txq; |
| 1280 | } |
| 1281 | |
| 1282 | if (!txq) |
Michal Kazior | 80a83cf | 2016-05-19 10:37:48 +0200 | [diff] [blame] | 1283 | return NULL; |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 1284 | |
Michal Kazior | 80a83cf | 2016-05-19 10:37:48 +0200 | [diff] [blame] | 1285 | return to_txq_info(txq); |
| 1286 | } |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 1287 | |
Michal Kazior | 5caa328 | 2016-05-19 10:37:51 +0200 | [diff] [blame] | 1288 | static void ieee80211_set_skb_enqueue_time(struct sk_buff *skb) |
| 1289 | { |
| 1290 | IEEE80211_SKB_CB(skb)->control.enqueue_time = codel_get_time(); |
| 1291 | } |
| 1292 | |
Michal Kazior | 5caa328 | 2016-05-19 10:37:51 +0200 | [diff] [blame] | 1293 | static u32 codel_skb_len_func(const struct sk_buff *skb) |
| 1294 | { |
| 1295 | return skb->len; |
| 1296 | } |
| 1297 | |
| 1298 | static codel_time_t codel_skb_time_func(const struct sk_buff *skb) |
| 1299 | { |
| 1300 | const struct ieee80211_tx_info *info; |
| 1301 | |
| 1302 | info = (const struct ieee80211_tx_info *)skb->cb; |
| 1303 | return info->control.enqueue_time; |
| 1304 | } |
| 1305 | |
| 1306 | static struct sk_buff *codel_dequeue_func(struct codel_vars *cvars, |
| 1307 | void *ctx) |
| 1308 | { |
| 1309 | struct ieee80211_local *local; |
| 1310 | struct txq_info *txqi; |
| 1311 | struct fq *fq; |
| 1312 | struct fq_flow *flow; |
| 1313 | |
| 1314 | txqi = ctx; |
| 1315 | local = vif_to_sdata(txqi->txq.vif)->local; |
| 1316 | fq = &local->fq; |
| 1317 | |
| 1318 | if (cvars == &txqi->def_cvars) |
| 1319 | flow = &txqi->def_flow; |
| 1320 | else |
| 1321 | flow = &fq->flows[cvars - local->cvars]; |
| 1322 | |
| 1323 | return fq_flow_dequeue(fq, flow); |
| 1324 | } |
| 1325 | |
| 1326 | static void codel_drop_func(struct sk_buff *skb, |
| 1327 | void *ctx) |
| 1328 | { |
| 1329 | struct ieee80211_local *local; |
| 1330 | struct ieee80211_hw *hw; |
| 1331 | struct txq_info *txqi; |
| 1332 | |
| 1333 | txqi = ctx; |
| 1334 | local = vif_to_sdata(txqi->txq.vif)->local; |
| 1335 | hw = &local->hw; |
| 1336 | |
| 1337 | ieee80211_free_txskb(hw, skb); |
| 1338 | } |
| 1339 | |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1340 | static struct sk_buff *fq_tin_dequeue_func(struct fq *fq, |
| 1341 | struct fq_tin *tin, |
| 1342 | struct fq_flow *flow) |
| 1343 | { |
Michal Kazior | 5caa328 | 2016-05-19 10:37:51 +0200 | [diff] [blame] | 1344 | struct ieee80211_local *local; |
| 1345 | struct txq_info *txqi; |
| 1346 | struct codel_vars *cvars; |
| 1347 | struct codel_params *cparams; |
| 1348 | struct codel_stats *cstats; |
| 1349 | |
| 1350 | local = container_of(fq, struct ieee80211_local, fq); |
| 1351 | txqi = container_of(tin, struct txq_info, tin); |
Toke Høiland-Jørgensen | 8d51dbb | 2016-09-12 15:55:43 +0200 | [diff] [blame] | 1352 | cstats = &txqi->cstats; |
Michal Kazior | 5caa328 | 2016-05-19 10:37:51 +0200 | [diff] [blame] | 1353 | |
Toke Høiland-Jørgensen | 484a54c | 2017-04-06 11:38:26 +0200 | [diff] [blame] | 1354 | if (txqi->txq.sta) { |
| 1355 | struct sta_info *sta = container_of(txqi->txq.sta, |
| 1356 | struct sta_info, sta); |
| 1357 | cparams = &sta->cparams; |
| 1358 | } else { |
| 1359 | cparams = &local->cparams; |
| 1360 | } |
| 1361 | |
Michal Kazior | 5caa328 | 2016-05-19 10:37:51 +0200 | [diff] [blame] | 1362 | if (flow == &txqi->def_flow) |
| 1363 | cvars = &txqi->def_cvars; |
| 1364 | else |
| 1365 | cvars = &local->cvars[flow - fq->flows]; |
| 1366 | |
| 1367 | return codel_dequeue(txqi, |
| 1368 | &flow->backlog, |
| 1369 | cparams, |
| 1370 | cvars, |
| 1371 | cstats, |
| 1372 | codel_skb_len_func, |
| 1373 | codel_skb_time_func, |
| 1374 | codel_drop_func, |
| 1375 | codel_dequeue_func); |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1376 | } |
| 1377 | |
| 1378 | static void fq_skb_free_func(struct fq *fq, |
| 1379 | struct fq_tin *tin, |
| 1380 | struct fq_flow *flow, |
| 1381 | struct sk_buff *skb) |
| 1382 | { |
| 1383 | struct ieee80211_local *local; |
| 1384 | |
| 1385 | local = container_of(fq, struct ieee80211_local, fq); |
| 1386 | ieee80211_free_txskb(&local->hw, skb); |
| 1387 | } |
| 1388 | |
| 1389 | static struct fq_flow *fq_flow_get_default_func(struct fq *fq, |
| 1390 | struct fq_tin *tin, |
| 1391 | int idx, |
| 1392 | struct sk_buff *skb) |
| 1393 | { |
| 1394 | struct txq_info *txqi; |
| 1395 | |
| 1396 | txqi = container_of(tin, struct txq_info, tin); |
| 1397 | return &txqi->def_flow; |
| 1398 | } |
| 1399 | |
Michal Kazior | 80a83cf | 2016-05-19 10:37:48 +0200 | [diff] [blame] | 1400 | static void ieee80211_txq_enqueue(struct ieee80211_local *local, |
| 1401 | struct txq_info *txqi, |
| 1402 | struct sk_buff *skb) |
| 1403 | { |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1404 | struct fq *fq = &local->fq; |
| 1405 | struct fq_tin *tin = &txqi->tin; |
Felix Fietkau | f2af2df | 2019-03-16 18:06:32 +0100 | [diff] [blame] | 1406 | u32 flow_idx = fq_flow_idx(fq, skb); |
Michal Kazior | 80a83cf | 2016-05-19 10:37:48 +0200 | [diff] [blame] | 1407 | |
Michal Kazior | 5caa328 | 2016-05-19 10:37:51 +0200 | [diff] [blame] | 1408 | ieee80211_set_skb_enqueue_time(skb); |
Felix Fietkau | f2af2df | 2019-03-16 18:06:32 +0100 | [diff] [blame] | 1409 | |
| 1410 | spin_lock_bh(&fq->lock); |
| 1411 | fq_tin_enqueue(fq, tin, flow_idx, skb, |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1412 | fq_skb_free_func, |
| 1413 | fq_flow_get_default_func); |
Felix Fietkau | f2af2df | 2019-03-16 18:06:32 +0100 | [diff] [blame] | 1414 | spin_unlock_bh(&fq->lock); |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1415 | } |
Michal Kazior | 80a83cf | 2016-05-19 10:37:48 +0200 | [diff] [blame] | 1416 | |
Johannes Berg | 2a9e257 | 2017-10-06 11:53:33 +0200 | [diff] [blame] | 1417 | static bool fq_vlan_filter_func(struct fq *fq, struct fq_tin *tin, |
| 1418 | struct fq_flow *flow, struct sk_buff *skb, |
| 1419 | void *data) |
| 1420 | { |
| 1421 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1422 | |
| 1423 | return info->control.vif == data; |
| 1424 | } |
| 1425 | |
| 1426 | void ieee80211_txq_remove_vlan(struct ieee80211_local *local, |
| 1427 | struct ieee80211_sub_if_data *sdata) |
| 1428 | { |
| 1429 | struct fq *fq = &local->fq; |
| 1430 | struct txq_info *txqi; |
| 1431 | struct fq_tin *tin; |
| 1432 | struct ieee80211_sub_if_data *ap; |
| 1433 | |
| 1434 | if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP_VLAN)) |
| 1435 | return; |
| 1436 | |
| 1437 | ap = container_of(sdata->bss, struct ieee80211_sub_if_data, u.ap); |
| 1438 | |
| 1439 | if (!ap->vif.txq) |
| 1440 | return; |
| 1441 | |
| 1442 | txqi = to_txq_info(ap->vif.txq); |
| 1443 | tin = &txqi->tin; |
| 1444 | |
| 1445 | spin_lock_bh(&fq->lock); |
| 1446 | fq_tin_filter(fq, tin, fq_vlan_filter_func, &sdata->vif, |
| 1447 | fq_skb_free_func); |
| 1448 | spin_unlock_bh(&fq->lock); |
| 1449 | } |
| 1450 | |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1451 | void ieee80211_txq_init(struct ieee80211_sub_if_data *sdata, |
| 1452 | struct sta_info *sta, |
| 1453 | struct txq_info *txqi, int tid) |
| 1454 | { |
| 1455 | fq_tin_init(&txqi->tin); |
| 1456 | fq_flow_init(&txqi->def_flow); |
Michal Kazior | 5caa328 | 2016-05-19 10:37:51 +0200 | [diff] [blame] | 1457 | codel_vars_init(&txqi->def_cvars); |
Toke Høiland-Jørgensen | 8d51dbb | 2016-09-12 15:55:43 +0200 | [diff] [blame] | 1458 | codel_stats_init(&txqi->cstats); |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1459 | __skb_queue_head_init(&txqi->frags); |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 1460 | INIT_LIST_HEAD(&txqi->schedule_order); |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1461 | |
| 1462 | txqi->txq.vif = &sdata->vif; |
| 1463 | |
Johannes Berg | adf8ed0 | 2018-08-31 11:31:08 +0300 | [diff] [blame] | 1464 | if (!sta) { |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1465 | sdata->vif.txq = &txqi->txq; |
| 1466 | txqi->txq.tid = 0; |
| 1467 | txqi->txq.ac = IEEE80211_AC_BE; |
Johannes Berg | adf8ed0 | 2018-08-31 11:31:08 +0300 | [diff] [blame] | 1468 | |
| 1469 | return; |
Michal Kazior | 80a83cf | 2016-05-19 10:37:48 +0200 | [diff] [blame] | 1470 | } |
Johannes Berg | adf8ed0 | 2018-08-31 11:31:08 +0300 | [diff] [blame] | 1471 | |
| 1472 | if (tid == IEEE80211_NUM_TIDS) { |
Sara Sharon | 0eeb2b6 | 2018-09-05 08:06:09 +0300 | [diff] [blame] | 1473 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
| 1474 | /* Drivers need to opt in to the management MPDU TXQ */ |
| 1475 | if (!ieee80211_hw_check(&sdata->local->hw, |
| 1476 | STA_MMPDU_TXQ)) |
| 1477 | return; |
| 1478 | } else if (!ieee80211_hw_check(&sdata->local->hw, |
| 1479 | BUFF_MMPDU_TXQ)) { |
| 1480 | /* Drivers need to opt in to the bufferable MMPDU TXQ */ |
Johannes Berg | adf8ed0 | 2018-08-31 11:31:08 +0300 | [diff] [blame] | 1481 | return; |
Sara Sharon | 0eeb2b6 | 2018-09-05 08:06:09 +0300 | [diff] [blame] | 1482 | } |
Johannes Berg | adf8ed0 | 2018-08-31 11:31:08 +0300 | [diff] [blame] | 1483 | txqi->txq.ac = IEEE80211_AC_VO; |
| 1484 | } else { |
| 1485 | txqi->txq.ac = ieee80211_ac_from_tid(tid); |
| 1486 | } |
| 1487 | |
| 1488 | txqi->txq.sta = &sta->sta; |
| 1489 | txqi->txq.tid = tid; |
| 1490 | sta->sta.txq[tid] = &txqi->txq; |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1491 | } |
Michal Kazior | 80a83cf | 2016-05-19 10:37:48 +0200 | [diff] [blame] | 1492 | |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1493 | void ieee80211_txq_purge(struct ieee80211_local *local, |
| 1494 | struct txq_info *txqi) |
| 1495 | { |
| 1496 | struct fq *fq = &local->fq; |
| 1497 | struct fq_tin *tin = &txqi->tin; |
| 1498 | |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 1499 | spin_lock_bh(&fq->lock); |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1500 | fq_tin_reset(fq, tin, fq_skb_free_func); |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1501 | ieee80211_purge_tx_queue(&local->hw, &txqi->frags); |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 1502 | spin_unlock_bh(&fq->lock); |
| 1503 | |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 1504 | spin_lock_bh(&local->active_txq_lock[txqi->txq.ac]); |
| 1505 | list_del_init(&txqi->schedule_order); |
| 1506 | spin_unlock_bh(&local->active_txq_lock[txqi->txq.ac]); |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1507 | } |
| 1508 | |
Toke Høiland-Jørgensen | 2fe4a29 | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 1509 | void ieee80211_txq_set_params(struct ieee80211_local *local) |
| 1510 | { |
| 1511 | if (local->hw.wiphy->txq_limit) |
| 1512 | local->fq.limit = local->hw.wiphy->txq_limit; |
| 1513 | else |
| 1514 | local->hw.wiphy->txq_limit = local->fq.limit; |
| 1515 | |
| 1516 | if (local->hw.wiphy->txq_memory_limit) |
| 1517 | local->fq.memory_limit = local->hw.wiphy->txq_memory_limit; |
| 1518 | else |
| 1519 | local->hw.wiphy->txq_memory_limit = local->fq.memory_limit; |
| 1520 | |
| 1521 | if (local->hw.wiphy->txq_quantum) |
| 1522 | local->fq.quantum = local->hw.wiphy->txq_quantum; |
| 1523 | else |
| 1524 | local->hw.wiphy->txq_quantum = local->fq.quantum; |
| 1525 | } |
| 1526 | |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1527 | int ieee80211_txq_setup_flows(struct ieee80211_local *local) |
| 1528 | { |
| 1529 | struct fq *fq = &local->fq; |
| 1530 | int ret; |
Michal Kazior | 5caa328 | 2016-05-19 10:37:51 +0200 | [diff] [blame] | 1531 | int i; |
Toke Høiland-Jørgensen | 3ff23cd | 2016-09-23 21:59:11 +0200 | [diff] [blame] | 1532 | bool supp_vht = false; |
| 1533 | enum nl80211_band band; |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1534 | |
| 1535 | if (!local->ops->wake_tx_queue) |
| 1536 | return 0; |
| 1537 | |
| 1538 | ret = fq_init(fq, 4096); |
| 1539 | if (ret) |
| 1540 | return ret; |
| 1541 | |
Toke Høiland-Jørgensen | 3ff23cd | 2016-09-23 21:59:11 +0200 | [diff] [blame] | 1542 | /* |
| 1543 | * If the hardware doesn't support VHT, it is safe to limit the maximum |
| 1544 | * queue size. 4 Mbytes is 64 max-size aggregates in 802.11n. |
| 1545 | */ |
| 1546 | for (band = 0; band < NUM_NL80211_BANDS; band++) { |
| 1547 | struct ieee80211_supported_band *sband; |
| 1548 | |
| 1549 | sband = local->hw.wiphy->bands[band]; |
| 1550 | if (!sband) |
| 1551 | continue; |
| 1552 | |
| 1553 | supp_vht = supp_vht || sband->vht_cap.vht_supported; |
| 1554 | } |
| 1555 | |
| 1556 | if (!supp_vht) |
| 1557 | fq->memory_limit = 4 << 20; /* 4 Mbytes */ |
| 1558 | |
Michal Kazior | 5caa328 | 2016-05-19 10:37:51 +0200 | [diff] [blame] | 1559 | codel_params_init(&local->cparams); |
Michal Kazior | 5caa328 | 2016-05-19 10:37:51 +0200 | [diff] [blame] | 1560 | local->cparams.interval = MS2TIME(100); |
| 1561 | local->cparams.target = MS2TIME(20); |
| 1562 | local->cparams.ecn = true; |
| 1563 | |
| 1564 | local->cvars = kcalloc(fq->flows_cnt, sizeof(local->cvars[0]), |
| 1565 | GFP_KERNEL); |
| 1566 | if (!local->cvars) { |
Michal Kazior | 59a7c82 | 2016-06-29 14:00:34 +0200 | [diff] [blame] | 1567 | spin_lock_bh(&fq->lock); |
Michal Kazior | 5caa328 | 2016-05-19 10:37:51 +0200 | [diff] [blame] | 1568 | fq_reset(fq, fq_skb_free_func); |
Michal Kazior | 59a7c82 | 2016-06-29 14:00:34 +0200 | [diff] [blame] | 1569 | spin_unlock_bh(&fq->lock); |
Michal Kazior | 5caa328 | 2016-05-19 10:37:51 +0200 | [diff] [blame] | 1570 | return -ENOMEM; |
| 1571 | } |
| 1572 | |
| 1573 | for (i = 0; i < fq->flows_cnt; i++) |
| 1574 | codel_vars_init(&local->cvars[i]); |
| 1575 | |
Toke Høiland-Jørgensen | 2fe4a29 | 2018-05-08 13:03:50 +0200 | [diff] [blame] | 1576 | ieee80211_txq_set_params(local); |
| 1577 | |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1578 | return 0; |
| 1579 | } |
| 1580 | |
| 1581 | void ieee80211_txq_teardown_flows(struct ieee80211_local *local) |
| 1582 | { |
| 1583 | struct fq *fq = &local->fq; |
| 1584 | |
| 1585 | if (!local->ops->wake_tx_queue) |
| 1586 | return; |
| 1587 | |
Michal Kazior | 5caa328 | 2016-05-19 10:37:51 +0200 | [diff] [blame] | 1588 | kfree(local->cvars); |
| 1589 | local->cvars = NULL; |
| 1590 | |
Michal Kazior | 59a7c82 | 2016-06-29 14:00:34 +0200 | [diff] [blame] | 1591 | spin_lock_bh(&fq->lock); |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 1592 | fq_reset(fq, fq_skb_free_func); |
Michal Kazior | 59a7c82 | 2016-06-29 14:00:34 +0200 | [diff] [blame] | 1593 | spin_unlock_bh(&fq->lock); |
Felix Fietkau | ba8c3d6 | 2015-03-27 21:30:37 +0100 | [diff] [blame] | 1594 | } |
| 1595 | |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1596 | static bool ieee80211_queue_skb(struct ieee80211_local *local, |
| 1597 | struct ieee80211_sub_if_data *sdata, |
| 1598 | struct sta_info *sta, |
| 1599 | struct sk_buff *skb) |
| 1600 | { |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1601 | struct ieee80211_vif *vif; |
| 1602 | struct txq_info *txqi; |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1603 | |
| 1604 | if (!local->ops->wake_tx_queue || |
| 1605 | sdata->vif.type == NL80211_IFTYPE_MONITOR) |
| 1606 | return false; |
| 1607 | |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1608 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 1609 | sdata = container_of(sdata->bss, |
| 1610 | struct ieee80211_sub_if_data, u.ap); |
| 1611 | |
| 1612 | vif = &sdata->vif; |
Michal Kazior | dbef536 | 2017-01-13 13:32:51 +0100 | [diff] [blame] | 1613 | txqi = ieee80211_get_txq(local, vif, sta, skb); |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1614 | |
| 1615 | if (!txqi) |
| 1616 | return false; |
| 1617 | |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1618 | ieee80211_txq_enqueue(local, txqi, skb); |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1619 | |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 1620 | schedule_and_wake_txq(local, txqi); |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1621 | |
| 1622 | return true; |
| 1623 | } |
| 1624 | |
Johannes Berg | 11127e9 | 2011-11-16 16:02:47 +0100 | [diff] [blame] | 1625 | static bool ieee80211_tx_frags(struct ieee80211_local *local, |
| 1626 | struct ieee80211_vif *vif, |
Johannes Berg | 4fd0328 | 2019-10-01 23:26:35 +0200 | [diff] [blame] | 1627 | struct sta_info *sta, |
Johannes Berg | 11127e9 | 2011-11-16 16:02:47 +0100 | [diff] [blame] | 1628 | struct sk_buff_head *skbs, |
| 1629 | bool txpending) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1630 | { |
Michal Kazior | 80a83cf | 2016-05-19 10:37:48 +0200 | [diff] [blame] | 1631 | struct ieee80211_tx_control control = {}; |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 1632 | struct sk_buff *skb, *tmp; |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1633 | unsigned long flags; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1634 | |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 1635 | skb_queue_walk_safe(skbs, skb, tmp) { |
Johannes Berg | 3a25a8c | 2012-04-03 16:28:50 +0200 | [diff] [blame] | 1636 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1637 | int q = info->hw_queue; |
| 1638 | |
| 1639 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
| 1640 | if (WARN_ON_ONCE(q >= local->hw.queues)) { |
| 1641 | __skb_unlink(skb, skbs); |
Felix Fietkau | c3e7724 | 2012-10-08 14:39:33 +0200 | [diff] [blame] | 1642 | ieee80211_free_txskb(&local->hw, skb); |
Johannes Berg | 3a25a8c | 2012-04-03 16:28:50 +0200 | [diff] [blame] | 1643 | continue; |
| 1644 | } |
| 1645 | #endif |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1646 | |
| 1647 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1648 | if (local->queue_stop_reasons[q] || |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1649 | (!txpending && !skb_queue_empty(&local->pending[q]))) { |
Seth Forshee | 6c17b77 | 2013-02-11 11:21:07 -0600 | [diff] [blame] | 1650 | if (unlikely(info->flags & |
Seth Forshee | a7679ed | 2013-02-25 14:58:05 -0600 | [diff] [blame] | 1651 | IEEE80211_TX_INTFL_OFFCHAN_TX_OK)) { |
| 1652 | if (local->queue_stop_reasons[q] & |
| 1653 | ~BIT(IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL)) { |
| 1654 | /* |
| 1655 | * Drop off-channel frames if queues |
| 1656 | * are stopped for any reason other |
| 1657 | * than off-channel operation. Never |
| 1658 | * queue them. |
| 1659 | */ |
| 1660 | spin_unlock_irqrestore( |
| 1661 | &local->queue_stop_reason_lock, |
| 1662 | flags); |
| 1663 | ieee80211_purge_tx_queue(&local->hw, |
| 1664 | skbs); |
| 1665 | return true; |
| 1666 | } |
| 1667 | } else { |
| 1668 | |
Seth Forshee | 6c17b77 | 2013-02-11 11:21:07 -0600 | [diff] [blame] | 1669 | /* |
Seth Forshee | a7679ed | 2013-02-25 14:58:05 -0600 | [diff] [blame] | 1670 | * Since queue is stopped, queue up frames for |
| 1671 | * later transmission from the tx-pending |
| 1672 | * tasklet when the queue is woken again. |
Seth Forshee | 6c17b77 | 2013-02-11 11:21:07 -0600 | [diff] [blame] | 1673 | */ |
Seth Forshee | a7679ed | 2013-02-25 14:58:05 -0600 | [diff] [blame] | 1674 | if (txpending) |
| 1675 | skb_queue_splice_init(skbs, |
| 1676 | &local->pending[q]); |
| 1677 | else |
| 1678 | skb_queue_splice_tail_init(skbs, |
| 1679 | &local->pending[q]); |
| 1680 | |
| 1681 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, |
| 1682 | flags); |
| 1683 | return false; |
Seth Forshee | 6c17b77 | 2013-02-11 11:21:07 -0600 | [diff] [blame] | 1684 | } |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1685 | } |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1686 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
Tomas Winkler | f8e79dd | 2008-07-24 18:46:44 +0300 | [diff] [blame] | 1687 | |
Johannes Berg | 11127e9 | 2011-11-16 16:02:47 +0100 | [diff] [blame] | 1688 | info->control.vif = vif; |
Johannes Berg | 4fd0328 | 2019-10-01 23:26:35 +0200 | [diff] [blame] | 1689 | control.sta = sta ? &sta->sta : NULL; |
Johannes Berg | ec25acc | 2010-07-22 17:11:28 +0200 | [diff] [blame] | 1690 | |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 1691 | __skb_unlink(skb, skbs); |
Michal Kazior | 80a83cf | 2016-05-19 10:37:48 +0200 | [diff] [blame] | 1692 | drv_tx(local, &control, skb); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1693 | } |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 1694 | |
Johannes Berg | 11127e9 | 2011-11-16 16:02:47 +0100 | [diff] [blame] | 1695 | return true; |
| 1696 | } |
| 1697 | |
| 1698 | /* |
| 1699 | * Returns false if the frame couldn't be transmitted but was queued instead. |
| 1700 | */ |
| 1701 | static bool __ieee80211_tx(struct ieee80211_local *local, |
| 1702 | struct sk_buff_head *skbs, int led_len, |
| 1703 | struct sta_info *sta, bool txpending) |
| 1704 | { |
| 1705 | struct ieee80211_tx_info *info; |
| 1706 | struct ieee80211_sub_if_data *sdata; |
| 1707 | struct ieee80211_vif *vif; |
Johannes Berg | 11127e9 | 2011-11-16 16:02:47 +0100 | [diff] [blame] | 1708 | struct sk_buff *skb; |
| 1709 | bool result = true; |
| 1710 | __le16 fc; |
| 1711 | |
| 1712 | if (WARN_ON(skb_queue_empty(skbs))) |
| 1713 | return true; |
| 1714 | |
| 1715 | skb = skb_peek(skbs); |
| 1716 | fc = ((struct ieee80211_hdr *)skb->data)->frame_control; |
| 1717 | info = IEEE80211_SKB_CB(skb); |
| 1718 | sdata = vif_to_sdata(info->control.vif); |
| 1719 | if (sta && !sta->uploaded) |
| 1720 | sta = NULL; |
| 1721 | |
Johannes Berg | 11127e9 | 2011-11-16 16:02:47 +0100 | [diff] [blame] | 1722 | switch (sdata->vif.type) { |
| 1723 | case NL80211_IFTYPE_MONITOR: |
Aviya Erenfeld | d821218 | 2016-08-29 23:25:15 +0300 | [diff] [blame] | 1724 | if (sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) { |
Johannes Berg | c82b5a7 | 2013-07-14 23:39:20 +0300 | [diff] [blame] | 1725 | vif = &sdata->vif; |
| 1726 | break; |
| 1727 | } |
Johannes Berg | 4b6f1dd | 2012-04-03 14:35:57 +0200 | [diff] [blame] | 1728 | sdata = rcu_dereference(local->monitor_sdata); |
Johannes Berg | 3a25a8c | 2012-04-03 16:28:50 +0200 | [diff] [blame] | 1729 | if (sdata) { |
Johannes Berg | 4b6f1dd | 2012-04-03 14:35:57 +0200 | [diff] [blame] | 1730 | vif = &sdata->vif; |
Johannes Berg | 3a25a8c | 2012-04-03 16:28:50 +0200 | [diff] [blame] | 1731 | info->hw_queue = |
| 1732 | vif->hw_queue[skb_get_queue_mapping(skb)]; |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1733 | } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) { |
Johannes Berg | 63b4d8b | 2015-11-24 15:41:50 +0100 | [diff] [blame] | 1734 | ieee80211_purge_tx_queue(&local->hw, skbs); |
Johannes Berg | 3a25a8c | 2012-04-03 16:28:50 +0200 | [diff] [blame] | 1735 | return true; |
| 1736 | } else |
Johannes Berg | 4b6f1dd | 2012-04-03 14:35:57 +0200 | [diff] [blame] | 1737 | vif = NULL; |
Johannes Berg | 11127e9 | 2011-11-16 16:02:47 +0100 | [diff] [blame] | 1738 | break; |
| 1739 | case NL80211_IFTYPE_AP_VLAN: |
| 1740 | sdata = container_of(sdata->bss, |
| 1741 | struct ieee80211_sub_if_data, u.ap); |
| 1742 | /* fall through */ |
| 1743 | default: |
| 1744 | vif = &sdata->vif; |
| 1745 | break; |
| 1746 | } |
| 1747 | |
Johannes Berg | 4fd0328 | 2019-10-01 23:26:35 +0200 | [diff] [blame] | 1748 | result = ieee80211_tx_frags(local, vif, sta, skbs, txpending); |
Johannes Berg | 11127e9 | 2011-11-16 16:02:47 +0100 | [diff] [blame] | 1749 | |
Johannes Berg | 74e4dbf | 2011-11-16 15:28:57 +0100 | [diff] [blame] | 1750 | ieee80211_tpt_led_trig_tx(local, fc, led_len); |
Johannes Berg | 74e4dbf | 2011-11-16 15:28:57 +0100 | [diff] [blame] | 1751 | |
Johannes Berg | 4db4e0a | 2011-11-24 14:47:36 +0100 | [diff] [blame] | 1752 | WARN_ON_ONCE(!skb_queue_empty(skbs)); |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 1753 | |
Johannes Berg | 11127e9 | 2011-11-16 16:02:47 +0100 | [diff] [blame] | 1754 | return result; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1755 | } |
| 1756 | |
Johannes Berg | 97b045d | 2008-06-20 01:22:30 +0200 | [diff] [blame] | 1757 | /* |
| 1758 | * Invoke TX handlers, return 0 on success and non-zero if the |
| 1759 | * frame was dropped or queued. |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1760 | * |
| 1761 | * The handlers are split into an early and late part. The latter is everything |
| 1762 | * that can be sensitive to reordering, and will be deferred to after packets |
| 1763 | * are dequeued from the intermediate queues (when they are enabled). |
Johannes Berg | 97b045d | 2008-06-20 01:22:30 +0200 | [diff] [blame] | 1764 | */ |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1765 | static int invoke_tx_handlers_early(struct ieee80211_tx_data *tx) |
Johannes Berg | 97b045d | 2008-06-20 01:22:30 +0200 | [diff] [blame] | 1766 | { |
Johannes Berg | 97b045d | 2008-06-20 01:22:30 +0200 | [diff] [blame] | 1767 | ieee80211_tx_result res = TX_DROP; |
Johannes Berg | 97b045d | 2008-06-20 01:22:30 +0200 | [diff] [blame] | 1768 | |
Johannes Berg | 9aa4aee | 2009-10-29 08:43:48 +0100 | [diff] [blame] | 1769 | #define CALL_TXH(txh) \ |
| 1770 | do { \ |
| 1771 | res = txh(tx); \ |
| 1772 | if (res != TX_CONTINUE) \ |
| 1773 | goto txh_done; \ |
| 1774 | } while (0) |
Johannes Berg | 97b045d | 2008-06-20 01:22:30 +0200 | [diff] [blame] | 1775 | |
Kalle Valo | 5c1b98a | 2010-01-12 10:42:46 +0200 | [diff] [blame] | 1776 | CALL_TXH(ieee80211_tx_h_dynamic_ps); |
Johannes Berg | 9aa4aee | 2009-10-29 08:43:48 +0100 | [diff] [blame] | 1777 | CALL_TXH(ieee80211_tx_h_check_assoc); |
| 1778 | CALL_TXH(ieee80211_tx_h_ps_buf); |
Johannes Berg | a621fa4 | 2010-08-27 14:26:54 +0300 | [diff] [blame] | 1779 | CALL_TXH(ieee80211_tx_h_check_control_port_protocol); |
Johannes Berg | 9aa4aee | 2009-10-29 08:43:48 +0100 | [diff] [blame] | 1780 | CALL_TXH(ieee80211_tx_h_select_key); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1781 | if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL)) |
Johannes Berg | af65cd96 | 2009-11-17 18:18:36 +0100 | [diff] [blame] | 1782 | CALL_TXH(ieee80211_tx_h_rate_ctrl); |
Johannes Berg | c6fcf6b | 2010-01-17 01:47:59 +0100 | [diff] [blame] | 1783 | |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1784 | txh_done: |
| 1785 | if (unlikely(res == TX_DROP)) { |
| 1786 | I802_DEBUG_INC(tx->local->tx_handlers_drop); |
| 1787 | if (tx->skb) |
| 1788 | ieee80211_free_txskb(&tx->local->hw, tx->skb); |
| 1789 | else |
| 1790 | ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs); |
| 1791 | return -1; |
| 1792 | } else if (unlikely(res == TX_QUEUED)) { |
| 1793 | I802_DEBUG_INC(tx->local->tx_handlers_queued); |
| 1794 | return -1; |
| 1795 | } |
| 1796 | |
| 1797 | return 0; |
| 1798 | } |
| 1799 | |
| 1800 | /* |
| 1801 | * Late handlers can be called while the sta lock is held. Handlers that can |
| 1802 | * cause packets to be generated will cause deadlock! |
| 1803 | */ |
| 1804 | static int invoke_tx_handlers_late(struct ieee80211_tx_data *tx) |
| 1805 | { |
| 1806 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb); |
| 1807 | ieee80211_tx_result res = TX_CONTINUE; |
| 1808 | |
Johannes Berg | aa5b549 | 2011-12-02 22:08:52 +0100 | [diff] [blame] | 1809 | if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION)) { |
| 1810 | __skb_queue_tail(&tx->skbs, tx->skb); |
| 1811 | tx->skb = NULL; |
Johannes Berg | c6fcf6b | 2010-01-17 01:47:59 +0100 | [diff] [blame] | 1812 | goto txh_done; |
Johannes Berg | aa5b549 | 2011-12-02 22:08:52 +0100 | [diff] [blame] | 1813 | } |
Johannes Berg | c6fcf6b | 2010-01-17 01:47:59 +0100 | [diff] [blame] | 1814 | |
| 1815 | CALL_TXH(ieee80211_tx_h_michael_mic_add); |
Johannes Berg | 9aa4aee | 2009-10-29 08:43:48 +0100 | [diff] [blame] | 1816 | CALL_TXH(ieee80211_tx_h_sequence); |
| 1817 | CALL_TXH(ieee80211_tx_h_fragment); |
Johannes Berg | d9e8a70 | 2008-06-30 15:10:44 +0200 | [diff] [blame] | 1818 | /* handlers after fragment must be aware of tx info fragmentation! */ |
Johannes Berg | 9aa4aee | 2009-10-29 08:43:48 +0100 | [diff] [blame] | 1819 | CALL_TXH(ieee80211_tx_h_stats); |
| 1820 | CALL_TXH(ieee80211_tx_h_encrypt); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1821 | if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL)) |
Arik Nemtsov | 8fd369e | 2011-01-31 22:29:12 +0200 | [diff] [blame] | 1822 | CALL_TXH(ieee80211_tx_h_calculate_duration); |
Johannes Berg | d9e8a70 | 2008-06-30 15:10:44 +0200 | [diff] [blame] | 1823 | #undef CALL_TXH |
| 1824 | |
| 1825 | txh_done: |
Johannes Berg | 97b045d | 2008-06-20 01:22:30 +0200 | [diff] [blame] | 1826 | if (unlikely(res == TX_DROP)) { |
Tomas Winkler | 5479d0e | 2008-06-28 03:15:03 +0300 | [diff] [blame] | 1827 | I802_DEBUG_INC(tx->local->tx_handlers_drop); |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 1828 | if (tx->skb) |
Felix Fietkau | c3e7724 | 2012-10-08 14:39:33 +0200 | [diff] [blame] | 1829 | ieee80211_free_txskb(&tx->local->hw, tx->skb); |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 1830 | else |
Felix Fietkau | 1f98ab7 | 2012-11-10 03:44:14 +0100 | [diff] [blame] | 1831 | ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs); |
Johannes Berg | 97b045d | 2008-06-20 01:22:30 +0200 | [diff] [blame] | 1832 | return -1; |
| 1833 | } else if (unlikely(res == TX_QUEUED)) { |
Tomas Winkler | 5479d0e | 2008-06-28 03:15:03 +0300 | [diff] [blame] | 1834 | I802_DEBUG_INC(tx->local->tx_handlers_queued); |
Johannes Berg | 97b045d | 2008-06-20 01:22:30 +0200 | [diff] [blame] | 1835 | return -1; |
| 1836 | } |
| 1837 | |
| 1838 | return 0; |
| 1839 | } |
| 1840 | |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1841 | static int invoke_tx_handlers(struct ieee80211_tx_data *tx) |
| 1842 | { |
| 1843 | int r = invoke_tx_handlers_early(tx); |
| 1844 | |
| 1845 | if (r) |
| 1846 | return r; |
| 1847 | return invoke_tx_handlers_late(tx); |
| 1848 | } |
| 1849 | |
Felix Fietkau | 06be6b1 | 2013-10-14 18:01:00 +0200 | [diff] [blame] | 1850 | bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw, |
| 1851 | struct ieee80211_vif *vif, struct sk_buff *skb, |
| 1852 | int band, struct ieee80211_sta **sta) |
| 1853 | { |
| 1854 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 1855 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 1856 | struct ieee80211_tx_data tx; |
Johannes Berg | 88724a8 | 2015-03-01 09:10:12 +0200 | [diff] [blame] | 1857 | struct sk_buff *skb2; |
Felix Fietkau | 06be6b1 | 2013-10-14 18:01:00 +0200 | [diff] [blame] | 1858 | |
Johannes Berg | 7c10770 | 2015-03-20 14:18:27 +0100 | [diff] [blame] | 1859 | if (ieee80211_tx_prepare(sdata, &tx, NULL, skb) == TX_DROP) |
Felix Fietkau | 06be6b1 | 2013-10-14 18:01:00 +0200 | [diff] [blame] | 1860 | return false; |
| 1861 | |
| 1862 | info->band = band; |
| 1863 | info->control.vif = vif; |
| 1864 | info->hw_queue = vif->hw_queue[skb_get_queue_mapping(skb)]; |
| 1865 | |
| 1866 | if (invoke_tx_handlers(&tx)) |
| 1867 | return false; |
| 1868 | |
| 1869 | if (sta) { |
| 1870 | if (tx.sta) |
| 1871 | *sta = &tx.sta->sta; |
| 1872 | else |
| 1873 | *sta = NULL; |
| 1874 | } |
| 1875 | |
Johannes Berg | 88724a8 | 2015-03-01 09:10:12 +0200 | [diff] [blame] | 1876 | /* this function isn't suitable for fragmented data frames */ |
| 1877 | skb2 = __skb_dequeue(&tx.skbs); |
| 1878 | if (WARN_ON(skb2 != skb || !skb_queue_empty(&tx.skbs))) { |
| 1879 | ieee80211_free_txskb(hw, skb2); |
| 1880 | ieee80211_purge_tx_queue(hw, &tx.skbs); |
| 1881 | return false; |
| 1882 | } |
| 1883 | |
Felix Fietkau | 06be6b1 | 2013-10-14 18:01:00 +0200 | [diff] [blame] | 1884 | return true; |
| 1885 | } |
| 1886 | EXPORT_SYMBOL(ieee80211_tx_prepare_skb); |
| 1887 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1888 | /* |
| 1889 | * Returns false if the frame couldn't be transmitted but was queued instead. |
| 1890 | */ |
| 1891 | static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 7c10770 | 2015-03-20 14:18:27 +0100 | [diff] [blame] | 1892 | struct sta_info *sta, struct sk_buff *skb, |
Johannes Berg | b9771d4 | 2018-05-28 15:47:41 +0200 | [diff] [blame] | 1893 | bool txpending, u32 txdata_flags) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1894 | { |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1895 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 1896 | struct ieee80211_tx_data tx; |
Johannes Berg | 97b045d | 2008-06-20 01:22:30 +0200 | [diff] [blame] | 1897 | ieee80211_tx_result res_prepare; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1898 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1899 | bool result = true; |
Johannes Berg | 74e4dbf | 2011-11-16 15:28:57 +0100 | [diff] [blame] | 1900 | int led_len; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1901 | |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1902 | if (unlikely(skb->len < 10)) { |
| 1903 | dev_kfree_skb(skb); |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1904 | return true; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1905 | } |
| 1906 | |
Johannes Berg | 58d4185 | 2007-09-26 17:53:18 +0200 | [diff] [blame] | 1907 | /* initialises tx */ |
Johannes Berg | 74e4dbf | 2011-11-16 15:28:57 +0100 | [diff] [blame] | 1908 | led_len = skb->len; |
Johannes Berg | 7c10770 | 2015-03-20 14:18:27 +0100 | [diff] [blame] | 1909 | res_prepare = ieee80211_tx_prepare(sdata, &tx, sta, skb); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1910 | |
Johannes Berg | b9771d4 | 2018-05-28 15:47:41 +0200 | [diff] [blame] | 1911 | tx.flags |= txdata_flags; |
| 1912 | |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 1913 | if (unlikely(res_prepare == TX_DROP)) { |
Felix Fietkau | c3e7724 | 2012-10-08 14:39:33 +0200 | [diff] [blame] | 1914 | ieee80211_free_txskb(&local->hw, skb); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1915 | return true; |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 1916 | } else if (unlikely(res_prepare == TX_QUEUED)) { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1917 | return true; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1918 | } |
| 1919 | |
Johannes Berg | 3a25a8c | 2012-04-03 16:28:50 +0200 | [diff] [blame] | 1920 | /* set up hw_queue value early */ |
| 1921 | if (!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) || |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1922 | !ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) |
Johannes Berg | 3a25a8c | 2012-04-03 16:28:50 +0200 | [diff] [blame] | 1923 | info->hw_queue = |
| 1924 | sdata->vif.hw_queue[skb_get_queue_mapping(skb)]; |
| 1925 | |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1926 | if (invoke_tx_handlers_early(&tx)) |
Bob Copeland | 6eae4a6 | 2018-09-05 06:22:59 -0400 | [diff] [blame] | 1927 | return true; |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 1928 | |
| 1929 | if (ieee80211_queue_skb(local, sdata, tx.sta, tx.skb)) |
| 1930 | return true; |
| 1931 | |
| 1932 | if (!invoke_tx_handlers_late(&tx)) |
Johannes Berg | 74e4dbf | 2011-11-16 15:28:57 +0100 | [diff] [blame] | 1933 | result = __ieee80211_tx(local, &tx.skbs, led_len, |
| 1934 | tx.sta, txpending); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 1935 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 1936 | return result; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | /* device xmit handlers */ |
| 1940 | |
Yogesh Ashok Powar | 3bff186 | 2011-06-28 18:41:37 +0530 | [diff] [blame] | 1941 | static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 1942 | struct sk_buff *skb, |
| 1943 | int head_need, bool may_encrypt) |
| 1944 | { |
Yogesh Ashok Powar | 3bff186 | 2011-06-28 18:41:37 +0530 | [diff] [blame] | 1945 | struct ieee80211_local *local = sdata->local; |
Felix Fietkau | 9d0f50b | 2019-01-29 11:10:57 +0100 | [diff] [blame] | 1946 | struct ieee80211_hdr *hdr; |
| 1947 | bool enc_tailroom; |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 1948 | int tail_need = 0; |
| 1949 | |
Felix Fietkau | 9d0f50b | 2019-01-29 11:10:57 +0100 | [diff] [blame] | 1950 | hdr = (struct ieee80211_hdr *) skb->data; |
| 1951 | enc_tailroom = may_encrypt && |
| 1952 | (sdata->crypto_tx_tailroom_needed_cnt || |
| 1953 | ieee80211_is_mgmt(hdr->frame_control)); |
| 1954 | |
| 1955 | if (enc_tailroom) { |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 1956 | tail_need = IEEE80211_ENCRYPT_TAILROOM; |
| 1957 | tail_need -= skb_tailroom(skb); |
| 1958 | tail_need = max_t(int, tail_need, 0); |
| 1959 | } |
| 1960 | |
Ido Yariv | c70f59a | 2014-07-29 15:39:14 +0300 | [diff] [blame] | 1961 | if (skb_cloned(skb) && |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 1962 | (!ieee80211_hw_check(&local->hw, SUPPORTS_CLONED_SKBS) || |
Felix Fietkau | 9d0f50b | 2019-01-29 11:10:57 +0100 | [diff] [blame] | 1963 | !skb_clone_writable(skb, ETH_HLEN) || enc_tailroom)) |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 1964 | I802_DEBUG_INC(local->tx_expand_skb_head_cloned); |
Felix Fietkau | 4cd06a3 | 2010-12-18 19:30:49 +0100 | [diff] [blame] | 1965 | else if (head_need || tail_need) |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 1966 | I802_DEBUG_INC(local->tx_expand_skb_head); |
Felix Fietkau | 4cd06a3 | 2010-12-18 19:30:49 +0100 | [diff] [blame] | 1967 | else |
| 1968 | return 0; |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 1969 | |
| 1970 | if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) { |
Joe Perches | 0fb9a9e | 2010-08-20 16:25:38 -0700 | [diff] [blame] | 1971 | wiphy_debug(local->hw.wiphy, |
| 1972 | "failed to reallocate TX buffer\n"); |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 1973 | return -ENOMEM; |
| 1974 | } |
| 1975 | |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 1976 | return 0; |
| 1977 | } |
| 1978 | |
Johannes Berg | 7c10770 | 2015-03-20 14:18:27 +0100 | [diff] [blame] | 1979 | void ieee80211_xmit(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | b9771d4 | 2018-05-28 15:47:41 +0200 | [diff] [blame] | 1980 | struct sta_info *sta, struct sk_buff *skb, |
| 1981 | u32 txdata_flags) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1982 | { |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1983 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 1984 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Colin Ian King | 11b05ba | 2018-02-02 16:31:42 +0000 | [diff] [blame] | 1985 | struct ieee80211_hdr *hdr; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1986 | int headroom; |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 1987 | bool may_encrypt; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 1988 | |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1989 | may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT); |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 1990 | |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1991 | headroom = local->tx_headroom; |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 1992 | if (may_encrypt) |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 1993 | headroom += sdata->encrypt_headroom; |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 1994 | headroom -= skb_headroom(skb); |
| 1995 | headroom = max_t(int, 0, headroom); |
| 1996 | |
Yogesh Ashok Powar | 3bff186 | 2011-06-28 18:41:37 +0530 | [diff] [blame] | 1997 | if (ieee80211_skb_resize(sdata, skb, headroom, may_encrypt)) { |
Felix Fietkau | c3e7724 | 2012-10-08 14:39:33 +0200 | [diff] [blame] | 1998 | ieee80211_free_txskb(&local->hw, skb); |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 1999 | return; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2000 | } |
| 2001 | |
Steve deRosier | 740c1aa | 2010-09-11 20:01:31 -0700 | [diff] [blame] | 2002 | hdr = (struct ieee80211_hdr *) skb->data; |
Johannes Berg | 5061b0c | 2009-07-14 00:33:34 +0200 | [diff] [blame] | 2003 | info->control.vif = &sdata->vif; |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 2004 | |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 2005 | if (ieee80211_vif_is_mesh(&sdata->vif)) { |
| 2006 | if (ieee80211_is_data(hdr->frame_control) && |
| 2007 | is_unicast_ether_addr(hdr->addr1)) { |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 2008 | if (mesh_nexthop_resolve(sdata, skb)) |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 2009 | return; /* skb queued: don't free */ |
| 2010 | } else { |
| 2011 | ieee80211_mps_set_frame_flags(sdata, NULL, hdr); |
| 2012 | } |
Johannes Berg | 98aed9f | 2012-03-27 14:18:36 +0200 | [diff] [blame] | 2013 | } |
Javier Cardona | cca8949 | 2009-08-10 17:29:29 -0700 | [diff] [blame] | 2014 | |
Javier Cardona | 2154c81c | 2011-09-07 17:49:53 -0700 | [diff] [blame] | 2015 | ieee80211_set_qos_hdr(sdata, skb); |
Johannes Berg | b9771d4 | 2018-05-28 15:47:41 +0200 | [diff] [blame] | 2016 | ieee80211_tx(sdata, sta, skb, false, txdata_flags); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2017 | } |
| 2018 | |
Sven Eckelmann | dfdfc2b | 2016-01-26 17:11:13 +0100 | [diff] [blame] | 2019 | static bool ieee80211_parse_tx_radiotap(struct ieee80211_local *local, |
| 2020 | struct sk_buff *skb) |
Johannes Berg | 73b9f03 | 2011-10-07 14:01:26 +0200 | [diff] [blame] | 2021 | { |
| 2022 | struct ieee80211_radiotap_iterator iterator; |
| 2023 | struct ieee80211_radiotap_header *rthdr = |
| 2024 | (struct ieee80211_radiotap_header *) skb->data; |
| 2025 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Sven Eckelmann | dfdfc2b | 2016-01-26 17:11:13 +0100 | [diff] [blame] | 2026 | struct ieee80211_supported_band *sband = |
| 2027 | local->hw.wiphy->bands[info->band]; |
Johannes Berg | 73b9f03 | 2011-10-07 14:01:26 +0200 | [diff] [blame] | 2028 | int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len, |
| 2029 | NULL); |
| 2030 | u16 txflags; |
Sven Eckelmann | dfdfc2b | 2016-01-26 17:11:13 +0100 | [diff] [blame] | 2031 | u16 rate = 0; |
| 2032 | bool rate_found = false; |
| 2033 | u8 rate_retries = 0; |
| 2034 | u16 rate_flags = 0; |
Sven Eckelmann | f66b60f | 2016-02-24 16:25:49 +0100 | [diff] [blame] | 2035 | u8 mcs_known, mcs_flags, mcs_bw; |
Lorenzo Bianconi | 646e76b | 2016-02-23 15:43:35 +0100 | [diff] [blame] | 2036 | u16 vht_known; |
| 2037 | u8 vht_mcs = 0, vht_nss = 0; |
Sven Eckelmann | dfdfc2b | 2016-01-26 17:11:13 +0100 | [diff] [blame] | 2038 | int i; |
Johannes Berg | 73b9f03 | 2011-10-07 14:01:26 +0200 | [diff] [blame] | 2039 | |
| 2040 | info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | |
| 2041 | IEEE80211_TX_CTL_DONTFRAG; |
| 2042 | |
| 2043 | /* |
| 2044 | * for every radiotap entry that is present |
| 2045 | * (ieee80211_radiotap_iterator_next returns -ENOENT when no more |
| 2046 | * entries present, or -EINVAL on error) |
| 2047 | */ |
| 2048 | |
| 2049 | while (!ret) { |
| 2050 | ret = ieee80211_radiotap_iterator_next(&iterator); |
| 2051 | |
| 2052 | if (ret) |
| 2053 | continue; |
| 2054 | |
| 2055 | /* see if this argument is something we can use */ |
| 2056 | switch (iterator.this_arg_index) { |
| 2057 | /* |
| 2058 | * You must take care when dereferencing iterator.this_arg |
| 2059 | * for multibyte types... the pointer is not aligned. Use |
| 2060 | * get_unaligned((type *)iterator.this_arg) to dereference |
| 2061 | * iterator.this_arg for type "type" safely on all arches. |
| 2062 | */ |
| 2063 | case IEEE80211_RADIOTAP_FLAGS: |
| 2064 | if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) { |
| 2065 | /* |
| 2066 | * this indicates that the skb we have been |
| 2067 | * handed has the 32-bit FCS CRC at the end... |
| 2068 | * we should react to that by snipping it off |
| 2069 | * because it will be recomputed and added |
| 2070 | * on transmission |
| 2071 | */ |
| 2072 | if (skb->len < (iterator._max_length + FCS_LEN)) |
| 2073 | return false; |
| 2074 | |
| 2075 | skb_trim(skb, skb->len - FCS_LEN); |
| 2076 | } |
| 2077 | if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP) |
| 2078 | info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 2079 | if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG) |
| 2080 | info->flags &= ~IEEE80211_TX_CTL_DONTFRAG; |
| 2081 | break; |
| 2082 | |
| 2083 | case IEEE80211_RADIOTAP_TX_FLAGS: |
| 2084 | txflags = get_unaligned_le16(iterator.this_arg); |
| 2085 | if (txflags & IEEE80211_RADIOTAP_F_TX_NOACK) |
| 2086 | info->flags |= IEEE80211_TX_CTL_NO_ACK; |
| 2087 | break; |
| 2088 | |
Sven Eckelmann | dfdfc2b | 2016-01-26 17:11:13 +0100 | [diff] [blame] | 2089 | case IEEE80211_RADIOTAP_RATE: |
| 2090 | rate = *iterator.this_arg; |
| 2091 | rate_flags = 0; |
| 2092 | rate_found = true; |
| 2093 | break; |
| 2094 | |
| 2095 | case IEEE80211_RADIOTAP_DATA_RETRIES: |
| 2096 | rate_retries = *iterator.this_arg; |
| 2097 | break; |
| 2098 | |
| 2099 | case IEEE80211_RADIOTAP_MCS: |
| 2100 | mcs_known = iterator.this_arg[0]; |
| 2101 | mcs_flags = iterator.this_arg[1]; |
| 2102 | if (!(mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_MCS)) |
| 2103 | break; |
| 2104 | |
| 2105 | rate_found = true; |
| 2106 | rate = iterator.this_arg[2]; |
| 2107 | rate_flags = IEEE80211_TX_RC_MCS; |
| 2108 | |
| 2109 | if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_GI && |
| 2110 | mcs_flags & IEEE80211_RADIOTAP_MCS_SGI) |
| 2111 | rate_flags |= IEEE80211_TX_RC_SHORT_GI; |
| 2112 | |
Sven Eckelmann | f66b60f | 2016-02-24 16:25:49 +0100 | [diff] [blame] | 2113 | mcs_bw = mcs_flags & IEEE80211_RADIOTAP_MCS_BW_MASK; |
Sven Eckelmann | dfdfc2b | 2016-01-26 17:11:13 +0100 | [diff] [blame] | 2114 | if (mcs_known & IEEE80211_RADIOTAP_MCS_HAVE_BW && |
Sven Eckelmann | f66b60f | 2016-02-24 16:25:49 +0100 | [diff] [blame] | 2115 | mcs_bw == IEEE80211_RADIOTAP_MCS_BW_40) |
Sven Eckelmann | dfdfc2b | 2016-01-26 17:11:13 +0100 | [diff] [blame] | 2116 | rate_flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; |
| 2117 | break; |
| 2118 | |
Lorenzo Bianconi | 646e76b | 2016-02-23 15:43:35 +0100 | [diff] [blame] | 2119 | case IEEE80211_RADIOTAP_VHT: |
| 2120 | vht_known = get_unaligned_le16(iterator.this_arg); |
| 2121 | rate_found = true; |
| 2122 | |
| 2123 | rate_flags = IEEE80211_TX_RC_VHT_MCS; |
| 2124 | if ((vht_known & IEEE80211_RADIOTAP_VHT_KNOWN_GI) && |
| 2125 | (iterator.this_arg[2] & |
| 2126 | IEEE80211_RADIOTAP_VHT_FLAG_SGI)) |
| 2127 | rate_flags |= IEEE80211_TX_RC_SHORT_GI; |
| 2128 | if (vht_known & |
| 2129 | IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH) { |
| 2130 | if (iterator.this_arg[3] == 1) |
| 2131 | rate_flags |= |
| 2132 | IEEE80211_TX_RC_40_MHZ_WIDTH; |
| 2133 | else if (iterator.this_arg[3] == 4) |
| 2134 | rate_flags |= |
| 2135 | IEEE80211_TX_RC_80_MHZ_WIDTH; |
| 2136 | else if (iterator.this_arg[3] == 11) |
| 2137 | rate_flags |= |
| 2138 | IEEE80211_TX_RC_160_MHZ_WIDTH; |
| 2139 | } |
| 2140 | |
| 2141 | vht_mcs = iterator.this_arg[4] >> 4; |
| 2142 | vht_nss = iterator.this_arg[4] & 0xF; |
| 2143 | break; |
| 2144 | |
Johannes Berg | 73b9f03 | 2011-10-07 14:01:26 +0200 | [diff] [blame] | 2145 | /* |
| 2146 | * Please update the file |
Mauro Carvalho Chehab | 429ff87 | 2020-04-30 18:03:59 +0200 | [diff] [blame] | 2147 | * Documentation/networking/mac80211-injection.rst |
Johannes Berg | 73b9f03 | 2011-10-07 14:01:26 +0200 | [diff] [blame] | 2148 | * when parsing new fields here. |
| 2149 | */ |
| 2150 | |
| 2151 | default: |
| 2152 | break; |
| 2153 | } |
| 2154 | } |
| 2155 | |
| 2156 | if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */ |
| 2157 | return false; |
| 2158 | |
Sven Eckelmann | dfdfc2b | 2016-01-26 17:11:13 +0100 | [diff] [blame] | 2159 | if (rate_found) { |
| 2160 | info->control.flags |= IEEE80211_TX_CTRL_RATE_INJECT; |
| 2161 | |
| 2162 | for (i = 0; i < IEEE80211_TX_MAX_RATES; i++) { |
| 2163 | info->control.rates[i].idx = -1; |
| 2164 | info->control.rates[i].flags = 0; |
| 2165 | info->control.rates[i].count = 0; |
| 2166 | } |
| 2167 | |
| 2168 | if (rate_flags & IEEE80211_TX_RC_MCS) { |
| 2169 | info->control.rates[0].idx = rate; |
Lorenzo Bianconi | 646e76b | 2016-02-23 15:43:35 +0100 | [diff] [blame] | 2170 | } else if (rate_flags & IEEE80211_TX_RC_VHT_MCS) { |
| 2171 | ieee80211_rate_set_vht(info->control.rates, vht_mcs, |
| 2172 | vht_nss); |
Sven Eckelmann | dfdfc2b | 2016-01-26 17:11:13 +0100 | [diff] [blame] | 2173 | } else { |
| 2174 | for (i = 0; i < sband->n_bitrates; i++) { |
| 2175 | if (rate * 5 != sband->bitrates[i].bitrate) |
| 2176 | continue; |
| 2177 | |
| 2178 | info->control.rates[0].idx = i; |
| 2179 | break; |
| 2180 | } |
| 2181 | } |
| 2182 | |
Felix Fietkau | 07310a6 | 2016-03-02 15:54:51 +0100 | [diff] [blame] | 2183 | if (info->control.rates[0].idx < 0) |
| 2184 | info->control.flags &= ~IEEE80211_TX_CTRL_RATE_INJECT; |
| 2185 | |
Sven Eckelmann | dfdfc2b | 2016-01-26 17:11:13 +0100 | [diff] [blame] | 2186 | info->control.rates[0].flags = rate_flags; |
| 2187 | info->control.rates[0].count = min_t(u8, rate_retries + 1, |
| 2188 | local->hw.max_rate_tries); |
| 2189 | } |
| 2190 | |
Johannes Berg | 73b9f03 | 2011-10-07 14:01:26 +0200 | [diff] [blame] | 2191 | /* |
| 2192 | * remove the radiotap header |
| 2193 | * iterator->_max_length was sanity-checked against |
| 2194 | * skb->len by iterator init |
| 2195 | */ |
| 2196 | skb_pull(skb, iterator._max_length); |
| 2197 | |
| 2198 | return true; |
| 2199 | } |
| 2200 | |
Stephen Hemminger | d0cf9c0 | 2009-08-31 19:50:57 +0000 | [diff] [blame] | 2201 | netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb, |
| 2202 | struct net_device *dev) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2203 | { |
| 2204 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2205 | struct ieee80211_chanctx_conf *chanctx_conf; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2206 | struct ieee80211_radiotap_header *prthdr = |
| 2207 | (struct ieee80211_radiotap_header *)skb->data; |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 2208 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Helmut Schaa | f75f5c6 | 2011-08-01 11:32:52 +0200 | [diff] [blame] | 2209 | struct ieee80211_hdr *hdr; |
Johannes Berg | 5d9cf4a | 2011-10-07 14:01:23 +0200 | [diff] [blame] | 2210 | struct ieee80211_sub_if_data *tmp_sdata, *sdata; |
Janusz Dziedzic | b493283 | 2014-06-05 08:12:57 +0200 | [diff] [blame] | 2211 | struct cfg80211_chan_def *chandef; |
Andy Green | 9b8a74e | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2212 | u16 len_rthdr; |
Johannes Berg | 5d9cf4a | 2011-10-07 14:01:23 +0200 | [diff] [blame] | 2213 | int hdrlen; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2214 | |
Andy Green | 9b8a74e | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2215 | /* check for not even having the fixed radiotap header part */ |
| 2216 | if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header))) |
| 2217 | goto fail; /* too short to be possibly valid */ |
| 2218 | |
| 2219 | /* is it a header version we can trust to find length from? */ |
| 2220 | if (unlikely(prthdr->it_version)) |
| 2221 | goto fail; /* only version 0 is supported */ |
| 2222 | |
| 2223 | /* then there must be a radiotap header with a length we can use */ |
| 2224 | len_rthdr = ieee80211_get_radiotap_len(skb->data); |
| 2225 | |
| 2226 | /* does the skb contain enough to deliver on the alleged length? */ |
| 2227 | if (unlikely(skb->len < len_rthdr)) |
| 2228 | goto fail; /* skb too short for claimed rt header extent */ |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2229 | |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2230 | /* |
| 2231 | * fix up the pointers accounting for the radiotap |
| 2232 | * header still being in there. We are being given |
| 2233 | * a precooked IEEE80211 header so no need for |
| 2234 | * normal processing |
| 2235 | */ |
Andy Green | 9b8a74e | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2236 | skb_set_mac_header(skb, len_rthdr); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2237 | /* |
Andy Green | 9b8a74e | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2238 | * these are just fixed to the end of the rt area since we |
| 2239 | * don't have any better information and at this point, nobody cares |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2240 | */ |
Andy Green | 9b8a74e | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2241 | skb_set_network_header(skb, len_rthdr); |
| 2242 | skb_set_transport_header(skb, len_rthdr); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2243 | |
Johannes Berg | 5d9cf4a | 2011-10-07 14:01:23 +0200 | [diff] [blame] | 2244 | if (skb->len < len_rthdr + 2) |
| 2245 | goto fail; |
| 2246 | |
| 2247 | hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr); |
| 2248 | hdrlen = ieee80211_hdrlen(hdr->frame_control); |
| 2249 | |
| 2250 | if (skb->len < len_rthdr + hdrlen) |
| 2251 | goto fail; |
| 2252 | |
Helmut Schaa | f75f5c6 | 2011-08-01 11:32:52 +0200 | [diff] [blame] | 2253 | /* |
| 2254 | * Initialize skb->protocol if the injected frame is a data frame |
| 2255 | * carrying a rfc1042 header |
| 2256 | */ |
Johannes Berg | 5d9cf4a | 2011-10-07 14:01:23 +0200 | [diff] [blame] | 2257 | if (ieee80211_is_data(hdr->frame_control) && |
| 2258 | skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) { |
| 2259 | u8 *payload = (u8 *)hdr + hdrlen; |
| 2260 | |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2261 | if (ether_addr_equal(payload, rfc1042_header)) |
Johannes Berg | 5d9cf4a | 2011-10-07 14:01:23 +0200 | [diff] [blame] | 2262 | skb->protocol = cpu_to_be16((payload[6] << 8) | |
| 2263 | payload[7]); |
Helmut Schaa | f75f5c6 | 2011-08-01 11:32:52 +0200 | [diff] [blame] | 2264 | } |
| 2265 | |
Fredrik Olofsson | 753ffad | 2019-11-19 14:34:51 +0100 | [diff] [blame] | 2266 | /* |
| 2267 | * Initialize skb->priority for QoS frames. This is put in the TID field |
| 2268 | * of the frame before passing it to the driver. |
| 2269 | */ |
| 2270 | if (ieee80211_is_data_qos(hdr->frame_control)) { |
| 2271 | u8 *p = ieee80211_get_qos_ctl(hdr); |
| 2272 | skb->priority = *p & IEEE80211_QOS_CTL_TAG1D_MASK; |
| 2273 | } |
| 2274 | |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 2275 | memset(info, 0, sizeof(*info)); |
| 2276 | |
Johannes Berg | 5d9cf4a | 2011-10-07 14:01:23 +0200 | [diff] [blame] | 2277 | info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS | |
Johannes Berg | 73b9f03 | 2011-10-07 14:01:26 +0200 | [diff] [blame] | 2278 | IEEE80211_TX_CTL_INJECTED; |
| 2279 | |
Johannes Berg | 5d9cf4a | 2011-10-07 14:01:23 +0200 | [diff] [blame] | 2280 | rcu_read_lock(); |
| 2281 | |
| 2282 | /* |
| 2283 | * We process outgoing injected frames that have a local address |
| 2284 | * we handle as though they are non-injected frames. |
| 2285 | * This code here isn't entirely correct, the local MAC address |
| 2286 | * isn't always enough to find the interface to use; for proper |
| 2287 | * VLAN/WDS support we will need a different mechanism (which |
| 2288 | * likely isn't going to be monitor interfaces). |
Johannes Berg | b226a82 | 2019-11-22 12:42:42 +0100 | [diff] [blame] | 2289 | * |
| 2290 | * This is necessary, for example, for old hostapd versions that |
| 2291 | * don't use nl80211-based management TX/RX. |
Johannes Berg | 5d9cf4a | 2011-10-07 14:01:23 +0200 | [diff] [blame] | 2292 | */ |
| 2293 | sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 2294 | |
| 2295 | list_for_each_entry_rcu(tmp_sdata, &local->interfaces, list) { |
| 2296 | if (!ieee80211_sdata_running(tmp_sdata)) |
| 2297 | continue; |
| 2298 | if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR || |
| 2299 | tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN || |
| 2300 | tmp_sdata->vif.type == NL80211_IFTYPE_WDS) |
| 2301 | continue; |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2302 | if (ether_addr_equal(tmp_sdata->vif.addr, hdr->addr2)) { |
Johannes Berg | 5d9cf4a | 2011-10-07 14:01:23 +0200 | [diff] [blame] | 2303 | sdata = tmp_sdata; |
| 2304 | break; |
| 2305 | } |
| 2306 | } |
Johannes Berg | 7351c6b | 2009-11-19 01:08:30 +0100 | [diff] [blame] | 2307 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2308 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 2309 | if (!chanctx_conf) { |
| 2310 | tmp_sdata = rcu_dereference(local->monitor_sdata); |
| 2311 | if (tmp_sdata) |
| 2312 | chanctx_conf = |
| 2313 | rcu_dereference(tmp_sdata->vif.chanctx_conf); |
| 2314 | } |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2315 | |
Felix Fietkau | b4a7ff7 | 2013-01-13 23:10:26 +0100 | [diff] [blame] | 2316 | if (chanctx_conf) |
Janusz Dziedzic | b493283 | 2014-06-05 08:12:57 +0200 | [diff] [blame] | 2317 | chandef = &chanctx_conf->def; |
Felix Fietkau | b4a7ff7 | 2013-01-13 23:10:26 +0100 | [diff] [blame] | 2318 | else if (!local->use_chanctx) |
Janusz Dziedzic | b493283 | 2014-06-05 08:12:57 +0200 | [diff] [blame] | 2319 | chandef = &local->_oper_chandef; |
Felix Fietkau | b4a7ff7 | 2013-01-13 23:10:26 +0100 | [diff] [blame] | 2320 | else |
| 2321 | goto fail_rcu; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2322 | |
| 2323 | /* |
| 2324 | * Frame injection is not allowed if beaconing is not allowed |
| 2325 | * or if we need radar detection. Beaconing is usually not allowed when |
| 2326 | * the mode or operation (Adhoc, AP, Mesh) does not support DFS. |
| 2327 | * Passive scan is also used in world regulatory domains where |
| 2328 | * your country is not known and as such it should be treated as |
| 2329 | * NO TX unless the channel is explicitly allowed in which case |
| 2330 | * your current regulatory domain would not have the passive scan |
| 2331 | * flag. |
| 2332 | * |
| 2333 | * Since AP mode uses monitor interfaces to inject/TX management |
| 2334 | * frames we can make AP mode the exception to this rule once it |
| 2335 | * supports radar detection as its implementation can deal with |
| 2336 | * radar detection by itself. We can do that later by adding a |
| 2337 | * monitor flag interfaces used for AP support. |
| 2338 | */ |
Janusz Dziedzic | b493283 | 2014-06-05 08:12:57 +0200 | [diff] [blame] | 2339 | if (!cfg80211_reg_can_beacon(local->hw.wiphy, chandef, |
| 2340 | sdata->vif.type)) |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2341 | goto fail_rcu; |
| 2342 | |
Johannes Berg | 73c4e19 | 2014-11-09 18:50:09 +0200 | [diff] [blame] | 2343 | info->band = chandef->chan->band; |
Lorenzo Bianconi | 109843b0 | 2016-02-19 12:18:01 +0100 | [diff] [blame] | 2344 | |
| 2345 | /* process and remove the injection radiotap header */ |
| 2346 | if (!ieee80211_parse_tx_radiotap(local, skb)) |
| 2347 | goto fail_rcu; |
| 2348 | |
Johannes Berg | b9771d4 | 2018-05-28 15:47:41 +0200 | [diff] [blame] | 2349 | ieee80211_xmit(sdata, NULL, skb, 0); |
Johannes Berg | 5d9cf4a | 2011-10-07 14:01:23 +0200 | [diff] [blame] | 2350 | rcu_read_unlock(); |
| 2351 | |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2352 | return NETDEV_TX_OK; |
Andy Green | 9b8a74e | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2353 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2354 | fail_rcu: |
| 2355 | rcu_read_unlock(); |
Andy Green | 9b8a74e | 2007-07-27 15:43:24 +0200 | [diff] [blame] | 2356 | fail: |
| 2357 | dev_kfree_skb(skb); |
| 2358 | return NETDEV_TX_OK; /* meaning, we dealt with the skb */ |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2359 | } |
| 2360 | |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 2361 | static inline bool ieee80211_is_tdls_setup(struct sk_buff *skb) |
Matti Gottlieb | ad38bfc | 2013-11-18 19:06:45 +0200 | [diff] [blame] | 2362 | { |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 2363 | u16 ethertype = (skb->data[12] << 8) | skb->data[13]; |
Matti Gottlieb | ad38bfc | 2013-11-18 19:06:45 +0200 | [diff] [blame] | 2364 | |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 2365 | return ethertype == ETH_P_TDLS && |
| 2366 | skb->len > 14 && |
| 2367 | skb->data[14] == WLAN_TDLS_SNAP_RFTYPE; |
| 2368 | } |
| 2369 | |
John Crispin | 50ff477 | 2019-11-25 11:04:37 +0100 | [diff] [blame] | 2370 | int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata, |
| 2371 | struct sk_buff *skb, |
| 2372 | struct sta_info **sta_out) |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 2373 | { |
| 2374 | struct sta_info *sta; |
| 2375 | |
| 2376 | switch (sdata->vif.type) { |
| 2377 | case NL80211_IFTYPE_AP_VLAN: |
| 2378 | sta = rcu_dereference(sdata->u.vlan.sta); |
| 2379 | if (sta) { |
| 2380 | *sta_out = sta; |
| 2381 | return 0; |
| 2382 | } else if (sdata->wdev.use_4addr) { |
| 2383 | return -ENOLINK; |
| 2384 | } |
| 2385 | /* fall through */ |
| 2386 | case NL80211_IFTYPE_AP: |
| 2387 | case NL80211_IFTYPE_OCB: |
| 2388 | case NL80211_IFTYPE_ADHOC: |
| 2389 | if (is_multicast_ether_addr(skb->data)) { |
| 2390 | *sta_out = ERR_PTR(-ENOENT); |
| 2391 | return 0; |
| 2392 | } |
| 2393 | sta = sta_info_get_bss(sdata, skb->data); |
| 2394 | break; |
| 2395 | case NL80211_IFTYPE_WDS: |
| 2396 | sta = sta_info_get(sdata, sdata->u.wds.remote_addr); |
| 2397 | break; |
| 2398 | #ifdef CONFIG_MAC80211_MESH |
| 2399 | case NL80211_IFTYPE_MESH_POINT: |
| 2400 | /* determined much later */ |
| 2401 | *sta_out = NULL; |
| 2402 | return 0; |
| 2403 | #endif |
| 2404 | case NL80211_IFTYPE_STATION: |
| 2405 | if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) { |
| 2406 | sta = sta_info_get(sdata, skb->data); |
Johannes Berg | 11d62ca | 2016-09-13 08:28:22 +0200 | [diff] [blame] | 2407 | if (sta && test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { |
| 2408 | if (test_sta_flag(sta, |
| 2409 | WLAN_STA_TDLS_PEER_AUTH)) { |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 2410 | *sta_out = sta; |
| 2411 | return 0; |
| 2412 | } |
| 2413 | |
| 2414 | /* |
| 2415 | * TDLS link during setup - throw out frames to |
| 2416 | * peer. Allow TDLS-setup frames to unauthorized |
| 2417 | * peers for the special case of a link teardown |
| 2418 | * after a TDLS sta is removed due to being |
| 2419 | * unreachable. |
| 2420 | */ |
Johannes Berg | 11d62ca | 2016-09-13 08:28:22 +0200 | [diff] [blame] | 2421 | if (!ieee80211_is_tdls_setup(skb)) |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 2422 | return -EINVAL; |
| 2423 | } |
| 2424 | |
| 2425 | } |
| 2426 | |
| 2427 | sta = sta_info_get(sdata, sdata->u.mgd.bssid); |
| 2428 | if (!sta) |
| 2429 | return -ENOLINK; |
| 2430 | break; |
| 2431 | default: |
| 2432 | return -EINVAL; |
| 2433 | } |
| 2434 | |
| 2435 | *sta_out = sta ?: ERR_PTR(-ENOENT); |
| 2436 | return 0; |
Matti Gottlieb | ad38bfc | 2013-11-18 19:06:45 +0200 | [diff] [blame] | 2437 | } |
| 2438 | |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 2439 | static u16 ieee80211_store_ack_skb(struct ieee80211_local *local, |
John Crispin | 5d8983c | 2019-10-29 10:13:02 +0100 | [diff] [blame] | 2440 | struct sk_buff *skb, |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 2441 | u32 *info_flags, |
| 2442 | u64 *cookie) |
John Crispin | 5d8983c | 2019-10-29 10:13:02 +0100 | [diff] [blame] | 2443 | { |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 2444 | struct sk_buff *ack_skb; |
John Crispin | 5d8983c | 2019-10-29 10:13:02 +0100 | [diff] [blame] | 2445 | u16 info_id = 0; |
| 2446 | |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 2447 | if (skb->sk) |
| 2448 | ack_skb = skb_clone_sk(skb); |
| 2449 | else |
| 2450 | ack_skb = skb_clone(skb, GFP_ATOMIC); |
| 2451 | |
John Crispin | 5d8983c | 2019-10-29 10:13:02 +0100 | [diff] [blame] | 2452 | if (ack_skb) { |
| 2453 | unsigned long flags; |
| 2454 | int id; |
| 2455 | |
| 2456 | spin_lock_irqsave(&local->ack_status_lock, flags); |
| 2457 | id = idr_alloc(&local->ack_status_frames, ack_skb, |
Johannes Berg | f2b18ba | 2020-01-15 12:25:50 +0100 | [diff] [blame] | 2458 | 1, 0x2000, GFP_ATOMIC); |
John Crispin | 5d8983c | 2019-10-29 10:13:02 +0100 | [diff] [blame] | 2459 | spin_unlock_irqrestore(&local->ack_status_lock, flags); |
| 2460 | |
| 2461 | if (id >= 0) { |
| 2462 | info_id = id; |
| 2463 | *info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 2464 | if (cookie) { |
| 2465 | *cookie = ieee80211_mgmt_tx_cookie(local); |
| 2466 | IEEE80211_SKB_CB(ack_skb)->ack.cookie = *cookie; |
| 2467 | } |
John Crispin | 5d8983c | 2019-10-29 10:13:02 +0100 | [diff] [blame] | 2468 | } else { |
| 2469 | kfree_skb(ack_skb); |
| 2470 | } |
| 2471 | } |
| 2472 | |
| 2473 | return info_id; |
| 2474 | } |
| 2475 | |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2476 | /** |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2477 | * ieee80211_build_hdr - build 802.11 header in the given frame |
| 2478 | * @sdata: virtual interface to build the header for |
| 2479 | * @skb: the skb to build the header in |
Liad Kaufman | 24d342c | 2014-11-09 18:50:07 +0200 | [diff] [blame] | 2480 | * @info_flags: skb flags to set |
Rajkumar Manoharan | 0601677 | 2019-04-11 13:47:25 -0700 | [diff] [blame] | 2481 | * @ctrl_flags: info control flags to set |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2482 | * |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2483 | * This function takes the skb with 802.3 header and reformats the header to |
| 2484 | * the appropriate IEEE 802.11 header based on which interface the packet is |
| 2485 | * being transmitted on. |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2486 | * |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2487 | * Note that this function also takes care of the TX status request and |
| 2488 | * potential unsharing of the SKB - this needs to be interleaved with the |
| 2489 | * header building. |
| 2490 | * |
| 2491 | * The function requires the read-side RCU lock held |
| 2492 | * |
| 2493 | * Returns: the (possibly reallocated) skb or an ERR_PTR() code |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2494 | */ |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2495 | static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 7c10770 | 2015-03-20 14:18:27 +0100 | [diff] [blame] | 2496 | struct sk_buff *skb, u32 info_flags, |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 2497 | struct sta_info *sta, u32 ctrl_flags, |
| 2498 | u64 *cookie) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2499 | { |
Johannes Berg | 133b822 | 2008-09-16 14:18:59 +0200 | [diff] [blame] | 2500 | struct ieee80211_local *local = sdata->local; |
Felix Fietkau | 489ee91 | 2010-12-18 19:30:48 +0100 | [diff] [blame] | 2501 | struct ieee80211_tx_info *info; |
Johannes Berg | dcf3396 | 2012-07-30 15:11:56 +0200 | [diff] [blame] | 2502 | int head_need; |
Harvey Harrison | 065e9605 | 2008-06-22 16:45:27 -0700 | [diff] [blame] | 2503 | u16 ethertype, hdrlen, meshhdrlen = 0; |
| 2504 | __le16 fc; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2505 | struct ieee80211_hdr hdr; |
Wey-Yi Guy | ff67bb8 | 2010-08-21 07:23:29 -0700 | [diff] [blame] | 2506 | struct ieee80211s_hdr mesh_hdr __maybe_unused; |
Chun-Yeow Yeoh | b8bacc1 | 2012-05-30 09:30:41 +0800 | [diff] [blame] | 2507 | struct mesh_path __maybe_unused *mppath = NULL, *mpath = NULL; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2508 | const u8 *encaps_data; |
| 2509 | int encaps_len, skip_header_bytes; |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 2510 | bool wme_sta = false, authorized = false; |
| 2511 | bool tdls_peer; |
Johannes Berg | a729cff | 2011-11-06 14:13:34 +0100 | [diff] [blame] | 2512 | bool multicast; |
Johannes Berg | a729cff | 2011-11-06 14:13:34 +0100 | [diff] [blame] | 2513 | u16 info_id = 0; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2514 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 2515 | struct ieee80211_sub_if_data *ap_sdata; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2516 | enum nl80211_band band; |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2517 | int ret; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2518 | |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 2519 | if (IS_ERR(sta)) |
| 2520 | sta = NULL; |
| 2521 | |
Julius Niedworok | 276d9e8 | 2019-03-28 21:01:06 +0100 | [diff] [blame] | 2522 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 2523 | if (local->force_tx_status) |
| 2524 | info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; |
| 2525 | #endif |
| 2526 | |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2527 | /* convert Ethernet header to proper 802.11 header (based on |
| 2528 | * operation mode) */ |
| 2529 | ethertype = (skb->data[12] << 8) | skb->data[13]; |
Harvey Harrison | 065e9605 | 2008-06-22 16:45:27 -0700 | [diff] [blame] | 2530 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2531 | |
Johannes Berg | 51fb61e | 2007-12-19 01:31:27 +0100 | [diff] [blame] | 2532 | switch (sdata->vif.type) { |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2533 | case NL80211_IFTYPE_AP_VLAN: |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 2534 | if (sdata->wdev.use_4addr) { |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2535 | fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); |
| 2536 | /* RA TA DA SA */ |
| 2537 | memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 2538 | memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2539 | memcpy(hdr.addr3, skb->data, ETH_ALEN); |
| 2540 | memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); |
| 2541 | hdrlen = 30; |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 2542 | authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); |
Johannes Berg | a74a8c8 | 2014-07-22 14:50:47 +0200 | [diff] [blame] | 2543 | wme_sta = sta->sta.wme; |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2544 | } |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2545 | ap_sdata = container_of(sdata->bss, struct ieee80211_sub_if_data, |
| 2546 | u.ap); |
| 2547 | chanctx_conf = rcu_dereference(ap_sdata->vif.chanctx_conf); |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2548 | if (!chanctx_conf) { |
| 2549 | ret = -ENOTCONN; |
| 2550 | goto free; |
| 2551 | } |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 2552 | band = chanctx_conf->def.chan->band; |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 2553 | if (sdata->wdev.use_4addr) |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2554 | break; |
| 2555 | /* fall through */ |
| 2556 | case NL80211_IFTYPE_AP: |
Arnd Bergmann | fe80123 | 2013-01-25 14:14:33 +0000 | [diff] [blame] | 2557 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
| 2558 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2559 | if (!chanctx_conf) { |
| 2560 | ret = -ENOTCONN; |
| 2561 | goto free; |
| 2562 | } |
Harvey Harrison | 065e9605 | 2008-06-22 16:45:27 -0700 | [diff] [blame] | 2563 | fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2564 | /* DA BSSID SA */ |
| 2565 | memcpy(hdr.addr1, skb->data, ETH_ALEN); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 2566 | memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2567 | memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN); |
| 2568 | hdrlen = 24; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 2569 | band = chanctx_conf->def.chan->band; |
Johannes Berg | cf96683 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2570 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2571 | case NL80211_IFTYPE_WDS: |
Harvey Harrison | 065e9605 | 2008-06-22 16:45:27 -0700 | [diff] [blame] | 2572 | fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2573 | /* RA TA DA SA */ |
| 2574 | memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 2575 | memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2576 | memcpy(hdr.addr3, skb->data, ETH_ALEN); |
| 2577 | memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); |
| 2578 | hdrlen = 30; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2579 | /* |
| 2580 | * This is the exception! WDS style interfaces are prohibited |
| 2581 | * when channel contexts are in used so this must be valid |
| 2582 | */ |
Karl Beldan | 675a0b0 | 2013-03-25 16:26:57 +0100 | [diff] [blame] | 2583 | band = local->hw.conf.chandef.chan->band; |
Johannes Berg | cf96683 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2584 | break; |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 2585 | #ifdef CONFIG_MAC80211_MESH |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2586 | case NL80211_IFTYPE_MESH_POINT: |
Chun-Yeow Yeoh | b8bacc1 | 2012-05-30 09:30:41 +0800 | [diff] [blame] | 2587 | if (!is_multicast_ether_addr(skb->data)) { |
Chun-Yeow Yeoh | 163df6c | 2013-02-19 10:04:50 +0800 | [diff] [blame] | 2588 | struct sta_info *next_hop; |
| 2589 | bool mpp_lookup = true; |
| 2590 | |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 2591 | mpath = mesh_path_lookup(sdata, skb->data); |
Chun-Yeow Yeoh | 163df6c | 2013-02-19 10:04:50 +0800 | [diff] [blame] | 2592 | if (mpath) { |
| 2593 | mpp_lookup = false; |
| 2594 | next_hop = rcu_dereference(mpath->next_hop); |
| 2595 | if (!next_hop || |
| 2596 | !(mpath->flags & (MESH_PATH_ACTIVE | |
| 2597 | MESH_PATH_RESOLVING))) |
| 2598 | mpp_lookup = true; |
| 2599 | } |
| 2600 | |
Henning Rogge | ab1c790 | 2016-02-03 13:58:37 +0100 | [diff] [blame] | 2601 | if (mpp_lookup) { |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 2602 | mppath = mpp_path_lookup(sdata, skb->data); |
Henning Rogge | ab1c790 | 2016-02-03 13:58:37 +0100 | [diff] [blame] | 2603 | if (mppath) |
| 2604 | mppath->exp_time = jiffies; |
| 2605 | } |
Chun-Yeow Yeoh | 163df6c | 2013-02-19 10:04:50 +0800 | [diff] [blame] | 2606 | |
| 2607 | if (mppath && mpath) |
Bob Copeland | 2bdaf38 | 2016-02-28 20:03:56 -0500 | [diff] [blame] | 2608 | mesh_path_del(sdata, mpath->dst); |
Chun-Yeow Yeoh | b8bacc1 | 2012-05-30 09:30:41 +0800 | [diff] [blame] | 2609 | } |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 2610 | |
Joel A Fernandes | f76b57b | 2010-12-28 19:28:11 -0600 | [diff] [blame] | 2611 | /* |
Joel A Fernandes | 9d52501 | 2011-01-10 00:44:23 -0600 | [diff] [blame] | 2612 | * Use address extension if it is a packet from |
| 2613 | * another interface or if we know the destination |
| 2614 | * is being proxied by a portal (i.e. portal address |
| 2615 | * differs from proxied address) |
Joel A Fernandes | f76b57b | 2010-12-28 19:28:11 -0600 | [diff] [blame] | 2616 | */ |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2617 | if (ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN) && |
| 2618 | !(mppath && !ether_addr_equal(mppath->mpp, skb->data))) { |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 2619 | hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc, |
| 2620 | skb->data, skb->data + ETH_ALEN); |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 2621 | meshhdrlen = ieee80211_new_mesh_header(sdata, &mesh_hdr, |
| 2622 | NULL, NULL); |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 2623 | } else { |
Thomas Pedersen | 27f0112 | 2012-08-20 11:28:25 -0700 | [diff] [blame] | 2624 | /* DS -> MBSS (802.11-2012 13.11.3.3). |
| 2625 | * For unicast with unknown forwarding information, |
| 2626 | * destination might be in the MBSS or if that fails |
| 2627 | * forwarded to another mesh gate. In either case |
| 2628 | * resolution will be handled in ieee80211_xmit(), so |
| 2629 | * leave the original DA. This also works for mcast */ |
| 2630 | const u8 *mesh_da = skb->data; |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 2631 | |
Thomas Pedersen | 27f0112 | 2012-08-20 11:28:25 -0700 | [diff] [blame] | 2632 | if (mppath) |
| 2633 | mesh_da = mppath->mpp; |
| 2634 | else if (mpath) |
| 2635 | mesh_da = mpath->dst; |
Thomas Pedersen | 27f0112 | 2012-08-20 11:28:25 -0700 | [diff] [blame] | 2636 | |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 2637 | hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc, |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 2638 | mesh_da, sdata->vif.addr); |
Thomas Pedersen | 27f0112 | 2012-08-20 11:28:25 -0700 | [diff] [blame] | 2639 | if (is_multicast_ether_addr(mesh_da)) |
| 2640 | /* DA TA mSA AE:SA */ |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 2641 | meshhdrlen = ieee80211_new_mesh_header( |
| 2642 | sdata, &mesh_hdr, |
| 2643 | skb->data + ETH_ALEN, NULL); |
Javier Cardona | 3c5772a | 2009-08-10 12:15:48 -0700 | [diff] [blame] | 2644 | else |
Thomas Pedersen | 27f0112 | 2012-08-20 11:28:25 -0700 | [diff] [blame] | 2645 | /* RA TA mDA mSA AE:DA SA */ |
Johannes Berg | bf7cd94 | 2013-02-15 14:40:31 +0100 | [diff] [blame] | 2646 | meshhdrlen = ieee80211_new_mesh_header( |
| 2647 | sdata, &mesh_hdr, skb->data, |
| 2648 | skb->data + ETH_ALEN); |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 2649 | |
YanBo | 79617de | 2008-09-22 13:30:32 +0800 | [diff] [blame] | 2650 | } |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2651 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2652 | if (!chanctx_conf) { |
| 2653 | ret = -ENOTCONN; |
| 2654 | goto free; |
| 2655 | } |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 2656 | band = chanctx_conf->def.chan->band; |
Rajkumar Manoharan | 8828f81 | 2019-04-11 13:47:26 -0700 | [diff] [blame] | 2657 | |
| 2658 | /* For injected frames, fill RA right away as nexthop lookup |
| 2659 | * will be skipped. |
| 2660 | */ |
| 2661 | if ((ctrl_flags & IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP) && |
| 2662 | is_zero_ether_addr(hdr.addr1)) |
| 2663 | memcpy(hdr.addr1, skb->data, ETH_ALEN); |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 2664 | break; |
| 2665 | #endif |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2666 | case NL80211_IFTYPE_STATION: |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 2667 | /* we already did checks when looking up the RA STA */ |
| 2668 | tdls_peer = test_sta_flag(sta, WLAN_STA_TDLS_PEER); |
Arik Nemtsov | 941c93c | 2011-09-28 14:12:54 +0300 | [diff] [blame] | 2669 | |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 2670 | if (tdls_peer) { |
Arik Nemtsov | 941c93c | 2011-09-28 14:12:54 +0300 | [diff] [blame] | 2671 | /* DA SA BSSID */ |
| 2672 | memcpy(hdr.addr1, skb->data, ETH_ALEN); |
| 2673 | memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); |
| 2674 | memcpy(hdr.addr3, sdata->u.mgd.bssid, ETH_ALEN); |
| 2675 | hdrlen = 24; |
| 2676 | } else if (sdata->u.mgd.use_4addr && |
| 2677 | cpu_to_be16(ethertype) != sdata->control_port_protocol) { |
| 2678 | fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | |
| 2679 | IEEE80211_FCTL_TODS); |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2680 | /* RA TA DA SA */ |
Arik Nemtsov | 941c93c | 2011-09-28 14:12:54 +0300 | [diff] [blame] | 2681 | memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 2682 | memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN); |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2683 | memcpy(hdr.addr3, skb->data, ETH_ALEN); |
| 2684 | memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN); |
| 2685 | hdrlen = 30; |
| 2686 | } else { |
| 2687 | fc |= cpu_to_le16(IEEE80211_FCTL_TODS); |
| 2688 | /* BSSID SA DA */ |
Arik Nemtsov | 941c93c | 2011-09-28 14:12:54 +0300 | [diff] [blame] | 2689 | memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN); |
Felix Fietkau | f14543ee | 2009-11-10 20:10:05 +0100 | [diff] [blame] | 2690 | memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); |
| 2691 | memcpy(hdr.addr3, skb->data, ETH_ALEN); |
| 2692 | hdrlen = 24; |
| 2693 | } |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2694 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2695 | if (!chanctx_conf) { |
| 2696 | ret = -ENOTCONN; |
| 2697 | goto free; |
| 2698 | } |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 2699 | band = chanctx_conf->def.chan->band; |
Johannes Berg | cf96683 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2700 | break; |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 2701 | case NL80211_IFTYPE_OCB: |
| 2702 | /* DA SA BSSID */ |
| 2703 | memcpy(hdr.addr1, skb->data, ETH_ALEN); |
| 2704 | memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); |
| 2705 | eth_broadcast_addr(hdr.addr3); |
| 2706 | hdrlen = 24; |
| 2707 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2708 | if (!chanctx_conf) { |
| 2709 | ret = -ENOTCONN; |
| 2710 | goto free; |
| 2711 | } |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 2712 | band = chanctx_conf->def.chan->band; |
| 2713 | break; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 2714 | case NL80211_IFTYPE_ADHOC: |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2715 | /* DA SA BSSID */ |
| 2716 | memcpy(hdr.addr1, skb->data, ETH_ALEN); |
| 2717 | memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 2718 | memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2719 | hdrlen = 24; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 2720 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2721 | if (!chanctx_conf) { |
| 2722 | ret = -ENOTCONN; |
| 2723 | goto free; |
| 2724 | } |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 2725 | band = chanctx_conf->def.chan->band; |
Johannes Berg | cf96683 | 2007-08-28 17:01:54 -0400 | [diff] [blame] | 2726 | break; |
| 2727 | default: |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2728 | ret = -EINVAL; |
| 2729 | goto free; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2730 | } |
| 2731 | |
Johannes Berg | a729cff | 2011-11-06 14:13:34 +0100 | [diff] [blame] | 2732 | multicast = is_multicast_ether_addr(hdr.addr1); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2733 | |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 2734 | /* sta is always NULL for mesh */ |
| 2735 | if (sta) { |
| 2736 | authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); |
| 2737 | wme_sta = sta->sta.wme; |
| 2738 | } else if (ieee80211_vif_is_mesh(&sdata->vif)) { |
| 2739 | /* For mesh, the use of the QoS header is mandatory */ |
Johannes Berg | c2c98fd | 2011-09-29 16:04:36 +0200 | [diff] [blame] | 2740 | wme_sta = true; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2741 | } |
| 2742 | |
Johannes Berg | 527871d | 2015-03-21 08:09:55 +0100 | [diff] [blame] | 2743 | /* receiver does QoS (which also means we do) use it */ |
| 2744 | if (wme_sta) { |
Harvey Harrison | 065e9605 | 2008-06-22 16:45:27 -0700 | [diff] [blame] | 2745 | fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA); |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2746 | hdrlen += 2; |
| 2747 | } |
| 2748 | |
| 2749 | /* |
Johannes Berg | 238814f | 2008-01-28 17:19:37 +0100 | [diff] [blame] | 2750 | * Drop unicast frames to unauthorised stations unless they are |
| 2751 | * EAPOL frames from the local station. |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2752 | */ |
Johannes Berg | 55182e4 | 2011-10-12 17:28:21 +0200 | [diff] [blame] | 2753 | if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) && |
Rostislav Lisovy | 239281f | 2014-11-03 10:33:19 +0100 | [diff] [blame] | 2754 | (sdata->vif.type != NL80211_IFTYPE_OCB) && |
Sergey Ryazanov | a6ececf | 2013-08-30 01:35:09 +0400 | [diff] [blame] | 2755 | !multicast && !authorized && |
Johannes Berg | 55182e4 | 2011-10-12 17:28:21 +0200 | [diff] [blame] | 2756 | (cpu_to_be16(ethertype) != sdata->control_port_protocol || |
Joe Perches | b203ca3 | 2012-05-08 18:56:52 +0000 | [diff] [blame] | 2757 | !ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN)))) { |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2758 | #ifdef CONFIG_MAC80211_VERBOSE_DEBUG |
Johannes Berg | bdcbd8e | 2012-06-22 11:29:50 +0200 | [diff] [blame] | 2759 | net_info_ratelimited("%s: dropped frame to %pM (unauthorized port)\n", |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2760 | sdata->name, hdr.addr1); |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2761 | #endif |
| 2762 | |
| 2763 | I802_DEBUG_INC(local->tx_handlers_drop_unauth_port); |
| 2764 | |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2765 | ret = -EPERM; |
| 2766 | goto free; |
Johannes Berg | ce3edf6d0 | 2007-12-19 01:31:22 +0100 | [diff] [blame] | 2767 | } |
| 2768 | |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 2769 | if (unlikely(!multicast && ((skb->sk && |
| 2770 | skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS) || |
| 2771 | ctrl_flags & IEEE80211_TX_CTL_REQ_TX_STATUS))) |
| 2772 | info_id = ieee80211_store_ack_skb(local, skb, &info_flags, |
| 2773 | cookie); |
Johannes Berg | a729cff | 2011-11-06 14:13:34 +0100 | [diff] [blame] | 2774 | |
Helmut Schaa | 7e24470 | 2010-12-02 18:44:09 +0100 | [diff] [blame] | 2775 | /* |
| 2776 | * If the skb is shared we need to obtain our own copy. |
| 2777 | */ |
| 2778 | if (skb_shared(skb)) { |
Johannes Berg | a729cff | 2011-11-06 14:13:34 +0100 | [diff] [blame] | 2779 | struct sk_buff *tmp_skb = skb; |
| 2780 | |
| 2781 | /* can't happen -- skb is a clone if info_id != 0 */ |
| 2782 | WARN_ON(info_id); |
| 2783 | |
Felix Fietkau | f8a0a78 | 2010-12-18 19:30:50 +0100 | [diff] [blame] | 2784 | skb = skb_clone(skb, GFP_ATOMIC); |
Helmut Schaa | 7e24470 | 2010-12-02 18:44:09 +0100 | [diff] [blame] | 2785 | kfree_skb(tmp_skb); |
| 2786 | |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2787 | if (!skb) { |
| 2788 | ret = -ENOMEM; |
| 2789 | goto free; |
| 2790 | } |
Helmut Schaa | 7e24470 | 2010-12-02 18:44:09 +0100 | [diff] [blame] | 2791 | } |
| 2792 | |
Harvey Harrison | 065e9605 | 2008-06-22 16:45:27 -0700 | [diff] [blame] | 2793 | hdr.frame_control = fc; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2794 | hdr.duration_id = 0; |
| 2795 | hdr.seq_ctrl = 0; |
| 2796 | |
| 2797 | skip_header_bytes = ETH_HLEN; |
| 2798 | if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) { |
| 2799 | encaps_data = bridge_tunnel_header; |
| 2800 | encaps_len = sizeof(bridge_tunnel_header); |
| 2801 | skip_header_bytes -= 2; |
Simon Horman | e5c5d22 | 2013-03-28 13:38:25 +0900 | [diff] [blame] | 2802 | } else if (ethertype >= ETH_P_802_3_MIN) { |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2803 | encaps_data = rfc1042_header; |
| 2804 | encaps_len = sizeof(rfc1042_header); |
| 2805 | skip_header_bytes -= 2; |
| 2806 | } else { |
| 2807 | encaps_data = NULL; |
| 2808 | encaps_len = 0; |
| 2809 | } |
| 2810 | |
| 2811 | skb_pull(skb, skip_header_bytes); |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 2812 | head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2813 | |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 2814 | /* |
| 2815 | * So we need to modify the skb header and hence need a copy of |
| 2816 | * that. The head_need variable above doesn't, so far, include |
| 2817 | * the needed header space that we don't need right away. If we |
| 2818 | * can, then we don't reallocate right now but only after the |
| 2819 | * frame arrives at the master device (if it does...) |
| 2820 | * |
| 2821 | * If we cannot, however, then we will reallocate to include all |
| 2822 | * the ever needed space. Also, if we need to reallocate it anyway, |
| 2823 | * make it big enough for everything we may ever need. |
| 2824 | */ |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2825 | |
David S. Miller | 3a5be7d | 2008-06-18 01:19:51 -0700 | [diff] [blame] | 2826 | if (head_need > 0 || skb_cloned(skb)) { |
Max Stepanov | 2475b1cc | 2013-03-24 14:23:27 +0200 | [diff] [blame] | 2827 | head_need += sdata->encrypt_headroom; |
Johannes Berg | 23c0752 | 2008-05-29 10:38:53 +0200 | [diff] [blame] | 2828 | head_need += local->tx_headroom; |
| 2829 | head_need = max_t(int, 0, head_need); |
Felix Fietkau | c3e7724 | 2012-10-08 14:39:33 +0200 | [diff] [blame] | 2830 | if (ieee80211_skb_resize(sdata, skb, head_need, true)) { |
| 2831 | ieee80211_free_txskb(&local->hw, skb); |
Johannes Berg | 1c963be | 2012-11-07 14:02:30 +0100 | [diff] [blame] | 2832 | skb = NULL; |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2833 | return ERR_PTR(-ENOMEM); |
Felix Fietkau | c3e7724 | 2012-10-08 14:39:33 +0200 | [diff] [blame] | 2834 | } |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2835 | } |
| 2836 | |
Felix Fietkau | eae4430 | 2016-07-13 11:00:02 +0200 | [diff] [blame] | 2837 | if (encaps_data) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2838 | memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len); |
Johannes Berg | c29b9b9 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 2839 | |
Yuri Ershov | e4ab7eb | 2010-06-29 15:08:06 +0400 | [diff] [blame] | 2840 | #ifdef CONFIG_MAC80211_MESH |
Felix Fietkau | eae4430 | 2016-07-13 11:00:02 +0200 | [diff] [blame] | 2841 | if (meshhdrlen > 0) |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 2842 | memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen); |
Yuri Ershov | e4ab7eb | 2010-06-29 15:08:06 +0400 | [diff] [blame] | 2843 | #endif |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 2844 | |
Harvey Harrison | 065e9605 | 2008-06-22 16:45:27 -0700 | [diff] [blame] | 2845 | if (ieee80211_is_data_qos(fc)) { |
Johannes Berg | c29b9b9 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 2846 | __le16 *qos_control; |
| 2847 | |
Johannes Berg | d58ff35 | 2017-06-16 14:29:23 +0200 | [diff] [blame] | 2848 | qos_control = skb_push(skb, 2); |
Johannes Berg | c29b9b9 | 2007-09-14 11:10:24 -0400 | [diff] [blame] | 2849 | memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2); |
| 2850 | /* |
| 2851 | * Maybe we could actually set some fields here, for now just |
| 2852 | * initialise to zero to indicate no special operation. |
| 2853 | */ |
| 2854 | *qos_control = 0; |
| 2855 | } else |
| 2856 | memcpy(skb_push(skb, hdrlen), &hdr, hdrlen); |
| 2857 | |
Zhang Shengju | d57a544 | 2016-03-03 01:16:56 +0000 | [diff] [blame] | 2858 | skb_reset_mac_header(skb); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2859 | |
Felix Fietkau | 489ee91 | 2010-12-18 19:30:48 +0100 | [diff] [blame] | 2860 | info = IEEE80211_SKB_CB(skb); |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 2861 | memset(info, 0, sizeof(*info)); |
| 2862 | |
Johannes Berg | a729cff | 2011-11-06 14:13:34 +0100 | [diff] [blame] | 2863 | info->flags = info_flags; |
| 2864 | info->ack_frame_id = info_id; |
Johannes Berg | 73c4e19 | 2014-11-09 18:50:09 +0200 | [diff] [blame] | 2865 | info->band = band; |
Rajkumar Manoharan | 0601677 | 2019-04-11 13:47:25 -0700 | [diff] [blame] | 2866 | info->control.flags = ctrl_flags; |
Johannes Berg | a729cff | 2011-11-06 14:13:34 +0100 | [diff] [blame] | 2867 | |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 2868 | return skb; |
| 2869 | free: |
| 2870 | kfree_skb(skb); |
| 2871 | return ERR_PTR(ret); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 2872 | } |
| 2873 | |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 2874 | /* |
| 2875 | * fast-xmit overview |
| 2876 | * |
| 2877 | * The core idea of this fast-xmit is to remove per-packet checks by checking |
| 2878 | * them out of band. ieee80211_check_fast_xmit() implements the out-of-band |
| 2879 | * checks that are needed to get the sta->fast_tx pointer assigned, after which |
| 2880 | * much less work can be done per packet. For example, fragmentation must be |
| 2881 | * disabled or the fast_tx pointer will not be set. All the conditions are seen |
| 2882 | * in the code here. |
| 2883 | * |
| 2884 | * Once assigned, the fast_tx data structure also caches the per-packet 802.11 |
| 2885 | * header and other data to aid packet processing in ieee80211_xmit_fast(). |
| 2886 | * |
| 2887 | * The most difficult part of this is that when any of these assumptions |
| 2888 | * change, an external trigger (i.e. a call to ieee80211_clear_fast_xmit(), |
| 2889 | * ieee80211_check_fast_xmit() or friends) is required to reset the data, |
| 2890 | * since the per-packet code no longer checks the conditions. This is reflected |
| 2891 | * by the calls to these functions throughout the rest of the code, and must be |
| 2892 | * maintained if any of the TX path checks change. |
| 2893 | */ |
| 2894 | |
| 2895 | void ieee80211_check_fast_xmit(struct sta_info *sta) |
| 2896 | { |
| 2897 | struct ieee80211_fast_tx build = {}, *fast_tx = NULL, *old; |
| 2898 | struct ieee80211_local *local = sta->local; |
| 2899 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 2900 | struct ieee80211_hdr *hdr = (void *)build.hdr; |
| 2901 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 2902 | __le16 fc; |
| 2903 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2904 | if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT)) |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 2905 | return; |
| 2906 | |
| 2907 | /* Locking here protects both the pointer itself, and against concurrent |
| 2908 | * invocations winning data access races to, e.g., the key pointer that |
| 2909 | * is used. |
| 2910 | * Without it, the invocation of this function right after the key |
| 2911 | * pointer changes wouldn't be sufficient, as another CPU could access |
| 2912 | * the pointer, then stall, and then do the cache update after the CPU |
| 2913 | * that invalidated the key. |
| 2914 | * With the locking, such scenarios cannot happen as the check for the |
| 2915 | * key and the fast-tx assignment are done atomically, so the CPU that |
| 2916 | * modifies the key will either wait or other one will see the key |
| 2917 | * cleared/changed already. |
| 2918 | */ |
| 2919 | spin_lock_bh(&sta->lock); |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 2920 | if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) && |
| 2921 | !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) && |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 2922 | sdata->vif.type == NL80211_IFTYPE_STATION) |
| 2923 | goto out; |
| 2924 | |
| 2925 | if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED)) |
| 2926 | goto out; |
| 2927 | |
| 2928 | if (test_sta_flag(sta, WLAN_STA_PS_STA) || |
| 2929 | test_sta_flag(sta, WLAN_STA_PS_DRIVER) || |
Felix Fietkau | f7418bc | 2015-09-24 14:59:49 +0200 | [diff] [blame] | 2930 | test_sta_flag(sta, WLAN_STA_PS_DELIVER) || |
| 2931 | test_sta_flag(sta, WLAN_STA_CLEAR_PS_FILT)) |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 2932 | goto out; |
| 2933 | |
| 2934 | if (sdata->noack_map) |
| 2935 | goto out; |
| 2936 | |
| 2937 | /* fast-xmit doesn't handle fragmentation at all */ |
Johannes Berg | 725b812 | 2015-04-10 14:02:08 +0200 | [diff] [blame] | 2938 | if (local->hw.wiphy->frag_threshold != (u32)-1 && |
Sara Sharon | f3fe4e9 | 2016-10-18 23:12:11 +0300 | [diff] [blame] | 2939 | !ieee80211_hw_check(&local->hw, SUPPORTS_TX_FRAG)) |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 2940 | goto out; |
| 2941 | |
| 2942 | rcu_read_lock(); |
| 2943 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 2944 | if (!chanctx_conf) { |
| 2945 | rcu_read_unlock(); |
| 2946 | goto out; |
| 2947 | } |
| 2948 | build.band = chanctx_conf->def.chan->band; |
| 2949 | rcu_read_unlock(); |
| 2950 | |
| 2951 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA); |
| 2952 | |
| 2953 | switch (sdata->vif.type) { |
Johannes Berg | 3ffd884 | 2015-04-14 10:28:37 +0200 | [diff] [blame] | 2954 | case NL80211_IFTYPE_ADHOC: |
| 2955 | /* DA SA BSSID */ |
| 2956 | build.da_offs = offsetof(struct ieee80211_hdr, addr1); |
| 2957 | build.sa_offs = offsetof(struct ieee80211_hdr, addr2); |
| 2958 | memcpy(hdr->addr3, sdata->u.ibss.bssid, ETH_ALEN); |
| 2959 | build.hdr_len = 24; |
| 2960 | break; |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 2961 | case NL80211_IFTYPE_STATION: |
| 2962 | if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) { |
| 2963 | /* DA SA BSSID */ |
| 2964 | build.da_offs = offsetof(struct ieee80211_hdr, addr1); |
| 2965 | build.sa_offs = offsetof(struct ieee80211_hdr, addr2); |
| 2966 | memcpy(hdr->addr3, sdata->u.mgd.bssid, ETH_ALEN); |
| 2967 | build.hdr_len = 24; |
| 2968 | break; |
| 2969 | } |
| 2970 | |
| 2971 | if (sdata->u.mgd.use_4addr) { |
| 2972 | /* non-regular ethertype cannot use the fastpath */ |
| 2973 | fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | |
| 2974 | IEEE80211_FCTL_TODS); |
| 2975 | /* RA TA DA SA */ |
| 2976 | memcpy(hdr->addr1, sdata->u.mgd.bssid, ETH_ALEN); |
| 2977 | memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); |
| 2978 | build.da_offs = offsetof(struct ieee80211_hdr, addr3); |
| 2979 | build.sa_offs = offsetof(struct ieee80211_hdr, addr4); |
| 2980 | build.hdr_len = 30; |
| 2981 | break; |
| 2982 | } |
| 2983 | fc |= cpu_to_le16(IEEE80211_FCTL_TODS); |
| 2984 | /* BSSID SA DA */ |
| 2985 | memcpy(hdr->addr1, sdata->u.mgd.bssid, ETH_ALEN); |
| 2986 | build.da_offs = offsetof(struct ieee80211_hdr, addr3); |
| 2987 | build.sa_offs = offsetof(struct ieee80211_hdr, addr2); |
| 2988 | build.hdr_len = 24; |
| 2989 | break; |
| 2990 | case NL80211_IFTYPE_AP_VLAN: |
| 2991 | if (sdata->wdev.use_4addr) { |
| 2992 | fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | |
| 2993 | IEEE80211_FCTL_TODS); |
| 2994 | /* RA TA DA SA */ |
| 2995 | memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN); |
| 2996 | memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); |
| 2997 | build.da_offs = offsetof(struct ieee80211_hdr, addr3); |
| 2998 | build.sa_offs = offsetof(struct ieee80211_hdr, addr4); |
| 2999 | build.hdr_len = 30; |
| 3000 | break; |
| 3001 | } |
| 3002 | /* fall through */ |
| 3003 | case NL80211_IFTYPE_AP: |
| 3004 | fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS); |
| 3005 | /* DA BSSID SA */ |
| 3006 | build.da_offs = offsetof(struct ieee80211_hdr, addr1); |
| 3007 | memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN); |
| 3008 | build.sa_offs = offsetof(struct ieee80211_hdr, addr3); |
| 3009 | build.hdr_len = 24; |
| 3010 | break; |
| 3011 | default: |
| 3012 | /* not handled on fast-xmit */ |
| 3013 | goto out; |
| 3014 | } |
| 3015 | |
| 3016 | if (sta->sta.wme) { |
| 3017 | build.hdr_len += 2; |
| 3018 | fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA); |
| 3019 | } |
| 3020 | |
| 3021 | /* We store the key here so there's no point in using rcu_dereference() |
| 3022 | * but that's fine because the code that changes the pointers will call |
| 3023 | * this function after doing so. For a single CPU that would be enough, |
| 3024 | * for multiple see the comment above. |
| 3025 | */ |
| 3026 | build.key = rcu_access_pointer(sta->ptk[sta->ptk_idx]); |
| 3027 | if (!build.key) |
| 3028 | build.key = rcu_access_pointer(sdata->default_unicast_key); |
| 3029 | if (build.key) { |
Johannes Berg | e495c24 | 2015-04-10 14:03:17 +0200 | [diff] [blame] | 3030 | bool gen_iv, iv_spc, mmic; |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3031 | |
| 3032 | gen_iv = build.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV; |
| 3033 | iv_spc = build.key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE; |
David Spinadel | 9de18d8 | 2017-12-01 13:50:52 +0200 | [diff] [blame] | 3034 | mmic = build.key->conf.flags & |
| 3035 | (IEEE80211_KEY_FLAG_GENERATE_MMIC | |
| 3036 | IEEE80211_KEY_FLAG_PUT_MIC_SPACE); |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3037 | |
| 3038 | /* don't handle software crypto */ |
| 3039 | if (!(build.key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)) |
| 3040 | goto out; |
| 3041 | |
Alexander Wetzel | 62872a9 | 2018-08-31 15:00:38 +0200 | [diff] [blame] | 3042 | /* Key is being removed */ |
| 3043 | if (build.key->flags & KEY_FLAG_TAINTED) |
| 3044 | goto out; |
| 3045 | |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3046 | switch (build.key->conf.cipher) { |
| 3047 | case WLAN_CIPHER_SUITE_CCMP: |
| 3048 | case WLAN_CIPHER_SUITE_CCMP_256: |
Alexander Wetzel | 96fc6ef | 2019-03-19 21:34:08 +0100 | [diff] [blame] | 3049 | if (gen_iv) |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3050 | build.pn_offs = build.hdr_len; |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3051 | if (gen_iv || iv_spc) |
| 3052 | build.hdr_len += IEEE80211_CCMP_HDR_LEN; |
| 3053 | break; |
| 3054 | case WLAN_CIPHER_SUITE_GCMP: |
| 3055 | case WLAN_CIPHER_SUITE_GCMP_256: |
Alexander Wetzel | 96fc6ef | 2019-03-19 21:34:08 +0100 | [diff] [blame] | 3056 | if (gen_iv) |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3057 | build.pn_offs = build.hdr_len; |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3058 | if (gen_iv || iv_spc) |
| 3059 | build.hdr_len += IEEE80211_GCMP_HDR_LEN; |
| 3060 | break; |
Johannes Berg | e495c24 | 2015-04-10 14:03:17 +0200 | [diff] [blame] | 3061 | case WLAN_CIPHER_SUITE_TKIP: |
| 3062 | /* cannot handle MMIC or IV generation in xmit-fast */ |
| 3063 | if (mmic || gen_iv) |
| 3064 | goto out; |
| 3065 | if (iv_spc) |
| 3066 | build.hdr_len += IEEE80211_TKIP_IV_LEN; |
| 3067 | break; |
| 3068 | case WLAN_CIPHER_SUITE_WEP40: |
| 3069 | case WLAN_CIPHER_SUITE_WEP104: |
| 3070 | /* cannot handle IV generation in fast-xmit */ |
| 3071 | if (gen_iv) |
| 3072 | goto out; |
| 3073 | if (iv_spc) |
| 3074 | build.hdr_len += IEEE80211_WEP_IV_LEN; |
| 3075 | break; |
| 3076 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 3077 | case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
| 3078 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 3079 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 3080 | WARN(1, |
| 3081 | "management cipher suite 0x%x enabled for data\n", |
| 3082 | build.key->conf.cipher); |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3083 | goto out; |
Johannes Berg | e495c24 | 2015-04-10 14:03:17 +0200 | [diff] [blame] | 3084 | default: |
| 3085 | /* we don't know how to generate IVs for this at all */ |
| 3086 | if (WARN_ON(gen_iv)) |
| 3087 | goto out; |
| 3088 | /* pure hardware keys are OK, of course */ |
| 3089 | if (!(build.key->flags & KEY_FLAG_CIPHER_SCHEME)) |
| 3090 | break; |
| 3091 | /* cipher scheme might require space allocation */ |
| 3092 | if (iv_spc && |
| 3093 | build.key->conf.iv_len > IEEE80211_FAST_XMIT_MAX_IV) |
| 3094 | goto out; |
| 3095 | if (iv_spc) |
| 3096 | build.hdr_len += build.key->conf.iv_len; |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3097 | } |
| 3098 | |
| 3099 | fc |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); |
| 3100 | } |
| 3101 | |
| 3102 | hdr->frame_control = fc; |
| 3103 | |
| 3104 | memcpy(build.hdr + build.hdr_len, |
| 3105 | rfc1042_header, sizeof(rfc1042_header)); |
| 3106 | build.hdr_len += sizeof(rfc1042_header); |
| 3107 | |
| 3108 | fast_tx = kmemdup(&build, sizeof(build), GFP_ATOMIC); |
| 3109 | /* if the kmemdup fails, continue w/o fast_tx */ |
| 3110 | if (!fast_tx) |
| 3111 | goto out; |
| 3112 | |
| 3113 | out: |
| 3114 | /* we might have raced against another call to this function */ |
| 3115 | old = rcu_dereference_protected(sta->fast_tx, |
| 3116 | lockdep_is_held(&sta->lock)); |
| 3117 | rcu_assign_pointer(sta->fast_tx, fast_tx); |
| 3118 | if (old) |
| 3119 | kfree_rcu(old, rcu_head); |
| 3120 | spin_unlock_bh(&sta->lock); |
| 3121 | } |
| 3122 | |
| 3123 | void ieee80211_check_fast_xmit_all(struct ieee80211_local *local) |
| 3124 | { |
| 3125 | struct sta_info *sta; |
| 3126 | |
| 3127 | rcu_read_lock(); |
| 3128 | list_for_each_entry_rcu(sta, &local->sta_list, list) |
| 3129 | ieee80211_check_fast_xmit(sta); |
| 3130 | rcu_read_unlock(); |
| 3131 | } |
| 3132 | |
| 3133 | void ieee80211_check_fast_xmit_iface(struct ieee80211_sub_if_data *sdata) |
| 3134 | { |
| 3135 | struct ieee80211_local *local = sdata->local; |
| 3136 | struct sta_info *sta; |
| 3137 | |
| 3138 | rcu_read_lock(); |
| 3139 | |
| 3140 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
| 3141 | if (sdata != sta->sdata && |
| 3142 | (!sta->sdata->bss || sta->sdata->bss != sdata->bss)) |
| 3143 | continue; |
| 3144 | ieee80211_check_fast_xmit(sta); |
| 3145 | } |
| 3146 | |
| 3147 | rcu_read_unlock(); |
| 3148 | } |
| 3149 | |
| 3150 | void ieee80211_clear_fast_xmit(struct sta_info *sta) |
| 3151 | { |
| 3152 | struct ieee80211_fast_tx *fast_tx; |
| 3153 | |
| 3154 | spin_lock_bh(&sta->lock); |
| 3155 | fast_tx = rcu_dereference_protected(sta->fast_tx, |
| 3156 | lockdep_is_held(&sta->lock)); |
| 3157 | RCU_INIT_POINTER(sta->fast_tx, NULL); |
| 3158 | spin_unlock_bh(&sta->lock); |
| 3159 | |
| 3160 | if (fast_tx) |
| 3161 | kfree_rcu(fast_tx, rcu_head); |
| 3162 | } |
| 3163 | |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3164 | static bool ieee80211_amsdu_realloc_pad(struct ieee80211_local *local, |
Sara Sharon | 166ac9d | 2018-08-29 08:57:02 +0200 | [diff] [blame] | 3165 | struct sk_buff *skb, int headroom) |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3166 | { |
Sara Sharon | 166ac9d | 2018-08-29 08:57:02 +0200 | [diff] [blame] | 3167 | if (skb_headroom(skb) < headroom) { |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3168 | I802_DEBUG_INC(local->tx_expand_skb_head); |
| 3169 | |
Sara Sharon | 166ac9d | 2018-08-29 08:57:02 +0200 | [diff] [blame] | 3170 | if (pskb_expand_head(skb, headroom, 0, GFP_ATOMIC)) { |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3171 | wiphy_debug(local->hw.wiphy, |
| 3172 | "failed to reallocate TX buffer\n"); |
| 3173 | return false; |
| 3174 | } |
| 3175 | } |
| 3176 | |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3177 | return true; |
| 3178 | } |
| 3179 | |
| 3180 | static bool ieee80211_amsdu_prepare_head(struct ieee80211_sub_if_data *sdata, |
| 3181 | struct ieee80211_fast_tx *fast_tx, |
| 3182 | struct sk_buff *skb) |
| 3183 | { |
| 3184 | struct ieee80211_local *local = sdata->local; |
| 3185 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 3186 | struct ieee80211_hdr *hdr; |
Michael Braun | 06f2bb1 | 2016-10-15 13:28:18 +0200 | [diff] [blame] | 3187 | struct ethhdr *amsdu_hdr; |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3188 | int hdr_len = fast_tx->hdr_len - sizeof(rfc1042_header); |
| 3189 | int subframe_len = skb->len - hdr_len; |
| 3190 | void *data; |
Michael Braun | 06f2bb1 | 2016-10-15 13:28:18 +0200 | [diff] [blame] | 3191 | u8 *qc, *h_80211_src, *h_80211_dst; |
Michael Braun | a3e2f4b | 2016-10-15 13:28:19 +0200 | [diff] [blame] | 3192 | const u8 *bssid; |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3193 | |
| 3194 | if (info->flags & IEEE80211_TX_CTL_RATE_CTRL_PROBE) |
| 3195 | return false; |
| 3196 | |
| 3197 | if (info->control.flags & IEEE80211_TX_CTRL_AMSDU) |
| 3198 | return true; |
| 3199 | |
Sara Sharon | 166ac9d | 2018-08-29 08:57:02 +0200 | [diff] [blame] | 3200 | if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(*amsdu_hdr))) |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3201 | return false; |
| 3202 | |
Michael Braun | 06f2bb1 | 2016-10-15 13:28:18 +0200 | [diff] [blame] | 3203 | data = skb_push(skb, sizeof(*amsdu_hdr)); |
| 3204 | memmove(data, data + sizeof(*amsdu_hdr), hdr_len); |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3205 | hdr = data; |
Michael Braun | 06f2bb1 | 2016-10-15 13:28:18 +0200 | [diff] [blame] | 3206 | amsdu_hdr = data + hdr_len; |
| 3207 | /* h_80211_src/dst is addr* field within hdr */ |
| 3208 | h_80211_src = data + fast_tx->sa_offs; |
| 3209 | h_80211_dst = data + fast_tx->da_offs; |
| 3210 | |
| 3211 | amsdu_hdr->h_proto = cpu_to_be16(subframe_len); |
| 3212 | ether_addr_copy(amsdu_hdr->h_source, h_80211_src); |
| 3213 | ether_addr_copy(amsdu_hdr->h_dest, h_80211_dst); |
| 3214 | |
Michael Braun | a3e2f4b | 2016-10-15 13:28:19 +0200 | [diff] [blame] | 3215 | /* according to IEEE 802.11-2012 8.3.2 table 8-19, the outer SA/DA |
| 3216 | * fields needs to be changed to BSSID for A-MSDU frames depending |
| 3217 | * on FromDS/ToDS values. |
| 3218 | */ |
| 3219 | switch (sdata->vif.type) { |
| 3220 | case NL80211_IFTYPE_STATION: |
| 3221 | bssid = sdata->u.mgd.bssid; |
| 3222 | break; |
| 3223 | case NL80211_IFTYPE_AP: |
| 3224 | case NL80211_IFTYPE_AP_VLAN: |
| 3225 | bssid = sdata->vif.addr; |
| 3226 | break; |
| 3227 | default: |
| 3228 | bssid = NULL; |
| 3229 | } |
| 3230 | |
| 3231 | if (bssid && ieee80211_has_fromds(hdr->frame_control)) |
| 3232 | ether_addr_copy(h_80211_src, bssid); |
| 3233 | |
| 3234 | if (bssid && ieee80211_has_tods(hdr->frame_control)) |
| 3235 | ether_addr_copy(h_80211_dst, bssid); |
| 3236 | |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3237 | qc = ieee80211_get_qos_ctl(hdr); |
| 3238 | *qc |= IEEE80211_QOS_CTL_A_MSDU_PRESENT; |
| 3239 | |
| 3240 | info->control.flags |= IEEE80211_TX_CTRL_AMSDU; |
| 3241 | |
| 3242 | return true; |
| 3243 | } |
| 3244 | |
| 3245 | static bool ieee80211_amsdu_aggregate(struct ieee80211_sub_if_data *sdata, |
| 3246 | struct sta_info *sta, |
| 3247 | struct ieee80211_fast_tx *fast_tx, |
| 3248 | struct sk_buff *skb) |
| 3249 | { |
| 3250 | struct ieee80211_local *local = sdata->local; |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 3251 | struct fq *fq = &local->fq; |
| 3252 | struct fq_tin *tin; |
| 3253 | struct fq_flow *flow; |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3254 | u8 tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; |
| 3255 | struct ieee80211_txq *txq = sta->sta.txq[tid]; |
| 3256 | struct txq_info *txqi; |
| 3257 | struct sk_buff **frag_tail, *head; |
| 3258 | int subframe_len = skb->len - ETH_ALEN; |
| 3259 | u8 max_subframes = sta->sta.max_amsdu_subframes; |
| 3260 | int max_frags = local->hw.max_tx_fragments; |
| 3261 | int max_amsdu_len = sta->sta.max_amsdu_len; |
Felix Fietkau | eb9b64e | 2019-03-16 18:06:31 +0100 | [diff] [blame] | 3262 | int orig_truesize; |
Felix Fietkau | f2af2df | 2019-03-16 18:06:32 +0100 | [diff] [blame] | 3263 | u32 flow_idx; |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3264 | __be16 len; |
| 3265 | void *data; |
| 3266 | bool ret = false; |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 3267 | unsigned int orig_len; |
Lorenzo Bianconi | 66eb02d | 2018-08-31 01:04:13 +0200 | [diff] [blame] | 3268 | int n = 2, nfrags, pad = 0; |
Sara Sharon | 166ac9d | 2018-08-29 08:57:02 +0200 | [diff] [blame] | 3269 | u16 hdrlen; |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3270 | |
| 3271 | if (!ieee80211_hw_check(&local->hw, TX_AMSDU)) |
| 3272 | return false; |
| 3273 | |
Sara Sharon | 344f8e0 | 2018-12-15 11:03:07 +0200 | [diff] [blame] | 3274 | if (skb_is_gso(skb)) |
| 3275 | return false; |
| 3276 | |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3277 | if (!txq) |
| 3278 | return false; |
| 3279 | |
| 3280 | txqi = to_txq_info(txq); |
| 3281 | if (test_bit(IEEE80211_TXQ_NO_AMSDU, &txqi->flags)) |
| 3282 | return false; |
| 3283 | |
| 3284 | if (sta->sta.max_rc_amsdu_len) |
| 3285 | max_amsdu_len = min_t(int, max_amsdu_len, |
| 3286 | sta->sta.max_rc_amsdu_len); |
| 3287 | |
Sara Sharon | edba6bd | 2018-09-05 08:06:10 +0300 | [diff] [blame] | 3288 | if (sta->sta.max_tid_amsdu_len[tid]) |
| 3289 | max_amsdu_len = min_t(int, max_amsdu_len, |
| 3290 | sta->sta.max_tid_amsdu_len[tid]); |
| 3291 | |
Felix Fietkau | f2af2df | 2019-03-16 18:06:32 +0100 | [diff] [blame] | 3292 | flow_idx = fq_flow_idx(fq, skb); |
| 3293 | |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 3294 | spin_lock_bh(&fq->lock); |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3295 | |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 3296 | /* TODO: Ideally aggregation should be done on dequeue to remain |
| 3297 | * responsive to environment changes. |
| 3298 | */ |
| 3299 | |
| 3300 | tin = &txqi->tin; |
Felix Fietkau | f2af2df | 2019-03-16 18:06:32 +0100 | [diff] [blame] | 3301 | flow = fq_flow_classify(fq, tin, flow_idx, skb, |
| 3302 | fq_flow_get_default_func); |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 3303 | head = skb_peek_tail(&flow->queue); |
Sara Sharon | 344f8e0 | 2018-12-15 11:03:07 +0200 | [diff] [blame] | 3304 | if (!head || skb_is_gso(head)) |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3305 | goto out; |
| 3306 | |
Felix Fietkau | eb9b64e | 2019-03-16 18:06:31 +0100 | [diff] [blame] | 3307 | orig_truesize = head->truesize; |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 3308 | orig_len = head->len; |
| 3309 | |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3310 | if (skb->len + head->len > max_amsdu_len) |
| 3311 | goto out; |
| 3312 | |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3313 | nfrags = 1 + skb_shinfo(skb)->nr_frags; |
| 3314 | nfrags += 1 + skb_shinfo(head)->nr_frags; |
| 3315 | frag_tail = &skb_shinfo(head)->frag_list; |
| 3316 | while (*frag_tail) { |
| 3317 | nfrags += 1 + skb_shinfo(*frag_tail)->nr_frags; |
| 3318 | frag_tail = &(*frag_tail)->next; |
| 3319 | n++; |
| 3320 | } |
| 3321 | |
| 3322 | if (max_subframes && n > max_subframes) |
| 3323 | goto out; |
| 3324 | |
| 3325 | if (max_frags && nfrags > max_frags) |
| 3326 | goto out; |
| 3327 | |
Sara Sharon | 9739fe2 | 2018-09-05 08:06:11 +0300 | [diff] [blame] | 3328 | if (!drv_can_aggregate_in_amsdu(local, head, skb)) |
| 3329 | goto out; |
| 3330 | |
Lorenzo Bianconi | 1eb5079 | 2018-08-29 21:03:25 +0200 | [diff] [blame] | 3331 | if (!ieee80211_amsdu_prepare_head(sdata, fast_tx, head)) |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3332 | goto out; |
| 3333 | |
Sara Sharon | 166ac9d | 2018-08-29 08:57:02 +0200 | [diff] [blame] | 3334 | /* |
| 3335 | * Pad out the previous subframe to a multiple of 4 by adding the |
| 3336 | * padding to the next one, that's being added. Note that head->len |
| 3337 | * is the length of the full A-MSDU, but that works since each time |
| 3338 | * we add a new subframe we pad out the previous one to a multiple |
| 3339 | * of 4 and thus it no longer matters in the next round. |
| 3340 | */ |
| 3341 | hdrlen = fast_tx->hdr_len - sizeof(rfc1042_header); |
| 3342 | if ((head->len - hdrlen) & 3) |
| 3343 | pad = 4 - ((head->len - hdrlen) & 3); |
| 3344 | |
| 3345 | if (!ieee80211_amsdu_realloc_pad(local, skb, sizeof(rfc1042_header) + |
| 3346 | 2 + pad)) |
Johannes Berg | aa58acf | 2018-08-30 10:55:49 +0200 | [diff] [blame] | 3347 | goto out_recalc; |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3348 | |
| 3349 | ret = true; |
| 3350 | data = skb_push(skb, ETH_ALEN + 2); |
| 3351 | memmove(data, data + ETH_ALEN + 2, 2 * ETH_ALEN); |
| 3352 | |
| 3353 | data += 2 * ETH_ALEN; |
| 3354 | len = cpu_to_be16(subframe_len); |
| 3355 | memcpy(data, &len, 2); |
| 3356 | memcpy(data + 2, rfc1042_header, sizeof(rfc1042_header)); |
| 3357 | |
Sara Sharon | 166ac9d | 2018-08-29 08:57:02 +0200 | [diff] [blame] | 3358 | memset(skb_push(skb, pad), 0, pad); |
| 3359 | |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3360 | head->len += skb->len; |
| 3361 | head->data_len += skb->len; |
| 3362 | *frag_tail = skb; |
| 3363 | |
Johannes Berg | aa58acf | 2018-08-30 10:55:49 +0200 | [diff] [blame] | 3364 | out_recalc: |
Felix Fietkau | eb9b64e | 2019-03-16 18:06:31 +0100 | [diff] [blame] | 3365 | fq->memory_usage += head->truesize - orig_truesize; |
Johannes Berg | aa58acf | 2018-08-30 10:55:49 +0200 | [diff] [blame] | 3366 | if (head->len != orig_len) { |
| 3367 | flow->backlog += head->len - orig_len; |
| 3368 | tin->backlog_bytes += head->len - orig_len; |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 3369 | |
Johannes Berg | aa58acf | 2018-08-30 10:55:49 +0200 | [diff] [blame] | 3370 | fq_recalc_backlog(fq, tin, flow); |
| 3371 | } |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3372 | out: |
Michal Kazior | fa962b9 | 2016-05-19 10:37:49 +0200 | [diff] [blame] | 3373 | spin_unlock_bh(&fq->lock); |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3374 | |
| 3375 | return ret; |
| 3376 | } |
| 3377 | |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3378 | /* |
| 3379 | * Can be called while the sta lock is held. Anything that can cause packets to |
| 3380 | * be generated will cause deadlock! |
| 3381 | */ |
| 3382 | static void ieee80211_xmit_fast_finish(struct ieee80211_sub_if_data *sdata, |
| 3383 | struct sta_info *sta, u8 pn_offs, |
| 3384 | struct ieee80211_key *key, |
| 3385 | struct sk_buff *skb) |
| 3386 | { |
| 3387 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 3388 | struct ieee80211_hdr *hdr = (void *)skb->data; |
| 3389 | u8 tid = IEEE80211_NUM_TIDS; |
| 3390 | |
| 3391 | if (key) |
| 3392 | info->control.hw_key = &key->conf; |
| 3393 | |
| 3394 | ieee80211_tx_stats(skb->dev, skb->len); |
| 3395 | |
| 3396 | if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) { |
| 3397 | tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3398 | hdr->seq_ctrl = ieee80211_tx_next_seq(sta, tid); |
| 3399 | } else { |
| 3400 | info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ; |
| 3401 | hdr->seq_ctrl = cpu_to_le16(sdata->sequence_number); |
| 3402 | sdata->sequence_number += 0x10; |
| 3403 | } |
| 3404 | |
| 3405 | if (skb_shinfo(skb)->gso_size) |
| 3406 | sta->tx_stats.msdu[tid] += |
| 3407 | DIV_ROUND_UP(skb->len, skb_shinfo(skb)->gso_size); |
| 3408 | else |
| 3409 | sta->tx_stats.msdu[tid]++; |
| 3410 | |
| 3411 | info->hw_queue = sdata->vif.hw_queue[skb_get_queue_mapping(skb)]; |
| 3412 | |
| 3413 | /* statistics normally done by ieee80211_tx_h_stats (but that |
| 3414 | * has to consider fragmentation, so is more complex) |
| 3415 | */ |
| 3416 | sta->tx_stats.bytes[skb_get_queue_mapping(skb)] += skb->len; |
| 3417 | sta->tx_stats.packets[skb_get_queue_mapping(skb)]++; |
| 3418 | |
| 3419 | if (pn_offs) { |
| 3420 | u64 pn; |
| 3421 | u8 *crypto_hdr = skb->data + pn_offs; |
| 3422 | |
| 3423 | switch (key->conf.cipher) { |
| 3424 | case WLAN_CIPHER_SUITE_CCMP: |
| 3425 | case WLAN_CIPHER_SUITE_CCMP_256: |
| 3426 | case WLAN_CIPHER_SUITE_GCMP: |
| 3427 | case WLAN_CIPHER_SUITE_GCMP_256: |
| 3428 | pn = atomic64_inc_return(&key->conf.tx_pn); |
| 3429 | crypto_hdr[0] = pn; |
| 3430 | crypto_hdr[1] = pn >> 8; |
Alexander Wetzel | 96fc6ef | 2019-03-19 21:34:08 +0100 | [diff] [blame] | 3431 | crypto_hdr[3] = 0x20 | (key->conf.keyidx << 6); |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3432 | crypto_hdr[4] = pn >> 16; |
| 3433 | crypto_hdr[5] = pn >> 24; |
| 3434 | crypto_hdr[6] = pn >> 32; |
| 3435 | crypto_hdr[7] = pn >> 40; |
| 3436 | break; |
| 3437 | } |
| 3438 | } |
| 3439 | } |
| 3440 | |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3441 | static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata, |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3442 | struct sta_info *sta, |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3443 | struct ieee80211_fast_tx *fast_tx, |
| 3444 | struct sk_buff *skb) |
| 3445 | { |
| 3446 | struct ieee80211_local *local = sdata->local; |
| 3447 | u16 ethertype = (skb->data[12] << 8) | skb->data[13]; |
| 3448 | int extra_head = fast_tx->hdr_len - (ETH_HLEN - 2); |
| 3449 | int hw_headroom = sdata->local->hw.extra_tx_headroom; |
| 3450 | struct ethhdr eth; |
Johannes Berg | 35f432a | 2017-01-02 11:19:29 +0100 | [diff] [blame] | 3451 | struct ieee80211_tx_info *info; |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3452 | struct ieee80211_hdr *hdr = (void *)fast_tx->hdr; |
| 3453 | struct ieee80211_tx_data tx; |
| 3454 | ieee80211_tx_result r; |
| 3455 | struct tid_ampdu_tx *tid_tx = NULL; |
| 3456 | u8 tid = IEEE80211_NUM_TIDS; |
| 3457 | |
| 3458 | /* control port protocol needs a lot of special handling */ |
| 3459 | if (cpu_to_be16(ethertype) == sdata->control_port_protocol) |
| 3460 | return false; |
| 3461 | |
| 3462 | /* only RFC 1042 SNAP */ |
| 3463 | if (ethertype < ETH_P_802_3_MIN) |
| 3464 | return false; |
| 3465 | |
| 3466 | /* don't handle TX status request here either */ |
| 3467 | if (skb->sk && skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS) |
| 3468 | return false; |
| 3469 | |
| 3470 | if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) { |
| 3471 | tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; |
| 3472 | tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]); |
Johannes Berg | 472be00 | 2015-06-09 16:45:08 +0200 | [diff] [blame] | 3473 | if (tid_tx) { |
| 3474 | if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) |
| 3475 | return false; |
| 3476 | if (tid_tx->timeout) |
| 3477 | tid_tx->last_tx = jiffies; |
| 3478 | } |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3479 | } |
| 3480 | |
| 3481 | /* after this point (skb is modified) we cannot return false */ |
| 3482 | |
| 3483 | if (skb_shared(skb)) { |
| 3484 | struct sk_buff *tmp_skb = skb; |
| 3485 | |
| 3486 | skb = skb_clone(skb, GFP_ATOMIC); |
| 3487 | kfree_skb(tmp_skb); |
| 3488 | |
| 3489 | if (!skb) |
| 3490 | return true; |
| 3491 | } |
| 3492 | |
Felix Fietkau | 6e0456b | 2016-03-03 22:59:00 +0100 | [diff] [blame] | 3493 | if ((hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) && |
| 3494 | ieee80211_amsdu_aggregate(sdata, sta, fast_tx, skb)) |
| 3495 | return true; |
| 3496 | |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3497 | /* will not be crypto-handled beyond what we do here, so use false |
| 3498 | * as the may-encrypt argument for the resize to not account for |
| 3499 | * more room than we already have in 'extra_head' |
| 3500 | */ |
| 3501 | if (unlikely(ieee80211_skb_resize(sdata, skb, |
| 3502 | max_t(int, extra_head + hw_headroom - |
| 3503 | skb_headroom(skb), 0), |
| 3504 | false))) { |
| 3505 | kfree_skb(skb); |
| 3506 | return true; |
| 3507 | } |
| 3508 | |
| 3509 | memcpy(ð, skb->data, ETH_HLEN - 2); |
Johannes Berg | d58ff35 | 2017-06-16 14:29:23 +0200 | [diff] [blame] | 3510 | hdr = skb_push(skb, extra_head); |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3511 | memcpy(skb->data, fast_tx->hdr, fast_tx->hdr_len); |
| 3512 | memcpy(skb->data + fast_tx->da_offs, eth.h_dest, ETH_ALEN); |
| 3513 | memcpy(skb->data + fast_tx->sa_offs, eth.h_source, ETH_ALEN); |
| 3514 | |
Johannes Berg | 35f432a | 2017-01-02 11:19:29 +0100 | [diff] [blame] | 3515 | info = IEEE80211_SKB_CB(skb); |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3516 | memset(info, 0, sizeof(*info)); |
| 3517 | info->band = fast_tx->band; |
| 3518 | info->control.vif = &sdata->vif; |
| 3519 | info->flags = IEEE80211_TX_CTL_FIRST_FRAGMENT | |
| 3520 | IEEE80211_TX_CTL_DONTFRAG | |
| 3521 | (tid_tx ? IEEE80211_TX_CTL_AMPDU : 0); |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3522 | info->control.flags = IEEE80211_TX_CTRL_FAST_XMIT; |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3523 | |
Julius Niedworok | 276d9e8 | 2019-03-28 21:01:06 +0100 | [diff] [blame] | 3524 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 3525 | if (local->force_tx_status) |
| 3526 | info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; |
| 3527 | #endif |
| 3528 | |
Felix Fietkau | a786f96 | 2016-11-04 10:27:54 +0100 | [diff] [blame] | 3529 | if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) { |
| 3530 | tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK; |
| 3531 | *ieee80211_get_qos_ctl(hdr) = tid; |
| 3532 | } |
| 3533 | |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3534 | __skb_queue_head_init(&tx.skbs); |
| 3535 | |
| 3536 | tx.flags = IEEE80211_TX_UNICAST; |
| 3537 | tx.local = local; |
| 3538 | tx.sdata = sdata; |
| 3539 | tx.sta = sta; |
| 3540 | tx.key = fast_tx->key; |
| 3541 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 3542 | if (!ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) { |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3543 | tx.skb = skb; |
| 3544 | r = ieee80211_tx_h_rate_ctrl(&tx); |
| 3545 | skb = tx.skb; |
| 3546 | tx.skb = NULL; |
| 3547 | |
| 3548 | if (r != TX_CONTINUE) { |
| 3549 | if (r != TX_QUEUED) |
| 3550 | kfree_skb(skb); |
| 3551 | return true; |
| 3552 | } |
| 3553 | } |
| 3554 | |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3555 | if (ieee80211_queue_skb(local, sdata, sta, skb)) |
| 3556 | return true; |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3557 | |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3558 | ieee80211_xmit_fast_finish(sdata, sta, fast_tx->pn_offs, |
| 3559 | fast_tx->key, skb); |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3560 | |
| 3561 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 3562 | sdata = container_of(sdata->bss, |
| 3563 | struct ieee80211_sub_if_data, u.ap); |
| 3564 | |
| 3565 | __skb_queue_tail(&tx.skbs, skb); |
Johannes Berg | 4fd0328 | 2019-10-01 23:26:35 +0200 | [diff] [blame] | 3566 | ieee80211_tx_frags(local, &sdata->vif, sta, &tx.skbs, false); |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3567 | return true; |
| 3568 | } |
| 3569 | |
Toke Høiland-Jørgensen | e0e2eff | 2016-09-22 19:04:19 +0200 | [diff] [blame] | 3570 | struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, |
| 3571 | struct ieee80211_txq *txq) |
| 3572 | { |
| 3573 | struct ieee80211_local *local = hw_to_local(hw); |
| 3574 | struct txq_info *txqi = container_of(txq, struct txq_info, txq); |
| 3575 | struct ieee80211_hdr *hdr; |
| 3576 | struct sk_buff *skb = NULL; |
| 3577 | struct fq *fq = &local->fq; |
| 3578 | struct fq_tin *tin = &txqi->tin; |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3579 | struct ieee80211_tx_info *info; |
| 3580 | struct ieee80211_tx_data tx; |
| 3581 | ieee80211_tx_result r; |
Manikanta Pubbisetty | 21a5d4c | 2018-07-11 00:12:53 +0530 | [diff] [blame] | 3582 | struct ieee80211_vif *vif = txq->vif; |
Toke Høiland-Jørgensen | e0e2eff | 2016-09-22 19:04:19 +0200 | [diff] [blame] | 3583 | |
Erik Stromdahl | fb0e76a | 2019-06-17 22:01:39 +0200 | [diff] [blame] | 3584 | WARN_ON_ONCE(softirq_count() == 0); |
| 3585 | |
Toke Høiland-Jørgensen | 7a89233 | 2019-11-18 22:06:10 -0800 | [diff] [blame] | 3586 | if (!ieee80211_txq_airtime_check(hw, txq)) |
| 3587 | return NULL; |
| 3588 | |
Felix Fietkau | ded4698 | 2019-03-16 18:06:33 +0100 | [diff] [blame] | 3589 | begin: |
Toke Høiland-Jørgensen | e0e2eff | 2016-09-22 19:04:19 +0200 | [diff] [blame] | 3590 | spin_lock_bh(&fq->lock); |
| 3591 | |
Manikanta Pubbisetty | 21a5d4c | 2018-07-11 00:12:53 +0530 | [diff] [blame] | 3592 | if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags) || |
| 3593 | test_bit(IEEE80211_TXQ_STOP_NETIF_TX, &txqi->flags)) |
Toke Høiland-Jørgensen | e0e2eff | 2016-09-22 19:04:19 +0200 | [diff] [blame] | 3594 | goto out; |
| 3595 | |
Manikanta Pubbisetty | 21a5d4c | 2018-07-11 00:12:53 +0530 | [diff] [blame] | 3596 | if (vif->txqs_stopped[ieee80211_ac_from_tid(txq->tid)]) { |
| 3597 | set_bit(IEEE80211_TXQ_STOP_NETIF_TX, &txqi->flags); |
| 3598 | goto out; |
| 3599 | } |
| 3600 | |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3601 | /* Make sure fragments stay together. */ |
| 3602 | skb = __skb_dequeue(&txqi->frags); |
| 3603 | if (skb) |
| 3604 | goto out; |
| 3605 | |
Toke Høiland-Jørgensen | e0e2eff | 2016-09-22 19:04:19 +0200 | [diff] [blame] | 3606 | skb = fq_tin_dequeue(fq, tin, fq_tin_dequeue_func); |
| 3607 | if (!skb) |
| 3608 | goto out; |
| 3609 | |
Felix Fietkau | ded4698 | 2019-03-16 18:06:33 +0100 | [diff] [blame] | 3610 | spin_unlock_bh(&fq->lock); |
| 3611 | |
Toke Høiland-Jørgensen | e0e2eff | 2016-09-22 19:04:19 +0200 | [diff] [blame] | 3612 | hdr = (struct ieee80211_hdr *)skb->data; |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3613 | info = IEEE80211_SKB_CB(skb); |
| 3614 | |
| 3615 | memset(&tx, 0, sizeof(tx)); |
| 3616 | __skb_queue_head_init(&tx.skbs); |
| 3617 | tx.local = local; |
| 3618 | tx.skb = skb; |
| 3619 | tx.sdata = vif_to_sdata(info->control.vif); |
| 3620 | |
Jouni Malinen | ce2e1ca | 2020-03-26 15:51:34 +0100 | [diff] [blame] | 3621 | if (txq->sta) { |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3622 | tx.sta = container_of(txq->sta, struct sta_info, sta); |
Jouni Malinen | ce2e1ca | 2020-03-26 15:51:34 +0100 | [diff] [blame] | 3623 | /* |
| 3624 | * Drop unicast frames to unauthorised stations unless they are |
| 3625 | * EAPOL frames from the local station. |
| 3626 | */ |
Johannes Berg | be8c827 | 2020-03-29 22:50:06 +0200 | [diff] [blame] | 3627 | if (unlikely(ieee80211_is_data(hdr->frame_control) && |
| 3628 | !ieee80211_vif_is_mesh(&tx.sdata->vif) && |
Jouni Malinen | ce2e1ca | 2020-03-26 15:51:34 +0100 | [diff] [blame] | 3629 | tx.sdata->vif.type != NL80211_IFTYPE_OCB && |
| 3630 | !is_multicast_ether_addr(hdr->addr1) && |
| 3631 | !test_sta_flag(tx.sta, WLAN_STA_AUTHORIZED) && |
| 3632 | (!(info->control.flags & |
| 3633 | IEEE80211_TX_CTRL_PORT_CTRL_PROTO) || |
| 3634 | !ether_addr_equal(tx.sdata->vif.addr, |
| 3635 | hdr->addr2)))) { |
| 3636 | I802_DEBUG_INC(local->tx_handlers_drop_unauth_port); |
| 3637 | ieee80211_free_txskb(&local->hw, skb); |
| 3638 | goto begin; |
| 3639 | } |
| 3640 | } |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3641 | |
| 3642 | /* |
| 3643 | * The key can be removed while the packet was queued, so need to call |
| 3644 | * this here to get the current key. |
| 3645 | */ |
| 3646 | r = ieee80211_tx_h_select_key(&tx); |
| 3647 | if (r != TX_CONTINUE) { |
| 3648 | ieee80211_free_txskb(&local->hw, skb); |
| 3649 | goto begin; |
| 3650 | } |
| 3651 | |
Felix Fietkau | c1f4c9e | 2016-11-04 10:27:52 +0100 | [diff] [blame] | 3652 | if (test_bit(IEEE80211_TXQ_AMPDU, &txqi->flags)) |
| 3653 | info->flags |= IEEE80211_TX_CTL_AMPDU; |
| 3654 | else |
| 3655 | info->flags &= ~IEEE80211_TX_CTL_AMPDU; |
| 3656 | |
John Crispin | 50ff477 | 2019-11-25 11:04:37 +0100 | [diff] [blame] | 3657 | if (info->control.flags & IEEE80211_TX_CTRL_HW_80211_ENCAP) |
| 3658 | goto encap_out; |
| 3659 | |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3660 | if (info->control.flags & IEEE80211_TX_CTRL_FAST_XMIT) { |
Toke Høiland-Jørgensen | e0e2eff | 2016-09-22 19:04:19 +0200 | [diff] [blame] | 3661 | struct sta_info *sta = container_of(txq->sta, struct sta_info, |
| 3662 | sta); |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3663 | u8 pn_offs = 0; |
Toke Høiland-Jørgensen | e0e2eff | 2016-09-22 19:04:19 +0200 | [diff] [blame] | 3664 | |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3665 | if (tx.key && |
| 3666 | (tx.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV)) |
| 3667 | pn_offs = ieee80211_hdrlen(hdr->frame_control); |
| 3668 | |
| 3669 | ieee80211_xmit_fast_finish(sta->sdata, sta, pn_offs, |
| 3670 | tx.key, skb); |
| 3671 | } else { |
| 3672 | if (invoke_tx_handlers_late(&tx)) |
| 3673 | goto begin; |
| 3674 | |
| 3675 | skb = __skb_dequeue(&tx.skbs); |
| 3676 | |
Felix Fietkau | ded4698 | 2019-03-16 18:06:33 +0100 | [diff] [blame] | 3677 | if (!skb_queue_empty(&tx.skbs)) { |
| 3678 | spin_lock_bh(&fq->lock); |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3679 | skb_queue_splice_tail(&tx.skbs, &txqi->frags); |
Felix Fietkau | ded4698 | 2019-03-16 18:06:33 +0100 | [diff] [blame] | 3680 | spin_unlock_bh(&fq->lock); |
| 3681 | } |
Toke Høiland-Jørgensen | e0e2eff | 2016-09-22 19:04:19 +0200 | [diff] [blame] | 3682 | } |
| 3683 | |
Johannes Berg | 233e98d | 2018-12-15 11:03:09 +0200 | [diff] [blame] | 3684 | if (skb_has_frag_list(skb) && |
Johannes Berg | 1e1430d | 2016-10-04 09:22:19 +0200 | [diff] [blame] | 3685 | !ieee80211_hw_check(&local->hw, TX_FRAG_LIST)) { |
| 3686 | if (skb_linearize(skb)) { |
| 3687 | ieee80211_free_txskb(&local->hw, skb); |
| 3688 | goto begin; |
| 3689 | } |
| 3690 | } |
| 3691 | |
Johannes Berg | 5316821 | 2017-06-22 12:20:30 +0200 | [diff] [blame] | 3692 | switch (tx.sdata->vif.type) { |
| 3693 | case NL80211_IFTYPE_MONITOR: |
| 3694 | if (tx.sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE) { |
| 3695 | vif = &tx.sdata->vif; |
| 3696 | break; |
| 3697 | } |
| 3698 | tx.sdata = rcu_dereference(local->monitor_sdata); |
| 3699 | if (tx.sdata) { |
| 3700 | vif = &tx.sdata->vif; |
| 3701 | info->hw_queue = |
| 3702 | vif->hw_queue[skb_get_queue_mapping(skb)]; |
| 3703 | } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) { |
| 3704 | ieee80211_free_txskb(&local->hw, skb); |
| 3705 | goto begin; |
| 3706 | } else { |
| 3707 | vif = NULL; |
| 3708 | } |
| 3709 | break; |
| 3710 | case NL80211_IFTYPE_AP_VLAN: |
| 3711 | tx.sdata = container_of(tx.sdata->bss, |
| 3712 | struct ieee80211_sub_if_data, u.ap); |
| 3713 | /* fall through */ |
| 3714 | default: |
| 3715 | vif = &tx.sdata->vif; |
| 3716 | break; |
| 3717 | } |
| 3718 | |
John Crispin | 50ff477 | 2019-11-25 11:04:37 +0100 | [diff] [blame] | 3719 | encap_out: |
Johannes Berg | 5316821 | 2017-06-22 12:20:30 +0200 | [diff] [blame] | 3720 | IEEE80211_SKB_CB(skb)->control.vif = vif; |
Toke Høiland-Jørgensen | 7a89233 | 2019-11-18 22:06:10 -0800 | [diff] [blame] | 3721 | |
Johannes Berg | ca98c47 | 2020-02-21 10:45:45 +0100 | [diff] [blame] | 3722 | if (vif && |
| 3723 | wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL)) { |
Toke Høiland-Jørgensen | 7a89233 | 2019-11-18 22:06:10 -0800 | [diff] [blame] | 3724 | u32 airtime; |
| 3725 | |
| 3726 | airtime = ieee80211_calc_expected_tx_airtime(hw, vif, txq->sta, |
| 3727 | skb->len); |
| 3728 | if (airtime) { |
| 3729 | airtime = ieee80211_info_set_tx_time_est(info, airtime); |
| 3730 | ieee80211_sta_update_pending_airtime(local, tx.sta, |
| 3731 | txq->ac, |
| 3732 | airtime, |
| 3733 | false); |
| 3734 | } |
| 3735 | } |
| 3736 | |
Felix Fietkau | ded4698 | 2019-03-16 18:06:33 +0100 | [diff] [blame] | 3737 | return skb; |
Manikanta Pubbisetty | 21a5d4c | 2018-07-11 00:12:53 +0530 | [diff] [blame] | 3738 | |
Toke Høiland-Jørgensen | e0e2eff | 2016-09-22 19:04:19 +0200 | [diff] [blame] | 3739 | out: |
| 3740 | spin_unlock_bh(&fq->lock); |
| 3741 | |
Toke Høiland-Jørgensen | e0e2eff | 2016-09-22 19:04:19 +0200 | [diff] [blame] | 3742 | return skb; |
| 3743 | } |
| 3744 | EXPORT_SYMBOL(ieee80211_tx_dequeue); |
| 3745 | |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 3746 | struct ieee80211_txq *ieee80211_next_txq(struct ieee80211_hw *hw, u8 ac) |
| 3747 | { |
| 3748 | struct ieee80211_local *local = hw_to_local(hw); |
Felix Fietkau | 5b989c1 | 2019-03-15 11:03:35 +0100 | [diff] [blame] | 3749 | struct ieee80211_txq *ret = NULL; |
Kan Yan | 3ace10f | 2019-11-18 22:06:09 -0800 | [diff] [blame] | 3750 | struct txq_info *txqi = NULL, *head = NULL; |
| 3751 | bool found_eligible_txq = false; |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 3752 | |
Felix Fietkau | 5b989c1 | 2019-03-15 11:03:35 +0100 | [diff] [blame] | 3753 | spin_lock_bh(&local->active_txq_lock[ac]); |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 3754 | |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 3755 | begin: |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 3756 | txqi = list_first_entry_or_null(&local->active_txqs[ac], |
| 3757 | struct txq_info, |
| 3758 | schedule_order); |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 3759 | if (!txqi) |
Felix Fietkau | 5b989c1 | 2019-03-15 11:03:35 +0100 | [diff] [blame] | 3760 | goto out; |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 3761 | |
Kan Yan | 3ace10f | 2019-11-18 22:06:09 -0800 | [diff] [blame] | 3762 | if (txqi == head) { |
| 3763 | if (!found_eligible_txq) |
| 3764 | goto out; |
| 3765 | else |
| 3766 | found_eligible_txq = false; |
| 3767 | } |
| 3768 | |
| 3769 | if (!head) |
| 3770 | head = txqi; |
| 3771 | |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 3772 | if (txqi->txq.sta) { |
| 3773 | struct sta_info *sta = container_of(txqi->txq.sta, |
Kan Yan | 3ace10f | 2019-11-18 22:06:09 -0800 | [diff] [blame] | 3774 | struct sta_info, sta); |
| 3775 | bool aql_check = ieee80211_txq_airtime_check(hw, &txqi->txq); |
| 3776 | s64 deficit = sta->airtime[txqi->txq.ac].deficit; |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 3777 | |
Kan Yan | 3ace10f | 2019-11-18 22:06:09 -0800 | [diff] [blame] | 3778 | if (aql_check) |
| 3779 | found_eligible_txq = true; |
| 3780 | |
| 3781 | if (deficit < 0) |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 3782 | sta->airtime[txqi->txq.ac].deficit += |
| 3783 | sta->airtime_weight; |
Kan Yan | 3ace10f | 2019-11-18 22:06:09 -0800 | [diff] [blame] | 3784 | |
| 3785 | if (deficit < 0 || !aql_check) { |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 3786 | list_move_tail(&txqi->schedule_order, |
| 3787 | &local->active_txqs[txqi->txq.ac]); |
| 3788 | goto begin; |
| 3789 | } |
| 3790 | } |
| 3791 | |
| 3792 | |
| 3793 | if (txqi->schedule_round == local->schedule_round[ac]) |
Felix Fietkau | 5b989c1 | 2019-03-15 11:03:35 +0100 | [diff] [blame] | 3794 | goto out; |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 3795 | |
| 3796 | list_del_init(&txqi->schedule_order); |
| 3797 | txqi->schedule_round = local->schedule_round[ac]; |
Felix Fietkau | 5b989c1 | 2019-03-15 11:03:35 +0100 | [diff] [blame] | 3798 | ret = &txqi->txq; |
| 3799 | |
| 3800 | out: |
| 3801 | spin_unlock_bh(&local->active_txq_lock[ac]); |
| 3802 | return ret; |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 3803 | } |
| 3804 | EXPORT_SYMBOL(ieee80211_next_txq); |
| 3805 | |
Felix Fietkau | 2b4a669 | 2019-03-18 12:00:58 +0100 | [diff] [blame] | 3806 | void __ieee80211_schedule_txq(struct ieee80211_hw *hw, |
| 3807 | struct ieee80211_txq *txq, |
| 3808 | bool force) |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 3809 | { |
| 3810 | struct ieee80211_local *local = hw_to_local(hw); |
| 3811 | struct txq_info *txqi = to_txq_info(txq); |
| 3812 | |
Felix Fietkau | 5b989c1 | 2019-03-15 11:03:35 +0100 | [diff] [blame] | 3813 | spin_lock_bh(&local->active_txq_lock[txq->ac]); |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 3814 | |
| 3815 | if (list_empty(&txqi->schedule_order) && |
Felix Fietkau | 2b4a669 | 2019-03-18 12:00:58 +0100 | [diff] [blame] | 3816 | (force || !skb_queue_empty(&txqi->frags) || |
| 3817 | txqi->tin.backlog_packets)) { |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 3818 | /* If airtime accounting is active, always enqueue STAs at the |
| 3819 | * head of the list to ensure that they only get moved to the |
| 3820 | * back by the airtime DRR scheduler once they have a negative |
| 3821 | * deficit. A station that already has a negative deficit will |
| 3822 | * get immediately moved to the back of the list on the next |
| 3823 | * call to ieee80211_next_txq(). |
| 3824 | */ |
| 3825 | if (txqi->txq.sta && |
| 3826 | wiphy_ext_feature_isset(local->hw.wiphy, |
| 3827 | NL80211_EXT_FEATURE_AIRTIME_FAIRNESS)) |
| 3828 | list_add(&txqi->schedule_order, |
| 3829 | &local->active_txqs[txq->ac]); |
| 3830 | else |
| 3831 | list_add_tail(&txqi->schedule_order, |
| 3832 | &local->active_txqs[txq->ac]); |
| 3833 | } |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 3834 | |
Toke Høiland-Jørgensen | 390298e | 2019-01-22 15:20:16 +0100 | [diff] [blame] | 3835 | spin_unlock_bh(&local->active_txq_lock[txq->ac]); |
| 3836 | } |
Felix Fietkau | 2b4a669 | 2019-03-18 12:00:58 +0100 | [diff] [blame] | 3837 | EXPORT_SYMBOL(__ieee80211_schedule_txq); |
Toke Høiland-Jørgensen | 390298e | 2019-01-22 15:20:16 +0100 | [diff] [blame] | 3838 | |
Kan Yan | 3ace10f | 2019-11-18 22:06:09 -0800 | [diff] [blame] | 3839 | bool ieee80211_txq_airtime_check(struct ieee80211_hw *hw, |
| 3840 | struct ieee80211_txq *txq) |
| 3841 | { |
| 3842 | struct sta_info *sta; |
| 3843 | struct ieee80211_local *local = hw_to_local(hw); |
| 3844 | |
Toke Høiland-Jørgensen | 911bde0 | 2019-12-12 12:14:37 +0100 | [diff] [blame] | 3845 | if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL)) |
Kan Yan | 3ace10f | 2019-11-18 22:06:09 -0800 | [diff] [blame] | 3846 | return true; |
| 3847 | |
| 3848 | if (!txq->sta) |
| 3849 | return true; |
| 3850 | |
| 3851 | sta = container_of(txq->sta, struct sta_info, sta); |
| 3852 | if (atomic_read(&sta->airtime[txq->ac].aql_tx_pending) < |
| 3853 | sta->airtime[txq->ac].aql_limit_low) |
| 3854 | return true; |
| 3855 | |
| 3856 | if (atomic_read(&local->aql_total_pending_airtime) < |
| 3857 | local->aql_threshold && |
| 3858 | atomic_read(&sta->airtime[txq->ac].aql_tx_pending) < |
| 3859 | sta->airtime[txq->ac].aql_limit_high) |
| 3860 | return true; |
| 3861 | |
| 3862 | return false; |
| 3863 | } |
| 3864 | EXPORT_SYMBOL(ieee80211_txq_airtime_check); |
| 3865 | |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 3866 | bool ieee80211_txq_may_transmit(struct ieee80211_hw *hw, |
| 3867 | struct ieee80211_txq *txq) |
| 3868 | { |
| 3869 | struct ieee80211_local *local = hw_to_local(hw); |
| 3870 | struct txq_info *iter, *tmp, *txqi = to_txq_info(txq); |
| 3871 | struct sta_info *sta; |
| 3872 | u8 ac = txq->ac; |
| 3873 | |
Felix Fietkau | 5b989c1 | 2019-03-15 11:03:35 +0100 | [diff] [blame] | 3874 | spin_lock_bh(&local->active_txq_lock[ac]); |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 3875 | |
| 3876 | if (!txqi->txq.sta) |
| 3877 | goto out; |
| 3878 | |
| 3879 | if (list_empty(&txqi->schedule_order)) |
| 3880 | goto out; |
| 3881 | |
| 3882 | list_for_each_entry_safe(iter, tmp, &local->active_txqs[ac], |
| 3883 | schedule_order) { |
| 3884 | if (iter == txqi) |
| 3885 | break; |
| 3886 | |
| 3887 | if (!iter->txq.sta) { |
| 3888 | list_move_tail(&iter->schedule_order, |
| 3889 | &local->active_txqs[ac]); |
| 3890 | continue; |
| 3891 | } |
| 3892 | sta = container_of(iter->txq.sta, struct sta_info, sta); |
| 3893 | if (sta->airtime[ac].deficit < 0) |
| 3894 | sta->airtime[ac].deficit += sta->airtime_weight; |
| 3895 | list_move_tail(&iter->schedule_order, &local->active_txqs[ac]); |
| 3896 | } |
| 3897 | |
| 3898 | sta = container_of(txqi->txq.sta, struct sta_info, sta); |
| 3899 | if (sta->airtime[ac].deficit >= 0) |
| 3900 | goto out; |
| 3901 | |
| 3902 | sta->airtime[ac].deficit += sta->airtime_weight; |
| 3903 | list_move_tail(&txqi->schedule_order, &local->active_txqs[ac]); |
Felix Fietkau | 5b989c1 | 2019-03-15 11:03:35 +0100 | [diff] [blame] | 3904 | spin_unlock_bh(&local->active_txq_lock[ac]); |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 3905 | |
| 3906 | return false; |
| 3907 | out: |
| 3908 | if (!list_empty(&txqi->schedule_order)) |
| 3909 | list_del_init(&txqi->schedule_order); |
Felix Fietkau | 5b989c1 | 2019-03-15 11:03:35 +0100 | [diff] [blame] | 3910 | spin_unlock_bh(&local->active_txq_lock[ac]); |
Toke Høiland-Jørgensen | b4809e9 | 2018-12-18 17:02:08 -0800 | [diff] [blame] | 3911 | |
| 3912 | return true; |
| 3913 | } |
| 3914 | EXPORT_SYMBOL(ieee80211_txq_may_transmit); |
| 3915 | |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 3916 | void ieee80211_txq_schedule_start(struct ieee80211_hw *hw, u8 ac) |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 3917 | { |
| 3918 | struct ieee80211_local *local = hw_to_local(hw); |
| 3919 | |
| 3920 | spin_lock_bh(&local->active_txq_lock[ac]); |
| 3921 | local->schedule_round[ac]++; |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 3922 | spin_unlock_bh(&local->active_txq_lock[ac]); |
| 3923 | } |
Felix Fietkau | 5b989c1 | 2019-03-15 11:03:35 +0100 | [diff] [blame] | 3924 | EXPORT_SYMBOL(ieee80211_txq_schedule_start); |
Toke Høiland-Jørgensen | 1866760 | 2018-12-18 17:02:06 -0800 | [diff] [blame] | 3925 | |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 3926 | void __ieee80211_subif_start_xmit(struct sk_buff *skb, |
| 3927 | struct net_device *dev, |
Rajkumar Manoharan | 0601677 | 2019-04-11 13:47:25 -0700 | [diff] [blame] | 3928 | u32 info_flags, |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 3929 | u32 ctrl_flags, |
| 3930 | u64 *cookie) |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 3931 | { |
| 3932 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
Felix Fietkau | 1974da8 | 2019-03-25 08:59:23 +0100 | [diff] [blame] | 3933 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 3934 | struct sta_info *sta; |
Johannes Berg | 80616c0 | 2015-04-14 14:50:41 +0200 | [diff] [blame] | 3935 | struct sk_buff *next; |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 3936 | |
| 3937 | if (unlikely(skb->len < ETH_HLEN)) { |
| 3938 | kfree_skb(skb); |
| 3939 | return; |
| 3940 | } |
| 3941 | |
| 3942 | rcu_read_lock(); |
| 3943 | |
Johannes Berg | 2d981fd | 2015-04-10 14:10:10 +0200 | [diff] [blame] | 3944 | if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) |
| 3945 | goto out_free; |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 3946 | |
Felix Fietkau | 1974da8 | 2019-03-25 08:59:23 +0100 | [diff] [blame] | 3947 | if (IS_ERR(sta)) |
| 3948 | sta = NULL; |
| 3949 | |
| 3950 | if (local->ops->wake_tx_queue) { |
| 3951 | u16 queue = __ieee80211_select_queue(sdata, sta, skb); |
| 3952 | skb_set_queue_mapping(skb, queue); |
| 3953 | } |
| 3954 | |
| 3955 | if (sta) { |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3956 | struct ieee80211_fast_tx *fast_tx; |
| 3957 | |
Wen Gong | 70e5366 | 2018-08-08 18:40:01 +0800 | [diff] [blame] | 3958 | sk_pacing_shift_update(skb->sk, sdata->local->hw.tx_sk_pacing_shift); |
Toke Høiland-Jørgensen | 36148c2 | 2018-02-02 16:11:05 +0100 | [diff] [blame] | 3959 | |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3960 | fast_tx = rcu_dereference(sta->fast_tx); |
| 3961 | |
| 3962 | if (fast_tx && |
Toke Høiland-Jørgensen | bb42f2d | 2016-09-22 19:04:20 +0200 | [diff] [blame] | 3963 | ieee80211_xmit_fast(sdata, sta, fast_tx, skb)) |
Johannes Berg | 17c18bf | 2015-03-21 15:25:43 +0100 | [diff] [blame] | 3964 | goto out; |
| 3965 | } |
| 3966 | |
Johannes Berg | 80616c0 | 2015-04-14 14:50:41 +0200 | [diff] [blame] | 3967 | if (skb_is_gso(skb)) { |
| 3968 | struct sk_buff *segs; |
Johannes Berg | 680a0da | 2015-04-13 16:58:25 +0200 | [diff] [blame] | 3969 | |
Johannes Berg | 80616c0 | 2015-04-14 14:50:41 +0200 | [diff] [blame] | 3970 | segs = skb_gso_segment(skb, 0); |
| 3971 | if (IS_ERR(segs)) { |
Johannes Berg | 2d981fd | 2015-04-10 14:10:10 +0200 | [diff] [blame] | 3972 | goto out_free; |
Johannes Berg | 80616c0 | 2015-04-14 14:50:41 +0200 | [diff] [blame] | 3973 | } else if (segs) { |
| 3974 | consume_skb(skb); |
| 3975 | skb = segs; |
| 3976 | } |
| 3977 | } else { |
| 3978 | /* we cannot process non-linear frames on this path */ |
| 3979 | if (skb_linearize(skb)) { |
| 3980 | kfree_skb(skb); |
| 3981 | goto out; |
| 3982 | } |
| 3983 | |
| 3984 | /* the frame could be fragmented, software-encrypted, and other |
| 3985 | * things so we cannot really handle checksum offload with it - |
| 3986 | * fix it up in software before we handle anything else. |
| 3987 | */ |
| 3988 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Johannes Berg | f603f1f | 2015-05-05 15:25:33 +0200 | [diff] [blame] | 3989 | skb_set_transport_header(skb, |
| 3990 | skb_checksum_start_offset(skb)); |
Johannes Berg | 80616c0 | 2015-04-14 14:50:41 +0200 | [diff] [blame] | 3991 | if (skb_checksum_help(skb)) |
| 3992 | goto out_free; |
| 3993 | } |
Johannes Berg | 2d981fd | 2015-04-10 14:10:10 +0200 | [diff] [blame] | 3994 | } |
| 3995 | |
Jason A. Donenfeld | 9f3ef3d | 2020-01-13 18:42:33 -0500 | [diff] [blame] | 3996 | skb_list_walk_safe(skb, skb, next) { |
| 3997 | skb_mark_not_on_list(skb); |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 3998 | |
Markus Theil | 5af7fef | 2020-06-17 10:26:36 +0200 | [diff] [blame] | 3999 | if (skb->protocol == sdata->control_port_protocol) |
| 4000 | ctrl_flags |= IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP; |
| 4001 | |
Rajkumar Manoharan | 0601677 | 2019-04-11 13:47:25 -0700 | [diff] [blame] | 4002 | skb = ieee80211_build_hdr(sdata, skb, info_flags, |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 4003 | sta, ctrl_flags, cookie); |
Jason A. Donenfeld | 9f3ef3d | 2020-01-13 18:42:33 -0500 | [diff] [blame] | 4004 | if (IS_ERR(skb)) { |
| 4005 | kfree_skb_list(next); |
Johannes Berg | 80616c0 | 2015-04-14 14:50:41 +0200 | [diff] [blame] | 4006 | goto out; |
Jason A. Donenfeld | 9f3ef3d | 2020-01-13 18:42:33 -0500 | [diff] [blame] | 4007 | } |
Johannes Berg | 80616c0 | 2015-04-14 14:50:41 +0200 | [diff] [blame] | 4008 | |
Johannes Berg | 5a49051 | 2015-04-22 17:10:38 +0200 | [diff] [blame] | 4009 | ieee80211_tx_stats(dev, skb->len); |
Johannes Berg | 80616c0 | 2015-04-14 14:50:41 +0200 | [diff] [blame] | 4010 | |
Johannes Berg | b9771d4 | 2018-05-28 15:47:41 +0200 | [diff] [blame] | 4011 | ieee80211_xmit(sdata, sta, skb, 0); |
Johannes Berg | 80616c0 | 2015-04-14 14:50:41 +0200 | [diff] [blame] | 4012 | } |
Johannes Berg | 2d981fd | 2015-04-10 14:10:10 +0200 | [diff] [blame] | 4013 | goto out; |
| 4014 | out_free: |
| 4015 | kfree_skb(skb); |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 4016 | out: |
| 4017 | rcu_read_unlock(); |
| 4018 | } |
| 4019 | |
Michael Braun | ebceec8 | 2016-11-22 11:52:18 +0100 | [diff] [blame] | 4020 | static int ieee80211_change_da(struct sk_buff *skb, struct sta_info *sta) |
| 4021 | { |
| 4022 | struct ethhdr *eth; |
| 4023 | int err; |
| 4024 | |
| 4025 | err = skb_ensure_writable(skb, ETH_HLEN); |
| 4026 | if (unlikely(err)) |
| 4027 | return err; |
| 4028 | |
| 4029 | eth = (void *)skb->data; |
| 4030 | ether_addr_copy(eth->h_dest, sta->sta.addr); |
| 4031 | |
| 4032 | return 0; |
| 4033 | } |
| 4034 | |
| 4035 | static bool ieee80211_multicast_to_unicast(struct sk_buff *skb, |
| 4036 | struct net_device *dev) |
| 4037 | { |
| 4038 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 4039 | const struct ethhdr *eth = (void *)skb->data; |
| 4040 | const struct vlan_ethhdr *ethvlan = (void *)skb->data; |
| 4041 | __be16 ethertype; |
| 4042 | |
| 4043 | if (likely(!is_multicast_ether_addr(eth->h_dest))) |
| 4044 | return false; |
| 4045 | |
| 4046 | switch (sdata->vif.type) { |
| 4047 | case NL80211_IFTYPE_AP_VLAN: |
| 4048 | if (sdata->u.vlan.sta) |
| 4049 | return false; |
| 4050 | if (sdata->wdev.use_4addr) |
| 4051 | return false; |
| 4052 | /* fall through */ |
| 4053 | case NL80211_IFTYPE_AP: |
| 4054 | /* check runtime toggle for this bss */ |
| 4055 | if (!sdata->bss->multicast_to_unicast) |
| 4056 | return false; |
| 4057 | break; |
| 4058 | default: |
| 4059 | return false; |
| 4060 | } |
| 4061 | |
| 4062 | /* multicast to unicast conversion only for some payload */ |
| 4063 | ethertype = eth->h_proto; |
| 4064 | if (ethertype == htons(ETH_P_8021Q) && skb->len >= VLAN_ETH_HLEN) |
| 4065 | ethertype = ethvlan->h_vlan_encapsulated_proto; |
| 4066 | switch (ethertype) { |
| 4067 | case htons(ETH_P_ARP): |
| 4068 | case htons(ETH_P_IP): |
| 4069 | case htons(ETH_P_IPV6): |
| 4070 | break; |
| 4071 | default: |
| 4072 | return false; |
| 4073 | } |
| 4074 | |
| 4075 | return true; |
| 4076 | } |
| 4077 | |
| 4078 | static void |
| 4079 | ieee80211_convert_to_unicast(struct sk_buff *skb, struct net_device *dev, |
| 4080 | struct sk_buff_head *queue) |
| 4081 | { |
| 4082 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 4083 | struct ieee80211_local *local = sdata->local; |
| 4084 | const struct ethhdr *eth = (struct ethhdr *)skb->data; |
| 4085 | struct sta_info *sta, *first = NULL; |
| 4086 | struct sk_buff *cloned_skb; |
| 4087 | |
| 4088 | rcu_read_lock(); |
| 4089 | |
| 4090 | list_for_each_entry_rcu(sta, &local->sta_list, list) { |
| 4091 | if (sdata != sta->sdata) |
| 4092 | /* AP-VLAN mismatch */ |
| 4093 | continue; |
| 4094 | if (unlikely(ether_addr_equal(eth->h_source, sta->sta.addr))) |
| 4095 | /* do not send back to source */ |
| 4096 | continue; |
| 4097 | if (!first) { |
| 4098 | first = sta; |
| 4099 | continue; |
| 4100 | } |
| 4101 | cloned_skb = skb_clone(skb, GFP_ATOMIC); |
| 4102 | if (!cloned_skb) |
| 4103 | goto multicast; |
| 4104 | if (unlikely(ieee80211_change_da(cloned_skb, sta))) { |
| 4105 | dev_kfree_skb(cloned_skb); |
| 4106 | goto multicast; |
| 4107 | } |
| 4108 | __skb_queue_tail(queue, cloned_skb); |
| 4109 | } |
| 4110 | |
| 4111 | if (likely(first)) { |
| 4112 | if (unlikely(ieee80211_change_da(skb, first))) |
| 4113 | goto multicast; |
| 4114 | __skb_queue_tail(queue, skb); |
| 4115 | } else { |
| 4116 | /* no STA connected, drop */ |
| 4117 | kfree_skb(skb); |
| 4118 | skb = NULL; |
| 4119 | } |
| 4120 | |
| 4121 | goto out; |
| 4122 | multicast: |
| 4123 | __skb_queue_purge(queue); |
| 4124 | __skb_queue_tail(queue, skb); |
| 4125 | out: |
| 4126 | rcu_read_unlock(); |
| 4127 | } |
| 4128 | |
Johannes Berg | 4c9451e | 2014-11-09 18:50:10 +0200 | [diff] [blame] | 4129 | /** |
| 4130 | * ieee80211_subif_start_xmit - netif start_xmit function for 802.3 vifs |
| 4131 | * @skb: packet to be sent |
| 4132 | * @dev: incoming interface |
| 4133 | * |
| 4134 | * On failure skb will be freed. |
| 4135 | */ |
Liad Kaufman | 24d342c | 2014-11-09 18:50:07 +0200 | [diff] [blame] | 4136 | netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb, |
| 4137 | struct net_device *dev) |
| 4138 | { |
Michael Braun | ebceec8 | 2016-11-22 11:52:18 +0100 | [diff] [blame] | 4139 | if (unlikely(ieee80211_multicast_to_unicast(skb, dev))) { |
| 4140 | struct sk_buff_head queue; |
| 4141 | |
| 4142 | __skb_queue_head_init(&queue); |
| 4143 | ieee80211_convert_to_unicast(skb, dev, &queue); |
| 4144 | while ((skb = __skb_dequeue(&queue))) |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 4145 | __ieee80211_subif_start_xmit(skb, dev, 0, 0, NULL); |
Michael Braun | ebceec8 | 2016-11-22 11:52:18 +0100 | [diff] [blame] | 4146 | } else { |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 4147 | __ieee80211_subif_start_xmit(skb, dev, 0, 0, NULL); |
Michael Braun | ebceec8 | 2016-11-22 11:52:18 +0100 | [diff] [blame] | 4148 | } |
| 4149 | |
Liad Kaufman | 24d342c | 2014-11-09 18:50:07 +0200 | [diff] [blame] | 4150 | return NETDEV_TX_OK; |
| 4151 | } |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4152 | |
John Crispin | 50ff477 | 2019-11-25 11:04:37 +0100 | [diff] [blame] | 4153 | static bool ieee80211_tx_8023(struct ieee80211_sub_if_data *sdata, |
| 4154 | struct sk_buff *skb, int led_len, |
| 4155 | struct sta_info *sta, |
| 4156 | bool txpending) |
| 4157 | { |
| 4158 | struct ieee80211_local *local = sdata->local; |
| 4159 | struct ieee80211_tx_control control = {}; |
| 4160 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 4161 | struct ieee80211_sta *pubsta = NULL; |
| 4162 | unsigned long flags; |
| 4163 | int q = info->hw_queue; |
| 4164 | |
| 4165 | if (ieee80211_queue_skb(local, sdata, sta, skb)) |
| 4166 | return true; |
| 4167 | |
| 4168 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
| 4169 | |
| 4170 | if (local->queue_stop_reasons[q] || |
| 4171 | (!txpending && !skb_queue_empty(&local->pending[q]))) { |
| 4172 | if (txpending) |
| 4173 | skb_queue_head(&local->pending[q], skb); |
| 4174 | else |
| 4175 | skb_queue_tail(&local->pending[q], skb); |
| 4176 | |
| 4177 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 4178 | |
| 4179 | return false; |
| 4180 | } |
| 4181 | |
| 4182 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
| 4183 | |
| 4184 | if (sta && sta->uploaded) |
| 4185 | pubsta = &sta->sta; |
| 4186 | |
| 4187 | control.sta = pubsta; |
| 4188 | |
| 4189 | drv_tx(local, &control, skb); |
| 4190 | |
| 4191 | return true; |
| 4192 | } |
| 4193 | |
| 4194 | static void ieee80211_8023_xmit(struct ieee80211_sub_if_data *sdata, |
| 4195 | struct net_device *dev, struct sta_info *sta, |
| 4196 | struct sk_buff *skb) |
| 4197 | { |
| 4198 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 4199 | struct ethhdr *ehdr = (struct ethhdr *)skb->data; |
| 4200 | struct ieee80211_local *local = sdata->local; |
| 4201 | bool authorized = false; |
| 4202 | bool multicast; |
| 4203 | unsigned char *ra = ehdr->h_dest; |
| 4204 | |
| 4205 | if (IS_ERR(sta) || (sta && !sta->uploaded)) |
| 4206 | sta = NULL; |
| 4207 | |
| 4208 | if (sdata->vif.type == NL80211_IFTYPE_STATION && |
| 4209 | (!sta || !test_sta_flag(sta, WLAN_STA_TDLS_PEER))) |
| 4210 | ra = sdata->u.mgd.bssid; |
| 4211 | |
Seevalamuthu Mariappan | 78fb5b5 | 2020-06-09 15:45:54 +0530 | [diff] [blame] | 4212 | if (is_zero_ether_addr(ra)) |
John Crispin | 50ff477 | 2019-11-25 11:04:37 +0100 | [diff] [blame] | 4213 | goto out_free; |
| 4214 | |
| 4215 | multicast = is_multicast_ether_addr(ra); |
| 4216 | |
| 4217 | if (sta) |
| 4218 | authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED); |
| 4219 | |
| 4220 | if (!multicast && !authorized && |
| 4221 | (ehdr->h_proto != sdata->control_port_protocol || |
| 4222 | !ether_addr_equal(sdata->vif.addr, ehdr->h_source))) |
| 4223 | goto out_free; |
| 4224 | |
| 4225 | if (multicast && sdata->vif.type == NL80211_IFTYPE_AP && |
| 4226 | !atomic_read(&sdata->u.ap.num_mcast_sta)) |
| 4227 | goto out_free; |
| 4228 | |
| 4229 | if (unlikely(test_bit(SCAN_SW_SCANNING, &local->scanning)) && |
| 4230 | test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)) |
| 4231 | goto out_free; |
| 4232 | |
| 4233 | if (unlikely(!multicast && skb->sk && |
| 4234 | skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)) |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 4235 | ieee80211_store_ack_skb(local, skb, &info->flags, NULL); |
John Crispin | 50ff477 | 2019-11-25 11:04:37 +0100 | [diff] [blame] | 4236 | |
| 4237 | memset(info, 0, sizeof(*info)); |
| 4238 | |
| 4239 | if (unlikely(sdata->control_port_protocol == ehdr->h_proto)) { |
| 4240 | if (sdata->control_port_no_encrypt) |
| 4241 | info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 4242 | info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO; |
| 4243 | } |
| 4244 | |
| 4245 | if (multicast) |
| 4246 | info->flags |= IEEE80211_TX_CTL_NO_ACK; |
| 4247 | |
| 4248 | info->hw_queue = sdata->vif.hw_queue[skb_get_queue_mapping(skb)]; |
| 4249 | |
| 4250 | ieee80211_tx_stats(dev, skb->len); |
| 4251 | |
| 4252 | if (sta) { |
| 4253 | sta->tx_stats.bytes[skb_get_queue_mapping(skb)] += skb->len; |
| 4254 | sta->tx_stats.packets[skb_get_queue_mapping(skb)]++; |
| 4255 | } |
| 4256 | |
| 4257 | if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
| 4258 | sdata = container_of(sdata->bss, |
| 4259 | struct ieee80211_sub_if_data, u.ap); |
| 4260 | |
| 4261 | info->control.flags |= IEEE80211_TX_CTRL_HW_80211_ENCAP; |
| 4262 | info->control.vif = &sdata->vif; |
| 4263 | |
| 4264 | ieee80211_tx_8023(sdata, skb, skb->len, sta, false); |
| 4265 | |
| 4266 | return; |
| 4267 | |
| 4268 | out_free: |
| 4269 | kfree_skb(skb); |
| 4270 | } |
| 4271 | |
| 4272 | netdev_tx_t ieee80211_subif_start_xmit_8023(struct sk_buff *skb, |
| 4273 | struct net_device *dev) |
| 4274 | { |
| 4275 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 4276 | struct sta_info *sta; |
| 4277 | |
| 4278 | if (WARN_ON(!sdata->hw_80211_encap)) { |
| 4279 | kfree_skb(skb); |
| 4280 | return NETDEV_TX_OK; |
| 4281 | } |
| 4282 | |
| 4283 | if (unlikely(skb->len < ETH_HLEN)) { |
| 4284 | kfree_skb(skb); |
| 4285 | return NETDEV_TX_OK; |
| 4286 | } |
| 4287 | |
| 4288 | rcu_read_lock(); |
| 4289 | |
| 4290 | if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) |
| 4291 | kfree_skb(skb); |
| 4292 | else |
| 4293 | ieee80211_8023_xmit(sdata, dev, sta, skb); |
| 4294 | |
| 4295 | rcu_read_unlock(); |
| 4296 | |
| 4297 | return NETDEV_TX_OK; |
| 4298 | } |
| 4299 | |
Johannes Berg | 7528ec5 | 2014-11-09 18:50:11 +0200 | [diff] [blame] | 4300 | struct sk_buff * |
| 4301 | ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata, |
| 4302 | struct sk_buff *skb, u32 info_flags) |
| 4303 | { |
| 4304 | struct ieee80211_hdr *hdr; |
| 4305 | struct ieee80211_tx_data tx = { |
| 4306 | .local = sdata->local, |
| 4307 | .sdata = sdata, |
| 4308 | }; |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 4309 | struct sta_info *sta; |
Johannes Berg | 7528ec5 | 2014-11-09 18:50:11 +0200 | [diff] [blame] | 4310 | |
| 4311 | rcu_read_lock(); |
| 4312 | |
Johannes Berg | 97ffe75 | 2015-03-21 09:13:45 +0100 | [diff] [blame] | 4313 | if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) { |
| 4314 | kfree_skb(skb); |
| 4315 | skb = ERR_PTR(-EINVAL); |
| 4316 | goto out; |
| 4317 | } |
| 4318 | |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 4319 | skb = ieee80211_build_hdr(sdata, skb, info_flags, sta, 0, NULL); |
Johannes Berg | 7528ec5 | 2014-11-09 18:50:11 +0200 | [diff] [blame] | 4320 | if (IS_ERR(skb)) |
| 4321 | goto out; |
| 4322 | |
| 4323 | hdr = (void *)skb->data; |
| 4324 | tx.sta = sta_info_get(sdata, hdr->addr1); |
| 4325 | tx.skb = skb; |
| 4326 | |
| 4327 | if (ieee80211_tx_h_select_key(&tx) != TX_CONTINUE) { |
| 4328 | rcu_read_unlock(); |
| 4329 | kfree_skb(skb); |
| 4330 | return ERR_PTR(-EINVAL); |
| 4331 | } |
| 4332 | |
| 4333 | out: |
| 4334 | rcu_read_unlock(); |
| 4335 | return skb; |
| 4336 | } |
| 4337 | |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 4338 | /* |
| 4339 | * ieee80211_clear_tx_pending may not be called in a context where |
| 4340 | * it is possible that it packets could come in again. |
| 4341 | */ |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4342 | void ieee80211_clear_tx_pending(struct ieee80211_local *local) |
| 4343 | { |
Felix Fietkau | 1f98ab7 | 2012-11-10 03:44:14 +0100 | [diff] [blame] | 4344 | struct sk_buff *skb; |
Johannes Berg | 2de8e0d | 2009-03-23 17:28:35 +0100 | [diff] [blame] | 4345 | int i; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4346 | |
Felix Fietkau | 1f98ab7 | 2012-11-10 03:44:14 +0100 | [diff] [blame] | 4347 | for (i = 0; i < local->hw.queues; i++) { |
| 4348 | while ((skb = skb_dequeue(&local->pending[i])) != NULL) |
| 4349 | ieee80211_free_txskb(&local->hw, skb); |
| 4350 | } |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4351 | } |
| 4352 | |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 4353 | /* |
| 4354 | * Returns false if the frame couldn't be transmitted but was queued instead, |
| 4355 | * which in this case means re-queued -- take as an indication to stop sending |
| 4356 | * more pending frames. |
| 4357 | */ |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 4358 | static bool ieee80211_tx_pending_skb(struct ieee80211_local *local, |
| 4359 | struct sk_buff *skb) |
| 4360 | { |
| 4361 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
| 4362 | struct ieee80211_sub_if_data *sdata; |
| 4363 | struct sta_info *sta; |
| 4364 | struct ieee80211_hdr *hdr; |
Johannes Berg | 7bb4568 | 2011-02-24 14:42:06 +0100 | [diff] [blame] | 4365 | bool result; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 4366 | struct ieee80211_chanctx_conf *chanctx_conf; |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 4367 | |
Johannes Berg | 5061b0c | 2009-07-14 00:33:34 +0200 | [diff] [blame] | 4368 | sdata = vif_to_sdata(info->control.vif); |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 4369 | |
| 4370 | if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) { |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 4371 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
| 4372 | if (unlikely(!chanctx_conf)) { |
| 4373 | dev_kfree_skb(skb); |
| 4374 | return true; |
| 4375 | } |
Johannes Berg | 73c4e19 | 2014-11-09 18:50:09 +0200 | [diff] [blame] | 4376 | info->band = chanctx_conf->def.chan->band; |
Johannes Berg | b9771d4 | 2018-05-28 15:47:41 +0200 | [diff] [blame] | 4377 | result = ieee80211_tx(sdata, NULL, skb, true, 0); |
John Crispin | 50ff477 | 2019-11-25 11:04:37 +0100 | [diff] [blame] | 4378 | } else if (info->control.flags & IEEE80211_TX_CTRL_HW_80211_ENCAP) { |
| 4379 | if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) { |
| 4380 | dev_kfree_skb(skb); |
| 4381 | return true; |
| 4382 | } |
| 4383 | |
| 4384 | if (IS_ERR(sta) || (sta && !sta->uploaded)) |
| 4385 | sta = NULL; |
| 4386 | |
| 4387 | result = ieee80211_tx_8023(sdata, skb, skb->len, sta, true); |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 4388 | } else { |
Johannes Berg | 252b86c | 2011-11-16 15:28:55 +0100 | [diff] [blame] | 4389 | struct sk_buff_head skbs; |
| 4390 | |
| 4391 | __skb_queue_head_init(&skbs); |
| 4392 | __skb_queue_tail(&skbs, skb); |
| 4393 | |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 4394 | hdr = (struct ieee80211_hdr *)skb->data; |
Johannes Berg | abe6063 | 2009-11-25 17:46:18 +0100 | [diff] [blame] | 4395 | sta = sta_info_get(sdata, hdr->addr1); |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 4396 | |
Johannes Berg | 74e4dbf | 2011-11-16 15:28:57 +0100 | [diff] [blame] | 4397 | result = __ieee80211_tx(local, &skbs, skb->len, sta, true); |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 4398 | } |
| 4399 | |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 4400 | return result; |
| 4401 | } |
| 4402 | |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 4403 | /* |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 4404 | * Transmit all pending packets. Called from tasklet. |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 4405 | */ |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4406 | void ieee80211_tx_pending(unsigned long data) |
| 4407 | { |
| 4408 | struct ieee80211_local *local = (struct ieee80211_local *)data; |
Johannes Berg | 2a577d9 | 2009-03-23 17:28:37 +0100 | [diff] [blame] | 4409 | unsigned long flags; |
Johannes Berg | cd8ffc8 | 2009-03-23 17:28:41 +0100 | [diff] [blame] | 4410 | int i; |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 4411 | bool txok; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4412 | |
Johannes Berg | f0e7285 | 2009-03-23 17:28:36 +0100 | [diff] [blame] | 4413 | rcu_read_lock(); |
Johannes Berg | 2a577d9 | 2009-03-23 17:28:37 +0100 | [diff] [blame] | 4414 | |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 4415 | spin_lock_irqsave(&local->queue_stop_reason_lock, flags); |
Johannes Berg | 176be72 | 2009-03-12 23:49:28 +0100 | [diff] [blame] | 4416 | for (i = 0; i < local->hw.queues; i++) { |
Johannes Berg | 2a577d9 | 2009-03-23 17:28:37 +0100 | [diff] [blame] | 4417 | /* |
| 4418 | * If queue is stopped by something other than due to pending |
| 4419 | * frames, or we have no pending frames, proceed to next queue. |
| 4420 | */ |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 4421 | if (local->queue_stop_reasons[i] || |
Johannes Berg | 2a577d9 | 2009-03-23 17:28:37 +0100 | [diff] [blame] | 4422 | skb_queue_empty(&local->pending[i])) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4423 | continue; |
Johannes Berg | e253008 | 2008-05-17 00:57:14 +0200 | [diff] [blame] | 4424 | |
Johannes Berg | 2a577d9 | 2009-03-23 17:28:37 +0100 | [diff] [blame] | 4425 | while (!skb_queue_empty(&local->pending[i])) { |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 4426 | struct sk_buff *skb = __skb_dequeue(&local->pending[i]); |
Johannes Berg | 5061b0c | 2009-07-14 00:33:34 +0200 | [diff] [blame] | 4427 | struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); |
Johannes Berg | 5061b0c | 2009-07-14 00:33:34 +0200 | [diff] [blame] | 4428 | |
Johannes Berg | a7bc376 | 2009-07-27 10:33:31 +0200 | [diff] [blame] | 4429 | if (WARN_ON(!info->control.vif)) { |
Felix Fietkau | c3e7724 | 2012-10-08 14:39:33 +0200 | [diff] [blame] | 4430 | ieee80211_free_txskb(&local->hw, skb); |
Johannes Berg | a7bc376 | 2009-07-27 10:33:31 +0200 | [diff] [blame] | 4431 | continue; |
| 4432 | } |
| 4433 | |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 4434 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, |
| 4435 | flags); |
Johannes Berg | 2a577d9 | 2009-03-23 17:28:37 +0100 | [diff] [blame] | 4436 | |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 4437 | txok = ieee80211_tx_pending_skb(local, skb); |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 4438 | spin_lock_irqsave(&local->queue_stop_reason_lock, |
| 4439 | flags); |
| 4440 | if (!txok) |
Johannes Berg | 2a577d9 | 2009-03-23 17:28:37 +0100 | [diff] [blame] | 4441 | break; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4442 | } |
Johannes Berg | 7236fe2 | 2010-03-22 13:42:43 -0700 | [diff] [blame] | 4443 | |
| 4444 | if (skb_queue_empty(&local->pending[i])) |
Johannes Berg | 3a25a8c | 2012-04-03 16:28:50 +0200 | [diff] [blame] | 4445 | ieee80211_propagate_queue_wake(local, i); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4446 | } |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 4447 | spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); |
Johannes Berg | 2a577d9 | 2009-03-23 17:28:37 +0100 | [diff] [blame] | 4448 | |
Johannes Berg | f0e7285 | 2009-03-23 17:28:36 +0100 | [diff] [blame] | 4449 | rcu_read_unlock(); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4450 | } |
| 4451 | |
| 4452 | /* functions for drivers to get certain frames */ |
| 4453 | |
Marco Porsch | eac70c1 | 2013-01-07 16:04:50 +0100 | [diff] [blame] | 4454 | static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata, |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4455 | struct ps_data *ps, struct sk_buff *skb, |
| 4456 | bool is_template) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4457 | { |
| 4458 | u8 *pos, *tim; |
| 4459 | int aid0 = 0; |
| 4460 | int i, have_bits = 0, n1, n2; |
| 4461 | |
| 4462 | /* Generate bitmap for TIM only if there are any STAs in power save |
| 4463 | * mode. */ |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 4464 | if (atomic_read(&ps->num_sta_ps) > 0) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4465 | /* in the hope that this is faster than |
| 4466 | * checking byte-for-byte */ |
Weilong Chen | f359d3f | 2013-12-18 15:44:16 +0800 | [diff] [blame] | 4467 | have_bits = !bitmap_empty((unsigned long *)ps->tim, |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4468 | IEEE80211_MAX_AID+1); |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4469 | if (!is_template) { |
| 4470 | if (ps->dtim_count == 0) |
| 4471 | ps->dtim_count = sdata->vif.bss_conf.dtim_period - 1; |
| 4472 | else |
| 4473 | ps->dtim_count--; |
| 4474 | } |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4475 | |
Johannes Berg | 4df864c | 2017-06-16 14:29:21 +0200 | [diff] [blame] | 4476 | tim = pos = skb_put(skb, 6); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4477 | *pos++ = WLAN_EID_TIM; |
| 4478 | *pos++ = 4; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 4479 | *pos++ = ps->dtim_count; |
Johannes Berg | 8860020 | 2012-02-13 15:17:18 +0100 | [diff] [blame] | 4480 | *pos++ = sdata->vif.bss_conf.dtim_period; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4481 | |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 4482 | if (ps->dtim_count == 0 && !skb_queue_empty(&ps->bc_buf)) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4483 | aid0 = 1; |
| 4484 | |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 4485 | ps->dtim_bc_mc = aid0 == 1; |
Christian Lamparter | 512119b | 2011-01-31 20:48:44 +0200 | [diff] [blame] | 4486 | |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4487 | if (have_bits) { |
| 4488 | /* Find largest even number N1 so that bits numbered 1 through |
| 4489 | * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits |
| 4490 | * (N2 + 1) x 8 through 2007 are 0. */ |
| 4491 | n1 = 0; |
| 4492 | for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) { |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 4493 | if (ps->tim[i]) { |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4494 | n1 = i & 0xfe; |
| 4495 | break; |
| 4496 | } |
| 4497 | } |
| 4498 | n2 = n1; |
| 4499 | for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) { |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 4500 | if (ps->tim[i]) { |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4501 | n2 = i; |
| 4502 | break; |
| 4503 | } |
| 4504 | } |
| 4505 | |
| 4506 | /* Bitmap control */ |
| 4507 | *pos++ = n1 | aid0; |
| 4508 | /* Part Virt Bitmap */ |
Eliad Peller | 5220da3 | 2011-11-24 16:50:00 +0200 | [diff] [blame] | 4509 | skb_put(skb, n2 - n1); |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 4510 | memcpy(pos, ps->tim + n1, n2 - n1 + 1); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4511 | |
| 4512 | tim[1] = n2 - n1 + 4; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4513 | } else { |
| 4514 | *pos++ = aid0; /* Bitmap control */ |
| 4515 | *pos++ = 0; /* Part Virt Bitmap */ |
| 4516 | } |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4517 | } |
| 4518 | |
Marco Porsch | eac70c1 | 2013-01-07 16:04:50 +0100 | [diff] [blame] | 4519 | static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata, |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4520 | struct ps_data *ps, struct sk_buff *skb, |
| 4521 | bool is_template) |
Marco Porsch | eac70c1 | 2013-01-07 16:04:50 +0100 | [diff] [blame] | 4522 | { |
| 4523 | struct ieee80211_local *local = sdata->local; |
| 4524 | |
| 4525 | /* |
| 4526 | * Not very nice, but we want to allow the driver to call |
| 4527 | * ieee80211_beacon_get() as a response to the set_tim() |
| 4528 | * callback. That, however, is already invoked under the |
| 4529 | * sta_lock to guarantee consistent and race-free update |
| 4530 | * of the tim bitmap in mac80211 and the driver. |
| 4531 | */ |
| 4532 | if (local->tim_in_locked_section) { |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4533 | __ieee80211_beacon_add_tim(sdata, ps, skb, is_template); |
Marco Porsch | eac70c1 | 2013-01-07 16:04:50 +0100 | [diff] [blame] | 4534 | } else { |
Johannes Berg | 1b91731 | 2013-02-22 12:55:01 +0100 | [diff] [blame] | 4535 | spin_lock_bh(&local->tim_lock); |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4536 | __ieee80211_beacon_add_tim(sdata, ps, skb, is_template); |
Johannes Berg | 1b91731 | 2013-02-22 12:55:01 +0100 | [diff] [blame] | 4537 | spin_unlock_bh(&local->tim_lock); |
Marco Porsch | eac70c1 | 2013-01-07 16:04:50 +0100 | [diff] [blame] | 4538 | } |
| 4539 | |
| 4540 | return 0; |
| 4541 | } |
| 4542 | |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4543 | static void ieee80211_set_csa(struct ieee80211_sub_if_data *sdata, |
| 4544 | struct beacon_data *beacon) |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 4545 | { |
| 4546 | struct probe_resp *resp; |
Simon Wunderlich | cd7760e | 2013-08-28 13:41:31 +0200 | [diff] [blame] | 4547 | u8 *beacon_data; |
| 4548 | size_t beacon_data_len; |
Andrei Otcheretianski | 0d06d9b | 2014-05-09 14:11:47 +0300 | [diff] [blame] | 4549 | int i; |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4550 | u8 count = beacon->csa_current_counter; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 4551 | |
Simon Wunderlich | cd7760e | 2013-08-28 13:41:31 +0200 | [diff] [blame] | 4552 | switch (sdata->vif.type) { |
| 4553 | case NL80211_IFTYPE_AP: |
| 4554 | beacon_data = beacon->tail; |
| 4555 | beacon_data_len = beacon->tail_len; |
| 4556 | break; |
| 4557 | case NL80211_IFTYPE_ADHOC: |
| 4558 | beacon_data = beacon->head; |
| 4559 | beacon_data_len = beacon->head_len; |
| 4560 | break; |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 4561 | case NL80211_IFTYPE_MESH_POINT: |
| 4562 | beacon_data = beacon->head; |
| 4563 | beacon_data_len = beacon->head_len; |
| 4564 | break; |
Simon Wunderlich | cd7760e | 2013-08-28 13:41:31 +0200 | [diff] [blame] | 4565 | default: |
| 4566 | return; |
| 4567 | } |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 4568 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4569 | rcu_read_lock(); |
Andrei Otcheretianski | 0d06d9b | 2014-05-09 14:11:47 +0300 | [diff] [blame] | 4570 | for (i = 0; i < IEEE80211_MAX_CSA_COUNTERS_NUM; ++i) { |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4571 | resp = rcu_dereference(sdata->u.ap.probe_resp); |
Andrei Otcheretianski | 0d06d9b | 2014-05-09 14:11:47 +0300 | [diff] [blame] | 4572 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4573 | if (beacon->csa_counter_offsets[i]) { |
| 4574 | if (WARN_ON_ONCE(beacon->csa_counter_offsets[i] >= |
| 4575 | beacon_data_len)) { |
Andrei Otcheretianski | 0d06d9b | 2014-05-09 14:11:47 +0300 | [diff] [blame] | 4576 | rcu_read_unlock(); |
| 4577 | return; |
| 4578 | } |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4579 | |
| 4580 | beacon_data[beacon->csa_counter_offsets[i]] = count; |
Andrei Otcheretianski | 0d06d9b | 2014-05-09 14:11:47 +0300 | [diff] [blame] | 4581 | } |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4582 | |
| 4583 | if (sdata->vif.type == NL80211_IFTYPE_AP && resp) |
| 4584 | resp->data[resp->csa_counter_offsets[i]] = count; |
Andrei Otcheretianski | 0d06d9b | 2014-05-09 14:11:47 +0300 | [diff] [blame] | 4585 | } |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4586 | rcu_read_unlock(); |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4587 | } |
| 4588 | |
Wojciech Dubowik | e996ec2 | 2015-06-10 13:06:53 +0200 | [diff] [blame] | 4589 | static u8 __ieee80211_csa_update_counter(struct beacon_data *beacon) |
| 4590 | { |
| 4591 | beacon->csa_current_counter--; |
| 4592 | |
| 4593 | /* the counter should never reach 0 */ |
| 4594 | WARN_ON_ONCE(!beacon->csa_current_counter); |
| 4595 | |
| 4596 | return beacon->csa_current_counter; |
| 4597 | } |
| 4598 | |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4599 | u8 ieee80211_csa_update_counter(struct ieee80211_vif *vif) |
| 4600 | { |
| 4601 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4602 | struct beacon_data *beacon = NULL; |
| 4603 | u8 count = 0; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 4604 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4605 | rcu_read_lock(); |
| 4606 | |
| 4607 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
| 4608 | beacon = rcu_dereference(sdata->u.ap.beacon); |
| 4609 | else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 4610 | beacon = rcu_dereference(sdata->u.ibss.presp); |
| 4611 | else if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 4612 | beacon = rcu_dereference(sdata->u.mesh.beacon); |
| 4613 | |
| 4614 | if (!beacon) |
| 4615 | goto unlock; |
| 4616 | |
Wojciech Dubowik | e996ec2 | 2015-06-10 13:06:53 +0200 | [diff] [blame] | 4617 | count = __ieee80211_csa_update_counter(beacon); |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4618 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4619 | unlock: |
| 4620 | rcu_read_unlock(); |
| 4621 | return count; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 4622 | } |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4623 | EXPORT_SYMBOL(ieee80211_csa_update_counter); |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 4624 | |
Gregory Greenman | 0373700 | 2018-04-20 13:49:24 +0300 | [diff] [blame] | 4625 | void ieee80211_csa_set_counter(struct ieee80211_vif *vif, u8 counter) |
| 4626 | { |
| 4627 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 4628 | struct beacon_data *beacon = NULL; |
| 4629 | |
| 4630 | rcu_read_lock(); |
| 4631 | |
| 4632 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
| 4633 | beacon = rcu_dereference(sdata->u.ap.beacon); |
| 4634 | else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) |
| 4635 | beacon = rcu_dereference(sdata->u.ibss.presp); |
| 4636 | else if (ieee80211_vif_is_mesh(&sdata->vif)) |
| 4637 | beacon = rcu_dereference(sdata->u.mesh.beacon); |
| 4638 | |
| 4639 | if (!beacon) |
| 4640 | goto unlock; |
| 4641 | |
| 4642 | if (counter < beacon->csa_current_counter) |
| 4643 | beacon->csa_current_counter = counter; |
| 4644 | |
| 4645 | unlock: |
| 4646 | rcu_read_unlock(); |
| 4647 | } |
| 4648 | EXPORT_SYMBOL(ieee80211_csa_set_counter); |
| 4649 | |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 4650 | bool ieee80211_csa_is_complete(struct ieee80211_vif *vif) |
| 4651 | { |
| 4652 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 4653 | struct beacon_data *beacon = NULL; |
| 4654 | u8 *beacon_data; |
| 4655 | size_t beacon_data_len; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 4656 | int ret = false; |
| 4657 | |
| 4658 | if (!ieee80211_sdata_running(sdata)) |
| 4659 | return false; |
| 4660 | |
| 4661 | rcu_read_lock(); |
| 4662 | if (vif->type == NL80211_IFTYPE_AP) { |
| 4663 | struct ieee80211_if_ap *ap = &sdata->u.ap; |
| 4664 | |
| 4665 | beacon = rcu_dereference(ap->beacon); |
| 4666 | if (WARN_ON(!beacon || !beacon->tail)) |
| 4667 | goto out; |
| 4668 | beacon_data = beacon->tail; |
| 4669 | beacon_data_len = beacon->tail_len; |
Simon Wunderlich | cd7760e | 2013-08-28 13:41:31 +0200 | [diff] [blame] | 4670 | } else if (vif->type == NL80211_IFTYPE_ADHOC) { |
| 4671 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
| 4672 | |
| 4673 | beacon = rcu_dereference(ifibss->presp); |
| 4674 | if (!beacon) |
| 4675 | goto out; |
| 4676 | |
| 4677 | beacon_data = beacon->head; |
| 4678 | beacon_data_len = beacon->head_len; |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 4679 | } else if (vif->type == NL80211_IFTYPE_MESH_POINT) { |
| 4680 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
| 4681 | |
| 4682 | beacon = rcu_dereference(ifmsh->beacon); |
| 4683 | if (!beacon) |
| 4684 | goto out; |
| 4685 | |
| 4686 | beacon_data = beacon->head; |
| 4687 | beacon_data_len = beacon->head_len; |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 4688 | } else { |
| 4689 | WARN_ON(1); |
| 4690 | goto out; |
| 4691 | } |
| 4692 | |
Michal Kazior | 10d78f2 | 2014-06-05 14:21:37 +0200 | [diff] [blame] | 4693 | if (!beacon->csa_counter_offsets[0]) |
| 4694 | goto out; |
| 4695 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4696 | if (WARN_ON_ONCE(beacon->csa_counter_offsets[0] > beacon_data_len)) |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 4697 | goto out; |
| 4698 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4699 | if (beacon_data[beacon->csa_counter_offsets[0]] == 1) |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 4700 | ret = true; |
| 4701 | out: |
| 4702 | rcu_read_unlock(); |
| 4703 | |
| 4704 | return ret; |
| 4705 | } |
| 4706 | EXPORT_SYMBOL(ieee80211_csa_is_complete); |
| 4707 | |
Jouni Malinen | 0a3a843 | 2020-02-22 15:25:46 +0200 | [diff] [blame] | 4708 | static int ieee80211_beacon_protect(struct sk_buff *skb, |
| 4709 | struct ieee80211_local *local, |
| 4710 | struct ieee80211_sub_if_data *sdata) |
| 4711 | { |
| 4712 | ieee80211_tx_result res; |
| 4713 | struct ieee80211_tx_data tx; |
Johannes Berg | 9524770 | 2020-03-20 10:20:23 +0100 | [diff] [blame] | 4714 | struct sk_buff *check_skb; |
Jouni Malinen | 0a3a843 | 2020-02-22 15:25:46 +0200 | [diff] [blame] | 4715 | |
| 4716 | memset(&tx, 0, sizeof(tx)); |
| 4717 | tx.key = rcu_dereference(sdata->default_beacon_key); |
| 4718 | if (!tx.key) |
| 4719 | return 0; |
| 4720 | tx.local = local; |
| 4721 | tx.sdata = sdata; |
| 4722 | __skb_queue_head_init(&tx.skbs); |
| 4723 | __skb_queue_tail(&tx.skbs, skb); |
| 4724 | res = ieee80211_tx_h_encrypt(&tx); |
Johannes Berg | 9524770 | 2020-03-20 10:20:23 +0100 | [diff] [blame] | 4725 | check_skb = __skb_dequeue(&tx.skbs); |
| 4726 | /* we may crash after this, but it'd be a bug in crypto */ |
| 4727 | WARN_ON(check_skb != skb); |
Jouni Malinen | 0a3a843 | 2020-02-22 15:25:46 +0200 | [diff] [blame] | 4728 | if (WARN_ON_ONCE(res != TX_CONTINUE)) |
Johannes Berg | 9524770 | 2020-03-20 10:20:23 +0100 | [diff] [blame] | 4729 | return -EINVAL; |
Jouni Malinen | 0a3a843 | 2020-02-22 15:25:46 +0200 | [diff] [blame] | 4730 | |
| 4731 | return 0; |
| 4732 | } |
| 4733 | |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4734 | static struct sk_buff * |
| 4735 | __ieee80211_beacon_get(struct ieee80211_hw *hw, |
| 4736 | struct ieee80211_vif *vif, |
| 4737 | struct ieee80211_mutable_offsets *offs, |
| 4738 | bool is_template) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4739 | { |
| 4740 | struct ieee80211_local *local = hw_to_local(hw); |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4741 | struct beacon_data *beacon = NULL; |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 4742 | struct sk_buff *skb = NULL; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 4743 | struct ieee80211_tx_info *info; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4744 | struct ieee80211_sub_if_data *sdata = NULL; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 4745 | enum nl80211_band band; |
Jouni Malinen | e00cfce | 2009-12-29 12:59:19 +0200 | [diff] [blame] | 4746 | struct ieee80211_tx_rate_control txrc; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 4747 | struct ieee80211_chanctx_conf *chanctx_conf; |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4748 | int csa_off_base = 0; |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 4749 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 4750 | rcu_read_lock(); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4751 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 4752 | sdata = vif_to_sdata(vif); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 4753 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4754 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 4755 | if (!ieee80211_sdata_running(sdata) || !chanctx_conf) |
Felix Fietkau | eb3e554 | 2011-01-24 19:28:49 +0100 | [diff] [blame] | 4756 | goto out; |
| 4757 | |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4758 | if (offs) |
| 4759 | memset(offs, 0, sizeof(*offs)); |
Johannes Berg | eddcbb94 | 2009-10-29 08:30:35 +0100 | [diff] [blame] | 4760 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 4761 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 4762 | struct ieee80211_if_ap *ap = &sdata->u.ap; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 4763 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4764 | beacon = rcu_dereference(ap->beacon); |
Dan Carpenter | 3ad97fb | 2011-02-07 22:03:35 +0300 | [diff] [blame] | 4765 | if (beacon) { |
Michal Kazior | 10d78f2 | 2014-06-05 14:21:37 +0200 | [diff] [blame] | 4766 | if (beacon->csa_counter_offsets[0]) { |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4767 | if (!is_template) |
Wojciech Dubowik | e996ec2 | 2015-06-10 13:06:53 +0200 | [diff] [blame] | 4768 | __ieee80211_csa_update_counter(beacon); |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4769 | |
| 4770 | ieee80211_set_csa(sdata, beacon); |
| 4771 | } |
Simon Wunderlich | 73da7d5 | 2013-07-11 16:09:06 +0200 | [diff] [blame] | 4772 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 4773 | /* |
| 4774 | * headroom, head length, |
| 4775 | * tail length and maximum TIM length |
| 4776 | */ |
| 4777 | skb = dev_alloc_skb(local->tx_headroom + |
| 4778 | beacon->head_len + |
Felix Fietkau | 70dabeb | 2013-12-14 13:54:53 +0100 | [diff] [blame] | 4779 | beacon->tail_len + 256 + |
| 4780 | local->hw.extra_beacon_tailroom); |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 4781 | if (!skb) |
| 4782 | goto out; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 4783 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 4784 | skb_reserve(skb, local->tx_headroom); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 4785 | skb_put_data(skb, beacon->head, beacon->head_len); |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 4786 | |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4787 | ieee80211_beacon_add_tim(sdata, &ap->ps, skb, |
| 4788 | is_template); |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 4789 | |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4790 | if (offs) { |
| 4791 | offs->tim_offset = beacon->head_len; |
| 4792 | offs->tim_length = skb->len - beacon->head_len; |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4793 | |
| 4794 | /* for AP the csa offsets are from tail */ |
| 4795 | csa_off_base = skb->len; |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4796 | } |
Johannes Berg | eddcbb94 | 2009-10-29 08:30:35 +0100 | [diff] [blame] | 4797 | |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 4798 | if (beacon->tail) |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 4799 | skb_put_data(skb, beacon->tail, |
| 4800 | beacon->tail_len); |
Jouni Malinen | 0a3a843 | 2020-02-22 15:25:46 +0200 | [diff] [blame] | 4801 | |
| 4802 | if (ieee80211_beacon_protect(skb, local, sdata) < 0) |
| 4803 | goto out; |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 4804 | } else |
| 4805 | goto out; |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 4806 | } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 4807 | struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 4808 | struct ieee80211_hdr *hdr; |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 4809 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4810 | beacon = rcu_dereference(ifibss->presp); |
| 4811 | if (!beacon) |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 4812 | goto out; |
| 4813 | |
Michal Kazior | 10d78f2 | 2014-06-05 14:21:37 +0200 | [diff] [blame] | 4814 | if (beacon->csa_counter_offsets[0]) { |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4815 | if (!is_template) |
Wojciech Dubowik | e996ec2 | 2015-06-10 13:06:53 +0200 | [diff] [blame] | 4816 | __ieee80211_csa_update_counter(beacon); |
Simon Wunderlich | cd7760e | 2013-08-28 13:41:31 +0200 | [diff] [blame] | 4817 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4818 | ieee80211_set_csa(sdata, beacon); |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4819 | } |
Simon Wunderlich | cd7760e | 2013-08-28 13:41:31 +0200 | [diff] [blame] | 4820 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4821 | skb = dev_alloc_skb(local->tx_headroom + beacon->head_len + |
Felix Fietkau | 70dabeb | 2013-12-14 13:54:53 +0100 | [diff] [blame] | 4822 | local->hw.extra_beacon_tailroom); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 4823 | if (!skb) |
| 4824 | goto out; |
Johannes Berg | c3ffeab | 2013-03-07 20:54:29 +0100 | [diff] [blame] | 4825 | skb_reserve(skb, local->tx_headroom); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 4826 | skb_put_data(skb, beacon->head, beacon->head_len); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 4827 | |
| 4828 | hdr = (struct ieee80211_hdr *) skb->data; |
Harvey Harrison | e7827a7 | 2008-07-15 18:44:13 -0700 | [diff] [blame] | 4829 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 4830 | IEEE80211_STYPE_BEACON); |
Johannes Berg | 902acc7 | 2008-02-23 15:17:19 +0100 | [diff] [blame] | 4831 | } else if (ieee80211_vif_is_mesh(&sdata->vif)) { |
Javier Cardona | dbf498f | 2012-03-31 11:31:32 -0700 | [diff] [blame] | 4832 | struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 4833 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4834 | beacon = rcu_dereference(ifmsh->beacon); |
| 4835 | if (!beacon) |
Johannes Berg | ac1bd84 | 2011-01-18 13:45:32 +0100 | [diff] [blame] | 4836 | goto out; |
Johannes Berg | ac1bd84 | 2011-01-18 13:45:32 +0100 | [diff] [blame] | 4837 | |
Michal Kazior | 10d78f2 | 2014-06-05 14:21:37 +0200 | [diff] [blame] | 4838 | if (beacon->csa_counter_offsets[0]) { |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4839 | if (!is_template) |
| 4840 | /* TODO: For mesh csa_counter is in TU, so |
| 4841 | * decrementing it by one isn't correct, but |
| 4842 | * for now we leave it consistent with overall |
| 4843 | * mac80211's behavior. |
| 4844 | */ |
Wojciech Dubowik | e996ec2 | 2015-06-10 13:06:53 +0200 | [diff] [blame] | 4845 | __ieee80211_csa_update_counter(beacon); |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4846 | |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4847 | ieee80211_set_csa(sdata, beacon); |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4848 | } |
Chun-Yeow Yeoh | b8456a1 | 2013-10-17 15:55:02 -0700 | [diff] [blame] | 4849 | |
Javier Cardona | dbf498f | 2012-03-31 11:31:32 -0700 | [diff] [blame] | 4850 | if (ifmsh->sync_ops) |
Masashi Honma | 445cd45 | 2016-12-08 10:15:51 +0900 | [diff] [blame] | 4851 | ifmsh->sync_ops->adjust_tsf(sdata, beacon); |
Javier Cardona | dbf498f | 2012-03-31 11:31:32 -0700 | [diff] [blame] | 4852 | |
Thomas Pedersen | 3b69a9c | 2011-10-26 14:47:25 -0700 | [diff] [blame] | 4853 | skb = dev_alloc_skb(local->tx_headroom + |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4854 | beacon->head_len + |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 4855 | 256 + /* TIM IE */ |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4856 | beacon->tail_len + |
Felix Fietkau | 70dabeb | 2013-12-14 13:54:53 +0100 | [diff] [blame] | 4857 | local->hw.extra_beacon_tailroom); |
Luis Carlos Cobo | 33b64eb | 2008-02-23 15:17:10 +0100 | [diff] [blame] | 4858 | if (!skb) |
| 4859 | goto out; |
Thomas Pedersen | 2b5e196 | 2013-02-14 11:20:13 -0800 | [diff] [blame] | 4860 | skb_reserve(skb, local->tx_headroom); |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 4861 | skb_put_data(skb, beacon->head, beacon->head_len); |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4862 | ieee80211_beacon_add_tim(sdata, &ifmsh->ps, skb, is_template); |
| 4863 | |
| 4864 | if (offs) { |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4865 | offs->tim_offset = beacon->head_len; |
| 4866 | offs->tim_length = skb->len - beacon->head_len; |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4867 | } |
| 4868 | |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 4869 | skb_put_data(skb, beacon->tail, beacon->tail_len); |
Johannes Berg | 9d139c8 | 2008-07-09 14:40:37 +0200 | [diff] [blame] | 4870 | } else { |
| 4871 | WARN_ON(1); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 4872 | goto out; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4873 | } |
| 4874 | |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4875 | /* CSA offsets */ |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4876 | if (offs && beacon) { |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4877 | int i; |
| 4878 | |
| 4879 | for (i = 0; i < IEEE80211_MAX_CSA_COUNTERS_NUM; i++) { |
Michal Kazior | af296bd | 2014-06-05 14:21:36 +0200 | [diff] [blame] | 4880 | u16 csa_off = beacon->csa_counter_offsets[i]; |
Andrei Otcheretianski | 1af586c | 2014-05-09 14:11:50 +0300 | [diff] [blame] | 4881 | |
| 4882 | if (!csa_off) |
| 4883 | continue; |
| 4884 | |
| 4885 | offs->csa_counter_offs[i] = csa_off_base + csa_off; |
| 4886 | } |
| 4887 | } |
| 4888 | |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 4889 | band = chanctx_conf->def.chan->band; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 4890 | |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 4891 | info = IEEE80211_SKB_CB(skb); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4892 | |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 4893 | info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
Jouni Malinen | e00cfce | 2009-12-29 12:59:19 +0200 | [diff] [blame] | 4894 | info->flags |= IEEE80211_TX_CTL_NO_ACK; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 4895 | info->band = band; |
Jouni Malinen | e00cfce | 2009-12-29 12:59:19 +0200 | [diff] [blame] | 4896 | |
| 4897 | memset(&txrc, 0, sizeof(txrc)); |
| 4898 | txrc.hw = hw; |
Johannes Berg | e31583c | 2012-07-26 14:07:46 +0200 | [diff] [blame] | 4899 | txrc.sband = local->hw.wiphy->bands[band]; |
Jouni Malinen | e00cfce | 2009-12-29 12:59:19 +0200 | [diff] [blame] | 4900 | txrc.bss_conf = &sdata->vif.bss_conf; |
| 4901 | txrc.skb = skb; |
| 4902 | txrc.reported_rate.idx = -1; |
Jouni Malinen | 08fad43 | 2020-04-25 18:57:12 +0300 | [diff] [blame] | 4903 | if (sdata->beacon_rate_set && sdata->beacon_rateidx_mask[band]) |
| 4904 | txrc.rate_idx_mask = sdata->beacon_rateidx_mask[band]; |
| 4905 | else |
| 4906 | txrc.rate_idx_mask = sdata->rc_rateidx_mask[band]; |
Felix Fietkau | 8f0729b | 2010-11-11 15:07:23 +0100 | [diff] [blame] | 4907 | txrc.bss = true; |
Jouni Malinen | e00cfce | 2009-12-29 12:59:19 +0200 | [diff] [blame] | 4908 | rate_control_get_rate(sdata, NULL, &txrc); |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 4909 | |
| 4910 | info->control.vif = vif; |
Johannes Berg | f591fa5 | 2008-07-10 11:21:26 +0200 | [diff] [blame] | 4911 | |
John W. Linville | a472e71 | 2010-05-06 14:45:17 -0400 | [diff] [blame] | 4912 | info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT | |
| 4913 | IEEE80211_TX_CTL_ASSIGN_SEQ | |
| 4914 | IEEE80211_TX_CTL_FIRST_FRAGMENT; |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 4915 | out: |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 4916 | rcu_read_unlock(); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4917 | return skb; |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4918 | |
| 4919 | } |
| 4920 | |
| 4921 | struct sk_buff * |
| 4922 | ieee80211_beacon_get_template(struct ieee80211_hw *hw, |
| 4923 | struct ieee80211_vif *vif, |
| 4924 | struct ieee80211_mutable_offsets *offs) |
| 4925 | { |
| 4926 | return __ieee80211_beacon_get(hw, vif, offs, true); |
| 4927 | } |
| 4928 | EXPORT_SYMBOL(ieee80211_beacon_get_template); |
| 4929 | |
| 4930 | struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw, |
| 4931 | struct ieee80211_vif *vif, |
| 4932 | u16 *tim_offset, u16 *tim_length) |
| 4933 | { |
| 4934 | struct ieee80211_mutable_offsets offs = {}; |
| 4935 | struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false); |
Helmut Schaa | 35afa58 | 2015-09-09 09:46:32 +0200 | [diff] [blame] | 4936 | struct sk_buff *copy; |
| 4937 | struct ieee80211_supported_band *sband; |
| 4938 | int shift; |
| 4939 | |
| 4940 | if (!bcn) |
| 4941 | return bcn; |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4942 | |
| 4943 | if (tim_offset) |
| 4944 | *tim_offset = offs.tim_offset; |
| 4945 | |
| 4946 | if (tim_length) |
| 4947 | *tim_length = offs.tim_length; |
| 4948 | |
Helmut Schaa | 35afa58 | 2015-09-09 09:46:32 +0200 | [diff] [blame] | 4949 | if (ieee80211_hw_check(hw, BEACON_TX_STATUS) || |
| 4950 | !hw_to_local(hw)->monitors) |
| 4951 | return bcn; |
| 4952 | |
| 4953 | /* send a copy to monitor interfaces */ |
| 4954 | copy = skb_copy(bcn, GFP_ATOMIC); |
| 4955 | if (!copy) |
| 4956 | return bcn; |
| 4957 | |
| 4958 | shift = ieee80211_vif_get_shift(vif); |
Mohammed Shafi Shajakhan | 21a8e9d | 2017-04-27 12:45:38 +0530 | [diff] [blame] | 4959 | sband = ieee80211_get_sband(vif_to_sdata(vif)); |
| 4960 | if (!sband) |
| 4961 | return bcn; |
| 4962 | |
John Crispin | b7b2e8c | 2019-07-14 17:44:15 +0200 | [diff] [blame] | 4963 | ieee80211_tx_monitor(hw_to_local(hw), copy, sband, 1, shift, false, |
| 4964 | NULL); |
Helmut Schaa | 35afa58 | 2015-09-09 09:46:32 +0200 | [diff] [blame] | 4965 | |
Andrei Otcheretianski | 6ec8c33 | 2014-05-09 14:11:49 +0300 | [diff] [blame] | 4966 | return bcn; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4967 | } |
Johannes Berg | eddcbb94 | 2009-10-29 08:30:35 +0100 | [diff] [blame] | 4968 | EXPORT_SYMBOL(ieee80211_beacon_get_tim); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 4969 | |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 4970 | struct sk_buff *ieee80211_proberesp_get(struct ieee80211_hw *hw, |
| 4971 | struct ieee80211_vif *vif) |
| 4972 | { |
| 4973 | struct ieee80211_if_ap *ap = NULL; |
Eyal Shapira | aa7a008 | 2012-08-06 14:26:16 +0300 | [diff] [blame] | 4974 | struct sk_buff *skb = NULL; |
| 4975 | struct probe_resp *presp = NULL; |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 4976 | struct ieee80211_hdr *hdr; |
| 4977 | struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); |
| 4978 | |
| 4979 | if (sdata->vif.type != NL80211_IFTYPE_AP) |
| 4980 | return NULL; |
| 4981 | |
| 4982 | rcu_read_lock(); |
| 4983 | |
| 4984 | ap = &sdata->u.ap; |
| 4985 | presp = rcu_dereference(ap->probe_resp); |
| 4986 | if (!presp) |
| 4987 | goto out; |
| 4988 | |
Eyal Shapira | aa7a008 | 2012-08-06 14:26:16 +0300 | [diff] [blame] | 4989 | skb = dev_alloc_skb(presp->len); |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 4990 | if (!skb) |
| 4991 | goto out; |
| 4992 | |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 4993 | skb_put_data(skb, presp->data, presp->len); |
Eyal Shapira | aa7a008 | 2012-08-06 14:26:16 +0300 | [diff] [blame] | 4994 | |
Arik Nemtsov | 0294582 | 2011-11-10 11:28:57 +0200 | [diff] [blame] | 4995 | hdr = (struct ieee80211_hdr *) skb->data; |
| 4996 | memset(hdr->addr1, 0, sizeof(hdr->addr1)); |
| 4997 | |
| 4998 | out: |
| 4999 | rcu_read_unlock(); |
| 5000 | return skb; |
| 5001 | } |
| 5002 | EXPORT_SYMBOL(ieee80211_proberesp_get); |
| 5003 | |
Kalle Valo | 7044cc5 | 2010-01-05 20:16:19 +0200 | [diff] [blame] | 5004 | struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw, |
| 5005 | struct ieee80211_vif *vif) |
| 5006 | { |
| 5007 | struct ieee80211_sub_if_data *sdata; |
| 5008 | struct ieee80211_if_managed *ifmgd; |
| 5009 | struct ieee80211_pspoll *pspoll; |
| 5010 | struct ieee80211_local *local; |
| 5011 | struct sk_buff *skb; |
| 5012 | |
| 5013 | if (WARN_ON(vif->type != NL80211_IFTYPE_STATION)) |
| 5014 | return NULL; |
| 5015 | |
| 5016 | sdata = vif_to_sdata(vif); |
| 5017 | ifmgd = &sdata->u.mgd; |
| 5018 | local = sdata->local; |
| 5019 | |
| 5020 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll)); |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 5021 | if (!skb) |
Kalle Valo | 7044cc5 | 2010-01-05 20:16:19 +0200 | [diff] [blame] | 5022 | return NULL; |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 5023 | |
Kalle Valo | 7044cc5 | 2010-01-05 20:16:19 +0200 | [diff] [blame] | 5024 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 5025 | |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 5026 | pspoll = skb_put_zero(skb, sizeof(*pspoll)); |
Kalle Valo | 7044cc5 | 2010-01-05 20:16:19 +0200 | [diff] [blame] | 5027 | pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | |
| 5028 | IEEE80211_STYPE_PSPOLL); |
Johannes Berg | 1db364c | 2020-04-17 12:38:04 +0200 | [diff] [blame] | 5029 | pspoll->aid = cpu_to_le16(sdata->vif.bss_conf.aid); |
Kalle Valo | 7044cc5 | 2010-01-05 20:16:19 +0200 | [diff] [blame] | 5030 | |
| 5031 | /* aid in PS-Poll has its two MSBs each set to 1 */ |
| 5032 | pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14); |
| 5033 | |
| 5034 | memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN); |
| 5035 | memcpy(pspoll->ta, vif->addr, ETH_ALEN); |
| 5036 | |
| 5037 | return skb; |
| 5038 | } |
| 5039 | EXPORT_SYMBOL(ieee80211_pspoll_get); |
| 5040 | |
| 5041 | struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw, |
Johannes Berg | 7b6ddea | 2017-11-21 14:46:08 +0100 | [diff] [blame] | 5042 | struct ieee80211_vif *vif, |
| 5043 | bool qos_ok) |
Kalle Valo | 7044cc5 | 2010-01-05 20:16:19 +0200 | [diff] [blame] | 5044 | { |
| 5045 | struct ieee80211_hdr_3addr *nullfunc; |
| 5046 | struct ieee80211_sub_if_data *sdata; |
| 5047 | struct ieee80211_if_managed *ifmgd; |
| 5048 | struct ieee80211_local *local; |
| 5049 | struct sk_buff *skb; |
Johannes Berg | 7b6ddea | 2017-11-21 14:46:08 +0100 | [diff] [blame] | 5050 | bool qos = false; |
Kalle Valo | 7044cc5 | 2010-01-05 20:16:19 +0200 | [diff] [blame] | 5051 | |
| 5052 | if (WARN_ON(vif->type != NL80211_IFTYPE_STATION)) |
| 5053 | return NULL; |
| 5054 | |
| 5055 | sdata = vif_to_sdata(vif); |
| 5056 | ifmgd = &sdata->u.mgd; |
| 5057 | local = sdata->local; |
| 5058 | |
Johannes Berg | 7b6ddea | 2017-11-21 14:46:08 +0100 | [diff] [blame] | 5059 | if (qos_ok) { |
| 5060 | struct sta_info *sta; |
| 5061 | |
| 5062 | rcu_read_lock(); |
| 5063 | sta = sta_info_get(sdata, ifmgd->bssid); |
| 5064 | qos = sta && sta->sta.wme; |
| 5065 | rcu_read_unlock(); |
| 5066 | } |
| 5067 | |
| 5068 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + |
| 5069 | sizeof(*nullfunc) + 2); |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 5070 | if (!skb) |
Kalle Valo | 7044cc5 | 2010-01-05 20:16:19 +0200 | [diff] [blame] | 5071 | return NULL; |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 5072 | |
Kalle Valo | 7044cc5 | 2010-01-05 20:16:19 +0200 | [diff] [blame] | 5073 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 5074 | |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 5075 | nullfunc = skb_put_zero(skb, sizeof(*nullfunc)); |
Kalle Valo | 7044cc5 | 2010-01-05 20:16:19 +0200 | [diff] [blame] | 5076 | nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 5077 | IEEE80211_STYPE_NULLFUNC | |
| 5078 | IEEE80211_FCTL_TODS); |
Johannes Berg | 7b6ddea | 2017-11-21 14:46:08 +0100 | [diff] [blame] | 5079 | if (qos) { |
Johannes Berg | e0ba709 | 2018-11-09 11:16:46 +0100 | [diff] [blame] | 5080 | __le16 qoshdr = cpu_to_le16(7); |
Johannes Berg | 7b6ddea | 2017-11-21 14:46:08 +0100 | [diff] [blame] | 5081 | |
| 5082 | BUILD_BUG_ON((IEEE80211_STYPE_QOS_NULLFUNC | |
| 5083 | IEEE80211_STYPE_NULLFUNC) != |
| 5084 | IEEE80211_STYPE_QOS_NULLFUNC); |
| 5085 | nullfunc->frame_control |= |
| 5086 | cpu_to_le16(IEEE80211_STYPE_QOS_NULLFUNC); |
| 5087 | skb->priority = 7; |
| 5088 | skb_set_queue_mapping(skb, IEEE80211_AC_VO); |
Johannes Berg | e0ba709 | 2018-11-09 11:16:46 +0100 | [diff] [blame] | 5089 | skb_put_data(skb, &qoshdr, sizeof(qoshdr)); |
Johannes Berg | 7b6ddea | 2017-11-21 14:46:08 +0100 | [diff] [blame] | 5090 | } |
| 5091 | |
Kalle Valo | 7044cc5 | 2010-01-05 20:16:19 +0200 | [diff] [blame] | 5092 | memcpy(nullfunc->addr1, ifmgd->bssid, ETH_ALEN); |
| 5093 | memcpy(nullfunc->addr2, vif->addr, ETH_ALEN); |
| 5094 | memcpy(nullfunc->addr3, ifmgd->bssid, ETH_ALEN); |
| 5095 | |
| 5096 | return skb; |
| 5097 | } |
| 5098 | EXPORT_SYMBOL(ieee80211_nullfunc_get); |
| 5099 | |
Kalle Valo | 05e54ea | 2010-01-05 20:16:38 +0200 | [diff] [blame] | 5100 | struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw, |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 5101 | const u8 *src_addr, |
Kalle Valo | 05e54ea | 2010-01-05 20:16:38 +0200 | [diff] [blame] | 5102 | const u8 *ssid, size_t ssid_len, |
Johannes Berg | b9a9ada | 2012-11-29 13:00:10 +0100 | [diff] [blame] | 5103 | size_t tailroom) |
Kalle Valo | 05e54ea | 2010-01-05 20:16:38 +0200 | [diff] [blame] | 5104 | { |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 5105 | struct ieee80211_local *local = hw_to_local(hw); |
Kalle Valo | 05e54ea | 2010-01-05 20:16:38 +0200 | [diff] [blame] | 5106 | struct ieee80211_hdr_3addr *hdr; |
| 5107 | struct sk_buff *skb; |
| 5108 | size_t ie_ssid_len; |
| 5109 | u8 *pos; |
| 5110 | |
Kalle Valo | 05e54ea | 2010-01-05 20:16:38 +0200 | [diff] [blame] | 5111 | ie_ssid_len = 2 + ssid_len; |
| 5112 | |
| 5113 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) + |
Johannes Berg | b9a9ada | 2012-11-29 13:00:10 +0100 | [diff] [blame] | 5114 | ie_ssid_len + tailroom); |
Joe Perches | d15b845 | 2011-08-29 14:17:31 -0700 | [diff] [blame] | 5115 | if (!skb) |
Kalle Valo | 05e54ea | 2010-01-05 20:16:38 +0200 | [diff] [blame] | 5116 | return NULL; |
Kalle Valo | 05e54ea | 2010-01-05 20:16:38 +0200 | [diff] [blame] | 5117 | |
| 5118 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 5119 | |
Johannes Berg | b080db5 | 2017-06-16 14:29:19 +0200 | [diff] [blame] | 5120 | hdr = skb_put_zero(skb, sizeof(*hdr)); |
Kalle Valo | 05e54ea | 2010-01-05 20:16:38 +0200 | [diff] [blame] | 5121 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 5122 | IEEE80211_STYPE_PROBE_REQ); |
Johannes Berg | e83e654 | 2012-07-13 16:23:07 +0200 | [diff] [blame] | 5123 | eth_broadcast_addr(hdr->addr1); |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 5124 | memcpy(hdr->addr2, src_addr, ETH_ALEN); |
Johannes Berg | e83e654 | 2012-07-13 16:23:07 +0200 | [diff] [blame] | 5125 | eth_broadcast_addr(hdr->addr3); |
Kalle Valo | 05e54ea | 2010-01-05 20:16:38 +0200 | [diff] [blame] | 5126 | |
| 5127 | pos = skb_put(skb, ie_ssid_len); |
| 5128 | *pos++ = WLAN_EID_SSID; |
| 5129 | *pos++ = ssid_len; |
Stanislaw Gruszka | 88c868c | 2012-03-29 16:30:41 +0200 | [diff] [blame] | 5130 | if (ssid_len) |
Kalle Valo | 05e54ea | 2010-01-05 20:16:38 +0200 | [diff] [blame] | 5131 | memcpy(pos, ssid, ssid_len); |
| 5132 | pos += ssid_len; |
| 5133 | |
Kalle Valo | 05e54ea | 2010-01-05 20:16:38 +0200 | [diff] [blame] | 5134 | return skb; |
| 5135 | } |
| 5136 | EXPORT_SYMBOL(ieee80211_probereq_get); |
| 5137 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5138 | void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5139 | const void *frame, size_t frame_len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 5140 | const struct ieee80211_tx_info *frame_txctl, |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5141 | struct ieee80211_rts *rts) |
| 5142 | { |
| 5143 | const struct ieee80211_hdr *hdr = frame; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5144 | |
Harvey Harrison | 065e9605 | 2008-06-22 16:45:27 -0700 | [diff] [blame] | 5145 | rts->frame_control = |
| 5146 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5147 | rts->duration = ieee80211_rts_duration(hw, vif, frame_len, |
| 5148 | frame_txctl); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5149 | memcpy(rts->ra, hdr->addr1, sizeof(rts->ra)); |
| 5150 | memcpy(rts->ta, hdr->addr2, sizeof(rts->ta)); |
| 5151 | } |
| 5152 | EXPORT_SYMBOL(ieee80211_rts_get); |
| 5153 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5154 | void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif, |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5155 | const void *frame, size_t frame_len, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 5156 | const struct ieee80211_tx_info *frame_txctl, |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5157 | struct ieee80211_cts *cts) |
| 5158 | { |
| 5159 | const struct ieee80211_hdr *hdr = frame; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5160 | |
Harvey Harrison | 065e9605 | 2008-06-22 16:45:27 -0700 | [diff] [blame] | 5161 | cts->frame_control = |
| 5162 | cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS); |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5163 | cts->duration = ieee80211_ctstoself_duration(hw, vif, |
| 5164 | frame_len, frame_txctl); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5165 | memcpy(cts->ra, hdr->addr1, sizeof(cts->ra)); |
| 5166 | } |
| 5167 | EXPORT_SYMBOL(ieee80211_ctstoself_get); |
| 5168 | |
| 5169 | struct sk_buff * |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5170 | ieee80211_get_buffered_bc(struct ieee80211_hw *hw, |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 5171 | struct ieee80211_vif *vif) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5172 | { |
| 5173 | struct ieee80211_local *local = hw_to_local(hw); |
Tomas Winkler | 747cf5e | 2008-05-27 17:50:51 +0300 | [diff] [blame] | 5174 | struct sk_buff *skb = NULL; |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 5175 | struct ieee80211_tx_data tx; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5176 | struct ieee80211_sub_if_data *sdata; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 5177 | struct ps_data *ps; |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 5178 | struct ieee80211_tx_info *info; |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 5179 | struct ieee80211_chanctx_conf *chanctx_conf; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5180 | |
Johannes Berg | 32bfd35 | 2007-12-19 01:31:26 +0100 | [diff] [blame] | 5181 | sdata = vif_to_sdata(vif); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 5182 | |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 5183 | rcu_read_lock(); |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 5184 | chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 5185 | |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 5186 | if (!chanctx_conf) |
Tomas Winkler | 747cf5e | 2008-05-27 17:50:51 +0300 | [diff] [blame] | 5187 | goto out; |
Johannes Berg | 5dfdaf5 | 2007-12-19 02:03:33 +0100 | [diff] [blame] | 5188 | |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 5189 | if (sdata->vif.type == NL80211_IFTYPE_AP) { |
| 5190 | struct beacon_data *beacon = |
| 5191 | rcu_dereference(sdata->u.ap.beacon); |
| 5192 | |
| 5193 | if (!beacon || !beacon->head) |
| 5194 | goto out; |
| 5195 | |
| 5196 | ps = &sdata->u.ap.ps; |
Marco Porsch | 3f52b7e | 2013-01-30 18:14:08 +0100 | [diff] [blame] | 5197 | } else if (ieee80211_vif_is_mesh(&sdata->vif)) { |
| 5198 | ps = &sdata->u.mesh.ps; |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 5199 | } else { |
| 5200 | goto out; |
| 5201 | } |
| 5202 | |
| 5203 | if (ps->dtim_count != 0 || !ps->dtim_bc_mc) |
Tomas Winkler | 747cf5e | 2008-05-27 17:50:51 +0300 | [diff] [blame] | 5204 | goto out; /* send buffered bc/mc only after DTIM beacon */ |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 5205 | |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5206 | while (1) { |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 5207 | skb = skb_dequeue(&ps->bc_buf); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5208 | if (!skb) |
Tomas Winkler | 747cf5e | 2008-05-27 17:50:51 +0300 | [diff] [blame] | 5209 | goto out; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5210 | local->total_ps_buffered--; |
| 5211 | |
Marco Porsch | d012a60 | 2012-10-10 12:39:50 -0700 | [diff] [blame] | 5212 | if (!skb_queue_empty(&ps->bc_buf) && skb->len >= 2) { |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5213 | struct ieee80211_hdr *hdr = |
| 5214 | (struct ieee80211_hdr *) skb->data; |
| 5215 | /* more buffered multicast/broadcast frames ==> set |
| 5216 | * MoreData flag in IEEE 802.11 header to inform PS |
| 5217 | * STAs */ |
| 5218 | hdr->frame_control |= |
| 5219 | cpu_to_le16(IEEE80211_FCTL_MOREDATA); |
| 5220 | } |
| 5221 | |
Michael Braun | 112c44b | 2014-03-06 15:08:43 +0100 | [diff] [blame] | 5222 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
Marco Porsch | 7cbf9d0 | 2013-03-01 16:01:18 +0100 | [diff] [blame] | 5223 | sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev); |
Johannes Berg | 7c10770 | 2015-03-20 14:18:27 +0100 | [diff] [blame] | 5224 | if (!ieee80211_tx_prepare(sdata, &tx, NULL, skb)) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5225 | break; |
Felix Fietkau | 6b07d9c | 2016-08-02 11:13:41 +0200 | [diff] [blame] | 5226 | ieee80211_free_txskb(hw, skb); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5227 | } |
Johannes Berg | e039fa4 | 2008-05-15 12:55:29 +0200 | [diff] [blame] | 5228 | |
| 5229 | info = IEEE80211_SKB_CB(skb); |
| 5230 | |
Johannes Berg | 5cf121c | 2008-02-25 16:27:43 +0100 | [diff] [blame] | 5231 | tx.flags |= IEEE80211_TX_PS_BUFFERED; |
Johannes Berg | 4bf8853 | 2012-11-09 11:39:59 +0100 | [diff] [blame] | 5232 | info->band = chanctx_conf->def.chan->band; |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5233 | |
Johannes Berg | 97b045d | 2008-06-20 01:22:30 +0200 | [diff] [blame] | 5234 | if (invoke_tx_handlers(&tx)) |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5235 | skb = NULL; |
Johannes Berg | 97b045d | 2008-06-20 01:22:30 +0200 | [diff] [blame] | 5236 | out: |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame] | 5237 | rcu_read_unlock(); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5238 | |
| 5239 | return skb; |
| 5240 | } |
| 5241 | EXPORT_SYMBOL(ieee80211_get_buffered_bc); |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 5242 | |
Liad Kaufman | b6da911 | 2014-11-19 13:47:38 +0200 | [diff] [blame] | 5243 | int ieee80211_reserve_tid(struct ieee80211_sta *pubsta, u8 tid) |
| 5244 | { |
| 5245 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
| 5246 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 5247 | struct ieee80211_local *local = sdata->local; |
| 5248 | int ret; |
| 5249 | u32 queues; |
| 5250 | |
| 5251 | lockdep_assert_held(&local->sta_mtx); |
| 5252 | |
| 5253 | /* only some cases are supported right now */ |
| 5254 | switch (sdata->vif.type) { |
| 5255 | case NL80211_IFTYPE_STATION: |
| 5256 | case NL80211_IFTYPE_AP: |
| 5257 | case NL80211_IFTYPE_AP_VLAN: |
| 5258 | break; |
| 5259 | default: |
| 5260 | WARN_ON(1); |
| 5261 | return -EINVAL; |
| 5262 | } |
| 5263 | |
| 5264 | if (WARN_ON(tid >= IEEE80211_NUM_UPS)) |
| 5265 | return -EINVAL; |
| 5266 | |
| 5267 | if (sta->reserved_tid == tid) { |
| 5268 | ret = 0; |
| 5269 | goto out; |
| 5270 | } |
| 5271 | |
| 5272 | if (sta->reserved_tid != IEEE80211_TID_UNRESERVED) { |
| 5273 | sdata_err(sdata, "TID reservation already active\n"); |
| 5274 | ret = -EALREADY; |
| 5275 | goto out; |
| 5276 | } |
| 5277 | |
| 5278 | ieee80211_stop_vif_queues(sdata->local, sdata, |
| 5279 | IEEE80211_QUEUE_STOP_REASON_RESERVE_TID); |
| 5280 | |
| 5281 | synchronize_net(); |
| 5282 | |
| 5283 | /* Tear down BA sessions so we stop aggregating on this TID */ |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5284 | if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION)) { |
Liad Kaufman | b6da911 | 2014-11-19 13:47:38 +0200 | [diff] [blame] | 5285 | set_sta_flag(sta, WLAN_STA_BLOCK_BA); |
| 5286 | __ieee80211_stop_tx_ba_session(sta, tid, |
| 5287 | AGG_STOP_LOCAL_REQUEST); |
| 5288 | } |
| 5289 | |
| 5290 | queues = BIT(sdata->vif.hw_queue[ieee802_1d_to_ac[tid]]); |
Emmanuel Grumbach | 3b24f4c | 2015-01-07 15:42:39 +0200 | [diff] [blame] | 5291 | __ieee80211_flush_queues(local, sdata, queues, false); |
Liad Kaufman | b6da911 | 2014-11-19 13:47:38 +0200 | [diff] [blame] | 5292 | |
| 5293 | sta->reserved_tid = tid; |
| 5294 | |
| 5295 | ieee80211_wake_vif_queues(local, sdata, |
| 5296 | IEEE80211_QUEUE_STOP_REASON_RESERVE_TID); |
| 5297 | |
Johannes Berg | 30686bf | 2015-06-02 21:39:54 +0200 | [diff] [blame] | 5298 | if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION)) |
Liad Kaufman | b6da911 | 2014-11-19 13:47:38 +0200 | [diff] [blame] | 5299 | clear_sta_flag(sta, WLAN_STA_BLOCK_BA); |
| 5300 | |
| 5301 | ret = 0; |
| 5302 | out: |
| 5303 | return ret; |
| 5304 | } |
| 5305 | EXPORT_SYMBOL(ieee80211_reserve_tid); |
| 5306 | |
| 5307 | void ieee80211_unreserve_tid(struct ieee80211_sta *pubsta, u8 tid) |
| 5308 | { |
| 5309 | struct sta_info *sta = container_of(pubsta, struct sta_info, sta); |
| 5310 | struct ieee80211_sub_if_data *sdata = sta->sdata; |
| 5311 | |
| 5312 | lockdep_assert_held(&sdata->local->sta_mtx); |
| 5313 | |
| 5314 | /* only some cases are supported right now */ |
| 5315 | switch (sdata->vif.type) { |
| 5316 | case NL80211_IFTYPE_STATION: |
| 5317 | case NL80211_IFTYPE_AP: |
| 5318 | case NL80211_IFTYPE_AP_VLAN: |
| 5319 | break; |
| 5320 | default: |
| 5321 | WARN_ON(1); |
| 5322 | return; |
| 5323 | } |
| 5324 | |
| 5325 | if (tid != sta->reserved_tid) { |
| 5326 | sdata_err(sdata, "TID to unreserve (%d) isn't reserved\n", tid); |
| 5327 | return; |
| 5328 | } |
| 5329 | |
| 5330 | sta->reserved_tid = IEEE80211_TID_UNRESERVED; |
| 5331 | } |
| 5332 | EXPORT_SYMBOL(ieee80211_unreserve_tid); |
| 5333 | |
Johannes Berg | 55de908 | 2012-07-26 17:24:39 +0200 | [diff] [blame] | 5334 | void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata, |
| 5335 | struct sk_buff *skb, int tid, |
Johannes Berg | b9771d4 | 2018-05-28 15:47:41 +0200 | [diff] [blame] | 5336 | enum nl80211_band band, u32 txdata_flags) |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 5337 | { |
Amadeusz Sławiński | 731977e | 2017-01-24 16:42:10 +0100 | [diff] [blame] | 5338 | int ac = ieee80211_ac_from_tid(tid); |
Johannes Berg | 3a25a8c | 2012-04-03 16:28:50 +0200 | [diff] [blame] | 5339 | |
Zhang Shengju | d57a544 | 2016-03-03 01:16:56 +0000 | [diff] [blame] | 5340 | skb_reset_mac_header(skb); |
Johannes Berg | 3a25a8c | 2012-04-03 16:28:50 +0200 | [diff] [blame] | 5341 | skb_set_queue_mapping(skb, ac); |
Helmut Schaa | cf6bb79 | 2011-12-15 10:18:34 +0100 | [diff] [blame] | 5342 | skb->priority = tid; |
Johannes Berg | cf0277e | 2010-01-05 18:00:58 +0100 | [diff] [blame] | 5343 | |
Johannes Berg | 89afe61 | 2013-02-13 15:39:57 +0100 | [diff] [blame] | 5344 | skb->dev = sdata->dev; |
| 5345 | |
Johannes Berg | 3d34deb | 2009-06-18 17:25:11 +0200 | [diff] [blame] | 5346 | /* |
| 5347 | * The other path calling ieee80211_xmit is from the tasklet, |
| 5348 | * and while we can handle concurrent transmissions locking |
| 5349 | * requirements are that we do not come into tx with bhs on. |
| 5350 | */ |
| 5351 | local_bh_disable(); |
Johannes Berg | 73c4e19 | 2014-11-09 18:50:09 +0200 | [diff] [blame] | 5352 | IEEE80211_SKB_CB(skb)->band = band; |
Johannes Berg | b9771d4 | 2018-05-28 15:47:41 +0200 | [diff] [blame] | 5353 | ieee80211_xmit(sdata, NULL, skb, txdata_flags); |
Johannes Berg | 3d34deb | 2009-06-18 17:25:11 +0200 | [diff] [blame] | 5354 | local_bh_enable(); |
Johannes Berg | 3b8d81e0 | 2009-06-17 17:43:56 +0200 | [diff] [blame] | 5355 | } |
Denis Kenzior | 9118064 | 2018-03-26 12:52:50 -0500 | [diff] [blame] | 5356 | |
| 5357 | int ieee80211_tx_control_port(struct wiphy *wiphy, struct net_device *dev, |
| 5358 | const u8 *buf, size_t len, |
Markus Theil | dca9ca2 | 2020-05-08 16:42:00 +0200 | [diff] [blame] | 5359 | const u8 *dest, __be16 proto, bool unencrypted, |
| 5360 | u64 *cookie) |
Denis Kenzior | 9118064 | 2018-03-26 12:52:50 -0500 | [diff] [blame] | 5361 | { |
| 5362 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 5363 | struct ieee80211_local *local = sdata->local; |
| 5364 | struct sk_buff *skb; |
| 5365 | struct ethhdr *ehdr; |
Johannes Berg | b95d2cc | 2020-03-26 15:53:34 +0100 | [diff] [blame] | 5366 | u32 ctrl_flags = 0; |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 5367 | u32 flags = 0; |
Denis Kenzior | 9118064 | 2018-03-26 12:52:50 -0500 | [diff] [blame] | 5368 | |
| 5369 | /* Only accept CONTROL_PORT_PROTOCOL configured in CONNECT/ASSOCIATE |
| 5370 | * or Pre-Authentication |
| 5371 | */ |
| 5372 | if (proto != sdata->control_port_protocol && |
| 5373 | proto != cpu_to_be16(ETH_P_PREAUTH)) |
| 5374 | return -EINVAL; |
| 5375 | |
Johannes Berg | b95d2cc | 2020-03-26 15:53:34 +0100 | [diff] [blame] | 5376 | if (proto == sdata->control_port_protocol) |
Markus Theil | 5af7fef | 2020-06-17 10:26:36 +0200 | [diff] [blame] | 5377 | ctrl_flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO | |
| 5378 | IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP; |
Johannes Berg | b95d2cc | 2020-03-26 15:53:34 +0100 | [diff] [blame] | 5379 | |
Denis Kenzior | 9118064 | 2018-03-26 12:52:50 -0500 | [diff] [blame] | 5380 | if (unencrypted) |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 5381 | flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; |
| 5382 | |
| 5383 | if (cookie) |
| 5384 | ctrl_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS; |
| 5385 | |
| 5386 | flags |= IEEE80211_TX_INTFL_NL80211_FRAME_TX | |
| 5387 | IEEE80211_TX_CTL_INJECTED; |
Denis Kenzior | 9118064 | 2018-03-26 12:52:50 -0500 | [diff] [blame] | 5388 | |
| 5389 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + |
| 5390 | sizeof(struct ethhdr) + len); |
| 5391 | if (!skb) |
| 5392 | return -ENOMEM; |
| 5393 | |
| 5394 | skb_reserve(skb, local->hw.extra_tx_headroom + sizeof(struct ethhdr)); |
| 5395 | |
| 5396 | skb_put_data(skb, buf, len); |
| 5397 | |
| 5398 | ehdr = skb_push(skb, sizeof(struct ethhdr)); |
| 5399 | memcpy(ehdr->h_dest, dest, ETH_ALEN); |
Johannes Berg | 8079e4f | 2020-02-24 10:19:11 +0100 | [diff] [blame] | 5400 | memcpy(ehdr->h_source, sdata->vif.addr, ETH_ALEN); |
Denis Kenzior | 9118064 | 2018-03-26 12:52:50 -0500 | [diff] [blame] | 5401 | ehdr->h_proto = proto; |
| 5402 | |
| 5403 | skb->dev = dev; |
| 5404 | skb->protocol = htons(ETH_P_802_3); |
| 5405 | skb_reset_network_header(skb); |
| 5406 | skb_reset_mac_header(skb); |
| 5407 | |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 5408 | /* mutex lock is only needed for incrementing the cookie counter */ |
| 5409 | mutex_lock(&local->mtx); |
| 5410 | |
Denis Kenzior | e7441c9 | 2018-06-19 10:39:50 -0500 | [diff] [blame] | 5411 | local_bh_disable(); |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 5412 | __ieee80211_subif_start_xmit(skb, skb->dev, flags, ctrl_flags, cookie); |
Denis Kenzior | e7441c9 | 2018-06-19 10:39:50 -0500 | [diff] [blame] | 5413 | local_bh_enable(); |
Denis Kenzior | 9118064 | 2018-03-26 12:52:50 -0500 | [diff] [blame] | 5414 | |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 5415 | mutex_unlock(&local->mtx); |
| 5416 | |
Denis Kenzior | 9118064 | 2018-03-26 12:52:50 -0500 | [diff] [blame] | 5417 | return 0; |
| 5418 | } |
Rajkumar Manoharan | 8828f81 | 2019-04-11 13:47:26 -0700 | [diff] [blame] | 5419 | |
| 5420 | int ieee80211_probe_mesh_link(struct wiphy *wiphy, struct net_device *dev, |
| 5421 | const u8 *buf, size_t len) |
| 5422 | { |
| 5423 | struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev); |
| 5424 | struct ieee80211_local *local = sdata->local; |
| 5425 | struct sk_buff *skb; |
| 5426 | |
| 5427 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + len + |
| 5428 | 30 + /* header size */ |
| 5429 | 18); /* 11s header size */ |
| 5430 | if (!skb) |
| 5431 | return -ENOMEM; |
| 5432 | |
| 5433 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 5434 | skb_put_data(skb, buf, len); |
| 5435 | |
| 5436 | skb->dev = dev; |
| 5437 | skb->protocol = htons(ETH_P_802_3); |
| 5438 | skb_reset_network_header(skb); |
| 5439 | skb_reset_mac_header(skb); |
| 5440 | |
| 5441 | local_bh_disable(); |
| 5442 | __ieee80211_subif_start_xmit(skb, skb->dev, 0, |
Markus Theil | a752819 | 2020-05-27 18:03:34 +0200 | [diff] [blame] | 5443 | IEEE80211_TX_CTRL_SKIP_MPATH_LOOKUP, |
| 5444 | NULL); |
Johannes Berg | e2ebc74 | 2007-07-27 15:43:22 +0200 | [diff] [blame] | 5445 | local_bh_enable(); |
| 5446 | |
| 5447 | return 0; |
| 5448 | } |