ReactOS  0.4.12-dev-685-gf36cbf7
i8042prt.h File Reference
#include <ntifs.h>
#include <kbdmou.h>
#include <ntdd8042.h>
Include dependency graph for i8042prt.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _I8042_SETTINGS
 
struct  _INTERRUPT_DATA
 
struct  _PORT_DEVICE_EXTENSION
 
struct  _I8042_DRIVER_EXTENSION
 
struct  _FDO_DEVICE_EXTENSION
 
struct  _I8042_KEYBOARD_EXTENSION
 
struct  _I8042_MOUSE_EXTENSION
 
struct  _I8042_HOOK_WORKITEM
 

Macros

#define I8042PRT_TAG   '2408'
 
#define WHEEL_DELTA   120
 
#define KEYBOARD_PRESENT   0x01 /* A keyboard is attached */
 
#define KEYBOARD_CONNECTED   0x02 /* Keyboard received IOCTL_INTERNAL_KEYBOARD_CONNECT */
 
#define KEYBOARD_STARTED   0x04 /* Keyboard FDO received IRP_MN_START_DEVICE */
 
#define KEYBOARD_INITIALIZED   0x08 /* Keyboard interrupt is connected */
 
#define MOUSE_PRESENT   0x10 /* A mouse is attached */
 
#define MOUSE_CONNECTED   0x20 /* Mouse received IOCTL_INTERNAL_MOUSE_CONNECT */
 
#define MOUSE_STARTED   0x40 /* Mouse FDO received IRP_MN_START_DEVICE */
 
#define MOUSE_INITIALIZED   0x80 /* Mouse interrupt is connected */
 
#define MAX(a, b)   ((a) >= (b) ? (a) : (b))
 
#define KEYBOARD_POWER_CODE   0x5E
 
#define KEYBOARD_SLEEP_CODE   0x5F
 
#define KEYBOARD_WAKE_CODE   0x63
 
#define KBD_READ_MODE   0x20
 
#define KBD_WRITE_MODE   0x60
 
#define MOUSE_ENAB   0xA8
 
#define MOUSE_LINE_TEST   0xA9
 
#define CTRL_SELF_TEST   0xAA
 
#define KBD_CLK_DISABLE   0xAD
 
#define KBD_CLK_ENABLE   0xAE
 
#define CTRL_WRITE_MOUSE   0xD4
 
#define KBD_CMD_SET_LEDS   0xED
 
#define KBD_CMD_GET_ID   0xF2
 
#define KBD_SELF_TEST_OK   0x55
 
#define KBD_ACK   0xFA
 
#define KBD_NACK   0xFC
 
#define KBD_RESEND   0xFE
 
#define KBD_OBF   0x01
 
#define KBD_IBF   0x02
 
#define MOU_OBF   0x20
 
#define KBD_PERR   0x80
 
#define CCB_KBD_INT_ENAB   0x01
 
#define CCB_MOUSE_INT_ENAB   0x02
 
#define CCB_SYSTEM_FLAG   0x04
 
#define CCB_KBD_DISAB   0x10
 
#define CCB_MOUSE_DISAB   0x20
 
#define CCB_TRANSLATE   0x40
 
#define KBD_LED_SCROLL   0x01
 
#define KBD_LED_NUM   0x02
 
#define KBD_LED_CAPS   0x04
 
#define MOU_ENAB   0xF4
 
#define MOU_CMD_RESET   0xFF
 
#define MOUSE_ACK   0xFA
 
#define MOUSE_ERROR   0xFC
 
#define MOUSE_NACK   0xFE
 
#define i8042ReadKeyboardData(DeviceExtension, Data)   i8042ReadData(DeviceExtension, KBD_OBF, Data)
 
#define i8042ReadMouseData(DeviceExtension, Data)   i8042ReadData(DeviceExtension, MOU_OBF, Data)
 

Typedefs

typedef struct _I8042_SETTINGS I8042_SETTINGS
 
typedef struct _I8042_SETTINGSPI8042_SETTINGS
 
typedef enum _MOUSE_TIMEOUT_STATE MOUSE_TIMEOUT_STATE
 
typedef enum _MOUSE_TIMEOUT_STATEPMOUSE_TIMEOUT_STATE
 
typedef struct _INTERRUPT_DATA INTERRUPT_DATA
 
typedef struct _INTERRUPT_DATAPINTERRUPT_DATA
 
typedef struct _I8042_KEYBOARD_EXTENSIONPI8042_KEYBOARD_EXTENSION
 
typedef struct _I8042_MOUSE_EXTENSIONPI8042_MOUSE_EXTENSION
 
typedef struct _PORT_DEVICE_EXTENSION PORT_DEVICE_EXTENSION
 
typedef struct _PORT_DEVICE_EXTENSIONPPORT_DEVICE_EXTENSION
 
typedef struct _I8042_DRIVER_EXTENSION I8042_DRIVER_EXTENSION
 
typedef struct _I8042_DRIVER_EXTENSIONPI8042_DRIVER_EXTENSION
 
typedef enum _I8042_DEVICE_TYPE I8042_DEVICE_TYPE
 
typedef enum _I8042_DEVICE_TYPEPI8042_DEVICE_TYPE
 
typedef struct _FDO_DEVICE_EXTENSION FDO_DEVICE_EXTENSION
 
typedef struct _FDO_DEVICE_EXTENSIONPFDO_DEVICE_EXTENSION
 
typedef struct _I8042_KEYBOARD_EXTENSION I8042_KEYBOARD_EXTENSION
 
typedef enum _I8042_MOUSE_TYPE I8042_MOUSE_TYPE
 
typedef enum _I8042_MOUSE_TYPEPI8042_MOUSE_TYPE
 
typedef struct _I8042_MOUSE_EXTENSION I8042_MOUSE_EXTENSION
 
typedef struct _I8042_HOOK_WORKITEM I8042_HOOK_WORKITEM
 
typedef struct _I8042_HOOK_WORKITEMPI8042_HOOK_WORKITEM
 

Enumerations

enum  DEVICE_STATE {
  dsStopped, dsStarted, dsPaused, dsRemoved,
  dsSurpriseRemoved, NotStarted = 0, Started, StopPending,
  Stopped, RemovePending, SurpriseRemovePending, Deleted,
  dsStopped, dsStarted, dsPaused, dsRemoved,
  dsSurpriseRemoved, dsStopped, dsStarted, dsPaused,
  dsRemoved, dsSurpriseRemoved
}
 
enum  _MOUSE_TIMEOUT_STATE { NoChange, TimeoutStart, TimeoutCancel }
 
enum  _I8042_DEVICE_TYPE { Unknown, Keyboard, Mouse, PhysicalDeviceObject }
 
enum  _I8042_MOUSE_TYPE { GenericPS2, Intellimouse, IntellimouseExplorer, Ps2pp }
 
enum  _FLAGS { FL_NOLOOP = 0x01, FL_INITHACK = 0x02 }
 

Functions

 _Dispatch_type_ (IRP_MJ_CREATE) DRIVER_DISPATCH i8042Create
 
 _Dispatch_type_ (IRP_MJ_CLEANUP) DRIVER_DISPATCH i8042Cleanup
 
 _Dispatch_type_ (IRP_MJ_CLOSE) DRIVER_DISPATCH i8042Close
 
NTSTATUS NTAPI i8042SynchWritePortKbd (IN PVOID Context, IN UCHAR Value, IN BOOLEAN WaitForAck)
 
BOOLEAN i8042PacketIsr (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Output)
 
NTSTATUS i8042StartPacket (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PFDO_DEVICE_EXTENSION FdoDeviceExtension, IN PUCHAR Bytes, IN ULONG ByteCount, IN PIRP Irp)
 
NTSTATUS DuplicateUnicodeString (IN ULONG Flags, IN PCUNICODE_STRING SourceString, OUT PUNICODE_STRING DestinationString)
 
VOID i8042MouHandle (IN PI8042_MOUSE_EXTENSION DeviceExtension, IN UCHAR Output)
 
VOID i8042MouHandleButtons (IN PI8042_MOUSE_EXTENSION DeviceExtension, IN USHORT Mask)
 
NTSTATUS i8042MouInitialize (IN PI8042_MOUSE_EXTENSION DeviceExtension)
 
BOOLEAN i8042ChangeMode (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR FlagsToDisable, IN UCHAR FlagsToEnable)
 
 _Dispatch_type_ (IRP_MJ_PNP) DRIVER_DISPATCH i8042Pnp
 
VOID i8042MouHandlePs2pp (IN PI8042_MOUSE_EXTENSION DeviceExtension, IN UCHAR Input)
 
VOID i8042Flush (IN PPORT_DEVICE_EXTENSION DeviceExtension)
 
BOOLEAN i8042IsrWritePort (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Value, IN UCHAR SelectCmd OPTIONAL)
 
NTSTATUS i8042ReadData (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR StatusFlags, OUT PUCHAR Data)
 
NTSTATUS i8042ReadDataWait (IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Data)
 
NTSTATUS i8042ReadStatus (IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Status)
 
NTSTATUS NTAPI i8042SynchReadPort (IN PVOID Context, OUT PUCHAR Value, IN BOOLEAN WaitForAck)
 
NTSTATUS NTAPI i8042SynchWritePort (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Port, IN UCHAR Value, IN BOOLEAN WaitForAck)
 
BOOLEAN i8042Write (IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PUCHAR addr, IN UCHAR data)
 
NTSTATUS ReadRegistryEntries (IN PUNICODE_STRING RegistryPath, OUT PI8042_SETTINGS Settings)
 
VOID NTAPI i8042InitializeHwHacks (VOID)
 

Variables

IO_WORKITEM_ROUTINE i8042SendHookWorkItem
 
DRIVER_STARTIO i8042KbdStartIo
 
DRIVER_DISPATCH i8042KbdDeviceControl
 
DRIVER_DISPATCH i8042KbdInternalDeviceControl
 
KSERVICE_ROUTINE i8042KbdInterruptService
 
DRIVER_ADD_DEVICE i8042AddDevice
 
DRIVER_DISPATCH ForwardIrpAndForget
 
DRIVER_DISPATCH ForwardIrpAndWait
 
DRIVER_DISPATCH i8042MouInternalDeviceControl
 
KSERVICE_ROUTINE i8042MouInterruptService
 
ULONG i8042HwFlags
 

Macro Definition Documentation

◆ CCB_KBD_DISAB

#define CCB_KBD_DISAB   0x10

Definition at line 262 of file i8042prt.h.

◆ CCB_KBD_INT_ENAB

#define CCB_KBD_INT_ENAB   0x01

Definition at line 259 of file i8042prt.h.

◆ CCB_MOUSE_DISAB

#define CCB_MOUSE_DISAB   0x20

Definition at line 263 of file i8042prt.h.

◆ CCB_MOUSE_INT_ENAB

#define CCB_MOUSE_INT_ENAB   0x02

Definition at line 260 of file i8042prt.h.

◆ CCB_SYSTEM_FLAG

#define CCB_SYSTEM_FLAG   0x04

Definition at line 261 of file i8042prt.h.

◆ CCB_TRANSLATE

#define CCB_TRANSLATE   0x40

Definition at line 264 of file i8042prt.h.

◆ CTRL_SELF_TEST

#define CTRL_SELF_TEST   0xAA

Definition at line 225 of file i8042prt.h.

◆ CTRL_WRITE_MOUSE

#define CTRL_WRITE_MOUSE   0xD4

Definition at line 228 of file i8042prt.h.

◆ I8042PRT_TAG

#define I8042PRT_TAG   '2408'

Definition at line 12 of file i8042prt.h.

◆ i8042ReadKeyboardData

#define i8042ReadKeyboardData (   DeviceExtension,
  Data 
)    i8042ReadData(DeviceExtension, KBD_OBF, Data)

Definition at line 405 of file i8042prt.h.

◆ i8042ReadMouseData

#define i8042ReadMouseData (   DeviceExtension,
  Data 
)    i8042ReadData(DeviceExtension, MOU_OBF, Data)

Definition at line 407 of file i8042prt.h.

◆ KBD_ACK

#define KBD_ACK   0xFA

Definition at line 242 of file i8042prt.h.

◆ KBD_CLK_DISABLE

#define KBD_CLK_DISABLE   0xAD

Definition at line 226 of file i8042prt.h.

◆ KBD_CLK_ENABLE

#define KBD_CLK_ENABLE   0xAE

Definition at line 227 of file i8042prt.h.

◆ KBD_CMD_GET_ID

#define KBD_CMD_GET_ID   0xF2

Definition at line 235 of file i8042prt.h.

◆ KBD_CMD_SET_LEDS

#define KBD_CMD_SET_LEDS   0xED

Definition at line 234 of file i8042prt.h.

◆ KBD_IBF

#define KBD_IBF   0x02

Definition at line 251 of file i8042prt.h.

◆ KBD_LED_CAPS

#define KBD_LED_CAPS   0x04

Definition at line 272 of file i8042prt.h.

◆ KBD_LED_NUM

#define KBD_LED_NUM   0x02

Definition at line 271 of file i8042prt.h.

◆ KBD_LED_SCROLL

#define KBD_LED_SCROLL   0x01

Definition at line 270 of file i8042prt.h.

◆ KBD_NACK

#define KBD_NACK   0xFC

Definition at line 243 of file i8042prt.h.

◆ KBD_OBF

#define KBD_OBF   0x01

Definition at line 250 of file i8042prt.h.

◆ KBD_PERR

#define KBD_PERR   0x80

Definition at line 253 of file i8042prt.h.

◆ KBD_READ_MODE

#define KBD_READ_MODE   0x20

Definition at line 221 of file i8042prt.h.

◆ KBD_RESEND

#define KBD_RESEND   0xFE

Definition at line 244 of file i8042prt.h.

◆ KBD_SELF_TEST_OK

#define KBD_SELF_TEST_OK   0x55

Definition at line 241 of file i8042prt.h.

◆ KBD_WRITE_MODE

#define KBD_WRITE_MODE   0x60

Definition at line 222 of file i8042prt.h.

◆ KEYBOARD_CONNECTED

#define KEYBOARD_CONNECTED   0x02 /* Keyboard received IOCTL_INTERNAL_KEYBOARD_CONNECT */

Definition at line 69 of file i8042prt.h.

◆ KEYBOARD_INITIALIZED

#define KEYBOARD_INITIALIZED   0x08 /* Keyboard interrupt is connected */

Definition at line 71 of file i8042prt.h.

◆ KEYBOARD_POWER_CODE

#define KEYBOARD_POWER_CODE   0x5E

Definition at line 213 of file i8042prt.h.

◆ KEYBOARD_PRESENT

#define KEYBOARD_PRESENT   0x01 /* A keyboard is attached */

Definition at line 68 of file i8042prt.h.

◆ KEYBOARD_SLEEP_CODE

#define KEYBOARD_SLEEP_CODE   0x5F

Definition at line 214 of file i8042prt.h.

◆ KEYBOARD_STARTED

#define KEYBOARD_STARTED   0x04 /* Keyboard FDO received IRP_MN_START_DEVICE */

Definition at line 70 of file i8042prt.h.

◆ KEYBOARD_WAKE_CODE

#define KEYBOARD_WAKE_CODE   0x63

Definition at line 215 of file i8042prt.h.

◆ MAX

#define MAX (   a,
  b 
)    ((a) >= (b) ? (a) : (b))

Definition at line 211 of file i8042prt.h.

◆ MOU_CMD_RESET

#define MOU_CMD_RESET   0xFF

Definition at line 279 of file i8042prt.h.

◆ MOU_ENAB

#define MOU_ENAB   0xF4

Definition at line 278 of file i8042prt.h.

◆ MOU_OBF

#define MOU_OBF   0x20

Definition at line 252 of file i8042prt.h.

◆ MOUSE_ACK

#define MOUSE_ACK   0xFA

Definition at line 285 of file i8042prt.h.

◆ MOUSE_CONNECTED

#define MOUSE_CONNECTED   0x20 /* Mouse received IOCTL_INTERNAL_MOUSE_CONNECT */

Definition at line 73 of file i8042prt.h.

◆ MOUSE_ENAB

#define MOUSE_ENAB   0xA8

Definition at line 223 of file i8042prt.h.

◆ MOUSE_ERROR

#define MOUSE_ERROR   0xFC

Definition at line 286 of file i8042prt.h.

◆ MOUSE_INITIALIZED

#define MOUSE_INITIALIZED   0x80 /* Mouse interrupt is connected */

Definition at line 75 of file i8042prt.h.

◆ MOUSE_LINE_TEST

#define MOUSE_LINE_TEST   0xA9

Definition at line 224 of file i8042prt.h.

◆ MOUSE_NACK

#define MOUSE_NACK   0xFE

Definition at line 287 of file i8042prt.h.

◆ MOUSE_PRESENT

#define MOUSE_PRESENT   0x10 /* A mouse is attached */

Definition at line 72 of file i8042prt.h.

◆ MOUSE_STARTED

#define MOUSE_STARTED   0x40 /* Mouse FDO received IRP_MN_START_DEVICE */

Definition at line 74 of file i8042prt.h.

◆ WHEEL_DELTA

#define WHEEL_DELTA   120

Definition at line 60 of file i8042prt.h.

Typedef Documentation

◆ FDO_DEVICE_EXTENSION

◆ I8042_DEVICE_TYPE

◆ I8042_DRIVER_EXTENSION

◆ I8042_HOOK_WORKITEM

◆ I8042_KEYBOARD_EXTENSION

◆ I8042_MOUSE_EXTENSION

◆ I8042_MOUSE_TYPE

◆ I8042_SETTINGS

◆ INTERRUPT_DATA

◆ MOUSE_TIMEOUT_STATE

◆ PFDO_DEVICE_EXTENSION

◆ PI8042_DEVICE_TYPE

◆ PI8042_DRIVER_EXTENSION

◆ PI8042_HOOK_WORKITEM

◆ PI8042_KEYBOARD_EXTENSION

◆ PI8042_MOUSE_EXTENSION

Definition at line 65 of file i8042prt.h.

◆ PI8042_MOUSE_TYPE

◆ PI8042_SETTINGS

◆ PINTERRUPT_DATA

◆ PMOUSE_TIMEOUT_STATE

◆ PORT_DEVICE_EXTENSION

◆ PPORT_DEVICE_EXTENSION

Enumeration Type Documentation

◆ _FLAGS

Enumerator
FL_NOLOOP 
FL_INITHACK 

Definition at line 453 of file i8042prt.h.

454 {
455  FL_NOLOOP = 0x01,
456  FL_INITHACK = 0x02,
457 };

◆ _I8042_DEVICE_TYPE

Enumerator
Unknown 
Keyboard 
Mouse 
PhysicalDeviceObject 

Definition at line 112 of file i8042prt.h.

113 {
114  Unknown,
115  Keyboard,
116  Mouse,
enum _I8042_DEVICE_TYPE * PI8042_DEVICE_TYPE
enum _I8042_DEVICE_TYPE I8042_DEVICE_TYPE

◆ _I8042_MOUSE_TYPE

Enumerator
GenericPS2 
Intellimouse 
IntellimouseExplorer 
Ps2pp 

Definition at line 167 of file i8042prt.h.

168 {
169  GenericPS2,
170  Intellimouse,
172  Ps2pp
enum _I8042_MOUSE_TYPE * PI8042_MOUSE_TYPE
enum _I8042_MOUSE_TYPE I8042_MOUSE_TYPE

◆ _MOUSE_TIMEOUT_STATE

Enumerator
NoChange 
TimeoutStart 
TimeoutCancel 

Definition at line 43 of file i8042prt.h.

44 {
45  NoChange,
enum _MOUSE_TIMEOUT_STATE MOUSE_TIMEOUT_STATE
enum _MOUSE_TIMEOUT_STATE * PMOUSE_TIMEOUT_STATE

◆ DEVICE_STATE

Enumerator
dsStopped 
dsStarted 
dsPaused 
dsRemoved 
dsSurpriseRemoved 
NotStarted 
Started 
StopPending 
Stopped 
RemovePending 
SurpriseRemovePending 
Deleted 
dsStopped 
dsStarted 
dsPaused 
dsRemoved 
dsSurpriseRemoved 
dsStopped 
dsStarted 
dsPaused 
dsRemoved 
dsSurpriseRemoved 

Definition at line 14 of file i8042prt.h.

15 {
16  dsStopped,
17  dsStarted,
18  dsPaused,
19  dsRemoved,
21 } DEVICE_STATE;
DEVICE_STATE
Definition: i8042prt.h:14

Function Documentation

◆ _Dispatch_type_() [1/4]

_Dispatch_type_ ( IRP_MJ_CREATE  )

Definition at line 3953 of file create.c.

3955  {
3956  NTSTATUS Status;
3959  BOOL top_level, locked = FALSE;
3960 
3962 
3963  TRACE("create (flags = %x)\n", Irp->Flags);
3964 
3965  top_level = is_top_level(Irp);
3966 
3967  /* return success if just called for FS device object */
3968  if (DeviceObject == master_devobj) {
3969  TRACE("create called for FS device object\n");
3970 
3971  Irp->IoStatus.Information = FILE_OPENED;
3973 
3974  goto exit;
3975  } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
3977  goto exit;
3978  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
3980  goto exit;
3981  }
3982 
3983  if (!(Vcb->Vpb->Flags & VPB_MOUNTED)) {
3985  goto exit;
3986  }
3987 
3988  if (Vcb->removing) {
3990  goto exit;
3991  }
3992 
3993  Status = verify_vcb(Vcb, Irp);
3994  if (!NT_SUCCESS(Status)) {
3995  ERR("verify_vcb returned %08x\n", Status);
3996  goto exit;
3997  }
3998 
3999  ExAcquireResourceSharedLite(&Vcb->load_lock, TRUE);
4000  locked = TRUE;
4001 
4003 
4004  if (IrpSp->Flags != 0) {
4005  UINT32 flags = IrpSp->Flags;
4006 
4007  TRACE("flags:\n");
4008 
4009  if (flags & SL_CASE_SENSITIVE) {
4010  TRACE("SL_CASE_SENSITIVE\n");
4012  }
4013 
4014  if (flags & SL_FORCE_ACCESS_CHECK) {
4015  TRACE("SL_FORCE_ACCESS_CHECK\n");
4017  }
4018 
4019  if (flags & SL_OPEN_PAGING_FILE) {
4020  TRACE("SL_OPEN_PAGING_FILE\n");
4022  }
4023 
4025  TRACE("SL_OPEN_TARGET_DIRECTORY\n");
4027  }
4028 
4029  if (flags & SL_STOP_ON_SYMLINK) {
4030  TRACE("SL_STOP_ON_SYMLINK\n");
4032  }
4033 
4034  if (flags)
4035  WARN("unknown flags: %x\n", flags);
4036  } else {
4037  TRACE("flags: (none)\n");
4038  }
4039 
4040  if (!IrpSp->FileObject) {
4041  ERR("FileObject was NULL\n");
4043  goto exit;
4044  }
4045 
4046  if (IrpSp->FileObject->RelatedFileObject) {
4047  fcb* relatedfcb = IrpSp->FileObject->RelatedFileObject->FsContext;
4048 
4049  if (relatedfcb && relatedfcb->Vcb != Vcb) {
4050  WARN("RelatedFileObject was for different device\n");
4052  goto exit;
4053  }
4054  }
4055 
4056  // opening volume
4057  if (IrpSp->FileObject->FileName.Length == 0 && !IrpSp->FileObject->RelatedFileObject) {
4058  ULONG RequestedDisposition = ((IrpSp->Parameters.Create.Options >> 24) & 0xff);
4059  ULONG RequestedOptions = IrpSp->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS;
4060 #ifdef DEBUG_FCB_REFCOUNTS
4061  LONG rc;
4062 #endif
4063  ccb* ccb;
4064 
4065  TRACE("open operation for volume\n");
4066 
4067  if (RequestedDisposition != FILE_OPEN && RequestedDisposition != FILE_OPEN_IF) {
4069  goto exit;
4070  }
4071 
4072  if (RequestedOptions & FILE_DIRECTORY_FILE) {
4074  goto exit;
4075  }
4076 
4078  if (!ccb) {
4079  ERR("out of memory\n");
4081  goto exit;
4082  }
4083 
4084  RtlZeroMemory(ccb, sizeof(*ccb));
4085 
4087  ccb->NodeSize = sizeof(*ccb);
4088  ccb->disposition = RequestedDisposition;
4089  ccb->options = RequestedOptions;
4090  ccb->access = IrpSp->Parameters.Create.SecurityContext->AccessState->PreviouslyGrantedAccess;
4092  IrpSp->Flags & SL_FORCE_ACCESS_CHECK ? UserMode : Irp->RequestorMode);
4093  ccb->reserving = FALSE;
4094  ccb->lxss = called_from_lxss();
4095 
4096 #ifdef DEBUG_FCB_REFCOUNTS
4097  rc = InterlockedIncrement(&Vcb->volume_fcb->refcount);
4098  WARN("fcb %p: refcount now %i (volume)\n", Vcb->volume_fcb, rc);
4099 #else
4100  InterlockedIncrement(&Vcb->volume_fcb->refcount);
4101 #endif
4102  IrpSp->FileObject->FsContext = Vcb->volume_fcb;
4103  IrpSp->FileObject->FsContext2 = ccb;
4104 
4105  IrpSp->FileObject->SectionObjectPointer = &Vcb->volume_fcb->nonpaged->segment_object;
4106 
4107  if (!IrpSp->FileObject->Vpb)
4108  IrpSp->FileObject->Vpb = DeviceObject->Vpb;
4109 
4110  InterlockedIncrement(&Vcb->open_files);
4111 
4112  Irp->IoStatus.Information = FILE_OPENED;
4114  } else {
4116  BOOL skip_lock;
4117 
4119 
4120  TRACE("file name: %.*S\n", IrpSp->FileObject->FileName.Length / sizeof(WCHAR), IrpSp->FileObject->FileName.Buffer);
4121 
4122  if (IrpSp->FileObject->RelatedFileObject)
4123  TRACE("related file = %S\n", file_desc(IrpSp->FileObject->RelatedFileObject));
4124 
4125  // Don't lock again if we're being called from within CcCopyRead etc.
4126  skip_lock = ExIsResourceAcquiredExclusiveLite(&Vcb->tree_lock);
4127 
4128  if (!skip_lock)
4129  ExAcquireResourceSharedLite(&Vcb->tree_lock, TRUE);
4130 
4132 
4133  if (!NT_SUCCESS(Status))
4135  else
4137 
4138  if (!skip_lock)
4139  ExReleaseResourceLite(&Vcb->tree_lock);
4140  }
4141 
4142 exit:
4143  Irp->IoStatus.Status = Status;
4145 
4146  TRACE("create returning %08x\n", Status);
4147 
4148  if (locked)
4149  ExReleaseResourceLite(&Vcb->load_lock);
4150 
4151  if (top_level)
4153 
4155 
4156  return Status;
4157 }
void do_rollback(device_extension *Vcb, LIST_ENTRY *rollback)
Definition: treefuncs.c:1032
void clear_rollback(LIST_ENTRY *rollback)
Definition: treefuncs.c:1011
#define TRUE
Definition: types.h:120
#define SL_CASE_SENSITIVE
Definition: iotypes.h:1776
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
#define FsRtlEnterFileSystem
#define FILE_OPEN_IF
Definition: from_kernel.h:56
ULONG options
Definition: btrfs_drv.h:349
USHORT Flags
Definition: iotypes.h:169
#define FsRtlExitFileSystem
Iosb Status
Definition: create.c:4311
#define SL_OPEN_PAGING_FILE
Definition: iotypes.h:1773
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
BOOL manage_volume_privilege
Definition: btrfs_drv.h:354
#define FILE_OPENED
Definition: nt_native.h:769
#define SL_STOP_ON_SYMLINK
Definition: iotypes.h:1775
#define VCB_TYPE_FS
Definition: btrfs_drv.h:627
ACCESS_MASK access
Definition: btrfs_drv.h:357
#define SL_FORCE_ACCESS_CHECK
Definition: iotypes.h:1772
#define FILE_VALID_OPTION_FLAGS
Definition: nt_native.h:759
#define ALLOC_TAG
Definition: btrfs_drv.h:86
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB Vcb
Definition: create.c:4157
static BOOL has_manage_volume_privilege(ACCESS_STATE *access_state, KPROCESSOR_MODE processor_mode)
Definition: create.c:3942
#define STATUS_NOT_A_DIRECTORY
Definition: udferr_usr.h:169
#define IO_DISK_INCREMENT
Definition: iotypes.h:567
unsigned int UINT32
long LONG
Definition: pedump.c:60
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:61
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
BOOLEAN NTAPI ExIsResourceAcquiredExclusiveLite(IN PERESOURCE Resource)
Definition: resource.c:1619
#define IoCompleteRequest
Definition: irp.c:1240
#define BTRFS_NODE_TYPE_CCB
Definition: btrfs_drv.h:83
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:629
NTSTATUS vol_create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:34
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
USHORT NodeType
Definition: btrfs_drv.h:346
GLbitfield flags
Definition: glext.h:7161
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
static NTSTATUS open_file(PDEVICE_OBJECT DeviceObject, _Requires_lock_held_(_Curr_->tree_lock) device_extension *Vcb, PIRP Irp, LIST_ENTRY *rollback)
Definition: create.c:3053
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Definition: typedefs.h:117
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: btrfs_drv.h:1321
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
#define ERR(fmt,...)
Definition: debug.h:109
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
#define SL_OPEN_TARGET_DIRECTORY
Definition: iotypes.h:1774
#define InterlockedIncrement
Definition: armddk.h:53
ULONG disposition
Definition: btrfs_drv.h:348
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:256
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define called_from_lxss()
Definition: create.c:2500
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
BOOL reserving
Definition: btrfs_drv.h:356
void exit(int exitcode)
Definition: _exit.c:33
struct _ccb ccb
static NTSTATUS verify_vcb(device_extension *Vcb, PIRP Irp)
Definition: create.c:3880
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2771
return STATUS_SUCCESS
Definition: btrfs.c:2725
CSHORT NodeSize
Definition: btrfs_drv.h:347
#define VPB_MOUNTED
Definition: iotypes.h:1763
BOOL lxss
Definition: btrfs_drv.h:366
HRESULT Create([out]ITransactionReceiver **ppReceiver)
struct _device_extension * Vcb
Definition: btrfs_drv.h:260
_Ret_z_ WCHAR * file_desc(_In_ PFILE_OBJECT FileObject)
Definition: btrfs.c:1332
#define STATUS_DEVICE_NOT_READY
Definition: shellext.h:65

