ReactOS  0.4.14-dev-114-gc8cbd56
serial.c File Reference
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <strings.h>
#include <sys/ioctl.h>
#include "rdesktop.h"
Include dependency graph for serial.c:

Go to the source code of this file.

Macros

#define DEBUG_SERIAL(args)
 
#define FILE_DEVICE_SERIAL_PORT   0x1b
 
#define SERIAL_SET_BAUD_RATE   1
 
#define SERIAL_SET_QUEUE_SIZE   2
 
#define SERIAL_SET_LINE_CONTROL   3
 
#define SERIAL_SET_BREAK_ON   4
 
#define SERIAL_SET_BREAK_OFF   5
 
#define SERIAL_IMMEDIATE_CHAR   6
 
#define SERIAL_SET_TIMEOUTS   7
 
#define SERIAL_GET_TIMEOUTS   8
 
#define SERIAL_SET_DTR   9
 
#define SERIAL_CLR_DTR   10
 
#define SERIAL_RESET_DEVICE   11
 
#define SERIAL_SET_RTS   12
 
#define SERIAL_CLR_RTS   13
 
#define SERIAL_SET_XOFF   14
 
#define SERIAL_SET_XON   15
 
#define SERIAL_GET_WAIT_MASK   16
 
#define SERIAL_SET_WAIT_MASK   17
 
#define SERIAL_WAIT_ON_MASK   18
 
#define SERIAL_PURGE   19
 
#define SERIAL_GET_BAUD_RATE   20
 
#define SERIAL_GET_LINE_CONTROL   21
 
#define SERIAL_GET_CHARS   22
 
#define SERIAL_SET_CHARS   23
 
#define SERIAL_GET_HANDFLOW   24
 
#define SERIAL_SET_HANDFLOW   25
 
#define SERIAL_GET_MODEMSTATUS   26
 
#define SERIAL_GET_COMMSTATUS   27
 
#define SERIAL_XOFF_COUNTER   28
 
#define SERIAL_GET_PROPERTIES   29
 
#define SERIAL_GET_DTRRTS   30
 
#define SERIAL_LSRMST_INSERT   31
 
#define SERIAL_CONFIG_SIZE   32
 
#define SERIAL_GET_COMMCONFIG   33
 
#define SERIAL_SET_COMMCONFIG   34
 
#define SERIAL_GET_STATS   35
 
#define SERIAL_CLEAR_STATS   36
 
#define SERIAL_GET_MODEM_CONTROL   37
 
#define SERIAL_SET_MODEM_CONTROL   38
 
#define SERIAL_SET_FIFO_CONTROL   39
 
#define STOP_BITS_1   0
 
#define STOP_BITS_2   2
 
#define NO_PARITY   0
 
#define ODD_PARITY   1
 
#define EVEN_PARITY   2
 
#define SERIAL_PURGE_TXABORT   0x00000001
 
#define SERIAL_PURGE_RXABORT   0x00000002
 
#define SERIAL_PURGE_TXCLEAR   0x00000004
 
#define SERIAL_PURGE_RXCLEAR   0x00000008
 
#define SERIAL_EV_RXCHAR   0x0001 /* Any Character received */
 
#define SERIAL_EV_RXFLAG   0x0002 /* Received certain character */
 
#define SERIAL_EV_TXEMPTY   0x0004 /* Transmitt Queue Empty */
 
#define SERIAL_EV_CTS   0x0008 /* CTS changed state */
 
#define SERIAL_EV_DSR   0x0010 /* DSR changed state */
 
#define SERIAL_EV_RLSD   0x0020 /* RLSD changed state */
 
#define SERIAL_EV_BREAK   0x0040 /* BREAK received */
 
#define SERIAL_EV_ERR   0x0080 /* Line status error occurred */
 
#define SERIAL_EV_RING   0x0100 /* Ring signal detected */
 
#define SERIAL_EV_PERR   0x0200 /* Printer error occured */
 
#define SERIAL_EV_RX80FULL   0x0400 /* Receive buffer is 80 percent full */
 
#define SERIAL_EV_EVENT1   0x0800 /* Provider specific event 1 */
 
#define SERIAL_EV_EVENT2   0x1000 /* Provider specific event 2 */
 
#define SERIAL_MS_DTR   0x01
 
#define SERIAL_MS_RTS   0x02
 
#define SERIAL_MS_CTS   0x10
 
#define SERIAL_MS_DSR   0x20
 
#define SERIAL_MS_RNG   0x40
 
#define SERIAL_MS_CAR   0x80
 
#define SERIAL_DTR_CONTROL   0x01
 
#define SERIAL_CTS_HANDSHAKE   0x08
 
#define SERIAL_ERROR_ABORT   0x80000000
 
#define SERIAL_XON_HANDSHAKE   0x01
 
#define SERIAL_XOFF_HANDSHAKE   0x02
 
#define SERIAL_DSR_SENSITIVITY   0x40
 
#define SERIAL_CHAR_EOF   0
 
#define SERIAL_CHAR_ERROR   1
 
#define SERIAL_CHAR_BREAK   2
 
#define SERIAL_CHAR_EVENT   3
 
#define SERIAL_CHAR_XON   4
 
#define SERIAL_CHAR_XOFF   5
 
#define CRTSCTS   0
 

Functions

static SERIAL_DEVICEget_serial_info (RDPCLIENT *This, NTHANDLE handle)
 
static BOOL get_termios (SERIAL_DEVICE *pser_inf, NTHANDLE serial_fd)
 
static void set_termios (SERIAL_DEVICE *pser_inf, NTHANDLE serial_fd)
 
int serial_enum_devices (RDPCLIENT *This, uint32 *id, char *optarg)
 
static NTSTATUS serial_create (RDPCLIENT *This, uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, uint32 flags_and_attributes, char *filename, NTHANDLE *handle)
 
static NTSTATUS serial_close (RDPCLIENT *This, NTHANDLE handle)
 
static NTSTATUS serial_read (RDPCLIENT *This, NTHANDLE handle, uint8 *data, uint32 length, uint32 offset, uint32 *result)
 
static NTSTATUS serial_write (RDPCLIENT *This, NTHANDLE handle, uint8 *data, uint32 length, uint32 offset, uint32 *result)
 
static NTSTATUS serial_device_control (RDPCLIENT *This, NTHANDLE handle, uint32 request, STREAM in, STREAM out)
 
BOOL serial_get_event (RDPCLIENT *This, NTHANDLE handle, uint32 *result)
 
BOOL serial_get_timeout (RDPCLIENT *This, NTHANDLE handle, uint32 length, uint32 *timeout, uint32 *itv_timeout)
 

Variables

DEVICE_FNS serial_fns
 

Macro Definition Documentation

◆ CRTSCTS

#define CRTSCTS   0

Definition at line 138 of file serial.c.

◆ DEBUG_SERIAL

#define DEBUG_SERIAL (   args)

Definition at line 41 of file serial.c.

◆ EVEN_PARITY

#define EVEN_PARITY   2

Definition at line 91 of file serial.c.

◆ FILE_DEVICE_SERIAL_PORT

#define FILE_DEVICE_SERIAL_PORT   0x1b

Definition at line 44 of file serial.c.

◆ NO_PARITY

#define NO_PARITY   0

Definition at line 89 of file serial.c.

◆ ODD_PARITY

#define ODD_PARITY   1

Definition at line 90 of file serial.c.

◆ SERIAL_CHAR_BREAK

#define SERIAL_CHAR_BREAK   2

Definition at line 132 of file serial.c.

◆ SERIAL_CHAR_EOF

#define SERIAL_CHAR_EOF   0

Definition at line 130 of file serial.c.

◆ SERIAL_CHAR_ERROR

#define SERIAL_CHAR_ERROR   1

Definition at line 131 of file serial.c.

◆ SERIAL_CHAR_EVENT

