3 |
#include <termios.h> |
#include <termios.h> |
4 |
#include <strings.h> |
#include <strings.h> |
5 |
#include <sys/ioctl.h> |
#include <sys/ioctl.h> |
6 |
|
|
7 |
|
#ifdef HAVE_SYS_MODEM_H |
8 |
|
#include <sys/modem.h> |
9 |
|
#endif |
10 |
|
#ifdef HAVE_SYS_FILIO_H |
11 |
|
#include <sys/filio.h> |
12 |
|
#endif |
13 |
|
#ifdef HAVE_SYS_STRTIO_H |
14 |
|
#include <sys/strtio.h> |
15 |
|
#endif |
16 |
|
|
17 |
#include "rdesktop.h" |
#include "rdesktop.h" |
18 |
|
|
19 |
#ifdef WITH_DEBUG_SERIAL |
#ifdef WITH_DEBUG_SERIAL |
121 |
|
|
122 |
/* FIONREAD should really do the same thing as TIOCINQ, where it is |
/* FIONREAD should really do the same thing as TIOCINQ, where it is |
123 |
* not available */ |
* not available */ |
124 |
#ifndef TIOCINQ |
#if !defined(TIOCINQ) && defined(FIONREAD) |
|
#include <sys/filio.h> |
|
125 |
#define TIOCINQ FIONREAD |
#define TIOCINQ FIONREAD |
126 |
#endif |
#endif |
127 |
|
#if !defined(TIOCOUTQ) && defined(FIONWRITE) |
128 |
|
#define TIOCOUTQ FIONWRITE |
129 |
|
#endif |
130 |
|
|
131 |
extern RDPDR_DEVICE g_rdpdr_device[]; |
extern RDPDR_DEVICE g_rdpdr_device[]; |
132 |
|
|
398 |
break; |
break; |
399 |
} |
} |
400 |
|
|
401 |
#if 0 |
#ifdef CBAUD |
402 |
|
ptermios->c_cflag &= ~CBAUD; |
403 |
|
ptermios->c_cflag |= speed; |
404 |
|
#else |
405 |
/* on systems with separate ispeed and ospeed, we can remember the speed |
/* on systems with separate ispeed and ospeed, we can remember the speed |
406 |
in ispeed while changing DTR with ospeed */ |
in ispeed while changing DTR with ospeed */ |
407 |
cfsetispeed(pser_inf->ptermios, speed); |
cfsetispeed(pser_inf->ptermios, speed); |
408 |
cfsetospeed(pser_inf->ptermios, pser_inf->dtr ? speed : 0); |
cfsetospeed(pser_inf->ptermios, pser_inf->dtr ? speed : 0); |
409 |
#endif |
#endif |
410 |
|
|
|
ptermios->c_cflag &= ~CBAUD; |
|
|
ptermios->c_cflag |= speed; |
|
|
|
|
411 |
ptermios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CSIZE | CRTSCTS); |
ptermios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CSIZE | CRTSCTS); |
412 |
switch (pser_inf->stop_bits) |
switch (pser_inf->stop_bits) |
413 |
{ |
{ |
568 |
pser_inf->ptermios->c_iflag &= |
pser_inf->ptermios->c_iflag &= |
569 |
~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); |
~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); |
570 |
pser_inf->ptermios->c_oflag &= ~OPOST; |
pser_inf->ptermios->c_oflag &= ~OPOST; |
571 |
pser_inf->ptermios->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN | XCASE); |
pser_inf->ptermios->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); |
572 |
pser_inf->ptermios->c_cflag &= ~(CSIZE | PARENB); |
pser_inf->ptermios->c_cflag &= ~(CSIZE | PARENB); |
573 |
pser_inf->ptermios->c_cflag |= CS8; |
pser_inf->ptermios->c_cflag |= CS8; |
574 |
|
|
646 |
} |
} |
647 |
tcsetattr(handle, TCSANOW, ptermios); |
tcsetattr(handle, TCSANOW, ptermios); |
648 |
|
|
649 |
#ifdef WITH_DEBUG_SERIAL |
#if defined(WITH_DEBUG_SERIAL) && defined(TIOCINQ) |
650 |
ioctl(handle, TIOCINQ, &bytes_inqueue); |
ioctl(handle, TIOCINQ, &bytes_inqueue); |
651 |
DEBUG_SERIAL(("serial_read inqueue: %d expected %d\n", bytes_inqueue, length)); |
DEBUG_SERIAL(("serial_read inqueue: %d expected %d\n", bytes_inqueue, length)); |
652 |
#endif |
#endif |
703 |
case SERIAL_SET_BAUD_RATE: |
case SERIAL_SET_BAUD_RATE: |
704 |
in_uint32_le(in, pser_inf->baud_rate); |
in_uint32_le(in, pser_inf->baud_rate); |
705 |
set_termios(pser_inf, handle); |
set_termios(pser_inf, handle); |
706 |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_BAUD_RATE %d\n", pser_inf->baud_rate)); |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_BAUD_RATE %d\n", |
707 |
|
pser_inf->baud_rate)); |
708 |
break; |
break; |
709 |
case SERIAL_GET_BAUD_RATE: |
case SERIAL_GET_BAUD_RATE: |
710 |
out_uint32_le(out, pser_inf->baud_rate); |
out_uint32_le(out, pser_inf->baud_rate); |
711 |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_BAUD_RATE %d\n", pser_inf->baud_rate)); |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_BAUD_RATE %d\n", |
712 |
|
pser_inf->baud_rate)); |
713 |
break; |
break; |
714 |
case SERIAL_SET_QUEUE_SIZE: |
case SERIAL_SET_QUEUE_SIZE: |
715 |
in_uint32_le(in, pser_inf->queue_in_size); |
in_uint32_le(in, pser_inf->queue_in_size); |
716 |
in_uint32_le(in, pser_inf->queue_out_size); |
in_uint32_le(in, pser_inf->queue_out_size); |
717 |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_QUEUE_SIZE in %d out %d\n", |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_QUEUE_SIZE in %d out %d\n", |
718 |
pser_inf->queue_in_size, pser_inf->queue_out_size)); |
pser_inf->queue_in_size, pser_inf->queue_out_size)); |
719 |
break; |
break; |
720 |
case SERIAL_SET_LINE_CONTROL: |
case SERIAL_SET_LINE_CONTROL: |
721 |
in_uint8(in, pser_inf->stop_bits); |
in_uint8(in, pser_inf->stop_bits); |
722 |
in_uint8(in, pser_inf->parity); |
in_uint8(in, pser_inf->parity); |
723 |
in_uint8(in, pser_inf->word_length); |
in_uint8(in, pser_inf->word_length); |
724 |
set_termios(pser_inf, handle); |
set_termios(pser_inf, handle); |
725 |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_LINE_CONTROL stop %d parity %d word %d\n", |
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)); |
|
pser_inf->stop_bits, pser_inf->parity, pser_inf->word_length)); |
|
726 |
break; |
break; |
727 |
case SERIAL_GET_LINE_CONTROL: |
case SERIAL_GET_LINE_CONTROL: |
728 |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_LINE_CONTROL\n")); |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_LINE_CONTROL\n")); |
765 |
in_uint32_le(in, pser_inf->onlimit); |
in_uint32_le(in, pser_inf->onlimit); |
766 |
in_uint32_le(in, pser_inf->offlimit); |
in_uint32_le(in, pser_inf->offlimit); |
767 |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_HANDFLOW %x %x %x %x\n", |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_HANDFLOW %x %x %x %x\n", |
768 |
pser_inf->control, pser_inf->xonoff, pser_inf->onlimit, |
pser_inf->control, pser_inf->xonoff, pser_inf->onlimit, |
769 |
pser_inf->onlimit)); |
pser_inf->onlimit)); |
770 |
set_termios(pser_inf, handle); |
set_termios(pser_inf, handle); |
771 |
break; |
break; |
772 |
case SERIAL_SET_TIMEOUTS: |
case SERIAL_SET_TIMEOUTS: |
776 |
in_uint32(in, pser_inf->write_total_timeout_multiplier); |
in_uint32(in, pser_inf->write_total_timeout_multiplier); |
777 |
in_uint32(in, pser_inf->write_total_timeout_constant); |
in_uint32(in, pser_inf->write_total_timeout_constant); |
778 |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_TIMEOUTS read timeout %d %d %d\n", |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_TIMEOUTS read timeout %d %d %d\n", |
779 |
pser_inf->read_interval_timeout, |
pser_inf->read_interval_timeout, |
780 |
pser_inf->read_total_timeout_multiplier, |
pser_inf->read_total_timeout_multiplier, |
781 |
pser_inf->read_total_timeout_constant)); |
pser_inf->read_total_timeout_constant)); |
782 |
break; |
break; |
783 |
case SERIAL_GET_TIMEOUTS: |
case SERIAL_GET_TIMEOUTS: |
784 |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_TIMEOUTS read timeout %d %d %d\n", |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_TIMEOUTS read timeout %d %d %d\n", |
785 |
pser_inf->read_interval_timeout, |
pser_inf->read_interval_timeout, |
786 |
pser_inf->read_total_timeout_multiplier, |
pser_inf->read_total_timeout_multiplier, |
787 |
pser_inf->read_total_timeout_constant)); |
pser_inf->read_total_timeout_constant)); |
788 |
|
|
789 |
out_uint32(out, pser_inf->read_interval_timeout); |
out_uint32(out, pser_inf->read_interval_timeout); |
790 |
out_uint32(out, pser_inf->read_total_timeout_multiplier); |
out_uint32(out, pser_inf->read_total_timeout_multiplier); |
793 |
out_uint32(out, pser_inf->write_total_timeout_constant); |
out_uint32(out, pser_inf->write_total_timeout_constant); |
794 |
break; |
break; |
795 |
case SERIAL_GET_WAIT_MASK: |
case SERIAL_GET_WAIT_MASK: |
796 |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_WAIT_MASK %X\n", pser_inf->wait_mask); |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_WAIT_MASK %X\n", |
797 |
out_uint32(out, pser_inf->wait_mask)); |
pser_inf->wait_mask); |
798 |
|
out_uint32(out, pser_inf->wait_mask)); |
799 |
break; |
break; |
800 |
case SERIAL_SET_WAIT_MASK: |
case SERIAL_SET_WAIT_MASK: |
801 |
in_uint32(in, pser_inf->wait_mask); |
in_uint32(in, pser_inf->wait_mask); |
802 |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_WAIT_MASK %X\n", pser_inf->wait_mask)); |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_WAIT_MASK %X\n", |
803 |
|
pser_inf->wait_mask)); |
804 |
break; |
break; |
805 |
case SERIAL_SET_DTR: |
case SERIAL_SET_DTR: |
806 |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_DTR\n")); |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_DTR\n")); |
855 |
out_uint32_le(out, 0); /* Hold reasons */ |
out_uint32_le(out, 0); /* Hold reasons */ |
856 |
|
|
857 |
result = 0; |
result = 0; |
858 |
|
#ifdef TIOCINQ |
859 |
ioctl(handle, TIOCINQ, &result); |
ioctl(handle, TIOCINQ, &result); |
860 |
|
#endif |
861 |
out_uint32_le(out, result); /* Amount in in queue */ |
out_uint32_le(out, result); /* Amount in in queue */ |
862 |
if (result) |
if (result) |
863 |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS in queue %d\n", result)); |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS in queue %d\n", |
864 |
|
result)); |
865 |
|
|
866 |
result = 0; |
result = 0; |
867 |
|
#ifdef TIOCOUTQ |
868 |
ioctl(handle, TIOCOUTQ, &result); |
ioctl(handle, TIOCOUTQ, &result); |
869 |
|
#endif |
870 |
out_uint32_le(out, result); /* Amount in out queue */ |
out_uint32_le(out, result); /* Amount in out queue */ |
871 |
if (result) |
if (result) |
872 |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS out queue %d\n", result)); |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS out queue %d\n", result)); |
890 |
rdpdr_abort_io(handle, 3, STATUS_CANCELLED); |
rdpdr_abort_io(handle, 3, STATUS_CANCELLED); |
891 |
break; |
break; |
892 |
case SERIAL_WAIT_ON_MASK: |
case SERIAL_WAIT_ON_MASK: |
893 |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_WAIT_ON_MASK %X\n", pser_inf->wait_mask)); |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_WAIT_ON_MASK %X\n", |
894 |
|
pser_inf->wait_mask)); |
895 |
pser_inf->event_pending = 1; |
pser_inf->event_pending = 1; |
896 |
if (serial_get_event(handle, &result)) |
if (serial_get_event(handle, &result)) |
897 |
{ |
{ |
939 |
if (index < 0) |
if (index < 0) |
940 |
return False; |
return False; |
941 |
|
|
942 |
|
#ifdef TIOCINQ |
943 |
pser_inf = (SERIAL_DEVICE *) g_rdpdr_device[index].pdevice_data; |
pser_inf = (SERIAL_DEVICE *) g_rdpdr_device[index].pdevice_data; |
944 |
|
|
|
|
|
945 |
ioctl(handle, TIOCINQ, &bytes); |
ioctl(handle, TIOCINQ, &bytes); |
946 |
|
|
947 |
if (bytes > 0) |
if (bytes > 0) |
977 |
{ |
{ |
978 |
pser_inf->event_rlsd = 0; |
pser_inf->event_rlsd = 0; |
979 |
} |
} |
980 |
|
#endif |
981 |
|
|
982 |
|
#ifdef TIOCOUTQ |
983 |
ioctl(handle, TIOCOUTQ, &bytes); |
ioctl(handle, TIOCOUTQ, &bytes); |
984 |
if ((bytes == 0) |
if ((bytes == 0) |
985 |
&& (pser_inf->event_txempty > 0) && (pser_inf->wait_mask & SERIAL_EV_TXEMPTY)) |
&& (pser_inf->event_txempty > 0) && (pser_inf->wait_mask & SERIAL_EV_TXEMPTY)) |
990 |
ret = True; |
ret = True; |
991 |
} |
} |
992 |
pser_inf->event_txempty = bytes; |
pser_inf->event_txempty = bytes; |
993 |
|
#endif |
994 |
|
|
995 |
ioctl(handle, TIOCMGET, &bytes); |
ioctl(handle, TIOCMGET, &bytes); |
996 |
if ((bytes & TIOCM_DSR) != pser_inf->event_dsr) |
if ((bytes & TIOCM_DSR) != pser_inf->event_dsr) |
998 |
pser_inf->event_dsr = bytes & TIOCM_DSR; |
pser_inf->event_dsr = bytes & TIOCM_DSR; |
999 |
if (pser_inf->wait_mask & SERIAL_EV_DSR) |
if (pser_inf->wait_mask & SERIAL_EV_DSR) |
1000 |
{ |
{ |
1001 |
DEBUG_SERIAL(("event -> SERIAL_EV_DSR %s\n", (bytes & TIOCM_DSR) ? "ON" : "OFF")); |
DEBUG_SERIAL(("event -> SERIAL_EV_DSR %s\n", |
1002 |
|
(bytes & TIOCM_DSR) ? "ON" : "OFF")); |
1003 |
*result |= SERIAL_EV_DSR; |
*result |= SERIAL_EV_DSR; |
1004 |
ret = True; |
ret = True; |
1005 |
} |
} |
1010 |
pser_inf->event_cts = bytes & TIOCM_CTS; |
pser_inf->event_cts = bytes & TIOCM_CTS; |
1011 |
if (pser_inf->wait_mask & SERIAL_EV_CTS) |
if (pser_inf->wait_mask & SERIAL_EV_CTS) |
1012 |
{ |
{ |
1013 |
DEBUG_SERIAL((" EVENT-> SERIAL_EV_CTS %s\n", (bytes & TIOCM_CTS) ? "ON" : "OFF")); |
DEBUG_SERIAL((" EVENT-> SERIAL_EV_CTS %s\n", |
1014 |
|
(bytes & TIOCM_CTS) ? "ON" : "OFF")); |
1015 |
*result |= SERIAL_EV_CTS; |
*result |= SERIAL_EV_CTS; |
1016 |
ret = True; |
ret = True; |
1017 |
} |
} |