Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * setkeycodes |
| 4 | * |
| 5 | * Copyright (C) 1994-1998 Andries E. Brouwer <aeb@cwi.nl> |
| 6 | * |
Eric Andersen | cb81e64 | 2003-07-14 21:21:08 +0000 | [diff] [blame] | 7 | * Adjusted for BusyBox by Erik Andersen <andersen@codepoet.org> |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 8 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 9 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 10 | */ |
Denys Vlasenko | 6d93299 | 2016-11-23 10:39:27 +0100 | [diff] [blame] | 11 | //config:config SETKEYCODES |
Denys Vlasenko | 4eed2c6 | 2017-07-18 22:01:24 +0200 | [diff] [blame] | 12 | //config: bool "setkeycodes (1.7 kb)" |
Denys Vlasenko | 6d93299 | 2016-11-23 10:39:27 +0100 | [diff] [blame] | 13 | //config: default y |
| 14 | //config: select PLATFORM_LINUX |
| 15 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 16 | //config: This program loads entries into the kernel's scancode-to-keycode |
| 17 | //config: map, allowing unusual keyboards to generate usable keycodes. |
Denys Vlasenko | 6d93299 | 2016-11-23 10:39:27 +0100 | [diff] [blame] | 18 | |
Denys Vlasenko | b83db4d | 2017-08-06 18:29:25 +0200 | [diff] [blame] | 19 | //applet:IF_SETKEYCODES(APPLET_NOEXEC(setkeycodes, setkeycodes, BB_DIR_USR_BIN, BB_SUID_DROP, setkeycodes)) |
Denys Vlasenko | 6d93299 | 2016-11-23 10:39:27 +0100 | [diff] [blame] | 20 | |
| 21 | //kbuild:lib-$(CONFIG_SETKEYCODES) += setkeycodes.o |
Pere Orga | 55068c4 | 2011-03-27 23:42:28 +0200 | [diff] [blame] | 22 | |
| 23 | //usage:#define setkeycodes_trivial_usage |
Denys Vlasenko | b83db4d | 2017-08-06 18:29:25 +0200 | [diff] [blame] | 24 | //usage: "{ SCANCODE KEYCODE }..." |
Pere Orga | 55068c4 | 2011-03-27 23:42:28 +0200 | [diff] [blame] | 25 | //usage:#define setkeycodes_full_usage "\n\n" |
Denys Vlasenko | b83db4d | 2017-08-06 18:29:25 +0200 | [diff] [blame] | 26 | //usage: "Modify kernel's scancode-to-keycode map,\n" |
Pere Orga | 55068c4 | 2011-03-27 23:42:28 +0200 | [diff] [blame] | 27 | //usage: "allowing unusual keyboards to generate usable keycodes.\n\n" |
Denys Vlasenko | b83db4d | 2017-08-06 18:29:25 +0200 | [diff] [blame] | 28 | //usage: "SCANCODE is either xx or e0xx (hexadecimal), KEYCODE is decimal." |
Pere Orga | 55068c4 | 2011-03-27 23:42:28 +0200 | [diff] [blame] | 29 | //usage: |
| 30 | //usage:#define setkeycodes_example_usage |
| 31 | //usage: "$ setkeycodes e030 127\n" |
| 32 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 33 | #include "libbb.h" |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 34 | |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 35 | /* From <linux/kd.h> */ |
| 36 | struct kbkeycode { |
Denis Vlasenko | 1d42665 | 2008-03-17 09:09:09 +0000 | [diff] [blame] | 37 | unsigned scancode, keycode; |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 38 | }; |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 39 | enum { |
| 40 | KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */ |
| 41 | }; |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 42 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 43 | int setkeycodes_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 44 | int setkeycodes_main(int argc, char **argv) |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 45 | { |
Denys Vlasenko | 2e068e7 | 2010-05-19 17:15:54 +0200 | [diff] [blame] | 46 | int fd; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 47 | |
Denis Vlasenko | 2afd5ab | 2008-08-05 23:32:27 +0000 | [diff] [blame] | 48 | if (!(argc & 1) /* if even */ || argc < 2) { |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 49 | bb_show_usage(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 50 | } |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 51 | |
Denis Vlasenko | 2afd5ab | 2008-08-05 23:32:27 +0000 | [diff] [blame] | 52 | fd = get_console_fd_or_die(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 53 | |
Denys Vlasenko | 2e068e7 | 2010-05-19 17:15:54 +0200 | [diff] [blame] | 54 | while (argv[1]) { |
Denys Vlasenko | b83db4d | 2017-08-06 18:29:25 +0200 | [diff] [blame] | 55 | struct kbkeycode a; |
| 56 | int sc; |
| 57 | |
| 58 | sc = xstrtoul_range(argv[1], 16, 0, 0xe07f); |
Denys Vlasenko | 2e068e7 | 2010-05-19 17:15:54 +0200 | [diff] [blame] | 59 | if (sc >= 0xe000) { |
| 60 | sc -= 0xe000; |
| 61 | sc += 0x0080; |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 62 | } |
Denys Vlasenko | 2e068e7 | 2010-05-19 17:15:54 +0200 | [diff] [blame] | 63 | a.scancode = sc; |
| 64 | a.keycode = xatou_range(argv[2], 0, 255); |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 65 | ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a, |
Denis Vlasenko | 2afd5ab | 2008-08-05 23:32:27 +0000 | [diff] [blame] | 66 | "can't set SCANCODE %x to KEYCODE %d", |
Denis Vlasenko | fb79a2e | 2007-07-14 22:07:14 +0000 | [diff] [blame] | 67 | sc, a.keycode); |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 68 | argv += 2; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 69 | } |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 70 | return EXIT_SUCCESS; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 71 | } |