add freefare_free_tag() to free only one tag and add freefare_duplicate_tag() in order to copy a tag struct.

This commit is contained in:
Romuald Conty 2010-04-20 15:17:17 +00:00
parent 2cf035768d
commit 99b261d132
2 changed files with 48 additions and 9 deletions

View file

@ -130,6 +130,32 @@ freefare_get_tags (nfc_device_t *device)
return tags;
}
/*
* Duplicate a tag
*/
MifareTag
freefare_duplicate_tag (MifareTag tag)
{
MifareTag ret;
/* Allocate memory for the MIFARE target */
switch (tag->tag_info->type) {
case CLASSIC_1K:
case CLASSIC_4K:
ret = mifare_classic_tag_new ();
break;
case ULTRALIGHT:
ret = mifare_ultralight_tag_new ();
break;
}
ret->device = tag->device;
ret->info = tag->info;
ret->active = tag->active;
ret->tag_info = tag->tag_info;
return ret;
}
/*
* Returns the type of the provided tag.
*/
@ -160,6 +186,25 @@ freefare_get_tag_uid (MifareTag tag)
return res;
}
/*
* Free the provided tag.
*/
void
freefare_free_tag (MifareTag tag)
{
if (tag) {
switch (tag->tag_info->type) {
case CLASSIC_1K:
case CLASSIC_4K:
mifare_classic_tag_free (tag);
break;
case ULTRALIGHT:
mifare_ultralight_tag_free (tag);
break;
}
}
}
/*
* Free the provided tag list.
*/
@ -168,15 +213,7 @@ freefare_free_tags (MifareTag *tags)
{
if (tags) {
for (int i=0; tags[i]; i++) {
switch (tags[i]->tag_info->type) {
case CLASSIC_1K:
case CLASSIC_4K:
mifare_classic_tag_free (tags[i]);
break;
case ULTRALIGHT:
mifare_ultralight_tag_free (tags[i]);
break;
}
freefare_free_tag(tags[i]);
}
free (tags);
}

View file

@ -52,9 +52,11 @@ typedef uint8_t MifareUltralightPageNumber;
typedef unsigned char MifareUltralightPage[4];
MifareTag *freefare_get_tags (nfc_device_t *device);
MifareTag freefare_duplicate_tag (MifareTag tag);
enum mifare_tag_type freefare_get_tag_type (MifareTag tag);
const char *freefare_get_tag_friendly_name (MifareTag tag);
char *freefare_get_tag_uid (MifareTag tag);
void freefare_free_tag (MifareTag tag);
void freefare_free_tags (MifareTag *tags);
int mifare_ultralight_connect (MifareTag tag);