wintun/api/adapter.h
Simon Rozman abf6962144 api: simplify driver removal
When we install the Wintun driver to the store, we get exact oem<nn>.inf
filename of the driver in the store we just installed. Since the
installation should be only temporarily, we should uninstall only the
driver we installed.

This also eliminates the need for iterating driver store speeding up
things.

The code we removed was inherited from the installer.dll, where it made
perfect sense to remove all installed Wintun drivers in the update
process.

Suggested-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Simon Rozman <simon@rozman.si>
2020-10-31 10:41:48 +01:00

119 lines
3.3 KiB
C

/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (C) 2018-2020 WireGuard LLC. All Rights Reserved.
*/
#pragma once
#include "wintun.h"
#include <SetupAPI.h>
#define MAX_INSTANCE_ID MAX_PATH /* TODO: Is MAX_PATH always enough? */
#define WINTUN_HWID L"Wintun"
typedef struct _SP_DEVINFO_DATA_LIST
{
SP_DEVINFO_DATA Data;
struct _SP_DEVINFO_DATA_LIST *Next;
} SP_DEVINFO_DATA_LIST;
/**
* Retrieves driver information detail for a device information set or a particular device information element in the
* device information set.
*
* @param DevInfo A handle to the device information set that contains a device information element that
* represents the device for which to retrieve driver information.
*
* @param DevInfoData A pointer to a structure that specifies the device information element in DevInfo.
*
* @param DrvInfoData A pointer to a structure that specifies the driver information element that represents the
* driver for which to retrieve details.
*
* @param DrvInfoDetailData A pointer to a structure that receives detailed information about the specified driver.
* Must be released with HeapFree(ModuleHeap, 0, *DrvInfoDetailData) after use.
*
* @return ERROR_SUCCESS on success; Win32 error code otherwise.
*/
WINTUN_STATUS
AdapterGetDrvInfoDetail(
_In_ HDEVINFO DevInfo,
_In_opt_ SP_DEVINFO_DATA *DevInfoData,
_In_ SP_DRVINFO_DATA_W *DrvInfoData,
_Out_ SP_DRVINFO_DETAIL_DATA_W **DrvInfoDetailData);
/**
* Disables all Wintun adapters.
*
* @param DevInfo A handle to the device information set.
*
* @param DisabledAdapters Output list of disabled adapters. The adapters disabled are inserted in the list head.
*
* @return ERROR_SUCCESS on success; Win32 error code otherwise.
*/
WINTUN_STATUS
AdapterDisableAllOurs(_In_ HDEVINFO DevInfo, _Inout_ SP_DEVINFO_DATA_LIST **DisabledAdapters);
/**
* Enables all adapters.
*
* @param DevInfo A handle to the device information set.
*
* @param AdaptersToEnable Input list of adapters to enable.
*
* @return ERROR_SUCCESS on success; Win32 error code otherwise.
*/
WINTUN_STATUS
AdapterEnableAll(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA_LIST *AdaptersToEnable);
/**
* Removes all Wintun adapters.
*
* @return ERROR_SUCCESS on success; Win32 error code otherwise.
*/
WINTUN_STATUS
AdapterDeleteAllOurs(void);
void
AdapterInit(void);
/**
* Wintun adapter descriptor.
*/
typedef struct _WINTUN_ADAPTER
{
GUID CfgInstanceID;
WCHAR DevInstanceID[MAX_INSTANCE_ID];
DWORD LuidIndex;
DWORD IfType;
WCHAR Pool[MAX_POOL];
} WINTUN_ADAPTER;
/**
* @copydoc WINTUN_FREE_ADAPTER_FUNC
*/
void WINAPI
WintunFreeAdapter(_In_ WINTUN_ADAPTER *Adapter);
/**
* @copydoc WINTUN_GET_ADAPTER_DEVICE_OBJECT_FUNC
*/
WINTUN_STATUS WINAPI
WintunGetAdapterDeviceObject(_In_ const WINTUN_ADAPTER *Adapter, _Out_ HANDLE *Handle);
/**
* @copydoc WINTUN_CREATE_ADAPTER_FUNC
*/
WINTUN_STATUS WINAPI
WintunCreateAdapter(
_In_z_count_c_(MAX_POOL) const WCHAR *Pool,
_In_z_count_c_(MAX_ADAPTER_NAME) const WCHAR *Name,
_In_opt_ const GUID *RequestedGUID,
_Out_ WINTUN_ADAPTER **Adapter,
_Inout_ BOOL *RebootRequired);
/**
* @copydoc WINTUN_DELETE_ADAPTER_FUNC
*/
WINTUN_STATUS WINAPI
WintunDeleteAdapter(_In_ const WINTUN_ADAPTER *Adapter, _Inout_ BOOL *RebootRequired);