ht.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * HT handling
  4. *
  5. * Copyright 2003, Jouni Malinen <[email protected]>
  6. * Copyright 2002-2005, Instant802 Networks, Inc.
  7. * Copyright 2005-2006, Devicescape Software, Inc.
  8. * Copyright 2006-2007 Jiri Benc <[email protected]>
  9. * Copyright 2007, Michael Wu <[email protected]>
  10. * Copyright 2007-2010, Intel Corporation
  11. * Copyright 2017 Intel Deutschland GmbH
  12. * Copyright(c) 2020-2022 Intel Corporation
  13. */
  14. #include <linux/ieee80211.h>
  15. #include <linux/export.h>
  16. #include <net/mac80211.h>
  17. #include "ieee80211_i.h"
  18. #include "rate.h"
  19. static void __check_htcap_disable(struct ieee80211_ht_cap *ht_capa,
  20. struct ieee80211_ht_cap *ht_capa_mask,
  21. struct ieee80211_sta_ht_cap *ht_cap,
  22. u16 flag)
  23. {
  24. __le16 le_flag = cpu_to_le16(flag);
  25. if (ht_capa_mask->cap_info & le_flag) {
  26. if (!(ht_capa->cap_info & le_flag))
  27. ht_cap->cap &= ~flag;
  28. }
  29. }
  30. static void __check_htcap_enable(struct ieee80211_ht_cap *ht_capa,
  31. struct ieee80211_ht_cap *ht_capa_mask,
  32. struct ieee80211_sta_ht_cap *ht_cap,
  33. u16 flag)
  34. {
  35. __le16 le_flag = cpu_to_le16(flag);
  36. if ((ht_capa_mask->cap_info & le_flag) &&
  37. (ht_capa->cap_info & le_flag))
  38. ht_cap->cap |= flag;
  39. }
  40. void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
  41. struct ieee80211_sta_ht_cap *ht_cap)
  42. {
  43. struct ieee80211_ht_cap *ht_capa, *ht_capa_mask;
  44. u8 *scaps, *smask;
  45. int i;
  46. if (!ht_cap->ht_supported)
  47. return;
  48. switch (sdata->vif.type) {
  49. case NL80211_IFTYPE_STATION:
  50. ht_capa = &sdata->u.mgd.ht_capa;
  51. ht_capa_mask = &sdata->u.mgd.ht_capa_mask;
  52. break;
  53. case NL80211_IFTYPE_ADHOC:
  54. ht_capa = &sdata->u.ibss.ht_capa;
  55. ht_capa_mask = &sdata->u.ibss.ht_capa_mask;
  56. break;
  57. default:
  58. WARN_ON_ONCE(1);
  59. return;
  60. }
  61. scaps = (u8 *)(&ht_capa->mcs.rx_mask);
  62. smask = (u8 *)(&ht_capa_mask->mcs.rx_mask);
  63. /* NOTE: If you add more over-rides here, update register_hw
  64. * ht_capa_mod_mask logic in main.c as well.
  65. * And, if this method can ever change ht_cap.ht_supported, fix
  66. * the check in ieee80211_add_ht_ie.
  67. */
  68. /* check for HT over-rides, MCS rates first. */
  69. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
  70. u8 m = smask[i];
  71. ht_cap->mcs.rx_mask[i] &= ~m; /* turn off all masked bits */
  72. /* Add back rates that are supported */
  73. ht_cap->mcs.rx_mask[i] |= (m & scaps[i]);
  74. }
  75. /* Force removal of HT-40 capabilities? */
  76. __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);
  80. /* Allow user to disable SGI-20 (SGI-40 is handled above) */
  81. __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
  82. IEEE80211_HT_CAP_SGI_20);
  83. /* Allow user to disable the max-AMSDU bit. */
  84. __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
  85. IEEE80211_HT_CAP_MAX_AMSDU);
  86. /* Allow user to disable LDPC */
  87. __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
  88. IEEE80211_HT_CAP_LDPC_CODING);
  89. /* Allow user to enable 40 MHz intolerant bit. */
  90. __check_htcap_enable(ht_capa, ht_capa_mask, ht_cap,
  91. IEEE80211_HT_CAP_40MHZ_INTOLERANT);
  92. /* Allow user to enable TX STBC bit */
  93. __check_htcap_enable(ht_capa, ht_capa_mask, ht_cap,
  94. IEEE80211_HT_CAP_TX_STBC);
  95. /* Allow user to configure RX STBC bits */
  96. if (ht_capa_mask->cap_info & cpu_to_le16(IEEE80211_HT_CAP_RX_STBC))
  97. ht_cap->cap |= le16_to_cpu(ht_capa->cap_info) &
  98. IEEE80211_HT_CAP_RX_STBC;
  99. /* Allow user to decrease AMPDU factor */
  100. if (ht_capa_mask->ampdu_params_info &
  101. IEEE80211_HT_AMPDU_PARM_FACTOR) {
  102. u8 n = ht_capa->ampdu_params_info &
  103. IEEE80211_HT_AMPDU_PARM_FACTOR;
  104. if (n < ht_cap->ampdu_factor)
  105. ht_cap->ampdu_factor = n;
  106. }
  107. /* Allow the user to increase AMPDU density. */
  108. if (ht_capa_mask->ampdu_params_info &
  109. IEEE80211_HT_AMPDU_PARM_DENSITY) {
  110. u8 n = (ht_capa->ampdu_params_info &
  111. IEEE80211_HT_AMPDU_PARM_DENSITY)
  112. >> IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT;
  113. if (n > ht_cap->ampdu_density)
  114. ht_cap->ampdu_density = n;
  115. }
  116. }
  117. bool ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data *sdata,
  118. struct ieee80211_supported_band *sband,
  119. const struct ieee80211_ht_cap *ht_cap_ie,
  120. struct link_sta_info *link_sta)
  121. {
  122. struct ieee80211_bss_conf *link_conf;
  123. struct sta_info *sta = link_sta->sta;
  124. struct ieee80211_sta_ht_cap ht_cap, own_cap;
  125. u8 ampdu_info, tx_mcs_set_cap;
  126. int i, max_tx_streams;
  127. bool changed;
  128. enum ieee80211_sta_rx_bandwidth bw;
  129. enum nl80211_chan_width width;
  130. memset(&ht_cap, 0, sizeof(ht_cap));
  131. if (!ht_cap_ie || !sband->ht_cap.ht_supported)
  132. goto apply;
  133. ht_cap.ht_supported = true;
  134. own_cap = sband->ht_cap;
  135. /*
  136. * If user has specified capability over-rides, take care
  137. * of that if the station we're setting up is the AP or TDLS peer that
  138. * we advertised a restricted capability set to. Override
  139. * our own capabilities and then use those below.
  140. */
  141. if (sdata->vif.type == NL80211_IFTYPE_STATION ||
  142. sdata->vif.type == NL80211_IFTYPE_ADHOC)
  143. ieee80211_apply_htcap_overrides(sdata, &own_cap);
  144. /*
  145. * The bits listed in this expression should be
  146. * the same for the peer and us, if the station
  147. * advertises more then we can't use those thus
  148. * we mask them out.
  149. */
  150. ht_cap.cap = le16_to_cpu(ht_cap_ie->cap_info) &
  151. (own_cap.cap | ~(IEEE80211_HT_CAP_LDPC_CODING |
  152. IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  153. IEEE80211_HT_CAP_GRN_FLD |
  154. IEEE80211_HT_CAP_SGI_20 |
  155. IEEE80211_HT_CAP_SGI_40 |
  156. IEEE80211_HT_CAP_DSSSCCK40));
  157. /*
  158. * The STBC bits are asymmetric -- if we don't have
  159. * TX then mask out the peer's RX and vice versa.
  160. */
  161. if (!(own_cap.cap & IEEE80211_HT_CAP_TX_STBC))
  162. ht_cap.cap &= ~IEEE80211_HT_CAP_RX_STBC;
  163. if (!(own_cap.cap & IEEE80211_HT_CAP_RX_STBC))
  164. ht_cap.cap &= ~IEEE80211_HT_CAP_TX_STBC;
  165. ampdu_info = ht_cap_ie->ampdu_params_info;
  166. ht_cap.ampdu_factor =
  167. ampdu_info & IEEE80211_HT_AMPDU_PARM_FACTOR;
  168. ht_cap.ampdu_density =
  169. (ampdu_info & IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
  170. /* own MCS TX capabilities */
  171. tx_mcs_set_cap = own_cap.mcs.tx_params;
  172. /* Copy peer MCS TX capabilities, the driver might need them. */
  173. ht_cap.mcs.tx_params = ht_cap_ie->mcs.tx_params;
  174. /* can we TX with MCS rates? */
  175. if (!(tx_mcs_set_cap & IEEE80211_HT_MCS_TX_DEFINED))
  176. goto apply;
  177. /* Counting from 0, therefore +1 */
  178. if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_RX_DIFF)
  179. max_tx_streams =
  180. ((tx_mcs_set_cap & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
  181. >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
  182. else
  183. max_tx_streams = IEEE80211_HT_MCS_TX_MAX_STREAMS;
  184. /*
  185. * 802.11n-2009 20.3.5 / 20.6 says:
  186. * - indices 0 to 7 and 32 are single spatial stream
  187. * - 8 to 31 are multiple spatial streams using equal modulation
  188. * [8..15 for two streams, 16..23 for three and 24..31 for four]
  189. * - remainder are multiple spatial streams using unequal modulation
  190. */
  191. for (i = 0; i < max_tx_streams; i++)
  192. ht_cap.mcs.rx_mask[i] =
  193. own_cap.mcs.rx_mask[i] & ht_cap_ie->mcs.rx_mask[i];
  194. if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION)
  195. for (i = IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE;
  196. i < IEEE80211_HT_MCS_MASK_LEN; i++)
  197. ht_cap.mcs.rx_mask[i] =
  198. own_cap.mcs.rx_mask[i] &
  199. ht_cap_ie->mcs.rx_mask[i];
  200. /* handle MCS rate 32 too */
  201. if (own_cap.mcs.rx_mask[32/8] & ht_cap_ie->mcs.rx_mask[32/8] & 1)
  202. ht_cap.mcs.rx_mask[32/8] |= 1;
  203. /* set Rx highest rate */
  204. ht_cap.mcs.rx_highest = ht_cap_ie->mcs.rx_highest;
  205. if (ht_cap.cap & IEEE80211_HT_CAP_MAX_AMSDU)
  206. link_sta->pub->agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_7935;
  207. else
  208. link_sta->pub->agg.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_3839;
  209. ieee80211_sta_recalc_aggregates(&sta->sta);
  210. apply:
  211. changed = memcmp(&link_sta->pub->ht_cap, &ht_cap, sizeof(ht_cap));
  212. memcpy(&link_sta->pub->ht_cap, &ht_cap, sizeof(ht_cap));
  213. rcu_read_lock();
  214. link_conf = rcu_dereference(sdata->vif.link_conf[link_sta->link_id]);
  215. if (WARN_ON(!link_conf))
  216. width = NL80211_CHAN_WIDTH_20_NOHT;
  217. else
  218. width = link_conf->chandef.width;
  219. switch (width) {
  220. default:
  221. WARN_ON_ONCE(1);
  222. fallthrough;
  223. case NL80211_CHAN_WIDTH_20_NOHT:
  224. case NL80211_CHAN_WIDTH_20:
  225. bw = IEEE80211_STA_RX_BW_20;
  226. break;
  227. case NL80211_CHAN_WIDTH_40:
  228. case NL80211_CHAN_WIDTH_80:
  229. case NL80211_CHAN_WIDTH_80P80:
  230. case NL80211_CHAN_WIDTH_160:
  231. bw = ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  232. IEEE80211_STA_RX_BW_40 : IEEE80211_STA_RX_BW_20;
  233. break;
  234. }
  235. rcu_read_unlock();
  236. link_sta->pub->bandwidth = bw;
  237. link_sta->cur_max_bandwidth =
  238. ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  239. IEEE80211_STA_RX_BW_40 : IEEE80211_STA_RX_BW_20;
  240. if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
  241. sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  242. enum ieee80211_smps_mode smps_mode;
  243. switch ((ht_cap.cap & IEEE80211_HT_CAP_SM_PS)
  244. >> IEEE80211_HT_CAP_SM_PS_SHIFT) {
  245. case WLAN_HT_CAP_SM_PS_INVALID:
  246. case WLAN_HT_CAP_SM_PS_STATIC:
  247. smps_mode = IEEE80211_SMPS_STATIC;
  248. break;
  249. case WLAN_HT_CAP_SM_PS_DYNAMIC:
  250. smps_mode = IEEE80211_SMPS_DYNAMIC;
  251. break;
  252. case WLAN_HT_CAP_SM_PS_DISABLED:
  253. smps_mode = IEEE80211_SMPS_OFF;
  254. break;
  255. }
  256. if (smps_mode != link_sta->pub->smps_mode)
  257. changed = true;
  258. link_sta->pub->smps_mode = smps_mode;
  259. } else {
  260. link_sta->pub->smps_mode = IEEE80211_SMPS_OFF;
  261. }
  262. return changed;
  263. }
  264. void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta,
  265. enum ieee80211_agg_stop_reason reason)
  266. {
  267. int i;
  268. mutex_lock(&sta->ampdu_mlme.mtx);
  269. for (i = 0; i < IEEE80211_NUM_TIDS; i++)
  270. ___ieee80211_stop_rx_ba_session(sta, i, WLAN_BACK_RECIPIENT,
  271. WLAN_REASON_QSTA_LEAVE_QBSS,
  272. reason != AGG_STOP_DESTROY_STA &&
  273. reason != AGG_STOP_PEER_REQUEST);
  274. for (i = 0; i < IEEE80211_NUM_TIDS; i++)
  275. ___ieee80211_stop_tx_ba_session(sta, i, reason);
  276. mutex_unlock(&sta->ampdu_mlme.mtx);
  277. /*
  278. * In case the tear down is part of a reconfigure due to HW restart
  279. * request, it is possible that the low level driver requested to stop
  280. * the BA session, so handle it to properly clean tid_tx data.
  281. */
  282. if(reason == AGG_STOP_DESTROY_STA) {
  283. cancel_work_sync(&sta->ampdu_mlme.work);
  284. mutex_lock(&sta->ampdu_mlme.mtx);
  285. for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
  286. struct tid_ampdu_tx *tid_tx =
  287. rcu_dereference_protected_tid_tx(sta, i);
  288. if (!tid_tx)
  289. continue;
  290. if (test_and_clear_bit(HT_AGG_STATE_STOP_CB, &tid_tx->state))
  291. ieee80211_stop_tx_ba_cb(sta, i, tid_tx);
  292. }
  293. mutex_unlock(&sta->ampdu_mlme.mtx);
  294. }
  295. }
  296. void ieee80211_ba_session_work(struct work_struct *work)
  297. {
  298. struct sta_info *sta =
  299. container_of(work, struct sta_info, ampdu_mlme.work);
  300. struct tid_ampdu_tx *tid_tx;
  301. bool blocked;
  302. int tid;
  303. /* When this flag is set, new sessions should be blocked. */
  304. blocked = test_sta_flag(sta, WLAN_STA_BLOCK_BA);
  305. mutex_lock(&sta->ampdu_mlme.mtx);
  306. for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
  307. if (test_and_clear_bit(tid, sta->ampdu_mlme.tid_rx_timer_expired))
  308. ___ieee80211_stop_rx_ba_session(
  309. sta, tid, WLAN_BACK_RECIPIENT,
  310. WLAN_REASON_QSTA_TIMEOUT, true);
  311. if (test_and_clear_bit(tid,
  312. sta->ampdu_mlme.tid_rx_stop_requested))
  313. ___ieee80211_stop_rx_ba_session(
  314. sta, tid, WLAN_BACK_RECIPIENT,
  315. WLAN_REASON_UNSPECIFIED, true);
  316. if (!blocked &&
  317. test_and_clear_bit(tid,
  318. sta->ampdu_mlme.tid_rx_manage_offl))
  319. ___ieee80211_start_rx_ba_session(sta, 0, 0, 0, 1, tid,
  320. IEEE80211_MAX_AMPDU_BUF_HT,
  321. false, true, NULL);
  322. if (test_and_clear_bit(tid + IEEE80211_NUM_TIDS,
  323. sta->ampdu_mlme.tid_rx_manage_offl))
  324. ___ieee80211_stop_rx_ba_session(
  325. sta, tid, WLAN_BACK_RECIPIENT,
  326. 0, false);
  327. spin_lock_bh(&sta->lock);
  328. tid_tx = sta->ampdu_mlme.tid_start_tx[tid];
  329. if (!blocked && tid_tx) {
  330. struct ieee80211_sub_if_data *sdata = sta->sdata;
  331. struct ieee80211_local *local = sdata->local;
  332. if (local->ops->wake_tx_queue) {
  333. struct txq_info *txqi =
  334. to_txq_info(sta->sta.txq[tid]);
  335. struct fq *fq = &local->fq;
  336. spin_lock_bh(&fq->lock);
  337. /* Allow only frags to be dequeued */
  338. set_bit(IEEE80211_TXQ_STOP, &txqi->flags);
  339. if (!skb_queue_empty(&txqi->frags)) {
  340. /* Fragmented Tx is ongoing, wait for it
  341. * to finish. Reschedule worker to retry
  342. * later.
  343. */
  344. spin_unlock_bh(&fq->lock);
  345. spin_unlock_bh(&sta->lock);
  346. /* Give the task working on the txq a
  347. * chance to send out the queued frags
  348. */
  349. synchronize_net();
  350. mutex_unlock(&sta->ampdu_mlme.mtx);
  351. ieee80211_queue_work(&sdata->local->hw,
  352. work);
  353. return;
  354. }
  355. spin_unlock_bh(&fq->lock);
  356. }
  357. /*
  358. * Assign it over to the normal tid_tx array
  359. * where it "goes live".
  360. */
  361. sta->ampdu_mlme.tid_start_tx[tid] = NULL;
  362. /* could there be a race? */
  363. if (sta->ampdu_mlme.tid_tx[tid])
  364. kfree(tid_tx);
  365. else
  366. ieee80211_assign_tid_tx(sta, tid, tid_tx);
  367. spin_unlock_bh(&sta->lock);
  368. ieee80211_tx_ba_session_handle_start(sta, tid);
  369. continue;
  370. }
  371. spin_unlock_bh(&sta->lock);
  372. tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
  373. if (!tid_tx)
  374. continue;
  375. if (!blocked &&
  376. test_and_clear_bit(HT_AGG_STATE_START_CB, &tid_tx->state))
  377. ieee80211_start_tx_ba_cb(sta, tid, tid_tx);
  378. if (test_and_clear_bit(HT_AGG_STATE_WANT_STOP, &tid_tx->state))
  379. ___ieee80211_stop_tx_ba_session(sta, tid,
  380. AGG_STOP_LOCAL_REQUEST);
  381. if (test_and_clear_bit(HT_AGG_STATE_STOP_CB, &tid_tx->state))
  382. ieee80211_stop_tx_ba_cb(sta, tid, tid_tx);
  383. }
  384. mutex_unlock(&sta->ampdu_mlme.mtx);
  385. }
  386. void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
  387. const u8 *da, u16 tid,
  388. u16 initiator, u16 reason_code)
  389. {
  390. struct ieee80211_local *local = sdata->local;
  391. struct sk_buff *skb;
  392. struct ieee80211_mgmt *mgmt;
  393. u16 params;
  394. skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
  395. if (!skb)
  396. return;
  397. skb_reserve(skb, local->hw.extra_tx_headroom);
  398. mgmt = skb_put_zero(skb, 24);
  399. memcpy(mgmt->da, da, ETH_ALEN);
  400. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  401. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  402. sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  403. sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
  404. memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
  405. else if (sdata->vif.type == NL80211_IFTYPE_STATION)
  406. memcpy(mgmt->bssid, sdata->deflink.u.mgd.bssid, ETH_ALEN);
  407. else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  408. memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
  409. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  410. IEEE80211_STYPE_ACTION);
  411. skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
  412. mgmt->u.action.category = WLAN_CATEGORY_BACK;
  413. mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
  414. params = (u16)(initiator << 11); /* bit 11 initiator */
  415. params |= (u16)(tid << 12); /* bit 15:12 TID number */
  416. mgmt->u.action.u.delba.params = cpu_to_le16(params);
  417. mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
  418. ieee80211_tx_skb(sdata, skb);
  419. }
  420. void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
  421. struct sta_info *sta,
  422. struct ieee80211_mgmt *mgmt, size_t len)
  423. {
  424. u16 tid, params;
  425. u16 initiator;
  426. params = le16_to_cpu(mgmt->u.action.u.delba.params);
  427. tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
  428. initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
  429. ht_dbg_ratelimited(sdata, "delba from %pM (%s) tid %d reason code %d\n",
  430. mgmt->sa, initiator ? "initiator" : "recipient",
  431. tid,
  432. le16_to_cpu(mgmt->u.action.u.delba.reason_code));
  433. if (initiator == WLAN_BACK_INITIATOR)
  434. __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_INITIATOR, 0,
  435. true);
  436. else
  437. __ieee80211_stop_tx_ba_session(sta, tid, AGG_STOP_PEER_REQUEST);
  438. }
  439. enum nl80211_smps_mode
  440. ieee80211_smps_mode_to_smps_mode(enum ieee80211_smps_mode smps)
  441. {
  442. switch (smps) {
  443. case IEEE80211_SMPS_OFF:
  444. return NL80211_SMPS_OFF;
  445. case IEEE80211_SMPS_STATIC:
  446. return NL80211_SMPS_STATIC;
  447. case IEEE80211_SMPS_DYNAMIC:
  448. return NL80211_SMPS_DYNAMIC;
  449. default:
  450. return NL80211_SMPS_OFF;
  451. }
  452. }
  453. int ieee80211_send_smps_action(struct ieee80211_sub_if_data *sdata,
  454. enum ieee80211_smps_mode smps, const u8 *da,
  455. const u8 *bssid)
  456. {
  457. struct ieee80211_local *local = sdata->local;
  458. struct sk_buff *skb;
  459. struct ieee80211_mgmt *action_frame;
  460. /* 27 = header + category + action + smps mode */
  461. skb = dev_alloc_skb(27 + local->hw.extra_tx_headroom);
  462. if (!skb)
  463. return -ENOMEM;
  464. skb_reserve(skb, local->hw.extra_tx_headroom);
  465. action_frame = skb_put(skb, 27);
  466. memcpy(action_frame->da, da, ETH_ALEN);
  467. memcpy(action_frame->sa, sdata->dev->dev_addr, ETH_ALEN);
  468. memcpy(action_frame->bssid, bssid, ETH_ALEN);
  469. action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  470. IEEE80211_STYPE_ACTION);
  471. action_frame->u.action.category = WLAN_CATEGORY_HT;
  472. action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
  473. switch (smps) {
  474. case IEEE80211_SMPS_AUTOMATIC:
  475. case IEEE80211_SMPS_NUM_MODES:
  476. WARN_ON(1);
  477. fallthrough;
  478. case IEEE80211_SMPS_OFF:
  479. action_frame->u.action.u.ht_smps.smps_control =
  480. WLAN_HT_SMPS_CONTROL_DISABLED;
  481. break;
  482. case IEEE80211_SMPS_STATIC:
  483. action_frame->u.action.u.ht_smps.smps_control =
  484. WLAN_HT_SMPS_CONTROL_STATIC;
  485. break;
  486. case IEEE80211_SMPS_DYNAMIC:
  487. action_frame->u.action.u.ht_smps.smps_control =
  488. WLAN_HT_SMPS_CONTROL_DYNAMIC;
  489. break;
  490. }
  491. /* we'll do more on status of this frame */
  492. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
  493. ieee80211_tx_skb(sdata, skb);
  494. return 0;
  495. }
  496. void ieee80211_request_smps(struct ieee80211_vif *vif, unsigned int link_id,
  497. enum ieee80211_smps_mode smps_mode)
  498. {
  499. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  500. struct ieee80211_link_data *link;
  501. if (WARN_ON_ONCE(vif->type != NL80211_IFTYPE_STATION))
  502. return;
  503. rcu_read_lock();
  504. link = rcu_dereference(sdata->link[link_id]);
  505. if (WARN_ON(!link))
  506. goto out;
  507. if (link->u.mgd.driver_smps_mode == smps_mode)
  508. goto out;
  509. link->u.mgd.driver_smps_mode = smps_mode;
  510. ieee80211_queue_work(&sdata->local->hw, &link->u.mgd.request_smps_work);
  511. out:
  512. rcu_read_unlock();
  513. }
  514. /* this might change ... don't want non-open drivers using it */
  515. EXPORT_SYMBOL_GPL(ieee80211_request_smps);