agg-tx.c 20 KB

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