aga
aga

Reputation: 29434

Writing data to a MIFARE card fails with 917E

I have an Android app that programs MIFARE cards (changes encryption mode from DES to AES, creates apps, writes some data to those apps - that sort of thing).

I'm using the standard WriteData command which is supposed to have several parameters:

It works fine with I'm trying to write small chunks of data (i.e. the data gets written correctly, the NFC card that I use does not report any CRC calculation problems, etc, etc)

The problems start when I need to write larger chunks of data (so that the card responds with 0x91AF, asking me to provide additional data frames). No matter how I calculate the CRC for a second data frame, the card always responds with 0x911E (which is an Integrity Error, according to the documentation).

So here's what I tried:

  1. The CRC calculation for a first data frame works over the command byte + file id + length + offset + first piece of data (I'm limiting it to 28 bytes). So, naturally, I thought that the second data frame is supposed to have the same structure and the CRC has to be calculated in the same manner - but when I did that I received 0x917e, which is a length error
  2. I looked over the documentation and I found on page 59 that subsequent data frames do not have the metadata (file id + length + offset) attached. So now I changed CRC calculation so that it's calculated over a command byte (0xAF) and a second piece of data, and I stopped adding metadata to the data frame. So the overall structure is now command byte + encrypted payload (which is a second data piece + CRC). The Length Error is gone, but the Integrity Error is raised
  3. I tried changing the command byte used in CRC calculation to 0x3D, but send the command with 0xAF. Still the same error

I'm a bit at loss here since I can't find a simple example on how the data exchange between PICC and PCD is supposed to look like in case a sequence of bytes that does not fit into a single frame has to be written to a standard file. Does anyone have an idea of what might be wrong?

Upvotes: 0

Views: 101

Answers (0)

Related Questions