ReactOS  0.4.14-dev-49-gfb4591c
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 4621 of file create.c.

4623  {
4624  NTSTATUS Status;
4627  bool top_level, locked = false;
4628 
4630 
4631  TRACE("create (flags = %x)\n", Irp->Flags);
4632 
4633  top_level = is_top_level(Irp);
4634 
4635  /* return success if just called for FS device object */
4636  if (DeviceObject == master_devobj) {
4637  TRACE("create called for FS device object\n");
4638 
4639  Irp->IoStatus.Information = FILE_OPENED;
4641 
4642  goto exit;
4643  } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
4645  goto exit;
4646  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
4648  goto exit;
4649  }
4650 
4651  if (!(Vcb->Vpb->Flags & VPB_MOUNTED)) {
4653  goto exit;
4654  }
4655 
4656  if (Vcb->removing) {
4658  goto exit;
4659  }
4660 
4661  Status = verify_vcb(Vcb, Irp);
4662  if (!NT_SUCCESS(Status)) {
4663  ERR("verify_vcb returned %08x\n", Status);
4664  goto exit;
4665  }
4666 
4667  ExAcquireResourceSharedLite(&Vcb->load_lock, true);
4668  locked = true;
4669 
4671 
4672  if (IrpSp->Flags != 0) {
4674 
4675  TRACE("flags:\n");
4676 
4677  if (flags & SL_CASE_SENSITIVE) {
4678  TRACE("SL_CASE_SENSITIVE\n");
4680  }
4681 
4682  if (flags & SL_FORCE_ACCESS_CHECK) {
4683  TRACE("SL_FORCE_ACCESS_CHECK\n");
4685  }
4686 
4687  if (flags & SL_OPEN_PAGING_FILE) {
4688  TRACE("SL_OPEN_PAGING_FILE\n");
4690  }
4691 
4693  TRACE("SL_OPEN_TARGET_DIRECTORY\n");
4695  }
4696 
4697  if (flags & SL_STOP_ON_SYMLINK) {
4698  TRACE("SL_STOP_ON_SYMLINK\n");
4700  }
4701 
4702  if (flags)
4703  WARN("unknown flags: %x\n", flags);
4704  } else {
4705  TRACE("flags: (none)\n");
4706  }
4707 
4708  if (!IrpSp->FileObject) {
4709  ERR("FileObject was NULL\n");
4711  goto exit;
4712  }
4713 
4714  if (IrpSp->FileObject->RelatedFileObject) {
4715  fcb* relatedfcb = IrpSp->FileObject->RelatedFileObject->FsContext;
4716 
4717  if (relatedfcb && relatedfcb->Vcb != Vcb) {
4718  WARN("RelatedFileObject was for different device\n");
4720  goto exit;
4721  }
4722  }
4723 
4724  // opening volume
4725  if (IrpSp->FileObject->FileName.Length == 0 && !IrpSp->FileObject->RelatedFileObject) {
4726  ULONG RequestedDisposition = ((IrpSp->Parameters.Create.Options >> 24) & 0xff);
4727  ULONG RequestedOptions = IrpSp->Parameters.Create.Options & FILE_VALID_OPTION_FLAGS;
4728 #ifdef DEBUG_FCB_REFCOUNTS
4729  LONG rc;
4730 #endif
4731  ccb* ccb;
4732 
4733  TRACE("open operation for volume\n");
4734 
4735  if (RequestedDisposition != FILE_OPEN && RequestedDisposition != FILE_OPEN_IF) {
4737  goto exit;
4738  }
4739 
4740  if (RequestedOptions & FILE_DIRECTORY_FILE) {
4742  goto exit;
4743  }
4744 
4746  if (!ccb) {
4747  ERR("out of memory\n");
4749  goto exit;
4750  }
4751 
4752  RtlZeroMemory(ccb, sizeof(*ccb));
4753 
4755  ccb->NodeSize = sizeof(*ccb);
4756  ccb->disposition = RequestedDisposition;
4757  ccb->options = RequestedOptions;
4758  ccb->access = IrpSp->Parameters.Create.SecurityContext->AccessState->PreviouslyGrantedAccess;
4760  IrpSp->Flags & SL_FORCE_ACCESS_CHECK ? UserMode : Irp->RequestorMode);
4761  ccb->reserving = false;
4762  ccb->lxss = called_from_lxss();
4763 
4764 #ifdef DEBUG_FCB_REFCOUNTS
4765  rc = InterlockedIncrement(&Vcb->volume_fcb->refcount);
4766  WARN("fcb %p: refcount now %i (volume)\n", Vcb->volume_fcb, rc);
4767 #else
4768  InterlockedIncrement(&Vcb->volume_fcb->refcount);
4769 #endif
4770  IrpSp->FileObject->FsContext = Vcb->volume_fcb;
4771  IrpSp->FileObject->FsContext2 = ccb;
4772 
4773  IrpSp->FileObject->SectionObjectPointer = &Vcb->volume_fcb->nonpaged->segment_object;
4774 
4775  if (!IrpSp->FileObject->Vpb)
4776  IrpSp->FileObject->Vpb = DeviceObject->Vpb;
4777 
4778  InterlockedIncrement(&Vcb->open_files);
4779 
4780  Irp->IoStatus.Information = FILE_OPENED;
4782  } else {
4784  bool skip_lock;
4785 
4787 
4788  TRACE("file name: %.*S\n", IrpSp->FileObject->FileName.Length / sizeof(WCHAR), IrpSp->FileObject->FileName.Buffer);
4789 
4790  if (IrpSp->FileObject->RelatedFileObject)
4791  TRACE("related file = %S\n", file_desc(IrpSp->FileObject->RelatedFileObject));
4792 
4793  // Don't lock again if we're being called from within CcCopyRead etc.
4794  skip_lock = ExIsResourceAcquiredExclusiveLite(&Vcb->tree_lock);
4795 
4796  if (!skip_lock)
4797  ExAcquireResourceSharedLite(&Vcb->tree_lock, true);
4798 
4799  ExAcquireResourceSharedLite(&Vcb->fileref_lock, true);
4800 
4802 
4803  if (!NT_SUCCESS(Status))
4805  else
4807 
4808  ExReleaseResourceLite(&Vcb->fileref_lock);
4809 
4810  if (!skip_lock)
4811  ExReleaseResourceLite(&Vcb->tree_lock);
4812  }
4813 
4814 exit:
4815  Irp->IoStatus.Status = Status;
4817 
4818  TRACE("create returning %08x\n", Status);
4819 
4820  if (locked)
4821  ExReleaseResourceLite(&Vcb->load_lock);
4822 
4823  if (top_level)
4825 
4827 
4828  return Status;
4829 }
void do_rollback(device_extension *Vcb, LIST_ENTRY *rollback)
Definition: treefuncs.c:1049
void clear_rollback(LIST_ENTRY *rollback)
Definition: treefuncs.c:1028
#define SL_CASE_SENSITIVE
Definition: iotypes.h:1777
#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:369
USHORT Flags
Definition: iotypes.h:169
#define FsRtlExitFileSystem
Iosb Status
Definition: create.c:4311
#define SL_OPEN_PAGING_FILE
Definition: iotypes.h:1774
_In_ PIRP Irp
Definition: csq.h:116
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define FILE_DIRECTORY_FILE
Definition: constants.h:491
#define WARN(fmt,...)
Definition: debug.h:111
LONG NTSTATUS
Definition: precomp.h:26
#define FILE_OPENED
Definition: nt_native.h:769
#define SL_STOP_ON_SYMLINK
Definition: iotypes.h:1776
#define VCB_TYPE_FS
Definition: btrfs_drv.h:657
ACCESS_MASK access
Definition: btrfs_drv.h:377
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:272
#define SL_FORCE_ACCESS_CHECK
Definition: iotypes.h:1773
bool manage_volume_privilege
Definition: btrfs_drv.h:374
#define FILE_VALID_OPTION_FLAGS
Definition: nt_native.h:759
#define ALLOC_TAG
Definition: btrfs_drv.h:91
_In_ PIO_STACK_LOCATION _Inout_ PFILE_OBJECT _Inout_ PVCB Vcb
Definition: create.c:4157
#define STATUS_NOT_A_DIRECTORY
Definition: udferr_usr.h:169
#define IO_DISK_INCREMENT
Definition: iotypes.h:568
long LONG
Definition: pedump.c:60
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:67
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
static bool has_manage_volume_privilege(ACCESS_STATE *access_state, KPROCESSOR_MODE processor_mode)
Definition: create.c:4610
#define BTRFS_NODE_TYPE_CCB
Definition: btrfs_drv.h:88
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
NTSTATUS vol_create(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:35
#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:366
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:4260
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Definition: typedefs.h:117
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:2813
#define SL_OPEN_TARGET_DIRECTORY
Definition: iotypes.h:1775
#define InterlockedIncrement
Definition: armddk.h:53
ULONG disposition
Definition: btrfs_drv.h:368
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: btrfs_drv.h:1301
UINT32 uint32_t
Definition: types.h:75
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
#define called_from_lxss()
Definition: create.c:2885
unsigned int ULONG
Definition: retypes.h:1
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
bool reserving
Definition: btrfs_drv.h:376
bool lxss
Definition: btrfs_drv.h:386
void exit(int exitcode)
Definition: _exit.c:33
struct _ccb ccb
static NTSTATUS verify_vcb(device_extension *Vcb, PIRP Irp)
Definition: create.c:4548
struct _NAMED_PIPE_CREATE_PARAMETERS * Parameters
Definition: iotypes.h:2772
return STATUS_SUCCESS
Definition: btrfs.c:2966
CSHORT NodeSize
Definition: btrfs_drv.h:367
#define VPB_MOUNTED
Definition: iotypes.h:1764
HRESULT Create([out]ITransactionReceiver **ppReceiver)
struct _device_extension * Vcb
Definition: btrfs_drv.h:276
_Ret_z_ WCHAR * file_desc(_In_ PFILE_OBJECT FileObject)
Definition: btrfs.c:1529
#define STATUS_DEVICE_NOT_READY
Definition: shellext.h:65

◆ _Dispatch_type_() [2/4]

_Dispatch_type_ ( IRP_MJ_CLEANUP  )

Definition at line 2385 of file btrfs.c.

2387  {
2388  NTSTATUS Status;
2392  fcb* fcb = FileObject->FsContext;
2393  bool top_level;
2394 
2396 
2397  TRACE("cleanup\n");
2398 
2399  top_level = is_top_level(Irp);
2400 
2401  if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
2403  goto exit;
2404  } else if (DeviceObject == master_devobj) {
2405  TRACE("closing file system\n");
2407  goto exit;
2408  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
2410  goto exit;
2411  }
2412 
2413  if (FileObject->Flags & FO_CLEANUP_COMPLETE) {
2414  TRACE("FileObject %p already cleaned up\n", FileObject);
2416  goto exit;
2417  }
2418 
2419  if (!fcb) {
2420  ERR("fcb was NULL\n");
2422  goto exit;
2423  }
2424 
2425  // We have to use the pointer to Vcb stored in the fcb, as we can receive cleanup
2426  // messages belonging to other devices.
2427 
2428  if (FileObject && FileObject->FsContext) {
2429  LONG oc;
2430  ccb* ccb;
2431  file_ref* fileref;
2432  bool locked = true;
2433 
2434  ccb = FileObject->FsContext2;
2435  fileref = ccb ? ccb->fileref : NULL;
2436 
2437  TRACE("cleanup called for FileObject %p\n", FileObject);
2438  TRACE("fileref %p (%S), refcount = %u, open_count = %u\n", fileref, file_desc(FileObject), fileref ? fileref->refcount : 0, fileref ? fileref->open_count : 0);
2439 
2440  ExAcquireResourceSharedLite(&fcb->Vcb->tree_lock, true);
2441 
2442  ExAcquireResourceExclusiveLite(fcb->Header.Resource, true);
2443 
2445 
2447 
2448  if (ccb)
2449  FsRtlNotifyCleanup(fcb->Vcb->NotifySync, &fcb->Vcb->DirNotifyList, ccb);
2450 
2451  if (fileref) {
2452  oc = InterlockedDecrement(&fileref->open_count);
2453 #ifdef DEBUG_FCB_REFCOUNTS
2454  ERR("fileref %p: open_count now %i\n", fileref, oc);
2455 #endif
2456  }
2457 
2458  if (ccb && ccb->options & FILE_DELETE_ON_CLOSE && fileref)
2459  fileref->delete_on_close = true;
2460 
2461  if (fileref && fileref->delete_on_close && fcb->type == BTRFS_TYPE_DIRECTORY && fcb->inode_item.st_size > 0 && fcb != fcb->Vcb->dummy_fcb)
2462  fileref->delete_on_close = false;
2463 
2464  if (fcb->Vcb->locked && fcb->Vcb->locked_fileobj == FileObject) {
2465  TRACE("unlocking volume\n");
2468  }
2469 
2470  if (ccb && ccb->reserving) {
2471  fcb->subvol->reserved = NULL;
2472  ccb->reserving = false;
2473  // FIXME - flush all of subvol's fcbs
2474  }
2475 
2476  if (fileref && (oc == 0 || (fileref->delete_on_close && fileref->posix_delete))) {
2477  if (!fcb->Vcb->removing) {
2478  if (oc == 0 && fileref->fcb->inode_item.st_nlink == 0 && fileref != fcb->Vcb->root_fileref && fcb != fcb->Vcb->volume_fcb) { // last handle closed on POSIX-deleted file
2480 
2482 
2484  if (!NT_SUCCESS(Status)) {
2485  ERR("delete_fileref_fcb returned %08x\n", Status);
2487  ExReleaseResourceLite(fileref->fcb->Header.Resource);
2488  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2489  goto exit;
2490  }
2491 
2493 
2494  mark_fcb_dirty(fileref->fcb);
2495  } else if (fileref->delete_on_close && fileref != fcb->Vcb->root_fileref && fcb != fcb->Vcb->volume_fcb) {
2497 
2499 
2500  if (!fileref->fcb->ads || fileref->dc) {
2501  if (fileref->fcb->ads) {
2503  FILE_ACTION_REMOVED, &fileref->dc->name);
2504  } else
2506  }
2507 
2508  ExReleaseResourceLite(fcb->Header.Resource);
2509  locked = false;
2510 
2511  // fileref_lock needs to be acquired before fcb->Header.Resource
2512  ExAcquireResourceExclusiveLite(&fcb->Vcb->fileref_lock, true);
2513 
2514  Status = delete_fileref(fileref, FileObject, oc > 0 && fileref->posix_delete, Irp, &rollback);
2515  if (!NT_SUCCESS(Status)) {
2516  ERR("delete_fileref returned %08x\n", Status);
2518  ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
2519  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2520  goto exit;
2521  }
2522 
2523  ExReleaseResourceLite(&fcb->Vcb->fileref_lock);
2524 
2526  } else if (FileObject->Flags & FO_CACHE_SUPPORTED && FileObject->SectionObjectPointer->DataSectionObject) {
2528  CcFlushCache(FileObject->SectionObjectPointer, NULL, 0, &iosb);
2529 
2530  if (!NT_SUCCESS(iosb.Status)) {
2531  ERR("CcFlushCache returned %08x\n", iosb.Status);
2532  }
2533 
2534  if (!ExIsResourceAcquiredSharedLite(fcb->Header.PagingIoResource)) {
2535  ExAcquireResourceExclusiveLite(fcb->Header.PagingIoResource, true);
2536  ExReleaseResourceLite(fcb->Header.PagingIoResource);
2537  }
2538 
2539  CcPurgeCacheSection(FileObject->SectionObjectPointer, NULL, 0, false);
2540 
2541  TRACE("flushed cache on close (FileObject = %p, fcb = %p, AllocationSize = %I64x, FileSize = %I64x, ValidDataLength = %I64x)\n",
2542  FileObject, fcb, fcb->Header.AllocationSize.QuadPart, fcb->Header.FileSize.QuadPart, fcb->Header.ValidDataLength.QuadPart);
2543  }
2544  }
2545 
2546  if (fcb->Vcb && fcb != fcb->Vcb->volume_fcb)
2548  }
2549 
2550  if (locked)
2551  ExReleaseResourceLite(fcb->Header.Resource);
2552 
2553  ExReleaseResourceLite(&fcb->Vcb->tree_lock);
2554 
2555  FileObject->Flags |= FO_CLEANUP_COMPLETE;
2556  }
2557 
2559 
2560 exit:
2561  TRACE("returning %08x\n", Status);
2562 
2563  Irp->IoStatus.Status = Status;
2564  Irp->IoStatus.Information = 0;
2565 
2567 
2568  if (top_level)
2570 
2572 
2573  return Status;
2574 }
struct _file_ref * parent
Definition: btrfs_drv.h:346
PEPROCESS NTAPI IoGetRequestorProcess(IN PIRP Irp)
Definition: irp.c:1782
void do_rollback(device_extension *Vcb, LIST_ENTRY *rollback)
Definition: treefuncs.c:1049
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:1028
#define FsRtlEnterFileSystem
ULONG options
Definition: btrfs_drv.h:369
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:4175
#define VCB_TYPE_FS
Definition: btrfs_drv.h:657
#define FILE_NOTIFY_CHANGE_FILE_NAME
LONG open_count
Definition: btrfs_drv.h:345
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:272
#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:1543
VOID NTAPI IoRemoveShareAccess(IN PFILE_OBJECT FileObject, IN PSHARE_ACCESS ShareAccess)
Definition: file.c:3477
bool posix_delete
Definition: btrfs_drv.h:339
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
uint32_t st_nlink
Definition: btrfs.h:274
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:67
#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
void mark_fcb_dirty(_In_ fcb *fcb)
Definition: btrfs.c:1664
#define IoCompleteRequest
Definition: irp.c:1240
uint8_t type
Definition: btrfs_drv.h:280
_Inout_ PFILE_OBJECT FileObject
Definition: cdprocs.h:593
LONG refcount
Definition: btrfs_drv.h:344
FILE_LOCK lock
Definition: btrfs_drv.h:283
InsertTailList & Vcb
Definition: btrfs.c:2930
FSRTL_ADVANCED_FCB_HEADER Header
Definition: btrfs_drv.h:272
#define FILE_DELETE_ON_CLOSE
Definition: constants.h:494
uint64_t st_size
Definition: btrfs.h:271
#define TRACE(s)
Definition: solgame.cpp:4
NTSTATUS NTAPI FsRtlNotifyVolumeEvent(IN PFILE_OBJECT FileObject, IN ULONG EventCode)
Definition: pnp.c:38
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
VOID FASTCALL ExReleaseResourceLite(IN PERESOURCE Resource)
Definition: resource.c:1817
* PFILE_OBJECT
Definition: iotypes.h:1955
#define FO_CACHE_SUPPORTED
Definition: iotypes.h:1738
dir_child * dc
Definition: btrfs_drv.h:348
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:327
fcb * fcb
Definition: btrfs_drv.h:335
Definition: typedefs.h:117
NTSTATUS NTAPI FsRtlFastUnlockAll(IN PFILE_LOCK FileLock, IN PFILE_OBJECT FileObject, IN PEPROCESS Process, IN PVOID Context OPTIONAL)
Definition: filelock.c:1026
INODE_ITEM inode_item
Definition: btrfs_drv.h:281
Status
Definition: gdiplustypes.h:24
#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:2813
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:1747
static NTSTATUS delete_fileref_fcb(_In_ file_ref *fileref, _In_opt_ PFILE_OBJECT FileObject, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
Definition: btrfs.c:2161
#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:277
_In_ fcb _In_ chunk _In_ uint64_t _In_ uint64_t _In_ bool _In_opt_ void _In_opt_ PIRP _In_ LIST_ENTRY * rollback
Definition: btrfs_drv.h:1301
BOOLEAN NTAPI ExAcquireResourceSharedLite(IN PERESOURCE Resource, IN BOOLEAN Wait)
Definition: resource.c:885
bool ads
Definition: btrfs_drv.h:319
NTSTATUS delete_fileref(_In_ file_ref *fileref, _In_opt_ PFILE_OBJECT FileObject, _In_ bool make_orphan, _In_opt_ PIRP Irp, _In_ LIST_ENTRY *rollback)
Definition: btrfs.c:2217
#define IO_NO_INCREMENT
Definition: iotypes.h:566
ULONG NTAPI ExIsResourceAcquiredSharedLite(IN PERESOURCE Resource)
Definition: resource.c:1658
bool reserving
Definition: btrfs_drv.h:376
SHARE_ACCESS share_access
Definition: btrfs_drv.h:287
void exit(int exitcode)
Definition: _exit.c:33
struct _ccb ccb
file_ref * fileref
Definition: btrfs_drv.h:378
return STATUS_SUCCESS
Definition: btrfs.c:2966
void do_unlock_volume(device_extension *Vcb)
Definition: fsctl.c:2318
struct _device_extension * Vcb
Definition: btrfs_drv.h:276
UNICODE_STRING name
Definition: btrfs_drv.h:246
_Ret_z_ WCHAR * file_desc(_In_ PFILE_OBJECT FileObject)
Definition: btrfs.c:1529
bool delete_on_close
Definition: btrfs_drv.h:338

◆ _Dispatch_type_() [3/4]

_Dispatch_type_ ( IRP_MJ_CLOSE  )

Definition at line 479 of file btrfs.c.

481  {
485  bool top_level;
486 
488 
489  TRACE("close\n");
490 
491  top_level = is_top_level(Irp);
492 
493  if (DeviceObject == master_devobj) {
494  TRACE("Closing file system\n");
496  goto end;
497  } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
499  goto end;
500  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
502  goto end;
503  }
504 
506 
507  // FIXME - unmount if called for volume
508  // FIXME - call FsRtlNotifyUninitializeSync(&Vcb->NotifySync) if unmounting
509 
511 
512 end:
513  Irp->IoStatus.Status = Status;
514  Irp->IoStatus.Information = 0;
515 
517 
518  if (top_level)
520 
521  TRACE("returning %08x\n", Status);
522 
524 
525  return Status;
526 }
#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:4175
#define VCB_TYPE_FS
Definition: btrfs_drv.h:657
GLuint GLuint end
Definition: gl.h:1545
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:272
#define IO_DISK_INCREMENT
Definition: iotypes.h:568
PDEVICE_OBJECT master_devobj
Definition: btrfs.c:67
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:2930
#define TRACE(s)
Definition: solgame.cpp:4
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
VOID NTAPI IoSetTopLevelIrp(IN PIRP Irp)
Definition: irp.c:2000
Status
Definition: gdiplustypes.h:24
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:2813
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
static NTSTATUS close_file(_In_ PFILE_OBJECT FileObject, _In_ PIRP Irp)
Definition: btrfs.c:1894
NTSTATUS vol_close(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: volume.c:49
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ _Dispatch_type_() [4/4]

_Dispatch_type_ ( IRP_MJ_PNP  )

Definition at line 588 of file pnp.c.

590  {
594  bool top_level;
595 
597 
598  top_level = is_top_level(Irp);
599 
600  if (Vcb && Vcb->type == VCB_TYPE_BUS) {
602  goto exit;
603  } else if (Vcb && Vcb->type == VCB_TYPE_VOLUME) {
607  goto exit;
608  } else if (Vcb && Vcb->type == VCB_TYPE_PDO) {
610  goto end;
611  } else if (!Vcb || Vcb->type != VCB_TYPE_FS) {
613  goto end;
614  }
615 
617 
618  switch (IrpSp->MinorFunction) {
621  break;
622 
625  break;
626 
629  break;
630 
633  break;
634 
637  goto exit;
638 
639  default:
640  TRACE("passing minor function 0x%x on\n", IrpSp->MinorFunction);
641 
643  Status = IoCallDriver(Vcb->Vpb->RealDevice, Irp);
644  goto exit;
645  }
646 
647 end:
648  Irp->IoStatus.Status = Status;
649 
651 
652 exit:
653  TRACE("returning %08x\n", Status);
654 
655  if (top_level)
657 
659 
660  return Status;
661 }
NTSTATUS pnp_query_remove_device(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pnp.c:181
#define IRP_MN_CANCEL_REMOVE_DEVICE
#define VCB_TYPE_PDO
Definition: btrfs_drv.h:660
#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
#define VCB_TYPE_FS
Definition: btrfs_drv.h:657
GLuint GLuint end
Definition: gl.h:1545
bool is_top_level(_In_ PIRP Irp)
Definition: btrfs.c:272
#define VCB_TYPE_BUS
Definition: btrfs_drv.h:661
static NTSTATUS pnp_remove_device(PDEVICE_OBJECT DeviceObject)
Definition: pnp.c:219
#define IRP_MN_QUERY_REMOVE_DEVICE
PVOID DeviceExtension
Definition: env_spec_w32.h:418
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
static NTSTATUS bus_pnp(bus_device_extension *bde, PIRP Irp)
Definition: pnp.c:353
#define VCB_TYPE_VOLUME
Definition: btrfs_drv.h:659
#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:155
PDEVICE_OBJECT attached_device
Definition: btrfs_drv.h:847
Status
Definition: gdiplustypes.h:24
static NTSTATUS pdo_pnp(PDEVICE_OBJECT pdo, PIRP Irp)
Definition: pnp.c:542
IN PDEVICE_OBJECT DeviceObject
Definition: fatprocs.h:1560
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2745
static NTSTATUS pnp_device_usage_notification(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pnp.c:567
_In_ PIO_STACK_LOCATION IrpSp
Definition: create.c:4157
NTSTATUS NTAPI IoCallDriver(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1218
#define IoSkipCurrentIrpStackLocation(Irp)
Definition: ntifs_ex.h:421
#define IO_NO_INCREMENT
Definition: iotypes.h:566
#define IRP_MN_DEVICE_USAGE_NOTIFICATION
void exit(int exitcode)
Definition: _exit.c:33
NTSTATUS pnp_surprise_removal(PDEVICE_OBJECT DeviceObject, PIRP Irp)
Definition: pnp.c:252

◆ 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 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
__wchar_t WCHAR
Definition: xmlstorage.h:180
#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:2966
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:2343
#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:32
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:32
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 183 of file hwhacks.c.

185 {
187  PVOID DataBlockObject;
188  PWNODE_ALL_DATA AllData;
190 
191  /* Open the data block object for the SMBIOS table */
194  &DataBlockObject);
195  if (!NT_SUCCESS(Status))
196  {
197  DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
198  return;
199  }
200 
201  /* Query the required buffer size */
202  BufferSize = 0;
203  Status = IoWMIQueryAllData(DataBlockObject, &BufferSize, NULL);
204  if (!NT_SUCCESS(Status))
205  {
206  DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
207  return;
208  }
209 
210  AllData = ExAllocatePoolWithTag(PagedPool, BufferSize, 'BTMS');
211  if (AllData == NULL)
212  {
213  DPRINT1("Failed to allocate %lu bytes for SMBIOS tables\n", BufferSize);
214  return;
215  }
216 
217  /* Query the buffer data */
218  Status = IoWMIQueryAllData(DataBlockObject, &BufferSize, AllData);
219  if (!NT_SUCCESS(Status))
220  {
221  DPRINT1("IoWMIOpenBlock failed: 0x%08lx\n", Status);
222  ExFreePoolWithTag(AllData, 'BTMS');
223  return;
224  }
225 
226  /* FIXME: This function should be removed once the mssmbios driver is implemented */
227  /* Store SMBios data in registry */
228  i8042StoreSMBiosTables(AllData + 1,
229  AllData->FixedInstanceSize);
230  DPRINT1("SMBiosTables HACK, see CORE-14867\n");
231 
232  /* Parse the table */
233  i8042ParseSMBiosTables(AllData + 1,
234  AllData->WnodeHeader.BufferSize);
235 
236  /* Free the buffer */
237  ExFreePoolWithTag(AllData, 'BTMS');
238 }
static VOID i8042StoreSMBiosTables(_In_reads_bytes_(TableSize) PVOID SMBiosTables, _In_ ULONG TableSize)
Definition: hwhacks.c:119
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:62
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#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:2343
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
long LONG
Definition: pedump.c:60
#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
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:2343
#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:32
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:2966
#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:2966
#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:528
LONG NTSTATUS
Definition: precomp.h:26
#define KBD_PERR
Definition: i8042prt.h:253
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#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:2966

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:32
#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:528
smooth NULL
Definition: ftsmooth.c:416
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
Status
Definition: gdiplustypes.h:24
return STATUS_SUCCESS
Definition: btrfs.c:2966

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:1061
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:566
#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:2343
#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:2343
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:32
#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:2966
#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:2343
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:528
#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:532
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:32
SETTINGS Settings
Definition: charmap.c:26
NTSYSAPI BOOLEAN NTAPI RtlCreateUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
_In_ PPCI_DEVICE_PRESENCE_PARAMETERS Parameters
Definition: iotypes.h:872
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:2966
#define REG_DWORD
Definition: sdbapi.c:596
#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().