[I8042PRT] Move DMI/SMBIOS parsing functions into library
authorStanislav Motylkov <x86corez@gmail.com>
Mon, 30 Jul 2018 21:22:35 +0000 (00:22 +0300)
committerMark Jansen <mark.jansen@reactos.org>
Thu, 2 Aug 2018 19:29:57 +0000 (21:29 +0200)
drivers/input/i8042prt/CMakeLists.txt
drivers/input/i8042prt/hwhacks.c
sdk/lib/CMakeLists.txt
sdk/lib/dmilib/CMakeLists.txt [new file with mode: 0644]
sdk/lib/dmilib/dmi.h [moved from drivers/input/i8042prt/dmi.h with 91% similarity]
sdk/lib/dmilib/dmilib.c [new file with mode: 0644]
sdk/lib/dmilib/dmilib.h [new file with mode: 0644]
sdk/lib/dmilib/precomp.h [new file with mode: 0644]

index 2e8c6ee..808367f 100644 (file)
@@ -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)
index 885f0a2..d6d81f2 100644 (file)
@@ -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");
index 700a332..99c6849 100644 (file)
@@ -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)
diff --git a/sdk/lib/dmilib/CMakeLists.txt b/sdk/lib/dmilib/CMakeLists.txt
new file mode 100644 (file)
index 0000000..a3ad96c
--- /dev/null
@@ -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)
similarity index 91%
rename from drivers/input/i8042prt/dmi.h
rename to sdk/lib/dmilib/dmi.h
index ba562e5..855b697 100644 (file)
@@ -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
 
diff --git a/sdk/lib/dmilib/dmilib.c b/sdk/lib/dmilib/dmilib.c
new file mode 100644 (file)
index 0000000..7571fca
--- /dev/null
@@ -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);
+    }
+}
diff --git a/sdk/lib/dmilib/dmilib.h b/sdk/lib/dmilib/dmilib.h
new file mode 100644 (file)
index 0000000..22f2331
--- /dev/null
@@ -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);
diff --git a/sdk/lib/dmilib/precomp.h b/sdk/lib/dmilib/precomp.h
new file mode 100644 (file)
index 0000000..550611e
--- /dev/null
@@ -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_ */