From 34b177aa69e29682f8f361199afa4a9263deb75b Mon Sep 17 00:00:00 2001 From: Glen Sawyer Date: Tue, 19 Jan 2021 13:09:17 -0700 Subject: [PATCH] Wifi toggle for reMarkable 2 (#7122) reMarkable 1 is no-op for the moment --- frontend/device/remarkable/device.lua | 29 +++++++++++++++++++++++++++ platform/remarkable/disable-wifi.sh | 18 +++++++++++++++++ platform/remarkable/enable-wifi.sh | 20 ++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100755 platform/remarkable/disable-wifi.sh create mode 100755 platform/remarkable/enable-wifi.sh diff --git a/frontend/device/remarkable/device.lua b/frontend/device/remarkable/device.lua index de5e37b71..9abd6db63 100644 --- a/frontend/device/remarkable/device.lua +++ b/frontend/device/remarkable/device.lua @@ -130,6 +130,32 @@ end function Remarkable:supportsScreensaver() return true end +function Remarkable:initNetworkManager(NetworkMgr) + function NetworkMgr:turnOnWifi(complete_callback) + os.execute("./enable-wifi.sh") + self:reconnectOrShowNetworkMenu(function() + self:connectivityCheck(1, complete_callback) + end) + end + + function NetworkMgr:turnOffWifi(complete_callback) + os.execute("./disable-wifi.sh") + if complete_callback then + complete_callback() + end + end + + function NetworkMgr:getNetworkInterfaceName() + return "wlan0" + end + + NetworkMgr:setWirelessBackend("wpa_supplicant", {ctrl_interface = "/var/run/wpa_supplicant/wlan0"}) + + NetworkMgr.isWifiOn = function() + return NetworkMgr:isConnected() + end +end + function Remarkable:setDateTime(year, month, day, hour, min, sec) if hour == nil or min == nil then return true end local command @@ -146,6 +172,9 @@ function Remarkable1:suspend() end function Remarkable2:suspend() + -- Need to remove brcmfmac kernel module before suspend. Otherwise the module crashes on wakeup + os.execute("./disable-wifi.sh") + os.execute("systemctl suspend") -- While device is suspended, when the user presses the power button and wakes up the device, -- a "Power" event is NOT sent. diff --git a/platform/remarkable/disable-wifi.sh b/platform/remarkable/disable-wifi.sh new file mode 100755 index 000000000..099f85c11 --- /dev/null +++ b/platform/remarkable/disable-wifi.sh @@ -0,0 +1,18 @@ +#!/bin/sh + +# disable wifi and remove modules + +read -r MACHINE_TYPE <"/sys/devices/soc0/machine" + +if [ "reMarkable 2.0" = "${MACHINE_TYPE}" ]; then + # 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 + + # power down wifi interface + ifconfig wlan0 down 2>/dev/null + + # remove module: IMPORTANT to do this before device suspends + modprobe -r brcmfmac 2>/dev/null +fi diff --git a/platform/remarkable/enable-wifi.sh b/platform/remarkable/enable-wifi.sh new file mode 100755 index 000000000..9968188e5 --- /dev/null +++ b/platform/remarkable/enable-wifi.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +read -r MACHINE_TYPE <"/sys/devices/soc0/machine" + +if [ "reMarkable 2.0" = "${MACHINE_TYPE}" ]; then + if lsmod | grep -q brcmfmac; then + ifconfig wlan0 up + else + modprobe brcmfmac + 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 + + sleep 1 + + wpa_supplicant -i wlan0 -C /var/run/wpa_supplicant -B 2>/dev/null +fi