]> git.ipfire.org Git - people/ms/network.git/blame - src/hooks/ports/wireless-ap
vpn-security-policies: fix +/- syntax handling for group type and integrity
[people/ms/network.git] / src / hooks / ports / wireless-ap
CommitLineData
d76f5107
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2010 Michael Tremer & Christian Schmidt #
6# #
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. #
11# #
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. #
16# #
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/>. #
19# #
20###############################################################################
21
8ee92277 22. /usr/lib/network/header-port
d76f5107 23
54bae947
MT
24HOOK_PORT_PATTERN="${PORT_PATTERN_ACCESSPOINT}"
25
31670741 26HOOK_SETTINGS="HOOK ADDRESS BROADCAST_SSID CHANNEL MODE PHY SSID"
25e32463 27HOOK_SETTINGS="${HOOK_SETTINGS} ENCRYPTION KEY"
d76f5107
MT
28
29ADDRESS=$(mac_generate)
30BROADCAST_SSID=on
31CHANNEL=1
25e32463
MT
32ENCRYPTION=""
33KEY=""
d76f5107
MT
34MODE="g"
35SSID=
36
1c6a4e30 37hook_check_settings() {
d76f5107
MT
38 assert isset ADDRESS
39 assert ismac ADDRESS
40 assert isset BROADCAST_SSID
41 assert isbool BROADCAST_SSID
42 assert isset CHANNEL
d76f5107 43 assert isset MODE
93d614f0 44 assert isoneof MODE a b g n
d76f5107
MT
45 assert isset PHY
46 assert ismac PHY
47 assert isset SSID
25e32463
MT
48
49 if isset ENCRYPTION; then
50 assert isoneof ENCRYPTION WPA WPA2 WPA/WPA2
51
52 assert isset KEY
53 assert [ ${#KEY} -ge 8 ]
54 assert [ ${#KEY} -le 63 ]
55 fi
d76f5107
MT
56}
57
270aab39 58hook_parse_cmdline() {
d76f5107
MT
59 while [ $# -gt 0 ]; do
60 case "${1}" in
61 --broadcast-ssid=*)
62 BROADCAST_SSID=$(cli_get_val ${1})
63 ;;
64 --channel=*)
65 CHANNEL=$(cli_get_val ${1})
66 ;;
25e32463
MT
67 --encryption=*)
68 ENCRYPTION=$(cli_get_val ${1})
69 ;;
70 --key=*)
71 KEY=$(cli_get_val ${1})
72 ;;
d76f5107
MT
73 --mac=*)
74 ADDRESS=$(cli_get_val ${1})
75 ;;
76 --mode=*)
77 MODE=$(cli_get_val ${1})
78 ;;
79 --phy=*)
80 PHY=$(cli_get_val ${1})
81 ;;
82 --ssid=*)
83 SSID=$(cli_get_val ${1})
84 ;;
85 *)
86 warning "Ignoring unknown argument '${1}'"
87 ;;
88 esac
89 shift
90 done
91
92 # Save address of phy do identify it again
93 PHY=$(phy_get ${PHY})
94 PHY=$(phy_get_address ${PHY})
270aab39
MT
95}
96
1c6a4e30 97hook_edit() {
d76f5107 98 local port=${1}
d76f5107
MT
99 assert isset port
100
270aab39
MT
101 if ! hook_default_edit $@; then
102 return ${EXIT_ERROR}
103 fi
d76f5107 104
270aab39
MT
105 # To apply all changes, we need to restart the port
106 port_restart "${port}"
d76f5107
MT
107}
108
1c6a4e30 109hook_create() {
1ba6a2bb 110 local port="${1}"
d76f5107
MT
111 assert isset port
112
1ba6a2bb
MT
113 device_exists "${port}" && exit ${EXIT_OK}
114
e9df08ad 115 port_settings_read "${port}" ${HOOK_SETTINGS}
d76f5107 116
49ec20d8
MT
117 # Check if the PHY is present.
118 local phy=$(phy_get ${PHY})
119 if ! isset phy; then
120 log DEBUG "phy '${PHY}' is not present"
121 exit ${EXIT_ERROR}
122 fi
123
1ba6a2bb
MT
124 # Create the wireless device
125 wireless_create "${port}" \
126 --phy="${phy}" \
127 --type="ap" \
128 --address="${ADDRESS}"
d76f5107
MT
129
130 exit ${EXIT_OK}
131}
132
1c6a4e30 133hook_remove() {
1ba6a2bb 134 local port="${1}"
d76f5107
MT
135 assert isset port
136
b8026986
MT
137 # Remove the device if present
138 if device_exists "${port}"; then
139 wireless_remove "${port}"
47859d95 140 fi
d76f5107
MT
141
142 exit ${EXIT_OK}
143}
144
1c6a4e30 145hook_up() {
1ba6a2bb
MT
146 local port="${1}"
147 assert isset port
148
149 # The port must already exist before
150 # hostapd is started. Otherwise it will
151 # fail horribly over and over again.
152 assert device_exists "${port}"
153
154 hostapd_start "${port}"
155}
156
1c6a4e30 157hook_down() {
1ba6a2bb
MT
158 local port="${1}"
159 assert isset port
160
161 hostapd_stop "${port}"
162}
163
1c6a4e30 164hook_hotplug() {
b8026986 165 local port="${1}"
47859d95 166 assert isset port
49ec20d8 167
b8026986
MT
168 case "$(hotplug_action)" in
169 add)
1ba6a2bb
MT
170 # Create the port when the phy is plugged in
171 if hotplug_event_port_uses_phy "${port}"; then
172 hook_create "${port}"
b8026986
MT
173 fi
174 ;;
175
176 remove)
177 # Stop hostapd
178 if hotplug_event_port_is_interface "${port}"; then
179 hostapd_stop "${port}"
b8026986 180
1ba6a2bb
MT
181 exit ${EXIT_OK}
182 fi
b8026986
MT
183 ;;
184 esac
47859d95 185
1ba6a2bb 186 exit ${EXIT_NOT_HANDLED}
47859d95 187}