diff options
Diffstat (limited to 'api')
-rw-r--r-- | api/adapter.c | 58 | ||||
-rw-r--r-- | api/logger.h | 2 | ||||
-rw-r--r-- | api/ntldr.h | 1 | ||||
-rw-r--r-- | api/rundll32.c | 1 |
4 files changed, 58 insertions, 4 deletions
diff --git a/api/adapter.c b/api/adapter.c index 9ae6608..80582d0 100644 --- a/api/adapter.c +++ b/api/adapter.c @@ -1030,6 +1030,8 @@ CreateAdapter( _Out_ WINTUN_ADAPTER **Adapter, _Inout_ BOOL *RebootRequired) { + LOG(WINTUN_LOG_INFO, L"Creating adapter"); + DWORD Result; HANDLE Mutex = NamespaceTakeMutex(Pool); if (!Mutex) @@ -1281,13 +1283,63 @@ CreateAdapter( Result = RegSetKeyValueW( TcpipInterfaceRegKey, NULL, L"EnableDeadGWDetect", REG_DWORD, &EnableDeadGWDetect, sizeof(EnableDeadGWDetect)); if (Result != ERROR_SUCCESS) + { LOG_ERROR(L"Failed to set EnableDeadGWDetect", Result); + goto cleanupTcpipInterfaceRegKey; + } Result = WintunSetAdapterName(a, Name); - if (Result == ERROR_SUCCESS) - *Adapter = a; - else + if (Result != ERROR_SUCCESS) + { LOG_ERROR(L"Failed to set adapter name", Result); + 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) + { + 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) + { + LOG_ERROR(L"Failed to setup adapter", Result); + goto cleanupTcpipInterfaceRegKey; + } + } + else + break; + } + LOG(WINTUN_LOG_WARN, L"Adapter setup error code vanished after initially there"); + } + + *Adapter = a; + +cleanupTcpipInterfaceRegKey: RegCloseKey(TcpipInterfaceRegKey); cleanupTcpipAdapterRegKey: RegCloseKey(TcpipAdapterRegKey); diff --git a/api/logger.h b/api/logger.h index 33a0e35..4bf8e04 100644 --- a/api/logger.h +++ b/api/logger.h @@ -19,7 +19,7 @@ WintunSetLogger(_In_ WINTUN_LOGGER_CALLBACK_FUNC NewLogger); _Post_equals_last_error_ DWORD LoggerError(_In_z_ const WCHAR *Prefix, _In_ DWORD Error); -inline _Post_equals_last_error_ DWORD +static inline _Post_equals_last_error_ DWORD LoggerLastError(_In_z_ const WCHAR *Prefix) { DWORD Error = GetLastError(); diff --git a/api/ntldr.h b/api/ntldr.h index 3511fd8..626a85f 100644 --- a/api/ntldr.h +++ b/api/ntldr.h @@ -34,3 +34,4 @@ typedef struct _RTL_PROCESS_MODULES #define STATUS_INFO_LENGTH_MISMATCH ((NTSTATUS)0xC0000004L) //TODO: #include <ntstatus.h> instead of this +#define STATUS_PNP_DEVICE_CONFIGURATION_PENDING ((NTSTATUS)0xC0000495L)
\ No newline at end of file diff --git a/api/rundll32.c b/api/rundll32.c index 1fa0bb1..3da204b 100644 --- a/api/rundll32.c +++ b/api/rundll32.c @@ -168,6 +168,7 @@ VOID __stdcall DoThingsForDebugging(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLin WintunEndSession(Session); assert(WintunDeleteAdapter(Adapter, TRUE, &RebootRequired) == ERROR_SUCCESS); assert(!RebootRequired); + system("pause"); } #endif |