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