home   articles   archive   forum   masthead  
Published at 6.1.2002
Author: Matthias Kranz
Translator: Tobias Bayer
Languages: de
Printer printer-version
Support Us!

Chipdrive - Reading chipcards

(Latest source code for accessing the Medical Insurance Card)


Towitoko chipdrive


Have you ever wanted to know what is on your medical insurance card? Are you interested in chipcard technology under Linux? If so, this article is a fine introduction for you!


Meanwhile, there are many chipdrives that are supported by Linux. Among others, the drives from Towitoko (http://www.towitoko.de) are supported, which have the term CHIPDRIVE in their names and get connected to the serial port. Other manufacturers of low priced chipcard terminals are:

Chipcard types

Three basic card types do exist:

  • Magnetic cards
  • Processor cards
  • Memory cards

Since the drives listed above only support the last two types, we will not dwell on magnetic cards (e.g. EC-cards, credit cards).

Processor cards

Processor cards are chipcards that have an own microprocessor, RAM, ROM and EEPROM (Electronically Erasable Read Only Memory) to execute sophisticated applications. Usually these cards are programmed in JAVA or BASIC; the programs are stored in the EEPROM.

Memory cards

Memory cards do not have any intelligence except for protecting saved data from unauthorized access. These cards are used as medical insurance cards or phone cards, for example.

But there are also contactless cards, e.g. by Legic (http://www.legic.de). These are especially suitable for security-sensitive sectors such as authentication or cashless payments. These cards are much more complex and the necessary hardware is much more expensive. They are mentioned here only for the sake of completeness.

More information on types of chipcards can be found at http://www.heise.de/ ix/artikel/2000/12/152/04.shtml.

Chipdrive micro 120 the Linux pack

Because we own two pieces of Towitoko Chipdrive micro 120 (the Linux pack from Towitoko's online store), the following implementations refer to these models. The Linux pack contains two chipcards:
a memory card with 256 bytes and a processor card with 2048 bytes capacity. With these, you can do some nice experiments.

If you are a customer of the Dresdner Bank, you can register for online banking and get a Chipdrive micro 120 for free. You do not have to use it for online banking (if you are somehow paranoid or you do not trust online banking ;-).

Serial plug

To use the chipdrive under Linux, you need a driver for it. The driver is used to manage the serial port and it provides a comfortable API (Application Programming Interface) known as the CTAPI (Card Terminal Application Programming Interface). The driver is available here (or on our server).

Driver Installation

The driver can be unpacked by:

  >> tar -zxvf towitoko.tar.gz

and then configured and compiled by:

  >> ./configure && make

in the Towitoko directory.
Now become root and enter:

make install

to copy the driver to the right location.
If the medical card reader complains about a missing library, you have to copy the libraries from /usr/local/towitoko/lib/ to /usr/lib or add the path /usr/local/towitoko/lib/ to the LD_LIBRARY_PATH.

Afterwards, you should execute:


to make sure that the new library is found by the system.


You can now start developing your own programs. You should look at the test program that comes with the Towitoko drivers. Many chipcard accessing functions are already implemented there - but not well documented. It is adviseable to read the CTAPI documentation. In this documentation, all available commands are documented extensively. Programming is easy because there are only three commands:

  • CT_init - Initialize the card terminal and start communication with the terminal.
  • CT_data - Chipcard access; send commands to the chipcard
  • CD_close - Stop communication; equivalent to CT_init

The basic structure of the CT_data command looks as follows:


the parameters are defined as:

  • ctn: Logical Card Terminal Nummer
  • dad: Destination Address
  • sad: Source Address
  • commands: Number of commands
  • command: commands to the chipdrive
  • response: Response to command from the chipdrive

You can find an exact specification in the API.

Since we have not found any working program on freshmeat.net (http://www.freshmeat.net) to read our medical insurance card quickly, we have used this as an example.

Source code for accessing the medical insurance card

medical-card-reader.c and the suitable Makefile

The documentation can be found in the source code. The dependencies are:

  • Necessary libraries:
    libtowitoko (towitoko.tar.gz)
  • Necessary headers:
    /usr/local/towitoko/include/ctacs.h (download)
    /usr/local/towitoko/include/ctapi-add.h (download)

Program structure

The basic structure of the program is:

    A chipcard is requested
  • Terminal reset
    Read the relevant data area of the card
    The chipcard is ejected.

We did not implement any functions for writing to the chipcard because the insurance cards do not have any write protection. If you consider manipulating the data on the card, you have to pay attention to writing the correct checksum. How to calculate this checksum is explained at http://themen02.mytoday .de/user/member/chipcard/ (download at the bottom).

The source code provided there does not compile (on our system) but the function for calculating the checksum is included. Oh, . . . it takes about two weeks until your medical insurance company sends you a new card....*sigh*

More application opportunities for chipcards

As further applications for chipcards you can imagine:

  • user authentication
  • saving crypto keys (e.g. for PGP, RSA, etc.)
  • deduction and payment procedures

Have fun with playing and programming,
Matthias Kranz




Information on chipdrives:

Information on medical insurance cards and phone cards:



Talkback Area

Enter Own Comment