termios.h revision 191882
1139825Simp/*-
21541Srgrimes * Copyright (c) 1988, 1989, 1993, 1994
31541Srgrimes *	The Regents of the University of California.  All rights reserved.
41541Srgrimes *
51541Srgrimes * Redistribution and use in source and binary forms, with or without
61541Srgrimes * modification, are permitted provided that the following conditions
71541Srgrimes * are met:
81541Srgrimes * 1. Redistributions of source code must retain the above copyright
91541Srgrimes *    notice, this list of conditions and the following disclaimer.
101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111541Srgrimes *    notice, this list of conditions and the following disclaimer in the
121541Srgrimes *    documentation and/or other materials provided with the distribution.
131541Srgrimes * 4. Neither the name of the University nor the names of its contributors
141541Srgrimes *    may be used to endorse or promote products derived from this software
151541Srgrimes *    without specific prior written permission.
161541Srgrimes *
171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201541Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271541Srgrimes * SUCH DAMAGE.
281541Srgrimes *
291541Srgrimes *	@(#)termios.h	8.3 (Berkeley) 3/28/94
3050477Speter * $FreeBSD: head/sys/sys/termios.h 191882 2009-05-07 13:49:48Z ed $
311541Srgrimes */
321541Srgrimes
331541Srgrimes#ifndef _SYS_TERMIOS_H_
34182817Sed#define	_SYS_TERMIOS_H_
351541Srgrimes
36178295Sdavidxu#include <sys/_types.h>
37178295Sdavidxu#ifndef _PID_T_DECLARED
38178295Sdavidxutypedef	__pid_t		pid_t;
39178295Sdavidxu#define	_PID_T_DECLARED
40178295Sdavidxu#endif
41178295Sdavidxu
428876Srgrimes/*
438876Srgrimes * Special Control Characters
441541Srgrimes *
451541Srgrimes * Index into c_cc[] character array.
461541Srgrimes *
478876Srgrimes *	Name	     Subscript	Enabled by
481541Srgrimes */
491541Srgrimes#define	VEOF		0	/* ICANON */
501541Srgrimes#define	VEOL		1	/* ICANON */
511541Srgrimes#ifndef _POSIX_SOURCE
5220020Sbde#define	VEOL2		2	/* ICANON together with IEXTEN */
531541Srgrimes#endif
541541Srgrimes#define	VERASE		3	/* ICANON */
551541Srgrimes#ifndef _POSIX_SOURCE
56182817Sed#define	VWERASE 	4	/* ICANON together with IEXTEN */
578876Srgrimes#endif
58182817Sed#define	VKILL		5	/* ICANON */
591541Srgrimes#ifndef _POSIX_SOURCE
6020020Sbde#define	VREPRINT 	6	/* ICANON together with IEXTEN */
61182817Sed#define	VERASE2 	7	/* ICANON */
621541Srgrimes#endif
6369322Sjkh/*			7	   ex-spare 1 */
64182817Sed#define	VINTR		8	/* ISIG */
65182817Sed#define	VQUIT		9	/* ISIG */
66182817Sed#define	VSUSP		10	/* ISIG */
671541Srgrimes#ifndef _POSIX_SOURCE
68182817Sed#define	VDSUSP		11	/* ISIG together with IEXTEN */
691541Srgrimes#endif
70182817Sed#define	VSTART		12	/* IXON, IXOFF */
71182817Sed#define	VSTOP		13	/* IXON, IXOFF */
721541Srgrimes#ifndef _POSIX_SOURCE
731541Srgrimes#define	VLNEXT		14	/* IEXTEN */
741541Srgrimes#define	VDISCARD	15	/* IEXTEN */
751541Srgrimes#endif
76182817Sed#define	VMIN		16	/* !ICANON */
77182817Sed#define	VTIME		17	/* !ICANON */
781541Srgrimes#ifndef _POSIX_SOURCE
79182817Sed#define	VSTATUS		18	/* ICANON together with IEXTEN */
801541Srgrimes/*			19	   spare 2 */
811541Srgrimes#endif
821541Srgrimes#define	NCCS		20
831541Srgrimes
848449Sbde#define	_POSIX_VDISABLE	0xff
851541Srgrimes
861541Srgrimes/*
871541Srgrimes * Input flags - software input processing
881541Srgrimes */
891541Srgrimes#define	IGNBRK		0x00000001	/* ignore BREAK condition */
901541Srgrimes#define	BRKINT		0x00000002	/* map BREAK to SIGINTR */
911541Srgrimes#define	IGNPAR		0x00000004	/* ignore (discard) parity errors */
921541Srgrimes#define	PARMRK		0x00000008	/* mark parity and framing errors */
931541Srgrimes#define	INPCK		0x00000010	/* enable checking of parity errors */
941541Srgrimes#define	ISTRIP		0x00000020	/* strip 8th bit off chars */
951541Srgrimes#define	INLCR		0x00000040	/* map NL into CR */
961541Srgrimes#define	IGNCR		0x00000080	/* ignore CR */
971541Srgrimes#define	ICRNL		0x00000100	/* map CR to NL (ala CRMOD) */
981541Srgrimes#define	IXON		0x00000200	/* enable output flow control */
991541Srgrimes#define	IXOFF		0x00000400	/* enable input flow control */
1001541Srgrimes#ifndef _POSIX_SOURCE
1011541Srgrimes#define	IXANY		0x00000800	/* any char will restart after stop */
102182817Sed#define	IMAXBEL		0x00002000	/* ring bell on input queue full */
1031541Srgrimes#endif  /*_POSIX_SOURCE */
1041541Srgrimes
1051541Srgrimes/*
1061541Srgrimes * Output flags - software output processing
1071541Srgrimes */
1081541Srgrimes#define	OPOST		0x00000001	/* enable following output processing */
1091541Srgrimes#ifndef _POSIX_SOURCE
110182817Sed#define	ONLCR		0x00000002	/* map NL to CR-NL (ala CRMOD) */
111181905Sed#define	TABDLY		0x00000004	/* tab delay mask */
112181905Sed#define	    TAB0	    0x00000000	    /* no tab delay and expansion */
113181905Sed#define	    TAB3	    0x00000004	    /* expand tabs to spaces */
114181905Sed#ifndef _KERNEL
115181905Sed#define	OXTABS		TAB3
116181905Sed#endif /* !_KERNEL */
117182817Sed#define	ONOEOT		0x00000008	/* discard EOT's (^D) on output) */
118182817Sed#define	OCRNL		0x00000010	/* map CR to NL on output */
119182817Sed#define	ONOCR		0x00000020	/* no CR output at column 0 */
120182817Sed#define	ONLRET		0x00000040	/* NL performs CR function */
1211541Srgrimes#endif  /*_POSIX_SOURCE */
1221541Srgrimes
1231541Srgrimes/*
1241541Srgrimes * Control flags - hardware control of terminal
1251541Srgrimes */
1261541Srgrimes#ifndef _POSIX_SOURCE
1271541Srgrimes#define	CIGNORE		0x00000001	/* ignore control flags */
1281541Srgrimes#endif
129182817Sed#define	CSIZE		0x00000300	/* character size mask */
130182817Sed#define	    CS5		    0x00000000	    /* 5 bits (pseudo) */
131182817Sed#define	    CS6		    0x00000100	    /* 6 bits */
132182817Sed#define	    CS7		    0x00000200	    /* 7 bits */
133182817Sed#define	    CS8		    0x00000300	    /* 8 bits */
134182817Sed#define	CSTOPB		0x00000400	/* send 2 stop bits */
135182817Sed#define	CREAD		0x00000800	/* enable receiver */
136182817Sed#define	PARENB		0x00001000	/* parity enable */
137182817Sed#define	PARODD		0x00002000	/* odd parity, else even */
138182817Sed#define	HUPCL		0x00004000	/* hang up on last close */
139182817Sed#define	CLOCAL		0x00008000	/* ignore modem status lines */
1401541Srgrimes#ifndef _POSIX_SOURCE
141182817Sed#define	CCTS_OFLOW	0x00010000	/* CTS flow control of output */
142182817Sed#define	CRTSCTS		(CCTS_OFLOW | CRTS_IFLOW)
143182817Sed#define	CRTS_IFLOW	0x00020000	/* RTS flow control of input */
1448187Sbde#define	CDTR_IFLOW	0x00040000	/* DTR flow control of input */
145182817Sed#define	CDSR_OFLOW	0x00080000	/* DSR flow control of output */
1468187Sbde#define	CCAR_OFLOW	0x00100000	/* DCD flow control of output */
147181905Sed#ifndef _KERNEL
148181905Sed#define	MDMBUF		CCAR_OFLOW
149181905Sed#endif /* !_KERNEL */
1501541Srgrimes#endif
1511541Srgrimes
1521541Srgrimes
1538876Srgrimes/*
1541541Srgrimes * "Local" flags - dumping ground for other state
1551541Srgrimes *
1561541Srgrimes * Warning: some flags in this structure begin with
1571541Srgrimes * the letter "I" and look like they belong in the
1581541Srgrimes * input flag.
1591541Srgrimes */
1601541Srgrimes
1611541Srgrimes#ifndef _POSIX_SOURCE
1621541Srgrimes#define	ECHOKE		0x00000001	/* visual erase for line kill */
1631541Srgrimes#endif  /*_POSIX_SOURCE */
1641541Srgrimes#define	ECHOE		0x00000002	/* visually erase chars */
1651541Srgrimes#define	ECHOK		0x00000004	/* echo NL after line kill */
166182817Sed#define	ECHO		0x00000008	/* enable echoing */
1671541Srgrimes#define	ECHONL		0x00000010	/* echo NL even if ECHO is off */
1681541Srgrimes#ifndef _POSIX_SOURCE
1691541Srgrimes#define	ECHOPRT		0x00000020	/* visual erase mode for hardcopy */
170182817Sed#define	ECHOCTL  	0x00000040	/* echo control chars as ^(Char) */
1711541Srgrimes#endif  /*_POSIX_SOURCE */
1721541Srgrimes#define	ISIG		0x00000080	/* enable signals INTR, QUIT, [D]SUSP */
1731541Srgrimes#define	ICANON		0x00000100	/* canonicalize input lines */
1741541Srgrimes#ifndef _POSIX_SOURCE
175182817Sed#define	ALTWERASE	0x00000200	/* use alternate WERASE algorithm */
1761541Srgrimes#endif  /*_POSIX_SOURCE */
1771541Srgrimes#define	IEXTEN		0x00000400	/* enable DISCARD and LNEXT */
178182817Sed#define	EXTPROC         0x00000800      /* external processing */
179182817Sed#define	TOSTOP		0x00400000	/* stop background jobs from output */
1801541Srgrimes#ifndef _POSIX_SOURCE
181182817Sed#define	FLUSHO		0x00800000	/* output being flushed (state) */
1821541Srgrimes#define	NOKERNINFO	0x02000000	/* no kernel output from VSTATUS */
183182817Sed#define	PENDIN		0x20000000	/* XXX retype pending input (state) */
1841541Srgrimes#endif  /*_POSIX_SOURCE */
1851541Srgrimes#define	NOFLSH		0x80000000	/* don't flush after interrupt */
1861541Srgrimes
18735755Sjbtypedef unsigned int	tcflag_t;
1881541Srgrimestypedef unsigned char	cc_t;
18935755Sjbtypedef unsigned int	speed_t;
1901541Srgrimes
1911541Srgrimesstruct termios {
1921541Srgrimes	tcflag_t	c_iflag;	/* input flags */
1931541Srgrimes	tcflag_t	c_oflag;	/* output flags */
1941541Srgrimes	tcflag_t	c_cflag;	/* control flags */
1951541Srgrimes	tcflag_t	c_lflag;	/* local flags */
1961541Srgrimes	cc_t		c_cc[NCCS];	/* control chars */
1978187Sbde	speed_t		c_ispeed;	/* input speed */
1988187Sbde	speed_t		c_ospeed;	/* output speed */
1991541Srgrimes};
2001541Srgrimes
2018876Srgrimes/*
2021541Srgrimes * Standard speeds
2031541Srgrimes */
204182817Sed#define	B0	0
205182817Sed#define	B50	50
206182817Sed#define	B75	75
207182817Sed#define	B110	110
208182817Sed#define	B134	134
209182817Sed#define	B150	150
210182817Sed#define	B200	200
211182817Sed#define	B300	300
212182817Sed#define	B600	600
213182817Sed#define	B1200	1200
2141541Srgrimes#define	B1800	1800
215182817Sed#define	B2400	2400
216182817Sed#define	B4800	4800
217182817Sed#define	B9600	9600
218182817Sed#define	B19200	19200
219182817Sed#define	B38400	38400
2201541Srgrimes#ifndef _POSIX_SOURCE
221182817Sed#define	B7200	7200
222182817Sed#define	B14400	14400
223182817Sed#define	B28800	28800
224182817Sed#define	B57600	57600
225182817Sed#define	B76800	76800
226182817Sed#define	B115200	115200
227182817Sed#define	B230400	230400
228182817Sed#define	B460800	460800
229182817Sed#define	B921600	921600
230182817Sed#define	EXTA	19200
231182817Sed#define	EXTB	38400
2321541Srgrimes#endif  /* !_POSIX_SOURCE */
2331541Srgrimes
23455205Speter#ifndef _KERNEL
2351541Srgrimes
236181905Sed#ifndef _POSIX_SOURCE
237185233Sdwmalone#define	CCEQ(val, c)	((c) == (val) && (val) != _POSIX_VDISABLE)
238181905Sed#endif
239181905Sed
240180561Sed/*
241180561Sed * Commands passed to tcsetattr() for setting the termios structure.
242180561Sed */
243180561Sed#define	TCSANOW		0		/* make change immediate */
244180561Sed#define	TCSADRAIN	1		/* drain output, then change */
245180561Sed#define	TCSAFLUSH	2		/* drain output, flush input */
246180561Sed#ifndef _POSIX_SOURCE
247182817Sed#define	TCSASOFT	0x10		/* flag - don't alter h.w. state */
248180561Sed#endif
249180561Sed
2501541Srgrimes#define	TCIFLUSH	1
2511541Srgrimes#define	TCOFLUSH	2
252182817Sed#define	TCIOFLUSH	3
2531541Srgrimes#define	TCOOFF		1
2541541Srgrimes#define	TCOON		2
255182817Sed#define	TCIOFF		3
256182817Sed#define	TCION		4
2571541Srgrimes
2581541Srgrimes#include <sys/cdefs.h>
2591541Srgrimes
2601541Srgrimes__BEGIN_DECLS
26192719Salfredspeed_t	cfgetispeed(const struct termios *);
26292719Salfredspeed_t	cfgetospeed(const struct termios *);
26392719Salfredint	cfsetispeed(struct termios *, speed_t);
26492719Salfredint	cfsetospeed(struct termios *, speed_t);
26592719Salfredint	tcgetattr(int, struct termios *);
26692719Salfredint	tcsetattr(int, int, const struct termios *);
26792719Salfredint	tcdrain(int);
26892719Salfredint	tcflow(int, int);
26992719Salfredint	tcflush(int, int);
27092719Salfredint	tcsendbreak(int, int);
2711541Srgrimes
272178295Sdavidxu#if __POSIX_VISIBLE >= 200112 || __BSD_VISIBLE
273178295Sdavidxupid_t	tcgetsid(int);
274178295Sdavidxu#endif
275191882Sed#if __BSD_VISIBLE
276191882Sedint	tcsetsid(int, pid_t);
277178295Sdavidxu
27892719Salfredvoid	cfmakeraw(struct termios *);
27992719Salfredint	cfsetspeed(struct termios *, speed_t);
280189813Sdas#endif
2811541Srgrimes__END_DECLS
2821541Srgrimes
28355205Speter#endif /* !_KERNEL */
2841541Srgrimes
2851541Srgrimes#ifndef _POSIX_SOURCE
2861541Srgrimes
2871541Srgrimes/*
2881541Srgrimes * Include tty ioctl's that aren't just for backwards compatibility
2891541Srgrimes * with the old tty driver.  These ioctl definitions were previously
2901541Srgrimes * in <sys/ioctl.h>.
2911541Srgrimes */
2921541Srgrimes#include <sys/ttycom.h>
2931541Srgrimes#endif
2941541Srgrimes
2951541Srgrimes/*
2961541Srgrimes * END OF PROTECTED INCLUDE.
2971541Srgrimes */
2981541Srgrimes#endif /* !_SYS_TERMIOS_H_ */
2991541Srgrimes
3001541Srgrimes#ifndef _POSIX_SOURCE
3011541Srgrimes#include <sys/ttydefaults.h>
3021541Srgrimes#endif
303