efi_selftest_util.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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, L"Null"},
  16. {8, L"BS"},
  17. {9, L"TAB"},
  18. {10, L"LF"},
  19. {13, L"CR"},
  20. {0, NULL},
  21. };
  22. static u16 efi_st_ch[] = L"' '";
  23. static u16 efi_st_unknown[] = L"unknown";
  24. static struct efi_st_translate efi_st_scan_codes[] = {
  25. {0x00, L"Null"},
  26. {0x01, L"Up"},
  27. {0x02, L"Down"},
  28. {0x03, L"Right"},
  29. {0x04, L"Left"},
  30. {0x05, L"Home"},
  31. {0x06, L"End"},
  32. {0x07, L"Insert"},
  33. {0x08, L"Delete"},
  34. {0x09, L"Page Up"},
  35. {0x0a, L"Page Down"},
  36. {0x0b, L"FN 1"},
  37. {0x0c, L"FN 2"},
  38. {0x0d, L"FN 3"},
  39. {0x0e, L"FN 4"},
  40. {0x0f, L"FN 5"},
  41. {0x10, L"FN 6"},
  42. {0x11, L"FN 7"},
  43. {0x12, L"FN 8"},
  44. {0x13, L"FN 9"},
  45. {0x14, L"FN 10"},
  46. {0x15, L"FN 11"},
  47. {0x16, L"FN 12"},
  48. {0x17, L"Escape"},
  49. {0x68, L"FN 13"},
  50. {0x69, L"FN 14"},
  51. {0x6a, L"FN 15"},
  52. {0x6b, L"FN 16"},
  53. {0x6c, L"FN 17"},
  54. {0x6d, L"FN 18"},
  55. {0x6e, L"FN 19"},
  56. {0x6f, L"FN 20"},
  57. {0x70, L"FN 21"},
  58. {0x71, L"FN 22"},
  59. {0x72, L"FN 23"},
  60. {0x73, L"FN 24"},
  61. {0x7f, L"Mute"},
  62. {0x80, L"Volume Up"},
  63. {0x81, L"Volume Down"},
  64. {0x100, L"Brightness Up"},
  65. {0x101, L"Brightness Down"},
  66. {0x102, L"Suspend"},
  67. {0x103, L"Hibernate"},
  68. {0x104, L"Toggle Display"},
  69. {0x105, L"Recovery"},
  70. {0x106, L"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 char *buf2)
  96. {
  97. for (; *buf1 || *buf2; ++buf1, ++buf2) {
  98. if (*buf1 != *buf2)
  99. return *buf1 - *buf2;
  100. }
  101. return 0;
  102. }