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> |
| 17 | #include <net/mac80211.h> |
| 18 | #include "ieee80211_i.h" |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 19 | #include "driver-ops.h" |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 20 | |
Johannes Berg | 849b796 | 2009-02-10 21:25:54 +0100 | [diff] [blame] | 21 | void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid, |
| 22 | u16 initiator, u16 reason) |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 23 | { |
Johannes Berg | d75636e | 2009-02-10 21:25:53 +0100 | [diff] [blame] | 24 | struct ieee80211_local *local = sta->local; |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame^] | 25 | struct tid_ampdu_rx *tid_rx; |
Johannes Berg | d75636e | 2009-02-10 21:25:53 +0100 | [diff] [blame] | 26 | int i; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 27 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 28 | spin_lock_bh(&sta->lock); |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame^] | 29 | |
| 30 | /* check if TID is in operational state */ |
| 31 | if (!sta->ampdu_mlme.tid_active_rx[tid]) { |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 32 | spin_unlock_bh(&sta->lock); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 33 | return; |
| 34 | } |
Johannes Berg | d75636e | 2009-02-10 21:25:53 +0100 | [diff] [blame] | 35 | |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame^] | 36 | sta->ampdu_mlme.tid_active_rx[tid] = false; |
| 37 | |
| 38 | tid_rx = sta->ampdu_mlme.tid_rx[tid]; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 39 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 40 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 41 | 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] | 42 | sta->sta.addr, tid); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 43 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 44 | |
Johannes Berg | 12375ef | 2009-11-25 20:30:31 +0100 | [diff] [blame] | 45 | if (drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_STOP, |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 46 | &sta->sta, tid, NULL)) |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 47 | printk(KERN_DEBUG "HW problem - can not stop rx " |
| 48 | "aggregation for tid %d\n", tid); |
| 49 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 50 | /* check if this is a self generated aggregation halt */ |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame^] | 51 | if (initiator == WLAN_BACK_RECIPIENT) |
Johannes Berg | d75636e | 2009-02-10 21:25:53 +0100 | [diff] [blame] | 52 | ieee80211_send_delba(sta->sdata, sta->sta.addr, |
| 53 | tid, 0, reason); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 54 | |
| 55 | /* free the reordering buffer */ |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame^] | 56 | for (i = 0; i < tid_rx->buf_size; i++) { |
| 57 | if (tid_rx->reorder_buf[i]) { |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 58 | /* release the reordered frames */ |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame^] | 59 | dev_kfree_skb(tid_rx->reorder_buf[i]); |
| 60 | tid_rx->stored_mpdu_num--; |
| 61 | tid_rx->reorder_buf[i] = NULL; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 62 | } |
| 63 | } |
Johannes Berg | 55687e3 | 2009-02-10 21:25:51 +0100 | [diff] [blame] | 64 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 65 | /* free resources */ |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame^] | 66 | kfree(tid_rx->reorder_buf); |
| 67 | kfree(tid_rx->reorder_time); |
| 68 | sta->ampdu_mlme.tid_rx[tid] = NULL; |
Johannes Berg | 55687e3 | 2009-02-10 21:25:51 +0100 | [diff] [blame] | 69 | |
Johannes Berg | 55687e3 | 2009-02-10 21:25:51 +0100 | [diff] [blame] | 70 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame^] | 71 | |
| 72 | del_timer_sync(&tid_rx->session_timer); |
| 73 | kfree(tid_rx); |
Johannes Berg | d75636e | 2009-02-10 21:25:53 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 76 | /* |
| 77 | * After accepting the AddBA Request we activated a timer, |
| 78 | * resetting it after each frame that arrives from the originator. |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 79 | */ |
| 80 | static 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 |
Johannes Berg | 66b0470 | 2010-04-06 11:18:45 +0200 | [diff] [blame] | 94 | __ieee80211_stop_rx_ba_session(sta, *ptid, WLAN_BACK_RECIPIENT, |
| 95 | WLAN_REASON_QSTA_TIMEOUT); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | static 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 | { |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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 " |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 111 | "for addba resp frame\n", sdata->name); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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); |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 119 | memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN); |
Johannes Berg | 8abd3f9 | 2009-02-10 21:25:47 +0100 | [diff] [blame] | 120 | if (sdata->vif.type == NL80211_IFTYPE_AP || |
| 121 | sdata->vif.type == NL80211_IFTYPE_AP_VLAN) |
Johannes Berg | 47846c9 | 2009-11-25 17:46:19 +0100 | [diff] [blame] | 122 | memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 123 | else if (sdata->vif.type == NL80211_IFTYPE_STATION) |
| 124 | memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN); |
| 125 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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 | |
Johannes Berg | 62ae67b | 2009-11-18 18:42:05 +0100 | [diff] [blame] | 142 | ieee80211_tx_skb(sdata, skb); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | void 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 | |
Johannes Berg | 618f356 | 2010-04-06 11:18:46 +0200 | [diff] [blame] | 170 | if (test_sta_flags(sta, WLAN_STA_BLOCK_BA)) { |
Sujith | 722f069 | 2009-03-17 08:50:06 +0530 | [diff] [blame] | 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 | |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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?? */ |
Joe Perches | f64f9e7 | 2009-11-29 16:55:45 -0800 | [diff] [blame] | 182 | if (((ba_policy != 1) && |
| 183 | (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA))) || |
| 184 | (buf_size > IEEE80211_MAX_AMPDU_BUF)) { |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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 | |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame^] | 208 | if (sta->ampdu_mlme.tid_active_rx[tid]) { |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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); |
Jouni Malinen | 4d050f1 | 2009-05-05 20:35:14 +0300 | [diff] [blame] | 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) { |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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 |
Jouni Malinen | 4d050f1 | 2009-05-05 20:35:14 +0300 | [diff] [blame] | 249 | kfree(tid_agg_rx->reorder_buf); |
| 250 | kfree(tid_agg_rx->reorder_time); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 251 | kfree(sta->ampdu_mlme.tid_rx[tid]); |
Jouni Malinen | 4d050f1 | 2009-05-05 20:35:14 +0300 | [diff] [blame] | 252 | sta->ampdu_mlme.tid_rx[tid] = NULL; |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 253 | goto end; |
| 254 | } |
| 255 | |
Johannes Berg | 12375ef | 2009-11-25 20:30:31 +0100 | [diff] [blame] | 256 | ret = drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_START, |
Johannes Berg | 2448798 | 2009-04-23 18:52:52 +0200 | [diff] [blame] | 257 | &sta->sta, tid, &start_seq_num); |
Johannes Berg | b8695a8 | 2009-02-10 21:25:46 +0100 | [diff] [blame] | 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 */ |
Johannes Berg | 098a607 | 2010-04-06 11:18:47 +0200 | [diff] [blame^] | 270 | sta->ampdu_mlme.tid_active_rx[tid] = true; |
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; |
| 278 | end: |
| 279 | spin_unlock_bh(&sta->lock); |
| 280 | |
| 281 | end_no_lock: |
| 282 | ieee80211_send_addba_resp(sta->sdata, sta->sta.addr, tid, |
| 283 | dialog_token, status, 1, buf_size, timeout); |
| 284 | } |