diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index cc170a2..dfae861 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -2315,28 +2315,27 @@ pn53x_InJumpForDEP (struct nfc_device *pnd, return res; // Make sure one target has been found, the PN53X returns 0x00 if none was available - if (abtRx[1] != 1) - return NFC_ECHIP; - - // Is a target struct available - if (pnt) { - pnt->nm.nmt = NMT_DEP; - pnt->nm.nbr = nbr; - pnt->nti.ndi.ndm = ndm; - memcpy (pnt->nti.ndi.abtNFCID3, abtRx + 2, 10); - pnt->nti.ndi.btDID = abtRx[12]; - pnt->nti.ndi.btBS = abtRx[13]; - pnt->nti.ndi.btBR = abtRx[14]; - pnt->nti.ndi.btTO = abtRx[15]; - pnt->nti.ndi.btPP = abtRx[16]; - if(szRx > 17) { - pnt->nti.ndi.szGB = szRx - 17; - memcpy (pnt->nti.ndi.abtGB, abtRx + 17, pnt->nti.ndi.szGB); - } else { - pnt->nti.ndi.szGB = 0; + if (abtRx[1] >= 1) { + // Is a target struct available + if (pnt) { + pnt->nm.nmt = NMT_DEP; + pnt->nm.nbr = nbr; + pnt->nti.ndi.ndm = ndm; + memcpy (pnt->nti.ndi.abtNFCID3, abtRx + 2, 10); + pnt->nti.ndi.btDID = abtRx[12]; + pnt->nti.ndi.btBS = abtRx[13]; + pnt->nti.ndi.btBR = abtRx[14]; + pnt->nti.ndi.btTO = abtRx[15]; + pnt->nti.ndi.btPP = abtRx[16]; + if(szRx > 17) { + pnt->nti.ndi.szGB = szRx - 17; + memcpy (pnt->nti.ndi.abtGB, abtRx + 17, pnt->nti.ndi.szGB); + } else { + pnt->nti.ndi.szGB = 0; + } } } - return NFC_SUCCESS; + return abtRx[1]; } int diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 723ceef..9de8049 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -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) - * @return Returns 0 on success, otherwise returns libnfc's error code (negative value). + * @return Returns selected D.E.P tagets count on success, otherwise returns libnfc's error code (negative value). * * @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) diff --git a/test/test_dep_active.c b/test/test_dep_active.c index 146efe6..e25aa88 100644 --- a/test/test_dep_active.c +++ b/test/test_dep_active.c @@ -116,16 +116,16 @@ initiator_thread (void *arg) */ sleep (1); printf ("=========== INITIATOR %s =========\n", nfc_device_get_name (device)); - int ires = nfc_initiator_init (device); - cut_assert_equal_int (0, ires, cut_message ("Can't initialize NFC device as initiator: %s", nfc_strerror (device))); - if (ires < 0) { thread_res = -1; return (void*) thread_res; } + int res = nfc_initiator_init (device); + cut_assert_equal_int (0, res, cut_message ("Can't initialize NFC device as initiator: %s", nfc_strerror (device))); + if (res < 0) { thread_res = -1; return (void*) thread_res; } nfc_target nt; // Active mode printf ("=========== INITIATOR %s (Active mode / %s Kbps) =========\n", nfc_device_get_name (device), str_nfc_baud_rate(nbr)); - int res = nfc_initiator_select_dep_target (device, NDM_ACTIVE, nbr, NULL, &nt, 1000); - cut_assert_equal_int (0, res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device))); + res = nfc_initiator_select_dep_target (device, NDM_ACTIVE, nbr, NULL, &nt, 1000); + cut_assert_operator_int (res, >=, 0, 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, 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")); diff --git a/test/test_dep_passive.c b/test/test_dep_passive.c index ce755c7..49f2936 100644 --- a/test/test_dep_passive.c +++ b/test/test_dep_passive.c @@ -148,17 +148,16 @@ initiator_thread (void *arg) sleep (1); printf ("=========== INITIATOR %s =========\n", nfc_device_get_name (device)); - int ires = nfc_initiator_init (device); - printf ("IRES: %d\n", ires); - cut_assert_equal_int (0, ires, cut_message ("Can't initialize NFC device as initiator: %s", nfc_strerror (device))); - if (ires < 0) { thread_res = -1; return (void*) thread_res; } + int res = nfc_initiator_init (device); + cut_assert_equal_int (0, res, cut_message ("Can't initialize NFC device as initiator: %s", nfc_strerror (device))); + if (res < 0) { thread_res = -1; return (void*) thread_res; } nfc_target nt; // Passive mode / 106Kbps printf ("=========== INITIATOR %s (Passive mode / 106Kbps) =========\n", nfc_device_get_name (device)); - int res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_106, NULL, &nt, 5000); - cut_assert_equal_int (0, res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device))); + res = nfc_initiator_select_dep_target (device, NDM_PASSIVE, NBR_106, NULL, &nt, 5000); + cut_assert_operator_int (res, >=, 0, 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_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")); @@ -183,7 +182,7 @@ initiator_thread (void *arg) // Passive mode / 212Kbps (second pass) 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); - cut_assert_equal_int (0, res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device))); + cut_assert_operator_int (res, >=, 0, 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")); @@ -205,7 +204,7 @@ initiator_thread (void *arg) // Passive mode / 212Kbps 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); - cut_assert_equal_int (0, res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device))); + cut_assert_operator_int (res, >=, 0, 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")); @@ -227,7 +226,7 @@ initiator_thread (void *arg) // Passive mode / 424Kbps 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); - cut_assert_equal_int (0, res, cut_message ("Can't select any DEP target: %s", nfc_strerror (device))); + cut_assert_operator_int (res, >=, 0, 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"));