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}"
34 hook_check_settings
() {
42 hook_parse_cmdline
() {
43 while [ $# -gt 0 ]; do
46 ADDRESS
=$
(cli_get_val
"${1}")
49 CHANNEL
=$
(cli_get_val
"${1}")
52 MESH_ID
=$
(cli_get_val
"${1}")
55 PHY
=$
(cli_get_val
"${1}")
58 PSK
=$
(cli_get_val
"${1}")
61 warning
"Ignoring unknown argument '${1}'"
67 if ! isset MESH_ID
; then
68 error
"Please pass a mesh ID"
72 # Save address of phy do identify it again
74 PHY
=$
(phy_get_address
${PHY})
76 # Generate a MAC address if none given
77 if ! isset ADDRESS
; then
78 ADDRESS
=$
(mac_generate
)
81 # Check if channel is valid
82 if ! wireless_channel_is_valid
"${CHANNEL}"; then
83 log ERROR
"Channel is invalid: ${CHANNEL}"
93 port_settings_read
"${port}" ${HOOK_SETTINGS[*]}
95 # Check if the PHY is present.
96 local phy
="$(phy_get "${PHY}")"
98 log DEBUG
"phy '${PHY}' is not present"
102 # Create the wireless device, if it does not exist, yet.
103 if ! device_exists
"${port}"; then
104 wireless_create
"${port}" \
105 --address="${ADDRESS}" \
106 --channel="${CHANNEL}" \
108 --type="mesh-point" ||
return $?
111 # Write WPA supplicant configuration
112 if ! wireless_mesh_to_wpa_supplicant
"${port}" --mesh-id="${MESH_ID}" \
113 --channel="${CHANNEL}" --pre-shared-key="${PSK}"; then
114 log ERROR
"Could not generate WPA supplicant configuration"
125 # Remove WPA supplicant configuration
126 wpa_supplicant_config_destroy
"${port}"
128 if device_exists
"${port}"; then
129 wireless_remove
"${port}"
138 # Start WPA supplicant
139 wpa_supplicant_start
"${port}"
145 wpa_supplicant_stop
"${port}"
152 port_settings_read
"${port}" ${HOOK_SETTINGS[*]}
154 case "$(hotplug_action)" in
156 # Bring up the port when the phy is plugged in
157 if hotplug_event_port_uses_phy
"${port}"; then
158 hook_create
"${port}" ||
exit $?
163 exit ${EXIT_NOT_HANDLED}