ReactOS 0.4.16-dev-109-gf4cb10f
detect.c File Reference
#include "sermouse.h"
#include <ntifs.h>
#include <debug.h>
Include dependency graph for detect.c:

Go to the source code of this file.

Functions

static NTSTATUS DeviceIoControl (IN PDEVICE_OBJECT DeviceObject, IN ULONG CtlCode, IN PVOID InputBuffer OPTIONAL, IN SIZE_T InputBufferSize, IN OUT PVOID OutputBuffer OPTIONAL, IN OUT PSIZE_T OutputBufferSize)
 
static NTSTATUS ReadBytes (IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
 
static NTSTATUS Wait (IN ULONG milliseconds)
 
SERMOUSE_MOUSE_TYPE SermouseDetectLegacyDevice (IN PDEVICE_OBJECT LowerDevice)
 

Function Documentation

◆ DeviceIoControl()

static NTSTATUS DeviceIoControl ( IN PDEVICE_OBJECT  DeviceObject,
IN ULONG  CtlCode,
IN PVOID InputBuffer  OPTIONAL,
IN SIZE_T  InputBufferSize,
IN OUT PVOID OutputBuffer  OPTIONAL,
IN OUT PSIZE_T  OutputBufferSize 
)
static

Definition at line 19 of file detect.c.

26{
28 PIRP Irp;
31
33
37 (ULONG)InputBufferSize,
39 (OutputBufferSize) ? (ULONG)*OutputBufferSize : 0,
40 FALSE,
41 &Event,
42 &IoStatus);
43 if (Irp == NULL)
44 {
45 WARN_(SERMOUSE, "IoBuildDeviceIoControlRequest() failed\n");
47 }
48
50
52 {
53 INFO_(SERMOUSE, "Operation pending\n");
55 Status = IoStatus.Status;
56 }
57
58 if (OutputBufferSize)
59 {
60 *OutputBufferSize = (SIZE_T)IoStatus.Information;
61 }
62
63 return Status;
64}
LONG NTSTATUS
Definition: precomp.h:26
_In_ PIRP Irp
Definition: csq.h:116
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
Status
Definition: gdiplustypes.h:25
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
#define KernelMode
Definition: asm.h:34
@ NotificationEvent
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define IoCallDriver
Definition: irp.c:1225
#define STATUS_PENDING
Definition: ntstatus.h:82
#define INFO_(ch,...)
Definition: debug.h:159
#define WARN_(ch,...)
Definition: debug.h:157
ULONG_PTR SIZE_T
Definition: typedefs.h:80
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2055
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953
@ Suspended
Definition: ketypes.h:420

Referenced by SerenumDetectLegacyDevice(), SerenumDetectPnpDevice(), and SermouseDetectLegacyDevice().

◆ ReadBytes()

static NTSTATUS ReadBytes ( IN PDEVICE_OBJECT  LowerDevice,
OUT PUCHAR  Buffer,
IN ULONG  BufferSize,
OUT PULONG_PTR  FilledBytes 
)
static

Definition at line 67 of file detect.c.

72{
73 PIRP Irp;
74 IO_STATUS_BLOCK ioStatus;
78
80 zero.QuadPart = 0;
83 LowerDevice,
85 &zero,
86 &event,
87 &ioStatus);
88 if (!Irp)
89 return FALSE;
90
91 Status = IoCallDriver(LowerDevice, Irp);
93 {
95 Status = ioStatus.Status;
96 }
97 INFO_(SERMOUSE, "Bytes received: %lu/%lu\n",
98 ioStatus.Information, BufferSize);
99 *FilledBytes = ioStatus.Information;
100 return Status;
101}
Definition: bufpool.h:45
struct _cl_event * event
Definition: glext.h:7739
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define IRP_MJ_READ
Definition: rdpdr.c:46
int zero
Definition: sehframes.cpp:29
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254

Referenced by SerenumDetectLegacyDevice(), SerenumDetectPnpDevice(), SermouseDetectLegacyDevice(), UDFAddXSpaceBitmap(), UDFCheckArea(), UDFConvertFEToExtended(), UDFConvertFEToNonInICB(), UDFCreateFile__(), UDFCreateRootFile__(), UDFExtAllocDescToMapping(), UDFFindVRS(), UDFGetDiskInfoAndVerify(), UDFIndexDirectory(), UDFLoadSparingTable(), UDFLoadVAT(), UDFLongAllocDescToMapping(), UDFOpenFile__(), UDFPackDirectory__(), UDFPhReadSynchronous(), UDFPrepareForReadOperation(), UDFPrepareXSpaceBitmap(), UDFReadDiscTrackInfo(), UDFReadFile__(), UDFReadTagged(), UDFRecordVAT(), UDFReTagDirectory(), UDFShortAllocDescToMapping(), UDFSparseFile__(), UDFTRead(), UDFUpdateSparingTable(), UDFUseStandard(), UDFVerifyXSpaceBitmap(), UDFVWorkItem(), UDFWriteFile__(), UDFWriteInSector(), UDFZeroFile__(), WCacheCheckLimitsR(), WCacheCheckLimitsRW(), WCacheFlushAllRW(), WCacheFlushBlocksRW(), WCachePurgeAllR(), WCachePurgeAllRW(), WCacheReadBlocks__(), and WCacheUpdatePacket().

