3 @@ -168,9 +168,21 @@ OBJS += ../src/eapol_auth/eapol_auth_sm.
6 CFLAGS += -DUBUS_SUPPORT
7 -OBJS += ../src/utils/uloop.o
8 OBJS += ../src/ap/ubus.o
15 +CFLAGS += -DUCODE_SUPPORT
16 +OBJS += ../src/utils/ucode.o
17 +OBJS += ../src/ap/ucode.o
22 +OBJS += ../src/utils/uloop.o
26 ifdef CONFIG_CODE_COVERAGE
29 @@ -1007,6 +1007,7 @@ int main(int argc, char *argv[])
32 hostapd_global_ctrl_iface_init(&interfaces);
33 + hostapd_ucode_init(&interfaces);
35 if (hostapd_global_run(&interfaces, daemonize, pid_file)) {
36 wpa_printf(MSG_ERROR, "Failed to start eloop");
37 @@ -1016,6 +1017,7 @@ int main(int argc, char *argv[])
41 + hostapd_ucode_free();
42 hostapd_global_ctrl_iface_deinit(&interfaces);
43 /* Deinitialize all interfaces */
44 for (i = 0; i < interfaces.count; i++) {
45 --- a/src/ap/hostapd.h
46 +++ b/src/ap/hostapd.h
48 #include "ap_config.h"
49 #include "drivers/driver.h"
53 #define OCE_STA_CFON_ENABLED(hapd) \
54 ((hapd->conf->oce & OCE_STA_CFON) && \
55 @@ -51,6 +52,10 @@ struct hapd_interfaces {
56 struct hostapd_config * (*config_read_cb)(const char *config_fname);
57 int (*ctrl_iface_init)(struct hostapd_data *hapd);
58 void (*ctrl_iface_deinit)(struct hostapd_data *hapd);
59 + int (*ctrl_iface_recv)(struct hostapd_data *hapd,
60 + char *buf, char *reply, int reply_size,
61 + struct sockaddr_storage *from,
63 int (*for_each_interface)(struct hapd_interfaces *interfaces,
64 int (*cb)(struct hostapd_iface *iface,
65 void *ctx), void *ctx);
66 @@ -186,6 +191,7 @@ struct hostapd_data {
67 struct hostapd_config *iconf;
68 struct hostapd_bss_config *conf;
69 struct hostapd_ubus_bss ubus;
70 + struct hostapd_ucode_bss ucode;
71 int interface_added; /* virtual interface added for this BSS */
72 unsigned int started:1;
73 unsigned int disabled:1;
74 @@ -506,6 +512,7 @@ struct hostapd_sta_info {
76 struct hostapd_iface {
77 struct hapd_interfaces *interfaces;
78 + struct hostapd_ucode_iface ucode;
81 struct hostapd_config *conf;
82 @@ -706,6 +713,8 @@ struct hostapd_iface * hostapd_init(stru
83 struct hostapd_iface *
84 hostapd_interface_init_bss(struct hapd_interfaces *interfaces, const char *phy,
85 const char *config_fname, int debug);
86 +int hostapd_setup_bss(struct hostapd_data *hapd, int first, bool start_beacon);
87 +void hostapd_bss_deinit(struct hostapd_data *hapd);
88 void hostapd_new_assoc_sta(struct hostapd_data *hapd, struct sta_info *sta,
90 void hostapd_interface_deinit_free(struct hostapd_iface *iface);
91 --- a/src/ap/hostapd.c
92 +++ b/src/ap/hostapd.c
93 @@ -252,6 +252,8 @@ int hostapd_reload_config(struct hostapd
94 struct hostapd_config *newconf, *oldconf;
97 + hostapd_ucode_reload_bss(hapd);
99 if (iface->config_fname == NULL) {
100 /* Only in-memory config in use - assume it has been updated */
101 hostapd_clear_old(iface);
102 @@ -435,6 +437,7 @@ void hostapd_free_hapd_data(struct hosta
103 hapd->beacon_set_done = 0;
105 wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
106 + hostapd_ucode_free_bss(hapd);
107 hostapd_ubus_free_bss(hapd);
108 accounting_deinit(hapd);
109 hostapd_deinit_wpa(hapd);
110 @@ -600,6 +603,7 @@ void hostapd_cleanup_iface_partial(struc
111 static void hostapd_cleanup_iface(struct hostapd_iface *iface)
113 wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
114 + hostapd_ucode_free_iface(iface);
115 eloop_cancel_timeout(hostapd_interface_setup_failure_handler, iface,
118 @@ -1189,6 +1193,7 @@ static int hostapd_start_beacon(struct h
119 hapd->driver->set_operstate(hapd->drv_priv, 1);
121 hostapd_ubus_add_bss(hapd);
122 + hostapd_ucode_add_bss(hapd);
126 @@ -1211,8 +1216,7 @@ static int hostapd_start_beacon(struct h
127 * initialized. Most of the modules that are initialized here will be
128 * deinitialized in hostapd_cleanup().
130 -static int hostapd_setup_bss(struct hostapd_data *hapd, int first,
132 +int hostapd_setup_bss(struct hostapd_data *hapd, int first, bool start_beacon)
134 struct hostapd_bss_config *conf = hapd->conf;
135 u8 ssid[SSID_MAX_LEN + 1];
136 @@ -2698,7 +2702,7 @@ hostapd_alloc_bss_data(struct hostapd_if
140 -static void hostapd_bss_deinit(struct hostapd_data *hapd)
141 +void hostapd_bss_deinit(struct hostapd_data *hapd)
145 @@ -3491,7 +3495,8 @@ int hostapd_remove_iface(struct hapd_int
146 hapd_iface = interfaces->iface[i];
147 if (hapd_iface == NULL)
149 - if (!os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
150 + if (!os_strcmp(hapd_iface->phy, buf) ||
151 + !os_strcmp(hapd_iface->conf->bss[0]->iface, buf)) {
152 wpa_printf(MSG_INFO, "Remove interface '%s'", buf);
153 hapd_iface->driver_ap_teardown =
154 !!(hapd_iface->drv_flags &
155 --- a/wpa_supplicant/Makefile
156 +++ b/wpa_supplicant/Makefile
157 @@ -195,8 +195,20 @@ endif
159 CFLAGS += -DUBUS_SUPPORT
166 +CFLAGS += -DUCODE_SUPPORT
167 +OBJS += ../src/utils/ucode.o
173 OBJS += ../src/utils/uloop.o
174 -LIBS += -lubox -lubus
178 ifdef CONFIG_CODE_COVERAGE
179 @@ -997,6 +1009,9 @@ OBJS += ../src/ap/ctrl_iface_ap.o
181 OBJS += ../src/ap/ubus.o
184 +OBJS += ../src/ap/ucode.o
188 CFLAGS += -DEAP_SERVER -DEAP_SERVER_IDENTITY
189 --- a/wpa_supplicant/wpa_supplicant.c
190 +++ b/wpa_supplicant/wpa_supplicant.c
191 @@ -1044,6 +1044,7 @@ void wpa_supplicant_set_state(struct wpa
192 sme_sched_obss_scan(wpa_s, 0);
194 wpa_s->wpa_state = state;
195 + wpas_ucode_update_state(wpa_s);
198 if (state == WPA_COMPLETED && wpa_s->current_ssid != wpa_s->bgscan_ssid)
199 @@ -7594,6 +7595,7 @@ struct wpa_supplicant * wpa_supplicant_a
200 #endif /* CONFIG_P2P */
202 wpas_ubus_add_bss(wpa_s);
203 + wpas_ucode_add_bss(wpa_s);
207 @@ -7621,6 +7623,7 @@ int wpa_supplicant_remove_iface(struct w
208 struct wpa_supplicant *parent = wpa_s->parent;
209 #endif /* CONFIG_MESH */
211 + wpas_ucode_free_bss(wpa_s);
212 wpas_ubus_free_bss(wpa_s);
214 /* Remove interface from the global list of interfaces */
215 @@ -7931,6 +7934,7 @@ struct wpa_global * wpa_supplicant_init(
217 eloop_register_timeout(WPA_SUPPLICANT_CLEANUP_INTERVAL, 0,
218 wpas_periodic, global, NULL);
219 + wpas_ucode_init(global);
223 @@ -7969,12 +7973,8 @@ int wpa_supplicant_run(struct wpa_global
224 eloop_register_signal_terminate(wpa_supplicant_terminate, global);
225 eloop_register_signal_reconfig(wpa_supplicant_reconfig, global);
227 - wpas_ubus_add(global);
231 - wpas_ubus_free(global);
236 @@ -8007,6 +8007,8 @@ void wpa_supplicant_deinit(struct wpa_gl
238 wpas_notify_supplicant_deinitialized(global);
242 eap_peer_unregister_methods();
244 eap_server_unregister_methods();
245 --- a/wpa_supplicant/wpa_supplicant_i.h
246 +++ b/wpa_supplicant/wpa_supplicant_i.h
249 #include "pasn/pasn_common.h"
253 extern const char *const wpa_supplicant_version;
254 extern const char *const wpa_supplicant_license;
255 @@ -689,6 +690,7 @@ struct wpa_supplicant {
256 unsigned char perm_addr[ETH_ALEN];
258 struct wpas_ubus_bss ubus;
259 + struct wpas_ucode_bss ucode;
260 #ifdef CONFIG_MATCH_IFACE
262 #endif /* CONFIG_MATCH_IFACE */
263 --- a/hostapd/ctrl_iface.c
264 +++ b/hostapd/ctrl_iface.c
265 @@ -4856,6 +4856,7 @@ try_again:
269 + interface->ctrl_iface_recv = hostapd_ctrl_iface_receive_process;
270 wpa_msg_register_cb(hostapd_ctrl_iface_msg_cb);
273 @@ -4957,6 +4958,7 @@ fail:
276 interface->global_ctrl_sock = s;
277 + interface->ctrl_iface_recv = hostapd_ctrl_iface_receive_process;
278 eloop_register_read_sock(s, hostapd_global_ctrl_iface_receive,
281 --- a/src/drivers/driver.h
282 +++ b/src/drivers/driver.h
283 @@ -3787,6 +3787,25 @@ struct wpa_driver_ops {
287 + * if_rename - Rename a virtual interface
288 + * @priv: Private driver interface data
289 + * @type: Interface type
290 + * @ifname: Interface name of the virtual interface to be renamed
291 + * (NULL when renaming the AP BSS interface)
292 + * @new_name: New interface name of the virtual interface
293 + * Returns: 0 on success, -1 on failure
295 + int (*if_rename)(void *priv, enum wpa_driver_if_type type,
296 + const char *ifname, const char *new_name);
299 + * set_first_bss - Make a virtual interface the first (primary) bss
300 + * @priv: Private driver interface data
301 + * Returns: 0 on success, -1 on failure
303 + int (*set_first_bss)(void *priv);
306 * set_sta_vlan - Bind a station into a specific interface (AP only)
307 * @priv: Private driver interface data
308 * @ifname: Interface (main or virtual BSS or VLAN)
309 @@ -6440,6 +6459,7 @@ union wpa_event_data {
313 + * @count: Count until channel switch activates
314 * @freq: Frequency of new channel in MHz
315 * @ht_enabled: Whether this is an HT channel
316 * @ch_offset: Secondary channel offset
317 @@ -6450,6 +6470,7 @@ union wpa_event_data {
318 * @punct_bitmap: Puncturing bitmap
325 --- a/src/drivers/driver_nl80211_event.c
326 +++ b/src/drivers/driver_nl80211_event.c
327 @@ -1202,6 +1202,7 @@ static void mlme_event_ch_switch(struct
328 struct nlattr *bw, struct nlattr *cf1,
330 struct nlattr *punct_bitmap,
331 + struct nlattr *count,
334 struct i802_bss *bss;
335 @@ -1265,6 +1266,8 @@ static void mlme_event_ch_switch(struct
336 data.ch_switch.cf1 = nla_get_u32(cf1);
338 data.ch_switch.cf2 = nla_get_u32(cf2);
340 + data.ch_switch.count = nla_get_u32(count);
343 bss->flink->freq = data.ch_switch.freq;
344 @@ -3912,6 +3915,7 @@ static void do_process_drv_event(struct
345 tb[NL80211_ATTR_CENTER_FREQ1],
346 tb[NL80211_ATTR_CENTER_FREQ2],
347 tb[NL80211_ATTR_PUNCT_BITMAP],
348 + tb[NL80211_ATTR_CH_SWITCH_COUNT],
351 case NL80211_CMD_CH_SWITCH_NOTIFY:
352 @@ -3924,6 +3928,7 @@ static void do_process_drv_event(struct
353 tb[NL80211_ATTR_CENTER_FREQ1],
354 tb[NL80211_ATTR_CENTER_FREQ2],
355 tb[NL80211_ATTR_PUNCT_BITMAP],
359 case NL80211_CMD_DISCONNECT:
360 --- a/wpa_supplicant/events.c
361 +++ b/wpa_supplicant/events.c
362 @@ -5389,6 +5389,7 @@ void supplicant_event(void *ctx, enum wp
363 event_to_string(event), event);
364 #endif /* CONFIG_NO_STDOUT_DEBUG */
366 + wpas_ucode_event(wpa_s, event, data);
370 --- a/src/ap/ap_drv_ops.h
371 +++ b/src/ap/ap_drv_ops.h
372 @@ -393,6 +393,23 @@ static inline int hostapd_drv_stop_ap(st
373 return hapd->driver->stop_ap(hapd->drv_priv);
376 +static inline int hostapd_drv_if_rename(struct hostapd_data *hapd,
377 + enum wpa_driver_if_type type,
378 + const char *ifname,
379 + const char *new_name)
381 + if (!hapd->driver || !hapd->driver->if_rename || !hapd->drv_priv)
383 + return hapd->driver->if_rename(hapd->drv_priv, type, ifname, new_name);
386 +static inline int hostapd_drv_set_first_bss(struct hostapd_data *hapd)
388 + if (!hapd->driver || !hapd->driver->set_first_bss || !hapd->drv_priv)
390 + return hapd->driver->set_first_bss(hapd->drv_priv);
393 static inline int hostapd_drv_channel_info(struct hostapd_data *hapd,
394 struct wpa_channel_info *ci)
396 --- a/src/drivers/driver_nl80211.c
397 +++ b/src/drivers/driver_nl80211.c
398 @@ -73,6 +73,16 @@ enum nlmsgerr_attrs {
402 +static void handle_nl_debug_hook(struct nl_msg *msg, int tx)
404 + const struct nlmsghdr *nlh;
406 + if (!wpa_netlink_hook)
409 + nlh = nlmsg_hdr(msg);
410 + wpa_netlink_hook(tx, nlh, nlh->nlmsg_len);
413 static struct nl_sock * nl_create_handle(struct nl_cb *cb, const char *dbg)
415 @@ -379,6 +389,11 @@ static int no_seq_check(struct nl_msg *m
419 +static int debug_handler(struct nl_msg *msg, void *arg)
421 + handle_nl_debug_hook(msg, 0);
425 static void nl80211_nlmsg_clear(struct nl_msg *msg)
427 @@ -415,6 +430,7 @@ static int send_and_recv(struct nl80211_
431 + handle_nl_debug_hook(msg, 1);
432 cb = nl_cb_clone(global->nl_cb);
435 @@ -443,6 +459,7 @@ static int send_and_recv(struct nl80211_
439 + nl_cb_set(cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
440 nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
441 nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
442 if (ack_handler_custom) {
443 @@ -919,6 +936,7 @@ nl80211_get_wiphy_data_ap(struct i802_bs
447 + nl_cb_set(w->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
448 nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
450 nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
451 @@ -1333,7 +1351,7 @@ static void wpa_driver_nl80211_event_rtm
453 wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
455 - if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
456 + if (drv->first_bss->ifindex != ifi->ifi_index) {
457 wpa_printf(MSG_DEBUG,
458 "nl80211: Not the main interface (%s) - do not indicate interface down",
459 drv->first_bss->ifname);
460 @@ -1369,7 +1387,7 @@ static void wpa_driver_nl80211_event_rtm
462 wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)",
464 - if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
465 + if (drv->first_bss->ifindex != ifi->ifi_index) {
466 wpa_printf(MSG_DEBUG,
467 "nl80211: Not the main interface (%s) - do not indicate interface up",
468 drv->first_bss->ifname);
469 @@ -1992,6 +2010,7 @@ static int wpa_driver_nl80211_init_nl_gl
470 /* Continue without vendor events */
473 + nl_cb_set(global->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
474 nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
476 nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
477 @@ -2160,6 +2179,7 @@ static int nl80211_init_bss(struct i802_
481 + nl_cb_set(bss->nl_cb, NL_CB_MSG_IN, NL_CB_CUSTOM, debug_handler, NULL);
482 nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
484 nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
485 @@ -8432,6 +8452,7 @@ static void *i802_init(struct hostapd_da
486 char master_ifname[IFNAMSIZ];
487 int ifindex, br_ifindex = 0;
491 bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
492 params->global_priv, 1,
493 @@ -8491,21 +8512,17 @@ static void *i802_init(struct hostapd_da
494 (params->num_bridge == 0 || !params->bridge[0]))
495 add_ifidx(drv, br_ifindex, drv->ifindex);
497 - if (bss->added_if_into_bridge || bss->already_in_bridge) {
500 - drv->rtnl_sk = nl_socket_alloc();
501 - if (drv->rtnl_sk == NULL) {
502 - wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
505 + drv->rtnl_sk = nl_socket_alloc();
506 + if (drv->rtnl_sk == NULL) {
507 + wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
511 - err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE);
513 - wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
517 + err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE);
519 + wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
524 if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) {
525 @@ -8875,6 +8892,50 @@ static int wpa_driver_nl80211_if_remove(
529 +static int wpa_driver_nl80211_if_rename(struct i802_bss *bss,
530 + enum wpa_driver_if_type type,
531 + const char *ifname, const char *new_name)
533 + struct wpa_driver_nl80211_data *drv = bss->drv;
534 + struct ifinfomsg ifi = {
535 + .ifi_family = AF_UNSPEC,
536 + .ifi_index = bss->ifindex,
538 + struct nl_msg *msg;
542 + ifi.ifi_index = if_nametoindex(ifname);
544 + msg = nlmsg_alloc_simple(RTM_SETLINK, 0);
548 + if (nlmsg_append(msg, &ifi, sizeof(ifi), NLMSG_ALIGNTO) < 0)
551 + if (nla_put_string(msg, IFLA_IFNAME, new_name))
554 + res = nl_send_auto_complete(drv->rtnl_sk, msg);
558 + res = nl_wait_for_ack(drv->rtnl_sk);
560 + wpa_printf(MSG_INFO,
561 + "nl80211: Renaming device %s to %s failed: %s",
562 + ifname ? ifname : bss->ifname, new_name, nl_geterror(res));
566 + if (type == WPA_IF_AP_BSS && !ifname)
567 + os_strlcpy(bss->ifname, new_name, sizeof(bss->ifname));
574 static int cookie_handler(struct nl_msg *msg, void *arg)
576 @@ -10513,6 +10574,37 @@ static int driver_nl80211_if_remove(void
580 +static int driver_nl80211_if_rename(void *priv, enum wpa_driver_if_type type,
581 + const char *ifname, const char *new_name)
583 + struct i802_bss *bss = priv;
584 + return wpa_driver_nl80211_if_rename(bss, type, ifname, new_name);
588 +static int driver_nl80211_set_first_bss(void *priv)
590 + struct i802_bss *bss = priv, *tbss;
591 + struct wpa_driver_nl80211_data *drv = bss->drv;
593 + if (drv->first_bss == bss)
596 + for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
597 + if (tbss->next != bss)
600 + tbss->next = bss->next;
601 + bss->next = drv->first_bss;
602 + drv->first_bss = bss;
603 + drv->ctx = bss->ctx;
611 static int driver_nl80211_send_mlme(void *priv, const u8 *data,
612 size_t data_len, int noack,
614 @@ -13697,6 +13789,8 @@ const struct wpa_driver_ops wpa_driver_n
615 .set_acl = wpa_driver_nl80211_set_acl,
616 .if_add = wpa_driver_nl80211_if_add,
617 .if_remove = driver_nl80211_if_remove,
618 + .if_rename = driver_nl80211_if_rename,
619 + .set_first_bss = driver_nl80211_set_first_bss,
620 .send_mlme = driver_nl80211_send_mlme,
621 .get_hw_feature_data = nl80211_get_hw_feature_data,
622 .sta_add = wpa_driver_nl80211_sta_add,
623 --- a/src/utils/wpa_debug.c
624 +++ b/src/utils/wpa_debug.c
625 @@ -26,6 +26,10 @@ static FILE *wpa_debug_tracing_file = NU
626 #define WPAS_TRACE_PFX "wpas <%d>: "
627 #endif /* CONFIG_DEBUG_LINUX_TRACING */
629 +void (*wpa_printf_hook)(int level, const char *fmt, va_list ap);
630 +void (*wpa_hexdump_hook)(int level, const char *title, const void *buf,
632 +void (*wpa_netlink_hook)(int tx, const void *data, size_t len);
634 int wpa_debug_level = MSG_INFO;
635 int wpa_debug_show_keys = 0;
636 @@ -210,6 +214,12 @@ void _wpa_printf(int level, const char *
640 + if (wpa_printf_hook) {
642 + wpa_printf_hook(level, fmt, ap);
646 if (level >= wpa_debug_level) {
647 #ifdef CONFIG_ANDROID_LOG
649 @@ -260,6 +270,9 @@ void _wpa_hexdump(int level, const char
653 + if (wpa_hexdump_hook)
654 + wpa_hexdump_hook(level, title, buf, len);
656 #ifdef CONFIG_DEBUG_LINUX_TRACING
657 if (wpa_debug_tracing_file != NULL) {
658 fprintf(wpa_debug_tracing_file,
659 --- a/src/utils/wpa_debug.h
660 +++ b/src/utils/wpa_debug.h
665 +extern void (*wpa_printf_hook)(int level, const char *fmt, va_list ap);
666 +extern void (*wpa_hexdump_hook)(int level, const char *title,
667 + const void *buf, size_t len);
668 +extern void (*wpa_netlink_hook)(int tx, const void *data, size_t len);
669 extern int wpa_debug_level;
670 extern int wpa_debug_show_keys;
671 extern int wpa_debug_timestamp;