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