Commit | Line | Data |
---|---|---|
b8695a8f JB |
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 | ||
16 | #include <linux/ieee80211.h> | |
17 | #include <net/mac80211.h> | |
18 | #include "ieee80211_i.h" | |
19 | #include "wme.h" | |
20 | ||
86ab6c5a JB |
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 | ||
b8695a8f JB |
46 | static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata, |
47 | const u8 *da, u16 tid, | |
48 | u8 dialog_token, u16 start_seq_num, | |
49 | u16 agg_size, u16 timeout) | |
50 | { | |
51 | struct ieee80211_local *local = sdata->local; | |
52 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; | |
53 | struct sk_buff *skb; | |
54 | struct ieee80211_mgmt *mgmt; | |
55 | u16 capab; | |
56 | ||
57 | skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom); | |
58 | ||
59 | if (!skb) { | |
60 | printk(KERN_ERR "%s: failed to allocate buffer " | |
61 | "for addba request frame\n", sdata->dev->name); | |
62 | return; | |
63 | } | |
64 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
65 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); | |
66 | memset(mgmt, 0, 24); | |
67 | memcpy(mgmt->da, da, ETH_ALEN); | |
68 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); | |
8abd3f9b JB |
69 | if (sdata->vif.type == NL80211_IFTYPE_AP || |
70 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN) | |
b8695a8f JB |
71 | memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); |
72 | else | |
73 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); | |
74 | ||
75 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | | |
76 | IEEE80211_STYPE_ACTION); | |
77 | ||
78 | skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req)); | |
79 | ||
80 | mgmt->u.action.category = WLAN_CATEGORY_BACK; | |
81 | mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ; | |
82 | ||
83 | mgmt->u.action.u.addba_req.dialog_token = dialog_token; | |
84 | capab = (u16)(1 << 1); /* bit 1 aggregation policy */ | |
85 | capab |= (u16)(tid << 2); /* bit 5:2 TID number */ | |
86 | capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */ | |
87 | ||
88 | mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab); | |
89 | ||
90 | mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout); | |
91 | mgmt->u.action.u.addba_req.start_seq_num = | |
92 | cpu_to_le16(start_seq_num << 4); | |
93 | ||
94 | ieee80211_tx_skb(sdata, skb, 1); | |
95 | } | |
96 | ||
97 | void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn) | |
98 | { | |
99 | struct ieee80211_local *local = sdata->local; | |
100 | struct sk_buff *skb; | |
101 | struct ieee80211_bar *bar; | |
102 | u16 bar_control = 0; | |
103 | ||
104 | skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom); | |
105 | if (!skb) { | |
106 | printk(KERN_ERR "%s: failed to allocate buffer for " | |
107 | "bar frame\n", sdata->dev->name); | |
108 | return; | |
109 | } | |
110 | skb_reserve(skb, local->hw.extra_tx_headroom); | |
111 | bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar)); | |
112 | memset(bar, 0, sizeof(*bar)); | |
113 | bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | | |
114 | IEEE80211_STYPE_BACK_REQ); | |
115 | memcpy(bar->ra, ra, ETH_ALEN); | |
116 | memcpy(bar->ta, sdata->dev->dev_addr, ETH_ALEN); | |
117 | bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL; | |
118 | bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA; | |
119 | bar_control |= (u16)(tid << 12); | |
120 | bar->control = cpu_to_le16(bar_control); | |
121 | bar->start_seq_num = cpu_to_le16(ssn); | |
122 | ||
123 | ieee80211_tx_skb(sdata, skb, 0); | |
124 | } | |
125 | ||
23e6a7ea JB |
126 | static int __ieee80211_stop_tx_ba_session(struct ieee80211_local *local, |
127 | struct sta_info *sta, u16 tid, | |
128 | enum ieee80211_back_parties initiator) | |
129 | { | |
130 | int ret; | |
131 | u8 *state; | |
132 | ||
133 | state = &sta->ampdu_mlme.tid_state_tx[tid]; | |
134 | ||
135 | if (local->hw.ampdu_queues) | |
136 | ieee80211_stop_queue(&local->hw, sta->tid_to_tx_q[tid]); | |
137 | ||
138 | *state = HT_AGG_STATE_REQ_STOP_BA_MSK | | |
139 | (initiator << HT_AGG_STATE_INITIATOR_SHIFT); | |
140 | ||
141 | ret = local->ops->ampdu_action(&local->hw, IEEE80211_AMPDU_TX_STOP, | |
142 | &sta->sta, tid, NULL); | |
143 | ||
144 | /* HW shall not deny going back to legacy */ | |
145 | if (WARN_ON(ret)) { | |
146 | *state = HT_AGG_STATE_OPERATIONAL; | |
147 | if (local->hw.ampdu_queues) | |
148 | ieee80211_wake_queue(&local->hw, sta->tid_to_tx_q[tid]); | |
149 | } | |
150 | ||
151 | return ret; | |
152 | } | |
153 | ||
b8695a8f JB |
154 | /* |
155 | * After sending add Block Ack request we activated a timer until | |
156 | * add Block Ack response will arrive from the recipient. | |
157 | * If this timer expires sta_addba_resp_timer_expired will be executed. | |
158 | */ | |
159 | static void sta_addba_resp_timer_expired(unsigned long data) | |
160 | { | |
161 | /* not an elegant detour, but there is no choice as the timer passes | |
162 | * only one argument, and both sta_info and TID are needed, so init | |
163 | * flow in sta_info_create gives the TID as data, while the timer_to_id | |
164 | * array gives the sta through container_of */ | |
165 | u16 tid = *(u8 *)data; | |
23e6a7ea | 166 | struct sta_info *sta = container_of((void *)data, |
b8695a8f | 167 | struct sta_info, timer_to_tid[tid]); |
23e6a7ea | 168 | struct ieee80211_local *local = sta->local; |
b8695a8f JB |
169 | u8 *state; |
170 | ||
b8695a8f | 171 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
23e6a7ea | 172 | |
b8695a8f JB |
173 | /* check if the TID waits for addBA response */ |
174 | spin_lock_bh(&sta->lock); | |
175 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { | |
176 | spin_unlock_bh(&sta->lock); | |
177 | *state = HT_AGG_STATE_IDLE; | |
178 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
179 | printk(KERN_DEBUG "timer expired on tid %d but we are not " | |
180 | "expecting addBA response there", tid); | |
181 | #endif | |
23e6a7ea | 182 | return; |
b8695a8f JB |
183 | } |
184 | ||
185 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
186 | printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid); | |
187 | #endif | |
188 | ||
23e6a7ea | 189 | __ieee80211_stop_tx_ba_session(local, sta, tid, WLAN_BACK_INITIATOR); |
b8695a8f | 190 | spin_unlock_bh(&sta->lock); |
b8695a8f JB |
191 | } |
192 | ||
193 | int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid) | |
194 | { | |
195 | struct ieee80211_local *local = hw_to_local(hw); | |
196 | struct sta_info *sta; | |
197 | struct ieee80211_sub_if_data *sdata; | |
198 | u16 start_seq_num; | |
199 | u8 *state; | |
200 | int ret = 0; | |
201 | ||
23e6a7ea JB |
202 | if (WARN_ON(!local->ops->ampdu_action)) |
203 | return -EINVAL; | |
204 | ||
b8695a8f JB |
205 | if ((tid >= STA_TID_NUM) || !(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION)) |
206 | return -EINVAL; | |
207 | ||
208 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
209 | printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n", | |
210 | ra, tid); | |
211 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
212 | ||
213 | rcu_read_lock(); | |
214 | ||
215 | sta = sta_info_get(local, ra); | |
216 | if (!sta) { | |
217 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
218 | printk(KERN_DEBUG "Could not find the station\n"); | |
219 | #endif | |
220 | ret = -ENOENT; | |
221 | goto exit; | |
222 | } | |
223 | ||
8abd3f9b JB |
224 | /* |
225 | * The aggregation code is not prepared to handle | |
226 | * anything but STA/AP due to the BSSID handling. | |
227 | * IBSS could work in the code but isn't supported | |
228 | * by drivers or the standard. | |
229 | */ | |
230 | if (sta->sdata->vif.type != NL80211_IFTYPE_STATION && | |
231 | sta->sdata->vif.type != NL80211_IFTYPE_AP_VLAN && | |
232 | sta->sdata->vif.type != NL80211_IFTYPE_AP) { | |
233 | ret = -EINVAL; | |
234 | goto exit; | |
235 | } | |
236 | ||
b8695a8f JB |
237 | spin_lock_bh(&sta->lock); |
238 | ||
239 | /* we have tried too many times, receiver does not want A-MPDU */ | |
240 | if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) { | |
241 | ret = -EBUSY; | |
242 | goto err_unlock_sta; | |
243 | } | |
244 | ||
245 | state = &sta->ampdu_mlme.tid_state_tx[tid]; | |
246 | /* check if the TID is not in aggregation flow already */ | |
247 | if (*state != HT_AGG_STATE_IDLE) { | |
248 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
249 | printk(KERN_DEBUG "BA request denied - session is not " | |
250 | "idle on tid %u\n", tid); | |
251 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
252 | ret = -EAGAIN; | |
253 | goto err_unlock_sta; | |
254 | } | |
255 | ||
256 | /* prepare A-MPDU MLME for Tx aggregation */ | |
257 | sta->ampdu_mlme.tid_tx[tid] = | |
258 | kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC); | |
259 | if (!sta->ampdu_mlme.tid_tx[tid]) { | |
260 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
261 | if (net_ratelimit()) | |
262 | printk(KERN_ERR "allocate tx mlme to tid %d failed\n", | |
263 | tid); | |
264 | #endif | |
265 | ret = -ENOMEM; | |
266 | goto err_unlock_sta; | |
267 | } | |
268 | /* Tx timer */ | |
269 | sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function = | |
270 | sta_addba_resp_timer_expired; | |
271 | sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data = | |
272 | (unsigned long)&sta->timer_to_tid[tid]; | |
273 | init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer); | |
274 | ||
275 | if (hw->ampdu_queues) { | |
276 | /* create a new queue for this aggregation */ | |
277 | ret = ieee80211_ht_agg_queue_add(local, sta, tid); | |
278 | ||
279 | /* case no queue is available to aggregation | |
280 | * don't switch to aggregation */ | |
281 | if (ret) { | |
282 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
283 | printk(KERN_DEBUG "BA request denied - " | |
284 | "queue unavailable for tid %d\n", tid); | |
285 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
286 | goto err_unlock_queue; | |
287 | } | |
288 | } | |
289 | sdata = sta->sdata; | |
290 | ||
291 | /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the | |
292 | * call back right away, it must see that the flow has begun */ | |
293 | *state |= HT_ADDBA_REQUESTED_MSK; | |
294 | ||
295 | /* This is slightly racy because the queue isn't stopped */ | |
296 | start_seq_num = sta->tid_seq[tid]; | |
297 | ||
23e6a7ea JB |
298 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START, |
299 | &sta->sta, tid, &start_seq_num); | |
b8695a8f JB |
300 | |
301 | if (ret) { | |
302 | /* No need to requeue the packets in the agg queue, since we | |
303 | * held the tx lock: no packet could be enqueued to the newly | |
304 | * allocated queue */ | |
305 | if (hw->ampdu_queues) | |
306 | ieee80211_ht_agg_queue_remove(local, sta, tid, 0); | |
307 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
308 | printk(KERN_DEBUG "BA request denied - HW unavailable for" | |
309 | " tid %d\n", tid); | |
310 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
311 | *state = HT_AGG_STATE_IDLE; | |
312 | goto err_unlock_queue; | |
313 | } | |
314 | ||
315 | /* Will put all the packets in the new SW queue */ | |
316 | if (hw->ampdu_queues) | |
317 | ieee80211_requeue(local, ieee802_1d_to_ac[tid]); | |
318 | spin_unlock_bh(&sta->lock); | |
319 | ||
320 | /* send an addBA request */ | |
321 | sta->ampdu_mlme.dialog_token_allocator++; | |
322 | sta->ampdu_mlme.tid_tx[tid]->dialog_token = | |
323 | sta->ampdu_mlme.dialog_token_allocator; | |
324 | sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num; | |
325 | ||
326 | ||
327 | ieee80211_send_addba_request(sta->sdata, ra, tid, | |
328 | sta->ampdu_mlme.tid_tx[tid]->dialog_token, | |
329 | sta->ampdu_mlme.tid_tx[tid]->ssn, | |
330 | 0x40, 5000); | |
331 | /* activate the timer for the recipient's addBA response */ | |
332 | sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires = | |
333 | jiffies + ADDBA_RESP_INTERVAL; | |
334 | add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer); | |
335 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
336 | printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid); | |
337 | #endif | |
338 | goto exit; | |
339 | ||
340 | err_unlock_queue: | |
341 | kfree(sta->ampdu_mlme.tid_tx[tid]); | |
342 | sta->ampdu_mlme.tid_tx[tid] = NULL; | |
343 | ret = -EBUSY; | |
344 | err_unlock_sta: | |
345 | spin_unlock_bh(&sta->lock); | |
346 | exit: | |
347 | rcu_read_unlock(); | |
348 | return ret; | |
349 | } | |
350 | EXPORT_SYMBOL(ieee80211_start_tx_ba_session); | |
351 | ||
352 | void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid) | |
353 | { | |
354 | struct ieee80211_local *local = hw_to_local(hw); | |
355 | struct sta_info *sta; | |
356 | u8 *state; | |
357 | ||
358 | if (tid >= STA_TID_NUM) { | |
359 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
360 | printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n", | |
361 | tid, STA_TID_NUM); | |
362 | #endif | |
363 | return; | |
364 | } | |
365 | ||
366 | rcu_read_lock(); | |
367 | sta = sta_info_get(local, ra); | |
368 | if (!sta) { | |
369 | rcu_read_unlock(); | |
370 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
371 | printk(KERN_DEBUG "Could not find station: %pM\n", ra); | |
372 | #endif | |
373 | return; | |
374 | } | |
375 | ||
376 | state = &sta->ampdu_mlme.tid_state_tx[tid]; | |
377 | spin_lock_bh(&sta->lock); | |
378 | ||
379 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { | |
380 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
381 | printk(KERN_DEBUG "addBA was not requested yet, state is %d\n", | |
382 | *state); | |
383 | #endif | |
384 | spin_unlock_bh(&sta->lock); | |
385 | rcu_read_unlock(); | |
386 | return; | |
387 | } | |
388 | ||
389 | WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK); | |
390 | ||
391 | *state |= HT_ADDBA_DRV_READY_MSK; | |
392 | ||
393 | if (*state == HT_AGG_STATE_OPERATIONAL) { | |
394 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
395 | printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid); | |
396 | #endif | |
397 | if (hw->ampdu_queues) | |
398 | ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); | |
399 | } | |
400 | spin_unlock_bh(&sta->lock); | |
401 | rcu_read_unlock(); | |
402 | } | |
403 | EXPORT_SYMBOL(ieee80211_start_tx_ba_cb); | |
404 | ||
86ab6c5a JB |
405 | void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, |
406 | const u8 *ra, u16 tid) | |
407 | { | |
408 | struct ieee80211_local *local = hw_to_local(hw); | |
409 | struct ieee80211_ra_tid *ra_tid; | |
410 | struct sk_buff *skb = dev_alloc_skb(0); | |
411 | ||
412 | if (unlikely(!skb)) { | |
413 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
414 | if (net_ratelimit()) | |
415 | printk(KERN_WARNING "%s: Not enough memory, " | |
416 | "dropping start BA session", skb->dev->name); | |
417 | #endif | |
418 | return; | |
419 | } | |
420 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; | |
421 | memcpy(&ra_tid->ra, ra, ETH_ALEN); | |
422 | ra_tid->tid = tid; | |
423 | ||
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 | ||
b8695a8f JB |
430 | |
431 | int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw, | |
432 | u8 *ra, u16 tid, | |
433 | enum ieee80211_back_parties initiator) | |
434 | { | |
435 | struct ieee80211_local *local = hw_to_local(hw); | |
436 | struct sta_info *sta; | |
437 | u8 *state; | |
438 | int ret = 0; | |
439 | ||
23e6a7ea JB |
440 | if (WARN_ON(!local->ops->ampdu_action)) |
441 | return -EINVAL; | |
442 | ||
b8695a8f JB |
443 | if (tid >= STA_TID_NUM) |
444 | return -EINVAL; | |
445 | ||
446 | rcu_read_lock(); | |
447 | sta = sta_info_get(local, ra); | |
448 | if (!sta) { | |
449 | rcu_read_unlock(); | |
450 | return -ENOENT; | |
451 | } | |
452 | ||
453 | /* check if the TID is in aggregation */ | |
454 | state = &sta->ampdu_mlme.tid_state_tx[tid]; | |
455 | spin_lock_bh(&sta->lock); | |
456 | ||
457 | if (*state != HT_AGG_STATE_OPERATIONAL) { | |
458 | ret = -ENOENT; | |
23e6a7ea | 459 | goto unlock; |
b8695a8f JB |
460 | } |
461 | ||
462 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
463 | printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n", | |
464 | ra, tid); | |
465 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
466 | ||
23e6a7ea | 467 | ret = __ieee80211_stop_tx_ba_session(local, sta, tid, initiator); |
b8695a8f | 468 | |
23e6a7ea | 469 | unlock: |
b8695a8f | 470 | spin_unlock_bh(&sta->lock); |
23e6a7ea | 471 | |
b8695a8f | 472 | rcu_read_unlock(); |
23e6a7ea | 473 | |
b8695a8f JB |
474 | return ret; |
475 | } | |
476 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_session); | |
477 | ||
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 | int agg_queue; | |
484 | ||
485 | if (tid >= STA_TID_NUM) { | |
486 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
487 | printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n", | |
488 | tid, STA_TID_NUM); | |
489 | #endif | |
490 | return; | |
491 | } | |
492 | ||
493 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
494 | printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n", | |
495 | ra, tid); | |
496 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
497 | ||
498 | rcu_read_lock(); | |
499 | sta = sta_info_get(local, ra); | |
500 | if (!sta) { | |
501 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
502 | printk(KERN_DEBUG "Could not find station: %pM\n", ra); | |
503 | #endif | |
504 | rcu_read_unlock(); | |
505 | return; | |
506 | } | |
507 | state = &sta->ampdu_mlme.tid_state_tx[tid]; | |
508 | ||
509 | /* NOTE: no need to use sta->lock in this state check, as | |
510 | * ieee80211_stop_tx_ba_session will let only one stop call to | |
511 | * pass through per sta/tid | |
512 | */ | |
513 | if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) { | |
514 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
515 | printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n"); | |
516 | #endif | |
517 | rcu_read_unlock(); | |
518 | return; | |
519 | } | |
520 | ||
521 | if (*state & HT_AGG_STATE_INITIATOR_MSK) | |
522 | ieee80211_send_delba(sta->sdata, ra, tid, | |
523 | WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE); | |
524 | ||
525 | if (hw->ampdu_queues) { | |
526 | agg_queue = sta->tid_to_tx_q[tid]; | |
527 | ieee80211_ht_agg_queue_remove(local, sta, tid, 1); | |
528 | ||
529 | /* We just requeued the all the frames that were in the | |
530 | * removed queue, and since we might miss a softirq we do | |
531 | * netif_schedule_queue. ieee80211_wake_queue is not used | |
532 | * here as this queue is not necessarily stopped | |
533 | */ | |
534 | netif_schedule_queue(netdev_get_tx_queue(local->mdev, | |
535 | agg_queue)); | |
536 | } | |
537 | spin_lock_bh(&sta->lock); | |
538 | *state = HT_AGG_STATE_IDLE; | |
539 | sta->ampdu_mlme.addba_req_num[tid] = 0; | |
540 | kfree(sta->ampdu_mlme.tid_tx[tid]); | |
541 | sta->ampdu_mlme.tid_tx[tid] = NULL; | |
542 | spin_unlock_bh(&sta->lock); | |
543 | ||
544 | rcu_read_unlock(); | |
545 | } | |
546 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb); | |
547 | ||
b8695a8f JB |
548 | void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, |
549 | const u8 *ra, u16 tid) | |
550 | { | |
551 | struct ieee80211_local *local = hw_to_local(hw); | |
552 | struct ieee80211_ra_tid *ra_tid; | |
553 | struct sk_buff *skb = dev_alloc_skb(0); | |
554 | ||
555 | if (unlikely(!skb)) { | |
556 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
557 | if (net_ratelimit()) | |
558 | printk(KERN_WARNING "%s: Not enough memory, " | |
559 | "dropping stop BA session", skb->dev->name); | |
560 | #endif | |
561 | return; | |
562 | } | |
563 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; | |
564 | memcpy(&ra_tid->ra, ra, ETH_ALEN); | |
565 | ra_tid->tid = tid; | |
566 | ||
567 | skb->pkt_type = IEEE80211_DELBA_MSG; | |
568 | skb_queue_tail(&local->skb_queue, skb); | |
569 | tasklet_schedule(&local->tasklet); | |
570 | } | |
571 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe); | |
572 | ||
86ab6c5a | 573 | |
b8695a8f JB |
574 | void ieee80211_process_addba_resp(struct ieee80211_local *local, |
575 | struct sta_info *sta, | |
576 | struct ieee80211_mgmt *mgmt, | |
577 | size_t len) | |
578 | { | |
579 | struct ieee80211_hw *hw = &local->hw; | |
580 | u16 capab; | |
581 | u16 tid, start_seq_num; | |
582 | u8 *state; | |
583 | ||
584 | capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab); | |
585 | tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; | |
586 | ||
587 | state = &sta->ampdu_mlme.tid_state_tx[tid]; | |
588 | ||
589 | spin_lock_bh(&sta->lock); | |
590 | ||
591 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { | |
592 | spin_unlock_bh(&sta->lock); | |
593 | return; | |
594 | } | |
595 | ||
596 | if (mgmt->u.action.u.addba_resp.dialog_token != | |
597 | sta->ampdu_mlme.tid_tx[tid]->dialog_token) { | |
598 | spin_unlock_bh(&sta->lock); | |
599 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
600 | printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid); | |
601 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
602 | return; | |
603 | } | |
604 | ||
605 | del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer); | |
606 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
607 | printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid); | |
608 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
609 | if (le16_to_cpu(mgmt->u.action.u.addba_resp.status) | |
610 | == WLAN_STATUS_SUCCESS) { | |
611 | *state |= HT_ADDBA_RECEIVED_MSK; | |
612 | sta->ampdu_mlme.addba_req_num[tid] = 0; | |
613 | ||
614 | if (*state == HT_AGG_STATE_OPERATIONAL && | |
615 | local->hw.ampdu_queues) | |
616 | ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); | |
617 | ||
618 | if (local->ops->ampdu_action) { | |
619 | (void)local->ops->ampdu_action(hw, | |
620 | IEEE80211_AMPDU_TX_RESUME, | |
621 | &sta->sta, tid, &start_seq_num); | |
622 | } | |
623 | #ifdef CONFIG_MAC80211_HT_DEBUG | |
624 | printk(KERN_DEBUG "Resuming TX aggregation for tid %d\n", tid); | |
625 | #endif /* CONFIG_MAC80211_HT_DEBUG */ | |
626 | spin_unlock_bh(&sta->lock); | |
627 | } else { | |
628 | sta->ampdu_mlme.addba_req_num[tid]++; | |
23e6a7ea JB |
629 | __ieee80211_stop_tx_ba_session(local, sta, tid, |
630 | WLAN_BACK_INITIATOR); | |
b8695a8f | 631 | spin_unlock_bh(&sta->lock); |
b8695a8f JB |
632 | } |
633 | } |