utuuid.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
  2. /******************************************************************************
  3. *
  4. * Module Name: utuuid -- UUID support functions
  5. *
  6. * Copyright (C) 2000 - 2025, Intel Corp.
  7. *
  8. *****************************************************************************/
  9. #include <acpi/acpi.h>
  10. #include "accommon.h"
  11. #define _COMPONENT ACPI_COMPILER
  12. ACPI_MODULE_NAME("utuuid")
  13. #if (defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP || defined ACPI_HELP_APP)
  14. /*
  15. * UUID support functions.
  16. *
  17. * This table is used to convert an input UUID ascii string to a 16 byte
  18. * buffer and the reverse. The table maps a UUID buffer index 0-15 to
  19. * the index within the 36-byte UUID string where the associated 2-byte
  20. * hex value can be found.
  21. *
  22. * 36-byte UUID strings are of the form:
  23. * aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
  24. * Where aa-pp are one byte hex numbers, made up of two hex digits
  25. *
  26. * Note: This table is basically the inverse of the string-to-offset table
  27. * found in the ACPI spec in the description of the to_UUID macro.
  28. */
  29. const u8 acpi_gbl_map_to_uuid_offset[UUID_BUFFER_LENGTH] = {
  30. 6, 4, 2, 0, 11, 9, 16, 14, 19, 21, 24, 26, 28, 30, 32, 34
  31. };
  32. /*******************************************************************************
  33. *
  34. * FUNCTION: acpi_ut_convert_string_to_uuid
  35. *
  36. * PARAMETERS: in_string - 36-byte formatted UUID string
  37. * uuid_buffer - Where the 16-byte UUID buffer is returned
  38. *
  39. * RETURN: None. Output data is returned in the uuid_buffer
  40. *
  41. * DESCRIPTION: Convert a 36-byte formatted UUID string to 16-byte UUID buffer
  42. *
  43. ******************************************************************************/
  44. void acpi_ut_convert_string_to_uuid(char *in_string, u8 *uuid_buffer)
  45. {
  46. u32 i;
  47. for (i = 0; i < UUID_BUFFER_LENGTH; i++) {
  48. uuid_buffer[i] =
  49. (acpi_ut_ascii_char_to_hex
  50. (in_string[acpi_gbl_map_to_uuid_offset[i]]) << 4);
  51. uuid_buffer[i] |=
  52. acpi_ut_ascii_char_to_hex(in_string
  53. [acpi_gbl_map_to_uuid_offset[i] +
  54. 1]);
  55. }
  56. }
  57. /*******************************************************************************
  58. *
  59. * FUNCTION: acpi_ut_convert_uuid_to_string
  60. *
  61. * PARAMETERS: uuid_buffer - 16-byte UUID buffer
  62. * out_string - 36-byte formatted UUID string
  63. *
  64. * RETURN: Status
  65. *
  66. * DESCRIPTION: Convert 16-byte UUID buffer to 36-byte formatted UUID string
  67. * out_string must be 37 bytes to include null terminator.
  68. *
  69. ******************************************************************************/
  70. acpi_status acpi_ut_convert_uuid_to_string(char *uuid_buffer, char *out_string)
  71. {
  72. u32 i;
  73. if (!uuid_buffer || !out_string) {
  74. return (AE_BAD_PARAMETER);
  75. }
  76. for (i = 0; i < UUID_BUFFER_LENGTH; i++) {
  77. out_string[acpi_gbl_map_to_uuid_offset[i]] =
  78. acpi_ut_hex_to_ascii_char(uuid_buffer[i], 4);
  79. out_string[acpi_gbl_map_to_uuid_offset[i] + 1] =
  80. acpi_ut_hex_to_ascii_char(uuid_buffer[i], 0);
  81. }
  82. /* Insert required hyphens (dashes) */
  83. out_string[UUID_HYPHEN1_OFFSET] =
  84. out_string[UUID_HYPHEN2_OFFSET] =
  85. out_string[UUID_HYPHEN3_OFFSET] =
  86. out_string[UUID_HYPHEN4_OFFSET] = '-';
  87. out_string[UUID_STRING_LENGTH] = 0; /* Null terminate */
  88. return (AE_OK);
  89. }
  90. #endif