aboutsummaryrefslogtreecommitdiffstats
path: root/api/adapter.h
diff options
context:
space:
mode:
Diffstat (limited to 'api/adapter.h')
-rw-r--r--api/adapter.h128
1 files changed, 86 insertions, 42 deletions
diff --git a/api/adapter.h b/api/adapter.h
index 5f468b0..ec84d70 100644
--- a/api/adapter.h
+++ b/api/adapter.h
@@ -12,97 +12,141 @@
#define MAX_INSTANCE_ID MAX_PATH /* TODO: Is MAX_PATH always enough? */
#define WINTUN_HWID L"Wintun"
+#define WINTUN_ENUMERATOR (IsWindows7 ? L"ROOT\\" WINTUN_HWID : L"SWD\\" WINTUN_HWID)
+
+extern const DEVPROPKEY DEVPKEY_Wintun_Name;
+
+typedef struct HSWDEVICE__ *HSWDEVICE;
/**
* Wintun adapter descriptor.
*/
typedef struct _WINTUN_ADAPTER
{
+ HSWDEVICE SwDevice;
HDEVINFO DevInfo;
SP_DEVINFO_DATA DevInfoData;
+ WCHAR *InterfaceFilename;
GUID CfgInstanceID;
WCHAR DevInstanceID[MAX_INSTANCE_ID];
DWORD LuidIndex;
DWORD IfType;
DWORD IfIndex;
- WCHAR Pool[WINTUN_MAX_POOL];
} WINTUN_ADAPTER;
-
-/**
- * @copydoc WINTUN_FREE_ADAPTER_FUNC
- */
-WINTUN_FREE_ADAPTER_FUNC_IMPL WintunFreeAdapter;
-
/**
* @copydoc WINTUN_CREATE_ADAPTER_FUNC
*/
-WINTUN_CREATE_ADAPTER_FUNC_IMPL WintunCreateAdapter;
+WINTUN_CREATE_ADAPTER_FUNC WintunCreateAdapter;
/**
* @copydoc WINTUN_OPEN_ADAPTER_FUNC
*/
-WINTUN_OPEN_ADAPTER_FUNC_IMPL WintunOpenAdapter;
+WINTUN_OPEN_ADAPTER_FUNC WintunOpenAdapter;
/**
- * @copydoc WINTUN_DELETE_ADAPTER_FUNC
+ * @copydoc WINTUN_CLOSE_ADAPTER_FUNC
*/
-WINTUN_DELETE_ADAPTER_FUNC_IMPL WintunDeleteAdapter;
+WINTUN_CLOSE_ADAPTER_FUNC WintunCloseAdapter;
/**
- * @copydoc WINTUN_ENUM_ADAPTERS_FUNC
+ * @copydoc WINTUN_GET_ADAPTER_LUID_FUNC
*/
-WINTUN_ENUM_ADAPTERS_FUNC_IMPL WintunEnumAdapters;
+WINTUN_GET_ADAPTER_LUID_FUNC WintunGetAdapterLUID;
/**
- * @copydoc WINTUN_DELETE_POOL_DRIVER_FUNC
+ * 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.
*/
-WINTUN_DELETE_POOL_DRIVER_FUNC_IMPL WintunDeletePoolDriver;
+_Return_type_success_(return != INVALID_HANDLE_VALUE)
+HANDLE WINAPI
+AdapterOpenDeviceObject(_In_ const WINTUN_ADAPTER *Adapter);
/**
- * @copydoc WINTUN_GET_ADAPTER_LUID_FUNC
+ * 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.
*/
-WINTUN_GET_ADAPTER_LUID_FUNC_IMPL WintunGetAdapterLUID;
+_Must_inspect_result_
+_Return_type_success_(return != NULL)
+_Post_maybenull_
+LPWSTR
+AdapterGetDeviceObjectFileName(_In_z_ LPCWSTR InstanceId);
/**
- * @copydoc WINTUN_GET_ADAPTER_NAME_FUNC
+ * Cleans up adapters with no attached process.
*/
-WINTUN_GET_ADAPTER_NAME_FUNC_IMPL WintunGetAdapterName;
+VOID AdapterCleanupOrphanedDevices(VOID);
/**
- * @copydoc WINTUN_SET_ADAPTER_NAME_FUNC
+ * Cleans up adapters that use the old enumerator.
*/
-WINTUN_SET_ADAPTER_NAME_FUNC_IMPL WintunSetAdapterName;
+VOID AdapterCleanupLegacyDevices(VOID);
/**
- * @copydoc WINTUN_GET_RUNNING_DRIVER_VERSION_FUNC
+ * 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.
*/
-WINTUN_GET_RUNNING_DRIVER_VERSION_FUNC_IMPL WintunGetRunningDriverVersion;
+
+_Return_type_success_(return != FALSE)
+BOOL
+AdapterRemoveInstance(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoData);
/**
- * Returns a handle to the adapter device object.
+ * Enables the specified device instance.
*
- * @param Adapter Adapter handle obtained with WintunOpenAdapter or WintunCreateAdapter.
+ * @param DevInfo Device info handle from SetupAPI.
+ * @param DevInfoData Device info data specifying which device.
*
- * @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.
+ * @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 != INVALID_HANDLE_VALUE)
-HANDLE WINAPI
-AdapterOpenDeviceObject(_In_ const WINTUN_ADAPTER *Adapter);
+
+_Return_type_success_(return != FALSE)
+BOOL
+AdapterEnableInstance(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoData);
+
/**
- * Returns an adapter object based on a devnode instance ID.
+ * Disables the specified device instance.
*
- * @param Pool Pool name of adapter object to be opened.
+ * @param DevInfo Device info handle from SetupAPI.
+ * @param DevInfoData Device info data specifying which device.
*
- * @param DevInstanceID Instance ID of devnode for opening adapter.
+ * @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);
+
+/**
+ * Force closes all device handles of the specified device instance.
*
- * @return If the function succeeds, the return value is adapter object..
- * If the function fails, the return value is NULL. To get extended error
- * information, call GetLastError.
+ * @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.
*/
-_Must_inspect_result_
-_Return_type_success_(return != NULL)
-_Post_maybenull_
-WINTUN_ADAPTER *
-AdapterOpenFromDevInstanceId(_In_z_ LPCWSTR Pool, _In_z_ LPCWSTR DevInstanceID);
+
+_Return_type_success_(return != FALSE)
+BOOL
+AdapterForceCloseHandles(_In_ HDEVINFO DevInfo, _In_ SP_DEVINFO_DATA *DevInfoData);