From c6ab0b0cb7054353b98fdff9edff65f1491cc69b Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@robotics.uk.to>
Date: Sat, 10 Sep 2016 14:58:51 +0100
Subject: [PATCH] Install horst for wifi network monitoring

---
 src/freedombone-image-customise |  3 +++
 src/freedombone-mesh-batman     | 34 ++++++++++++++++++++++++++++++++-
 2 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/src/freedombone-image-customise b/src/freedombone-image-customise
index 6a6ea3c6f..b648471ca 100755
--- a/src/freedombone-image-customise
+++ b/src/freedombone-image-customise
@@ -735,6 +735,9 @@ function configure_user_interface {
     # a sane editor
     chroot "$rootdir" apt-get -y install emacs24
 
+    # for wifi monitoring
+    chroot "$rootdir" apt-get -y install horst
+
     # for sound level control
     chroot "$rootdir" apt-get -y install alsa-utils
 
diff --git a/src/freedombone-mesh-batman b/src/freedombone-mesh-batman
index 1d6618e41..afef1e788 100755
--- a/src/freedombone-mesh-batman
+++ b/src/freedombone-mesh-batman
@@ -260,6 +260,38 @@ function start {
     verify
 }
 
+function monitor {
+    if [ -z "$IFACE" ] ; then
+        echo 'error: unable to find wifi interface, not enabling batman-adv mesh'
+        exit 723657
+    fi
+
+    stop
+
+    echo "info: monitoring mesh network $WIFI_SSID on $IFACE"
+
+    systemctl stop network-manager
+    sleep 5
+
+    global_rate_limit
+
+    # Might have to re-enable wifi
+    rfkill unblock $(rfkill list|awk -F: "/phy/ {print $1}") || true
+
+    ifconfig $IFACE down
+    ifconfig $IFACE mtu 1532
+    ifconfig $IFACE hw ether $(assign_peer_address)
+    iwconfig $IFACE enc off
+    iwconfig $IFACE mode monitor channel $CHANNEL
+    sleep 1
+    iwconfig $IFACE ap $CELLID
+
+    modprobe batman-adv
+    batctl if add $IFACE
+    ifconfig $IFACE up
+    horst -i $IFACE
+}
+
 if ! grep -q "$IFACE" /proc/net/dev; then
     echo 'Interface $IFACE was not found'
     stop
@@ -267,7 +299,7 @@ if ! grep -q "$IFACE" /proc/net/dev; then
 fi
 
 case "$1" in
-    start|stop|status)
+    start|stop|status|monitor)
         $1
         ;;
     restart)
-- 
GitLab