\r
*key = -1;\r
\r
- UsbCommand c = {CMD_MIFARE_CHKKEYS, {((blockNo & 0xff) | ((keyType&0xff)<<8)), clear_trace, keycnt}};\r
+ UsbCommand c = {CMD_MIFARE_CHKKEYS, {((blockNo & 0xff) | ((keyType & 0xff) << 8)), clear_trace, keycnt}}; \r
memcpy(c.d.asBytes, keyBlock, 6 * keycnt);\r
SendCommand(&c);\r
\r
UsbCommand resp;\r
- if (!WaitForResponseTimeout(CMD_ACK,&resp,3000)) return 1;\r
+ if (!WaitForResponseTimeout(CMD_ACK,&resp,3000)) return 1; \r
if ((resp.arg[0] & 0xff) != 0x01) return 2;\r
*key = bytes_to_num(resp.d.asBytes, 6);\r
return 0;\r
}\r
\r
+int mfCheckKeysSec(uint8_t sectorCnt, uint8_t keyType, uint8_t timeout14a, bool clear_trace, uint8_t keycnt, uint8_t * keyBlock, sector_t * e_sector){\r
+\r
+ uint8_t keyPtr = 0;\r
+\r
+ if (e_sector == NULL)\r
+ return -1;\r
+\r
+ UsbCommand c = {CMD_MIFARE_CHKKEYS, {((sectorCnt & 0xff) | ((keyType & 0xff) << 8)), (clear_trace | 0x02)|((timeout14a & 0xff) << 8), keycnt}}; \r
+ memcpy(c.d.asBytes, keyBlock, 6 * keycnt);\r
+ SendCommand(&c);\r
+\r
+ UsbCommand resp;\r
+ if (!WaitForResponseTimeoutW(CMD_ACK, &resp, MAX(3000, 1000 + 13 * sectorCnt * keycnt * (keyType == 2 ? 2 : 1)), false)) return 1; // timeout: 13 ms / fail auth\r
+ if ((resp.arg[0] & 0xff) != 0x01) return 2;\r
+ \r
+ bool foundAKey = false;\r
+ for(int sec = 0; sec < sectorCnt; sec++){\r
+ for(int keyAB = 0; keyAB < 2; keyAB++){\r
+ keyPtr = *(resp.d.asBytes + keyAB * 40 + sec);\r
+ if (keyPtr){\r
+ e_sector[sec].foundKey[keyAB] = true;\r
+ e_sector[sec].Key[keyAB] = bytes_to_num(keyBlock + (keyPtr - 1) * 6, 6);\r
+ foundAKey = true;\r
+ }\r
+ }\r
+ }\r
+ return foundAKey ? 0 : 3;\r
+}\r
+\r
// Compare 16 Bits out of cryptostate\r
int Compare16Bits(const void * a, const void * b) {\r
if ((*(uint64_t*)b & 0x00ff000000ff0000) == (*(uint64_t*)a & 0x00ff000000ff0000)) return 0;\r