◆ SermouseDetectLegacyDevice()

SERMOUSE_MOUSE_TYPE SermouseDetectLegacyDevice ( IN PDEVICE_OBJECT  LowerDevice)

Definition at line 117 of file detect.c.

119{
121 ULONG Fcr, Mcr;
122 ULONG BaudRate;
124 SERIAL_TIMEOUTS Timeouts;
126 ULONG_PTR i, Count = 0;
127 UCHAR Buffer[16];
128 SERMOUSE_MOUSE_TYPE MouseType = mtNone;
130
131 TRACE_(SERMOUSE, "SermouseDetectLegacyDevice(LowerDevice %p)\n", LowerDevice);
132
133 RtlZeroMemory(Buffer, sizeof(Buffer));
134
135 /* Open port */
137 LowerDevice,
139 NULL,
140 0,
141 NULL,
143 &Handle);
144 if (!NT_SUCCESS(Status)) return mtNone;
145
146 /* Reset UART */
147 TRACE_(SERMOUSE, "Reset UART\n");
148 Mcr = 0; /* MCR: DTR/RTS/OUT2 off */
150 &Mcr, sizeof(Mcr), NULL, NULL);
151 if (!NT_SUCCESS(Status)) goto ByeBye;
152
153 /* Set communications parameters */
154 TRACE_(SERMOUSE, "Set communications parameters\n");
155 /* DLAB off */
156 Fcr = 0;
158 &Fcr, sizeof(Fcr), NULL, NULL);
159 if (!NT_SUCCESS(Status)) goto ByeBye;
160 /* Set serial port speed */
161 BaudRate = 1200;
163 &BaudRate, sizeof(BaudRate), NULL, NULL);
164 if (!NT_SUCCESS(Status)) goto ByeBye;
165 /* Set LCR */
166 LCR.WordLength = 7;
167 LCR.Parity = NO_PARITY;
168 LCR.StopBits = STOP_BITS_2;
170 &LCR, sizeof(LCR), NULL, NULL);
171 if (!NT_SUCCESS(Status)) goto ByeBye;
172
173 /* Flush receive buffer */
174 TRACE_(SERMOUSE, "Flush receive buffer\n");
177 &Command, sizeof(Command), NULL, NULL);
178 if (!NT_SUCCESS(Status)) goto ByeBye;
179 /* Wait 100 ms */
180 Wait(100);
181
182 /* Enable DTR/RTS */
183 TRACE_(SERMOUSE, "Enable DTR/RTS\n");
185 NULL, 0, NULL, NULL);
186 if (!NT_SUCCESS(Status)) goto ByeBye;
188 NULL, 0, NULL, NULL);
189 if (!NT_SUCCESS(Status)) goto ByeBye;
190
191 /* Set timeout to 500 microseconds */
192 TRACE_(SERMOUSE, "Set timeout to 500 microseconds\n");
193 Timeouts.ReadIntervalTimeout = 100;
194 Timeouts.ReadTotalTimeoutMultiplier = 0;
195 Timeouts.ReadTotalTimeoutConstant = 500;
198 &Timeouts, sizeof(Timeouts), NULL, NULL);
199 if (!NT_SUCCESS(Status)) goto ByeBye;
200
201 /* Fill the read buffer */
202 TRACE_(SERMOUSE, "Fill the read buffer\n");
203 Status = ReadBytes(LowerDevice, Buffer, sizeof(Buffer)/sizeof(Buffer[0]), &Count);
204 if (!NT_SUCCESS(Status)) goto ByeBye;
205
206 for (i = 0; i < Count; i++)
207 {
208 if (Buffer[i] == 'B')
209 {
210 /* Sign for Microsoft Ballpoint */
211 ERR_(SERMOUSE, "Microsoft Ballpoint device detected. THIS DEVICE IS NOT YET SUPPORTED");
212 MouseType = mtNone;
213 goto ByeBye;
214 }
215 else if (Buffer[i] == 'M')
216 {
217 /* Sign for Microsoft Mouse protocol followed by button specifier */
218 if (i == sizeof(Buffer) - 1)
219 {
220 /* Overflow Error */
221 goto ByeBye;
222 }
223 switch (Buffer[i + 1])
224 {
225 case '3':
226 INFO_(SERMOUSE, "Microsoft Mouse with 3-buttons detected\n");
227 MouseType = mtLogitech;
228 break;
229 case 'Z':
230 INFO_(SERMOUSE, "Microsoft Wheel Mouse detected\n");
231 MouseType = mtWheelZ;
232 break;
233 default:
234 INFO_(SERMOUSE, "Microsoft Mouse with 2-buttons detected\n");
235 MouseType = mtMicrosoft;
236 break;
237 }
238 goto ByeBye;
239 }
240 }
241
242ByeBye:
243 /* Close port */
244 if (Handle)
246 return MouseType;
247}
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define TRACE_(x)
Definition: compat.h:76
static NTSTATUS DeviceIoControl(IN PDEVICE_OBJECT DeviceObject, IN ULONG CtlCode, IN PVOID InputBuffer OPTIONAL, IN SIZE_T InputBufferSize, IN OUT PVOID OutputBuffer OPTIONAL, IN OUT PSIZE_T OutputBufferSize)
Definition: detect.c:19
static NTSTATUS ReadBytes(IN PDEVICE_OBJECT LowerDevice, OUT PUCHAR Buffer, IN ULONG BufferSize, OUT PULONG_PTR FilledBytes)
Definition: detect.c:67
ULONG Handle
Definition: gdb_input.c:15
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
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define STOP_BITS_2
Definition: serial.c:87
#define SERIAL_PURGE_RXCLEAR
Definition: serial.c:96
#define NO_PARITY
Definition: serial.c:89
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
int Count
Definition: noreturn.cpp:7
#define IOCTL_SERIAL_SET_LINE_CONTROL
Definition: ntddser.h:96
#define IOCTL_SERIAL_SET_TIMEOUTS
Definition: ntddser.h:104
#define IOCTL_SERIAL_SET_MODEM_CONTROL
Definition: ntddser.h:98
#define IOCTL_SERIAL_SET_FIFO_CONTROL
Definition: ntddser.h:92
#define IOCTL_SERIAL_SET_BAUD_RATE
Definition: ntddser.h:82
#define IOCTL_SERIAL_SET_DTR
Definition: ntddser.h:90
#define IOCTL_SERIAL_SET_RTS
Definition: ntddser.h:102
NTSTATUS NTAPI ObOpenObjectByPointer(IN PVOID Object, IN ULONG HandleAttributes, IN PACCESS_STATE PassedAccessState, IN ACCESS_MASK DesiredAccess, IN POBJECT_TYPE ObjectType, IN KPROCESSOR_MODE AccessMode, OUT PHANDLE Handle)
Definition: obhandle.c:2742
#define ERR_(ch,...)
Definition: debug.h:156
SERMOUSE_MOUSE_TYPE
Definition: sermouse.h:20
@ mtMicrosoft
Definition: sermouse.h:22
@ mtNone
Definition: sermouse.h:21
@ mtLogitech
Definition: sermouse.h:23
@ mtWheelZ
Definition: sermouse.h:24
Definition: shell.h:41
ULONG WriteTotalTimeoutMultiplier
Definition: ntddser.h:306
ULONG ReadTotalTimeoutConstant
Definition: ntddser.h:305
ULONG WriteTotalTimeoutConstant
Definition: ntddser.h:307
ULONG ReadTotalTimeoutMultiplier
Definition: ntddser.h:304
ULONG ReadIntervalTimeout
Definition: ntddser.h:303
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG_PTR
Definition: typedefs.h:65
_In_ WDFDPC _In_ BOOLEAN Wait
Definition: wdfdpc.h:170
unsigned char UCHAR
Definition: xmlstorage.h:181

Referenced by SermouseStartDevice().

◆ Wait()

static NTSTATUS Wait ( IN ULONG  milliseconds)
static

Definition at line 104 of file detect.c.

106{
109
110 DueTime.QuadPart = milliseconds * -10;
114}
BOOLEAN NTAPI KeSetTimer(IN OUT PKTIMER Timer, IN LARGE_INTEGER DueTime, IN PKDPC Dpc OPTIONAL)
Definition: timerobj.c:281
VOID NTAPI KeInitializeTimer(OUT PKTIMER Timer)
Definition: timerobj.c:233
_In_ WDFTIMER _In_ LONGLONG DueTime
Definition: wdftimer.h:190
@ Executive
Definition: ketypes.h:415