asluuid.c revision 1.1.1.1.2.2 1 1.1.1.1.2.2 bouyer /******************************************************************************
2 1.1.1.1.2.2 bouyer *
3 1.1.1.1.2.2 bouyer * Module Name: asluuid-- compiler UUID support
4 1.1.1.1.2.2 bouyer *
5 1.1.1.1.2.2 bouyer *****************************************************************************/
6 1.1.1.1.2.2 bouyer
7 1.1.1.1.2.2 bouyer /*
8 1.1.1.1.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
9 1.1.1.1.2.2 bouyer * All rights reserved.
10 1.1.1.1.2.2 bouyer *
11 1.1.1.1.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.1.1.1.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.1.1.1.2.2 bouyer * are met:
14 1.1.1.1.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.1.1.1.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
16 1.1.1.1.2.2 bouyer * without modification.
17 1.1.1.1.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.1.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.1.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.1.2.2 bouyer * including a substantially similar Disclaimer requirement for further
21 1.1.1.1.2.2 bouyer * binary redistribution.
22 1.1.1.1.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.1.2.2 bouyer * of any contributors may be used to endorse or promote products derived
24 1.1.1.1.2.2 bouyer * from this software without specific prior written permission.
25 1.1.1.1.2.2 bouyer *
26 1.1.1.1.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
27 1.1.1.1.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.1.2.2 bouyer * Software Foundation.
29 1.1.1.1.2.2 bouyer *
30 1.1.1.1.2.2 bouyer * NO WARRANTY
31 1.1.1.1.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.1.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.1.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.1.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.1.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.1.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.1.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.1.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.1.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.1.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.1.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.1.2.2 bouyer */
43 1.1.1.1.2.2 bouyer
44 1.1.1.1.2.2 bouyer
45 1.1.1.1.2.2 bouyer #include "aslcompiler.h"
46 1.1.1.1.2.2 bouyer
47 1.1.1.1.2.2 bouyer #define _COMPONENT ACPI_COMPILER
48 1.1.1.1.2.2 bouyer ACPI_MODULE_NAME ("asluuid")
49 1.1.1.1.2.2 bouyer
50 1.1.1.1.2.2 bouyer
51 1.1.1.1.2.2 bouyer /*
52 1.1.1.1.2.2 bouyer * UUID support functions.
53 1.1.1.1.2.2 bouyer *
54 1.1.1.1.2.2 bouyer * This table is used to convert an input UUID ascii string to a 16 byte
55 1.1.1.1.2.2 bouyer * buffer and the reverse. The table maps a UUID buffer index 0-15 to
56 1.1.1.1.2.2 bouyer * the index within the 36-byte UUID string where the associated 2-byte
57 1.1.1.1.2.2 bouyer * hex value can be found.
58 1.1.1.1.2.2 bouyer *
59 1.1.1.1.2.2 bouyer * 36-byte UUID strings are of the form:
60 1.1.1.1.2.2 bouyer * aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
61 1.1.1.1.2.2 bouyer * Where aa-pp are one byte hex numbers, made up of two hex digits
62 1.1.1.1.2.2 bouyer *
63 1.1.1.1.2.2 bouyer * Note: This table is basically the inverse of the string-to-offset table
64 1.1.1.1.2.2 bouyer * found in the ACPI spec in the description of the ToUUID macro.
65 1.1.1.1.2.2 bouyer */
66 1.1.1.1.2.2 bouyer static UINT8 Gbl_MapToUuidOffset[16] =
67 1.1.1.1.2.2 bouyer {
68 1.1.1.1.2.2 bouyer 6,4,2,0,11,9,16,14,19,21,24,26,28,30,32,34
69 1.1.1.1.2.2 bouyer };
70 1.1.1.1.2.2 bouyer
71 1.1.1.1.2.2 bouyer #define UUID_BUFFER_LENGTH 16
72 1.1.1.1.2.2 bouyer #define UUID_STRING_LENGTH 36
73 1.1.1.1.2.2 bouyer
74 1.1.1.1.2.2 bouyer /* Positions for required hyphens (dashes) in UUID strings */
75 1.1.1.1.2.2 bouyer
76 1.1.1.1.2.2 bouyer #define UUID_HYPHEN1_OFFSET 8
77 1.1.1.1.2.2 bouyer #define UUID_HYPHEN2_OFFSET 13
78 1.1.1.1.2.2 bouyer #define UUID_HYPHEN3_OFFSET 18
79 1.1.1.1.2.2 bouyer #define UUID_HYPHEN4_OFFSET 23
80 1.1.1.1.2.2 bouyer
81 1.1.1.1.2.2 bouyer
82 1.1.1.1.2.2 bouyer /*******************************************************************************
83 1.1.1.1.2.2 bouyer *
84 1.1.1.1.2.2 bouyer * FUNCTION: AuValiduateUuid
85 1.1.1.1.2.2 bouyer *
86 1.1.1.1.2.2 bouyer * PARAMETERS: InString - 36-byte formatted UUID string
87 1.1.1.1.2.2 bouyer *
88 1.1.1.1.2.2 bouyer * RETURN: Status
89 1.1.1.1.2.2 bouyer *
90 1.1.1.1.2.2 bouyer * DESCRIPTION: Check all 36 characters for correct format
91 1.1.1.1.2.2 bouyer *
92 1.1.1.1.2.2 bouyer ******************************************************************************/
93 1.1.1.1.2.2 bouyer
94 1.1.1.1.2.2 bouyer ACPI_STATUS
95 1.1.1.1.2.2 bouyer AuValidateUuid (
96 1.1.1.1.2.2 bouyer char *InString)
97 1.1.1.1.2.2 bouyer {
98 1.1.1.1.2.2 bouyer UINT32 i;
99 1.1.1.1.2.2 bouyer
100 1.1.1.1.2.2 bouyer
101 1.1.1.1.2.2 bouyer if (!InString || (ACPI_STRLEN (InString) != UUID_STRING_LENGTH))
102 1.1.1.1.2.2 bouyer {
103 1.1.1.1.2.2 bouyer return (AE_BAD_PARAMETER);
104 1.1.1.1.2.2 bouyer }
105 1.1.1.1.2.2 bouyer
106 1.1.1.1.2.2 bouyer /* Check all 36 characters for correct format */
107 1.1.1.1.2.2 bouyer
108 1.1.1.1.2.2 bouyer for (i = 0; i < UUID_STRING_LENGTH; i++)
109 1.1.1.1.2.2 bouyer {
110 1.1.1.1.2.2 bouyer /* Must have 4 hyphens (dashes) in these positions: */
111 1.1.1.1.2.2 bouyer
112 1.1.1.1.2.2 bouyer if ((i == UUID_HYPHEN1_OFFSET) ||
113 1.1.1.1.2.2 bouyer (i == UUID_HYPHEN2_OFFSET) ||
114 1.1.1.1.2.2 bouyer (i == UUID_HYPHEN3_OFFSET) ||
115 1.1.1.1.2.2 bouyer (i == UUID_HYPHEN4_OFFSET))
116 1.1.1.1.2.2 bouyer {
117 1.1.1.1.2.2 bouyer if (InString[i] != '-')
118 1.1.1.1.2.2 bouyer {
119 1.1.1.1.2.2 bouyer return (AE_BAD_PARAMETER);
120 1.1.1.1.2.2 bouyer }
121 1.1.1.1.2.2 bouyer }
122 1.1.1.1.2.2 bouyer
123 1.1.1.1.2.2 bouyer /* All other positions must contain hex digits */
124 1.1.1.1.2.2 bouyer
125 1.1.1.1.2.2 bouyer else
126 1.1.1.1.2.2 bouyer {
127 1.1.1.1.2.2 bouyer if (!isxdigit ((int) InString[i]))
128 1.1.1.1.2.2 bouyer {
129 1.1.1.1.2.2 bouyer return (AE_BAD_PARAMETER);
130 1.1.1.1.2.2 bouyer }
131 1.1.1.1.2.2 bouyer }
132 1.1.1.1.2.2 bouyer }
133 1.1.1.1.2.2 bouyer
134 1.1.1.1.2.2 bouyer return (AE_OK);
135 1.1.1.1.2.2 bouyer }
136 1.1.1.1.2.2 bouyer
137 1.1.1.1.2.2 bouyer
138 1.1.1.1.2.2 bouyer /*******************************************************************************
139 1.1.1.1.2.2 bouyer *
140 1.1.1.1.2.2 bouyer * FUNCTION: AuConvertStringToUuid
141 1.1.1.1.2.2 bouyer *
142 1.1.1.1.2.2 bouyer * PARAMETERS: InString - 36-byte formatted UUID string
143 1.1.1.1.2.2 bouyer * UuidBuffer - 16-byte UUID buffer
144 1.1.1.1.2.2 bouyer *
145 1.1.1.1.2.2 bouyer * RETURN: Status
146 1.1.1.1.2.2 bouyer *
147 1.1.1.1.2.2 bouyer * DESCRIPTION: Convert 36-byte formatted UUID string to 16-byte UUID buffer
148 1.1.1.1.2.2 bouyer *
149 1.1.1.1.2.2 bouyer ******************************************************************************/
150 1.1.1.1.2.2 bouyer
151 1.1.1.1.2.2 bouyer ACPI_STATUS
152 1.1.1.1.2.2 bouyer AuConvertStringToUuid (
153 1.1.1.1.2.2 bouyer char *InString,
154 1.1.1.1.2.2 bouyer char *UuidBuffer)
155 1.1.1.1.2.2 bouyer {
156 1.1.1.1.2.2 bouyer UINT32 i;
157 1.1.1.1.2.2 bouyer
158 1.1.1.1.2.2 bouyer
159 1.1.1.1.2.2 bouyer if (!InString || !UuidBuffer)
160 1.1.1.1.2.2 bouyer {
161 1.1.1.1.2.2 bouyer return (AE_BAD_PARAMETER);
162 1.1.1.1.2.2 bouyer }
163 1.1.1.1.2.2 bouyer
164 1.1.1.1.2.2 bouyer for (i = 0; i < UUID_BUFFER_LENGTH; i++)
165 1.1.1.1.2.2 bouyer {
166 1.1.1.1.2.2 bouyer UuidBuffer[i] = (char) (UtHexCharToValue (InString[Gbl_MapToUuidOffset[i]]) << 4);
167 1.1.1.1.2.2 bouyer UuidBuffer[i] |= (char) UtHexCharToValue (InString[Gbl_MapToUuidOffset[i] + 1]);
168 1.1.1.1.2.2 bouyer }
169 1.1.1.1.2.2 bouyer
170 1.1.1.1.2.2 bouyer return (AE_OK);
171 1.1.1.1.2.2 bouyer }
172 1.1.1.1.2.2 bouyer
173 1.1.1.1.2.2 bouyer
174 1.1.1.1.2.2 bouyer /*******************************************************************************
175 1.1.1.1.2.2 bouyer *
176 1.1.1.1.2.2 bouyer * FUNCTION: AuConvertUuidToString
177 1.1.1.1.2.2 bouyer *
178 1.1.1.1.2.2 bouyer * PARAMETERS: UuidBuffer - 16-byte UUID buffer
179 1.1.1.1.2.2 bouyer * OutString - 36-byte formatted UUID string
180 1.1.1.1.2.2 bouyer *
181 1.1.1.1.2.2 bouyer * RETURN: Status
182 1.1.1.1.2.2 bouyer *
183 1.1.1.1.2.2 bouyer * DESCRIPTION: Convert 16-byte UUID buffer to 36-byte formatted UUID string
184 1.1.1.1.2.2 bouyer * OutString must be 37 bytes to include null terminator.
185 1.1.1.1.2.2 bouyer *
186 1.1.1.1.2.2 bouyer ******************************************************************************/
187 1.1.1.1.2.2 bouyer
188 1.1.1.1.2.2 bouyer ACPI_STATUS
189 1.1.1.1.2.2 bouyer AuConvertUuidToString (
190 1.1.1.1.2.2 bouyer char *UuidBuffer,
191 1.1.1.1.2.2 bouyer char *OutString)
192 1.1.1.1.2.2 bouyer {
193 1.1.1.1.2.2 bouyer UINT32 i;
194 1.1.1.1.2.2 bouyer
195 1.1.1.1.2.2 bouyer
196 1.1.1.1.2.2 bouyer if (!UuidBuffer || !OutString)
197 1.1.1.1.2.2 bouyer {
198 1.1.1.1.2.2 bouyer return (AE_BAD_PARAMETER);
199 1.1.1.1.2.2 bouyer }
200 1.1.1.1.2.2 bouyer
201 1.1.1.1.2.2 bouyer for (i = 0; i < UUID_BUFFER_LENGTH; i++)
202 1.1.1.1.2.2 bouyer {
203 1.1.1.1.2.2 bouyer OutString[Gbl_MapToUuidOffset[i]] = (UINT8) AslHexLookup[(UuidBuffer[i] >> 4) & 0xF];
204 1.1.1.1.2.2 bouyer OutString[Gbl_MapToUuidOffset[i] + 1] = (UINT8) AslHexLookup[UuidBuffer[i] & 0xF];
205 1.1.1.1.2.2 bouyer }
206 1.1.1.1.2.2 bouyer
207 1.1.1.1.2.2 bouyer /* Insert required hyphens (dashes) */
208 1.1.1.1.2.2 bouyer
209 1.1.1.1.2.2 bouyer OutString[UUID_HYPHEN1_OFFSET] =
210 1.1.1.1.2.2 bouyer OutString[UUID_HYPHEN2_OFFSET] =
211 1.1.1.1.2.2 bouyer OutString[UUID_HYPHEN3_OFFSET] =
212 1.1.1.1.2.2 bouyer OutString[UUID_HYPHEN4_OFFSET] = '-';
213 1.1.1.1.2.2 bouyer
214 1.1.1.1.2.2 bouyer OutString[UUID_STRING_LENGTH] = 0; /* Null terminate */
215 1.1.1.1.2.2 bouyer return (AE_OK);
216 1.1.1.1.2.2 bouyer }
217