◆ _Dispatch_type_() [2/4]

_Dispatch_type_ ( IRP_MJ_CLEANUP  )

Definition at line 2161 of file btrfs.c.

2164  {
2165 #else
2166 static NTSTATUS drv_cleanup(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
2167 #endif
2168  NTSTATUS Status;
2172  fcb* fcb = FileObject->FsContext;
2173  BOOL top_level;
2174 
2176 
2177  TRACE("cleanup\n");
2178 
2179  top_level = is_top_level(Irp);
2180 
2181  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
2183  goto exit;
2184  } else if (DeviceObject == master_devobj) {
2185  TRACE("closing file system\n");
2187  goto exit;
2188  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
2190  goto exit;
2191  }
2192 
2193  if (FileObject->Flags & FO_CLEANUP_COMPLETE) {
2194  TRACE("FileObject %p already cleaned up\n", FileObject);
2196  goto exit;
2197  }
2198 
2199  if (!fcb) {
2200  ERR("fcb was NULL\n");
2202  goto exit;
2203  }
2204 
2205  // We have to use the pointer to Vcb stored in the fcb, as we can receive cleanup
2206  // messages belonging to other devices.
2207 
2208  if (FileObject && FileObject->FsContext) {
2209  LONG oc;
2210  ccb* ccb;
2211  file_ref* fileref;
2212  BOOL locked = TRUE;
2213 
2214  ccb = FileObject->FsContext2;
2215  fileref = ccb ? ccb->fileref : NULL;
2216 
2217  TRACE("cleanup called for FileObject %p\n", FileObject);
2218  TRACE("fileref %p (%S), refcount = %u, open_count = %u\n", fileref, file_desc(FileObject), fileref ? fileref->refcount : 0, fileref ? fileref->open_count : 0);
2219 
2220  ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, TRUE);
2221 
2223 
2225 
2226  if (ccb)
2227  FsRtlNotifyCleanup(fcb->Vcb->NotifySync, &fcb->Vcb->DirNotifyList, ccb);
2228 
2229  if (fileref) {
2230  oc = InterlockedDecrement(&fileref->open_count);
2231 #ifdef DEBUG_FCB_REFCOUNTS
2232  ERR("fileref %p: open_count now %i\n", fileref, oc);
2233 #endif
2234  }
2235 
2236  if (ccb && ccb->options & FILE_DELETE_ON_CLOSE && fileref)
2237  fileref->delete_on_close = TRUE;
2238 
2239  if (fileref && fileref->delete_on_close && fcb->type == BTRFS_TYPE_DIRECTORY && fcb->inode_item.st_size > 0 && fcb != fcb->Vcb->dummy_fcb)
2240  fileref->delete_on_close = FALSE;
2241 
2242  if (fcb->Vcb->locked && fcb->Vcb->locked_fileobj == FileObject) {
2243  TRACE("unlocking volume\n");
2246  }
2247 
2248  if (ccb && ccb->reserving) {
2249  fcb->subvol->reserved = NULL;
2250  ccb->reserving = FALSE;
2251  // FIXME - flush all of subvol's fcbs
2252  }
2253 
2254  if (fileref && oc == 0) {
2255  if (!fcb->Vcb->removing) {
2256  if (fileref && fileref->delete_on_close && fileref != fcb->Vcb->root_fileref && fcb != fcb->Vcb->volume_fcb) {
2258 
2260 
2261  if (!fileref->fcb->ads || fileref->dc) {
2262  if (fileref->fcb->ads) {
2264  FILE_ACTION_REMOVED, &fileref->dc->name);
2265  } else
2267  }
2268 
2269  ExReleaseResourceLite(fcb->Header.Resource);
2270  locked = FALSE;
2271 
2272  // fcb_lock needs to be acquired before fcb->Header.Resource
2273  acquire_fcb_lock_exclusive(fcb->Vcb);
2274 
2275  Status = delete_fileref(fileref, FileObject, Irp, &rollback);
2276  if (!NT_SUCCESS(Status)) {
2277  ERR("delete_fileref returned %08x\n", Status);
2279  release_fcb_lock(fcb->Vcb);
2280  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2281  goto exit;
2282  }
2283 
2284  release_fcb_lock(fcb->Vcb);
2285 
2286  locked = FALSE;
2287 
2289  } else if (FileObject->Flags & FO_CACHE_SUPPORTED && fcb->nonpaged->segment_object.DataSectionObject) {
2291  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &iosb);
2292 
2293  if (!NT_SUCCESS(iosb.Status)) {
2294  ERR("CcFlushCache returned %08x\n", iosb.Status);
2295  }
2296 
2297  if (!ExIsResourceAcquiredSharedLite(fcb->Header.PagingIoResource)) {
2298  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, TRUE);
2299  ExReleaseResourceLite(fcb->Header.PagingIoResource);
2300  }
2301 
2302  CcPurgeCacheSection(&fcb->nonpaged->segment_object, NULL, 0, FALSE);
2303 
2304  TRACE("flushed cache on close (FileObject = %p, fcb = %p, AllocationSize = %llx, FileSize = %llx, ValidDataLength = %llx)\n",
2305  FileObject, fcb, fcb->Header.AllocationSize.QuadPart, fcb->Header.FileSize.QuadPart, fcb->Header.ValidDataLength.QuadPart);
2306  }
2307  }
2308 
2309  if (fcb->Vcb && fcb != fcb->Vcb->volume_fcb)
2311  }
2312 
2313  if (locked)
2314  ExReleaseResourceLite(fcb->Header.Resource);
2315 
2316  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2317 
2318  FileObject->Flags |= FO_CLEANUP_COMPLETE;
2319  }
2320 
2322 
2323 exit:
2324  TRACE("returning %08x\n", Status);
2325 
2326  Irp->IoStatus.Status = Status;
2327  Irp->IoStatus.Information = 0;
2328 
2330 
2331  if (top_level)
2333 
2335 
2336  return Status;
2337 }
struct _file_ref * parent
Definition: btrfs_drv.h:326
void do_rollback(device_extension *Vcb, LIST_ENTRY *rollback)
Definition: treefuncs.c:1032
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
BOOLEAN NTAPI CcPurgeCacheSection(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, IN BOOLEAN UninitializeCacheMaps)
Definition: fssup.c:384
void clear_rollback(LIST_ENTRY *rollback)
Definition: treefuncs.c:1011
#define TRUE
Definition: types.h:120
#define FsRtlEnterFileSystem
ULONG options
Definition: btrfs_drv.h:349
VOID NTAPI CcFlushCache(IN PSECTION_OBJECT_POINTERS SectionObjectPointer, IN OPTIONAL PLARGE_INTEGER FileOffset, IN ULONG Length, OUT OPTIONAL PIO_STATUS_BLOCK IoStatus)
Definition: cachesub.c:222
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define FSRTL_VOLUME_UNLOCK
Definition: ntifs_ex.h:443
Status
Definition: btrfs.c:3889
#define VCB_TYPE_FS
Definition: btrfs_drv.h:627
#define FILE_NOTIFY_CHANGE_FILE_NAME
LONG open_count
Definition: btrfs_drv.h:325
#define FILE_NOTIFY_CHANGE_DIR_NAME
void send_notification_fileref(_In_ file_ref *fileref, _In_ ULONG filter_match, _In_ ULONG action, _In_opt_ PUNICODE_STRING stream)
Definition: btrfs.c:1343
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3477
VOID NTAPI FsRtlNotifyCleanup(IN PNOTIFY_SYNC NotifySync, IN PLIST_ENTRY NotifyList, IN PVOID FsContext)
Definition: notify.c:635
BOOLEAN NTAPI ExAcquireResourceExclusiveLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:770
long LONG
Definition: pedump.c:60
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:61
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:81
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define FILE_ACTION_REMOVED
#define IoCompleteRequest
Definition: irp.c:1240
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
LONG refcount
Definition: btrfs_drv.h:324
InsertTailList & Vcb
Definition: btrfs.c:2689
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:256
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
NTSTATUS NTAPI FsRtlNotifyVolumeEvent(IN PFILE_OBJECT FileObject, IN ULONG EventCode)
Definition: pnp.c:38
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:629
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1954
#define FO_CACHE_SUPPORTED
Definition: iotypes.h:1737
BOOL ads
Definition: btrfs_drv.h:299
dir_child * dc
Definition: btrfs_drv.h:328
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
#define InterlockedDecrement
Definition: armddk.h:52
NTSTATUS vol_cleanup(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:328
fcb * fcb
Definition: btrfs_drv.h:316
Definition: typedefs.h:117
INODE_ITEM inode_item
Definition: btrfs_drv.h:264
_In_ fcb _In_ chunk _In_ UINT64 _In_ UINT64 _In_ BOOL _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: btrfs_drv.h:1321
Status
Definition: gdiplustypes.h:24
#define ERR(fmt,...)
Definition: debug.h:109
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
UINT64 st_size
Definition: btrfs.h:267
struct _fcb_nonpaged * nonpaged
Definition: btrfs_drv.h:257
BOOLEAN NTAPI CcUninitializeCacheMap(IN PFILE_OBJECT FileObject, IN OPTIONAL PLARGE_INTEGER TruncateSize, IN OPTIONAL PCACHE_UNINITIALIZE_EVENT UninitializeEvent)
Definition: fssup.c:284
#define FO_CLEANUP_COMPLETE
Definition: iotypes.h:1746
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
struct _root * subvol
Definition: btrfs_drv.h:261
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:256
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
UINT8 type
Definition: btrfs_drv.h:263
BOOL delete_on_close
Definition: btrfs_drv.h:319
NTSTATUS delete_fileref(_In_ file_ref *fileref, _In_opt_ PFILE_OBJECT FileObject, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
Definition: btrfs.c:1949
#define IO_NO_INCREMENT
Definition: iotypes.h:565
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1658
BOOL reserving
Definition: btrfs_drv.h:356
SHARE_ACCESS share_access
Definition: btrfs_drv.h:270
void exit(int exitcode)
Definition: _exit.c:33
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:358
return STATUS_SUCCESS
Definition: btrfs.c:2725
void do_unlock_volume(device_extension *Vcb)
Definition: fsctl.c:2300
struct _device_extension * Vcb
Definition: btrfs_drv.h:260
UNICODE_STRING name
Definition: btrfs_drv.h:230
_Ret_z_ WCHAR * file_desc(_In_ PFILE_OBJECT FileObject)
Definition: btrfs.c:1332

◆ _Dispatch_type_() [3/4]

_Dispatch_type_ ( IRP_MJ_CLOSE  )

Definition at line 467 of file btrfs.c.

470  {
471 #else
472 static NTSTATUS drv_close(_In_ PDEVICE_OBJECT DeviceObject, _In_ PIRP Irp) {
473 #endif
477  BOOL top_level;
478 
480 
481  TRACE("close\n");
482 
483  top_level = is_top_level(Irp);
484 
485  if (DeviceObject == master_devobj) {
486  TRACE("Closing file system\n");
488  goto end;
489  } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
491  goto end;
492  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
494  goto end;
495  }
496 
498 
499  // FIXME - unmount if called for volume
500  // FIXME - call FsRtlNotifyUninitializeSync(&Vcb->NotifySync) if unmounting
501 
503 
504 end:
505  Irp->IoStatus.Status = Status;
506  Irp->IoStatus.Information = 0;
507 
509 
510  if (top_level)
512 
513  TRACE("returning %08x\n", Status);
514 
516 
517  return Status;
518 }
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
Status
Definition: btrfs.c:3889
#define VCB_TYPE_FS
Definition: btrfs_drv.h:627
GLuint GLuint end
Definition: gl.h:1545
#define IO_DISK_INCREMENT
Definition: iotypes.h:567
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:61
PVOID DeviceExtension
Definition: env_spec_w32.h:418
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
InsertTailList & Vcb
Definition: btrfs.c:2689
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:629
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
PFILE_OBJECT FileObject
Definition: iotypes.h:2812
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:256
static NTSTATUS close_file(_In_ PFILE_OBJECT FileObject, _In_ PIRP Irp)
Definition: btrfs.c:1669
NTSTATUS vol_close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:48
return STATUS_SUCCESS
Definition: btrfs.c:2725

◆ _Dispatch_type_() [4/4]

_Dispatch_type_ ( IRP_MJ_PNP  )

Definition at line 488 of file pnp.c.

490  {
494  BOOL top_level;
495 
497 
498  top_level = is_top_level(Irp);
499 
500  if (Vcb && Vcb->type == VCB_TYPE_CONTROL) {
502  goto exit;
503  } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
506  Status = IoCallDriver(vde->pdo, Irp);
507  goto exit;
508  } else if (Vcb && Vcb->type == VCB_TYPE_PDO) {
510  goto end;
511  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
513  goto end;
514  }
515 
517 
518  switch (IrpSp->MinorFunction) {
521  break;
522 
525  break;
526 
529  break;
530 
533  break;
534 
535  default:
536  TRACE("passing minor function 0x%x on\n", IrpSp->MinorFunction);
537 
539  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
540  goto exit;
541  }
542 
543 end:
544  Irp->IoStatus.Status = Status;
545 
547 
548 exit:
549  TRACE("returning %08x\n", Status);
550 
551  if (top_level)
553 
555 
556  return Status;
557 }
NTSTATUS pnp_query_remove_device(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pnp.c:184
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define VCB_TYPE_PDO
Definition: btrfs_drv.h:630
#define IRP_MN_REMOVE_DEVICE
#define FsRtlEnterFileSystem
#define FsRtlExitFileSystem
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
PDEVICE_OBJECT pdo
Definition: btrfs_drv.h:831
#define VCB_TYPE_FS
Definition: btrfs_drv.h:627
GLuint GLuint end
Definition: gl.h:1545
static NTSTATUS pnp_remove_device(PDEVICE_OBJECT DeviceObject)
Definition: pnp.c:226
#define IRP_MN_QUERY_REMOVE_DEVICE
PVOID DeviceExtension
Definition: env_spec_w32.h:418
static NTSTATUS bus_pnp(control_device_extension *cde, PIRP Irp)
Definition: pnp.c:363
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
#define IRP_MN_SURPRISE_REMOVAL
Definition: ntifs_ex.h:408
#define TRACE(s)
Definition: solgame.cpp:4
unsigned int BOOL
Definition: ntddk_ex.h:94
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:629
#define Vcb
Definition: cdprocs.h:1425
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
static NTSTATUS pnp_cancel_remove_device(PDEVICE_OBJECT DeviceObject)
Definition: pnp.c:158
#define VCB_TYPE_CONTROL
Definition: btrfs_drv.h:628
Status
Definition: gdiplustypes.h:24
static NTSTATUS pdo_pnp(PDEVICE_OBJECT pdo, PIRP Irp)
Definition: pnp.c:467
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
BOOL is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:256
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:565
void exit(int exitcode)
Definition: _exit.c:33
NTSTATUS pnp_surprise_removal(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pnp.c:259

◆ DuplicateUnicodeString()

NTSTATUS DuplicateUnicodeString ( IN ULONG  Flags,
IN PCUNICODE_STRING  SourceString,
OUT PUNICODE_STRING  DestinationString 
)

Definition at line 72 of file misc.c.

76 {
81  {
83  }
84 
85 
86  if ((SourceString->Length == 0)
89  {
93  }
94  else
95  {
96  USHORT DestMaxLength = SourceString->Length;
97 
99  DestMaxLength += sizeof(UNICODE_NULL);
100 
102  if (DestinationString->Buffer == NULL)
103  return STATUS_NO_MEMORY;
104 
107  DestinationString->MaximumLength = DestMaxLength;
108 
111  }
112 
113  return STATUS_SUCCESS;
114 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define RTL_DUPLICATE_UNICODE_STRING_ALLOCATE_NULL_STRING
Definition: green.h:16
unsigned short Length
Definition: sprintf.c:451
#define WCHAR
Definition: msvc.h:43
#define I8042PRT_TAG
Definition: i8042prt.h:12
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
void * Buffer
Definition: sprintf.c:453
#define UNICODE_NULL
_Out_ _Inout_ POEM_STRING DestinationString
Definition: rtlfuncs.h:1869
smooth NULL
Definition: ftsmooth.c:416
#define RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE
Definition: green.h:15
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
_Out_ _Inout_ POEM_STRING _In_ PCUNICODE_STRING SourceString
Definition: rtlfuncs.h:1869
unsigned short USHORT
Definition: pedump.c:61
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
return STATUS_SUCCESS
Definition: btrfs.c:2725
unsigned short MaximumLength
Definition: sprintf.c:452

Referenced by DriverEntry(), FdcPdoQueryId(), PciCreateCompatibleIDsString(), PciCreateHardwareIDsString(), PciIdeXPdoQueryId(), ReportDetectedDevice(), SearchForLegacyDrivers(), and SerenumPdoQueryId().

◆ i8042ChangeMode()

BOOLEAN i8042ChangeMode ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN UCHAR  FlagsToDisable,
IN UCHAR  FlagsToEnable 
)

Definition at line 37 of file pnp.c.

41 {
42  UCHAR Value;
44 
45  if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, KBD_READ_MODE))
46  {
47  WARN_(I8042PRT, "Can't read i8042 mode\n");
48  return FALSE;
49  }
50 
51  Status = i8042ReadDataWait(DeviceExtension, &Value);
52  if (!NT_SUCCESS(Status))
53  {
54  WARN_(I8042PRT, "No response after read i8042 mode\n");
55  return FALSE;
56  }
57 
58  Value &= ~FlagsToDisable;
59  Value |= FlagsToEnable;
60 
61  if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, KBD_WRITE_MODE))
62  {
63  WARN_(I8042PRT, "Can't set i8042 mode\n");
64  return FALSE;
65  }
66 
67  if (!i8042Write(DeviceExtension, DeviceExtension->DataPort, Value))
68  {
69  WARN_(I8042PRT, "Can't send i8042 mode\n");
70  return FALSE;
71  }
72 
73  return TRUE;
74 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN i8042Write(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PUCHAR addr, IN UCHAR data)
Definition: readwrite.c:199
#define KBD_WRITE_MODE
Definition: i8042prt.h:222
#define KBD_READ_MODE
Definition: i8042prt.h:221
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
NTSTATUS i8042ReadDataWait(IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Data)
Definition: readwrite.c:95
#define WARN_(ch,...)
Definition: debug.h:157

Referenced by EnableInterrupts(), i8042BasicDetect(), and i8042DetectKeyboard().

◆ i8042Flush()

VOID i8042Flush ( IN PPORT_DEVICE_EXTENSION  DeviceExtension)

Definition at line 21 of file readwrite.c.

23 {
24  UCHAR Ignore;
25 
26  /* Flush output buffer */
27  while (NT_SUCCESS(i8042ReadData(DeviceExtension, KBD_OBF /* | MOU_OBF*/, &Ignore))) {
29  TRACE_(I8042PRT, "Output data flushed\n");
30  }
31 
32  /* Flush input buffer */
33  while (NT_SUCCESS(i8042ReadData(DeviceExtension, KBD_IBF, &Ignore))) {
35  TRACE_(I8042PRT, "Input data flushed\n");
36  }
37 }
#define KBD_OBF
Definition: i8042prt.h:250
#define KBD_IBF
Definition: i8042prt.h:251
#define TRACE_(x)
Definition: compat.h:66
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
unsigned char UCHAR
Definition: xmlstorage.h:181
NTSTATUS i8042ReadData(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR StatusFlags, OUT PUCHAR Data)
Definition: readwrite.c:56
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:99

Referenced by EnableInterrupts(), i8042BasicDetect(), and i8042DetectMouse().

◆ i8042InitializeHwHacks()

VOID NTAPI i8042InitializeHwHacks ( VOID  )

Definition at line 182 of file hwhacks.c.

184 {
186  PVOID DataBlockObject;
187  PWNODE_ALL_DATA AllData;
189 
190  /* Open the data block object for the SMBIOS table */
193  &DataBlockObject);
194  if (!NT_SUCCESS(Status))
195  {
196  DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
197  return;
198  }
199 
200  /* Query the required buffer size */
201  BufferSize = 0;
202  Status = IoWMIQueryAllData(DataBlockObject, &BufferSize, NULL);
203  if (!NT_SUCCESS(Status))
204  {
205  DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
206  return;
207  }
208 
209  AllData = ExAllocatePoolWithTag(PagedPool, BufferSize, 'BTMS');
210  if (AllData == NULL)
211  {
212  DPRINT1("Failed to allocate %lu bytes for SMBIOS tables\n", BufferSize);
213  return;
214  }
215 
216  /* Query the buffer data */
217  Status = IoWMIQueryAllData(DataBlockObject, &BufferSize, AllData);
218  if (!NT_SUCCESS(Status))
219  {
220  DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
221  ExFreePoolWithTag(AllData, 'BTMS');
222  return;
223  }
224 
225  /* FIXME: This function should be removed once the mssmbios driver is implemented */
226  /* Store SMBios data in registry */
227  i8042StoreSMBiosTables(AllData + 1,
228  AllData->FixedInstanceSize);
229  DPRINT1("SMBiosTables HACK, see CORE-14867\n");
230 
231  /* Parse the table */
232  i8042ParseSMBiosTables(AllData + 1,
233  AllData->WnodeHeader.BufferSize);
234 
235  /* Free the buffer */
236  ExFreePoolWithTag(AllData, 'BTMS');
237 }
static VOID i8042StoreSMBiosTables(_In_reads_bytes_(TableSize) PVOID SMBiosTables, _In_ ULONG TableSize)
Definition: hwhacks.c:118
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI IoWMIQueryAllData(IN PVOID DataBlockObject, IN OUT ULONG *InOutBufferSize, OUT PVOID OutBuffer)
Definition: wmi.c:155
smooth NULL
Definition: ftsmooth.c:416
const GUID MSSmBios_RawSMBiosTables_GUID
Definition: hwhacks.c:20
static VOID i8042ParseSMBiosTables(_In_reads_bytes_(TableSize) PVOID SMBiosTables, _In_ ULONG TableSize)
Definition: hwhacks.c:61
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define BufferSize
Definition: classpnp.h:419
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI IoWMIOpenBlock(_In_ LPCGUID DataBlockGuid, _In_ ULONG DesiredAccess, _Out_ PVOID *DataBlockObject)
Definition: wmi.c:126
ULONG FixedInstanceSize
Definition: wmistr.h:118
#define WMIGUID_QUERY
Definition: wmistr.h:159
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
struct _WNODE_HEADER WnodeHeader
Definition: wmistr.h:112
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099

