Chuck's Code Blog

Assorted solutions and musings

Wake On LAN (WOL)

In the process of learning about the new Wake on Wireless technologies, I found myself adding some Wake On LAN (WOL) functionality to my kiosk application, I thought I would perhaps post some of that code and info here.  One of these days I will sit down and do a proper publication, but for now WordPress is still new to me and I haven’t the time that I would like to do this correctly.

Certain network cards also support a security feature called “SecureON password”. This feature allows users to set a Magic Packet password. The password is 6 bytes like the MAC address. Still, only a few NIC and router manufacturers seem to support such security features.

What do I need to use WOL?

• A network card that can support WOL with its cable to the motherboard properly installed.

• In the BIOS Power Management, you must enable the LAN Wakeup option. The option might also be named:

o Wake On LAN,                                                     o Resume on LAN,
o MAC Resume From S3/S4,                            o Resume on LAN/PME#,
o MACPME Power Up Control,                        o Wake on LAN from S5,
o Power On By Onboard LAN,                          o Wake Up On LAN,
o Power Up By Onboard LAN,                          o Wake Up by Onboard LAN,
o Resume by LAN,                                                 o WOL (PME#) From Soft-Off
o Resume By WOL,

• Then take a look at your network card settings, (right click mouse on “My Computer” icon on your desktop, select Manage -> “Device Manager”) in “Device Manager” open the properties of your “Network Card” and select “Power Management” tab. Wakeup should be also enabled as shown below.


Power Management Settings


Wake from Shutdown = On; Wake-Up Capabilities = Magic Packet.

Some network cards support additional options to wake up from shutdown.

After completing these settings, check that the “Good Connection” light (typically green led) on the back of the network card is lit when the machine is off.

Most implementations send the “magic packet” via UDP over either port 7 or port 9 .  So you’ll have to make sure that port is forwarded by your firewall/router to the IP broadcast address.


Magic packet

The magic packet is a broadcast frame containing anywhere within its payload: 6 bytes of ones (resulting in hexadecimal FF FF FF FF FF FF), followed by sixteen repetitions of the target computer’s MAC address.

Since the magic packet is only scanned for the string above, and not actually parsed by a full protocol stack, it may be sent as a broadcast packet of any network- and transport-layer protocol. It is typically sent as a UDP datagram to port 0, 7 or 9, or, in former times, as an IPX packet.



using System;
using System.Net;
using System.Net.Sockets;
namespace WakeOnLan
    class Program
        static void Main(string[] args)
            byte[] mac = new byte[] {0x00, 0x0F, 0x1F, 0x20, 0x2D, 0x35};
        /// <summary>
        /// Sends a Wake-On-Lan packet to the specified MAC address.
        /// </summary>
        /// <param name="mac">Physical MAC address to send WOL packet to.</param>
        private static void WakeUp(byte[] mac)
            // WOL packet is sent over UDP
            UdpClient client = new UdpClient();
            client.Connect(IPAddress.Broadcast, 40000);
            // WOL packet contains a 6-bytes trailer and
            // 16 times a 6-bytes sequence containing the MAC address.
            byte[] packet = new byte[17 * 6];
            // Trailer of 6 times 0xFF.
            for (int i = 0; i < 6; i++)
                packet[i] = 0xFF;
            // Body of magic packet contains 16 times the MAC address.
            for (int i = 1; i <= 16; i++)
                for (int j = 0; j < 6; j++)
                    packet[i * 6 + j] = mac[j];
            // Submit WOL packet.
            client.Send(packet, packet.Length);


November 11, 2009 Posted by | UMPC | , | 2 Comments

Button Map for the Samsung Q1-Ultra UMPC.

I’m working on a home automation project that involves amongst other things creating a software application that operates on Windows XP Tablet Edition running on a touchscreen-enabled Samsung Q1-Ultra Ultra Mobile Personal Computer (or UMPC).

One of the requirements of this application is that the UMPC will operate in a kiosk mode – okay simple enough, [perhaps I’ll post some information on accomplishing this by trapping certain key combinations and using the Windows Group Policy Editor if anyone is interested] but for this article the question is, “How do I disable some of the hardware buttons on the computer?”

We still want some of the hardware buttons to be available to the user.  Buttons such as “Vol-“, “Vol+”, as well as the traditional keyboard characters will be very useful, so we don’t want to disable them.  Other buttons will come in quite handy for purposes other than their intended uses, for example the arrow up and arrow down buttons on the user pad to the right will provide the user with handy Volume Up and Volume Down buttons (the Vol- and Vol+ buttons are used to control the volume locally on the UMPC where as these arrow up and arrow down buttons will send a control code to the AMX brain that will in-turn adjust the actual source volume for the various routed zones.

The first step of this task after determining the list of which hardware buttons we need to control or disable, is to identify how the system addresses these hardware keys.  I wrote a simple application that hooked into the low-level keyboard handler and trapped all values that came through.  From there I was able to create a table that shows for each hardware button what the BIOS key value is in both Hex and Decimal as well as the constants defined for those values in the Windows API WinUser.DLL library file and the .NET Windows.Forms.Key Keys enumerator.  Both of these are necessary because I wanted to trap some key codes in a dll and utilize some of the keys within the managed C# application.

Below I have provided the table showing the button mappings and the buttons’ relative positions on the UMPC.

Q1-U_Left Q1-U_Right

Button BIOS (Hex) BIOS (Dec) Windows (Hex) WinUser DLL Constant .Windows.Forms.Key
▲ Up
0x58 088 0xFF VK_X Keys.X
▼ Down 0x59 089 0xFF VK_Y Keys.Y
◄ Left
0x56 086 0xFF VK_V Keys.V
► Right 0x57 087 0xFF VK_W Keys.W
Internet 0x32 050 0xAC VK_2 Keys.D2
Menu 0x54 084 0xFF VK_T Keys.T
UDF 0x6E 110 0xFF VK_DECIMAL Keys.Decimal
Q \ AV 0x74 116 0xFF VK_F5 Keys.F5
Shutter 0x64 100 0xFF VK_NUMPAD4 Keys.NumPad4

One of the biggest concerns was the Internet button.  In a kiosk-type application that does not use the Internet, this button is a huge security hole in that people could launch Internet explorer and in the address bar use “File///…” and access anything within the UMPC.  It was a relief to me when I discovered that Samsung had used a standard keyboard key for the number 2 (above the Q and W on a QWERTY keyboard).  This meant there is a way to trap for that keystroke and prohibit it from launching the (in this case) Internet Explorer application.

November 4, 2009 Posted by | UMPC | , , , , | Leave a comment