driver.c
Go to the documentation of this file.
1 /*
2  * Bareflank Hypervisor
3  *
4  * Copyright (C) 2015 Assured Information Security, Inc.
5  * Author: Rian Quinn <quinnr@ainfosec.com>
6  * Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include <debug.h>
24 #include <driver.h>
25 #include <driver.tmh>
26 
27 NTSTATUS
29  _In_ PDRIVER_OBJECT DriverObject,
30  _In_ PUNICODE_STRING RegistryPath
31 )
32 {
33  NTSTATUS status;
34  WDF_DRIVER_CONFIG config;
35  WDF_OBJECT_ATTRIBUTES attributes;
36 
37  WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
38  attributes.EvtCleanupCallback = bareflankEvtDriverContextCleanup;
39 
40  WDF_DRIVER_CONFIG_INIT(&config, bareflankEvtDeviceAdd);
41 
42  status = WdfDriverCreate(DriverObject, RegistryPath, &attributes, &config, WDF_NO_HANDLE);
43  if (!NT_SUCCESS(status))
44  return status;
45 
46  DEBUG("DriverEntry: success\n");
47  return STATUS_SUCCESS;
48 }
49 
50 NTSTATUS
52  _In_ WDFDRIVER Driver,
53  _Inout_ PWDFDEVICE_INIT DeviceInit
54 )
55 {
56  NTSTATUS status;
57  WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks;
58 
59  UNREFERENCED_PARAMETER(Driver);
60 
61  WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks);
62  pnpPowerCallbacks.EvtDeviceD0Entry = bareflankEvtDeviceD0Entry;
63  pnpPowerCallbacks.EvtDeviceD0Exit = bareflankEvtDeviceD0Exit;
64 
65  WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks);
66 
67  status = bareflankCreateDevice(DeviceInit);
68  if (!NT_SUCCESS(status))
69  return status;
70 
71  DEBUG("bareflankEvtDeviceAdd: success\n");
72  return STATUS_SUCCESS;
73 }
74 
75 VOID
77  _In_ WDFOBJECT DriverObject
78 )
79 {
80  UNREFERENCED_PARAMETER(DriverObject);
81 
82  common_fini();
83 
84  DEBUG("bareflankEvtDriverContextCleanup: success\n");
85 }
86 
87 NTSTATUS
89  _In_ WDFDEVICE Device,
90  _In_ WDF_POWER_DEVICE_STATE PreviousState
91 )
92 {
93  UNREFERENCED_PARAMETER(Device);
94  UNREFERENCED_PARAMETER(PreviousState);
95 
96  DEBUG("bareflankEvtDeviceD0Entry: success\n");
97  return STATUS_SUCCESS;
98 }
99 
100 NTSTATUS
102  _In_ WDFDEVICE Device,
103  _In_ WDF_POWER_DEVICE_STATE TargetState
104 )
105 {
106  UNREFERENCED_PARAMETER(Device);
107  UNREFERENCED_PARAMETER(TargetState);
108 
109  common_fini();
110 
111  DEBUG("bareflankEvtDeviceD0Entry: success\n");
112  return STATUS_SUCCESS;
113 }
int64_t common_fini(void)
Definition: common.c:273
NTSTATUS bareflankEvtDeviceD0Entry(_In_ WDFDEVICE Device, _In_ WDF_POWER_DEVICE_STATE PreviousState)
Definition: driver.c:88
NTSTATUS bareflankCreateDevice(_Inout_ PWDFDEVICE_INIT DeviceInit)
Definition: device.c:27
NTSTATUS bareflankEvtDeviceAdd(_In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT DeviceInit)
Definition: driver.c:51
#define DEBUG(...)
Definition: debug.h:155
NTSTATUS DriverEntry(_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
Definition: driver.c:28
NTSTATUS bareflankEvtDeviceD0Exit(_In_ WDFDEVICE Device, _In_ WDF_POWER_DEVICE_STATE TargetState)
Definition: driver.c:101
VOID bareflankEvtDriverContextCleanup(_In_ WDFOBJECT DriverObject)
Definition: driver.c:76