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-2008, Intel Corporation
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.
16 #include <linux/ieee80211.h>
17 #include <net/wireless.h>
18 #include <net/mac80211.h>
19 #include "ieee80211_i.h"
23 void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_supported_band *sband,
24 struct ieee80211_ht_cap *ht_cap_ie,
25 struct ieee80211_sta_ht_cap *ht_cap)
27 u8 ampdu_info, tx_mcs_set_cap;
28 int i, max_tx_streams;
32 memset(ht_cap, 0, sizeof(*ht_cap));
37 ht_cap->ht_supported = true;
39 ht_cap->cap = le16_to_cpu(ht_cap_ie->cap_info) & sband->ht_cap.cap;
40 ht_cap->cap &= ~IEEE80211_HT_CAP_SM_PS;
41 ht_cap->cap |= sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS;
43 ampdu_info = ht_cap_ie->ampdu_params_info;
44 ht_cap->ampdu_factor =
45 ampdu_info & IEEE80211_HT_AMPDU_PARM_FACTOR;
46 ht_cap->ampdu_density =
47 (ampdu_info & IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
49 /* own MCS TX capabilities */
50 tx_mcs_set_cap = sband->ht_cap.mcs.tx_params;
52 /* can we TX with MCS rates? */
53 if (!(tx_mcs_set_cap & IEEE80211_HT_MCS_TX_DEFINED))
56 /* Counting from 0, therefore +1 */
57 if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_RX_DIFF)
59 ((tx_mcs_set_cap & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
60 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
62 max_tx_streams = IEEE80211_HT_MCS_TX_MAX_STREAMS;
65 * 802.11n D5.0 20.3.5 / 20.6 says:
66 * - indices 0 to 7 and 32 are single spatial stream
67 * - 8 to 31 are multiple spatial streams using equal modulation
68 * [8..15 for two streams, 16..23 for three and 24..31 for four]
69 * - remainder are multiple spatial streams using unequal modulation
71 for (i = 0; i < max_tx_streams; i++)
72 ht_cap->mcs.rx_mask[i] =
73 sband->ht_cap.mcs.rx_mask[i] & ht_cap_ie->mcs.rx_mask[i];
75 if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION)
76 for (i = IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE;
77 i < IEEE80211_HT_MCS_MASK_LEN; i++)
78 ht_cap->mcs.rx_mask[i] =
79 sband->ht_cap.mcs.rx_mask[i] &
80 ht_cap_ie->mcs.rx_mask[i];
82 /* handle MCS rate 32 too */
83 if (sband->ht_cap.mcs.rx_mask[32/8] & ht_cap_ie->mcs.rx_mask[32/8] & 1)
84 ht_cap->mcs.rx_mask[32/8] |= 1;
88 * ieee80211_enable_ht should be called only after the operating band
89 * has been determined as ht configuration depends on the hw's
90 * HT abilities for a specific band.
92 u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,
93 struct ieee80211_ht_info *hti,
96 struct ieee80211_local *local = sdata->local;
97 struct ieee80211_supported_band *sband;
98 struct ieee80211_bss_ht_conf ht;
100 bool enable_ht = true, ht_changed;
102 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
104 memset(&ht, 0, sizeof(ht));
106 /* HT is not supported */
107 if (!sband->ht_cap.ht_supported)
110 /* check that channel matches the right operating channel */
111 if (local->hw.conf.channel->center_freq !=
112 ieee80211_channel_to_frequency(hti->control_chan))
116 * XXX: This is totally incorrect when there are multiple virtual
117 * interfaces, needs to be fixed later.
119 ht_changed = local->hw.conf.ht.enabled != enable_ht;
120 local->hw.conf.ht.enabled = enable_ht;
122 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_HT);
127 ht.secondary_channel_offset =
128 hti->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET;
130 !(ap_ht_cap_flags & IEEE80211_HT_CAP_40MHZ_INTOLERANT) &&
131 (sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) &&
132 (hti->ht_param & IEEE80211_HT_PARAM_CHAN_WIDTH_ANY);
133 ht.operation_mode = le16_to_cpu(hti->operation_mode);
135 /* if bss configuration changed store the new one */
136 if (memcmp(&sdata->vif.bss_conf.ht, &ht, sizeof(ht))) {
137 changed |= BSS_CHANGED_HT;
138 sdata->vif.bss_conf.ht = ht;
144 static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata,
145 const u8 *da, u16 tid,
146 u8 dialog_token, u16 start_seq_num,
147 u16 agg_size, u16 timeout)
149 struct ieee80211_local *local = sdata->local;
150 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
152 struct ieee80211_mgmt *mgmt;
155 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
158 printk(KERN_ERR "%s: failed to allocate buffer "
159 "for addba request frame\n", sdata->dev->name);
162 skb_reserve(skb, local->hw.extra_tx_headroom);
163 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
165 memcpy(mgmt->da, da, ETH_ALEN);
166 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
167 if (sdata->vif.type == NL80211_IFTYPE_AP)
168 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
170 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
172 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
173 IEEE80211_STYPE_ACTION);
175 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req));
177 mgmt->u.action.category = WLAN_CATEGORY_BACK;
178 mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ;
180 mgmt->u.action.u.addba_req.dialog_token = dialog_token;
181 capab = (u16)(1 << 1); /* bit 1 aggregation policy */
182 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
183 capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */
185 mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab);
187 mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout);
188 mgmt->u.action.u.addba_req.start_seq_num =
189 cpu_to_le16(start_seq_num << 4);
191 ieee80211_tx_skb(sdata, skb, 0);
194 static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *da, u16 tid,
195 u8 dialog_token, u16 status, u16 policy,
196 u16 buf_size, u16 timeout)
198 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
199 struct ieee80211_local *local = sdata->local;
201 struct ieee80211_mgmt *mgmt;
204 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
207 printk(KERN_DEBUG "%s: failed to allocate buffer "
208 "for addba resp frame\n", sdata->dev->name);
212 skb_reserve(skb, local->hw.extra_tx_headroom);
213 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
215 memcpy(mgmt->da, da, ETH_ALEN);
216 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
217 if (sdata->vif.type == NL80211_IFTYPE_AP)
218 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
220 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
221 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
222 IEEE80211_STYPE_ACTION);
224 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
225 mgmt->u.action.category = WLAN_CATEGORY_BACK;
226 mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
227 mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
229 capab = (u16)(policy << 1); /* bit 1 aggregation policy */
230 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
231 capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
233 mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
234 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
235 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
237 ieee80211_tx_skb(sdata, skb, 0);
240 static void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
241 const u8 *da, u16 tid,
242 u16 initiator, u16 reason_code)
244 struct ieee80211_local *local = sdata->local;
245 struct ieee80211_if_sta *ifsta = &sdata->u.sta;
247 struct ieee80211_mgmt *mgmt;
250 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
253 printk(KERN_ERR "%s: failed to allocate buffer "
254 "for delba frame\n", sdata->dev->name);
258 skb_reserve(skb, local->hw.extra_tx_headroom);
259 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
261 memcpy(mgmt->da, da, ETH_ALEN);
262 memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN);
263 if (sdata->vif.type == NL80211_IFTYPE_AP)
264 memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN);
266 memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN);
267 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
268 IEEE80211_STYPE_ACTION);
270 skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
272 mgmt->u.action.category = WLAN_CATEGORY_BACK;
273 mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
274 params = (u16)(initiator << 11); /* bit 11 initiator */
275 params |= (u16)(tid << 12); /* bit 15:12 TID number */
277 mgmt->u.action.u.delba.params = cpu_to_le16(params);
278 mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
280 ieee80211_tx_skb(sdata, skb, 0);
283 void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn)
285 struct ieee80211_local *local = sdata->local;
287 struct ieee80211_bar *bar;
290 skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom);
292 printk(KERN_ERR "%s: failed to allocate buffer for "
293 "bar frame\n", sdata->dev->name);
296 skb_reserve(skb, local->hw.extra_tx_headroom);
297 bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar));
298 memset(bar, 0, sizeof(*bar));
299 bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
300 IEEE80211_STYPE_BACK_REQ);
301 memcpy(bar->ra, ra, ETH_ALEN);
302 memcpy(bar->ta, sdata->dev->dev_addr, ETH_ALEN);
303 bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL;
304 bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA;
305 bar_control |= (u16)(tid << 12);
306 bar->control = cpu_to_le16(bar_control);
307 bar->start_seq_num = cpu_to_le16(ssn);
309 ieee80211_tx_skb(sdata, skb, 0);
312 void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid,
313 u16 initiator, u16 reason)
315 struct ieee80211_local *local = sdata->local;
316 struct ieee80211_hw *hw = &local->hw;
317 struct sta_info *sta;
322 sta = sta_info_get(local, ra);
328 /* check if TID is in operational state */
329 spin_lock_bh(&sta->lock);
330 if (sta->ampdu_mlme.tid_state_rx[tid]
331 != HT_AGG_STATE_OPERATIONAL) {
332 spin_unlock_bh(&sta->lock);
336 sta->ampdu_mlme.tid_state_rx[tid] =
337 HT_AGG_STATE_REQ_STOP_BA_MSK |
338 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
339 spin_unlock_bh(&sta->lock);
341 /* stop HW Rx aggregation. ampdu_action existence
342 * already verified in session init so we add the BUG_ON */
343 BUG_ON(!local->ops->ampdu_action);
345 #ifdef CONFIG_MAC80211_HT_DEBUG
346 printk(KERN_DEBUG "Rx BA session stop requested for %pM tid %u\n",
348 #endif /* CONFIG_MAC80211_HT_DEBUG */
350 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP,
351 &sta->sta, tid, NULL);
353 printk(KERN_DEBUG "HW problem - can not stop rx "
354 "aggregation for tid %d\n", tid);
356 /* shutdown timer has not expired */
357 if (initiator != WLAN_BACK_TIMER)
358 del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
360 /* check if this is a self generated aggregation halt */
361 if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER)
362 ieee80211_send_delba(sdata, ra, tid, 0, reason);
364 /* free the reordering buffer */
365 for (i = 0; i < sta->ampdu_mlme.tid_rx[tid]->buf_size; i++) {
366 if (sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]) {
367 /* release the reordered frames */
368 dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]);
369 sta->ampdu_mlme.tid_rx[tid]->stored_mpdu_num--;
370 sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i] = NULL;
374 kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf);
375 kfree(sta->ampdu_mlme.tid_rx[tid]);
376 sta->ampdu_mlme.tid_rx[tid] = NULL;
377 sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_IDLE;
384 * After sending add Block Ack request we activated a timer until
385 * add Block Ack response will arrive from the recipient.
386 * If this timer expires sta_addba_resp_timer_expired will be executed.
388 static void sta_addba_resp_timer_expired(unsigned long data)
390 /* not an elegant detour, but there is no choice as the timer passes
391 * only one argument, and both sta_info and TID are needed, so init
392 * flow in sta_info_create gives the TID as data, while the timer_to_id
393 * array gives the sta through container_of */
394 u16 tid = *(u8 *)data;
395 struct sta_info *temp_sta = container_of((void *)data,
396 struct sta_info, timer_to_tid[tid]);
398 struct ieee80211_local *local = temp_sta->local;
399 struct ieee80211_hw *hw = &local->hw;
400 struct sta_info *sta;
405 sta = sta_info_get(local, temp_sta->sta.addr);
411 state = &sta->ampdu_mlme.tid_state_tx[tid];
412 /* check if the TID waits for addBA response */
413 spin_lock_bh(&sta->lock);
414 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
415 spin_unlock_bh(&sta->lock);
416 *state = HT_AGG_STATE_IDLE;
417 #ifdef CONFIG_MAC80211_HT_DEBUG
418 printk(KERN_DEBUG "timer expired on tid %d but we are not "
419 "expecting addBA response there", tid);
421 goto timer_expired_exit;
424 #ifdef CONFIG_MAC80211_HT_DEBUG
425 printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid);
428 /* go through the state check in stop_BA_session */
429 *state = HT_AGG_STATE_OPERATIONAL;
430 spin_unlock_bh(&sta->lock);
431 ieee80211_stop_tx_ba_session(hw, temp_sta->sta.addr, tid,
432 WLAN_BACK_INITIATOR);
438 void ieee80211_sta_tear_down_BA_sessions(struct ieee80211_sub_if_data *sdata, u8 *addr)
440 struct ieee80211_local *local = sdata->local;
443 for (i = 0; i < STA_TID_NUM; i++) {
444 ieee80211_stop_tx_ba_session(&local->hw, addr, i,
445 WLAN_BACK_INITIATOR);
446 ieee80211_sta_stop_rx_ba_session(sdata, addr, i,
448 WLAN_REASON_QSTA_LEAVE_QBSS);
452 int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid)
454 struct ieee80211_local *local = hw_to_local(hw);
455 struct sta_info *sta;
456 struct ieee80211_sub_if_data *sdata;
461 if ((tid >= STA_TID_NUM) || !(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
464 #ifdef CONFIG_MAC80211_HT_DEBUG
465 printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n",
467 #endif /* CONFIG_MAC80211_HT_DEBUG */
471 sta = sta_info_get(local, ra);
473 #ifdef CONFIG_MAC80211_HT_DEBUG
474 printk(KERN_DEBUG "Could not find the station\n");
480 spin_lock_bh(&sta->lock);
482 /* we have tried too many times, receiver does not want A-MPDU */
483 if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) {
488 state = &sta->ampdu_mlme.tid_state_tx[tid];
489 /* check if the TID is not in aggregation flow already */
490 if (*state != HT_AGG_STATE_IDLE) {
491 #ifdef CONFIG_MAC80211_HT_DEBUG
492 printk(KERN_DEBUG "BA request denied - session is not "
493 "idle on tid %u\n", tid);
494 #endif /* CONFIG_MAC80211_HT_DEBUG */
499 /* prepare A-MPDU MLME for Tx aggregation */
500 sta->ampdu_mlme.tid_tx[tid] =
501 kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC);
502 if (!sta->ampdu_mlme.tid_tx[tid]) {
503 #ifdef CONFIG_MAC80211_HT_DEBUG
505 printk(KERN_ERR "allocate tx mlme to tid %d failed\n",
512 sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function =
513 sta_addba_resp_timer_expired;
514 sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data =
515 (unsigned long)&sta->timer_to_tid[tid];
516 init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
518 if (hw->ampdu_queues) {
519 /* create a new queue for this aggregation */
520 ret = ieee80211_ht_agg_queue_add(local, sta, tid);
522 /* case no queue is available to aggregation
523 * don't switch to aggregation */
525 #ifdef CONFIG_MAC80211_HT_DEBUG
526 printk(KERN_DEBUG "BA request denied - "
527 "queue unavailable for tid %d\n", tid);
528 #endif /* CONFIG_MAC80211_HT_DEBUG */
529 goto err_unlock_queue;
534 /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the
535 * call back right away, it must see that the flow has begun */
536 *state |= HT_ADDBA_REQUESTED_MSK;
538 /* This is slightly racy because the queue isn't stopped */
539 start_seq_num = sta->tid_seq[tid];
541 if (local->ops->ampdu_action)
542 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START,
543 &sta->sta, tid, &start_seq_num);
546 /* No need to requeue the packets in the agg queue, since we
547 * held the tx lock: no packet could be enqueued to the newly
549 if (hw->ampdu_queues)
550 ieee80211_ht_agg_queue_remove(local, sta, tid, 0);
551 #ifdef CONFIG_MAC80211_HT_DEBUG
552 printk(KERN_DEBUG "BA request denied - HW unavailable for"
554 #endif /* CONFIG_MAC80211_HT_DEBUG */
555 *state = HT_AGG_STATE_IDLE;
556 goto err_unlock_queue;
559 /* Will put all the packets in the new SW queue */
560 if (hw->ampdu_queues)
561 ieee80211_requeue(local, ieee802_1d_to_ac[tid]);
562 spin_unlock_bh(&sta->lock);
564 /* send an addBA request */
565 sta->ampdu_mlme.dialog_token_allocator++;
566 sta->ampdu_mlme.tid_tx[tid]->dialog_token =
567 sta->ampdu_mlme.dialog_token_allocator;
568 sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num;
571 ieee80211_send_addba_request(sta->sdata, ra, tid,
572 sta->ampdu_mlme.tid_tx[tid]->dialog_token,
573 sta->ampdu_mlme.tid_tx[tid]->ssn,
575 /* activate the timer for the recipient's addBA response */
576 sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires =
577 jiffies + ADDBA_RESP_INTERVAL;
578 add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
579 #ifdef CONFIG_MAC80211_HT_DEBUG
580 printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid);
585 kfree(sta->ampdu_mlme.tid_tx[tid]);
586 sta->ampdu_mlme.tid_tx[tid] = NULL;
589 spin_unlock_bh(&sta->lock);
594 EXPORT_SYMBOL(ieee80211_start_tx_ba_session);
596 int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw,
598 enum ieee80211_back_parties initiator)
600 struct ieee80211_local *local = hw_to_local(hw);
601 struct sta_info *sta;
605 if (tid >= STA_TID_NUM)
609 sta = sta_info_get(local, ra);
615 /* check if the TID is in aggregation */
616 state = &sta->ampdu_mlme.tid_state_tx[tid];
617 spin_lock_bh(&sta->lock);
619 if (*state != HT_AGG_STATE_OPERATIONAL) {
624 #ifdef CONFIG_MAC80211_HT_DEBUG
625 printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n",
627 #endif /* CONFIG_MAC80211_HT_DEBUG */
629 if (hw->ampdu_queues)
630 ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]);
632 *state = HT_AGG_STATE_REQ_STOP_BA_MSK |
633 (initiator << HT_AGG_STATE_INITIATOR_SHIFT);
635 if (local->ops->ampdu_action)
636 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP,
637 &sta->sta, tid, NULL);
639 /* case HW denied going back to legacy */
641 WARN_ON(ret != -EBUSY);
642 *state = HT_AGG_STATE_OPERATIONAL;
643 if (hw->ampdu_queues)
644 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
649 spin_unlock_bh(&sta->lock);
653 EXPORT_SYMBOL(ieee80211_stop_tx_ba_session);
655 void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid)
657 struct ieee80211_local *local = hw_to_local(hw);
658 struct sta_info *sta;
661 if (tid >= STA_TID_NUM) {
662 #ifdef CONFIG_MAC80211_HT_DEBUG
663 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
670 sta = sta_info_get(local, ra);
673 #ifdef CONFIG_MAC80211_HT_DEBUG
674 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
679 state = &sta->ampdu_mlme.tid_state_tx[tid];
680 spin_lock_bh(&sta->lock);
682 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
683 #ifdef CONFIG_MAC80211_HT_DEBUG
684 printk(KERN_DEBUG "addBA was not requested yet, state is %d\n",
687 spin_unlock_bh(&sta->lock);
692 WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK);
694 *state |= HT_ADDBA_DRV_READY_MSK;
696 if (*state == HT_AGG_STATE_OPERATIONAL) {
697 #ifdef CONFIG_MAC80211_HT_DEBUG
698 printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid);
700 if (hw->ampdu_queues)
701 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
703 spin_unlock_bh(&sta->lock);
706 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb);
708 void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid)
710 struct ieee80211_local *local = hw_to_local(hw);
711 struct sta_info *sta;
715 if (tid >= STA_TID_NUM) {
716 #ifdef CONFIG_MAC80211_HT_DEBUG
717 printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n",
723 #ifdef CONFIG_MAC80211_HT_DEBUG
724 printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n",
726 #endif /* CONFIG_MAC80211_HT_DEBUG */
729 sta = sta_info_get(local, ra);
731 #ifdef CONFIG_MAC80211_HT_DEBUG
732 printk(KERN_DEBUG "Could not find station: %pM\n", ra);
737 state = &sta->ampdu_mlme.tid_state_tx[tid];
739 /* NOTE: no need to use sta->lock in this state check, as
740 * ieee80211_stop_tx_ba_session will let only one stop call to
741 * pass through per sta/tid
743 if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) {
744 #ifdef CONFIG_MAC80211_HT_DEBUG
745 printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n");
751 if (*state & HT_AGG_STATE_INITIATOR_MSK)
752 ieee80211_send_delba(sta->sdata, ra, tid,
753 WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE);
755 if (hw->ampdu_queues) {
756 agg_queue = sta->tid_to_tx_q[tid];
757 ieee80211_ht_agg_queue_remove(local, sta, tid, 1);
759 /* We just requeued the all the frames that were in the
760 * removed queue, and since we might miss a softirq we do
761 * netif_schedule_queue. ieee80211_wake_queue is not used
762 * here as this queue is not necessarily stopped
764 netif_schedule_queue(netdev_get_tx_queue(local->mdev,
767 spin_lock_bh(&sta->lock);
768 *state = HT_AGG_STATE_IDLE;
769 sta->ampdu_mlme.addba_req_num[tid] = 0;
770 kfree(sta->ampdu_mlme.tid_tx[tid]);
771 sta->ampdu_mlme.tid_tx[tid] = NULL;
772 spin_unlock_bh(&sta->lock);
776 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb);
778 void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
779 const u8 *ra, u16 tid)
781 struct ieee80211_local *local = hw_to_local(hw);
782 struct ieee80211_ra_tid *ra_tid;
783 struct sk_buff *skb = dev_alloc_skb(0);
785 if (unlikely(!skb)) {
786 #ifdef CONFIG_MAC80211_HT_DEBUG
788 printk(KERN_WARNING "%s: Not enough memory, "
789 "dropping start BA session", skb->dev->name);
793 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
794 memcpy(&ra_tid->ra, ra, ETH_ALEN);
797 skb->pkt_type = IEEE80211_ADDBA_MSG;
798 skb_queue_tail(&local->skb_queue, skb);
799 tasklet_schedule(&local->tasklet);
801 EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe);
803 void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw,
804 const u8 *ra, u16 tid)
806 struct ieee80211_local *local = hw_to_local(hw);
807 struct ieee80211_ra_tid *ra_tid;
808 struct sk_buff *skb = dev_alloc_skb(0);
810 if (unlikely(!skb)) {
811 #ifdef CONFIG_MAC80211_HT_DEBUG
813 printk(KERN_WARNING "%s: Not enough memory, "
814 "dropping stop BA session", skb->dev->name);
818 ra_tid = (struct ieee80211_ra_tid *) &skb->cb;
819 memcpy(&ra_tid->ra, ra, ETH_ALEN);
822 skb->pkt_type = IEEE80211_DELBA_MSG;
823 skb_queue_tail(&local->skb_queue, skb);
824 tasklet_schedule(&local->tasklet);
826 EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe);
829 * After accepting the AddBA Request we activated a timer,
830 * resetting it after each frame that arrives from the originator.
831 * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed.
833 static void sta_rx_agg_session_timer_expired(unsigned long data)
835 /* not an elegant detour, but there is no choice as the timer passes
836 * only one argument, and various sta_info are needed here, so init
837 * flow in sta_info_create gives the TID as data, while the timer_to_id
838 * array gives the sta through container_of */
839 u8 *ptid = (u8 *)data;
840 u8 *timer_to_id = ptid - *ptid;
841 struct sta_info *sta = container_of(timer_to_id, struct sta_info,
844 #ifdef CONFIG_MAC80211_HT_DEBUG
845 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
847 ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->sta.addr,
848 (u16)*ptid, WLAN_BACK_TIMER,
849 WLAN_REASON_QSTA_TIMEOUT);
852 void ieee80211_process_addba_request(struct ieee80211_local *local,
853 struct sta_info *sta,
854 struct ieee80211_mgmt *mgmt,
857 struct ieee80211_hw *hw = &local->hw;
858 struct ieee80211_conf *conf = &hw->conf;
859 struct tid_ampdu_rx *tid_agg_rx;
860 u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
862 int ret = -EOPNOTSUPP;
864 /* extract session parameters from addba request frame */
865 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
866 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
868 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
870 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
871 ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
872 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
873 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
875 status = WLAN_STATUS_REQUEST_DECLINED;
877 /* sanity check for incoming parameters:
878 * check if configuration can support the BA policy
879 * and if buffer size does not exceeds max value */
880 /* XXX: check own ht delayed BA capability?? */
881 if (((ba_policy != 1)
882 && (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA)))
883 || (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
884 status = WLAN_STATUS_INVALID_QOS_PARAM;
885 #ifdef CONFIG_MAC80211_HT_DEBUG
887 printk(KERN_DEBUG "AddBA Req with bad params from "
888 "%pM on tid %u. policy %d, buffer size %d\n",
889 mgmt->sa, tid, ba_policy,
891 #endif /* CONFIG_MAC80211_HT_DEBUG */
894 /* determine default buffer size */
896 struct ieee80211_supported_band *sband;
898 sband = local->hw.wiphy->bands[conf->channel->band];
899 buf_size = IEEE80211_MIN_AMPDU_BUF;
900 buf_size = buf_size << sband->ht_cap.ampdu_factor;
904 /* examine state machine */
905 spin_lock_bh(&sta->lock);
907 if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_IDLE) {
908 #ifdef CONFIG_MAC80211_HT_DEBUG
910 printk(KERN_DEBUG "unexpected AddBA Req from "
913 #endif /* CONFIG_MAC80211_HT_DEBUG */
917 /* prepare A-MPDU MLME for Rx aggregation */
918 sta->ampdu_mlme.tid_rx[tid] =
919 kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC);
920 if (!sta->ampdu_mlme.tid_rx[tid]) {
921 #ifdef CONFIG_MAC80211_HT_DEBUG
923 printk(KERN_ERR "allocate rx mlme to tid %d failed\n",
929 sta->ampdu_mlme.tid_rx[tid]->session_timer.function =
930 sta_rx_agg_session_timer_expired;
931 sta->ampdu_mlme.tid_rx[tid]->session_timer.data =
932 (unsigned long)&sta->timer_to_tid[tid];
933 init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
935 tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
937 /* prepare reordering buffer */
938 tid_agg_rx->reorder_buf =
939 kmalloc(buf_size * sizeof(struct sk_buff *), GFP_ATOMIC);
940 if (!tid_agg_rx->reorder_buf) {
941 #ifdef CONFIG_MAC80211_HT_DEBUG
943 printk(KERN_ERR "can not allocate reordering buffer "
946 kfree(sta->ampdu_mlme.tid_rx[tid]);
949 memset(tid_agg_rx->reorder_buf, 0,
950 buf_size * sizeof(struct sk_buff *));
952 if (local->ops->ampdu_action)
953 ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START,
954 &sta->sta, tid, &start_seq_num);
955 #ifdef CONFIG_MAC80211_HT_DEBUG
956 printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
957 #endif /* CONFIG_MAC80211_HT_DEBUG */
960 kfree(tid_agg_rx->reorder_buf);
962 sta->ampdu_mlme.tid_rx[tid] = NULL;
966 /* change state and send addba resp */
967 sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_OPERATIONAL;
968 tid_agg_rx->dialog_token = dialog_token;
969 tid_agg_rx->ssn = start_seq_num;
970 tid_agg_rx->head_seq_num = start_seq_num;
971 tid_agg_rx->buf_size = buf_size;
972 tid_agg_rx->timeout = timeout;
973 tid_agg_rx->stored_mpdu_num = 0;
974 status = WLAN_STATUS_SUCCESS;
976 spin_unlock_bh(&sta->lock);
979 ieee80211_send_addba_resp(sta->sdata, sta->sta.addr, tid,
980 dialog_token, status, 1, buf_size, timeout);
983 void ieee80211_process_addba_resp(struct ieee80211_local *local,
984 struct sta_info *sta,
985 struct ieee80211_mgmt *mgmt,
988 struct ieee80211_hw *hw = &local->hw;
990 u16 tid, start_seq_num;
993 capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab);
994 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
996 state = &sta->ampdu_mlme.tid_state_tx[tid];
998 spin_lock_bh(&sta->lock);
1000 if (!(*state & HT_ADDBA_REQUESTED_MSK)) {
1001 spin_unlock_bh(&sta->lock);
1005 if (mgmt->u.action.u.addba_resp.dialog_token !=
1006 sta->ampdu_mlme.tid_tx[tid]->dialog_token) {
1007 spin_unlock_bh(&sta->lock);
1008 #ifdef CONFIG_MAC80211_HT_DEBUG
1009 printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid);
1010 #endif /* CONFIG_MAC80211_HT_DEBUG */
1014 del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer);
1015 #ifdef CONFIG_MAC80211_HT_DEBUG
1016 printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid);
1017 #endif /* CONFIG_MAC80211_HT_DEBUG */
1018 if (le16_to_cpu(mgmt->u.action.u.addba_resp.status)
1019 == WLAN_STATUS_SUCCESS) {
1020 *state |= HT_ADDBA_RECEIVED_MSK;
1021 sta->ampdu_mlme.addba_req_num[tid] = 0;
1023 if (*state == HT_AGG_STATE_OPERATIONAL &&
1024 local->hw.ampdu_queues)
1025 ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]);
1027 if (local->ops->ampdu_action) {
1028 (void)local->ops->ampdu_action(hw,
1029 IEEE80211_AMPDU_TX_RESUME,
1030 &sta->sta, tid, &start_seq_num);
1032 #ifdef CONFIG_MAC80211_HT_DEBUG
1033 printk(KERN_DEBUG "Resuming TX aggregation for tid %d\n", tid);
1034 #endif /* CONFIG_MAC80211_HT_DEBUG */
1035 spin_unlock_bh(&sta->lock);
1037 sta->ampdu_mlme.addba_req_num[tid]++;
1038 /* this will allow the state check in stop_BA_session */
1039 *state = HT_AGG_STATE_OPERATIONAL;
1040 spin_unlock_bh(&sta->lock);
1041 ieee80211_stop_tx_ba_session(hw, sta->sta.addr, tid,
1042 WLAN_BACK_INITIATOR);
1046 void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
1047 struct sta_info *sta,
1048 struct ieee80211_mgmt *mgmt, size_t len)
1050 struct ieee80211_local *local = sdata->local;
1054 params = le16_to_cpu(mgmt->u.action.u.delba.params);
1055 tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
1056 initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
1058 #ifdef CONFIG_MAC80211_HT_DEBUG
1059 if (net_ratelimit())
1060 printk(KERN_DEBUG "delba from %pM (%s) tid %d reason code %d\n",
1061 mgmt->sa, initiator ? "initiator" : "recipient", tid,
1062 mgmt->u.action.u.delba.reason_code);
1063 #endif /* CONFIG_MAC80211_HT_DEBUG */
1065 if (initiator == WLAN_BACK_INITIATOR)
1066 ieee80211_sta_stop_rx_ba_session(sdata, sta->sta.addr, tid,
1067 WLAN_BACK_INITIATOR, 0);
1068 else { /* WLAN_BACK_RECIPIENT */
1069 spin_lock_bh(&sta->lock);
1070 sta->ampdu_mlme.tid_state_tx[tid] =
1071 HT_AGG_STATE_OPERATIONAL;
1072 spin_unlock_bh(&sta->lock);
1073 ieee80211_stop_tx_ba_session(&local->hw, sta->sta.addr, tid,
1074 WLAN_BACK_RECIPIENT);