]> git.ipfire.org Git - people/stevee/network.git/blame - src/hooks/zones/wireless
Convert HOOK_SETTINGS into an array
[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 23
d389e96b
MT
24HOOK_SETTINGS=(
25 "ADDRESS"
26 "PHY"
27)
f6ee6bb1 28
1c6a4e30 29hook_check_settings() {
e66e539b 30 assert ismac ADDRESS
f6ee6bb1 31 assert ismac PHY
f6ee6bb1
AF
32}
33
1c6a4e30 34hook_parse_cmdline() {
f6ee6bb1
AF
35 while [ $# -gt 0 ]; do
36 case "${1}" in
22a61046 37 --address=*)
2212045f 38 ADDRESS=$(cli_get_val "${1}")
f6ee6bb1 39 ;;
e66e539b
MT
40 --phy=*)
41 PHY=$(cli_get_val "${1}")
f6ee6bb1
AF
42 ;;
43 *)
22a61046 44 warning "Unrecognized option: ${1}"
f6ee6bb1
AF
45 ;;
46 esac
47 shift
48 done
49
22a61046 50 # Just save the MAC address of the phy.
f6ee6bb1
AF
51 PHY=$(phy_get ${PHY})
52 PHY=$(phy_get_address ${PHY})
e66e539b
MT
53
54 # Generate a random MAC address if none given
55 if ! isset ADDRESS; then
56 ADDRESS="$(mac_generate)"
57 fi
f6ee6bb1
AF
58}
59
1c6a4e30 60hook_up() {
f6ee6bb1 61 local zone=${1}
f6ee6bb1
AF
62 assert isset zone
63
22a61046 64 # Read zone configuration.
1e6f187e 65 zone_settings_read "${zone}"
f6ee6bb1 66
e66e539b
MT
67 # Create the wireless interface
68 if ! device_exists "${zone}"; then
69 wireless_create "${zone}" \
22a61046
MT
70 --phy=${PHY} \
71 --type="managed" \
72 --address="${ADDRESS}" \
e66e539b 73 || return $?
22a61046 74 fi
f6ee6bb1 75
02807ad2 76 # Write WPA supplicant configuration
e66e539b
MT
77 if ! wireless_networks_write_wpa_supplicant_configuration "${zone}"; then
78 log ERROR "Could not write WPA supplicant configuration for ${zone}"
79 return ${EXIT_ERROR}
80 fi
02807ad2 81
22a61046
MT
82 # Start the WPA supplicant daemon.
83 wpa_supplicant_start ${zone}
f6ee6bb1
AF
84
85 zone_configs_up ${zone}
86
e66e539b 87 return ${EXIT_OK}
f6ee6bb1
AF
88}
89
1c6a4e30 90hook_down() {
f6ee6bb1
AF
91 local zone=${1}
92 shift
93
94 if ! device_is_up ${zone}; then
95 warning "Zone '${zone}' is not up"
96 exit ${EXIT_OK}
97 fi
98
f6ee6bb1
AF
99 zone_configs_down ${zone}
100
101 wpa_supplicant_stop ${zone}
102
02807ad2
MT
103 # Remove WPA supplicant configuration
104 wpa_supplicant_config_destroy "${zone}"
105
f6ee6bb1
AF
106 wireless_remove ${zone}
107
108 exit ${EXIT_OK}
109}
110
1c6a4e30 111hook_status() {
f6ee6bb1 112 local zone=${1}
3cb2fc42 113 assert isset zone
f6ee6bb1 114
22a61046 115 # Print the default header.
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
607481ac
MT
124 if wireless_client_is_connected "${zone}"; then
125 cli_headline 2 "Wireless network information"
126 cli_print_fmt1 2 "SSID" "$(wpa_cli_status_get ${zone} ssid)"
127 cli_space
128
129 cli_headline 3 "Access Point"
130 local bssid=$(wpa_cli_status_get ${zone} bssid)
131 assert isset bssid
132
133 local frequency=$(wpa_cli_bss_get_frequency "${zone}" "${bssid}")
134 cli_print_fmt1 3 "Channel" "$(wireless_frequency_to_channel ${frequency}) (${frequency} MHz)"
135 cli_print_fmt1 3 "BSSID" "${bssid}"
136 cli_print_fmt1 3 "Noise" \
137 "$(wpa_cli_bss_get_noise ${zone} ${bssid})"
138 cli_print_fmt1 3 "Quality" \
139 "$(wpa_cli_bss_get_quality ${zone} ${bssid})%%"
140 cli_print_fmt1 3 "Flags" \
141 "$(wpa_cli_bss_get_flags ${zone} ${bssid})"
142 cli_space
143
144 cli_headline 3 "Encryption"
145 cli_print_fmt1 3 "Mode" \
146 "$(wpa_cli_status_get ${zone} key_mgmt)"
147 cli_print_fmt1 3 "Pairwise cipher" \
148 "$(wpa_cli_status_get ${zone} pairwise_cipher)"
149 cli_print_fmt1 3 "Group cipher" \
150 "$(wpa_cli_status_get ${zone} group_cipher)"
151 cli_space
152 fi
22a61046
MT
153
154 cli_headline 2 "Configurations"
f6ee6bb1 155 zone_configs_cmd status ${zone}
22a61046 156 cli_space
f6ee6bb1 157
f6ee6bb1
AF
158 exit ${EXIT_OK}
159}