utuuid.c revision 271440
1271440Sjkim/****************************************************************************** 2271440Sjkim * 3271440Sjkim * Module Name: utuuid -- UUID support functions 4271440Sjkim * 5271440Sjkim *****************************************************************************/ 6271440Sjkim 7271440Sjkim/* 8271440Sjkim * Copyright (C) 2000 - 2014, Intel Corp. 9271440Sjkim * All rights reserved. 10271440Sjkim * 11271440Sjkim * Redistribution and use in source and binary forms, with or without 12271440Sjkim * modification, are permitted provided that the following conditions 13271440Sjkim * are met: 14271440Sjkim * 1. Redistributions of source code must retain the above copyright 15271440Sjkim * notice, this list of conditions, and the following disclaimer, 16271440Sjkim * without modification. 17271440Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18271440Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 19271440Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 20271440Sjkim * including a substantially similar Disclaimer requirement for further 21271440Sjkim * binary redistribution. 22271440Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 23271440Sjkim * of any contributors may be used to endorse or promote products derived 24271440Sjkim * from this software without specific prior written permission. 25271440Sjkim * 26271440Sjkim * Alternatively, this software may be distributed under the terms of the 27271440Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 28271440Sjkim * Software Foundation. 29271440Sjkim * 30271440Sjkim * NO WARRANTY 31271440Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32271440Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33271440Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34271440Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35271440Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36271440Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37271440Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38271440Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39271440Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40271440Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41271440Sjkim * POSSIBILITY OF SUCH DAMAGES. 42271440Sjkim */ 43271440Sjkim 44271440Sjkim#define __UTUUID_C__ 45271440Sjkim 46271440Sjkim#include "acpi.h" 47271440Sjkim#include "accommon.h" 48271440Sjkim 49271440Sjkim#define _COMPONENT ACPI_COMPILER 50271440Sjkim ACPI_MODULE_NAME ("utuuid") 51271440Sjkim 52271440Sjkim 53271440Sjkim/* 54271440Sjkim * UUID support functions. 55271440Sjkim * 56271440Sjkim * This table is used to convert an input UUID ascii string to a 16 byte 57271440Sjkim * buffer and the reverse. The table maps a UUID buffer index 0-15 to 58271440Sjkim * the index within the 36-byte UUID string where the associated 2-byte 59271440Sjkim * hex value can be found. 60271440Sjkim * 61271440Sjkim * 36-byte UUID strings are of the form: 62271440Sjkim * aabbccdd-eeff-gghh-iijj-kkllmmnnoopp 63271440Sjkim * Where aa-pp are one byte hex numbers, made up of two hex digits 64271440Sjkim * 65271440Sjkim * Note: This table is basically the inverse of the string-to-offset table 66271440Sjkim * found in the ACPI spec in the description of the ToUUID macro. 67271440Sjkim */ 68271440Sjkimconst UINT8 AcpiGbl_MapToUuidOffset[UUID_BUFFER_LENGTH] = 69271440Sjkim{ 70271440Sjkim 6,4,2,0,11,9,16,14,19,21,24,26,28,30,32,34 71271440Sjkim}; 72271440Sjkim 73271440Sjkim 74271440Sjkim/******************************************************************************* 75271440Sjkim * 76271440Sjkim * FUNCTION: AcpiUtConvertStringToUuid 77271440Sjkim * 78271440Sjkim * PARAMETERS: InString - 36-byte formatted UUID string 79271440Sjkim * UuidBuffer - Where the 16-byte UUID buffer is returned 80271440Sjkim * 81271440Sjkim * RETURN: None. Output data is returned in the UuidBuffer 82271440Sjkim * 83271440Sjkim * DESCRIPTION: Convert a 36-byte formatted UUID string to 16-byte UUID buffer 84271440Sjkim * 85271440Sjkim ******************************************************************************/ 86271440Sjkim 87271440Sjkimvoid 88271440SjkimAcpiUtConvertStringToUuid ( 89271440Sjkim char *InString, 90271440Sjkim UINT8 *UuidBuffer) 91271440Sjkim{ 92271440Sjkim UINT32 i; 93271440Sjkim 94271440Sjkim 95271440Sjkim for (i = 0; i < UUID_BUFFER_LENGTH; i++) 96271440Sjkim { 97271440Sjkim UuidBuffer[i] = 98271440Sjkim (AcpiUtAsciiCharToHex (InString[AcpiGbl_MapToUuidOffset[i]]) << 4); 99271440Sjkim 100271440Sjkim UuidBuffer[i] |= 101271440Sjkim AcpiUtAsciiCharToHex (InString[AcpiGbl_MapToUuidOffset[i] + 1]); 102271440Sjkim } 103271440Sjkim} 104