Telnet IAC codes: reading FF FB 01, WILL, WONT, DO and DONT in a trace
What the bytes 255 251 1 (FF FB 01) mean in a Telnet trace: the IAC command codes, common option numbers, subnegotiation, and how to read a negotiation log.
Every Telnet command starts with the byte 255 (hex FF), called IAC (Interpret As Command). The byte after it is the command. For option negotiation a third byte names the option. So FF FB 01 is IAC WILL ECHO: "I will echo."
If you see ÿû or ÿý at the start of a raw connection, those are the same bytes shown as Latin-1 text: ÿ is 255, û is 251 and ý is 253. The program that printed them is not a Telnet client, or it is showing the raw stream.
Command codes
From RFC 854:
240(F0) SE: end of a subnegotiation.241(F1) NOP: no operation.242(F2) DM, Data Mark: the in-stream part of a Synch.243(F3) BRK: Break.244(F4) IP: Interrupt Process.245(F5) AO: Abort Output.246(F6) AYT: Are You There.247(F7) EC: Erase Character.248(F8) EL: Erase Line.249(F9) GA: Go Ahead.250(FA) SB: start of a subnegotiation.251(FB) WILL: I want to start using this option, or I agree to.252(FC) WON'T: I will not use it, or I am stopping.253(FD) DO: please start using it, or yes, go ahead.254(FE) DON'T: do not use it, or stop.255(FF) IAC. A data byte of 255 is sent twice (FF FF) so it is not read as a command.
Common option numbers
0Binary transmission (RFC 856)1Echo (RFC 857)3Suppress Go Ahead (RFC 858)6Timing Mark (RFC 860)24(18hex) Terminal Type (RFC 1091)25(19hex) End of Record (RFC 885). The end-of-record mark itself isIAC EOR,FF EF, whereEORis 239.31(1Fhex) Window size, NAWS (RFC 1073)39(27hex) New Environment (RFC 1572)40(28hex) TN3270E (RFC 2355)
How a request and answer pair up
WILL and DO are offers or requests. The other side answers once:
WILL xis answered byDO x(accepted) orDON'T x(refused).DO xis answered byWILL x(accepted) orWON'T x(refused).
WILL is about what the sender will do. DO is about what the sender asks the other side to do. RFC 854 points out that WON'T and DON'T always leave the connection in a state both ends can handle, the plain default terminal, so any option can be refused.
RFC 854 also has rules that stop loops: a side does not send a request just to announce the mode it is in, and does not answer a request for the mode it is already in. RFC 1143 describes a state machine for clients that implement it carefully.
Subnegotiation
After both sides agree on an option, details travel between IAC SB option and IAC SE. Two that show up in almost every terminal trace:
- Terminal type. The server sends
IAC SB TERMINAL-TYPE SEND IAC SE(FF FA 18 01 FF F0). The client answers withIAC SB TERMINAL-TYPE ISfollowed by a name in ASCII, for exampleIBM-3278-2-EorVT220, andIAC SE.SENDis 1 andISis 0. Only the server asks, and the client sends a name only when asked. - Window size. The client sends
IAC SB NAWS, then width and height as two bytes each, thenIAC SE. An 80 by 24 window isFF FA 1F 00 50 00 18 FF F0.
A trace, line by line
A typical TN3270 start, in the simplified form many clients use for their negotiation log (RCVD is from the host, SENT is from the client):
RCVD DO TERMINAL-TYPE
SENT WILL TERMINAL-TYPE
RCVD SB TERMINAL-TYPE SEND
SENT SB TERMINAL-TYPE IS IBM-3278-2-E
RCVD DO END-OF-RECORD
SENT WILL END-OF-RECORD
RCVD WILL END-OF-RECORD
SENT DO END-OF-RECORD
RCVD DO BINARY
SENT WILL BINARY
RCVD WILL BINARY
SENT DO BINARY
The host asks for the terminal type, the client says it will tell it, the host asks for the name and the client sends it. Binary and End of Record are agreed in both directions. Those three options are what classic TN3270 negotiates before 3270 data can flow (RFC 1576), and RFC 1576 notes that their order does not matter. A VT session usually shows Echo, Suppress Go Ahead, Terminal Type and NAWS instead.
Reading a failed negotiation
- A
DON'TorWON'Tfollowed by the host closing the connection. The host needed that option. A 3270 or 5250 session cannot start without Terminal Type, Binary and End of Record, so a host either closes the connection or carries on as a plain line-mode Telnet session, which shows up as unreadable characters in a 3270 or 5250 client. On IBM i, see TN5250 garbage or VT100 screen after connecting to IBM i. - The terminal type was sent and then the connection closed. The host does not accept that name. Try a different model, for example
IBM-3278-2instead ofIBM-3278-5-E. For TN3270E device-type errors, see TN3270E negotiation errors. - Requests going back and forth for the same option without end. One side breaks the loop rules above.
- Characters typed twice, or not at all. Look at the Echo option. See Telnet echo, typed characters twice, missing or visible passwords.
Related
- Telnet basics
- Telnet echo, typed characters twice, missing or visible passwords
- TN3270E
- TN3270E negotiation errors
- TN5250 garbage or VT100 screen after connecting to IBM i
- Telnet "Connection closed by foreign host"
Sources
- RFC 854, Telnet Protocol Specification
- RFC 855, Telnet Option Specifications
- RFC 1576, TN3270 Current Practices
- RFC 1143, The Q Method of Implementing Telnet Option Negotiation
- RFC 856, Telnet Binary Transmission
- RFC 885, Telnet End of Record Option
- RFC 1091, Telnet Terminal-Type Option
- RFC 1073, Telnet Window Size Option
- RFC 1572, Telnet Environment Option
- RFC 2355, TN3270 Enhancements