2006-01-12 13:32:51 +01:00
|
|
|
/* Main file for COMM support
|
|
|
|
*
|
|
|
|
* DEC 93 Erik Bos <erik@xs4all.nl>
|
|
|
|
* Copyright 1996 Marcus Meissner
|
2006-09-30 21:20:41 +02:00
|
|
|
* Copyright 2005,2006 Eric Pouech
|
2006-01-12 13:32:51 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2006-01-12 13:32:51 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#ifdef HAVE_TERMIOS_H
|
|
|
|
#include <termios.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
#include <fcntl.h>
|
|
|
|
#ifdef HAVE_SYS_STAT_H
|
|
|
|
# include <sys/stat.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/types.h>
|
|
|
|
#ifdef HAVE_SYS_FILIO_H
|
|
|
|
# include <sys/filio.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_POLL_H
|
|
|
|
# include <sys/poll.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_MODEM_H
|
|
|
|
# include <sys/modem.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_STRTIO_H
|
|
|
|
# include <sys/strtio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2015-03-14 03:38:17 +01:00
|
|
|
#define NONAMELESSUNION
|
2006-01-12 13:32:51 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "winioctl.h"
|
|
|
|
#include "ddk/ntddser.h"
|
|
|
|
#include "ntdll_misc.h"
|
|
|
|
#include "wine/server.h"
|
|
|
|
#include "wine/library.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_LINUX_SERIAL_H
|
2009-01-03 20:49:30 +01:00
|
|
|
#ifdef HAVE_ASM_TYPES_H
|
|
|
|
#include <asm/types.h>
|
|
|
|
#endif
|
2006-01-12 13:32:51 +01:00
|
|
|
#include <linux/serial.h>
|
|
|
|
#endif
|
|
|
|
|
2006-09-30 21:20:41 +02:00
|
|
|
#if !defined(TIOCINQ) && defined(FIONREAD)
|
|
|
|
#define TIOCINQ FIONREAD
|
|
|
|
#endif
|
|
|
|
|
2006-01-12 13:32:51 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(comm);
|
|
|
|
|
|
|
|
static const char* iocode2str(DWORD ioc)
|
|
|
|
{
|
|
|
|
switch (ioc)
|
|
|
|
{
|
2008-12-24 19:13:15 +01:00
|
|
|
#define X(x) case (x): return #x
|
2006-01-12 13:32:51 +01:00
|
|
|
X(IOCTL_SERIAL_CLEAR_STATS);
|
|
|
|
X(IOCTL_SERIAL_CLR_DTR);
|
|
|
|
X(IOCTL_SERIAL_CLR_RTS);
|
|
|
|
X(IOCTL_SERIAL_CONFIG_SIZE);
|
|
|
|
X(IOCTL_SERIAL_GET_BAUD_RATE);
|
|
|
|
X(IOCTL_SERIAL_GET_CHARS);
|
|
|
|
X(IOCTL_SERIAL_GET_COMMSTATUS);
|
|
|
|
X(IOCTL_SERIAL_GET_DTRRTS);
|
|
|
|
X(IOCTL_SERIAL_GET_HANDFLOW);
|
|
|
|
X(IOCTL_SERIAL_GET_LINE_CONTROL);
|
|
|
|
X(IOCTL_SERIAL_GET_MODEM_CONTROL);
|
|
|
|
X(IOCTL_SERIAL_GET_MODEMSTATUS);
|
|
|
|
X(IOCTL_SERIAL_GET_PROPERTIES);
|
|
|
|
X(IOCTL_SERIAL_GET_STATS);
|
|
|
|
X(IOCTL_SERIAL_GET_TIMEOUTS);
|
|
|
|
X(IOCTL_SERIAL_GET_WAIT_MASK);
|
|
|
|
X(IOCTL_SERIAL_IMMEDIATE_CHAR);
|
|
|
|
X(IOCTL_SERIAL_LSRMST_INSERT);
|
|
|
|
X(IOCTL_SERIAL_PURGE);
|
|
|
|
X(IOCTL_SERIAL_RESET_DEVICE);
|
|
|
|
X(IOCTL_SERIAL_SET_BAUD_RATE);
|
|
|
|
X(IOCTL_SERIAL_SET_BREAK_ON);
|
|
|
|
X(IOCTL_SERIAL_SET_BREAK_OFF);
|
|
|
|
X(IOCTL_SERIAL_SET_CHARS);
|
|
|
|
X(IOCTL_SERIAL_SET_DTR);
|
|
|
|
X(IOCTL_SERIAL_SET_FIFO_CONTROL);
|
|
|
|
X(IOCTL_SERIAL_SET_HANDFLOW);
|
|
|
|
X(IOCTL_SERIAL_SET_LINE_CONTROL);
|
|
|
|
X(IOCTL_SERIAL_SET_MODEM_CONTROL);
|
|
|
|
X(IOCTL_SERIAL_SET_QUEUE_SIZE);
|
|
|
|
X(IOCTL_SERIAL_SET_RTS);
|
|
|
|
X(IOCTL_SERIAL_SET_TIMEOUTS);
|
|
|
|
X(IOCTL_SERIAL_SET_WAIT_MASK);
|
|
|
|
X(IOCTL_SERIAL_SET_XOFF);
|
|
|
|
X(IOCTL_SERIAL_SET_XON);
|
|
|
|
X(IOCTL_SERIAL_WAIT_ON_MASK);
|
|
|
|
X(IOCTL_SERIAL_XOFF_COUNTER);
|
|
|
|
#undef X
|
2006-10-16 13:49:06 +02:00
|
|
|
default: { static char tmp[32]; sprintf(tmp, "IOCTL_SERIAL_%d\n", ioc); return tmp; }
|
2006-01-12 13:32:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-07 14:10:46 +02:00
|
|
|
static NTSTATUS get_baud_rate(int fd, SERIAL_BAUD_RATE* sbr)
|
|
|
|
{
|
|
|
|
struct termios port;
|
|
|
|
int speed;
|
|
|
|
|
|
|
|
if (tcgetattr(fd, &port) == -1)
|
|
|
|
{
|
|
|
|
ERR("tcgetattr error '%s'\n", strerror(errno));
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
speed = cfgetospeed(&port);
|
|
|
|
switch (speed)
|
|
|
|
{
|
|
|
|
case B0: sbr->BaudRate = 0; break;
|
|
|
|
case B50: sbr->BaudRate = 50; break;
|
|
|
|
case B75: sbr->BaudRate = 75; break;
|
|
|
|
case B110: sbr->BaudRate = 110; break;
|
|
|
|
case B134: sbr->BaudRate = 134; break;
|
|
|
|
case B150: sbr->BaudRate = 150; break;
|
|
|
|
case B200: sbr->BaudRate = 200; break;
|
|
|
|
case B300: sbr->BaudRate = 300; break;
|
|
|
|
case B600: sbr->BaudRate = 600; break;
|
|
|
|
case B1200: sbr->BaudRate = 1200; break;
|
|
|
|
case B1800: sbr->BaudRate = 1800; break;
|
|
|
|
case B2400: sbr->BaudRate = 2400; break;
|
|
|
|
case B4800: sbr->BaudRate = 4800; break;
|
|
|
|
case B9600: sbr->BaudRate = 9600; break;
|
|
|
|
case B19200: sbr->BaudRate = 19200; break;
|
|
|
|
case B38400: sbr->BaudRate = 38400; break;
|
|
|
|
#ifdef B57600
|
|
|
|
case B57600: sbr->BaudRate = 57600; break;
|
|
|
|
#endif
|
|
|
|
#ifdef B115200
|
|
|
|
case B115200: sbr->BaudRate = 115200; break;
|
|
|
|
#endif
|
|
|
|
#ifdef B230400
|
|
|
|
case B230400: sbr->BaudRate = 230400; break;
|
|
|
|
#endif
|
|
|
|
#ifdef B460800
|
|
|
|
case B460800: sbr->BaudRate = 460800; break;
|
2015-02-12 17:53:28 +01:00
|
|
|
#endif
|
|
|
|
#ifdef B500000
|
|
|
|
case B500000: sbr->BaudRate = 500000; break;
|
|
|
|
#endif
|
|
|
|
#ifdef B921600
|
|
|
|
case B921600: sbr->BaudRate = 921600; break;
|
|
|
|
#endif
|
|
|
|
#ifdef B1000000
|
|
|
|
case B1000000: sbr->BaudRate = 1000000; break;
|
|
|
|
#endif
|
|
|
|
#ifdef B1152000
|
|
|
|
case B1152000: sbr->BaudRate = 1152000; break;
|
|
|
|
#endif
|
|
|
|
#ifdef B1500000
|
|
|
|
case B1500000: sbr->BaudRate = 1500000; break;
|
|
|
|
#endif
|
|
|
|
#ifdef B2000000
|
|
|
|
case B2000000: sbr->BaudRate = 2000000; break;
|
|
|
|
#endif
|
|
|
|
#ifdef B2500000
|
|
|
|
case B2500000: sbr->BaudRate = 2500000; break;
|
|
|
|
#endif
|
|
|
|
#ifdef B3000000
|
|
|
|
case B3000000: sbr->BaudRate = 3000000; break;
|
|
|
|
#endif
|
|
|
|
#ifdef B3500000
|
|
|
|
case B3500000: sbr->BaudRate = 3500000; break;
|
|
|
|
#endif
|
|
|
|
#ifdef B4000000
|
|
|
|
case B4000000: sbr->BaudRate = 4000000; break;
|
2006-05-07 14:10:46 +02:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
ERR("unknown speed %x\n", speed);
|
|
|
|
return STATUS_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-05-07 14:10:52 +02:00
|
|
|
static NTSTATUS get_hand_flow(int fd, SERIAL_HANDFLOW* shf)
|
|
|
|
{
|
2008-01-21 21:45:18 +01:00
|
|
|
int stat = 0;
|
2006-05-07 14:10:52 +02:00
|
|
|
struct termios port;
|
2008-01-21 21:45:18 +01:00
|
|
|
|
2006-05-07 14:10:52 +02:00
|
|
|
if (tcgetattr(fd, &port) == -1)
|
|
|
|
{
|
|
|
|
ERR("tcgetattr error '%s'\n", strerror(errno));
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
2008-01-21 21:45:18 +01:00
|
|
|
/* termios does not support DTR/DSR flow control */
|
|
|
|
shf->ControlHandShake = 0;
|
|
|
|
shf->FlowReplace = 0;
|
2006-05-07 14:10:52 +02:00
|
|
|
#ifdef TIOCMGET
|
|
|
|
if (ioctl(fd, TIOCMGET, &stat) == -1)
|
|
|
|
{
|
|
|
|
WARN("ioctl error '%s'\n", strerror(errno));
|
2008-01-21 21:45:18 +01:00
|
|
|
shf->ControlHandShake |= SERIAL_DTR_CONTROL;
|
|
|
|
shf->FlowReplace |= SERIAL_RTS_CONTROL;
|
2006-05-07 14:10:52 +02:00
|
|
|
}
|
2008-01-21 21:45:18 +01:00
|
|
|
#else
|
|
|
|
WARN("Setting DTR/RTS to enabled by default\n");
|
|
|
|
shf->ControlHandShake |= SERIAL_DTR_CONTROL;
|
|
|
|
shf->FlowReplace |= SERIAL_RTS_CONTROL;
|
2006-05-07 14:10:52 +02:00
|
|
|
#endif
|
|
|
|
#ifdef TIOCM_DTR
|
|
|
|
if (stat & TIOCM_DTR)
|
|
|
|
#endif
|
|
|
|
shf->ControlHandShake |= SERIAL_DTR_CONTROL;
|
|
|
|
#ifdef CRTSCTS
|
|
|
|
if (port.c_cflag & CRTSCTS)
|
|
|
|
{
|
2008-01-21 21:45:18 +01:00
|
|
|
shf->FlowReplace |= SERIAL_RTS_CONTROL;
|
2006-05-07 14:10:52 +02:00
|
|
|
shf->ControlHandShake |= SERIAL_CTS_HANDSHAKE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
#ifdef TIOCM_RTS
|
|
|
|
if (stat & TIOCM_RTS)
|
|
|
|
#endif
|
2008-01-21 21:45:18 +01:00
|
|
|
shf->FlowReplace |= SERIAL_RTS_CONTROL;
|
2006-05-07 14:10:52 +02:00
|
|
|
}
|
|
|
|
if (port.c_iflag & IXOFF)
|
2007-10-28 21:24:40 +01:00
|
|
|
shf->FlowReplace |= SERIAL_AUTO_RECEIVE;
|
|
|
|
if (port.c_iflag & IXON)
|
2006-05-07 14:10:52 +02:00
|
|
|
shf->FlowReplace |= SERIAL_AUTO_TRANSMIT;
|
|
|
|
|
|
|
|
shf->XonLimit = 10;
|
|
|
|
shf->XoffLimit = 10;
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-05-07 14:10:49 +02:00
|
|
|
static NTSTATUS get_line_control(int fd, SERIAL_LINE_CONTROL* slc)
|
|
|
|
{
|
|
|
|
struct termios port;
|
|
|
|
|
|
|
|
if (tcgetattr(fd, &port) == -1)
|
|
|
|
{
|
|
|
|
ERR("tcgetattr error '%s'\n", strerror(errno));
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CMSPAR
|
|
|
|
switch (port.c_cflag & (PARENB | PARODD | CMSPAR))
|
|
|
|
#else
|
|
|
|
switch (port.c_cflag & (PARENB | PARODD))
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
case 0: slc->Parity = NOPARITY; break;
|
|
|
|
case PARENB: slc->Parity = EVENPARITY; break;
|
|
|
|
case PARENB|PARODD: slc->Parity = ODDPARITY; break;
|
|
|
|
#ifdef CMSPAR
|
2019-02-04 09:08:06 +01:00
|
|
|
case PARENB|PARODD|CMSPAR: slc->Parity = MARKPARITY; break;
|
|
|
|
case PARENB|CMSPAR: slc->Parity = SPACEPARITY; break;
|
2006-05-07 14:10:49 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
switch (port.c_cflag & CSIZE)
|
|
|
|
{
|
|
|
|
case CS5: slc->WordLength = 5; break;
|
|
|
|
case CS6: slc->WordLength = 6; break;
|
|
|
|
case CS7: slc->WordLength = 7; break;
|
|
|
|
case CS8: slc->WordLength = 8; break;
|
2008-01-15 20:36:48 +01:00
|
|
|
default: ERR("unknown size %x\n", (UINT)(port.c_cflag & CSIZE));
|
2006-05-07 14:10:49 +02:00
|
|
|
}
|
2008-01-12 17:05:50 +01:00
|
|
|
|
2006-05-07 14:10:49 +02:00
|
|
|
if (port.c_cflag & CSTOPB)
|
|
|
|
{
|
|
|
|
if (slc->WordLength == 5)
|
|
|
|
slc->StopBits = ONE5STOPBITS;
|
|
|
|
else
|
|
|
|
slc->StopBits = TWOSTOPBITS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
slc->StopBits = ONESTOPBIT;
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-02-06 11:37:39 +01:00
|
|
|
static NTSTATUS get_modem_status(int fd, DWORD* lpModemStat)
|
|
|
|
{
|
2008-05-07 21:10:39 +02:00
|
|
|
NTSTATUS status = STATUS_NOT_SUPPORTED;
|
2006-02-06 11:37:39 +01:00
|
|
|
int mstat;
|
|
|
|
|
2008-05-07 21:10:39 +02:00
|
|
|
*lpModemStat = 0;
|
2006-02-06 11:37:39 +01:00
|
|
|
#ifdef TIOCMGET
|
2008-05-07 21:10:39 +02:00
|
|
|
if (!ioctl(fd, TIOCMGET, &mstat))
|
2006-02-06 11:37:39 +01:00
|
|
|
{
|
|
|
|
#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 " : "");
|
2008-05-07 21:10:39 +02:00
|
|
|
return STATUS_SUCCESS;
|
2006-02-06 11:37:39 +01:00
|
|
|
}
|
2013-08-28 09:15:13 +02:00
|
|
|
WARN("TIOCMGET err %s\n", strerror(errno));
|
2008-05-07 21:10:39 +02:00
|
|
|
status = FILE_GetNtStatus();
|
2006-02-06 11:37:39 +01:00
|
|
|
#endif
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2006-05-07 14:10:55 +02:00
|
|
|
static NTSTATUS get_special_chars(int fd, SERIAL_CHARS* sc)
|
|
|
|
{
|
|
|
|
struct termios port;
|
|
|
|
|
|
|
|
if (tcgetattr(fd, &port) == -1)
|
|
|
|
{
|
|
|
|
ERR("tcgetattr error '%s'\n", strerror(errno));
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
sc->EofChar = port.c_cc[VEOF];
|
|
|
|
sc->ErrorChar = 0xFF;
|
|
|
|
sc->BreakChar = 0; /* FIXME */
|
|
|
|
sc->EventChar = 0; /* FIXME */
|
|
|
|
sc->XonChar = port.c_cc[VSTART];
|
|
|
|
sc->XoffChar = port.c_cc[VSTOP];
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-02-27 22:22:06 +01:00
|
|
|
static NTSTATUS get_status(int fd, SERIAL_STATUS* ss)
|
|
|
|
{
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
|
|
|
|
|
|
|
ss->Errors = 0;
|
|
|
|
ss->HoldReasons = 0;
|
|
|
|
ss->EofReceived = FALSE;
|
|
|
|
ss->WaitForImmediate = FALSE;
|
|
|
|
#ifdef TIOCOUTQ
|
|
|
|
if (ioctl(fd, TIOCOUTQ, &ss->AmountInOutQueue) == -1)
|
|
|
|
{
|
|
|
|
WARN("ioctl returned error\n");
|
|
|
|
status = FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
ss->AmountInOutQueue = 0; /* FIXME: find a different way to find out */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TIOCINQ
|
|
|
|
if (ioctl(fd, TIOCINQ, &ss->AmountInInQueue))
|
|
|
|
{
|
|
|
|
WARN("ioctl returned error\n");
|
|
|
|
status = FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
ss->AmountInInQueue = 0; /* FIXME: find a different way to find out */
|
|
|
|
#endif
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2013-10-31 08:58:19 +01:00
|
|
|
static void stop_waiting( HANDLE handle )
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
SERVER_START_REQ( set_serial_info )
|
|
|
|
{
|
|
|
|
req->handle = wine_server_obj_handle( handle );
|
|
|
|
req->flags = SERIALINFO_PENDING_WAIT;
|
|
|
|
if ((status = wine_server_call( req )))
|
|
|
|
ERR("failed to clear waiting state: %#x\n", status);
|
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS get_wait_mask(HANDLE hDevice, DWORD *mask, DWORD *cookie, DWORD *pending_write, BOOL start_wait)
|
2006-02-06 11:37:06 +01:00
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
SERVER_START_REQ( get_serial_info )
|
|
|
|
{
|
2008-12-08 16:05:17 +01:00
|
|
|
req->handle = wine_server_obj_handle( hDevice );
|
2013-10-25 05:14:42 +02:00
|
|
|
req->flags = pending_write ? SERIALINFO_PENDING_WRITE : 0;
|
2013-10-31 08:58:19 +01:00
|
|
|
if (start_wait) req->flags |= SERIALINFO_PENDING_WAIT;
|
2006-02-06 11:37:06 +01:00
|
|
|
if (!(status = wine_server_call( req )))
|
2013-09-10 04:29:57 +02:00
|
|
|
{
|
2006-02-06 11:37:06 +01:00
|
|
|
*mask = reply->eventmask;
|
2013-09-10 04:29:57 +02:00
|
|
|
if (cookie) *cookie = reply->cookie;
|
2013-10-25 05:14:42 +02:00
|
|
|
if (pending_write) *pending_write = reply->pending_write;
|
2013-09-10 04:29:57 +02:00
|
|
|
}
|
2006-02-06 11:37:06 +01:00
|
|
|
}
|
|
|
|
SERVER_END_REQ;
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2006-02-06 11:36:19 +01:00
|
|
|
static NTSTATUS purge(int fd, DWORD flags)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
** not exactly sure how these are different
|
|
|
|
** Perhaps if we had our own internal queues, one flushes them
|
|
|
|
** and the other flushes the kernel's buffers.
|
|
|
|
*/
|
|
|
|
if (flags & PURGE_TXABORT) tcflush(fd, TCOFLUSH);
|
|
|
|
if (flags & PURGE_RXABORT) tcflush(fd, TCIFLUSH);
|
|
|
|
if (flags & PURGE_TXCLEAR) tcflush(fd, TCOFLUSH);
|
|
|
|
if (flags & PURGE_RXCLEAR) tcflush(fd, TCIFLUSH);
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-05-07 14:10:32 +02:00
|
|
|
static NTSTATUS set_baud_rate(int fd, const SERIAL_BAUD_RATE* sbr)
|
|
|
|
{
|
|
|
|
struct termios port;
|
|
|
|
|
|
|
|
if (tcgetattr(fd, &port) == -1)
|
|
|
|
{
|
|
|
|
ERR("tcgetattr error '%s'\n", strerror(errno));
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (sbr->BaudRate)
|
|
|
|
{
|
2010-10-08 11:21:22 +02:00
|
|
|
case 0: cfsetospeed( &port, B0 ); break;
|
|
|
|
case 50: cfsetospeed( &port, B50 ); break;
|
|
|
|
case 75: cfsetospeed( &port, B75 ); break;
|
|
|
|
case 110:
|
|
|
|
case CBR_110: cfsetospeed( &port, B110 ); break;
|
|
|
|
case 134: cfsetospeed( &port, B134 ); break;
|
|
|
|
case 150: cfsetospeed( &port, B150 ); break;
|
|
|
|
case 200: cfsetospeed( &port, B200 ); break;
|
|
|
|
case 300:
|
|
|
|
case CBR_300: cfsetospeed( &port, B300 ); break;
|
2006-05-07 14:10:32 +02:00
|
|
|
case 600:
|
2010-10-08 11:21:22 +02:00
|
|
|
case CBR_600: cfsetospeed( &port, B600 ); break;
|
2006-05-07 14:10:32 +02:00
|
|
|
case 1200:
|
2010-10-08 11:21:22 +02:00
|
|
|
case CBR_1200: cfsetospeed( &port, B1200 ); break;
|
|
|
|
case 1800: cfsetospeed( &port, B1800 ); break;
|
2006-05-07 14:10:32 +02:00
|
|
|
case 2400:
|
2010-10-08 11:21:22 +02:00
|
|
|
case CBR_2400: cfsetospeed( &port, B2400 ); break;
|
2006-05-07 14:10:32 +02:00
|
|
|
case 4800:
|
2010-10-08 11:21:22 +02:00
|
|
|
case CBR_4800: cfsetospeed( &port, B4800 ); break;
|
2006-05-07 14:10:32 +02:00
|
|
|
case 9600:
|
2010-10-08 11:21:22 +02:00
|
|
|
case CBR_9600: cfsetospeed( &port, B9600 ); break;
|
2006-05-07 14:10:32 +02:00
|
|
|
case 19200:
|
2010-10-08 11:21:22 +02:00
|
|
|
case CBR_19200: cfsetospeed( &port, B19200 ); break;
|
2006-05-07 14:10:32 +02:00
|
|
|
case 38400:
|
2010-10-08 11:21:22 +02:00
|
|
|
case CBR_38400: cfsetospeed( &port, B38400 ); break;
|
2006-05-07 14:10:32 +02:00
|
|
|
#ifdef B57600
|
2010-10-08 11:21:22 +02:00
|
|
|
case 57600: cfsetospeed( &port, B57600 ); break;
|
2006-05-07 14:10:32 +02:00
|
|
|
#endif
|
|
|
|
#ifdef B115200
|
2010-10-08 11:21:22 +02:00
|
|
|
case 115200: cfsetospeed( &port, B115200 ); break;
|
2006-05-07 14:10:32 +02:00
|
|
|
#endif
|
|
|
|
#ifdef B230400
|
2010-10-08 11:21:22 +02:00
|
|
|
case 230400: cfsetospeed( &port, B230400 ); break;
|
2006-05-07 14:10:32 +02:00
|
|
|
#endif
|
|
|
|
#ifdef B460800
|
2010-10-08 11:21:22 +02:00
|
|
|
case 460800: cfsetospeed( &port, B460800 ); break;
|
2015-02-12 17:53:28 +01:00
|
|
|
#endif
|
|
|
|
#ifdef B500000
|
|
|
|
case 500000: cfsetospeed( &port, B500000 ); break;
|
|
|
|
#endif
|
|
|
|
#ifdef B921600
|
|
|
|
case 921600: cfsetospeed( &port, B921600 ); break;
|
|
|
|
#endif
|
|
|
|
#ifdef B1000000
|
|
|
|
case 1000000: cfsetospeed( &port, B1000000 ); break;
|
|
|
|
#endif
|
|
|
|
#ifdef B1152000
|
|
|
|
case 1152000: cfsetospeed( &port, B1152000 ); break;
|
|
|
|
#endif
|
|
|
|
#ifdef B1500000
|
|
|
|
case 1500000: cfsetospeed( &port, B1500000 ); break;
|
|
|
|
#endif
|
|
|
|
#ifdef B2000000
|
|
|
|
case 2000000: cfsetospeed( &port, B2000000 ); break;
|
|
|
|
#endif
|
|
|
|
#ifdef B2500000
|
|
|
|
case 2500000: cfsetospeed( &port, B2500000 ); break;
|
|
|
|
#endif
|
|
|
|
#ifdef B3000000
|
|
|
|
case 3000000: cfsetospeed( &port, B3000000 ); break;
|
|
|
|
#endif
|
|
|
|
#ifdef B3500000
|
|
|
|
case 3500000: cfsetospeed( &port, B3500000 ); break;
|
|
|
|
#endif
|
|
|
|
#ifdef B4000000
|
|
|
|
case 4000000: cfsetospeed( &port, B4000000 ); break;
|
2006-05-07 14:10:32 +02:00
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
#if defined (HAVE_LINUX_SERIAL_H) && defined (TIOCSSERIAL)
|
|
|
|
{
|
|
|
|
struct serial_struct nuts;
|
|
|
|
int arby;
|
|
|
|
|
|
|
|
ioctl(fd, TIOCGSERIAL, &nuts);
|
|
|
|
nuts.custom_divisor = nuts.baud_base / sbr->BaudRate;
|
|
|
|
if (!(nuts.custom_divisor)) nuts.custom_divisor = 1;
|
|
|
|
arby = nuts.baud_base / nuts.custom_divisor;
|
|
|
|
nuts.flags &= ~ASYNC_SPD_MASK;
|
|
|
|
nuts.flags |= ASYNC_SPD_CUST;
|
|
|
|
WARN("You (or a program acting at your behest) have specified\n"
|
2006-10-16 13:49:06 +02:00
|
|
|
"a non-standard baud rate %d. Wine will set the rate to %d,\n"
|
2006-05-07 14:10:32 +02:00
|
|
|
"which is as close as we can get by our present understanding of your\n"
|
|
|
|
"hardware. I hope you know what you are doing. Any disruption Wine\n"
|
2009-03-08 23:48:03 +01:00
|
|
|
"has caused to your linux system can be undone with setserial\n"
|
2006-05-07 14:10:32 +02:00
|
|
|
"(see man setserial). If you have incapacitated a Hayes type modem,\n"
|
|
|
|
"reset it and it will probably recover.\n", sbr->BaudRate, arby);
|
|
|
|
ioctl(fd, TIOCSSERIAL, &nuts);
|
2010-10-08 11:21:22 +02:00
|
|
|
cfsetospeed( &port, B38400 );
|
2006-05-07 14:10:32 +02:00
|
|
|
}
|
|
|
|
break;
|
2007-07-18 22:21:49 +02:00
|
|
|
#else /* Don't have linux/serial.h or lack TIOCSSERIAL */
|
2006-10-16 13:49:06 +02:00
|
|
|
ERR("baudrate %d\n", sbr->BaudRate);
|
2006-05-07 14:10:32 +02:00
|
|
|
return STATUS_NOT_SUPPORTED;
|
2007-07-18 22:21:49 +02:00
|
|
|
#endif /* Don't have linux/serial.h or lack TIOCSSERIAL */
|
2006-05-07 14:10:32 +02:00
|
|
|
}
|
2010-10-08 11:21:22 +02:00
|
|
|
cfsetispeed( &port, cfgetospeed(&port) );
|
2006-05-07 14:10:32 +02:00
|
|
|
if (tcsetattr(fd, TCSANOW, &port) == -1)
|
|
|
|
{
|
|
|
|
ERR("tcsetattr error '%s'\n", strerror(errno));
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-05-07 14:10:39 +02:00
|
|
|
static int whack_modem(int fd, unsigned int andy, unsigned int orrie)
|
|
|
|
{
|
|
|
|
#ifdef TIOCMGET
|
|
|
|
unsigned int mstat, okay;
|
|
|
|
okay = ioctl(fd, TIOCMGET, &mstat);
|
|
|
|
if (okay) return okay;
|
|
|
|
if (andy) mstat &= andy;
|
|
|
|
mstat |= orrie;
|
|
|
|
return ioctl(fd, TIOCMSET, &mstat);
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static NTSTATUS set_handflow(int fd, const SERIAL_HANDFLOW* shf)
|
|
|
|
{
|
|
|
|
struct termios port;
|
|
|
|
|
|
|
|
if ((shf->FlowReplace & (SERIAL_RTS_CONTROL | SERIAL_RTS_HANDSHAKE)) ==
|
|
|
|
(SERIAL_RTS_CONTROL | SERIAL_RTS_HANDSHAKE))
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
|
|
|
|
if (tcgetattr(fd, &port) == -1)
|
|
|
|
{
|
|
|
|
ERR("tcgetattr error '%s'\n", strerror(errno));
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CRTSCTS
|
|
|
|
if ((shf->ControlHandShake & SERIAL_CTS_HANDSHAKE) ||
|
|
|
|
(shf->FlowReplace & SERIAL_RTS_HANDSHAKE))
|
|
|
|
{
|
|
|
|
port.c_cflag |= CRTSCTS;
|
|
|
|
TRACE("CRTSCTS\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
port.c_cflag &= ~CRTSCTS;
|
|
|
|
#endif
|
|
|
|
#ifdef TIOCM_DTR
|
|
|
|
if (shf->ControlHandShake & SERIAL_DTR_HANDSHAKE)
|
|
|
|
{
|
|
|
|
WARN("DSR/DTR flow control not supported\n");
|
2007-01-01 17:41:52 +01:00
|
|
|
} else if (!(shf->ControlHandShake & SERIAL_DTR_CONTROL))
|
2006-05-07 14:10:39 +02:00
|
|
|
whack_modem(fd, ~TIOCM_DTR, 0);
|
2007-01-01 17:41:52 +01:00
|
|
|
else
|
2006-05-07 14:10:39 +02:00
|
|
|
whack_modem(fd, 0, TIOCM_DTR);
|
|
|
|
#endif
|
|
|
|
#ifdef TIOCM_RTS
|
2007-01-01 17:41:52 +01:00
|
|
|
if (!(shf->ControlHandShake & SERIAL_CTS_HANDSHAKE))
|
2006-05-07 14:10:39 +02:00
|
|
|
{
|
|
|
|
if ((shf->FlowReplace & (SERIAL_RTS_CONTROL|SERIAL_RTS_HANDSHAKE)) == 0)
|
|
|
|
whack_modem(fd, ~TIOCM_RTS, 0);
|
|
|
|
else
|
|
|
|
whack_modem(fd, 0, TIOCM_RTS);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (shf->FlowReplace & SERIAL_AUTO_RECEIVE)
|
|
|
|
port.c_iflag |= IXOFF;
|
|
|
|
else
|
|
|
|
port.c_iflag &= ~IXOFF;
|
2007-10-28 21:24:40 +01:00
|
|
|
if (shf->FlowReplace & SERIAL_AUTO_TRANSMIT)
|
|
|
|
port.c_iflag |= IXON;
|
|
|
|
else
|
|
|
|
port.c_iflag &= ~IXON;
|
2006-05-07 14:10:39 +02:00
|
|
|
if (tcsetattr(fd, TCSANOW, &port) == -1)
|
|
|
|
{
|
|
|
|
ERR("tcsetattr error '%s'\n", strerror(errno));
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-05-07 14:10:36 +02:00
|
|
|
static NTSTATUS set_line_control(int fd, const SERIAL_LINE_CONTROL* slc)
|
|
|
|
{
|
|
|
|
struct termios port;
|
|
|
|
unsigned bytesize, stopbits;
|
2013-09-26 04:52:48 +02:00
|
|
|
|
2006-05-07 14:10:36 +02:00
|
|
|
if (tcgetattr(fd, &port) == -1)
|
|
|
|
{
|
|
|
|
ERR("tcgetattr error '%s'\n", strerror(errno));
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
2013-09-26 04:52:48 +02:00
|
|
|
|
2006-05-07 14:10:36 +02:00
|
|
|
#ifdef IMAXBEL
|
|
|
|
port.c_iflag &= ~(ISTRIP|BRKINT|IGNCR|ICRNL|INLCR|PARMRK|IMAXBEL);
|
|
|
|
#else
|
|
|
|
port.c_iflag &= ~(ISTRIP|BRKINT|IGNCR|ICRNL|INLCR|PARMRK);
|
|
|
|
#endif
|
|
|
|
port.c_iflag |= IGNBRK | INPCK;
|
|
|
|
port.c_oflag &= ~(OPOST);
|
|
|
|
port.c_cflag &= ~(HUPCL);
|
|
|
|
port.c_cflag |= CLOCAL | CREAD;
|
2013-09-26 04:52:48 +02:00
|
|
|
|
2009-01-06 20:40:09 +01:00
|
|
|
/*
|
|
|
|
* on FreeBSD, turning off ICANON does not disable IEXTEN,
|
|
|
|
* so we must turn it off explicitly. No harm done on Linux.
|
|
|
|
*/
|
|
|
|
port.c_lflag &= ~(ICANON|ECHO|ISIG|IEXTEN);
|
2006-05-07 14:10:36 +02:00
|
|
|
port.c_lflag |= NOFLSH;
|
2013-09-26 04:52:48 +02:00
|
|
|
|
2006-05-07 14:10:36 +02:00
|
|
|
bytesize = slc->WordLength;
|
|
|
|
stopbits = slc->StopBits;
|
2013-09-26 04:52:48 +02:00
|
|
|
|
2006-05-07 14:10:36 +02:00
|
|
|
#ifdef CMSPAR
|
|
|
|
port.c_cflag &= ~(PARENB | PARODD | CMSPAR);
|
|
|
|
#else
|
|
|
|
port.c_cflag &= ~(PARENB | PARODD);
|
|
|
|
#endif
|
|
|
|
|
2008-05-07 20:17:32 +02:00
|
|
|
/* make sure that reads don't block */
|
|
|
|
port.c_cc[VMIN] = 0;
|
|
|
|
port.c_cc[VTIME] = 0;
|
|
|
|
|
2006-05-07 14:10:36 +02:00
|
|
|
switch (slc->Parity)
|
|
|
|
{
|
|
|
|
case NOPARITY: port.c_iflag &= ~INPCK; break;
|
|
|
|
case ODDPARITY: port.c_cflag |= PARENB | PARODD; break;
|
|
|
|
case EVENPARITY: port.c_cflag |= PARENB; break;
|
|
|
|
#ifdef CMSPAR
|
|
|
|
/* Linux defines mark/space (stick) parity */
|
2019-02-04 09:08:06 +01:00
|
|
|
case MARKPARITY: port.c_cflag |= PARENB | PARODD | CMSPAR; break;
|
|
|
|
case SPACEPARITY: port.c_cflag |= PARENB | CMSPAR; break;
|
2006-05-07 14:10:36 +02:00
|
|
|
#else
|
|
|
|
/* try the POSIX way */
|
|
|
|
case MARKPARITY:
|
|
|
|
if (slc->StopBits == ONESTOPBIT)
|
|
|
|
{
|
|
|
|
stopbits = TWOSTOPBITS;
|
|
|
|
port.c_iflag &= ~INPCK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-26 04:52:48 +02:00
|
|
|
FIXME("Cannot set MARK Parity\n");
|
2006-05-07 14:10:36 +02:00
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SPACEPARITY:
|
|
|
|
if (slc->WordLength < 8)
|
|
|
|
{
|
|
|
|
bytesize +=1;
|
|
|
|
port.c_iflag &= ~INPCK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-26 04:52:48 +02:00
|
|
|
FIXME("Cannot set SPACE Parity\n");
|
2006-05-07 14:10:36 +02:00
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2013-09-26 04:52:48 +02:00
|
|
|
FIXME("Parity %d is not supported\n", slc->Parity);
|
2006-05-07 14:10:36 +02:00
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
2013-09-26 04:52:48 +02:00
|
|
|
|
2006-05-07 14:10:36 +02:00
|
|
|
port.c_cflag &= ~CSIZE;
|
|
|
|
switch (bytesize)
|
|
|
|
{
|
|
|
|
case 5: port.c_cflag |= CS5; break;
|
|
|
|
case 6: port.c_cflag |= CS6; break;
|
|
|
|
case 7: port.c_cflag |= CS7; break;
|
|
|
|
case 8: port.c_cflag |= CS8; break;
|
|
|
|
default:
|
2013-09-26 04:52:48 +02:00
|
|
|
FIXME("ByteSize %d is not supported\n", bytesize);
|
2006-05-07 14:10:36 +02:00
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
2013-09-26 04:52:48 +02:00
|
|
|
|
2006-05-07 14:10:36 +02:00
|
|
|
switch (stopbits)
|
|
|
|
{
|
|
|
|
case ONESTOPBIT: port.c_cflag &= ~CSTOPB; break;
|
|
|
|
case ONE5STOPBITS: /* will be selected if bytesize is 5 */
|
|
|
|
case TWOSTOPBITS: port.c_cflag |= CSTOPB; break;
|
|
|
|
default:
|
2013-09-26 04:52:48 +02:00
|
|
|
FIXME("StopBits %d is not supported\n", stopbits);
|
2006-05-07 14:10:36 +02:00
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
/* otherwise it hangs with pending input*/
|
|
|
|
if (tcsetattr(fd, TCSANOW, &port) == -1)
|
|
|
|
{
|
|
|
|
ERR("tcsetattr error '%s'\n", strerror(errno));
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-05-07 14:11:02 +02:00
|
|
|
static NTSTATUS set_queue_size(int fd, const SERIAL_QUEUE_SIZE* sqs)
|
|
|
|
{
|
2006-10-16 13:49:06 +02:00
|
|
|
FIXME("insize %d outsize %d unimplemented stub\n", sqs->InSize, sqs->OutSize);
|
2006-05-07 14:11:02 +02:00
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-05-07 14:10:43 +02:00
|
|
|
static NTSTATUS set_special_chars(int fd, const SERIAL_CHARS* sc)
|
|
|
|
{
|
|
|
|
struct termios port;
|
|
|
|
|
|
|
|
if (tcgetattr(fd, &port) == -1)
|
|
|
|
{
|
|
|
|
ERR("tcgetattr error '%s'\n", strerror(errno));
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
|
|
|
|
port.c_cc[VEOF ] = sc->EofChar;
|
|
|
|
/* FIXME: sc->ErrorChar is not supported */
|
|
|
|
/* FIXME: sc->BreakChar is not supported */
|
|
|
|
/* FIXME: sc->EventChar is not supported */
|
|
|
|
port.c_cc[VSTART] = sc->XonChar;
|
|
|
|
port.c_cc[VSTOP ] = sc->XoffChar;
|
|
|
|
|
|
|
|
if (tcsetattr(fd, TCSANOW, &port) == -1)
|
|
|
|
{
|
|
|
|
ERR("tcsetattr error '%s'\n", strerror(errno));
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-12-20 16:56:22 +01:00
|
|
|
/*
|
|
|
|
* does not change IXOFF but simulates that IXOFF has been received:
|
|
|
|
*/
|
2006-05-07 14:11:05 +02:00
|
|
|
static NTSTATUS set_XOff(int fd)
|
|
|
|
{
|
2008-12-20 16:56:22 +01:00
|
|
|
if (tcflow(fd, TCOOFF))
|
2006-05-07 14:11:05 +02:00
|
|
|
{
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2008-12-20 16:56:22 +01:00
|
|
|
/*
|
|
|
|
* does not change IXON but simulates that IXON has been received:
|
|
|
|
*/
|
2006-05-07 14:11:05 +02:00
|
|
|
static NTSTATUS set_XOn(int fd)
|
|
|
|
{
|
2008-12-20 16:56:22 +01:00
|
|
|
if (tcflow(fd, TCOON))
|
2006-05-07 14:11:05 +02:00
|
|
|
{
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-09-30 21:20:41 +02:00
|
|
|
/* serial_irq_info
|
|
|
|
* local structure holding the irq values we need for WaitCommEvent()
|
|
|
|
*
|
|
|
|
* Stripped down from struct serial_icounter_struct, which may not be available on some systems
|
|
|
|
* As the modem line interrupts (cts, dsr, rng, dcd) only get updated with TIOCMIWAIT active,
|
|
|
|
* no need to carry them in the internal structure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
typedef struct serial_irq_info
|
|
|
|
{
|
2013-08-28 05:29:45 +02:00
|
|
|
int rx, tx, frame, overrun, parity, brk, buf_overrun, temt;
|
2006-09-30 21:20:41 +02:00
|
|
|
}serial_irq_info;
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Data needed by the thread polling for the changing CommEvent
|
|
|
|
*/
|
|
|
|
typedef struct async_commio
|
|
|
|
{
|
|
|
|
HANDLE hDevice;
|
|
|
|
DWORD* events;
|
2009-09-04 03:47:32 +02:00
|
|
|
IO_STATUS_BLOCK* iosb;
|
2006-09-30 21:20:41 +02:00
|
|
|
HANDLE hEvent;
|
|
|
|
DWORD evtmask;
|
2013-09-10 04:29:57 +02:00
|
|
|
DWORD cookie;
|
2006-09-30 21:20:41 +02:00
|
|
|
DWORD mstat;
|
2013-10-25 05:14:42 +02:00
|
|
|
DWORD pending_write;
|
2006-09-30 21:20:41 +02:00
|
|
|
serial_irq_info irq_info;
|
|
|
|
} async_commio;
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Get extended interrupt count info, needed for wait_on
|
|
|
|
*/
|
|
|
|
static NTSTATUS get_irq_info(int fd, serial_irq_info *irq_info)
|
|
|
|
{
|
2013-08-27 10:41:10 +02:00
|
|
|
int out;
|
|
|
|
|
2013-07-29 21:08:02 +02:00
|
|
|
#if defined (HAVE_LINUX_SERIAL_H) && defined (TIOCGICOUNT)
|
2006-09-30 21:20:41 +02:00
|
|
|
struct serial_icounter_struct einfo;
|
|
|
|
if (!ioctl(fd, TIOCGICOUNT, &einfo))
|
|
|
|
{
|
|
|
|
irq_info->rx = einfo.rx;
|
|
|
|
irq_info->tx = einfo.tx;
|
|
|
|
irq_info->frame = einfo.frame;
|
|
|
|
irq_info->overrun = einfo.overrun;
|
|
|
|
irq_info->parity = einfo.parity;
|
|
|
|
irq_info->brk = einfo.brk;
|
|
|
|
irq_info->buf_overrun = einfo.buf_overrun;
|
|
|
|
}
|
2011-10-13 11:30:37 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
TRACE("TIOCGICOUNT err %s\n", strerror(errno));
|
|
|
|
memset(irq_info,0, sizeof(serial_irq_info));
|
|
|
|
}
|
|
|
|
#else
|
2008-05-07 21:10:39 +02:00
|
|
|
memset(irq_info,0, sizeof(serial_irq_info));
|
2011-10-13 11:30:37 +02:00
|
|
|
#endif
|
2013-08-27 10:38:23 +02:00
|
|
|
|
2011-10-13 11:30:37 +02:00
|
|
|
irq_info->temt = 0;
|
|
|
|
/* Generate a single TX_TXEMPTY event when the TX Buffer turns empty*/
|
|
|
|
#ifdef TIOCSERGETLSR /* prefer to log the state TIOCSERGETLSR */
|
2013-08-27 10:41:10 +02:00
|
|
|
if (!ioctl(fd, TIOCSERGETLSR, &out))
|
|
|
|
{
|
|
|
|
irq_info->temt = (out & TIOCSER_TEMT) != 0;
|
2013-08-27 10:40:17 +02:00
|
|
|
return STATUS_SUCCESS;
|
2013-08-27 10:41:10 +02:00
|
|
|
}
|
2013-08-27 10:40:17 +02:00
|
|
|
|
|
|
|
TRACE("TIOCSERGETLSR err %s\n", strerror(errno));
|
|
|
|
#endif
|
|
|
|
#ifdef TIOCOUTQ /* otherwise we log when the out queue gets empty */
|
2013-08-29 03:26:24 +02:00
|
|
|
if (!ioctl(fd, TIOCOUTQ, &out))
|
2011-10-13 11:30:37 +02:00
|
|
|
{
|
2013-08-29 03:26:24 +02:00
|
|
|
irq_info->temt = out == 0;
|
|
|
|
return STATUS_SUCCESS;
|
2011-10-13 11:30:37 +02:00
|
|
|
}
|
2013-08-29 03:26:24 +02:00
|
|
|
TRACE("TIOCOUTQ err %s\n", strerror(errno));
|
|
|
|
return FILE_GetNtStatus();
|
2011-10-13 11:30:37 +02:00
|
|
|
#endif
|
|
|
|
return STATUS_SUCCESS;
|
2006-09-30 21:20:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-11-26 17:15:40 +01:00
|
|
|
static DWORD check_events(int fd, DWORD mask,
|
|
|
|
const serial_irq_info *new,
|
|
|
|
const serial_irq_info *old,
|
2013-10-25 05:14:42 +02:00
|
|
|
DWORD new_mstat, DWORD old_mstat, DWORD pending_write)
|
2006-09-30 21:20:41 +02:00
|
|
|
{
|
|
|
|
DWORD ret = 0, queue;
|
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE("mask 0x%08x\n", mask);
|
2006-09-30 21:20:41 +02:00
|
|
|
TRACE("old->rx 0x%08x vs. new->rx 0x%08x\n", old->rx, new->rx);
|
|
|
|
TRACE("old->tx 0x%08x vs. new->tx 0x%08x\n", old->tx, new->tx);
|
|
|
|
TRACE("old->frame 0x%08x vs. new->frame 0x%08x\n", old->frame, new->frame);
|
|
|
|
TRACE("old->overrun 0x%08x vs. new->overrun 0x%08x\n", old->overrun, new->overrun);
|
|
|
|
TRACE("old->parity 0x%08x vs. new->parity 0x%08x\n", old->parity, new->parity);
|
|
|
|
TRACE("old->brk 0x%08x vs. new->brk 0x%08x\n", old->brk, new->brk);
|
|
|
|
TRACE("old->buf_overrun 0x%08x vs. new->buf_overrun 0x%08x\n", old->buf_overrun, new->buf_overrun);
|
2013-08-28 05:29:45 +02:00
|
|
|
TRACE("old->temt 0x%08x vs. new->temt 0x%08x\n", old->temt, new->temt);
|
2006-09-30 21:20:41 +02:00
|
|
|
|
|
|
|
if (old->brk != new->brk) ret |= EV_BREAK;
|
|
|
|
if ((old_mstat & MS_CTS_ON ) != (new_mstat & MS_CTS_ON )) ret |= EV_CTS;
|
|
|
|
if ((old_mstat & MS_DSR_ON ) != (new_mstat & MS_DSR_ON )) ret |= EV_DSR;
|
|
|
|
if ((old_mstat & MS_RING_ON) != (new_mstat & MS_RING_ON)) ret |= EV_RING;
|
|
|
|
if ((old_mstat & MS_RLSD_ON) != (new_mstat & MS_RLSD_ON)) ret |= EV_RLSD;
|
|
|
|
if (old->frame != new->frame || old->overrun != new->overrun || old->parity != new->parity) ret |= EV_ERR;
|
|
|
|
if (mask & EV_RXCHAR)
|
|
|
|
{
|
|
|
|
queue = 0;
|
|
|
|
#ifdef TIOCINQ
|
|
|
|
if (ioctl(fd, TIOCINQ, &queue))
|
|
|
|
WARN("TIOCINQ returned error\n");
|
|
|
|
#endif
|
|
|
|
if (queue)
|
|
|
|
ret |= EV_RXCHAR;
|
|
|
|
}
|
|
|
|
if (mask & EV_TXEMPTY)
|
|
|
|
{
|
2013-10-25 05:14:42 +02:00
|
|
|
if ((!old->temt || pending_write) && new->temt)
|
2011-10-13 11:30:37 +02:00
|
|
|
ret |= EV_TXEMPTY;
|
2006-09-30 21:20:41 +02:00
|
|
|
}
|
|
|
|
return ret & mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* wait_for_event (INTERNAL)
|
|
|
|
*
|
|
|
|
* We need to poll for what is interesting
|
|
|
|
* TIOCMIWAIT only checks modem status line and may not be aborted by a changing mask
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static DWORD CALLBACK wait_for_event(LPVOID arg)
|
|
|
|
{
|
2009-03-17 00:12:11 +01:00
|
|
|
async_commio *commio = arg;
|
2006-11-03 11:38:44 +01:00
|
|
|
int fd, needs_close;
|
2006-09-30 21:20:41 +02:00
|
|
|
|
2006-11-20 14:15:06 +01:00
|
|
|
if (!server_get_unix_fd( commio->hDevice, FILE_READ_DATA | FILE_WRITE_DATA, &fd, &needs_close, NULL, NULL ))
|
2006-09-30 21:20:41 +02:00
|
|
|
{
|
|
|
|
serial_irq_info new_irq_info;
|
2013-09-10 04:29:57 +02:00
|
|
|
DWORD new_mstat, dummy, cookie;
|
2006-09-30 21:20:41 +02:00
|
|
|
LARGE_INTEGER time;
|
2013-09-10 04:29:57 +02:00
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE("device=%p fd=0x%08x mask=0x%08x buffer=%p event=%p irq_info=%p\n",
|
2006-09-30 21:20:41 +02:00
|
|
|
commio->hDevice, fd, commio->evtmask, commio->events, commio->hEvent, &commio->irq_info);
|
|
|
|
|
|
|
|
time.QuadPart = (ULONGLONG)10000;
|
|
|
|
time.QuadPart = -time.QuadPart;
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* TIOCMIWAIT is not adequate
|
|
|
|
*
|
|
|
|
* FIXME:
|
|
|
|
* We don't handle the EV_RXFLAG (the eventchar)
|
|
|
|
*/
|
|
|
|
NtDelayExecution(FALSE, &time);
|
|
|
|
get_irq_info(fd, &new_irq_info);
|
|
|
|
if (get_modem_status(fd, &new_mstat))
|
2013-08-28 09:15:13 +02:00
|
|
|
{
|
2006-09-30 21:20:41 +02:00
|
|
|
TRACE("get_modem_status failed\n");
|
2013-08-28 09:15:13 +02:00
|
|
|
*commio->events = 0;
|
|
|
|
break;
|
|
|
|
}
|
2006-09-30 21:20:41 +02:00
|
|
|
*commio->events = check_events(fd, commio->evtmask,
|
|
|
|
&new_irq_info, &commio->irq_info,
|
2013-10-25 05:14:42 +02:00
|
|
|
new_mstat, commio->mstat, commio->pending_write);
|
2006-09-30 21:20:41 +02:00
|
|
|
if (*commio->events) break;
|
2013-10-31 08:58:19 +01:00
|
|
|
get_wait_mask(commio->hDevice, &dummy, &cookie, (commio->evtmask & EV_TXEMPTY) ? &commio->pending_write : NULL, FALSE);
|
2013-09-10 04:29:57 +02:00
|
|
|
if (commio->cookie != cookie)
|
2006-09-30 21:20:41 +02:00
|
|
|
{
|
|
|
|
*commio->events = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-11-03 11:38:44 +01:00
|
|
|
if (needs_close) close( fd );
|
2006-09-30 21:20:41 +02:00
|
|
|
}
|
2013-09-26 04:51:40 +02:00
|
|
|
if (commio->iosb)
|
|
|
|
{
|
|
|
|
if (*commio->events)
|
|
|
|
{
|
|
|
|
commio->iosb->u.Status = STATUS_SUCCESS;
|
|
|
|
commio->iosb->Information = sizeof(DWORD);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
commio->iosb->u.Status = STATUS_CANCELLED;
|
|
|
|
}
|
2013-10-31 08:58:19 +01:00
|
|
|
stop_waiting(commio->hDevice);
|
2006-11-03 11:38:44 +01:00
|
|
|
if (commio->hEvent) NtSetEvent(commio->hEvent, NULL);
|
2006-09-30 21:20:41 +02:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, commio);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-09-04 03:47:32 +02:00
|
|
|
static NTSTATUS wait_on(HANDLE hDevice, int fd, HANDLE hEvent, PIO_STATUS_BLOCK piosb, DWORD* events)
|
2006-09-30 21:20:41 +02:00
|
|
|
{
|
|
|
|
async_commio* commio;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if ((status = NtResetEvent(hEvent, NULL)))
|
|
|
|
return status;
|
|
|
|
|
|
|
|
commio = RtlAllocateHeap(GetProcessHeap(), 0, sizeof (async_commio));
|
|
|
|
if (!commio) return STATUS_NO_MEMORY;
|
|
|
|
|
|
|
|
commio->hDevice = hDevice;
|
|
|
|
commio->events = events;
|
2009-09-04 03:47:32 +02:00
|
|
|
commio->iosb = piosb;
|
2006-09-30 21:20:41 +02:00
|
|
|
commio->hEvent = hEvent;
|
2013-10-25 05:14:42 +02:00
|
|
|
commio->pending_write = 0;
|
2013-10-31 08:58:19 +01:00
|
|
|
status = get_wait_mask(commio->hDevice, &commio->evtmask, &commio->cookie, (commio->evtmask & EV_TXEMPTY) ? &commio->pending_write : NULL, TRUE);
|
|
|
|
if (status)
|
|
|
|
{
|
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, commio);
|
|
|
|
return status;
|
|
|
|
}
|
2006-09-30 21:20:41 +02:00
|
|
|
|
|
|
|
/* We may never return, if some capabilities miss
|
|
|
|
* Return error in that case
|
|
|
|
*/
|
|
|
|
#if !defined(TIOCINQ)
|
|
|
|
if (commio->evtmask & EV_RXCHAR)
|
|
|
|
goto error_caps;
|
|
|
|
#endif
|
|
|
|
#if !(defined(TIOCSERGETLSR) && defined(TIOCSER_TEMT)) || !defined(TIOCINQ)
|
|
|
|
if (commio->evtmask & EV_TXEMPTY)
|
|
|
|
goto error_caps;
|
|
|
|
#endif
|
|
|
|
#if !defined(TIOCMGET)
|
|
|
|
if (commio->evtmask & (EV_CTS | EV_DSR| EV_RING| EV_RLSD))
|
|
|
|
goto error_caps;
|
|
|
|
#endif
|
|
|
|
#if !defined(TIOCM_CTS)
|
|
|
|
if (commio->evtmask & EV_CTS)
|
|
|
|
goto error_caps;
|
|
|
|
#endif
|
|
|
|
#if !defined(TIOCM_DSR)
|
|
|
|
if (commio->evtmask & EV_DSR)
|
|
|
|
goto error_caps;
|
|
|
|
#endif
|
|
|
|
#if !defined(TIOCM_RNG)
|
|
|
|
if (commio->evtmask & EV_RING)
|
|
|
|
goto error_caps;
|
|
|
|
#endif
|
|
|
|
#if !defined(TIOCM_CAR)
|
|
|
|
if (commio->evtmask & EV_RLSD)
|
|
|
|
goto error_caps;
|
|
|
|
#endif
|
|
|
|
if (commio->evtmask & EV_RXFLAG)
|
|
|
|
FIXME("EV_RXFLAG not handled\n");
|
2008-05-07 21:10:39 +02:00
|
|
|
|
|
|
|
if ((status = get_irq_info(fd, &commio->irq_info)) &&
|
|
|
|
(commio->evtmask & (EV_BREAK | EV_ERR)))
|
|
|
|
goto out_now;
|
|
|
|
|
|
|
|
if ((status = get_modem_status(fd, &commio->mstat)) &&
|
|
|
|
(commio->evtmask & (EV_CTS | EV_DSR| EV_RING| EV_RLSD)))
|
|
|
|
goto out_now;
|
2006-09-30 21:20:41 +02:00
|
|
|
|
2008-04-08 23:22:43 +02:00
|
|
|
/* We might have received something or the TX buffer is delivered */
|
2006-09-30 21:20:41 +02:00
|
|
|
*events = check_events(fd, commio->evtmask,
|
|
|
|
&commio->irq_info, &commio->irq_info,
|
2013-10-25 05:14:42 +02:00
|
|
|
commio->mstat, commio->mstat, commio->pending_write);
|
2008-05-07 21:10:39 +02:00
|
|
|
if (*events)
|
|
|
|
{
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
goto out_now;
|
|
|
|
}
|
2006-09-30 21:20:41 +02:00
|
|
|
|
|
|
|
/* create the worker for the task */
|
|
|
|
status = RtlQueueWorkItem(wait_for_event, commio, 0 /* FIXME */);
|
|
|
|
if (status != STATUS_SUCCESS) goto out_now;
|
|
|
|
return STATUS_PENDING;
|
|
|
|
|
|
|
|
#if !defined(TIOCINQ) || (!(defined(TIOCSERGETLSR) && defined(TIOCSER_TEMT)) || !defined(TIOCINQ)) || !defined(TIOCMGET) || !defined(TIOCM_CTS) ||!defined(TIOCM_DSR) || !defined(TIOCM_RNG) || !defined(TIOCM_CAR)
|
|
|
|
error_caps:
|
|
|
|
FIXME("Returning error because of missing capabilities\n");
|
2006-10-04 22:16:34 +02:00
|
|
|
status = STATUS_INVALID_PARAMETER;
|
2006-09-30 21:20:41 +02:00
|
|
|
#endif
|
|
|
|
out_now:
|
2013-10-31 08:58:19 +01:00
|
|
|
stop_waiting(commio->hDevice);
|
2006-09-30 21:20:41 +02:00
|
|
|
RtlFreeHeap(GetProcessHeap(), 0, commio);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2007-06-25 22:11:38 +02:00
|
|
|
static NTSTATUS xmit_immediate(HANDLE hDevice, int fd, const char* ptr)
|
2006-02-06 11:38:53 +01:00
|
|
|
{
|
|
|
|
/* FIXME: not perfect as it should bypass the in-queue */
|
|
|
|
WARN("(%p,'%c') not perfect!\n", hDevice, *ptr);
|
|
|
|
if (write(fd, ptr, 1) != 1)
|
|
|
|
return FILE_GetNtStatus();
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2006-01-12 13:32:51 +01:00
|
|
|
/******************************************************************
|
|
|
|
* COMM_DeviceIoControl
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2006-09-30 21:20:41 +02:00
|
|
|
static inline NTSTATUS io_control(HANDLE hDevice,
|
|
|
|
HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,
|
|
|
|
PVOID UserApcContext,
|
|
|
|
PIO_STATUS_BLOCK piosb,
|
|
|
|
ULONG dwIoControlCode,
|
|
|
|
LPVOID lpInBuffer, DWORD nInBufferSize,
|
|
|
|
LPVOID lpOutBuffer, DWORD nOutBufferSize)
|
2006-01-12 13:32:51 +01:00
|
|
|
{
|
|
|
|
DWORD sz = 0, access = FILE_READ_DATA;
|
|
|
|
NTSTATUS status = STATUS_SUCCESS;
|
2006-11-03 11:38:44 +01:00
|
|
|
int fd = -1, needs_close = 0;
|
2017-05-05 12:21:09 +02:00
|
|
|
enum server_fd_type type;
|
2006-01-12 13:32:51 +01:00
|
|
|
|
2006-10-16 13:49:06 +02:00
|
|
|
TRACE("%p %s %p %d %p %d %p\n",
|
2006-01-12 13:32:51 +01:00
|
|
|
hDevice, iocode2str(dwIoControlCode), lpInBuffer, nInBufferSize,
|
|
|
|
lpOutBuffer, nOutBufferSize, piosb);
|
|
|
|
|
2017-05-05 12:21:09 +02:00
|
|
|
switch (dwIoControlCode)
|
|
|
|
{
|
|
|
|
case IOCTL_SERIAL_GET_TIMEOUTS:
|
|
|
|
case IOCTL_SERIAL_SET_TIMEOUTS:
|
2017-05-05 12:34:16 +02:00
|
|
|
case IOCTL_SERIAL_GET_WAIT_MASK:
|
2017-05-05 12:28:19 +02:00
|
|
|
case IOCTL_SERIAL_SET_WAIT_MASK:
|
2017-05-05 12:21:09 +02:00
|
|
|
/* these are handled on the server side */
|
|
|
|
return STATUS_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
|
2006-01-12 13:32:51 +01:00
|
|
|
piosb->Information = 0;
|
|
|
|
|
2017-05-05 12:21:09 +02:00
|
|
|
if ((status = server_get_unix_fd( hDevice, access, &fd, &needs_close, &type, NULL )))
|
|
|
|
goto error;
|
|
|
|
if (type != FD_TYPE_SERIAL)
|
2009-09-10 11:06:01 +02:00
|
|
|
{
|
2017-05-05 12:21:09 +02:00
|
|
|
if (needs_close) close( fd );
|
|
|
|
status = STATUS_OBJECT_TYPE_MISMATCH;
|
|
|
|
goto error;
|
2009-09-10 11:06:01 +02:00
|
|
|
}
|
2006-01-12 13:32:51 +01:00
|
|
|
|
|
|
|
switch (dwIoControlCode)
|
|
|
|
{
|
2006-05-07 14:11:05 +02:00
|
|
|
case IOCTL_SERIAL_CLR_DTR:
|
|
|
|
#ifdef TIOCM_DTR
|
|
|
|
if (whack_modem(fd, ~TIOCM_DTR, 0) == -1) status = FILE_GetNtStatus();
|
|
|
|
#else
|
|
|
|
status = STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case IOCTL_SERIAL_CLR_RTS:
|
|
|
|
#ifdef TIOCM_RTS
|
|
|
|
if (whack_modem(fd, ~TIOCM_RTS, 0) == -1) status = FILE_GetNtStatus();
|
|
|
|
#else
|
|
|
|
status = STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
break;
|
2006-05-07 14:10:46 +02:00
|
|
|
case IOCTL_SERIAL_GET_BAUD_RATE:
|
|
|
|
if (lpOutBuffer && nOutBufferSize == sizeof(SERIAL_BAUD_RATE))
|
|
|
|
{
|
2009-03-17 00:12:11 +01:00
|
|
|
if (!(status = get_baud_rate(fd, lpOutBuffer)))
|
2006-05-07 14:10:46 +02:00
|
|
|
sz = sizeof(SERIAL_BAUD_RATE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
2006-05-07 14:10:55 +02:00
|
|
|
case IOCTL_SERIAL_GET_CHARS:
|
|
|
|
if (lpOutBuffer && nOutBufferSize == sizeof(SERIAL_CHARS))
|
|
|
|
{
|
2009-03-17 00:12:11 +01:00
|
|
|
if (!(status = get_special_chars(fd, lpOutBuffer)))
|
2006-05-07 14:10:55 +02:00
|
|
|
sz = sizeof(SERIAL_CHARS);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
2006-05-07 14:10:46 +02:00
|
|
|
case IOCTL_SERIAL_GET_COMMSTATUS:
|
2006-02-27 22:22:06 +01:00
|
|
|
if (lpOutBuffer && nOutBufferSize == sizeof(SERIAL_STATUS))
|
|
|
|
{
|
2009-03-17 00:12:11 +01:00
|
|
|
if (!(status = get_status(fd, lpOutBuffer)))
|
2006-02-27 22:22:06 +01:00
|
|
|
sz = sizeof(SERIAL_STATUS);
|
|
|
|
}
|
|
|
|
else status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
2006-05-07 14:10:52 +02:00
|
|
|
case IOCTL_SERIAL_GET_HANDFLOW:
|
|
|
|
if (lpOutBuffer && nOutBufferSize == sizeof(SERIAL_HANDFLOW))
|
|
|
|
{
|
2009-03-17 00:12:11 +01:00
|
|
|
if (!(status = get_hand_flow(fd, lpOutBuffer)))
|
2006-05-07 14:10:52 +02:00
|
|
|
sz = sizeof(SERIAL_HANDFLOW);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
2006-05-07 14:10:49 +02:00
|
|
|
case IOCTL_SERIAL_GET_LINE_CONTROL:
|
|
|
|
if (lpOutBuffer && nOutBufferSize == sizeof(SERIAL_LINE_CONTROL))
|
|
|
|
{
|
2009-03-17 00:12:11 +01:00
|
|
|
if (!(status = get_line_control(fd, lpOutBuffer)))
|
2006-05-07 14:10:49 +02:00
|
|
|
sz = sizeof(SERIAL_LINE_CONTROL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
2006-02-06 11:37:39 +01:00
|
|
|
case IOCTL_SERIAL_GET_MODEMSTATUS:
|
|
|
|
if (lpOutBuffer && nOutBufferSize == sizeof(DWORD))
|
|
|
|
{
|
2009-03-17 00:12:11 +01:00
|
|
|
if (!(status = get_modem_status(fd, lpOutBuffer)))
|
2006-02-06 11:37:39 +01:00
|
|
|
sz = sizeof(DWORD);
|
|
|
|
}
|
|
|
|
else status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
2006-02-06 11:38:53 +01:00
|
|
|
case IOCTL_SERIAL_IMMEDIATE_CHAR:
|
|
|
|
if (lpInBuffer && nInBufferSize == sizeof(CHAR))
|
|
|
|
status = xmit_immediate(hDevice, fd, lpInBuffer);
|
|
|
|
else
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
2006-02-06 11:36:19 +01:00
|
|
|
case IOCTL_SERIAL_PURGE:
|
|
|
|
if (lpInBuffer && nInBufferSize == sizeof(DWORD))
|
|
|
|
status = purge(fd, *(DWORD*)lpInBuffer);
|
|
|
|
else
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
2006-05-07 14:11:05 +02:00
|
|
|
case IOCTL_SERIAL_RESET_DEVICE:
|
|
|
|
FIXME("Unsupported\n");
|
|
|
|
break;
|
2006-05-07 14:10:32 +02:00
|
|
|
case IOCTL_SERIAL_SET_BAUD_RATE:
|
|
|
|
if (lpInBuffer && nInBufferSize == sizeof(SERIAL_BAUD_RATE))
|
2009-03-17 00:12:11 +01:00
|
|
|
status = set_baud_rate(fd, lpInBuffer);
|
2006-05-07 14:10:32 +02:00
|
|
|
else
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
2006-01-12 13:32:51 +01:00
|
|
|
case IOCTL_SERIAL_SET_BREAK_OFF:
|
|
|
|
#if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
|
|
|
|
if (ioctl(fd, TIOCCBRK, 0) == -1)
|
|
|
|
{
|
|
|
|
TRACE("ioctl failed\n");
|
|
|
|
status = FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
FIXME("ioctl not available\n");
|
|
|
|
status = STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case IOCTL_SERIAL_SET_BREAK_ON:
|
|
|
|
#if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
|
|
|
|
if (ioctl(fd, TIOCSBRK, 0) == -1)
|
|
|
|
{
|
|
|
|
TRACE("ioctl failed\n");
|
|
|
|
status = FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
FIXME("ioctl not available\n");
|
|
|
|
status = STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
break;
|
2006-05-07 14:10:43 +02:00
|
|
|
case IOCTL_SERIAL_SET_CHARS:
|
|
|
|
if (lpInBuffer && nInBufferSize == sizeof(SERIAL_CHARS))
|
2009-03-17 00:12:11 +01:00
|
|
|
status = set_special_chars(fd, lpInBuffer);
|
2006-05-07 14:10:43 +02:00
|
|
|
else
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
2006-05-07 14:11:05 +02:00
|
|
|
case IOCTL_SERIAL_SET_DTR:
|
|
|
|
#ifdef TIOCM_DTR
|
|
|
|
if (whack_modem(fd, 0, TIOCM_DTR) == -1) status = FILE_GetNtStatus();
|
|
|
|
#else
|
|
|
|
status = STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
break;
|
2006-05-07 14:10:39 +02:00
|
|
|
case IOCTL_SERIAL_SET_HANDFLOW:
|
|
|
|
if (lpInBuffer && nInBufferSize == sizeof(SERIAL_HANDFLOW))
|
2009-03-17 00:12:11 +01:00
|
|
|
status = set_handflow(fd, lpInBuffer);
|
2006-05-07 14:10:39 +02:00
|
|
|
else
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
2006-05-07 14:10:36 +02:00
|
|
|
case IOCTL_SERIAL_SET_LINE_CONTROL:
|
|
|
|
if (lpInBuffer && nInBufferSize == sizeof(SERIAL_LINE_CONTROL))
|
2009-03-17 00:12:11 +01:00
|
|
|
status = set_line_control(fd, lpInBuffer);
|
2006-05-07 14:10:36 +02:00
|
|
|
else
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
2006-05-07 14:11:02 +02:00
|
|
|
case IOCTL_SERIAL_SET_QUEUE_SIZE:
|
|
|
|
if (lpInBuffer && nInBufferSize == sizeof(SERIAL_QUEUE_SIZE))
|
2009-03-17 00:12:11 +01:00
|
|
|
status = set_queue_size(fd, lpInBuffer);
|
2006-05-07 14:11:02 +02:00
|
|
|
else
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
2006-05-07 14:11:05 +02:00
|
|
|
case IOCTL_SERIAL_SET_RTS:
|
|
|
|
#ifdef TIOCM_RTS
|
|
|
|
if (whack_modem(fd, 0, TIOCM_RTS) == -1) status = FILE_GetNtStatus();
|
|
|
|
#else
|
|
|
|
status = STATUS_NOT_SUPPORTED;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case IOCTL_SERIAL_SET_XOFF:
|
|
|
|
status = set_XOff(fd);
|
|
|
|
break;
|
|
|
|
case IOCTL_SERIAL_SET_XON:
|
|
|
|
status = set_XOn(fd);
|
|
|
|
break;
|
2006-09-30 21:20:41 +02:00
|
|
|
case IOCTL_SERIAL_WAIT_ON_MASK:
|
|
|
|
if (lpOutBuffer && nOutBufferSize == sizeof(DWORD))
|
|
|
|
{
|
2009-09-04 03:47:32 +02:00
|
|
|
if (!(status = wait_on(hDevice, fd, hEvent, piosb, lpOutBuffer)))
|
2006-09-30 21:20:41 +02:00
|
|
|
sz = sizeof(DWORD);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
2006-01-12 13:32:51 +01:00
|
|
|
default:
|
2006-10-16 13:49:06 +02:00
|
|
|
FIXME("Unsupported IOCTL %x (type=%x access=%x func=%x meth=%x)\n",
|
2006-01-12 13:32:51 +01:00
|
|
|
dwIoControlCode, dwIoControlCode >> 16, (dwIoControlCode >> 14) & 3,
|
|
|
|
(dwIoControlCode >> 2) & 0xFFF, dwIoControlCode & 3);
|
|
|
|
sz = 0;
|
|
|
|
status = STATUS_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
2006-11-03 11:38:44 +01:00
|
|
|
if (needs_close) close( fd );
|
2006-01-12 13:32:51 +01:00
|
|
|
error:
|
|
|
|
piosb->u.Status = status;
|
|
|
|
piosb->Information = sz;
|
2006-09-30 21:20:41 +02:00
|
|
|
if (hEvent && status != STATUS_PENDING) NtSetEvent(hEvent, NULL);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
NTSTATUS COMM_DeviceIoControl(HANDLE hDevice,
|
|
|
|
HANDLE hEvent, PIO_APC_ROUTINE UserApcRoutine,
|
|
|
|
PVOID UserApcContext,
|
|
|
|
PIO_STATUS_BLOCK piosb,
|
|
|
|
ULONG dwIoControlCode,
|
|
|
|
LPVOID lpInBuffer, DWORD nInBufferSize,
|
|
|
|
LPVOID lpOutBuffer, DWORD nOutBufferSize)
|
|
|
|
{
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
if (dwIoControlCode == IOCTL_SERIAL_WAIT_ON_MASK)
|
|
|
|
{
|
|
|
|
HANDLE hev = hEvent;
|
|
|
|
|
|
|
|
/* this is an ioctl we implement in a non blocking way if hEvent is not
|
|
|
|
* null
|
2008-01-16 12:20:50 +01:00
|
|
|
* so we have to explicitly wait if no hEvent is provided
|
2006-09-30 21:20:41 +02:00
|
|
|
*/
|
|
|
|
if (!hev)
|
|
|
|
{
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
|
|
|
|
attr.Length = sizeof(attr);
|
|
|
|
attr.RootDirectory = 0;
|
|
|
|
attr.ObjectName = NULL;
|
|
|
|
attr.Attributes = OBJ_CASE_INSENSITIVE | OBJ_OPENIF;
|
|
|
|
attr.SecurityDescriptor = NULL;
|
|
|
|
attr.SecurityQualityOfService = NULL;
|
2010-01-18 20:34:54 +01:00
|
|
|
status = NtCreateEvent(&hev, EVENT_ALL_ACCESS, &attr, SynchronizationEvent, FALSE);
|
2006-09-30 21:20:41 +02:00
|
|
|
|
2013-09-03 10:24:52 +02:00
|
|
|
if (status) return status;
|
2006-09-30 21:20:41 +02:00
|
|
|
}
|
|
|
|
status = io_control(hDevice, hev, UserApcRoutine, UserApcContext,
|
|
|
|
piosb, dwIoControlCode, lpInBuffer, nInBufferSize,
|
|
|
|
lpOutBuffer, nOutBufferSize);
|
|
|
|
if (hev != hEvent)
|
|
|
|
{
|
|
|
|
if (status == STATUS_PENDING)
|
|
|
|
{
|
|
|
|
NtWaitForSingleObject(hev, FALSE, NULL);
|
|
|
|
status = STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
NtClose(hev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else status = io_control(hDevice, hEvent, UserApcRoutine, UserApcContext,
|
|
|
|
piosb, dwIoControlCode, lpInBuffer, nInBufferSize,
|
|
|
|
lpOutBuffer, nOutBufferSize);
|
2006-01-12 13:32:51 +01:00
|
|
|
return status;
|
|
|
|
}
|
2013-09-05 00:10:19 +02:00
|
|
|
|
|
|
|
NTSTATUS COMM_FlushBuffersFile( int fd )
|
|
|
|
{
|
|
|
|
#ifdef HAVE_TCDRAIN
|
|
|
|
while (tcdrain( fd ) == -1)
|
|
|
|
{
|
|
|
|
if (errno != EINTR) return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
#elif defined(TIOCDRAIN)
|
|
|
|
while (ioctl( fd, TIOCDRAIN ) == -1)
|
|
|
|
{
|
|
|
|
if (errno != EINTR) return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
#elif defined(TCSBRK)
|
|
|
|
while (ioctl( fd, TCSBRK, 1 ) == -1)
|
|
|
|
{
|
|
|
|
if (errno != EINTR) return FILE_GetNtStatus();
|
|
|
|
}
|
|
|
|
return STATUS_SUCCESS;
|
|
|
|
#else
|
|
|
|
ERR( "not supported\n" );
|
|
|
|
return STATUS_NOT_IMPLEMENTED;
|
|
|
|
#endif
|
|
|
|
}
|