From patchwork Fri Jul 11 08:20:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keng-Yu Lin X-Patchwork-Id: 369052 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 5FB9C1400F1; Fri, 11 Jul 2014 18:21:11 +1000 (EST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1X5W4s-00023z-0g; Fri, 11 Jul 2014 08:21:10 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1X5W4n-000239-Kq for fwts-devel@lists.ubuntu.com; Fri, 11 Jul 2014 08:21:05 +0000 Received: from 114-43-47-11.dynamic.hinet.net ([114.43.47.11] helo=canonical.com) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1X5W4m-0003eG-NM; Fri, 11 Jul 2014 08:21:05 +0000 From: Keng-Yu Lin To: fwts-devel@lists.ubuntu.com Subject: [PATCH 1/3] import acpi-fakekey tool Date: Fri, 11 Jul 2014 16:20:53 +0800 Message-Id: <1405066855-17918-1-git-send-email-kengyu@canonical.com> X-Mailer: git-send-email 1.9.1 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com This tool is imported from acpi-support v0.141. The tool can find the correct input event node of the keyboard and send a keycode to it. The keycode value is specified as an parameter of the command. Signed-off-by: Keng-Yu Lin --- debian/copyright | 8 +++++ debian/fwts.install | 1 + debian/rules | 3 ++ src/Makefile.am | 3 +- src/utilities/Makefile.am | 4 ++- src/utilities/acpi_fakekey.c | 77 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 src/utilities/acpi_fakekey.c diff --git a/debian/copyright b/debian/copyright index eaefaee..a3f1a9c 100644 --- a/debian/copyright +++ b/debian/copyright @@ -153,3 +153,11 @@ License: other United States government or any agency thereof requires an export license, other governmental approval, or letter of assurance, without first obtaining such license, approval or letter. + +Files: src/utilities/acpi_fakekey.c +Copyright: 2004-2014, Canonical Ltd + 2004, Matthew Garrett + 2004-2014, Thom May +License: GPL-2 + On Debian systems, the complete text of the GNU General Public + License can be found in `/usr/share/common-licenses/GPL-2'. diff --git a/debian/fwts.install b/debian/fwts.install index 2630f4e..8400417 100644 --- a/debian/fwts.install +++ b/debian/fwts.install @@ -4,3 +4,4 @@ usr/bin/fwts usr/bin usr/share/man/man1/fwts.1 usr/share/man/man1 scripts/fwts-collect usr/bin usr/share/man/man1/fwts-collect.1 usr/share/man/man1 +usr/lib/fwts/acpi_fakekey usr/lib/fwts diff --git a/debian/rules b/debian/rules index 0887c38..5011334 100755 --- a/debian/rules +++ b/debian/rules @@ -21,6 +21,9 @@ override_dh_auto_install: override_dh_dkms: dh_dkms -V $(VERSION) +override_dh_auto_configure: + dh_auto_configure -- --libexecdir=/usr/lib/fwts + override_dh_auto_test: ifneq ($(DEB_BUILD_ARCH),arm64) dh_auto_test $@ diff --git a/src/Makefile.am b/src/Makefile.am index ace23d6..eff1e31 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -11,7 +11,8 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/src/acpica/source/include \ -I$(top_srcdir)/src/acpica/source/compiler \ -I$(top_srcdir)/efi_runtime \ - -Wall -Werror -Wextra + -Wall -Werror -Wextra \ + -DLIBEXECDIR='"$(libexecdir)"' bin_PROGRAMS = fwts diff --git a/src/utilities/Makefile.am b/src/utilities/Makefile.am index 01b534a..ecededa 100644 --- a/src/utilities/Makefile.am +++ b/src/utilities/Makefile.am @@ -1,6 +1,8 @@ AM_CPPFLAGS = -Wall -Werror -Wextra -DDATAROOTDIR=\"$(datarootdir)\" bin_PROGRAMS = kernelscan +libexec_PROGRAMS = acpi_fakekey kernelscan_SOURCES = kernelscan.c kernelscan_LDFLAGS = -lpcre - +acpi_fakekey_SOURCES = acpi_fakekey.c +acpi_fakekey_CFLAGS = -w diff --git a/src/utilities/acpi_fakekey.c b/src/utilities/acpi_fakekey.c new file mode 100644 index 0000000..a2f3f85 --- /dev/null +++ b/src/utilities/acpi_fakekey.c @@ -0,0 +1,77 @@ +#include +#include +#include +#include +#include +#include + +#define TestBit(bit, array) (array[(bit) / 8] & (1 << ((bit) % 8))) + +int find_keyboard() { + int i, j; + int fd; + char filename[32]; + char key_bitmask[(KEY_MAX + 7) / 8]; + + for (i=0; i<32; i++) { + snprintf(filename,sizeof(filename), "/dev/input/event%d", i); + + fd = open(filename, O_RDWR); + if (fd < 0) { + perror("open"); + exit(EXIT_FAILURE); + } + + ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(key_bitmask)), key_bitmask); + + /* We assume that anything that has an alphabetic key in the + QWERTYUIOP range in it is the main keyboard. */ + for (j = KEY_Q; j <= KEY_P; j++) { + if (TestBit(j, key_bitmask)) + return fd; + } + + close (fd); + } + return 0; +} + +int main(int argc, char** argv) { + int fd; + int key; + struct input_event event; + + if (argc == 2) { + key = atoi(argv[1]); + } else { + return 1; + } + + fd = find_keyboard(); + + if (!fd) { + return 2; + } + event.type = EV_SYN; + event.code = SYN_REPORT; + event.value = 0; + write(fd, &event, sizeof event); + + event.type = EV_KEY; + event.code = key; + event.value = 1; + write(fd, &event, sizeof event); + + event.type = EV_KEY; + event.code = key; + event.value = 0; + write(fd, &event, sizeof event); + + event.type = EV_SYN; + event.code = SYN_REPORT; + event.value = 0; + write(fd, &event, sizeof event); + + return 0; +} +