1 /* Main file for COMM support
3 * DEC 93 Erik Bos <erik@xs4all.nl>
4 * Copyright 1996 Marcus Meissner
5 * Copyright 2005,2006 Eric Pouech
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
40 #ifdef HAVE_SYS_STAT_H
41 # include <sys/stat.h>
43 #include <sys/types.h>
44 #ifdef HAVE_SYS_FILIO_H
45 # include <sys/filio.h>
47 #ifdef HAVE_SYS_IOCTL_H
48 #include <sys/ioctl.h>
50 #ifdef HAVE_SYS_POLL_H
51 # include <sys/poll.h>
53 #ifdef HAVE_SYS_MODEM_H
54 # include <sys/modem.h>
56 #ifdef HAVE_SYS_STRTIO_H
57 # include <sys/strtio.h>
61 #define WIN32_NO_STATUS
62 #define NONAMELESSUNION
66 #include "ddk/ntddser.h"
67 #include "ntdll_misc.h"
68 #include "wine/server.h"
69 #include "wine/library.h"
70 #include "wine/debug.h"
72 #ifdef HAVE_LINUX_SERIAL_H
73 #ifdef HAVE_ASM_TYPES_H
74 #include <asm/types.h>
76 #include <linux/serial.h>
79 #if !defined(TIOCINQ) && defined(FIONREAD)
80 #define TIOCINQ FIONREAD
83 WINE_DEFAULT_DEBUG_CHANNEL(comm
);
85 static const char* iocode2str(DWORD ioc
)
89 #define X(x) case (x): return #x
90 X(IOCTL_SERIAL_CLEAR_STATS
);
91 X(IOCTL_SERIAL_CLR_DTR
);
92 X(IOCTL_SERIAL_CLR_RTS
);
93 X(IOCTL_SERIAL_CONFIG_SIZE
);
94 X(IOCTL_SERIAL_GET_BAUD_RATE
);
95 X(IOCTL_SERIAL_GET_CHARS
);
96 X(IOCTL_SERIAL_GET_COMMSTATUS
);
97 X(IOCTL_SERIAL_GET_DTRRTS
);
98 X(IOCTL_SERIAL_GET_HANDFLOW
);
99 X(IOCTL_SERIAL_GET_LINE_CONTROL
);
100 X(IOCTL_SERIAL_GET_MODEM_CONTROL
);
101 X(IOCTL_SERIAL_GET_MODEMSTATUS
);
102 X(IOCTL_SERIAL_GET_PROPERTIES
);
103 X(IOCTL_SERIAL_GET_STATS
);
104 X(IOCTL_SERIAL_GET_TIMEOUTS
);
105 X(IOCTL_SERIAL_GET_WAIT_MASK
);
106 X(IOCTL_SERIAL_IMMEDIATE_CHAR
);
107 X(IOCTL_SERIAL_LSRMST_INSERT
);
108 X(IOCTL_SERIAL_PURGE
);
109 X(IOCTL_SERIAL_RESET_DEVICE
);
110 X(IOCTL_SERIAL_SET_BAUD_RATE
);
111 X(IOCTL_SERIAL_SET_BREAK_ON
);
112 X(IOCTL_SERIAL_SET_BREAK_OFF
);
113 X(IOCTL_SERIAL_SET_CHARS
);
114 X(IOCTL_SERIAL_SET_DTR
);
115 X(IOCTL_SERIAL_SET_FIFO_CONTROL
);
116 X(IOCTL_SERIAL_SET_HANDFLOW
);
117 X(IOCTL_SERIAL_SET_LINE_CONTROL
);
118 X(IOCTL_SERIAL_SET_MODEM_CONTROL
);
119 X(IOCTL_SERIAL_SET_QUEUE_SIZE
);
120 X(IOCTL_SERIAL_SET_RTS
);
121 X(IOCTL_SERIAL_SET_TIMEOUTS
);
122 X(IOCTL_SERIAL_SET_WAIT_MASK
);
123 X(IOCTL_SERIAL_SET_XOFF
);
124 X(IOCTL_SERIAL_SET_XON
);
125 X(IOCTL_SERIAL_WAIT_ON_MASK
);
126 X(IOCTL_SERIAL_XOFF_COUNTER
);
128 default: { static char tmp
[32]; sprintf(tmp
, "IOCTL_SERIAL_%d\n", ioc
); return tmp
; }
132 static NTSTATUS
get_baud_rate(int fd
, SERIAL_BAUD_RATE
* sbr
)
137 if (tcgetattr(fd
, &port
) == -1)
139 ERR("tcgetattr error '%s'\n", strerror(errno
));
140 return FILE_GetNtStatus();
142 speed
= cfgetospeed(&port
);
145 case B0
: sbr
->BaudRate
= 0; break;
146 case B50
: sbr
->BaudRate
= 50; break;
147 case B75
: sbr
->BaudRate
= 75; break;
148 case B110
: sbr
->BaudRate
= 110; break;
149 case B134
: sbr
->BaudRate
= 134; break;
150 case B150
: sbr
->BaudRate
= 150; break;
151 case B200
: sbr
->BaudRate
= 200; break;
152 case B300
: sbr
->BaudRate
= 300; break;
153 case B600
: sbr
->BaudRate
= 600; break;
154 case B1200
: sbr
->BaudRate
= 1200; break;
155 case B1800
: sbr
->BaudRate
= 1800; break;
156 case B2400
: sbr
->BaudRate
= 2400; break;
157 case B4800
: sbr
->BaudRate
= 4800; break;
158 case B9600
: sbr
->BaudRate
= 9600; break;
159 case B19200
: sbr
->BaudRate
= 19200; break;
160 case B38400
: sbr
->BaudRate
= 38400; break;
162 case B57600
: sbr
->BaudRate
= 57600; break;
165 case B115200
: sbr
->BaudRate
= 115200; break;
168 case B230400
: sbr
->BaudRate
= 230400; break;
171 case B460800
: sbr
->BaudRate
= 460800; break;
174 case B500000
: sbr
->BaudRate
= 500000; break;
177 case B921600
: sbr
->BaudRate
= 921600; break;
180 case B1000000
: sbr
->BaudRate
= 1000000; break;
183 case B1152000
: sbr
->BaudRate
= 1152000; break;
186 case B1500000
: sbr
->BaudRate
= 1500000; break;
189 case B2000000
: sbr
->BaudRate
= 2000000; break;
192 case B2500000
: sbr
->BaudRate
= 2500000; break;
195 case B3000000
: sbr
->BaudRate
= 3000000; break;
198 case B3500000
: sbr
->BaudRate
= 3500000; break;
201 case B4000000
: sbr
->BaudRate
= 4000000; break;
204 ERR("unknown speed %x\n", speed
);
205 return STATUS_INVALID_PARAMETER
;
207 return STATUS_SUCCESS
;
210 static NTSTATUS
get_hand_flow(int fd
, SERIAL_HANDFLOW
* shf
)
215 if (tcgetattr(fd
, &port
) == -1)
217 ERR("tcgetattr error '%s'\n", strerror(errno
));
218 return FILE_GetNtStatus();
220 /* termios does not support DTR/DSR flow control */
221 shf
->ControlHandShake
= 0;
222 shf
->FlowReplace
= 0;
224 if (ioctl(fd
, TIOCMGET
, &stat
) == -1)
226 WARN("ioctl error '%s'\n", strerror(errno
));
227 shf
->ControlHandShake
|= SERIAL_DTR_CONTROL
;
228 shf
->FlowReplace
|= SERIAL_RTS_CONTROL
;
231 WARN("Setting DTR/RTS to enabled by default\n");
232 shf
->ControlHandShake
|= SERIAL_DTR_CONTROL
;
233 shf
->FlowReplace
|= SERIAL_RTS_CONTROL
;
236 if (stat
& TIOCM_DTR
)
238 shf
->ControlHandShake
|= SERIAL_DTR_CONTROL
;
240 if (port
.c_cflag
& CRTSCTS
)
242 shf
->FlowReplace
|= SERIAL_RTS_CONTROL
;
243 shf
->ControlHandShake
|= SERIAL_CTS_HANDSHAKE
;
249 if (stat
& TIOCM_RTS
)
251 shf
->FlowReplace
|= SERIAL_RTS_CONTROL
;
253 if (port
.c_iflag
& IXOFF
)
254 shf
->FlowReplace
|= SERIAL_AUTO_RECEIVE
;
255 if (port
.c_iflag
& IXON
)
256 shf
->FlowReplace
|= SERIAL_AUTO_TRANSMIT
;
260 return STATUS_SUCCESS
;
263 static NTSTATUS
get_line_control(int fd
, SERIAL_LINE_CONTROL
* slc
)
267 if (tcgetattr(fd
, &port
) == -1)
269 ERR("tcgetattr error '%s'\n", strerror(errno
));
270 return FILE_GetNtStatus();
274 switch (port
.c_cflag
& (PARENB
| PARODD
| CMSPAR
))
276 switch (port
.c_cflag
& (PARENB
| PARODD
))
279 case 0: slc
->Parity
= NOPARITY
; break;
280 case PARENB
: slc
->Parity
= EVENPARITY
; break;
281 case PARENB
|PARODD
: slc
->Parity
= ODDPARITY
; break;
283 case PARENB
|CMSPAR
: slc
->Parity
= MARKPARITY
; break;
284 case PARENB
|PARODD
|CMSPAR
: slc
->Parity
= SPACEPARITY
; break;
287 switch (port
.c_cflag
& CSIZE
)
289 case CS5
: slc
->WordLength
= 5; break;
290 case CS6
: slc
->WordLength
= 6; break;
291 case CS7
: slc
->WordLength
= 7; break;
292 case CS8
: slc
->WordLength
= 8; break;
293 default: ERR("unknown size %x\n", (UINT
)(port
.c_cflag
& CSIZE
));
296 if (port
.c_cflag
& CSTOPB
)
298 if (slc
->WordLength
== 5)
299 slc
->StopBits
= ONE5STOPBITS
;
301 slc
->StopBits
= TWOSTOPBITS
;
304 slc
->StopBits
= ONESTOPBIT
;
306 return STATUS_SUCCESS
;
309 static NTSTATUS
get_modem_status(int fd
, DWORD
* lpModemStat
)
311 NTSTATUS status
= STATUS_NOT_SUPPORTED
;
316 if (!ioctl(fd
, TIOCMGET
, &mstat
))
319 if (mstat
& TIOCM_CTS
) *lpModemStat
|= MS_CTS_ON
;
322 if (mstat
& TIOCM_DSR
) *lpModemStat
|= MS_DSR_ON
;
325 if (mstat
& TIOCM_RNG
) *lpModemStat
|= MS_RING_ON
;
328 /* FIXME: Not really sure about RLSD UB 990810 */
329 if (mstat
& TIOCM_CAR
) *lpModemStat
|= MS_RLSD_ON
;
331 TRACE("%04x -> %s%s%s%s\n", mstat
,
332 (*lpModemStat
& MS_RLSD_ON
) ? "MS_RLSD_ON " : "",
333 (*lpModemStat
& MS_RING_ON
) ? "MS_RING_ON " : "",
334 (*lpModemStat
& MS_DSR_ON
) ? "MS_DSR_ON " : "",
335 (*lpModemStat
& MS_CTS_ON
) ? "MS_CTS_ON " : "");
336 return STATUS_SUCCESS
;
338 WARN("TIOCMGET err %s\n", strerror(errno
));
339 status
= FILE_GetNtStatus();
344 static NTSTATUS
get_special_chars(int fd
, SERIAL_CHARS
* sc
)
348 if (tcgetattr(fd
, &port
) == -1)
350 ERR("tcgetattr error '%s'\n", strerror(errno
));
351 return FILE_GetNtStatus();
353 sc
->EofChar
= port
.c_cc
[VEOF
];
354 sc
->ErrorChar
= 0xFF;
355 sc
->BreakChar
= 0; /* FIXME */
356 sc
->EventChar
= 0; /* FIXME */
357 sc
->XonChar
= port
.c_cc
[VSTART
];
358 sc
->XoffChar
= port
.c_cc
[VSTOP
];
360 return STATUS_SUCCESS
;
363 static NTSTATUS
get_status(int fd
, SERIAL_STATUS
* ss
)
365 NTSTATUS status
= STATUS_SUCCESS
;
369 ss
->EofReceived
= FALSE
;
370 ss
->WaitForImmediate
= FALSE
;
372 if (ioctl(fd
, TIOCOUTQ
, &ss
->AmountInOutQueue
) == -1)
374 WARN("ioctl returned error\n");
375 status
= FILE_GetNtStatus();
378 ss
->AmountInOutQueue
= 0; /* FIXME: find a different way to find out */
382 if (ioctl(fd
, TIOCINQ
, &ss
->AmountInInQueue
))
384 WARN("ioctl returned error\n");
385 status
= FILE_GetNtStatus();
388 ss
->AmountInInQueue
= 0; /* FIXME: find a different way to find out */
393 static void stop_waiting( HANDLE handle
)
397 SERVER_START_REQ( set_serial_info
)
399 req
->handle
= wine_server_obj_handle( handle
);
400 req
->flags
= SERIALINFO_PENDING_WAIT
;
401 if ((status
= wine_server_call( req
)))
402 ERR("failed to clear waiting state: %#x\n", status
);
407 static NTSTATUS
get_wait_mask(HANDLE hDevice
, DWORD
*mask
, DWORD
*cookie
, DWORD
*pending_write
, BOOL start_wait
)
411 SERVER_START_REQ( get_serial_info
)
413 req
->handle
= wine_server_obj_handle( hDevice
);
414 req
->flags
= pending_write
? SERIALINFO_PENDING_WRITE
: 0;
415 if (start_wait
) req
->flags
|= SERIALINFO_PENDING_WAIT
;
416 if (!(status
= wine_server_call( req
)))
418 *mask
= reply
->eventmask
;
419 if (cookie
) *cookie
= reply
->cookie
;
420 if (pending_write
) *pending_write
= reply
->pending_write
;
427 static NTSTATUS
purge(int fd
, DWORD flags
)
430 ** not exactly sure how these are different
431 ** Perhaps if we had our own internal queues, one flushes them
432 ** and the other flushes the kernel's buffers.
434 if (flags
& PURGE_TXABORT
) tcflush(fd
, TCOFLUSH
);
435 if (flags
& PURGE_RXABORT
) tcflush(fd
, TCIFLUSH
);
436 if (flags
& PURGE_TXCLEAR
) tcflush(fd
, TCOFLUSH
);
437 if (flags
& PURGE_RXCLEAR
) tcflush(fd
, TCIFLUSH
);
438 return STATUS_SUCCESS
;
441 static NTSTATUS
set_baud_rate(int fd
, const SERIAL_BAUD_RATE
* sbr
)
445 if (tcgetattr(fd
, &port
) == -1)
447 ERR("tcgetattr error '%s'\n", strerror(errno
));
448 return FILE_GetNtStatus();
451 switch (sbr
->BaudRate
)
453 case 0: cfsetospeed( &port
, B0
); break;
454 case 50: cfsetospeed( &port
, B50
); break;
455 case 75: cfsetospeed( &port
, B75
); break;
457 case CBR_110
: cfsetospeed( &port
, B110
); break;
458 case 134: cfsetospeed( &port
, B134
); break;
459 case 150: cfsetospeed( &port
, B150
); break;
460 case 200: cfsetospeed( &port
, B200
); break;
462 case CBR_300
: cfsetospeed( &port
, B300
); break;
464 case CBR_600
: cfsetospeed( &port
, B600
); break;
466 case CBR_1200
: cfsetospeed( &port
, B1200
); break;
467 case 1800: cfsetospeed( &port
, B1800
); break;
469 case CBR_2400
: cfsetospeed( &port
, B2400
); break;
471 case CBR_4800
: cfsetospeed( &port
, B4800
); break;
473 case CBR_9600
: cfsetospeed( &port
, B9600
); break;
475 case CBR_19200
: cfsetospeed( &port
, B19200
); break;
477 case CBR_38400
: cfsetospeed( &port
, B38400
); break;
479 case 57600: cfsetospeed( &port
, B57600
); break;
482 case 115200: cfsetospeed( &port
, B115200
); break;
485 case 230400: cfsetospeed( &port
, B230400
); break;
488 case 460800: cfsetospeed( &port
, B460800
); break;
491 case 500000: cfsetospeed( &port
, B500000
); break;
494 case 921600: cfsetospeed( &port
, B921600
); break;
497 case 1000000: cfsetospeed( &port
, B1000000
); break;
500 case 1152000: cfsetospeed( &port
, B1152000
); break;
503 case 1500000: cfsetospeed( &port
, B1500000
); break;
506 case 2000000: cfsetospeed( &port
, B2000000
); break;
509 case 2500000: cfsetospeed( &port
, B2500000
); break;
512 case 3000000: cfsetospeed( &port
, B3000000
); break;
515 case 3500000: cfsetospeed( &port
, B3500000
); break;
518 case 4000000: cfsetospeed( &port
, B4000000
); break;
521 #if defined (HAVE_LINUX_SERIAL_H) && defined (TIOCSSERIAL)
523 struct serial_struct nuts
;
526 ioctl(fd
, TIOCGSERIAL
, &nuts
);
527 nuts
.custom_divisor
= nuts
.baud_base
/ sbr
->BaudRate
;
528 if (!(nuts
.custom_divisor
)) nuts
.custom_divisor
= 1;
529 arby
= nuts
.baud_base
/ nuts
.custom_divisor
;
530 nuts
.flags
&= ~ASYNC_SPD_MASK
;
531 nuts
.flags
|= ASYNC_SPD_CUST
;
532 WARN("You (or a program acting at your behest) have specified\n"
533 "a non-standard baud rate %d. Wine will set the rate to %d,\n"
534 "which is as close as we can get by our present understanding of your\n"
535 "hardware. I hope you know what you are doing. Any disruption Wine\n"
536 "has caused to your linux system can be undone with setserial\n"
537 "(see man setserial). If you have incapacitated a Hayes type modem,\n"
538 "reset it and it will probably recover.\n", sbr
->BaudRate
, arby
);
539 ioctl(fd
, TIOCSSERIAL
, &nuts
);
540 cfsetospeed( &port
, B38400
);
543 #else /* Don't have linux/serial.h or lack TIOCSSERIAL */
544 ERR("baudrate %d\n", sbr
->BaudRate
);
545 return STATUS_NOT_SUPPORTED
;
546 #endif /* Don't have linux/serial.h or lack TIOCSSERIAL */
548 cfsetispeed( &port
, cfgetospeed(&port
) );
549 if (tcsetattr(fd
, TCSANOW
, &port
) == -1)
551 ERR("tcsetattr error '%s'\n", strerror(errno
));
552 return FILE_GetNtStatus();
554 return STATUS_SUCCESS
;
557 static int whack_modem(int fd
, unsigned int andy
, unsigned int orrie
)
560 unsigned int mstat
, okay
;
561 okay
= ioctl(fd
, TIOCMGET
, &mstat
);
562 if (okay
) return okay
;
563 if (andy
) mstat
&= andy
;
565 return ioctl(fd
, TIOCMSET
, &mstat
);
571 static NTSTATUS
set_handflow(int fd
, const SERIAL_HANDFLOW
* shf
)
575 if ((shf
->FlowReplace
& (SERIAL_RTS_CONTROL
| SERIAL_RTS_HANDSHAKE
)) ==
576 (SERIAL_RTS_CONTROL
| SERIAL_RTS_HANDSHAKE
))
577 return STATUS_NOT_SUPPORTED
;
579 if (tcgetattr(fd
, &port
) == -1)
581 ERR("tcgetattr error '%s'\n", strerror(errno
));
582 return FILE_GetNtStatus();
586 if ((shf
->ControlHandShake
& SERIAL_CTS_HANDSHAKE
) ||
587 (shf
->FlowReplace
& SERIAL_RTS_HANDSHAKE
))
589 port
.c_cflag
|= CRTSCTS
;
593 port
.c_cflag
&= ~CRTSCTS
;
596 if (shf
->ControlHandShake
& SERIAL_DTR_HANDSHAKE
)
598 WARN("DSR/DTR flow control not supported\n");
599 } else if (!(shf
->ControlHandShake
& SERIAL_DTR_CONTROL
))
600 whack_modem(fd
, ~TIOCM_DTR
, 0);
602 whack_modem(fd
, 0, TIOCM_DTR
);
605 if (!(shf
->ControlHandShake
& SERIAL_CTS_HANDSHAKE
))
607 if ((shf
->FlowReplace
& (SERIAL_RTS_CONTROL
|SERIAL_RTS_HANDSHAKE
)) == 0)
608 whack_modem(fd
, ~TIOCM_RTS
, 0);
610 whack_modem(fd
, 0, TIOCM_RTS
);
614 if (shf
->FlowReplace
& SERIAL_AUTO_RECEIVE
)
615 port
.c_iflag
|= IXOFF
;
617 port
.c_iflag
&= ~IXOFF
;
618 if (shf
->FlowReplace
& SERIAL_AUTO_TRANSMIT
)
619 port
.c_iflag
|= IXON
;
621 port
.c_iflag
&= ~IXON
;
622 if (tcsetattr(fd
, TCSANOW
, &port
) == -1)
624 ERR("tcsetattr error '%s'\n", strerror(errno
));
625 return FILE_GetNtStatus();
628 return STATUS_SUCCESS
;
631 static NTSTATUS
set_line_control(int fd
, const SERIAL_LINE_CONTROL
* slc
)
634 unsigned bytesize
, stopbits
;
636 if (tcgetattr(fd
, &port
) == -1)
638 ERR("tcgetattr error '%s'\n", strerror(errno
));
639 return FILE_GetNtStatus();
643 port
.c_iflag
&= ~(ISTRIP
|BRKINT
|IGNCR
|ICRNL
|INLCR
|PARMRK
|IMAXBEL
);
645 port
.c_iflag
&= ~(ISTRIP
|BRKINT
|IGNCR
|ICRNL
|INLCR
|PARMRK
);
647 port
.c_iflag
|= IGNBRK
| INPCK
;
648 port
.c_oflag
&= ~(OPOST
);
649 port
.c_cflag
&= ~(HUPCL
);
650 port
.c_cflag
|= CLOCAL
| CREAD
;
653 * on FreeBSD, turning off ICANON does not disable IEXTEN,
654 * so we must turn it off explicitly. No harm done on Linux.
656 port
.c_lflag
&= ~(ICANON
|ECHO
|ISIG
|IEXTEN
);
657 port
.c_lflag
|= NOFLSH
;
659 bytesize
= slc
->WordLength
;
660 stopbits
= slc
->StopBits
;
663 port
.c_cflag
&= ~(PARENB
| PARODD
| CMSPAR
);
665 port
.c_cflag
&= ~(PARENB
| PARODD
);
668 /* make sure that reads don't block */
670 port
.c_cc
[VTIME
] = 0;
674 case NOPARITY
: port
.c_iflag
&= ~INPCK
; break;
675 case ODDPARITY
: port
.c_cflag
|= PARENB
| PARODD
; break;
676 case EVENPARITY
: port
.c_cflag
|= PARENB
; break;
678 /* Linux defines mark/space (stick) parity */
679 case MARKPARITY
: port
.c_cflag
|= PARENB
| CMSPAR
; break;
680 case SPACEPARITY
: port
.c_cflag
|= PARENB
| PARODD
| CMSPAR
; break;
682 /* try the POSIX way */
684 if (slc
->StopBits
== ONESTOPBIT
)
686 stopbits
= TWOSTOPBITS
;
687 port
.c_iflag
&= ~INPCK
;
691 FIXME("Cannot set MARK Parity\n");
692 return STATUS_NOT_SUPPORTED
;
696 if (slc
->WordLength
< 8)
699 port
.c_iflag
&= ~INPCK
;
703 FIXME("Cannot set SPACE Parity\n");
704 return STATUS_NOT_SUPPORTED
;
709 FIXME("Parity %d is not supported\n", slc
->Parity
);
710 return STATUS_NOT_SUPPORTED
;
713 port
.c_cflag
&= ~CSIZE
;
716 case 5: port
.c_cflag
|= CS5
; break;
717 case 6: port
.c_cflag
|= CS6
; break;
718 case 7: port
.c_cflag
|= CS7
; break;
719 case 8: port
.c_cflag
|= CS8
; break;
721 FIXME("ByteSize %d is not supported\n", bytesize
);
722 return STATUS_NOT_SUPPORTED
;
727 case ONESTOPBIT
: port
.c_cflag
&= ~CSTOPB
; break;
728 case ONE5STOPBITS
: /* will be selected if bytesize is 5 */
729 case TWOSTOPBITS
: port
.c_cflag
|= CSTOPB
; break;
731 FIXME("StopBits %d is not supported\n", stopbits
);
732 return STATUS_NOT_SUPPORTED
;
734 /* otherwise it hangs with pending input*/
735 if (tcsetattr(fd
, TCSANOW
, &port
) == -1)
737 ERR("tcsetattr error '%s'\n", strerror(errno
));
738 return FILE_GetNtStatus();
740 return STATUS_SUCCESS
;
743 static NTSTATUS
set_queue_size(int fd
, const SERIAL_QUEUE_SIZE
* sqs
)
745 FIXME("insize %d outsize %d unimplemented stub\n", sqs
->InSize
, sqs
->OutSize
);
746 return STATUS_SUCCESS
;
749 static NTSTATUS
set_special_chars(int fd
, const SERIAL_CHARS
* sc
)
753 if (tcgetattr(fd
, &port
) == -1)
755 ERR("tcgetattr error '%s'\n", strerror(errno
));
756 return FILE_GetNtStatus();
759 port
.c_cc
[VEOF
] = sc
->EofChar
;
760 /* FIXME: sc->ErrorChar is not supported */
761 /* FIXME: sc->BreakChar is not supported */
762 /* FIXME: sc->EventChar is not supported */
763 port
.c_cc
[VSTART
] = sc
->XonChar
;
764 port
.c_cc
[VSTOP
] = sc
->XoffChar
;
766 if (tcsetattr(fd
, TCSANOW
, &port
) == -1)
768 ERR("tcsetattr error '%s'\n", strerror(errno
));
769 return FILE_GetNtStatus();
771 return STATUS_SUCCESS
;
775 * does not change IXOFF but simulates that IXOFF has been received:
777 static NTSTATUS
set_XOff(int fd
)
779 if (tcflow(fd
, TCOOFF
))
781 return FILE_GetNtStatus();
783 return STATUS_SUCCESS
;
787 * does not change IXON but simulates that IXON has been received:
789 static NTSTATUS
set_XOn(int fd
)
791 if (tcflow(fd
, TCOON
))
793 return FILE_GetNtStatus();
795 return STATUS_SUCCESS
;
799 * local structure holding the irq values we need for WaitCommEvent()
801 * Stripped down from struct serial_icounter_struct, which may not be available on some systems
802 * As the modem line interrupts (cts, dsr, rng, dcd) only get updated with TIOCMIWAIT active,
803 * no need to carry them in the internal structure
806 typedef struct serial_irq_info
808 int rx
, tx
, frame
, overrun
, parity
, brk
, buf_overrun
, temt
;
811 /***********************************************************************
812 * Data needed by the thread polling for the changing CommEvent
814 typedef struct async_commio
818 IO_STATUS_BLOCK
* iosb
;
824 serial_irq_info irq_info
;
827 /***********************************************************************
828 * Get extended interrupt count info, needed for wait_on
830 static NTSTATUS
get_irq_info(int fd
, serial_irq_info
*irq_info
)
834 #if defined (HAVE_LINUX_SERIAL_H) && defined (TIOCGICOUNT)
835 struct serial_icounter_struct einfo
;
836 if (!ioctl(fd
, TIOCGICOUNT
, &einfo
))
838 irq_info
->rx
= einfo
.rx
;
839 irq_info
->tx
= einfo
.tx
;
840 irq_info
->frame
= einfo
.frame
;
841 irq_info
->overrun
= einfo
.overrun
;
842 irq_info
->parity
= einfo
.parity
;
843 irq_info
->brk
= einfo
.brk
;
844 irq_info
->buf_overrun
= einfo
.buf_overrun
;
848 TRACE("TIOCGICOUNT err %s\n", strerror(errno
));
849 memset(irq_info
,0, sizeof(serial_irq_info
));
852 memset(irq_info
,0, sizeof(serial_irq_info
));
856 /* Generate a single TX_TXEMPTY event when the TX Buffer turns empty*/
857 #ifdef TIOCSERGETLSR /* prefer to log the state TIOCSERGETLSR */
858 if (!ioctl(fd
, TIOCSERGETLSR
, &out
))
860 irq_info
->temt
= (out
& TIOCSER_TEMT
) != 0;
861 return STATUS_SUCCESS
;
864 TRACE("TIOCSERGETLSR err %s\n", strerror(errno
));
866 #ifdef TIOCOUTQ /* otherwise we log when the out queue gets empty */
867 if (!ioctl(fd
, TIOCOUTQ
, &out
))
869 irq_info
->temt
= out
== 0;
870 return STATUS_SUCCESS
;
872 TRACE("TIOCOUTQ err %s\n", strerror(errno
));
873 return FILE_GetNtStatus();
875 return STATUS_SUCCESS
;
879 static DWORD
check_events(int fd
, DWORD mask
,
880 const serial_irq_info
*new,
881 const serial_irq_info
*old
,
882 DWORD new_mstat
, DWORD old_mstat
, DWORD pending_write
)
884 DWORD ret
= 0, queue
;
886 TRACE("mask 0x%08x\n", mask
);
887 TRACE("old->rx 0x%08x vs. new->rx 0x%08x\n", old
->rx
, new->rx
);
888 TRACE("old->tx 0x%08x vs. new->tx 0x%08x\n", old
->tx
, new->tx
);
889 TRACE("old->frame 0x%08x vs. new->frame 0x%08x\n", old
->frame
, new->frame
);
890 TRACE("old->overrun 0x%08x vs. new->overrun 0x%08x\n", old
->overrun
, new->overrun
);
891 TRACE("old->parity 0x%08x vs. new->parity 0x%08x\n", old
->parity
, new->parity
);
892 TRACE("old->brk 0x%08x vs. new->brk 0x%08x\n", old
->brk
, new->brk
);
893 TRACE("old->buf_overrun 0x%08x vs. new->buf_overrun 0x%08x\n", old
->buf_overrun
, new->buf_overrun
);
894 TRACE("old->temt 0x%08x vs. new->temt 0x%08x\n", old
->temt
, new->temt
);
896 if (old
->brk
!= new->brk
) ret
|= EV_BREAK
;
897 if ((old_mstat
& MS_CTS_ON
) != (new_mstat
& MS_CTS_ON
)) ret
|= EV_CTS
;
898 if ((old_mstat
& MS_DSR_ON
) != (new_mstat
& MS_DSR_ON
)) ret
|= EV_DSR
;
899 if ((old_mstat
& MS_RING_ON
) != (new_mstat
& MS_RING_ON
)) ret
|= EV_RING
;
900 if ((old_mstat
& MS_RLSD_ON
) != (new_mstat
& MS_RLSD_ON
)) ret
|= EV_RLSD
;
901 if (old
->frame
!= new->frame
|| old
->overrun
!= new->overrun
|| old
->parity
!= new->parity
) ret
|= EV_ERR
;
902 if (mask
& EV_RXCHAR
)
906 if (ioctl(fd
, TIOCINQ
, &queue
))
907 WARN("TIOCINQ returned error\n");
912 if (mask
& EV_TXEMPTY
)
914 if ((!old
->temt
|| pending_write
) && new->temt
)
920 /***********************************************************************
921 * wait_for_event (INTERNAL)
923 * We need to poll for what is interesting
924 * TIOCMIWAIT only checks modem status line and may not be aborted by a changing mask
927 static DWORD CALLBACK
wait_for_event(LPVOID arg
)
929 async_commio
*commio
= arg
;
932 if (!server_get_unix_fd( commio
->hDevice
, FILE_READ_DATA
| FILE_WRITE_DATA
, &fd
, &needs_close
, NULL
, NULL
))
934 serial_irq_info new_irq_info
;
935 DWORD new_mstat
, dummy
, cookie
;
938 TRACE("device=%p fd=0x%08x mask=0x%08x buffer=%p event=%p irq_info=%p\n",
939 commio
->hDevice
, fd
, commio
->evtmask
, commio
->events
, commio
->hEvent
, &commio
->irq_info
);
941 time
.QuadPart
= (ULONGLONG
)10000;
942 time
.QuadPart
= -time
.QuadPart
;
946 * TIOCMIWAIT is not adequate
949 * We don't handle the EV_RXFLAG (the eventchar)
951 NtDelayExecution(FALSE
, &time
);
952 get_irq_info(fd
, &new_irq_info
);
953 if (get_modem_status(fd
, &new_mstat
))
955 TRACE("get_modem_status failed\n");
959 *commio
->events
= check_events(fd
, commio
->evtmask
,
960 &new_irq_info
, &commio
->irq_info
,
961 new_mstat
, commio
->mstat
, commio
->pending_write
);
962 if (*commio
->events
) break;
963 get_wait_mask(commio
->hDevice
, &dummy
, &cookie
, (commio
->evtmask
& EV_TXEMPTY
) ? &commio
->pending_write
: NULL
, FALSE
);
964 if (commio
->cookie
!= cookie
)
970 if (needs_close
) close( fd
);
976 commio
->iosb
->u
.Status
= STATUS_SUCCESS
;
977 commio
->iosb
->Information
= sizeof(DWORD
);
980 commio
->iosb
->u
.Status
= STATUS_CANCELLED
;
982 stop_waiting(commio
->hDevice
);
983 if (commio
->hEvent
) NtSetEvent(commio
->hEvent
, NULL
);
984 RtlFreeHeap(GetProcessHeap(), 0, commio
);
988 static NTSTATUS
wait_on(HANDLE hDevice
, int fd
, HANDLE hEvent
, PIO_STATUS_BLOCK piosb
, DWORD
* events
)
990 async_commio
* commio
;
993 if ((status
= NtResetEvent(hEvent
, NULL
)))
996 commio
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof (async_commio
));
997 if (!commio
) return STATUS_NO_MEMORY
;
999 commio
->hDevice
= hDevice
;
1000 commio
->events
= events
;
1001 commio
->iosb
= piosb
;
1002 commio
->hEvent
= hEvent
;
1003 commio
->pending_write
= 0;
1004 status
= get_wait_mask(commio
->hDevice
, &commio
->evtmask
, &commio
->cookie
, (commio
->evtmask
& EV_TXEMPTY
) ? &commio
->pending_write
: NULL
, TRUE
);
1007 RtlFreeHeap(GetProcessHeap(), 0, commio
);
1011 /* We may never return, if some capabilities miss
1012 * Return error in that case
1014 #if !defined(TIOCINQ)
1015 if (commio
->evtmask
& EV_RXCHAR
)
1018 #if !(defined(TIOCSERGETLSR) && defined(TIOCSER_TEMT)) || !defined(TIOCINQ)
1019 if (commio
->evtmask
& EV_TXEMPTY
)
1022 #if !defined(TIOCMGET)
1023 if (commio
->evtmask
& (EV_CTS
| EV_DSR
| EV_RING
| EV_RLSD
))
1026 #if !defined(TIOCM_CTS)
1027 if (commio
->evtmask
& EV_CTS
)
1030 #if !defined(TIOCM_DSR)
1031 if (commio
->evtmask
& EV_DSR
)
1034 #if !defined(TIOCM_RNG)
1035 if (commio
->evtmask
& EV_RING
)
1038 #if !defined(TIOCM_CAR)
1039 if (commio
->evtmask
& EV_RLSD
)
1042 if (commio
->evtmask
& EV_RXFLAG
)
1043 FIXME("EV_RXFLAG not handled\n");
1045 if ((status
= get_irq_info(fd
, &commio
->irq_info
)) &&
1046 (commio
->evtmask
& (EV_BREAK
| EV_ERR
)))
1049 if ((status
= get_modem_status(fd
, &commio
->mstat
)) &&
1050 (commio
->evtmask
& (EV_CTS
| EV_DSR
| EV_RING
| EV_RLSD
)))
1053 /* We might have received something or the TX buffer is delivered */
1054 *events
= check_events(fd
, commio
->evtmask
,
1055 &commio
->irq_info
, &commio
->irq_info
,
1056 commio
->mstat
, commio
->mstat
, commio
->pending_write
);
1059 status
= STATUS_SUCCESS
;
1063 /* create the worker for the task */
1064 status
= RtlQueueWorkItem(wait_for_event
, commio
, 0 /* FIXME */);
1065 if (status
!= STATUS_SUCCESS
) goto out_now
;
1066 return STATUS_PENDING
;
1068 #if !defined(TIOCINQ) || (!(defined(TIOCSERGETLSR) && defined(TIOCSER_TEMT)) || !defined(TIOCINQ)) || !defined(TIOCMGET) || !defined(TIOCM_CTS) ||!defined(TIOCM_DSR) || !defined(TIOCM_RNG) || !defined(TIOCM_CAR)
1070 FIXME("Returning error because of missing capabilities\n");
1071 status
= STATUS_INVALID_PARAMETER
;
1074 stop_waiting(commio
->hDevice
);
1075 RtlFreeHeap(GetProcessHeap(), 0, commio
);
1079 static NTSTATUS
xmit_immediate(HANDLE hDevice
, int fd
, const char* ptr
)
1081 /* FIXME: not perfect as it should bypass the in-queue */
1082 WARN("(%p,'%c') not perfect!\n", hDevice
, *ptr
);
1083 if (write(fd
, ptr
, 1) != 1)
1084 return FILE_GetNtStatus();
1085 return STATUS_SUCCESS
;
1088 /******************************************************************
1089 * COMM_DeviceIoControl
1093 static inline NTSTATUS
io_control(HANDLE hDevice
,
1094 HANDLE hEvent
, PIO_APC_ROUTINE UserApcRoutine
,
1095 PVOID UserApcContext
,
1096 PIO_STATUS_BLOCK piosb
,
1097 ULONG dwIoControlCode
,
1098 LPVOID lpInBuffer
, DWORD nInBufferSize
,
1099 LPVOID lpOutBuffer
, DWORD nOutBufferSize
)
1101 DWORD sz
= 0, access
= FILE_READ_DATA
;
1102 NTSTATUS status
= STATUS_SUCCESS
;
1103 int fd
= -1, needs_close
= 0;
1104 enum server_fd_type type
;
1106 TRACE("%p %s %p %d %p %d %p\n",
1107 hDevice
, iocode2str(dwIoControlCode
), lpInBuffer
, nInBufferSize
,
1108 lpOutBuffer
, nOutBufferSize
, piosb
);
1110 switch (dwIoControlCode
)
1112 case IOCTL_SERIAL_GET_TIMEOUTS
:
1113 case IOCTL_SERIAL_SET_TIMEOUTS
:
1114 case IOCTL_SERIAL_GET_WAIT_MASK
:
1115 case IOCTL_SERIAL_SET_WAIT_MASK
:
1116 /* these are handled on the server side */
1117 return STATUS_NOT_SUPPORTED
;
1120 piosb
->Information
= 0;
1122 if ((status
= server_get_unix_fd( hDevice
, access
, &fd
, &needs_close
, &type
, NULL
)))
1124 if (type
!= FD_TYPE_SERIAL
)
1126 if (needs_close
) close( fd
);
1127 status
= STATUS_OBJECT_TYPE_MISMATCH
;
1131 switch (dwIoControlCode
)
1133 case IOCTL_SERIAL_CLR_DTR
:
1135 if (whack_modem(fd
, ~TIOCM_DTR
, 0) == -1) status
= FILE_GetNtStatus();
1137 status
= STATUS_NOT_SUPPORTED
;
1140 case IOCTL_SERIAL_CLR_RTS
:
1142 if (whack_modem(fd
, ~TIOCM_RTS
, 0) == -1) status
= FILE_GetNtStatus();
1144 status
= STATUS_NOT_SUPPORTED
;
1147 case IOCTL_SERIAL_GET_BAUD_RATE
:
1148 if (lpOutBuffer
&& nOutBufferSize
== sizeof(SERIAL_BAUD_RATE
))
1150 if (!(status
= get_baud_rate(fd
, lpOutBuffer
)))
1151 sz
= sizeof(SERIAL_BAUD_RATE
);
1154 status
= STATUS_INVALID_PARAMETER
;
1156 case IOCTL_SERIAL_GET_CHARS
:
1157 if (lpOutBuffer
&& nOutBufferSize
== sizeof(SERIAL_CHARS
))
1159 if (!(status
= get_special_chars(fd
, lpOutBuffer
)))
1160 sz
= sizeof(SERIAL_CHARS
);
1163 status
= STATUS_INVALID_PARAMETER
;
1165 case IOCTL_SERIAL_GET_COMMSTATUS
:
1166 if (lpOutBuffer
&& nOutBufferSize
== sizeof(SERIAL_STATUS
))
1168 if (!(status
= get_status(fd
, lpOutBuffer
)))
1169 sz
= sizeof(SERIAL_STATUS
);
1171 else status
= STATUS_INVALID_PARAMETER
;
1173 case IOCTL_SERIAL_GET_HANDFLOW
:
1174 if (lpOutBuffer
&& nOutBufferSize
== sizeof(SERIAL_HANDFLOW
))
1176 if (!(status
= get_hand_flow(fd
, lpOutBuffer
)))
1177 sz
= sizeof(SERIAL_HANDFLOW
);
1180 status
= STATUS_INVALID_PARAMETER
;
1182 case IOCTL_SERIAL_GET_LINE_CONTROL
:
1183 if (lpOutBuffer
&& nOutBufferSize
== sizeof(SERIAL_LINE_CONTROL
))
1185 if (!(status
= get_line_control(fd
, lpOutBuffer
)))
1186 sz
= sizeof(SERIAL_LINE_CONTROL
);
1189 status
= STATUS_INVALID_PARAMETER
;
1191 case IOCTL_SERIAL_GET_MODEMSTATUS
:
1192 if (lpOutBuffer
&& nOutBufferSize
== sizeof(DWORD
))
1194 if (!(status
= get_modem_status(fd
, lpOutBuffer
)))
1197 else status
= STATUS_INVALID_PARAMETER
;
1199 case IOCTL_SERIAL_IMMEDIATE_CHAR
:
1200 if (lpInBuffer
&& nInBufferSize
== sizeof(CHAR
))
1201 status
= xmit_immediate(hDevice
, fd
, lpInBuffer
);
1203 status
= STATUS_INVALID_PARAMETER
;
1205 case IOCTL_SERIAL_PURGE
:
1206 if (lpInBuffer
&& nInBufferSize
== sizeof(DWORD
))
1207 status
= purge(fd
, *(DWORD
*)lpInBuffer
);
1209 status
= STATUS_INVALID_PARAMETER
;
1211 case IOCTL_SERIAL_RESET_DEVICE
:
1212 FIXME("Unsupported\n");
1214 case IOCTL_SERIAL_SET_BAUD_RATE
:
1215 if (lpInBuffer
&& nInBufferSize
== sizeof(SERIAL_BAUD_RATE
))
1216 status
= set_baud_rate(fd
, lpInBuffer
);
1218 status
= STATUS_INVALID_PARAMETER
;
1220 case IOCTL_SERIAL_SET_BREAK_OFF
:
1221 #if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
1222 if (ioctl(fd
, TIOCCBRK
, 0) == -1)
1224 TRACE("ioctl failed\n");
1225 status
= FILE_GetNtStatus();
1228 FIXME("ioctl not available\n");
1229 status
= STATUS_NOT_SUPPORTED
;
1232 case IOCTL_SERIAL_SET_BREAK_ON
:
1233 #if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
1234 if (ioctl(fd
, TIOCSBRK
, 0) == -1)
1236 TRACE("ioctl failed\n");
1237 status
= FILE_GetNtStatus();
1240 FIXME("ioctl not available\n");
1241 status
= STATUS_NOT_SUPPORTED
;
1244 case IOCTL_SERIAL_SET_CHARS
:
1245 if (lpInBuffer
&& nInBufferSize
== sizeof(SERIAL_CHARS
))
1246 status
= set_special_chars(fd
, lpInBuffer
);
1248 status
= STATUS_INVALID_PARAMETER
;
1250 case IOCTL_SERIAL_SET_DTR
:
1252 if (whack_modem(fd
, 0, TIOCM_DTR
) == -1) status
= FILE_GetNtStatus();
1254 status
= STATUS_NOT_SUPPORTED
;
1257 case IOCTL_SERIAL_SET_HANDFLOW
:
1258 if (lpInBuffer
&& nInBufferSize
== sizeof(SERIAL_HANDFLOW
))
1259 status
= set_handflow(fd
, lpInBuffer
);
1261 status
= STATUS_INVALID_PARAMETER
;
1263 case IOCTL_SERIAL_SET_LINE_CONTROL
:
1264 if (lpInBuffer
&& nInBufferSize
== sizeof(SERIAL_LINE_CONTROL
))
1265 status
= set_line_control(fd
, lpInBuffer
);
1267 status
= STATUS_INVALID_PARAMETER
;
1269 case IOCTL_SERIAL_SET_QUEUE_SIZE
:
1270 if (lpInBuffer
&& nInBufferSize
== sizeof(SERIAL_QUEUE_SIZE
))
1271 status
= set_queue_size(fd
, lpInBuffer
);
1273 status
= STATUS_INVALID_PARAMETER
;
1275 case IOCTL_SERIAL_SET_RTS
:
1277 if (whack_modem(fd
, 0, TIOCM_RTS
) == -1) status
= FILE_GetNtStatus();
1279 status
= STATUS_NOT_SUPPORTED
;
1282 case IOCTL_SERIAL_SET_XOFF
:
1283 status
= set_XOff(fd
);
1285 case IOCTL_SERIAL_SET_XON
:
1286 status
= set_XOn(fd
);
1288 case IOCTL_SERIAL_WAIT_ON_MASK
:
1289 if (lpOutBuffer
&& nOutBufferSize
== sizeof(DWORD
))
1291 if (!(status
= wait_on(hDevice
, fd
, hEvent
, piosb
, lpOutBuffer
)))
1295 status
= STATUS_INVALID_PARAMETER
;
1298 FIXME("Unsupported IOCTL %x (type=%x access=%x func=%x meth=%x)\n",
1299 dwIoControlCode
, dwIoControlCode
>> 16, (dwIoControlCode
>> 14) & 3,
1300 (dwIoControlCode
>> 2) & 0xFFF, dwIoControlCode
& 3);
1302 status
= STATUS_INVALID_PARAMETER
;
1305 if (needs_close
) close( fd
);
1307 piosb
->u
.Status
= status
;
1308 piosb
->Information
= sz
;
1309 if (hEvent
&& status
!= STATUS_PENDING
) NtSetEvent(hEvent
, NULL
);
1313 NTSTATUS
COMM_DeviceIoControl(HANDLE hDevice
,
1314 HANDLE hEvent
, PIO_APC_ROUTINE UserApcRoutine
,
1315 PVOID UserApcContext
,
1316 PIO_STATUS_BLOCK piosb
,
1317 ULONG dwIoControlCode
,
1318 LPVOID lpInBuffer
, DWORD nInBufferSize
,
1319 LPVOID lpOutBuffer
, DWORD nOutBufferSize
)
1323 if (dwIoControlCode
== IOCTL_SERIAL_WAIT_ON_MASK
)
1325 HANDLE hev
= hEvent
;
1327 /* this is an ioctl we implement in a non blocking way if hEvent is not
1329 * so we have to explicitly wait if no hEvent is provided
1333 OBJECT_ATTRIBUTES attr
;
1335 attr
.Length
= sizeof(attr
);
1336 attr
.RootDirectory
= 0;
1337 attr
.ObjectName
= NULL
;
1338 attr
.Attributes
= OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
;
1339 attr
.SecurityDescriptor
= NULL
;
1340 attr
.SecurityQualityOfService
= NULL
;
1341 status
= NtCreateEvent(&hev
, EVENT_ALL_ACCESS
, &attr
, SynchronizationEvent
, FALSE
);
1343 if (status
) return status
;
1345 status
= io_control(hDevice
, hev
, UserApcRoutine
, UserApcContext
,
1346 piosb
, dwIoControlCode
, lpInBuffer
, nInBufferSize
,
1347 lpOutBuffer
, nOutBufferSize
);
1350 if (status
== STATUS_PENDING
)
1352 NtWaitForSingleObject(hev
, FALSE
, NULL
);
1353 status
= STATUS_SUCCESS
;
1358 else status
= io_control(hDevice
, hEvent
, UserApcRoutine
, UserApcContext
,
1359 piosb
, dwIoControlCode
, lpInBuffer
, nInBufferSize
,
1360 lpOutBuffer
, nOutBufferSize
);
1364 NTSTATUS
COMM_FlushBuffersFile( int fd
)
1367 while (tcdrain( fd
) == -1)
1369 if (errno
!= EINTR
) return FILE_GetNtStatus();
1371 return STATUS_SUCCESS
;
1372 #elif defined(TIOCDRAIN)
1373 while (ioctl( fd
, TIOCDRAIN
) == -1)
1375 if (errno
!= EINTR
) return FILE_GetNtStatus();
1377 return STATUS_SUCCESS
;
1378 #elif defined(TCSBRK)
1379 while (ioctl( fd
, TCSBRK
, 1 ) == -1)
1381 if (errno
!= EINTR
) return FILE_GetNtStatus();
1383 return STATUS_SUCCESS
;
1385 ERR( "not supported\n" );
1386 return STATUS_NOT_IMPLEMENTED
;