1 /*-
2  * Copyright (c) 1983, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  *
7  *	@(#)telnet.h	8.1 (Berkeley) 06/06/93
8  */
9 
10 /*
11  * Definitions for the TELNET protocol.
12  */
13 #define	IAC	255		/* interpret as command: */
14 #define	DONT	254		/* you are not to use option */
15 #define	DO	253		/* please, you use option */
16 #define	WONT	252		/* I won't use option */
17 #define	WILL	251		/* I will use option */
18 #define	SB	250		/* interpret as subnegotiation */
19 #define	GA	249		/* you may reverse the line */
20 #define	EL	248		/* erase the current line */
21 #define	EC	247		/* erase the current character */
22 #define	AYT	246		/* are you there */
23 #define	AO	245		/* abort output--but let prog finish */
24 #define	IP	244		/* interrupt process--permanently */
25 #define	BREAK	243		/* break */
26 #define	DM	242		/* data mark--for connect. cleaning */
27 #define	NOP	241		/* nop */
28 #define	SE	240		/* end sub negotiation */
29 #define EOR     239             /* end of record (transparent mode) */
30 #define	ABORT	238		/* Abort process */
31 #define	SUSP	237		/* Suspend process */
32 #define	xEOF	236		/* End of file: EOF is already used... */
33 
34 #define SYNCH	242		/* for telfunc calls */
35 
36 #ifdef TELCMDS
37 char *telcmds[] = {
38 	"EOF", "SUSP", "ABORT", "EOR",
39 	"SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
40 	"EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC",
41 };
42 #define	TELCMD_FIRST	xEOF
43 #define	TELCMD_LAST	IAC
44 #define	TELCMD_OK(x)	((x) <= TELCMD_LAST && (x) >= TELCMD_FIRST)
45 #define	TELCMD(x)	telcmds[(x)-TELCMD_FIRST]
46 #endif
47 
48 /* telnet options */
49 #define TELOPT_BINARY	0	/* 8-bit data path */
50 #define TELOPT_ECHO	1	/* echo */
51 #define	TELOPT_RCP	2	/* prepare to reconnect */
52 #define	TELOPT_SGA	3	/* suppress go ahead */
53 #define	TELOPT_NAMS	4	/* approximate message size */
54 #define	TELOPT_STATUS	5	/* give status */
55 #define	TELOPT_TM	6	/* timing mark */
56 #define	TELOPT_RCTE	7	/* remote controlled transmission and echo */
57 #define TELOPT_NAOL 	8	/* negotiate about output line width */
58 #define TELOPT_NAOP 	9	/* negotiate about output page size */
59 #define TELOPT_NAOCRD	10	/* negotiate about CR disposition */
60 #define TELOPT_NAOHTS	11	/* negotiate about horizontal tabstops */
61 #define TELOPT_NAOHTD	12	/* negotiate about horizontal tab disposition */
62 #define TELOPT_NAOFFD	13	/* negotiate about formfeed disposition */
63 #define TELOPT_NAOVTS	14	/* negotiate about vertical tab stops */
64 #define TELOPT_NAOVTD	15	/* negotiate about vertical tab disposition */
65 #define TELOPT_NAOLFD	16	/* negotiate about output LF disposition */
66 #define TELOPT_XASCII	17	/* extended ascic character set */
67 #define	TELOPT_LOGOUT	18	/* force logout */
68 #define	TELOPT_BM	19	/* byte macro */
69 #define	TELOPT_DET	20	/* data entry terminal */
70 #define	TELOPT_SUPDUP	21	/* supdup protocol */
71 #define	TELOPT_SUPDUPOUTPUT 22	/* supdup output */
72 #define	TELOPT_SNDLOC	23	/* send location */
73 #define	TELOPT_TTYPE	24	/* terminal type */
74 #define	TELOPT_EOR	25	/* end or record */
75 #define	TELOPT_TUID	26	/* TACACS user identification */
76 #define	TELOPT_OUTMRK	27	/* output marking */
77 #define	TELOPT_TTYLOC	28	/* terminal location number */
78 #define	TELOPT_3270REGIME 29	/* 3270 regime */
79 #define	TELOPT_X3PAD	30	/* X.3 PAD */
80 #define	TELOPT_NAWS	31	/* window size */
81 #define	TELOPT_TSPEED	32	/* terminal speed */
82 #define	TELOPT_LFLOW	33	/* remote flow control */
83 #define TELOPT_LINEMODE	34	/* Linemode option */
84 #define	TELOPT_EXOPL	255	/* extended-options-list */
85 
86 #define	NTELOPTS	(1+TELOPT_LINEMODE)
87 #ifdef TELOPTS
88 char *telopts[NTELOPTS] = {
89 	"BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
90 	"STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
91 	"NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
92 	"NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO",
93 	"DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT",
94 	"SEND LOCATION", "TERMINAL TYPE", "END OF RECORD",
95 	"TACACS UID", "OUTPUT MARKING", "TTYLOC",
96 	"3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW",
97 	"LINEMODE",
98 };
99 #define	TELOPT_FIRST	TELOPT_BINARY
100 #define	TELOPT_LAST	TELOPT_LINEMODE
101 #define	TELOPT_OK(x)	((x) <= TELOPT_LAST && (x) >= TELOPT_FIRST)
102 #define	TELOPT(x)	telopts[(x)-TELOPT_FIRST]
103 #endif
104 
105 /* sub-option qualifiers */
106 #define	TELQUAL_IS	0	/* option is... */
107 #define	TELQUAL_SEND	1	/* send option */
108 
109 /*
110  * LINEMODE suboptions
111  */
112 
113 #define	LM_MODE		1
114 #define	LM_FORWARDMASK	2
115 #define	LM_SLC		3
116 
117 #define	MODE_EDIT	0x01
118 #define	MODE_TRAPSIG	0x02
119 #define	MODE_ACK	0x04
120 
121 #define	MODE_MASK	(MODE_EDIT|MODE_TRAPSIG|MODE_ACK)
122 
123 /* Not part of protocol, but needed to simplify things... */
124 #define MODE_FLOW		0x40
125 #define MODE_ECHO		0x80
126 #define MODE_FORCE		0x20
127 
128 #define	SLC_SYNCH	1
129 #define	SLC_BRK		2
130 #define	SLC_IP		3
131 #define	SLC_AO		4
132 #define	SLC_AYT		5
133 #define	SLC_EOR		6
134 #define	SLC_ABORT	7
135 #define	SLC_EOF		8
136 #define	SLC_SUSP	9
137 #define	SLC_EC		10
138 #define	SLC_EL		11
139 #define	SLC_EW		12
140 #define	SLC_RP		13
141 #define	SLC_LNEXT	14
142 #define	SLC_XON		15
143 #define	SLC_XOFF	16
144 #define	SLC_FORW1	17
145 #define	SLC_FORW2	18
146 
147 #define	NSLC		18
148 
149 #define	SLC_NAMES	"0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \
150 			"ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \
151 			"LNEXT", "XON", "XOFF", "FORW1", "FORW2"
152 
153 #define	SLC_NOSUPPORT	0
154 #define	SLC_CANTCHANGE	1
155 #define	SLC_VARIABLE	2
156 #define	SLC_DEFAULT	3
157 #define	SLC_LEVELBITS	0x03
158 
159 #define	SLC_FUNC	0
160 #define	SLC_FLAGS	1
161 #define	SLC_VALUE	2
162 
163 #define	SLC_ACK		0x80
164 #define	SLC_FLUSHIN	0x40
165 #define	SLC_FLUSHOUT	0x20
166