NTSTATUS DF_DispatchPower(PDEVICE_OBJECT DeviceObject, PIRP Irp) { PDF_DEVICE_EXTENSION DevExt; PIO_STACK_LOCATION IrpSp; PAGED_CODE(); DevExt = (PDF_DEVICE_EXTENSION)DeviceObject->DeviceExtension; IrpSp = IoGetCurrentIrpStackLocation(Irp); DBG_PRINT(DBG_TRACE_ROUTINES, ("%s: ", __FUNCTION__)); if (IrpSp->Parameters.Power.Type == SystemPowerState) { DBG_PRINT(DBG_TRACE_OPS, ("SystemPowerState...\n")); if (PowerSystemShutdown == IrpSp->Parameters.Power.State.SystemState) { DBG_PRINT(DBG_TRACE_OPS, ("%d-%d: Stopping Device...\n", DevExt->DiskNumber, DevExt->PartitionNumber)); StopDevice(DeviceObject); DBG_PRINT(DBG_TRACE_OPS, ("%d-%d: Device Stopped.\n", DevExt->DiskNumber, DevExt->PartitionNumber)); } } else if (IrpSp->Parameters.Power.Type == DevicePowerState) DBG_PRINT(DBG_TRACE_OPS, ("DevicePowerState...\n")); else DBG_PRINT(DBG_TRACE_OPS, ("\n")); #if WINVER < _WIN32_WINNT_VISTA PoStartNextPowerIrp(Irp); IoSkipCurrentIrpStackLocation(Irp); return PoCallDriver(DevExt->LowerDeviceObject, Irp); #else IoSkipCurrentIrpStackLocation(Irp); return IoCallDriver(DevExt->LowerDeviceObject, Irp); #endif }
NTSTATUS DriverPNP(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp) { Debug("Enter DriverPNP"); if(pDevObj == g_MasterDeviceObj) { pIrp->IoStatus.Information = 0; pIrp->IoStatus.Status = STATUS_SUCCESS; IoCompleteRequest(pIrp,IO_NO_INCREMENT); Debug("g_MasterDeviceObj,DriverPNP"); return STATUS_SUCCESS; } PMYDEVICE_EXTENSION tDevExtend = (PMYDEVICE_EXTENSION)pDevObj->DeviceExtension; PIO_STACK_LOCATION tIrpStack = IoGetCurrentIrpStackLocation(pIrp); NTSTATUS tStatus; if(IRP_MN_REMOVE_DEVICE == tIrpStack->MinorFunction) { IoSkipCurrentIrpStackLocation(pIrp); tStatus = IoCallDriver(tDevExtend->LowDeviceObj,pIrp); IoDetachDevice(tDevExtend->LowDeviceObj); IoDeleteDevice(pDevObj); tStatus = STATUS_SUCCESS; } else { IoSkipCurrentIrpStackLocation(pIrp); tStatus = IoCallDriver(tDevExtend->LowDeviceObj,pIrp); } Debug("Leave DriverPNP"); return tStatus; }
NTSTATUS HotKeyKrnlPnP( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) { PDEVICE_EXTENSION devExt; PIO_STACK_LOCATION irpStack; NTSTATUS status = STATUS_SUCCESS; KdPrint(("[shadow] Enter HotKeyKrnlPnP...\n")); devExt = (PDEVICE_EXTENSION)(DeviceObject->DeviceExtension); irpStack = IoGetCurrentIrpStackLocation(Irp); switch (irpStack->MinorFunction) { case IRP_MN_REMOVE_DEVICE: KdPrint(("[shadow] Enter IRP_MJ_PNP - IRP_MN_REMOVE_DEVICE\n")); IoSkipCurrentIrpStackLocation(Irp); IoCallDriver(devExt->LowerDeviceObject, Irp); IoDetachDevice(devExt->LowerDeviceObject); IoDeleteDevice(DeviceObject); status = STATUS_SUCCESS; break; default: IoSkipCurrentIrpStackLocation(Irp); status = IoCallDriver(devExt->LowerDeviceObject, Irp); } return status; }
NTSTATUS KbLayoutDispatchPNP( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) { PDEVICE_EXTENSION devExt; PIO_STACK_LOCATION irpStack; NTSTATUS status = STATUS_SUCCESS; devExt = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension; irpStack = IoGetCurrentIrpStackLocation(Irp); switch(irpStack->MinorFunction){ case IRP_MN_REMOVE_DEVICE: IoSkipCurrentIrpStackLocation(Irp); IoCallDriver(devExt->NextDevice, Irp); IoDetachDevice(devExt->NextDevice); // the argument is actually the device to detach *from* IoDeleteDevice(DeviceObject); break; default: IoSkipCurrentIrpStackLocation(Irp); status = IoCallDriver(devExt->NextDevice, Irp); break; } return status; }
NTSTATUS CFTDefaultDispatch(PDEVICE_OBJECT aDeviceObject, PIRP aIrp) { PIO_STACK_LOCATION ioStackLocation = IoGetCurrentIrpStackLocation(aIrp); NTSTATUS status = STATUS_SUCCESS; ULONG i = 0, j = 0; // 首先需要知道发送给了那哪个设备。 for (i = 0; i < CFT_MAX_COM_ID; ++i) { if (global_FileDevice[i] == aDeviceObject) { // 所有电源操作一律不过滤 if (ioStackLocation->MajorFunction == IRP_MJ_POWER) { // 直接发送 PoStartNextPowerIrp(aIrp); IoSkipCurrentIrpStackLocation(aIrp); return PoCallDriver(global_RealDevice[i], aIrp); } // 我们只过滤写请求,获得缓冲区以及长度,打印出来。 if (ioStackLocation->MajorFunction == IRP_MJ_WRITE) { // 获得长度 ULONG len = ioStackLocation->Parameters.Write.Length; // 获得缓冲区 PUCHAR buf = NULL; if (aIrp->MdlAddress != NULL) buf = (PUCHAR)MmGetSystemAddressForMdlSafe(aIrp->MdlAddress, NormalPagePriority); else buf = (PUCHAR)aIrp->UserBuffer; if (buf == NULL) buf = (PUCHAR)aIrp->AssociatedIrp.SystemBuffer; // 打印内容 for (j = 0; j < len; ++j) DbgPrint("COM capture : Send-Data : %2x\r\n", buf[j]); } } // 直接下发 IoSkipCurrentIrpStackLocation(aIrp); return IoCallDriver(global_RealDevice[i], aIrp); } // 如果根本就不在被绑定的设备中,那是有问题的,直接返回参数 aIrp->IoStatus.Information = 0; aIrp->IoStatus.Status = STATUS_INVALID_PARAMETER; IoCompleteRequest(aIrp, IO_NO_INCREMENT); return STATUS_SUCCESS; }
NTSTATUS BulkUsb_DispatchSysCtrl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { PTDeviceExtension deviceExtension; SYSCTL_IRP_DISPOSITION disposition; NTSTATUS ntStatus; PIO_STACK_LOCATION irpStack; PAGED_CODE(); irpStack = IoGetCurrentIrpStackLocation (Irp); deviceExtension = (PTDeviceExtension) DeviceObject->DeviceExtension; if(REMOVED == deviceExtension->DeviceState) { ntStatus = STATUS_DELETE_PENDING; Irp->IoStatus.Status = ntStatus; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); return ntStatus; } BulkUsb_DbgPrint(3, ("file bulkwmi: BulkUsb_DispatchSysCtrl::\n")); BulkUsb_IoIncrement(deviceExtension); ntStatus = WmiSystemControl(&deviceExtension->WmiLibInfo, DeviceObject, Irp, &disposition); switch(disposition) { case IrpProcessed: break; case IrpNotCompleted: IoCompleteRequest(Irp, IO_NO_INCREMENT); break; case IrpForward: case IrpNotWmi: IoSkipCurrentIrpStackLocation (Irp); ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp); break; default: IoSkipCurrentIrpStackLocation (Irp); ntStatus = IoCallDriver(deviceExtension->TopOfStackDeviceObject, Irp); break; } BulkUsb_DbgPrint(3, ("file bulkwmi: BulkUsb_DispatchSysCtrl::\n")); BulkUsb_IoDecrement(deviceExtension); return ntStatus; }
__drv_mustHoldCriticalRegion NTSTATUS RfsdPnpCancelRemove ( PRFSD_IRP_CONTEXT IrpContext, PRFSD_VCB Vcb ) { NTSTATUS Status; PAGED_CODE(); RfsdPrint((DBG_PNP, "RfsdPnpCancelRemove by RfsdPnp ...\n")); ExAcquireResourceExclusiveLite( &Vcb->MainResource, TRUE ); Status = RfsdUnlockVcb(Vcb, IrpContext->FileObject); ExReleaseResourceForThreadLite( &Vcb->MainResource, ExGetCurrentResourceThread()); IoSkipCurrentIrpStackLocation(IrpContext->Irp); Status = IoCallDriver(Vcb->TargetDeviceObject, IrpContext->Irp); IrpContext->Irp = NULL; return Status; }
/********************************************************************** * * ExampleFilter_Close * * This is called when an instance of this driver is closed (CloseHandle) * **********************************************************************/ NTSTATUS ExampleFilter_Close(PDEVICE_OBJECT DeviceObject, PIRP Irp) { NTSTATUS NtStatus = STATUS_SUCCESS; PEXAMPLE_FILTER_EXTENSION pExampleFilterDeviceContext = (PEXAMPLE_FILTER_EXTENSION)DeviceObject->DeviceExtension; PIO_STACK_LOCATION pIoStackIrp = NULL; DbgPrint("ExampleFilter_Close Called \r\n"); /* * We do not want to process this IRP, we simply want to send it down to the next driver. * We use IoSkipCurrentIrpStackLocation() since we do not want to set a completion routine. * * We should not complete this IRP! Once we pass it down we must forget about it. */ IoSkipCurrentIrpStackLocation(Irp); /* * IoCallDriver() simply calls the appropriate entry point in the driver object associated * with the device object. This is how drivers are basically "chained" together, they must know * that there are lower driver so they can perform the appropriate action and send down the IRP. * * They do not have to send the IRP down they could simply process it completely themselves if they wish. */ NtStatus = IoCallDriver(pExampleFilterDeviceContext->pNextDeviceInChain, Irp); DbgPrint("ExampleFilter_Close Exit 0x%0x \r\n", NtStatus); return NtStatus; }
static NTSTATUS vboxUsbPnPMnRemoveDevice(PVBOXUSBDEV_EXT pDevExt, PIRP pIrp) { ENMVBOXUSB_PNPSTATE enmState = vboxUsbPnPStateGet(pDevExt); NTSTATUS Status = STATUS_SUCCESS; if (enmState != ENMVBOXUSB_PNPSTATE_SURPRISE_REMOVED) { Status = vboxUsbPnPRmDev(pDevExt); Assert(Status == STATUS_SUCCESS); } vboxUsbPnPStateSet(pDevExt, ENMVBOXUSB_PNPSTATE_REMOVED); vboxUsbDdiStateRelease(pDevExt); vboxUsbDdiStateReleaseAndWaitRemoved(pDevExt); vboxUsbRtClear(pDevExt); pIrp->IoStatus.Status = STATUS_SUCCESS; pIrp->IoStatus.Information = 0; IoSkipCurrentIrpStackLocation(pIrp); Status = IoCallDriver(pDevExt->pLowerDO, pIrp); IoDetachDevice(pDevExt->pLowerDO); IoDeleteDevice(pDevExt->pFDO); return Status; }
NTSTATUS PassThruPnp( IN PDEVICE_OBJECT fdo, IN PIRP Irp) { DebugPrint("PnP %I",Irp); PPASSTHRU_DEVICE_EXTENSION dx=(PPASSTHRU_DEVICE_EXTENSION)fdo->DeviceExtension; // Remember minor function PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp); ULONG MinorFunction = IrpStack->MinorFunction; // Just pass to lower driver IoSkipCurrentIrpStackLocation(Irp); NTSTATUS status = IoCallDriver( dx->NextStackDevice, Irp); // Device removed if( MinorFunction==IRP_MN_REMOVE_DEVICE) { DebugPrint("PnP RemoveDevice"); // disable device interface IoSetDeviceInterfaceState(&dx->ifSymLinkName, FALSE); RtlFreeUnicodeString(&dx->ifSymLinkName); // unattach from stack if (dx->NextStackDevice) IoDetachDevice(dx->NextStackDevice); // delete our fdo IoDeleteDevice(fdo); } return status; }
//======================================================================================== // Function: PassIRP // Purpose: Free all the allocated resources, etc. // Return Value: // NT status code //======================================================================================== NTSTATUS PassIRP( IN PDEVICE_OBJECT fido, IN PIRP irp // Irp - pointer to an I/O Request Packet. ) { PDEVICE_EXTENSION dx; NTSTATUS ntStatus; dx = (PDEVICE_EXTENSION)fido->DeviceExtension; // acquire remove lock ntStatus = IoAcquireRemoveLock(&dx->rmLock, irp); if (!NT_SUCCESS(ntStatus)) { //complete irp if cannot acquire remove lock irp->IoStatus.Status=ntStatus; irp->IoStatus.Information=0; IoCompleteRequest(irp, IO_NO_INCREMENT); return ntStatus; } IoSkipCurrentIrpStackLocation(irp); ntStatus = IoCallDriver(dx->lowerdo, irp); IoReleaseRemoveLock(&dx->rmLock, irp); return ntStatus; }
NTSTATUS DkDefault(PDEVICE_OBJECT pDevObj, PIRP pIrp) { NTSTATUS ntStat = STATUS_SUCCESS; PDEVICE_EXTENSION pDevExt = NULL; PIO_STACK_LOCATION pStack = NULL; PDEVICE_OBJECT pNextDevObj = NULL; pDevExt = (PDEVICE_EXTENSION) pDevObj->DeviceExtension; ntStat = IoAcquireRemoveLock(&pDevExt->removeLock, (PVOID) pIrp); if (!NT_SUCCESS(ntStat)) { DkDbgVal("Error acquire lock!", ntStat); DkCompleteRequest(pIrp, ntStat, 0); return ntStat; } pStack = IoGetCurrentIrpStackLocation(pIrp); DkDbgVal("DkDefault", pStack->MajorFunction); pNextDevObj = pDevExt->pNextDevObj; IoSkipCurrentIrpStackLocation(pIrp); ntStat = IoCallDriver(pNextDevObj, pIrp); IoReleaseRemoveLock(&pDevExt->removeLock, (PVOID) pIrp); return ntStat; }
DECLHIDDEN(NTSTATUS) vboxUsbDispatchPower(IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp) { PVBOXUSBDEV_EXT pDevExt = (PVBOXUSBDEV_EXT)pDeviceObject->DeviceExtension; ENMVBOXUSB_PNPSTATE enmState = vboxUsbDdiStateRetainIfNotRemoved(pDevExt); switch (enmState) { case ENMVBOXUSB_PNPSTATE_REMOVED: { PoStartNextPowerIrp(pIrp); pIrp->IoStatus.Status = STATUS_DELETE_PENDING; pIrp->IoStatus.Information = 0; IoCompleteRequest(pIrp, IO_NO_INCREMENT); vboxUsbDdiStateRelease(pDevExt); return STATUS_DELETE_PENDING; } case ENMVBOXUSB_PNPSTATE_START_PENDING: { PoStartNextPowerIrp(pIrp); IoSkipCurrentIrpStackLocation(pIrp); vboxUsbDdiStateRelease(pDevExt); return PoCallDriver(pDevExt->pLowerDO, pIrp); } default: { return vboxUsbPwrDispatch(pDevExt, pIrp); } } }
static NTSTATUS vboxUsbPwrQueryPowerDev(IN PVBOXUSBDEV_EXT pDevExt, IN PIRP pIrp) { PIO_STACK_LOCATION pSl = IoGetCurrentIrpStackLocation(pIrp); DEVICE_POWER_STATE enmDevPState = pSl->Parameters.Power.State.DeviceState; NTSTATUS Status = STATUS_SUCCESS; if (enmDevPState >= pDevExt->DdiState.PwrState.PowerState.DeviceState) { Status = vboxUsbPwrIoWaitCompletionAndPostAsync(pDevExt, pIrp); Assert(NT_SUCCESS(Status)); if (NT_SUCCESS(Status)) return Status; } pIrp->IoStatus.Status = Status; pIrp->IoStatus.Information = 0; PoStartNextPowerIrp(pIrp); if (NT_SUCCESS(Status)) { IoSkipCurrentIrpStackLocation(pIrp); Status = PoCallDriver(pDevExt->pLowerDO, pIrp); } else { IoCompleteRequest(pIrp, IO_NO_INCREMENT); } vboxUsbDdiStateRelease(pDevExt); return Status; }
NTSTATUS NTAPI PciPassIrpFromFdoToPdo(IN PPCI_FDO_EXTENSION DeviceExtension, IN PIRP Irp) { PIO_STACK_LOCATION IoStackLocation; NTSTATUS Status; DPRINT1("Pci PassIrp ...\n"); /* Get the stack location to check which function this is */ IoStackLocation = IoGetCurrentIrpStackLocation(Irp); if (IoStackLocation->MajorFunction == IRP_MJ_POWER) { /* Power IRPs are special since we have to notify the Power Manager */ IoCopyCurrentIrpStackLocationToNext(Irp); PoStartNextPowerIrp(Irp); Status = PoCallDriver(DeviceExtension->AttachedDeviceObject, Irp); } else { /* For a normal IRP, just call the next driver in the stack */ IoSkipCurrentIrpStackLocation(Irp); Status = IoCallDriver(DeviceExtension->AttachedDeviceObject, Irp); } /* Return the status back to the caller */ return Status; }
NTSTATUS NTAPI USBSTOR_DispatchPower( PDEVICE_OBJECT DeviceObject, PIRP Irp) { PFDO_DEVICE_EXTENSION DeviceExtension; // get common device extension DeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; if (DeviceExtension->Common.IsFDO) { PoStartNextPowerIrp(Irp); IoSkipCurrentIrpStackLocation(Irp); return PoCallDriver(DeviceExtension->LowerDeviceObject, Irp); } else { PoStartNextPowerIrp(Irp); Irp->IoStatus.Status = STATUS_SUCCESS; IoCompleteRequest(Irp, IO_NO_INCREMENT); return STATUS_SUCCESS; } }
NTSTATUS my_ioctl_push(PDEVICE_OBJECT deviceObject, PIRP Irp) { NTSTATUS status = STATUS_SUCCESS; DbgPrint("my_ioctl_push called\n"); PCHAR c = (PCHAR) Irp->AssociatedIrp.SystemBuffer; char old = *c; if (*c >= 97 && *c <= 97 + 26) { *c -= 32; DbgPrint("Translate: %d=>%c\n", old, *c); } else { DbgPrint("Error: input is not lower case: %c\n", *c); status = STATUS_UNSUCCESSFUL; Irp->IoStatus.Information = 0; goto cleanup; } IoSkipCurrentIrpStackLocation(Irp); device_extension_t* device_extension = (device_extension_t*) deviceObject->DeviceExtension; status = IoCallDriver(device_extension->next, Irp); cleanup: return status; }
//@@@@@@@@@@@@@@@@@@@@@@@@ // IRQL = passive level //@@@@@@@@@@@@@@@@@@@@@@@@@ NTSTATUS DispatchPassDown(IN PDEVICE_OBJECT pDeviceObject, IN PIRP pIrp ) { DbgPrint("Entering DispatchPassDown Routine...\n"); //pass the irp down to the target without touching it IoSkipCurrentIrpStackLocation(pIrp); return IoCallDriver(((PDEVICE_EXTENSION) pDeviceObject->DeviceExtension)->pKeyboardDevice ,pIrp); }//end DriverDispatcher
//======================================================================================== // Function: DispatchPower // Purpose: This routine is the dispatch routine for power irps. // Does nothing except forwarding the IRP to the next device in the stack. // Return Value: // NT status code //======================================================================================== NTSTATUS DispatchPower( IN PDEVICE_OBJECT fido, // fido - Pointer to the device object. IN PIRP irp // Irp - Pointer to the request packet. ) { PDEVICE_EXTENSION dx; NTSTATUS ntStatus; dx = (PDEVICE_EXTENSION)fido->DeviceExtension; PoStartNextPowerIrp(irp); //acquire remove lock ntStatus=IoAcquireRemoveLock(&dx->rmLock, irp); if (!NT_SUCCESS(ntStatus)) { //complete irp if cannot acquire remove lock irp->IoStatus.Status=ntStatus; irp->IoStatus.Information=0; IoCompleteRequest(irp, IO_NO_INCREMENT); return ntStatus; } IoSkipCurrentIrpStackLocation(irp); ntStatus = PoCallDriver(dx->lowerdo, irp); IoReleaseRemoveLock(&dx->rmLock, irp); return ntStatus; }
NTSTATUS FDO_HandleInternalDeviceControl( PDEVICE_OBJECT DeviceObject, PIRP Irp) { PIO_STACK_LOCATION IoStack; NTSTATUS Status; PFDO_DEVICE_EXTENSION FDODeviceExtension; /* Get device extension */ FDODeviceExtension = (PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension; ASSERT(FDODeviceExtension->Common.IsFDO); /* Get stack location */ IoStack = IoGetCurrentIrpStackLocation(Irp); if (IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_RESET_PORT || IoStack->Parameters.DeviceIoControl.IoControlCode == IOCTL_INTERNAL_USB_CYCLE_PORT) { /* Handle reset / cycle ports */ Status = FDO_HandleResetCyclePort(DeviceObject, Irp); DPRINT("FDO_HandleResetCyclePort Status %x\n", Status); if (Status != STATUS_PENDING) { /* Complete request */ Irp->IoStatus.Status = Status; IoCompleteRequest(Irp, IO_NO_INCREMENT); } return Status; } /* Forward and forget request */ IoSkipCurrentIrpStackLocation(Irp); return IoCallDriver(FDODeviceExtension->NextDeviceObject, Irp); }
// system control NTSTATUS AppleKeyboardSystemControl(__in PDEVICE_OBJECT pDeviceObject,__in PIRP pIrp) { CDeviceExtension* pDevExt = static_cast<CDeviceExtension*>(pDeviceObject->DeviceExtension); AppleDebugPrint(DBGLEVEL_INFO,"Enter AppleKeyboardSystemControl %p,%p\n",pDeviceObject,pIrp); SYSCTL_IRP_DISPOSITION disposition; NTSTATUS statusRet = WmiSystemControl(&pDevExt->m_wmiLibContext,pDeviceObject,pIrp,&disposition); switch(disposition) { case IrpProcessed: break; case IrpNotCompleted: IoCompleteRequest(pIrp,IO_NO_INCREMENT); break; case IrpNotWmi: case IrpForward: IoSkipCurrentIrpStackLocation(pIrp); statusRet = IoCallDriver(pDevExt->m_pLowerDevice,pIrp); break; default: ASSERT(FALSE); break; } AppleDebugPrint(DBGLEVEL_INFO,"Leave AppleKeyboardSystemControl 0x%08x\n",statusRet); return statusRet; }
NTSTATUS NTAPI CompBattSystemControl(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { PCOMPBATT_DEVICE_EXTENSION DeviceExtension = DeviceObject->DeviceExtension; NTSTATUS Status; PAGED_CODE(); if (CompBattDebug & 1) DbgPrint("CompBatt: ENTERING System Control\n"); /* Are we attached yet? */ if (DeviceExtension->AttachedDevice) { /* Send it up the stack */ IoSkipCurrentIrpStackLocation(Irp); Status = IoCallDriver(DeviceExtension->AttachedDevice, Irp); } else { /* We don't support WMI */ Status = STATUS_NOT_SUPPORTED; Irp->IoStatus.Status = STATUS_NOT_SUPPORTED; IoCompleteRequest(Irp, IO_NO_INCREMENT); } /* Return status */ return Status; }
static NTSTATUS NTAPI PopRequestPowerIrpCompletion(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context) { PIO_STACK_LOCATION Stack; PREQUEST_POWER_COMPLETE CompletionRoutine; POWER_STATE PowerState; Stack = IoGetCurrentIrpStackLocation(Irp); CompletionRoutine = Context; PowerState.DeviceState = (ULONG_PTR)Stack->Parameters.Others.Argument3; CompletionRoutine(Stack->Parameters.Others.Argument1, (UCHAR)(ULONG_PTR)Stack->Parameters.Others.Argument2, PowerState, Stack->Parameters.Others.Argument4, &Irp->IoStatus); IoSkipCurrentIrpStackLocation(Irp); IoFreeIrp(Irp); ObDereferenceObject(DeviceObject); return STATUS_MORE_PROCESSING_REQUIRED; }
NTSTATUS c0cPowerDispatch(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp) { NTSTATUS status; PC0C_COMMON_EXTENSION pDevExt = pDevObj->DeviceExtension; HALT_UNLESS2(IoGetCurrentIrpStackLocation(pIrp)->MajorFunction == IRP_MJ_POWER, IoGetCurrentIrpStackLocation(pIrp)->MajorFunction, IoGetCurrentIrpStackLocation(pIrp)->MinorFunction); TraceIrp("POWER", pIrp, NULL, TRACE_FLAG_PARAMS); switch (pDevExt->doType) { case C0C_DOTYPE_FB: case C0C_DOTYPE_FP: PoStartNextPowerIrp(pIrp); IoSkipCurrentIrpStackLocation(pIrp); status = PoCallDriver(((PC0C_COMMON_FDO_EXTENSION)pDevExt)->pLowDevObj, pIrp); break; case C0C_DOTYPE_PP: status = PdoPortPower((PC0C_PDOPORT_EXTENSION)pDevExt, pIrp); break; default: status = STATUS_NO_SUCH_DEVICE; pIrp->IoStatus.Status = status; IoCompleteRequest(pIrp, IO_NO_INCREMENT); } return status; }
NTSTATUS MouFilter_Power( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp ) /*++ Routine Description: This routine is the dispatch routine for power irps Does nothing except record the state of the device. Arguments: DeviceObject - Pointer to the device object. Irp - Pointer to the request packet. Return Value: Status is returned. --*/ { PIO_STACK_LOCATION irpStack; PDEVICE_EXTENSION devExt; POWER_STATE powerState; POWER_STATE_TYPE powerType; PAGED_CODE(); DbgPrint(("MouFilter_Power() called\n")); devExt = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension; irpStack = IoGetCurrentIrpStackLocation(Irp); powerType = irpStack->Parameters.Power.Type; powerState = irpStack->Parameters.Power.State; switch (irpStack->MinorFunction) { case IRP_MN_SET_POWER: if (powerType == DevicePowerState) { devExt->DeviceState = powerState.DeviceState; } case IRP_MN_QUERY_POWER: case IRP_MN_WAIT_WAKE: case IRP_MN_POWER_SEQUENCE: default: break; } // The PoStartNextPowerIrp routine signals the power manager that the driver is ready to handle the next power IRP. // This routine must be called by every driver in the device stack - from the April 2005 MSDN Library PoStartNextPowerIrp(Irp); IoSkipCurrentIrpStackLocation(Irp); return PoCallDriver(devExt->TopOfStack, Irp); }
static NTSTATUS bus_pnp(control_device_extension* cde, PIRP Irp) { PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(Irp); switch (IrpSp->MinorFunction) { case IRP_MN_QUERY_CAPABILITIES: bus_query_capabilities(Irp); break; case IRP_MN_QUERY_DEVICE_RELATIONS: if (IrpSp->Parameters.QueryDeviceRelations.Type != BusRelations || no_pnp) break; return bus_query_device_relations(Irp); case IRP_MN_QUERY_ID: { NTSTATUS Status; if (IrpSp->Parameters.QueryId.IdType != BusQueryHardwareIDs) break; Status = bus_query_hardware_ids(Irp); Irp->IoStatus.Status = Status; IoCompleteRequest(Irp, IO_NO_INCREMENT); return Status; } } IoSkipCurrentIrpStackLocation(Irp); return IoCallDriver(cde->attached_device, Irp); }
NTSTATUS USBSTOR_FdoHandleRemoveDevice( IN PDEVICE_OBJECT DeviceObject, IN PFDO_DEVICE_EXTENSION DeviceExtension, IN OUT PIRP Irp) { NTSTATUS Status; ULONG Index; DPRINT("Handling FDO removal %p\n", DeviceObject); /* FIXME: wait for devices finished processing */ for(Index = 0; Index < 16; Index++) { if (DeviceExtension->ChildPDO[Index] != NULL) { DPRINT("Deleting PDO %p RefCount %x AttachedDevice %p \n", DeviceExtension->ChildPDO[Index], DeviceExtension->ChildPDO[Index]->ReferenceCount, DeviceExtension->ChildPDO[Index]->AttachedDevice); IoDeleteDevice(DeviceExtension->ChildPDO[Index]); } } /* Send the IRP down the stack */ IoSkipCurrentIrpStackLocation(Irp); Status = IoCallDriver(DeviceExtension->LowerDeviceObject, Irp); /* Detach from the device stack */ IoDetachDevice(DeviceExtension->LowerDeviceObject); /* Delete the device object */ IoDeleteDevice(DeviceObject); return Status; }
static NTSTATUS NTAPI TestDispatch( IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp) { NTSTATUS Status = STATUS_SUCCESS; PIO_STACK_LOCATION IoStackLocation; PAGED_CODE(); IoStackLocation = IoGetCurrentIrpStackLocation(Irp); DPRINT("TestIrpHandler. Function=%s, DeviceObject=%p, AttachDeviceObject=%p\n", KmtMajorFunctionNames[IoStackLocation->MajorFunction], DeviceObject, AttachDeviceObject); if (AttachDeviceObject) { IoSkipCurrentIrpStackLocation(Irp); Status = IoCallDriver(AttachDeviceObject, Irp); return Status; } TestDriverObject(DeviceObject->DriverObject, DriverIrp); Irp->IoStatus.Status = Status; Irp->IoStatus.Information = 0; IoCompleteRequest(Irp, IO_NO_INCREMENT); return Status; }
NTSTATUS RemoveDevice( __in PDEVICE_OBJECT DeviceObject, __in PIRP Irp ) { PDEVICE_EXTENSION pdx; NTSTATUS status; pdx = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension; status = DisconnectEvtchnInterface(DeviceObject); pdx->StoreInterface = NULL; pdx->EvtchnInterface = NULL; Irp->IoStatus.Status = STATUS_SUCCESS; IoSkipCurrentIrpStackLocation(Irp); status = IoCallDriver(pdx->LowerDeviceObject, Irp); IoDetachDevice(pdx->LowerDeviceObject); IoDeleteDevice(DeviceObject); return status; }
static NTSTATUS NTAPI V4vDispatchWmi(PDEVICE_OBJECT fdo, PIRP irp) { NTSTATUS status; PXENV4V_EXTENSION pde = V4vGetDeviceExtension(fdo); TraceVerbose(("====> '%s'.\n", __FUNCTION__)); // We don't support WMI, so just pass it on down the stack status = IoAcquireRemoveLock(&pde->removeLock, irp); if (!NT_SUCCESS(status)) { TraceError(("failed to acquire IO lock - error: 0x%x\n", status)); return V4vSimpleCompleteIrp(irp, status); } IoSkipCurrentIrpStackLocation(irp); status = IoCallDriver(pde->ldo, irp); IoReleaseRemoveLock(&pde->removeLock, irp); TraceVerbose(("<==== '%s'.\n", __FUNCTION__)); return status; }