diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-05-10 11:10:35 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-05-10 11:23:58 +0200 |
commit | 3c8b92e80e66b29da3ccd8b0b3c4f15514d5b379 (patch) | |
tree | be9f1aba0663da93a573320b442e1a8c0da428f4 /api | |
parent | api: check that GUID is valid before assuming it's in use (diff) | |
download | wintun-3c8b92e80e66b29da3ccd8b0b3c4f15514d5b379.tar.xz wintun-3c8b92e80e66b29da3ccd8b0b3c4f15514d5b379.zip |
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 <Jason@zx2c4.com>
Diffstat (limited to 'api')
-rw-r--r-- | api/adapter.c | 25 |
1 files 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,21 +1724,10 @@ 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, &PropertyType, (PBYTE)&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; |