[ros-diffs] [hpoussin] 29817: Code refactoring to be able to handle installation of network protocols/services/clients

hpoussin at svn.reactos.org hpoussin at svn.reactos.org
Tue Oct 23 10:25:53 CEST 2007


Author: hpoussin
Date: Tue Oct 23 12:25:53 2007
New Revision: 29817

URL: http://svn.reactos.org/svn/reactos?rev=29817&view=rev
Log:
Code refactoring to be able to handle installation of network protocols/services/clients

Modified:
    trunk/reactos/dll/win32/netcfgx/netcfgx.c
    trunk/reactos/dll/win32/netcfgx/netcfgx.h

Modified: trunk/reactos/dll/win32/netcfgx/netcfgx.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netcfgx/netcfgx.c?rev=29817&r1=29816&r2=29817&view=diff
==============================================================================
--- trunk/reactos/dll/win32/netcfgx/netcfgx.c (original)
+++ trunk/reactos/dll/win32/netcfgx/netcfgx.c Tue Oct 23 12:25:53 2007
@@ -1,16 +1,17 @@
 /*
  * COPYRIGHT:       See COPYING in the top level directory
- * PROJECT:         ReactOS Configuration of networkd devices
- * FILE:            lib/netcfgx/netcfgx.c
+ * PROJECT:         ReactOS Configuration of network devices
+ * FILE:            dll/win32/netcfgx/netcfgx.c
  * PURPOSE:         Network devices installer
  *
  * PROGRAMMERS:     Hervé Poussineau (hpoussin at reactos.org)
  */
 
+#define INITGUID
+#include "netcfgx.h"
+
 #define NDEBUG
 #include <debug.h>
