1 /*	$OpenBSD: termios.h,v 1.9 2003/08/28 16:59:34 jmc 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 /*
39  * Special Control Characters
40  *
41  * Index into c_cc[] character array.
42  *
43  *	Name	     Subscript	Enabled by
44  */
45 #define	VEOF		0	/* ICANON */
46 #define	VEOL		1	/* ICANON */
47 #ifndef _POSIX_SOURCE
48 #define	VEOL2		2	/* ICANON */
49 #endif
50 #define	VERASE		3	/* ICANON */
51 #ifndef _POSIX_SOURCE
52 #define VWERASE 	4	/* ICANON */
53 #endif
54 #define VKILL		5	/* ICANON */
55 #ifndef _POSIX_SOURCE
56 #define	VREPRINT 	6	/* ICANON */
57 #endif
58 /*			7	   spare 1 */
59 #define VINTR		8	/* ISIG */
60 #define VQUIT		9	/* ISIG */
61 #define VSUSP		10	/* ISIG */
62 #ifndef _POSIX_SOURCE
63 #define VDSUSP		11	/* ISIG */
64 #endif
65 #define VSTART		12	/* IXON, IXOFF */
66 #define VSTOP		13	/* IXON, IXOFF */
67 #ifndef _POSIX_SOURCE
68 #define	VLNEXT		14	/* IEXTEN */
69 #define	VDISCARD	15	/* IEXTEN */
70 #endif
71 #define VMIN		16	/* !ICANON */
72 #define VTIME		17	/* !ICANON */
73 #ifndef _POSIX_SOURCE
74 #define VSTATUS		18	/* ICANON */
75 /*			19	   spare 2 */
76 #endif
77 #define	NCCS		20
78 
79 #define _POSIX_VDISABLE	(0377)
80 
81 #ifndef _POSIX_SOURCE
82 #define CCEQ(val, c)	(c == val ? val != _POSIX_VDISABLE : 0)
83 #endif
84 
85 /*
86  * Input flags - software input processing
87  */
88 #define	IGNBRK		0x00000001	/* ignore BREAK condition */
89 #define	BRKINT		0x00000002	/* map BREAK to SIGINTR */
90 #define	IGNPAR		0x00000004	/* ignore (discard) parity errors */
91 #define	PARMRK		0x00000008	/* mark parity and framing errors */
92 #define	INPCK		0x00000010	/* enable checking of parity errors */
93 #define	ISTRIP		0x00000020	/* strip 8th bit off chars */
94 #define	INLCR		0x00000040	/* map NL into CR */
95 #define	IGNCR		0x00000080	/* ignore CR */
96 #define	ICRNL		0x00000100	/* map CR to NL (ala CRMOD) */
97 #define	IXON		0x00000200	/* enable output flow control */
98 #define	IXOFF		0x00000400	/* enable input flow control */
99 #ifndef _POSIX_SOURCE
100 #define	IXANY		0x00000800	/* any char will restart after stop */
101 #define	IUCLC		0x00001000	/* translate upper to lower case */
102 #define IMAXBEL		0x00002000	/* ring bell on input queue full */
103 #endif  /*_POSIX_SOURCE */
104 
105 /*
106  * Output flags - software output processing
107  */
108 #define	OPOST		0x00000001	/* enable following output processing */
109 #ifndef _POSIX_SOURCE
110 #define ONLCR		0x00000002	/* map NL to CR-NL (ala CRMOD) */
111 #define OXTABS		0x00000004	/* expand tabs to spaces */
112 #define ONOEOT		0x00000008	/* discard EOT's (^D) on output */
113 #define OCRNL		0x00000010	/* map CR to NL */
114 #define OLCUC		0x00000020	/* translate lower case to upper case */
115 #define ONOCR		0x00000040	/* No CR output at column 0 */
116 #define ONLRET		0x00000080	/* NL performs the CR function */
117 #endif  /*_POSIX_SOURCE */
118 
119 /*
120  * Control flags - hardware control of terminal
121  */
122 #ifndef _POSIX_SOURCE
123 #define	CIGNORE		0x00000001	/* ignore control flags */
124 #endif
125 #define CSIZE		0x00000300	/* character size mask */
126 #define     CS5		    0x00000000	    /* 5 bits (pseudo) */
127 #define     CS6		    0x00000100	    /* 6 bits */
128 #define     CS7		    0x00000200	    /* 7 bits */
129 #define     CS8		    0x00000300	    /* 8 bits */
130 #define CSTOPB		0x00000400	/* send 2 stop bits */
131 #define CREAD		0x00000800	/* enable receiver */
132 #define PARENB		0x00001000	/* parity enable */
133 #define PARODD		0x00002000	/* odd parity, else even */
134 #define HUPCL		0x00004000	/* hang up on last close */
135 #define CLOCAL		0x00008000	/* ignore modem status lines */
136 #ifndef _POSIX_SOURCE
137 #define	CRTSCTS		0x00010000	/* RTS/CTS full-duplex flow control */
138 #define	CRTS_IFLOW	CRTSCTS		/* XXX compat */
139 #define	CCTS_OFLOW	CRTSCTS		/* XXX compat */
140 #define	MDMBUF		0x00100000	/* DTR/DCD hardware flow control */
141 #define	CHWFLOW		(MDMBUF|CRTSCTS) /* all types of hw flow control */
142 #endif
143 
144 
145 /*
146  * "Local" flags - dumping ground for other state
147  *
148  * Warning: some flags in this structure begin with
149  * the letter "I" and look like they belong in the
150  * input flag.
151  */
152 
153 #ifndef _POSIX_SOURCE
154 #define	ECHOKE		0x00000001	/* visual erase for line kill */
155 #endif  /*_POSIX_SOURCE */
156 #define	ECHOE		0x00000002	/* visually erase chars */
157 #define	ECHOK		0x00000004	/* echo NL after line kill */
158 #define ECHO		0x00000008	/* enable echoing */
159 #define	ECHONL		0x00000010	/* echo NL even if ECHO is off */
160 #ifndef _POSIX_SOURCE
161 #define	ECHOPRT		0x00000020	/* visual erase mode for hardcopy */
162 #define ECHOCTL  	0x00000040	/* echo control chars as ^(Char) */
163 #endif  /*_POSIX_SOURCE */
164 #define	ISIG		0x00000080	/* enable signals INTR, QUIT, [D]SUSP */
165 #define	ICANON		0x00000100	/* canonicalize input lines */
166 #ifndef _POSIX_SOURCE
167 #define ALTWERASE	0x00000200	/* use alternate WERASE algorithm */
168 #endif  /*_POSIX_SOURCE */
169 #define	IEXTEN		0x00000400	/* enable DISCARD and LNEXT */
170 #define EXTPROC         0x00000800      /* external processing */
171 #define TOSTOP		0x00400000	/* stop background jobs from output */
172 #ifndef _POSIX_SOURCE
173 #define FLUSHO		0x00800000	/* output being flushed (state) */
174 #define XCASE		0x01000000	/* canonical upper/lower case */
175 #define	NOKERNINFO	0x02000000	/* no kernel output from VSTATUS */
176 #define PENDIN		0x20000000	/* XXX retype pending input (state) */
177 #endif  /*_POSIX_SOURCE */
178 #define	NOFLSH		0x80000000	/* don't flush after interrupt */
179 
180 typedef unsigned int	tcflag_t;
181 typedef unsigned char	cc_t;
182 typedef unsigned int	speed_t;
183 
184 struct termios {
185 	tcflag_t	c_iflag;	/* input flags */
186 	tcflag_t	c_oflag;	/* output flags */
187 	tcflag_t	c_cflag;	/* control flags */
188 	tcflag_t	c_lflag;	/* local flags */
189 	cc_t		c_cc[NCCS];	/* control chars */
190 	int		c_ispeed;	/* input speed */
191 	int		c_ospeed;	/* output speed */
192 };
193 
194 /*
195  * Commands passed to tcsetattr() for setting the termios structure.
196  */
197 #define	TCSANOW		0		/* make change immediate */
198 #define	TCSADRAIN	1		/* drain output, then change */
199 #define	TCSAFLUSH	2		/* drain output, flush input */
200 #ifndef _POSIX_SOURCE
201 #define TCSASOFT	0x10		/* flag - don't alter h.w. state */
202 #endif
203 
204 /*
205  * Standard speeds
206  */
207 #define B0	0
208 #define B50	50
209 #define B75	75
210 #define B110	110
211 #define B134	134
212 #define B150	150
213 #define B200	200
214 #define B300	300
215 #define B600	600
216 #define B1200	1200
217 #define	B1800	1800
218 #define B2400	2400
219 #define B4800	4800
220 #define B9600	9600
221 #define B19200	19200
222 #define B38400	38400
223 #ifndef _POSIX_SOURCE
224 #define B7200	7200
225 #define B14400	14400
226 #define B28800	28800
227 #define B57600	57600
228 #define B76800	76800
229 #define B115200	115200
230 #define B230400	230400
231 #define EXTA	19200
232 #define EXTB	38400
233 #endif  /* !_POSIX_SOURCE */
234 
235 #ifndef _KERNEL
236 
237 #define	TCIFLUSH	1
238 #define	TCOFLUSH	2
239 #define TCIOFLUSH	3
240 #define	TCOOFF		1
241 #define	TCOON		2
242 #define TCIOFF		3
243 #define TCION		4
244 
245 #include <sys/cdefs.h>
246 
247 __BEGIN_DECLS
248 speed_t	cfgetispeed(const struct termios *);
249 speed_t	cfgetospeed(const struct termios *);
250 int	cfsetispeed(struct termios *, speed_t);
251 int	cfsetospeed(struct termios *, speed_t);
252 int	tcgetattr(int, struct termios *);
253 int	tcsetattr(int, int, const struct termios *);
254 int	tcdrain(int);
255 int	tcflow(int, int);
256 int	tcflush(int, int);
257 int	tcsendbreak(int, int);
258 
259 #ifndef _POSIX_SOURCE
260 void	cfmakeraw(struct termios *);
261 int	cfsetspeed(struct termios *, speed_t);
262 #endif /* !_POSIX_SOURCE */
263 __END_DECLS
264 
265 #endif /* !_KERNEL */
266 
267 #ifndef _POSIX_SOURCE
268 
269 /*
270  * Include tty ioctl's that aren't just for backwards compatibility
271  * with the old tty driver.  These ioctl definitions were previously
272  * in <sys/ioctl.h>.
273  */
274 #include <sys/ttycom.h>
275 #endif
276 
277 /*
278  * END OF PROTECTED INCLUDE.
279  */
280 #endif /* !_SYS_TERMIOS_H_ */
281 
282 #ifndef _POSIX_SOURCE
283 #include <sys/ttydefaults.h>
284 #endif
285