1ec04308bSmckusick /*
2ec04308bSmckusick * Copyright (c) 1988 University of Utah.
3cb540868Sbostic * Copyright (c) 1990, 1993
4cb540868Sbostic * The Regents of the University of California. All rights reserved.
5ec04308bSmckusick *
6ec04308bSmckusick * This code is derived from software contributed to Berkeley by
7ec04308bSmckusick * the Systems Programming Group of the University of Utah Computer
8ec04308bSmckusick * Science Department.
9ec04308bSmckusick *
10ec04308bSmckusick * %sccs.include.redist.c%
11ec04308bSmckusick *
12a807ce0aShibler * from: Utah $Hdr: hpux_tty.c 1.14 93/08/05$
13ec04308bSmckusick *
14*eeb57a89Scgd * @(#)hpux_tty.c 8.4 (Berkeley) 02/19/95
15ec04308bSmckusick */
16ec04308bSmckusick
17ec04308bSmckusick /*
18ec04308bSmckusick * stty/gtty/termio emulation stuff
19ec04308bSmckusick */
20ec04308bSmckusick #ifdef HPUXCOMPAT
21c859f549Smckusick #ifndef COMPAT_43
22c859f549Smckusick #define COMPAT_43
23c859f549Smckusick #endif
24ec04308bSmckusick
2585ea23b5Sbostic #include <sys/param.h>
2685ea23b5Sbostic #include <sys/systm.h>
2785ea23b5Sbostic #include <sys/filedesc.h>
2885ea23b5Sbostic #include <sys/ioctl.h>
2985ea23b5Sbostic #include <sys/proc.h>
3085ea23b5Sbostic #include <sys/tty.h>
3185ea23b5Sbostic #include <sys/file.h>
3285ea23b5Sbostic #include <sys/conf.h>
3385ea23b5Sbostic #include <sys/buf.h>
3485ea23b5Sbostic #include <sys/kernel.h>
35ec04308bSmckusick
3685ea23b5Sbostic #include <hp/hpux/hpux.h>
3785ea23b5Sbostic #include <hp/hpux/hpux_termio.h>
38ec04308bSmckusick
39ec04308bSmckusick /*
407a0049f0Shibler * Map BSD/POSIX style termios info to and from SYS5 style termio stuff.
41ec04308bSmckusick */
hpuxtermio(fd,com,data,p)42a807ce0aShibler hpuxtermio(fd, com, data, p)
43d5aaf4efSbostic int fd, com;
44ec04308bSmckusick caddr_t data;
45de3baf12Skarels struct proc *p;
46ec04308bSmckusick {
47a807ce0aShibler struct file *fp;
487a0049f0Shibler struct termios tios;
4975a212a6Shibler struct hpuxtermios htios;
507a0049f0Shibler int line, error, (*ioctlrout)();
5175a212a6Shibler int newi = 0;
52ec04308bSmckusick
53a807ce0aShibler fp = p->p_fd->fd_ofiles[fd];
54ec04308bSmckusick ioctlrout = fp->f_ops->fo_ioctl;
55ec04308bSmckusick switch (com) {
5675a212a6Shibler case HPUXTCGETATTR:
5775a212a6Shibler newi = 1;
5875a212a6Shibler /* fall into ... */
59ec04308bSmckusick case HPUXTCGETA:
607a0049f0Shibler /*
617a0049f0Shibler * Get BSD terminal state
627a0049f0Shibler */
63de3baf12Skarels if (error = (*ioctlrout)(fp, TIOCGETA, (caddr_t)&tios, p))
64ec04308bSmckusick break;
6575a212a6Shibler bzero((char *)&htios, sizeof htios);
667a0049f0Shibler /*
677a0049f0Shibler * Set iflag.
687a0049f0Shibler * Same through ICRNL, no BSD equivs for IUCLC, IENQAK
697a0049f0Shibler */
7075a212a6Shibler htios.c_iflag = tios.c_iflag & 0x1ff;
717a0049f0Shibler if (tios.c_iflag & IXON)
7275a212a6Shibler htios.c_iflag |= TIO_IXON;
737a0049f0Shibler if (tios.c_iflag & IXOFF)
7475a212a6Shibler htios.c_iflag |= TIO_IXOFF;
757a0049f0Shibler if (tios.c_iflag & IXANY)
7675a212a6Shibler htios.c_iflag |= TIO_IXANY;
777a0049f0Shibler /*
787a0049f0Shibler * Set oflag.
797a0049f0Shibler * No BSD equivs for OLCUC/OCRNL/ONOCR/ONLRET/OFILL/OFDEL
807a0049f0Shibler * or any of the delays.
817a0049f0Shibler */
827a0049f0Shibler if (tios.c_oflag & OPOST)
8375a212a6Shibler htios.c_oflag |= TIO_OPOST;
847a0049f0Shibler if (tios.c_oflag & ONLCR)
8575a212a6Shibler htios.c_oflag |= TIO_ONLCR;
867a0049f0Shibler if (tios.c_oflag & OXTABS)
8775a212a6Shibler htios.c_oflag |= TIO_TAB3;
887a0049f0Shibler /*
897a0049f0Shibler * Set cflag.
907a0049f0Shibler * Baud from ospeed, rest from cflag.
917a0049f0Shibler */
9275a212a6Shibler htios.c_cflag = bsdtohpuxbaud(tios.c_ospeed);
937a0049f0Shibler switch (tios.c_cflag & CSIZE) {
947a0049f0Shibler case CS5:
9575a212a6Shibler htios.c_cflag |= TIO_CS5; break;
967a0049f0Shibler case CS6:
9775a212a6Shibler htios.c_cflag |= TIO_CS6; break;
987a0049f0Shibler case CS7:
9975a212a6Shibler htios.c_cflag |= TIO_CS7; break;
1007a0049f0Shibler case CS8:
10175a212a6Shibler htios.c_cflag |= TIO_CS8; break;
102ec04308bSmckusick }
1037a0049f0Shibler if (tios.c_cflag & CSTOPB)
10475a212a6Shibler htios.c_cflag |= TIO_CSTOPB;
1057a0049f0Shibler if (tios.c_cflag & CREAD)
10675a212a6Shibler htios.c_cflag |= TIO_CREAD;
1077a0049f0Shibler if (tios.c_cflag & PARENB)
10875a212a6Shibler htios.c_cflag |= TIO_PARENB;
1097a0049f0Shibler if (tios.c_cflag & PARODD)
11075a212a6Shibler htios.c_cflag |= TIO_PARODD;
1117a0049f0Shibler if (tios.c_cflag & HUPCL)
11275a212a6Shibler htios.c_cflag |= TIO_HUPCL;
1137a0049f0Shibler if (tios.c_cflag & CLOCAL)
11475a212a6Shibler htios.c_cflag |= TIO_CLOCAL;
1157a0049f0Shibler /*
1167a0049f0Shibler * Set lflag.
1177a0049f0Shibler * No BSD equiv for XCASE.
1187a0049f0Shibler */
1197a0049f0Shibler if (tios.c_lflag & ECHOE)
12075a212a6Shibler htios.c_lflag |= TIO_ECHOE;
1217a0049f0Shibler if (tios.c_lflag & ECHOK)
12275a212a6Shibler htios.c_lflag |= TIO_ECHOK;
1237a0049f0Shibler if (tios.c_lflag & ECHO)
12475a212a6Shibler htios.c_lflag |= TIO_ECHO;
1257a0049f0Shibler if (tios.c_lflag & ECHONL)
12675a212a6Shibler htios.c_lflag |= TIO_ECHONL;
1277a0049f0Shibler if (tios.c_lflag & ISIG)
12875a212a6Shibler htios.c_lflag |= TIO_ISIG;
1297a0049f0Shibler if (tios.c_lflag & ICANON)
13075a212a6Shibler htios.c_lflag |= TIO_ICANON;
1317a0049f0Shibler if (tios.c_lflag & NOFLSH)
13275a212a6Shibler htios.c_lflag |= TIO_NOFLSH;
1337a0049f0Shibler /*
1347a0049f0Shibler * Line discipline
1357a0049f0Shibler */
13675a212a6Shibler if (!newi) {
1377a0049f0Shibler line = 0;
138de3baf12Skarels (void) (*ioctlrout)(fp, TIOCGETD, (caddr_t)&line, p);
13975a212a6Shibler htios.c_reserved = line;
140ec04308bSmckusick }
14175a212a6Shibler /*
14275a212a6Shibler * Set editing chars.
14375a212a6Shibler * No BSD equiv for VSWTCH.
14475a212a6Shibler */
14575a212a6Shibler htios.c_cc[HPUXVINTR] = tios.c_cc[VINTR];
14675a212a6Shibler htios.c_cc[HPUXVQUIT] = tios.c_cc[VQUIT];
14775a212a6Shibler htios.c_cc[HPUXVERASE] = tios.c_cc[VERASE];
14875a212a6Shibler htios.c_cc[HPUXVKILL] = tios.c_cc[VKILL];
14975a212a6Shibler htios.c_cc[HPUXVEOF] = tios.c_cc[VEOF];
15075a212a6Shibler htios.c_cc[HPUXVEOL] = tios.c_cc[VEOL];
15175a212a6Shibler htios.c_cc[HPUXVEOL2] = tios.c_cc[VEOL2];
15275a212a6Shibler htios.c_cc[HPUXVSWTCH] = 0;
153a807ce0aShibler #if 1
154a807ce0aShibler /*
155a807ce0aShibler * XXX since VMIN and VTIME are not implemented,
156a807ce0aShibler * we need to return something reasonable.
157a807ce0aShibler * Otherwise a GETA/SETA combo would always put
158a807ce0aShibler * the tty in non-blocking mode (since VMIN == VTIME == 0).
159a807ce0aShibler */
160a807ce0aShibler if (fp->f_flag & FNONBLOCK) {
161a807ce0aShibler htios.c_cc[HPUXVMINS] = 0;
162a807ce0aShibler htios.c_cc[HPUXVTIMES] = 0;
163a807ce0aShibler } else {
164a807ce0aShibler htios.c_cc[HPUXVMINS] = 6;
165a807ce0aShibler htios.c_cc[HPUXVTIMES] = 1;
166a807ce0aShibler }
167a807ce0aShibler #else
16875a212a6Shibler htios.c_cc[HPUXVMINS] = tios.c_cc[VMIN];
16975a212a6Shibler htios.c_cc[HPUXVTIMES] = tios.c_cc[VTIME];
170a807ce0aShibler #endif
17175a212a6Shibler htios.c_cc[HPUXVSUSP] = tios.c_cc[VSUSP];
17275a212a6Shibler htios.c_cc[HPUXVSTART] = tios.c_cc[VSTART];
17375a212a6Shibler htios.c_cc[HPUXVSTOP] = tios.c_cc[VSTOP];
17475a212a6Shibler if (newi)
17575a212a6Shibler bcopy((char *)&htios, data, sizeof htios);
17675a212a6Shibler else
17775a212a6Shibler termiostotermio(&htios, (struct hpuxtermio *)data);
178ec04308bSmckusick break;
179ec04308bSmckusick
18075a212a6Shibler case HPUXTCSETATTR:
18175a212a6Shibler case HPUXTCSETATTRD:
18275a212a6Shibler case HPUXTCSETATTRF:
18375a212a6Shibler newi = 1;
18475a212a6Shibler /* fall into ... */
185ec04308bSmckusick case HPUXTCSETA:
186ec04308bSmckusick case HPUXTCSETAW:
187ec04308bSmckusick case HPUXTCSETAF:
1887a0049f0Shibler /*
1897a0049f0Shibler * Get old characteristics and determine if we are a tty.
1907a0049f0Shibler */
191de3baf12Skarels if (error = (*ioctlrout)(fp, TIOCGETA, (caddr_t)&tios, p))
192ec04308bSmckusick break;
193bd14e74fShibler if (newi)
194bd14e74fShibler bcopy(data, (char *)&htios, sizeof htios);
195bd14e74fShibler else
196bd14e74fShibler termiototermios((struct termio *)data, &htios, &tios);
1977a0049f0Shibler /*
1987a0049f0Shibler * Set iflag.
1997a0049f0Shibler * Same through ICRNL, no HP-UX equiv for IMAXBEL
2007a0049f0Shibler */
2017a0049f0Shibler tios.c_iflag &= ~(IXON|IXOFF|IXANY|0x1ff);
20275a212a6Shibler tios.c_iflag |= htios.c_iflag & 0x1ff;
20375a212a6Shibler if (htios.c_iflag & TIO_IXON)
2047a0049f0Shibler tios.c_iflag |= IXON;
20575a212a6Shibler if (htios.c_iflag & TIO_IXOFF)
2067a0049f0Shibler tios.c_iflag |= IXOFF;
20775a212a6Shibler if (htios.c_iflag & TIO_IXANY)
2087a0049f0Shibler tios.c_iflag |= IXANY;
2097a0049f0Shibler /*
2107a0049f0Shibler * Set oflag.
2117a0049f0Shibler * No HP-UX equiv for ONOEOT
2127a0049f0Shibler */
2137a0049f0Shibler tios.c_oflag &= ~(OPOST|ONLCR|OXTABS);
21475a212a6Shibler if (htios.c_oflag & TIO_OPOST)
2157a0049f0Shibler tios.c_oflag |= OPOST;
21675a212a6Shibler if (htios.c_oflag & TIO_ONLCR)
2177a0049f0Shibler tios.c_oflag |= ONLCR;
21875a212a6Shibler if (htios.c_oflag & TIO_TAB3)
2197a0049f0Shibler tios.c_oflag |= OXTABS;
2207a0049f0Shibler /*
2217a0049f0Shibler * Set cflag.
2227a0049f0Shibler * No HP-UX equiv for CCTS_OFLOW/CCTS_IFLOW/MDMBUF
2237a0049f0Shibler */
2247a0049f0Shibler tios.c_cflag &=
2257a0049f0Shibler ~(CSIZE|CSTOPB|CREAD|PARENB|PARODD|HUPCL|CLOCAL);
22675a212a6Shibler switch (htios.c_cflag & TIO_CSIZE) {
2277a0049f0Shibler case TIO_CS5:
2287a0049f0Shibler tios.c_cflag |= CS5; break;
2297a0049f0Shibler case TIO_CS6:
2307a0049f0Shibler tios.c_cflag |= CS6; break;
2317a0049f0Shibler case TIO_CS7:
2327a0049f0Shibler tios.c_cflag |= CS7; break;
2337a0049f0Shibler case TIO_CS8:
2347a0049f0Shibler tios.c_cflag |= CS8; break;
235ec04308bSmckusick }
23675a212a6Shibler if (htios.c_cflag & TIO_CSTOPB)
2377a0049f0Shibler tios.c_cflag |= CSTOPB;
23875a212a6Shibler if (htios.c_cflag & TIO_CREAD)
2397a0049f0Shibler tios.c_cflag |= CREAD;
24075a212a6Shibler if (htios.c_cflag & TIO_PARENB)
2417a0049f0Shibler tios.c_cflag |= PARENB;
24275a212a6Shibler if (htios.c_cflag & TIO_PARODD)
2437a0049f0Shibler tios.c_cflag |= PARODD;
24475a212a6Shibler if (htios.c_cflag & TIO_HUPCL)
2457a0049f0Shibler tios.c_cflag |= HUPCL;
24675a212a6Shibler if (htios.c_cflag & TIO_CLOCAL)
2477a0049f0Shibler tios.c_cflag |= CLOCAL;
2487a0049f0Shibler /*
2497a0049f0Shibler * Set lflag.
2507a0049f0Shibler * No HP-UX equiv for ECHOKE/ECHOPRT/ECHOCTL
2517a0049f0Shibler * IEXTEN treated as part of ICANON
2527a0049f0Shibler */
2537a0049f0Shibler tios.c_lflag &= ~(ECHOE|ECHOK|ECHO|ISIG|ICANON|IEXTEN|NOFLSH);
25475a212a6Shibler if (htios.c_lflag & TIO_ECHOE)
2557a0049f0Shibler tios.c_lflag |= ECHOE;
25675a212a6Shibler if (htios.c_lflag & TIO_ECHOK)
2577a0049f0Shibler tios.c_lflag |= ECHOK;
25875a212a6Shibler if (htios.c_lflag & TIO_ECHO)
2597a0049f0Shibler tios.c_lflag |= ECHO;
26075a212a6Shibler if (htios.c_lflag & TIO_ECHONL)
2617a0049f0Shibler tios.c_lflag |= ECHONL;
26275a212a6Shibler if (htios.c_lflag & TIO_ISIG)
2637a0049f0Shibler tios.c_lflag |= ISIG;
26475a212a6Shibler if (htios.c_lflag & TIO_ICANON)
2657a0049f0Shibler tios.c_lflag |= (ICANON|IEXTEN);
26675a212a6Shibler if (htios.c_lflag & TIO_NOFLSH)
2677a0049f0Shibler tios.c_lflag |= NOFLSH;
2687a0049f0Shibler /*
2697a0049f0Shibler * Set editing chars.
27075a212a6Shibler * No HP-UX equivs of VWERASE/VREPRINT/VDSUSP/VLNEXT
27175a212a6Shibler * /VDISCARD/VSTATUS/VERASE2
2727a0049f0Shibler */
27375a212a6Shibler tios.c_cc[VINTR] = htios.c_cc[HPUXVINTR];
27475a212a6Shibler tios.c_cc[VQUIT] = htios.c_cc[HPUXVQUIT];
27575a212a6Shibler tios.c_cc[VERASE] = htios.c_cc[HPUXVERASE];
27675a212a6Shibler tios.c_cc[VKILL] = htios.c_cc[HPUXVKILL];
27775a212a6Shibler tios.c_cc[VEOF] = htios.c_cc[HPUXVEOF];
27875a212a6Shibler tios.c_cc[VEOL] = htios.c_cc[HPUXVEOL];
27975a212a6Shibler tios.c_cc[VEOL2] = htios.c_cc[HPUXVEOL2];
28075a212a6Shibler tios.c_cc[VMIN] = htios.c_cc[HPUXVMINS];
28175a212a6Shibler tios.c_cc[VTIME] = htios.c_cc[HPUXVTIMES];
28275a212a6Shibler tios.c_cc[VSUSP] = htios.c_cc[HPUXVSUSP];
28375a212a6Shibler tios.c_cc[VSTART] = htios.c_cc[HPUXVSTART];
28475a212a6Shibler tios.c_cc[VSTOP] = htios.c_cc[HPUXVSTOP];
28575a212a6Shibler
2867a0049f0Shibler /*
2877a0049f0Shibler * Set the new stuff
2887a0049f0Shibler */
28975a212a6Shibler if (com == HPUXTCSETA || com == HPUXTCSETATTR)
2907a0049f0Shibler com = TIOCSETA;
29175a212a6Shibler else if (com == HPUXTCSETAW || com == HPUXTCSETATTRD)
2927a0049f0Shibler com = TIOCSETAW;
2937a0049f0Shibler else
2947a0049f0Shibler com = TIOCSETAF;
295de3baf12Skarels error = (*ioctlrout)(fp, com, (caddr_t)&tios, p);
2967a0049f0Shibler if (error == 0) {
2977a0049f0Shibler /*
2987a0049f0Shibler * Set line discipline
2997a0049f0Shibler */
30075a212a6Shibler if (!newi) {
30175a212a6Shibler line = htios.c_reserved;
30275a212a6Shibler (void) (*ioctlrout)(fp, TIOCSETD,
30375a212a6Shibler (caddr_t)&line, p);
30475a212a6Shibler }
3057a0049f0Shibler /*
306a807ce0aShibler * Set non-blocking IO if VMIN == VTIME == 0, clear
307a807ce0aShibler * if not. Should handle the other cases as well.
308a807ce0aShibler * Note it isn't correct to just turn NBIO off like
309a807ce0aShibler * we do as it could be on as the result of a fcntl
310a807ce0aShibler * operation.
311a807ce0aShibler *
3127a0049f0Shibler * XXX - wouldn't need to do this at all if VMIN/VTIME
3137a0049f0Shibler * were implemented.
3147a0049f0Shibler */
315a807ce0aShibler {
316a807ce0aShibler struct hpuxfcntl_args {
317a807ce0aShibler int fdes, cmd, arg;
318a807ce0aShibler } args;
319a807ce0aShibler int flags, nbio;
320a807ce0aShibler
321a807ce0aShibler nbio = (htios.c_cc[HPUXVMINS] == 0 &&
322a807ce0aShibler htios.c_cc[HPUXVTIMES] == 0);
323a807ce0aShibler if (nbio && (fp->f_flag & FNONBLOCK) == 0 ||
324a807ce0aShibler !nbio && (fp->f_flag & FNONBLOCK)) {
325a807ce0aShibler args.fdes = fd;
326a807ce0aShibler args.cmd = F_GETFL;
327a807ce0aShibler args.arg = 0;
328a807ce0aShibler (void) hpuxfcntl(p, &args, &flags);
329a807ce0aShibler if (nbio)
330a807ce0aShibler flags |= HPUXNDELAY;
331de3baf12Skarels else
332a807ce0aShibler flags &= ~HPUXNDELAY;
333a807ce0aShibler args.cmd = F_SETFL;
334a807ce0aShibler args.arg = flags;
335a807ce0aShibler (void) hpuxfcntl(p, &args, &flags);
336a807ce0aShibler }
337a807ce0aShibler }
3387a0049f0Shibler }
339ec04308bSmckusick break;
340ec04308bSmckusick
341ec04308bSmckusick default:
3426c0841e1Shibler error = EINVAL;
343ec04308bSmckusick break;
344ec04308bSmckusick }
3456c0841e1Shibler return(error);
346ec04308bSmckusick }
347ec04308bSmckusick
348bd14e74fShibler termiototermios(tio, tios, bsdtios)
34975a212a6Shibler struct hpuxtermio *tio;
35075a212a6Shibler struct hpuxtermios *tios;
351bd14e74fShibler struct termios *bsdtios;
35275a212a6Shibler {
35375a212a6Shibler int i;
35475a212a6Shibler
35575a212a6Shibler bzero((char *)tios, sizeof *tios);
35675a212a6Shibler tios->c_iflag = tio->c_iflag;
35775a212a6Shibler tios->c_oflag = tio->c_oflag;
35875a212a6Shibler tios->c_cflag = tio->c_cflag;
35975a212a6Shibler tios->c_lflag = tio->c_lflag;
36075a212a6Shibler tios->c_reserved = tio->c_line;
36175a212a6Shibler for (i = 0; i <= HPUXVSWTCH; i++)
36275a212a6Shibler tios->c_cc[i] = tio->c_cc[i];
36375a212a6Shibler if (tios->c_lflag & TIO_ICANON) {
36475a212a6Shibler tios->c_cc[HPUXVEOF] = tio->c_cc[HPUXVEOF];
36575a212a6Shibler tios->c_cc[HPUXVEOL] = tio->c_cc[HPUXVEOL];
36673b3ed04Shibler tios->c_cc[HPUXVMINS] = 0;
36773b3ed04Shibler tios->c_cc[HPUXVTIMES] = 0;
36875a212a6Shibler } else {
36973b3ed04Shibler tios->c_cc[HPUXVEOF] = 0;
37073b3ed04Shibler tios->c_cc[HPUXVEOL] = 0;
37175a212a6Shibler tios->c_cc[HPUXVMINS] = tio->c_cc[HPUXVMIN];
37275a212a6Shibler tios->c_cc[HPUXVTIMES] = tio->c_cc[HPUXVTIME];
37375a212a6Shibler }
374bd14e74fShibler tios->c_cc[HPUXVSUSP] = bsdtios->c_cc[VSUSP];
375bd14e74fShibler tios->c_cc[HPUXVSTART] = bsdtios->c_cc[VSTART];
376bd14e74fShibler tios->c_cc[HPUXVSTOP] = bsdtios->c_cc[VSTOP];
37775a212a6Shibler }
37875a212a6Shibler
37975a212a6Shibler termiostotermio(tios, tio)
38075a212a6Shibler struct hpuxtermios *tios;
38175a212a6Shibler struct hpuxtermio *tio;
38275a212a6Shibler {
38375a212a6Shibler int i;
38475a212a6Shibler
38575a212a6Shibler tio->c_iflag = tios->c_iflag;
38675a212a6Shibler tio->c_oflag = tios->c_oflag;
38775a212a6Shibler tio->c_cflag = tios->c_cflag;
38875a212a6Shibler tio->c_lflag = tios->c_lflag;
38975a212a6Shibler tio->c_line = tios->c_reserved;
39075a212a6Shibler for (i = 0; i <= HPUXVSWTCH; i++)
39175a212a6Shibler tio->c_cc[i] = tios->c_cc[i];
392bd14e74fShibler if (tios->c_lflag & TIO_ICANON) {
39375a212a6Shibler tio->c_cc[HPUXVEOF] = tios->c_cc[HPUXVEOF];
39475a212a6Shibler tio->c_cc[HPUXVEOL] = tios->c_cc[HPUXVEOL];
39575a212a6Shibler } else {
39675a212a6Shibler tio->c_cc[HPUXVMIN] = tios->c_cc[HPUXVMINS];
39775a212a6Shibler tio->c_cc[HPUXVTIME] = tios->c_cc[HPUXVTIMES];
39875a212a6Shibler }
39975a212a6Shibler }
40075a212a6Shibler
bsdtohpuxbaud(bsdspeed)4017a0049f0Shibler bsdtohpuxbaud(bsdspeed)
4027a0049f0Shibler long bsdspeed;
4037a0049f0Shibler {
4047a0049f0Shibler switch (bsdspeed) {
4057a0049f0Shibler case B0: return(TIO_B0);
4067a0049f0Shibler case B50: return(TIO_B50);
4077a0049f0Shibler case B75: return(TIO_B75);
4087a0049f0Shibler case B110: return(TIO_B110);
4097a0049f0Shibler case B134: return(TIO_B134);
4107a0049f0Shibler case B150: return(TIO_B150);
4117a0049f0Shibler case B200: return(TIO_B200);
4127a0049f0Shibler case B300: return(TIO_B300);
4137a0049f0Shibler case B600: return(TIO_B600);
4147a0049f0Shibler case B1200: return(TIO_B1200);
4157a0049f0Shibler case B1800: return(TIO_B1800);
4167a0049f0Shibler case B2400: return(TIO_B2400);
4177a0049f0Shibler case B4800: return(TIO_B4800);
4187a0049f0Shibler case B9600: return(TIO_B9600);
4197a0049f0Shibler case B19200: return(TIO_B19200);
4207a0049f0Shibler case B38400: return(TIO_B38400);
4217a0049f0Shibler default: return(TIO_B0);
4227a0049f0Shibler }
4237a0049f0Shibler }
4247a0049f0Shibler
hpuxtobsdbaud(hpuxspeed)4257a0049f0Shibler hpuxtobsdbaud(hpuxspeed)
4267a0049f0Shibler int hpuxspeed;
4277a0049f0Shibler {
4287a0049f0Shibler static char hpuxtobsdbaudtab[32] = {
4297a0049f0Shibler B0, B50, B75, B110, B134, B150, B200, B300,
4307a0049f0Shibler B600, B0, B1200, B1800, B2400, B0, B4800, B0,
4317a0049f0Shibler B9600, B19200, B38400, B0, B0, B0, B0, B0,
4327a0049f0Shibler B0, B0, B0, B0, B0, B0, EXTA, EXTB
4337a0049f0Shibler };
4347a0049f0Shibler
4357a0049f0Shibler return(hpuxtobsdbaudtab[hpuxspeed & TIO_CBAUD]);
4367a0049f0Shibler }
4377a0049f0Shibler
43875a212a6Shibler #ifdef COMPAT_OHPUX
4393815b3eeShibler struct ohpuxsgtty_args {
440ec04308bSmckusick int fdes;
441ec04308bSmckusick caddr_t cmarg;
4423815b3eeShibler };
443*eeb57a89Scgd compat_43_hpuxgtty(p, uap, retval)
4443815b3eeShibler struct proc *p;
4453815b3eeShibler struct ohpuxsgtty_args *uap;
4466c0841e1Shibler int *retval;
4476c0841e1Shibler {
448ec04308bSmckusick
449e23b2b40Smckusick return (getsettty(p, uap->fdes, HPUXTIOCGETP, uap->cmarg));
450ec04308bSmckusick }
451ec04308bSmckusick
452*eeb57a89Scgd compat_43_hpuxstty(p, uap, retval)
4536c0841e1Shibler struct proc *p;
4543815b3eeShibler struct ohpuxsgtty_args *uap;
4556c0841e1Shibler int *retval;
4566c0841e1Shibler {
457ec04308bSmckusick
458e23b2b40Smckusick return (getsettty(p, uap->fdes, HPUXTIOCSETP, uap->cmarg));
459ec04308bSmckusick }
460ec04308bSmckusick
461ec04308bSmckusick /*
462ec04308bSmckusick * Simplified version of ioctl() for use by
463ec04308bSmckusick * gtty/stty and TIOCGETP/TIOCSETP.
464ec04308bSmckusick */
465e23b2b40Smckusick getsettty(p, fdes, com, cmarg)
466e23b2b40Smckusick struct proc *p;
467ec04308bSmckusick int fdes, com;
468ec04308bSmckusick caddr_t cmarg;
469ec04308bSmckusick {
470e23b2b40Smckusick register struct filedesc *fdp = p->p_fd;
471ec04308bSmckusick register struct file *fp;
472ec04308bSmckusick struct hpuxsgttyb hsb;
473ec04308bSmckusick struct sgttyb sb;
4746c0841e1Shibler int error;
475ec04308bSmckusick
476de3baf12Skarels if (((unsigned)fdes) >= fdp->fd_nfiles ||
477de3baf12Skarels (fp = fdp->fd_ofiles[fdes]) == NULL)
4786c0841e1Shibler return (EBADF);
4796c0841e1Shibler if ((fp->f_flag & (FREAD|FWRITE)) == 0)
4806c0841e1Shibler return (EBADF);
481ec04308bSmckusick if (com == HPUXTIOCSETP) {
4826c0841e1Shibler if (error = copyin(cmarg, (caddr_t)&hsb, sizeof hsb))
4836c0841e1Shibler return (error);
484ec04308bSmckusick sb.sg_ispeed = hsb.sg_ispeed;
485ec04308bSmckusick sb.sg_ospeed = hsb.sg_ospeed;
486ec04308bSmckusick sb.sg_erase = hsb.sg_erase;
487ec04308bSmckusick sb.sg_kill = hsb.sg_kill;
4886c0841e1Shibler sb.sg_flags = hsb.sg_flags & ~(V7_HUPCL|V7_XTABS|V7_NOAL);
4896c0841e1Shibler if (hsb.sg_flags & V7_XTABS)
4906c0841e1Shibler sb.sg_flags |= XTABS;
4916c0841e1Shibler if (hsb.sg_flags & V7_HUPCL)
492de3baf12Skarels (void)(*fp->f_ops->fo_ioctl)
493de3baf12Skarels (fp, TIOCHPCL, (caddr_t)0, p);
494ec04308bSmckusick com = TIOCSETP;
495ec04308bSmckusick } else {
496ec04308bSmckusick bzero((caddr_t)&hsb, sizeof hsb);
497ec04308bSmckusick com = TIOCGETP;
498ec04308bSmckusick }
499de3baf12Skarels error = (*fp->f_ops->fo_ioctl)(fp, com, (caddr_t)&sb, p);
5006c0841e1Shibler if (error == 0 && com == TIOCGETP) {
501ec04308bSmckusick hsb.sg_ispeed = sb.sg_ispeed;
502ec04308bSmckusick hsb.sg_ospeed = sb.sg_ospeed;
503ec04308bSmckusick hsb.sg_erase = sb.sg_erase;
504ec04308bSmckusick hsb.sg_kill = sb.sg_kill;
5056c0841e1Shibler hsb.sg_flags = sb.sg_flags & ~(V7_HUPCL|V7_XTABS|V7_NOAL);
5066c0841e1Shibler if (sb.sg_flags & XTABS)
5076c0841e1Shibler hsb.sg_flags |= V7_XTABS;
5086c0841e1Shibler error = copyout((caddr_t)&hsb, cmarg, sizeof hsb);
509ec04308bSmckusick }
5106c0841e1Shibler return (error);
511ec04308bSmckusick }
51275a212a6Shibler #endif
513ec04308bSmckusick #endif
514