Microchip Telnet Server fixes

I've been implementing a Telnet server on our products using the Microchip TCP/IP stack on a PIC18F87J50. Following are some useful notes!

- The TCP/IP stack does not like being interrupted, especially by the USB stack if you have both of them compiled in together. I suggest you get your telnet working fully first before putting USB in place... I found issues with Stack overflows, processor lockup and lost Telnet data when using both at the same time!

- If Telnet works but the socked does not disconnect properly when closed by the remote client, check you have initialised the Tick(TCP/IP timing) functions and have it correctly called in the interrupt routines!

- Microchip have not bothered to implement Telnet properly. On connection a Telnet connection sends a bunch of options back and forwards to work out what each side can do. The Microchip example ignores these so you get 'junk' data on connection. HyperTerminal on windows sends 6 bytes of settings which the Microchip example ignores completely, Putty sends about 30 bytes which causes problems!

Fixing Telnet:

Telnet options are send as IAC (Interpret As Command) codes. Each basic command is 3 bytes, the first byte is always 0xFF.

This site explains the main problems with the Telnet control simply and easily

Here is a description of the IAC command protocol

Here is a full list of the Telnet IAC codes (this was difficult to find!)

The simple solution:
when you find an 0xFF byte in the Telnet data, you need to remove it, and the next 2 bytes and process them separately. You 'could' just throw them away, but that breaks the spec. Processing them is simple...

If you receive:
Send back again:

If you receive:
Send back again:

You just need to change the middle byte and send it back. For each 'request' the client is making, you are refusing them. This forces the Telnet connection into the most basic form which all terminals should be able to deal with.

If you want more control, you may want to accept some of the options or send your own option requests. This is easy to do but its best to wait until the client has sent all its options them make any change requests you need. This helps avoid confusion where you can get into a loop, fighting over the option settings!

The most common one to handle is 'ECHO' to decide which side, if any will echo characters, description of the command here

Good luck!

Comments

Popular posts from this blog

JTAG Progromming on a PIC

Using Plink.exe from C# (accessing a linux PC)

Evohome problems on Danfoss RAS-C2 valves