ReactOS  0.4.14-dev-608-gd495a4f
hwhacks.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS i8042 (ps/2 keyboard-mouse controller) driver
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: drivers/input/i8042prt/hwhacks.c
5  * PURPOSE: Mouse specific functions
6  * PROGRAMMERS: Timo Kreuzer (timo.kreuzer@reactos.org)
7  * REFERENCES: - http://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.0.0.pdf
8  * -
9  */
10 
11 #include "i8042prt.h"
12 #include <wmiguid.h>
13 #include <wmidata.h>
14 #include <wmistr.h>
15 #include <dmilib.h>
16 
17 #define NDEBUG
18 #include <debug.h>
19 
23 
24 typedef struct _MATCHENTRY
25 {
28 } MATCHENTRY;
29 
30 #define MAX_MATCH_ENTRIES 3
31 typedef struct _HARDWARE_TABLE
32 {
36 
38 {
39 // { {{BOARD_VENDOR, "RIOWORKS"}, {BOARD_NAME, "HDAMB"}, {BOARD_VERSION, "Rev E"}}, FL_NOLOOP },
40 // { {{BOARD_VENDOR, "ASUSTeK Computer Inc."}, {BOARD_NAME, "G1S"}, {BOARD_VERSION, "1.0"}}, FL_NOLOOP },
41 
42  { {{SYS_VENDOR, "Microsoft Corporation"}, {SYS_PRODUCT, "Virtual Machine"}}, FL_INITHACK },
43  { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Inspiron 6000 "}}, FL_INITHACK },
44  { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D430 "}}, FL_INITHACK },
45  { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D530 "}}, FL_INITHACK },
46  { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D531 "}}, FL_INITHACK },
47  { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D600 "}}, FL_INITHACK },
48  { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D610 "}}, FL_INITHACK },
49  { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D620 "}}, FL_INITHACK },
50  { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D630 "}}, FL_INITHACK },
51  { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude D810 "}}, FL_INITHACK },
52  { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude E4300 "}}, FL_INITHACK },
53  { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude E4310 "}}, FL_INITHACK },
54  { {{SYS_VENDOR, "Dell Inc."}, {SYS_PRODUCT, "Latitude E6400 "}}, FL_INITHACK },
55 
56 };
57 
58 
59 
60 static
61 VOID
63  _In_reads_bytes_(TableSize) PVOID SMBiosTables,
65 {
66  ULONG i, j;
67  PCHAR Strings[ID_STRINGS_MAX] = { 0 };
68 
69  ParseSMBiosTables(SMBiosTables, TableSize, Strings);
70 
71 #if 0 // DBG
72  DbgPrint("i8042prt: Dumping DMI data:\n");
73  DbgPrint("BIOS_VENDOR: %s\n", Strings[BIOS_VENDOR]);
74  DbgPrint("BIOS_VERSION: %s\n", Strings[BIOS_VERSION]);
75  DbgPrint("BIOS_DATE: %s\n", Strings[BIOS_DATE]);
76  DbgPrint("SYS_VENDOR: %s\n", Strings[SYS_VENDOR]);
77  DbgPrint("SYS_PRODUCT: %s\n", Strings[SYS_PRODUCT]);
78  DbgPrint("SYS_VERSION: %s\n", Strings[SYS_VERSION]);
79  DbgPrint("SYS_SERIAL: %s\n", Strings[SYS_SERIAL]);
80  DbgPrint("BOARD_VENDOR: %s\n", Strings[BOARD_VENDOR]);
81  DbgPrint("BOARD_NAME: %s\n", Strings[BOARD_NAME]);
82  DbgPrint("BOARD_VERSION: %s\n", Strings[BOARD_VERSION]);
83  DbgPrint("BOARD_SERIAL: %s\n", Strings[BOARD_SERIAL]);
84  DbgPrint("BOARD_ASSET_TAG: %s\n", Strings[BOARD_ASSET_TAG]);
85 #endif
86 
87  /* Now loop the hardware table to find a match */
88  for (i = 0; i < ARRAYSIZE(i8042HardwareTable); i++)
89  {
90  for (j = 0; j < MAX_MATCH_ENTRIES; j++)
91  {
93 
94  if (Type != ID_NONE)
95  {
96  /* Check for a match */
97  if ((Strings[Type] == NULL) ||
98  strcmp(i8042HardwareTable[i].MatchEntries[j].String,
99  Strings[i8042HardwareTable[i].MatchEntries[j].Type]))
100  {
101  /* Does not match, try next entry */
102  break;
103  }
104  }
105  }
106 
107  if (j == MAX_MATCH_ENTRIES)
108  {
109  /* All items matched! */
111  DPRINT("Found match for hw table index %u\n", i);
112  break;
113  }
114  }
115 }
116 
117 static
118 VOID
120  _In_reads_bytes_(TableSize) PVOID SMBiosTables,
122 {
123  static UNICODE_STRING mssmbiosKeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services\\mssmbios");
124  static UNICODE_STRING DataName = RTL_CONSTANT_STRING(L"Data");
125  static UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"SMBiosData");
129 
130  /* Create registry key */
132  &mssmbiosKeyName,
134  NULL,
135  NULL);
136  Status = ZwCreateKey(&KeyHandle,
137  KEY_WRITE,
139  0,
140  NULL,
142  NULL);
143 
144  if (!NT_SUCCESS(Status))
145  {
146  return;
147  }
148 
149  /* Create sub key */
151  &DataName,
153  KeyHandle,
154  NULL);
155  Status = ZwCreateKey(&SubKeyHandle,
156  KEY_WRITE,
158  0,
159  NULL,
161  NULL);
162 
163  if (!NT_SUCCESS(Status))
164  {
166  return;
167  }
168 
169  /* Write value */
170  ZwSetValueKey(SubKeyHandle,
171  &ValueName,
172  0,
173  REG_BINARY,
174  SMBiosTables,
175  TableSize);
176 
179 }
180 
181 VOID
182 NTAPI
184  VOID)
185 {
187  PVOID DataBlockObject;
188  PWNODE_ALL_DATA AllData;
190 
191  /* Open the data block object for the SMBIOS table */
194  &DataBlockObject);
195  if (!NT_SUCCESS(Status))
196  {
197  DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
198  return;
199  }
200 
201  /* Query the required buffer size */
202  BufferSize = 0;
203  Status = IoWMIQueryAllData(DataBlockObject, &BufferSize, NULL);
204  if (!NT_SUCCESS(Status))
205  {
206  DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
207  return;
208  }
209 
210  AllData = ExAllocatePoolWithTag(PagedPool, BufferSize, 'BTMS');
211  if (AllData == NULL)
212  {
213  DPRINT1("Failed to allocate %lu bytes for SMBIOS tables\n", BufferSize);
214  return;
215  }
216 
217  /* Query the buffer data */
218  Status = IoWMIQueryAllData(DataBlockObject, &BufferSize, AllData);
219  if (!NT_SUCCESS(Status))
220  {
221  DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
222  ExFreePoolWithTag(AllData, 'BTMS');
223  return;
224  }
225 
226  /* FIXME: This function should be removed once the mssmbios driver is implemented */
227  /* Store SMBios data in registry */
228  i8042StoreSMBiosTables(AllData + 1,
229  AllData->FixedInstanceSize);
230  DPRINT1("SMBiosTables HACK, see CORE-14867\n");
231 
232  /* Parse the table */
233  i8042ParseSMBiosTables(AllData + 1,
234  AllData->WnodeHeader.BufferSize);
235 
236  /* Free the buffer */
237  ExFreePoolWithTag(AllData, 'BTMS');
238 }
239 
signed char * PCHAR
Definition: retypes.h:7
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
static VOID i8042StoreSMBiosTables(_In_reads_bytes_(TableSize) PVOID SMBiosTables, _In_ ULONG TableSize)
Definition: hwhacks.c:119
Type
Definition: Type.h:6
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4711
#define DbgPrint
Definition: loader.c:25
#define REG_BINARY
Definition: nt_native.h:1496
VOID ParseSMBiosTables(_In_reads_bytes_(TableSize) PVOID SMBiosTables, _In_ ULONG TableSize, _Inout_updates_(ID_STRINGS_MAX) PCHAR *Strings)
Definition: dmilib.c:41
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
struct _HARDWARE_TABLE HARDWARE_TABLE
LONG NTSTATUS
Definition: precomp.h:26
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
static WCHAR String[]
Definition: stringtable.c:55
PCHAR String
Definition: hwhacks.c:27
MATCHENTRY MatchEntries[MAX_MATCH_ENTRIES]
Definition: hwhacks.c:33
_In_ PUNICODE_STRING ValueName
Definition: cmfuncs.h:264
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
NTSTATUS NTAPI IoWMIQueryAllData(IN PVOID DataBlockObject, IN OUT ULONG *InOutBufferSize, OUT PVOID OutBuffer)
Definition: wmi.c:155
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define KEY_WRITE
Definition: nt_native.h:1031
const GUID MSSmBios_RawSMBiosTables_GUID
Definition: hwhacks.c:20
static VOID i8042ParseSMBiosTables(_In_reads_bytes_(TableSize) PVOID SMBiosTables, _In_ ULONG TableSize)
Definition: hwhacks.c:62
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BufferSize
Definition: classpnp.h:419
static const WCHAR Strings[]
Definition: reg.c:35
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ PNDIS_STRING _Out_ PNDIS_HANDLE SubKeyHandle
Definition: ndis.h:4723
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static const WCHAR L[]
Definition: oid.c:1250
struct _MATCHENTRY MATCHENTRY
#define SMBIOS_DATA_GUID
Definition: wmiguid.h:30
PVOID i8042SMBiosTables
Definition: hwhacks.c:21
ULONG Flags
Definition: hwhacks.c:34
#define _In_reads_bytes_(size)
Definition: no_sal2.h:229
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
ULONG i8042HwFlags
Definition: hwhacks.c:22
NTSTATUS NTAPI IoWMIOpenBlock(_In_ LPCGUID DataBlockGuid, _In_ ULONG DesiredAccess, _Out_ PVOID *DataBlockObject)
Definition: wmi.c:126
#define MAX_MATCH_ENTRIES
Definition: hwhacks.c:30
ULONG FixedInstanceSize
Definition: wmistr.h:118
#define WMIGUID_QUERY
Definition: wmistr.h:159
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ typedef _Out_ PULONG TableSize
Definition: iotypes.h:3971
ULONG Type
Definition: hwhacks.c:26
unsigned int ULONG
Definition: retypes.h:1
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
struct _WNODE_HEADER WnodeHeader
Definition: wmistr.h:112
VOID NTAPI i8042InitializeHwHacks(VOID)
Definition: hwhacks.c:183
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1060
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
Definition: dmilib.h:14
const HARDWARE_TABLE i8042HardwareTable[]
Definition: hwhacks.c:37
#define RTL_CONSTANT_STRING(s)
Definition: tunneltest.c:14