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 COUNTRY_CODE MODE PHY SSID"
25 HOOK_SETTINGS
="${HOOK_SETTINGS} ENCRYPTION KEY"
27 ADDRESS
=$
(mac_generate
)
36 function hook_check
() {
39 assert isset BROADCAST_SSID
40 assert isbool BROADCAST_SSID
42 assert isset COUNTRY_CODE
44 assert isoneof MODE a b g n
49 if isset ENCRYPTION
; then
50 assert isoneof ENCRYPTION WPA WPA2 WPA
/WPA2
53 assert
[ ${#KEY} -ge 8 ]
54 assert
[ ${#KEY} -le 63 ]
58 function hook_create
() {
59 while [ $# -gt 0 ]; do
62 BROADCAST_SSID
=$
(cli_get_val
${1})
65 CHANNEL
=$
(cli_get_val
${1})
68 COUNTRY_CODE
=$
(cli_get_val
${1})
71 ENCRYPTION
=$
(cli_get_val
${1})
74 KEY
=$
(cli_get_val
${1})
77 ADDRESS
=$
(cli_get_val
${1})
80 MODE
=$
(cli_get_val
${1})
83 PHY
=$
(cli_get_val
${1})
86 SSID
=$
(cli_get_val
${1})
89 warning
"Ignoring unknown argument '${1}'"
95 # Save address of phy do identify it again
97 PHY
=$
(phy_get_address
${PHY})
99 local port
=$
(port_find_free
${PORT_PATTERN_ACCESSPOINT})
102 config_write $
(port_file
${port}) ${HOOK_SETTINGS}
107 function hook_edit
() {
113 config_read $
(port_file
${port})
115 while [ $# -gt 0 ]; do
118 BROADCAST_SSID
=$
(cli_get_val
${1})
121 CHANNEL
=$
(cli_get_val
${1})
124 COUNTRY_CODE
=$
(cli_get_val
${1})
127 ENCRYPTION
=$
(cli_get_val
${1})
130 KEY
=$
(cli_get_val
${1})
133 SSID
=$
(cli_get_val
${1})
136 MODE
=$
(cli_get_val
${1})
139 warning
"Unknown argument '${1}'"
145 config_write $
(port_file
${port}) ${HOOK_SETTINGS}
154 config_read $
(port_file
${port})
156 # Check if the PHY is present.
157 local phy
=$
(phy_get
${PHY})
159 log DEBUG
"phy '${PHY}' is not present"
163 # Create the wireless device, if it does not exist, yet.
164 if ! device_exists
${port}; then
165 wireless_create
${port} --phy="${phy}" --type="ap" \
166 --address="${ADDRESS}"
169 # Start the hostapd service.
170 hostapd_start
${port}
173 if [ ${ret} -ne ${EXIT_OK} ]; then
174 log ERROR
"Could not start hostapd on port '${port}': ${ret}"
181 function hook_down
() {
185 # Stop the hostapd daemon.
188 # Remove the device if it is still present.
189 if device_exists
${port}; then
190 wireless_remove
${port}
196 function hook_hotplug
() {
203 assert port_exists
${port}
205 # Read configuration of port.
206 config_read $
(port_file
${port})
208 # Get the address of the phy.
209 local phy_address
=$
(phy_get_address
${phy})
211 # Check if the phy is the same we have
212 # read from the configuration file.
213 if [ "${PHY}" = "${phy_address}" ]; then
214 wireless_create
${port} --phy="${phy_address}" --type="ap" \
215 --address="${ADDRESS}"