diff --git a/package/network/services/hostapd/Makefile b/package/network/services/hostapd/Makefile
index fbc4e8c1c305d0580e44969973cc3438e1e3682b..896a6373bd84da03f3b9c4d5573dba9531085513 100644
--- a/package/network/services/hostapd/Makefile
+++ b/package/network/services/hostapd/Makefile
@@ -8,16 +8,16 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=hostapd
-PKG_VERSION:=20130807
+PKG_VERSION:=20131120
 PKG_RELEASE:=1
-PKG_REV:=d2ba3d6bd9336ef8fd761a0cc7999824d4c4da41
+PKG_REV:=594516b4c28a94ca686b17f1e463dfd6712b75a7
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
 PKG_SOURCE_URL:=git://w1.fi/srv/git/hostap.git
 PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
 PKG_SOURCE_VERSION:=$(PKG_REV)
 PKG_SOURCE_PROTO:=git
-PKG_MIRROR_MD5SUM:=4e7c1f97edd7514535056fce54ae053a
+# PKG_MIRROR_MD5SUM:=4e7c1f97edd7514535056fce54ae053a
 
 PKG_MAINTAINER:=Felix Fietkau <nbd@openwrt.org>
 
@@ -252,6 +252,7 @@ define Build/RunMake
 		$(TARGET_CONFIGURE_OPTS) \
 		$(DRIVER_MAKEOPTS) \
 		LIBS="$(TARGET_LDFLAGS)" \
+		LIBS_c="" \
 		BCHECK= \
 		$(2)
 endef
diff --git a/package/network/services/hostapd/patches/320-madwifi_key_fixes.patch b/package/network/services/hostapd/patches/100-madwifi_key_fixes.patch
similarity index 88%
rename from package/network/services/hostapd/patches/320-madwifi_key_fixes.patch
rename to package/network/services/hostapd/patches/100-madwifi_key_fixes.patch
index 45a7ac6c831e45b8c300e2ce8c90ea7c5b113cd6..dcd6d10bd682471dafae8c90d89a26a1b88ab574 100644
--- a/package/network/services/hostapd/patches/320-madwifi_key_fixes.patch
+++ b/package/network/services/hostapd/patches/100-madwifi_key_fixes.patch
@@ -1,6 +1,6 @@
 --- a/src/drivers/driver_madwifi.c
 +++ b/src/drivers/driver_madwifi.c
