hostapd: fix AP+STA configuration with autochannel enabled
authorFelix Fietkau <nbd@nbd.name>
Wed, 13 Sep 2023 10:36:15 +0000 (12:36 +0200)
committerFelix Fietkau <nbd@nbd.name>
Wed, 13 Sep 2023 10:36:55 +0000 (12:36 +0200)
Properly disable the interface when requested
Disable ACS when bringing it back up on the new channel

Signed-off-by: Felix Fietkau <nbd@nbd.name>
package/network/services/hostapd/src/src/ap/ucode.c

index 42c2548208df102415fa78f53da8647e16fb463a..fc8e7c5d77a61f716f578507d2d3b1c82aceedc6 100644 (file)
@@ -8,6 +8,7 @@
 #include "hw_features.h"
 #include "ap_drv_ops.h"
 #include "dfs.h"
+#include "acs.h"
 #include <libubox/uloop.h>
 
 static uc_resource_type_t *global_type, *bss_type, *iface_type;
@@ -299,6 +300,14 @@ uc_hostapd_iface_stop(uc_vm_t *vm, size_t nargs)
        struct hostapd_iface *iface = uc_fn_thisval("hostapd.iface");
        int i;
 
+#ifdef CONFIG_ACS
+       if (iface->state == HAPD_IFACE_ACS) {
+               acs_cleanup(iface);
+               iface->scan_cb = NULL;
+               hostapd_disable_iface(iface);
+       }
+#endif
+
        for (i = 0; i < iface->num_bss; i++) {
                struct hostapd_data *hapd = iface->bss[i];
 
@@ -319,6 +328,7 @@ uc_hostapd_iface_start(uc_vm_t *vm, size_t nargs)
        if (!iface)
                return NULL;
 
+       iface->freq = 0;
        if (!info)
                goto out;
 
@@ -347,13 +357,30 @@ uc_hostapd_iface_start(uc_vm_t *vm, size_t nargs)
        if (!errno)
                hostapd_set_oper_chwidth(conf, intval);
 
-out:
-       if (conf->channel)
-               iface->freq = hostapd_hw_get_freq(iface->bss[0], conf->channel);
+       intval = ucv_int64_get(ucv_object_get(info, "frequency", NULL));
+       if (!errno)
+               iface->freq = intval;
+       conf->acs = 0;
 
-       if (hostapd_is_dfs_required(iface) && !hostapd_is_dfs_chan_available(iface)) {
+out:
+       switch (iface->state) {
+       case HAPD_IFACE_DISABLED:
+               break;
+       case HAPD_IFACE_ENABLED:
+               if (!hostapd_is_dfs_required(iface) ||
+                       hostapd_is_dfs_chan_available(iface))
+                       break;
                wpa_printf(MSG_INFO, "DFS CAC required on new channel, restart interface");
+               /* fallthrough */
+       default:
                hostapd_disable_iface(iface);
+               break;
+       }
+
+       if (conf->channel && !iface->freq)
+               iface->freq = hostapd_hw_get_freq(iface->bss[0], conf->channel);
+
+       if (iface->state != HAPD_IFACE_ENABLED) {
                hostapd_enable_iface(iface);
                return ucv_boolean_new(true);
        }