# Wake on LAN



## trutlze (Jan 6, 2012)

Hi,

I want to shutdown my FreeBSD-Server and start it over LAN via Wake on LAN. But it doesn't work.

I set sysctl-variable dev.re.0.wake to 1 . I shut down the server with `# shutdown -p now`. Then I tried `# wake INTERFACE SERVERNAME` or `# wakeonlan SERVER-NIC-MAC` on a client on the same net, but nothing happened.


*Hardware*
*Mainboard*: ASUS E35M1-I
OnBoard *CPU*: AMD E-350
OnBoard *NIC*:

```
re0: <RealTek 8168/8111 B/C/CP/D/DP/E PCIe Gigabit Ethernet> port 0xe000-0xe0ff mem 0xd0004000-0xd0004fff,0xd0000000-0xd0003fff irq 17 at device 0.0 on pci4
re0: Using 1 MSI messages
re0: Chip rev. 0x2c000000
re0: MAC rev. 0x00000000
```

*Software*
BIOS Version: 0401 x64 from 3/18/2011
FreeBSD 8.2-RELEASE-p5 amd64 from Sun Jan 1 2012

[CMD=""]ifconfig[/CMD] shows this:

```
re0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=389b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_UCAST,WOL_MCAST,WOL_MAGIC>
```

So I suppose WoL is supported on this NIC with this driver.

In BIOS there is no option to turn WoL on or off, but I found several sites that claimed that this board supports WoL. When the server is turned off, there is no active light on LAN-port. So maybe the NIC isn't waiting for WoL-packets?

Do you have any suggestions?


----------



## wblock@ (Jan 6, 2012)

trutlze said:
			
		

> Hi,
> 
> I want to shutdown my FreeBSD-Server and start it over LAN via Wake on LAN. But it doesn't work.
> 
> I set sysctl-variable dev.re.0.wake to 1 .



That OID doesn't exist on 8-STABLE.  But I've never needed it, either.



> I shut down the server with `# shutdown -p now`. Then I tried `# wake INTERFACE SERVERNAME`



INTERFACE is the interface to use for sending the magic packet.  SERVERNAME as a name only works if it has been added to /etc/ethers.  Otherwise, it's the MAC address of the system to wake.

For example, sending from a system that has an Intel Ethernet card:
`# wake em0 00:1a:21:5c:b1:71`



> `# wakeonlan SERVER-NIC-MAC` on a client on the same net, but nothing happened.



The FreeBSD command is just wake.


----------



## trutlze (Jan 6, 2012)

Thanks for your reply. What you described is what I've done. I just used those wildcards to not "reveal" my MACs/Names/etc.


----------



## wblock@ (Jan 6, 2012)

Okay, one other point: the FreeBSD driver on the target system should not matter at all.  That system is off, and the Ethernet interface and BIOS are in charge.  So either the packet is not arriving, or the card or BIOS are not reacting to it.


----------



## trutlze (Jan 7, 2012)

That's what I feared. I sent the WoL-packets while the target system was up and doing a tcpdump. And the packet arrived. So I have to ask ASUS-guys ...

As far as I understand the WoL-thingy the OS and driver is the instance that tells the NIC to stay in a listening mode after the system shut down. Thus the driver on the target system has a certain relevance.


----------



## wblock@ (Jan 7, 2012)

trutlze said:
			
		

> That's what I feared. I sent the WoL-packets while the target system was up and doing a tcpdump. And the packet arrived. So I have to ask ASUS-guys ...
> 
> As far as I understand the WoL-thingy the OS and driver is the instance that tells the NIC to stay in a listening mode after the system shut down. Thus the driver on the target system has a certain relevance.



That would make sense if the system is in sleep, not off.  But I've got a system right here that will wake up (WOL) even after the power cord has been disconnected.  Well, and reconnected.

It's possible the packet isn't right to wake up that system.  Have you tried other operating systems like a Linux live CD to wake it?  Most likely is still BIOS settings or bugs, though.


----------



## yongari@ (Jan 12, 2012)

It seems your controller is RTL8168E PCIe gigabit ethernet. There was a bug in re(4) where WOL on recent controllers like RTL8168E may not work.  This was fixed in stable/[7-9] so try latest stable release. Alternatively, you can apply the patch from the following URL.
http://svnweb.freebsd.org/base/head/sys/dev/re/if_re.c?r1=227843&r2=227850&view=patch


----------



## Talisker (Jan 14, 2012)

Hi, I've got an E35M1-M PRO (Realtek 8111E according to asus.com) with the same problem.

Setup:

FreeBSD 9.0-RELEASE with or without the patch that yongari references applied (makes no difference).


```
re0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=389b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_UCAST,WOL_MCAST,WOL_MAGIC>
```
Wake on LAN doesn't work.

On the same hardware and the same wake-up host it works fine with Ubuntu 11.10, so it ought to be something FreeBSD specific.

Any suggestion/advice would be most welcome.

Thanks,
Torsten


----------



## wblock@ (Jan 14, 2012)

I would like to understand how the operating system affects this.  Is there nonvolatile memory in the Ethernet board, or maybe a volatile setting that remains after shutdown as long as the system has standby power?


----------



## yongari@ (Jan 15, 2012)

According to the ifconfig output you posted, you didn't correctly apply the patch.  If you applied the patch correctly, you should not see WOL_UCAST and WOL_MCAST capabilities because I intentionally disabled them in the patch.
So make sure to rebuild/reboot kernel after applying the patch. Instead of just saying WOL works on Linux, elaborating on what you did on FreeBSD would get more chances to get answers from other users/developers in this forum.


----------



