agg-rx.c
Go to the documentation of this file.
00001 /*
00002  * HT handling
00003  *
00004  * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
00005  * Copyright 2002-2005, Instant802 Networks, Inc.
00006  * Copyright 2005-2006, Devicescape Software, Inc.
00007  * Copyright 2006-2007  Jiri Benc <jbenc@suse.cz>
00008  * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
00009  * Copyright 2007-2010, Intel Corporation
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License version 2 as
00013  * published by the Free Software Foundation.
00014  */
00015 
00039 #include <linux/ieee80211.h>
00040 #include <linux/slab.h>
00041 #include <linux/export.h>
00042 #include <net/mac80211.h>
00043 #include "ieee80211_i.h"
00044 #include "driver-ops.h"
00045 
00046 static void ieee80211_free_tid_rx(struct rcu_head *h)
00047 {
00048         struct tid_ampdu_rx *tid_rx =
00049                 container_of(h, struct tid_ampdu_rx, rcu_head);
00050         int i;
00051 
00052         del_timer_sync(&tid_rx->reorder_timer);
00053 
00054         for (i = 0; i < tid_rx->buf_size; i++)
00055                 dev_kfree_skb(tid_rx->reorder_buf[i]);
00056         kfree(tid_rx->reorder_buf);
00057         kfree(tid_rx->reorder_time);
00058         kfree(tid_rx);
00059 }
00060 
00061 void ___ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
00062                                      u16 initiator, u16 reason, bool tx)
00063 {
00064         struct ieee80211_local *local = sta->local;
00065         struct tid_ampdu_rx *tid_rx;
00066 
00067         lockdep_assert_held(&sta->ampdu_mlme.mtx);
00068 
00069         tid_rx = rcu_dereference_protected(sta->ampdu_mlme.tid_rx[tid],
00070                                         lockdep_is_held(&sta->ampdu_mlme.mtx));
00071 
00072         if (!tid_rx)
00073                 return;
00074 
00075         RCU_INIT_POINTER(sta->ampdu_mlme.tid_rx[tid], NULL);
00076 
00077 #ifdef CONFIG_MAC80211_HT_DEBUG
00078         printk(KERN_DEBUG
00079                "Rx BA session stop requested for %pM tid %u %s reason: %d\n",
00080                sta->sta.addr, tid,
00081                initiator == WLAN_BACK_RECIPIENT ? "recipient" : "inititator",
00082                (int)reason);
00083 #endif /* CONFIG_MAC80211_HT_DEBUG */
00084 
00085         if (drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_STOP,
00086                              &sta->sta, tid, NULL, 0))
00087                 printk(KERN_DEBUG "HW problem - can not stop rx "
00088                                 "aggregation for tid %d\n", tid);
00089 
00090         /* check if this is a self generated aggregation halt */
00091         if (initiator == WLAN_BACK_RECIPIENT && tx)
00092                 ieee80211_send_delba(sta->sdata, sta->sta.addr,
00093                                      tid, WLAN_BACK_RECIPIENT, reason);
00094 
00095         del_timer_sync(&tid_rx->session_timer);
00096 
00097         call_rcu(&tid_rx->rcu_head, ieee80211_free_tid_rx);
00098 }
00099 
00100 void __ieee80211_stop_rx_ba_session(struct sta_info *sta, u16 tid,
00101                                     u16 initiator, u16 reason, bool tx)
00102 {
00103         mutex_lock(&sta->ampdu_mlme.mtx);
00104         ___ieee80211_stop_rx_ba_session(sta, tid, initiator, reason, tx);
00105         mutex_unlock(&sta->ampdu_mlme.mtx);
00106 }
00107 
00108 void ieee80211_stop_rx_ba_session(struct ieee80211_vif *vif, u16 ba_rx_bitmap,
00109                                   const u8 *addr)
00110 {
00111         struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
00112         struct sta_info *sta;
00113         int i;
00114 
00115         rcu_read_lock();
00116         sta = sta_info_get_bss(sdata, addr);
00117         if (!sta) {
00118                 rcu_read_unlock();
00119                 return;
00120         }
00121 
00122         for (i = 0; i < STA_TID_NUM; i++)
00123                 if (ba_rx_bitmap & BIT(i))
00124                         set_bit(i, sta->ampdu_mlme.tid_rx_stop_requested);
00125 
00126         ieee80211_queue_work(&sta->local->hw, &sta->ampdu_mlme.work);
00127         rcu_read_unlock();
00128 }
00129 EXPORT_SYMBOL(ieee80211_stop_rx_ba_session);
00130 
00131 /*
00132  * After accepting the AddBA Request we activated a timer,
00133  * resetting it after each frame that arrives from the originator.
00134  */
00135 static void sta_rx_agg_session_timer_expired(unsigned long data)
00136 {
00137         /* not an elegant detour, but there is no choice as the timer passes
00138          * only one argument, and various sta_info are needed here, so init
00139          * flow in sta_info_create gives the TID as data, while the timer_to_id
00140          * array gives the sta through container_of */
00141         u8 *ptid = (u8 *)data;
00142         u8 *timer_to_id = ptid - *ptid;
00143         struct sta_info *sta = container_of(timer_to_id, struct sta_info,
00144                                          timer_to_tid[0]);
00145         struct tid_ampdu_rx *tid_rx;
00146         unsigned long timeout;
00147 
00148         rcu_read_lock();
00149         tid_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[*ptid]);
00150         if (!tid_rx) {
00151                 rcu_read_unlock();
00152                 return;
00153         }
00154 
00155         timeout = tid_rx->last_rx + TU_TO_JIFFIES(tid_rx->timeout);
00156         if (time_is_after_jiffies(timeout)) {
00157                 mod_timer(&tid_rx->session_timer, timeout);
00158                 rcu_read_unlock();
00159                 return;
00160         }
00161         rcu_read_unlock();
00162 
00163 #ifdef CONFIG_MAC80211_HT_DEBUG
00164         printk(KERN_DEBUG "rx session timer expired on tid %d\n", (u16)*ptid);
00165 #endif
00166         set_bit(*ptid, sta->ampdu_mlme.tid_rx_timer_expired);
00167         ieee80211_queue_work(&sta->local->hw, &sta->ampdu_mlme.work);
00168 }
00169 
00170 static void sta_rx_agg_reorder_timer_expired(unsigned long data)
00171 {
00172         u8 *ptid = (u8 *)data;
00173         u8 *timer_to_id = ptid - *ptid;
00174         struct sta_info *sta = container_of(timer_to_id, struct sta_info,
00175                         timer_to_tid[0]);
00176 
00177         rcu_read_lock();
00178         ieee80211_release_reorder_timeout(sta, *ptid);
00179         rcu_read_unlock();
00180 }
00181 
00182 static void ieee80211_send_addba_resp(struct ieee80211_sub_if_data *sdata, u8 *da, u16 tid,
00183                                       u8 dialog_token, u16 status, u16 policy,
00184                                       u16 buf_size, u16 timeout)
00185 {
00186         struct ieee80211_local *local = sdata->local;
00187         struct sk_buff *skb;
00188         struct ieee80211_mgmt *mgmt;
00189         u16 capab;
00190 
00191         skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
00192         if (!skb)
00193                 return;
00194 
00195         skb_reserve(skb, local->hw.extra_tx_headroom);
00196         mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
00197         memset(mgmt, 0, 24);
00198         memcpy(mgmt->da, da, ETH_ALEN);
00199         memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
00200         if (sdata->vif.type == NL80211_IFTYPE_AP ||
00201             sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
00202             sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
00203                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
00204         else if (sdata->vif.type == NL80211_IFTYPE_STATION)
00205                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
00206         else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
00207                 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
00208 
00209         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
00210                                           IEEE80211_STYPE_ACTION);
00211 
00212         skb_put(skb, 1 + sizeof(mgmt->u.action.u.addba_resp));
00213         mgmt->u.action.category = WLAN_CATEGORY_BACK;
00214         mgmt->u.action.u.addba_resp.action_code = WLAN_ACTION_ADDBA_RESP;
00215         mgmt->u.action.u.addba_resp.dialog_token = dialog_token;
00216 
00217         capab = (u16)(policy << 1);     /* bit 1 aggregation policy */
00218         capab |= (u16)(tid << 2);       /* bit 5:2 TID number */
00219         capab |= (u16)(buf_size << 6);  /* bit 15:6 max size of aggregation */
00220 
00221         mgmt->u.action.u.addba_resp.capab = cpu_to_le16(capab);
00222         mgmt->u.action.u.addba_resp.timeout = cpu_to_le16(timeout);
00223         mgmt->u.action.u.addba_resp.status = cpu_to_le16(status);
00224 
00225         ieee80211_tx_skb(sdata, skb);
00226 }
00227 
00228 void ieee80211_process_addba_request(struct ieee80211_local *local,
00229                                      struct sta_info *sta,
00230                                      struct ieee80211_mgmt *mgmt,
00231                                      size_t len)
00232 {
00233         struct tid_ampdu_rx *tid_agg_rx;
00234         u16 capab, tid, timeout, ba_policy, buf_size, start_seq_num, status;
00235         u8 dialog_token;
00236         int ret = -EOPNOTSUPP;
00237 
00238         /* extract session parameters from addba request frame */
00239         dialog_token = mgmt->u.action.u.addba_req.dialog_token;
00240         timeout = le16_to_cpu(mgmt->u.action.u.addba_req.timeout);
00241         start_seq_num =
00242                 le16_to_cpu(mgmt->u.action.u.addba_req.start_seq_num) >> 4;
00243 
00244         capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
00245         ba_policy = (capab & IEEE80211_ADDBA_PARAM_POLICY_MASK) >> 1;
00246         tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
00247         buf_size = (capab & IEEE80211_ADDBA_PARAM_BUF_SIZE_MASK) >> 6;
00248 
00249         status = WLAN_STATUS_REQUEST_DECLINED;
00250 
00251         if (test_sta_flag(sta, WLAN_STA_BLOCK_BA)) {
00252 #ifdef CONFIG_MAC80211_HT_DEBUG
00253                 printk(KERN_DEBUG "Suspend in progress. "
00254                        "Denying ADDBA request\n");
00255 #endif
00256                 goto end_no_lock;
00257         }
00258 
00259         /* sanity check for incoming parameters:
00260          * check if configuration can support the BA policy
00261          * and if buffer size does not exceeds max value */
00262         /* XXX: check own ht delayed BA capability?? */
00263         if (((ba_policy != 1) &&
00264              (!(sta->sta.ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA))) ||
00265             (buf_size > IEEE80211_MAX_AMPDU_BUF)) {
00266                 status = WLAN_STATUS_INVALID_QOS_PARAM;
00267 #ifdef CONFIG_MAC80211_HT_DEBUG
00268                 net_dbg_ratelimited("AddBA Req with bad params from %pM on tid %u. policy %d, buffer size %d\n",
00269                                     mgmt->sa, tid, ba_policy, buf_size);
00270 #endif /* CONFIG_MAC80211_HT_DEBUG */
00271                 goto end_no_lock;
00272         }
00273         /* determine default buffer size */
00274         if (buf_size == 0)
00275                 buf_size = IEEE80211_MAX_AMPDU_BUF;
00276 
00277         /* make sure the size doesn't exceed the maximum supported by the hw */
00278         if (buf_size > local->hw.max_rx_aggregation_subframes)
00279                 buf_size = local->hw.max_rx_aggregation_subframes;
00280 
00281         /* examine state machine */
00282         mutex_lock(&sta->ampdu_mlme.mtx);
00283 
00284         if (sta->ampdu_mlme.tid_rx[tid]) {
00285 #ifdef CONFIG_MAC80211_HT_DEBUG
00286                 net_dbg_ratelimited("unexpected AddBA Req from %pM on tid %u\n",
00287                                     mgmt->sa, tid);
00288 #endif /* CONFIG_MAC80211_HT_DEBUG */
00289 
00290                 /* delete existing Rx BA session on the same tid */
00291                 ___ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_RECIPIENT,
00292                                                 WLAN_STATUS_UNSPECIFIED_QOS,
00293                                                 false);
00294         }
00295 
00296         /* prepare A-MPDU MLME for Rx aggregation */
00297         tid_agg_rx = kmalloc(sizeof(struct tid_ampdu_rx), GFP_KERNEL);
00298         if (!tid_agg_rx)
00299                 goto end;
00300 
00301         spin_lock_init(&tid_agg_rx->reorder_lock);
00302 
00303         /* rx timer */
00304         tid_agg_rx->session_timer.function = sta_rx_agg_session_timer_expired;
00305         tid_agg_rx->session_timer.data = (unsigned long)&sta->timer_to_tid[tid];
00306         init_timer_deferrable(&tid_agg_rx->session_timer);
00307 
00308         /* rx reorder timer */
00309         tid_agg_rx->reorder_timer.function = sta_rx_agg_reorder_timer_expired;
00310         tid_agg_rx->reorder_timer.data = (unsigned long)&sta->timer_to_tid[tid];
00311         init_timer(&tid_agg_rx->reorder_timer);
00312 
00313         /* prepare reordering buffer */
00314         tid_agg_rx->reorder_buf =
00315                 kcalloc(buf_size, sizeof(struct sk_buff *), GFP_KERNEL);
00316         tid_agg_rx->reorder_time =
00317                 kcalloc(buf_size, sizeof(unsigned long), GFP_KERNEL);
00318         if (!tid_agg_rx->reorder_buf || !tid_agg_rx->reorder_time) {
00319                 kfree(tid_agg_rx->reorder_buf);
00320                 kfree(tid_agg_rx->reorder_time);
00321                 kfree(tid_agg_rx);
00322                 goto end;
00323         }
00324 
00325         ret = drv_ampdu_action(local, sta->sdata, IEEE80211_AMPDU_RX_START,
00326                                &sta->sta, tid, &start_seq_num, 0);
00327 #ifdef CONFIG_MAC80211_HT_DEBUG
00328         printk(KERN_DEBUG "Rx A-MPDU request on tid %d result %d\n", tid, ret);
00329 #endif /* CONFIG_MAC80211_HT_DEBUG */
00330 
00331         if (ret) {
00332                 kfree(tid_agg_rx->reorder_buf);
00333                 kfree(tid_agg_rx->reorder_time);
00334                 kfree(tid_agg_rx);
00335                 goto end;
00336         }
00337 
00338         /* update data */
00339         tid_agg_rx->dialog_token = dialog_token;
00340         tid_agg_rx->ssn = start_seq_num;
00341         tid_agg_rx->head_seq_num = start_seq_num;
00342         tid_agg_rx->buf_size = buf_size;
00343         tid_agg_rx->timeout = timeout;
00344         tid_agg_rx->stored_mpdu_num = 0;
00345         status = WLAN_STATUS_SUCCESS;
00346 
00347         /* activate it for RX */
00348         rcu_assign_pointer(sta->ampdu_mlme.tid_rx[tid], tid_agg_rx);
00349 
00350         if (timeout) {
00351                 mod_timer(&tid_agg_rx->session_timer, TU_TO_EXP_TIME(timeout));
00352                 tid_agg_rx->last_rx = jiffies;
00353         }
00354 
00355 end:
00356         mutex_unlock(&sta->ampdu_mlme.mtx);
00357 
00358 end_no_lock:
00359         ieee80211_send_addba_resp(sta->sdata, sta->sta.addr, tid,
00360                                   dialog_token, status, 1, buf_size, timeout);
00361 }


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Fri Jan 3 2014 12:07:54