efi_selftest_util.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * efi_selftest_util
  4. *
  5. * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
  6. *
  7. * Utility functions
  8. */
  9. #include <efi_selftest.h>
  10. struct efi_st_translate {
  11. u16 code;
  12. u16 *text;
  13. };
  14. static struct efi_st_translate efi_st_control_characters[] = {
  15. {0, u"Null"},
  16. {8, u"BS"},
  17. {9, u"TAB"},
  18. {10, u"LF"},
  19. {13, u"CR"},
  20. {0, NULL},
  21. };
  22. static u16 efi_st_ch[] = u"' '";
  23. static u16 efi_st_unknown[] = u"unknown";
  24. static struct efi_st_translate efi_st_scan_codes[] = {
  25. {0x00, u"Null"},
  26. {0x01, u"Up"},
  27. {0x02, u"Down"},
  28. {0x03, u"Right"},
  29. {0x04, u"Left"},
  30. {0x05, u"Home"},
  31. {0x06, u"End"},
  32. {0x07, u"Insert"},
  33. {0x08, u"Delete"},
  34. {0x09, u"Page Up"},
  35. {0x0a, u"Page Down"},
  36. {0x0b, u"FN 1"},
  37. {0x0c, u"FN 2"},
  38. {0x0d, u"FN 3"},
  39. {0x0e, u"FN 4"},
  40. {0x0f, u"FN 5"},
  41. {0x10, u"FN 6"},
  42. {0x11, u"FN 7"},
  43. {0x12, u"FN 8"},
  44. {0x13, u"FN 9"},
  45. {0x14, u"FN 10"},
  46. {0x15, u"FN 11"},
  47. {0x16, u"FN 12"},
  48. {0x17, u"Escape"},
  49. {0x68, u"FN 13"},
  50. {0x69, u"FN 14"},
  51. {0x6a, u"FN 15"},
  52. {0x6b, u"FN 16"},
  53. {0x6c, u"FN 17"},
  54. {0x6d, u"FN 18"},
  55. {0x6e, u"FN 19"},
  56. {0x6f, u"FN 20"},
  57. {0x70, u"FN 21"},
  58. {0x71, u"FN 22"},
  59. {0x72, u"FN 23"},
  60. {0x73, u"FN 24"},
  61. {0x7f, u"Mute"},
  62. {0x80, u"Volume Up"},
  63. {0x81, u"Volume Down"},
  64. {0x100, u"Brightness Up"},
  65. {0x101, u"Brightness Down"},
  66. {0x102, u"Suspend"},
  67. {0x103, u"Hibernate"},
  68. {0x104, u"Toggle Display"},
  69. {0x105, u"Recovery"},
  70. {0x106, u"Reject"},
  71. {0x0, NULL},
  72. };
  73. u16 *efi_st_translate_char(u16 code)
  74. {
  75. struct efi_st_translate *tr;
  76. if (code >= ' ') {
  77. efi_st_ch[1] = code;
  78. return efi_st_ch;
  79. }
  80. for (tr = efi_st_control_characters; tr->text; ++tr) {
  81. if (tr->code == code)
  82. return tr->text;
  83. }
  84. return efi_st_unknown;
  85. }
  86. u16 *efi_st_translate_code(u16 code)
  87. {
  88. struct efi_st_translate *tr;
  89. for (tr = efi_st_scan_codes; tr->text; ++tr) {
  90. if (tr->code == code)
  91. return tr->text;
  92. }
  93. return efi_st_unknown;
  94. }
  95. int efi_st_strcmp_16_8(const u16 *buf1, const unsigned char *buf2)
  96. {
  97. for (; *buf1 || *buf2; ++buf1, ++buf2) {
  98. if (*buf1 != *buf2)
  99. return *buf1 - *buf2;
  100. }
  101. return 0;
  102. }
  103. void *efi_st_get_config_table(const efi_guid_t *guid)
  104. {
  105. size_t i;
  106. for (i = 0; i < st_systable->nr_tables; i++) {
  107. if (!guidcmp(guid, &st_systable->tables[i].guid))
  108. return st_systable->tables[i].table;
  109. }
  110. return NULL;
  111. }