-@@ -453,7 +453,9 @@ wpa_driver_madwifi_set_key(const char *i
+@@ -450,7 +450,9 @@ wpa_driver_madwifi_set_key(const char *i
  
  	memset(&wk, 0, sizeof(wk));
  	wk.ik_type = cipher;
@@ -11,7 +11,7 @@
  	if (addr == NULL || is_broadcast_ether_addr(addr)) {
  		memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
  		wk.ik_keyix = key_idx;
-@@ -465,6 +467,20 @@ wpa_driver_madwifi_set_key(const char *i
+@@ -462,6 +464,20 @@ wpa_driver_madwifi_set_key(const char *i
  	wk.ik_keylen = key_len;
  	memcpy(wk.ik_keydata, key, key_len);
  
diff --git a/package/network/services/hostapd/patches/630-bool_fix.patch b/package/network/services/hostapd/patches/110-bool_fix.patch
similarity index 71%
rename from package/network/services/hostapd/patches/630-bool_fix.patch
rename to package/network/services/hostapd/patches/110-bool_fix.patch
index 6b48006ed8317a33d293ae10a00a4aee45eff860..9f82b0b0578e3645ba4ba2b2d18eb7918d56fa1d 100644
--- a/package/network/services/hostapd/patches/630-bool_fix.patch
+++ b/package/network/services/hostapd/patches/110-bool_fix.patch
@@ -1,6 +1,6 @@
 --- a/src/ap/ieee802_1x.c
 +++ b/src/ap/ieee802_1x.c
-@@ -1934,9 +1934,9 @@ void ieee802_1x_notify_pre_auth(struct e
+@@ -1933,9 +1933,9 @@ void ieee802_1x_notify_pre_auth(struct e
  }
  
  
@@ -11,4 +11,4 @@
 +	return bool_val ? "TRUE" : "FALSE";
  }
  
- #ifdef CONFIG_CTRL_IFACE_MIB
+ 
diff --git a/package/network/services/hostapd/patches/410-multicall.patch b/package/network/services/hostapd/patches/200-multicall.patch
similarity index 87%
rename from package/network/services/hostapd/patches/410-multicall.patch
rename to package/network/services/hostapd/patches/200-multicall.patch
index 62d37cb6d81815dbcae62dc2dda889384f7d98ed..2289f517f8062047da1d51ca64abd20517b5f72d 100644
--- a/package/network/services/hostapd/patches/410-multicall.patch
+++ b/package/network/services/hostapd/patches/200-multicall.patch
@@ -8,7 +8,7 @@
  
  ifndef CONFIG_OS
  ifdef CONFIG_NATIVE_WINDOWS
-@@ -192,10 +193,14 @@ ifdef CONFIG_IEEE80211AC
+@@ -200,10 +201,14 @@ ifdef CONFIG_IEEE80211AC
  CFLAGS += -DCONFIG_IEEE80211AC
  endif
  
@@ -26,7 +26,7 @@
  LIBS += $(DRV_AP_LIBS)
  
  ifdef CONFIG_L2_PACKET
-@@ -871,6 +876,12 @@ install: all
+@@ -890,6 +895,12 @@ install: all
  
  BCHECK=../src/drivers/build.hostapd
  
@@ -39,7 +39,7 @@
  hostapd: $(BCHECK) $(OBJS)
  	$(Q)$(CC) $(LDFLAGS) -o hostapd $(OBJS) $(LIBS)
  	@$(E) "  LD " $@
-@@ -909,6 +920,12 @@ HOBJS += ../src/crypto/aes-internal.o
+@@ -928,6 +939,12 @@ HOBJS += ../src/crypto/aes-internal.o
  HOBJS += ../src/crypto/aes-internal-enc.o
  endif
  
@@ -62,7 +62,7 @@
  
  BINALL=wpa_supplicant wpa_cli
  
-@@ -720,6 +721,10 @@ ifdef CONFIG_DYNAMIC_EAP_METHODS
+@@ -727,6 +728,10 @@ ifdef CONFIG_DYNAMIC_EAP_METHODS
  CFLAGS += -DCONFIG_DYNAMIC_EAP_METHODS
  LIBS += -ldl -rdynamic
  endif
@@ -73,7 +73,7 @@
  endif
  
  ifdef CONFIG_AP
-@@ -728,9 +733,11 @@ NEED_EAP_COMMON=y
+@@ -735,9 +740,11 @@ NEED_EAP_COMMON=y
  NEED_RSN_AUTHENTICATOR=y
  CFLAGS += -DCONFIG_AP
  OBJS += ap.o
@@ -85,7 +85,7 @@
  OBJS += ../src/ap/hostapd.o
  OBJS += ../src/ap/wpa_auth_glue.o
  OBJS += ../src/ap/utils.o
-@@ -785,10 +792,18 @@ endif
+@@ -799,10 +806,18 @@ endif
  ifdef CONFIG_HS20
  OBJS += ../src/ap/hs20.o
  endif
@@ -104,7 +104,7 @@
  NEED_AES_WRAP=y
  OBJS += ../src/ap/wpa_auth.o
  OBJS += ../src/ap/wpa_auth_ie.o
-@@ -1537,6 +1552,12 @@ wpa_priv: $(BCHECK) $(OBJS_priv)
+@@ -1551,6 +1566,12 @@ wpa_priv: $(BCHECK) $(OBJS_priv)
  
  $(OBJS_c) $(OBJS_t) $(OBJS_t2) $(OBJS) $(BCHECK) $(EXTRA_progs): .config
  
@@ -117,7 +117,7 @@
  wpa_supplicant: $(BCHECK) $(OBJS) $(EXTRA_progs)
  	$(Q)$(LDO) $(LDFLAGS) -o wpa_supplicant $(OBJS) $(LIBS) $(EXTRALIBS)
  	@$(E) "  LD " $@
-@@ -1611,6 +1632,12 @@ eap_eke.so: ../src/eap_peer/eap_eke.c ..
+@@ -1625,6 +1646,12 @@ eap_eke.so: ../src/eap_peer/eap_eke.c ..
  %@.service: %.service.arg.in
  	sed -e 's|\@BINDIR\@|$(BINDIR)|g' $< >$@
  
@@ -132,7 +132,7 @@
  wpa_cli.exe: wpa_cli
 --- a/src/drivers/driver.h
 +++ b/src/drivers/driver.h
-@@ -3868,8 +3868,8 @@ union wpa_event_data {
+@@ -4079,8 +4079,8 @@ union wpa_event_data {
   * Driver wrapper code should call this function whenever an event is received
   * from the driver.
   */
@@ -145,8 +145,8 @@
  /*
 --- a/src/ap/drv_callbacks.c
 +++ b/src/ap/drv_callbacks.c
-@@ -715,8 +715,8 @@ static void hostapd_event_eapol_rx(struc
- }
+@@ -844,8 +844,8 @@ static void hostapd_event_dfs_nop_finish
+ #endif /* NEED_AP_MLME */
  
  
 -void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
@@ -179,7 +179,7 @@
  	for (;;) {
 --- a/wpa_supplicant/events.c
 +++ b/wpa_supplicant/events.c
-@@ -2561,8 +2561,8 @@ static void wpas_event_deauth(struct wpa
+@@ -2710,8 +2710,8 @@ static void wpa_supplicant_update_channe
  }
  
  
@@ -192,7 +192,7 @@
  
 --- a/wpa_supplicant/wpa_supplicant.c
 +++ b/wpa_supplicant/wpa_supplicant.c
-@@ -3106,6 +3106,9 @@ static void wpa_supplicant_deinit_iface(
+@@ -3138,6 +3138,9 @@ static void wpa_supplicant_deinit_iface(
  	os_free(wpa_s);
  }
  
@@ -202,7 +202,7 @@
  
  /**
   * wpa_supplicant_add_iface - Add a new network interface
-@@ -3297,6 +3300,7 @@ struct wpa_global * wpa_supplicant_init(
+@@ -3329,6 +3332,7 @@ struct wpa_global * wpa_supplicant_init(
  	wpa_msg_register_ifname_cb(wpa_supplicant_msg_ifname_cb);
  #endif /* CONFIG_NO_WPA_MSG */
  
@@ -212,7 +212,7 @@
  		wpa_debug_open_syslog();
 --- a/hostapd/main.c
 +++ b/hostapd/main.c
-@@ -562,6 +562,9 @@ static int hostapd_get_ctrl_iface_group(
+@@ -511,6 +511,9 @@ static int hostapd_get_ctrl_iface_group(
  	return 0;
  }
  
@@ -222,13 +222,13 @@
  
  int main(int argc, char *argv[])
  {
-@@ -587,6 +590,7 @@ int main(int argc, char *argv[])
+@@ -541,6 +544,7 @@ int main(int argc, char *argv[])
  	interfaces.global_iface_name = NULL;
  	interfaces.global_ctrl_sock = -1;
  
 +	wpa_supplicant_event = hostapd_wpa_event;
  	for (;;) {
- 		c = getopt(argc, argv, "Bde:f:hKP:tvg:G:");
+ 		c = getopt(argc, argv, "b:Bde:f:hKP:Ttvg:G:");
  		if (c < 0)
 --- a/src/drivers/drivers.c
 +++ b/src/drivers/drivers.c
diff --git a/package/network/services/hostapd/patches/300-nl80211_multicall_fixes.patch b/package/network/services/hostapd/patches/300-nl80211_multicall_fixes.patch
deleted file mode 100644
index b3515340736abf500007c2d5f9a7e3b306d0a1c5..0000000000000000000000000000000000000000
--- a/package/network/services/hostapd/patches/300-nl80211_multicall_fixes.patch
+++ /dev/null
@@ -1,101 +0,0 @@
---- a/src/drivers/driver_nl80211.c
-+++ b/src/drivers/driver_nl80211.c
-@@ -754,7 +754,6 @@ nla_put_failure:
- }
- 
- 
--#ifndef HOSTAPD
- static int nl80211_get_macaddr(struct i802_bss *bss)
- {
- 	struct nl_msg *msg;
-@@ -776,7 +775,6 @@ nla_put_failure:
- 	nlmsg_free(msg);
- 	return NL80211_IFTYPE_UNSPECIFIED;
- }
--#endif /* HOSTAPD */
- 
- 
- static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv,
-@@ -3613,6 +3611,7 @@ static void * wpa_driver_nl80211_init(vo
- 	drv->monitor_sock = -1;
- 	drv->eapol_tx_sock = -1;
- 	drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
-+	drv->nlmode = NL80211_IFTYPE_STATION;
- 
- 	if (wpa_driver_nl80211_init_nl(drv)) {
- 		os_free(drv);
-@@ -4003,31 +4002,16 @@ static int i802_set_iface_flags(struct i
- 
- 
- static int
--wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv)
-+wpa_driver_nl80211_finish_drv_init_sta(struct wpa_driver_nl80211_data *drv,
-+				       int *send_rfkill_event)
- {
--#ifndef HOSTAPD
- 	enum nl80211_iftype nlmode = NL80211_IFTYPE_STATION;
--#endif /* HOSTAPD */
- 	struct i802_bss *bss = &drv->first_bss;
--	int send_rfkill_event = 0;
- 	int dynamic_if;
- 
--	drv->ifindex = if_nametoindex(bss->ifname);
--	bss->ifindex = drv->ifindex;
--	bss->wdev_id = drv->global->if_add_wdevid;
--	bss->wdev_id_set = drv->global->if_add_wdevid_set;
--
- 	dynamic_if = drv->ifindex == drv->global->if_add_ifindex;
- 	dynamic_if = dynamic_if || drv->global->if_add_wdevid_set;
--	drv->global->if_add_wdevid_set = 0;
- 
--	if (wpa_driver_nl80211_capa(drv))
--		return -1;
--
--	wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s",
--		   bss->ifname, drv->phyname);
--
--#ifndef HOSTAPD
- 	if (dynamic_if)
- 		nlmode = nl80211_get_ifmode(bss);
- 
-@@ -4056,7 +4040,7 @@ wpa_driver_nl80211_finish_drv_init(struc
- 				   "interface '%s' due to rfkill",
- 				   bss->ifname);
- 			drv->if_disabled = 1;
--			send_rfkill_event = 1;
-+			*send_rfkill_event = 1;
- 		} else {
- 			wpa_printf(MSG_ERROR, "nl80211: Could not set "
- 				   "interface '%s' UP", bss->ifname);
-@@ -4066,7 +4050,30 @@ wpa_driver_nl80211_finish_drv_init(struc
- 
- 	netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
- 			       1, IF_OPER_DORMANT);
--#endif /* HOSTAPD */
-+	return 0;
-+}
-+
-+static int
-+wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv)
-+{
-+	struct i802_bss *bss = &drv->first_bss;
-+	int send_rfkill_event = 0;
-+
-+	drv->ifindex = if_nametoindex(bss->ifname);
-+	bss->ifindex = drv->ifindex;
-+	bss->wdev_id = drv->global->if_add_wdevid;
-+	bss->wdev_id_set = drv->global->if_add_wdevid_set;
-+	drv->global->if_add_wdevid_set = 0;
-+
-+	if (wpa_driver_nl80211_capa(drv))
-+		return -1;
-+
-+	wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s",
-+		   bss->ifname, drv->phyname);
-+
-+	if (drv->nlmode == NL80211_IFTYPE_STATION &&
-+	    wpa_driver_nl80211_finish_drv_init_sta(drv, &send_rfkill_event))
-+		return -1;
- 
- 	if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
- 			       bss->addr))
diff --git a/package/network/services/hostapd/patches/400-noscan.patch b/package/network/services/hostapd/patches/300-noscan.patch
similarity index 75%
rename from package/network/services/hostapd/patches/400-noscan.patch
rename to package/network/services/hostapd/patches/300-noscan.patch
index 2c580299a5bf4670844589ae78bf087692422635..17e766161cb7e1147e46b8f8283358246224e8b2 100644
--- a/package/network/services/hostapd/patches/400-noscan.patch
+++ b/package/network/services/hostapd/patches/300-noscan.patch
@@ -1,6 +1,6 @@
 --- a/hostapd/config_file.c
 +++ b/hostapd/config_file.c
-@@ -2477,6 +2477,8 @@ static int hostapd_config_fill(struct ho
+@@ -2412,6 +2412,8 @@ static int hostapd_config_fill(struct ho
  			}
  #endif /* CONFIG_IEEE80211W */
  #ifdef CONFIG_IEEE80211N
@@ -11,7 +11,7 @@
  		} else if (os_strcmp(buf, "ht_capab") == 0) {
 --- a/src/ap/ap_config.h
 +++ b/src/ap/ap_config.h
-@@ -515,6 +515,7 @@ struct hostapd_config {
+@@ -527,6 +527,7 @@ struct hostapd_config {
  
  	int ht_op_mode_fixed;
  	u16 ht_capab;
@@ -21,7 +21,7 @@
  	int require_ht;
 --- a/src/ap/hw_features.c
 +++ b/src/ap/hw_features.c
-@@ -494,7 +494,7 @@ static int ieee80211n_check_40mhz(struct
+@@ -577,7 +577,7 @@ static int ieee80211n_check_40mhz(struct
  {
  	struct wpa_driver_scan_params params;
  
@@ -29,4 +29,4 @@
 +	if (!iface->conf->secondary_channel || iface->conf->noscan)
  		return 0; /* HT40 not used */
  
- 	wpa_printf(MSG_DEBUG, "Scan for neighboring BSSes prior to enabling "
+ 	hostapd_set_state(iface, HAPD_IFACE_HT_SCAN);
diff --git a/package/network/services/hostapd/patches/310-multicall_bridge_fix.patch b/package/network/services/hostapd/patches/310-multicall_bridge_fix.patch
deleted file mode 100644
index a4f9a00e00c03986f9a7da6e2ed854f5c110f618..0000000000000000000000000000000000000000
--- a/package/network/services/hostapd/patches/310-multicall_bridge_fix.patch
+++ /dev/null
@@ -1,45 +0,0 @@
---- a/src/drivers/driver_nl80211.c
-+++ b/src/drivers/driver_nl80211.c
-@@ -1095,6 +1095,10 @@ static void wpa_driver_nl80211_event_rtm
- 		return;
- 	}
- 
-+	if (ifi->ifi_family == AF_BRIDGE &&
-+	    drv->nlmode != NL80211_IFTYPE_AP)
-+		return;
-+
- 	wpa_printf(MSG_DEBUG, "RTM_NEWLINK: operstate=%d ifi_flags=0x%x "
- 		   "(%s%s%s%s)",
- 		   drv->operstate, ifi->ifi_flags,
-@@ -1202,6 +1206,10 @@ static void wpa_driver_nl80211_event_rtm
- 	attrlen = len;
- 	attr = (struct rtattr *) buf;
- 
-+	if (ifi->ifi_family == AF_BRIDGE &&
-+	    drv->nlmode != NL80211_IFTYPE_AP)
-+		return;
-+
- 	rta_len = RTA_ALIGN(sizeof(struct rtattr));
- 	while (RTA_OK(attr, attrlen)) {
- 		if (attr->rta_type == IFLA_IFNAME) {
-@@ -3613,6 +3621,11 @@ static void * wpa_driver_nl80211_init(vo
- 	drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
- 	drv->nlmode = NL80211_IFTYPE_STATION;
- 
-+#ifdef HOSTAPD
-+	drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
-+	drv->if_indices = drv->default_if_indices;
-+#endif
-+
- 	if (wpa_driver_nl80211_init_nl(drv)) {
- 		os_free(drv);
- 		return NULL;
-@@ -8845,8 +8858,6 @@ static void *i802_init(struct hostapd_da
- 		br_ifindex = 0;
- 	}
- 
--	drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
--	drv->if_indices = drv->default_if_indices;
- 	for (i = 0; i < params->num_bridge; i++) {
- 		if (params->bridge[i]) {
- 			ifindex = if_nametoindex(params->bridge[i]);
diff --git a/package/network/services/hostapd/patches/430-rescan_immediately.patch b/package/network/services/hostapd/patches/310-rescan_immediately.patch
similarity index 82%
rename from package/network/services/hostapd/patches/430-rescan_immediately.patch
rename to package/network/services/hostapd/patches/310-rescan_immediately.patch
index fc49995fa4efaa0eefb0f836b3d51eee1484c076..043f07c6271d78d310df585594257ff67892cea7 100644
--- a/package/network/services/hostapd/patches/430-rescan_immediately.patch
+++ b/package/network/services/hostapd/patches/310-rescan_immediately.patch
@@ -1,6 +1,6 @@
 --- a/wpa_supplicant/wpa_supplicant.c
 +++ b/wpa_supplicant/wpa_supplicant.c
-@@ -2457,7 +2457,7 @@ static struct wpa_supplicant * wpa_suppl
+@@ -2488,7 +2488,7 @@ static struct wpa_supplicant * wpa_suppl
  	if (wpa_s == NULL)
  		return NULL;
  	wpa_s->scan_req = INITIAL_SCAN_REQ;
diff --git a/package/network/services/hostapd/patches/440-optional_rfkill.patch b/package/network/services/hostapd/patches/320-optional_rfkill.patch
similarity index 88%
rename from package/network/services/hostapd/patches/440-optional_rfkill.patch
rename to package/network/services/hostapd/patches/320-optional_rfkill.patch
index 6bff863e3d59d255e382eb8cd2bf8b1e53d4d5a4..7ec51b102743b55da58fd10e1e52591546a908ef 100644
--- a/package/network/services/hostapd/patches/440-optional_rfkill.patch
+++ b/package/network/services/hostapd/patches/320-optional_rfkill.patch
@@ -1,6 +1,6 @@
 --- a/src/drivers/driver_nl80211.c
 +++ b/src/drivers/driver_nl80211.c
-@@ -216,7 +216,9 @@ struct wpa_driver_nl80211_data {
+@@ -254,7 +254,9 @@ struct wpa_driver_nl80211_data {
  	int if_removed;
  	int if_disabled;
  	int ignore_if_down_event;
@@ -10,7 +10,7 @@
  	struct wpa_driver_capa capa;
  	u8 *extended_capa, *extended_capa_mask;
  	unsigned int extended_capa_len;
-@@ -3482,7 +3484,7 @@ static int wpa_driver_nl80211_init_nl(st
+@@ -3630,7 +3632,7 @@ static int wpa_driver_nl80211_init_nl(st
  	return 0;
  }
  
@@ -19,7 +19,7 @@
  static void wpa_driver_nl80211_rfkill_blocked(void *ctx)
  {
  	wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked");
-@@ -3505,6 +3507,7 @@ static void wpa_driver_nl80211_rfkill_un
+@@ -3652,6 +3654,7 @@ static void wpa_driver_nl80211_rfkill_un
  	}
  	/* rtnetlink ifup handler will report interface as enabled */
  }
@@ -27,8 +27,8 @@
  
  
  static void wpa_driver_nl80211_handle_eapol_tx_status(int sock,
-@@ -3600,7 +3603,9 @@ static void * wpa_driver_nl80211_init(vo
- 				      void *global_priv)
+@@ -3740,7 +3743,9 @@ static void * wpa_driver_nl80211_drv_ini
+ 					  const u8 *set_addr)
  {
  	struct wpa_driver_nl80211_data *drv;
 +#ifdef CONFIG_RFKILL
@@ -37,7 +37,7 @@
  	struct i802_bss *bss;
  
  	if (global_priv == NULL)
-@@ -3634,6 +3639,7 @@ static void * wpa_driver_nl80211_init(vo
+@@ -3778,6 +3783,7 @@ static void * wpa_driver_nl80211_drv_ini
  	if (nl80211_init_bss(bss))
  		goto failed;
  
@@ -45,15 +45,15 @@
  	rcfg = os_zalloc(sizeof(*rcfg));
  	if (rcfg == NULL)
  		goto failed;
-@@ -3646,6 +3652,7 @@ static void * wpa_driver_nl80211_init(vo
+@@ -3790,6 +3796,7 @@ static void * wpa_driver_nl80211_drv_ini
  		wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available");
  		os_free(rcfg);
  	}
 +#endif /* CONFIG_RFKILL */
  
- 	if (wpa_driver_nl80211_finish_drv_init(drv))
- 		goto failed;
-@@ -3937,10 +3944,12 @@ static void nl80211_mgmt_unsubscribe(str
+ 	if (linux_iface_up(drv->global->ioctl_sock, ifname) > 0)
+ 		drv->start_iface_up = 1;
+@@ -4116,10 +4123,12 @@ static void nl80211_mgmt_unsubscribe(str
  }
  
  
@@ -66,7 +66,7 @@
  
  
  static void nl80211_del_p2pdev(struct i802_bss *bss)
-@@ -4048,13 +4057,16 @@ wpa_driver_nl80211_finish_drv_init_sta(s
+@@ -4246,13 +4255,16 @@ wpa_driver_nl80211_finish_drv_init(struc
  	}
  
  	if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1)) {
@@ -76,7 +76,7 @@
  				   "interface '%s' due to rfkill",
  				   bss->ifname);
  			drv->if_disabled = 1;
- 			*send_rfkill_event = 1;
+ 			send_rfkill_event = 1;
 -		} else {
 +		} else
 +#endif
@@ -84,7 +84,7 @@
  			wpa_printf(MSG_ERROR, "nl80211: Could not set "
  				   "interface '%s' UP", bss->ifname);
  			return -1;
-@@ -4093,8 +4105,10 @@ wpa_driver_nl80211_finish_drv_init(struc
+@@ -4268,8 +4280,10 @@ wpa_driver_nl80211_finish_drv_init(struc
  		return -1;
  
  	if (send_rfkill_event) {
@@ -95,7 +95,7 @@
  	}
  
  	return 0;
-@@ -4180,7 +4194,9 @@ static void wpa_driver_nl80211_deinit(st
+@@ -4347,7 +4361,9 @@ static void wpa_driver_nl80211_deinit(st
  
  	netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0,
  			       IF_OPER_UP);
diff --git a/package/network/services/hostapd/patches/330-nl80211_fix_set_freq.patch b/package/network/services/hostapd/patches/330-nl80211_fix_set_freq.patch
new file mode 100644
index 0000000000000000000000000000000000000000..a505a6089d555bc842df01ad809e28308f2969f9
--- /dev/null
+++ b/package/network/services/hostapd/patches/330-nl80211_fix_set_freq.patch
@@ -0,0 +1,20 @@
+--- a/src/drivers/driver_nl80211.c
++++ b/src/drivers/driver_nl80211.c
+@@ -6860,7 +6860,7 @@ static int wpa_driver_nl80211_set_freq(s
+ 
+ 	nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY);
+ 
+-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
++	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
+ 	if (nl80211_put_freq_params(msg, freq) < 0)
+ 		goto nla_put_failure;
+ 
+@@ -11322,7 +11322,7 @@ static int nl80211_switch_channel(void *
+ 		return -ENOMEM;
+ 
+ 	nl80211_cmd(drv, msg, 0, NL80211_CMD_CHANNEL_SWITCH);
+-	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
++	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
+ 	NLA_PUT_U32(msg, NL80211_ATTR_CH_SWITCH_COUNT, settings->cs_count);
+ 	ret = nl80211_put_freq_params(msg, &settings->freq_params);
+ 	if (ret)
diff --git a/package/network/services/hostapd/patches/340-reload_freq_change.patch b/package/network/services/hostapd/patches/340-reload_freq_change.patch
new file mode 100644
index 0000000000000000000000000000000000000000..d36b0460faae60948eb15a75abc5da481daa6734
--- /dev/null
+++ b/package/network/services/hostapd/patches/340-reload_freq_change.patch
@@ -0,0 +1,19 @@
+--- a/src/ap/hostapd.c
++++ b/src/ap/hostapd.c
+@@ -72,6 +72,16 @@ static void hostapd_reload_bss(struct ho
+ #endif /* CONFIG_NO_RADIUS */
+ 
+ 	ssid = &hapd->conf->ssid;
++
++	hostapd_set_freq(hapd, hapd->iconf->hw_mode, hapd->iface->freq,
++			 hapd->iconf->channel,
++			 hapd->iconf->ieee80211n,
++			 hapd->iconf->ieee80211ac,
++			 hapd->iconf->secondary_channel,
++			 hapd->iconf->vht_oper_chwidth,
++			 hapd->iconf->vht_oper_centr_freq_seg0_idx,
++			 hapd->iconf->vht_oper_centr_freq_seg1_idx);
++
+ 	if (!ssid->wpa_psk_set && ssid->wpa_psk && !ssid->wpa_psk->next &&
+ 	    ssid->wpa_passphrase_set && ssid->wpa_passphrase) {
+ 		/*
diff --git a/package/network/services/hostapd/patches/451-nl80211_del_beacon_bss.patch b/package/network/services/hostapd/patches/350-nl80211_del_beacon_bss.patch
similarity index 74%
rename from package/network/services/hostapd/patches/451-nl80211_del_beacon_bss.patch
rename to package/network/services/hostapd/patches/350-nl80211_del_beacon_bss.patch
index 0e33f0afaad99d344cfcec63d87a3158b3216ace..885922cdf123457d419cd35d393e56208e0e3edf 100644
--- a/package/network/services/hostapd/patches/451-nl80211_del_beacon_bss.patch
+++ b/package/network/services/hostapd/patches/350-nl80211_del_beacon_bss.patch
@@ -1,6 +1,6 @@
 --- a/src/drivers/driver_nl80211.c
 +++ b/src/drivers/driver_nl80211.c
-@@ -4115,16 +4115,18 @@ wpa_driver_nl80211_finish_drv_init(struc
+@@ -4290,18 +4290,20 @@ wpa_driver_nl80211_finish_drv_init(struc
  }
  
  
@@ -10,18 +10,21 @@
 +	struct wpa_driver_nl80211_data *drv = bss->drv;
  	struct nl_msg *msg;
  
-+	bss->beacon_set = 0;
  	msg = nlmsg_alloc();
  	if (!msg)
  		return -ENOMEM;
  
++	bss->beacon_set = 0;
+ 	wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)",
+-		   drv->ifindex);
++		   bss->ifindex);
  	nl80211_cmd(drv, msg, 0, NL80211_CMD_DEL_BEACON);
 -	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
 +	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
  
  	return send_and_recv_msgs(drv, msg, NULL, NULL);
   nla_put_failure:
-@@ -4132,6 +4134,15 @@ static int wpa_driver_nl80211_del_beacon
+@@ -4309,6 +4311,15 @@ static int wpa_driver_nl80211_del_beacon
  	return -ENOBUFS;
  }
  
@@ -29,7 +32,7 @@
 +{
 +	struct i802_bss *bss;
 +
-+	for (bss = &drv->first_bss; bss; bss = bss->next)
++	for (bss = drv->first_bss; bss; bss = bss->next)
 +		wpa_driver_nl80211_del_bss_beacon(bss);
 +
 +	return 0;
@@ -37,7 +40,7 @@
  
  /**
   * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
-@@ -9575,7 +9586,6 @@ static int wpa_driver_nl80211_stop_ap(vo
+@@ -9911,7 +9922,6 @@ static int wpa_driver_nl80211_stop_ap(vo
  	if (!is_ap_interface(drv->nlmode))
  		return -1;
  	wpa_driver_nl80211_del_beacon(drv);
diff --git a/package/network/services/hostapd/patches/452-ctrl_iface_reload.patch b/package/network/services/hostapd/patches/360-ctrl_iface_reload.patch
similarity index 97%
rename from package/network/services/hostapd/patches/452-ctrl_iface_reload.patch
rename to package/network/services/hostapd/patches/360-ctrl_iface_reload.patch
index 7459a0f7cd41256d0e84a6cd4199c31cea2be1c4..170d4f2f0c12ad5f0cacf5263e79ac63c3542e1c 100644
--- a/package/network/services/hostapd/patches/452-ctrl_iface_reload.patch
+++ b/package/network/services/hostapd/patches/360-ctrl_iface_reload.patch
@@ -85,7 +85,7 @@
  
  #ifdef CONFIG_IEEE80211W
  #ifdef NEED_AP_MLME
-@@ -949,6 +1013,10 @@ static void hostapd_ctrl_iface_receive(i
+@@ -1199,6 +1263,10 @@ static void hostapd_ctrl_iface_receive(i
  				reply_len += res;
  		}
  #endif /* CONFIG_NO_RADIUS */
diff --git a/package/network/services/hostapd/patches/453-ap_sta_support.patch b/package/network/services/hostapd/patches/370-ap_sta_support.patch
similarity index 97%
rename from package/network/services/hostapd/patches/453-ap_sta_support.patch
rename to package/network/services/hostapd/patches/370-ap_sta_support.patch
index d4b6c1da04dfab4d7745e26ba8987f086734bc75..95bde3f659b1dfb69a36cdfe7b0374c4a420e6dc 100644
--- a/package/network/services/hostapd/patches/453-ap_sta_support.patch
+++ b/package/network/services/hostapd/patches/370-ap_sta_support.patch
@@ -12,7 +12,7 @@
  	 * bridge_ifname - Optional bridge interface name
  	 *
  	 * If the driver interface (ifname) is included in a Linux bridge
-@@ -328,6 +333,8 @@ struct wpa_supplicant {
+@@ -325,6 +330,8 @@ struct wpa_supplicant {
  #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */
  	char bridge_ifname[16];
  
@@ -92,7 +92,7 @@
  /* Configure default/group WEP keys for static WEP */
  int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
  {
-@@ -676,8 +716,12 @@ void wpa_supplicant_set_state(struct wpa
+@@ -685,8 +725,12 @@ void wpa_supplicant_set_state(struct wpa
  #endif /* CONFIG_P2P */
  
  		sme_sched_obss_scan(wpa_s, 1);
@@ -105,7 +105,7 @@
  		wpa_s->new_connection = 1;
  		wpa_drv_set_operstate(wpa_s, 0);
  #ifndef IEEE8021X_EAPOL
-@@ -2875,6 +2919,20 @@ static int wpa_supplicant_init_iface(str
+@@ -2906,6 +2950,20 @@ static int wpa_supplicant_init_iface(str
  			   sizeof(wpa_s->bridge_ifname));
  	}
  
diff --git a/package/network/services/hostapd/patches/460-disable_ctrl_iface_mib.patch b/package/network/services/hostapd/patches/380-disable_ctrl_iface_mib.patch
similarity index 77%
rename from package/network/services/hostapd/patches/460-disable_ctrl_iface_mib.patch
rename to package/network/services/hostapd/patches/380-disable_ctrl_iface_mib.patch
index 8dc0a5de0752ee693dda1b269467130e8a07fc55..27f21bdb8f86b9011e2323046de28de6f7e9de59 100644
--- a/package/network/services/hostapd/patches/460-disable_ctrl_iface_mib.patch
+++ b/package/network/services/hostapd/patches/380-disable_ctrl_iface_mib.patch
@@ -1,6 +1,6 @@
 --- a/hostapd/Makefile
 +++ b/hostapd/Makefile
-@@ -136,6 +136,9 @@ endif
+@@ -144,6 +144,9 @@ endif
  ifdef CONFIG_NO_CTRL_IFACE
  CFLAGS += -DCONFIG_NO_CTRL_IFACE
  else
@@ -12,15 +12,15 @@
  endif
 --- a/hostapd/ctrl_iface.c
 +++ b/hostapd/ctrl_iface.c
-@@ -984,6 +984,7 @@ static void hostapd_ctrl_iface_receive(i
- 	} else if (os_strncmp(buf, "RELOG", 5) == 0) {
- 		if (wpa_debug_reopen_file() < 0)
- 			reply_len = -1;
+@@ -1234,6 +1234,7 @@ static void hostapd_ctrl_iface_receive(i
+ 	} else if (os_strcmp(buf, "STATUS") == 0) {
+ 		reply_len = hostapd_ctrl_iface_status(hapd, reply,
+ 						      reply_size);
 +#ifdef CONFIG_CTRL_IFACE_MIB
  	} else if (os_strcmp(buf, "MIB") == 0) {
  		reply_len = ieee802_11_get_mib(hapd, reply, reply_size);
  		if (reply_len >= 0) {
-@@ -1013,10 +1014,12 @@ static void hostapd_ctrl_iface_receive(i
+@@ -1263,10 +1264,12 @@ static void hostapd_ctrl_iface_receive(i
  				reply_len += res;
  		}
  #endif /* CONFIG_NO_RADIUS */
@@ -33,7 +33,7 @@
  	} else if (os_strcmp(buf, "STA-FIRST") == 0) {
  		reply_len = hostapd_ctrl_iface_sta_first(hapd, reply,
  							 reply_size);
-@@ -1026,6 +1029,7 @@ static void hostapd_ctrl_iface_receive(i
+@@ -1276,6 +1279,7 @@ static void hostapd_ctrl_iface_receive(i
  	} else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
  		reply_len = hostapd_ctrl_iface_sta_next(hapd, buf + 9, reply,
  							reply_size);
@@ -43,7 +43,7 @@
  			reply_len = -1;
 --- a/wpa_supplicant/Makefile
 +++ b/wpa_supplicant/Makefile
-@@ -768,6 +768,9 @@ ifdef CONFIG_WNM
+@@ -778,6 +778,9 @@ ifdef CONFIG_WNM
  OBJS += ../src/ap/wnm_ap.o
  endif
  ifdef CONFIG_CTRL_IFACE
@@ -55,7 +55,7 @@
  
 --- a/wpa_supplicant/ctrl_iface.c
 +++ b/wpa_supplicant/ctrl_iface.c
-@@ -5193,6 +5193,7 @@ char * wpa_supplicant_ctrl_iface_process
+@@ -5262,6 +5262,7 @@ char * wpa_supplicant_ctrl_iface_process
  			reply_len = -1;
  	} else if (os_strncmp(buf, "NOTE ", 5) == 0) {
  		wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
@@ -63,7 +63,7 @@
  	} else if (os_strcmp(buf, "MIB") == 0) {
  		reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
  		if (reply_len >= 0) {
-@@ -5204,6 +5205,7 @@ char * wpa_supplicant_ctrl_iface_process
+@@ -5273,6 +5274,7 @@ char * wpa_supplicant_ctrl_iface_process
  			else
  				reply_len += res;
  		}
@@ -71,7 +71,7 @@
  	} else if (os_strncmp(buf, "STATUS", 6) == 0) {
  		reply_len = wpa_supplicant_ctrl_iface_status(
  			wpa_s, buf + 6, reply, reply_size);
-@@ -5607,6 +5609,7 @@ char * wpa_supplicant_ctrl_iface_process
+@@ -5687,6 +5689,7 @@ char * wpa_supplicant_ctrl_iface_process
  		reply_len = wpa_supplicant_ctrl_iface_bss(
  			wpa_s, buf + 4, reply, reply_size);
  #ifdef CONFIG_AP
@@ -79,7 +79,7 @@
  	} else if (os_strcmp(buf, "STA-FIRST") == 0) {
  		reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
  	} else if (os_strncmp(buf, "STA ", 4) == 0) {
-@@ -5615,6 +5618,7 @@ char * wpa_supplicant_ctrl_iface_process
+@@ -5695,6 +5698,7 @@ char * wpa_supplicant_ctrl_iface_process
  	} else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
  		reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
  						   reply_size);
@@ -105,22 +105,22 @@
  
  #ifdef CONFIG_P2P_MANAGER
  static int p2p_manager_disconnect(struct hostapd_data *hapd, u16 stype,
-@@ -303,3 +305,4 @@ int hostapd_ctrl_iface_disassociate(stru
+@@ -423,3 +425,4 @@ int hostapd_parse_csa_settings(const cha
  
  	return 0;
  }
 +
 --- a/src/ap/ieee802_1x.c
 +++ b/src/ap/ieee802_1x.c
-@@ -1939,6 +1939,7 @@ static const char * bool_txt(Boolean boo
- 	return bool ? "TRUE" : "FALSE";
+@@ -1938,6 +1938,7 @@ static const char * bool_txt(Boolean boo
+ 	return bool_val ? "TRUE" : "FALSE";
  }
  
 +#ifdef CONFIG_CTRL_IFACE_MIB
  
  int ieee802_1x_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen)
  {
-@@ -2091,6 +2092,7 @@ int ieee802_1x_get_mib_sta(struct hostap
+@@ -2090,6 +2091,7 @@ int ieee802_1x_get_mib_sta(struct hostap
  	return len;
  }
  
@@ -130,7 +130,7 @@
  				struct sta_info *sta, int success)
 --- a/src/ap/wpa_auth.c
 +++ b/src/ap/wpa_auth.c
-@@ -2697,6 +2697,7 @@ static const char * wpa_bool_txt(int boo
+@@ -2708,6 +2708,7 @@ static const char * wpa_bool_txt(int boo
  	return bool ? "TRUE" : "FALSE";
  }
  
@@ -138,7 +138,7 @@
  
  #define RSN_SUITE "%02x-%02x-%02x-%d"
  #define RSN_SUITE_ARG(s) \
-@@ -2841,7 +2842,7 @@ int wpa_get_mib_sta(struct wpa_state_mac
+@@ -2852,7 +2853,7 @@ int wpa_get_mib_sta(struct wpa_state_mac
  
  	return len;
  }
@@ -149,7 +149,7 @@
  {
 --- a/src/rsn_supp/wpa.c
 +++ b/src/rsn_supp/wpa.c
-@@ -1842,6 +1842,8 @@ static u32 wpa_key_mgmt_suite(struct wpa
+@@ -1844,6 +1844,8 @@ static u32 wpa_key_mgmt_suite(struct wpa
  }
  
  
@@ -158,7 +158,7 @@
  #define RSN_SUITE "%02x-%02x-%02x-%d"
  #define RSN_SUITE_ARG(s) \
  ((s) >> 24) & 0xff, ((s) >> 16) & 0xff, ((s) >> 8) & 0xff, (s) & 0xff
-@@ -1925,6 +1927,7 @@ int wpa_sm_get_mib(struct wpa_sm *sm, ch
+@@ -1927,6 +1929,7 @@ int wpa_sm_get_mib(struct wpa_sm *sm, ch
  
  	return (int) len;
  }
diff --git a/package/network/services/hostapd/patches/470-wpa_ie_cap_workaround.patch b/package/network/services/hostapd/patches/390-wpa_ie_cap_workaround.patch
similarity index 100%
rename from package/network/services/hostapd/patches/470-wpa_ie_cap_workaround.patch
rename to package/network/services/hostapd/patches/390-wpa_ie_cap_workaround.patch
diff --git a/package/network/services/hostapd/patches/480-terminate_on_setup_failure.patch b/package/network/services/hostapd/patches/400-terminate_on_setup_failure.patch
similarity index 66%
rename from package/network/services/hostapd/patches/480-terminate_on_setup_failure.patch
rename to package/network/services/hostapd/patches/400-terminate_on_setup_failure.patch
index a8f395237c3cc92e4681e9a189562d781ea9bf2d..1270861e1e4d9bbd54488a136847f270129676bd 100644
--- a/package/network/services/hostapd/patches/480-terminate_on_setup_failure.patch
+++ b/package/network/services/hostapd/patches/400-terminate_on_setup_failure.patch
@@ -1,20 +1,22 @@
 --- a/src/ap/hostapd.c
 +++ b/src/ap/hostapd.c
-@@ -951,11 +951,8 @@ int hostapd_setup_interface_complete(str
+@@ -1100,13 +1100,8 @@ int hostapd_setup_interface_complete(str
  	size_t j;
  	u8 *prev_addr;
  
 -	if (err) {
 -		wpa_printf(MSG_ERROR, "Interface initialization failed");
--		eloop_terminate();
+-		hostapd_set_state(iface, HAPD_IFACE_DISABLED);
+-		if (iface->interfaces && iface->interfaces->terminate_on_error)
+-			eloop_terminate();
 -		return -1;
 -	}
 +	if (err)
 +		goto error;
  
  	wpa_printf(MSG_DEBUG, "Completing interface initialization");
- 	if (hapd->iconf->channel) {
-@@ -975,7 +972,7 @@ int hostapd_setup_interface_complete(str
+ 	if (iface->conf->channel) {
+@@ -1137,7 +1132,7 @@ int hostapd_setup_interface_complete(str
  				     hapd->iconf->vht_oper_centr_freq_seg1_idx)) {
  			wpa_printf(MSG_ERROR, "Could not set channel for "
  				   "kernel driver");
@@ -23,7 +25,7 @@
  		}
  	}
  
-@@ -986,7 +983,7 @@ int hostapd_setup_interface_complete(str
+@@ -1148,7 +1143,7 @@ int hostapd_setup_interface_complete(str
  			hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
  				       HOSTAPD_LEVEL_WARNING,
  				       "Failed to prepare rates table.");
@@ -32,7 +34,7 @@
  		}
  	}
  
-@@ -994,14 +991,14 @@ int hostapd_setup_interface_complete(str
+@@ -1156,14 +1151,14 @@ int hostapd_setup_interface_complete(str
  	    hostapd_set_rts(hapd, hapd->iconf->rts_threshold)) {
  		wpa_printf(MSG_ERROR, "Could not set RTS threshold for "
  			   "kernel driver");
@@ -49,7 +51,7 @@
  	}
  
  	prev_addr = hapd->own_addr;
-@@ -1011,7 +1008,7 @@ int hostapd_setup_interface_complete(str
+@@ -1173,7 +1168,7 @@ int hostapd_setup_interface_complete(str
  		if (j)
  			os_memcpy(hapd->own_addr, prev_addr, ETH_ALEN);
  		if (hostapd_setup_bss(hapd, j == 0))
@@ -58,7 +60,7 @@
  		if (hostapd_mac_comp_empty(hapd->conf->bssid) == 0)
  			prev_addr = hapd->own_addr;
  	}
-@@ -1025,7 +1022,7 @@ int hostapd_setup_interface_complete(str
+@@ -1188,7 +1183,7 @@ int hostapd_setup_interface_complete(str
  	if (hostapd_driver_commit(hapd) < 0) {
  		wpa_printf(MSG_ERROR, "%s: Failed to commit driver "
  			   "configuration", __func__);
@@ -67,14 +69,16 @@
  	}
  
  	/*
-@@ -1046,6 +1043,11 @@ int hostapd_setup_interface_complete(str
- 		   iface->bss[0]->conf->iface);
+@@ -1213,6 +1208,13 @@ int hostapd_setup_interface_complete(str
+ 		iface->interfaces->terminate_on_error--;
  
  	return 0;
 +
 +error:
 +	wpa_printf(MSG_ERROR, "Interface initialization failed");
-+	eloop_terminate();
++	hostapd_set_state(iface, HAPD_IFACE_DISABLED);
++	if (iface->interfaces && iface->interfaces->terminate_on_error)
++		eloop_terminate();
 +	return -1;
  }
  
diff --git a/package/network/services/hostapd/patches/510-bring_down_interface.patch b/package/network/services/hostapd/patches/410-bring_down_interface.patch
similarity index 82%
rename from package/network/services/hostapd/patches/510-bring_down_interface.patch
rename to package/network/services/hostapd/patches/410-bring_down_interface.patch
index e7520df341262b2a35001328b57fd716d4d7f951..31033a01a41fe530d70b2d3fa31dd286aab54582 100644
--- a/package/network/services/hostapd/patches/510-bring_down_interface.patch
+++ b/package/network/services/hostapd/patches/410-bring_down_interface.patch
@@ -1,6 +1,6 @@
 --- a/src/drivers/driver_nl80211.c
 +++ b/src/drivers/driver_nl80211.c
-@@ -8145,12 +8145,7 @@ static int wpa_driver_nl80211_set_mode(s
+@@ -8480,12 +8480,7 @@ static int wpa_driver_nl80211_set_mode(s
  			/* Try to set the mode again while the interface is
  			 * down */
  			ret = nl80211_set_mode(drv, drv->ifindex, nlmode);
@@ -14,7 +14,7 @@
  				break;
  		} else
  			wpa_printf(MSG_DEBUG, "nl80211: Failed to set "
-@@ -8163,6 +8158,8 @@ static int wpa_driver_nl80211_set_mode(s
+@@ -8498,6 +8493,8 @@ static int wpa_driver_nl80211_set_mode(s
  			   "interface is down");
  		drv->nlmode = nlmode;
  		drv->ignore_if_down_event = 1;
diff --git a/package/network/services/hostapd/patches/520-fix_wps_pin_crash.patch b/package/network/services/hostapd/patches/420-fix_wps_pin_crash.patch
similarity index 100%
rename from package/network/services/hostapd/patches/520-fix_wps_pin_crash.patch
rename to package/network/services/hostapd/patches/420-fix_wps_pin_crash.patch
diff --git a/package/network/services/hostapd/patches/420-timestamp_check.patch b/package/network/services/hostapd/patches/420-timestamp_check.patch
deleted file mode 100644
index 7ca9127037cc3a3649b8773c47ddb8ab8325f752..0000000000000000000000000000000000000000
--- a/package/network/services/hostapd/patches/420-timestamp_check.patch
+++ /dev/null
@@ -1,12 +0,0 @@
---- a/src/tls/x509v3.c
-+++ b/src/tls/x509v3.c
-@@ -1847,6 +1847,9 @@ int x509_certificate_chain_validate(stru
- 		if (chain_trusted)
- 			continue;
- 
-+#ifdef NO_TIMESTAMP_CHECK
-+		disable_time_checks = 1;
-+#endif
- 		if (!disable_time_checks &&
- 		    ((unsigned long) now.sec <
- 		     (unsigned long) cert->not_before ||
diff --git a/package/network/services/hostapd/patches/530-wps_single_auth_enc_type.patch b/package/network/services/hostapd/patches/430-wps_single_auth_enc_type.patch
similarity index 84%
rename from package/network/services/hostapd/patches/530-wps_single_auth_enc_type.patch
rename to package/network/services/hostapd/patches/430-wps_single_auth_enc_type.patch
index 6f4a6557d5654e2a741cf125a31f81ebde7d9ad3..6e86658857b98e18efda5e7eae70246fed47f081 100644
--- a/package/network/services/hostapd/patches/530-wps_single_auth_enc_type.patch
+++ b/package/network/services/hostapd/patches/430-wps_single_auth_enc_type.patch
@@ -1,6 +1,6 @@
 --- a/src/ap/wps_hostapd.c
 +++ b/src/ap/wps_hostapd.c
-@@ -989,11 +989,9 @@ int hostapd_init_wps(struct hostapd_data
+@@ -1069,11 +1069,9 @@ int hostapd_init_wps(struct hostapd_data
  
  		if (conf->rsn_pairwise & WPA_CIPHER_CCMP)
  			wps->encr_types |= WPS_ENCR_AES;
@@ -14,7 +14,7 @@
  		if (conf->wpa_key_mgmt & WPA_KEY_MGMT_PSK)
  			wps->auth_types |= WPS_AUTH_WPAPSK;
  		if (conf->wpa_key_mgmt & WPA_KEY_MGMT_IEEE8021X)
-@@ -1001,7 +999,7 @@ int hostapd_init_wps(struct hostapd_data
+@@ -1081,7 +1079,7 @@ int hostapd_init_wps(struct hostapd_data
  
  		if (conf->wpa_pairwise & WPA_CIPHER_CCMP)
  			wps->encr_types |= WPS_ENCR_AES;
diff --git a/package/network/services/hostapd/patches/540-dynamic_20_40_mhz.patch b/package/network/services/hostapd/patches/440-dynamic_20_40_mhz.patch
similarity index 89%
rename from package/network/services/hostapd/patches/540-dynamic_20_40_mhz.patch
rename to package/network/services/hostapd/patches/440-dynamic_20_40_mhz.patch
index 0ce8772c609ad6143b65fb16828b892c90c7b992..f2d7795e81cd5878720a60fa7143b35c1c4e2698 100644
--- a/package/network/services/hostapd/patches/540-dynamic_20_40_mhz.patch
+++ b/package/network/services/hostapd/patches/440-dynamic_20_40_mhz.patch
@@ -1,6 +1,6 @@
 --- a/hostapd/config_file.c
 +++ b/hostapd/config_file.c
-@@ -2487,6 +2487,10 @@ static int hostapd_config_fill(struct ho
+@@ -2422,6 +2422,10 @@ static int hostapd_config_fill(struct ho
  					   "ht_capab", line);
  				errors++;
  			}
@@ -10,20 +10,20 @@
 +				conf->dynamic_ht40 = 1500;
  		} else if (os_strcmp(buf, "require_ht") == 0) {
  			conf->require_ht = atoi(pos);
- #endif /* CONFIG_IEEE80211N */
+ 		} else if (os_strcmp(buf, "obss_interval") == 0) {
 --- a/src/ap/ap_config.h
 +++ b/src/ap/ap_config.h
-@@ -519,6 +519,7 @@ struct hostapd_config {
+@@ -531,6 +531,7 @@ struct hostapd_config {
  	int ieee80211n;
  	int secondary_channel;
  	int require_ht;
 +	int dynamic_ht40;
+ 	int obss_interval;
  	u32 vht_capab;
  	int ieee80211ac;
- 	int require_vht;
 --- a/src/ap/hostapd.c
 +++ b/src/ap/hostapd.c
-@@ -22,6 +22,7 @@
+@@ -23,6 +23,7 @@
  #include "beacon.h"
  #include "iapp.h"
  #include "ieee802_1x.h"
@@ -31,17 +31,17 @@
  #include "ieee802_11_auth.h"
  #include "vlan_init.h"
  #include "wpa_auth.h"
-@@ -319,6 +320,7 @@ static void hostapd_cleanup_iface_pre(st
- 
+@@ -329,6 +330,7 @@ static void hostapd_cleanup(struct hosta
  static void hostapd_cleanup_iface_partial(struct hostapd_iface *iface)
  {
+ 	wpa_printf(MSG_DEBUG, "%s(%p)", __func__, iface);
 +	hostapd_deinit_ht(iface);
  	hostapd_free_hw_features(iface->hw_features, iface->num_hw_features);
  	iface->hw_features = NULL;
  	os_free(iface->current_rates);
 --- a/src/ap/hostapd.h
 +++ b/src/ap/hostapd.h
-@@ -274,6 +274,9 @@ struct hostapd_iface {
+@@ -326,6 +326,9 @@ struct hostapd_iface {
  	/* Overlapping BSS information */
  	int olbc_ht;
  
@@ -49,11 +49,11 @@
 +	struct os_time last_20mhz_trigger;
 +
  	u16 ht_op_mode;
- 	void (*scan_cb)(struct hostapd_iface *iface);
- };
+ 
+ 	/* surveying helpers */
 --- a/src/ap/ieee802_11.c
 +++ b/src/ap/ieee802_11.c
-@@ -1513,6 +1513,9 @@ static void handle_beacon(struct hostapd
+@@ -1538,6 +1538,9 @@ static void handle_beacon(struct hostapd
  					     sizeof(mgmt->u.beacon)), &elems,
  				      0);
  
@@ -65,7 +65,7 @@
  
 --- a/src/ap/ieee802_11.h
 +++ b/src/ap/ieee802_11.h
-@@ -81,4 +81,17 @@ int hostapd_update_time_adv(struct hosta
+@@ -82,4 +82,17 @@ int hostapd_update_time_adv(struct hosta
  void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr);
  u8 * hostapd_eid_bss_max_idle_period(struct hostapd_data *hapd, u8 *eid);
  
@@ -97,7 +97,7 @@
  
  
  u8 * hostapd_eid_ht_capabilities(struct hostapd_data *hapd, u8 *eid)
-@@ -70,12 +72,15 @@ u8 * hostapd_eid_ht_operation(struct hos
+@@ -86,12 +88,15 @@ u8 * hostapd_eid_ht_operation(struct hos
  
  	oper->control_chan = hapd->iconf->channel;
  	oper->operation_mode = host_to_le16(hapd->iface->ht_op_mode);
@@ -119,7 +119,7 @@
  
  	pos += sizeof(*oper);
  
-@@ -270,3 +275,84 @@ void hostapd_get_ht_capab(struct hostapd
+@@ -286,3 +291,84 @@ void hostapd_get_ht_capab(struct hostapd
  
  	neg_ht_cap->ht_capabilities_info = host_to_le16(cap);
  }
diff --git a/package/network/services/hostapd/patches/550-limit_debug_messages.patch b/package/network/services/hostapd/patches/450-limit_debug_messages.patch
similarity index 100%
rename from package/network/services/hostapd/patches/550-limit_debug_messages.patch
rename to package/network/services/hostapd/patches/450-limit_debug_messages.patch
diff --git a/package/network/services/hostapd/patches/450-reload_freq_change.patch b/package/network/services/hostapd/patches/450-reload_freq_change.patch
deleted file mode 100644
index e98137569216fbea5678ca543e4cf03efa1ffb78..0000000000000000000000000000000000000000
--- a/package/network/services/hostapd/patches/450-reload_freq_change.patch
+++ /dev/null
@@ -1,85 +0,0 @@
---- a/src/ap/hostapd.c
-+++ b/src/ap/hostapd.c
-@@ -133,38 +133,51 @@ static void hostapd_clear_old(struct hos
- int hostapd_reload_config(struct hostapd_iface *iface)
- {
- 	struct hostapd_data *hapd = iface->bss[0];
--	struct hostapd_config *newconf, *oldconf;
-+	struct hostapd_config *conf = hapd->iconf, *oldconf = NULL;
- 	size_t j;
- 
--	if (iface->config_fname == NULL) {
--		/* Only in-memory config in use - assume it has been updated */
-+	if (iface->config_fname) {
-+		if (iface->interfaces == NULL ||
-+			iface->interfaces->config_read_cb == NULL)
-+			return -1;
-+		conf = iface->interfaces->config_read_cb(iface->config_fname);
-+		if (conf == NULL)
-+			return -1;
-+
- 		hostapd_clear_old(iface);
--		for (j = 0; j < iface->num_bss; j++)
--			hostapd_reload_bss(iface->bss[j]);
--		return 0;
--	}
- 
--	if (iface->interfaces == NULL ||
--	    iface->interfaces->config_read_cb == NULL)
--		return -1;
--	newconf = iface->interfaces->config_read_cb(iface->config_fname);
--	if (newconf == NULL)
--		return -1;
-+		oldconf = hapd->iconf;
-+		iface->conf = conf;
-+	}
- 
--	hostapd_clear_old(iface);
-+	hostapd_select_hw_mode(iface);
-+	iface->freq = hostapd_hw_get_freq(hapd, conf->channel);
- 
--	oldconf = hapd->iconf;
--	iface->conf = newconf;
-+	if (iface->current_mode)
-+		hostapd_prepare_rates(iface, iface->current_mode);
- 
- 	for (j = 0; j < iface->num_bss; j++) {
- 		hapd = iface->bss[j];
--		hapd->iconf = newconf;
--		hapd->conf = &newconf->bss[j];
-+		hapd->iconf = iface->conf;
-+		hapd->conf = &iface->conf->bss[j];
-+
-+		if (hostapd_set_freq(hapd, conf->hw_mode, iface->freq,
-+					 conf->channel,
-+					 conf->ieee80211n,
-+					 conf->ieee80211ac,
-+					 conf->secondary_channel,
-+					 conf->vht_oper_chwidth,
-+					 conf->vht_oper_centr_freq_seg0_idx,
-+					 conf->vht_oper_centr_freq_seg1_idx)) {
-+			wpa_printf(MSG_ERROR, "Could not set channel for "
-+				   "kernel driver");
-+		}
-+
- 		hostapd_reload_bss(hapd);
- 	}
- 
--	hostapd_config_free(oldconf);
--
-+	if (oldconf)
-+		hostapd_config_free(oldconf);
- 
- 	return 0;
- }
---- a/src/drivers/driver_nl80211.c
-+++ b/src/drivers/driver_nl80211.c
-@@ -6511,7 +6511,7 @@ static int wpa_driver_nl80211_set_freq(s
- 
- 	nl80211_cmd(drv, msg, 0, NL80211_CMD_SET_WIPHY);
- 
--	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex);
-+	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
- 	NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq);
- 	if (freq->vht_enabled) {
- 		switch (freq->bandwidth) {
diff --git a/package/network/services/hostapd/patches/560-indicate-features.patch b/package/network/services/hostapd/patches/460-indicate-features.patch
similarity index 86%
rename from package/network/services/hostapd/patches/560-indicate-features.patch
rename to package/network/services/hostapd/patches/460-indicate-features.patch
index a719afd1fdc170e3b0d70985aec812d5a8d7c24d..7a44da122b8da0776352c4356d1ebffb0149b3ac 100644
--- a/package/network/services/hostapd/patches/560-indicate-features.patch
+++ b/package/network/services/hostapd/patches/460-indicate-features.patch
@@ -8,18 +8,18 @@
  #include "crypto/random.h"
  #include "crypto/tls.h"
  #include "common/version.h"
-@@ -592,7 +593,7 @@ int main(int argc, char *argv[])
+@@ -546,7 +547,7 @@ int main(int argc, char *argv[])
  
  	wpa_supplicant_event = hostapd_wpa_event;
  	for (;;) {
--		c = getopt(argc, argv, "Bde:f:hKP:tvg:G:");
-+		c = getopt(argc, argv, "Bde:f:hKP:tg:G:v::");
+-		c = getopt(argc, argv, "b:Bde:f:hKP:Ttvg:G:");
++		c = getopt(argc, argv, "b:Bde:f:hKP:Ttg:G:v::");
  		if (c < 0)
  			break;
  		switch (c) {
-@@ -624,6 +625,8 @@ int main(int argc, char *argv[])
- 			wpa_debug_timestamp++;
+@@ -583,6 +584,8 @@ int main(int argc, char *argv[])
  			break;
+ #endif /* CONFIG_DEBUG_LINUX_TRACING */
  		case 'v':
 +			if (optarg)
 +				exit(!has_feature(optarg));
diff --git a/package/network/services/hostapd/patches/590-hostapd_cli_ifdef.patch b/package/network/services/hostapd/patches/470-hostapd_cli_ifdef.patch
similarity index 79%
rename from package/network/services/hostapd/patches/590-hostapd_cli_ifdef.patch
rename to package/network/services/hostapd/patches/470-hostapd_cli_ifdef.patch
index cbf1e485cded1e8d2f1c6aa2ef89b1eb7f5c9779..5ac0fddf7097ca020ce86e3a5c2c4d29b025cc56 100644
--- a/package/network/services/hostapd/patches/590-hostapd_cli_ifdef.patch
+++ b/package/network/services/hostapd/patches/470-hostapd_cli_ifdef.patch
@@ -8,15 +8,15 @@
  "   wps_pin <uuid> <pin> [timeout] [addr]  add WPS Enrollee PIN\n"
  "   wps_check_pin <PIN>  verify PIN checksum\n"
  "   wps_pbc              indicate button pushed to initiate PBC\n"
-@@ -79,7 +78,6 @@ static const char *commands_help =
- #endif /* CONFIG_WPS_NFC */
+@@ -80,7 +79,6 @@ static const char *commands_help =
  "   wps_ap_pin <cmd> [params..]  enable/disable AP PIN\n"
  "   wps_config <SSID> <auth> <encr> <key>  configure AP\n"
+ "   wps_get_status       show current WPS status\n"
 -#endif /* CONFIG_WPS */
  "   get_config           show current configuration\n"
  "   help                 show this usage help\n"
  "   interface [ifname]   show interfaces/select interface\n"
-@@ -340,7 +338,6 @@ static int hostapd_cli_cmd_sa_query(stru
+@@ -352,7 +350,6 @@ static int hostapd_cli_cmd_sa_query(stru
  #endif /* CONFIG_IEEE80211W */
  
  
@@ -24,7 +24,7 @@
  static int hostapd_cli_cmd_wps_pin(struct wpa_ctrl *ctrl, int argc,
  				   char *argv[])
  {
-@@ -559,7 +556,6 @@ static int hostapd_cli_cmd_wps_config(st
+@@ -578,7 +575,6 @@ static int hostapd_cli_cmd_wps_config(st
  			 ssid_hex, argv[1]);
  	return wpa_ctrl_command(ctrl, buf);
  }
@@ -32,7 +32,7 @@
  
  
  static int hostapd_cli_cmd_disassoc_imminent(struct wpa_ctrl *ctrl, int argc,
-@@ -805,7 +801,6 @@ static struct hostapd_cli_cmd hostapd_cl
+@@ -903,7 +899,6 @@ static struct hostapd_cli_cmd hostapd_cl
  #ifdef CONFIG_IEEE80211W
  	{ "sa_query", hostapd_cli_cmd_sa_query },
  #endif /* CONFIG_IEEE80211W */
@@ -40,10 +40,10 @@
  	{ "wps_pin", hostapd_cli_cmd_wps_pin },
  	{ "wps_check_pin", hostapd_cli_cmd_wps_check_pin },
  	{ "wps_pbc", hostapd_cli_cmd_wps_pbc },
-@@ -818,7 +813,6 @@ static struct hostapd_cli_cmd hostapd_cl
- #endif /* CONFIG_WPS_NFC */
+@@ -917,7 +912,6 @@ static struct hostapd_cli_cmd hostapd_cl
  	{ "wps_ap_pin", hostapd_cli_cmd_wps_ap_pin },
  	{ "wps_config", hostapd_cli_cmd_wps_config },
+ 	{ "wps_get_status", hostapd_cli_cmd_wps_get_status },
 -#endif /* CONFIG_WPS */
  	{ "disassoc_imminent", hostapd_cli_cmd_disassoc_imminent },
  	{ "ess_disassoc", hostapd_cli_cmd_ess_disassoc },
diff --git a/package/network/services/hostapd/patches/610-max_num_sta_probe.patch b/package/network/services/hostapd/patches/480-max_num_sta_probe.patch
similarity index 85%
rename from package/network/services/hostapd/patches/610-max_num_sta_probe.patch
rename to package/network/services/hostapd/patches/480-max_num_sta_probe.patch
index 141eb5b6e362402a9c7b688305f9b32cfe065716..e5ca8b443430f5a8bce8cd80cf342e6a56d90bea 100644
--- a/package/network/services/hostapd/patches/610-max_num_sta_probe.patch
+++ b/package/network/services/hostapd/patches/480-max_num_sta_probe.patch
@@ -1,6 +1,6 @@
 --- a/src/ap/beacon.c
 +++ b/src/ap/beacon.c
-@@ -455,6 +455,10 @@ void handle_probe_req(struct hostapd_dat
+@@ -501,6 +501,10 @@ void handle_probe_req(struct hostapd_dat
  		return;
  	}
  
diff --git a/package/network/services/hostapd/patches/620-scan_wait.patch b/package/network/services/hostapd/patches/490-scan_wait.patch
similarity index 65%
rename from package/network/services/hostapd/patches/620-scan_wait.patch
rename to package/network/services/hostapd/patches/490-scan_wait.patch
index ea1528049c64a6930e5956beeddf48263f2e3ff6..61715d6a985724b4b23ce7688fe831bee294f690 100644
--- a/package/network/services/hostapd/patches/620-scan_wait.patch
+++ b/package/network/services/hostapd/patches/490-scan_wait.patch
@@ -23,16 +23,17 @@
 +}
  
  /**
-  * hostapd_init - Allocate and initialize per-interface data
-@@ -190,6 +200,7 @@ static struct hostapd_iface * hostapd_in
- 		if (hapd == NULL)
- 			goto fail;
- 		hapd->msg_ctx = hapd;
-+		hapd->setup_complete_cb = hostapd_setup_complete_cb;
+  * hostapd_driver_init - Preparate driver interface
+@@ -165,6 +175,8 @@ static int hostapd_driver_init(struct ho
+ 		return -1;
  	}
  
- 	return hapd_iface;
-@@ -437,8 +448,6 @@ static void hostapd_global_deinit(const 
++	hapd->setup_complete_cb = hostapd_setup_complete_cb;
++
+ 	/* Initialize the driver interface */
+ 	if (!(b[0] | b[1] | b[2] | b[3] | b[4] | b[5]))
+ 		b = NULL;
+@@ -381,8 +393,6 @@ static void hostapd_global_deinit(const 
  #endif /* CONFIG_NATIVE_WINDOWS */
  
  	eap_server_unregister_methods();
@@ -41,7 +42,7 @@
  }
  
  
-@@ -464,11 +473,6 @@ static int hostapd_global_run(struct hap
+@@ -408,11 +418,6 @@ static int hostapd_global_run(struct hap
  	}
  #endif /* EAP_SERVER_TNC */
  
@@ -53,13 +54,13 @@
  	eloop_run();
  
  	return 0;
-@@ -572,8 +576,7 @@ int main(int argc, char *argv[])
+@@ -521,8 +526,7 @@ int main(int argc, char *argv[])
  	struct hapd_interfaces interfaces;
  	int ret = 1;
- 	size_t i;
+ 	size_t i, j;
 -	int c, debug = 0, daemonize = 0;
 -	char *pid_file = NULL;
 +	int c, debug = 0;
  	const char *log_file = NULL;
  	const char *entropy_file = NULL;
- 
+ 	char **bss_config = NULL, **tmp_bss;
diff --git a/package/network/services/hostapd/patches/601-wpa_supplicant-add-new-config-params-to-be-used-with.patch b/package/network/services/hostapd/patches/500-wpa_supplicant-add-new-config-params-to-be-used-with.patch
similarity index 93%
rename from package/network/services/hostapd/patches/601-wpa_supplicant-add-new-config-params-to-be-used-with.patch
rename to package/network/services/hostapd/patches/500-wpa_supplicant-add-new-config-params-to-be-used-with.patch
index 0e3f248fcf73c7e45337edcfb38844662f8acc09..544151ef2b2bce784d1ca24d1bf4bcc47627ebfe 100644
--- a/package/network/services/hostapd/patches/601-wpa_supplicant-add-new-config-params-to-be-used-with.patch
+++ b/package/network/services/hostapd/patches/500-wpa_supplicant-add-new-config-params-to-be-used-with.patch
@@ -20,9 +20,9 @@ Signed-hostap: Antonio Quartulli <ordex@autistici.org>
  
 +#include "drivers/nl80211_copy.h"
  #include "common/defs.h"
+ #include "utils/list.h"
  
- #define HOSTAPD_CHAN_DISABLED 0x00000001
-@@ -370,6 +371,11 @@ struct wpa_driver_associate_params {
+@@ -404,6 +405,11 @@ struct wpa_driver_associate_params {
  	 */
  	int freq;
  
@@ -44,7 +44,7 @@ Signed-hostap: Antonio Quartulli <ordex@autistici.org>
  #include "config.h"
  
  
-@@ -1374,6 +1375,97 @@ static char * wpa_config_write_p2p_clien
+@@ -1512,6 +1513,97 @@ static char * wpa_config_write_psk_list(
  
  #endif /* CONFIG_P2P */
  
@@ -142,7 +142,7 @@ Signed-hostap: Antonio Quartulli <ordex@autistici.org>
  /* Helper macros for network block parser */
  
  #ifdef OFFSET
-@@ -1573,6 +1665,9 @@ static const struct parse_data ssid_fiel
+@@ -1715,6 +1807,9 @@ static const struct parse_data ssid_fiel
  	{ INT(ap_max_inactivity) },
  	{ INT(dtim_period) },
  	{ INT(beacon_int) },
@@ -154,15 +154,15 @@ Signed-hostap: Antonio Quartulli <ordex@autistici.org>
  #undef OFFSET
 --- a/wpa_supplicant/config_ssid.h
 +++ b/wpa_supplicant/config_ssid.h
-@@ -11,6 +11,7 @@
- 
+@@ -12,6 +12,7 @@
  #include "common/defs.h"
+ #include "utils/list.h"
  #include "eap_peer/eap_config.h"
 +#include "drivers/nl80211_copy.h"
  
  #define MAX_SSID_LEN 32
  
-@@ -600,6 +601,10 @@ struct wpa_ssid {
+@@ -620,6 +621,10 @@ struct wpa_ssid {
  	 * dereferences since it may not be updated in all cases.
  	 */
  	void *parent_cred;
@@ -175,7 +175,7 @@ Signed-hostap: Antonio Quartulli <ordex@autistici.org>
  #endif /* CONFIG_SSID_H */
 --- a/wpa_supplicant/wpa_supplicant.c
 +++ b/wpa_supplicant/wpa_supplicant.c
-@@ -1594,15 +1594,24 @@ void wpa_supplicant_associate(struct wpa
+@@ -1623,15 +1623,24 @@ void wpa_supplicant_associate(struct wpa
  		params.ssid_len = ssid->ssid_len;
  	}
  
diff --git a/package/network/services/hostapd/patches/602-driver_nl80211-use-new-parameters-during-ibss-join.patch b/package/network/services/hostapd/patches/501-driver_nl80211-use-new-parameters-during-ibss-join.patch
similarity index 94%
rename from package/network/services/hostapd/patches/602-driver_nl80211-use-new-parameters-during-ibss-join.patch
rename to package/network/services/hostapd/patches/501-driver_nl80211-use-new-parameters-during-ibss-join.patch
index a95860260b2c780ae7f65b119b091bb08dd2f4e7..565bbc9762a631382e2f9519b16330f5f1d08c52 100644
--- a/package/network/services/hostapd/patches/602-driver_nl80211-use-new-parameters-during-ibss-join.patch
+++ b/package/network/services/hostapd/patches/501-driver_nl80211-use-new-parameters-during-ibss-join.patch
@@ -10,7 +10,7 @@ Signed-hostap: Antonio Quartulli <ordex@autistici.org>
 
 --- a/src/drivers/driver_nl80211.c
 +++ b/src/drivers/driver_nl80211.c
-@@ -7570,7 +7570,7 @@ static int wpa_driver_nl80211_ibss(struc
+@@ -7903,7 +7903,7 @@ static int wpa_driver_nl80211_ibss(struc
  				   struct wpa_driver_associate_params *params)
  {
  	struct nl_msg *msg;
@@ -19,7 +19,7 @@ Signed-hostap: Antonio Quartulli <ordex@autistici.org>
  	int count = 0;
  
  	wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex);
-@@ -7603,6 +7603,37 @@ retry:
+@@ -7936,6 +7936,37 @@ retry:
  	wpa_printf(MSG_DEBUG, "  * freq=%d", params->freq);
  	NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq);
  
diff --git a/package/network/services/hostapd/patches/604-wpa_s-support-htmode-param.patch b/package/network/services/hostapd/patches/502-wpa_s-support-htmode-param.patch
similarity index 92%
rename from package/network/services/hostapd/patches/604-wpa_s-support-htmode-param.patch
rename to package/network/services/hostapd/patches/502-wpa_s-support-htmode-param.patch
index 7b980926d5c3a9def95f76cc20ba2e9360bb7929..adb20a25c5589af4a47f59352ebf2482efa9e4df 100644
--- a/package/network/services/hostapd/patches/604-wpa_s-support-htmode-param.patch
+++ b/package/network/services/hostapd/patches/502-wpa_s-support-htmode-param.patch
@@ -16,7 +16,7 @@ Signed-off-by: Antonio Quartulli <ordex@autistici.org>
 
 --- a/src/drivers/driver.h
 +++ b/src/drivers/driver.h
-@@ -375,6 +375,8 @@ struct wpa_driver_associate_params {
+@@ -409,6 +409,8 @@ struct wpa_driver_associate_params {
  	int fixed_freq;
  	unsigned char rates[NL80211_MAX_SUPP_RATES];
  	int mcast_rate;
@@ -27,7 +27,7 @@ Signed-off-by: Antonio Quartulli <ordex@autistici.org>
  	 * bg_scan_period - Background scan period in seconds, 0 to disable
 --- a/src/drivers/driver_nl80211.c
 +++ b/src/drivers/driver_nl80211.c
-@@ -7634,6 +7634,22 @@ retry:
+@@ -7967,6 +7967,22 @@ retry:
  		NLA_PUT_U32(msg, NL80211_ATTR_MCAST_RATE, params->mcast_rate);
  	}
  
@@ -52,7 +52,7 @@ Signed-off-by: Antonio Quartulli <ordex@autistici.org>
  		goto nla_put_failure;
 --- a/wpa_supplicant/config.c
 +++ b/wpa_supplicant/config.c
-@@ -1406,6 +1406,71 @@ static char * wpa_config_write_mcast_rat
+@@ -1544,6 +1544,71 @@ static char * wpa_config_write_mcast_rat
  }
  #endif /* NO_CONFIG_WRITE */
  
@@ -124,7 +124,7 @@ Signed-off-by: Antonio Quartulli <ordex@autistici.org>
  static int wpa_config_parse_rates(const struct parse_data *data,
  				  struct wpa_ssid *ssid, int line,
  				  const char *value)
-@@ -1668,6 +1733,7 @@ static const struct parse_data ssid_fiel
+@@ -1810,6 +1875,7 @@ static const struct parse_data ssid_fiel
  	{ INT_RANGE(fixed_freq, 0, 1) },
  	{ FUNC(rates) },
  	{ FUNC(mcast_rate) },
@@ -134,7 +134,7 @@ Signed-off-by: Antonio Quartulli <ordex@autistici.org>
  #undef OFFSET
 --- a/wpa_supplicant/config_ssid.h
 +++ b/wpa_supplicant/config_ssid.h
-@@ -605,6 +605,8 @@ struct wpa_ssid {
+@@ -625,6 +625,8 @@ struct wpa_ssid {
  	int fixed_freq;
  	unsigned char rates[NL80211_MAX_SUPP_RATES];
  	double mcast_rate;
@@ -145,7 +145,7 @@ Signed-off-by: Antonio Quartulli <ordex@autistici.org>
  #endif /* CONFIG_SSID_H */
 --- a/wpa_supplicant/wpa_supplicant.c
 +++ b/wpa_supplicant/wpa_supplicant.c
-@@ -1610,6 +1610,8 @@ void wpa_supplicant_associate(struct wpa
+@@ -1639,6 +1639,8 @@ void wpa_supplicant_associate(struct wpa
  			i++;
  		}
  		params.mcast_rate = ssid->mcast_rate;
diff --git a/package/network/services/hostapd/patches/570-genl_connect_debug.patch b/package/network/services/hostapd/patches/570-genl_connect_debug.patch
deleted file mode 100644
index 5475cbe9eb0408dc5c347062772651b9c94af7e4..0000000000000000000000000000000000000000
--- a/package/network/services/hostapd/patches/570-genl_connect_debug.patch
+++ /dev/null
@@ -1,11 +0,0 @@
---- a/src/drivers/driver_nl80211.c
-+++ b/src/drivers/driver_nl80211.c
-@@ -121,7 +121,7 @@ static struct nl_handle * nl_create_hand
- 	}
- 
- 	if (genl_connect(handle)) {
--		wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic "
-+		wpa_printf(MSG_DEBUG, "nl80211: Failed to connect to generic "
- 			   "netlink (%s)", dbg);
- 		nl80211_handle_destroy(handle);
- 		return NULL;
diff --git a/package/network/services/hostapd/patches/700-ubus_support.patch b/package/network/services/hostapd/patches/600-ubus_support.patch
similarity index 91%
rename from package/network/services/hostapd/patches/700-ubus_support.patch
rename to package/network/services/hostapd/patches/600-ubus_support.patch
index c1759c8fb8e085d328fe00465f74dfc49a989556..04af5da7deeaa04a3715db587388163536cb3723 100644
--- a/package/network/services/hostapd/patches/700-ubus_support.patch
+++ b/package/network/services/hostapd/patches/600-ubus_support.patch
@@ -1,6 +1,6 @@
 --- a/hostapd/Makefile
 +++ b/hostapd/Makefile
-@@ -97,6 +97,11 @@ OBJS += ../src/common/wpa_common.o
+@@ -105,6 +105,11 @@ OBJS += ../src/common/wpa_common.o
  
  OBJS += ../src/eapol_auth/eapol_auth_sm.o
  
@@ -22,22 +22,23 @@
  
  struct wpa_driver_ops;
  struct wpa_ctrl_dst;
-@@ -75,6 +76,7 @@ struct hostapd_data {
+@@ -105,6 +106,7 @@ struct hostapd_data {
  	struct hostapd_iface *iface;
  	struct hostapd_config *iconf;
  	struct hostapd_bss_config *conf;
 +	struct hostapd_ubus_bss ubus;
  	int interface_added; /* virtual interface added for this BSS */
+ 	unsigned int started:1;
  
- 	u8 own_addr[ETH_ALEN];
-@@ -216,6 +218,7 @@ struct hostapd_iface {
- 	void *owner;
- 	char *config_fname;
+@@ -256,6 +258,8 @@ struct hostapd_iface {
  	struct hostapd_config *conf;
-+	struct hostapd_ubus_iface ubus;
+ 	char phy[16]; /* Name of the PHY (radio) */
  
- 	size_t num_bss;
- 	struct hostapd_data **bss;
++	struct hostapd_ubus_iface ubus;
++
+ 	enum hostapd_iface_state {
+ 		HAPD_IFACE_UNINITIALIZED,
+ 		HAPD_IFACE_DISABLED,
 --- /dev/null
 +++ b/src/ap/ubus.c
 @@ -0,0 +1,373 @@
@@ -497,15 +498,15 @@
 +#endif
 --- a/src/ap/hostapd.c
 +++ b/src/ap/hostapd.c
-@@ -241,6 +241,7 @@ static int hostapd_broadcast_wep_set(str
+@@ -262,6 +262,7 @@ static void hostapd_free_hapd_data(struc
+ 	hapd->started = 0;
  
- static void hostapd_free_hapd_data(struct hostapd_data *hapd)
- {
+ 	wpa_printf(MSG_DEBUG, "%s(%s)", __func__, hapd->conf->iface);
 +	hostapd_ubus_free_bss(hapd);
  	iapp_deinit(hapd->iapp);
  	hapd->iapp = NULL;
  	accounting_deinit(hapd);
-@@ -806,6 +807,8 @@ static int hostapd_setup_bss(struct host
+@@ -831,6 +832,8 @@ static int hostapd_setup_bss(struct host
  	if (hapd->driver && hapd->driver->set_operstate)
  		hapd->driver->set_operstate(hapd->drv_priv, 1);
  
@@ -514,31 +515,30 @@
  	return 0;
  }
  
-@@ -956,6 +959,7 @@ int hostapd_setup_interface_complete(str
+@@ -1105,6 +1108,7 @@ int hostapd_setup_interface_complete(str
  	if (err)
  		goto error;
  
 +	hostapd_ubus_add_iface(iface);
  	wpa_printf(MSG_DEBUG, "Completing interface initialization");
- 	if (hapd->iconf->channel) {
- 		iface->freq = hostapd_hw_get_freq(hapd, hapd->iconf->channel);
-@@ -1048,6 +1052,7 @@ int hostapd_setup_interface_complete(str
+ 	if (iface->conf->channel) {
+ #ifdef NEED_AP_MLME
+@@ -1213,6 +1217,7 @@ int hostapd_setup_interface_complete(str
  
  error:
  	wpa_printf(MSG_ERROR, "Interface initialization failed");
 +	hostapd_ubus_free_iface(iface);
- 	eloop_terminate();
- 	return -1;
- }
-@@ -1146,6 +1151,8 @@ void hostapd_interface_deinit_free(struc
- 	void *drv_priv;
- 	if (iface == NULL)
- 		return;
-+
-+	hostapd_ubus_free_iface(iface);
+ 	hostapd_set_state(iface, HAPD_IFACE_DISABLED);
+ 	if (iface->interfaces && iface->interfaces->terminate_on_error)
+ 		eloop_terminate();
+@@ -1534,6 +1539,7 @@ void hostapd_interface_deinit_free(struc
+ 		   (unsigned int) iface->conf->num_bss);
  	driver = iface->bss[0]->driver;
  	drv_priv = iface->bss[0]->drv_priv;
++	hostapd_ubus_free_iface(iface);
  	hostapd_interface_deinit(iface);
+ 	wpa_printf(MSG_DEBUG, "%s: driver=%p drv_priv=%p -> hapd_deinit",
+ 		   __func__, driver, drv_priv);
 --- a/src/ap/ieee802_11.c
 +++ b/src/ap/ieee802_11.c
 @@ -535,7 +535,8 @@ static void handle_auth_sae(struct hosta
@@ -562,7 +562,7 @@
 +	};
  
  	if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
- 		printf("handle_auth - too short payload (len=%lu)\n",
+ 		wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)",
 @@ -633,6 +639,14 @@ static void handle_auth(struct hostapd_d
  		resp = WLAN_STATUS_UNSPECIFIED_FAILURE;
  		goto fail;
@@ -578,7 +578,7 @@
  	if (res == HOSTAPD_ACL_PENDING) {
  		wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR
  			   " waiting for an external authentication",
-@@ -1220,13 +1234,18 @@ static void send_assoc_resp(struct hosta
+@@ -1245,13 +1259,18 @@ static void send_assoc_resp(struct hosta
  
  static void handle_assoc(struct hostapd_data *hapd,
  			 const struct ieee80211_mgmt *mgmt, size_t len,
@@ -598,7 +598,7 @@
  
  	if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) :
  				      sizeof(mgmt->u.assoc_req))) {
-@@ -1325,6 +1344,13 @@ static void handle_assoc(struct hostapd_
+@@ -1350,6 +1369,13 @@ static void handle_assoc(struct hostapd_
  		goto fail;
  	}
  
@@ -612,7 +612,7 @@
  	sta->capability = capab_info;
  	sta->listen_interval = listen_interval;
  
-@@ -1734,7 +1760,7 @@ void ieee802_11_mgmt(struct hostapd_data
+@@ -1759,7 +1785,7 @@ void ieee802_11_mgmt(struct hostapd_data
  
  
  	if (stype == WLAN_FC_STYPE_PROBE_REQ) {
@@ -621,7 +621,7 @@
  		return;
  	}
  
-@@ -1749,15 +1775,15 @@ void ieee802_11_mgmt(struct hostapd_data
+@@ -1774,15 +1800,15 @@ void ieee802_11_mgmt(struct hostapd_data
  	switch (stype) {
  	case WLAN_FC_STYPE_AUTH:
  		wpa_printf(MSG_DEBUG, "mgmt::auth");
@@ -642,7 +642,7 @@
  		wpa_printf(MSG_DEBUG, "mgmt::disassoc");
 --- a/src/ap/beacon.c
 +++ b/src/ap/beacon.c
-@@ -352,7 +352,7 @@ static enum ssid_match_result ssid_match
+@@ -398,7 +398,7 @@ static enum ssid_match_result ssid_match
  
  void handle_probe_req(struct hostapd_data *hapd,
  		      const struct ieee80211_mgmt *mgmt, size_t len,
@@ -651,7 +651,7 @@
  {
  	u8 *resp;
  	struct ieee802_11_elems elems;
-@@ -360,8 +360,14 @@ void handle_probe_req(struct hostapd_dat
+@@ -406,8 +406,14 @@ void handle_probe_req(struct hostapd_dat
  	size_t ie_len;
  	struct sta_info *sta = NULL;
  	size_t i, resp_len;
@@ -666,7 +666,7 @@
  
  	ie = mgmt->u.probe_req.variable;
  	if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.probe_req))
-@@ -500,6 +506,12 @@ void handle_probe_req(struct hostapd_dat
+@@ -546,6 +552,12 @@ void handle_probe_req(struct hostapd_dat
  	}
  #endif /* CONFIG_P2P */