77 |
#define SERIAL_PURGE_RXCLEAR 0x00000008 |
#define SERIAL_PURGE_RXCLEAR 0x00000008 |
78 |
|
|
79 |
/* SERIAL_WAIT_ON_MASK */ |
/* SERIAL_WAIT_ON_MASK */ |
80 |
#define SERIAL_EV_RXCHAR 0x0001 // Any Character received |
#define SERIAL_EV_RXCHAR 0x0001 /* Any Character received */ |
81 |
#define SERIAL_EV_RXFLAG 0x0002 // Received certain character |
#define SERIAL_EV_RXFLAG 0x0002 /* Received certain character */ |
82 |
#define SERIAL_EV_TXEMPTY 0x0004 // Transmitt Queue Empty |
#define SERIAL_EV_TXEMPTY 0x0004 /* Transmitt Queue Empty */ |
83 |
#define SERIAL_EV_CTS 0x0008 // CTS changed state |
#define SERIAL_EV_CTS 0x0008 /* CTS changed state */ |
84 |
#define SERIAL_EV_DSR 0x0010 // DSR changed state |
#define SERIAL_EV_DSR 0x0010 /* DSR changed state */ |
85 |
#define SERIAL_EV_RLSD 0x0020 // RLSD changed state |
#define SERIAL_EV_RLSD 0x0020 /* RLSD changed state */ |
86 |
#define SERIAL_EV_BREAK 0x0040 // BREAK received |
#define SERIAL_EV_BREAK 0x0040 /* BREAK received */ |
87 |
#define SERIAL_EV_ERR 0x0080 // Line status error occurred |
#define SERIAL_EV_ERR 0x0080 /* Line status error occurred */ |
88 |
#define SERIAL_EV_RING 0x0100 // Ring signal detected |
#define SERIAL_EV_RING 0x0100 /* Ring signal detected */ |
89 |
#define SERIAL_EV_PERR 0x0200 // Printer error occured |
#define SERIAL_EV_PERR 0x0200 /* Printer error occured */ |
90 |
#define SERIAL_EV_RX80FULL 0x0400 // Receive buffer is 80 percent full |
#define SERIAL_EV_RX80FULL 0x0400 /* Receive buffer is 80 percent full */ |
91 |
#define SERIAL_EV_EVENT1 0x0800 // Provider specific event 1 |
#define SERIAL_EV_EVENT1 0x0800 /* Provider specific event 1 */ |
92 |
#define SERIAL_EV_EVENT2 0x1000 // Provider specific event 2 |
#define SERIAL_EV_EVENT2 0x1000 /* Provider specific event 2 */ |
93 |
|
|
94 |
/* Modem Status */ |
/* Modem Status */ |
95 |
#define SERIAL_MS_DTR 0x01 |
#define SERIAL_MS_DTR 0x01 |
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) |
125 |
#define TIOCINQ FIONREAD |
#define TIOCINQ FIONREAD |
126 |
#endif |
#endif |
127 |
#ifndef TIOCOUTQ |
#if !defined(TIOCOUTQ) && defined(FIONWRITE) |
128 |
#define TIOCOUTQ FIONWRITE |
#define TIOCOUTQ FIONWRITE |
129 |
#endif |
#endif |
130 |
|
|
503 |
char *pos2; |
char *pos2; |
504 |
int count = 0; |
int count = 0; |
505 |
|
|
506 |
// skip the first colon |
/* skip the first colon */ |
507 |
optarg++; |
optarg++; |
508 |
while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES) |
while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES) |
509 |
{ |
{ |
510 |
// Init data structures for device |
/* Init data structures for device */ |
511 |
pser_inf = (SERIAL_DEVICE *) xmalloc(sizeof(SERIAL_DEVICE)); |
pser_inf = (SERIAL_DEVICE *) xmalloc(sizeof(SERIAL_DEVICE)); |
512 |
pser_inf->ptermios = (struct termios *) xmalloc(sizeof(struct termios)); |
pser_inf->ptermios = (struct termios *) xmalloc(sizeof(struct termios)); |
513 |
memset(pser_inf->ptermios, 0, sizeof(struct termios)); |
memset(pser_inf->ptermios, 0, sizeof(struct termios)); |
523 |
strcpy(g_rdpdr_device[*id].local_path, pos2); |
strcpy(g_rdpdr_device[*id].local_path, pos2); |
524 |
printf("SERIAL %s to %s\n", g_rdpdr_device[*id].name, |
printf("SERIAL %s to %s\n", g_rdpdr_device[*id].name, |
525 |
g_rdpdr_device[*id].local_path); |
g_rdpdr_device[*id].local_path); |
526 |
// set device type |
/* set device type */ |
527 |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_SERIAL; |
g_rdpdr_device[*id].device_type = DEVICE_TYPE_SERIAL; |
528 |
g_rdpdr_device[*id].pdevice_data = (void *) pser_inf; |
g_rdpdr_device[*id].pdevice_data = (void *) pser_inf; |
529 |
count++; |
count++; |
559 |
return STATUS_ACCESS_DENIED; |
return STATUS_ACCESS_DENIED; |
560 |
} |
} |
561 |
|
|
562 |
// Store handle for later use |
/* Store handle for later use */ |
563 |
g_rdpdr_device[device_id].handle = serial_fd; |
g_rdpdr_device[device_id].handle = serial_fd; |
564 |
|
|
565 |
/* some sane information */ |
/* some sane information */ |
618 |
pser_inf = get_serial_info(handle); |
pser_inf = get_serial_info(handle); |
619 |
ptermios = pser_inf->ptermios; |
ptermios = pser_inf->ptermios; |
620 |
|
|
621 |
// Set timeouts kind of like the windows serial timeout parameters. Multiply timeout |
/* Set timeouts kind of like the windows serial timeout parameters. Multiply timeout |
622 |
// with requested read size |
with requested read size */ |
623 |
if (pser_inf->read_total_timeout_multiplier | pser_inf->read_total_timeout_constant) |
if (pser_inf->read_total_timeout_multiplier | pser_inf->read_total_timeout_constant) |
624 |
{ |
{ |
625 |
timeout = |
timeout = |
631 |
timeout = (pser_inf->read_interval_timeout * length + 99) / 100; |
timeout = (pser_inf->read_interval_timeout * length + 99) / 100; |
632 |
} |
} |
633 |
|
|
634 |
// If a timeout is set, do a blocking read, which times out after some time. |
/* If a timeout is set, do a blocking read, which times out after some time. |
635 |
// It will make rdesktop less responsive, but it will improve serial performance, by not |
It will make rdesktop less responsive, but it will improve serial performance, by not |
636 |
// reading one character at a time. |
reading one character at a time. */ |
637 |
if (timeout == 0) |
if (timeout == 0) |
638 |
{ |
{ |
639 |
ptermios->c_cc[VTIME] = 0; |
ptermios->c_cc[VTIME] = 0; |
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 |
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", |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_WAIT_MASK %X\n", |
797 |
pser_inf->wait_mask); 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); |
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", |
DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS in queue %d\n", |
864 |
result)); |
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)); |
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) |