LCOV - code coverage report
Current view: top level - src/ap - ieee802_11_ht.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1393793999 Lines: 118 139 84.9 %
Date: 2014-03-02 Functions: 8 8 100.0 %
Branches: 59 84 70.2 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * hostapd / IEEE 802.11n HT
       3                 :            :  * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
       4                 :            :  * Copyright (c) 2007-2008, Intel Corporation
       5                 :            :  *
       6                 :            :  * This software may be distributed under the terms of the BSD license.
       7                 :            :  * See README for more details.
       8                 :            :  */
       9                 :            : 
      10                 :            : #include "utils/includes.h"
      11                 :            : 
      12                 :            : #include "utils/common.h"
      13                 :            : #include "common/ieee802_11_defs.h"
      14                 :            : #include "hostapd.h"
      15                 :            : #include "ap_config.h"
      16                 :            : #include "sta_info.h"
      17                 :            : #include "beacon.h"
      18                 :            : #include "ieee802_11.h"
      19                 :            : 
      20                 :            : 
      21                 :       2919 : u8 * hostapd_eid_ht_capabilities(struct hostapd_data *hapd, u8 *eid)
      22                 :            : {
      23                 :            :         struct ieee80211_ht_capabilities *cap;
      24                 :       2919 :         u8 *pos = eid;
      25                 :            : 
      26 [ +  + ][ +  - ]:       2919 :         if (!hapd->iconf->ieee80211n || !hapd->iface->current_mode ||
                 [ +  + ]
      27                 :       2917 :             hapd->conf->disable_11n)
      28                 :         56 :                 return eid;
      29                 :            : 
      30                 :       2863 :         *pos++ = WLAN_EID_HT_CAP;
      31                 :       2863 :         *pos++ = sizeof(*cap);
      32                 :            : 
      33                 :       2863 :         cap = (struct ieee80211_ht_capabilities *) pos;
      34                 :       2863 :         os_memset(cap, 0, sizeof(*cap));
      35                 :       2863 :         cap->ht_capabilities_info = host_to_le16(hapd->iconf->ht_capab);
      36                 :       2863 :         cap->a_mpdu_params = hapd->iface->current_mode->a_mpdu_params;
      37                 :       2863 :         os_memcpy(cap->supported_mcs_set, hapd->iface->current_mode->mcs_set,
      38                 :            :                   16);
      39                 :            : 
      40                 :            :         /* TODO: ht_extended_capabilities (now fully disabled) */
      41                 :            :         /* TODO: tx_bf_capability_info (now fully disabled) */
      42                 :            :         /* TODO: asel_capabilities (now fully disabled) */
      43                 :            : 
      44                 :       2863 :         pos += sizeof(*cap);
      45                 :            : 
      46         [ +  + ]:       2863 :         if (hapd->iconf->obss_interval) {
      47                 :            :                 struct ieee80211_obss_scan_parameters *scan_params;
      48                 :            : 
      49                 :          3 :                 *pos++ = WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS;
      50                 :          3 :                 *pos++ = sizeof(*scan_params);
      51                 :            : 
      52                 :          3 :                 scan_params = (struct ieee80211_obss_scan_parameters *) pos;
      53                 :          3 :                 os_memset(scan_params, 0, sizeof(*scan_params));
      54                 :          3 :                 scan_params->width_trigger_scan_interval =
      55                 :          3 :                         host_to_le16(hapd->iconf->obss_interval);
      56                 :            : 
      57                 :            :                 /* TODO: Fill in more parameters (supplicant ignores them) */
      58                 :            : 
      59                 :          3 :                 pos += sizeof(*scan_params);
      60                 :            :         }
      61                 :            : 
      62                 :       2919 :         return pos;
      63                 :            : }
      64                 :            : 
      65                 :            : 
      66                 :       2919 : u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
      67                 :            : {
      68                 :            :         struct ieee80211_ht_operation *oper;
      69                 :       2919 :         u8 *pos = eid;
      70                 :            : 
      71 [ +  + ][ +  + ]:       2919 :         if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
      72                 :         56 :                 return eid;
      73                 :            : 
      74                 :       2863 :         *pos++ = WLAN_EID_HT_OPERATION;
      75                 :       2863 :         *pos++ = sizeof(*oper);
      76                 :            : 
      77                 :       2863 :         oper = (struct ieee80211_ht_operation *) pos;
      78                 :       2863 :         os_memset(oper, 0, sizeof(*oper));
      79                 :            : 
      80                 :       2863 :         oper->control_chan = hapd->iconf->channel;
      81                 :       2863 :         oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
      82         [ +  + ]:       2863 :         if (hapd->iconf->secondary_channel == 1)
      83                 :         20 :                 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
      84                 :            :                         HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
      85         [ +  + ]:       2863 :         if (hapd->iconf->secondary_channel == -1)
      86                 :          8 :                 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
      87                 :            :                         HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
      88                 :            : 
      89                 :       2863 :         pos += sizeof(*oper);
      90                 :            : 
      91                 :       2919 :         return pos;
      92                 :            : }
      93                 :            : 
      94                 :            : 
      95                 :            : /*
      96                 :            : op_mode
      97                 :            : Set to 0 (HT pure) under the followign conditions
      98                 :            :         - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
      99                 :            :         - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
     100                 :            : Set to 1 (HT non-member protection) if there may be non-HT STAs
     101                 :            :         in both the primary and the secondary channel
     102                 :            : Set to 2 if only HT STAs are associated in BSS,
     103                 :            :         however and at least one 20 MHz HT STA is associated
     104                 :            : Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
     105                 :            : */
     106                 :       1325 : int hostapd_ht_operation_update(struct hostapd_iface *iface)
     107                 :            : {
     108                 :            :         u16 cur_op_mode, new_op_mode;
     109                 :       1325 :         int op_mode_changes = 0;
     110                 :            : 
     111 [ +  - ][ -  + ]:       1325 :         if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
     112                 :          0 :                 return 0;
     113                 :            : 
     114                 :       1325 :         wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
     115                 :       1325 :                    __func__, iface->ht_op_mode);
     116                 :            : 
     117         [ +  - ]:       1325 :         if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
     118         [ -  + ]:       1325 :             && iface->num_sta_ht_no_gf) {
     119                 :          0 :                 iface->ht_op_mode |=
     120                 :            :                         HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
     121                 :          0 :                 op_mode_changes++;
     122         [ -  + ]:       1325 :         } else if ((iface->ht_op_mode &
     123         [ #  # ]:          0 :                     HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
     124                 :          0 :                    iface->num_sta_ht_no_gf == 0) {
     125                 :          0 :                 iface->ht_op_mode &=
     126                 :            :                         ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
     127                 :          0 :                 op_mode_changes++;
     128                 :            :         }
     129                 :            : 
     130 [ +  + ][ +  + ]:       1325 :         if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
     131         [ +  + ]:       1293 :             (iface->num_sta_no_ht || iface->olbc_ht)) {
     132                 :         12 :                 iface->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
     133                 :         12 :                 op_mode_changes++;
     134         [ +  + ]:       1313 :         } else if ((iface->ht_op_mode &
     135         [ +  + ]:         21 :                     HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
     136         [ +  - ]:         11 :                    (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
     137                 :         11 :                 iface->ht_op_mode &=
     138                 :            :                         ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
     139                 :         11 :                 op_mode_changes++;
     140                 :            :         }
     141                 :            : 
     142         [ +  + ]:       1325 :         if (iface->num_sta_no_ht)
     143                 :         21 :                 new_op_mode = OP_MODE_MIXED;
     144 [ +  + ][ -  + ]:       1304 :         else if (iface->conf->secondary_channel && iface->num_sta_ht_20mhz)
     145                 :          0 :                 new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
     146         [ +  + ]:       1304 :         else if (iface->olbc_ht)
     147                 :          1 :                 new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
     148                 :            :         else
     149                 :       1303 :                 new_op_mode = OP_MODE_PURE;
     150                 :            : 
     151                 :       1325 :         cur_op_mode = iface->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
     152         [ +  + ]:       1325 :         if (cur_op_mode != new_op_mode) {
     153                 :         23 :                 iface->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
     154                 :         23 :                 iface->ht_op_mode |= new_op_mode;
     155                 :         23 :                 op_mode_changes++;
     156                 :            :         }
     157                 :            : 
     158                 :       1325 :         wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
     159                 :       1325 :                    __func__, iface->ht_op_mode, op_mode_changes);
     160                 :            : 
     161                 :       1325 :         return op_mode_changes;
     162                 :            : }
     163                 :            : 
     164                 :            : 
     165                 :        674 : u16 copy_sta_ht_capab(struct hostapd_data *hapd, struct sta_info *sta,
     166                 :            :                       const u8 *ht_capab, size_t ht_capab_len)
     167                 :            : {
     168                 :            :         /* Disable HT caps for STAs associated to no-HT BSSes. */
     169 [ +  + ][ +  - ]:        674 :         if (!ht_capab ||
     170         [ -  + ]:        660 :             ht_capab_len < sizeof(struct ieee80211_ht_capabilities) ||
     171                 :        660 :             hapd->conf->disable_11n) {
     172                 :         14 :                 sta->flags &= ~WLAN_STA_HT;
     173                 :         14 :                 os_free(sta->ht_capabilities);
     174                 :         14 :                 sta->ht_capabilities = NULL;
     175                 :         14 :                 return WLAN_STATUS_SUCCESS;
     176                 :            :         }
     177                 :            : 
     178         [ +  + ]:        660 :         if (sta->ht_capabilities == NULL) {
     179                 :        632 :                 sta->ht_capabilities =
     180                 :        632 :                         os_zalloc(sizeof(struct ieee80211_ht_capabilities));
     181         [ -  + ]:        632 :                 if (sta->ht_capabilities == NULL)
     182                 :          0 :                         return WLAN_STATUS_UNSPECIFIED_FAILURE;
     183                 :            :         }
     184                 :            : 
     185                 :        660 :         sta->flags |= WLAN_STA_HT;
     186                 :        660 :         os_memcpy(sta->ht_capabilities, ht_capab,
     187                 :            :                   sizeof(struct ieee80211_ht_capabilities));
     188                 :            : 
     189                 :        674 :         return WLAN_STATUS_SUCCESS;
     190                 :            : }
     191                 :            : 
     192                 :            : 
     193                 :        660 : static void update_sta_ht(struct hostapd_data *hapd, struct sta_info *sta)
     194                 :            : {
     195                 :            :         u16 ht_capab;
     196                 :            : 
     197                 :        660 :         ht_capab = le_to_host16(sta->ht_capabilities->ht_capabilities_info);
     198                 :        660 :         wpa_printf(MSG_DEBUG, "HT: STA " MACSTR " HT Capabilities Info: "
     199                 :       3960 :                    "0x%04x", MAC2STR(sta->addr), ht_capab);
     200         [ -  + ]:        660 :         if ((ht_capab & HT_CAP_INFO_GREEN_FIELD) == 0) {
     201         [ #  # ]:          0 :                 if (!sta->no_ht_gf_set) {
     202                 :          0 :                         sta->no_ht_gf_set = 1;
     203                 :          0 :                         hapd->iface->num_sta_ht_no_gf++;
     204                 :            :                 }
     205                 :          0 :                 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no greenfield, num "
     206                 :            :                            "of non-gf stations %d",
     207                 :          0 :                            __func__, MAC2STR(sta->addr),
     208                 :          0 :                            hapd->iface->num_sta_ht_no_gf);
     209                 :            :         }
     210         [ -  + ]:        660 :         if ((ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
     211         [ #  # ]:          0 :                 if (!sta->ht_20mhz_set) {
     212                 :          0 :                         sta->ht_20mhz_set = 1;
     213                 :          0 :                         hapd->iface->num_sta_ht_20mhz++;
     214                 :            :                 }
     215                 :          0 :                 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, num of "
     216                 :            :                            "20MHz HT STAs %d",
     217                 :          0 :                            __func__, MAC2STR(sta->addr),
     218                 :          0 :                            hapd->iface->num_sta_ht_20mhz);
     219                 :            :         }
     220                 :        660 : }
     221                 :            : 
     222                 :            : 
     223                 :         14 : static void update_sta_no_ht(struct hostapd_data *hapd, struct sta_info *sta)
     224                 :            : {
     225         [ +  - ]:         14 :         if (!sta->no_ht_set) {
     226                 :         14 :                 sta->no_ht_set = 1;
     227                 :         14 :                 hapd->iface->num_sta_no_ht++;
     228                 :            :         }
     229         [ +  - ]:         14 :         if (hapd->iconf->ieee80211n) {
     230                 :         14 :                 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no HT, num of "
     231                 :            :                            "non-HT stations %d",
     232                 :         84 :                            __func__, MAC2STR(sta->addr),
     233                 :         14 :                            hapd->iface->num_sta_no_ht);
     234                 :            :         }
     235                 :         14 : }
     236                 :            : 
     237                 :            : 
     238                 :        674 : void update_ht_state(struct hostapd_data *hapd, struct sta_info *sta)
     239                 :            : {
     240 [ +  + ][ +  - ]:        674 :         if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities)
     241                 :        660 :                 update_sta_ht(hapd, sta);
     242                 :            :         else
     243                 :         14 :                 update_sta_no_ht(hapd, sta);
     244                 :            : 
     245         [ +  + ]:        674 :         if (hostapd_ht_operation_update(hapd->iface) > 0)
     246                 :         11 :                 ieee802_11_set_beacons(hapd->iface);
     247                 :        674 : }
     248                 :            : 
     249                 :            : 
     250                 :        660 : void hostapd_get_ht_capab(struct hostapd_data *hapd,
     251                 :            :                           struct ieee80211_ht_capabilities *ht_cap,
     252                 :            :                           struct ieee80211_ht_capabilities *neg_ht_cap)
     253                 :            : {
     254                 :            :         u16 cap;
     255                 :            : 
     256         [ -  + ]:        660 :         if (ht_cap == NULL)
     257                 :        660 :                 return;
     258                 :        660 :         os_memcpy(neg_ht_cap, ht_cap, sizeof(*neg_ht_cap));
     259                 :        660 :         cap = le_to_host16(neg_ht_cap->ht_capabilities_info);
     260                 :            : 
     261                 :            :         /*
     262                 :            :          * Mask out HT features we don't support, but don't overwrite
     263                 :            :          * non-symmetric features like STBC and SMPS. Just because
     264                 :            :          * we're not in dynamic SMPS mode the STA might still be.
     265                 :            :          */
     266                 :        660 :         cap &= (hapd->iconf->ht_capab | HT_CAP_INFO_RX_STBC_MASK |
     267                 :            :                 HT_CAP_INFO_TX_STBC | HT_CAP_INFO_SMPS_MASK);
     268                 :            : 
     269                 :            :         /*
     270                 :            :          * STBC needs to be handled specially
     271                 :            :          * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
     272                 :            :          * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
     273                 :            :          */
     274         [ +  - ]:        660 :         if (!(hapd->iconf->ht_capab & HT_CAP_INFO_RX_STBC_MASK))
     275                 :        660 :                 cap &= ~HT_CAP_INFO_TX_STBC;
     276         [ +  - ]:        660 :         if (!(hapd->iconf->ht_capab & HT_CAP_INFO_TX_STBC))
     277                 :        660 :                 cap &= ~HT_CAP_INFO_RX_STBC_MASK;
     278                 :            : 
     279                 :        660 :         neg_ht_cap->ht_capabilities_info = host_to_le16(cap);
     280                 :            : }

Generated by: LCOV version 1.9