From c673f80b25b1084f7ee48b8aaddc3fa51250edbe Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 11 Aug 2013 19:57:47 +0000 Subject: [PATCH] [UMPNPMGR] - Handle the CM_CREATE_DEVNODE_GENERATE_ID flag [SETUPAPI] - Use the correct ID (the newly generated instance ID) when creating the device info if the DICD_GENERATE_ID flag was passed in svn path=/trunk/; revision=59699 --- reactos/base/services/umpnpmgr/umpnpmgr.c | 42 ++++++++++++++++++----- reactos/dll/win32/setupapi/cfgmgr.c | 4 ++- reactos/dll/win32/setupapi/devinst.c | 19 ++++++++++ 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/reactos/base/services/umpnpmgr/umpnpmgr.c b/reactos/base/services/umpnpmgr/umpnpmgr.c index 12254267713..c821105c335 100644 --- a/reactos/base/services/umpnpmgr/umpnpmgr.c +++ b/reactos/base/services/umpnpmgr/umpnpmgr.c @@ -1613,16 +1613,42 @@ DWORD PNP_CreateDevInst( if (ulFlags & CM_CREATE_DEVNODE_GENERATE_ID) { - /* FIXME */ - DPRINT1("CM_CREATE_DEVNODE_GENERATE_ID support not implemented yet!\n", ret); - ret = CR_CALL_NOT_IMPLEMENTED; - goto done; + WCHAR szGeneratedInstance[MAX_DEVICE_ID_LEN]; + DWORD dwInstanceNumber; + + /* Generated ID is: Root\\ */ + dwInstanceNumber = 0; + do + { + swprintf(szGeneratedInstance, L"Root\\%ls\\%04d", + pszDeviceID, dwInstanceNumber); + + /* Try to create a device instance with this ID */ + ret = CreateDeviceInstance(szGeneratedInstance); + + dwInstanceNumber++; + } + while (ret == CR_ALREADY_SUCH_DEVINST); + + if (ret == CR_SUCCESS) + { + /* pszDeviceID is an out parameter too for generated IDs */ + if (wcslen(szGeneratedInstance) > ulLength) + { + ret = CR_BUFFER_SMALL; + } + else + { + wcscpy(pszDeviceID, szGeneratedInstance); + } + } + } + else + { + /* Create the device instance */ + ret = CreateDeviceInstance(pszDeviceID); } - /* Create the device instance */ - ret = CreateDeviceInstance(pszDeviceID); - -done:; DPRINT("PNP_CreateDevInst() done (returns %lx)\n", ret); return ret; diff --git a/reactos/dll/win32/setupapi/cfgmgr.c b/reactos/dll/win32/setupapi/cfgmgr.c index d6beff2b3f6..b6bacb0d372 100644 --- a/reactos/dll/win32/setupapi/cfgmgr.c +++ b/reactos/dll/win32/setupapi/cfgmgr.c @@ -681,7 +681,9 @@ CONFIGRET WINAPI CM_Create_DevNode_ExW( if (ret == CR_SUCCESS) { - *pdnDevInst = pSetupStringTableAddString(StringTable, pDeviceID, 1); + /* If CM_CREATE_DEVINST_GENERATE_ID was passed in, PNP_CreateDevInst + * will return the generated device ID in szLocalDeviceID */ + *pdnDevInst = pSetupStringTableAddString(StringTable, szLocalDeviceID, 1); if (*pdnDevInst == 0) ret = CR_NO_SUCH_DEVNODE; } diff --git a/reactos/dll/win32/setupapi/devinst.c b/reactos/dll/win32/setupapi/devinst.c index a487de8b365..1130b137cac 100644 --- a/reactos/dll/win32/setupapi/devinst.c +++ b/reactos/dll/win32/setupapi/devinst.c @@ -1727,6 +1727,7 @@ BOOL WINAPI SetupDiCreateDeviceInfoW( CONFIGRET cr; DEVINST RootDevInst; DEVINST DevInst; + WCHAR GenInstanceId[MAX_DEVICE_ID_LEN]; TRACE("%p %s %s %s %p %x %p\n", DeviceInfoSet, debugstr_w(DeviceName), debugstr_guid(ClassGuid), debugstr_w(DeviceDescription), @@ -1789,6 +1790,24 @@ BOOL WINAPI SetupDiCreateDeviceInfoW( return FALSE; } + if (CreationFlags & DICD_GENERATE_ID) + { + /* Grab the actual instance ID that was created */ + cr = CM_Get_Device_ID_Ex(DevInst, + GenInstanceId, + MAX_DEVICE_ID_LEN, + 0, + set->hMachine); + if (cr != CR_SUCCESS) + { + SetLastError(GetErrorCodeFromCrCode(cr)); + return FALSE; + } + + DeviceName = GenInstanceId; + TRACE("Using generated instance ID: %s\n", debugstr_w(DeviceName)); + } + if (CreateDeviceInfo(set, DeviceName, ClassGuid, &deviceInfo)) { InsertTailList(&set->ListHead, &deviceInfo->ListEntry);