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