Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Previous section Next section Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Topic:
UDP Socket implementation and WOL
This thread has 8 replies. Displaying all posts.
Post 1 made on Thursday September 30, 2010 at 12:11
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
The UDP Socket implementation in the latest firmware has a bug. It will not send a subnet broadcast message but will error out. This is confirmed by Philips and will probably not be fixed since there is a simple workaround (Which I suggested they document).

Background:

In the offical WOL documentation it states that the magic packet is to be sent to the subnet broadcast address. A subnet broadcast address is formed by first and'ing the subnet IP address with the subnet mask producing the network portion of the address then or'ing in an all ones pattern for the host address field. The host address field of the IP address is determined by and'ing the IP address with the compliment of the subnet mask. For most LAN's encountered in residences the mask is 255.255.255.0. This is 24 bits of subnet address and 8 bits of host address. for example if a device is sitting on 192.168.1.x with an IP address of 192.168.1.203 then the proper subnet broadcast address to send a WOL magic packet to is 192.168.1.255.

Unfortunately this will throw an error when used with a UDP socket on the Pronto.

There are a set of predefined multicast addresses that all hosts on a network are obligated to accept. The Address "224.0.0.1" is defined as "All Hosts on this subnet". Sending a WOL magic packet to that IP address will cause it to be seen by every host on the same subnet as the sender. The UDP implementation in the latest firmware allows you to send to that UDP address.

I believe (Have not tested but am 99% sure) that the magic packet can be sent directly to the devices IP address. The only thing the Magic packet needs is to be accepted by the devices NIC and a message sent directly to the device should be accepted.

The device's NIC then verifies its MAC address against the one in the packet to determine if the WOL is for it. Based on BIOS settings it will then either wake up the machine or disregard the message

Since UDP is a best effort delivery protocol unlike TCP which is guaranteed delivery, I send the message multiple (40) times. 40 May be overkill but it will not hurt as I do it so rarely.

Last edited by Barry Gordon on September 30, 2010 18:36.
Post 2 made on Thursday September 30, 2010 at 21:58
2Many
Long Time Member
Joined:
Posts:
September 2009
106
I 'think' the subnet is only required if trying to wake a PC on another network. But that is based on PC to PC WOL.

If the Pronto is sending a WOL command to a device on the same LAN, should it actually require the subnet address?



On September 30, 2010 at 12:11, Barry Gordon said...
I believe (Have not tested but am 99% sure) that the magic packet can be sent directly to the devices IP address. The only thing the Magic packet needs is to be accepted by the devices NIC and a message sent directly to the device should be accepted.

I presume you mean the Broadcast IP address and not the individual device IP addresses. If a PC is in the Powered-Off state, it doesn't have an IP address. The IP address is provided by the operating system or router.


When it comes to networking the Pronto could be better. I've had to downgrade my router Wifi security to WPA. I have to broadcast my SSID, and my Pronto doesn't appear to like DHCP. This all had a knock-on effect on all the other WiFi devices in my home.

The addition of UDP was great for me, WOL is working fine. Hammering on the network 40 times does seem excessive. This must have an effect on the Pronto battery? Hope your solution improves things.



Slightly off topic (but still might be useful in WOL trouble-shooting), but there seems to have been a slight change in getting a NIC to accept a WOL command.

I'd been using WOL for many years. WOL used to be enabled by default in a NIC. The only thing required was to enable the wake-up event in the BIOS. This appears to have changed in recent years, by default WOL seems to be disabled in a NIC.

To access the NIC's WOL setting(s) I have to use Device Manger in Windows (Device Manager > Network Adapter > Advanced > Wake Up). There may be more than one property that has to be configured to enable WOL but that's where the settings are.

I guess the default disabling of WOL on a NIC is a security measure.
"Home" is where my Pronto is.
OP | Post 3 made on Thursday September 30, 2010 at 22:33
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
You are probably correct re the device address. It will probably respond in a sleep state but not in a full power off state. One of these days I will try it. The "224.0.0.1" does always work.

When you say no subnet address do you mean "000.000.000.255" I am not sure that will work.

Since 224.0.0.1 always seems to work I thionk I will just stick with that.

I do the send (socket.write) in an if clause repeating 40 times. I think that 5 would be good enough, but if the network is busy streaming video maybe not. It is very low overhead since the connect occurs before the loop and the close and socket to null after the loop. It just blasts out the packets as fast as the NIC/Pronto can.
Post 4 made on Friday October 1, 2010 at 00:27
2Many
Long Time Member
Joined:
Posts:
September 2009
106
I meant subnet as in the example from your first post - the address 192.168.1.255 - the broadcast IP address.

