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