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
|
/*++
Copyright (c) Microsoft Corporation. All rights reserved.
Module Name:
device.c
Abstract:
This file contains the device entry points and callbacks.
Environment:
Windows User-Mode Driver Framework
--*/
#include "precomp.h"
#include "Trace.h"
#include "Defaults.h"
#include "Device.h"
#include "FixSession.h"
#include "FixHandler.h"
#include "Queue.h"
#include "Device.tmh"
CDevice::CDevice(
_In_ WDFDEVICE Device
) :
_Device(Device),
_Queue(nullptr)
{
}
CDevice::~CDevice()
{
if (_Queue != nullptr)
{
_Queue = nullptr;
}
}
CQueue*
CDevice::GetQueue()
{
return _Queue;
}
NTSTATUS
CDevice::OnDeviceAdd(
_In_ WDFDRIVER /*Driver*/,
_Inout_ PWDFDEVICE_INIT DeviceInit
)
{
NTSTATUS status = STATUS_SUCCESS;
WDF_PNPPOWER_EVENT_CALLBACKS powerCallbacks;
WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&powerCallbacks);
powerCallbacks.EvtDeviceD0Entry = CDevice::OnD0Entry;
powerCallbacks.EvtDeviceD0Exit = CDevice::OnD0Exit;
WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &powerCallbacks);
WDF_OBJECT_ATTRIBUTES deviceAttributes;
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&deviceAttributes,
CDevice);
deviceAttributes.EvtCleanupCallback = CDevice::OnCleanup;
deviceAttributes.SynchronizationScope = WdfSynchronizationScopeNone;
deviceAttributes.ExecutionLevel = WdfExecutionLevelPassive;
WDFDEVICE device;
status = WdfDeviceCreate(&DeviceInit, &deviceAttributes, &device);
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "WdfDeviceCreate failed with Status %!STATUS!", status);
goto Exit;
}
// Construct device object on the preallocated buffer using placement 'new'
CDevice* pDevice = new (GetDeviceObject(device)) CDevice(device);
status = pDevice->Initialize();
Exit:
return status;
}
NTSTATUS
CDevice::Initialize()
{
NTSTATUS status = STATUS_SUCCESS;
status = CQueue::AddQueueToDevice(_Device, &_Queue);
// Register GNSS Device interface. Note that this sample is not publishing a symbolic link.
status = WdfDeviceCreateDeviceInterface(_Device,
(LPGUID)&GUID_DEVINTERFACE_GNSS,
nullptr);
if (!NT_SUCCESS(status))
{
TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "WdfDeviceCreateDeviceInterface failed with %!STATUS!", status);
goto Exit;
}
Exit:
return status;
}
void
CDevice::OnCleanup(
_In_ WDFOBJECT Object
)
{
CDevice *pDevice = GetDeviceObject(Object);
// Device object constructed using placement 'new' so explicitly invoke destructor
pDevice->~CDevice();
}
NTSTATUS
CDevice::OnD0Entry(
_In_ WDFDEVICE /*Device*/,
_In_ WDF_POWER_DEVICE_STATE /*PreviousState*/
)
{
NTSTATUS status;
//
// FIX ME:
// Add further functionality.
// Refer to power consideration from MSDN document: https://docs.microsoft.com/en-us/windows-hardware/drivers/gnss/gnss-driver-requirements
//
status = STATUS_SUCCESS;
return status;
}
NTSTATUS
CDevice::OnD0Exit(
_In_ WDFDEVICE /*Device*/,
_In_ WDF_POWER_DEVICE_STATE /*TargetState*/
)
{
NTSTATUS status;
//
// FIX ME:
// Add further functionality.
// Refer to power consideration from MSDN document: https://docs.microsoft.com/en-us/windows-hardware/drivers/gnss/gnss-driver-requirements
//
status = STATUS_SUCCESS;
return status;
}
|