From a84ab265b8626791244700adb0a206755d365bd6 Mon Sep 17 00:00:00 2001 From: gbyl <71516803+gbyl@users.noreply.github.com> Date: Sun, 14 Jan 2024 21:38:30 -0600 Subject: [PATCH] reMarkable: More robust Wi-Fi scripts (#11287) Fixing a bunch of issues in the process. --------- Co-authored-by: gbyl --- platform/remarkable/disable-wifi.sh | 26 +++++++++++++++-------- platform/remarkable/enable-wifi.sh | 32 ++++++++++++++++++----------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/platform/remarkable/disable-wifi.sh b/platform/remarkable/disable-wifi.sh index 0b40e6d4e..831e11789 100755 --- a/platform/remarkable/disable-wifi.sh +++ b/platform/remarkable/disable-wifi.sh @@ -1,14 +1,24 @@ #!/bin/sh -# disable wifi and remove modules +# stop wpa_supplicant service cleanly, used by xochitl +if systemctl is-active -q wpa_supplicant; then + systemctl stop wpa_supplicant +fi -# clean stop (if it's running) of main wpa_supplicant service, used by xochitl -systemctl stop wpa_supplicant -# clean stop of non-service wpa_supplicant, if running -wpa_cli terminate 2>/dev/null +# stop non-service wpa_supplicant cleanly +if pidof wpa_supplicant; then + wpa_cli terminate +fi + +# stop dhcpcd if not enabled +if ! systemctl is-enabled -q dhcpcd; then + systemctl stop dhcpcd +fi # power down wifi interface -ifconfig wlan0 down 2>/dev/null +ifconfig wlan0 down -# remove module -modprobe -r brcmfmac 2>/dev/null +# unload brcmfmac kernel module +if grep -q "^brcmfmac " "/proc/modules"; then + modprobe -r brcmfmac +fi diff --git a/platform/remarkable/enable-wifi.sh b/platform/remarkable/enable-wifi.sh index bf77f5a99..6570f0b57 100755 --- a/platform/remarkable/enable-wifi.sh +++ b/platform/remarkable/enable-wifi.sh @@ -1,19 +1,27 @@ #!/bin/sh -read -r MACHINE_TYPE <"/sys/devices/soc0/machine" -if [ "reMarkable 2.0" = "${MACHINE_TYPE}" ]; then - if ! lsmod | grep -q brcmfmac; then - modprobe brcmfmac - fi +# load brcmfmac kernel module +if ! grep -q "^brcmfmac " "/proc/modules"; then + modprobe brcmfmac + sleep 1 fi -# clean stop (if it's running) of main wpa_supplicant service, used by xochitl -systemctl stop wpa_supplicant - -# clean stop of non-service wpa_supplicant, if running -wpa_cli terminate 2>/dev/null +# stop wpa_supplicant service cleanly, used by xochitl +if systemctl is-active -q wpa_supplicant; then + systemctl stop wpa_supplicant +fi -sleep 1 +# stop non-service wpa_supplicant cleanly +if pidof wpa_supplicant; then + wpa_cli terminate +fi +# power up wifi interface ifconfig wlan0 up -wpa_supplicant -i wlan0 -C /var/run/wpa_supplicant -B 2>/dev/null + +# make sure dhcpcd is running +if ! systemctl is-active -q dhcpcd; then + systemctl start dhcpcd +fi + +wpa_supplicant -i wlan0 -C /var/run/wpa_supplicant -B