Send Wake on Lan (WoL) request manually through the ethernet cable using an Arduino or Raspberry Pi

arduinoethernetnetworkingraspberry piwake-on-lan

I'm trying to make a circuit that "intercepts" the ethernet cable before it enters the computer, allowing me to send a "Magic Packet" through the cable manually – by the press of a button for example.

As far as I could gather, to make Wake on Lan happen, you must send 6 bytes of 255 (FF FF FF FF FF FF in hexadecimal), followed by sixteen repetitions of the target computer's MAC adress – total of 102 bytes. (source: Wikipedia). I'm just having a hard time figuring out how to send this magic packet manually, not through the router (if it's even possible).

The sketch below illustrates what I'm trying to do.

Rough sketch

An ethernet cable has 8 wires, the interesting ones for this probably being no. 1, 2, 3 and 6 – TX+, RX-, RX+ and RX- (illustration).

I'm trying to determine how this specific serial protocol works, and how to use it in practice on a development-board like Arduino. This website says it can either be "RS423" or "RS422".

So my question is; is it possible to do what I'm trying to do? And if so, how do I go about sending the Magic Packet correctly?

Best Answer

As you wrote, a WoL magic packet (frame) contains the sequence anywhere in its data stream.

Usually, the WoL packet is sent using a higher-layer protocol since it's easier to do. Simply send a UDP packet (any port is possible, 0, 7 or 9 is customary) containing the sequence to broadcast address 255.255.255.255.

Good luck on encoding the Ethernet stream though - it's not as simple as RS422/423.

Before line encoding you need to build an Ethernet frame preceded by the preamble/SOF sequence, then the frame header (use Ethertype 0x0842) followed by the magic pattern. Depending on the WoL mechanism, you'll probably need to pad the frame to its minimal size (64 w/o preamble/SOF) and calculate the correct frame check sequence (FCS).

The frame then needs to be line encoded. 10BASE-T uses simple Manchester code (01="1" and 10="0"). 100BASE-TX uses 4b/5b line code. 1000BASE-T uses a much more complicate line code that's probably outside your project's scope. Most probably the WoL link is 10BASE-T, so that's doable. If you can't take over an existing WoL link you'll also need to generate regular link pulses to make the far side "link up".

All in all, it'll be much easier to wake the hardware using another method if you don't need to do it over the network cable.

If you're using an Ethernet node to generate the WoL packet you can just connect it anywhere in your network, on any switch port. Simply broadcasting the packet will send it to all linked nodes, including the selected MAC.