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 | |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 11 | #include <errno.h> |
| 12 | #include <fcntl.h> |
| 13 | #include <stdio.h> |
Eric Andersen | ed3ef50 | 2001-01-27 08:24:39 +0000 | [diff] [blame] | 14 | #include <string.h> |
| 15 | #include <stdlib.h> |
| 16 | #include <unistd.h> |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 17 | #include <sys/ioctl.h> |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 18 | #include "busybox.h" |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 19 | |
Matt Kraai | 9133c98 | 2000-10-25 16:48:15 +0000 | [diff] [blame] | 20 | #define BINARY_KEYMAP_MAGIC "bkeymap" |
| 21 | |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 22 | /* From <linux/kd.h> */ |
| 23 | struct kbentry { |
| 24 | unsigned char kb_table; |
| 25 | unsigned char kb_index; |
| 26 | unsigned short kb_value; |
| 27 | }; |
Glenn L McGrath | acbdc47 | 2003-11-21 09:27:02 +0000 | [diff] [blame] | 28 | /* sets one entry in translation table */ |
| 29 | #define KDSKBENT 0x4B47 |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 30 | |
| 31 | /* From <linux/keyboard.h> */ |
Glenn L McGrath | acbdc47 | 2003-11-21 09:27:02 +0000 | [diff] [blame] | 32 | #define NR_KEYS 128 |
| 33 | #define MAX_NR_KEYMAPS 256 |
Eric Andersen | bd22ed8 | 2000-07-08 18:55:24 +0000 | [diff] [blame] | 34 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 35 | int loadkmap_main(int argc, char **argv) |
| 36 | { |
| 37 | struct kbentry ke; |
Glenn L McGrath | acbdc47 | 2003-11-21 09:27:02 +0000 | [diff] [blame] | 38 | int i, j, fd; |
| 39 | u_short ibuff[NR_KEYS]; |
| 40 | char flags[MAX_NR_KEYMAPS]; |
| 41 | char buff[7]; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 42 | |
Matt Kraai | 9133c98 | 2000-10-25 16:48:15 +0000 | [diff] [blame] | 43 | if (argc != 1) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 44 | bb_show_usage(); |
Erik Andersen | 3fe7f9f | 2000-04-19 03:59:10 +0000 | [diff] [blame] | 45 | |
Glenn L McGrath | acbdc47 | 2003-11-21 09:27:02 +0000 | [diff] [blame] | 46 | fd = bb_xopen(CURRENT_VC, O_RDWR); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 47 | |
Rob Landley | 5343747 | 2006-07-16 08:14:35 +0000 | [diff] [blame] | 48 | xread(0, buff, 7); |
| 49 | if (strncmp(buff, BINARY_KEYMAP_MAGIC, 7)) |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 50 | bb_error_msg_and_die("This is not a valid binary keymap."); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 51 | |
Rob Landley | 5343747 | 2006-07-16 08:14:35 +0000 | [diff] [blame] | 52 | xread(0, flags, MAX_NR_KEYMAPS); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 53 | |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 54 | for (i = 0; i < MAX_NR_KEYMAPS; i++) { |
| 55 | if (flags[i] == 1) { |
Rob Landley | 5343747 | 2006-07-16 08:14:35 +0000 | [diff] [blame] | 56 | xread(0, ibuff, NR_KEYS * sizeof(u_short)); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 57 | for (j = 0; j < NR_KEYS; j++) { |
| 58 | ke.kb_index = j; |
| 59 | ke.kb_table = i; |
| 60 | ke.kb_value = ibuff[j]; |
| 61 | ioctl(fd, KDSKBENT, &ke); |
| 62 | } |
| 63 | } |
| 64 | } |
Glenn L McGrath | acbdc47 | 2003-11-21 09:27:02 +0000 | [diff] [blame] | 65 | |
Rob Landley | 5343747 | 2006-07-16 08:14:35 +0000 | [diff] [blame] | 66 | if (ENABLE_FEATURE_CLEAN_UP) close(fd); |
| 67 | return 0; |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 68 | } |