Package: qcontrol Version: 0.4.2+svn-r40-3 Severity: wishlist Attached you can find a patch which allows the user to control the qnap Wake on LAN functionality. Please add it to your next upload of qcontrol.
Note that in order to use it, you also need a fairly recent kernel including these two commits (likely to be included in Linux 3.10): https://git.kernel.org/cgit/linux/kernel/git/davem/net-next.git/commit/?id=42e836eb4527fb635cb799a701fe4c9fe741c03a https://git.kernel.org/cgit/linux/kernel/git/davem/net-next.git/commit/?id=3871c3876f8084a2f40ba3c3fc20a6bb5754d88d (you need to enable CONFIG_MARVELL_PHY in your .config and possibly patches in order to get poweroff to work¹) Afterwards, run these commands to power off the qnap (tested with the TS-119P II only, but qnap has a list of models²) in a way that you can wake it up via the WOL magic packet afterwards: ethtool -s eth0 wol g qcontrol wakeonlan on poweroff ① http://thread.gmane.org/gmane.linux.debian.ports.arm/11933/focus=12060 ② http://wiki.qnap.com/wiki/FAQs#Q.EF.BC.9AWake_on_LAN_support_models
Index: qcontrol-0.4.2+svn-r40/ts219.c =================================================================== --- qcontrol-0.4.2+svn-r40.orig/ts219.c 2013-03-25 12:48:50.000000000 +0100 +++ qcontrol-0.4.2+svn-r40/ts219.c 2013-03-25 12:51:33.254744373 +0100 @@ -1,6 +1,7 @@ /* * Copyright (C) 2007-2008 Byron Bradley (byron.bbrad...@gmail.com) * Copyright (C) 2008, 2009 Martin Michlmayr (t...@cyrius.com) + * Copyright (C) 2013 Michael Stapelberg (michael+q...@stapelberg.de) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,6 +33,15 @@ #include "picmodule.h" +/* These defines are from qnap’s GPL source code: + * src/linux-2.6.33.2-arm/include/qnap/pic.h + */ +#define QNAP_PIC_EUP_DISABLE 0xF4 +#define QNAP_PIC_EUP_ENABLE 0xF5 + +#define QNAP_PIC_WOL_ENABLE 0xF2 +#define QNAP_PIC_WOL_DISABLE 0xF3 + static int serial; static struct termios oldtio, newtio; static pthread_t ts219_thread; @@ -330,6 +340,46 @@ return 0; } +static int ts219_eup(int argc, const char **argv) +{ + unsigned char code = 0; + + if (argc != 1) + return -1; + + if (strcmp(argv[0], "on") == 0) + code = QNAP_PIC_EUP_ENABLE; + else if (strcmp(argv[0], "off") == 0) + code = QNAP_PIC_EUP_DISABLE; + else + return -1; + + serial_write(&code, 1); + return 0; +} + +static int ts219_wakeonlan(int argc, const char **argv) +{ + unsigned char code[3] = { 0, 0, 0 }; + + if (argc != 1) + return -1; + + if (strcmp(argv[0], "on") == 0) { + /* EUP turns the device in such a deep power-saving + * mode that WOL does not work. Therefore, in order + * to have WOL turned on, we also disable EUP. */ + code[0] = QNAP_PIC_WOL_ENABLE; + code[1] = QNAP_PIC_EUP_DISABLE; + } else if (strcmp(argv[0], "off") == 0) + code[0] = QNAP_PIC_WOL_DISABLE; + else + return -1; + + serial_write(code, strlen(code)); + return 0; +} + static int ts219_init(int argc, const char **argv UNUSED) { int err; @@ -381,6 +431,16 @@ "Watchdog options are:\n" "\toff", ts219_wdt); + err = register_command("wakeonlan", + "Control Wake on LAN", + "Control Wake on LAN, options are:\n" + "\ton\n\toff", + ts219_wakeonlan); + err = register_command("eup", + "Control EUP (Energy-using Products) power saving", + "Control EUP, options are:\n" + "\ton\n\toff", + ts219_eup); return pthread_create(&ts219_thread, NULL, serial_poll, NULL); }