1 --- a/hostapd/config_file.c
2 +++ b/hostapd/config_file.c
3 @@ -2648,6 +2648,10 @@ static int hostapd_config_fill(struct ho
7 + } else if (os_strcmp(buf, "dynamic_ht40") == 0) {
8 + conf->dynamic_ht40 = atoi(pos);
9 + if (conf->dynamic_ht40 == 1)
10 + conf->dynamic_ht40 = 1500;
11 } else if (os_strcmp(buf, "require_ht") == 0) {
12 conf->require_ht = atoi(pos);
13 } else if (os_strcmp(buf, "obss_interval") == 0) {
14 --- a/src/ap/ap_config.h
15 +++ b/src/ap/ap_config.h
16 @@ -580,6 +580,7 @@ struct hostapd_config {
18 int secondary_channel;
24 --- a/src/ap/hostapd.c
25 +++ b/src/ap/hostapd.c
29 #include "ieee802_1x.h"
30 +#include "ieee802_11.h"
31 #include "ieee802_11_auth.h"
32 #include "vlan_init.h"
34 @@ -328,6 +329,7 @@ static void hostapd_cleanup(struct hosta
35 static void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
37 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
38 + hostapd_deinit_ht(iface);
39 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
40 iface->hw_features = NULL;
41 os_free(iface->current_rates);
42 --- a/src/ap/hostapd.h
43 +++ b/src/ap/hostapd.h
44 @@ -330,6 +330,9 @@ struct hostapd_iface {
45 /* Overlapping BSS information */
49 + struct os_time last_20mhz_trigger;
53 /* surveying helpers */
54 --- a/src/ap/ieee802_11.c
55 +++ b/src/ap/ieee802_11.c
56 @@ -1556,6 +1556,9 @@ static void handle_beacon(struct hostapd
57 sizeof(mgmt->u.beacon)), &elems,
60 + if (!elems.ht_capabilities)
61 + hostapd_trigger_20mhz(hapd->iface);
63 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
66 --- a/src/ap/ieee802_11.h
67 +++ b/src/ap/ieee802_11.h
68 @@ -83,4 +83,17 @@ int hostapd_update_time_adv(struct hosta
69 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr);
70 u8 * hostapd_eid_bss_max_idle_period(struct hostapd_data *hapd, u8 *eid);
72 +#ifdef CONFIG_IEEE80211N
73 +void hostapd_trigger_20mhz(struct hostapd_iface *iface);
74 +void hostapd_deinit_ht(struct hostapd_iface *iface);
77 +static inline void hostapd_deinit_ht(struct hostapd_iface *iface)
80 +static inline void hostapd_trigger_20mhz(struct hostapd_iface *iface)
83 +#endif /* CONFIG_IEEE80211N */
85 #endif /* IEEE802_11_H */
86 --- a/src/ap/ieee802_11_ht.c
87 +++ b/src/ap/ieee802_11_ht.c
89 #include "common/ieee802_11_defs.h"
91 #include "ap_config.h"
92 +#include "ap_drv_ops.h"
95 #include "ieee802_11.h"
96 +#include "utils/eloop.h"
99 u8 * hostapd_eid_ht_capabilities(struct hostapd_data *hapd, u8 *eid)
100 @@ -92,6 +94,9 @@ u8 * hostapd_eid_ht_operation(struct hos
102 oper->primary_chan = hapd->iconf->channel;
103 oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
104 + if (hapd->iface->force_20mhz)
107 if (hapd->iconf->secondary_channel == 1)
108 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
109 HT_INFO_HT_PARAM_STA_CHNL_WIDTH;
110 @@ -99,6 +104,7 @@ u8 * hostapd_eid_ht_operation(struct hos
111 oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
112 HT_INFO_HT_PARAM_STA_CHNL_WIDTH;
115 pos += sizeof(*oper);
118 @@ -288,3 +294,84 @@ void hostapd_get_ht_capab(struct hostapd
120 neg_ht_cap->ht_capabilities_info = host_to_le16(cap);
123 +static void hostapd_set_force_20mhz(struct hostapd_iface *iface);
125 +static void hostapd_restore_40mhz(void *eloop_data, void *user_ctx)
127 + struct hostapd_iface *iface = eloop_data;
128 + struct os_time time;
131 + if (!iface->last_20mhz_trigger.sec)
134 + os_get_time(&time);
135 + timeout = iface->last_20mhz_trigger.sec + iface->conf->dynamic_ht40 -
139 + eloop_register_timeout(timeout, 0, hostapd_restore_40mhz,
144 + iface->last_20mhz_trigger.sec = 0;
145 + iface->last_20mhz_trigger.usec = 0;
147 + iface->force_20mhz = 0;
148 + hostapd_set_force_20mhz(iface);
151 +static void hostapd_set_force_20mhz(struct hostapd_iface *iface)
153 + int secondary_channel;
156 + ieee802_11_set_beacons(iface);
158 + for (i = 0; i < iface->num_bss; i++) {
159 + struct hostapd_data *hapd = iface->bss[i];
161 + if (iface->force_20mhz)
162 + secondary_channel = 0;
164 + secondary_channel = hapd->iconf->secondary_channel;
166 + if (hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
167 + hapd->iconf->channel,
168 + hapd->iconf->ieee80211n,
169 + hapd->iconf->ieee80211ac,
171 + hapd->iconf->vht_oper_chwidth,
172 + hapd->iconf->vht_oper_centr_freq_seg0_idx,
173 + hapd->iconf->vht_oper_centr_freq_seg1_idx)) {
174 + wpa_printf(MSG_ERROR, "Could not set channel for "
180 +void hostapd_deinit_ht(struct hostapd_iface *iface)
182 + eloop_cancel_timeout(hostapd_restore_40mhz, iface, NULL);
185 +void hostapd_trigger_20mhz(struct hostapd_iface *iface)
187 + if (!iface->conf->dynamic_ht40)
190 + if (!iface->force_20mhz) {
191 + iface->force_20mhz = 1;
192 + hostapd_set_force_20mhz(iface);
195 + if (!iface->last_20mhz_trigger.sec) {
196 + eloop_cancel_timeout(hostapd_restore_40mhz, iface, NULL);
197 + eloop_register_timeout(iface->conf->dynamic_ht40, 0,
198 + hostapd_restore_40mhz, iface, NULL);
201 + os_get_time(&iface->last_20mhz_trigger);