mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 01:55:19 +00:00
[I8042PRT] Move DMI/SMBIOS parsing functions into library
This commit is contained in:
parent
d956eafda8
commit
0854c69a75
8 changed files with 179 additions and 116 deletions
|
@ -1,4 +1,7 @@
|
|||
|
||||
include_directories(
|
||||
${REACTOS_SOURCE_DIR}/sdk/lib/dmilib)
|
||||
|
||||
list(APPEND SOURCE
|
||||
createclose.c
|
||||
hwhacks.c
|
||||
|
@ -18,6 +21,7 @@ add_library(i8042prt SHARED
|
|||
i8042prt.rc)
|
||||
|
||||
set_module_type(i8042prt kernelmodedriver)
|
||||
target_link_libraries(i8042prt dmilib)
|
||||
add_importlibs(i8042prt ntoskrnl hal)
|
||||
add_pch(i8042prt i8042prt.h SOURCE)
|
||||
add_cd_file(TARGET i8042prt DESTINATION reactos/system32/drivers NO_CAB FOR all)
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include <wmiguid.h>
|
||||
#include <wmidata.h>
|
||||
#include <wmistr.h>
|
||||
#include "dmi.h"
|
||||
#include <dmilib.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
@ -21,25 +21,6 @@ const GUID MSSmBios_RawSMBiosTables_GUID = SMBIOS_DATA_GUID;
|
|||
PVOID i8042SMBiosTables;
|
||||
ULONG i8042HwFlags;
|
||||
|
||||
enum _ID_STRINGS
|
||||
{
|
||||
ID_NONE = 0,
|
||||
BIOS_VENDOR,
|
||||
BIOS_VERSION,
|
||||
BIOS_DATE,
|
||||
SYS_VENDOR,
|
||||
SYS_PRODUCT,
|
||||
SYS_VERSION,
|
||||
SYS_SERIAL,
|
||||
BOARD_VENDOR,
|
||||
BOARD_NAME,
|
||||
BOARD_VERSION,
|
||||
BOARD_SERIAL,
|
||||
BOARD_ASSET_TAG,
|
||||
|
||||
ID_STRINGS_MAX,
|
||||
};
|
||||
|
||||
typedef struct _MATCHENTRY
|
||||
{
|
||||
ULONG Type;
|
||||
|
@ -75,110 +56,16 @@ const HARDWARE_TABLE i8042HardwareTable[] =
|
|||
|
||||
|
||||
|
||||
static
|
||||
PCHAR
|
||||
GetDmiString(
|
||||
_In_ PDMI_HEADER Header,
|
||||
_In_ ULONG FieldOffset)
|
||||
{
|
||||
ULONG StringIndex;
|
||||
PCHAR String;
|
||||
|
||||
StringIndex = ((PUCHAR)Header)[FieldOffset];
|
||||
if (StringIndex == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
String = (PCHAR)Header + Header->Length;
|
||||
|
||||
while (--StringIndex != 0)
|
||||
{
|
||||
while (*String != 0)
|
||||
String++;
|
||||
|
||||
String++;
|
||||
}
|
||||
|
||||
return String;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
VOID
|
||||
i8042ParseSMBiosTables(
|
||||
_In_reads_bytes_(TableSize) PVOID SMBiosTables,
|
||||
_In_ ULONG TableSize)
|
||||
{
|
||||
PMSSmBios_RawSMBiosTables BiosTablesHeader = SMBiosTables;
|
||||
PDMI_HEADER Header;
|
||||
ULONG Remaining, i, j;
|
||||
PCHAR Data;
|
||||
ULONG i, j;
|
||||
PCHAR Strings[ID_STRINGS_MAX] = { 0 };
|
||||
|
||||
Header = (PDMI_HEADER)(&BiosTablesHeader->SMBiosData);
|
||||
Remaining = BiosTablesHeader->Size;
|
||||
|
||||
while (Remaining >= sizeof(*Header))
|
||||
{
|
||||
|
||||
if (Header->Type == DMI_ENTRY_END_OF_TABLE)
|
||||
break;
|
||||
|
||||
switch (Header->Type)
|
||||
{
|
||||
case DMI_ENTRY_BIOS:
|
||||
if (Remaining < DMI_BIOS_SIZE)
|
||||
return;
|
||||
Strings[BIOS_VENDOR] = GetDmiString(Header, DMI_BIOS_VENDOR);
|
||||
Strings[BIOS_VERSION] = GetDmiString(Header, DMI_BIOS_VERSION);
|
||||
Strings[BIOS_DATE] = GetDmiString(Header, DMI_BIOS_DATE);
|
||||
break;
|
||||
|
||||
case DMI_ENTRY_SYSTEM:
|
||||
if (Remaining < DMI_SYS_SIZE)
|
||||
return;
|
||||
Strings[SYS_VENDOR] = GetDmiString(Header, DMI_SYS_VENDOR);
|
||||
Strings[SYS_PRODUCT] = GetDmiString(Header, DMI_SYS_PRODUCT);
|
||||
Strings[SYS_VERSION] = GetDmiString(Header, DMI_SYS_VERSION);
|
||||
Strings[SYS_SERIAL] = GetDmiString(Header, DMI_SYS_SERIAL);
|
||||
break;
|
||||
|
||||
case DMI_ENTRY_BASEBOARD:
|
||||
if (Remaining < DMI_BOARD_SIZE)
|
||||
return;
|
||||
Strings[BOARD_VENDOR] = GetDmiString(Header, DMI_BOARD_VENDOR);
|
||||
Strings[BOARD_NAME] = GetDmiString(Header, DMI_BOARD_NAME);
|
||||
Strings[BOARD_VERSION] = GetDmiString(Header, DMI_BOARD_VERSION);
|
||||
Strings[BOARD_SERIAL] = GetDmiString(Header, DMI_BOARD_SERIAL);
|
||||
Strings[BOARD_ASSET_TAG] = GetDmiString(Header, DMI_BOARD_ASSET_TAG);
|
||||
break;
|
||||
|
||||
case DMI_ENTRY_CHASSIS:
|
||||
case DMI_ENTRY_ONBOARD_DEVICE:
|
||||
case DMI_ENTRY_OEMSTRINGS:
|
||||
// DMI_ENTRY_IPMI_DEV?
|
||||
// DMI_ENTRY_ONBOARD_DEV_EXT?
|
||||
break;
|
||||
}
|
||||
|
||||
Remaining -= Header->Length;
|
||||
Data = (PCHAR)Header + Header->Length;
|
||||
|
||||
/* Now loop until we find 2 zeroes */
|
||||
while ((Remaining >= 2) && ((Data[0] != 0) || (Data[1] != 0)))
|
||||
{
|
||||
Data++;
|
||||
Remaining--;
|
||||
}
|
||||
|
||||
if (Remaining < 2)
|
||||
break;
|
||||
|
||||
/* Go to the next header */
|
||||
Remaining -= 2;
|
||||
Header = (PDMI_HEADER)((PUCHAR)Data + 2);
|
||||
}
|
||||
ParseSMBiosTables(SMBiosTables, TableSize, Strings);
|
||||
|
||||
#if 0 // DBG
|
||||
DbgPrint("i8042prt: Dumping DMI data:\n");
|
||||
|
|
|
@ -18,6 +18,7 @@ if(MSVC)
|
|||
endif()
|
||||
|
||||
add_subdirectory(delayimp)
|
||||
add_subdirectory(dmilib)
|
||||
#add_subdirectory(dnslib) Nothing links to this lib.
|
||||
add_subdirectory(drivers)
|
||||
add_subdirectory(dxguid)
|
||||
|
|
8
sdk/lib/dmilib/CMakeLists.txt
Normal file
8
sdk/lib/dmilib/CMakeLists.txt
Normal file
|
@ -0,0 +1,8 @@
|
|||
|
||||
list(APPEND SOURCE
|
||||
dmilib.c
|
||||
precomp.h)
|
||||
|
||||
add_library(dmilib ${SOURCE})
|
||||
add_pch(dmilib precomp.h SOURCE)
|
||||
add_dependencies(dmilib psdk)
|
|
@ -1,3 +1,10 @@
|
|||
/*
|
||||
* PROJECT: ReactOS DMI/SMBIOS Library
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: dmi.h
|
||||
* PURPOSE: SMBIOS table parsing functions
|
||||
* PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
113
sdk/lib/dmilib/dmilib.c
Normal file
113
sdk/lib/dmilib/dmilib.c
Normal file
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* PROJECT: ReactOS DMI/SMBIOS Library
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: dmilib.c
|
||||
* PURPOSE: SMBIOS table parsing functions
|
||||
* PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
* REFERENCES: http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.0.0.pdf
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
|
||||
static
|
||||
PCHAR
|
||||
GetDmiString(
|
||||
_In_ PDMI_HEADER Header,
|
||||
_In_ ULONG FieldOffset)
|
||||
{
|
||||
ULONG StringIndex;
|
||||
PCHAR String;
|
||||
|
||||
StringIndex = ((PUCHAR)Header)[FieldOffset];
|
||||
if (StringIndex == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
String = (PCHAR)Header + Header->Length;
|
||||
|
||||
while (--StringIndex != 0)
|
||||
{
|
||||
while (*String != 0)
|
||||
String++;
|
||||
|
||||
String++;
|
||||
}
|
||||
|
||||
return String;
|
||||
}
|
||||
|
||||
VOID
|
||||
ParseSMBiosTables(
|
||||
_In_reads_bytes_(TableSize) PVOID SMBiosTables,
|
||||
_In_ ULONG TableSize,
|
||||
_Inout_updates_(ID_STRINGS_MAX) PCHAR * Strings)
|
||||
{
|
||||
PMSSmBios_RawSMBiosTables BiosTablesHeader = SMBiosTables;
|
||||
PDMI_HEADER Header;
|
||||
ULONG Remaining;
|
||||
PCHAR Data;
|
||||
|
||||
Header = (PDMI_HEADER)(&BiosTablesHeader->SMBiosData);
|
||||
Remaining = BiosTablesHeader->Size;
|
||||
|
||||
while (Remaining >= sizeof(*Header))
|
||||
{
|
||||
if (Header->Type == DMI_ENTRY_END_OF_TABLE)
|
||||
break;
|
||||
|
||||
switch (Header->Type)
|
||||
{
|
||||
case DMI_ENTRY_BIOS:
|
||||
if (Remaining < DMI_BIOS_SIZE)
|
||||
return;
|
||||
Strings[BIOS_VENDOR] = GetDmiString(Header, DMI_BIOS_VENDOR);
|
||||
Strings[BIOS_VERSION] = GetDmiString(Header, DMI_BIOS_VERSION);
|
||||
Strings[BIOS_DATE] = GetDmiString(Header, DMI_BIOS_DATE);
|
||||
break;
|
||||
|
||||
case DMI_ENTRY_SYSTEM:
|
||||
if (Remaining < DMI_SYS_SIZE)
|
||||
return;
|
||||
Strings[SYS_VENDOR] = GetDmiString(Header, DMI_SYS_VENDOR);
|
||||
Strings[SYS_PRODUCT] = GetDmiString(Header, DMI_SYS_PRODUCT);
|
||||
Strings[SYS_VERSION] = GetDmiString(Header, DMI_SYS_VERSION);
|
||||
Strings[SYS_SERIAL] = GetDmiString(Header, DMI_SYS_SERIAL);
|
||||
break;
|
||||
|
||||
case DMI_ENTRY_BASEBOARD:
|
||||
if (Remaining < DMI_BOARD_SIZE)
|
||||
return;
|
||||
Strings[BOARD_VENDOR] = GetDmiString(Header, DMI_BOARD_VENDOR);
|
||||
Strings[BOARD_NAME] = GetDmiString(Header, DMI_BOARD_NAME);
|
||||
Strings[BOARD_VERSION] = GetDmiString(Header, DMI_BOARD_VERSION);
|
||||
Strings[BOARD_SERIAL] = GetDmiString(Header, DMI_BOARD_SERIAL);
|
||||
Strings[BOARD_ASSET_TAG] = GetDmiString(Header, DMI_BOARD_ASSET_TAG);
|
||||
break;
|
||||
|
||||
case DMI_ENTRY_CHASSIS:
|
||||
case DMI_ENTRY_ONBOARD_DEVICE:
|
||||
case DMI_ENTRY_OEMSTRINGS:
|
||||
// DMI_ENTRY_IPMI_DEV?
|
||||
// DMI_ENTRY_ONBOARD_DEV_EXT?
|
||||
break;
|
||||
}
|
||||
|
||||
Remaining -= Header->Length;
|
||||
Data = (PCHAR)Header + Header->Length;
|
||||
|
||||
/* Now loop until we find 2 zeroes */
|
||||
while ((Remaining >= 2) && ((Data[0] != 0) || (Data[1] != 0)))
|
||||
{
|
||||
Data++;
|
||||
Remaining--;
|
||||
}
|
||||
|
||||
if (Remaining < 2)
|
||||
break;
|
||||
|
||||
/* Go to the next header */
|
||||
Remaining -= 2;
|
||||
Header = (PDMI_HEADER)((PUCHAR)Data + 2);
|
||||
}
|
||||
}
|
34
sdk/lib/dmilib/dmilib.h
Normal file
34
sdk/lib/dmilib/dmilib.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* PROJECT: ReactOS DMI/SMBIOS Library
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: dmilib.h
|
||||
* PURPOSE: SMBIOS table parsing functions
|
||||
* PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
enum _ID_STRINGS
|
||||
{
|
||||
ID_NONE = 0,
|
||||
BIOS_VENDOR,
|
||||
BIOS_VERSION,
|
||||
BIOS_DATE,
|
||||
SYS_VENDOR,
|
||||
SYS_PRODUCT,
|
||||
SYS_VERSION,
|
||||
SYS_SERIAL,
|
||||
BOARD_VENDOR,
|
||||
BOARD_NAME,
|
||||
BOARD_VERSION,
|
||||
BOARD_SERIAL,
|
||||
BOARD_ASSET_TAG,
|
||||
|
||||
ID_STRINGS_MAX,
|
||||
};
|
||||
|
||||
VOID
|
||||
ParseSMBiosTables(
|
||||
_In_reads_bytes_(TableSize) PVOID SMBiosTables,
|
||||
_In_ ULONG TableSize,
|
||||
_Inout_updates_(ID_STRINGS_MAX) PCHAR * Strings);
|
9
sdk/lib/dmilib/precomp.h
Normal file
9
sdk/lib/dmilib/precomp.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef _DMILIB_PCH_
|
||||
#define _DMILIB_PCH_
|
||||
|
||||
#include <ntdef.h>
|
||||
#include <wmidata.h>
|
||||
#include "dmi.h"
|
||||
#include "dmilib.h"
|
||||
|
||||
#endif /* _DMILIB_PCH_ */
|
Loading…
Reference in a new issue