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:
parent
e52fbccb4a
commit
e0d2405a30
4 changed files with 53 additions and 21 deletions
|
@ -109,10 +109,10 @@ freefare_get_tags (nfc_device_t *device)
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case CLASSIC_1K:
|
case CLASSIC_1K:
|
||||||
case CLASSIC_4K:
|
case CLASSIC_4K:
|
||||||
tags[tag_count-1] = malloc (sizeof (struct mifare_classic_tag));
|
tags[tag_count-1] = mifare_classic_tag_new ();
|
||||||
break;
|
break;
|
||||||
case ULTRALIGHT:
|
case ULTRALIGHT:
|
||||||
tags[tag_count-1] = malloc (sizeof (struct mifare_ultralight_tag));
|
tags[tag_count-1] = mifare_ultralight_tag_new ();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ freefare_get_tags (nfc_device_t *device)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize common fields
|
* 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])->device = device;
|
||||||
(tags[tag_count-1])->info = target_info.nai;
|
(tags[tag_count-1])->info = target_info.nai;
|
||||||
|
@ -155,10 +155,10 @@ freefare_free_tags (MifareTag *tags)
|
||||||
switch (tags[i]->type) {
|
switch (tags[i]->type) {
|
||||||
case CLASSIC_1K:
|
case CLASSIC_1K:
|
||||||
case CLASSIC_4K:
|
case CLASSIC_4K:
|
||||||
mifare_classic_free_tag (tags[i]);
|
mifare_classic_tag_free (tags[i]);
|
||||||
break;
|
break;
|
||||||
case ULTRALIGHT:
|
case ULTRALIGHT:
|
||||||
mifare_ultralight_free_tag (tags[i]);
|
mifare_ultralight_tag_free (tags[i]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,8 +24,10 @@ struct mad_sector_0x00;
|
||||||
struct mad_sector_0x10;
|
struct mad_sector_0x10;
|
||||||
|
|
||||||
void crc8 (uint8_t *crc, const uint8_t value);
|
void crc8 (uint8_t *crc, const uint8_t value);
|
||||||
void mifare_classic_free_tag (MifareTag tag);
|
MifareTag mifare_classic_tag_new (void);
|
||||||
void mifare_ultralight_free_tag (MifareTag tag);
|
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_0x00_crc8 (Mad mad);
|
||||||
uint8_t sector_0x10_crc8 (Mad mad);
|
uint8_t sector_0x10_crc8 (Mad mad);
|
||||||
|
|
||||||
|
|
|
@ -131,22 +131,37 @@ int get_block_access_bits (MifareTag tag, const MifareClassicBlockNumber block,
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MIFARE card communication preparation functions
|
* Memory management 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
void
|
||||||
mifare_classic_free_tag (MifareTag tag)
|
mifare_classic_tag_free (MifareTag tag)
|
||||||
{
|
{
|
||||||
free (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.
|
* Establish connection to the provided tag.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -43,22 +43,37 @@
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MIFARE card communication preparation functions
|
* Memory management 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.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
void
|
||||||
mifare_ultralight_free_tag (MifareTag tag)
|
mifare_ultralight_tag_free (MifareTag tag)
|
||||||
{
|
{
|
||||||
free (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.
|
* Establish connection to the provided tag.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue