]>
Commit | Line | Data |
---|---|---|
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 | |
fee7200e | 24 | HOOK_SETTINGS="HOOK ADDRESS BROADCAST_SSID CHANNEL COUNTRY_CODE MODE PHY SSID" |
25e32463 | 25 | HOOK_SETTINGS="${HOOK_SETTINGS} ENCRYPTION KEY" |
d76f5107 MT |
26 | |
27 | ADDRESS=$(mac_generate) | |
28 | BROADCAST_SSID=on | |
29 | CHANNEL=1 | |
30 | COUNTRY_CODE="US" | |
25e32463 MT |
31 | ENCRYPTION="" |
32 | KEY="" | |
d76f5107 MT |
33 | MODE="g" |
34 | SSID= | |
35 | ||
2181765d | 36 | function hook_check() { |
d76f5107 MT |
37 | assert isset ADDRESS |
38 | assert ismac ADDRESS | |
39 | assert isset BROADCAST_SSID | |
40 | assert isbool BROADCAST_SSID | |
41 | assert isset CHANNEL | |
42 | assert isset COUNTRY_CODE | |
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 | ||
2181765d | 58 | function hook_create() { |
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 | ;; | |
67 | --country-code=*) | |
68 | COUNTRY_CODE=$(cli_get_val ${1}) | |
69 | ;; | |
25e32463 MT |
70 | --encryption=*) |
71 | ENCRYPTION=$(cli_get_val ${1}) | |
72 | ;; | |
73 | --key=*) | |
74 | KEY=$(cli_get_val ${1}) | |
75 | ;; | |
d76f5107 MT |
76 | --mac=*) |
77 | ADDRESS=$(cli_get_val ${1}) | |
78 | ;; | |
79 | --mode=*) | |
80 | MODE=$(cli_get_val ${1}) | |
81 | ;; | |
82 | --phy=*) | |
83 | PHY=$(cli_get_val ${1}) | |
84 | ;; | |
85 | --ssid=*) | |
86 | SSID=$(cli_get_val ${1}) | |
87 | ;; | |
88 | *) | |
89 | warning "Ignoring unknown argument '${1}'" | |
90 | ;; | |
91 | esac | |
92 | shift | |
93 | done | |
94 | ||
95 | # Save address of phy do identify it again | |
96 | PHY=$(phy_get ${PHY}) | |
97 | PHY=$(phy_get_address ${PHY}) | |
98 | ||
8ee92277 | 99 | local port=$(port_find_free ${PORT_PATTERN_ACCESSPOINT}) |
d76f5107 MT |
100 | assert isset port |
101 | ||
102 | config_write $(port_file ${port}) ${HOOK_SETTINGS} | |
103 | ||
104 | exit ${EXIT_OK} | |
105 | } | |
106 | ||
2181765d | 107 | function hook_edit() { |
d76f5107 MT |
108 | local port=${1} |
109 | shift | |
110 | ||
111 | assert isset port | |
112 | ||
113 | config_read $(port_file ${port}) | |
114 | ||
115 | while [ $# -gt 0 ]; do | |
116 | case "${1}" in | |
117 | --broadcast-ssid=*) | |
118 | BROADCAST_SSID=$(cli_get_val ${1}) | |
119 | ;; | |
120 | --channel=*) | |
121 | CHANNEL=$(cli_get_val ${1}) | |
122 | ;; | |
123 | --country-code=*) | |
124 | COUNTRY_CODE=$(cli_get_val ${1}) | |
125 | ;; | |
25e32463 MT |
126 | --encryption=*) |
127 | ENCRYPTION=$(cli_get_val ${1}) | |
128 | ;; | |
129 | --key=*) | |
130 | KEY=$(cli_get_val ${1}) | |
131 | ;; | |
d76f5107 MT |
132 | --ssid=*) |
133 | SSID=$(cli_get_val ${1}) | |
134 | ;; | |
135 | --mode=*) | |
136 | MODE=$(cli_get_val ${1}) | |
137 | ;; | |
138 | *) | |
139 | warning "Unknown argument '${1}'" | |
140 | ;; | |
141 | esac | |
142 | shift | |
143 | done | |
144 | ||
145 | config_write $(port_file ${port}) ${HOOK_SETTINGS} | |
146 | ||
147 | exit ${EXIT_OK} | |
148 | } | |
149 | ||
2181765d | 150 | function hook_up() { |
d76f5107 | 151 | local port=${1} |
d76f5107 MT |
152 | assert isset port |
153 | ||
154 | config_read $(port_file ${port}) | |
155 | ||
49ec20d8 MT |
156 | # Check if the PHY is present. |
157 | local phy=$(phy_get ${PHY}) | |
158 | if ! isset phy; then | |
159 | log DEBUG "phy '${PHY}' is not present" | |
160 | exit ${EXIT_ERROR} | |
161 | fi | |
162 | ||
163 | # Create the wireless device, if it does not exist, yet. | |
d76f5107 | 164 | if ! device_exists ${port}; then |
49ec20d8 MT |
165 | wireless_create ${port} --phy="${phy}" --type="ap" \ |
166 | --address="${ADDRESS}" | |
d76f5107 MT |
167 | fi |
168 | ||
49ec20d8 MT |
169 | # Start the hostapd service. |
170 | hostapd_start ${port} | |
171 | local ret=$? | |
172 | ||
173 | if [ ${ret} -ne ${EXIT_OK} ]; then | |
174 | log ERROR "Could not start hostapd on port '${port}': ${ret}" | |
175 | exit ${EXIT_ERROR} | |
d76f5107 MT |
176 | fi |
177 | ||
178 | exit ${EXIT_OK} | |
179 | } | |
180 | ||
2181765d | 181 | function hook_down() { |
d76f5107 | 182 | local port=${1} |
d76f5107 MT |
183 | assert isset port |
184 | ||
47859d95 | 185 | # Stop the hostapd daemon. |
d76f5107 | 186 | hostapd_stop ${port} |
47859d95 MT |
187 | |
188 | # Remove the device if it is still present. | |
189 | if device_exists ${port}; then | |
190 | wireless_remove ${port} | |
191 | fi | |
d76f5107 MT |
192 | |
193 | exit ${EXIT_OK} | |
194 | } | |
195 | ||
2181765d | 196 | function hook_hotplug() { |
47859d95 | 197 | local port=${1} |
47859d95 | 198 | assert isset port |
49ec20d8 MT |
199 | |
200 | local phy=${2} | |
47859d95 | 201 | assert isset phy |
49ec20d8 | 202 | |
47859d95 MT |
203 | assert port_exists ${port} |
204 | ||
205 | # Read configuration of port. | |
206 | config_read $(port_file ${port}) | |
207 | ||
208 | # Get the address of the phy. | |
209 | local phy_address=$(phy_get_address ${phy}) | |
210 | ||
211 | # Check if the phy is the same we have | |
212 | # read from the configuration file. | |
213 | if [ "${PHY}" = "${phy_address}" ]; then | |
49ec20d8 MT |
214 | wireless_create ${port} --phy="${phy_address}" --type="ap" \ |
215 | --address="${ADDRESS}" | |
47859d95 MT |
216 | fi |
217 | ||
218 | exit ${EXIT_OK} | |
219 | } |