]> git.ipfire.org Git - people/ms/network.git/commitdiff
Import missing BATMAN zone hook
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 24 Aug 2014 19:48:10 +0000 (21:48 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 24 Aug 2014 19:48:10 +0000 (21:48 +0200)
src/hooks/zones/batman-adv [new file with mode: 0644]

diff --git a/src/hooks/zones/batman-adv b/src/hooks/zones/batman-adv
new file mode 100644 (file)
index 0000000..7390114
--- /dev/null
@@ -0,0 +1,192 @@
+#!/bin/bash
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2013 Michael Tremer                                           #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
+
+. /usr/lib/network/header-zone
+
+HOOK_SETTINGS="HOOK ADDRESS MESH_ID SSID CHANNEL COUNTRY_CODE PHY"
+
+# Default values
+ADDRESS=$(mac_generate)
+CHANNEL=1
+COUNTRY_CODE="US"
+MESH_ID=
+SSID=
+
+# batman-adv inserts an additional header of 28 bytes, so we set the MTU
+# to 1528, that normal ethernet packets with 1500 bytes can pass the network.
+MTU=1528
+
+function hook_check() {
+       assert isset ADDRESS
+       assert ismac ADDRESS
+       assert isset CHANNEL
+       assert isset COUNTRY_CODE
+       assert isset MESH_ID
+       assert ismac MESH_ID
+       assert isset PHY
+       assert ismac PHY
+       assert isset SSID
+}
+
+function hook_parse_cmdline() {
+       while [ $# -gt 0 ]; do
+               case "${1}" in
+                       --address=*)
+                               ADDRESS="$(cli_get_val ${1})"
+                               ;;
+                       --channel=*)
+                               CHANNEL="$(cli_get_val ${1})"
+                               ;;
+                       --country-code=*)
+                               COUNTRY_CODE="$(cli_get_val ${1})"
+                               ;;
+                       --mesh-id=*)
+                               MESH_ID="$(cli_get_val ${1})"
+                               ;;
+                       --phy=*)
+                               PHY="$(cli_get_val ${1})"
+                               ;;
+                       --ssid=*)
+                               SSID=$(cli_get_val ${1})
+                               ;;
+                       *)
+                               warning "Unrecognized option: ${1}"
+                               ;;
+               esac
+               shift
+       done
+
+       # Save address of phy do identify it again
+       PHY=$(phy_get ${PHY})
+       PHY=$(phy_get_address ${PHY})
+
+       return ${EXIT_OK}
+}
+
+function hook_up() {
+       local zone=${1}
+       assert isset zone
+
+       # Read zone configuration.
+       zone_config_read ${zone}
+
+       # Check if the PHY is present.
+       local phy="$(phy_get ${PHY})"
+       if ! isset phy; then
+               log DEBUG "phy '${PHY}' is not present"
+               exit ${EXIT_ERROR}
+       fi
+
+       # Create the wireless device, if it does not exist, yet.
+       if ! device_exists "${zone}"; then
+               wireless_create "${zone}" \
+                       --address="${ADDRESS}" \
+                       --phy="${phy}" \
+                       --type="ibss"
+       fi
+
+       # Set the MTU.
+       device_set_mtu "${zone}" "${MTU}"
+
+       # Join the ad-hoc network.
+       wireless_ibss_join "${zone}" --channel="${CHANNEL}" \
+               --bssid="${MESH_ID}" --essid="${SSID}"
+
+       # Add the device as a batman-adv device.
+       batman_adv_interface_add "${zone}"
+
+       zone_configs_up ${zone}
+
+       exit ${EXIT_OK}
+}
+
+function hook_down() {
+       local zone=${1}
+       shift
+
+       if ! device_is_up ${zone}; then
+               warning "Zone '${zone}' is not up"
+               exit ${EXIT_OK}
+       fi
+
+       zone_configs_down ${zone}
+
+       # Remove the batman-adv device.
+       batman_adv_interface_del "${zone}"
+
+       # Leave the ad-hoc network.
+       wireless_ibss_leave "${zone}"
+
+       # Remove the device if it is still present.
+       if device_exists "${zone}"; then
+               wireless_remove "${zone}"
+       fi
+
+       exit ${EXIT_OK}
+}
+
+function hook_status() {
+       local zone=${1}
+       assert isset zone
+
+       # Print the default header.
+       cli_device_headline ${zone}
+
+       # Exit if zone is down
+       if ! zone_is_up ${zone}; then
+               echo # Empty line
+               exit ${EXIT_ERROR}
+       fi
+
+       cli_headline 2 "Wireless network information"
+       cli_print_fmt1 2 "SSID" "$(wpa_cli_status_get ${zone} ssid)"
+       cli_space
+
+       cli_headline 3 "Access Point"
+       local bssid=$(wpa_cli_status_get ${zone} bssid)
+       assert isset bssid
+
+       cli_print_fmt1 3 "BSSID" "${bssid}"
+       cli_print_fmt1 3 "Frequency" \
+               "$(wpa_cli_bss_get_frequency ${zone} ${bssid}) MHz"
+       cli_print_fmt1 3 "Noise" \
+               "$(wpa_cli_bss_get_noise ${zone} ${bssid})"
+       cli_print_fmt1 3 "Quality" \
+               "$(wpa_cli_bss_get_quality ${zone} ${bssid})"
+       cli_print_fmt1 3 "Flags" \
+               "$(wpa_cli_bss_get_flags ${zone} ${bssid})"
+       cli_space
+
+       cli_headline 3 "Encryption"
+       cli_print_fmt1 3 "Mode" \
+               "$(wpa_cli_status_get ${zone} key_mgmt)"
+       cli_print_fmt1 3 "Pairwise cipher" \
+               "$(wpa_cli_status_get ${zone} pairwise_cipher)"
+       cli_print_fmt1 3 "Group cipher" \
+               "$(wpa_cli_status_get ${zone} group_cipher)"
+       cli_space
+
+       cli_headline 2 "Configurations"
+       zone_configs_cmd status ${zone}
+       cli_space
+
+       exit ${EXIT_OK}
+}