1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
22/*	  All Rights Reserved	*/
23
24
25/*
26 * Copyright 2014 Garrett D'Amore <garrett@damore.org>
27 *
28 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
29 */
30
31#ifndef _SYS_TERMIOS_H
32#define	_SYS_TERMIOS_H
33
34#include <sys/feature_tests.h>
35
36#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
37#include <sys/ttydev.h>
38#include <sys/time.h>
39#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
40
41#include <sys/types.h>
42
43#ifdef	__cplusplus
44extern "C" {
45#endif
46
47/*
48 * _POSIX_VDISABLE has been defined in <sys/termios.h> since the
49 * introduction of the header. The POSIX standard, IEEE Std.
50 * 1003.1-1988 also required  the existence of _POSIX_VDISABLE in
51 * this header. Subsequent versions of the IEEE Standard as well
52 * as the X/Open specifications required that _POSIX_VDISABLE be
53 * defined in <unistd.h> while still allowing for it's existence
54 * here. With the introduction of XPG6, _POSIX_VDISABLE can only
55 * be defined in <unistd.h>.
56 */
57#if !defined(_XPG6) || defined(__EXTENSIONS__)
58#ifndef _POSIX_VDISABLE
59#define	_POSIX_VDISABLE 0 /* Disable special character functions */
60#endif
61#endif /* !defined(_XPG6) || defined(__EXTENSIONS__) */
62
63#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
64#define	CTRL(c)	((c)&037)
65#define	IBSHIFT 16
66#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
67
68/* required by termio.h and VCEOF/VCEOL */
69#define	_NCC	8
70#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
71#define	NCC	_NCC
72#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
73
74/* some defines required by POSIX */
75#define	NCCS	19
76
77/*
78 * types defined by POSIX. These are better off in types.h, but
79 * the standard says that they have to be in termios.h.
80 */
81typedef unsigned int tcflag_t;
82typedef unsigned char cc_t;
83typedef unsigned int speed_t;
84
85/*
86 * Ioctl control packet
87 */
88struct termios {
89	tcflag_t	c_iflag;	/* input modes */
90	tcflag_t	c_oflag;	/* output modes */
91	tcflag_t	c_cflag;	/* control modes */
92	tcflag_t	c_lflag;	/* line discipline modes */
93	cc_t		c_cc[NCCS];	/* control chars */
94};
95
96/*
97 * POSIX termios functions
98 * These functions get mapped into ioctls.
99 */
100
101#ifndef _KERNEL
102
103extern speed_t cfgetospeed(const struct termios *);
104extern int cfsetospeed(struct termios *, speed_t);
105extern speed_t cfgetispeed(const struct termios *);
106extern int cfsetispeed(struct termios *, speed_t);
107extern int tcgetattr(int, struct termios *);
108extern int tcsetattr(int, int, const struct termios *);
109extern int tcsendbreak(int, int);
110extern int tcdrain(int);
111extern int tcflush(int, int);
112extern int tcflow(int, int);
113
114#if !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) || defined(__EXTENSIONS__)
115
116extern pid_t tcgetsid(int);
117
118#endif /* !defined(__XOPEN_OR_POSIX) || defined(_XPG4_2) ... */
119
120#endif
121
122/* control characters */
123#define	VINTR	0
124#define	VQUIT	1
125#define	VERASE	2
126#define	VKILL	3
127#define	VEOF	4
128#define	VEOL	5
129#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
130#define	VEOL2	6
131#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
132#define	VMIN	4
133#define	VTIME	5
134#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
135#define	VSWTCH	7
136#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
137#define	VSTART		8
138#define	VSTOP		9
139#define	VSUSP		10
140#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
141#define	VDSUSP		11
142#define	VREPRINT	12
143#define	VDISCARD	13
144#define	VWERASE		14
145#define	VLNEXT		15
146#define	VSTATUS		16
147#define	VERASE2		17
148/* 18 through 19 reserved for future use */
149
150/*
151 * control characters form Xenix termio.h
152 */
153#define	VCEOF	NCC		/* RESERVED true EOF char (V7 compatability) */
154#define	VCEOL	(NCC + 1)	/* RESERVED true EOL char */
155
156#define	CNUL	0
157#define	CDEL	0177
158
159/* S5 default control chars */
160/* CINTR, CERASE and CKILL modified to SunOS traditional values */
161#define	CESC	'\\'
162#define	CINTR	CTRL('c')
163#define	CQUIT	034	/* FS, cntl | */
164#define	CERASE	0177	/* DEL */
165#define	CERASE2	CTRL('h')
166#define	CKILL	CTRL('u')
167#define	CEOT	04
168#define	CEOL	0
169#define	CEOL2	0
170#define	CEOF	04	/* cntl d */
171#define	CSTART	021	/* cntl q */
172#define	CSTOP	023	/* cntl s */
173#define	CSWTCH	032	/* cntl z */
174#define	CNSWTCH	0
175#define	CSUSP	CTRL('z')
176#define	CDSUSP	CTRL('y')
177#define	CRPRNT	CTRL('r')
178#define	CFLUSH	CTRL('o')
179#define	CWERASE	CTRL('w')
180#define	CLNEXT	CTRL('v')
181#define	CSTATUS	CTRL('t')
182#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
183
184
185/* input modes */
186#define	IGNBRK	0000001
187#define	BRKINT	0000002
188#define	IGNPAR	0000004
189#define	PARMRK	0000010
190#define	INPCK	0000020
191#define	ISTRIP	0000040
192#define	INLCR	0000100
193#define	IGNCR	0000200
194#define	ICRNL	0000400
195#if !defined(_POSIX_C_SOURCE) || \
196	(defined(_XOPEN_SOURCE) && !defined(_XPG6)) || \
197	defined(__EXTENSIONS__)
198#define	IUCLC	0001000
199#endif /* !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)... */
200#define	IXON	0002000
201#if !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
202	defined(__EXTENSIONS__)
203#define	IXANY	0004000
204#endif /* !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)... */
205#define	IXOFF	0010000
206#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
207#define	IMAXBEL 0020000
208#define	DOSMODE	0100000  /* for 386 compatibility */
209#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
210
211/* output modes */
212#define	OPOST	0000001
213#if !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
214	defined(__EXTENSIONS__)
215#if !defined(_XPG6) || defined(__EXTENSIONS__)
216#define	OLCUC	0000002
217#endif
218#define	ONLCR	0000004
219#define	OCRNL	0000010
220#define	ONOCR	0000020
221#define	ONLRET	0000040
222#define	OFILL	0000100
223#define	OFDEL	0000200
224#define	NLDLY	0000400
225#define	NL0	0
226#define	NL1	0000400
227#define	CRDLY	0003000
228#define	CR0	0
229#define	CR1	0001000
230#define	CR2	0002000
231#define	CR3	0003000
232#define	TABDLY	0014000
233#define	TAB0	0
234#define	TAB1	0004000
235#define	TAB2	0010000
236#define	TAB3	0014000
237#endif /* !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)... */
238#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
239#define	XTABS	0014000
240#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
241#if !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE) || \
242	defined(__EXTENSIONS__)
243#define	BSDLY	0020000
244#define	BS0	0
245#define	BS1	0020000
246#define	VTDLY	0040000
247#define	VT0	0
248#define	VT1	0040000
249#define	FFDLY	0100000
250#define	FF0	0
251#define	FF1	0100000
252#endif /* !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)... */
253#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
254#define	PAGEOUT 0200000
255#define	WRAP	0400000
256
257/* control modes */
258#define	CBAUD	0000017
259#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
260#define	CSIZE	0000060
261#define	CS5	0
262#define	CS6	0000020
263#define	CS7	0000040
264#define	CS8	0000060
265#define	CSTOPB	0000100
266#define	CREAD	0000200
267#define	PARENB	0000400
268#define	PARODD	0001000
269#define	HUPCL	0002000
270#define	CLOCAL	0004000
271#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
272#define	RCV1EN	0010000
273#define	XMT1EN	0020000
274#define	LOBLK	0040000
275#define	XCLUDE	0100000		/* *V7* exclusive use coming fron XENIX */
276#define	CRTSXOFF 010000000000
277#define	CRTSCTS	020000000000
278#define	CIBAUD	03600000
279#define	PAREXT	04000000
280#define	CBAUDEXT 010000000
281#define	CIBAUDEXT 020000000
282
283/*
284 * 4.4BSD hardware flow control flags
285 */
286#define	CRTS_IFLOW 010000000000
287#define	CCTS_OFLOW 020000000000
288
289#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
290
291/* line discipline 0 modes */
292#define	ISIG	0000001
293#define	ICANON	0000002
294#if !defined(_POSIX_C_SOURCE) || \
295	(defined(_XOPEN_SOURCE) && !defined(_XPG6)) || \
296	defined(__EXTENSIONS__)
297#define	XCASE	0000004
298#endif /* !defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)... */
299#define	ECHO	0000010
300#define	ECHOE	0000020
301#define	ECHOK	0000040
302#define	ECHONL	0000100
303#define	NOFLSH	0000200
304#define	TOSTOP	0000400
305#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
306#define	ECHOCTL	0001000
307#define	ECHOPRT	0002000
308#define	ECHOKE	0004000
309#define	DEFECHO	0010000
310#define	FLUSHO	0020000
311#define	PENDIN	0040000
312#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
313
314#define	IEXTEN	0100000  /* POSIX flag - enable POSIX extensions */
315#define	_TIOC	('T'<<8)
316
317#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
318
319#define	TIOC	_TIOC
320
321#define	TCGETA	(_TIOC|1)
322#define	TCSETA	(_TIOC|2)
323#define	TCSETAW	(_TIOC|3)
324#define	TCSETAF	(_TIOC|4)
325#define	TCSBRK	(_TIOC|5)
326#define	TCXONC	(_TIOC|6)
327#define	TCFLSH	(_TIOC|7)
328
329/* Slots reserved for 386/XENIX compatibility - keyboard control */
330
331#define	TIOCKBON	(_TIOC|8)
332#define	TIOCKBOF 	(_TIOC|9)
333#define	KBENABLED 	(_TIOC|10)
334
335#ifndef IOCTYPE
336#define	IOCTYPE	0xff00
337#endif
338
339#define	TCDSET	(_TIOC|32)
340#define	RTS_TOG	(_TIOC|33)	/* 386 - "RTS" toggle define 8A1 protocol */
341
342#define	TIOCGWINSZ (_TIOC|104)
343#define	TIOCSWINSZ (_TIOC|103)
344
345/*
346 * Softcarrier ioctls
347 */
348#define	TIOCGSOFTCAR (_TIOC|105)
349#define	TIOCSSOFTCAR (_TIOC|106)
350
351
352/* termios ioctls */
353
354#define	TCGETS		(_TIOC|13)
355#define	TCSETS		(_TIOC|14)
356#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
357#define	TCSANOW		(_TIOC|14) /* same as TCSETS */
358#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
359#define	TCSETSW		(_TIOC|15)
360#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
361#define	TCSADRAIN	(_TIOC|15) /* same as TCSETSW */
362#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
363#define	TCSETSF		(_TIOC|16)
364
365/*
366 * NTP PPS ioctls
367 */
368#define	TIOCGPPS	(_TIOC|125)
369#define	TIOCSPPS	(_TIOC|126)
370#define	TIOCGPPSEV	(_TIOC|127)
371
372/* Argument filled in by TIOCGPPSEV */
373struct ppsclockev {
374	struct timeval tv;
375	uint_t serial;
376};
377
378#if defined(_SYSCALL32)
379struct ppsclockev32 {
380	struct timeval32 tv;
381	uint32_t serial;
382};
383#endif /* _SYSCALL32 */
384
385#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
386
387#define	TCSAFLUSH	(_TIOC|16) /* same as TCSETSF */
388
389/* termios option flags */
390
391#define	TCIFLUSH	0  /* flush data received but not read */
392#define	TCOFLUSH	1  /* flush data written but not transmitted */
393#define	TCIOFLUSH	2  /* flush both data both input and output queues */
394
395#define	TCOOFF		0  /* suspend output */
396#define	TCOON		1  /* restart suspended output */
397#define	TCIOFF		2  /* suspend input */
398#define	TCION		3  /* restart suspended input */
399
400/* TIOC ioctls for BSD, ptys, job control and modem control */
401
402#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
403#define	tIOC	('t'<<8)
404#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
405
406/* Slots for 386/XENIX compatibility */
407/* BSD includes these ioctls in ttold.h */
408
409#ifndef _SYS_TTOLD_H
410
411#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
412#define	TIOCGETD	(tIOC|0)
413#define	TIOCSETD	(tIOC|1)
414#define	TIOCHPCL	(tIOC|2)
415#define	TIOCGETP	(tIOC|8)
416#define	TIOCSETP  	(tIOC|9)
417#define	TIOCSETN	(tIOC|10)
418#define	TIOCEXCL	(tIOC|13)
419#define	TIOCNXCL	(tIOC|14)
420#define	TIOCFLUSH	(tIOC|16)
421#define	TIOCSETC	(tIOC|17)
422#define	TIOCGETC	(tIOC|18)
423/*
424 * BSD ioctls that are not the same as XENIX are included here.
425 * There are also some relevant ioctls from SUN/BSD sys/ttycom.h
426 * BSD pty ioctls like TIOCPKT are not supported in SVR4.
427 */
428
429#define	TIOCLBIS	(tIOC|127)	/* bis local mode bits */
430#define	TIOCLBIC	(tIOC|126)	/* bic local mode bits */
431#define	TIOCLSET	(tIOC|125)	/* set entire local mode word */
432#define	TIOCLGET	(tIOC|124)	/* get local modes */
433#define	TIOCSBRK	(tIOC|123)	/* set break bit */
434#define	TIOCCBRK	(tIOC|122)	/* clear break bit */
435#define	TIOCSDTR	(tIOC|121)	/* set data terminal ready */
436#define	TIOCCDTR	(tIOC|120)	/* clear data terminal ready */
437#define	TIOCSLTC	(tIOC|117)	/* set local special chars */
438#define	TIOCGLTC	(tIOC|116)	/* get local special chars */
439#define	TIOCOUTQ	(tIOC|115)	/* driver output queue size */
440#define	TIOCNOTTY	(tIOC|113)	/* void tty association */
441#define	TIOCSCTTY	(tIOC|132)	/* get a ctty */
442#define	TIOCSTOP	(tIOC|111)	/* stop output, like ^S */
443#define	TIOCSTART	(tIOC|110)	/* start output, like ^Q */
444#define	TIOCSILOOP	(tIOC|109)	/* private to Sun; do not use */
445#define	TIOCCILOOP	(tIOC|108)	/* private to Sun; do not use */
446
447#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
448
449#endif /* end _SYS_TTOLD_H */
450
451/* POSIX job control ioctls */
452
453#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
454#define	TIOCGPGRP	(tIOC|20)	/* get pgrp of tty */
455#define	TIOCSPGRP	(tIOC|21)	/* set pgrp of tty */
456#define	TIOCGSID	(tIOC|22)	/* get session id on ctty */
457
458/* Miscellaneous */
459#define	TIOCSTI		(tIOC|23)	/* simulate terminal input */
460
461/* Modem control */
462#define	TIOCMSET	(tIOC|26)	/* set all modem bits */
463#define	TIOCMBIS	(tIOC|27)	/* bis modem bits */
464#define	TIOCMBIC	(tIOC|28)	/* bic modem bits */
465#define	TIOCMGET	(tIOC|29)	/* get all modem bits */
466#define		TIOCM_LE	0001		/* line enable */
467#define		TIOCM_DTR	0002		/* data terminal ready */
468#define		TIOCM_RTS	0004		/* request to send */
469#define		TIOCM_ST	0010		/* secondary transmit */
470#define		TIOCM_SR	0020		/* secondary receive */
471#define		TIOCM_CTS	0040		/* clear to send */
472#define		TIOCM_CAR	0100		/* carrier detect */
473#define		TIOCM_CD	TIOCM_CAR
474#define		TIOCM_RNG	0200		/* ring */
475#define		TIOCM_RI	TIOCM_RNG
476#define		TIOCM_DSR	0400		/* data set ready */
477
478/* pseudo-tty */
479
480#define	TIOCREMOTE	(tIOC|30)	/* remote input editing */
481#define	TIOCSIGNAL	(tIOC|31)	/* pty: send signal to slave */
482
483
484/* Some more 386 xenix stuff */
485
486#define	LDIOC	('D'<<8)
487
488#define	LDOPEN	(LDIOC|0)
489#define	LDCLOSE	(LDIOC|1)
490#define	LDCHG	(LDIOC|2)
491#define	LDGETT	(LDIOC|8)
492#define	LDSETT	(LDIOC|9)
493
494/* Slots for 386 compatibility */
495
496#define	LDSMAP	(LDIOC|110)
497#define	LDGMAP	(LDIOC|111)
498#define	LDNMAP	(LDIOC|112)
499#define	LDEMAP	(LDIOC|113)
500#define	LDDMAP	(LDIOC|114)
501
502/*
503 * These are retained for 386/XENIX compatibility.
504 */
505
506#define	DIOC		('d'<<8)
507#define	DIOCGETP	(DIOC|8)		/* V7 */
508#define	DIOCSETP	(DIOC|9)		/* V7 */
509
510/*
511 * Returns a non-zero value if there
512 * are characters in the input queue.
513 *
514 * XXX - somebody is confused here.  V7 had no such "ioctl", although XENIX may
515 * have added it; 4BSD had FIONREAD, which returned the number of characters
516 * waiting, and was supposed to work on all descriptors (i.e., every driver
517 * should make a stab at implementing it).
518 */
519#define	FIORDCHK	(('f'<<8)|3)		/* V7 */
520#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
521
522/*
523 * Speeds
524 */
525#define	B0	0
526#define	B50	1
527#define	B75	2
528#define	B110	3
529#define	B134	4
530#define	B150	5
531#define	B200	6
532#define	B300	7
533#define	B600	8
534#define	B1200	9
535#define	B1800	10
536#define	B2400	11
537#define	B4800	12
538#define	B9600	13
539#define	B19200	14
540#define	B38400	15
541#define	B57600	16
542#define	B76800	17
543#define	B115200	18
544#define	B153600	19
545#define	B230400	20
546#define	B307200	21
547#define	B460800	22
548#define	B921600	23
549
550#ifndef _SYS_TTOLD_H
551
552#if !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__)
553/* Windowing structure to support JWINSIZE/TIOCSWINSZ/TIOCGWINSZ */
554struct winsize {
555	unsigned short ws_row;	/* rows, in characters */
556	unsigned short ws_col;	/* columns, in character */
557	unsigned short ws_xpixel;	/* horizontal size, pixels */
558	unsigned short ws_ypixel;	/* vertical size, pixels */
559};
560#endif /* !defined(__XOPEN_OR_POSIX) || defined(__EXTENSIONS__) */
561
562#endif /* end _SYS_TTOLD_H */
563
564#ifdef	__cplusplus
565}
566#endif
567
568#endif	/* _SYS_TERMIOS_H */
569