#define SERIAL_CHAR_EVENT   3

Definition at line 133 of file serial.c.

◆ SERIAL_CHAR_XOFF

#define SERIAL_CHAR_XOFF   5

Definition at line 135 of file serial.c.

◆ SERIAL_CHAR_XON

#define SERIAL_CHAR_XON   4

Definition at line 134 of file serial.c.

◆ SERIAL_CLEAR_STATS

#define SERIAL_CLEAR_STATS   36

Definition at line 81 of file serial.c.

◆ SERIAL_CLR_DTR

#define SERIAL_CLR_DTR   10

Definition at line 55 of file serial.c.

◆ SERIAL_CLR_RTS

#define SERIAL_CLR_RTS   13

Definition at line 58 of file serial.c.

◆ SERIAL_CONFIG_SIZE

#define SERIAL_CONFIG_SIZE   32

Definition at line 77 of file serial.c.

◆ SERIAL_CTS_HANDSHAKE

#define SERIAL_CTS_HANDSHAKE   0x08

Definition at line 123 of file serial.c.

◆ SERIAL_DSR_SENSITIVITY

#define SERIAL_DSR_SENSITIVITY   0x40

Definition at line 128 of file serial.c.

◆ SERIAL_DTR_CONTROL

#define SERIAL_DTR_CONTROL   0x01

Definition at line 122 of file serial.c.

◆ SERIAL_ERROR_ABORT

#define SERIAL_ERROR_ABORT   0x80000000

Definition at line 124 of file serial.c.

◆ SERIAL_EV_BREAK

#define SERIAL_EV_BREAK   0x0040 /* BREAK received */

Definition at line 105 of file serial.c.

◆ SERIAL_EV_CTS

#define SERIAL_EV_CTS   0x0008 /* CTS changed state */

Definition at line 102 of file serial.c.

◆ SERIAL_EV_DSR

#define SERIAL_EV_DSR   0x0010 /* DSR changed state */

Definition at line 103 of file serial.c.

◆ SERIAL_EV_ERR

#define SERIAL_EV_ERR   0x0080 /* Line status error occurred */

Definition at line 106 of file serial.c.

◆ SERIAL_EV_EVENT1

#define SERIAL_EV_EVENT1   0x0800 /* Provider specific event 1 */

Definition at line 110 of file serial.c.

◆ SERIAL_EV_EVENT2

#define SERIAL_EV_EVENT2   0x1000 /* Provider specific event 2 */

Definition at line 111 of file serial.c.

◆ SERIAL_EV_PERR

#define SERIAL_EV_PERR   0x0200 /* Printer error occured */

Definition at line 108 of file serial.c.

◆ SERIAL_EV_RING

#define SERIAL_EV_RING   0x0100 /* Ring signal detected */

Definition at line 107 of file serial.c.

◆ SERIAL_EV_RLSD

#define SERIAL_EV_RLSD   0x0020 /* RLSD changed state */

Definition at line 104 of file serial.c.

◆ SERIAL_EV_RX80FULL

#define SERIAL_EV_RX80FULL   0x0400 /* Receive buffer is 80 percent full */

Definition at line 109 of file serial.c.

◆ SERIAL_EV_RXCHAR

#define SERIAL_EV_RXCHAR   0x0001 /* Any Character received */

Definition at line 99 of file serial.c.

◆ SERIAL_EV_RXFLAG

#define SERIAL_EV_RXFLAG   0x0002 /* Received certain character */

Definition at line 100 of file serial.c.

◆ SERIAL_EV_TXEMPTY

#define SERIAL_EV_TXEMPTY   0x0004 /* Transmitt Queue Empty */

Definition at line 101 of file serial.c.

◆ SERIAL_GET_BAUD_RATE

#define SERIAL_GET_BAUD_RATE   20

Definition at line 65 of file serial.c.

◆ SERIAL_GET_CHARS

#define SERIAL_GET_CHARS   22

Definition at line 67 of file serial.c.

◆ SERIAL_GET_COMMCONFIG

#define SERIAL_GET_COMMCONFIG   33

Definition at line 78 of file serial.c.

◆ SERIAL_GET_COMMSTATUS

#define SERIAL_GET_COMMSTATUS   27

Definition at line 72 of file serial.c.

◆ SERIAL_GET_DTRRTS

#define SERIAL_GET_DTRRTS   30

Definition at line 75 of file serial.c.

◆ SERIAL_GET_HANDFLOW

#define SERIAL_GET_HANDFLOW   24

Definition at line 69 of file serial.c.

◆ SERIAL_GET_LINE_CONTROL

#define SERIAL_GET_LINE_CONTROL   21

Definition at line 66 of file serial.c.

◆ SERIAL_GET_MODEM_CONTROL

#define SERIAL_GET_MODEM_CONTROL   37

Definition at line 82 of file serial.c.

◆ SERIAL_GET_MODEMSTATUS

#define SERIAL_GET_MODEMSTATUS   26

Definition at line 71 of file serial.c.

◆ SERIAL_GET_PROPERTIES

#define SERIAL_GET_PROPERTIES   29

Definition at line 74 of file serial.c.

◆ SERIAL_GET_STATS

#define SERIAL_GET_STATS   35

Definition at line 80 of file serial.c.

◆ SERIAL_GET_TIMEOUTS

#define SERIAL_GET_TIMEOUTS   8

Definition at line 53 of file serial.c.

◆ SERIAL_GET_WAIT_MASK

#define SERIAL_GET_WAIT_MASK   16

Definition at line 61 of file serial.c.

◆ SERIAL_IMMEDIATE_CHAR

#define SERIAL_IMMEDIATE_CHAR   6

Definition at line 51 of file serial.c.

◆ SERIAL_LSRMST_INSERT

#define SERIAL_LSRMST_INSERT   31

Definition at line 76 of file serial.c.

◆ SERIAL_MS_CAR

#define SERIAL_MS_CAR   0x80

Definition at line 119 of file serial.c.

◆ SERIAL_MS_CTS

#define SERIAL_MS_CTS   0x10

Definition at line 116 of file serial.c.

◆ SERIAL_MS_DSR

#define SERIAL_MS_DSR   0x20

Definition at line 117 of file serial.c.

◆ SERIAL_MS_DTR

#define SERIAL_MS_DTR   0x01

Definition at line 114 of file serial.c.

◆ SERIAL_MS_RNG

#define SERIAL_MS_RNG   0x40

Definition at line 118 of file serial.c.

◆ SERIAL_MS_RTS

#define SERIAL_MS_RTS   0x02

Definition at line 115 of file serial.c.

◆ SERIAL_PURGE

#define SERIAL_PURGE   19

Definition at line 64 of file serial.c.

◆ SERIAL_PURGE_RXABORT

#define SERIAL_PURGE_RXABORT   0x00000002

Definition at line 94 of file serial.c.

◆ SERIAL_PURGE_RXCLEAR

#define SERIAL_PURGE_RXCLEAR   0x00000008

Definition at line 96 of file serial.c.

◆ SERIAL_PURGE_TXABORT

#define SERIAL_PURGE_TXABORT   0x00000001

Definition at line 93 of file serial.c.

◆ SERIAL_PURGE_TXCLEAR

#define SERIAL_PURGE_TXCLEAR   0x00000004

Definition at line 95 of file serial.c.

◆ SERIAL_RESET_DEVICE

#define SERIAL_RESET_DEVICE   11

Definition at line 56 of file serial.c.

◆ SERIAL_SET_BAUD_RATE

#define SERIAL_SET_BAUD_RATE   1

Definition at line 46 of file serial.c.

◆ SERIAL_SET_BREAK_OFF

#define SERIAL_SET_BREAK_OFF   5

Definition at line 50 of file serial.c.

◆ SERIAL_SET_BREAK_ON

#define SERIAL_SET_BREAK_ON   4

Definition at line 49 of file serial.c.

◆ SERIAL_SET_CHARS

#define SERIAL_SET_CHARS   23

Definition at line 68 of file serial.c.

◆ SERIAL_SET_COMMCONFIG

#define SERIAL_SET_COMMCONFIG   34

Definition at line 79 of file serial.c.

◆ SERIAL_SET_DTR

#define SERIAL_SET_DTR   9

Definition at line 54 of file serial.c.

◆ SERIAL_SET_FIFO_CONTROL

#define SERIAL_SET_FIFO_CONTROL   39

Definition at line 84 of file serial.c.

◆ SERIAL_SET_HANDFLOW

#define SERIAL_SET_HANDFLOW   25

Definition at line 70 of file serial.c.

◆ SERIAL_SET_LINE_CONTROL

#define SERIAL_SET_LINE_CONTROL   3

Definition at line 48 of file serial.c.

◆ SERIAL_SET_MODEM_CONTROL

#define SERIAL_SET_MODEM_CONTROL   38

Definition at line 83 of file serial.c.

◆ SERIAL_SET_QUEUE_SIZE

#define SERIAL_SET_QUEUE_SIZE   2

Definition at line 47 of file serial.c.

◆ SERIAL_SET_RTS

#define SERIAL_SET_RTS   12

Definition at line 57 of file serial.c.

◆ SERIAL_SET_TIMEOUTS

#define SERIAL_SET_TIMEOUTS   7

Definition at line 52 of file serial.c.

◆ SERIAL_SET_WAIT_MASK

#define SERIAL_SET_WAIT_MASK   17

Definition at line 62 of file serial.c.

◆ SERIAL_SET_XOFF

#define SERIAL_SET_XOFF   14

Definition at line 59 of file serial.c.

◆ SERIAL_SET_XON

#define SERIAL_SET_XON   15

Definition at line 60 of file serial.c.

◆ SERIAL_WAIT_ON_MASK

#define SERIAL_WAIT_ON_MASK   18

Definition at line 63 of file serial.c.

◆ SERIAL_XOFF_COUNTER

Definition at line 73 of file serial.c.

◆ SERIAL_XOFF_HANDSHAKE

#define SERIAL_XOFF_HANDSHAKE   0x02

Definition at line 127 of file serial.c.

◆ SERIAL_XON_HANDSHAKE

#define SERIAL_XON_HANDSHAKE   0x01

Definition at line 126 of file serial.c.

◆ STOP_BITS_1

#define STOP_BITS_1   0

Definition at line 86 of file serial.c.

◆ STOP_BITS_2

#define STOP_BITS_2   2

Definition at line 87 of file serial.c.

Function Documentation

◆ get_serial_info()

static SERIAL_DEVICE* get_serial_info ( RDPCLIENT This,
NTHANDLE  handle 
)
static

Definition at line 151 of file serial.c.

152 {
153  int index;
154 
155  for (index = 0; index < RDPDR_MAX_DEVICES; index++)
156  {
157  if (handle == This->rdpdr_device[index].handle)
158  return (SERIAL_DEVICE *) This->rdpdr_device[index].pdevice_data;
159  }
160  return NULL;
161 }
#define RDPDR_MAX_DEVICES
Definition: constants.h:484
smooth NULL
Definition: ftsmooth.c:416
GLuint index
Definition: glext.h:6031
#define index(s, c)
Definition: various.h:29

Referenced by serial_device_control(), serial_read(), and serial_write().

◆ get_termios()

static BOOL get_termios ( SERIAL_DEVICE pser_inf,
NTHANDLE  serial_fd 
)
static

Definition at line 164 of file serial.c.

165 {
166  speed_t speed;
167  struct termios *ptermios;
168 
169  ptermios = pser_inf->ptermios;
170 
171  if (tcgetattr(serial_fd, ptermios) == -1)
172  return False;
173 
174  speed = cfgetispeed(ptermios);
175  switch (speed)
176  {
177 #ifdef B75
178  case B75:
179  pser_inf->baud_rate = 75;
180  break;
181 #endif
182 #ifdef B110
183  case B110:
184  pser_inf->baud_rate = 110;
185  break;
186 #endif
187 #ifdef B134
188  case B134:
189  pser_inf->baud_rate = 134;
190  break;
191 #endif
192 #ifdef B150
193  case B150:
194  pser_inf->baud_rate = 150;
195  break;
196 #endif
197 #ifdef B300
198  case B300:
199  pser_inf->baud_rate = 300;
200  break;
201 #endif
202 #ifdef B600
203  case B600:
204  pser_inf->baud_rate = 600;
205  break;
206 #endif
207 #ifdef B1200
208  case B1200:
209  pser_inf->baud_rate = 1200;
210  break;
211 #endif
212 #ifdef B1800
213  case B1800:
214  pser_inf->baud_rate = 1800;
215  break;
216 #endif
217 #ifdef B2400
218  case B2400:
219  pser_inf->baud_rate = 2400;
220  break;
221 #endif
222 #ifdef B4800
223  case B4800:
224  pser_inf->baud_rate = 4800;
225  break;
226 #endif
227 #ifdef B9600
228  case B9600:
229  pser_inf->baud_rate = 9600;
230  break;
231 #endif
232 #ifdef B19200
233  case B19200:
234  pser_inf->baud_rate = 19200;
235  break;
236 #endif
237 #ifdef B38400
238  case B38400:
239  pser_inf->baud_rate = 38400;
240  break;
241 #endif
242 #ifdef B57600
243  case B57600:
244  pser_inf->baud_rate = 57600;
245  break;
246 #endif
247 #ifdef B115200
248  case B115200:
249  pser_inf->baud_rate = 115200;
250  break;
251 #endif
252 #ifdef B230400
253  case B230400:
254  pser_inf->baud_rate = 230400;
255  break;
256 #endif
257 #ifdef B460800
258  case B460800:
259  pser_inf->baud_rate = 460800;
260  break;
261 #endif
262  default:
263  pser_inf->baud_rate = 9600;
264  break;
265  }
266 
267  speed = cfgetospeed(ptermios);
268  pser_inf->dtr = (speed == B0) ? 0 : 1;
269 
270  pser_inf->stop_bits = (ptermios->c_cflag & CSTOPB) ? STOP_BITS_2 : STOP_BITS_1;
271  pser_inf->parity =
272  (ptermios->
273  c_cflag & PARENB) ? ((ptermios->
274  c_cflag & PARODD) ? ODD_PARITY : EVEN_PARITY) : NO_PARITY;
275  switch (ptermios->c_cflag & CSIZE)
276  {
277  case CS5:
278  pser_inf->word_length = 5;
279  break;
280  case CS6:
281  pser_inf->word_length = 6;
282  break;
283  case CS7:
284  pser_inf->word_length = 7;
285  break;
286  default:
287  pser_inf->word_length = 8;
288  break;
289  }
290 
291  if (ptermios->c_cflag & CRTSCTS)
292  {
294  }
295  else
296  {
298  }
299 
300  pser_inf->xonoff = SERIAL_DSR_SENSITIVITY;
301  if (ptermios->c_iflag & IXON)
302  pser_inf->xonoff |= SERIAL_XON_HANDSHAKE;
303 
304  if (ptermios->c_iflag & IXOFF)
305  pser_inf->xonoff |= SERIAL_XOFF_HANDSHAKE;
306 
307  pser_inf->chars[SERIAL_CHAR_XON] = ptermios->c_cc[VSTART];
308  pser_inf->chars[SERIAL_CHAR_XOFF] = ptermios->c_cc[VSTOP];
309  pser_inf->chars[SERIAL_CHAR_EOF] = ptermios->c_cc[VEOF];
310  pser_inf->chars[SERIAL_CHAR_BREAK] = ptermios->c_cc[VINTR];
311  pser_inf->chars[SERIAL_CHAR_ERROR] = ptermios->c_cc[VKILL];
312 
313  return True;
314 }
#define SERIAL_XON_HANDSHAKE
Definition: serial.c:126
#define SERIAL_CHAR_XOFF
Definition: serial.c:135
#define SERIAL_DSR_SENSITIVITY
Definition: serial.c:128
#define ODD_PARITY
Definition: serial.c:90
struct termios * ptermios
Definition: types.h:240
#define SERIAL_CHAR_EOF
Definition: serial.c:130
#define True
Definition: types.h:24
#define SERIAL_DTR_CONTROL
Definition: serial.c:122
#define False
Definition: types.h:25
#define SERIAL_CHAR_XON
Definition: serial.c:134
#define SERIAL_CHAR_ERROR
Definition: serial.c:131
#define STOP_BITS_2
Definition: serial.c:87
#define SERIAL_CHAR_BREAK
Definition: serial.c:132
#define SERIAL_ERROR_ABORT
Definition: serial.c:124
#define NO_PARITY
Definition: serial.c:89
#define EVEN_PARITY
Definition: serial.c:91
#define STOP_BITS_1
Definition: serial.c:86
#define CRTSCTS
Definition: serial.c:138
#define SERIAL_XOFF_HANDSHAKE
Definition: serial.c:127
#define SERIAL_CTS_HANDSHAKE
Definition: serial.c:123

