Chameleon

Chameleon Commit Details

Date:2010-02-15 23:16:34 (14 years 2 months ago)
Author:JrCs
Commit:79
Parents: 78
Message:New functions to convert UUID to and from string
Changes:
M/branches/JrCs/i386/libsaio/convert.c
M/branches/JrCs/i386/libsaio/convert.h
M/branches/JrCs/i386/libsaio/fake_efi.c

File differences

branches/JrCs/i386/libsaio/convert.c
77
88
99
10
11
10
11
1212
13
14
15
16
17
18
19
20
21
13
14
15
16
17
2218
2319
24
25
26
27
20
21
2822
29
23
3024
31
32
33
34
35
25
26
27
28
3629
37
38
39
40
41
42
43
44
45
46
47
48
49
30
31
32
33
5034
51
52
53
35
36
37
38
39
5440
55
56
41
42
43
44
5745
58
46
47
48
5949
6050
6151
......
133123
134124
135125
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#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 */
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)<UUID_LEN) return (EFI_CHAR8*) 0;
while(*szInUUID) if (*szInUUID!='-') *p++=*szInUUID++; else szInUUID++;
*p='\0';
ret = convertHexStr2Binary(szUUID, &size);
if (!ret || size!=UUID_LEN)
{
verbose("UUID: cannot convert string <%s> to valid UUID.\n", szUUID);
return (EFI_CHAR8*) 0;
}
return (EFI_CHAR8*) ret; // new allocated buffer containing the converted string to bin
}
*/
branches/JrCs/i386/libsaio/convert.h
1010
1111
1212
13
14
1315
14
15
16
16
17
18
1719
1820
1921
#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)
branches/JrCs/i386/libsaio/fake_efi.c
8080
8181
8282
83
83
8484
8585
8686
......
332332
333333
334334
335
335
336336
337337
338338
339
340
339
340
341341
342342
343343
......
351351
352352
353353
354
354355
355356
356357
......
358359
359360
360361
361
362
362
363
364
363365
364366
365367
......
428430
429431
430432
431
432
433
433
434
435
436
437
438
439
434440
435441
436442
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};
/* 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
}
if (SystemId == NULL) {
uuid_string_t UUIDstr;
// EFI_CHAR8* ret = getUUIDFromString(sysId);
//
// if(!sysId || !ret) { // try bios dmi info UUID extraction
// 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
}
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.
*/

Archive Download the corresponding diff file

Revision: 79