librfid - A free software RFID stack The librfid project intends to provide a free software reader-side implementation of common RFID protocols such as ISO 14443, ISO 15693. Careful design and various abstraction layers should enable it to include support for various readers and protocols, even though as of now only a single reader and ISO 14443(A+B) is implemented.
Data Structures The librfid codebase is very modular and therefore data-centric. It is therefore important to understand the various data structures and how they interact.
struct rfid_asic A struct rfid_asic is the integral part of every supported reader. A separation between ASIC and reader makes sense, since almost all of the existing readers use one of the few available ASIC solutions from Philips, TI and the like.
struct rfid_asic_transport A struct rfid_asic_transport connects a struct rfid_asic to librfid. This transport is usually limited to very few essential primitives. With the Philips CL RC632, the asic transport has to provide four primitives: read/write register, and read/write FIFO.
struct rfid_reader A struct rfid_reader contains information about the specific configuration of the ASIC as well as the transport.
struct rfid_layer2 A struct rfid_layer2 implements the anticollision procedure, such as ISO 14443-3.
struct rfid_protocol A struct rfid_protocol implements a transport protocol, such as ISO 14443-4
Runtime handles Each of the structures described above, have a _handle structure. The _handle (e.g. rfid_layer2_handle) saves instance-local state and allows the stack to identify the user.
Protocol Stack In the typical current setup (CardMan 5121 reader, ISO14443-123A, ISO14443-4), those data structures are stacked on top of each other like this: rfid_protocol_tcl rfid_layer2_iso14443a CM5121 reader CL RC632 asic PC_to_RDR_Escape transport USB-CCID libusb
Interaction with OpenCT
What is OpenCT OpenCT is a free software smart card reader driver package, originally developed for the OpenSC (http://www.opensc.org) project. As of now, it only supports contact based smart cards.
Integration with OpenCT First of all, why use OpenCT at all? Because like other "consumer" RFID readers, the 5121 supports contact based and contactless operation. Its contact based operation is already supported by the OpenCT ifd-ccid driver. Also, many "legacy" smart card applications expect to talk to a PC/SC or CT-API interface. OpenCT already provides a "ifdehandler" backend for pcsc-lite, as well as a CT-API wrapper. In addition, OpenCT suports a client/server architecture where readers can be shared in a network. If librfid was integrated with OpenCT, it could directly benefit from those features. On the other hand, there are many usage cases, where neither dual-interface operation nor a PC/SC API is applicable. This includes usage of passive (state machine) tags that do not speak sophisticate transport protocols such as 14443-4. Therefore, OpenCT integration on both backend and frontend can only be provided optionally, ant not made mandatory. The overall integration with OpenCT is: Export the PC_TO_RDR_ESCAPE based interface to the RFID Reader ASIC (Philips RC632) as a virtual slot (always the last slot number 2 of the cm5121). This virtual slot supports only one special protocol: The "ESCAPE" protocol. The RFID software stack opens this virtual slot to talk to the RFID Reader ASIC using the OpenCT API (CT_Card_Transact). The RFID software stack implements the various protocols and protocol layers The RFID software stack registers a number of slots as ifd-handler with OpenCT. The slots provide access to protocols like T=CL.
Application Interfaces
Native API The native API is the API that librfid uses internally. It reflects all features, and by it's very nature not compatible to any standard. Also, it is the only API that is fully supported at the time this paper was written. The API is not very comfortable, as many calls have to be made, and everything is explicit. There is no support for advanced features such as auto-detecting the standard/protocol a given tag supports. An application will likely start with rfid_init(), followed by rfid_reader_open(), rfid_layer2_init(), rfid_layer2_open(), rfid_protocol_init() and rfid_orotocol_open(). Data is transcieved to and from the tag by calling rfid_protocol_transcieve(). For an example on how to use the API, please look at the librfid/openct-secape.c program in the librfid source tree.
OpenCT, CT-API, PC/SC librfid will not by itself provide any of those interfaces, but rather implement an OpenCT backend driver (ifd-librfid). At the time of writing, such a backend did not yet exist.
Future Development librfid is currently in an early alpha/beta state. It is not yet ready for production use. Apart from a hand full of minor fixes from MaskTech GmbH, it's a one-man project. It's also not a project that I can focus on, because its main author has many other project and considers librfid more or less a "pet project". Therefore, skilled developers are needed. If you want to experiment with RFID technology, and really learn about the protocols instead of just using something ready-built, librfid should provide you with a good basis. The initial code is there, you can do something useful (namely: Talk to ISO14443-A and -B cards using T=CL protocol). If you feel like adding support for some other reader device, or further protocols, any help is appreciated. There's now also a development mailinglist at librfid-devel@lists.gnumonks.org.