1 /* 2 * Copyright (c) 1982, 1986 Regents of the University of California. 3 * All rights reserved. The Berkeley software License Agreement 4 * specifies the terms and conditions for redistribution. 5 * 6 * @(#)tty.h 7.6 (Berkeley) 04/04/90 7 */ 8 9 #ifdef KERNEL 10 #include "termios.h" 11 #else 12 #include <sys/termios.h> 13 #endif 14 15 /* 16 * A clist structure is the head of a linked list queue 17 * of characters. The characters are stored in blocks 18 * containing a link and CBSIZE (param.h) characters. 19 * The routines in tty_subr.c manipulate these structures. 20 */ 21 struct clist { 22 int c_cc; /* character count */ 23 char *c_cf; /* pointer to first char */ 24 char *c_cl; /* pointer to last char */ 25 }; 26 27 /* 28 * Per-tty structure. 29 * 30 * Should be split in two, into device and tty drivers. 31 * Glue could be masks of what to echo and circular buffer 32 * (low, high, timeout). 33 */ 34 struct tty { 35 struct clist t_rawq; 36 struct clist t_canq; 37 struct clist t_outq; /* device */ 38 int (*t_oproc)(); /* device */ 39 int (*t_param)(); /* device */ 40 struct proc *t_rsel; /* tty */ 41 struct proc *t_wsel; 42 caddr_t T_LINEP; /* XXX */ 43 caddr_t t_addr; /* ??? */ 44 dev_t t_dev; /* device */ 45 int t_flags; /* (compat) some of both */ 46 int t_state; /* some of both */ 47 struct session *t_session; /* tty */ 48 struct pgrp *t_pgrp; /* foreground process group */ 49 char t_line; /* glue */ 50 char t_col; /* tty */ 51 char t_rocount, t_rocol; /* tty */ 52 short t_hiwat; /* hi water mark */ 53 short t_lowat; /* low water mark */ 54 struct winsize t_winsize; /* window size */ 55 struct termios t_termios; /* termios state */ 56 #define t_iflag t_termios.c_iflag 57 #define t_oflag t_termios.c_oflag 58 #define t_cflag t_termios.c_cflag 59 #define t_lflag t_termios.c_lflag 60 #define t_min t_termios.c_min 61 #define t_time t_termios.c_time 62 #define t_cc t_termios.c_cc 63 #define t_ispeed t_termios.c_ispeed 64 #define t_ospeed t_termios.c_ospeed 65 long t_cancc; /* stats */ 66 long t_rawcc; 67 long t_outcc; 68 }; 69 70 #define TTIPRI 28 71 #define TTOPRI 29 72 73 /* limits */ 74 #define TTMASK 15 75 #define OBUFSIZ 100 76 #define TTYHOG 1024 77 #ifdef KERNEL 78 #define TTMAXHIWAT roundup(2048, CBSIZE) 79 #define TTMINHIWAT roundup(100, CBSIZE) 80 #define TTMAXLOWAT 256 81 #define TTMINLOWAT 32 82 extern struct ttychars ttydefaults; 83 #endif /*KERNEL*/ 84 85 /* internal state bits */ 86 #define TS_TIMEOUT 0x000001 /* delay timeout in progress */ 87 #define TS_WOPEN 0x000002 /* waiting for open to complete */ 88 #define TS_ISOPEN 0x000004 /* device is open */ 89 #define TS_FLUSH 0x000008 /* outq has been flushed during DMA */ 90 #define TS_CARR_ON 0x000010 /* software copy of carrier-present */ 91 #define TS_BUSY 0x000020 /* output in progress */ 92 #define TS_ASLEEP 0x000040 /* wakeup when output done */ 93 #define TS_XCLUDE 0x000080 /* exclusive-use flag against open */ 94 #define TS_TTSTOP 0x000100 /* output stopped by ctl-s */ 95 #define TS_HUPCLS 0x000200 /* hang up upon last close */ 96 #define TS_TBLOCK 0x000400 /* tandem queue blocked */ 97 #define TS_RCOLL 0x000800 /* collision in read select */ 98 #define TS_WCOLL 0x001000 /* collision in write select */ 99 #define TS_ASYNC 0x004000 /* tty in async i/o mode */ 100 /* state for intra-line fancy editing work */ 101 #define TS_BKSL 0x010000 /* state for lowercase \ work */ 102 #define TS_ERASE 0x040000 /* within a \.../ for PRTRUB */ 103 #define TS_LNCH 0x080000 /* next character is literal */ 104 #define TS_TYPEN 0x100000 /* retyping suspended input (PENDIN) */ 105 #define TS_CNTTB 0x200000 /* counting tab width, leave FLUSHO alone */ 106 107 #define TS_LOCAL (TS_BKSL|TS_ERASE|TS_LNCH|TS_TYPEN|TS_CNTTB) 108 109 /* define partab character types */ 110 #define ORDINARY 0 111 #define CONTROL 1 112 #define BACKSPACE 2 113 #define NEWLINE 3 114 #define TAB 4 115 #define VTAB 5 116 #define RETURN 6 117 118 struct speedtab { 119 int sp_speed; 120 int sp_code; 121 }; 122 /* 123 * Flags on character passed to ttyinput 124 */ 125 #define TTY_CHARMASK 0x000000ff /* Character mask */ 126 #define TTY_QUOTE 0x00000100 /* Character quoted */ 127 #define TTY_ERRORMASK 0xff000000 /* Error mask */ 128 #define TTY_FE 0x01000000 /* Framing error or BREAK condition */ 129 #define TTY_PE 0x02000000 /* Parity error */ 130 131 /* 132 * Macros 133 */ 134 #define isctty(p, tp) ((p)->p_session == (tp)->t_session && \ 135 (p)->p_flag&SCTTY) 136 #define isbackground(p, tp) (isctty((p), (tp)) && \ 137 (p)->p_pgrp != (tp)->t_pgrp) 138 139 /* 140 * Modem control commands (driver). 141 */ 142 #define DMSET 0 143 #define DMBIS 1 144 #define DMBIC 2 145 #define DMGET 3 146 147 #ifdef KERNEL 148 /* symbolic sleep message strings */ 149 extern char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[], ttybuf[]; 150 #endif 151