dhcp: Add support for DHCPv6 over Ethernet
[people/stevee/network.git] / src / 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
22a61046 27ADDRESS=$(mac_generate)
f6ee6bb1
AF
28PHY=
29MTU=1500
30SSID=
31KEY=
22a61046 32ENCRYPTION_MODE=
f6ee6bb1 33
1e6f187e 34function hook_check_settings() {
f6ee6bb1 35 assert isset SSID
22a61046
MT
36
37 if isset ADDRESS; then
38 assert ismac ADDRESS
39 fi
40
f6ee6bb1
AF
41 assert isinteger MTU
42 assert ismac PHY
43
22a61046 44 if [ -n "${ENCRYPTION_MODE}" ]; then
f6ee6bb1
AF
45 assert isset KEY
46 fi
47}
48
2181765d 49function hook_parse_cmdline() {
f6ee6bb1
AF
50 while [ $# -gt 0 ]; do
51 case "${1}" in
22a61046
MT
52 --phy=*|--parent-device=*)
53 PHY=$(cli_get_val ${1})
54 ;;
55 --encryption-mode=*)
56 ENCRYPTION_MODE=$(cli_get_val ${1})
57 ;;
58 --address=*)
59 ADDRESS=$(cli_get_val ${1})
f6ee6bb1
AF
60 ;;
61 --ssid=*)
22a61046 62 SSID=$(cli_get_val ${1})
f6ee6bb1
AF
63 ;;
64 --key=*)
22a61046 65 KEY=$(cli_get_val ${1})
f6ee6bb1
AF
66 ;;
67 *)
22a61046 68 warning "Unrecognized option: ${1}"
f6ee6bb1
AF
69 ;;
70 esac
71 shift
72 done
73
22a61046 74 # Just save the MAC address of the phy.
f6ee6bb1
AF
75 PHY=$(phy_get ${PHY})
76 PHY=$(phy_get_address ${PHY})
77}
78
2181765d 79function hook_up() {
f6ee6bb1 80 local zone=${1}
f6ee6bb1
AF
81 assert isset zone
82
22a61046 83 # Read zone configuration.
1e6f187e 84 zone_settings_read "${zone}"
f6ee6bb1 85
22a61046
MT
86 if ! device_exists ${zone}; then
87 # Create the wireless interface.
88 wireless_create ${zone} \
89 --phy=${PHY} \
90 --type="managed" \
91 --address="${ADDRESS}" \
92 || exit $?
93 fi
f6ee6bb1 94
22a61046
MT
95 # Start the WPA supplicant daemon.
96 wpa_supplicant_start ${zone}
f6ee6bb1
AF
97
98 zone_configs_up ${zone}
99
f6ee6bb1
AF
100 exit ${EXIT_OK}
101}
102
2181765d 103function hook_down() {
f6ee6bb1
AF
104 local zone=${1}
105 shift
106
107 if ! device_is_up ${zone}; then
108 warning "Zone '${zone}' is not up"
109 exit ${EXIT_OK}
110 fi
111
f6ee6bb1
AF
112 zone_configs_down ${zone}
113
114 wpa_supplicant_stop ${zone}
115
f6ee6bb1
AF
116 wireless_remove ${zone}
117
118 exit ${EXIT_OK}
119}
120
2181765d 121function hook_status() {
f6ee6bb1 122 local zone=${1}
3cb2fc42 123 assert isset zone
f6ee6bb1 124
22a61046 125 # Print the default header.
3cb2fc42 126 cli_device_headline ${zone}
f6ee6bb1
AF
127
128 # Exit if zone is down
129 if ! zone_is_up ${zone}; then
130 echo # Empty line
131 exit ${EXIT_ERROR}
132 fi
133
22a61046
MT
134 cli_headline 2 "Wireless network information"
135 cli_print_fmt1 2 "SSID" "$(wpa_cli_status_get ${zone} ssid)"
136 cli_space
137
138 cli_headline 3 "Access Point"
139 local bssid=$(wpa_cli_status_get ${zone} bssid)
140 assert isset bssid
141
142 cli_print_fmt1 3 "BSSID" "${bssid}"
143 cli_print_fmt1 3 "Frequency" \
144 "$(wpa_cli_bss_get_frequency ${zone} ${bssid}) MHz"
145 cli_print_fmt1 3 "Noise" \
146 "$(wpa_cli_bss_get_noise ${zone} ${bssid})"
147 cli_print_fmt1 3 "Quality" \
148 "$(wpa_cli_bss_get_quality ${zone} ${bssid})"
149 cli_print_fmt1 3 "Flags" \
150 "$(wpa_cli_bss_get_flags ${zone} ${bssid})"
151 cli_space
152
153 cli_headline 3 "Encryption"
154 cli_print_fmt1 3 "Mode" \
155 "$(wpa_cli_status_get ${zone} key_mgmt)"
156 cli_print_fmt1 3 "Pairwise cipher" \
157 "$(wpa_cli_status_get ${zone} pairwise_cipher)"
158 cli_print_fmt1 3 "Group cipher" \
159 "$(wpa_cli_status_get ${zone} group_cipher)"
160 cli_space
161
162 cli_headline 2 "Configurations"
f6ee6bb1 163 zone_configs_cmd status ${zone}
22a61046 164 cli_space
f6ee6bb1 165
f6ee6bb1
AF
166 exit ${EXIT_OK}
167}