1 #ifndef TELNET_H__
2 #define TELNET_H__ 1
3 
4 /*
5  * Copyright (c) 1983 Regents of the University of California.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms are permitted
9  * provided that the above copyright notice and this paragraph are
10  * duplicated in all such forms and that any documentation,
11  * advertising materials, and other materials related to such
12  * distribution and use acknowledge that the software was developed
13  * by the University of California, Berkeley.  The name of the
14  * University may not be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
18  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19  *
20  *        @(#)telnet.h        5.7 (Berkeley) 11/14/89
21  */
22 
23 /*
24  * Definitions for the TELNET protocol.
25  */
26 #define  IAC     255      /* interpret as command: */
27 #define  DONT    254      /* you are not to use option */
28 #define  DO      253      /* please, you use option */
29 #define  WONT    252      /* I won't use option */
30 #define  WILL    251      /* I will use option */
31 #define  SB      250      /* interpret as subnegotiation */
32 #define  GA      249      /* you may reverse the line */
33 #define  EL      248      /* erase the current line */
34 #define  EC      247      /* erase the current character */
35 #define  AYT     246      /* are you there */
36 #define  AO      245      /* abort output--but let prog finish */
37 #define  IP      244      /* interrupt process--permanently */
38 #define  BREAK   243      /* break */
39 #define  DM      242      /* data mark--for connect. cleaning */
40 #define  NOP     241      /* nop */
41 #define  SE      240      /* end sub negotiation */
42 #define  EOR     239      /* end of record (transparent mode) */
43 #define  ABORT   238      /* Abort process */
44 #define  SUSP    237      /* Suspend process */
45 #define  xEOF    236      /* End of file: EOF is already used... */
46 
47 #define  SYNCH   242      /* for telfunc calls */
48 
49 #ifdef __DRIVER_SOURCE__
50 
51 #ifdef TELCMDS
52 char *telcmds[] = {
53         "EOF", "SUSP", "ABORT", "EOR",
54         "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
55         "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC",
56 };
57 #define  TELCMD_FIRST   xEOF
58 #define  TELCMD_LAST    IAC
59 #define  TELCMD_OK(x)   ((x) <= TELCMD_LAST && (x) >= TELCMD_FIRST)
60 #define  TELCMD(x)      telcmds[(x)-TELCMD_FIRST]
61 #endif
62 
63 #endif /* __DRIVER_SOURCE__ */
64 
65 /* telnet options */
66 #define  TELOPT_BINARY         0        /* 8-bit data path */
67 #define  TELOPT_ECHO           1        /* echo */
68 #define  TELOPT_RCP            2        /* prepare to reconnect */
69 #define  TELOPT_SGA            3        /* suppress go ahead */
70 #define  TELOPT_NAMS           4        /* approximate message size */
71 #define  TELOPT_STATUS         5        /* give status */
72 #define  TELOPT_TM             6        /* timing mark */
73 #define  TELOPT_RCTE           7        /* remote controlled transmission and echo */
74 #define  TELOPT_NAOL           8        /* negotiate about output line width */
75 #define  TELOPT_NAOP           9        /* negotiate about output page size */
76 #define  TELOPT_NAOCRD        10        /* negotiate about CR disposition */
77 #define  TELOPT_NAOHTS        11        /* negotiate about horizontal tabstops */
78 #define  TELOPT_NAOHTD        12        /* negotiate about horizontal tab disposition */
79 #define  TELOPT_NAOFFD        13        /* negotiate about formfeed disposition */
80 #define  TELOPT_NAOVTS        14        /* negotiate about vertical tab stops */
81 #define  TELOPT_NAOVTD        15        /* negotiate about vertical tab disposition */
82 #define  TELOPT_NAOLFD        16        /* negotiate about output LF disposition */
83 #define  TELOPT_XASCII        17        /* extended ascic character set */
84 #define  TELOPT_LOGOUT        18        /* force logout */
85 #define  TELOPT_BM            19        /* byte macro */
86 #define  TELOPT_DET           20        /* data entry terminal */
87 #define  TELOPT_SUPDUP        21        /* supdup protocol */
88 #define  TELOPT_SUPDUPOUTPUT  22        /* supdup output */
89 #define  TELOPT_SNDLOC        23        /* send location */
90 #define  TELOPT_TTYPE         24        /* terminal type */
91 #define  TELOPT_EOR           25        /* end or record */
92 #define  TELOPT_TUID          26        /* TACACS user identification */
93 #define  TELOPT_OUTMRK        27        /* output marking */
94 #define  TELOPT_TTYLOC        28        /* terminal location number */
95 #define  TELOPT_3270REGIME    29        /* 3270 regime */
96 #define  TELOPT_X3PAD         30        /* X.3 PAD */
97 #define  TELOPT_NAWS          31        /* window size */
98 #define  TELOPT_TSPEED        32        /* terminal speed */
99 #define  TELOPT_LFLOW         33        /* remote flow control */
100 #define  TELOPT_LINEMODE      34        /* Linemode option */
101 #define  TELOPT_XDISPLOC      35        /* X Display Location */
102 #define	 TELOPT_ENVIRON	      36        /* Environment opt for Port ID */
103 #define  TELOPT_AUTHENTICATION 37       /* authentication */
104 #define  TELOPT_ENCRYPT       38        /* authentication */
105 #define	 TELOPT_NEWENV        39        /* Environment opt for Port ID */
106 #define  TELOPT_STARTTLS      46        /* Transport Layer Security */
107 
108 /* Inofficial, mud specific telnet options */
109 #define  TELOPT_COMPRESS      85        /* Mud Compression Protocol, v.1 */
110 #define  TELOPT_COMPRESS2     86        /* Mud Compression Protocol, v.2 */
111 #define  TELOPT_MSP           90        /* Mud Sound Protocol */
112 #define  TELOPT_MXP           91        /* Mud Extension Protocol */
113 #define  TELOPT_EXOPL        255        /* extended-options-list */
114 
115 #define  NTELOPTS            256        /* was: (1+TELOPT_NEWENV) */
116 
117 #ifdef __DRIVER_SOURCE__
118 
119 #ifdef TELOPTS
120 char *telopts[NTELOPTS]
121  = { "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD"
122    , "NAME", "STATUS", "TIMING MARK", "RCTE"
123    , "NAOL", "NAOP", "NAOCRD", "NAOHTS"
124    , "NAOHTD", "NAOFFD", "NAOVTS", "NAOVTD"
125    , "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO"
126    , "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT", "SEND LOCATION"
127    , "TERMINAL TYPE", "END OF RECORD", "TACACS UID", "OUTPUT MARKING"
128    , "TTYLOC", "3270 REGIME", "X.3 PAD", "NAWS"
129    , "TSPEED", "LFLOW", "LINEMODE", "XDISPLOC"
130    , "ENVIRON", "AUTH", "ENCRYPT", "NEWENV"
131    , "TELOPT 40", "TELOPT 41", "TELOPT 42", "TELOPT 43"
132    , "TELOPT 44", "TELOPT 45", "STARTTLS", "TELOPT 47"
133    , "TELOPT 48", "TELOPT 49", "TELOPT 50", "TELOPT 51"
134    , "TELOPT 52", "TELOPT 53", "TELOPT 54", "TELOPT 55"
135    , "TELOPT 56", "TELOPT 57", "TELOPT 58", "TELOPT 59"
136    , "TELOPT 60", "TELOPT 61", "TELOPT 62", "TELOPT 63"
137    , "TELOPT 64", "TELOPT 65", "TELOPT 66", "TELOPT 67"
138    , "TELOPT 68", "TELOPT 69", "TELOPT 70", "TELOPT 71"
139    , "TELOPT 72", "TELOPT 73", "TELOPT 74", "TELOPT 75"
140    , "TELOPT 76", "TELOPT 77", "TELOPT 78", "TELOPT 79"
141    , "TELOPT 80", "TELOPT 81", "TELOPT 82", "TELOPT 83"
142    , "TELOPT 84", "MUD COMPRESS", "MUD COMPRESS2", "TELOPT 87"
143    , "TELOPT 88", "TELOPT 89", "MUD SOUND", "MUD EXTENSION"
144 };
145 #define  TELOPT_FIRST   TELOPT_BINARY
146 #define  TELOPT_LAST    TELOPT_MXP
147 #define  TELOPT_OK(x)   ((x) <= TELOPT_LAST && (x) >= TELOPT_FIRST)
148 #define  TELOPT(x)      telopts[(x)-TELOPT_FIRST]
149 #endif
150 
151 #endif /* __DRIVER_SOURCE__ */
152 
153 /* sub-option qualifiers */
154 #define  TELQUAL_IS     0        /* option is... */
155 #define  TELQUAL_SEND   1        /* send option */
156 
157 /*
158  * LINEMODE suboptions
159  */
160 
161 #define  LM_MODE            1
162 #define  LM_FORWARDMASK     2
163 #define  LM_SLC             3
164 
165 #define  MODE_EDIT       0x01
166 #define  MODE_TRAPSIG    0x02
167 #define  MODE_ACK        0x04
168 
169 #define  MODE_MASK       (MODE_EDIT|MODE_TRAPSIG|MODE_ACK)
170 
171 /* Not part of protocol, but needed to simplify things... */
172 #define  MODE_FLOW       0x0100
173 #define  MODE_ECHO       0x0200
174 #define  MODE_INBIN      0x0400
175 #define  MODE_OUTBIN     0x0800
176 #define  MODE_FORCE      0x1000
177 
178 #define  SLC_SYNCH   1
179 #define  SLC_BRK     2
180 #define  SLC_IP      3
181 #define  SLC_AO      4
182 #define  SLC_AYT     5
183 #define  SLC_EOR     6
184 #define  SLC_ABORT   7
185 #define  SLC_EOF     8
186 #define  SLC_SUSP    9
187 #define  SLC_EC     10
188 #define  SLC_EL     11
189 #define  SLC_EW     12
190 #define  SLC_RP     13
191 #define  SLC_LNEXT  14
192 #define  SLC_XON    15
193 #define  SLC_XOFF   16
194 #define  SLC_FORW1  17
195 #define  SLC_FORW2  18
196 
197 #define  NSLC       18
198 
199 #define  SLC_NAMES  "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \
200                     "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \
201                     "LNEXT", "XON", "XOFF", "FORW1", "FORW2"
202 
203 #define  SLC_NOSUPPORT     0
204 #define  SLC_CANTCHANGE    1
205 #define  SLC_VARIABLE      2
206 #define  SLC_DEFAULT       3
207 #define  SLC_LEVELBITS    0x03
208 
209 #define  SLC_FUNC          0
210 #define  SLC_FLAGS         1
211 #define  SLC_VALUE         2
212 
213 #define  SLC_ACK          0x80
214 #define  SLC_FLUSHIN      0x40
215 #define  SLC_FLUSHOUT     0x20
216 
217 #endif  /* TELNET_H__ */
218