+From: Felix Fietkau <nbd@openwrt.org>
+Date: Sat, 23 Jan 2010 08:28:26 +0000
+Subject: [PATCH] Add option to build a multicall binary
+
+This allows building both hostapd and wpa_supplicant as a single binary
+(wpad).
+
--- a/hostapd/Makefile
+++ b/hostapd/Makefile
-@@ -28,6 +28,7 @@ CFLAGS += -I$(abspath ../src/utils)
- export BINDIR ?= /usr/local/bin/
+@@ -1,6 +1,7 @@
+ ALL=hostapd hostapd_cli
+ CONFIG_FILE = .config
- -include .config
+-include $(if $(MULTICALL), ../wpa_supplicant/.config)
+ include ../src/build.rules
- ifndef CONFIG_NO_GITVER
- # Add VERSION_STR postfix for builds from a git repository
-@@ -193,7 +194,8 @@ endif
+ ifdef LIBS
+@@ -199,7 +200,8 @@ endif
ifdef CONFIG_NO_VLAN
CFLAGS += -DCONFIG_NO_VLAN
OBJS += ../src/ap/vlan_init.o
OBJS += ../src/ap/vlan_ifconfig.o
OBJS += ../src/ap/vlan.o
-@@ -318,10 +320,14 @@ CFLAGS += -DCONFIG_MBO
+@@ -358,10 +360,14 @@ CFLAGS += -DCONFIG_MBO
OBJS += ../src/ap/mbo_ap.o
endif
LIBS += $(DRV_AP_LIBS)
ifdef CONFIG_L2_PACKET
-@@ -1054,6 +1060,12 @@ install: $(addprefix $(DESTDIR)$(BINDIR)
-
- BCHECK=../src/drivers/build.hostapd
+@@ -1392,6 +1398,12 @@ install: $(addprefix $(DESTDIR)$(BINDIR)
+ _OBJS_VAR := OBJS
+ include ../src/objs.mk
+hostapd_multi.a: $(BCHECK) $(OBJS)
+ $(Q)$(CC) -c -o hostapd_multi.o -Dmain=hostapd_main $(CFLAGS) main.c
+ @rm -f $@
+ @$(AR) cr $@ hostapd_multi.o $(OBJS)
+
- hostapd: $(BCHECK) $(OBJS)
+ hostapd: $(OBJS)
$(Q)$(CC) $(LDFLAGS) -o hostapd $(OBJS) $(LIBS)
@$(E) " LD " $@
-@@ -1095,6 +1107,12 @@ HOBJS += ../src/crypto/aes-internal.o
- HOBJS += ../src/crypto/aes-internal-enc.o
- endif
+@@ -1472,6 +1484,12 @@ include ../src/objs.mk
+ _OBJS_VAR := SOBJS
+ include ../src/objs.mk
+dump_cflags:
+ @printf "%s " "$(CFLAGS)"
nt_password_hash: $(NOBJS)
$(Q)$(CC) $(LDFLAGS) -o nt_password_hash $(NOBJS) $(LIBS_n)
@$(E) " LD " $@
+--- a/hostapd/main.c
++++ b/hostapd/main.c
+@@ -705,6 +705,11 @@ fail:
+ return -1;
+ }
+
++void hostapd_wpa_event(void *ctx, enum wpa_event_type event,
++ union wpa_event_data *data);
++
++void hostapd_wpa_event_global(void *ctx, enum wpa_event_type event,
++ union wpa_event_data *data);
+
+ #ifdef CONFIG_WPS
+ static int gen_uuid(const char *txt_addr)
+@@ -798,6 +803,8 @@ int main(int argc, char *argv[])
+ return -1;
+ #endif /* CONFIG_DPP */
+
++ wpa_supplicant_event = hostapd_wpa_event;
++ wpa_supplicant_event_global = hostapd_wpa_event_global;
+ for (;;) {
+ c = getopt(argc, argv, "b:Bde:f:hi:KP:sSTtu:vg:G:q");
+ if (c < 0)
+--- a/src/ap/drv_callbacks.c
++++ b/src/ap/drv_callbacks.c
+@@ -2341,8 +2341,8 @@ err:
+ #endif /* CONFIG_OWE */
+
+
+-void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
+- union wpa_event_data *data)
++void hostapd_wpa_event(void *ctx, enum wpa_event_type event,
++ union wpa_event_data *data)
+ {
+ struct hostapd_data *hapd = ctx;
+ struct sta_info *sta;
+@@ -2674,7 +2674,7 @@ void wpa_supplicant_event(void *ctx, enu
+ }
+
+
+-void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
++void hostapd_wpa_event_global(void *ctx, enum wpa_event_type event,
+ union wpa_event_data *data)
+ {
+ struct hapd_interfaces *interfaces = ctx;
+--- a/src/drivers/driver.h
++++ b/src/drivers/driver.h
+@@ -6763,8 +6763,8 @@ union wpa_event_data {
+ * Driver wrapper code should call this function whenever an event is received
+ * from the driver.
+ */
+-void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
+- union wpa_event_data *data);
++extern void (*wpa_supplicant_event)(void *ctx, enum wpa_event_type event,
++ union wpa_event_data *data);
+
+ /**
+ * wpa_supplicant_event_global - Report a driver event for wpa_supplicant
+@@ -6776,7 +6776,7 @@ void wpa_supplicant_event(void *ctx, enu
+ * Same as wpa_supplicant_event(), but we search for the interface in
+ * wpa_global.
+ */
+-void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
++extern void (*wpa_supplicant_event_global)(void *ctx, enum wpa_event_type event,
+ union wpa_event_data *data);
+
+ /*
+--- a/src/drivers/drivers.c
++++ b/src/drivers/drivers.c
+@@ -10,6 +10,10 @@
+ #include "utils/common.h"
+ #include "driver.h"
+
++void (*wpa_supplicant_event)(void *ctx, enum wpa_event_type event,
++ union wpa_event_data *data);
++void (*wpa_supplicant_event_global)(void *ctx, enum wpa_event_type event,
++ union wpa_event_data *data);
+
+ const struct wpa_driver_ops *const wpa_drivers[] =
+ {
--- a/wpa_supplicant/Makefile
+++ b/wpa_supplicant/Makefile
-@@ -27,6 +27,7 @@ CFLAGS += -I$(abspath ../src)
- CFLAGS += -I$(abspath ../src/utils)
+@@ -10,6 +10,7 @@ ALL += dbus/fi.w1.wpa_supplicant1.servic
+ EXTRA_TARGETS=dynamic_eap_methods
- -include .config
+ CONFIG_FILE=.config
+-include $(if $(MULTICALL),../hostapd/.config)
+ include ../src/build.rules
- ifndef CONFIG_NO_GITVER
- # Add VERSION_STR postfix for builds from a git repository
-@@ -313,7 +314,9 @@ endif
+ ifdef CONFIG_BUILD_PASN_SO
+@@ -388,7 +389,9 @@ endif
ifdef CONFIG_IBSS_RSN
NEED_RSN_AUTHENTICATOR=y
CFLAGS += -DCONFIG_IBSS_RSN
OBJS += ibss_rsn.o
endif
-@@ -804,6 +807,10 @@ ifdef CONFIG_DYNAMIC_EAP_METHODS
+@@ -980,6 +983,10 @@ ifdef CONFIG_DYNAMIC_EAP_METHODS
CFLAGS += -DCONFIG_DYNAMIC_EAP_METHODS
LIBS += -ldl -rdynamic
endif
+ endif
endif
- ifdef CONFIG_MACSEC
-@@ -824,9 +831,11 @@ NEED_EAP_COMMON=y
+ ifdef CONFIG_AP
+@@ -987,9 +994,11 @@ NEED_EAP_COMMON=y
NEED_RSN_AUTHENTICATOR=y
CFLAGS += -DCONFIG_AP
OBJS += ap.o
OBJS += ../src/ap/hostapd.o
OBJS += ../src/ap/wpa_auth_glue.o
OBJS += ../src/ap/utils.o
-@@ -899,10 +908,18 @@ endif
+@@ -1080,6 +1089,12 @@ endif
ifdef CONFIG_HS20
OBJS += ../src/ap/hs20.o
endif
+ endif
endif
+ ifdef CONFIG_MBO
+@@ -1089,7 +1104,9 @@ NEED_GAS=y
+ endif
+
ifdef NEED_RSN_AUTHENTICATOR
+ifndef MULTICALL
CFLAGS += -DCONFIG_NO_RADIUS
NEED_AES_WRAP=y
OBJS += ../src/ap/wpa_auth.o
OBJS += ../src/ap/wpa_auth_ie.o
-@@ -1685,6 +1702,12 @@ wpa_priv: $(BCHECK) $(OBJS_priv)
-
- $(OBJS_c) $(OBJS_t) $(OBJS_t2) $(OBJS) $(BCHECK) $(EXTRA_progs): .config
+@@ -2079,6 +2096,12 @@ wpa_priv: $(BCHECK) $(OBJS_priv)
+ _OBJS_VAR := OBJS
+ include ../src/objs.mk
+wpa_supplicant_multi.a: .config $(BCHECK) $(OBJS) $(EXTRA_progs)
+ $(Q)$(CC) -c -o wpa_supplicant_multi.o -Dmain=wpa_supplicant_main $(CFLAGS) main.c
+ @$(E) " CC " $<
wpa_supplicant: $(BCHECK) $(OBJS) $(EXTRA_progs)
$(Q)$(LDO) $(LDFLAGS) -o wpa_supplicant $(OBJS) $(LIBS) $(EXTRALIBS)
@$(E) " LD " $@
-@@ -1787,6 +1810,12 @@ endif
- -e 's|\@DBUS_INTERFACE\@|$(DBUS_INTERFACE)|g' $< >$@
+@@ -2211,6 +2234,12 @@ eap_gpsk.so: $(SRC_EAP_GPSK)
+ $(Q)sed -e 's|\@BINDIR\@|$(BINDIR)|g' $< >$@
@$(E) " sed" $<
+dump_cflags:
wpa_supplicant.exe: wpa_supplicant
mv -f $< $@
wpa_cli.exe: wpa_cli
---- a/src/drivers/driver.h
-+++ b/src/drivers/driver.h
-@@ -4870,8 +4870,8 @@ union wpa_event_data {
- * Driver wrapper code should call this function whenever an event is received
- * from the driver.
- */
--void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
-- union wpa_event_data *data);
-+extern void (*wpa_supplicant_event)(void *ctx, enum wpa_event_type event,
-+ union wpa_event_data *data);
+--- a/wpa_supplicant/eapol_test.c
++++ b/wpa_supplicant/eapol_test.c
+@@ -31,7 +31,12 @@
+ #include "ctrl_iface.h"
+ #include "pcsc_funcs.h"
+ #include "wpas_glue.h"
++#include "drivers/driver.h"
- /**
- * wpa_supplicant_event_global - Report a driver event for wpa_supplicant
-@@ -4883,7 +4883,7 @@ void wpa_supplicant_event(void *ctx, enu
- * Same as wpa_supplicant_event(), but we search for the interface in
- * wpa_global.
- */
--void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
-+extern void (*wpa_supplicant_event_global)(void *ctx, enum wpa_event_type event,
- union wpa_event_data *data);
++void (*wpa_supplicant_event)(void *ctx, enum wpa_event_type event,
++ union wpa_event_data *data);
++void (*wpa_supplicant_event_global)(void *ctx, enum wpa_event_type event,
++ union wpa_event_data *data);
- /*
---- a/src/ap/drv_callbacks.c
-+++ b/src/ap/drv_callbacks.c
-@@ -1164,8 +1164,8 @@ static void hostapd_event_dfs_cac_starte
- #endif /* NEED_AP_MLME */
+ const struct wpa_driver_ops *const wpa_drivers[] = { NULL };
+
+@@ -1325,6 +1330,10 @@ static void usage(void)
+ "option several times.\n");
+ }
+
++extern void supplicant_event(void *ctx, enum wpa_event_type event,
++ union wpa_event_data *data);
++extern void supplicant_event_global(void *ctx, enum wpa_event_type event,
++ union wpa_event_data *data);
+
+ int main(int argc, char *argv[])
+ {
+@@ -1348,6 +1357,8 @@ int main(int argc, char *argv[])
+ if (os_program_init())
+ return -1;
+
++ wpa_supplicant_event = supplicant_event;
++ wpa_supplicant_event_global = supplicant_event_global;
+ hostapd_logger_register_cb(hostapd_logger_cb);
+
+ os_memset(&eapol_test, 0, sizeof(eapol_test));
+--- a/wpa_supplicant/events.c
++++ b/wpa_supplicant/events.c
+@@ -5919,8 +5919,8 @@ static void wpas_link_reconfig(struct wp
+ }
-void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
- union wpa_event_data *data)
-+void hostapd_wpa_event(void *ctx, enum wpa_event_type event,
-+ union wpa_event_data *data)
++void supplicant_event(void *ctx, enum wpa_event_type event,
++ union wpa_event_data *data)
{
- struct hostapd_data *hapd = ctx;
- #ifndef CONFIG_NO_STDOUT_DEBUG
-@@ -1374,7 +1374,7 @@ void wpa_supplicant_event(void *ctx, enu
+ struct wpa_supplicant *wpa_s = ctx;
+ int resched;
+@@ -6872,7 +6872,7 @@ void wpa_supplicant_event(void *ctx, enu
}
-void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
-+void hostapd_wpa_event_global(void *ctx, enum wpa_event_type event,
++void supplicant_event_global(void *ctx, enum wpa_event_type event,
union wpa_event_data *data)
{
- struct hapd_interfaces *interfaces = ctx;
+ struct wpa_supplicant *wpa_s;
--- a/wpa_supplicant/wpa_priv.c
+++ b/wpa_supplicant/wpa_priv.c
-@@ -940,8 +940,8 @@ static void wpa_priv_send_ft_response(st
+@@ -1039,8 +1039,8 @@ static void wpa_priv_send_ft_response(st
}
{
struct wpa_priv_interface *iface = ctx;
-@@ -1010,7 +1010,7 @@ void wpa_supplicant_event(void *ctx, enu
+@@ -1103,7 +1103,7 @@ void wpa_supplicant_event(void *ctx, enu
}
union wpa_event_data *data)
{
struct wpa_priv_global *global = ctx;
-@@ -1122,6 +1122,8 @@ int main(int argc, char *argv[])
+@@ -1217,6 +1217,8 @@ int main(int argc, char *argv[])
if (os_program_init())
return -1;
wpa_priv_fd_workaround();
os_memset(&global, 0, sizeof(global));
---- a/wpa_supplicant/events.c
-+++ b/wpa_supplicant/events.c
-@@ -3398,8 +3398,8 @@ static void wpa_supplicant_event_assoc_a
- }
-
-
--void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
-- union wpa_event_data *data)
-+void supplicant_event(void *ctx, enum wpa_event_type event,
-+ union wpa_event_data *data)
- {
- struct wpa_supplicant *wpa_s = ctx;
- int resched;
-@@ -4074,7 +4074,7 @@ void wpa_supplicant_event(void *ctx, enu
- #endif /* CONFIG_AP */
- break;
- case EVENT_ACS_CHANNEL_SELECTED:
--#ifdef CONFIG_ACS
-+#if defined(CONFIG_ACS) && defined(CONFIG_AP)
- if (!wpa_s->ap_iface)
- break;
- hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0],
-@@ -4096,7 +4096,7 @@ void wpa_supplicant_event(void *ctx, enu
- }
-
-
--void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
-+void supplicant_event_global(void *ctx, enum wpa_event_type event,
- union wpa_event_data *data)
- {
- struct wpa_supplicant *wpa_s;
--- a/wpa_supplicant/wpa_supplicant.c
+++ b/wpa_supplicant/wpa_supplicant.c
-@@ -5094,7 +5094,6 @@ struct wpa_interface * wpa_supplicant_ma
+@@ -7583,7 +7583,6 @@ struct wpa_interface * wpa_supplicant_ma
return NULL;
}
/**
* wpa_supplicant_match_existing - Match existing interfaces
* @global: Pointer to global data from wpa_supplicant_init()
-@@ -5131,6 +5130,11 @@ static int wpa_supplicant_match_existing
+@@ -7618,6 +7617,11 @@ static int wpa_supplicant_match_existing
#endif /* CONFIG_MATCH_IFACE */
/**
* wpa_supplicant_add_iface - Add a new network interface
-@@ -5386,6 +5390,8 @@ struct wpa_global * wpa_supplicant_init(
+@@ -7874,6 +7878,8 @@ struct wpa_global * wpa_supplicant_init(
#ifndef CONFIG_NO_WPA_MSG
wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb);
#endif /* CONFIG_NO_WPA_MSG */
if (params->wpa_debug_file_path)
wpa_debug_open_file(params->wpa_debug_file_path);
---- a/hostapd/main.c
-+++ b/hostapd/main.c
-@@ -583,6 +583,11 @@ fail:
- return -1;
- }
-
-+void hostapd_wpa_event(void *ctx, enum wpa_event_type event,
-+ union wpa_event_data *data);
-+
-+void hostapd_wpa_event_global(void *ctx, enum wpa_event_type event,
-+ union wpa_event_data *data);
-
- #ifdef CONFIG_WPS
- static int gen_uuid(const char *txt_addr)
-@@ -660,6 +665,8 @@ int main(int argc, char *argv[])
- interfaces.global_ctrl_sock = -1;
- dl_list_init(&interfaces.global_ctrl_dst);
-
-+ wpa_supplicant_event = hostapd_wpa_event;
-+ wpa_supplicant_event_global = hostapd_wpa_event_global;
- for (;;) {
- c = getopt(argc, argv, "b:Bde:f:hi:KP:STtu:vg:G:");
- if (c < 0)
---- a/src/drivers/drivers.c
-+++ b/src/drivers/drivers.c
-@@ -10,6 +10,10 @@
- #include "utils/common.h"
- #include "driver.h"
-
-+void (*wpa_supplicant_event)(void *ctx, enum wpa_event_type event,
-+ union wpa_event_data *data);
-+void (*wpa_supplicant_event_global)(void *ctx, enum wpa_event_type event,
-+ union wpa_event_data *data);
-
- const struct wpa_driver_ops *const wpa_drivers[] =
- {
---- a/wpa_supplicant/eapol_test.c
-+++ b/wpa_supplicant/eapol_test.c
-@@ -29,7 +29,12 @@
- #include "ctrl_iface.h"
- #include "pcsc_funcs.h"
- #include "wpas_glue.h"
-+#include "drivers/driver.h"
-
-+void (*wpa_supplicant_event)(void *ctx, enum wpa_event_type event,
-+ union wpa_event_data *data);
-+void (*wpa_supplicant_event_global)(void *ctx, enum wpa_event_type event,
-+ union wpa_event_data *data);
-
- const struct wpa_driver_ops *const wpa_drivers[] = { NULL };
-
-@@ -1295,6 +1300,10 @@ static void usage(void)
- "option several times.\n");
- }
-
-+extern void supplicant_event(void *ctx, enum wpa_event_type event,
-+ union wpa_event_data *data);
-+extern void supplicant_event_global(void *ctx, enum wpa_event_type event,
-+ union wpa_event_data *data);
-
- int main(int argc, char *argv[])
- {
-@@ -1315,6 +1324,8 @@ int main(int argc, char *argv[])
- if (os_program_init())
- return -1;
-
-+ wpa_supplicant_event = supplicant_event;
-+ wpa_supplicant_event_global = supplicant_event_global;
- hostapd_logger_register_cb(hostapd_logger_cb);
-
- os_memset(&eapol_test, 0, sizeof(eapol_test));