Referenced by DriverEntry().

◆ i8042IsrWritePort()

BOOLEAN i8042IsrWritePort ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN UCHAR  Value,
IN UCHAR SelectCmd  OPTIONAL 
)

Definition at line 40 of file readwrite.c.

44 {
45  if (SelectCmd)
46  if (!i8042Write(DeviceExtension, DeviceExtension->ControlPort, SelectCmd))
47  return FALSE;
48 
49  return i8042Write(DeviceExtension, DeviceExtension->DataPort, Value);
50 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
BOOLEAN i8042Write(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PUCHAR addr, IN UCHAR data)
Definition: readwrite.c:199

Referenced by i8042DetectMouse(), i8042MouInitialize(), i8042MouIsrWritePort(), and StartProcedure().

◆ i8042MouHandle()

VOID i8042MouHandle ( IN PI8042_MOUSE_EXTENSION  DeviceExtension,
IN UCHAR  Output 
)

Definition at line 68 of file mouse.c.

71 {
72  PMOUSE_INPUT_DATA MouseInput;
73  CHAR Scroll;
74 
75  MouseInput = DeviceExtension->MouseBuffer + DeviceExtension->MouseInBuffer;
76 
77  switch (DeviceExtension->MouseState)
78  {
79  case MouseIdle:
80  /* This bit should be 1, if not drop the packet, we
81  * might be lucky and get in sync again
82  */
83  if (!(Output & 8)) {
84  WARN_(I8042PRT, "Bad input, dropping..\n");
85  return;
86  }
87 
88  MouseInput->Buttons = 0;
89  MouseInput->RawButtons = 0;
90  MouseInput->Flags = MOUSE_MOVE_RELATIVE;
91 
92  /* Note how we ignore the overflow bits, like Windows
93  * is said to do. There's no reasonable thing to do
94  * anyway.
95  */
96 
97  if (Output & 16)
98  MouseInput->LastX = 1;
99  else
100  MouseInput->LastX = 0;
101  if (Output & 32)
102  MouseInput->LastY = 1;
103  else
104  MouseInput->LastY = 0;
105 
106  if (Output & 1)
107  MouseInput->RawButtons |= MOUSE_LEFT_BUTTON_DOWN;
108  if (Output & 2)
109  MouseInput->RawButtons |= MOUSE_RIGHT_BUTTON_DOWN;
110  if (Output & 4)
111  MouseInput->RawButtons |= MOUSE_MIDDLE_BUTTON_DOWN;
112 
113  DeviceExtension->MouseState = XMovement;
114  break;
115 
116  case XMovement:
117  if (MouseInput->LastX)
118  MouseInput->LastX = (LONG) Output - 256;
119  else
120  MouseInput->LastX = Output;
121 
122  DeviceExtension->MouseState = YMovement;
123  break;
124 
125  case YMovement:
126  if (MouseInput->LastY)
127  MouseInput->LastY = (LONG)Output - 256;
128  else
129  MouseInput->LastY = (LONG)Output;
130 
131  /* Windows wants it the other way around */
132  MouseInput->LastY = -MouseInput->LastY;
133 
134  if (DeviceExtension->MouseType == GenericPS2 ||
135  DeviceExtension->MouseType == Ps2pp)
136  {
138  DeviceExtension,
142  DeviceExtension->MouseHook.QueueMousePacket(DeviceExtension->MouseHook.CallContext);
143  DeviceExtension->MouseState = MouseIdle;
144  }
145  else
146  {
147  DeviceExtension->MouseState = ZMovement;
148  }
149  break;
150 
151  case ZMovement:
152  Scroll = Output & 0x0f;
153  if (Scroll & 8)
154  Scroll |= 0xf0;
155 
156  if (Scroll)
157  {
158  MouseInput->RawButtons |= MOUSE_WHEEL;
159  MouseInput->ButtonData = (USHORT)(Scroll * -WHEEL_DELTA);
160  }
161 
162  if (DeviceExtension->MouseType == IntellimouseExplorer)
163  {
164  if (Output & 16)
165  MouseInput->RawButtons |= MOUSE_BUTTON_4_DOWN;
166  if (Output & 32)
167  MouseInput->RawButtons |= MOUSE_BUTTON_5_DOWN;
168  }
170  DeviceExtension,
176  DeviceExtension->MouseHook.QueueMousePacket(DeviceExtension->MouseHook.CallContext);
177  DeviceExtension->MouseState = MouseIdle;
178  break;
179 
180  default:
181  ERR_(I8042PRT, "Unexpected state 0x%lx!\n", DeviceExtension->MouseState);
182  ASSERT(FALSE);
183  }
184 }
#define MOUSE_MIDDLE_BUTTON_DOWN
Definition: ntddmou.h:50
#define MOUSE_LEFT_BUTTON_DOWN
Definition: ntddmou.h:46
#define MOUSE_WHEEL
Definition: ntddmou.h:56
char CHAR
Definition: xmlstorage.h:175
#define ERR_(ch,...)
Definition: debug.h:156
USHORT Flags
Definition: ntddmou.h:78
#define WHEEL_DELTA
Definition: treelist.c:99
ULONG RawButtons
Definition: ntddmou.h:86
#define MOUSE_BUTTON_4_DOWN
Definition: ntddmou.h:52
#define MOUSE_MOVE_RELATIVE
Definition: ntddmou.h:67
#define MOUSE_RIGHT_BUTTON_DOWN
Definition: ntddmou.h:48
USHORT ButtonData
Definition: ntddmou.h:83
#define LONG
Definition: msvc.h:36
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Definition: arc.h:85
unsigned short USHORT
Definition: pedump.c:61
#define MOUSE_BUTTON_5_DOWN
Definition: ntddmou.h:54
#define WARN_(ch,...)
Definition: debug.h:157
VOID i8042MouHandleButtons(IN PI8042_MOUSE_EXTENSION DeviceExtension, IN USHORT Mask)
Definition: mouse.c:191

Referenced by i8042MouHandlePs2pp(), and i8042MouInterruptService().

◆ i8042MouHandleButtons()

VOID i8042MouHandleButtons ( IN PI8042_MOUSE_EXTENSION  DeviceExtension,
IN USHORT  Mask 
)

Definition at line 191 of file mouse.c.

194 {
195  PMOUSE_INPUT_DATA MouseInput;
196  USHORT NewButtonData;
197  USHORT ButtonDiff;
198 
199  MouseInput = DeviceExtension->MouseBuffer + DeviceExtension->MouseInBuffer;
200  NewButtonData = (USHORT)(MouseInput->RawButtons & Mask);
201  ButtonDiff = (NewButtonData ^ DeviceExtension->MouseButtonState) & Mask;
202 
203  /* Note that the defines are such:
204  * MOUSE_LEFT_BUTTON_DOWN 1
205  * MOUSE_LEFT_BUTTON_UP 2
206  */
207  MouseInput->ButtonFlags |= (NewButtonData & ButtonDiff) |
208  (((~(NewButtonData)) << 1) & (ButtonDiff << 1)) |
209  (MouseInput->RawButtons & 0xfc00);
210 
211  INFO_(I8042PRT, "Left raw/up/down: %u/%u/%u\n",
212  MouseInput->RawButtons & MOUSE_LEFT_BUTTON_DOWN,
213  MouseInput->ButtonFlags & MOUSE_LEFT_BUTTON_DOWN,
214  MouseInput->ButtonFlags & MOUSE_LEFT_BUTTON_UP);
215 
216  DeviceExtension->MouseButtonState =
217  (DeviceExtension->MouseButtonState & ~Mask) | (NewButtonData & Mask);
218 }
#define MOUSE_LEFT_BUTTON_DOWN
Definition: ntddmou.h:46
#define INFO_(ch,...)
Definition: debug.h:159
ULONG RawButtons
Definition: ntddmou.h:86
#define MOUSE_LEFT_BUTTON_UP
Definition: ntddmou.h:47
USHORT ButtonFlags
Definition: ntddmou.h:82
unsigned short USHORT
Definition: pedump.c:61

Referenced by i8042MouHandle(), and i8042MouHandlePs2pp().

◆ i8042MouHandlePs2pp()

VOID i8042MouHandlePs2pp ( IN PI8042_MOUSE_EXTENSION  DeviceExtension,
IN UCHAR  Input 
)

Definition at line 19 of file ps2pp.c.

22 {
23  UCHAR PktType;
24  PMOUSE_INPUT_DATA MouseInput;
25 
26  MouseInput = DeviceExtension->MouseBuffer + DeviceExtension->MouseInBuffer;
27 
28  /* First, collect 3 bytes for a packet
29  * We can detect out-of-sync only by checking
30  * the whole packet anyway.
31  *
32  * If bit 7 and 8 of the first byte are 0, its
33  * a normal packet.
34  *
35  * Otherwise, the packet is different, like this:
36  * 1: E 1 b3 b2 1 x x x
37  * 2: x x b1 b0 x1 x0 1 0
38  * 3: x x x x x x x1 x0
39  *
40  * b3-0 form a code that specifies the packet type:
41  *
42  * 0 Device Type
43  * 1 Rollers and buttons
44  * 2 Reserved
45  * 3 Reserved
46  * 4 Device ID
47  * 5 Channel & Battery
48  * 6 Wireless notifications
49  * 7 Reserved
50  * 8 ShortID LSB (ShortID is a number that is supposed to differentiate
51  * 9 ShortID MSB between your mouse and your neighbours')
52  * 10 Reserved
53  * 11 Mouse capabilities
54  * 12 Remote control LSB
55  * 13 Remote control MSB
56  * 14 Reserved
57  * 15 Extended packet
58  */
59 
60  switch (DeviceExtension->MouseState)
61  {
62  case MouseIdle:
63  case XMovement:
64  DeviceExtension->MouseLogiBuffer[DeviceExtension->MouseState] = Input;
65  DeviceExtension->MouseState++;
66  break;
67 
68  case YMovement:
69  DeviceExtension->MouseLogiBuffer[2] = Input;
70  DeviceExtension->MouseState = MouseIdle;
71 
72  /* first check if it's a normal packet */
73 
74  if (!(DeviceExtension->MouseLogiBuffer[0] & 0xC0))
75  {
76  DeviceExtension->MouseState = MouseIdle;
77  i8042MouHandle(DeviceExtension, DeviceExtension->MouseLogiBuffer[0]);
78  i8042MouHandle(DeviceExtension, DeviceExtension->MouseLogiBuffer[1]);
79  i8042MouHandle(DeviceExtension, DeviceExtension->MouseLogiBuffer[2]);
80  /* We could care about wether MouseState really
81  * advances, but we don't need to because we're
82  * only doing three bytes anyway, so the packet
83  * will never complete if it's broken.
84  */
85  return;
86  }
87 
88  /* sanity check */
89  if (((DeviceExtension->MouseLogiBuffer[0] & 0x48) != 0x48) ||
90  (((DeviceExtension->MouseLogiBuffer[1] & 0x0C) >> 2) !=
91  (DeviceExtension->MouseLogiBuffer[2] & 0x03)))
92  {
93  WARN_(I8042PRT, "Ps2pp packet fails sanity checks\n");
94  return;
95  }
96 
97  /* Now get the packet type */
98  PktType = ((DeviceExtension->MouseLogiBuffer[0] & 0x30) >> 2) |
99  ((DeviceExtension->MouseLogiBuffer[1] & 0x30) >> 4);
100 
101  switch (PktType)
102  {
103  case 0:
104  /* The packet contains the device ID, but we
105  * already read that in the initialization
106  * sequence. Ignore it.
107  */
108  return;
109  case 1:
110  RtlZeroMemory(MouseInput, sizeof(MOUSE_INPUT_DATA));
111  if (DeviceExtension->MouseLogiBuffer[2] & 0x10)
112  MouseInput->RawButtons |= MOUSE_BUTTON_4_DOWN;
113 
114  if (DeviceExtension->MouseLogiBuffer[2] & 0x20)
115  MouseInput->RawButtons |= MOUSE_BUTTON_5_DOWN;
116 
117  if (DeviceExtension->MouseLogiBuffer[2] & 0x0F)
118  {
119  MouseInput->ButtonFlags |= MOUSE_WHEEL;
120  if (DeviceExtension->MouseLogiBuffer[2] & 0x08)
121  MouseInput->ButtonData = (DeviceExtension->MouseLogiBuffer[2] & 0x07) - 8;
122  else
123  MouseInput->ButtonData = DeviceExtension->MouseLogiBuffer[2] & 0x07;
124  }
126  DeviceExtension,
128  DeviceExtension->MouseHook.QueueMousePacket(DeviceExtension->MouseHook.CallContext);
129  return;
130  default:
131  /* These are for things that would probably
132  * be handled by logitechs own driver.
133  */
134  return;
135  }
136 
137  default:
138  WARN_(I8042PRT, "Unexpected input state for ps2pp!\n");
139  }
140 }
#define MOUSE_WHEEL
Definition: ntddmou.h:56
Definition: arc.h:84
VOID i8042MouHandleButtons(IN PI8042_MOUSE_EXTENSION DeviceExtension, IN USHORT Mask)
Definition: mouse.c:191
ULONG RawButtons
Definition: ntddmou.h:86
#define MOUSE_BUTTON_4_DOWN
Definition: ntddmou.h:52
USHORT ButtonData
Definition: ntddmou.h:83
unsigned char UCHAR
Definition: xmlstorage.h:181
USHORT ButtonFlags
Definition: ntddmou.h:82
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define MOUSE_BUTTON_5_DOWN
Definition: ntddmou.h:54
VOID i8042MouHandle(IN PI8042_MOUSE_EXTENSION DeviceExtension, IN UCHAR Output)
Definition: mouse.c:68
#define WARN_(ch,...)
Definition: debug.h:157

Referenced by i8042MouInterruptService().

◆ i8042MouInitialize()

NTSTATUS i8042MouInitialize ( IN PI8042_MOUSE_EXTENSION  DeviceExtension)

Definition at line 224 of file mouse.c.

226 {
228  UCHAR Value;
229 
230  /* Enable the PS/2 mouse port */
231  i8042Write(DeviceExtension->Common.PortDeviceExtension, DeviceExtension->Common.PortDeviceExtension->ControlPort, MOUSE_ENAB);
232 
233  /* Enable the mouse */
234  if(!i8042IsrWritePort(DeviceExtension->Common.PortDeviceExtension, MOU_ENAB, CTRL_WRITE_MOUSE))
235  {
236  WARN_(I8042PRT, "Failed to enable mouse!\n");
237  return STATUS_IO_DEVICE_ERROR;
238  }
239 
240  Status = i8042ReadDataWait(DeviceExtension->Common.PortDeviceExtension, &Value);
241  if (!NT_SUCCESS(Status))
242  {
243  WARN_(I8042PRT, "Failed to read the response of MOU_ENAB, status 0x%08lx\n", Status);
244  return Status;
245  }
246 
247  if(Value == MOUSE_ACK)
248  {
249  INFO_(I8042PRT, "Mouse was enabled successfully!\n");
250  return STATUS_SUCCESS;
251  }
252 
253  WARN_(I8042PRT, "Got 0x%02x instead of 0xFA\n", Value);
254  return STATUS_IO_DEVICE_ERROR;
255 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
#define INFO_(ch,...)
Definition: debug.h:159
#define MOU_ENAB
Definition: i8042prt.h:278
LONG NTSTATUS
Definition: precomp.h:26
#define MOUSE_ENAB
Definition: i8042prt.h:223
BOOLEAN i8042Write(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PUCHAR addr, IN UCHAR data)
Definition: readwrite.c:199
BOOLEAN i8042IsrWritePort(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Value, IN UCHAR SelectCmd OPTIONAL)
Definition: readwrite.c:40
#define STATUS_IO_DEVICE_ERROR
Definition: udferr_usr.h:179
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
unsigned char UCHAR
Definition: xmlstorage.h:181
#define MOUSE_ACK
Definition: i8042prt.h:285
Status
Definition: gdiplustypes.h:24
NTSTATUS i8042ReadDataWait(IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Data)
Definition: readwrite.c:95
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define WARN_(ch,...)
Definition: debug.h:157
#define CTRL_WRITE_MOUSE
Definition: i8042prt.h:228

Referenced by i8042ConnectMouseInterrupt().

◆ i8042PacketIsr()

BOOLEAN i8042PacketIsr ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN UCHAR  Output 
)

Definition at line 272 of file i8042prt.c.

275 {
276  if (DeviceExtension->Packet.State == Idle)
277  return FALSE;
278 
279  switch (Output)
280  {
281  case KBD_RESEND:
282  DeviceExtension->PacketResends++;
283  if (DeviceExtension->PacketResends > DeviceExtension->Settings.ResendIterations)
284  {
285  DeviceExtension->Packet.State = Idle;
286  DeviceExtension->PacketComplete = TRUE;
287  DeviceExtension->PacketResult = STATUS_IO_TIMEOUT;
288  DeviceExtension->PacketResends = 0;
289  return TRUE;
290  }
291  DeviceExtension->Packet.CurrentByte--;
292  break;
293 
294  case KBD_NACK:
295  DeviceExtension->Packet.State = Idle;
296  DeviceExtension->PacketComplete = TRUE;
297  DeviceExtension->PacketResult = STATUS_UNEXPECTED_IO_ERROR;
298  DeviceExtension->PacketResends = 0;
299  return TRUE;
300 
301  default:
302  DeviceExtension->PacketResends = 0;
303  }
304 
305  if (DeviceExtension->Packet.CurrentByte >= DeviceExtension->Packet.ByteCount)
306  {
307  DeviceExtension->Packet.State = Idle;
308  DeviceExtension->PacketComplete = TRUE;
309  DeviceExtension->PacketResult = STATUS_SUCCESS;
310  return TRUE;
311  }
312 
313  if (!i8042PacketWrite(DeviceExtension))
314  {
315  DeviceExtension->Packet.State = Idle;
316  DeviceExtension->PacketComplete = TRUE;
317  DeviceExtension->PacketResult = STATUS_IO_TIMEOUT;
318  return TRUE;
319  }
320  DeviceExtension->Packet.CurrentByte++;
321 
322  return TRUE;
323 }
#define TRUE
Definition: types.h:120
static BOOLEAN i8042PacketWrite(IN PPORT_DEVICE_EXTENSION DeviceExtension)
Definition: i8042prt.c:249
Definition: ntdd8042.h:62
Definition: arc.h:85
#define KBD_RESEND
Definition: i8042prt.h:244
#define STATUS_IO_TIMEOUT
Definition: udferr_usr.h:163
#define STATUS_UNEXPECTED_IO_ERROR
Definition: ntstatus.h:455
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define KBD_NACK
Definition: i8042prt.h:243

Referenced by i8042KbdInterruptService(), and i8042MouInterruptService().

◆ i8042ReadData()

NTSTATUS i8042ReadData ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN UCHAR  StatusFlags,
OUT PUCHAR  Data 
)

