hostapd: use new udebug ubus api to make debug rings configurable
[openwrt/staging/hauke.git] / package / network / services / hostapd / files / hostapd.uc
index 6b6e41b6f79dbbb5c29432ce8f8a232b0106bd42..b85f523b352fec118a3b8a614ae77db42db8b882 100644 (file)
@@ -26,7 +26,6 @@ function iface_remove(cfg)
        if (!cfg || !cfg.bss || !cfg.bss[0] || !cfg.bss[0].ifname)
                return;
 
-       hostapd.remove_iface(cfg.bss[0].ifname);
        for (let bss in cfg.bss)
                wdev_remove(bss.ifname);
 }
@@ -95,14 +94,14 @@ function iface_add(phy, config, phy_status)
        let config_inline = iface_gen_config(phy, config, !!phy_status);
 
        let bss = config.bss[0];
-       let ret = hostapd.add_iface(`bss_config=${bss.ifname}:${config_inline}`);
+       let ret = hostapd.add_iface(`bss_config=${phy}:${config_inline}`);
        if (ret < 0)
                return false;
 
        if (!phy_status)
                return true;
 
-       let iface = hostapd.interfaces[bss.ifname];
+       let iface = hostapd.interfaces[phy];
        if (!iface)
                return false;
 
@@ -123,10 +122,19 @@ function iface_config_macaddr_list(config)
        return macaddr_list;
 }
 
+function iface_update_supplicant_macaddr(phy, config)
+{
+       let macaddr_list = [];
+       for (let i = 0; i < length(config.bss); i++)
+               push(macaddr_list, config.bss[i].bssid);
+       ubus.call("wpa_supplicant", "phy_set_macaddr_list", { phy: phy, macaddr: macaddr_list });
+}
+
 function iface_restart(phydev, config, old_config)
 {
        let phy = phydev.name;
 
+       hostapd.remove_iface(phy);
        iface_remove(old_config);
        iface_remove(config);
 
@@ -142,6 +150,8 @@ function iface_restart(phydev, config, old_config)
                        bss.bssid = phydev.macaddr_next();
        }
 
+       iface_update_supplicant_macaddr(phy, config);
+
        let bss = config.bss[0];
        let err = wdev_create(phy, bss.ifname, { mode: "ap" });
        if (err)
@@ -215,6 +225,7 @@ function bss_remove_file_fields(config)
        for (let key in config.hash)
                new_cfg.hash[key] = config.hash[key];
        delete new_cfg.hash.wpa_psk_file;
+       delete new_cfg.hash.vlan_file;
 
        return new_cfg;
 }
@@ -266,8 +277,8 @@ function iface_reload_config(phydev, config, old_config)
        if (!old_config.bss || !old_config.bss[0])
                return false;
 
+       let iface = hostapd.interfaces[phy];
        let iface_name = old_config.bss[0].ifname;
-       let iface = hostapd.interfaces[iface_name];
        if (!iface) {
                hostapd.printf(`Could not find previous interface ${iface_name}`);
                return false;
@@ -475,11 +486,12 @@ function iface_reload_config(phydev, config, old_config)
                             bss_remove_file_fields(bss_list_cfg[i]))) {
                        hostapd.printf(`Update config data files for bss ${ifname}`);
                        if (bss.set_config(config_inline, i, true) < 0) {
-                               hostapd.printf(`Failed to update config data files for bss ${ifname}`);
+                               hostapd.printf(`Could not update config data files for bss ${ifname}`);
                                return false;
+                       } else {
+                               bss.ctrl("RELOAD_WPA_PSK");
+                               continue;
                        }
-                       bss.ctrl("RELOAD_WPA_PSK");
-                       continue;
                }
 
                bss_reload_psk(bss, config.bss[i], bss_list_cfg[i]);
@@ -487,8 +499,6 @@ function iface_reload_config(phydev, config, old_config)
                        continue;
 
                hostapd.printf(`Reload config for bss '${config.bss[0].ifname}' on phy '${phy}'`);
-               hostapd.printf(`old: ${bss_remove_file_fields(bss_list_cfg[i])}`);
-               hostapd.printf(`new: ${bss_remove_file_fields(config.bss[i])}`);
                if (bss.set_config(config_inline, i) < 0) {
                        hostapd.printf(`Failed to set config for bss ${ifname}`);
                        return false;
@@ -498,22 +508,16 @@ function iface_reload_config(phydev, config, old_config)
        return true;
 }
 
-function iface_update_supplicant_macaddr(phy, config)
-{
-       let macaddr_list = [];
-       for (let i = 0; i < length(config.bss); i++)
-               push(macaddr_list, config.bss[i].bssid);
-       ubus.call("wpa_supplicant", "phy_set_macaddr_list", { phy: phy, macaddr: macaddr_list });
-}
-
 function iface_set_config(phy, config)
 {
        let old_config = hostapd.data.config[phy];
 
        hostapd.data.config[phy] = config;
 
-       if (!config)
+       if (!config) {
+               hostapd.remove_iface(phy);
                return iface_remove(old_config);
+       }
 
        let phydev = phy_open(phy);
        if (!phydev) {
@@ -534,7 +538,6 @@ function iface_set_config(phy, config)
 
        hostapd.printf(`Restart interface for phy ${phy}`);
        let ret = iface_restart(phydev, config, old_config);
-       iface_update_supplicant_macaddr(phy, config);
 
        return ret;
 }
@@ -568,7 +571,7 @@ function iface_load_config(filename)
 
        let bss;
        let line;
-       while ((line = trim(f.read("line"))) != null) {
+       while ((line = rtrim(f.read("line"), "\n")) != null) {
                let val = split(line, "=", 2);
                if (!val[0])
                        continue;
@@ -590,7 +593,7 @@ function iface_load_config(filename)
                push(config.radio.data, line);
        }
 
-       while ((line = trim(f.read("line"))) != null) {
+       while ((line = rtrim(f.read("line"), "\n")) != null) {
                if (line == "#default_macaddr")
                        bss.default_macaddr = true;
 
@@ -667,7 +670,7 @@ let main_obj = {
                        if (!config || !config.bss || !config.bss[0] || !config.bss[0].ifname)
                                return 0;
 
-                       let iface = hostapd.interfaces[config.bss[0].ifname];
+                       let iface = hostapd.interfaces[phy];
                        if (!iface)
                                return 0;
 
@@ -781,6 +784,7 @@ let main_obj = {
 
 hostapd.data.ubus = ubus;
 hostapd.data.obj = ubus.publish("hostapd", main_obj);
+hostapd.udebug_set("hostapd", hostapd.data.ubus);
 
 function bss_event(type, name, data) {
        let ubus = hostapd.data.ubus;
@@ -795,6 +799,7 @@ return {
        shutdown: function() {
                for (let phy in hostapd.data.config)
                        iface_set_config(phy, null);
+               hostapd.udebug_set(null);
                hostapd.ubus.disconnect();
        },
        bss_add: function(name, obj) {