Commit 898ab8da authored by Kirill Zhumarin's avatar Kirill Zhumarin Committed by Alexandre Julliard

ntdll: Use termios2 for serial when possible.

parent b5b22136
...@@ -7890,6 +7890,12 @@ then : ...@@ -7890,6 +7890,12 @@ then :
printf "%s\n" "#define HAVE_ARPA_NAMESER_H 1" >>confdefs.h printf "%s\n" "#define HAVE_ARPA_NAMESER_H 1" >>confdefs.h
fi fi
ac_fn_c_check_header_compile "$LINENO" "asm/termbits.h" "ac_cv_header_asm_termbits_h" "$ac_includes_default"
if test "x$ac_cv_header_asm_termbits_h" = xyes
then :
printf "%s\n" "#define HAVE_ASM_TERMBITS_H 1" >>confdefs.h
fi
ac_fn_c_check_header_compile "$LINENO" "asm/types.h" "ac_cv_header_asm_types_h" "$ac_includes_default" ac_fn_c_check_header_compile "$LINENO" "asm/types.h" "ac_cv_header_asm_types_h" "$ac_includes_default"
if test "x$ac_cv_header_asm_types_h" = xyes if test "x$ac_cv_header_asm_types_h" = xyes
then : then :
......
...@@ -368,6 +368,7 @@ AC_CHECK_HEADERS(\ ...@@ -368,6 +368,7 @@ AC_CHECK_HEADERS(\
OpenCL/opencl.h \ OpenCL/opencl.h \
arpa/inet.h \ arpa/inet.h \
arpa/nameser.h \ arpa/nameser.h \
asm/termbits.h \
asm/types.h \ asm/types.h \
asm/user.h \ asm/user.h \
elf.h \ elf.h \
......
...@@ -31,7 +31,11 @@ ...@@ -31,7 +31,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <termios.h> #ifdef HAVE_ASM_TERMBITS_H
# include <asm/termbits.h>
#else
# include <termios.h>
#endif
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -119,6 +123,18 @@ static const char* iocode2str(UINT ioc) ...@@ -119,6 +123,18 @@ static const char* iocode2str(UINT ioc)
static NTSTATUS get_baud_rate(int fd, SERIAL_BAUD_RATE* sbr) static NTSTATUS get_baud_rate(int fd, SERIAL_BAUD_RATE* sbr)
{ {
#ifdef HAVE_ASM_TERMBITS_H
struct termios2 port;
if (ioctl(fd, TCGETS2, &port) == -1)
{
ERR("ioctl TCGETS2 error '%s'\n", strerror(errno));
return errno_to_status( errno );
}
/* TERMIOS2 supports separate input and output baudrate, but wine supports only the common baudrate. */
sbr->BaudRate = port.c_ospeed;
#else
struct termios port; struct termios port;
int speed; int speed;
...@@ -192,12 +208,22 @@ static NTSTATUS get_baud_rate(int fd, SERIAL_BAUD_RATE* sbr) ...@@ -192,12 +208,22 @@ static NTSTATUS get_baud_rate(int fd, SERIAL_BAUD_RATE* sbr)
ERR("unknown speed %x\n", speed); ERR("unknown speed %x\n", speed);
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
#endif
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
static NTSTATUS get_hand_flow(int fd, SERIAL_HANDFLOW* shf) static NTSTATUS get_hand_flow(int fd, SERIAL_HANDFLOW* shf)
{ {
int stat = 0; int stat = 0;
#ifdef HAVE_ASM_TERMBITS_H
struct termios2 port;
if (ioctl(fd, TCGETS2, &port) == -1)
{
ERR("ioctl TCGETS2 error '%s'\n", strerror(errno));
return errno_to_status( errno );
}
#else
struct termios port; struct termios port;
if (tcgetattr(fd, &port) == -1) if (tcgetattr(fd, &port) == -1)
...@@ -205,6 +231,7 @@ static NTSTATUS get_hand_flow(int fd, SERIAL_HANDFLOW* shf) ...@@ -205,6 +231,7 @@ static NTSTATUS get_hand_flow(int fd, SERIAL_HANDFLOW* shf)
ERR("tcgetattr error '%s'\n", strerror(errno)); ERR("tcgetattr error '%s'\n", strerror(errno));
return errno_to_status( errno ); return errno_to_status( errno );
} }
#endif
/* termios does not support DTR/DSR flow control */ /* termios does not support DTR/DSR flow control */
shf->ControlHandShake = 0; shf->ControlHandShake = 0;
shf->FlowReplace = 0; shf->FlowReplace = 0;
...@@ -250,6 +277,15 @@ static NTSTATUS get_hand_flow(int fd, SERIAL_HANDFLOW* shf) ...@@ -250,6 +277,15 @@ static NTSTATUS get_hand_flow(int fd, SERIAL_HANDFLOW* shf)
static NTSTATUS get_line_control(int fd, SERIAL_LINE_CONTROL* slc) static NTSTATUS get_line_control(int fd, SERIAL_LINE_CONTROL* slc)
{ {
#ifdef HAVE_ASM_TERMBITS_H
struct termios2 port;
if (ioctl(fd, TCGETS2, &port) == -1)
{
ERR("ioctl TCGETS2 error '%s'\n", strerror(errno));
return errno_to_status( errno );
}
#else
struct termios port; struct termios port;
if (tcgetattr(fd, &port) == -1) if (tcgetattr(fd, &port) == -1)
...@@ -257,6 +293,7 @@ static NTSTATUS get_line_control(int fd, SERIAL_LINE_CONTROL* slc) ...@@ -257,6 +293,7 @@ static NTSTATUS get_line_control(int fd, SERIAL_LINE_CONTROL* slc)
ERR("tcgetattr error '%s'\n", strerror(errno)); ERR("tcgetattr error '%s'\n", strerror(errno));
return errno_to_status( errno ); return errno_to_status( errno );
} }
#endif
#ifdef CMSPAR #ifdef CMSPAR
switch (port.c_cflag & (PARENB | PARODD | CMSPAR)) switch (port.c_cflag & (PARENB | PARODD | CMSPAR))
...@@ -356,6 +393,15 @@ static NTSTATUS get_properties(int fd, SERIAL_COMMPROP *prop) ...@@ -356,6 +393,15 @@ static NTSTATUS get_properties(int fd, SERIAL_COMMPROP *prop)
static NTSTATUS get_special_chars(int fd, SERIAL_CHARS* sc) static NTSTATUS get_special_chars(int fd, SERIAL_CHARS* sc)
{ {
#ifdef HAVE_ASM_TERMBITS_H
struct termios2 port;
if (ioctl(fd, TCGETS2, &port) == -1)
{
ERR("ioctl TCGETS2 error '%s'\n", strerror(errno));
return errno_to_status( errno );
}
#else
struct termios port; struct termios port;
if (tcgetattr(fd, &port) == -1) if (tcgetattr(fd, &port) == -1)
...@@ -363,6 +409,8 @@ static NTSTATUS get_special_chars(int fd, SERIAL_CHARS* sc) ...@@ -363,6 +409,8 @@ static NTSTATUS get_special_chars(int fd, SERIAL_CHARS* sc)
ERR("tcgetattr error '%s'\n", strerror(errno)); ERR("tcgetattr error '%s'\n", strerror(errno));
return errno_to_status( errno ); return errno_to_status( errno );
} }
#endif
sc->EofChar = port.c_cc[VEOF]; sc->EofChar = port.c_cc[VEOF];
sc->ErrorChar = 0xFF; sc->ErrorChar = 0xFF;
sc->BreakChar = 0; /* FIXME */ sc->BreakChar = 0; /* FIXME */
...@@ -444,15 +492,45 @@ static NTSTATUS purge(int fd, DWORD flags) ...@@ -444,15 +492,45 @@ static NTSTATUS purge(int fd, DWORD flags)
** Perhaps if we had our own internal queues, one flushes them ** Perhaps if we had our own internal queues, one flushes them
** and the other flushes the kernel's buffers. ** and the other flushes the kernel's buffers.
*/ */
#ifdef HAVE_ASM_TERMBITS_H
if (flags & PURGE_TXABORT) ioctl(fd, TCFLSH, TCOFLUSH);
if (flags & PURGE_RXABORT) ioctl(fd, TCFLSH, TCIFLUSH);
if (flags & PURGE_TXCLEAR) ioctl(fd, TCFLSH, TCOFLUSH);
if (flags & PURGE_RXCLEAR) ioctl(fd, TCFLSH, TCIFLUSH);
#else
if (flags & PURGE_TXABORT) tcflush(fd, TCOFLUSH); if (flags & PURGE_TXABORT) tcflush(fd, TCOFLUSH);
if (flags & PURGE_RXABORT) tcflush(fd, TCIFLUSH); if (flags & PURGE_RXABORT) tcflush(fd, TCIFLUSH);
if (flags & PURGE_TXCLEAR) tcflush(fd, TCOFLUSH); if (flags & PURGE_TXCLEAR) tcflush(fd, TCOFLUSH);
if (flags & PURGE_RXCLEAR) tcflush(fd, TCIFLUSH); if (flags & PURGE_RXCLEAR) tcflush(fd, TCIFLUSH);
#endif
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
static NTSTATUS set_baud_rate(int fd, const SERIAL_BAUD_RATE* sbr) static NTSTATUS set_baud_rate(int fd, const SERIAL_BAUD_RATE* sbr)
{ {
#ifdef HAVE_ASM_TERMBITS_H
struct termios2 port;
if (ioctl(fd, TCGETS2, &port) == -1)
{
ERR("ioctl TCGETS2 error '%s'\n", strerror(errno));
return errno_to_status( errno );
}
port.c_cflag &= ~CBAUD;
port.c_cflag |= BOTHER;
port.c_ospeed = sbr->BaudRate;
port.c_cflag &= ~(CBAUD << IBSHIFT);
port.c_cflag |= BOTHER << IBSHIFT;
port.c_ispeed = sbr->BaudRate;
if (ioctl(fd, TCSETS2, &port) == -1)
{
ERR("ioctl TCSETS2 error '%s'\n", strerror(errno));
return errno_to_status( errno );
}
#else
struct termios port; struct termios port;
if (tcgetattr(fd, &port) == -1) if (tcgetattr(fd, &port) == -1)
...@@ -564,6 +642,7 @@ static NTSTATUS set_baud_rate(int fd, const SERIAL_BAUD_RATE* sbr) ...@@ -564,6 +642,7 @@ static NTSTATUS set_baud_rate(int fd, const SERIAL_BAUD_RATE* sbr)
ERR("tcsetattr error '%s'\n", strerror(errno)); ERR("tcsetattr error '%s'\n", strerror(errno));
return errno_to_status( errno ); return errno_to_status( errno );
} }
#endif
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -583,17 +662,29 @@ static int whack_modem(int fd, unsigned int andy, unsigned int orrie) ...@@ -583,17 +662,29 @@ static int whack_modem(int fd, unsigned int andy, unsigned int orrie)
static NTSTATUS set_handflow(int fd, const SERIAL_HANDFLOW* shf) static NTSTATUS set_handflow(int fd, const SERIAL_HANDFLOW* shf)
{ {
#ifdef HAVE_ASM_TERMBITS_H
struct termios2 port;
#else
struct termios port; struct termios port;
#endif
if ((shf->FlowReplace & (SERIAL_RTS_CONTROL | SERIAL_RTS_HANDSHAKE)) == if ((shf->FlowReplace & (SERIAL_RTS_CONTROL | SERIAL_RTS_HANDSHAKE)) ==
(SERIAL_RTS_CONTROL | SERIAL_RTS_HANDSHAKE)) (SERIAL_RTS_CONTROL | SERIAL_RTS_HANDSHAKE))
return STATUS_NOT_SUPPORTED; return STATUS_NOT_SUPPORTED;
#ifdef HAVE_ASM_TERMBITS_H
if (ioctl(fd, TCGETS2, &port) == -1)
{
ERR("ioctl TCGETS2 error '%s'\n", strerror(errno));
return errno_to_status( errno );
}
#else
if (tcgetattr(fd, &port) == -1) if (tcgetattr(fd, &port) == -1)
{ {
ERR("tcgetattr error '%s'\n", strerror(errno)); ERR("tcgetattr error '%s'\n", strerror(errno));
return errno_to_status( errno ); return errno_to_status( errno );
} }
#endif
#ifdef CRTSCTS #ifdef CRTSCTS
if ((shf->ControlHandShake & SERIAL_CTS_HANDSHAKE) || if ((shf->ControlHandShake & SERIAL_CTS_HANDSHAKE) ||
...@@ -632,25 +723,44 @@ static NTSTATUS set_handflow(int fd, const SERIAL_HANDFLOW* shf) ...@@ -632,25 +723,44 @@ static NTSTATUS set_handflow(int fd, const SERIAL_HANDFLOW* shf)
port.c_iflag |= IXON; port.c_iflag |= IXON;
else else
port.c_iflag &= ~IXON; port.c_iflag &= ~IXON;
#ifdef HAVE_ASM_TERMBITS_H
if (ioctl(fd, TCSETS2, &port) == -1)
{
ERR("ioctl TCSETS2 error '%s'\n", strerror(errno));
return errno_to_status( errno );
}
#else
if (tcsetattr(fd, TCSANOW, &port) == -1) if (tcsetattr(fd, TCSANOW, &port) == -1)
{ {
ERR("tcsetattr error '%s'\n", strerror(errno)); ERR("tcsetattr error '%s'\n", strerror(errno));
return errno_to_status( errno ); return errno_to_status( errno );
} }
#endif
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
static NTSTATUS set_line_control(int fd, const SERIAL_LINE_CONTROL* slc) static NTSTATUS set_line_control(int fd, const SERIAL_LINE_CONTROL* slc)
{ {
struct termios port;
unsigned bytesize, stopbits; unsigned bytesize, stopbits;
#ifdef HAVE_ASM_TERMBITS_H
struct termios2 port;
if (ioctl(fd, TCGETS2, &port) == -1)
{
ERR("ioctl TCGETS2 error '%s'\n", strerror(errno));
return errno_to_status( errno );
}
#else
struct termios port;
if (tcgetattr(fd, &port) == -1) if (tcgetattr(fd, &port) == -1)
{ {
ERR("tcgetattr error '%s'\n", strerror(errno)); ERR("tcgetattr error '%s'\n", strerror(errno));
return errno_to_status( errno ); return errno_to_status( errno );
} }
#endif
#ifdef IMAXBEL #ifdef IMAXBEL
port.c_iflag &= ~(ISTRIP|BRKINT|IGNCR|ICRNL|INLCR|PARMRK|IMAXBEL); port.c_iflag &= ~(ISTRIP|BRKINT|IGNCR|ICRNL|INLCR|PARMRK|IMAXBEL);
...@@ -745,11 +855,19 @@ static NTSTATUS set_line_control(int fd, const SERIAL_LINE_CONTROL* slc) ...@@ -745,11 +855,19 @@ static NTSTATUS set_line_control(int fd, const SERIAL_LINE_CONTROL* slc)
return STATUS_NOT_SUPPORTED; return STATUS_NOT_SUPPORTED;
} }
/* otherwise it hangs with pending input*/ /* otherwise it hangs with pending input*/
#ifdef HAVE_ASM_TERMBITS_H
if (ioctl(fd, TCSETS2, &port) == -1)
{
ERR("ioctl TCSETS2 error '%s'\n", strerror(errno));
return errno_to_status( errno );
}
#else
if (tcsetattr(fd, TCSANOW, &port) == -1) if (tcsetattr(fd, TCSANOW, &port) == -1)
{ {
ERR("tcsetattr error '%s'\n", strerror(errno)); ERR("tcsetattr error '%s'\n", strerror(errno));
return errno_to_status( errno ); return errno_to_status( errno );
} }
#endif
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -761,6 +879,15 @@ static NTSTATUS set_queue_size(int fd, const SERIAL_QUEUE_SIZE* sqs) ...@@ -761,6 +879,15 @@ static NTSTATUS set_queue_size(int fd, const SERIAL_QUEUE_SIZE* sqs)
static NTSTATUS set_special_chars(int fd, const SERIAL_CHARS* sc) static NTSTATUS set_special_chars(int fd, const SERIAL_CHARS* sc)
{ {
#ifdef HAVE_ASM_TERMBITS_H
struct termios2 port;
if (ioctl(fd, TCGETS2, &port) == -1)
{
ERR("ioctl TCGETS2 error '%s'\n", strerror(errno));
return errno_to_status( errno );
}
#else
struct termios port; struct termios port;
if (tcgetattr(fd, &port) == -1) if (tcgetattr(fd, &port) == -1)
...@@ -768,6 +895,7 @@ static NTSTATUS set_special_chars(int fd, const SERIAL_CHARS* sc) ...@@ -768,6 +895,7 @@ static NTSTATUS set_special_chars(int fd, const SERIAL_CHARS* sc)
ERR("tcgetattr error '%s'\n", strerror(errno)); ERR("tcgetattr error '%s'\n", strerror(errno));
return errno_to_status( errno ); return errno_to_status( errno );
} }
#endif
port.c_cc[VEOF ] = sc->EofChar; port.c_cc[VEOF ] = sc->EofChar;
/* FIXME: sc->ErrorChar is not supported */ /* FIXME: sc->ErrorChar is not supported */
...@@ -776,11 +904,19 @@ static NTSTATUS set_special_chars(int fd, const SERIAL_CHARS* sc) ...@@ -776,11 +904,19 @@ static NTSTATUS set_special_chars(int fd, const SERIAL_CHARS* sc)
port.c_cc[VSTART] = sc->XonChar; port.c_cc[VSTART] = sc->XonChar;
port.c_cc[VSTOP ] = sc->XoffChar; port.c_cc[VSTOP ] = sc->XoffChar;
#ifdef HAVE_ASM_TERMBITS_H
if (ioctl(fd, TCSETS2, &port) == -1)
{
ERR("ioctl TCSETS2 error '%s'\n", strerror(errno));
return errno_to_status( errno );
}
#else
if (tcsetattr(fd, TCSANOW, &port) == -1) if (tcsetattr(fd, TCSANOW, &port) == -1)
{ {
ERR("tcsetattr error '%s'\n", strerror(errno)); ERR("tcsetattr error '%s'\n", strerror(errno));
return errno_to_status( errno ); return errno_to_status( errno );
} }
#endif
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -789,10 +925,18 @@ static NTSTATUS set_special_chars(int fd, const SERIAL_CHARS* sc) ...@@ -789,10 +925,18 @@ static NTSTATUS set_special_chars(int fd, const SERIAL_CHARS* sc)
*/ */
static NTSTATUS set_XOff(int fd) static NTSTATUS set_XOff(int fd)
{ {
#ifdef HAVE_ASM_TERMBITS_H
if (ioctl(fd, TCXONC, TCOOFF) == -1)
{
ERR("ioctl TCXONC error '%s'\n", strerror(errno));
return errno_to_status( errno );
}
#else
if (tcflow(fd, TCOOFF)) if (tcflow(fd, TCOOFF))
{ {
return errno_to_status( errno ); return errno_to_status( errno );
} }
#endif
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -801,10 +945,18 @@ static NTSTATUS set_XOff(int fd) ...@@ -801,10 +945,18 @@ static NTSTATUS set_XOff(int fd)
*/ */
static NTSTATUS set_XOn(int fd) static NTSTATUS set_XOn(int fd)
{ {
#ifdef HAVE_ASM_TERMBITS_H
if (ioctl(fd, TCXONC, TCOON) == -1)
{
ERR("ioctl TCXONC error '%s'\n", strerror(errno));
return errno_to_status( errno );
}
#else
if (tcflow(fd, TCOON)) if (tcflow(fd, TCOON))
{ {
return errno_to_status( errno ); return errno_to_status( errno );
} }
#endif
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
...@@ -1364,7 +1516,7 @@ NTSTATUS serial_DeviceIoControl( HANDLE device, HANDLE event, PIO_APC_ROUTINE ap ...@@ -1364,7 +1516,7 @@ NTSTATUS serial_DeviceIoControl( HANDLE device, HANDLE event, PIO_APC_ROUTINE ap
NTSTATUS serial_FlushBuffersFile( int fd ) NTSTATUS serial_FlushBuffersFile( int fd )
{ {
#ifdef HAVE_TCDRAIN #if defined(HAVE_TCDRAIN) && !defined(HAVE_ASM_TERMBITS_H)
while (tcdrain( fd ) == -1) while (tcdrain( fd ) == -1)
{ {
if (errno != EINTR) return errno_to_status( errno ); if (errno != EINTR) return errno_to_status( errno );
......
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
/* Define to 1 if you have the <arpa/nameser.h> header file. */ /* Define to 1 if you have the <arpa/nameser.h> header file. */
#undef HAVE_ARPA_NAMESER_H #undef HAVE_ARPA_NAMESER_H
/* Define to 1 if you have the <asm/termbits.h> header file. */
#undef HAVE_ASM_TERMBITS_H
/* Define to 1 if you have the <asm/types.h> header file. */ /* Define to 1 if you have the <asm/types.h> header file. */
#undef HAVE_ASM_TYPES_H #undef HAVE_ASM_TYPES_H
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment