DEP enhancements:

- Add timeout on InJumpForDEP (pn53x) and initiator_select_dep (libnfc API)
- test_dep now works again (except 424Kbps)
- Fix ndi.ndm feeling when select a DEP target
Important: test_dep does not work on PN53x_USB devices after running previous tests
This commit is contained in:
Romuald Conty 2011-12-06 10:05:35 +00:00
parent 3b657ee547
commit c286eec920
8 changed files with 123 additions and 47 deletions

View file

@ -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)) { if(!nfc_initiator_select_dep_target (pnd, NDM_PASSIVE, NBR_212, NULL, &nt, 1000)) {
nfc_perror(pnd, "nfc_initiator_select_dep_target"); nfc_perror(pnd, "nfc_initiator_select_dep_target");
goto error; goto error;
} }

View file

@ -76,7 +76,7 @@ extern "C" {
NFC_EXPORT bool 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 bool 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 bool nfc_initiator_list_passive_targets (nfc_device *pnd, const nfc_modulation nm, nfc_target ant[], const size_t szTargets, size_t *pszTargetFound); NFC_EXPORT bool nfc_initiator_list_passive_targets (nfc_device *pnd, const nfc_modulation nm, nfc_target ant[], const size_t szTargets, size_t *pszTargetFound);
NFC_EXPORT bool 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_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); 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 bool nfc_initiator_deselect_target (nfc_device *pnd); NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device *pnd);
NFC_EXPORT bool 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_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);

View file

