Skip to content

Commit

Permalink
Reload brcmfmac driver on crash,
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorm committed Jan 11, 2020
1 parent 2653cff commit 0fbae55
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
1 change: 1 addition & 0 deletions packer/rootfs/etc/pwnagotchi.env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
PWNAGOTCHI_USERNAME=pwnagotchi
PWNAGOTCHI_PASSWORD=pwnagotchi
PWNAGOTCHI_IFACE_NET=wlan0
12 changes: 6 additions & 6 deletions packer/rootfs/etc/systemd/system/pwnagotchi.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ 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 \
--mount type=tmpfs,dst=/tmp/,tmpfs-mode=1777 \
--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]
Expand Down
23 changes: 23 additions & 0 deletions packer/rootfs/usr/bin/reload-brcmfmac-driver
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0fbae55

Please sign in to comment.