From 494b7e8f9306e706d23be7e5e574c5fdbcb7db6f Mon Sep 17 00:00:00 2001 From: Emmanuel Ledoux Date: Thu, 1 May 2014 00:04:55 +0200 Subject: [PATCH] winpr-comm: fixed DCB's fBinary and fParity flags --- winpr/libwinpr/comm/comm.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/winpr/libwinpr/comm/comm.c b/winpr/libwinpr/comm/comm.c index 86df72c86..acc8f15f5 100644 --- a/winpr/libwinpr/comm/comm.c +++ b/winpr/libwinpr/comm/comm.c @@ -216,9 +216,13 @@ BOOL GetCommState(HANDLE hFile, LPDCB lpDCB) } lpLocalDcb->BaudRate = baudRate.BaudRate; - lpLocalDcb->fBinary = TRUE; /* TMP: TODO: seems equivalent to the raw mode */ + lpLocalDcb->fBinary = (currentState.c_cflag & ICANON) == 0; + if (!lpLocalDcb->fBinary) + { + DEBUG_WARN("Unexpected nonbinary mode, consider to unset the ICANON flag."); + } - lpLocalDcb->fParity = (currentState.c_cflag & PARENB) != 0; + lpLocalDcb->fParity = (currentState.c_iflag & INPCK) != 0; /* TMP: TODO: */ /* (...) */ @@ -349,21 +353,24 @@ BOOL SetCommState(HANDLE hFile, LPDCB lpDCB) return FALSE; } - if (!lpDCB->fBinary) + if (lpDCB->fBinary) { - DEBUG_WARN("unexpected nonbinary mode transfers"); - SetLastError(ERROR_NOT_SUPPORTED); - return FALSE; - } - // TMP: set the raw mode here? - - if (lpDCB->fParity) - { - upcomingTermios.c_cflag |= PARENB; + upcomingTermios.c_lflag &= ~ICANON; + // TMP: complete the raw mode here? } else { - upcomingTermios.c_cflag &= ~PARENB; + upcomingTermios.c_lflag |= ICANON; + DEBUG_WARN("Unexpected nonbinary mode, consider to unset the ICANON flag."); + } + + if (lpDCB->fParity) + { + upcomingTermios.c_iflag |= INPCK; + } + else + { + upcomingTermios.c_iflag &= ~INPCK; } // TMP: TODO: