2 * Serial device support
4 * Copyright 1993 Erik Bos
5 * Copyright 1996 Marcus Meissner
6 * Copyright 2005,2006 Eric Pouech
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/port.h"
42 #ifdef HAVE_SYS_STAT_H
43 # include <sys/stat.h>
45 #include <sys/types.h>
46 #ifdef HAVE_SYS_FILIO_H
47 # include <sys/filio.h>
49 #ifdef HAVE_SYS_IOCTL_H
50 #include <sys/ioctl.h>
52 #ifdef HAVE_SYS_POLL_H
53 # include <sys/poll.h>
55 #ifdef HAVE_SYS_MODEM_H
56 # include <sys/modem.h>
58 #ifdef HAVE_SYS_STRTIO_H
59 # include <sys/strtio.h>
63 #define WIN32_NO_STATUS
64 #define NONAMELESSUNION
68 #include "ddk/ntddser.h"
69 #include "wine/server.h"
70 #include "unix_private.h"
71 #include "wine/debug.h"
73 #ifdef HAVE_LINUX_SERIAL_H
74 #ifdef HAVE_ASM_TYPES_H
75 #include <asm/types.h>
77 #include <linux/serial.h>
80 #if !defined(TIOCINQ) && defined(FIONREAD)
81 #define TIOCINQ FIONREAD
84 WINE_DEFAULT_DEBUG_CHANNEL(comm
);
86 static const char* iocode2str(DWORD ioc
)
90 #define X(x) case (x): return #x
91 X(IOCTL_SERIAL_CLEAR_STATS
);
92 X(IOCTL_SERIAL_CLR_DTR
);
93 X(IOCTL_SERIAL_CLR_RTS
);
94 X(IOCTL_SERIAL_CONFIG_SIZE
);
95 X(IOCTL_SERIAL_GET_BAUD_RATE
);
96 X(IOCTL_SERIAL_GET_CHARS
);
97 X(IOCTL_SERIAL_GET_COMMSTATUS
);
98 X(IOCTL_SERIAL_GET_DTRRTS
);
99 X(IOCTL_SERIAL_GET_HANDFLOW
);
100 X(IOCTL_SERIAL_GET_LINE_CONTROL
);
101 X(IOCTL_SERIAL_GET_MODEM_CONTROL
);
102 X(IOCTL_SERIAL_GET_MODEMSTATUS
);
103 X(IOCTL_SERIAL_GET_PROPERTIES
);
104 X(IOCTL_SERIAL_GET_STATS
);
105 X(IOCTL_SERIAL_GET_TIMEOUTS
);
106 X(IOCTL_SERIAL_GET_WAIT_MASK
);
107 X(IOCTL_SERIAL_IMMEDIATE_CHAR
);
108 X(IOCTL_SERIAL_LSRMST_INSERT
);
109 X(IOCTL_SERIAL_PURGE
);
110 X(IOCTL_SERIAL_RESET_DEVICE
);
111 X(IOCTL_SERIAL_SET_BAUD_RATE
);
112 X(IOCTL_SERIAL_SET_BREAK_ON
);
113 X(IOCTL_SERIAL_SET_BREAK_OFF
);
114 X(IOCTL_SERIAL_SET_CHARS
);
115 X(IOCTL_SERIAL_SET_DTR
);
116 X(IOCTL_SERIAL_SET_FIFO_CONTROL
);
117 X(IOCTL_SERIAL_SET_HANDFLOW
);
118 X(IOCTL_SERIAL_SET_LINE_CONTROL
);
119 X(IOCTL_SERIAL_SET_MODEM_CONTROL
);
120 X(IOCTL_SERIAL_SET_QUEUE_SIZE
);
121 X(IOCTL_SERIAL_SET_RTS
);
122 X(IOCTL_SERIAL_SET_TIMEOUTS
);
123 X(IOCTL_SERIAL_SET_WAIT_MASK
);
124 X(IOCTL_SERIAL_SET_XOFF
);
125 X(IOCTL_SERIAL_SET_XON
);
126 X(IOCTL_SERIAL_WAIT_ON_MASK
);
127 X(IOCTL_SERIAL_XOFF_COUNTER
);
129 default: { static char tmp
[32]; sprintf(tmp
, "IOCTL_SERIAL_%d\n", ioc
); return tmp
; }
133 static NTSTATUS
get_baud_rate(int fd
, SERIAL_BAUD_RATE
* sbr
)
138 if (tcgetattr(fd
, &port
) == -1)
140 ERR("tcgetattr error '%s'\n", strerror(errno
));
141 return errno_to_status( errno
);
143 speed
= cfgetospeed(&port
);
146 case B0
: sbr
->BaudRate
= 0; break;
147 case B50
: sbr
->BaudRate
= 50; break;
148 case B75
: sbr
->BaudRate
= 75; break;
149 case B110
: sbr
->BaudRate
= 110; break;
150 case B134
: sbr
->BaudRate
= 134; break;
151 case B150
: sbr
->BaudRate
= 150; break;
152 case B200
: sbr
->BaudRate
= 200; break;
153 case B300
: sbr
->BaudRate
= 300; break;
154 case B600
: sbr
->BaudRate
= 600; break;
155 case B1200
: sbr
->BaudRate
= 1200; break;
156 case B1800
: sbr
->BaudRate
= 1800; break;
157 case B2400
: sbr
->BaudRate
= 2400; break;
158 case B4800
: sbr
->BaudRate
= 4800; break;
159 case B9600
: sbr
->BaudRate
= 9600; break;
160 case B19200
: sbr
->BaudRate
= 19200; break;
161 case B38400
: sbr
->BaudRate
= 38400; break;
163 case B57600
: sbr
->BaudRate
= 57600; break;
166 case B115200
: sbr
->BaudRate
= 115200; break;
169 case B230400
: sbr
->BaudRate
= 230400; break;
172 case B460800
: sbr
->BaudRate
= 460800; break;
175 case B500000
: sbr
->BaudRate
= 500000; break;
178 case B921600
: sbr
->BaudRate
= 921600; break;
181 case B1000000
: sbr
->BaudRate
= 1000000; break;
184 case B1152000
: sbr
->BaudRate
= 1152000; break;
187 case B1500000
: sbr
->BaudRate
= 1500000; break;
190 case B2000000
: sbr
->BaudRate
= 2000000; break;
193 case B2500000
: sbr
->BaudRate
= 2500000; break;
196 case B3000000
: sbr
->BaudRate
= 3000000; break;
199 case B3500000
: sbr
->BaudRate
= 3500000; break;
202 case B4000000
: sbr
->BaudRate
= 4000000; break;
205 ERR("unknown speed %x\n", speed
);
206 return STATUS_INVALID_PARAMETER
;
208 return STATUS_SUCCESS
;
211 static NTSTATUS
get_hand_flow(int fd
, SERIAL_HANDFLOW
* shf
)
216 if (tcgetattr(fd
, &port
) == -1)
218 ERR("tcgetattr error '%s'\n", strerror(errno
));
219 return errno_to_status( errno
);
221 /* termios does not support DTR/DSR flow control */
222 shf
->ControlHandShake
= 0;
223 shf
->FlowReplace
= 0;
225 if (ioctl(fd
, TIOCMGET
, &stat
) == -1)
227 WARN("ioctl error '%s'\n", strerror(errno
));
228 shf
->ControlHandShake
|= SERIAL_DTR_CONTROL
;
229 shf
->FlowReplace
|= SERIAL_RTS_CONTROL
;
232 WARN("Setting DTR/RTS to enabled by default\n");
233 shf
->ControlHandShake
|= SERIAL_DTR_CONTROL
;
234 shf
->FlowReplace
|= SERIAL_RTS_CONTROL
;
237 if (stat
& TIOCM_DTR
)
239 shf
->ControlHandShake
|= SERIAL_DTR_CONTROL
;
241 if (port
.c_cflag
& CRTSCTS
)
243 shf
->FlowReplace
|= SERIAL_RTS_CONTROL
;
244 shf
->ControlHandShake
|= SERIAL_CTS_HANDSHAKE
;
250 if (stat
& TIOCM_RTS
)
252 shf
->FlowReplace
|= SERIAL_RTS_CONTROL
;
254 if (port
.c_iflag
& IXOFF
)
255 shf
->FlowReplace
|= SERIAL_AUTO_RECEIVE
;
256 if (port
.c_iflag
& IXON
)
257 shf
->FlowReplace
|= SERIAL_AUTO_TRANSMIT
;
261 return STATUS_SUCCESS
;
264 static NTSTATUS
get_line_control(int fd
, SERIAL_LINE_CONTROL
* slc
)
268 if (tcgetattr(fd
, &port
) == -1)
270 ERR("tcgetattr error '%s'\n", strerror(errno
));
271 return errno_to_status( errno
);
275 switch (port
.c_cflag
& (PARENB
| PARODD
| CMSPAR
))
277 switch (port
.c_cflag
& (PARENB
| PARODD
))
280 case 0: slc
->Parity
= NOPARITY
; break;
281 case PARENB
: slc
->Parity
= EVENPARITY
; break;
282 case PARENB
|PARODD
: slc
->Parity
= ODDPARITY
; break;
284 case PARENB
|PARODD
|CMSPAR
: slc
->Parity
= MARKPARITY
; break;
285 case PARENB
|CMSPAR
: slc
->Parity
= SPACEPARITY
; break;
288 switch (port
.c_cflag
& CSIZE
)
290 case CS5
: slc
->WordLength
= 5; break;
291 case CS6
: slc
->WordLength
= 6; break;
292 case CS7
: slc
->WordLength
= 7; break;
293 case CS8
: slc
->WordLength
= 8; break;
294 default: ERR("unknown size %x\n", (UINT
)(port
.c_cflag
& CSIZE
));
297 if (port
.c_cflag
& CSTOPB
)
299 if (slc
->WordLength
== 5)
300 slc
->StopBits
= ONE5STOPBITS
;
302 slc
->StopBits
= TWOSTOPBITS
;
305 slc
->StopBits
= ONESTOPBIT
;
307 return STATUS_SUCCESS
;
310 static NTSTATUS
get_modem_status(int fd
, DWORD
* lpModemStat
)
312 NTSTATUS status
= STATUS_NOT_SUPPORTED
;
317 if (!ioctl(fd
, TIOCMGET
, &mstat
))
320 if (mstat
& TIOCM_CTS
) *lpModemStat
|= MS_CTS_ON
;
323 if (mstat
& TIOCM_DSR
) *lpModemStat
|= MS_DSR_ON
;
326 if (mstat
& TIOCM_RNG
) *lpModemStat
|= MS_RING_ON
;
329 /* FIXME: Not really sure about RLSD UB 990810 */
330 if (mstat
& TIOCM_CAR
) *lpModemStat
|= MS_RLSD_ON
;
332 TRACE("%04x -> %s%s%s%s\n", mstat
,
333 (*lpModemStat
& MS_RLSD_ON
) ? "MS_RLSD_ON " : "",
334 (*lpModemStat
& MS_RING_ON
) ? "MS_RING_ON " : "",
335 (*lpModemStat
& MS_DSR_ON
) ? "MS_DSR_ON " : "",
336 (*lpModemStat
& MS_CTS_ON
) ? "MS_CTS_ON " : "");
337 return STATUS_SUCCESS
;
339 WARN("TIOCMGET err %s\n", strerror(errno
));
340 status
= errno_to_status( errno
);
345 static NTSTATUS
get_properties(int fd
, SERIAL_COMMPROP
*prop
)
347 /* FIXME: get actual properties from the device */
348 memset( prop
, 0, sizeof(*prop
) );
349 prop
->PacketLength
= 1;
350 prop
->PacketVersion
= 1;
351 prop
->ServiceMask
= SP_SERIALCOMM
;
352 prop
->MaxTxQueue
= 4096;
353 prop
->MaxRxQueue
= 4096;
354 prop
->MaxBaud
= BAUD_115200
;
355 prop
->ProvSubType
= PST_RS232
;
356 prop
->ProvCapabilities
= PCF_DTRDSR
| PCF_PARITY_CHECK
| PCF_RTSCTS
| PCF_TOTALTIMEOUTS
| PCF_INTTIMEOUTS
;
357 prop
->SettableParams
= SP_BAUD
| SP_DATABITS
| SP_HANDSHAKING
|
358 SP_PARITY
| SP_PARITY_CHECK
| SP_STOPBITS
;
359 prop
->SettableBaud
= BAUD_075
| BAUD_110
| BAUD_134_5
| BAUD_150
|
360 BAUD_300
| BAUD_600
| BAUD_1200
| BAUD_1800
| BAUD_2400
| BAUD_4800
|
361 BAUD_9600
| BAUD_19200
| BAUD_38400
| BAUD_57600
| BAUD_115200
;
362 prop
->SettableData
= DATABITS_5
| DATABITS_6
| DATABITS_7
| DATABITS_8
;
363 prop
->SettableStopParity
= STOPBITS_10
| STOPBITS_15
| STOPBITS_20
|
364 PARITY_NONE
| PARITY_ODD
|PARITY_EVEN
| PARITY_MARK
| PARITY_SPACE
;
365 prop
->CurrentTxQueue
= prop
->MaxTxQueue
;
366 prop
->CurrentRxQueue
= prop
->MaxRxQueue
;
367 return STATUS_SUCCESS
;
370 static NTSTATUS
get_special_chars(int fd
, SERIAL_CHARS
* sc
)
374 if (tcgetattr(fd
, &port
) == -1)
376 ERR("tcgetattr error '%s'\n", strerror(errno
));
377 return errno_to_status( errno
);
379 sc
->EofChar
= port
.c_cc
[VEOF
];
380 sc
->ErrorChar
= 0xFF;
381 sc
->BreakChar
= 0; /* FIXME */
382 sc
->EventChar
= 0; /* FIXME */
383 sc
->XonChar
= port
.c_cc
[VSTART
];
384 sc
->XoffChar
= port
.c_cc
[VSTOP
];
386 return STATUS_SUCCESS
;
389 static NTSTATUS
get_status(int fd
, SERIAL_STATUS
* ss
)
391 NTSTATUS status
= STATUS_SUCCESS
;
395 ss
->EofReceived
= FALSE
;
396 ss
->WaitForImmediate
= FALSE
;
398 if (ioctl(fd
, TIOCOUTQ
, &ss
->AmountInOutQueue
) == -1)
400 WARN("ioctl returned error\n");
401 status
= errno_to_status( errno
);
404 ss
->AmountInOutQueue
= 0; /* FIXME: find a different way to find out */
408 if (ioctl(fd
, TIOCINQ
, &ss
->AmountInInQueue
))
410 WARN("ioctl returned error\n");
411 status
= errno_to_status( errno
);
414 ss
->AmountInInQueue
= 0; /* FIXME: find a different way to find out */
419 static void stop_waiting( HANDLE handle
)
423 SERVER_START_REQ( set_serial_info
)
425 req
->handle
= wine_server_obj_handle( handle
);
426 req
->flags
= SERIALINFO_PENDING_WAIT
;
427 if ((status
= wine_server_call( req
)))
428 ERR("failed to clear waiting state: %#x\n", status
);
433 static NTSTATUS
get_wait_mask(HANDLE hDevice
, DWORD
*mask
, DWORD
*cookie
, DWORD
*pending_write
, BOOL start_wait
)
437 SERVER_START_REQ( get_serial_info
)
439 req
->handle
= wine_server_obj_handle( hDevice
);
440 req
->flags
= pending_write
? SERIALINFO_PENDING_WRITE
: 0;
441 if (start_wait
) req
->flags
|= SERIALINFO_PENDING_WAIT
;
442 if (!(status
= wine_server_call( req
)))
444 *mask
= reply
->eventmask
;
445 if (cookie
) *cookie
= reply
->cookie
;
446 if (pending_write
) *pending_write
= reply
->pending_write
;
453 static NTSTATUS
purge(int fd
, DWORD flags
)
456 ** not exactly sure how these are different
457 ** Perhaps if we had our own internal queues, one flushes them
458 ** and the other flushes the kernel's buffers.
460 if (flags
& PURGE_TXABORT
) tcflush(fd
, TCOFLUSH
);
461 if (flags
& PURGE_RXABORT
) tcflush(fd
, TCIFLUSH
);
462 if (flags
& PURGE_TXCLEAR
) tcflush(fd
, TCOFLUSH
);
463 if (flags
& PURGE_RXCLEAR
) tcflush(fd
, TCIFLUSH
);
464 return STATUS_SUCCESS
;
467 static NTSTATUS
set_baud_rate(int fd
, const SERIAL_BAUD_RATE
* sbr
)
471 if (tcgetattr(fd
, &port
) == -1)
473 ERR("tcgetattr error '%s'\n", strerror(errno
));
474 return errno_to_status( errno
);
477 switch (sbr
->BaudRate
)
479 case 0: cfsetospeed( &port
, B0
); break;
480 case 50: cfsetospeed( &port
, B50
); break;
481 case 75: cfsetospeed( &port
, B75
); break;
483 case CBR_110
: cfsetospeed( &port
, B110
); break;
484 case 134: cfsetospeed( &port
, B134
); break;
485 case 150: cfsetospeed( &port
, B150
); break;
486 case 200: cfsetospeed( &port
, B200
); break;
488 case CBR_300
: cfsetospeed( &port
, B300
); break;
490 case CBR_600
: cfsetospeed( &port
, B600
); break;
492 case CBR_1200
: cfsetospeed( &port
, B1200
); break;
493 case 1800: cfsetospeed( &port
, B1800
); break;
495 case CBR_2400
: cfsetospeed( &port
, B2400
); break;
497 case CBR_4800
: cfsetospeed( &port
, B4800
); break;
499 case CBR_9600
: cfsetospeed( &port
, B9600
); break;
501 case CBR_19200
: cfsetospeed( &port
, B19200
); break;
503 case CBR_38400
: cfsetospeed( &port
, B38400
); break;
505 case 57600: cfsetospeed( &port
, B57600
); break;
508 case 115200: cfsetospeed( &port
, B115200
); break;
511 case 230400: cfsetospeed( &port
, B230400
); break;
514 case 460800: cfsetospeed( &port
, B460800
); break;
517 case 500000: cfsetospeed( &port
, B500000
); break;
520 case 921600: cfsetospeed( &port
, B921600
); break;
523 case 1000000: cfsetospeed( &port
, B1000000
); break;
526 case 1152000: cfsetospeed( &port
, B1152000
); break;
529 case 1500000: cfsetospeed( &port
, B1500000
); break;
532 case 2000000: cfsetospeed( &port
, B2000000
); break;
535 case 2500000: cfsetospeed( &port
, B2500000
); break;
538 case 3000000: cfsetospeed( &port
, B3000000
); break;
541 case 3500000: cfsetospeed( &port
, B3500000
); break;
544 case 4000000: cfsetospeed( &port
, B4000000
); break;
547 #if defined (HAVE_LINUX_SERIAL_H) && defined (TIOCSSERIAL)
549 struct serial_struct nuts
;
552 ioctl(fd
, TIOCGSERIAL
, &nuts
);
553 nuts
.custom_divisor
= nuts
.baud_base
/ sbr
->BaudRate
;
554 if (!(nuts
.custom_divisor
)) nuts
.custom_divisor
= 1;
555 arby
= nuts
.baud_base
/ nuts
.custom_divisor
;
556 nuts
.flags
&= ~ASYNC_SPD_MASK
;
557 nuts
.flags
|= ASYNC_SPD_CUST
;
558 WARN("You (or a program acting at your behest) have specified\n"
559 "a non-standard baud rate %d. Wine will set the rate to %d,\n"
560 "which is as close as we can get by our present understanding of your\n"
561 "hardware. I hope you know what you are doing. Any disruption Wine\n"
562 "has caused to your linux system can be undone with setserial\n"
563 "(see man setserial). If you have incapacitated a Hayes type modem,\n"
564 "reset it and it will probably recover.\n", sbr
->BaudRate
, arby
);
565 ioctl(fd
, TIOCSSERIAL
, &nuts
);
566 cfsetospeed( &port
, B38400
);
569 #else /* Don't have linux/serial.h or lack TIOCSSERIAL */
570 ERR("baudrate %d\n", sbr
->BaudRate
);
571 return STATUS_NOT_SUPPORTED
;
572 #endif /* Don't have linux/serial.h or lack TIOCSSERIAL */
574 cfsetispeed( &port
, cfgetospeed(&port
) );
575 if (tcsetattr(fd
, TCSANOW
, &port
) == -1)
577 ERR("tcsetattr error '%s'\n", strerror(errno
));
578 return errno_to_status( errno
);
580 return STATUS_SUCCESS
;
583 static int whack_modem(int fd
, unsigned int andy
, unsigned int orrie
)
586 unsigned int mstat
, okay
;
587 okay
= ioctl(fd
, TIOCMGET
, &mstat
);
588 if (okay
) return okay
;
589 if (andy
) mstat
&= andy
;
591 return ioctl(fd
, TIOCMSET
, &mstat
);
597 static NTSTATUS
set_handflow(int fd
, const SERIAL_HANDFLOW
* shf
)
601 if ((shf
->FlowReplace
& (SERIAL_RTS_CONTROL
| SERIAL_RTS_HANDSHAKE
)) ==
602 (SERIAL_RTS_CONTROL
| SERIAL_RTS_HANDSHAKE
))
603 return STATUS_NOT_SUPPORTED
;
605 if (tcgetattr(fd
, &port
) == -1)
607 ERR("tcgetattr error '%s'\n", strerror(errno
));
608 return errno_to_status( errno
);
612 if ((shf
->ControlHandShake
& SERIAL_CTS_HANDSHAKE
) ||
613 (shf
->FlowReplace
& SERIAL_RTS_HANDSHAKE
))
615 port
.c_cflag
|= CRTSCTS
;
619 port
.c_cflag
&= ~CRTSCTS
;
622 if (shf
->ControlHandShake
& SERIAL_DTR_HANDSHAKE
)
624 WARN("DSR/DTR flow control not supported\n");
625 } else if (!(shf
->ControlHandShake
& SERIAL_DTR_CONTROL
))
626 whack_modem(fd
, ~TIOCM_DTR
, 0);
628 whack_modem(fd
, 0, TIOCM_DTR
);
631 if (!(shf
->ControlHandShake
& SERIAL_CTS_HANDSHAKE
))
633 if ((shf
->FlowReplace
& (SERIAL_RTS_CONTROL
|SERIAL_RTS_HANDSHAKE
)) == 0)
634 whack_modem(fd
, ~TIOCM_RTS
, 0);
636 whack_modem(fd
, 0, TIOCM_RTS
);
640 if (shf
->FlowReplace
& SERIAL_AUTO_RECEIVE
)
641 port
.c_iflag
|= IXOFF
;
643 port
.c_iflag
&= ~IXOFF
;
644 if (shf
->FlowReplace
& SERIAL_AUTO_TRANSMIT
)
645 port
.c_iflag
|= IXON
;
647 port
.c_iflag
&= ~IXON
;
648 if (tcsetattr(fd
, TCSANOW
, &port
) == -1)
650 ERR("tcsetattr error '%s'\n", strerror(errno
));
651 return errno_to_status( errno
);
654 return STATUS_SUCCESS
;
657 static NTSTATUS
set_line_control(int fd
, const SERIAL_LINE_CONTROL
* slc
)
660 unsigned bytesize
, stopbits
;
662 if (tcgetattr(fd
, &port
) == -1)
664 ERR("tcgetattr error '%s'\n", strerror(errno
));
665 return errno_to_status( errno
);
669 port
.c_iflag
&= ~(ISTRIP
|BRKINT
|IGNCR
|ICRNL
|INLCR
|PARMRK
|IMAXBEL
);
671 port
.c_iflag
&= ~(ISTRIP
|BRKINT
|IGNCR
|ICRNL
|INLCR
|PARMRK
);
673 port
.c_iflag
|= IGNBRK
| INPCK
;
674 port
.c_oflag
&= ~(OPOST
);
675 port
.c_cflag
&= ~(HUPCL
);
676 port
.c_cflag
|= CLOCAL
| CREAD
;
679 * on FreeBSD, turning off ICANON does not disable IEXTEN,
680 * so we must turn it off explicitly. No harm done on Linux.
682 port
.c_lflag
&= ~(ICANON
|ECHO
|ISIG
|IEXTEN
);
683 port
.c_lflag
|= NOFLSH
;
685 bytesize
= slc
->WordLength
;
686 stopbits
= slc
->StopBits
;
689 port
.c_cflag
&= ~(PARENB
| PARODD
| CMSPAR
);
691 port
.c_cflag
&= ~(PARENB
| PARODD
);
694 /* make sure that reads don't block */
696 port
.c_cc
[VTIME
] = 0;
700 case NOPARITY
: port
.c_iflag
&= ~INPCK
; break;
701 case ODDPARITY
: port
.c_cflag
|= PARENB
| PARODD
; break;
702 case EVENPARITY
: port
.c_cflag
|= PARENB
; break;
704 /* Linux defines mark/space (stick) parity */
705 case MARKPARITY
: port
.c_cflag
|= PARENB
| PARODD
| CMSPAR
; break;
706 case SPACEPARITY
: port
.c_cflag
|= PARENB
| CMSPAR
; break;
708 /* try the POSIX way */
710 if (slc
->StopBits
== ONESTOPBIT
)
712 stopbits
= TWOSTOPBITS
;
713 port
.c_iflag
&= ~INPCK
;
717 FIXME("Cannot set MARK Parity\n");
718 return STATUS_NOT_SUPPORTED
;
722 if (slc
->WordLength
< 8)
725 port
.c_iflag
&= ~INPCK
;
729 FIXME("Cannot set SPACE Parity\n");
730 return STATUS_NOT_SUPPORTED
;
735 FIXME("Parity %d is not supported\n", slc
->Parity
);
736 return STATUS_NOT_SUPPORTED
;
739 port
.c_cflag
&= ~CSIZE
;
742 case 5: port
.c_cflag
|= CS5
; break;
743 case 6: port
.c_cflag
|= CS6
; break;
744 case 7: port
.c_cflag
|= CS7
; break;
745 case 8: port
.c_cflag
|= CS8
; break;
747 FIXME("ByteSize %d is not supported\n", bytesize
);
748 return STATUS_NOT_SUPPORTED
;
753 case ONESTOPBIT
: port
.c_cflag
&= ~CSTOPB
; break;
754 case ONE5STOPBITS
: /* will be selected if bytesize is 5 */
755 case TWOSTOPBITS
: port
.c_cflag
|= CSTOPB
; break;
757 FIXME("StopBits %d is not supported\n", stopbits
);
758 return STATUS_NOT_SUPPORTED
;
760 /* otherwise it hangs with pending input*/
761 if (tcsetattr(fd
, TCSANOW
, &port
) == -1)
763 ERR("tcsetattr error '%s'\n", strerror(errno
));
764 return errno_to_status( errno
);
766 return STATUS_SUCCESS
;
769 static NTSTATUS
set_queue_size(int fd
, const SERIAL_QUEUE_SIZE
* sqs
)
771 FIXME("insize %d outsize %d unimplemented stub\n", sqs
->InSize
, sqs
->OutSize
);
772 return STATUS_SUCCESS
;
775 static NTSTATUS
set_special_chars(int fd
, const SERIAL_CHARS
* sc
)
779 if (tcgetattr(fd
, &port
) == -1)
781 ERR("tcgetattr error '%s'\n", strerror(errno
));
782 return errno_to_status( errno
);
785 port
.c_cc
[VEOF
] = sc
->EofChar
;
786 /* FIXME: sc->ErrorChar is not supported */
787 /* FIXME: sc->BreakChar is not supported */
788 /* FIXME: sc->EventChar is not supported */
789 port
.c_cc
[VSTART
] = sc
->XonChar
;
790 port
.c_cc
[VSTOP
] = sc
->XoffChar
;
792 if (tcsetattr(fd
, TCSANOW
, &port
) == -1)
794 ERR("tcsetattr error '%s'\n", strerror(errno
));
795 return errno_to_status( errno
);
797 return STATUS_SUCCESS
;
801 * does not change IXOFF but simulates that IXOFF has been received:
803 static NTSTATUS
set_XOff(int fd
)
805 if (tcflow(fd
, TCOOFF
))
807 return errno_to_status( errno
);
809 return STATUS_SUCCESS
;
813 * does not change IXON but simulates that IXON has been received:
815 static NTSTATUS
set_XOn(int fd
)
817 if (tcflow(fd
, TCOON
))
819 return errno_to_status( errno
);
821 return STATUS_SUCCESS
;
825 * local structure holding the irq values we need for WaitCommEvent()
827 * Stripped down from struct serial_icounter_struct, which may not be available on some systems
828 * As the modem line interrupts (cts, dsr, rng, dcd) only get updated with TIOCMIWAIT active,
829 * no need to carry them in the internal structure
832 typedef struct serial_irq_info
834 int rx
, tx
, frame
, overrun
, parity
, brk
, buf_overrun
, temt
;
837 /***********************************************************************
838 * Data needed by the thread polling for the changing CommEvent
840 typedef struct async_commio
844 IO_STATUS_BLOCK
* iosb
;
850 serial_irq_info irq_info
;
853 /***********************************************************************
854 * Get extended interrupt count info, needed for wait_on
856 static NTSTATUS
get_irq_info(int fd
, serial_irq_info
*irq_info
)
860 #if defined (HAVE_LINUX_SERIAL_H) && defined (TIOCGICOUNT)
861 struct serial_icounter_struct einfo
;
862 if (!ioctl(fd
, TIOCGICOUNT
, &einfo
))
864 irq_info
->rx
= einfo
.rx
;
865 irq_info
->tx
= einfo
.tx
;
866 irq_info
->frame
= einfo
.frame
;
867 irq_info
->overrun
= einfo
.overrun
;
868 irq_info
->parity
= einfo
.parity
;
869 irq_info
->brk
= einfo
.brk
;
870 irq_info
->buf_overrun
= einfo
.buf_overrun
;
874 TRACE("TIOCGICOUNT err %s\n", strerror(errno
));
875 memset(irq_info
,0, sizeof(serial_irq_info
));
878 memset(irq_info
,0, sizeof(serial_irq_info
));
882 /* Generate a single TX_TXEMPTY event when the TX Buffer turns empty*/
883 #ifdef TIOCSERGETLSR /* prefer to log the state TIOCSERGETLSR */
884 if (!ioctl(fd
, TIOCSERGETLSR
, &out
))
886 irq_info
->temt
= (out
& TIOCSER_TEMT
) != 0;
887 return STATUS_SUCCESS
;
890 TRACE("TIOCSERGETLSR err %s\n", strerror(errno
));
892 #ifdef TIOCOUTQ /* otherwise we log when the out queue gets empty */
893 if (!ioctl(fd
, TIOCOUTQ
, &out
))
895 irq_info
->temt
= out
== 0;
896 return STATUS_SUCCESS
;
898 TRACE("TIOCOUTQ err %s\n", strerror(errno
));
899 return errno_to_status( errno
);
901 return STATUS_SUCCESS
;
905 static DWORD
check_events(int fd
, DWORD mask
,
906 const serial_irq_info
*new,
907 const serial_irq_info
*old
,
908 DWORD new_mstat
, DWORD old_mstat
, DWORD pending_write
)
910 DWORD ret
= 0, queue
;
912 TRACE("mask 0x%08x\n", mask
);
913 TRACE("old->rx 0x%08x vs. new->rx 0x%08x\n", old
->rx
, new->rx
);
914 TRACE("old->tx 0x%08x vs. new->tx 0x%08x\n", old
->tx
, new->tx
);
915 TRACE("old->frame 0x%08x vs. new->frame 0x%08x\n", old
->frame
, new->frame
);
916 TRACE("old->overrun 0x%08x vs. new->overrun 0x%08x\n", old
->overrun
, new->overrun
);
917 TRACE("old->parity 0x%08x vs. new->parity 0x%08x\n", old
->parity
, new->parity
);
918 TRACE("old->brk 0x%08x vs. new->brk 0x%08x\n", old
->brk
, new->brk
);
919 TRACE("old->buf_overrun 0x%08x vs. new->buf_overrun 0x%08x\n", old
->buf_overrun
, new->buf_overrun
);
920 TRACE("old->temt 0x%08x vs. new->temt 0x%08x\n", old
->temt
, new->temt
);
922 if (old
->brk
!= new->brk
) ret
|= EV_BREAK
;
923 if ((old_mstat
& MS_CTS_ON
) != (new_mstat
& MS_CTS_ON
)) ret
|= EV_CTS
;
924 if ((old_mstat
& MS_DSR_ON
) != (new_mstat
& MS_DSR_ON
)) ret
|= EV_DSR
;
925 if ((old_mstat
& MS_RING_ON
) != (new_mstat
& MS_RING_ON
)) ret
|= EV_RING
;
926 if ((old_mstat
& MS_RLSD_ON
) != (new_mstat
& MS_RLSD_ON
)) ret
|= EV_RLSD
;
927 if (old
->frame
!= new->frame
|| old
->overrun
!= new->overrun
|| old
->parity
!= new->parity
) ret
|= EV_ERR
;
928 if (mask
& EV_RXCHAR
)
932 if (ioctl(fd
, TIOCINQ
, &queue
))
933 WARN("TIOCINQ returned error\n");
938 if (mask
& EV_TXEMPTY
)
940 if ((!old
->temt
|| pending_write
) && new->temt
)
946 /***********************************************************************
947 * wait_for_event (INTERNAL)
949 * We need to poll for what is interesting
950 * TIOCMIWAIT only checks modem status line and may not be aborted by a changing mask
953 static void CALLBACK
wait_for_event(LPVOID arg
)
955 async_commio
*commio
= arg
;
958 if (!server_get_unix_fd( commio
->hDevice
, FILE_READ_DATA
| FILE_WRITE_DATA
, &fd
, &needs_close
, NULL
, NULL
))
960 serial_irq_info new_irq_info
;
961 DWORD new_mstat
, dummy
, cookie
;
964 TRACE("device=%p fd=0x%08x mask=0x%08x buffer=%p event=%p irq_info=%p\n",
965 commio
->hDevice
, fd
, commio
->evtmask
, commio
->events
, commio
->hEvent
, &commio
->irq_info
);
967 time
.QuadPart
= (ULONGLONG
)10000;
968 time
.QuadPart
= -time
.QuadPart
;
972 * TIOCMIWAIT is not adequate
975 * We don't handle the EV_RXFLAG (the eventchar)
977 NtDelayExecution(FALSE
, &time
);
978 get_irq_info(fd
, &new_irq_info
);
979 if (get_modem_status(fd
, &new_mstat
))
981 TRACE("get_modem_status failed\n");
985 *commio
->events
= check_events(fd
, commio
->evtmask
,
986 &new_irq_info
, &commio
->irq_info
,
987 new_mstat
, commio
->mstat
, commio
->pending_write
);
988 if (*commio
->events
) break;
989 get_wait_mask(commio
->hDevice
, &dummy
, &cookie
, (commio
->evtmask
& EV_TXEMPTY
) ? &commio
->pending_write
: NULL
, FALSE
);
990 if (commio
->cookie
!= cookie
)
996 if (needs_close
) close( fd
);
1000 if (*commio
->events
)
1002 commio
->iosb
->u
.Status
= STATUS_SUCCESS
;
1003 commio
->iosb
->Information
= sizeof(DWORD
);
1006 commio
->iosb
->u
.Status
= STATUS_CANCELLED
;
1008 stop_waiting(commio
->hDevice
);
1009 if (commio
->hEvent
) NtSetEvent(commio
->hEvent
, NULL
);
1011 NtTerminateThread( GetCurrentThread(), 0 );
1014 static NTSTATUS
wait_on(HANDLE hDevice
, int fd
, HANDLE hEvent
, PIO_STATUS_BLOCK piosb
, DWORD
* events
)
1016 async_commio
* commio
;
1020 if ((status
= NtResetEvent(hEvent
, NULL
)))
1023 commio
= malloc( sizeof(async_commio
) );
1024 if (!commio
) return STATUS_NO_MEMORY
;
1026 commio
->hDevice
= hDevice
;
1027 commio
->events
= events
;
1028 commio
->iosb
= piosb
;
1029 commio
->hEvent
= hEvent
;
1030 commio
->pending_write
= 0;
1031 status
= get_wait_mask(commio
->hDevice
, &commio
->evtmask
, &commio
->cookie
, (commio
->evtmask
& EV_TXEMPTY
) ? &commio
->pending_write
: NULL
, TRUE
);
1038 /* We may never return, if some capabilities miss
1039 * Return error in that case
1041 #if !defined(TIOCINQ)
1042 if (commio
->evtmask
& EV_RXCHAR
)
1045 #if !(defined(TIOCSERGETLSR) && defined(TIOCSER_TEMT)) || !defined(TIOCINQ)
1046 if (commio
->evtmask
& EV_TXEMPTY
)
1049 #if !defined(TIOCMGET)
1050 if (commio
->evtmask
& (EV_CTS
| EV_DSR
| EV_RING
| EV_RLSD
))
1053 #if !defined(TIOCM_CTS)
1054 if (commio
->evtmask
& EV_CTS
)
1057 #if !defined(TIOCM_DSR)
1058 if (commio
->evtmask
& EV_DSR
)
1061 #if !defined(TIOCM_RNG)
1062 if (commio
->evtmask
& EV_RING
)
1065 #if !defined(TIOCM_CAR)
1066 if (commio
->evtmask
& EV_RLSD
)
1069 if (commio
->evtmask
& EV_RXFLAG
)
1070 FIXME("EV_RXFLAG not handled\n");
1072 if ((status
= get_irq_info(fd
, &commio
->irq_info
)) &&
1073 (commio
->evtmask
& (EV_BREAK
| EV_ERR
)))
1076 if ((status
= get_modem_status(fd
, &commio
->mstat
)) &&
1077 (commio
->evtmask
& (EV_CTS
| EV_DSR
| EV_RING
| EV_RLSD
)))
1080 /* We might have received something or the TX buffer is delivered */
1081 *events
= check_events(fd
, commio
->evtmask
,
1082 &commio
->irq_info
, &commio
->irq_info
,
1083 commio
->mstat
, commio
->mstat
, commio
->pending_write
);
1086 status
= STATUS_SUCCESS
;
1090 /* create the worker thread for the task */
1091 /* FIXME: should use async I/O instead */
1092 status
= NtCreateThreadEx( &handle
, THREAD_ALL_ACCESS
, NULL
, GetCurrentProcess(),
1093 wait_for_event
, commio
, 0, 0, 0, 0, NULL
);
1094 if (status
!= STATUS_SUCCESS
) goto out_now
;
1096 return STATUS_PENDING
;
1098 #if !defined(TIOCINQ) || (!(defined(TIOCSERGETLSR) && defined(TIOCSER_TEMT)) || !defined(TIOCINQ)) || !defined(TIOCMGET) || !defined(TIOCM_CTS) ||!defined(TIOCM_DSR) || !defined(TIOCM_RNG) || !defined(TIOCM_CAR)
1100 FIXME("Returning error because of missing capabilities\n");
1101 status
= STATUS_INVALID_PARAMETER
;
1104 stop_waiting(commio
->hDevice
);
1109 static NTSTATUS
xmit_immediate(HANDLE hDevice
, int fd
, const char* ptr
)
1111 /* FIXME: not perfect as it should bypass the in-queue */
1112 WARN("(%p,'%c') not perfect!\n", hDevice
, *ptr
);
1113 if (write(fd
, ptr
, 1) != 1)
1114 return errno_to_status( errno
);
1115 return STATUS_SUCCESS
;
1118 static NTSTATUS
io_control( HANDLE device
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_user
,
1119 IO_STATUS_BLOCK
*io
, ULONG code
, void *in_buffer
,
1120 ULONG in_size
, void *out_buffer
, ULONG out_size
)
1122 DWORD sz
= 0, access
= FILE_READ_DATA
;
1123 NTSTATUS status
= STATUS_SUCCESS
;
1124 int fd
= -1, needs_close
= 0;
1125 enum server_fd_type type
;
1127 TRACE("%p %s %p %d %p %d %p\n",
1128 device
, iocode2str(code
), in_buffer
, in_size
, out_buffer
, out_size
, io
);
1132 case IOCTL_SERIAL_GET_TIMEOUTS
:
1133 case IOCTL_SERIAL_SET_TIMEOUTS
:
1134 case IOCTL_SERIAL_GET_WAIT_MASK
:
1135 case IOCTL_SERIAL_SET_WAIT_MASK
:
1136 /* these are handled on the server side */
1137 return STATUS_NOT_SUPPORTED
;
1140 io
->Information
= 0;
1142 if ((status
= server_get_unix_fd( device
, access
, &fd
, &needs_close
, &type
, NULL
))) goto error
;
1143 if (type
!= FD_TYPE_SERIAL
)
1145 if (needs_close
) close( fd
);
1146 status
= STATUS_OBJECT_TYPE_MISMATCH
;
1152 case IOCTL_SERIAL_CLR_DTR
:
1154 if (whack_modem(fd
, ~TIOCM_DTR
, 0) == -1) status
= errno_to_status( errno
);
1156 status
= STATUS_NOT_SUPPORTED
;
1159 case IOCTL_SERIAL_CLR_RTS
:
1161 if (whack_modem(fd
, ~TIOCM_RTS
, 0) == -1) status
= errno_to_status( errno
);
1163 status
= STATUS_NOT_SUPPORTED
;
1166 case IOCTL_SERIAL_GET_BAUD_RATE
:
1167 if (out_buffer
&& out_size
== sizeof(SERIAL_BAUD_RATE
))
1169 if (!(status
= get_baud_rate(fd
, out_buffer
)))
1170 sz
= sizeof(SERIAL_BAUD_RATE
);
1173 status
= STATUS_INVALID_PARAMETER
;
1175 case IOCTL_SERIAL_GET_CHARS
:
1176 if (out_buffer
&& out_size
== sizeof(SERIAL_CHARS
))
1178 if (!(status
= get_special_chars(fd
, out_buffer
)))
1179 sz
= sizeof(SERIAL_CHARS
);
1182 status
= STATUS_INVALID_PARAMETER
;
1184 case IOCTL_SERIAL_GET_COMMSTATUS
:
1185 if (out_buffer
&& out_size
== sizeof(SERIAL_STATUS
))
1187 if (!(status
= get_status(fd
, out_buffer
)))
1188 sz
= sizeof(SERIAL_STATUS
);
1190 else status
= STATUS_INVALID_PARAMETER
;
1192 case IOCTL_SERIAL_GET_HANDFLOW
:
1193 if (out_buffer
&& out_size
== sizeof(SERIAL_HANDFLOW
))
1195 if (!(status
= get_hand_flow(fd
, out_buffer
)))
1196 sz
= sizeof(SERIAL_HANDFLOW
);
1199 status
= STATUS_INVALID_PARAMETER
;
1201 case IOCTL_SERIAL_GET_LINE_CONTROL
:
1202 if (out_buffer
&& out_size
== sizeof(SERIAL_LINE_CONTROL
))
1204 if (!(status
= get_line_control(fd
, out_buffer
)))
1205 sz
= sizeof(SERIAL_LINE_CONTROL
);
1208 status
= STATUS_INVALID_PARAMETER
;
1210 case IOCTL_SERIAL_GET_MODEMSTATUS
:
1211 if (out_buffer
&& out_size
== sizeof(DWORD
))
1213 if (!(status
= get_modem_status(fd
, out_buffer
)))
1216 else status
= STATUS_INVALID_PARAMETER
;
1218 case IOCTL_SERIAL_GET_PROPERTIES
:
1219 if (out_buffer
&& out_size
== sizeof(SERIAL_COMMPROP
))
1221 if (!(status
= get_properties(fd
, out_buffer
)))
1222 sz
= sizeof(SERIAL_COMMPROP
);
1224 else status
= STATUS_INVALID_PARAMETER
;
1226 case IOCTL_SERIAL_IMMEDIATE_CHAR
:
1227 if (in_buffer
&& in_size
== sizeof(CHAR
))
1228 status
= xmit_immediate(device
, fd
, in_buffer
);
1230 status
= STATUS_INVALID_PARAMETER
;
1232 case IOCTL_SERIAL_PURGE
:
1233 if (in_buffer
&& in_size
== sizeof(DWORD
))
1234 status
= purge(fd
, *(DWORD
*)in_buffer
);
1236 status
= STATUS_INVALID_PARAMETER
;
1238 case IOCTL_SERIAL_RESET_DEVICE
:
1239 FIXME("Unsupported\n");
1241 case IOCTL_SERIAL_SET_BAUD_RATE
:
1242 if (in_buffer
&& in_size
== sizeof(SERIAL_BAUD_RATE
))
1243 status
= set_baud_rate(fd
, in_buffer
);
1245 status
= STATUS_INVALID_PARAMETER
;
1247 case IOCTL_SERIAL_SET_BREAK_OFF
:
1248 #if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
1249 if (ioctl(fd
, TIOCCBRK
, 0) == -1)
1251 TRACE("ioctl failed\n");
1252 status
= errno_to_status( errno
);
1255 FIXME("ioctl not available\n");
1256 status
= STATUS_NOT_SUPPORTED
;
1259 case IOCTL_SERIAL_SET_BREAK_ON
:
1260 #if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
1261 if (ioctl(fd
, TIOCSBRK
, 0) == -1)
1263 TRACE("ioctl failed\n");
1264 status
= errno_to_status( errno
);
1267 FIXME("ioctl not available\n");
1268 status
= STATUS_NOT_SUPPORTED
;
1271 case IOCTL_SERIAL_SET_CHARS
:
1272 if (in_buffer
&& in_size
== sizeof(SERIAL_CHARS
))
1273 status
= set_special_chars(fd
, in_buffer
);
1275 status
= STATUS_INVALID_PARAMETER
;
1277 case IOCTL_SERIAL_SET_DTR
:
1279 if (whack_modem(fd
, 0, TIOCM_DTR
) == -1) status
= errno_to_status( errno
);
1281 status
= STATUS_NOT_SUPPORTED
;
1284 case IOCTL_SERIAL_SET_HANDFLOW
:
1285 if (in_buffer
&& in_size
== sizeof(SERIAL_HANDFLOW
))
1286 status
= set_handflow(fd
, in_buffer
);
1288 status
= STATUS_INVALID_PARAMETER
;
1290 case IOCTL_SERIAL_SET_LINE_CONTROL
:
1291 if (in_buffer
&& in_size
== sizeof(SERIAL_LINE_CONTROL
))
1292 status
= set_line_control(fd
, in_buffer
);
1294 status
= STATUS_INVALID_PARAMETER
;
1296 case IOCTL_SERIAL_SET_QUEUE_SIZE
:
1297 if (in_buffer
&& in_size
== sizeof(SERIAL_QUEUE_SIZE
))
1298 status
= set_queue_size(fd
, in_buffer
);
1300 status
= STATUS_INVALID_PARAMETER
;
1302 case IOCTL_SERIAL_SET_RTS
:
1304 if (whack_modem(fd
, 0, TIOCM_RTS
) == -1) status
= errno_to_status( errno
);
1306 status
= STATUS_NOT_SUPPORTED
;
1309 case IOCTL_SERIAL_SET_XOFF
:
1310 status
= set_XOff(fd
);
1312 case IOCTL_SERIAL_SET_XON
:
1313 status
= set_XOn(fd
);
1315 case IOCTL_SERIAL_WAIT_ON_MASK
:
1316 if (out_buffer
&& out_size
== sizeof(DWORD
))
1318 if (!(status
= wait_on(device
, fd
, event
, io
, out_buffer
)))
1322 status
= STATUS_INVALID_PARAMETER
;
1325 FIXME("Unsupported IOCTL %x (type=%x access=%x func=%x meth=%x)\n",
1326 code
, code
>> 16, (code
>> 14) & 3, (code
>> 2) & 0xFFF, code
& 3);
1328 status
= STATUS_INVALID_PARAMETER
;
1331 if (needs_close
) close( fd
);
1333 io
->u
.Status
= status
;
1334 io
->Information
= sz
;
1335 if (event
&& status
!= STATUS_PENDING
) NtSetEvent(event
, NULL
);
1339 /******************************************************************
1340 * serial_DeviceIoControl
1342 NTSTATUS
serial_DeviceIoControl( HANDLE device
, HANDLE event
, PIO_APC_ROUTINE apc
, void *apc_user
,
1343 IO_STATUS_BLOCK
*io
, ULONG code
, void *in_buffer
,
1344 ULONG in_size
, void *out_buffer
, ULONG out_size
)
1348 if (code
== IOCTL_SERIAL_WAIT_ON_MASK
)
1352 /* this is an ioctl we implement in a non blocking way if event is not null
1353 * so we have to explicitly wait if no event is provided
1357 OBJECT_ATTRIBUTES attr
;
1359 attr
.Length
= sizeof(attr
);
1360 attr
.RootDirectory
= 0;
1361 attr
.ObjectName
= NULL
;
1362 attr
.Attributes
= OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
;
1363 attr
.SecurityDescriptor
= NULL
;
1364 attr
.SecurityQualityOfService
= NULL
;
1365 status
= NtCreateEvent(&hev
, EVENT_ALL_ACCESS
, &attr
, SynchronizationEvent
, FALSE
);
1367 if (status
) return status
;
1369 status
= io_control( device
, hev
, apc
, apc_user
, io
, code
,
1370 in_buffer
, in_size
, out_buffer
, out_size
);
1373 if (status
== STATUS_PENDING
)
1375 NtWaitForSingleObject(hev
, FALSE
, NULL
);
1376 status
= STATUS_SUCCESS
;
1381 else status
= io_control( device
, event
, apc
, apc_user
, io
, code
,
1382 in_buffer
, in_size
, out_buffer
, out_size
);
1386 NTSTATUS
serial_FlushBuffersFile( int fd
)
1389 while (tcdrain( fd
) == -1)
1391 if (errno
!= EINTR
) return errno_to_status( errno
);
1393 return STATUS_SUCCESS
;
1394 #elif defined(TIOCDRAIN)
1395 while (ioctl( fd
, TIOCDRAIN
) == -1)
1397 if (errno
!= EINTR
) return errno_to_status( errno
);
1399 return STATUS_SUCCESS
;
1400 #elif defined(TCSBRK)
1401 while (ioctl( fd
, TCSBRK
, 1 ) == -1)
1403 if (errno
!= EINTR
) return errno_to_status( errno
);
1405 return STATUS_SUCCESS
;
1407 ERR( "not supported\n" );
1408 return STATUS_NOT_IMPLEMENTED
;