2020-07-29 10:10:42 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0
|
|
|
|
*
|
2021-01-30 16:45:26 +01:00
|
|
|
* Copyright (C) 2018-2021 WireGuard LLC. All Rights Reserved.
|
2020-07-29 10:10:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2020-10-17 15:11:34 +02:00
|
|
|
#include "wintun.h"
|
2020-10-31 11:55:26 +01:00
|
|
|
#include <IPExport.h>
|
2020-10-15 11:32:06 +02:00
|
|
|
#include <SetupAPI.h>
|
2021-10-14 08:37:50 +02:00
|
|
|
#include <cfgmgr32.h>
|
2020-10-31 11:55:26 +01:00
|
|
|
#include <Windows.h>
|
2020-07-29 10:10:42 +02:00
|
|
|
|
2020-10-30 09:53:09 +01:00
|
|
|
#define WINTUN_HWID L"Wintun"
|
2021-10-12 07:21:31 +02:00
|
|
|
#define WINTUN_ENUMERATOR (IsWindows7 ? L"ROOT\\" WINTUN_HWID : L"SWD\\" WINTUN_HWID)
|
|
|
|
|
|
|
|
extern const DEVPROPKEY DEVPKEY_Wintun_Name;
|
|
|
|
|
|
|
|
typedef struct HSWDEVICE__ *HSWDEVICE;
|
2020-07-29 10:10:42 +02:00
|
|
|
|
2020-10-17 15:11:34 +02:00
|
|
|
/**
|
|
|
|
* Wintun adapter descriptor.
|
|
|
|
*/
|
2020-07-29 10:10:42 +02:00
|
|
|
typedef struct _WINTUN_ADAPTER
|
|
|
|
{
|
2021-10-12 07:21:31 +02:00
|
|
|
HSWDEVICE SwDevice;
|
2021-07-28 20:20:09 +02:00
|
|
|
HDEVINFO DevInfo;
|
|
|
|
SP_DEVINFO_DATA DevInfoData;
|
2021-10-12 07:21:31 +02:00
|
|
|
WCHAR *InterfaceFilename;
|
2020-07-29 10:10:42 +02:00
|
|
|
GUID CfgInstanceID;
|
2021-10-14 08:37:50 +02:00
|
|
|
WCHAR DevInstanceID[MAX_DEVICE_ID_LEN];
|
2020-07-29 10:10:42 +02:00
|
|
|
DWORD LuidIndex;
|
|
|
|
DWORD IfType;
|
2021-07-28 20:20:09 +02:00
|
|
|
DWORD IfIndex;
|
2020-07-29 10:10:42 +02:00
|
|
|
} WINTUN_ADAPTER;
|
2020-10-15 12:52:01 +02:00
|
|
|
/**
|
2020-10-17 15:11:34 +02:00
|
|
|
* @copydoc WINTUN_CREATE_ADAPTER_FUNC
|
2020-10-15 12:52:01 +02:00
|
|
|
*/
|
2021-10-12 07:21:31 +02:00
|
|
|
WINTUN_CREATE_ADAPTER_FUNC WintunCreateAdapter;
|
2021-07-28 20:20:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @copydoc WINTUN_OPEN_ADAPTER_FUNC
|
|
|
|
*/
|
2021-10-12 07:21:31 +02:00
|
|
|
WINTUN_OPEN_ADAPTER_FUNC WintunOpenAdapter;
|
2020-07-29 10:10:42 +02:00
|
|
|
|
2020-10-15 12:52:01 +02:00
|
|
|
/**
|
2021-10-12 07:21:31 +02:00
|
|
|
* @copydoc WINTUN_CLOSE_ADAPTER_FUNC
|
2020-10-15 12:52:01 +02:00
|
|
|
*/
|
2021-10-12 07:21:31 +02:00
|
|
|
WINTUN_CLOSE_ADAPTER_FUNC WintunCloseAdapter;
|
2021-07-28 20:20:09 +02:00
|
|
|
|
|
|
|
/**
|
2021-10-12 07:21:31 +02:00
|
|
|
* @copydoc WINTUN_GET_ADAPTER_LUID_FUNC
|
2021-07-28 20:20:09 +02:00
|
|
|
*/
|
2021-10-12 07:21:31 +02:00
|
|
|
WINTUN_GET_ADAPTER_LUID_FUNC WintunGetAdapterLUID;
|
2020-11-02 16:28:51 +01:00
|
|
|
|
|
|
|
/**
|
2021-10-12 07:21:31 +02:00
|
|
|
* Returns a handle to the adapter device object.
|
|
|
|
*
|
|
|
|
* @param Adapter Adapter handle obtained with WintunOpenAdapter or WintunCreateAdapter.
|
|
|
|
*
|
|
|
|
* @return If the function succeeds, the return value is adapter device object handle.
|
|
|
|
* If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error
|
|
|
|
* information, call GetLastError.
|
2020-11-02 16:28:51 +01:00
|
|
|
*/
|
2021-10-12 07:21:31 +02:00
|
|
|
_Return_type_success_(return != INVALID_HANDLE_VALUE)
|
|
|
|
HANDLE WINAPI
|
|
|
|
AdapterOpenDeviceObject(_In_ const WINTUN_ADAPTER *Adapter);
|
2021-07-28 20:20:09 +02:00
|
|
|
|
|
|
|
/**
|
2021-10-12 07:21:31 +02:00
|
|
|
* Returns the device object file name for an adapter instance ID.
|
|
|
|
*
|
|
|
|
* @param InstanceID The device instance ID of the adapter.
|
|
|
|
*
|
|
|
|
* @return If the function succeeds, the return value is the filename of the device object, which
|
|
|
|
* must be freed with Free(). If the function fails, the return value is INVALID_HANDLE_VALUE.
|
|
|
|
* To get extended error information, call GetLastError.
|
2021-07-28 20:20:09 +02:00
|
|
|
*/
|
2021-10-12 07:21:31 +02:00
|
|
|
_Must_inspect_result_
|
|
|
|
_Return_type_success_(return != NULL)
|
|
|
|
_Post_maybenull_
|
|
|
|
LPWSTR
|
|
|
|
AdapterGetDeviceObjectFileName(_In_z_ LPCWSTR InstanceId);
|
2021-07-28 20:20:09 +02:00
|
|
|
|
|
|
|
/**
|
2021-10-12 07:21:31 +02:00
|
|
|
* Cleans up adapters with no attached process.
|
2021-07-28 20:20:09 +02:00
|
|
|
*/
|
2021-10-12 07:21:31 +02:00
|
|
|
VOID AdapterCleanupOrphanedDevices(VOID);
|
2021-07-28 20:20:09 +02:00
|
|
|
|
|
|
|
/**
|
2021-10-12 07:21:31 +02:00
|
|
|
* Cleans up adapters that use the old enumerator.
|
2021-07-28 20:20:09 +02:00
|
|
|
*/
|
2021-10-12 07:21:31 +02:00
|
|
|
VOID AdapterCleanupLegacyDevices(VOID);
|
2021-07-28 20:20:09 +02:00
|
|
|
|
|
|
|
/**
|
2021-10-12 07:21:31 +02:00
|
|
|
* Removes the specified device instance.
|
|
|
|
*
|
|
|
|
* @param DevInfo Device info handle from SetupAPI.
|
|
|
|
* @param DevInfoData Device info data specifying which device.
|
|
|
|
*
|
|
|
|
* @return If the function succeeds, the return value is TRUE. If the
|
|
|
|
* function fails, the return value is FALSE. To get extended
|
|
|
|
* error information, call GetLastError.
|
2021-07-28 20:20:09 +02:00
|
|
|
*/
|
2021-10-12 07:21:31 +02:00
|
|
|
|
|
|
|
_Return_type_success_(return != FALSE)
|
|
|
|
BOOL
|
|
|
|
AdapterRemoveInstance(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoData);
|
2020-11-05 15:25:52 +01:00
|
|
|
|
|
|
|
/**
|
2021-10-12 07:21:31 +02:00
|
|
|
* Enables the specified device instance.
|
2020-11-05 15:25:52 +01:00
|
|
|
*
|
2021-10-12 07:21:31 +02:00
|
|
|
* @param DevInfo Device info handle from SetupAPI.
|
|
|
|
* @param DevInfoData Device info data specifying which device.
|
2020-11-05 15:25:52 +01:00
|
|
|
*
|
2021-10-12 07:21:31 +02:00
|
|
|
* @return If the function succeeds, the return value is TRUE. If the
|
|
|
|
* function fails, the return value is FALSE. To get extended
|
|
|
|
* error information, call GetLastError.
|
2021-07-28 20:20:09 +02:00
|
|
|
*/
|
2021-10-12 07:21:31 +02:00
|
|
|
|
|
|
|
_Return_type_success_(return != FALSE)
|
|
|
|
BOOL
|
|
|
|
AdapterEnableInstance(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoData);
|
|
|
|
|
2021-07-28 20:20:09 +02:00
|
|
|
/**
|
2021-10-12 07:21:31 +02:00
|
|
|
* Disables the specified device instance.
|
2021-07-28 20:20:09 +02:00
|
|
|
*
|
2021-10-12 07:21:31 +02:00
|
|
|
* @param DevInfo Device info handle from SetupAPI.
|
|
|
|
* @param DevInfoData Device info data specifying which device.
|
2021-07-28 20:20:09 +02:00
|
|
|
*
|
2021-10-12 07:21:31 +02:00
|
|
|
* @return If the function succeeds, the return value is TRUE. If the
|
|
|
|
* function fails, the return value is FALSE. To get extended
|
|
|
|
* error information, call GetLastError.
|
|
|
|
*/
|
|
|
|
|
|
|
|
_Return_type_success_(return != FALSE)
|
|
|
|
BOOL
|
|
|
|
AdapterDisableInstance(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoData);
|