Current version
This commit is contained in:
parent
67e2c550b2
commit
5210de18c7
|
@ -26,9 +26,10 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
uint8_t key_data_real[16] = {0};
|
uint8_t key_data_real[16] = {0};
|
||||||
{
|
{
|
||||||
FILE *f = fopen("key", "rb");
|
char const *name = (argc > 1) ? argv[1] : "key";
|
||||||
|
FILE *f = fopen(name, "rb");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
errx(EXIT_FAILURE, "error opening key file.");
|
errx(EXIT_FAILURE, "error opening key file: %s", name);
|
||||||
}
|
}
|
||||||
if (fread(key_data_real, 1, sizeof key_data_real, f) < sizeof key_data_real) {
|
if (fread(key_data_real, 1, sizeof key_data_real, f) < sizeof key_data_real) {
|
||||||
errx(EXIT_FAILURE, "key file too small.");
|
errx(EXIT_FAILURE, "key file too small.");
|
||||||
|
@ -37,6 +38,8 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
MifareDESFireKey key_real = mifare_desfire_aes_key_new(key_data_real);
|
MifareDESFireKey key_real = mifare_desfire_aes_key_new(key_data_real);
|
||||||
|
|
||||||
|
FILE *out = argc > 2 ? fopen(argv[2], "w") : stdout;
|
||||||
|
|
||||||
device_count = nfc_list_devices(context, devices, sizeof(devices) / sizeof(devices[0]));
|
device_count = nfc_list_devices(context, devices, sizeof(devices) / sizeof(devices[0]));
|
||||||
if (device_count <= 0) {
|
if (device_count <= 0) {
|
||||||
errx(EXIT_FAILURE, "No NFC device found.");
|
errx(EXIT_FAILURE, "No NFC device found.");
|
||||||
|
@ -59,7 +62,7 @@ int main(int argc, char **argv) {
|
||||||
/* Poll for targets */
|
/* Poll for targets */
|
||||||
const nfc_modulation nmModulations = {.nmt = NMT_ISO14443A, .nbr = NBR_106};
|
const nfc_modulation nmModulations = {.nmt = NMT_ISO14443A, .nbr = NBR_106};
|
||||||
nfc_target target;
|
nfc_target target;
|
||||||
nfc_initiator_poll_target(device, &nmModulations, 1, 0x10, 1, &target);
|
nfc_initiator_poll_target(device, &nmModulations, 1, 10, 1, &target);
|
||||||
|
|
||||||
/* Got at least one, read tag list */
|
/* Got at least one, read tag list */
|
||||||
tags = freefare_get_tags(device);
|
tags = freefare_get_tags(device);
|
||||||
|
@ -69,7 +72,6 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tags[0]) {
|
if (!tags[0]) {
|
||||||
printf("Tag list returned no tags\n");
|
|
||||||
goto free_tags;
|
goto free_tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +106,8 @@ int main(int argc, char **argv) {
|
||||||
warnx("Authentication on master application failed");
|
warnx("Authentication on master application failed");
|
||||||
goto free_tag;
|
goto free_tag;
|
||||||
} else {
|
} else {
|
||||||
printf("Valid key: %s\n", tag_uid);
|
fprintf(out, "%s\n", tag_uid);
|
||||||
|
fflush(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_disconnect:
|
wait_disconnect:
|
||||||
|
@ -116,7 +119,8 @@ int main(int argc, char **argv) {
|
||||||
free(tag_uid);
|
free(tag_uid);
|
||||||
free_tags:
|
free_tags:
|
||||||
freefare_free_tags(tags);
|
freefare_free_tags(tags);
|
||||||
|
fflush(stdout);
|
||||||
|
fflush(stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
mifare_desfire_key_free(key_null);
|
mifare_desfire_key_free(key_null);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user