# Wake on Lan doesn't work from shutdown scripts...

## Elton

I posted a message some months ago about a problem with wake on lan, but no one knew the solution back then. So here's another shot.

I have a asus a7n8x motherboard, with integrated ethernet (nvidia 

chipset...).

For Wake on Lan to work, it is required that the network interface is in 

the proper power condition before the computer is turned off.

I use the pci-config tool from scyld.com. This takes care of the right 

powercondition.

Ok, here follow some diagnostics:

* If the computer shuts down from windows, Wake on Lan works 

* If the computer is shut down from Linux with the following commands:

pci-config -#12 -S (for bringing the card in sleep condition)

sleep 10

/sbin/halt -dfi

the machine shuts down and powers up properly with WOL. Now this is not 

desirable, because halt -dfi shuts down the machine immediately, without 

killing jobs, or umounting disks  :Crying or Very sad: 

* The goal is obviously to run pci-config just before /sbin/shutdown calls 

halt. (Is done in the shutdown scripts /etc/init.d/halt.sh and 

/etc/init.d/shutdown.sh)

If I put the above commands in /etc/init.d/shutdown.sh, the machine shuts 

down but won't wake up again  :Shocked: 

Anyone has a solution?

----------

## grant.mcdorman

I would suspect that the ethernet driver is responsible for this; I know that for a non-integrated NIC on a system I have, a driver option will enable wake-on-lan. Check the documentation for your driver, or - if all else fails - Use The Source, Luke ... err, Elton  :Wink: 

----------

## b0fh

I'm having a similar problem with my PC. I've got an RealTek RTL8139 controller, when I shutdown with windows, it wakes up fine, but it does nothing when shut down from linux... any ideas?

----------

## Elton

Hi,

I got it solved.

You probably should do two things:

get pci-config from:

ftp://ftp.scyld.com/pub/diag/pci-config.c

and compile it, copy to /sbin/

Get the output of lspci -v, find your netwerkcard's PCI id.

run pci-config. It gives you something like:

pci-config.c:v2.03 4/15/2002 Donald Becker (becker@scyld.com)

http://www.scyld.com/diag/index.html

Device #1 at bus 0 device/function 0/0, 01e010de.

Device #2 at bus 0 device/function 0/1, 01eb10de.

Device #3 at bus 0 device/function 0/2, 01ee10de.

Device #4 at bus 0 device/function 0/3, 01ed10de.

Device #5 at bus 0 device/function 0/4, 01ec10de.

Device #6 at bus 0 device/function 0/5, 01ef10de.

Device #7 at bus 0 device/function 1/0, 006010de.

Device #8 at bus 0 device/function 1/1, 006410de.

Device #9 at bus 0 device/function 2/0, 006710de.

Device #10 at bus 0 device/function 2/1, 006710de.

Device #11 at bus 0 device/function 2/2, 006810de.

Device #12 at bus 0 device/function 4/0, 006610de.

Device #13 at bus 0 device/function 6/0, 006a10de.

Device #14 at bus 0 device/function 8/0, 006c10de.

Device #15 at bus 0 device/function 9/0, 006510de.

Device #16 at bus 0 device/function 30/0, 01e810de.

[21:38 0.04]

In my case, lspci returns 00:04.0 for the ethernet card, corresponding to device number 12 in pci-config. (device/fn 4/0)

Now, in net.eth0, comment out the line  

              /sbin/ifconfig ${IFACE} down >/dev/null

[this line is close to the end of the iface_stop() function]

Finally, in the the /etc/init.d/shutdown.sh, add the next 2 lines:

pci-config -#12 -S   ### Replace 12 with the proper device number

sleep 5

BEFORE the halt command.

That should do it.

I only tested the configuration with fixed ip. If you use dhcp you'd probably don't want to run dhcpcd -z as well, but I guess you have to find out yourself.

The idea is that the pci-config puts the device in low-power mode. 

The "ifconfig down" command somehow prevents the card from receiving the packages while the machine is off.

