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 | 7c3b1dd | 2010-06-10 10:21:44 +0200 | [diff] [blame^] | 35 | void ___ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid, |
| 36 | u16 initiator, u16 reason) |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 37 | { |
Johannes Berg | d75636e | 2009-02-10 21:25:53 +0100 | [diff] [blame] | 38 | struct ieee80211_local *local = sta->local; |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame] | 39 | struct tid_ampdu_rx *tid_rx; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 40 | |
Johannes Berg | 7c3b1dd | 2010-06-10 10:21:44 +0200 | [diff] [blame^] | 41 | lockdep_assert_held(&sta->lock); |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame] | 42 | |
Johannes Berg | a87f736 | 2010-06-10 10:21:38 +0200 | [diff] [blame] | 43 | tid_rx = sta->ampdu_mlme.tid_rx[tid]; |
| 44 | |
Johannes Berg | 7c3b1dd | 2010-06-10 10:21:44 +0200 | [diff] [blame^] | 45 | if (!tid_rx) |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 46 | return; |
Johannes Berg | d75636e | 2009-02-10 21:25:53 +0100 | [diff] [blame] | 47 | |
Johannes Berg | a87f736 | 2010-06-10 10:21:38 +0200 | [diff] [blame] | 48 | rcu_assign_pointer(sta->ampdu_mlme.tid_rx[tid], NULL); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 49 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 50 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 51 | 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] | 52 | sta->sta.addr, tid); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 53 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 54 | |
Johannes Berg | 12375ef | 2009-11-25 20:30:31 +0100 | [diff] [blame] | 55 | if (drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_STOP, |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 56 | &sta->sta, tid, NULL)) |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 57 | printk(KERN_DEBUG "HW problem - can not stop rx " |
| 58 | "aggregation for tid %d\n", tid); |
| 59 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 60 | /* check if this is a self generated aggregation halt */ |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame] | 61 | if (initiator == WLAN_BACK_RECIPIENT) |
Johannes Berg | d75636e | 2009-02-10 21:25:53 +0100 | [diff] [blame] | 62 | ieee80211_send_delba(sta->sdata, sta->sta.addr, |
| 63 | tid, 0, reason); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 64 | |
Johannes Berg | 7c3b1dd | 2010-06-10 10:21:44 +0200 | [diff] [blame^] | 65 | del_timer_sync(&tid_rx->session_timer); |
Johannes Berg | a87f736 | 2010-06-10 10:21:38 +0200 | [diff] [blame] | 66 | |
| 67 | call_rcu(&tid_rx->rcu_head, ieee80211_free_tid_rx); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 68 | } |
| 69 | |
Johannes Berg | 2aab4c2 | 2010-04-19 11:00:24 +0200 | [diff] [blame] | 70 | void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid, |
| 71 | u16 initiator, u16 reason) |
| 72 | { |
Johannes Berg | 7c3b1dd | 2010-06-10 10:21:44 +0200 | [diff] [blame^] | 73 | spin_lock_bh(&sta->lock); |
| 74 | ___ieee80211_stop_rx_ba_session(sta, tid, initiator, reason); |
| 75 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 2aab4c2 | 2010-04-19 11:00:24 +0200 | [diff] [blame] | 76 | } |
| 77 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 78 | /* |
| 79 | * After accepting the AddBA Request we activated a timer, |
| 80 | * resetting it after each frame that arrives from the originator. |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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 |
Johannes Berg | 7c3b1dd | 2010-06-10 10:21:44 +0200 | [diff] [blame^] | 96 | set_bit(*ptid, sta->ampdu_mlme.tid_rx_timer_expired); |
| 97 | ieee80211_queue_work(&sta->local->hw, &sta->ampdu_mlme.work); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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 | { |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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 " |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 113 | "for addba resp frame\n", sdata->name); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 121 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
Johannes Berg | 8abd3f9 | 2009-02-10 21:25:47 +0100 | [diff] [blame] | 122 | if (sdata->vif.type == NL80211_IFTYPE_AP || |
| 123 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 124 | memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 125 | else if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 126 | memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN); |
| 127 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 144 | ieee80211_tx_skb(sdata, skb); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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 | |
Johannes Berg | 618f356 | 2010-04-06 11:18:46 +0200 | [diff] [blame] | 172 | if (test_sta_flags(sta, WLAN_STA_BLOCK_BA)) { |
Sujith | 722f069 | 2009-03-17 08:50:06 +0530 | [diff] [blame] | 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 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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?? */ |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 184 | if (((ba_policy != 1) && |
| 185 | (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA))) || |
| 186 | (buf_size > IEEE80211_MAX_AMPDU_BUF)) { |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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 | |
Johannes Berg | a87f736 | 2010-06-10 10:21:38 +0200 | [diff] [blame] | 210 | if (sta->ampdu_mlme.tid_rx[tid]) { |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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 */ |
Johannes Berg | a87f736 | 2010-06-10 10:21:38 +0200 | [diff] [blame] | 221 | tid_agg_rx = kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC); |
| 222 | if (!tid_agg_rx) { |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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 | } |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 230 | |
Johannes Berg | a87f736 | 2010-06-10 10:21:38 +0200 | [diff] [blame] | 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); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 235 | |
| 236 | /* prepare reordering buffer */ |
| 237 | tid_agg_rx->reorder_buf = |
| 238 | kcalloc(buf_size, sizeof(struct sk_buff *), GFP_ATOMIC); |
Jouni Malinen | 4d050f1 | 2009-05-05 20:35:14 +0300 | [diff] [blame] | 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) { |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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 |
Jouni Malinen | 4d050f1 | 2009-05-05 20:35:14 +0300 | [diff] [blame] | 247 | kfree(tid_agg_rx->reorder_buf); |
| 248 | kfree(tid_agg_rx->reorder_time); |
Johannes Berg | a87f736 | 2010-06-10 10:21:38 +0200 | [diff] [blame] | 249 | kfree(tid_agg_rx); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 250 | goto end; |
| 251 | } |
| 252 | |
Johannes Berg | 12375ef | 2009-11-25 20:30:31 +0100 | [diff] [blame] | 253 | ret = drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_START, |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 254 | &sta->sta, tid, &start_seq_num); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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); |
Johannes Berg | a87f736 | 2010-06-10 10:21:38 +0200 | [diff] [blame] | 261 | kfree(tid_agg_rx->reorder_time); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 262 | kfree(tid_agg_rx); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 263 | goto end; |
| 264 | } |
| 265 | |
Johannes Berg | a87f736 | 2010-06-10 10:21:38 +0200 | [diff] [blame] | 266 | /* update data */ |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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; |
Johannes Berg | a87f736 | 2010-06-10 10:21:38 +0200 | [diff] [blame] | 274 | |
| 275 | /* activate it for RX */ |
| 276 | rcu_assign_pointer(sta->ampdu_mlme.tid_rx[tid], tid_agg_rx); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 277 | end: |
| 278 | spin_unlock_bh(&sta->lock); |
| 279 | |
| 280 | end_no_lock: |
| 281 | ieee80211_send_addba_resp(sta->sdata, sta->sta.addr, tid, |
| 282 | dialog_token, status, 1, buf_size, timeout); |
| 283 | } |