--- sourceforge.net/trunk/rdesktop/serial.c 2004/04/17 07:24:22 665 +++ sourceforge.net/trunk/rdesktop/serial.c 2004/10/07 13:00:29 782 @@ -2,6 +2,7 @@ #include #include #include +#include #include "rdesktop.h" #define FILE_DEVICE_SERIAL_PORT 0x1b @@ -73,11 +74,21 @@ #define SERIAL_EV_EVENT1 0x0800 // Provider specific event 1 #define SERIAL_EV_EVENT2 0x1000 // Provider specific event 2 +/* Modem Status */ +#define SERIAL_MS_CTS 0x10 +#define SERIAL_MS_DSR 0x20 +#define SERIAL_MS_RNG 0x40 +#define SERIAL_MS_CAR 0x80 + +#ifndef CRTSCTS +#define CRTSCTS 0 +#endif + extern RDPDR_DEVICE g_rdpdr_device[]; static SERIAL_DEVICE * -get_serial_info(HANDLE handle) +get_serial_info(NTHANDLE handle) { int index; @@ -90,7 +101,7 @@ } static BOOL -get_termios(SERIAL_DEVICE * pser_inf, HANDLE serial_fd) +get_termios(SERIAL_DEVICE * pser_inf, NTHANDLE serial_fd) { speed_t speed; struct termios *ptermios; @@ -213,7 +224,7 @@ } static void -set_termios(SERIAL_DEVICE * pser_inf, HANDLE serial_fd) +set_termios(SERIAL_DEVICE * pser_inf, NTHANDLE serial_fd) { speed_t speed; @@ -370,7 +381,9 @@ // Init data structures for device pser_inf = (SERIAL_DEVICE *) xmalloc(sizeof(SERIAL_DEVICE)); pser_inf->ptermios = (struct termios *) xmalloc(sizeof(struct termios)); + memset(pser_inf->ptermios, 0, sizeof(struct termios)); pser_inf->pold_termios = (struct termios *) xmalloc(sizeof(struct termios)); + memset(pser_inf->pold_termios, 0, sizeof(struct termios)); pos2 = next_arg(optarg, '='); strcpy(g_rdpdr_device[*id].name, optarg); @@ -394,15 +407,15 @@ static NTSTATUS serial_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, - uint32 flags_and_attributes, char *filename, HANDLE * handle) + uint32 flags_and_attributes, char *filename, NTHANDLE * handle) { - HANDLE serial_fd; + NTHANDLE serial_fd; SERIAL_DEVICE *pser_inf; struct termios *ptermios; pser_inf = (SERIAL_DEVICE *) g_rdpdr_device[device_id].pdevice_data; ptermios = pser_inf->ptermios; - serial_fd = open(g_rdpdr_device[device_id].local_path, O_RDWR | O_NOCTTY); + serial_fd = open(g_rdpdr_device[device_id].local_path, O_RDWR | O_NOCTTY | O_NONBLOCK); if (serial_fd == -1) { @@ -432,6 +445,13 @@ tcsetattr(serial_fd, TCSANOW, ptermios); */ + pser_inf->ptermios->c_iflag &= + ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); + pser_inf->ptermios->c_oflag &= ~OPOST; + pser_inf->ptermios->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); + pser_inf->ptermios->c_cflag &= ~(CSIZE | PARENB); + pser_inf->ptermios->c_cflag |= CS8; + tcsetattr(serial_fd, TCSANOW, pser_inf->ptermios); *handle = serial_fd; @@ -443,7 +463,7 @@ } static NTSTATUS -serial_close(HANDLE handle) +serial_close(NTHANDLE handle) { int i = get_device_index(handle); if (i >= 0) @@ -453,7 +473,7 @@ } static NTSTATUS -serial_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) +serial_read(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) { long timeout; SERIAL_DEVICE *pser_inf; @@ -500,17 +520,19 @@ } static NTSTATUS -serial_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) +serial_write(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) { *result = write(handle, data, length); return STATUS_SUCCESS; } static NTSTATUS -serial_device_control(HANDLE handle, uint32 request, STREAM in, STREAM out) +serial_device_control(NTHANDLE handle, uint32 request, STREAM in, STREAM out) { +#if 0 int flush_mask, purge_mask; - uint32 result; +#endif + uint32 result, modemstate; uint8 immediate; SERIAL_DEVICE *pser_inf; struct termios *ptermios; @@ -602,7 +624,19 @@ set_termios(pser_inf, handle); break; case SERIAL_GET_MODEMSTATUS: - out_uint32_le(out, 0); /* Errors */ + modemstate = 0; +#ifdef TIOCMGET + ioctl(handle, TIOCMGET, &result); + if (result & TIOCM_CTS) + modemstate |= SERIAL_MS_CTS; + if (result & TIOCM_DSR) + modemstate |= SERIAL_MS_DSR; + if (result & TIOCM_RNG) + modemstate |= SERIAL_MS_RNG; + if (result & TIOCM_CAR) + modemstate |= SERIAL_MS_CAR; +#endif + out_uint32_le(out, modemstate); break; case SERIAL_GET_COMMSTATUS: out_uint32_le(out, 0); /* Errors */ @@ -651,7 +685,7 @@ /* Read timeout for a given file descripter (device) when adding fd's to select() */ BOOL -serial_get_timeout(HANDLE handle, uint32 length, uint32 * timeout, uint32 * itv_timeout) +serial_get_timeout(NTHANDLE handle, uint32 length, uint32 * timeout, uint32 * itv_timeout) { int index; SERIAL_DEVICE *pser_inf;