hostapd: enhance wifi reload
[openwrt/openwrt.git] / package / network / services / hostapd / patches / 700-wifi-reload.patch
1 Index: hostapd-2019-08-08-ca8c2bd2/hostapd/config_file.c
2 ===================================================================
3 --- hostapd-2019-08-08-ca8c2bd2.orig/hostapd/config_file.c
4 +++ hostapd-2019-08-08-ca8c2bd2/hostapd/config_file.c
5 @@ -2470,6 +2470,8 @@ static int hostapd_config_fill(struct ho
6 bss->isolate = atoi(pos);
7 } else if (os_strcmp(buf, "ap_max_inactivity") == 0) {
8 bss->ap_max_inactivity = atoi(pos);
9 + } else if (os_strcmp(buf, "config_id") == 0) {
10 + bss->config_id = os_strdup(pos);
11 } else if (os_strcmp(buf, "skip_inactivity_poll") == 0) {
12 bss->skip_inactivity_poll = atoi(pos);
13 } else if (os_strcmp(buf, "country_code") == 0) {
14 @@ -3131,6 +3133,8 @@ static int hostapd_config_fill(struct ho
15 }
16 } else if (os_strcmp(buf, "acs_exclude_dfs") == 0) {
17 conf->acs_exclude_dfs = atoi(pos);
18 + } else if (os_strcmp(buf, "radio_config_id") == 0) {
19 + conf->config_id = os_strdup(pos);
20 } else if (os_strcmp(buf, "channel") == 0) {
21 if (os_strcmp(pos, "acs_survey") == 0) {
22 #ifndef CONFIG_ACS
23 Index: hostapd-2019-08-08-ca8c2bd2/src/ap/ap_config.c
24 ===================================================================
25 --- hostapd-2019-08-08-ca8c2bd2.orig/src/ap/ap_config.c
26 +++ hostapd-2019-08-08-ca8c2bd2/src/ap/ap_config.c
27 @@ -698,6 +698,7 @@ void hostapd_config_free_bss(struct host
28 os_free(conf->radius_req_attr_sqlite);
29 os_free(conf->rsn_preauth_interfaces);
30 os_free(conf->ctrl_interface);
31 + os_free(conf->config_id);
32 os_free(conf->ca_cert);
33 os_free(conf->server_cert);
34 os_free(conf->server_cert2);
35 @@ -881,6 +882,7 @@ void hostapd_config_free(struct hostapd_
36
37 for (i = 0; i < conf->num_bss; i++)
38 hostapd_config_free_bss(conf->bss[i]);
39 + os_free(conf->config_id);
40 os_free(conf->bss);
41 os_free(conf->supported_rates);
42 os_free(conf->basic_rates);
43 Index: hostapd-2019-08-08-ca8c2bd2/src/ap/ap_config.h
44 ===================================================================
45 --- hostapd-2019-08-08-ca8c2bd2.orig/src/ap/ap_config.h
46 +++ hostapd-2019-08-08-ca8c2bd2/src/ap/ap_config.h
47 @@ -829,6 +829,7 @@ struct hostapd_bss_config {
48 */
49 u8 mka_psk_set;
50 #endif /* CONFIG_MACSEC */
51 + char *config_id;
52 };
53
54 /**
55 @@ -1012,6 +1013,7 @@ struct hostapd_config {
56 unsigned int airtime_update_interval;
57 #define AIRTIME_MODE_MAX (__AIRTIME_MODE_MAX - 1)
58 #endif /* CONFIG_AIRTIME_POLICY */
59 + char *config_id;
60 };
61
62
63 Index: hostapd-2019-08-08-ca8c2bd2/src/ap/hostapd.c
64 ===================================================================
65 --- hostapd-2019-08-08-ca8c2bd2.orig/src/ap/hostapd.c
66 +++ hostapd-2019-08-08-ca8c2bd2/src/ap/hostapd.c
67 @@ -206,6 +206,10 @@ static int hostapd_iface_conf_changed(st
68 {
69 size_t i;
70
71 + if (newconf->config_id != oldconf->config_id)
72 + if (strcmp(newconf->config_id, oldconf->config_id))
73 + return 1;
74 +
75 if (newconf->num_bss != oldconf->num_bss)
76 return 1;
77
78 @@ -219,7 +223,7 @@ static int hostapd_iface_conf_changed(st
79 }
80
81
82 -int hostapd_reload_config(struct hostapd_iface *iface)
83 +int hostapd_reload_config(struct hostapd_iface *iface, int reconf)
84 {
85 struct hapd_interfaces *interfaces = iface->interfaces;
86 struct hostapd_data *hapd = iface->bss[0];
87 @@ -242,13 +246,16 @@ int hostapd_reload_config(struct hostapd
88 if (newconf == NULL)
89 return -1;
90
91 - hostapd_clear_old(iface);
92 -
93 oldconf = hapd->iconf;
94 if (hostapd_iface_conf_changed(newconf, oldconf)) {
95 char *fname;
96 int res;
97
98 + if (reconf)
99 + return -1;
100 +
101 + hostapd_clear_old(iface);
102 +
103 wpa_printf(MSG_DEBUG,
104 "Configuration changes include interface/BSS modification - force full disable+enable sequence");
105 fname = os_strdup(iface->config_fname);
106 @@ -273,6 +280,22 @@ int hostapd_reload_config(struct hostapd
107 wpa_printf(MSG_ERROR,
108 "Failed to enable interface on config reload");
109 return res;
110 + } else {
111 + for (j = 0; j < iface->num_bss; j++) {
112 + hapd = iface->bss[j];
113 + if (!hapd->config_id || strcmp(hapd->config_id, newconf->bss[j]->config_id)) {
114 + hostapd_flush_old_stations(iface->bss[j],
115 + WLAN_REASON_PREV_AUTH_NOT_VALID);
116 + hostapd_broadcast_wep_clear(iface->bss[j]);
117 +
118 +#ifndef CONFIG_NO_RADIUS
119 + /* TODO: update dynamic data based on changed configuration
120 + * items (e.g., open/close sockets, etc.) */
121 + radius_client_flush(iface->bss[j]->radius, 0);
122 +#endif /* CONFIG_NO_RADIUS */
123 + wpa_printf(MSG_INFO, "bss %d changed", j);
124 + }
125 + }
126 }
127 iface->conf = newconf;
128
129 @@ -289,6 +312,12 @@ int hostapd_reload_config(struct hostapd
130
131 for (j = 0; j < iface->num_bss; j++) {
132 hapd = iface->bss[j];
133 + if (hapd->config_id) {
134 + os_free(hapd->config_id);
135 + hapd->config_id = NULL;
136 + }
137 + if (newconf->bss[j]->config_id)
138 + hapd->config_id = strdup(newconf->bss[j]->config_id);
139 hapd->iconf = newconf;
140 hapd->conf = newconf->bss[j];
141 hostapd_reload_bss(hapd);
142 @@ -2257,6 +2286,10 @@ hostapd_alloc_bss_data(struct hostapd_if
143 hapd->iconf = conf;
144 hapd->conf = bss;
145 hapd->iface = hapd_iface;
146 + if (bss && bss->config_id)
147 + hapd->config_id = strdup(bss->config_id);
148 + else
149 + hapd->config_id = NULL;
150 if (conf)
151 hapd->driver = conf->driver;
152 hapd->ctrl_sock = -1;
153 Index: hostapd-2019-08-08-ca8c2bd2/src/ap/hostapd.h
154 ===================================================================
155 --- hostapd-2019-08-08-ca8c2bd2.orig/src/ap/hostapd.h
156 +++ hostapd-2019-08-08-ca8c2bd2/src/ap/hostapd.h
157 @@ -42,7 +42,7 @@ struct mesh_conf;
158 struct hostapd_iface;
159
160 struct hapd_interfaces {
161 - int (*reload_config)(struct hostapd_iface *iface);
162 + int (*reload_config)(struct hostapd_iface *iface, int reconf);
163 struct hostapd_config * (*config_read_cb)(const char *config_fname);
164 int (*ctrl_iface_init)(struct hostapd_data *hapd);
165 void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
166 @@ -149,6 +149,7 @@ struct hostapd_data {
167 struct hostapd_config *iconf;
168 struct hostapd_bss_config *conf;
169 struct hostapd_ubus_bss ubus;
170 + char *config_id;
171 int interface_added; /* virtual interface added for this BSS */
172 unsigned int started:1;
173 unsigned int disabled:1;
174 @@ -576,7 +577,7 @@ struct hostapd_iface {
175 int hostapd_for_each_interface(struct hapd_interfaces *interfaces,
176 int (*cb)(struct hostapd_iface *iface,
177 void *ctx), void *ctx);
178 -int hostapd_reload_config(struct hostapd_iface *iface);
179 +int hostapd_reload_config(struct hostapd_iface *iface, int reconf);
180 void hostapd_reconfig_encryption(struct hostapd_data *hapd);
181 struct hostapd_data *
182 hostapd_alloc_bss_data(struct hostapd_iface *hapd_iface,
183 Index: hostapd-2019-08-08-ca8c2bd2/src/drivers/driver_nl80211.c
184 ===================================================================
185 --- hostapd-2019-08-08-ca8c2bd2.orig/src/drivers/driver_nl80211.c
186 +++ hostapd-2019-08-08-ca8c2bd2/src/drivers/driver_nl80211.c
187 @@ -4295,6 +4295,9 @@ static int wpa_driver_nl80211_set_ap(voi
188 if (ret) {
189 wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
190 ret, strerror(-ret));
191 + if (!bss->beacon_set)
192 + ret = 0;
193 + bss->beacon_set = 0;
194 } else {
195 bss->beacon_set = 1;
196 nl80211_set_bss(bss, params->cts_protect, params->preamble,
197 Index: hostapd-2019-08-08-ca8c2bd2/hostapd/ctrl_iface.c
198 ===================================================================
199 --- hostapd-2019-08-08-ca8c2bd2.orig/hostapd/ctrl_iface.c
200 +++ hostapd-2019-08-08-ca8c2bd2/hostapd/ctrl_iface.c
201 @@ -182,7 +182,7 @@ static int hostapd_ctrl_iface_update(str
202 iface->interfaces->config_read_cb = hostapd_ctrl_iface_config_read;
203 reload_opts = txt;
204
205 - hostapd_reload_config(iface);
206 + hostapd_reload_config(iface, 0);
207
208 iface->interfaces->config_read_cb = config_read_cb;
209 }
210 Index: hostapd-2019-08-08-ca8c2bd2/hostapd/main.c
211 ===================================================================
212 --- hostapd-2019-08-08-ca8c2bd2.orig/hostapd/main.c
213 +++ hostapd-2019-08-08-ca8c2bd2/hostapd/main.c
214 @@ -320,7 +320,7 @@ static void handle_term(int sig, void *s
215
216 static int handle_reload_iface(struct hostapd_iface *iface, void *ctx)
217 {
218 - if (hostapd_reload_config(iface) < 0) {
219 + if (hostapd_reload_config(iface, 0) < 0) {
220 wpa_printf(MSG_WARNING, "Failed to read new configuration "
221 "file - continuing with old.");
222 }
223 Index: hostapd-2019-08-08-ca8c2bd2/src/ap/wps_hostapd.c
224 ===================================================================
225 --- hostapd-2019-08-08-ca8c2bd2.orig/src/ap/wps_hostapd.c
226 +++ hostapd-2019-08-08-ca8c2bd2/src/ap/wps_hostapd.c
227 @@ -275,7 +275,7 @@ static void wps_reload_config(void *eloo
228
229 wpa_printf(MSG_DEBUG, "WPS: Reload configuration data");
230 if (iface->interfaces == NULL ||
231 - iface->interfaces->reload_config(iface) < 0) {
232 + iface->interfaces->reload_config(iface, 1) < 0) {
233 wpa_printf(MSG_WARNING, "WPS: Failed to reload the updated "
234 "configuration");
235 }