📄 firefly.c
字号:
status = Irp->IoStatus.Status;
}
if (NT_SUCCESS(status) &&
deviceExtension->DevicePnPState != Stopped) {
status = FireflyRegisterWmi(deviceExtension);
}
if (NT_SUCCESS(status)) {
//
// Set the state of the device to started
//
SET_NEW_PNP_STATE(deviceExtension, Started);
}
//
// We must now complete the IRP, since we stopped it in the
// completion routine with STATUS_MORE_PROCESSING_REQUIRED.
//
Irp->IoStatus.Status = status;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
IoReleaseRemoveLock(&deviceExtension->RemoveLock, Irp);
return status;
case IRP_MN_REMOVE_DEVICE:
SET_NEW_PNP_STATE(deviceExtension, Deleted);
IoWMIRegistrationControl(
deviceExtension->Self,
WMIREG_ACTION_DEREGISTER
);
//
// Wait for all outstanding requests to complete
//
DebugPrint(("Waiting for outstanding requests\n"));
IoReleaseRemoveLockAndWait(&deviceExtension->RemoveLock, Irp);
IoSkipCurrentIrpStackLocation(Irp);
status = IoCallDriver(deviceExtension->NextLowerDriver, Irp);
IoDetachDevice(deviceExtension->NextLowerDriver);
IoDeleteDevice(DeviceObject);
return status;
case IRP_MN_QUERY_STOP_DEVICE:
SET_NEW_PNP_STATE(deviceExtension, StopPending);
status = STATUS_SUCCESS;
break;
case IRP_MN_CANCEL_STOP_DEVICE:
//
// Check to see whether you have received cancel-stop
// without first receiving a query-stop. This could happen if someone
// above us fails a query-stop and passes down the subsequent
// cancel-stop.
//
if(StopPending == deviceExtension->DevicePnPState)
{
//
// We did receive a query-stop, so restore.
//
RESTORE_PREVIOUS_PNP_STATE(deviceExtension);
}
status = STATUS_SUCCESS; // We must not fail this IRP.
break;
case IRP_MN_STOP_DEVICE:
SET_NEW_PNP_STATE(deviceExtension, StopPending);
status = STATUS_SUCCESS;
break;
case IRP_MN_QUERY_REMOVE_DEVICE:
SET_NEW_PNP_STATE(deviceExtension, RemovePending);
status = STATUS_SUCCESS;
break;
case IRP_MN_SURPRISE_REMOVAL:
SET_NEW_PNP_STATE(deviceExtension, SurpriseRemovePending);
status = STATUS_SUCCESS;
break;
case IRP_MN_CANCEL_REMOVE_DEVICE:
//
// Check to see whether you have received cancel-remove
// without first receiving a query-remove. This could happen if
// someone above us fails a query-remove and passes down the
// subsequent cancel-remove.
//
if (RemovePending == deviceExtension->DevicePnPState) {
//
// We did receive a query-remove, so restore.
//
RESTORE_PREVIOUS_PNP_STATE(deviceExtension);
}
status = STATUS_SUCCESS; // We must not fail this IRP.
break;
default:
//
// If you don't handle any IRP you must leave the
// status as is.
//
status = Irp->IoStatus.Status;
break;
}
//
// Pass the IRP down and forget it.
//
Irp->IoStatus.Status = status;
IoSkipCurrentIrpStackLocation (Irp);
status = IoCallDriver (deviceExtension->NextLowerDriver, Irp);
IoReleaseRemoveLock(&deviceExtension->RemoveLock, Irp);
return status;
}
NTSTATUS
FireflySynchronousCompletionRoutine(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context
)
/*++
Routine Description:
A completion routine for use when calling the lower device objects to
which our filter deviceobject is attached.
Arguments:
DeviceObject - Pointer to deviceobject
Irp - Pointer to a PnP Irp.
Context - Pointer to an event object
Return Value:
NT Status is returned.
--*/
{
UNREFERENCED_PARAMETER(DeviceObject);
//
// We could switch on the major and minor functions of the IRP to perform
// different functions, but we know that Context is an event that needs
// to be set.
//
KeSetEvent((PKEVENT) Context, IO_NO_INCREMENT, FALSE);
//
// Allows the caller to use the IRP after it is completed
//
return STATUS_MORE_PROCESSING_REQUIRED;
}
NTSTATUS
FireflyDispatchPower(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
/*++
Routine Description:
This routine is the dispatch routine for power irps.
Arguments:
DeviceObject - Pointer to the device object.
Irp - Pointer to the request packet.
Return Value:
NT Status code
--*/
{
PDEVICE_EXTENSION deviceExtension;
NTSTATUS status;
PAGED_CODE();
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
status = IoAcquireRemoveLock (&deviceExtension->RemoveLock, Irp);
if (!NT_SUCCESS (status)) { // may be device is being removed.
Irp->IoStatus.Status = status;
PoStartNextPowerIrp(Irp);
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return status;
}
PoStartNextPowerIrp(Irp);
IoSkipCurrentIrpStackLocation(Irp);
status = PoCallDriver(deviceExtension->NextLowerDriver, Irp);
IoReleaseRemoveLock(&deviceExtension->RemoveLock, Irp);
return status;
}
NTSTATUS
FireflyDispatchWmi(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
/*++
Routine Description:
This routine is the dispatch routine for Ioctls.
Arguments:
DeviceObject - Pointer to the device object.
Irp - Pointer to the request packet.
Return Value:
NT Status code
--*/
{
SYSCTL_IRP_DISPOSITION disposition;
NTSTATUS status;
PDEVICE_EXTENSION deviceExtension;
PAGED_CODE();
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
status = IoAcquireRemoveLock (&deviceExtension->RemoveLock, Irp);
if (!NT_SUCCESS (status)) { // may be device is being removed.
Irp->IoStatus.Status = status;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return status;
}
status = WmiSystemControl(
&deviceExtension->WmiLibInfo,
DeviceObject,
Irp,
&disposition
);
switch(disposition) {
case IrpProcessed:
//
// This irp has been processed and may be completed or pending.
//
break;
case IrpNotCompleted:
//
// This irp has not been completed, but has been fully processed.
// we will complete it now
//
IoCompleteRequest(Irp, IO_NO_INCREMENT);
break;
case IrpForward:
case IrpNotWmi:
//
// This irp is either not a WMI irp or is a WMI irp targeted at a
// device lower in the stack.
//
IoSkipCurrentIrpStackLocation (Irp);
status = IoCallDriver (deviceExtension->NextLowerDriver, Irp);
break;
default:
//
// We really should never get here, but if we do just forward....
//
ASSERT(FALSE);
IoSkipCurrentIrpStackLocation (Irp);
status = IoCallDriver (deviceExtension->NextLowerDriver, Irp);
break;
}
IoReleaseRemoveLock(&deviceExtension->RemoveLock, Irp);
return status;
}
NTSTATUS
FireflyForwardIrp(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp
)
/*++
Routine Description:
The default dispatch routine. If this driver does not recognize the
IRP, then it should send it down, unmodified.
If the device holds iris, this IRP must be queued in the device extension
No completion routine is required.
For demonstrative purposes only, we will pass all the (non-PnP) Irps down
on the stack (as we are a filter driver). A real driver might choose to
service some of these Irps.
As we have NO idea which function we are happily passing on, we can make
NO assumptions about whether or not it will be called at raised IRQL.
For this reason, this function must be in put into non-paged pool
(aka the default location).
Arguments:
DeviceObject - pointer to a device object.
Irp - pointer to an I/O Request Packet.
Return Value:
NT status code
--*/
{
PDEVICE_EXTENSION deviceExtension;
NTSTATUS status;
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
status = IoAcquireRemoveLock (&deviceExtension->RemoveLock, Irp);
if (!NT_SUCCESS (status)) {
Irp->IoStatus.Status = status;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
return status;
}
IoSkipCurrentIrpStackLocation (Irp);
status = IoCallDriver (deviceExtension->NextLowerDriver, Irp);
IoReleaseRemoveLock(&deviceExtension->RemoveLock, Irp);
return status;
}
NTSTATUS
FireflyRegisterWmi(
IN PDEVICE_EXTENSION DeviceExtension
)
{
ULONG guidCount;
PAGED_CODE();
//
// Initialize our WMI state.
//
DeviceExtension->StdDeviceData.TailLit = TRUE;
//
// Register with the WMI library.
//
guidCount = ARRAYLEN(FireflyWmiGuidList);
ASSERT(1 == guidCount);
DeviceExtension->WmiLibInfo.GuidCount = guidCount;
DeviceExtension->WmiLibInfo.GuidList = FireflyWmiGuidList;
DeviceExtension->WmiLibInfo.QueryWmiRegInfo = FireflyQueryWmiRegInfo;
DeviceExtension->WmiLibInfo.QueryWmiDataBlock = FireflyQueryWmiDataBlock;
DeviceExtension->WmiLibInfo.SetWmiDataBlock = FireflySetWmiDataBlock;
DeviceExtension->WmiLibInfo.SetWmiDataItem = FireflySetWmiDataItem;
DeviceExtension->WmiLibInfo.ExecuteWmiMethod = NULL;
DeviceExtension->WmiLibInfo.WmiFunctionControl = NULL;
return IoWMIRegistrationControl(
DeviceExtension->Self,
WMIREG_ACTION_REGISTER
);
}
//
// WMI System Call back functions
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -