From ecdb1afb6ef175ce111d02cc7a93077ba5cf4c33 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Tue, 19 Jan 2010 23:15:10 +0000 Subject: [PATCH] Use the new ASSERT_INACTIVE macro in mifare_classic.c. --- libfreefare/mifare_classic.c | 46 ++++++++---------------------------- 1 file changed, 10 insertions(+), 36 deletions(-) diff --git a/libfreefare/mifare_classic.c b/libfreefare/mifare_classic.c index 4a870cb..7c2298e 100644 --- a/libfreefare/mifare_classic.c +++ b/libfreefare/mifare_classic.c @@ -46,6 +46,7 @@ #include #include +#include "freefare_internal.h" struct mifare_classic_tag { nfc_device_t *device; @@ -247,10 +248,7 @@ mifare_classic_free_tags (MifareClassicTag *tags) int mifare_classic_connect (MifareClassicTag tag) { - if (tag->active) { - errno = EINVAL; - return -1; - } + ASSERT_INACTIVE (tag); nfc_target_info_t pnti; if (nfc_initiator_select_tag (tag->device, NM_ISO14443A_106, tag->info.abtUid, 4, &pnti)) { @@ -268,10 +266,7 @@ mifare_classic_connect (MifareClassicTag tag) int mifare_classic_disconnect (MifareClassicTag tag) { - if (!(tag->active)) { - errno = EINVAL; - return -1; - } + ASSERT_ACTIVE (tag); if (nfc_initiator_deselect_tag (tag->device)) { tag->active = 0; @@ -296,10 +291,7 @@ mifare_classic_disconnect (MifareClassicTag tag) int mifare_classic_authenticate (MifareClassicTag tag, const MifareClassicBlockNumber block, const MifareClassicKey key, const MifareClassicKeyType key_type) { - if (!tag->active) { - errno = EINVAL; - return -1; - } + ASSERT_ACTIVE (tag); unsigned char command[12]; command[0] = (key_type == MFC_KEY_A) ? MC_AUTH_A : MC_AUTH_B; @@ -329,10 +321,7 @@ mifare_classic_authenticate (MifareClassicTag tag, const MifareClassicBlockNumbe int mifare_classic_read (MifareClassicTag tag, const MifareClassicBlockNumber block, MifareClassicBlock *data) { - if (!tag->active) { - errno = EINVAL; - return -1; - } + ASSERT_ACTIVE (tag); unsigned char command[2]; command[0] = MC_READ; @@ -403,10 +392,7 @@ mifare_classic_read_value (MifareClassicTag tag, const MifareClassicBlockNumber int mifare_classic_write (MifareClassicTag tag, const MifareClassicBlockNumber block, const MifareClassicBlock data) { - if (!tag->active) { - errno = EINVAL; - return -1; - } + ASSERT_ACTIVE (tag); unsigned char command[2 + sizeof (MifareClassicBlock)]; command[0] = MC_WRITE; @@ -431,10 +417,7 @@ mifare_classic_write (MifareClassicTag tag, const MifareClassicBlockNumber block int mifare_classic_increment (MifareClassicTag tag, const MifareClassicBlockNumber block, const uint32_t amount) { - if (!tag->active) { - errno = EINVAL; - return -1; - } + ASSERT_ACTIVE (tag); unsigned char command[6]; command[0] = MC_INCREMENT; @@ -460,10 +443,7 @@ mifare_classic_increment (MifareClassicTag tag, const MifareClassicBlockNumber b int mifare_classic_decrement (MifareClassicTag tag, const MifareClassicBlockNumber block, const uint32_t amount) { - if (!tag->active) { - errno = EINVAL; - return -1; - } + ASSERT_ACTIVE (tag); unsigned char command[6]; command[0] = MC_DECREMENT; @@ -488,10 +468,7 @@ mifare_classic_decrement (MifareClassicTag tag, const MifareClassicBlockNumber b int mifare_classic_restore (MifareClassicTag tag, const MifareClassicBlockNumber block) { - if (!tag->active) { - errno = EINVAL; - return -1; - } + ASSERT_ACTIVE (tag); unsigned char command[2]; /* XXX Should be MC_RESTORE according to the MIFARE documentation. */ @@ -515,10 +492,7 @@ mifare_classic_restore (MifareClassicTag tag, const MifareClassicBlockNumber blo int mifare_classic_transfer (MifareClassicTag tag, const MifareClassicBlockNumber block) { - if (!tag->active) { - errno = EINVAL; - return -1; - } + ASSERT_ACTIVE (tag); unsigned char command[2]; command[0] = MC_TRANSFER;