1/*
2 * Copyright (c) 1989, 1993
3 *	The Regents of the University of California.  All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 *    must display the following acknowledgement:
15 *	This product includes software developed by the University of
16 *	California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 *	@(#)defs.h	8.1 (Berkeley) 6/4/93
34 */
35
36/*
37 * Telnet server defines
38 */
39
40#ifndef __DEFS_H__
41#define __DEFS_H__
42
43#ifndef	BSD
44# define	BSD 43
45#endif
46
47#if defined(PRINTOPTIONS) && defined(DIAGNOSTICS)
48#define TELOPTS
49#define TELCMDS
50#define	SLC_NAMES
51#endif
52
53#if	!defined(TIOCSCTTY) && defined(TCSETCTTY)
54# define	TIOCSCTTY TCSETCTTY
55#endif
56
57#ifndef TIOCPKT_FLUSHWRITE
58#define TIOCPKT_FLUSHWRITE      0x02
59#endif
60
61#ifndef TIOCPKT_NOSTOP
62#define TIOCPKT_NOSTOP  0x10
63#endif
64
65#ifndef TIOCPKT_DOSTOP
66#define TIOCPKT_DOSTOP  0x20
67#endif
68
69/*
70 * I/O data buffers defines
71 */
72#define	NETSLOP	64
73#ifdef _CRAY
74#undef BUFSIZ
75#define BUFSIZ  2048
76#endif
77
78#define	NIACCUM(c)	{   *netip++ = c; \
79			    ncc++; \
80			}
81
82/* clock manipulations */
83#define	settimer(x)	(clocks.x = ++clocks.system)
84#define	sequenceIs(x,y)	(clocks.x < clocks.y)
85
86/*
87 * Structures of information for each special character function.
88 */
89typedef struct {
90	unsigned char	flag;		/* the flags for this function */
91	cc_t		val;		/* the value of the special character */
92} slcent, *Slcent;
93
94typedef struct {
95	slcent		defset;		/* the default settings */
96	slcent		current;	/* the current settings */
97	cc_t		*sptr;		/* a pointer to the char in */
98					/* system data structures */
99} slcfun, *Slcfun;
100
101#ifdef DIAGNOSTICS
102/*
103 * Diagnostics capabilities
104 */
105#define	TD_REPORT	0x01	/* Report operations to client */
106#define TD_EXERCISE	0x02	/* Exercise client's implementation */
107#define TD_NETDATA	0x04	/* Display received data stream */
108#define TD_PTYDATA	0x08	/* Display data passed to pty */
109#define	TD_OPTIONS	0x10	/* Report just telnet options */
110#endif /* DIAGNOSTICS */
111
112/*
113 * We keep track of each side of the option negotiation.
114 */
115
116#define	MY_STATE_WILL		0x01
117#define	MY_WANT_STATE_WILL	0x02
118#define	MY_STATE_DO		0x04
119#define	MY_WANT_STATE_DO	0x08
120
121/*
122 * Macros to check the current state of things
123 */
124
125#define	my_state_is_do(opt)		(options[opt]&MY_STATE_DO)
126#define	my_state_is_will(opt)		(options[opt]&MY_STATE_WILL)
127#define my_want_state_is_do(opt)	(options[opt]&MY_WANT_STATE_DO)
128#define my_want_state_is_will(opt)	(options[opt]&MY_WANT_STATE_WILL)
129
130#define	my_state_is_dont(opt)		(!my_state_is_do(opt))
131#define	my_state_is_wont(opt)		(!my_state_is_will(opt))
132#define my_want_state_is_dont(opt)	(!my_want_state_is_do(opt))
133#define my_want_state_is_wont(opt)	(!my_want_state_is_will(opt))
134
135#define	set_my_state_do(opt)		(options[opt] |= MY_STATE_DO)
136#define	set_my_state_will(opt)		(options[opt] |= MY_STATE_WILL)
137#define	set_my_want_state_do(opt)	(options[opt] |= MY_WANT_STATE_DO)
138#define	set_my_want_state_will(opt)	(options[opt] |= MY_WANT_STATE_WILL)
139
140#define	set_my_state_dont(opt)		(options[opt] &= ~MY_STATE_DO)
141#define	set_my_state_wont(opt)		(options[opt] &= ~MY_STATE_WILL)
142#define	set_my_want_state_dont(opt)	(options[opt] &= ~MY_WANT_STATE_DO)
143#define	set_my_want_state_wont(opt)	(options[opt] &= ~MY_WANT_STATE_WILL)
144
145/*
146 * Tricky code here.  What we want to know is if the MY_STATE_WILL
147 * and MY_WANT_STATE_WILL bits have the same value.  Since the two
148 * bits are adjacent, a little arithmatic will show that by adding
149 * in the lower bit, the upper bit will be set if the two bits were
150 * different, and clear if they were the same.
151 */
152#define my_will_wont_is_changing(opt) \
153			((options[opt]+MY_STATE_WILL) & MY_WANT_STATE_WILL)
154
155#define my_do_dont_is_changing(opt) \
156			((options[opt]+MY_STATE_DO) & MY_WANT_STATE_DO)
157
158/*
159 * Make everything symmetrical
160 */
161
162#define	HIS_STATE_WILL			MY_STATE_DO
163#define	HIS_WANT_STATE_WILL		MY_WANT_STATE_DO
164#define HIS_STATE_DO			MY_STATE_WILL
165#define HIS_WANT_STATE_DO		MY_WANT_STATE_WILL
166
167#define	his_state_is_do			my_state_is_will
168#define	his_state_is_will		my_state_is_do
169#define his_want_state_is_do		my_want_state_is_will
170#define his_want_state_is_will		my_want_state_is_do
171
172#define	his_state_is_dont		my_state_is_wont
173#define	his_state_is_wont		my_state_is_dont
174#define his_want_state_is_dont		my_want_state_is_wont
175#define his_want_state_is_wont		my_want_state_is_dont
176
177#define	set_his_state_do		set_my_state_will
178#define	set_his_state_will		set_my_state_do
179#define	set_his_want_state_do		set_my_want_state_will
180#define	set_his_want_state_will		set_my_want_state_do
181
182#define	set_his_state_dont		set_my_state_wont
183#define	set_his_state_wont		set_my_state_dont
184#define	set_his_want_state_dont		set_my_want_state_wont
185#define	set_his_want_state_wont		set_my_want_state_dont
186
187#define his_will_wont_is_changing	my_do_dont_is_changing
188#define his_do_dont_is_changing		my_will_wont_is_changing
189
190#endif /* __DEFS_H__ */
191