asluuid.c revision 281075
1227825Stheraven/****************************************************************************** 2227825Stheraven * 3227825Stheraven * Module Name: asluuid-- compiler UUID support 4227825Stheraven * 5227825Stheraven *****************************************************************************/ 6227825Stheraven 7227825Stheraven/* 8227825Stheraven * Copyright (C) 2000 - 2015, Intel Corp. 9227825Stheraven * All rights reserved. 10227825Stheraven * 11227825Stheraven * Redistribution and use in source and binary forms, with or without 12227825Stheraven * modification, are permitted provided that the following conditions 13227825Stheraven * are met: 14227825Stheraven * 1. Redistributions of source code must retain the above copyright 15227825Stheraven * notice, this list of conditions, and the following disclaimer, 16227825Stheraven * without modification. 17227825Stheraven * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18227825Stheraven * substantially similar to the "NO WARRANTY" disclaimer below 19227825Stheraven * ("Disclaimer") and any redistribution must be conditioned upon 20227825Stheraven * including a substantially similar Disclaimer requirement for further 21227825Stheraven * binary redistribution. 22227825Stheraven * 3. Neither the names of the above-listed copyright holders nor the names 23227825Stheraven * of any contributors may be used to endorse or promote products derived 24227825Stheraven * from this software without specific prior written permission. 25227825Stheraven * 26227825Stheraven * Alternatively, this software may be distributed under the terms of the 27227825Stheraven * GNU General Public License ("GPL") version 2 as published by the Free 28227825Stheraven * Software Foundation. 29227825Stheraven * 30227825Stheraven * NO WARRANTY 31227825Stheraven * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32227825Stheraven * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33227825Stheraven * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34227825Stheraven * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35227825Stheraven * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36227825Stheraven * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37227825Stheraven * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38227825Stheraven * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39227825Stheraven * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40227825Stheraven * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41227825Stheraven * POSSIBILITY OF SUCH DAMAGES. 42227825Stheraven */ 43227825Stheraven 44227825Stheraven#include <contrib/dev/acpica/compiler/aslcompiler.h> 45227825Stheraven 46227825Stheraven#define _COMPONENT ACPI_COMPILER 47227825Stheraven ACPI_MODULE_NAME ("asluuid") 48227825Stheraven 49227825Stheraven 50227825Stheravenextern UINT8 AcpiGbl_MapToUuidOffset[UUID_BUFFER_LENGTH]; 51227825Stheraven 52227825Stheraven 53227825Stheraven/******************************************************************************* 54227825Stheraven * 55227825Stheraven * FUNCTION: AuValiduateUuid 56227825Stheraven * 57227825Stheraven * PARAMETERS: InString - 36-byte formatted UUID string 58227825Stheraven * 59227825Stheraven * RETURN: Status 60227825Stheraven * 61227825Stheraven * DESCRIPTION: Check all 36 characters for correct format 62227825Stheraven * 63227825Stheraven ******************************************************************************/ 64227825Stheraven 65227825StheravenACPI_STATUS 66227825StheravenAuValidateUuid ( 67227825Stheraven char *InString) 68227825Stheraven{ 69227825Stheraven UINT32 i; 70227825Stheraven 71227825Stheraven 72227825Stheraven if (!InString || (ACPI_STRLEN (InString) != UUID_STRING_LENGTH)) 73227825Stheraven { 74227825Stheraven return (AE_BAD_PARAMETER); 75227825Stheraven } 76227825Stheraven 77227825Stheraven /* Check all 36 characters for correct format */ 78227825Stheraven 79227825Stheraven for (i = 0; i < UUID_STRING_LENGTH; i++) 80227825Stheraven { 81227825Stheraven /* Must have 4 hyphens (dashes) in these positions: */ 82227825Stheraven 83227825Stheraven if ((i == UUID_HYPHEN1_OFFSET) || 84227825Stheraven (i == UUID_HYPHEN2_OFFSET) || 85227825Stheraven (i == UUID_HYPHEN3_OFFSET) || 86227825Stheraven (i == UUID_HYPHEN4_OFFSET)) 87227825Stheraven { 88227825Stheraven if (InString[i] != '-') 89227825Stheraven { 90227825Stheraven return (AE_BAD_PARAMETER); 91227825Stheraven } 92227825Stheraven } 93227825Stheraven 94227825Stheraven /* All other positions must contain hex digits */ 95227825Stheraven 96227825Stheraven else 97227825Stheraven { 98227825Stheraven if (!isxdigit ((int) InString[i])) 99227825Stheraven { 100227825Stheraven return (AE_BAD_PARAMETER); 101227825Stheraven } 102227825Stheraven } 103227825Stheraven } 104227825Stheraven 105227825Stheraven return (AE_OK); 106227825Stheraven} 107227825Stheraven 108227825Stheraven 109227825Stheraven/******************************************************************************* 110227825Stheraven * 111227825Stheraven * FUNCTION: AuConvertUuidToString 112227825Stheraven * 113227825Stheraven * PARAMETERS: UuidBuffer - 16-byte UUID buffer 114227825Stheraven * OutString - 36-byte formatted UUID string 115227825Stheraven * 116227825Stheraven * RETURN: Status 117227825Stheraven * 118227825Stheraven * DESCRIPTION: Convert 16-byte UUID buffer to 36-byte formatted UUID string 119227825Stheraven * OutString must be 37 bytes to include null terminator. 120232950Stheraven * 121232950Stheraven ******************************************************************************/ 122227825Stheraven 123227825StheravenACPI_STATUS 124227825StheravenAuConvertUuidToString ( 125227825Stheraven char *UuidBuffer, 126227825Stheraven char *OutString) 127227825Stheraven{ 128227825Stheraven UINT32 i; 129232950Stheraven 130232950Stheraven 131232950Stheraven if (!UuidBuffer || !OutString) 132232950Stheraven { 133232950Stheraven return (AE_BAD_PARAMETER); 134232950Stheraven } 135232950Stheraven 136232950Stheraven for (i = 0; i < UUID_BUFFER_LENGTH; i++) 137232950Stheraven { 138232950Stheraven OutString[AcpiGbl_MapToUuidOffset[i]] = 139232950Stheraven AcpiUtHexToAsciiChar (UuidBuffer[i], 4); 140232950Stheraven 141232950Stheraven OutString[AcpiGbl_MapToUuidOffset[i] + 1] = 142232950Stheraven AcpiUtHexToAsciiChar (UuidBuffer[i], 0); 143232950Stheraven } 144232950Stheraven 145232950Stheraven /* Insert required hyphens (dashes) */ 146232950Stheraven 147232950Stheraven OutString[UUID_HYPHEN1_OFFSET] = 148232950Stheraven OutString[UUID_HYPHEN2_OFFSET] = 149232950Stheraven OutString[UUID_HYPHEN3_OFFSET] = 150232950Stheraven OutString[UUID_HYPHEN4_OFFSET] = '-'; 151232950Stheraven 152232950Stheraven OutString[UUID_STRING_LENGTH] = 0; /* Null terminate */ 153232950Stheraven return (AE_OK); 154232950Stheraven} 155232950Stheraven