examples/mifare-desfire-create-ndef.c prepare for DF EV1 NDEF mapping
This commit is contained in:
parent
5bec80fb07
commit
9d34554270
1 changed files with 36 additions and 12 deletions
|
@ -30,9 +30,10 @@
|
|||
* This example was written based on information provided by the
|
||||
* following documents:
|
||||
*
|
||||
* Mifare DESFire as Type 4 Tag
|
||||
* AN11004 Mifare DESFire as Type 4 Tag
|
||||
* NFC Forum Type 4 Tag Extensions for Mifare DESFire
|
||||
* Rev. 1.1 - 21 August 2007
|
||||
* Rev. 2.2 - 4 January 2012
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -122,18 +123,6 @@ main(int argc, char *argv[])
|
|||
|
||||
char *tag_uid = freefare_get_tag_uid (tags[i]);
|
||||
char buffer[BUFSIZ];
|
||||
|
||||
printf ("Found %s with UID %s. ", freefare_get_tag_friendly_name (tags[i]), tag_uid);
|
||||
bool create_ndef = true;
|
||||
if (create_options.interactive) {
|
||||
printf ("Create NDEF app [yN] ");
|
||||
fgets (buffer, BUFSIZ, stdin);
|
||||
create_ndef = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
||||
} else {
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
if (create_ndef) {
|
||||
int res;
|
||||
|
||||
res = mifare_desfire_connect (tags[i]);
|
||||
|
@ -143,6 +132,37 @@ main(int argc, char *argv[])
|
|||
break;
|
||||
}
|
||||
|
||||
// We've to track DESFire version as NDEF mapping is different
|
||||
struct mifare_desfire_version_info info;
|
||||
res = mifare_desfire_get_version (tags[i], &info);
|
||||
if (res < 0) {
|
||||
freefare_perror (tags[i], "mifare_desfire_get_version");
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
printf ("Found %s with UID %s and software v%d.%d\n", freefare_get_tag_friendly_name (tags[i]), tag_uid, info.software.version_major, info.software.version_minor);
|
||||
bool create_ndef = true;
|
||||
int ndef_mapping;
|
||||
switch (info.software.version_major) {
|
||||
case 0:
|
||||
ndef_mapping = 1;
|
||||
break;
|
||||
case 1:
|
||||
ndef_mapping = 2;
|
||||
default: // newer version? let's assume it supports latest mapping too
|
||||
ndef_mapping = 2;
|
||||
}
|
||||
if (create_options.interactive) {
|
||||
printf ("Create NDEF app v%d [yN] ", ndef_mapping);
|
||||
fgets (buffer, BUFSIZ, stdin);
|
||||
create_ndef = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
||||
} else {
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
if (create_ndef) {
|
||||
|
||||
/* Initialised Formatting Procedure. See section 6.5.1 and 8.1 of Mifare DESFire as Type 4 Tag document*/
|
||||
// Send Mifare DESFire Select Application with AID equal to 000000h to select the PICC level
|
||||
res = mifare_desfire_select_application(tags[i], NULL);
|
||||
|
@ -159,6 +179,10 @@ main(int argc, char *argv[])
|
|||
if (res < 0)
|
||||
errx (EXIT_FAILURE, "Authentication with PICC master key failed");
|
||||
|
||||
// TODO
|
||||
if (info.software.version_major > 0)
|
||||
errx (EXIT_FAILURE, "Not implemented yet, sorry!");
|
||||
|
||||
uint8_t key_settings;
|
||||
uint8_t max_keys;
|
||||
mifare_desfire_get_key_settings(tags[i], &key_settings,&max_keys);
|
||||
|
@ -231,8 +255,8 @@ main(int argc, char *argv[])
|
|||
mifare_desfire_key_free (key_picc);
|
||||
mifare_desfire_key_free (key_app);
|
||||
|
||||
mifare_desfire_disconnect (tags[i]);
|
||||
}
|
||||
mifare_desfire_disconnect (tags[i]);
|
||||
free (tag_uid);
|
||||
}
|
||||
freefare_free_tags (tags);
|
||||
|
|
Loading…
Reference in a new issue