Referenced by serial_create(), and serial_device_control().

◆ serial_close()

static NTSTATUS serial_close ( RDPCLIENT This,
NTHANDLE  handle 
)
static

Definition at line 612 of file serial.c.

613 {
614  int i = get_device_index(This, handle);
615  if (i >= 0)
616  This->rdpdr_device[i].handle = 0;
617 
619  close(handle);
620  return STATUS_SUCCESS;
621 }
RD_BOOL rdpdr_abort_io(uint32 fd, uint32 major, RD_NTSTATUS status)
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
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
Definition: glfuncs.h:248
int get_device_index(RD_NTHANDLE handle)
#define close
Definition: acwin.h:98
return STATUS_SUCCESS
Definition: btrfs.c:2966

◆ serial_create()

static NTSTATUS serial_create ( RDPCLIENT This,
uint32  device_id,
uint32  access,
uint32  share_mode,
uint32  disposition,
uint32  flags_and_attributes,
char filename,
NTHANDLE *  handle 
)
static

Definition at line 555 of file serial.c.

557 {
558  NTHANDLE serial_fd;
559  SERIAL_DEVICE *pser_inf;
560  struct termios *ptermios;
561 
562  pser_inf = (SERIAL_DEVICE *) This->rdpdr_device[device_id].pdevice_data;
563  ptermios = pser_inf->ptermios;
564  serial_fd = open(This->rdpdr_device[device_id].local_path, O_RDWR | O_NOCTTY | O_NONBLOCK);
565 
566  if (serial_fd == -1)
567  {
568  perror("open");
569  return STATUS_ACCESS_DENIED;
570  }
571 
572  if (!get_termios(pser_inf, serial_fd))
573  {
574  printf("INFO: SERIAL %s access denied\n", This->rdpdr_device[device_id].name);
575  fflush(stdout);
576  return STATUS_ACCESS_DENIED;
577  }
578 
579  /* Store handle for later use */
580  This->rdpdr_device[device_id].handle = serial_fd;
581 
582  /* some sane information */
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));
584 
585  pser_inf->ptermios->c_iflag &=
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);
590  pser_inf->ptermios->c_cflag |= CS8;
591 
592  tcsetattr(serial_fd, TCSANOW, pser_inf->ptermios);
593 
594  pser_inf->event_txempty = 0;
595  pser_inf->event_cts = 0;
596  pser_inf->event_dsr = 0;
597  pser_inf->event_rlsd = 0;
598  pser_inf->event_pending = 0;
599 
600  *handle = serial_fd;
601 
602  /* all read and writes should be non blocking */
603  if (fcntl(*handle, F_SETFL, O_NONBLOCK) == -1)
604  perror("fcntl");
605 
606  pser_inf->read_total_timeout_constant = 5;
607 
608  return STATUS_SUCCESS;
609 }
#define open
Definition: acwin.h:95
#define O_NONBLOCK
Definition: port.h:158
static BOOL get_termios(SERIAL_DEVICE *pser_inf, NTHANDLE serial_fd)
Definition: serial.c:164
FILE * stdout
uint32 read_total_timeout_constant
Definition: types.h:230
_CRTIMP void __cdecl perror(_In_opt_z_ const char *_ErrMsg)
struct termios * ptermios
Definition: types.h:240
#define STATUS_ACCESS_DENIED
Definition: udferr_usr.h:145
#define ECHO
Definition: macro.lex.yy.c:616
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
#define DEBUG_SERIAL(args)
Definition: serial.c:41
#define O_RDWR
Definition: fcntl.h:36
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define printf
Definition: config.h:203

◆ serial_device_control()

static NTSTATUS serial_device_control ( RDPCLIENT This,
NTHANDLE  handle,
uint32  request,
STREAM  in,
STREAM  out 
)
static

Definition at line 700 of file serial.c.

