Index: branches/JrCs/i386/libsaio/convert.c =================================================================== --- branches/JrCs/i386/libsaio/convert.c (revision 78) +++ branches/JrCs/i386/libsaio/convert.c (revision 79) @@ -7,55 +7,45 @@ #include "convert.h" -/** Transform a 16 bytes hexadecimal value UUID to a string */ -const char* getStringFromUUID(const EFI_CHAR8* eUUID) +/* Return a string that is the representation of a 16 bytes UUID */ +void getStringFromUUID(const uuid_t uuid, uuid_string_t out) { - static char msg[UUID_LEN*2 + 8] = ""; - if (!eUUID) return NULL; - const unsigned char * uuid = (unsigned char*) eUUID; - sprintf(msg, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", - uuid[0], uuid[1], uuid[2], uuid[3], - uuid[4], uuid[5], uuid[6], uuid[7], - uuid[8], uuid[9], uuid[10],uuid[11], - uuid[12],uuid[13],uuid[14],uuid[15]); - return msg; + sprintf((char*) out, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X", + uuid[0], uuid[1], uuid[2], uuid[3], + uuid[4], uuid[5], uuid[6], uuid[7], + uuid[8], uuid[9], uuid[10],uuid[11], + uuid[12],uuid[13],uuid[14],uuid[15]); } -/* Parse an UUID string into an (EFI_CHAR8*) buffer - * Return a new allocated uuid - */ -EFI_CHAR8* newUUIDFromString(const char *source) +/* Parse an UUID string and return a new allocated UUID */ +uuid_t* newUUIDFromString(const char *source) { - if (! source) return NULL; + if (! source) return NULL; - char* p = (char*) source; - int i; - char buf[3]; - EFI_CHAR8 uuid[UUID_LEN+1]; - EFI_CHAR8* result; + const char* p = source; + int i; + int len; + char uuid_hex[UUID_LEN*2+1]; - buf[2] = '\0'; - for (i=0; i < UUID_LEN; i++) { - if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1])) { - return NULL; - } - buf[0] = *p++; - buf[1] = *p++; - uuid[i] = (unsigned char) strtoul(buf, NULL, 16); - if (*p == '-' && (i % 2) == 1 && i < UUID_LEN - 1) { - p++; - } - } - uuid[UUID_LEN]='\0'; + // Check if UUID is valid + for (i=0; *p != 0 && i < UUID_LEN*2; p++) { + if (*p == '-') + continue; - if (*p != '\0') { - return NULL; - } + if (!isxdigit(*p)) { + return NULL; + } + uuid_hex[i++] = *p; + } - result = malloc(UUID_LEN+1); - bcopy(uuid, result, UUID_LEN+1); + // invalid size + if (*p != 0 || i != UUID_LEN*2) { + return NULL; + } - return result; + uuid_hex[i] = 0; // null terminated string + + return convertHexStr2Binary(uuid_hex, &len); } /** XXX AsereBLN replace by strtoul */ @@ -133,26 +123,3 @@ return NULL; } } - -// FIXME: can't use my original code here, -// Ironically, trying to reuse convertHexStr2Binary() would RESET the system! -/* -static EFI_CHAR8* getUUIDFromString2(const char * szInUUID) -{ - char szUUID[UUID_LEN+1], *p=szUUID; - int size=0; - void* ret; - - if (!szInUUID || strlen(szInUUID) to valid UUID.\n", szUUID); - return (EFI_CHAR8*) 0; - } - return (EFI_CHAR8*) ret; // new allocated buffer containing the converted string to bin -} -*/ Index: branches/JrCs/i386/libsaio/convert.h =================================================================== --- branches/JrCs/i386/libsaio/convert.h (revision 78) +++ branches/JrCs/i386/libsaio/convert.h (revision 79) @@ -10,10 +10,12 @@ #include "efi.h" #define UUID_LEN 16 +typedef unsigned char uuid_t[UUID_LEN]; +typedef unsigned char uuid_string_t[sizeof ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx") ]; -const char * getStringFromUUID(const EFI_CHAR8* uuid); -EFI_CHAR8* newUUIDFromString(const char *source); -void *convertHexStr2Binary(const char *hexStr, int *outLength); +void getStringFromUUID(const uuid_t uuid, uuid_string_t out); +uuid_t* newUUIDFromString(const char *source); +void * convertHexStr2Binary(const char *hexStr, int *outLength); uint32_t ascii_hex_to_int(char *buff); static inline uint16_t dp_swap16(uint16_t toswap) Index: branches/JrCs/i386/libsaio/fake_efi.c =================================================================== --- branches/JrCs/i386/libsaio/fake_efi.c (revision 78) +++ branches/JrCs/i386/libsaio/fake_efi.c (revision 79) @@ -80,7 +80,7 @@ static EFI_UINT32 const FIRMWARE_REVISION = 132; /* FIXME: Find a constant for this. */ /* Default platform system_id (fix by IntVar) */ -static EFI_CHAR8 const SYSTEM_ID[] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10}; //random value gen by uuidgen +static uuid_t const SYSTEM_ID = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10}; //random value gen by uuidgen /* Just a ret instruction */ static uint8_t const VOIDRET_INSTRUCTIONS[] = {0xc3}; @@ -332,12 +332,12 @@ /* return a binary UUID value from the overriden SystemID, * or from a fixed value if none found */ -static const EFI_CHAR8* getSystemID() +static uuid_t* getSystemID() { bool pause = FALSE; int len; - const char* StrSystemId = NULL; - const EFI_CHAR8* SystemId = NULL; + const char* StrSystemId = NULL; + uuid_t* SystemId = NULL; // unable to determine UUID for host. Error: 35 fix @@ -351,6 +351,7 @@ } if (SystemId == NULL) { + uuid_string_t UUIDstr; // EFI_CHAR8* ret = getUUIDFromString(sysId); // // if(!sysId || !ret) { // try bios dmi info UUID extraction @@ -358,8 +359,9 @@ // sysId = 0; // } // if(!ret) // no bios dmi UUID available, set a fixed value for system-id - SystemId = SYSTEM_ID; - error("Using a fixed SystemID: '%s'\n", getStringFromUUID(SystemId)); + SystemId = (uuid_t*) &SYSTEM_ID; + getStringFromUUID(*SystemId, UUIDstr); + error("Using a fixed SystemID: '%s'\n", UUIDstr); // // verbose("Customizing SystemID with : %s\n", getStringFromUUID(ret)); // apply a nice formatting to the displayed output } @@ -428,9 +430,13 @@ DT__AddProperty(efiPlatformNode, CPU_Frequency_prop, sizeof(uint64_t), &Platform.CPU.CPUFrequency); /* Set EFI system-id. */ - const EFI_CHAR8* systemId = getSystemID(); - verbose("Customizing %s with: %s\n", SYSTEM_ID_PROP, getStringFromUUID(systemId)); - DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, UUID_LEN, systemId); + uuid_t* systemId = getSystemID(); + if (gVerboseMode) { + uuid_string_t uuid_string; + getStringFromUUID(*systemId, uuid_string); + verbose("Customizing %s with: %s\n", SYSTEM_ID_PROP, uuid_string); + } + DT__AddProperty(efiPlatformNode, SYSTEM_ID_PROP, sizeof(uuid_t), systemId); /* Fill /efi/device-properties node. */