📄 sermdep.c
字号:
errorLogEntry->ErrorCode = status;
errorLogEntry->DumpDataSize = (USHORT) dumpCount * sizeof(ULONG);
errorLogEntry->SequenceNumber = 0;
errorLogEntry->MajorFunctionCode = 0;
errorLogEntry->IoControlCode = 0;
errorLogEntry->RetryCount = 0;
// errorLogEntry->UniqueErrorValue = uniqueErrorValue;
errorLogEntry->FinalStatus = status;
for (i = 0; i < dumpCount; i++)
errorLogEntry->DumpData[i] = dumpData[i];
IoWriteErrorLogEntry(errorLogEntry);
}
}
Print(DeviceExtension, DBG_SS_TRACE, ("IntializeDevice 0x%x\n", status));
return status;
}
VOID
SerialMouseUnload(
IN PDRIVER_OBJECT DriverObject
)
{
PUNICODE_STRING regPath;
PAGED_CODE();
ASSERT(NULL == DriverObject->DeviceObject);
regPath = SerialMouseGetRegistryPath(DriverObject);
if (regPath && regPath->Buffer) {
ExFreePool(regPath->Buffer);
}
}
NTSTATUS
SerialMouseInitializeHardware(
IN PDEVICE_EXTENSION DeviceExtension
)
/*++
Routine Description:
This routine initializes the serial mouse/ballpoint. Note that this
routine is only called at initialization time, so synchronization is
not required.
Arguments:
DeviceObject - Pointer to the device object.
Return Value:
STATUS_SUCCESS if a pointing device is detected, otherwise STATUS_UNSUCCESSFUL
--*/
{
MOUSETYPE mouseType;
ULONG hardwareButtons;
NTSTATUS status = STATUS_UNSUCCESSFUL;
Print(DeviceExtension, DBG_SS_TRACE, ("SerialMouseInitializeHardware: enter\n"));
//
// Zero out the handler data in case we have previous state from a
// previous start
//
RtlZeroMemory(&DeviceExtension->HandlerData, sizeof(HANDLER_DATA));
if ((mouseType = MSerDetect(DeviceExtension)) != NO_MOUSE) {
status = STATUS_SUCCESS;
switch (mouseType) {
case MOUSE_2B:
DeviceExtension->ProtocolHandler =
MSerSetProtocol(DeviceExtension, MSER_PROTOCOL_MP);
DeviceExtension->MouseAttributes.MouseIdentifier =
MOUSE_SERIAL_HARDWARE;
hardwareButtons = 2;
break;
case MOUSE_3B:
DeviceExtension->ProtocolHandler =
MSerSetProtocol(DeviceExtension, MSER_PROTOCOL_MP);
DeviceExtension->MouseAttributes.MouseIdentifier =
MOUSE_SERIAL_HARDWARE;
hardwareButtons = 3;
break;
case BALLPOINT:
DeviceExtension->ProtocolHandler =
MSerSetProtocol(DeviceExtension, MSER_PROTOCOL_BP);
DeviceExtension->MouseAttributes.MouseIdentifier =
BALLPOINT_SERIAL_HARDWARE;
hardwareButtons = 2;
break;
case MOUSE_Z:
DeviceExtension->ProtocolHandler =
MSerSetProtocol(DeviceExtension, MSER_PROTOCOL_Z);
hardwareButtons = 3;
DeviceExtension->MouseAttributes.MouseIdentifier =
WHEELMOUSE_SERIAL_HARDWARE;
break;
}
}
else if (CSerDetect(DeviceExtension, &hardwareButtons)) {
status = STATUS_SUCCESS;
DeviceExtension->ProtocolHandler =
CSerSetProtocol(DeviceExtension, CSER_PROTOCOL_MM);
#if DBG
DeviceExtension->DebugFlags |= (DBG_HANDLER_INFO | DBG_HANDLER_ERROR);
#endif
}
else {
DeviceExtension->ProtocolHandler = NULL;
hardwareButtons = MOUSE_NUMBER_OF_BUTTONS;
}
//
// If the hardware wasn't overridden, set the number of buttons
// according to the protocol.
//
DeviceExtension->MouseAttributes.NumberOfButtons =
(USHORT) hardwareButtons;
if (NT_SUCCESS(status)) {
//
// Make sure the FIFO is turned off.
//
SerialMouseSetFifo(DeviceExtension, 0);
//
// Clean up anything left in the receive buffer.
//
SerialMouseFlushReadBuffer(DeviceExtension);
}
Print(DeviceExtension, DBG_SS_TRACE,
("SerialMouseInitializeHardware exit (0x%x)\n", status));
return status;
}
#if DBG
VOID
SerialMouseGetDebugFlags(
IN PUNICODE_STRING RegPath
)
{
}
#endif
VOID
SerialMouseServiceParameters(
IN PDEVICE_EXTENSION DeviceExtension,
IN HANDLE Handle
)
/*++
Routine Description:
This routine retrieves this driver's service parameters information
from the registry.
Arguments:
DeviceExtension - Pointer to the device extension.
RegistryPath - Pointer to the null-terminated Unicode name of the
registry path for this driver.
DeviceName - Pointer to the Unicode string that will receive
the port device name.
Return Value:
None. As a side-effect, sets fields in DeviceExtension->Configuration.
--*/
{
PRTL_QUERY_REGISTRY_TABLE parameters = NULL;
NTSTATUS status = STATUS_SUCCESS;
LONG defaultWaitEventMask = 0x0,
numberOfButtons = MOUSE_NUMBER_OF_BUTTONS,
defaultNumberOfButtons = MOUSE_NUMBER_OF_BUTTONS,
sampleRate = MOUSE_SAMPLE_RATE,
defaultSampleRate = MOUSE_SAMPLE_RATE,
i;
USHORT queriesPlusOne = 4;
WCHAR strParameters[] = L"Parameters";
PUNICODE_STRING regPath;
UNICODE_STRING parametersPath;
#if DBG
ULONG defaultDebugFlags = DEFAULT_DEBUG_FLAGS;
queriesPlusOne++;
#endif
RtlInitUnicodeString(¶metersPath, NULL);
//
// Allocate the Rtl query table.
//
parameters = ExAllocatePool(
PagedPool,
sizeof(RTL_QUERY_REGISTRY_TABLE) * queriesPlusOne
);
if (!parameters) {
status = STATUS_UNSUCCESSFUL;
goto SetParameters;
}
else {
RtlZeroMemory(
parameters,
sizeof(RTL_QUERY_REGISTRY_TABLE) * queriesPlusOne
);
regPath = SerialMouseGetRegistryPath(DeviceExtension->Self->DriverObject);
if (!regPath || !regPath->Buffer) {
goto GetServiceParametersByHandle;
}
parametersPath.MaximumLength = regPath->Length +
(wcslen(strParameters) * sizeof(WCHAR) ) + sizeof(UNICODE_NULL);
parametersPath.Buffer = ExAllocatePool(PagedPool,
parametersPath.MaximumLength);
if (!parametersPath.Buffer) {
status = STATUS_UNSUCCESSFUL;
goto GetServiceParametersByHandle;
}
}
RtlZeroMemory(parametersPath.Buffer,
parametersPath.MaximumLength);
RtlAppendUnicodeToString(¶metersPath,
regPath->Buffer);
RtlAppendUnicodeToString(¶metersPath,
strParameters);
//
// Gather all of the "user specified" information from
// the registry.
//
i = 0;
parameters[i].Flags = RTL_QUERY_REGISTRY_DIRECT;
parameters[i].Name = L"NumberOfButtons";
parameters[i].EntryContext = &numberOfButtons;
parameters[i].DefaultType = REG_DWORD;
parameters[i].DefaultData = &defaultNumberOfButtons;
parameters[i].DefaultLength = sizeof(LONG);
parameters[++i].Flags = RTL_QUERY_REGISTRY_DIRECT;
parameters[i].Name = L"SampleRate";
parameters[i].EntryContext = &sampleRate;
parameters[i].DefaultType = REG_DWORD;
parameters[i].DefaultData = &defaultSampleRate;
parameters[i].DefaultLength = sizeof(LONG);
#if DBG
parameters[++i].Flags = RTL_QUERY_REGISTRY_DIRECT;
parameters[i].Name = L"DebugFlags";
parameters[i].EntryContext = &DeviceExtension->DebugFlags;
parameters[i].DefaultType = REG_DWORD;
parameters[i].DefaultData = &defaultDebugFlags;
parameters[i].DefaultLength = sizeof(ULONG);
#endif
status = RtlQueryRegistryValues(
RTL_REGISTRY_ABSOLUTE | RTL_REGISTRY_OPTIONAL,
parametersPath.Buffer,
parameters,
NULL,
NULL
);
if (!NT_SUCCESS(status)) {
Print(DeviceExtension, DBG_SS_ERROR,
("RtlQueryRegistryValues failed with 0x%x\n", status));
DeviceExtension->DebugFlags = DEFAULT_DEBUG_FLAGS;
}
GetServiceParametersByHandle:
if (Handle) {
LONG prevNumberOfButtons = numberOfButtons,
prevSampleRate = sampleRate;
i = 0;
parameters[i].Flags = RTL_QUERY_REGISTRY_DIRECT;
parameters[i].Name = L"NumberOfButtons";
parameters[i].EntryContext = &numberOfButtons;
parameters[i].DefaultType = REG_DWORD;
parameters[i].DefaultData = &prevNumberOfButtons;
parameters[i].DefaultLength = sizeof(LONG);
parameters[++i].Flags = RTL_QUERY_REGISTRY_DIRECT;
parameters[i].Name = L"SampleRate";
parameters[i].EntryContext = &sampleRate;
parameters[i].DefaultType = REG_DWORD;
parameters[i].DefaultData = &prevSampleRate;
parameters[i].DefaultLength = sizeof(LONG);
parameters[++i].Flags = RTL_QUERY_REGISTRY_DIRECT;
parameters[i].Name = L"WaitEventMask";
parameters[i].EntryContext = &DeviceExtension->WaitEventMask;
parameters[i].DefaultType = REG_DWORD;
parameters[i].DefaultData = &defaultWaitEventMask;
parameters[i].DefaultLength = sizeof(LONG);
#if DBG
parameters[++i].Flags = RTL_QUERY_REGISTRY_DIRECT;
parameters[i].Name = L"DebugFlags";
parameters[i].EntryContext = &DeviceExtension->DebugFlags;
parameters[i].DefaultType = REG_DWORD;
parameters[i].DefaultData = &defaultDebugFlags;
parameters[i].DefaultLength = sizeof(ULONG);
#endif
status = RtlQueryRegistryValues(
RTL_REGISTRY_HANDLE,
(PWSTR) Handle,
parameters,
NULL,
NULL
);
}
SetParameters:
if (!NT_SUCCESS(status)) {
DeviceExtension->WaitEventMask = defaultWaitEventMask;
#if DBG
DeviceExtension->DebugFlags = defaultDebugFlags;
#endif
}
#if DBG
if (defaultDebugFlags == DeviceExtension->DebugFlags &&
GlobalDebugFlags != 0x0) {
DeviceExtension->DebugFlags = GlobalDebugFlags;
}
#endif
DeviceExtension->MouseAttributes.NumberOfButtons = (USHORT) numberOfButtons;
DeviceExtension->MouseAttributes.SampleRate = (USHORT) sampleRate;
Print(DeviceExtension, DBG_SS_NOISE, ("NumberOfButtons = %d\n",
DeviceExtension->MouseAttributes.NumberOfButtons));
Print(DeviceExtension, DBG_SS_NOISE, ("SampleRate = %d\n",
DeviceExtension->MouseAttributes.SampleRate));
Print(DeviceExtension, DBG_SS_NOISE, ("WaitEventMask = 0x%x\n",
DeviceExtension->WaitEventMask));
Print(DeviceExtension, DBG_SS_NOISE, ("DebugFlags 0x%x\n",
DeviceExtension->DebugFlags));
if (parametersPath.Buffer)
ExFreePool(parametersPath.Buffer);
if (parameters)
ExFreePool(parameters);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -