ieee802_11_ht.c
Go to the documentation of this file.
00001 /*
00002  * hostapd / IEEE 802.11n HT
00003  * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
00004  * Copyright (c) 2007-2008, Intel Corporation
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License version 2 as
00008  * published by the Free Software Foundation.
00009  *
00010  * Alternatively, this software may be distributed under the terms of BSD
00011  * license.
00012  *
00013  * See README and COPYING for more details.
00014  */
00015 
00016 #include "utils/includes.h"
00017 
00018 #include "utils/common.h"
00019 #include "common/ieee802_11_defs.h"
00020 #include "drivers/driver.h"
00021 #include "hostapd.h"
00022 #include "ap_config.h"
00023 #include "sta_info.h"
00024 #include "beacon.h"
00025 #include "ieee802_11.h"
00026 
00027 
00028 u8 * hostapd_eid_ht_capabilities(struct hostapd_data *hapd, u8 *eid)
00029 {
00030         struct ieee80211_ht_capabilities *cap;
00031         u8 *pos = eid;
00032 
00033         if (!hapd->iconf->ieee80211n)
00034                 return eid;
00035 
00036         *pos++ = WLAN_EID_HT_CAP;
00037         *pos++ = sizeof(*cap);
00038 
00039         cap = (struct ieee80211_ht_capabilities *) pos;
00040         os_memset(cap, 0, sizeof(*cap));
00041         cap->ht_capabilities_info = host_to_le16(hapd->iconf->ht_capab);
00042         cap->a_mpdu_params = hapd->iface->current_mode->a_mpdu_params;
00043         os_memcpy(cap->supported_mcs_set, hapd->iface->current_mode->mcs_set,
00044                   16);
00045 
00046         /* TODO: ht_extended_capabilities (now fully disabled) */
00047         /* TODO: tx_bf_capability_info (now fully disabled) */
00048         /* TODO: asel_capabilities (now fully disabled) */
00049 
00050         pos += sizeof(*cap);
00051 
00052         return pos;
00053 }
00054 
00055 
00056 u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
00057 {
00058         struct ieee80211_ht_operation *oper;
00059         u8 *pos = eid;
00060 
00061         if (!hapd->iconf->ieee80211n)
00062                 return eid;
00063 
00064         *pos++ = WLAN_EID_HT_OPERATION;
00065         *pos++ = sizeof(*oper);
00066 
00067         oper = (struct ieee80211_ht_operation *) pos;
00068         os_memset(oper, 0, sizeof(*oper));
00069 
00070         oper->control_chan = hapd->iconf->channel;
00071         oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
00072         if (hapd->iconf->secondary_channel == 1)
00073                 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
00074                         HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
00075         if (hapd->iconf->secondary_channel == -1)
00076                 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
00077                         HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
00078 
00079         pos += sizeof(*oper);
00080 
00081         return pos;
00082 }
00083 
00084 
00085 /*
00086 op_mode
00087 Set to 0 (HT pure) under the followign conditions
00088         - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
00089         - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
00090 Set to 1 (HT non-member protection) if there may be non-HT STAs
00091         in both the primary and the secondary channel
00092 Set to 2 if only HT STAs are associated in BSS,
00093         however and at least one 20 MHz HT STA is associated
00094 Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
00095         (currently non-GF HT station is considered as non-HT STA also)
00096 */
00097 int hostapd_ht_operation_update(struct hostapd_iface *iface)
00098 {
00099         u16 cur_op_mode, new_op_mode;
00100         int op_mode_changes = 0;
00101 
00102         if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
00103                 return 0;
00104 
00105         wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
00106                    __func__, iface->ht_op_mode);
00107 
00108         if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
00109             && iface->num_sta_ht_no_gf) {
00110                 iface->ht_op_mode |=
00111                         HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
00112                 op_mode_changes++;
00113         } else if ((iface->ht_op_mode &
00114                     HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
00115                    iface->num_sta_ht_no_gf == 0) {
00116                 iface->ht_op_mode &=
00117                         ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
00118                 op_mode_changes++;
00119         }
00120 
00121         if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
00122             (iface->num_sta_no_ht || iface->olbc_ht)) {
00123                 iface->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
00124                 op_mode_changes++;
00125         } else if ((iface->ht_op_mode &
00126                     HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
00127                    (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
00128                 iface->ht_op_mode &=
00129                         ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
00130                 op_mode_changes++;
00131         }
00132 
00133         /* Note: currently we switch to the MIXED op mode if HT non-greenfield
00134          * station is associated. Probably it's a theoretical case, since
00135          * it looks like all known HT STAs support greenfield.
00136          */
00137         new_op_mode = 0;
00138         if (iface->num_sta_no_ht ||
00139             (iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT))
00140                 new_op_mode = OP_MODE_MIXED;
00141         else if ((iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)
00142                  && iface->num_sta_ht_20mhz)
00143                 new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
00144         else if (iface->olbc_ht)
00145                 new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
00146         else
00147                 new_op_mode = OP_MODE_PURE;
00148 
00149         cur_op_mode = iface->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
00150         if (cur_op_mode != new_op_mode) {
00151                 iface->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
00152                 iface->ht_op_mode |= new_op_mode;
00153                 op_mode_changes++;
00154         }
00155 
00156         wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
00157                    __func__, iface->ht_op_mode, op_mode_changes);
00158 
00159         return op_mode_changes;
00160 }
00161 
00162 
00163 u16 copy_sta_ht_capab(struct sta_info *sta, const u8 *ht_capab,
00164                       size_t ht_capab_len)
00165 {
00166         if (!ht_capab ||
00167             ht_capab_len < sizeof(struct ieee80211_ht_capabilities)) {
00168                 sta->flags &= ~WLAN_STA_HT;
00169                 os_free(sta->ht_capabilities);
00170                 sta->ht_capabilities = NULL;
00171                 return WLAN_STATUS_SUCCESS;
00172         }
00173 
00174         if (sta->ht_capabilities == NULL) {
00175                 sta->ht_capabilities =
00176                         os_zalloc(sizeof(struct ieee80211_ht_capabilities));
00177                 if (sta->ht_capabilities == NULL)
00178                         return WLAN_STATUS_UNSPECIFIED_FAILURE;
00179         }
00180 
00181         sta->flags |= WLAN_STA_HT;
00182         os_memcpy(sta->ht_capabilities, ht_capab,
00183                   sizeof(struct ieee80211_ht_capabilities));
00184 
00185         return WLAN_STATUS_SUCCESS;
00186 }
00187 
00188 
00189 static void update_sta_ht(struct hostapd_data *hapd, struct sta_info *sta)
00190 {
00191         u16 ht_capab;
00192 
00193         ht_capab = le_to_host16(sta->ht_capabilities->ht_capabilities_info);
00194         wpa_printf(MSG_DEBUG, "HT: STA " MACSTR " HT Capabilities Info: "
00195                    "0x%04x", MAC2STR(sta->addr), ht_capab);
00196         if ((ht_capab & HT_CAP_INFO_GREEN_FIELD) == 0) {
00197                 if (!sta->no_ht_gf_set) {
00198                         sta->no_ht_gf_set = 1;
00199                         hapd->iface->num_sta_ht_no_gf++;
00200                 }
00201                 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no greenfield, num "
00202                            "of non-gf stations %d",
00203                            __func__, MAC2STR(sta->addr),
00204                            hapd->iface->num_sta_ht_no_gf);
00205         }
00206         if ((ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
00207                 if (!sta->ht_20mhz_set) {
00208                         sta->ht_20mhz_set = 1;
00209                         hapd->iface->num_sta_ht_20mhz++;
00210                 }
00211                 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, num of "
00212                            "20MHz HT STAs %d",
00213                            __func__, MAC2STR(sta->addr),
00214                            hapd->iface->num_sta_ht_20mhz);
00215         }
00216 }
00217 
00218 
00219 static void update_sta_no_ht(struct hostapd_data *hapd, struct sta_info *sta)
00220 {
00221         if (!sta->no_ht_set) {
00222                 sta->no_ht_set = 1;
00223                 hapd->iface->num_sta_no_ht++;
00224         }
00225         if (hapd->iconf->ieee80211n) {
00226                 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no HT, num of "
00227                            "non-HT stations %d",
00228                            __func__, MAC2STR(sta->addr),
00229                            hapd->iface->num_sta_no_ht);
00230         }
00231 }
00232 
00233 
00234 void update_ht_state(struct hostapd_data *hapd, struct sta_info *sta)
00235 {
00236         if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities)
00237                 update_sta_ht(hapd, sta);
00238         else
00239                 update_sta_no_ht(hapd, sta);
00240 
00241         if (hostapd_ht_operation_update(hapd->iface) > 0)
00242                 ieee802_11_set_beacons(hapd->iface);
00243 }
00244 
00245 
00246 void hostapd_get_ht_capab(struct hostapd_data *hapd,
00247                           struct ieee80211_ht_capabilities *ht_cap,
00248                           struct ieee80211_ht_capabilities *neg_ht_cap)
00249 {
00250         u16 cap;
00251 
00252         if (ht_cap == NULL)
00253                 return;
00254         os_memcpy(neg_ht_cap, ht_cap, sizeof(*neg_ht_cap));
00255         cap = le_to_host16(neg_ht_cap->ht_capabilities_info);
00256         cap &= hapd->iconf->ht_capab;
00257         cap |= (hapd->iconf->ht_capab & HT_CAP_INFO_SMPS_DISABLED);
00258 
00259         /* FIXME: Rx STBC needs to be handled specially */
00260         cap |= (hapd->iconf->ht_capab & HT_CAP_INFO_RX_STBC_MASK);
00261         neg_ht_cap->ht_capabilities_info = host_to_le16(cap);
00262 }


wpa_supplicant
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Jan 2 2014 11:26:38