Tried out WOL with sleep and hibernate, no luck so far. Research required.
"Home" is where my Pronto is.
OP | Post 5 made on Friday October 1, 2010 at 08:42
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
What I documented works well for me. When I get back on monday I will put it into a library, test it out and post it on my web site.

I am using it on an Asrock ION 330 on which I am running xbmc. As you stated in your post it is sometimes a bit involved to get a pc properly configured (BIOS OS, NIC)
Post 6 made on Friday October 1, 2010 at 09:17
sWORDs
Long Time Member
Joined:
Posts:
November 2006
373
//WakeupOnLan function wakes up devices that are in G2 (S5) state or
//lower and set to respond on magicpacket, on UDP port 7. Wake On
//Wireless LAN compatible WIFI adapters will work only in S3 (sleep) or
//S4 (hibernate) state.

//Parameter a = MACADDRESS ("e0:cb:4e:df:8d:0b" or "E0-CB-4E-DF-8D-0B" or
//"e0cb4edf8d0b") Optional Parameter e = MULTICASTADDRESS. Only needed for cross
//subnet, defaults to all hosts multicast group (224.0.0.1) when omitted.
//Please note that on current firmware broadcast addresses (255) do not work.


WakeupOnLan=function(a,e
){
    if(a.length==17){

        b=String.fromCharCode(parseInt(a.substr(0,2),16),parseInt(a.substr(3,2),16),
        parseInt(a.substr(6,2),16),parseInt(a.substr(9,2),16),
        parseInt(a.substr(12,2),16),parseInt(a.substr(15,2),
16));
    }
    else if(a.length==12){
        b=String.fromCharCode(parseInt(a.substr(0,2),16),parseInt(a.substr(2,2),16),
        parseInt(a.substr(4,2),16),parseInt(a.substr(6,2),16),
       
parseInt(a.substr(8,2),16),parseInt(a.substr(10,2),
16));
    }
    
else{Diagnostics.log("WOL failed: Incorrect MAC ADDRESS");return;}
    c="\xff";
   
d=c+c+c+c+c+c+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b;
   
if(arguments.length==1){e="224.0.0.1";}
    f=new UDPSocket();f.send(d,e,7);f.send(d,e,7);f.send(d,e,7);f.close();f=null;
};
WakeupOnLan("e0:cb:4e:df:8d:0b"); //or E0-CB-4E-DF-8D-0B or e0cb4edf8d0b

Or the function compacted:

WakeupOnLan=function(a,e){if(a.length==17){b=String.fromCharCode(parseInt(a.substr(0,2),16),parseInt(a.substr(3,2),16),parseInt(a.substr(6,2),16),parseInt(a.substr(9,2),16),parseInt(a.substr(12,2),16),parseInt(a.substr(15,2),16));}else if(a.length==12){b=String.fromCharCode(parseInt(a.substr(0,2),16),parseInt(a.substr(2,2),16),parseInt(a.substr(4,2),16),parseInt(a.substr(6,2),16),parseInt(a.substr(8,2),16),parseInt(a.substr(10,2),16));}else{Diagnostics.log("WOL failed: Incorrect MAC ADDRESS");return;}c="\xff";d=c+c+c+c+c+c+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b;if(arguments.length==1){e="224.0.0.1";}f=new UDPSocket();f.send(d,e,7);f.send(d,e,7);f.send(d,e,7);f.close();f=null;};

All Hosts multicast group is what works for me (Tnx, Barry). All other multicast and broadcast addresses fail, also destination ip.

One good tip for bios configuration is that modern motherboards have the NIC on PCIe, so sometimes the setting you're looking for is called PCIe event.

edit: function adjusted based on the comments below!

Last edited by sWORDs on October 4, 2010 05:03.
OP | Post 7 made on Saturday October 2, 2010 at 14:50
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
What sWords has done is in line with what I suggested with one exception, he sends the WOL packet once. That will work almost all the time, unless there is some sort of network collision/issue, I suggest sending it more than once, 5 will probably be enough. Just put the send command inside a for loop running from 1 to 5. I do not believe the close of the socket will free it up (I am not sure) so I also do socket=null; after the close. In that way I do not run up against any active socket limitations.

I am not sure there should be a blank between the 6 flag bytes of \xff and the mac address iteration. It might work in some cases but not in others depending on how the NIC logic was implemented. I am pretty sure the Magic packet spec does not call for a blank at that position in the message, but I could be wrong.

I will probbaly adopt your function with changes as I noted above, as it is a little tighter than what I use
Post 8 made on Sunday October 3, 2010 at 07:26
sWORDs
Long Time Member
Joined:
Posts:
November 2006
373
That blank isn't intended, it's just a typo. It does work with the blank on several NICs (nVidia, Realtek, Broadcom and Intel). I don't like loops, they seem slower if you don't do a lot, so when they're simple I rather type it out. We've talked about UDP before and I know you don't like UDP, but I use UDP for a lot of stuff and I never ever missed a frame, I do use professional network gear but the main router is a simple tplink with DDWRT. To be safe sending it two or three times isn't a bad idea. Setting the socket to null is a great tip. I also thought that it might be handy to accept all forms of MAC's.

Barry thanks for the All Hosts multicast group tip, I would have never got it working without it!

I've adjusted the function so it does it all.

//WakeupOnLan function wakes up devices that are in G2 (S5) state or
//lower and set to respond on magicpacket, on UDP port 7. Wake On
//Wireless LAN compatible WIFI adapters will work only in S3 (sleep) or
//S4 (hibernate) state.

//Parameter a = MACADDRESS ("e0:cb:4e:df:8d:0b" or "E0-CB-4E-DF-8D-0B" or
//"e0cb4edf8d0b") Optional Parameter e = MULTICASTADDRESS. Only needed for cross
//subnet, defaults to all hosts multicast group (224.0.0.1) when omitted.
//Please note that on current firmware broadcast addresses (255) do not work.

WakeupOnLan=function(a,e
){
    if(a.length==17){

        b=String.fromCharCode(parseInt(a.substr(0,2),16),parseInt(a.substr(3,2),16),
        parseInt(a.substr(6,2),16),parseInt(a.substr(9,2),16),
        parseInt(a.substr(12,2),16),parseInt(a.substr(15,2),
16));
    }
    else if(a.length==12){
        b=String.fromCharCode(parseInt(a.substr(0,2),16),parseInt(a.substr(2,2),16),
        parseInt(a.substr(4,2),16),parseInt(a.substr(6,2),16),
       
parseInt(a.substr(8,2),16),parseInt(a.substr(10,2),
16));
    }
    
else{Diagnostics.log("WOL failed: Incorrect MAC ADDRESS");return;}
    c="\xff";
   
d=c+c+c+c+c+c+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b;
   
if(arguments.length==1){e="224.0.0.1";}
    f=new UDPSocket();f.send(d,e,7);f.send(d,e,7);f.send(d,e,7);f.close();f=null;
};
WakeupOnLan("e0:cb:4e:df:8d:0b"); //or E0-CB-4E-DF-8D-0B or e0cb4edf8d0b

Or the function compacted:

WakeupOnLan=function(a,e){if(a.length==17){b=String.fromCharCode(parseInt(a.substr(0,2),16),parseInt(a.substr(3,2),16),parseInt(a.substr(6,2),16),parseInt(a.substr(9,2),16),parseInt(a.substr(12,2),16),parseInt(a.substr(15,2),16));}else if(a.length==12){b=String.fromCharCode(parseInt(a.substr(0,2),16),parseInt(a.substr(2,2),16),parseInt(a.substr(4,2),16),parseInt(a.substr(6,2),16),parseInt(a.substr(8,2),16),parseInt(a.substr(10,2),16));}else{Diagnostics.log("WOL failed: Incorrect MAC ADDRESS");return;}c="\xff";d=c+c+c+c+c+c+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b+b;if(arguments.length==1){e="224.0.0.1";}f=new UDPSocket();f.send(d,e,7);f.send(d,e,7);f.send(d,e,7);f.close();f=null;};

Last edited by sWORDs on October 4, 2010 05:03.
Post 9 made on Monday November 21, 2011 at 13:53
menino
Long Time Member
Joined:
Posts:
September 2004
141
Hi all,
I have a MAC address that contains a "00".

And this function does not work with 00 in the MAC address, as String.fromCharCode(0) returns NULL and so the resulting string is invalid.

How should I change the function in order to remove this limitation?

thanks

EDIT: Sorry the problem is not the "00". It seems it's the router that do not broadcast the magic packet.

Last edited by menino on November 22, 2011 12:24.


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse