]>
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 | ||
26 | HOOK_SETTINGS="HOOK ADDRESS MESH_ID CHANNEL PHY" | |
27 | ||
28 | hook_check_settings() { | |
29 | assert ismac ADDRESS | |
30 | assert isset MESH_ID | |
31 | assert isset CHANNEL | |
32 | assert isset PHY | |
33 | assert ismac PHY | |
34 | } | |
35 | ||
36 | hook_parse_cmdline() { | |
37 | while [ $# -gt 0 ]; do | |
38 | case "${1}" in | |
39 | --address=*) | |
40 | ADDRESS=$(cli_get_val "${1}") | |
41 | ;; | |
42 | --channel=*) | |
43 | CHANNEL=$(cli_get_val "${1}") | |
44 | ;; | |
45 | --mesh-id=*) | |
46 | MESH_ID=$(cli_get_val "${1}") | |
47 | ;; | |
48 | --phy=*) | |
49 | PHY=$(cli_get_val "${1}") | |
50 | ;; | |
51 | *) | |
52 | warning "Ignoring unknown argument '${1}'" | |
53 | ;; | |
54 | esac | |
55 | shift | |
56 | done | |
57 | ||
58 | if ! isset MESH_ID; then | |
59 | error "Please pass a mesh ID" | |
60 | return ${EXIT_ERROR} | |
61 | fi | |
62 | ||
63 | # Save address of phy do identify it again | |
64 | PHY=$(phy_get ${PHY}) | |
65 | PHY=$(phy_get_address ${PHY}) | |
66 | ||
67 | # Generate a MAC address if none given | |
68 | if ! isset ADDRESS; then | |
69 | ADDRESS=$(mac_generate) | |
70 | fi | |
71 | ||
72 | # XXX check if wireless channel is valid | |
f8b7f135 MT |
73 | # Check if channel is valid |
74 | if ! wireless_channel_is_valid "${CHANNEL}"; then | |
75 | log ERROR "Channel is invalid: ${CHANNEL}" | |
76 | return ${EXIT_ERROR} | |
77 | fi | |
727248f0 MT |
78 | } |
79 | ||
80 | hook_create() { | |
81 | local port="${1}" | |
82 | assert isset port | |
83 | ||
84 | # Read settings | |
85 | port_settings_read "${port}" ${HOOK_SETTINGS} | |
86 | ||
87 | # Check if the PHY is present. | |
88 | local phy="$(phy_get "${PHY}")" | |
89 | if ! isset phy; then | |
90 | log DEBUG "phy '${PHY}' is not present" | |
91 | return ${EXIT_ERROR} | |
92 | fi | |
93 | ||
94 | # Create the wireless device, if it does not exist, yet. | |
95 | if ! device_exists "${port}"; then | |
96 | wireless_create "${port}" \ | |
97 | --address="${ADDRESS}" \ | |
98 | --channel="${CHANNEL}" \ | |
99 | --phy="${phy}" \ | |
100 | --type="mesh-point" || return $? | |
101 | fi | |
102 | ||
103 | return ${EXIT_OK} | |
104 | } | |
105 | ||
106 | hook_remove() { | |
107 | local port="${1}" | |
108 | assert isset port | |
109 | ||
110 | if device_exists "${port}"; then | |
111 | wireless_remove "${port}" | |
112 | fi | |
113 | ||
114 | exit ${EXIT_OK} | |
115 | } | |
116 | ||
117 | hook_hotplug() { | |
118 | local port="${1}" | |
119 | assert isset port | |
120 | ||
121 | port_settings_read "${port}" ${HOOK_SETTINGS} | |
122 | ||
123 | case "$(hotplug_action)" in | |
124 | add) | |
125 | # Bring up the port when the phy is plugged in | |
126 | if hotplug_event_port_uses_phy "${port}"; then | |
127 | hook_create "${port}" || exit $? | |
128 | fi | |
129 | ;; | |
130 | ||
131 | *) | |
132 | exit ${EXIT_NOT_HANDLED} | |
133 | ;; | |
134 | esac | |
135 | ||
136 | exit ${EXIT_OK} | |
137 | } |