1 --- a/hostapd/config_file.c
2 +++ b/hostapd/config_file.c
3 @@ -1901,6 +1901,10 @@ struct hostapd_config * hostapd_config_r
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 @@ -393,6 +393,7 @@ struct hostapd_config {
18 int secondary_channel;
24 --- a/src/ap/hostapd.c
25 +++ b/src/ap/hostapd.c
26 @@ -285,6 +285,7 @@ static void hostapd_cleanup_iface_pre(st
28 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
30 + hostapd_deinit_ht(iface);
31 hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
32 iface->hw_features = NULL;
33 os_free(iface->current_rates);
34 --- a/src/ap/hostapd.h
35 +++ b/src/ap/hostapd.h
36 @@ -220,6 +220,9 @@ struct hostapd_iface {
37 /* Overlapping BSS information */
41 + struct os_time last_20mhz_trigger;
44 void (*scan_cb)(struct hostapd_iface *iface);
46 --- a/src/ap/ieee802_11.c
47 +++ b/src/ap/ieee802_11.c
48 @@ -1242,6 +1242,9 @@ static void handle_beacon(struct hostapd
49 sizeof(mgmt->u.beacon)), &elems,
52 + if (!elems.ht_capabilities)
53 + hostapd_trigger_20mhz(hapd->iface);
55 ap_list_process_beacon(hapd->iface, mgmt, &elems, fi);
58 --- a/src/ap/ieee802_11.h
59 +++ b/src/ap/ieee802_11.h
60 @@ -65,4 +65,17 @@ void hostapd_tx_status(struct hostapd_da
61 void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src,
64 +#ifdef CONFIG_IEEE80211N
65 +void hostapd_trigger_20mhz(struct hostapd_iface *iface);
66 +void hostapd_deinit_ht(struct hostapd_iface *iface);
69 +static inline void hostapd_deinit_ht(struct hostapd_iface *iface)
72 +static inline void hostapd_trigger_20mhz(struct hostapd_iface *iface)
75 +#endif /* CONFIG_IEEE80211N */
77 #endif /* IEEE802_11_H */
78 --- a/src/ap/ieee802_11_ht.c
79 +++ b/src/ap/ieee802_11_ht.c
80 @@ -70,12 +70,15 @@ u8 * hostapd_eid_ht_operation(struct hos
82 oper->control_chan = hapd->iconf->channel;
83 oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
84 - if (hapd->iconf->secondary_channel == 1)
85 - oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
86 - HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
87 - if (hapd->iconf->secondary_channel == -1)
88 - oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
89 - HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
91 + if (!hapd->iface->force_20mhz) {
92 + if (hapd->iconf->secondary_channel == 1)
93 + oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE |
94 + HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
95 + if (hapd->iconf->secondary_channel == -1)
96 + oper->ht_param |= HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW |
97 + HT_INFO_HT_PARAM_REC_TRANS_CHNL_WIDTH;
100 pos += sizeof(*oper);
102 @@ -265,3 +268,80 @@ void hostapd_get_ht_capab(struct hostapd
104 neg_ht_cap->ht_capabilities_info = host_to_le16(cap);
107 +static int hostapd_set_force_20mhz(struct hostapd_iface *iface);
109 +static int hostapd_restore_40mhz(void *eloop_data, void *user_ctx)
111 + struct hostapd_iface *iface = eloop_data;
112 + struct os_time time;
115 + if (!iface->last_20mhz_trigger.sec)
118 + os_get_time(&time);
119 + timeout = iface->last_20mhz_trigger.sec + iface->conf->dynamic_ht40 -
123 + eloop_register_timeout(timeout, 0, hostapd_restore_40mhz,
128 + iface->last_20mhz_trigger.sec = 0;
129 + iface->last_20mhz_trigger.usec = 0;
131 + iface->force_20mhz = 0;
132 + hostapd_set_force_20mhz(iface);
135 +static int hostapd_set_force_20mhz(struct hostapd_iface *iface)
137 + int secondary_channel;
140 + ieee802_11_set_beacons(iface);
142 + for (i = 0; i < iface->num_bss; i++) {
143 + struct hostapd_data *hapd = iface->bss[i];
145 + if (iface->force_20mhz)
146 + secondary_channel = 0;
148 + secondary_channel = hapd->iconf->secondary_channel;
150 + if (hostapd_set_freq(hapd, hapd->iconf->hw_mode, iface->freq,
151 + hapd->iconf->channel,
152 + hapd->iconf->ieee80211n,
153 + secondary_channel)) {
154 + wpa_printf(MSG_ERROR, "Could not set channel for "
160 +void hostapd_deinit_ht(struct hostapd_iface *iface)
162 + eloop_cancel_timeout(hostapd_restore_40mhz, iface, NULL);
165 +void hostapd_trigger_20mhz(struct hostapd_iface *iface)
167 + if (!iface->conf->dynamic_ht40)
170 + if (!iface->force_20mhz) {
171 + iface->force_20mhz = 1;
172 + hostapd_set_force_20mhz(iface);
175 + if (!iface->last_20mhz_trigger.sec) {
176 + eloop_cancel_timeout(hostapd_restore_40mhz, iface, NULL);
177 + eloop_register_timeout(iface->conf->dynamic_ht40, 0,
178 + hostapd_restore_40mhz, iface, NULL);
181 + os_get_time(&iface->last_20mhz_trigger);