diff --git a/examples/felica-read-ndef.c b/examples/felica-read-ndef.c index ec247f1..442a600 100644 --- a/examples/felica-read-ndef.c +++ b/examples/felica-read-ndef.c @@ -1,5 +1,5 @@ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include @@ -8,15 +8,15 @@ #include #if defined(HAVE_SYS_ENDIAN_H) -# include + #include #endif #if defined(HAVE_ENDIAN_H) -# include + #include #endif #if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) -# include + #include #endif #include diff --git a/examples/mifare-classic-format.c b/examples/mifare-classic-format.c index 39ea818..e8daa7f 100644 --- a/examples/mifare-classic-format.c +++ b/examples/mifare-classic-format.c @@ -1,5 +1,5 @@ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include diff --git a/examples/mifare-classic-read-ndef.c b/examples/mifare-classic-read-ndef.c index 69b8dce..a72fb21 100644 --- a/examples/mifare-classic-read-ndef.c +++ b/examples/mifare-classic-read-ndef.c @@ -14,7 +14,7 @@ */ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include diff --git a/examples/mifare-classic-write-ndef.c b/examples/mifare-classic-write-ndef.c index a32b952..134ce61 100644 --- a/examples/mifare-classic-write-ndef.c +++ b/examples/mifare-classic-write-ndef.c @@ -1,5 +1,5 @@ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include diff --git a/examples/mifare-desfire-create-ndef.c b/examples/mifare-desfire-create-ndef.c index 6c5ff50..bee68cb 100644 --- a/examples/mifare-desfire-create-ndef.c +++ b/examples/mifare-desfire-create-ndef.c @@ -1,5 +1,5 @@ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include diff --git a/examples/mifare-desfire-ev1-configure-ats.c b/examples/mifare-desfire-ev1-configure-ats.c index b52b75e..26e2676 100644 --- a/examples/mifare-desfire-ev1-configure-ats.c +++ b/examples/mifare-desfire-ev1-configure-ats.c @@ -1,5 +1,5 @@ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include diff --git a/examples/mifare-desfire-ev1-configure-default-key.c b/examples/mifare-desfire-ev1-configure-default-key.c index bd3cd17..435749e 100644 --- a/examples/mifare-desfire-ev1-configure-default-key.c +++ b/examples/mifare-desfire-ev1-configure-default-key.c @@ -1,5 +1,5 @@ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include diff --git a/examples/mifare-desfire-ev1-configure-random-uid.c b/examples/mifare-desfire-ev1-configure-random-uid.c index 8d89556..ad777b7 100644 --- a/examples/mifare-desfire-ev1-configure-random-uid.c +++ b/examples/mifare-desfire-ev1-configure-random-uid.c @@ -1,5 +1,5 @@ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include diff --git a/examples/mifare-desfire-format.c b/examples/mifare-desfire-format.c index 36aae3c..1665210 100644 --- a/examples/mifare-desfire-format.c +++ b/examples/mifare-desfire-format.c @@ -1,5 +1,5 @@ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include diff --git a/examples/mifare-desfire-read-ndef.c b/examples/mifare-desfire-read-ndef.c index 08ab413..9186432 100644 --- a/examples/mifare-desfire-read-ndef.c +++ b/examples/mifare-desfire-read-ndef.c @@ -1,5 +1,5 @@ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include diff --git a/examples/mifare-desfire-write-ndef.c b/examples/mifare-desfire-write-ndef.c index e0c96a2..a8f00d2 100644 --- a/examples/mifare-desfire-write-ndef.c +++ b/examples/mifare-desfire-write-ndef.c @@ -1,5 +1,5 @@ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include diff --git a/libfreefare/felica.c b/libfreefare/felica.c index d9e4de2..f549119 100644 --- a/libfreefare/felica.c +++ b/libfreefare/felica.c @@ -8,7 +8,7 @@ */ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include @@ -18,7 +18,7 @@ #include #ifdef WITH_DEBUG -# include + #include #endif #include diff --git a/libfreefare/freefare.c b/libfreefare/freefare.c index 09b475f..d46446f 100644 --- a/libfreefare/freefare.c +++ b/libfreefare/freefare.c @@ -1,5 +1,5 @@ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include diff --git a/libfreefare/freefare.h b/libfreefare/freefare.h index 4dc402a..d84ed08 100644 --- a/libfreefare/freefare.h +++ b/libfreefare/freefare.h @@ -279,11 +279,11 @@ bit 0: PICC master key frozen (reversible with configuration change or when form */ #define MDMK_SETTINGS(picc_master_key_settings_changeable,free_create_delete_application,free_listing_apps_and_key_settings,picc_master_key_changeable) ( \ - (picc_master_key_settings_changeable << 3) | \ - (free_create_delete_application << 2) | \ - (free_listing_apps_and_key_settings << 1) | \ - (picc_master_key_changeable) \ -) + (picc_master_key_settings_changeable << 3) | \ + (free_create_delete_application << 2) | \ + (free_listing_apps_and_key_settings << 1) | \ + (picc_master_key_changeable) \ + ) /* Mifare DESFire EV1 Application crypto operations */ @@ -300,21 +300,21 @@ bit 0: PICC master key frozen (reversible with configuration change or when form */ #define MDAPP_SETTINGS(key_no_for_key_changing,config_changeable,free_create_delete_files,free_listing_contents,app_master_key_changeable) ( \ - (key_no_for_key_changing << 4) | \ - (config_changeable << 3) | \ - (free_create_delete_files << 2) | \ - (free_listing_contents << 1) | \ - (app_master_key_changeable) \ -) + (key_no_for_key_changing << 4) | \ + (config_changeable << 3) | \ + (free_create_delete_files << 2) | \ + (free_listing_contents << 1) | \ + (app_master_key_changeable) \ + ) /* Access right */ #define MDAR(read,write,read_write,change_access_rights) ( \ - (read << 12) | \ - (write << 8) | \ - (read_write << 4) | \ - (change_access_rights) \ -) + (read << 12) | \ + (write << 8) | \ + (read_write << 4) | \ + (change_access_rights) \ + ) #define MDAR_READ(ar) (((ar) >> 12) & 0x0f) #define MDAR_WRITE(ar) (((ar) >> 8) & 0x0f) diff --git a/libfreefare/freefare_internal.h b/libfreefare/freefare_internal.h index a4ee1e1..6b1c604 100644 --- a/libfreefare/freefare_internal.h +++ b/libfreefare/freefare_internal.h @@ -2,7 +2,7 @@ #define __FREEFARE_INTERNAL_H__ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include @@ -25,55 +25,55 @@ */ #if !defined(le32toh) && defined(letoh32) -# define le32toh(x) letoh32(x) -# define be32toh(x) betoh32(x) + #define le32toh(x) letoh32(x) + #define be32toh(x) betoh32(x) #endif #if !defined(le16toh) && defined(letoh16) -# define le16toh(x) letoh16(x) -# define be16toh(x) betoh16(x) + #define le16toh(x) letoh16(x) + #define be16toh(x) betoh16(x) #endif #if !defined(le32toh) && defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) -# define be32toh(x) CFSwapInt32BigToHost(x) -# define htobe32(x) CFSwapInt32HostToBig(x) -# define le32toh(x) CFSwapInt32LittleToHost(x) -# define htole32(x) CFSwapInt32HostToLittle(x) + #define be32toh(x) CFSwapInt32BigToHost(x) + #define htobe32(x) CFSwapInt32HostToBig(x) + #define le32toh(x) CFSwapInt32LittleToHost(x) + #define htole32(x) CFSwapInt32HostToLittle(x) #endif #if !defined(le16toh) && defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) -# define be16toh(x) CFSwapInt16BigToHost(x) -# define htobe16(x) CFSwapInt16HostToBig(x) -# define le16toh(x) CFSwapInt16LittleToHost(x) -# define htole16(x) CFSwapInt16HostToLittle(x) + #define be16toh(x) CFSwapInt16BigToHost(x) + #define htobe16(x) CFSwapInt16HostToBig(x) + #define le16toh(x) CFSwapInt16LittleToHost(x) + #define htole16(x) CFSwapInt16HostToLittle(x) #endif #if !defined(le32toh) && defined(bswap_32) -# if BYTE_ORDER == LITTLE_ENDIAN -# define be32toh(x) bswap_32(x) -# define htobe32(x) bswap_32(x) -# define le32toh(x) (x) -# define htole32(x) (x) -# else -# define be32toh(x) (x) -# define htobe32(x) (x) -# define le32toh(x) bswap_32(x) -# define htole32(x) bswap_32(x) -# endif + #if BYTE_ORDER == LITTLE_ENDIAN + #define be32toh(x) bswap_32(x) + #define htobe32(x) bswap_32(x) + #define le32toh(x) (x) + #define htole32(x) (x) + #else + #define be32toh(x) (x) + #define htobe32(x) (x) + #define le32toh(x) bswap_32(x) + #define htole32(x) bswap_32(x) + #endif #endif #if !defined(htole16) && defined(bswap_16) -# if BYTE_ORDER == LITTLE_ENDIAN -# define be16toh(x) (bswap_16(x)) -# define htobe16(x) (bswap_16(x)) -# define htole16(x) (x) -# define le16toh(x) (x) -# else -# define be16toh(x) (x) -# define htobe16(x) (x) -# define htole16(x) (bswap_16(x)) -# define le16toh(x) (bswap_16(x)) -# endif + #if BYTE_ORDER == LITTLE_ENDIAN + #define be16toh(x) (bswap_16(x)) + #define htobe16(x) (bswap_16(x)) + #define htole16(x) (x) + #define le16toh(x) (x) + #else + #define be16toh(x) (x) + #define htobe16(x) (x) + #define htole16(x) (bswap_16(x)) + #define le16toh(x) (bswap_16(x)) + #endif #endif #define MIN(a, b) (((a) < (b)) ? (a) : (b)) @@ -276,11 +276,11 @@ struct ntag21x_key { #define TB_AB(ab) ((ab == C_DEFAULT) ? C_100 : ab) #ifdef WITH_DEBUG -#define DEBUG_FUNCTION() do { printf("*** \033[033;1m%s\033[0m ***\n", __FUNCTION__); } while (0) -#define DEBUG_XFER(data, nbytes, hint) do { hexdump (data, nbytes, hint, 0); } while (0) + #define DEBUG_FUNCTION() do { printf("*** \033[033;1m%s\033[0m ***\n", __FUNCTION__); } while (0) + #define DEBUG_XFER(data, nbytes, hint) do { hexdump (data, nbytes, hint, 0); } while (0) #else -#define DEBUG_FUNCTION() do {} while (0) -#define DEBUG_XFER(data, nbytes, hint) do {} while (0) + #define DEBUG_FUNCTION() do {} while (0) + #define DEBUG_XFER(data, nbytes, hint) do {} while (0) #endif @@ -328,7 +328,7 @@ struct ntag21x_key { */ #define BUFFER_APPEND(buffer_name, data) \ do { \ - buffer_name[__##buffer_name##_n++] = data; \ + buffer_name[__##buffer_name##_n++] = data; \ } while (0) /* @@ -336,10 +336,10 @@ struct ntag21x_key { */ #define BUFFER_APPEND_BYTES(buffer_name, data, size) \ do { \ - size_t __n = 0; \ - while (__n < size) { \ - buffer_name[__##buffer_name##_n++] = ((uint8_t *)data)[__n++]; \ - } \ + size_t __n = 0; \ + while (__n < size) { \ + buffer_name[__##buffer_name##_n++] = ((uint8_t *)data)[__n++]; \ + } \ } while (0) /* @@ -354,17 +354,17 @@ struct ntag21x_key { #if defined(_BYTE_ORDER) && (_BYTE_ORDER != _LITTLE_ENDIAN) #define BUFFER_APPEND_LE(buffer, data, data_size, field_size) \ do { \ - size_t __data_size = data_size; \ - size_t __field_size = field_size; \ - while (__field_size--, __data_size--) { \ - buffer[__##buffer##_n++] = ((uint8_t *)&data)[__field_size]; \ - } \ + size_t __data_size = data_size; \ + size_t __field_size = field_size; \ + while (__field_size--, __data_size--) { \ + buffer[__##buffer##_n++] = ((uint8_t *)&data)[__field_size]; \ + } \ } while (0) #else #define BUFFER_APPEND_LE(buffer, data, data_size, field_size) \ do { \ - memcpy (buffer + __##buffer##_n, &data, data_size); \ - __##buffer##_n += data_size; \ + memcpy (buffer + __##buffer##_n, &data, data_size); \ + __##buffer##_n += data_size; \ } while (0) #endif diff --git a/libfreefare/mad.c b/libfreefare/mad.c index 3205a3d..6b984e4 100644 --- a/libfreefare/mad.c +++ b/libfreefare/mad.c @@ -12,7 +12,7 @@ */ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include diff --git a/libfreefare/mifare_application.c b/libfreefare/mifare_application.c index afce8e2..855db11 100644 --- a/libfreefare/mifare_application.c +++ b/libfreefare/mifare_application.c @@ -6,7 +6,7 @@ */ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #include diff --git a/libfreefare/mifare_classic.c b/libfreefare/mifare_classic.c index 2842b11..07305b4 100644 --- a/libfreefare/mifare_classic.c +++ b/libfreefare/mifare_classic.c @@ -20,27 +20,27 @@ */ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #if defined(HAVE_SYS_TYPES_H) -# include + #include #endif #if defined(HAVE_SYS_ENDIAN_H) -# include + #include #endif #if defined(HAVE_ENDIAN_H) -# include + #include #endif #if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) -# include + #include #endif #if defined(HAVE_BYTESWAP_H) -# include + #include #endif #include @@ -49,7 +49,7 @@ #include #ifdef WITH_DEBUG -# include + #include #endif #include @@ -70,19 +70,19 @@ #define CLASSIC_TRANSCEIVE_EX(tag, msg, res, disconnect) \ do { \ - errno = 0; \ - DEBUG_XFER (msg, __##msg##_n, "===> "); \ - int _res; \ - if ((_res = nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, __##res##_size, 0)) < 0) { \ - if (disconnect) { \ - tag->active = false; \ - } \ - if (_res == NFC_EMFCAUTHFAIL) \ - return errno = EACCES, -1; \ - return errno = EIO, -1; \ - } \ - __##res##_n = _res; \ - DEBUG_XFER (res, __##res##_n, "<=== "); \ + errno = 0; \ + DEBUG_XFER (msg, __##msg##_n, "===> "); \ + int _res; \ + if ((_res = nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, __##res##_size, 0)) < 0) { \ + if (disconnect) { \ + tag->active = false; \ + } \ + if (_res == NFC_EMFCAUTHFAIL) \ + return errno = EACCES, -1; \ + return errno = EIO, -1; \ + } \ + __##res##_n = _res; \ + DEBUG_XFER (res, __##res##_n, "<=== "); \ } while (0) diff --git a/libfreefare/mifare_desfire.c b/libfreefare/mifare_desfire.c index 4dad0bc..609559d 100644 --- a/libfreefare/mifare_desfire.c +++ b/libfreefare/mifare_desfire.c @@ -13,27 +13,27 @@ */ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #if defined(HAVE_SYS_TYPES_H) -# include + #include #endif #if defined(HAVE_SYS_ENDIAN_H) -# include + #include #endif #if defined(HAVE_ENDIAN_H) -# include + #include #endif #if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) -# include + #include #endif #if defined(HAVE_BYTESWAP_H) -# include + #include #endif #include @@ -42,7 +42,7 @@ #include #ifdef WITH_DEBUG -# include + #include #endif #include @@ -93,9 +93,9 @@ static ssize_t read_data(FreefareTag tag, uint8_t command, uint8_t file_no, off #define ASSERT_AUTHENTICATED(tag) \ do { \ - if (MIFARE_DESFIRE (tag)->authenticated_key_no == NOT_YET_AUTHENTICATED) { \ - return errno = EINVAL, -1;\ - } \ + if (MIFARE_DESFIRE (tag)->authenticated_key_no == NOT_YET_AUTHENTICATED) { \ + return errno = EINVAL, -1;\ + } \ } while (0) /* @@ -104,20 +104,20 @@ static ssize_t read_data(FreefareTag tag, uint8_t command, uint8_t file_no, off */ #define ASSERT_CS(cs) \ do { \ - if (cs < 0) { \ - return errno = EINVAL, -1; \ - } else if (cs == 0x02) { \ - return errno = EINVAL, -1; \ - } else if (cs > 0x03) { \ - return errno = EINVAL, -1; \ - } \ + if (cs < 0) { \ + return errno = EINVAL, -1; \ + } else if (cs == 0x02) { \ + return errno = EINVAL, -1; \ + } else if (cs > 0x03) { \ + return errno = EINVAL, -1; \ + } \ } while (0) #define ASSERT_NOT_NULL(argument) \ do { \ - if (!argument) { \ - return errno = EINVAL, -1; \ - } \ + if (!argument) { \ + return errno = EINVAL, -1; \ + } \ } while (0) @@ -149,38 +149,38 @@ static ssize_t read_data(FreefareTag tag, uint8_t command, uint8_t file_no, off */ #define DESFIRE_TRANSCEIVE2(tag, msg, msg_len, res) \ do { \ - DEBUG_FUNCTION(); \ - static uint8_t __msg[MAX_CAPDU_SIZE + 5] = { 0x90, 0x00, 0x00, 0x00, 0x00, /* ..., */ 0x00 }; \ - /* CLA INS P1 P2 Lc PAYLOAD LE*/ \ - static uint8_t __res[MAX_RAPDU_SIZE + 1]; \ - size_t __len = 5; \ - errno = 0; \ - if (!msg) return errno = EINVAL, -1; \ - __msg[1] = msg[0]; \ - if (msg_len > 1) { \ - __len += msg_len; \ - __msg[4] = msg_len - 1; \ - memcpy (__msg + 5, msg + 1, msg_len - 1); \ - } \ - /* reply length */ \ - __msg[__len-1] = 0x00; \ - MIFARE_DESFIRE (tag)->last_picc_error = OPERATION_OK; \ - MIFARE_DESFIRE (tag)->last_pcd_error = OPERATION_OK; \ - DEBUG_XFER (__msg, __len, "===> "); \ - int _res; \ - if ((_res = nfc_initiator_transceive_bytes (tag->device, __msg, __len, __res, __##res##_size + 1, 0)) < 0) { \ - return errno = EIO, -1; \ - } \ - __##res##_n = _res; \ - DEBUG_XFER (__res, __##res##_n, "<=== "); \ - res[__##res##_n-2] = __res[__##res##_n-1]; \ - __##res##_n--; \ - if ((1 == __##res##_n) && (ADDITIONAL_FRAME != res[__##res##_n-1]) && (OPERATION_OK != res[__##res##_n-1])) { \ - if (res[0] == AUTHENTICATION_ERROR) \ - errno = EACCES; \ - return MIFARE_DESFIRE (tag)->last_picc_error = res[0], -1; \ - } \ - memcpy (res, __res, __##res##_n - 1); \ + DEBUG_FUNCTION(); \ + static uint8_t __msg[MAX_CAPDU_SIZE + 5] = { 0x90, 0x00, 0x00, 0x00, 0x00, /* ..., */ 0x00 }; \ + /* CLA INS P1 P2 Lc PAYLOAD LE*/ \ + static uint8_t __res[MAX_RAPDU_SIZE + 1]; \ + size_t __len = 5; \ + errno = 0; \ + if (!msg) return errno = EINVAL, -1; \ + __msg[1] = msg[0]; \ + if (msg_len > 1) { \ + __len += msg_len; \ + __msg[4] = msg_len - 1; \ + memcpy (__msg + 5, msg + 1, msg_len - 1); \ + } \ + /* reply length */ \ + __msg[__len-1] = 0x00; \ + MIFARE_DESFIRE (tag)->last_picc_error = OPERATION_OK; \ + MIFARE_DESFIRE (tag)->last_pcd_error = OPERATION_OK; \ + DEBUG_XFER (__msg, __len, "===> "); \ + int _res; \ + if ((_res = nfc_initiator_transceive_bytes (tag->device, __msg, __len, __res, __##res##_size + 1, 0)) < 0) { \ + return errno = EIO, -1; \ + } \ + __##res##_n = _res; \ + DEBUG_XFER (__res, __##res##_n, "<=== "); \ + res[__##res##_n-2] = __res[__##res##_n-1]; \ + __##res##_n--; \ + if ((1 == __##res##_n) && (ADDITIONAL_FRAME != res[__##res##_n-1]) && (OPERATION_OK != res[__##res##_n-1])) { \ + if (res[0] == AUTHENTICATION_ERROR) \ + errno = EACCES; \ + return MIFARE_DESFIRE (tag)->last_picc_error = res[0], -1; \ + } \ + memcpy (res, __res, __##res##_n - 1); \ } while (0) diff --git a/libfreefare/mifare_desfire_aid.c b/libfreefare/mifare_desfire_aid.c index a237e77..19793f0 100644 --- a/libfreefare/mifare_desfire_aid.c +++ b/libfreefare/mifare_desfire_aid.c @@ -8,27 +8,27 @@ */ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #if defined(HAVE_SYS_TYPES_H) -# include + #include #endif #if defined(HAVE_SYS_ENDIAN_H) -# include + #include #endif #if defined(HAVE_ENDIAN_H) -# include + #include #endif #if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) -# include + #include #endif #if defined(HAVE_BYTESWAP_H) -# include + #include #endif #include diff --git a/libfreefare/mifare_desfire_crypto.c b/libfreefare/mifare_desfire_crypto.c index 9429fad..4c8dc36 100644 --- a/libfreefare/mifare_desfire_crypto.c +++ b/libfreefare/mifare_desfire_crypto.c @@ -8,32 +8,32 @@ */ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #if defined(HAVE_SYS_TYPES_H) -# include + #include #endif #if defined(HAVE_SYS_ENDIAN_H) -# include + #include #endif #if defined(HAVE_ENDIAN_H) -# include + #include #endif #if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) -# include + #include #endif #if defined(HAVE_BYTESWAP_H) -# include + #include #endif #if defined(HAVE_SYS_TYPES_H) -# include + #include #endif #include @@ -45,7 +45,7 @@ #include #ifdef WITH_DEBUG -# include + #include #endif #include diff --git a/libfreefare/mifare_ultralight.c b/libfreefare/mifare_ultralight.c index 12e1fb0..5562fb0 100644 --- a/libfreefare/mifare_ultralight.c +++ b/libfreefare/mifare_ultralight.c @@ -10,11 +10,11 @@ */ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #if defined(HAVE_SYS_TYPES_H) -# include + #include #endif #include @@ -22,7 +22,7 @@ #include #ifdef WITH_DEBUG -# include + #include #endif #include @@ -30,48 +30,48 @@ #define ASSERT_VALID_PAGE(tag, page, mode_write) \ do { \ - if (is_mifare_ultralightc (tag)) { \ - if (mode_write) { \ - if (page >= MIFARE_ULTRALIGHT_C_PAGE_COUNT) return errno = EINVAL, -1; \ - } else { \ - if (page >= MIFARE_ULTRALIGHT_C_PAGE_COUNT_READ) return errno = EINVAL, -1; \ - } \ - } else { \ - if (page >= MIFARE_ULTRALIGHT_PAGE_COUNT) return errno = EINVAL, -1; \ - } \ + if (is_mifare_ultralightc (tag)) { \ + if (mode_write) { \ + if (page >= MIFARE_ULTRALIGHT_C_PAGE_COUNT) return errno = EINVAL, -1; \ + } else { \ + if (page >= MIFARE_ULTRALIGHT_C_PAGE_COUNT_READ) return errno = EINVAL, -1; \ + } \ + } else { \ + if (page >= MIFARE_ULTRALIGHT_PAGE_COUNT) return errno = EINVAL, -1; \ + } \ } while (0) #define ULTRALIGHT_TRANSCEIVE(tag, msg, res) \ do { \ - errno = 0; \ - DEBUG_XFER (msg, __##msg##_n, "===> "); \ - int _res; \ - if ((_res = nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, __##res##_size, 0)) < 0) { \ - return errno = EIO, -1; \ - } \ - __##res##_n = _res; \ - DEBUG_XFER (res, __##res##_n, "<=== "); \ + errno = 0; \ + DEBUG_XFER (msg, __##msg##_n, "===> "); \ + int _res; \ + if ((_res = nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, __##res##_size, 0)) < 0) { \ + return errno = EIO, -1; \ + } \ + __##res##_n = _res; \ + DEBUG_XFER (res, __##res##_n, "<=== "); \ } while (0) #define ULTRALIGHT_TRANSCEIVE_RAW(tag, msg, res) \ do { \ - errno = 0; \ - if (nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, false) < 0) { \ - errno = EIO; \ - return -1; \ - } \ - DEBUG_XFER (msg, __##msg##_n, "===> "); \ - int _res; \ - if ((_res = nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, __##res##_size, 0)) < 0) { \ - nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, true); \ - return errno = EIO, -1; \ - } \ - __##res##_n = _res; \ - DEBUG_XFER (res, __##res##_n, "<=== "); \ - if (nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, true) < 0) { \ - errno = EIO; \ - return -1; \ - } \ + errno = 0; \ + if (nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, false) < 0) { \ + errno = EIO; \ + return -1; \ + } \ + DEBUG_XFER (msg, __##msg##_n, "===> "); \ + int _res; \ + if ((_res = nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, __##res##_size, 0)) < 0) { \ + nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, true); \ + return errno = EIO, -1; \ + } \ + __##res##_n = _res; \ + DEBUG_XFER (res, __##res##_n, "<=== "); \ + if (nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, true) < 0) { \ + errno = EIO; \ + return -1; \ + } \ } while (0) static bool diff --git a/libfreefare/ntag21x.c b/libfreefare/ntag21x.c index ece1fcf..3b68843 100644 --- a/libfreefare/ntag21x.c +++ b/libfreefare/ntag21x.c @@ -15,11 +15,11 @@ */ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #if defined(HAVE_SYS_TYPES_H) -# include + #include #endif #include @@ -27,7 +27,7 @@ #include #ifdef WITH_DEBUG -# include + #include #endif #include @@ -35,56 +35,56 @@ #define NTAG_ASSERT_VALID_PAGE(tag, page, mode_write) \ do { \ - if (mode_write) { \ - if (page<=0x02) \ - {return errno = EINVAL, -1;} \ - else if(NTAG_21x(tag)->subtype == NTAG_213&&page>0x2C) \ - {return errno = EINVAL, -1;} \ - else if(NTAG_21x(tag)->subtype == NTAG_215&&page>0x86) \ - {return errno = EINVAL, -1;} \ - else if(NTAG_21x(tag)->subtype == NTAG_216&&page>0xE6) \ - {return errno = EINVAL, -1;} \ - } else { \ - if(NTAG_21x(tag)->subtype == NTAG_213&&page>0x2C) \ - {return errno = EINVAL, -1;} \ - else if(NTAG_21x(tag)->subtype == NTAG_215&&page>0x86) \ - {return errno = EINVAL, -1;} \ - else if(NTAG_21x(tag)->subtype == NTAG_216&&page>0xE6) \ - {return errno = EINVAL, -1;} \ - } \ + if (mode_write) { \ + if (page<=0x02) \ + {return errno = EINVAL, -1;} \ + else if(NTAG_21x(tag)->subtype == NTAG_213&&page>0x2C) \ + {return errno = EINVAL, -1;} \ + else if(NTAG_21x(tag)->subtype == NTAG_215&&page>0x86) \ + {return errno = EINVAL, -1;} \ + else if(NTAG_21x(tag)->subtype == NTAG_216&&page>0xE6) \ + {return errno = EINVAL, -1;} \ + } else { \ + if(NTAG_21x(tag)->subtype == NTAG_213&&page>0x2C) \ + {return errno = EINVAL, -1;} \ + else if(NTAG_21x(tag)->subtype == NTAG_215&&page>0x86) \ + {return errno = EINVAL, -1;} \ + else if(NTAG_21x(tag)->subtype == NTAG_216&&page>0xE6) \ + {return errno = EINVAL, -1;} \ + } \ } while (0) #define NTAG_TRANSCEIVE(tag, msg, res) \ do { \ - errno = 0; \ - DEBUG_XFER (msg, __##msg##_n, "===> "); \ - int _res; \ - if ((_res = nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, __##res##_size, 0)) < 0) { \ - return errno = EIO, -1; \ - } \ - __##res##_n = _res; \ - DEBUG_XFER (res, __##res##_n, "<=== "); \ + errno = 0; \ + DEBUG_XFER (msg, __##msg##_n, "===> "); \ + int _res; \ + if ((_res = nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, __##res##_size, 0)) < 0) { \ + return errno = EIO, -1; \ + } \ + __##res##_n = _res; \ + DEBUG_XFER (res, __##res##_n, "<=== "); \ } while (0) #define NTAG_TRANSCEIVE_RAW(tag, msg, res) \ do { \ - errno = 0; \ - if (nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, false) < 0) { \ - errno = EIO; \ - return -1; \ - } \ - DEBUG_XFER (msg, __##msg##_n, "===> "); \ - int _res; \ - if ((_res = nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, __##res##_size, 0)) < 0) { \ - nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, true); \ - return errno = EIO, -1; \ - } \ - __##res##_n = _res; \ - DEBUG_XFER (res, __##res##_n, "<=== "); \ - if (nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, true) < 0) { \ - errno = EIO; \ - return -1; \ - } \ + errno = 0; \ + if (nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, false) < 0) { \ + errno = EIO; \ + return -1; \ + } \ + DEBUG_XFER (msg, __##msg##_n, "===> "); \ + int _res; \ + if ((_res = nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, __##res##_size, 0)) < 0) { \ + nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, true); \ + return errno = EIO, -1; \ + } \ + __##res##_n = _res; \ + DEBUG_XFER (res, __##res##_n, "<=== "); \ + if (nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, true) < 0) { \ + errno = EIO; \ + return -1; \ + } \ } while (0) diff --git a/libfreefare/tlv.c b/libfreefare/tlv.c index 1e9d602..2641c4d 100644 --- a/libfreefare/tlv.c +++ b/libfreefare/tlv.c @@ -8,27 +8,27 @@ */ #if defined(HAVE_CONFIG_H) -# include "config.h" + #include "config.h" #endif #if defined(HAVE_SYS_TYPES_H) -# include + #include #endif #if defined(HAVE_SYS_ENDIAN_H) -# include + #include #endif #if defined(HAVE_ENDIAN_H) -# include + #include #endif #if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H) -# include + #include #endif #if defined(HAVE_BYTESWAP_H) -# include + #include #endif #include diff --git a/test/test_mifare_desfire.c b/test/test_mifare_desfire.c index 6c50793..f7540e1 100644 --- a/test/test_mifare_desfire.c +++ b/test/test_mifare_desfire.c @@ -11,8 +11,8 @@ #define cut_assert_success(last_command) \ do { \ - cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \ - cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \ + cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \ + cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \ } while (0) void diff --git a/test/test_mifare_desfire_ev1.c b/test/test_mifare_desfire_ev1.c index 2ed7bb1..1b7ba70 100644 --- a/test/test_mifare_desfire_ev1.c +++ b/test/test_mifare_desfire_ev1.c @@ -11,8 +11,8 @@ #define cut_assert_success(last_command) \ do { \ - cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \ - cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \ + cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \ + cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \ } while (0) void diff --git a/test/test_mifare_desfire_ev1_3des.c b/test/test_mifare_desfire_ev1_3des.c index 49f776b..b988f27 100644 --- a/test/test_mifare_desfire_ev1_3des.c +++ b/test/test_mifare_desfire_ev1_3des.c @@ -11,8 +11,8 @@ #define cut_assert_success(last_command) \ do { \ - cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \ - cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \ + cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \ + cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \ } while (0) void diff --git a/test/test_mifare_desfire_ev1_3k3des.c b/test/test_mifare_desfire_ev1_3k3des.c index 048d0e0..7498d01 100644 --- a/test/test_mifare_desfire_ev1_3k3des.c +++ b/test/test_mifare_desfire_ev1_3k3des.c @@ -11,8 +11,8 @@ #define cut_assert_success(last_command) \ do { \ - cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \ - cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \ + cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \ + cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \ } while (0) void diff --git a/test/test_mifare_desfire_ev1_aes.c b/test/test_mifare_desfire_ev1_aes.c index 55b7b30..6c0fec8 100644 --- a/test/test_mifare_desfire_ev1_aes.c +++ b/test/test_mifare_desfire_ev1_aes.c @@ -11,8 +11,8 @@ #define cut_assert_success(last_command) \ do { \ - cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \ - cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \ + cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \ + cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \ } while (0) void diff --git a/test/test_mifare_desfire_ev1_iso.c b/test/test_mifare_desfire_ev1_iso.c index 9a4993c..004d07d 100644 --- a/test/test_mifare_desfire_ev1_iso.c +++ b/test/test_mifare_desfire_ev1_iso.c @@ -8,8 +8,8 @@ #define cut_assert_success(last_command) \ do { \ - cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \ - cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \ + cut_assert_equal_int (OPERATION_OK, mifare_desfire_last_picc_error (tag), cut_message ("PICC replied %s", mifare_desfire_error_lookup (mifare_desfire_last_picc_error (tag)))); \ + cut_assert_not_equal_int (-1, res, cut_message ("Wrong return value")); \ } while (0) void