Under Construction!

Java iButtons under Linux

Here is what I did to get my Dallas Semiconductor Java iButton working under Linux. I am using Sun's JDK 1.3, which is assumed to be installed in $JDK (on my system this is in /usr/java).

My iButton is a DS19550 (Java Crypto iButton) which is connected through a DS1402D (1-Wire) and a DS9097U (Serial adapter) to the serial port (/dev/ttyS0) of my computer.

Accessing the Serial Ports: Javacomm and RXTX

First, you need Sun's Java Communications API, available from http://java.sun.com/products/javacomm/. Get the Solaris version. After unpacking the archive, you will have a comm.jar file (containing the javax.comm.* classes) which provides the Java API to communicate with the serial and parallel ports. Put comm.jar in $JDK/jre/lib/ext where javac can find it.

Next, download the RXTX package, available from http://www.rxtx.org. This contains the native code which does the actual talking to the serial (and parallel) ports under Linux. Just follow the installation instructions (./configure; make; make install) and the installation procedure will detect your Java setup and the Java Communications API. It puts jcl.jar (containing the gnu.io.* classes) in $JDK/jre/lib/ext and, to tell the Java Communications API about RXTX, it creates a javax.comm.properties file in $JDK/jre/lib with a single line:

Driver=gnu.io.RXTXCommDriver

You can test whether it works by running the SerialDemo which is one of the samples that come with the Java Communications API. Make sure the device corresponding to the port you are trying to open (for example /dev/ttyS0) is readable and writable by the current user. It may help to add this user to the uucp group. Also, I needed to change the permissions of the /var/lock directory to allow non-root users to create lock files for the devices.

Writing an Applet: The JavaCard API and iB-IDE

Applets use the JavaCard API (version 2.0). A reference implementation of this API is available from http://java.sun.com/products/javacard/. However, for the iButton we use an implementation of the API that comes with the iB-IDE program, available from ftp://ftp.dalsemi.com/pub/iB-IDE_1.10. Although I do not use the iB-IDE myself, it seems to be the only source for the necessary tools for compiling and installing applets onto iButtons. Install the iB-IDE using its graphical installer and locate the classes directory. This contains .jar files for different iButtons. The iButton41.jar and the jib41.jibdb files are needed for the DS19550 iButton.

As an example, consider the following JavaCard applet which just echoes the information it receives in the apdu buffer. This is the simplest applet I could think of.

   import javacard.framework.*;

   public class EchoApplet extends Applet {

      public static void install(APDU apdu) {
         new EchoApplet();
      }

      public void process(APDU apdu) {
         apdu.setIncomingAndReceive();
         byte[] buffer = apdu.getBuffer();
         apdu.setOutgoingAndSend((short)0,(short)buffer.length);
      }
   }

The above code is located in a file called EchoApplet.java. Compiling it into a .jib file is done as follows.

   javac -classpath iButton41.jar EchoApplet.java
   java BuildJiBlet -d jib41.jibdb -f EchoApplet.class -o echoapplet.jib

Writing a Terminal application: The OneWire API

In order to write terminal applications we install Dallas Semiconductor's OneWire API, available from ftp://ftp.dalsemi.com/pub/auto_id/public. After unpacking the archive, you will have a file called OneWireAPI.jar. Put this file in $JDK/jre/lib/ext where javac can find it. The API uses a onewire.properties file in the $JDK/jre/lib directory, containing the following:

   onewire.adapter.default=DS9097U
   onewire.port.default=/dev/ttyS0

The OneWire API contains classes for the different devices that can be connected to a 1-Wire network (the OneWireAPI.jar contains the com.dalsemi.onewire.* classes). Functionality for loading, deleting and communicating with Java iButtons is available in the OneWireContainer16 class.