From: Vibhav Pant vibhavp@gmail.com
--- dlls/ntoskrnl.exe/tests/ntoskrnl.c | 24 ++++++------- dlls/setupapi/devinst.c | 54 ++++++++++++++++++++++++------ 2 files changed, 56 insertions(+), 22 deletions(-)
diff --git a/dlls/ntoskrnl.exe/tests/ntoskrnl.c b/dlls/ntoskrnl.exe/tests/ntoskrnl.c index 7ed5f4e22ba..673a38a05b1 100644 --- a/dlls/ntoskrnl.exe/tests/ntoskrnl.c +++ b/dlls/ntoskrnl.exe/tests/ntoskrnl.c @@ -1695,28 +1695,28 @@ static void test_pnp_devices(void) size = 0; ret = SetupDiGetDevicePropertyW(set, &device, &DEVPKEY_Device_HardwareIds, &prop_type, (BYTE *)buffer_w, sizeof(buffer_w), &size, 0); - todo_wine ok(ret, "failed to get device property, error %#lx\n", GetLastError()); - todo_wine ok(prop_type == DEVPROP_TYPE_STRING_LIST, "got type %#lx\n", prop_type); - todo_wine ok(size == sizeof(expect_hardware_id_w), "got size %lu\n", size); - todo_wine ok(!memcmp(buffer_w, expect_hardware_id_w, size), "got hardware IDs %s\n", debugstr_wn(buffer_w, size)); + ok(ret, "failed to get device property, error %#lx\n", GetLastError()); + ok(prop_type == DEVPROP_TYPE_STRING_LIST, "got type %#lx\n", prop_type); + ok(size == sizeof(expect_hardware_id_w), "got size %lu\n", size); + ok(!memcmp(buffer_w, expect_hardware_id_w, size), "got hardware IDs %s\n", debugstr_wn(buffer_w, size));
prop_type = DEVPROP_TYPE_EMPTY; size = 0; ret = SetupDiGetDevicePropertyW(set, &device, &DEVPKEY_Device_CompatibleIds, &prop_type, (BYTE *)buffer_w, sizeof(buffer_w), &size, 0); - todo_wine ok(ret, "failed to get device property, error %#lx\n", GetLastError()); - todo_wine ok(prop_type == DEVPROP_TYPE_STRING_LIST, "got type %#lx\n", prop_type); - todo_wine ok(size == sizeof(expect_compat_id_w), "got size %lu\n", size); - todo_wine ok(!memcmp(buffer_w, expect_compat_id_w, size), "got compatible IDs %s\n", debugstr_wn(buffer_w, size)); + ok(ret, "failed to get device property, error %#lx\n", GetLastError()); + ok(prop_type == DEVPROP_TYPE_STRING_LIST, "got type %#lx\n", prop_type); + ok(size == sizeof(expect_compat_id_w), "got size %lu\n", size); + ok(!memcmp(buffer_w, expect_compat_id_w, size), "got compatible IDs %s\n", debugstr_wn(buffer_w, size));
prop_type = DEVPROP_TYPE_EMPTY; size = 0; ret = SetupDiGetDevicePropertyW(set, &device, &DEVPKEY_Device_ContainerId, &prop_type, (BYTE *)&buffer_guid, sizeof(buffer_guid), &size, 0); - todo_wine ok(ret, "failed to get device property, error %#lx\n", GetLastError()); - todo_wine ok(prop_type == DEVPROP_TYPE_GUID, "got type %#lx\n", prop_type); - todo_wine ok(size == sizeof(expect_container_id_guid), "got size %lu\n", size); - todo_wine ok(IsEqualGUID(&buffer_guid, &expect_container_id_guid), "got container ID %s != %s\n", debugstr_guid(&buffer_guid), debugstr_guid(&expect_container_id_guid)); + ok(ret, "failed to get device property, error %#lx\n", GetLastError()); + ok(prop_type == DEVPROP_TYPE_GUID, "got type %#lx\n", prop_type); + ok(size == sizeof(expect_container_id_guid), "got size %lu\n", size); + ok(IsEqualGUID(&buffer_guid, &expect_container_id_guid), "got container ID %s != %s\n", debugstr_guid(&buffer_guid), debugstr_guid(&expect_container_id_guid));
ret = SetupDiEnumDeviceInterfaces(set, NULL, &child_class, 0, &iface); ok(ret, "failed to get interface, error %#lx\n", GetLastError()); diff --git a/dlls/setupapi/devinst.c b/dlls/setupapi/devinst.c index e065e6cbe98..3c98244b8d1 100644 --- a/dlls/setupapi/devinst.c +++ b/dlls/setupapi/devinst.c @@ -895,10 +895,8 @@ static struct device *create_device(struct DeviceInfoSet *set, return device; }
-static struct device *get_devnode_device(DEVINST devnode, HDEVINFO *set) +static struct device *get_devnode_device(DEVINST devnode, HDEVINFO *set, SP_DEVINFO_DATA *data) { - SP_DEVINFO_DATA data = { sizeof(data) }; - *set = NULL; if (devnode >= devinst_table_size || !devinst_table[devnode]) { @@ -908,13 +906,13 @@ static struct device *get_devnode_device(DEVINST devnode, HDEVINFO *set)
*set = SetupDiCreateDeviceInfoListExW(NULL, NULL, NULL, NULL); if (*set == INVALID_HANDLE_VALUE) return NULL; - if (!SetupDiOpenDeviceInfoW(*set, devinst_table[devnode], NULL, 0, &data)) + if (!SetupDiOpenDeviceInfoW(*set, devinst_table[devnode], NULL, 0, data)) { SetupDiDestroyDeviceInfoList(*set); *set = NULL; return NULL; } - return get_device(*set, &data); + return get_device(*set, data); }
/*********************************************************************** @@ -5275,8 +5273,9 @@ BOOL WINAPI SetupDiGetDevicePropertyKeys( HDEVINFO devinfo, PSP_DEVINFO_DATA dev return !ret; }
-static DWORD get_device_property( struct device *device, const DEVPROPKEY *prop_key, DEVPROPTYPE *prop_type, - BYTE *buf, DWORD buf_size, DWORD *req_size, DWORD flags ) +static DWORD get_device_property( struct device *device, HDEVINFO devinfo, PSP_DEVINFO_DATA device_data, + const DEVPROPKEY *prop_key, DEVPROPTYPE *prop_type, BYTE *buf, DWORD buf_size, + DWORD *req_size, DWORD flags ) { DWORD ret = ERROR_SUCCESS;
@@ -5309,6 +5308,38 @@ static DWORD get_device_property( struct device *device, const DEVPROPKEY *prop_ if (req_size) *req_size = size; } + else if (IsEqualDevPropKey( *prop_key, DEVPKEY_Device_HardwareIds ) + || IsEqualDevPropKey( *prop_key, DEVPKEY_Device_CompatibleIds )) + { + DWORD prop = IsEqualDevPropKey( *prop_key, DEVPKEY_Device_HardwareIds ) ? SPDRP_HARDWAREID : SPDRP_COMPATIBLEIDS, size = 0; + if (!SetupDiGetDeviceRegistryPropertyW( devinfo, device_data, prop, NULL, buf, buf_size, &size )) + ret = GetLastError() == ERROR_INVALID_DATA ? ERROR_NOT_FOUND : GetLastError(); + if (ret != ERROR_NOT_FOUND) + { + *prop_type = DEVPROP_TYPE_STRING_LIST; + if (req_size) + *req_size = size; + } + } + else if (IsEqualDevPropKey( *prop_key, DEVPKEY_Device_ContainerId )) + { + WCHAR id_str[39]; + if (!SetupDiGetDeviceRegistryPropertyW( devinfo, device_data, SPDRP_BASE_CONTAINERID, NULL, (BYTE *)id_str, + sizeof(id_str), NULL )) + return GetLastError() == ERROR_INVALID_DATA ? ERROR_NOT_FOUND : GetLastError(); + *prop_type = DEVPROP_TYPE_GUID; + if (buf_size >= sizeof( GUID )) + { + GUID guid = {0}; + id_str[37] = 0; + UuidFromStringW( &id_str[1], &guid ); + memcpy( buf, &guid, sizeof( guid ) ); + } + else + ret = ERROR_INSUFFICIENT_BUFFER; + if (req_size) + *req_size = sizeof( GUID ); + } else ret = get_device_reg_property( device->key, prop_key, prop_type, buf, buf_size, req_size, flags ); return ret; @@ -5330,7 +5361,8 @@ BOOL WINAPI SetupDiGetDevicePropertyW(HDEVINFO devinfo, PSP_DEVINFO_DATA device_ if (!(device = get_device(devinfo, device_data))) return FALSE;
- ls = get_device_property(device, prop_key, prop_type, prop_buff, prop_buff_size, required_size, flags); + ls = get_device_property(device, devinfo, device_data, prop_key, prop_type, prop_buff, prop_buff_size, + required_size, flags);
SetLastError(ls); return !ls; @@ -5343,6 +5375,7 @@ CONFIGRET WINAPI CM_Get_DevNode_Property_ExW(DEVINST devnode, const DEVPROPKEY * BYTE *prop_buff, ULONG *prop_buff_size, ULONG flags, HMACHINE machine) { HDEVINFO set; + SP_DEVINFO_DATA data = { sizeof(data) }; struct device *device; LSTATUS ls;
@@ -5355,10 +5388,11 @@ CONFIGRET WINAPI CM_Get_DevNode_Property_ExW(DEVINST devnode, const DEVPROPKEY * if (!prop_buff_size) return CR_INVALID_POINTER;
- if (!(device = get_devnode_device(devnode, &set))) + if (!(device = get_devnode_device(devnode, &set, &data))) return CR_NO_SUCH_DEVINST;
- ls = get_device_property(device, prop_key, prop_type, prop_buff, *prop_buff_size, prop_buff_size, flags); + ls = get_device_property(device, set, &data, prop_key, prop_type, prop_buff, *prop_buff_size, + prop_buff_size, flags); SetupDiDestroyDeviceInfoList(set); switch (ls) {