• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 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.
9  *
10  * Alternatively, this software may be distributed under the terms of BSD
11  * license.
12  *
13  * See README and COPYING for more details.
14  */
15 
16 #include "utils/includes.h"
17 
18 #include "utils/common.h"
19 #include "common/ieee802_11_defs.h"
20 #include "drivers/driver.h"
21 #include "hostapd.h"
22 #include "ap_config.h"
23 #include "sta_info.h"
24 #include "beacon.h"
25 #include "ieee802_11.h"
26 
27 
hostapd_eid_ht_capabilities(struct hostapd_data * hapd,u8 * eid)28 u8 * hostapd_eid_ht_capabilities(struct hostapd_data *hapd, u8 *eid)
29 {
30 	struct ieee80211_ht_capabilities *cap;
31 	u8 *pos = eid;
32 
33 	if (!hapd->iconf->ieee80211n || !hapd->iface->current_mode ||
34 	    hapd->conf->disable_11n)
35 		return eid;
36 
37 	*pos++ = WLAN_EID_HT_CAP;
38 	*pos++ = sizeof(*cap);
39 
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,
45 		  16);
46 
47 	/* TODO: ht_extended_capabilities (now fully disabled) */
48 	/* TODO: tx_bf_capability_info (now fully disabled) */
49 	/* TODO: asel_capabilities (now fully disabled) */
50 
51  	pos += sizeof(*cap);
52 
53 	return pos;
54 }
55 
56 
hostapd_eid_ht_operation(struct hostapd_data * hapd,u8 * eid)57 u8 * hostapd_eid_ht_operation(struct hostapd_data *hapd, u8 *eid)
58 {
59 	struct ieee80211_ht_operation *oper;
60 	u8 *pos = eid;
61 
62 	if (!hapd->iconf->ieee80211n || hapd->conf->disable_11n)
63 		return eid;
64 
65 	*pos++ = WLAN_EID_HT_OPERATION;
66 	*pos++ = sizeof(*oper);
67 
68 	oper = (struct ieee80211_ht_operation *) pos;
69 	os_memset(oper, 0, sizeof(*oper));
70 
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;
79 
80 	pos += sizeof(*oper);
81 
82 	return pos;
83 }
84 
85 
86 /*
87 op_mode
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
96 */
hostapd_ht_operation_update(struct hostapd_iface * iface)97 int hostapd_ht_operation_update(struct hostapd_iface *iface)
98 {
99 	u16 cur_op_mode, new_op_mode;
100 	int op_mode_changes = 0;
101 
102 	if (!iface->conf->ieee80211n || iface->conf->ht_op_mode_fixed)
103 		return 0;
104 
105 	wpa_printf(MSG_DEBUG, "%s current operation mode=0x%X",
106 		   __func__, iface->ht_op_mode);
107 
108 	if (!(iface->ht_op_mode & HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT)
109 	    && iface->num_sta_ht_no_gf) {
110 		iface->ht_op_mode |=
111 			HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
112 		op_mode_changes++;
113 	} else if ((iface->ht_op_mode &
114 		    HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT) &&
115 		   iface->num_sta_ht_no_gf == 0) {
116 		iface->ht_op_mode &=
117 			~HT_INFO_OPERATION_MODE_NON_GF_DEVS_PRESENT;
118 		op_mode_changes++;
119 	}
120 
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;
124 		op_mode_changes++;
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)) {
128 		iface->ht_op_mode &=
129 			~HT_INFO_OPERATION_MODE_NON_HT_STA_PRESENT;
130 		op_mode_changes++;
131 	}
132 
133 	new_op_mode = 0;
134 	if (iface->num_sta_no_ht)
135 		new_op_mode = OP_MODE_MIXED;
136 	else if (iface->conf->secondary_channel && iface->num_sta_ht_20mhz)
137 		new_op_mode = OP_MODE_20MHZ_HT_STA_ASSOCED;
138 	else if (iface->olbc_ht)
139 		new_op_mode = OP_MODE_MAY_BE_LEGACY_STAS;
140 	else
141 		new_op_mode = OP_MODE_PURE;
142 
143 	cur_op_mode = iface->ht_op_mode & HT_INFO_OPERATION_MODE_OP_MODE_MASK;
144 	if (cur_op_mode != new_op_mode) {
145 		iface->ht_op_mode &= ~HT_INFO_OPERATION_MODE_OP_MODE_MASK;
146 		iface->ht_op_mode |= new_op_mode;
147 		op_mode_changes++;
148 	}
149 
150 	wpa_printf(MSG_DEBUG, "%s new operation mode=0x%X changes=%d",
151 		   __func__, iface->ht_op_mode, op_mode_changes);
152 
153 	return op_mode_changes;
154 }
155 
156 
copy_sta_ht_capab(struct hostapd_data * hapd,struct sta_info * sta,const u8 * ht_capab,size_t ht_capab_len)157 u16 copy_sta_ht_capab(struct hostapd_data *hapd, struct sta_info *sta,
158 		      const u8 *ht_capab, size_t ht_capab_len)
159 {
160 	/* Disable HT caps for STAs associated to no-HT BSSes. */
161 	if (!ht_capab ||
162 	    ht_capab_len < sizeof(struct ieee80211_ht_capabilities) ||
163 	    hapd->conf->disable_11n) {
164 		sta->flags &= ~WLAN_STA_HT;
165 		os_free(sta->ht_capabilities);
166 		sta->ht_capabilities = NULL;
167 		return WLAN_STATUS_SUCCESS;
168 	}
169 
170 	if (sta->ht_capabilities == NULL) {
171 		sta->ht_capabilities =
172 			os_zalloc(sizeof(struct ieee80211_ht_capabilities));
173 		if (sta->ht_capabilities == NULL)
174 			return WLAN_STATUS_UNSPECIFIED_FAILURE;
175 	}
176 
177 	sta->flags |= WLAN_STA_HT;
178 	os_memcpy(sta->ht_capabilities, ht_capab,
179 		  sizeof(struct ieee80211_ht_capabilities));
180 
181 	return WLAN_STATUS_SUCCESS;
182 }
183 
184 
update_sta_ht(struct hostapd_data * hapd,struct sta_info * sta)185 static void update_sta_ht(struct hostapd_data *hapd, struct sta_info *sta)
186 {
187 	u16 ht_capab;
188 
189 	ht_capab = le_to_host16(sta->ht_capabilities->ht_capabilities_info);
190 	wpa_printf(MSG_DEBUG, "HT: STA " MACSTR " HT Capabilities Info: "
191 		   "0x%04x", MAC2STR(sta->addr), ht_capab);
192 	if ((ht_capab & HT_CAP_INFO_GREEN_FIELD) == 0) {
193 		if (!sta->no_ht_gf_set) {
194 			sta->no_ht_gf_set = 1;
195 			hapd->iface->num_sta_ht_no_gf++;
196 		}
197 		wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no greenfield, num "
198 			   "of non-gf stations %d",
199 			   __func__, MAC2STR(sta->addr),
200 			   hapd->iface->num_sta_ht_no_gf);
201 	}
202 	if ((ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET) == 0) {
203 		if (!sta->ht_20mhz_set) {
204 			sta->ht_20mhz_set = 1;
205 			hapd->iface->num_sta_ht_20mhz++;
206 		}
207 		wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - 20 MHz HT, num of "
208 			   "20MHz HT STAs %d",
209 			   __func__, MAC2STR(sta->addr),
210 			   hapd->iface->num_sta_ht_20mhz);
211 	}
212 }
213 
214 
update_sta_no_ht(struct hostapd_data * hapd,struct sta_info * sta)215 static void update_sta_no_ht(struct hostapd_data *hapd, struct sta_info *sta)
216 {
217 	if (!sta->no_ht_set) {
218 		sta->no_ht_set = 1;
219 		hapd->iface->num_sta_no_ht++;
220 	}
221 	if (hapd->iconf->ieee80211n) {
222 		wpa_printf(MSG_DEBUG, "%s STA " MACSTR " - no HT, num of "
223 			   "non-HT stations %d",
224 			   __func__, MAC2STR(sta->addr),
225 			   hapd->iface->num_sta_no_ht);
226 	}
227 }
228 
229 
update_ht_state(struct hostapd_data * hapd,struct sta_info * sta)230 void update_ht_state(struct hostapd_data *hapd, struct sta_info *sta)
231 {
232 	if ((sta->flags & WLAN_STA_HT) && sta->ht_capabilities)
233 		update_sta_ht(hapd, sta);
234 	else
235 		update_sta_no_ht(hapd, sta);
236 
237 	if (hostapd_ht_operation_update(hapd->iface) > 0)
238 		ieee802_11_set_beacons(hapd->iface);
239 }
240 
241 
hostapd_get_ht_capab(struct hostapd_data * hapd,struct ieee80211_ht_capabilities * ht_cap,struct ieee80211_ht_capabilities * neg_ht_cap)242 void hostapd_get_ht_capab(struct hostapd_data *hapd,
243 			  struct ieee80211_ht_capabilities *ht_cap,
244 			  struct ieee80211_ht_capabilities *neg_ht_cap)
245 {
246 	u16 cap;
247 
248 	if (ht_cap == NULL)
249 		return;
250 	os_memcpy(neg_ht_cap, ht_cap, sizeof(*neg_ht_cap));
251 	cap = le_to_host16(neg_ht_cap->ht_capabilities_info);
252 
253 	/*
254 	 * Mask out HT features we don't support, but don't overwrite
255 	 * non-symmetric features like STBC and SMPS. Just because
256 	 * we're not in dynamic SMPS mode the STA might still be.
257 	 */
258 	cap &= (hapd->iconf->ht_capab | HT_CAP_INFO_RX_STBC_MASK |
259 		HT_CAP_INFO_TX_STBC | HT_CAP_INFO_SMPS_MASK);
260 
261 	/*
262 	 * STBC needs to be handled specially
263 	 * if we don't support RX STBC, mask out TX STBC in the STA's HT caps
264 	 * if we don't support TX STBC, mask out RX STBC in the STA's HT caps
265 	 */
266 	if (!(hapd->iconf->ht_capab & HT_CAP_INFO_RX_STBC_MASK))
267 		cap &= ~HT_CAP_INFO_TX_STBC;
268 	if (!(hapd->iconf->ht_capab & HT_CAP_INFO_TX_STBC))
269 		cap &= ~HT_CAP_INFO_RX_STBC_MASK;
270 
271 	neg_ht_cap->ht_capabilities_info = host_to_le16(cap);
272 }
273