]> git.ipfire.org Git - people/ms/network.git/blame - hooks/ports/wireless-ap
Add detection for wireless devices.
[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
22. /lib/network/header-port
23
0647ed2d 24DEVICE_PATTERN="apN"
d76f5107 25
fee7200e 26HOOK_SETTINGS="HOOK ADDRESS BROADCAST_SSID CHANNEL COUNTRY_CODE MODE PHY SSID"
d76f5107
MT
27
28ADDRESS=$(mac_generate)
29BROADCAST_SSID=on
30CHANNEL=1
31COUNTRY_CODE="US"
32MODE="g"
33SSID=
34
35function _check() {
36 assert isset ADDRESS
37 assert ismac ADDRESS
38 assert isset BROADCAST_SSID
39 assert isbool BROADCAST_SSID
40 assert isset CHANNEL
41 assert isset COUNTRY_CODE
42 assert isset MODE
43 assert isoneof MODE b g
44 assert isset PHY
45 assert ismac PHY
46 assert isset SSID
47}
48
49function _create() {
50 while [ $# -gt 0 ]; do
51 case "${1}" in
52 --broadcast-ssid=*)
53 BROADCAST_SSID=$(cli_get_val ${1})
54 ;;
55 --channel=*)
56 CHANNEL=$(cli_get_val ${1})
57 ;;
58 --country-code=*)
59 COUNTRY_CODE=$(cli_get_val ${1})
60 ;;
61 --mac=*)
62 ADDRESS=$(cli_get_val ${1})
63 ;;
64 --mode=*)
65 MODE=$(cli_get_val ${1})
66 ;;
67 --phy=*)
68 PHY=$(cli_get_val ${1})
69 ;;
70 --ssid=*)
71 SSID=$(cli_get_val ${1})
72 ;;
73 *)
74 warning "Ignoring unknown argument '${1}'"
75 ;;
76 esac
77 shift
78 done
79
80 # Save address of phy do identify it again
81 PHY=$(phy_get ${PHY})
82 PHY=$(phy_get_address ${PHY})
83
84 local port=$(port_find_free ${DEVICE_PATTERN})
85 assert isset port
86
87 config_write $(port_file ${port}) ${HOOK_SETTINGS}
88
89 exit ${EXIT_OK}
90}
91
92function _edit() {
93 local port=${1}
94 shift
95
96 assert isset port
97
98 config_read $(port_file ${port})
99
100 while [ $# -gt 0 ]; do
101 case "${1}" in
102 --broadcast-ssid=*)
103 BROADCAST_SSID=$(cli_get_val ${1})
104 ;;
105 --channel=*)
106 CHANNEL=$(cli_get_val ${1})
107 ;;
108 --country-code=*)
109 COUNTRY_CODE=$(cli_get_val ${1})
110 ;;
111 --ssid=*)
112 SSID=$(cli_get_val ${1})
113 ;;
114 --mode=*)
115 MODE=$(cli_get_val ${1})
116 ;;
117 *)
118 warning "Unknown argument '${1}'"
119 ;;
120 esac
121 shift
122 done
123
124 config_write $(port_file ${port}) ${HOOK_SETTINGS}
125
126 exit ${EXIT_OK}
127}
128
129function _up() {
130 local port=${1}
131
132 assert isset port
133
134 config_read $(port_file ${port})
135
136 if ! device_exists ${port}; then
137 wireless_create ${port} ${PHY} __ap ${ADDRESS}
138 fi
139
140 if ! hostapd_is_running ${port}; then
141 hostapd_start ${port} \
142 --broadcast-ssid="${BROADCAST_SSID}" \
143 --channel="${CHANNEL}" \
144 --country-code="${COUNTRY_CODE}" \
145 --mode="${MODE}" \
146 --ssid="${SSID}"
147
148 local ret=$?
149
150 if [ ${ret} -eq ${EXIT_ERROR} ]; then
151 error_log "Could not start '${port}' because hostapd crashed previously."
152 ( _down ${port} )
153 exit ${EXIT_ERROR}
154 fi
155 fi
156
157 exit ${EXIT_OK}
158}
159
160function _down() {
161 local port=${1}
162
163 assert isset port
164
165 config_read $(port_file ${port})
166
167 if ! device_exists ${port}; then
168 exit ${EXIT_OK}
169 fi
170
171 hostapd_stop ${port}
172 wireless_remove ${port}
173
174 exit ${EXIT_OK}
175}
176
177function _status() {
178 local zone=${1}
179 local port=${2}
180
181config_read $(zone_dir ${zone})/${port}
182
183 local device=$(devicify ${DEVICE_MAC})
184
185 printf " %-10s - " "${device}"
186 if ! device_is_up ${device}; then
187 echo -ne "${COLOUR_DOWN} DOWN ${COLOUR_NORMAL}"
188 else
189 local state=$(stp_port_state ${zone} ${device})
190 local colour="COLOUR_STP_${state}"
191 printf "${!colour}%10s${COLOUR_NORMAL}" ${state}
192 fi
193
194 echo -n " - DSR: $(stp_port_designated_root ${zone} ${device})"
195 echo -n " - Cost: $(stp_port_pathcost ${zone} ${device})"
196 echo
197
198 exit ${EXIT_OK}
199}
200
201run $@