Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: utuuid -- UUID support functions
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 
0013 #define _COMPONENT          ACPI_COMPILER
0014 ACPI_MODULE_NAME("utuuid")
0015 
0016 #if (defined ACPI_ASL_COMPILER || defined ACPI_EXEC_APP || defined ACPI_HELP_APP)
0017 /*
0018  * UUID support functions.
0019  *
0020  * This table is used to convert an input UUID ascii string to a 16 byte
0021  * buffer and the reverse. The table maps a UUID buffer index 0-15 to
0022  * the index within the 36-byte UUID string where the associated 2-byte
0023  * hex value can be found.
0024  *
0025  * 36-byte UUID strings are of the form:
0026  *     aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
0027  * Where aa-pp are one byte hex numbers, made up of two hex digits
0028  *
0029  * Note: This table is basically the inverse of the string-to-offset table
0030  * found in the ACPI spec in the description of the to_UUID macro.
0031  */
0032 const u8 acpi_gbl_map_to_uuid_offset[UUID_BUFFER_LENGTH] = {
0033     6, 4, 2, 0, 11, 9, 16, 14, 19, 21, 24, 26, 28, 30, 32, 34
0034 };
0035 
0036 /*******************************************************************************
0037  *
0038  * FUNCTION:    acpi_ut_convert_string_to_uuid
0039  *
0040  * PARAMETERS:  in_string           - 36-byte formatted UUID string
0041  *              uuid_buffer         - Where the 16-byte UUID buffer is returned
0042  *
0043  * RETURN:      None. Output data is returned in the uuid_buffer
0044  *
0045  * DESCRIPTION: Convert a 36-byte formatted UUID string to 16-byte UUID buffer
0046  *
0047  ******************************************************************************/
0048 
0049 void acpi_ut_convert_string_to_uuid(char *in_string, u8 *uuid_buffer)
0050 {
0051     u32 i;
0052 
0053     for (i = 0; i < UUID_BUFFER_LENGTH; i++) {
0054         uuid_buffer[i] =
0055             (acpi_ut_ascii_char_to_hex
0056              (in_string[acpi_gbl_map_to_uuid_offset[i]]) << 4);
0057 
0058         uuid_buffer[i] |=
0059             acpi_ut_ascii_char_to_hex(in_string
0060                           [acpi_gbl_map_to_uuid_offset[i] +
0061                            1]);
0062     }
0063 }
0064 
0065 /*******************************************************************************
0066  *
0067  * FUNCTION:    acpi_ut_convert_uuid_to_string
0068  *
0069  * PARAMETERS:  uuid_buffer         - 16-byte UUID buffer
0070  *              out_string          - 36-byte formatted UUID string
0071  *
0072  * RETURN:      Status
0073  *
0074  * DESCRIPTION: Convert 16-byte UUID buffer to 36-byte formatted UUID string
0075  *              out_string must be 37 bytes to include null terminator.
0076  *
0077  ******************************************************************************/
0078 
0079 acpi_status acpi_ut_convert_uuid_to_string(char *uuid_buffer, char *out_string)
0080 {
0081     u32 i;
0082 
0083     if (!uuid_buffer || !out_string) {
0084         return (AE_BAD_PARAMETER);
0085     }
0086 
0087     for (i = 0; i < UUID_BUFFER_LENGTH; i++) {
0088         out_string[acpi_gbl_map_to_uuid_offset[i]] =
0089             acpi_ut_hex_to_ascii_char(uuid_buffer[i], 4);
0090 
0091         out_string[acpi_gbl_map_to_uuid_offset[i] + 1] =
0092             acpi_ut_hex_to_ascii_char(uuid_buffer[i], 0);
0093     }
0094 
0095     /* Insert required hyphens (dashes) */
0096 
0097     out_string[UUID_HYPHEN1_OFFSET] =
0098         out_string[UUID_HYPHEN2_OFFSET] =
0099         out_string[UUID_HYPHEN3_OFFSET] =
0100         out_string[UUID_HYPHEN4_OFFSET] = '-';
0101 
0102     out_string[UUID_STRING_LENGTH] = 0; /* Null terminate */
0103     return (AE_OK);
0104 }
0105 #endif