701 {
702  int flush_mask, purge_mask;
703  uint32 result, modemstate;
704  uint8 immediate;
705  SERIAL_DEVICE *pser_inf;
706  struct termios *ptermios;
707 
708  if ((request >> 16) != FILE_DEVICE_SERIAL_PORT)
710 
711  pser_inf = get_serial_info(This, handle);
712  ptermios = pser_inf->ptermios;
713 
714  /* extract operation */
715  request >>= 2;
716  request &= 0xfff;
717 
718  switch (request)
719  {
721  in_uint32_le(in, pser_inf->baud_rate);
722  set_termios(pser_inf, handle);
723  DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_BAUD_RATE %d\n",
724  pser_inf->baud_rate));
725  break;
727  out_uint32_le(out, pser_inf->baud_rate);
728  DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_BAUD_RATE %d\n",
729  pser_inf->baud_rate));
730  break;
732  in_uint32_le(in, pser_inf->queue_in_size);
733  in_uint32_le(in, pser_inf->queue_out_size);
734  DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_QUEUE_SIZE in %d out %d\n",
735  pser_inf->queue_in_size, pser_inf->queue_out_size));
736  break;
738  in_uint8(in, pser_inf->stop_bits);
739  in_uint8(in, pser_inf->parity);
740  in_uint8(in, pser_inf->word_length);
741  set_termios(pser_inf, handle);
742  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));
743  break;
745  DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_LINE_CONTROL\n"));
746  out_uint8(out, pser_inf->stop_bits);
747  out_uint8(out, pser_inf->parity);
748  out_uint8(out, pser_inf->word_length);
749  break;
751  DEBUG_SERIAL(("serial_ioctl -> SERIAL_IMMEDIATE_CHAR\n"));
752  in_uint8(in, immediate);
753  serial_write(This, handle, &immediate, 1, 0, &result);
754  break;
755  case SERIAL_CONFIG_SIZE:
756  DEBUG_SERIAL(("serial_ioctl -> SERIAL_CONFIG_SIZE\n"));
757  out_uint32_le(out, 0);
758  break;
759  case SERIAL_GET_CHARS:
760  DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_CHARS\n"));
761  out_uint8a(out, pser_inf->chars, 6);
762  break;
763  case SERIAL_SET_CHARS:
764  DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_CHARS\n"));
765  in_uint8a(in, pser_inf->chars, 6);
766 #ifdef WITH_DEBUG_SERIAL
767  hexdump(pser_inf->chars, 6);
768 #endif
769  set_termios(pser_inf, handle);
770  break;
771  case SERIAL_GET_HANDFLOW:
772  DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_HANDFLOW\n"));
773  get_termios(pser_inf, handle);
774  out_uint32_le(out, pser_inf->control);
775  out_uint32_le(out, pser_inf->xonoff); /* Xon/Xoff */
776  out_uint32_le(out, pser_inf->onlimit);
777  out_uint32_le(out, pser_inf->offlimit);
778  break;
779  case SERIAL_SET_HANDFLOW:
780  in_uint32_le(in, pser_inf->control);
781  in_uint32_le(in, pser_inf->xonoff);
782  in_uint32_le(in, pser_inf->onlimit);
783  in_uint32_le(in, pser_inf->offlimit);
784  DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_HANDFLOW %x %x %x %x\n",
785  pser_inf->control, pser_inf->xonoff, pser_inf->onlimit,
786  pser_inf->onlimit));
787  set_termios(pser_inf, handle);
788  break;
789  case SERIAL_SET_TIMEOUTS:
790  in_uint32(in, pser_inf->read_interval_timeout);
795  DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_TIMEOUTS read timeout %d %d %d\n",
796  pser_inf->read_interval_timeout,
798  pser_inf->read_total_timeout_constant));
799  break;
800  case SERIAL_GET_TIMEOUTS:
801  DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_TIMEOUTS read timeout %d %d %d\n",
802  pser_inf->read_interval_timeout,
804  pser_inf->read_total_timeout_constant));
805 
811  break;
813  DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_WAIT_MASK %X\n",
814  pser_inf->wait_mask));
815  out_uint32(out, pser_inf->wait_mask);
816  break;
818  in_uint32(in, pser_inf->wait_mask);
819  DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_WAIT_MASK %X\n",
820  pser_inf->wait_mask));
821  break;
822  case SERIAL_SET_DTR:
823  DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_DTR\n"));
824  ioctl(handle, TIOCMGET, &result);
825  result |= TIOCM_DTR;
826  ioctl(handle, TIOCMSET, &result);
827  pser_inf->dtr = 1;
828  break;
829  case SERIAL_CLR_DTR:
830  DEBUG_SERIAL(("serial_ioctl -> SERIAL_CLR_DTR\n"));
831  ioctl(handle, TIOCMGET, &result);
832  result &= ~TIOCM_DTR;
833  ioctl(handle, TIOCMSET, &result);
834  pser_inf->dtr = 0;
835  break;
836  case SERIAL_SET_RTS:
837  DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_RTS\n"));
838  ioctl(handle, TIOCMGET, &result);
839  result |= TIOCM_RTS;
840  ioctl(handle, TIOCMSET, &result);
841  pser_inf->rts = 1;
842  break;
843  case SERIAL_CLR_RTS:
844  DEBUG_SERIAL(("serial_ioctl -> SERIAL_CLR_RTS\n"));
845  ioctl(handle, TIOCMGET, &result);
846  result &= ~TIOCM_RTS;
847  ioctl(handle, TIOCMSET, &result);
848  pser_inf->rts = 0;
849  break;
851  modemstate = 0;
852 #ifdef TIOCMGET
853  ioctl(handle, TIOCMGET, &result);
854  if (result & TIOCM_CTS)
855  modemstate |= SERIAL_MS_CTS;
856  if (result & TIOCM_DSR)
857  modemstate |= SERIAL_MS_DSR;
858  if (result & TIOCM_RNG)
859  modemstate |= SERIAL_MS_RNG;
860  if (result & TIOCM_CAR)
861  modemstate |= SERIAL_MS_CAR;
862  if (result & TIOCM_DTR)
863  modemstate |= SERIAL_MS_DTR;
864  if (result & TIOCM_RTS)
865  modemstate |= SERIAL_MS_RTS;
866 #endif
867  DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_MODEMSTATUS %X\n", modemstate));
868  out_uint32_le(out, modemstate);
869  break;
871  out_uint32_le(out, 0); /* Errors */
872  out_uint32_le(out, 0); /* Hold reasons */
873 
874  result = 0;
875 #ifdef TIOCINQ
876  ioctl(handle, TIOCINQ, &result);
877 #endif
878  out_uint32_le(out, result); /* Amount in in queue */
879  if (result)
880  DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS in queue %d\n",
881  result));
882 
883  result = 0;
884 #ifdef TIOCOUTQ
885  ioctl(handle, TIOCOUTQ, &result);
886 #endif
887  out_uint32_le(out, result); /* Amount in out queue */
888  if (result)
889  DEBUG_SERIAL(("serial_ioctl -> SERIAL_GET_COMMSTATUS out queue %d\n", result));
890 
891  out_uint8(out, 0); /* EofReceived */
892  out_uint8(out, 0); /* WaitForImmediate */
893  break;
894  case SERIAL_PURGE:
895  in_uint32(in, purge_mask);
896  DEBUG_SERIAL(("serial_ioctl -> SERIAL_PURGE purge_mask %X\n", purge_mask));
897  flush_mask = 0;
898  if (purge_mask & SERIAL_PURGE_TXCLEAR)
899  flush_mask |= TCOFLUSH;
900  if (purge_mask & SERIAL_PURGE_RXCLEAR)
901  flush_mask |= TCIFLUSH;
902  if (flush_mask != 0)
903  tcflush(handle, flush_mask);
904  if (purge_mask & SERIAL_PURGE_TXABORT)
906  if (purge_mask & SERIAL_PURGE_RXABORT)
908  break;
909  case SERIAL_WAIT_ON_MASK:
910  DEBUG_SERIAL(("serial_ioctl -> SERIAL_WAIT_ON_MASK %X\n",
911  pser_inf->wait_mask));
912  pser_inf->event_pending = 1;
914  {
915  DEBUG_SERIAL(("WAIT end event = %x\n", result));
917  break;
918  }
919  return STATUS_PENDING;
920  break;
921  case SERIAL_SET_BREAK_ON:
922  DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_BREAK_ON\n"));
923  tcsendbreak(handle, 0);
924  break;
925  case SERIAL_RESET_DEVICE:
926  DEBUG_SERIAL(("serial_ioctl -> SERIAL_RESET_DEVICE\n"));
927  break;
929  DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_BREAK_OFF\n"));
930  break;
931  case SERIAL_SET_XOFF:
932  DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_XOFF\n"));
933  break;
934  case SERIAL_SET_XON:
935  DEBUG_SERIAL(("serial_ioctl -> SERIAL_SET_XON\n"));
936  tcflow(handle, TCION);
937  break;
938  default:
939  unimpl("SERIAL IOCTL %d\n", request);
941  }
942 
943  return STATUS_SUCCESS;
944 }
#define SERIAL_PURGE_TXCLEAR
Definition: serial.c:95
#define SERIAL_WAIT_ON_MASK
Definition: serial.c:63
#define SERIAL_PURGE_RXCLEAR
Definition: serial.c:96
uint32 write_total_timeout_multiplier
Definition: types.h:230
#define SERIAL_CLR_RTS
Definition: serial.c:58
#define SERIAL_SET_QUEUE_SIZE
Definition: serial.c:47
BOOL serial_get_event(RDPCLIENT *This, NTHANDLE handle, uint32 *result)
Definition: serial.c:947
uint32 read_interval_timeout
Definition: types.h:230
RD_BOOL rdpdr_abort_io(uint32 fd, uint32 major, RD_NTSTATUS status)
#define out_uint8a(s, v, n)
Definition: parse.h:94
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
unsigned int uint32
Definition: types.h:32
#define SERIAL_SET_XOFF
Definition: serial.c:59
#define SERIAL_MS_CTS
Definition: serial.c:116
#define SERIAL_RESET_DEVICE
Definition: serial.c:56
#define out_uint32_le(s, v)
Definition: parse.h:59
#define SERIAL_SET_BREAK_ON
Definition: serial.c:49
#define SERIAL_GET_MODEMSTATUS
Definition: serial.c:71
static BOOL get_termios(SERIAL_DEVICE *pser_inf, NTHANDLE serial_fd)
Definition: serial.c:164
#define SERIAL_GET_CHARS
Definition: serial.c:67
static SERIAL_DEVICE * get_serial_info(RDPCLIENT *This, NTHANDLE handle)
Definition: serial.c:151
#define SERIAL_CONFIG_SIZE
Definition: serial.c:77
static NTSTATUS serial_write(RDPCLIENT *This, NTHANDLE handle, uint8 *data, uint32 length, uint32 offset, uint32 *result)
Definition: serial.c:683
uint32 read_total_timeout_constant
Definition: types.h:230
#define out_uint8(s, v)
Definition: parse.h:92
#define SERIAL_SET_HANDFLOW
Definition: serial.c:70
uint32 read_total_timeout_multiplier
Definition: types.h:230
#define SERIAL_MS_CAR
Definition: serial.c:119
#define ioctl
Definition: wintirpc.h:60
struct termios * ptermios
Definition: types.h:240
#define SERIAL_MS_RNG
Definition: serial.c:118
#define SERIAL_SET_RTS
Definition: serial.c:57
#define SERIAL_GET_HANDFLOW
Definition: serial.c:69
#define SERIAL_SET_XON
Definition: serial.c:60
#define SERIAL_IMMEDIATE_CHAR
Definition: serial.c:51
#define STATUS_PENDING
Definition: ntstatus.h:82
#define SERIAL_SET_BREAK_OFF
Definition: serial.c:50
#define STATUS_CANCELLED
Definition: udferr_usr.h:170
static FILE * out
Definition: regtests2xml.c:44
#define SERIAL_GET_COMMSTATUS
Definition: serial.c:72
unsigned char uint8
Definition: types.h:28
#define in_uint32(s, v)
Definition: parse.h:83
#define SERIAL_SET_LINE_CONTROL
Definition: serial.c:48
uint32 write_total_timeout_constant
Definition: types.h:230
#define SERIAL_SET_BAUD_RATE
Definition: serial.c:46
#define SERIAL_MS_RTS
Definition: serial.c:115
#define SERIAL_GET_TIMEOUTS
Definition: serial.c:53
#define SERIAL_PURGE
Definition: serial.c:64
#define SERIAL_GET_WAIT_MASK
Definition: serial.c:61
#define SERIAL_GET_BAUD_RATE
Definition: serial.c:65
#define in_uint8a(s, v, n)
Definition: parse.h:90
#define SERIAL_PURGE_RXABORT
Definition: serial.c:94
#define SERIAL_GET_LINE_CONTROL
Definition: serial.c:66
void hexdump(unsigned char *p, unsigned int len)
Definition: shimdbg.c:234
GLuint in
Definition: glext.h:9616
#define DEBUG_SERIAL(args)
Definition: serial.c:41
#define SERIAL_CLR_DTR
Definition: serial.c:55
#define in_uint8(s, v)
Definition: parse.h:88
Definition: tftpd.h:85
static void set_termios(SERIAL_DEVICE *pser_inf, NTHANDLE serial_fd)
Definition: serial.c:317
#define SERIAL_MS_DTR
Definition: serial.c:114
#define SERIAL_MS_DSR
Definition: serial.c:117
#define SERIAL_SET_WAIT_MASK
Definition: serial.c:62
#define SERIAL_PURGE_TXABORT
Definition: serial.c:93
#define out_uint32(s, v)
Definition: parse.h:85
#define SERIAL_SET_TIMEOUTS
Definition: serial.c:52
void unimpl(char *format,...)
Definition: uimain.c:801
#define SERIAL_SET_CHARS
Definition: serial.c:68
#define SERIAL_SET_DTR
Definition: serial.c:54
#define in_uint32_le(s, v)
Definition: parse.h:56
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define FILE_DEVICE_SERIAL_PORT
Definition: serial.c:44
GLuint64EXT * result
Definition: glext.h:11304

