nfc_initiator_select_dep_target() function returns nox libnf error code and fix some uses of nfc_initiator_transceive_bytes() function.
This commit is contained in:
parent
0f5cc5683d
commit
c41d7de8ca
12 changed files with 58 additions and 57 deletions
|
@ -86,7 +86,7 @@ main (int argc, const char *argv[])
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!nfc_initiator_select_dep_target (pnd, NDM_PASSIVE, NBR_212, NULL, &nt, 1000)) {
|
if(nfc_initiator_select_dep_target (pnd, NDM_PASSIVE, NBR_212, NULL, &nt, 1000) < 0) {
|
||||||
nfc_perror(pnd, "nfc_initiator_select_dep_target");
|
nfc_perror(pnd, "nfc_initiator_select_dep_target");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ extern "C" {
|
||||||
NFC_EXPORT int nfc_initiator_select_passive_target (nfc_device *pnd, const nfc_modulation nm, const uint8_t *pbtInitData, const size_t szInitData, nfc_target *pnt);
|
NFC_EXPORT int nfc_initiator_select_passive_target (nfc_device *pnd, const nfc_modulation nm, const uint8_t *pbtInitData, const size_t szInitData, nfc_target *pnt);
|
||||||
NFC_EXPORT int nfc_initiator_list_passive_targets (nfc_device *pnd, const nfc_modulation nm, nfc_target ant[], const size_t szTargets);
|
NFC_EXPORT int nfc_initiator_list_passive_targets (nfc_device *pnd, const nfc_modulation nm, nfc_target ant[], const size_t szTargets);
|
||||||
NFC_EXPORT int nfc_initiator_poll_target (nfc_device *pnd, const nfc_modulation *pnmTargetTypes, const size_t szTargetTypes, const uint8_t uiPollNr, const uint8_t uiPeriod, nfc_target *pnt);
|
NFC_EXPORT int nfc_initiator_poll_target (nfc_device *pnd, const nfc_modulation *pnmTargetTypes, const size_t szTargetTypes, const uint8_t uiPollNr, const uint8_t uiPeriod, nfc_target *pnt);
|
||||||
NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout);
|
NFC_EXPORT int nfc_initiator_select_dep_target (nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout);
|
||||||
NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device *pnd);
|
NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device *pnd);
|
||||||
NFC_EXPORT int nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, size_t *pszRx, int timeout);
|
NFC_EXPORT int nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx, size_t *pszRx, int timeout);
|
||||||
NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar);
|
NFC_EXPORT bool nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits, uint8_t *pbtRxPar);
|
||||||
|
|
|
@ -1082,7 +1082,7 @@ pn53x_initiator_poll_target (struct nfc_device *pnd,
|
||||||
return NFC_ECHIP;
|
return NFC_ECHIP;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
int
|
||||||
pn53x_initiator_select_dep_target(struct nfc_device *pnd,
|
pn53x_initiator_select_dep_target(struct nfc_device *pnd,
|
||||||
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
||||||
const nfc_dep_info *pndiInitiator,
|
const nfc_dep_info *pndiInitiator,
|
||||||
|
@ -2243,7 +2243,7 @@ pn53x_InAutoPoll (struct nfc_device *pnd,
|
||||||
* @param szGBi count of General Bytes
|
* @param szGBi count of General Bytes
|
||||||
* @param[out] pnt \a nfc_target which will be filled by this function
|
* @param[out] pnt \a nfc_target which will be filled by this function
|
||||||
*/
|
*/
|
||||||
bool
|
int
|
||||||
pn53x_InJumpForDEP (struct nfc_device *pnd,
|
pn53x_InJumpForDEP (struct nfc_device *pnd,
|
||||||
const nfc_dep_mode ndm,
|
const nfc_dep_mode ndm,
|
||||||
const nfc_baud_rate nbr,
|
const nfc_baud_rate nbr,
|
||||||
|
@ -2271,7 +2271,7 @@ pn53x_InJumpForDEP (struct nfc_device *pnd,
|
||||||
case NBR_847:
|
case NBR_847:
|
||||||
case NBR_UNDEFINED:
|
case NBR_UNDEFINED:
|
||||||
pnd->last_error = NFC_EINVARG;
|
pnd->last_error = NFC_EINVARG;
|
||||||
return false;
|
return pnd->last_error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2291,7 +2291,7 @@ pn53x_InJumpForDEP (struct nfc_device *pnd,
|
||||||
case NBR_847:
|
case NBR_847:
|
||||||
case NBR_UNDEFINED:
|
case NBR_UNDEFINED:
|
||||||
pnd->last_error = NFC_EINVARG;
|
pnd->last_error = NFC_EINVARG;
|
||||||
return false;
|
return pnd->last_error;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2310,13 +2310,14 @@ pn53x_InJumpForDEP (struct nfc_device *pnd,
|
||||||
|
|
||||||
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||||
size_t szRx = sizeof (abtRx);
|
size_t szRx = sizeof (abtRx);
|
||||||
|
int res = 0;
|
||||||
// Try to find a target, call the transceive callback function of the current device
|
// Try to find a target, call the transceive callback function of the current device
|
||||||
if (pn53x_transceive (pnd, abtCmd, offset, abtRx, &szRx, timeout) < 0)
|
if ((res = pn53x_transceive (pnd, abtCmd, offset, abtRx, &szRx, timeout)) < 0)
|
||||||
return false;
|
return res;
|
||||||
|
|
||||||
// Make sure one target has been found, the PN53X returns 0x00 if none was available
|
// Make sure one target has been found, the PN53X returns 0x00 if none was available
|
||||||
if (abtRx[1] != 1)
|
if (abtRx[1] != 1)
|
||||||
return false;
|
return NFC_ECHIP;
|
||||||
|
|
||||||
// Is a target struct available
|
// Is a target struct available
|
||||||
if (pnt) {
|
if (pnt) {
|
||||||
|
@ -2336,7 +2337,7 @@ pn53x_InJumpForDEP (struct nfc_device *pnd,
|
||||||
pnt->nti.ndi.szGB = 0;
|
pnt->nti.ndi.szGB = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return NFC_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -294,7 +294,7 @@ int pn53x_initiator_poll_target (struct nfc_device *pnd,
|
||||||
const nfc_modulation *pnmModulations, const size_t szModulations,
|
const nfc_modulation *pnmModulations, const size_t szModulations,
|
||||||
const uint8_t uiPollNr, const uint8_t uiPeriod,
|
const uint8_t uiPollNr, const uint8_t uiPeriod,
|
||||||
nfc_target *pnt);
|
nfc_target *pnt);
|
||||||
bool pn53x_initiator_select_dep_target (struct nfc_device *pnd,
|
int pn53x_initiator_select_dep_target (struct nfc_device *pnd,
|
||||||
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
||||||
const nfc_dep_info *pndiInitiator,
|
const nfc_dep_info *pndiInitiator,
|
||||||
nfc_target *pnt,
|
nfc_target *pnt,
|
||||||
|
@ -335,7 +335,7 @@ int pn53x_InAutoPoll (struct nfc_device *pnd, const pn53x_target_type *ppttTa
|
||||||
const uint8_t btPollNr, const uint8_t btPeriod, nfc_target *pntTargets,
|
const uint8_t btPollNr, const uint8_t btPeriod, nfc_target *pntTargets,
|
||||||
size_t *pszTargetFound,
|
size_t *pszTargetFound,
|
||||||
const int timeout);
|
const int timeout);
|
||||||
bool pn53x_InJumpForDEP (struct nfc_device *pnd,
|
int pn53x_InJumpForDEP (struct nfc_device *pnd,
|
||||||
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
||||||
const uint8_t *pbtPassiveInitiatorData,
|
const uint8_t *pbtPassiveInitiatorData,
|
||||||
const uint8_t *pbtNFCID3i,
|
const uint8_t *pbtNFCID3i,
|
||||||
|
|
|
@ -135,7 +135,7 @@ struct nfc_driver_t {
|
||||||
int (*initiator_init) (struct nfc_device *pnd);
|
int (*initiator_init) (struct nfc_device *pnd);
|
||||||
int (*initiator_select_passive_target) (struct nfc_device *pnd, const nfc_modulation nm, const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt);
|
int (*initiator_select_passive_target) (struct nfc_device *pnd, const nfc_modulation nm, const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt);
|
||||||
int (*initiator_poll_target) (struct nfc_device *pnd, const nfc_modulation * pnmModulations, const size_t szModulations, const uint8_t uiPollNr, const uint8_t btPeriod, nfc_target * pnt);
|
int (*initiator_poll_target) (struct nfc_device *pnd, const nfc_modulation * pnmModulations, const size_t szModulations, const uint8_t uiPollNr, const uint8_t btPeriod, nfc_target * pnt);
|
||||||
bool (*initiator_select_dep_target) (struct nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info * pndiInitiator, nfc_target * pnt, const int timeout);
|
int (*initiator_select_dep_target) (struct nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info * pndiInitiator, nfc_target * pnt, const int timeout);
|
||||||
bool (*initiator_deselect_target) (struct nfc_device *pnd);
|
bool (*initiator_deselect_target) (struct nfc_device *pnd);
|
||||||
int (*initiator_transceive_bytes) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, int timeout);
|
int (*initiator_transceive_bytes) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, int timeout);
|
||||||
bool (*initiator_transceive_bits) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar);
|
bool (*initiator_transceive_bits) (struct nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar);
|
||||||
|
|
|
@ -433,7 +433,7 @@ nfc_initiator_poll_target (nfc_device *pnd,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Select a target and request active or passive mode for D.E.P. (Data Exchange Protocol)
|
* @brief Select a target and request active or passive mode for D.E.P. (Data Exchange Protocol)
|
||||||
* @return Returns \c true if action was successfully performed; otherwise returns \c false.
|
* @return Returns 0 on success, otherwise returns libnfc's error code (negative value).
|
||||||
*
|
*
|
||||||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||||
* @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode)
|
* @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode)
|
||||||
|
@ -446,7 +446,7 @@ nfc_initiator_poll_target (nfc_device *pnd,
|
||||||
*
|
*
|
||||||
* @note \a nfc_dep_info will be returned when the target was acquired successfully.
|
* @note \a nfc_dep_info will be returned when the target was acquired successfully.
|
||||||
*/
|
*/
|
||||||
bool
|
int
|
||||||
nfc_initiator_select_dep_target (nfc_device *pnd,
|
nfc_initiator_select_dep_target (nfc_device *pnd,
|
||||||
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
const nfc_dep_mode ndm, const nfc_baud_rate nbr,
|
||||||
const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout)
|
const nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout)
|
||||||
|
|
|
@ -124,27 +124,27 @@ initiator_thread (void *arg)
|
||||||
|
|
||||||
// Active mode
|
// Active mode
|
||||||
printf ("=========== INITIATOR %s (Active mode / %s Kbps) =========\n", nfc_device_get_name (device), str_nfc_baud_rate(nbr));
|
printf ("=========== INITIATOR %s (Active mode / %s Kbps) =========\n", nfc_device_get_name (device), str_nfc_baud_rate(nbr));
|
||||||
bool res = nfc_initiator_select_dep_target (device, NDM_ACTIVE, nbr, NULL, &nt, 1000);
|
int res = nfc_initiator_select_dep_target (device, NDM_ACTIVE, nbr, NULL, &nt, 1000);
|
||||||
cut_assert_true (res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
|
cut_assert_equal_int (0, res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
|
||||||
cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
|
cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
|
||||||
cut_assert_equal_int (nbr, nt.nm.nbr, cut_message ("Invalid target baud rate"));
|
cut_assert_equal_int (nbr, nt.nm.nbr, cut_message ("Invalid target baud rate"));
|
||||||
cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
|
cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
|
||||||
cut_assert_equal_int (NDM_ACTIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
|
cut_assert_equal_int (NDM_ACTIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
|
||||||
cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
|
cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP target!";
|
const uint8_t abtTx[] = "Hello DEP target!";
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
size_t szRx = sizeof (abtRx);
|
size_t szRx = sizeof (abtRx);
|
||||||
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 5000);
|
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 5000);
|
||||||
cut_assert_true (res, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
cut_assert_operator_int (res, >=, 0, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
||||||
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
||||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||||
res = nfc_initiator_deselect_target (device);
|
bool bres = nfc_initiator_deselect_target (device);
|
||||||
cut_assert_true (res, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
cut_assert_true (bres, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (!bres) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
return (void *) thread_res;
|
return (void *) thread_res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,94 +157,94 @@ initiator_thread (void *arg)
|
||||||
|
|
||||||
// Passive mode / 106Kbps
|
// Passive mode / 106Kbps
|
||||||
printf ("=========== INITIATOR %s (Passive mode / 106Kbps) =========\n", nfc_device_get_name (device));
|
printf ("=========== INITIATOR %s (Passive mode / 106Kbps) =========\n", nfc_device_get_name (device));
|
||||||
bool res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_106, NULL, &nt, 5000);
|
int res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_106, NULL, &nt, 5000);
|
||||||
cut_assert_true (res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
|
cut_assert_equal_int (0, res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
|
||||||
cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
|
cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
|
||||||
cut_assert_equal_int (NBR_106, nt.nm.nbr, cut_message ("Invalid target baud rate"));
|
cut_assert_equal_int (NBR_106, nt.nm.nbr, cut_message ("Invalid target baud rate"));
|
||||||
cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
|
cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
|
||||||
cut_assert_equal_int (NDM_PASSIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
|
cut_assert_equal_int (NDM_PASSIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
|
||||||
cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
|
cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
const uint8_t abtTx[] = "Hello DEP target!";
|
const uint8_t abtTx[] = "Hello DEP target!";
|
||||||
uint8_t abtRx[1024];
|
uint8_t abtRx[1024];
|
||||||
size_t szRx = sizeof (abtRx);
|
size_t szRx = sizeof (abtRx);
|
||||||
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 500);
|
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 500);
|
||||||
cut_assert_true (res, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
cut_assert_operator_int (res, >=, 0, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
||||||
|
|
||||||
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
const uint8_t abtAttRx[] = "Hello DEP initiator!";
|
||||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target (device);
|
bool bres = nfc_initiator_deselect_target (device);
|
||||||
cut_assert_true (res, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
cut_assert_true (bres, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (!bres) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
// Passive mode / 212Kbps (second pass)
|
// Passive mode / 212Kbps (second pass)
|
||||||
printf ("=========== INITIATOR %s (Passive mode / 212Kbps) =========\n", nfc_device_get_name (device));
|
printf ("=========== INITIATOR %s (Passive mode / 212Kbps) =========\n", nfc_device_get_name (device));
|
||||||
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_212, NULL, &nt, 1000);
|
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_212, NULL, &nt, 1000);
|
||||||
cut_assert_true (res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
|
cut_assert_equal_int (0, res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
|
||||||
cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
|
cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
|
||||||
cut_assert_equal_int (NBR_212, nt.nm.nbr, cut_message ("Invalid target baud rate"));
|
cut_assert_equal_int (NBR_212, nt.nm.nbr, cut_message ("Invalid target baud rate"));
|
||||||
cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
|
cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
|
||||||
cut_assert_equal_int (NDM_PASSIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
|
cut_assert_equal_int (NDM_PASSIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
|
||||||
cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
|
cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
szRx = sizeof (abtRx);
|
szRx = sizeof (abtRx);
|
||||||
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 1000);
|
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 1000);
|
||||||
cut_assert_true (res, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
cut_assert_operator_int (res, >=, 0, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
||||||
|
|
||||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target (device);
|
bres = nfc_initiator_deselect_target (device);
|
||||||
cut_assert_true (res, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
cut_assert_true (bres, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (!bres) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
// Passive mode / 212Kbps
|
// Passive mode / 212Kbps
|
||||||
printf ("=========== INITIATOR %s (Passive mode / 212Kbps, second pass) =========\n", nfc_device_get_name (device));
|
printf ("=========== INITIATOR %s (Passive mode / 212Kbps, second pass) =========\n", nfc_device_get_name (device));
|
||||||
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_212, NULL, &nt, 1000);
|
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_212, NULL, &nt, 1000);
|
||||||
cut_assert_true (res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
|
cut_assert_equal_int (0, res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
|
||||||
cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
|
cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
|
||||||
cut_assert_equal_int (NBR_212, nt.nm.nbr, cut_message ("Invalid target baud rate"));
|
cut_assert_equal_int (NBR_212, nt.nm.nbr, cut_message ("Invalid target baud rate"));
|
||||||
cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
|
cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
|
||||||
cut_assert_equal_int (NDM_PASSIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
|
cut_assert_equal_int (NDM_PASSIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
|
||||||
cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
|
cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
szRx = sizeof (abtRx);
|
szRx = sizeof (abtRx);
|
||||||
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 5000);
|
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 5000);
|
||||||
cut_assert_true (res, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
cut_assert_operator_int (res, >=, 0, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
||||||
|
|
||||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target (device);
|
bres = nfc_initiator_deselect_target (device);
|
||||||
cut_assert_true (res, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
cut_assert_true (bres, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (!bres) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
// Passive mode / 424Kbps
|
// Passive mode / 424Kbps
|
||||||
printf ("=========== INITIATOR %s (Passive mode / 424Kbps) =========\n", nfc_device_get_name (device));
|
printf ("=========== INITIATOR %s (Passive mode / 424Kbps) =========\n", nfc_device_get_name (device));
|
||||||
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_424, NULL, &nt, 1000);
|
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_424, NULL, &nt, 1000);
|
||||||
cut_assert_true (res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
|
cut_assert_equal_int (0, res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
|
||||||
cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
|
cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
|
||||||
cut_assert_equal_int (NBR_424, nt.nm.nbr, cut_message ("Invalid target baud rate"));
|
cut_assert_equal_int (NBR_424, nt.nm.nbr, cut_message ("Invalid target baud rate"));
|
||||||
cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
|
cut_assert_equal_memory ("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message ("Invalid target NFCID3"));
|
||||||
cut_assert_equal_int (NDM_PASSIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
|
cut_assert_equal_int (NDM_PASSIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode"));
|
||||||
cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
|
cut_assert_equal_memory ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes"));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
szRx = sizeof (abtRx);
|
szRx = sizeof (abtRx);
|
||||||
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 5000);
|
res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 5000);
|
||||||
cut_assert_true (res, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
cut_assert_operator_int (res, >=, 0, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
|
||||||
|
|
||||||
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (res < 0) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
res = nfc_initiator_deselect_target (device);
|
bres = nfc_initiator_deselect_target (device);
|
||||||
cut_assert_true (res, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
cut_assert_true (bres, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
|
||||||
if (!res) { thread_res = -1; return (void*) thread_res; }
|
if (!bres) { thread_res = -1; return (void*) thread_res; }
|
||||||
|
|
||||||
return (void *) thread_res;
|
return (void *) thread_res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,7 @@ transmit_bytes (const uint8_t *pbtTx, const size_t szTx)
|
||||||
printf ("Sent bits: ");
|
printf ("Sent bits: ");
|
||||||
print_hex (pbtTx, szTx);
|
print_hex (pbtTx, szTx);
|
||||||
// Transmit the command bytes
|
// Transmit the command bytes
|
||||||
if (!nfc_initiator_transceive_bytes (pnd, pbtTx, szTx, abtRx, &szRx, 0))
|
if (nfc_initiator_transceive_bytes (pnd, pbtTx, szTx, abtRx, &szRx, 0) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Show received answer
|
// Show received answer
|
||||||
|
|
|
@ -118,7 +118,7 @@ transmit_bytes (const uint8_t *pbtTx, const size_t szTx)
|
||||||
print_hex (pbtTx, szTx);
|
print_hex (pbtTx, szTx);
|
||||||
}
|
}
|
||||||
// Transmit the command bytes
|
// Transmit the command bytes
|
||||||
if (!nfc_initiator_transceive_bytes (pnd, pbtTx, szTx, abtRx, &szRx, 0))
|
if (nfc_initiator_transceive_bytes (pnd, pbtTx, szTx, abtRx, &szRx, 0) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Show received answer
|
// Show received answer
|
||||||
|
|
|
@ -116,7 +116,7 @@ nfc_forum_tag_type3_check (nfc_device *pnd, const nfc_target nt, const uint16_t
|
||||||
uint8_t res[1024];
|
uint8_t res[1024];
|
||||||
|
|
||||||
size_t res_len;
|
size_t res_len;
|
||||||
if (!nfc_initiator_transceive_bytes (pnd, frame, frame_len, res, &res_len, 0)) {
|
if (nfc_initiator_transceive_bytes (pnd, frame, frame_len, res, &res_len, 0) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
const size_t res_overhead = 1 + 1 + 8 + 2; // 1+1+8+2: LEN + CMD + NFCID2 + STATUS
|
const size_t res_overhead = 1 + 1 + 8 + 2; // 1+1+8+2: LEN + CMD + NFCID2 + STATUS
|
||||||
|
|
|
@ -400,8 +400,8 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
if (!target_only_mode) {
|
if (!target_only_mode) {
|
||||||
// Forward the frame to the original tag
|
// Forward the frame to the original tag
|
||||||
ret = nfc_initiator_transceive_bytes
|
ret = (nfc_initiator_transceive_bytes
|
||||||
(pndInitiator, abtCapdu, szCapduLen, abtRapdu, &szRapduLen, 0);
|
(pndInitiator, abtCapdu, szCapduLen, abtRapdu, &szRapduLen, 0) < 0) ? 0 : 1;
|
||||||
} else {
|
} else {
|
||||||
if (scan_hex_fd3(abtRapdu, &szRapduLen, "R-APDU") != EXIT_SUCCESS) {
|
if (scan_hex_fd3(abtRapdu, &szRapduLen, "R-APDU") != EXIT_SUCCESS) {
|
||||||
fprintf (stderr, "Error while scanning R-APDU from FD3\n");
|
fprintf (stderr, "Error while scanning R-APDU from FD3\n");
|
||||||
|
|
Loading…
Reference in a new issue