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