1/* $OpenBSD: termios.h,v 1.14 2022/12/30 23:41:45 millert Exp $ */
2/* $NetBSD: termios.h,v 1.14 1996/04/09 20:55:41 cgd Exp $ */
3
4/*
5 * Copyright (c) 1988, 1989, 1993, 1994
6 * The Regents of the University of California. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * @(#)termios.h 8.3 (Berkeley) 3/28/94
33 */
34
35#ifndef _SYS_TERMIOS_H_
36#define _SYS_TERMIOS_H_
37
38#include <sys/cdefs.h>
39
40/*
41 * Special Control Characters
42 *
43 * Index into c_cc[] character array.
44 *
45 * Name Subscript Enabled by
46 */
47#define VEOF 0 /* ICANON */
48#define VEOL 1 /* ICANON */
49#if __BSD_VISIBLE
50#define VEOL2 2 /* ICANON */
51#endif
52#define VERASE 3 /* ICANON */
53#if __BSD_VISIBLE
54#define VWERASE 4 /* ICANON */
55#endif
56#define VKILL 5 /* ICANON */
57#if __BSD_VISIBLE
58#define VREPRINT 6 /* ICANON */
59#endif
60/* 7 spare 1 */
61#define VINTR 8 /* ISIG */
62#define VQUIT 9 /* ISIG */
63#define VSUSP 10 /* ISIG */
64#if __BSD_VISIBLE
65#define VDSUSP 11 /* ISIG */
66#endif
67#define VSTART 12 /* IXON, IXOFF */
68#define VSTOP 13 /* IXON, IXOFF */
69#if __BSD_VISIBLE
70#define VLNEXT 14 /* IEXTEN */
71#define VDISCARD 15 /* IEXTEN */
72#endif
73#define VMIN 16 /* !ICANON */
74#define VTIME 17 /* !ICANON */
75#if __BSD_VISIBLE
76#define VSTATUS 18 /* ICANON */
77/* 19 spare 2 */
78#endif
79#define NCCS 20
80
81#define _POSIX_VDISABLE (0377)
82
83#if __BSD_VISIBLE
84#define CCEQ(val, c) (c == val ? val != _POSIX_VDISABLE : 0)
85#endif
86
87/*
88 * Input flags - software input processing
89 */
90#define IGNBRK 0x00000001 /* ignore BREAK condition */
91#define BRKINT 0x00000002 /* map BREAK to SIGINT */
92#define IGNPAR 0x00000004 /* ignore (discard) parity errors */
93#define PARMRK 0x00000008 /* mark parity and framing errors */
94#define INPCK 0x00000010 /* enable checking of parity errors */
95#define ISTRIP 0x00000020 /* strip 8th bit off chars */
96#define INLCR 0x00000040 /* map NL into CR */
97#define IGNCR 0x00000080 /* ignore CR */
98#define ICRNL 0x00000100 /* map CR to NL (ala CRMOD) */
99#define IXON 0x00000200 /* enable output flow control */
100#define IXOFF 0x00000400 /* enable input flow control */
101#if __BSD_VISIBLE
102#define IXANY 0x00000800 /* any char will restart after stop */
103#define IUCLC 0x00001000 /* translate upper to lower case */
104#define IMAXBEL 0x00002000 /* ring bell on input queue full */
105#endif /* __BSD_VISIBLE */
106
107/*
108 * Output flags - software output processing
109 */
110#define OPOST 0x00000001 /* enable following output processing */
111#if __XPG_VISIBLE
112#define ONLCR 0x00000002 /* map NL to CR-NL (ala CRMOD) */
113#endif
114#if __BSD_VISIBLE || __XPG_VISIBLE
115#define TABDLY 0x00000004 /* horizontal tab delay mask */
116#define TAB0 0x00000000 /* no tab delay or expansion */
117#define TAB3 0x00000004 /* expand tabs to spaces */
118#if __BSD_VISIBLE
119#define OXTABS TAB3 /* BSD name for TAB3 */
120#define ONOEOT 0x00000008 /* discard EOT's (^D) on output */
121#endif
122#endif
123#if __XPG_VISIBLE
124#define OCRNL 0x00000010 /* map CR to NL */
125#define OLCUC 0x00000020 /* translate lower case to upper case */
126#define ONOCR 0x00000040 /* No CR output at column 0 */
127#define ONLRET 0x00000080 /* NL performs the CR function */
128#endif /* __XPG_VISIBLE */
129
130/*
131 * Control flags - hardware control of terminal
132 */
133#if __BSD_VISIBLE
134#define CIGNORE 0x00000001 /* ignore control flags */
135#endif
136#define CSIZE 0x00000300 /* character size mask */
137#define CS5 0x00000000 /* 5 bits (pseudo) */
138#define CS6 0x00000100 /* 6 bits */
139#define CS7 0x00000200 /* 7 bits */
140#define CS8 0x00000300 /* 8 bits */
141#define CSTOPB 0x00000400 /* send 2 stop bits */
142#define CREAD 0x00000800 /* enable receiver */
143#define PARENB 0x00001000 /* parity enable */
144#define PARODD 0x00002000 /* odd parity, else even */
145#define HUPCL 0x00004000 /* hang up on last close */
146#define CLOCAL 0x00008000 /* ignore modem status lines */
147#if __BSD_VISIBLE
148#define CRTSCTS 0x00010000 /* RTS/CTS full-duplex flow control */
149#define CRTS_IFLOW CRTSCTS /* XXX compat */
150#define CCTS_OFLOW CRTSCTS /* XXX compat */
151#define MDMBUF 0x00100000 /* DTR/DCD hardware flow control */
152#define CHWFLOW (MDMBUF|CRTSCTS) /* all types of hw flow control */
153#endif /* __BSD_VISIBLE */
154
155/*
156 * "Local" flags - dumping ground for other state
157 *
158 * Warning: some flags in this structure begin with
159 * the letter "I" and look like they belong in the
160 * input flag.
161 */
162
163#if __BSD_VISIBLE
164#define ECHOKE 0x00000001 /* visual erase for line kill */
165#endif
166#define ECHOE 0x00000002 /* visually erase chars */
167#define ECHOK 0x00000004 /* echo NL after line kill */
168#define ECHO 0x00000008 /* enable echoing */
169#define ECHONL 0x00000010 /* echo NL even if ECHO is off */
170#if __BSD_VISIBLE
171#define ECHOPRT 0x00000020 /* visual erase mode for hardcopy */
172#define ECHOCTL 0x00000040 /* echo control chars as ^(Char) */
173#endif
174#define ISIG 0x00000080 /* enable signals INTR, QUIT, [D]SUSP */
175#define ICANON 0x00000100 /* canonicalize input lines */
176#if __BSD_VISIBLE
177#define ALTWERASE 0x00000200 /* use alternate WERASE algorithm */
178#endif
179#define IEXTEN 0x00000400 /* enable DISCARD and LNEXT */
180#define EXTPROC 0x00000800 /* external processing */
181#define TOSTOP 0x00400000 /* stop background jobs from output */
182#if __BSD_VISIBLE
183#define FLUSHO 0x00800000 /* output being flushed (state) */
184#define XCASE 0x01000000 /* canonical upper/lower case */
185#define NOKERNINFO 0x02000000 /* no kernel output from VSTATUS */
186#define PENDIN 0x20000000 /* XXX retype pending input (state) */
187#endif
188#define NOFLSH 0x80000000 /* don't flush after interrupt */
189
190typedef unsigned int tcflag_t;
191typedef unsigned char cc_t;
192typedef unsigned int speed_t;
193
194struct termios {
195 tcflag_t c_iflag; /* input flags */
196 tcflag_t c_oflag; /* output flags */
197 tcflag_t c_cflag; /* control flags */
198 tcflag_t c_lflag; /* local flags */
199 cc_t c_cc[NCCS]; /* control chars */
200 int c_ispeed; /* input speed */
201 int c_ospeed; /* output speed */
202};
203
204/*
205 * Commands passed to tcsetattr() for setting the termios structure.
206 */
207#define TCSANOW 0 /* make change immediate */
208#define TCSADRAIN 1 /* drain output, then change */
209#define TCSAFLUSH 2 /* drain output, flush input */
210#if __BSD_VISIBLE
211#define TCSASOFT 0x10 /* flag - don't alter h.w. state */
212#endif
213
214/*
215 * Standard speeds
216 */
217#define B0 0
218#define B50 50
219#define B75 75
220#define B110 110
221#define B134 134
222#define B150 150
223#define B200 200
224#define B300 300
225#define B600 600
226#define B1200 1200
227#define B1800 1800
228#define B2400 2400
229#define B4800 4800
230#define B9600 9600
231#define B19200 19200
232#define B38400 38400
233#if __BSD_VISIBLE
234#define B7200 7200
235#define B14400 14400
236#define B28800 28800
237#define B57600 57600
238#define B76800 76800
239#define B115200 115200
240#define B230400 230400
241#define EXTA 19200
242#define EXTB 38400
243#endif /* __BSD_VISIBLE */
244
245#ifndef _KERNEL
246
247#define TCIFLUSH 1
248#define TCOFLUSH 2
249#define TCIOFLUSH 3
250#define TCOOFF 1
251#define TCOON 2
252#define TCIOFF 3
253#define TCION 4
254
255#include <sys/_types.h>
256
257#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809
258#ifndef _PID_T_DEFINED_
259#define _PID_T_DEFINED_
260typedef __pid_t pid_t;
261#endif
262#endif
263
264__BEGIN_DECLS
265speed_t cfgetispeed(const struct termios *);
266speed_t cfgetospeed(const struct termios *);
267int cfsetispeed(struct termios *, speed_t);
268int cfsetospeed(struct termios *, speed_t);
269int tcgetattr(int, struct termios *);
270int tcsetattr(int, int, const struct termios *);
271int tcdrain(int);
272int tcflow(int, int);
273int tcflush(int, int);
274int tcsendbreak(int, int);
275
276#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809
277pid_t tcgetsid(int);
278#endif
279
280#if __BSD_VISIBLE
281void cfmakeraw(struct termios *);
282int cfsetspeed(struct termios *, speed_t);
283#endif /* __BSD_VISIBLE */
284__END_DECLS
285
286#endif /* !_KERNEL */
287
288#if __BSD_VISIBLE
289/*
290 * Include tty ioctl's that aren't just for backwards compatibility
291 * with the old tty driver. These ioctl definitions were previously
292 * in <sys/ioctl.h>.
293 */
294#include <sys/ttycom.h>
295#endif
296
297/*
298 * END OF PROTECTED INCLUDE.
299 */
300#endif /* !_SYS_TERMIOS_H_ */
301
302#if __BSD_VISIBLE
303#include <sys/ttydefaults.h>
304#endif