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 MODE PHY SSID"
27 HOOK_SETTINGS
="${HOOK_SETTINGS} ENCRYPTION KEY"
29 ADDRESS
=$
(mac_generate
)
36 # Perform radar detection by default when possible
39 hook_check_settings
() {
42 assert isset BROADCAST_SSID
43 assert isbool BROADCAST_SSID
47 assert isoneof MODE
${HOSTAPD_SUPPORTED_MODES}
52 if isset ENCRYPTION
; then
53 assert isoneof ENCRYPTION WPA WPA2 WPA
/WPA2
56 assert
[ ${#KEY} -ge 8 ]
57 assert
[ ${#KEY} -le 63 ]
61 hook_parse_cmdline
() {
62 while [ $# -gt 0 ]; do
65 BROADCAST_SSID
=$
(cli_get_val
"${1}")
68 CHANNEL
=$
(cli_get_val
"${1}")
71 DFS
="$(cli_get_val "${1}")"
75 elif disabled DFS
; then
78 error
"Invalid value for DFS: ${DFS}"
83 ENCRYPTION
=$
(cli_get_val
"${1}")
86 KEY
=$
(cli_get_val
"${1}")
89 ADDRESS
=$
(cli_get_val
"${1}")
92 MODE
=$
(cli_get_val
"${1}")
94 if ! isoneof MODE
${HOSTAPD_SUPPORTED_MODES}; then
95 error
"Unsupported mode: ${MODE}"
96 error
"Mode must be one of ${HOSTAPD_SUPPORTED_MODES}"
101 PHY
=$
(cli_get_val
"${1}")
104 SSID
=$
(cli_get_val
"${1}")
107 warning
"Ignoring unknown argument '${1}'"
113 # Generate a random MAC address if none is set
114 if ! isset ADDRESS
; then
115 ADDRESS
="$(mac_generate)"
119 if ! isset MODE
; then
120 error
"--mode is not set"
124 # Save address of phy do identify it again
125 PHY
=$
(phy_get
${PHY})
126 PHY
=$
(phy_get_address
${PHY})
133 if ! hook_default_edit
"$@"; then
137 # To apply all changes, we need to restart the port
138 port_restart
"${port}"
145 device_exists
"${port}" && exit ${EXIT_OK}
147 port_settings_read
"${port}" ${HOOK_SETTINGS}
149 # Check if the PHY is present.
150 local phy
=$
(phy_get
${PHY})
152 log DEBUG
"phy '${PHY}' is not present"
156 # Create the wireless device
157 wireless_create
"${port}" \
160 --address="${ADDRESS}"
169 # Remove the device if present
170 if device_exists
"${port}"; then
171 wireless_remove
"${port}"
181 # The port must already exist before
182 # hostapd is started. Otherwise it will
183 # fail horribly over and over again.
184 assert device_exists
"${port}"
186 hostapd_start
"${port}"
193 hostapd_stop
"${port}"
200 case "$(hotplug_action)" in
202 # Create the port when the phy is plugged in
203 if hotplug_event_port_uses_phy
"${port}"; then
204 hook_create
"${port}"
210 if hotplug_event_port_is_interface
"${port}"; then
211 hostapd_stop
"${port}"
218 exit ${EXIT_NOT_HANDLED}