summaryrefslogtreecommitdiff
path: root/lib/efi_selftest/efi_selftest_util.c
blob: dba02d6b5672c8557d8f9b2d9dadb99f06dffd51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// SPDX-License-Identifier: GPL-2.0+
/*
 * efi_selftest_util
 *
 * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
 *
 * Utility functions
 */

#include <efi_selftest.h>

struct efi_st_translate {
	u16 code;
	u16 *text;
};

static struct efi_st_translate efi_st_control_characters[] = {
	{0, u"Null"},
	{8, u"BS"},
	{9, u"TAB"},
	{10, u"LF"},
	{13, u"CR"},
	{0, NULL},
};

static u16 efi_st_ch[] = u"' '";
static u16 efi_st_unknown[] = u"unknown";

static struct efi_st_translate efi_st_scan_codes[] = {
	{0x00, u"Null"},
	{0x01, u"Up"},
	{0x02, u"Down"},
	{0x03, u"Right"},
	{0x04, u"Left"},
	{0x05, u"Home"},
	{0x06, u"End"},
	{0x07, u"Insert"},
	{0x08, u"Delete"},
	{0x09, u"Page Up"},
	{0x0a, u"Page Down"},
	{0x0b, u"FN 1"},
	{0x0c, u"FN 2"},
	{0x0d, u"FN 3"},
	{0x0e, u"FN 4"},
	{0x0f, u"FN 5"},
	{0x10, u"FN 6"},
	{0x11, u"FN 7"},
	{0x12, u"FN 8"},
	{0x13, u"FN 9"},
	{0x14, u"FN 10"},
	{0x15, u"FN 11"},
	{0x16, u"FN 12"},
	{0x17, u"Escape"},
	{0x68, u"FN 13"},
	{0x69, u"FN 14"},
	{0x6a, u"FN 15"},
	{0x6b, u"FN 16"},
	{0x6c, u"FN 17"},
	{0x6d, u"FN 18"},
	{0x6e, u"FN 19"},
	{0x6f, u"FN 20"},
	{0x70, u"FN 21"},
	{0x71, u"FN 22"},
	{0x72, u"FN 23"},
	{0x73, u"FN 24"},
	{0x7f, u"Mute"},
	{0x80, u"Volume Up"},
	{0x81, u"Volume Down"},
	{0x100, u"Brightness Up"},
	{0x101, u"Brightness Down"},
	{0x102, u"Suspend"},
	{0x103, u"Hibernate"},
	{0x104, u"Toggle Display"},
	{0x105, u"Recovery"},
	{0x106, u"Reject"},
	{0x0, NULL},
};

u16 *efi_st_translate_char(u16 code)
{
	struct efi_st_translate *tr;

	if (code >= ' ') {
		efi_st_ch[1] = code;
		return efi_st_ch;
	}
	for (tr = efi_st_control_characters; tr->text; ++tr) {
		if (tr->code == code)
			return tr->text;
	}
	return efi_st_unknown;
}

u16 *efi_st_translate_code(u16 code)
{
	struct efi_st_translate *tr;

	for (tr = efi_st_scan_codes; tr->text; ++tr) {
		if (tr->code == code)
			return tr->text;
	}
	return efi_st_unknown;
}

int efi_st_strcmp_16_8(const u16 *buf1, const char *buf2)
{
	for (; *buf1 || *buf2; ++buf1, ++buf2) {
		if (*buf1 != *buf2)
			return *buf1 - *buf2;
	}
	return 0;
}