2 |
#include <fcntl.h> |
#include <fcntl.h> |
3 |
#include <termios.h> |
#include <termios.h> |
4 |
#include <strings.h> |
#include <strings.h> |
5 |
|
#include <sys/ioctl.h> |
6 |
#include "rdesktop.h" |
#include "rdesktop.h" |
7 |
|
|
8 |
#define FILE_DEVICE_SERIAL_PORT 0x1b |
#define FILE_DEVICE_SERIAL_PORT 0x1b |
74 |
#define SERIAL_EV_EVENT1 0x0800 // Provider specific event 1 |
#define SERIAL_EV_EVENT1 0x0800 // Provider specific event 1 |
75 |
#define SERIAL_EV_EVENT2 0x1000 // Provider specific event 2 |
#define SERIAL_EV_EVENT2 0x1000 // Provider specific event 2 |
76 |
|
|
77 |
|
/* Modem Status */ |
78 |
|
#define SERIAL_MS_CTS 0x10 |
79 |
|
#define SERIAL_MS_DSR 0x20 |
80 |
|
#define SERIAL_MS_RNG 0x40 |
81 |
|
#define SERIAL_MS_CAR 0x80 |
82 |
|
|
83 |
|
#ifndef CRTSCTS |
84 |
|
#define CRTSCTS 0 |
85 |
|
#endif |
86 |
|
|
87 |
|
|
88 |
extern RDPDR_DEVICE g_rdpdr_device[]; |
extern RDPDR_DEVICE g_rdpdr_device[]; |
89 |
|
|
90 |
static SERIAL_DEVICE * |
static SERIAL_DEVICE * |
91 |
get_serial_info(HANDLE handle) |
get_serial_info(NTHANDLE handle) |
92 |
{ |
{ |
93 |
int index; |
int index; |
94 |
|
|
101 |
} |
} |
102 |
|
|
103 |
static BOOL |
static BOOL |
104 |
get_termios(SERIAL_DEVICE * pser_inf, HANDLE serial_fd) |
get_termios(SERIAL_DEVICE * pser_inf, NTHANDLE serial_fd) |
105 |
{ |
{ |
106 |
speed_t speed; |
speed_t speed; |
107 |
struct termios *ptermios; |
struct termios *ptermios; |
224 |
} |
} |
225 |
|
|
226 |
static void |
static void |
227 |
set_termios(SERIAL_DEVICE * pser_inf, HANDLE serial_fd) |
set_termios(SERIAL_DEVICE * pser_inf, NTHANDLE serial_fd) |
228 |
{ |
{ |
229 |
speed_t speed; |
speed_t speed; |
230 |
|
|
381 |
// Init data structures for device |
// Init data structures for device |
382 |
pser_inf = (SERIAL_DEVICE *) xmalloc(sizeof(SERIAL_DEVICE)); |
pser_inf = (SERIAL_DEVICE *) xmalloc(sizeof(SERIAL_DEVICE)); |
383 |
pser_inf->ptermios = (struct termios *) xmalloc(sizeof(struct termios)); |
pser_inf->ptermios = (struct termios *) xmalloc(sizeof(struct termios)); |
384 |
|
memset(pser_inf->ptermios, 0, sizeof(struct termios)); |
385 |
pser_inf->pold_termios = (struct termios *) xmalloc(sizeof(struct termios)); |
pser_inf->pold_termios = (struct termios *) xmalloc(sizeof(struct termios)); |
386 |
|
memset(pser_inf->pold_termios, 0, sizeof(struct termios)); |
387 |
|
|
388 |
pos2 = next_arg(optarg, '='); |
pos2 = next_arg(optarg, '='); |
389 |
strcpy(g_rdpdr_device[*id].name, optarg); |
strcpy(g_rdpdr_device[*id].name, optarg); |
407 |
|
|
408 |
static NTSTATUS |
static NTSTATUS |
409 |
serial_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, |
serial_create(uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, |
410 |
uint32 flags_and_attributes, char *filename, HANDLE * handle) |
uint32 flags_and_attributes, char *filename, NTHANDLE * handle) |
411 |
{ |
{ |
412 |
HANDLE serial_fd; |
NTHANDLE serial_fd; |
413 |
SERIAL_DEVICE *pser_inf; |
SERIAL_DEVICE *pser_inf; |
414 |
struct termios *ptermios; |
struct termios *ptermios; |
415 |
|
|
416 |
pser_inf = (SERIAL_DEVICE *) g_rdpdr_device[device_id].pdevice_data; |
pser_inf = (SERIAL_DEVICE *) g_rdpdr_device[device_id].pdevice_data; |
417 |
ptermios = pser_inf->ptermios; |
ptermios = pser_inf->ptermios; |
418 |
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); |
419 |
|
|
420 |
if (serial_fd == -1) |
if (serial_fd == -1) |
421 |
{ |
{ |
445 |
|
|
446 |
tcsetattr(serial_fd, TCSANOW, ptermios); |
tcsetattr(serial_fd, TCSANOW, ptermios); |
447 |
*/ |
*/ |
448 |
|
pser_inf->ptermios->c_iflag &= |
449 |
|
~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON); |
450 |
|
pser_inf->ptermios->c_oflag &= ~OPOST; |
451 |
|
pser_inf->ptermios->c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN); |
452 |
|
pser_inf->ptermios->c_cflag &= ~(CSIZE | PARENB); |
453 |
|
pser_inf->ptermios->c_cflag |= CS8; |
454 |
|
tcsetattr(serial_fd, TCSANOW, pser_inf->ptermios); |
455 |
|
|
456 |
*handle = serial_fd; |
*handle = serial_fd; |
457 |
|
|
463 |
} |
} |
464 |
|
|
465 |
static NTSTATUS |
static NTSTATUS |
466 |
serial_close(HANDLE handle) |
serial_close(NTHANDLE handle) |
467 |
{ |
{ |
468 |
int i = get_device_index(handle); |
int i = get_device_index(handle); |
469 |
if (i >= 0) |
if (i >= 0) |
473 |
} |
} |
474 |
|
|
475 |
static NTSTATUS |
static NTSTATUS |
476 |
serial_read(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
serial_read(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
477 |
{ |
{ |
478 |
long timeout; |
long timeout; |
479 |
SERIAL_DEVICE *pser_inf; |
SERIAL_DEVICE *pser_inf; |
520 |
} |
} |
521 |
|
|
522 |
static NTSTATUS |
static NTSTATUS |
523 |
serial_write(HANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
serial_write(NTHANDLE handle, uint8 * data, uint32 length, uint32 offset, uint32 * result) |
524 |
{ |
{ |
525 |
*result = write(handle, data, length); |
*result = write(handle, data, length); |
526 |
return STATUS_SUCCESS; |
return STATUS_SUCCESS; |
527 |
} |
} |
528 |
|
|
529 |
static NTSTATUS |
static NTSTATUS |
530 |
serial_device_control(HANDLE handle, uint32 request, STREAM in, STREAM out) |
serial_device_control(NTHANDLE handle, uint32 request, STREAM in, STREAM out) |
531 |
{ |
{ |
532 |
|
#if 0 |
533 |
int flush_mask, purge_mask; |
int flush_mask, purge_mask; |
534 |
uint32 result; |
#endif |
535 |
|
uint32 result, modemstate; |
536 |
uint8 immediate; |
uint8 immediate; |
537 |
SERIAL_DEVICE *pser_inf; |
SERIAL_DEVICE *pser_inf; |
538 |
struct termios *ptermios; |
struct termios *ptermios; |
624 |
set_termios(pser_inf, handle); |
set_termios(pser_inf, handle); |
625 |
break; |
break; |
626 |
case SERIAL_GET_MODEMSTATUS: |
case SERIAL_GET_MODEMSTATUS: |
627 |
out_uint32_le(out, 0); /* Errors */ |
modemstate = 0; |
628 |
|
#ifdef TIOCMGET |
629 |
|
ioctl(handle, TIOCMGET, &result); |
630 |
|
if (result & TIOCM_CTS) |
631 |
|
modemstate |= SERIAL_MS_CTS; |
632 |
|
if (result & TIOCM_DSR) |
633 |
|
modemstate |= SERIAL_MS_DSR; |
634 |
|
if (result & TIOCM_RNG) |
635 |
|
modemstate |= SERIAL_MS_RNG; |
636 |
|
if (result & TIOCM_CAR) |
637 |
|
modemstate |= SERIAL_MS_CAR; |
638 |
|
#endif |
639 |
|
out_uint32_le(out, modemstate); |
640 |
break; |
break; |
641 |
case SERIAL_GET_COMMSTATUS: |
case SERIAL_GET_COMMSTATUS: |
642 |
out_uint32_le(out, 0); /* Errors */ |
out_uint32_le(out, 0); /* Errors */ |
685 |
|
|
686 |
/* Read timeout for a given file descripter (device) when adding fd's to select() */ |
/* Read timeout for a given file descripter (device) when adding fd's to select() */ |
687 |
BOOL |
BOOL |
688 |
serial_get_timeout(HANDLE handle, uint32 length, uint32 * timeout, uint32 * itv_timeout) |
serial_get_timeout(NTHANDLE handle, uint32 length, uint32 * timeout, uint32 * itv_timeout) |
689 |
{ |
{ |
690 |
int index; |
int index; |
691 |
SERIAL_DEVICE *pser_inf; |
SERIAL_DEVICE *pser_inf; |