hyperv: Factor out snprinf_hv_guid()

Submitted by:	Ju Sun <junsu microsoft com>
Reviewed by:	Dexuan Cui <decui microsoft com>, sephe
MFC after:	1 week
Sponsored by:	Microsoft OSTC
Differential Revision:	https://reviews.freebsd.org/D5651
This commit is contained in:
Sepherosa Ziehau 2016-03-21 06:54:21 +00:00
parent 53fd961f05
commit 57a339543d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=297142
3 changed files with 19 additions and 38 deletions

View File

@ -124,6 +124,8 @@ typedef struct hv_guid {
unsigned char data[16];
} __packed hv_guid;
int snprintf_hv_guid(char *, size_t, const hv_guid *);
#define HV_NIC_GUID \
.data = {0x63, 0x51, 0x61, 0xF8, 0x3E, 0xDF, 0xc5, 0x46, \
0x91, 0x3F, 0xF2, 0xD2, 0xF9, 0x65, 0xED, 0x0E}

View File

@ -304,28 +304,11 @@ hv_kvp_convert_utf16_ipinfo_to_utf8(struct hv_kvp_ip_msg *host_ip_msg,
{
int err_ip, err_subnet, err_gway, err_dns, err_adap;
int UNUSED_FLAG = 1;
int guid_index;
struct hv_device *hv_dev; /* GUID Data Structure */
hn_softc_t *sc; /* hn softc structure */
char if_name[4];
unsigned char guid_instance[40];
char *guid_data = NULL;
char buf[39];
struct guid_extract {
char a1[2];
char a2[2];
char a3[2];
char a4[2];
char b1[2];
char b2[2];
char c1[2];
char c2[2];
char d[4];
char e[12];
};
struct guid_extract *id;
device_t *devs;
int devcnt;
@ -352,17 +335,7 @@ hv_kvp_convert_utf16_ipinfo_to_utf8(struct hv_kvp_ip_msg *host_ip_msg,
/* Trying to find GUID of Network Device */
hv_dev = sc->hn_dev_obj;
for (guid_index = 0; guid_index < 16; guid_index++) {
sprintf(&guid_instance[guid_index * 2], "%02x",
hv_dev->device_id.data[guid_index]);
}
guid_data = (char *)guid_instance;
id = (struct guid_extract *)guid_data;
snprintf(buf, sizeof(buf), "{%.2s%.2s%.2s%.2s-%.2s%.2s-%.2s%.2s-%.4s-%s}",
id->a4, id->a3, id->a2, id->a1,
id->b2, id->b1, id->c2, id->c1, id->d, id->e);
guid_data = NULL;
snprintf_hv_guid(buf, sizeof(buf), &hv_dev->device_id);
sprintf(if_name, "%s%d", "hn", device_get_unit(devs[devcnt]));
if (strncmp(buf, (char *)umsg->body.kvp_ip_val.adapter_id, 39) == 0) {

View File

@ -59,6 +59,7 @@ __FBSDID("$FreeBSD$");
#include <sys/pcpu.h>
#include <x86/apicvar.h>
#include <dev/hyperv/include/hyperv.h>
#include "hv_vmbus_priv.h"
#include <contrib/dev/acpica/include/acpi.h>
@ -300,15 +301,17 @@ hv_vmbus_child_device_create(
return (child_dev);
}
static void
print_dev_guid(struct hv_device *dev)
int
snprintf_hv_guid(char *buf, size_t sz, const hv_guid *guid)
{
int i;
unsigned char guid_name[100];
for (i = 0; i < 32; i += 2)
sprintf(&guid_name[i], "%02x", dev->class_id.data[i / 2]);
if(bootverbose)
printf("VMBUS: Class ID: %s\n", guid_name);
int cnt;
const unsigned char *d = guid->data;
cnt = snprintf(buf, sz,
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
d[3], d[2], d[1], d[0], d[5], d[4], d[7], d[6],
d[8], d[9], d[10], d[11], d[12], d[13], d[14], d[15]);
return (cnt);
}
int
@ -317,8 +320,11 @@ hv_vmbus_child_device_register(struct hv_device *child_dev)
device_t child;
int ret = 0;
print_dev_guid(child_dev);
if (bootverbose) {
char name[40];
snprintf_hv_guid(name, sizeof(name), &child_dev->class_id);
printf("VMBUS: Class ID: %s\n", name);
}
child = device_add_child(vmbus_devp, NULL, -1);
child_dev->device = child;