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_SETTINGS
="HOOK ADDRESS BROADCAST_SSID CHANNEL MODE PHY SSID"
25 HOOK_SETTINGS
="${HOOK_SETTINGS} ENCRYPTION KEY"
27 ADDRESS
=$
(mac_generate
)
35 function hook_check
() {
38 assert isset BROADCAST_SSID
39 assert isbool BROADCAST_SSID
42 assert isoneof MODE a b g n
47 if isset ENCRYPTION
; then
48 assert isoneof ENCRYPTION WPA WPA2 WPA
/WPA2
51 assert
[ ${#KEY} -ge 8 ]
52 assert
[ ${#KEY} -le 63 ]
56 function hook_create
() {
57 while [ $# -gt 0 ]; do
60 BROADCAST_SSID
=$
(cli_get_val
${1})
63 CHANNEL
=$
(cli_get_val
${1})
66 ENCRYPTION
=$
(cli_get_val
${1})
69 KEY
=$
(cli_get_val
${1})
72 ADDRESS
=$
(cli_get_val
${1})
75 MODE
=$
(cli_get_val
${1})
78 PHY
=$
(cli_get_val
${1})
81 SSID
=$
(cli_get_val
${1})
84 warning
"Ignoring unknown argument '${1}'"
90 # Save address of phy do identify it again
92 PHY
=$
(phy_get_address
${PHY})
94 local port
=$
(port_find_free
${PORT_PATTERN_ACCESSPOINT})
97 port_settings_write
"${port}" ${HOOK_SETTINGS}
102 function hook_edit
() {
108 port_settings_read
"${port}" ${HOOK_SETTINGS}
110 while [ $# -gt 0 ]; do
113 BROADCAST_SSID
=$
(cli_get_val
${1})
116 CHANNEL
=$
(cli_get_val
${1})
119 ENCRYPTION
=$
(cli_get_val
${1})
122 KEY
=$
(cli_get_val
${1})
125 SSID
=$
(cli_get_val
${1})
128 MODE
=$
(cli_get_val
${1})
131 warning
"Unknown argument '${1}'"
137 port_settings_write
"${port}" ${HOOK_SETTINGS}
146 port_settings_read
"${port}" ${HOOK_SETTINGS}
148 # Check if the PHY is present.
149 local phy
=$
(phy_get
${PHY})
151 log DEBUG
"phy '${PHY}' is not present"
155 # Create the wireless device, if it does not exist, yet.
156 if ! device_exists
${port}; then
157 wireless_create
${port} --phy="${phy}" --type="ap" \
158 --address="${ADDRESS}"
161 # Start the hostapd service.
162 #hostapd_start ${port}
165 if [ ${ret} -ne ${EXIT_OK} ]; then
166 log ERROR
"Could not start hostapd on port '${port}': ${ret}"
173 function hook_down
() {
177 # Remove the device if present
178 if device_exists
"${port}"; then
179 wireless_remove
"${port}"
185 function hook_hotplug
() {
189 case "$(hotplug_action)" in
191 # Start hostapd after the port has been brought up
192 if hotplug_event_port_is_interface
"${port}"; then
193 hostapd_start
"${port}"
195 # Bring up the port when the phy is plugged in
196 elif hotplug_event_port_uses_phy
"${port}"; then
203 if hotplug_event_port_is_interface
"${port}"; then
204 hostapd_stop
"${port}"
209 exit ${EXIT_NOT_HANDLED}