blob: a141435e2b3024e8dda7ac742b41c1d6954059f5 [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
Eric Andersencbe31da2001-02-20 06:14:08 +000011#include "busybox.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 Vlasenko06af2162007-02-03 17:28:39 +000028int loadkmap_main(int argc, char **argv);
Erik Andersene49d5ec2000-02-08 19:58:47 +000029int loadkmap_main(int argc, char **argv)
30{
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];
Glenn L McGrathacbdc472003-11-21 09:27:02 +000034 char flags[MAX_NR_KEYMAPS];
35 char buff[7];
Eric Andersencc8ed391999-10-05 16:24:54 +000036
Matt Kraai9133c982000-10-25 16:48:15 +000037 if (argc != 1)
Manuel Novoa III cad53642003-03-19 09:13:01 +000038 bb_show_usage();
Erik Andersen3fe7f9f2000-04-19 03:59:10 +000039
Rob Landleyd921b2e2006-08-03 15:41:12 +000040 fd = xopen(CURRENT_VC, O_RDWR);
Erik Andersene49d5ec2000-02-08 19:58:47 +000041
Rob Landley53437472006-07-16 08:14:35 +000042 xread(0, buff, 7);
43 if (strncmp(buff, BINARY_KEYMAP_MAGIC, 7))
Denis Vlasenkoe1a0d482006-10-20 13:28:22 +000044 bb_error_msg_and_die("this is not a valid binary keymap");
Erik Andersene49d5ec2000-02-08 19:58:47 +000045
Rob Landley53437472006-07-16 08:14:35 +000046 xread(0, 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) {
Denis Vlasenko28703012006-12-19 20:32:02 +000050 xread(0, 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
Rob Landley53437472006-07-16 08:14:35 +000060 if (ENABLE_FEATURE_CLEAN_UP) close(fd);
61 return 0;
Eric Andersencc8ed391999-10-05 16:24:54 +000062}