bc50606038dad30f6bf05eb3b623615b14b7ed4b
[openwrt/staging/xback.git] / package / network / services / hostapd / patches / 601-ucode_support.patch
1 From: Felix Fietkau <nbd@nbd.name>
2 Date: Fri, 26 May 2023 10:23:59 +0200
3 Subject: [PATCH] Add ucode support, use ucode for the main ubus object
4
5 This implements vastly improved dynamic configuration reload support.
6 It can handle configuration changes on individual wifi interfaces, as well
7 as adding/removing interfaces.
8
9 --- a/hostapd/Makefile
10 +++ b/hostapd/Makefile
11 @@ -168,9 +168,21 @@ OBJS += ../src/eapol_auth/eapol_auth_sm.
12
13 ifdef CONFIG_UBUS
14 CFLAGS += -DUBUS_SUPPORT
15 -OBJS += ../src/utils/uloop.o
16 OBJS += ../src/ap/ubus.o
17 -LIBS += -lubox -lubus
18 +LIBS += -lubus
19 +NEED_ULOOP:=y
20 +endif
21 +
22 +ifdef CONFIG_UCODE
23 +CFLAGS += -DUCODE_SUPPORT
24 +OBJS += ../src/utils/ucode.o
25 +OBJS += ../src/ap/ucode.o
26 +NEED_ULOOP:=y
27 +endif
28 +
29 +ifdef NEED_ULOOP
30 +OBJS += ../src/utils/uloop.o
31 +LIBS += -lubox
32 endif
33
34 ifdef CONFIG_CODE_COVERAGE
35 --- a/hostapd/ctrl_iface.c
36 +++ b/hostapd/ctrl_iface.c
37 @@ -5487,6 +5487,7 @@ try_again:
38 return -1;
39 }
40
41 + interface->ctrl_iface_recv = hostapd_ctrl_iface_receive_process;
42 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
43
44 return 0;
45 @@ -5588,6 +5589,7 @@ fail:
46 os_free(fname);
47
48 interface->global_ctrl_sock = s;
49 + interface->ctrl_iface_recv = hostapd_ctrl_iface_receive_process;
50 eloop_register_read_sock(s, hostapd_global_ctrl_iface_receive,
51 interface, NULL);
52
53 --- a/hostapd/main.c
54 +++ b/hostapd/main.c
55 @@ -1014,6 +1014,7 @@ int main(int argc, char *argv[])
56 }
57
58 hostapd_global_ctrl_iface_init(&interfaces);
59 + hostapd_ucode_init(&interfaces);
60
61 if (hostapd_global_run(&interfaces, daemonize, pid_file)) {
62 wpa_printf(MSG_ERROR, "Failed to start eloop");
63 @@ -1023,6 +1024,7 @@ int main(int argc, char *argv[])
64 ret = 0;
65
66 out:
67 + hostapd_ucode_free();
68 hostapd_global_ctrl_iface_deinit(&interfaces);
69 /* Deinitialize all interfaces */
70 for (i = 0; i < interfaces.count; i++) {
71 --- a/src/ap/ap_drv_ops.h
72 +++ b/src/ap/ap_drv_ops.h
73 @@ -399,6 +399,23 @@ static inline int hostapd_drv_stop_ap(st
74 return hapd->driver->stop_ap(hapd->drv_priv, link_id);
75 }
76
77 +static inline int hostapd_drv_if_rename(struct hostapd_data *hapd,
78 + enum wpa_driver_if_type type,
79 + const char *ifname,
80 + const char *new_name)
81 +{
82 + if (!hapd->driver || !hapd->driver->if_rename || !hapd->drv_priv)
83 + return -1;
84 + return hapd->driver->if_rename(hapd->drv_priv, type, ifname, new_name);
85 +}
86 +
87 +static inline int hostapd_drv_set_first_bss(struct hostapd_data *hapd)
88 +{
89 + if (!hapd->driver || !hapd->driver->set_first_bss || !hapd->drv_priv)
90 + return 0;
91 + return hapd->driver->set_first_bss(hapd->drv_priv);
92 +}
93 +
94 static inline int hostapd_drv_channel_info(struct hostapd_data *hapd,
95 struct wpa_channel_info *ci)
96 {
97 --- a/src/ap/hostapd.c
98 +++ b/src/ap/hostapd.c
99 @@ -255,6 +255,8 @@ int hostapd_reload_config(struct hostapd
100 struct hostapd_config *newconf, *oldconf;
101 size_t j;
102
103 + hostapd_ucode_reload_bss(hapd);
104 +
105 if (iface->config_fname == NULL) {
106 /* Only in-memory config in use - assume it has been updated */
107 hostapd_clear_old(iface);
108 @@ -493,6 +495,7 @@ void hostapd_free_hapd_data(struct hosta
109 hapd->beacon_set_done = 0;
110
111 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
112 + hostapd_ucode_free_bss(hapd);
113 hostapd_ubus_free_bss(hapd);
114 accounting_deinit(hapd);
115 hostapd_deinit_wpa(hapd);
116 @@ -687,6 +690,7 @@ void hostapd_cleanup_iface_partial(struc
117 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
118 {
119 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
120 + hostapd_ucode_free_iface(iface);
121 eloop_cancel_timeout(hostapd_interface_setup_failure_handler, iface,
122 NULL);
123
124 @@ -1276,6 +1280,7 @@ static int hostapd_start_beacon(struct h
125 hapd->driver->set_operstate(hapd->drv_priv, 1);
126
127 hostapd_ubus_add_bss(hapd);
128 + hostapd_ucode_add_bss(hapd);
129
130 return 0;
131 }
132 @@ -1298,8 +1303,7 @@ static int hostapd_start_beacon(struct h
133 * initialized. Most of the modules that are initialized here will be
134 * deinitialized in hostapd_cleanup().
135 */
136 -static int hostapd_setup_bss(struct hostapd_data *hapd, int first,
137 - bool start_beacon)
138 +int hostapd_setup_bss(struct hostapd_data *hapd, int first, bool start_beacon)
139 {
140 struct hostapd_bss_config *conf = hapd->conf;
141 u8 ssid[SSID_MAX_LEN + 1];
142 @@ -2790,7 +2794,7 @@ hostapd_alloc_bss_data(struct hostapd_if
143 }
144
145
146 -static void hostapd_bss_deinit(struct hostapd_data *hapd)
147 +void hostapd_bss_deinit(struct hostapd_data *hapd)
148 {
149 if (!hapd)
150 return;
151 @@ -3608,7 +3612,8 @@ int hostapd_remove_iface(struct hapd_int
152 hapd_iface = interfaces->iface[i];
153 if (hapd_iface == NULL)
154 return -1;
155 - if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
156 + if (!os_strcmp(hapd_iface->phy, buf) ||
157 + !os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
158 wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
159 hapd_iface->driver_ap_teardown =
160 !!(hapd_iface->drv_flags &
161 --- a/src/ap/hostapd.h
162 +++ b/src/ap/hostapd.h
163 @@ -19,6 +19,7 @@
164 #include "ap_config.h"
165 #include "drivers/driver.h"
166 #include "ubus.h"
167 +#include "ucode.h"
168
169 #define OCE_STA_CFON_ENABLED(hapd) \
170 ((hapd->conf->oce & OCE_STA_CFON) && \
171 @@ -51,6 +52,10 @@ struct hapd_interfaces {
172 struct hostapd_config * (*config_read_cb)(const char *config_fname);
173 int (*ctrl_iface_init)(struct hostapd_data *hapd);
174 void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
175 + int (*ctrl_iface_recv)(struct hostapd_data *hapd,
176 + char *buf, char *reply, int reply_size,
177 + struct sockaddr_storage *from,
178 + socklen_t fromlen);
179 int (*for_each_interface)(struct hapd_interfaces *interfaces,
180 int (*cb)(struct hostapd_iface *iface,
181 void *ctx), void *ctx);
182 @@ -186,6 +191,7 @@ struct hostapd_data {
183 struct hostapd_config *iconf;
184 struct hostapd_bss_config *conf;
185 struct hostapd_ubus_bss ubus;
186 + struct hostapd_ucode_bss ucode;
187 int interface_added; /* virtual interface added for this BSS */
188 unsigned int started:1;
189 unsigned int disabled:1;
190 @@ -518,6 +524,7 @@ struct hostapd_sta_info {
191 */
192 struct hostapd_iface {
193 struct hapd_interfaces *interfaces;
194 + struct hostapd_ucode_iface ucode;
195 void *owner;
196 char *config_fname;
197 struct hostapd_config *conf;
198 @@ -718,6 +725,8 @@ struct hostapd_iface * hostapd_init(stru
199 struct hostapd_iface *
200 hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
201 const char *config_fname, int debug);
202 +int hostapd_setup_bss(struct hostapd_data *hapd, int first, bool start_beacon);
203 +void hostapd_bss_deinit(struct hostapd_data *hapd);
204 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
205 int reassoc);
206 void hostapd_interface_deinit_free(struct hostapd_iface *iface);
207 --- a/src/drivers/driver.h
208 +++ b/src/drivers/driver.h
209 @@ -3853,6 +3853,25 @@ struct wpa_driver_ops {
210 const char *ifname);
211
212 /**
213 + * if_rename - Rename a virtual interface
214 + * @priv: Private driver interface data
215 + * @type: Interface type
216 + * @ifname: Interface name of the virtual interface to be renamed
217 + * (NULL when renaming the AP BSS interface)
218 + * @new_name: New interface name of the virtual interface
219 + * Returns: 0 on success, -1 on failure
220 + */
221 + int (*if_rename)(void *priv, enum wpa_driver_if_type type,
222 + const char *ifname, const char *new_name);
223 +
224 + /**
225 + * set_first_bss - Make a virtual interface the first (primary) bss
226 + * @priv: Private driver interface data
227 + * Returns: 0 on success, -1 on failure
228 + */
229 + int (*set_first_bss)(void *priv);
230 +
231 + /**
232 * set_sta_vlan - Bind a station into a specific interface (AP only)
233 * @priv: Private driver interface data
234 * @ifname: Interface (main or virtual BSS or VLAN)
235 @@ -6507,6 +6526,7 @@ union wpa_event_data {
236
237 /**
238 * struct ch_switch
239 + * @count: Count until channel switch activates
240 * @freq: Frequency of new channel in MHz
241 * @ht_enabled: Whether this is an HT channel
242 * @ch_offset: Secondary channel offset
243 @@ -6517,6 +6537,7 @@ union wpa_event_data {
244 * @punct_bitmap: Puncturing bitmap
245 */
246 struct ch_switch {
247 + int count;
248 int freq;
249 int ht_enabled;
250 int ch_offset;
251 --- a/src/drivers/driver_nl80211.c
252 +++ b/src/drivers/driver_nl80211.c
253 @@ -75,6 +75,16 @@ enum nlmsgerr_attrs {
254
255 #endif /* ANDROID */
256
257 +static void handle_nl_debug_hook(struct nl_msg *msg, int tx)
258 +{
259 + const struct nlmsghdr *nlh;
260 +
261 + if (!wpa_netlink_hook)
262 + return;
263 +
264 + nlh = nlmsg_hdr(msg);
265 + wpa_netlink_hook(tx, nlh, nlh->nlmsg_len);
266 +}
267
268 static struct nl_sock * nl_create_handle(struct nl_cb *cb, const char *dbg)
269 {
270 @@ -429,6 +439,11 @@ static int no_seq_check(struct nl_msg *m
271 return NL_OK;
272 }
273
274 +static int debug_handler(struct nl_msg *msg, void *arg)
275 +{
276 + handle_nl_debug_hook(msg, 0);
277 + return NL_OK;
278 +}
279
280 static void nl80211_nlmsg_clear(struct nl_msg *msg)
281 {
282 @@ -502,6 +517,8 @@ int send_and_recv(struct nl80211_global
283 if (!msg)
284 return -ENOMEM;
285
286 + handle_nl_debug_hook(msg, 1);
287 +
288 err.err = -ENOMEM;
289
290 s_nl_cb = nl_socket_get_cb(nl_handle);
291 @@ -536,6 +553,7 @@ int send_and_recv(struct nl80211_global
292 err.orig_msg = msg;
293 err.err_info = err_info;
294
295 + nl_cb_set(cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
296 nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
297 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err.err);
298 if (ack_handler_custom) {
299 @@ -939,6 +957,7 @@ nl80211_get_wiphy_data_ap(struct i802_bs
300 os_free(w);
301 return NULL;
302 }
303 + nl_cb_set(w->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
304 nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
305 no_seq_check, NULL);
306 nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
307 @@ -1353,7 +1372,7 @@ static void wpa_driver_nl80211_event_rtm
308 }
309 wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
310 namebuf, ifname);
311 - if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
312 + if (drv->first_bss->ifindex != ifi->ifi_index) {
313 wpa_printf(MSG_DEBUG,
314 "nl80211: Not the main interface (%s) - do not indicate interface down",
315 drv->first_bss->ifname);
316 @@ -1389,7 +1408,7 @@ static void wpa_driver_nl80211_event_rtm
317 }
318 wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)",
319 namebuf, ifname);
320 - if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
321 + if (drv->first_bss->ifindex != ifi->ifi_index) {
322 wpa_printf(MSG_DEBUG,
323 "nl80211: Not the main interface (%s) - do not indicate interface up",
324 drv->first_bss->ifname);
325 @@ -2035,6 +2054,7 @@ static int wpa_driver_nl80211_init_nl_gl
326 genl_family_put(family);
327 nl_cache_free(cache);
328
329 + nl_cb_set(global->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
330 nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
331 no_seq_check, NULL);
332 nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
333 @@ -2205,6 +2225,7 @@ static int nl80211_init_bss(struct i802_
334 if (!bss->nl_cb)
335 return -1;
336
337 + nl_cb_set(bss->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
338 nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
339 no_seq_check, NULL);
340 nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
341 @@ -8554,6 +8575,7 @@ static void *i802_init(struct hostapd_da
342 char master_ifname[IFNAMSIZ];
343 int ifindex, br_ifindex = 0;
344 int br_added = 0;
345 + int err;
346
347 bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
348 params->global_priv, 1,
349 @@ -8613,21 +8635,17 @@ static void *i802_init(struct hostapd_da
350 (params->num_bridge == 0 || !params->bridge[0]))
351 add_ifidx(drv, br_ifindex, drv->ifindex);
352
353 - if (bss->added_if_into_bridge || bss->already_in_bridge) {
354 - int err;
355 -
356 - drv->rtnl_sk = nl_socket_alloc();
357 - if (drv->rtnl_sk == NULL) {
358 - wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
359 - goto failed;
360 - }
361 + drv->rtnl_sk = nl_socket_alloc();
362 + if (drv->rtnl_sk == NULL) {
363 + wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
364 + goto failed;
365 + }
366
367 - err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE);
368 - if (err) {
369 - wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
370 - nl_geterror(err));
371 - goto failed;
372 - }
373 + err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE);
374 + if (err) {
375 + wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
376 + nl_geterror(err));
377 + goto failed;
378 }
379
380 if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) {
381 @@ -8992,6 +9010,50 @@ static int wpa_driver_nl80211_if_remove(
382 return 0;
383 }
384
385 +static int wpa_driver_nl80211_if_rename(struct i802_bss *bss,
386 + enum wpa_driver_if_type type,
387 + const char *ifname, const char *new_name)
388 +{
389 + struct wpa_driver_nl80211_data *drv = bss->drv;
390 + struct ifinfomsg ifi = {
391 + .ifi_family = AF_UNSPEC,
392 + .ifi_index = bss->ifindex,
393 + };
394 + struct nl_msg *msg;
395 + int res = -ENOMEM;
396 +
397 + if (ifname)
398 + ifi.ifi_index = if_nametoindex(ifname);
399 +
400 + msg = nlmsg_alloc_simple(RTM_SETLINK, 0);
401 + if (!msg)
402 + return res;
403 +
404 + if (nlmsg_append(msg, &ifi, sizeof(ifi), NLMSG_ALIGNTO) < 0)
405 + goto out;
406 +
407 + if (nla_put_string(msg, IFLA_IFNAME, new_name))
408 + goto out;
409 +
410 + res = nl_send_auto_complete(drv->rtnl_sk, msg);
411 + if (res < 0)
412 + goto out;
413 +
414 + res = nl_wait_for_ack(drv->rtnl_sk);
415 + if (res) {
416 + wpa_printf(MSG_INFO,
417 + "nl80211: Renaming device %s to %s failed: %s",
418 + ifname ? ifname : bss->ifname, new_name, nl_geterror(res));
419 + goto out;
420 + }
421 +
422 + if (type == WPA_IF_AP_BSS && !ifname)
423 + os_strlcpy(bss->ifname, new_name, sizeof(bss->ifname));
424 +
425 +out:
426 + nlmsg_free(msg);
427 + return res;
428 +}
429
430 static int cookie_handler(struct nl_msg *msg, void *arg)
431 {
432 @@ -10688,6 +10750,37 @@ static int driver_nl80211_if_remove(void
433 }
434
435
436 +static int driver_nl80211_if_rename(void *priv, enum wpa_driver_if_type type,
437 + const char *ifname, const char *new_name)
438 +{
439 + struct i802_bss *bss = priv;
440 + return wpa_driver_nl80211_if_rename(bss, type, ifname, new_name);
441 +}
442 +
443 +
444 +static int driver_nl80211_set_first_bss(void *priv)
445 +{
446 + struct i802_bss *bss = priv, *tbss;
447 + struct wpa_driver_nl80211_data *drv = bss->drv;
448 +
449 + if (drv->first_bss == bss)
450 + return 0;
451 +
452 + for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
453 + if (tbss->next != bss)
454 + continue;
455 +
456 + tbss->next = bss->next;
457 + bss->next = drv->first_bss;
458 + drv->first_bss = bss;
459 + drv->ctx = bss->ctx;
460 + return 0;
461 + }
462 +
463 + return -1;
464 +}
465 +
466 +
467 static int driver_nl80211_send_mlme(void *priv, const u8 *data,
468 size_t data_len, int noack,
469 unsigned int freq,
470 @@ -13881,6 +13974,8 @@ const struct wpa_driver_ops wpa_driver_n
471 .set_acl = wpa_driver_nl80211_set_acl,
472 .if_add = wpa_driver_nl80211_if_add,
473 .if_remove = driver_nl80211_if_remove,
474 + .if_rename = driver_nl80211_if_rename,
475 + .set_first_bss = driver_nl80211_set_first_bss,
476 .send_mlme = driver_nl80211_send_mlme,
477 .get_hw_feature_data = nl80211_get_hw_feature_data,
478 .sta_add = wpa_driver_nl80211_sta_add,
479 --- a/src/drivers/driver_nl80211_event.c
480 +++ b/src/drivers/driver_nl80211_event.c
481 @@ -1196,6 +1196,7 @@ static void mlme_event_ch_switch(struct
482 struct nlattr *bw, struct nlattr *cf1,
483 struct nlattr *cf2,
484 struct nlattr *punct_bitmap,
485 + struct nlattr *count,
486 int finished)
487 {
488 struct i802_bss *bss;
489 @@ -1259,6 +1260,8 @@ static void mlme_event_ch_switch(struct
490 data.ch_switch.cf1 = nla_get_u32(cf1);
491 if (cf2)
492 data.ch_switch.cf2 = nla_get_u32(cf2);
493 + if (count)
494 + data.ch_switch.count = nla_get_u32(count);
495
496 if (finished)
497 bss->flink->freq = data.ch_switch.freq;
498 @@ -3961,6 +3964,7 @@ static void do_process_drv_event(struct
499 tb[NL80211_ATTR_CENTER_FREQ1],
500 tb[NL80211_ATTR_CENTER_FREQ2],
501 tb[NL80211_ATTR_PUNCT_BITMAP],
502 + tb[NL80211_ATTR_CH_SWITCH_COUNT],
503 0);
504 break;
505 case NL80211_CMD_CH_SWITCH_NOTIFY:
506 @@ -3973,6 +3977,7 @@ static void do_process_drv_event(struct
507 tb[NL80211_ATTR_CENTER_FREQ1],
508 tb[NL80211_ATTR_CENTER_FREQ2],
509 tb[NL80211_ATTR_PUNCT_BITMAP],
510 + NULL,
511 1);
512 break;
513 case NL80211_CMD_DISCONNECT:
514 --- a/src/utils/wpa_debug.c
515 +++ b/src/utils/wpa_debug.c
516 @@ -26,6 +26,10 @@ static FILE *wpa_debug_tracing_file = NU
517 #define WPAS_TRACE_PFX "wpas <%d>: "
518 #endif /* CONFIG_DEBUG_LINUX_TRACING */
519
520 +void (*wpa_printf_hook)(int level, const char *fmt, va_list ap);
521 +void (*wpa_hexdump_hook)(int level, const char *title, const void *buf,
522 + size_t len);
523 +void (*wpa_netlink_hook)(int tx, const void *data, size_t len);
524
525 int wpa_debug_level = MSG_INFO;
526 int wpa_debug_show_keys = 0;
527 @@ -210,6 +214,12 @@ void _wpa_printf(int level, const char *
528 {
529 va_list ap;
530
531 + if (wpa_printf_hook) {
532 + va_start(ap, fmt);
533 + wpa_printf_hook(level, fmt, ap);
534 + va_end(ap);
535 + }
536 +
537 if (level >= wpa_debug_level) {
538 #ifdef CONFIG_ANDROID_LOG
539 va_start(ap, fmt);
540 @@ -260,6 +270,9 @@ void _wpa_hexdump(int level, const char
541 {
542 size_t i;
543
544 + if (wpa_hexdump_hook)
545 + wpa_hexdump_hook(level, title, buf, len);
546 +
547 #ifdef CONFIG_DEBUG_LINUX_TRACING
548 if (wpa_debug_tracing_file != NULL) {
549 fprintf(wpa_debug_tracing_file,
550 --- a/src/utils/wpa_debug.h
551 +++ b/src/utils/wpa_debug.h
552 @@ -11,6 +11,10 @@
553
554 #include "wpabuf.h"
555
556 +extern void (*wpa_printf_hook)(int level, const char *fmt, va_list ap);
557 +extern void (*wpa_hexdump_hook)(int level, const char *title,
558 + const void *buf, size_t len);
559 +extern void (*wpa_netlink_hook)(int tx, const void *data, size_t len);
560 extern int wpa_debug_level;
561 extern int wpa_debug_show_keys;
562 extern int wpa_debug_timestamp;
563 --- a/wpa_supplicant/Makefile
564 +++ b/wpa_supplicant/Makefile
565 @@ -192,8 +192,20 @@ endif
566 ifdef CONFIG_UBUS
567 CFLAGS += -DUBUS_SUPPORT
568 OBJS += ubus.o
569 +LIBS += -lubus
570 +NEED_ULOOP:=y
571 +endif
572 +
573 +ifdef CONFIG_UCODE
574 +CFLAGS += -DUCODE_SUPPORT
575 +OBJS += ../src/utils/ucode.o
576 +OBJS += ucode.o
577 +NEED_ULOOP:=y
578 +endif
579 +
580 +ifdef NEED_ULOOP
581 OBJS += ../src/utils/uloop.o
582 -LIBS += -lubox -lubus
583 +LIBS += -lubox
584 endif
585
586 ifdef CONFIG_CODE_COVERAGE
587 @@ -1052,6 +1064,9 @@ OBJS += ../src/ap/ctrl_iface_ap.o
588 ifdef CONFIG_UBUS
589 OBJS += ../src/ap/ubus.o
590 endif
591 +ifdef CONFIG_UCODE
592 +OBJS += ../src/ap/ucode.o
593 +endif
594 endif
595
596 CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY
597 --- a/wpa_supplicant/events.c
598 +++ b/wpa_supplicant/events.c
599 @@ -5955,6 +5955,7 @@ void supplicant_event(void *ctx, enum wp
600 event_to_string(event), event);
601 #endif /* CONFIG_NO_STDOUT_DEBUG */
602
603 + wpas_ucode_event(wpa_s, event, data);
604 switch (event) {
605 case EVENT_AUTH:
606 #ifdef CONFIG_FST
607 --- a/wpa_supplicant/wpa_supplicant.c
608 +++ b/wpa_supplicant/wpa_supplicant.c
609 @@ -1060,6 +1060,7 @@ void wpa_supplicant_set_state(struct wpa
610 sme_sched_obss_scan(wpa_s, 0);
611 }
612 wpa_s->wpa_state = state;
613 + wpas_ucode_update_state(wpa_s);
614
615 #ifdef CONFIG_BGSCAN
616 if (state == WPA_COMPLETED && wpa_s->current_ssid != wpa_s->bgscan_ssid)
617 @@ -7717,6 +7718,7 @@ struct wpa_supplicant * wpa_supplicant_a
618 #endif /* CONFIG_P2P */
619
620 wpas_ubus_add_bss(wpa_s);
621 + wpas_ucode_add_bss(wpa_s);
622
623 return wpa_s;
624 }
625 @@ -7744,6 +7746,7 @@ int wpa_supplicant_remove_iface(struct w
626 struct wpa_supplicant *parent = wpa_s->parent;
627 #endif /* CONFIG_MESH */
628
629 + wpas_ucode_free_bss(wpa_s);
630 wpas_ubus_free_bss(wpa_s);
631
632 /* Remove interface from the global list of interfaces */
633 @@ -8054,6 +8057,7 @@ struct wpa_global * wpa_supplicant_init(
634
635 eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0,
636 wpas_periodic, global, NULL);
637 + wpas_ucode_init(global);
638
639 return global;
640 }
641 @@ -8092,12 +8096,8 @@ int wpa_supplicant_run(struct wpa_global
642 eloop_register_signal_terminate(wpa_supplicant_terminate, global);
643 eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
644
645 - wpas_ubus_add(global);
646 -
647 eloop_run();
648
649 - wpas_ubus_free(global);
650 -
651 return 0;
652 }
653
654 @@ -8130,6 +8130,8 @@ void wpa_supplicant_deinit(struct wpa_gl
655
656 wpas_notify_supplicant_deinitialized(global);
657
658 + wpas_ucode_free();
659 +
660 eap_peer_unregister_methods();
661 #ifdef CONFIG_AP
662 eap_server_unregister_methods();
663 --- a/wpa_supplicant/wpa_supplicant_i.h
664 +++ b/wpa_supplicant/wpa_supplicant_i.h
665 @@ -22,6 +22,7 @@
666 #include "wmm_ac.h"
667 #include "pasn/pasn_common.h"
668 #include "ubus.h"
669 +#include "ucode.h"
670
671 extern const char *const wpa_supplicant_version;
672 extern const char *const wpa_supplicant_license;
673 @@ -697,6 +698,7 @@ struct wpa_supplicant {
674 unsigned char perm_addr[ETH_ALEN];
675 char ifname[100];
676 struct wpas_ubus_bss ubus;
677 + struct wpas_ucode_bss ucode;
678 #ifdef CONFIG_MATCH_IFACE
679 int matched;
680 #endif /* CONFIG_MATCH_IFACE */