How to use The TNC-X USB module under Linux

I recently acquired and built the TNC-X KISS mode TNC from John Hansen. I opted to purchase the USB module as well, which not only frees up a COM port on the computer but also powers the TNC, saving the need for yet another wall wart. My plan for the TNC-X was to use it in conjunction with the fantastic Xastir software under Linux.

Unfortunately, The TNC-X USB module as shipped by John Hansen is not natively supported under Linux. Us Linux users are in luck, however, for two reasons:

1) The USB module shipped with the TNC-X is manufactured by FTDI. Recent 2.4 and 2.6 kernels include support for the FTDI USB modules. This driver is completely compatible with the TNC-X USB module provided by John, but the driver does not recognise the TNC-X's PID. Thus, all we need to do is "teach" the driver to recognise the TNC-X as something it can support.

2) Dave Platt, AE5EO, discovered this compatibility and submitted a patch to the FTDI driver that would accomplish this.

Unfortunately, Dave's patch was specifically for the 2.4.22 Linux kernel, and I was using 2.4.27 on one machine and 2.6.9 on another. Also, there were no instructions with the patch, so those without experience in hacking at or patching source files may not know where to begin.

Using Dave's patch as a starting point, I began manually editing the source files for the FTDI driver, and was quite successful in getting the TNC-X and Linux to play nicely together. Hopefully this HOWTO will help you be just as successful.

Before you begin, I highly recommend that you test your TNC-X out on a Windows computer using the drivers on John's website at www.tnc-x.com. This will make sure that any problems you may encounter later are with Linux and not because of a faulty TNC-X.

Also before you begin, remember that you could render your Linux system unbootable or otherwise unuseable by messing up while playing around with the kernel. If you are not comfortable with following these steps, don't!! Or, find someone who has compiled kernels before to help. Your local linux users group could be helpful. Remember, I AM NOT RESPONSIBLE FOR ANYTHING BAD THAT HAPPENS!!! If you're reading this, you're likely a ham operator. If you're a ham operator, you probably don't mind the potential of breaking things! :)

I have tried this successfully on kernel versions 2.4.27 and 2.6.9, but it should work with any recent kernel.

Step 1: Download and configure the kernel source

Unfortunately this modification does require re-compiling your kernel. Doing this is never fun (for me at least), but depending on your Linux distribution of choice, it can be somewhat painless. I use Debian, which has a fantastic package ("kernel-package") available that makes compiling and installing a new kernel much easier than it generally would be.

Step by step instructions for "rolling your own" kernel are beyond the scope of this HOWTO. If you are not familiar with building a custom kernel, you will want to pause at this step and google around for a guide. If you use Debian, a very easy to follow guide is available here:

http://newbiedoc.sourceforge.net/system/kernel-pkg.html

As an unrelated tip, you will probably want to use your existing kernel's configuration as a starting point. Otherwise you might forget to include something important. The existing kernel configuration should be stored in the /boot directory, called config-x.xx or something similar. You can use the "load" feature when configuring the kernel to load the current options.

When configuring your kernel, you will need to make sure the FTDI serial drivers are enabled. In the 2.4 kernels, this is under:

USB Support -> USB Serial Converter Support -> USB FTDI Single Port Serial Driver

In the 2.6 kernels, it can be found under:

Device Drivers -> USB Support -> USB Serial Converter Support -> USB FTDI Single Port Serial Driver

Regardless of kernel, set it to be included as a module, not statically compiled into the kernel. This is identified by an M under menuconfig, not an asterisk or a blank.

You might want to consider turning on some of the kernel AX.25 and KISS features, found under the Ham Radio category. This is once again beyond the scope of this HOWTO though. These extra modules are not necessary for most applications, but if you plan on doing TCP/IP over AX.25 or other more advanced applications.

Whatever distribution and instructions you follow, you will want to jump down to step 2 of this HOWTO somewhere after configuring the kernel (using make menuconfig or whatever method you use), but somewhere before you actually begin compiling the kernel.

Step 2: Modify the FTDI driver source files.

