aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-10-07 21:40:24 +0000
committerJason A. Donenfeld <Jason@zx2c4.com>2021-10-11 16:12:09 +0000
commitd59103ba07d1ef30d7365ac9650431951893963f (patch)
tree94185849f3944c1b4bd7e041de33810ed73edd40
parentapi: adapter: replace INF Include/Needs hack with stub device (diff)
downloadwireguard-nt-d59103ba07d1ef30d7365ac9650431951893963f.tar.xz
wireguard-nt-d59103ba07d1ef30d7365ac9650431951893963f.zip
api: adapter: open devinst after arrival and skip stub on win8
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--api/adapter.c57
-rw-r--r--api/api.vcxproj2
-rw-r--r--setupapihost/host.c7
3 files changed, 43 insertions, 23 deletions
diff --git a/api/adapter.c b/api/adapter.c
index 14a4435..02c5336 100644
--- a/api/adapter.c
+++ b/api/adapter.c
@@ -595,8 +595,11 @@ WireGuardCreateAdapter(LPCWSTR Name, LPCWSTR TunnelType, const GUID *RequestedGU
LastError = GetLastError();
goto cleanupCreateContext;
}
- goto resumeAfterInstanceId;
+ goto skipSwDevice;
}
+ if (!IsWindows10)
+ goto skipStub;
+
SW_DEVICE_CREATE_INFO StubCreateInfo = { .cbSize = sizeof(StubCreateInfo),
.pszInstanceId = InstanceIdStr,
.pszzHardwareIds = L"",
@@ -659,6 +662,7 @@ WireGuardCreateAdapter(LPCWSTR Name, LPCWSTR TunnelType, const GUID *RequestedGU
SwDeviceClose(Adapter->SwDevice);
Adapter->SwDevice = NULL;
+skipStub:;
static const WCHAR Hwids[_countof(WIREGUARD_HWID) + 1 /*Multi-string terminator*/] = WIREGUARD_HWID;
SW_DEVICE_CREATE_INFO CreateInfo = { .cbSize = sizeof(CreateInfo),
.pszInstanceId = InstanceIdStr,
@@ -706,29 +710,26 @@ WireGuardCreateAdapter(LPCWSTR Name, LPCWSTR TunnelType, const GUID *RequestedGU
goto cleanupCreateContext;
}
-resumeAfterInstanceId:
- Adapter->DevInfo = SetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL);
- if (Adapter->DevInfo == INVALID_HANDLE_VALUE)
- {
- Adapter->DevInfo = NULL;
- LastError = LOG_LAST_ERROR(L"Failed to make device list");
- goto cleanupCreateContext;
- }
- Adapter->DevInfoData.cbSize = sizeof(Adapter->DevInfoData);
- if (!SetupDiOpenDeviceInfoW(
- Adapter->DevInfo, Adapter->DevInstanceID, NULL, DIOD_INHERIT_CLASSDRVS, &Adapter->DevInfoData))
- {
- LastError = LOG_LAST_ERROR(L"Failed to open device instance ID %s", Adapter->DevInstanceID);
- SetupDiDestroyDeviceInfoList(Adapter->DevInfo);
- Adapter->DevInfo = NULL;
- goto cleanupCreateContext;
- }
-
if (!WaitForInterface(Adapter->DevInstanceID))
{
+ LastError = GetLastError();
DEVPROPTYPE PropertyType = 0;
NTSTATUS NtStatus = 0;
INT32 ProblemCode = 0;
+ Adapter->DevInfo = SetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL);
+ if (Adapter->DevInfo == INVALID_HANDLE_VALUE)
+ {
+ Adapter->DevInfo = NULL;
+ goto cleanupCreateContext;
+ }
+ Adapter->DevInfoData.cbSize = sizeof(Adapter->DevInfoData);
+ if (!SetupDiOpenDeviceInfoW(
+ Adapter->DevInfo, Adapter->DevInstanceID, NULL, DIOD_INHERIT_CLASSDRVS, &Adapter->DevInfoData))
+ {
+ SetupDiDestroyDeviceInfoList(Adapter->DevInfo);
+ Adapter->DevInfo = NULL;
+ goto cleanupCreateContext;
+ }
if (!SetupDiGetDevicePropertyW(
Adapter->DevInfo,
&Adapter->DevInfoData,
@@ -758,6 +759,24 @@ resumeAfterInstanceId:
goto cleanupCreateContext;
}
+skipSwDevice:
+ Adapter->DevInfo = SetupDiCreateDeviceInfoListExW(&GUID_DEVCLASS_NET, NULL, NULL, NULL);
+ if (Adapter->DevInfo == INVALID_HANDLE_VALUE)
+ {
+ Adapter->DevInfo = NULL;
+ LastError = LOG_LAST_ERROR(L"Failed to make device list");
+ goto cleanupCreateContext;
+ }
+ Adapter->DevInfoData.cbSize = sizeof(Adapter->DevInfoData);
+ if (!SetupDiOpenDeviceInfoW(
+ Adapter->DevInfo, Adapter->DevInstanceID, NULL, DIOD_INHERIT_CLASSDRVS, &Adapter->DevInfoData))
+ {
+ LastError = LOG_LAST_ERROR(L"Failed to open device instance ID %s", Adapter->DevInstanceID);
+ SetupDiDestroyDeviceInfoList(Adapter->DevInfo);
+ Adapter->DevInfo = NULL;
+ goto cleanupCreateContext;
+ }
+
if (!PopulateAdapterData(Adapter))
{
LastError = LOG(WIREGUARD_LOG_ERR, L"Failed to populate adapter data");
diff --git a/api/api.vcxproj b/api/api.vcxproj
index 13d3a85..cce5cac 100644
--- a/api/api.vcxproj
+++ b/api/api.vcxproj
@@ -92,4 +92,4 @@
<Target Name="CleanNci">
<Delete Files="$(IntDir)nci.obj;$(IntDir)nci.lib" />
</Target>
-</Project>
+</Project> \ No newline at end of file
diff --git a/setupapihost/host.c b/setupapihost/host.c
index 6f643fd..e930358 100644
--- a/setupapihost/host.c
+++ b/setupapihost/host.c
@@ -6,6 +6,7 @@
#include <windows.h>
#include <delayimp.h>
#include <setupapi.h>
+#include <devguid.h>
#include <shellapi.h>
#include <intsafe.h>
#include <stdlib.h>
@@ -61,7 +62,7 @@ VOID __stdcall RemoveInstance(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int
goto cleanup;
WCHAR *InstanceId = Argv[2];
- HDEVINFO DevInfo = SetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL);
+ HDEVINFO DevInfo = SetupDiCreateDeviceInfoListExW(&GUID_DEVCLASS_NET, NULL, NULL, NULL);
if (DevInfo == INVALID_HANDLE_VALUE)
{
LastError = GetLastError();
@@ -104,7 +105,7 @@ VOID __stdcall EnableInstance(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int
goto cleanup;
WCHAR *InstanceId = Argv[2];
- HDEVINFO DevInfo = SetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL);
+ HDEVINFO DevInfo = SetupDiCreateDeviceInfoListExW(&GUID_DEVCLASS_NET, NULL, NULL, NULL);
if (DevInfo == INVALID_HANDLE_VALUE)
{
LastError = GetLastError();
@@ -147,7 +148,7 @@ VOID __stdcall DisableInstance(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, in
goto cleanup;
WCHAR *InstanceId = Argv[2];
- HDEVINFO DevInfo = SetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL);
+ HDEVINFO DevInfo = SetupDiCreateDeviceInfoListExW(&GUID_DEVCLASS_NET, NULL, NULL, NULL);
if (DevInfo == INVALID_HANDLE_VALUE)
{
LastError = GetLastError();