I'd like to know whether you're successful or not!  :Wink: 

----------

## b0fh

My biggest problem at the moment is that pci-config doesn't compile with 2.6.0...  :Sad: 

----------

## Elton

O? I just switched to 2.6, and it compiles fine...

What is the error message?

Elton

----------

## b0fh

 *Elton wrote:*   

> O? I just switched to 2.6, and it compiles fine...
> 
> What is the error message?
> 
> Elton

 

A long long error  :Smile: 

```
bash-2.05b$ gcc pci-config.c -o pci-config

pci-config.c:31:30: missing terminating " character

pci-config.c:33: error: syntax error before "This"

pci-config.c:34:60: warning: multi-character character constant

pci-config.c:37: error: syntax error at '#' token

pci-config.c:38: error: stray '\' in program

pci-config.c:38:9: missing terminating " character

pci-config.c:41: error: syntax error at '#' token

pci-config.c:41: error: syntax error at '#' token

pci-config.c:55:50: missing terminating ' character

pci-config.c:55:50: warning: character constant too long for its type

pci-config.c:57:1: missing terminating " character

In file included from pci-config.c:59:

/usr/include/unistd.h:312: error: syntax error before "size_t"

/usr/include/unistd.h:318: error: syntax error before "size_t"

/usr/include/unistd.h:448: error: syntax error before "size_t"

In file included from pci-config.c:59:

/usr/include/unistd.h:538: error: syntax error before "confstr"

/usr/include/unistd.h:538: error: syntax error before "size_t"

/usr/include/unistd.h:707: error: syntax error before "size_t"

/usr/include/unistd.h:732: error: syntax error before "size_t"

In file included from pci-config.c:59:

/usr/include/unistd.h:783: error: syntax error before "size_t"

/usr/include/unistd.h:790: error: syntax error before "size_t"

/usr/include/unistd.h:800: error: syntax error before "size_t"

/usr/include/unistd.h:801: error: syntax error before "size_t"

/usr/include/unistd.h:818: error: syntax error before "size_t"

In file included from /usr/include/_G_config.h:44,

                 from /usr/include/libio.h:32,

                 from /usr/include/stdio.h:72,

                 from pci-config.c:60:

/usr/include/gconv.h:72: error: syntax error before "size_t"

/usr/include/gconv.h:88: error: syntax error before "size_t"

/usr/include/gconv.h:97: error: syntax error before "size_t"

/usr/include/gconv.h:174: error: syntax error before "size_t"

/usr/include/gconv.h:177: error: syntax error before '}' token

In file included from /usr/include/libio.h:32,

                 from /usr/include/stdio.h:72,

                 from pci-config.c:60:

/usr/include/_G_config.h:47: error: field `__cd' has incomplete type

