Add access bit macros to ease-up writing code using the library.

This commit is contained in:
Romain Tartiere 2010-03-19 09:00:06 +00:00
parent feb240ee73
commit 3b737a11e8
3 changed files with 23 additions and 2 deletions

View file

@ -92,7 +92,17 @@ int mifare_classic_get_data_block_permission (MifareTag tag, const MifareClass
int mifare_classic_format_sector (MifareTag tag, const MifareClassicBlockNumber block);
char *mifare_classic_get_uid (MifareTag 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);
void mifare_classic_trailer_block (MifareClassicBlock *block, const MifareClassicKey key_a, uint8_t ab_0, uint8_t ab_1, uint8_t ab_2, uint8_t ab_tb, const uint8_t gpb, const MifareClassicKey key_b);
#define C_000 0
#define C_001 1
#define C_010 2
#define C_011 3
#define C_100 4
#define C_101 5
#define C_110 6
#define C_111 7
#define C_DEFAULT 255
/* MIFARE Classic Access Bits */
#define MCAB_R 0x8

View file

@ -118,4 +118,10 @@ struct mifare_ultralight_tag {
#define MIFARE_CLASSIC(tag) ((struct mifare_classic_tag *) tag)
#define MIFARE_ULTRALIGHT(tag) ((struct mifare_ultralight_tag *) tag)
/*
* Access bits manipulation macros
*/
#define DB_AB(ab) ((ab == C_DEFAULT) ? C_000 : ab)
#define TB_AB(ab) ((ab == C_DEFAULT) ? C_100 : ab)
#endif /* !__FREEFARE_INTERNAL_H__ */

View file

@ -709,10 +709,15 @@ mifare_classic_last_sector_block (MifareClassicBlockNumber block)
* Generates a MIFARE trailer block.
*/
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_trailer_block (MifareClassicBlock *block, const MifareClassicKey key_a, uint8_t ab_0, uint8_t ab_1, uint8_t ab_2, uint8_t ab_tb, const uint8_t gpb, const MifareClassicKey key_b)
{
union mifare_classic_block *b = (union mifare_classic_block *)block; // *((union mifare_classic_block *)(&block));
ab_0 = DB_AB(ab_0);
ab_1 = DB_AB(ab_1);
ab_2 = DB_AB(ab_2);
ab_tb = TB_AB(ab_tb);
memcpy (b->trailer.key_a, key_a, sizeof (MifareClassicKey));
uint32_t access_bits = ((((( ab_0 & 0x4) >> 2) << 8) | (((ab_0 & 0x2) >> 1) << 4) | (ab_0 & 0x1)) |