ht.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  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. mutex_lock(&sta->ampdu_mlme.mtx);
  248. for (i = 0; i < IEEE80211_NUM_TIDS; i++)
  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. for (i = 0; i < IEEE80211_NUM_TIDS; i++)
  254. ___ieee80211_stop_tx_ba_session(sta, i, reason);
  255. mutex_unlock(&sta->ampdu_mlme.mtx);
  256. /*
  257. * In case the tear down is part of a reconfigure due to HW restart
  258. * request, it is possible that the low level driver requested to stop
  259. * the BA session, so handle it to properly clean tid_tx data.
  260. */
  261. if(reason == AGG_STOP_DESTROY_STA) {
  262. cancel_work_sync(&sta->ampdu_mlme.work);
  263. mutex_lock(&sta->ampdu_mlme.mtx);
  264. for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
  265. struct tid_ampdu_tx *tid_tx =
  266. rcu_dereference_protected_tid_tx(sta, i);
  267. if (!tid_tx)
  268. continue;
  269. if (test_and_clear_bit(HT_AGG_STATE_STOP_CB, &tid_tx->state))
  270. ieee80211_stop_tx_ba_cb(sta, i, tid_tx);
  271. }
  272. mutex_unlock(&sta->ampdu_mlme.mtx);
  273. }
  274. }
  275. void ieee80211_ba_session_work(struct work_struct *work)
  276. {
  277. struct sta_info *sta =
  278. container_of(work, struct sta_info, ampdu_mlme.work);
  279. struct tid_ampdu_tx *tid_tx;
  280. bool blocked;
  281. int tid;
  282. /* When this flag is set, new sessions should be blocked. */
  283. blocked = test_sta_flag(sta, WLAN_STA_BLOCK_BA);
  284. mutex_lock(&sta->ampdu_mlme.mtx);
  285. for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
  286. if (test_and_clear_bit(tid, sta->ampdu_mlme.tid_rx_timer_expired))
  287. ___ieee80211_stop_rx_ba_session(
  288. sta, tid, WLAN_BACK_RECIPIENT,
  289. WLAN_REASON_QSTA_TIMEOUT, true);
  290. if (test_and_clear_bit(tid,
  291. sta->ampdu_mlme.tid_rx_stop_requested))
  292. ___ieee80211_stop_rx_ba_session(
  293. sta, tid, WLAN_BACK_RECIPIENT,
  294. WLAN_REASON_UNSPECIFIED, true);
  295. if (!blocked &&
  296. test_and_clear_bit(tid,
  297. sta->ampdu_mlme.tid_rx_manage_offl))
  298. ___ieee80211_start_rx_ba_session(sta, 0, 0, 0, 1, tid,
  299. IEEE80211_MAX_AMPDU_BUF_HT,
  300. false, true);
  301. if (test_and_clear_bit(tid + IEEE80211_NUM_TIDS,
  302. sta->ampdu_mlme.tid_rx_manage_offl))
  303. ___ieee80211_stop_rx_ba_session(
  304. sta, tid, WLAN_BACK_RECIPIENT,
  305. 0, false);
  306. spin_lock_bh(&sta->lock);
  307. tid_tx = sta->ampdu_mlme.tid_start_tx[tid];
  308. if (!blocked && tid_tx) {
  309. /*
  310. * Assign it over to the normal tid_tx array
  311. * where it "goes live".
  312. */
  313. sta->ampdu_mlme.tid_start_tx[tid] = NULL;
  314. /* could there be a race? */
  315. if (sta->ampdu_mlme.tid_tx[tid])
  316. kfree(tid_tx);
  317. else
  318. ieee80211_assign_tid_tx(sta, tid, tid_tx);
  319. spin_unlock_bh(&sta->lock);
  320. ieee80211_tx_ba_session_handle_start(sta, tid);
  321. continue;
  322. }
  323. spin_unlock_bh(&sta->lock);
  324. tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
  325. if (!tid_tx)
  326. continue;
  327. if (!blocked &&
  328. test_and_clear_bit(HT_AGG_STATE_START_CB, &tid_tx->state))
  329. ieee80211_start_tx_ba_cb(sta, tid, tid_tx);
  330. if (test_and_clear_bit(HT_AGG_STATE_WANT_STOP, &tid_tx->state))
  331. ___ieee80211_stop_tx_ba_session(sta, tid,
  332. AGG_STOP_LOCAL_REQUEST);
  333. if (test_and_clear_bit(HT_AGG_STATE_STOP_CB, &tid_tx->state))
  334. ieee80211_stop_tx_ba_cb(sta, tid, tid_tx);
  335. }
  336. mutex_unlock(&sta->ampdu_mlme.mtx);
  337. }
  338. void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
  339. const u8 *da, u16 tid,
  340. u16 initiator, u16 reason_code)
  341. {
  342. struct ieee80211_local *local = sdata->local;
  343. struct sk_buff *skb;
  344. struct ieee80211_mgmt *mgmt;
  345. u16 params;
  346. skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
  347. if (!skb)
  348. return;
  349. skb_reserve(skb, local->hw.extra_tx_headroom);
  350. mgmt = skb_put_zero(skb, 24);
  351. memcpy(mgmt->da, da, ETH_ALEN);
  352. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  353. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  354. sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  355. sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
  356. memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
  357. else if (sdata->vif.type == NL80211_IFTYPE_STATION)
  358. memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  359. else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  360. memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
  361. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  362. IEEE80211_STYPE_ACTION);
  363. skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
  364. mgmt->u.action.category = WLAN_CATEGORY_BACK;
  365. mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
  366. params = (u16)(initiator << 11); /* bit 11 initiator */
  367. params |= (u16)(tid << 12); /* bit 15:12 TID number */
  368. mgmt->u.action.u.delba.params = cpu_to_le16(params);
  369. mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
  370. ieee80211_tx_skb(sdata, skb);
  371. }
  372. void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
  373. struct sta_info *sta,
  374. struct ieee80211_mgmt *mgmt, size_t len)
  375. {
  376. u16 tid, params;
  377. u16 initiator;
  378. params = le16_to_cpu(mgmt->u.action.u.delba.params);
  379. tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
  380. initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
  381. ht_dbg_ratelimited(sdata, "delba from %pM (%s) tid %d reason code %d\n",
  382. mgmt->sa, initiator ? "initiator" : "recipient",
  383. tid,
  384. le16_to_cpu(mgmt->u.action.u.delba.reason_code));
  385. if (initiator == WLAN_BACK_INITIATOR)
  386. __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_INITIATOR, 0,
  387. true);
  388. else
  389. __ieee80211_stop_tx_ba_session(sta, tid, AGG_STOP_PEER_REQUEST);
  390. }
  391. enum nl80211_smps_mode
  392. ieee80211_smps_mode_to_smps_mode(enum ieee80211_smps_mode smps)
  393. {
  394. switch (smps) {
  395. case IEEE80211_SMPS_OFF:
  396. return NL80211_SMPS_OFF;
  397. case IEEE80211_SMPS_STATIC:
  398. return NL80211_SMPS_STATIC;
  399. case IEEE80211_SMPS_DYNAMIC:
  400. return NL80211_SMPS_DYNAMIC;
  401. default:
  402. return NL80211_SMPS_OFF;
  403. }
  404. }
  405. int ieee80211_send_smps_action(struct ieee80211_sub_if_data *sdata,
  406. enum ieee80211_smps_mode smps, const u8 *da,
  407. const u8 *bssid)
  408. {
  409. struct ieee80211_local *local = sdata->local;
  410. struct sk_buff *skb;
  411. struct ieee80211_mgmt *action_frame;
  412. /* 27 = header + category + action + smps mode */
  413. skb = dev_alloc_skb(27 + local->hw.extra_tx_headroom);
  414. if (!skb)
  415. return -ENOMEM;
  416. skb_reserve(skb, local->hw.extra_tx_headroom);
  417. action_frame = skb_put(skb, 27);
  418. memcpy(action_frame->da, da, ETH_ALEN);
  419. memcpy(action_frame->sa, sdata->dev->dev_addr, ETH_ALEN);
  420. memcpy(action_frame->bssid, bssid, ETH_ALEN);
  421. action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  422. IEEE80211_STYPE_ACTION);
  423. action_frame->u.action.category = WLAN_CATEGORY_HT;
  424. action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
  425. switch (smps) {
  426. case IEEE80211_SMPS_AUTOMATIC:
  427. case IEEE80211_SMPS_NUM_MODES:
  428. WARN_ON(1);
  429. /* fall through */
  430. case IEEE80211_SMPS_OFF:
  431. action_frame->u.action.u.ht_smps.smps_control =
  432. WLAN_HT_SMPS_CONTROL_DISABLED;
  433. break;
  434. case IEEE80211_SMPS_STATIC:
  435. action_frame->u.action.u.ht_smps.smps_control =
  436. WLAN_HT_SMPS_CONTROL_STATIC;
  437. break;
  438. case IEEE80211_SMPS_DYNAMIC:
  439. action_frame->u.action.u.ht_smps.smps_control =
  440. WLAN_HT_SMPS_CONTROL_DYNAMIC;
  441. break;
  442. }
  443. /* we'll do more on status of this frame */
  444. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
  445. ieee80211_tx_skb(sdata, skb);
  446. return 0;
  447. }
  448. void ieee80211_request_smps_mgd_work(struct work_struct *work)
  449. {
  450. struct ieee80211_sub_if_data *sdata =
  451. container_of(work, struct ieee80211_sub_if_data,
  452. u.mgd.request_smps_work);
  453. sdata_lock(sdata);
  454. __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.driver_smps_mode);
  455. sdata_unlock(sdata);
  456. }
  457. void ieee80211_request_smps_ap_work(struct work_struct *work)
  458. {
  459. struct ieee80211_sub_if_data *sdata =
  460. container_of(work, struct ieee80211_sub_if_data,
  461. u.ap.request_smps_work);
  462. sdata_lock(sdata);
  463. if (sdata_dereference(sdata->u.ap.beacon, sdata))
  464. __ieee80211_request_smps_ap(sdata,
  465. sdata->u.ap.driver_smps_mode);
  466. sdata_unlock(sdata);
  467. }
  468. void ieee80211_request_smps(struct ieee80211_vif *vif,
  469. enum ieee80211_smps_mode smps_mode)
  470. {
  471. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  472. if (WARN_ON_ONCE(vif->type != NL80211_IFTYPE_STATION &&
  473. vif->type != NL80211_IFTYPE_AP))
  474. return;
  475. if (vif->type == NL80211_IFTYPE_STATION) {
  476. if (sdata->u.mgd.driver_smps_mode == smps_mode)
  477. return;
  478. sdata->u.mgd.driver_smps_mode = smps_mode;
  479. ieee80211_queue_work(&sdata->local->hw,
  480. &sdata->u.mgd.request_smps_work);
  481. } else {
  482. /* AUTOMATIC is meaningless in AP mode */
  483. if (WARN_ON_ONCE(smps_mode == IEEE80211_SMPS_AUTOMATIC))
  484. return;
  485. if (sdata->u.ap.driver_smps_mode == smps_mode)
  486. return;
  487. sdata->u.ap.driver_smps_mode = smps_mode;
  488. ieee80211_queue_work(&sdata->local->hw,
  489. &sdata->u.ap.request_smps_work);
  490. }
  491. }
  492. /* this might change ... don't want non-open drivers using it */
  493. EXPORT_SYMBOL_GPL(ieee80211_request_smps);