Definition at line 56 of file readwrite.c.

60 {
63 
64  Status = i8042ReadStatus(DeviceExtension, &PortStatus);
65  if (!NT_SUCCESS(Status))
66  return Status;
67 
68  // If data is available
69  if (PortStatus & StatusFlags)
70  {
71  *Data = READ_PORT_UCHAR(DeviceExtension->DataPort);
72  INFO_(I8042PRT, "Read: 0x%02x (status: 0x%x)\n", Data[0], PortStatus);
73 
74  // If the data is valid (not timeout, not parity error)
75  if ((PortStatus & KBD_PERR) == 0)
76  return STATUS_SUCCESS;
77  }
78  return STATUS_UNSUCCESSFUL;
79 }
#define INFO_(ch,...)
Definition: debug.h:159
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:535
LONG NTSTATUS
Definition: precomp.h:26
#define KBD_PERR
Definition: i8042prt.h:253
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
unsigned char UCHAR
Definition: xmlstorage.h:181
_Outptr_ PUSB_DEVICE_HANDLE _In_ PUSB_DEVICE_HANDLE _In_ USHORT PortStatus
Definition: hubbusif.h:40
Status
Definition: gdiplustypes.h:24
NTSTATUS i8042ReadStatus(IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Status)
Definition: readwrite.c:82
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by i8042Flush().

