blob: 53233ab50f656da9a9e1e33994adcc2aacb5077b [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 Berg849b7962009-02-10 21:25:54 +010021void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
22 u16 initiator, u16 reason)
Johannes Bergb8695a82009-02-10 21:25:46 +010023{
Johannes Bergd75636e2009-02-10 21:25:53 +010024 struct ieee80211_local *local = sta->local;
Johannes Berg098a6072010-04-06 11:18:47 +020025 struct tid_ampdu_rx *tid_rx;
Johannes Bergd75636e2009-02-10 21:25:53 +010026 int i;
Johannes Bergb8695a82009-02-10 21:25:46 +010027
Johannes Bergb8695a82009-02-10 21:25:46 +010028 spin_lock_bh(&sta->lock);
Johannes Berg098a6072010-04-06 11:18:47 +020029
30 /* check if TID is in operational state */
31 if (!sta->ampdu_mlme.tid_active_rx[tid]) {
Johannes Bergb8695a82009-02-10 21:25:46 +010032 spin_unlock_bh(&sta->lock);
Johannes Bergb8695a82009-02-10 21:25:46 +010033 return;
34 }
Johannes Bergd75636e2009-02-10 21:25:53 +010035
Johannes Berg098a6072010-04-06 11:18:47 +020036 sta->ampdu_mlme.tid_active_rx[tid] = false;
37
38 tid_rx = sta->ampdu_mlme.tid_rx[tid];
Johannes Bergb8695a82009-02-10 21:25:46 +010039
Johannes Bergb8695a82009-02-10 21:25:46 +010040#ifdef CONFIG_MAC80211_HT_DEBUG
41 printk(KERN_DEBUG "Rx BA session stop requested for %pM tid %u\n",
Johannes Bergd75636e2009-02-10 21:25:53 +010042 sta->sta.addr, tid);
Johannes Bergb8695a82009-02-10 21:25:46 +010043#endif /* CONFIG_MAC80211_HT_DEBUG */
44
Johannes Berg12375ef2009-11-25 20:30:31 +010045 if (drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_STOP,
Johannes Berg24487982009-04-23 18:52:52 +020046 &sta->sta, tid, NULL))
Johannes Bergb8695a82009-02-10 21:25:46 +010047 printk(KERN_DEBUG "HW problem - can not stop rx "
48 "aggregation for tid %d\n", tid);
49
Johannes Bergb8695a82009-02-10 21:25:46 +010050 /* check if this is a self generated aggregation halt */
Johannes Berg098a6072010-04-06 11:18:47 +020051 if (initiator == WLAN_BACK_RECIPIENT)
Johannes Bergd75636e2009-02-10 21:25:53 +010052 ieee80211_send_delba(sta->sdata, sta->sta.addr,
53 tid, 0, reason);
Johannes Bergb8695a82009-02-10 21:25:46 +010054
55 /* free the reordering buffer */
Johannes Berg098a6072010-04-06 11:18:47 +020056 for (i = 0; i < tid_rx->buf_size; i++) {
57 if (tid_rx->reorder_buf[i]) {
Johannes Bergb8695a82009-02-10 21:25:46 +010058 /* release the reordered frames */
Johannes Berg098a6072010-04-06 11:18:47 +020059 dev_kfree_skb(tid_rx->reorder_buf[i]);
60 tid_rx->stored_mpdu_num--;
61 tid_rx->reorder_buf[i] = NULL;
Johannes Bergb8695a82009-02-10 21:25:46 +010062 }
63 }
Johannes Berg55687e32009-02-10 21:25:51 +010064
Johannes Bergb8695a82009-02-10 21:25:46 +010065 /* free resources */
Johannes Berg098a6072010-04-06 11:18:47 +020066 kfree(tid_rx->reorder_buf);
67 kfree(tid_rx->reorder_time);
68 sta->ampdu_mlme.tid_rx[tid] = NULL;
Johannes Berg55687e32009-02-10 21:25:51 +010069
Johannes Berg55687e32009-02-10 21:25:51 +010070 spin_unlock_bh(&sta->lock);
Johannes Berg098a6072010-04-06 11:18:47 +020071
72 del_timer_sync(&tid_rx->session_timer);
73 kfree(tid_rx);
Johannes Bergd75636e2009-02-10 21:25:53 +010074}
75
Johannes Bergb8695a82009-02-10 21:25:46 +010076/*
77 * After accepting the AddBA Request we activated a timer,
78 * resetting it after each frame that arrives from the originator.
Johannes Bergb8695a82009-02-10 21:25:46 +010079 */
80static void sta_rx_agg_session_timer_expired(unsigned long data)
81{
82 /* not an elegant detour, but there is no choice as the timer passes
83 * only one argument, and various sta_info are needed here, so init
84 * flow in sta_info_create gives the TID as data, while the timer_to_id
85 * array gives the sta through container_of */
86 u8 *ptid = (u8 *)data;
87 u8 *timer_to_id = ptid - *ptid;
88 struct sta_info *sta = container_of(timer_to_id, struct sta_info,
89 timer_to_tid[0]);
90
91#ifdef CONFIG_MAC80211_HT_DEBUG
92 printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
93#endif
Johannes Berg66b04702010-04-06 11:18:45 +020094 __ieee80211_stop_rx_ba_session(sta, *ptid, WLAN_BACK_RECIPIENT,
95 WLAN_REASON_QSTA_TIMEOUT);
Johannes Bergb8695a82009-02-10 21:25:46 +010096}
97
98static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *da, u16 tid,
99 u8 dialog_token, u16 status, u16 policy,
100 u16 buf_size, u16 timeout)
101{
Johannes Bergb8695a82009-02-10 21:25:46 +0100102 struct ieee80211_local *local = sdata->local;
103 struct sk_buff *skb;
104 struct ieee80211_mgmt *mgmt;
105 u16 capab;
106
107 skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
108
109 if (!skb) {
110 printk(KERN_DEBUG "%s: failed to allocate buffer "
Johannes Berg47846c92009-11-25 17:46:19 +0100111 "for addba resp frame\n", sdata->name);
Johannes Bergb8695a82009-02-10 21:25:46 +0100112 return;
113 }
114
115 skb_reserve(skb, local->hw.extra_tx_headroom);
116 mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
117 memset(mgmt, 0, 24);
118 memcpy(mgmt->da, da, ETH_ALEN);
Johannes Berg47846c92009-11-25 17:46:19 +0100119 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
Johannes Berg8abd3f92009-02-10 21:25:47 +0100120 if (sdata->vif.type == NL80211_IFTYPE_AP ||
121 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
Johannes Berg47846c92009-11-25 17:46:19 +0100122 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
Johannes Berg46900292009-02-15 12:44:28 +0100123 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
124 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
125
Johannes Bergb8695a82009-02-10 21:25:46 +0100126 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
127 IEEE80211_STYPE_ACTION);
128
129 skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
130 mgmt->u.action.category = WLAN_CATEGORY_BACK;
131 mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
132 mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
133
134 capab = (u16)(policy << 1); /* bit 1 aggregation policy */
135 capab |= (u16)(tid << 2); /* bit 5:2 TID number */
136 capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */
137
138 mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
139 mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
140 mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
141
Johannes Berg62ae67b2009-11-18 18:42:05 +0100142 ieee80211_tx_skb(sdata, skb);
Johannes Bergb8695a82009-02-10 21:25:46 +0100143}
144
145void ieee80211_process_addba_request(struct ieee80211_local *local,
146 struct sta_info *sta,
147 struct ieee80211_mgmt *mgmt,
148 size_t len)
149{
150 struct ieee80211_hw *hw = &local->hw;
151 struct ieee80211_conf *conf = &hw->conf;
152 struct tid_ampdu_rx *tid_agg_rx;
153 u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
154 u8 dialog_token;
155 int ret = -EOPNOTSUPP;
156
157 /* extract session parameters from addba request frame */
158 dialog_token = mgmt->u.action.u.addba_req.dialog_token;
159 timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
160 start_seq_num =
161 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
162
163 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
164 ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
165 tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
166 buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
167
168 status = WLAN_STATUS_REQUEST_DECLINED;
169
Johannes Berg618f3562010-04-06 11:18:46 +0200170 if (test_sta_flags(sta, WLAN_STA_BLOCK_BA)) {
Sujith722f0692009-03-17 08:50:06 +0530171#ifdef CONFIG_MAC80211_HT_DEBUG
172 printk(KERN_DEBUG "Suspend in progress. "
173 "Denying ADDBA request\n");
174#endif
175 goto end_no_lock;
176 }
177
Johannes Bergb8695a82009-02-10 21:25:46 +0100178 /* sanity check for incoming parameters:
179 * check if configuration can support the BA policy
180 * and if buffer size does not exceeds max value */
181 /* XXX: check own ht delayed BA capability?? */
Joe Perchesf64f9e72009-11-29 16:55:45 -0800182 if (((ba_policy != 1) &&
183 (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA))) ||
184 (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
Johannes Bergb8695a82009-02-10 21:25:46 +0100185 status = WLAN_STATUS_INVALID_QOS_PARAM;
186#ifdef CONFIG_MAC80211_HT_DEBUG
187 if (net_ratelimit())
188 printk(KERN_DEBUG "AddBA Req with bad params from "
189 "%pM on tid %u. policy %d, buffer size %d\n",
190 mgmt->sa, tid, ba_policy,
191 buf_size);
192#endif /* CONFIG_MAC80211_HT_DEBUG */
193 goto end_no_lock;
194 }
195 /* determine default buffer size */
196 if (buf_size == 0) {
197 struct ieee80211_supported_band *sband;
198
199 sband = local->hw.wiphy->bands[conf->channel->band];
200 buf_size = IEEE80211_MIN_AMPDU_BUF;
201 buf_size = buf_size << sband->ht_cap.ampdu_factor;
202 }
203
204
205 /* examine state machine */
206 spin_lock_bh(&sta->lock);
207
Johannes Berg098a6072010-04-06 11:18:47 +0200208 if (sta->ampdu_mlme.tid_active_rx[tid]) {
Johannes Bergb8695a82009-02-10 21:25:46 +0100209#ifdef CONFIG_MAC80211_HT_DEBUG
210 if (net_ratelimit())
211 printk(KERN_DEBUG "unexpected AddBA Req from "
212 "%pM on tid %u\n",
213 mgmt->sa, tid);
214#endif /* CONFIG_MAC80211_HT_DEBUG */
215 goto end;
216 }
217
218 /* prepare A-MPDU MLME for Rx aggregation */
219 sta->ampdu_mlme.tid_rx[tid] =
220 kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC);
221 if (!sta->ampdu_mlme.tid_rx[tid]) {
222#ifdef CONFIG_MAC80211_HT_DEBUG
223 if (net_ratelimit())
224 printk(KERN_ERR "allocate rx mlme to tid %d failed\n",
225 tid);
226#endif
227 goto end;
228 }
229 /* rx timer */
230 sta->ampdu_mlme.tid_rx[tid]->session_timer.function =
231 sta_rx_agg_session_timer_expired;
232 sta->ampdu_mlme.tid_rx[tid]->session_timer.data =
233 (unsigned long)&sta->timer_to_tid[tid];
234 init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
235
236 tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
237
238 /* prepare reordering buffer */
239 tid_agg_rx->reorder_buf =
240 kcalloc(buf_size, sizeof(struct sk_buff *), GFP_ATOMIC);
Jouni Malinen4d050f12009-05-05 20:35:14 +0300241 tid_agg_rx->reorder_time =
242 kcalloc(buf_size, sizeof(unsigned long), GFP_ATOMIC);
243 if (!tid_agg_rx->reorder_buf || !tid_agg_rx->reorder_time) {
Johannes Bergb8695a82009-02-10 21:25:46 +0100244#ifdef CONFIG_MAC80211_HT_DEBUG
245 if (net_ratelimit())
246 printk(KERN_ERR "can not allocate reordering buffer "
247 "to tid %d\n", tid);
248#endif
Jouni Malinen4d050f12009-05-05 20:35:14 +0300249 kfree(tid_agg_rx->reorder_buf);
250 kfree(tid_agg_rx->reorder_time);
Johannes Bergb8695a82009-02-10 21:25:46 +0100251 kfree(sta->ampdu_mlme.tid_rx[tid]);
Jouni Malinen4d050f12009-05-05 20:35:14 +0300252 sta->ampdu_mlme.tid_rx[tid] = NULL;
Johannes Bergb8695a82009-02-10 21:25:46 +0100253 goto end;
254 }
255
Johannes Berg12375ef2009-11-25 20:30:31 +0100256 ret = drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_START,
Johannes Berg24487982009-04-23 18:52:52 +0200257 &sta->sta, tid, &start_seq_num);
Johannes Bergb8695a82009-02-10 21:25:46 +0100258#ifdef CONFIG_MAC80211_HT_DEBUG
259 printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
260#endif /* CONFIG_MAC80211_HT_DEBUG */
261
262 if (ret) {
263 kfree(tid_agg_rx->reorder_buf);
264 kfree(tid_agg_rx);
265 sta->ampdu_mlme.tid_rx[tid] = NULL;
266 goto end;
267 }
268
269 /* change state and send addba resp */
Johannes Berg098a6072010-04-06 11:18:47 +0200270 sta->ampdu_mlme.tid_active_rx[tid] = true;
Johannes Bergb8695a82009-02-10 21:25:46 +0100271 tid_agg_rx->dialog_token = dialog_token;
272 tid_agg_rx->ssn = start_seq_num;
273 tid_agg_rx->head_seq_num = start_seq_num;
274 tid_agg_rx->buf_size = buf_size;
275 tid_agg_rx->timeout = timeout;
276 tid_agg_rx->stored_mpdu_num = 0;
277 status = WLAN_STATUS_SUCCESS;
278end:
279 spin_unlock_bh(&sta->lock);
280
281end_no_lock:
282 ieee80211_send_addba_resp(sta->sdata, sta->sta.addr, tid,
283 dialog_token, status, 1, buf_size, timeout);
284}