26#ifdef HAVE_SYS_MODEM_H
29#ifdef HAVE_SYS_FILIO_H
32#ifdef HAVE_SYS_STRTIO_H
33#include <sys/strtio.h>
38#ifdef WITH_DEBUG_SERIAL
39#define DEBUG_SERIAL(args) printf args;
41#define DEBUG_SERIAL(args)
44#define FILE_DEVICE_SERIAL_PORT 0x1b
46#define SERIAL_SET_BAUD_RATE 1
47#define SERIAL_SET_QUEUE_SIZE 2
48#define SERIAL_SET_LINE_CONTROL 3
49#define SERIAL_SET_BREAK_ON 4
50#define SERIAL_SET_BREAK_OFF 5
51#define SERIAL_IMMEDIATE_CHAR 6
52#define SERIAL_SET_TIMEOUTS 7
53#define SERIAL_GET_TIMEOUTS 8
54#define SERIAL_SET_DTR 9
55#define SERIAL_CLR_DTR 10
56#define SERIAL_RESET_DEVICE 11
57#define SERIAL_SET_RTS 12
58#define SERIAL_CLR_RTS 13
59#define SERIAL_SET_XOFF 14
60#define SERIAL_SET_XON 15
61#define SERIAL_GET_WAIT_MASK 16
62#define SERIAL_SET_WAIT_MASK 17
63#define SERIAL_WAIT_ON_MASK 18
64#define SERIAL_PURGE 19
65#define SERIAL_GET_BAUD_RATE 20
66#define SERIAL_GET_LINE_CONTROL 21
67#define SERIAL_GET_CHARS 22
68#define SERIAL_SET_CHARS 23
69#define SERIAL_GET_HANDFLOW 24
70#define SERIAL_SET_HANDFLOW 25
71#define SERIAL_GET_MODEMSTATUS 26
72#define SERIAL_GET_COMMSTATUS 27
73#define SERIAL_XOFF_COUNTER 28
74#define SERIAL_GET_PROPERTIES 29
75#define SERIAL_GET_DTRRTS 30
76#define SERIAL_LSRMST_INSERT 31
77#define SERIAL_CONFIG_SIZE 32
78#define SERIAL_GET_COMMCONFIG 33
79#define SERIAL_SET_COMMCONFIG 34
80#define SERIAL_GET_STATS 35
81#define SERIAL_CLEAR_STATS 36
82#define SERIAL_GET_MODEM_CONTROL 37
83#define SERIAL_SET_MODEM_CONTROL 38
84#define SERIAL_SET_FIFO_CONTROL 39
93#define SERIAL_PURGE_TXABORT 0x00000001
94#define SERIAL_PURGE_RXABORT 0x00000002
95#define SERIAL_PURGE_TXCLEAR 0x00000004
96#define SERIAL_PURGE_RXCLEAR 0x00000008
99#define SERIAL_EV_RXCHAR 0x0001
100#define SERIAL_EV_RXFLAG 0x0002
101#define SERIAL_EV_TXEMPTY 0x0004
102#define SERIAL_EV_CTS 0x0008
103#define SERIAL_EV_DSR 0x0010
104#define SERIAL_EV_RLSD 0x0020
105#define SERIAL_EV_BREAK 0x0040
106#define SERIAL_EV_ERR 0x0080
107#define SERIAL_EV_RING 0x0100
108#define SERIAL_EV_PERR 0x0200
109#define SERIAL_EV_RX80FULL 0x0400
110#define SERIAL_EV_EVENT1 0x0800
111#define SERIAL_EV_EVENT2 0x1000
114#define SERIAL_MS_DTR 0x01
115#define SERIAL_MS_RTS 0x02
116#define SERIAL_MS_CTS 0x10
117#define SERIAL_MS_DSR 0x20
118#define SERIAL_MS_RNG 0x40
119#define SERIAL_MS_CAR 0x80
122#define SERIAL_DTR_CONTROL 0x01
123#define SERIAL_CTS_HANDSHAKE 0x08
124#define SERIAL_ERROR_ABORT 0x80000000
126#define SERIAL_XON_HANDSHAKE 0x01
127#define SERIAL_XOFF_HANDSHAKE 0x02
128#define SERIAL_DSR_SENSITIVITY 0x40
130#define SERIAL_CHAR_EOF 0
131#define SERIAL_CHAR_ERROR 1
132#define SERIAL_CHAR_BREAK 2
133#define SERIAL_CHAR_EVENT 3
134#define SERIAL_CHAR_XON 4
135#define SERIAL_CHAR_XOFF 5
143#if !defined(TIOCINQ) && defined(FIONREAD)
144#define TIOCINQ FIONREAD
146#if !defined(TIOCOUTQ) && defined(FIONWRITE)
147#define TIOCOUTQ FIONWRITE
167 struct termios *ptermios;
171 if (tcgetattr(serial_fd, ptermios) == -1)
174 speed = cfgetispeed(ptermios);
267 speed = cfgetospeed(ptermios);
268 pser_inf->
dtr = (speed == B0) ? 0 : 1;
273 c_cflag & PARENB) ? ((ptermios->
275 switch (ptermios->c_cflag & CSIZE)
291 if (ptermios->c_cflag &
CRTSCTS)
301 if (ptermios->c_iflag & IXON)
304 if (ptermios->c_iflag & IXOFF)
321 struct termios *ptermios;
419 ptermios->c_cflag &= ~CBAUD;
420 ptermios->c_cflag |= speed;
424 cfsetispeed(pser_inf->
ptermios, speed);
425 cfsetospeed(pser_inf->
ptermios, pser_inf->
dtr ? speed : 0);
428 ptermios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CSIZE |
CRTSCTS);
432 ptermios->c_cflag |= CSTOPB;
435 ptermios->c_cflag &= ~CSTOPB;
442 ptermios->c_cflag |= PARENB;
445 ptermios->c_cflag |= PARENB | PARODD;
448 ptermios->c_cflag &= ~(PARENB | PARODD);
455 ptermios->c_cflag |= CS5;
458 ptermios->c_cflag |= CS6;
461 ptermios->c_cflag |= CS7;
464 ptermios->c_cflag |= CS8;
472 ptermios->c_cflag &= ~CRTSCTS;
481 ptermios->c_cflag &= ~CRTSCTS;
487 ptermios->c_iflag |= IXON | IMAXBEL;
491 ptermios->c_iflag |= IXOFF | IMAXBEL;
496 ptermios->c_iflag &= ~IXON;
497 ptermios->c_iflag &= ~IXOFF;
506 tcsetattr(serial_fd, TCSANOW, ptermios);
529 pser_inf->
ptermios = (
struct termios *)
xmalloc(
sizeof(
struct termios));
540 strcpy(
This->rdpdr_device[*
id].local_path, pos2);
541 printf(
"SERIAL %s to %s\n",
This->rdpdr_device[*
id].name,
542 This->rdpdr_device[*
id].local_path);
545 This->rdpdr_device[*
id].pdevice_data = (
void *) pser_inf;
560 struct termios *ptermios;
574 printf(
"INFO: SERIAL %s access denied\n",
This->rdpdr_device[device_id].name);
580 This->rdpdr_device[device_id].handle = serial_fd;
583 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",
This->rdpdr_device[device_id].name,
This->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));
586 ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
587 pser_inf->
ptermios->c_oflag &= ~OPOST;
588 pser_inf->
ptermios->c_lflag &= ~(
ECHO | ECHONL | ICANON | ISIG | IEXTEN);
589 pser_inf->
ptermios->c_cflag &= ~(CSIZE | PARENB);
592 tcsetattr(serial_fd, TCSANOW, pser_inf->
ptermios);
616 This->rdpdr_device[
i].handle = 0;
628 struct termios *ptermios;
629#ifdef WITH_DEBUG_SERIAL
656 ptermios->c_cc[VTIME] = 0;
657 ptermios->c_cc[VMIN] = 0;
661 ptermios->c_cc[VTIME] =
timeout;
662 ptermios->c_cc[VMIN] = 1;
664 tcsetattr(
handle, TCSANOW, ptermios);
666#if defined(WITH_DEBUG_SERIAL) && defined(TIOCINQ)
673#ifdef WITH_DEBUG_SERIAL
702 int flush_mask, purge_mask;
706 struct termios *ptermios;
723 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_SET_BAUD_RATE %d\n",
728 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_GET_BAUD_RATE %d\n",
734 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_SET_QUEUE_SIZE in %d out %d\n",
745 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_GET_LINE_CONTROL\n"));
751 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_IMMEDIATE_CHAR\n"));
766#ifdef WITH_DEBUG_SERIAL
772 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_GET_HANDFLOW\n"));
784 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_SET_HANDFLOW %x %x %x %x\n",
795 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_SET_TIMEOUTS read timeout %d %d %d\n",
801 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_GET_TIMEOUTS read timeout %d %d %d\n",
813 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_GET_WAIT_MASK %X\n",
819 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_SET_WAIT_MASK %X\n",
867 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_GET_MODEMSTATUS %X\n", modemstate));
880 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_GET_COMMSTATUS in queue %d\n",
896 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_PURGE purge_mask %X\n", purge_mask));
899 flush_mask |= TCOFLUSH;
901 flush_mask |= TCIFLUSH;
903 tcflush(
handle, flush_mask);
910 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_WAIT_ON_MASK %X\n",
922 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_SET_BREAK_ON\n"));
926 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_RESET_DEVICE\n"));
929 DEBUG_SERIAL((
"serial_ioctl -> SERIAL_SET_BREAK_OFF\n"));
1019 (
bytes & TIOCM_DSR) ?
"ON" :
"OFF"));
1031 (
bytes & TIOCM_CTS) ?
"ON" :
"OFF"));
ACPI_SIZE strlen(const char *String)
char * strcpy(char *DstString, const char *SrcString)
static unsigned char bytes[4]
#define DEVICE_TYPE_SERIAL
#define RDPDR_MAX_DEVICES
#define out_uint32_le(s, v)
#define in_uint8a(s, v, n)
#define in_uint32_le(s, v)
#define out_uint8a(s, v, n)
RD_BOOL rdpdr_abort_io(uint32 fd, uint32 major, RD_NTSTATUS status)
char * next_arg(char *src, char needle)
int get_device_index(RD_NTHANDLE handle)
void unimpl(char *format,...)
void hexdump(unsigned char *p, unsigned int len)
void toupper_str(char *p)
GLuint GLuint GLsizei count
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLuint GLsizei GLsizei * length
GLuint GLint GLboolean GLint GLenum access
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
#define SERIAL_EV_TXEMPTY
#define SERIAL_DSR_SENSITIVITY
#define SERIAL_WAIT_ON_MASK
#define SERIAL_SET_BREAK_ON
#define SERIAL_SET_TIMEOUTS
#define SERIAL_SET_HANDFLOW
#define SERIAL_XOFF_HANDSHAKE
#define SERIAL_PURGE_TXCLEAR
#define SERIAL_CONFIG_SIZE
static NTSTATUS serial_device_control(RDPCLIENT *This, NTHANDLE handle, uint32 request, STREAM in, STREAM out)
static NTSTATUS serial_create(RDPCLIENT *This, uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, uint32 flags_and_attributes, char *filename, NTHANDLE *handle)
#define SERIAL_SET_LINE_CONTROL
#define SERIAL_PURGE_RXCLEAR
#define FILE_DEVICE_SERIAL_PORT
#define SERIAL_CHAR_BREAK
#define SERIAL_GET_MODEMSTATUS
#define SERIAL_SET_BREAK_OFF
static BOOL get_termios(SERIAL_DEVICE *pser_inf, NTHANDLE serial_fd)
BOOL serial_get_event(RDPCLIENT *This, NTHANDLE handle, uint32 *result)
#define SERIAL_GET_COMMSTATUS
#define SERIAL_ERROR_ABORT
#define SERIAL_SET_QUEUE_SIZE
#define SERIAL_SET_BAUD_RATE
#define SERIAL_GET_TIMEOUTS
static NTSTATUS serial_read(RDPCLIENT *This, NTHANDLE handle, uint8 *data, uint32 length, uint32 offset, uint32 *result)
#define SERIAL_CTS_HANDSHAKE
#define SERIAL_PURGE_RXABORT
#define SERIAL_SET_WAIT_MASK
#define SERIAL_GET_BAUD_RATE
#define SERIAL_DTR_CONTROL
#define SERIAL_GET_HANDFLOW
#define SERIAL_GET_LINE_CONTROL
static void set_termios(SERIAL_DEVICE *pser_inf, NTHANDLE serial_fd)
#define SERIAL_XON_HANDSHAKE
static NTSTATUS serial_close(RDPCLIENT *This, NTHANDLE handle)
#define SERIAL_RESET_DEVICE
#define SERIAL_GET_WAIT_MASK
BOOL serial_get_timeout(RDPCLIENT *This, NTHANDLE handle, uint32 length, uint32 *timeout, uint32 *itv_timeout)
#define SERIAL_CHAR_ERROR
#define SERIAL_PURGE_TXABORT
#define SERIAL_IMMEDIATE_CHAR
static NTSTATUS serial_write(RDPCLIENT *This, NTHANDLE handle, uint8 *data, uint32 length, uint32 offset, uint32 *result)
static SERIAL_DEVICE * get_serial_info(RDPCLIENT *This, NTHANDLE handle)
#define DEBUG_SERIAL(args)
int serial_enum_devices(RDPCLIENT *This, uint32 *id, char *optarg)
struct termios * ptermios
struct termios * pold_termios
uint32 read_interval_timeout
uint32 read_total_timeout_multiplier
uint32 write_total_timeout_multiplier
uint32 write_total_timeout_constant
uint32 read_total_timeout_constant
#define STATUS_ACCESS_DENIED
#define STATUS_INVALID_PARAMETER