◆ i8042ReadDataWait()

NTSTATUS i8042ReadDataWait ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
OUT PUCHAR  Data 
)

Definition at line 95 of file readwrite.c.

98 {
99  ULONG Counter;
101 
102  Counter = DeviceExtension->Settings.PollingIterations;
103 
104  while (Counter--)
105  {
106  Status = i8042ReadKeyboardData(DeviceExtension, Data);
107 
108  if (NT_SUCCESS(Status))
109  return Status;
110 
112  }
113 
114  /* Timed out */
115  return STATUS_IO_TIMEOUT;
116 }
LONG NTSTATUS
Definition: precomp.h:26
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define i8042ReadKeyboardData(DeviceExtension, Data)
Definition: i8042prt.h:405
Status
Definition: gdiplustypes.h:24
#define STATUS_IO_TIMEOUT
Definition: udferr_usr.h:163
static LARGE_INTEGER Counter
Definition: clock.c:43
unsigned int ULONG
Definition: retypes.h:1
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:99

Referenced by i8042BasicDetect(), i8042ChangeMode(), i8042DetectMouse(), i8042MouInitialize(), i8042SynchReadPort(), and i8042SynchWritePort().

◆ i8042ReadStatus()

NTSTATUS i8042ReadStatus ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
OUT PUCHAR  Status 
)

