Initial support for encrypted wireless networks.
[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
22. /lib/network/header-zone
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
89 event_interface_up ${zone}
90
91 exit ${EXIT_OK}
92}
93
94function _down() {
95 local zone=${1}
96 shift
97
98 if ! device_is_up ${zone}; then
99 warning "Zone '${zone}' is not up"
100 exit ${EXIT_OK}
101 fi
102
103 event_interface_down ${zone}
104
105 zone_configs_down ${zone}
106
107 wpa_supplicant_stop ${zone}
108
109 #device_set_down ${zone}
110
111 wireless_remove ${zone}
112
113 exit ${EXIT_OK}
114}
115
116function _status() {
117 local zone=${1}
118
119 cli_status_headline ${zone}
120
121 # Exit if zone is down
122 if ! zone_is_up ${zone}; then
123 echo # Empty line
124 exit ${EXIT_ERROR}
125 fi
126
127 # XXX Add bridge stp priority here
128 # brctl does not give any information about that
129
130 cli_headline " Spanning Tree Protocol information:"
131 printf "${DEVICE_PRINT_LINE1}" "ID:" $(stp_bridge_get_id ${zone})
132 printf "${DEVICE_PRINT_LINE1}" "Priority:" $(stp_bridge_get_priority ${zone})
133
134 if stp_bridge_is_root ${zone}; then
135 echo -e " ${COLOUR_BOLD}This bridge is root.${COLOUR_NORMAL}"
136 else
137 printf "${DEVICE_PRINT_LINE1}" "Designated root:" $(stp_bridge_get_designated_root ${zone})
138 printf "${DEVICE_PRINT_LINE1}" "Root path cost:" $(stp_bridge_get_root_path_cost ${zone})
139 fi
140 echo # Empty line
141
142 # Topology information
143 printf "${DEVICE_PRINT_LINE1}" "Topology changing:" $(stp_bridge_get_topology_change_detected ${zone})
144 printf "${DEVICE_PRINT_LINE1}" "Topology change time:" $(beautify_time $(stp_bridge_get_topology_change_timer ${zone}))
145 printf "${DEVICE_PRINT_LINE1}" "Topology change count:" $(stp_bridge_get_topology_change_count ${zone})
146
147 cli_headline " Ports:"
148 zone_ports_status ${zone}
149
150 cli_headline " Configurations:"
151 zone_configs_cmd status ${zone}
152
153 echo # Empty line
154 exit ${EXIT_OK}
155}
156
157run $@