1 --- a/hostapd/config_file.c
2 +++ b/hostapd/config_file.c
3 @@ -1951,6 +1951,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 #endif /* CONFIG_IEEE80211N */
14 --- a/src/ap/ap_config.h
15 +++ b/src/ap/ap_config.h
16 @@ -434,6 +434,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 @@ -306,6 +307,7 @@ static void hostapd_cleanup_iface_pre(st
36 static void hostapd_cleanup_iface_partial(struct hostapd_iface *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 @@ -238,6 +238,9 @@ struct hostapd_iface {
45 /* Overlapping BSS information */
49 + struct os_time last_20mhz_trigger;
52 void (*scan_cb)(struct hostapd_iface *iface);
54 --- a/src/ap/ieee802_11.c
55 +++ b/src/ap/ieee802_11.c
56 @@ -1205,6 +1205,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 @@ -73,4 +73,17 @@ u8 * hostapd_eid_time_zone(struct hostap
69 int hostapd_update_time_adv(struct hostapd_data *hapd);
70 void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr);
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 "drivers/driver.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 @@ -70,12 +72,15 @@ u8 * hostapd_eid_ht_operation(struct hos
102 oper->control_chan = hapd->iconf->channel;
103 oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
104 - if (hapd->iconf->secondary_channel == 1)
105 - oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
106 - HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
107 - if (hapd->iconf->secondary_channel == -1)
108 - oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
109 - HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
111 + if (!hapd->iface->force_20mhz) {
112 + if (hapd->iconf->secondary_channel == 1)
113 + oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
114 + HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
115 + if (hapd->iconf->secondary_channel == -1)
116 + oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
117 + HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
120 pos += sizeof(*oper);
122 @@ -271,3 +276,80 @@ void hostapd_get_ht_capab(struct hostapd
124 neg_ht_cap->ht_capabilities_info = host_to_le16(cap);
127 +static void hostapd_set_force_20mhz(struct hostapd_iface *iface);
129 +static void hostapd_restore_40mhz(void *eloop_data, void *user_ctx)
131 + struct hostapd_iface *iface = eloop_data;
132 + struct os_time time;
135 + if (!iface->last_20mhz_trigger.sec)
138 + os_get_time(&time);
139 + timeout = iface->last_20mhz_trigger.sec + iface->conf->dynamic_ht40 -
143 + eloop_register_timeout(timeout, 0, hostapd_restore_40mhz,
148 + iface->last_20mhz_trigger.sec = 0;
149 + iface->last_20mhz_trigger.usec = 0;
151 + iface->force_20mhz = 0;
152 + hostapd_set_force_20mhz(iface);
155 +static void hostapd_set_force_20mhz(struct hostapd_iface *iface)
157 + int secondary_channel;
160 + ieee802_11_set_beacons(iface);
162 + for (i = 0; i < iface->num_bss; i++) {
163 + struct hostapd_data *hapd = iface->bss[i];
165 + if (iface->force_20mhz)
166 + secondary_channel = 0;
168 + secondary_channel = hapd->iconf->secondary_channel;
170 + if (hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
171 + hapd->iconf->channel,
172 + hapd->iconf->ieee80211n,
173 + secondary_channel)) {
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);