agg-tx.c 20 KB

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