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"
37 #ifdef HAVE_SYS_STAT_H
38 # include <sys/stat.h>
40 #include <sys/types.h>
41 #ifdef HAVE_SYS_FILIO_H
42 # include <sys/filio.h>
44 #ifdef HAVE_SYS_IOCTL_H
45 #include <sys/ioctl.h>
47 #ifdef HAVE_SYS_POLL_H
48 # include <sys/poll.h>
50 #ifdef HAVE_SYS_MODEM_H
51 # include <sys/modem.h>
53 #ifdef HAVE_SYS_STRTIO_H
54 # include <sys/strtio.h>
58 #define WIN32_NO_STATUS
59 #define NONAMELESSUNION
63 #include "ddk/ntddser.h"
64 #include "ntdll_misc.h"
65 #include "wine/server.h"
66 #include "wine/library.h"
67 #include "wine/debug.h"
69 #ifdef HAVE_LINUX_SERIAL_H
70 #ifdef HAVE_ASM_TYPES_H
71 #include <asm/types.h>
73 #include <linux/serial.h>
76 #if !defined(TIOCINQ) && defined(FIONREAD)
77 #define TIOCINQ FIONREAD
80 WINE_DEFAULT_DEBUG_CHANNEL(comm
);
82 static const char* iocode2str(DWORD ioc
)
86 #define X(x) case (x): return #x
87 X(IOCTL_SERIAL_CLEAR_STATS
);
88 X(IOCTL_SERIAL_CLR_DTR
);
89 X(IOCTL_SERIAL_CLR_RTS
);
90 X(IOCTL_SERIAL_CONFIG_SIZE
);
91 X(IOCTL_SERIAL_GET_BAUD_RATE
);
92 X(IOCTL_SERIAL_GET_CHARS
);
93 X(IOCTL_SERIAL_GET_COMMSTATUS
);
94 X(IOCTL_SERIAL_GET_DTRRTS
);
95 X(IOCTL_SERIAL_GET_HANDFLOW
);
96 X(IOCTL_SERIAL_GET_LINE_CONTROL
);
97 X(IOCTL_SERIAL_GET_MODEM_CONTROL
);
98 X(IOCTL_SERIAL_GET_MODEMSTATUS
);
99 X(IOCTL_SERIAL_GET_PROPERTIES
);
100 X(IOCTL_SERIAL_GET_STATS
);
101 X(IOCTL_SERIAL_GET_TIMEOUTS
);
102 X(IOCTL_SERIAL_GET_WAIT_MASK
);
103 X(IOCTL_SERIAL_IMMEDIATE_CHAR
);
104 X(IOCTL_SERIAL_LSRMST_INSERT
);
105 X(IOCTL_SERIAL_PURGE
);
106 X(IOCTL_SERIAL_RESET_DEVICE
);
107 X(IOCTL_SERIAL_SET_BAUD_RATE
);
108 X(IOCTL_SERIAL_SET_BREAK_ON
);
109 X(IOCTL_SERIAL_SET_BREAK_OFF
);
110 X(IOCTL_SERIAL_SET_CHARS
);
111 X(IOCTL_SERIAL_SET_DTR
);
112 X(IOCTL_SERIAL_SET_FIFO_CONTROL
);
113 X(IOCTL_SERIAL_SET_HANDFLOW
);
114 X(IOCTL_SERIAL_SET_LINE_CONTROL
);
115 X(IOCTL_SERIAL_SET_MODEM_CONTROL
);
116 X(IOCTL_SERIAL_SET_QUEUE_SIZE
);
117 X(IOCTL_SERIAL_SET_RTS
);
118 X(IOCTL_SERIAL_SET_TIMEOUTS
);
119 X(IOCTL_SERIAL_SET_WAIT_MASK
);
120 X(IOCTL_SERIAL_SET_XOFF
);
121 X(IOCTL_SERIAL_SET_XON
);
122 X(IOCTL_SERIAL_WAIT_ON_MASK
);
123 X(IOCTL_SERIAL_XOFF_COUNTER
);
125 default: { static char tmp
[32]; sprintf(tmp
, "IOCTL_SERIAL_%d\n", ioc
); return tmp
; }
129 static NTSTATUS
get_baud_rate(int fd
, SERIAL_BAUD_RATE
* sbr
)
134 if (tcgetattr(fd
, &port
) == -1)
136 ERR("tcgetattr error '%s'\n", strerror(errno
));
137 return FILE_GetNtStatus();
139 speed
= cfgetospeed(&port
);
142 case B0
: sbr
->BaudRate
= 0; break;
143 case B50
: sbr
->BaudRate
= 50; break;
144 case B75
: sbr
->BaudRate
= 75; break;
145 case B110
: sbr
->BaudRate
= 110; break;
146 case B134
: sbr
->BaudRate
= 134; break;
147 case B150
: sbr
->BaudRate
= 150; break;
148 case B200
: sbr
->BaudRate
= 200; break;
149 case B300
: sbr
->BaudRate
= 300; break;
150 case B600
: sbr
->BaudRate
= 600; break;
151 case B1200
: sbr
->BaudRate
= 1200; break;
152 case B1800
: sbr
->BaudRate
= 1800; break;
153 case B2400
: sbr
->BaudRate
= 2400; break;
154 case B4800
: sbr
->BaudRate
= 4800; break;
155 case B9600
: sbr
->BaudRate
= 9600; break;
156 case B19200
: sbr
->BaudRate
= 19200; break;
157 case B38400
: sbr
->BaudRate
= 38400; break;
159 case B57600
: sbr
->BaudRate
= 57600; break;
162 case B115200
: sbr
->BaudRate
= 115200; break;
165 case B230400
: sbr
->BaudRate
= 230400; break;
168 case B460800
: sbr
->BaudRate
= 460800; break;
171 case B500000
: sbr
->BaudRate
= 500000; break;
174 case B921600
: sbr
->BaudRate
= 921600; break;
177 case B1000000
: sbr
->BaudRate
= 1000000; break;
180 case B1152000
: sbr
->BaudRate
= 1152000; break;
183 case B1500000
: sbr
->BaudRate
= 1500000; break;
186 case B2000000
: sbr
->BaudRate
= 2000000; break;
189 case B2500000
: sbr
->BaudRate
= 2500000; break;
192 case B3000000
: sbr
->BaudRate
= 3000000; break;
195 case B3500000
: sbr
->BaudRate
= 3500000; break;
198 case B4000000
: sbr
->BaudRate
= 4000000; break;
201 ERR("unknown speed %x\n", speed
);
202 return STATUS_INVALID_PARAMETER
;
204 return STATUS_SUCCESS
;
207 static NTSTATUS
get_hand_flow(int fd
, SERIAL_HANDFLOW
* shf
)
212 if (tcgetattr(fd
, &port
) == -1)
214 ERR("tcgetattr error '%s'\n", strerror(errno
));
215 return FILE_GetNtStatus();
217 /* termios does not support DTR/DSR flow control */
218 shf
->ControlHandShake
= 0;
219 shf
->FlowReplace
= 0;
221 if (ioctl(fd
, TIOCMGET
, &stat
) == -1)
223 WARN("ioctl error '%s'\n", strerror(errno
));
224 shf
->ControlHandShake
|= SERIAL_DTR_CONTROL
;
225 shf
->FlowReplace
|= SERIAL_RTS_CONTROL
;
228 WARN("Setting DTR/RTS to enabled by default\n");
229 shf
->ControlHandShake
|= SERIAL_DTR_CONTROL
;
230 shf
->FlowReplace
|= SERIAL_RTS_CONTROL
;
233 if (stat
& TIOCM_DTR
)
235 shf
->ControlHandShake
|= SERIAL_DTR_CONTROL
;
237 if (port
.c_cflag
& CRTSCTS
)
239 shf
->FlowReplace
|= SERIAL_RTS_CONTROL
;
240 shf
->ControlHandShake
|= SERIAL_CTS_HANDSHAKE
;
246 if (stat
& TIOCM_RTS
)
248 shf
->FlowReplace
|= SERIAL_RTS_CONTROL
;
250 if (port
.c_iflag
& IXOFF
)
251 shf
->FlowReplace
|= SERIAL_AUTO_RECEIVE
;
252 if (port
.c_iflag
& IXON
)
253 shf
->FlowReplace
|= SERIAL_AUTO_TRANSMIT
;
257 return STATUS_SUCCESS
;
260 static NTSTATUS
get_line_control(int fd
, SERIAL_LINE_CONTROL
* slc
)
264 if (tcgetattr(fd
, &port
) == -1)
266 ERR("tcgetattr error '%s'\n", strerror(errno
));
267 return FILE_GetNtStatus();
271 switch (port
.c_cflag
& (PARENB
| PARODD
| CMSPAR
))
273 switch (port
.c_cflag
& (PARENB
| PARODD
))
276 case 0: slc
->Parity
= NOPARITY
; break;
277 case PARENB
: slc
->Parity
= EVENPARITY
; break;
278 case PARENB
|PARODD
: slc
->Parity
= ODDPARITY
; break;
280 case PARENB
|PARODD
|CMSPAR
: slc
->Parity
= MARKPARITY
; break;
281 case PARENB
|CMSPAR
: slc
->Parity
= SPACEPARITY
; break;
284 switch (port
.c_cflag
& CSIZE
)
286 case CS5
: slc
->WordLength
= 5; break;
287 case CS6
: slc
->WordLength
= 6; break;
288 case CS7
: slc
->WordLength
= 7; break;
289 case CS8
: slc
->WordLength
= 8; break;
290 default: ERR("unknown size %x\n", (UINT
)(port
.c_cflag
& CSIZE
));
293 if (port
.c_cflag
& CSTOPB
)
295 if (slc
->WordLength
== 5)
296 slc
->StopBits
= ONE5STOPBITS
;
298 slc
->StopBits
= TWOSTOPBITS
;
301 slc
->StopBits
= ONESTOPBIT
;
303 return STATUS_SUCCESS
;
306 static NTSTATUS
get_modem_status(int fd
, DWORD
* lpModemStat
)
308 NTSTATUS status
= STATUS_NOT_SUPPORTED
;
313 if (!ioctl(fd
, TIOCMGET
, &mstat
))
316 if (mstat
& TIOCM_CTS
) *lpModemStat
|= MS_CTS_ON
;
319 if (mstat
& TIOCM_DSR
) *lpModemStat
|= MS_DSR_ON
;
322 if (mstat
& TIOCM_RNG
) *lpModemStat
|= MS_RING_ON
;
325 /* FIXME: Not really sure about RLSD UB 990810 */
326 if (mstat
& TIOCM_CAR
) *lpModemStat
|= MS_RLSD_ON
;
328 TRACE("%04x -> %s%s%s%s\n", mstat
,
329 (*lpModemStat
& MS_RLSD_ON
) ? "MS_RLSD_ON " : "",
330 (*lpModemStat
& MS_RING_ON
) ? "MS_RING_ON " : "",
331 (*lpModemStat
& MS_DSR_ON
) ? "MS_DSR_ON " : "",
332 (*lpModemStat
& MS_CTS_ON
) ? "MS_CTS_ON " : "");
333 return STATUS_SUCCESS
;
335 WARN("TIOCMGET err %s\n", strerror(errno
));
336 status
= FILE_GetNtStatus();
341 static NTSTATUS
get_special_chars(int fd
, SERIAL_CHARS
* sc
)
345 if (tcgetattr(fd
, &port
) == -1)
347 ERR("tcgetattr error '%s'\n", strerror(errno
));
348 return FILE_GetNtStatus();
350 sc
->EofChar
= port
.c_cc
[VEOF
];
351 sc
->ErrorChar
= 0xFF;
352 sc
->BreakChar
= 0; /* FIXME */
353 sc
->EventChar
= 0; /* FIXME */
354 sc
->XonChar
= port
.c_cc
[VSTART
];
355 sc
->XoffChar
= port
.c_cc
[VSTOP
];
357 return STATUS_SUCCESS
;
360 static NTSTATUS
get_status(int fd
, SERIAL_STATUS
* ss
)
362 NTSTATUS status
= STATUS_SUCCESS
;
366 ss
->EofReceived
= FALSE
;
367 ss
->WaitForImmediate
= FALSE
;
369 if (ioctl(fd
, TIOCOUTQ
, &ss
->AmountInOutQueue
) == -1)
371 WARN("ioctl returned error\n");
372 status
= FILE_GetNtStatus();
375 ss
->AmountInOutQueue
= 0; /* FIXME: find a different way to find out */
379 if (ioctl(fd
, TIOCINQ
, &ss
->AmountInInQueue
))
381 WARN("ioctl returned error\n");
382 status
= FILE_GetNtStatus();
385 ss
->AmountInInQueue
= 0; /* FIXME: find a different way to find out */
390 static void stop_waiting( HANDLE handle
)
394 SERVER_START_REQ( set_serial_info
)
396 req
->handle
= wine_server_obj_handle( handle
);
397 req
->flags
= SERIALINFO_PENDING_WAIT
;
398 if ((status
= wine_server_call( req
)))
399 ERR("failed to clear waiting state: %#x\n", status
);
404 static NTSTATUS
get_wait_mask(HANDLE hDevice
, DWORD
*mask
, DWORD
*cookie
, DWORD
*pending_write
, BOOL start_wait
)
408 SERVER_START_REQ( get_serial_info
)
410 req
->handle
= wine_server_obj_handle( hDevice
);
411 req
->flags
= pending_write
? SERIALINFO_PENDING_WRITE
: 0;
412 if (start_wait
) req
->flags
|= SERIALINFO_PENDING_WAIT
;
413 if (!(status
= wine_server_call( req
)))
415 *mask
= reply
->eventmask
;
416 if (cookie
) *cookie
= reply
->cookie
;
417 if (pending_write
) *pending_write
= reply
->pending_write
;
424 static NTSTATUS
purge(int fd
, DWORD flags
)
427 ** not exactly sure how these are different
428 ** Perhaps if we had our own internal queues, one flushes them
429 ** and the other flushes the kernel's buffers.
431 if (flags
& PURGE_TXABORT
) tcflush(fd
, TCOFLUSH
);
432 if (flags
& PURGE_RXABORT
) tcflush(fd
, TCIFLUSH
);
433 if (flags
& PURGE_TXCLEAR
) tcflush(fd
, TCOFLUSH
);
434 if (flags
& PURGE_RXCLEAR
) tcflush(fd
, TCIFLUSH
);
435 return STATUS_SUCCESS
;
438 static NTSTATUS
set_baud_rate(int fd
, const SERIAL_BAUD_RATE
* sbr
)
442 if (tcgetattr(fd
, &port
) == -1)
444 ERR("tcgetattr error '%s'\n", strerror(errno
));
445 return FILE_GetNtStatus();
448 switch (sbr
->BaudRate
)
450 case 0: cfsetospeed( &port
, B0
); break;
451 case 50: cfsetospeed( &port
, B50
); break;
452 case 75: cfsetospeed( &port
, B75
); break;
454 case CBR_110
: cfsetospeed( &port
, B110
); break;
455 case 134: cfsetospeed( &port
, B134
); break;
456 case 150: cfsetospeed( &port
, B150
); break;
457 case 200: cfsetospeed( &port
, B200
); break;
459 case CBR_300
: cfsetospeed( &port
, B300
); break;
461 case CBR_600
: cfsetospeed( &port
, B600
); break;
463 case CBR_1200
: cfsetospeed( &port
, B1200
); break;
464 case 1800: cfsetospeed( &port
, B1800
); break;
466 case CBR_2400
: cfsetospeed( &port
, B2400
); break;
468 case CBR_4800
: cfsetospeed( &port
, B4800
); break;
470 case CBR_9600
: cfsetospeed( &port
, B9600
); break;
472 case CBR_19200
: cfsetospeed( &port
, B19200
); break;
474 case CBR_38400
: cfsetospeed( &port
, B38400
); break;
476 case 57600: cfsetospeed( &port
, B57600
); break;
479 case 115200: cfsetospeed( &port
, B115200
); break;
482 case 230400: cfsetospeed( &port
, B230400
); break;
485 case 460800: cfsetospeed( &port
, B460800
); break;
488 case 500000: cfsetospeed( &port
, B500000
); break;
491 case 921600: cfsetospeed( &port
, B921600
); break;
494 case 1000000: cfsetospeed( &port
, B1000000
); break;
497 case 1152000: cfsetospeed( &port
, B1152000
); break;
500 case 1500000: cfsetospeed( &port
, B1500000
); break;
503 case 2000000: cfsetospeed( &port
, B2000000
); break;
506 case 2500000: cfsetospeed( &port
, B2500000
); break;
509 case 3000000: cfsetospeed( &port
, B3000000
); break;
512 case 3500000: cfsetospeed( &port
, B3500000
); break;
515 case 4000000: cfsetospeed( &port
, B4000000
); break;
518 #if defined (HAVE_LINUX_SERIAL_H) && defined (TIOCSSERIAL)
520 struct serial_struct nuts
;
523 ioctl(fd
, TIOCGSERIAL
, &nuts
);
524 nuts
.custom_divisor
= nuts
.baud_base
/ sbr
->BaudRate
;
525 if (!(nuts
.custom_divisor
)) nuts
.custom_divisor
= 1;
526 arby
= nuts
.baud_base
/ nuts
.custom_divisor
;
527 nuts
.flags
&= ~ASYNC_SPD_MASK
;
528 nuts
.flags
|= ASYNC_SPD_CUST
;
529 WARN("You (or a program acting at your behest) have specified\n"
530 "a non-standard baud rate %d. Wine will set the rate to %d,\n"
531 "which is as close as we can get by our present understanding of your\n"
532 "hardware. I hope you know what you are doing. Any disruption Wine\n"
533 "has caused to your linux system can be undone with setserial\n"
534 "(see man setserial). If you have incapacitated a Hayes type modem,\n"
535 "reset it and it will probably recover.\n", sbr
->BaudRate
, arby
);
536 ioctl(fd
, TIOCSSERIAL
, &nuts
);
537 cfsetospeed( &port
, B38400
);
540 #else /* Don't have linux/serial.h or lack TIOCSSERIAL */
541 ERR("baudrate %d\n", sbr
->BaudRate
);
542 return STATUS_NOT_SUPPORTED
;
543 #endif /* Don't have linux/serial.h or lack TIOCSSERIAL */
545 cfsetispeed( &port
, cfgetospeed(&port
) );
546 if (tcsetattr(fd
, TCSANOW
, &port
) == -1)
548 ERR("tcsetattr error '%s'\n", strerror(errno
));
549 return FILE_GetNtStatus();
551 return STATUS_SUCCESS
;
554 static int whack_modem(int fd
, unsigned int andy
, unsigned int orrie
)
557 unsigned int mstat
, okay
;
558 okay
= ioctl(fd
, TIOCMGET
, &mstat
);
559 if (okay
) return okay
;
560 if (andy
) mstat
&= andy
;
562 return ioctl(fd
, TIOCMSET
, &mstat
);
568 static NTSTATUS
set_handflow(int fd
, const SERIAL_HANDFLOW
* shf
)
572 if ((shf
->FlowReplace
& (SERIAL_RTS_CONTROL
| SERIAL_RTS_HANDSHAKE
)) ==
573 (SERIAL_RTS_CONTROL
| SERIAL_RTS_HANDSHAKE
))
574 return STATUS_NOT_SUPPORTED
;
576 if (tcgetattr(fd
, &port
) == -1)
578 ERR("tcgetattr error '%s'\n", strerror(errno
));
579 return FILE_GetNtStatus();
583 if ((shf
->ControlHandShake
& SERIAL_CTS_HANDSHAKE
) ||
584 (shf
->FlowReplace
& SERIAL_RTS_HANDSHAKE
))
586 port
.c_cflag
|= CRTSCTS
;
590 port
.c_cflag
&= ~CRTSCTS
;
593 if (shf
->ControlHandShake
& SERIAL_DTR_HANDSHAKE
)
595 WARN("DSR/DTR flow control not supported\n");
596 } else if (!(shf
->ControlHandShake
& SERIAL_DTR_CONTROL
))
597 whack_modem(fd
, ~TIOCM_DTR
, 0);
599 whack_modem(fd
, 0, TIOCM_DTR
);
602 if (!(shf
->ControlHandShake
& SERIAL_CTS_HANDSHAKE
))
604 if ((shf
->FlowReplace
& (SERIAL_RTS_CONTROL
|SERIAL_RTS_HANDSHAKE
)) == 0)
605 whack_modem(fd
, ~TIOCM_RTS
, 0);
607 whack_modem(fd
, 0, TIOCM_RTS
);
611 if (shf
->FlowReplace
& SERIAL_AUTO_RECEIVE
)
612 port
.c_iflag
|= IXOFF
;
614 port
.c_iflag
&= ~IXOFF
;
615 if (shf
->FlowReplace
& SERIAL_AUTO_TRANSMIT
)
616 port
.c_iflag
|= IXON
;
618 port
.c_iflag
&= ~IXON
;
619 if (tcsetattr(fd
, TCSANOW
, &port
) == -1)
621 ERR("tcsetattr error '%s'\n", strerror(errno
));
622 return FILE_GetNtStatus();
625 return STATUS_SUCCESS
;
628 static NTSTATUS
set_line_control(int fd
, const SERIAL_LINE_CONTROL
* slc
)
631 unsigned bytesize
, stopbits
;
633 if (tcgetattr(fd
, &port
) == -1)
635 ERR("tcgetattr error '%s'\n", strerror(errno
));
636 return FILE_GetNtStatus();
640 port
.c_iflag
&= ~(ISTRIP
|BRKINT
|IGNCR
|ICRNL
|INLCR
|PARMRK
|IMAXBEL
);
642 port
.c_iflag
&= ~(ISTRIP
|BRKINT
|IGNCR
|ICRNL
|INLCR
|PARMRK
);
644 port
.c_iflag
|= IGNBRK
| INPCK
;
645 port
.c_oflag
&= ~(OPOST
);
646 port
.c_cflag
&= ~(HUPCL
);
647 port
.c_cflag
|= CLOCAL
| CREAD
;
650 * on FreeBSD, turning off ICANON does not disable IEXTEN,
651 * so we must turn it off explicitly. No harm done on Linux.
653 port
.c_lflag
&= ~(ICANON
|ECHO
|ISIG
|IEXTEN
);
654 port
.c_lflag
|= NOFLSH
;
656 bytesize
= slc
->WordLength
;
657 stopbits
= slc
->StopBits
;
660 port
.c_cflag
&= ~(PARENB
| PARODD
| CMSPAR
);
662 port
.c_cflag
&= ~(PARENB
| PARODD
);
665 /* make sure that reads don't block */
667 port
.c_cc
[VTIME
] = 0;
671 case NOPARITY
: port
.c_iflag
&= ~INPCK
; break;
672 case ODDPARITY
: port
.c_cflag
|= PARENB
| PARODD
; break;
673 case EVENPARITY
: port
.c_cflag
|= PARENB
; break;
675 /* Linux defines mark/space (stick) parity */
676 case MARKPARITY
: port
.c_cflag
|= PARENB
| PARODD
| CMSPAR
; break;
677 case SPACEPARITY
: port
.c_cflag
|= PARENB
| CMSPAR
; break;
679 /* try the POSIX way */
681 if (slc
->StopBits
== ONESTOPBIT
)
683 stopbits
= TWOSTOPBITS
;
684 port
.c_iflag
&= ~INPCK
;
688 FIXME("Cannot set MARK Parity\n");
689 return STATUS_NOT_SUPPORTED
;
693 if (slc
->WordLength
< 8)
696 port
.c_iflag
&= ~INPCK
;
700 FIXME("Cannot set SPACE Parity\n");
701 return STATUS_NOT_SUPPORTED
;
706 FIXME("Parity %d is not supported\n", slc
->Parity
);
707 return STATUS_NOT_SUPPORTED
;
710 port
.c_cflag
&= ~CSIZE
;
713 case 5: port
.c_cflag
|= CS5
; break;
714 case 6: port
.c_cflag
|= CS6
; break;
715 case 7: port
.c_cflag
|= CS7
; break;
716 case 8: port
.c_cflag
|= CS8
; break;
718 FIXME("ByteSize %d is not supported\n", bytesize
);
719 return STATUS_NOT_SUPPORTED
;
724 case ONESTOPBIT
: port
.c_cflag
&= ~CSTOPB
; break;
725 case ONE5STOPBITS
: /* will be selected if bytesize is 5 */
726 case TWOSTOPBITS
: port
.c_cflag
|= CSTOPB
; break;
728 FIXME("StopBits %d is not supported\n", stopbits
);
729 return STATUS_NOT_SUPPORTED
;
731 /* otherwise it hangs with pending input*/
732 if (tcsetattr(fd
, TCSANOW
, &port
) == -1)
734 ERR("tcsetattr error '%s'\n", strerror(errno
));
735 return FILE_GetNtStatus();
737 return STATUS_SUCCESS
;
740 static NTSTATUS
set_queue_size(int fd
, const SERIAL_QUEUE_SIZE
* sqs
)
742 FIXME("insize %d outsize %d unimplemented stub\n", sqs
->InSize
, sqs
->OutSize
);
743 return STATUS_SUCCESS
;
746 static NTSTATUS
set_special_chars(int fd
, const SERIAL_CHARS
* sc
)
750 if (tcgetattr(fd
, &port
) == -1)
752 ERR("tcgetattr error '%s'\n", strerror(errno
));
753 return FILE_GetNtStatus();
756 port
.c_cc
[VEOF
] = sc
->EofChar
;
757 /* FIXME: sc->ErrorChar is not supported */
758 /* FIXME: sc->BreakChar is not supported */
759 /* FIXME: sc->EventChar is not supported */
760 port
.c_cc
[VSTART
] = sc
->XonChar
;
761 port
.c_cc
[VSTOP
] = sc
->XoffChar
;
763 if (tcsetattr(fd
, TCSANOW
, &port
) == -1)
765 ERR("tcsetattr error '%s'\n", strerror(errno
));
766 return FILE_GetNtStatus();
768 return STATUS_SUCCESS
;
772 * does not change IXOFF but simulates that IXOFF has been received:
774 static NTSTATUS
set_XOff(int fd
)
776 if (tcflow(fd
, TCOOFF
))
778 return FILE_GetNtStatus();
780 return STATUS_SUCCESS
;
784 * does not change IXON but simulates that IXON has been received:
786 static NTSTATUS
set_XOn(int fd
)
788 if (tcflow(fd
, TCOON
))
790 return FILE_GetNtStatus();
792 return STATUS_SUCCESS
;
796 * local structure holding the irq values we need for WaitCommEvent()
798 * Stripped down from struct serial_icounter_struct, which may not be available on some systems
799 * As the modem line interrupts (cts, dsr, rng, dcd) only get updated with TIOCMIWAIT active,
800 * no need to carry them in the internal structure
803 typedef struct serial_irq_info
805 int rx
, tx
, frame
, overrun
, parity
, brk
, buf_overrun
, temt
;
808 /***********************************************************************
809 * Data needed by the thread polling for the changing CommEvent
811 typedef struct async_commio
815 IO_STATUS_BLOCK
* iosb
;
821 serial_irq_info irq_info
;
824 /***********************************************************************
825 * Get extended interrupt count info, needed for wait_on
827 static NTSTATUS
get_irq_info(int fd
, serial_irq_info
*irq_info
)
831 #if defined (HAVE_LINUX_SERIAL_H) && defined (TIOCGICOUNT)
832 struct serial_icounter_struct einfo
;
833 if (!ioctl(fd
, TIOCGICOUNT
, &einfo
))
835 irq_info
->rx
= einfo
.rx
;
836 irq_info
->tx
= einfo
.tx
;
837 irq_info
->frame
= einfo
.frame
;
838 irq_info
->overrun
= einfo
.overrun
;
839 irq_info
->parity
= einfo
.parity
;
840 irq_info
->brk
= einfo
.brk
;
841 irq_info
->buf_overrun
= einfo
.buf_overrun
;
845 TRACE("TIOCGICOUNT err %s\n", strerror(errno
));
846 memset(irq_info
,0, sizeof(serial_irq_info
));
849 memset(irq_info
,0, sizeof(serial_irq_info
));
853 /* Generate a single TX_TXEMPTY event when the TX Buffer turns empty*/
854 #ifdef TIOCSERGETLSR /* prefer to log the state TIOCSERGETLSR */
855 if (!ioctl(fd
, TIOCSERGETLSR
, &out
))
857 irq_info
->temt
= (out
& TIOCSER_TEMT
) != 0;
858 return STATUS_SUCCESS
;
861 TRACE("TIOCSERGETLSR err %s\n", strerror(errno
));
863 #ifdef TIOCOUTQ /* otherwise we log when the out queue gets empty */
864 if (!ioctl(fd
, TIOCOUTQ
, &out
))
866 irq_info
->temt
= out
== 0;
867 return STATUS_SUCCESS
;
869 TRACE("TIOCOUTQ err %s\n", strerror(errno
));
870 return FILE_GetNtStatus();
872 return STATUS_SUCCESS
;
876 static DWORD
check_events(int fd
, DWORD mask
,
877 const serial_irq_info
*new,
878 const serial_irq_info
*old
,
879 DWORD new_mstat
, DWORD old_mstat
, DWORD pending_write
)
881 DWORD ret
= 0, queue
;
883 TRACE("mask 0x%08x\n", mask
);
884 TRACE("old->rx 0x%08x vs. new->rx 0x%08x\n", old
->rx
, new->rx
);
885 TRACE("old->tx 0x%08x vs. new->tx 0x%08x\n", old
->tx
, new->tx
);
886 TRACE("old->frame 0x%08x vs. new->frame 0x%08x\n", old
->frame
, new->frame
);
887 TRACE("old->overrun 0x%08x vs. new->overrun 0x%08x\n", old
->overrun
, new->overrun
);
888 TRACE("old->parity 0x%08x vs. new->parity 0x%08x\n", old
->parity
, new->parity
);
889 TRACE("old->brk 0x%08x vs. new->brk 0x%08x\n", old
->brk
, new->brk
);
890 TRACE("old->buf_overrun 0x%08x vs. new->buf_overrun 0x%08x\n", old
->buf_overrun
, new->buf_overrun
);
891 TRACE("old->temt 0x%08x vs. new->temt 0x%08x\n", old
->temt
, new->temt
);
893 if (old
->brk
!= new->brk
) ret
|= EV_BREAK
;
894 if ((old_mstat
& MS_CTS_ON
) != (new_mstat
& MS_CTS_ON
)) ret
|= EV_CTS
;
895 if ((old_mstat
& MS_DSR_ON
) != (new_mstat
& MS_DSR_ON
)) ret
|= EV_DSR
;
896 if ((old_mstat
& MS_RING_ON
) != (new_mstat
& MS_RING_ON
)) ret
|= EV_RING
;
897 if ((old_mstat
& MS_RLSD_ON
) != (new_mstat
& MS_RLSD_ON
)) ret
|= EV_RLSD
;
898 if (old
->frame
!= new->frame
|| old
->overrun
!= new->overrun
|| old
->parity
!= new->parity
) ret
|= EV_ERR
;
899 if (mask
& EV_RXCHAR
)
903 if (ioctl(fd
, TIOCINQ
, &queue
))
904 WARN("TIOCINQ returned error\n");
909 if (mask
& EV_TXEMPTY
)
911 if ((!old
->temt
|| pending_write
) && new->temt
)
917 /***********************************************************************
918 * wait_for_event (INTERNAL)
920 * We need to poll for what is interesting
921 * TIOCMIWAIT only checks modem status line and may not be aborted by a changing mask
924 static DWORD CALLBACK
wait_for_event(LPVOID arg
)
926 async_commio
*commio
= arg
;
929 if (!server_get_unix_fd( commio
->hDevice
, FILE_READ_DATA
| FILE_WRITE_DATA
, &fd
, &needs_close
, NULL
, NULL
))
931 serial_irq_info new_irq_info
;
932 DWORD new_mstat
, dummy
, cookie
;
935 TRACE("device=%p fd=0x%08x mask=0x%08x buffer=%p event=%p irq_info=%p\n",
936 commio
->hDevice
, fd
, commio
->evtmask
, commio
->events
, commio
->hEvent
, &commio
->irq_info
);
938 time
.QuadPart
= (ULONGLONG
)10000;
939 time
.QuadPart
= -time
.QuadPart
;
943 * TIOCMIWAIT is not adequate
946 * We don't handle the EV_RXFLAG (the eventchar)
948 NtDelayExecution(FALSE
, &time
);
949 get_irq_info(fd
, &new_irq_info
);
950 if (get_modem_status(fd
, &new_mstat
))
952 TRACE("get_modem_status failed\n");
956 *commio
->events
= check_events(fd
, commio
->evtmask
,
957 &new_irq_info
, &commio
->irq_info
,
958 new_mstat
, commio
->mstat
, commio
->pending_write
);
959 if (*commio
->events
) break;
960 get_wait_mask(commio
->hDevice
, &dummy
, &cookie
, (commio
->evtmask
& EV_TXEMPTY
) ? &commio
->pending_write
: NULL
, FALSE
);
961 if (commio
->cookie
!= cookie
)
967 if (needs_close
) close( fd
);
973 commio
->iosb
->u
.Status
= STATUS_SUCCESS
;
974 commio
->iosb
->Information
= sizeof(DWORD
);
977 commio
->iosb
->u
.Status
= STATUS_CANCELLED
;
979 stop_waiting(commio
->hDevice
);
980 if (commio
->hEvent
) NtSetEvent(commio
->hEvent
, NULL
);
981 RtlFreeHeap(GetProcessHeap(), 0, commio
);
985 static NTSTATUS
wait_on(HANDLE hDevice
, int fd
, HANDLE hEvent
, PIO_STATUS_BLOCK piosb
, DWORD
* events
)
987 async_commio
* commio
;
990 if ((status
= NtResetEvent(hEvent
, NULL
)))
993 commio
= RtlAllocateHeap(GetProcessHeap(), 0, sizeof (async_commio
));
994 if (!commio
) return STATUS_NO_MEMORY
;
996 commio
->hDevice
= hDevice
;
997 commio
->events
= events
;
998 commio
->iosb
= piosb
;
999 commio
->hEvent
= hEvent
;
1000 commio
->pending_write
= 0;
1001 status
= get_wait_mask(commio
->hDevice
, &commio
->evtmask
, &commio
->cookie
, (commio
->evtmask
& EV_TXEMPTY
) ? &commio
->pending_write
: NULL
, TRUE
);
1004 RtlFreeHeap(GetProcessHeap(), 0, commio
);
1008 /* We may never return, if some capabilities miss
1009 * Return error in that case
1011 #if !defined(TIOCINQ)
1012 if (commio
->evtmask
& EV_RXCHAR
)
1015 #if !(defined(TIOCSERGETLSR) && defined(TIOCSER_TEMT)) || !defined(TIOCINQ)
1016 if (commio
->evtmask
& EV_TXEMPTY
)
1019 #if !defined(TIOCMGET)
1020 if (commio
->evtmask
& (EV_CTS
| EV_DSR
| EV_RING
| EV_RLSD
))
1023 #if !defined(TIOCM_CTS)
1024 if (commio
->evtmask
& EV_CTS
)
1027 #if !defined(TIOCM_DSR)
1028 if (commio
->evtmask
& EV_DSR
)
1031 #if !defined(TIOCM_RNG)
1032 if (commio
->evtmask
& EV_RING
)
1035 #if !defined(TIOCM_CAR)
1036 if (commio
->evtmask
& EV_RLSD
)
1039 if (commio
->evtmask
& EV_RXFLAG
)
1040 FIXME("EV_RXFLAG not handled\n");
1042 if ((status
= get_irq_info(fd
, &commio
->irq_info
)) &&
1043 (commio
->evtmask
& (EV_BREAK
| EV_ERR
)))
1046 if ((status
= get_modem_status(fd
, &commio
->mstat
)) &&
1047 (commio
->evtmask
& (EV_CTS
| EV_DSR
| EV_RING
| EV_RLSD
)))
1050 /* We might have received something or the TX buffer is delivered */
1051 *events
= check_events(fd
, commio
->evtmask
,
1052 &commio
->irq_info
, &commio
->irq_info
,
1053 commio
->mstat
, commio
->mstat
, commio
->pending_write
);
1056 status
= STATUS_SUCCESS
;
1060 /* create the worker for the task */
1061 status
= RtlQueueWorkItem(wait_for_event
, commio
, 0 /* FIXME */);
1062 if (status
!= STATUS_SUCCESS
) goto out_now
;
1063 return STATUS_PENDING
;
1065 #if !defined(TIOCINQ) || (!(defined(TIOCSERGETLSR) && defined(TIOCSER_TEMT)) || !defined(TIOCINQ)) || !defined(TIOCMGET) || !defined(TIOCM_CTS) ||!defined(TIOCM_DSR) || !defined(TIOCM_RNG) || !defined(TIOCM_CAR)
1067 FIXME("Returning error because of missing capabilities\n");
1068 status
= STATUS_INVALID_PARAMETER
;
1071 stop_waiting(commio
->hDevice
);
1072 RtlFreeHeap(GetProcessHeap(), 0, commio
);
1076 static NTSTATUS
xmit_immediate(HANDLE hDevice
, int fd
, const char* ptr
)
1078 /* FIXME: not perfect as it should bypass the in-queue */
1079 WARN("(%p,'%c') not perfect!\n", hDevice
, *ptr
);
1080 if (write(fd
, ptr
, 1) != 1)
1081 return FILE_GetNtStatus();
1082 return STATUS_SUCCESS
;
1085 /******************************************************************
1086 * COMM_DeviceIoControl
1090 static inline NTSTATUS
io_control(HANDLE hDevice
,
1091 HANDLE hEvent
, PIO_APC_ROUTINE UserApcRoutine
,
1092 PVOID UserApcContext
,
1093 PIO_STATUS_BLOCK piosb
,
1094 ULONG dwIoControlCode
,
1095 LPVOID lpInBuffer
, DWORD nInBufferSize
,
1096 LPVOID lpOutBuffer
, DWORD nOutBufferSize
)
1098 DWORD sz
= 0, access
= FILE_READ_DATA
;
1099 NTSTATUS status
= STATUS_SUCCESS
;
1100 int fd
= -1, needs_close
= 0;
1101 enum server_fd_type type
;
1103 TRACE("%p %s %p %d %p %d %p\n",
1104 hDevice
, iocode2str(dwIoControlCode
), lpInBuffer
, nInBufferSize
,
1105 lpOutBuffer
, nOutBufferSize
, piosb
);
1107 switch (dwIoControlCode
)
1109 case IOCTL_SERIAL_GET_TIMEOUTS
:
1110 case IOCTL_SERIAL_SET_TIMEOUTS
:
1111 case IOCTL_SERIAL_GET_WAIT_MASK
:
1112 case IOCTL_SERIAL_SET_WAIT_MASK
:
1113 /* these are handled on the server side */
1114 return STATUS_NOT_SUPPORTED
;
1117 piosb
->Information
= 0;
1119 if ((status
= server_get_unix_fd( hDevice
, access
, &fd
, &needs_close
, &type
, NULL
)))
1121 if (type
!= FD_TYPE_SERIAL
)
1123 if (needs_close
) close( fd
);
1124 status
= STATUS_OBJECT_TYPE_MISMATCH
;
1128 switch (dwIoControlCode
)
1130 case IOCTL_SERIAL_CLR_DTR
:
1132 if (whack_modem(fd
, ~TIOCM_DTR
, 0) == -1) status
= FILE_GetNtStatus();
1134 status
= STATUS_NOT_SUPPORTED
;
1137 case IOCTL_SERIAL_CLR_RTS
:
1139 if (whack_modem(fd
, ~TIOCM_RTS
, 0) == -1) status
= FILE_GetNtStatus();
1141 status
= STATUS_NOT_SUPPORTED
;
1144 case IOCTL_SERIAL_GET_BAUD_RATE
:
1145 if (lpOutBuffer
&& nOutBufferSize
== sizeof(SERIAL_BAUD_RATE
))
1147 if (!(status
= get_baud_rate(fd
, lpOutBuffer
)))
1148 sz
= sizeof(SERIAL_BAUD_RATE
);
1151 status
= STATUS_INVALID_PARAMETER
;
1153 case IOCTL_SERIAL_GET_CHARS
:
1154 if (lpOutBuffer
&& nOutBufferSize
== sizeof(SERIAL_CHARS
))
1156 if (!(status
= get_special_chars(fd
, lpOutBuffer
)))
1157 sz
= sizeof(SERIAL_CHARS
);
1160 status
= STATUS_INVALID_PARAMETER
;
1162 case IOCTL_SERIAL_GET_COMMSTATUS
:
1163 if (lpOutBuffer
&& nOutBufferSize
== sizeof(SERIAL_STATUS
))
1165 if (!(status
= get_status(fd
, lpOutBuffer
)))
1166 sz
= sizeof(SERIAL_STATUS
);
1168 else status
= STATUS_INVALID_PARAMETER
;
1170 case IOCTL_SERIAL_GET_HANDFLOW
:
1171 if (lpOutBuffer
&& nOutBufferSize
== sizeof(SERIAL_HANDFLOW
))
1173 if (!(status
= get_hand_flow(fd
, lpOutBuffer
)))
1174 sz
= sizeof(SERIAL_HANDFLOW
);
1177 status
= STATUS_INVALID_PARAMETER
;
1179 case IOCTL_SERIAL_GET_LINE_CONTROL
:
1180 if (lpOutBuffer
&& nOutBufferSize
== sizeof(SERIAL_LINE_CONTROL
))
1182 if (!(status
= get_line_control(fd
, lpOutBuffer
)))
1183 sz
= sizeof(SERIAL_LINE_CONTROL
);
1186 status
= STATUS_INVALID_PARAMETER
;
1188 case IOCTL_SERIAL_GET_MODEMSTATUS
:
1189 if (lpOutBuffer
&& nOutBufferSize
== sizeof(DWORD
))
1191 if (!(status
= get_modem_status(fd
, lpOutBuffer
)))
1194 else status
= STATUS_INVALID_PARAMETER
;
1196 case IOCTL_SERIAL_IMMEDIATE_CHAR
:
1197 if (lpInBuffer
&& nInBufferSize
== sizeof(CHAR
))
1198 status
= xmit_immediate(hDevice
, fd
, lpInBuffer
);
1200 status
= STATUS_INVALID_PARAMETER
;
1202 case IOCTL_SERIAL_PURGE
:
1203 if (lpInBuffer
&& nInBufferSize
== sizeof(DWORD
))
1204 status
= purge(fd
, *(DWORD
*)lpInBuffer
);
1206 status
= STATUS_INVALID_PARAMETER
;
1208 case IOCTL_SERIAL_RESET_DEVICE
:
1209 FIXME("Unsupported\n");
1211 case IOCTL_SERIAL_SET_BAUD_RATE
:
1212 if (lpInBuffer
&& nInBufferSize
== sizeof(SERIAL_BAUD_RATE
))
1213 status
= set_baud_rate(fd
, lpInBuffer
);
1215 status
= STATUS_INVALID_PARAMETER
;
1217 case IOCTL_SERIAL_SET_BREAK_OFF
:
1218 #if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
1219 if (ioctl(fd
, TIOCCBRK
, 0) == -1)
1221 TRACE("ioctl failed\n");
1222 status
= FILE_GetNtStatus();
1225 FIXME("ioctl not available\n");
1226 status
= STATUS_NOT_SUPPORTED
;
1229 case IOCTL_SERIAL_SET_BREAK_ON
:
1230 #if defined(TIOCSBRK) && defined(TIOCCBRK) /* check if available for compilation */
1231 if (ioctl(fd
, TIOCSBRK
, 0) == -1)
1233 TRACE("ioctl failed\n");
1234 status
= FILE_GetNtStatus();
1237 FIXME("ioctl not available\n");
1238 status
= STATUS_NOT_SUPPORTED
;
1241 case IOCTL_SERIAL_SET_CHARS
:
1242 if (lpInBuffer
&& nInBufferSize
== sizeof(SERIAL_CHARS
))
1243 status
= set_special_chars(fd
, lpInBuffer
);
1245 status
= STATUS_INVALID_PARAMETER
;
1247 case IOCTL_SERIAL_SET_DTR
:
1249 if (whack_modem(fd
, 0, TIOCM_DTR
) == -1) status
= FILE_GetNtStatus();
1251 status
= STATUS_NOT_SUPPORTED
;
1254 case IOCTL_SERIAL_SET_HANDFLOW
:
1255 if (lpInBuffer
&& nInBufferSize
== sizeof(SERIAL_HANDFLOW
))
1256 status
= set_handflow(fd
, lpInBuffer
);
1258 status
= STATUS_INVALID_PARAMETER
;
1260 case IOCTL_SERIAL_SET_LINE_CONTROL
:
1261 if (lpInBuffer
&& nInBufferSize
== sizeof(SERIAL_LINE_CONTROL
))
1262 status
= set_line_control(fd
, lpInBuffer
);
1264 status
= STATUS_INVALID_PARAMETER
;
1266 case IOCTL_SERIAL_SET_QUEUE_SIZE
:
1267 if (lpInBuffer
&& nInBufferSize
== sizeof(SERIAL_QUEUE_SIZE
))
1268 status
= set_queue_size(fd
, lpInBuffer
);
1270 status
= STATUS_INVALID_PARAMETER
;
1272 case IOCTL_SERIAL_SET_RTS
:
1274 if (whack_modem(fd
, 0, TIOCM_RTS
) == -1) status
= FILE_GetNtStatus();
1276 status
= STATUS_NOT_SUPPORTED
;
1279 case IOCTL_SERIAL_SET_XOFF
:
1280 status
= set_XOff(fd
);
1282 case IOCTL_SERIAL_SET_XON
:
1283 status
= set_XOn(fd
);
1285 case IOCTL_SERIAL_WAIT_ON_MASK
:
1286 if (lpOutBuffer
&& nOutBufferSize
== sizeof(DWORD
))
1288 if (!(status
= wait_on(hDevice
, fd
, hEvent
, piosb
, lpOutBuffer
)))
1292 status
= STATUS_INVALID_PARAMETER
;
1295 FIXME("Unsupported IOCTL %x (type=%x access=%x func=%x meth=%x)\n",
1296 dwIoControlCode
, dwIoControlCode
>> 16, (dwIoControlCode
>> 14) & 3,
1297 (dwIoControlCode
>> 2) & 0xFFF, dwIoControlCode
& 3);
1299 status
= STATUS_INVALID_PARAMETER
;
1302 if (needs_close
) close( fd
);
1304 piosb
->u
.Status
= status
;
1305 piosb
->Information
= sz
;
1306 if (hEvent
&& status
!= STATUS_PENDING
) NtSetEvent(hEvent
, NULL
);
1310 NTSTATUS
COMM_DeviceIoControl(HANDLE hDevice
,
1311 HANDLE hEvent
, PIO_APC_ROUTINE UserApcRoutine
,
1312 PVOID UserApcContext
,
1313 PIO_STATUS_BLOCK piosb
,
1314 ULONG dwIoControlCode
,
1315 LPVOID lpInBuffer
, DWORD nInBufferSize
,
1316 LPVOID lpOutBuffer
, DWORD nOutBufferSize
)
1320 if (dwIoControlCode
== IOCTL_SERIAL_WAIT_ON_MASK
)
1322 HANDLE hev
= hEvent
;
1324 /* this is an ioctl we implement in a non blocking way if hEvent is not
1326 * so we have to explicitly wait if no hEvent is provided
1330 OBJECT_ATTRIBUTES attr
;
1332 attr
.Length
= sizeof(attr
);
1333 attr
.RootDirectory
= 0;
1334 attr
.ObjectName
= NULL
;
1335 attr
.Attributes
= OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
;
1336 attr
.SecurityDescriptor
= NULL
;
1337 attr
.SecurityQualityOfService
= NULL
;
1338 status
= NtCreateEvent(&hev
, EVENT_ALL_ACCESS
, &attr
, SynchronizationEvent
, FALSE
);
1340 if (status
) return status
;
1342 status
= io_control(hDevice
, hev
, UserApcRoutine
, UserApcContext
,
1343 piosb
, dwIoControlCode
, lpInBuffer
, nInBufferSize
,
1344 lpOutBuffer
, nOutBufferSize
);
1347 if (status
== STATUS_PENDING
)
1349 NtWaitForSingleObject(hev
, FALSE
, NULL
);
1350 status
= STATUS_SUCCESS
;
1355 else status
= io_control(hDevice
, hEvent
, UserApcRoutine
, UserApcContext
,
1356 piosb
, dwIoControlCode
, lpInBuffer
, nInBufferSize
,
1357 lpOutBuffer
, nOutBufferSize
);
1361 NTSTATUS
COMM_FlushBuffersFile( int fd
)
1364 while (tcdrain( fd
) == -1)
1366 if (errno
!= EINTR
) return FILE_GetNtStatus();
1368 return STATUS_SUCCESS
;
1369 #elif defined(TIOCDRAIN)
1370 while (ioctl( fd
, TIOCDRAIN
) == -1)
1372 if (errno
!= EINTR
) return FILE_GetNtStatus();
1374 return STATUS_SUCCESS
;
1375 #elif defined(TCSBRK)
1376 while (ioctl( fd
, TCSBRK
, 1 ) == -1)
1378 if (errno
!= EINTR
) return FILE_GetNtStatus();
1380 return STATUS_SUCCESS
;
1382 ERR( "not supported\n" );
1383 return STATUS_NOT_IMPLEMENTED
;