1 /*- 2 * Copyright (c) 1982, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)tty.h 8.4 (Berkeley) 09/23/93 8 */ 9 10 #include <sys/termios.h> 11 #include <sys/select.h> /* For struct selinfo. */ 12 13 /* 14 * Clists are character lists, which is a variable length linked list 15 * of cblocks, with a count of the number of characters in the list. 16 */ 17 struct clist { 18 int c_cc; /* Number of characters in the clist. */ 19 char *c_cf; /* Pointer to the first cblock. */ 20 char *c_cl; /* Pointer to the last cblock. */ 21 }; 22 23 /* 24 * Per-tty structure. 25 * 26 * Should be split in two, into device and tty drivers. 27 * Glue could be masks of what to echo and circular buffer 28 * (low, high, timeout). 29 */ 30 struct tty { 31 struct clist t_rawq; /* Device raw input queue. */ 32 long t_rawcc; /* Raw input queue statistics. */ 33 struct clist t_canq; /* Device canonical queue. */ 34 long t_cancc; /* Canonical queue statistics. */ 35 struct clist t_outq; /* Device output queue. */ 36 long t_outcc; /* Output queue statistics. */ 37 char t_line; /* Interface to device drivers. */ 38 dev_t t_dev; /* Device. */ 39 int t_state; /* Device and driver (TS*) state. */ 40 int t_flags; /* Tty flags. */ 41 struct pgrp *t_pgrp; /* Foreground process group. */ 42 struct session *t_session; /* Enclosing session. */ 43 struct selinfo t_rsel; /* Tty read/oob select. */ 44 struct selinfo t_wsel; /* Tty write select. */ 45 struct termios t_termios; /* Termios state. */ 46 struct winsize t_winsize; /* Window size. */ 47 /* Start output. */ 48 void (*t_oproc) __P((struct tty *)); 49 #ifdef sun4c 50 /* Stop output. */ 51 void (*t_stop) __P((struct tty *, int)); 52 #endif 53 /* Set hardware state. */ 54 int (*t_param) __P((struct tty *, struct termios *)); 55 void *t_sc; /* XXX: net/if_sl.c:sl_softc. */ 56 short t_column; /* Tty output column. */ 57 short t_rocount, t_rocol; /* Tty. */ 58 short t_hiwat; /* High water mark. */ 59 short t_lowat; /* Low water mark. */ 60 short t_gen; /* Generation number. */ 61 }; 62 63 #define t_cc t_termios.c_cc 64 #define t_cflag t_termios.c_cflag 65 #define t_iflag t_termios.c_iflag 66 #define t_ispeed t_termios.c_ispeed 67 #define t_lflag t_termios.c_lflag 68 #define t_min t_termios.c_min 69 #define t_oflag t_termios.c_oflag 70 #define t_ospeed t_termios.c_ospeed 71 #define t_time t_termios.c_time 72 73 #define TTIPRI 25 /* Sleep priority for tty reads. */ 74 #define TTOPRI 26 /* Sleep priority for tty writes. */ 75 76 #define TTMASK 15 77 #define OBUFSIZ 100 78 #define TTYHOG 1024 79 80 #ifdef KERNEL 81 #define TTMAXHIWAT roundup(2048, CBSIZE) 82 #define TTMINHIWAT roundup(100, CBSIZE) 83 #define TTMAXLOWAT 256 84 #define TTMINLOWAT 32 85 #endif 86 87 /* These flags are kept in t_state. */ 88 #define TS_ASLEEP 0x00001 /* Process waiting for tty. */ 89 #define TS_ASYNC 0x00002 /* Tty in async I/O mode. */ 90 #define TS_BUSY 0x00004 /* Draining output. */ 91 #define TS_CARR_ON 0x00008 /* Carrier is present. */ 92 #define TS_FLUSH 0x00010 /* Outq has been flushed during DMA. */ 93 #define TS_ISOPEN 0x00020 /* Open has completed. */ 94 #define TS_TBLOCK 0x00040 /* Further input blocked. */ 95 #define TS_TIMEOUT 0x00080 /* Wait for output char processing. */ 96 #define TS_TTSTOP 0x00100 /* Output paused. */ 97 #define TS_WOPEN 0x00200 /* Open in progress. */ 98 #define TS_XCLUDE 0x00400 /* Tty requires exclusivity. */ 99 100 /* State for intra-line fancy editing work. */ 101 #define TS_BKSL 0x00800 /* State for lowercase \ work. */ 102 #define TS_CNTTB 0x01000 /* Counting tab width, ignore FLUSHO. */ 103 #define TS_ERASE 0x02000 /* Within a \.../ for PRTRUB. */ 104 #define TS_LNCH 0x04000 /* Next character is literal. */ 105 #define TS_TYPEN 0x08000 /* Retyping suspended input (PENDIN). */ 106 #define TS_LOCAL (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN) 107 108 /* Character type information. */ 109 #define ORDINARY 0 110 #define CONTROL 1 111 #define BACKSPACE 2 112 #define NEWLINE 3 113 #define TAB 4 114 #define VTAB 5 115 #define RETURN 6 116 117 struct speedtab { 118 int sp_speed; /* Speed. */ 119 int sp_code; /* Code. */ 120 }; 121 122 /* Modem control commands (driver). */ 123 #define DMSET 0 124 #define DMBIS 1 125 #define DMBIC 2 126 #define DMGET 3 127 128 /* Flags on a character passed to ttyinput. */ 129 #define TTY_CHARMASK 0x000000ff /* Character mask */ 130 #define TTY_QUOTE 0x00000100 /* Character quoted */ 131 #define TTY_ERRORMASK 0xff000000 /* Error mask */ 132 #define TTY_FE 0x01000000 /* Framing error or BREAK condition */ 133 #define TTY_PE 0x02000000 /* Parity error */ 134 135 /* Is tp controlling terminal for p? */ 136 #define isctty(p, tp) \ 137 ((p)->p_session == (tp)->t_session && (p)->p_flag & P_CONTROLT) 138 139 /* Is p in background of tp? */ 140 #define isbackground(p, tp) \ 141 (isctty((p), (tp)) && (p)->p_pgrp != (tp)->t_pgrp) 142 143 #ifdef KERNEL 144 extern struct ttychars ttydefaults; 145 146 /* Symbolic sleep message strings. */ 147 extern char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[], ttybuf[]; 148 149 int b_to_q __P((char *cp, int cc, struct clist *q)); 150 void catq __P((struct clist *from, struct clist *to)); 151 void clist_init __P((void)); 152 int getc __P((struct clist *q)); 153 void ndflush __P((struct clist *q, int cc)); 154 int ndqb __P((struct clist *q, int flag)); 155 char *nextc __P((struct clist *q, char *cp, int *c)); 156 int putc __P((int c, struct clist *q)); 157 int q_to_b __P((struct clist *q, char *cp, int cc)); 158 int unputc __P((struct clist *q)); 159 160 int nullmodem __P((struct tty *tp, int flag)); 161 int tputchar __P((int c, struct tty *tp)); 162 int ttioctl __P((struct tty *tp, int com, void *data, int flag)); 163 int ttread __P((struct tty *tp, struct uio *uio, int flag)); 164 void ttrstrt __P((void *tp)); 165 int ttselect __P((dev_t device, int rw, struct proc *p)); 166 void ttsetwater __P((struct tty *tp)); 167 int ttspeedtab __P((int speed, struct speedtab *table)); 168 int ttstart __P((struct tty *tp)); 169 void ttwakeup __P((struct tty *tp)); 170 int ttwrite __P((struct tty *tp, struct uio *uio, int flag)); 171 void ttychars __P((struct tty *tp)); 172 int ttycheckoutq __P((struct tty *tp, int wait)); 173 int ttyclose __P((struct tty *tp)); 174 void ttyflush __P((struct tty *tp, int rw)); 175 void ttyinfo __P((struct tty *tp)); 176 int ttyinput __P((int c, struct tty *tp)); 177 int ttylclose __P((struct tty *tp, int flag)); 178 int ttymodem __P((struct tty *tp, int flag)); 179 int ttyopen __P((dev_t device, struct tty *tp)); 180 int ttyoutput __P((int c, struct tty *tp)); 181 void ttypend __P((struct tty *tp)); 182 void ttyretype __P((struct tty *tp)); 183 void ttyrub __P((int c, struct tty *tp)); 184 int ttysleep __P((struct tty *tp, 185 void *chan, int pri, char *wmesg, int timeout)); 186 int ttywait __P((struct tty *tp)); 187 int ttywflush __P((struct tty *tp)); 188 #endif 189