X-Git-Url: http://cvs.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/873014de8a4be0f68524531cc90fe6c1dfdffded..ec56429002dbccf8af357253a758ec88f359a21e:/client/mifarehost.c diff --git a/client/mifarehost.c b/client/mifarehost.c index c6f2fe3f..fb6a4bdb 100644 --- a/client/mifarehost.c +++ b/client/mifarehost.c @@ -1,4 +1,4 @@ -// Merlok, 2011 +// Merlok, 2011, 2012 // people from mifare@nethemba.com, 2010 // // This code is licensed to you under the terms of the GNU GPL, version 2 or, @@ -10,6 +10,7 @@ #include #include +#include #include "mifarehost.h" @@ -195,3 +196,74 @@ int mfCheckKeys (uint8_t blockNo, uint8_t keyType, uint8_t keycnt, uint8_t * key *key = bytes_to_num(resp->d.asBytes, 6); return 0; } + +int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) { + UsbCommand c = {CMD_MIFARE_EML_MEMGET, {blockNum, blocksCount, 0}}; + + SendCommand(&c); + + UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500); + + if (resp == NULL) return 1; + memcpy(data, resp->d.asBytes, blocksCount * 16); + return 0; +} + +int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount) { + UsbCommand c = {CMD_MIFARE_EML_MEMSET, {blockNum, blocksCount, 0}}; + memcpy(c.d.asBytes, data, blocksCount * 16); + SendCommand(&c); + return 0; +} + +int mfCSetUID(uint8_t *uid, uint8_t *oldUID, int wantWipe) { + uint8_t block0[16]; + memset(block0, 0, 16); + memcpy(block0, uid, 4); + block0[4] = block0[0]^block0[1]^block0[2]^block0[3]; // Mifare UID BCC + // mifare classic SAK(byte 5) and ATQA(byte 6 and 7) + block0[5] = 0x88; + block0[6] = 0x04; + block0[7] = 0x00; + + return mfCSetBlock(0, block0, oldUID, wantWipe, CSETBLOCK_SINGLE_OPER); +} + +int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, int wantWipe, uint8_t params) { + uint8_t isOK = 0; + + UsbCommand c = {CMD_MIFARE_EML_CSETBLOCK, {wantWipe, params & (0xFE | (uid == NULL ? 0:1)), blockNo}}; + memcpy(c.d.asBytes, data, 16); + SendCommand(&c); + + UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500); + + if (resp != NULL) { + isOK = resp->arg[0] & 0xff; + if (uid != NULL) memcpy(uid, resp->d.asBytes, 4); + if (!isOK) return 2; + } else { + PrintAndLog("Command execute timeout"); + return 1; + } + return 0; +} + +int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) { + uint8_t isOK = 0; + + UsbCommand c = {CMD_MIFARE_EML_CGETBLOCK, {params, 0, blockNo}}; + SendCommand(&c); + + UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500); + + if (resp != NULL) { + isOK = resp->arg[0] & 0xff; + memcpy(data, resp->d.asBytes, 16); + if (!isOK) return 2; + } else { + PrintAndLog("Command execute timeout"); + return 1; + } + return 0; +}