📄 gg.h
字号:
/*
Copyright GG Lab Corporation, All Rights Reserved
Module Name:
GG.h
*/
#ifndef _GG_
#define _GG_
#include <ntddk.h>
#include <ntddmou.h>
#include <ntddser.h>
#include "kbdmou.h"
#include "wmilib.h"
#define SERMOU_POOL_TAG (ULONG) 'resM'
#undef ExAllocatePool
#define ExAllocatePool(type, size) \
ExAllocatePoolWithTag (type, size, SERMOU_POOL_TAG);
//
// Default number of buttons and sample rate for the serial mouse.
//
#define MOUSE_NUMBER_OF_BUTTONS 2
#define MOUSE_SAMPLE_RATE 40 // 1200 baud
#define DETECTION_TIMEOUT_DEFAULT 50 // expressed in 10ths of a second
//
// Protocol handler state constants.
//
#define STATE0 0 // Sync bit, buttons and high x & y bits
#define STATE1 1 // lower x bits
#define STATE2 2 // lower y bits
#define STATE3 3 // Switch 2, extended packet bit & low z data
#define STATE4 4 // high z data
#define STATE_MAX 5
//
// Useful constants.
//
#define MOUSE_BUTTON_1 0x01
#define MOUSE_BUTTON_2 0x02
#define MOUSE_BUTTON_3 0x04
#define MOUSE_BUTTON_LEFT 0x01
#define MOUSE_BUTTON_RIGHT 0x02
#define MOUSE_BUTTON_MIDDLE 0x04
//
// Conversion factor for milliseconds to microseconds.
//
#define MS_TO_MICROSECONDS 1000
//
// 150/200 millisecond pause expressed in 100's of nanoseconds
// 200 ms * 1000 us/ms * 10 ns/100 us
//
#define PAUSE_200_MS (200 * 1000 * 10)
#define PAUSE_150_MS (150 * 1000 * 10)
//
// convert milliseconds to 100's of nanoseconds
// 1000 us/ms * 10 ns/100 us
//
#define MS_TO_100_NS 10000
//
// Protocol handler static data.
//
typedef struct _HANDLER_DATA {
ULONG Error; // Error count
ULONG State; // Keep the current state
ULONG PreviousButtons; // The previous button state
UCHAR Raw[STATE_MAX]; // Accumulate raw data
} HANDLER_DATA, *PHANDLER_DATA;
//
// Define the protocol handler type.
//
typedef BOOLEAN
(*PPROTOCOL_HANDLER)(
IN PVOID DevicExtension,
IN PMOUSE_INPUT_DATA CurrentInput,
IN PHANDLER_DATA HandlerData,
IN UCHAR Value,
IN UCHAR LineState);
//
// Defines for DeviceExtension->HardwarePresent.
// These should match the values in i8042prt
//
#define MOUSE_HARDWARE_PRESENT 0x02
#define BALLPOINT_HARDWARE_PRESENT 0x04
#define WHEELMOUSE_HARDWARE_PRESENT 0x08
#define SERIAL_MOUSE_START_READ 0x01
#define SERIAL_MOUSE_END_READ 0x02
#define SERIAL_MOUSE_IMMEDIATE_READ 0x03
//
// Port device extension.
//
typedef struct _DEVICE_EXTENSION {
//
// Debug flags
//
ULONG DebugFlags;
//
// Pointer back to the this extension's device object.
//
PDEVICE_OBJECT Self;
//
// An event to halt the deletion of a device until it is ready to go.
//
KEVENT StartEvent;
//
// The top of the stack before this filter was added. AKA the location
// to which all IRPS should be directed.
//
PDEVICE_OBJECT TopOfStack;
//
// "THE PDO" (ejected by serenum)
//
PDEVICE_OBJECT PDO;
//
// Remove Lock object to protect IRP_MN_REMOVE_DEVICE
//
IO_REMOVE_LOCK RemoveLock;
ULONG ReadInterlock;
//
// Pointer to the mouse class device object and callback routine
// above us, Used as the first parameter and the MouseClassCallback().
// routine itself.
//
CONNECT_DATA ConnectData;
//
// Reference count for number of mouse enables.
//
LONG EnableCount;
//
// GGmouse created irp used to bounce reads down to the serial driver
//
PIRP ReadIrp;
//
// GGmouse created irp used to detect when the mouse has been hot plugged
//
PIRP DetectionIrp;
ULONG SerialEventBits;
//
// WMI Information
//
WMILIB_CONTEXT WmiLibInfo;
//
// Attributes of the mouse
//
MOUSE_ATTRIBUTES MouseAttributes;
//
// Current mouse input packet.
//
MOUSE_INPUT_DATA InputData;
//
// Timer used during startup to follow power cycle detection protocol
//
KTIMER DelayTimer;
//
// Bits to use when testing if the device has been removed
//
ULONG WaitEventMask;
ULONG ModemStatusBits;
//
// Request sequence number (used for error logging).
//
ULONG SequenceNumber;
//
// Pointer to the interrupt protocol handler routine.
//
PPROTOCOL_HANDLER ProtocolHandler;
//
// Static state machine handler data.
//
HANDLER_DATA HandlerData;
DEVICE_POWER_STATE PowerState;
SERIAL_BASIC_SETTINGS SerialBasicSettings;
//
// Has the device been taken out from under us?
// Has it been started?
//
BOOLEAN Removed;
BOOLEAN SurpriseRemoved;
BOOLEAN Started;
BOOLEAN RemovalDremoved;
//
// Buffer used in the read irp
//
UCHAR ReadBuffer[1];
//
// Set to false if all the lines are low on the first attempt at detection
// If false, all further attempts at detection are stopped
//
BOOLEAN DetectionSupported;
BOOLEAN WaitWakePending;
BOOLEAN PoweringDown;
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
//
// Function prototypes.
//
/*
PUNICODE_STRING
SerialMouseGetRegistryPath(
PDRIVER_OBJECT DriverObject
);
*/
#define SerialMouseGetRegistryPath(DriverObject) \
(PUNICODE_STRING)IoGetDriverObjectExtension(DriverObject, (PVOID) 1)
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
);
NTSTATUS
SerialMouseCompletionRoutine (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context
);
VOID
SerialMouseClosePort(
PDEVICE_EXTENSION DeviceExtension,
PIRP Irp
);
NTSTATUS
SerialMouseSpinUpRead(
PDEVICE_EXTENSION DeviceExtension
);
NTSTATUS
SerialMouseStartDevice(
PDEVICE_EXTENSION DeviceExtension,
PIRP Irp,
BOOLEAN CloseOnFailure
);
NTSTATUS
SerialMouseInitializeDevice (
IN PDEVICE_EXTENSION DeviceExtension
);
VOID
SerialMouseStartDetection(
PDEVICE_EXTENSION DeviceExtension
);
VOID
SerialMouseStopDetection(
PDEVICE_EXTENSION DeviceExtension
);
VOID
SerialMouseDetectionDpc(
IN PKDPC Dpc,
IN PDEVICE_OBJECT DeviceObject,
IN PVOID SystemArg1,
IN PVOID SystemArg2
);
VOID
SerialMouseDetectionRoutine(
PDEVICE_EXTENSION DeviceExtension
);
NTSTATUS
SerialMouseSendIrpSynchronously (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN BOOLEAN CopyToNext
);
NTSTATUS
SerialMouseFlush(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -