]> git.ipfire.org Git - people/stevee/network.git/blob - src/hooks/zones/wireless
Convert HOOK_SETTINGS into an array
[people/stevee/network.git] / src / hooks / zones / wireless
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 . /usr/lib/network/header-zone
23
24 HOOK_SETTINGS=(
25 "ADDRESS"
26 "PHY"
27 )
28
29 hook_check_settings() {
30 assert ismac ADDRESS
31 assert ismac PHY
32 }
33
34 hook_parse_cmdline() {
35 while [ $# -gt 0 ]; do
36 case "${1}" in
37 --address=*)
38 ADDRESS=$(cli_get_val "${1}")
39 ;;
40 --phy=*)
41 PHY=$(cli_get_val "${1}")
42 ;;
43 *)
44 warning "Unrecognized option: ${1}"
45 ;;
46 esac
47 shift
48 done
49
50 # Just save the MAC address of the phy.
51 PHY=$(phy_get ${PHY})
52 PHY=$(phy_get_address ${PHY})
53
54 # Generate a random MAC address if none given
55 if ! isset ADDRESS; then
56 ADDRESS="$(mac_generate)"
57 fi
58 }
59
60 hook_up() {
61 local zone=${1}
62 assert isset zone
63
64 # Read zone configuration.
65 zone_settings_read "${zone}"
66
67 # Create the wireless interface
68 if ! device_exists "${zone}"; then
69 wireless_create "${zone}" \
70 --phy=${PHY} \
71 --type="managed" \
72 --address="${ADDRESS}" \
73 || return $?
74 fi
75
76 # Write WPA supplicant configuration
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
81
82 # Start the WPA supplicant daemon.
83 wpa_supplicant_start ${zone}
84
85 zone_configs_up ${zone}
86
87 return ${EXIT_OK}
88 }
89
90 hook_down() {
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
99 zone_configs_down ${zone}
100
101 wpa_supplicant_stop ${zone}
102
103 # Remove WPA supplicant configuration
104 wpa_supplicant_config_destroy "${zone}"
105
106 wireless_remove ${zone}
107
108 exit ${EXIT_OK}
109 }
110
111 hook_status() {
112 local zone=${1}
113 assert isset zone
114
115 # Print the default header.
116 cli_device_headline ${zone}
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 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
153
154 cli_headline 2 "Configurations"
155 zone_configs_cmd status ${zone}
156 cli_space
157
158 exit ${EXIT_OK}
159 }