Definition at line 82 of file readwrite.c.

85 {
86  ASSERT(DeviceExtension->ControlPort != NULL);
87  *Status = READ_PORT_UCHAR(DeviceExtension->ControlPort);
88  return STATUS_SUCCESS;
89 }
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:535
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2725

Referenced by i8042KbdInterruptService(), i8042MouInterruptService(), and i8042ReadData().

◆ i8042StartPacket()

NTSTATUS i8042StartPacket ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN PFDO_DEVICE_EXTENSION  FdoDeviceExtension,
IN PUCHAR  Bytes,
IN ULONG  ByteCount,
IN PIRP  Irp 
)

Definition at line 330 of file i8042prt.c.

336 {
337  KIRQL Irql;
339 
340  Irql = KeAcquireInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt);
341 
342  if (DeviceExtension->Packet.State != Idle)
343  {
345  goto done;
346  }
347 
348  switch (FdoDeviceExtension->Type)
349  {
350  case Keyboard: DeviceExtension->PacketPort = 0; break;
351  case Mouse: DeviceExtension->PacketPort = CTRL_WRITE_MOUSE; break;
352  default:
353  ERR_(I8042PRT, "Unknown FDO type %u\n", FdoDeviceExtension->Type);
354  ASSERT(FALSE);
356  goto done;
357  }
358 
359  DeviceExtension->Packet.Bytes = Bytes;
360  DeviceExtension->Packet.CurrentByte = 0;
361  DeviceExtension->Packet.ByteCount = ByteCount;
362  DeviceExtension->Packet.State = SendingBytes;
363  DeviceExtension->PacketResult = Status = STATUS_PENDING;
364  DeviceExtension->CurrentIrp = Irp;
365  DeviceExtension->CurrentIrpDevice = FdoDeviceExtension->Fdo;
366 
367  if (!i8042PacketWrite(DeviceExtension))
368  {
370  DeviceExtension->Packet.State = Idle;
371  DeviceExtension->PacketResult = STATUS_ABANDONED;
372  goto done;
373  }
374 
375  DeviceExtension->Packet.CurrentByte++;
376 
377 done:
378  KeReleaseInterruptSpinLock(DeviceExtension->HighestDIRQLInterrupt, Irql);
379 
380  if (Status != STATUS_PENDING)
381  {
382  DeviceExtension->CurrentIrp = NULL;
383  DeviceExtension->CurrentIrpDevice = NULL;
384  Irp->IoStatus.Status = Status;
386  }
387  return Status;
388 }
_In_ PIRP Irp
Definition: csq.h:116
#define ERR_(ch,...)
Definition: debug.h:156
LONG NTSTATUS
Definition: precomp.h:26
_In_ UINT Bytes
Definition: mmcopy.h:9
_Out_ PKIRQL Irql
Definition: csq.h:179
#define STATUS_INTERNAL_ERROR
Definition: ntstatus.h:451
UCHAR KIRQL
Definition: env_spec_w32.h:591
static BOOLEAN i8042PacketWrite(IN PPORT_DEVICE_EXTENSION DeviceExtension)
Definition: i8042prt.c:249
VOID NTAPI KeReleaseInterruptSpinLock(IN PKINTERRUPT Interrupt, IN KIRQL OldIrql)
Definition: spinlock.c:165
smooth NULL
Definition: ftsmooth.c:416
#define IoCompleteRequest
Definition: irp.c:1240
Definition: ntdd8042.h:62
#define STATUS_PENDING
Definition: ntstatus.h:82
KIRQL NTAPI KeAcquireInterruptSpinLock(IN PKINTERRUPT Interrupt)
Definition: spinlock.c:148
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
_Must_inspect_result_ typedef _In_ PHYSICAL_ADDRESS _In_ LARGE_INTEGER ByteCount
Definition: iotypes.h:1060
Status
Definition: gdiplustypes.h:24
#define STATUS_DEVICE_BUSY
Definition: udferr_usr.h:129
#define STATUS_IO_TIMEOUT
Definition: udferr_usr.h:163
#define IO_NO_INCREMENT
Definition: iotypes.h:565
#define STATUS_ABANDONED
Definition: ntstatus.h:75
#define CTRL_WRITE_MOUSE
Definition: i8042prt.h:228

Referenced by i8042KbdStartIo().

◆ i8042SynchReadPort()

NTSTATUS NTAPI i8042SynchReadPort ( IN PVOID  Context,
OUT PUCHAR  Value,
IN BOOLEAN  WaitForAck 
)

Definition at line 125 of file readwrite.c.

129 {
130  PPORT_DEVICE_EXTENSION DeviceExtension;
131 
132  UNREFERENCED_PARAMETER(WaitForAck);
133 
134  DeviceExtension = (PPORT_DEVICE_EXTENSION)Context;
135 
136  return i8042ReadDataWait(DeviceExtension, Value);
137 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
struct _PORT_DEVICE_EXTENSION * PPORT_DEVICE_EXTENSION
NTSTATUS i8042ReadDataWait(IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Data)
Definition: readwrite.c:95

Referenced by i8042SendHookWorkItem().

◆ i8042SynchWritePort()

NTSTATUS NTAPI i8042SynchWritePort ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN UCHAR  Port,
IN UCHAR  Value,
IN BOOLEAN  WaitForAck 
)

Definition at line 144 of file readwrite.c.