Right before you start compiling and installing the kernel files, you will need to make the actual modifications to the driver files to support the TNC-X. Begin by determining which directory the kernel source is in. In most cases, it will be /usr/src/linux or /usr/src/linux-x.x.xx (with the x's being the kernel version number). Assuming the former, the drivers are located in:

/usr/src/linux/drivers/usb/serial

Replace the /usr/src/linux with whatever directory your source files are in. There are two files in this location that we will need to edit. Use your favorite text editor to edit these -- I personally use nano, because I've never left that "newbie" stage. You can also use emacs, vi, joe, pico, or whatever you like. You can also use a graphical editor -- anything you are comfortable searching and editing with. Before we edit though, it's probably a good idea to make a backup copy of the two files we will be editing:

cp ftdi_sio.c ftdi_sio.c.old
cp ftdi_sio.h ftdi_sio.h.old

Now let's edit the first file, ftdi_sio.c.

nano -w ftdi_sio.c

In this file, search for the first line containing the text DSS20. It should look exactly like this:

{ USB_DEVICE_VER(FTDI_VID, FTDI_DSS20_PID, 0, 0x3ff) },

Immediately following that line, insert the following line on its own blank line:

{ USB_DEVICE_VER(FTDI_VID, FTDI_TNC_X_PID, 0, 0x3ff) },

Once again, search for the text DSS20. The next line found should look like this:

{ USB_DEVICE_VER(FTDI_VID, FTDI_DSS20_PID, 0x400, 0xffff) },

Again put a blank line right after the line above, and insert this:

{ USB_DEVICE_VER(FTDI_VID, FTDI_TNC_X_PID, 0x400, 0xffff) },

For a third and final time, search for the text DSS20. The line looks like this:

{ USB_DEVICE(FTDI_VID, FTDI_DSS20_PID) },

And again, insert this on the very next line:

{ USB_DEVICE(FTDI_VID, FTDI_TNC_X_PID) },

Now that you have added three lines to the file, save and exit. Now move on to the second and last file, ftdi_sio.h:

nano -w ftdi_sio.h

I lied -- you'll need to search this new file for the text DSS20 one more time. The resulting line will be:

#define FTDI_DSS20_PID 0xFC82

Let's add a new line after the above one containing this:

#define FTDI_TNC_X_PID 0xEBE0

Now save this file and exit. You've now made all of the modifications necessary to your kernel source.

Step 3: Compile and install your new kernel

If you've been following a custom kernel guide, go back to it now to finish compiling and installing your kernel. This will take between 15 minutes and a few hours, depending on what options your kernel is enabling and how fast your processor is. Go grab a coffee or watch Family Guy reruns for a bit.

Once your kernel has completed compiling, assuming it didn't die with any errors, reboot your system. At the GRUB or LILO screen, be sure to choose the kernel you just built. Many distributions will default to the previous version of the kernel.

Step 4: Test 'er out!

Once you have booted into your new kernel, you're ready to plug in your TNC-X!! Uups, you already did? No biggie, it should be recognised. If you haven't plugged it in to an available USB port yet, go for it! An easy way to check and see if your unit was recognised is:

dmesg | grep -i ftdi

This should return a few lines about USB serial, FTDI, etc etc. If you see nothing, your kernel did not recognise the TNC-X for some reason. Make sure the cables are tight, check all of the previous steps, etc.

If you do see the correct messages, your device should be registered. Linux will usually register the TNC-X as /dev/ttyUSB0. If you have other USB adaptors that convert to serial, it might be /dev/ttyUSB1, /dev/ttyUSB2, etc. As a final test, enter a program that supports KISS mode TNC's. I use the fantastic Xastir APRS program. You can use any packet mode you wish. Tune to 144.39, or any other frequency you'll see APRS or other packet traffic, and make sure everything is working.

That's it!! If you have any problems, e-mail me at matt /at/ podsix \dot\ org and I will do my best to help. I'm a far cry from a developer though, and I'm more familiar with Debian than with other distros, so I may or may not be a help.