add an accessor to UID contained in MifareClassicTag
This commit is contained in:
parent
fc3c23502c
commit
7d1495940f
2 changed files with 20 additions and 0 deletions
|
@ -61,6 +61,8 @@ int mifare_classic_get_trailer_block_permission (MifareClassicTag tag, const
|
|||
int mifare_classic_get_data_block_permission (MifareClassicTag tag, const MifareClassicBlockNumber block, const unsigned char permission, const MifareClassicKeyType key_type);
|
||||
|
||||
int mifare_classic_format_sector (MifareClassicTag tag, const MifareSectorNumber sector);
|
||||
char* mifare_classic_get_uid(MifareClassicTag tag);
|
||||
|
||||
void mifare_classic_trailer_block (MifareClassicBlock *block, const MifareClassicKey key_a, const uint8_t ab_0, const uint8_t ab_1, const uint8_t ab_2, const uint8_t ab_tb, const uint8_t gpb, const MifareClassicKey key_b);
|
||||
|
||||
/* MIFARE Classic Access Bits */
|
||||
|
|
|
@ -693,6 +693,24 @@ mifare_classic_format_sector (MifareClassicTag tag, const MifareSectorNumber sec
|
|||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* UID accessor
|
||||
*/
|
||||
char*
|
||||
mifare_classic_get_uid(MifareClassicTag tag)
|
||||
{
|
||||
char* uid = malloc((4 * 2) + 1);
|
||||
for( uint8_t i = 0; i < 4; i++) {
|
||||
unsigned char msb = (tag->info.abtUid[i] | 0xf0) >> 4;
|
||||
unsigned char lsb = (tag->info.abtUid[i] | 0x0f);
|
||||
|
||||
uid[i] = msb < 9 ? msb + '0' : msb + 'a';
|
||||
uid[i+1] = lsb < 9 ? lsb + '0' : lsb + 'a';
|
||||
}
|
||||
uid[8] = '\0';
|
||||
return uid;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generates a MIFARE trailer block.
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue