commit
1eac72641c
2 changed files with 35 additions and 7 deletions
27
src/mfoc.c
27
src/mfoc.c
|
@ -219,12 +219,31 @@ int main(int argc, char *const argv[])
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save tag's block size (b4K)
|
|
||||||
t.b4K = (t.nt.nti.nai.abtAtqa[1] == 0x02);
|
|
||||||
t.authuid = (uint32_t) bytes_to_num(t.nt.nti.nai.abtUid + t.nt.nti.nai.szUidLen - 4, 4);
|
t.authuid = (uint32_t) bytes_to_num(t.nt.nti.nai.abtUid + t.nt.nti.nai.szUidLen - 4, 4);
|
||||||
|
|
||||||
t.num_blocks = (t.b4K) ? 0xff : 0x3f;
|
// Get Mifare Classic type from SAK
|
||||||
t.num_sectors = t.b4K ? NR_TRAILERS_4k : NR_TRAILERS_1k;
|
// see http://www.nxp.com/documents/application_note/AN10833.pdf Section 3.2
|
||||||
|
switch (t.nt.nti.nai.btSak)
|
||||||
|
{
|
||||||
|
case 0x08:
|
||||||
|
printf("Found Mifare Classic 1k tag\n");
|
||||||
|
t.num_sectors = NR_TRAILERS_1k;
|
||||||
|
t.num_blocks = NR_BLOCKS_1k;
|
||||||
|
break;
|
||||||
|
case 0x09:
|
||||||
|
printf("Found Mifare Classic Mini tag\n");
|
||||||
|
t.num_sectors = NR_TRAILERS_MINI;
|
||||||
|
t.num_blocks = NR_BLOCKS_MINI;
|
||||||
|
break;
|
||||||
|
case 0x18:
|
||||||
|
printf("Found Mifare Classic 4k tag\n");
|
||||||
|
t.num_sectors = NR_TRAILERS_4k;
|
||||||
|
t.num_blocks = NR_BLOCKS_4k;
|
||||||
|
break;
|
||||||
|
defaul:
|
||||||
|
ERR("Cannot determine card type from SAK");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
t.sectors = (void *) calloc(t.num_sectors, sizeof(sector));
|
t.sectors = (void *) calloc(t.num_sectors, sizeof(sector));
|
||||||
if (t.sectors == NULL) {
|
if (t.sectors == NULL) {
|
||||||
|
|
15
src/mfoc.h
15
src/mfoc.h
|
@ -2,11 +2,21 @@
|
||||||
#define TRY_KEYS 50
|
#define TRY_KEYS 50
|
||||||
|
|
||||||
// Number of trailers == number of sectors
|
// Number of trailers == number of sectors
|
||||||
// 16x64b = 16
|
// Mifare Classic 1k 16x64b = 16
|
||||||
#define NR_TRAILERS_1k (16)
|
#define NR_TRAILERS_1k (16)
|
||||||
// 32x64b + 8*256b = 40
|
// Mifare Classic Mini
|
||||||
|
#define NR_TRAILERS_MINI (5)
|
||||||
|
// Mifare Classic 4k 32x64b + 8*256b = 40
|
||||||
#define NR_TRAILERS_4k (40)
|
#define NR_TRAILERS_4k (40)
|
||||||
|
|
||||||
|
// Number of blocks
|
||||||
|
// Mifare Classic 1k
|
||||||
|
#define NR_BLOCKS_1k 0x3f
|
||||||
|
// Mifare Classic Mini
|
||||||
|
#define NR_BLOCKS_MINI 0x13
|
||||||
|
// Mifare Classic 4k
|
||||||
|
#define NR_BLOCKS_4k 0xff
|
||||||
|
|
||||||
#define MAX_FRAME_LEN 264
|
#define MAX_FRAME_LEN 264
|
||||||
|
|
||||||
// Used for counting nonce distances, explore [nd-value, nd+value]
|
// Used for counting nonce distances, explore [nd-value, nd+value]
|
||||||
|
@ -46,7 +56,6 @@ typedef struct {
|
||||||
uint8_t num_sectors;
|
uint8_t num_sectors;
|
||||||
uint8_t num_blocks;
|
uint8_t num_blocks;
|
||||||
uint32_t authuid;
|
uint32_t authuid;
|
||||||
bool b4K;
|
|
||||||
} mftag;
|
} mftag;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
Loading…
Reference in a new issue