blob: 1495b9e39484c945a6ac818c4130a308da0ab070 [file] [log] [blame]
Johannes Berg44d414d2008-09-08 17:44:28 +02001/*
2 * HT handling
3 *
4 * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
Johannes Bergbacac542008-09-08 17:44:29 +02005 * Copyright 2002-2005, Instant802 Networks, Inc.
6 * Copyright 2005-2006, Devicescape Software, Inc.
Johannes Berg44d414d2008-09-08 17:44:28 +02007 * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
8 * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
Johannes Bergcfcdbde2010-06-10 10:21:48 +02009 * Copyright 2007-2010, Intel Corporation
Johannes Berg44d414d2008-09-08 17:44:28 +020010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/ieee80211.h>
Paul Gortmakerbc3b2d72011-07-15 11:47:34 -040017#include <linux/export.h>
Johannes Berg44d414d2008-09-08 17:44:28 +020018#include <net/mac80211.h>
19#include "ieee80211_i.h"
Sujith81cb7622009-02-12 11:38:37 +053020#include "rate.h"
Johannes Berg44d414d2008-09-08 17:44:28 +020021
Simon Wunderlich822854b2013-06-28 10:39:59 +020022static void __check_htcap_disable(struct ieee80211_ht_cap *ht_capa,
23 struct ieee80211_ht_cap *ht_capa_mask,
Ben Greear32dfefa2011-11-24 11:15:21 -080024 struct ieee80211_sta_ht_cap *ht_cap,
25 u16 flag)
Ben Greearef96a8422011-11-18 11:32:00 -080026{
27 __le16 le_flag = cpu_to_le16(flag);
Simon Wunderlich822854b2013-06-28 10:39:59 +020028 if (ht_capa_mask->cap_info & le_flag) {
29 if (!(ht_capa->cap_info & le_flag))
Ben Greearef96a8422011-11-18 11:32:00 -080030 ht_cap->cap &= ~flag;
31 }
32}
33
34void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
35 struct ieee80211_sta_ht_cap *ht_cap)
36{
Simon Wunderlich822854b2013-06-28 10:39:59 +020037 struct ieee80211_ht_cap *ht_capa, *ht_capa_mask;
38 u8 *scaps, *smask;
Ben Greearef96a8422011-11-18 11:32:00 -080039 int i;
40
Johannes Berge1a0c6b2013-02-07 11:47:44 +010041 if (!ht_cap->ht_supported)
42 return;
43
Simon Wunderlich822854b2013-06-28 10:39:59 +020044 switch (sdata->vif.type) {
45 case NL80211_IFTYPE_STATION:
46 ht_capa = &sdata->u.mgd.ht_capa;
47 ht_capa_mask = &sdata->u.mgd.ht_capa_mask;
48 break;
49 case NL80211_IFTYPE_ADHOC:
50 ht_capa = &sdata->u.ibss.ht_capa;
51 ht_capa_mask = &sdata->u.ibss.ht_capa_mask;
52 break;
53 default:
54 WARN_ON_ONCE(1);
55 return;
56 }
57
58 scaps = (u8 *)(&ht_capa->mcs.rx_mask);
59 smask = (u8 *)(&ht_capa_mask->mcs.rx_mask);
60
Ben Greearef96a8422011-11-18 11:32:00 -080061 /* NOTE: If you add more over-rides here, update register_hw
62 * ht_capa_mod_msk logic in main.c as well.
63 * And, if this method can ever change ht_cap.ht_supported, fix
64 * the check in ieee80211_add_ht_ie.
65 */
66
67 /* check for HT over-rides, MCS rates first. */
68 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
69 u8 m = smask[i];
70 ht_cap->mcs.rx_mask[i] &= ~m; /* turn off all masked bits */
71 /* Add back rates that are supported */
72 ht_cap->mcs.rx_mask[i] |= (m & scaps[i]);
73 }
74
75 /* Force removal of HT-40 capabilities? */
Simon Wunderlich822854b2013-06-28 10:39:59 +020076 __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
77 IEEE80211_HT_CAP_SUP_WIDTH_20_40);
78 __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
79 IEEE80211_HT_CAP_SGI_40);
Ben Greearef96a8422011-11-18 11:32:00 -080080
Ben Greearbc0784d2012-12-12 16:56:20 -080081 /* Allow user to disable SGI-20 (SGI-40 is handled above) */
Simon Wunderlich822854b2013-06-28 10:39:59 +020082 __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
83 IEEE80211_HT_CAP_SGI_20);
Ben Greearbc0784d2012-12-12 16:56:20 -080084
Ben Greearef96a8422011-11-18 11:32:00 -080085 /* Allow user to disable the max-AMSDU bit. */
Simon Wunderlich822854b2013-06-28 10:39:59 +020086 __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
87 IEEE80211_HT_CAP_MAX_AMSDU);
Ben Greearef96a8422011-11-18 11:32:00 -080088
Pawel Kulakowskia2e74952014-04-01 07:13:21 +020089 /* Allow user to disable LDPC */
90 __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
91 IEEE80211_HT_CAP_LDPC_CODING);
92
Ben Greearef96a8422011-11-18 11:32:00 -080093 /* Allow user to decrease AMPDU factor */
Simon Wunderlich822854b2013-06-28 10:39:59 +020094 if (ht_capa_mask->ampdu_params_info &
Ben Greearef96a8422011-11-18 11:32:00 -080095 IEEE80211_HT_AMPDU_PARM_FACTOR) {
Simon Wunderlich822854b2013-06-28 10:39:59 +020096 u8 n = ht_capa->ampdu_params_info &
97 IEEE80211_HT_AMPDU_PARM_FACTOR;
Ben Greearef96a8422011-11-18 11:32:00 -080098 if (n < ht_cap->ampdu_factor)
99 ht_cap->ampdu_factor = n;
100 }
101
102 /* Allow the user to increase AMPDU density. */
Simon Wunderlich822854b2013-06-28 10:39:59 +0200103 if (ht_capa_mask->ampdu_params_info &
Ben Greearef96a8422011-11-18 11:32:00 -0800104 IEEE80211_HT_AMPDU_PARM_DENSITY) {
Simon Wunderlich822854b2013-06-28 10:39:59 +0200105 u8 n = (ht_capa->ampdu_params_info &
Ben Greearef96a8422011-11-18 11:32:00 -0800106 IEEE80211_HT_AMPDU_PARM_DENSITY)
107 >> IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT;
108 if (n > ht_cap->ampdu_density)
109 ht_cap->ampdu_density = n;
110 }
111}
112
113
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100114bool ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data *sdata,
Ben Greearef96a8422011-11-18 11:32:00 -0800115 struct ieee80211_supported_band *sband,
Johannes Berg4a3cb702013-02-12 16:43:19 +0100116 const struct ieee80211_ht_cap *ht_cap_ie,
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100117 struct sta_info *sta)
Johannes Berg44d414d2008-09-08 17:44:28 +0200118{
Johannes Bergc07270b2013-03-01 11:54:43 +0100119 struct ieee80211_sta_ht_cap ht_cap, own_cap;
Johannes Bergae5eb022008-10-14 16:58:37 +0200120 u8 ampdu_info, tx_mcs_set_cap;
121 int i, max_tx_streams;
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100122 bool changed;
123 enum ieee80211_sta_rx_bandwidth bw;
Johannes Bergaf0ed692013-02-12 14:21:00 +0100124 enum ieee80211_smps_mode smps_mode;
Johannes Berg44d414d2008-09-08 17:44:28 +0200125
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100126 memset(&ht_cap, 0, sizeof(ht_cap));
Johannes Berg44d414d2008-09-08 17:44:28 +0200127
Christian Lamparter15804e32010-07-16 13:01:24 +0200128 if (!ht_cap_ie || !sband->ht_cap.ht_supported)
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100129 goto apply;
Johannes Berg44d414d2008-09-08 17:44:28 +0200130
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100131 ht_cap.ht_supported = true;
Johannes Berg44d414d2008-09-08 17:44:28 +0200132
Johannes Bergc07270b2013-03-01 11:54:43 +0100133 own_cap = sband->ht_cap;
134
135 /*
136 * If user has specified capability over-rides, take care
137 * of that if the station we're setting up is the AP that
138 * we advertised a restricted capability set to. Override
139 * our own capabilities and then use those below.
140 */
Simon Wunderlich822854b2013-06-28 10:39:59 +0200141 if ((sdata->vif.type == NL80211_IFTYPE_STATION ||
142 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
Johannes Bergc07270b2013-03-01 11:54:43 +0100143 !test_sta_flag(sta, WLAN_STA_TDLS_PEER))
144 ieee80211_apply_htcap_overrides(sdata, &own_cap);
145
Johannes Berg9a418af2009-12-17 13:55:48 +0100146 /*
147 * The bits listed in this expression should be
148 * the same for the peer and us, if the station
149 * advertises more then we can't use those thus
150 * we mask them out.
151 */
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100152 ht_cap.cap = le16_to_cpu(ht_cap_ie->cap_info) &
Johannes Bergc07270b2013-03-01 11:54:43 +0100153 (own_cap.cap | ~(IEEE80211_HT_CAP_LDPC_CODING |
154 IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
155 IEEE80211_HT_CAP_GRN_FLD |
156 IEEE80211_HT_CAP_SGI_20 |
157 IEEE80211_HT_CAP_SGI_40 |
158 IEEE80211_HT_CAP_DSSSCCK40));
Johannes Berg21add822012-12-28 15:01:57 +0100159
Johannes Berg9a418af2009-12-17 13:55:48 +0100160 /*
161 * The STBC bits are asymmetric -- if we don't have
162 * TX then mask out the peer's RX and vice versa.
163 */
Johannes Bergc07270b2013-03-01 11:54:43 +0100164 if (!(own_cap.cap & IEEE80211_HT_CAP_TX_STBC))
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100165 ht_cap.cap &= ~IEEE80211_HT_CAP_RX_STBC;
Johannes Bergc07270b2013-03-01 11:54:43 +0100166 if (!(own_cap.cap & IEEE80211_HT_CAP_RX_STBC))
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100167 ht_cap.cap &= ~IEEE80211_HT_CAP_TX_STBC;
Johannes Berg44d414d2008-09-08 17:44:28 +0200168
Johannes Bergae5eb022008-10-14 16:58:37 +0200169 ampdu_info = ht_cap_ie->ampdu_params_info;
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100170 ht_cap.ampdu_factor =
Johannes Bergae5eb022008-10-14 16:58:37 +0200171 ampdu_info & IEEE80211_HT_AMPDU_PARM_FACTOR;
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100172 ht_cap.ampdu_density =
Johannes Bergae5eb022008-10-14 16:58:37 +0200173 (ampdu_info & IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200174
175 /* own MCS TX capabilities */
Johannes Bergc07270b2013-03-01 11:54:43 +0100176 tx_mcs_set_cap = own_cap.mcs.tx_params;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200177
Johannes Berg90b4ca92011-02-25 12:24:10 +0100178 /* Copy peer MCS TX capabilities, the driver might need them. */
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100179 ht_cap.mcs.tx_params = ht_cap_ie->mcs.tx_params;
Johannes Berg90b4ca92011-02-25 12:24:10 +0100180
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200181 /* can we TX with MCS rates? */
182 if (!(tx_mcs_set_cap & IEEE80211_HT_MCS_TX_DEFINED))
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100183 goto apply;
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200184
185 /* Counting from 0, therefore +1 */
186 if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_RX_DIFF)
187 max_tx_streams =
188 ((tx_mcs_set_cap & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
189 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
190 else
191 max_tx_streams = IEEE80211_HT_MCS_TX_MAX_STREAMS;
192
193 /*
Johannes Berg90b4ca92011-02-25 12:24:10 +0100194 * 802.11n-2009 20.3.5 / 20.6 says:
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200195 * - indices 0 to 7 and 32 are single spatial stream
196 * - 8 to 31 are multiple spatial streams using equal modulation
197 * [8..15 for two streams, 16..23 for three and 24..31 for four]
198 * - remainder are multiple spatial streams using unequal modulation
199 */
200 for (i = 0; i < max_tx_streams; i++)
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100201 ht_cap.mcs.rx_mask[i] =
Johannes Bergc07270b2013-03-01 11:54:43 +0100202 own_cap.mcs.rx_mask[i] & ht_cap_ie->mcs.rx_mask[i];
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200203
204 if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION)
205 for (i = IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE;
206 i < IEEE80211_HT_MCS_MASK_LEN; i++)
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100207 ht_cap.mcs.rx_mask[i] =
Johannes Bergc07270b2013-03-01 11:54:43 +0100208 own_cap.mcs.rx_mask[i] &
Johannes Bergae5eb022008-10-14 16:58:37 +0200209 ht_cap_ie->mcs.rx_mask[i];
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200210
211 /* handle MCS rate 32 too */
Johannes Bergc07270b2013-03-01 11:54:43 +0100212 if (own_cap.mcs.rx_mask[32/8] & ht_cap_ie->mcs.rx_mask[32/8] & 1)
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100213 ht_cap.mcs.rx_mask[32/8] |= 1;
Ben Greearef96a8422011-11-18 11:32:00 -0800214
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100215 apply:
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100216 changed = memcmp(&sta->sta.ht_cap, &ht_cap, sizeof(ht_cap));
217
218 memcpy(&sta->sta.ht_cap, &ht_cap, sizeof(ht_cap));
219
220 switch (sdata->vif.bss_conf.chandef.width) {
221 default:
222 WARN_ON_ONCE(1);
223 /* fall through */
224 case NL80211_CHAN_WIDTH_20_NOHT:
225 case NL80211_CHAN_WIDTH_20:
226 bw = IEEE80211_STA_RX_BW_20;
227 break;
228 case NL80211_CHAN_WIDTH_40:
229 case NL80211_CHAN_WIDTH_80:
230 case NL80211_CHAN_WIDTH_80P80:
231 case NL80211_CHAN_WIDTH_160:
232 bw = ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
233 IEEE80211_STA_RX_BW_40 : IEEE80211_STA_RX_BW_20;
234 break;
235 }
236
237 if (bw != sta->sta.bandwidth)
238 changed = true;
239 sta->sta.bandwidth = bw;
240
Johannes Berg0af83d32012-12-27 18:55:36 +0100241 sta->cur_max_bandwidth =
242 ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
243 IEEE80211_STA_RX_BW_40 : IEEE80211_STA_RX_BW_20;
244
Johannes Bergaf0ed692013-02-12 14:21:00 +0100245 switch ((ht_cap.cap & IEEE80211_HT_CAP_SM_PS)
246 >> IEEE80211_HT_CAP_SM_PS_SHIFT) {
247 case WLAN_HT_CAP_SM_PS_INVALID:
248 case WLAN_HT_CAP_SM_PS_STATIC:
249 smps_mode = IEEE80211_SMPS_STATIC;
250 break;
251 case WLAN_HT_CAP_SM_PS_DYNAMIC:
252 smps_mode = IEEE80211_SMPS_DYNAMIC;
253 break;
254 case WLAN_HT_CAP_SM_PS_DISABLED:
255 smps_mode = IEEE80211_SMPS_OFF;
256 break;
257 }
258
259 if (smps_mode != sta->sta.smps_mode)
260 changed = true;
261 sta->sta.smps_mode = smps_mode;
262
Johannes Berge1a0c6b2013-02-07 11:47:44 +0100263 return changed;
Johannes Bergae5eb022008-10-14 16:58:37 +0200264}
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200265
Johannes Bergc82c4a82012-07-18 13:31:31 +0200266void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta,
267 enum ieee80211_agg_stop_reason reason)
Johannes Berg44d414d2008-09-08 17:44:28 +0200268{
Johannes Bergb8695a82009-02-10 21:25:46 +0100269 int i;
Johannes Berg44d414d2008-09-08 17:44:28 +0200270
Johannes Berg0ab33702010-06-10 10:21:42 +0200271 cancel_work_sync(&sta->ampdu_mlme.work);
272
Johannes Berg5a306f52012-11-14 23:22:21 +0100273 for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
Johannes Bergc82c4a82012-07-18 13:31:31 +0200274 __ieee80211_stop_tx_ba_session(sta, i, reason);
Johannes Berg849b7962009-02-10 21:25:54 +0100275 __ieee80211_stop_rx_ba_session(sta, i, WLAN_BACK_RECIPIENT,
Johannes Bergc82c4a82012-07-18 13:31:31 +0200276 WLAN_REASON_QSTA_LEAVE_QBSS,
277 reason != AGG_STOP_DESTROY_STA &&
278 reason != AGG_STOP_PEER_REQUEST);
Johannes Berg44d414d2008-09-08 17:44:28 +0200279 }
Johannes Berg44d414d2008-09-08 17:44:28 +0200280}
281
Johannes Berg67c282c2010-06-10 10:21:43 +0200282void ieee80211_ba_session_work(struct work_struct *work)
283{
284 struct sta_info *sta =
285 container_of(work, struct sta_info, ampdu_mlme.work);
286 struct tid_ampdu_tx *tid_tx;
287 int tid;
288
289 /*
290 * When this flag is set, new sessions should be
291 * blocked, and existing sessions will be torn
292 * down by the code that set the flag, so this
293 * need not run.
294 */
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200295 if (test_sta_flag(sta, WLAN_STA_BLOCK_BA))
Johannes Berg67c282c2010-06-10 10:21:43 +0200296 return;
297
Johannes Berga93e3642010-06-10 10:21:46 +0200298 mutex_lock(&sta->ampdu_mlme.mtx);
Johannes Berg5a306f52012-11-14 23:22:21 +0100299 for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
Johannes Berg7c3b1dd2010-06-10 10:21:44 +0200300 if (test_and_clear_bit(tid, sta->ampdu_mlme.tid_rx_timer_expired))
301 ___ieee80211_stop_rx_ba_session(
302 sta, tid, WLAN_BACK_RECIPIENT,
Johannes Berg53f73c02010-10-05 19:37:40 +0200303 WLAN_REASON_QSTA_TIMEOUT, true);
Johannes Berg7c3b1dd2010-06-10 10:21:44 +0200304
Shahar Levif41ccd72011-05-22 16:10:21 +0300305 if (test_and_clear_bit(tid,
306 sta->ampdu_mlme.tid_rx_stop_requested))
307 ___ieee80211_stop_rx_ba_session(
308 sta, tid, WLAN_BACK_RECIPIENT,
309 WLAN_REASON_UNSPECIFIED, true);
310
Ben Greeare5620782013-06-12 14:08:44 -0700311 spin_lock_bh(&sta->lock);
312
Johannes Bergec034b22011-05-13 13:35:40 +0200313 tid_tx = sta->ampdu_mlme.tid_start_tx[tid];
314 if (tid_tx) {
315 /*
316 * Assign it over to the normal tid_tx array
317 * where it "goes live".
318 */
Johannes Berg67c282c2010-06-10 10:21:43 +0200319
Johannes Bergec034b22011-05-13 13:35:40 +0200320 sta->ampdu_mlme.tid_start_tx[tid] = NULL;
321 /* could there be a race? */
322 if (sta->ampdu_mlme.tid_tx[tid])
323 kfree(tid_tx);
324 else
325 ieee80211_assign_tid_tx(sta, tid, tid_tx);
326 spin_unlock_bh(&sta->lock);
327
Johannes Berg67c282c2010-06-10 10:21:43 +0200328 ieee80211_tx_ba_session_handle_start(sta, tid);
Johannes Bergec034b22011-05-13 13:35:40 +0200329 continue;
330 }
Ben Greeare5620782013-06-12 14:08:44 -0700331 spin_unlock_bh(&sta->lock);
Johannes Bergec034b22011-05-13 13:35:40 +0200332
Johannes Berg40b275b2011-05-13 14:15:49 +0200333 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
Johannes Bergec034b22011-05-13 13:35:40 +0200334 if (tid_tx && test_and_clear_bit(HT_AGG_STATE_WANT_STOP,
335 &tid_tx->state))
Johannes Berg67c282c2010-06-10 10:21:43 +0200336 ___ieee80211_stop_tx_ba_session(sta, tid,
Johannes Bergc82c4a82012-07-18 13:31:31 +0200337 AGG_STOP_LOCAL_REQUEST);
Johannes Berg67c282c2010-06-10 10:21:43 +0200338 }
Johannes Bergcfcdbde2010-06-10 10:21:48 +0200339 mutex_unlock(&sta->ampdu_mlme.mtx);
Johannes Berg67c282c2010-06-10 10:21:43 +0200340}
341
Johannes Bergb8695a82009-02-10 21:25:46 +0100342void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
343 const u8 *da, u16 tid,
344 u16 initiator, u16 reason_code)
Johannes Berg44d414d2008-09-08 17:44:28 +0200345{
346 struct ieee80211_local *local = sdata->local;
Johannes Berg44d414d2008-09-08 17:44:28 +0200347 struct sk_buff *skb;
348 struct ieee80211_mgmt *mgmt;
349 u16 params;
350
351 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
Joe Perchesd15b8452011-08-29 14:17:31 -0700352 if (!skb)
Johannes Berg44d414d2008-09-08 17:44:28 +0200353 return;
Johannes Berg44d414d2008-09-08 17:44:28 +0200354
355 skb_reserve(skb, local->hw.extra_tx_headroom);
356 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
357 memset(mgmt, 0, 24);
358 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100359 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg8abd3f92009-02-10 21:25:47 +0100360 if (sdata->vif.type == NL80211_IFTYPE_AP ||
Thomas Pedersenae2772b2011-10-26 14:47:29 -0700361 sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
362 sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
Johannes Berg47846c92009-11-25 17:46:19 +0100363 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100364 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
365 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
Alexander Simon13c40c52011-11-30 16:56:34 +0100366 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
367 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100368
Johannes Berg44d414d2008-09-08 17:44:28 +0200369 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
370 IEEE80211_STYPE_ACTION);
371
372 skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
373
374 mgmt->u.action.category = WLAN_CATEGORY_BACK;
375 mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
376 params = (u16)(initiator << 11); /* bit 11 initiator */
377 params |= (u16)(tid << 12); /* bit 15:12 TID number */
378
379 mgmt->u.action.u.delba.params = cpu_to_le16(params);
380 mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
381
Karl Beldanc6e13322014-01-23 20:06:34 +0100382 ieee80211_tx_skb(sdata, skb);
Johannes Berg44d414d2008-09-08 17:44:28 +0200383}
384
Johannes Bergde1ede72008-09-09 14:42:50 +0200385void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
386 struct sta_info *sta,
387 struct ieee80211_mgmt *mgmt, size_t len)
388{
Johannes Bergde1ede72008-09-09 14:42:50 +0200389 u16 tid, params;
390 u16 initiator;
Johannes Bergde1ede72008-09-09 14:42:50 +0200391
392 params = le16_to_cpu(mgmt->u.action.u.delba.params);
393 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
394 initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
395
Johannes Bergbdcbd8e2012-06-22 11:29:50 +0200396 ht_dbg_ratelimited(sdata, "delba from %pM (%s) tid %d reason code %d\n",
397 mgmt->sa, initiator ? "initiator" : "recipient",
398 tid,
399 le16_to_cpu(mgmt->u.action.u.delba.reason_code));
Johannes Bergde1ede72008-09-09 14:42:50 +0200400
401 if (initiator == WLAN_BACK_INITIATOR)
Johannes Berg53f73c02010-10-05 19:37:40 +0200402 __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_INITIATOR, 0,
403 true);
Johannes Berga622ab72010-06-10 10:21:39 +0200404 else
Johannes Bergc82c4a82012-07-18 13:31:31 +0200405 __ieee80211_stop_tx_ba_session(sta, tid, AGG_STOP_PEER_REQUEST);
Johannes Bergde1ede72008-09-09 14:42:50 +0200406}
Johannes Berg0f782312009-12-01 13:37:02 +0100407
408int ieee80211_send_smps_action(struct ieee80211_sub_if_data *sdata,
409 enum ieee80211_smps_mode smps, const u8 *da,
410 const u8 *bssid)
411{
412 struct ieee80211_local *local = sdata->local;
413 struct sk_buff *skb;
414 struct ieee80211_mgmt *action_frame;
415
416 /* 27 = header + category + action + smps mode */
417 skb = dev_alloc_skb(27 + local->hw.extra_tx_headroom);
418 if (!skb)
419 return -ENOMEM;
420
421 skb_reserve(skb, local->hw.extra_tx_headroom);
422 action_frame = (void *)skb_put(skb, 27);
423 memcpy(action_frame->da, da, ETH_ALEN);
424 memcpy(action_frame->sa, sdata->dev->dev_addr, ETH_ALEN);
425 memcpy(action_frame->bssid, bssid, ETH_ALEN);
426 action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
427 IEEE80211_STYPE_ACTION);
428 action_frame->u.action.category = WLAN_CATEGORY_HT;
429 action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
430 switch (smps) {
431 case IEEE80211_SMPS_AUTOMATIC:
432 case IEEE80211_SMPS_NUM_MODES:
433 WARN_ON(1);
434 case IEEE80211_SMPS_OFF:
435 action_frame->u.action.u.ht_smps.smps_control =
436 WLAN_HT_SMPS_CONTROL_DISABLED;
437 break;
438 case IEEE80211_SMPS_STATIC:
439 action_frame->u.action.u.ht_smps.smps_control =
440 WLAN_HT_SMPS_CONTROL_STATIC;
441 break;
442 case IEEE80211_SMPS_DYNAMIC:
443 action_frame->u.action.u.ht_smps.smps_control =
444 WLAN_HT_SMPS_CONTROL_DYNAMIC;
445 break;
446 }
447
448 /* we'll do more on status of this frame */
449 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
450 ieee80211_tx_skb(sdata, skb);
451
452 return 0;
453}
Johannes Bergd1f5b7a2010-08-05 17:05:55 +0200454
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300455void ieee80211_request_smps_mgd_work(struct work_struct *work)
Johannes Bergd1f5b7a2010-08-05 17:05:55 +0200456{
457 struct ieee80211_sub_if_data *sdata =
458 container_of(work, struct ieee80211_sub_if_data,
459 u.mgd.request_smps_work);
460
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200461 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300462 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.driver_smps_mode);
463 sdata_unlock(sdata);
464}
465
466void ieee80211_request_smps_ap_work(struct work_struct *work)
467{
468 struct ieee80211_sub_if_data *sdata =
469 container_of(work, struct ieee80211_sub_if_data,
470 u.ap.request_smps_work);
471
472 sdata_lock(sdata);
Emmanuel Grumbach8ffcc702014-01-23 14:28:16 +0200473 if (sdata_dereference(sdata->u.ap.beacon, sdata))
474 __ieee80211_request_smps_ap(sdata,
475 sdata->u.ap.driver_smps_mode);
Johannes Berg8d61ffa2013-05-10 12:32:47 +0200476 sdata_unlock(sdata);
Johannes Bergd1f5b7a2010-08-05 17:05:55 +0200477}
478
479void ieee80211_request_smps(struct ieee80211_vif *vif,
480 enum ieee80211_smps_mode smps_mode)
481{
482 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
483
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300484 if (WARN_ON_ONCE(vif->type != NL80211_IFTYPE_STATION &&
485 vif->type != NL80211_IFTYPE_AP))
Johannes Bergd1f5b7a2010-08-05 17:05:55 +0200486 return;
487
Emmanuel Grumbach687da132013-10-01 16:45:43 +0300488 if (vif->type == NL80211_IFTYPE_STATION) {
489 if (sdata->u.mgd.driver_smps_mode == smps_mode)
490 return;
491 sdata->u.mgd.driver_smps_mode = smps_mode;
492 ieee80211_queue_work(&sdata->local->hw,
493 &sdata->u.mgd.request_smps_work);
494 } else {
495 /* AUTOMATIC is meaningless in AP mode */
496 if (WARN_ON_ONCE(smps_mode == IEEE80211_SMPS_AUTOMATIC))
497 return;
498 if (sdata->u.ap.driver_smps_mode == smps_mode)
499 return;
500 sdata->u.ap.driver_smps_mode = smps_mode;
501 ieee80211_queue_work(&sdata->local->hw,
502 &sdata->u.ap.request_smps_work);
503 }
Johannes Bergd1f5b7a2010-08-05 17:05:55 +0200504}
505/* this might change ... don't want non-open drivers using it */
506EXPORT_SYMBOL_GPL(ieee80211_request_smps);