Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * HT handling
0004  *
0005  * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi>
0006  * Copyright 2002-2005, Instant802 Networks, Inc.
0007  * Copyright 2005-2006, Devicescape Software, Inc.
0008  * Copyright 2006-2007  Jiri Benc <jbenc@suse.cz>
0009  * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
0010  * Copyright 2007-2010, Intel Corporation
0011  * Copyright 2017   Intel Deutschland GmbH
0012  * Copyright(c) 2020-2022 Intel Corporation
0013  */
0014 
0015 #include <linux/ieee80211.h>
0016 #include <linux/export.h>
0017 #include <net/mac80211.h>
0018 #include "ieee80211_i.h"
0019 #include "rate.h"
0020 
0021 static void __check_htcap_disable(struct ieee80211_ht_cap *ht_capa,
0022                   struct ieee80211_ht_cap *ht_capa_mask,
0023                   struct ieee80211_sta_ht_cap *ht_cap,
0024                   u16 flag)
0025 {
0026     __le16 le_flag = cpu_to_le16(flag);
0027     if (ht_capa_mask->cap_info & le_flag) {
0028         if (!(ht_capa->cap_info & le_flag))
0029             ht_cap->cap &= ~flag;
0030     }
0031 }
0032 
0033 static void __check_htcap_enable(struct ieee80211_ht_cap *ht_capa,
0034                   struct ieee80211_ht_cap *ht_capa_mask,
0035                   struct ieee80211_sta_ht_cap *ht_cap,
0036                   u16 flag)
0037 {
0038     __le16 le_flag = cpu_to_le16(flag);
0039 
0040     if ((ht_capa_mask->cap_info & le_flag) &&
0041         (ht_capa->cap_info & le_flag))
0042         ht_cap->cap |= flag;
0043 }
0044 
0045 void ieee80211_apply_htcap_overrides(struct ieee80211_sub_if_data *sdata,
0046                      struct ieee80211_sta_ht_cap *ht_cap)
0047 {
0048     struct ieee80211_ht_cap *ht_capa, *ht_capa_mask;
0049     u8 *scaps, *smask;
0050     int i;
0051 
0052     if (!ht_cap->ht_supported)
0053         return;
0054 
0055     switch (sdata->vif.type) {
0056     case NL80211_IFTYPE_STATION:
0057         ht_capa = &sdata->u.mgd.ht_capa;
0058         ht_capa_mask = &sdata->u.mgd.ht_capa_mask;
0059         break;
0060     case NL80211_IFTYPE_ADHOC:
0061         ht_capa = &sdata->u.ibss.ht_capa;
0062         ht_capa_mask = &sdata->u.ibss.ht_capa_mask;
0063         break;
0064     default:
0065         WARN_ON_ONCE(1);
0066         return;
0067     }
0068 
0069     scaps = (u8 *)(&ht_capa->mcs.rx_mask);
0070     smask = (u8 *)(&ht_capa_mask->mcs.rx_mask);
0071 
0072     /* NOTE:  If you add more over-rides here, update register_hw
0073      * ht_capa_mod_mask logic in main.c as well.
0074      * And, if this method can ever change ht_cap.ht_supported, fix
0075      * the check in ieee80211_add_ht_ie.
0076      */
0077 
0078     /* check for HT over-rides, MCS rates first. */
0079     for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
0080         u8 m = smask[i];
0081         ht_cap->mcs.rx_mask[i] &= ~m; /* turn off all masked bits */
0082         /* Add back rates that are supported */
0083         ht_cap->mcs.rx_mask[i] |= (m & scaps[i]);
0084     }
0085 
0086     /* Force removal of HT-40 capabilities? */
0087     __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
0088                   IEEE80211_HT_CAP_SUP_WIDTH_20_40);
0089     __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
0090                   IEEE80211_HT_CAP_SGI_40);
0091 
0092     /* Allow user to disable SGI-20 (SGI-40 is handled above) */
0093     __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
0094                   IEEE80211_HT_CAP_SGI_20);
0095 
0096     /* Allow user to disable the max-AMSDU bit. */
0097     __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
0098                   IEEE80211_HT_CAP_MAX_AMSDU);
0099 
0100     /* Allow user to disable LDPC */
0101     __check_htcap_disable(ht_capa, ht_capa_mask, ht_cap,
0102                   IEEE80211_HT_CAP_LDPC_CODING);
0103 
0104     /* Allow user to enable 40 MHz intolerant bit. */
0105     __check_htcap_enable(ht_capa, ht_capa_mask, ht_cap,
0106                  IEEE80211_HT_CAP_40MHZ_INTOLERANT);
0107 
0108     /* Allow user to enable TX STBC bit  */
0109     __check_htcap_enable(ht_capa, ht_capa_mask, ht_cap,
0110                  IEEE80211_HT_CAP_TX_STBC);
0111 
0112     /* Allow user to configure RX STBC bits */
0113     if (ht_capa_mask->cap_info & cpu_to_le16(IEEE80211_HT_CAP_RX_STBC))
0114         ht_cap->cap |= le16_to_cpu(ht_capa->cap_info) &
0115                     IEEE80211_HT_CAP_RX_STBC;
0116 
0117     /* Allow user to decrease AMPDU factor */
0118     if (ht_capa_mask->ampdu_params_info &
0119         IEEE80211_HT_AMPDU_PARM_FACTOR) {
0120         u8 n = ht_capa->ampdu_params_info &
0121                IEEE80211_HT_AMPDU_PARM_FACTOR;
0122         if (n < ht_cap->ampdu_factor)
0123             ht_cap->ampdu_factor = n;
0124     }
0125 
0126     /* Allow the user to increase AMPDU density. */
0127     if (ht_capa_mask->ampdu_params_info &
0128         IEEE80211_HT_AMPDU_PARM_DENSITY) {
0129         u8 n = (ht_capa->ampdu_params_info &
0130             IEEE80211_HT_AMPDU_PARM_DENSITY)
0131             >> IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT;
0132         if (n > ht_cap->ampdu_density)
0133             ht_cap->ampdu_density = n;
0134     }
0135 }
0136 
0137 
0138 bool ieee80211_ht_cap_ie_to_sta_ht_cap(struct ieee80211_sub_if_data *sdata,
0139                        struct ieee80211_supported_band *sband,
0140                        const struct ieee80211_ht_cap *ht_cap_ie,
0141                        struct link_sta_info *link_sta)
0142 {
0143     struct ieee80211_bss_conf *link_conf;
0144     struct sta_info *sta = link_sta->sta;
0145     struct ieee80211_sta_ht_cap ht_cap, own_cap;
0146     u8 ampdu_info, tx_mcs_set_cap;
0147     int i, max_tx_streams;
0148     bool changed;
0149     enum ieee80211_sta_rx_bandwidth bw;
0150     enum nl80211_chan_width width;
0151 
0152     memset(&ht_cap, 0, sizeof(ht_cap));
0153 
0154     if (!ht_cap_ie || !sband->ht_cap.ht_supported)
0155         goto apply;
0156 
0157     ht_cap.ht_supported = true;
0158 
0159     own_cap = sband->ht_cap;
0160 
0161     /*
0162      * If user has specified capability over-rides, take care
0163      * of that if the station we're setting up is the AP or TDLS peer that
0164      * we advertised a restricted capability set to. Override
0165      * our own capabilities and then use those below.
0166      */
0167     if (sdata->vif.type == NL80211_IFTYPE_STATION ||
0168         sdata->vif.type == NL80211_IFTYPE_ADHOC)
0169         ieee80211_apply_htcap_overrides(sdata, &own_cap);
0170 
0171     /*
0172      * The bits listed in this expression should be
0173      * the same for the peer and us, if the station
0174      * advertises more then we can't use those thus
0175      * we mask them out.
0176      */
0177     ht_cap.cap = le16_to_cpu(ht_cap_ie->cap_info) &
0178         (own_cap.cap | ~(IEEE80211_HT_CAP_LDPC_CODING |
0179                  IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
0180                  IEEE80211_HT_CAP_GRN_FLD |
0181                  IEEE80211_HT_CAP_SGI_20 |
0182                  IEEE80211_HT_CAP_SGI_40 |
0183                  IEEE80211_HT_CAP_DSSSCCK40));
0184 
0185     /*
0186      * The STBC bits are asymmetric -- if we don't have
0187      * TX then mask out the peer's RX and vice versa.
0188      */
0189     if (!(own_cap.cap & IEEE80211_HT_CAP_TX_STBC))
0190         ht_cap.cap &= ~IEEE80211_HT_CAP_RX_STBC;
0191     if (!(own_cap.cap & IEEE80211_HT_CAP_RX_STBC))
0192         ht_cap.cap &= ~IEEE80211_HT_CAP_TX_STBC;
0193 
0194     ampdu_info = ht_cap_ie->ampdu_params_info;
0195     ht_cap.ampdu_factor =
0196         ampdu_info & IEEE80211_HT_AMPDU_PARM_FACTOR;
0197     ht_cap.ampdu_density =
0198         (ampdu_info & IEEE80211_HT_AMPDU_PARM_DENSITY) >> 2;
0199 
0200     /* own MCS TX capabilities */
0201     tx_mcs_set_cap = own_cap.mcs.tx_params;
0202 
0203     /* Copy peer MCS TX capabilities, the driver might need them. */
0204     ht_cap.mcs.tx_params = ht_cap_ie->mcs.tx_params;
0205 
0206     /* can we TX with MCS rates? */
0207     if (!(tx_mcs_set_cap & IEEE80211_HT_MCS_TX_DEFINED))
0208         goto apply;
0209 
0210     /* Counting from 0, therefore +1 */
0211     if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_RX_DIFF)
0212         max_tx_streams =
0213             ((tx_mcs_set_cap & IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
0214                 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT) + 1;
0215     else
0216         max_tx_streams = IEEE80211_HT_MCS_TX_MAX_STREAMS;
0217 
0218     /*
0219      * 802.11n-2009 20.3.5 / 20.6 says:
0220      * - indices 0 to 7 and 32 are single spatial stream
0221      * - 8 to 31 are multiple spatial streams using equal modulation
0222      *   [8..15 for two streams, 16..23 for three and 24..31 for four]
0223      * - remainder are multiple spatial streams using unequal modulation
0224      */
0225     for (i = 0; i < max_tx_streams; i++)
0226         ht_cap.mcs.rx_mask[i] =
0227             own_cap.mcs.rx_mask[i] & ht_cap_ie->mcs.rx_mask[i];
0228 
0229     if (tx_mcs_set_cap & IEEE80211_HT_MCS_TX_UNEQUAL_MODULATION)
0230         for (i = IEEE80211_HT_MCS_UNEQUAL_MODULATION_START_BYTE;
0231              i < IEEE80211_HT_MCS_MASK_LEN; i++)
0232             ht_cap.mcs.rx_mask[i] =
0233                 own_cap.mcs.rx_mask[i] &
0234                     ht_cap_ie->mcs.rx_mask[i];
0235 
0236     /* handle MCS rate 32 too */
0237     if (own_cap.mcs.rx_mask[32/8] & ht_cap_ie->mcs.rx_mask[32/8] & 1)
0238         ht_cap.mcs.rx_mask[32/8] |= 1;
0239 
0240     /* set Rx highest rate */
0241     ht_cap.mcs.rx_highest = ht_cap_ie->mcs.rx_highest;
0242 
0243     if (ht_cap.cap & IEEE80211_HT_CAP_MAX_AMSDU)
0244         sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_7935;
0245     else
0246         sta->sta.max_amsdu_len = IEEE80211_MAX_MPDU_LEN_HT_3839;
0247 
0248  apply:
0249     changed = memcmp(&link_sta->pub->ht_cap, &ht_cap, sizeof(ht_cap));
0250 
0251     memcpy(&link_sta->pub->ht_cap, &ht_cap, sizeof(ht_cap));
0252 
0253     rcu_read_lock();
0254     link_conf = rcu_dereference(sdata->vif.link_conf[link_sta->link_id]);
0255     if (WARN_ON(!link_conf))
0256         width = NL80211_CHAN_WIDTH_20_NOHT;
0257     else
0258         width = link_conf->chandef.width;
0259 
0260     switch (width) {
0261     default:
0262         WARN_ON_ONCE(1);
0263         fallthrough;
0264     case NL80211_CHAN_WIDTH_20_NOHT:
0265     case NL80211_CHAN_WIDTH_20:
0266         bw = IEEE80211_STA_RX_BW_20;
0267         break;
0268     case NL80211_CHAN_WIDTH_40:
0269     case NL80211_CHAN_WIDTH_80:
0270     case NL80211_CHAN_WIDTH_80P80:
0271     case NL80211_CHAN_WIDTH_160:
0272         bw = ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
0273                 IEEE80211_STA_RX_BW_40 : IEEE80211_STA_RX_BW_20;
0274         break;
0275     }
0276     rcu_read_unlock();
0277 
0278     link_sta->pub->bandwidth = bw;
0279 
0280     link_sta->cur_max_bandwidth =
0281         ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
0282                 IEEE80211_STA_RX_BW_40 : IEEE80211_STA_RX_BW_20;
0283 
0284     if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
0285         sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
0286         enum ieee80211_smps_mode smps_mode;
0287 
0288         switch ((ht_cap.cap & IEEE80211_HT_CAP_SM_PS)
0289                 >> IEEE80211_HT_CAP_SM_PS_SHIFT) {
0290         case WLAN_HT_CAP_SM_PS_INVALID:
0291         case WLAN_HT_CAP_SM_PS_STATIC:
0292             smps_mode = IEEE80211_SMPS_STATIC;
0293             break;
0294         case WLAN_HT_CAP_SM_PS_DYNAMIC:
0295             smps_mode = IEEE80211_SMPS_DYNAMIC;
0296             break;
0297         case WLAN_HT_CAP_SM_PS_DISABLED:
0298             smps_mode = IEEE80211_SMPS_OFF;
0299             break;
0300         }
0301 
0302         if (smps_mode != sta->sta.smps_mode)
0303             changed = true;
0304         sta->sta.smps_mode = smps_mode;
0305     } else {
0306         sta->sta.smps_mode = IEEE80211_SMPS_OFF;
0307     }
0308     return changed;
0309 }
0310 
0311 void ieee80211_sta_tear_down_BA_sessions(struct sta_info *sta,
0312                      enum ieee80211_agg_stop_reason reason)
0313 {
0314     int i;
0315 
0316     mutex_lock(&sta->ampdu_mlme.mtx);
0317     for (i = 0; i <  IEEE80211_NUM_TIDS; i++)
0318         ___ieee80211_stop_rx_ba_session(sta, i, WLAN_BACK_RECIPIENT,
0319                         WLAN_REASON_QSTA_LEAVE_QBSS,
0320                         reason != AGG_STOP_DESTROY_STA &&
0321                         reason != AGG_STOP_PEER_REQUEST);
0322 
0323     for (i = 0; i <  IEEE80211_NUM_TIDS; i++)
0324         ___ieee80211_stop_tx_ba_session(sta, i, reason);
0325     mutex_unlock(&sta->ampdu_mlme.mtx);
0326 
0327     /*
0328      * In case the tear down is part of a reconfigure due to HW restart
0329      * request, it is possible that the low level driver requested to stop
0330      * the BA session, so handle it to properly clean tid_tx data.
0331      */
0332     if(reason == AGG_STOP_DESTROY_STA) {
0333         cancel_work_sync(&sta->ampdu_mlme.work);
0334 
0335         mutex_lock(&sta->ampdu_mlme.mtx);
0336         for (i = 0; i < IEEE80211_NUM_TIDS; i++) {
0337             struct tid_ampdu_tx *tid_tx =
0338                 rcu_dereference_protected_tid_tx(sta, i);
0339 
0340             if (!tid_tx)
0341                 continue;
0342 
0343             if (test_and_clear_bit(HT_AGG_STATE_STOP_CB, &tid_tx->state))
0344                 ieee80211_stop_tx_ba_cb(sta, i, tid_tx);
0345         }
0346         mutex_unlock(&sta->ampdu_mlme.mtx);
0347     }
0348 }
0349 
0350 void ieee80211_ba_session_work(struct work_struct *work)
0351 {
0352     struct sta_info *sta =
0353         container_of(work, struct sta_info, ampdu_mlme.work);
0354     struct tid_ampdu_tx *tid_tx;
0355     bool blocked;
0356     int tid;
0357 
0358     /* When this flag is set, new sessions should be blocked. */
0359     blocked = test_sta_flag(sta, WLAN_STA_BLOCK_BA);
0360 
0361     mutex_lock(&sta->ampdu_mlme.mtx);
0362     for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
0363         if (test_and_clear_bit(tid, sta->ampdu_mlme.tid_rx_timer_expired))
0364             ___ieee80211_stop_rx_ba_session(
0365                 sta, tid, WLAN_BACK_RECIPIENT,
0366                 WLAN_REASON_QSTA_TIMEOUT, true);
0367 
0368         if (test_and_clear_bit(tid,
0369                        sta->ampdu_mlme.tid_rx_stop_requested))
0370             ___ieee80211_stop_rx_ba_session(
0371                 sta, tid, WLAN_BACK_RECIPIENT,
0372                 WLAN_REASON_UNSPECIFIED, true);
0373 
0374         if (!blocked &&
0375             test_and_clear_bit(tid,
0376                        sta->ampdu_mlme.tid_rx_manage_offl))
0377             ___ieee80211_start_rx_ba_session(sta, 0, 0, 0, 1, tid,
0378                              IEEE80211_MAX_AMPDU_BUF_HT,
0379                              false, true, NULL);
0380 
0381         if (test_and_clear_bit(tid + IEEE80211_NUM_TIDS,
0382                        sta->ampdu_mlme.tid_rx_manage_offl))
0383             ___ieee80211_stop_rx_ba_session(
0384                 sta, tid, WLAN_BACK_RECIPIENT,
0385                 0, false);
0386 
0387         spin_lock_bh(&sta->lock);
0388 
0389         tid_tx = sta->ampdu_mlme.tid_start_tx[tid];
0390         if (!blocked && tid_tx) {
0391             /*
0392              * Assign it over to the normal tid_tx array
0393              * where it "goes live".
0394              */
0395 
0396             sta->ampdu_mlme.tid_start_tx[tid] = NULL;
0397             /* could there be a race? */
0398             if (sta->ampdu_mlme.tid_tx[tid])
0399                 kfree(tid_tx);
0400             else
0401                 ieee80211_assign_tid_tx(sta, tid, tid_tx);
0402             spin_unlock_bh(&sta->lock);
0403 
0404             ieee80211_tx_ba_session_handle_start(sta, tid);
0405             continue;
0406         }
0407         spin_unlock_bh(&sta->lock);
0408 
0409         tid_tx = rcu_dereference_protected_tid_tx(sta, tid);
0410         if (!tid_tx)
0411             continue;
0412 
0413         if (!blocked &&
0414             test_and_clear_bit(HT_AGG_STATE_START_CB, &tid_tx->state))
0415             ieee80211_start_tx_ba_cb(sta, tid, tid_tx);
0416         if (test_and_clear_bit(HT_AGG_STATE_WANT_STOP, &tid_tx->state))
0417             ___ieee80211_stop_tx_ba_session(sta, tid,
0418                             AGG_STOP_LOCAL_REQUEST);
0419         if (test_and_clear_bit(HT_AGG_STATE_STOP_CB, &tid_tx->state))
0420             ieee80211_stop_tx_ba_cb(sta, tid, tid_tx);
0421     }
0422     mutex_unlock(&sta->ampdu_mlme.mtx);
0423 }
0424 
0425 void ieee80211_send_delba(struct ieee80211_sub_if_data *sdata,
0426               const u8 *da, u16 tid,
0427               u16 initiator, u16 reason_code)
0428 {
0429     struct ieee80211_local *local = sdata->local;
0430     struct sk_buff *skb;
0431     struct ieee80211_mgmt *mgmt;
0432     u16 params;
0433 
0434     skb = dev_alloc_skb(sizeof(*mgmt) + local->hw.extra_tx_headroom);
0435     if (!skb)
0436         return;
0437 
0438     skb_reserve(skb, local->hw.extra_tx_headroom);
0439     mgmt = skb_put_zero(skb, 24);
0440     memcpy(mgmt->da, da, ETH_ALEN);
0441     memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
0442     if (sdata->vif.type == NL80211_IFTYPE_AP ||
0443         sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
0444         sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
0445         memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
0446     else if (sdata->vif.type == NL80211_IFTYPE_STATION)
0447         memcpy(mgmt->bssid, sdata->deflink.u.mgd.bssid, ETH_ALEN);
0448     else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
0449         memcpy(mgmt->bssid, sdata->u.ibss.bssid, ETH_ALEN);
0450 
0451     mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
0452                       IEEE80211_STYPE_ACTION);
0453 
0454     skb_put(skb, 1 + sizeof(mgmt->u.action.u.delba));
0455 
0456     mgmt->u.action.category = WLAN_CATEGORY_BACK;
0457     mgmt->u.action.u.delba.action_code = WLAN_ACTION_DELBA;
0458     params = (u16)(initiator << 11);    /* bit 11 initiator */
0459     params |= (u16)(tid << 12);         /* bit 15:12 TID number */
0460 
0461     mgmt->u.action.u.delba.params = cpu_to_le16(params);
0462     mgmt->u.action.u.delba.reason_code = cpu_to_le16(reason_code);
0463 
0464     ieee80211_tx_skb(sdata, skb);
0465 }
0466 
0467 void ieee80211_process_delba(struct ieee80211_sub_if_data *sdata,
0468                  struct sta_info *sta,
0469                  struct ieee80211_mgmt *mgmt, size_t len)
0470 {
0471     u16 tid, params;
0472     u16 initiator;
0473 
0474     params = le16_to_cpu(mgmt->u.action.u.delba.params);
0475     tid = (params & IEEE80211_DELBA_PARAM_TID_MASK) >> 12;
0476     initiator = (params & IEEE80211_DELBA_PARAM_INITIATOR_MASK) >> 11;
0477 
0478     ht_dbg_ratelimited(sdata, "delba from %pM (%s) tid %d reason code %d\n",
0479                mgmt->sa, initiator ? "initiator" : "recipient",
0480                tid,
0481                le16_to_cpu(mgmt->u.action.u.delba.reason_code));
0482 
0483     if (initiator == WLAN_BACK_INITIATOR)
0484         __ieee80211_stop_rx_ba_session(sta, tid, WLAN_BACK_INITIATOR, 0,
0485                            true);
0486     else
0487         __ieee80211_stop_tx_ba_session(sta, tid, AGG_STOP_PEER_REQUEST);
0488 }
0489 
0490 enum nl80211_smps_mode
0491 ieee80211_smps_mode_to_smps_mode(enum ieee80211_smps_mode smps)
0492 {
0493     switch (smps) {
0494     case IEEE80211_SMPS_OFF:
0495         return NL80211_SMPS_OFF;
0496     case IEEE80211_SMPS_STATIC:
0497         return NL80211_SMPS_STATIC;
0498     case IEEE80211_SMPS_DYNAMIC:
0499         return NL80211_SMPS_DYNAMIC;
0500     default:
0501         return NL80211_SMPS_OFF;
0502     }
0503 }
0504 
0505 int ieee80211_send_smps_action(struct ieee80211_sub_if_data *sdata,
0506                    enum ieee80211_smps_mode smps, const u8 *da,
0507                    const u8 *bssid)
0508 {
0509     struct ieee80211_local *local = sdata->local;
0510     struct sk_buff *skb;
0511     struct ieee80211_mgmt *action_frame;
0512 
0513     /* 27 = header + category + action + smps mode */
0514     skb = dev_alloc_skb(27 + local->hw.extra_tx_headroom);
0515     if (!skb)
0516         return -ENOMEM;
0517 
0518     skb_reserve(skb, local->hw.extra_tx_headroom);
0519     action_frame = skb_put(skb, 27);
0520     memcpy(action_frame->da, da, ETH_ALEN);
0521     memcpy(action_frame->sa, sdata->dev->dev_addr, ETH_ALEN);
0522     memcpy(action_frame->bssid, bssid, ETH_ALEN);
0523     action_frame->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
0524                           IEEE80211_STYPE_ACTION);
0525     action_frame->u.action.category = WLAN_CATEGORY_HT;
0526     action_frame->u.action.u.ht_smps.action = WLAN_HT_ACTION_SMPS;
0527     switch (smps) {
0528     case IEEE80211_SMPS_AUTOMATIC:
0529     case IEEE80211_SMPS_NUM_MODES:
0530         WARN_ON(1);
0531         fallthrough;
0532     case IEEE80211_SMPS_OFF:
0533         action_frame->u.action.u.ht_smps.smps_control =
0534                 WLAN_HT_SMPS_CONTROL_DISABLED;
0535         break;
0536     case IEEE80211_SMPS_STATIC:
0537         action_frame->u.action.u.ht_smps.smps_control =
0538                 WLAN_HT_SMPS_CONTROL_STATIC;
0539         break;
0540     case IEEE80211_SMPS_DYNAMIC:
0541         action_frame->u.action.u.ht_smps.smps_control =
0542                 WLAN_HT_SMPS_CONTROL_DYNAMIC;
0543         break;
0544     }
0545 
0546     /* we'll do more on status of this frame */
0547     IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
0548     ieee80211_tx_skb(sdata, skb);
0549 
0550     return 0;
0551 }
0552 
0553 void ieee80211_request_smps(struct ieee80211_vif *vif, unsigned int link_id,
0554                 enum ieee80211_smps_mode smps_mode)
0555 {
0556     struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
0557     struct ieee80211_link_data *link;
0558 
0559     if (WARN_ON_ONCE(vif->type != NL80211_IFTYPE_STATION))
0560         return;
0561 
0562     rcu_read_lock();
0563     link = rcu_dereference(sdata->link[link_id]);
0564     if (WARN_ON(!link))
0565         goto out;
0566 
0567     if (link->u.mgd.driver_smps_mode == smps_mode)
0568         goto out;
0569 
0570     link->u.mgd.driver_smps_mode = smps_mode;
0571     ieee80211_queue_work(&sdata->local->hw, &link->u.mgd.request_smps_work);
0572 out:
0573     rcu_read_unlock();
0574 }
0575 /* this might change ... don't want non-open drivers using it */
0576 EXPORT_SYMBOL_GPL(ieee80211_request_smps);