LCOV - code coverage report
Current view: top level - src/ap - ieee802_11_vht.c (source / functions) Hit Total Coverage
Test: wpa_supplicant/hostapd combined for hwsim test run 1401264779 Lines: 74 91 81.3 %
Date: 2014-05-28 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /*
       2             :  * hostapd / IEEE 802.11ac VHT
       3             :  * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
       4             :  *
       5             :  * This program is free software; you can redistribute it and/or modify
       6             :  * it under the terms of BSD license
       7             :  *
       8             :  * See README and COPYING for more details.
       9             :  */
      10             : 
      11             : #include "utils/includes.h"
      12             : 
      13             : #include "utils/common.h"
      14             : #include "common/ieee802_11_defs.h"
      15             : #include "hostapd.h"
      16             : #include "ap_config.h"
      17             : #include "sta_info.h"
      18             : #include "beacon.h"
      19             : #include "ieee802_11.h"
      20             : 
      21             : 
      22        2751 : u8 * hostapd_eid_vht_capabilities(struct hostapd_data *hapd, u8 *eid)
      23             : {
      24             :         struct ieee80211_vht_capabilities *cap;
      25        2751 :         u8 *pos = eid;
      26             : 
      27        2762 :         if (!hapd->iconf->ieee80211ac || !hapd->iface->current_mode ||
      28          11 :             hapd->conf->disable_11ac)
      29        2740 :                 return eid;
      30             : 
      31          11 :         *pos++ = WLAN_EID_VHT_CAP;
      32          11 :         *pos++ = sizeof(*cap);
      33             : 
      34          11 :         cap = (struct ieee80211_vht_capabilities *) pos;
      35          11 :         os_memset(cap, 0, sizeof(*cap));
      36          11 :         cap->vht_capabilities_info = host_to_le32(
      37             :                 hapd->iface->conf->vht_capab);
      38             : 
      39             :         /* Supported MCS set comes from hw */
      40          11 :         os_memcpy(&cap->vht_supported_mcs_set,
      41             :                   hapd->iface->current_mode->vht_mcs_set, 8);
      42             : 
      43          11 :         pos += sizeof(*cap);
      44             : 
      45          11 :         return pos;
      46             : }
      47             : 
      48             : 
      49        2751 : u8 * hostapd_eid_vht_operation(struct hostapd_data *hapd, u8 *eid)
      50             : {
      51             :         struct ieee80211_vht_operation *oper;
      52        2751 :         u8 *pos = eid;
      53             : 
      54        2751 :         if (!hapd->iconf->ieee80211ac || hapd->conf->disable_11ac)
      55        2740 :                 return eid;
      56             : 
      57          11 :         *pos++ = WLAN_EID_VHT_OPERATION;
      58          11 :         *pos++ = sizeof(*oper);
      59             : 
      60          11 :         oper = (struct ieee80211_vht_operation *) pos;
      61          11 :         os_memset(oper, 0, sizeof(*oper));
      62             : 
      63             :         /*
      64             :          * center freq = 5 GHz + (5 * index)
      65             :          * So index 42 gives center freq 5.210 GHz
      66             :          * which is channel 42 in 5G band
      67             :          */
      68          11 :         oper->vht_op_info_chan_center_freq_seg0_idx =
      69          11 :                 hapd->iconf->vht_oper_centr_freq_seg0_idx;
      70          11 :         oper->vht_op_info_chan_center_freq_seg1_idx =
      71          11 :                 hapd->iconf->vht_oper_centr_freq_seg1_idx;
      72             : 
      73          11 :         oper->vht_op_info_chwidth = hapd->iconf->vht_oper_chwidth;
      74             : 
      75             :         /* VHT Basic MCS set comes from hw */
      76             :         /* Hard code 1 stream, MCS0-7 is a min Basic VHT MCS rates */
      77          11 :         oper->vht_basic_mcs_set = host_to_le16(0xfffc);
      78          11 :         pos += sizeof(*oper);
      79             : 
      80          11 :         return pos;
      81             : }
      82             : 
      83             : 
      84         769 : u16 copy_sta_vht_capab(struct hostapd_data *hapd, struct sta_info *sta,
      85             :                        const u8 *vht_capab, size_t vht_capab_len)
      86             : {
      87             :         /* Disable VHT caps for STAs associated to no-VHT BSSes. */
      88         769 :         if (!vht_capab ||
      89           3 :             vht_capab_len < sizeof(struct ieee80211_vht_capabilities) ||
      90           3 :             hapd->conf->disable_11ac) {
      91         766 :                 sta->flags &= ~WLAN_STA_VHT;
      92         766 :                 os_free(sta->vht_capabilities);
      93         766 :                 sta->vht_capabilities = NULL;
      94         766 :                 return WLAN_STATUS_SUCCESS;
      95             :         }
      96             : 
      97           3 :         if (sta->vht_capabilities == NULL) {
      98           3 :                 sta->vht_capabilities =
      99           3 :                         os_zalloc(sizeof(struct ieee80211_vht_capabilities));
     100           3 :                 if (sta->vht_capabilities == NULL)
     101           0 :                         return WLAN_STATUS_UNSPECIFIED_FAILURE;
     102             :         }
     103             : 
     104           3 :         sta->flags |= WLAN_STA_VHT;
     105           3 :         os_memcpy(sta->vht_capabilities, vht_capab,
     106             :                   sizeof(struct ieee80211_vht_capabilities));
     107             : 
     108           3 :         return WLAN_STATUS_SUCCESS;
     109             : }
     110             : 
     111             : 
     112         769 : u16 set_sta_vht_opmode(struct hostapd_data *hapd, struct sta_info *sta,
     113             :                        const u8 *vht_oper_notif)
     114             : {
     115             :         u8 channel_width;
     116             : 
     117         769 :         if (!vht_oper_notif) {
     118         769 :                 sta->flags &= ~WLAN_STA_VHT_OPMODE_ENABLED;
     119         769 :                 return WLAN_STATUS_SUCCESS;
     120             :         }
     121             : 
     122           0 :         channel_width = *vht_oper_notif & VHT_OPMODE_CHANNEL_WIDTH_MASK;
     123             : 
     124           0 :         if (channel_width != VHT_CHANWIDTH_USE_HT &&
     125           0 :             channel_width != VHT_CHANWIDTH_80MHZ &&
     126           0 :             channel_width != VHT_CHANWIDTH_160MHZ &&
     127           0 :             channel_width != VHT_CHANWIDTH_80P80MHZ &&
     128           0 :             ((*vht_oper_notif & VHT_OPMODE_CHANNEL_RxNSS_MASK) >>
     129             :              VHT_OPMODE_NOTIF_RX_NSS_SHIFT) > VHT_RX_NSS_MAX_STREAMS - 1) {
     130           0 :                 sta->flags &= ~WLAN_STA_VHT_OPMODE_ENABLED;
     131           0 :                 return WLAN_STATUS_UNSPECIFIED_FAILURE;
     132             :         }
     133             : 
     134           0 :         sta->flags |= WLAN_STA_VHT_OPMODE_ENABLED;
     135           0 :         sta->vht_opmode = *vht_oper_notif;
     136           0 :         return WLAN_STATUS_SUCCESS;
     137             : }
     138             : 
     139             : 
     140           3 : void hostapd_get_vht_capab(struct hostapd_data *hapd,
     141             :                            struct ieee80211_vht_capabilities *vht_cap,
     142             :                            struct ieee80211_vht_capabilities *neg_vht_cap)
     143             : {
     144             :         u32 cap, own_cap, sym_caps;
     145             : 
     146           3 :         if (vht_cap == NULL)
     147           3 :                 return;
     148           3 :         os_memcpy(neg_vht_cap, vht_cap, sizeof(*neg_vht_cap));
     149             : 
     150           3 :         cap = le_to_host32(neg_vht_cap->vht_capabilities_info);
     151           3 :         own_cap = hapd->iconf->vht_capab;
     152             : 
     153             :         /* mask out symmetric VHT capabilities we don't support */
     154           3 :         sym_caps = VHT_CAP_SHORT_GI_80 | VHT_CAP_SHORT_GI_160;
     155           3 :         cap &= ~sym_caps | (own_cap & sym_caps);
     156             : 
     157             :         /* mask out beamformer/beamformee caps if not supported */
     158           3 :         if (!(own_cap & VHT_CAP_SU_BEAMFORMER_CAPABLE))
     159           3 :                 cap &= ~(VHT_CAP_SU_BEAMFORMEE_CAPABLE |
     160             :                          VHT_CAP_BEAMFORMEE_STS_MAX);
     161             : 
     162           3 :         if (!(own_cap & VHT_CAP_SU_BEAMFORMEE_CAPABLE))
     163           3 :                 cap &= ~(VHT_CAP_SU_BEAMFORMER_CAPABLE |
     164             :                          VHT_CAP_SOUNDING_DIMENSION_MAX);
     165             : 
     166           3 :         if (!(own_cap & VHT_CAP_MU_BEAMFORMER_CAPABLE))
     167           3 :                 cap &= ~VHT_CAP_MU_BEAMFORMEE_CAPABLE;
     168             : 
     169           3 :         if (!(own_cap & VHT_CAP_MU_BEAMFORMEE_CAPABLE))
     170           3 :                 cap &= ~VHT_CAP_MU_BEAMFORMER_CAPABLE;
     171             : 
     172             :         /* mask channel widths we don't support */
     173           3 :         switch (own_cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK) {
     174             :         case VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ:
     175           0 :                 break;
     176             :         case VHT_CAP_SUPP_CHAN_WIDTH_160MHZ:
     177           0 :                 if (cap & VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ) {
     178           0 :                         cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ;
     179           0 :                         cap |= VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
     180             :                 }
     181           0 :                 break;
     182             :         default:
     183           3 :                 cap &= ~VHT_CAP_SUPP_CHAN_WIDTH_MASK;
     184           3 :                 break;
     185             :         }
     186             : 
     187           3 :         if (!(cap & VHT_CAP_SUPP_CHAN_WIDTH_MASK))
     188           3 :                 cap &= ~VHT_CAP_SHORT_GI_160;
     189             : 
     190             :         /*
     191             :          * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
     192             :          * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
     193             :          */
     194           3 :         if (!(own_cap & VHT_CAP_RXSTBC_MASK))
     195           2 :                 cap &= ~VHT_CAP_TXSTBC;
     196           3 :         if (!(own_cap & VHT_CAP_TXSTBC))
     197           2 :                 cap &= ~VHT_CAP_RXSTBC_MASK;
     198             : 
     199           3 :         neg_vht_cap->vht_capabilities_info = host_to_le32(cap);
     200             : }

Generated by: LCOV version 1.10