]> git.saurik.com Git - apple/xnu.git/blame - bsd/kern/tty_compat.c
xnu-792.2.4.tar.gz
[apple/xnu.git] / bsd / kern / tty_compat.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
e5568f75
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
1c79356b 11 *
e5568f75
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
e5568f75
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/* Copyright (c) 1997 Apple Computer, Inc. All Rights Reserved */
23/*-
24 * Copyright (c) 1982, 1986, 1991, 1993
25 * The Regents of the University of California. All rights reserved.
26 *
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
29 * are met:
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 * @(#)tty_compat.c 8.1 (Berkeley) 6/10/93
56 */
57
58/*
59 * mapping routines for old line discipline (yuck)
60 */
61
62#include <sys/param.h>
63#include <sys/systm.h>
64#include <sys/ioctl.h>
91447636 65#include <sys/proc_internal.h>
1c79356b
A
66#include <sys/tty.h>
67#include <sys/termios.h>
91447636 68#include <sys/file_internal.h>
1c79356b
A
69#include <sys/conf.h>
70#include <sys/kernel.h>
71#include <sys/sysctl.h>
72#include <sys/syslog.h>
73
91447636
A
74/* NeXT Move define down here cause COMPAT_43_TTY not valid earlier */
75#if COMPAT_43_TTY || defined(COMPAT_SUNOS)
1c79356b 76
91447636
A
77static int ttcompatgetflags(struct tty *tp);
78static void ttcompatsetflags(struct tty *tp, struct termios *t);
79static void ttcompatsetlflags(struct tty *tp, struct termios *t);
80static int ttcompatspeedtab(int speed, struct speedtab *table);
1c79356b 81
91447636
A
82/*
83 * These two tables encode baud rate to speed code and speed code to
84 * baud rate information. They are a mapping between the <sys/termios.h>
85 * baud rate constants and the <sys/ttydev.h> baud rate constants. We
86 * cannot use those constants directly here because they occupy the same
87 * name space.
88 */
1c79356b
A
89static struct speedtab compatspeeds[] = {
90#define MAX_SPEED 17
91 { 115200, 17 },
92 { 57600, 16 },
93 { 38400, 15 },
94 { 19200, 14 },
95 { 9600, 13 },
96 { 4800, 12 },
97 { 2400, 11 },
98 { 1800, 10 },
99 { 1200, 9 },
100 { 600, 8 },
101 { 300, 7 },
102 { 200, 6 },
103 { 150, 5 },
104 { 134, 4 },
105 { 110, 3 },
106 { 75, 2 },
107 { 50, 1 },
108 { 0, 0 },
109 { -1, -1 },
110};
111static int compatspcodes[] = {
112 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
113 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200,
114};
115
91447636
A
116/*
117 * ttcompatspeedtab
118 *
119 * Description: Given a baud rate value as an integer, and a speed table,
120 * convert the baud rate to a speed code, according to the
121 * contents of the table. This effectively changes termios.h
122 * baud rate values into ttydev.h baud rate codes.
123 *
124 * Parameters: int speed Baud rate, as an integer
125 * struct speedtab *table Baud rate table to speed code table
126 *
127 * Returns: 1 B50 speed code; returned if we can
128 * not find an answer in the table.
129 * 0 If a 0 was requested in order to
130 * trigger a hangup (250ms of line
131 * silence, per Bell 103C standard).
132 * * A speed code matching the requested
133 * baud rate (potentially rounded down,
134 * if there is no exact match).
135 *
136 * Notes: This function is used for TIOCGETP, TIOCSETP, and TIOCSETN.
137 */
1c79356b 138static int
91447636 139ttcompatspeedtab(int speed, struct speedtab *table)
1c79356b
A
140{
141 if (speed == 0)
142 return (0); /* hangup */
143 for ( ; table->sp_speed > 0; table++)
144 if (table->sp_speed <= speed) /* nearest one, rounded down */
145 return (table->sp_code);
146 return (1); /* 50, min and not hangup */
147}
148
91447636
A
149/*
150 * ttsetcompat
151 *
152 * Description: Convert backward compatability set command arguments as
153 * follows:
154 *
155 * TIOCSETP -> TIOSETAF
156 * TIOCSETN -> TIOCSETA
157 * TIOCSETC -> TIOCSETA
158 * TIOCSLTC -> TIOCSETA
159 * TIOCLBIS -> TIOCSETA
160 * TIOCLBIC -> TIOCSETA
161 * TIOCLSET -> TIOCSETA
162 *
163 * The converted command argument and potentially modified 'term'
164 * argument are returned to the caller, which will then call ttioctl(),
165 * if this function returns successfully.
166 *
167 * Parameters struct tty *tp The tty on which the operation is
168 * being performed.
169 * u_long *com A pointer to the terminal input/output
170 * command being requested; its contents
171 * will be modified per the table above,
172 * on a non-error return.
173 * caddr_t data Command specific parameter data; this
174 * data is read but not modified.
175 * struct termios *term A local stack termios structure from
176 * ttcompat(), whose contents are to be
177 * modified based on *com and *data.
178 *
179 * Returns: EINVAL An input speed or output speed is
180 * outside the allowable range for a
181 * TIOCSETP or TIOCSETN command.
182 * 0 All other cases return 0.
183 *
184 * Notes: This function may modify the contents of the tp->t_flags
185 * field in a successful call to TIOCSETP, TIOCSETN, TIOCLBIS,
186 * TIOCLBIC, or TIOCLSET.
187 *
188 * All other tp fields will remain unmodifed, since the struct
189 * termious is a local stack copy from ttcompat(), and not the
190 * real thing. A subsequent call to ttioctl() in ttcompat(),
191 * however, may result in subsequent changes.
192 */
1c79356b 193__private_extern__ int
91447636 194ttsetcompat(struct tty *tp, u_long *com, caddr_t data, struct termios *term)
1c79356b
A
195{
196 switch (*com) {
197 case TIOCSETP:
91447636
A
198 /*
199 * Wait for all characters queued for output to drain, then
200 * Discard all characters queued for input, and then set
201 * the input and output speeds and device flags, per the
202 * contents of the struct sgttyb that 'data' points to.
203 */
204 case TIOCSETN:
205 /*
206 * Same as TIOCSETP, but the output is not drained, and any
207 * pending input is not discarded.
208 */
209 {
1c79356b
A
210 register struct sgttyb *sg = (struct sgttyb *)data;
211 int speed;
212
213 if ((speed = sg->sg_ispeed) > MAX_SPEED || speed < 0)
214 return(EINVAL);
215 else if (speed != ttcompatspeedtab(tp->t_ispeed, compatspeeds))
216 term->c_ispeed = compatspcodes[speed];
217 else
218 term->c_ispeed = tp->t_ispeed;
219 if ((speed = sg->sg_ospeed) > MAX_SPEED || speed < 0)
220 return(EINVAL);
221 else if (speed != ttcompatspeedtab(tp->t_ospeed, compatspeeds))
222 term->c_ospeed = compatspcodes[speed];
223 else
224 term->c_ospeed = tp->t_ospeed;
225 term->c_cc[VERASE] = sg->sg_erase;
226 term->c_cc[VKILL] = sg->sg_kill;
227 tp->t_flags = (tp->t_flags&0xffff0000) | (sg->sg_flags&0xffff);
228 ttcompatsetflags(tp, term);
229 *com = (*com == TIOCSETP) ? TIOCSETAF : TIOCSETA;
230 break;
231 }
91447636
A
232 case TIOCSETC:
233 /*
234 * Set the terminal control characters per the contents of
235 * the struct tchars that 'data' points to.
236 */
237 {
1c79356b
A
238 struct tchars *tc = (struct tchars *)data;
239 register cc_t *cc;
240
241 cc = term->c_cc;
242 cc[VINTR] = tc->t_intrc;
243 cc[VQUIT] = tc->t_quitc;
244 cc[VSTART] = tc->t_startc;
245 cc[VSTOP] = tc->t_stopc;
246 cc[VEOF] = tc->t_eofc;
247 cc[VEOL] = tc->t_brkc;
248 if (tc->t_brkc == -1)
249 cc[VEOL2] = _POSIX_VDISABLE;
250 *com = TIOCSETA;
251 break;
252 }
91447636
A
253 case TIOCSLTC:
254 /*
255 * Set the terminal control characters per the contents of
256 * the struct ltchars that 'data' points to.
257 */
258 {
1c79356b
A
259 struct ltchars *ltc = (struct ltchars *)data;
260 register cc_t *cc;
261
262 cc = term->c_cc;
263 cc[VSUSP] = ltc->t_suspc;
264 cc[VDSUSP] = ltc->t_dsuspc;
265 cc[VREPRINT] = ltc->t_rprntc;
266 cc[VDISCARD] = ltc->t_flushc;
267 cc[VWERASE] = ltc->t_werasc;
268 cc[VLNEXT] = ltc->t_lnextc;
269 *com = TIOCSETA;
270 break;
271 }
272 case TIOCLBIS:
91447636
A
273 /*
274 * Set the bits in the terminal state local flags word
275 * (16 bits) for the terminal to the current bits OR
276 * those in the 16 bit value pointed to by 'data'.
277 */
1c79356b 278 case TIOCLBIC:
91447636
A
279 /*
280 * Clear the bits in the terminal state local flags word
281 * for the terminal to the current bits AND those bits NOT
282 * in the 16 bit value pointed to by 'data'.
283 */
1c79356b 284 case TIOCLSET:
91447636
A
285 /*
286 * Set the terminal state local flags word to exactly those
287 * bits that correspond to the 16 bit value pointed to by
288 * 'data'.
289 */
1c79356b
A
290 if (*com == TIOCLSET)
291 tp->t_flags = (tp->t_flags&0xffff) | *(int *)data<<16;
292 else {
293 tp->t_flags =
294 (ttcompatgetflags(tp)&0xffff0000)|(tp->t_flags&0xffff);
295 if (*com == TIOCLBIS)
296 tp->t_flags |= *(int *)data<<16;
297 else
298 tp->t_flags &= ~(*(int *)data<<16);
299 }
300 ttcompatsetlflags(tp, term);
301 *com = TIOCSETA;
302 break;
303 }
304 return 0;
305}
306
91447636
A
307/*
308 * ttcompat
309 *
310 * Description: For 'set' commands, convert the command and arguments as
311 * necessary, and call ttioctl(), returning the result as
312 * our result; for 'get' commands, obtain the requested data
313 * from the appropriate source, and return it in the expected
314 * format. If the command is not recognized, return EINVAL.
315 *
316 * Parameters struct tty *tp The tty on which the operation is
317 * being performed.
318 * u_long com The terminal input/output command
319 * being requested.
320 * caddr_t data The pointer to the user data argument
321 * provided with the command.
322 * int flag The file open flags (e.g. FREAD).
323 * struct proc *p The current process pointer for the
324 * operation.
325 *
326 * Returns: 0 Most 'get' operations can't fail, and
327 * therefore return this.
328 * ENOTTY TIOCGSID may return this when you
329 * attempt to get the session ID for a
330 * terminal with no associated session,
331 * or for which there is a session, but
332 * no session leader.
333 * EIOCTL If the command cannot be handled at
334 * this layer, this will be returned.
335 * * Any value returned by ttioctl(), if a
336 * set command is requested.
337 *
338 * NOTES: The process pointer may be a proxy on whose behalf we are
339 * operating, so it is not safe to simply use current_process()
340 * instead.
341 */
1c79356b 342/*ARGSUSED*/
1c79356b 343__private_extern__ int
91447636 344ttcompat(struct tty *tp, u_long com, caddr_t data, int flag, struct proc *p)
1c79356b
A
345{
346 switch (com) {
347 case TIOCSETP:
348 case TIOCSETN:
349 case TIOCSETC:
350 case TIOCSLTC:
351 case TIOCLBIS:
352 case TIOCLBIC:
91447636
A
353 case TIOCLSET:
354 /*
355 * See ttsetcompat() for a full description of these command
356 * values and their meanings.
357 */
358 {
1c79356b
A
359 struct termios term;
360 int error;
361
362 term = tp->t_termios;
363 if ((error = ttsetcompat(tp, &com, data, &term)) != 0)
364 return error;
1c79356b 365 return ttioctl(tp, com, (caddr_t) &term, flag, p);
1c79356b 366 }
91447636
A
367 case TIOCGETP:
368 /*
369 * Get the current input and output speeds, and device
370 * flags, into the structure pointed to by 'data'.
371 */
372 {
1c79356b
A
373 register struct sgttyb *sg = (struct sgttyb *)data;
374 register cc_t *cc = tp->t_cc;
375
376 sg->sg_ospeed = ttcompatspeedtab(tp->t_ospeed, compatspeeds);
377 if (tp->t_ispeed == 0)
378 sg->sg_ispeed = sg->sg_ospeed;
379 else
380 sg->sg_ispeed = ttcompatspeedtab(tp->t_ispeed, compatspeeds);
381 sg->sg_erase = cc[VERASE];
382 sg->sg_kill = cc[VKILL];
383 sg->sg_flags = tp->t_flags = ttcompatgetflags(tp);
384 break;
385 }
91447636
A
386 case TIOCGETC:
387 /*
388 * Get the terminal control characters into the struct
389 * tchars that 'data' points to.
390 */
391 {
1c79356b
A
392 struct tchars *tc = (struct tchars *)data;
393 register cc_t *cc = tp->t_cc;
394
395 tc->t_intrc = cc[VINTR];
396 tc->t_quitc = cc[VQUIT];
397 tc->t_startc = cc[VSTART];
398 tc->t_stopc = cc[VSTOP];
399 tc->t_eofc = cc[VEOF];
400 tc->t_brkc = cc[VEOL];
401 break;
402 }
91447636
A
403 case TIOCGLTC:
404 /*
405 * Get the terminal control characters into the struct
406 * ltchars that 'data' points to.
407 */
408 {
1c79356b
A
409 struct ltchars *ltc = (struct ltchars *)data;
410 register cc_t *cc = tp->t_cc;
411
412 ltc->t_suspc = cc[VSUSP];
413 ltc->t_dsuspc = cc[VDSUSP];
414 ltc->t_rprntc = cc[VREPRINT];
415 ltc->t_flushc = cc[VDISCARD];
416 ltc->t_werasc = cc[VWERASE];
417 ltc->t_lnextc = cc[VLNEXT];
418 break;
419 }
420 case TIOCLGET:
91447636
A
421 /*
422 * Get the terminal state local flags word into the 16 bit
423 * value pointed to by 'data'.
424 */
1c79356b
A
425 tp->t_flags =
426 (ttcompatgetflags(tp) & 0xffff0000UL)
427 | (tp->t_flags & 0xffff);
428 *(int *)data = tp->t_flags>>16;
1c79356b
A
429 break;
430
431 case OTIOCGETD:
91447636
A
432 /*
433 * Get the current line discipline into the int pointed to
434 * by 'data'.
435 */
1c79356b
A
436 *(int *)data = tp->t_line ? tp->t_line : 2;
437 break;
438
91447636
A
439 case OTIOCSETD:
440 /*
441 * Set the current line discipline based on the value of the
442 * int pointed to by 'data'.
443 */
444 {
1c79356b
A
445 int ldisczero = 0;
446
447 return (ttioctl(tp, TIOCSETD,
448 *(int *)data == 2 ? (caddr_t)&ldisczero : data, flag, p));
449 }
450
451 case OTIOCCONS:
91447636
A
452 /*
453 * Become the console device.
454 */
1c79356b
A
455 *(int *)data = 1;
456 return (ttioctl(tp, TIOCCONS, data, flag, p));
457
458 case TIOCGSID:
91447636
A
459 /*
460 * Get the current session ID (controlling process' PID).
461 */
1c79356b
A
462 if (tp->t_session == NULL)
463 return ENOTTY;
464
465 if (tp->t_session->s_leader == NULL)
466 return ENOTTY;
467
468 *(int *) data = tp->t_session->s_leader->p_pid;
469 break;
1c79356b
A
470
471 default:
91447636
A
472 /*
473 * This ioctl is not handled at this layer.
474 */
475 return (ENOTTY);
1c79356b 476 }
91447636
A
477
478 /*
479 * Successful 'get' operation.
480 */
1c79356b
A
481 return (0);
482}
483
91447636
A
484/*
485 * ttcompatgetflags
486 *
487 * Description: Get the terminal state local flags, device flags, and current
488 * speed code for the device (all 32 bits are returned).
489 *
490 * Parameters struct tty *tp The tty on which the operation is
491 * being performed.
492 *
493 * Returns: * Integer value corresponding to the
494 * current terminal state local flags
495 * word.
496 *
497 * Notes: Caller is responsible for breaking these bits back out into
498 * separate 16 bit filelds, if that's what was actually desired.
499 */
1c79356b 500static int
91447636 501ttcompatgetflags(struct tty *tp)
1c79356b
A
502{
503 register tcflag_t iflag = tp->t_iflag;
504 register tcflag_t lflag = tp->t_lflag;
505 register tcflag_t oflag = tp->t_oflag;
506 register tcflag_t cflag = tp->t_cflag;
91447636 507 register int flags = 0;
1c79356b
A
508
509 if (iflag&IXOFF)
510 flags |= TANDEM;
511 if (iflag&ICRNL || oflag&ONLCR)
512 flags |= CRMOD;
513 if ((cflag&CSIZE) == CS8) {
514 flags |= PASS8;
515 if (iflag&ISTRIP)
516 flags |= ANYP;
517 }
518 else if (cflag&PARENB) {
519 if (iflag&INPCK) {
520 if (cflag&PARODD)
521 flags |= ODDP;
522 else
523 flags |= EVENP;
524 } else
525 flags |= EVENP | ODDP;
526 }
527
528 if ((lflag&ICANON) == 0) {
529 /* fudge */
530 if (iflag&(INPCK|ISTRIP|IXON) || lflag&(IEXTEN|ISIG)
91447636 531 || (cflag&(CSIZE|PARENB)) != CS8)
1c79356b
A
532 flags |= CBREAK;
533 else
534 flags |= RAW;
535 }
91447636 536 if (!(flags&RAW) && !(oflag&OPOST) && (cflag&(CSIZE|PARENB)) == CS8)
1c79356b
A
537 flags |= LITOUT;
538 if (cflag&MDMBUF)
539 flags |= MDMBUF;
540 if ((cflag&HUPCL) == 0)
541 flags |= NOHANG;
542 if (oflag&OXTABS)
543 flags |= XTABS;
544 if (lflag&ECHOE)
545 flags |= CRTERA|CRTBS;
546 if (lflag&ECHOKE)
547 flags |= CRTKIL|CRTBS;
548 if (lflag&ECHOPRT)
549 flags |= PRTERA;
550 if (lflag&ECHOCTL)
551 flags |= CTLECH;
552 if ((iflag&IXANY) == 0)
553 flags |= DECCTQ;
554 flags |= lflag&(ECHO|TOSTOP|FLUSHO|PENDIN|NOFLSH);
1c79356b
A
555 return (flags);
556}
557
91447636
A
558/*
559 * ttcompatsetflags
560 *
561 * Description: Given a set of compatability flags, convert the compatability
562 * flags in the terminal flags fields into canonical flags in the
563 * provided termios struct.
564 *
565 * Parameters: struct tty *tp The tty on which the operation is
566 * being performed.
567 * struct termios *t The termios structure into which to
568 * return the converted flags.
569 *
570 * Returns: void (implicit: *t, modified)
571 */
1c79356b 572static void
91447636 573ttcompatsetflags(struct tty *tp, struct termios *t)
1c79356b 574{
91447636 575 register int flags = tp->t_flags;
1c79356b
A
576 register tcflag_t iflag = t->c_iflag;
577 register tcflag_t oflag = t->c_oflag;
578 register tcflag_t lflag = t->c_lflag;
579 register tcflag_t cflag = t->c_cflag;
580
581 if (flags & RAW) {
582 iflag = IGNBRK;
583 lflag &= ~(ECHOCTL|ISIG|ICANON|IEXTEN);
584 } else {
585 iflag &= ~(PARMRK|IGNPAR|IGNCR|INLCR);
586 iflag |= BRKINT|IXON|IMAXBEL;
587 lflag |= ISIG|IEXTEN|ECHOCTL; /* XXX was echoctl on ? */
588 if (flags & XTABS)
589 oflag |= OXTABS;
590 else
591 oflag &= ~OXTABS;
592 if (flags & CBREAK)
593 lflag &= ~ICANON;
594 else
595 lflag |= ICANON;
596 if (flags&CRMOD) {
597 iflag |= ICRNL;
598 oflag |= ONLCR;
599 } else {
600 iflag &= ~ICRNL;
601 oflag &= ~ONLCR;
602 }
603 }
604 if (flags&ECHO)
605 lflag |= ECHO;
606 else
607 lflag &= ~ECHO;
608
609 cflag &= ~(CSIZE|PARENB);
610 if (flags&(RAW|LITOUT|PASS8)) {
611 cflag |= CS8;
612 if (!(flags&(RAW|PASS8))
613 || (flags&(RAW|PASS8|ANYP)) == (PASS8|ANYP))
614 iflag |= ISTRIP;
615 else
616 iflag &= ~ISTRIP;
617 if (flags&(RAW|LITOUT))
618 oflag &= ~OPOST;
619 else
620 oflag |= OPOST;
621 } else {
622 cflag |= CS7|PARENB;
623 iflag |= ISTRIP;
624 oflag |= OPOST;
625 }
626 /* XXX don't set INPCK if RAW or PASS8? */
627 if ((flags&(EVENP|ODDP)) == EVENP) {
628 iflag |= INPCK;
629 cflag &= ~PARODD;
630 } else if ((flags&(EVENP|ODDP)) == ODDP) {
631 iflag |= INPCK;
632 cflag |= PARODD;
633 } else
634 iflag &= ~INPCK;
635 if (flags&TANDEM)
636 iflag |= IXOFF;
637 else
638 iflag &= ~IXOFF;
639 if ((flags&DECCTQ) == 0)
640 iflag |= IXANY;
641 else
642 iflag &= ~IXANY;
643 t->c_iflag = iflag;
644 t->c_oflag = oflag;
645 t->c_lflag = lflag;
646 t->c_cflag = cflag;
647}
648
91447636
A
649/*
650 * ttcompatsetlflags
651 *
652 * Description: Given a set of compatability terminal state local flags,
653 * convert the compatability flags in the terminal flags
654 * fields into canonical flags in the provided termios struct.
655 *
656 * Parameters: struct tty *tp The tty on which the operation is
657 * being performed.
658 * struct termios *t The termios structure into which to
659 * return the converted local flags.
660 *
661 * Returns: void (implicit: *t, modified)
662 */
1c79356b 663static void
91447636 664ttcompatsetlflags(struct tty *tp, struct termios *t)
1c79356b 665{
91447636 666 register int flags = tp->t_flags;
1c79356b
A
667 register tcflag_t iflag = t->c_iflag;
668 register tcflag_t oflag = t->c_oflag;
669 register tcflag_t lflag = t->c_lflag;
670 register tcflag_t cflag = t->c_cflag;
671
672 iflag &= ~(PARMRK|IGNPAR|IGNCR|INLCR);
673 if (flags&CRTERA)
674 lflag |= ECHOE;
675 else
676 lflag &= ~ECHOE;
677 if (flags&CRTKIL)
678 lflag |= ECHOKE;
679 else
680 lflag &= ~ECHOKE;
681 if (flags&PRTERA)
682 lflag |= ECHOPRT;
683 else
684 lflag &= ~ECHOPRT;
685 if (flags&CTLECH)
686 lflag |= ECHOCTL;
687 else
688 lflag &= ~ECHOCTL;
689 if (flags&TANDEM)
690 iflag |= IXOFF;
691 else
692 iflag &= ~IXOFF;
693 if ((flags&DECCTQ) == 0)
694 iflag |= IXANY;
695 else
696 iflag &= ~IXANY;
697 if (flags & MDMBUF)
698 cflag |= MDMBUF;
699 else
700 cflag &= ~MDMBUF;
701 if (flags&NOHANG)
702 cflag &= ~HUPCL;
703 else
704 cflag |= HUPCL;
705 lflag &= ~(TOSTOP|FLUSHO|PENDIN|NOFLSH);
706 lflag |= flags&(TOSTOP|FLUSHO|PENDIN|NOFLSH);
707
708 /*
709 * The next if-else statement is copied from above so don't bother
710 * checking it separately. We could avoid fiddlling with the
711 * character size if the mode is already RAW or if neither the
712 * LITOUT bit or the PASS8 bit is being changed, but the delta of
713 * the change is not available here and skipping the RAW case would
714 * make the code different from above.
715 */
716 cflag &= ~(CSIZE|PARENB);
717 if (flags&(RAW|LITOUT|PASS8)) {
718 cflag |= CS8;
719 if (!(flags&(RAW|PASS8))
720 || (flags&(RAW|PASS8|ANYP)) == (PASS8|ANYP))
721 iflag |= ISTRIP;
722 else
723 iflag &= ~ISTRIP;
724 if (flags&(RAW|LITOUT))
725 oflag &= ~OPOST;
726 else
727 oflag |= OPOST;
728 } else {
729 cflag |= CS7|PARENB;
730 iflag |= ISTRIP;
731 oflag |= OPOST;
732 }
733 t->c_iflag = iflag;
734 t->c_oflag = oflag;
735 t->c_lflag = lflag;
736 t->c_cflag = cflag;
737}
91447636 738#endif /* COMPAT_43_TTY || COMPAT_SUNOS */