Wake-On-Lan for Android

Preface

For background information about WOL, please check wikipedia:
https://en.wikipedia.org/wiki/Wake-on-LAN

The flow is: someone sends an OSI Level-2 magic packet, which contains magic header (ff ff ff ff ff ff), following by MAC addresses of target platforms.
Normally this is done by BIOS and NIC firmware, which can receive the magic packet on standby, and can power on the platform when receive the packet.
Strictly speaking, any L2 magic packet is allowed to serve as a wake up packet, but most wake up clients use UDP and discard port (port 9).

Android WakeOnLan

  1. Andorid has standard Linux suspend state,

it can enter this state by “echo mem > /sys/power/state”.
In this state, system follows standard WOL flow, NIC firmware or some low level module needs to listen to network data and wake up system.

  1. Android also has an intermediate state between awake and suspend

Android is sleeping after a call to PowerManager.goToSleep(), but sometimes application still holds wakelock, which blocking the system enters real Linux suspend state. We call it Android sleeping mode.
In this mode all userspace processes are alive, WOL features can only be implemented by user space applications.

Points need to be taken care of

  1. process needs to listen to UDP port 9 for most wake up clients. This needs the process running as root (user 0).

  2. To be more compitible, process needs to open a RAW_SOCKET to listen to all port packets, only root progresses written in C can do this. Or use JNI to call native C code.

  3. In selinux enforcing mode, additional rules are required.

  4. CTS DO NOT allow port listening.
    Android CTS case: android.security.cts.ListeningPortsTest
    We can overcome this issue by closing the listening daemon when SCREEN_ON(“android.intent.action.SCREEN_ON”), and start the listening daemon when SCREEN_OFF(“android.intent.action.SCREEN_OFF”).

Implementation

In wireshark WOL section, it recommends:

ether proto 0x0842 or udp port 9

To be more generic, we wil use:

ether proto 0x0842 or udp

TBD