Hello,

I've a problem when trying to access Mifare cards on which i'm stuck now for a while.

The first problem infolves reading the UID from the card I can't seem to find any APDU to do this but reading sector 0 block 0 should work since it's programmed and write protected by the card manufacturer. For a few cards this actually works fine but some card respond with an error. I sent:

< ATR 3B8F8001804F0CA0000003060300020000000069
> FF 82 00 00 06 A0 A1 A2 A3 A4 A5
< 90 00
> FF 88 00 00 60 00
< 69 83



With other cards that do respond reading sector 0 I've trouble calculating and verifying the CRC 8 of the MAD. I've also tried with the example card data from the M001824.pdf document. I'm completely bedazzled since the crc routine used works fine for cheking CRC's of CCIT and Onewire.

< ATR 3B8F8001804F0CA000000306030001000000006A
> FF 82 00 00 06 A0 A1 A2 A3 A4 A5
< 90 00
>  FF 88 00 00 60 00
< 90 00
> FF B0 00 00 10
< B2 A0 05 B3 A4 88 04 00 45 DE 8A 05 31 37 30 31 90 00
> FF B0 00 03 10
< 00 00 00 00 00 00 79 67 88 C1 00 00 00 00 00 00 90 00
> FF B0 00 01 10
< F2 00 02 00 02 00 02 00 03 38 03 38 02 00 02 00 90 00
> FF B0 00 02 10
< 02 00 02 00 02 00 02 00 02 00 02 00 02 00 02 00 90 00

After this I've filled an array with the MAD from sector 0 blocks 1 and 2 (the first byte in the following data is at raaray loication 0 so the CRC should calculate 0xF2 but it does calculate 0xD9 with the data from the datasheet is does calculate 0xA2 instead of 0x89

m_abMAD array contents for real card:
F2 00 02 00 02 00 02 00 03 38 03 38 02 00 02 00 02 00 02 00 02 00 02 00 02 00 02 00 02 00 02 00
Gives output:
CRC calculated D9 card data CRC F2

m_abMAD array contents for example card data from datasheet:
89 01 01 08 01 08 01 08 00 00 00 00 00 00 04 00 03 10 03 10 02 10 02 10 00 00 00 00 00 00 11 30
Gives output:
CRC calculated A2 card data CRC 89

   int  iCRC8 = crc8(0xE3, 0x00, 0x1D, m_abMAD, 1, 31);
System.out.println("CRC calculated " + Debug.toHex((byte)iCRC8) + " card data CRC " + Debug.toHex(m_abMAD[0]);

public static int crc8(int iStart, int iPost, int iPoly, byte[] abData, int iOfs, int iLen)
   {
       int iEnd = iOfs + iLen;
       int iCRC = iStart;

       for (int i=iOfs; i<iEnd; i++) {
           byte bData = abData[i];
           iCRC ^= bData;
//            System.out.println(" " + i + " -> " + Debug.toBin(bData));
           for (int j=7; j >= 0; j--) {
               if ((iCRC & 0x80) != 0) {
                   iCRC <<= 1;
                   iCRC  ^= iPoly;
//            System.out.println("      ^= " + Debug.toBin((byte)iCRC));
               }else {
                   iCRC <<= 1;
//            System.out.println("      <= " + Debug.toBin((byte)iCRC));
               }
           }
       }

       iCRC ^= iPost;
       return iCRC & 0xff;
   }


Also testing any polynomial gives no results:

   for (int i=0; i<256; ++i) {
       int  iCRC8 = crc8(0xE3, 0x00, i, m_abMAD, 1, 31);
if (iCRC8 == (m_abMAD[0] & 0xff)) System.out.println("Polynomial " + Debug.toHex((byte)i) + " matches");
   }

Any help or suggestions are very welcome

Yours sincerely
Christian




_______________________________________________
Muscle mailing list
[email protected]
http://lists.drizzle.com/mailman/listinfo/muscle

Reply via email to