Run make style
to indent macros
This commit is contained in:
parent
c54e3d981c
commit
69bf99b33d
30 changed files with 272 additions and 272 deletions
|
@ -1,5 +1,5 @@
|
|||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
|
@ -8,15 +8,15 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#if defined(HAVE_SYS_ENDIAN_H)
|
||||
# include <sys/endian.h>
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_ENDIAN_H)
|
||||
# include <endian.h>
|
||||
#include <endian.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
|
||||
# include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
#include <nfc/nfc.h>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <err.h>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -18,7 +18,7 @@
|
|||
#include <sys/types.h>
|
||||
|
||||
#ifdef WITH_DEBUG
|
||||
# include <libutil.h>
|
||||
#include <libutil.h>
|
||||
#endif
|
||||
|
||||
#include <freefare.h>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdlib.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)
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define __FREEFARE_INTERNAL_H__
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <openssl/des.h>
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/types.h>
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
|
|
@ -20,27 +20,27 @@
|
|||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_TYPES_H)
|
||||
# include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_ENDIAN_H)
|
||||
# include <sys/endian.h>
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_ENDIAN_H)
|
||||
# include <endian.h>
|
||||
#include <endian.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
|
||||
# include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_BYTESWAP_H)
|
||||
# include <byteswap.h>
|
||||
#include <byteswap.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
@ -49,7 +49,7 @@
|
|||
#include <strings.h>
|
||||
|
||||
#ifdef WITH_DEBUG
|
||||
# include <libutil.h>
|
||||
#include <libutil.h>
|
||||
#endif
|
||||
|
||||
#include <freefare.h>
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -13,27 +13,27 @@
|
|||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_TYPES_H)
|
||||
# include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_ENDIAN_H)
|
||||
# include <sys/endian.h>
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_ENDIAN_H)
|
||||
# include <endian.h>
|
||||
#include <endian.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
|
||||
# include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_BYTESWAP_H)
|
||||
# include <byteswap.h>
|
||||
#include <byteswap.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
@ -42,7 +42,7 @@
|
|||
#include <strings.h>
|
||||
|
||||
#ifdef WITH_DEBUG
|
||||
# include <libutil.h>
|
||||
#include <libutil.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/rand.h>
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -8,27 +8,27 @@
|
|||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_TYPES_H)
|
||||
# include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_ENDIAN_H)
|
||||
# include <sys/endian.h>
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_ENDIAN_H)
|
||||
# include <endian.h>
|
||||
#include <endian.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
|
||||
# include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_BYTESWAP_H)
|
||||
# include <byteswap.h>
|
||||
#include <byteswap.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
|
|
@ -8,32 +8,32 @@
|
|||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_TYPES_H)
|
||||
# include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_ENDIAN_H)
|
||||
# include <sys/endian.h>
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_ENDIAN_H)
|
||||
# include <endian.h>
|
||||
#include <endian.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
|
||||
# include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_BYTESWAP_H)
|
||||
# include <byteswap.h>
|
||||
#include <byteswap.h>
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(HAVE_SYS_TYPES_H)
|
||||
# include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <openssl/aes.h>
|
||||
|
@ -45,7 +45,7 @@
|
|||
#include <strings.h>
|
||||
|
||||
#ifdef WITH_DEBUG
|
||||
# include <libutil.h>
|
||||
#include <libutil.h>
|
||||
#endif
|
||||
|
||||
#include <freefare.h>
|
||||
|
|
|
@ -10,11 +10,11 @@
|
|||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_TYPES_H)
|
||||
# include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
@ -22,7 +22,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#ifdef WITH_DEBUG
|
||||
# include <libutil.h>
|
||||
#include <libutil.h>
|
||||
#endif
|
||||
|
||||
#include <freefare.h>
|
||||
|
@ -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
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_TYPES_H)
|
||||
# include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
|
@ -27,7 +27,7 @@
|
|||
#include <string.h>
|
||||
|
||||
#ifdef WITH_DEBUG
|
||||
# include <libutil.h>
|
||||
#include <libutil.h>
|
||||
#endif
|
||||
|
||||
#include <freefare.h>
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -8,27 +8,27 @@
|
|||
*/
|
||||
|
||||
#if defined(HAVE_CONFIG_H)
|
||||
# include "config.h"
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_TYPES_H)
|
||||
# include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_SYS_ENDIAN_H)
|
||||
# include <sys/endian.h>
|
||||
#include <sys/endian.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_ENDIAN_H)
|
||||
# include <endian.h>
|
||||
#include <endian.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_COREFOUNDATION_COREFOUNDATION_H)
|
||||
# include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_BYTESWAP_H)
|
||||
# include <byteswap.h>
|
||||
#include <byteswap.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue