serial.c revision d65680efa46fa49e8bf14e67b29b782510ff934c
/* -*- c-basic-offset: 8 -*-
rdesktop: A Remote Desktop Protocol client.
Copyright (C) Matthew Chapman 1999-2007
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* Sun GPL Disclaimer: For the avoidance of doubt, except that if any license choice
* other than GPL or LGPL is available it will apply instead, Sun elects to use only
* the General Public License version 2 (GPLv2) at this time for any software where
* a choice of GPL license versions is made available with the language indicating
* that GPLv2 or any later version may be used, or where a choice of which version
* of the GPL is applied is otherwise unspecified.
*/
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <strings.h>
#ifdef HAVE_SYS_MODEM_H
#endif
#ifdef HAVE_SYS_FILIO_H
#endif
#ifdef HAVE_SYS_STRTIO_H
#endif
#include "rdesktop.h"
#ifdef WITH_DEBUG_SERIAL
#else
#define DEBUG_SERIAL(args)
#endif
#define FILE_DEVICE_SERIAL_PORT 0x1b
#define SERIAL_SET_BAUD_RATE 1
#define SERIAL_SET_QUEUE_SIZE 2
#define SERIAL_SET_LINE_CONTROL 3
#define SERIAL_SET_BREAK_ON 4
#define SERIAL_SET_BREAK_OFF 5
#define SERIAL_IMMEDIATE_CHAR 6
#define SERIAL_SET_TIMEOUTS 7
#define SERIAL_GET_TIMEOUTS 8
#define SERIAL_SET_DTR 9
#define SERIAL_CLR_DTR 10
#define SERIAL_RESET_DEVICE 11
#define SERIAL_SET_RTS 12
#define SERIAL_CLR_RTS 13
#define SERIAL_SET_XOFF 14
#define SERIAL_SET_XON 15
#define SERIAL_GET_WAIT_MASK 16
#define SERIAL_SET_WAIT_MASK 17
#define SERIAL_WAIT_ON_MASK 18
#define SERIAL_PURGE 19
#define SERIAL_GET_BAUD_RATE 20
#define SERIAL_GET_LINE_CONTROL 21
#define SERIAL_GET_CHARS 22
#define SERIAL_SET_CHARS 23
#define SERIAL_GET_HANDFLOW 24
#define SERIAL_SET_HANDFLOW 25
#define SERIAL_GET_MODEMSTATUS 26
#define SERIAL_GET_COMMSTATUS 27
#define SERIAL_XOFF_COUNTER 28
#define SERIAL_GET_PROPERTIES 29
#define SERIAL_GET_DTRRTS 30
#define SERIAL_LSRMST_INSERT 31
#define SERIAL_CONFIG_SIZE 32
#define SERIAL_GET_COMMCONFIG 33
#define SERIAL_SET_COMMCONFIG 34
#define SERIAL_GET_STATS 35
#define SERIAL_CLEAR_STATS 36
#define SERIAL_GET_MODEM_CONTROL 37
#define SERIAL_SET_MODEM_CONTROL 38
#define SERIAL_SET_FIFO_CONTROL 39
#define STOP_BITS_1 0
#define STOP_BITS_2 2
#define NO_PARITY 0
#define ODD_PARITY 1
#define EVEN_PARITY 2
#define SERIAL_PURGE_TXABORT 0x00000001
#define SERIAL_PURGE_RXABORT 0x00000002
#define SERIAL_PURGE_TXCLEAR 0x00000004
#define SERIAL_PURGE_RXCLEAR 0x00000008
/* SERIAL_WAIT_ON_MASK */
/* Modem Status */
#define SERIAL_MS_DTR 0x01
#define SERIAL_MS_RTS 0x02
#define SERIAL_MS_CTS 0x10
#define SERIAL_MS_DSR 0x20
#define SERIAL_MS_RNG 0x40
#define SERIAL_MS_CAR 0x80
/* Handflow */
#define SERIAL_DTR_CONTROL 0x01
#define SERIAL_CTS_HANDSHAKE 0x08
#define SERIAL_ERROR_ABORT 0x80000000
#define SERIAL_XON_HANDSHAKE 0x01
#define SERIAL_XOFF_HANDSHAKE 0x02
#define SERIAL_DSR_SENSITIVITY 0x40
#define SERIAL_CHAR_EOF 0
#define SERIAL_CHAR_ERROR 1
#define SERIAL_CHAR_BREAK 2
#define SERIAL_CHAR_EVENT 3
#define SERIAL_CHAR_XON 4
#define SERIAL_CHAR_XOFF 5
#ifndef CRTSCTS
#define CRTSCTS 0
#endif
/* FIONREAD should really do the same thing as TIOCINQ, where it is
* not available */
#endif
#endif
extern RDPDR_DEVICE g_rdpdr_device[];
static SERIAL_DEVICE *
{
int index;
{
}
return NULL;
}
static RD_BOOL
{
return False;
switch (speed)
{
#ifdef B75
case B75:
break;
#endif
#ifdef B110
case B110:
break;
#endif
#ifdef B134
case B134:
break;
#endif
#ifdef B150
case B150:
break;
#endif
#ifdef B300
case B300:
break;
#endif
#ifdef B600
case B600:
break;
#endif
#ifdef B1200
case B1200:
break;
#endif
#ifdef B1800
case B1800:
break;
#endif
#ifdef B2400
case B2400:
break;
#endif
#ifdef B4800
case B4800:
break;
#endif
#ifdef B9600
case B9600:
break;
#endif
#ifdef B19200
case B19200:
break;
#endif
#ifdef B38400
case B38400:
break;
#endif
#ifdef B57600
case B57600:
break;
#endif
#ifdef B115200
case B115200:
break;
#endif
#ifdef B230400
case B230400:
break;
#endif
#ifdef B460800
case B460800:
break;
#endif
default:
break;
}
(ptermios->
{
case CS5:
break;
case CS6:
break;
case CS7:
break;
default:
break;
}
{
}
else
{
}
return True;
}
static void
{
{
#ifdef B75
case 75:
break;
#endif
#ifdef B110
case 110:
break;
#endif
#ifdef B134
case 134:
break;
#endif
#ifdef B150
case 150:
break;
#endif
#ifdef B300
case 300:
break;
#endif
#ifdef B600
case 600:
break;
#endif
#ifdef B1200
case 1200:
break;
#endif
#ifdef B1800
case 1800:
break;
#endif
#ifdef B2400
case 2400:
break;
#endif
#ifdef B4800
case 4800:
break;
#endif
#ifdef B9600
case 9600:
break;
#endif
#ifdef B19200
case 19200:
break;
#endif
#ifdef B38400
case 38400:
break;
#endif
#ifdef B57600
case 57600:
break;
#endif
#ifdef B115200
case 115200:
break;
#endif
#ifdef B230400
case 230400:
break;
#endif
#ifdef B460800
case 460800:
break;
#endif
default:
break;
}
#ifdef CBAUD
#else
/* on systems with separate ispeed and ospeed, we can remember the speed
in ispeed while changing DTR with ospeed */
#endif
{
case STOP_BITS_2:
break;
default:
break;
}
{
case EVEN_PARITY:
break;
case ODD_PARITY:
break;
case NO_PARITY:
break;
}
switch (pser_inf->word_length)
{
case 5:
break;
case 6:
break;
case 7:
break;
default:
break;
}
#if 0
else
#endif
{
}
else
{
}
{
}
{
}
{
}
}
/* Enumeration of devices from rdesktop.c */
/* returns numer of units found and initialized. */
/* when it arrives to this function. */
int
{
char *pos2;
int count = 0;
/* skip the first colon */
optarg++;
{
/* Init data structures for device */
/* set device type */
count++;
(*id)++;
}
return count;
}
static RD_NTSTATUS
{
if (serial_fd == -1)
{
perror("open");
return RD_STATUS_ACCESS_DENIED;
}
{
return RD_STATUS_ACCESS_DENIED;
}
/* Store handle for later use */
/* some sane information */
DEBUG_SERIAL(("INFO: SERIAL %s to %s\nINFO: speed %u baud, stop bits %u, parity %u, word length %u bits, dtr %u, rts %u\n", g_rdpdr_device[device_id].name, g_rdpdr_device[device_id].local_path, pser_inf->baud_rate, pser_inf->stop_bits, pser_inf->parity, pser_inf->word_length, pser_inf->dtr, pser_inf->rts));
pser_inf->event_txempty = 0;
pser_inf->event_rlsd = 0;
pser_inf->event_pending = 0;
/* all read and writes should be non blocking */
perror("fcntl");
return RD_STATUS_SUCCESS;
}
static RD_NTSTATUS
{
int i = get_device_index(handle);
if (i >= 0)
g_rdpdr_device[i].handle = 0;
return RD_STATUS_SUCCESS;
}
static RD_NTSTATUS
{
long timeout;
#ifdef WITH_DEBUG_SERIAL
int bytes_inqueue;
#endif
timeout = 90;
/* Set timeouts kind of like the windows serial timeout parameters. Multiply timeout
with requested read size */
{
timeout =
}
else if (pser_inf->read_interval_timeout)
{
}
/* If a timeout is set, do a blocking read, which times out after some time.
It will make rdesktop less responsive, but it will improve serial performance, by not
reading one character at a time. */
if (timeout == 0)
{
}
else
{
}
#if defined(WITH_DEBUG_SERIAL) && defined(TIOCINQ)
#endif
#ifdef WITH_DEBUG_SERIAL
if (*result > 0)
#endif
return RD_STATUS_SUCCESS;
}
static RD_NTSTATUS
{
if (*result > 0)
return RD_STATUS_SUCCESS;
}
static RD_NTSTATUS
{
int flush_mask, purge_mask;
return RD_STATUS_INVALID_PARAMETER;
/* extract operation */
request >>= 2;
request &= 0xfff;
switch (request)
{
case SERIAL_SET_BAUD_RATE:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_BAUD_RATE %d\n",
break;
case SERIAL_GET_BAUD_RATE:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_BAUD_RATE %d\n",
break;
case SERIAL_SET_QUEUE_SIZE:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_QUEUE_SIZE in %d out %d\n",
break;
case SERIAL_SET_LINE_CONTROL:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_LINE_CONTROL stop %d parity %d word %d\n", pser_inf->stop_bits, pser_inf->parity, pser_inf->word_length));
break;
case SERIAL_GET_LINE_CONTROL:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_LINE_CONTROL\n"));
break;
case SERIAL_IMMEDIATE_CHAR:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_IMMEDIATE_CHAR\n"));
break;
case SERIAL_CONFIG_SIZE:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_CONFIG_SIZE\n"));
out_uint32_le(out, 0);
break;
case SERIAL_GET_CHARS:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_CHARS\n"));
break;
case SERIAL_SET_CHARS:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_CHARS\n"));
#ifdef WITH_DEBUG_SERIAL
#endif
break;
case SERIAL_GET_HANDFLOW:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_HANDFLOW\n"));
break;
case SERIAL_SET_HANDFLOW:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_HANDFLOW %x %x %x %x\n",
break;
case SERIAL_SET_TIMEOUTS:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_TIMEOUTS read timeout %d %d %d\n",
break;
case SERIAL_GET_TIMEOUTS:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_TIMEOUTS read timeout %d %d %d\n",
break;
case SERIAL_GET_WAIT_MASK:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_WAIT_MASK %X\n",
break;
case SERIAL_SET_WAIT_MASK:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_WAIT_MASK %X\n",
break;
case SERIAL_SET_DTR:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_DTR\n"));
break;
case SERIAL_CLR_DTR:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_CLR_DTR\n"));
break;
case SERIAL_SET_RTS:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_RTS\n"));
break;
case SERIAL_CLR_RTS:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_CLR_RTS\n"));
break;
case SERIAL_GET_MODEMSTATUS:
modemstate = 0;
#ifdef TIOCMGET
#endif
break;
case SERIAL_GET_COMMSTATUS:
result = 0;
#ifdef TIOCINQ
#endif
if (result)
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS in queue %d\n",
result));
result = 0;
#ifdef TIOCOUTQ
#endif
if (result)
break;
case SERIAL_PURGE:
flush_mask = 0;
if (purge_mask & SERIAL_PURGE_TXCLEAR)
flush_mask |= TCOFLUSH;
if (purge_mask & SERIAL_PURGE_RXCLEAR)
flush_mask |= TCIFLUSH;
if (flush_mask != 0)
if (purge_mask & SERIAL_PURGE_TXABORT)
if (purge_mask & SERIAL_PURGE_RXABORT)
break;
case SERIAL_WAIT_ON_MASK:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_WAIT_ON_MASK %X\n",
{
break;
}
return RD_STATUS_PENDING;
break;
case SERIAL_SET_BREAK_ON:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_BREAK_ON\n"));
tcsendbreak(handle, 0);
break;
case SERIAL_RESET_DEVICE:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_RESET_DEVICE\n"));
break;
case SERIAL_SET_BREAK_OFF:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_BREAK_OFF\n"));
break;
case SERIAL_SET_XOFF:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_XOFF\n"));
break;
case SERIAL_SET_XON:
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_XON\n"));
break;
default:
return RD_STATUS_INVALID_PARAMETER;
}
return RD_STATUS_SUCCESS;
}
{
int index;
int bytes;
*result = 0;
if (index < 0)
return False;
#ifdef TIOCINQ
if (bytes > 0)
{
{
{
DEBUG_SERIAL(("Event -> SERIAL_EV_RLSD \n"));
*result |= SERIAL_EV_RLSD;
}
}
{
*result |= SERIAL_EV_RXFLAG;
}
{
*result |= SERIAL_EV_RXCHAR;
}
}
else
{
pser_inf->event_rlsd = 0;
}
#endif
#ifdef TIOCOUTQ
if ((bytes == 0)
{
DEBUG_SERIAL(("Event -> SERIAL_EV_TXEMPTY\n"));
*result |= SERIAL_EV_TXEMPTY;
}
#endif
{
{
DEBUG_SERIAL(("event -> SERIAL_EV_DSR %s\n",
*result |= SERIAL_EV_DSR;
}
}
{
{
DEBUG_SERIAL((" EVENT-> SERIAL_EV_CTS %s\n",
*result |= SERIAL_EV_CTS;
}
}
if (ret)
pser_inf->event_pending = 0;
return ret;
}
/* Read timeout for a given file descripter (device) when adding fd's to select() */
{
int index;
if (index < 0)
return True;
{
return False;
}
*timeout =
return True;
}
DEVICE_FNS serial_fns = {
};