/*
* 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@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.
* Returns ERROR_SUCCESS if success. Othewise, returns an error code
return ERROR_SUCCESS;
}
-DWORD WINAPI
-NetClassInstaller(
- IN DI_FUNCTION InstallFunction,
+static DWORD
+InstallNetDevice(
IN HDEVINFO DeviceInfoSet,
- IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
+ IN PSP_DEVINFO_DATA DeviceInfoData,
+ LPCWSTR UuidString,
+ DWORD Characteristics,
+ LPCWSTR BusType)
{
- SP_DRVINFO_DATA_W DriverInfoData;
- SP_DRVINFO_DETAIL_DATA_W DriverInfoDetail;
- WCHAR SectionName[LINE_LEN];
- HINF hInf = INVALID_HANDLE_VALUE;
- INFCONTEXT InfContext;
- UINT ErrorLine;
- INT CharacteristicsInt;
- DWORD Characteristics;
- 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 hLinkageKey = NULL;
HKEY hConnectionKey = NULL;
+ DWORD dwShowIcon, dwLength;
SP_DEVINSTALL_PARAMS_W installParams;
- if (InstallFunction != DIF_INSTALLDEVICE)
- return ERROR_DI_DO_DEFAULT;
-
- DPRINT("%lu %p %p\n", InstallFunction, DeviceInfoSet, DeviceInfoData);
-
- /* Get driver info details */
- DriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA_W);
- if (!SetupDiGetSelectedDriverW(DeviceInfoSet, DeviceInfoData, &DriverInfoData))
- {
- rc = GetLastError();
- DPRINT("SetupDiGetSelectedDriverW() failed with error 0x%lx\n", rc);
- goto cleanup;
- }
- DriverInfoDetail.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA_W);
- if (!SetupDiGetDriverInfoDetailW(DeviceInfoSet, DeviceInfoData, &DriverInfoData, &DriverInfoDetail, sizeof(DriverInfoDetail), NULL)
- && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
- {
- rc = GetLastError();
- DPRINT("SetupDiGetDriverInfoDetailW() failed with error 0x%lx\n", rc);
- goto cleanup;
- }
- hInf = SetupOpenInfFileW(DriverInfoDetail.InfFileName, NULL, INF_STYLE_WIN4, &ErrorLine);
- if (hInf == INVALID_HANDLE_VALUE)
- {
- rc = GetLastError();
- DPRINT("SetupOpenInfFileW() failed with error 0x%lx\n", rc);
- goto cleanup;
- }
- if (!SetupDiGetActualSectionToInstallW(hInf, DriverInfoDetail.SectionName, SectionName, LINE_LEN, NULL, NULL))
- {
- rc = GetLastError();
- DPRINT("SetupDiGetActualSectionToInstallW() failed with error 0x%lx\n", rc);
- goto cleanup;
- }
-
/* Get Instance ID */
if (SetupDiGetDeviceInstanceIdW(DeviceInfoSet, DeviceInfoData, NULL, 0, &dwLength))
{
goto cleanup;
}
- /* Get Characteristics and BusType (optional) from .inf file */
- if (!SetupFindFirstLineW(hInf, SectionName, L"Characteristics", &InfContext))
- {
- rc = GetLastError();
- DPRINT("Unable to find key %S in section %S of file %S (error 0x%lx)\n",
- L"Characteristics", SectionName, DriverInfoDetail.InfFileName, rc);
- goto cleanup;
- }
- if (!SetupGetIntField(&InfContext, 1, &CharacteristicsInt))
- {
- rc = GetLastError();
- DPRINT("SetupGetIntField() failed with error 0x%lx\n", rc);
- goto cleanup;
- }
- Characteristics = (DWORD)CharacteristicsInt;
- if (SetupFindFirstLineW(hInf, SectionName, L"BusType", &InfContext))
- {
- 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;
- }
- }
- else
- BusType = NULL;
-
- /* Create a new UUID */
- RpcStatus = UuidCreate(&Uuid);
- if (RpcStatus != RPC_S_OK && RpcStatus != RPC_S_UUID_LOCAL_ONLY)
- {
- DPRINT("UuidCreate() failed with RPC status 0x%lx\n", RpcStatus);
- rc = ERROR_GEN_FAILURE;
- goto cleanup;
- }
- RpcStatus = UuidToStringW(&Uuid, &UuidRpcString);
- if (RpcStatus != RPC_S_OK)
- {
- DPRINT("UuidToStringW() failed with RPC status 0x%lx\n", RpcStatus);
- rc = ERROR_GEN_FAILURE;
- goto cleanup;
- }
-
- /* Add curly braces around Uuid */
- UuidString = HeapAlloc(GetProcessHeap(), 0, (2 + wcslen(UuidRpcString)) * sizeof(WCHAR) + sizeof(UNICODE_NULL));
- if (!UuidString)
- {
- DPRINT("HeapAlloc() failed\n");
- rc = ERROR_NOT_ENOUGH_MEMORY;
- goto cleanup;
- }
- wcscpy(UuidString, L"{");
- 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)
}
/* Install additionnal services */
- /* FIXME: do it only if it is a network adapter! */
rc = InstallAdditionalServices(NULL);
if (rc != ERROR_SUCCESS)
{
rc = ERROR_SUCCESS;
cleanup:
- if (hInf != INVALID_HANDLE_VALUE)
- SetupCloseInfFile(hInf);
- 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 (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,
+ IN HDEVINFO DeviceInfoSet,
+ IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
+{
+ SP_DRVINFO_DATA_W DriverInfoData;
+ SP_DRVINFO_DETAIL_DATA_W DriverInfoDetail;
+ WCHAR SectionName[LINE_LEN];
+ HINF hInf = INVALID_HANDLE_VALUE;
+ INFCONTEXT InfContext;
+ UINT ErrorLine;
+ INT CharacteristicsInt;
+ DWORD Characteristics;
+ LPWSTR BusType = NULL;
+ RPC_STATUS RpcStatus;
+ UUID Uuid;
+ LPWSTR UuidRpcString = NULL;
+ LPWSTR UuidString = NULL;
+ LONG rc;
+ DWORD dwLength;
+
+ if (InstallFunction != DIF_INSTALLDEVICE)
+ return ERROR_DI_DO_DEFAULT;
+
+ DPRINT("%lu %p %p\n", InstallFunction, DeviceInfoSet, DeviceInfoData);
+
+ /* Get driver info details */
+ DriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA_W);
+ if (!SetupDiGetSelectedDriverW(DeviceInfoSet, DeviceInfoData, &DriverInfoData))
+ {
+ rc = GetLastError();
+ DPRINT("SetupDiGetSelectedDriverW() failed with error 0x%lx\n", rc);
+ goto cleanup;
+ }
+ DriverInfoDetail.cbSize = sizeof(SP_DRVINFO_DETAIL_DATA_W);
+ if (!SetupDiGetDriverInfoDetailW(DeviceInfoSet, DeviceInfoData, &DriverInfoData, &DriverInfoDetail, sizeof(DriverInfoDetail), NULL)
+ && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+ {
+ rc = GetLastError();
+ DPRINT("SetupDiGetDriverInfoDetailW() failed with error 0x%lx\n", rc);
+ goto cleanup;
+ }
+ hInf = SetupOpenInfFileW(DriverInfoDetail.InfFileName, NULL, INF_STYLE_WIN4, &ErrorLine);
+ if (hInf == INVALID_HANDLE_VALUE)
+ {
+ rc = GetLastError();
+ DPRINT("SetupOpenInfFileW() failed with error 0x%lx\n", rc);
+ goto cleanup;
+ }
+ if (!SetupDiGetActualSectionToInstallW(hInf, DriverInfoDetail.SectionName, SectionName, LINE_LEN, NULL, NULL))
+ {
+ rc = GetLastError();
+ DPRINT("SetupDiGetActualSectionToInstallW() failed with error 0x%lx\n", rc);
+ goto cleanup;
+ }
+
+ /* Get Characteristics and BusType (optional) from .inf file */
+ if (!SetupFindFirstLineW(hInf, SectionName, L"Characteristics", &InfContext))
+ {
+ rc = GetLastError();
+ DPRINT("Unable to find key %S in section %S of file %S (error 0x%lx)\n",
+ L"Characteristics", SectionName, DriverInfoDetail.InfFileName, rc);
+ goto cleanup;
+ }
+ if (!SetupGetIntField(&InfContext, 1, &CharacteristicsInt))
+ {
+ rc = GetLastError();
+ DPRINT("SetupGetIntField() failed with error 0x%lx\n", rc);
+ goto cleanup;
+ }
+ Characteristics = (DWORD)CharacteristicsInt;
+ if (IsEqualIID(&DeviceInfoData->ClassGuid, &GUID_DEVCLASS_NET))
+ {
+ if (SetupFindFirstLineW(hInf, SectionName, L"BusType", &InfContext))
+ {
+ 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;
+ }
+ }
+ }
+
+ /* Create a new UUID */
+ RpcStatus = UuidCreate(&Uuid);
+ if (RpcStatus != RPC_S_OK && RpcStatus != RPC_S_UUID_LOCAL_ONLY)
+ {
+ DPRINT("UuidCreate() failed with RPC status 0x%lx\n", RpcStatus);
+ rc = ERROR_GEN_FAILURE;
+ goto cleanup;
+ }
+ RpcStatus = UuidToStringW(&Uuid, &UuidRpcString);
+ if (RpcStatus != RPC_S_OK)
+ {
+ DPRINT("UuidToStringW() failed with RPC status 0x%lx\n", RpcStatus);
+ rc = ERROR_GEN_FAILURE;
+ goto cleanup;
+ }
+
+ /* Add curly braces around Uuid */
+ UuidString = HeapAlloc(GetProcessHeap(), 0, (2 + wcslen(UuidRpcString)) * sizeof(WCHAR) + sizeof(UNICODE_NULL));
+ if (!UuidString)
+ {
+ DPRINT("HeapAlloc() failed\n");
+ rc = ERROR_NOT_ENOUGH_MEMORY;
+ goto cleanup;
+ }
+ wcscpy(UuidString, L"{");
+ wcscat(UuidString, UuidRpcString);
+ wcscat(UuidString, L"}");
+
+ 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)
+ SetupCloseInfFile(hInf);
+ if (UuidRpcString != NULL)
+ RpcStringFreeW(&UuidRpcString);
+ HeapFree(GetProcessHeap(), 0, BusType);
+ HeapFree(GetProcessHeap(), 0, UuidString);
if (rc == ERROR_SUCCESS)
rc = ERROR_DI_DO_DEFAULT;