Eric Pouech : ntdll: Implemented COMM IOCTL for modem status: GET_MODEMSTATUS.

Alexandre Julliard julliard at wine.codeweavers.com
Mon Feb 6 05:10:28 CST 2006


Module: wine
Branch: refs/heads/master
Commit: 5973955e4e82edb114e1559f729b0e2b41bdbf4c
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=5973955e4e82edb114e1559f729b0e2b41bdbf4c

Author: Eric Pouech <eric.pouech at wanadoo.fr>
Date:   Mon Feb  6 11:37:39 2006 +0100

ntdll: Implemented COMM IOCTL for modem status: GET_MODEMSTATUS.

---

 dlls/kernel/comm.c  |   53 +++++++++------------------------------------------
 dlls/ntdll/serial.c |   47 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 44 deletions(-)

diff --git a/dlls/kernel/comm.c b/dlls/kernel/comm.c
index 3a63c02..75ee11c 100644
--- a/dlls/kernel/comm.c
+++ b/dlls/kernel/comm.c
@@ -1801,55 +1801,20 @@ BOOL WINAPI SetCommTimeouts(
  *
  *  Obtains the four control register bits if supported by the hardware.
  *
+ * PARAMS
+ *
+ *      hFile           [in]    The communications device
+ *      lpModemStat     [out]   The control register bits
+ *
  * RETURNS
  *
  *  True if the communications handle was good and for hardware that
  *  control register access, false otherwise.
  */
-BOOL WINAPI GetCommModemStatus(
-    HANDLE  hFile,       /* [in] The communications device. */
-    LPDWORD lpModemStat) /* [out] The control register bits. */
-{
-	int fd,mstat, result=FALSE;
-
-	*lpModemStat=0;
-#ifdef TIOCMGET
-	fd = get_comm_fd( hFile, FILE_READ_DATA );
-	if(fd<0)
-		return FALSE;
-	result = ioctl(fd, TIOCMGET, &mstat);
-	release_comm_fd( hFile, fd );
-	if (result == -1)
-	  {
-	    WARN("ioctl failed\n");
-	    return FALSE;
-	  }
-#ifdef TIOCM_CTS
-	if (mstat & TIOCM_CTS)
-	    *lpModemStat |= MS_CTS_ON;
-#endif
-#ifdef TIOCM_DSR
-	if (mstat & TIOCM_DSR)
-	  *lpModemStat |= MS_DSR_ON;
-#endif
-#ifdef TIOCM_RNG
-	if (mstat & TIOCM_RNG)
-	  *lpModemStat |= MS_RING_ON;
-#endif
-#ifdef TIOCM_CAR
-	/*FIXME:  Not really sure about RLSD  UB 990810*/
-	if (mstat & TIOCM_CAR)
-	  *lpModemStat |= MS_RLSD_ON;
-#endif
-	TRACE("%04x -> %s%s%s%s\n", mstat,
-	      (*lpModemStat &MS_RLSD_ON)?"MS_RLSD_ON ":"",
-	      (*lpModemStat &MS_RING_ON)?"MS_RING_ON ":"",
-	      (*lpModemStat &MS_DSR_ON)?"MS_DSR_ON ":"",
-	      (*lpModemStat &MS_CTS_ON)?"MS_CTS_ON ":"");
-	return TRUE;
-#else
-	return FALSE;
-#endif
+BOOL WINAPI GetCommModemStatus(HANDLE hFile, LPDWORD lpModemStat)
+{
+    return DeviceIoControl(hFile, IOCTL_SERIAL_GET_MODEMSTATUS,
+                           NULL, 0, lpModemStat, sizeof(DWORD), NULL, NULL);
 }
 
 static DWORD WINAPI Comm_CheckEvents(int fd, DWORD mask, serial_irq_info *new, serial_irq_info *old, DWORD new_mstat, DWORD old_mstat)
diff --git a/dlls/ntdll/serial.c b/dlls/ntdll/serial.c
index b364376..115d981 100644
--- a/dlls/ntdll/serial.c
+++ b/dlls/ntdll/serial.c
@@ -129,6 +129,45 @@ static const char* iocode2str(DWORD ioc)
     }
 }
 
+static NTSTATUS get_modem_status(int fd, DWORD* lpModemStat)
+{
+    NTSTATUS    status = STATUS_SUCCESS;
+    int         mstat;
+
+#ifdef TIOCMGET
+    if (ioctl(fd, TIOCMGET, &mstat) == -1)
+    {
+        WARN("ioctl failed\n");
+        status = FILE_GetNtStatus();
+    }
+    else
+    {
+        *lpModemStat = 0;
+#ifdef TIOCM_CTS
+        if (mstat & TIOCM_CTS)  *lpModemStat |= MS_CTS_ON;
+#endif
+#ifdef TIOCM_DSR
+        if (mstat & TIOCM_DSR)  *lpModemStat |= MS_DSR_ON;
+#endif
+#ifdef TIOCM_RNG
+        if (mstat & TIOCM_RNG)  *lpModemStat |= MS_RING_ON;
+#endif
+#ifdef TIOCM_CAR
+        /* FIXME: Not really sure about RLSD UB 990810 */
+        if (mstat & TIOCM_CAR)  *lpModemStat |= MS_RLSD_ON;
+#endif
+        TRACE("%04x -> %s%s%s%s\n", mstat,
+              (*lpModemStat & MS_RLSD_ON) ? "MS_RLSD_ON " : "",
+              (*lpModemStat & MS_RING_ON) ? "MS_RING_ON " : "",
+              (*lpModemStat & MS_DSR_ON)  ? "MS_DSR_ON  " : "",
+              (*lpModemStat & MS_CTS_ON)  ? "MS_CTS_ON  " : "");
+    }
+#else
+    status = STATUS_NOT_SUPPORTED;
+#endif
+    return status;
+}
+
 static NTSTATUS get_wait_mask(HANDLE hDevice, DWORD* mask)
 {
     NTSTATUS    status;
@@ -199,6 +238,14 @@ NTSTATUS COMM_DeviceIoControl(HANDLE hDe
 
     switch (dwIoControlCode)
     {
+    case IOCTL_SERIAL_GET_MODEMSTATUS:
+        if (lpOutBuffer && nOutBufferSize == sizeof(DWORD))
+        {
+            if (!(status = get_modem_status(fd, (DWORD*)lpOutBuffer)))
+                sz = sizeof(DWORD);
+        }
+        else status = STATUS_INVALID_PARAMETER;
+        break;
     case IOCTL_SERIAL_GET_WAIT_MASK:
         if (lpOutBuffer && nOutBufferSize == sizeof(DWORD))
         {




More information about the wine-cvs mailing list