Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 2 | /* |
| 3 | * Mini loadkmap implementation for busybox |
| 4 | * |
| 5 | * Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es> |
| 6 | * |
"Robert P. J. Day" | 801ab14 | 2006-07-12 07:56:04 +0000 | [diff] [blame] | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 8 | */ |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 9 | #include "libbb.h" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 10 | |
Matt Kraai | 9133c98 | 2000-10-25 16:48:15 +0000 | [diff] [blame] | 11 | #define BINARY_KEYMAP_MAGIC "bkeymap" |
| 12 | |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 13 | /* From <linux/kd.h> */ |
| 14 | struct kbentry { |
| 15 | unsigned char kb_table; |
| 16 | unsigned char kb_index; |
| 17 | unsigned short kb_value; |
| 18 | }; |
Glenn L McGrath | acbdc47 | 2003-11-21 09:27:02 +0000 | [diff] [blame] | 19 | /* sets one entry in translation table */ |
| 20 | #define KDSKBENT 0x4B47 |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 21 | |
| 22 | /* From <linux/keyboard.h> */ |
Glenn L McGrath | acbdc47 | 2003-11-21 09:27:02 +0000 | [diff] [blame] | 23 | #define NR_KEYS 128 |
| 24 | #define MAX_NR_KEYMAPS 256 |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 25 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 26 | int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 27 | int loadkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 28 | { |
| 29 | struct kbentry ke; |
Glenn L McGrath | acbdc47 | 2003-11-21 09:27:02 +0000 | [diff] [blame] | 30 | int i, j, fd; |
Denis Vlasenko | 2870301 | 2006-12-19 20:32:02 +0000 | [diff] [blame] | 31 | uint16_t ibuff[NR_KEYS]; |
Denis Vlasenko | dc70069 | 2008-11-08 21:39:06 +0000 | [diff] [blame] | 32 | /* const char *tty_name = CURRENT_TTY; */ |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 33 | RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 34 | |
Denis Vlasenko | dc70069 | 2008-11-08 21:39:06 +0000 | [diff] [blame] | 35 | /* bb_warn_ignoring_args(argc >= 2); */ |
Denis Vlasenko | 2afd5ab | 2008-08-05 23:32:27 +0000 | [diff] [blame] | 36 | fd = get_console_fd_or_die(); |
Denis Vlasenko | dc70069 | 2008-11-08 21:39:06 +0000 | [diff] [blame] | 37 | /* or maybe: |
| 38 | opt = getopt32(argv, "C:", &tty_name); |
| 39 | fd = xopen(tty_name, O_NONBLOCK); |
| 40 | */ |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 41 | |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 42 | xread(STDIN_FILENO, flags, 7); |
| 43 | if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7)) |
| 44 | bb_error_msg_and_die("not a valid binary keymap"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 45 | |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 46 | xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 47 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 48 | for (i = 0; i < MAX_NR_KEYMAPS; i++) { |
| 49 | if (flags[i] == 1) { |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 50 | xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 51 | for (j = 0; j < NR_KEYS; j++) { |
| 52 | ke.kb_index = j; |
| 53 | ke.kb_table = i; |
| 54 | ke.kb_value = ibuff[j]; |
| 55 | ioctl(fd, KDSKBENT, &ke); |
| 56 | } |
| 57 | } |
| 58 | } |
Glenn L McGrath | acbdc47 | 2003-11-21 09:27:02 +0000 | [diff] [blame] | 59 | |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 60 | if (ENABLE_FEATURE_CLEAN_UP) { |
| 61 | close(fd); |
| 62 | RELEASE_CONFIG_BUFFER(flags); |
| 63 | } |
| 64 | return EXIT_SUCCESS; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 65 | } |