]> git.ipfire.org Git - people/stevee/network.git/blobdiff - src/hooks/ports/wireless-adhoc
Split port hooks in to (create|remove|up|down) actions
[people/stevee/network.git] / src / hooks / ports / wireless-adhoc
index 515c9057e277037871ac9c384b1f676d98871319..1544473cb3d1dcadf0f55f6e7d7894bedfe04e05 100644 (file)
@@ -114,6 +114,41 @@ function hook_edit() {
        exit ${EXIT_OK}
 }
 
+function hook_create() {
+       local port="${1}"
+       assert isset port
+
+       device_exists "${port}" && exit ${EXIT_OK}
+
+       port_settings_read "${port}" ${HOOK_SETTINGS}
+
+       # Check if the PHY is present.
+       local phy="$(phy_get "${PHY}")"
+       if ! isset phy; then
+               log DEBUG "phy '${PHY}' is not present"
+               exit ${EXIT_ERROR}
+       fi
+
+       # Create the wireless device, if it does not exist, yet.
+       wireless_create "${port}" \
+               --address="${ADDRESS}" \
+               --phy="${phy}" \
+               --type="ibss"
+
+       exit ${EXIT_OK}
+}
+
+function hook_remove() {
+       local port="${1}"
+       assert isset port
+
+       if device_exists "${port}"; then
+               wireless_remove "${port}"
+       fi
+
+       exit ${EXIT_OK}
+}
+
 function hook_up() {
        local port=${1}
        assert isset port
@@ -148,9 +183,6 @@ function hook_down() {
        # Leave the ad-hoc network.
        wireless_ibss_leave "${port}"
 
-       # Remove the device if it is still present.
-       wireless_remove "${port}"
-
        exit ${EXIT_OK}
 }