summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWei Mao <[email protected]>2018-01-12 13:54:10 -0800
committerWei Mao <[email protected]>2018-01-12 13:54:10 -0800
commit80e1fd60244b1e339e75dc6ae43766f1b5c73dd9 (patch)
treedf0abc91cc52c27ec9dd024e687f7099ceb3b871
parent0990b0cbbd460336036dc6ec71cb8e2a8403e287 (diff)
Format toastmon
-rw-r--r--general/toaster/toastDrv/kmdf/toastmon/toastmon.H76
-rw-r--r--general/toaster/toastDrv/kmdf/toastmon/toastmon.RC6
-rw-r--r--general/toaster/toastDrv/kmdf/toastmon/toastmon.c206
-rw-r--r--general/toaster/toastDrv/kmdf/toastmon/wmi.c98
4 files changed, 147 insertions, 239 deletions
diff --git a/general/toaster/toastDrv/kmdf/toastmon/toastmon.H b/general/toaster/toastDrv/kmdf/toastmon/toastmon.H
index 896fc1b0..62a986a8 100644
--- a/general/toaster/toastDrv/kmdf/toastmon/toastmon.H
+++ b/general/toaster/toastDrv/kmdf/toastmon/toastmon.H
@@ -17,44 +17,46 @@ Environment:
#if !defined(__TOASTMON_H__)
#define __TOASTMON_H__
-#include <ntddk.h> //wdm.h>
-#include <wdf.h> // Driver Framework.
+#include <wdm.h>
+#include <wdf.h>
-#define DRIVER_TAG 'NOMT'
+#define DRIVER_TAG 'NOMT' // "TMON"
#define READ_BUF_SIZE 100
#define WRITE_BUF_SIZE 120
typedef struct _DEVICE_EXTENSION {
+
WDFDEVICE WdfDevice;
- WDFIOTARGET ToasterTarget;
PVOID NotificationHandle; // Interface notification handle
WDFCOLLECTION TargetDeviceCollection;
WDFWAITLOCK TargetDeviceCollectionLock;
PVOID WMIDeviceArrivalNotificationObject;
+
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DEVICE_EXTENSION, GetDeviceExtension)
typedef struct _TARGET_DEVICE_INFO {
+
PDEVICE_EXTENSION DeviceExtension; // Our FDO device extension
- LIST_ENTRY ListEntry; // Entry to chain to the listhead
WDFREQUEST ReadRequest;
WDFREQUEST WriteRequest;
WDFTIMER TimerForPostingRequests;
- //
- // Set to TRUE while the target is opened. Will be set to FALSE at query remove (for a graceful remove)
- // or removal complete (surprise removal of the target). Can be set back to TRUE if the graceful remove
+ //
+ // Set to TRUE while the target is opened. Will be set to FALSE at query remove (for a graceful remove)
+ // or removal complete (surprise removal of the target). Can be set back to TRUE if the graceful remove
// fails and the query remove is canceled.
//
// Guarded by DeviceExtension->TargetDeviceCollectionLock
- //
+ //
BOOLEAN Opened;
} TARGET_DEVICE_INFO, *PTARGET_DEVICE_INFO;
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(TARGET_DEVICE_INFO, GetTargetDeviceInfo)
+
typedef struct _TIMER_CONTEXT {
WDFIOTARGET IoTarget;
@@ -63,53 +65,36 @@ typedef struct _TIMER_CONTEXT {
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(TIMER_CONTEXT, GetTimerContext)
-#if DBG
-#define DebugPrint(_x_) \
- DbgPrint ("ToastMon:"); \
- DbgPrint _x_;
-
-#define TRAP() DbgBreakPoint()
-
-#else
-#define DebugPrint(_x_)
-#define TRAP()
-#endif
-
/********************* function prototypes ***********************************/
-//
-DRIVER_INITIALIZE DriverEntry;
-
-EVT_WDF_DRIVER_DEVICE_ADD ToastMon_EvtDeviceAdd;
-
-EVT_WDF_DEVICE_CONTEXT_CLEANUP ToastMon_EvtDeviceContextCleanup;
-
-EVT_WDF_IO_TARGET_QUERY_REMOVE ToastMon_EvtIoTargetQueryRemove;
-EVT_WDF_IO_TARGET_REMOVE_CANCELED ToastMon_EvtIoTargetRemoveCanceled;
-EVT_WDF_IO_TARGET_REMOVE_COMPLETE ToastMon_EvtIoTargetRemoveComplete;
-
-EVT_WDF_TIMER Toastmon_EvtTimerPostRequests;
-EVT_WDF_REQUEST_COMPLETION_ROUTINE Toastmon_ReadRequestCompletionRoutine;
-EVT_WDF_REQUEST_COMPLETION_ROUTINE Toastmon_WriteRequestCompletionRoutine;
-
-DRIVER_NOTIFICATION_CALLBACK_ROUTINE ToastMon_PnpNotifyInterfaceChange;
+DRIVER_INITIALIZE DriverEntry;
+EVT_WDF_DRIVER_DEVICE_ADD ToastMon_EvtDeviceAdd;
+EVT_WDF_DEVICE_CONTEXT_CLEANUP ToastMon_EvtDeviceContextCleanup;
+EVT_WDF_IO_TARGET_QUERY_REMOVE ToastMon_EvtIoTargetQueryRemove;
+EVT_WDF_IO_TARGET_REMOVE_CANCELED ToastMon_EvtIoTargetRemoveCanceled;
+EVT_WDF_IO_TARGET_REMOVE_COMPLETE ToastMon_EvtIoTargetRemoveComplete;
+EVT_WDF_TIMER Toastmon_EvtTimerPostRequests;
+EVT_WDF_REQUEST_COMPLETION_ROUTINE Toastmon_ReadRequestCompletionRoutine;
+EVT_WDF_REQUEST_COMPLETION_ROUTINE Toastmon_WriteRequestCompletionRoutine;
+DRIVER_NOTIFICATION_CALLBACK_ROUTINE ToastMon_PnpNotifyInterfaceChange;
+FWMI_NOTIFICATION_CALLBACK WmiNotificationCallback;
NTSTATUS
Toastmon_OpenDevice(
- WDFDEVICE Device,
- PUNICODE_STRING SymbolicLink,
- WDFIOTARGET *Target
+ _In_ WDFDEVICE Device,
+ _In_ PUNICODE_STRING SymbolicLink,
+ _Out_ WDFIOTARGET* Target
);
NTSTATUS
ToastMon_PostReadRequests(
- IN WDFIOTARGET IoTarget
+ WDFIOTARGET IoTarget
);
NTSTATUS
ToastMon_PostWriteRequests(
- IN WDFIOTARGET IoTarget
+ WDFIOTARGET IoTarget
);
NTSTATUS
@@ -122,7 +107,10 @@ UnregisterForWMINotification(
PDEVICE_EXTENSION DeviceExt
);
-FWMI_NOTIFICATION_CALLBACK WmiNotificationCallback;
+NTSTATUS
+GetTargetFriendlyName(
+ _In_ WDFIOTARGET Target,
+ _Out_ WDFMEMORY* TargetName
+ );
#endif
-
diff --git a/general/toaster/toastDrv/kmdf/toastmon/toastmon.RC b/general/toaster/toastDrv/kmdf/toastmon/toastmon.RC
index e1a5d4a2..ed94359d 100644
--- a/general/toaster/toastDrv/kmdf/toastmon/toastmon.RC
+++ b/general/toaster/toastDrv/kmdf/toastmon/toastmon.RC
@@ -2,11 +2,9 @@
#include <ntverp.h>
-#define VER_FILETYPE VFT_DRV
-#define VER_FILESUBTYPE VFT2_DRV_SYSTEM
+#define VER_FILETYPE VFT_DRV
+#define VER_FILESUBTYPE VFT2_DRV_SYSTEM
#define VER_FILEDESCRIPTION_STR "Toaster PnP Monitor"
#define VER_INTERNALNAME_STR "wdftoastmon.sys"
#include "common.ver"
-
- \ No newline at end of file
diff --git a/general/toaster/toastDrv/kmdf/toastmon/toastmon.c b/general/toaster/toastDrv/kmdf/toastmon/toastmon.c
index 82b2e5d3..f140e9d7 100644
--- a/general/toaster/toastDrv/kmdf/toastmon/toastmon.c
+++ b/general/toaster/toastDrv/kmdf/toastmon/toastmon.c
@@ -11,16 +11,15 @@ Module Name:
toastmon.c
-Abstract:
+Abstract:
This sample demonstrates how to register PnP event notification
for an interface class, how to open the target device in the
callback and register and respond to device change notification.
-
+
To schedule sending Read and Write requests to the target device
- the sample uses a "passive" timer. This feature enables getting
- a timer callback at PASSIVE_LEVEL without having to create and
- queue a WDFWORKITEM objects on its own.
-
+ the sample uses a "passive" timer. This feature enables getting
+ a timer callback at PASSIVE_LEVEL without having to create and
+ queue a WDFWORKITEM objects on its own.
Environment:
@@ -45,11 +44,11 @@ Environment:
#pragma alloc_text (PAGE, ToastMon_EvtIoTargetRemoveComplete)
#endif
-
+_Use_decl_annotations_
NTSTATUS
DriverEntry(
- IN PDRIVER_OBJECT DriverObject,
- IN PUNICODE_STRING RegistryPath
+ PDRIVER_OBJECT DriverObject,
+ PUNICODE_STRING RegistryPath
)
/*++
@@ -109,10 +108,11 @@ Return Value:
return status;
}
+_Use_decl_annotations_
NTSTATUS
ToastMon_EvtDeviceAdd(
- IN WDFDRIVER Driver,
- IN PWDFDEVICE_INIT DeviceInit
+ WDFDRIVER Driver,
+ PWDFDEVICE_INIT DeviceInit
)
/*++
Routine Description:
@@ -138,12 +138,12 @@ Return Value:
WDFDEVICE device;
PDEVICE_EXTENSION deviceExtension;
- KdPrint( ("ToastMon_EvtDeviceAdd routine\n"));
-
UNREFERENCED_PARAMETER(Driver);
PAGED_CODE();
+ KdPrint( ("ToastMon_EvtDeviceAdd routine\n"));
+
//
// Specify the size of device extension where we track per device
// context.
@@ -218,8 +218,7 @@ Return Value:
PNPNOTIFY_DEVICE_INTERFACE_INCLUDE_EXISTING_INTERFACES,
(PVOID)&GUID_DEVINTERFACE_TOASTER,
WdfDriverWdmGetDriverObject(WdfDeviceGetDriver(device)),
- (PDRIVER_NOTIFICATION_CALLBACK_ROUTINE)
- ToastMon_PnpNotifyInterfaceChange,
+ ToastMon_PnpNotifyInterfaceChange,
(PVOID)deviceExtension,
&deviceExtension->NotificationHandle);
@@ -228,13 +227,11 @@ Return Value:
return status;
}
- RegisterForWMINotification(deviceExtension);
+ status = RegisterForWMINotification(deviceExtension);
return status;
}
-#pragma warning(push)
-#pragma warning(disable:28118) // this callback will run at IRQL=PASSIVE_LEVEL
_Use_decl_annotations_
VOID
ToastMon_EvtDeviceContextCleanup(
@@ -263,10 +260,10 @@ Return Value:
{
PDEVICE_EXTENSION deviceExtension;
- KdPrint( ("ToastMon_EvtDeviceContextCleanup\n"));
-
PAGED_CODE();
+ KdPrint( ("ToastMon_EvtDeviceContextCleanup\n"));
+
deviceExtension = GetDeviceExtension((WDFDEVICE)Device);
//
@@ -290,14 +287,12 @@ Return Value:
return;
}
-#pragma warning(pop) // enable 28118 again
-__drv_functionClass(DRIVER_NOTIFICATION_CALLBACK_ROUTINE)
-__drv_maxIRQL(PASSIVE_LEVEL)
+_Use_decl_annotations_
NTSTATUS
ToastMon_PnpNotifyInterfaceChange(
- _In_ PVOID NotificationStruct,
- _Inout_opt_ PVOID Context
+ PVOID NotificationStruct,
+ PVOID Context
)
/*++
@@ -342,12 +337,12 @@ Return Value:
WDFIOTARGET ioTarget;
PDEVICE_INTERFACE_CHANGE_NOTIFICATION devNotificationStruct = NotificationStruct;
- _Analysis_assume_(NULL != deviceExtension);
-
PAGED_CODE();
KdPrint(("Entered ToastMon_PnpNotifyInterfaceChange\n"));
+ _Analysis_assume_(NULL != deviceExtension);
+
//
// Verify that interface class is a toaster device interface.
//
@@ -387,20 +382,19 @@ Return Value:
WdfWaitLockRelease(deviceExtension->TargetDeviceCollectionLock);
-
} else {
-
KdPrint(("Removal Interface Notification\n"));
}
+
return STATUS_SUCCESS;
}
-
+_Use_decl_annotations_
NTSTATUS
Toastmon_OpenDevice(
- WDFDEVICE Device,
+ WDFDEVICE Device,
PUNICODE_STRING SymbolicLink,
- WDFIOTARGET *Target
+ WDFIOTARGET* Target
)
/*++
@@ -417,15 +411,15 @@ Return Value:
--*/
{
- NTSTATUS status = STATUS_SUCCESS;
- PTARGET_DEVICE_INFO targetDeviceInfo = NULL;
+ NTSTATUS status;
+ PTARGET_DEVICE_INFO targetDeviceInfo;
WDF_IO_TARGET_OPEN_PARAMS openParams;
WDFIOTARGET ioTarget;
WDF_OBJECT_ATTRIBUTES attributes;
- PDEVICE_EXTENSION deviceExtension = GetDeviceExtension(Device);
+ PDEVICE_EXTENSION deviceExtension;
WDF_TIMER_CONFIG wdfTimerConfig;
-
+ deviceExtension = GetDeviceExtension(Device);
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, TARGET_DEVICE_INFO);
status = WdfIoTargetCreate(deviceExtension->WdfDevice,
@@ -458,6 +452,7 @@ Return Value:
STANDARD_RIGHTS_ALL);
openParams.ShareAccess = FILE_SHARE_WRITE | FILE_SHARE_READ;
+
//
// Framework provides default action for all of these if you don't register
// these callbacks -it will close the handle to the target when the device is
@@ -472,7 +467,6 @@ Return Value:
openParams.EvtIoTargetRemoveCanceled = ToastMon_EvtIoTargetRemoveCanceled;
openParams.EvtIoTargetRemoveComplete = ToastMon_EvtIoTargetRemoveComplete;
-
status = WdfIoTargetOpen(ioTarget, &openParams);
if (!NT_SUCCESS(status)) {
@@ -480,13 +474,13 @@ Return Value:
WdfObjectDelete(ioTarget);
return status;
}
-
+
//
- // NOTE:
+ // NOTE:
//
// These WdfIoTargetWdmGetXxxx calls can be made outside of holding TargetDeviceCollectionLock
// because we are in the interface arrival notification callback and the target cannot be
- // gracefully or surprise removed until we return back to the kernel.
+ // gracefully or surprise removed until we return back to the kernel.
//
// If the target is being opened in another context outside of interface arrival callback,
// proper synchronization between the target's state change and the API calls must be made.
@@ -529,7 +523,7 @@ Return Value:
//
WDF_TIMER_CONFIG_INIT(&wdfTimerConfig,
Toastmon_EvtTimerPostRequests);
-
+
WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&attributes, TIMER_CONTEXT);
//
@@ -546,11 +540,11 @@ Return Value:
//
// Setting the AutomaticSerialization to FALSE prevents
- // WdfTimerCreate to fail if the parent device object's
+ // WdfTimerCreate to fail if the parent device object's
// execution level is set to WdfExecutionLevelPassive.
//
wdfTimerConfig.AutomaticSerialization = FALSE;
-
+
status = WdfTimerCreate(&wdfTimerConfig,
&attributes,
&targetDeviceInfo->TimerForPostingRequests
@@ -566,8 +560,8 @@ Return Value:
//
// Start the passive timer. The first timer will be queued after 1ms interval and
- // after that it will be requeued in the timer callback function.
- // The value of 1 ms (lowest timer resoltion allowed on NT) is chosen here so
+ // after that it will be requeued in the timer callback function.
+ // The value of 1 ms (lowest timer resoltion allowed on NT) is chosen here so
// that timer would fire right away.
//
WdfTimerStart(targetDeviceInfo->TimerForPostingRequests,
@@ -586,10 +580,11 @@ Return Value:
}
+_Use_decl_annotations_
NTSTATUS
ToastMon_EvtIoTargetQueryRemove(
WDFIOTARGET IoTarget
-)
+ )
/*++
Routine Description:
@@ -610,17 +605,17 @@ Return Value:
--*/
{
- PTARGET_DEVICE_INFO targetDeviceInfo = NULL;
+ PTARGET_DEVICE_INFO targetDeviceInfo;
WDFWAITLOCK targetDeviceCollectionLock;
PAGED_CODE();
- targetDeviceInfo = GetTargetDeviceInfo(IoTarget);
-
KdPrint((("Device Removal (query remove) Notification\n")));
+ targetDeviceInfo = GetTargetDeviceInfo(IoTarget);
+
//
- // Stop the timer
+ // Stop the timer
//
WdfTimerStop(targetDeviceInfo->TimerForPostingRequests, TRUE);
@@ -637,9 +632,9 @@ Return Value:
WdfIoTargetCloseForQueryRemove(IoTarget);
return STATUS_SUCCESS;
-
}
+_Use_decl_annotations_
VOID
ToastMon_EvtIoTargetRemoveCanceled(
WDFIOTARGET IoTarget
@@ -661,10 +656,10 @@ Return Value:
--*/
{
- PTARGET_DEVICE_INFO targetDeviceInfo = NULL;
+ PTARGET_DEVICE_INFO targetDeviceInfo;
WDFWAITLOCK targetDeviceCollectionLock;
WDF_IO_TARGET_OPEN_PARAMS openParams;
- NTSTATUS status;
+ NTSTATUS status;
PAGED_CODE();
@@ -695,19 +690,18 @@ Return Value:
targetDeviceInfo->Opened = TRUE;
WdfWaitLockRelease(targetDeviceCollectionLock);
-
//
// Restart the timer.
//
WdfTimerStart(targetDeviceInfo->TimerForPostingRequests,
WDF_REL_TIMEOUT_IN_SEC(1));
-
}
+_Use_decl_annotations_
VOID
ToastMon_EvtIoTargetRemoveComplete(
WDFIOTARGET IoTarget
-)
+ )
/*++
Routine Description:
@@ -721,48 +715,45 @@ Arguments:
Return Value:
-
--*/
{
PDEVICE_EXTENSION deviceExtension;
- PTARGET_DEVICE_INFO targetDeviceInfo = NULL;
-
- KdPrint((("Device Removal (remove complete) Notification\n")));
+ PTARGET_DEVICE_INFO targetDeviceInfo;
PAGED_CODE();
+ KdPrint((("Device Removal (remove complete) Notification\n")));
+
targetDeviceInfo = GetTargetDeviceInfo(IoTarget);
deviceExtension = targetDeviceInfo->DeviceExtension;
//
- // Stop the timer
+ // Stop the timer
//
WdfTimerStop(targetDeviceInfo->TimerForPostingRequests, TRUE);
//
// Remove the target device from the collection and set Opened to FALSE to match
- // the state change (in the case of a surprise removal of the target,
+ // the state change (in the case of a surprise removal of the target,
// ToastMon_EvtIoTargetQueryRemove is not called so Opened is still TRUE).
//
WdfWaitLockAcquire(deviceExtension->TargetDeviceCollectionLock, NULL);
WdfCollectionRemove(deviceExtension->TargetDeviceCollection, IoTarget);
targetDeviceInfo->Opened = FALSE;
-
+
WdfWaitLockRelease(deviceExtension->TargetDeviceCollectionLock);
//
// Finally delete the target.
//
WdfObjectDelete(IoTarget);
-
- return;
-
}
+_Use_decl_annotations_
VOID
Toastmon_EvtTimerPostRequests(
- IN WDFTIMER Timer
+ WDFTIMER Timer
)
/*++
@@ -776,18 +767,18 @@ Return Value:
--*/
{
- PTARGET_DEVICE_INFO targetInfo;
-
- WDFIOTARGET ioTarget = GetTimerContext(Timer)->IoTarget;
+ PTARGET_DEVICE_INFO targetInfo;
+ WDFIOTARGET ioTarget;
+ ioTarget = GetTimerContext(Timer)->IoTarget;
targetInfo = GetTargetDeviceInfo(ioTarget);
//
- // Even though this routine and the completion routine check the
- // ReadRequest/WriteRequest field outside a lock, no harm is done.
- // Depending on how far the completion-routine has run, timer
- // may miss an opportunity to post a request. Even if we use a lock,
- // this race condition will still exist.
+ // Even though this routine and the completion routine check the
+ // ReadRequest/WriteRequest field outside a lock, no harm is done.
+ // Depending on how far the completion-routine has run, timer
+ // may miss an opportunity to post a request. Even if we use a lock,
+ // this race condition will still exist.
//
//
@@ -809,13 +800,12 @@ Return Value:
//
WdfTimerStart(targetInfo->TimerForPostingRequests,
WDF_REL_TIMEOUT_IN_SEC(1));
-
- return;
}
+_Use_decl_annotations_
NTSTATUS
ToastMon_PostReadRequests(
- IN WDFIOTARGET IoTarget
+ WDFIOTARGET IoTarget
)
/*++
@@ -829,12 +819,11 @@ Return Value:
--*/
{
-
- WDFREQUEST request;
- NTSTATUS status;
- PTARGET_DEVICE_INFO targetInfo;
+ WDFREQUEST request;
+ NTSTATUS status;
+ PTARGET_DEVICE_INFO targetInfo;
WDFMEMORY memory;
- WDF_OBJECT_ATTRIBUTES attributes;
+ WDF_OBJECT_ATTRIBUTES attributes;
targetInfo = GetTargetDeviceInfo(IoTarget);
@@ -893,9 +882,10 @@ Return Value:
return status;
}
+_Use_decl_annotations_
NTSTATUS
ToastMon_PostWriteRequests(
- IN WDFIOTARGET IoTarget
+ WDFIOTARGET IoTarget
)
/*++
@@ -909,12 +899,11 @@ Return Value:
--*/
{
-
- WDFREQUEST request;
- NTSTATUS status;
- PTARGET_DEVICE_INFO targetInfo;
+ WDFREQUEST request;
+ NTSTATUS status;
+ PTARGET_DEVICE_INFO targetInfo;
WDFMEMORY memory;
- WDF_OBJECT_ATTRIBUTES attributes;
+ WDF_OBJECT_ATTRIBUTES attributes;
targetInfo = GetTargetDeviceInfo(IoTarget);
@@ -957,7 +946,6 @@ Return Value:
Toastmon_WriteRequestCompletionRoutine,
targetInfo);
-
//
// Clear the WriteRequest field in the context to avoid
// being reposted even before the reqeuest completes.
@@ -970,15 +958,17 @@ Return Value:
KdPrint(("WdfRequestSend failed 0x%x\n", status));
targetInfo->WriteRequest = request;
}
+
return status;
}
+_Use_decl_annotations_
VOID
Toastmon_ReadRequestCompletionRoutine(
- IN WDFREQUEST Request,
- IN WDFIOTARGET Target,
- PWDF_REQUEST_COMPLETION_PARAMS CompletionParams,
- IN WDFCONTEXT Context
+ WDFREQUEST Request,
+ WDFIOTARGET Target,
+ PWDF_REQUEST_COMPLETION_PARAMS CompletionParams,
+ WDFCONTEXT Context
)
/*++
@@ -1000,13 +990,13 @@ Return Value:
--*/
{
WDF_REQUEST_REUSE_PARAMS params;
- PTARGET_DEVICE_INFO targetInfo;
- NTSTATUS status;
+ PTARGET_DEVICE_INFO targetInfo;
+ NTSTATUS status;
UNREFERENCED_PARAMETER(Context);
targetInfo = GetTargetDeviceInfo(Target);
-
+
//
// Delete the memory object because we create a new one every time we post
// the request. For perf reason, it would be better to preallocate the memory
@@ -1024,6 +1014,7 @@ Return Value:
status = WdfRequestReuse(Request, &params);
ASSERT(NT_SUCCESS(status));
_Analysis_assume_(NT_SUCCESS(status));
+
//
// RequestReuse zero all the values in structure pointed by CompletionParams.
// So you must get all the information from completion params before
@@ -1036,15 +1027,15 @@ Return Value:
// Don't repost the request in the completion routine because it may lead to recursion
// if the driver below completes the request synchronously.
//
- return;
}
+_Use_decl_annotations_
VOID
Toastmon_WriteRequestCompletionRoutine(
- IN WDFREQUEST Request,
- IN WDFIOTARGET Target,
- PWDF_REQUEST_COMPLETION_PARAMS CompletionParams,
- IN WDFCONTEXT Context
+ WDFREQUEST Request,
+ WDFIOTARGET Target,
+ PWDF_REQUEST_COMPLETION_PARAMS CompletionParams,
+ WDFCONTEXT Context
)
/*++
@@ -1066,13 +1057,13 @@ Return Value:
--*/
{
WDF_REQUEST_REUSE_PARAMS params;
- PTARGET_DEVICE_INFO targetInfo;
- NTSTATUS status;
+ PTARGET_DEVICE_INFO targetInfo;
+ NTSTATUS status;
UNREFERENCED_PARAMETER(Context);
targetInfo = GetTargetDeviceInfo(Target);
-
+
//
// Delete the memory object because we create a new one every time we post
// the request. For perf reason, it would be better to preallocate even memory object.
@@ -1102,8 +1093,5 @@ Return Value:
//
// Don't repost the request in the completion routine because it may lead to recursion
// if the driver below completes the request synchronously.
- //
- return;
+ //
}
-
-
diff --git a/general/toaster/toastDrv/kmdf/toastmon/wmi.c b/general/toaster/toastDrv/kmdf/toastmon/wmi.c
index b3cdcb88..8d8b4406 100644
--- a/general/toaster/toastDrv/kmdf/toastmon/wmi.c
+++ b/general/toaster/toastDrv/kmdf/toastmon/wmi.c
@@ -22,45 +22,12 @@ Environment:
Kernel mode
-
--*/
#include "toastmon.h"
#include "public.h"
#include <wmistr.h>
-//
-// These typedefs required to avoid compilation errors in Win2K build environment.
-//
-typedef
-VOID
-(*WMI_NOTIFICATION_CALLBACK)( // Copied from WDM.H
- PVOID Wnode,
- PVOID Context
- );
-
-typedef
-NTSTATUS
-(*PFN_IO_WMI_OPEN_BLOCK)(
- IN GUID * DataBlockGuid,
- IN ULONG DesiredAccess,
- OUT PVOID * DataBlockObject
- );
-
-typedef
-NTSTATUS
-(*PFN_IO_WMI_SET_NOTIFICATION_CALLBACK)(
- IN PVOID Object,
- IN WMI_NOTIFICATION_CALLBACK Callback,
- IN PVOID Context
- );
-
-NTSTATUS
-GetTargetFriendlyName(
- WDFIOTARGET Target,
- IN WDFMEMORY* TargetName
- );
-
#ifdef ALLOC_PRAGMA
#pragma alloc_text(PAGE, RegisterForWMINotification)
#pragma alloc_text(PAGE, UnregisterForWMINotification)
@@ -68,7 +35,6 @@ GetTargetFriendlyName(
#pragma alloc_text(PAGE, WmiNotificationCallback)
#endif
-
NTSTATUS
RegisterForWMINotification(
PDEVICE_EXTENSION DeviceExt
@@ -76,38 +42,10 @@ RegisterForWMINotification(
{
NTSTATUS status = STATUS_SUCCESS;
GUID wmiGuid;
- UNICODE_STRING funcName;
-
- PFN_IO_WMI_OPEN_BLOCK WmiOpenBlock;
- PFN_IO_WMI_SET_NOTIFICATION_CALLBACK WmiSetNotificationCallback;
PAGED_CODE();
//
- // APIs to open WMI interfaces are available on XP and beyond, so let us
- // first check to see whether there are exported in the kernel we are
- // running before using them.
- //
- RtlInitUnicodeString(&funcName, L"IoWMIOpenBlock");
-
- WmiOpenBlock =
- (PFN_IO_WMI_OPEN_BLOCK) (ULONG_PTR)
- MmGetSystemRoutineAddress(&funcName);
-
- RtlInitUnicodeString(&funcName, L"IoWMISetNotificationCallback");
-
- WmiSetNotificationCallback =
- (PFN_IO_WMI_SET_NOTIFICATION_CALLBACK) (ULONG_PTR)
- MmGetSystemRoutineAddress(&funcName);
-
- if(WmiOpenBlock == NULL || WmiSetNotificationCallback == NULL) {
- //
- // Not available.
- //
- return STATUS_NOT_SUPPORTED;
- }
-
- //
// Check to make sure we are not called multiple times.
//
ASSERT(DeviceExt->WMIDeviceArrivalNotificationObject == NULL);
@@ -117,7 +55,7 @@ RegisterForWMINotification(
//
wmiGuid = TOASTER_NOTIFY_DEVICE_ARRIVAL_EVENT;
- status = WmiOpenBlock(
+ status = IoWMIOpenBlock(
&wmiGuid,
WMIGUID_NOTIFICATION,
&DeviceExt->WMIDeviceArrivalNotificationObject
@@ -129,7 +67,7 @@ RegisterForWMINotification(
} else {
- status = WmiSetNotificationCallback(
+ status = IoWMISetNotificationCallback(
DeviceExt->WMIDeviceArrivalNotificationObject,
WmiNotificationCallback,
DeviceExt
@@ -148,7 +86,7 @@ RegisterForWMINotification(
VOID
UnregisterForWMINotification(
PDEVICE_EXTENSION DeviceExt
-)
+ )
{
PAGED_CODE();
@@ -158,11 +96,11 @@ UnregisterForWMINotification(
}
}
-
+_Use_decl_annotations_
NTSTATUS
GetTargetFriendlyName(
WDFIOTARGET Target,
- IN WDFMEMORY* TargetName
+ WDFMEMORY* TargetName
)
/*++
@@ -210,8 +148,8 @@ Return Value:
VOID
WmiNotificationCallback(
- IN PVOID Wnode,
- IN PVOID Context
+ PVOID Wnode,
+ PVOID Context
)
/*++
@@ -232,15 +170,15 @@ Return Value:
--*/
{
- PWNODE_SINGLE_INSTANCE wnode = (PWNODE_SINGLE_INSTANCE) Wnode;
- WDFMEMORY memory;
- UNICODE_STRING deviceName;
- PDEVICE_OBJECT devobj;
- NTSTATUS status;
- PDEVICE_EXTENSION deviceExt = Context;
- WDFCOLLECTION hCollection = deviceExt->TargetDeviceCollection;
- WDFIOTARGET ioTarget;
- ULONG i;
+ PWNODE_SINGLE_INSTANCE wnode = (PWNODE_SINGLE_INSTANCE) Wnode;
+ WDFMEMORY memory;
+ UNICODE_STRING deviceName;
+ PDEVICE_OBJECT devobj;
+ NTSTATUS status;
+ PDEVICE_EXTENSION deviceExt = Context;
+ WDFCOLLECTION hCollection = deviceExt->TargetDeviceCollection;
+ WDFIOTARGET ioTarget;
+ ULONG i;
PAGED_CODE();
@@ -296,7 +234,3 @@ Return Value:
WdfWaitLockRelease(deviceExt->TargetDeviceCollectionLock);
}
-
-
-
-