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 | * |
"Robert P. J. Day" | 801ab14 | 2006-07-12 07:56:04 +0000 | [diff] [blame] | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 10 | */ |
| 11 | |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #include <fcntl.h> |
| 15 | #include <sys/ioctl.h> |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 16 | #include "busybox.h" |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 17 | |
| 18 | |
| 19 | /* From <linux/kd.h> */ |
| 20 | struct kbkeycode { |
| 21 | unsigned int scancode, keycode; |
| 22 | }; |
Rob Landley | bc68cd1 | 2006-03-10 19:22:06 +0000 | [diff] [blame] | 23 | enum { |
| 24 | KDSETKEYCODE = 0x4B4D /* write kernel keycode table entry */ |
| 25 | }; |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 26 | |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 27 | extern int |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 28 | setkeycodes_main(int argc, char** argv) |
| 29 | { |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 30 | char *ep; |
| 31 | int fd, sc; |
| 32 | struct kbkeycode a; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 33 | |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 34 | if (argc % 2 != 1 || argc < 2) { |
| 35 | bb_show_usage(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 36 | } |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 37 | |
Eric Andersen | c38678d | 2002-09-16 06:22:25 +0000 | [diff] [blame] | 38 | fd = get_console_fd(); |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 39 | |
Denis Vlasenko | 8fafacd | 2006-09-09 13:23:04 +0000 | [diff] [blame] | 40 | while (argc > 2) { |
| 41 | a.keycode = atoi(argv[2]); |
| 42 | a.scancode = sc = strtol(argv[1], &ep, 16); |
| 43 | if (*ep) { |
| 44 | bb_error_msg_and_die("error reading SCANCODE: '%s'", argv[1]); |
| 45 | } |
| 46 | if (a.scancode > 127) { |
| 47 | a.scancode -= 0xe000; |
| 48 | a.scancode += 128; |
| 49 | } |
| 50 | if (a.scancode > 255 || a.keycode > 127) { |
| 51 | bb_error_msg_and_die("SCANCODE or KEYCODE outside bounds"); |
| 52 | } |
| 53 | if (ioctl(fd,KDSETKEYCODE,&a)) { |
| 54 | bb_perror_msg_and_die("failed to set SCANCODE %x to KEYCODE %d", sc, a.keycode); |
| 55 | } |
| 56 | argc -= 2; |
| 57 | argv += 2; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 58 | } |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 59 | return EXIT_SUCCESS; |
Erik Andersen | abc199e | 2000-04-28 01:26:31 +0000 | [diff] [blame] | 60 | } |