1 /*	$OpenBSD: telnet.h,v 1.7 2003/06/02 19:34:12 millert Exp $	*/
2 /*	$NetBSD: telnet.h,v 1.4 1994/10/26 00:56:46 cgd Exp $	*/
3 
4 /*
5  * Copyright (c) 1983, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)telnet.h	8.1 (Berkeley) 6/2/93
33  */
34 
35 #ifndef _TELNET_H_
36 #define	_TELNET_H_
37 
38 /*
39  * Definitions for the TELNET protocol.
40  */
41 #define	IAC	255		/* interpret as command: */
42 #define	DONT	254		/* you are not to use option */
43 #define	DO	253		/* please, you use option */
44 #define	WONT	252		/* I won't use option */
45 #define	WILL	251		/* I will use option */
46 #define	SB	250		/* interpret as subnegotiation */
47 #define	GA	249		/* you may reverse the line */
48 #define	EL	248		/* erase the current line */
49 #define	EC	247		/* erase the current character */
50 #define	AYT	246		/* are you there */
51 #define	AO	245		/* abort output--but let prog finish */
52 #define	IP	244		/* interrupt process--permanently */
53 #define	BREAK	243		/* break */
54 #define	DM	242		/* data mark--for connect. cleaning */
55 #define	NOP	241		/* nop */
56 #define	SE	240		/* end sub negotiation */
57 #define EOR     239             /* end of record (transparent mode) */
58 #define	ABORT	238		/* Abort process */
59 #define	SUSP	237		/* Suspend process */
60 #define	xEOF	236		/* End of file: EOF is already used... */
61 
62 #define SYNCH	242		/* for telfunc calls */
63 
64 #ifdef TELCMDS
65 char *telcmds[] = {
66 	"EOF", "SUSP", "ABORT", "EOR",
67 	"SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
68 	"EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC",
69 	0
70 };
71 #else
72 extern char *telcmds[];
73 #endif
74 
75 #define	TELCMD_FIRST	xEOF
76 #define	TELCMD_LAST	IAC
77 #define	TELCMD_OK(x)	((unsigned int)(x) <= TELCMD_LAST && \
78 			 (unsigned int)(x) >= TELCMD_FIRST)
79 #define	TELCMD(x)	telcmds[(x)-TELCMD_FIRST]
80 
81 /* telnet options */
82 #define TELOPT_BINARY	0	/* 8-bit data path */
83 #define TELOPT_ECHO	1	/* echo */
84 #define	TELOPT_RCP	2	/* prepare to reconnect */
85 #define	TELOPT_SGA	3	/* suppress go ahead */
86 #define	TELOPT_NAMS	4	/* approximate message size */
87 #define	TELOPT_STATUS	5	/* give status */
88 #define	TELOPT_TM	6	/* timing mark */
89 #define	TELOPT_RCTE	7	/* remote controlled transmission and echo */
90 #define TELOPT_NAOL 	8	/* negotiate about output line width */
91 #define TELOPT_NAOP 	9	/* negotiate about output page size */
92 #define TELOPT_NAOCRD	10	/* negotiate about CR disposition */
93 #define TELOPT_NAOHTS	11	/* negotiate about horizontal tabstops */
94 #define TELOPT_NAOHTD	12	/* negotiate about horizontal tab disposition */
95 #define TELOPT_NAOFFD	13	/* negotiate about formfeed disposition */
96 #define TELOPT_NAOVTS	14	/* negotiate about vertical tab stops */
97 #define TELOPT_NAOVTD	15	/* negotiate about vertical tab disposition */
98 #define TELOPT_NAOLFD	16	/* negotiate about output LF disposition */
99 #define TELOPT_XASCII	17	/* extended ascic character set */
100 #define	TELOPT_LOGOUT	18	/* force logout */
101 #define	TELOPT_BM	19	/* byte macro */
102 #define	TELOPT_DET	20	/* data entry terminal */
103 #define	TELOPT_SUPDUP	21	/* supdup protocol */
104 #define	TELOPT_SUPDUPOUTPUT 22	/* supdup output */
105 #define	TELOPT_SNDLOC	23	/* send location */
106 #define	TELOPT_TTYPE	24	/* terminal type */
107 #define	TELOPT_EOR	25	/* end or record */
108 #define	TELOPT_TUID	26	/* TACACS user identification */
109 #define	TELOPT_OUTMRK	27	/* output marking */
110 #define	TELOPT_TTYLOC	28	/* terminal location number */
111 #define	TELOPT_3270REGIME 29	/* 3270 regime */
112 #define	TELOPT_X3PAD	30	/* X.3 PAD */
113 #define	TELOPT_NAWS	31	/* window size */
114 #define	TELOPT_TSPEED	32	/* terminal speed */
115 #define	TELOPT_LFLOW	33	/* remote flow control */
116 #define TELOPT_LINEMODE	34	/* Linemode option */
117 #define TELOPT_XDISPLOC	35	/* X Display Location */
118 #define TELOPT_OLD_ENVIRON 36	/* Old - Environment variables */
119 #define	TELOPT_AUTHENTICATION 37/* Authenticate */
120 #define	TELOPT_ENCRYPT	38	/* Encryption option */
121 #define TELOPT_NEW_ENVIRON 39	/* New - Environment variables */
122 #define	TELOPT_EXOPL	255	/* extended-options-list */
123 
124 
125 #define	NTELOPTS	(1+TELOPT_NEW_ENVIRON)
126 #ifdef TELOPTS
127 char *telopts[NTELOPTS+1] = {
128 	"BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
129 	"STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
130 	"NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
131 	"NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO",
132 	"DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT",
133 	"SEND LOCATION", "TERMINAL TYPE", "END OF RECORD",
134 	"TACACS UID", "OUTPUT MARKING", "TTYLOC",
135 	"3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW",
136 	"LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION",
137 	"ENCRYPT", "NEW-ENVIRON",
138 	0
139 };
140 #define	TELOPT_FIRST	TELOPT_BINARY
141 #define	TELOPT_LAST	TELOPT_NEW_ENVIRON
142 #define	TELOPT_OK(x)	((unsigned int)(x) <= TELOPT_LAST)
143 #define	TELOPT(x)	telopts[(x)-TELOPT_FIRST]
144 #endif
145 
146 /* sub-option qualifiers */
147 #define	TELQUAL_IS	0	/* option is... */
148 #define	TELQUAL_SEND	1	/* send option */
149 #define	TELQUAL_INFO	2	/* ENVIRON: informational version of IS */
150 #define	TELQUAL_REPLY	2	/* AUTHENTICATION: client version of IS */
151 #define	TELQUAL_NAME	3	/* AUTHENTICATION: client version of IS */
152 
153 #define	LFLOW_OFF		0	/* Disable remote flow control */
154 #define	LFLOW_ON		1	/* Enable remote flow control */
155 #define	LFLOW_RESTART_ANY	2	/* Restart output on any char */
156 #define	LFLOW_RESTART_XON	3	/* Restart output only on XON */
157 
158 /*
159  * LINEMODE suboptions
160  */
161 
162 #define	LM_MODE		1
163 #define	LM_FORWARDMASK	2
164 #define	LM_SLC		3
165 
166 #define	MODE_EDIT	0x01
167 #define	MODE_TRAPSIG	0x02
168 #define	MODE_ACK	0x04
169 #define MODE_SOFT_TAB	0x08
170 #define MODE_LIT_ECHO	0x10
171 
172 #define	MODE_MASK	0x1f
173 
174 /* Not part of protocol, but needed to simplify things... */
175 #define MODE_FLOW		0x0100
176 #define MODE_ECHO		0x0200
177 #define MODE_INBIN		0x0400
178 #define MODE_OUTBIN		0x0800
179 #define MODE_FORCE		0x1000
180 
181 #define	SLC_SYNCH	1
182 #define	SLC_BRK		2
183 #define	SLC_IP		3
184 #define	SLC_AO		4
185 #define	SLC_AYT		5
186 #define	SLC_EOR		6
187 #define	SLC_ABORT	7
188 #define	SLC_EOF		8
189 #define	SLC_SUSP	9
190 #define	SLC_EC		10
191 #define	SLC_EL		11
192 #define	SLC_EW		12
193 #define	SLC_RP		13
194 #define	SLC_LNEXT	14
195 #define	SLC_XON		15
196 #define	SLC_XOFF	16
197 #define	SLC_FORW1	17
198 #define	SLC_FORW2	18
199 #define	SLC_MCL		19
200 #define	SLC_MCR		20
201 #define	SLC_MCWL	21
202 #define	SLC_MCWR	22
203 #define	SLC_MCBOL	23
204 #define	SLC_MCEOL	24
205 #define	SLC_INSRT	25
206 #define	SLC_OVER	26
207 #define	SLC_ECR		27
208 #define	SLC_EWR		28
209 #define	SLC_EBOL	29
210 #define	SLC_EEOL	30
211 
212 #define	NSLC		30
213 
214 /*
215  * For backwards compatibility, we define SLC_NAMES to be the
216  * list of names if SLC_NAMES is not defined.
217  */
218 #define	SLC_NAMELIST	"0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR",	\
219 			"ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP",	\
220 			"LNEXT", "XON", "XOFF", "FORW1", "FORW2",	\
221 			"MCL", "MCR", "MCWL", "MCWR", "MCBOL",		\
222 			"MCEOL", "INSRT", "OVER", "ECR", "EWR",		\
223 			"EBOL", "EEOL",					\
224 			0
225 
226 #ifdef	SLC_NAMES
227 char *slc_names[] = {
228 	SLC_NAMELIST
229 };
230 #else
231 extern char *slc_names[];
232 #define	SLC_NAMES SLC_NAMELIST
233 #endif
234 
235 #define	SLC_NAME_OK(x)	((unsigned)(x) > 0 && (unsigned)(x) <= NSLC)
236 #define SLC_NAME(x)	slc_names[x]
237 
238 #define	SLC_NOSUPPORT	0
239 #define	SLC_CANTCHANGE	1
240 #define	SLC_VARIABLE	2
241 #define	SLC_DEFAULT	3
242 #define	SLC_LEVELBITS	0x03
243 
244 #define	SLC_FUNC	0
245 #define	SLC_FLAGS	1
246 #define	SLC_VALUE	2
247 
248 #define	SLC_ACK		0x80
249 #define	SLC_FLUSHIN	0x40
250 #define	SLC_FLUSHOUT	0x20
251 
252 #define	OLD_ENV_VAR	1
253 #define	OLD_ENV_VALUE	0
254 #define	NEW_ENV_VAR	0
255 #define	NEW_ENV_VALUE	1
256 #define	ENV_ESC		2
257 #define ENV_USERVAR	3
258 
259 /*
260  * AUTHENTICATION suboptions
261  */
262 
263 /*
264  * Who is authenticating who ...
265  */
266 #define	AUTH_WHO_CLIENT		0	/* Client authenticating server */
267 #define	AUTH_WHO_SERVER		1	/* Server authenticating client */
268 #define	AUTH_WHO_MASK		1
269 
270 /*
271  * amount of authentication done
272  */
273 #define	AUTH_HOW_ONE_WAY	0
274 #define	AUTH_HOW_MUTUAL		2
275 #define	AUTH_HOW_MASK		2
276 
277 #define	AUTHTYPE_NULL		0
278 #define	AUTHTYPE_KERBEROS_V4	1
279 #define	AUTHTYPE_KERBEROS_V5	2
280 #define	AUTHTYPE_SPX		3
281 #define	AUTHTYPE_MINK		4
282 #define	AUTHTYPE_CNT		5
283 
284 #define	AUTHTYPE_TEST		99
285 
286 #ifdef	AUTH_NAMES
287 char *authtype_names[] = {
288 	"NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK",
289 	0
290 };
291 #else
292 extern char *authtype_names[];
293 #endif
294 
295 #define	AUTHTYPE_NAME_OK(x)	((unsigned int)(x) < AUTHTYPE_CNT)
296 #define	AUTHTYPE_NAME(x)	authtype_names[x]
297 
298 /*
299  * ENCRYPTion suboptions
300  */
301 #define	ENCRYPT_IS		0	/* I pick encryption type ... */
302 #define	ENCRYPT_SUPPORT		1	/* I support encryption types ... */
303 #define	ENCRYPT_REPLY		2	/* Initial setup response */
304 #define	ENCRYPT_START		3	/* Am starting to send encrypted */
305 #define	ENCRYPT_END		4	/* Am ending encrypted */
306 #define	ENCRYPT_REQSTART	5	/* Request you start encrypting */
307 #define	ENCRYPT_REQEND		6	/* Request you end encrypting */
308 #define	ENCRYPT_ENC_KEYID	7
309 #define	ENCRYPT_DEC_KEYID	8
310 #define	ENCRYPT_CNT		9
311 
312 #define	ENCTYPE_ANY		0
313 #define	ENCTYPE_DES_CFB64	1
314 #define	ENCTYPE_DES_OFB64	2
315 #define	ENCTYPE_CNT		3
316 
317 #ifdef	ENCRYPT_NAMES
318 char *encrypt_names[] = {
319 	"IS", "SUPPORT", "REPLY", "START", "END",
320 	"REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID",
321 	0
322 };
323 char *enctype_names[] = {
324 	"ANY", "DES_CFB64",  "DES_OFB64",
325 	0
326 };
327 #else
328 extern char *encrypt_names[];
329 extern char *enctype_names[];
330 #endif
331 
332 
333 #define	ENCRYPT_NAME_OK(x)	((unsigned int)(x) < ENCRYPT_CNT)
334 #define	ENCRYPT_NAME(x)		encrypt_names[x]
335 
336 #define	ENCTYPE_NAME_OK(x)	((unsigned int)(x) < ENCTYPE_CNT)
337 #define	ENCTYPE_NAME(x)		enctype_names[x]
338 
339 #endif /* !_TELNET_H_ */
340