/*
 * Copyright (c) 2000-2018 Apple Inc. All rights reserved.
 *
 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
 *
 * This file contains Original Code and/or Modifications of Original Code
 * as defined in and that are subject to the Apple Public Source License
 * Version 2.0 (the 'License'). You may not use this file except in
 * compliance with the License. The rights granted to you under the License
 * may not be used to create, or enable the creation or redistribution of,
 * unlawful or unlicensed copies of an Apple operating system, or to
 * circumvent, violate, or enable the circumvention or violation of, any
 * terms of an Apple operating system software license agreement.
 *
 * Please obtain a copy of the License at
 * http://www.opensource.apple.com/apsl/ and read it before using this file.
 *
 * The Original Code and all software distributed under the License are
 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
 * Please see the License for the specific language governing rights and
 * limitations under the License.
 *
 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
 */
/* Copyright (c) 1997 Apple Computer, Inc. All Rights Reserved */
/*-
 * Copyright (c) 1982, 1986, 1993
 *	The Regents of the University of California.  All rights reserved.
 * (c) UNIX System Laboratories, Inc.
 * All or some portions of this file are derived from material licensed
 * to the University of California by American Telephone and Telegraph
 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
 * the permission of UNIX System Laboratories, Inc.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by the University of
 *      California, Berkeley and its contributors.
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 *	@(#)tty.h	8.6 (Berkeley) 1/21/94
 */

#ifndef _SYS_TTY_H_
#define _SYS_TTY_H_

#include <sys/appleapiopts.h>
#include <sys/cdefs.h>
#include <sys/termios.h>
#include <sys/select.h>         /* For struct selinfo. */

struct tty;
struct clist;

/* These flags are kept in t_state. */
#define TS_SO_OLOWAT    0x00001         /* Wake up when output <= low water. */
#define TS_ASYNC        0x00002         /* Tty in async I/O mode. */
#define TS_BUSY         0x00004         /* Draining output. */
#define TS_CARR_ON      0x00008         /* Carrier is present. */
#define TS_FLUSH        0x00010         /* Outq has been flushed during DMA. */
#define TS_ISOPEN       0x00020         /* Open has completed. */
#define TS_TBLOCK       0x00040         /* Further input blocked. */
#define TS_TIMEOUT      0x00080         /* Wait for output char processing. */
#define TS_TTSTOP       0x00100         /* Output paused. */
#ifdef notyet
#define TS_WOPEN        0x00200         /* Open in progress. */
#endif
#define TS_XCLUDE       0x00400         /* Tty requires exclusivity. */

/* State for intra-line fancy editing work. */
#define TS_BKSL         0x00800         /* State for lowercase \ work. */
#define TS_CNTTB        0x01000         /* Counting tab width, ignore FLUSHO. */
#define TS_ERASE        0x02000         /* Within a \.../ for PRTRUB. */
#define TS_LNCH         0x04000         /* Next character is literal. */
#define TS_TYPEN        0x08000         /* Retyping suspended input (PENDIN). */
#define TS_LOCAL        (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)

/* Extras. */
#define TS_CAN_BYPASS_L_RINT 0x010000   /* Device in "raw" mode. */
#define TS_CONNECTED    0x020000        /* Connection open. */
#define TS_SNOOP        0x040000        /* Device is being snooped on. */
#define TS_SO_OCOMPLETE 0x080000        /* Wake up when output completes. */
#define TS_ZOMBIE       0x100000        /* Connection lost. */

/* Hardware flow-control-invoked bits. */
#define TS_CAR_OFLOW    0x200000        /* For MDMBUF (XXX handle in driver). */
#ifdef notyet
#define TS_CTS_OFLOW    0x400000        /* For CCTS_OFLOW. */
#define TS_DSR_OFLOW    0x800000        /* For CDSR_OFLOW. */
#endif

#define TS_IOCTL_NOT_OK 0x1000000       /* Workaround <rdar://....> */
#define TS_REVOKE       0x2000000       /* Terminal getting revoked */


/* Character type information. */
#define ORDINARY        0
#define CONTROL         1
#define BACKSPACE       2
#define NEWLINE         3
#define TAB             4
#define VTAB            5
#define RETURN          6

struct speedtab {
	int sp_speed;
	int sp_code;
};

/* Modem control commands (driver). */
#define DMSET           0
#define DMBIS           1
#define DMBIC           2
#define DMGET           3

/* Flags on a character passed to ttyinput. */
#define TTY_CHARMASK    0x000000ff      /* Character mask */
#define TTY_QUOTE       0x00000100      /* Character quoted */
#define TTY_ERRORMASK   0xff000000      /* Error mask */
#define TTY_FE          0x01000000      /* Framing error */
#define TTY_PE          0x02000000      /* Parity error */
#define TTY_OE          0x04000000      /* Overrun error */
#define TTY_BI          0x08000000      /* Break condition */


#endif /* !_SYS_TTY_H_ */
