ht.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  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-2008, Intel Corporation
  10. *
  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. #include <linux/ieee80211.h>
  16. #include <net/wireless.h>
  17. #include <net/mac80211.h>
  18. #include "ieee80211_i.h"
  19. #include "sta_info.h"
  20. #include "wme.h"
  21. void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband,
  22. struct ieee80211_ht_cap *ht_cap_ie,
  23. struct ieee80211_sta_ht_cap *ht_cap)
  24. {
  25. u8 ampdu_info, tx_mcs_set_cap;
  26. int i, max_tx_streams;
  27. BUG_ON(!ht_cap);
  28. memset(ht_cap, 0, sizeof(*ht_cap));
  29. if (!ht_cap_ie)
  30. return;
  31. ht_cap->ht_supported = true;
  32. ht_cap->cap = ht_cap->cap & sband->ht_cap.cap;
  33. ht_cap->cap &= ~IEEE80211_HT_CAP_SM_PS;
  34. ht_cap->cap |= sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS;
  35. ampdu_info = ht_cap_ie->ampdu_params_info;
  36. ht_cap->ampdu_factor =
  37. ampdu_info & IEEE80211_HT_AMPDU_PARM_FACTOR;
  38. ht_cap->ampdu_density =
  39. (ampdu_info & IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
  40. /* own MCS TX capabilities */
  41. tx_mcs_set_cap = sband->ht_cap.mcs.tx_params;
  42. /* can we TX with MCS rates? */
  43. if (!(tx_mcs_set_cap & IEEE80211_HT_MCS_TX_DEFINED))
  44. return;
  45. /* Counting from 0, therefore +1 */
  46. if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_RX_DIFF)
  47. max_tx_streams =
  48. ((tx_mcs_set_cap & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
  49. >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
  50. else
  51. max_tx_streams = IEEE80211_HT_MCS_TX_MAX_STREAMS;
  52. /*
  53. * 802.11n D5.0 20.3.5 / 20.6 says:
  54. * - indices 0 to 7 and 32 are single spatial stream
  55. * - 8 to 31 are multiple spatial streams using equal modulation
  56. * [8..15 for two streams, 16..23 for three and 24..31 for four]
  57. * - remainder are multiple spatial streams using unequal modulation
  58. */
  59. for (i = 0; i < max_tx_streams; i++)
  60. ht_cap->mcs.rx_mask[i] =
  61. sband->ht_cap.mcs.rx_mask[i] & ht_cap_ie->mcs.rx_mask[i];
  62. if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION)
  63. for (i = IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE;
  64. i < IEEE80211_HT_MCS_MASK_LEN; i++)
  65. ht_cap->mcs.rx_mask[i] =
  66. sband->ht_cap.mcs.rx_mask[i] &
  67. ht_cap_ie->mcs.rx_mask[i];
  68. /* handle MCS rate 32 too */
  69. if (sband->ht_cap.mcs.rx_mask[32/8] & ht_cap_ie->mcs.rx_mask[32/8] & 1)
  70. ht_cap->mcs.rx_mask[32/8] |= 1;
  71. }
  72. /*
  73. * ieee80211_enable_ht should be called only after the operating band
  74. * has been determined as ht configuration depends on the hw's
  75. * HT abilities for a specific band.
  76. */
  77. u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
  78. struct ieee80211_ht_info *hti,
  79. u16 ap_ht_cap_flags)
  80. {
  81. struct ieee80211_local *local = sdata->local;
  82. struct ieee80211_supported_band *sband;
  83. struct ieee80211_bss_ht_conf ht;
  84. u32 changed = 0;
  85. bool enable_ht = true, ht_changed;
  86. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  87. memset(&ht, 0, sizeof(ht));
  88. /* HT is not supported */
  89. if (!sband->ht_cap.ht_supported)
  90. enable_ht = false;
  91. /* check that channel matches the right operating channel */
  92. if (local->hw.conf.channel->center_freq !=
  93. ieee80211_channel_to_frequency(hti->control_chan))
  94. enable_ht = false;
  95. /*
  96. * XXX: This is totally incorrect when there are multiple virtual
  97. * interfaces, needs to be fixed later.
  98. */
  99. ht_changed = local->hw.conf.ht.enabled != enable_ht;
  100. local->hw.conf.ht.enabled = enable_ht;
  101. if (ht_changed)
  102. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_HT);
  103. /* disable HT */
  104. if (!enable_ht)
  105. return 0;
  106. ht.secondary_channel_offset =
  107. hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
  108. ht.width_40_ok =
  109. !(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
  110. (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
  111. (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY);
  112. ht.operation_mode = le16_to_cpu(hti->operation_mode);
  113. /* if bss configuration changed store the new one */
  114. if (memcmp(&sdata->vif.bss_conf.ht, &ht, sizeof(ht))) {
  115. changed |= BSS_CHANGED_HT;
  116. sdata->vif.bss_conf.ht = ht;
  117. }
  118. return changed;
  119. }
  120. static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
  121. const u8 *da, u16 tid,
  122. u8 dialog_token, u16 start_seq_num,
  123. u16 agg_size, u16 timeout)
  124. {
  125. struct ieee80211_local *local = sdata->local;
  126. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  127. struct sk_buff *skb;
  128. struct ieee80211_mgmt *mgmt;
  129. u16 capab;
  130. skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
  131. if (!skb) {
  132. printk(KERN_ERR "%s: failed to allocate buffer "
  133. "for addba request frame\n", sdata->dev->name);
  134. return;
  135. }
  136. skb_reserve(skb, local->hw.extra_tx_headroom);
  137. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  138. memset(mgmt, 0, 24);
  139. memcpy(mgmt->da, da, ETH_ALEN);
  140. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  141. if (sdata->vif.type == NL80211_IFTYPE_AP)
  142. memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
  143. else
  144. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  145. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  146. IEEE80211_STYPE_ACTION);
  147. skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
  148. mgmt->u.action.category = WLAN_CATEGORY_BACK;
  149. mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
  150. mgmt->u.action.u.addba_req.dialog_token = dialog_token;
  151. capab = (u16)(1 << 1); /* bit 1 aggregation policy */
  152. capab |= (u16)(tid << 2); /* bit 5:2 TID number */
  153. capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
  154. mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
  155. mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
  156. mgmt->u.action.u.addba_req.start_seq_num =
  157. cpu_to_le16(start_seq_num << 4);
  158. ieee80211_tx_skb(sdata, skb, 0);
  159. }
  160. static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *da, u16 tid,
  161. u8 dialog_token, u16 status, u16 policy,
  162. u16 buf_size, u16 timeout)
  163. {
  164. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  165. struct ieee80211_local *local = sdata->local;
  166. struct sk_buff *skb;
  167. struct ieee80211_mgmt *mgmt;
  168. u16 capab;
  169. skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
  170. if (!skb) {
  171. printk(KERN_DEBUG "%s: failed to allocate buffer "
  172. "for addba resp frame\n", sdata->dev->name);
  173. return;
  174. }
  175. skb_reserve(skb, local->hw.extra_tx_headroom);
  176. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  177. memset(mgmt, 0, 24);
  178. memcpy(mgmt->da, da, ETH_ALEN);
  179. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  180. if (sdata->vif.type == NL80211_IFTYPE_AP)
  181. memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
  182. else
  183. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  184. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  185. IEEE80211_STYPE_ACTION);
  186. skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
  187. mgmt->u.action.category = WLAN_CATEGORY_BACK;
  188. mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
  189. mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
  190. capab = (u16)(policy << 1); /* bit 1 aggregation policy */
  191. capab |= (u16)(tid << 2); /* bit 5:2 TID number */
  192. capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
  193. mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
  194. mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
  195. mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
  196. ieee80211_tx_skb(sdata, skb, 0);
  197. }
  198. static void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
  199. const u8 *da, u16 tid,
  200. u16 initiator, u16 reason_code)
  201. {
  202. struct ieee80211_local *local = sdata->local;
  203. struct ieee80211_if_sta *ifsta = &sdata->u.sta;
  204. struct sk_buff *skb;
  205. struct ieee80211_mgmt *mgmt;
  206. u16 params;
  207. skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
  208. if (!skb) {
  209. printk(KERN_ERR "%s: failed to allocate buffer "
  210. "for delba frame\n", sdata->dev->name);
  211. return;
  212. }
  213. skb_reserve(skb, local->hw.extra_tx_headroom);
  214. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  215. memset(mgmt, 0, 24);
  216. memcpy(mgmt->da, da, ETH_ALEN);
  217. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  218. if (sdata->vif.type == NL80211_IFTYPE_AP)
  219. memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
  220. else
  221. memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
  222. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  223. IEEE80211_STYPE_ACTION);
  224. skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
  225. mgmt->u.action.category = WLAN_CATEGORY_BACK;
  226. mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
  227. params = (u16)(initiator << 11); /* bit 11 initiator */
  228. params |= (u16)(tid << 12); /* bit 15:12 TID number */
  229. mgmt->u.action.u.delba.params = cpu_to_le16(params);
  230. mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
  231. ieee80211_tx_skb(sdata, skb, 0);
  232. }
  233. void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn)
  234. {
  235. struct ieee80211_local *local = sdata->local;
  236. struct sk_buff *skb;
  237. struct ieee80211_bar *bar;
  238. u16 bar_control = 0;
  239. skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom);
  240. if (!skb) {
  241. printk(KERN_ERR "%s: failed to allocate buffer for "
  242. "bar frame\n", sdata->dev->name);
  243. return;
  244. }
  245. skb_reserve(skb, local->hw.extra_tx_headroom);
  246. bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar));
  247. memset(bar, 0, sizeof(*bar));
  248. bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
  249. IEEE80211_STYPE_BACK_REQ);
  250. memcpy(bar->ra, ra, ETH_ALEN);
  251. memcpy(bar->ta, sdata->dev->dev_addr, ETH_ALEN);
  252. bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL;
  253. bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA;
  254. bar_control |= (u16)(tid << 12);
  255. bar->control = cpu_to_le16(bar_control);
  256. bar->start_seq_num = cpu_to_le16(ssn);
  257. ieee80211_tx_skb(sdata, skb, 0);
  258. }
  259. void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid,
  260. u16 initiator, u16 reason)
  261. {
  262. struct ieee80211_local *local = sdata->local;
  263. struct ieee80211_hw *hw = &local->hw;
  264. struct sta_info *sta;
  265. int ret, i;
  266. rcu_read_lock();
  267. sta = sta_info_get(local, ra);
  268. if (!sta) {
  269. rcu_read_unlock();
  270. return;
  271. }
  272. /* check if TID is in operational state */
  273. spin_lock_bh(&sta->lock);
  274. if (sta->ampdu_mlme.tid_state_rx[tid]
  275. != HT_AGG_STATE_OPERATIONAL) {
  276. spin_unlock_bh(&sta->lock);
  277. rcu_read_unlock();
  278. return;
  279. }
  280. sta->ampdu_mlme.tid_state_rx[tid] =
  281. HT_AGG_STATE_REQ_STOP_BA_MSK |
  282. (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
  283. spin_unlock_bh(&sta->lock);
  284. /* stop HW Rx aggregation. ampdu_action existence
  285. * already verified in session init so we add the BUG_ON */
  286. BUG_ON(!local->ops->ampdu_action);
  287. #ifdef CONFIG_MAC80211_HT_DEBUG
  288. printk(KERN_DEBUG "Rx BA session stop requested for %pM tid %u\n",
  289. ra, tid);
  290. #endif /* CONFIG_MAC80211_HT_DEBUG */
  291. ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
  292. &sta->sta, tid, NULL);
  293. if (ret)
  294. printk(KERN_DEBUG "HW problem - can not stop rx "
  295. "aggregation for tid %d\n", tid);
  296. /* shutdown timer has not expired */
  297. if (initiator != WLAN_BACK_TIMER)
  298. del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
  299. /* check if this is a self generated aggregation halt */
  300. if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
  301. ieee80211_send_delba(sdata, ra, tid, 0, reason);
  302. /* free the reordering buffer */
  303. for (i = 0; i < sta->ampdu_mlme.tid_rx[tid]->buf_size; i++) {
  304. if (sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]) {
  305. /* release the reordered frames */
  306. dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]);
  307. sta->ampdu_mlme.tid_rx[tid]->stored_mpdu_num--;
  308. sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i] = NULL;
  309. }
  310. }
  311. /* free resources */
  312. kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf);
  313. kfree(sta->ampdu_mlme.tid_rx[tid]);
  314. sta->ampdu_mlme.tid_rx[tid] = NULL;
  315. sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_IDLE;
  316. rcu_read_unlock();
  317. }
  318. /*
  319. * After sending add Block Ack request we activated a timer until
  320. * add Block Ack response will arrive from the recipient.
  321. * If this timer expires sta_addba_resp_timer_expired will be executed.
  322. */
  323. static void sta_addba_resp_timer_expired(unsigned long data)
  324. {
  325. /* not an elegant detour, but there is no choice as the timer passes
  326. * only one argument, and both sta_info and TID are needed, so init
  327. * flow in sta_info_create gives the TID as data, while the timer_to_id
  328. * array gives the sta through container_of */
  329. u16 tid = *(u8 *)data;
  330. struct sta_info *temp_sta = container_of((void *)data,
  331. struct sta_info, timer_to_tid[tid]);
  332. struct ieee80211_local *local = temp_sta->local;
  333. struct ieee80211_hw *hw = &local->hw;
  334. struct sta_info *sta;
  335. u8 *state;
  336. rcu_read_lock();
  337. sta = sta_info_get(local, temp_sta->sta.addr);
  338. if (!sta) {
  339. rcu_read_unlock();
  340. return;
  341. }
  342. state = &sta->ampdu_mlme.tid_state_tx[tid];
  343. /* check if the TID waits for addBA response */
  344. spin_lock_bh(&sta->lock);
  345. if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
  346. spin_unlock_bh(&sta->lock);
  347. *state = HT_AGG_STATE_IDLE;
  348. #ifdef CONFIG_MAC80211_HT_DEBUG
  349. printk(KERN_DEBUG "timer expired on tid %d but we are not "
  350. "expecting addBA response there", tid);
  351. #endif
  352. goto timer_expired_exit;
  353. }
  354. #ifdef CONFIG_MAC80211_HT_DEBUG
  355. printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
  356. #endif
  357. /* go through the state check in stop_BA_session */
  358. *state = HT_AGG_STATE_OPERATIONAL;
  359. spin_unlock_bh(&sta->lock);
  360. ieee80211_stop_tx_ba_session(hw, temp_sta->sta.addr, tid,
  361. WLAN_BACK_INITIATOR);
  362. timer_expired_exit:
  363. rcu_read_unlock();
  364. }
  365. void ieee80211_sta_tear_down_BA_sessions(struct ieee80211_sub_if_data *sdata, u8 *addr)
  366. {
  367. struct ieee80211_local *local = sdata->local;
  368. int i;
  369. for (i = 0; i < STA_TID_NUM; i++) {
  370. ieee80211_stop_tx_ba_session(&local->hw, addr, i,
  371. WLAN_BACK_INITIATOR);
  372. ieee80211_sta_stop_rx_ba_session(sdata, addr, i,
  373. WLAN_BACK_RECIPIENT,
  374. WLAN_REASON_QSTA_LEAVE_QBSS);
  375. }
  376. }
  377. int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
  378. {
  379. struct ieee80211_local *local = hw_to_local(hw);
  380. struct sta_info *sta;
  381. struct ieee80211_sub_if_data *sdata;
  382. u16 start_seq_num;
  383. u8 *state;
  384. int ret;
  385. if ((tid >= STA_TID_NUM) || !(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
  386. return -EINVAL;
  387. #ifdef CONFIG_MAC80211_HT_DEBUG
  388. printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n",
  389. ra, tid);
  390. #endif /* CONFIG_MAC80211_HT_DEBUG */
  391. rcu_read_lock();
  392. sta = sta_info_get(local, ra);
  393. if (!sta) {
  394. #ifdef CONFIG_MAC80211_HT_DEBUG
  395. printk(KERN_DEBUG "Could not find the station\n");
  396. #endif
  397. ret = -ENOENT;
  398. goto exit;
  399. }
  400. spin_lock_bh(&sta->lock);
  401. /* we have tried too many times, receiver does not want A-MPDU */
  402. if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
  403. ret = -EBUSY;
  404. goto err_unlock_sta;
  405. }
  406. state = &sta->ampdu_mlme.tid_state_tx[tid];
  407. /* check if the TID is not in aggregation flow already */
  408. if (*state != HT_AGG_STATE_IDLE) {
  409. #ifdef CONFIG_MAC80211_HT_DEBUG
  410. printk(KERN_DEBUG "BA request denied - session is not "
  411. "idle on tid %u\n", tid);
  412. #endif /* CONFIG_MAC80211_HT_DEBUG */
  413. ret = -EAGAIN;
  414. goto err_unlock_sta;
  415. }
  416. /* prepare A-MPDU MLME for Tx aggregation */
  417. sta->ampdu_mlme.tid_tx[tid] =
  418. kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
  419. if (!sta->ampdu_mlme.tid_tx[tid]) {
  420. #ifdef CONFIG_MAC80211_HT_DEBUG
  421. if (net_ratelimit())
  422. printk(KERN_ERR "allocate tx mlme to tid %d failed\n",
  423. tid);
  424. #endif
  425. ret = -ENOMEM;
  426. goto err_unlock_sta;
  427. }
  428. /* Tx timer */
  429. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function =
  430. sta_addba_resp_timer_expired;
  431. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data =
  432. (unsigned long)&sta->timer_to_tid[tid];
  433. init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  434. if (hw->ampdu_queues) {
  435. /* create a new queue for this aggregation */
  436. ret = ieee80211_ht_agg_queue_add(local, sta, tid);
  437. /* case no queue is available to aggregation
  438. * don't switch to aggregation */
  439. if (ret) {
  440. #ifdef CONFIG_MAC80211_HT_DEBUG
  441. printk(KERN_DEBUG "BA request denied - "
  442. "queue unavailable for tid %d\n", tid);
  443. #endif /* CONFIG_MAC80211_HT_DEBUG */
  444. goto err_unlock_queue;
  445. }
  446. }
  447. sdata = sta->sdata;
  448. /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
  449. * call back right away, it must see that the flow has begun */
  450. *state |= HT_ADDBA_REQUESTED_MSK;
  451. /* This is slightly racy because the queue isn't stopped */
  452. start_seq_num = sta->tid_seq[tid];
  453. if (local->ops->ampdu_action)
  454. ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
  455. &sta->sta, tid, &start_seq_num);
  456. if (ret) {
  457. /* No need to requeue the packets in the agg queue, since we
  458. * held the tx lock: no packet could be enqueued to the newly
  459. * allocated queue */
  460. if (hw->ampdu_queues)
  461. ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
  462. #ifdef CONFIG_MAC80211_HT_DEBUG
  463. printk(KERN_DEBUG "BA request denied - HW unavailable for"
  464. " tid %d\n", tid);
  465. #endif /* CONFIG_MAC80211_HT_DEBUG */
  466. *state = HT_AGG_STATE_IDLE;
  467. goto err_unlock_queue;
  468. }
  469. /* Will put all the packets in the new SW queue */
  470. if (hw->ampdu_queues)
  471. ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
  472. spin_unlock_bh(&sta->lock);
  473. /* send an addBA request */
  474. sta->ampdu_mlme.dialog_token_allocator++;
  475. sta->ampdu_mlme.tid_tx[tid]->dialog_token =
  476. sta->ampdu_mlme.dialog_token_allocator;
  477. sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num;
  478. ieee80211_send_addba_request(sta->sdata, ra, tid,
  479. sta->ampdu_mlme.tid_tx[tid]->dialog_token,
  480. sta->ampdu_mlme.tid_tx[tid]->ssn,
  481. 0x40, 5000);
  482. /* activate the timer for the recipient's addBA response */
  483. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires =
  484. jiffies + ADDBA_RESP_INTERVAL;
  485. add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  486. #ifdef CONFIG_MAC80211_HT_DEBUG
  487. printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
  488. #endif
  489. goto exit;
  490. err_unlock_queue:
  491. kfree(sta->ampdu_mlme.tid_tx[tid]);
  492. sta->ampdu_mlme.tid_tx[tid] = NULL;
  493. ret = -EBUSY;
  494. err_unlock_sta:
  495. spin_unlock_bh(&sta->lock);
  496. exit:
  497. rcu_read_unlock();
  498. return ret;
  499. }
  500. EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
  501. int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
  502. u8 *ra, u16 tid,
  503. enum ieee80211_back_parties initiator)
  504. {
  505. struct ieee80211_local *local = hw_to_local(hw);
  506. struct sta_info *sta;
  507. u8 *state;
  508. int ret = 0;
  509. if (tid >= STA_TID_NUM)
  510. return -EINVAL;
  511. rcu_read_lock();
  512. sta = sta_info_get(local, ra);
  513. if (!sta) {
  514. rcu_read_unlock();
  515. return -ENOENT;
  516. }
  517. /* check if the TID is in aggregation */
  518. state = &sta->ampdu_mlme.tid_state_tx[tid];
  519. spin_lock_bh(&sta->lock);
  520. if (*state != HT_AGG_STATE_OPERATIONAL) {
  521. ret = -ENOENT;
  522. goto stop_BA_exit;
  523. }
  524. #ifdef CONFIG_MAC80211_HT_DEBUG
  525. printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
  526. ra, tid);
  527. #endif /* CONFIG_MAC80211_HT_DEBUG */
  528. if (hw->ampdu_queues)
  529. ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
  530. *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
  531. (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
  532. if (local->ops->ampdu_action)
  533. ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
  534. &sta->sta, tid, NULL);
  535. /* case HW denied going back to legacy */
  536. if (ret) {
  537. WARN_ON(ret != -EBUSY);
  538. *state = HT_AGG_STATE_OPERATIONAL;
  539. if (hw->ampdu_queues)
  540. ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
  541. goto stop_BA_exit;
  542. }
  543. stop_BA_exit:
  544. spin_unlock_bh(&sta->lock);
  545. rcu_read_unlock();
  546. return ret;
  547. }
  548. EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
  549. void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
  550. {
  551. struct ieee80211_local *local = hw_to_local(hw);
  552. struct sta_info *sta;
  553. u8 *state;
  554. if (tid >= STA_TID_NUM) {
  555. #ifdef CONFIG_MAC80211_HT_DEBUG
  556. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  557. tid, STA_TID_NUM);
  558. #endif
  559. return;
  560. }
  561. rcu_read_lock();
  562. sta = sta_info_get(local, ra);
  563. if (!sta) {
  564. rcu_read_unlock();
  565. #ifdef CONFIG_MAC80211_HT_DEBUG
  566. printk(KERN_DEBUG "Could not find station: %pM\n", ra);
  567. #endif
  568. return;
  569. }
  570. state = &sta->ampdu_mlme.tid_state_tx[tid];
  571. spin_lock_bh(&sta->lock);
  572. if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
  573. #ifdef CONFIG_MAC80211_HT_DEBUG
  574. printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
  575. *state);
  576. #endif
  577. spin_unlock_bh(&sta->lock);
  578. rcu_read_unlock();
  579. return;
  580. }
  581. WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
  582. *state |= HT_ADDBA_DRV_READY_MSK;
  583. if (*state == HT_AGG_STATE_OPERATIONAL) {
  584. #ifdef CONFIG_MAC80211_HT_DEBUG
  585. printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
  586. #endif
  587. if (hw->ampdu_queues)
  588. ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
  589. }
  590. spin_unlock_bh(&sta->lock);
  591. rcu_read_unlock();
  592. }
  593. EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
  594. void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
  595. {
  596. struct ieee80211_local *local = hw_to_local(hw);
  597. struct sta_info *sta;
  598. u8 *state;
  599. int agg_queue;
  600. if (tid >= STA_TID_NUM) {
  601. #ifdef CONFIG_MAC80211_HT_DEBUG
  602. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  603. tid, STA_TID_NUM);
  604. #endif
  605. return;
  606. }
  607. #ifdef CONFIG_MAC80211_HT_DEBUG
  608. printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n",
  609. ra, tid);
  610. #endif /* CONFIG_MAC80211_HT_DEBUG */
  611. rcu_read_lock();
  612. sta = sta_info_get(local, ra);
  613. if (!sta) {
  614. #ifdef CONFIG_MAC80211_HT_DEBUG
  615. printk(KERN_DEBUG "Could not find station: %pM\n", ra);
  616. #endif
  617. rcu_read_unlock();
  618. return;
  619. }
  620. state = &sta->ampdu_mlme.tid_state_tx[tid];
  621. /* NOTE: no need to use sta->lock in this state check, as
  622. * ieee80211_stop_tx_ba_session will let only one stop call to
  623. * pass through per sta/tid
  624. */
  625. if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
  626. #ifdef CONFIG_MAC80211_HT_DEBUG
  627. printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
  628. #endif
  629. rcu_read_unlock();
  630. return;
  631. }
  632. if (*state & HT_AGG_STATE_INITIATOR_MSK)
  633. ieee80211_send_delba(sta->sdata, ra, tid,
  634. WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
  635. if (hw->ampdu_queues) {
  636. agg_queue = sta->tid_to_tx_q[tid];
  637. ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
  638. /* We just requeued the all the frames that were in the
  639. * removed queue, and since we might miss a softirq we do
  640. * netif_schedule_queue. ieee80211_wake_queue is not used
  641. * here as this queue is not necessarily stopped
  642. */
  643. netif_schedule_queue(netdev_get_tx_queue(local->mdev,
  644. agg_queue));
  645. }
  646. spin_lock_bh(&sta->lock);
  647. *state = HT_AGG_STATE_IDLE;
  648. sta->ampdu_mlme.addba_req_num[tid] = 0;
  649. kfree(sta->ampdu_mlme.tid_tx[tid]);
  650. sta->ampdu_mlme.tid_tx[tid] = NULL;
  651. spin_unlock_bh(&sta->lock);
  652. rcu_read_unlock();
  653. }
  654. EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
  655. void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
  656. const u8 *ra, u16 tid)
  657. {
  658. struct ieee80211_local *local = hw_to_local(hw);
  659. struct ieee80211_ra_tid *ra_tid;
  660. struct sk_buff *skb = dev_alloc_skb(0);
  661. if (unlikely(!skb)) {
  662. #ifdef CONFIG_MAC80211_HT_DEBUG
  663. if (net_ratelimit())
  664. printk(KERN_WARNING "%s: Not enough memory, "
  665. "dropping start BA session", skb->dev->name);
  666. #endif
  667. return;
  668. }
  669. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  670. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  671. ra_tid->tid = tid;
  672. skb->pkt_type = IEEE80211_ADDBA_MSG;
  673. skb_queue_tail(&local->skb_queue, skb);
  674. tasklet_schedule(&local->tasklet);
  675. }
  676. EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
  677. void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
  678. const u8 *ra, u16 tid)
  679. {
  680. struct ieee80211_local *local = hw_to_local(hw);
  681. struct ieee80211_ra_tid *ra_tid;
  682. struct sk_buff *skb = dev_alloc_skb(0);
  683. if (unlikely(!skb)) {
  684. #ifdef CONFIG_MAC80211_HT_DEBUG
  685. if (net_ratelimit())
  686. printk(KERN_WARNING "%s: Not enough memory, "
  687. "dropping stop BA session", skb->dev->name);
  688. #endif
  689. return;
  690. }
  691. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  692. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  693. ra_tid->tid = tid;
  694. skb->pkt_type = IEEE80211_DELBA_MSG;
  695. skb_queue_tail(&local->skb_queue, skb);
  696. tasklet_schedule(&local->tasklet);
  697. }
  698. EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
  699. /*
  700. * After accepting the AddBA Request we activated a timer,
  701. * resetting it after each frame that arrives from the originator.
  702. * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
  703. */
  704. static void sta_rx_agg_session_timer_expired(unsigned long data)
  705. {
  706. /* not an elegant detour, but there is no choice as the timer passes
  707. * only one argument, and various sta_info are needed here, so init
  708. * flow in sta_info_create gives the TID as data, while the timer_to_id
  709. * array gives the sta through container_of */
  710. u8 *ptid = (u8 *)data;
  711. u8 *timer_to_id = ptid - *ptid;
  712. struct sta_info *sta = container_of(timer_to_id, struct sta_info,
  713. timer_to_tid[0]);
  714. #ifdef CONFIG_MAC80211_HT_DEBUG
  715. printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
  716. #endif
  717. ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->sta.addr,
  718. (u16)*ptid, WLAN_BACK_TIMER,
  719. WLAN_REASON_QSTA_TIMEOUT);
  720. }
  721. void ieee80211_process_addba_request(struct ieee80211_local *local,
  722. struct sta_info *sta,
  723. struct ieee80211_mgmt *mgmt,
  724. size_t len)
  725. {
  726. struct ieee80211_hw *hw = &local->hw;
  727. struct ieee80211_conf *conf = &hw->conf;
  728. struct tid_ampdu_rx *tid_agg_rx;
  729. u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
  730. u8 dialog_token;
  731. int ret = -EOPNOTSUPP;
  732. /* extract session parameters from addba request frame */
  733. dialog_token = mgmt->u.action.u.addba_req.dialog_token;
  734. timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
  735. start_seq_num =
  736. le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
  737. capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
  738. ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
  739. tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  740. buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
  741. status = WLAN_STATUS_REQUEST_DECLINED;
  742. /* sanity check for incoming parameters:
  743. * check if configuration can support the BA policy
  744. * and if buffer size does not exceeds max value */
  745. /* XXX: check own ht delayed BA capability?? */
  746. if (((ba_policy != 1)
  747. && (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA)))
  748. || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
  749. status = WLAN_STATUS_INVALID_QOS_PARAM;
  750. #ifdef CONFIG_MAC80211_HT_DEBUG
  751. if (net_ratelimit())
  752. printk(KERN_DEBUG "AddBA Req with bad params from "
  753. "%pM on tid %u. policy %d, buffer size %d\n",
  754. mgmt->sa, tid, ba_policy,
  755. buf_size);
  756. #endif /* CONFIG_MAC80211_HT_DEBUG */
  757. goto end_no_lock;
  758. }
  759. /* determine default buffer size */
  760. if (buf_size == 0) {
  761. struct ieee80211_supported_band *sband;
  762. sband = local->hw.wiphy->bands[conf->channel->band];
  763. buf_size = IEEE80211_MIN_AMPDU_BUF;
  764. buf_size = buf_size << sband->ht_cap.ampdu_factor;
  765. }
  766. /* examine state machine */
  767. spin_lock_bh(&sta->lock);
  768. if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_IDLE) {
  769. #ifdef CONFIG_MAC80211_HT_DEBUG
  770. if (net_ratelimit())
  771. printk(KERN_DEBUG "unexpected AddBA Req from "
  772. "%pM on tid %u\n",
  773. mgmt->sa, tid);
  774. #endif /* CONFIG_MAC80211_HT_DEBUG */
  775. goto end;
  776. }
  777. /* prepare A-MPDU MLME for Rx aggregation */
  778. sta->ampdu_mlme.tid_rx[tid] =
  779. kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC);
  780. if (!sta->ampdu_mlme.tid_rx[tid]) {
  781. #ifdef CONFIG_MAC80211_HT_DEBUG
  782. if (net_ratelimit())
  783. printk(KERN_ERR "allocate rx mlme to tid %d failed\n",
  784. tid);
  785. #endif
  786. goto end;
  787. }
  788. /* rx timer */
  789. sta->ampdu_mlme.tid_rx[tid]->session_timer.function =
  790. sta_rx_agg_session_timer_expired;
  791. sta->ampdu_mlme.tid_rx[tid]->session_timer.data =
  792. (unsigned long)&sta->timer_to_tid[tid];
  793. init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
  794. tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
  795. /* prepare reordering buffer */
  796. tid_agg_rx->reorder_buf =
  797. kmalloc(buf_size * sizeof(struct sk_buff *), GFP_ATOMIC);
  798. if (!tid_agg_rx->reorder_buf) {
  799. #ifdef CONFIG_MAC80211_HT_DEBUG
  800. if (net_ratelimit())
  801. printk(KERN_ERR "can not allocate reordering buffer "
  802. "to tid %d\n", tid);
  803. #endif
  804. kfree(sta->ampdu_mlme.tid_rx[tid]);
  805. goto end;
  806. }
  807. memset(tid_agg_rx->reorder_buf, 0,
  808. buf_size * sizeof(struct sk_buff *));
  809. if (local->ops->ampdu_action)
  810. ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
  811. &sta->sta, tid, &start_seq_num);
  812. #ifdef CONFIG_MAC80211_HT_DEBUG
  813. printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
  814. #endif /* CONFIG_MAC80211_HT_DEBUG */
  815. if (ret) {
  816. kfree(tid_agg_rx->reorder_buf);
  817. kfree(tid_agg_rx);
  818. sta->ampdu_mlme.tid_rx[tid] = NULL;
  819. goto end;
  820. }
  821. /* change state and send addba resp */
  822. sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_OPERATIONAL;
  823. tid_agg_rx->dialog_token = dialog_token;
  824. tid_agg_rx->ssn = start_seq_num;
  825. tid_agg_rx->head_seq_num = start_seq_num;
  826. tid_agg_rx->buf_size = buf_size;
  827. tid_agg_rx->timeout = timeout;
  828. tid_agg_rx->stored_mpdu_num = 0;
  829. status = WLAN_STATUS_SUCCESS;
  830. end:
  831. spin_unlock_bh(&sta->lock);
  832. end_no_lock:
  833. ieee80211_send_addba_resp(sta->sdata, sta->sta.addr, tid,
  834. dialog_token, status, 1, buf_size, timeout);
  835. }
  836. void ieee80211_process_addba_resp(struct ieee80211_local *local,
  837. struct sta_info *sta,
  838. struct ieee80211_mgmt *mgmt,
  839. size_t len)
  840. {
  841. struct ieee80211_hw *hw = &local->hw;
  842. u16 capab;
  843. u16 tid;
  844. u8 *state;
  845. capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
  846. tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  847. state = &sta->ampdu_mlme.tid_state_tx[tid];
  848. spin_lock_bh(&sta->lock);
  849. if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
  850. spin_unlock_bh(&sta->lock);
  851. return;
  852. }
  853. if (mgmt->u.action.u.addba_resp.dialog_token !=
  854. sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
  855. spin_unlock_bh(&sta->lock);
  856. #ifdef CONFIG_MAC80211_HT_DEBUG
  857. printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
  858. #endif /* CONFIG_MAC80211_HT_DEBUG */
  859. return;
  860. }
  861. del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  862. #ifdef CONFIG_MAC80211_HT_DEBUG
  863. printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
  864. #endif /* CONFIG_MAC80211_HT_DEBUG */
  865. if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
  866. == WLAN_STATUS_SUCCESS) {
  867. *state |= HT_ADDBA_RECEIVED_MSK;
  868. sta->ampdu_mlme.addba_req_num[tid] = 0;
  869. if (*state == HT_AGG_STATE_OPERATIONAL &&
  870. local->hw.ampdu_queues)
  871. ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
  872. spin_unlock_bh(&sta->lock);
  873. } else {
  874. sta->ampdu_mlme.addba_req_num[tid]++;
  875. /* this will allow the state check in stop_BA_session */
  876. *state = HT_AGG_STATE_OPERATIONAL;
  877. spin_unlock_bh(&sta->lock);
  878. ieee80211_stop_tx_ba_session(hw, sta->sta.addr, tid,
  879. WLAN_BACK_INITIATOR);
  880. }
  881. }
  882. void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
  883. struct sta_info *sta,
  884. struct ieee80211_mgmt *mgmt, size_t len)
  885. {
  886. struct ieee80211_local *local = sdata->local;
  887. u16 tid, params;
  888. u16 initiator;
  889. params = le16_to_cpu(mgmt->u.action.u.delba.params);
  890. tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
  891. initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
  892. #ifdef CONFIG_MAC80211_HT_DEBUG
  893. if (net_ratelimit())
  894. printk(KERN_DEBUG "delba from %pM (%s) tid %d reason code %d\n",
  895. mgmt->sa, initiator ? "initiator" : "recipient", tid,
  896. mgmt->u.action.u.delba.reason_code);
  897. #endif /* CONFIG_MAC80211_HT_DEBUG */
  898. if (initiator == WLAN_BACK_INITIATOR)
  899. ieee80211_sta_stop_rx_ba_session(sdata, sta->sta.addr, tid,
  900. WLAN_BACK_INITIATOR, 0);
  901. else { /* WLAN_BACK_RECIPIENT */
  902. spin_lock_bh(&sta->lock);
  903. sta->ampdu_mlme.tid_state_tx[tid] =
  904. HT_AGG_STATE_OPERATIONAL;
  905. spin_unlock_bh(&sta->lock);
  906. ieee80211_stop_tx_ba_session(&local->hw, sta->sta.addr, tid,
  907. WLAN_BACK_RECIPIENT);
  908. }
  909. }