mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-06-28 08:16:54 +00:00
dm: mei: add guid handling functions
libuuid sports only uuid (big endian encoding), though mei requires guids (little endian encoding). The base types are based on <linux/uuid.h> header. Tracked-On: #1536 Signed-off-by: Alexander Usyskin <alexander.usyskin@intel.com> Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Acked-by: Wang, Yu1 <yu1.wang@intel.com>
This commit is contained in:
parent
d141aebdcd
commit
4e057c32d2
131
devicemodel/hw/pci/virtio/virtio_mei.c
Normal file
131
devicemodel/hw/pci/virtio/virtio_mei.c
Normal file
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
*/
|
||||
/*
|
||||
* MEI device virtualization.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/uio.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <dirent.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <linux/uuid.h>
|
||||
#include <linux/mei.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "vmmapi.h"
|
||||
#include "mevent.h"
|
||||
#include "pci_core.h"
|
||||
#include "virtio.h"
|
||||
#include "dm.h"
|
||||
|
||||
#include "mei.h"
|
||||
|
||||
#ifndef UUID_STR_LEN
|
||||
#define UUID_STR_LEN 37
|
||||
#endif
|
||||
|
||||
#ifndef GUID_INIT
|
||||
#define GUID_INIT(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7) \
|
||||
UUID_LE(a, b, c, d0, d1, d2, d3, d4, d5, d6, d7)
|
||||
#endif
|
||||
|
||||
static int guid_parse(const char *str, size_t maxlen, guid_t *guid)
|
||||
{
|
||||
const char *p = "00000000-0000-0000-0000-000000000000";
|
||||
const size_t len = strnlen(p, UUID_STR_LEN);
|
||||
uint32_t a;
|
||||
uint16_t b, c;
|
||||
uint8_t d[2], e[6];
|
||||
char buf[3];
|
||||
unsigned int i;
|
||||
|
||||
if (strnlen(str, maxlen) != len)
|
||||
return -1;
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
if (str[i] == '-') {
|
||||
if (p[i] == '-')
|
||||
continue;
|
||||
else
|
||||
return -1;
|
||||
} else if (!isxdigit(str[i])) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
a = strtoul(str + 0, NULL, 16);
|
||||
b = strtoul(str + 9, NULL, 16);
|
||||
c = strtoul(str + 14, NULL, 16);
|
||||
|
||||
buf[2] = 0;
|
||||
for (i = 0; i < 2; i++) {
|
||||
buf[0] = str[19 + i * 2];
|
||||
buf[1] = str[19 + i * 2 + 1];
|
||||
d[i] = strtoul(buf, NULL, 16);
|
||||
}
|
||||
|
||||
for (i = 0; i < 6; i++) {
|
||||
buf[0] = str[24 + i * 2];
|
||||
buf[1] = str[24 + i * 2 + 1];
|
||||
e[i] = strtoul(buf, NULL, 16);
|
||||
}
|
||||
|
||||
*guid = GUID_INIT(a, b, c,
|
||||
d[0], d[1], e[0], e[1], e[2], e[3], e[4], e[5]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int guid_unparse(const guid_t *guid, char *str, size_t len)
|
||||
{
|
||||
unsigned int i;
|
||||
size_t pos = 0;
|
||||
|
||||
if (len < UUID_STR_LEN)
|
||||
return -EINVAL;
|
||||
|
||||
pos += snprintf(str + pos, len - pos, "%02x", guid->b[3]);
|
||||
pos += snprintf(str + pos, len - pos, "%02x", guid->b[2]);
|
||||
pos += snprintf(str + pos, len - pos, "%02x", guid->b[1]);
|
||||
pos += snprintf(str + pos, len - pos, "%02x", guid->b[0]);
|
||||
str[pos] = '-';
|
||||
pos++;
|
||||
pos += snprintf(str + pos, len - pos, "%02x", guid->b[5]);
|
||||
pos += snprintf(str + pos, len - pos, "%02x", guid->b[4]);
|
||||
str[pos] = '-';
|
||||
pos++;
|
||||
pos += snprintf(str + pos, len - pos, "%02x", guid->b[7]);
|
||||
pos += snprintf(str + pos, len - pos, "%02x", guid->b[6]);
|
||||
str[pos] = '-';
|
||||
pos++;
|
||||
pos += snprintf(str + pos, len - pos, "%02x", guid->b[8]);
|
||||
pos += snprintf(str + pos, len - pos, "%02x", guid->b[9]);
|
||||
str[pos] = '-';
|
||||
pos++;
|
||||
for (i = 10; i < 16; i++)
|
||||
pos += snprintf(str + pos, len - pos, "%02x", guid->b[i]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user