1c2d1560aSJohannes Berg /* 2c2d1560aSJohannes Berg * Copyright 2002-2005, Instant802 Networks, Inc. 3c2d1560aSJohannes Berg * Copyright 2005-2006, Devicescape Software, Inc. 4c2d1560aSJohannes Berg * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> 5c2d1560aSJohannes Berg * Copyright 2007 Johannes Berg <johannes@sipsolutions.net> 6d98ad83eSJohannes Berg * Copyright 2013-2014 Intel Mobile Communications GmbH 7f4a0f0c5SJohannes Berg * Copyright (C) 2015-2016 Intel Deutschland GmbH 8c2d1560aSJohannes Berg * 9c2d1560aSJohannes Berg * This program is free software; you can redistribute it and/or modify 10c2d1560aSJohannes Berg * it under the terms of the GNU General Public License version 2 as 11c2d1560aSJohannes Berg * published by the Free Software Foundation. 12c2d1560aSJohannes Berg * 13c2d1560aSJohannes Berg * utilities for mac80211 14c2d1560aSJohannes Berg */ 15c2d1560aSJohannes Berg 16c2d1560aSJohannes Berg #include <net/mac80211.h> 17c2d1560aSJohannes Berg #include <linux/netdevice.h> 18bc3b2d7fSPaul Gortmaker #include <linux/export.h> 19c2d1560aSJohannes Berg #include <linux/types.h> 20c2d1560aSJohannes Berg #include <linux/slab.h> 21c2d1560aSJohannes Berg #include <linux/skbuff.h> 22c2d1560aSJohannes Berg #include <linux/etherdevice.h> 23c2d1560aSJohannes Berg #include <linux/if_arp.h> 24c2d1560aSJohannes Berg #include <linux/bitmap.h> 25dd76986bSJohannes Berg #include <linux/crc32.h> 26881d966bSEric W. Biederman #include <net/net_namespace.h> 27c2d1560aSJohannes Berg #include <net/cfg80211.h> 28dabeb344SJohannes Berg #include <net/rtnetlink.h> 29c2d1560aSJohannes Berg 30c2d1560aSJohannes Berg #include "ieee80211_i.h" 3124487981SJohannes Berg #include "driver-ops.h" 322c8dccc7SJohannes Berg #include "rate.h" 33ee385855SLuis Carlos Cobo #include "mesh.h" 34c2d1560aSJohannes Berg #include "wme.h" 35f2753ddbSJohannes Berg #include "led.h" 36fffd0934SJohannes Berg #include "wep.h" 37c2d1560aSJohannes Berg 38c2d1560aSJohannes Berg /* privid for wiphys to determine whether they belong to us or not */ 398a47cea7SJohannes Berg const void *const mac80211_wiphy_privid = &mac80211_wiphy_privid; 40c2d1560aSJohannes Berg 419a95371aSLuis R. Rodriguez struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy) 429a95371aSLuis R. Rodriguez { 439a95371aSLuis R. Rodriguez struct ieee80211_local *local; 449a95371aSLuis R. Rodriguez BUG_ON(!wiphy); 459a95371aSLuis R. Rodriguez 469a95371aSLuis R. Rodriguez local = wiphy_priv(wiphy); 479a95371aSLuis R. Rodriguez return &local->hw; 489a95371aSLuis R. Rodriguez } 499a95371aSLuis R. Rodriguez EXPORT_SYMBOL(wiphy_to_ieee80211_hw); 50c2d1560aSJohannes Berg 515cf121c3SJohannes Berg void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx) 52c2d1560aSJohannes Berg { 53252b86c4SJohannes Berg struct sk_buff *skb; 542de8e0d9SJohannes Berg struct ieee80211_hdr *hdr; 55c2d1560aSJohannes Berg 56252b86c4SJohannes Berg skb_queue_walk(&tx->skbs, skb) { 572de8e0d9SJohannes Berg hdr = (struct ieee80211_hdr *) skb->data; 58c2d1560aSJohannes Berg hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); 59252b86c4SJohannes Berg } 60c2d1560aSJohannes Berg } 61c2d1560aSJohannes Berg 6257fbcce3SJohannes Berg int ieee80211_frame_duration(enum nl80211_band band, size_t len, 63438b61b7SSimon Wunderlich int rate, int erp, int short_preamble, 64438b61b7SSimon Wunderlich int shift) 65c2d1560aSJohannes Berg { 66c2d1560aSJohannes Berg int dur; 67c2d1560aSJohannes Berg 68c2d1560aSJohannes Berg /* calculate duration (in microseconds, rounded up to next higher 69c2d1560aSJohannes Berg * integer if it includes a fractional microsecond) to send frame of 70c2d1560aSJohannes Berg * len bytes (does not include FCS) at the given rate. Duration will 71c2d1560aSJohannes Berg * also include SIFS. 72c2d1560aSJohannes Berg * 73c2d1560aSJohannes Berg * rate is in 100 kbps, so divident is multiplied by 10 in the 74c2d1560aSJohannes Berg * DIV_ROUND_UP() operations. 75438b61b7SSimon Wunderlich * 76438b61b7SSimon Wunderlich * shift may be 2 for 5 MHz channels or 1 for 10 MHz channels, and 77438b61b7SSimon Wunderlich * is assumed to be 0 otherwise. 78c2d1560aSJohannes Berg */ 79c2d1560aSJohannes Berg 8057fbcce3SJohannes Berg if (band == NL80211_BAND_5GHZ || erp) { 81c2d1560aSJohannes Berg /* 82c2d1560aSJohannes Berg * OFDM: 83c2d1560aSJohannes Berg * 84c2d1560aSJohannes Berg * N_DBPS = DATARATE x 4 85c2d1560aSJohannes Berg * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS) 86c2d1560aSJohannes Berg * (16 = SIGNAL time, 6 = tail bits) 87c2d1560aSJohannes Berg * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext 88c2d1560aSJohannes Berg * 89c2d1560aSJohannes Berg * T_SYM = 4 usec 90438b61b7SSimon Wunderlich * 802.11a - 18.5.2: aSIFSTime = 16 usec 91c2d1560aSJohannes Berg * 802.11g - 19.8.4: aSIFSTime = 10 usec + 92c2d1560aSJohannes Berg * signal ext = 6 usec 93c2d1560aSJohannes Berg */ 94c2d1560aSJohannes Berg dur = 16; /* SIFS + signal ext */ 95438b61b7SSimon Wunderlich dur += 16; /* IEEE 802.11-2012 18.3.2.4: T_PREAMBLE = 16 usec */ 96438b61b7SSimon Wunderlich dur += 4; /* IEEE 802.11-2012 18.3.2.4: T_SIGNAL = 4 usec */ 97438b61b7SSimon Wunderlich 98438b61b7SSimon Wunderlich /* IEEE 802.11-2012 18.3.2.4: all values above are: 99438b61b7SSimon Wunderlich * * times 4 for 5 MHz 100438b61b7SSimon Wunderlich * * times 2 for 10 MHz 101438b61b7SSimon Wunderlich */ 102438b61b7SSimon Wunderlich dur *= 1 << shift; 1032103dec1SSimon Wunderlich 1042103dec1SSimon Wunderlich /* rates should already consider the channel bandwidth, 1052103dec1SSimon Wunderlich * don't apply divisor again. 1062103dec1SSimon Wunderlich */ 1072103dec1SSimon Wunderlich dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10, 1082103dec1SSimon Wunderlich 4 * rate); /* T_SYM x N_SYM */ 109c2d1560aSJohannes Berg } else { 110c2d1560aSJohannes Berg /* 111c2d1560aSJohannes Berg * 802.11b or 802.11g with 802.11b compatibility: 112c2d1560aSJohannes Berg * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime + 113c2d1560aSJohannes Berg * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0. 114c2d1560aSJohannes Berg * 115c2d1560aSJohannes Berg * 802.11 (DS): 15.3.3, 802.11b: 18.3.4 116c2d1560aSJohannes Berg * aSIFSTime = 10 usec 117c2d1560aSJohannes Berg * aPreambleLength = 144 usec or 72 usec with short preamble 118c2d1560aSJohannes Berg * aPLCPHeaderLength = 48 usec or 24 usec with short preamble 119c2d1560aSJohannes Berg */ 120c2d1560aSJohannes Berg dur = 10; /* aSIFSTime = 10 usec */ 121c2d1560aSJohannes Berg dur += short_preamble ? (72 + 24) : (144 + 48); 122c2d1560aSJohannes Berg 123c2d1560aSJohannes Berg dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate); 124c2d1560aSJohannes Berg } 125c2d1560aSJohannes Berg 126c2d1560aSJohannes Berg return dur; 127c2d1560aSJohannes Berg } 128c2d1560aSJohannes Berg 129c2d1560aSJohannes Berg /* Exported duration function for driver use */ 13032bfd35dSJohannes Berg __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw, 13132bfd35dSJohannes Berg struct ieee80211_vif *vif, 13257fbcce3SJohannes Berg enum nl80211_band band, 1338318d78aSJohannes Berg size_t frame_len, 1348318d78aSJohannes Berg struct ieee80211_rate *rate) 135c2d1560aSJohannes Berg { 13625d834e1SJohannes Berg struct ieee80211_sub_if_data *sdata; 137c2d1560aSJohannes Berg u16 dur; 138438b61b7SSimon Wunderlich int erp, shift = 0; 13925d834e1SJohannes Berg bool short_preamble = false; 140c2d1560aSJohannes Berg 1418318d78aSJohannes Berg erp = 0; 14225d834e1SJohannes Berg if (vif) { 14325d834e1SJohannes Berg sdata = vif_to_sdata(vif); 144bda3933aSJohannes Berg short_preamble = sdata->vif.bss_conf.use_short_preamble; 1458318d78aSJohannes Berg if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) 1468318d78aSJohannes Berg erp = rate->flags & IEEE80211_RATE_ERP_G; 147438b61b7SSimon Wunderlich shift = ieee80211_vif_get_shift(vif); 14825d834e1SJohannes Berg } 1498318d78aSJohannes Berg 1504ee73f33SMichal Kazior dur = ieee80211_frame_duration(band, frame_len, rate->bitrate, erp, 151438b61b7SSimon Wunderlich short_preamble, shift); 152c2d1560aSJohannes Berg 153c2d1560aSJohannes Berg return cpu_to_le16(dur); 154c2d1560aSJohannes Berg } 155c2d1560aSJohannes Berg EXPORT_SYMBOL(ieee80211_generic_frame_duration); 156c2d1560aSJohannes Berg 15732bfd35dSJohannes Berg __le16 ieee80211_rts_duration(struct ieee80211_hw *hw, 15832bfd35dSJohannes Berg struct ieee80211_vif *vif, size_t frame_len, 159e039fa4aSJohannes Berg const struct ieee80211_tx_info *frame_txctl) 160c2d1560aSJohannes Berg { 161c2d1560aSJohannes Berg struct ieee80211_local *local = hw_to_local(hw); 162c2d1560aSJohannes Berg struct ieee80211_rate *rate; 16325d834e1SJohannes Berg struct ieee80211_sub_if_data *sdata; 164471b3efdSJohannes Berg bool short_preamble; 1652103dec1SSimon Wunderlich int erp, shift = 0, bitrate; 166c2d1560aSJohannes Berg u16 dur; 1672e92e6f2SJohannes Berg struct ieee80211_supported_band *sband; 1682e92e6f2SJohannes Berg 1694ee73f33SMichal Kazior sband = local->hw.wiphy->bands[frame_txctl->band]; 170c2d1560aSJohannes Berg 17125d834e1SJohannes Berg short_preamble = false; 1727e9ed188SDaniel Drake 173e039fa4aSJohannes Berg rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; 1748318d78aSJohannes Berg 1758318d78aSJohannes Berg erp = 0; 17625d834e1SJohannes Berg if (vif) { 17725d834e1SJohannes Berg sdata = vif_to_sdata(vif); 178bda3933aSJohannes Berg short_preamble = sdata->vif.bss_conf.use_short_preamble; 1798318d78aSJohannes Berg if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) 1808318d78aSJohannes Berg erp = rate->flags & IEEE80211_RATE_ERP_G; 181438b61b7SSimon Wunderlich shift = ieee80211_vif_get_shift(vif); 18225d834e1SJohannes Berg } 183c2d1560aSJohannes Berg 1842103dec1SSimon Wunderlich bitrate = DIV_ROUND_UP(rate->bitrate, 1 << shift); 1852103dec1SSimon Wunderlich 186c2d1560aSJohannes Berg /* CTS duration */ 1872103dec1SSimon Wunderlich dur = ieee80211_frame_duration(sband->band, 10, bitrate, 188438b61b7SSimon Wunderlich erp, short_preamble, shift); 189c2d1560aSJohannes Berg /* Data frame duration */ 1902103dec1SSimon Wunderlich dur += ieee80211_frame_duration(sband->band, frame_len, bitrate, 191438b61b7SSimon Wunderlich erp, short_preamble, shift); 192c2d1560aSJohannes Berg /* ACK duration */ 1932103dec1SSimon Wunderlich dur += ieee80211_frame_duration(sband->band, 10, bitrate, 194438b61b7SSimon Wunderlich erp, short_preamble, shift); 195c2d1560aSJohannes Berg 196c2d1560aSJohannes Berg return cpu_to_le16(dur); 197c2d1560aSJohannes Berg } 198c2d1560aSJohannes Berg EXPORT_SYMBOL(ieee80211_rts_duration); 199c2d1560aSJohannes Berg 20032bfd35dSJohannes Berg __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw, 20132bfd35dSJohannes Berg struct ieee80211_vif *vif, 202c2d1560aSJohannes Berg size_t frame_len, 203e039fa4aSJohannes Berg const struct ieee80211_tx_info *frame_txctl) 204c2d1560aSJohannes Berg { 205c2d1560aSJohannes Berg struct ieee80211_local *local = hw_to_local(hw); 206c2d1560aSJohannes Berg struct ieee80211_rate *rate; 20725d834e1SJohannes Berg struct ieee80211_sub_if_data *sdata; 208471b3efdSJohannes Berg bool short_preamble; 2092103dec1SSimon Wunderlich int erp, shift = 0, bitrate; 210c2d1560aSJohannes Berg u16 dur; 2112e92e6f2SJohannes Berg struct ieee80211_supported_band *sband; 2122e92e6f2SJohannes Berg 2134ee73f33SMichal Kazior sband = local->hw.wiphy->bands[frame_txctl->band]; 214c2d1560aSJohannes Berg 21525d834e1SJohannes Berg short_preamble = false; 2167e9ed188SDaniel Drake 217e039fa4aSJohannes Berg rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx]; 2188318d78aSJohannes Berg erp = 0; 21925d834e1SJohannes Berg if (vif) { 22025d834e1SJohannes Berg sdata = vif_to_sdata(vif); 221bda3933aSJohannes Berg short_preamble = sdata->vif.bss_conf.use_short_preamble; 2228318d78aSJohannes Berg if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE) 2238318d78aSJohannes Berg erp = rate->flags & IEEE80211_RATE_ERP_G; 224438b61b7SSimon Wunderlich shift = ieee80211_vif_get_shift(vif); 22525d834e1SJohannes Berg } 226c2d1560aSJohannes Berg 2272103dec1SSimon Wunderlich bitrate = DIV_ROUND_UP(rate->bitrate, 1 << shift); 2282103dec1SSimon Wunderlich 229c2d1560aSJohannes Berg /* Data frame duration */ 2302103dec1SSimon Wunderlich dur = ieee80211_frame_duration(sband->band, frame_len, bitrate, 231438b61b7SSimon Wunderlich erp, short_preamble, shift); 232e039fa4aSJohannes Berg if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) { 233c2d1560aSJohannes Berg /* ACK duration */ 2342103dec1SSimon Wunderlich dur += ieee80211_frame_duration(sband->band, 10, bitrate, 235438b61b7SSimon Wunderlich erp, short_preamble, shift); 236c2d1560aSJohannes Berg } 237c2d1560aSJohannes Berg 238c2d1560aSJohannes Berg return cpu_to_le16(dur); 239c2d1560aSJohannes Berg } 240c2d1560aSJohannes Berg EXPORT_SYMBOL(ieee80211_ctstoself_duration); 241c2d1560aSJohannes Berg 2423a25a8c8SJohannes Berg void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue) 2433a25a8c8SJohannes Berg { 2443a25a8c8SJohannes Berg struct ieee80211_sub_if_data *sdata; 245a6f38ac3SJohannes Berg int n_acs = IEEE80211_NUM_ACS; 246a6f38ac3SJohannes Berg 24780a83cfcSMichal Kazior if (local->ops->wake_tx_queue) 24880a83cfcSMichal Kazior return; 24980a83cfcSMichal Kazior 250a6f38ac3SJohannes Berg if (local->hw.queues < IEEE80211_NUM_ACS) 251a6f38ac3SJohannes Berg n_acs = 1; 2523a25a8c8SJohannes Berg 2533a25a8c8SJohannes Berg list_for_each_entry_rcu(sdata, &local->interfaces, list) { 2543a25a8c8SJohannes Berg int ac; 2553a25a8c8SJohannes Berg 256f142c6b9SJohannes Berg if (!sdata->dev) 257f142c6b9SJohannes Berg continue; 258f142c6b9SJohannes Berg 2593a25a8c8SJohannes Berg if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE && 2603a25a8c8SJohannes Berg local->queue_stop_reasons[sdata->vif.cab_queue] != 0) 2613a25a8c8SJohannes Berg continue; 2623a25a8c8SJohannes Berg 263a6f38ac3SJohannes Berg for (ac = 0; ac < n_acs; ac++) { 2643a25a8c8SJohannes Berg int ac_queue = sdata->vif.hw_queue[ac]; 2653a25a8c8SJohannes Berg 2663a25a8c8SJohannes Berg if (ac_queue == queue || 2673a25a8c8SJohannes Berg (sdata->vif.cab_queue == queue && 2683a25a8c8SJohannes Berg local->queue_stop_reasons[ac_queue] == 0 && 2693a25a8c8SJohannes Berg skb_queue_empty(&local->pending[ac_queue]))) 2703a25a8c8SJohannes Berg netif_wake_subqueue(sdata->dev, ac); 2713a25a8c8SJohannes Berg } 2723a25a8c8SJohannes Berg } 2733a25a8c8SJohannes Berg } 2743a25a8c8SJohannes Berg 275ce7c9111SKalle Valo static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue, 276cca07b00SLuciano Coelho enum queue_stop_reason reason, 277cca07b00SLuciano Coelho bool refcounted) 278c2d1560aSJohannes Berg { 279c2d1560aSJohannes Berg struct ieee80211_local *local = hw_to_local(hw); 280c2d1560aSJohannes Berg 281b5878a2dSJohannes Berg trace_wake_queue(local, queue, reason); 282b5878a2dSJohannes Berg 283e4e72fb4SJohannes Berg if (WARN_ON(queue >= hw->queues)) 28496f5e66eSJohannes Berg return; 28596f5e66eSJohannes Berg 286ada15125SJohannes Berg if (!test_bit(reason, &local->queue_stop_reasons[queue])) 287ada15125SJohannes Berg return; 288ada15125SJohannes Berg 289856142cdSJohannes Berg if (!refcounted) { 290cca07b00SLuciano Coelho local->q_stop_reasons[queue][reason] = 0; 291856142cdSJohannes Berg } else { 292cca07b00SLuciano Coelho local->q_stop_reasons[queue][reason]--; 293856142cdSJohannes Berg if (WARN_ON(local->q_stop_reasons[queue][reason] < 0)) 294856142cdSJohannes Berg local->q_stop_reasons[queue][reason] = 0; 295856142cdSJohannes Berg } 296cca07b00SLuciano Coelho 297cca07b00SLuciano Coelho if (local->q_stop_reasons[queue][reason] == 0) 298ce7c9111SKalle Valo __clear_bit(reason, &local->queue_stop_reasons[queue]); 299ce7c9111SKalle Valo 300ce7c9111SKalle Valo if (local->queue_stop_reasons[queue] != 0) 301ce7c9111SKalle Valo /* someone still has this queue stopped */ 302ce7c9111SKalle Valo return; 303ce7c9111SKalle Valo 3047236fe29SJohannes Berg if (skb_queue_empty(&local->pending[queue])) { 305cf0277e7SJohannes Berg rcu_read_lock(); 3063a25a8c8SJohannes Berg ieee80211_propagate_queue_wake(local, queue); 307cf0277e7SJohannes Berg rcu_read_unlock(); 3087236fe29SJohannes Berg } else 3097236fe29SJohannes Berg tasklet_schedule(&local->tx_pending_tasklet); 310c2d1560aSJohannes Berg } 311ce7c9111SKalle Valo 31296f5e66eSJohannes Berg void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue, 313cca07b00SLuciano Coelho enum queue_stop_reason reason, 314cca07b00SLuciano Coelho bool refcounted) 315ce7c9111SKalle Valo { 316ce7c9111SKalle Valo struct ieee80211_local *local = hw_to_local(hw); 317ce7c9111SKalle Valo unsigned long flags; 318ce7c9111SKalle Valo 319ce7c9111SKalle Valo spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 320cca07b00SLuciano Coelho __ieee80211_wake_queue(hw, queue, reason, refcounted); 321ce7c9111SKalle Valo spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 322ce7c9111SKalle Valo } 323ce7c9111SKalle Valo 324ce7c9111SKalle Valo void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue) 325ce7c9111SKalle Valo { 326ce7c9111SKalle Valo ieee80211_wake_queue_by_reason(hw, queue, 327cca07b00SLuciano Coelho IEEE80211_QUEUE_STOP_REASON_DRIVER, 328cca07b00SLuciano Coelho false); 329ce7c9111SKalle Valo } 330c2d1560aSJohannes Berg EXPORT_SYMBOL(ieee80211_wake_queue); 331c2d1560aSJohannes Berg 332ce7c9111SKalle Valo static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue, 333cca07b00SLuciano Coelho enum queue_stop_reason reason, 334cca07b00SLuciano Coelho bool refcounted) 335c2d1560aSJohannes Berg { 336c2d1560aSJohannes Berg struct ieee80211_local *local = hw_to_local(hw); 337cf0277e7SJohannes Berg struct ieee80211_sub_if_data *sdata; 338a6f38ac3SJohannes Berg int n_acs = IEEE80211_NUM_ACS; 339c2d1560aSJohannes Berg 340b5878a2dSJohannes Berg trace_stop_queue(local, queue, reason); 341b5878a2dSJohannes Berg 342e4e72fb4SJohannes Berg if (WARN_ON(queue >= hw->queues)) 34396f5e66eSJohannes Berg return; 34496f5e66eSJohannes Berg 345cca07b00SLuciano Coelho if (!refcounted) 346cca07b00SLuciano Coelho local->q_stop_reasons[queue][reason] = 1; 347cca07b00SLuciano Coelho else 348cca07b00SLuciano Coelho local->q_stop_reasons[queue][reason]++; 349ada15125SJohannes Berg 350cca07b00SLuciano Coelho if (__test_and_set_bit(reason, &local->queue_stop_reasons[queue])) 351cca07b00SLuciano Coelho return; 352cf0277e7SJohannes Berg 35380a83cfcSMichal Kazior if (local->ops->wake_tx_queue) 35480a83cfcSMichal Kazior return; 35580a83cfcSMichal Kazior 356a6f38ac3SJohannes Berg if (local->hw.queues < IEEE80211_NUM_ACS) 357a6f38ac3SJohannes Berg n_acs = 1; 358a6f38ac3SJohannes Berg 359cf0277e7SJohannes Berg rcu_read_lock(); 3603a25a8c8SJohannes Berg list_for_each_entry_rcu(sdata, &local->interfaces, list) { 3613a25a8c8SJohannes Berg int ac; 3623a25a8c8SJohannes Berg 363f142c6b9SJohannes Berg if (!sdata->dev) 364f142c6b9SJohannes Berg continue; 365f142c6b9SJohannes Berg 366a6f38ac3SJohannes Berg for (ac = 0; ac < n_acs; ac++) { 3673a25a8c8SJohannes Berg if (sdata->vif.hw_queue[ac] == queue || 3683a25a8c8SJohannes Berg sdata->vif.cab_queue == queue) 3693a25a8c8SJohannes Berg netif_stop_subqueue(sdata->dev, ac); 3703a25a8c8SJohannes Berg } 3713a25a8c8SJohannes Berg } 372cf0277e7SJohannes Berg rcu_read_unlock(); 373c2d1560aSJohannes Berg } 374ce7c9111SKalle Valo 37596f5e66eSJohannes Berg void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue, 376cca07b00SLuciano Coelho enum queue_stop_reason reason, 377cca07b00SLuciano Coelho bool refcounted) 378ce7c9111SKalle Valo { 379ce7c9111SKalle Valo struct ieee80211_local *local = hw_to_local(hw); 380ce7c9111SKalle Valo unsigned long flags; 381ce7c9111SKalle Valo 382ce7c9111SKalle Valo spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 383cca07b00SLuciano Coelho __ieee80211_stop_queue(hw, queue, reason, refcounted); 384ce7c9111SKalle Valo spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 385ce7c9111SKalle Valo } 386ce7c9111SKalle Valo 387ce7c9111SKalle Valo void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue) 388ce7c9111SKalle Valo { 389ce7c9111SKalle Valo ieee80211_stop_queue_by_reason(hw, queue, 390cca07b00SLuciano Coelho IEEE80211_QUEUE_STOP_REASON_DRIVER, 391cca07b00SLuciano Coelho false); 392ce7c9111SKalle Valo } 393c2d1560aSJohannes Berg EXPORT_SYMBOL(ieee80211_stop_queue); 394c2d1560aSJohannes Berg 3958f77f384SJohannes Berg void ieee80211_add_pending_skb(struct ieee80211_local *local, 3968f77f384SJohannes Berg struct sk_buff *skb) 3978f77f384SJohannes Berg { 3988f77f384SJohannes Berg struct ieee80211_hw *hw = &local->hw; 3998f77f384SJohannes Berg unsigned long flags; 400a7bc376cSJohannes Berg struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 4013a25a8c8SJohannes Berg int queue = info->hw_queue; 402a7bc376cSJohannes Berg 403a7bc376cSJohannes Berg if (WARN_ON(!info->control.vif)) { 404d4fa14cdSFelix Fietkau ieee80211_free_txskb(&local->hw, skb); 405a7bc376cSJohannes Berg return; 406a7bc376cSJohannes Berg } 4078f77f384SJohannes Berg 4088f77f384SJohannes Berg spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 409cca07b00SLuciano Coelho __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD, 410cca07b00SLuciano Coelho false); 4113b8d81e0SJohannes Berg __skb_queue_tail(&local->pending[queue], skb); 412cca07b00SLuciano Coelho __ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD, 413cca07b00SLuciano Coelho false); 4148f77f384SJohannes Berg spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 4158f77f384SJohannes Berg } 4168f77f384SJohannes Berg 417e3685e03SJohannes Berg void ieee80211_add_pending_skbs(struct ieee80211_local *local, 418e3685e03SJohannes Berg struct sk_buff_head *skbs) 4198f77f384SJohannes Berg { 4208f77f384SJohannes Berg struct ieee80211_hw *hw = &local->hw; 4218f77f384SJohannes Berg struct sk_buff *skb; 4228f77f384SJohannes Berg unsigned long flags; 423b0b97a8aSJohannes Berg int queue, i; 4248f77f384SJohannes Berg 4258f77f384SJohannes Berg spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 4268f77f384SJohannes Berg while ((skb = skb_dequeue(skbs))) { 427a7bc376cSJohannes Berg struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 428a7bc376cSJohannes Berg 429a7bc376cSJohannes Berg if (WARN_ON(!info->control.vif)) { 430d4fa14cdSFelix Fietkau ieee80211_free_txskb(&local->hw, skb); 431a7bc376cSJohannes Berg continue; 432a7bc376cSJohannes Berg } 433a7bc376cSJohannes Berg 4343a25a8c8SJohannes Berg queue = info->hw_queue; 4354644ae89SJohannes Berg 4364644ae89SJohannes Berg __ieee80211_stop_queue(hw, queue, 437cca07b00SLuciano Coelho IEEE80211_QUEUE_STOP_REASON_SKB_ADD, 438cca07b00SLuciano Coelho false); 4394644ae89SJohannes Berg 4403b8d81e0SJohannes Berg __skb_queue_tail(&local->pending[queue], skb); 4418f77f384SJohannes Berg } 4428f77f384SJohannes Berg 4433b8d81e0SJohannes Berg for (i = 0; i < hw->queues; i++) 4448f77f384SJohannes Berg __ieee80211_wake_queue(hw, i, 445cca07b00SLuciano Coelho IEEE80211_QUEUE_STOP_REASON_SKB_ADD, 446cca07b00SLuciano Coelho false); 4478f77f384SJohannes Berg spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 4488f77f384SJohannes Berg } 4498f77f384SJohannes Berg 450ce7c9111SKalle Valo void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw, 451445ea4e8SJohannes Berg unsigned long queues, 452cca07b00SLuciano Coelho enum queue_stop_reason reason, 453cca07b00SLuciano Coelho bool refcounted) 454c2d1560aSJohannes Berg { 455ce7c9111SKalle Valo struct ieee80211_local *local = hw_to_local(hw); 456ce7c9111SKalle Valo unsigned long flags; 457c2d1560aSJohannes Berg int i; 458c2d1560aSJohannes Berg 459ce7c9111SKalle Valo spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 460ce7c9111SKalle Valo 461445ea4e8SJohannes Berg for_each_set_bit(i, &queues, hw->queues) 462cca07b00SLuciano Coelho __ieee80211_stop_queue(hw, i, reason, refcounted); 463ce7c9111SKalle Valo 464ce7c9111SKalle Valo spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 465ce7c9111SKalle Valo } 466ce7c9111SKalle Valo 467ce7c9111SKalle Valo void ieee80211_stop_queues(struct ieee80211_hw *hw) 468ce7c9111SKalle Valo { 469445ea4e8SJohannes Berg ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP, 470cca07b00SLuciano Coelho IEEE80211_QUEUE_STOP_REASON_DRIVER, 471cca07b00SLuciano Coelho false); 472c2d1560aSJohannes Berg } 473c2d1560aSJohannes Berg EXPORT_SYMBOL(ieee80211_stop_queues); 474c2d1560aSJohannes Berg 47592ab8535STomas Winkler int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue) 47692ab8535STomas Winkler { 47792ab8535STomas Winkler struct ieee80211_local *local = hw_to_local(hw); 4783b8d81e0SJohannes Berg unsigned long flags; 4793b8d81e0SJohannes Berg int ret; 48096f5e66eSJohannes Berg 481e4e72fb4SJohannes Berg if (WARN_ON(queue >= hw->queues)) 48296f5e66eSJohannes Berg return true; 48396f5e66eSJohannes Berg 4843b8d81e0SJohannes Berg spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 4852419ea14SThomas Pedersen ret = test_bit(IEEE80211_QUEUE_STOP_REASON_DRIVER, 4862419ea14SThomas Pedersen &local->queue_stop_reasons[queue]); 4873b8d81e0SJohannes Berg spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 4883b8d81e0SJohannes Berg return ret; 48992ab8535STomas Winkler } 49092ab8535STomas Winkler EXPORT_SYMBOL(ieee80211_queue_stopped); 49192ab8535STomas Winkler 492ce7c9111SKalle Valo void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw, 493445ea4e8SJohannes Berg unsigned long queues, 494cca07b00SLuciano Coelho enum queue_stop_reason reason, 495cca07b00SLuciano Coelho bool refcounted) 496c2d1560aSJohannes Berg { 497ce7c9111SKalle Valo struct ieee80211_local *local = hw_to_local(hw); 498ce7c9111SKalle Valo unsigned long flags; 499c2d1560aSJohannes Berg int i; 500c2d1560aSJohannes Berg 501ce7c9111SKalle Valo spin_lock_irqsave(&local->queue_stop_reason_lock, flags); 502ce7c9111SKalle Valo 503445ea4e8SJohannes Berg for_each_set_bit(i, &queues, hw->queues) 504cca07b00SLuciano Coelho __ieee80211_wake_queue(hw, i, reason, refcounted); 505ce7c9111SKalle Valo 506ce7c9111SKalle Valo spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags); 507ce7c9111SKalle Valo } 508ce7c9111SKalle Valo 509ce7c9111SKalle Valo void ieee80211_wake_queues(struct ieee80211_hw *hw) 510ce7c9111SKalle Valo { 511445ea4e8SJohannes Berg ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP, 512cca07b00SLuciano Coelho IEEE80211_QUEUE_STOP_REASON_DRIVER, 513cca07b00SLuciano Coelho false); 514c2d1560aSJohannes Berg } 515c2d1560aSJohannes Berg EXPORT_SYMBOL(ieee80211_wake_queues); 516dabeb344SJohannes Berg 51726da23b6SLuciano Coelho static unsigned int 51826da23b6SLuciano Coelho ieee80211_get_vif_queues(struct ieee80211_local *local, 51939ecc01dSJohannes Berg struct ieee80211_sub_if_data *sdata) 52039ecc01dSJohannes Berg { 52126da23b6SLuciano Coelho unsigned int queues; 52239ecc01dSJohannes Berg 52330686bf7SJohannes Berg if (sdata && ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) { 52439ecc01dSJohannes Berg int ac; 52539ecc01dSJohannes Berg 52639ecc01dSJohannes Berg queues = 0; 52739ecc01dSJohannes Berg 52839ecc01dSJohannes Berg for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) 52939ecc01dSJohannes Berg queues |= BIT(sdata->vif.hw_queue[ac]); 53039ecc01dSJohannes Berg if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE) 53139ecc01dSJohannes Berg queues |= BIT(sdata->vif.cab_queue); 53239ecc01dSJohannes Berg } else { 53339ecc01dSJohannes Berg /* all queues */ 53439ecc01dSJohannes Berg queues = BIT(local->hw.queues) - 1; 53539ecc01dSJohannes Berg } 53639ecc01dSJohannes Berg 53726da23b6SLuciano Coelho return queues; 53826da23b6SLuciano Coelho } 53926da23b6SLuciano Coelho 5404f9610d5SLiad Kaufman void __ieee80211_flush_queues(struct ieee80211_local *local, 5414f9610d5SLiad Kaufman struct ieee80211_sub_if_data *sdata, 5423b24f4c6SEmmanuel Grumbach unsigned int queues, bool drop) 54326da23b6SLuciano Coelho { 54426da23b6SLuciano Coelho if (!local->ops->flush) 54526da23b6SLuciano Coelho return; 54626da23b6SLuciano Coelho 5474f9610d5SLiad Kaufman /* 5484f9610d5SLiad Kaufman * If no queue was set, or if the HW doesn't support 5494f9610d5SLiad Kaufman * IEEE80211_HW_QUEUE_CONTROL - flush all queues 5504f9610d5SLiad Kaufman */ 55130686bf7SJohannes Berg if (!queues || !ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) 55226da23b6SLuciano Coelho queues = ieee80211_get_vif_queues(local, sdata); 55326da23b6SLuciano Coelho 55459f48fe2SLuciano Coelho ieee80211_stop_queues_by_reason(&local->hw, queues, 555cca07b00SLuciano Coelho IEEE80211_QUEUE_STOP_REASON_FLUSH, 556cca07b00SLuciano Coelho false); 557445ea4e8SJohannes Berg 5583b24f4c6SEmmanuel Grumbach drv_flush(local, sdata, queues, drop); 559445ea4e8SJohannes Berg 56059f48fe2SLuciano Coelho ieee80211_wake_queues_by_reason(&local->hw, queues, 561cca07b00SLuciano Coelho IEEE80211_QUEUE_STOP_REASON_FLUSH, 562cca07b00SLuciano Coelho false); 56339ecc01dSJohannes Berg } 56439ecc01dSJohannes Berg 5654f9610d5SLiad Kaufman void ieee80211_flush_queues(struct ieee80211_local *local, 5663b24f4c6SEmmanuel Grumbach struct ieee80211_sub_if_data *sdata, bool drop) 5674f9610d5SLiad Kaufman { 5683b24f4c6SEmmanuel Grumbach __ieee80211_flush_queues(local, sdata, 0, drop); 5694f9610d5SLiad Kaufman } 5704f9610d5SLiad Kaufman 57126da23b6SLuciano Coelho void ieee80211_stop_vif_queues(struct ieee80211_local *local, 57226da23b6SLuciano Coelho struct ieee80211_sub_if_data *sdata, 57326da23b6SLuciano Coelho enum queue_stop_reason reason) 57426da23b6SLuciano Coelho { 57526da23b6SLuciano Coelho ieee80211_stop_queues_by_reason(&local->hw, 57626da23b6SLuciano Coelho ieee80211_get_vif_queues(local, sdata), 57726da23b6SLuciano Coelho reason, true); 57826da23b6SLuciano Coelho } 57926da23b6SLuciano Coelho 58026da23b6SLuciano Coelho void ieee80211_wake_vif_queues(struct ieee80211_local *local, 58126da23b6SLuciano Coelho struct ieee80211_sub_if_data *sdata, 58226da23b6SLuciano Coelho enum queue_stop_reason reason) 58326da23b6SLuciano Coelho { 58426da23b6SLuciano Coelho ieee80211_wake_queues_by_reason(&local->hw, 58526da23b6SLuciano Coelho ieee80211_get_vif_queues(local, sdata), 58626da23b6SLuciano Coelho reason, true); 58726da23b6SLuciano Coelho } 58826da23b6SLuciano Coelho 5893384d757SArik Nemtsov static void __iterate_interfaces(struct ieee80211_local *local, 590c7c71066SJohannes Berg u32 iter_flags, 591dabeb344SJohannes Berg void (*iterator)(void *data, u8 *mac, 59232bfd35dSJohannes Berg struct ieee80211_vif *vif), 593dabeb344SJohannes Berg void *data) 594dabeb344SJohannes Berg { 595dabeb344SJohannes Berg struct ieee80211_sub_if_data *sdata; 5963384d757SArik Nemtsov bool active_only = iter_flags & IEEE80211_IFACE_ITER_ACTIVE; 597dabeb344SJohannes Berg 598e38bad47SJohannes Berg list_for_each_entry_rcu(sdata, &local->interfaces, list) { 59951fb61e7SJohannes Berg switch (sdata->vif.type) { 60005c914feSJohannes Berg case NL80211_IFTYPE_MONITOR: 601d8212184SAviya Erenfeld if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE)) 60231eba5bcSFelix Fietkau continue; 60331eba5bcSFelix Fietkau break; 60405c914feSJohannes Berg case NL80211_IFTYPE_AP_VLAN: 605dabeb344SJohannes Berg continue; 6062ca27bcfSJohannes Berg default: 607dabeb344SJohannes Berg break; 608dabeb344SJohannes Berg } 6098b2c9824SJohannes Berg if (!(iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL) && 6103384d757SArik Nemtsov active_only && !(sdata->flags & IEEE80211_SDATA_IN_DRIVER)) 6118b2c9824SJohannes Berg continue; 6123384d757SArik Nemtsov if (ieee80211_sdata_running(sdata) || !active_only) 61347846c9bSJohannes Berg iterator(data, sdata->vif.addr, 61432bfd35dSJohannes Berg &sdata->vif); 615dabeb344SJohannes Berg } 616e38bad47SJohannes Berg 617c7c71066SJohannes Berg sdata = rcu_dereference_check(local->monitor_sdata, 618c7c71066SJohannes Berg lockdep_is_held(&local->iflist_mtx) || 619c7c71066SJohannes Berg lockdep_rtnl_is_held()); 6208b2c9824SJohannes Berg if (sdata && 6213384d757SArik Nemtsov (iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL || !active_only || 6228b2c9824SJohannes Berg sdata->flags & IEEE80211_SDATA_IN_DRIVER)) 623685fb72bSJohannes Berg iterator(data, sdata->vif.addr, &sdata->vif); 624c7c71066SJohannes Berg } 625685fb72bSJohannes Berg 6263384d757SArik Nemtsov void ieee80211_iterate_interfaces( 627c7c71066SJohannes Berg struct ieee80211_hw *hw, u32 iter_flags, 628c7c71066SJohannes Berg void (*iterator)(void *data, u8 *mac, 629c7c71066SJohannes Berg struct ieee80211_vif *vif), 630c7c71066SJohannes Berg void *data) 631c7c71066SJohannes Berg { 632c7c71066SJohannes Berg struct ieee80211_local *local = hw_to_local(hw); 633c7c71066SJohannes Berg 634c7c71066SJohannes Berg mutex_lock(&local->iflist_mtx); 6353384d757SArik Nemtsov __iterate_interfaces(local, iter_flags, iterator, data); 636c7c71066SJohannes Berg mutex_unlock(&local->iflist_mtx); 637c7c71066SJohannes Berg } 6383384d757SArik Nemtsov EXPORT_SYMBOL_GPL(ieee80211_iterate_interfaces); 639c7c71066SJohannes Berg 640c7c71066SJohannes Berg void ieee80211_iterate_active_interfaces_atomic( 641c7c71066SJohannes Berg struct ieee80211_hw *hw, u32 iter_flags, 642c7c71066SJohannes Berg void (*iterator)(void *data, u8 *mac, 643c7c71066SJohannes Berg struct ieee80211_vif *vif), 644c7c71066SJohannes Berg void *data) 645c7c71066SJohannes Berg { 646c7c71066SJohannes Berg struct ieee80211_local *local = hw_to_local(hw); 647c7c71066SJohannes Berg 648c7c71066SJohannes Berg rcu_read_lock(); 6493384d757SArik Nemtsov __iterate_interfaces(local, iter_flags | IEEE80211_IFACE_ITER_ACTIVE, 6503384d757SArik Nemtsov iterator, data); 651e38bad47SJohannes Berg rcu_read_unlock(); 652dabeb344SJohannes Berg } 6532f561febSIvo van Doorn EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic); 65437ffc8daSJohannes Berg 655c7c71066SJohannes Berg void ieee80211_iterate_active_interfaces_rtnl( 656c7c71066SJohannes Berg struct ieee80211_hw *hw, u32 iter_flags, 657c7c71066SJohannes Berg void (*iterator)(void *data, u8 *mac, 658c7c71066SJohannes Berg struct ieee80211_vif *vif), 659c7c71066SJohannes Berg void *data) 660c7c71066SJohannes Berg { 661c7c71066SJohannes Berg struct ieee80211_local *local = hw_to_local(hw); 662c7c71066SJohannes Berg 663c7c71066SJohannes Berg ASSERT_RTNL(); 664c7c71066SJohannes Berg 6653384d757SArik Nemtsov __iterate_interfaces(local, iter_flags | IEEE80211_IFACE_ITER_ACTIVE, 6663384d757SArik Nemtsov iterator, data); 667c7c71066SJohannes Berg } 668c7c71066SJohannes Berg EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_rtnl); 669c7c71066SJohannes Berg 6700fc1e049SArik Nemtsov static void __iterate_stations(struct ieee80211_local *local, 6710fc1e049SArik Nemtsov void (*iterator)(void *data, 6720fc1e049SArik Nemtsov struct ieee80211_sta *sta), 6730fc1e049SArik Nemtsov void *data) 6740fc1e049SArik Nemtsov { 6750fc1e049SArik Nemtsov struct sta_info *sta; 6760fc1e049SArik Nemtsov 6770fc1e049SArik Nemtsov list_for_each_entry_rcu(sta, &local->sta_list, list) { 6780fc1e049SArik Nemtsov if (!sta->uploaded) 6790fc1e049SArik Nemtsov continue; 6800fc1e049SArik Nemtsov 6810fc1e049SArik Nemtsov iterator(data, &sta->sta); 6820fc1e049SArik Nemtsov } 6830fc1e049SArik Nemtsov } 6840fc1e049SArik Nemtsov 6850fc1e049SArik Nemtsov void ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw, 6860fc1e049SArik Nemtsov void (*iterator)(void *data, 6870fc1e049SArik Nemtsov struct ieee80211_sta *sta), 6880fc1e049SArik Nemtsov void *data) 6890fc1e049SArik Nemtsov { 6900fc1e049SArik Nemtsov struct ieee80211_local *local = hw_to_local(hw); 6910fc1e049SArik Nemtsov 6920fc1e049SArik Nemtsov rcu_read_lock(); 6930fc1e049SArik Nemtsov __iterate_stations(local, iterator, data); 6940fc1e049SArik Nemtsov rcu_read_unlock(); 6950fc1e049SArik Nemtsov } 6960fc1e049SArik Nemtsov EXPORT_SYMBOL_GPL(ieee80211_iterate_stations_atomic); 6970fc1e049SArik Nemtsov 698ad7e718cSJohannes Berg struct ieee80211_vif *wdev_to_ieee80211_vif(struct wireless_dev *wdev) 699ad7e718cSJohannes Berg { 700ad7e718cSJohannes Berg struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev); 701ad7e718cSJohannes Berg 702ad7e718cSJohannes Berg if (!ieee80211_sdata_running(sdata) || 703ad7e718cSJohannes Berg !(sdata->flags & IEEE80211_SDATA_IN_DRIVER)) 704ad7e718cSJohannes Berg return NULL; 705ad7e718cSJohannes Berg return &sdata->vif; 706ad7e718cSJohannes Berg } 707ad7e718cSJohannes Berg EXPORT_SYMBOL_GPL(wdev_to_ieee80211_vif); 708ad7e718cSJohannes Berg 709dc5a1ad7SEmmanuel Grumbach struct wireless_dev *ieee80211_vif_to_wdev(struct ieee80211_vif *vif) 710dc5a1ad7SEmmanuel Grumbach { 7116513e98eSJohannes Berg struct ieee80211_sub_if_data *sdata; 7126513e98eSJohannes Berg 7136513e98eSJohannes Berg if (!vif) 7146513e98eSJohannes Berg return NULL; 7156513e98eSJohannes Berg 7166513e98eSJohannes Berg sdata = vif_to_sdata(vif); 717dc5a1ad7SEmmanuel Grumbach 718dc5a1ad7SEmmanuel Grumbach if (!ieee80211_sdata_running(sdata) || 719dc5a1ad7SEmmanuel Grumbach !(sdata->flags & IEEE80211_SDATA_IN_DRIVER)) 720dc5a1ad7SEmmanuel Grumbach return NULL; 721dc5a1ad7SEmmanuel Grumbach 722dc5a1ad7SEmmanuel Grumbach return &sdata->wdev; 723dc5a1ad7SEmmanuel Grumbach } 724dc5a1ad7SEmmanuel Grumbach EXPORT_SYMBOL_GPL(ieee80211_vif_to_wdev); 725dc5a1ad7SEmmanuel Grumbach 72642935ecaSLuis R. Rodriguez /* 72742935ecaSLuis R. Rodriguez * Nothing should have been stuffed into the workqueue during 7284afaff17SEmmanuel Grumbach * the suspend->resume cycle. Since we can't check each caller 7294afaff17SEmmanuel Grumbach * of this function if we are already quiescing / suspended, 7304afaff17SEmmanuel Grumbach * check here and don't WARN since this can actually happen when 7314afaff17SEmmanuel Grumbach * the rx path (for example) is racing against __ieee80211_suspend 7324afaff17SEmmanuel Grumbach * and suspending / quiescing was set after the rx path checked 7334afaff17SEmmanuel Grumbach * them. 73442935ecaSLuis R. Rodriguez */ 73542935ecaSLuis R. Rodriguez static bool ieee80211_can_queue_work(struct ieee80211_local *local) 73642935ecaSLuis R. Rodriguez { 7374afaff17SEmmanuel Grumbach if (local->quiescing || (local->suspended && !local->resuming)) { 7384afaff17SEmmanuel Grumbach pr_warn("queueing ieee80211 work while going to suspend\n"); 73942935ecaSLuis R. Rodriguez return false; 7404afaff17SEmmanuel Grumbach } 74142935ecaSLuis R. Rodriguez 74242935ecaSLuis R. Rodriguez return true; 74342935ecaSLuis R. Rodriguez } 74442935ecaSLuis R. Rodriguez 74542935ecaSLuis R. Rodriguez void ieee80211_queue_work(struct ieee80211_hw *hw, struct work_struct *work) 74642935ecaSLuis R. Rodriguez { 74742935ecaSLuis R. Rodriguez struct ieee80211_local *local = hw_to_local(hw); 74842935ecaSLuis R. Rodriguez 74942935ecaSLuis R. Rodriguez if (!ieee80211_can_queue_work(local)) 75042935ecaSLuis R. Rodriguez return; 75142935ecaSLuis R. Rodriguez 75242935ecaSLuis R. Rodriguez queue_work(local->workqueue, work); 75342935ecaSLuis R. Rodriguez } 75442935ecaSLuis R. Rodriguez EXPORT_SYMBOL(ieee80211_queue_work); 75542935ecaSLuis R. Rodriguez 75642935ecaSLuis R. Rodriguez void ieee80211_queue_delayed_work(struct ieee80211_hw *hw, 75742935ecaSLuis R. Rodriguez struct delayed_work *dwork, 75842935ecaSLuis R. Rodriguez unsigned long delay) 75942935ecaSLuis R. Rodriguez { 76042935ecaSLuis R. Rodriguez struct ieee80211_local *local = hw_to_local(hw); 76142935ecaSLuis R. Rodriguez 76242935ecaSLuis R. Rodriguez if (!ieee80211_can_queue_work(local)) 76342935ecaSLuis R. Rodriguez return; 76442935ecaSLuis R. Rodriguez 76542935ecaSLuis R. Rodriguez queue_delayed_work(local->workqueue, dwork, delay); 76642935ecaSLuis R. Rodriguez } 76742935ecaSLuis R. Rodriguez EXPORT_SYMBOL(ieee80211_queue_delayed_work); 76842935ecaSLuis R. Rodriguez 76935d865afSJohannes Berg u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action, 770dd76986bSJohannes Berg struct ieee802_11_elems *elems, 771dd76986bSJohannes Berg u64 filter, u32 crc) 772dd76986bSJohannes Berg { 773dd76986bSJohannes Berg size_t left = len; 77435d865afSJohannes Berg const u8 *pos = start; 775dd76986bSJohannes Berg bool calc_crc = filter != 0; 776fcff4f10SPaul Stewart DECLARE_BITMAP(seen_elems, 256); 777b2e506bfSJohannes Berg const u8 *ie; 778dd76986bSJohannes Berg 779fcff4f10SPaul Stewart bitmap_zero(seen_elems, 256); 780dd76986bSJohannes Berg memset(elems, 0, sizeof(*elems)); 781dd76986bSJohannes Berg elems->ie_start = start; 782dd76986bSJohannes Berg elems->total_len = len; 783dd76986bSJohannes Berg 784dd76986bSJohannes Berg while (left >= 2) { 785dd76986bSJohannes Berg u8 id, elen; 786fcff4f10SPaul Stewart bool elem_parse_failed; 787dd76986bSJohannes Berg 788dd76986bSJohannes Berg id = *pos++; 789dd76986bSJohannes Berg elen = *pos++; 790dd76986bSJohannes Berg left -= 2; 791dd76986bSJohannes Berg 792fcff4f10SPaul Stewart if (elen > left) { 793fcff4f10SPaul Stewart elems->parse_error = true; 794dd76986bSJohannes Berg break; 795fcff4f10SPaul Stewart } 796fcff4f10SPaul Stewart 7979690fb16SJohannes Berg switch (id) { 7989690fb16SJohannes Berg case WLAN_EID_SSID: 7999690fb16SJohannes Berg case WLAN_EID_SUPP_RATES: 8009690fb16SJohannes Berg case WLAN_EID_FH_PARAMS: 8019690fb16SJohannes Berg case WLAN_EID_DS_PARAMS: 8029690fb16SJohannes Berg case WLAN_EID_CF_PARAMS: 8039690fb16SJohannes Berg case WLAN_EID_TIM: 8049690fb16SJohannes Berg case WLAN_EID_IBSS_PARAMS: 8059690fb16SJohannes Berg case WLAN_EID_CHALLENGE: 8069690fb16SJohannes Berg case WLAN_EID_RSN: 8079690fb16SJohannes Berg case WLAN_EID_ERP_INFO: 8089690fb16SJohannes Berg case WLAN_EID_EXT_SUPP_RATES: 8099690fb16SJohannes Berg case WLAN_EID_HT_CAPABILITY: 8109690fb16SJohannes Berg case WLAN_EID_HT_OPERATION: 8119690fb16SJohannes Berg case WLAN_EID_VHT_CAPABILITY: 8129690fb16SJohannes Berg case WLAN_EID_VHT_OPERATION: 8139690fb16SJohannes Berg case WLAN_EID_MESH_ID: 8149690fb16SJohannes Berg case WLAN_EID_MESH_CONFIG: 8159690fb16SJohannes Berg case WLAN_EID_PEER_MGMT: 8169690fb16SJohannes Berg case WLAN_EID_PREQ: 8179690fb16SJohannes Berg case WLAN_EID_PREP: 8189690fb16SJohannes Berg case WLAN_EID_PERR: 8199690fb16SJohannes Berg case WLAN_EID_RANN: 8209690fb16SJohannes Berg case WLAN_EID_CHANNEL_SWITCH: 8219690fb16SJohannes Berg case WLAN_EID_EXT_CHANSWITCH_ANN: 8229690fb16SJohannes Berg case WLAN_EID_COUNTRY: 8239690fb16SJohannes Berg case WLAN_EID_PWR_CONSTRAINT: 8249690fb16SJohannes Berg case WLAN_EID_TIMEOUT_INTERVAL: 82585220d71SJohannes Berg case WLAN_EID_SECONDARY_CHANNEL_OFFSET: 826b2e506bfSJohannes Berg case WLAN_EID_WIDE_BW_CHANNEL_SWITCH: 8278f2535b9SChun-Yeow Yeoh case WLAN_EID_CHAN_SWITCH_PARAM: 8289041c1faSArik Nemtsov case WLAN_EID_EXT_CAPABILITY: 82953837584SArik Nemtsov case WLAN_EID_CHAN_SWITCH_TIMING: 83053837584SArik Nemtsov case WLAN_EID_LINK_ID: 831b2e506bfSJohannes Berg /* 832b2e506bfSJohannes Berg * not listing WLAN_EID_CHANNEL_SWITCH_WRAPPER -- it seems possible 833b2e506bfSJohannes Berg * that if the content gets bigger it might be needed more than once 834b2e506bfSJohannes Berg */ 8359690fb16SJohannes Berg if (test_bit(id, seen_elems)) { 836fcff4f10SPaul Stewart elems->parse_error = true; 837fcff4f10SPaul Stewart left -= elen; 838fcff4f10SPaul Stewart pos += elen; 839fcff4f10SPaul Stewart continue; 840fcff4f10SPaul Stewart } 8419690fb16SJohannes Berg break; 8429690fb16SJohannes Berg } 843dd76986bSJohannes Berg 844dd76986bSJohannes Berg if (calc_crc && id < 64 && (filter & (1ULL << id))) 845dd76986bSJohannes Berg crc = crc32_be(crc, pos - 2, elen + 2); 846dd76986bSJohannes Berg 847fcff4f10SPaul Stewart elem_parse_failed = false; 848fcff4f10SPaul Stewart 849dd76986bSJohannes Berg switch (id) { 85053837584SArik Nemtsov case WLAN_EID_LINK_ID: 85153837584SArik Nemtsov if (elen + 2 != sizeof(struct ieee80211_tdls_lnkie)) { 85253837584SArik Nemtsov elem_parse_failed = true; 85353837584SArik Nemtsov break; 85453837584SArik Nemtsov } 85553837584SArik Nemtsov elems->lnk_id = (void *)(pos - 2); 85653837584SArik Nemtsov break; 85753837584SArik Nemtsov case WLAN_EID_CHAN_SWITCH_TIMING: 85853837584SArik Nemtsov if (elen != sizeof(struct ieee80211_ch_switch_timing)) { 85953837584SArik Nemtsov elem_parse_failed = true; 86053837584SArik Nemtsov break; 86153837584SArik Nemtsov } 86253837584SArik Nemtsov elems->ch_sw_timing = (void *)pos; 86353837584SArik Nemtsov break; 8649041c1faSArik Nemtsov case WLAN_EID_EXT_CAPABILITY: 8659041c1faSArik Nemtsov elems->ext_capab = pos; 8669041c1faSArik Nemtsov elems->ext_capab_len = elen; 8679041c1faSArik Nemtsov break; 868dd76986bSJohannes Berg case WLAN_EID_SSID: 869dd76986bSJohannes Berg elems->ssid = pos; 870dd76986bSJohannes Berg elems->ssid_len = elen; 871dd76986bSJohannes Berg break; 872dd76986bSJohannes Berg case WLAN_EID_SUPP_RATES: 873dd76986bSJohannes Berg elems->supp_rates = pos; 874dd76986bSJohannes Berg elems->supp_rates_len = elen; 875dd76986bSJohannes Berg break; 876dd76986bSJohannes Berg case WLAN_EID_DS_PARAMS: 8771cd8e88eSJohannes Berg if (elen >= 1) 878dd76986bSJohannes Berg elems->ds_params = pos; 8791cd8e88eSJohannes Berg else 8801cd8e88eSJohannes Berg elem_parse_failed = true; 881dd76986bSJohannes Berg break; 882dd76986bSJohannes Berg case WLAN_EID_TIM: 883dd76986bSJohannes Berg if (elen >= sizeof(struct ieee80211_tim_ie)) { 884dd76986bSJohannes Berg elems->tim = (void *)pos; 885dd76986bSJohannes Berg elems->tim_len = elen; 886fcff4f10SPaul Stewart } else 887fcff4f10SPaul Stewart elem_parse_failed = true; 888dd76986bSJohannes Berg break; 889dd76986bSJohannes Berg case WLAN_EID_CHALLENGE: 890dd76986bSJohannes Berg elems->challenge = pos; 891dd76986bSJohannes Berg elems->challenge_len = elen; 892dd76986bSJohannes Berg break; 893dd76986bSJohannes Berg case WLAN_EID_VENDOR_SPECIFIC: 894dd76986bSJohannes Berg if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 && 895dd76986bSJohannes Berg pos[2] == 0xf2) { 896dd76986bSJohannes Berg /* Microsoft OUI (00:50:F2) */ 897dd76986bSJohannes Berg 898dd76986bSJohannes Berg if (calc_crc) 899dd76986bSJohannes Berg crc = crc32_be(crc, pos - 2, elen + 2); 900dd76986bSJohannes Berg 901441a33baSJohannes Berg if (elen >= 5 && pos[3] == 2) { 902dd76986bSJohannes Berg /* OUI Type 2 - WMM IE */ 903dd76986bSJohannes Berg if (pos[4] == 0) { 904dd76986bSJohannes Berg elems->wmm_info = pos; 905dd76986bSJohannes Berg elems->wmm_info_len = elen; 906dd76986bSJohannes Berg } else if (pos[4] == 1) { 907dd76986bSJohannes Berg elems->wmm_param = pos; 908dd76986bSJohannes Berg elems->wmm_param_len = elen; 909dd76986bSJohannes Berg } 910dd76986bSJohannes Berg } 911dd76986bSJohannes Berg } 912dd76986bSJohannes Berg break; 913dd76986bSJohannes Berg case WLAN_EID_RSN: 914dd76986bSJohannes Berg elems->rsn = pos; 915dd76986bSJohannes Berg elems->rsn_len = elen; 916dd76986bSJohannes Berg break; 917dd76986bSJohannes Berg case WLAN_EID_ERP_INFO: 9181946bed9SJohannes Berg if (elen >= 1) 919dd76986bSJohannes Berg elems->erp_info = pos; 9201946bed9SJohannes Berg else 9211946bed9SJohannes Berg elem_parse_failed = true; 922dd76986bSJohannes Berg break; 923dd76986bSJohannes Berg case WLAN_EID_EXT_SUPP_RATES: 924dd76986bSJohannes Berg elems->ext_supp_rates = pos; 925dd76986bSJohannes Berg elems->ext_supp_rates_len = elen; 926dd76986bSJohannes Berg break; 927dd76986bSJohannes Berg case WLAN_EID_HT_CAPABILITY: 928dd76986bSJohannes Berg if (elen >= sizeof(struct ieee80211_ht_cap)) 929dd76986bSJohannes Berg elems->ht_cap_elem = (void *)pos; 930fcff4f10SPaul Stewart else 931fcff4f10SPaul Stewart elem_parse_failed = true; 932dd76986bSJohannes Berg break; 933074d46d1SJohannes Berg case WLAN_EID_HT_OPERATION: 934074d46d1SJohannes Berg if (elen >= sizeof(struct ieee80211_ht_operation)) 935074d46d1SJohannes Berg elems->ht_operation = (void *)pos; 936fcff4f10SPaul Stewart else 937fcff4f10SPaul Stewart elem_parse_failed = true; 938dd76986bSJohannes Berg break; 939818255eaSMahesh Palivela case WLAN_EID_VHT_CAPABILITY: 940818255eaSMahesh Palivela if (elen >= sizeof(struct ieee80211_vht_cap)) 941818255eaSMahesh Palivela elems->vht_cap_elem = (void *)pos; 942818255eaSMahesh Palivela else 943818255eaSMahesh Palivela elem_parse_failed = true; 944818255eaSMahesh Palivela break; 945818255eaSMahesh Palivela case WLAN_EID_VHT_OPERATION: 946818255eaSMahesh Palivela if (elen >= sizeof(struct ieee80211_vht_operation)) 947818255eaSMahesh Palivela elems->vht_operation = (void *)pos; 948818255eaSMahesh Palivela else 949818255eaSMahesh Palivela elem_parse_failed = true; 950818255eaSMahesh Palivela break; 951bee7f586SJohannes Berg case WLAN_EID_OPMODE_NOTIF: 952bee7f586SJohannes Berg if (elen > 0) 953bee7f586SJohannes Berg elems->opmode_notif = pos; 954bee7f586SJohannes Berg else 955bee7f586SJohannes Berg elem_parse_failed = true; 956bee7f586SJohannes Berg break; 957dd76986bSJohannes Berg case WLAN_EID_MESH_ID: 958dd76986bSJohannes Berg elems->mesh_id = pos; 959dd76986bSJohannes Berg elems->mesh_id_len = elen; 960dd76986bSJohannes Berg break; 961dd76986bSJohannes Berg case WLAN_EID_MESH_CONFIG: 962dd76986bSJohannes Berg if (elen >= sizeof(struct ieee80211_meshconf_ie)) 963dd76986bSJohannes Berg elems->mesh_config = (void *)pos; 964fcff4f10SPaul Stewart else 965fcff4f10SPaul Stewart elem_parse_failed = true; 966dd76986bSJohannes Berg break; 967dd76986bSJohannes Berg case WLAN_EID_PEER_MGMT: 968dd76986bSJohannes Berg elems->peering = pos; 969dd76986bSJohannes Berg elems->peering_len = elen; 970dd76986bSJohannes Berg break; 9713f52b7e3SMarco Porsch case WLAN_EID_MESH_AWAKE_WINDOW: 9723f52b7e3SMarco Porsch if (elen >= 2) 9733f52b7e3SMarco Porsch elems->awake_window = (void *)pos; 9743f52b7e3SMarco Porsch break; 975dd76986bSJohannes Berg case WLAN_EID_PREQ: 976dd76986bSJohannes Berg elems->preq = pos; 977dd76986bSJohannes Berg elems->preq_len = elen; 978dd76986bSJohannes Berg break; 979dd76986bSJohannes Berg case WLAN_EID_PREP: 980dd76986bSJohannes Berg elems->prep = pos; 981dd76986bSJohannes Berg elems->prep_len = elen; 982dd76986bSJohannes Berg break; 983dd76986bSJohannes Berg case WLAN_EID_PERR: 984dd76986bSJohannes Berg elems->perr = pos; 985dd76986bSJohannes Berg elems->perr_len = elen; 986dd76986bSJohannes Berg break; 987dd76986bSJohannes Berg case WLAN_EID_RANN: 988dd76986bSJohannes Berg if (elen >= sizeof(struct ieee80211_rann_ie)) 989dd76986bSJohannes Berg elems->rann = (void *)pos; 990fcff4f10SPaul Stewart else 991fcff4f10SPaul Stewart elem_parse_failed = true; 992dd76986bSJohannes Berg break; 993dd76986bSJohannes Berg case WLAN_EID_CHANNEL_SWITCH: 9945bc1420bSJohannes Berg if (elen != sizeof(struct ieee80211_channel_sw_ie)) { 9955bc1420bSJohannes Berg elem_parse_failed = true; 9965bc1420bSJohannes Berg break; 9975bc1420bSJohannes Berg } 9985bc1420bSJohannes Berg elems->ch_switch_ie = (void *)pos; 999dd76986bSJohannes Berg break; 1000b4f286a1SJohannes Berg case WLAN_EID_EXT_CHANSWITCH_ANN: 1001b4f286a1SJohannes Berg if (elen != sizeof(struct ieee80211_ext_chansw_ie)) { 1002b4f286a1SJohannes Berg elem_parse_failed = true; 1003b4f286a1SJohannes Berg break; 1004b4f286a1SJohannes Berg } 1005b4f286a1SJohannes Berg elems->ext_chansw_ie = (void *)pos; 1006b4f286a1SJohannes Berg break; 100785220d71SJohannes Berg case WLAN_EID_SECONDARY_CHANNEL_OFFSET: 100885220d71SJohannes Berg if (elen != sizeof(struct ieee80211_sec_chan_offs_ie)) { 100985220d71SJohannes Berg elem_parse_failed = true; 101085220d71SJohannes Berg break; 101185220d71SJohannes Berg } 101285220d71SJohannes Berg elems->sec_chan_offs = (void *)pos; 101385220d71SJohannes Berg break; 10148f2535b9SChun-Yeow Yeoh case WLAN_EID_CHAN_SWITCH_PARAM: 10158f2535b9SChun-Yeow Yeoh if (elen != 10168f2535b9SChun-Yeow Yeoh sizeof(*elems->mesh_chansw_params_ie)) { 10178f2535b9SChun-Yeow Yeoh elem_parse_failed = true; 10188f2535b9SChun-Yeow Yeoh break; 10198f2535b9SChun-Yeow Yeoh } 10208f2535b9SChun-Yeow Yeoh elems->mesh_chansw_params_ie = (void *)pos; 10218f2535b9SChun-Yeow Yeoh break; 1022b2e506bfSJohannes Berg case WLAN_EID_WIDE_BW_CHANNEL_SWITCH: 1023b2e506bfSJohannes Berg if (!action || 1024b2e506bfSJohannes Berg elen != sizeof(*elems->wide_bw_chansw_ie)) { 1025b2e506bfSJohannes Berg elem_parse_failed = true; 1026b2e506bfSJohannes Berg break; 1027b2e506bfSJohannes Berg } 1028b2e506bfSJohannes Berg elems->wide_bw_chansw_ie = (void *)pos; 1029b2e506bfSJohannes Berg break; 1030b2e506bfSJohannes Berg case WLAN_EID_CHANNEL_SWITCH_WRAPPER: 1031b2e506bfSJohannes Berg if (action) { 1032b2e506bfSJohannes Berg elem_parse_failed = true; 1033b2e506bfSJohannes Berg break; 1034b2e506bfSJohannes Berg } 1035b2e506bfSJohannes Berg /* 1036b2e506bfSJohannes Berg * This is a bit tricky, but as we only care about 1037b2e506bfSJohannes Berg * the wide bandwidth channel switch element, so 1038b2e506bfSJohannes Berg * just parse it out manually. 1039b2e506bfSJohannes Berg */ 1040b2e506bfSJohannes Berg ie = cfg80211_find_ie(WLAN_EID_WIDE_BW_CHANNEL_SWITCH, 1041b2e506bfSJohannes Berg pos, elen); 1042b2e506bfSJohannes Berg if (ie) { 1043b2e506bfSJohannes Berg if (ie[1] == sizeof(*elems->wide_bw_chansw_ie)) 1044b2e506bfSJohannes Berg elems->wide_bw_chansw_ie = 1045b2e506bfSJohannes Berg (void *)(ie + 2); 1046b2e506bfSJohannes Berg else 1047b2e506bfSJohannes Berg elem_parse_failed = true; 1048b2e506bfSJohannes Berg } 1049b2e506bfSJohannes Berg break; 1050dd76986bSJohannes Berg case WLAN_EID_COUNTRY: 1051dd76986bSJohannes Berg elems->country_elem = pos; 1052dd76986bSJohannes Berg elems->country_elem_len = elen; 1053dd76986bSJohannes Berg break; 1054dd76986bSJohannes Berg case WLAN_EID_PWR_CONSTRAINT: 1055761a48d2SJohannes Berg if (elen != 1) { 1056761a48d2SJohannes Berg elem_parse_failed = true; 1057761a48d2SJohannes Berg break; 1058761a48d2SJohannes Berg } 1059dd76986bSJohannes Berg elems->pwr_constr_elem = pos; 1060dd76986bSJohannes Berg break; 1061c8d65917SSteinar H. Gunderson case WLAN_EID_CISCO_VENDOR_SPECIFIC: 1062c8d65917SSteinar H. Gunderson /* Lots of different options exist, but we only care 1063c8d65917SSteinar H. Gunderson * about the Dynamic Transmit Power Control element. 1064c8d65917SSteinar H. Gunderson * First check for the Cisco OUI, then for the DTPC 1065c8d65917SSteinar H. Gunderson * tag (0x00). 1066c8d65917SSteinar H. Gunderson */ 1067c8d65917SSteinar H. Gunderson if (elen < 4) { 1068c8d65917SSteinar H. Gunderson elem_parse_failed = true; 1069c8d65917SSteinar H. Gunderson break; 1070c8d65917SSteinar H. Gunderson } 1071c8d65917SSteinar H. Gunderson 1072c8d65917SSteinar H. Gunderson if (pos[0] != 0x00 || pos[1] != 0x40 || 1073c8d65917SSteinar H. Gunderson pos[2] != 0x96 || pos[3] != 0x00) 1074c8d65917SSteinar H. Gunderson break; 1075c8d65917SSteinar H. Gunderson 1076c8d65917SSteinar H. Gunderson if (elen != 6) { 1077c8d65917SSteinar H. Gunderson elem_parse_failed = true; 1078c8d65917SSteinar H. Gunderson break; 1079c8d65917SSteinar H. Gunderson } 1080c8d65917SSteinar H. Gunderson 1081c8d65917SSteinar H. Gunderson if (calc_crc) 1082c8d65917SSteinar H. Gunderson crc = crc32_be(crc, pos - 2, elen + 2); 1083c8d65917SSteinar H. Gunderson 1084c8d65917SSteinar H. Gunderson elems->cisco_dtpc_elem = pos; 1085c8d65917SSteinar H. Gunderson break; 1086dd76986bSJohannes Berg case WLAN_EID_TIMEOUT_INTERVAL: 108779ba1d89SJohannes Berg if (elen >= sizeof(struct ieee80211_timeout_interval_ie)) 108879ba1d89SJohannes Berg elems->timeout_int = (void *)pos; 108979ba1d89SJohannes Berg else 109079ba1d89SJohannes Berg elem_parse_failed = true; 1091dd76986bSJohannes Berg break; 1092dd76986bSJohannes Berg default: 1093dd76986bSJohannes Berg break; 1094dd76986bSJohannes Berg } 1095dd76986bSJohannes Berg 1096fcff4f10SPaul Stewart if (elem_parse_failed) 1097fcff4f10SPaul Stewart elems->parse_error = true; 1098fcff4f10SPaul Stewart else 10995df45690SJohannes Berg __set_bit(id, seen_elems); 1100fcff4f10SPaul Stewart 1101dd76986bSJohannes Berg left -= elen; 1102dd76986bSJohannes Berg pos += elen; 1103dd76986bSJohannes Berg } 1104dd76986bSJohannes Berg 1105fcff4f10SPaul Stewart if (left != 0) 1106fcff4f10SPaul Stewart elems->parse_error = true; 1107fcff4f10SPaul Stewart 1108dd76986bSJohannes Berg return crc; 1109dd76986bSJohannes Berg } 1110dd76986bSJohannes Berg 11113abead59SJohannes Berg void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata, 1112cec66283SJohannes Berg bool bss_notify, bool enable_qos) 11135825fe10SJohannes Berg { 11145825fe10SJohannes Berg struct ieee80211_local *local = sdata->local; 11155825fe10SJohannes Berg struct ieee80211_tx_queue_params qparam; 111655de908aSJohannes Berg struct ieee80211_chanctx_conf *chanctx_conf; 111754bcbc69SJohannes Berg int ac; 1118cec66283SJohannes Berg bool use_11b; 1119239281f8SRostislav Lisovy bool is_ocb; /* Use another EDCA parameters if dot11OCBActivated=true */ 1120aa837e1dSJohannes Berg int aCWmin, aCWmax; 11215825fe10SJohannes Berg 11225825fe10SJohannes Berg if (!local->ops->conf_tx) 11235825fe10SJohannes Berg return; 11245825fe10SJohannes Berg 112554bcbc69SJohannes Berg if (local->hw.queues < IEEE80211_NUM_ACS) 112654bcbc69SJohannes Berg return; 112754bcbc69SJohannes Berg 11285825fe10SJohannes Berg memset(&qparam, 0, sizeof(qparam)); 11295825fe10SJohannes Berg 113055de908aSJohannes Berg rcu_read_lock(); 113155de908aSJohannes Berg chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf); 113255de908aSJohannes Berg use_11b = (chanctx_conf && 113357fbcce3SJohannes Berg chanctx_conf->def.chan->band == NL80211_BAND_2GHZ) && 1134aa837e1dSJohannes Berg !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE); 113555de908aSJohannes Berg rcu_read_unlock(); 11365825fe10SJohannes Berg 1137239281f8SRostislav Lisovy is_ocb = (sdata->vif.type == NL80211_IFTYPE_OCB); 1138239281f8SRostislav Lisovy 1139aa837e1dSJohannes Berg /* Set defaults according to 802.11-2007 Table 7-37 */ 1140aa837e1dSJohannes Berg aCWmax = 1023; 1141aa837e1dSJohannes Berg if (use_11b) 1142aa837e1dSJohannes Berg aCWmin = 31; 11435825fe10SJohannes Berg else 1144aa837e1dSJohannes Berg aCWmin = 15; 11455825fe10SJohannes Berg 11461f4ffde8SFred Zhou /* Confiure old 802.11b/g medium access rules. */ 11471f4ffde8SFred Zhou qparam.cw_max = aCWmax; 11481f4ffde8SFred Zhou qparam.cw_min = aCWmin; 11491f4ffde8SFred Zhou qparam.txop = 0; 11501f4ffde8SFred Zhou qparam.aifs = 2; 11511f4ffde8SFred Zhou 11521f4ffde8SFred Zhou for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 11531f4ffde8SFred Zhou /* Update if QoS is enabled. */ 1154a8ce8544SStanislaw Gruszka if (enable_qos) { 115554bcbc69SJohannes Berg switch (ac) { 11561d98fb12SJohannes Berg case IEEE80211_AC_BK: 11577ba10a8eSJohannes Berg qparam.cw_max = aCWmax; 11587ba10a8eSJohannes Berg qparam.cw_min = aCWmin; 11595825fe10SJohannes Berg qparam.txop = 0; 1160239281f8SRostislav Lisovy if (is_ocb) 1161239281f8SRostislav Lisovy qparam.aifs = 9; 1162239281f8SRostislav Lisovy else 1163aa837e1dSJohannes Berg qparam.aifs = 7; 1164aa837e1dSJohannes Berg break; 1165a8ce8544SStanislaw Gruszka /* never happens but let's not leave undefined */ 1166a8ce8544SStanislaw Gruszka default: 11671d98fb12SJohannes Berg case IEEE80211_AC_BE: 11687ba10a8eSJohannes Berg qparam.cw_max = aCWmax; 11697ba10a8eSJohannes Berg qparam.cw_min = aCWmin; 1170aa837e1dSJohannes Berg qparam.txop = 0; 1171239281f8SRostislav Lisovy if (is_ocb) 1172239281f8SRostislav Lisovy qparam.aifs = 6; 1173239281f8SRostislav Lisovy else 1174aa837e1dSJohannes Berg qparam.aifs = 3; 1175aa837e1dSJohannes Berg break; 11761d98fb12SJohannes Berg case IEEE80211_AC_VI: 1177aa837e1dSJohannes Berg qparam.cw_max = aCWmin; 1178aa837e1dSJohannes Berg qparam.cw_min = (aCWmin + 1) / 2 - 1; 1179239281f8SRostislav Lisovy if (is_ocb) 1180239281f8SRostislav Lisovy qparam.txop = 0; 1181239281f8SRostislav Lisovy else if (use_11b) 1182aa837e1dSJohannes Berg qparam.txop = 6016/32; 1183aa837e1dSJohannes Berg else 1184aa837e1dSJohannes Berg qparam.txop = 3008/32; 1185239281f8SRostislav Lisovy 1186239281f8SRostislav Lisovy if (is_ocb) 1187239281f8SRostislav Lisovy qparam.aifs = 3; 1188239281f8SRostislav Lisovy else 1189aa837e1dSJohannes Berg qparam.aifs = 2; 1190aa837e1dSJohannes Berg break; 11911d98fb12SJohannes Berg case IEEE80211_AC_VO: 1192aa837e1dSJohannes Berg qparam.cw_max = (aCWmin + 1) / 2 - 1; 1193aa837e1dSJohannes Berg qparam.cw_min = (aCWmin + 1) / 4 - 1; 1194239281f8SRostislav Lisovy if (is_ocb) 1195239281f8SRostislav Lisovy qparam.txop = 0; 1196239281f8SRostislav Lisovy else if (use_11b) 1197aa837e1dSJohannes Berg qparam.txop = 3264/32; 1198aa837e1dSJohannes Berg else 1199aa837e1dSJohannes Berg qparam.txop = 1504/32; 1200aa837e1dSJohannes Berg qparam.aifs = 2; 1201aa837e1dSJohannes Berg break; 1202aa837e1dSJohannes Berg } 1203a8ce8544SStanislaw Gruszka } 12045825fe10SJohannes Berg 1205ab13315aSKalle Valo qparam.uapsd = false; 1206ab13315aSKalle Valo 120754bcbc69SJohannes Berg sdata->tx_conf[ac] = qparam; 120854bcbc69SJohannes Berg drv_conf_tx(local, sdata, ac, &qparam); 1209aa837e1dSJohannes Berg } 1210e1b3ec1aSStanislaw Gruszka 1211f142c6b9SJohannes Berg if (sdata->vif.type != NL80211_IFTYPE_MONITOR && 1212f142c6b9SJohannes Berg sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE) { 1213a8ce8544SStanislaw Gruszka sdata->vif.bss_conf.qos = enable_qos; 12143abead59SJohannes Berg if (bss_notify) 12153abead59SJohannes Berg ieee80211_bss_info_change_notify(sdata, 12163abead59SJohannes Berg BSS_CHANGED_QOS); 12175825fe10SJohannes Berg } 1218d9734979SSujith } 1219e50db65cSJohannes Berg 122046900298SJohannes Berg void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata, 1221700e8ea6SJouni Malinen u16 transaction, u16 auth_alg, u16 status, 12224a3cb702SJohannes Berg const u8 *extra, size_t extra_len, const u8 *da, 12231672c0e3SJohannes Berg const u8 *bssid, const u8 *key, u8 key_len, u8 key_idx, 12241672c0e3SJohannes Berg u32 tx_flags) 122546900298SJohannes Berg { 122646900298SJohannes Berg struct ieee80211_local *local = sdata->local; 122746900298SJohannes Berg struct sk_buff *skb; 122846900298SJohannes Berg struct ieee80211_mgmt *mgmt; 1229fffd0934SJohannes Berg int err; 123046900298SJohannes Berg 123115e230abSFred Zhou /* 24 + 6 = header + auth_algo + auth_transaction + status_code */ 1232744462a9SMax Stepanov skb = dev_alloc_skb(local->hw.extra_tx_headroom + IEEE80211_WEP_IV_LEN + 1233744462a9SMax Stepanov 24 + 6 + extra_len + IEEE80211_WEP_ICV_LEN); 1234d15b8459SJoe Perches if (!skb) 123546900298SJohannes Berg return; 1236d15b8459SJoe Perches 1237744462a9SMax Stepanov skb_reserve(skb, local->hw.extra_tx_headroom + IEEE80211_WEP_IV_LEN); 123846900298SJohannes Berg 123946900298SJohannes Berg mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6); 124046900298SJohannes Berg memset(mgmt, 0, 24 + 6); 124146900298SJohannes Berg mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 124246900298SJohannes Berg IEEE80211_STYPE_AUTH); 1243efa6a09dSAntonio Quartulli memcpy(mgmt->da, da, ETH_ALEN); 124447846c9bSJohannes Berg memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 124546900298SJohannes Berg memcpy(mgmt->bssid, bssid, ETH_ALEN); 124646900298SJohannes Berg mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg); 124746900298SJohannes Berg mgmt->u.auth.auth_transaction = cpu_to_le16(transaction); 1248700e8ea6SJouni Malinen mgmt->u.auth.status_code = cpu_to_le16(status); 124946900298SJohannes Berg if (extra) 125046900298SJohannes Berg memcpy(skb_put(skb, extra_len), extra, extra_len); 125146900298SJohannes Berg 1252fffd0934SJohannes Berg if (auth_alg == WLAN_AUTH_SHARED_KEY && transaction == 3) { 1253fffd0934SJohannes Berg mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED); 1254fffd0934SJohannes Berg err = ieee80211_wep_encrypt(local, skb, key, key_len, key_idx); 1255fffd0934SJohannes Berg WARN_ON(err); 1256fffd0934SJohannes Berg } 1257fffd0934SJohannes Berg 12581672c0e3SJohannes Berg IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT | 12591672c0e3SJohannes Berg tx_flags; 126062ae67beSJohannes Berg ieee80211_tx_skb(sdata, skb); 126146900298SJohannes Berg } 126246900298SJohannes Berg 12636ae16775SAntonio Quartulli void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata, 12646ae16775SAntonio Quartulli const u8 *bssid, u16 stype, u16 reason, 12656ae16775SAntonio Quartulli bool send_frame, u8 *frame_buf) 12666ae16775SAntonio Quartulli { 12676ae16775SAntonio Quartulli struct ieee80211_local *local = sdata->local; 12686ae16775SAntonio Quartulli struct sk_buff *skb; 12696ae16775SAntonio Quartulli struct ieee80211_mgmt *mgmt = (void *)frame_buf; 12706ae16775SAntonio Quartulli 12716ae16775SAntonio Quartulli /* build frame */ 12726ae16775SAntonio Quartulli mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype); 12736ae16775SAntonio Quartulli mgmt->duration = 0; /* initialize only */ 12746ae16775SAntonio Quartulli mgmt->seq_ctrl = 0; /* initialize only */ 12756ae16775SAntonio Quartulli memcpy(mgmt->da, bssid, ETH_ALEN); 12766ae16775SAntonio Quartulli memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 12776ae16775SAntonio Quartulli memcpy(mgmt->bssid, bssid, ETH_ALEN); 12786ae16775SAntonio Quartulli /* u.deauth.reason_code == u.disassoc.reason_code */ 12796ae16775SAntonio Quartulli mgmt->u.deauth.reason_code = cpu_to_le16(reason); 12806ae16775SAntonio Quartulli 12816ae16775SAntonio Quartulli if (send_frame) { 12826ae16775SAntonio Quartulli skb = dev_alloc_skb(local->hw.extra_tx_headroom + 12836ae16775SAntonio Quartulli IEEE80211_DEAUTH_FRAME_LEN); 12846ae16775SAntonio Quartulli if (!skb) 12856ae16775SAntonio Quartulli return; 12866ae16775SAntonio Quartulli 12876ae16775SAntonio Quartulli skb_reserve(skb, local->hw.extra_tx_headroom); 12886ae16775SAntonio Quartulli 12896ae16775SAntonio Quartulli /* copy in frame */ 12906ae16775SAntonio Quartulli memcpy(skb_put(skb, IEEE80211_DEAUTH_FRAME_LEN), 12916ae16775SAntonio Quartulli mgmt, IEEE80211_DEAUTH_FRAME_LEN); 12926ae16775SAntonio Quartulli 12936ae16775SAntonio Quartulli if (sdata->vif.type != NL80211_IFTYPE_STATION || 12946ae16775SAntonio Quartulli !(sdata->u.mgd.flags & IEEE80211_STA_MFP_ENABLED)) 12956ae16775SAntonio Quartulli IEEE80211_SKB_CB(skb)->flags |= 12966ae16775SAntonio Quartulli IEEE80211_TX_INTFL_DONT_ENCRYPT; 12976ae16775SAntonio Quartulli 12986ae16775SAntonio Quartulli ieee80211_tx_skb(sdata, skb); 12996ae16775SAntonio Quartulli } 13006ae16775SAntonio Quartulli } 13016ae16775SAntonio Quartulli 1302c56ef672SDavid Spinadel static int ieee80211_build_preq_ies_band(struct ieee80211_local *local, 1303c56ef672SDavid Spinadel u8 *buffer, size_t buffer_len, 1304c56ef672SDavid Spinadel const u8 *ie, size_t ie_len, 130557fbcce3SJohannes Berg enum nl80211_band band, 1306c56ef672SDavid Spinadel u32 rate_mask, 1307c56ef672SDavid Spinadel struct cfg80211_chan_def *chandef, 1308c56ef672SDavid Spinadel size_t *offset) 1309de95a54bSJohannes Berg { 1310de95a54bSJohannes Berg struct ieee80211_supported_band *sband; 1311c604b9f2SJohannes Berg u8 *pos = buffer, *end = buffer + buffer_len; 1312c56ef672SDavid Spinadel size_t noffset; 13138e664fb3SJohannes Berg int supp_rates_len, i; 13148dcb2003SJouni Malinen u8 rates[32]; 13158dcb2003SJouni Malinen int num_rates; 13168dcb2003SJouni Malinen int ext_rates_len; 13172103dec1SSimon Wunderlich int shift; 13182103dec1SSimon Wunderlich u32 rate_flags; 131940a11ca8SJohannes Berg bool have_80mhz = false; 1320de95a54bSJohannes Berg 1321c56ef672SDavid Spinadel *offset = 0; 1322c56ef672SDavid Spinadel 13234d36ec58SJohannes Berg sband = local->hw.wiphy->bands[band]; 1324d811b3d5SArik Nemtsov if (WARN_ON_ONCE(!sband)) 1325d811b3d5SArik Nemtsov return 0; 1326de95a54bSJohannes Berg 13272103dec1SSimon Wunderlich rate_flags = ieee80211_chandef_rate_flags(chandef); 13282103dec1SSimon Wunderlich shift = ieee80211_chandef_get_shift(chandef); 13292103dec1SSimon Wunderlich 13308dcb2003SJouni Malinen num_rates = 0; 13318dcb2003SJouni Malinen for (i = 0; i < sband->n_bitrates; i++) { 13328dcb2003SJouni Malinen if ((BIT(i) & rate_mask) == 0) 13338dcb2003SJouni Malinen continue; /* skip rate */ 13342103dec1SSimon Wunderlich if ((rate_flags & sband->bitrates[i].flags) != rate_flags) 13352103dec1SSimon Wunderlich continue; 13362103dec1SSimon Wunderlich 13372103dec1SSimon Wunderlich rates[num_rates++] = 13382103dec1SSimon Wunderlich (u8) DIV_ROUND_UP(sband->bitrates[i].bitrate, 13392103dec1SSimon Wunderlich (1 << shift) * 5); 13408dcb2003SJouni Malinen } 13418dcb2003SJouni Malinen 13428dcb2003SJouni Malinen supp_rates_len = min_t(int, num_rates, 8); 13438e664fb3SJohannes Berg 1344c604b9f2SJohannes Berg if (end - pos < 2 + supp_rates_len) 1345c604b9f2SJohannes Berg goto out_err; 1346de95a54bSJohannes Berg *pos++ = WLAN_EID_SUPP_RATES; 13478e664fb3SJohannes Berg *pos++ = supp_rates_len; 13488dcb2003SJouni Malinen memcpy(pos, rates, supp_rates_len); 13498dcb2003SJouni Malinen pos += supp_rates_len; 1350de95a54bSJohannes Berg 13518e664fb3SJohannes Berg /* insert "request information" if in custom IEs */ 13528e664fb3SJohannes Berg if (ie && ie_len) { 13538e664fb3SJohannes Berg static const u8 before_extrates[] = { 13548e664fb3SJohannes Berg WLAN_EID_SSID, 13558e664fb3SJohannes Berg WLAN_EID_SUPP_RATES, 13568e664fb3SJohannes Berg WLAN_EID_REQUEST, 13578e664fb3SJohannes Berg }; 13588e664fb3SJohannes Berg noffset = ieee80211_ie_split(ie, ie_len, 13598e664fb3SJohannes Berg before_extrates, 13608e664fb3SJohannes Berg ARRAY_SIZE(before_extrates), 1361c56ef672SDavid Spinadel *offset); 1362c56ef672SDavid Spinadel if (end - pos < noffset - *offset) 1363c604b9f2SJohannes Berg goto out_err; 1364c56ef672SDavid Spinadel memcpy(pos, ie + *offset, noffset - *offset); 1365c56ef672SDavid Spinadel pos += noffset - *offset; 1366c56ef672SDavid Spinadel *offset = noffset; 13678e664fb3SJohannes Berg } 13688e664fb3SJohannes Berg 13698dcb2003SJouni Malinen ext_rates_len = num_rates - supp_rates_len; 13708dcb2003SJouni Malinen if (ext_rates_len > 0) { 1371c604b9f2SJohannes Berg if (end - pos < 2 + ext_rates_len) 1372c604b9f2SJohannes Berg goto out_err; 1373de95a54bSJohannes Berg *pos++ = WLAN_EID_EXT_SUPP_RATES; 13748dcb2003SJouni Malinen *pos++ = ext_rates_len; 13758dcb2003SJouni Malinen memcpy(pos, rates + supp_rates_len, ext_rates_len); 13768dcb2003SJouni Malinen pos += ext_rates_len; 13778e664fb3SJohannes Berg } 13788e664fb3SJohannes Berg 137957fbcce3SJohannes Berg if (chandef->chan && sband->band == NL80211_BAND_2GHZ) { 1380c604b9f2SJohannes Berg if (end - pos < 3) 1381c604b9f2SJohannes Berg goto out_err; 1382651b5225SJouni Malinen *pos++ = WLAN_EID_DS_PARAMS; 1383651b5225SJouni Malinen *pos++ = 1; 13842103dec1SSimon Wunderlich *pos++ = ieee80211_frequency_to_channel( 13852103dec1SSimon Wunderlich chandef->chan->center_freq); 1386651b5225SJouni Malinen } 1387651b5225SJouni Malinen 13888e664fb3SJohannes Berg /* insert custom IEs that go before HT */ 13898e664fb3SJohannes Berg if (ie && ie_len) { 13908e664fb3SJohannes Berg static const u8 before_ht[] = { 13918e664fb3SJohannes Berg WLAN_EID_SSID, 13928e664fb3SJohannes Berg WLAN_EID_SUPP_RATES, 13938e664fb3SJohannes Berg WLAN_EID_REQUEST, 13948e664fb3SJohannes Berg WLAN_EID_EXT_SUPP_RATES, 13958e664fb3SJohannes Berg WLAN_EID_DS_PARAMS, 13968e664fb3SJohannes Berg WLAN_EID_SUPPORTED_REGULATORY_CLASSES, 13978e664fb3SJohannes Berg }; 13988e664fb3SJohannes Berg noffset = ieee80211_ie_split(ie, ie_len, 13998e664fb3SJohannes Berg before_ht, ARRAY_SIZE(before_ht), 1400c56ef672SDavid Spinadel *offset); 1401c56ef672SDavid Spinadel if (end - pos < noffset - *offset) 1402c604b9f2SJohannes Berg goto out_err; 1403c56ef672SDavid Spinadel memcpy(pos, ie + *offset, noffset - *offset); 1404c56ef672SDavid Spinadel pos += noffset - *offset; 1405c56ef672SDavid Spinadel *offset = noffset; 1406de95a54bSJohannes Berg } 1407de95a54bSJohannes Berg 1408c604b9f2SJohannes Berg if (sband->ht_cap.ht_supported) { 1409c604b9f2SJohannes Berg if (end - pos < 2 + sizeof(struct ieee80211_ht_cap)) 1410c604b9f2SJohannes Berg goto out_err; 1411ef96a842SBen Greear pos = ieee80211_ie_build_ht_cap(pos, &sband->ht_cap, 1412ef96a842SBen Greear sband->ht_cap.cap); 1413c604b9f2SJohannes Berg } 14145ef2d41aSJohannes Berg 1415de95a54bSJohannes Berg /* 1416de95a54bSJohannes Berg * If adding more here, adjust code in main.c 1417de95a54bSJohannes Berg * that calculates local->scan_ies_len. 1418de95a54bSJohannes Berg */ 1419de95a54bSJohannes Berg 14204d952300SJohannes Berg /* insert custom IEs that go before VHT */ 14218e664fb3SJohannes Berg if (ie && ie_len) { 14224d952300SJohannes Berg static const u8 before_vht[] = { 14234d952300SJohannes Berg WLAN_EID_SSID, 14244d952300SJohannes Berg WLAN_EID_SUPP_RATES, 14254d952300SJohannes Berg WLAN_EID_REQUEST, 14264d952300SJohannes Berg WLAN_EID_EXT_SUPP_RATES, 14274d952300SJohannes Berg WLAN_EID_DS_PARAMS, 14284d952300SJohannes Berg WLAN_EID_SUPPORTED_REGULATORY_CLASSES, 14294d952300SJohannes Berg WLAN_EID_HT_CAPABILITY, 14304d952300SJohannes Berg WLAN_EID_BSS_COEX_2040, 14314d952300SJohannes Berg WLAN_EID_EXT_CAPABILITY, 14324d952300SJohannes Berg WLAN_EID_SSID_LIST, 14334d952300SJohannes Berg WLAN_EID_CHANNEL_USAGE, 14344d952300SJohannes Berg WLAN_EID_INTERWORKING, 14354d952300SJohannes Berg /* mesh ID can't happen here */ 14364d952300SJohannes Berg /* 60 GHz can't happen here right now */ 14374d952300SJohannes Berg }; 14384d952300SJohannes Berg noffset = ieee80211_ie_split(ie, ie_len, 14394d952300SJohannes Berg before_vht, ARRAY_SIZE(before_vht), 1440c56ef672SDavid Spinadel *offset); 1441c56ef672SDavid Spinadel if (end - pos < noffset - *offset) 1442c604b9f2SJohannes Berg goto out_err; 1443c56ef672SDavid Spinadel memcpy(pos, ie + *offset, noffset - *offset); 1444c56ef672SDavid Spinadel pos += noffset - *offset; 1445c56ef672SDavid Spinadel *offset = noffset; 1446de95a54bSJohannes Berg } 1447de95a54bSJohannes Berg 144840a11ca8SJohannes Berg /* Check if any channel in this sband supports at least 80 MHz */ 144940a11ca8SJohannes Berg for (i = 0; i < sband->n_channels; i++) { 1450fa44b988SArik Nemtsov if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED | 1451fa44b988SArik Nemtsov IEEE80211_CHAN_NO_80MHZ)) 1452fa44b988SArik Nemtsov continue; 1453fa44b988SArik Nemtsov 145440a11ca8SJohannes Berg have_80mhz = true; 145540a11ca8SJohannes Berg break; 145640a11ca8SJohannes Berg } 145740a11ca8SJohannes Berg 145840a11ca8SJohannes Berg if (sband->vht_cap.vht_supported && have_80mhz) { 1459c604b9f2SJohannes Berg if (end - pos < 2 + sizeof(struct ieee80211_vht_cap)) 1460c604b9f2SJohannes Berg goto out_err; 1461ba0afa2fSMahesh Palivela pos = ieee80211_ie_build_vht_cap(pos, &sband->vht_cap, 1462ba0afa2fSMahesh Palivela sband->vht_cap.cap); 1463c604b9f2SJohannes Berg } 1464ba0afa2fSMahesh Palivela 1465de95a54bSJohannes Berg return pos - buffer; 1466c604b9f2SJohannes Berg out_err: 1467c604b9f2SJohannes Berg WARN_ONCE(1, "not enough space for preq IEs\n"); 1468c604b9f2SJohannes Berg return pos - buffer; 1469de95a54bSJohannes Berg } 1470de95a54bSJohannes Berg 1471c56ef672SDavid Spinadel int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer, 1472c56ef672SDavid Spinadel size_t buffer_len, 1473c56ef672SDavid Spinadel struct ieee80211_scan_ies *ie_desc, 1474c56ef672SDavid Spinadel const u8 *ie, size_t ie_len, 1475c56ef672SDavid Spinadel u8 bands_used, u32 *rate_masks, 1476c56ef672SDavid Spinadel struct cfg80211_chan_def *chandef) 1477c56ef672SDavid Spinadel { 1478c56ef672SDavid Spinadel size_t pos = 0, old_pos = 0, custom_ie_offset = 0; 1479c56ef672SDavid Spinadel int i; 1480c56ef672SDavid Spinadel 1481c56ef672SDavid Spinadel memset(ie_desc, 0, sizeof(*ie_desc)); 1482c56ef672SDavid Spinadel 148357fbcce3SJohannes Berg for (i = 0; i < NUM_NL80211_BANDS; i++) { 1484c56ef672SDavid Spinadel if (bands_used & BIT(i)) { 1485c56ef672SDavid Spinadel pos += ieee80211_build_preq_ies_band(local, 1486c56ef672SDavid Spinadel buffer + pos, 1487c56ef672SDavid Spinadel buffer_len - pos, 1488c56ef672SDavid Spinadel ie, ie_len, i, 1489c56ef672SDavid Spinadel rate_masks[i], 1490c56ef672SDavid Spinadel chandef, 1491c56ef672SDavid Spinadel &custom_ie_offset); 1492c56ef672SDavid Spinadel ie_desc->ies[i] = buffer + old_pos; 1493c56ef672SDavid Spinadel ie_desc->len[i] = pos - old_pos; 1494c56ef672SDavid Spinadel old_pos = pos; 1495c56ef672SDavid Spinadel } 1496c56ef672SDavid Spinadel } 1497c56ef672SDavid Spinadel 1498c56ef672SDavid Spinadel /* add any remaining custom IEs */ 1499c56ef672SDavid Spinadel if (ie && ie_len) { 1500c56ef672SDavid Spinadel if (WARN_ONCE(buffer_len - pos < ie_len - custom_ie_offset, 1501c56ef672SDavid Spinadel "not enough space for preq custom IEs\n")) 1502c56ef672SDavid Spinadel return pos; 1503c56ef672SDavid Spinadel memcpy(buffer + pos, ie + custom_ie_offset, 1504c56ef672SDavid Spinadel ie_len - custom_ie_offset); 1505c56ef672SDavid Spinadel ie_desc->common_ies = buffer + pos; 1506c56ef672SDavid Spinadel ie_desc->common_ie_len = ie_len - custom_ie_offset; 1507c56ef672SDavid Spinadel pos += ie_len - custom_ie_offset; 1508c56ef672SDavid Spinadel } 1509c56ef672SDavid Spinadel 1510c56ef672SDavid Spinadel return pos; 1511c56ef672SDavid Spinadel }; 1512c56ef672SDavid Spinadel 1513a619a4c0SJuuso Oikarinen struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata, 1514a344d677SJohannes Berg const u8 *src, const u8 *dst, 1515a344d677SJohannes Berg u32 ratemask, 15166b77863bSJohannes Berg struct ieee80211_channel *chan, 1517de95a54bSJohannes Berg const u8 *ssid, size_t ssid_len, 1518a806c558SPaul Stewart const u8 *ie, size_t ie_len, 1519a806c558SPaul Stewart bool directed) 152046900298SJohannes Berg { 152146900298SJohannes Berg struct ieee80211_local *local = sdata->local; 15222103dec1SSimon Wunderlich struct cfg80211_chan_def chandef; 152346900298SJohannes Berg struct sk_buff *skb; 152446900298SJohannes Berg struct ieee80211_mgmt *mgmt; 1525b9a9ada1SJohannes Berg int ies_len; 152657fbcce3SJohannes Berg u32 rate_masks[NUM_NL80211_BANDS] = {}; 1527c56ef672SDavid Spinadel struct ieee80211_scan_ies dummy_ie_desc; 152846900298SJohannes Berg 1529a806c558SPaul Stewart /* 1530a806c558SPaul Stewart * Do not send DS Channel parameter for directed probe requests 1531a806c558SPaul Stewart * in order to maximize the chance that we get a response. Some 1532a806c558SPaul Stewart * badly-behaved APs don't respond when this parameter is included. 1533a806c558SPaul Stewart */ 15342103dec1SSimon Wunderlich chandef.width = sdata->vif.bss_conf.chandef.width; 1535a806c558SPaul Stewart if (directed) 15362103dec1SSimon Wunderlich chandef.chan = NULL; 1537a806c558SPaul Stewart else 15382103dec1SSimon Wunderlich chandef.chan = chan; 1539651b5225SJouni Malinen 1540a344d677SJohannes Berg skb = ieee80211_probereq_get(&local->hw, src, ssid, ssid_len, 1541a344d677SJohannes Berg 100 + ie_len); 15425b2bbf75SJohannes Berg if (!skb) 1543b9a9ada1SJohannes Berg return NULL; 1544b9a9ada1SJohannes Berg 1545c56ef672SDavid Spinadel rate_masks[chan->band] = ratemask; 1546b9a9ada1SJohannes Berg ies_len = ieee80211_build_preq_ies(local, skb_tail_pointer(skb), 1547c56ef672SDavid Spinadel skb_tailroom(skb), &dummy_ie_desc, 1548c56ef672SDavid Spinadel ie, ie_len, BIT(chan->band), 1549c56ef672SDavid Spinadel rate_masks, &chandef); 1550b9a9ada1SJohannes Berg skb_put(skb, ies_len); 15517c12ce8bSKalle Valo 155246900298SJohannes Berg if (dst) { 15537c12ce8bSKalle Valo mgmt = (struct ieee80211_mgmt *) skb->data; 155446900298SJohannes Berg memcpy(mgmt->da, dst, ETH_ALEN); 155546900298SJohannes Berg memcpy(mgmt->bssid, dst, ETH_ALEN); 155646900298SJohannes Berg } 155746900298SJohannes Berg 155862ae67beSJohannes Berg IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT; 15595b2bbf75SJohannes Berg 1560a619a4c0SJuuso Oikarinen return skb; 1561a619a4c0SJuuso Oikarinen } 1562a619a4c0SJuuso Oikarinen 1563a344d677SJohannes Berg void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, 1564a344d677SJohannes Berg const u8 *src, const u8 *dst, 1565a619a4c0SJuuso Oikarinen const u8 *ssid, size_t ssid_len, 1566a806c558SPaul Stewart const u8 *ie, size_t ie_len, 15671672c0e3SJohannes Berg u32 ratemask, bool directed, u32 tx_flags, 156855de908aSJohannes Berg struct ieee80211_channel *channel, bool scan) 1569a619a4c0SJuuso Oikarinen { 1570a619a4c0SJuuso Oikarinen struct sk_buff *skb; 1571a619a4c0SJuuso Oikarinen 1572a344d677SJohannes Berg skb = ieee80211_build_probe_req(sdata, src, dst, ratemask, channel, 15736b77863bSJohannes Berg ssid, ssid_len, 157485a237feSJohannes Berg ie, ie_len, directed); 1575aad14cebSRajkumar Manoharan if (skb) { 15761672c0e3SJohannes Berg IEEE80211_SKB_CB(skb)->flags |= tx_flags; 157755de908aSJohannes Berg if (scan) 157855de908aSJohannes Berg ieee80211_tx_skb_tid_band(sdata, skb, 7, channel->band); 157955de908aSJohannes Berg else 1580a619a4c0SJuuso Oikarinen ieee80211_tx_skb(sdata, skb); 158146900298SJohannes Berg } 1582aad14cebSRajkumar Manoharan } 158346900298SJohannes Berg 15842103dec1SSimon Wunderlich u32 ieee80211_sta_get_rates(struct ieee80211_sub_if_data *sdata, 158546900298SJohannes Berg struct ieee802_11_elems *elems, 158657fbcce3SJohannes Berg enum nl80211_band band, u32 *basic_rates) 158746900298SJohannes Berg { 158846900298SJohannes Berg struct ieee80211_supported_band *sband; 158946900298SJohannes Berg size_t num_rates; 15902103dec1SSimon Wunderlich u32 supp_rates, rate_flags; 15912103dec1SSimon Wunderlich int i, j, shift; 15922103dec1SSimon Wunderlich sband = sdata->local->hw.wiphy->bands[band]; 15932103dec1SSimon Wunderlich 15942103dec1SSimon Wunderlich rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef); 15952103dec1SSimon Wunderlich shift = ieee80211_vif_get_shift(&sdata->vif); 159646900298SJohannes Berg 15974ee73f33SMichal Kazior if (WARN_ON(!sband)) 15984ee73f33SMichal Kazior return 1; 159946900298SJohannes Berg 160046900298SJohannes Berg num_rates = sband->n_bitrates; 160146900298SJohannes Berg supp_rates = 0; 160246900298SJohannes Berg for (i = 0; i < elems->supp_rates_len + 160346900298SJohannes Berg elems->ext_supp_rates_len; i++) { 160446900298SJohannes Berg u8 rate = 0; 160546900298SJohannes Berg int own_rate; 16069ebb61a2SAshok Nagarajan bool is_basic; 160746900298SJohannes Berg if (i < elems->supp_rates_len) 160846900298SJohannes Berg rate = elems->supp_rates[i]; 160946900298SJohannes Berg else if (elems->ext_supp_rates) 161046900298SJohannes Berg rate = elems->ext_supp_rates 161146900298SJohannes Berg [i - elems->supp_rates_len]; 161246900298SJohannes Berg own_rate = 5 * (rate & 0x7f); 16139ebb61a2SAshok Nagarajan is_basic = !!(rate & 0x80); 16149ebb61a2SAshok Nagarajan 16159ebb61a2SAshok Nagarajan if (is_basic && (rate & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY) 16169ebb61a2SAshok Nagarajan continue; 16179ebb61a2SAshok Nagarajan 16189ebb61a2SAshok Nagarajan for (j = 0; j < num_rates; j++) { 16192103dec1SSimon Wunderlich int brate; 16202103dec1SSimon Wunderlich if ((rate_flags & sband->bitrates[j].flags) 16212103dec1SSimon Wunderlich != rate_flags) 16222103dec1SSimon Wunderlich continue; 16232103dec1SSimon Wunderlich 16242103dec1SSimon Wunderlich brate = DIV_ROUND_UP(sband->bitrates[j].bitrate, 16252103dec1SSimon Wunderlich 1 << shift); 16262103dec1SSimon Wunderlich 16272103dec1SSimon Wunderlich if (brate == own_rate) { 162846900298SJohannes Berg supp_rates |= BIT(j); 16299ebb61a2SAshok Nagarajan if (basic_rates && is_basic) 16309ebb61a2SAshok Nagarajan *basic_rates |= BIT(j); 16319ebb61a2SAshok Nagarajan } 16329ebb61a2SAshok Nagarajan } 163346900298SJohannes Berg } 163446900298SJohannes Berg return supp_rates; 163546900298SJohannes Berg } 1636f2753ddbSJohannes Berg 163784f6a01cSJohannes Berg void ieee80211_stop_device(struct ieee80211_local *local) 163884f6a01cSJohannes Berg { 163984f6a01cSJohannes Berg ieee80211_led_radio(local, false); 164067408c8cSJohannes Berg ieee80211_mod_tpt_led_trig(local, 0, IEEE80211_TPT_LEDTRIG_FL_RADIO); 164184f6a01cSJohannes Berg 164284f6a01cSJohannes Berg cancel_work_sync(&local->reconfig_filter); 164384f6a01cSJohannes Berg 164484f6a01cSJohannes Berg flush_workqueue(local->workqueue); 1645678f415fSLennert Buytenhek drv_stop(local); 164684f6a01cSJohannes Berg } 164784f6a01cSJohannes Berg 164874430f94SJohannes Berg static void ieee80211_flush_completed_scan(struct ieee80211_local *local, 164974430f94SJohannes Berg bool aborted) 165074430f94SJohannes Berg { 165174430f94SJohannes Berg /* It's possible that we don't handle the scan completion in 165274430f94SJohannes Berg * time during suspend, so if it's still marked as completed 165374430f94SJohannes Berg * here, queue the work and flush it to clean things up. 165474430f94SJohannes Berg * Instead of calling the worker function directly here, we 165574430f94SJohannes Berg * really queue it to avoid potential races with other flows 165674430f94SJohannes Berg * scheduling the same work. 165774430f94SJohannes Berg */ 165874430f94SJohannes Berg if (test_bit(SCAN_COMPLETED, &local->scanning)) { 165974430f94SJohannes Berg /* If coming from reconfiguration failure, abort the scan so 166074430f94SJohannes Berg * we don't attempt to continue a partial HW scan - which is 166174430f94SJohannes Berg * possible otherwise if (e.g.) the 2.4 GHz portion was the 166274430f94SJohannes Berg * completed scan, and a 5 GHz portion is still pending. 166374430f94SJohannes Berg */ 166474430f94SJohannes Berg if (aborted) 166574430f94SJohannes Berg set_bit(SCAN_ABORTED, &local->scanning); 166674430f94SJohannes Berg ieee80211_queue_delayed_work(&local->hw, &local->scan_work, 0); 166774430f94SJohannes Berg flush_delayed_work(&local->scan_work); 166874430f94SJohannes Berg } 166974430f94SJohannes Berg } 167074430f94SJohannes Berg 1671f6837ba8SJohannes Berg static void ieee80211_handle_reconfig_failure(struct ieee80211_local *local) 1672f6837ba8SJohannes Berg { 1673f6837ba8SJohannes Berg struct ieee80211_sub_if_data *sdata; 1674f6837ba8SJohannes Berg struct ieee80211_chanctx *ctx; 1675f6837ba8SJohannes Berg 1676f6837ba8SJohannes Berg /* 1677f6837ba8SJohannes Berg * We get here if during resume the device can't be restarted properly. 1678f6837ba8SJohannes Berg * We might also get here if this happens during HW reset, which is a 1679f6837ba8SJohannes Berg * slightly different situation and we need to drop all connections in 1680f6837ba8SJohannes Berg * the latter case. 1681f6837ba8SJohannes Berg * 1682f6837ba8SJohannes Berg * Ask cfg80211 to turn off all interfaces, this will result in more 1683f6837ba8SJohannes Berg * warnings but at least we'll then get into a clean stopped state. 1684f6837ba8SJohannes Berg */ 1685f6837ba8SJohannes Berg 1686f6837ba8SJohannes Berg local->resuming = false; 1687f6837ba8SJohannes Berg local->suspended = false; 16887584f88fSEliad Peller local->in_reconfig = false; 1689f6837ba8SJohannes Berg 169074430f94SJohannes Berg ieee80211_flush_completed_scan(local, true); 169174430f94SJohannes Berg 1692f6837ba8SJohannes Berg /* scheduled scan clearly can't be running any more, but tell 1693f6837ba8SJohannes Berg * cfg80211 and clear local state 1694f6837ba8SJohannes Berg */ 1695f6837ba8SJohannes Berg ieee80211_sched_scan_end(local); 1696f6837ba8SJohannes Berg 1697f6837ba8SJohannes Berg list_for_each_entry(sdata, &local->interfaces, list) 1698f6837ba8SJohannes Berg sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER; 1699f6837ba8SJohannes Berg 1700f6837ba8SJohannes Berg /* Mark channel contexts as not being in the driver any more to avoid 1701f6837ba8SJohannes Berg * removing them from the driver during the shutdown process... 1702f6837ba8SJohannes Berg */ 1703f6837ba8SJohannes Berg mutex_lock(&local->chanctx_mtx); 1704f6837ba8SJohannes Berg list_for_each_entry(ctx, &local->chanctx_list, list) 1705f6837ba8SJohannes Berg ctx->driver_present = false; 1706f6837ba8SJohannes Berg mutex_unlock(&local->chanctx_mtx); 1707f6837ba8SJohannes Berg 1708f6837ba8SJohannes Berg cfg80211_shutdown_all_interfaces(local->hw.wiphy); 1709f6837ba8SJohannes Berg } 1710f6837ba8SJohannes Berg 1711153a5fc4SStanislaw Gruszka static void ieee80211_assign_chanctx(struct ieee80211_local *local, 1712153a5fc4SStanislaw Gruszka struct ieee80211_sub_if_data *sdata) 1713153a5fc4SStanislaw Gruszka { 1714153a5fc4SStanislaw Gruszka struct ieee80211_chanctx_conf *conf; 1715153a5fc4SStanislaw Gruszka struct ieee80211_chanctx *ctx; 1716153a5fc4SStanislaw Gruszka 1717153a5fc4SStanislaw Gruszka if (!local->use_chanctx) 1718153a5fc4SStanislaw Gruszka return; 1719153a5fc4SStanislaw Gruszka 1720153a5fc4SStanislaw Gruszka mutex_lock(&local->chanctx_mtx); 1721153a5fc4SStanislaw Gruszka conf = rcu_dereference_protected(sdata->vif.chanctx_conf, 1722153a5fc4SStanislaw Gruszka lockdep_is_held(&local->chanctx_mtx)); 1723153a5fc4SStanislaw Gruszka if (conf) { 1724153a5fc4SStanislaw Gruszka ctx = container_of(conf, struct ieee80211_chanctx, conf); 1725153a5fc4SStanislaw Gruszka drv_assign_vif_chanctx(local, sdata, ctx); 1726153a5fc4SStanislaw Gruszka } 1727153a5fc4SStanislaw Gruszka mutex_unlock(&local->chanctx_mtx); 1728153a5fc4SStanislaw Gruszka } 1729153a5fc4SStanislaw Gruszka 17301ea2c864SJohannes Berg static void ieee80211_reconfig_stations(struct ieee80211_sub_if_data *sdata) 17311ea2c864SJohannes Berg { 17321ea2c864SJohannes Berg struct ieee80211_local *local = sdata->local; 17331ea2c864SJohannes Berg struct sta_info *sta; 17341ea2c864SJohannes Berg 17351ea2c864SJohannes Berg /* add STAs back */ 17361ea2c864SJohannes Berg mutex_lock(&local->sta_mtx); 17371ea2c864SJohannes Berg list_for_each_entry(sta, &local->sta_list, list) { 17381ea2c864SJohannes Berg enum ieee80211_sta_state state; 17391ea2c864SJohannes Berg 17401ea2c864SJohannes Berg if (!sta->uploaded || sta->sdata != sdata) 17411ea2c864SJohannes Berg continue; 17421ea2c864SJohannes Berg 17431ea2c864SJohannes Berg for (state = IEEE80211_STA_NOTEXIST; 17441ea2c864SJohannes Berg state < sta->sta_state; state++) 17451ea2c864SJohannes Berg WARN_ON(drv_sta_state(local, sta->sdata, sta, state, 17461ea2c864SJohannes Berg state + 1)); 17471ea2c864SJohannes Berg } 17481ea2c864SJohannes Berg mutex_unlock(&local->sta_mtx); 17491ea2c864SJohannes Berg } 17501ea2c864SJohannes Berg 1751f2753ddbSJohannes Berg int ieee80211_reconfig(struct ieee80211_local *local) 1752f2753ddbSJohannes Berg { 1753f2753ddbSJohannes Berg struct ieee80211_hw *hw = &local->hw; 1754f2753ddbSJohannes Berg struct ieee80211_sub_if_data *sdata; 175555de908aSJohannes Berg struct ieee80211_chanctx *ctx; 1756f2753ddbSJohannes Berg struct sta_info *sta; 17572683d65bSEliad Peller int res, i; 1758d888130aSJohannes Berg bool reconfig_due_to_wowlan = false; 1759d43c6b6eSDavid Spinadel struct ieee80211_sub_if_data *sched_scan_sdata; 17606ea0a69cSJohannes Berg struct cfg80211_sched_scan_request *sched_scan_req; 1761d43c6b6eSDavid Spinadel bool sched_scan_stopped = false; 1762b0485e9fSEliad Peller bool suspended = local->suspended; 1763d888130aSJohannes Berg 17640f8b8245SEliad Peller /* nothing to do if HW shouldn't run */ 17650f8b8245SEliad Peller if (!local->open_count) 17660f8b8245SEliad Peller goto wake_up; 17670f8b8245SEliad Peller 17688f21b0adSJohannes Berg #ifdef CONFIG_PM 1769b0485e9fSEliad Peller if (suspended) 1770ceb99fe0SJohannes Berg local->resuming = true; 1771f2753ddbSJohannes Berg 1772eecc4800SJohannes Berg if (local->wowlan) { 1773b0485e9fSEliad Peller /* 1774b0485e9fSEliad Peller * In the wowlan case, both mac80211 and the device 1775b0485e9fSEliad Peller * are functional when the resume op is called, so 1776b0485e9fSEliad Peller * clear local->suspended so the device could operate 1777b0485e9fSEliad Peller * normally (e.g. pass rx frames). 1778b0485e9fSEliad Peller */ 1779b0485e9fSEliad Peller local->suspended = false; 1780eecc4800SJohannes Berg res = drv_resume(local); 178127b3eb9cSJohannes Berg local->wowlan = false; 1782eecc4800SJohannes Berg if (res < 0) { 1783eecc4800SJohannes Berg local->resuming = false; 1784eecc4800SJohannes Berg return res; 1785eecc4800SJohannes Berg } 1786eecc4800SJohannes Berg if (res == 0) 1787eecc4800SJohannes Berg goto wake_up; 1788eecc4800SJohannes Berg WARN_ON(res > 1); 1789eecc4800SJohannes Berg /* 1790eecc4800SJohannes Berg * res is 1, which means the driver requested 1791eecc4800SJohannes Berg * to go through a regular reset on wakeup. 1792b0485e9fSEliad Peller * restore local->suspended in this case. 1793eecc4800SJohannes Berg */ 1794d888130aSJohannes Berg reconfig_due_to_wowlan = true; 1795b0485e9fSEliad Peller local->suspended = true; 1796eecc4800SJohannes Berg } 1797eecc4800SJohannes Berg #endif 179894f9b97bSJohannes Berg 179924feda00SLuis R. Rodriguez /* 180043d6df00SEliad Peller * In case of hw_restart during suspend (without wowlan), 180143d6df00SEliad Peller * cancel restart work, as we are reconfiguring the device 180243d6df00SEliad Peller * anyway. 180343d6df00SEliad Peller * Note that restart_work is scheduled on a frozen workqueue, 180443d6df00SEliad Peller * so we can't deadlock in this case. 180543d6df00SEliad Peller */ 180643d6df00SEliad Peller if (suspended && local->in_reconfig && !reconfig_due_to_wowlan) 180743d6df00SEliad Peller cancel_work_sync(&local->restart_work); 180843d6df00SEliad Peller 1809968a76ceSEliad Peller local->started = false; 1810968a76ceSEliad Peller 181143d6df00SEliad Peller /* 181224feda00SLuis R. Rodriguez * Upon resume hardware can sometimes be goofy due to 181324feda00SLuis R. Rodriguez * various platform / driver / bus issues, so restarting 181424feda00SLuis R. Rodriguez * the device may at times not work immediately. Propagate 181524feda00SLuis R. Rodriguez * the error. 181624feda00SLuis R. Rodriguez */ 181724487981SJohannes Berg res = drv_start(local); 181824feda00SLuis R. Rodriguez if (res) { 1819b0485e9fSEliad Peller if (suspended) 1820f6837ba8SJohannes Berg WARN(1, "Hardware became unavailable upon resume. This could be a software issue prior to suspend or a hardware issue.\n"); 1821f6837ba8SJohannes Berg else 1822f6837ba8SJohannes Berg WARN(1, "Hardware became unavailable during restart.\n"); 1823f6837ba8SJohannes Berg ieee80211_handle_reconfig_failure(local); 182424feda00SLuis R. Rodriguez return res; 182524feda00SLuis R. Rodriguez } 1826f2753ddbSJohannes Berg 18277f281975SYogesh Ashok Powar /* setup fragmentation threshold */ 18287f281975SYogesh Ashok Powar drv_set_frag_threshold(local, hw->wiphy->frag_threshold); 18297f281975SYogesh Ashok Powar 18307f281975SYogesh Ashok Powar /* setup RTS threshold */ 18317f281975SYogesh Ashok Powar drv_set_rts_threshold(local, hw->wiphy->rts_threshold); 18327f281975SYogesh Ashok Powar 18337f281975SYogesh Ashok Powar /* reset coverage class */ 18347f281975SYogesh Ashok Powar drv_set_coverage_class(local, hw->wiphy->coverage_class); 18357f281975SYogesh Ashok Powar 18361f87f7d3SJohannes Berg ieee80211_led_radio(local, true); 183767408c8cSJohannes Berg ieee80211_mod_tpt_led_trig(local, 183867408c8cSJohannes Berg IEEE80211_TPT_LEDTRIG_FL_RADIO, 0); 1839f2753ddbSJohannes Berg 1840f2753ddbSJohannes Berg /* add interfaces */ 18414b6f1dd6SJohannes Berg sdata = rtnl_dereference(local->monitor_sdata); 18424b6f1dd6SJohannes Berg if (sdata) { 18433c3e21e7SJohannes Berg /* in HW restart it exists already */ 18443c3e21e7SJohannes Berg WARN_ON(local->resuming); 18454b6f1dd6SJohannes Berg res = drv_add_interface(local, sdata); 18464b6f1dd6SJohannes Berg if (WARN_ON(res)) { 18470c2bef46SMonam Agarwal RCU_INIT_POINTER(local->monitor_sdata, NULL); 18484b6f1dd6SJohannes Berg synchronize_net(); 18494b6f1dd6SJohannes Berg kfree(sdata); 18504b6f1dd6SJohannes Berg } 18514b6f1dd6SJohannes Berg } 18524b6f1dd6SJohannes Berg 1853f2753ddbSJohannes Berg list_for_each_entry(sdata, &local->interfaces, list) { 1854f2753ddbSJohannes Berg if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && 1855f2753ddbSJohannes Berg sdata->vif.type != NL80211_IFTYPE_MONITOR && 1856c8fff3dcSLuciano Coelho ieee80211_sdata_running(sdata)) { 18577b7eab6fSJohannes Berg res = drv_add_interface(local, sdata); 1858c8fff3dcSLuciano Coelho if (WARN_ON(res)) 1859c8fff3dcSLuciano Coelho break; 1860c8fff3dcSLuciano Coelho } 1861c8fff3dcSLuciano Coelho } 1862c8fff3dcSLuciano Coelho 1863c8fff3dcSLuciano Coelho /* If adding any of the interfaces failed above, roll back and 1864c8fff3dcSLuciano Coelho * report failure. 1865c8fff3dcSLuciano Coelho */ 1866c8fff3dcSLuciano Coelho if (res) { 1867c8fff3dcSLuciano Coelho list_for_each_entry_continue_reverse(sdata, &local->interfaces, 1868c8fff3dcSLuciano Coelho list) 1869c8fff3dcSLuciano Coelho if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN && 1870c8fff3dcSLuciano Coelho sdata->vif.type != NL80211_IFTYPE_MONITOR && 1871c8fff3dcSLuciano Coelho ieee80211_sdata_running(sdata)) 1872c8fff3dcSLuciano Coelho drv_remove_interface(local, sdata); 1873c8fff3dcSLuciano Coelho ieee80211_handle_reconfig_failure(local); 1874c8fff3dcSLuciano Coelho return res; 1875f2753ddbSJohannes Berg } 1876f2753ddbSJohannes Berg 187755de908aSJohannes Berg /* add channel contexts */ 1878f0dea9c7SArend van Spriel if (local->use_chanctx) { 187955de908aSJohannes Berg mutex_lock(&local->chanctx_mtx); 188055de908aSJohannes Berg list_for_each_entry(ctx, &local->chanctx_list, list) 18815bcae31dSMichal Kazior if (ctx->replace_state != 18825bcae31dSMichal Kazior IEEE80211_CHANCTX_REPLACES_OTHER) 188355de908aSJohannes Berg WARN_ON(drv_add_chanctx(local, ctx)); 188455de908aSJohannes Berg mutex_unlock(&local->chanctx_mtx); 188555de908aSJohannes Berg 1886fe5f2559SJohannes Berg sdata = rtnl_dereference(local->monitor_sdata); 1887153a5fc4SStanislaw Gruszka if (sdata && ieee80211_sdata_running(sdata)) 1888153a5fc4SStanislaw Gruszka ieee80211_assign_chanctx(local, sdata); 18897df180f7SZhao, Gang } 1890fe5f2559SJohannes Berg 1891f2753ddbSJohannes Berg /* reconfigure hardware */ 1892f2753ddbSJohannes Berg ieee80211_hw_config(local, ~0); 1893f2753ddbSJohannes Berg 1894f2753ddbSJohannes Berg ieee80211_configure_filter(local); 1895f2753ddbSJohannes Berg 1896f2753ddbSJohannes Berg /* Finally also reconfigure all the BSS information */ 1897f2753ddbSJohannes Berg list_for_each_entry(sdata, &local->interfaces, list) { 1898ac8dd506SJohannes Berg u32 changed; 1899ac8dd506SJohannes Berg 19009607e6b6SJohannes Berg if (!ieee80211_sdata_running(sdata)) 1901f2753ddbSJohannes Berg continue; 1902ac8dd506SJohannes Berg 19031ea2c864SJohannes Berg ieee80211_assign_chanctx(local, sdata); 19041ea2c864SJohannes Berg 19051ea2c864SJohannes Berg switch (sdata->vif.type) { 19061ea2c864SJohannes Berg case NL80211_IFTYPE_AP_VLAN: 19071ea2c864SJohannes Berg case NL80211_IFTYPE_MONITOR: 19081ea2c864SJohannes Berg break; 19091ea2c864SJohannes Berg default: 19101ea2c864SJohannes Berg ieee80211_reconfig_stations(sdata); 19111ea2c864SJohannes Berg /* fall through */ 19121ea2c864SJohannes Berg case NL80211_IFTYPE_AP: /* AP stations are handled later */ 19131ea2c864SJohannes Berg for (i = 0; i < IEEE80211_NUM_ACS; i++) 19141ea2c864SJohannes Berg drv_conf_tx(local, sdata, i, 19151ea2c864SJohannes Berg &sdata->tx_conf[i]); 19161ea2c864SJohannes Berg break; 19171ea2c864SJohannes Berg } 19181ea2c864SJohannes Berg 1919ac8dd506SJohannes Berg /* common change flags for all interface types */ 1920ac8dd506SJohannes Berg changed = BSS_CHANGED_ERP_CTS_PROT | 1921ac8dd506SJohannes Berg BSS_CHANGED_ERP_PREAMBLE | 1922ac8dd506SJohannes Berg BSS_CHANGED_ERP_SLOT | 1923ac8dd506SJohannes Berg BSS_CHANGED_HT | 1924ac8dd506SJohannes Berg BSS_CHANGED_BASIC_RATES | 1925ac8dd506SJohannes Berg BSS_CHANGED_BEACON_INT | 1926ac8dd506SJohannes Berg BSS_CHANGED_BSSID | 19274ced3f74SJohannes Berg BSS_CHANGED_CQM | 192855de47f6SEliad Peller BSS_CHANGED_QOS | 19291ea6f9c0SJohannes Berg BSS_CHANGED_IDLE | 19301ea6f9c0SJohannes Berg BSS_CHANGED_TXPOWER; 1931ac8dd506SJohannes Berg 1932b5a33d52SSara Sharon if (sdata->vif.mu_mimo_owner) 193323a1f8d4SSara Sharon changed |= BSS_CHANGED_MU_GROUPS; 193423a1f8d4SSara Sharon 1935f2753ddbSJohannes Berg switch (sdata->vif.type) { 1936f2753ddbSJohannes Berg case NL80211_IFTYPE_STATION: 19370d392e93SEliad Peller changed |= BSS_CHANGED_ASSOC | 1938ab095877SEliad Peller BSS_CHANGED_ARP_FILTER | 1939ab095877SEliad Peller BSS_CHANGED_PS; 1940c65dd147SEmmanuel Grumbach 1941989c6505SAlexander Bondar /* Re-send beacon info report to the driver */ 1942989c6505SAlexander Bondar if (sdata->u.mgd.have_beacon) 1943989c6505SAlexander Bondar changed |= BSS_CHANGED_BEACON_INFO; 1944c65dd147SEmmanuel Grumbach 19458d61ffa5SJohannes Berg sdata_lock(sdata); 1946ac8dd506SJohannes Berg ieee80211_bss_info_change_notify(sdata, changed); 19478d61ffa5SJohannes Berg sdata_unlock(sdata); 1948ac8dd506SJohannes Berg break; 19496e0bd6c3SRostislav Lisovy case NL80211_IFTYPE_OCB: 1950239281f8SRostislav Lisovy changed |= BSS_CHANGED_OCB; 1951239281f8SRostislav Lisovy ieee80211_bss_info_change_notify(sdata, changed); 19526e0bd6c3SRostislav Lisovy break; 1953f2753ddbSJohannes Berg case NL80211_IFTYPE_ADHOC: 1954ac8dd506SJohannes Berg changed |= BSS_CHANGED_IBSS; 1955ac8dd506SJohannes Berg /* fall through */ 1956f2753ddbSJohannes Berg case NL80211_IFTYPE_AP: 1957339afbf4SJohannes Berg changed |= BSS_CHANGED_SSID | BSS_CHANGED_P2P_PS; 1958e7979ac7SArik Nemtsov 19591041638fSJohannes Berg if (sdata->vif.type == NL80211_IFTYPE_AP) { 1960e7979ac7SArik Nemtsov changed |= BSS_CHANGED_AP_PROBE_RESP; 1961e7979ac7SArik Nemtsov 19621041638fSJohannes Berg if (rcu_access_pointer(sdata->u.ap.beacon)) 19631041638fSJohannes Berg drv_start_ap(local, sdata); 19641041638fSJohannes Berg } 19651041638fSJohannes Berg 19667827493bSArik Nemtsov /* fall through */ 1967f2753ddbSJohannes Berg case NL80211_IFTYPE_MESH_POINT: 19688da34932SJohannes Berg if (sdata->vif.bss_conf.enable_beacon) { 1969ac8dd506SJohannes Berg changed |= BSS_CHANGED_BEACON | 1970ac8dd506SJohannes Berg BSS_CHANGED_BEACON_ENABLED; 19712d0ddec5SJohannes Berg ieee80211_bss_info_change_notify(sdata, changed); 19728da34932SJohannes Berg } 1973f2753ddbSJohannes Berg break; 1974f2753ddbSJohannes Berg case NL80211_IFTYPE_WDS: 1975f2753ddbSJohannes Berg case NL80211_IFTYPE_AP_VLAN: 1976f2753ddbSJohannes Berg case NL80211_IFTYPE_MONITOR: 197798104fdeSJohannes Berg case NL80211_IFTYPE_P2P_DEVICE: 1978b205786eSZhao, Gang /* nothing to do */ 1979f142c6b9SJohannes Berg break; 1980f2753ddbSJohannes Berg case NL80211_IFTYPE_UNSPECIFIED: 19812e161f78SJohannes Berg case NUM_NL80211_IFTYPES: 19822ca27bcfSJohannes Berg case NL80211_IFTYPE_P2P_CLIENT: 19832ca27bcfSJohannes Berg case NL80211_IFTYPE_P2P_GO: 1984f2753ddbSJohannes Berg WARN_ON(1); 1985f2753ddbSJohannes Berg break; 1986f2753ddbSJohannes Berg } 1987f2753ddbSJohannes Berg } 1988f2753ddbSJohannes Berg 19894a733ef1SJohannes Berg ieee80211_recalc_ps(local); 19908e1b23b9SEyal Shapira 19912a419056SJohannes Berg /* 19926e1b1b24SEliad Peller * The sta might be in psm against the ap (e.g. because 19936e1b1b24SEliad Peller * this was the state before a hw restart), so we 19946e1b1b24SEliad Peller * explicitly send a null packet in order to make sure 19956e1b1b24SEliad Peller * it'll sync against the ap (and get out of psm). 19966e1b1b24SEliad Peller */ 19976e1b1b24SEliad Peller if (!(local->hw.conf.flags & IEEE80211_CONF_PS)) { 19986e1b1b24SEliad Peller list_for_each_entry(sdata, &local->interfaces, list) { 19996e1b1b24SEliad Peller if (sdata->vif.type != NL80211_IFTYPE_STATION) 20006e1b1b24SEliad Peller continue; 200120f544eeSJohannes Berg if (!sdata->u.mgd.associated) 200220f544eeSJohannes Berg continue; 20036e1b1b24SEliad Peller 2004076cdcb1SJohannes Berg ieee80211_send_nullfunc(local, sdata, false); 20056e1b1b24SEliad Peller } 20066e1b1b24SEliad Peller } 20076e1b1b24SEliad Peller 20082e8d397eSArik Nemtsov /* APs are now beaconing, add back stations */ 20092e8d397eSArik Nemtsov mutex_lock(&local->sta_mtx); 20102e8d397eSArik Nemtsov list_for_each_entry(sta, &local->sta_list, list) { 20112e8d397eSArik Nemtsov enum ieee80211_sta_state state; 20122e8d397eSArik Nemtsov 20132e8d397eSArik Nemtsov if (!sta->uploaded) 20142e8d397eSArik Nemtsov continue; 20152e8d397eSArik Nemtsov 20162e8d397eSArik Nemtsov if (sta->sdata->vif.type != NL80211_IFTYPE_AP) 20172e8d397eSArik Nemtsov continue; 20182e8d397eSArik Nemtsov 20192e8d397eSArik Nemtsov for (state = IEEE80211_STA_NOTEXIST; 20202e8d397eSArik Nemtsov state < sta->sta_state; state++) 20212e8d397eSArik Nemtsov WARN_ON(drv_sta_state(local, sta->sdata, sta, state, 20222e8d397eSArik Nemtsov state + 1)); 20232e8d397eSArik Nemtsov } 20242e8d397eSArik Nemtsov mutex_unlock(&local->sta_mtx); 20252e8d397eSArik Nemtsov 20267b21aea0SEyal Shapira /* add back keys */ 20277b21aea0SEyal Shapira list_for_each_entry(sdata, &local->interfaces, list) 2028f9dca80bSMichal Kazior ieee80211_reset_crypto_tx_tailroom(sdata); 2029f9dca80bSMichal Kazior 2030f9dca80bSMichal Kazior list_for_each_entry(sdata, &local->interfaces, list) 20317b21aea0SEyal Shapira if (ieee80211_sdata_running(sdata)) 20327b21aea0SEyal Shapira ieee80211_enable_keys(sdata); 20337b21aea0SEyal Shapira 20340d440ea2SEliad Peller /* Reconfigure sched scan if it was interrupted by FW restart */ 20350d440ea2SEliad Peller mutex_lock(&local->mtx); 20360d440ea2SEliad Peller sched_scan_sdata = rcu_dereference_protected(local->sched_scan_sdata, 20370d440ea2SEliad Peller lockdep_is_held(&local->mtx)); 20380d440ea2SEliad Peller sched_scan_req = rcu_dereference_protected(local->sched_scan_req, 20390d440ea2SEliad Peller lockdep_is_held(&local->mtx)); 20400d440ea2SEliad Peller if (sched_scan_sdata && sched_scan_req) 20410d440ea2SEliad Peller /* 20420d440ea2SEliad Peller * Sched scan stopped, but we don't want to report it. Instead, 20430d440ea2SEliad Peller * we're trying to reschedule. However, if more than one scan 20440d440ea2SEliad Peller * plan was set, we cannot reschedule since we don't know which 20450d440ea2SEliad Peller * scan plan was currently running (and some scan plans may have 20460d440ea2SEliad Peller * already finished). 20470d440ea2SEliad Peller */ 20480d440ea2SEliad Peller if (sched_scan_req->n_scan_plans > 1 || 20490d440ea2SEliad Peller __ieee80211_request_sched_scan_start(sched_scan_sdata, 2050b9f628fcSEliad Peller sched_scan_req)) { 2051b9f628fcSEliad Peller RCU_INIT_POINTER(local->sched_scan_sdata, NULL); 2052b9f628fcSEliad Peller RCU_INIT_POINTER(local->sched_scan_req, NULL); 20530d440ea2SEliad Peller sched_scan_stopped = true; 2054b9f628fcSEliad Peller } 20550d440ea2SEliad Peller mutex_unlock(&local->mtx); 20560d440ea2SEliad Peller 20570d440ea2SEliad Peller if (sched_scan_stopped) 20580d440ea2SEliad Peller cfg80211_sched_scan_stopped_rtnl(local->hw.wiphy); 20590d440ea2SEliad Peller 2060c6209488SEliad Peller wake_up: 2061470f4d61SEliad Peller if (local->in_reconfig) { 206204800adaSArik Nemtsov local->in_reconfig = false; 206304800adaSArik Nemtsov barrier(); 206404800adaSArik Nemtsov 2065470f4d61SEliad Peller /* Restart deferred ROCs */ 2066470f4d61SEliad Peller mutex_lock(&local->mtx); 2067470f4d61SEliad Peller ieee80211_start_next_roc(local); 2068470f4d61SEliad Peller mutex_unlock(&local->mtx); 2069470f4d61SEliad Peller } 2070470f4d61SEliad Peller 20713c3e21e7SJohannes Berg if (local->monitors == local->open_count && local->monitors > 0) 20723c3e21e7SJohannes Berg ieee80211_add_virtual_monitor(local); 20733c3e21e7SJohannes Berg 20746e1b1b24SEliad Peller /* 20752a419056SJohannes Berg * Clear the WLAN_STA_BLOCK_BA flag so new aggregation 20762a419056SJohannes Berg * sessions can be established after a resume. 20772a419056SJohannes Berg * 20782a419056SJohannes Berg * Also tear down aggregation sessions since reconfiguring 20792a419056SJohannes Berg * them in a hardware restart scenario is not easily done 20802a419056SJohannes Berg * right now, and the hardware will have lost information 20812a419056SJohannes Berg * about the sessions, but we and the AP still think they 20822a419056SJohannes Berg * are active. This is really a workaround though. 20832a419056SJohannes Berg */ 208430686bf7SJohannes Berg if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) { 20852a419056SJohannes Berg mutex_lock(&local->sta_mtx); 20862a419056SJohannes Berg 20872a419056SJohannes Berg list_for_each_entry(sta, &local->sta_list, list) { 208827392719SEliad Peller if (!local->resuming) 2089c82c4a80SJohannes Berg ieee80211_sta_tear_down_BA_sessions( 2090c82c4a80SJohannes Berg sta, AGG_STOP_LOCAL_REQUEST); 2091c2c98fdeSJohannes Berg clear_sta_flag(sta, WLAN_STA_BLOCK_BA); 209274e2bd1fSWey-Yi Guy } 20932a419056SJohannes Berg 20942a419056SJohannes Berg mutex_unlock(&local->sta_mtx); 209574e2bd1fSWey-Yi Guy } 209674e2bd1fSWey-Yi Guy 2097445ea4e8SJohannes Berg ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP, 2098cca07b00SLuciano Coelho IEEE80211_QUEUE_STOP_REASON_SUSPEND, 2099cca07b00SLuciano Coelho false); 2100f2753ddbSJohannes Berg 21015bb644a0SJohannes Berg /* 21025bb644a0SJohannes Berg * If this is for hw restart things are still running. 21035bb644a0SJohannes Berg * We may want to change that later, however. 21045bb644a0SJohannes Berg */ 2105b0485e9fSEliad Peller if (local->open_count && (!suspended || reconfig_due_to_wowlan)) 2106cf2c92d8SEliad Peller drv_reconfig_complete(local, IEEE80211_RECONFIG_TYPE_RESTART); 21078f21b0adSJohannes Berg 2108b0485e9fSEliad Peller if (!suspended) 21095bb644a0SJohannes Berg return 0; 21105bb644a0SJohannes Berg 21115bb644a0SJohannes Berg #ifdef CONFIG_PM 2112ceb99fe0SJohannes Berg /* first set suspended false, then resuming */ 21135bb644a0SJohannes Berg local->suspended = false; 2114ceb99fe0SJohannes Berg mb(); 2115ceb99fe0SJohannes Berg local->resuming = false; 21165bb644a0SJohannes Berg 211774430f94SJohannes Berg ieee80211_flush_completed_scan(local, false); 21189120d94eSLuciano Coelho 21190f8b8245SEliad Peller if (local->open_count && !reconfig_due_to_wowlan) 2120cf2c92d8SEliad Peller drv_reconfig_complete(local, IEEE80211_RECONFIG_TYPE_SUSPEND); 2121cf2c92d8SEliad Peller 2122b8360ab8SJohannes Berg list_for_each_entry(sdata, &local->interfaces, list) { 2123b8360ab8SJohannes Berg if (!ieee80211_sdata_running(sdata)) 2124b8360ab8SJohannes Berg continue; 2125b8360ab8SJohannes Berg if (sdata->vif.type == NL80211_IFTYPE_STATION) 2126b8360ab8SJohannes Berg ieee80211_sta_restart(sdata); 2127b8360ab8SJohannes Berg } 2128b8360ab8SJohannes Berg 212926d59535SJohannes Berg mod_timer(&local->sta_cleanup, jiffies + 1); 21305bb644a0SJohannes Berg #else 21315bb644a0SJohannes Berg WARN_ON(1); 21325bb644a0SJohannes Berg #endif 2133d43c6b6eSDavid Spinadel 2134f2753ddbSJohannes Berg return 0; 2135f2753ddbSJohannes Berg } 213642935ecaSLuis R. Rodriguez 213795acac61SJohannes Berg void ieee80211_resume_disconnect(struct ieee80211_vif *vif) 213895acac61SJohannes Berg { 213995acac61SJohannes Berg struct ieee80211_sub_if_data *sdata; 214095acac61SJohannes Berg struct ieee80211_local *local; 214195acac61SJohannes Berg struct ieee80211_key *key; 214295acac61SJohannes Berg 214395acac61SJohannes Berg if (WARN_ON(!vif)) 214495acac61SJohannes Berg return; 214595acac61SJohannes Berg 214695acac61SJohannes Berg sdata = vif_to_sdata(vif); 214795acac61SJohannes Berg local = sdata->local; 214895acac61SJohannes Berg 214995acac61SJohannes Berg if (WARN_ON(!local->resuming)) 215095acac61SJohannes Berg return; 215195acac61SJohannes Berg 215295acac61SJohannes Berg if (WARN_ON(vif->type != NL80211_IFTYPE_STATION)) 215395acac61SJohannes Berg return; 215495acac61SJohannes Berg 215595acac61SJohannes Berg sdata->flags |= IEEE80211_SDATA_DISCONNECT_RESUME; 215695acac61SJohannes Berg 215795acac61SJohannes Berg mutex_lock(&local->key_mtx); 215895acac61SJohannes Berg list_for_each_entry(key, &sdata->key_list, list) 215995acac61SJohannes Berg key->flags |= KEY_FLAG_TAINTED; 216095acac61SJohannes Berg mutex_unlock(&local->key_mtx); 216195acac61SJohannes Berg } 216295acac61SJohannes Berg EXPORT_SYMBOL_GPL(ieee80211_resume_disconnect); 216395acac61SJohannes Berg 216404ecd257SJohannes Berg void ieee80211_recalc_smps(struct ieee80211_sub_if_data *sdata) 21650f78231bSJohannes Berg { 216604ecd257SJohannes Berg struct ieee80211_local *local = sdata->local; 216704ecd257SJohannes Berg struct ieee80211_chanctx_conf *chanctx_conf; 216804ecd257SJohannes Berg struct ieee80211_chanctx *chanctx; 21690f78231bSJohannes Berg 217004ecd257SJohannes Berg mutex_lock(&local->chanctx_mtx); 21710f78231bSJohannes Berg 217204ecd257SJohannes Berg chanctx_conf = rcu_dereference_protected(sdata->vif.chanctx_conf, 217304ecd257SJohannes Berg lockdep_is_held(&local->chanctx_mtx)); 21740f78231bSJohannes Berg 2175c189a685SAndrei Otcheretianski /* 2176c189a685SAndrei Otcheretianski * This function can be called from a work, thus it may be possible 2177c189a685SAndrei Otcheretianski * that the chanctx_conf is removed (due to a disconnection, for 2178c189a685SAndrei Otcheretianski * example). 2179c189a685SAndrei Otcheretianski * So nothing should be done in such case. 2180c189a685SAndrei Otcheretianski */ 2181c189a685SAndrei Otcheretianski if (!chanctx_conf) 21825d8e4237SJohannes Berg goto unlock; 21830f78231bSJohannes Berg 218404ecd257SJohannes Berg chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf); 218504ecd257SJohannes Berg ieee80211_recalc_smps_chanctx(local, chanctx); 21865d8e4237SJohannes Berg unlock: 218704ecd257SJohannes Berg mutex_unlock(&local->chanctx_mtx); 21880f78231bSJohannes Berg } 21898e664fb3SJohannes Berg 219021f659bfSEliad Peller void ieee80211_recalc_min_chandef(struct ieee80211_sub_if_data *sdata) 219121f659bfSEliad Peller { 219221f659bfSEliad Peller struct ieee80211_local *local = sdata->local; 219321f659bfSEliad Peller struct ieee80211_chanctx_conf *chanctx_conf; 219421f659bfSEliad Peller struct ieee80211_chanctx *chanctx; 219521f659bfSEliad Peller 219621f659bfSEliad Peller mutex_lock(&local->chanctx_mtx); 219721f659bfSEliad Peller 219821f659bfSEliad Peller chanctx_conf = rcu_dereference_protected(sdata->vif.chanctx_conf, 219921f659bfSEliad Peller lockdep_is_held(&local->chanctx_mtx)); 220021f659bfSEliad Peller 220121f659bfSEliad Peller if (WARN_ON_ONCE(!chanctx_conf)) 220221f659bfSEliad Peller goto unlock; 220321f659bfSEliad Peller 220421f659bfSEliad Peller chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf); 220521f659bfSEliad Peller ieee80211_recalc_chanctx_min_def(local, chanctx); 220621f659bfSEliad Peller unlock: 220721f659bfSEliad Peller mutex_unlock(&local->chanctx_mtx); 220821f659bfSEliad Peller } 220921f659bfSEliad Peller 22108e664fb3SJohannes Berg size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset) 22118e664fb3SJohannes Berg { 22128e664fb3SJohannes Berg size_t pos = offset; 22138e664fb3SJohannes Berg 22148e664fb3SJohannes Berg while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC) 22158e664fb3SJohannes Berg pos += 2 + ies[pos + 1]; 22168e664fb3SJohannes Berg 22178e664fb3SJohannes Berg return pos; 22188e664fb3SJohannes Berg } 2219615f7b9bSMeenakshi Venkataraman 2220615f7b9bSMeenakshi Venkataraman static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata, 2221615f7b9bSMeenakshi Venkataraman int rssi_min_thold, 2222615f7b9bSMeenakshi Venkataraman int rssi_max_thold) 2223615f7b9bSMeenakshi Venkataraman { 2224615f7b9bSMeenakshi Venkataraman trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold); 2225615f7b9bSMeenakshi Venkataraman 2226615f7b9bSMeenakshi Venkataraman if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION)) 2227615f7b9bSMeenakshi Venkataraman return; 2228615f7b9bSMeenakshi Venkataraman 2229615f7b9bSMeenakshi Venkataraman /* 2230615f7b9bSMeenakshi Venkataraman * Scale up threshold values before storing it, as the RSSI averaging 2231615f7b9bSMeenakshi Venkataraman * algorithm uses a scaled up value as well. Change this scaling 2232615f7b9bSMeenakshi Venkataraman * factor if the RSSI averaging algorithm changes. 2233615f7b9bSMeenakshi Venkataraman */ 2234615f7b9bSMeenakshi Venkataraman sdata->u.mgd.rssi_min_thold = rssi_min_thold*16; 2235615f7b9bSMeenakshi Venkataraman sdata->u.mgd.rssi_max_thold = rssi_max_thold*16; 2236615f7b9bSMeenakshi Venkataraman } 2237615f7b9bSMeenakshi Venkataraman 2238615f7b9bSMeenakshi Venkataraman void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif, 2239615f7b9bSMeenakshi Venkataraman int rssi_min_thold, 2240615f7b9bSMeenakshi Venkataraman int rssi_max_thold) 2241615f7b9bSMeenakshi Venkataraman { 2242615f7b9bSMeenakshi Venkataraman struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 2243615f7b9bSMeenakshi Venkataraman 2244615f7b9bSMeenakshi Venkataraman WARN_ON(rssi_min_thold == rssi_max_thold || 2245615f7b9bSMeenakshi Venkataraman rssi_min_thold > rssi_max_thold); 2246615f7b9bSMeenakshi Venkataraman 2247615f7b9bSMeenakshi Venkataraman _ieee80211_enable_rssi_reports(sdata, rssi_min_thold, 2248615f7b9bSMeenakshi Venkataraman rssi_max_thold); 2249615f7b9bSMeenakshi Venkataraman } 2250615f7b9bSMeenakshi Venkataraman EXPORT_SYMBOL(ieee80211_enable_rssi_reports); 2251615f7b9bSMeenakshi Venkataraman 2252615f7b9bSMeenakshi Venkataraman void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif) 2253615f7b9bSMeenakshi Venkataraman { 2254615f7b9bSMeenakshi Venkataraman struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 2255615f7b9bSMeenakshi Venkataraman 2256615f7b9bSMeenakshi Venkataraman _ieee80211_enable_rssi_reports(sdata, 0, 0); 2257615f7b9bSMeenakshi Venkataraman } 2258615f7b9bSMeenakshi Venkataraman EXPORT_SYMBOL(ieee80211_disable_rssi_reports); 2259768db343SArik Nemtsov 2260ef96a842SBen Greear u8 *ieee80211_ie_build_ht_cap(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap, 226142e7aa77SAlexander Simon u16 cap) 226242e7aa77SAlexander Simon { 226342e7aa77SAlexander Simon __le16 tmp; 226442e7aa77SAlexander Simon 226542e7aa77SAlexander Simon *pos++ = WLAN_EID_HT_CAPABILITY; 226642e7aa77SAlexander Simon *pos++ = sizeof(struct ieee80211_ht_cap); 226742e7aa77SAlexander Simon memset(pos, 0, sizeof(struct ieee80211_ht_cap)); 226842e7aa77SAlexander Simon 226942e7aa77SAlexander Simon /* capability flags */ 227042e7aa77SAlexander Simon tmp = cpu_to_le16(cap); 227142e7aa77SAlexander Simon memcpy(pos, &tmp, sizeof(u16)); 227242e7aa77SAlexander Simon pos += sizeof(u16); 227342e7aa77SAlexander Simon 227442e7aa77SAlexander Simon /* AMPDU parameters */ 2275ef96a842SBen Greear *pos++ = ht_cap->ampdu_factor | 2276ef96a842SBen Greear (ht_cap->ampdu_density << 227742e7aa77SAlexander Simon IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT); 227842e7aa77SAlexander Simon 227942e7aa77SAlexander Simon /* MCS set */ 2280ef96a842SBen Greear memcpy(pos, &ht_cap->mcs, sizeof(ht_cap->mcs)); 2281ef96a842SBen Greear pos += sizeof(ht_cap->mcs); 228242e7aa77SAlexander Simon 228342e7aa77SAlexander Simon /* extended capabilities */ 228442e7aa77SAlexander Simon pos += sizeof(__le16); 228542e7aa77SAlexander Simon 228642e7aa77SAlexander Simon /* BF capabilities */ 228742e7aa77SAlexander Simon pos += sizeof(__le32); 228842e7aa77SAlexander Simon 228942e7aa77SAlexander Simon /* antenna selection */ 229042e7aa77SAlexander Simon pos += sizeof(u8); 229142e7aa77SAlexander Simon 229242e7aa77SAlexander Simon return pos; 229342e7aa77SAlexander Simon } 229442e7aa77SAlexander Simon 2295ba0afa2fSMahesh Palivela u8 *ieee80211_ie_build_vht_cap(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap, 2296ba0afa2fSMahesh Palivela u32 cap) 2297ba0afa2fSMahesh Palivela { 2298ba0afa2fSMahesh Palivela __le32 tmp; 2299ba0afa2fSMahesh Palivela 2300ba0afa2fSMahesh Palivela *pos++ = WLAN_EID_VHT_CAPABILITY; 2301d4950281SMahesh Palivela *pos++ = sizeof(struct ieee80211_vht_cap); 2302d4950281SMahesh Palivela memset(pos, 0, sizeof(struct ieee80211_vht_cap)); 2303ba0afa2fSMahesh Palivela 2304ba0afa2fSMahesh Palivela /* capability flags */ 2305ba0afa2fSMahesh Palivela tmp = cpu_to_le32(cap); 2306ba0afa2fSMahesh Palivela memcpy(pos, &tmp, sizeof(u32)); 2307ba0afa2fSMahesh Palivela pos += sizeof(u32); 2308ba0afa2fSMahesh Palivela 2309ba0afa2fSMahesh Palivela /* VHT MCS set */ 2310ba0afa2fSMahesh Palivela memcpy(pos, &vht_cap->vht_mcs, sizeof(vht_cap->vht_mcs)); 2311ba0afa2fSMahesh Palivela pos += sizeof(vht_cap->vht_mcs); 2312ba0afa2fSMahesh Palivela 2313ba0afa2fSMahesh Palivela return pos; 2314ba0afa2fSMahesh Palivela } 2315ba0afa2fSMahesh Palivela 2316074d46d1SJohannes Berg u8 *ieee80211_ie_build_ht_oper(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap, 23174bf88530SJohannes Berg const struct cfg80211_chan_def *chandef, 231857f255f5SArik Nemtsov u16 prot_mode, bool rifs_mode) 231942e7aa77SAlexander Simon { 2320074d46d1SJohannes Berg struct ieee80211_ht_operation *ht_oper; 232142e7aa77SAlexander Simon /* Build HT Information */ 2322074d46d1SJohannes Berg *pos++ = WLAN_EID_HT_OPERATION; 2323074d46d1SJohannes Berg *pos++ = sizeof(struct ieee80211_ht_operation); 2324074d46d1SJohannes Berg ht_oper = (struct ieee80211_ht_operation *)pos; 23254bf88530SJohannes Berg ht_oper->primary_chan = ieee80211_frequency_to_channel( 23264bf88530SJohannes Berg chandef->chan->center_freq); 23274bf88530SJohannes Berg switch (chandef->width) { 23284bf88530SJohannes Berg case NL80211_CHAN_WIDTH_160: 23294bf88530SJohannes Berg case NL80211_CHAN_WIDTH_80P80: 23304bf88530SJohannes Berg case NL80211_CHAN_WIDTH_80: 23314bf88530SJohannes Berg case NL80211_CHAN_WIDTH_40: 23324bf88530SJohannes Berg if (chandef->center_freq1 > chandef->chan->center_freq) 23334bf88530SJohannes Berg ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_ABOVE; 23344bf88530SJohannes Berg else 2335074d46d1SJohannes Berg ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_BELOW; 233642e7aa77SAlexander Simon break; 233742e7aa77SAlexander Simon default: 2338074d46d1SJohannes Berg ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_NONE; 233942e7aa77SAlexander Simon break; 234042e7aa77SAlexander Simon } 2341aee286c2SThomas Pedersen if (ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 && 23424bf88530SJohannes Berg chandef->width != NL80211_CHAN_WIDTH_20_NOHT && 23434bf88530SJohannes Berg chandef->width != NL80211_CHAN_WIDTH_20) 2344074d46d1SJohannes Berg ht_oper->ht_param |= IEEE80211_HT_PARAM_CHAN_WIDTH_ANY; 2345ff3cc5f4SSimon Wunderlich 234657f255f5SArik Nemtsov if (rifs_mode) 234757f255f5SArik Nemtsov ht_oper->ht_param |= IEEE80211_HT_PARAM_RIFS_MODE; 234857f255f5SArik Nemtsov 2349431e3154SAshok Nagarajan ht_oper->operation_mode = cpu_to_le16(prot_mode); 2350074d46d1SJohannes Berg ht_oper->stbc_param = 0x0000; 235142e7aa77SAlexander Simon 235242e7aa77SAlexander Simon /* It seems that Basic MCS set and Supported MCS set 235342e7aa77SAlexander Simon are identical for the first 10 bytes */ 2354074d46d1SJohannes Berg memset(&ht_oper->basic_set, 0, 16); 2355074d46d1SJohannes Berg memcpy(&ht_oper->basic_set, &ht_cap->mcs, 10); 235642e7aa77SAlexander Simon 2357074d46d1SJohannes Berg return pos + sizeof(struct ieee80211_ht_operation); 235842e7aa77SAlexander Simon } 235942e7aa77SAlexander Simon 2360fb28ec0cSArik Nemtsov u8 *ieee80211_ie_build_vht_oper(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap, 2361fb28ec0cSArik Nemtsov const struct cfg80211_chan_def *chandef) 2362fb28ec0cSArik Nemtsov { 2363fb28ec0cSArik Nemtsov struct ieee80211_vht_operation *vht_oper; 2364fb28ec0cSArik Nemtsov 2365fb28ec0cSArik Nemtsov *pos++ = WLAN_EID_VHT_OPERATION; 2366fb28ec0cSArik Nemtsov *pos++ = sizeof(struct ieee80211_vht_operation); 2367fb28ec0cSArik Nemtsov vht_oper = (struct ieee80211_vht_operation *)pos; 2368fb28ec0cSArik Nemtsov vht_oper->center_freq_seg1_idx = ieee80211_frequency_to_channel( 2369fb28ec0cSArik Nemtsov chandef->center_freq1); 2370fb28ec0cSArik Nemtsov if (chandef->center_freq2) 2371fb28ec0cSArik Nemtsov vht_oper->center_freq_seg2_idx = 2372fb28ec0cSArik Nemtsov ieee80211_frequency_to_channel(chandef->center_freq2); 2373f020ae40SChun-Yeow Yeoh else 2374f020ae40SChun-Yeow Yeoh vht_oper->center_freq_seg2_idx = 0x00; 2375fb28ec0cSArik Nemtsov 2376fb28ec0cSArik Nemtsov switch (chandef->width) { 2377fb28ec0cSArik Nemtsov case NL80211_CHAN_WIDTH_160: 237823665aafSJouni Malinen /* 237923665aafSJouni Malinen * Convert 160 MHz channel width to new style as interop 238023665aafSJouni Malinen * workaround. 238123665aafSJouni Malinen */ 238223665aafSJouni Malinen vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ; 238323665aafSJouni Malinen vht_oper->center_freq_seg2_idx = vht_oper->center_freq_seg1_idx; 238423665aafSJouni Malinen if (chandef->chan->center_freq < chandef->center_freq1) 238523665aafSJouni Malinen vht_oper->center_freq_seg1_idx -= 8; 238623665aafSJouni Malinen else 238723665aafSJouni Malinen vht_oper->center_freq_seg1_idx += 8; 2388fb28ec0cSArik Nemtsov break; 2389fb28ec0cSArik Nemtsov case NL80211_CHAN_WIDTH_80P80: 239023665aafSJouni Malinen /* 239123665aafSJouni Malinen * Convert 80+80 MHz channel width to new style as interop 239223665aafSJouni Malinen * workaround. 239323665aafSJouni Malinen */ 239423665aafSJouni Malinen vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ; 2395fb28ec0cSArik Nemtsov break; 2396fb28ec0cSArik Nemtsov case NL80211_CHAN_WIDTH_80: 2397fb28ec0cSArik Nemtsov vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ; 2398fb28ec0cSArik Nemtsov break; 2399fb28ec0cSArik Nemtsov default: 2400fb28ec0cSArik Nemtsov vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_USE_HT; 2401fb28ec0cSArik Nemtsov break; 2402fb28ec0cSArik Nemtsov } 2403fb28ec0cSArik Nemtsov 2404fb28ec0cSArik Nemtsov /* don't require special VHT peer rates */ 2405fb28ec0cSArik Nemtsov vht_oper->basic_mcs_set = cpu_to_le16(0xffff); 2406fb28ec0cSArik Nemtsov 2407fb28ec0cSArik Nemtsov return pos + sizeof(struct ieee80211_vht_operation); 2408fb28ec0cSArik Nemtsov } 2409fb28ec0cSArik Nemtsov 24108ac3c704SJohannes Berg bool ieee80211_chandef_ht_oper(const struct ieee80211_ht_operation *ht_oper, 24114bf88530SJohannes Berg struct cfg80211_chan_def *chandef) 241242e7aa77SAlexander Simon { 241342e7aa77SAlexander Simon enum nl80211_channel_type channel_type; 241442e7aa77SAlexander Simon 24158ac3c704SJohannes Berg if (!ht_oper) 24168ac3c704SJohannes Berg return false; 241742e7aa77SAlexander Simon 2418074d46d1SJohannes Berg switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) { 241942e7aa77SAlexander Simon case IEEE80211_HT_PARAM_CHA_SEC_NONE: 242042e7aa77SAlexander Simon channel_type = NL80211_CHAN_HT20; 242142e7aa77SAlexander Simon break; 242242e7aa77SAlexander Simon case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: 242342e7aa77SAlexander Simon channel_type = NL80211_CHAN_HT40PLUS; 242442e7aa77SAlexander Simon break; 242542e7aa77SAlexander Simon case IEEE80211_HT_PARAM_CHA_SEC_BELOW: 242642e7aa77SAlexander Simon channel_type = NL80211_CHAN_HT40MINUS; 242742e7aa77SAlexander Simon break; 242842e7aa77SAlexander Simon default: 242942e7aa77SAlexander Simon channel_type = NL80211_CHAN_NO_HT; 24308ac3c704SJohannes Berg return false; 243142e7aa77SAlexander Simon } 243242e7aa77SAlexander Simon 24338ac3c704SJohannes Berg cfg80211_chandef_create(chandef, chandef->chan, channel_type); 24348ac3c704SJohannes Berg return true; 243542e7aa77SAlexander Simon } 243642e7aa77SAlexander Simon 24378ac3c704SJohannes Berg bool ieee80211_chandef_vht_oper(const struct ieee80211_vht_operation *oper, 2438abcff6efSJanusz.Dziedzic@tieto.com struct cfg80211_chan_def *chandef) 2439abcff6efSJanusz.Dziedzic@tieto.com { 24408ac3c704SJohannes Berg struct cfg80211_chan_def new = *chandef; 24418ac3c704SJohannes Berg int cf1, cf2; 2442abcff6efSJanusz.Dziedzic@tieto.com 24438ac3c704SJohannes Berg if (!oper) 24448ac3c704SJohannes Berg return false; 24458ac3c704SJohannes Berg 24468ac3c704SJohannes Berg cf1 = ieee80211_channel_to_frequency(oper->center_freq_seg1_idx, 24478ac3c704SJohannes Berg chandef->chan->band); 24488ac3c704SJohannes Berg cf2 = ieee80211_channel_to_frequency(oper->center_freq_seg2_idx, 24498ac3c704SJohannes Berg chandef->chan->band); 2450abcff6efSJanusz.Dziedzic@tieto.com 2451abcff6efSJanusz.Dziedzic@tieto.com switch (oper->chan_width) { 2452abcff6efSJanusz.Dziedzic@tieto.com case IEEE80211_VHT_CHANWIDTH_USE_HT: 2453abcff6efSJanusz.Dziedzic@tieto.com break; 2454abcff6efSJanusz.Dziedzic@tieto.com case IEEE80211_VHT_CHANWIDTH_80MHZ: 24558ac3c704SJohannes Berg new.width = NL80211_CHAN_WIDTH_80; 24568ac3c704SJohannes Berg new.center_freq1 = cf1; 245723665aafSJouni Malinen /* If needed, adjust based on the newer interop workaround. */ 245823665aafSJouni Malinen if (oper->center_freq_seg2_idx) { 245923665aafSJouni Malinen unsigned int diff; 246023665aafSJouni Malinen 246123665aafSJouni Malinen diff = abs(oper->center_freq_seg2_idx - 246223665aafSJouni Malinen oper->center_freq_seg1_idx); 246323665aafSJouni Malinen if (diff == 8) { 246423665aafSJouni Malinen new.width = NL80211_CHAN_WIDTH_160; 246523665aafSJouni Malinen new.center_freq1 = cf2; 246623665aafSJouni Malinen } else if (diff > 8) { 246723665aafSJouni Malinen new.width = NL80211_CHAN_WIDTH_80P80; 246823665aafSJouni Malinen new.center_freq2 = cf2; 246923665aafSJouni Malinen } 247023665aafSJouni Malinen } 2471abcff6efSJanusz.Dziedzic@tieto.com break; 2472abcff6efSJanusz.Dziedzic@tieto.com case IEEE80211_VHT_CHANWIDTH_160MHZ: 24738ac3c704SJohannes Berg new.width = NL80211_CHAN_WIDTH_160; 24748ac3c704SJohannes Berg new.center_freq1 = cf1; 2475abcff6efSJanusz.Dziedzic@tieto.com break; 2476abcff6efSJanusz.Dziedzic@tieto.com case IEEE80211_VHT_CHANWIDTH_80P80MHZ: 24778ac3c704SJohannes Berg new.width = NL80211_CHAN_WIDTH_80P80; 24788ac3c704SJohannes Berg new.center_freq1 = cf1; 24798ac3c704SJohannes Berg new.center_freq2 = cf2; 2480abcff6efSJanusz.Dziedzic@tieto.com break; 2481abcff6efSJanusz.Dziedzic@tieto.com default: 24828ac3c704SJohannes Berg return false; 2483abcff6efSJanusz.Dziedzic@tieto.com } 2484abcff6efSJanusz.Dziedzic@tieto.com 24858ac3c704SJohannes Berg if (!cfg80211_chandef_valid(&new)) 24868ac3c704SJohannes Berg return false; 24878ac3c704SJohannes Berg 24888ac3c704SJohannes Berg *chandef = new; 24898ac3c704SJohannes Berg return true; 2490abcff6efSJanusz.Dziedzic@tieto.com } 2491abcff6efSJanusz.Dziedzic@tieto.com 24922103dec1SSimon Wunderlich int ieee80211_parse_bitrates(struct cfg80211_chan_def *chandef, 24932103dec1SSimon Wunderlich const struct ieee80211_supported_band *sband, 24942103dec1SSimon Wunderlich const u8 *srates, int srates_len, u32 *rates) 24952103dec1SSimon Wunderlich { 24962103dec1SSimon Wunderlich u32 rate_flags = ieee80211_chandef_rate_flags(chandef); 24972103dec1SSimon Wunderlich int shift = ieee80211_chandef_get_shift(chandef); 24982103dec1SSimon Wunderlich struct ieee80211_rate *br; 24992103dec1SSimon Wunderlich int brate, rate, i, j, count = 0; 25002103dec1SSimon Wunderlich 25012103dec1SSimon Wunderlich *rates = 0; 25022103dec1SSimon Wunderlich 25032103dec1SSimon Wunderlich for (i = 0; i < srates_len; i++) { 25042103dec1SSimon Wunderlich rate = srates[i] & 0x7f; 25052103dec1SSimon Wunderlich 25062103dec1SSimon Wunderlich for (j = 0; j < sband->n_bitrates; j++) { 25072103dec1SSimon Wunderlich br = &sband->bitrates[j]; 25082103dec1SSimon Wunderlich if ((rate_flags & br->flags) != rate_flags) 25092103dec1SSimon Wunderlich continue; 25102103dec1SSimon Wunderlich 25112103dec1SSimon Wunderlich brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5); 25122103dec1SSimon Wunderlich if (brate == rate) { 25132103dec1SSimon Wunderlich *rates |= BIT(j); 25142103dec1SSimon Wunderlich count++; 25152103dec1SSimon Wunderlich break; 25162103dec1SSimon Wunderlich } 25172103dec1SSimon Wunderlich } 25182103dec1SSimon Wunderlich } 25192103dec1SSimon Wunderlich return count; 25202103dec1SSimon Wunderlich } 25212103dec1SSimon Wunderlich 2522fc8a7321SJohannes Berg int ieee80211_add_srates_ie(struct ieee80211_sub_if_data *sdata, 25236b77863bSJohannes Berg struct sk_buff *skb, bool need_basic, 252457fbcce3SJohannes Berg enum nl80211_band band) 2525768db343SArik Nemtsov { 2526768db343SArik Nemtsov struct ieee80211_local *local = sdata->local; 2527768db343SArik Nemtsov struct ieee80211_supported_band *sband; 25282103dec1SSimon Wunderlich int rate, shift; 2529768db343SArik Nemtsov u8 i, rates, *pos; 2530fc8a7321SJohannes Berg u32 basic_rates = sdata->vif.bss_conf.basic_rates; 25312103dec1SSimon Wunderlich u32 rate_flags; 2532768db343SArik Nemtsov 25332103dec1SSimon Wunderlich shift = ieee80211_vif_get_shift(&sdata->vif); 25342103dec1SSimon Wunderlich rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef); 25356b77863bSJohannes Berg sband = local->hw.wiphy->bands[band]; 25362103dec1SSimon Wunderlich rates = 0; 25372103dec1SSimon Wunderlich for (i = 0; i < sband->n_bitrates; i++) { 25382103dec1SSimon Wunderlich if ((rate_flags & sband->bitrates[i].flags) != rate_flags) 25392103dec1SSimon Wunderlich continue; 25402103dec1SSimon Wunderlich rates++; 25412103dec1SSimon Wunderlich } 2542768db343SArik Nemtsov if (rates > 8) 2543768db343SArik Nemtsov rates = 8; 2544768db343SArik Nemtsov 2545768db343SArik Nemtsov if (skb_tailroom(skb) < rates + 2) 2546768db343SArik Nemtsov return -ENOMEM; 2547768db343SArik Nemtsov 2548768db343SArik Nemtsov pos = skb_put(skb, rates + 2); 2549768db343SArik Nemtsov *pos++ = WLAN_EID_SUPP_RATES; 2550768db343SArik Nemtsov *pos++ = rates; 2551768db343SArik Nemtsov for (i = 0; i < rates; i++) { 2552657c3e0cSAshok Nagarajan u8 basic = 0; 25532103dec1SSimon Wunderlich if ((rate_flags & sband->bitrates[i].flags) != rate_flags) 25542103dec1SSimon Wunderlich continue; 25552103dec1SSimon Wunderlich 2556657c3e0cSAshok Nagarajan if (need_basic && basic_rates & BIT(i)) 2557657c3e0cSAshok Nagarajan basic = 0x80; 2558768db343SArik Nemtsov rate = sband->bitrates[i].bitrate; 25592103dec1SSimon Wunderlich rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, 25602103dec1SSimon Wunderlich 5 * (1 << shift)); 25612103dec1SSimon Wunderlich *pos++ = basic | (u8) rate; 2562768db343SArik Nemtsov } 2563768db343SArik Nemtsov 2564768db343SArik Nemtsov return 0; 2565768db343SArik Nemtsov } 2566768db343SArik Nemtsov 2567fc8a7321SJohannes Berg int ieee80211_add_ext_srates_ie(struct ieee80211_sub_if_data *sdata, 25686b77863bSJohannes Berg struct sk_buff *skb, bool need_basic, 256957fbcce3SJohannes Berg enum nl80211_band band) 2570768db343SArik Nemtsov { 2571768db343SArik Nemtsov struct ieee80211_local *local = sdata->local; 2572768db343SArik Nemtsov struct ieee80211_supported_band *sband; 2573cc63ec76SChun-Yeow Yeoh int rate, shift; 2574768db343SArik Nemtsov u8 i, exrates, *pos; 2575fc8a7321SJohannes Berg u32 basic_rates = sdata->vif.bss_conf.basic_rates; 25762103dec1SSimon Wunderlich u32 rate_flags; 25772103dec1SSimon Wunderlich 25782103dec1SSimon Wunderlich rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef); 25792103dec1SSimon Wunderlich shift = ieee80211_vif_get_shift(&sdata->vif); 2580768db343SArik Nemtsov 25816b77863bSJohannes Berg sband = local->hw.wiphy->bands[band]; 25822103dec1SSimon Wunderlich exrates = 0; 25832103dec1SSimon Wunderlich for (i = 0; i < sband->n_bitrates; i++) { 25842103dec1SSimon Wunderlich if ((rate_flags & sband->bitrates[i].flags) != rate_flags) 25852103dec1SSimon Wunderlich continue; 25862103dec1SSimon Wunderlich exrates++; 25872103dec1SSimon Wunderlich } 25882103dec1SSimon Wunderlich 2589768db343SArik Nemtsov if (exrates > 8) 2590768db343SArik Nemtsov exrates -= 8; 2591768db343SArik Nemtsov else 2592768db343SArik Nemtsov exrates = 0; 2593768db343SArik Nemtsov 2594768db343SArik Nemtsov if (skb_tailroom(skb) < exrates + 2) 2595768db343SArik Nemtsov return -ENOMEM; 2596768db343SArik Nemtsov 2597768db343SArik Nemtsov if (exrates) { 2598768db343SArik Nemtsov pos = skb_put(skb, exrates + 2); 2599768db343SArik Nemtsov *pos++ = WLAN_EID_EXT_SUPP_RATES; 2600768db343SArik Nemtsov *pos++ = exrates; 2601768db343SArik Nemtsov for (i = 8; i < sband->n_bitrates; i++) { 2602657c3e0cSAshok Nagarajan u8 basic = 0; 26032103dec1SSimon Wunderlich if ((rate_flags & sband->bitrates[i].flags) 26042103dec1SSimon Wunderlich != rate_flags) 26052103dec1SSimon Wunderlich continue; 2606657c3e0cSAshok Nagarajan if (need_basic && basic_rates & BIT(i)) 2607657c3e0cSAshok Nagarajan basic = 0x80; 26082103dec1SSimon Wunderlich rate = DIV_ROUND_UP(sband->bitrates[i].bitrate, 26092103dec1SSimon Wunderlich 5 * (1 << shift)); 26102103dec1SSimon Wunderlich *pos++ = basic | (u8) rate; 2611768db343SArik Nemtsov } 2612768db343SArik Nemtsov } 2613768db343SArik Nemtsov return 0; 2614768db343SArik Nemtsov } 26151dae27f8SWey-Yi Guy 26161dae27f8SWey-Yi Guy int ieee80211_ave_rssi(struct ieee80211_vif *vif) 26171dae27f8SWey-Yi Guy { 26181dae27f8SWey-Yi Guy struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif); 26191dae27f8SWey-Yi Guy struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; 26201dae27f8SWey-Yi Guy 2621be6bcabcSWey-Yi Guy if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION)) { 2622be6bcabcSWey-Yi Guy /* non-managed type inferfaces */ 2623be6bcabcSWey-Yi Guy return 0; 2624be6bcabcSWey-Yi Guy } 2625338c17aeSJohannes Berg return -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal); 26261dae27f8SWey-Yi Guy } 26270d8a0a17SWey-Yi Guy EXPORT_SYMBOL_GPL(ieee80211_ave_rssi); 262804ecd257SJohannes Berg 262904ecd257SJohannes Berg u8 ieee80211_mcs_to_chains(const struct ieee80211_mcs_info *mcs) 263004ecd257SJohannes Berg { 263104ecd257SJohannes Berg if (!mcs) 263204ecd257SJohannes Berg return 1; 263304ecd257SJohannes Berg 263404ecd257SJohannes Berg /* TODO: consider rx_highest */ 263504ecd257SJohannes Berg 263604ecd257SJohannes Berg if (mcs->rx_mask[3]) 263704ecd257SJohannes Berg return 4; 263804ecd257SJohannes Berg if (mcs->rx_mask[2]) 263904ecd257SJohannes Berg return 3; 264004ecd257SJohannes Berg if (mcs->rx_mask[1]) 264104ecd257SJohannes Berg return 2; 264204ecd257SJohannes Berg return 1; 264304ecd257SJohannes Berg } 2644f4bda337SThomas Pedersen 2645f4bda337SThomas Pedersen /** 2646f4bda337SThomas Pedersen * ieee80211_calculate_rx_timestamp - calculate timestamp in frame 2647f4bda337SThomas Pedersen * @local: mac80211 hw info struct 2648f4bda337SThomas Pedersen * @status: RX status 2649f4bda337SThomas Pedersen * @mpdu_len: total MPDU length (including FCS) 2650f4bda337SThomas Pedersen * @mpdu_offset: offset into MPDU to calculate timestamp at 2651f4bda337SThomas Pedersen * 2652f4bda337SThomas Pedersen * This function calculates the RX timestamp at the given MPDU offset, taking 2653f4bda337SThomas Pedersen * into account what the RX timestamp was. An offset of 0 will just normalize 2654f4bda337SThomas Pedersen * the timestamp to TSF at beginning of MPDU reception. 2655f4bda337SThomas Pedersen */ 2656f4bda337SThomas Pedersen u64 ieee80211_calculate_rx_timestamp(struct ieee80211_local *local, 2657f4bda337SThomas Pedersen struct ieee80211_rx_status *status, 2658f4bda337SThomas Pedersen unsigned int mpdu_len, 2659f4bda337SThomas Pedersen unsigned int mpdu_offset) 2660f4bda337SThomas Pedersen { 2661f4bda337SThomas Pedersen u64 ts = status->mactime; 2662f4bda337SThomas Pedersen struct rate_info ri; 2663f4bda337SThomas Pedersen u16 rate; 2664f4bda337SThomas Pedersen 2665f4bda337SThomas Pedersen if (WARN_ON(!ieee80211_have_rx_timestamp(status))) 2666f4bda337SThomas Pedersen return 0; 2667f4bda337SThomas Pedersen 2668f4bda337SThomas Pedersen memset(&ri, 0, sizeof(ri)); 2669f4bda337SThomas Pedersen 2670f4bda337SThomas Pedersen /* Fill cfg80211 rate info */ 2671f4bda337SThomas Pedersen if (status->flag & RX_FLAG_HT) { 2672f4bda337SThomas Pedersen ri.mcs = status->rate_idx; 2673f4bda337SThomas Pedersen ri.flags |= RATE_INFO_FLAGS_MCS; 2674f4bda337SThomas Pedersen if (status->flag & RX_FLAG_40MHZ) 2675b51f3beeSJohannes Berg ri.bw = RATE_INFO_BW_40; 2676b51f3beeSJohannes Berg else 2677b51f3beeSJohannes Berg ri.bw = RATE_INFO_BW_20; 2678f4bda337SThomas Pedersen if (status->flag & RX_FLAG_SHORT_GI) 2679f4bda337SThomas Pedersen ri.flags |= RATE_INFO_FLAGS_SHORT_GI; 26805614618eSJohannes Berg } else if (status->flag & RX_FLAG_VHT) { 26815614618eSJohannes Berg ri.flags |= RATE_INFO_FLAGS_VHT_MCS; 26825614618eSJohannes Berg ri.mcs = status->rate_idx; 26835614618eSJohannes Berg ri.nss = status->vht_nss; 26845614618eSJohannes Berg if (status->flag & RX_FLAG_40MHZ) 2685b51f3beeSJohannes Berg ri.bw = RATE_INFO_BW_40; 2686b51f3beeSJohannes Berg else if (status->vht_flag & RX_VHT_FLAG_80MHZ) 2687b51f3beeSJohannes Berg ri.bw = RATE_INFO_BW_80; 2688b51f3beeSJohannes Berg else if (status->vht_flag & RX_VHT_FLAG_160MHZ) 2689b51f3beeSJohannes Berg ri.bw = RATE_INFO_BW_160; 2690b51f3beeSJohannes Berg else 2691b51f3beeSJohannes Berg ri.bw = RATE_INFO_BW_20; 26925614618eSJohannes Berg if (status->flag & RX_FLAG_SHORT_GI) 26935614618eSJohannes Berg ri.flags |= RATE_INFO_FLAGS_SHORT_GI; 2694f4bda337SThomas Pedersen } else { 2695f4bda337SThomas Pedersen struct ieee80211_supported_band *sband; 26962103dec1SSimon Wunderlich int shift = 0; 26972103dec1SSimon Wunderlich int bitrate; 26982103dec1SSimon Wunderlich 2699b51f3beeSJohannes Berg if (status->flag & RX_FLAG_10MHZ) { 27002103dec1SSimon Wunderlich shift = 1; 2701b51f3beeSJohannes Berg ri.bw = RATE_INFO_BW_10; 2702b51f3beeSJohannes Berg } else if (status->flag & RX_FLAG_5MHZ) { 27032103dec1SSimon Wunderlich shift = 2; 2704b51f3beeSJohannes Berg ri.bw = RATE_INFO_BW_5; 2705b51f3beeSJohannes Berg } else { 2706b51f3beeSJohannes Berg ri.bw = RATE_INFO_BW_20; 2707b51f3beeSJohannes Berg } 2708f4bda337SThomas Pedersen 2709f4bda337SThomas Pedersen sband = local->hw.wiphy->bands[status->band]; 27102103dec1SSimon Wunderlich bitrate = sband->bitrates[status->rate_idx].bitrate; 27112103dec1SSimon Wunderlich ri.legacy = DIV_ROUND_UP(bitrate, (1 << shift)); 2712f4a0f0c5SJohannes Berg 2713f4a0f0c5SJohannes Berg if (status->flag & RX_FLAG_MACTIME_PLCP_START) { 2714f4a0f0c5SJohannes Berg /* TODO: handle HT/VHT preambles */ 271557fbcce3SJohannes Berg if (status->band == NL80211_BAND_5GHZ) { 2716f4a0f0c5SJohannes Berg ts += 20 << shift; 2717f4a0f0c5SJohannes Berg mpdu_offset += 2; 2718f4a0f0c5SJohannes Berg } else if (status->flag & RX_FLAG_SHORTPRE) { 2719f4a0f0c5SJohannes Berg ts += 96; 2720f4a0f0c5SJohannes Berg } else { 2721f4a0f0c5SJohannes Berg ts += 192; 2722f4a0f0c5SJohannes Berg } 2723f4a0f0c5SJohannes Berg } 2724f4bda337SThomas Pedersen } 2725f4bda337SThomas Pedersen 2726f4bda337SThomas Pedersen rate = cfg80211_calculate_bitrate(&ri); 2727d86aa4f8SJohannes Berg if (WARN_ONCE(!rate, 2728f980ebc0SSara Sharon "Invalid bitrate: flags=0x%llx, idx=%d, vht_nss=%d\n", 2729f980ebc0SSara Sharon (unsigned long long)status->flag, status->rate_idx, 2730f980ebc0SSara Sharon status->vht_nss)) 2731d86aa4f8SJohannes Berg return 0; 2732f4bda337SThomas Pedersen 2733f4bda337SThomas Pedersen /* rewind from end of MPDU */ 2734f4bda337SThomas Pedersen if (status->flag & RX_FLAG_MACTIME_END) 2735f4bda337SThomas Pedersen ts -= mpdu_len * 8 * 10 / rate; 2736f4bda337SThomas Pedersen 2737f4bda337SThomas Pedersen ts += mpdu_offset * 8 * 10 / rate; 2738f4bda337SThomas Pedersen 2739f4bda337SThomas Pedersen return ts; 2740f4bda337SThomas Pedersen } 2741164eb02dSSimon Wunderlich 2742164eb02dSSimon Wunderlich void ieee80211_dfs_cac_cancel(struct ieee80211_local *local) 2743164eb02dSSimon Wunderlich { 2744164eb02dSSimon Wunderlich struct ieee80211_sub_if_data *sdata; 2745d2859df5SJanusz Dziedzic struct cfg80211_chan_def chandef; 2746164eb02dSSimon Wunderlich 274734a3740dSJohannes Berg mutex_lock(&local->mtx); 2748164eb02dSSimon Wunderlich mutex_lock(&local->iflist_mtx); 2749164eb02dSSimon Wunderlich list_for_each_entry(sdata, &local->interfaces, list) { 275034a3740dSJohannes Berg /* it might be waiting for the local->mtx, but then 275134a3740dSJohannes Berg * by the time it gets it, sdata->wdev.cac_started 275234a3740dSJohannes Berg * will no longer be true 275334a3740dSJohannes Berg */ 275434a3740dSJohannes Berg cancel_delayed_work(&sdata->dfs_cac_timer_work); 2755164eb02dSSimon Wunderlich 2756164eb02dSSimon Wunderlich if (sdata->wdev.cac_started) { 2757d2859df5SJanusz Dziedzic chandef = sdata->vif.bss_conf.chandef; 2758164eb02dSSimon Wunderlich ieee80211_vif_release_channel(sdata); 2759164eb02dSSimon Wunderlich cfg80211_cac_event(sdata->dev, 2760d2859df5SJanusz Dziedzic &chandef, 2761164eb02dSSimon Wunderlich NL80211_RADAR_CAC_ABORTED, 2762164eb02dSSimon Wunderlich GFP_KERNEL); 2763164eb02dSSimon Wunderlich } 2764164eb02dSSimon Wunderlich } 2765164eb02dSSimon Wunderlich mutex_unlock(&local->iflist_mtx); 276634a3740dSJohannes Berg mutex_unlock(&local->mtx); 2767164eb02dSSimon Wunderlich } 2768164eb02dSSimon Wunderlich 2769164eb02dSSimon Wunderlich void ieee80211_dfs_radar_detected_work(struct work_struct *work) 2770164eb02dSSimon Wunderlich { 2771164eb02dSSimon Wunderlich struct ieee80211_local *local = 2772164eb02dSSimon Wunderlich container_of(work, struct ieee80211_local, radar_detected_work); 277384a3d1c9SJanusz Dziedzic struct cfg80211_chan_def chandef = local->hw.conf.chandef; 2774486cf4c0SMichal Kazior struct ieee80211_chanctx *ctx; 2775486cf4c0SMichal Kazior int num_chanctx = 0; 2776486cf4c0SMichal Kazior 2777486cf4c0SMichal Kazior mutex_lock(&local->chanctx_mtx); 2778486cf4c0SMichal Kazior list_for_each_entry(ctx, &local->chanctx_list, list) { 2779486cf4c0SMichal Kazior if (ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER) 2780486cf4c0SMichal Kazior continue; 2781486cf4c0SMichal Kazior 2782486cf4c0SMichal Kazior num_chanctx++; 2783486cf4c0SMichal Kazior chandef = ctx->conf.def; 2784486cf4c0SMichal Kazior } 2785486cf4c0SMichal Kazior mutex_unlock(&local->chanctx_mtx); 2786164eb02dSSimon Wunderlich 2787164eb02dSSimon Wunderlich ieee80211_dfs_cac_cancel(local); 2788164eb02dSSimon Wunderlich 2789486cf4c0SMichal Kazior if (num_chanctx > 1) 2790486cf4c0SMichal Kazior /* XXX: multi-channel is not supported yet */ 2791164eb02dSSimon Wunderlich WARN_ON(1); 279284a3d1c9SJanusz Dziedzic else 2793164eb02dSSimon Wunderlich cfg80211_radar_event(local->hw.wiphy, &chandef, GFP_KERNEL); 2794164eb02dSSimon Wunderlich } 2795164eb02dSSimon Wunderlich 2796164eb02dSSimon Wunderlich void ieee80211_radar_detected(struct ieee80211_hw *hw) 2797164eb02dSSimon Wunderlich { 2798164eb02dSSimon Wunderlich struct ieee80211_local *local = hw_to_local(hw); 2799164eb02dSSimon Wunderlich 2800164eb02dSSimon Wunderlich trace_api_radar_detected(local); 2801164eb02dSSimon Wunderlich 2802164eb02dSSimon Wunderlich ieee80211_queue_work(hw, &local->radar_detected_work); 2803164eb02dSSimon Wunderlich } 2804164eb02dSSimon Wunderlich EXPORT_SYMBOL(ieee80211_radar_detected); 2805e6b7cde4SSimon Wunderlich 2806e6b7cde4SSimon Wunderlich u32 ieee80211_chandef_downgrade(struct cfg80211_chan_def *c) 2807e6b7cde4SSimon Wunderlich { 2808e6b7cde4SSimon Wunderlich u32 ret; 2809e6b7cde4SSimon Wunderlich int tmp; 2810e6b7cde4SSimon Wunderlich 2811e6b7cde4SSimon Wunderlich switch (c->width) { 2812e6b7cde4SSimon Wunderlich case NL80211_CHAN_WIDTH_20: 2813e6b7cde4SSimon Wunderlich c->width = NL80211_CHAN_WIDTH_20_NOHT; 2814e6b7cde4SSimon Wunderlich ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT; 2815e6b7cde4SSimon Wunderlich break; 2816e6b7cde4SSimon Wunderlich case NL80211_CHAN_WIDTH_40: 2817e6b7cde4SSimon Wunderlich c->width = NL80211_CHAN_WIDTH_20; 2818e6b7cde4SSimon Wunderlich c->center_freq1 = c->chan->center_freq; 2819e6b7cde4SSimon Wunderlich ret = IEEE80211_STA_DISABLE_40MHZ | 2820e6b7cde4SSimon Wunderlich IEEE80211_STA_DISABLE_VHT; 2821e6b7cde4SSimon Wunderlich break; 2822e6b7cde4SSimon Wunderlich case NL80211_CHAN_WIDTH_80: 2823e6b7cde4SSimon Wunderlich tmp = (30 + c->chan->center_freq - c->center_freq1)/20; 2824e6b7cde4SSimon Wunderlich /* n_P40 */ 2825e6b7cde4SSimon Wunderlich tmp /= 2; 2826e6b7cde4SSimon Wunderlich /* freq_P40 */ 2827e6b7cde4SSimon Wunderlich c->center_freq1 = c->center_freq1 - 20 + 40 * tmp; 2828e6b7cde4SSimon Wunderlich c->width = NL80211_CHAN_WIDTH_40; 2829e6b7cde4SSimon Wunderlich ret = IEEE80211_STA_DISABLE_VHT; 2830e6b7cde4SSimon Wunderlich break; 2831e6b7cde4SSimon Wunderlich case NL80211_CHAN_WIDTH_80P80: 2832e6b7cde4SSimon Wunderlich c->center_freq2 = 0; 2833e6b7cde4SSimon Wunderlich c->width = NL80211_CHAN_WIDTH_80; 2834e6b7cde4SSimon Wunderlich ret = IEEE80211_STA_DISABLE_80P80MHZ | 2835e6b7cde4SSimon Wunderlich IEEE80211_STA_DISABLE_160MHZ; 2836e6b7cde4SSimon Wunderlich break; 2837e6b7cde4SSimon Wunderlich case NL80211_CHAN_WIDTH_160: 2838e6b7cde4SSimon Wunderlich /* n_P20 */ 2839e6b7cde4SSimon Wunderlich tmp = (70 + c->chan->center_freq - c->center_freq1)/20; 2840e6b7cde4SSimon Wunderlich /* n_P80 */ 2841e6b7cde4SSimon Wunderlich tmp /= 4; 2842e6b7cde4SSimon Wunderlich c->center_freq1 = c->center_freq1 - 40 + 80 * tmp; 2843e6b7cde4SSimon Wunderlich c->width = NL80211_CHAN_WIDTH_80; 2844e6b7cde4SSimon Wunderlich ret = IEEE80211_STA_DISABLE_80P80MHZ | 2845e6b7cde4SSimon Wunderlich IEEE80211_STA_DISABLE_160MHZ; 2846e6b7cde4SSimon Wunderlich break; 2847e6b7cde4SSimon Wunderlich default: 2848e6b7cde4SSimon Wunderlich case NL80211_CHAN_WIDTH_20_NOHT: 2849e6b7cde4SSimon Wunderlich WARN_ON_ONCE(1); 2850e6b7cde4SSimon Wunderlich c->width = NL80211_CHAN_WIDTH_20_NOHT; 2851e6b7cde4SSimon Wunderlich ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT; 2852e6b7cde4SSimon Wunderlich break; 2853e6b7cde4SSimon Wunderlich case NL80211_CHAN_WIDTH_5: 2854e6b7cde4SSimon Wunderlich case NL80211_CHAN_WIDTH_10: 2855e6b7cde4SSimon Wunderlich WARN_ON_ONCE(1); 2856e6b7cde4SSimon Wunderlich /* keep c->width */ 2857e6b7cde4SSimon Wunderlich ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT; 2858e6b7cde4SSimon Wunderlich break; 2859e6b7cde4SSimon Wunderlich } 2860e6b7cde4SSimon Wunderlich 2861e6b7cde4SSimon Wunderlich WARN_ON_ONCE(!cfg80211_chandef_valid(c)); 2862e6b7cde4SSimon Wunderlich 2863e6b7cde4SSimon Wunderlich return ret; 2864e6b7cde4SSimon Wunderlich } 2865687da132SEmmanuel Grumbach 2866687da132SEmmanuel Grumbach /* 2867687da132SEmmanuel Grumbach * Returns true if smps_mode_new is strictly more restrictive than 2868687da132SEmmanuel Grumbach * smps_mode_old. 2869687da132SEmmanuel Grumbach */ 2870687da132SEmmanuel Grumbach bool ieee80211_smps_is_restrictive(enum ieee80211_smps_mode smps_mode_old, 2871687da132SEmmanuel Grumbach enum ieee80211_smps_mode smps_mode_new) 2872687da132SEmmanuel Grumbach { 2873687da132SEmmanuel Grumbach if (WARN_ON_ONCE(smps_mode_old == IEEE80211_SMPS_AUTOMATIC || 2874687da132SEmmanuel Grumbach smps_mode_new == IEEE80211_SMPS_AUTOMATIC)) 2875687da132SEmmanuel Grumbach return false; 2876687da132SEmmanuel Grumbach 2877687da132SEmmanuel Grumbach switch (smps_mode_old) { 2878687da132SEmmanuel Grumbach case IEEE80211_SMPS_STATIC: 2879687da132SEmmanuel Grumbach return false; 2880687da132SEmmanuel Grumbach case IEEE80211_SMPS_DYNAMIC: 2881687da132SEmmanuel Grumbach return smps_mode_new == IEEE80211_SMPS_STATIC; 2882687da132SEmmanuel Grumbach case IEEE80211_SMPS_OFF: 2883687da132SEmmanuel Grumbach return smps_mode_new != IEEE80211_SMPS_OFF; 2884687da132SEmmanuel Grumbach default: 2885687da132SEmmanuel Grumbach WARN_ON(1); 2886687da132SEmmanuel Grumbach } 2887687da132SEmmanuel Grumbach 2888687da132SEmmanuel Grumbach return false; 2889687da132SEmmanuel Grumbach } 2890c6da674aSChun-Yeow Yeoh 2891c6da674aSChun-Yeow Yeoh int ieee80211_send_action_csa(struct ieee80211_sub_if_data *sdata, 2892c6da674aSChun-Yeow Yeoh struct cfg80211_csa_settings *csa_settings) 2893c6da674aSChun-Yeow Yeoh { 2894c6da674aSChun-Yeow Yeoh struct sk_buff *skb; 2895c6da674aSChun-Yeow Yeoh struct ieee80211_mgmt *mgmt; 2896c6da674aSChun-Yeow Yeoh struct ieee80211_local *local = sdata->local; 2897c6da674aSChun-Yeow Yeoh int freq; 2898c6da674aSChun-Yeow Yeoh int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.chan_switch) + 2899c6da674aSChun-Yeow Yeoh sizeof(mgmt->u.action.u.chan_switch); 2900c6da674aSChun-Yeow Yeoh u8 *pos; 2901c6da674aSChun-Yeow Yeoh 2902c6da674aSChun-Yeow Yeoh if (sdata->vif.type != NL80211_IFTYPE_ADHOC && 2903c6da674aSChun-Yeow Yeoh sdata->vif.type != NL80211_IFTYPE_MESH_POINT) 2904c6da674aSChun-Yeow Yeoh return -EOPNOTSUPP; 2905c6da674aSChun-Yeow Yeoh 2906c6da674aSChun-Yeow Yeoh skb = dev_alloc_skb(local->tx_headroom + hdr_len + 2907c6da674aSChun-Yeow Yeoh 5 + /* channel switch announcement element */ 2908c6da674aSChun-Yeow Yeoh 3 + /* secondary channel offset element */ 2909c6da674aSChun-Yeow Yeoh 8); /* mesh channel switch parameters element */ 2910c6da674aSChun-Yeow Yeoh if (!skb) 2911c6da674aSChun-Yeow Yeoh return -ENOMEM; 2912c6da674aSChun-Yeow Yeoh 2913c6da674aSChun-Yeow Yeoh skb_reserve(skb, local->tx_headroom); 2914c6da674aSChun-Yeow Yeoh mgmt = (struct ieee80211_mgmt *)skb_put(skb, hdr_len); 2915c6da674aSChun-Yeow Yeoh memset(mgmt, 0, hdr_len); 2916c6da674aSChun-Yeow Yeoh mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | 2917c6da674aSChun-Yeow Yeoh IEEE80211_STYPE_ACTION); 2918c6da674aSChun-Yeow Yeoh 2919c6da674aSChun-Yeow Yeoh eth_broadcast_addr(mgmt->da); 2920c6da674aSChun-Yeow Yeoh memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); 2921c6da674aSChun-Yeow Yeoh if (ieee80211_vif_is_mesh(&sdata->vif)) { 2922c6da674aSChun-Yeow Yeoh memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); 2923c6da674aSChun-Yeow Yeoh } else { 2924c6da674aSChun-Yeow Yeoh struct ieee80211_if_ibss *ifibss = &sdata->u.ibss; 2925c6da674aSChun-Yeow Yeoh memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN); 2926c6da674aSChun-Yeow Yeoh } 2927c6da674aSChun-Yeow Yeoh mgmt->u.action.category = WLAN_CATEGORY_SPECTRUM_MGMT; 2928c6da674aSChun-Yeow Yeoh mgmt->u.action.u.chan_switch.action_code = WLAN_ACTION_SPCT_CHL_SWITCH; 2929c6da674aSChun-Yeow Yeoh pos = skb_put(skb, 5); 2930c6da674aSChun-Yeow Yeoh *pos++ = WLAN_EID_CHANNEL_SWITCH; /* EID */ 2931c6da674aSChun-Yeow Yeoh *pos++ = 3; /* IE length */ 2932c6da674aSChun-Yeow Yeoh *pos++ = csa_settings->block_tx ? 1 : 0; /* CSA mode */ 2933c6da674aSChun-Yeow Yeoh freq = csa_settings->chandef.chan->center_freq; 2934c6da674aSChun-Yeow Yeoh *pos++ = ieee80211_frequency_to_channel(freq); /* channel */ 2935c6da674aSChun-Yeow Yeoh *pos++ = csa_settings->count; /* count */ 2936c6da674aSChun-Yeow Yeoh 2937c6da674aSChun-Yeow Yeoh if (csa_settings->chandef.width == NL80211_CHAN_WIDTH_40) { 2938c6da674aSChun-Yeow Yeoh enum nl80211_channel_type ch_type; 2939c6da674aSChun-Yeow Yeoh 2940c6da674aSChun-Yeow Yeoh skb_put(skb, 3); 2941c6da674aSChun-Yeow Yeoh *pos++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET; /* EID */ 2942c6da674aSChun-Yeow Yeoh *pos++ = 1; /* IE length */ 2943c6da674aSChun-Yeow Yeoh ch_type = cfg80211_get_chandef_type(&csa_settings->chandef); 2944c6da674aSChun-Yeow Yeoh if (ch_type == NL80211_CHAN_HT40PLUS) 2945c6da674aSChun-Yeow Yeoh *pos++ = IEEE80211_HT_PARAM_CHA_SEC_ABOVE; 2946c6da674aSChun-Yeow Yeoh else 2947c6da674aSChun-Yeow Yeoh *pos++ = IEEE80211_HT_PARAM_CHA_SEC_BELOW; 2948c6da674aSChun-Yeow Yeoh } 2949c6da674aSChun-Yeow Yeoh 2950c6da674aSChun-Yeow Yeoh if (ieee80211_vif_is_mesh(&sdata->vif)) { 2951c6da674aSChun-Yeow Yeoh struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh; 2952c6da674aSChun-Yeow Yeoh 2953c6da674aSChun-Yeow Yeoh skb_put(skb, 8); 2954c6da674aSChun-Yeow Yeoh *pos++ = WLAN_EID_CHAN_SWITCH_PARAM; /* EID */ 2955c6da674aSChun-Yeow Yeoh *pos++ = 6; /* IE length */ 2956c6da674aSChun-Yeow Yeoh *pos++ = sdata->u.mesh.mshcfg.dot11MeshTTL; /* Mesh TTL */ 2957c6da674aSChun-Yeow Yeoh *pos = 0x00; /* Mesh Flag: Tx Restrict, Initiator, Reason */ 2958c6da674aSChun-Yeow Yeoh *pos |= WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR; 2959c6da674aSChun-Yeow Yeoh *pos++ |= csa_settings->block_tx ? 2960c6da674aSChun-Yeow Yeoh WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT : 0x00; 2961c6da674aSChun-Yeow Yeoh put_unaligned_le16(WLAN_REASON_MESH_CHAN, pos); /* Reason Cd */ 2962c6da674aSChun-Yeow Yeoh pos += 2; 2963ca91dc97SChun-Yeow Yeoh put_unaligned_le16(ifmsh->pre_value, pos);/* Precedence Value */ 2964c6da674aSChun-Yeow Yeoh pos += 2; 2965c6da674aSChun-Yeow Yeoh } 2966c6da674aSChun-Yeow Yeoh 2967c6da674aSChun-Yeow Yeoh ieee80211_tx_skb(sdata, skb); 2968c6da674aSChun-Yeow Yeoh return 0; 2969c6da674aSChun-Yeow Yeoh } 29702475b1ccSMax Stepanov 29712475b1ccSMax Stepanov bool ieee80211_cs_valid(const struct ieee80211_cipher_scheme *cs) 29722475b1ccSMax Stepanov { 29732475b1ccSMax Stepanov return !(cs == NULL || cs->cipher == 0 || 29742475b1ccSMax Stepanov cs->hdr_len < cs->pn_len + cs->pn_off || 29752475b1ccSMax Stepanov cs->hdr_len <= cs->key_idx_off || 29762475b1ccSMax Stepanov cs->key_idx_shift > 7 || 29772475b1ccSMax Stepanov cs->key_idx_mask == 0); 29782475b1ccSMax Stepanov } 29792475b1ccSMax Stepanov 29802475b1ccSMax Stepanov bool ieee80211_cs_list_valid(const struct ieee80211_cipher_scheme *cs, int n) 29812475b1ccSMax Stepanov { 29822475b1ccSMax Stepanov int i; 29832475b1ccSMax Stepanov 29842475b1ccSMax Stepanov /* Ensure we have enough iftype bitmap space for all iftype values */ 29852475b1ccSMax Stepanov WARN_ON((NUM_NL80211_IFTYPES / 8 + 1) > sizeof(cs[0].iftype)); 29862475b1ccSMax Stepanov 29872475b1ccSMax Stepanov for (i = 0; i < n; i++) 29882475b1ccSMax Stepanov if (!ieee80211_cs_valid(&cs[i])) 29892475b1ccSMax Stepanov return false; 29902475b1ccSMax Stepanov 29912475b1ccSMax Stepanov return true; 29922475b1ccSMax Stepanov } 29932475b1ccSMax Stepanov 29942475b1ccSMax Stepanov const struct ieee80211_cipher_scheme * 29952475b1ccSMax Stepanov ieee80211_cs_get(struct ieee80211_local *local, u32 cipher, 29962475b1ccSMax Stepanov enum nl80211_iftype iftype) 29972475b1ccSMax Stepanov { 29982475b1ccSMax Stepanov const struct ieee80211_cipher_scheme *l = local->hw.cipher_schemes; 29992475b1ccSMax Stepanov int n = local->hw.n_cipher_schemes; 30002475b1ccSMax Stepanov int i; 30012475b1ccSMax Stepanov const struct ieee80211_cipher_scheme *cs = NULL; 30022475b1ccSMax Stepanov 30032475b1ccSMax Stepanov for (i = 0; i < n; i++) { 30042475b1ccSMax Stepanov if (l[i].cipher == cipher) { 30052475b1ccSMax Stepanov cs = &l[i]; 30062475b1ccSMax Stepanov break; 30072475b1ccSMax Stepanov } 30082475b1ccSMax Stepanov } 30092475b1ccSMax Stepanov 30102475b1ccSMax Stepanov if (!cs || !(cs->iftype & BIT(iftype))) 30112475b1ccSMax Stepanov return NULL; 30122475b1ccSMax Stepanov 30132475b1ccSMax Stepanov return cs; 30142475b1ccSMax Stepanov } 30152475b1ccSMax Stepanov 30162475b1ccSMax Stepanov int ieee80211_cs_headroom(struct ieee80211_local *local, 30172475b1ccSMax Stepanov struct cfg80211_crypto_settings *crypto, 30182475b1ccSMax Stepanov enum nl80211_iftype iftype) 30192475b1ccSMax Stepanov { 30202475b1ccSMax Stepanov const struct ieee80211_cipher_scheme *cs; 30212475b1ccSMax Stepanov int headroom = IEEE80211_ENCRYPT_HEADROOM; 30222475b1ccSMax Stepanov int i; 30232475b1ccSMax Stepanov 30242475b1ccSMax Stepanov for (i = 0; i < crypto->n_ciphers_pairwise; i++) { 30252475b1ccSMax Stepanov cs = ieee80211_cs_get(local, crypto->ciphers_pairwise[i], 30262475b1ccSMax Stepanov iftype); 30272475b1ccSMax Stepanov 30282475b1ccSMax Stepanov if (cs && headroom < cs->hdr_len) 30292475b1ccSMax Stepanov headroom = cs->hdr_len; 30302475b1ccSMax Stepanov } 30312475b1ccSMax Stepanov 30322475b1ccSMax Stepanov cs = ieee80211_cs_get(local, crypto->cipher_group, iftype); 30332475b1ccSMax Stepanov if (cs && headroom < cs->hdr_len) 30342475b1ccSMax Stepanov headroom = cs->hdr_len; 30352475b1ccSMax Stepanov 30362475b1ccSMax Stepanov return headroom; 30372475b1ccSMax Stepanov } 3038a7022e65SFelix Fietkau 3039a7022e65SFelix Fietkau static bool 3040a7022e65SFelix Fietkau ieee80211_extend_noa_desc(struct ieee80211_noa_data *data, u32 tsf, int i) 3041a7022e65SFelix Fietkau { 3042a7022e65SFelix Fietkau s32 end = data->desc[i].start + data->desc[i].duration - (tsf + 1); 3043a7022e65SFelix Fietkau int skip; 3044a7022e65SFelix Fietkau 3045a7022e65SFelix Fietkau if (end > 0) 3046a7022e65SFelix Fietkau return false; 3047a7022e65SFelix Fietkau 3048519ee691SJanusz.Dziedzic@tieto.com /* One shot NOA */ 3049519ee691SJanusz.Dziedzic@tieto.com if (data->count[i] == 1) 3050519ee691SJanusz.Dziedzic@tieto.com return false; 3051519ee691SJanusz.Dziedzic@tieto.com 3052519ee691SJanusz.Dziedzic@tieto.com if (data->desc[i].interval == 0) 3053519ee691SJanusz.Dziedzic@tieto.com return false; 3054519ee691SJanusz.Dziedzic@tieto.com 3055a7022e65SFelix Fietkau /* End time is in the past, check for repetitions */ 3056a7022e65SFelix Fietkau skip = DIV_ROUND_UP(-end, data->desc[i].interval); 3057a7022e65SFelix Fietkau if (data->count[i] < 255) { 3058a7022e65SFelix Fietkau if (data->count[i] <= skip) { 3059a7022e65SFelix Fietkau data->count[i] = 0; 3060a7022e65SFelix Fietkau return false; 3061a7022e65SFelix Fietkau } 3062a7022e65SFelix Fietkau 3063a7022e65SFelix Fietkau data->count[i] -= skip; 3064a7022e65SFelix Fietkau } 3065a7022e65SFelix Fietkau 3066a7022e65SFelix Fietkau data->desc[i].start += skip * data->desc[i].interval; 3067a7022e65SFelix Fietkau 3068a7022e65SFelix Fietkau return true; 3069a7022e65SFelix Fietkau } 3070a7022e65SFelix Fietkau 3071a7022e65SFelix Fietkau static bool 3072a7022e65SFelix Fietkau ieee80211_extend_absent_time(struct ieee80211_noa_data *data, u32 tsf, 3073a7022e65SFelix Fietkau s32 *offset) 3074a7022e65SFelix Fietkau { 3075a7022e65SFelix Fietkau bool ret = false; 3076a7022e65SFelix Fietkau int i; 3077a7022e65SFelix Fietkau 3078a7022e65SFelix Fietkau for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) { 3079a7022e65SFelix Fietkau s32 cur; 3080a7022e65SFelix Fietkau 3081a7022e65SFelix Fietkau if (!data->count[i]) 3082a7022e65SFelix Fietkau continue; 3083a7022e65SFelix Fietkau 3084a7022e65SFelix Fietkau if (ieee80211_extend_noa_desc(data, tsf + *offset, i)) 3085a7022e65SFelix Fietkau ret = true; 3086a7022e65SFelix Fietkau 3087a7022e65SFelix Fietkau cur = data->desc[i].start - tsf; 3088a7022e65SFelix Fietkau if (cur > *offset) 3089a7022e65SFelix Fietkau continue; 3090a7022e65SFelix Fietkau 3091a7022e65SFelix Fietkau cur = data->desc[i].start + data->desc[i].duration - tsf; 3092a7022e65SFelix Fietkau if (cur > *offset) 3093a7022e65SFelix Fietkau *offset = cur; 3094a7022e65SFelix Fietkau } 3095a7022e65SFelix Fietkau 3096a7022e65SFelix Fietkau return ret; 3097a7022e65SFelix Fietkau } 3098a7022e65SFelix Fietkau 3099a7022e65SFelix Fietkau static u32 3100a7022e65SFelix Fietkau ieee80211_get_noa_absent_time(struct ieee80211_noa_data *data, u32 tsf) 3101a7022e65SFelix Fietkau { 3102a7022e65SFelix Fietkau s32 offset = 0; 3103a7022e65SFelix Fietkau int tries = 0; 3104a7022e65SFelix Fietkau /* 3105a7022e65SFelix Fietkau * arbitrary limit, used to avoid infinite loops when combined NoA 3106a7022e65SFelix Fietkau * descriptors cover the full time period. 3107a7022e65SFelix Fietkau */ 3108a7022e65SFelix Fietkau int max_tries = 5; 3109a7022e65SFelix Fietkau 3110a7022e65SFelix Fietkau ieee80211_extend_absent_time(data, tsf, &offset); 3111a7022e65SFelix Fietkau do { 3112a7022e65SFelix Fietkau if (!ieee80211_extend_absent_time(data, tsf, &offset)) 3113a7022e65SFelix Fietkau break; 3114a7022e65SFelix Fietkau 3115a7022e65SFelix Fietkau tries++; 3116a7022e65SFelix Fietkau } while (tries < max_tries); 3117a7022e65SFelix Fietkau 3118a7022e65SFelix Fietkau return offset; 3119a7022e65SFelix Fietkau } 3120a7022e65SFelix Fietkau 3121a7022e65SFelix Fietkau void ieee80211_update_p2p_noa(struct ieee80211_noa_data *data, u32 tsf) 3122a7022e65SFelix Fietkau { 3123a7022e65SFelix Fietkau u32 next_offset = BIT(31) - 1; 3124a7022e65SFelix Fietkau int i; 3125a7022e65SFelix Fietkau 3126a7022e65SFelix Fietkau data->absent = 0; 3127a7022e65SFelix Fietkau data->has_next_tsf = false; 3128a7022e65SFelix Fietkau for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) { 3129a7022e65SFelix Fietkau s32 start; 3130a7022e65SFelix Fietkau 3131a7022e65SFelix Fietkau if (!data->count[i]) 3132a7022e65SFelix Fietkau continue; 3133a7022e65SFelix Fietkau 3134a7022e65SFelix Fietkau ieee80211_extend_noa_desc(data, tsf, i); 3135a7022e65SFelix Fietkau start = data->desc[i].start - tsf; 3136a7022e65SFelix Fietkau if (start <= 0) 3137a7022e65SFelix Fietkau data->absent |= BIT(i); 3138a7022e65SFelix Fietkau 3139a7022e65SFelix Fietkau if (next_offset > start) 3140a7022e65SFelix Fietkau next_offset = start; 3141a7022e65SFelix Fietkau 3142a7022e65SFelix Fietkau data->has_next_tsf = true; 3143a7022e65SFelix Fietkau } 3144a7022e65SFelix Fietkau 3145a7022e65SFelix Fietkau if (data->absent) 3146a7022e65SFelix Fietkau next_offset = ieee80211_get_noa_absent_time(data, tsf); 3147a7022e65SFelix Fietkau 3148a7022e65SFelix Fietkau data->next_tsf = tsf + next_offset; 3149a7022e65SFelix Fietkau } 3150a7022e65SFelix Fietkau EXPORT_SYMBOL(ieee80211_update_p2p_noa); 3151a7022e65SFelix Fietkau 3152a7022e65SFelix Fietkau int ieee80211_parse_p2p_noa(const struct ieee80211_p2p_noa_attr *attr, 3153a7022e65SFelix Fietkau struct ieee80211_noa_data *data, u32 tsf) 3154a7022e65SFelix Fietkau { 3155a7022e65SFelix Fietkau int ret = 0; 3156a7022e65SFelix Fietkau int i; 3157a7022e65SFelix Fietkau 3158a7022e65SFelix Fietkau memset(data, 0, sizeof(*data)); 3159a7022e65SFelix Fietkau 3160a7022e65SFelix Fietkau for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) { 3161a7022e65SFelix Fietkau const struct ieee80211_p2p_noa_desc *desc = &attr->desc[i]; 3162a7022e65SFelix Fietkau 3163a7022e65SFelix Fietkau if (!desc->count || !desc->duration) 3164a7022e65SFelix Fietkau continue; 3165a7022e65SFelix Fietkau 3166a7022e65SFelix Fietkau data->count[i] = desc->count; 3167a7022e65SFelix Fietkau data->desc[i].start = le32_to_cpu(desc->start_time); 3168a7022e65SFelix Fietkau data->desc[i].duration = le32_to_cpu(desc->duration); 3169a7022e65SFelix Fietkau data->desc[i].interval = le32_to_cpu(desc->interval); 3170a7022e65SFelix Fietkau 3171a7022e65SFelix Fietkau if (data->count[i] > 1 && 3172a7022e65SFelix Fietkau data->desc[i].interval < data->desc[i].duration) 3173a7022e65SFelix Fietkau continue; 3174a7022e65SFelix Fietkau 3175a7022e65SFelix Fietkau ieee80211_extend_noa_desc(data, tsf, i); 3176a7022e65SFelix Fietkau ret++; 3177a7022e65SFelix Fietkau } 3178a7022e65SFelix Fietkau 3179a7022e65SFelix Fietkau if (ret) 3180a7022e65SFelix Fietkau ieee80211_update_p2p_noa(data, tsf); 3181a7022e65SFelix Fietkau 3182a7022e65SFelix Fietkau return ret; 3183a7022e65SFelix Fietkau } 3184a7022e65SFelix Fietkau EXPORT_SYMBOL(ieee80211_parse_p2p_noa); 3185057d5f4bSThomas Pedersen 3186057d5f4bSThomas Pedersen void ieee80211_recalc_dtim(struct ieee80211_local *local, 3187057d5f4bSThomas Pedersen struct ieee80211_sub_if_data *sdata) 3188057d5f4bSThomas Pedersen { 3189057d5f4bSThomas Pedersen u64 tsf = drv_get_tsf(local, sdata); 3190057d5f4bSThomas Pedersen u64 dtim_count = 0; 3191057d5f4bSThomas Pedersen u16 beacon_int = sdata->vif.bss_conf.beacon_int * 1024; 3192057d5f4bSThomas Pedersen u8 dtim_period = sdata->vif.bss_conf.dtim_period; 3193057d5f4bSThomas Pedersen struct ps_data *ps; 3194057d5f4bSThomas Pedersen u8 bcns_from_dtim; 3195057d5f4bSThomas Pedersen 3196057d5f4bSThomas Pedersen if (tsf == -1ULL || !beacon_int || !dtim_period) 3197057d5f4bSThomas Pedersen return; 3198057d5f4bSThomas Pedersen 3199057d5f4bSThomas Pedersen if (sdata->vif.type == NL80211_IFTYPE_AP || 3200057d5f4bSThomas Pedersen sdata->vif.type == NL80211_IFTYPE_AP_VLAN) { 3201057d5f4bSThomas Pedersen if (!sdata->bss) 3202057d5f4bSThomas Pedersen return; 3203057d5f4bSThomas Pedersen 3204057d5f4bSThomas Pedersen ps = &sdata->bss->ps; 3205057d5f4bSThomas Pedersen } else if (ieee80211_vif_is_mesh(&sdata->vif)) { 3206057d5f4bSThomas Pedersen ps = &sdata->u.mesh.ps; 3207057d5f4bSThomas Pedersen } else { 3208057d5f4bSThomas Pedersen return; 3209057d5f4bSThomas Pedersen } 3210057d5f4bSThomas Pedersen 3211057d5f4bSThomas Pedersen /* 3212057d5f4bSThomas Pedersen * actually finds last dtim_count, mac80211 will update in 3213057d5f4bSThomas Pedersen * __beacon_add_tim(). 3214057d5f4bSThomas Pedersen * dtim_count = dtim_period - (tsf / bcn_int) % dtim_period 3215057d5f4bSThomas Pedersen */ 3216057d5f4bSThomas Pedersen do_div(tsf, beacon_int); 3217057d5f4bSThomas Pedersen bcns_from_dtim = do_div(tsf, dtim_period); 3218057d5f4bSThomas Pedersen /* just had a DTIM */ 3219057d5f4bSThomas Pedersen if (!bcns_from_dtim) 3220057d5f4bSThomas Pedersen dtim_count = 0; 3221057d5f4bSThomas Pedersen else 3222057d5f4bSThomas Pedersen dtim_count = dtim_period - bcns_from_dtim; 3223057d5f4bSThomas Pedersen 3224057d5f4bSThomas Pedersen ps->dtim_count = dtim_count; 3225057d5f4bSThomas Pedersen } 322673de86a3SLuciano Coelho 322771e6195eSMichal Kazior static u8 ieee80211_chanctx_radar_detect(struct ieee80211_local *local, 322871e6195eSMichal Kazior struct ieee80211_chanctx *ctx) 322971e6195eSMichal Kazior { 323071e6195eSMichal Kazior struct ieee80211_sub_if_data *sdata; 323171e6195eSMichal Kazior u8 radar_detect = 0; 323271e6195eSMichal Kazior 323371e6195eSMichal Kazior lockdep_assert_held(&local->chanctx_mtx); 323471e6195eSMichal Kazior 323571e6195eSMichal Kazior if (WARN_ON(ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED)) 323671e6195eSMichal Kazior return 0; 323771e6195eSMichal Kazior 323871e6195eSMichal Kazior list_for_each_entry(sdata, &ctx->reserved_vifs, reserved_chanctx_list) 323971e6195eSMichal Kazior if (sdata->reserved_radar_required) 324071e6195eSMichal Kazior radar_detect |= BIT(sdata->reserved_chandef.width); 324171e6195eSMichal Kazior 324271e6195eSMichal Kazior /* 324371e6195eSMichal Kazior * An in-place reservation context should not have any assigned vifs 324471e6195eSMichal Kazior * until it replaces the other context. 324571e6195eSMichal Kazior */ 324671e6195eSMichal Kazior WARN_ON(ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER && 324771e6195eSMichal Kazior !list_empty(&ctx->assigned_vifs)); 324871e6195eSMichal Kazior 324971e6195eSMichal Kazior list_for_each_entry(sdata, &ctx->assigned_vifs, assigned_chanctx_list) 325071e6195eSMichal Kazior if (sdata->radar_required) 325171e6195eSMichal Kazior radar_detect |= BIT(sdata->vif.bss_conf.chandef.width); 325271e6195eSMichal Kazior 325371e6195eSMichal Kazior return radar_detect; 325471e6195eSMichal Kazior } 325571e6195eSMichal Kazior 325673de86a3SLuciano Coelho int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata, 325773de86a3SLuciano Coelho const struct cfg80211_chan_def *chandef, 325873de86a3SLuciano Coelho enum ieee80211_chanctx_mode chanmode, 325973de86a3SLuciano Coelho u8 radar_detect) 326073de86a3SLuciano Coelho { 326173de86a3SLuciano Coelho struct ieee80211_local *local = sdata->local; 326273de86a3SLuciano Coelho struct ieee80211_sub_if_data *sdata_iter; 326373de86a3SLuciano Coelho enum nl80211_iftype iftype = sdata->wdev.iftype; 326473de86a3SLuciano Coelho int num[NUM_NL80211_IFTYPES]; 326573de86a3SLuciano Coelho struct ieee80211_chanctx *ctx; 3266b6a55015SLuciano Coelho int num_different_channels = 0; 326773de86a3SLuciano Coelho int total = 1; 326873de86a3SLuciano Coelho 326973de86a3SLuciano Coelho lockdep_assert_held(&local->chanctx_mtx); 327073de86a3SLuciano Coelho 327173de86a3SLuciano Coelho if (WARN_ON(hweight32(radar_detect) > 1)) 327273de86a3SLuciano Coelho return -EINVAL; 327373de86a3SLuciano Coelho 3274b6a55015SLuciano Coelho if (WARN_ON(chandef && chanmode == IEEE80211_CHANCTX_SHARED && 3275b6a55015SLuciano Coelho !chandef->chan)) 327673de86a3SLuciano Coelho return -EINVAL; 327773de86a3SLuciano Coelho 3278b6a55015SLuciano Coelho if (chandef) 3279b6a55015SLuciano Coelho num_different_channels = 1; 3280b6a55015SLuciano Coelho 328173de86a3SLuciano Coelho if (WARN_ON(iftype >= NUM_NL80211_IFTYPES)) 328273de86a3SLuciano Coelho return -EINVAL; 328373de86a3SLuciano Coelho 328473de86a3SLuciano Coelho /* Always allow software iftypes */ 328573de86a3SLuciano Coelho if (local->hw.wiphy->software_iftypes & BIT(iftype)) { 328673de86a3SLuciano Coelho if (radar_detect) 328773de86a3SLuciano Coelho return -EINVAL; 328873de86a3SLuciano Coelho return 0; 328973de86a3SLuciano Coelho } 329073de86a3SLuciano Coelho 329173de86a3SLuciano Coelho memset(num, 0, sizeof(num)); 329273de86a3SLuciano Coelho 329373de86a3SLuciano Coelho if (iftype != NL80211_IFTYPE_UNSPECIFIED) 329473de86a3SLuciano Coelho num[iftype] = 1; 329573de86a3SLuciano Coelho 329673de86a3SLuciano Coelho list_for_each_entry(ctx, &local->chanctx_list, list) { 32975bcae31dSMichal Kazior if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED) 32985bcae31dSMichal Kazior continue; 329971e6195eSMichal Kazior radar_detect |= ieee80211_chanctx_radar_detect(local, ctx); 330073de86a3SLuciano Coelho if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) { 330173de86a3SLuciano Coelho num_different_channels++; 330273de86a3SLuciano Coelho continue; 330373de86a3SLuciano Coelho } 3304b6a55015SLuciano Coelho if (chandef && chanmode == IEEE80211_CHANCTX_SHARED && 330573de86a3SLuciano Coelho cfg80211_chandef_compatible(chandef, 330673de86a3SLuciano Coelho &ctx->conf.def)) 330773de86a3SLuciano Coelho continue; 330873de86a3SLuciano Coelho num_different_channels++; 330973de86a3SLuciano Coelho } 331073de86a3SLuciano Coelho 331173de86a3SLuciano Coelho list_for_each_entry_rcu(sdata_iter, &local->interfaces, list) { 331273de86a3SLuciano Coelho struct wireless_dev *wdev_iter; 331373de86a3SLuciano Coelho 331473de86a3SLuciano Coelho wdev_iter = &sdata_iter->wdev; 331573de86a3SLuciano Coelho 331673de86a3SLuciano Coelho if (sdata_iter == sdata || 33170f611d28SAndrei Otcheretianski !ieee80211_sdata_running(sdata_iter) || 331873de86a3SLuciano Coelho local->hw.wiphy->software_iftypes & BIT(wdev_iter->iftype)) 331973de86a3SLuciano Coelho continue; 332073de86a3SLuciano Coelho 332173de86a3SLuciano Coelho num[wdev_iter->iftype]++; 332273de86a3SLuciano Coelho total++; 332373de86a3SLuciano Coelho } 332473de86a3SLuciano Coelho 332573de86a3SLuciano Coelho if (total == 1 && !radar_detect) 332673de86a3SLuciano Coelho return 0; 332773de86a3SLuciano Coelho 332873de86a3SLuciano Coelho return cfg80211_check_combinations(local->hw.wiphy, 332973de86a3SLuciano Coelho num_different_channels, 333073de86a3SLuciano Coelho radar_detect, num); 333173de86a3SLuciano Coelho } 33326fa001bcSMichal Kazior 33336fa001bcSMichal Kazior static void 33346fa001bcSMichal Kazior ieee80211_iter_max_chans(const struct ieee80211_iface_combination *c, 33356fa001bcSMichal Kazior void *data) 33366fa001bcSMichal Kazior { 33376fa001bcSMichal Kazior u32 *max_num_different_channels = data; 33386fa001bcSMichal Kazior 33396fa001bcSMichal Kazior *max_num_different_channels = max(*max_num_different_channels, 33406fa001bcSMichal Kazior c->num_different_channels); 33416fa001bcSMichal Kazior } 33426fa001bcSMichal Kazior 33436fa001bcSMichal Kazior int ieee80211_max_num_channels(struct ieee80211_local *local) 33446fa001bcSMichal Kazior { 33456fa001bcSMichal Kazior struct ieee80211_sub_if_data *sdata; 33466fa001bcSMichal Kazior int num[NUM_NL80211_IFTYPES] = {}; 33476fa001bcSMichal Kazior struct ieee80211_chanctx *ctx; 33486fa001bcSMichal Kazior int num_different_channels = 0; 33496fa001bcSMichal Kazior u8 radar_detect = 0; 33506fa001bcSMichal Kazior u32 max_num_different_channels = 1; 33516fa001bcSMichal Kazior int err; 33526fa001bcSMichal Kazior 33536fa001bcSMichal Kazior lockdep_assert_held(&local->chanctx_mtx); 33546fa001bcSMichal Kazior 33556fa001bcSMichal Kazior list_for_each_entry(ctx, &local->chanctx_list, list) { 33565bcae31dSMichal Kazior if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED) 33575bcae31dSMichal Kazior continue; 33585bcae31dSMichal Kazior 33596fa001bcSMichal Kazior num_different_channels++; 33606fa001bcSMichal Kazior 336171e6195eSMichal Kazior radar_detect |= ieee80211_chanctx_radar_detect(local, ctx); 33626fa001bcSMichal Kazior } 33636fa001bcSMichal Kazior 33646fa001bcSMichal Kazior list_for_each_entry_rcu(sdata, &local->interfaces, list) 33656fa001bcSMichal Kazior num[sdata->wdev.iftype]++; 33666fa001bcSMichal Kazior 33676fa001bcSMichal Kazior err = cfg80211_iter_combinations(local->hw.wiphy, 33686fa001bcSMichal Kazior num_different_channels, radar_detect, 33696fa001bcSMichal Kazior num, ieee80211_iter_max_chans, 33706fa001bcSMichal Kazior &max_num_different_channels); 33716fa001bcSMichal Kazior if (err < 0) 33726fa001bcSMichal Kazior return err; 33736fa001bcSMichal Kazior 33746fa001bcSMichal Kazior return max_num_different_channels; 33756fa001bcSMichal Kazior } 337640b861a0SArik Nemtsov 337740b861a0SArik Nemtsov u8 *ieee80211_add_wmm_info_ie(u8 *buf, u8 qosinfo) 337840b861a0SArik Nemtsov { 337940b861a0SArik Nemtsov *buf++ = WLAN_EID_VENDOR_SPECIFIC; 338040b861a0SArik Nemtsov *buf++ = 7; /* len */ 338140b861a0SArik Nemtsov *buf++ = 0x00; /* Microsoft OUI 00:50:F2 */ 338240b861a0SArik Nemtsov *buf++ = 0x50; 338340b861a0SArik Nemtsov *buf++ = 0xf2; 338440b861a0SArik Nemtsov *buf++ = 2; /* WME */ 338540b861a0SArik Nemtsov *buf++ = 0; /* WME info */ 338640b861a0SArik Nemtsov *buf++ = 1; /* WME ver */ 338740b861a0SArik Nemtsov *buf++ = qosinfo; /* U-APSD no in use */ 338840b861a0SArik Nemtsov 338940b861a0SArik Nemtsov return buf; 339040b861a0SArik Nemtsov } 3391ba8c3d6fSFelix Fietkau 3392f2ac7e30SMichal Kazior void ieee80211_txq_get_depth(struct ieee80211_txq *txq, 3393f2ac7e30SMichal Kazior unsigned long *frame_cnt, 3394f2ac7e30SMichal Kazior unsigned long *byte_cnt) 3395f2ac7e30SMichal Kazior { 3396f2ac7e30SMichal Kazior struct txq_info *txqi = to_txq_info(txq); 3397f2ac7e30SMichal Kazior 3398f2ac7e30SMichal Kazior if (frame_cnt) 3399fa962b92SMichal Kazior *frame_cnt = txqi->tin.backlog_packets; 3400f2ac7e30SMichal Kazior 3401f2ac7e30SMichal Kazior if (byte_cnt) 3402fa962b92SMichal Kazior *byte_cnt = txqi->tin.backlog_bytes; 3403f2ac7e30SMichal Kazior } 3404f2ac7e30SMichal Kazior EXPORT_SYMBOL(ieee80211_txq_get_depth); 3405