Files
ViGEmBus/sys/Driver.h

135 lines
3.5 KiB
C
Raw Normal View History

2017-08-31 18:32:11 +02:00
/*
2018-08-25 22:17:27 +02:00
* Virtual Gamepad Emulation Framework - Windows kernel-mode bus driver
*
2020-05-22 15:26:24 +02:00
* BSD 3-Clause License
2018-08-25 22:17:27 +02:00
*
2022-08-06 11:56:08 +02:00
* Copyright (c) 2018-2022, Nefarius Software Solutions e.U. and Contributors
2020-05-22 15:26:24 +02:00
* All rights reserved.
2018-08-25 22:17:27 +02:00
*
2020-05-22 15:26:24 +02:00
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
2020-05-22 15:26:24 +02:00
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
2020-05-22 15:26:24 +02:00
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2017-08-31 18:32:11 +02:00
*/
#pragma once
2020-11-22 09:46:25 +01:00
#pragma warning(disable:5040)
#include <DmfModules.Library.h>
#pragma warning(default:5040)
2017-08-31 18:32:11 +02:00
#include <ntddk.h>
#include <wdf.h>
#define NTSTRSAFE_LIB
#include <ntstrsafe.h>
2017-08-31 18:32:11 +02:00
#pragma region Macros
2020-05-13 21:37:57 +02:00
#define DRIVERNAME "ViGEm: "
2017-08-31 18:32:11 +02:00
2020-05-13 21:37:57 +02:00
#pragma endregion
2020-05-11 17:27:15 +02:00
2020-05-13 21:37:57 +02:00
//
// FDO (bus device) context data
//
typedef struct _FDO_DEVICE_DATA
{
//
// Counter of interface references
//
LONG InterfaceReferenceCounter;
2017-08-31 18:32:11 +02:00
2020-05-13 21:37:57 +02:00
//
// Next SessionId to assign to a file handle
//
LONG NextSessionId;
2017-08-31 18:32:11 +02:00
2020-05-13 21:37:57 +02:00
} FDO_DEVICE_DATA, * PFDO_DEVICE_DATA;
2018-05-13 22:27:53 +02:00
2020-05-13 21:37:57 +02:00
#define FDO_FIRST_SESSION_ID 100
2017-08-31 18:32:11 +02:00
2020-05-13 21:37:57 +02:00
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FDO_DEVICE_DATA, FdoGetData)
//
// Context data associated with file objects created by user mode applications
//
typedef struct _FDO_FILE_DATA
{
//
// SessionId associated with file handle. Used to map file handles to emulated gamepad devices
//
LONG SessionId;
} FDO_FILE_DATA, * PFDO_FILE_DATA;
WDF_DECLARE_CONTEXT_TYPE_WITH_NAME(FDO_FILE_DATA, FileObjectGetData)
2017-08-31 18:32:11 +02:00
2020-05-11 17:27:15 +02:00
EXTERN_C_START
2017-08-31 18:32:11 +02:00
#pragma region WDF callback prototypes
DRIVER_INITIALIZE DriverEntry;
EVT_WDF_DRIVER_DEVICE_ADD Bus_EvtDeviceAdd;
2020-05-12 17:42:08 +02:00
2017-08-31 18:32:11 +02:00
EVT_WDF_DEVICE_FILE_CREATE Bus_DeviceFileCreate;
2020-05-12 17:42:08 +02:00
2017-08-31 18:32:11 +02:00
EVT_WDF_FILE_CLOSE Bus_FileClose;
EVT_WDF_CHILD_LIST_CREATE_DEVICE Bus_EvtDeviceListCreatePdo;
2018-05-12 14:31:07 +02:00
EVT_WDF_OBJECT_CONTEXT_CLEANUP Bus_EvtDriverContextCleanup;
2017-08-31 18:32:11 +02:00
#pragma endregion
_IRQL_requires_max_(PASSIVE_LEVEL)
VOID
DmfDeviceModulesAdd(
_In_ WDFDEVICE Device,
_In_ PDMFMODULE_INIT DmfModuleInit
);
2017-08-31 18:32:11 +02:00
#pragma region Bus enumeration-specific functions
NTSTATUS
Bus_PlugInDevice(
_In_ WDFDEVICE Device,
_In_ WDFREQUEST Request,
_In_ BOOLEAN IsInternal,
_Out_ size_t* Transferred
);
NTSTATUS
Bus_UnPlugDevice(
_In_ WDFDEVICE Device,
_In_ WDFREQUEST Request,
_In_ BOOLEAN IsInternal,
_Out_ size_t* Transferred
);
#pragma endregion
2020-05-11 17:27:15 +02:00
EXTERN_C_END