2 * hostapd / IEEE 802.11n HT
3 * Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
4 * Copyright (c) 2007-2008, Intel Corporation
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * See README and COPYING for more details.
16 #include "utils/includes.h"
18 #include "utils/common.h"
19 #include "common/ieee802_11_defs.h"
20 #include "drivers/driver.h"
22 #include "ap_config.h"
25 #include "ieee802_11.h"
28 u8 * hostapd_eid_ht_capabilities(struct hostapd_data *hapd, u8 *eid)
30 struct ieee80211_ht_capabilities *cap;
33 if (!hapd->iconf->ieee80211n || !hapd->iface->current_mode ||
34 hapd->conf->disable_11n)
37 *pos++ = WLAN_EID_HT_CAP;
38 *pos++ = sizeof(*cap);
40 cap = (struct ieee80211_ht_capabilities *) pos;
41 os_memset(cap, 0, sizeof(*cap));
42 cap->ht_capabilities_info = host_to_le16(hapd->iconf->ht_capab);
43 cap->a_mpdu_params = hapd->iface->current_mode->a_mpdu_params;
44 os_memcpy(cap->supported_mcs_set, hapd->iface->current_mode->mcs_set,
47 /* TODO: ht_extended_capabilities (now fully disabled) */
48 /* TODO: tx_bf_capability_info (now fully disabled) */
49 /* TODO: asel_capabilities (now fully disabled) */
57 u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
59 struct ieee80211_ht_operation *oper;
62 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
65 *pos++ = WLAN_EID_HT_OPERATION;
66 *pos++ = sizeof(*oper);
68 oper = (struct ieee80211_ht_operation *) pos;
69 os_memset(oper, 0, sizeof(*oper));
71 oper->control_chan = hapd->iconf->channel;
72 oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
73 if (hapd->iconf->secondary_channel == 1)
74 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
75 HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
76 if (hapd->iconf->secondary_channel == -1)
77 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
78 HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
88 Set to 0 (HT pure) under the followign conditions
89 - all STAs in the BSS are 20/40 MHz HT in 20/40 MHz BSS or
90 - all STAs in the BSS are 20 MHz HT in 20 MHz BSS
91 Set to 1 (HT non-member protection) if there may be non-HT STAs
92 in both the primary and the secondary channel
93 Set to 2 if only HT STAs are associated in BSS,
94 however and at least one 20 MHz HT STA is associated
95 Set to 3 (HT mixed mode) when one or more non-HT STAs are associated
97 int hostapd_ht_operation_update(struct hostapd_iface *iface)
99 u16 cur_op_mode, new_op_mode;
100 int op_mode_changes = 0;
102 if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
105 wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
106 __func__, iface->ht_op_mode);
108 if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
109 && iface->num_sta_ht_no_gf) {
111 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
113 } else if ((iface->ht_op_mode &
114 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
115 iface->num_sta_ht_no_gf == 0) {
117 ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
121 if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
122 (iface->num_sta_no_ht || iface->olbc_ht)) {
123 iface->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
125 } else if ((iface->ht_op_mode &
126 HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
127 (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
129 ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
134 if (iface->num_sta_no_ht)
135 new_op_mode = OP_MODE_MIXED;
136 else if ((iface->conf->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)
137 && iface->num_sta_ht_20mhz)
138 new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
139 else if (iface->olbc_ht)
140 new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
142 new_op_mode = OP_MODE_PURE;
144 cur_op_mode = iface->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
145 if (cur_op_mode != new_op_mode) {
146 iface->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
147 iface->ht_op_mode |= new_op_mode;
151 wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
152 __func__, iface->ht_op_mode, op_mode_changes);
154 return op_mode_changes;
158 u16 copy_sta_ht_capab(struct hostapd_data *hapd, struct sta_info *sta,
159 const u8 *ht_capab, size_t ht_capab_len)
161 /* Disable HT caps for STAs associated to no-HT BSSes. */
163 ht_capab_len < sizeof(struct ieee80211_ht_capabilities) ||
164 hapd->conf->disable_11n) {
165 sta->flags &= ~WLAN_STA_HT;
166 os_free(sta->ht_capabilities);
167 sta->ht_capabilities = NULL;
168 return WLAN_STATUS_SUCCESS;
171 if (sta->ht_capabilities == NULL) {
172 sta->ht_capabilities =
173 os_zalloc(sizeof(struct ieee80211_ht_capabilities));
174 if (sta->ht_capabilities == NULL)
175 return WLAN_STATUS_UNSPECIFIED_FAILURE;
178 sta->flags |= WLAN_STA_HT;
179 os_memcpy(sta->ht_capabilities, ht_capab,
180 sizeof(struct ieee80211_ht_capabilities));
182 return WLAN_STATUS_SUCCESS;
186 static void update_sta_ht(struct hostapd_data *hapd, struct sta_info *sta)
190 ht_capab = le_to_host16(sta->ht_capabilities->ht_capabilities_info);
191 wpa_printf(MSG_DEBUG, "HT: STA " MACSTR " HT Capabilities Info: "
192 "0x%04x", MAC2STR(sta->addr), ht_capab);
193 if ((ht_capab & HT_CAP_INFO_GREEN_FIELD) == 0) {
194 if (!sta->no_ht_gf_set) {
195 sta->no_ht_gf_set = 1;
196 hapd->iface->num_sta_ht_no_gf++;
198 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no greenfield, num "
199 "of non-gf stations %d",
200 __func__, MAC2STR(sta->addr),
201 hapd->iface->num_sta_ht_no_gf);
203 if ((ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
204 if (!sta->ht_20mhz_set) {
205 sta->ht_20mhz_set = 1;
206 hapd->iface->num_sta_ht_20mhz++;
208 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, num of "
210 __func__, MAC2STR(sta->addr),
211 hapd->iface->num_sta_ht_20mhz);
216 static void update_sta_no_ht(struct hostapd_data *hapd, struct sta_info *sta)
218 if (!sta->no_ht_set) {
220 hapd->iface->num_sta_no_ht++;
222 if (hapd->iconf->ieee80211n) {
223 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no HT, num of "
224 "non-HT stations %d",
225 __func__, MAC2STR(sta->addr),
226 hapd->iface->num_sta_no_ht);
231 void update_ht_state(struct hostapd_data *hapd, struct sta_info *sta)
233 if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities)
234 update_sta_ht(hapd, sta);
236 update_sta_no_ht(hapd, sta);
238 if (hostapd_ht_operation_update(hapd->iface) > 0)
239 ieee802_11_set_beacons(hapd->iface);
243 void hostapd_get_ht_capab(struct hostapd_data *hapd,
244 struct ieee80211_ht_capabilities *ht_cap,
245 struct ieee80211_ht_capabilities *neg_ht_cap)
251 os_memcpy(neg_ht_cap, ht_cap, sizeof(*neg_ht_cap));
252 cap = le_to_host16(neg_ht_cap->ht_capabilities_info);
255 * Mask out HT features we don't support, but don't overwrite
256 * non-symmetric features like STBC and SMPS. Just because
257 * we're not in dynamic SMPS mode the STA might still be.
259 cap &= (hapd->iconf->ht_capab | HT_CAP_INFO_RX_STBC_MASK |
260 HT_CAP_INFO_TX_STBC | HT_CAP_INFO_SMPS_MASK);
263 * STBC needs to be handled specially
264 * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
265 * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
267 if (!(hapd->iconf->ht_capab & HT_CAP_INFO_RX_STBC_MASK))
268 cap &= ~HT_CAP_INFO_TX_STBC;
269 if (!(hapd->iconf->ht_capab & HT_CAP_INFO_TX_STBC))
270 cap &= ~HT_CAP_INFO_RX_STBC_MASK;
272 neg_ht_cap->ht_capabilities_info = host_to_le16(cap);