summaryrefslogtreecommitdiffhomepage
path: root/windows/driverlogic/src/device.cpp
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2022-07-21 16:30:28 +0200
committerDavid Lönnhager <david.l@mullvad.net>2022-08-25 15:16:40 +0200
commit29df2434c5e726574379860329eb123c2139dad6 (patch)
tree34be2878dae0de5a5929d8eaa53f82cf89667fc1 /windows/driverlogic/src/device.cpp
parent91d8377262050012de75979e5c940cb6812f25ea (diff)
downloadmullvadvpn-29df2434c5e726574379860329eb123c2139dad6.tar.xz
mullvadvpn-29df2434c5e726574379860329eb123c2139dad6.zip
Remove ST setup from installer and increase robustness of cleanup
Cleanup will now succeed in these cases: 1. There is no devnode, but the driver service exists. 2. There is no driver service, but there is a devnode. 3. The service exists but isn't running.
Diffstat (limited to 'windows/driverlogic/src/device.cpp')
-rw-r--r--windows/driverlogic/src/device.cpp170
1 files changed, 0 insertions, 170 deletions
diff --git a/windows/driverlogic/src/device.cpp b/windows/driverlogic/src/device.cpp
index e38709f01d..71abb56266 100644
--- a/windows/driverlogic/src/device.cpp
+++ b/windows/driverlogic/src/device.cpp
@@ -38,47 +38,6 @@ constexpr SIZE_T ST_DRIVER_STATE_STARTED = 1;
// Onwards.
//
-void
-ThrowUpdateException
-(
- DWORD lastError,
- const char *operation
-)
-{
- if (ERROR_DEVICE_INSTALLER_NOT_READY == lastError)
- {
- bool deviceInstallDisabled = false;
-
- try
- {
- const auto key = common::registry::Registry::OpenKey
- (
- HKEY_LOCAL_MACHINE,
- L"SYSTEM\\CurrentControlSet\\Services\\DeviceInstall\\Parameters"
- );
-
- deviceInstallDisabled = (0 != key->readUint32(L"DeviceInstallDisabled"));
- }
- catch (...)
- {
- }
-
- if (deviceInstallDisabled)
- {
- throw common::error::WindowsException
- (
- "Device installs must be enabled to continue. "
- "Enable them in the Local Group Policy editor, or "
- "update the registry value DeviceInstallDisabled in "
- "[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\\DeviceInstall\\Parameters]",
- lastError
- );
- }
- }
-
- THROW_SETUPAPI_ERROR(lastError, operation);
-}
-
} // anonymous namespace
std::wstring
@@ -196,135 +155,6 @@ GetDeviceNetCfgInstanceId
}
void
-CreateDevice
-(
- const GUID &classGuid,
- const std::wstring &deviceName,
- const std::wstring &deviceHardwareId
-)
-{
- Log(L"Attempting to create device");
-
- const auto deviceInfoSet = SetupDiCreateDeviceInfoList(&classGuid, 0);
-
- if (INVALID_HANDLE_VALUE == deviceInfoSet)
- {
- THROW_SETUPAPI_ERROR(GetLastError(), "SetupDiCreateDeviceInfoList");
- }
-
- common::memory::ScopeDestructor scopeDestructor;
-
- scopeDestructor += [&deviceInfoSet]()
- {
- SetupDiDestroyDeviceInfoList(deviceInfoSet);
- };
-
- SP_DEVINFO_DATA devInfoData {0};
- devInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
-
- auto status = SetupDiCreateDeviceInfoW
- (
- deviceInfoSet,
- deviceName.c_str(),
- &classGuid,
- nullptr,
- 0,
- DICD_GENERATE_ID,
- &devInfoData
- );
-
- if (FALSE == status)
- {
- THROW_SETUPAPI_ERROR(GetLastError(), "SetupDiCreateDeviceInfoW");
- }
-
- status = SetupDiSetDeviceRegistryPropertyW
- (
- deviceInfoSet,
- &devInfoData,
- SPDRP_HARDWAREID,
- reinterpret_cast<const BYTE *>(deviceHardwareId.c_str()),
- static_cast<DWORD>(deviceHardwareId.size() * sizeof(wchar_t))
- );
-
- if (FALSE == status)
- {
- THROW_SETUPAPI_ERROR(GetLastError(), "SetupDiSetDeviceRegistryPropertyW");
- }
-
- //
- // Create a devnode in the PnP HW tree
- //
- status = SetupDiCallClassInstaller
- (
- DIF_REGISTERDEVICE,
- deviceInfoSet,
- &devInfoData
- );
-
- if (FALSE == status)
- {
- THROW_SETUPAPI_ERROR(GetLastError(), "SetupDiCallClassInstaller");
- }
-
- Log(L"Created new device successfully");
-}
-
-void
-InstallDriverForDevice
-(
- const std::wstring &deviceHardwareId,
- const std::wstring &infPath
-)
-{
- Log(L"Attempting to install new driver");
-
- DWORD installFlags = 0;
- BOOL rebootRequired = FALSE;
-
- for (;;)
- {
- auto result = UpdateDriverForPlugAndPlayDevicesW
- (
- nullptr,
- deviceHardwareId.c_str(),
- infPath.c_str(),
- installFlags,
- &rebootRequired
- );
-
- if (FALSE != result)
- {
- break;
- }
-
- const auto lastError = GetLastError();
-
- if (ERROR_NO_MORE_ITEMS == lastError
- && (0 == (installFlags & INSTALLFLAG_FORCE)))
- {
- Log(L"Driver installation/update failed. Attempting forced install.");
- installFlags |= INSTALLFLAG_FORCE;
-
- continue;
- }
-
- ThrowUpdateException(lastError, "UpdateDriverForPlugAndPlayDevicesW");
- }
-
- //
- // Driver successfully installed or updated
- //
-
- std::wstringstream ss;
-
- ss << L"Device driver update complete. Reboot required: "
- << rebootRequired;
-
- Log(ss.str());
-}
-
-void
UninstallDevice
(
const EnumeratedDevice &device