hostapd: improve channel switch support
[openwrt/staging/mkresin.git] / package / network / services / hostapd / src / src / ap / ubus.c
index 8546d2ce6991cb6b9cd0b7cb36b790d2b45f1c41..bfa44e291539b5f9395062024fdca2744bd8d587 100644 (file)
@@ -658,6 +658,10 @@ hostapd_config_add(struct ubus_context *ctx, struct ubus_object *obj,
        if (hostapd_add_iface(interfaces, buf))
                return UBUS_STATUS_INVALID_ARGUMENT;
 
+       blob_buf_init(&b, 0);
+       blobmsg_add_u32(&b, "pid", getpid());
+       ubus_send_reply(ctx, req, b.head);
+
        return UBUS_STATUS_OK;
 }
 
@@ -724,6 +728,8 @@ hostapd_switch_chan(struct ubus_context *ctx, struct ubus_object *obj,
        struct blob_attr *tb[__CSA_MAX];
        struct hostapd_data *hapd = get_hapd_from_object(obj);
        struct csa_settings css;
+       int ret = UBUS_STATUS_OK;
+       int i;
 
        blobmsg_parse(csa_policy, __CSA_MAX, tb, blob_data(msg), blob_len(msg));
 
@@ -748,10 +754,14 @@ hostapd_switch_chan(struct ubus_context *ctx, struct ubus_object *obj,
        SET_CSA_SETTING(CSA_VHT, freq_params.vht_enabled, bool);
        SET_CSA_SETTING(CSA_BLOCK_TX, block_tx, bool);
 
+       for (i = 0; i < hapd->iface->num_bss; i++) {
+               struct hostapd_data *bss = hapd->iface->bss[i];
 
-       if (hostapd_switch_channel(hapd, &css) != 0)
-               return UBUS_STATUS_NOT_SUPPORTED;
-       return UBUS_STATUS_OK;
+               if (hostapd_switch_channel(bss, &css) != 0)
+                       ret = UBUS_STATUS_NOT_SUPPORTED;
+       }
+
+       return ret;
 #undef SET_CSA_SETTING
 }
 #endif
@@ -1360,6 +1370,43 @@ void hostapd_ubus_free_bss(struct hostapd_data *hapd)
        free(name);
 }
 
+static void
+hostapd_ubus_vlan_action(struct hostapd_data *hapd, struct hostapd_vlan *vlan,
+                        const char *action)
+{
+       struct vlan_description *desc = &vlan->vlan_desc;
+       void *c;
+       int i;
+
+       if (!hapd->ubus.obj.has_subscribers)
+               return;
+
+       blob_buf_init(&b, 0);
+       blobmsg_add_string(&b, "ifname", vlan->ifname);
+       blobmsg_add_string(&b, "bridge", vlan->bridge);
+       blobmsg_add_u32(&b, "vlan_id", vlan->vlan_id);
+
+       if (desc->notempty) {
+               blobmsg_add_u32(&b, "untagged", desc->untagged);
+               c = blobmsg_open_array(&b, "tagged");
+               for (i = 0; i < ARRAY_SIZE(desc->tagged) && desc->tagged[i]; i++)
+                       blobmsg_add_u32(&b, "", desc->tagged[i]);
+               blobmsg_close_array(&b, c);
+       }
+
+       ubus_notify(ctx, &hapd->ubus.obj, action, b.head, -1);
+}
+
+void hostapd_ubus_add_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan)
+{
+       hostapd_ubus_vlan_action(hapd, vlan, "vlan_add");
+}
+
+void hostapd_ubus_remove_vlan(struct hostapd_data *hapd, struct hostapd_vlan *vlan)
+{
+       hostapd_ubus_vlan_action(hapd, vlan, "vlan_remove");
+}
+
 static const struct ubus_method daemon_methods[] = {
        UBUS_METHOD("config_add", hostapd_config_add, config_add_policy),
        UBUS_METHOD("config_remove", hostapd_config_remove, config_remove_policy),