nfc_initiator_select_passive_target() function returns now libnfc error code.
This commit is contained in:
parent
ba2a7cfe2e
commit
103485518c
11 changed files with 42 additions and 41 deletions
|
@ -35,7 +35,7 @@ main (int argc, const char *argv[])
|
|||
.nmt = NMT_ISO14443A,
|
||||
.nbr = NBR_106,
|
||||
};
|
||||
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt)) {
|
||||
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) == 0) {
|
||||
printf ("The following (NFC) ISO14443A tag was found:\n");
|
||||
printf (" ATQA (SENS_RES): ");
|
||||
print_hex (nt.nti.nai.abtAtqa, 2);
|
||||
|
|
|
@ -140,7 +140,7 @@ main (int argc, const char *argv[])
|
|||
.nmt = NMT_ISO14443A,
|
||||
.nbr = NBR_106,
|
||||
};
|
||||
if (!nfc_initiator_select_passive_target (pnd, nmSAM, NULL, 0, &nt)) {
|
||||
if (nfc_initiator_select_passive_target (pnd, nmSAM, NULL, 0, &nt) < 0) {
|
||||
nfc_perror (pnd, "nfc_initiator_select_passive_target");
|
||||
ERR ("%s", "Reading of SAM info failed.");
|
||||
exit (EXIT_FAILURE);
|
||||
|
|
|
@ -72,7 +72,7 @@ extern "C" {
|
|||
|
||||
/* NFC initiator: act as "reader" */
|
||||
NFC_EXPORT int nfc_initiator_init (nfc_device *pnd);
|
||||
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 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 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, const int timeout);
|
||||
|
|
|
@ -907,7 +907,7 @@ pn53x_initiator_init (struct nfc_device *pnd)
|
|||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
bool
|
||||
int
|
||||
pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
|
||||
const nfc_modulation nm,
|
||||
const uint8_t *pbtInitData, const size_t szInitData,
|
||||
|
@ -916,22 +916,23 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
|
|||
{
|
||||
uint8_t abtTargetsData[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
|
||||
size_t szTargetsData = sizeof(abtTargetsData);
|
||||
int res = 0;
|
||||
|
||||
if (nm.nmt == NMT_ISO14443BI || nm.nmt == NMT_ISO14443B2SR || nm.nmt == NMT_ISO14443B2CT) {
|
||||
if (CHIP_DATA(pnd)->type == RCS360) {
|
||||
// TODO add support for RC-S360, at the moment it refuses to send raw frames without a first select
|
||||
pnd->last_error = NFC_ENOTIMPL;
|
||||
return false;
|
||||
return pnd->last_error;
|
||||
}
|
||||
// No native support in InListPassiveTarget so we do discovery by hand
|
||||
if (nfc_device_set_property_bool (pnd, NP_FORCE_ISO14443_B, true) < 0) {
|
||||
return false;
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_FORCE_ISO14443_B, true)) < 0) {
|
||||
return res;
|
||||
}
|
||||
if (nfc_device_set_property_bool (pnd, NP_FORCE_SPEED_106, true) < 0) {
|
||||
return false;
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_FORCE_SPEED_106, true)) < 0) {
|
||||
return res;
|
||||
}
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, true) < 0) {
|
||||
return false;
|
||||
if ((res = nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, true)) < 0) {
|
||||
return res;
|
||||
}
|
||||
pnd->bEasyFraming = false;
|
||||
if (nm.nmt == NMT_ISO14443B2SR) {
|
||||
|
@ -943,12 +944,12 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
|
|||
uint8_t abtRx[1];
|
||||
size_t szRxLen = 1;
|
||||
// Getting random Chip_ID
|
||||
if (pn53x_initiator_transceive_bytes (pnd, abtInitiate, szInitiateLen, abtRx, &szRxLen, timeout) < 0) {
|
||||
return false;
|
||||
if ((res = pn53x_initiator_transceive_bytes (pnd, abtInitiate, szInitiateLen, abtRx, &szRxLen, timeout)) < 0) {
|
||||
return res;
|
||||
}
|
||||
abtSelect[1] = abtRx[0];
|
||||
if (pn53x_initiator_transceive_bytes (pnd, abtSelect, szSelectLen, abtRx, &szRxLen, timeout) < 0) {
|
||||
return false;
|
||||
if ((res = pn53x_initiator_transceive_bytes (pnd, abtSelect, szSelectLen, abtRx, &szRxLen, timeout)) < 0) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
else if (nm.nmt == NMT_ISO14443B2CT) {
|
||||
|
@ -956,20 +957,20 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
|
|||
uint8_t abtReqt[]="\x10";
|
||||
size_t szReqtLen = 1;
|
||||
// Getting product code / fab code & store it in output buffer after the serial nr we'll obtain later
|
||||
if ((pn53x_initiator_transceive_bytes (pnd, abtReqt, szReqtLen, abtTargetsData+2, &szTargetsData, timeout) < 0) || szTargetsData != 2) {
|
||||
return false;
|
||||
if ((res = pn53x_initiator_transceive_bytes (pnd, abtReqt, szReqtLen, abtTargetsData+2, &szTargetsData, timeout)) < 0) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
if (pn53x_initiator_transceive_bytes (pnd, pbtInitData, szInitData, abtTargetsData, &szTargetsData, timeout) < 0) {
|
||||
return false;
|
||||
if ((res = pn53x_initiator_transceive_bytes (pnd, pbtInitData, szInitData, abtTargetsData, &szTargetsData, timeout)) < 0) {
|
||||
return res;
|
||||
}
|
||||
if (nm.nmt == NMT_ISO14443B2CT) {
|
||||
if (szTargetsData != 2)
|
||||
return false;
|
||||
return NFC_ECHIP;
|
||||
uint8_t abtRead[]="\xC4"; // Reading UID_MSB (Read address 4)
|
||||
size_t szReadLen = 1;
|
||||
if ((pn53x_initiator_transceive_bytes (pnd, abtRead, szReadLen, abtTargetsData+4, &szTargetsData, timeout) < 0) || szTargetsData != 2) {
|
||||
return false;
|
||||
if ((res = pn53x_initiator_transceive_bytes (pnd, abtRead, szReadLen, abtTargetsData+4, &szTargetsData, timeout) < 0)) {
|
||||
return res;
|
||||
}
|
||||
szTargetsData = 6; // u16 UID_LSB, u8 prod code, u8 fab code, u16 UID_MSB
|
||||
}
|
||||
|
@ -977,7 +978,7 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
|
|||
pnt->nm = nm;
|
||||
// Fill the tag info struct with the values corresponding to this init modulation
|
||||
if (!pn53x_decode_target_data (abtTargetsData, szTargetsData, CHIP_DATA(pnd)->type, nm.nmt, &(pnt->nti))) {
|
||||
return false;
|
||||
return NFC_ECHIP;
|
||||
}
|
||||
}
|
||||
if (nm.nmt == NMT_ISO14443BI) {
|
||||
|
@ -986,11 +987,11 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
|
|||
size_t szAttribLen = sizeof(abtAttrib);
|
||||
memcpy(abtAttrib, abtTargetsData, szAttribLen);
|
||||
abtAttrib[1] = 0x0f; // ATTRIB
|
||||
if (pn53x_initiator_transceive_bytes (pnd, abtAttrib, szAttribLen, NULL, NULL, timeout) < 0) {
|
||||
return false;
|
||||
if ((res = pn53x_initiator_transceive_bytes (pnd, abtAttrib, szAttribLen, NULL, NULL, timeout)) < 0) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return NFC_SUCCESS;
|
||||
} // else:
|
||||
|
||||
const pn53x_modulation pm = pn53x_nm_to_pm(nm);
|
||||
|
@ -1017,7 +1018,7 @@ pn53x_initiator_select_passive_target_ext (struct nfc_device *pnd,
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
int
|
||||
pn53x_initiator_select_passive_target (struct nfc_device *pnd,
|
||||
const nfc_modulation nm,
|
||||
const uint8_t *pbtInitData, const size_t szInitData,
|
||||
|
@ -1077,7 +1078,7 @@ pn53x_initiator_poll_target (struct nfc_device *pnd,
|
|||
prepare_initiator_data (pnmModulations[n], &pbtInitiatorData, &szInitiatorData);
|
||||
const int timeout_ms = uiPeriod * 150;
|
||||
|
||||
if (!pn53x_initiator_select_passive_target_ext (pnd, pnmModulations[n], pbtInitiatorData, szInitiatorData, pnt, timeout_ms)) {
|
||||
if (pn53x_initiator_select_passive_target_ext (pnd, pnmModulations[n], pbtInitiatorData, szInitiatorData, pnt, timeout_ms) < 0) {
|
||||
if (pnd->last_error != NFC_ETIMEOUT)
|
||||
return false;
|
||||
} else {
|
||||
|
|
|
@ -286,7 +286,7 @@ bool pn53x_idle (struct nfc_device *pnd);
|
|||
|
||||
// NFC device as Initiator functions
|
||||
int pn53x_initiator_init (struct nfc_device *pnd);
|
||||
bool pn53x_initiator_select_passive_target (struct nfc_device *pnd,
|
||||
int pn53x_initiator_select_passive_target (struct nfc_device *pnd,
|
||||
const nfc_modulation nm,
|
||||
const uint8_t *pbtInitData, const size_t szInitData,
|
||||
nfc_target *pnt);
|
||||
|
|
|
@ -133,7 +133,7 @@ struct nfc_driver_t {
|
|||
const char *(*strerror) (const struct nfc_device *pnd);
|
||||
|
||||
int (*initiator_init) (struct nfc_device *pnd);
|
||||
bool (*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);
|
||||
bool (*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);
|
||||
bool (*initiator_deselect_target) (struct nfc_device *pnd);
|
||||
|
|
|
@ -304,7 +304,7 @@ nfc_initiator_init (nfc_device *pnd)
|
|||
|
||||
/**
|
||||
* @brief Select a passive or emulated tag
|
||||
* @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 nm desired modulation
|
||||
|
@ -322,7 +322,7 @@ nfc_initiator_init (nfc_device *pnd)
|
|||
* The chip needs to know with what kind of tag it is dealing with, therefore
|
||||
* the initial modulation and speed (106, 212 or 424 kbps) should be supplied.
|
||||
*/
|
||||
bool
|
||||
int
|
||||
nfc_initiator_select_passive_target (nfc_device *pnd,
|
||||
const nfc_modulation nm,
|
||||
const uint8_t *pbtInitData, const size_t szInitData,
|
||||
|
@ -381,7 +381,7 @@ nfc_initiator_list_passive_targets (nfc_device *pnd,
|
|||
|
||||
prepare_initiator_data (nm, &pbtInitData, &szInitDataLen);
|
||||
|
||||
while (nfc_initiator_select_passive_target (pnd, nm, pbtInitData, szInitDataLen, &nt)) {
|
||||
while (nfc_initiator_select_passive_target (pnd, nm, pbtInitData, szInitDataLen, &nt) == 0) {
|
||||
nfc_initiator_deselect_target (pnd);
|
||||
if (szTargets == szTargetFound) {
|
||||
break;
|
||||
|
|
|
@ -280,7 +280,7 @@ read_card (int read_unlocked)
|
|||
// Show if the readout went well
|
||||
if (bFailure) {
|
||||
// When a failure occured we need to redo the anti-collision
|
||||
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt)) {
|
||||
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) {
|
||||
printf ("!\nError: tag was removed\n");
|
||||
return false;
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ write_card (int write_block_zero)
|
|||
// Show if the readout went well
|
||||
if (bFailure) {
|
||||
// When a failure occured we need to redo the anti-collision
|
||||
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt)) {
|
||||
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) {
|
||||
printf ("!\nError: tag was removed\n");
|
||||
return false;
|
||||
}
|
||||
|
@ -557,7 +557,7 @@ main (int argc, const char *argv[])
|
|||
printf ("Connected to NFC reader: %s\n", nfc_device_get_name (pnd));
|
||||
|
||||
// Try to find a MIFARE Classic tag
|
||||
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt)) {
|
||||
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) {
|
||||
printf ("Error: no tag was found\n");
|
||||
nfc_disconnect (pnd);
|
||||
exit (EXIT_FAILURE);
|
||||
|
|
|
@ -142,7 +142,7 @@ write_card (void)
|
|||
// Show if the readout went well
|
||||
if (bFailure) {
|
||||
// When a failure occured we need to redo the anti-collision
|
||||
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt)) {
|
||||
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) {
|
||||
ERR ("tag was removed");
|
||||
return false;
|
||||
}
|
||||
|
@ -222,7 +222,7 @@ main (int argc, const char *argv[])
|
|||
printf ("Connected to NFC device: %s\n", nfc_device_get_name (pnd));
|
||||
|
||||
// Try to find a MIFARE Ultralight tag
|
||||
if (!nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt)) {
|
||||
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) {
|
||||
ERR ("no tag was found\n");
|
||||
nfc_disconnect (pnd);
|
||||
return 1;
|
||||
|
|
|
@ -219,7 +219,7 @@ main(int argc, char *argv[])
|
|||
int error = EXIT_SUCCESS;
|
||||
// Polling payload (SENSF_REQ) must be present (see NFC Digital Protol)
|
||||
const uint8_t *pbtSensfReq = (uint8_t*)"\x00\xff\xff\x01\x00";
|
||||
if (!nfc_initiator_select_passive_target(pnd, nm, pbtSensfReq, 5, &nt)) {
|
||||
if (nfc_initiator_select_passive_target(pnd, nm, pbtSensfReq, 5, &nt) < 0) {
|
||||
nfc_perror (pnd, "nfc_initiator_select_passive_target");
|
||||
error = EXIT_FAILURE;
|
||||
goto error;
|
||||
|
@ -230,7 +230,7 @@ main(int argc, char *argv[])
|
|||
if (0 != memcmp (nt.nti.nfi.abtSysCode, abtNfcForumSysCode, 2)) {
|
||||
// Retry with special polling
|
||||
const uint8_t *pbtSensfReqNfcForum = (uint8_t*)"\x00\x12\xfc\x01\x00";
|
||||
if (!nfc_initiator_select_passive_target(pnd, nm, pbtSensfReqNfcForum, 5, &nt)) {
|
||||
if (nfc_initiator_select_passive_target(pnd, nm, pbtSensfReqNfcForum, 5, &nt) < 0) {
|
||||
nfc_perror (pnd, "nfc_initiator_select_passive_target");
|
||||
error = EXIT_FAILURE;
|
||||
goto error;
|
||||
|
|
|
@ -240,7 +240,7 @@ main (int argc, char *argv[])
|
|||
.nmt = NMT_ISO14443A,
|
||||
.nbr = NBR_106,
|
||||
};
|
||||
if (!nfc_initiator_select_passive_target (pndInitiator, nm, NULL, 0, &ntRealTarget)) {
|
||||
if (nfc_initiator_select_passive_target (pndInitiator, nm, NULL, 0, &ntRealTarget) < 0) {
|
||||
printf ("Error: no tag was found\n");
|
||||
nfc_disconnect (pndInitiator);
|
||||
exit (EXIT_FAILURE);
|
||||
|
|
Loading…
Add table
Reference in a new issue