Update to current libnfc devel API.
libnfc changed its nfc_initiator_transceive_bytes(): it now takes a const size_t used as maximal allowed rx bytes. libnfc now checks if rx buffer is large enough to get the full response, so libfreefare should take care about whole size of its buffers.
This commit is contained in:
parent
a8e0b6e1e7
commit
dd1315321d
4 changed files with 18 additions and 9 deletions
|
@ -315,14 +315,16 @@ struct mifare_ultralight_tag {
|
||||||
*/
|
*/
|
||||||
#define BUFFER_INIT(buffer_name, size) \
|
#define BUFFER_INIT(buffer_name, size) \
|
||||||
uint8_t buffer_name[size]; \
|
uint8_t buffer_name[size]; \
|
||||||
|
size_t __##buffer_name##_size = size; \
|
||||||
size_t __##buffer_name##_n = 0
|
size_t __##buffer_name##_n = 0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a wrapper for an existing buffer.
|
* Create a wrapper for an existing buffer.
|
||||||
* BEWARE! It eats children!
|
* BEWARE! It eats children!
|
||||||
*/
|
*/
|
||||||
#define BUFFER_ALIAS(buffer_name, origin) \
|
#define BUFFER_ALIAS(buffer_name, origin, origin_size) \
|
||||||
uint8_t *buffer_name = (void *)origin; \
|
uint8_t *buffer_name = (void *)origin; \
|
||||||
|
size_t __##buffer_name##_size = origin_size; \
|
||||||
size_t __##buffer_name##_n = 0;
|
size_t __##buffer_name##_n = 0;
|
||||||
|
|
||||||
#define BUFFER_SIZE(buffer_name) (__##buffer_name##_n)
|
#define BUFFER_SIZE(buffer_name) (__##buffer_name##_n)
|
||||||
|
|
|
@ -89,12 +89,14 @@
|
||||||
do { \
|
do { \
|
||||||
errno = 0; \
|
errno = 0; \
|
||||||
DEBUG_XFER (msg, __##msg##_n, "===> "); \
|
DEBUG_XFER (msg, __##msg##_n, "===> "); \
|
||||||
if ((nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, &__##res##_n, 0) < 0)) { \
|
int _res; \
|
||||||
|
if ((_res = nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, __##res##_size, 0)) < 0) { \
|
||||||
if (disconnect) { \
|
if (disconnect) { \
|
||||||
tag->active = false; \
|
tag->active = false; \
|
||||||
} \
|
} \
|
||||||
return errno = EIO, -1; \
|
return errno = EIO, -1; \
|
||||||
} \
|
} \
|
||||||
|
__##res##_n = _res; \
|
||||||
DEBUG_XFER (res, __##res##_n, "<=== "); \
|
DEBUG_XFER (res, __##res##_n, "<=== "); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
@ -308,7 +310,7 @@ mifare_classic_read (MifareTag tag, const MifareClassicBlockNumber block, Mifare
|
||||||
ASSERT_MIFARE_CLASSIC (tag);
|
ASSERT_MIFARE_CLASSIC (tag);
|
||||||
|
|
||||||
BUFFER_INIT (cmd, 2);
|
BUFFER_INIT (cmd, 2);
|
||||||
BUFFER_ALIAS (res, data);
|
BUFFER_ALIAS (res, data, sizeof(MifareClassicBlock));
|
||||||
|
|
||||||
BUFFER_APPEND (cmd, MC_READ);
|
BUFFER_APPEND (cmd, MC_READ);
|
||||||
BUFFER_APPEND (cmd, block);
|
BUFFER_APPEND (cmd, block);
|
||||||
|
|
|
@ -172,9 +172,11 @@ static ssize_t read_data (MifareTag tag, uint8_t command, uint8_t file_no, off_
|
||||||
MIFARE_DESFIRE (tag)->last_picc_error = OPERATION_OK; \
|
MIFARE_DESFIRE (tag)->last_picc_error = OPERATION_OK; \
|
||||||
MIFARE_DESFIRE (tag)->last_pcd_error = OPERATION_OK; \
|
MIFARE_DESFIRE (tag)->last_pcd_error = OPERATION_OK; \
|
||||||
DEBUG_XFER (__msg, __len, "===> "); \
|
DEBUG_XFER (__msg, __len, "===> "); \
|
||||||
if ((nfc_initiator_transceive_bytes (tag->device, __msg, __len, __res, &__##res##_n, 0)) < 0) { \
|
int _res; \
|
||||||
|
if ((_res = nfc_initiator_transceive_bytes (tag->device, __msg, __len, __res, __##res##_size, 0)) < 0) { \
|
||||||
return errno = EIO, -1; \
|
return errno = EIO, -1; \
|
||||||
} \
|
} \
|
||||||
|
__##res##_n = _res; \
|
||||||
DEBUG_XFER (__res, __##res##_n, "<=== "); \
|
DEBUG_XFER (__res, __##res##_n, "<=== "); \
|
||||||
res[__##res##_n-2] = __res[__##res##_n-1]; \
|
res[__##res##_n-2] = __res[__##res##_n-1]; \
|
||||||
__##res##_n--; \
|
__##res##_n--; \
|
||||||
|
|
|
@ -62,9 +62,11 @@
|
||||||
do { \
|
do { \
|
||||||
errno = 0; \
|
errno = 0; \
|
||||||
DEBUG_XFER (msg, __##msg##_n, "===> "); \
|
DEBUG_XFER (msg, __##msg##_n, "===> "); \
|
||||||
if ((nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, &__##res##_n, 0)) < 0) { \
|
int _res; \
|
||||||
|
if ((_res = nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, __##res##_size, 0)) < 0) { \
|
||||||
return errno = EIO, -1; \
|
return errno = EIO, -1; \
|
||||||
} \
|
} \
|
||||||
|
__##res##_n = _res; \
|
||||||
DEBUG_XFER (res, __##res##_n, "<=== "); \
|
DEBUG_XFER (res, __##res##_n, "<=== "); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
@ -76,10 +78,12 @@
|
||||||
return -1; \
|
return -1; \
|
||||||
} \
|
} \
|
||||||
DEBUG_XFER (msg, __##msg##_n, "===> "); \
|
DEBUG_XFER (msg, __##msg##_n, "===> "); \
|
||||||
if ((nfc_initiator_transceive_bytes (tag->device, msg, __##msg##_n, res, &__##res##_n, 0)) < 0) { \
|
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); \
|
nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, true); \
|
||||||
return errno = EIO, -1; \
|
return errno = EIO, -1; \
|
||||||
} \
|
} \
|
||||||
|
__##res##_n = _res; \
|
||||||
DEBUG_XFER (res, __##res##_n, "<=== "); \
|
DEBUG_XFER (res, __##res##_n, "<=== "); \
|
||||||
if (nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, true) < 0) { \
|
if (nfc_device_set_property_bool (tag->device, NP_EASY_FRAMING, true) < 0) { \
|
||||||
errno = EIO; \
|
errno = EIO; \
|
||||||
|
@ -183,7 +187,7 @@ mifare_ultralight_read (MifareTag tag, MifareUltralightPageNumber page, MifareUl
|
||||||
|
|
||||||
if (!MIFARE_ULTRALIGHT(tag)->cached_pages[page]) {
|
if (!MIFARE_ULTRALIGHT(tag)->cached_pages[page]) {
|
||||||
BUFFER_INIT (cmd, 2);
|
BUFFER_INIT (cmd, 2);
|
||||||
BUFFER_ALIAS (res, MIFARE_ULTRALIGHT(tag)->cache[page]);
|
BUFFER_ALIAS (res, MIFARE_ULTRALIGHT(tag)->cache[page], sizeof(MifareUltralightPage));
|
||||||
|
|
||||||
BUFFER_APPEND (cmd, 0x30);
|
BUFFER_APPEND (cmd, 0x30);
|
||||||
BUFFER_APPEND (cmd, page);
|
BUFFER_APPEND (cmd, page);
|
||||||
|
@ -322,8 +326,7 @@ is_mifare_ultralightc_on_reader (nfc_device *device, nfc_iso14443a_info nai)
|
||||||
};
|
};
|
||||||
nfc_initiator_select_passive_target (device, modulation, nai.abtUid, nai.szUidLen, &pnti);
|
nfc_initiator_select_passive_target (device, modulation, nai.abtUid, nai.szUidLen, &pnti);
|
||||||
nfc_device_set_property_bool (device, NP_EASY_FRAMING, false);
|
nfc_device_set_property_bool (device, NP_EASY_FRAMING, false);
|
||||||
size_t n;
|
ret = nfc_initiator_transceive_bytes (device, cmd_step1, sizeof (cmd_step1), res_step1, sizeof(res_step1), 0);
|
||||||
ret = nfc_initiator_transceive_bytes (device, cmd_step1, sizeof (cmd_step1), res_step1, &n, 0);
|
|
||||||
nfc_device_set_property_bool (device, NP_EASY_FRAMING, true);
|
nfc_device_set_property_bool (device, NP_EASY_FRAMING, true);
|
||||||
nfc_initiator_deselect_target (device);
|
nfc_initiator_deselect_target (device);
|
||||||
return ret >= 0;
|
return ret >= 0;
|
||||||
|
|
Loading…
Reference in a new issue