2015-05-14 14:42:05 +00:00
|
|
|
/*
|
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: Parallel Port Function Driver
|
|
|
|
* FILE: drivers/parallel/parport/pdo.c
|
|
|
|
* PURPOSE: PDO functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "parport.h"
|
|
|
|
|
|
|
|
/* FUNCTIONS ****************************************************************/
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
PdoCreate(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2015-05-27 20:18:10 +00:00
|
|
|
PPDO_DEVICE_EXTENSION DeviceExtension;
|
|
|
|
PIO_STACK_LOCATION Stack;
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
2015-05-14 14:42:05 +00:00
|
|
|
DPRINT("PdoCreate()\n");
|
|
|
|
|
2015-05-27 20:18:10 +00:00
|
|
|
Stack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
DeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
|
|
|
|
if (Stack->Parameters.Create.Options & FILE_DIRECTORY_FILE)
|
|
|
|
{
|
|
|
|
DPRINT1("Not a directory\n");
|
|
|
|
Status = STATUS_NOT_A_DIRECTORY;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINT("Open LPT%lu: successful\n", DeviceExtension->LptPort);
|
|
|
|
DeviceExtension->OpenCount++;
|
|
|
|
|
|
|
|
done:
|
|
|
|
Irp->IoStatus.Status = Status;
|
2015-05-14 14:42:05 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2015-05-27 20:18:10 +00:00
|
|
|
|
|
|
|
return Status;
|
2015-05-14 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
PdoClose(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2015-05-27 20:18:10 +00:00
|
|
|
PPDO_DEVICE_EXTENSION pDeviceExtension;
|
|
|
|
|
2015-05-14 14:42:05 +00:00
|
|
|
DPRINT("PdoClose()\n");
|
|
|
|
|
2015-05-27 20:18:10 +00:00
|
|
|
pDeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
pDeviceExtension->OpenCount--;
|
|
|
|
|
2015-05-14 14:42:05 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2015-05-27 20:18:10 +00:00
|
|
|
|
2015-05-14 14:42:05 +00:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
PdoCleanup(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
DPRINT("PdoCleanup()\n");
|
|
|
|
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-01 18:02:45 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
PdoRead(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
|
|
|
DPRINT("PdoRead()\n");
|
|
|
|
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-14 14:42:05 +00:00
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
PdoWrite(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2015-05-27 20:18:10 +00:00
|
|
|
PPDO_DEVICE_EXTENSION PdoDeviceExtension;
|
|
|
|
PFDO_DEVICE_EXTENSION FdoDeviceExtension;
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
PUCHAR Buffer;
|
|
|
|
ULONG i;
|
|
|
|
UCHAR PortStatus;
|
|
|
|
ULONG ulCount;
|
|
|
|
|
2015-05-14 14:42:05 +00:00
|
|
|
DPRINT("PdoWrite()\n");
|
|
|
|
|
2015-05-27 20:18:10 +00:00
|
|
|
PdoDeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
|
|
|
|
FdoDeviceExtension = (PFDO_DEVICE_EXTENSION)PdoDeviceExtension->AttachedFdo->DeviceExtension;
|
|
|
|
|
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
Buffer = GetUserBuffer(Irp);
|
|
|
|
DPRINT("Length: %lu\n", IoStack->Parameters.Write.Length);
|
|
|
|
DPRINT("Buffer: %p\n", Buffer);
|
|
|
|
|
|
|
|
for (i = 0; i < IoStack->Parameters.Write.Length; i++)
|
|
|
|
{
|
|
|
|
ulCount = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
KeStallExecutionProcessor(10);
|
2018-04-23 09:27:49 +00:00
|
|
|
PortStatus = READ_PORT_UCHAR(UlongToPtr(FdoDeviceExtension->BaseAddress + 1));
|
2015-05-27 20:18:10 +00:00
|
|
|
ulCount++;
|
|
|
|
}
|
|
|
|
while (ulCount < 500000 && !(PortStatus & LP_PBUSY));
|
|
|
|
|
|
|
|
if (ulCount == 500000)
|
|
|
|
{
|
|
|
|
DPRINT("Timed out\n");
|
|
|
|
|
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = STATUS_TIMEOUT;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
|
|
|
|
return STATUS_TIMEOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Write character */
|
2018-04-23 09:27:49 +00:00
|
|
|
WRITE_PORT_UCHAR(UlongToPtr(FdoDeviceExtension->BaseAddress), Buffer[i]);
|
2015-05-27 20:18:10 +00:00
|
|
|
|
|
|
|
KeStallExecutionProcessor(10);
|
|
|
|
|
2018-04-23 09:27:49 +00:00
|
|
|
WRITE_PORT_UCHAR(UlongToPtr(FdoDeviceExtension->BaseAddress + 2), (LP_PSELECP | LP_PINITP | LP_PSTROBE));
|
2015-05-27 20:18:10 +00:00
|
|
|
|
|
|
|
KeStallExecutionProcessor(10);
|
|
|
|
|
2018-04-23 09:27:49 +00:00
|
|
|
WRITE_PORT_UCHAR(UlongToPtr(FdoDeviceExtension->BaseAddress + 2), (LP_PSELECP | LP_PINITP));
|
2015-05-27 20:18:10 +00:00
|
|
|
}
|
|
|
|
|
2015-05-14 14:42:05 +00:00
|
|
|
Irp->IoStatus.Information = 0;
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
PdoPnp(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2015-11-16 19:56:00 +00:00
|
|
|
NTSTATUS Status;
|
2015-05-14 14:42:05 +00:00
|
|
|
DPRINT("PdoPnp()\n");
|
|
|
|
|
2015-11-16 19:56:00 +00:00
|
|
|
Status = Irp->IoStatus.Status;
|
2015-05-14 14:42:05 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2015-11-16 19:56:00 +00:00
|
|
|
return Status;
|
2015-05-14 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NTSTATUS
|
|
|
|
NTAPI
|
|
|
|
PdoPower(IN PDEVICE_OBJECT DeviceObject,
|
|
|
|
IN PIRP Irp)
|
|
|
|
{
|
2016-07-20 12:21:11 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
PIO_STACK_LOCATION IoStack;
|
|
|
|
|
2015-05-14 14:42:05 +00:00
|
|
|
DPRINT("PdoPower()\n");
|
|
|
|
|
2016-07-20 12:21:11 +00:00
|
|
|
IoStack = IoGetCurrentIrpStackLocation(Irp);
|
|
|
|
|
|
|
|
switch (IoStack->MinorFunction)
|
|
|
|
{
|
|
|
|
case IRP_MN_SET_POWER:
|
|
|
|
case IRP_MN_QUERY_POWER:
|
|
|
|
Irp->IoStatus.Status = STATUS_SUCCESS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = Irp->IoStatus.Status;
|
|
|
|
PoStartNextPowerIrp(Irp);
|
2015-05-14 14:42:05 +00:00
|
|
|
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
2016-07-20 12:21:11 +00:00
|
|
|
return Status;
|
2015-05-14 14:42:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|