◆ serial_enum_devices()

int serial_enum_devices ( RDPCLIENT This,
uint32 id,
char optarg 
)

Definition at line 515 of file serial.c.

516 {
517  SERIAL_DEVICE *pser_inf;
518 
519  char *pos = optarg;
520  char *pos2;
521  int count = 0;
522 
523  /* skip the first colon */
524  optarg++;
525  while ((pos = next_arg(optarg, ',')) && *id < RDPDR_MAX_DEVICES)
526  {
527  /* Init data structures for device */
528  pser_inf = (SERIAL_DEVICE *) xmalloc(sizeof(SERIAL_DEVICE));
529  pser_inf->ptermios = (struct termios *) xmalloc(sizeof(struct termios));
530  memset(pser_inf->ptermios, 0, sizeof(struct termios));
531  pser_inf->pold_termios = (struct termios *) xmalloc(sizeof(struct termios));
532  memset(pser_inf->pold_termios, 0, sizeof(struct termios));
533 
534  pos2 = next_arg(optarg, '=');
535  strcpy(This->rdpdr_device[*id].name, optarg);
536 
537  toupper_str(This->rdpdr_device[*id].name);
538 
539  This->rdpdr_device[*id].local_path = xmalloc(strlen(pos2) + 1);
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);
543  /* set device type */
544  This->rdpdr_device[*id].device_type = DEVICE_TYPE_SERIAL;
545  This->rdpdr_device[*id].pdevice_data = (void *) pser_inf;
546  count++;
547  (*id)++;
548 
549  optarg = pos;
550  }
551  return count;
552 }
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define DEVICE_TYPE_SERIAL
Definition: constants.h:485
struct termios * pold_termios
Definition: types.h:240
void * xmalloc(int size)
Definition: uimain.c:747
#define RDPDR_MAX_DEVICES
Definition: constants.h:484
struct termios * ptermios
Definition: types.h:240
char * next_arg(char *src, char needle)
Definition: rdesktop.c:1174
const char * optarg
Definition: getopt.c:49
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
GLenum GLuint id
Definition: glext.h:5579
#define memset(x, y, z)
Definition: compat.h:39
void toupper_str(char *p)
Definition: rdesktop.c:1223
#define printf
Definition: config.h:203

◆ serial_get_event()

BOOL serial_get_event ( RDPCLIENT This,
NTHANDLE  handle,
uint32 result 
)

Definition at line 947 of file serial.c.

