]>
Commit | Line | Data |
---|---|---|
727248f0 MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2017 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-port | |
23 | ||
24 | HOOK_PORT_PATTERN="${PORT_PATTERN_MESH}" | |
25 | ||
d389e96b MT |
26 | HOOK_SETTINGS=( |
27 | "ADDRESS" | |
28 | "CHANNEL" | |
29 | "MESH_ID" | |
30 | "PHY" | |
31 | "PSK" | |
32 | ) | |
727248f0 MT |
33 | |
34 | hook_check_settings() { | |
35 | assert ismac ADDRESS | |
36 | assert isset MESH_ID | |
37 | assert isset CHANNEL | |
38 | assert isset PHY | |
39 | assert ismac PHY | |
40 | } | |
41 | ||
42 | hook_parse_cmdline() { | |
43 | while [ $# -gt 0 ]; do | |
44 | case "${1}" in | |
45 | --address=*) | |
46 | ADDRESS=$(cli_get_val "${1}") | |
47 | ;; | |
48 | --channel=*) | |
49 | CHANNEL=$(cli_get_val "${1}") | |
50 | ;; | |
51 | --mesh-id=*) | |
52 | MESH_ID=$(cli_get_val "${1}") | |
53 | ;; | |
54 | --phy=*) | |
55 | PHY=$(cli_get_val "${1}") | |
56 | ;; | |
5ffbe0d5 MT |
57 | --pre-shared-key=*) |
58 | PSK=$(cli_get_val "${1}") | |
59 | ;; | |
727248f0 MT |
60 | *) |
61 | warning "Ignoring unknown argument '${1}'" | |
62 | ;; | |
63 | esac | |
64 | shift | |
65 | done | |
66 | ||
67 | if ! isset MESH_ID; then | |
68 | error "Please pass a mesh ID" | |
69 | return ${EXIT_ERROR} | |
70 | fi | |
71 | ||
72 | # Save address of phy do identify it again | |
73 | PHY=$(phy_get ${PHY}) | |
74 | PHY=$(phy_get_address ${PHY}) | |
75 | ||
76 | # Generate a MAC address if none given | |
77 | if ! isset ADDRESS; then | |
78 | ADDRESS=$(mac_generate) | |
79 | fi | |
80 | ||
f8b7f135 MT |
81 | # Check if channel is valid |
82 | if ! wireless_channel_is_valid "${CHANNEL}"; then | |
83 | log ERROR "Channel is invalid: ${CHANNEL}" | |
84 | return ${EXIT_ERROR} | |
85 | fi | |
727248f0 MT |
86 | } |
87 | ||
88 | hook_create() { | |
89 | local port="${1}" | |
90 | assert isset port | |
91 | ||
92 | # Read settings | |
eba9fa9c | 93 | port_settings_read "${port}" |
727248f0 MT |
94 | |
95 | # Check if the PHY is present. | |
96 | local phy="$(phy_get "${PHY}")" | |
97 | if ! isset phy; then | |
98 | log DEBUG "phy '${PHY}' is not present" | |
99 | return ${EXIT_ERROR} | |
100 | fi | |
101 | ||
102 | # Create the wireless device, if it does not exist, yet. | |
103 | if ! device_exists "${port}"; then | |
104 | wireless_create "${port}" \ | |
105 | --address="${ADDRESS}" \ | |
106 | --channel="${CHANNEL}" \ | |
107 | --phy="${phy}" \ | |
108 | --type="mesh-point" || return $? | |
109 | fi | |
110 | ||
1d736e21 | 111 | # Write WPA supplicant configuration |
81bf9898 MT |
112 | if ! wireless_mesh_to_wpa_supplicant "${port}" --mesh-id="${MESH_ID}" \ |
113 | --channel="${CHANNEL}" --pre-shared-key="${PSK}"; then | |
114 | log ERROR "Could not generate WPA supplicant configuration" | |
115 | return ${EXIT_ERROR} | |
116 | fi | |
1d736e21 | 117 | |
727248f0 MT |
118 | return ${EXIT_OK} |
119 | } | |
120 | ||
121 | hook_remove() { | |
122 | local port="${1}" | |
123 | assert isset port | |
124 | ||
02807ad2 MT |
125 | # Remove WPA supplicant configuration |
126 | wpa_supplicant_config_destroy "${port}" | |
127 | ||
727248f0 MT |
128 | if device_exists "${port}"; then |
129 | wireless_remove "${port}" | |
130 | fi | |
131 | ||
132 | exit ${EXIT_OK} | |
133 | } | |
134 | ||
1d736e21 MT |
135 | hook_up() { |
136 | local port="${1}" | |
137 | ||
138 | # Start WPA supplicant | |
139 | wpa_supplicant_start "${port}" | |
140 | } | |
141 | ||
142 | hook_down() { | |
143 | local port="${1}" | |
144 | ||
145 | wpa_supplicant_stop "${port}" | |
146 | } | |
147 | ||
727248f0 MT |
148 | hook_hotplug() { |
149 | local port="${1}" | |
150 | assert isset port | |
151 | ||
eba9fa9c | 152 | port_settings_read "${port}" |
727248f0 MT |
153 | |
154 | case "$(hotplug_action)" in | |
155 | add) | |
156 | # Bring up the port when the phy is plugged in | |
157 | if hotplug_event_port_uses_phy "${port}"; then | |
158 | hook_create "${port}" || exit $? | |
159 | fi | |
160 | ;; | |
161 | ||
162 | *) | |
163 | exit ${EXIT_NOT_HANDLED} | |
164 | ;; | |
165 | esac | |
166 | ||
167 | exit ${EXIT_OK} | |
168 | } |