aboutsummaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-11-01 03:47:19 +0100
committerSimon Rozman <simon@rozman.si>2020-11-02 09:17:47 +0100
commit99097022fef94af4bea9d743de700b7ffb01e3c2 (patch)
tree5881998f61dd9a807db176bbfafc5136ee33788a /api
parentapi: check for duplicate adapter status (diff)
downloadwintun-99097022fef94af4bea9d743de700b7ffb01e3c2.tar.xz
wintun-99097022fef94af4bea9d743de700b7ffb01e3c2.zip
api: avoid call to CM_Get_DevNode_Status
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'api')
-rw-r--r--api/adapter.c61
1 files changed, 25 insertions, 36 deletions
diff --git a/api/adapter.c b/api/adapter.c
index 80582d0..95b844b 100644
--- a/api/adapter.c
+++ b/api/adapter.c
@@ -1295,46 +1295,35 @@ CreateAdapter(
goto cleanupTcpipInterfaceRegKey;
}
- ULONG Status, ProblemCode;
- Result = CM_MapCrToWin32Err(
- CM_Get_DevNode_Status(&Status, &ProblemCode, DevInfoData.DevInst, 0), ERROR_DEVICE_NOT_AVAILABLE);
- if (Result != ERROR_SUCCESS)
- {
- LOG_ERROR(L"Failed to get status of adapter", Result);
- goto cleanupTcpipInterfaceRegKey;
- }
- if (Status & DN_HAS_PROBLEM)
- {
- /* TODO: This GUIDs is in devpkey.h, but we can't link to it? Which dll? */
- static const DEVPROPKEY DEVPKEY_Device_ProblemStatus = {
- { 0x4340a6c5, 0x93fa, 0x4706, { 0x97, 0x2c, 0x7b, 0x64, 0x80, 0x08, 0xa5, 0xa7 } }, 12
- };
- DEVPROPTYPE PropertyType;
- for (int Tries = 0; Tries < 1000; Sleep(10), ++Tries)
+ /* TODO: This GUIDs is in devpkey.h, but we can't link to it? Which dll? */
+ static const DEVPROPKEY DEVPKEY_Device_ProblemStatus = {
+ { 0x4340a6c5, 0x93fa, 0x4706, { 0x97, 0x2c, 0x7b, 0x64, 0x80, 0x08, 0xa5, 0xa7 } }, 12
+ };
+ DEVPROPTYPE PropertyType;
+ for (int Tries = 0; Tries < 1000; ++Tries)
+ {
+ NTSTATUS ProblemStatus;
+ if (SetupDiGetDevicePropertyW(
+ DevInfo,
+ &DevInfoData,
+ &DEVPKEY_Device_ProblemStatus,
+ &PropertyType,
+ (PBYTE)&ProblemStatus,
+ sizeof(ProblemStatus),
+ NULL,
+ 0) &&
+ PropertyType == DEVPROP_TYPE_NTSTATUS)
{
- NTSTATUS ProblemStatus;
- if (SetupDiGetDevicePropertyW(
- DevInfo,
- &DevInfoData,
- &DEVPKEY_Device_ProblemStatus,
- &PropertyType,
- (PBYTE)&ProblemStatus,
- sizeof(ProblemStatus),
- NULL,
- 0) &&
- PropertyType == DEVPROP_TYPE_NTSTATUS)
+ Result = RtlNtStatusToDosError(ProblemStatus);
+ if (ProblemStatus != STATUS_PNP_DEVICE_CONFIGURATION_PENDING || Tries == 999)
{
- Result = RtlNtStatusToDosError(ProblemStatus);
- if (ProblemStatus != STATUS_PNP_DEVICE_CONFIGURATION_PENDING || Tries == 999)
- {
- LOG_ERROR(L"Failed to setup adapter", Result);
- goto cleanupTcpipInterfaceRegKey;
- }
+ LOG_ERROR(L"Failed to setup adapter", Result);
+ goto cleanupTcpipInterfaceRegKey;
}
- else
- break;
+ Sleep(10);
}
- LOG(WINTUN_LOG_WARN, L"Adapter setup error code vanished after initially there");
+ else
+ break;
}
*Adapter = a;