]> git.karo-electronics.de Git - mv-sheeva.git/blob - net/mac80211/agg-rx.c
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[mv-sheeva.git] / net / mac80211 / agg-rx.c
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 <linux/slab.h>
18 #include <net/mac80211.h>
19 #include "ieee80211_i.h"
20 #include "driver-ops.h"
21
22 void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
23                                     u16 initiator, u16 reason)
24 {
25         struct ieee80211_local *local = sta->local;
26         struct tid_ampdu_rx *tid_rx;
27         int i;
28
29         spin_lock_bh(&sta->lock);
30
31         /* check if TID is in operational state */
32         if (!sta->ampdu_mlme.tid_active_rx[tid]) {
33                 spin_unlock_bh(&sta->lock);
34                 return;
35         }
36
37         sta->ampdu_mlme.tid_active_rx[tid] = false;
38
39         tid_rx = sta->ampdu_mlme.tid_rx[tid];
40
41 #ifdef CONFIG_MAC80211_HT_DEBUG
42         printk(KERN_DEBUG "Rx BA session stop requested for %pM tid %u\n",
43                sta->sta.addr, tid);
44 #endif /* CONFIG_MAC80211_HT_DEBUG */
45
46         if (drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_STOP,
47                              &sta->sta, tid, NULL))
48                 printk(KERN_DEBUG "HW problem - can not stop rx "
49                                 "aggregation for tid %d\n", tid);
50
51         /* check if this is a self generated aggregation halt */
52         if (initiator == WLAN_BACK_RECIPIENT)
53                 ieee80211_send_delba(sta->sdata, sta->sta.addr,
54                                      tid, 0, reason);
55
56         /* free the reordering buffer */
57         for (i = 0; i < tid_rx->buf_size; i++) {
58                 if (tid_rx->reorder_buf[i]) {
59                         /* release the reordered frames */
60                         dev_kfree_skb(tid_rx->reorder_buf[i]);
61                         tid_rx->stored_mpdu_num--;
62                         tid_rx->reorder_buf[i] = NULL;
63                 }
64         }
65
66         /* free resources */
67         kfree(tid_rx->reorder_buf);
68         kfree(tid_rx->reorder_time);
69         sta->ampdu_mlme.tid_rx[tid] = NULL;
70
71         spin_unlock_bh(&sta->lock);
72
73         del_timer_sync(&tid_rx->session_timer);
74         kfree(tid_rx);
75 }
76
77 /*
78  * After accepting the AddBA Request we activated a timer,
79  * resetting it after each frame that arrives from the originator.
80  */
81 static void sta_rx_agg_session_timer_expired(unsigned long data)
82 {
83         /* not an elegant detour, but there is no choice as the timer passes
84          * only one argument, and various sta_info are needed here, so init
85          * flow in sta_info_create gives the TID as data, while the timer_to_id
86          * array gives the sta through container_of */
87         u8 *ptid = (u8 *)data;
88         u8 *timer_to_id = ptid - *ptid;
89         struct sta_info *sta = container_of(timer_to_id, struct sta_info,
90                                          timer_to_tid[0]);
91
92 #ifdef CONFIG_MAC80211_HT_DEBUG
93         printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
94 #endif
95         __ieee80211_stop_rx_ba_session(sta, *ptid, WLAN_BACK_RECIPIENT,
96                                        WLAN_REASON_QSTA_TIMEOUT);
97 }
98
99 static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *da, u16 tid,
100                                       u8 dialog_token, u16 status, u16 policy,
101                                       u16 buf_size, u16 timeout)
102 {
103         struct ieee80211_local *local = sdata->local;
104         struct sk_buff *skb;
105         struct ieee80211_mgmt *mgmt;
106         u16 capab;
107
108         skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
109
110         if (!skb) {
111                 printk(KERN_DEBUG "%s: failed to allocate buffer "
112                        "for addba resp frame\n", sdata->name);
113                 return;
114         }
115
116         skb_reserve(skb, local->hw.extra_tx_headroom);
117         mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
118         memset(mgmt, 0, 24);
119         memcpy(mgmt->da, da, ETH_ALEN);
120         memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
121         if (sdata->vif.type == NL80211_IFTYPE_AP ||
122             sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
123                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
124         else if (sdata->vif.type == NL80211_IFTYPE_STATION)
125                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
126
127         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
128                                           IEEE80211_STYPE_ACTION);
129
130         skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
131         mgmt->u.action.category = WLAN_CATEGORY_BACK;
132         mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
133         mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
134
135         capab = (u16)(policy << 1);     /* bit 1 aggregation policy */
136         capab |= (u16)(tid << 2);       /* bit 5:2 TID number */
137         capab |= (u16)(buf_size << 6);  /* bit 15:6 max size of aggregation */
138
139         mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
140         mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
141         mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
142
143         ieee80211_tx_skb(sdata, skb);
144 }
145
146 void ieee80211_process_addba_request(struct ieee80211_local *local,
147                                      struct sta_info *sta,
148                                      struct ieee80211_mgmt *mgmt,
149                                      size_t len)
150 {
151         struct ieee80211_hw *hw = &local->hw;
152         struct ieee80211_conf *conf = &hw->conf;
153         struct tid_ampdu_rx *tid_agg_rx;
154         u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
155         u8 dialog_token;
156         int ret = -EOPNOTSUPP;
157
158         /* extract session parameters from addba request frame */
159         dialog_token = mgmt->u.action.u.addba_req.dialog_token;
160         timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
161         start_seq_num =
162                 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
163
164         capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
165         ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
166         tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
167         buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
168
169         status = WLAN_STATUS_REQUEST_DECLINED;
170
171         if (test_sta_flags(sta, WLAN_STA_BLOCK_BA)) {
172 #ifdef CONFIG_MAC80211_HT_DEBUG
173                 printk(KERN_DEBUG "Suspend in progress. "
174                        "Denying ADDBA request\n");
175 #endif
176                 goto end_no_lock;
177         }
178
179         /* sanity check for incoming parameters:
180          * check if configuration can support the BA policy
181          * and if buffer size does not exceeds max value */
182         /* XXX: check own ht delayed BA capability?? */
183         if (((ba_policy != 1) &&
184              (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA))) ||
185             (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
186                 status = WLAN_STATUS_INVALID_QOS_PARAM;
187 #ifdef CONFIG_MAC80211_HT_DEBUG
188                 if (net_ratelimit())
189                         printk(KERN_DEBUG "AddBA Req with bad params from "
190                                 "%pM on tid %u. policy %d, buffer size %d\n",
191                                 mgmt->sa, tid, ba_policy,
192                                 buf_size);
193 #endif /* CONFIG_MAC80211_HT_DEBUG */
194                 goto end_no_lock;
195         }
196         /* determine default buffer size */
197         if (buf_size == 0) {
198                 struct ieee80211_supported_band *sband;
199
200                 sband = local->hw.wiphy->bands[conf->channel->band];
201                 buf_size = IEEE80211_MIN_AMPDU_BUF;
202                 buf_size = buf_size << sband->ht_cap.ampdu_factor;
203         }
204
205
206         /* examine state machine */
207         spin_lock_bh(&sta->lock);
208
209         if (sta->ampdu_mlme.tid_active_rx[tid]) {
210 #ifdef CONFIG_MAC80211_HT_DEBUG
211                 if (net_ratelimit())
212                         printk(KERN_DEBUG "unexpected AddBA Req from "
213                                 "%pM on tid %u\n",
214                                 mgmt->sa, tid);
215 #endif /* CONFIG_MAC80211_HT_DEBUG */
216                 goto end;
217         }
218
219         /* prepare A-MPDU MLME for Rx aggregation */
220         sta->ampdu_mlme.tid_rx[tid] =
221                         kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC);
222         if (!sta->ampdu_mlme.tid_rx[tid]) {
223 #ifdef CONFIG_MAC80211_HT_DEBUG
224                 if (net_ratelimit())
225                         printk(KERN_ERR "allocate rx mlme to tid %d failed\n",
226                                         tid);
227 #endif
228                 goto end;
229         }
230         /* rx timer */
231         sta->ampdu_mlme.tid_rx[tid]->session_timer.function =
232                                 sta_rx_agg_session_timer_expired;
233         sta->ampdu_mlme.tid_rx[tid]->session_timer.data =
234                                 (unsigned long)&sta->timer_to_tid[tid];
235         init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer);
236
237         tid_agg_rx = sta->ampdu_mlme.tid_rx[tid];
238
239         /* prepare reordering buffer */
240         tid_agg_rx->reorder_buf =
241                 kcalloc(buf_size, sizeof(struct sk_buff *), GFP_ATOMIC);
242         tid_agg_rx->reorder_time =
243                 kcalloc(buf_size, sizeof(unsigned long), GFP_ATOMIC);
244         if (!tid_agg_rx->reorder_buf || !tid_agg_rx->reorder_time) {
245 #ifdef CONFIG_MAC80211_HT_DEBUG
246                 if (net_ratelimit())
247                         printk(KERN_ERR "can not allocate reordering buffer "
248                                "to tid %d\n", tid);
249 #endif
250                 kfree(tid_agg_rx->reorder_buf);
251                 kfree(tid_agg_rx->reorder_time);
252                 kfree(sta->ampdu_mlme.tid_rx[tid]);
253                 sta->ampdu_mlme.tid_rx[tid] = NULL;
254                 goto end;
255         }
256
257         ret = drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_START,
258                                &sta->sta, tid, &start_seq_num);
259 #ifdef CONFIG_MAC80211_HT_DEBUG
260         printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
261 #endif /* CONFIG_MAC80211_HT_DEBUG */
262
263         if (ret) {
264                 kfree(tid_agg_rx->reorder_buf);
265                 kfree(tid_agg_rx);
266                 sta->ampdu_mlme.tid_rx[tid] = NULL;
267                 goto end;
268         }
269
270         /* change state and send addba resp */
271         sta->ampdu_mlme.tid_active_rx[tid] = true;
272         tid_agg_rx->dialog_token = dialog_token;
273         tid_agg_rx->ssn = start_seq_num;
274         tid_agg_rx->head_seq_num = start_seq_num;
275         tid_agg_rx->buf_size = buf_size;
276         tid_agg_rx->timeout = timeout;
277         tid_agg_rx->stored_mpdu_num = 0;
278         status = WLAN_STATUS_SUCCESS;
279 end:
280         spin_unlock_bh(&sta->lock);
281
282 end_no_lock:
283         ieee80211_send_addba_resp(sta->sdata, sta->sta.addr, tid,
284                                   dialog_token, status, 1, buf_size, timeout);
285 }