[ DIY ]

PASSING ON THE TARSYS LEGACY

+

With a project like TARSYS, it is vital that others are able to learn how it works.

It can effectively give the project immortality, so that it may continue its work after a potential shutdown.

SYSTEM DESIGN

To understand TARSYS, let's look at its constitutent parts

I

SHEATH is:

  1. A desktop application using Electron
  2. Utilizes nfc-pcsc for NFC integration
  3. Implements a ACR122U USB NFC reader to communicate with TARCELs

Frankly, SHEATH can be greatly improved. nfc-pcsc is a bit outdated and incompatible with the newest version of Node.js. This can make installation rather nightmarish. So it might be better to talk about the code in a general sense so the logic may be applied in other languages.

If you are curious as to the Javascript implementation, the project GitHub can be found here.

NFC communication is a technology that is more reasonably achieved in non-Node environments. Nonetheless, the steps for interfacing with the cards will be the same, so the logic can still apply.

II

TARCELs are:

  1. MIFARE DESFire EV3 8KB NFC cards
  2. Can go up to 32KB of storage
  3. PVC Plastic
  4. 3.375 in. (85.6mm) x 2.125 in. (53.98mm)

There are a wide variety of different NFC chip types available for purchase and use. However, the DESFire platform was specifically useful for two main features: storage capacity and memory flexibility.

DESFire chips can store the most memory of any NFC chip, which is the most essential feature for our use case. There are also other chips with high storage but that memory is not flexible (namely, MIFARE Classic). This means that a lot of the memory isn't actually useable and is heavily partioned and separated. DESFire is not like this and we can structure our data pretty freely, being able to use up nearly all of the card's actual storage however we see fit.

However, there are some drawbacks. The DESFire, in standard applications, is highly praised for its security features. In order to maintain this, all of the documentation is behind a heavy NDA. Thus, finding the information necessary to work on the card can be extremely difficult.

Yet, there is hope.

A SHINING LIGHT

III

This is the part where I state my immense gratitude to the NFC open-source community.

I won't link it here for fear of takedown, but there is a Holy Grail document that perfectly outlines all of the necessary information to work with MIFARE DESFire cards on GitHub.

The document is fully reverse-engineered, so you will not break NDA by using and referring to it. It also states that it is for EV1, but has worked fine (so far) for my use of EV3.

Should one wish to find it, Googling MIFARE DESFire PDF seems to work.

IV

The other crucial aspect of working with DESFire cards specifically is how you authenticate with them. It's a very specific sequence of steps that must be done exactly in order to do ANY sort of operation on the card.

Of course, the steps for doing exactly that in Javascript just so happens to be perfectly documented in an example code in the nfc-pcsc GitHub. These steps must be done prior to any command sent to the card, or else nothing will happen.

I also wish to mention that the margin of error for this project is INCREDIBLY slim. Had it not been for these two masterpieces of the NFC dev community, this project could not exist. My deepest gratitude to all those involved.

EXTRAPOLATION AND EXTENSION

+

Now, there are some additional bits and pieces of information that should be mentioned so as to make the process a bit easier to understand.

V

For one, NFC cards store binary data. This means that each single character is stored as a number from 0 to 255, like an "R" value in a RGB color. Now, these numbers are easily interpretable for computers but humans, not so much. Thus, it is essential that you convert these numbers into hexadecimal or ASCII.

VI

Note that all of the commands and status codes in the DESFire.pdf are referred to in hexadecimal format. As for sending these commands, look at the example in the nfc-pcsc GitHub. That example specifically mentions reading from a DESFire card. If we browse the code, we see that it (in the try {}) selects an application, gets the key, authenticates with the key and then reads the data. Notice how for each of these functions, the code uses the send() command with a parameter of "0x" followed by a hexadecimal number.

VII

This is the essential method of sending commands to the card. All of the commands can be found in the PDF but, effectivelly, you are just sending a special hexadecimal number that then triggers the action in the card. This can be select application (0x5A), read data (0xBD), and so on and so forth.

VIII

A peculiar detail that is also extremely important: DESFire EV3s can read a maximum of 256 bytes in a single command and only write a maximum of 55 bytes. Thus, if more data needs to be read or written then you would have to loop repeatedly in chunks of 256 or 55 bytes respectively.

IX

The DESFire storage structure is based on files and applications. The storage is first broken up into one or more applications. Then, each application can have multiple files for storing information.

When working with the card, you choose a particular application and you work with that specific application until you change. For this project it makes sense to work with a single application and file so that you can use the full storage capacity. Of course, this can be customized as you see fit.

Each application has a specific key/ID represented by 3 bytes. I recommend using the :Get Application IDs" command (0x6A) and then this allows you to just keep the default application key with a single file, making for the simplest and most efficient workflow.

X

NXP (the manufacturing company behind the chips) offets their own mobile apps for working with their chips. I HIGHLY recommend using these as they can offer a lot of useful information without needing much work on your end.

For one, you can list all of the data on a DESFire card and how it is structured regarding the applications and files.

Another crucial factor is formatting as NDEF. This is EXTREMELY important and can be a source of errors. When working with a newly purchased card, it may be necessary to format it as NDEF to allow it to work. This process is very simple to do when using the NXP app and just involves a simple buttton tap.

XI

Also, as general rule, Android devices are superior to iOS devices regarding NFC technology. It is far less restricted and can make working with NFC cards much easier.

The NXP apps on Android are far more robust than the iOS ones.

Hierarchy 2 Streamline Icon: https://streamlinehq.com