149 {
151  UCHAR Ack;
152  ULONG ResendIterations;
153 
154  ResendIterations = DeviceExtension->Settings.ResendIterations + 1;
155 
156  do
157  {
158  if (Port)
159  if (!i8042Write(DeviceExtension, DeviceExtension->DataPort, Port))
160  {
161  WARN_(I8042PRT, "Failed to write Port\n");
162  return STATUS_IO_TIMEOUT;
163  }
164 
165  if (!i8042Write(DeviceExtension, DeviceExtension->DataPort, Value))
166  {
167  WARN_(I8042PRT, "Failed to write Value\n");
168  return STATUS_IO_TIMEOUT;
169  }
170 
171  if (WaitForAck)
172  {
173  Status = i8042ReadDataWait(DeviceExtension, &Ack);
174  if (!NT_SUCCESS(Status))
175  {
176  WARN_(I8042PRT, "Failed to read Ack\n");
177  return Status;
178  }
179  if (Ack == KBD_ACK)
180  return STATUS_SUCCESS;
181  else if (Ack == KBD_RESEND)
182  INFO_(I8042PRT, "i8042 asks for a data resend\n");
183  }
184  else
185  {
186  return STATUS_SUCCESS;
187  }
188  TRACE_(I8042PRT, "Reiterating\n");
189  ResendIterations--;
190  } while (ResendIterations);
191 
192  return STATUS_IO_TIMEOUT;
193 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
CPPORT Port[4]
Definition: headless.c:34
#define INFO_(ch,...)
Definition: debug.h:159
LONG NTSTATUS
Definition: precomp.h:26
BOOLEAN i8042Write(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN PUCHAR addr, IN UCHAR data)
Definition: readwrite.c:199
#define TRACE_(x)
Definition: compat.h:66
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
#define KBD_ACK
Definition: i8042prt.h:242
unsigned char UCHAR
Definition: xmlstorage.h:181
Status
Definition: gdiplustypes.h:24
NTSTATUS i8042ReadDataWait(IN PPORT_DEVICE_EXTENSION DeviceExtension, OUT PUCHAR Data)
Definition: readwrite.c:95
#define KBD_RESEND
Definition: i8042prt.h:244
#define STATUS_IO_TIMEOUT
Definition: udferr_usr.h:163
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define WARN_(ch,...)
Definition: debug.h:157

Referenced by i8042DetectKeyboard(), and i8042SynchWritePortKbd().

◆ i8042SynchWritePortKbd()

NTSTATUS NTAPI i8042SynchWritePortKbd ( IN PVOID  Context,
IN UCHAR  Value,
IN BOOLEAN  WaitForAck 
)

Definition at line 87 of file keyboard.c.

91 {
92  return i8042SynchWritePort(
94  0,
95  Value,
96  WaitForAck);
97 }
_In_opt_ ULONG _Out_ PULONG Value
Definition: rtlfuncs.h:2327
NTSTATUS NTAPI i8042SynchWritePort(IN PPORT_DEVICE_EXTENSION DeviceExtension, IN UCHAR Port, IN UCHAR Value, IN BOOLEAN WaitForAck)
Definition: readwrite.c:144

Referenced by i8042SendHookWorkItem().

◆ i8042Write()

BOOLEAN i8042Write ( IN PPORT_DEVICE_EXTENSION  DeviceExtension,
IN PUCHAR  addr,
IN UCHAR  data 
)

Definition at line 199 of file readwrite.c.

203 {
204  ULONG Counter;
205 
206  ASSERT(addr);
207  ASSERT(DeviceExtension->ControlPort != NULL);
208 
209  Counter = DeviceExtension->Settings.PollingIterations;
210 
211  while ((KBD_IBF & READ_PORT_UCHAR(DeviceExtension->ControlPort)) &&
212  (Counter--))
213  {
215  }
216 
217  if (Counter)
218  {
220  INFO_(I8042PRT, "Sent 0x%x to port %p\n", data, addr);
221  return TRUE;
222  }
223  return FALSE;
224 }
#define TRUE
Definition: types.h:120
#define INFO_(ch,...)
Definition: debug.h:159
UCHAR NTAPI READ_PORT_UCHAR(PUCHAR Address)
Definition: mach.c:535
#define KBD_IBF
Definition: i8042prt.h:251
smooth NULL
Definition: ftsmooth.c:416
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
GLenum const GLvoid * addr
Definition: glext.h:9621
static LARGE_INTEGER Counter
Definition: clock.c:43
unsigned int ULONG
Definition: retypes.h:1
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:539
VOID NTAPI KeStallExecutionProcessor(IN ULONG MicroSeconds)
Definition: ntoskrnl.c:99

Referenced by i8042BasicDetect(), i8042ChangeMode(), i8042ConnectKeyboardInterrupt(), i8042DetectMouse(), i8042IsrWritePort(), i8042MouInitialize(), i8042PacketWrite(), and i8042SynchWritePort().

◆ ReadRegistryEntries()

NTSTATUS ReadRegistryEntries ( IN PUNICODE_STRING  RegistryPath,
OUT PI8042_SETTINGS  Settings 
)

Definition at line 21 of file registry.c.

24 {
27 
28  ULONG DefaultKeyboardDataQueueSize = 0x64;
29  PCWSTR DefaultKeyboardDeviceBaseName = L"KeyboardPort";
30  ULONG DefaultMouseDataQueueSize = 0x64;
31  ULONG DefaultMouseResolution = 3;
32  ULONG DefaultMouseSynchIn100ns = 20000000;
33  ULONG DefaultNumberOfButtons = 2;
34  PCWSTR DefaultPointerDeviceBaseName = L"PointerPort";
35  ULONG DefaultPollStatusIterations = 1;
36  ULONG DefaultOverrideKeyboardType = 4;
37  ULONG DefaultOverrideKeyboardSubtype = 0;
38  ULONG DefaultPollingIterations = 12000;
39  ULONG DefaultPollingIterationsMaximum = 12000;
40  ULONG DefaultResendIterations = 0x3;
41  ULONG DefaultSampleRate = 60;
42  ULONG DefaultCrashOnCtrlScroll;
43 
44  /* Default value for CrashOnCtrlScroll depends if we're
45  * running a debug build or a normal build.
46  */
47 #if DBG
48  DefaultCrashOnCtrlScroll = 1;
49 #else
50  DefaultCrashOnCtrlScroll = 0;
51 #endif
52 
54 
56  Parameters[0].Name = L"Parameters";
57 
59  Parameters[1].Name = L"KeyboardDataQueueSize";
60  Parameters[1].EntryContext = &Settings->KeyboardDataQueueSize;
61  Parameters[1].DefaultType = REG_DWORD;
62  Parameters[1].DefaultData = &DefaultKeyboardDataQueueSize;
63  Parameters[1].DefaultLength = sizeof(ULONG);
64 
66  Parameters[2].Name = L"KeyboardDeviceBaseName";
67  Parameters[2].EntryContext = &Settings->KeyboardDeviceBaseName;
68  Parameters[2].DefaultType = REG_SZ;
69  Parameters[2].DefaultData = (PVOID)DefaultKeyboardDeviceBaseName;
70  Parameters[2].DefaultLength = 0;
71 
73  Parameters[3].Name = L"MouseDataQueueSize";
74  Parameters[3].EntryContext = &Settings->MouseDataQueueSize;
75  Parameters[3].DefaultType = REG_DWORD;
76  Parameters[3].DefaultData = &DefaultMouseDataQueueSize;
77  Parameters[3].DefaultLength = sizeof(ULONG);
78 
80  Parameters[4].Name = L"MouseResolution";
81  Parameters[4].EntryContext = &Settings->MouseResolution;
82  Parameters[4].DefaultType = REG_DWORD;
83  Parameters[4].DefaultData = &DefaultMouseResolution;
84  Parameters[4].DefaultLength = sizeof(ULONG);
85 
87  Parameters[5].Name = L"MouseSynchIn100ns";
88  Parameters[5].EntryContext = &Settings->MouseSynchIn100ns;
89  Parameters[5].DefaultType = REG_DWORD;
90  Parameters[5].DefaultData = &DefaultMouseSynchIn100ns;
91  Parameters[5].DefaultLength = sizeof(ULONG);
92 
94  Parameters[6].Name = L"NumberOfButtons";
95  Parameters[6].EntryContext = &Settings->NumberOfButtons;
96  Parameters[6].DefaultType = REG_DWORD;
97  Parameters[6].DefaultData = &DefaultNumberOfButtons;
98  Parameters[6].DefaultLength = sizeof(ULONG);
99 
101  Parameters[7].Name = L"PointerDeviceBaseName";
102  Parameters[7].EntryContext = &Settings->PointerDeviceBaseName;
103  Parameters[7].DefaultType = REG_SZ;
104  Parameters[7].DefaultData = (PVOID)DefaultPointerDeviceBaseName;
105  Parameters[7].DefaultLength = 0;
106 
108  Parameters[8].Name = L"PollStatusIterations";
109  Parameters[8].EntryContext = &Settings->PollStatusIterations;
110  Parameters[8].DefaultType = REG_DWORD;
111  Parameters[8].DefaultData = &DefaultPollStatusIterations;
112  Parameters[8].DefaultLength = sizeof(ULONG);
113 
115  Parameters[9].Name = L"OverrideKeyboardType";
116  Parameters[9].EntryContext = &Settings->OverrideKeyboardType;
117  Parameters[9].DefaultType = REG_DWORD;
118  Parameters[9].DefaultData = &DefaultOverrideKeyboardType;
119  Parameters[9].DefaultLength = sizeof(ULONG);
120 
122  Parameters[10].Name = L"OverrideKeyboardSubtype";
123  Parameters[10].EntryContext = &Settings->OverrideKeyboardSubtype;
124  Parameters[10].DefaultType = REG_DWORD;
125  Parameters[10].DefaultData = &DefaultOverrideKeyboardSubtype;
126  Parameters[10].DefaultLength = sizeof(ULONG);
127 
129  Parameters[11].Name = L"PollingIterations";
130  Parameters[11].EntryContext = &Settings->PollingIterations;
131  Parameters[11].DefaultType = REG_DWORD;
132  Parameters[11].DefaultData = &DefaultPollingIterations;
133  Parameters[11].DefaultLength = sizeof(ULONG);
134 
136  Parameters[12].Name = L"PollingIterationsMaximum";
137  Parameters[12].EntryContext = &Settings->PollingIterationsMaximum;
138  Parameters[12].DefaultType = REG_DWORD;
139  Parameters[12].DefaultData = &DefaultPollingIterationsMaximum;
140  Parameters[12].DefaultLength = sizeof(ULONG);
141 
143  Parameters[13].Name = L"ResendIterations";
144  Parameters[13].EntryContext = &Settings->ResendIterations;
145  Parameters[13].DefaultType = REG_DWORD;
146  Parameters[13].DefaultData = &DefaultResendIterations;
147  Parameters[13].DefaultLength = sizeof(ULONG);
148 
150  Parameters[14].Name = L"SampleRate";
151  Parameters[14].EntryContext = &Settings->SampleRate;
152  Parameters[14].DefaultType = REG_DWORD;
153  Parameters[14].DefaultData = &DefaultSampleRate;
154  Parameters[14].DefaultLength = sizeof(ULONG);
155 
157  Parameters[15].Name = L"CrashOnCtrlScroll";
158  Parameters[15].EntryContext = &Settings->CrashOnCtrlScroll;
159  Parameters[15].DefaultType = REG_DWORD;
160  Parameters[15].DefaultData = &DefaultCrashOnCtrlScroll;
161  Parameters[15].DefaultLength = sizeof(ULONG);
162 
166  Parameters,
167  NULL,
168  NULL);
169 
170  if (NT_SUCCESS(Status))
171  {
172  /* Check values */
173  if (Settings->KeyboardDataQueueSize < 1)
174  Settings->KeyboardDataQueueSize = DefaultKeyboardDataQueueSize;
175  if (Settings->MouseDataQueueSize < 1)
176  Settings->MouseDataQueueSize = DefaultMouseDataQueueSize;
177  if (Settings->NumberOfButtons < 1)
178  Settings->NumberOfButtons = DefaultNumberOfButtons;
179  if (Settings->PollingIterations < 0x400)
180  Settings->PollingIterations = DefaultPollingIterations;
181  if (Settings->PollingIterationsMaximum < 0x400)
182  Settings->PollingIterationsMaximum = DefaultPollingIterationsMaximum;
183  if (Settings->ResendIterations < 1)
184  Settings->ResendIterations = DefaultResendIterations;
185  }
187  {
188  /* Registry path doesn't exist. Set defaults */
189  Settings->KeyboardDataQueueSize = DefaultKeyboardDataQueueSize;
190  Settings->MouseDataQueueSize = DefaultMouseDataQueueSize;
191  Settings->MouseResolution = DefaultMouseResolution;
192  Settings->MouseSynchIn100ns = DefaultMouseSynchIn100ns;
193  Settings->NumberOfButtons = DefaultNumberOfButtons;
194  Settings->PollStatusIterations = DefaultPollStatusIterations;
195  Settings->OverrideKeyboardType = DefaultOverrideKeyboardType;
196  Settings->OverrideKeyboardSubtype = DefaultOverrideKeyboardSubtype;
197  Settings->PollingIterations = DefaultPollingIterations;
198  Settings->PollingIterationsMaximum = DefaultPollingIterationsMaximum;
199  Settings->ResendIterations = DefaultResendIterations;
200  Settings->SampleRate = DefaultSampleRate;
201  Settings->CrashOnCtrlScroll = DefaultCrashOnCtrlScroll;
202  if (!RtlCreateUnicodeString(&Settings->KeyboardDeviceBaseName, DefaultKeyboardDeviceBaseName)
203  || !RtlCreateUnicodeString(&Settings->PointerDeviceBaseName, DefaultPointerDeviceBaseName))
204  {
205  WARN_(I8042PRT, "RtlCreateUnicodeString() failed\n");
207  }
208  else
209  {
211  }
212  }
213 
214  if (NT_SUCCESS(Status))
215  {
216  INFO_(I8042PRT, "KeyboardDataQueueSize : 0x%lx\n", Settings->KeyboardDataQueueSize);
217  INFO_(I8042PRT, "KeyboardDeviceBaseName : %wZ\n", &Settings->KeyboardDeviceBaseName);
218  INFO_(I8042PRT, "MouseDataQueueSize : 0x%lx\n", Settings->MouseDataQueueSize);
219  INFO_(I8042PRT, "MouseResolution : 0x%lx\n", Settings->MouseResolution);
220  INFO_(I8042PRT, "MouseSynchIn100ns : %lu\n", Settings->MouseSynchIn100ns);
221  INFO_(I8042PRT, "NumberOfButtons : 0x%lx\n", Settings->NumberOfButtons);
222  INFO_(I8042PRT, "PointerDeviceBaseName : %wZ\n", &Settings->PointerDeviceBaseName);
223  INFO_(I8042PRT, "PollStatusIterations : 0x%lx\n", Settings->PollStatusIterations);
224  INFO_(I8042PRT, "OverrideKeyboardType : 0x%lx\n", Settings->OverrideKeyboardType);
225  INFO_(I8042PRT, "OverrideKeyboardSubtype : 0x%lx\n", Settings->OverrideKeyboardSubtype);
226  INFO_(I8042PRT, "PollingIterations : 0x%lx\n", Settings->PollingIterations);
227  INFO_(I8042PRT, "PollingIterationsMaximum : %lu\n", Settings->PollingIterationsMaximum);
228  INFO_(I8042PRT, "ResendIterations : 0x%lx\n", Settings->ResendIterations);
229  INFO_(I8042PRT, "SampleRate : %lu\n", Settings->SampleRate);
230  }
231 
232  return Status;
233 }
const uint16_t * PCWSTR
Definition: typedefs.h:55
#define INFO_(ch,...)
Definition: debug.h:159
LONG NTSTATUS
Definition: precomp.h:26
static PVOID
Definition: registry.c:44
smooth NULL
Definition: ftsmooth.c:416
#define RTL_QUERY_REGISTRY_SUBKEY
Definition: nt_native.h:125
#define RTL_REGISTRY_OPTIONAL
Definition: nt_native.h:169
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
SETTINGS Settings
Definition: charmap.c:26
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:871
static const WCHAR L[]
Definition: oid.c:1250
#define RTL_REGISTRY_ABSOLUTE
Definition: nt_native.h:161
Status
Definition: gdiplustypes.h:24
NTSTATUS NTAPI RtlQueryRegistryValues(IN ULONG RelativeTo, IN PCWSTR Path, IN PRTL_QUERY_REGISTRY_TABLE QueryTable, IN PVOID Context, IN PVOID Environment OPTIONAL)
Definition: registry.c:1010
#define STATUS_OBJECT_NAME_NOT_FOUND
Definition: udferr_usr.h:149
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
unsigned int ULONG
Definition: retypes.h:1
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
_In_ PUNICODE_STRING RegistryPath
Definition: wmip.h:27
return STATUS_SUCCESS
Definition: btrfs.c:2725
#define REG_DWORD
Definition: sdbapi.c:539
#define WARN_(ch,...)
Definition: debug.h:157
#define RTL_QUERY_REGISTRY_DIRECT
Definition: nt_native.h:144
#define REG_SZ
Definition: layer.c:22

Referenced by DriverEntry().

Variable Documentation

◆ ForwardIrpAndForget

◆ ForwardIrpAndWait

◆ i8042AddDevice

DRIVER_ADD_DEVICE i8042AddDevice

Definition at line 324 of file i8042prt.h.

Referenced by DriverEntry().

◆ i8042HwFlags

ULONG i8042HwFlags

Definition at line 22 of file hwhacks.c.

Referenced by i8042ParseSMBiosTables(), and StartProcedure().

◆ i8042KbdDeviceControl

DRIVER_DISPATCH i8042KbdDeviceControl

Definition at line 316 of file i8042prt.h.

Referenced by i8042DeviceControl().

◆ i8042KbdInternalDeviceControl

DRIVER_DISPATCH i8042KbdInternalDeviceControl

Definition at line 318 of file i8042prt.h.

Referenced by i8042InternalDeviceControl().

◆ i8042KbdInterruptService

KSERVICE_ROUTINE i8042KbdInterruptService

Definition at line 320 of file i8042prt.h.

Referenced by i8042ConnectKeyboardInterrupt().

◆ i8042KbdStartIo

DRIVER_STARTIO i8042KbdStartIo

Definition at line 314 of file i8042prt.h.

Referenced by i8042StartIo().

◆ i8042MouInternalDeviceControl

DRIVER_DISPATCH i8042MouInternalDeviceControl

Definition at line 367 of file i8042prt.h.

Referenced by i8042InternalDeviceControl().

◆ i8042MouInterruptService

KSERVICE_ROUTINE i8042MouInterruptService

Definition at line 369 of file i8042prt.h.

Referenced by i8042ConnectMouseInterrupt().

◆ i8042SendHookWorkItem

IO_WORKITEM_ROUTINE i8042SendHookWorkItem

Definition at line 295 of file i8042prt.h.

Referenced by i8042KbdInternalDeviceControl(), and i8042MouInternalDeviceControl().