utuuid.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 - 2018, 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. #endif