ht.c 32 KB

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