c# - Mifare DESFIRE EV1 GetCardUid -
c# - Mifare DESFIRE EV1 GetCardUid -
the next code works , allows me uid of mifare 1k card. unfortunately, not work desfire cards.
public byte[] getuid() { byte[] uid = new byte[6]; int rc = communicate(new byte[]{0xff, 0xca, 0x00, 0x00, 0x04}, ref uid); if (rc != 0) throw new exception("failure: " + rc); int rc1, rc2; if (uid.length == 2) { rc1 = uid[0]; rc2 = uid[1]; } else { rc1 = uid[4]; rc2 = uid[5]; } if (rc1 != 0x90 || rc2 != 0x00) throw new exception("failure: " + rc1 + "/" + rc2); byte[] result = new byte[4]; array.copy(uid, result, 4); homecoming result; }
i had @ next resources
http://ridrix.wordpress.com/2009/09/19/mifare-desfire-communication-example/ http://code.google.com/p/nfc-tools/source/browse/trunk/libfreefare/libfreefare/mifare_desfire.c?r=532... , tried this:
byte[] outb = new byte[15]; int rc9 = communicate(new byte[] { 0x60 }, ref outb);
outb contains { 0x67, 0x00 } , not, expected, { af 04 01 01 00 02 18 05 }.
connect sucessful, , scardgetattrib allows me fetch atr. communicate method works scardtransmit. can post code if helps.
thanks pointer!
edit:
thanks first answer! changed programme suggested:
byte[] outb = new byte[9]; int rc5 = communicate(new byte[]{0x90, 0x60, 0x00, 0x00, 0x00, 0x00}, ref outb);
now outb { 0x91, 0x7e }. seems better, 0x91 looking iso 7816 response code, unfortunately not 0x90, expected. (i had @ desfire_transceive macro in sec link continues reading if receives 0xf2.) tried google search iso 7816 apdu response codes, had no success in decoding error code.
edit 2:
i found next comment:
with omnikey 5321 desfire atr 3b8180018080 uid 04 52 2e aa 47 23 80 90 00 [from apdu ffca000000] other apdu give 917e unknown error
this explains error code , gives me hint, ffca000000 looking quite similar other mifare 1k string. ffca000000 9 byte response seem contain uid. interestingly, ffca000000 code works 1k cards, maybe solution alter lastly 04 00 , deal responses of different length. right?
edit 3:
it seems penny has dropped... 0x04 = 4 bytes response = little 7 byte uid = response 917e = buffer little :-)
try "native wrapped" version of first link supplied instead. interface expects iso 7816-4 style apdu's (as returns iso 7816-4 status word meaning wrong length).
c# .net smartcard des mifare
Comments
Post a Comment