📄 parport.h
字号:
/*++
Copyright (C) Microsoft Corporation, 1993 - 1999
Module Name :
parport.h
Abstract:
Type definitions and data for the parallel port driver.
Revision History:
--*/
#ifndef _PARPORT_H_
#define _PARPORT_H_
#define arraysize(p) (sizeof(p)/sizeof((p)[0])) // From Walter Oney WDM book
// Used to keep track of the state of an IEEE negotiation, transfer, or termination
typedef struct _IEEE_STATE {
ULONG CurrentEvent; // IEEE 1284 event - see IEEE 1284-1994 spec
P1284_PHASE CurrentPhase; // see parallel.h for enum def - PHASE_UNKNOWN, ..., PHASE_INTERRUPT_HOST
BOOLEAN Connected; // are we currently negotiated into a 1284 mode?
BOOLEAN IsIeeeTerminateOk; // are we in a state where an IEEE Terminate is legal?
USHORT ProtocolFamily; // what protocol family are we currently using (if connected)
} IEEE_STATE, *PIEEE_STATE;
// should we use or ignore XFlag on termination event 24 when terminating NIBBLE mode for 1284 ID query?
typedef enum {
IgnoreXFlagOnEvent24,
UseXFlagOnEvent24
} XFlagOnEvent24;
// DVDF - 2000-08-16
// Used with IOCTL_INTERNAL_PARPORT_EXECUTE_TASK
typedef enum {
Select,
Deselect,
Write,
Read,
MaxTask
} ParportTask;
// Used with IOCTL_INTERNAL_PARPORT_EXECUTE_TASK
typedef struct _PARPORT_TASK {
ParportTask Task; // what type of request?
PCHAR Buffer; // where is the buffer to use?
ULONG BufferLength; // how big is the buffer?
ULONG RequestLength; // how many bytes of data is requested or supplied?
CHAR Requestor[8]; // diagnostic use only - suggest pdx->Location, e.g., "LPT2.4"
} PARPORT_TASK, *PPARPORT_TASK;
// handled by parport FDOs - execute a specified task
#define IOCTL_INTERNAL_PARPORT_EXECUTE_TASK CTL_CODE(FILE_DEVICE_PARALLEL_PORT, 64, METHOD_BUFFERED, FILE_ANY_ACCESS)
struct _PDO_EXTENSION;
typedef struct _PDO_EXTENSION * PPDO_EXTENSION;
typedef
NTSTATUS
(*PPROTOCOL_READ_ROUTINE) (
IN PPDO_EXTENSION Extension,
IN PVOID Buffer,
IN ULONG BufferSize,
OUT PULONG BytesTransferred
);
typedef
NTSTATUS
(*PPROTOCOL_WRITE_ROUTINE) (
IN PPDO_EXTENSION Extension,
IN PVOID Buffer,
IN ULONG BufferSize,
OUT PULONG BytesTransferred
);
typedef
NTSTATUS
(*PDOT3_RESET_ROUTINE) (
IN PPDO_EXTENSION Extension
);
typedef struct _DOT3DL_PCTL {
PPROTOCOL_READ_ROUTINE fnRead;
PPROTOCOL_WRITE_ROUTINE fnWrite;
PDOT3_RESET_ROUTINE fnReset;
P12843_DL_MODES DataLinkMode;
USHORT CurrentPID;
USHORT FwdSkipMask;
USHORT RevSkipMask;
UCHAR DataChannel;
UCHAR ResetChannel;
UCHAR ResetByteCount;
UCHAR ResetByte;
PKEVENT Event;
BOOLEAN bEventActive;
} DOT3DL_PCTL, *PDOT3DL_PCTL;
//
// If we can't use our preferred \Device\ParallelN number due to name collision,
// then start with N == PAR_CLASSNAME_OFFSET and increment until we are successful
//
#define PAR_CLASSNAME_OFFSET 8
//
// For pnp id strings
//
#define MAX_ID_SIZE 256
// used to construct IEEE 1284.3 "Dot" name suffixes
// table lookup for integer to WCHAR conversion
#define PAR_UNICODE_PERIOD L'.'
#define PAR_UNICODE_COLON L':'
//#define PAR_REV_MODE_SKIP_MASK (CHANNEL_NIBBLE | BYTE_BIDIR | EPP_ANY)
#define PAR_REV_MODE_SKIP_MASK (CHANNEL_NIBBLE | BYTE_BIDIR | EPP_ANY | ECP_ANY)
#define PAR_FWD_MODE_SKIP_MASK (EPP_ANY | BOUNDED_ECP | ECP_HW_NOIRQ | ECP_HW_IRQ)
//#define PAR_FWD_MODE_SKIP_MASK (EPP_ANY)
#define PAR_MAX_CHANNEL 127
#define PAR_COMPATIBILITY_RESET 300
#define PptSetFlags( FlagsVariable, FlagsToSet ) { (FlagsVariable) |= (FlagsToSet); }
#define PptClearFlags( FlagsVariable, FlagsToClear ) { (FlagsVariable) &= ~(FlagsToClear); }
// convert timeout in Milliseconds to relative timeout in 100ns units
// suitable as parameter 5 to KeWaitForSingleObject(..., TimeOut)
#define PPT_SET_RELATIVE_TIMEOUT_IN_MILLISECONDS(VARIABLE, VALUE) (VARIABLE).QuadPart = -( (LONGLONG) (VALUE)*10*1000 )
#define MAX_PNP_IRP_MN_HANDLED IRP_MN_QUERY_LEGACY_BUS_INFORMATION
extern ULONG PptDebugLevel;
extern ULONG PptBreakOn;
extern UNICODE_STRING RegistryPath; // copy of the registry path passed to DriverEntry()
extern UCHAR PptDot3Retries; // variable to know how many times to try a select or
// deselect for 1284.3 if we do not succeed.
typedef enum _DevType {
DevTypeFdo = 1,
DevTypePdo = 2,
} DevType, *PDevType;
typedef enum _PdoType {
PdoTypeRawPort = 1,
PdoTypeEndOfChain = 2,
PdoTypeDaisyChain = 4,
PdoTypeLegacyZip = 8
} PdoType, *PPdoType;
extern const PHYSICAL_ADDRESS PhysicalZero;
#define PARPORT_TAG (ULONG) 'PraP'
#ifdef POOL_TAGGING
#ifdef ExAllocatePool
#undef ExAllocatePool
#endif
#define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,PARPORT_TAG)
#endif
//
// used for FilterResourceMethod in processing PnP IRP_MN_FILTER_RESOURCE_REQUIREMENTS
//
#define PPT_TRY_USE_NO_IRQ 0 // if alternatives exist that don't require an IRQ then
// delete those alternatives that do, otherwise do nothing
#define PPT_FORCE_USE_NO_IRQ 1 // try previous method - if it fails (i.e., all alternatives
// require resources), then nuke IRQ resource descriptors
// in all alternatives
#define PPT_ACCEPT_IRQ 2 // don't do any resource filtering - accept resources that
// we are given
//
// Keep track of GET and RELEASE port info.
//
extern LONG PortInfoReferenceCount;
extern PFAST_MUTEX PortInfoMutex;
//
// DeviceStateFlags
//
#define PAR_DEVICE_PAUSED ((ULONG)0x00000010) // stop-pending, stopped, or remove-pending states
#define PAR_DEVICE_PORT_REMOVE_PENDING ((ULONG)0x00000200) // our ParPort is in a Remove Pending State
//
// extension->PnpState - define the current PnP state of the device
//
#define PPT_DEVICE_STARTED ((ULONG)0x00000001) // Device has succeeded START
#define PPT_DEVICE_DELETED ((ULONG)0x00000002) // IoDeleteDevice has been called
#define PPT_DEVICE_STOP_PENDING ((ULONG)0x00000010) // Device has succeeded QUERY_STOP, waiting for STOP or CANCEL
#define PPT_DEVICE_STOPPED ((ULONG)0x00000020) // Device has received STOP
#define PPT_DEVICE_DELETE_PENDING ((ULONG)0x00000040) // we have started the process of deleting device object
#define PPT_DEVICE_HARDWARE_GONE ((ULONG)0x00000080) // our hardware is gone
#define PPT_DEVICE_REMOVE_PENDING ((ULONG)0x00000100) // Device succeeded QUERY_REMOVE, waiting for REMOVE or CANCEL
#define PPT_DEVICE_REMOVED ((ULONG)0x00000200) // Device has received REMOVE
#define PPT_DEVICE_SURPRISE_REMOVED ((ULONG)0x00001000) // Device has received SURPRISE_REMOVAL
#define PPT_DEVICE_PAUSED ((ULONG)0x00010000) // stop-pending, stopped, or remove-pending - hold requests
//
// IEEE 1284 constants (Protocol Families)
//
#define FAMILY_NONE 0x0
#define FAMILY_REVERSE_NIBBLE 0x1
#define FAMILY_REVERSE_BYTE 0x2
#define FAMILY_ECP 0x3
#define FAMILY_EPP 0x4
#define FAMILY_BECP 0x5
#define FAMILY_MAX FAMILY_BECP
typedef struct _IRPQUEUE_CONTEXT {
LIST_ENTRY irpQueue;
KSPIN_LOCK irpQueueSpinLock;
} IRPQUEUE_CONTEXT, *PIRPQUEUE_CONTEXT;
typedef struct _COMMON_EXTENSION {
ULONG Signature1; // Used to increase our confidence that this is a ParPort extension
enum _DevType DevType; // distinguish an FDO_EXTENSION from a PDO_EXTENSION
PCHAR Location; // LPTx or LPTx.y location for PDO (symlink name less the \DosDevices prefix)
// LPTxF for FDO
PDEVICE_OBJECT DeviceObject; // back pointer to our DEVICE_OBJECT
ULONG PnpState; // Device State - See Device State Flags: PPT_DEVICE_... above
IO_REMOVE_LOCK RemoveLock; // Used to prevent PnP from removing us while requests are pending
LONG OpenCloseRefCount; // keep track of the number of handles open to our device
UNICODE_STRING DeviceInterface; // SymbolicLinkName returned from IoRegisterDeviceInterface
BOOLEAN DeviceInterfaceState; // Did we last set the DeviceInterface to True or False?
BOOLEAN TimeToTerminateThread;// TRUE == worker thread should kill itself via PsTerminateSystemThread()
PVOID ThreadObjectPointer; // pointer to a worker thread for this Device
} COMMON_EXTENSION, *PCOMMON_EXTENSION, *PCE;
//
// Fdo Device Extension
//
typedef struct _FDO_EXTENSION {
COMMON_EXTENSION;
//
// Devices that we have enumerated
//
PDEVICE_OBJECT RawPortPdo; // LPTx - legacy "Raw Port" interface
PDEVICE_OBJECT DaisyChainPdo[4]; // LPTx.0 -- LPTx.3 - IEEE 1284.3 daisy chain devices
PDEVICE_OBJECT EndOfChainPdo; // LPTx.4 - end-of-chain devices
PDEVICE_OBJECT LegacyZipPdo; // LPTx.5 - original (non-1284.3) Iomega Zip drive
IEEE_STATE IeeeState;
//
// DisableEndOfChainBusRescan - if TRUE then do NOT rescan bus for change in End Of Chain (LPTx.4)
// device in response to PnP IRP_MN_QUERY_DEVICE_RELATIONS / BusRelations,
// simply report the LPTx.4 device that we found on the previous bus rescan.
// - if we did not have an End Of Chain device on the previous rescan then this
// flag is ignored.
//
BOOLEAN DisableEndOfChainBusRescan;
//
// Points to the driver object that contains this instance of parport.
//
PDRIVER_OBJECT DriverObject;
//
// Points to the PDO
//
PDEVICE_OBJECT PhysicalDeviceObject;
//
// Points to our parent
//
PDEVICE_OBJECT ParentDeviceObject;
//
// Counter is incremented by the "polling for printers" thread on
// each failed attempt at reading the IEEE 1284 Device ID from the
// device. When the counter hits a defined threshold the polling
// thread considers the error unrecoverable and stops polling
//
ULONG PollingFailureCounter;
// list head for list of PDOs to delete on Driver Unload
LIST_ENTRY DevDeletionListHead;
//
// Queue of ALLOCATE & SELECT irps waiting to be processed. Access with cancel spin lock.
//
LIST_ENTRY WorkQueue;
// Queue Irps while waiting to be processed
IRPQUEUE_CONTEXT IrpQueueContext;
//
// The number of irps in the queue where -1 represents
// a free port, 0 represents an allocated port with
// zero waiters, 1 represents an allocated port with
// 1 waiter, etc...
//
// This variable must be accessed with the cancel spin
// lock or at interrupt level whenever interrupts are
// being used.
//
LONG WorkQueueCount;
//
// These structures hold the port address and range for the parallel port.
//
PARALLEL_PORT_INFORMATION PortInfo;
PARALLEL_PNP_INFORMATION PnpInfo;
//
// Information about the interrupt so that we
// can connect to it when we have a client that
// uses the interrupt.
//
ULONG AddressSpace;
ULONG EcpAddressSpace;
INTERFACE_TYPE InterfaceType;
ULONG BusNumber;
BOOLEAN FoundInterrupt;
KIRQL InterruptLevel;
ULONG InterruptVector;
KAFFINITY InterruptAffinity;
KINTERRUPT_MODE InterruptMode;
//
// This list contains all of the interrupt service
// routines registered by class drivers. All access
// to this list should be done at interrupt level.
//
// This list also contains all of the deferred port check
// routines. These routines are called whenever
// the port is freed if there are no IRPs queued for
// the port. Access this list only at interrupt level.
//
LIST_ENTRY IsrList;
//
// The parallel port interrupt object.
//
PKINTERRUPT InterruptObject;
//
// Keep a reference count for the interrupt object.
// This count should be referenced with the cancel
// spin lock.
//
ULONG InterruptRefCount;
//
// DPC for freeing the port from the interrupt routine.
//
KDPC FreePortDpc;
//
// Points to workitem for freeing the port
//
PIO_WORKITEM FreePortWorkItem;
//
// Set at initialization to indicate that on the current
// architecture we need to unmap the base register address
// when we unload the driver.
//
BOOLEAN UnMapRegisters;
//
// Flags for ECP and EPP detection and changing of the modes
//
BOOLEAN NationalChecked;
BOOLEAN NationalChipFound;
BOOLEAN FilterMode;
UCHAR EcrPortData;
//
// Structure that hold information from the Chip Filter Driver
//
PARALLEL_PARCHIP_INFO ChipInfo;
UNICODE_STRING DeviceName;
//
// Current Device Power State
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -