f2ad0d7f04fc317d09071b9e47a1695d0fe192c4
[reactos.git] / dll / win32 / setupapi / cfgmgr.c
1 /*
2 * Configuration manager functions
3 *
4 * Copyright 2000 James Hatheway
5 * Copyright 2005, 2006 Eric Kohl
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 */
21
22 #include "setupapi_private.h"
23
24 #include <dbt.h>
25 #include <pnp_c.h>
26
27 #include "rpc_private.h"
28
29 /* Registry key and value names */
30 static const WCHAR Backslash[] = {'\\', 0};
31 static const WCHAR Class[] = {'C','l','a','s','s',0};
32
33 static const WCHAR ControlClass[] = {'S','y','s','t','e','m','\\',
34 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
35 'C','o','n','t','r','o','l','\\',
36 'C','l','a','s','s',0};
37
38 static const WCHAR DeviceClasses[] = {'S','y','s','t','e','m','\\',
39 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
40 'C','o','n','t','r','o','l','\\',
41 'D','e','v','i','c','e','C','l','a','s','s','e','s',0};
42
43 typedef struct _MACHINE_INFO
44 {
45 WCHAR szMachineName[SP_MAX_MACHINENAME_LENGTH];
46 RPC_BINDING_HANDLE BindingHandle;
47 HSTRING_TABLE StringTable;
48 BOOL bLocal;
49 } MACHINE_INFO, *PMACHINE_INFO;
50
51
52 typedef struct _LOG_CONF_INFO
53 {
54 ULONG ulMagic;
55 DEVINST dnDevInst;
56 ULONG ulFlags;
57 ULONG ulTag;
58 } LOG_CONF_INFO, *PLOG_CONF_INFO;
59
60 #define LOG_CONF_MAGIC 0x464E434C /* "LCNF" */
61
62
63 typedef struct _NOTIFY_DATA
64 {
65 ULONG ulMagic;
66 ULONG ulNotifyData;
67 } NOTIFY_DATA, *PNOTIFY_DATA;
68
69 #define NOTIFY_MAGIC 0x44556677
70
71
72 typedef struct _INTERNAL_RANGE_ELEMENT
73 {
74 struct _INTERNAL_RANGE_ELEMENT *Next;
75 ULONG ulDummy;
76 } INTERNAL_RANGE_ELEMENT, *PINTERNAL_RANGE_ELEMENT;
77
78 typedef struct _INTERNAL_RANGE_LIST
79 {
80 ULONG ulMagic;
81 PINTERNAL_RANGE_ELEMENT Current;
82 PINTERNAL_RANGE_ELEMENT First;
83 } INTERNAL_RANGE_LIST, *PINTERNAL_RANGE_LIST;
84
85 #define RANGE_LIST_MAGIC 0x33445566
86
87
88 static BOOL GuidToString(LPGUID Guid, LPWSTR String)
89 {
90 LPWSTR lpString;
91
92 if (UuidToStringW(Guid, &lpString) != RPC_S_OK)
93 return FALSE;
94
95 lstrcpyW(&String[1], lpString);
96
97 String[0] = '{';
98 String[MAX_GUID_STRING_LEN - 2] = '}';
99 String[MAX_GUID_STRING_LEN - 1] = UNICODE_NULL;
100
101 RpcStringFreeW(&lpString);
102
103 return TRUE;
104 }
105
106
107 static CONFIGRET
108 RpcStatusToCmStatus(RPC_STATUS Status)
109 {
110 return CR_FAILURE;
111 }
112
113
114 static
115 ULONG
116 GetRegistryPropertyType(
117 ULONG ulProperty)
118 {
119 switch (ulProperty)
120 {
121 case CM_DRP_DEVICEDESC:
122 case CM_DRP_SERVICE:
123 case CM_DRP_CLASS:
124 case CM_DRP_CLASSGUID:
125 case CM_DRP_DRIVER:
126 case CM_DRP_MFG:
127 case CM_DRP_FRIENDLYNAME:
128 case CM_DRP_LOCATION_INFORMATION:
129 case CM_DRP_PHYSICAL_DEVICE_OBJECT_NAME:
130 case CM_DRP_ENUMERATOR_NAME:
131 case CM_DRP_SECURITY_SDS:
132 case CM_DRP_UI_NUMBER_DESC_FORMAT:
133 return REG_SZ;
134
135 case CM_DRP_HARDWAREID:
136 case CM_DRP_COMPATIBLEIDS:
137 case CM_DRP_UPPERFILTERS:
138 case CM_DRP_LOWERFILTERS:
139 return REG_MULTI_SZ;
140
141 case CM_DRP_CONFIGFLAGS:
142 case CM_DRP_CAPABILITIES:
143 case CM_DRP_UI_NUMBER:
144 case CM_DRP_LEGACYBUSTYPE:
145 case CM_DRP_BUSNUMBER:
146 case CM_DRP_DEVTYPE:
147 case CM_DRP_EXCLUSIVE:
148 case CM_DRP_CHARACTERISTICS:
149 case CM_DRP_ADDRESS:
150 case CM_DRP_REMOVAL_POLICY:
151 case CM_DRP_REMOVAL_POLICY_HW_DEFAULT:
152 case CM_DRP_REMOVAL_POLICY_OVERRIDE:
153 case CM_DRP_INSTALL_STATE:
154 return REG_DWORD;
155
156 case CM_DRP_BUSTYPEGUID:
157 case CM_DRP_SECURITY:
158 case CM_DRP_DEVICE_POWER_DATA:
159 default:
160 return REG_BINARY;
161 }
162
163 return REG_NONE;
164 }
165
166
167 /***********************************************************************
168 * CMP_GetBlockedDriverInfo [SETUPAPI.@]
169 */
170 CONFIGRET
171 WINAPI
172 CMP_GetBlockedDriverInfo(
173 _Out_opt_ LPWSTR pszNames,
174 _Inout_ PULONG pulLength,
175 _In_ ULONG ulFlags,
176 _In_opt_ HMACHINE hMachine)
177 {
178 RPC_BINDING_HANDLE BindingHandle = NULL;
179 ULONG ulTransferLength;
180 CONFIGRET ret;
181
182 TRACE("CMP_GetBlockedDriverInfo(%p %p %lx %p)\n",
183 pszNames, pulLength, ulFlags, hMachine);
184
185 if (hMachine != NULL)
186 {
187 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
188 if (BindingHandle == NULL)
189 return CR_FAILURE;
190 }
191 else
192 {
193 if (!PnpGetLocalHandles(&BindingHandle, NULL))
194 return CR_FAILURE;
195 }
196
197 ulTransferLength = *pulLength;
198
199 RpcTryExcept
200 {
201 ret = PNP_GetBlockedDriverInfo(BindingHandle,
202 (PBYTE)pszNames,
203 &ulTransferLength,
204 pulLength,
205 ulFlags);
206 }
207 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
208 {
209 ret = RpcStatusToCmStatus(RpcExceptionCode());
210 }
211 RpcEndExcept;
212
213 return ret;
214 }
215
216
217 /***********************************************************************
218 * CMP_GetServerSideDeviceInstallFlags [SETUPAPI.@]
219 */
220 CONFIGRET
221 WINAPI
222 CMP_GetServerSideDeviceInstallFlags(
223 _Out_ PULONG pulSSDIFlags,
224 _In_ ULONG ulFlags,
225 _In_opt_ HMACHINE hMachine)
226 {
227 RPC_BINDING_HANDLE BindingHandle = NULL;
228 CONFIGRET ret;
229
230 TRACE("CMP_GetServerSideDeviceInstallFlags(%p %lx %p)\n",
231 pulSSDIFlags, ulFlags, hMachine);
232
233 if (pulSSDIFlags == NULL)
234 return CR_INVALID_POINTER;
235
236 if (ulFlags != 0)
237 return CR_INVALID_FLAG;
238
239 if (hMachine != NULL)
240 {
241 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
242 if (BindingHandle == NULL)
243 return CR_FAILURE;
244 }
245 else
246 {
247 if (!PnpGetLocalHandles(&BindingHandle, NULL))
248 return CR_FAILURE;
249 }
250
251 RpcTryExcept
252 {
253 ret = PNP_GetServerSideDeviceInstallFlags(BindingHandle,
254 pulSSDIFlags,
255 ulFlags);
256 }
257 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
258 {
259 ret = RpcStatusToCmStatus(RpcExceptionCode());
260 }
261 RpcEndExcept;
262
263 return ret;
264 }
265
266
267 /***********************************************************************
268 * CMP_Init_Detection [SETUPAPI.@]
269 */
270 CONFIGRET
271 WINAPI
272 CMP_Init_Detection(
273 _In_ ULONG ulMagic)
274 {
275 RPC_BINDING_HANDLE BindingHandle = NULL;
276 CONFIGRET ret;
277
278 TRACE("CMP_Init_Detection(%lu)\n", ulMagic);
279
280 if (ulMagic != CMP_MAGIC)
281 return CR_INVALID_DATA;
282
283 if (!PnpGetLocalHandles(&BindingHandle, NULL))
284 return CR_FAILURE;
285
286 RpcTryExcept
287 {
288 ret = PNP_InitDetection(BindingHandle);
289 }
290 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
291 {
292 ret = RpcStatusToCmStatus(RpcExceptionCode());
293 }
294 RpcEndExcept;
295
296 return ret;
297 }
298
299
300 /***********************************************************************
301 * CMP_RegisterNotification [SETUPAPI.@]
302 */
303 CONFIGRET
304 WINAPI
305 CMP_RegisterNotification(
306 _In_ HANDLE hRecipient,
307 _In_ LPVOID lpvNotificationFilter,
308 _In_ ULONG ulFlags,
309 _Out_ PHDEVNOTIFY phDevNotify)
310 {
311 RPC_BINDING_HANDLE BindingHandle = NULL;
312 PNOTIFY_DATA pNotifyData = NULL;
313 CONFIGRET ret = CR_SUCCESS;
314
315 TRACE("CMP_RegisterNotification(%p %p %lu %p)\n",
316 hRecipient, lpvNotificationFilter, ulFlags, phDevNotify);
317
318 if ((hRecipient == NULL) ||
319 (lpvNotificationFilter == NULL) ||
320 (phDevNotify == NULL))
321 return CR_INVALID_POINTER;
322
323 if (ulFlags & ~0x7)
324 return CR_INVALID_FLAG;
325
326 if (((PDEV_BROADCAST_HDR)lpvNotificationFilter)->dbch_size < sizeof(DEV_BROADCAST_HDR))
327 return CR_INVALID_DATA;
328
329 if (!PnpGetLocalHandles(&BindingHandle, NULL))
330 return CR_FAILURE;
331
332 pNotifyData = HeapAlloc(GetProcessHeap(),
333 HEAP_ZERO_MEMORY,
334 sizeof(NOTIFY_DATA));
335 if (pNotifyData == NULL)
336 return CR_OUT_OF_MEMORY;
337
338 pNotifyData->ulMagic = NOTIFY_MAGIC;
339
340 /*
341 if (dwFlags & DEVICE_NOTIFY_SERVICE_HANDLE == DEVICE_NOTYFY_WINDOW_HANDLE)
342 {
343
344 }
345 else if (dwFlags & DEVICE_NOTIFY_SERVICE_HANDLE == DEVICE_NOTYFY_SERVICE_HANDLE)
346 {
347
348 }
349 */
350
351 RpcTryExcept
352 {
353 ret = PNP_RegisterNotification(BindingHandle,
354 ulFlags,
355 &pNotifyData->ulNotifyData);
356 }
357 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
358 {
359 ret = RpcStatusToCmStatus(RpcExceptionCode());
360 }
361 RpcEndExcept;
362
363 if (ret == CR_SUCCESS)
364 {
365 *phDevNotify = (HDEVNOTIFY)pNotifyData;
366 }
367 else
368 {
369 if (pNotifyData != NULL)
370 HeapFree(GetProcessHeap(), 0, pNotifyData);
371
372 *phDevNotify = (HDEVNOTIFY)NULL;
373 }
374
375 return ret;
376 }
377
378
379 /***********************************************************************
380 * CMP_Report_LogOn [SETUPAPI.@]
381 */
382 CONFIGRET
383 WINAPI
384 CMP_Report_LogOn(
385 _In_ DWORD dwMagic,
386 _In_ DWORD dwProcessId)
387 {
388 RPC_BINDING_HANDLE BindingHandle = NULL;
389 CONFIGRET ret = CR_SUCCESS;
390 BOOL bAdmin;
391 DWORD i;
392
393 TRACE("CMP_Report_LogOn(%lu %lu)\n", dwMagic, dwProcessId);
394
395 if (dwMagic != CMP_MAGIC)
396 return CR_INVALID_DATA;
397
398 if (!PnpGetLocalHandles(&BindingHandle, NULL))
399 return CR_FAILURE;
400
401 bAdmin = pSetupIsUserAdmin();
402
403 for (i = 0; i < 30; i++)
404 {
405 RpcTryExcept
406 {
407 ret = PNP_ReportLogOn(BindingHandle,
408 bAdmin,
409 dwProcessId);
410 }
411 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
412 {
413 ret = RpcStatusToCmStatus(RpcExceptionCode());
414 }
415 RpcEndExcept;
416
417 if (ret == CR_SUCCESS)
418 break;
419
420 Sleep(5000);
421 }
422
423 return ret;
424 }
425
426
427 /***********************************************************************
428 * CMP_UnregisterNotification [SETUPAPI.@]
429 */
430 CONFIGRET
431 WINAPI
432 CMP_UnregisterNotification(
433 _In_ HDEVNOTIFY hDevNotify)
434 {
435 RPC_BINDING_HANDLE BindingHandle = NULL;
436 PNOTIFY_DATA pNotifyData;
437 CONFIGRET ret = CR_SUCCESS;
438
439 TRACE("CMP_UnregisterNotification(%p)\n", hDevNotify);
440
441 pNotifyData = (PNOTIFY_DATA)hDevNotify;
442
443 if ((pNotifyData == NULL) ||
444 (pNotifyData->ulMagic != NOTIFY_MAGIC))
445 return CR_INVALID_POINTER;
446
447 if (!PnpGetLocalHandles(&BindingHandle, NULL))
448 return CR_FAILURE;
449
450 RpcTryExcept
451 {
452 ret = PNP_UnregisterNotification(BindingHandle,
453 pNotifyData->ulNotifyData);
454 }
455 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
456 {
457 ret = RpcStatusToCmStatus(RpcExceptionCode());
458 }
459 RpcEndExcept;
460
461 if (ret == CR_SUCCESS)
462 HeapFree(GetProcessHeap(), 0, pNotifyData);
463
464 return ret;
465 }
466
467
468 /***********************************************************************
469 * CMP_WaitNoPendingInstallEvents [SETUPAPI.@]
470 */
471 DWORD
472 WINAPI
473 CMP_WaitNoPendingInstallEvents(
474 _In_ DWORD dwTimeout)
475 {
476 HANDLE hEvent;
477 DWORD ret;
478
479 TRACE("CMP_WaitNoPendingInstallEvents(%lu)\n", dwTimeout);
480
481 hEvent = OpenEventW(SYNCHRONIZE, FALSE, L"Global\\PnP_No_Pending_Install_Events");
482 if (hEvent == NULL)
483 return WAIT_FAILED;
484
485 ret = WaitForSingleObject(hEvent, dwTimeout);
486 CloseHandle(hEvent);
487 return ret;
488 }
489
490
491 /***********************************************************************
492 * CMP_WaitServicesAvailable [SETUPAPI.@]
493 */
494 CONFIGRET
495 WINAPI
496 CMP_WaitServicesAvailable(
497 _In_opt_ HMACHINE hMachine)
498 {
499 RPC_BINDING_HANDLE BindingHandle = NULL;
500 CONFIGRET ret = CR_SUCCESS;
501 WORD Version;
502
503 TRACE("CMP_WaitServicesAvailable(%p)\n", hMachine);
504
505 if (hMachine != NULL)
506 {
507 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
508 if (BindingHandle == NULL)
509 return CR_FAILURE;
510 }
511 else
512 {
513 if (!PnpGetLocalHandles(&BindingHandle, NULL))
514 return CR_FAILURE;
515 }
516
517 RpcTryExcept
518 {
519 ret = PNP_GetVersion(BindingHandle, &Version);
520 }
521 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
522 {
523 ret = RpcStatusToCmStatus(RpcExceptionCode());
524 }
525 RpcEndExcept;
526
527 return ret;
528 }
529
530
531 /***********************************************************************
532 * CM_Add_Empty_Log_Conf [SETUPAPI.@]
533 */
534 CONFIGRET WINAPI CM_Add_Empty_Log_Conf(
535 PLOG_CONF plcLogConf, DEVINST dnDevInst, PRIORITY Priority,
536 ULONG ulFlags)
537 {
538 TRACE("%p %p %lu %lx\n", plcLogConf, dnDevInst, Priority, ulFlags);
539 return CM_Add_Empty_Log_Conf_Ex(plcLogConf, dnDevInst, Priority,
540 ulFlags, NULL);
541 }
542
543
544 /***********************************************************************
545 * CM_Add_Empty_Log_Conf_Ex [SETUPAPI.@]
546 */
547 CONFIGRET WINAPI CM_Add_Empty_Log_Conf_Ex(
548 PLOG_CONF plcLogConf, DEVINST dnDevInst, PRIORITY Priority,
549 ULONG ulFlags, HMACHINE hMachine)
550 {
551 RPC_BINDING_HANDLE BindingHandle = NULL;
552 HSTRING_TABLE StringTable = NULL;
553 ULONG ulLogConfTag = 0;
554 LPWSTR lpDevInst;
555 PLOG_CONF_INFO pLogConfInfo;
556 CONFIGRET ret = CR_SUCCESS;
557
558 FIXME("%p %p %lu %lx %p\n",
559 plcLogConf, dnDevInst, Priority, ulFlags, hMachine);
560
561 if (!pSetupIsUserAdmin())
562 return CR_ACCESS_DENIED;
563
564 if (plcLogConf == NULL)
565 return CR_INVALID_POINTER;
566
567 if (dnDevInst == 0)
568 return CR_INVALID_DEVINST;
569
570 if (Priority > 0xFFFF)
571 return CR_INVALID_PRIORITY;
572
573 if (ulFlags & ~(LOG_CONF_BITS | PRIORITY_BIT))
574 return CR_INVALID_FLAG;
575
576 if (hMachine != NULL)
577 {
578 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
579 if (BindingHandle == NULL)
580 return CR_FAILURE;
581
582 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
583 if (StringTable == 0)
584 return CR_FAILURE;
585 }
586 else
587 {
588 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
589 return CR_FAILURE;
590 }
591
592 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
593 if (lpDevInst == NULL)
594 return CR_INVALID_DEVNODE;
595
596 RpcTryExcept
597 {
598 ret = PNP_AddEmptyLogConf(BindingHandle, lpDevInst, Priority,
599 &ulLogConfTag, ulFlags);
600 }
601 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
602 {
603 ret = RpcStatusToCmStatus(RpcExceptionCode());
604 }
605 RpcEndExcept;
606
607 if (ret == CR_SUCCESS)
608 {
609 pLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO));
610 if (pLogConfInfo == NULL)
611 {
612 ret = CR_OUT_OF_MEMORY;
613 }
614 else
615 {
616 pLogConfInfo->ulMagic = LOG_CONF_MAGIC;
617 pLogConfInfo->dnDevInst = dnDevInst;
618 pLogConfInfo->ulFlags = ulFlags;
619 pLogConfInfo->ulTag = ulLogConfTag;
620
621 *plcLogConf = (LOG_CONF)pLogConfInfo;
622
623 ret = CR_SUCCESS;
624 }
625 }
626
627 return ret;
628 }
629
630
631 /***********************************************************************
632 * CM_Add_IDA [SETUPAPI.@]
633 */
634 CONFIGRET WINAPI CM_Add_IDA(
635 DEVINST dnDevInst, PSTR pszID, ULONG ulFlags)
636 {
637 TRACE("%p %s %lx\n", dnDevInst, pszID, ulFlags);
638 return CM_Add_ID_ExA(dnDevInst, pszID, ulFlags, NULL);
639 }
640
641
642 /***********************************************************************
643 * CM_Add_IDW [SETUPAPI.@]
644 */
645 CONFIGRET WINAPI CM_Add_IDW(
646 DEVINST dnDevInst, PWSTR pszID, ULONG ulFlags)
647 {
648 TRACE("%p %s %lx\n", dnDevInst, debugstr_w(pszID), ulFlags);
649 return CM_Add_ID_ExW(dnDevInst, pszID, ulFlags, NULL);
650 }
651
652
653 /***********************************************************************
654 * CM_Add_ID_ExA [SETUPAPI.@]
655 */
656 CONFIGRET WINAPI CM_Add_ID_ExA(
657 DEVINST dnDevInst, PSTR pszID, ULONG ulFlags, HMACHINE hMachine)
658 {
659 PWSTR pszIDW;
660 CONFIGRET ret;
661
662 TRACE("%p %s %lx %p\n", dnDevInst, pszID, ulFlags, hMachine);
663
664 if (pSetupCaptureAndConvertAnsiArg(pszID, &pszIDW))
665 return CR_INVALID_DATA;
666
667 ret = CM_Add_ID_ExW(dnDevInst, pszIDW, ulFlags, hMachine);
668
669 MyFree(pszIDW);
670
671 return ret;
672 }
673
674
675 /***********************************************************************
676 * CM_Add_ID_ExW [SETUPAPI.@]
677 */
678 CONFIGRET WINAPI CM_Add_ID_ExW(
679 DEVINST dnDevInst, PWSTR pszID, ULONG ulFlags, HMACHINE hMachine)
680 {
681 RPC_BINDING_HANDLE BindingHandle = NULL;
682 HSTRING_TABLE StringTable = NULL;
683 LPWSTR lpDevInst;
684 CONFIGRET ret;
685
686 TRACE("%p %s %lx %p\n", dnDevInst, debugstr_w(pszID), ulFlags, hMachine);
687
688 if (!pSetupIsUserAdmin())
689 return CR_ACCESS_DENIED;
690
691 if (dnDevInst == 0)
692 return CR_INVALID_DEVINST;
693
694 if (pszID == NULL)
695 return CR_INVALID_POINTER;
696
697 if (ulFlags & ~CM_ADD_ID_BITS)
698 return CR_INVALID_FLAG;
699
700 if (hMachine != NULL)
701 {
702 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
703 if (BindingHandle == NULL)
704 return CR_FAILURE;
705
706 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
707 if (StringTable == 0)
708 return CR_FAILURE;
709 }
710 else
711 {
712 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
713 return CR_FAILURE;
714 }
715
716 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
717 if (lpDevInst == NULL)
718 return CR_INVALID_DEVNODE;
719
720 RpcTryExcept
721 {
722 ret = PNP_AddID(BindingHandle,
723 lpDevInst,
724 pszID,
725 ulFlags);
726 }
727 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
728 {
729 ret = RpcStatusToCmStatus(RpcExceptionCode());
730 }
731 RpcEndExcept;
732
733 return ret;
734 }
735
736
737 /***********************************************************************
738 * CM_Add_Range [SETUPAPI.@]
739 */
740 CONFIGRET
741 WINAPI
742 CM_Add_Range(
743 _In_ DWORDLONG ullStartValue,
744 _In_ DWORDLONG ullEndValue,
745 _In_ RANGE_LIST rlh,
746 _In_ ULONG ulFlags)
747 {
748 FIXME("CM_Add_Range(%I64u %I64u %p %lx)\n",
749 ullStartValue, ullEndValue, rlh, ulFlags);
750 return CR_CALL_NOT_IMPLEMENTED;
751 }
752
753
754 /***********************************************************************
755 * CM_Add_Res_Des [SETUPAPI.@]
756 */
757 CONFIGRET WINAPI CM_Add_Res_Des(
758 PRES_DES prdResDes, LOG_CONF lcLogConf, RESOURCEID ResourceID,
759 PCVOID ResourceData, ULONG ResourceLen, ULONG ulFlags)
760 {
761 TRACE("%p %p %lu %p %lu %lx\n", prdResDes, lcLogConf, ResourceID,
762 ResourceData, ResourceLen, ulFlags);
763 return CM_Add_Res_Des_Ex(prdResDes, lcLogConf, ResourceID, ResourceData,
764 ResourceLen, ulFlags, NULL);
765 }
766
767
768 /***********************************************************************
769 * CM_Add_Res_Des_Ex [SETUPAPI.@]
770 */
771 CONFIGRET WINAPI CM_Add_Res_Des_Ex(
772 PRES_DES prdResDes, LOG_CONF lcLogConf, RESOURCEID ResourceID,
773 PCVOID ResourceData, ULONG ResourceLen, ULONG ulFlags, HMACHINE hMachine)
774 {
775 FIXME("%p %p %lu %p %lu %lx %p\n", prdResDes, lcLogConf, ResourceID,
776 ResourceData, ResourceLen, ulFlags, hMachine);
777
778 return CR_CALL_NOT_IMPLEMENTED;
779 }
780
781
782 /***********************************************************************
783 * CM_Connect_MachineA [SETUPAPI.@]
784 */
785 CONFIGRET WINAPI CM_Connect_MachineA(
786 PCSTR UNCServerName, PHMACHINE phMachine)
787 {
788 PWSTR pServerNameW;
789 CONFIGRET ret;
790
791 TRACE("%s %p\n", UNCServerName, phMachine);
792
793 if (UNCServerName == NULL || *UNCServerName == 0)
794 return CM_Connect_MachineW(NULL, phMachine);
795
796 if (pSetupCaptureAndConvertAnsiArg(UNCServerName, &pServerNameW))
797 return CR_INVALID_DATA;
798
799 ret = CM_Connect_MachineW(pServerNameW, phMachine);
800
801 MyFree(pServerNameW);
802
803 return ret;
804 }
805
806
807 /***********************************************************************
808 * CM_Connect_MachineW [SETUPAPI.@]
809 */
810 CONFIGRET WINAPI CM_Connect_MachineW(
811 PCWSTR UNCServerName, PHMACHINE phMachine)
812 {
813 PMACHINE_INFO pMachine;
814
815 TRACE("%s %p\n", debugstr_w(UNCServerName), phMachine);
816
817 if (phMachine == NULL)
818 return CR_INVALID_POINTER;
819
820 *phMachine = NULL;
821
822 pMachine = HeapAlloc(GetProcessHeap(), 0, sizeof(MACHINE_INFO));
823 if (pMachine == NULL)
824 return CR_OUT_OF_MEMORY;
825
826 if (UNCServerName == NULL || *UNCServerName == 0)
827 {
828 pMachine->bLocal = TRUE;
829
830 /* FIXME: store the computers name in pMachine->szMachineName */
831
832 if (!PnpGetLocalHandles(&pMachine->BindingHandle,
833 &pMachine->StringTable))
834 {
835 HeapFree(GetProcessHeap(), 0, pMachine);
836 return CR_FAILURE;
837 }
838 }
839 else
840 {
841 pMachine->bLocal = FALSE;
842 if (wcslen(UNCServerName) >= SP_MAX_MACHINENAME_LENGTH - 1)
843 {
844 HeapFree(GetProcessHeap(), 0, pMachine);
845 return CR_INVALID_MACHINENAME;
846 }
847 lstrcpyW(pMachine->szMachineName, UNCServerName);
848
849 pMachine->StringTable = pSetupStringTableInitialize();
850 if (pMachine->StringTable == NULL)
851 {
852 HeapFree(GetProcessHeap(), 0, pMachine);
853 return CR_FAILURE;
854 }
855
856 pSetupStringTableAddString(pMachine->StringTable, L"PLT", 1);
857
858 if (!PnpBindRpc(UNCServerName, &pMachine->BindingHandle))
859 {
860 pSetupStringTableDestroy(pMachine->StringTable);
861 HeapFree(GetProcessHeap(), 0, pMachine);
862 return CR_INVALID_MACHINENAME;
863 }
864 }
865
866 *phMachine = (PHMACHINE)pMachine;
867
868 return CR_SUCCESS;
869 }
870
871
872 /***********************************************************************
873 * CM_Create_DevNodeA [SETUPAPI.@]
874 */
875 CONFIGRET WINAPI CM_Create_DevNodeA(
876 PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, DEVINST dnParent,
877 ULONG ulFlags)
878 {
879 TRACE("%p %s %p %lx\n",
880 pdnDevInst, debugstr_a(pDeviceID), dnParent, ulFlags);
881 return CM_Create_DevNode_ExA(pdnDevInst, pDeviceID, dnParent,
882 ulFlags, NULL);
883 }
884
885
886 /***********************************************************************
887 * CM_Create_DevNodeW [SETUPAPI.@]
888 */
889 CONFIGRET WINAPI CM_Create_DevNodeW(
890 PDEVINST pdnDevInst, DEVINSTID_W pDeviceID, DEVINST dnParent,
891 ULONG ulFlags)
892 {
893 TRACE("%p %s %p %lx\n",
894 pdnDevInst, debugstr_w(pDeviceID), dnParent, ulFlags);
895 return CM_Create_DevNode_ExW(pdnDevInst, pDeviceID, dnParent,
896 ulFlags, NULL);
897 }
898
899
900 /***********************************************************************
901 * CM_Create_DevNode_ExA [SETUPAPI.@]
902 */
903 CONFIGRET WINAPI CM_Create_DevNode_ExA(
904 PDEVINST pdnDevInst, DEVINSTID_A pDeviceID, DEVINST dnParent,
905 ULONG ulFlags, HANDLE hMachine)
906 {
907 DEVINSTID_W pDeviceIDW;
908 CONFIGRET ret;
909
910 TRACE("%p %s %p %lx %p\n",
911 pdnDevInst, debugstr_a(pDeviceID), dnParent, ulFlags, hMachine);
912
913 if (pSetupCaptureAndConvertAnsiArg(pDeviceID, &pDeviceIDW))
914 return CR_INVALID_DATA;
915
916 ret = CM_Create_DevNode_ExW(pdnDevInst, pDeviceIDW, dnParent, ulFlags,
917 hMachine);
918
919 MyFree(pDeviceIDW);
920
921 return ret;
922 }
923
924
925 /***********************************************************************
926 * CM_Create_DevNode_ExW [SETUPAPI.@]
927 */
928 CONFIGRET WINAPI CM_Create_DevNode_ExW(
929 PDEVINST pdnDevInst, DEVINSTID_W pDeviceID, DEVINST dnParent,
930 ULONG ulFlags, HANDLE hMachine)
931 {
932 RPC_BINDING_HANDLE BindingHandle = NULL;
933 HSTRING_TABLE StringTable = NULL;
934 LPWSTR lpParentDevInst;
935 CONFIGRET ret = CR_SUCCESS;
936 WCHAR szLocalDeviceID[MAX_DEVICE_ID_LEN];
937
938 TRACE("%p %s %p %lx %p\n",
939 pdnDevInst, debugstr_w(pDeviceID), dnParent, ulFlags, hMachine);
940
941 if (!pSetupIsUserAdmin())
942 return CR_ACCESS_DENIED;
943
944 if (pdnDevInst == NULL)
945 return CR_INVALID_POINTER;
946
947 if (pDeviceID == NULL || wcslen(pDeviceID) == 0 || wcslen(pDeviceID) >= MAX_DEVICE_ID_LEN)
948 return CR_INVALID_DEVICE_ID;
949
950 if (dnParent == 0)
951 return CR_INVALID_DEVNODE;
952
953 if (ulFlags & ~CM_CREATE_DEVNODE_BITS)
954 return CR_INVALID_FLAG;
955
956 if (hMachine != NULL)
957 {
958 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
959 if (BindingHandle == NULL)
960 return CR_FAILURE;
961
962 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
963 if (StringTable == 0)
964 return CR_FAILURE;
965 }
966 else
967 {
968 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
969 return CR_FAILURE;
970 }
971
972 lpParentDevInst = pSetupStringTableStringFromId(StringTable, dnParent);
973 if (lpParentDevInst == NULL)
974 return CR_INVALID_DEVNODE;
975
976 wcscpy(szLocalDeviceID, pDeviceID);
977
978 RpcTryExcept
979 {
980 ret = PNP_CreateDevInst(BindingHandle,
981 szLocalDeviceID,
982 lpParentDevInst,
983 MAX_DEVICE_ID_LEN,
984 ulFlags);
985 }
986 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
987 {
988 ret = RpcStatusToCmStatus(RpcExceptionCode());
989 }
990 RpcEndExcept;
991
992 if (ret == CR_SUCCESS)
993 {
994 /* If CM_CREATE_DEVINST_GENERATE_ID was passed in, PNP_CreateDevInst
995 * will return the generated device ID in szLocalDeviceID */
996 *pdnDevInst = pSetupStringTableAddString(StringTable, szLocalDeviceID, 1);
997 if (*pdnDevInst == 0)
998 ret = CR_NO_SUCH_DEVNODE;
999 }
1000
1001 return ret;
1002 }
1003
1004
1005 /***********************************************************************
1006 * CM_Create_Range_List [SETUPAPI.@]
1007 */
1008 CONFIGRET
1009 WINAPI
1010 CM_Create_Range_List(
1011 _Out_ PRANGE_LIST prlh,
1012 _In_ ULONG ulFlags)
1013 {
1014 PINTERNAL_RANGE_LIST pRangeList = NULL;
1015
1016 FIXME("CM_Create_Range_List(%p %lx)\n", prlh, ulFlags);
1017
1018 if (ulFlags != 0)
1019 return CR_INVALID_FLAG;
1020
1021 if (prlh == NULL)
1022 return CR_INVALID_POINTER;
1023
1024 pRangeList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(INTERNAL_RANGE_LIST));
1025 if (pRangeList == NULL)
1026 return CR_OUT_OF_MEMORY;
1027
1028 pRangeList->ulMagic = RANGE_LIST_MAGIC;
1029
1030 // TODO: More initialization
1031
1032 *prlh = (RANGE_LIST)pRangeList;
1033
1034 return CR_SUCCESS;
1035 }
1036
1037
1038 /***********************************************************************
1039 * CM_Delete_Class_Key [SETUPAPI.@]
1040 */
1041 CONFIGRET WINAPI CM_Delete_Class_Key(
1042 LPGUID ClassGuid, ULONG ulFlags)
1043 {
1044 TRACE("%p %lx\n", ClassGuid, ulFlags);
1045 return CM_Delete_Class_Key_Ex(ClassGuid, ulFlags, NULL);
1046 }
1047
1048
1049 /***********************************************************************
1050 * CM_Delete_Class_Key_Ex [SETUPAPI.@]
1051 */
1052 CONFIGRET WINAPI CM_Delete_Class_Key_Ex(
1053 LPGUID ClassGuid, ULONG ulFlags, HANDLE hMachine)
1054 {
1055 WCHAR szGuidString[MAX_GUID_STRING_LEN];
1056 RPC_BINDING_HANDLE BindingHandle = NULL;
1057 CONFIGRET ret;
1058
1059 TRACE("%p %lx %lx\n", ClassGuid, ulFlags, hMachine);
1060
1061 if (ClassGuid == NULL)
1062 return CR_INVALID_POINTER;
1063
1064 if (ulFlags & ~CM_DELETE_CLASS_BITS)
1065 return CR_INVALID_FLAG;
1066
1067 if (!GuidToString(ClassGuid, szGuidString))
1068 return CR_INVALID_DATA;
1069
1070 if (hMachine != NULL)
1071 {
1072 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1073 if (BindingHandle == NULL)
1074 return CR_FAILURE;
1075 }
1076 else
1077 {
1078 if (!PnpGetLocalHandles(&BindingHandle, NULL))
1079 return CR_FAILURE;
1080 }
1081
1082 RpcTryExcept
1083 {
1084 ret = PNP_DeleteClassKey(BindingHandle,
1085 szGuidString,
1086 ulFlags);
1087 }
1088 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1089 {
1090 ret = RpcStatusToCmStatus(RpcExceptionCode());
1091 }
1092 RpcEndExcept;
1093
1094 return ret;
1095 }
1096
1097
1098 /***********************************************************************
1099 * CM_Delete_DevNode_Key [SETUPAPI.@]
1100 */
1101 CONFIGRET WINAPI CM_Delete_DevNode_Key(
1102 DEVNODE dnDevNode, ULONG ulHardwareProfile, ULONG ulFlags)
1103 {
1104 TRACE("%p %lu %lx\n", dnDevNode, ulHardwareProfile, ulFlags);
1105 return CM_Delete_DevNode_Key_Ex(dnDevNode, ulHardwareProfile, ulFlags,
1106 NULL);
1107 }
1108
1109
1110 /***********************************************************************
1111 * CM_Delete_DevNode_Key_Ex [SETUPAPI.@]
1112 */
1113 CONFIGRET WINAPI CM_Delete_DevNode_Key_Ex(
1114 DEVNODE dnDevNode, ULONG ulHardwareProfile, ULONG ulFlags,
1115 HANDLE hMachine)
1116 {
1117 FIXME("%p %lu %lx %p\n",
1118 dnDevNode, ulHardwareProfile, ulFlags, hMachine);
1119
1120 return CR_CALL_NOT_IMPLEMENTED;
1121 }
1122
1123
1124 /***********************************************************************
1125 * CM_Delete_Range [SETUPAPI.@]
1126 */
1127 CONFIGRET
1128 WINAPI
1129 CM_Delete_Range(
1130 _In_ DWORDLONG ullStartValue,
1131 _In_ DWORDLONG ullEndValue,
1132 _In_ RANGE_LIST rlh,
1133 _In_ ULONG ulFlags)
1134 {
1135 FIXME("CM_Delete_Range(%I64u %I64u %p %lx)\n",
1136 ullStartValue, ullEndValue, rlh, ulFlags);
1137 return CR_CALL_NOT_IMPLEMENTED;
1138 }
1139
1140
1141 /***********************************************************************
1142 * CM_Disable_DevNode [SETUPAPI.@]
1143 */
1144 CONFIGRET WINAPI CM_Disable_DevNode(
1145 DEVINST dnDevInst, ULONG ulFlags)
1146 {
1147 TRACE("%p %lx\n", dnDevInst, ulFlags);
1148 return CM_Disable_DevNode_Ex(dnDevInst, ulFlags, NULL);
1149 }
1150
1151
1152 /***********************************************************************
1153 * CM_Disable_DevNode_Ex [SETUPAPI.@]
1154 */
1155 CONFIGRET WINAPI CM_Disable_DevNode_Ex(
1156 DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
1157 {
1158 RPC_BINDING_HANDLE BindingHandle = NULL;
1159 HSTRING_TABLE StringTable = NULL;
1160 LPWSTR lpDevInst;
1161 CONFIGRET ret;
1162
1163 FIXME("%p %lx %p\n", dnDevInst, ulFlags, hMachine);
1164
1165 if (!pSetupIsUserAdmin())
1166 return CR_ACCESS_DENIED;
1167
1168 if (dnDevInst == 0)
1169 return CR_INVALID_DEVINST;
1170
1171 if (ulFlags != 0)
1172 return CR_INVALID_FLAG;
1173
1174 if (hMachine != NULL)
1175 {
1176 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1177 if (BindingHandle == NULL)
1178 return CR_FAILURE;
1179
1180 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1181 if (StringTable == 0)
1182 return CR_FAILURE;
1183 }
1184 else
1185 {
1186 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1187 return CR_FAILURE;
1188 }
1189
1190 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1191 if (lpDevInst == NULL)
1192 return CR_INVALID_DEVNODE;
1193
1194 RpcTryExcept
1195 {
1196 ret = PNP_DeviceInstanceAction(BindingHandle,
1197 PNP_DEVINST_DISABLE,
1198 ulFlags,
1199 lpDevInst,
1200 NULL);
1201 }
1202 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1203 {
1204 ret = RpcStatusToCmStatus(RpcExceptionCode());
1205 }
1206 RpcEndExcept;
1207
1208 return ret;
1209 }
1210
1211
1212 /***********************************************************************
1213 * CM_Disconnect_Machine [SETUPAPI.@]
1214 */
1215 CONFIGRET WINAPI CM_Disconnect_Machine(HMACHINE hMachine)
1216 {
1217 PMACHINE_INFO pMachine;
1218
1219 TRACE("%lx\n", hMachine);
1220
1221 pMachine = (PMACHINE_INFO)hMachine;
1222 if (pMachine == NULL)
1223 return CR_SUCCESS;
1224
1225 if (pMachine->bLocal == FALSE)
1226 {
1227 if (pMachine->StringTable != NULL)
1228 pSetupStringTableDestroy(pMachine->StringTable);
1229
1230 if (!PnpUnbindRpc(pMachine->BindingHandle))
1231 return CR_ACCESS_DENIED;
1232 }
1233
1234 HeapFree(GetProcessHeap(), 0, pMachine);
1235
1236 return CR_SUCCESS;
1237 }
1238
1239
1240 /***********************************************************************
1241 * CM_Dup_Range_List [SETUPAPI.@]
1242 */
1243 CONFIGRET
1244 WINAPI
1245 CM_Dup_Range_List(
1246 _In_ RANGE_LIST rlhOld,
1247 _In_ RANGE_LIST rlhNew,
1248 _In_ ULONG ulFlags)
1249 {
1250 FIXME("CM_Dup_Range_List(%p %p %lx)\n",
1251 rlhOld, rlhNew, ulFlags);
1252 return CR_CALL_NOT_IMPLEMENTED;
1253 }
1254
1255
1256 /***********************************************************************
1257 * CM_Enable_DevNode [SETUPAPI.@]
1258 */
1259 CONFIGRET WINAPI CM_Enable_DevNode(
1260 DEVINST dnDevInst, ULONG ulFlags)
1261 {
1262 TRACE("%p %lx\n", dnDevInst, ulFlags);
1263 return CM_Enable_DevNode_Ex(dnDevInst, ulFlags, NULL);
1264 }
1265
1266
1267 /***********************************************************************
1268 * CM_Enable_DevNode_Ex [SETUPAPI.@]
1269 */
1270 CONFIGRET WINAPI CM_Enable_DevNode_Ex(
1271 DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
1272 {
1273 RPC_BINDING_HANDLE BindingHandle = NULL;
1274 HSTRING_TABLE StringTable = NULL;
1275 LPWSTR lpDevInst;
1276 CONFIGRET ret;
1277
1278 TRACE("%p %lx %p\n", dnDevInst, ulFlags, hMachine);
1279
1280 if (!pSetupIsUserAdmin())
1281 return CR_ACCESS_DENIED;
1282
1283 if (dnDevInst == 0)
1284 return CR_INVALID_DEVINST;
1285
1286 if (ulFlags != 0)
1287 return CR_INVALID_FLAG;
1288
1289 if (hMachine != NULL)
1290 {
1291 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1292 if (BindingHandle == NULL)
1293 return CR_FAILURE;
1294
1295 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1296 if (StringTable == 0)
1297 return CR_FAILURE;
1298 }
1299 else
1300 {
1301 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1302 return CR_FAILURE;
1303 }
1304
1305 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1306 if (lpDevInst == NULL)
1307 return CR_INVALID_DEVNODE;
1308
1309 RpcTryExcept
1310 {
1311 ret = PNP_DeviceInstanceAction(BindingHandle,
1312 PNP_DEVINST_ENABLE,
1313 ulFlags,
1314 lpDevInst,
1315 NULL);
1316 }
1317 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1318 {
1319 ret = RpcStatusToCmStatus(RpcExceptionCode());
1320 }
1321 RpcEndExcept;
1322
1323 return ret;
1324 }
1325
1326
1327 /***********************************************************************
1328 * CM_Enumerate_Classes [SETUPAPI.@]
1329 */
1330 CONFIGRET WINAPI CM_Enumerate_Classes(
1331 ULONG ulClassIndex, LPGUID ClassGuid, ULONG ulFlags)
1332 {
1333 TRACE("%lx %p %lx\n", ulClassIndex, ClassGuid, ulFlags);
1334 return CM_Enumerate_Classes_Ex(ulClassIndex, ClassGuid, ulFlags, NULL);
1335 }
1336
1337
1338 /***********************************************************************
1339 * CM_Enumerate_Classes_Ex [SETUPAPI.@]
1340 */
1341 CONFIGRET WINAPI CM_Enumerate_Classes_Ex(
1342 ULONG ulClassIndex, LPGUID ClassGuid, ULONG ulFlags, HMACHINE hMachine)
1343 {
1344 WCHAR szBuffer[MAX_GUID_STRING_LEN];
1345 RPC_BINDING_HANDLE BindingHandle = NULL;
1346 CONFIGRET ret = CR_SUCCESS;
1347 ULONG ulLength = MAX_GUID_STRING_LEN;
1348
1349 TRACE("%lx %p %lx %p\n", ulClassIndex, ClassGuid, ulFlags, hMachine);
1350
1351 if (ClassGuid == NULL)
1352 return CR_INVALID_POINTER;
1353
1354 if (ulFlags != 0)
1355 return CR_INVALID_FLAG;
1356
1357 if (hMachine != NULL)
1358 {
1359 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1360 if (BindingHandle == NULL)
1361 return CR_FAILURE;
1362 }
1363 else
1364 {
1365 if (!PnpGetLocalHandles(&BindingHandle, NULL))
1366 return CR_FAILURE;
1367 }
1368
1369 RpcTryExcept
1370 {
1371 ret = PNP_EnumerateSubKeys(BindingHandle,
1372 PNP_CLASS_SUBKEYS,
1373 ulClassIndex,
1374 szBuffer,
1375 MAX_GUID_STRING_LEN,
1376 &ulLength,
1377 ulFlags);
1378 }
1379 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1380 {
1381 ret = RpcStatusToCmStatus(RpcExceptionCode());
1382 }
1383 RpcEndExcept;
1384
1385 if (ret == CR_SUCCESS)
1386 {
1387 /* Remove the {} */
1388 szBuffer[MAX_GUID_STRING_LEN - 2] = UNICODE_NULL;
1389
1390 /* Convert the buffer to a GUID */
1391 if (UuidFromStringW(&szBuffer[1], ClassGuid) != RPC_S_OK)
1392 return CR_FAILURE;
1393 }
1394
1395 return ret;
1396 }
1397
1398
1399 /***********************************************************************
1400 * CM_Enumerate_EnumeratorsA [SETUPAPI.@]
1401 */
1402 CONFIGRET WINAPI CM_Enumerate_EnumeratorsA(
1403 ULONG ulEnumIndex, PCHAR Buffer, PULONG pulLength, ULONG ulFlags)
1404 {
1405 TRACE("%lu %p %p %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags);
1406 return CM_Enumerate_Enumerators_ExA(ulEnumIndex, Buffer, pulLength,
1407 ulFlags, NULL);
1408 }
1409
1410
1411 /***********************************************************************
1412 * CM_Enumerate_EnumeratorsW [SETUPAPI.@]
1413 */
1414 CONFIGRET WINAPI CM_Enumerate_EnumeratorsW(
1415 ULONG ulEnumIndex, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags)
1416 {
1417 TRACE("%lu %p %p %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags);
1418 return CM_Enumerate_Enumerators_ExW(ulEnumIndex, Buffer, pulLength,
1419 ulFlags, NULL);
1420 }
1421
1422
1423 /***********************************************************************
1424 * CM_Enumerate_Enumerators_ExA [SETUPAPI.@]
1425 */
1426 CONFIGRET WINAPI CM_Enumerate_Enumerators_ExA(
1427 ULONG ulEnumIndex, PCHAR Buffer, PULONG pulLength, ULONG ulFlags,
1428 HMACHINE hMachine)
1429 {
1430 WCHAR szBuffer[MAX_DEVICE_ID_LEN];
1431 ULONG ulOrigLength;
1432 ULONG ulLength;
1433 CONFIGRET ret = CR_SUCCESS;
1434
1435 TRACE("%lu %p %p %lx %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags,
1436 hMachine);
1437
1438 if (Buffer == NULL || pulLength == NULL)
1439 return CR_INVALID_POINTER;
1440
1441 if (ulFlags != 0)
1442 return CR_INVALID_FLAG;
1443
1444 ulOrigLength = *pulLength;
1445 *pulLength = 0;
1446
1447 ulLength = MAX_DEVICE_ID_LEN;
1448 ret = CM_Enumerate_Enumerators_ExW(ulEnumIndex, szBuffer, &ulLength,
1449 ulFlags, hMachine);
1450 if (ret == CR_SUCCESS)
1451 {
1452 if (WideCharToMultiByte(CP_ACP,
1453 0,
1454 szBuffer,
1455 ulLength,
1456 Buffer,
1457 ulOrigLength,
1458 NULL,
1459 NULL) == 0)
1460 ret = CR_FAILURE;
1461 else
1462 *pulLength = lstrlenA(Buffer) + 1;
1463 }
1464
1465 return ret;
1466 }
1467
1468
1469 /***********************************************************************
1470 * CM_Enumerate_Enumerators_ExW [SETUPAPI.@]
1471 */
1472 CONFIGRET WINAPI CM_Enumerate_Enumerators_ExW(
1473 ULONG ulEnumIndex, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags,
1474 HMACHINE hMachine)
1475 {
1476 RPC_BINDING_HANDLE BindingHandle = NULL;
1477 CONFIGRET ret;
1478
1479 TRACE("%lu %p %p %lx %lx\n", ulEnumIndex, Buffer, pulLength, ulFlags,
1480 hMachine);
1481
1482 if (Buffer == NULL || pulLength == NULL)
1483 return CR_INVALID_POINTER;
1484
1485 if (ulFlags != 0)
1486 return CR_INVALID_FLAG;
1487
1488 *Buffer = UNICODE_NULL;
1489
1490 if (hMachine != NULL)
1491 {
1492 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1493 if (BindingHandle == NULL)
1494 return CR_FAILURE;
1495 }
1496 else
1497 {
1498 if (!PnpGetLocalHandles(&BindingHandle, NULL))
1499 return CR_FAILURE;
1500 }
1501
1502 RpcTryExcept
1503 {
1504 ret = PNP_EnumerateSubKeys(BindingHandle,
1505 PNP_ENUMERATOR_SUBKEYS,
1506 ulEnumIndex,
1507 Buffer,
1508 *pulLength,
1509 pulLength,
1510 ulFlags);
1511 }
1512 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1513 {
1514 ret = RpcStatusToCmStatus(RpcExceptionCode());
1515 }
1516 RpcEndExcept;
1517
1518 return ret;
1519 }
1520
1521
1522 /***********************************************************************
1523 * CM_Find_Range [SETUPAPI.@]
1524 */
1525 CONFIGRET
1526 WINAPI
1527 CM_Find_Range(
1528 _Out_ PDWORDLONG pullStart,
1529 _In_ DWORDLONG ullStart,
1530 _In_ ULONG ulLength,
1531 _In_ DWORDLONG ullAlignment,
1532 _In_ DWORDLONG ullEnd,
1533 _In_ RANGE_LIST rlh,
1534 _In_ ULONG ulFlags)
1535 {
1536 FIXME("CM_Find_Range(%p %I64u %lu %I64u %I64u %p %lx)\n",
1537 pullStart, ullStart, ulLength, ullAlignment, ullEnd, rlh, ulFlags);
1538 return CR_CALL_NOT_IMPLEMENTED;
1539 }
1540
1541
1542 /***********************************************************************
1543 * CM_First_Range [SETUPAPI.@]
1544 */
1545 CONFIGRET
1546 WINAPI
1547 CM_First_Range(
1548 _In_ RANGE_LIST rlh,
1549 _Out_ PDWORDLONG pullStart,
1550 _Out_ PDWORDLONG pullEnd,
1551 _Out_ PRANGE_ELEMENT preElement,
1552 _In_ ULONG ulFlags)
1553 {
1554 FIXME("CM_First_Range(%p %p %p %p %lx)\n",
1555 rlh, pullStart, pullEnd, preElement, ulFlags);
1556 return CR_CALL_NOT_IMPLEMENTED;
1557 }
1558
1559
1560 /***********************************************************************
1561 * CM_Free_Log_Conf [SETUPAPI.@]
1562 */
1563 CONFIGRET WINAPI CM_Free_Log_Conf(
1564 LOG_CONF lcLogConfToBeFreed, ULONG ulFlags)
1565 {
1566 TRACE("%lx %lx\n", lcLogConfToBeFreed, ulFlags);
1567 return CM_Free_Log_Conf_Ex(lcLogConfToBeFreed, ulFlags, NULL);
1568 }
1569
1570
1571 /***********************************************************************
1572 * CM_Free_Log_Conf_Ex [SETUPAPI.@]
1573 */
1574 CONFIGRET WINAPI CM_Free_Log_Conf_Ex(
1575 LOG_CONF lcLogConfToBeFreed, ULONG ulFlags, HMACHINE hMachine)
1576 {
1577 RPC_BINDING_HANDLE BindingHandle = NULL;
1578 HSTRING_TABLE StringTable = NULL;
1579 LPWSTR lpDevInst;
1580 PLOG_CONF_INFO pLogConfInfo;
1581 CONFIGRET ret;
1582
1583 TRACE("%lx %lx %lx\n", lcLogConfToBeFreed, ulFlags, hMachine);
1584
1585 if (!pSetupIsUserAdmin())
1586 return CR_ACCESS_DENIED;
1587
1588 pLogConfInfo = (PLOG_CONF_INFO)lcLogConfToBeFreed;
1589 if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
1590 return CR_INVALID_LOG_CONF;
1591
1592 if (ulFlags != 0)
1593 return CR_INVALID_FLAG;
1594
1595 if (hMachine != NULL)
1596 {
1597 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1598 if (BindingHandle == NULL)
1599 return CR_FAILURE;
1600
1601 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1602 if (StringTable == 0)
1603 return CR_FAILURE;
1604 }
1605 else
1606 {
1607 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1608 return CR_FAILURE;
1609 }
1610
1611 lpDevInst = pSetupStringTableStringFromId(StringTable, pLogConfInfo->dnDevInst);
1612 if (lpDevInst == NULL)
1613 return CR_INVALID_DEVNODE;
1614
1615 RpcTryExcept
1616 {
1617 ret = PNP_FreeLogConf(BindingHandle, lpDevInst, pLogConfInfo->ulFlags,
1618 pLogConfInfo->ulTag, 0);
1619 }
1620 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1621 {
1622 ret = RpcStatusToCmStatus(RpcExceptionCode());
1623 }
1624 RpcEndExcept;
1625
1626 return ret;
1627 }
1628
1629
1630 /***********************************************************************
1631 * CM_Free_Log_Conf_Handle [SETUPAPI.@]
1632 */
1633 CONFIGRET WINAPI CM_Free_Log_Conf_Handle(
1634 LOG_CONF lcLogConf)
1635 {
1636 PLOG_CONF_INFO pLogConfInfo;
1637
1638 TRACE("%lx\n", lcLogConf);
1639
1640 pLogConfInfo = (PLOG_CONF_INFO)lcLogConf;
1641 if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
1642 return CR_INVALID_LOG_CONF;
1643
1644 HeapFree(GetProcessHeap(), 0, pLogConfInfo);
1645
1646 return CR_SUCCESS;
1647 }
1648
1649
1650 /***********************************************************************
1651 * CM_Free_Range_List [SETUPAPI.@]
1652 */
1653 CONFIGRET
1654 WINAPI
1655 CM_Free_Range_List(
1656 _In_ RANGE_LIST RangeList,
1657 _In_ ULONG ulFlags)
1658 {
1659 PINTERNAL_RANGE_LIST pRangeList;
1660
1661 FIXME("CM_Free_Range_List(%p %lx)\n", RangeList, ulFlags);
1662
1663 pRangeList = (PINTERNAL_RANGE_LIST)RangeList;
1664
1665 if (pRangeList == NULL || pRangeList->ulMagic != RANGE_LIST_MAGIC)
1666 return CR_INVALID_RANGE_LIST;
1667
1668 if (ulFlags != 0)
1669 return CR_INVALID_FLAG;
1670
1671 // TODO: Free the list of ranges
1672
1673 HeapFree(GetProcessHeap(), 0, pRangeList);
1674
1675 return CR_SUCCESS;
1676 }
1677
1678
1679 /***********************************************************************
1680 * CM_Free_Res_Des [SETUPAPI.@]
1681 */
1682 CONFIGRET WINAPI CM_Free_Res_Des(
1683 PRES_DES prdResDes, RES_DES rdResDes, ULONG ulFlags)
1684 {
1685 TRACE("%p %p %lx\n", prdResDes, rdResDes, ulFlags);
1686 return CM_Free_Res_Des_Ex(prdResDes, rdResDes, ulFlags, NULL);
1687 }
1688
1689
1690 /***********************************************************************
1691 * CM_Free_Res_Des_Ex [SETUPAPI.@]
1692 */
1693 CONFIGRET WINAPI CM_Free_Res_Des_Ex(
1694 PRES_DES prdResDes, RES_DES rdResDes, ULONG ulFlags,
1695 HMACHINE hMachine)
1696 {
1697 FIXME("%p %p %lx %lx\n", prdResDes, rdResDes, ulFlags, hMachine);
1698
1699 return CR_CALL_NOT_IMPLEMENTED;
1700 }
1701
1702
1703 /***********************************************************************
1704 * CM_Free_Res_Des_Handle [SETUPAPI.@]
1705 */
1706 CONFIGRET WINAPI CM_Free_Res_Des_Handle(
1707 RES_DES rdResDes)
1708 {
1709 FIXME("%p\n", rdResDes);
1710
1711 return CR_CALL_NOT_IMPLEMENTED;
1712 }
1713
1714
1715 /***********************************************************************
1716 * CM_Get_Child [SETUPAPI.@]
1717 */
1718 CONFIGRET WINAPI CM_Get_Child(
1719 PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags)
1720 {
1721 TRACE("%p %p %lx\n", pdnDevInst, dnDevInst, ulFlags);
1722 return CM_Get_Child_Ex(pdnDevInst, dnDevInst, ulFlags, NULL);
1723 }
1724
1725
1726 /***********************************************************************
1727 * CM_Get_Child_Ex [SETUPAPI.@]
1728 */
1729 CONFIGRET WINAPI CM_Get_Child_Ex(
1730 PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
1731 {
1732 WCHAR szRelatedDevInst[MAX_DEVICE_ID_LEN];
1733 RPC_BINDING_HANDLE BindingHandle = NULL;
1734 HSTRING_TABLE StringTable = NULL;
1735 LPWSTR lpDevInst;
1736 DWORD dwIndex, dwLength = MAX_DEVICE_ID_LEN;
1737 CONFIGRET ret;
1738
1739 TRACE("%p %lx %lx %lx\n", pdnDevInst, dnDevInst, ulFlags, hMachine);
1740
1741 if (pdnDevInst == NULL)
1742 return CR_INVALID_POINTER;
1743
1744 if (dnDevInst == 0)
1745 return CR_INVALID_DEVINST;
1746
1747 if (ulFlags != 0)
1748 return CR_INVALID_FLAG;
1749
1750 *pdnDevInst = -1;
1751
1752 if (hMachine != NULL)
1753 {
1754 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1755 if (BindingHandle == NULL)
1756 return CR_FAILURE;
1757
1758 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
1759 if (StringTable == 0)
1760 return CR_FAILURE;
1761 }
1762 else
1763 {
1764 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
1765 return CR_FAILURE;
1766 }
1767
1768 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
1769 if (lpDevInst == NULL)
1770 return CR_INVALID_DEVNODE;
1771
1772 RpcTryExcept
1773 {
1774 ret = PNP_GetRelatedDeviceInstance(BindingHandle,
1775 PNP_GET_CHILD_DEVICE_INSTANCE,
1776 lpDevInst,
1777 szRelatedDevInst,
1778 &dwLength,
1779 0);
1780 }
1781 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
1782 {
1783 ret = RpcStatusToCmStatus(RpcExceptionCode());
1784 }
1785 RpcEndExcept;
1786
1787 if (ret != CR_SUCCESS)
1788 return ret;
1789
1790 TRACE("szRelatedDevInst: %s\n", debugstr_w(szRelatedDevInst));
1791
1792 dwIndex = pSetupStringTableAddString(StringTable, szRelatedDevInst, 1);
1793 if (dwIndex == -1)
1794 return CR_FAILURE;
1795
1796 *pdnDevInst = dwIndex;
1797
1798 return CR_SUCCESS;
1799 }
1800
1801
1802 /***********************************************************************
1803 * CM_Get_Class_Key_NameA [SETUPAPI.@]
1804 */
1805 CONFIGRET WINAPI CM_Get_Class_Key_NameA(
1806 LPGUID ClassGuid, LPSTR pszKeyName, PULONG pulLength, ULONG ulFlags)
1807 {
1808 TRACE("%p %p %p %lx\n",
1809 ClassGuid, pszKeyName, pulLength, ulFlags);
1810 return CM_Get_Class_Key_Name_ExA(ClassGuid, pszKeyName, pulLength,
1811 ulFlags, NULL);
1812 }
1813
1814
1815 /***********************************************************************
1816 * CM_Get_Class_Key_NameW [SETUPAPI.@]
1817 */
1818 CONFIGRET WINAPI CM_Get_Class_Key_NameW(
1819 LPGUID ClassGuid, LPWSTR pszKeyName, PULONG pulLength, ULONG ulFlags)
1820 {
1821 TRACE("%p %p %p %lx\n",
1822 ClassGuid, pszKeyName, pulLength, ulFlags);
1823 return CM_Get_Class_Key_Name_ExW(ClassGuid, pszKeyName, pulLength,
1824 ulFlags, NULL);
1825 }
1826
1827
1828 /***********************************************************************
1829 * CM_Get_Class_Key_Name_ExA [SETUPAPI.@]
1830 */
1831 CONFIGRET WINAPI CM_Get_Class_Key_Name_ExA(
1832 LPGUID ClassGuid, LPSTR pszKeyName, PULONG pulLength, ULONG ulFlags,
1833 HMACHINE hMachine)
1834 {
1835 WCHAR szBuffer[MAX_GUID_STRING_LEN];
1836 CONFIGRET ret = CR_SUCCESS;
1837 ULONG ulLength;
1838 ULONG ulOrigLength;
1839
1840 TRACE("%p %p %p %lx %lx\n",
1841 ClassGuid, pszKeyName, pulLength, ulFlags, hMachine);
1842
1843 if (ClassGuid == NULL || pszKeyName == NULL || pulLength == NULL)
1844 return CR_INVALID_POINTER;
1845
1846 ulOrigLength = *pulLength;
1847 *pulLength = 0;
1848
1849 ulLength = MAX_GUID_STRING_LEN;
1850 ret = CM_Get_Class_Key_Name_ExW(ClassGuid, szBuffer, &ulLength,
1851 ulFlags, hMachine);
1852 if (ret == CR_SUCCESS)
1853 {
1854 if (WideCharToMultiByte(CP_ACP,
1855 0,
1856 szBuffer,
1857 ulLength,
1858 pszKeyName,
1859 ulOrigLength,
1860 NULL,
1861 NULL) == 0)
1862 ret = CR_FAILURE;
1863 else
1864 *pulLength = lstrlenA(pszKeyName) + 1;
1865 }
1866
1867 return CR_SUCCESS;
1868 }
1869
1870
1871 /***********************************************************************
1872 * CM_Get_Class_Key_Name_ExW [SETUPAPI.@]
1873 */
1874 CONFIGRET WINAPI CM_Get_Class_Key_Name_ExW(
1875 LPGUID ClassGuid, LPWSTR pszKeyName, PULONG pulLength, ULONG ulFlags,
1876 HMACHINE hMachine)
1877 {
1878 TRACE("%p %p %p %lx %lx\n",
1879 ClassGuid, pszKeyName, pulLength, ulFlags, hMachine);
1880
1881 if (ClassGuid == NULL || pszKeyName == NULL || pulLength == NULL)
1882 return CR_INVALID_POINTER;
1883
1884 if (ulFlags != 0)
1885 return CR_INVALID_FLAG;
1886
1887 if (*pulLength < MAX_GUID_STRING_LEN)
1888 {
1889 *pulLength = 0;
1890 return CR_BUFFER_SMALL;
1891 }
1892
1893 if (!GuidToString(ClassGuid, pszKeyName))
1894 return CR_INVALID_DATA;
1895
1896 *pulLength = MAX_GUID_STRING_LEN;
1897
1898 return CR_SUCCESS;
1899 }
1900
1901
1902 /***********************************************************************
1903 * CM_Get_Class_NameA [SETUPAPI.@]
1904 */
1905 CONFIGRET WINAPI CM_Get_Class_NameA(
1906 LPGUID ClassGuid, PCHAR Buffer, PULONG pulLength, ULONG ulFlags)
1907 {
1908 TRACE("%p %p %p %lx\n", ClassGuid, Buffer, pulLength, ulFlags);
1909 return CM_Get_Class_Name_ExA(ClassGuid, Buffer, pulLength, ulFlags,
1910 NULL);
1911 }
1912
1913
1914 /***********************************************************************
1915 * CM_Get_Class_NameW [SETUPAPI.@]
1916 */
1917 CONFIGRET WINAPI CM_Get_Class_NameW(
1918 LPGUID ClassGuid, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags)
1919 {
1920 TRACE("%p %p %p %lx\n", ClassGuid, Buffer, pulLength, ulFlags);
1921 return CM_Get_Class_Name_ExW(ClassGuid, Buffer, pulLength, ulFlags,
1922 NULL);
1923 }
1924
1925
1926 /***********************************************************************
1927 * CM_Get_Class_Name_ExA [SETUPAPI.@]
1928 */
1929 CONFIGRET WINAPI CM_Get_Class_Name_ExA(
1930 LPGUID ClassGuid, PCHAR Buffer, PULONG pulLength, ULONG ulFlags,
1931 HMACHINE hMachine)
1932 {
1933 WCHAR szBuffer[MAX_CLASS_NAME_LEN];
1934 CONFIGRET ret = CR_SUCCESS;
1935 ULONG ulLength;
1936 ULONG ulOrigLength;
1937
1938 TRACE("%p %p %p %lx %lx\n",
1939 ClassGuid, Buffer, pulLength, ulFlags, hMachine);
1940
1941 if (ClassGuid == NULL || Buffer == NULL || pulLength == NULL)
1942 return CR_INVALID_POINTER;
1943
1944 ulOrigLength = *pulLength;
1945 *pulLength = 0;
1946
1947 ulLength = MAX_CLASS_NAME_LEN;
1948 ret = CM_Get_Class_Name_ExW(ClassGuid, szBuffer, &ulLength,
1949 ulFlags, hMachine);
1950 if (ret == CR_SUCCESS)
1951 {
1952 if (WideCharToMultiByte(CP_ACP,
1953 0,
1954 szBuffer,
1955 ulLength,
1956 Buffer,
1957 ulOrigLength,
1958 NULL,
1959 NULL) == 0)
1960 ret = CR_FAILURE;
1961 else
1962 *pulLength = lstrlenA(Buffer) + 1;
1963 }
1964
1965 return ret;
1966 }
1967
1968
1969 /***********************************************************************
1970 * CM_Get_Class_Name_ExW [SETUPAPI.@]
1971 */
1972 CONFIGRET WINAPI
1973 CM_Get_Class_Name_ExW(
1974 LPGUID ClassGuid, PWCHAR Buffer, PULONG pulLength, ULONG ulFlags,
1975 HMACHINE hMachine)
1976 {
1977 WCHAR szGuidString[MAX_GUID_STRING_LEN];
1978 RPC_BINDING_HANDLE BindingHandle = NULL;
1979 CONFIGRET ret;
1980
1981 TRACE("%p %p %p %lx %lx\n",
1982 ClassGuid, Buffer, pulLength, ulFlags, hMachine);
1983
1984 if (ClassGuid == NULL || Buffer == NULL || pulLength == NULL)
1985 return CR_INVALID_POINTER;
1986
1987 if (ulFlags != 0)
1988 return CR_INVALID_FLAG;
1989
1990 if (!GuidToString(ClassGuid, szGuidString))
1991 return CR_INVALID_DATA;
1992
1993 TRACE("Guid %s\n", debugstr_w(szGuidString));
1994
1995 if (hMachine != NULL)
1996 {
1997 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
1998 if (BindingHandle == NULL)
1999 return CR_FAILURE;
2000 }
2001 else
2002 {
2003 if (!PnpGetLocalHandles(&BindingHandle, NULL))
2004 return CR_FAILURE;
2005 }
2006
2007 RpcTryExcept
2008 {
2009 ret = PNP_GetClassName(BindingHandle,
2010 szGuidString,
2011 Buffer,
2012 pulLength,
2013 ulFlags);
2014 }
2015 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2016 {
2017 ret = RpcStatusToCmStatus(RpcExceptionCode());
2018 }
2019 RpcEndExcept;
2020
2021 return ret;
2022 }
2023
2024
2025 /***********************************************************************
2026 * CM_Get_Class_Registry_PropertyA [SETUPAPI.@]
2027 */
2028 CONFIGRET WINAPI CM_Get_Class_Registry_PropertyA(
2029 LPGUID ClassGuid, ULONG ulProperty, PULONG pulRegDataType,
2030 PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2031 {
2032 PWSTR BufferW = NULL;
2033 ULONG ulLength = 0;
2034 ULONG ulType;
2035 CONFIGRET ret;
2036
2037 TRACE("%p %lu %p %p %p %lx %lx\n",
2038 ClassGuid, ulProperty, pulRegDataType, Buffer, pulLength,
2039 ulFlags, hMachine);
2040
2041 if (pulLength == NULL)
2042 return CR_INVALID_POINTER;
2043
2044 if (ulProperty < CM_CRP_MIN || ulProperty > CM_CRP_MAX)
2045 return CR_INVALID_PROPERTY;
2046
2047 ulType = GetRegistryPropertyType(ulProperty);
2048 if (ulType == REG_SZ || ulType == REG_MULTI_SZ)
2049 {
2050 /* Get the required buffer size */
2051 ret = CM_Get_Class_Registry_PropertyW(ClassGuid, ulProperty, pulRegDataType,
2052 NULL, &ulLength, ulFlags, hMachine);
2053 if (ret != CR_BUFFER_SMALL)
2054 return ret;
2055
2056 /* Allocate the unicode buffer */
2057 BufferW = HeapAlloc(GetProcessHeap(), 0, ulLength);
2058 if (BufferW == NULL)
2059 return CR_OUT_OF_MEMORY;
2060
2061 /* Get the property */
2062 ret = CM_Get_Class_Registry_PropertyW(ClassGuid, ulProperty, pulRegDataType,
2063 BufferW, &ulLength, ulFlags, hMachine);
2064 if (ret != CR_SUCCESS)
2065 {
2066 HeapFree(GetProcessHeap(), 0, BufferW);
2067 return ret;
2068 }
2069
2070 /* Do W->A conversion */
2071 *pulLength = WideCharToMultiByte(CP_ACP,
2072 0,
2073 BufferW,
2074 lstrlenW(BufferW) + 1,
2075 Buffer,
2076 *pulLength,
2077 NULL,
2078 NULL);
2079
2080 /* Release the unicode buffer */
2081 HeapFree(GetProcessHeap(), 0, BufferW);
2082
2083 if (*pulLength == 0)
2084 ret = CR_FAILURE;
2085 }
2086 else
2087 {
2088 /* Get the property */
2089 ret = CM_Get_Class_Registry_PropertyW(ClassGuid, ulProperty, pulRegDataType,
2090 Buffer, pulLength, ulFlags, hMachine);
2091 }
2092
2093 return ret;
2094 }
2095
2096
2097 /***********************************************************************
2098 * CM_Get_Class_Registry_PropertyW [SETUPAPI.@]
2099 */
2100 CONFIGRET WINAPI CM_Get_Class_Registry_PropertyW(
2101 LPGUID ClassGuid, ULONG ulProperty, PULONG pulRegDataType,
2102 PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2103 {
2104 RPC_BINDING_HANDLE BindingHandle = NULL;
2105 WCHAR szGuidString[PNP_MAX_GUID_STRING_LEN + 1];
2106 ULONG ulType = 0;
2107 ULONG ulTransferLength = 0;
2108 CONFIGRET ret;
2109
2110 TRACE("%p %lu %p %p %p %lx %lx\n",
2111 ClassGuid, ulProperty, pulRegDataType, Buffer, pulLength,
2112 ulFlags, hMachine);
2113
2114 if (ClassGuid == NULL || pulLength == NULL)
2115 return CR_INVALID_POINTER;
2116
2117 if (ulFlags != 0)
2118 return CR_INVALID_FLAG;
2119
2120 if (pSetupStringFromGuid(ClassGuid,
2121 szGuidString,
2122 PNP_MAX_GUID_STRING_LEN) != 0)
2123 return CR_INVALID_DATA;
2124
2125 if (ulProperty < CM_CRP_MIN || ulProperty > CM_CRP_MAX)
2126 return CR_INVALID_PROPERTY;
2127
2128 if (hMachine != NULL)
2129 {
2130 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2131 if (BindingHandle == NULL)
2132 return CR_FAILURE;
2133 }
2134 else
2135 {
2136 if (!PnpGetLocalHandles(&BindingHandle, NULL))
2137 return CR_FAILURE;
2138 }
2139
2140 ulTransferLength = *pulLength;
2141
2142 RpcTryExcept
2143 {
2144 ret = PNP_GetClassRegProp(BindingHandle,
2145 szGuidString,
2146 ulProperty,
2147 &ulType,
2148 Buffer,
2149 &ulTransferLength,
2150 pulLength,
2151 ulFlags);
2152 }
2153 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2154 {
2155 ret = RpcStatusToCmStatus(RpcExceptionCode());
2156 }
2157 RpcEndExcept;
2158
2159 if (ret == CR_SUCCESS)
2160 {
2161 if (pulRegDataType != NULL)
2162 *pulRegDataType = ulType;
2163 }
2164
2165 return ret;
2166 }
2167
2168
2169 /***********************************************************************
2170 * CM_Get_Depth [SETUPAPI.@]
2171 */
2172 CONFIGRET WINAPI CM_Get_Depth(
2173 PULONG pulDepth, DEVINST dnDevInst, ULONG ulFlags)
2174 {
2175 TRACE("%p %lx %lx\n", pulDepth, dnDevInst, ulFlags);
2176 return CM_Get_Depth_Ex(pulDepth, dnDevInst, ulFlags, NULL);
2177 }
2178
2179
2180 /***********************************************************************
2181 * CM_Get_Depth_Ex [SETUPAPI.@]
2182 */
2183 CONFIGRET WINAPI CM_Get_Depth_Ex(
2184 PULONG pulDepth, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
2185 {
2186 RPC_BINDING_HANDLE BindingHandle = NULL;
2187 HSTRING_TABLE StringTable = NULL;
2188 LPWSTR lpDevInst;
2189 CONFIGRET ret;
2190
2191 TRACE("%p %lx %lx %lx\n",
2192 pulDepth, dnDevInst, ulFlags, hMachine);
2193
2194 if (pulDepth == NULL)
2195 return CR_INVALID_POINTER;
2196
2197 if (dnDevInst == 0)
2198 return CR_INVALID_DEVINST;
2199
2200 if (ulFlags != 0)
2201 return CR_INVALID_FLAG;
2202
2203 if (hMachine != NULL)
2204 {
2205 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2206 if (BindingHandle == NULL)
2207 return CR_FAILURE;
2208
2209 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2210 if (StringTable == 0)
2211 return CR_FAILURE;
2212 }
2213 else
2214 {
2215 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2216 return CR_FAILURE;
2217 }
2218
2219 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2220 if (lpDevInst == NULL)
2221 return CR_INVALID_DEVNODE;
2222
2223 RpcTryExcept
2224 {
2225 ret = PNP_GetDepth(BindingHandle,
2226 lpDevInst,
2227 pulDepth,
2228 ulFlags);
2229 }
2230 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2231 {
2232 ret = RpcStatusToCmStatus(RpcExceptionCode());
2233 }
2234 RpcEndExcept;
2235
2236 return ret;
2237 }
2238
2239
2240 /***********************************************************************
2241 * CM_Get_DevNode_Custom_PropertyA [SETUPAPI.@]
2242 */
2243 CONFIGRET WINAPI CM_Get_DevNode_Custom_PropertyA(
2244 DEVINST dnDevInst, PCSTR pszCustomPropertyName, PULONG pulRegDataType,
2245 PVOID Buffer, PULONG pulLength, ULONG ulFlags)
2246 {
2247 TRACE("%lx %s %p %p %p %lx\n", dnDevInst, pszCustomPropertyName,
2248 pulRegDataType, Buffer, pulLength, ulFlags);
2249 return CM_Get_DevNode_Custom_Property_ExA(dnDevInst, pszCustomPropertyName,
2250 pulRegDataType, Buffer,
2251 pulLength, ulFlags, NULL);
2252 }
2253
2254
2255 /***********************************************************************
2256 * CM_Get_DevNode_Custom_PropertyW [SETUPAPI.@]
2257 */
2258 CONFIGRET WINAPI CM_Get_DevNode_Custom_PropertyW(
2259 DEVINST dnDevInst, PCWSTR pszCustomPropertyName, PULONG pulRegDataType,
2260 PVOID Buffer, PULONG pulLength, ULONG ulFlags)
2261 {
2262 TRACE("%lx %s %p %p %p %lx\n", dnDevInst, debugstr_w(pszCustomPropertyName),
2263 pulRegDataType, Buffer, pulLength, ulFlags);
2264 return CM_Get_DevNode_Custom_Property_ExW(dnDevInst, pszCustomPropertyName,
2265 pulRegDataType, Buffer,
2266 pulLength, ulFlags, NULL);
2267 }
2268
2269
2270 /***********************************************************************
2271 * CM_Get_DevNode_Custom_Property_ExA [SETUPAPI.@]
2272 */
2273 CONFIGRET WINAPI CM_Get_DevNode_Custom_Property_ExA(
2274 DEVINST dnDevInst, PCSTR pszCustomPropertyName, PULONG pulRegDataType,
2275 PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2276 {
2277 LPWSTR pszPropertyNameW = NULL;
2278 PVOID BufferW;
2279 ULONG ulLengthW;
2280 ULONG ulDataType = REG_NONE;
2281 CONFIGRET ret;
2282
2283 TRACE("%lx %s %p %p %p %lx %p\n", dnDevInst, pszCustomPropertyName,
2284 pulRegDataType, Buffer, pulLength, ulFlags, hMachine);
2285
2286 if (!pulLength)
2287 return CR_INVALID_POINTER;
2288
2289 ulLengthW = *pulLength * sizeof(WCHAR);
2290 BufferW = HeapAlloc(GetProcessHeap(), 0, ulLengthW);
2291 if (!BufferW)
2292 return CR_OUT_OF_MEMORY;
2293
2294 pszPropertyNameW = pSetupMultiByteToUnicode(pszCustomPropertyName,
2295 CP_ACP);
2296 if (pszPropertyNameW == NULL)
2297 {
2298 HeapFree(GetProcessHeap(), 0, BufferW);
2299 return CR_OUT_OF_MEMORY;
2300 }
2301
2302 ret = CM_Get_DevNode_Custom_Property_ExW(dnDevInst,
2303 pszPropertyNameW,
2304 &ulDataType,
2305 BufferW,
2306 &ulLengthW,
2307 ulFlags,
2308 hMachine);
2309 if (ret == CR_SUCCESS)
2310 {
2311 if (ulDataType == REG_SZ ||
2312 ulDataType == REG_EXPAND_SZ ||
2313 ulDataType == REG_MULTI_SZ)
2314 {
2315 /* Do W->A conversion */
2316 *pulLength = WideCharToMultiByte(CP_ACP,
2317 0,
2318 BufferW,
2319 lstrlenW(BufferW) + 1,
2320 Buffer,
2321 *pulLength,
2322 NULL,
2323 NULL);
2324 if (*pulLength == 0)
2325 ret = CR_FAILURE;
2326 }
2327 else
2328 {
2329 /* Directly copy the value */
2330 if (ulLengthW <= *pulLength)
2331 memcpy(Buffer, BufferW, ulLengthW);
2332 else
2333 {
2334 *pulLength = ulLengthW;
2335 ret = CR_BUFFER_SMALL;
2336 }
2337 }
2338 }
2339
2340 if (pulRegDataType)
2341 *pulRegDataType = ulDataType;
2342
2343 HeapFree(GetProcessHeap(), 0, BufferW);
2344 MyFree(pszPropertyNameW);
2345
2346 return ret;
2347 }
2348
2349
2350 /***********************************************************************
2351 * CM_Get_DevNode_Custom_Property_ExW [SETUPAPI.@]
2352 */
2353 CONFIGRET WINAPI CM_Get_DevNode_Custom_Property_ExW(
2354 DEVINST dnDevInst, PCWSTR pszCustomPropertyName, PULONG pulRegDataType,
2355 PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2356 {
2357 RPC_BINDING_HANDLE BindingHandle = NULL;
2358 HSTRING_TABLE StringTable = NULL;
2359 LPWSTR lpDevInst;
2360 ULONG ulDataType = REG_NONE;
2361 ULONG ulTransferLength;
2362 CONFIGRET ret = CR_SUCCESS;
2363
2364 TRACE("%lx %s %p %p %p %lx %p\n", dnDevInst,
2365 debugstr_w(pszCustomPropertyName), pulRegDataType, Buffer,
2366 pulLength, ulFlags, hMachine);
2367
2368 if (dnDevInst == 0)
2369 return CR_INVALID_DEVNODE;
2370
2371 if (pszCustomPropertyName == NULL ||
2372 pulLength == NULL ||
2373 *pulLength == 0)
2374 return CR_INVALID_POINTER;
2375
2376 if (ulFlags & ~CM_CUSTOMDEVPROP_BITS)
2377 return CR_INVALID_FLAG;
2378
2379 if (hMachine != NULL)
2380 {
2381 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2382 if (BindingHandle == NULL)
2383 return CR_FAILURE;
2384
2385 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2386 if (StringTable == 0)
2387 return CR_FAILURE;
2388 }
2389 else
2390 {
2391 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2392 return CR_FAILURE;
2393 }
2394
2395 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2396 if (lpDevInst == NULL)
2397 return CR_INVALID_DEVNODE;
2398
2399 ulTransferLength = *pulLength;
2400
2401 RpcTryExcept
2402 {
2403 ret = PNP_GetCustomDevProp(BindingHandle,
2404 lpDevInst,
2405 (LPWSTR)pszCustomPropertyName,
2406 &ulDataType,
2407 Buffer,
2408 &ulTransferLength,
2409 pulLength,
2410 ulFlags);
2411 }
2412 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2413 {
2414 ret = RpcStatusToCmStatus(RpcExceptionCode());
2415 }
2416 RpcEndExcept;
2417
2418 if (ret == CR_SUCCESS)
2419 {
2420 if (pulRegDataType != NULL)
2421 *pulRegDataType = ulDataType;
2422 }
2423
2424 return ret;
2425 }
2426
2427
2428 /***********************************************************************
2429 * CM_Get_DevNode_Registry_PropertyA [SETUPAPI.@]
2430 */
2431 CONFIGRET WINAPI CM_Get_DevNode_Registry_PropertyA(
2432 DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
2433 PVOID Buffer, PULONG pulLength, ULONG ulFlags)
2434 {
2435 TRACE("%lx %lu %p %p %p %lx\n",
2436 dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength, ulFlags);
2437
2438 return CM_Get_DevNode_Registry_Property_ExA(dnDevInst, ulProperty,
2439 pulRegDataType, Buffer,
2440 pulLength, ulFlags, NULL);
2441 }
2442
2443
2444 /***********************************************************************
2445 * CM_Get_DevNode_Registry_PropertyW [SETUPAPI.@]
2446 */
2447 CONFIGRET WINAPI CM_Get_DevNode_Registry_PropertyW(
2448 DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
2449 PVOID Buffer, PULONG pulLength, ULONG ulFlags)
2450 {
2451 TRACE("%lx %lu %p %p %p %lx\n",
2452 dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength, ulFlags);
2453
2454 return CM_Get_DevNode_Registry_Property_ExW(dnDevInst, ulProperty,
2455 pulRegDataType, Buffer,
2456 pulLength, ulFlags, NULL);
2457 }
2458
2459
2460 /***********************************************************************
2461 * CM_Get_DevNode_Registry_Property_ExA [SETUPAPI.@]
2462 */
2463 CONFIGRET WINAPI CM_Get_DevNode_Registry_Property_ExA(
2464 DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
2465 PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2466 {
2467 PVOID BufferW;
2468 ULONG LengthW;
2469 ULONG ulDataType = REG_NONE;
2470 CONFIGRET ret;
2471
2472 TRACE("%lx %lu %p %p %p %lx %lx\n",
2473 dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength,
2474 ulFlags, hMachine);
2475
2476 if (!pulLength)
2477 return CR_INVALID_POINTER;
2478
2479 LengthW = *pulLength * sizeof(WCHAR);
2480 BufferW = HeapAlloc(GetProcessHeap(), 0, LengthW);
2481
2482 if (!BufferW)
2483 return CR_OUT_OF_MEMORY;
2484
2485 ret = CM_Get_DevNode_Registry_Property_ExW(dnDevInst,
2486 ulProperty,
2487 &ulDataType,
2488 BufferW,
2489 &LengthW,
2490 ulFlags,
2491 hMachine);
2492
2493 if (ret == CR_SUCCESS)
2494 {
2495 if (ulDataType == REG_SZ ||
2496 ulDataType == REG_EXPAND_SZ ||
2497 ulDataType == REG_MULTI_SZ)
2498 {
2499 /* Do W->A conversion */
2500 *pulLength = WideCharToMultiByte(CP_ACP,
2501 0,
2502 BufferW,
2503 lstrlenW(BufferW) + 1,
2504 Buffer,
2505 *pulLength,
2506 NULL,
2507 NULL);
2508 if (*pulLength == 0)
2509 ret = CR_FAILURE;
2510 }
2511 else
2512 {
2513 /* Directly copy the value */
2514 if (LengthW <= *pulLength)
2515 memcpy(Buffer, BufferW, LengthW);
2516 else
2517 {
2518 *pulLength = LengthW;
2519 ret = CR_BUFFER_SMALL;
2520 }
2521 }
2522 }
2523
2524 if (pulRegDataType)
2525 *pulRegDataType = ulDataType;
2526
2527 HeapFree(GetProcessHeap(), 0, BufferW);
2528
2529 return ret;
2530 }
2531
2532
2533 /***********************************************************************
2534 * CM_Get_DevNode_Registry_Property_ExW [SETUPAPI.@]
2535 */
2536 CONFIGRET WINAPI CM_Get_DevNode_Registry_Property_ExW(
2537 DEVINST dnDevInst, ULONG ulProperty, PULONG pulRegDataType,
2538 PVOID Buffer, PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
2539 {
2540 RPC_BINDING_HANDLE BindingHandle = NULL;
2541 HSTRING_TABLE StringTable = NULL;
2542 CONFIGRET ret = CR_SUCCESS;
2543 LPWSTR lpDevInst;
2544 ULONG ulDataType = REG_NONE;
2545 ULONG ulTransferLength = 0;
2546
2547 TRACE("%lx %lu %p %p %p %lx %lx\n",
2548 dnDevInst, ulProperty, pulRegDataType, Buffer, pulLength,
2549 ulFlags, hMachine);
2550
2551 if (dnDevInst == 0)
2552 return CR_INVALID_DEVNODE;
2553
2554 if (ulProperty < CM_DRP_MIN || ulProperty > CM_DRP_MAX)
2555 return CR_INVALID_PROPERTY;
2556
2557 /* pulRegDataType is optional */
2558
2559 /* Buffer is optional */
2560
2561 if (pulLength == NULL)
2562 return CR_INVALID_POINTER;
2563
2564 if (*pulLength == 0)
2565 return CR_INVALID_POINTER;
2566
2567 if (ulFlags != 0)
2568 return CR_INVALID_FLAG;
2569
2570 if (hMachine != NULL)
2571 {
2572 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2573 if (BindingHandle == NULL)
2574 return CR_FAILURE;
2575
2576 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2577 if (StringTable == 0)
2578 return CR_FAILURE;
2579 }
2580 else
2581 {
2582 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2583 return CR_FAILURE;
2584 }
2585
2586 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2587 if (lpDevInst == NULL)
2588 return CR_INVALID_DEVNODE;
2589
2590 ulTransferLength = *pulLength;
2591
2592 RpcTryExcept
2593 {
2594 ret = PNP_GetDeviceRegProp(BindingHandle,
2595 lpDevInst,
2596 ulProperty,
2597 &ulDataType,
2598 Buffer,
2599 &ulTransferLength,
2600 pulLength,
2601 ulFlags);
2602 }
2603 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2604 {
2605 ret = RpcStatusToCmStatus(RpcExceptionCode());
2606 }
2607 RpcEndExcept;
2608
2609 if (ret == CR_SUCCESS)
2610 {
2611 if (pulRegDataType != NULL)
2612 *pulRegDataType = ulDataType;
2613 }
2614
2615 return ret;
2616 }
2617
2618
2619 /***********************************************************************
2620 * CM_Get_DevNode_Status [SETUPAPI.@]
2621 */
2622 CONFIGRET WINAPI CM_Get_DevNode_Status(
2623 PULONG pulStatus, PULONG pulProblemNumber, DEVINST dnDevInst,
2624 ULONG ulFlags)
2625 {
2626 TRACE("%p %p %lx %lx\n",
2627 pulStatus, pulProblemNumber, dnDevInst, ulFlags);
2628 return CM_Get_DevNode_Status_Ex(pulStatus, pulProblemNumber, dnDevInst,
2629 ulFlags, NULL);
2630 }
2631
2632
2633 /***********************************************************************
2634 * CM_Get_DevNode_Status_Ex [SETUPAPI.@]
2635 */
2636 CONFIGRET WINAPI
2637 CM_Get_DevNode_Status_Ex(
2638 PULONG pulStatus, PULONG pulProblemNumber, DEVINST dnDevInst,
2639 ULONG ulFlags, HMACHINE hMachine)
2640 {
2641 RPC_BINDING_HANDLE BindingHandle = NULL;
2642 HSTRING_TABLE StringTable = NULL;
2643 LPWSTR lpDevInst;
2644 CONFIGRET ret;
2645
2646 TRACE("%p %p %lx %lx %lx\n",
2647 pulStatus, pulProblemNumber, dnDevInst, ulFlags, hMachine);
2648
2649 if (pulStatus == NULL || pulProblemNumber == NULL)
2650 return CR_INVALID_POINTER;
2651
2652 if (dnDevInst == 0)
2653 return CR_INVALID_DEVINST;
2654
2655 if (ulFlags != 0)
2656 return CR_INVALID_FLAG;
2657
2658 if (hMachine != NULL)
2659 {
2660 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2661 if (BindingHandle == NULL)
2662 return CR_FAILURE;
2663
2664 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2665 if (StringTable == 0)
2666 return CR_FAILURE;
2667 }
2668 else
2669 {
2670 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
2671 return CR_FAILURE;
2672 }
2673
2674 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
2675 if (lpDevInst == NULL)
2676 return CR_INVALID_DEVNODE;
2677
2678 RpcTryExcept
2679 {
2680 ret = PNP_GetDeviceStatus(BindingHandle,
2681 lpDevInst,
2682 pulStatus,
2683 pulProblemNumber,
2684 ulFlags);
2685 }
2686 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2687 {
2688 ret = RpcStatusToCmStatus(RpcExceptionCode());
2689 }
2690 RpcEndExcept;
2691
2692 return ret;
2693 }
2694
2695
2696 /***********************************************************************
2697 * CM_Get_Device_IDA [SETUPAPI.@]
2698 */
2699 CONFIGRET WINAPI CM_Get_Device_IDA(
2700 DEVINST dnDevInst, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
2701 {
2702 TRACE("%lx %p %ld %ld\n",
2703 dnDevInst, Buffer, BufferLen, ulFlags);
2704 return CM_Get_Device_ID_ExA(dnDevInst, Buffer, BufferLen, ulFlags, NULL);
2705 }
2706
2707
2708 /***********************************************************************
2709 * CM_Get_Device_IDW [SETUPAPI.@]
2710 */
2711 CONFIGRET WINAPI CM_Get_Device_IDW(
2712 DEVINST dnDevInst, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
2713 {
2714 TRACE("%lx %p %ld %ld\n",
2715 dnDevInst, Buffer, BufferLen, ulFlags);
2716 return CM_Get_Device_ID_ExW(dnDevInst, Buffer, BufferLen, ulFlags, NULL);
2717 }
2718
2719
2720 /***********************************************************************
2721 * CM_Get_Device_ID_ExA [SETUPAPI.@]
2722 */
2723 CONFIGRET WINAPI CM_Get_Device_ID_ExA(
2724 DEVINST dnDevInst, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
2725 HMACHINE hMachine)
2726 {
2727 WCHAR szBufferW[MAX_DEVICE_ID_LEN];
2728 CONFIGRET ret = CR_SUCCESS;
2729
2730 TRACE("%lx %p %ld %ld %lx\n",
2731 dnDevInst, Buffer, BufferLen, ulFlags, hMachine);
2732
2733 if (Buffer == NULL)
2734 return CR_INVALID_POINTER;
2735
2736 ret = CM_Get_Device_ID_ExW(dnDevInst,
2737 szBufferW,
2738 MAX_DEVICE_ID_LEN,
2739 ulFlags,
2740 hMachine);
2741 if (ret == CR_SUCCESS)
2742 {
2743 if (WideCharToMultiByte(CP_ACP,
2744 0,
2745 szBufferW,
2746 lstrlenW(szBufferW) + 1,
2747 Buffer,
2748 BufferLen,
2749 NULL,
2750 NULL) == 0)
2751 ret = CR_FAILURE;
2752 }
2753
2754 return ret;
2755 }
2756
2757
2758 /***********************************************************************
2759 * CM_Get_Device_ID_ExW [SETUPAPI.@]
2760 */
2761 CONFIGRET WINAPI CM_Get_Device_ID_ExW(
2762 DEVINST dnDevInst, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
2763 HMACHINE hMachine)
2764 {
2765 HSTRING_TABLE StringTable = NULL;
2766
2767 TRACE("%lx %p %ld %ld %lx\n",
2768 dnDevInst, Buffer, BufferLen, ulFlags, hMachine);
2769
2770 if (dnDevInst == 0)
2771 return CR_INVALID_DEVINST;
2772
2773 if (Buffer == NULL)
2774 return CR_INVALID_POINTER;
2775
2776 if (ulFlags != 0)
2777 return CR_INVALID_FLAG;
2778
2779 if (hMachine != NULL)
2780 {
2781 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
2782 if (StringTable == NULL)
2783 return CR_FAILURE;
2784 }
2785 else
2786 {
2787 if (!PnpGetLocalHandles(NULL, &StringTable))
2788 return CR_FAILURE;
2789 }
2790
2791 if (!pSetupStringTableStringFromIdEx(StringTable,
2792 dnDevInst,
2793 Buffer,
2794 &BufferLen))
2795 return CR_FAILURE;
2796
2797 return CR_SUCCESS;
2798 }
2799
2800
2801 /***********************************************************************
2802 * CM_Get_Device_ID_ListA [SETUPAPI.@]
2803 */
2804 CONFIGRET WINAPI CM_Get_Device_ID_ListA(
2805 PCSTR pszFilter, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
2806 {
2807 TRACE("%p %p %ld %ld\n", pszFilter, Buffer, BufferLen, ulFlags);
2808 return CM_Get_Device_ID_List_ExA(pszFilter, Buffer, BufferLen,
2809 ulFlags, NULL);
2810 }
2811
2812
2813 /***********************************************************************
2814 * CM_Get_Device_ID_ListW [SETUPAPI.@]
2815 */
2816 CONFIGRET WINAPI CM_Get_Device_ID_ListW(
2817 PCWSTR pszFilter, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags)
2818 {
2819 TRACE("%p %p %ld %ld\n", pszFilter, Buffer, BufferLen, ulFlags);
2820 return CM_Get_Device_ID_List_ExW(pszFilter, Buffer, BufferLen,
2821 ulFlags, NULL);
2822 }
2823
2824
2825 /***********************************************************************
2826 * CM_Get_Device_ID_List_ExA [SETUPAPI.@]
2827 */
2828 CONFIGRET WINAPI CM_Get_Device_ID_List_ExA(
2829 PCSTR pszFilter, PCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
2830 HMACHINE hMachine)
2831 {
2832 LPWSTR BufferW = NULL;
2833 LPWSTR pszFilterW = NULL;
2834 CONFIGRET ret = CR_SUCCESS;
2835
2836 TRACE("%p %p %ld %ld %lx\n",
2837 pszFilter, Buffer, BufferLen, ulFlags, hMachine);
2838
2839 BufferW = MyMalloc(BufferLen * sizeof(WCHAR));
2840 if (BufferW == NULL)
2841 return CR_OUT_OF_MEMORY;
2842
2843 if (pszFilter == NULL)
2844 {
2845 ret = CM_Get_Device_ID_List_ExW(NULL,
2846 BufferW,
2847 BufferLen,
2848 ulFlags,
2849 hMachine);
2850 }
2851 else
2852 {
2853 if (pSetupCaptureAndConvertAnsiArg(pszFilter, &pszFilterW))
2854 {
2855 ret = CR_INVALID_DEVICE_ID;
2856 goto Done;
2857 }
2858
2859 ret = CM_Get_Device_ID_List_ExW(pszFilterW,
2860 BufferW,
2861 BufferLen,
2862 ulFlags,
2863 hMachine);
2864
2865 MyFree(pszFilterW);
2866 }
2867
2868 if (WideCharToMultiByte(CP_ACP,
2869 0,
2870 BufferW,
2871 lstrlenW(BufferW) + 1,
2872 Buffer,
2873 BufferLen,
2874 NULL,
2875 NULL) == 0)
2876 ret = CR_FAILURE;
2877
2878 Done:
2879 MyFree(BufferW);
2880
2881 return ret;
2882 }
2883
2884
2885 /***********************************************************************
2886 * CM_Get_Device_ID_List_ExW [SETUPAPI.@]
2887 */
2888 CONFIGRET WINAPI CM_Get_Device_ID_List_ExW(
2889 PCWSTR pszFilter, PWCHAR Buffer, ULONG BufferLen, ULONG ulFlags,
2890 HMACHINE hMachine)
2891 {
2892 RPC_BINDING_HANDLE BindingHandle = NULL;
2893 CONFIGRET ret;
2894
2895 TRACE("%p %p %ld %ld %lx\n",
2896 pszFilter, Buffer, BufferLen, ulFlags, hMachine);
2897
2898 if (Buffer == NULL || BufferLen == 0)
2899 return CR_INVALID_POINTER;
2900
2901 if (ulFlags & ~CM_GETIDLIST_FILTER_BITS)
2902 return CR_INVALID_FLAG;
2903
2904 if (hMachine != NULL)
2905 {
2906 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
2907 if (BindingHandle == NULL)
2908 return CR_FAILURE;
2909 }
2910 else
2911 {
2912 if (!PnpGetLocalHandles(&BindingHandle, NULL))
2913 return CR_FAILURE;
2914 }
2915
2916 *Buffer = 0;
2917
2918 RpcTryExcept
2919 {
2920 ret = PNP_GetDeviceList(BindingHandle,
2921 (LPWSTR)pszFilter,
2922 Buffer,
2923 &BufferLen,
2924 ulFlags);
2925 }
2926 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
2927 {
2928 ret = RpcStatusToCmStatus(RpcExceptionCode());
2929 }
2930 RpcEndExcept;
2931
2932 return ret;
2933 }
2934
2935
2936 /***********************************************************************
2937 * CM_Get_Device_ID_List_SizeA [SETUPAPI.@]
2938 */
2939 CONFIGRET WINAPI CM_Get_Device_ID_List_SizeA(
2940 PULONG pulLen, PCSTR pszFilter, ULONG ulFlags)
2941 {
2942 TRACE("%p %s %ld\n", pulLen, pszFilter, ulFlags);
2943 return CM_Get_Device_ID_List_Size_ExA(pulLen, pszFilter, ulFlags, NULL);
2944 }
2945
2946
2947 /***********************************************************************
2948 * CM_Get_Device_ID_List_SizeW [SETUPAPI.@]
2949 */
2950 CONFIGRET WINAPI CM_Get_Device_ID_List_SizeW(
2951 PULONG pulLen, PCWSTR pszFilter, ULONG ulFlags)
2952 {
2953 TRACE("%p %s %ld\n", pulLen, debugstr_w(pszFilter), ulFlags);
2954 return CM_Get_Device_ID_List_Size_ExW(pulLen, pszFilter, ulFlags, NULL);
2955 }
2956
2957
2958 /***********************************************************************
2959 * CM_Get_Device_ID_List_Size_ExA [SETUPAPI.@]
2960 */
2961 CONFIGRET WINAPI CM_Get_Device_ID_List_Size_ExA(
2962 PULONG pulLen, PCSTR pszFilter, ULONG ulFlags, HMACHINE hMachine)
2963 {
2964 LPWSTR pszFilterW = NULL;
2965 CONFIGRET ret = CR_SUCCESS;
2966
2967 FIXME("%p %s %lx %lx\n", pulLen, pszFilter, ulFlags, hMachine);
2968
2969 if (pszFilter == NULL)
2970 {
2971 ret = CM_Get_Device_ID_List_Size_ExW(pulLen,
2972 NULL,
2973 ulFlags,
2974 hMachine);
2975 }
2976 else
2977 {
2978 if (pSetupCaptureAndConvertAnsiArg(pszFilter, &pszFilterW))
2979 return CR_INVALID_DEVICE_ID;
2980
2981 ret = CM_Get_Device_ID_List_Size_ExW(pulLen,
2982 pszFilterW,
2983 ulFlags,
2984 hMachine);
2985
2986 MyFree(pszFilterW);
2987 }
2988
2989 return ret;
2990 }
2991
2992
2993 /***********************************************************************
2994 * CM_Get_Device_ID_List_Size_ExW [SETUPAPI.@]
2995 */
2996 CONFIGRET WINAPI CM_Get_Device_ID_List_Size_ExW(
2997 PULONG pulLen, PCWSTR pszFilter, ULONG ulFlags, HMACHINE hMachine)
2998 {
2999 RPC_BINDING_HANDLE BindingHandle = NULL;
3000 CONFIGRET ret;
3001
3002 FIXME("%p %s %ld %lx\n", pulLen, debugstr_w(pszFilter), ulFlags, hMachine);
3003
3004 if (pulLen == NULL)
3005 return CR_INVALID_POINTER;
3006
3007 if (ulFlags & ~CM_GETIDLIST_FILTER_BITS)
3008 return CR_INVALID_FLAG;
3009
3010 if (hMachine != NULL)
3011 {
3012 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3013 if (BindingHandle == NULL)
3014 return CR_FAILURE;
3015 }
3016 else
3017 {
3018 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3019 return CR_FAILURE;
3020 }
3021
3022 *pulLen = 0;
3023
3024 RpcTryExcept
3025 {
3026 ret = PNP_GetDeviceListSize(BindingHandle,
3027 (LPWSTR)pszFilter,
3028 pulLen,
3029 ulFlags);
3030 }
3031 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3032 {
3033 ret = RpcStatusToCmStatus(RpcExceptionCode());
3034 }
3035 RpcEndExcept;
3036
3037 return ret;
3038 }
3039
3040
3041 /***********************************************************************
3042 * CM_Get_Device_ID_Size [SETUPAPI.@]
3043 */
3044 CONFIGRET WINAPI CM_Get_Device_ID_Size(
3045 PULONG pulLen, DEVINST dnDevInst, ULONG ulFlags)
3046 {
3047 TRACE("%p %lx %lx\n", pulLen, dnDevInst, ulFlags);
3048 return CM_Get_Device_ID_Size_Ex(pulLen, dnDevInst, ulFlags, NULL);
3049 }
3050
3051
3052 /***********************************************************************
3053 * CM_Get_Device_ID_Size_Ex [SETUPAPI.@]
3054 */
3055 CONFIGRET WINAPI CM_Get_Device_ID_Size_Ex(
3056 PULONG pulLen, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
3057 {
3058 HSTRING_TABLE StringTable = NULL;
3059 LPWSTR DeviceId;
3060
3061 TRACE("%p %lx %lx %lx\n", pulLen, dnDevInst, ulFlags, hMachine);
3062
3063 if (pulLen == NULL)
3064 return CR_INVALID_POINTER;
3065
3066 if (dnDevInst == 0)
3067 return CR_INVALID_DEVINST;
3068
3069 if (ulFlags != 0)
3070 return CR_INVALID_FLAG;
3071
3072 if (hMachine != NULL)
3073 {
3074 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3075 if (StringTable == NULL)
3076 return CR_FAILURE;
3077 }
3078 else
3079 {
3080 if (!PnpGetLocalHandles(NULL, &StringTable))
3081 return CR_FAILURE;
3082 }
3083
3084 DeviceId = pSetupStringTableStringFromId(StringTable, dnDevInst);
3085 if (DeviceId == NULL)
3086 {
3087 *pulLen = 0;
3088 return CR_SUCCESS;
3089 }
3090
3091 *pulLen = lstrlenW(DeviceId);
3092
3093 return CR_SUCCESS;
3094 }
3095
3096
3097 /***********************************************************************
3098 * CM_Get_Device_Interface_AliasA [SETUPAPI.@]
3099 */
3100 CONFIGRET WINAPI CM_Get_Device_Interface_AliasA(
3101 LPCSTR pszDeviceInterface, LPGUID AliasInterfaceGuid,
3102 LPSTR pszAliasDeviceInterface, PULONG pulLength, ULONG ulFlags)
3103 {
3104 TRACE("%p %p %p %p %lu\n", pszDeviceInterface, AliasInterfaceGuid,
3105 pszAliasDeviceInterface, pulLength, ulFlags);
3106
3107 return CM_Get_Device_Interface_Alias_ExA(pszDeviceInterface,
3108 AliasInterfaceGuid, pszAliasDeviceInterface, pulLength,
3109 ulFlags, NULL);
3110 }
3111
3112
3113 /***********************************************************************
3114 * CM_Get_Device_Interface_AliasW [SETUPAPI.@]
3115 */
3116 CONFIGRET WINAPI CM_Get_Device_Interface_AliasW(
3117 LPCWSTR pszDeviceInterface, LPGUID AliasInterfaceGuid,
3118 LPWSTR pszAliasDeviceInterface, PULONG pulLength, ULONG ulFlags)
3119 {
3120 TRACE("%p %p %p %p %lu\n", pszDeviceInterface, AliasInterfaceGuid,
3121 pszAliasDeviceInterface, pulLength, ulFlags);
3122
3123 return CM_Get_Device_Interface_Alias_ExW(pszDeviceInterface,
3124 AliasInterfaceGuid, pszAliasDeviceInterface, pulLength,
3125 ulFlags, NULL);
3126 }
3127
3128
3129 /***********************************************************************
3130 * CM_Get_Device_Interface_Alias_ExA [SETUPAPI.@]
3131 */
3132 CONFIGRET WINAPI CM_Get_Device_Interface_Alias_ExA(
3133 LPCSTR pszDeviceInterface, LPGUID AliasInterfaceGuid, LPSTR pszAliasDeviceInterface,
3134 PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
3135 {
3136 FIXME("%p %p %p %p %lu %lx\n", pszDeviceInterface, AliasInterfaceGuid,
3137 pszAliasDeviceInterface, pulLength, ulFlags, hMachine);
3138
3139 return CR_CALL_NOT_IMPLEMENTED;
3140 }
3141
3142
3143 /***********************************************************************
3144 * CM_Get_Device_Interface_Alias_ExW [SETUPAPI.@]
3145 */
3146 CONFIGRET WINAPI CM_Get_Device_Interface_Alias_ExW(
3147 LPCWSTR pszDeviceInterface, LPGUID AliasInterfaceGuid, LPWSTR pszAliasDeviceInterface,
3148 PULONG pulLength, ULONG ulFlags, HMACHINE hMachine)
3149 {
3150 RPC_BINDING_HANDLE BindingHandle = NULL;
3151 ULONG ulTransferLength;
3152 CONFIGRET ret = CR_SUCCESS;
3153
3154 TRACE("%p %p %p %p %lu %lx\n", pszDeviceInterface, AliasInterfaceGuid,
3155 pszAliasDeviceInterface, pulLength, ulFlags, hMachine);
3156
3157 if (pszDeviceInterface == NULL ||
3158 AliasInterfaceGuid == NULL ||
3159 pszAliasDeviceInterface == NULL ||
3160 pulLength == NULL)
3161 return CR_INVALID_POINTER;
3162
3163 if (ulFlags != 0)
3164 return CR_INVALID_FLAG;
3165
3166 if (hMachine != NULL)
3167 {
3168 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3169 if (BindingHandle == NULL)
3170 return CR_FAILURE;
3171 }
3172 else
3173 {
3174 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3175 return CR_FAILURE;
3176 }
3177
3178 ulTransferLength = *pulLength;
3179
3180 RpcTryExcept
3181 {
3182 ret = PNP_GetInterfaceDeviceAlias(BindingHandle,
3183 (LPWSTR)pszDeviceInterface,
3184 AliasInterfaceGuid,
3185 pszAliasDeviceInterface,
3186 pulLength,
3187 &ulTransferLength,
3188 0);
3189 }
3190 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3191 {
3192 ret = RpcStatusToCmStatus(RpcExceptionCode());
3193 }
3194 RpcEndExcept;
3195
3196 return ret;
3197 }
3198
3199
3200 /***********************************************************************
3201 * CM_Get_Device_Interface_ListA (SETUPAPI.@)
3202 */
3203 CONFIGRET WINAPI CM_Get_Device_Interface_ListA(
3204 LPGUID InterfaceClassGuid, DEVINSTID_A pDeviceID, PCHAR Buffer,
3205 ULONG BufferLen, ULONG ulFlags)
3206 {
3207 TRACE("%s %s %p %lu 0x%08lx\n", debugstr_guid(InterfaceClassGuid),
3208 pDeviceID, Buffer, BufferLen, ulFlags);
3209
3210 return CM_Get_Device_Interface_List_ExA(InterfaceClassGuid, pDeviceID,
3211 Buffer, BufferLen, ulFlags, NULL);
3212 }
3213
3214
3215 /***********************************************************************
3216 * CM_Get_Device_Interface_ListW (SETUPAPI.@)
3217 */
3218 CONFIGRET WINAPI CM_Get_Device_Interface_ListW(
3219 LPGUID InterfaceClassGuid, DEVINSTID_W pDeviceID, PWCHAR Buffer,
3220 ULONG BufferLen, ULONG ulFlags)
3221 {
3222 TRACE("%s %s %p %lu 0x%08lx\n", debugstr_guid(InterfaceClassGuid),
3223 debugstr_w(pDeviceID), Buffer, BufferLen, ulFlags);
3224
3225 return CM_Get_Device_Interface_List_ExW(InterfaceClassGuid, pDeviceID,
3226 Buffer, BufferLen, ulFlags, NULL);
3227 }
3228
3229
3230 /***********************************************************************
3231 * CM_Get_Device_Interface_List_ExA (SETUPAPI.@)
3232 */
3233 CONFIGRET WINAPI CM_Get_Device_Interface_List_ExA(
3234 LPGUID InterfaceClassGuid, DEVINSTID_A pDeviceID, PCHAR Buffer,
3235 ULONG BufferLen, ULONG ulFlags, HMACHINE hMachine)
3236 {
3237 DEVINSTID_W pDeviceIdW = NULL;
3238 PWCHAR BufferW = NULL;
3239 CONFIGRET ret = CR_SUCCESS;
3240
3241 TRACE("%s %s %p %lu 0x%08lx %p\n", debugstr_guid(InterfaceClassGuid),
3242 pDeviceID, Buffer, BufferLen, ulFlags, hMachine);
3243
3244 if (Buffer == NULL ||
3245 BufferLen == 0)
3246 return CR_INVALID_POINTER;
3247
3248 if (pDeviceID != NULL)
3249 {
3250 if (!pSetupCaptureAndConvertAnsiArg(pDeviceID, &pDeviceIdW))
3251 return CR_INVALID_DEVICE_ID;
3252 }
3253
3254 BufferW = MyMalloc(BufferLen * sizeof(WCHAR));
3255 if (BufferW == NULL)
3256 {
3257 ret = CR_OUT_OF_MEMORY;
3258 goto Done;
3259 }
3260
3261 ret = CM_Get_Device_Interface_List_ExW(InterfaceClassGuid, pDeviceIdW,
3262 BufferW, BufferLen, ulFlags,
3263 hMachine);
3264 if (ret != CR_SUCCESS)
3265 goto Done;
3266
3267 if (WideCharToMultiByte(CP_ACP,
3268 0,
3269 BufferW,
3270 lstrlenW(BufferW) + 1,
3271 Buffer,
3272 BufferLen,
3273 NULL,
3274 NULL) == 0)
3275 ret = CR_FAILURE;
3276
3277 Done:
3278 if (BufferW != NULL)
3279 MyFree(BufferW);
3280
3281 if (pDeviceIdW != NULL)
3282 MyFree(pDeviceIdW);
3283
3284 return ret;
3285 }
3286
3287
3288 /***********************************************************************
3289 * CM_Get_Device_Interface_List_ExW (SETUPAPI.@)
3290 */
3291 CONFIGRET WINAPI CM_Get_Device_Interface_List_ExW(
3292 LPGUID InterfaceClassGuid, DEVINSTID_W pDeviceID, PWCHAR Buffer,
3293 ULONG BufferLen, ULONG ulFlags, HMACHINE hMachine)
3294 {
3295 RPC_BINDING_HANDLE BindingHandle = NULL;
3296 PNP_RPC_BUFFER_SIZE BufferSize = 0;
3297 CONFIGRET ret = CR_SUCCESS;
3298
3299 TRACE("%s %s %p %lu 0x%08lx %p\n", debugstr_guid(InterfaceClassGuid),
3300 debugstr_w(pDeviceID), Buffer, BufferLen, ulFlags, hMachine);
3301
3302 if (Buffer == NULL ||
3303 BufferLen == 0)
3304 return CR_INVALID_POINTER;
3305
3306 if (ulFlags & ~CM_GET_DEVICE_INTERFACE_LIST_BITS)
3307 return CR_INVALID_FLAG;
3308
3309 if (hMachine != NULL)
3310 {
3311 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3312 if (BindingHandle == NULL)
3313 return CR_FAILURE;
3314 }
3315 else
3316 {
3317 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3318 return CR_FAILURE;
3319 }
3320
3321 *Buffer = 0;
3322 BufferSize = BufferLen;
3323
3324 RpcTryExcept
3325 {
3326 ret = PNP_GetInterfaceDeviceList(BindingHandle,
3327 InterfaceClassGuid,
3328 pDeviceID,
3329 (LPBYTE)Buffer,
3330 &BufferSize,
3331 ulFlags);
3332 }
3333 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3334 {
3335 ret = RpcStatusToCmStatus(RpcExceptionCode());
3336 }
3337 RpcEndExcept;
3338
3339 return ret;
3340 }
3341
3342
3343 /***********************************************************************
3344 * CM_Get_Device_Interface_List_SizeA (SETUPAPI.@)
3345 */
3346 CONFIGRET WINAPI CM_Get_Device_Interface_List_SizeA(
3347 PULONG pulLen, LPGUID InterfaceClassGuid, DEVINSTID_A pDeviceId,
3348 ULONG ulFlags)
3349 {
3350 TRACE("%p %p %s 0x%08lx\n", pulLen, InterfaceClassGuid,
3351 pDeviceId, ulFlags);
3352
3353 return CM_Get_Device_Interface_List_Size_ExA(pulLen, InterfaceClassGuid,
3354 pDeviceId, ulFlags, NULL);
3355 }
3356
3357
3358 /***********************************************************************
3359 * CM_Get_Device_Interface_List_SizeW (SETUPAPI.@)
3360 */
3361 CONFIGRET WINAPI CM_Get_Device_Interface_List_SizeW(
3362 PULONG pulLen, LPGUID InterfaceClassGuid, DEVINSTID_W pDeviceId,
3363 ULONG ulFlags)
3364 {
3365 TRACE("%p %p %s 0x%08lx\n", pulLen, InterfaceClassGuid,
3366 debugstr_w(pDeviceId), ulFlags);
3367
3368 return CM_Get_Device_Interface_List_Size_ExW(pulLen, InterfaceClassGuid,
3369 pDeviceId, ulFlags, NULL);
3370 }
3371
3372
3373 /***********************************************************************
3374 * CM_Get_Device_Interface_List_Size_ExA (SETUPAPI.@)
3375 */
3376 CONFIGRET WINAPI CM_Get_Device_Interface_List_Size_ExA(
3377 PULONG pulLen, LPGUID InterfaceClassGuid, DEVINSTID_A pDeviceId,
3378 ULONG ulFlags, HMACHINE hMachine)
3379 {
3380 DEVINSTID_W pDeviceIdW = NULL;
3381 CONFIGRET ret = CR_SUCCESS;
3382
3383 TRACE("%p %p %s 0x%08lx %p\n", pulLen, InterfaceClassGuid,
3384 pDeviceId, ulFlags, hMachine);
3385
3386 if (pulLen == NULL)
3387 return CR_INVALID_POINTER;
3388
3389 if (pDeviceId != NULL)
3390 {
3391 if (!pSetupCaptureAndConvertAnsiArg(pDeviceId, &pDeviceIdW))
3392 return CR_INVALID_DEVICE_ID;
3393 }
3394
3395 *pulLen = 0;
3396
3397 ret = CM_Get_Device_Interface_List_Size_ExW(pulLen, InterfaceClassGuid,
3398 pDeviceIdW, ulFlags, hMachine);
3399
3400 if (pDeviceIdW != NULL)
3401 MyFree(pDeviceIdW);
3402
3403 return ret;
3404 }
3405
3406
3407 /***********************************************************************
3408 * CM_Get_Device_Interface_List_Size_ExW (SETUPAPI.@)
3409 */
3410 CONFIGRET WINAPI CM_Get_Device_Interface_List_Size_ExW(
3411 PULONG pulLen, LPGUID InterfaceClassGuid, DEVINSTID_W pDeviceId,
3412 ULONG ulFlags, HMACHINE hMachine)
3413 {
3414 RPC_BINDING_HANDLE BindingHandle = NULL;
3415 CONFIGRET ret = CR_SUCCESS;
3416
3417 TRACE("%p %p %s 0x%08lx %p\n", pulLen, InterfaceClassGuid,
3418 debugstr_w(pDeviceId), ulFlags, hMachine);
3419
3420 if (pulLen == NULL)
3421 return CR_INVALID_POINTER;
3422
3423 if (ulFlags & ~CM_GET_DEVICE_INTERFACE_LIST_BITS)
3424 return CR_INVALID_FLAG;
3425
3426 if (hMachine != NULL)
3427 {
3428 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3429 if (BindingHandle == NULL)
3430 return CR_FAILURE;
3431 }
3432 else
3433 {
3434 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3435 return CR_FAILURE;
3436 }
3437
3438 *pulLen = 0;
3439
3440 RpcTryExcept
3441 {
3442 ret = PNP_GetInterfaceDeviceListSize(BindingHandle,
3443 pulLen,
3444 InterfaceClassGuid,
3445 pDeviceId,
3446 ulFlags);
3447 }
3448 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3449 {
3450 ret = RpcStatusToCmStatus(RpcExceptionCode());
3451 }
3452 RpcEndExcept;
3453
3454 return ret;
3455 }
3456
3457
3458 /***********************************************************************
3459 * CM_Get_First_Log_Conf [SETUPAPI.@]
3460 */
3461 CONFIGRET WINAPI CM_Get_First_Log_Conf(
3462 PLOG_CONF plcLogConf, DEVINST dnDevInst, ULONG ulFlags)
3463 {
3464 TRACE("%p %lx %lx\n", plcLogConf, dnDevInst, ulFlags);
3465 return CM_Get_First_Log_Conf_Ex(plcLogConf, dnDevInst, ulFlags, NULL);
3466 }
3467
3468
3469 /***********************************************************************
3470 * CM_Get_First_Log_Conf_Ex [SETUPAPI.@]
3471 */
3472 CONFIGRET WINAPI CM_Get_First_Log_Conf_Ex(
3473 PLOG_CONF plcLogConf, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
3474 {
3475 RPC_BINDING_HANDLE BindingHandle = NULL;
3476 HSTRING_TABLE StringTable = NULL;
3477 LPWSTR lpDevInst = NULL;
3478 CONFIGRET ret = CR_SUCCESS;
3479 ULONG ulTag;
3480 PLOG_CONF_INFO pLogConfInfo;
3481
3482 FIXME("%p %lx %lx %lx\n", plcLogConf, dnDevInst, ulFlags, hMachine);
3483
3484 if (dnDevInst == 0)
3485 return CR_INVALID_DEVINST;
3486
3487 if (ulFlags & ~LOG_CONF_BITS)
3488 return CR_INVALID_FLAG;
3489
3490 if (plcLogConf)
3491 *plcLogConf = 0;
3492
3493 if (hMachine != NULL)
3494 {
3495 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3496 if (BindingHandle == NULL)
3497 return CR_FAILURE;
3498
3499 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3500 if (StringTable == 0)
3501 return CR_FAILURE;
3502 }
3503 else
3504 {
3505 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
3506 return CR_FAILURE;
3507 }
3508
3509 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
3510 if (lpDevInst == NULL)
3511 return CR_INVALID_DEVNODE;
3512
3513 RpcTryExcept
3514 {
3515 ret = PNP_GetFirstLogConf(BindingHandle,
3516 lpDevInst,
3517 ulFlags,
3518 &ulTag,
3519 ulFlags);
3520 }
3521 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3522 {
3523 ret = RpcStatusToCmStatus(RpcExceptionCode());
3524 }
3525 RpcEndExcept;
3526
3527 if (ret != CR_SUCCESS)
3528 return ret;
3529
3530 if (plcLogConf)
3531 {
3532 pLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO));
3533 if (pLogConfInfo == NULL)
3534 return CR_OUT_OF_MEMORY;
3535
3536 pLogConfInfo->ulMagic = LOG_CONF_MAGIC;
3537 pLogConfInfo->dnDevInst = dnDevInst;
3538 pLogConfInfo->ulFlags = ulFlags;
3539 pLogConfInfo->ulTag = ulTag;
3540
3541 *plcLogConf = (LOG_CONF)pLogConfInfo;
3542 }
3543
3544 return CR_SUCCESS;
3545 }
3546
3547
3548 /***********************************************************************
3549 * CM_Get_Global_State [SETUPAPI.@]
3550 */
3551 CONFIGRET WINAPI CM_Get_Global_State(
3552 PULONG pulState, ULONG ulFlags)
3553 {
3554 TRACE("%p %lx\n", pulState, ulFlags);
3555 return CM_Get_Global_State_Ex(pulState, ulFlags, NULL);
3556 }
3557
3558
3559 /***********************************************************************
3560 * CM_Get_Global_State_Ex [SETUPAPI.@]
3561 */
3562 CONFIGRET WINAPI CM_Get_Global_State_Ex(
3563 PULONG pulState, ULONG ulFlags, HMACHINE hMachine)
3564 {
3565 RPC_BINDING_HANDLE BindingHandle = NULL;
3566 CONFIGRET ret;
3567
3568 TRACE("%p %lx %lx\n", pulState, ulFlags, hMachine);
3569
3570 if (pulState == NULL)
3571 return CR_INVALID_POINTER;
3572
3573 if (ulFlags != 0)
3574 return CR_INVALID_FLAG;
3575
3576 if (hMachine != NULL)
3577 {
3578 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3579 if (BindingHandle == NULL)
3580 return CR_FAILURE;
3581 }
3582 else
3583 {
3584 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3585 return CR_FAILURE;
3586 }
3587
3588 RpcTryExcept
3589 {
3590 ret = PNP_GetGlobalState(BindingHandle, pulState, ulFlags);
3591 }
3592 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3593 {
3594 ret = RpcStatusToCmStatus(RpcExceptionCode());
3595 }
3596 RpcEndExcept;
3597
3598 return ret;
3599 }
3600
3601
3602 /***********************************************************************
3603 * CM_Get_HW_Prof_FlagsA [SETUPAPI.@]
3604 */
3605 CONFIGRET WINAPI CM_Get_HW_Prof_FlagsA(
3606 DEVINSTID_A szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
3607 ULONG ulFlags)
3608 {
3609 TRACE("%s %lu %p %lx\n", szDevInstName,
3610 ulHardwareProfile, pulValue, ulFlags);
3611
3612 return CM_Get_HW_Prof_Flags_ExA(szDevInstName, ulHardwareProfile,
3613 pulValue, ulFlags, NULL);
3614 }
3615
3616
3617 /***********************************************************************
3618 * CM_Get_HW_Prof_FlagsW [SETUPAPI.@]
3619 */
3620 CONFIGRET WINAPI CM_Get_HW_Prof_FlagsW(
3621 DEVINSTID_W szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
3622 ULONG ulFlags)
3623 {
3624 TRACE("%s %lu %p %lx\n", debugstr_w(szDevInstName),
3625 ulHardwareProfile, pulValue, ulFlags);
3626
3627 return CM_Get_HW_Prof_Flags_ExW(szDevInstName, ulHardwareProfile,
3628 pulValue, ulFlags, NULL);
3629 }
3630
3631
3632 /***********************************************************************
3633 * CM_Get_HW_Prof_Flags_ExA [SETUPAPI.@]
3634 */
3635 CONFIGRET WINAPI CM_Get_HW_Prof_Flags_ExA(
3636 DEVINSTID_A szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
3637 ULONG ulFlags, HMACHINE hMachine)
3638 {
3639 DEVINSTID_W pszDevIdW = NULL;
3640 CONFIGRET ret = CR_SUCCESS;
3641
3642 TRACE("%s %lu %p %lx %lx\n", szDevInstName,
3643 ulHardwareProfile, pulValue, ulFlags, hMachine);
3644
3645 if (szDevInstName != NULL)
3646 {
3647 if (pSetupCaptureAndConvertAnsiArg(szDevInstName, &pszDevIdW))
3648 return CR_INVALID_DEVICE_ID;
3649 }
3650
3651 ret = CM_Get_HW_Prof_Flags_ExW(pszDevIdW, ulHardwareProfile,
3652 pulValue, ulFlags, hMachine);
3653
3654 if (pszDevIdW != NULL)
3655 MyFree(pszDevIdW);
3656
3657 return ret;
3658 }
3659
3660
3661 /***********************************************************************
3662 * CM_Get_HW_Prof_Flags_ExW [SETUPAPI.@]
3663 */
3664 CONFIGRET WINAPI CM_Get_HW_Prof_Flags_ExW(
3665 DEVINSTID_W szDevInstName, ULONG ulHardwareProfile, PULONG pulValue,
3666 ULONG ulFlags, HMACHINE hMachine)
3667 {
3668 RPC_BINDING_HANDLE BindingHandle = NULL;
3669 CONFIGRET ret;
3670
3671 FIXME("%s %lu %p %lx %lx\n", debugstr_w(szDevInstName),
3672 ulHardwareProfile, pulValue, ulFlags, hMachine);
3673
3674 if ((szDevInstName == NULL) || (pulValue == NULL))
3675 return CR_INVALID_POINTER;
3676
3677 if (ulFlags != 0)
3678 return CR_INVALID_FLAG;
3679
3680 /* FIXME: Check whether szDevInstName is valid */
3681
3682 if (hMachine != NULL)
3683 {
3684 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3685 if (BindingHandle == NULL)
3686 return CR_FAILURE;
3687 }
3688 else
3689 {
3690 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3691 return CR_FAILURE;
3692 }
3693
3694 RpcTryExcept
3695 {
3696 ret = PNP_HwProfFlags(BindingHandle, PNP_GET_HWPROFFLAGS, szDevInstName,
3697 ulHardwareProfile, pulValue, NULL, NULL, 0, 0);
3698 }
3699 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3700 {
3701 ret = RpcStatusToCmStatus(RpcExceptionCode());
3702 }
3703 RpcEndExcept;
3704
3705 return ret;
3706 }
3707
3708
3709 /***********************************************************************
3710 * CM_Get_Hardware_Profile_InfoA [SETUPAPI.@]
3711 */
3712 CONFIGRET WINAPI CM_Get_Hardware_Profile_InfoA(
3713 ULONG ulIndex, PHWPROFILEINFO_A pHWProfileInfo, ULONG ulFlags)
3714 {
3715 TRACE("%lu %p %lx\n", ulIndex, pHWProfileInfo, ulFlags);
3716
3717 return CM_Get_Hardware_Profile_Info_ExA(ulIndex, pHWProfileInfo,
3718 ulFlags, NULL);
3719 }
3720
3721
3722 /***********************************************************************
3723 * CM_Get_Hardware_Profile_InfoW [SETUPAPI.@]
3724 */
3725 CONFIGRET WINAPI CM_Get_Hardware_Profile_InfoW(
3726 ULONG ulIndex, PHWPROFILEINFO_W pHWProfileInfo, ULONG ulFlags)
3727 {
3728 TRACE("%lu %p %lx\n", ulIndex, pHWProfileInfo, ulFlags);
3729
3730 return CM_Get_Hardware_Profile_Info_ExW(ulIndex, pHWProfileInfo,
3731 ulFlags, NULL);
3732 }
3733
3734
3735 /***********************************************************************
3736 * CM_Get_Hardware_Profile_Info_ExA [SETUPAPI.@]
3737 */
3738 CONFIGRET WINAPI CM_Get_Hardware_Profile_Info_ExA(
3739 ULONG ulIndex, PHWPROFILEINFO_A pHWProfileInfo, ULONG ulFlags,
3740 HMACHINE hMachine)
3741 {
3742 HWPROFILEINFO_W LocalProfileInfo;
3743 CONFIGRET ret;
3744
3745 TRACE("%lu %p %lx %lx\n", ulIndex, pHWProfileInfo, ulFlags, hMachine);
3746
3747 if (pHWProfileInfo == NULL)
3748 return CR_INVALID_POINTER;
3749
3750 ret = CM_Get_Hardware_Profile_Info_ExW(ulIndex, &LocalProfileInfo,
3751 ulFlags, hMachine);
3752 if (ret == CR_SUCCESS)
3753 {
3754 pHWProfileInfo->HWPI_ulHWProfile = LocalProfileInfo.HWPI_ulHWProfile;
3755 pHWProfileInfo->HWPI_dwFlags = LocalProfileInfo.HWPI_dwFlags;
3756
3757 if (WideCharToMultiByte(CP_ACP,
3758 0,
3759 LocalProfileInfo.HWPI_szFriendlyName,
3760 lstrlenW(LocalProfileInfo.HWPI_szFriendlyName) + 1,
3761 pHWProfileInfo->HWPI_szFriendlyName,
3762 MAX_PROFILE_LEN,
3763 NULL,
3764 NULL) == 0)
3765 ret = CR_FAILURE;
3766 }
3767
3768 return ret;
3769 }
3770
3771
3772 /***********************************************************************
3773 * CM_Get_Hardware_Profile_Info_ExW [SETUPAPI.@]
3774 */
3775 CONFIGRET WINAPI CM_Get_Hardware_Profile_Info_ExW(
3776 ULONG ulIndex, PHWPROFILEINFO_W pHWProfileInfo, ULONG ulFlags,
3777 HMACHINE hMachine)
3778 {
3779 RPC_BINDING_HANDLE BindingHandle = NULL;
3780 CONFIGRET ret;
3781
3782 TRACE("%lu %p %lx %lx\n", ulIndex, pHWProfileInfo, ulFlags, hMachine);
3783
3784 if (pHWProfileInfo == NULL)
3785 return CR_INVALID_POINTER;
3786
3787 if (ulFlags != 0)
3788 return CR_INVALID_FLAG;
3789
3790 if (hMachine != NULL)
3791 {
3792 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3793 if (BindingHandle == NULL)
3794 return CR_FAILURE;
3795 }
3796 else
3797 {
3798 if (!PnpGetLocalHandles(&BindingHandle, NULL))
3799 return CR_FAILURE;
3800 }
3801
3802 RpcTryExcept
3803 {
3804 ret = PNP_GetHwProfInfo(BindingHandle, ulIndex, pHWProfileInfo,
3805 sizeof(HWPROFILEINFO_W), 0);
3806 }
3807 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3808 {
3809 ret = RpcStatusToCmStatus(RpcExceptionCode());
3810 }
3811 RpcEndExcept;
3812
3813 return ret;
3814 }
3815
3816
3817 /***********************************************************************
3818 * CM_Get_Log_Conf_Priority [SETUPAPI.@]
3819 */
3820 CONFIGRET WINAPI CM_Get_Log_Conf_Priority(
3821 LOG_CONF lcLogConf, PPRIORITY pPriority, ULONG ulFlags)
3822 {
3823 TRACE("%p %p %lx\n", lcLogConf, pPriority, ulFlags);
3824 return CM_Get_Log_Conf_Priority_Ex(lcLogConf, pPriority, ulFlags, NULL);
3825 }
3826
3827
3828 /***********************************************************************
3829 * CM_Get_Log_Conf_Priority_Ex [SETUPAPI.@]
3830 */
3831 CONFIGRET WINAPI CM_Get_Log_Conf_Priority_Ex(
3832 LOG_CONF lcLogConf, PPRIORITY pPriority, ULONG ulFlags,
3833 HMACHINE hMachine)
3834 {
3835 RPC_BINDING_HANDLE BindingHandle = NULL;
3836 HSTRING_TABLE StringTable = NULL;
3837 PLOG_CONF_INFO pLogConfInfo;
3838 LPWSTR lpDevInst;
3839 CONFIGRET ret;
3840
3841 FIXME("%p %p %lx %lx\n", lcLogConf, pPriority, ulFlags, hMachine);
3842
3843 pLogConfInfo = (PLOG_CONF_INFO)lcLogConf;
3844 if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
3845 return CR_INVALID_LOG_CONF;
3846
3847 if (pPriority == NULL)
3848 return CR_INVALID_POINTER;
3849
3850 if (ulFlags != 0)
3851 return CR_INVALID_FLAG;
3852
3853 if (hMachine != NULL)
3854 {
3855 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3856 if (BindingHandle == NULL)
3857 return CR_FAILURE;
3858
3859 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3860 if (StringTable == 0)
3861 return CR_FAILURE;
3862 }
3863 else
3864 {
3865 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
3866 return CR_FAILURE;
3867 }
3868
3869 lpDevInst = pSetupStringTableStringFromId(StringTable, pLogConfInfo->dnDevInst);
3870 if (lpDevInst == NULL)
3871 return CR_INVALID_DEVNODE;
3872
3873 RpcTryExcept
3874 {
3875 ret = PNP_GetLogConfPriority(BindingHandle,
3876 lpDevInst,
3877 pLogConfInfo->ulFlags,
3878 pLogConfInfo->ulTag,
3879 pPriority,
3880 0);
3881 }
3882 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3883 {
3884 ret = RpcStatusToCmStatus(RpcExceptionCode());
3885 }
3886 RpcEndExcept;
3887
3888 return ret;
3889 }
3890
3891
3892 /***********************************************************************
3893 * CM_Get_Next_Log_Conf [SETUPAPI.@]
3894 */
3895 CONFIGRET WINAPI CM_Get_Next_Log_Conf(
3896 PLOG_CONF plcLogConf, LOG_CONF lcLogConf, ULONG ulFlags)
3897 {
3898 TRACE("%p %p %lx\n", plcLogConf, lcLogConf, ulFlags);
3899 return CM_Get_Next_Log_Conf_Ex(plcLogConf, lcLogConf, ulFlags, NULL);
3900 }
3901
3902
3903 /***********************************************************************
3904 * CM_Get_Next_Log_Conf_Ex [SETUPAPI.@]
3905 */
3906 CONFIGRET WINAPI CM_Get_Next_Log_Conf_Ex(
3907 PLOG_CONF plcLogConf, LOG_CONF lcLogConf, ULONG ulFlags,
3908 HMACHINE hMachine)
3909 {
3910 RPC_BINDING_HANDLE BindingHandle = NULL;
3911 HSTRING_TABLE StringTable = NULL;
3912 PLOG_CONF_INFO pLogConfInfo;
3913 PLOG_CONF_INFO pNewLogConfInfo;
3914 ULONG ulNewTag;
3915 LPWSTR lpDevInst;
3916 CONFIGRET ret;
3917
3918 FIXME("%p %p %lx %lx\n", plcLogConf, lcLogConf, ulFlags, hMachine);
3919
3920 if (plcLogConf)
3921 *plcLogConf = 0;
3922
3923 pLogConfInfo = (PLOG_CONF_INFO)lcLogConf;
3924 if (pLogConfInfo == NULL || pLogConfInfo->ulMagic != LOG_CONF_MAGIC)
3925 return CR_INVALID_LOG_CONF;
3926
3927 if (ulFlags != 0)
3928 return CR_INVALID_FLAG;
3929
3930 if (hMachine != NULL)
3931 {
3932 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
3933 if (BindingHandle == NULL)
3934 return CR_FAILURE;
3935
3936 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
3937 if (StringTable == 0)
3938 return CR_FAILURE;
3939 }
3940 else
3941 {
3942 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
3943 return CR_FAILURE;
3944 }
3945
3946 lpDevInst = pSetupStringTableStringFromId(StringTable, pLogConfInfo->dnDevInst);
3947 if (lpDevInst == NULL)
3948 return CR_INVALID_DEVNODE;
3949
3950 RpcTryExcept
3951 {
3952 ret = PNP_GetNextLogConf(BindingHandle,
3953 lpDevInst,
3954 pLogConfInfo->ulFlags,
3955 pLogConfInfo->ulTag,
3956 &ulNewTag,
3957 0);
3958 }
3959 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
3960 {
3961 ret = RpcStatusToCmStatus(RpcExceptionCode());
3962 }
3963 RpcEndExcept;
3964
3965 if (ret != CR_SUCCESS)
3966 return ret;
3967
3968 if (plcLogConf)
3969 {
3970 pNewLogConfInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(LOG_CONF_INFO));
3971 if (pNewLogConfInfo == NULL)
3972 return CR_OUT_OF_MEMORY;
3973
3974 pNewLogConfInfo->ulMagic = LOG_CONF_MAGIC;
3975 pNewLogConfInfo->dnDevInst = pLogConfInfo->dnDevInst;
3976 pNewLogConfInfo->ulFlags = pLogConfInfo->ulFlags;
3977 pNewLogConfInfo->ulTag = ulNewTag;
3978
3979 *plcLogConf = (LOG_CONF)pNewLogConfInfo;
3980 }
3981
3982 return CR_SUCCESS;
3983 }
3984
3985
3986 /***********************************************************************
3987 * CM_Get_Next_Re_Des [SETUPAPI.@]
3988 */
3989 CONFIGRET WINAPI CM_Get_Next_Res_Des(
3990 PRES_DES prdResDes, RES_DES rdResDes, RESOURCEID ForResource,
3991 PRESOURCEID pResourceID, ULONG ulFlags)
3992 {
3993 TRACE("%p %p %lu %p %lx\n", prdResDes, rdResDes, ForResource,
3994 pResourceID, ulFlags);
3995 return CM_Get_Next_Res_Des_Ex(prdResDes, rdResDes, ForResource,
3996 pResourceID, ulFlags, NULL);
3997 }
3998
3999
4000 /***********************************************************************
4001 * CM_Get_Next_Re_Des_Ex [SETUPAPI.@]
4002 */
4003 CONFIGRET WINAPI CM_Get_Next_Res_Des_Ex(
4004 PRES_DES prdResDes, RES_DES rdResDes, RESOURCEID ForResource,
4005 PRESOURCEID pResourceID, ULONG ulFlags, HMACHINE hMachine)
4006 {
4007 FIXME("%p %p %lu %p %lx %lx\n", prdResDes, rdResDes, ForResource,
4008 pResourceID, ulFlags, hMachine);
4009
4010 return CR_CALL_NOT_IMPLEMENTED;
4011 }
4012
4013
4014 /***********************************************************************
4015 * CM_Get_Parent [SETUPAPI.@]
4016 */
4017 CONFIGRET WINAPI CM_Get_Parent(
4018 PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags)
4019 {
4020 TRACE("%p %p %lx\n", pdnDevInst, dnDevInst, ulFlags);
4021 return CM_Get_Parent_Ex(pdnDevInst, dnDevInst, ulFlags, NULL);
4022 }
4023
4024
4025 /***********************************************************************
4026 * CM_Get_Parent_Ex [SETUPAPI.@]
4027 */
4028 CONFIGRET WINAPI CM_Get_Parent_Ex(
4029 PDEVINST pdnDevInst, DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
4030 {
4031 WCHAR szRelatedDevInst[MAX_DEVICE_ID_LEN];
4032 RPC_BINDING_HANDLE BindingHandle = NULL;
4033 HSTRING_TABLE StringTable = NULL;
4034 LPWSTR lpDevInst;
4035 DWORD dwIndex, dwLength = MAX_DEVICE_ID_LEN;
4036 CONFIGRET ret;
4037
4038 TRACE("%p %lx %lx %lx\n", pdnDevInst, dnDevInst, ulFlags, hMachine);
4039
4040 if (pdnDevInst == NULL)
4041 return CR_INVALID_POINTER;
4042
4043 if (dnDevInst == 0)
4044 return CR_INVALID_DEVINST;
4045
4046 if (ulFlags != 0)
4047 return CR_INVALID_FLAG;
4048
4049 *pdnDevInst = -1;
4050
4051 if (hMachine != NULL)
4052 {
4053 BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
4054 if (BindingHandle == NULL)
4055 return CR_FAILURE;
4056
4057 StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
4058 if (StringTable == 0)
4059 return CR_FAILURE;
4060 }
4061 else
4062 {
4063 if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
4064 return CR_FAILURE;
4065 }
4066
4067 lpDevInst = pSetupStringTableStringFromId(StringTable, dnDevInst);
4068 if (lpDevInst == NULL)
4069 return CR_INVALID_DEVNODE;
4070
4071 RpcTryExcept
4072 {
4073 ret = PNP_GetRelatedDeviceInstance(BindingHandle,
4074 PNP_GET_PARENT_DEVICE_INSTANCE,
4075 lpDevInst,
4076 szRelatedDevInst,
4077 &dwLength,
4078 0);
4079 }
4080 RpcExcept(EXCEPTION_EXECUTE_HANDLER)
4081 {
4082 ret = RpcStatusToCmStatus(RpcExceptionCode());
4083 }
4084 RpcEndExcept;
4085
4086 if (ret != CR_SUCCESS)
4087 return ret;
4088
4089 TRACE("szRelatedDevInst: %s\n", debugstr_w(szRelatedDevInst));
4090
4091 dwIndex = pSetupStringTableAddString(StringTable, szRelatedDevInst, 1);
4092 if (dwIndex == -1)
4093 return CR_FAILURE;
4094
4095 *pdnDevInst = dwIndex;
4096