2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2017 Michael Tremer #
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. #
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. #
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/>. #
20 ###############################################################################
22 .
/usr
/lib
/network
/header-port
24 HOOK_PORT_PATTERN
="${PORT_PATTERN_MESH}"
26 HOOK_SETTINGS
="HOOK ADDRESS MESH_ID CHANNEL PHY PSK"
28 hook_check_settings
() {
36 hook_parse_cmdline
() {
37 while [ $# -gt 0 ]; do
40 ADDRESS
=$
(cli_get_val
"${1}")
43 CHANNEL
=$
(cli_get_val
"${1}")
46 MESH_ID
=$
(cli_get_val
"${1}")
49 PHY
=$
(cli_get_val
"${1}")
52 PSK
=$
(cli_get_val
"${1}")
55 warning
"Ignoring unknown argument '${1}'"
61 if ! isset MESH_ID
; then
62 error
"Please pass a mesh ID"
66 # Save address of phy do identify it again
68 PHY
=$
(phy_get_address
${PHY})
70 # Generate a MAC address if none given
71 if ! isset ADDRESS
; then
72 ADDRESS
=$
(mac_generate
)
75 # Check if channel is valid
76 if ! wireless_channel_is_valid
"${CHANNEL}"; then
77 log ERROR
"Channel is invalid: ${CHANNEL}"
87 port_settings_read
"${port}" ${HOOK_SETTINGS}
89 # Check if the PHY is present.
90 local phy
="$(phy_get "${PHY}")"
92 log DEBUG
"phy '${PHY}' is not present"
96 # Create the wireless device, if it does not exist, yet.
97 if ! device_exists
"${port}"; then
98 wireless_create
"${port}" \
99 --address="${ADDRESS}" \
100 --channel="${CHANNEL}" \
102 --type="mesh-point" ||
return $?
105 # Write WPA supplicant configuration
106 local config_file
="$(wpa_supplicant_config_dir "${port}")/wpa_supplicant.conf"
108 wpa_supplicant_config_write \
111 --channel="${CHANNEL}" \
114 --ssid="${MESH_ID}" ||
return $?
123 if device_exists
"${port}"; then
124 wireless_remove
"${port}"
133 # Start WPA supplicant
134 wpa_supplicant_start
"${port}"
140 wpa_supplicant_stop
"${port}"
147 port_settings_read
"${port}" ${HOOK_SETTINGS}
149 case "$(hotplug_action)" in
151 # Bring up the port when the phy is plugged in
152 if hotplug_event_port_uses_phy
"${port}"; then
153 hook_create
"${port}" ||
exit $?
158 exit ${EXIT_NOT_HANDLED}