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 software may be distributed under the terms of the BSD license.
7 * See README for more details.
10 #include "utils/includes.h"
12 #include "utils/common.h"
13 #include "common/ieee802_11_defs.h"
15 #include "ap_config.h"
18 #include "ieee802_11.h"
21 u8 * hostapd_eid_ht_capabilities(struct hostapd_data *hapd, u8 *eid)
23 struct ieee80211_ht_capabilities *cap;
26 if (!hapd->iconf->ieee80211n || !hapd->iface->current_mode ||
27 hapd->conf->disable_11n)
30 *pos++ = WLAN_EID_HT_CAP;
31 *pos++ = sizeof(*cap);
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,
40 /* TODO: ht_extended_capabilities (now fully disabled) */
41 /* TODO: tx_bf_capability_info (now fully disabled) */
42 /* TODO: asel_capabilities (now fully disabled) */
46 if (hapd->iconf->obss_interval) {
47 struct ieee80211_obss_scan_parameters *scan_params;
49 *pos++ = WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS;
50 *pos++ = sizeof(*scan_params);
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);
57 /* TODO: Fill in more parameters (supplicant ignores them) */
59 pos += sizeof(*scan_params);
66 u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
68 struct ieee80211_ht_operation *oper;
71 if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
74 *pos++ = WLAN_EID_HT_OPERATION;
75 *pos++ = sizeof(*oper);
77 oper = (struct ieee80211_ht_operation *) pos;
78 os_memset(oper, 0, sizeof(*oper));
80 oper->control_chan = hapd->iconf->channel;
81 oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
82 if (hapd->iconf->secondary_channel == 1)
83 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
84 HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
85 if (hapd->iconf->secondary_channel == -1)
86 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
87 HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
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
106 int hostapd_ht_operation_update(struct hostapd_iface *iface)
108 u16 cur_op_mode, new_op_mode;
109 int op_mode_changes = 0;
111 if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
114 wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
115 __func__, iface->ht_op_mode);
117 if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
118 && iface->num_sta_ht_no_gf) {
120 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
122 } else if ((iface->ht_op_mode &
123 HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
124 iface->num_sta_ht_no_gf == 0) {
126 ~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
130 if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
131 (iface->num_sta_no_ht || iface->olbc_ht)) {
132 iface->ht_op_mode |= HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
134 } else if ((iface->ht_op_mode &
135 HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT) &&
136 (iface->num_sta_no_ht == 0 && !iface->olbc_ht)) {
138 ~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
143 if (iface->num_sta_no_ht)
144 new_op_mode = OP_MODE_MIXED;
145 else if (iface->conf->secondary_channel && iface->num_sta_ht_20mhz)
146 new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
147 else if (iface->olbc_ht)
148 new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
150 new_op_mode = OP_MODE_PURE;
152 cur_op_mode = iface->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
153 if (cur_op_mode != new_op_mode) {
154 iface->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
155 iface->ht_op_mode |= new_op_mode;
159 wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
160 __func__, iface->ht_op_mode, op_mode_changes);
162 return op_mode_changes;
166 u16 copy_sta_ht_capab(struct hostapd_data *hapd, struct sta_info *sta,
167 const u8 *ht_capab, size_t ht_capab_len)
169 /* Disable HT caps for STAs associated to no-HT BSSes. */
171 ht_capab_len < sizeof(struct ieee80211_ht_capabilities) ||
172 hapd->conf->disable_11n) {
173 sta->flags &= ~WLAN_STA_HT;
174 os_free(sta->ht_capabilities);
175 sta->ht_capabilities = NULL;
176 return WLAN_STATUS_SUCCESS;
179 if (sta->ht_capabilities == NULL) {
180 sta->ht_capabilities =
181 os_zalloc(sizeof(struct ieee80211_ht_capabilities));
182 if (sta->ht_capabilities == NULL)
183 return WLAN_STATUS_UNSPECIFIED_FAILURE;
186 sta->flags |= WLAN_STA_HT;
187 os_memcpy(sta->ht_capabilities, ht_capab,
188 sizeof(struct ieee80211_ht_capabilities));
190 return WLAN_STATUS_SUCCESS;
194 static void update_sta_ht(struct hostapd_data *hapd, struct sta_info *sta)
198 ht_capab = le_to_host16(sta->ht_capabilities->ht_capabilities_info);
199 wpa_printf(MSG_DEBUG, "HT: STA " MACSTR " HT Capabilities Info: "
200 "0x%04x", MAC2STR(sta->addr), ht_capab);
201 if ((ht_capab & HT_CAP_INFO_GREEN_FIELD) == 0) {
202 if (!sta->no_ht_gf_set) {
203 sta->no_ht_gf_set = 1;
204 hapd->iface->num_sta_ht_no_gf++;
206 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no greenfield, num "
207 "of non-gf stations %d",
208 __func__, MAC2STR(sta->addr),
209 hapd->iface->num_sta_ht_no_gf);
211 if ((ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
212 if (!sta->ht_20mhz_set) {
213 sta->ht_20mhz_set = 1;
214 hapd->iface->num_sta_ht_20mhz++;
216 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, num of "
218 __func__, MAC2STR(sta->addr),
219 hapd->iface->num_sta_ht_20mhz);
224 static void update_sta_no_ht(struct hostapd_data *hapd, struct sta_info *sta)
226 if (!sta->no_ht_set) {
228 hapd->iface->num_sta_no_ht++;
230 if (hapd->iconf->ieee80211n) {
231 wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no HT, num of "
232 "non-HT stations %d",
233 __func__, MAC2STR(sta->addr),
234 hapd->iface->num_sta_no_ht);
239 void update_ht_state(struct hostapd_data *hapd, struct sta_info *sta)
241 if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities)
242 update_sta_ht(hapd, sta);
244 update_sta_no_ht(hapd, sta);
246 if (hostapd_ht_operation_update(hapd->iface) > 0)
247 ieee802_11_set_beacons(hapd->iface);
251 void hostapd_get_ht_capab(struct hostapd_data *hapd,
252 struct ieee80211_ht_capabilities *ht_cap,
253 struct ieee80211_ht_capabilities *neg_ht_cap)
259 os_memcpy(neg_ht_cap, ht_cap, sizeof(*neg_ht_cap));
260 cap = le_to_host16(neg_ht_cap->ht_capabilities_info);
263 * Mask out HT features we don't support, but don't overwrite
264 * non-symmetric features like STBC and SMPS. Just because
265 * we're not in dynamic SMPS mode the STA might still be.
267 cap &= (hapd->iconf->ht_capab | HT_CAP_INFO_RX_STBC_MASK |
268 HT_CAP_INFO_TX_STBC | HT_CAP_INFO_SMPS_MASK);
271 * STBC needs to be handled specially
272 * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
273 * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
275 if (!(hapd->iconf->ht_capab & HT_CAP_INFO_RX_STBC_MASK))
276 cap &= ~HT_CAP_INFO_TX_STBC;
277 if (!(hapd->iconf->ht_capab & HT_CAP_INFO_TX_STBC))
278 cap &= ~HT_CAP_INFO_RX_STBC_MASK;
280 neg_ht_cap->ht_capabilities_info = host_to_le16(cap);