948 {
949  int index;
950  SERIAL_DEVICE *pser_inf;
951  int bytes;
952  BOOL ret = False;
953 
954  *result = 0;
956  if (index < 0)
957  return False;
958 
959 #ifdef TIOCINQ
960  pser_inf = (SERIAL_DEVICE *) This->rdpdr_device[index].pdevice_data;
961 
962  ioctl(handle, TIOCINQ, &bytes);
963 
964  if (bytes > 0)
965  {
966  DEBUG_SERIAL(("serial_get_event Bytes %d\n", bytes));
967  if (bytes > pser_inf->event_rlsd)
968  {
969  pser_inf->event_rlsd = bytes;
970  if (pser_inf->wait_mask & SERIAL_EV_RLSD)
971  {
972  DEBUG_SERIAL(("Event -> SERIAL_EV_RLSD \n"));
974  ret = True;
975  }
976 
977  }
978 
979  if ((bytes > 1) && (pser_inf->wait_mask & SERIAL_EV_RXFLAG))
980  {
981  DEBUG_SERIAL(("Event -> SERIAL_EV_RXFLAG Bytes %d\n", bytes));
983  ret = True;
984  }
985  if ((pser_inf->wait_mask & SERIAL_EV_RXCHAR))
986  {
987  DEBUG_SERIAL(("Event -> SERIAL_EV_RXCHAR Bytes %d\n", bytes));
989  ret = True;
990  }
991 
992  }
993  else
994  {
995  pser_inf->event_rlsd = 0;
996  }
997 #endif
998 
999 #ifdef TIOCOUTQ
1000  ioctl(handle, TIOCOUTQ, &bytes);
1001  if ((bytes == 0)
1002  && (pser_inf->event_txempty > 0) && (pser_inf->wait_mask & SERIAL_EV_TXEMPTY))
1003  {
1004 
1005  DEBUG_SERIAL(("Event -> SERIAL_EV_TXEMPTY\n"));
1007  ret = True;
1008  }
1009  pser_inf->event_txempty = bytes;
1010 #endif
1011 
1012  ioctl(handle, TIOCMGET, &bytes);
1013  if ((bytes & TIOCM_DSR) != pser_inf->event_dsr)
1014  {
1015  pser_inf->event_dsr = bytes & TIOCM_DSR;
1016  if (pser_inf->wait_mask & SERIAL_EV_DSR)
1017  {
1018  DEBUG_SERIAL(("event -> SERIAL_EV_DSR %s\n",
1019  (bytes & TIOCM_DSR) ? "ON" : "OFF"));
1020  *result |= SERIAL_EV_DSR;
1021  ret = True;
1022  }
1023  }
1024 
1025  if ((bytes & TIOCM_CTS) != pser_inf->event_cts)
1026  {
1027  pser_inf->event_cts = bytes & TIOCM_CTS;
1028  if (pser_inf->wait_mask & SERIAL_EV_CTS)
1029  {
1030  DEBUG_SERIAL((" EVENT-> SERIAL_EV_CTS %s\n",
1031  (bytes & TIOCM_CTS) ? "ON" : "OFF"));
1032  *result |= SERIAL_EV_CTS;
1033  ret = True;
1034  }
1035  }
1036 
1037  if (ret)
1038  pser_inf->event_pending = 0;
1039 
1040  return ret;
1041 }
#define SERIAL_EV_RXFLAG
Definition: serial.c:100
#define SERIAL_EV_DSR
Definition: serial.c:103
#define SERIAL_EV_TXEMPTY
Definition: serial.c:101
#define SERIAL_EV_RLSD
Definition: serial.c:104
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
unsigned int BOOL
Definition: ntddk_ex.h:94
#define ioctl
Definition: wintirpc.h:60
GLuint index
Definition: glext.h:6031
#define True
Definition: types.h:24
#define SERIAL_EV_CTS
Definition: serial.c:102
#define False
Definition: types.h:25
int get_device_index(RD_NTHANDLE handle)
int ret
#define index(s, c)
Definition: various.h:29
#define DEBUG_SERIAL(args)
Definition: serial.c:41
#define SERIAL_EV_RXCHAR
Definition: serial.c:99
GLuint64EXT * result
Definition: glext.h:11304

Referenced by serial_device_control().

◆ serial_get_timeout()

BOOL serial_get_timeout ( RDPCLIENT This,
NTHANDLE  handle,
uint32  length,
uint32 timeout,
uint32 itv_timeout 
)

Definition at line 1045 of file serial.c.

1046 {
1047  int index;
1048  SERIAL_DEVICE *pser_inf;
1049 
1051  if (index < 0)
1052  return True;
1053 
1054  if (This->rdpdr_device[index].device_type != DEVICE_TYPE_SERIAL)
1055  {
1056  return False;
1057  }
1058 
1059  pser_inf = (SERIAL_DEVICE *) This->rdpdr_device[index].pdevice_data;
1060 
1061  *timeout =
1063  pser_inf->read_total_timeout_constant;
1064  *itv_timeout = pser_inf->read_interval_timeout;
1065  return True;
1066 }
uint32 read_interval_timeout
Definition: types.h:230
Definition: dhcpd.h:245
#define DEVICE_TYPE_SERIAL
Definition: constants.h:485
uint32 read_total_timeout_constant
Definition: types.h:230
uint32 read_total_timeout_multiplier
Definition: types.h:230
GLuint index
Definition: glext.h:6031
#define True
Definition: types.h:24
#define False
Definition: types.h:25
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
int get_device_index(RD_NTHANDLE handle)
#define index(s, c)
Definition: various.h:29

◆ serial_read()

static NTSTATUS serial_read ( RDPCLIENT This,
NTHANDLE  handle,
uint8 data,
uint32  length,
uint32  offset,
uint32 result 
)
static

Definition at line 624 of file serial.c.

625 {
626  long timeout;
627  SERIAL_DEVICE *pser_inf;
628  struct termios *ptermios;
629 #ifdef WITH_DEBUG_SERIAL
630  int bytes_inqueue;
631 #endif
632 
633 
634  timeout = 90;
635  pser_inf = get_serial_info(This, handle);
636  ptermios = pser_inf->ptermios;
637 
638  /* Set timeouts kind of like the windows serial timeout parameters. Multiply timeout
639  with requested read size */
641  {
642  timeout =
644  pser_inf->read_total_timeout_constant + 99) / 100;
645  }
646  else if (pser_inf->read_interval_timeout)
647  {
648  timeout = (pser_inf->read_interval_timeout * length + 99) / 100;
649  }
650 
651  /* If a timeout is set, do a blocking read, which times out after some time.
652  It will make rdesktop less responsive, but it will improve serial performance, by not
653  reading one character at a time. */
654  if (timeout == 0)
655  {
656  ptermios->c_cc[VTIME] = 0;
657  ptermios->c_cc[VMIN] = 0;
658  }
659  else
660  {
661  ptermios->c_cc[VTIME] = timeout;
662  ptermios->c_cc[VMIN] = 1;
663  }
664  tcsetattr(handle, TCSANOW, ptermios);
665 
666 #if defined(WITH_DEBUG_SERIAL) && defined(TIOCINQ)
667  ioctl(handle, TIOCINQ, &bytes_inqueue);
668  DEBUG_SERIAL(("serial_read inqueue: %d expected %d\n", bytes_inqueue, length));
669 #endif
670 
671  *result = read(handle, data, length);
672 
673 #ifdef WITH_DEBUG_SERIAL
674  DEBUG_SERIAL(("serial_read Bytes %d\n", *result));
675  if (*result > 0)
676  hexdump(data, *result);
677 #endif
678 
679  return STATUS_SUCCESS;
680 }
uint32 read_interval_timeout
Definition: types.h:230
Definition: dhcpd.h:245
GLbitfield GLuint64 timeout
Definition: glext.h:7164
static SERIAL_DEVICE * get_serial_info(RDPCLIENT *This, NTHANDLE handle)
Definition: serial.c:151
uint32 read_total_timeout_constant
Definition: types.h:230
uint32 read_total_timeout_multiplier
Definition: types.h:230
#define ioctl
Definition: wintirpc.h:60
struct termios * ptermios
Definition: types.h:240
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
void hexdump(unsigned char *p, unsigned int len)
Definition: shimdbg.c:234
#define DEBUG_SERIAL(args)
Definition: serial.c:41
return STATUS_SUCCESS
Definition: btrfs.c:2966
GLuint64EXT * result
Definition: glext.h:11304
_CRTIMP int __cdecl read(_In_ int _FileHandle, _Out_writes_bytes_(_MaxCharCount) void *_DstBuf, _In_ unsigned int _MaxCharCount)

◆ serial_write()

static NTSTATUS serial_write ( RDPCLIENT This,
NTHANDLE  handle,
uint8 data,
uint32  length,
uint32  offset,
uint32 result 
)
static

Definition at line 683 of file serial.c.

684 {
685  SERIAL_DEVICE *pser_inf;
686 
687  pser_inf = get_serial_info(This, handle);
688 
689  *result = write(handle, data, length);
690 
691  if (*result > 0)
692  pser_inf->event_txempty = *result;
693 
694  DEBUG_SERIAL(("serial_write length %d, offset %d result %d\n", length, offset, *result));
695 
696  return STATUS_SUCCESS;
697 }
GLintptr offset
Definition: glext.h:5920
static SERIAL_DEVICE * get_serial_info(RDPCLIENT *This, NTHANDLE handle)
Definition: serial.c:151
#define write
Definition: acwin.h:97
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define DEBUG_SERIAL(args)
Definition: serial.c:41
return STATUS_SUCCESS
Definition: btrfs.c:2966
GLuint64EXT * result
Definition: glext.h:11304

