]>
Commit | Line | Data |
---|---|---|
ff358a46 MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2013 Michael Tremer # | |
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 | ||
31670741 | 24 | HOOK_SETTINGS="HOOK ADDRESS MESH_ID SSID CHANNEL PHY" |
ff358a46 MT |
25 | |
26 | # Default values | |
27 | ADDRESS=$(mac_generate) | |
28 | CHANNEL=1 | |
ff358a46 MT |
29 | MESH_ID= |
30 | SSID= | |
31 | ||
32 | # batman-adv inserts an additional header of 28 bytes, so we set the MTU | |
33 | # to 1528, that normal ethernet packets with 1500 bytes can pass the network. | |
34 | MTU=1528 | |
35 | ||
36 | function hook_check() { | |
37 | assert isset ADDRESS | |
38 | assert ismac ADDRESS | |
39 | assert isset CHANNEL | |
ff358a46 MT |
40 | assert isset MESH_ID |
41 | assert ismac MESH_ID | |
42 | assert isset PHY | |
43 | assert ismac PHY | |
44 | assert isset SSID | |
45 | } | |
46 | ||
47 | function hook_parse_cmdline() { | |
48 | while [ $# -gt 0 ]; do | |
49 | case "${1}" in | |
50 | --address=*) | |
51 | ADDRESS="$(cli_get_val ${1})" | |
52 | ;; | |
53 | --channel=*) | |
54 | CHANNEL="$(cli_get_val ${1})" | |
55 | ;; | |
ff358a46 MT |
56 | --mesh-id=*) |
57 | MESH_ID="$(cli_get_val ${1})" | |
58 | ;; | |
59 | --phy=*) | |
60 | PHY="$(cli_get_val ${1})" | |
61 | ;; | |
62 | --ssid=*) | |
63 | SSID=$(cli_get_val ${1}) | |
64 | ;; | |
65 | *) | |
66 | warning "Unrecognized option: ${1}" | |
67 | ;; | |
68 | esac | |
69 | shift | |
70 | done | |
71 | ||
72 | # Save address of phy do identify it again | |
73 | PHY=$(phy_get ${PHY}) | |
74 | PHY=$(phy_get_address ${PHY}) | |
75 | ||
76 | return ${EXIT_OK} | |
77 | } | |
78 | ||
79 | function hook_up() { | |
80 | local zone=${1} | |
81 | assert isset zone | |
82 | ||
83 | # Read zone configuration. | |
84 | zone_config_read ${zone} | |
85 | ||
86 | # Check if the PHY is present. | |
87 | local phy="$(phy_get ${PHY})" | |
88 | if ! isset phy; then | |
89 | log DEBUG "phy '${PHY}' is not present" | |
90 | exit ${EXIT_ERROR} | |
91 | fi | |
92 | ||
93 | # Create the wireless device, if it does not exist, yet. | |
94 | if ! device_exists "${zone}"; then | |
95 | wireless_create "${zone}" \ | |
96 | --address="${ADDRESS}" \ | |
97 | --phy="${phy}" \ | |
98 | --type="ibss" | |
99 | fi | |
100 | ||
101 | # Set the MTU. | |
102 | device_set_mtu "${zone}" "${MTU}" | |
103 | ||
104 | # Join the ad-hoc network. | |
105 | wireless_ibss_join "${zone}" --channel="${CHANNEL}" \ | |
106 | --bssid="${MESH_ID}" --essid="${SSID}" | |
107 | ||
108 | # Add the device as a batman-adv device. | |
109 | batman_adv_interface_add "${zone}" | |
110 | ||
111 | zone_configs_up ${zone} | |
112 | ||
113 | exit ${EXIT_OK} | |
114 | } | |
115 | ||
116 | function hook_down() { | |
117 | local zone=${1} | |
118 | shift | |
119 | ||
120 | if ! device_is_up ${zone}; then | |
121 | warning "Zone '${zone}' is not up" | |
122 | exit ${EXIT_OK} | |
123 | fi | |
124 | ||
125 | zone_configs_down ${zone} | |
126 | ||
127 | # Remove the batman-adv device. | |
128 | batman_adv_interface_del "${zone}" | |
129 | ||
130 | # Leave the ad-hoc network. | |
131 | wireless_ibss_leave "${zone}" | |
132 | ||
133 | # Remove the device if it is still present. | |
134 | if device_exists "${zone}"; then | |
135 | wireless_remove "${zone}" | |
136 | fi | |
137 | ||
138 | exit ${EXIT_OK} | |
139 | } | |
140 | ||
141 | function hook_status() { | |
142 | local zone=${1} | |
143 | assert isset zone | |
144 | ||
145 | # Print the default header. | |
146 | cli_device_headline ${zone} | |
147 | ||
148 | # Exit if zone is down | |
149 | if ! zone_is_up ${zone}; then | |
150 | echo # Empty line | |
151 | exit ${EXIT_ERROR} | |
152 | fi | |
153 | ||
154 | cli_headline 2 "Wireless network information" | |
155 | cli_print_fmt1 2 "SSID" "$(wpa_cli_status_get ${zone} ssid)" | |
156 | cli_space | |
157 | ||
158 | cli_headline 3 "Access Point" | |
159 | local bssid=$(wpa_cli_status_get ${zone} bssid) | |
160 | assert isset bssid | |
161 | ||
162 | cli_print_fmt1 3 "BSSID" "${bssid}" | |
163 | cli_print_fmt1 3 "Frequency" \ | |
164 | "$(wpa_cli_bss_get_frequency ${zone} ${bssid}) MHz" | |
165 | cli_print_fmt1 3 "Noise" \ | |
166 | "$(wpa_cli_bss_get_noise ${zone} ${bssid})" | |
167 | cli_print_fmt1 3 "Quality" \ | |
168 | "$(wpa_cli_bss_get_quality ${zone} ${bssid})" | |
169 | cli_print_fmt1 3 "Flags" \ | |
170 | "$(wpa_cli_bss_get_flags ${zone} ${bssid})" | |
171 | cli_space | |
172 | ||
173 | cli_headline 3 "Encryption" | |
174 | cli_print_fmt1 3 "Mode" \ | |
175 | "$(wpa_cli_status_get ${zone} key_mgmt)" | |
176 | cli_print_fmt1 3 "Pairwise cipher" \ | |
177 | "$(wpa_cli_status_get ${zone} pairwise_cipher)" | |
178 | cli_print_fmt1 3 "Group cipher" \ | |
179 | "$(wpa_cli_status_get ${zone} group_cipher)" | |
180 | cli_space | |
181 | ||
182 | cli_headline 2 "Configurations" | |
183 | zone_configs_cmd status ${zone} | |
184 | cli_space | |
185 | ||
186 | exit ${EXIT_OK} | |
187 | } |