|
|
1.1 root 1: /*
2: * Copyright (c) 1988 University of Utah.
3: * Copyright (c) 1990 The Regents of the University of California.
4: * All rights reserved.
5: *
6: * This code is derived from software contributed to Berkeley by
7: * the Systems Programming Group of the University of Utah Computer
8: * Science Department.
9: *
10: * Redistribution and use in source and binary forms, with or without
11: * modification, are permitted provided that the following conditions
12: * are met:
13: * 1. Redistributions of source code must retain the above copyright
14: * notice, this list of conditions and the following disclaimer.
15: * 2. Redistributions in binary form must reproduce the above copyright
16: * notice, this list of conditions and the following disclaimer in the
17: * documentation and/or other materials provided with the distribution.
18: * 3. All advertising materials mentioning features or use of this software
19: * must display the following acknowledgement:
20: * This product includes software developed by the University of
21: * California, Berkeley and its contributors.
22: * 4. Neither the name of the University nor the names of its contributors
23: * may be used to endorse or promote products derived from this software
24: * without specific prior written permission.
25: *
26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36: * SUCH DAMAGE.
37: *
38: * from: Utah $Hdr: hpux_tty.c 1.1 90/07/09$
39: *
1.1.1.2 ! root 40: * from: @(#)hpux_tty.c 7.9 (Berkeley) 5/30/91
! 41: * hpux_tty.c,v 1.2 1993/05/22 07:58:13 cgd Exp
1.1 root 42: */
43:
44: /*
45: * stty/gtty/termio emulation stuff
46: */
47: #ifdef HPUXCOMPAT
48:
49: #include "param.h"
50: #include "systm.h"
51: #include "filedesc.h"
52: #include "ioctl.h"
53: #include "tty.h"
54: #include "proc.h"
55: #include "file.h"
56: #include "conf.h"
57: #include "buf.h"
58: #include "kernel.h"
59:
60: #include "hpux.h"
61: #include "hpux_termio.h"
62:
63: /*
64: * Map BSD/POSIX style termios info to and from SYS5 style termio stuff.
65: */
66: hpuxtermio(fp, com, data, p)
67: struct file *fp;
68: caddr_t data;
69: struct proc *p;
70: {
71: struct termios tios;
72: int line, error, (*ioctlrout)();
73: register struct hpuxtermio *tiop;
74:
75: ioctlrout = fp->f_ops->fo_ioctl;
76: tiop = (struct hpuxtermio *)data;
77: switch (com) {
78: case HPUXTCGETA:
79: /*
80: * Get BSD terminal state
81: */
82: bzero(data, sizeof(struct hpuxtermio));
83: if (error = (*ioctlrout)(fp, TIOCGETA, (caddr_t)&tios, p))
84: break;
85: /*
86: * Set iflag.
87: * Same through ICRNL, no BSD equivs for IUCLC, IENQAK
88: */
89: tiop->c_iflag = tios.c_iflag & 0x1ff;
90: if (tios.c_iflag & IXON)
91: tiop->c_iflag |= TIO_IXON;
92: if (tios.c_iflag & IXOFF)
93: tiop->c_iflag |= TIO_IXOFF;
94: if (tios.c_iflag & IXANY)
95: tiop->c_iflag |= TIO_IXANY;
96: /*
97: * Set oflag.
98: * No BSD equivs for OLCUC/OCRNL/ONOCR/ONLRET/OFILL/OFDEL
99: * or any of the delays.
100: */
101: if (tios.c_oflag & OPOST)
102: tiop->c_oflag |= TIO_OPOST;
103: if (tios.c_oflag & ONLCR)
104: tiop->c_oflag |= TIO_ONLCR;
105: if (tios.c_oflag & OXTABS)
106: tiop->c_oflag |= TIO_TAB3;
107: /*
108: * Set cflag.
109: * Baud from ospeed, rest from cflag.
110: */
111: tiop->c_cflag = bsdtohpuxbaud(tios.c_ospeed);
112: switch (tios.c_cflag & CSIZE) {
113: case CS5:
114: tiop->c_cflag |= TIO_CS5; break;
115: case CS6:
116: tiop->c_cflag |= TIO_CS6; break;
117: case CS7:
118: tiop->c_cflag |= TIO_CS7; break;
119: case CS8:
120: tiop->c_cflag |= TIO_CS8; break;
121: }
122: if (tios.c_cflag & CSTOPB)
123: tiop->c_cflag |= TIO_CSTOPB;
124: if (tios.c_cflag & CREAD)
125: tiop->c_cflag |= TIO_CREAD;
126: if (tios.c_cflag & PARENB)
127: tiop->c_cflag |= TIO_PARENB;
128: if (tios.c_cflag & PARODD)
129: tiop->c_cflag |= TIO_PARODD;
130: if (tios.c_cflag & HUPCL)
131: tiop->c_cflag |= TIO_HUPCL;
132: if (tios.c_cflag & CLOCAL)
133: tiop->c_cflag |= TIO_CLOCAL;
134: /*
135: * Set lflag.
136: * No BSD equiv for XCASE.
137: */
138: if (tios.c_lflag & ECHOE)
139: tiop->c_lflag |= TIO_ECHOE;
140: if (tios.c_lflag & ECHOK)
141: tiop->c_lflag |= TIO_ECHOK;
142: if (tios.c_lflag & ECHO)
143: tiop->c_lflag |= TIO_ECHO;
144: if (tios.c_lflag & ECHONL)
145: tiop->c_lflag |= TIO_ECHONL;
146: if (tios.c_lflag & ISIG)
147: tiop->c_lflag |= TIO_ISIG;
148: if (tios.c_lflag & ICANON)
149: tiop->c_lflag |= TIO_ICANON;
150: if (tios.c_lflag & NOFLSH)
151: tiop->c_lflag |= TIO_NOFLSH;
152: /*
153: * Line discipline
154: */
155: line = 0;
156: (void) (*ioctlrout)(fp, TIOCGETD, (caddr_t)&line, p);
157: tiop->c_line = line;
158: /*
159: * Set editing chars
160: */
161: tiop->c_cc[HPUXVINTR] = tios.c_cc[VINTR];
162: tiop->c_cc[HPUXVQUIT] = tios.c_cc[VQUIT];
163: tiop->c_cc[HPUXVERASE] = tios.c_cc[VERASE];
164: tiop->c_cc[HPUXVKILL] = tios.c_cc[VKILL];
165: if (tiop->c_lflag & TIO_ICANON) {
166: tiop->c_cc[HPUXVEOF] = tios.c_cc[VEOF];
167: tiop->c_cc[HPUXVEOL] = tios.c_cc[VEOL];
168: } else {
169: tiop->c_cc[HPUXVMIN] = tios.c_cc[VMIN];
170: tiop->c_cc[HPUXVTIME] = tios.c_cc[VTIME];
171: }
172: break;
173:
174: case HPUXTCSETA:
175: case HPUXTCSETAW:
176: case HPUXTCSETAF:
177: /*
178: * Get old characteristics and determine if we are a tty.
179: */
180: if (error = (*ioctlrout)(fp, TIOCGETA, (caddr_t)&tios, p))
181: break;
182: /*
183: * Set iflag.
184: * Same through ICRNL, no HP-UX equiv for IMAXBEL
185: */
186: tios.c_iflag &= ~(IXON|IXOFF|IXANY|0x1ff);
187: tios.c_iflag |= tiop->c_iflag & 0x1ff;
188: if (tiop->c_iflag & TIO_IXON)
189: tios.c_iflag |= IXON;
190: if (tiop->c_iflag & TIO_IXOFF)
191: tios.c_iflag |= IXOFF;
192: if (tiop->c_iflag & TIO_IXANY)
193: tios.c_iflag |= IXANY;
194: /*
195: * Set oflag.
196: * No HP-UX equiv for ONOEOT
197: */
198: tios.c_oflag &= ~(OPOST|ONLCR|OXTABS);
199: if (tiop->c_oflag & TIO_OPOST)
200: tios.c_oflag |= OPOST;
201: if (tiop->c_oflag & TIO_ONLCR)
202: tios.c_oflag |= ONLCR;
203: if (tiop->c_oflag & TIO_TAB3)
204: tios.c_oflag |= OXTABS;
205: /*
206: * Set cflag.
207: * No HP-UX equiv for CCTS_OFLOW/CCTS_IFLOW/MDMBUF
208: */
209: tios.c_cflag &=
210: ~(CSIZE|CSTOPB|CREAD|PARENB|PARODD|HUPCL|CLOCAL);
211: switch (tiop->c_cflag & TIO_CSIZE) {
212: case TIO_CS5:
213: tios.c_cflag |= CS5; break;
214: case TIO_CS6:
215: tios.c_cflag |= CS6; break;
216: case TIO_CS7:
217: tios.c_cflag |= CS7; break;
218: case TIO_CS8:
219: tios.c_cflag |= CS8; break;
220: }
221: if (tiop->c_cflag & TIO_CSTOPB)
222: tios.c_cflag |= CSTOPB;
223: if (tiop->c_cflag & TIO_CREAD)
224: tios.c_cflag |= CREAD;
225: if (tiop->c_cflag & TIO_PARENB)
226: tios.c_cflag |= PARENB;
227: if (tiop->c_cflag & TIO_PARODD)
228: tios.c_cflag |= PARODD;
229: if (tiop->c_cflag & TIO_HUPCL)
230: tios.c_cflag |= HUPCL;
231: if (tiop->c_cflag & TIO_CLOCAL)
232: tios.c_cflag |= CLOCAL;
233: /*
234: * Set lflag.
235: * No HP-UX equiv for ECHOKE/ECHOPRT/ECHOCTL
236: * IEXTEN treated as part of ICANON
237: */
238: tios.c_lflag &= ~(ECHOE|ECHOK|ECHO|ISIG|ICANON|IEXTEN|NOFLSH);
239: if (tiop->c_lflag & TIO_ECHOE)
240: tios.c_lflag |= ECHOE;
241: if (tiop->c_lflag & TIO_ECHOK)
242: tios.c_lflag |= ECHOK;
243: if (tiop->c_lflag & TIO_ECHO)
244: tios.c_lflag |= ECHO;
245: if (tiop->c_lflag & TIO_ECHONL)
246: tios.c_lflag |= ECHONL;
247: if (tiop->c_lflag & TIO_ISIG)
248: tios.c_lflag |= ISIG;
249: if (tiop->c_lflag & TIO_ICANON)
250: tios.c_lflag |= (ICANON|IEXTEN);
251: if (tiop->c_lflag & TIO_NOFLSH)
252: tios.c_lflag |= NOFLSH;
253: /*
254: * Set editing chars.
255: * No HP-UX equivs of VEOL2/VWERASE/VREPRINT/VSUSP/VDSUSP
256: * VSTOP/VLNEXT/VDISCARD/VMIN/VTIME/VSTATUS/VERASE2
257: */
258: tios.c_cc[VINTR] = tiop->c_cc[HPUXVINTR];
259: tios.c_cc[VQUIT] = tiop->c_cc[HPUXVQUIT];
260: tios.c_cc[VERASE] = tiop->c_cc[HPUXVERASE];
261: tios.c_cc[VKILL] = tiop->c_cc[HPUXVKILL];
262: if (tios.c_lflag & ICANON) {
263: tios.c_cc[VEOF] = tiop->c_cc[HPUXVEOF];
264: tios.c_cc[VEOL] = tiop->c_cc[HPUXVEOL];
265: } else {
266: tios.c_cc[VMIN] = tiop->c_cc[HPUXVMIN];
267: tios.c_cc[VTIME] = tiop->c_cc[HPUXVTIME];
268: }
269: /*
270: * Set the new stuff
271: */
272: if (com == HPUXTCSETA)
273: com = TIOCSETA;
274: else if (com == HPUXTCSETAW)
275: com = TIOCSETAW;
276: else
277: com = TIOCSETAF;
278: error = (*ioctlrout)(fp, com, (caddr_t)&tios, p);
279: if (error == 0) {
280: /*
281: * Set line discipline
282: */
283: line = tiop->c_line;
284: (void) (*ioctlrout)(fp, TIOCSETD, (caddr_t)&line, p);
285: /*
286: * Set non-blocking IO if VMIN == VTIME == 0.
287: * Should handle the other cases as well. It also
288: * isn't correct to just turn it off as it could be
289: * on as the result of a fcntl operation.
290: * XXX - wouldn't need to do this at all if VMIN/VTIME
291: * were implemented.
292: */
293: line = (tiop->c_cc[HPUXVMIN] == 0 &&
294: tiop->c_cc[HPUXVTIME] == 0);
295: if (line)
296: fp->f_flag |= FNONBLOCK;
297: else
298: fp->f_flag &= ~FNONBLOCK;
299: (void) (*ioctlrout)(fp, FIONBIO, (caddr_t)&line, p);
300: }
301: break;
302:
303: default:
304: error = EINVAL;
305: break;
306: }
307: return(error);
308: }
309:
310: bsdtohpuxbaud(bsdspeed)
311: long bsdspeed;
312: {
313: switch (bsdspeed) {
314: case B0: return(TIO_B0);
315: case B50: return(TIO_B50);
316: case B75: return(TIO_B75);
317: case B110: return(TIO_B110);
318: case B134: return(TIO_B134);
319: case B150: return(TIO_B150);
320: case B200: return(TIO_B200);
321: case B300: return(TIO_B300);
322: case B600: return(TIO_B600);
323: case B1200: return(TIO_B1200);
324: case B1800: return(TIO_B1800);
325: case B2400: return(TIO_B2400);
326: case B4800: return(TIO_B4800);
327: case B9600: return(TIO_B9600);
328: case B19200: return(TIO_B19200);
329: case B38400: return(TIO_B38400);
330: default: return(TIO_B0);
331: }
332: }
333:
334: hpuxtobsdbaud(hpuxspeed)
335: int hpuxspeed;
336: {
337: static char hpuxtobsdbaudtab[32] = {
338: B0, B50, B75, B110, B134, B150, B200, B300,
339: B600, B0, B1200, B1800, B2400, B0, B4800, B0,
340: B9600, B19200, B38400, B0, B0, B0, B0, B0,
341: B0, B0, B0, B0, B0, B0, EXTA, EXTB
342: };
343:
344: return(hpuxtobsdbaudtab[hpuxspeed & TIO_CBAUD]);
345: }
346:
347: /* #ifdef COMPAT */
348: ohpuxgtty(p, uap, retval)
349: struct proc *p;
350: struct args {
351: int fdes;
352: caddr_t cmarg;
353: } *uap;
354: int *retval;
355: {
356:
357: return (getsettty(p, uap->fdes, HPUXTIOCGETP, uap->cmarg));
358: }
359:
360: ohpuxstty(p, uap, retval)
361: struct proc *p;
362: struct args {
363: int fdes;
364: caddr_t cmarg;
365: } *uap;
366: int *retval;
367: {
368:
369: return (getsettty(p, uap->fdes, HPUXTIOCSETP, uap->cmarg));
370: }
371:
372: /*
373: * Simplified version of ioctl() for use by
374: * gtty/stty and TIOCGETP/TIOCSETP.
375: */
376: getsettty(p, fdes, com, cmarg)
377: struct proc *p;
378: int fdes, com;
379: caddr_t cmarg;
380: {
381: register struct filedesc *fdp = p->p_fd;
382: register struct file *fp;
383: struct hpuxsgttyb hsb;
384: struct sgttyb sb;
385: int error;
386:
387: if (((unsigned)fdes) >= fdp->fd_nfiles ||
388: (fp = fdp->fd_ofiles[fdes]) == NULL)
389: return (EBADF);
390: if ((fp->f_flag & (FREAD|FWRITE)) == 0)
391: return (EBADF);
392: if (com == HPUXTIOCSETP) {
393: if (error = copyin(cmarg, (caddr_t)&hsb, sizeof hsb))
394: return (error);
395: sb.sg_ispeed = hsb.sg_ispeed;
396: sb.sg_ospeed = hsb.sg_ospeed;
397: sb.sg_erase = hsb.sg_erase;
398: sb.sg_kill = hsb.sg_kill;
399: sb.sg_flags = hsb.sg_flags & ~(V7_HUPCL|V7_XTABS|V7_NOAL);
400: if (hsb.sg_flags & V7_XTABS)
401: sb.sg_flags |= XTABS;
402: if (hsb.sg_flags & V7_HUPCL)
403: (void)(*fp->f_ops->fo_ioctl)
404: (fp, TIOCHPCL, (caddr_t)0, p);
405: com = TIOCSETP;
406: } else {
407: bzero((caddr_t)&hsb, sizeof hsb);
408: com = TIOCGETP;
409: }
410: error = (*fp->f_ops->fo_ioctl)(fp, com, (caddr_t)&sb, p);
411: if (error == 0 && com == TIOCGETP) {
412: hsb.sg_ispeed = sb.sg_ispeed;
413: hsb.sg_ospeed = sb.sg_ospeed;
414: hsb.sg_erase = sb.sg_erase;
415: hsb.sg_kill = sb.sg_kill;
416: hsb.sg_flags = sb.sg_flags & ~(V7_HUPCL|V7_XTABS|V7_NOAL);
417: if (sb.sg_flags & XTABS)
418: hsb.sg_flags |= V7_XTABS;
419: error = copyout((caddr_t)&hsb, cmarg, sizeof hsb);
420: }
421: return (error);
422: }
423: /* #endif */
424: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.