4 This file is part of Cygwin.
6 This software is a copyrighted work licensed under the terms of the
7 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
12 #include <sys/param.h>
19 #include <asm/socket.h>
24 /**********************************************************************/
27 fhandler_serial::fhandler_serial ()
28 : fhandler_base (), vmin_ (0), vtime_ (0), pgrp_ (myself
->pgid
)
30 need_fork_fixup (true);
34 fhandler_serial::raw_read (void *ptr
, size_t& ulen
)
36 OVERLAPPED ov
= { 0 };
39 DWORD bytes_to_read
, read_bytes
;
47 /* If MIN > 0 in blocking mode, we have to read at least VMIN chars,
48 otherwise we're in polling mode and there's no minimum chars. */
49 ssize_t minchars
= (!is_nonblocking () && vmin_
) ? MIN (vmin_
, ulen
) : 0;
51 debug_printf ("ulen %ld, vmin_ %u, vtime_ %u", ulen
, vmin_
, vtime_
);
53 ov
.hEvent
= CreateEvent (&sec_none_nih
, TRUE
, FALSE
, NULL
);
57 /* First check if chars are already in the inbound queue. */
58 if (!ClearCommError (get_handle (), &io_err
, &st
))
60 /* FIXME: In case of I/O error, do we really want to bail out or is it
61 better just trying to pull through? */
64 termios_printf ("error detected %x", io_err
);
65 SetLastError (ERROR_IO_DEVICE
);
68 /* ReadFile only handles up to DWORD bytes. */
69 bytes_to_read
= MIN (ulen
, UINT32_MAX
);
70 if (is_nonblocking ())
72 /* In O_NONBLOCK mode we just care for the number of chars already
73 in the inbound queue. */
76 bytes_to_read
= MIN (st
.cbInQue
, bytes_to_read
);
80 /* If the number of chars in the inbound queue is sufficent
81 (minchars defines the minimum), set bytes_to_read accordingly
83 if (st
.cbInQue
&& (ssize_t
) st
.cbInQue
>= minchars
)
84 bytes_to_read
= MIN (st
.cbInQue
, bytes_to_read
);
87 ResetEvent (ov
.hEvent
);
88 if (!ReadFile (get_handle (), ptr
, bytes_to_read
, &read_bytes
, &ov
))
90 if (GetLastError () != ERROR_IO_PENDING
)
92 if (is_nonblocking ())
94 CancelIo (get_handle ());
95 if (!GetOverlappedResult (get_handle (), &ov
, &read_bytes
,
101 switch (cygwait (ov
.hEvent
))
103 default: /* Handle an error case from cygwait basically like
104 a cancel condition and see if we got "something" */
105 CancelIo (get_handle ());
108 if (!GetOverlappedResult (get_handle (), &ov
, &read_bytes
,
111 debug_printf ("got %u bytes from ReadFile", read_bytes
);
114 CancelIo (get_handle ());
115 if (!GetOverlappedResult (get_handle (), &ov
, &read_bytes
,
118 /* Only if no bytes read, return with EINTR. */
119 if (!tot
&& !read_bytes
)
122 set_sig_errno (EINTR
);
123 debug_printf ("signal received, set EINTR");
126 debug_printf ("signal received but ignored");
129 CancelIo (get_handle ());
130 GetOverlappedResult (get_handle (), &ov
, &read_bytes
, TRUE
);
131 debug_printf ("thread canceled");
132 pthread::static_cancel_self ();
138 ptr
= (void *) ((caddr_t
) ptr
+ read_bytes
);
140 minchars
-= read_bytes
;
141 debug_printf ("vtime_ %u, vmin_ %u, read_bytes %u, tot %D",
142 vtime_
, vmin_
, read_bytes
, tot
);
146 debug_printf ("err %E");
147 if (GetLastError () != ERROR_OPERATION_ABORTED
)
157 /* ALL of these are required to loop:
159 Still room in user space buffer
160 AND still a minchars requirement (implies blocking mode)
161 AND vtime_ is not set. */
162 while (ulen
> 0 && minchars
> 0 && vtime_
== 0);
165 CloseHandle (ov
.hEvent
);
167 if (is_nonblocking () && ulen
== 0)
174 /* Cover function to WriteFile to provide Posix interface and semantics
175 (as much as possible). */
177 fhandler_serial::raw_write (const void *ptr
, size_t len
)
180 OVERLAPPED write_status
;
182 memset (&write_status
, 0, sizeof (write_status
));
183 write_status
.hEvent
= CreateEvent (&sec_none_nih
, TRUE
, FALSE
, NULL
);
184 ProtectHandle (write_status
.hEvent
);
188 if (WriteFile (get_handle (), ptr
, len
, &bytes_written
, &write_status
))
191 switch (GetLastError ())
193 case ERROR_OPERATION_ABORTED
:
195 if (!ClearCommError (get_handle (), &ev
, NULL
))
198 termios_printf ("error detected %x", ev
);
200 case ERROR_IO_PENDING
:
206 if (!is_nonblocking ())
208 switch (cygwait (write_status
.hEvent
))
213 PurgeComm (get_handle (), PURGE_TXABORT
);
214 set_sig_errno (EINTR
);
215 ForceCloseHandle (write_status
.hEvent
);
218 PurgeComm (get_handle (), PURGE_TXABORT
);
219 pthread::static_cancel_self ();
225 if (!GetOverlappedResult (get_handle (), &write_status
, &bytes_written
, TRUE
))
231 ForceCloseHandle (write_status
.hEvent
);
233 return bytes_written
;
237 ForceCloseHandle (write_status
.hEvent
);
242 fhandler_serial::init (HANDLE f
, DWORD flags
, mode_t bin
)
244 return open (flags
, bin
& (O_BINARY
| O_TEXT
));
248 fhandler_serial::open (int flags
, mode_t mode
)
253 syscall_printf ("fhandler_serial::open (%s, %y, 0%o)",
254 get_name (), flags
, mode
);
256 if (!fhandler_base::open (flags
, mode
))
261 SetCommMask (get_handle (), EV_RXCHAR
);
263 memset (&to
, 0, sizeof (to
));
264 SetCommTimeouts (get_handle (), &to
);
266 /* Reset serial port to known state of 9600-8-1-no flow control
267 on open for better behavior under Win 95.
269 FIXME: This should only be done when explicitly opening the com
270 port. It should not be reset if an fd is inherited.
271 Using __progname in this way, to determine how far along in the
272 initialization we are, is really a terrible kludge and should
275 if (reset_com
&& __progname
)
278 GetCommState (get_handle (), &state
);
279 syscall_printf ("setting initial state on %s (reset_com %d)",
280 get_name (), reset_com
);
281 state
.BaudRate
= CBR_9600
;
283 state
.StopBits
= ONESTOPBIT
;
284 state
.Parity
= NOPARITY
; /* FIXME: correct default? */
285 state
.fBinary
= TRUE
; /* binary xfer */
286 state
.EofChar
= 0; /* no end-of-data in binary mode */
287 state
.fNull
= FALSE
; /* don't discard nulls in binary mode */
288 state
.fParity
= FALSE
; /* ignore parity errors */
289 state
.fErrorChar
= FALSE
;
290 state
.fTXContinueOnXoff
= TRUE
; /* separate TX and RX flow control */
291 state
.fOutX
= FALSE
; /* disable transmission flow control */
292 state
.fInX
= FALSE
; /* disable reception flow control */
293 state
.XonChar
= 0x11;
294 state
.XoffChar
= 0x13;
295 state
.fOutxDsrFlow
= FALSE
; /* disable DSR flow control */
296 state
.fRtsControl
= RTS_CONTROL_ENABLE
; /* ignore lead control except
298 state
.fOutxCtsFlow
= FALSE
; /* disable output flow control */
299 state
.fDtrControl
= DTR_CONTROL_ENABLE
; /* assert DTR */
300 state
.fDsrSensitivity
= FALSE
; /* don't assert DSR */
301 state
.fAbortOnError
= TRUE
;
302 if (!SetCommState (get_handle (), &state
))
303 system_printf ("couldn't set initial state for %s, %E", get_name ());
306 SetCommMask (get_handle (), EV_RXCHAR
);
308 syscall_printf ("%p = fhandler_serial::open (%s, %y, 0%o)",
309 res
, get_name (), flags
, mode
);
313 /* tcsendbreak: POSIX 7.2.2.1 */
314 /* Break for 250-500 milliseconds if duration == 0 */
315 /* Otherwise, units for duration are undefined */
317 fhandler_serial::tcsendbreak (int duration
)
319 unsigned int sleeptime
= 300000;
322 sleeptime
*= duration
;
324 if (SetCommBreak (get_handle ()) == 0)
327 /* FIXME: need to send zero bits during duration */
330 if (ClearCommBreak (get_handle ()) == 0)
333 syscall_printf ("0 = fhandler_serial:tcsendbreak (%d)", duration
);
338 /* tcdrain: POSIX 7.2.2.1 */
340 fhandler_serial::tcdrain ()
342 if (FlushFileBuffers (get_handle ()) == 0)
348 /* tcflow: POSIX 7.2.2.1 */
350 fhandler_serial::tcflow (int action
)
352 DWORD win32action
= 0;
356 termios_printf ("action %d", action
);
361 win32action
= SETXOFF
;
364 win32action
= SETXON
;
368 if (GetCommState (get_handle (), &dcb
) == 0)
371 xchar
= (dcb
.XonChar
? dcb
.XonChar
: 0x11);
373 xchar
= (dcb
.XoffChar
? dcb
.XoffChar
: 0x13);
374 if (TransmitCommChar (get_handle (), xchar
) == 0)
383 if (EscapeCommFunction (get_handle (), win32action
) == 0)
390 /* switch_modem_lines: set or clear RTS and/or DTR */
392 fhandler_serial::switch_modem_lines (int set
, int clr
)
394 if ((set
& (TIOCM_RTS
| TIOCM_DTR
)) || (clr
& (TIOCM_RTS
| TIOCM_DTR
)))
398 memset(&dcb
,0,sizeof(dcb
));
399 dcb
.DCBlength
= sizeof(dcb
);
401 if (!GetCommState(get_handle(), &dcb
))
408 dcb
.fRtsControl
= RTS_CONTROL_ENABLE
;
411 dcb
.fRtsControl
= RTS_CONTROL_DISABLE
;
414 dcb
.fDtrControl
= DTR_CONTROL_ENABLE
;
417 dcb
.fDtrControl
= DTR_CONTROL_DISABLE
;
419 if (!SetCommState(get_handle(), &dcb
))
431 fhandler_serial::ioctl (unsigned int cmd
, void *buf
)
435 # define ibuf ((int) (intptr_t) buf)
436 # define ipbuf (*(int *) buf)
440 if (!ClearCommError (get_handle (), &ev
, &st
))
449 res
= tcflush (ibuf
);
453 if (!GetCommModemStatus (get_handle (), &modem_lines
))
461 if (modem_lines
& MS_CTS_ON
)
463 if (modem_lines
& MS_DSR_ON
)
465 if (modem_lines
& MS_RING_ON
)
467 if (modem_lines
& MS_RLSD_ON
)
472 if (!DeviceIoControl (get_handle (), IOCTL_SERIAL_GET_DTRRTS
,
473 NULL
, 0, &mcr
, 4, &cb
, 0) || cb
!= 4)
485 if (switch_modem_lines (ipbuf
, ~ipbuf
))
489 if (switch_modem_lines (ipbuf
, 0))
493 if (switch_modem_lines (0, ipbuf
))
497 if (ClearCommBreak (get_handle ()) == 0)
504 if (SetCommBreak (get_handle ()) == 0)
514 ((struct winsize
*) buf
)->ws_row
= 0;
515 ((struct winsize
*) buf
)->ws_col
= 0;
522 res
= fhandler_base::ioctl (cmd
, buf
);
526 termios_printf ("%d = ioctl(%x, %p)", res
, cmd
, buf
);
532 /* tcflush: POSIX 7.2.2.1 */
534 fhandler_serial::tcflush (int queue
)
541 flags
= PURGE_TXABORT
| PURGE_TXCLEAR
;
544 flags
= PURGE_RXABORT
| PURGE_RXCLEAR
;
547 flags
= PURGE_TXABORT
| PURGE_TXCLEAR
| PURGE_RXABORT
| PURGE_RXCLEAR
;
550 termios_printf ("Invalid tcflush queue %d", queue
);
555 if (!PurgeComm (get_handle (), flags
))
564 /* tcsetattr: POSIX 7.2.1.1 */
566 fhandler_serial::tcsetattr (int action
, const struct termios
*t
)
569 TCSANOW: immediately change attributes.
570 TCSADRAIN: flush output, then change attributes.
571 TCSAFLUSH: flush output and discard input, then change attributes.
574 bool dropDTR
= false;
577 int tmpDtr
, tmpRts
, res
;
578 res
= tmpDtr
= tmpRts
= 0;
580 termios_printf ("action %d", action
);
581 if ((action
== TCSADRAIN
) || (action
== TCSAFLUSH
))
583 FlushFileBuffers (get_handle ());
584 termios_printf ("flushed file buffers");
586 if (action
== TCSAFLUSH
)
587 PurgeComm (get_handle (), (PURGE_RXABORT
| PURGE_RXCLEAR
));
589 /* get default/last comm state */
590 if (!GetCommState (get_handle (), &ostate
))
595 /* -------------- Set baud rate ------------------ */
596 /* FIXME: WIN32 also has 14400, 56000, 128000, and 256000.
597 Unix also has 230400. */
602 /* Drop DTR - but leave DCB-resident bitrate as-is since
603 0 is an invalid bitrate in Win32 */
607 state
.BaudRate
= CBR_110
;
610 state
.BaudRate
= CBR_300
;
613 state
.BaudRate
= CBR_600
;
616 state
.BaudRate
= CBR_1200
;
619 state
.BaudRate
= CBR_2400
;
622 state
.BaudRate
= CBR_4800
;
625 state
.BaudRate
= CBR_9600
;
628 state
.BaudRate
= CBR_19200
;
631 state
.BaudRate
= CBR_38400
;
634 state
.BaudRate
= CBR_57600
;
637 state
.BaudRate
= CBR_115200
;
640 state
.BaudRate
= CBR_128000
;
643 state
.BaudRate
= 230400 /* CBR_230400 - not defined */;
646 state
.BaudRate
= CBR_256000
;
649 state
.BaudRate
= 460800 /* CBR_460800 - not defined */;
652 state
.BaudRate
= 500000 /* CBR_500000 - not defined */;
655 state
.BaudRate
= 576000 /* CBR_576000 - not defined */;
658 state
.BaudRate
= 921600 /* CBR_921600 - not defined */;
661 state
.BaudRate
= 1000000 /* CBR_1000000 - not defined */;
664 state
.BaudRate
= 1152000 /* CBR_1152000 - not defined */;
667 state
.BaudRate
= 1500000 /* CBR_1500000 - not defined */;
670 state
.BaudRate
= 2000000 /* CBR_2000000 - not defined */;
673 state
.BaudRate
= 2500000 /* CBR_2500000 - not defined */;
676 state
.BaudRate
= 3000000 /* CBR_3000000 - not defined */;
679 /* Unsupported baud rate! */
680 termios_printf ("Invalid t->c_ospeed %u", t
->c_ospeed
);
685 /* -------------- Set byte size ------------------ */
687 switch (t
->c_cflag
& CSIZE
)
702 /* Unsupported byte size! */
703 termios_printf ("Invalid t->c_cflag byte size %u",
709 /* -------------- Set stop bits ------------------ */
711 if (t
->c_cflag
& CSTOPB
)
712 state
.StopBits
= TWOSTOPBITS
;
714 state
.StopBits
= ONESTOPBIT
;
716 /* -------------- Set parity ------------------ */
718 if (t
->c_cflag
& PARENB
)
720 if(t
->c_cflag
& CMSPAR
)
721 state
.Parity
= (t
->c_cflag
& PARODD
) ? MARKPARITY
: SPACEPARITY
;
723 state
.Parity
= (t
->c_cflag
& PARODD
) ? ODDPARITY
: EVENPARITY
;
726 state
.Parity
= NOPARITY
;
728 state
.fBinary
= TRUE
; /* Binary transfer */
729 state
.EofChar
= 0; /* No end-of-data in binary mode */
730 state
.fNull
= FALSE
; /* Don't discard nulls in binary mode */
732 /* -------------- Parity errors ------------------ */
733 /* fParity combines the function of INPCK and NOT IGNPAR */
735 if ((t
->c_iflag
& INPCK
) && !(t
->c_iflag
& IGNPAR
))
736 state
.fParity
= TRUE
; /* detect parity errors */
738 state
.fParity
= FALSE
; /* ignore parity errors */
740 /* Only present in Win32, Unix has no equivalent */
741 state
.fErrorChar
= FALSE
;
744 /* -------------- Set software flow control ------------------ */
745 /* Set fTXContinueOnXoff to FALSE. This prevents the triggering of a
746 premature XON when the remote device interprets a received character
747 as XON (same as IXANY on the remote side). Otherwise, a TRUE
748 value separates the TX and RX functions. */
750 state
.fTXContinueOnXoff
= TRUE
; /* separate TX and RX flow control */
752 /* Transmission flow control */
753 if (t
->c_iflag
& IXON
)
754 state
.fOutX
= TRUE
; /* enable */
756 state
.fOutX
= FALSE
; /* disable */
758 /* Reception flow control */
759 if (t
->c_iflag
& IXOFF
)
760 state
.fInX
= TRUE
; /* enable */
762 state
.fInX
= FALSE
; /* disable */
764 /* XoffLim and XonLim are left at default values */
766 state
.XonChar
= (t
->c_cc
[VSTART
] ? t
->c_cc
[VSTART
] : 0x11);
767 state
.XoffChar
= (t
->c_cc
[VSTOP
] ? t
->c_cc
[VSTOP
] : 0x13);
769 /* -------------- Set hardware flow control ------------------ */
771 /* Disable DSR flow control */
772 state
.fOutxDsrFlow
= FALSE
;
774 /* Some old flavors of Unix automatically enabled hardware flow
775 control when software flow control was not enabled. Since newer
776 Unices tend to require explicit setting of hardware flow-control,
777 this is what we do. */
779 /* RTS/CTS flow control */
780 if (t
->c_cflag
& CRTSCTS
)
782 state
.fOutxCtsFlow
= TRUE
;
783 state
.fRtsControl
= RTS_CONTROL_HANDSHAKE
;
787 state
.fRtsControl
= RTS_CONTROL_ENABLE
;
788 state
.fOutxCtsFlow
= FALSE
;
792 if (t
->c_cflag
& CRTSXOFF
)
793 state
.fRtsControl
= RTS_CONTROL_HANDSHAKE
;
795 /* -------------- DTR ------------------ */
796 /* Assert DTR on device open */
798 state
.fDtrControl
= DTR_CONTROL_ENABLE
;
800 /* -------------- DSR ------------------ */
801 /* Assert DSR at the device? */
803 if (t
->c_cflag
& CLOCAL
)
804 state
.fDsrSensitivity
= FALSE
; /* no */
806 state
.fDsrSensitivity
= TRUE
; /* yes */
808 /* -------------- Error handling ------------------ */
809 /* Since read/write operations terminate upon error, we
810 will use ClearCommError() to resume. */
812 state
.fAbortOnError
= TRUE
;
814 if ((memcmp (&ostate
, &state
, sizeof (state
)) != 0)
815 && !SetCommState (get_handle (), &state
))
817 /* SetCommState() failed, usually due to invalid DCB param.
818 Keep track of this so we can set errno to EINVAL later
819 and return failure */
820 termios_printf ("SetCommState() failed, %E");
825 rbinary ((t
->c_iflag
& IGNCR
) ? false : true);
826 wbinary ((t
->c_oflag
& ONLCR
) ? false : true);
830 EscapeCommFunction (get_handle (), CLRDTR
);
835 /* FIXME: Sometimes when CLRDTR is set, setting
836 state.fDtrControl = DTR_CONTROL_ENABLE will fail. This
837 is a problem since a program might want to change some
838 parameters while DTR is still down. */
840 EscapeCommFunction (get_handle (), SETDTR
);
847 /* The following documentation on was taken from "Linux Serial Programming
848 HOWTO". It explains how MIN (t->c_cc[VMIN] || vmin_) and TIME
849 (t->c_cc[VTIME] || vtime_) is to be used.
851 In non-canonical input processing mode, input is not assembled into
852 lines and input processing (erase, kill, delete, etc.) does not
853 occur. Two parameters control the behavior of this mode: c_cc[VTIME]
854 sets the character timer, and c_cc[VMIN] sets the minimum number of
855 characters to receive before satisfying the read.
857 If MIN > 0 and TIME = 0, MIN sets the number of characters to receive
858 before the read is satisfied. As TIME is zero, the timer is not used.
860 If MIN = 0 and TIME > 0, TIME serves as a timeout value. The read will
861 be satisfied if a single character is read, or TIME is exceeded (t =
862 TIME *0.1 s). If TIME is exceeded, no character will be returned.
864 If MIN > 0 and TIME > 0, TIME serves as an inter-character timer. The
865 read will be satisfied if MIN characters are received, or the time
866 between two characters exceeds TIME. The timer is restarted every time
867 a character is received and only becomes active after the first
868 character has been received.
870 If MIN = 0 and TIME = 0, read will be satisfied immediately. The
871 number of characters currently available, or the number of characters
872 requested will be returned. According to Antonino (see contributions),
873 you could issue a fcntl(fd, F_SETFL, FNDELAY); before reading to get
877 if (t
->c_lflag
& ICANON
)
884 vtime_
= t
->c_cc
[VTIME
];
885 vmin_
= t
->c_cc
[VMIN
];
888 debug_printf ("vtime %u, vmin %u", vtime_
, vmin_
);
890 memset (&to
, 0, sizeof (to
));
892 if ((vmin_
> 0) && (vtime_
== 0))
894 /* Returns immediately with whatever is in buffer on a ReadFile();
895 or blocks if nothing found. We will keep calling ReadFile(); until
896 vmin_ characters are read */
897 to
.ReadIntervalTimeout
= to
.ReadTotalTimeoutMultiplier
= MAXDWORD
;
898 to
.ReadTotalTimeoutConstant
= MAXDWORD
- 1;
900 else if ((vmin_
== 0) && (vtime_
> 0))
902 /* set timeoout constant appropriately and we will only try to
903 read one character in ReadFile() */
904 to
.ReadTotalTimeoutConstant
= vtime_
* 100;
905 to
.ReadIntervalTimeout
= to
.ReadTotalTimeoutMultiplier
= MAXDWORD
;
907 else if ((vmin_
> 0) && (vtime_
> 0))
909 /* time applies to the interval time for this case */
910 to
.ReadIntervalTimeout
= vtime_
* 100;
912 else if ((vmin_
== 0) && (vtime_
== 0))
914 /* returns immediately with whatever is in buffer as per
915 Time-Outs docs in Win32 SDK API docs */
916 to
.ReadIntervalTimeout
= MAXDWORD
;
919 debug_printf ("ReadTotalTimeoutConstant %u, ReadIntervalTimeout %u, "
920 "ReadTotalTimeoutMultiplier %u", to
.ReadTotalTimeoutConstant
,
921 to
.ReadIntervalTimeout
, to
.ReadTotalTimeoutMultiplier
);
923 if (!SetCommTimeouts(get_handle (), &to
))
925 /* SetCommTimeouts() failed. Keep track of this so we
926 can set errno to EINVAL later and return failure */
927 termios_printf ("SetCommTimeouts() failed, %E");
935 /* tcgetattr: POSIX 7.2.1.1 */
937 fhandler_serial::tcgetattr (struct termios
*t
)
941 /* Get current Win32 comm state */
942 if (GetCommState (get_handle (), &state
) == 0)
946 memset (t
, 0, sizeof (*t
));
949 /* -------------- Baud rate ------------------ */
950 switch (state
.BaudRate
)
953 t
->c_ospeed
= t
->c_ispeed
= B110
;
956 t
->c_ospeed
= t
->c_ispeed
= B300
;
959 t
->c_ospeed
= t
->c_ispeed
= B600
;
962 t
->c_ospeed
= t
->c_ispeed
= B1200
;
965 t
->c_ospeed
= t
->c_ispeed
= B2400
;
968 t
->c_ospeed
= t
->c_ispeed
= B4800
;
971 t
->c_ospeed
= t
->c_ispeed
= B9600
;
974 t
->c_ospeed
= t
->c_ispeed
= B19200
;
977 t
->c_ospeed
= t
->c_ispeed
= B38400
;
980 t
->c_ospeed
= t
->c_ispeed
= B57600
;
983 t
->c_ospeed
= t
->c_ispeed
= B115200
;
986 t
->c_ospeed
= t
->c_ispeed
= B128000
;
988 case 230400: /* CBR_230400 - not defined */
989 t
->c_ospeed
= t
->c_ispeed
= B230400
;
992 t
->c_ospeed
= t
->c_ispeed
= B256000
;
994 case 460800: /* CBR_460000 - not defined */
995 t
->c_ospeed
= t
->c_ispeed
= B460800
;
997 case 500000: /* CBR_500000 - not defined */
998 t
->c_ospeed
= t
->c_ispeed
= B500000
;
1000 case 576000: /* CBR_576000 - not defined */
1001 t
->c_ospeed
= t
->c_ispeed
= B576000
;
1003 case 921600: /* CBR_921600 - not defined */
1004 t
->c_ospeed
= t
->c_ispeed
= B921600
;
1006 case 1000000: /* CBR_1000000 - not defined */
1007 t
->c_ospeed
= t
->c_ispeed
= B1000000
;
1009 case 1152000: /* CBR_1152000 - not defined */
1010 t
->c_ospeed
= t
->c_ispeed
= B1152000
;
1012 case 1500000: /* CBR_1500000 - not defined */
1013 t
->c_ospeed
= t
->c_ispeed
= B1500000
;
1015 case 2000000: /* CBR_2000000 - not defined */
1016 t
->c_ospeed
= t
->c_ispeed
= B2000000
;
1018 case 2500000: /* CBR_2500000 - not defined */
1019 t
->c_ospeed
= t
->c_ispeed
= B2500000
;
1021 case 3000000: /* CBR_3000000 - not defined */
1022 t
->c_ospeed
= t
->c_ispeed
= B3000000
;
1025 /* Unsupported baud rate! */
1026 termios_printf ("Invalid baud rate %u", state
.BaudRate
);
1031 /* -------------- Byte size ------------------ */
1033 switch (state
.ByteSize
)
1048 /* Unsupported byte size! */
1049 termios_printf ("Invalid byte size %u", state
.ByteSize
);
1054 /* -------------- Stop bits ------------------ */
1056 if (state
.StopBits
== TWOSTOPBITS
)
1057 t
->c_cflag
|= CSTOPB
;
1059 /* -------------- Parity ------------------ */
1061 if (state
.Parity
== ODDPARITY
)
1062 t
->c_cflag
|= (PARENB
| PARODD
);
1063 if (state
.Parity
== EVENPARITY
)
1064 t
->c_cflag
|= PARENB
;
1065 if (state
.Parity
== MARKPARITY
)
1066 t
->c_cflag
|= (PARENB
| PARODD
| CMSPAR
);
1067 if (state
.Parity
== SPACEPARITY
)
1068 t
->c_cflag
|= (PARENB
| CMSPAR
);
1070 /* -------------- Parity errors ------------------ */
1072 /* fParity combines the function of INPCK and NOT IGNPAR */
1074 t
->c_iflag
|= INPCK
;
1076 t
->c_iflag
|= IGNPAR
; /* not necessarily! */
1078 /* -------------- Software flow control ------------------ */
1080 /* transmission flow control */
1084 /* reception flow control */
1086 t
->c_iflag
|= IXOFF
;
1088 t
->c_cc
[VSTART
] = (state
.XonChar
? state
.XonChar
: 0x11);
1089 t
->c_cc
[VSTOP
] = (state
.XoffChar
? state
.XoffChar
: 0x13);
1091 /* -------------- Hardware flow control ------------------ */
1092 /* Some old flavors of Unix automatically enabled hardware flow
1093 control when software flow control was not enabled. Since newer
1094 Unices tend to require explicit setting of hardware flow-control,
1095 this is what we do. */
1097 /* Input flow-control */
1098 if ((state
.fRtsControl
== RTS_CONTROL_HANDSHAKE
) && state
.fOutxCtsFlow
)
1099 t
->c_cflag
|= CRTSCTS
;
1100 if (state
.fRtsControl
== RTS_CONTROL_HANDSHAKE
)
1101 t
->c_cflag
|= CRTSXOFF
;
1103 /* -------------- CLOCAL --------------- */
1104 /* DSR is only lead toggled only by CLOCAL. Check it to see if
1105 CLOCAL was called. */
1106 /* FIXME: If tcsetattr() hasn't been called previously, this may
1107 give a false CLOCAL. */
1109 if (!state
.fDsrSensitivity
)
1110 t
->c_cflag
|= CLOCAL
;
1112 /* FIXME: need to handle IGNCR */
1115 t
->c_iflag
|= IGNCR
;
1119 t
->c_oflag
|= ONLCR
;
1121 t
->c_cc
[VTIME
] = vtime_
;
1122 t
->c_cc
[VMIN
] = vmin_
;
1124 debug_printf ("vmin_ %u, vtime_ %u", vmin_
, vtime_
);