modules/admin-full: when toggling a wifi-iface, first bring the radio down, then...
[project/luci.git] / modules / admin-full / luasrc / controller / admin / network.lua
index 954ba12..a79d080 100644 (file)
@@ -198,9 +198,21 @@ end
 
 function wifi_delete(network)
        local ntm = require "luci.model.network".init()
-
-       ntm:del_wifinet(network)
-       ntm:save("wireless")
+       local wnet = ntm:get_wifinet(network)
+       if wnet then
+               local dev = wnet:get_device()
+               local net = wnet:get_network()
+               if dev then
+                       luci.sys.call("env -i /sbin/wifi down %q" % dev:name())
+                       ntm:del_wifinet(network)
+                       ntm:commit("wireless")
+                       if net:is_empty() then
+                               ntm:del_network(net:name())
+                               ntm:commit("network")
+                       end
+                       luci.sys.call("env -i /sbin/wifi up %q" % dev:name())
+               end
+       end
 
        luci.http.redirect(luci.dispatcher.build_url("admin/network/wireless"))
 end
@@ -215,8 +227,7 @@ function iface_status()
                local net = netm:get_network(iface)
                local device = net and net:get_interface()
                if device then
-                       local device = net:get_interface()
-                       local data   = {
+                       local data = {
                                id         = iface,
                                proto      = net:proto(),
                                uptime     = net:uptime(),
@@ -362,11 +373,13 @@ function wifi_reconnect()
        local net = netmd:get_wifinet(wnet)
        local dev = net:get_device()
        if dev and net then
+               luci.sys.call("env -i /sbin/wifi down >/dev/null 2>/dev/null")
+
                dev:set("disabled", nil)
                net:set("disabled", (mode == "wireless_shutdown") and 1 or nil)
                netmd:commit("wireless")
 
-               luci.sys.call("(env -i /sbin/wifi down; env -i /sbin/wifi up) >/dev/null 2>/dev/null")
+               luci.sys.call("env -i /sbin/wifi up >/dev/null 2>/dev/null")
                luci.http.status(200, (mode == "wireless_shutdown") and "Shutdown" or "Reconnected")
 
                return