blob: 1771dd9bd137f44c7d32d8c5d5d8c392e2dd8e41 [file] [log] [blame]
Johannes Bergb8695a82009-02-10 21:25:46 +01001/*
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-2008, 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"
Johannes Berg24487982009-04-23 18:52:52 +020019#include "driver-ops.h"
Johannes Bergb8695a82009-02-10 21:25:46 +010020
Johannes Berg2aab4c22010-04-19 11:00:24 +020021static void ___ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
22 u16 initiator, u16 reason,
23 bool from_timer)
Johannes Bergb8695a82009-02-10 21:25:46 +010024{
Johannes Bergd75636e2009-02-10 21:25:53 +010025 struct ieee80211_local *local = sta->local;
Johannes Berg098a6072010-04-06 11:18:47 +020026 struct tid_ampdu_rx *tid_rx;
Johannes Bergd75636e2009-02-10 21:25:53 +010027 int i;
Johannes Bergb8695a82009-02-10 21:25:46 +010028
Johannes Bergb8695a82009-02-10 21:25:46 +010029 spin_lock_bh(&sta->lock);
Johannes Berg098a6072010-04-06 11:18:47 +020030
31 /* check if TID is in operational state */
32 if (!sta->ampdu_mlme.tid_active_rx[tid]) {
Johannes Bergb8695a82009-02-10 21:25:46 +010033 spin_unlock_bh(&sta->lock);
Johannes Bergb8695a82009-02-10 21:25:46 +010034 return;
35 }
Johannes Bergd75636e2009-02-10 21:25:53 +010036
Johannes Berg098a6072010-04-06 11:18:47 +020037 sta->ampdu_mlme.tid_active_rx[tid] = false;
38
39 tid_rx = sta->ampdu_mlme.tid_rx[tid];
Johannes Bergb8695a82009-02-10 21:25:46 +010040
Johannes Bergb8695a82009-02-10 21:25:46 +010041#ifdef CONFIG_MAC80211_HT_DEBUG
42 printk(KERN_DEBUG "Rx BA session stop requested for %pM tid %u\n",
Johannes Bergd75636e2009-02-10 21:25:53 +010043 sta->sta.addr, tid);
Johannes Bergb8695a82009-02-10 21:25:46 +010044#endif /* CONFIG_MAC80211_HT_DEBUG */
45
Johannes Berg12375ef2009-11-25 20:30:31 +010046 if (drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_STOP,
Johannes Berg24487982009-04-23 18:52:52 +020047 &sta->sta, tid, NULL))
Johannes Bergb8695a82009-02-10 21:25:46 +010048 printk(KERN_DEBUG "HW problem - can not stop rx "
49 "aggregation for tid %d\n", tid);
50
Johannes Bergb8695a82009-02-10 21:25:46 +010051 /* check if this is a self generated aggregation halt */
Johannes Berg098a6072010-04-06 11:18:47 +020052 if (initiator == WLAN_BACK_RECIPIENT)
Johannes Bergd75636e2009-02-10 21:25:53 +010053 ieee80211_send_delba(sta->sdata, sta->sta.addr,
54 tid, 0, reason);
Johannes Bergb8695a82009-02-10 21:25:46 +010055
56 /* free the reordering buffer */
Johannes Berg098a6072010-04-06 11:18:47 +020057 for (i = 0; i < tid_rx->buf_size; i++) {
58 if (tid_rx->reorder_buf[i]) {
Johannes Bergb8695a82009-02-10 21:25:46 +010059 /* release the reordered frames */
Johannes Berg098a6072010-04-06 11:18:47 +020060 dev_kfree_skb(tid_rx->reorder_buf[i]);
61 tid_rx->stored_mpdu_num--;
62 tid_rx->reorder_buf[i] = NULL;
Johannes Bergb8695a82009-02-10 21:25:46 +010063 }
64 }
Johannes Berg55687e32009-02-10 21:25:51 +010065
Johannes Bergb8695a82009-02-10 21:25:46 +010066 /* free resources */
Johannes Berg098a6072010-04-06 11:18:47 +020067 kfree(tid_rx->reorder_buf);
68 kfree(tid_rx->reorder_time);
69 sta->ampdu_mlme.tid_rx[tid] = NULL;
Johannes Berg55687e32009-02-10 21:25:51 +010070
Johannes Berg55687e32009-02-10 21:25:51 +010071 spin_unlock_bh(&sta->lock);
Johannes Berg098a6072010-04-06 11:18:47 +020072
Johannes Berg2aab4c22010-04-19 11:00:24 +020073 if (!from_timer)
74 del_timer_sync(&tid_rx->session_timer);
Johannes Berg098a6072010-04-06 11:18:47 +020075 kfree(tid_rx);
Johannes Bergd75636e2009-02-10 21:25:53 +010076}
77
Johannes Berg2aab4c22010-04-19 11:00:24 +020078void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
79 u16 initiator, u16 reason)
80{
81 ___ieee80211_stop_rx_ba_session(sta, tid, initiator, reason, false);
82}
83
Johannes Bergb8695a82009-02-10 21:25:46 +010084/*
85 * After accepting the AddBA Request we activated a timer,
86 * resetting it after each frame that arrives from the originator.
Johannes Bergb8695a82009-02-10 21:25:46 +010087 */
88static void sta_rx_agg_session_timer_expired(unsigned long data)
89{
90 /* not an elegant detour, but there is no choice as the timer passes
91 * only one argument, and various sta_info are needed here, so init
92 * flow in sta_info_create gives the TID as data, while the timer_to_id
93 * array gives the sta through container_of */
94 u8 *ptid = (u8 *)data;
95 u8 *timer_to_id = ptid - *ptid;
96 struct sta_info *sta = container_of(timer_to_id, struct sta_info,
97 timer_to_tid[0]);
98
99#ifdef CONFIG_MAC80211_HT_DEBUG
100 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
101#endif
Johannes Berg2aab4c22010-04-19 11:00:24 +0200102 ___ieee80211_stop_rx_ba_session(sta, *ptid, WLAN_BACK_RECIPIENT,
103 WLAN_REASON_QSTA_TIMEOUT, true);
Johannes Bergb8695a82009-02-10 21:25:46 +0100104}
105
106static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *da, u16 tid,
107 u8 dialog_token, u16 status, u16 policy,
108 u16 buf_size, u16 timeout)
109{
Johannes Bergb8695a82009-02-10 21:25:46 +0100110 struct ieee80211_local *local = sdata->local;
111 struct sk_buff *skb;
112 struct ieee80211_mgmt *mgmt;
113 u16 capab;
114
115 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
116
117 if (!skb) {
118 printk(KERN_DEBUG "%s: failed to allocate buffer "
Johannes Berg47846c92009-11-25 17:46:19 +0100119 "for addba resp frame\n", sdata->name);
Johannes Bergb8695a82009-02-10 21:25:46 +0100120 return;
121 }
122
123 skb_reserve(skb, local->hw.extra_tx_headroom);
124 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
125 memset(mgmt, 0, 24);
126 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100127 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg8abd3f92009-02-10 21:25:47 +0100128 if (sdata->vif.type == NL80211_IFTYPE_AP ||
129 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
Johannes Berg47846c92009-11-25 17:46:19 +0100130 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100131 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
132 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
133
Johannes Bergb8695a82009-02-10 21:25:46 +0100134 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
135 IEEE80211_STYPE_ACTION);
136
137 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
138 mgmt->u.action.category = WLAN_CATEGORY_BACK;
139 mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
140 mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
141
142 capab = (u16)(policy << 1); /* bit 1 aggregation policy */
143 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
144 capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
145
146 mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
147 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
148 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
149
Johannes Berg62ae67b2009-11-18 18:42:05 +0100150 ieee80211_tx_skb(sdata, skb);
Johannes Bergb8695a82009-02-10 21:25:46 +0100151}
152
153void ieee80211_process_addba_request(struct ieee80211_local *local,
154 struct sta_info *sta,
155 struct ieee80211_mgmt *mgmt,
156 size_t len)
157{
158 struct ieee80211_hw *hw = &local->hw;
159 struct ieee80211_conf *conf = &hw->conf;
160 struct tid_ampdu_rx *tid_agg_rx;
161 u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
162 u8 dialog_token;
163 int ret = -EOPNOTSUPP;
164
165 /* extract session parameters from addba request frame */
166 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
167 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
168 start_seq_num =
169 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
170
171 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
172 ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
173 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
174 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
175
176 status = WLAN_STATUS_REQUEST_DECLINED;
177
Johannes Berg618f3562010-04-06 11:18:46 +0200178 if (test_sta_flags(sta, WLAN_STA_BLOCK_BA)) {
Sujith722f0692009-03-17 08:50:06 +0530179#ifdef CONFIG_MAC80211_HT_DEBUG
180 printk(KERN_DEBUG "Suspend in progress. "
181 "Denying ADDBA request\n");
182#endif
183 goto end_no_lock;
184 }
185
Johannes Bergb8695a82009-02-10 21:25:46 +0100186 /* sanity check for incoming parameters:
187 * check if configuration can support the BA policy
188 * and if buffer size does not exceeds max value */
189 /* XXX: check own ht delayed BA capability?? */
Joe Perchesf64f9e72009-11-29 16:55:45 -0800190 if (((ba_policy != 1) &&
191 (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA))) ||
192 (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
Johannes Bergb8695a82009-02-10 21:25:46 +0100193 status = WLAN_STATUS_INVALID_QOS_PARAM;
194#ifdef CONFIG_MAC80211_HT_DEBUG
195 if (net_ratelimit())
196 printk(KERN_DEBUG "AddBA Req with bad params from "
197 "%pM on tid %u. policy %d, buffer size %d\n",
198 mgmt->sa, tid, ba_policy,
199 buf_size);
200#endif /* CONFIG_MAC80211_HT_DEBUG */
201 goto end_no_lock;
202 }
203 /* determine default buffer size */
204 if (buf_size == 0) {
205 struct ieee80211_supported_band *sband;
206
207 sband = local->hw.wiphy->bands[conf->channel->band];
208 buf_size = IEEE80211_MIN_AMPDU_BUF;
209 buf_size = buf_size << sband->ht_cap.ampdu_factor;
210 }
211
212
213 /* examine state machine */
214 spin_lock_bh(&sta->lock);
215
Johannes Berg098a6072010-04-06 11:18:47 +0200216 if (sta->ampdu_mlme.tid_active_rx[tid]) {
Johannes Bergb8695a82009-02-10 21:25:46 +0100217#ifdef CONFIG_MAC80211_HT_DEBUG
218 if (net_ratelimit())
219 printk(KERN_DEBUG "unexpected AddBA Req from "
220 "%pM on tid %u\n",
221 mgmt->sa, tid);
222#endif /* CONFIG_MAC80211_HT_DEBUG */
223 goto end;
224 }
225
226 /* prepare A-MPDU MLME for Rx aggregation */
227 sta->ampdu_mlme.tid_rx[tid] =
228 kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC);
229 if (!sta->ampdu_mlme.tid_rx[tid]) {
230#ifdef CONFIG_MAC80211_HT_DEBUG
231 if (net_ratelimit())
232 printk(KERN_ERR "allocate rx mlme to tid %d failed\n",
233 tid);
234#endif
235 goto end;
236 }
237 /* rx timer */
238 sta->ampdu_mlme.tid_rx[tid]->session_timer.function =
239 sta_rx_agg_session_timer_expired;
240 sta->ampdu_mlme.tid_rx[tid]->session_timer.data =
241 (unsigned long)&sta->timer_to_tid[tid];
242 init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
243
244 tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
245
246 /* prepare reordering buffer */
247 tid_agg_rx->reorder_buf =
248 kcalloc(buf_size, sizeof(struct sk_buff *), GFP_ATOMIC);
Jouni Malinen4d050f12009-05-05 20:35:14 +0300249 tid_agg_rx->reorder_time =
250 kcalloc(buf_size, sizeof(unsigned long), GFP_ATOMIC);
251 if (!tid_agg_rx->reorder_buf || !tid_agg_rx->reorder_time) {
Johannes Bergb8695a82009-02-10 21:25:46 +0100252#ifdef CONFIG_MAC80211_HT_DEBUG
253 if (net_ratelimit())
254 printk(KERN_ERR "can not allocate reordering buffer "
255 "to tid %d\n", tid);
256#endif
Jouni Malinen4d050f12009-05-05 20:35:14 +0300257 kfree(tid_agg_rx->reorder_buf);
258 kfree(tid_agg_rx->reorder_time);
Johannes Bergb8695a82009-02-10 21:25:46 +0100259 kfree(sta->ampdu_mlme.tid_rx[tid]);
Jouni Malinen4d050f12009-05-05 20:35:14 +0300260 sta->ampdu_mlme.tid_rx[tid] = NULL;
Johannes Bergb8695a82009-02-10 21:25:46 +0100261 goto end;
262 }
263
Johannes Berg12375ef2009-11-25 20:30:31 +0100264 ret = drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_START,
Johannes Berg24487982009-04-23 18:52:52 +0200265 &sta->sta, tid, &start_seq_num);
Johannes Bergb8695a82009-02-10 21:25:46 +0100266#ifdef CONFIG_MAC80211_HT_DEBUG
267 printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
268#endif /* CONFIG_MAC80211_HT_DEBUG */
269
270 if (ret) {
271 kfree(tid_agg_rx->reorder_buf);
272 kfree(tid_agg_rx);
273 sta->ampdu_mlme.tid_rx[tid] = NULL;
274 goto end;
275 }
276
277 /* change state and send addba resp */
Johannes Berg098a6072010-04-06 11:18:47 +0200278 sta->ampdu_mlme.tid_active_rx[tid] = true;
Johannes Bergb8695a82009-02-10 21:25:46 +0100279 tid_agg_rx->dialog_token = dialog_token;
280 tid_agg_rx->ssn = start_seq_num;
281 tid_agg_rx->head_seq_num = start_seq_num;
282 tid_agg_rx->buf_size = buf_size;
283 tid_agg_rx->timeout = timeout;
284 tid_agg_rx->stored_mpdu_num = 0;
285 status = WLAN_STATUS_SUCCESS;
286end:
287 spin_unlock_bh(&sta->lock);
288
289end_no_lock:
290 ieee80211_send_addba_resp(sta->sdata, sta->sta.addr, tid,
291 dialog_token, status, 1, buf_size, timeout);
292}