From 3c8b92e80e66b29da3ccd8b0b3c4f15514d5b379 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Mon, 10 May 2021 11:10:35 +0200 Subject: [PATCH] api: use simpler problem status checking This reworks commit e51b49604b5d00a641b698e7c40d4d46a06644c9. Link: https://www.reddit.com/r/WireGuard/comments/n6yocf/unable_to_create_wintun_on_windows_7_laptop_with/ Reported-by: Alirz Signed-off-by: Jason A. Donenfeld --- api/adapter.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/api/adapter.c b/api/adapter.c index ec14d99..5cc0dad 100644 --- a/api/adapter.c +++ b/api/adapter.c @@ -1724,19 +1724,8 @@ static _Return_type_success_(return != NULL) WINTUN_ADAPTER *CreateAdapter( for (int Tries = 0; Tries < 1000; ++Tries) { DEVPROPTYPE PropertyType; - INT32 ProblemCode; NTSTATUS ProblemStatus; if (SetupDiGetDevicePropertyW( - DevInfo, - &DevInfoData, - &DEVPKEY_Device_ProblemCode, - &PropertyType, - (PBYTE)&ProblemCode, - sizeof(ProblemCode), - NULL, - 0) && - PropertyType == DEVPROP_TYPE_INT32 && ProblemCode && - SetupDiGetDevicePropertyW( DevInfo, &DevInfoData, &DEVPKEY_Device_ProblemStatus, @@ -1749,8 +1738,20 @@ static _Return_type_success_(return != NULL) WINTUN_ADAPTER *CreateAdapter( { if (ProblemStatus != STATUS_PNP_DEVICE_CONFIGURATION_PENDING || Tries == 999) { - LastError = RtlNtStatusToDosError(ProblemStatus); + INT32 ProblemCode; + if (!SetupDiGetDevicePropertyW( + DevInfo, + &DevInfoData, + &DEVPKEY_Device_ProblemCode, + &PropertyType, + (PBYTE)&ProblemCode, + sizeof(ProblemCode), + NULL, + 0) || + PropertyType != DEVPROP_TYPE_INT32) + ProblemCode = 0; LOG_ERROR(LastError, L"Failed to setup adapter (code: 0x%x, status: 0x%x)", ProblemCode, ProblemStatus); + LastError = RtlNtStatusToDosError(ProblemStatus); if (LastError == ERROR_SUCCESS) LastError = ERROR_NOT_READY; goto cleanupTcpipAdapterRegKey;