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