-
-#include "netcfgx.h"
 
 /* Append a REG_SZ to an existing REG_MULTI_SZ string in the registry.
  * If the value doesn't exist, create it.
@@ -169,6 +170,311 @@
 	return ERROR_SUCCESS;
 }
 
+static DWORD
+InstallNetDevice(
+	IN HDEVINFO DeviceInfoSet,
+	IN PSP_DEVINFO_DATA DeviceInfoData,
+	LPCWSTR UuidString,
+	DWORD Characteristics,
+	LPCWSTR BusType)
+{
+	LPWSTR InstanceId = NULL;
+	LPWSTR DeviceName = NULL;
+	LPWSTR ExportName = NULL;
+	LONG rc;
+	HKEY hKey = NULL;
+	HKEY hNetworkKey = NULL;
+	HKEY hLinkageKey = NULL;
+	HKEY hConnectionKey = NULL;
+	DWORD dwShowIcon, dwLength;
+	SP_DEVINSTALL_PARAMS_W installParams;
+
+	/* Get Instance ID */
+	if (SetupDiGetDeviceInstanceIdW(DeviceInfoSet, DeviceInfoData, NULL, 0, &dwLength))
+	{
+		DPRINT("SetupDiGetDeviceInstanceIdW() returned TRUE. FALSE expected\n");
+		rc = ERROR_GEN_FAILURE;
+		goto cleanup;
+	}
+	InstanceId = HeapAlloc(GetProcessHeap(), 0, dwLength * sizeof(WCHAR));
+	if (!InstanceId)
+	{
+		DPRINT("HeapAlloc() failed\n");
+		rc = ERROR_NOT_ENOUGH_MEMORY;
+		goto cleanup;
+	}
+	if (!SetupDiGetDeviceInstanceIdW(DeviceInfoSet, DeviceInfoData, InstanceId, dwLength, NULL))
+	{
+		rc = GetLastError();
+		DPRINT("SetupDiGetDeviceInstanceIdW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+
+	/* Create device name */
+	DeviceName = HeapAlloc(GetProcessHeap(), 0, (wcslen(L"\\Device\\") + wcslen(UuidString)) * sizeof(WCHAR) + sizeof(UNICODE_NULL));
+	if (!DeviceName)
+	{
+		DPRINT("HeapAlloc() failed\n");
+		rc = ERROR_NOT_ENOUGH_MEMORY;
+		goto cleanup;
+	}
+	wcscpy(DeviceName, L"\\Device\\");
+	wcscat(DeviceName, UuidString);
+
+	/* Create export name */
+	ExportName = HeapAlloc(GetProcessHeap(), 0, (wcslen(L"\\Device\\Tcpip_") + wcslen(UuidString)) * sizeof(WCHAR) + sizeof(UNICODE_NULL));
+	if (!ExportName)
+	{
+		DPRINT("HeapAlloc() failed\n");
+		rc = ERROR_NOT_ENOUGH_MEMORY;
+		goto cleanup;
+	}
+	wcscpy(ExportName, L"\\Device\\Tcpip_");
+	wcscat(ExportName, UuidString);
+
+	/* Write Tcpip parameters in new service Key */
+	rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services", 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hKey, NULL);
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = RegCreateKeyExW(hKey, UuidString, 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hNetworkKey, NULL);
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	RegCloseKey(hKey);
+	hKey = NULL;
+	rc = RegCreateKeyExW(hNetworkKey, L"Parameters\\Tcpip", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, NULL);
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	RegCloseKey(hNetworkKey);
+	hNetworkKey = NULL;
+	rc = RegSetValueExW(hKey, L"DefaultGateway", 0, REG_SZ, (const BYTE*)L"0.0.0.0", (wcslen(L"0.0.0.0") + 1) * sizeof(WCHAR));
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = RegSetValueExW(hKey, L"IPAddress", 0, REG_SZ, (const BYTE*)L"0.0.0.0", (wcslen(L"0.0.0.0") + 1) * sizeof(WCHAR));
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = RegSetValueExW(hKey, L"SubnetMask", 0, REG_SZ, (const BYTE*)L"0.0.0.0", (wcslen(L"0.0.0.0") + 1) * sizeof(WCHAR));
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	RegCloseKey(hKey);
+	hKey = NULL;
+
+	/* Write 'Linkage' key in hardware key */
+#if _WIN32_WINNT >= 0x502
+	hKey = SetupDiOpenDevRegKey(DeviceInfoSet, DeviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_READ | KEY_WRITE);
+#else
+	hKey = SetupDiOpenDevRegKey(DeviceInfoSet, DeviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_ALL_ACCESS);
+#endif
+	if (hKey == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_NOT_FOUND)
+		hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet, DeviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, NULL, NULL);
+	if (hKey == INVALID_HANDLE_VALUE)
+	{
+		hKey = NULL;
+		rc = GetLastError();
+		DPRINT("SetupDiCreateDevRegKeyW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = RegSetValueExW(hKey, L"NetCfgInstanceId", 0, REG_SZ, (const BYTE*)UuidString, (wcslen(UuidString) + 1) * sizeof(WCHAR));
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = RegSetValueExW(hKey, L"Characteristics", 0, REG_DWORD, (const BYTE*)&Characteristics, sizeof(DWORD));
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	if (BusType)
+		rc = RegSetValueExW(hKey, L"BusType", 0, REG_SZ, (const BYTE*)BusType, (wcslen(BusType) + 1) * sizeof(WCHAR));
+		if (rc != ERROR_SUCCESS)
+		{
+			DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
+			goto cleanup;
+		}
+	rc = RegCreateKeyExW(hKey, L"Linkage", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hLinkageKey, NULL);
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = RegSetValueExW(hLinkageKey, L"Export", 0, REG_SZ, (const BYTE*)DeviceName, (wcslen(DeviceName) + 1) * sizeof(WCHAR));
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = RegSetValueExW(hLinkageKey, L"RootDevice", 0, REG_SZ, (const BYTE*)UuidString, (wcslen(UuidString) + 1) * sizeof(WCHAR));
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = RegSetValueExW(hLinkageKey, L"UpperBind", 0, REG_SZ, (const BYTE*)L"Tcpip", (wcslen(L"Tcpip") + 1) * sizeof(WCHAR));
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	RegCloseKey(hKey);
+	hKey = NULL;
+
+	/* Write connection information in network subkey */
+	rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}", 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hNetworkKey, NULL);
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = RegCreateKeyExW(hNetworkKey, UuidString, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_CREATE_SUB_KEY, NULL, &hKey, NULL);
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = RegCreateKeyExW(hKey, L"Connection", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hConnectionKey, NULL);
+	RegCloseKey(hKey);
+	hKey = NULL;
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = RegSetValueExW(hConnectionKey, L"Name", 0, REG_SZ, (const BYTE*)L"Network connection", (wcslen(L"Network connection") + 1) * sizeof(WCHAR));
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = RegSetValueExW(hConnectionKey, L"PnpInstanceId", 0, REG_SZ, (const BYTE*)InstanceId, (wcslen(InstanceId) + 1) * sizeof(WCHAR));
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	dwShowIcon = 1;
+	rc = RegSetValueExW(hConnectionKey, L"ShowIcon", 0, REG_DWORD, (const BYTE*)&dwShowIcon, sizeof(dwShowIcon));
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+
+	/* Write linkage information in Tcpip service */
+	rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Linkage", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &hKey, NULL);
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = AppendStringToMultiSZ(hKey, L"Bind", DeviceName);
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("AppendStringToMultiSZ() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = AppendStringToMultiSZ(hKey, L"Export", ExportName);
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("AppendStringToMultiSZ() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = AppendStringToMultiSZ(hKey, L"Route", UuidString);
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("AppendStringToMultiSZ() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+
+	/* Install additionnal services */
+	rc = InstallAdditionalServices(NULL);
+	if (rc != ERROR_SUCCESS)
+	{
+		DPRINT("InstallAdditionalServices() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+
+	/* HACK: hpoussin, Dec 2005. TCP/IP driver is not able to manage devices
+	 * which are installed after its startup. So, we have to reboot to take
+	 * this new netcard into account.
+	 */
+	/* Should we reboot? */
+	installParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS_W);
+	if (!SetupDiGetDeviceInstallParamsW(
+		DeviceInfoSet,
+		DeviceInfoData,
+		&installParams))
+	{
+		rc = GetLastError();
+		DPRINT("SetupDiGetDeviceInstallParams() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	installParams.Flags |= DI_NEEDRESTART;
+	if (!SetupDiSetDeviceInstallParamsW(
+		DeviceInfoSet,
+		DeviceInfoData,
+		&installParams))
+	{
+		rc = GetLastError();
+		DPRINT("SetupDiSetDeviceInstallParams() failed with error 0x%lx\n", rc);
+		goto cleanup;
+	}
+	rc = ERROR_SUCCESS;
+
+cleanup:
+	HeapFree(GetProcessHeap(), 0, InstanceId);
+	HeapFree(GetProcessHeap(), 0, DeviceName);
+	HeapFree(GetProcessHeap(), 0, ExportName);
+	if (hKey != NULL)
+		RegCloseKey(hKey);
+	if (hNetworkKey != NULL)
+		RegCloseKey(hNetworkKey);
+	if (hLinkageKey != NULL)
+		RegCloseKey(hLinkageKey);
+	if (hConnectionKey != NULL)
+		RegCloseKey(hConnectionKey);
+	return rc;
+}
+
+static DWORD
+InstallNetClient(VOID)
+{
+	DPRINT1("Installation of network clients is not yet supported\n");
+	return ERROR_GEN_FAILURE;
+}
+
+static DWORD
+InstallNetService(VOID)
+{
+	DPRINT1("Installation of network services is not yet supported\n");
+	return ERROR_GEN_FAILURE;
+}
+
+static DWORD
+InstallNetTransport(VOID)
+{
+	DPRINT1("Installation of network protocols is not yet supported\n");
+	return ERROR_GEN_FAILURE;
+}
+
 DWORD WINAPI
 NetClassInstaller(
 	IN DI_FUNCTION InstallFunction,
@@ -186,18 +492,10 @@
 	LPWSTR BusType = NULL;
 	RPC_STATUS RpcStatus;
 	UUID Uuid;
-	LPWSTR InstanceId = NULL;
 	LPWSTR UuidRpcString = NULL;
 	LPWSTR UuidString = NULL;
-	LPWSTR DeviceName = NULL;
-	LPWSTR ExportName = NULL;
 	LONG rc;
-	DWORD dwShowIcon, dwLength;
-	HKEY hKey = NULL;
-	HKEY hLinkageKey = NULL;
-	HKEY hNetworkKey = NULL;
-	HKEY hConnectionKey = NULL;
-	SP_DEVINSTALL_PARAMS_W installParams;
+	DWORD dwLength;
 
 	if (InstallFunction != DIF_INSTALLDEVICE)
 		return ERROR_DI_DO_DEFAULT;
@@ -234,27 +532,6 @@
 		goto cleanup;
 	}
 
-	/* Get Instance ID */
-	if (SetupDiGetDeviceInstanceIdW(DeviceInfoSet, DeviceInfoData, NULL, 0, &dwLength))
-	{
-		DPRINT("SetupDiGetDeviceInstanceIdW() returned TRUE. FALSE expected\n");
-		rc = ERROR_GEN_FAILURE;
-		goto cleanup;
-	}
-	InstanceId = HeapAlloc(GetProcessHeap(), 0, dwLength * sizeof(WCHAR));
-	if (!InstanceId)
-	{
-		DPRINT("HeapAlloc() failed\n");
-		rc = ERROR_NOT_ENOUGH_MEMORY;
-		goto cleanup;
-	}
-	if (!SetupDiGetDeviceInstanceIdW(DeviceInfoSet, DeviceInfoData, InstanceId, dwLength, NULL))
-	{
-		rc = GetLastError();
-		DPRINT("SetupDiGetDeviceInstanceIdW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-
 	/* Get Characteristics and BusType (optional) from .inf file */
 	if (!SetupFindFirstLineW(hInf, SectionName, L"Characteristics", &InfContext))
 	{
@@ -270,30 +547,31 @@
 		goto cleanup;
 	}
 	Characteristics = (DWORD)CharacteristicsInt;
-	if (SetupFindFirstLineW(hInf, SectionName, L"BusType", &InfContext))
-	{
-		if (!SetupGetStringFieldW(&InfContext, 1, NULL, 0, &dwLength))
+	if (IsEqualIID(&DeviceInfoData->ClassGuid, &GUID_DEVCLASS_NET))
+	{
+		if (SetupFindFirstLineW(hInf, SectionName, L"BusType", &InfContext))
 		{
-			rc = GetLastError();
-			DPRINT("SetupGetStringFieldW() failed with error 0x%lx\n", rc);
-			goto cleanup;
+			if (!SetupGetStringFieldW(&InfContext, 1, NULL, 0, &dwLength))
+			{
+				rc = GetLastError();
+				DPRINT("SetupGetStringFieldW() failed with error 0x%lx\n", rc);
+				goto cleanup;
+			}
+			BusType = HeapAlloc(GetProcessHeap(), 0, dwLength * sizeof(WCHAR));
+			if (!BusType)
+			{
+				DPRINT("HeapAlloc() failed\n");
+				rc = ERROR_NOT_ENOUGH_MEMORY;
+				goto cleanup;
+			}
+			if (!SetupGetStringFieldW(&InfContext, 1, BusType, dwLength, NULL))
+			{
+				rc = GetLastError();
+				DPRINT("SetupGetStringFieldW() failed with error 0x%lx\n", rc);
+				goto cleanup;
+			}
 		}
-		BusType = HeapAlloc(GetProcessHeap(), 0, dwLength * sizeof(WCHAR));
-		if (!BusType)
-		{
-			DPRINT("HeapAlloc() failed\n");
-			rc = ERROR_NOT_ENOUGH_MEMORY;
-			goto cleanup;
-		}
-		if (!SetupGetStringFieldW(&InfContext, 1, BusType, dwLength, NULL))
-		{
-			rc = GetLastError();
-			DPRINT("SetupGetStringFieldW() failed with error 0x%lx\n", rc);
-			goto cleanup;
-		}
-	}
-	else
-		BusType = NULL;
+	}
 
 	/* Create a new UUID */
 	RpcStatus = UuidCreate(&Uuid);
@@ -323,235 +601,19 @@
 	wcscat(UuidString, UuidRpcString);
 	wcscat(UuidString, L"}");
 
-	/* Create device name */
-	DeviceName = HeapAlloc(GetProcessHeap(), 0, (wcslen(L"\\Device\\") + wcslen(UuidString)) * sizeof(WCHAR) + sizeof(UNICODE_NULL));
-	if (!DeviceName)
-	{
-		DPRINT("HeapAlloc() failed\n");
-		rc = ERROR_NOT_ENOUGH_MEMORY;
-		goto cleanup;
-	}
-	wcscpy(DeviceName, L"\\Device\\");
-	wcscat(DeviceName, UuidString);
-
-	/* Create export name */
-	ExportName = HeapAlloc(GetProcessHeap(), 0, (wcslen(L"\\Device\\Tcpip_") + wcslen(UuidString)) * sizeof(WCHAR) + sizeof(UNICODE_NULL));
-	if (!ExportName)
-	{
-		DPRINT("HeapAlloc() failed\n");
-		rc = ERROR_NOT_ENOUGH_MEMORY;
-		goto cleanup;
-	}
-	wcscpy(ExportName, L"\\Device\\Tcpip_");
-	wcscat(ExportName, UuidString);
-
-	/* Write Tcpip parameters in new service Key */
-	rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services", 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hKey, NULL);
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = RegCreateKeyExW(hKey, UuidString, 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hNetworkKey, NULL);
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	RegCloseKey(hKey);
-	hKey = NULL;
-	rc = RegCreateKeyExW(hNetworkKey, L"Parameters\\Tcpip", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hKey, NULL);
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	RegCloseKey(hNetworkKey);
-	hNetworkKey = NULL;
-	rc = RegSetValueExW(hKey, L"DefaultGateway", 0, REG_SZ, (const BYTE*)L"0.0.0.0", (wcslen(L"0.0.0.0") + 1) * sizeof(WCHAR));
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = RegSetValueExW(hKey, L"IPAddress", 0, REG_SZ, (const BYTE*)L"0.0.0.0", (wcslen(L"0.0.0.0") + 1) * sizeof(WCHAR));
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = RegSetValueExW(hKey, L"SubnetMask", 0, REG_SZ, (const BYTE*)L"0.0.0.0", (wcslen(L"0.0.0.0") + 1) * sizeof(WCHAR));
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	RegCloseKey(hKey);
-	hKey = NULL;
-
-	/* Write 'Linkage' key in hardware key */
-#if _WIN32_WINNT >= 0x502
-	hKey = SetupDiOpenDevRegKey(DeviceInfoSet, DeviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_READ | KEY_WRITE);
-#else
-	hKey = SetupDiOpenDevRegKey(DeviceInfoSet, DeviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, KEY_ALL_ACCESS);
-#endif
-	if (hKey == INVALID_HANDLE_VALUE && GetLastError() == ERROR_FILE_NOT_FOUND)
-		hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet, DeviceInfoData, DICS_FLAG_GLOBAL, 0, DIREG_DRV, NULL, NULL);
-	if (hKey == INVALID_HANDLE_VALUE)
-	{
-		hKey = NULL;
-		rc = GetLastError();
-		DPRINT("SetupDiCreateDevRegKeyW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = RegSetValueExW(hKey, L"NetCfgInstanceId", 0, REG_SZ, (const BYTE*)UuidString, (wcslen(UuidString) + 1) * sizeof(WCHAR));
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = RegSetValueExW(hKey, L"Characteristics", 0, REG_DWORD, (const BYTE*)&Characteristics, sizeof(DWORD));
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	if (BusType)
-		rc = RegSetValueExW(hKey, L"BusType", 0, REG_SZ, (const BYTE*)BusType, (wcslen(BusType) + 1) * sizeof(WCHAR));
-		if (rc != ERROR_SUCCESS)
-		{
-			DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
-			goto cleanup;
-		}
-	rc = RegCreateKeyExW(hKey, L"Linkage", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hLinkageKey, NULL);
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = RegSetValueExW(hLinkageKey, L"Export", 0, REG_SZ, (const BYTE*)DeviceName, (wcslen(DeviceName) + 1) * sizeof(WCHAR));
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = RegSetValueExW(hLinkageKey, L"RootDevice", 0, REG_SZ, (const BYTE*)UuidString, (wcslen(UuidString) + 1) * sizeof(WCHAR));
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = RegSetValueExW(hLinkageKey, L"UpperBind", 0, REG_SZ, (const BYTE*)L"Tcpip", (wcslen(L"Tcpip") + 1) * sizeof(WCHAR));
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	RegCloseKey(hKey);
-	hKey = NULL;
-
-	/* Write connection information in network subkey */
-	rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}", 0, NULL, REG_OPTION_NON_VOLATILE, 0, NULL, &hNetworkKey, NULL);
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = RegCreateKeyExW(hNetworkKey, UuidString, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_CREATE_SUB_KEY, NULL, &hKey, NULL);
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = RegCreateKeyExW(hKey, L"Connection", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, &hConnectionKey, NULL);
-	RegCloseKey(hKey);
-	hKey = NULL;
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = RegSetValueExW(hConnectionKey, L"Name", 0, REG_SZ, (const BYTE*)L"Network connection", (wcslen(L"Network connection") + 1) * sizeof(WCHAR));
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = RegSetValueExW(hConnectionKey, L"PnpInstanceId", 0, REG_SZ, (const BYTE*)InstanceId, (wcslen(InstanceId) + 1) * sizeof(WCHAR));
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	dwShowIcon = 1;
-	rc = RegSetValueExW(hConnectionKey, L"ShowIcon", 0, REG_DWORD, (const BYTE*)&dwShowIcon, sizeof(dwShowIcon));
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegSetValueExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-
-	/* Write linkage information in Tcpip service */
-	rc = RegCreateKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Linkage", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_QUERY_VALUE | KEY_SET_VALUE, NULL, &hKey, NULL);
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("RegCreateKeyExW() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = AppendStringToMultiSZ(hKey, L"Bind", DeviceName);
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("AppendStringToMultiSZ() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = AppendStringToMultiSZ(hKey, L"Export", ExportName);
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("AppendStringToMultiSZ() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = AppendStringToMultiSZ(hKey, L"Route", UuidString);
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("AppendStringToMultiSZ() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-
-	/* Install additionnal services */
-	/* FIXME: do it only if it is a network adapter! */
-	rc = InstallAdditionalServices(NULL);
-	if (rc != ERROR_SUCCESS)
-	{
-		DPRINT("InstallAdditionalServices() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-
-	/* HACK: hpoussin, Dec 2005. TCP/IP driver is not able to manage devices
-	 * which are installed after its startup. So, we have to reboot to take
-	 * this new netcard into account.
-	 */
-	/* Should we reboot? */
-	installParams.cbSize = sizeof(SP_DEVINSTALL_PARAMS_W);
-	if (!SetupDiGetDeviceInstallParamsW(
-		DeviceInfoSet,
-		DeviceInfoData,
-		&installParams))
-	{
-		rc = GetLastError();
-		DPRINT("SetupDiGetDeviceInstallParams() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	installParams.Flags |= DI_NEEDRESTART;
-	if (!SetupDiSetDeviceInstallParamsW(
-		DeviceInfoSet,
-		DeviceInfoData,
-		&installParams))
-	{
-		rc = GetLastError();
-		DPRINT("SetupDiSetDeviceInstallParams() failed with error 0x%lx\n", rc);
-		goto cleanup;
-	}
-	rc = ERROR_SUCCESS;
+	if (IsEqualIID(&DeviceInfoData->ClassGuid, &GUID_DEVCLASS_NET))
+		rc = InstallNetDevice(DeviceInfoSet, DeviceInfoData, UuidString, Characteristics, BusType);
+	else if (IsEqualIID(&DeviceInfoData->ClassGuid, &GUID_DEVCLASS_NETCLIENT))
+		rc = InstallNetClient();
+	else if (IsEqualIID(&DeviceInfoData->ClassGuid, &GUID_DEVCLASS_NETSERVICE))
+		rc = InstallNetService();
+	else if (IsEqualIID(&DeviceInfoData->ClassGuid, &GUID_DEVCLASS_NETTRANS))
+		rc = InstallNetTransport();
+	else
+	{
+		DPRINT("Invalid class guid\n");
+		rc = ERROR_GEN_FAILURE;
+	}
 
 cleanup:
 	if (hInf != INVALID_HANDLE_VALUE)
@@ -559,18 +621,7 @@
 	if (UuidRpcString != NULL)
 		RpcStringFreeW(&UuidRpcString);
 	HeapFree(GetProcessHeap(), 0, BusType);
-	HeapFree(GetProcessHeap(), 0, InstanceId);
 	HeapFree(GetProcessHeap(), 0, UuidString);
-	HeapFree(GetProcessHeap(), 0, DeviceName);
-	HeapFree(GetProcessHeap(), 0, ExportName);
-	if (hKey != NULL)
-		RegCloseKey(hKey);
-	if (hLinkageKey != NULL)
-		RegCloseKey(hLinkageKey);
-	if (hNetworkKey != NULL)
-		RegCloseKey(hNetworkKey);
-	if (hConnectionKey != NULL)
-		RegCloseKey(hConnectionKey);
 
 	if (rc == ERROR_SUCCESS)
 		rc = ERROR_DI_DO_DEFAULT;

Modified: trunk/reactos/dll/win32/netcfgx/netcfgx.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/netcfgx/netcfgx.h?rev=29817&r1=29816&r2=29817&view=diff
==============================================================================
--- trunk/reactos/dll/win32/netcfgx/netcfgx.h (original)
+++ trunk/reactos/dll/win32/netcfgx/netcfgx.h Tue Oct 23 12:25:53 2007
@@ -1,5 +1,8 @@
+#ifndef _NETCFGX_H_
+#define _NETCFGX_H_
+
 #include <windows.h>
 #include <setupapi.h>
+#include <devguid.h>
 
-ULONG DbgPrint(PCH Format,...);
-
+#endif /* _NETCFGX_H_ */




More information about the Ros-diffs mailing list