ht.c 32 KB

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