blob: 912291a7dd11511f00c079ba688b646df79e310e [file] [log] [blame]
Erik Andersene49d5ec2000-02-08 19:58:47 +00001/* vi: set sw=4 ts=4: */
Eric Andersenc4996011999-10-20 22:08:37 +00002/*
3 * Mini loadkmap implementation for busybox
4 *
5 * Copyright (C) 1998 Enrique Zanardi <ezanardi@ull.es>
6 *
"Robert P. J. Day"801ab142006-07-12 07:56:04 +00007 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
Eric Andersenc4996011999-10-20 22:08:37 +00008 */
Denis Vlasenkob6adbf12007-05-26 19:00:18 +00009#include "libbb.h"
Eric Andersencc8ed391999-10-05 16:24:54 +000010
Matt Kraai9133c982000-10-25 16:48:15 +000011#define BINARY_KEYMAP_MAGIC "bkeymap"
12
Eric Andersenbd22ed82000-07-08 18:55:24 +000013/* From <linux/kd.h> */
14struct kbentry {
15 unsigned char kb_table;
16 unsigned char kb_index;
17 unsigned short kb_value;
18};
Glenn L McGrathacbdc472003-11-21 09:27:02 +000019/* sets one entry in translation table */
20#define KDSKBENT 0x4B47
Eric Andersenbd22ed82000-07-08 18:55:24 +000021
22/* From <linux/keyboard.h> */
Glenn L McGrathacbdc472003-11-21 09:27:02 +000023#define NR_KEYS 128
24#define MAX_NR_KEYMAPS 256
Eric Andersenbd22ed82000-07-08 18:55:24 +000025
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000026int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000027int loadkmap_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
Erik Andersene49d5ec2000-02-08 19:58:47 +000028{
29 struct kbentry ke;
Glenn L McGrathacbdc472003-11-21 09:27:02 +000030 int i, j, fd;
Denis Vlasenko28703012006-12-19 20:32:02 +000031 uint16_t ibuff[NR_KEYS];
Denis Vlasenkodc700692008-11-08 21:39:06 +000032/* const char *tty_name = CURRENT_TTY; */
Denys Vlasenkoa355da02010-01-04 13:16:08 +010033 RESERVE_CONFIG_BUFFER(flags, MAX_NR_KEYMAPS);
Eric Andersencc8ed391999-10-05 16:24:54 +000034
Denys Vlasenkoa355da02010-01-04 13:16:08 +010035/* bb_warn_ignoring_args(argv[1]); */
Denis Vlasenko2afd5ab2008-08-05 23:32:27 +000036 fd = get_console_fd_or_die();
Denis Vlasenkodc700692008-11-08 21:39:06 +000037/* or maybe:
38 opt = getopt32(argv, "C:", &tty_name);
Bernhard Reutner-Fischera4830872009-10-26 23:27:08 +010039 fd = xopen_nonblocking(tty_name);
Denis Vlasenkodc700692008-11-08 21:39:06 +000040*/
Erik Andersene49d5ec2000-02-08 19:58:47 +000041
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000042 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 Andersene49d5ec2000-02-08 19:58:47 +000045
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000046 xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
Erik Andersene49d5ec2000-02-08 19:58:47 +000047
Erik Andersene49d5ec2000-02-08 19:58:47 +000048 for (i = 0; i < MAX_NR_KEYMAPS; i++) {
49 if (flags[i] == 1) {
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000050 xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t));
Erik Andersene49d5ec2000-02-08 19:58:47 +000051 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 McGrathacbdc472003-11-21 09:27:02 +000059
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000060 if (ENABLE_FEATURE_CLEAN_UP) {
61 close(fd);
62 RELEASE_CONFIG_BUFFER(flags);
63 }
64 return EXIT_SUCCESS;
Eric Andersencc8ed391999-10-05 16:24:54 +000065}