]> git.ipfire.org Git - people/ms/network.git/blame - src/hooks/ports/wireless-ap
Move offloading code into an own file
[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
34SSID=
35
1c6a4e30 36hook_check_settings() {
d76f5107
MT
37 assert isset ADDRESS
38 assert ismac ADDRESS
39 assert isset BROADCAST_SSID
40 assert isbool BROADCAST_SSID
41 assert isset CHANNEL
d76f5107 42 assert isset MODE
6c262922 43 assert isoneof MODE ${HOSTAPD_SUPPORTED_MODES}
d76f5107
MT
44 assert isset PHY
45 assert ismac PHY
46 assert isset SSID
25e32463
MT
47
48 if isset ENCRYPTION; then
49 assert isoneof ENCRYPTION WPA WPA2 WPA/WPA2
50
51 assert isset KEY
52 assert [ ${#KEY} -ge 8 ]
53 assert [ ${#KEY} -le 63 ]
54 fi
d76f5107
MT
55}
56
270aab39 57hook_parse_cmdline() {
d76f5107
MT
58 while [ $# -gt 0 ]; do
59 case "${1}" in
60 --broadcast-ssid=*)
2212045f 61 BROADCAST_SSID=$(cli_get_val "${1}")
d76f5107
MT
62 ;;
63 --channel=*)
2212045f 64 CHANNEL=$(cli_get_val "${1}")
d76f5107 65 ;;
25e32463 66 --encryption=*)
2212045f 67 ENCRYPTION=$(cli_get_val "${1}")
25e32463
MT
68 ;;
69 --key=*)
2212045f 70 KEY=$(cli_get_val "${1}")
25e32463 71 ;;
d76f5107 72 --mac=*)
2212045f 73 ADDRESS=$(cli_get_val "${1}")
d76f5107
MT
74 ;;
75 --mode=*)
2212045f 76 MODE=$(cli_get_val "${1}")
6c262922
MT
77
78 if ! isoneof MODE ${HOSTAPD_SUPPORTED_MODES}; then
79 error "Unsupported mode: ${MODE}"
80 error "Mode must be one of ${HOSTAPD_SUPPORTED_MODES}"
81 return ${EXIT_ERROR}
82 fi
d76f5107
MT
83 ;;
84 --phy=*)
2212045f 85 PHY=$(cli_get_val "${1}")
d76f5107
MT
86 ;;
87 --ssid=*)
2212045f 88 SSID=$(cli_get_val "${1}")
d76f5107
MT
89 ;;
90 *)
91 warning "Ignoring unknown argument '${1}'"
92 ;;
93 esac
94 shift
95 done
96
6c262922
MT
97 # MODE must be set
98 if ! isset MODE; then
99 error "--mode is not set"
100 return ${EXIT_ERROR}
101 fi
102
d76f5107
MT
103 # Save address of phy do identify it again
104 PHY=$(phy_get ${PHY})
105 PHY=$(phy_get_address ${PHY})
270aab39
MT
106}
107
1c6a4e30 108hook_edit() {
d76f5107 109 local port=${1}
d76f5107
MT
110 assert isset port
111
2212045f 112 if ! hook_default_edit "$@"; then
270aab39
MT
113 return ${EXIT_ERROR}
114 fi
d76f5107 115
270aab39
MT
116 # To apply all changes, we need to restart the port
117 port_restart "${port}"
d76f5107
MT
118}
119
1c6a4e30 120hook_create() {
1ba6a2bb 121 local port="${1}"
d76f5107
MT
122 assert isset port
123
1ba6a2bb
MT
124 device_exists "${port}" && exit ${EXIT_OK}
125
e9df08ad 126 port_settings_read "${port}" ${HOOK_SETTINGS}
d76f5107 127
49ec20d8
MT
128 # Check if the PHY is present.
129 local phy=$(phy_get ${PHY})
130 if ! isset phy; then
131 log DEBUG "phy '${PHY}' is not present"
132 exit ${EXIT_ERROR}
133 fi
134
1ba6a2bb
MT
135 # Create the wireless device
136 wireless_create "${port}" \
137 --phy="${phy}" \
138 --type="ap" \
139 --address="${ADDRESS}"
d76f5107
MT
140
141 exit ${EXIT_OK}
142}
143
1c6a4e30 144hook_remove() {
1ba6a2bb 145 local port="${1}"
d76f5107
MT
146 assert isset port
147
b8026986
MT
148 # Remove the device if present
149 if device_exists "${port}"; then
150 wireless_remove "${port}"
47859d95 151 fi
d76f5107
MT
152
153 exit ${EXIT_OK}
154}
155
1c6a4e30 156hook_up() {
1ba6a2bb
MT
157 local port="${1}"
158 assert isset port
159
160 # The port must already exist before
161 # hostapd is started. Otherwise it will
162 # fail horribly over and over again.
163 assert device_exists "${port}"
164
165 hostapd_start "${port}"
166}
167
1c6a4e30 168hook_down() {
1ba6a2bb
MT
169 local port="${1}"
170 assert isset port
171
172 hostapd_stop "${port}"
173}
174
1c6a4e30 175hook_hotplug() {
b8026986 176 local port="${1}"
47859d95 177 assert isset port
49ec20d8 178
b8026986
MT
179 case "$(hotplug_action)" in
180 add)
1ba6a2bb
MT
181 # Create the port when the phy is plugged in
182 if hotplug_event_port_uses_phy "${port}"; then
183 hook_create "${port}"
b8026986
MT
184 fi
185 ;;
186
187 remove)
188 # Stop hostapd
189 if hotplug_event_port_is_interface "${port}"; then
190 hostapd_stop "${port}"
b8026986 191
1ba6a2bb
MT
192 exit ${EXIT_OK}
193 fi
b8026986
MT
194 ;;
195 esac
47859d95 196
1ba6a2bb 197 exit ${EXIT_NOT_HANDLED}
47859d95 198}