[MSPORTS]
authorEric Kohl <eric.kohl@reactos.org>
Tue, 17 May 2011 19:24:19 +0000 (19:24 +0000)
committerEric Kohl <eric.kohl@reactos.org>
Tue, 17 May 2011 19:24:19 +0000 (19:24 +0000)
- Implement a simple class installer that assigns the friendly name "Serial Port (COMx)" to all serial ports.
- Enable the class installer in ports.inf.
- Add parallel port installer configuration to ports.inf (disabled).

svn path=/trunk/; revision=51813

12 files changed:
reactos/baseaddress.cmake
reactos/baseaddress.rbuild
reactos/boot/bootdata/packages/reactos.dff
reactos/dll/win32/CMakeLists.txt
reactos/dll/win32/msports/CMakeLists.txt [new file with mode: 0644]
reactos/dll/win32/msports/classinst.c [new file with mode: 0644]
reactos/dll/win32/msports/msports.c [new file with mode: 0644]
reactos/dll/win32/msports/msports.rbuild [new file with mode: 0644]
reactos/dll/win32/msports/msports.rc [new file with mode: 0644]
reactos/dll/win32/msports/msports.spec [new file with mode: 0644]
reactos/dll/win32/win32.rbuild
reactos/media/inf/ports.inf

index 9a3128c..4430a00 100644 (file)
@@ -49,6 +49,7 @@ set(baseaddress_dinput                        0x5f580000)
 set(baseaddress_netid                  0x5f660000)
 set(baseaddress_ntprint                        0x5f6a0000)
 set(baseaddress_mssip32                        0x60430000)
+set(baseaddress_msports                        0x60450000)
 set(baseaddress_msisip                 0x60b10000)
 set(baseaddress_inseng                 0x61000000)
 set(baseaddress_qedit                  0x611c0000)
index 5df296d..33a469a 100644 (file)
@@ -52,6 +52,7 @@
        <property name="BASEADDRESS_NETID"              value="0x5f660000" />
        <property name="BASEADDRESS_NTPRINT"            value="0x5f6a0000" />
        <property name="BASEADDRESS_MSSIP32"            value="0x60430000" />
+       <property name="BASEADDRESS_MSPORTS"            value="0x60450000" />
        <property name="BASEADDRESS_MSISIP"             value="0x60b10000" />
        <property name="BASEADDRESS_INSENG"             value="0x61000000" />
        <property name="BASEADDRESS_QEDIT"              value="0x611c0000" />
index 47d5ee4..8416c1b 100644 (file)
@@ -357,6 +357,7 @@ dll\win32\msimtf\msimtf.dll                         1
 dll\win32\msisip\msisip.dll                         1
 dll\win32\msisys.ocx\msisys.ocx                     1
 dll\win32\msnet32\msnet32.dll                       1
+dll\win32\msports\msports.dll                       1
 dll\win32\msrle32\msrle32.dll                       1
 dll\win32\mssign32\mssign32.dll                     1
 dll\win32\mssip32\mssip32.dll                       1
index 42e04b5..743abac 100644 (file)
@@ -99,6 +99,7 @@ add_subdirectory(msimtf)
 add_subdirectory(msisip)
 add_subdirectory(msisys.ocx)
 #add_subdirectory(msnet32) #to be deleted in trunk.
+add_subdirectory(msports)
 add_subdirectory(msrle32)
 add_subdirectory(mssign32)
 add_subdirectory(mssip32)
