From e28e60769a7f71f23b799d10828f6266b29ce994 Mon Sep 17 00:00:00 2001 From: Colin Date: Tue, 10 Oct 2023 00:35:32 +0000 Subject: [PATCH] sxmo: postwake: show the human-readable wakeup reason --- hosts/modules/gui/sxmo/default.nix | 3 +- .../gui/sxmo/hooks/sxmo_hook_postwake.sh | 37 ++++++++++++++++++- hosts/modules/gui/sxmo/hooks/sxmo_suspend.sh | 8 +--- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/hosts/modules/gui/sxmo/default.nix b/hosts/modules/gui/sxmo/default.nix index 2f6bb293..fbb3c1bf 100644 --- a/hosts/modules/gui/sxmo/default.nix +++ b/hosts/modules/gui/sxmo/default.nix @@ -75,6 +75,7 @@ let }; postwake = pkgs.static-nix-shell.mkBash { pname = "sxmo_hook_postwake.sh"; + pkgs = [ "coreutils" ]; src = ./hooks; }; rotate = pkgs.static-nix-shell.mkBash { @@ -90,7 +91,7 @@ let suspend = pkgs.static-nix-shell.mkBash { pname = "sxmo_suspend.sh"; src = ./hooks; - pkgs = [ "coreutils" "util-linux" ]; + pkgs = [ "util-linux" ]; }; }; in diff --git a/hosts/modules/gui/sxmo/hooks/sxmo_hook_postwake.sh b/hosts/modules/gui/sxmo/hooks/sxmo_hook_postwake.sh index ffd09b73..973228d5 100755 --- a/hosts/modules/gui/sxmo/hooks/sxmo_hook_postwake.sh +++ b/hosts/modules/gui/sxmo/hooks/sxmo_hook_postwake.sh @@ -1,7 +1,42 @@ #!/usr/bin/env nix-shell -#!nix-shell -i bash +#!nix-shell -i bash -p coreutils # the default sxmo_postwake handler checks if the modem is offline # and if so installs a wakelock to block suspend for 30s. # that's a questionable place to install that logic, and i want to keep stuff # out of the wake-from-sleep critical path, so i'm overriding this hook to disable that. + +declare -A newmap +wowlan_reason[0x0]="not wowlan" + +# mappings are found in megi's linux: drivers/staging/rtl8723cs/include/hal_com.h +wowlan_reason[0x1]="RX_PAIRWISEKEY" +wowlan_reason[0x2]="RX_GTK" +wowlan_reason[0x3]="RX_FOURWAY_HANDSHAKE" +wowlan_reason[0x4]="RX_DISASSOC" +wowlan_reason[0x8]="RX_DEAUTH" +wowlan_reason[0x9]="RX_ARP_REQUEST" +wowlan_reason[0x10]="FW_DECISION_DISCONNECT" +wowlan_reason[0x21]="RX_MAGIC_PKT" +wowlan_reason[0x22]="RX_UNICAST_PKT" +wowlan_reason[0x23]="RX_PATTERN_PKT" +wowlan_reason[0x24]="RTD3_SSID_MATCH" +wowlan_reason[0x30]="RX_REALWOW_V2_WAKEUP_PKT" +wowlan_reason[0x31]="RX_REALWOW_V2_ACK_LOST" +wowlan_reason[0x40]="ENABLE_FAIL_DMA_IDLE" +wowlan_reason[0x41]="ENABLE_FAIL_DMA_PAUSE" +wowlan_reason[0x42]="RTIME_FAIL_DMA_IDLE" +wowlan_reason[0x43]="RTIME_FAIL_DMA_PAUSE" +wowlan_reason[0x55]="RX_PNO" +#ifdef CONFIG_WOW_KEEP_ALIVE_PATTERN +wowlan_reason[0x60]="WOW_KEEPALIVE_ACK_TIMEOUT" +wowlan_reason[0x61]="WOW_KEEPALIVE_WAKE" +#endif/*CONFIG_WOW_KEEP_ALIVE_PATTERN*/ +wowlan_reason[0x66]="AP_OFFLOAD_WAKEUP" +wowlan_reason[0xfd]="CLK_32K_UNLOCK" +wowlan_reason[0xfe]="CLK_32K_LOCK" + +wowlan_text="$(cat /proc/net/rtl8723cs/wlan0/wowlan_last_wake_reason)" +wowlan_bits="${wowlan_text/last wake reason: /}" +wowlan_reason="${wowlan_reason[$wowlan_bits]}" +echo "exited suspend: $wowlan_text ($wowlan_reason)" diff --git a/hosts/modules/gui/sxmo/hooks/sxmo_suspend.sh b/hosts/modules/gui/sxmo/hooks/sxmo_suspend.sh index 7756a926..bfa43df5 100755 --- a/hosts/modules/gui/sxmo/hooks/sxmo_suspend.sh +++ b/hosts/modules/gui/sxmo/hooks/sxmo_suspend.sh @@ -1,5 +1,5 @@ #!/usr/bin/env nix-shell -#!nix-shell -i bash -p coreutils -p util-linux +#!nix-shell -i bash -p util-linux # yeah, this isn't technically a hook, but the hook infrastructure isn't actually # restricted to stuff that starts with sxmo_hook_ ... @@ -7,15 +7,11 @@ # this script is only called by sxmo_autosuspend, which is small, so if i wanted to # be more proper i could instead re-implement autosuspend + integrations. -. sxmo_common.sh - suspend_time=300 -sxmo_log "calling suspend for duration: $suspend_time" +echo "calling suspend for duration: $suspend_time" rtcwake -m mem -s "$suspend_time" || exit 1 -sxmo_log "exited suspend: $(cat /proc/net/rtl8723cs/wlan0/wowlan_last_wake_reason)" - sxmo_hook_postwake.sh