Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HT handling |
| 3 | * |
| 4 | * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi> |
Johannes Berg | bacac54 | 2008-09-08 17:44:29 +0200 | [diff] [blame] | 5 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 6 | * Copyright 2005-2006, Devicescape Software, Inc. |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 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/wireless.h> |
| 18 | #include <net/mac80211.h> |
| 19 | #include "ieee80211_i.h" |
| 20 | #include "sta_info.h" |
Johannes Berg | bacac54 | 2008-09-08 17:44:29 +0200 | [diff] [blame] | 21 | #include "wme.h" |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 22 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame^] | 23 | void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_ht_cap *ht_cap_ie, |
| 24 | struct ieee80211_sta_ht_cap *ht_cap) |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 25 | { |
| 26 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame^] | 27 | BUG_ON(!ht_cap); |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 28 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame^] | 29 | memset(ht_cap, 0, sizeof(*ht_cap)); |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 30 | |
| 31 | if (ht_cap_ie) { |
| 32 | u8 ampdu_info = ht_cap_ie->ampdu_params_info; |
| 33 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame^] | 34 | ht_cap->ht_supported = true; |
| 35 | ht_cap->cap = le16_to_cpu(ht_cap_ie->cap_info); |
| 36 | ht_cap->ampdu_factor = |
| 37 | ampdu_info & IEEE80211_HT_AMPDU_PARM_FACTOR; |
| 38 | ht_cap->ampdu_density = |
| 39 | (ampdu_info & IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2; |
| 40 | memcpy(&ht_cap->mcs, &ht_cap_ie->mcs, sizeof(ht_cap->mcs)); |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 41 | } else |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame^] | 42 | ht_cap->ht_supported = false; |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 43 | } |
| 44 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame^] | 45 | void ieee80211_ht_info_ie_to_ht_bss_info( |
| 46 | struct ieee80211_ht_info *ht_add_info_ie, |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 47 | struct ieee80211_ht_bss_info *bss_info) |
| 48 | { |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame^] | 49 | BUG_ON(!bss_info); |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 50 | |
| 51 | memset(bss_info, 0, sizeof(*bss_info)); |
| 52 | |
| 53 | if (ht_add_info_ie) { |
| 54 | u16 op_mode; |
| 55 | op_mode = le16_to_cpu(ht_add_info_ie->operation_mode); |
| 56 | |
| 57 | bss_info->primary_channel = ht_add_info_ie->control_chan; |
| 58 | bss_info->bss_cap = ht_add_info_ie->ht_param; |
| 59 | bss_info->bss_op_mode = (u8)(op_mode & 0xff); |
| 60 | } |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame^] | 61 | } |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 62 | |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame^] | 63 | /* |
| 64 | * ieee80211_handle_ht should be called only after the operating band |
| 65 | * has been determined as ht configuration depends on the hw's |
| 66 | * HT abilities for a specific band. |
| 67 | */ |
| 68 | u32 ieee80211_handle_ht(struct ieee80211_local *local, |
| 69 | struct ieee80211_sta_ht_cap *req_ht_cap, |
| 70 | struct ieee80211_ht_bss_info *req_bss_cap) |
| 71 | { |
| 72 | struct ieee80211_conf *conf = &local->hw.conf; |
| 73 | struct ieee80211_supported_band *sband; |
| 74 | struct ieee80211_sta_ht_cap ht_cap; |
| 75 | struct ieee80211_ht_bss_info ht_bss_conf; |
| 76 | u32 changed = 0; |
| 77 | int i; |
| 78 | u8 max_tx_streams; |
| 79 | u8 tx_mcs_set_cap; |
| 80 | bool enable_ht = true; |
| 81 | |
| 82 | sband = local->hw.wiphy->bands[conf->channel->band]; |
| 83 | |
| 84 | memset(&ht_cap, 0, sizeof(ht_cap)); |
| 85 | memset(&ht_bss_conf, 0, sizeof(struct ieee80211_ht_bss_info)); |
| 86 | |
| 87 | /* HT is not supported */ |
| 88 | if (!sband->ht_cap.ht_supported) |
| 89 | enable_ht = false; |
| 90 | |
| 91 | /* disable HT */ |
| 92 | if (!enable_ht) { |
| 93 | if (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) |
| 94 | changed |= BSS_CHANGED_HT; |
| 95 | conf->flags &= ~IEEE80211_CONF_SUPPORT_HT_MODE; |
| 96 | conf->ht_cap.ht_supported = false; |
| 97 | return changed; |
| 98 | } |
| 99 | |
| 100 | |
| 101 | if (!(conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE)) |
| 102 | changed |= BSS_CHANGED_HT; |
| 103 | |
| 104 | conf->flags |= IEEE80211_CONF_SUPPORT_HT_MODE; |
| 105 | ht_cap.ht_supported = true; |
| 106 | |
| 107 | ht_cap.cap = req_ht_cap->cap & sband->ht_cap.cap; |
| 108 | ht_cap.cap &= ~IEEE80211_HT_CAP_SM_PS; |
| 109 | ht_cap.cap |= sband->ht_cap.cap & IEEE80211_HT_CAP_SM_PS; |
| 110 | |
| 111 | ht_bss_conf.primary_channel = req_bss_cap->primary_channel; |
| 112 | ht_bss_conf.bss_cap = req_bss_cap->bss_cap; |
| 113 | ht_bss_conf.bss_op_mode = req_bss_cap->bss_op_mode; |
| 114 | |
| 115 | ht_cap.ampdu_factor = req_ht_cap->ampdu_factor; |
| 116 | ht_cap.ampdu_density = req_ht_cap->ampdu_density; |
| 117 | |
| 118 | /* own MCS TX capabilities */ |
| 119 | tx_mcs_set_cap = sband->ht_cap.mcs.tx_params; |
| 120 | |
| 121 | /* |
| 122 | * configure supported Tx MCS according to requested MCS |
| 123 | * (based in most cases on Rx capabilities of peer) and self |
| 124 | * Tx MCS capabilities (as defined by low level driver HW |
| 125 | * Tx capabilities) |
| 126 | */ |
| 127 | |
| 128 | /* can we TX with MCS rates? */ |
| 129 | if (!(tx_mcs_set_cap & IEEE80211_HT_MCS_TX_DEFINED)) |
| 130 | goto check_changed; |
| 131 | |
| 132 | /* Counting from 0, therefore +1 */ |
| 133 | if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_RX_DIFF) |
| 134 | max_tx_streams = |
| 135 | ((tx_mcs_set_cap & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK) |
| 136 | >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1; |
| 137 | else |
| 138 | max_tx_streams = IEEE80211_HT_MCS_TX_MAX_STREAMS; |
| 139 | |
| 140 | /* |
| 141 | * 802.11n D5.0 20.3.5 / 20.6 says: |
| 142 | * - indices 0 to 7 and 32 are single spatial stream |
| 143 | * - 8 to 31 are multiple spatial streams using equal modulation |
| 144 | * [8..15 for two streams, 16..23 for three and 24..31 for four] |
| 145 | * - remainder are multiple spatial streams using unequal modulation |
| 146 | */ |
| 147 | for (i = 0; i < max_tx_streams; i++) |
| 148 | ht_cap.mcs.rx_mask[i] = |
| 149 | sband->ht_cap.mcs.rx_mask[i] & |
| 150 | req_ht_cap->mcs.rx_mask[i]; |
| 151 | |
| 152 | if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION) |
| 153 | for (i = IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE; |
| 154 | i < IEEE80211_HT_MCS_MASK_LEN; i++) |
| 155 | ht_cap.mcs.rx_mask[i] = |
| 156 | sband->ht_cap.mcs.rx_mask[i] & |
| 157 | req_ht_cap->mcs.rx_mask[i]; |
| 158 | |
| 159 | /* handle MCS rate 32 too */ |
| 160 | if (sband->ht_cap.mcs.rx_mask[32/8] & |
| 161 | req_ht_cap->mcs.rx_mask[32/8] & 1) |
| 162 | ht_cap.mcs.rx_mask[32/8] |= 1; |
| 163 | |
| 164 | check_changed: |
| 165 | /* if bss configuration changed store the new one */ |
| 166 | if (memcmp(&conf->ht_cap, &ht_cap, sizeof(ht_cap)) || |
| 167 | memcmp(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf))) { |
| 168 | changed |= BSS_CHANGED_HT; |
| 169 | memcpy(&conf->ht_cap, &ht_cap, sizeof(ht_cap)); |
| 170 | memcpy(&conf->ht_bss_conf, &ht_bss_conf, sizeof(ht_bss_conf)); |
| 171 | } |
| 172 | |
| 173 | return changed; |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 176 | static void ieee80211_send_addba_request(struct ieee80211_sub_if_data *sdata, |
| 177 | const u8 *da, u16 tid, |
| 178 | u8 dialog_token, u16 start_seq_num, |
| 179 | u16 agg_size, u16 timeout) |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 180 | { |
| 181 | struct ieee80211_local *local = sdata->local; |
| 182 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 183 | struct sk_buff *skb; |
| 184 | struct ieee80211_mgmt *mgmt; |
| 185 | u16 capab; |
| 186 | |
| 187 | skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom); |
| 188 | |
| 189 | if (!skb) { |
| 190 | printk(KERN_ERR "%s: failed to allocate buffer " |
| 191 | "for addba request frame\n", sdata->dev->name); |
| 192 | return; |
| 193 | } |
| 194 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 195 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 196 | memset(mgmt, 0, 24); |
| 197 | memcpy(mgmt->da, da, ETH_ALEN); |
| 198 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 199 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 200 | memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); |
| 201 | else |
| 202 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 203 | |
| 204 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 205 | IEEE80211_STYPE_ACTION); |
| 206 | |
| 207 | skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_req)); |
| 208 | |
| 209 | mgmt->u.action.category = WLAN_CATEGORY_BACK; |
| 210 | mgmt->u.action.u.addba_req.action_code = WLAN_ACTION_ADDBA_REQ; |
| 211 | |
| 212 | mgmt->u.action.u.addba_req.dialog_token = dialog_token; |
| 213 | capab = (u16)(1 << 1); /* bit 1 aggregation policy */ |
| 214 | capab |= (u16)(tid << 2); /* bit 5:2 TID number */ |
| 215 | capab |= (u16)(agg_size << 6); /* bit 15:6 max size of aggergation */ |
| 216 | |
| 217 | mgmt->u.action.u.addba_req.capab = cpu_to_le16(capab); |
| 218 | |
| 219 | mgmt->u.action.u.addba_req.timeout = cpu_to_le16(timeout); |
| 220 | mgmt->u.action.u.addba_req.start_seq_num = |
| 221 | cpu_to_le16(start_seq_num << 4); |
| 222 | |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame] | 223 | ieee80211_tx_skb(sdata, skb, 0); |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 226 | static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *da, u16 tid, |
| 227 | u8 dialog_token, u16 status, u16 policy, |
| 228 | u16 buf_size, u16 timeout) |
| 229 | { |
| 230 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 231 | struct ieee80211_local *local = sdata->local; |
| 232 | struct sk_buff *skb; |
| 233 | struct ieee80211_mgmt *mgmt; |
| 234 | u16 capab; |
| 235 | |
| 236 | skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom); |
| 237 | |
| 238 | if (!skb) { |
| 239 | printk(KERN_DEBUG "%s: failed to allocate buffer " |
| 240 | "for addba resp frame\n", sdata->dev->name); |
| 241 | return; |
| 242 | } |
| 243 | |
| 244 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 245 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 246 | memset(mgmt, 0, 24); |
| 247 | memcpy(mgmt->da, da, ETH_ALEN); |
| 248 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 249 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 250 | memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); |
| 251 | else |
| 252 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 253 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 254 | IEEE80211_STYPE_ACTION); |
| 255 | |
| 256 | skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp)); |
| 257 | mgmt->u.action.category = WLAN_CATEGORY_BACK; |
| 258 | mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP; |
| 259 | mgmt->u.action.u.addba_resp.dialog_token = dialog_token; |
| 260 | |
| 261 | capab = (u16)(policy << 1); /* bit 1 aggregation policy */ |
| 262 | capab |= (u16)(tid << 2); /* bit 5:2 TID number */ |
| 263 | capab |= (u16)(buf_size << 6); /* bit 15:6 max size of aggregation */ |
| 264 | |
| 265 | mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab); |
| 266 | mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout); |
| 267 | mgmt->u.action.u.addba_resp.status = cpu_to_le16(status); |
| 268 | |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame] | 269 | ieee80211_tx_skb(sdata, skb, 0); |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | static void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata, |
| 273 | const u8 *da, u16 tid, |
| 274 | u16 initiator, u16 reason_code) |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 275 | { |
| 276 | struct ieee80211_local *local = sdata->local; |
| 277 | struct ieee80211_if_sta *ifsta = &sdata->u.sta; |
| 278 | struct sk_buff *skb; |
| 279 | struct ieee80211_mgmt *mgmt; |
| 280 | u16 params; |
| 281 | |
| 282 | skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom); |
| 283 | |
| 284 | if (!skb) { |
| 285 | printk(KERN_ERR "%s: failed to allocate buffer " |
| 286 | "for delba frame\n", sdata->dev->name); |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 291 | mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24); |
| 292 | memset(mgmt, 0, 24); |
| 293 | memcpy(mgmt->da, da, ETH_ALEN); |
| 294 | memcpy(mgmt->sa, sdata->dev->dev_addr, ETH_ALEN); |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 295 | if (sdata->vif.type == NL80211_IFTYPE_AP) |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 296 | memcpy(mgmt->bssid, sdata->dev->dev_addr, ETH_ALEN); |
| 297 | else |
| 298 | memcpy(mgmt->bssid, ifsta->bssid, ETH_ALEN); |
| 299 | mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | |
| 300 | IEEE80211_STYPE_ACTION); |
| 301 | |
| 302 | skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba)); |
| 303 | |
| 304 | mgmt->u.action.category = WLAN_CATEGORY_BACK; |
| 305 | mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA; |
| 306 | params = (u16)(initiator << 11); /* bit 11 initiator */ |
| 307 | params |= (u16)(tid << 12); /* bit 15:12 TID number */ |
| 308 | |
| 309 | mgmt->u.action.u.delba.params = cpu_to_le16(params); |
| 310 | mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code); |
| 311 | |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame] | 312 | ieee80211_tx_skb(sdata, skb, 0); |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | void ieee80211_send_bar(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, u16 ssn) |
| 316 | { |
| 317 | struct ieee80211_local *local = sdata->local; |
| 318 | struct sk_buff *skb; |
| 319 | struct ieee80211_bar *bar; |
| 320 | u16 bar_control = 0; |
| 321 | |
| 322 | skb = dev_alloc_skb(sizeof(*bar) + local->hw.extra_tx_headroom); |
| 323 | if (!skb) { |
| 324 | printk(KERN_ERR "%s: failed to allocate buffer for " |
| 325 | "bar frame\n", sdata->dev->name); |
| 326 | return; |
| 327 | } |
| 328 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 329 | bar = (struct ieee80211_bar *)skb_put(skb, sizeof(*bar)); |
| 330 | memset(bar, 0, sizeof(*bar)); |
| 331 | bar->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL | |
| 332 | IEEE80211_STYPE_BACK_REQ); |
| 333 | memcpy(bar->ra, ra, ETH_ALEN); |
| 334 | memcpy(bar->ta, sdata->dev->dev_addr, ETH_ALEN); |
| 335 | bar_control |= (u16)IEEE80211_BAR_CTRL_ACK_POLICY_NORMAL; |
| 336 | bar_control |= (u16)IEEE80211_BAR_CTRL_CBMTID_COMPRESSED_BA; |
| 337 | bar_control |= (u16)(tid << 12); |
| 338 | bar->control = cpu_to_le16(bar_control); |
| 339 | bar->start_seq_num = cpu_to_le16(ssn); |
| 340 | |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame] | 341 | ieee80211_tx_skb(sdata, skb, 0); |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | void ieee80211_sta_stop_rx_ba_session(struct ieee80211_sub_if_data *sdata, u8 *ra, u16 tid, |
| 345 | u16 initiator, u16 reason) |
| 346 | { |
| 347 | struct ieee80211_local *local = sdata->local; |
| 348 | struct ieee80211_hw *hw = &local->hw; |
| 349 | struct sta_info *sta; |
| 350 | int ret, i; |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 351 | |
| 352 | rcu_read_lock(); |
| 353 | |
| 354 | sta = sta_info_get(local, ra); |
| 355 | if (!sta) { |
| 356 | rcu_read_unlock(); |
| 357 | return; |
| 358 | } |
| 359 | |
| 360 | /* check if TID is in operational state */ |
| 361 | spin_lock_bh(&sta->lock); |
| 362 | if (sta->ampdu_mlme.tid_state_rx[tid] |
| 363 | != HT_AGG_STATE_OPERATIONAL) { |
| 364 | spin_unlock_bh(&sta->lock); |
| 365 | rcu_read_unlock(); |
| 366 | return; |
| 367 | } |
| 368 | sta->ampdu_mlme.tid_state_rx[tid] = |
| 369 | HT_AGG_STATE_REQ_STOP_BA_MSK | |
| 370 | (initiator << HT_AGG_STATE_INITIATOR_SHIFT); |
| 371 | spin_unlock_bh(&sta->lock); |
| 372 | |
| 373 | /* stop HW Rx aggregation. ampdu_action existence |
| 374 | * already verified in session init so we add the BUG_ON */ |
| 375 | BUG_ON(!local->ops->ampdu_action); |
| 376 | |
| 377 | #ifdef CONFIG_MAC80211_HT_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 378 | printk(KERN_DEBUG "Rx BA session stop requested for %pM tid %u\n", |
| 379 | ra, tid); |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 380 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 381 | |
| 382 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_STOP, |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 383 | &sta->sta, tid, NULL); |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 384 | if (ret) |
| 385 | printk(KERN_DEBUG "HW problem - can not stop rx " |
| 386 | "aggregation for tid %d\n", tid); |
| 387 | |
| 388 | /* shutdown timer has not expired */ |
| 389 | if (initiator != WLAN_BACK_TIMER) |
| 390 | del_timer_sync(&sta->ampdu_mlme.tid_rx[tid]->session_timer); |
| 391 | |
| 392 | /* check if this is a self generated aggregation halt */ |
| 393 | if (initiator == WLAN_BACK_RECIPIENT || initiator == WLAN_BACK_TIMER) |
| 394 | ieee80211_send_delba(sdata, ra, tid, 0, reason); |
| 395 | |
| 396 | /* free the reordering buffer */ |
| 397 | for (i = 0; i < sta->ampdu_mlme.tid_rx[tid]->buf_size; i++) { |
| 398 | if (sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]) { |
| 399 | /* release the reordered frames */ |
| 400 | dev_kfree_skb(sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i]); |
| 401 | sta->ampdu_mlme.tid_rx[tid]->stored_mpdu_num--; |
| 402 | sta->ampdu_mlme.tid_rx[tid]->reorder_buf[i] = NULL; |
| 403 | } |
| 404 | } |
| 405 | /* free resources */ |
| 406 | kfree(sta->ampdu_mlme.tid_rx[tid]->reorder_buf); |
| 407 | kfree(sta->ampdu_mlme.tid_rx[tid]); |
| 408 | sta->ampdu_mlme.tid_rx[tid] = NULL; |
| 409 | sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_IDLE; |
| 410 | |
| 411 | rcu_read_unlock(); |
| 412 | } |
| 413 | |
| 414 | |
| 415 | /* |
| 416 | * After sending add Block Ack request we activated a timer until |
| 417 | * add Block Ack response will arrive from the recipient. |
| 418 | * If this timer expires sta_addba_resp_timer_expired will be executed. |
| 419 | */ |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 420 | static void sta_addba_resp_timer_expired(unsigned long data) |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 421 | { |
| 422 | /* not an elegant detour, but there is no choice as the timer passes |
| 423 | * only one argument, and both sta_info and TID are needed, so init |
| 424 | * flow in sta_info_create gives the TID as data, while the timer_to_id |
| 425 | * array gives the sta through container_of */ |
| 426 | u16 tid = *(u8 *)data; |
| 427 | struct sta_info *temp_sta = container_of((void *)data, |
| 428 | struct sta_info, timer_to_tid[tid]); |
| 429 | |
| 430 | struct ieee80211_local *local = temp_sta->local; |
| 431 | struct ieee80211_hw *hw = &local->hw; |
| 432 | struct sta_info *sta; |
| 433 | u8 *state; |
| 434 | |
| 435 | rcu_read_lock(); |
| 436 | |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 437 | sta = sta_info_get(local, temp_sta->sta.addr); |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 438 | if (!sta) { |
| 439 | rcu_read_unlock(); |
| 440 | return; |
| 441 | } |
| 442 | |
| 443 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
| 444 | /* check if the TID waits for addBA response */ |
| 445 | spin_lock_bh(&sta->lock); |
| 446 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { |
| 447 | spin_unlock_bh(&sta->lock); |
| 448 | *state = HT_AGG_STATE_IDLE; |
| 449 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 450 | printk(KERN_DEBUG "timer expired on tid %d but we are not " |
| 451 | "expecting addBA response there", tid); |
| 452 | #endif |
| 453 | goto timer_expired_exit; |
| 454 | } |
| 455 | |
| 456 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 457 | printk(KERN_DEBUG "addBA response timer expired on tid %d\n", tid); |
| 458 | #endif |
| 459 | |
| 460 | /* go through the state check in stop_BA_session */ |
| 461 | *state = HT_AGG_STATE_OPERATIONAL; |
| 462 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 463 | ieee80211_stop_tx_ba_session(hw, temp_sta->sta.addr, tid, |
Johannes Berg | 44d414d | 2008-09-08 17:44:28 +0200 | [diff] [blame] | 464 | WLAN_BACK_INITIATOR); |
| 465 | |
| 466 | timer_expired_exit: |
| 467 | rcu_read_unlock(); |
| 468 | } |
| 469 | |
| 470 | void ieee80211_sta_tear_down_BA_sessions(struct ieee80211_sub_if_data *sdata, u8 *addr) |
| 471 | { |
| 472 | struct ieee80211_local *local = sdata->local; |
| 473 | int i; |
| 474 | |
| 475 | for (i = 0; i < STA_TID_NUM; i++) { |
| 476 | ieee80211_stop_tx_ba_session(&local->hw, addr, i, |
| 477 | WLAN_BACK_INITIATOR); |
| 478 | ieee80211_sta_stop_rx_ba_session(sdata, addr, i, |
| 479 | WLAN_BACK_RECIPIENT, |
| 480 | WLAN_REASON_QSTA_LEAVE_QBSS); |
| 481 | } |
| 482 | } |
| 483 | |
Johannes Berg | bacac54 | 2008-09-08 17:44:29 +0200 | [diff] [blame] | 484 | int ieee80211_start_tx_ba_session(struct ieee80211_hw *hw, u8 *ra, u16 tid) |
| 485 | { |
| 486 | struct ieee80211_local *local = hw_to_local(hw); |
| 487 | struct sta_info *sta; |
| 488 | struct ieee80211_sub_if_data *sdata; |
| 489 | u16 start_seq_num; |
| 490 | u8 *state; |
| 491 | int ret; |
Johannes Berg | bacac54 | 2008-09-08 17:44:29 +0200 | [diff] [blame] | 492 | |
| 493 | if (tid >= STA_TID_NUM) |
| 494 | return -EINVAL; |
| 495 | |
| 496 | #ifdef CONFIG_MAC80211_HT_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 497 | printk(KERN_DEBUG "Open BA session requested for %pM tid %u\n", |
| 498 | ra, tid); |
Johannes Berg | bacac54 | 2008-09-08 17:44:29 +0200 | [diff] [blame] | 499 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 500 | |
| 501 | rcu_read_lock(); |
| 502 | |
| 503 | sta = sta_info_get(local, ra); |
| 504 | if (!sta) { |
| 505 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 506 | printk(KERN_DEBUG "Could not find the station\n"); |
| 507 | #endif |
| 508 | ret = -ENOENT; |
| 509 | goto exit; |
| 510 | } |
| 511 | |
| 512 | spin_lock_bh(&sta->lock); |
| 513 | |
| 514 | /* we have tried too many times, receiver does not want A-MPDU */ |
| 515 | if (sta->ampdu_mlme.addba_req_num[tid] > HT_AGG_MAX_RETRIES) { |
| 516 | ret = -EBUSY; |
| 517 | goto err_unlock_sta; |
| 518 | } |
| 519 | |
| 520 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
| 521 | /* check if the TID is not in aggregation flow already */ |
| 522 | if (*state != HT_AGG_STATE_IDLE) { |
| 523 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 524 | printk(KERN_DEBUG "BA request denied - session is not " |
| 525 | "idle on tid %u\n", tid); |
| 526 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 527 | ret = -EAGAIN; |
| 528 | goto err_unlock_sta; |
| 529 | } |
| 530 | |
| 531 | /* prepare A-MPDU MLME for Tx aggregation */ |
| 532 | sta->ampdu_mlme.tid_tx[tid] = |
| 533 | kmalloc(sizeof(struct tid_ampdu_tx), GFP_ATOMIC); |
| 534 | if (!sta->ampdu_mlme.tid_tx[tid]) { |
| 535 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 536 | if (net_ratelimit()) |
| 537 | printk(KERN_ERR "allocate tx mlme to tid %d failed\n", |
| 538 | tid); |
| 539 | #endif |
| 540 | ret = -ENOMEM; |
| 541 | goto err_unlock_sta; |
| 542 | } |
| 543 | /* Tx timer */ |
| 544 | sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.function = |
| 545 | sta_addba_resp_timer_expired; |
| 546 | sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.data = |
| 547 | (unsigned long)&sta->timer_to_tid[tid]; |
| 548 | init_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer); |
| 549 | |
| 550 | /* create a new queue for this aggregation */ |
| 551 | ret = ieee80211_ht_agg_queue_add(local, sta, tid); |
| 552 | |
| 553 | /* case no queue is available to aggregation |
| 554 | * don't switch to aggregation */ |
| 555 | if (ret) { |
| 556 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 557 | printk(KERN_DEBUG "BA request denied - queue unavailable for" |
| 558 | " tid %d\n", tid); |
| 559 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 560 | goto err_unlock_queue; |
| 561 | } |
| 562 | sdata = sta->sdata; |
| 563 | |
| 564 | /* Ok, the Addba frame hasn't been sent yet, but if the driver calls the |
| 565 | * call back right away, it must see that the flow has begun */ |
| 566 | *state |= HT_ADDBA_REQUESTED_MSK; |
| 567 | |
| 568 | /* This is slightly racy because the queue isn't stopped */ |
| 569 | start_seq_num = sta->tid_seq[tid]; |
| 570 | |
| 571 | if (local->ops->ampdu_action) |
| 572 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_START, |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 573 | &sta->sta, tid, &start_seq_num); |
Johannes Berg | bacac54 | 2008-09-08 17:44:29 +0200 | [diff] [blame] | 574 | |
| 575 | if (ret) { |
| 576 | /* No need to requeue the packets in the agg queue, since we |
| 577 | * held the tx lock: no packet could be enqueued to the newly |
| 578 | * allocated queue */ |
| 579 | ieee80211_ht_agg_queue_remove(local, sta, tid, 0); |
| 580 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 581 | printk(KERN_DEBUG "BA request denied - HW unavailable for" |
| 582 | " tid %d\n", tid); |
| 583 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 584 | *state = HT_AGG_STATE_IDLE; |
| 585 | goto err_unlock_queue; |
| 586 | } |
| 587 | |
| 588 | /* Will put all the packets in the new SW queue */ |
| 589 | ieee80211_requeue(local, ieee802_1d_to_ac[tid]); |
| 590 | spin_unlock_bh(&sta->lock); |
| 591 | |
| 592 | /* send an addBA request */ |
| 593 | sta->ampdu_mlme.dialog_token_allocator++; |
| 594 | sta->ampdu_mlme.tid_tx[tid]->dialog_token = |
| 595 | sta->ampdu_mlme.dialog_token_allocator; |
| 596 | sta->ampdu_mlme.tid_tx[tid]->ssn = start_seq_num; |
| 597 | |
| 598 | |
| 599 | ieee80211_send_addba_request(sta->sdata, ra, tid, |
| 600 | sta->ampdu_mlme.tid_tx[tid]->dialog_token, |
| 601 | sta->ampdu_mlme.tid_tx[tid]->ssn, |
| 602 | 0x40, 5000); |
| 603 | /* activate the timer for the recipient's addBA response */ |
| 604 | sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer.expires = |
| 605 | jiffies + ADDBA_RESP_INTERVAL; |
| 606 | add_timer(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer); |
| 607 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 608 | printk(KERN_DEBUG "activated addBA response timer on tid %d\n", tid); |
| 609 | #endif |
| 610 | goto exit; |
| 611 | |
| 612 | err_unlock_queue: |
| 613 | kfree(sta->ampdu_mlme.tid_tx[tid]); |
| 614 | sta->ampdu_mlme.tid_tx[tid] = NULL; |
| 615 | ret = -EBUSY; |
| 616 | err_unlock_sta: |
| 617 | spin_unlock_bh(&sta->lock); |
| 618 | exit: |
| 619 | rcu_read_unlock(); |
| 620 | return ret; |
| 621 | } |
| 622 | EXPORT_SYMBOL(ieee80211_start_tx_ba_session); |
| 623 | |
| 624 | int ieee80211_stop_tx_ba_session(struct ieee80211_hw *hw, |
| 625 | u8 *ra, u16 tid, |
| 626 | enum ieee80211_back_parties initiator) |
| 627 | { |
| 628 | struct ieee80211_local *local = hw_to_local(hw); |
| 629 | struct sta_info *sta; |
| 630 | u8 *state; |
| 631 | int ret = 0; |
Johannes Berg | bacac54 | 2008-09-08 17:44:29 +0200 | [diff] [blame] | 632 | |
| 633 | if (tid >= STA_TID_NUM) |
| 634 | return -EINVAL; |
| 635 | |
| 636 | rcu_read_lock(); |
| 637 | sta = sta_info_get(local, ra); |
| 638 | if (!sta) { |
| 639 | rcu_read_unlock(); |
| 640 | return -ENOENT; |
| 641 | } |
| 642 | |
| 643 | /* check if the TID is in aggregation */ |
| 644 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
| 645 | spin_lock_bh(&sta->lock); |
| 646 | |
| 647 | if (*state != HT_AGG_STATE_OPERATIONAL) { |
| 648 | ret = -ENOENT; |
| 649 | goto stop_BA_exit; |
| 650 | } |
| 651 | |
| 652 | #ifdef CONFIG_MAC80211_HT_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 653 | printk(KERN_DEBUG "Tx BA session stop requested for %pM tid %u\n", |
| 654 | ra, tid); |
Johannes Berg | bacac54 | 2008-09-08 17:44:29 +0200 | [diff] [blame] | 655 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 656 | |
| 657 | ieee80211_stop_queue(hw, sta->tid_to_tx_q[tid]); |
| 658 | |
| 659 | *state = HT_AGG_STATE_REQ_STOP_BA_MSK | |
| 660 | (initiator << HT_AGG_STATE_INITIATOR_SHIFT); |
| 661 | |
| 662 | if (local->ops->ampdu_action) |
| 663 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_TX_STOP, |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 664 | &sta->sta, tid, NULL); |
Johannes Berg | bacac54 | 2008-09-08 17:44:29 +0200 | [diff] [blame] | 665 | |
| 666 | /* case HW denied going back to legacy */ |
| 667 | if (ret) { |
| 668 | WARN_ON(ret != -EBUSY); |
| 669 | *state = HT_AGG_STATE_OPERATIONAL; |
| 670 | ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); |
| 671 | goto stop_BA_exit; |
| 672 | } |
| 673 | |
| 674 | stop_BA_exit: |
| 675 | spin_unlock_bh(&sta->lock); |
| 676 | rcu_read_unlock(); |
| 677 | return ret; |
| 678 | } |
| 679 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_session); |
| 680 | |
| 681 | void ieee80211_start_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u16 tid) |
| 682 | { |
| 683 | struct ieee80211_local *local = hw_to_local(hw); |
| 684 | struct sta_info *sta; |
| 685 | u8 *state; |
Johannes Berg | bacac54 | 2008-09-08 17:44:29 +0200 | [diff] [blame] | 686 | |
| 687 | if (tid >= STA_TID_NUM) { |
| 688 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 689 | printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n", |
| 690 | tid, STA_TID_NUM); |
| 691 | #endif |
| 692 | return; |
| 693 | } |
| 694 | |
| 695 | rcu_read_lock(); |
| 696 | sta = sta_info_get(local, ra); |
| 697 | if (!sta) { |
| 698 | rcu_read_unlock(); |
| 699 | #ifdef CONFIG_MAC80211_HT_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 700 | printk(KERN_DEBUG "Could not find station: %pM\n", ra); |
Johannes Berg | bacac54 | 2008-09-08 17:44:29 +0200 | [diff] [blame] | 701 | #endif |
| 702 | return; |
| 703 | } |
| 704 | |
| 705 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
| 706 | spin_lock_bh(&sta->lock); |
| 707 | |
| 708 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { |
| 709 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 710 | printk(KERN_DEBUG "addBA was not requested yet, state is %d\n", |
| 711 | *state); |
| 712 | #endif |
| 713 | spin_unlock_bh(&sta->lock); |
| 714 | rcu_read_unlock(); |
| 715 | return; |
| 716 | } |
| 717 | |
| 718 | WARN_ON_ONCE(*state & HT_ADDBA_DRV_READY_MSK); |
| 719 | |
| 720 | *state |= HT_ADDBA_DRV_READY_MSK; |
| 721 | |
| 722 | if (*state == HT_AGG_STATE_OPERATIONAL) { |
| 723 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 724 | printk(KERN_DEBUG "Aggregation is on for tid %d \n", tid); |
| 725 | #endif |
| 726 | ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); |
| 727 | } |
| 728 | spin_unlock_bh(&sta->lock); |
| 729 | rcu_read_unlock(); |
| 730 | } |
| 731 | EXPORT_SYMBOL(ieee80211_start_tx_ba_cb); |
| 732 | |
| 733 | void ieee80211_stop_tx_ba_cb(struct ieee80211_hw *hw, u8 *ra, u8 tid) |
| 734 | { |
| 735 | struct ieee80211_local *local = hw_to_local(hw); |
| 736 | struct sta_info *sta; |
| 737 | u8 *state; |
| 738 | int agg_queue; |
Johannes Berg | bacac54 | 2008-09-08 17:44:29 +0200 | [diff] [blame] | 739 | |
| 740 | if (tid >= STA_TID_NUM) { |
| 741 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 742 | printk(KERN_DEBUG "Bad TID value: tid = %d (>= %d)\n", |
| 743 | tid, STA_TID_NUM); |
| 744 | #endif |
| 745 | return; |
| 746 | } |
| 747 | |
| 748 | #ifdef CONFIG_MAC80211_HT_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 749 | printk(KERN_DEBUG "Stopping Tx BA session for %pM tid %d\n", |
| 750 | ra, tid); |
Johannes Berg | bacac54 | 2008-09-08 17:44:29 +0200 | [diff] [blame] | 751 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 752 | |
| 753 | rcu_read_lock(); |
| 754 | sta = sta_info_get(local, ra); |
| 755 | if (!sta) { |
| 756 | #ifdef CONFIG_MAC80211_HT_DEBUG |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 757 | printk(KERN_DEBUG "Could not find station: %pM\n", ra); |
Johannes Berg | bacac54 | 2008-09-08 17:44:29 +0200 | [diff] [blame] | 758 | #endif |
| 759 | rcu_read_unlock(); |
| 760 | return; |
| 761 | } |
| 762 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
| 763 | |
| 764 | /* NOTE: no need to use sta->lock in this state check, as |
| 765 | * ieee80211_stop_tx_ba_session will let only one stop call to |
| 766 | * pass through per sta/tid |
| 767 | */ |
| 768 | if ((*state & HT_AGG_STATE_REQ_STOP_BA_MSK) == 0) { |
| 769 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 770 | printk(KERN_DEBUG "unexpected callback to A-MPDU stop\n"); |
| 771 | #endif |
| 772 | rcu_read_unlock(); |
| 773 | return; |
| 774 | } |
| 775 | |
| 776 | if (*state & HT_AGG_STATE_INITIATOR_MSK) |
| 777 | ieee80211_send_delba(sta->sdata, ra, tid, |
| 778 | WLAN_BACK_INITIATOR, WLAN_REASON_QSTA_NOT_USE); |
| 779 | |
| 780 | agg_queue = sta->tid_to_tx_q[tid]; |
| 781 | |
| 782 | ieee80211_ht_agg_queue_remove(local, sta, tid, 1); |
| 783 | |
| 784 | /* We just requeued the all the frames that were in the |
| 785 | * removed queue, and since we might miss a softirq we do |
| 786 | * netif_schedule_queue. ieee80211_wake_queue is not used |
| 787 | * here as this queue is not necessarily stopped |
| 788 | */ |
| 789 | netif_schedule_queue(netdev_get_tx_queue(local->mdev, agg_queue)); |
| 790 | spin_lock_bh(&sta->lock); |
| 791 | *state = HT_AGG_STATE_IDLE; |
| 792 | sta->ampdu_mlme.addba_req_num[tid] = 0; |
| 793 | kfree(sta->ampdu_mlme.tid_tx[tid]); |
| 794 | sta->ampdu_mlme.tid_tx[tid] = NULL; |
| 795 | spin_unlock_bh(&sta->lock); |
| 796 | |
| 797 | rcu_read_unlock(); |
| 798 | } |
| 799 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb); |
| 800 | |
| 801 | void ieee80211_start_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, |
| 802 | const u8 *ra, u16 tid) |
| 803 | { |
| 804 | struct ieee80211_local *local = hw_to_local(hw); |
| 805 | struct ieee80211_ra_tid *ra_tid; |
| 806 | struct sk_buff *skb = dev_alloc_skb(0); |
| 807 | |
| 808 | if (unlikely(!skb)) { |
| 809 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 810 | if (net_ratelimit()) |
| 811 | printk(KERN_WARNING "%s: Not enough memory, " |
| 812 | "dropping start BA session", skb->dev->name); |
| 813 | #endif |
| 814 | return; |
| 815 | } |
| 816 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; |
| 817 | memcpy(&ra_tid->ra, ra, ETH_ALEN); |
| 818 | ra_tid->tid = tid; |
| 819 | |
| 820 | skb->pkt_type = IEEE80211_ADDBA_MSG; |
| 821 | skb_queue_tail(&local->skb_queue, skb); |
| 822 | tasklet_schedule(&local->tasklet); |
| 823 | } |
| 824 | EXPORT_SYMBOL(ieee80211_start_tx_ba_cb_irqsafe); |
| 825 | |
| 826 | void ieee80211_stop_tx_ba_cb_irqsafe(struct ieee80211_hw *hw, |
| 827 | const u8 *ra, u16 tid) |
| 828 | { |
| 829 | struct ieee80211_local *local = hw_to_local(hw); |
| 830 | struct ieee80211_ra_tid *ra_tid; |
| 831 | struct sk_buff *skb = dev_alloc_skb(0); |
| 832 | |
| 833 | if (unlikely(!skb)) { |
| 834 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 835 | if (net_ratelimit()) |
| 836 | printk(KERN_WARNING "%s: Not enough memory, " |
| 837 | "dropping stop BA session", skb->dev->name); |
| 838 | #endif |
| 839 | return; |
| 840 | } |
| 841 | ra_tid = (struct ieee80211_ra_tid *) &skb->cb; |
| 842 | memcpy(&ra_tid->ra, ra, ETH_ALEN); |
| 843 | ra_tid->tid = tid; |
| 844 | |
| 845 | skb->pkt_type = IEEE80211_DELBA_MSG; |
| 846 | skb_queue_tail(&local->skb_queue, skb); |
| 847 | tasklet_schedule(&local->tasklet); |
| 848 | } |
| 849 | EXPORT_SYMBOL(ieee80211_stop_tx_ba_cb_irqsafe); |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 850 | |
| 851 | /* |
| 852 | * After accepting the AddBA Request we activated a timer, |
| 853 | * resetting it after each frame that arrives from the originator. |
| 854 | * if this timer expires ieee80211_sta_stop_rx_ba_session will be executed. |
| 855 | */ |
| 856 | static void sta_rx_agg_session_timer_expired(unsigned long data) |
| 857 | { |
| 858 | /* not an elegant detour, but there is no choice as the timer passes |
| 859 | * only one argument, and various sta_info are needed here, so init |
| 860 | * flow in sta_info_create gives the TID as data, while the timer_to_id |
| 861 | * array gives the sta through container_of */ |
| 862 | u8 *ptid = (u8 *)data; |
| 863 | u8 *timer_to_id = ptid - *ptid; |
| 864 | struct sta_info *sta = container_of(timer_to_id, struct sta_info, |
| 865 | timer_to_tid[0]); |
| 866 | |
| 867 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 868 | printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid); |
| 869 | #endif |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 870 | ieee80211_sta_stop_rx_ba_session(sta->sdata, sta->sta.addr, |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 871 | (u16)*ptid, WLAN_BACK_TIMER, |
| 872 | WLAN_REASON_QSTA_TIMEOUT); |
| 873 | } |
| 874 | |
| 875 | void ieee80211_process_addba_request(struct ieee80211_local *local, |
| 876 | struct sta_info *sta, |
| 877 | struct ieee80211_mgmt *mgmt, |
| 878 | size_t len) |
| 879 | { |
| 880 | struct ieee80211_hw *hw = &local->hw; |
| 881 | struct ieee80211_conf *conf = &hw->conf; |
| 882 | struct tid_ampdu_rx *tid_agg_rx; |
| 883 | u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status; |
| 884 | u8 dialog_token; |
| 885 | int ret = -EOPNOTSUPP; |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 886 | |
| 887 | /* extract session parameters from addba request frame */ |
| 888 | dialog_token = mgmt->u.action.u.addba_req.dialog_token; |
| 889 | timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout); |
| 890 | start_seq_num = |
| 891 | le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4; |
| 892 | |
| 893 | capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab); |
| 894 | ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1; |
| 895 | tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; |
| 896 | buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6; |
| 897 | |
| 898 | status = WLAN_STATUS_REQUEST_DECLINED; |
| 899 | |
| 900 | /* sanity check for incoming parameters: |
| 901 | * check if configuration can support the BA policy |
| 902 | * and if buffer size does not exceeds max value */ |
| 903 | if (((ba_policy != 1) |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame^] | 904 | && (!(conf->ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA))) |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 905 | || (buf_size > IEEE80211_MAX_AMPDU_BUF)) { |
| 906 | status = WLAN_STATUS_INVALID_QOS_PARAM; |
| 907 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 908 | if (net_ratelimit()) |
| 909 | printk(KERN_DEBUG "AddBA Req with bad params from " |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 910 | "%pM on tid %u. policy %d, buffer size %d\n", |
| 911 | mgmt->sa, tid, ba_policy, |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 912 | buf_size); |
| 913 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 914 | goto end_no_lock; |
| 915 | } |
| 916 | /* determine default buffer size */ |
| 917 | if (buf_size == 0) { |
| 918 | struct ieee80211_supported_band *sband; |
| 919 | |
| 920 | sband = local->hw.wiphy->bands[conf->channel->band]; |
| 921 | buf_size = IEEE80211_MIN_AMPDU_BUF; |
Johannes Berg | d9fe60d | 2008-10-09 12:13:49 +0200 | [diff] [blame^] | 922 | buf_size = buf_size << sband->ht_cap.ampdu_factor; |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | |
| 926 | /* examine state machine */ |
| 927 | spin_lock_bh(&sta->lock); |
| 928 | |
| 929 | if (sta->ampdu_mlme.tid_state_rx[tid] != HT_AGG_STATE_IDLE) { |
| 930 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 931 | if (net_ratelimit()) |
| 932 | printk(KERN_DEBUG "unexpected AddBA Req from " |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 933 | "%pM on tid %u\n", |
| 934 | mgmt->sa, tid); |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 935 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 936 | goto end; |
| 937 | } |
| 938 | |
| 939 | /* prepare A-MPDU MLME for Rx aggregation */ |
| 940 | sta->ampdu_mlme.tid_rx[tid] = |
| 941 | kmalloc(sizeof(struct tid_ampdu_rx), GFP_ATOMIC); |
| 942 | if (!sta->ampdu_mlme.tid_rx[tid]) { |
| 943 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 944 | if (net_ratelimit()) |
| 945 | printk(KERN_ERR "allocate rx mlme to tid %d failed\n", |
| 946 | tid); |
| 947 | #endif |
| 948 | goto end; |
| 949 | } |
| 950 | /* rx timer */ |
| 951 | sta->ampdu_mlme.tid_rx[tid]->session_timer.function = |
| 952 | sta_rx_agg_session_timer_expired; |
| 953 | sta->ampdu_mlme.tid_rx[tid]->session_timer.data = |
| 954 | (unsigned long)&sta->timer_to_tid[tid]; |
| 955 | init_timer(&sta->ampdu_mlme.tid_rx[tid]->session_timer); |
| 956 | |
| 957 | tid_agg_rx = sta->ampdu_mlme.tid_rx[tid]; |
| 958 | |
| 959 | /* prepare reordering buffer */ |
| 960 | tid_agg_rx->reorder_buf = |
| 961 | kmalloc(buf_size * sizeof(struct sk_buff *), GFP_ATOMIC); |
| 962 | if (!tid_agg_rx->reorder_buf) { |
| 963 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 964 | if (net_ratelimit()) |
| 965 | printk(KERN_ERR "can not allocate reordering buffer " |
| 966 | "to tid %d\n", tid); |
| 967 | #endif |
| 968 | kfree(sta->ampdu_mlme.tid_rx[tid]); |
| 969 | goto end; |
| 970 | } |
| 971 | memset(tid_agg_rx->reorder_buf, 0, |
| 972 | buf_size * sizeof(struct sk_buff *)); |
| 973 | |
| 974 | if (local->ops->ampdu_action) |
| 975 | ret = local->ops->ampdu_action(hw, IEEE80211_AMPDU_RX_START, |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 976 | &sta->sta, tid, &start_seq_num); |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 977 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 978 | printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret); |
| 979 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 980 | |
| 981 | if (ret) { |
| 982 | kfree(tid_agg_rx->reorder_buf); |
| 983 | kfree(tid_agg_rx); |
| 984 | sta->ampdu_mlme.tid_rx[tid] = NULL; |
| 985 | goto end; |
| 986 | } |
| 987 | |
| 988 | /* change state and send addba resp */ |
| 989 | sta->ampdu_mlme.tid_state_rx[tid] = HT_AGG_STATE_OPERATIONAL; |
| 990 | tid_agg_rx->dialog_token = dialog_token; |
| 991 | tid_agg_rx->ssn = start_seq_num; |
| 992 | tid_agg_rx->head_seq_num = start_seq_num; |
| 993 | tid_agg_rx->buf_size = buf_size; |
| 994 | tid_agg_rx->timeout = timeout; |
| 995 | tid_agg_rx->stored_mpdu_num = 0; |
| 996 | status = WLAN_STATUS_SUCCESS; |
| 997 | end: |
| 998 | spin_unlock_bh(&sta->lock); |
| 999 | |
| 1000 | end_no_lock: |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 1001 | ieee80211_send_addba_resp(sta->sdata, sta->sta.addr, tid, |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 1002 | dialog_token, status, 1, buf_size, timeout); |
| 1003 | } |
| 1004 | |
| 1005 | void ieee80211_process_addba_resp(struct ieee80211_local *local, |
| 1006 | struct sta_info *sta, |
| 1007 | struct ieee80211_mgmt *mgmt, |
| 1008 | size_t len) |
| 1009 | { |
| 1010 | struct ieee80211_hw *hw = &local->hw; |
| 1011 | u16 capab; |
| 1012 | u16 tid; |
| 1013 | u8 *state; |
| 1014 | |
| 1015 | capab = le16_to_cpu(mgmt->u.action.u.addba_resp.capab); |
| 1016 | tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2; |
| 1017 | |
| 1018 | state = &sta->ampdu_mlme.tid_state_tx[tid]; |
| 1019 | |
| 1020 | spin_lock_bh(&sta->lock); |
| 1021 | |
| 1022 | if (!(*state & HT_ADDBA_REQUESTED_MSK)) { |
| 1023 | spin_unlock_bh(&sta->lock); |
| 1024 | return; |
| 1025 | } |
| 1026 | |
| 1027 | if (mgmt->u.action.u.addba_resp.dialog_token != |
| 1028 | sta->ampdu_mlme.tid_tx[tid]->dialog_token) { |
| 1029 | spin_unlock_bh(&sta->lock); |
| 1030 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 1031 | printk(KERN_DEBUG "wrong addBA response token, tid %d\n", tid); |
| 1032 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 1033 | return; |
| 1034 | } |
| 1035 | |
| 1036 | del_timer_sync(&sta->ampdu_mlme.tid_tx[tid]->addba_resp_timer); |
| 1037 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 1038 | printk(KERN_DEBUG "switched off addBA timer for tid %d \n", tid); |
| 1039 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 1040 | if (le16_to_cpu(mgmt->u.action.u.addba_resp.status) |
| 1041 | == WLAN_STATUS_SUCCESS) { |
| 1042 | *state |= HT_ADDBA_RECEIVED_MSK; |
| 1043 | sta->ampdu_mlme.addba_req_num[tid] = 0; |
| 1044 | |
| 1045 | if (*state == HT_AGG_STATE_OPERATIONAL) |
| 1046 | ieee80211_wake_queue(hw, sta->tid_to_tx_q[tid]); |
| 1047 | |
| 1048 | spin_unlock_bh(&sta->lock); |
| 1049 | } else { |
| 1050 | sta->ampdu_mlme.addba_req_num[tid]++; |
| 1051 | /* this will allow the state check in stop_BA_session */ |
| 1052 | *state = HT_AGG_STATE_OPERATIONAL; |
| 1053 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 1054 | ieee80211_stop_tx_ba_session(hw, sta->sta.addr, tid, |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 1055 | WLAN_BACK_INITIATOR); |
| 1056 | } |
| 1057 | } |
| 1058 | |
| 1059 | void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata, |
| 1060 | struct sta_info *sta, |
| 1061 | struct ieee80211_mgmt *mgmt, size_t len) |
| 1062 | { |
| 1063 | struct ieee80211_local *local = sdata->local; |
| 1064 | u16 tid, params; |
| 1065 | u16 initiator; |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 1066 | |
| 1067 | params = le16_to_cpu(mgmt->u.action.u.delba.params); |
| 1068 | tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12; |
| 1069 | initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11; |
| 1070 | |
| 1071 | #ifdef CONFIG_MAC80211_HT_DEBUG |
| 1072 | if (net_ratelimit()) |
Johannes Berg | 0c68ae26 | 2008-10-27 15:56:10 -0700 | [diff] [blame] | 1073 | printk(KERN_DEBUG "delba from %pM (%s) tid %d reason code %d\n", |
| 1074 | mgmt->sa, initiator ? "initiator" : "recipient", tid, |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 1075 | mgmt->u.action.u.delba.reason_code); |
| 1076 | #endif /* CONFIG_MAC80211_HT_DEBUG */ |
| 1077 | |
| 1078 | if (initiator == WLAN_BACK_INITIATOR) |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 1079 | ieee80211_sta_stop_rx_ba_session(sdata, sta->sta.addr, tid, |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 1080 | WLAN_BACK_INITIATOR, 0); |
| 1081 | else { /* WLAN_BACK_RECIPIENT */ |
| 1082 | spin_lock_bh(&sta->lock); |
| 1083 | sta->ampdu_mlme.tid_state_tx[tid] = |
| 1084 | HT_AGG_STATE_OPERATIONAL; |
| 1085 | spin_unlock_bh(&sta->lock); |
Johannes Berg | 17741cd | 2008-09-11 00:02:02 +0200 | [diff] [blame] | 1086 | ieee80211_stop_tx_ba_session(&local->hw, sta->sta.addr, tid, |
Johannes Berg | de1ede7 | 2008-09-09 14:42:50 +0200 | [diff] [blame] | 1087 | WLAN_BACK_RECIPIENT); |
| 1088 | } |
| 1089 | } |