Implement CMP_Init_Detection, CMP_Report_LogOn, CM_Setup_DevNode[_Ex] and CM_Uninstall_DevNode[_Ex].
Modified: trunk/reactos/include/idl/pnp.idl
Modified: trunk/reactos/include/wine/cfgmgr32.h
Modified: trunk/reactos/lib/setupapi/cfgmgr.c
Modified: trunk/reactos/services/umpnpmgr/umpnpmgr.c

Modified: trunk/reactos/include/idl/pnp.idl
--- trunk/reactos/include/idl/pnp.idl	2005-12-17 17:31:32 UTC (rev 20227)
+++ trunk/reactos/include/idl/pnp.idl	2005-12-17 19:58:23 UTC (rev 20228)
@@ -5,6 +5,7 @@
 #define WORD unsigned short
 #define DWORD unsigned long
 #define CONFIGRET unsigned long
+#define BOOL unsigned long
 #define PBOOL unsigned long *
 
 [
@@ -33,6 +34,11 @@
   /* Function 4 */
   CONFIGRET PNP_InitDetection(handle_t BindingHandle);
 
+  /* Function 5 */
+  CONFIGRET PNP_ReportLogOn(handle_t BindingHandle,
+                            [in] BOOL Admin,
+                            [in] DWORD ProcessId);
+
   /* Function 6 */
   CONFIGRET PNP_ValidateDeviceInstance(handle_t BindingHandle,
                                        [in, string] wchar_t *DeviceInstance,
@@ -103,6 +109,12 @@
                                  [in] unsigned long Length,
                                  [in] unsigned long Flags);
 
+  /* Function 15 */
+  CONFIGRET PNP_GetClassInstance(handle_t BindingHandle,
+                                 [in, string] wchar_t *DeviceId,
+                                 [out, string, size_is(Length)] wchar_t *Buffer,
+                                 [in] unsigned long Length);
+
   /* Function 16 */
   CONFIGRET PNP_CreateKey(handle_t BindingHandle,
                           [in, string] wchar_t *SubKey,
@@ -148,6 +160,11 @@
                                  [in] unsigned long Problem,
                                  [in] DWORD Flags);
 
+  /* Function 33 */
+  CONFIGRET PNP_UninstallDevInst(handle_t BindingHandle,
+                                 [in, string] wchar_t *DeviceInstance,
+                                 [in] DWORD Flags);
+
   /* Function 38 */
   CONFIGRET PNP_IsDockStationPresent(handle_t BindingHandle,
                                      [out]PBOOL Present);

Modified: trunk/reactos/include/wine/cfgmgr32.h
--- trunk/reactos/include/wine/cfgmgr32.h	2005-12-17 17:31:32 UTC (rev 20227)
+++ trunk/reactos/include/wine/cfgmgr32.h	2005-12-17 19:58:23 UTC (rev 20228)
@@ -153,7 +153,22 @@
 #define CM_DETECT_RUN               0x80000000
 #define CM_DETECT_BITS              0x80000007
 
+/* ulFlags for CM_Setup_DevInst[_Ex] */
+#define CM_SETUP_DEVNODE_READY   0x00000000
+#define CM_SETUP_DEVINST_READY   CM_SETUP_DEVNODE_READY
+#define CM_SETUP_DOWNLOAD        0x00000001
+#define CM_SETUP_WRITE_LOG_CONFS 0x00000002
+#define CM_SETUP_PROP_CHANGE     0x00000003
+#define CM_SETUP_DEVNODE_RESET   0x00000004
+#define CM_SETUP_DEVINST_RESET   CM_SETUP_DEVNODE_RESET
+#define CM_SETUP_BITS            0x00000007
 
+#define CMP_MAGIC  0x01234567
+
+
+CONFIGRET WINAPI CMP_Init_Detection( DWORD );
+CONFIGRET WINAPI CMP_Report_LogOn( DWORD, DWORD );
+
 CONFIGRET WINAPI CM_Connect_MachineA( PCSTR, PHMACHINE );
 CONFIGRET WINAPI CM_Connect_MachineW( PCWSTR, PHMACHINE );
 #define     CM_Connect_Machine WINELIB_NAME_AW(CM_Connect_Machine)
@@ -227,18 +242,21 @@
 
 CONFIGRET WINAPI CM_Is_Dock_Station_Present( PBOOL );
 CONFIGRET WINAPI CM_Is_Dock_Station_Present_Ex( PBOOL, HMACHINE );
-CONFIGRET WINAPI CM_Locate_DevNodeA(PDEVINST, DEVINSTID_A, ULONG);
-CONFIGRET WINAPI CM_Locate_DevNodeW(PDEVINST, DEVINSTID_W, ULONG);
+CONFIGRET WINAPI CM_Locate_DevNodeA( PDEVINST, DEVINSTID_A, ULONG );
+CONFIGRET WINAPI CM_Locate_DevNodeW( PDEVINST, DEVINSTID_W, ULONG );
 #define     CM_Locate_DevNode WINELIB_NAME_AW(CM_Locate_DevNode)
-CONFIGRET WINAPI CM_Locate_DevNode_ExA(PDEVINST, DEVINSTID_A, ULONG, HMACHINE);
-CONFIGRET WINAPI CM_Locate_DevNode_ExW(PDEVINST, DEVINSTID_W, ULONG, HMACHINE);
+CONFIGRET WINAPI CM_Locate_DevNode_ExA( PDEVINST, DEVINSTID_A, ULONG, HMACHINE );
+CONFIGRET WINAPI CM_Locate_DevNode_ExW( PDEVINST, DEVINSTID_W, ULONG, HMACHINE );
 #define     CM_Locate_DevNode_Ex WINELIB_NAME_AW(CM_Locate_DevNode_Ex)
 
-CONFIGRET WINAPI CM_Open_Class_KeyA(LPGUID, LPCSTR, REGSAM, REGDISPOSITION, PHKEY, ULONG);
-CONFIGRET WINAPI CM_Open_Class_KeyW(LPGUID, LPCWSTR, REGSAM, REGDISPOSITION, PHKEY, ULONG);
+CONFIGRET WINAPI CM_Move_DevNode( DEVINST, DEVINST, ULONG );
+CONFIGRET WINAPI CM_Move_DevNode_Ex( DEVINST, DEVINST, ULONG, HMACHINE );
+
+CONFIGRET WINAPI CM_Open_Class_KeyA( LPGUID, LPCSTR, REGSAM, REGDISPOSITION, PHKEY, ULONG );
+CONFIGRET WINAPI CM_Open_Class_KeyW( LPGUID, LPCWSTR, REGSAM, REGDISPOSITION, PHKEY, ULONG );
 #define     CM_Open_Class_Key WINELIB_NAME_AW(CM_Open_Class_Key)
-CONFIGRET WINAPI CM_Open_Class_Key_ExA(LPGUID, LPCSTR, REGSAM, REGDISPOSITION, PHKEY, ULONG, HMACHINE);
-CONFIGRET WINAPI CM_Open_Class_Key_ExW(LPGUID, LPCWSTR, REGSAM, REGDISPOSITION, PHKEY, ULONG, HMACHINE);
+CONFIGRET WINAPI CM_Open_Class_Key_ExA( LPGUID, LPCSTR, REGSAM, REGDISPOSITION, PHKEY, ULONG, HMACHINE );
+CONFIGRET WINAPI CM_Open_Class_Key_ExW( LPGUID, LPCWSTR, REGSAM, REGDISPOSITION, PHKEY, ULONG, HMACHINE );
 #define     CM_Open_Class_Key_Ex WINELIB_NAME_AW(CM_Open_Class_Key_Ex)
 
 CONFIGRET WINAPI CM_Reenumerate_DevNode( DEVINST, ULONG );
@@ -258,4 +276,10 @@
 CONFIGRET WINAPI CM_Set_DevNode_Registry_Property_ExW( DEVINST, ULONG, PCVOID, ULONG, ULONG, HMACHINE );
 #define     CM_Set_DevNode_Registry_Property_Ex WINELIB_NAME_AW(CM_Set_DevNode_Registry_Property_Ex)
 
+CONFIGRET WINAPI CM_Setup_DevNode( DEVINST, ULONG );
+CONFIGRET WINAPI CM_Setup_DevNode_Ex( DEVINST, ULONG, HMACHINE );
+
+CONFIGRET WINAPI CM_Uninstall_DevNode( DEVINST, ULONG );
+CONFIGRET WINAPI CM_Uninstall_DevNode_Ex( DEVINST, ULONG, HMACHINE );
+
 #endif /* _CFGMGR32_H_ */

Modified: trunk/reactos/lib/setupapi/cfgmgr.c
--- trunk/reactos/lib/setupapi/cfgmgr.c	2005-12-17 17:31:32 UTC (rev 20227)
+++ trunk/reactos/lib/setupapi/cfgmgr.c	2005-12-17 19:58:23 UTC (rev 20228)
@@ -65,9 +65,67 @@
 
 
 /***********************************************************************
+ * CMP_Init_Detection [SETUPAPI.@]
+ */
+CONFIGRET WINAPI CMP_Init_Detection(
+    DWORD dwMagic)
+{
+    RPC_BINDING_HANDLE BindingHandle = NULL;
+
+    TRACE("%lu\n", dwMagic);
+
+    if (dwMagic != CMP_MAGIC)
+        return CR_INVALID_DATA;
+
+    if (!PnpGetLocalHandles(&BindingHandle, NULL))
+        return CR_FAILURE;
+
+    return PNP_InitDetection(BindingHandle);
+}
+
+
+/***********************************************************************
+ * CMP_Report_LogOn [SETUPAPI.@]
+ */
+CONFIGRET WINAPI CMP_Report_LogOn(
+    DWORD dwMagic,
+    DWORD dwProcessId)
+{
+    RPC_BINDING_HANDLE BindingHandle = NULL;
+    CONFIGRET ret = CR_SUCCESS;
+    BOOL bAdmin;
+    DWORD i;
+
+    TRACE("%lu\n", dwMagic);
+
+    if (dwMagic != CMP_MAGIC)
+        return CR_INVALID_DATA;
+
+    if (!PnpGetLocalHandles(&BindingHandle, NULL))
+        return CR_FAILURE;
+
+    bAdmin = TRUE; //IsUserAdmin();
+
+    for (i = 0; i < 30; i++)
+    {
+        ret = PNP_ReportLogOn(BindingHandle,
+                              bAdmin,
+                              dwProcessId);
+        if (ret == CR_SUCCESS)
+            break;
+
+        Sleep(5000);
+    }
+
+    return ret;
+}
+
+
+/***********************************************************************
  * CM_Connect_MachineA [SETUPAPI.@]
  */
-CONFIGRET WINAPI CM_Connect_MachineA(PCSTR UNCServerName, PHMACHINE phMachine)
+CONFIGRET WINAPI CM_Connect_MachineA(
+    PCSTR UNCServerName, PHMACHINE phMachine)
 {
     PWSTR pServerNameW;
     CONFIGRET ret;
@@ -91,7 +149,8 @@
 /***********************************************************************
  * CM_Connect_MachineW [SETUPAPI.@]
  */
-CONFIGRET WINAPI CM_Connect_MachineW(PCWSTR UNCServerName, PHMACHINE phMachine)
+CONFIGRET WINAPI CM_Connect_MachineW(
+    PCWSTR UNCServerName, PHMACHINE phMachine)
 {
     PMACHINE_INFO pMachine;
 
@@ -128,7 +187,8 @@
 /***********************************************************************
  * CM_Delete_Class_Key [SETUPAPI.@]
  */
-CONFIGRET WINAPI CM_Delete_Class_Key(LPGUID ClassGuid, ULONG ulFlags)
+CONFIGRET WINAPI CM_Delete_Class_Key(
+    LPGUID ClassGuid, ULONG ulFlags)
 {
     TRACE("%p %lx\n", ClassGuid, ulFlags);
     return CM_Delete_Class_Key_Ex(ClassGuid, ulFlags, NULL);
@@ -1836,6 +1896,73 @@
 
 
 /***********************************************************************
+ * CM_Move_DevNode [SETUPAPI.@]
+ */
+CONFIGRET WINAPI CM_Move_DevNode(
+    DEVINST dnFromDevInst, DEVINST dnToDevInst, ULONG ulFlags)
+{
+    TRACE("%lx %lx %lx\n", dnFromDevInst, dnToDevInst, ulFlags);
+    return CM_Move_DevNode_Ex(dnFromDevInst, dnToDevInst, ulFlags, NULL);
+}
+
+
+/***********************************************************************
+ * CM_Move_DevNode_Ex [SETUPAPI.@]
+ */
+CONFIGRET WINAPI CM_Move_DevNode_Ex(
+    DEVINST dnFromDevInst, DEVINST dnToDevInst, ULONG ulFlags,
+    HMACHINE hMachine)
+{
+    RPC_BINDING_HANDLE BindingHandle = NULL;
+    HSTRING_TABLE StringTable = NULL;
+    LPWSTR lpFromDevInst;
+    LPWSTR lpToDevInst;
+
+    FIXME("%lx %lx %lx %lx\n",
+          dnFromDevInst, dnToDevInst, ulFlags, hMachine);
+
+//    if (!IsUserAdmin())
+//        return CR_ACCESS_DENIED;
+
+    if (dnFromDevInst == 0 || dnToDevInst == 0)
+        return CR_INVALID_DEVNODE;
+
+    if (ulFlags != 0)
+        return CR_INVALID_FLAG;
+
+    if (hMachine != NULL)
+    {
+        BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
+        if (BindingHandle == NULL)
+            return CR_FAILURE;
+
+        StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
+        if (StringTable == 0)
+            return CR_FAILURE;
+    }
+    else
+    {
+        if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
+            return CR_FAILURE;
+    }
+
+    lpFromDevInst = StringTableStringFromId(StringTable, dnFromDevInst);
+    if (lpFromDevInst == NULL)
+        return CR_INVALID_DEVNODE;
+
+    lpToDevInst = StringTableStringFromId(StringTable, dnToDevInst);
+    if (lpToDevInst == NULL)
+        return CR_INVALID_DEVNODE;
+
+    return PNP_DeviceInstanceAction(BindingHandle,
+                                    2,
+                                    ulFlags,
+                                    lpFromDevInst,
+                                    lpToDevInst);
+}
+
+
+/***********************************************************************
  * CM_Open_Class_KeyA [SETUPAPI.@]
  */
 CONFIGRET WINAPI CM_Open_Class_KeyA(
@@ -2464,3 +2591,118 @@
                                 ulLength,
                                 ulFlags);
 }
+
+
+/***********************************************************************
+ * CM_Setup_DevNode [SETUPAPI.@]
+ */
+CONFIGRET WINAPI CM_Setup_DevNode(
+    DEVINST dnDevInst, ULONG ulFlags)
+{
+    TRACE("%lx %lx\n", dnDevInst, ulFlags);
+    return CM_Setup_DevNode_Ex(dnDevInst, ulFlags, NULL);
+}
+
+
+/***********************************************************************
+ * CM_Setup_DevNode_Ex [SETUPAPI.@]
+ */
+CONFIGRET WINAPI CM_Setup_DevNode_Ex(
+    DEVINST dnDevInst, ULONG ulFlags, HMACHINE hMachine)
+{
+    RPC_BINDING_HANDLE BindingHandle = NULL;
+    HSTRING_TABLE StringTable = NULL;
+    LPWSTR lpDevInst;
+
+    FIXME("%lx %lx %lx\n", dnDevInst, ulFlags, hMachine);
+
+//    if (!IsUserAdmin())
+//        return CR_ACCESS_DENIED;
+
+    if (dnDevInst == 0)
+        return CR_INVALID_DEVNODE;
+
+    if (ulFlags & ~CM_SETUP_BITS)
+        return CR_INVALID_FLAG;
+
+    if (hMachine != NULL)
+    {
+        BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
+        if (BindingHandle == NULL)
+            return CR_FAILURE;
+
+        StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
+        if (StringTable == 0)
+            return CR_FAILURE;
+    }
+    else
+    {
+        if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
+            return CR_FAILURE;
+    }
+
+    lpDevInst = StringTableStringFromId(StringTable, dnDevInst);
+    if (lpDevInst == NULL)
+        return CR_INVALID_DEVNODE;
+
+    return PNP_DeviceInstanceAction(BindingHandle,
+                                    3,
+                                    ulFlags,
+                                    lpDevInst,
+                                    NULL);
+}
+
+
+/***********************************************************************
+ * CM_Uninstall_DevNode [SETUPAPI.@]
+ */
+CONFIGRET WINAPI CM_Uninstall_DevNode(
+    DEVINST dnPhantom, ULONG ulFlags)
+{
+    TRACE("%lx %lx\n", dnPhantom, ulFlags);
+    return CM_Uninstall_DevNode_Ex(dnPhantom, ulFlags, NULL);
+}
+
+
+/***********************************************************************
+ * CM_Uninstall_DevNode_Ex [SETUPAPI.@]
+ */
+CONFIGRET WINAPI CM_Uninstall_DevNode_Ex(
+    DEVINST dnPhantom, ULONG ulFlags, HMACHINE hMachine)
+{
+    RPC_BINDING_HANDLE BindingHandle = NULL;
+    HSTRING_TABLE StringTable = NULL;
+    LPWSTR lpDevInst;
+
+    TRACE("%lx %lx %lx\n", dnPhantom, ulFlags, hMachine);
+
+    if (dnPhantom == 0)
+        return CR_INVALID_DEVNODE;
+
+    if (ulFlags != 0)
+        return CR_INVALID_FLAG;
+
+    if (hMachine != NULL)
+    {
+        BindingHandle = ((PMACHINE_INFO)hMachine)->BindingHandle;
+        if (BindingHandle == NULL)
+            return CR_FAILURE;
+
+        StringTable = ((PMACHINE_INFO)hMachine)->StringTable;
+        if (StringTable == 0)
+            return CR_FAILURE;
+    }
+    else
+    {
+        if (!PnpGetLocalHandles(&BindingHandle, &StringTable))
+            return CR_FAILURE;
+    }
+
+    lpDevInst = StringTableStringFromId(StringTable, dnPhantom);
+    if (lpDevInst == NULL)
+        return CR_INVALID_DEVNODE;
+
+    return PNP_UninstallDevInst(BindingHandle,
+                                lpDevInst,
+                                ulFlags);
+}

Modified: trunk/reactos/services/umpnpmgr/umpnpmgr.c
--- trunk/reactos/services/umpnpmgr/umpnpmgr.c	2005-12-17 17:31:32 UTC (rev 20227)
+++ trunk/reactos/services/umpnpmgr/umpnpmgr.c	2005-12-17 19:58:23 UTC (rev 20228)
@@ -58,6 +58,10 @@
 static HKEY hEnumKey = NULL;
 static HKEY hClassKey = NULL;
 
+static HANDLE hUserToken = NULL;
+static HANDLE hInstallEvent = NULL;
+
+
 /* FUNCTIONS *****************************************************************/
 
 static DWORD WINAPI
@@ -159,6 +163,42 @@
 }
 
 
+/* Function 5 */
+CONFIGRET
+PNP_ReportLogOn(handle_t BindingHandle,
+                unsigned long Admin,
+                unsigned long ProcessId)
+{
+    HANDLE hProcess;
+
+    DPRINT1("PNP_ReportLogOn(%lu, %lu) called\n", Admin, ProcessId);
+
+    /* Get the users token */
+    hProcess = OpenProcess(PROCESS_ALL_ACCESS,
+                           TRUE,
+                           ProcessId);
+    if (hProcess != NULL)
+    {
+        if (hUserToken != NULL)
+        {
+            CloseHandle(hUserToken);
+            hUserToken = NULL;
+        }
+
+        OpenProcessToken(hProcess,
+                         TOKEN_ALL_ACCESS,
+                         &hUserToken);
+        CloseHandle(hProcess);
+    }
+
+    /* Trigger the installer thread */
+    if (hInstallEvent != NULL)
+        SetEvent(hInstallEvent);
+
+    return CR_SUCCESS;
+}
+
+
 /* Function 6 */
 CONFIGRET
 PNP_ValidateDeviceInstance(handle_t BindingHandle,
@@ -684,6 +724,23 @@
 }
 
 
+/* Function 15 */
+CONFIGRET
+PNP_GetClassInstance(handle_t BindingHandle,
+                     wchar_t *DeviceId, /* in */
+                     wchar_t *Buffer, /* out */
+                     unsigned long Length)
+{
+    CONFIGRET ret = CR_SUCCESS;
+
+    DPRINT("PNP_Get_Class_Instance() called\n");
+
+    DPRINT("PNP_Get_Class_Instance() done (returns %lx)\n", ret);
+
+    return ret;
+}
+
+
 /* Function 16 */
 CONFIGRET
 PNP_CreateKey(handle_t BindingHandle,
@@ -849,16 +906,34 @@
 
     switch (MajorAction)
     {
+        case 2:
+            DPRINT("Move device instance\n");
+            /* FIXME */
+            ret = CR_CALL_NOT_IMPLEMENTED;
+            break;
+
+        case 3:
+            DPRINT("Setup device instance\n");
+            /* FIXME */
+            ret = CR_CALL_NOT_IMPLEMENTED;
+            break;
+
         case 4:
             DPRINT("Enable device instance\n");
+            /* FIXME */
+            ret = CR_CALL_NOT_IMPLEMENTED;
             break;
 
         case 5:
             DPRINT("Disable device instance\n");
+            /* FIXME */
+            ret = CR_CALL_NOT_IMPLEMENTED;
             break;
 
         case 7:
             DPRINT("Reenumerate device instance\n");
+            /* FIXME */
+            ret = CR_CALL_NOT_IMPLEMENTED;
             break;
 
         default:
@@ -909,6 +984,7 @@
 }
 
 
+/* Function 31 */
 CONFIGRET
 PNP_SetDeviceProblem(handle_t BindingHandle,
                      wchar_t *DeviceInstance,
@@ -927,6 +1003,24 @@
 }
 
 
+/* Function 33 */
+CONFIGRET
+PNP_UninstallDevInst(handle_t BindingHandle,
+                     wchar_t *DeviceInstance,
+                     DWORD Flags)
+{
+    CONFIGRET ret = CR_SUCCESS;
+
+    DPRINT1("PNP_UninstallDevInst() called\n");
+
+    /* FIXME */
+
+    DPRINT1("PNP_UninstallDevInst() done (returns %lx)\n", ret);
+
+    return ret;
+}
+
+
 /* Function 38 */
 CONFIGRET
 PNP_IsDockStationPresent(handle_t BindingHandle,
@@ -1184,6 +1278,14 @@
 
     DPRINT("Umpnpmgr: main() started\n");
 
+    hInstallEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
+    if (hInstallEvent == NULL)
+    {
+        dwError = GetLastError();
+        DPRINT1("Could not create the Install Event! (Error %lu)\n", dwError);
+        return dwError;
+    }
+
     dwError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
                             L"System\\CurrentControlSet\\Enum",
                             0,