]> git.ipfire.org Git - people/ms/network.git/blame - hooks/ports/wireless-ap
route: Create a log message, when (re)loading static routes.
[people/ms/network.git] / 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
fee7200e 24HOOK_SETTINGS="HOOK ADDRESS BROADCAST_SSID CHANNEL COUNTRY_CODE MODE PHY SSID"
d76f5107
MT
25
26ADDRESS=$(mac_generate)
27BROADCAST_SSID=on
28CHANNEL=1
29COUNTRY_CODE="US"
30MODE="g"
31SSID=
32
33function _check() {
34 assert isset ADDRESS
35 assert ismac ADDRESS
36 assert isset BROADCAST_SSID
37 assert isbool BROADCAST_SSID
38 assert isset CHANNEL
39 assert isset COUNTRY_CODE
40 assert isset MODE
41 assert isoneof MODE b g
42 assert isset PHY
43 assert ismac PHY
44 assert isset SSID
45}
46
47function _create() {
48 while [ $# -gt 0 ]; do
49 case "${1}" in
50 --broadcast-ssid=*)
51 BROADCAST_SSID=$(cli_get_val ${1})
52 ;;
53 --channel=*)
54 CHANNEL=$(cli_get_val ${1})
55 ;;
56 --country-code=*)
57 COUNTRY_CODE=$(cli_get_val ${1})
58 ;;
59 --mac=*)
60 ADDRESS=$(cli_get_val ${1})
61 ;;
62 --mode=*)
63 MODE=$(cli_get_val ${1})
64 ;;
65 --phy=*)
66 PHY=$(cli_get_val ${1})
67 ;;
68 --ssid=*)
69 SSID=$(cli_get_val ${1})
70 ;;
71 *)
72 warning "Ignoring unknown argument '${1}'"
73 ;;
74 esac
75 shift
76 done
77
78 # Save address of phy do identify it again
79 PHY=$(phy_get ${PHY})
80 PHY=$(phy_get_address ${PHY})
81
8ee92277 82 local port=$(port_find_free ${PORT_PATTERN_ACCESSPOINT})
d76f5107
MT
83 assert isset port
84
85 config_write $(port_file ${port}) ${HOOK_SETTINGS}
86
87 exit ${EXIT_OK}
88}
89
90function _edit() {
91 local port=${1}
92 shift
93
94 assert isset port
95
96 config_read $(port_file ${port})
97
98 while [ $# -gt 0 ]; do
99 case "${1}" in
100 --broadcast-ssid=*)
101 BROADCAST_SSID=$(cli_get_val ${1})
102 ;;
103 --channel=*)
104 CHANNEL=$(cli_get_val ${1})
105 ;;
106 --country-code=*)
107 COUNTRY_CODE=$(cli_get_val ${1})
108 ;;
109 --ssid=*)
110 SSID=$(cli_get_val ${1})
111 ;;
112 --mode=*)
113 MODE=$(cli_get_val ${1})
114 ;;
115 *)
116 warning "Unknown argument '${1}'"
117 ;;
118 esac
119 shift
120 done
121
122 config_write $(port_file ${port}) ${HOOK_SETTINGS}
123
124 exit ${EXIT_OK}
125}
126
127function _up() {
128 local port=${1}
129
130 assert isset port
131
132 config_read $(port_file ${port})
133
134 if ! device_exists ${port}; then
135 wireless_create ${port} ${PHY} __ap ${ADDRESS}
136 fi
137
138 if ! hostapd_is_running ${port}; then
139 hostapd_start ${port} \
140 --broadcast-ssid="${BROADCAST_SSID}" \
141 --channel="${CHANNEL}" \
142 --country-code="${COUNTRY_CODE}" \
143 --mode="${MODE}" \
144 --ssid="${SSID}"
145
146 local ret=$?
147
148 if [ ${ret} -eq ${EXIT_ERROR} ]; then
149 error_log "Could not start '${port}' because hostapd crashed previously."
150 ( _down ${port} )
151 exit ${EXIT_ERROR}
152 fi
153 fi
154
155 exit ${EXIT_OK}
156}
157
158function _down() {
159 local port=${1}
d76f5107
MT
160 assert isset port
161
162 config_read $(port_file ${port})
163
47859d95 164 # Stop the hostapd daemon.
d76f5107 165 hostapd_stop ${port}
47859d95
MT
166
167 # Remove the device if it is still present.
168 if device_exists ${port}; then
169 wireless_remove ${port}
170 fi
d76f5107
MT
171
172 exit ${EXIT_OK}
173}
174
47859d95
MT
175function _hotplug() {
176 local port=${1}
177 local phy=${2}
178
179 assert isset port
180 assert isset phy
181 assert port_exists ${port}
182
183 # Read configuration of port.
184 config_read $(port_file ${port})
185
186 # Get the address of the phy.
187 local phy_address=$(phy_get_address ${phy})
188
189 # Check if the phy is the same we have
190 # read from the configuration file.
191 if [ "${PHY}" = "${phy_address}" ]; then
192 wireless_create ${port} ${PHY} __ap ${ADDRESS}
193 fi
194
195 exit ${EXIT_OK}
196}