ht.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 
00016 #include <linux/ieee80211.h>
00017 #include <linux/export.h>
00018 #include <net/mac80211.h>
00019 #include "ieee80211_i.h"
00020 #include "rate.h"
00021 
00022 static void __check_htcap_disable(struct ieee80211_sub_if_data *sdata,
00023                                   struct ieee80211_sta_ht_cap *ht_cap,
00024                                   u16 flag)
00025 {
00026         __le16 le_flag = cpu_to_le16(flag);
00027         if (sdata->u.mgd.ht_capa_mask.cap_info & le_flag) {
00028                 if (!(sdata->u.mgd.ht_capa.cap_info & le_flag))
00029                         ht_cap->cap &= ~flag;
00030         }
00031 }
00032 
00033 void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
00034                                      struct ieee80211_sta_ht_cap *ht_cap)
00035 {
00036         u8 *scaps = (u8 *)(&sdata->u.mgd.ht_capa.mcs.rx_mask);
00037         u8 *smask = (u8 *)(&sdata->u.mgd.ht_capa_mask.mcs.rx_mask);
00038         int i;
00039 
00040         if (sdata->vif.type != NL80211_IFTYPE_STATION) {
00041                 /* AP interfaces call this code when adding new stations,
00042                  * so just silently ignore non station interfaces.
00043                  */
00044                 return;
00045         }
00046 
00047         /* NOTE:  If you add more over-rides here, update register_hw
00048          * ht_capa_mod_msk logic in main.c as well.
00049          * And, if this method can ever change ht_cap.ht_supported, fix
00050          * the check in ieee80211_add_ht_ie.
00051          */
00052 
00053         /* check for HT over-rides, MCS rates first. */
00054         for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
00055                 u8 m = smask[i];
00056                 ht_cap->mcs.rx_mask[i] &= ~m; /* turn off all masked bits */
00057                 /* Add back rates that are supported */
00058                 ht_cap->mcs.rx_mask[i] |= (m & scaps[i]);
00059         }
00060 
00061         /* Force removal of HT-40 capabilities? */
00062         __check_htcap_disable(sdata, ht_cap, IEEE80211_HT_CAP_SUP_WIDTH_20_40);
00063         __check_htcap_disable(sdata, ht_cap, IEEE80211_HT_CAP_SGI_40);
00064 
00065         /* Allow user to disable the max-AMSDU bit. */
00066         __check_htcap_disable(sdata, ht_cap, IEEE80211_HT_CAP_MAX_AMSDU);
00067 
00068         /* Allow user to decrease AMPDU factor */
00069         if (sdata->u.mgd.ht_capa_mask.ampdu_params_info &
00070             IEEE80211_HT_AMPDU_PARM_FACTOR) {
00071                 u8 n = sdata->u.mgd.ht_capa.ampdu_params_info
00072                         & IEEE80211_HT_AMPDU_PARM_FACTOR;
00073                 if (n < ht_cap->ampdu_factor)
00074                         ht_cap->ampdu_factor = n;
00075         }
00076 
00077         /* Allow the user to increase AMPDU density. */
00078         if (sdata->u.mgd.ht_capa_mask.ampdu_params_info &
00079             IEEE80211_HT_AMPDU_PARM_DENSITY) {
00080                 u8 n = (sdata->u.mgd.ht_capa.ampdu_params_info &
00081                         IEEE80211_HT_AMPDU_PARM_DENSITY)
00082                         >> IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT;
00083                 if (n > ht_cap->ampdu_density)
00084                         ht_cap->ampdu_density = n;
00085         }
00086 }
00087 
00088 
00089 void ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data *sdata,
00090                                        struct ieee80211_supported_band *sband,
00091                                        struct ieee80211_ht_cap *ht_cap_ie,
00092                                        struct ieee80211_sta_ht_cap *ht_cap)
00093 {
00094         u8 ampdu_info, tx_mcs_set_cap;
00095         int i, max_tx_streams;
00096 
00097         BUG_ON(!ht_cap);
00098 
00099         memset(ht_cap, 0, sizeof(*ht_cap));
00100 
00101         if (!ht_cap_ie || !sband->ht_cap.ht_supported)
00102                 return;
00103 
00104         ht_cap->ht_supported = true;
00105 
00106         /*
00107          * The bits listed in this expression should be
00108          * the same for the peer and us, if the station
00109          * advertises more then we can't use those thus
00110          * we mask them out.
00111          */
00112         ht_cap->cap = le16_to_cpu(ht_cap_ie->cap_info) &
00113                 (sband->ht_cap.cap |
00114                  ~(IEEE80211_HT_CAP_LDPC_CODING |
00115                    IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
00116                    IEEE80211_HT_CAP_GRN_FLD |
00117                    IEEE80211_HT_CAP_SGI_20 |
00118                    IEEE80211_HT_CAP_SGI_40 |
00119                    IEEE80211_HT_CAP_DSSSCCK40));
00120         /*
00121          * The STBC bits are asymmetric -- if we don't have
00122          * TX then mask out the peer's RX and vice versa.
00123          */
00124         if (!(sband->ht_cap.cap & IEEE80211_HT_CAP_TX_STBC))
00125                 ht_cap->cap &= ~IEEE80211_HT_CAP_RX_STBC;
00126         if (!(sband->ht_cap.cap & IEEE80211_HT_CAP_RX_STBC))
00127                 ht_cap->cap &= ~IEEE80211_HT_CAP_TX_STBC;
00128 
00129         ampdu_info = ht_cap_ie->ampdu_params_info;
00130         ht_cap->ampdu_factor =
00131                 ampdu_info & IEEE80211_HT_AMPDU_PARM_FACTOR;
00132         ht_cap->ampdu_density =
00133                 (ampdu_info & IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
00134 
00135         /* own MCS TX capabilities */
00136         tx_mcs_set_cap = sband->ht_cap.mcs.tx_params;
00137 
00138         /* Copy peer MCS TX capabilities, the driver might need them. */
00139         ht_cap->mcs.tx_params = ht_cap_ie->mcs.tx_params;
00140 
00141         /* can we TX with MCS rates? */
00142         if (!(tx_mcs_set_cap & IEEE80211_HT_MCS_TX_DEFINED))
00143                 return;
00144 
00145         /* Counting from 0, therefore +1 */
00146         if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_RX_DIFF)
00147                 max_tx_streams =
00148                         ((tx_mcs_set_cap & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
00149                                 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
00150         else
00151                 max_tx_streams = IEEE80211_HT_MCS_TX_MAX_STREAMS;
00152 
00153         /*
00154          * 802.11n-2009 20.3.5 / 20.6 says:
00155          * - indices 0 to 7 and 32 are single spatial stream
00156          * - 8 to 31 are multiple spatial streams using equal modulation
00157          *   [8..15 for two streams, 16..23 for three and 24..31 for four]
00158          * - remainder are multiple spatial streams using unequal modulation
00159          */
00160         for (i = 0; i < max_tx_streams; i++)
00161                 ht_cap->mcs.rx_mask[i] =
00162                         sband->ht_cap.mcs.rx_mask[i] & ht_cap_ie->mcs.rx_mask[i];
00163 
00164         if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION)
00165                 for (i = IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE;
00166                      i < IEEE80211_HT_MCS_MASK_LEN; i++)
00167                         ht_cap->mcs.rx_mask[i] =
00168                                 sband->ht_cap.mcs.rx_mask[i] &
00169                                         ht_cap_ie->mcs.rx_mask[i];
00170 
00171         /* handle MCS rate 32 too */
00172         if (sband->ht_cap.mcs.rx_mask[32/8] & ht_cap_ie->mcs.rx_mask[32/8] & 1)
00173                 ht_cap->mcs.rx_mask[32/8] |= 1;
00174 
00175         /*
00176          * If user has specified capability over-rides, take care
00177          * of that here.
00178          */
00179         ieee80211_apply_htcap_overrides(sdata, ht_cap);
00180 }
00181 
00182 void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta, bool tx)
00183 {
00184         int i;
00185 
00186         cancel_work_sync(&sta->ampdu_mlme.work);
00187 
00188         for (i = 0; i <  STA_TID_NUM; i++) {
00189                 __ieee80211_stop_tx_ba_session(sta, i, WLAN_BACK_INITIATOR, tx);
00190                 __ieee80211_stop_rx_ba_session(sta, i, WLAN_BACK_RECIPIENT,
00191                                                WLAN_REASON_QSTA_LEAVE_QBSS, tx);
00192         }
00193 }
00194 
00195 void ieee80211_ba_session_work(struct work_struct *work)
00196 {
00197         struct sta_info *sta =
00198                 container_of(work, struct sta_info, ampdu_mlme.work);
00199         struct tid_ampdu_tx *tid_tx;
00200         int tid;
00201 
00202         /*
00203          * When this flag is set, new sessions should be
00204          * blocked, and existing sessions will be torn
00205          * down by the code that set the flag, so this
00206          * need not run.
00207          */
00208         if (test_sta_flag(sta, WLAN_STA_BLOCK_BA))
00209                 return;
00210 
00211         mutex_lock(&sta->ampdu_mlme.mtx);
00212         for (tid = 0; tid < STA_TID_NUM; tid++) {
00213                 if (test_and_clear_bit(tid, sta->ampdu_mlme.tid_rx_timer_expired))
00214                         ___ieee80211_stop_rx_ba_session(
00215                                 sta, tid, WLAN_BACK_RECIPIENT,
00216                                 WLAN_REASON_QSTA_TIMEOUT, true);
00217 
00218                 if (test_and_clear_bit(tid,
00219                                        sta->ampdu_mlme.tid_rx_stop_requested))
00220                         ___ieee80211_stop_rx_ba_session(
00221                                 sta, tid, WLAN_BACK_RECIPIENT,
00222                                 WLAN_REASON_UNSPECIFIED, true);
00223 
00224                 tid_tx = sta->ampdu_mlme.tid_start_tx[tid];
00225                 if (tid_tx) {
00226                         /*
00227                          * Assign it over to the normal tid_tx array
00228                          * where it "goes live".
00229                          */
00230                         spin_lock_bh(&sta->lock);
00231 
00232                         sta->ampdu_mlme.tid_start_tx[tid] = NULL;
00233                         /* could there be a race? */
00234                         if (sta->ampdu_mlme.tid_tx[tid])
00235                                 kfree(tid_tx);
00236                         else
00237                                 ieee80211_assign_tid_tx(sta, tid, tid_tx);
00238                         spin_unlock_bh(&sta->lock);
00239 
00240                         ieee80211_tx_ba_session_handle_start(sta, tid);
00241                         continue;
00242                 }
00243 
00244                 tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
00245                 if (tid_tx && test_and_clear_bit(HT_AGG_STATE_WANT_STOP,
00246                                                  &tid_tx->state))
00247                         ___ieee80211_stop_tx_ba_session(sta, tid,
00248                                                         WLAN_BACK_INITIATOR,
00249                                                         true);
00250         }
00251         mutex_unlock(&sta->ampdu_mlme.mtx);
00252 }
00253 
00254 void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
00255                           const u8 *da, u16 tid,
00256                           u16 initiator, u16 reason_code)
00257 {
00258         struct ieee80211_local *local = sdata->local;
00259         struct sk_buff *skb;
00260         struct ieee80211_mgmt *mgmt;
00261         u16 params;
00262 
00263         skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
00264         if (!skb)
00265                 return;
00266 
00267         skb_reserve(skb, local->hw.extra_tx_headroom);
00268         mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24);
00269         memset(mgmt, 0, 24);
00270         memcpy(mgmt->da, da, ETH_ALEN);
00271         memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
00272         if (sdata->vif.type == NL80211_IFTYPE_AP ||
00273             sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
00274             sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
00275                 memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
00276         else if (sdata->vif.type == NL80211_IFTYPE_STATION)
00277                 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
00278         else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
00279                 memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
00280 
00281         mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
00282                                           IEEE80211_STYPE_ACTION);
00283 
00284         skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
00285 
00286         mgmt->u.action.category = WLAN_CATEGORY_BACK;
00287         mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
00288         params = (u16)(initiator << 11);        /* bit 11 initiator */
00289         params |= (u16)(tid << 12);             /* bit 15:12 TID number */
00290 
00291         mgmt->u.action.u.delba.params = cpu_to_le16(params);
00292         mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
00293 
00294         ieee80211_tx_skb_tid(sdata, skb, tid);
00295 }
00296 
00297 void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
00298                              struct sta_info *sta,
00299                              struct ieee80211_mgmt *mgmt, size_t len)
00300 {
00301         u16 tid, params;
00302         u16 initiator;
00303 
00304         params = le16_to_cpu(mgmt->u.action.u.delba.params);
00305         tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
00306         initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
00307 
00308 #ifdef CONFIG_MAC80211_HT_DEBUG
00309         net_dbg_ratelimited("delba from %pM (%s) tid %d reason code %d\n",
00310                             mgmt->sa, initiator ? "initiator" : "recipient",
00311                             tid,
00312                             le16_to_cpu(mgmt->u.action.u.delba.reason_code));
00313 #endif /* CONFIG_MAC80211_HT_DEBUG */
00314 
00315         if (initiator == WLAN_BACK_INITIATOR)
00316                 __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_INITIATOR, 0,
00317                                                true);
00318         else
00319                 __ieee80211_stop_tx_ba_session(sta, tid, WLAN_BACK_RECIPIENT,
00320                                                true);
00321 }
00322 
00323 int ieee80211_send_smps_action(struct ieee80211_sub_if_data *sdata,
00324                                enum ieee80211_smps_mode smps, const u8 *da,
00325                                const u8 *bssid)
00326 {
00327         struct ieee80211_local *local = sdata->local;
00328         struct sk_buff *skb;
00329         struct ieee80211_mgmt *action_frame;
00330 
00331         /* 27 = header + category + action + smps mode */
00332         skb = dev_alloc_skb(27 + local->hw.extra_tx_headroom);
00333         if (!skb)
00334                 return -ENOMEM;
00335 
00336         skb_reserve(skb, local->hw.extra_tx_headroom);
00337         action_frame = (void *)skb_put(skb, 27);
00338         memcpy(action_frame->da, da, ETH_ALEN);
00339         memcpy(action_frame->sa, sdata->dev->dev_addr, ETH_ALEN);
00340         memcpy(action_frame->bssid, bssid, ETH_ALEN);
00341         action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
00342                                                   IEEE80211_STYPE_ACTION);
00343         action_frame->u.action.category = WLAN_CATEGORY_HT;
00344         action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
00345         switch (smps) {
00346         case IEEE80211_SMPS_AUTOMATIC:
00347         case IEEE80211_SMPS_NUM_MODES:
00348                 WARN_ON(1);
00349         case IEEE80211_SMPS_OFF:
00350                 action_frame->u.action.u.ht_smps.smps_control =
00351                                 WLAN_HT_SMPS_CONTROL_DISABLED;
00352                 break;
00353         case IEEE80211_SMPS_STATIC:
00354                 action_frame->u.action.u.ht_smps.smps_control =
00355                                 WLAN_HT_SMPS_CONTROL_STATIC;
00356                 break;
00357         case IEEE80211_SMPS_DYNAMIC:
00358                 action_frame->u.action.u.ht_smps.smps_control =
00359                                 WLAN_HT_SMPS_CONTROL_DYNAMIC;
00360                 break;
00361         }
00362 
00363         /* we'll do more on status of this frame */
00364         IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
00365         ieee80211_tx_skb(sdata, skb);
00366 
00367         return 0;
00368 }
00369 
00370 void ieee80211_request_smps_work(struct work_struct *work)
00371 {
00372         struct ieee80211_sub_if_data *sdata =
00373                 container_of(work, struct ieee80211_sub_if_data,
00374                              u.mgd.request_smps_work);
00375 
00376         mutex_lock(&sdata->u.mgd.mtx);
00377         __ieee80211_request_smps(sdata, sdata->u.mgd.driver_smps_mode);
00378         mutex_unlock(&sdata->u.mgd.mtx);
00379 }
00380 
00381 void ieee80211_request_smps(struct ieee80211_vif *vif,
00382                             enum ieee80211_smps_mode smps_mode)
00383 {
00384         struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
00385 
00386         if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
00387                 return;
00388 
00389         if (WARN_ON(smps_mode == IEEE80211_SMPS_OFF))
00390                 smps_mode = IEEE80211_SMPS_AUTOMATIC;
00391 
00392         sdata->u.mgd.driver_smps_mode = smps_mode;
00393 
00394         ieee80211_queue_work(&sdata->local->hw,
00395                              &sdata->u.mgd.request_smps_work);
00396 }
00397 /* this might change ... don't want non-open drivers using it */
00398 EXPORT_SYMBOL_GPL(ieee80211_request_smps);


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:10