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 | * |
| 9 | */ |
| 10 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 11 | #include "libbb.h" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 12 | |
Matt Kraai | 9133c98 | 2000-10-25 16:48:15 +0000 | [diff] [blame] | 13 | #define BINARY_KEYMAP_MAGIC "bkeymap" |
| 14 | |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 15 | /* From <linux/kd.h> */ |
| 16 | struct kbentry { |
| 17 | unsigned char kb_table; |
| 18 | unsigned char kb_index; |
| 19 | unsigned short kb_value; |
| 20 | }; |
Glenn L McGrath | acbdc47 | 2003-11-21 09:27:02 +0000 | [diff] [blame] | 21 | /* sets one entry in translation table */ |
| 22 | #define KDSKBENT 0x4B47 |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 23 | |
| 24 | /* From <linux/keyboard.h> */ |
Glenn L McGrath | acbdc47 | 2003-11-21 09:27:02 +0000 | [diff] [blame] | 25 | #define NR_KEYS 128 |
| 26 | #define MAX_NR_KEYMAPS 256 |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 27 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 28 | int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 29 | int loadkmap_main(int ATTRIBUTE_UNUSED argc, char **argv ATTRIBUTE_UNUSED) |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 30 | { |
| 31 | struct kbentry ke; |
Glenn L McGrath | acbdc47 | 2003-11-21 09:27:02 +0000 | [diff] [blame] | 32 | int i, j, fd; |
Denis Vlasenko | 2870301 | 2006-12-19 20:32:02 +0000 | [diff] [blame] | 33 | uint16_t ibuff[NR_KEYS]; |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 34 | RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS); |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 35 | |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 36 | /* bb_warn_ignoring_args(argc>=2);*/ |
Erik Andersen | 3fe7f9f | 2000-04-19 03:59:10 +0000 | [diff] [blame] | 37 | |
Rob Landley | d921b2e | 2006-08-03 15:41:12 +0000 | [diff] [blame] | 38 | fd = xopen(CURRENT_VC, O_RDWR); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 39 | |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 40 | xread(STDIN_FILENO, flags, 7); |
| 41 | if (strncmp(flags, BINARY_KEYMAP_MAGIC, 7)) |
| 42 | bb_error_msg_and_die("not a valid binary keymap"); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 43 | |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 44 | xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 45 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 46 | for (i = 0; i < MAX_NR_KEYMAPS; i++) { |
| 47 | if (flags[i] == 1) { |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 48 | xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 49 | for (j = 0; j < NR_KEYS; j++) { |
| 50 | ke.kb_index = j; |
| 51 | ke.kb_table = i; |
| 52 | ke.kb_value = ibuff[j]; |
| 53 | ioctl(fd, KDSKBENT, &ke); |
| 54 | } |
| 55 | } |
| 56 | } |
Glenn L McGrath | acbdc47 | 2003-11-21 09:27:02 +0000 | [diff] [blame] | 57 | |
Bernhard Reutner-Fischer | ae4342c | 2008-05-19 08:18:50 +0000 | [diff] [blame] | 58 | if (ENABLE_FEATURE_CLEAN_UP) { |
| 59 | close(fd); |
| 60 | RELEASE_CONFIG_BUFFER(flags); |
| 61 | } |
| 62 | return EXIT_SUCCESS; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 63 | } |