2023-10-08 01:57:01 +00:00
|
|
|
#!/usr/bin/env nix-shell
|
2023-10-10 09:26:48 +00:00
|
|
|
#!nix-shell -i bash -p coreutils -p rtl8723cs-wowlan -p time -p util-linux
|
2023-10-08 01:57:01 +00:00
|
|
|
|
|
|
|
# yeah, this isn't technically a hook, but the hook infrastructure isn't actually
|
|
|
|
# restricted to stuff that starts with sxmo_hook_ ...
|
|
|
|
#
|
|
|
|
# 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.
|
2023-10-11 00:58:49 +00:00
|
|
|
#
|
|
|
|
# N.B.: if any wake locks are acquired between invocation of this script and the
|
|
|
|
# rtcwake call below, suspend will fail -- even if those locks are released during
|
|
|
|
# the same period.
|
|
|
|
#
|
|
|
|
# this is because the caller of this script writes /sys/power/wakeup_count, and the
|
|
|
|
# kernel checks consistency with that during the actual suspend request.
|
|
|
|
# see: <https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-power>
|
|
|
|
#
|
|
|
|
# for this reason, keep this script as short as possible.
|
|
|
|
#
|
|
|
|
# common sources of wakelocks (which one may wish to reduce) include:
|
|
|
|
# - `sxmo_led.sh blink` (every 2s, by default)
|
2023-10-08 01:57:01 +00:00
|
|
|
|
2023-10-08 04:16:37 +00:00
|
|
|
suspend_time=300
|
2023-10-08 01:57:01 +00:00
|
|
|
|
2023-10-11 00:58:49 +00:00
|
|
|
# TODO: don't do this wowlan stuff every single time.
|
|
|
|
# - it's costly (can take like 1sec)
|
|
|
|
# - it seems to actually block suspension quite often
|
|
|
|
# - possibly rtl8723cs takes time to apply wowlan changes during which suspension is impossible
|
|
|
|
# alternative is to introduce some layer of cache:
|
|
|
|
# - do so in a way such that WiFi connection state changes invalidate the cache
|
|
|
|
# - because wowlan enable w/o connection may well behave differently than w/ connection
|
|
|
|
# - calculating IP addr from link, and then caching on the args we call our helper with may well suffice
|
2023-10-10 09:50:13 +00:00
|
|
|
doas rtl8723cs-wowlan enable-clean
|
2023-10-10 09:26:48 +00:00
|
|
|
# wake on ssh
|
2023-10-10 09:50:13 +00:00
|
|
|
doas rtl8723cs-wowlan tcp --dest-port 22
|
2023-10-10 09:26:48 +00:00
|
|
|
# wake on notification (ntfy/Universal Push)
|
2023-10-10 09:50:13 +00:00
|
|
|
doas rtl8723cs-wowlan tcp --source-port 2587
|
2023-10-10 09:26:48 +00:00
|
|
|
# wake if someone doesn't know how to route to us, because that could obstruct the above
|
2023-10-11 02:41:49 +00:00
|
|
|
doas rtl8723cs-wowlan arp --dest-ip SELF
|
2023-10-10 09:26:48 +00:00
|
|
|
|
2023-10-10 00:35:32 +00:00
|
|
|
echo "calling suspend for duration: $suspend_time"
|
2023-10-08 01:57:01 +00:00
|
|
|
|
2023-10-10 10:05:09 +00:00
|
|
|
start="$(date "+%s")"
|
2023-10-10 09:47:41 +00:00
|
|
|
rtcwake -m mem -s "$suspend_time" || exit 1
|
2023-10-10 10:05:09 +00:00
|
|
|
#We woke up again
|
|
|
|
time_spent="$(( $(date "+%s") - start ))"
|
|
|
|
echo "suspended for $time_spent seconds"
|
2023-10-08 01:57:01 +00:00
|
|
|
|
|
|
|
sxmo_hook_postwake.sh
|
|
|
|
|