### Install DMF Sample Driver Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/InterfaceSample2/README.md Use this command to install the sample driver. Ensure Devcon.exe from the DDK is in your PATH. ```bash devcon install InterfaceSample2.inf root\Transport22 ``` -------------------------------- ### Install Provider Manifest Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/Documentation/Compare-kmdf_fx2-to-kmdf_fx2_dmf/Files/root_README.md.html Install the provider manifest for unified tracing. This command must be run from an elevated prompt. ```bash wevtutil im osrusbfx2.man ``` -------------------------------- ### Start Trace with logman Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/Documentation/Compare-kmdf_fx2-to-kmdf_fx2_dmf/Files/root_README.md.html Starts a trace session using the `logman` command. Specify the output file and the trace provider. ```bash logman start sample -o osrusbfx2.etl -ets -p OSRUSBFX2 ``` -------------------------------- ### Testing User-mode Driver Installation Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/VirtualHidDeviceVhfDmf/README.md Command to install the User-mode driver on a target machine. ```bash devcon install VirtualHidDeviceVhfDmfU.inf root\VirtualHidDeviceVhfDmfU ``` -------------------------------- ### Define Multiple WPP Control GUIDs for Client and DMF Source: https://github.com/microsoft/dmf/blob/master/Dmf/Documentation/Driver Module Framework.md This example demonstrates defining multiple WPP control GUIDs, including one for DMF tracing and others for the Client Driver's own tracing needs. Each GUID should have unique bits defined. ```c // Define the tracing flags. // // Tracing GUID - {1AE05C6D-9140-41DC-BFBD-C8C4391FD95F} // #define WPP_CONTROL_GUIDS \ WPP_DEFINE_CONTROL_GUID( DmfLibraryTraceGuid, (74DC7AB3,690B,480A,87A4,3627882A831C), WPP_DEFINE_BIT(DMF_TRACE) ) \ WPP_DEFINE_CONTROL_GUID( DmfSampleDriverTraceGuid, {1AE05C6D,9140,41DC,BFBD,C8C4391FD95F} WPP_DEFINE_BIT(MYDRIVER_ALL_INFO) WPP_DEFINE_BIT(TRACE_DRIVER) WPP_DEFINE_BIT(TRACE_DEVICE) WPP_DEFINE_BIT(TRACE_QUEUE) WPP_DEFINE_BIT(TRACE_USP) ) // This comment block is scanned by the trace preprocessor to define our // Trace function. // // USEPREFIX and USESUFFIX strip all trailing whitespace, so we need to surround // FuncExit messages with brackets // // begin_wpp config // FUNC Trace{FLAG=MYDRIVER_ALL_INFO}(LEVEL, MSG, ...); // FUNC TraceEvents(LEVEL, FLAGS, MSG, ...); // FUNC FuncEntry{LEVEL=TRACE_LEVEL_VERBOSE}(FLAGS); // FUNC FuncEntryArguments{LEVEL=TRACE_LEVEL_VERBOSE}(FLAGS, MSG, ...); // FUNC FuncExit{LEVEL=TRACE_LEVEL_VERBOSE}(FLAGS, MSG, ...); ``` -------------------------------- ### Example: DECLARE_DMF_MODULE for OsrFx2 Source: https://github.com/microsoft/dmf/blob/master/Dmf/Documentation/Driver Module Framework.md This example shows how DECLARE_DMF_MODULE(OsrFx2) declares specific functions for the OsrFx2 module, including attribute initialization, config initialization, and creation functions. ```c // This macro declares the following functions: // DMF_OsrFx2_ATTRIBUTES_INIT() // DMF_CONFIG_OsrFx2_AND_ATTRIBUTES_INIT() // DMF_OsrFx2_Create() // DECLARE_DMF_MODULE(OsrFx2) ``` -------------------------------- ### Testing Kernel-mode Driver Installation Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/VirtualHidDeviceVhfDmf/README.md Command to install the Kernel-mode driver on a target machine. ```bash devcon install VirtualHidDeviceVhfDmfK.inf root\VirtualHidDeviceVhfDmfK ``` -------------------------------- ### Handle Device Power Up and Start Streaming Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/SwitchBar5/README.md This function is called when the device powers up. It reads the switch states, updates the lightbar, and starts the DMF Continuous Request Target streaming. ```c NTSTATUS SwitchBarEvtDeviceD0Entry( WDFDEVICE Device, WDF_POWER_DEVICE_STATE PreviousState ) /*++ Routine Description: When the device powers up, read the switches and set the lightbar appropriately. Arguments: Device - Handle to a framework device object. PreviousState - Device power state which the device was in most recently. If the device is being newly started, this will be PowerDeviceUnspecified. Return Value: NTSTATUS --*/ { DEVICE_CONTEXT* deviceContext; NTSTATUS ntStatus; UNREFERENCED_PARAMETER(PreviousState); TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "-->%!FUNC!"); deviceContext = DeviceContextGet(Device); // Read the state of switches and initialize lightbar. // SwitchBarReadSwitchesAndUpdateLightBar(deviceContext->DmfModuleContinuousRequestTarget); // Start streaming. // ntStatus = DMF_ContinuousRequestTarget_Start(deviceContext->DmfModuleContinuousRequestTarget); TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "<--%!FUNC!"); return ntStatus; } ``` -------------------------------- ### EVT_DMF_UdeClient_Endpoint_Start Source: https://github.com/microsoft/dmf/blob/master/Dmf/Modules.Library/Dmf_UdeClient.md Callback to indicate to clients that that framework is starting processing I/O request on an Endpoint. This callback is Optional. ```APIDOC ## EVT_DMF_UdeClient_Endpoint_Start ### Description Callback to indicate to clients that that framework is starting processing I/O request on an Endpoint. This callback is Optional. ### Method Callback ### Endpoint N/A (Callback) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A ### Request Example N/A ### Response #### Success Response (200) N/A #### Response Example N/A ### Parameters - **DmfModule** (DMFMODULE) - An open DMF_UdeClient Module handle. - **Endpoint** (UDECXUSBENDPOINT) - A handle to a framework device object that represents an Endpoint on a Virtual USB Device. ``` -------------------------------- ### Trace Read Operation Start Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/Documentation/Compare-kmdf_fx2-to-kmdf_fx2_dmf/Files/driver_bulkrwr.c.html Traces the entry into the OsrFxEvtIoRead event handler with verbose logging. ```c TraceEvents(TRACE_LEVEL_VERBOSE, DBG_READ, "-->OsrFxEvtIoRead\n"); ``` -------------------------------- ### Initialize DMF Device with Callbacks Source: https://github.com/microsoft/dmf/blob/master/Dmf/Documentation/Driver Module Framework.md This example demonstrates a comprehensive device initialization process using DMF. It involves allocating a DMF device initialization structure, hooking various callbacks for file objects, power events, and DMF events, and finally creating the WDF device. Use this when setting up a new DMF-enabled device. ```c WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks; WDF_OBJECT_ATTRIBUTES deviceAttributes; PDEVICE_CONTEXT deviceContext; WDFDEVICE device; WDF_DEVICE_STATE deviceState; NTSTATUS ntStatus; WDF_TIMER_CONFIG timerConfig; WDF_OBJECT_ATTRIBUTES timerAttributes; DMF_EVENT_CALLBACKS dmfCallbacks; DMF_CONFIG_BranchTrack branchTrackModuleConfig; PDMFDEVICE_INIT dmfDeviceInit; PAGED_CODE(); FuncEntry(TRACE_DEVICE); dmfDeviceInit = DMF_DmfDeviceInitAllocate(DeviceInit); DMF_DmfDeviceInitHookFileObjectConfig(dmfDeviceInit, NULL); DMF_DmfDeviceInitHookPowerPolicyEventCallbacks(dmfDeviceInit, NULL); WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks); pnpPowerCallbacks.EvtDeviceD0Entry = DmfSampleEvtDeviceD0Entry; pnpPowerCallbacks.EvtDeviceD0Exit = DmfSampleEvtDeviceD0Exit; pnpPowerCallbacks.EvtDevicePrepareHardware = DmfSampleEvtDevicePrepareHardware; DMF_DmfDeviceInitHookPnpPowerEventCallbacks(dmfDeviceInit, &pnpPowerCallbacks); WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks); WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_UNKNOWN); WdfDeviceInitSetIoType(DeviceInit, WdfDeviceIoBuffered); WdfDeviceInitSetExclusive(DeviceInit, FALSE); WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&deviceAttributes, DEVICE_CONTEXT); deviceAttributes.EvtCleanupCallback = DmfSampleEvtDeviceContextCleanup; ntStatus = WdfDeviceCreate(&DeviceInit, &deviceAttributes, &device); if (!NT_SUCCESS(ntStatus)) { goto Exit; } deviceContext = DeviceContextGet(device); RtlSecureZeroMemory(deviceContext, sizeof(DEVICE_CONTEXT)); deviceContext->WdfDevice = device; DMF_EVENT_CALLBACKS_INIT(&dmfCallbacks); dmfCallbacks.EvtDmfDeviceModulesAdd = DmfDeviceModulesAdd; DMF_DmfDeviceInitSetEventCallbacks(dmfDeviceInit, &dmfCallbacks); ntStatus = DMF_ModulesCreate(device, &dmfDeviceInit, deviceContext); ``` -------------------------------- ### DMF_UefiOperation_FirmwareEnvironmentVariableGetEx Source: https://github.com/microsoft/dmf/blob/master/Dmf/Modules.Library/DMF_UefiOperation.md Allows the client to get UEFI variable data to a specified UEFI GUID and name in both user-mode and kernel-mode. ```APIDOC ## DMF_UefiOperation_FirmwareEnvironmentVariableGetEx ### Description Allows the Client to get the UEFI variable data to certain UEFI Guid and name in both User-mode and Kernel-mode. ### Method NTSTATUS ### Endpoint N/A (This is a function call, not an HTTP endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (NTSTATUS) - **VariableBuffer** (VOID*) - Buffer that will store the data that is read from the UEFI variable. - **VariableBufferSize** (ULONG*) - As input, it passes the desired size that needs to be read. As output, it sends back the actual size that was read from UEFI. - **Attributes** (ULONG*) - Optional: Location to which the routine writes the attributes of the specified environment variable. #### Response Example None ``` -------------------------------- ### DMF_UefiOperation_FirmwareEnvironmentVariableGet Source: https://github.com/microsoft/dmf/blob/master/Dmf/Modules.Library/DMF_UefiOperation.md Allows the client to get UEFI variable data from a specified UEFI GUID and name. This method is deprecated and DMF_UefiOperation_FirmwareEnvironmentVariableGetEx should be used instead. ```APIDOC ## DMF_UefiOperation_FirmwareEnvironmentVariableGet ### Description Allows the Client to get the UEFI variable data from certain UEFI Guid and name. This Method is deprecated. Use DMF_UefiOperation_FirmwareEnvironmentVariableGetEx() instead. ### Method NTSTATUS ### Endpoint N/A (This is a function call, not an HTTP endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (NTSTATUS) - **VariableBuffer** (VOID*) - Buffer that will store the data that is read from the UEFI variable. - **VariableBufferSize** (DWORD*) - As input, it pass the desired size that needs to be read. As output, it send back the actual size that was read from UEFI. #### Response Example None ``` -------------------------------- ### Initialize Device and Set Callbacks Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/SwitchBar5/README.md Initializes the WDFDEVICE and sets up PNP/Power event callbacks. It avoids DMF hooking APIs as it exclusively uses Dynamic Modules. ```c _IRQL_requires_max_(PASSIVE_LEVEL) NTSTATUS DmfDeviceDynamicModulesAdd( _In_ WDFDEVICE Device ); typedef struct { // Allows this driver to send communicate with the USB device both using streaming // and by sending individual requests. // DMFMODULE DmfModuleContinuousRequestTarget; } DEVICE_CONTEXT, *PDEVICE_CONTEXT; WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(DEVICE_CONTEXT, DeviceContextGet) _Use_decl_annotations_ NTSTATUS SwitchBarEvtDeviceAdd( _In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT DeviceInit ) { NTSTATUS ntStatus; WDFDEVICE device; WDF_OBJECT_ATTRIBUTES objectAttributes; WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks; UNREFERENCED_PARAMETER(Driver); PAGED_CODE(); TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "-->%!FUNC!"); // Tell WDF this callback should be called. // WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks); pnpPowerCallbacks.EvtDeviceD0Entry = SwitchBarEvtDeviceD0Entry; pnpPowerCallbacks.EvtDeviceD0Exit = SwitchBarEvtDeviceD0Exit; // It is not necessary to call DMF Hooking APIs since this sample use only Dynamic Modules. // WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks); // Set any device attributes needed. // WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_UNKNOWN); WdfDeviceInitSetExclusive(DeviceInit, FALSE); // This is a filter driver that loads on OSRUSBFX2 driver. // WdfFdoInitSetFilter(DeviceInit); // Define a device context type. // WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&objectAttributes, DEVICE_CONTEXT); // Create the Client driver's WDFDEVICE. // ntStatus = WdfDeviceCreate(&DeviceInit, &objectAttributes, &device); if (! NT_SUCCESS(ntStatus)) { goto Exit; } // It is not necessary to call DMF_ModulesCreate since this driver uses only // Dynamic Modules. // ntStatus = DmfDeviceDynamicModulesAdd(device); Exit: TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_CALLBACK, "<--%!FUNC! ntStatus=%!STATUS!", ntStatus); return ntStatus; } #pragma code_seg() ``` -------------------------------- ### DMF_UefiOperation_FirmwareEnvironmentVariableAllocateGet Source: https://github.com/microsoft/dmf/blob/master/Dmf/Modules.Library/DMF_UefiOperation.md Allows the client to get UEFI variable data from a specified UEFI GUID and name. This API automatically allocates the required memory, and the client is responsible for freeing it. ```APIDOC ## DMF_UefiOperation_FirmwareEnvironmentVariableAllocateGet ### Description Allows the Client to get the UEFI variable data from certain UEFI Guid and name in both User-mode and Kernel-mode. This API allocates required memory automatically and the client is responsible to free the memory. ### Method NTSTATUS ### Endpoint N/A (This is a function call, not an HTTP endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (NTSTATUS) - **VariableBuffer** (VOID**) - Buffer that will store the data that is read from the UEFI variable. - **VariableBufferSize** (ULONG*) - As input, it pass the desired size that needs to be read. As output, it send back the actual size that was read from UEFI. - **VariableBufferHandle** (WDFMEMORY*) - WDF Memory Handle for the client - **Attributes** (ULONG*) - Optional: Location to which the routine writes the attributes of the specified environment variable. #### Response Example None ``` -------------------------------- ### Select USB Interfaces and Pipes Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/Documentation/Compare-kmdf_fx2-to-kmdf_fx2_dmf/Files/driver_Device.c.html This helper routine selects the configuration, interface, and creates a context for every pipe (endpoint) in that interface. It takes a handle to a framework device as input. ```C NTSTATUS OsrFxSetPowerPolicy( _In_ WDFDEVICE Device ) { WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS idleSettings; WDF_DEVICE_POWER_POLICY_WAKE_SETTINGS wakeSettings; NTSTATUS status = STATUS_SUCCESS; PAGED_CODE(); // // Init the idle policy structure. // WDF_DEVICE_POWER_POLICY_IDLE_SETTINGS_INIT(&idleSettings, IdleUsbSelectiveSuspend); idleSettings.IdleTimeout = 10000; // 10-sec status = WdfDeviceAssignS0IdleSettings(Device, &idleSettings); if ( !NT_SUCCESS(status)) { TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, "WdfDeviceSetPowerPolicyS0IdlePolicy failed %x\n", status); return status; } // // Init wait-wake policy structure. // WDF_DEVICE_POWER_POLICY_WAKE_SETTINGS_INIT(&wakeSettings); status = WdfDeviceAssignSxWakeSettings(Device, &wakeSettings); if (!NT_SUCCESS(status)) { TraceEvents(TRACE_LEVEL_ERROR, DBG_PNP, "WdfDeviceAssignSxWakeSettings failed %x\n", status); return status; } return status; } ``` ```C NTSTATUS SelectInterfaces( _In_ WDFDEVICE Device ) /*++ Routine Description: This helper routine selects the configuration, interface and creates a context for every pipe (end point) in that interface. Arguments: Device - Handle to a framework device Return Value: ``` -------------------------------- ### DMF Method for Getting Preparsed Data Source: https://github.com/microsoft/dmf/blob/master/Dmf/Documentation/Driver Module Framework.md Example of a DMF method signature for retrieving HID PreparsedData. This method likely follows the resource management pattern requiring reference counting. ```c NTSTATUS DMF_HidTarget_PreparsedDataGet( _In_ DMFMODULE DmfModule, _Out_ PHIDP_PREPARSED_DATA* PreparsedData ); ``` -------------------------------- ### Get UINT32 Device Property Source: https://github.com/microsoft/dmf/blob/master/Dmf/Modules.Library/Dmf_CmApi.md Use this function to retrieve the UINT32 value of a specified device property key for a given device interface GUID. Ensure the DMF module is open and valid. ```c _IRQL_requires_max_(PASSIVE_LEVEL) NTSTATUS DMF_CmApi_PropertyUint32Get( _In_ DMFMODULE DmfModule, _In_reads_bytes_(sizeof(GUID)) GUID* PropertyInterfaceGuid, _In_ PDEVPROPKEY PropertyKey, _Out_ UINT32* Value ); ``` -------------------------------- ### Initialize Sample Interface Upper Protocol and Add Module Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/InterfaceSample2/README.md Initializes the SampleInterfaceUpperProtocol configuration and adds the module. This is a prerequisite for binding transports. ```c DMF_CONFIG_SampleInterfaceUpperProtocol_AND_ATTRIBUTES_INIT(&moduleConfigSampleInterfaceUpperProtocol, &moduleAttributes); moduleConfigSampleInterfaceUpperProtocol.ModuleId = 1; moduleConfigSampleInterfaceUpperProtocol.ModuleName = "SampleInterfaceUpperProtocol"; DMF_DmfModuleAdd(DmfModuleInit, &moduleAttributes, WDF_NO_OBJECT_ATTRIBUTES, &(deviceContext->DmfModuleProtocol)); ``` -------------------------------- ### Get Bar Graph State Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/Documentation/Compare-kmdf_fx2-to-kmdf_fx2_dmf/Files/driver_ioctl.c.html This function retrieves the state of the bar graph on a device. It initializes send options with a timeout and prepares a USB control setup packet. Ensure the device context and bar graph state structures are valid. ```c NTSTATUS status; WDF_USB_CONTROL_SETUP_PACKET controlSetupPacket; WDF_REQUEST_SEND_OPTIONS sendOptions; WDF_MEMORY_DESCRIPTOR memDesc; ULONG bytesTransferred; PAGED_CODE(); TraceEvents(TRACE_LEVEL_VERBOSE, DBG_IOCTL, "--> GetBarGraphState\n"); WDF_REQUEST_SEND_OPTIONS_INIT( &sendOptions, WDF_REQUEST_SEND_OPTION_TIMEOUT ); WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT( &sendOptions, DEFAULT_CONTROL_TRANSFER_TIMEOUT ); WDF_USB_CONTROL_SETUP_PACKET_INIT_VENDOR(&controlSetupPacket, ``` -------------------------------- ### EvtDevicePrepareHardware Entry Point Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/Documentation/Compare-kmdf_fx2-to-kmdf_fx2_dmf/Files/driver_Device.c.html Marks the end of the EvtDevicePrepareHardware callback, indicating successful preparation of the device hardware. This is a standard WDF callback. ```C TraceEvents(TRACE_LEVEL_INFORMATION, DBG_PNP, "<-- EvtDevicePrepareHardware\n"); ``` -------------------------------- ### Initialize WDFDEVICE and Set Callbacks Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/SwitchBar5/README.md Initializes a WDFDEVICE, sets PNP/Power event callbacks, and configures device attributes. This is typically done in the driver's AddDevice routine. ```c NTSTATUS DriverEvtDeviceAdd( _In_ WDFDRIVER Driver, _Inout_ PWDFDEVICE_INIT DeviceInit ) { NTSTATUS ntStatus; WDFDEVICE device; WDF_OBJECT_ATTRIBUTES objectAttributes; WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks; UNREFERENCED_PARAMETER(Driver); PAGED_CODE(); TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, ">>%!FUNC!"); // Tell WDF this callback should be called. // WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks); pnpPowerCallbacks.EvtDeviceD0Entry = SwitchBarEvtDeviceD0Entry; pnpPowerCallbacks.EvtDeviceD0Exit = SwitchBarEvtDeviceD0Exit; // It is not necessary to call DMF Hooking APIs since this sample use only Dynamic Modules. // WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks); // Set any device attributes needed. // WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_UNKNOWN); WdfDeviceInitSetExclusive(DeviceInit, FALSE); // This is a filter driver that loads on OSRUSBFX2 driver. // WdfFdoInitSetFilter(DeviceInit); // Define a device context type. // WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&objectAttributes, DEVICE_CONTEXT); // Create the Client driver's WDFDEVICE. // ntStatus = WdfDeviceCreate(&DeviceInit, &objectAttributes, &device); if (! NT_SUCCESS(ntStatus)) { goto Exit; } // It is not necessary to call DMF_ModulesCreate since this driver uses only // Dynamic Modules. // ntStatus = DmfDeviceDynamicModulesAdd(device); Exit: TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_CALLBACK, "<--%!FUNC! ntStatus=%!STATUS!", ntStatus); return ntStatus; } #pragma code_seg() ``` -------------------------------- ### Start Hinge Angle Monitor Source: https://github.com/microsoft/dmf/blob/master/Dmf/Modules.Library/Dmf_HingeAngle.md Starts the Hinge Angle monitor and events. The module starts automatically when opened, but this function allows for manual starting if needed. The operation must be performed at PASSIVE_LEVEL. ```c _IRQL_requires_max_(PASSIVE_LEVEL) _Must_inspect_result_ NTSTATUS DMF_HingeAngle_Start( _In_ DMFMODULE DmfModule ); ``` -------------------------------- ### DMF_HingeAngle_Start Source: https://github.com/microsoft/dmf/blob/master/Dmf/Modules.Library/Dmf_HingeAngle.md Starts the Hinge Angle monitor and events. The module starts automatically on open, but this function allows manual starting. ```APIDOC ## DMF_HingeAngle_Start ### Description Start the Hinge Angle monitor and events. Module start when open by default, client can also use this function to manually start. ### Method POST (Conceptual - This is a function call, not a direct HTTP endpoint) ### Endpoint N/A (This is a module function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c // Example usage (conceptual) NTSTATUS status = DMF_HingeAngle_Start(dmfModule); ``` ### Response #### Success Response (NTSTATUS) Indicates success or failure of the operation. #### Response Example ```json { "status": "NT_SUCCESS" } ``` ``` -------------------------------- ### Implement DMF_ResourcesAssign Callback Source: https://github.com/microsoft/dmf/blob/master/Dmf/Documentation/Driver Module Framework.md Modules that do not support EvtDevicePrepareHardware can use this callback to obtain and select resources from the Client Driver. It is called by DMF and is not accessible to Clients or other Modules. ```c static NTSTATUS DMF_ResourcesAssign( _In_ DMFMODULE DmfModule, _In_ WDFCMRESLIST ResourcesRaw, _In_ WDFCMRESLIST ResourcesTranslated ) ``` -------------------------------- ### Initialize DMF Device Driver Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/SwitchBar3/README.md This snippet demonstrates the core initialization logic for a DMF driver, including setting up PnP Power event callbacks, device attributes, and creating the WDFDEVICE. It also shows how to hook DMF-specific configurations for queues and modules. ```C TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "-->%!FUNC!"); dmfDeviceInit = DMF_DmfDeviceInitAllocate(DeviceInit); // Tell WDF this callback should be called. // WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks); pnpPowerCallbacks.EvtDeviceD0Entry = SwitchBarEvtDeviceD0Entry; // All DMF drivers must call this function even if they do not support PnP Power callbacks. // (In this case, this driver does support a PnP Power callback.) // DMF_DmfDeviceInitHookPnpPowerEventCallbacks(dmfDeviceInit, &pnpPowerCallbacks); WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks); // All DMF drivers must call this function even if they do not support File Object callbacks. // DMF_DmfDeviceInitHookFileObjectConfig(dmfDeviceInit, NULL); // All DMF drivers must call this function even if they do not support Power Policy callbacks. // DMF_DmfDeviceInitHookPowerPolicyEventCallbacks(dmfDeviceInit, NULL); // Set any device attributes needed. // WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_UNKNOWN); WdfDeviceInitSetExclusive(DeviceInit, FALSE); // This is a filter driver that loads on OSRUSBFX2 driver. // WdfFdoInitSetFilter(DeviceInit); // DMF Client drivers that are filter drivers must also make this call. // DMF_DmfFdoSetFilter(dmfDeviceInit); // Define a device context type. // WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&objectAttributes, DEVICE_CONTEXT); // Create the Client driver's WDFDEVICE. // ntStatus = WdfDeviceCreate(&DeviceInit, &objectAttributes, &device); if (! NT_SUCCESS(ntStatus)) { goto Exit; } // This driver will filter IOCTLS, so set up a default queue. // WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queueConfig, WdfIoQueueDispatchSequential); queueConfig.EvtIoDeviceControl = SwitchBarModuleDeviceIoControl; // When a DMF Client driver creates a default queue, it must also make this call. // This call is not needed if the Client driver does not create a default queue. // DMF_DmfDeviceInitHookQueueConfig(dmfDeviceInit, &queueConfig); ntStatus = WdfIoQueueCreate(device, &queueConfig, &objectAttributes, &queue); if (! NT_SUCCESS(ntStatus)) { goto Exit; } // Create the DMF Modules this Client driver will use. // dmfCallbacks.EvtDmfDeviceModulesAdd = DmfDeviceModulesAdd; DMF_DmfDeviceInitSetEventCallbacks(dmfDeviceInit, &dmfCallbacks); ntStatus = DMF_ModulesCreate(device, &dmfDeviceInit); if (! NT_SUCCESS(ntStatus)) { goto Exit; } Exit: if (dmfDeviceInit != NULL) { DMF_DmfDeviceInitFree(&dmfDeviceInit); } TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_CALLBACK, "<--%!FUNC! ntStatus=%!STATUS!", ntStatus); return ntStatus; } #pragma code_seg() ``` -------------------------------- ### WPP Control GUIDs Definition for DMF Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/Documentation/Compare-kmdf_fx2-to-kmdf_fx2_dmf/Files/driver_trace.h.html Defines the control GUID for DMF tracing and associated bit flags. Ensure the GUID is unique for your driver. ```c #define WPP_CONTROL_GUIDS \ WPP_DEFINE_CONTROL_GUID( \ DmfTraceGuid, (12C255E8,E614,4DD2,B93B,5624E48C119E), \ WPP_DEFINE_BIT(DMF_TRACE) \ ) ``` -------------------------------- ### Define SMF Interface GUIDs Source: https://github.com/microsoft/dmf/blob/master/Dmf/Modules.Library/Dmf_Interface_SystemManagementFramework.md These GUIDs are used to identify specific SMF interfaces. Ensure correct GUIDs are used when interacting with SMF components. ```c // {0B7B5350-BB8C-4459-8D4A-A75C57073801?} DEFINE_GUID(SMF_POWER_LIMIT_CONTROL_TYPE, 0xb7b5350, 0xbb8c, 0x4459, 0x8d, 0x4a, 0xa7, 0x5c, 0x57, 0x7, 0x38, 0x1); ``` ```c // {2E8B14C2-26D6-4119-A62E-9D108C4DDC2A} DEFINE_GUID(SMF_TEMPERATURE_SENSOR_TYPE, 0x2e8b14c2, 0x26d6, 0x4119, 0xa6, 0x2e, 0x9d, 0x10, 0x8c, 0x4d, 0xdc, 0x2a); ``` ```c // {349D0E39-53E2-449C-8067-D690B39E7459} DEFINE_GUID(SMF_FREQUENCY_LIMIT_CONTROL_TYPE, 0x349D0E39, 0x53E2, 0x449C, 0x80, 0x67, 0xD6, 0x90, 0xB3, 0x9E, 0x74, 0x59); ``` ```c // {87008365-EA3A-461C-B83D-6AC6E8DB2F8A} DEFINE_GUID(SMF_GENERIC_TYPE, 0x87008365, 0xea3a, 0x461c, 0xb8, 0x3d, 0x6a, 0xc6, 0xe8, 0xdb, 0x2f, 0x8a); ``` ```c // {CF2F6076-EC8B-4D3D-AF61-CC76B118588A} DEFINE_GUID(SMF_TIME_LIMIT_CONTROL_OUTPUT_TYPE, 0xCF2F6076, 0xEC8B, 0x4D3D, 0xaf, 0x61, 0xcc, 0x76, 0xb1, 0x18, 0x58, 0x8a); ``` -------------------------------- ### DMF_UdeClient_Static_DeviceInitInitialize Source: https://github.com/microsoft/dmf/blob/master/Dmf/Modules.Library/Dmf_UdeClient.md Initializes the UDECX framework. This function must be called before the WdfDevice is created. ```APIDOC ## DMF_UdeClient_Static_DeviceInitInitialize ### Description This Method is for initializing the UDECX. This MUST be called before the WdfDevice is created. ### Method Not specified (likely internal or part of a larger framework) ### Endpoint Not applicable (function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) NTSTATUS #### Response Example None ### Parameters - **DeviceInit** (PWDFDEVICE_INIT) - Required - Pointer to the WDFDEVICE_INIT structure. ``` -------------------------------- ### Find Exact GUID in List Source: https://github.com/microsoft/dmf/blob/master/Dmf/Modules.Library/DMF_String.md Searches for a specific GUID within a list of GUIDs using an exact match. Returns -1 if not found, otherwise returns the index. ```c _Must_inspect_result_ LONG DMF_String_FindInListExactGuid( _In_ DMFMODULE DmfModule, _In_ GUID* GuidList, _In_ ULONG NumberOfGuidsInGuidList, _In_ GUID* LookFor ); ``` -------------------------------- ### Initialize DMF Device and Configure Callbacks Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/SwitchBar4/README.md This snippet shows the core initialization of a DMF device, including setting up PnP/Power event callbacks and hooking them into the DMF device initialization structure. It also configures device attributes and sets the driver as a filter driver. ```c UNREFERENCED_PARAMETER(Driver); PAGED_CODE(); TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_DEVICE, "-->%!FUNC!"); dmfDeviceInit = DMF_DmfDeviceInitAllocate(DeviceInit); // Tell WDF this callback should be called. // WDF_PNPPOWER_EVENT_CALLBACKS_INIT(&pnpPowerCallbacks); pnpPowerCallbacks.EvtDeviceD0Entry = SwitchBarEvtDeviceD0Entry; // All DMF drivers must call this function even if they do not support PnP Power callbacks. // (In this case, this driver does support a PnP Power callback.) // DMF_DmfDeviceInitHookPnpPowerEventCallbacks(dmfDeviceInit, &pnpPowerCallbacks); WdfDeviceInitSetPnpPowerEventCallbacks(DeviceInit, &pnpPowerCallbacks); // All DMF drivers must call this function even if they do not support File Object callbacks. // DMF_DmfDeviceInitHookFileObjectConfig(dmfDeviceInit, NULL); // All DMF drivers must call this function even if they do not support Power Policy callbacks. // DMF_DmfDeviceInitHookPowerPolicyEventCallbacks(dmfDeviceInit, NULL); // Set any device attributes needed. // WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_UNKNOWN); WdfDeviceInitSetExclusive(DeviceInit, FALSE); // This is a filter driver that loads on OSRUSBFX2 driver. // WdfFdoInitSetFilter(DeviceInit); // DMF Client drivers that are filter drivers must also make this call. // DMF_DmfFdoSetFilter(dmfDeviceInit); // Define a device context type. // WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&objectAttributes, DEVICE_CONTEXT); // Create the Client driver's WDFDEVICE. // ntStatus = WdfDeviceCreate(&DeviceInit, &objectAttributes, &device); if (! NT_SUCCESS(ntStatus)) { goto Exit; } // Create the DMF Modules this Client driver will use. // dmfCallbacks.EvtDmfDeviceModulesAdd = DmfDeviceModulesAdd; DMF_DmfDeviceInitSetEventCallbacks(dmfDeviceInit, &dmfCallbacks); ntStatus = DMF_ModulesCreate(device, &dmfDeviceInit); if (! NT_SUCCESS(ntStatus)) { goto Exit; } Exit: if (dmfDeviceInit != NULL) { DMF_DmfDeviceInitFree(&dmfDeviceInit); } TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_CALLBACK, "<--%!FUNC! ntStatus=%!STATUS!", ntStatus); return ntStatus; } #pragma code_seg() ``` -------------------------------- ### DMF_SimpleOrientation_Start Source: https://github.com/microsoft/dmf/blob/master/Dmf/Modules.Library/Dmf_SimpleOrientation.md Starts the monitoring of the Simple Orientation sensor. Note that the sensor is started by default. ```APIDOC ## DMF_SimpleOrientation_Start ### Description Allows Client to start monitoring SimpleOrientation sensor. ### Method NTSTATUS DMF_SimpleOrientation_Start( _In_ DMFMODULE DmfModule ); ### Parameters - **DmfModule** (DMFMODULE) - An open DMF_SimpleOrientation Module handle. ### Remarks * SimpleOrientation sensor is started by default. * Only use this Method, if `DMF_SimpleOrientation_Stop` is used. ``` -------------------------------- ### InterfaceClientServerEvtDevicePrepareHardware Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/InterfaceSample1/README.md Handles the PrepareHardware event to bind the client (Protocol) and server (Transport) modules. ```APIDOC ## InterfaceClientServerEvtDevicePrepareHardware ### Description This routine binds the client and server modules when the device hardware is prepared. ### Method NTSTATUS ### Endpoint N/A (Callback function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (NTSTATUS) - **NT_SUCCESS(ntStatus)** (BOOLEAN) - Indicates if the binding operation was successful. #### Response Example ```c // Success Example NTSTATUS ntStatus = DMF_INTERFACE_BIND(...); // ntStatus will be STATUS_SUCCESS if successful // Error Example NTSTATUS ntStatus = DMF_INTERFACE_BIND(...); // ntStatus will be an error code if binding fails ``` ``` -------------------------------- ### Start Trace with xperf Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/Documentation/Compare-kmdf_fx2-to-kmdf_fx2_dmf/Files/root_README.md.html Initiates a trace session using the `xperf` command from the Windows Performance Toolkit. Specify the output file and the trace provider. ```bash xperf -start sample -f osrusbfx2.etl -on OSRUSBFX2 ``` -------------------------------- ### DMF_ResourcesAssign Callback Source: https://github.com/microsoft/dmf/blob/master/Dmf/Documentation/Driver Module Framework.md Modules that do not support EvtDevicePrepareHardware can support this callback in order to get the Client Driver's resources. The Module will enumerate the resources and choose the resources it needs. ```APIDOC ## DMF_ResourcesAssign ### Description Modules that do not support EvtDevicePrepareHardware can support this callback in order to get the Client Driver's resources. The Module will enumerate the resources and choose the resources it needs. ### Method static ### Endpoint N/A (Callback function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (STATUS_SUCCESS) STATUS_SUCCESS if no error is encountered in the callback. Otherwise, an error code corresponding to the error is returned. #### Response Example None ### Remarks None ``` -------------------------------- ### DMF_String_FindInListExactGuid Source: https://github.com/microsoft/dmf/blob/master/Dmf/Modules.Library/DMF_String.md Finds a specific GUID within a list of GUIDs using an exact match comparison. ```APIDOC ## DMF_String_FindInListExactGuid ### Description Given a list of GUIDs and a GUID to find, find the GUID in the list. The comparison made is: Full GUID, exact match. ### Method (Not specified, likely a function call) ### Endpoint (Not applicable, this is a function) ### Parameters #### Path Parameters (None) #### Query Parameters (None) #### Request Body (None) ### Request Example (Not applicable) ### Response #### Success Response (Return Value) - **LONG**: -1 indicates the GUID to look for was not found. Otherwise, the index of the matching GUID in the list of strings is returned. #### Response Example (Not applicable) ``` -------------------------------- ### Initialize PnP Capabilities Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/Documentation/Compare-kmdf_fx2-to-kmdf_fx2_dmf/Files/driver_Device.c.html Initializes WDF_DEVICE_PNP_CAPABILITIES and sets SurpriseRemovalOK to WdfTrue to prevent user-mode popups on device removal. ```c WDF_DEVICE_PNP_CAPABILITIES_INIT(&pnpCaps); pnpCaps.SurpriseRemovalOK = WdfTrue; WdfDeviceSetPnpCapabilities(device, &pnpCaps); ``` -------------------------------- ### DeviceToActivityId Function Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/Documentation/Compare-kmdf_fx2-to-kmdf_fx2_dmf/Files/driver_osrusbfx2.h.html This function generates an activity GUID based on a WDFDEVICE. It copies the memory of the WDFDEVICE to a GUID structure. ```APIDOC ## FORCEINLINE GUID DeviceToActivityId ### Description Converts a WDFDEVICE into an activity GUID. ### Method Not Applicable (This is a C function, not an HTTP endpoint) ### Endpoint Not Applicable ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example Not Applicable ### Response #### Success Response (200) - **activity** (GUID) - The generated activity GUID. #### Response Example ```json { "activity": "00000000-0000-0000-0000-000000000000" } ``` ### Code Snippet ```c FORCEINLINE GUID DeviceToActivityId( _In_ WDFDEVICE Device ) { GUID activity = {0}; RtlCopyMemory(&activity, &Device, sizeof(WDFDEVICE)); return activity; } ``` ``` -------------------------------- ### Initialize Device Initialization - DMF_UdeClient_Static_DeviceInitInitialize Source: https://github.com/microsoft/dmf/blob/master/Dmf/Modules.Library/Dmf_UdeClient.md Initializes the UDECX framework before creating a WdfDevice. This is a mandatory setup step for UDECX operations. ```c _IRQL_requires_max_(PASSIVE_LEVEL) _Must_inspect_result_ NTSTATUS DMF_UdeClient_Static_DeviceInitInitialize( _In_ PWDFDEVICE_INIT DeviceInit ); ``` -------------------------------- ### DMF ModulePrepareHardware Callback Source: https://github.com/microsoft/dmf/blob/master/Dmf/Documentation/Driver Module Framework.md DMF calls this callback when the Client Driver receives EvtDevicePrepareHardware. Modules generally do not use this callback; DMF_MODULE_OPEN_OPTION_OPEN_PrepareHardware and DMF_[ModuleName]_ResourcesAssign are preferred. ```c static NTSTATUS DMF_[ModuleName]_ModulePrepareHardware( _In_ DMFMODULE DmfModule, _In_ WDFCMRESLIST ResourcesRaw, _In_ WDFCMRESLIST ResourcesTranslated ) ``` -------------------------------- ### DMF_ActivitySensor_Start Method Source: https://github.com/microsoft/dmf/blob/master/Dmf/Modules.Library/Dmf_ActivitySensor.md Starts the monitoring of the ActivitySensor sensor. This method is optional as the sensor starts by default. It operates at PASSIVE_LEVEL IRQL. ```c _IRQL_requires_max_(PASSIVE_LEVEL) _Must_inspect_result_ NTSTATUS DMF_ActivitySensor_Start( _In_ DMFMODULE DmfModule ); ``` -------------------------------- ### Initialize DMF Device and Modules Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/SwitchBar3/README.md Initializes the DMF device and its modules. This includes setting device attributes, configuring PnP/Power callbacks, and creating the default I/O queue. Ensure all mandatory DMF_DmfDeviceInitHook* calls are made. ```c // Set any device attributes needed. // WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_UNKNOWN); WdfDeviceInitSetExclusive(DeviceInit, FALSE); // This is a filter driver that loads on OSRUSBFX2 driver. // WdfFdoInitSetFilter(DeviceInit); // DMF Client drivers that are filter drivers must also make this call. // DMF_DmfFdoSetFilter(dmfDeviceInit); // Define a device context type. // WDF_OBJECT_ATTRIBUTES_INIT_CONTEXT_TYPE(&objectAttributes, DEVICE_CONTEXT); // Create the Client driver's WDFDEVICE. // ntStatus = WdfDeviceCreate(&DeviceInit, &objectAttributes, &device); if (! NT_SUCCESS(ntStatus)) { goto Exit; } // This driver will filter IOCTLS, so set up a default queue. // WDF_IO_QUEUE_CONFIG_INIT_DEFAULT_QUEUE(&queueConfig, WdfIoQueueDispatchSequential); queueConfig.EvtIoDeviceControl = SwitchBarModuleDeviceIoControl; // When a DMF Client driver creates a default queue, it must also make this call. // This call is not needed if the Client driver does not create a default queue. // DMF_DmfDeviceInitHookQueueConfig(dmfDeviceInit, &queueConfig); ntStatus = WdfIoQueueCreate(device, &queueConfig, &objectAttributes, &queue); if (! NT_SUCCESS(ntStatus)) { goto Exit; } // Create the DMF Modules this Client driver will use. // dmfCallbacks.EvtDmfDeviceModulesAdd = DmfDeviceModulesAdd; DMF_DmfDeviceInitSetEventCallbacks(dmfDeviceInit, &dmfCallbacks); ntStatus = DMF_ModulesCreate(device, &dmfDeviceInit); if (! NT_SUCCESS(ntStatus)) { goto Exit; } Exit: if (dmfDeviceInit != NULL) { DMF_DmfDeviceInitFree(&dmfDeviceInit); } TraceEvents(TRACE_LEVEL_INFORMATION, TRACE_CALLBACK, "<--%!FUNC! ntStatus=%!STATUS!", ntStatus); return ntStatus; } #pragma code_seg() ``` -------------------------------- ### DMF Driver Initialization Source: https://context7.com/microsoft/dmf/llms.txt Sets up DMF driver entry points and uses DMF macros for simplified initialization of driver entry, cleanup, and device add callbacks. Ensure DMF library headers are included. ```c #include "DmfModules.Library.h" DRIVER_INITIALIZE DriverEntry; EVT_WDF_DRIVER_DEVICE_ADD MyDriverEvtDeviceAdd; EVT_WDF_OBJECT_CONTEXT_CLEANUP MyDriverEvtDriverContextCleanup; EVT_DMF_DEVICE_MODULES_ADD DmfDeviceModulesAdd; #pragma code_seg("INIT") DMF_DEFAULT_DRIVERENTRY(DriverEntry, MyDriverEvtDriverContextCleanup, MyDriverEvtDeviceAdd) #pragma code_seg() #pragma code_seg("PAGED") DMF_DEFAULT_DRIVERCLEANUP(MyDriverEvtDriverContextCleanup) DMF_DEFAULT_DEVICEADD(MyDriverEvtDeviceAdd, DmfDeviceModulesAdd) #pragma code_seg() ``` -------------------------------- ### Start All USB Target Pipes Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/Documentation/Compare-kmdf_fx2-to-kmdf_fx2_dmf/Files/driver_ioctl.c.html Starts all USB target pipes (Interrupt, Bulk Read, Bulk Write) for a given device context. This function checks the success of starting each pipe individually and returns the status. It's used to re-initialize communication after a stop or during device initialization. ```c NTSTATUS StartAllPipes( IN PDEVICE_CONTEXT DeviceContext ) { NTSTATUS status; status = WdfIoTargetStart(WdfUsbTargetPipeGetIoTarget(DeviceContext->InterruptPipe)); if (!NT_SUCCESS(status)) { return status; } status = WdfIoTargetStart(WdfUsbTargetPipeGetIoTarget(DeviceContext->BulkReadPipe)); if (!NT_SUCCESS(status)) { return status; } status = WdfIoTargetStart(WdfUsbTargetPipeGetIoTarget(DeviceContext->BulkWritePipe)); if (!NT_SUCCESS(status)) { return status; } return status; } ``` -------------------------------- ### Convert WDFDEVICE to Activity ID Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/Documentation/Compare-kmdf_fx2-to-kmdf_fx2_dmf/Files/driver_osrusbfx2.h.html This function converts a WDFDEVICE to a GUID representing an activity ID. It copies the memory of the WDFDEVICE into a GUID structure. ```C++ #ifndef GUID #define GUID GUID DeviceToActivityId( _In_ WDFDEVICE Device ) { GUID activity = {0}; RtlCopyMemory(&activity, &Device, sizeof(WDFDEVICE)); return activity; } #endif #endif ``` -------------------------------- ### Configure and Create WDF Device Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/NonPnp1/sys/README.md Configures the WDF device initialization settings, including assigning a name, setting I/O type to buffered, and device type. Finally, it creates the WDF device object. ```c // Assign the device name to the device. // ntStatus = WdfDeviceInitAssignName(DeviceInit, &deviceName); if (!NT_SUCCESS(ntStatus)) { goto Exit; } WdfDeviceInitSetIoType(DeviceInit, WdfDeviceIoBuffered); WdfDeviceInitSetDeviceType(DeviceInit, FILE_DEVICE_UNKNOWN); ntStatus = WdfDeviceCreate(&DeviceInit, &deviceAttributes, &device ); if ( !NT_SUCCESS ( ntStatus ) ) { goto Exit; } ``` -------------------------------- ### Log Write Start Event Source: https://github.com/microsoft/dmf/blob/master/DmfSamples/Documentation/Compare-kmdf_fx2-to-kmdf_fx2_dmf/Files/driver_bulkrwr.c.html Logs a write start event using the IRP activity ID or request handle. This is useful for tracing and debugging. ```c EventWriteWriteStart(&activity, WdfIoQueueGetDevice(Queue), (ULONG)Length); ```