From: Michael Tremer Date: Sat, 19 Aug 2017 09:48:22 +0000 (+0000) Subject: 802.11s: Generate config in extra function X-Git-Tag: 010~201 X-Git-Url: http://git.ipfire.org/?p=people%2Fms%2Fnetwork.git;a=commitdiff_plain;h=81bf98985e417dc96dcea4fe395112d0890beeb5 802.11s: Generate config in extra function Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index a39af22a..c963b7c8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -164,6 +164,7 @@ dist_network_SCRIPTS = \ src/functions/functions.vpn \ src/functions/functions.vpn-security-policies \ src/functions/functions.wireless \ + src/functions/functions.wireless-mesh \ src/functions/functions.wireless-networks \ src/functions/functions.wpa_supplicant \ src/functions/functions.zone \ diff --git a/src/functions/functions.wireless-mesh b/src/functions/functions.wireless-mesh new file mode 100644 index 00000000..7315c8a7 --- /dev/null +++ b/src/functions/functions.wireless-mesh @@ -0,0 +1,94 @@ +#!/bin/bash +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2017 IPFire Network Development Team # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### + +wireless_mesh_to_wpa_supplicant() { + local device="${1}" + shift + + local file="${WPA_SUPPLICANT_CONF_DIR}/${device}.conf" + + local channel + local mesh_id + local psk + + local arg + for arg in "$@"; do + case "${arg}" in + --channel=*) + channel=$(cli_get_val "${arg}") + ;; + --mesh-id=*) + mesh_id=$(cli_get_val "${arg}") + ;; + --pre-shared-key=*) + psk=$(cli_get_val "${arg}") + ;; + *) + error "Unrecognized argument: ${arg}" + return ${EXIT_ERROR} + ;; + esac + done + + if ! isset mesh_id; then + error "Mesh ID is not set" + return ${EXIT_ERROR} + fi + + if ! wireless_channel_is_valid "${channel}"; then + error "Invalid wireless channel given: ${channel}" + return ${EXIT_ERROR} + fi + + # Ensure we can write the file + make_parent_directory "${file}" + + ( + # Write a config header + wpa_supplicant_config_header + + print_indent 0 "# ${MESH_ID}" + print_indent 0 "network={" + print_indent 1 "ssid=\"${MESH_ID}\"" + print + + print_indent 1 "# Launch in 802.11s mesh mode" + print_indent 1 "mode=5" + print + + # Authentication + print_indent 1 "# Authentication" + if isset psk; then + print_indent 1 "key_mgmt=SAE" + print_indent 1 "psk=\"${psk}\"" + else + print_indent 1 "key_mgmt=NONE" + fi + print + + # Frequency + if isset channel; then + print " frequency=$(wireless_channel_to_frequency "${channel}")" + fi + + print "}" + ) > ${file} +} diff --git a/src/hooks/ports/wireless-mesh b/src/hooks/ports/wireless-mesh index 83c8b756..f1fc5416 100644 --- a/src/hooks/ports/wireless-mesh +++ b/src/hooks/ports/wireless-mesh @@ -103,11 +103,11 @@ hook_create() { fi # Write WPA supplicant configuration - wpa_supplicant_config_write "${port}" \ - --channel="${CHANNEL}" \ - --key="${PSK}" \ - --mode="802.11s" \ - --ssid="${MESH_ID}" || return $? + if ! wireless_mesh_to_wpa_supplicant "${port}" --mesh-id="${MESH_ID}" \ + --channel="${CHANNEL}" --pre-shared-key="${PSK}"; then + log ERROR "Could not generate WPA supplicant configuration" + return ${EXIT_ERROR} + fi return ${EXIT_OK} }