]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/mifarehost.c
A lot of changes...
[proxmark3-svn] / client / mifarehost.c
index 6acd22f8cb0e0cdaa287b3f0023b6256b4ff9e27..d3f4a4cde6f55b64a4c75dfb9dd9dd1c2ecb9e21 100644 (file)
@@ -93,16 +93,16 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo
                return resp.arg[0];  // error during nested\r
        }\r
                \r
-                       memcpy(&uid, resp.d.asBytes, 4);\r
+       memcpy(&uid, resp.d.asBytes, 4);\r
        PrintAndLog("uid:%08x trgbl=%d trgkey=%x", uid, (uint16_t)resp.arg[2] & 0xff, (uint16_t)resp.arg[2] >> 8);\r
                        \r
-                       for (i = 0; i < 2; i++) {\r
-                               statelists[i].blockNo = resp.arg[2] & 0xff;\r
-                               statelists[i].keyType = (resp.arg[2] >> 8) & 0xff;\r
-                               statelists[i].uid = uid;\r
-                               memcpy(&statelists[i].nt,  (void *)(resp.d.asBytes + 4 + i * 8 + 0), 4);\r
-                               memcpy(&statelists[i].ks1, (void *)(resp.d.asBytes + 4 + i * 8 + 4), 4);\r
-                       }\r
+       for (i = 0; i < 2; i++) {\r
+               statelists[i].blockNo = resp.arg[2] & 0xff;\r
+               statelists[i].keyType = (resp.arg[2] >> 8) & 0xff;\r
+               statelists[i].uid = uid;\r
+               memcpy(&statelists[i].nt,  (void *)(resp.d.asBytes + 4 + i * 8 + 0), 4);\r
+               memcpy(&statelists[i].ks1, (void *)(resp.d.asBytes + 4 + i * 8 + 4), 4);\r
+       }\r
        \r
        // calc keys\r
        \r
@@ -190,8 +190,7 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo
        }\r
        \r
        free(statelists[0].head.slhead);\r
-       free(statelists[1].head.slhead);\r
-       \r
+       free(statelists[1].head.slhead);        \r
        return 0;\r
 }\r
 \r
@@ -201,8 +200,9 @@ int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t key
 \r
        UsbCommand c = {CMD_MIFARE_CHKKEYS, {((blockNo & 0xff) | ((keyType&0xff)<<8)), clear_trace, keycnt}};\r
        memcpy(c.d.asBytes, keyBlock, 6 * keycnt);\r
+       \r
+       clearCommandBuffer();\r
        SendCommand(&c);\r
-\r
        UsbCommand resp;\r
        if (!WaitForResponseTimeout(CMD_ACK,&resp,3000)) return 1;\r
        if ((resp.arg[0] & 0xff) != 0x01) return 2;\r
@@ -214,8 +214,8 @@ int mfCheckKeys (uint8_t blockNo, uint8_t keyType, bool clear_trace, uint8_t key
 \r
 int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) {\r
        UsbCommand c = {CMD_MIFARE_EML_MEMGET, {blockNum, blocksCount, 0}};\r
+       clearCommandBuffer();\r
        SendCommand(&c);\r
-\r
        UsbCommand resp;\r
        if (!WaitForResponseTimeout(CMD_ACK,&resp,1500)) return 1;\r
        memcpy(data, resp.d.asBytes, blocksCount * 16);\r
@@ -223,8 +223,14 @@ int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) {
 }\r
 \r
 int mfEmlSetMem(uint8_t *data, int blockNum, int blocksCount) {\r
-       UsbCommand c = {CMD_MIFARE_EML_MEMSET, {blockNum, blocksCount, 0}};\r
-       memcpy(c.d.asBytes, data, blocksCount * 16); \r
+       return mfEmlSetMem_xt(data, blockNum, blocksCount, 16);\r
+}\r
+\r
+int mfEmlSetMem_xt(uint8_t *data, int blockNum, int blocksCount, int blockBtWidth) {\r
+       UsbCommand c = {CMD_MIFARE_EML_MEMSET, {blockNum, blocksCount, blockBtWidth}};\r
+       memcpy(c.d.asBytes, data, blocksCount * blockBtWidth); \r
+\r
+       clearCommandBuffer();\r
        SendCommand(&c);\r
        return 0;\r
 }\r
@@ -264,8 +270,9 @@ int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, bool wantWipe, uin
        uint8_t isOK = 0;\r
        UsbCommand c = {CMD_MIFARE_CSETBLOCK, {wantWipe, params & (0xFE | (uid == NULL ? 0:1)), blockNo}};\r
        memcpy(c.d.asBytes, data, 16); \r
-       SendCommand(&c);\r
 \r
+       clearCommandBuffer();\r
+       SendCommand(&c);\r
        UsbCommand resp;\r
        if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
                isOK  = resp.arg[0] & 0xff;\r
@@ -284,9 +291,10 @@ int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) {
        uint8_t isOK = 0;\r
 \r
        UsbCommand c = {CMD_MIFARE_CGETBLOCK, {params, 0, blockNo}};\r
+       \r
+       clearCommandBuffer();\r
        SendCommand(&c);\r
-\r
-  UsbCommand resp;\r
+       UsbCommand resp;\r
        if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
                isOK  = resp.arg[0] & 0xff;\r
                memcpy(data, resp.d.asBytes, 16);\r
Impressum, Datenschutz