]> git.ipfire.org Git - people/ms/network.git/commitdiff
wireless: Drop old network configuration from hook and use new one
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Aug 2017 17:22:46 +0000 (19:22 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 18 Aug 2017 17:22:46 +0000 (19:22 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.wireless-networks
src/hooks/zones/wireless

index 2afb4def5304bba2deef93bf757a621b565ab5db..66e906c63af46b7cc67aa90b2528f7f8a3f47971 100644 (file)
@@ -333,6 +333,29 @@ wireless_network_priority() {
        fi
 }
 
+wireless_networks_write_wpa_supplicant_configuration() {
+       local device="${1}"
+
+       local file="${WPA_SUPPLICANT_CONF_DIR}/${device}.conf"
+
+       # Ensure we can write the file
+       make_parent_directory "${file}"
+
+       local country="$(wireless_get_reg_domain)"
+
+       (
+               config_header "WPA supplicant configuration file"
+
+               # Honour country
+               if isset country; then
+                       print "country=${country}"
+                       print
+               fi
+
+               wireless_networks_to_wpa_supplicant
+       ) > ${file}
+}
+
 wireless_networks_to_wpa_supplicant() {
        local handle
        for handle in $(wireless_network_list); do
index 593b37c45166c757af871bdbe0b494727d035ad8..f75e4b2489e1b24e59495f1a5ba74ca8506eb6e7 100644 (file)
 
 . /usr/lib/network/header-zone
 
-HOOK_SETTINGS="HOOK PHY MAC SSID KEY ENCRYPTION_MODE"
-
-# Default values
-ADDRESS=$(mac_generate)
-PHY=
-SSID=
-KEY=
-ENCRYPTION_MODE=
+HOOK_SETTINGS="HOOK ADDRESS PHY"
 
 hook_check_settings() {
-       assert isset SSID
-
-       if isset ADDRESS; then
-               assert ismac ADDRESS
-       fi
-
+       assert ismac ADDRESS
        assert ismac PHY
-
-       if [ -n "${ENCRYPTION_MODE}" ]; then
-               assert isset KEY
-       fi
 }
 
 hook_parse_cmdline() {
        while [ $# -gt 0 ]; do
                case "${1}" in
-                       --phy=*|--parent-device=*)
-                               PHY=$(cli_get_val "${1}")
-                               ;;
-                       --encryption-mode=*)
-                               ENCRYPTION_MODE=$(cli_get_val "${1}")
-                               ;;
                        --address=*)
                                ADDRESS=$(cli_get_val "${1}")
                                ;;
-                       --ssid=*)
-                               SSID=$(cli_get_val "${1}")
-                               ;;
-                       --key=*)
-                               KEY=$(cli_get_val "${1}")
+                       --phy=*)
+                               PHY=$(cli_get_val "${1}")
                                ;;
                        *)
                                warning "Unrecognized option: ${1}"
@@ -72,6 +47,11 @@ hook_parse_cmdline() {
        # Just save the MAC address of the phy.
        PHY=$(phy_get ${PHY})
        PHY=$(phy_get_address ${PHY})
+
+       # Generate a random MAC address if none given
+       if ! isset ADDRESS; then
+               ADDRESS="$(mac_generate)"
+       fi
 }
 
 hook_up() {
@@ -81,27 +61,27 @@ hook_up() {
        # Read zone configuration.
        zone_settings_read "${zone}"
 
-       if ! device_exists ${zone}; then
-               #  Create the wireless interface.
-               wireless_create ${zone} \
+       #  Create the wireless interface
+       if ! device_exists "${zone}"; then
+               wireless_create "${zone}" \
                        --phy=${PHY} \
                        --type="managed" \
                        --address="${ADDRESS}" \
-               || exit $?
+               || return $?
        fi
 
        # Write WPA supplicant configuration
-       wpa_supplicant_config_write "${zone}" \
-               --mode="${ENCRYPTION_MODE}" \
-               --ssid="${SSID}" \
-               --key="${KEY}" || return $?
+       if ! wireless_networks_write_wpa_supplicant_configuration "${zone}"; then
+               log ERROR "Could not write WPA supplicant configuration for ${zone}"
+               return ${EXIT_ERROR}
+       fi
 
        # Start the WPA supplicant daemon.
        wpa_supplicant_start ${zone}
 
        zone_configs_up ${zone}
 
-       exit ${EXIT_OK}
+       return ${EXIT_OK}
 }
 
 hook_down() {