diff --git a/reactos/dll/win32/msports/CMakeLists.txt b/reactos/dll/win32/msports/CMakeLists.txt
new file mode 100644 (file)
index 0000000..36b24da
--- /dev/null
@@ -0,0 +1,24 @@
+
+set_unicode()
+
+spec2def(msports.dll msports.spec)
+
+list(APPEND SOURCE
+    classinst.c
+    msports.c
+    parallel.c
+    serial.c
+    msports.rc
+    ${CMAKE_CURRENT_BINARY_DIR}/msports_stubs.c
+    ${CMAKE_CURRENT_BINARY_DIR}/msports.def)
+
+add_library(msports SHARED ${SOURCE})
+
+set_module_type(msports win32dll)
+
+target_link_libraries(msports wine)
+
+add_importlibs(msports comctl32 setupapi advapi32 user32 kernel32 ntdll)
+
+add_cd_file(TARGET msports DESTINATION reactos/system32 FOR all)
+add_importlib_target(msports.spec)
diff --git a/reactos/dll/win32/msports/classinst.c b/reactos/dll/win32/msports/classinst.c
new file mode 100644 (file)
index 0000000..63273fb
--- /dev/null
@@ -0,0 +1,250 @@
+/*
+ * PROJECT:     ReactOS system libraries
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        dlls\win32\msports\classinst.c
+ * PURPOSE:     Ports class installer
+ * PROGRAMMERS: Copyright 2011 Eric Kohl
+ */
+
+#include <windows.h>
+#include <setupapi.h>
+#include <wine/debug.h>
+
+WINE_DEFAULT_DEBUG_CHANNEL(msports);
+
+
+typedef enum _PORT_TYPE
+{
+    UnknownPort,
+    ParallelPort,
+    SerialPort
+} PORT_TYPE;
+
+
+static DWORD
+InstallSerialPort(IN HDEVINFO DeviceInfoSet,
+                  IN PSP_DEVINFO_DATA DeviceInfoData)
+{
+    LPWSTR pszFriendlyName = L"Serial Port (COMx)";
+
+    TRACE("InstallSerialPort(%p, %p)\n",
+          DeviceInfoSet, DeviceInfoData);
+
+    /* Install the device */
+    if (!SetupDiInstallDevice(DeviceInfoSet,
+                              DeviceInfoData))
+    {
+        return GetLastError();
+    }
+
+    /* Set the friendly name for the device */
+    SetupDiSetDeviceRegistryPropertyW(DeviceInfoSet,
+                                      DeviceInfoData,
+                                      SPDRP_FRIENDLYNAME,
+                                      (LPBYTE)pszFriendlyName,
+                                      (wcslen(pszFriendlyName) + 1) * sizeof(WCHAR));
+
+    return ERROR_SUCCESS;
+}
+
+
+static DWORD
+InstallParallelPort(IN HDEVINFO DeviceInfoSet,
+                    IN PSP_DEVINFO_DATA DeviceInfoData)
+{
+     FIXME("InstallParallelPort(%p, %p)\n",
+           DeviceInfoSet, DeviceInfoData);
+     return ERROR_DI_DO_DEFAULT;
+}
+
+
+VOID
+InstallDeviceData(IN HDEVINFO DeviceInfoSet,
+                  IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
+{
+    HKEY hKey = NULL;
+    HINF hInf = INVALID_HANDLE_VALUE;
+    SP_DRVINFO_DATA DriverInfoData;
+    PSP_DRVINFO_DETAIL_DATA DriverInfoDetailData;
+    WCHAR InfSectionWithExt[256];
+    BYTE buffer[2048];
+    DWORD dwRequired;
+
+    TRACE("InstallDeviceData()\n");
+
+    hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet,
+                                   DeviceInfoData,
+                                   DICS_FLAG_GLOBAL,
+                                   0,
+                                   DIREG_DRV,
+                                   NULL,
+                                   NULL);
+    if (hKey == NULL)
+        goto done;
+
+    DriverInfoData.cbSize = sizeof(SP_DRVINFO_DATA);
+    if (!SetupDiGetSelectedDriverW(DeviceInfoSet,
+                                   DeviceInfoData,
+                                   &DriverInfoData))
+    {
+        goto done;
+    }
+
+    DriverInfoDetailData = (PSP_DRVINFO_DETAIL_DATA)buffer;
+    DriverInfoDetailData->cbSize = sizeof(SP_DRVINFO_DETAIL_DATA);
+    if (!SetupDiGetDriverInfoDetailW(DeviceInfoSet,
+                                     DeviceInfoData,
+                                     &DriverInfoData,
+                                     DriverInfoDetailData,
+                                     2048,
+                                     &dwRequired))
+    {
+        if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+            goto done;
+    }
+
+    TRACE("Inf file name: %S\n", DriverInfoDetailData->InfFileName);
+
+    hInf = SetupOpenInfFileW(DriverInfoDetailData->InfFileName,
+                             NULL,
+                             INF_STYLE_WIN4,
+                             NULL);
+    if (hInf == INVALID_HANDLE_VALUE)
+        goto done;
+
+    TRACE("Section name: %S\n", DriverInfoDetailData->SectionName);
+
+    SetupDiGetActualSectionToInstallW(hInf,
+                                      DriverInfoDetailData->SectionName,
+                                      InfSectionWithExt,
+                                      256,
+                                      NULL,
+                                      NULL);
+
+    TRACE("InfSectionWithExt: %S\n", InfSectionWithExt);
+
+    SetupInstallFromInfSectionW(NULL,
+                                hInf,
+                                InfSectionWithExt,
+                                SPINST_REGISTRY,
+                                hKey,
+                                NULL,
+                                0,
+                                NULL,
+                                NULL,
+                                NULL,
+                                NULL);
+
+    TRACE("Done\n");
+
+done:;
+    if (hKey != NULL)
+        RegCloseKey(hKey);
+
+    if (hInf != INVALID_HANDLE_VALUE)
+        SetupCloseInfFile(hInf);
+}
+
+
+
+PORT_TYPE
+GetPortType(IN HDEVINFO DeviceInfoSet,
+            IN PSP_DEVINFO_DATA DeviceInfoData)
+{
+    HKEY hKey = NULL;
+    DWORD dwSize;
+    DWORD dwType = 0;
+    BYTE bData = 0;
+    PORT_TYPE PortType = UnknownPort;
+    LONG lError;
+
+    TRACE("GetPortType()\n");
+
+    hKey = SetupDiCreateDevRegKeyW(DeviceInfoSet,
+                                   DeviceInfoData,
+                                   DICS_FLAG_GLOBAL,
+                                   0,
+                                   DIREG_DRV,
+                                   NULL,
+                                   NULL);
+    if (hKey == NULL)
+    {
+        goto done;
+    }
+
+    dwSize = sizeof(BYTE);
+    lError = RegQueryValueExW(hKey,
+                              L"PortSubClass",
+                              NULL,
+                              &dwType,
+                              &bData,
+                              &dwSize);
+
+    TRACE("lError: %ld\n", lError);
+    TRACE("dwSize: %lu\n", dwSize);
+    TRACE("dwType: %lu\n", dwType);
+
+    if (lError == ERROR_SUCCESS &&
+        dwSize == sizeof(BYTE) &&
+        dwType == REG_BINARY)
+    {
+        if (bData == 0)
+            PortType = ParallelPort;
+        else
+            PortType = SerialPort;
+    }
+
+done:;
+    if (hKey != NULL)
+        RegCloseKey(hKey);
+
+    TRACE("GetPortType() returns %u \n", PortType);
+
+    return PortType;
+}
+
+
+static DWORD
+InstallPort(IN HDEVINFO DeviceInfoSet,
+            IN PSP_DEVINFO_DATA DeviceInfoData)
+{
+    PORT_TYPE PortType;
+
+    InstallDeviceData(DeviceInfoSet, DeviceInfoData);
+
+    PortType = GetPortType(DeviceInfoSet, DeviceInfoData);
+    switch (PortType)
+    {
+        case ParallelPort:
+            return InstallParallelPort(DeviceInfoSet, DeviceInfoData);
+
+        case SerialPort:
+            return InstallSerialPort(DeviceInfoSet, DeviceInfoData);
+
+        default:
+            return ERROR_DI_DO_DEFAULT;
+    }
+}
+
+
+DWORD
+WINAPI
+PortsClassInstaller(IN DI_FUNCTION InstallFunction,
+                    IN HDEVINFO DeviceInfoSet,
+                    IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
+{
+    TRACE("PortsClassInstaller(%lu, %p, %p)\n",
+          InstallFunction, DeviceInfoSet, DeviceInfoData);
+
+    switch (InstallFunction)
+    {
+        case DIF_INSTALLDEVICE:
+            return InstallPort(DeviceInfoSet, DeviceInfoData);
+
+        default:
+            TRACE("Install function %u ignored\n", InstallFunction);
+            return ERROR_DI_DO_DEFAULT;
+    }
+}
+
+/* EOF */
diff --git a/reactos/dll/win32/msports/msports.c b/reactos/dll/win32/msports/msports.c
new file mode 100644 (file)
index 0000000..2d0bcc5
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * PROJECT:     Ports installer library
+ * LICENSE:     GPL - See COPYING in the top level directory
+ * FILE:        dll/win32/msports/msports.c
+ * PURPOSE:     Library main function
+ * COPYRIGHT:   Copyright 2011 Eric Kohl
+ */
+
+#include <windows.h>
+#include <wine/debug.h>
+
+
+WINE_DEFAULT_DEBUG_CHANNEL(msports);
+
+
+BOOL
+WINAPI
+DllMain(HINSTANCE hinstDll,
+        DWORD dwReason,
+        LPVOID reserved)
+{
+    switch (dwReason)
+    {
+        case DLL_PROCESS_ATTACH:
+            TRACE("DLL_PROCESS_ATTACH\n");
+            DisableThreadLibraryCalls(hinstDll);
+            break;
+    }
+
+    return TRUE;
+}
+
+/* EOF */
diff --git a/reactos/dll/win32/msports/msports.rbuild b/reactos/dll/win32/msports/msports.rbuild
new file mode 100644 (file)
index 0000000..6c19b29
--- /dev/null
@@ -0,0 +1,11 @@
+<module name="msports" type="win32dll" baseaddress="${BASEADDRESS_MSPORTS}" installbase="system32" installname="msports.dll" unicode="yes">
+       <include base="msports">.</include>
+       <importlibrary definition="msports.spec" />
+       <library>wine</library>
+       <library>kernel32</library>
+       <library>advapi32</library>
+       <library>setupapi</library>
+       <file>classinst.c</file>
+       <file>msports.c</file>
+       <file>msports.rc</file>
+</module>
diff --git a/reactos/dll/win32/msports/msports.rc b/reactos/dll/win32/msports/msports.rc
new file mode 100644 (file)
index 0000000..33ab2b4
--- /dev/null
@@ -0,0 +1,7 @@
+#include <windows.h>
+
+#define REACTOS_VERSION_DLL
+#define REACTOS_STR_FILE_DESCRIPTION   "Ports Class Installer\0"
+#define REACTOS_STR_INTERNAL_NAME      "msports\0"
+#define REACTOS_STR_ORIGINAL_FILENAME  "msports.dll\0"
+#include <reactos/version.rc>
diff --git a/reactos/dll/win32/msports/msports.spec b/reactos/dll/win32/msports/msports.spec
new file mode 100644 (file)
index 0000000..f2155b2
--- /dev/null
@@ -0,0 +1,12 @@
+@ stub ComDBClaimNextFreePort
+@ stub ComDBClaimPort
+@ stub ComDBClose
+@ stub ComDBGetCurrentPortUsage
+@ stub ComDBOpen
+@ stub ComDBReleasePort
+@ stub ComDBResizeDatabase
+@ stdcall LibMain(ptr long ptr) DllMain
+@ stub ParallelPortPropPageProvider
+@ stdcall PortsClassInstaller(long ptr ptr)
+@ stub SerialDisplayAdvancedSettings
+@ stub SerialPortPropPageProvider
index 53fbfd0..c83f901 100644 (file)
 <directory name="msnet32">
        <xi:include href="msnet32/msnet32.rbuild" />
 </directory>
+<directory name="msports">
+       <xi:include href="msports/msports.rbuild" />
+</directory>
 <directory name="msrle32">
        <xi:include href="msrle32/msrle32.rbuild" />
 </directory>
index 198bf98..ebe6dfa 100644 (file)
Binary files a/reactos/media/inf/ports.inf and b/reactos/media/inf/ports.inf differ