Don't strip "" from strings that contain spaces.
[people/stevee/network.git] / hooks / zones / wireless
CommitLineData
f6ee6bb1
AF
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
f41fa3d7 22. /usr/lib/network/header-zone
f6ee6bb1
AF
23
24HOOK_SETTINGS="HOOK PHY MAC MTU SSID KEY ENCRYPTION"
25
26# Default values
27MAC=$(mac_generate)
28PHY=
29MTU=1500
30SSID=
31KEY=
32ENCRYPTION="WPA-PSK"
33
34function _check() {
35 assert isset SSID
36 assert ismac MAC
37 assert isinteger MTU
38 assert ismac PHY
39
40 if [ -n "${ENCRYPTION}" ]; then
41 assert isset KEY
42 fi
43}
44
45function _parse_cmdline() {
46 while [ $# -gt 0 ]; do
47 case "${1}" in
48 --phy=*)
49 PHY=${1#--phy=}
50 ;;
51 --ssid=*)
52 SSID=${1#--ssid=}
53 ;;
54 --key=*)
55 KEY=${1#--key=}
56 ;;
57 *)
58 warning "Ignoring unknown option '${1}'"
59 ;;
60 esac
61 shift
62 done
63
64 PHY=$(phy_get ${PHY})
65 PHY=$(phy_get_address ${PHY})
66}
67
68function _up() {
69 local zone=${1}
70 shift
71
72 assert isset zone
73
74 zone_config_read ${zone}
75
76 wireless_create ${zone} ${PHY} managed ${MAC}
77
78 [ -n "${MAC}" ] && device_set_address ${zone} ${MAC}
79 [ -n "${MTU}" ] && device_set_mtu ${zone} ${MTU}
80
81 # Create WPA supplicant configuration.
82 wpa_supplicant_start ${zone} --ssid=${SSID} \
83 --encryption=${ENCRYPTION} --key=${KEY}
84
85 #device_set_up ${zone}
86
87 zone_configs_up ${zone}
88
f6ee6bb1
AF
89 exit ${EXIT_OK}
90}
91
92function _down() {
93 local zone=${1}
94 shift
95
96 if ! device_is_up ${zone}; then
97 warning "Zone '${zone}' is not up"
98 exit ${EXIT_OK}
99 fi
100
f6ee6bb1
AF
101 zone_configs_down ${zone}
102
103 wpa_supplicant_stop ${zone}
104
105 #device_set_down ${zone}
106
107 wireless_remove ${zone}
108
109 exit ${EXIT_OK}
110}
111
112function _status() {
113 local zone=${1}
3cb2fc42 114 assert isset zone
f6ee6bb1 115
3cb2fc42 116 cli_device_headline ${zone}
f6ee6bb1
AF
117
118 # Exit if zone is down
119 if ! zone_is_up ${zone}; then
120 echo # Empty line
121 exit ${EXIT_ERROR}
122 fi
123
124 # XXX Add bridge stp priority here
125 # brctl does not give any information about that
126
127 cli_headline " Spanning Tree Protocol information:"
128 printf "${DEVICE_PRINT_LINE1}" "ID:" $(stp_bridge_get_id ${zone})
129 printf "${DEVICE_PRINT_LINE1}" "Priority:" $(stp_bridge_get_priority ${zone})
130
131 if stp_bridge_is_root ${zone}; then
fcbf6823 132 echo -e " ${CLR_BLACK_B}This bridge is root.${CLR_RESET}"
f6ee6bb1
AF
133 else
134 printf "${DEVICE_PRINT_LINE1}" "Designated root:" $(stp_bridge_get_designated_root ${zone})
135 printf "${DEVICE_PRINT_LINE1}" "Root path cost:" $(stp_bridge_get_root_path_cost ${zone})
136 fi
137 echo # Empty line
138
139 # Topology information
140 printf "${DEVICE_PRINT_LINE1}" "Topology changing:" $(stp_bridge_get_topology_change_detected ${zone})
141 printf "${DEVICE_PRINT_LINE1}" "Topology change time:" $(beautify_time $(stp_bridge_get_topology_change_timer ${zone}))
142 printf "${DEVICE_PRINT_LINE1}" "Topology change count:" $(stp_bridge_get_topology_change_count ${zone})
143
144 cli_headline " Ports:"
145 zone_ports_status ${zone}
146
147 cli_headline " Configurations:"
148 zone_configs_cmd status ${zone}
149
150 echo # Empty line
151 exit ${EXIT_OK}
152}