agg-tx.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  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-2009, 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/mac80211.h>
  17. #include "ieee80211_i.h"
  18. #include "driver-ops.h"
  19. #include "wme.h"
  20. /**
  21. * DOC: TX aggregation
  22. *
  23. * Aggregation on the TX side requires setting the hardware flag
  24. * %IEEE80211_HW_AMPDU_AGGREGATION as well as, if present, the @ampdu_queues
  25. * hardware parameter to the number of hardware AMPDU queues. If there are no
  26. * hardware queues then the driver will (currently) have to do all frame
  27. * buffering.
  28. *
  29. * When TX aggregation is started by some subsystem (usually the rate control
  30. * algorithm would be appropriate) by calling the
  31. * ieee80211_start_tx_ba_session() function, the driver will be notified via
  32. * its @ampdu_action function, with the %IEEE80211_AMPDU_TX_START action.
  33. *
  34. * In response to that, the driver is later required to call the
  35. * ieee80211_start_tx_ba_cb() (or ieee80211_start_tx_ba_cb_irqsafe())
  36. * function, which will start the aggregation session.
  37. *
  38. * Similarly, when the aggregation session is stopped by
  39. * ieee80211_stop_tx_ba_session(), the driver's @ampdu_action function will
  40. * be called with the action %IEEE80211_AMPDU_TX_STOP. In this case, the
  41. * call must not fail, and the driver must later call ieee80211_stop_tx_ba_cb()
  42. * (or ieee80211_stop_tx_ba_cb_irqsafe()).
  43. */
  44. static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
  45. const u8 *da, u16 tid,
  46. u8 dialog_token, u16 start_seq_num,
  47. u16 agg_size, u16 timeout)
  48. {
  49. struct ieee80211_local *local = sdata->local;
  50. struct sk_buff *skb;
  51. struct ieee80211_mgmt *mgmt;
  52. u16 capab;
  53. skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
  54. if (!skb) {
  55. printk(KERN_ERR "%s: failed to allocate buffer "
  56. "for addba request frame\n", sdata->dev->name);
  57. return;
  58. }
  59. skb_reserve(skb, local->hw.extra_tx_headroom);
  60. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
  61. memset(mgmt, 0, 24);
  62. memcpy(mgmt->da, da, ETH_ALEN);
  63. memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
  64. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  65. sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  66. memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
  67. else if (sdata->vif.type == NL80211_IFTYPE_STATION)
  68. memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  69. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  70. IEEE80211_STYPE_ACTION);
  71. skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
  72. mgmt->u.action.category = WLAN_CATEGORY_BACK;
  73. mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
  74. mgmt->u.action.u.addba_req.dialog_token = dialog_token;
  75. capab = (u16)(1 << 1); /* bit 1 aggregation policy */
  76. capab |= (u16)(tid << 2); /* bit 5:2 TID number */
  77. capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
  78. mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
  79. mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
  80. mgmt->u.action.u.addba_req.start_seq_num =
  81. cpu_to_le16(start_seq_num << 4);
  82. ieee80211_tx_skb(sdata, skb, 1);
  83. }
  84. void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn)
  85. {
  86. struct ieee80211_local *local = sdata->local;
  87. struct sk_buff *skb;
  88. struct ieee80211_bar *bar;
  89. u16 bar_control = 0;
  90. skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom);
  91. if (!skb) {
  92. printk(KERN_ERR "%s: failed to allocate buffer for "
  93. "bar frame\n", sdata->dev->name);
  94. return;
  95. }
  96. skb_reserve(skb, local->hw.extra_tx_headroom);
  97. bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar));
  98. memset(bar, 0, sizeof(*bar));
  99. bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
  100. IEEE80211_STYPE_BACK_REQ);
  101. memcpy(bar->ra, ra, ETH_ALEN);
  102. memcpy(bar->ta, sdata->dev->dev_addr, ETH_ALEN);
  103. bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL;
  104. bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA;
  105. bar_control |= (u16)(tid << 12);
  106. bar->control = cpu_to_le16(bar_control);
  107. bar->start_seq_num = cpu_to_le16(ssn);
  108. ieee80211_tx_skb(sdata, skb, 0);
  109. }
  110. static int ___ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
  111. enum ieee80211_back_parties initiator)
  112. {
  113. struct ieee80211_local *local = sta->local;
  114. int ret;
  115. u8 *state;
  116. state = &sta->ampdu_mlme.tid_state_tx[tid];
  117. if (*state == HT_AGG_STATE_OPERATIONAL)
  118. sta->ampdu_mlme.addba_req_num[tid] = 0;
  119. *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
  120. (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
  121. ret = drv_ampdu_action(local, IEEE80211_AMPDU_TX_STOP,
  122. &sta->sta, tid, NULL);
  123. /* HW shall not deny going back to legacy */
  124. if (WARN_ON(ret)) {
  125. *state = HT_AGG_STATE_OPERATIONAL;
  126. /*
  127. * We may have pending packets get stuck in this case...
  128. * Not bothering with a workaround for now.
  129. */
  130. }
  131. return ret;
  132. }
  133. /*
  134. * After sending add Block Ack request we activated a timer until
  135. * add Block Ack response will arrive from the recipient.
  136. * If this timer expires sta_addba_resp_timer_expired will be executed.
  137. */
  138. static void sta_addba_resp_timer_expired(unsigned long data)
  139. {
  140. /* not an elegant detour, but there is no choice as the timer passes
  141. * only one argument, and both sta_info and TID are needed, so init
  142. * flow in sta_info_create gives the TID as data, while the timer_to_id
  143. * array gives the sta through container_of */
  144. u16 tid = *(u8 *)data;
  145. struct sta_info *sta = container_of((void *)data,
  146. struct sta_info, timer_to_tid[tid]);
  147. u8 *state;
  148. state = &sta->ampdu_mlme.tid_state_tx[tid];
  149. /* check if the TID waits for addBA response */
  150. spin_lock_bh(&sta->lock);
  151. if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
  152. spin_unlock_bh(&sta->lock);
  153. *state = HT_AGG_STATE_IDLE;
  154. #ifdef CONFIG_MAC80211_HT_DEBUG
  155. printk(KERN_DEBUG "timer expired on tid %d but we are not "
  156. "expecting addBA response there", tid);
  157. #endif
  158. return;
  159. }
  160. #ifdef CONFIG_MAC80211_HT_DEBUG
  161. printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
  162. #endif
  163. ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR);
  164. spin_unlock_bh(&sta->lock);
  165. }
  166. static inline int ieee80211_ac_from_tid(int tid)
  167. {
  168. return ieee802_1d_to_ac[tid & 7];
  169. }
  170. int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
  171. {
  172. struct ieee80211_local *local = hw_to_local(hw);
  173. struct sta_info *sta;
  174. struct ieee80211_sub_if_data *sdata;
  175. u8 *state;
  176. int ret = 0;
  177. u16 start_seq_num;
  178. if (WARN_ON(!local->ops->ampdu_action))
  179. return -EINVAL;
  180. if ((tid >= STA_TID_NUM) || !(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
  181. return -EINVAL;
  182. #ifdef CONFIG_MAC80211_HT_DEBUG
  183. printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n",
  184. ra, tid);
  185. #endif /* CONFIG_MAC80211_HT_DEBUG */
  186. rcu_read_lock();
  187. sta = sta_info_get(local, ra);
  188. if (!sta) {
  189. #ifdef CONFIG_MAC80211_HT_DEBUG
  190. printk(KERN_DEBUG "Could not find the station\n");
  191. #endif
  192. ret = -ENOENT;
  193. goto unlock;
  194. }
  195. /*
  196. * The aggregation code is not prepared to handle
  197. * anything but STA/AP due to the BSSID handling.
  198. * IBSS could work in the code but isn't supported
  199. * by drivers or the standard.
  200. */
  201. if (sta->sdata->vif.type != NL80211_IFTYPE_STATION &&
  202. sta->sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  203. sta->sdata->vif.type != NL80211_IFTYPE_AP) {
  204. ret = -EINVAL;
  205. goto unlock;
  206. }
  207. if (test_sta_flags(sta, WLAN_STA_SUSPEND)) {
  208. #ifdef CONFIG_MAC80211_HT_DEBUG
  209. printk(KERN_DEBUG "Suspend in progress. "
  210. "Denying BA session request\n");
  211. #endif
  212. ret = -EINVAL;
  213. goto unlock;
  214. }
  215. spin_lock_bh(&sta->lock);
  216. spin_lock(&local->ampdu_lock);
  217. sdata = sta->sdata;
  218. /* we have tried too many times, receiver does not want A-MPDU */
  219. if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
  220. ret = -EBUSY;
  221. goto err_unlock_sta;
  222. }
  223. state = &sta->ampdu_mlme.tid_state_tx[tid];
  224. /* check if the TID is not in aggregation flow already */
  225. if (*state != HT_AGG_STATE_IDLE) {
  226. #ifdef CONFIG_MAC80211_HT_DEBUG
  227. printk(KERN_DEBUG "BA request denied - session is not "
  228. "idle on tid %u\n", tid);
  229. #endif /* CONFIG_MAC80211_HT_DEBUG */
  230. ret = -EAGAIN;
  231. goto err_unlock_sta;
  232. }
  233. /*
  234. * While we're asking the driver about the aggregation,
  235. * stop the AC queue so that we don't have to worry
  236. * about frames that came in while we were doing that,
  237. * which would require us to put them to the AC pending
  238. * afterwards which just makes the code more complex.
  239. */
  240. ieee80211_stop_queue_by_reason(
  241. &local->hw, ieee80211_ac_from_tid(tid),
  242. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  243. /* prepare A-MPDU MLME for Tx aggregation */
  244. sta->ampdu_mlme.tid_tx[tid] =
  245. kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
  246. if (!sta->ampdu_mlme.tid_tx[tid]) {
  247. #ifdef CONFIG_MAC80211_HT_DEBUG
  248. if (net_ratelimit())
  249. printk(KERN_ERR "allocate tx mlme to tid %d failed\n",
  250. tid);
  251. #endif
  252. ret = -ENOMEM;
  253. goto err_wake_queue;
  254. }
  255. skb_queue_head_init(&sta->ampdu_mlme.tid_tx[tid]->pending);
  256. /* Tx timer */
  257. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function =
  258. sta_addba_resp_timer_expired;
  259. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data =
  260. (unsigned long)&sta->timer_to_tid[tid];
  261. init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  262. /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
  263. * call back right away, it must see that the flow has begun */
  264. *state |= HT_ADDBA_REQUESTED_MSK;
  265. start_seq_num = sta->tid_seq[tid];
  266. ret = drv_ampdu_action(local, IEEE80211_AMPDU_TX_START,
  267. &sta->sta, tid, &start_seq_num);
  268. if (ret) {
  269. #ifdef CONFIG_MAC80211_HT_DEBUG
  270. printk(KERN_DEBUG "BA request denied - HW unavailable for"
  271. " tid %d\n", tid);
  272. #endif /* CONFIG_MAC80211_HT_DEBUG */
  273. *state = HT_AGG_STATE_IDLE;
  274. goto err_free;
  275. }
  276. /* Driver vetoed or OKed, but we can take packets again now */
  277. ieee80211_wake_queue_by_reason(
  278. &local->hw, ieee80211_ac_from_tid(tid),
  279. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  280. spin_unlock(&local->ampdu_lock);
  281. spin_unlock_bh(&sta->lock);
  282. /* send an addBA request */
  283. sta->ampdu_mlme.dialog_token_allocator++;
  284. sta->ampdu_mlme.tid_tx[tid]->dialog_token =
  285. sta->ampdu_mlme.dialog_token_allocator;
  286. sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num;
  287. ieee80211_send_addba_request(sta->sdata, ra, tid,
  288. sta->ampdu_mlme.tid_tx[tid]->dialog_token,
  289. sta->ampdu_mlme.tid_tx[tid]->ssn,
  290. 0x40, 5000);
  291. sta->ampdu_mlme.addba_req_num[tid]++;
  292. /* activate the timer for the recipient's addBA response */
  293. sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires =
  294. jiffies + ADDBA_RESP_INTERVAL;
  295. add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  296. #ifdef CONFIG_MAC80211_HT_DEBUG
  297. printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
  298. #endif
  299. goto unlock;
  300. err_free:
  301. kfree(sta->ampdu_mlme.tid_tx[tid]);
  302. sta->ampdu_mlme.tid_tx[tid] = NULL;
  303. err_wake_queue:
  304. ieee80211_wake_queue_by_reason(
  305. &local->hw, ieee80211_ac_from_tid(tid),
  306. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  307. err_unlock_sta:
  308. spin_unlock(&local->ampdu_lock);
  309. spin_unlock_bh(&sta->lock);
  310. unlock:
  311. rcu_read_unlock();
  312. return ret;
  313. }
  314. EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
  315. /*
  316. * splice packets from the STA's pending to the local pending,
  317. * requires a call to ieee80211_agg_splice_finish and holding
  318. * local->ampdu_lock across both calls.
  319. */
  320. static void ieee80211_agg_splice_packets(struct ieee80211_local *local,
  321. struct sta_info *sta, u16 tid)
  322. {
  323. unsigned long flags;
  324. u16 queue = ieee80211_ac_from_tid(tid);
  325. ieee80211_stop_queue_by_reason(
  326. &local->hw, queue,
  327. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  328. if (!(sta->ampdu_mlme.tid_state_tx[tid] & HT_ADDBA_REQUESTED_MSK))
  329. return;
  330. if (WARN(!sta->ampdu_mlme.tid_tx[tid],
  331. "TID %d gone but expected when splicing aggregates from"
  332. "the pending queue\n", tid))
  333. return;
  334. if (!skb_queue_empty(&sta->ampdu_mlme.tid_tx[tid]->pending)) {
  335. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  336. /* copy over remaining packets */
  337. skb_queue_splice_tail_init(
  338. &sta->ampdu_mlme.tid_tx[tid]->pending,
  339. &local->pending[queue]);
  340. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  341. }
  342. }
  343. static void ieee80211_agg_splice_finish(struct ieee80211_local *local,
  344. struct sta_info *sta, u16 tid)
  345. {
  346. u16 queue = ieee80211_ac_from_tid(tid);
  347. ieee80211_wake_queue_by_reason(
  348. &local->hw, queue,
  349. IEEE80211_QUEUE_STOP_REASON_AGGREGATION);
  350. }
  351. /* caller must hold sta->lock */
  352. static void ieee80211_agg_tx_operational(struct ieee80211_local *local,
  353. struct sta_info *sta, u16 tid)
  354. {
  355. #ifdef CONFIG_MAC80211_HT_DEBUG
  356. printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
  357. #endif
  358. spin_lock(&local->ampdu_lock);
  359. ieee80211_agg_splice_packets(local, sta, tid);
  360. /*
  361. * NB: we rely on sta->lock being taken in the TX
  362. * processing here when adding to the pending queue,
  363. * otherwise we could only change the state of the
  364. * session to OPERATIONAL _here_.
  365. */
  366. ieee80211_agg_splice_finish(local, sta, tid);
  367. spin_unlock(&local->ampdu_lock);
  368. drv_ampdu_action(local, IEEE80211_AMPDU_TX_OPERATIONAL,
  369. &sta->sta, tid, NULL);
  370. }
  371. void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
  372. {
  373. struct ieee80211_local *local = hw_to_local(hw);
  374. struct sta_info *sta;
  375. u8 *state;
  376. if (tid >= STA_TID_NUM) {
  377. #ifdef CONFIG_MAC80211_HT_DEBUG
  378. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  379. tid, STA_TID_NUM);
  380. #endif
  381. return;
  382. }
  383. rcu_read_lock();
  384. sta = sta_info_get(local, ra);
  385. if (!sta) {
  386. rcu_read_unlock();
  387. #ifdef CONFIG_MAC80211_HT_DEBUG
  388. printk(KERN_DEBUG "Could not find station: %pM\n", ra);
  389. #endif
  390. return;
  391. }
  392. state = &sta->ampdu_mlme.tid_state_tx[tid];
  393. spin_lock_bh(&sta->lock);
  394. if (WARN_ON(!(*state & HT_ADDBA_REQUESTED_MSK))) {
  395. #ifdef CONFIG_MAC80211_HT_DEBUG
  396. printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
  397. *state);
  398. #endif
  399. spin_unlock_bh(&sta->lock);
  400. rcu_read_unlock();
  401. return;
  402. }
  403. if (WARN_ON(*state & HT_ADDBA_DRV_READY_MSK))
  404. goto out;
  405. *state |= HT_ADDBA_DRV_READY_MSK;
  406. if (*state == HT_AGG_STATE_OPERATIONAL)
  407. ieee80211_agg_tx_operational(local, sta, tid);
  408. out:
  409. spin_unlock_bh(&sta->lock);
  410. rcu_read_unlock();
  411. }
  412. EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
  413. void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
  414. const u8 *ra, u16 tid)
  415. {
  416. struct ieee80211_local *local = hw_to_local(hw);
  417. struct ieee80211_ra_tid *ra_tid;
  418. struct sk_buff *skb = dev_alloc_skb(0);
  419. if (unlikely(!skb)) {
  420. #ifdef CONFIG_MAC80211_HT_DEBUG
  421. if (net_ratelimit())
  422. printk(KERN_WARNING "%s: Not enough memory, "
  423. "dropping start BA session", skb->dev->name);
  424. #endif
  425. return;
  426. }
  427. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  428. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  429. ra_tid->tid = tid;
  430. skb->pkt_type = IEEE80211_ADDBA_MSG;
  431. skb_queue_tail(&local->skb_queue, skb);
  432. tasklet_schedule(&local->tasklet);
  433. }
  434. EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
  435. int __ieee80211_stop_tx_ba_session(struct sta_info *sta, u16 tid,
  436. enum ieee80211_back_parties initiator)
  437. {
  438. u8 *state;
  439. int ret;
  440. /* check if the TID is in aggregation */
  441. state = &sta->ampdu_mlme.tid_state_tx[tid];
  442. spin_lock_bh(&sta->lock);
  443. if (*state != HT_AGG_STATE_OPERATIONAL) {
  444. ret = -ENOENT;
  445. goto unlock;
  446. }
  447. #ifdef CONFIG_MAC80211_HT_DEBUG
  448. printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
  449. sta->sta.addr, tid);
  450. #endif /* CONFIG_MAC80211_HT_DEBUG */
  451. ret = ___ieee80211_stop_tx_ba_session(sta, tid, initiator);
  452. unlock:
  453. spin_unlock_bh(&sta->lock);
  454. return ret;
  455. }
  456. int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
  457. u8 *ra, u16 tid,
  458. enum ieee80211_back_parties initiator)
  459. {
  460. struct ieee80211_local *local = hw_to_local(hw);
  461. struct sta_info *sta;
  462. int ret = 0;
  463. if (WARN_ON(!local->ops->ampdu_action))
  464. return -EINVAL;
  465. if (tid >= STA_TID_NUM)
  466. return -EINVAL;
  467. rcu_read_lock();
  468. sta = sta_info_get(local, ra);
  469. if (!sta) {
  470. rcu_read_unlock();
  471. return -ENOENT;
  472. }
  473. ret = __ieee80211_stop_tx_ba_session(sta, tid, initiator);
  474. rcu_read_unlock();
  475. return ret;
  476. }
  477. EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
  478. void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
  479. {
  480. struct ieee80211_local *local = hw_to_local(hw);
  481. struct sta_info *sta;
  482. u8 *state;
  483. if (tid >= STA_TID_NUM) {
  484. #ifdef CONFIG_MAC80211_HT_DEBUG
  485. printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
  486. tid, STA_TID_NUM);
  487. #endif
  488. return;
  489. }
  490. #ifdef CONFIG_MAC80211_HT_DEBUG
  491. printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n",
  492. ra, tid);
  493. #endif /* CONFIG_MAC80211_HT_DEBUG */
  494. rcu_read_lock();
  495. sta = sta_info_get(local, ra);
  496. if (!sta) {
  497. #ifdef CONFIG_MAC80211_HT_DEBUG
  498. printk(KERN_DEBUG "Could not find station: %pM\n", ra);
  499. #endif
  500. rcu_read_unlock();
  501. return;
  502. }
  503. state = &sta->ampdu_mlme.tid_state_tx[tid];
  504. /* NOTE: no need to use sta->lock in this state check, as
  505. * ieee80211_stop_tx_ba_session will let only one stop call to
  506. * pass through per sta/tid
  507. */
  508. if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
  509. #ifdef CONFIG_MAC80211_HT_DEBUG
  510. printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
  511. #endif
  512. rcu_read_unlock();
  513. return;
  514. }
  515. if (*state & HT_AGG_STATE_INITIATOR_MSK)
  516. ieee80211_send_delba(sta->sdata, ra, tid,
  517. WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
  518. spin_lock_bh(&sta->lock);
  519. spin_lock(&local->ampdu_lock);
  520. ieee80211_agg_splice_packets(local, sta, tid);
  521. *state = HT_AGG_STATE_IDLE;
  522. /* from now on packets are no longer put onto sta->pending */
  523. kfree(sta->ampdu_mlme.tid_tx[tid]);
  524. sta->ampdu_mlme.tid_tx[tid] = NULL;
  525. ieee80211_agg_splice_finish(local, sta, tid);
  526. spin_unlock(&local->ampdu_lock);
  527. spin_unlock_bh(&sta->lock);
  528. rcu_read_unlock();
  529. }
  530. EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
  531. void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
  532. const u8 *ra, u16 tid)
  533. {
  534. struct ieee80211_local *local = hw_to_local(hw);
  535. struct ieee80211_ra_tid *ra_tid;
  536. struct sk_buff *skb = dev_alloc_skb(0);
  537. if (unlikely(!skb)) {
  538. #ifdef CONFIG_MAC80211_HT_DEBUG
  539. if (net_ratelimit())
  540. printk(KERN_WARNING "%s: Not enough memory, "
  541. "dropping stop BA session", skb->dev->name);
  542. #endif
  543. return;
  544. }
  545. ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
  546. memcpy(&ra_tid->ra, ra, ETH_ALEN);
  547. ra_tid->tid = tid;
  548. skb->pkt_type = IEEE80211_DELBA_MSG;
  549. skb_queue_tail(&local->skb_queue, skb);
  550. tasklet_schedule(&local->tasklet);
  551. }
  552. EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
  553. void ieee80211_process_addba_resp(struct ieee80211_local *local,
  554. struct sta_info *sta,
  555. struct ieee80211_mgmt *mgmt,
  556. size_t len)
  557. {
  558. u16 capab, tid;
  559. u8 *state;
  560. capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
  561. tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  562. state = &sta->ampdu_mlme.tid_state_tx[tid];
  563. del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  564. spin_lock_bh(&sta->lock);
  565. if (!(*state & HT_ADDBA_REQUESTED_MSK))
  566. goto timer_still_needed;
  567. if (mgmt->u.action.u.addba_resp.dialog_token !=
  568. sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
  569. #ifdef CONFIG_MAC80211_HT_DEBUG
  570. printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
  571. #endif /* CONFIG_MAC80211_HT_DEBUG */
  572. goto timer_still_needed;
  573. }
  574. #ifdef CONFIG_MAC80211_HT_DEBUG
  575. printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
  576. #endif /* CONFIG_MAC80211_HT_DEBUG */
  577. if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
  578. == WLAN_STATUS_SUCCESS) {
  579. u8 curstate = *state;
  580. *state |= HT_ADDBA_RECEIVED_MSK;
  581. if (*state != curstate && *state == HT_AGG_STATE_OPERATIONAL)
  582. ieee80211_agg_tx_operational(local, sta, tid);
  583. sta->ampdu_mlme.addba_req_num[tid] = 0;
  584. } else {
  585. ___ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_INITIATOR);
  586. }
  587. goto out;
  588. timer_still_needed:
  589. add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
  590. out:
  591. spin_unlock_bh(&sta->lock);
  592. }