utuuid.c 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /******************************************************************************
  2. *
  3. * Module Name: utuuid -- UUID support functions
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #define _COMPONENT ACPI_COMPILER
  45. ACPI_MODULE_NAME("utuuid")
  46. #if (defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP || defined ACPI_HELP_APP)
  47. /*
  48. * UUID support functions.
  49. *
  50. * This table is used to convert an input UUID ascii string to a 16 byte
  51. * buffer and the reverse. The table maps a UUID buffer index 0-15 to
  52. * the index within the 36-byte UUID string where the associated 2-byte
  53. * hex value can be found.
  54. *
  55. * 36-byte UUID strings are of the form:
  56. * aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
  57. * Where aa-pp are one byte hex numbers, made up of two hex digits
  58. *
  59. * Note: This table is basically the inverse of the string-to-offset table
  60. * found in the ACPI spec in the description of the to_UUID macro.
  61. */
  62. const u8 acpi_gbl_map_to_uuid_offset[UUID_BUFFER_LENGTH] = {
  63. 6, 4, 2, 0, 11, 9, 16, 14, 19, 21, 24, 26, 28, 30, 32, 34
  64. };
  65. /*******************************************************************************
  66. *
  67. * FUNCTION: acpi_ut_convert_string_to_uuid
  68. *
  69. * PARAMETERS: in_string - 36-byte formatted UUID string
  70. * uuid_buffer - Where the 16-byte UUID buffer is returned
  71. *
  72. * RETURN: None. Output data is returned in the uuid_buffer
  73. *
  74. * DESCRIPTION: Convert a 36-byte formatted UUID string to 16-byte UUID buffer
  75. *
  76. ******************************************************************************/
  77. void acpi_ut_convert_string_to_uuid(char *in_string, u8 *uuid_buffer)
  78. {
  79. u32 i;
  80. for (i = 0; i < UUID_BUFFER_LENGTH; i++) {
  81. uuid_buffer[i] =
  82. (acpi_ut_ascii_char_to_hex
  83. (in_string[acpi_gbl_map_to_uuid_offset[i]]) << 4);
  84. uuid_buffer[i] |=
  85. acpi_ut_ascii_char_to_hex(in_string
  86. [acpi_gbl_map_to_uuid_offset[i] +
  87. 1]);
  88. }
  89. }
  90. #endif