agg-tx.c 19 KB

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