@ -1038,7 +1038,8 @@ bool
pn53x_initiator_select_dep_target(nfc_device *pnd, pn53x_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, const nfc_dep_info *pndiInitiator,
nfc_target *pnt) nfc_target *pnt,
const int timeout)
{ {
const uint8_t abtPassiveInitiatorData[] = { 0x00, 0xff, 0xff, 0x00, 0x00 }; // Only for 212/424 kpbs: First 4 bytes shall be set like this according to NFCIP-1, last byte is TSN (Time Slot Number) const uint8_t abtPassiveInitiatorData[] = { 0x00, 0xff, 0xff, 0x00, 0x00 }; // Only for 212/424 kpbs: First 4 bytes shall be set like this according to NFCIP-1, last byte is TSN (Time Slot Number)
const uint8_t * pbtPassiveInitiatorData = NULL; const uint8_t * pbtPassiveInitiatorData = NULL;
@ -1056,9 +1057,9 @@ pn53x_initiator_select_dep_target(nfc_device *pnd,
} }
if (pndiInitiator) { if (pndiInitiator) {
return pn53x_InJumpForDEP (pnd, ndm, nbr, pbtPassiveInitiatorData, pndiInitiator->abtNFCID3, pndiInitiator->abtGB, pndiInitiator->szGB, pnt); return pn53x_InJumpForDEP (pnd, ndm, nbr, pbtPassiveInitiatorData, pndiInitiator->abtNFCID3, pndiInitiator->abtGB, pndiInitiator->szGB, pnt, timeout);
} else { } else {
return pn53x_InJumpForDEP (pnd, ndm, nbr, pbtPassiveInitiatorData, NULL, NULL, 0, pnt); return pn53x_InJumpForDEP (pnd, ndm, nbr, pbtPassiveInitiatorData, NULL, NULL, 0, pnt, timeout);
} }
} }
@ -2199,7 +2200,8 @@ pn53x_InJumpForDEP (nfc_device *pnd,
const uint8_t *pbtPassiveInitiatorData, const uint8_t *pbtPassiveInitiatorData,
const uint8_t *pbtNFCID3i, const uint8_t *pbtNFCID3i,
const uint8_t *pbtGBi, const size_t szGBi, const uint8_t *pbtGBi, const size_t szGBi,
nfc_target *pnt) nfc_target *pnt,
const int timeout)
{ {
// Max frame size = 1 (Command) + 1 (ActPass) + 1 (Baud rate) + 1 (Next) + 5 (PassiveInitiatorData) + 10 (NFCID3) + 48 (General bytes) = 67 bytes // Max frame size = 1 (Command) + 1 (ActPass) + 1 (Baud rate) + 1 (Next) + 5 (PassiveInitiatorData) + 10 (NFCID3) + 48 (General bytes) = 67 bytes
uint8_t abtCmd[67] = { InJumpForDEP, (ndm == NDM_ACTIVE) ? 0x01 : 0x00 }; uint8_t abtCmd[67] = { InJumpForDEP, (ndm == NDM_ACTIVE) ? 0x01 : 0x00 };
@ -2259,7 +2261,7 @@ pn53x_InJumpForDEP (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);
// 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, 0)) if (!pn53x_transceive (pnd, abtCmd, offset, abtRx, &szRx, timeout))
return false; return false;
// 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
@ -2270,6 +2272,7 @@ pn53x_InJumpForDEP (nfc_device *pnd,
if (pnt) { if (pnt) {
pnt->nm.nmt = NMT_DEP; pnt->nm.nmt = NMT_DEP;
pnt->nm.nbr = nbr; pnt->nm.nbr = nbr;
pnt->nti.ndi.ndm = ndm;
memcpy (pnt->nti.ndi.abtNFCID3, abtRx + 2, 10); memcpy (pnt->nti.ndi.abtNFCID3, abtRx + 2, 10);
pnt->nti.ndi.btDID = abtRx[12]; pnt->nti.ndi.btDID = abtRx[12];
pnt->nti.ndi.btBS = abtRx[13]; pnt->nti.ndi.btBS = abtRx[13];

View file

@ -287,7 +287,8 @@ bool pn53x_initiator_poll_target (nfc_device *pnd,
bool pn53x_initiator_select_dep_target (nfc_device *pnd, bool pn53x_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, const nfc_dep_info *pndiInitiator,
nfc_target *pnt); nfc_target *pnt,
const int timeout);
bool pn53x_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, bool pn53x_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits,
const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits, const uint8_t *pbtTxPar, uint8_t *pbtRx, size_t *pszRxBits,
uint8_t *pbtRxPar); uint8_t *pbtRxPar);
@ -328,7 +329,8 @@ bool pn53x_InJumpForDEP (nfc_device *pnd,
const uint8_t *pbtPassiveInitiatorData, const uint8_t *pbtPassiveInitiatorData,
const uint8_t *pbtNFCID3i, const uint8_t *pbtNFCID3i,
const uint8_t *pbtGB, const size_t szGB, const uint8_t *pbtGB, const size_t szGB,
nfc_target *pnt); nfc_target *pnt,
const int timeout);
bool pn53x_TgInitAsTarget (nfc_device *pnd, pn53x_target_mode ptm, bool pn53x_TgInitAsTarget (nfc_device *pnd, pn53x_target_mode ptm,
const uint8_t *pbtMifareParams, const uint8_t *pbtMifareParams,
const uint8_t *pbtTkt, size_t szTkt, const uint8_t *pbtTkt, size_t szTkt,

View file

@ -571,6 +571,7 @@ read:
if (timeout == USB_INFINITE_TIMEOUT) { if (timeout == USB_INFINITE_TIMEOUT) {
usb_timeout = USB_TIMEOUT_PER_PASS; usb_timeout = USB_TIMEOUT_PER_PASS;
} else { } else {
// A user-provided timeout is set, we have to cut it in multiple chunk to be able to keep an nfc_abort_command() mecanism
remaining_time -= USB_TIMEOUT_PER_PASS; remaining_time -= USB_TIMEOUT_PER_PASS;
if (remaining_time <= 0) { if (remaining_time <= 0) {
pnd->iLastError = ECOMTIMEOUT; pnd->iLastError = ECOMTIMEOUT;

View file

@ -134,7 +134,7 @@ struct nfc_driver_t {
bool (*initiator_init) (nfc_device *pnd); bool (*initiator_init) (nfc_device *pnd);
bool (*initiator_select_passive_target) (nfc_device *pnd, const nfc_modulation nm, const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt); bool (*initiator_select_passive_target) (nfc_device *pnd, const nfc_modulation nm, const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt);
bool (*initiator_poll_target) (nfc_device *pnd, const nfc_modulation * pnmModulations, const size_t szModulations, const uint8_t uiPollNr, const uint8_t btPeriod, nfc_target * pnt); bool (*initiator_poll_target) (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) (nfc_device *pnd, const nfc_dep_mode ndm, const nfc_baud_rate nbr, const nfc_dep_info * pndiInitiator, nfc_target * pnt); bool (*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);
bool (*initiator_deselect_target) (nfc_device *pnd); bool (*initiator_deselect_target) (nfc_device *pnd);
bool (*initiator_transceive_bytes) (nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, int timeout); bool (*initiator_transceive_bytes) (nfc_device *pnd, const uint8_t * pbtTx, const size_t szTx, uint8_t * pbtRx, size_t * pszRx, int timeout);
bool (*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); bool (*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);

View file

@ -432,9 +432,9 @@ nfc_initiator_poll_target (nfc_device *pnd,
bool bool
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 nfc_dep_info *pndiInitiator, nfc_target *pnt, const int timeout)
{ {
HAL (initiator_select_dep_target, pnd, ndm, nbr, pndiInitiator, pnt); HAL (initiator_select_dep_target, pnd, ndm, nbr, pndiInitiator, pnt, timeout);
} }
/** /**

View file

@ -55,10 +55,10 @@ void *
target_thread (void *arg) target_thread (void *arg)
{ {
intptr_t thread_res = 0; intptr_t thread_res = 0;
// nfc_device *device = ((struct thread_data *) arg)->device; nfc_device *device = ((struct thread_data *) arg)->device;
cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context); cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context);
#if 0 printf ("=========== TARGET %s =========\n", nfc_device_name (device));
nfc_target nt = { nfc_target nt = {
.nm = { .nm = {
.nmt = NMT_DEP, .nmt = NMT_DEP,
@ -69,7 +69,7 @@ target_thread (void *arg)
.abtNFCID3 = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA }, .abtNFCID3 = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA },
.szGB = 4, .szGB = 4,
.abtGB = { 0x12, 0x34, 0x56, 0x78 }, .abtGB = { 0x12, 0x34, 0x56, 0x78 },
.ndm = NDM_UNDEFINED, .ndm = NDM_PASSIVE,
/* These bytes are not used by nfc_target_init: the chip will provide them automatically to the initiator */ /* These bytes are not used by nfc_target_init: the chip will provide them automatically to the initiator */
.btDID = 0x00, .btDID = 0x00,
.btBS = 0x00, .btBS = 0x00,
@ -83,21 +83,46 @@ target_thread (void *arg)
uint8_t abtRx[1024]; uint8_t abtRx[1024];
size_t szRx = sizeof (abtRx); size_t szRx = sizeof (abtRx);
bool res = nfc_target_init (device, &nt, abtRx, &szRx); bool res = nfc_target_init (device, &nt, abtRx, &szRx);
// cut_assert_true (res, cut_message ("Can't initialize NFC device as target")); cut_assert_true (res, cut_message ("Can't initialize NFC device as target: %s", nfc_strerror (device)));
uint8_t abtAtrRes[] = "\x11\xd4\x00\x01\xfe\x12\x34\x56\x78\x90\x12\x00\x00\x00\x00\x00\x00"; const uint8_t abtAtrRes[] = "\x11\xd4\x00\x01\xfe\x12\x34\x56\x78\x90\x12\x00\x00\x00\x00\x00\x00";
// cut_assert_equal_memory (abtAtrRes, sizeof (abtAtrRes) - 1, abtRx, szRx, cut_message ("Invalid received ATR_RES")); cut_assert_equal_memory (abtAtrRes, sizeof (abtAtrRes) - 1, abtRx, szRx, cut_message ("Invalid received ATR_RES"));
if (!res) { thread_res = -1; return (void*) thread_res; }
res = nfc_target_receive_bytes (device, abtRx, &szRx); // First pass
// cut_assert_true (res, cut_message ("Can't receive bytes from initiator")); res = nfc_target_receive_bytes (device, abtRx, &szRx, 500);
cut_assert_true (res, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
uint8_t abtAttRx[] = "Hello DEP target!"; const uint8_t abtAttRx[] = "Hello DEP target!";
// 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; }
uint8_t abtTx[] = "Hello DEP initiator!"; const uint8_t abtTx[] = "Hello DEP initiator!";
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx)); res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
// cut_assert_true (res, cut_message ("Can't send bytes to initiator")); cut_assert_true (res, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
#endif if (!res) { thread_res = -1; return (void*) thread_res; }
// Second pass
res = nfc_target_receive_bytes (device, abtRx, &szRx, 500);
cut_assert_true (res, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
if (!res) { thread_res = -1; return (void*) thread_res; }
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
cut_assert_true (res, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
if (!res) { thread_res = -1; return (void*) thread_res; }
// Third pass
res = nfc_target_receive_bytes (device, abtRx, &szRx, 500);
cut_assert_true (res, cut_message ("Can't receive bytes from initiator: %s", nfc_strerror (device)));
cut_assert_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
if (!res) { thread_res = -1; return (void*) thread_res; }
res = nfc_target_send_bytes (device, abtTx, sizeof(abtTx), 500);
cut_assert_true (res, cut_message ("Can't send bytes to initiator: %s", nfc_strerror (device)));
if (!res) { thread_res = -1; return (void*) thread_res; }
return (void *) thread_res; return (void *) thread_res;
} }
@ -106,45 +131,90 @@ void *
initiator_thread (void *arg) initiator_thread (void *arg)
{ {
intptr_t thread_res = 0; intptr_t thread_res = 0;
// nfc_device *device = ((struct thread_data *) arg)->device; nfc_device *device = ((struct thread_data *) arg)->device;
cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context); cut_set_current_test_context (((struct thread_data *) arg)->cut_test_context);
cut_fail("plop");
#if 0
/* /*
* Wait some time for the other thread to initialise NFC device as target * Wait some time for the other thread to initialise NFC device as target
*/ */
sleep (1); sleep (1);
printf ("====================================\n"); printf ("=========== INITIATOR %s =========\n", nfc_device_name (device));
printf ("Activating initiator...\n");
bool res = nfc_initiator_init (device); bool res = nfc_initiator_init (device);
// cut_assert_true (res, cut_message ("Can't initialize NFC device as initiator")); cut_assert_true (res, cut_message ("Can't initialize NFC device as initiator: %s", nfc_strerror (device)));
if (!res) { thread_res = -1; return (void*) thread_res; }
nfc_target nt; nfc_target nt;
// Passive mode / 212Kbps // Passive mode / 212Kbps
res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_212, NULL, &nt); printf ("=========== INITIATOR %s (Passive mode / 212Kbps) =========\n", nfc_device_name (device));
// cut_assert_true (res, cut_message ("Can't select any DEP target")); res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_212, NULL, &nt, 5000);
// cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation")); cut_assert_true (res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device)));
// cut_assert_equal_int (NBR_212, nt.nm.nbr, cut_message ("Invalid target baud rate")); cut_assert_equal_int (NMT_DEP, nt.nm.nmt, cut_message ("Invalid target modulation"));
// 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 (NBR_212, nt.nm.nbr, cut_message ("Invalid target baud rate"));
// cut_assert_equal_int (NDM_PASSIVE, nt.nti.ndi.ndm, cut_message ("Invalid target DEP mode")); 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 ("\x12\x34\x56\x78", 4, nt.nti.ndi.abtGB, nt.nti.ndi.szGB, cut_message ("Invalid target general bytes")); 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"));
if (!res) { thread_res = -1; return (void*) thread_res; }
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); res = nfc_initiator_transceive_bytes (device, abtTx, sizeof (abtTx), abtRx, &szRx, 500);
// cut_assert_true (res, cut_message ("Can't transceive bytes to target")); cut_assert_true (res, cut_message ("Can't transceive bytes to target: %s", nfc_strerror (device)));
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; }
res = nfc_initiator_deselect_target (device); res = nfc_initiator_deselect_target (device);
// cut_assert_true (res, cut_message ("Can't deselect target")); cut_assert_true (res, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
#endif if (!res) { thread_res = -1; return (void*) thread_res; }
// Passive mode / 212Kbps (second pass)
printf ("=========== INITIATOR %s (Passive mode / 212Kbps, second pass) =========\n", nfc_device_name (device));
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 (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_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_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; }
szRx = sizeof (abtRx);
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_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
if (!res) { thread_res = -1; return (void*) thread_res; }
res = nfc_initiator_deselect_target (device);
cut_assert_true (res, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
if (!res) { thread_res = -1; return (void*) thread_res; }
// Passive mode / 424Kbps
printf ("=========== INITIATOR %s (Passive mode / 424Kbps) =========\n", nfc_device_name (device));
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 (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_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_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; }
szRx = sizeof (abtRx);
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_equal_memory (abtAttRx, sizeof (abtAttRx), abtRx, szRx, cut_message ("Invalid received data"));
if (!res) { thread_res = -1; return (void*) thread_res; }
res = nfc_initiator_deselect_target (device);
cut_assert_true (res, cut_message ("Can't deselect target: %s", nfc_strerror (device)));
if (!res) { thread_res = -1; return (void*) thread_res; }
return (void *) thread_res; return (void *) thread_res;
} }