summaryrefslogtreecommitdiff
path: root/tools/dv/samples/DV-FailDriver-WDM/defect_toastmon.h
blob: c70d53d8d51f60df8b371b2a276955147479a135 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*++

Copyright (c) 1990-2000 Microsoft Corporation, All Rights Reserved

Module Name:

    defect_toastmon.h

Abstract:


Environment:

    Kernel mode

Revision History:

--*/
#include <ntddk.h>
#include <dontuse.h>

#if     !defined(__TOASTMON_H__)
#define __TOASTMON_H__

#define DRIVER_TAG 'NOMT'

#define INITIALIZE_PNP_STATE(_Data_)    \
        (_Data_)->DevicePnPState =  NotStarted;\
        (_Data_)->PreviousPnPState = NotStarted;

#define SET_NEW_PNP_STATE(_Data_, _state_) \
        (_Data_)->PreviousPnPState =  (_Data_)->DevicePnPState;\
        (_Data_)->DevicePnPState = (_state_);

#define RESTORE_PREVIOUS_PNP_STATE(_Data_)   \
        (_Data_)->DevicePnPState =   (_Data_)->PreviousPnPState;\
//
// These are the states a PDO or FDO transition upon
// receiving a specific PnP Irp. Refer to the PnP Device States
// diagram in DDK documentation for better understanding.
//

typedef enum _DEVICE_PNP_STATE {

    NotStarted = 0,         // Not started yet
    Started,                // Device has received the START_DEVICE IRP
    StopPending,            // Device has received the QUERY_STOP IRP
    Stopped,                // Device has received the STOP_DEVICE IRP
    RemovePending,          // Device has received the QUERY_REMOVE IRP
    SurpriseRemovePending,  // Device has received the SURPRISE_REMOVE IRP
    Deleted,                // Device has received the REMOVE_DEVICE IRP
    UnKnown                 // Unknown state

} DEVICE_PNP_STATE;


typedef struct _DEVICE_EXTENSION {
    PDEVICE_OBJECT          DeviceObject; // The Defect_ToastMon device object.
    PDEVICE_OBJECT          TopOfStack;   // The top of the stack
    DEVICE_PNP_STATE        DevicePnPState; // Track PnP state
    DEVICE_PNP_STATE        PreviousPnPState;
    IO_REMOVE_LOCK          RemoveLock;   //
	KSPIN_LOCK              deviceSpinlock; // device wide spinlock    
    PVOID                   NotificationHandle; // Interface notification handle
    LIST_ENTRY              DeviceListHead; // List to queue the target device info
    FAST_MUTEX              ListMutex;    // Synchronize access to DeviceList
    PVOID		            WMIDeviceArrivalNotificationObject;
	LIST_ENTRY              RecvQueueHead;
    KSPIN_LOCK              RecvQueueLock;
    KSPIN_LOCK              RcvLock;
	KSPIN_LOCK              ToasterpCancelSpinLock;
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;


typedef struct _DEVICE_INFO {
    PDEVICE_EXTENSION    DeviceExtension; // Our FDO device extension
    PDEVICE_OBJECT      TargetDeviceObject; // Toplevel deviceobject of the target device
    PDEVICE_OBJECT      Pdo;          // It's PDO
    PFILE_OBJECT        FileObject;
    PVOID                NotificationHandle; //Device change notification handle
    LIST_ENTRY            ListEntry; // Entry to chain to the listhead
    UNICODE_STRING        SymbolicLink;
} DEVICE_INFO, *PDEVICE_INFO;


#if DBG
#define DebugPrint(_x_) \
               DbgPrint ("Defect_ToastMon:"); \
               DbgPrint _x_;

#define TRAP() DbgBreakPoint()

#else
#define DebugPrint(_x_)
#define TRAP()
#endif


/********************* function prototypes ***********************************/
//

DRIVER_INITIALIZE DriverEntry;

DRIVER_ADD_DEVICE Defect_ToastMon_AddDevice;

__drv_dispatchType(IRP_MJ_CREATE)
__drv_dispatchType(IRP_MJ_CLOSE)
__drv_dispatchType(IRP_MJ_DEVICE_CONTROL)
DRIVER_DISPATCH Defect_ToastMon_Dispatch;

__drv_dispatchType(IRP_MJ_PNP)
DRIVER_DISPATCH Defect_ToastMon_DispatchPnp;

__drv_dispatchType(IRP_MJ_POWER)
DRIVER_DISPATCH Defect_ToastMon_DispatchPower;

DRIVER_DISPATCH Defect_ToastMon_StartDevice;

__drv_dispatchType(IRP_MJ_SYSTEM_CONTROL)
DRIVER_DISPATCH Defect_ToastMon_DispatchSystemControl;

DRIVER_UNLOAD Defect_ToastMon_Unload;

IO_COMPLETION_ROUTINE Defect_ToastMon_CompletionRoutine;

DRIVER_NOTIFICATION_CALLBACK_ROUTINE Defect_ToastMon_PnpNotifyDeviceChange;

DRIVER_NOTIFICATION_CALLBACK_ROUTINE Defect_ToastMon_PnpNotifyInterfaceChange;

NTSTATUS
Defect_ToastMon_GetTargetDevicePdo(
    __in PDEVICE_OBJECT DeviceObject,
    __out PDEVICE_OBJECT* PhysicalDeviceObject
    );

NTSTATUS
Defect_ToastMon_OpenTargetDevice(
    __in PDEVICE_INFO        List
    );

__drv_arg(List->SymbolicLink.Buffer, __drv_freesMem(SymLink))
VOID
Defect_ToastMon_CloseTargetDevice(
    __in __drv_freesMem(List) PDEVICE_INFO        List
    );

PCHAR
PnPMinorFunctionString (
    __in UCHAR MinorFunction
);

NTSTATUS
RegisterForWMINotification(
    __in PDEVICE_EXTENSION DeviceExt
    );

VOID
UnregisterForWMINotification(
    __in PDEVICE_EXTENSION DeviceExt
);

FWMI_NOTIFICATION_CALLBACK WmiNotificationCallback;


DRIVER_CANCEL Defect_ToastmonCancelRoutineForReadIrp;

__drv_dispatchType(IRP_MJ_READ)
DRIVER_DISPATCH Defect_ToastMon_DispatchRead;

VOID
ToasterDrvCancelQueuedReadIrps(
    PDEVICE_EXTENSION       deviceExtension
    );
#endif