blob: 28e53ebcadbfd50a34948deb38e2e814d809e9c6 [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 *
9 */
10
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000011#include "libbb.h"
Eric Andersencc8ed391999-10-05 16:24:54 +000012
Matt Kraai9133c982000-10-25 16:48:15 +000013#define BINARY_KEYMAP_MAGIC "bkeymap"
14
Eric Andersenbd22ed82000-07-08 18:55:24 +000015/* From <linux/kd.h> */
16struct kbentry {
17 unsigned char kb_table;
18 unsigned char kb_index;
19 unsigned short kb_value;
20};
Glenn L McGrathacbdc472003-11-21 09:27:02 +000021/* sets one entry in translation table */
22#define KDSKBENT 0x4B47
Eric Andersenbd22ed82000-07-08 18:55:24 +000023
24/* From <linux/keyboard.h> */
Glenn L McGrathacbdc472003-11-21 09:27:02 +000025#define NR_KEYS 128
26#define MAX_NR_KEYMAPS 256
Eric Andersenbd22ed82000-07-08 18:55:24 +000027
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000028int loadkmap_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000029int loadkmap_main(int ATTRIBUTE_UNUSED argc, char **argv ATTRIBUTE_UNUSED)
Erik Andersene49d5ec2000-02-08 19:58:47 +000030{
31 struct kbentry ke;
Glenn L McGrathacbdc472003-11-21 09:27:02 +000032 int i, j, fd;
Denis Vlasenko28703012006-12-19 20:32:02 +000033 uint16_t ibuff[NR_KEYS];
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000034 RESERVE_CONFIG_BUFFER(flags,MAX_NR_KEYMAPS);
Eric Andersencc8ed391999-10-05 16:24:54 +000035
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000036/* bb_warn_ignoring_args(argc>=2);*/
Erik Andersen3fe7f9f2000-04-19 03:59:10 +000037
Rob Landleyd921b2e2006-08-03 15:41:12 +000038 fd = xopen(CURRENT_VC, O_RDWR);
Erik Andersene49d5ec2000-02-08 19:58:47 +000039
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000040 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 Andersene49d5ec2000-02-08 19:58:47 +000043
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000044 xread(STDIN_FILENO, flags, MAX_NR_KEYMAPS);
Erik Andersene49d5ec2000-02-08 19:58:47 +000045
Erik Andersene49d5ec2000-02-08 19:58:47 +000046 for (i = 0; i < MAX_NR_KEYMAPS; i++) {
47 if (flags[i] == 1) {
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000048 xread(STDIN_FILENO, ibuff, NR_KEYS * sizeof(uint16_t));
Erik Andersene49d5ec2000-02-08 19:58:47 +000049 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 McGrathacbdc472003-11-21 09:27:02 +000057
Bernhard Reutner-Fischerae4342c2008-05-19 08:18:50 +000058 if (ENABLE_FEATURE_CLEAN_UP) {
59 close(fd);
60 RELEASE_CONFIG_BUFFER(flags);
61 }
62 return EXIT_SUCCESS;
Eric Andersencc8ed391999-10-05 16:24:54 +000063}