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}"
26 HOOK_SETTINGS
="ADDRESS BROADCAST_SSID CHANNEL CHANNEL_BANDWIDTH DFS MODE PHY"
27 HOOK_SETTINGS
="${HOOK_SETTINGS} ENCRYPTION ENVIRONMENT KEY SSID"
28 HOOK_SETTINGS
="${HOOK_SETTINGS} MFP"
30 # Broadcast SSID by default
31 DEFAULT_BROADCAST_SSID
="on"
33 # Perform radar detection by default when possible
36 # 802.11w - Management Frame Protection
37 # Disable by default because many clients cannot connect when enabled
40 DEFAULT_ENVIRONMENT
="${WIRELESS_DEFAULT_ENVIRONMENT}"
42 hook_check_settings
() {
45 assert isset BROADCAST_SSID
46 assert isbool BROADCAST_SSID
51 assert isoneof MODE
${HOSTAPD_SUPPORTED_MODES}
56 if isset ENCRYPTION
; then
57 assert isoneof ENCRYPTION WPA WPA2 WPA
/WPA2
60 assert
[ ${#KEY} -ge 8 ]
61 assert
[ ${#KEY} -le 63 ]
64 assert wireless_environment_is_valid
"${ENVIRONMENT}"
67 hook_parse_cmdline
() {
68 while [ $# -gt 0 ]; do
71 BROADCAST_SSID
=$
(cli_get_val
"${1}")
74 CHANNEL
=$
(cli_get_val
"${1}")
76 --channel-bandwidth=*)
77 CHANNEL_BANDWIDTH
="$(cli_get_val "${1}")"
80 DFS
="$(cli_get_val "${1}")"
84 elif disabled DFS
; then
87 error
"Invalid value for DFS: ${DFS}"
92 ENCRYPTION
=$
(cli_get_val
"${1}")
95 ENVIRONMENT
="$(cli_get_val "${1}")"
97 if ! wireless_environment_is_valid
"${ENVIRONMENT}"; then
98 error
"Invalid wireless environment: ${ENVIRONMENT}"
103 KEY
=$
(cli_get_val
"${1}")
106 ADDRESS
=$
(cli_get_val
"${1}")
109 MFP
="$(cli_get_val "${1}")"
113 elif disabled MFP
; then
116 error
"Invalid value for --mfp: ${MFP}"
121 MODE
=$
(cli_get_val
"${1}")
123 if ! isoneof MODE
${HOSTAPD_SUPPORTED_MODES}; then
124 error
"Unsupported mode: ${MODE}"
125 error
"Mode must be one of ${HOSTAPD_SUPPORTED_MODES}"
130 PHY
=$
(cli_get_val
"${1}")
133 SSID
=$
(cli_get_val
"${1}")
136 warning
"Ignoring unknown argument '${1}'"
142 # Generate a random MAC address if none is set
143 if ! isset ADDRESS
; then
144 ADDRESS
="$(mac_generate)"
148 if ! isset MODE
; then
149 error
"--mode is not set"
153 # Automatically enable ACS if no channel is set and ACS is available
154 if ! isset CHANNEL
&& phy_supports_acs
"${PHY}"; then
157 log INFO
"Automatic Channel Selection (ACS) enabled"
160 # Channel bandwidth must match the mode
161 if isset CHANNEL_BANDWIDTH
&& ! wireless_channel_bandwidth_is_valid
"${MODE}" "${CHANNEL_BANDWIDTH}"; then
162 error
"Channel Bandwidth '${CHANNEL_BANDWIDTH}' is not supported for ${MODE}"
166 # Save address of phy do identify it again
167 PHY
=$
(phy_get
${PHY})
168 PHY
=$
(phy_get_address
${PHY})
175 if ! hook_default_edit
"$@"; then
179 # To apply all changes, we need to restart the port
180 port_restart
"${port}"
187 device_exists
"${port}" && exit ${EXIT_OK}
189 port_settings_read
"${port}" ${HOOK_SETTINGS}
191 # Check if the PHY is present.
192 local phy
=$
(phy_get
${PHY})
194 log DEBUG
"phy '${PHY}' is not present"
198 # Create the wireless device
199 wireless_create
"${port}" \
202 --address="${ADDRESS}"
211 # Remove the device if present
212 if device_exists
"${port}"; then
213 wireless_remove
"${port}"
223 # The port must already exist before
224 # hostapd is started. Otherwise it will
225 # fail horribly over and over again.
226 assert device_exists
"${port}"
228 hostapd_start
"${port}"
235 hostapd_stop
"${port}"
242 case "$(hotplug_action)" in
244 # Create the port when the phy is plugged in
245 if hotplug_event_port_uses_phy
"${port}"; then
246 hook_create
"${port}"
252 if hotplug_event_port_is_interface
"${port}"; then
253 hostapd_stop
"${port}"
260 exit ${EXIT_NOT_HANDLED}