#!/bin/bash

# Om WoL te laten werken, moet aan 3 eisen voldaan zijn:
# 1) het moet in de BIOS ingeschakeld staan
# 2) de netwerkdriver moet WoL accepteren
# 3) de ACPI layer moet een wakeup accepteren

# Ad 1) in de BIOS aanpassen

# Ad 2) Dit is met ethtool uit te lezen en in te stellen

# ethtool eth0
# Settings for eth0:
#        Supported ports: [ TP MII ]
#        Supported link modes:   10baseT/Half 10baseT/Full 
#                                100baseT/Half 100baseT/Full 
#        Supports auto-negotiation: Yes
#        Advertised link modes:  10baseT/Half 10baseT/Full 
#                                100baseT/Half 100baseT/Full 
#        Advertised auto-negotiation: Yes
#        Speed: 100Mb/s
#        Duplex: Full
#        Port: MII
#        PHYAD: 1
#        Transceiver: internal
#        Auto-negotiation: on
#        Supports Wake-on: pg
#        Wake-on: d
#        Current message level: 0x000000c5 (197)
#        Link detected: yes

#      wol p|u|m|b|a|g|s|d...
#             Set Wake-on-LAN options.  Not all  devices  support  this.   The
#             argument  to  this  option  is a string of characters specifying
#             which options to enable.
#             p  Wake on phy activity
#             u  Wake on unicast messages
#             m  Wake on multicast messages
#             b  Wake on broadcast messages
#             a  Wake on ARP
#             g  Wake on MagicPacket(tm)
#             s  Enable SecureOn(tm) password for MagicPacket(tm)
#             d  Disable (wake on nothing).  This option clears  all  previous
#                options.

# deze netwerkkaart staat na een boot op wol disabled 
# en kan op phy en magic gezet worden.

/usr/sbin/ethtool -s eth0 wol g
 
# Ad 3) lees /proc/acpi/wakeup uit en initieer het zonodig.

if (grep PCI0 /proc/acpi/wakeup | grep disabled 2>&1 >> /dev/null) ; then
    echo -n PCI0 > /proc/acpi/wakeup
fi