Referenced by serial_device_control().

◆ set_termios()

static void set_termios ( SERIAL_DEVICE pser_inf,
NTHANDLE  serial_fd 
)
static

Definition at line 317 of file serial.c.

318 {
319  speed_t speed;
320 
321  struct termios *ptermios;
322 
323  ptermios = pser_inf->ptermios;
324 
325 
326  switch (pser_inf->baud_rate)
327  {
328 #ifdef B75
329  case 75:
330  speed = B75;
331  break;
332 #endif
333 #ifdef B110
334  case 110:
335  speed = B110;
336  break;
337 #endif
338 #ifdef B134
339  case 134:
340  speed = B134;
341  break;
342 #endif
343 #ifdef B150
344  case 150:
345  speed = B150;
346  break;
347 #endif
348 #ifdef B300
349  case 300:
350  speed = B300;
351  break;
352 #endif
353 #ifdef B600
354  case 600:
355  speed = B600;
356  break;
357 #endif
358 #ifdef B1200
359  case 1200:
360  speed = B1200;
361  break;
362 #endif
363 #ifdef B1800
364  case 1800:
365  speed = B1800;
366  break;
367 #endif
368 #ifdef B2400
369  case 2400:
370  speed = B2400;
371  break;
372 #endif
373 #ifdef B4800
374  case 4800:
375  speed = B4800;
376  break;
377 #endif
378 #ifdef B9600
379  case 9600:
380  speed = B9600;
381  break;
382 #endif
383 #ifdef B19200
384  case 19200:
385  speed = B19200;
386  break;
387 #endif
388 #ifdef B38400
389  case 38400:
390  speed = B38400;
391  break;
392 #endif
393 #ifdef B57600
394  case 57600:
395  speed = B57600;
396  break;
397 #endif
398 #ifdef B115200
399  case 115200:
400  speed = B115200;
401  break;
402 #endif
403 #ifdef B230400
404  case 230400:
405  speed = B115200;
406  break;
407 #endif
408 #ifdef B460800
409  case 460800:
410  speed = B115200;
411  break;
412 #endif
413  default:
414  speed = B9600;
415  break;
416  }
417 
418 #ifdef CBAUD
419  ptermios->c_cflag &= ~CBAUD;
420  ptermios->c_cflag |= speed;
421 #else
422  /* on systems with separate ispeed and ospeed, we can remember the speed
423  in ispeed while changing DTR with ospeed */
424  cfsetispeed(pser_inf->ptermios, speed);
425  cfsetospeed(pser_inf->ptermios, pser_inf->dtr ? speed : 0);
426 #endif
427 
428  ptermios->c_cflag &= ~(CSTOPB | PARENB | PARODD | CSIZE | CRTSCTS);
429  switch (pser_inf->stop_bits)
430  {
431  case STOP_BITS_2:
432  ptermios->c_cflag |= CSTOPB;
433  break;
434  default:
435  ptermios->c_cflag &= ~CSTOPB;
436  break;
437  }
438 
439  switch (pser_inf->parity)
440  {
441  case EVEN_PARITY:
442  ptermios->c_cflag |= PARENB;
443  break;
444  case ODD_PARITY:
445  ptermios->c_cflag |= PARENB | PARODD;
446  break;
447  case NO_PARITY:
448  ptermios->c_cflag &= ~(PARENB | PARODD);
449  break;
450  }
451 
452  switch (pser_inf->word_length)
453  {
454  case 5:
455  ptermios->c_cflag |= CS5;
456  break;
457  case 6:
458  ptermios->c_cflag |= CS6;
459  break;
460  case 7:
461  ptermios->c_cflag |= CS7;
462  break;
463  default:
464  ptermios->c_cflag |= CS8;
465  break;
466  }
467 
468 #if 0
469  if (pser_inf->rts)
470  ptermios->c_cflag |= CRTSCTS;
471  else
472  ptermios->c_cflag &= ~CRTSCTS;
473 #endif
474 
475  if (pser_inf->control & SERIAL_CTS_HANDSHAKE)
476  {
477  ptermios->c_cflag |= CRTSCTS;
478  }
479  else
480  {
481  ptermios->c_cflag &= ~CRTSCTS;
482  }
483 
484 
485  if (pser_inf->xonoff & SERIAL_XON_HANDSHAKE)
486  {
487  ptermios->c_iflag |= IXON | IMAXBEL;
488  }
489  if (pser_inf->xonoff & SERIAL_XOFF_HANDSHAKE)
490  {
491  ptermios->c_iflag |= IXOFF | IMAXBEL;
492  }
493 
494  if ((pser_inf->xonoff & (SERIAL_XOFF_HANDSHAKE | SERIAL_XON_HANDSHAKE)) == 0)
495  {
496  ptermios->c_iflag &= ~IXON;
497  ptermios->c_iflag &= ~IXOFF;
498  }
499 
500  ptermios->c_cc[VSTART] = pser_inf->chars[SERIAL_CHAR_XON];
501  ptermios->c_cc[VSTOP] = pser_inf->chars[SERIAL_CHAR_XOFF];
502  ptermios->c_cc[VEOF] = pser_inf->chars[SERIAL_CHAR_EOF];
503  ptermios->c_cc[VINTR] = pser_inf->chars[SERIAL_CHAR_BREAK];
504  ptermios->c_cc[VKILL] = pser_inf->chars[SERIAL_CHAR_ERROR];
505 
506  tcsetattr(serial_fd, TCSANOW, ptermios);
507 }
#define SERIAL_XON_HANDSHAKE
Definition: serial.c:126
#define SERIAL_CHAR_XOFF
Definition: serial.c:135
#define ODD_PARITY
Definition: serial.c:90
struct termios * ptermios
Definition: types.h:240
#define SERIAL_CHAR_EOF
Definition: serial.c:130
#define SERIAL_CHAR_XON
Definition: serial.c:134
#define SERIAL_CHAR_ERROR
Definition: serial.c:131
#define STOP_BITS_2
Definition: serial.c:87
#define SERIAL_CHAR_BREAK
Definition: serial.c:132
#define NO_PARITY
Definition: serial.c:89
#define EVEN_PARITY
Definition: serial.c:91
#define CRTSCTS
Definition: serial.c:138
#define SERIAL_XOFF_HANDSHAKE
Definition: serial.c:127
#define SERIAL_CTS_HANDSHAKE
Definition: serial.c:123

Referenced by serial_device_control().

Variable Documentation

◆ serial_fns

DEVICE_FNS serial_fns
Initial value:
= {
}
static NTSTATUS serial_write(RDPCLIENT *This, NTHANDLE handle, uint8 *data, uint32 length, uint32 offset, uint32 *result)
Definition: serial.c:683
static NTSTATUS serial_read(RDPCLIENT *This, NTHANDLE handle, uint8 *data, uint32 length, uint32 offset, uint32 *result)
Definition: serial.c:624
static NTSTATUS serial_create(RDPCLIENT *This, uint32 device_id, uint32 access, uint32 share_mode, uint32 disposition, uint32 flags_and_attributes, char *filename, NTHANDLE *handle)
Definition: serial.c:555
static NTSTATUS serial_close(RDPCLIENT *This, NTHANDLE handle)
Definition: serial.c:612
static NTSTATUS serial_device_control(RDPCLIENT *This, NTHANDLE handle, uint32 request, STREAM in, STREAM out)
Definition: serial.c:700

Definition at line 1068 of file serial.c.

Referenced by rdpdr_process_irp().