]> git.ipfire.org Git - people/ms/network.git/blob - src/functions/functions.wireless-mesh
802.11s: Generate config in extra function
[people/ms/network.git] / src / functions / functions.wireless-mesh
1 #!/bin/bash
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2017 IPFire Network Development Team #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 wireless_mesh_to_wpa_supplicant() {
23 local device="${1}"
24 shift
25
26 local file="${WPA_SUPPLICANT_CONF_DIR}/${device}.conf"
27
28 local channel
29 local mesh_id
30 local psk
31
32 local arg
33 for arg in "$@"; do
34 case "${arg}" in
35 --channel=*)
36 channel=$(cli_get_val "${arg}")
37 ;;
38 --mesh-id=*)
39 mesh_id=$(cli_get_val "${arg}")
40 ;;
41 --pre-shared-key=*)
42 psk=$(cli_get_val "${arg}")
43 ;;
44 *)
45 error "Unrecognized argument: ${arg}"
46 return ${EXIT_ERROR}
47 ;;
48 esac
49 done
50
51 if ! isset mesh_id; then
52 error "Mesh ID is not set"
53 return ${EXIT_ERROR}
54 fi
55
56 if ! wireless_channel_is_valid "${channel}"; then
57 error "Invalid wireless channel given: ${channel}"
58 return ${EXIT_ERROR}
59 fi
60
61 # Ensure we can write the file
62 make_parent_directory "${file}"
63
64 (
65 # Write a config header
66 wpa_supplicant_config_header
67
68 print_indent 0 "# ${MESH_ID}"
69 print_indent 0 "network={"
70 print_indent 1 "ssid=\"${MESH_ID}\""
71 print
72
73 print_indent 1 "# Launch in 802.11s mesh mode"
74 print_indent 1 "mode=5"
75 print
76
77 # Authentication
78 print_indent 1 "# Authentication"
79 if isset psk; then
80 print_indent 1 "key_mgmt=SAE"
81 print_indent 1 "psk=\"${psk}\""
82 else
83 print_indent 1 "key_mgmt=NONE"
84 fi
85 print
86
87 # Frequency
88 if isset channel; then
89 print " frequency=$(wireless_channel_to_frequency "${channel}")"
90 fi
91
92 print "}"
93 ) > ${file}
94 }