Rework data structures allocations / frees.

- New mifare_*_tag_new() functions for allocating and initialising memory for a given MIFARE tag;
  - Rename mifare_*_free_tag() to mifare_*_tag_free() for consistent names with mifare_*_tag_new() functions.
This commit is contained in:
Romain Tartiere 2010-02-22 12:25:23 +00:00
parent e52fbccb4a
commit e0d2405a30
4 changed files with 53 additions and 21 deletions

View file

@ -109,10 +109,10 @@ freefare_get_tags (nfc_device_t *device)
switch (type) {
case CLASSIC_1K:
case CLASSIC_4K:
tags[tag_count-1] = malloc (sizeof (struct mifare_classic_tag));
tags[tag_count-1] = mifare_classic_tag_new ();
break;
case ULTRALIGHT:
tags[tag_count-1] = malloc (sizeof (struct mifare_ultralight_tag));
tags[tag_count-1] = mifare_ultralight_tag_new ();
break;
}
@ -121,7 +121,7 @@ freefare_get_tags (nfc_device_t *device)
/*
* Initialize common fields
* (Target specific fields are initialized in mifare_*_connect())
* (Target specific fields are initialized in mifare_*_tag_new())
*/
(tags[tag_count-1])->device = device;
(tags[tag_count-1])->info = target_info.nai;
@ -155,10 +155,10 @@ freefare_free_tags (MifareTag *tags)
switch (tags[i]->type) {
case CLASSIC_1K:
case CLASSIC_4K:
mifare_classic_free_tag (tags[i]);
mifare_classic_tag_free (tags[i]);
break;
case ULTRALIGHT:
mifare_ultralight_free_tag (tags[i]);
mifare_ultralight_tag_free (tags[i]);
break;
}
}

View file

@ -24,8 +24,10 @@ struct mad_sector_0x00;
struct mad_sector_0x10;
void crc8 (uint8_t *crc, const uint8_t value);
void mifare_classic_free_tag (MifareTag tag);
void mifare_ultralight_free_tag (MifareTag tag);
MifareTag mifare_classic_tag_new (void);
void mifare_classic_tag_free (MifareTag tag);
MifareTag mifare_ultralight_tag_new (void);
void mifare_ultralight_tag_free (MifareTag tag);
uint8_t sector_0x00_crc8 (Mad mad);
uint8_t sector_0x10_crc8 (Mad mad);

View file

@ -131,22 +131,37 @@ int get_block_access_bits (MifareTag tag, const MifareClassicBlockNumber block,
/*
* MIFARE card communication preparation functions
*
* The following functions send NFC commands to the initiator to prepare
* communication with a MIFARE card, and perform required cleannups after using
* the target.
* Memory management functions.
*/
/*
* Free the provided tag list.
* Allocates and initialize a MIFARE Classic tag.
*/
MifareTag
mifare_classic_tag_new (void)
{
return malloc (sizeof (struct mifare_classic_tag));
}
/*
* Free the provided tag.
*/
void
mifare_classic_free_tag (MifareTag tag)
mifare_classic_tag_free (MifareTag tag)
{
free (tag);
}
/*
* MIFARE card communication preparation functions
*
* The following functions send NFC commands to the initiator to prepare
* communication with a MIFARE card, and perform required cleanups after using
* the target.
*/
/*
* Establish connection to the provided tag.
*/

View file

@ -43,22 +43,37 @@
/*
* MIFARE card communication preparation functions
*
* The following functions send NFC commands to the initiator to prepare
* communication with a MIFARE card, and perform required cleannups after using
* the target.
* Memory management functions.
*/
/*
* Free the provided tag list.
* Allocates and initialize a MIFARE UltraLight tag.
*/
MifareTag
mifare_ultralight_tag_new (void)
{
return malloc (sizeof (struct mifare_ultralight_tag));
}
/*
* Free the provided tag.
*/
void
mifare_ultralight_free_tag (MifareTag tag)
mifare_ultralight_tag_free (MifareTag tag)
{
free (tag);
}
/*
* MIFARE card communication preparation functions
*
* The following functions send NFC commands to the initiator to prepare
* communication with a MIFARE card, and perform required cleanups after using
* the target.
*/
/*
* Establish connection to the provided tag.
*/