From 0fbae55bf6c4bb4352bca80131ffb8d295aa98bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Molinero=20Fern=C3=A1ndez?= Date: Sat, 11 Jan 2020 11:42:05 +0100 Subject: [PATCH] Reload brcmfmac driver on crash, workaround for evilsocket/pwnagotchi#267 --- packer/rootfs/etc/pwnagotchi.env | 1 + .../etc/systemd/system/pwnagotchi.service | 12 +++++----- packer/rootfs/usr/bin/reload-brcmfmac-driver | 23 +++++++++++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) create mode 100755 packer/rootfs/usr/bin/reload-brcmfmac-driver diff --git a/packer/rootfs/etc/pwnagotchi.env b/packer/rootfs/etc/pwnagotchi.env index 1b66a96..860b75c 100644 --- a/packer/rootfs/etc/pwnagotchi.env +++ b/packer/rootfs/etc/pwnagotchi.env @@ -1,2 +1,3 @@ PWNAGOTCHI_USERNAME=pwnagotchi PWNAGOTCHI_PASSWORD=pwnagotchi +PWNAGOTCHI_IFACE_NET=wlan0 diff --git a/packer/rootfs/etc/systemd/system/pwnagotchi.service b/packer/rootfs/etc/systemd/system/pwnagotchi.service index dfc487a..bbe3c0e 100644 --- a/packer/rootfs/etc/systemd/system/pwnagotchi.service +++ b/packer/rootfs/etc/systemd/system/pwnagotchi.service @@ -6,12 +6,10 @@ After=docker.service [Service] Type=simple ExecStartPre=-/bin/mkdir /var/lib/pwnagotchi/ -ExecStartPre=-/usr/bin/docker rm "%N" +ExecStartPre=-/usr/bin/docker rm pwnagotchi ExecStart=/usr/bin/docker run \ - --rm --tty \ - --name "%N" \ - --hostname "%H" \ - --privileged --net host \ + --name pwnagotchi --hostname "%H" \ + --rm --tty --privileged --net host \ --env PWNAGOTCHI_NAME="%H" \ --env-file /etc/pwnagotchi.env \ --mount type=tmpfs,dst=/run/,tmpfs-mode=0755 \ @@ -19,7 +17,9 @@ ExecStart=/usr/bin/docker run \ --mount type=bind,src=/sys/fs/cgroup/,dst=/sys/fs/cgroup/,ro \ --mount type=bind,src=/var/lib/pwnagotchi/,dst=/root/ \ docker.io/hectormolinero/pwnagotchi:latest -ExecStop=/usr/bin/docker stop "%N" +ExecStop=/usr/bin/docker stop pwnagotchi +ExecStopPost=/usr/bin/reload-brcmfmac-driver +TimeoutStopSec=180 Restart=always [Install] diff --git a/packer/rootfs/usr/bin/reload-brcmfmac-driver b/packer/rootfs/usr/bin/reload-brcmfmac-driver new file mode 100755 index 0000000..156a88c --- /dev/null +++ b/packer/rootfs/usr/bin/reload-brcmfmac-driver @@ -0,0 +1,23 @@ +#!/bin/sh + +# Workaround for: +# https://github.com/evilsocket/pwnagotchi/issues/267 + +set -eu + +reload_driver() { + printf '%s\n' 'Reloading brcmfmac driver...' + + modprobe -rv brcmfmac || return 1; sleep 3 + modprobe -v brcmfmac || return 1; sleep 3 + + printf 'mmc1:0001:1' > /sys/bus/sdio/drivers/brcmfmac/unbind || return 1; sleep 3 + printf 'mmc1:0001:2' > /sys/bus/sdio/drivers/brcmfmac/unbind || return 1; sleep 3 + printf 'mmc1:0001:1' > /sys/bus/sdio/drivers/brcmfmac/bind || return 1; sleep 3 + printf 'mmc1:0001:2' > /sys/bus/sdio/drivers/brcmfmac/bind || return 1; sleep 3 +} + +t=0; tmax=3 +until [ "${t:?}" -ge "${tmax:?}" ] || reload_driver; do + t=$((t+1)); sleep 10 +done