## yongari@ (Jan 15, 2012)

The behavior highly depends on WOL implementation of controller.  For controllers that support automatic wake functions, driver may not need any programming for the controller to make WOL work.  This feature even works when system get power again after power lost.  However, if you changed controller's station address to other one rather than using factory default one, automatic wakeup via WOL wouldn't work. Also driver will make controller to use 10/100Mbps link to save power with WOL. If automatic wakeup function is used after power lost, the link speed chosen for WOL may or may not be 10/100Mbps link.


----------



## Talisker (Jan 16, 2012)

yongari@ said:
			
		

> According to the ifconfig output you posted, you didn't correctly apply the patch.  If you applied the patch correctly, you should not see WOL_UCAST and WOL_MCAST capabilities because I intentionally disabled them in the patch.
> So make sure to rebuild/reboot kernel after applying the patch. Instead of just saying WOL works on Linux, elaborating on what you did on FreeBSD would get more chances to get answers from other users/developers in this forum.



First: I don't know why you think it's appropriate to be rude. It isn't.

I did apply the patch correctly and did an *ifconfig re0 wol* just to make sure I don't miss any WOL packet. That's why WOL_UCAST and WOL_MCAST are in there.

And what exactly do you want me to elaborate on? I'm more than happy to supply any relevant information but WOL is pretty basic after all.

Boot up machine, check WOL_MAGIC is active for re0, turn off machine, try to wake it up. Works in Linux, works in Windows 7, doesn't work in FreeBSD. Anything I'm missing here?


----------



## yongari@ (Jan 16, 2012)

Ah, I see. Now I can understand why you have both WOL_UCAST and WOL_MCAST capabilities are enabled.  The patch disables them by default but it will still allows them to be configured if user explicitly wants the feature and you explicitly enabled all WOL features. WOL_MAGIC is enabled by default so you don't have to issue ifconfig command again to enable wakeup via magic packet and 'wol' option of ifconfig means WOL_UCAST, WOL_MCAST and WOL_MAGIC.

There are also a couple of WOL related changes but I thought r227850 would be minimal one that makes WOL work on recent RealTek controllers.  Your experiment indicates my assumption was wrong.  Given that r227850 didn't work, would you try latest stable/9 on your box? Also it would be good to know what kind of controller you have.  Just post re(4) related message from the dmesg output.


----------



## Talisker (Jan 17, 2012)

Thanks for looking into this further.

I've just upgraded the kernel (not userland) to 9.0-STABLE as of today. if_re.c is revision 1.198.2.5.

Unfortunately Wake on LAN still doesn't work.

The board is an ASUS E35M1-M PRO with a Realtek 8111E according to the specs at asus.com.

This is what dmesg says about re0:


```
re0: <RealTek 8168/8111 B/C/CP/D/DP/E/F PCIe Gigabit Ethernet> port 0xe000-0xe0ff mem 0xd0004000-0xd0004fff,0xd0000000-0xd0003fff irq 17 at device 0.0 on pci4
re0: Using 1 MSI-X message
re0: Chip rev. 0x2c000000
re0: MAC rev. 0x00000000
miibus0: <MII bus> on re0
re0: Ethernet address: bc:ae:c5:cb:d4:25
```

If I can be of any further assistance then please let me know.


----------



## yongari@ (Jan 19, 2012)

Thanks for the information. Your controller is RTL8168E so I tried to reproduce the issue with RTL8168E sample board. I was successfully able to reproduce the issue.  It seems there was a logic error in the driver such that WOL on some controllers didn't work as expected.  Please try the patch at the following URL and let me know how it goes on your box. Since you already use latest stable/9, just apply the patch and rebuild/reboot kernel.
http://people.freebsd.org/~yongari/re/re.wol.diff


----------



## Talisker (Jan 19, 2012)

Thank you very much, that patch works!

It also works with 9.0-RELEASE when applying both of your patches in this thread.

And just to clarify things for everyone: *ifconfig re0 wol* and *sysctl dev.re.0.wake=1* are both NOT required. WOL works out of the box for me with these patches.


----------



## yongari@ (Jan 19, 2012)

Thanks a lot for testing.
Patch committed to HEAD(r230336) will MFC the change after settlement.


----------



## trutlze (Jan 23, 2012)

Thanks for the patches. It's working now.

Here's what I did step-by-step:

1. Getting sources for RELENG_9_0 with csup (Handbook: A.6 Using CVSup)
2. `# cd /usr/src/sys/dev/re`
3. fetching both patches (fetch(1))
4. create a backup-copy of if_re.c
5. applying both patches (patch(1))
6. building world & kernel, installing kernel & world (Handbook: 25.7 Rebuilding "world")


After updating went fine, I shutdown the system and woke it up again (the system was still plugged into the wall). I wasn't able to wake it up after completely removing current. So the WoL-settings seem to be stored on volatile memory.

The BIOS-setting that needs to be enabled is called "Advanced\ APM\ Power On By PME".


----------



## shulfei (May 28, 2016)

Hi all.
Help me if it possible.

```
FreeBSD 10.3
re0: <RealTek 8168/8111 B/C/CP/D/DP/E/F/G PCIe Gigabit Ethernet> port 0xe000-0xe0ff mem 0xf7e00000-0xf7e00fff,0xf0100000-0xf0103fff irq 16 at device 0.0 on pci1
```
`tcpdump -i re0 -x port 9` show me that packets arrived.
I successfully wake up host machine after poweroff.
But only in 2 minutes period after poweroff.
If period more than 2 minutes, host does not wake up.

Patches not applying, don't understand how.

```
/usr/src/sys/dev/re: No such file or directory
```


----------

