2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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_ACCESSPOINT}"
42 # Disable WPA3+2 by default
43 DEFAULT_WPA3_PERSONAL
="off"
44 DEFAULT_WPA2_PERSONAL
="off"
46 # Broadcast SSID by default
47 DEFAULT_BROADCAST_SSID
="on"
49 # Perform radar detection by default when possible
52 # 802.11w - Management Frame Protection
55 DEFAULT_ENVIRONMENT
="${WIRELESS_DEFAULT_ENVIRONMENT}"
57 hook_check_settings
() {
60 assert isset BROADCAST_SSID
61 assert isbool BROADCAST_SSID
66 assert isoneof MODE
${HOSTAPD_SUPPORTED_MODES}
71 assert wireless_environment_is_valid
"${ENVIRONMENT}"
74 hook_parse_cmdline
() {
75 while [ $# -gt 0 ]; do
78 BROADCAST_SSID
=$
(cli_get_val
"${1}")
81 CHANNEL
=$
(cli_get_val
"${1}")
83 --channel-bandwidth=*)
84 CHANNEL_BANDWIDTH
="$(cli_get_val "${1}")"
87 DFS
="$(cli_get_val "${1}")"
91 elif disabled DFS
; then
94 error
"Invalid value for DFS: ${DFS}"
99 ENVIRONMENT
="$(cli_get_val "${1}")"
101 if ! wireless_environment_is_valid
"${ENVIRONMENT}"; then
102 error
"Invalid wireless environment: ${ENVIRONMENT}"
107 ADDRESS
=$
(cli_get_val
"${1}")
110 MFP
="$(cli_get_val "${1}")"
114 elif disabled MFP
; then
117 error
"Invalid value for --mfp: ${MFP}"
122 MODE
=$
(cli_get_val
"${1}")
124 if ! isoneof MODE
${HOSTAPD_SUPPORTED_MODES}; then
125 error
"Unsupported mode: ${MODE}"
126 error
"Mode must be one of ${HOSTAPD_SUPPORTED_MODES}"
131 PHY
=$
(cli_get_val
"${1}")
134 SECRET
="$(cli_get_val "${1}")"
137 SSID
=$
(cli_get_val
"${1}")
140 WPA2_PERSONAL
="$(cli_get_bool "${1}")"
143 WPA3_PERSONAL
="$(cli_get_bool "${1}")"
146 warning
"Ignoring unknown argument '${1}'"
152 # Generate a random MAC address if none is set
153 if ! isset ADDRESS
; then
154 ADDRESS
="$(mac_generate)"
158 if ! isset MODE
; then
159 error
"--mode is not set"
163 # Automatically enable ACS if no channel is set and ACS is available
164 if ! isset CHANNEL
&& phy_supports_acs
"${PHY}"; then
167 log INFO
"Automatic Channel Selection (ACS) enabled"
170 # Channel bandwidth must match the mode
171 if isset CHANNEL_BANDWIDTH
&& ! wireless_channel_bandwidth_is_valid
"${MODE}" "${CHANNEL_BANDWIDTH}"; then
172 error
"Channel Bandwidth '${CHANNEL_BANDWIDTH}' is not supported for ${MODE}"
176 # Check if SECRET is set when WPA* is enabled
177 if ! isset SECRET
&& (enabled WPA3_PERSONAL || enabled WPA2_PERSONAL
); then
178 error
"Secret is not set when PSK authentication is enabled"
182 # Save address of phy do identify it again
183 PHY
=$
(phy_get
${PHY})
184 PHY
=$
(phy_get_address
${PHY})
191 if ! hook_default_edit
"$@"; then
195 # To apply all changes, we need to restart the port
196 port_restart
"${port}"
203 device_exists
"${port}" && exit ${EXIT_OK}
205 port_settings_read
"${port}"
207 # Check if the PHY is present.
208 local phy
=$
(phy_get
${PHY})
210 log DEBUG
"phy '${PHY}' is not present"
214 # Create the wireless device
215 wireless_create
"${port}" \
218 --address="${ADDRESS}"
227 # Remove the device if present
228 if device_exists
"${port}"; then
229 wireless_remove
"${port}"
239 # The port must already exist before
240 # hostapd is started. Otherwise it will
241 # fail horribly over and over again.
242 assert device_exists
"${port}"
244 hostapd_start
"${port}"
251 hostapd_stop
"${port}"
258 case "$(hotplug_action)" in
260 # Create the port when the phy is plugged in
261 if hotplug_event_port_uses_phy
"${port}"; then
262 hook_create
"${port}"
268 if hotplug_event_port_is_interface
"${port}"; then
269 hostapd_stop
"${port}"
276 exit ${EXIT_NOT_HANDLED}