]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - net/mac80211/agg-rx.c
mac80211: fix typo in comments
[mirror_ubuntu-artful-kernel.git] / net / mac80211 / agg-rx.c
CommitLineData
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-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"
24487981 19#include "driver-ops.h"
b8695a8f 20
849b7967
JB
21void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
22 u16 initiator, u16 reason)
b8695a8f 23{
d75636ef 24 struct ieee80211_local *local = sta->local;
098a6070 25 struct tid_ampdu_rx *tid_rx;
d75636ef 26 int i;
b8695a8f 27
b8695a8f 28 spin_lock_bh(&sta->lock);
098a6070
JB
29
30 /* check if TID is in operational state */
31 if (!sta->ampdu_mlme.tid_active_rx[tid]) {
b8695a8f 32 spin_unlock_bh(&sta->lock);
b8695a8f
JB
33 return;
34 }
d75636ef 35
098a6070
JB
36 sta->ampdu_mlme.tid_active_rx[tid] = false;
37
38 tid_rx = sta->ampdu_mlme.tid_rx[tid];
b8695a8f 39
b8695a8f
JB
40#ifdef CONFIG_MAC80211_HT_DEBUG
41 printk(KERN_DEBUG "Rx BA session stop requested for %pM tid %u\n",
d75636ef 42 sta->sta.addr, tid);
b8695a8f
JB
43#endif /* CONFIG_MAC80211_HT_DEBUG */
44
12375ef9 45 if (drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_STOP,
24487981 46 &sta->sta, tid, NULL))
b8695a8f
JB
47 printk(KERN_DEBUG "HW problem - can not stop rx "
48 "aggregation for tid %d\n", tid);
49
b8695a8f 50 /* check if this is a self generated aggregation halt */
098a6070 51 if (initiator == WLAN_BACK_RECIPIENT)
d75636ef
JB
52 ieee80211_send_delba(sta->sdata, sta->sta.addr,
53 tid, 0, reason);
b8695a8f
JB
54
55 /* free the reordering buffer */
098a6070
JB
56 for (i = 0; i < tid_rx->buf_size; i++) {
57 if (tid_rx->reorder_buf[i]) {
b8695a8f 58 /* release the reordered frames */
098a6070
JB
59 dev_kfree_skb(tid_rx->reorder_buf[i]);
60 tid_rx->stored_mpdu_num--;
61 tid_rx->reorder_buf[i] = NULL;
b8695a8f
JB
62 }
63 }
55687e38 64
b8695a8f 65 /* free resources */
098a6070
JB
66 kfree(tid_rx->reorder_buf);
67 kfree(tid_rx->reorder_time);
68 sta->ampdu_mlme.tid_rx[tid] = NULL;
55687e38 69
55687e38 70 spin_unlock_bh(&sta->lock);
098a6070
JB
71
72 del_timer_sync(&tid_rx->session_timer);
73 kfree(tid_rx);
d75636ef
JB
74}
75
b8695a8f
JB
76/*
77 * After accepting the AddBA Request we activated a timer,
78 * resetting it after each frame that arrives from the originator.
b8695a8f
JB
79 */
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
66b0470a
JB
94 __ieee80211_stop_rx_ba_session(sta, *ptid, WLAN_BACK_RECIPIENT,
95 WLAN_REASON_QSTA_TIMEOUT);
b8695a8f
JB
96}
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{
b8695a8f
JB
102 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 "
47846c9b 111 "for addba resp frame\n", sdata->name);
b8695a8f
JB
112 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);
47846c9b 119 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
8abd3f9b
JB
120 if (sdata->vif.type == NL80211_IFTYPE_AP ||
121 sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
47846c9b 122 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
46900298
JB
123 else if (sdata->vif.type == NL80211_IFTYPE_STATION)
124 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
125
b8695a8f
JB
126 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
62ae67be 142 ieee80211_tx_skb(sdata, skb);
b8695a8f
JB
143}
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
618f356b 170 if (test_sta_flags(sta, WLAN_STA_BLOCK_BA)) {
722f069a
S
171#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
b8695a8f
JB
178 /* 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?? */
f64f9e71
JP
182 if (((ba_policy != 1) &&
183 (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA))) ||
184 (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
b8695a8f
JB
185 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
098a6070 208 if (sta->ampdu_mlme.tid_active_rx[tid]) {
b8695a8f
JB
209#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);
4d050f1d
JM
241 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) {
b8695a8f
JB
244#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
4d050f1d
JM
249 kfree(tid_agg_rx->reorder_buf);
250 kfree(tid_agg_rx->reorder_time);
b8695a8f 251 kfree(sta->ampdu_mlme.tid_rx[tid]);
4d050f1d 252 sta->ampdu_mlme.tid_rx[tid] = NULL;
b8695a8f
JB
253 goto end;
254 }
255
12375ef9 256 ret = drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_START,
24487981 257 &sta->sta, tid, &start_seq_num);
b8695a8f
JB
258#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 */
098a6070 270 sta->ampdu_mlme.tid_active_rx[tid] = true;
b8695a8f
JB
271 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}