ht.c 16 KB

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