1 /*++
2 
3 Copyright (c) Microsoft Corporation
4 
5 Module Name:
6 
7     FxDefaultIrpHandler.cpp
8 
9 Abstract:
10 
11     This module implements the default handler for IRPs that WDF does not handle
12     automatically for an FxDevice
13 
14 Author:
15 
16 
17 
18 Environment:
19 
20     Both kernel and user mode
21 
22 Revision History:
23 
24 --*/
25 
26 #if ((FX_CORE_MODE)==(FX_CORE_USER_MODE))
27 #define FX_IS_USER_MODE (TRUE)
28 #define FX_IS_KERNEL_MODE (FALSE)
29 #elif ((FX_CORE_MODE)==(FX_CORE_KERNEL_MODE))
30 #define FX_IS_USER_MODE (FALSE)
31 #define FX_IS_KERNEL_MODE (TRUE)
32 #endif
33 
34 extern "C" {
35 #include "mx.h"
36 }
37 #include "fxmin.hpp"
38 
39 extern "C" {
40 // #include "FxDefaultIrpHandler.tmh"
41 }
42 
43 FxDefaultIrpHandler::FxDefaultIrpHandler(
44     __in PFX_DRIVER_GLOBALS FxDriverGlobals,
45     __in CfxDevice *Device
46     ) :
47     FxPackage(FxDriverGlobals, Device, FX_TYPE_DEFAULT_IRP_HANDLER)
48 {
49 }
50 
51 _Must_inspect_result_
52 NTSTATUS
53 FxDefaultIrpHandler::Dispatch(
54     __in MdIrp Irp
55     )
56 {
57     UCHAR major, minor;
58     FxIrp fxIrp(Irp);
59 
60     major = fxIrp.GetMajorFunction();
61     minor = fxIrp.GetMinorFunction();
62 
63     if (FxDevice::_RequiresRemLock(major, minor) == FxDeviceRemLockRequired) {
64         if (major == IRP_MJ_POWER) {
65             //
66             // Required to be called before the power irp is completed
67             //
68             fxIrp.StartNextPowerIrp();
69         }
70 
71         fxIrp.SetStatus(STATUS_INVALID_DEVICE_REQUEST);
72         fxIrp.SetInformation(0);
73 
74         fxIrp.CompleteRequest(IO_NO_INCREMENT);
75 
76         //
77         // If we are in this function, m_Device is still valid, so we can use it
78         // to get the WDM remove lock and not have to get it out of the
79         // device object from current irp stack location.
80         //
81         Mx::MxReleaseRemoveLock(m_Device->GetRemoveLock(), Irp);
82 
83         return STATUS_INVALID_DEVICE_REQUEST;
84     }
85 
86     if (m_Device->IsFilter()) {
87         fxIrp.SkipCurrentIrpStackLocation();
88         return fxIrp.CallDriver(m_Device->GetAttachedDevice());
89     }
90     else {
91         fxIrp.SetStatus(STATUS_INVALID_DEVICE_REQUEST);
92         fxIrp.SetInformation(0);
93 
94         fxIrp.CompleteRequest(IO_NO_INCREMENT);
95         return STATUS_INVALID_DEVICE_REQUEST;
96     }
97 }
98