/usr/include/_G_config.h:50: error: field `__cd' has incomplete type

In file included from /usr/include/stdio.h:72,

                 from pci-config.c:60:

/usr/include/libio.h:351: error: syntax error before "size_t"

/usr/include/libio.h:360: error: syntax error before "size_t"

/usr/include/libio.h:468: error: syntax error before "_IO_sgetn"

/usr/include/libio.h:468: error: syntax error before "size_t"

In file included from pci-config.c:60:

/usr/include/stdio.h:302: error: syntax error before "size_t"

/usr/include/stdio.h:309: error: syntax error before "size_t"

/usr/include/stdio.h:351: error: syntax error before "size_t"

/usr/include/stdio.h:355: error: syntax error before "size_t"

/usr/include/stdio.h:603: error: syntax error before "fread"

/usr/include/stdio.h:603: error: syntax error before "size_t"

/usr/include/stdio.h:609: error: syntax error before "fwrite"

/usr/include/stdio.h:609: error: syntax error before "size_t"

/usr/include/stdio.h:631: error: syntax error before "fread_unlocked"

/usr/include/stdio.h:631: error: syntax error before "size_t"

/usr/include/stdio.h:633: error: syntax error before "fwrite_unlocked"

/usr/include/stdio.h:633: error: syntax error before "size_t"

In file included from pci-config.c:61:

/usr/include/stdlib.h:137: error: syntax error before "__ctype_get_mb_cur_max"

In file included from /usr/include/sys/types.h:266,

                 from /usr/include/stdlib.h:416,

                 from pci-config.c:61:

/usr/include/bits/pthreadtypes.h:48: error: syntax error before "size_t"

/usr/include/bits/pthreadtypes.h:51: error: syntax error before "__stacksize"

In file included from pci-config.c:61:

/usr/include/stdlib.h:433: error: syntax error before "size_t"

/usr/include/stdlib.h:462: error: syntax error before "size_t"

/usr/include/stdlib.h:556: error: syntax error before "__size"

/usr/include/stdlib.h:558: error: syntax error before "__nmemb"

/usr/include/stdlib.h:567: error: syntax error before "size_t"

In file included from /usr/include/stdlib.h:578,

                 from pci-config.c:61:

/usr/include/alloca.h:33: error: syntax error before "__size"

In file included from pci-config.c:61:

/usr/include/stdlib.h:583: error: syntax error before "__size"

/usr/include/stdlib.h:739: error: syntax error before "size_t"

/usr/include/stdlib.h:743: error: syntax error before "size_t"

/usr/include/stdlib.h:812: error: syntax error before "size_t"

/usr/include/stdlib.h:815: error: syntax error before "size_t"

/usr/include/stdlib.h:819: error: syntax error before "size_t"

/usr/include/stdlib.h:822: error: syntax error before "size_t"

/usr/include/stdlib.h:830: error: syntax error before "size_t"

/usr/include/stdlib.h:834: error: syntax error before "size_t"

/usr/include/stdlib.h:841: error: syntax error before "mbstowcs"

/usr/include/stdlib.h:842: error: syntax error before "size_t"

/usr/include/stdlib.h:844: error: syntax error before "wcstombs"

/usr/include/stdlib.h:845: error: syntax error before "size_t"

In file included from pci-config.c:62:

/usr/include/sys/mman.h:58: error: syntax error before "size_t"

/usr/include/sys/mman.h:77: error: syntax error before "size_t"

/usr/include/sys/mman.h:82: error: syntax error before "size_t"

/usr/include/sys/mman.h:90: error: syntax error before "size_t"

/usr/include/sys/mman.h:95: error: syntax error before "size_t"

/usr/include/sys/mman.h:104: error: syntax error before "size_t"

/usr/include/sys/mman.h:107: error: syntax error before "size_t"

/usr/include/sys/mman.h:122: error: syntax error before "size_t"

/usr/include/sys/mman.h:130: error: syntax error before "size_t"

/usr/include/sys/mman.h:135: error: syntax error before "size_t"

pci-config.c:72:2: #error You must compile this driver with "-O"!

/usr/include/gconv.h:176: warning: array `__data' assumed to have one element

bash-2.05b$
```

----------

## Elton

 :Cool: 

Cool.

I guess there's something wrong with your copy of the source code.  :Question: 

the line

pci-config.c:31:30: missing terminating " character 

suggests that the line is not correctly ended.

How did you download the source code? If you downloaded it with a browser and then copy-paste into a file this could happen.

I guess you could download the file again with wget

wget ftp.scyld.com/pub/diag/pci-config.c

and then try again.

----------

## b0fh

I got the file with wget. Although reloading it or doing a "save link..." with mozilla gives the same error... Could somebody who has a right version tar it up or so?

----------

## Elton

Sure. If you send me a mail at ealgera@tiscali.nl I'll know your mail address, so I can reply

----------

## Rosjahh

Hey guys,

I've got the same issue with etherwake. Have you found a solution ?

EDIT: OK, ether-wake compiled fine now, but I'm getting the exact same error message that b0fh got with compiling pci-config. Have you solved that one ?

Thanks

----------

## AudioGuy223

I modified the source code slightly.  I moved the entire string (lines 31 to 57) all onto one line, and use \n instead.  It compiled perfectly for me.  Haven't fully tested it to make sure it's functional (No time right now, I'll do it when I get home), but it compiled without any problems.

You can get my modified source code at ftp://rcti.us/linux/pci-config.c

or http://rcti.us/linux/pci-config.c

----------

## dscha

@elton: this works fine, great!!! very good hint

have an another interesting issue: i plugged in an SCSI controller in (2940UW) and after that wol doesnt work any more. i checked all parameters regareding Device ids. ist fine, the controller doesnt change th pci id of teh nic. 

maybe its because of the increased power consumtion so that there is not enought left for deht NIC? 

regards 

dscha

----------

## sdct989

I was having a lot of problems with WOL, and I was about to try the above proposed solution, when I ran accross this website:

http://lkml.org/lkml/2005/2/20/63

By changing the way that my module loaded WOL worked great for me!  My /etc/modules.autoload.d/kernel-2.6 file originally looked like:

```

3c59x

```

And now looks like:

```

3c59x options=0x408

```

It has so far booted successfully using WOL 3 times now for me.  Hopefully this helps someone out there!

----------

## nic0000

 *Elton wrote:*   

> 
> 
> Get the output of lspci -v, find your netwerkcard's PCI id.
> 
> run pci-config. It gives you something like:
> ...

 

I do not understand ;-(

```

 # lspci -v

[...]

01:0c.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 02)

        Subsystem: Dell PRO/1000 MT Network Connection

        Flags: bus master, 66MHz, medium devsel, latency 64, IRQ 16

        Memory at feae0000 (32-bit, non-prefetchable) [size=128K]

        I/O ports at df40 [size=64]

        Capabilities: [dc] Power Management version 2

        Capabilities: [e4] PCI-X non-bridge device

        Capabilities: [f0] Message Signalled Interrupts: 64bit+ Queue=0/0 Enable-

```

```
 ./pci-config -a

pci-config.c:v2.05 2/23/2005 Donald Becker (becker@scyld.com)

 http://www.scyld.com/diag/index.html

Device #1 at bus 0 device/function 0/0, 25708086.

Device #2 at bus 0 device/function 2/0, 25728086.

Device #3 at bus 0 device/function 29/0, 24d28086.

Device #4 at bus 0 device/function 29/2, 24d78086.

Device #5 at bus 0 device/function 29/3, 24de8086.

Device #6 at bus 0 device/function 29/7, 24dd8086.

Device #7 at bus 0 device/function 30/0, 244e8086.

Device #8 at bus 0 device/function 31/0, 24d08086.

Device #9 at bus 0 device/function 31/1, 24db8086.

Device #10 at bus 0 device/function 31/3, 24d38086.

Device #11 at bus 0 device/function 31/5, 24d58086.

```

I cannot pair "01:0c.0" and the output of "pci-config"

Can someone help me please?

----------

## ESSO

To find your nic you shold eamine the nex bus. Try pci-config -B 1

Gives you de devices on bus 1

----------

## FrozenMist

I am also trying to get WOL to work, have tried the above but it didnt work. I have a RTL-8139 based chip - the same as b0fh, and was wondering if he had gotten it to work.

----------

## solamour

Was there any progress on it yet? I have a similar problem with A7N266-VM board with an integrated NVIDIA network card ("forcedeth" driver). I can wake it up when I shut down from Windows, but not from Gentoo. I think I tried pretty much everything I read, such as pci-config, RC_DOWN_INTERFACE="yes/no", ethtool, etc.

If I were to get a dedicated NIC, what should I get? Unlike the motherboard I used to have (A7V133), the this one doesn't seem to have the connector for WoL (built into the PCI slot??).

(Update)

https://forums.gentoo.org/viewtopic-p-5181111.html#5181111

In short, A7V133 works perfectly, but A7N266-VM works only when hibernated from Windows.

__

sol

----------

