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