less structs and defines publicly exposed
- nfc_device is now an opaque type; - PN53x specific errors are not public anymore; - nfc_device_name() renamed to nfc_device_get_name() for the sake of consistency; - examples/*, utils/* uses the new nfc_device_get_name() function instead of access directly to struct's content; - new error defined: NFC_ERFTRANS for notifying about RF transmission error, its used by mifare.c to detect permissions error on mifare; - drivers initiator_transceive_bytes() function now returns libnfc's error code on failure (<0), and received bytes count on success (>=0); - remove some unused errors.
This commit is contained in:
parent
9bdc20353c
commit
bf7c36d9bb
29 changed files with 162 additions and 178 deletions
|
|
@ -94,28 +94,32 @@ nfc_initiator_mifare_cmd (nfc_device *pnd, const mifare_cmd mc, const uint8_t ui
|
|||
if (szParamLen)
|
||||
memcpy (abtCmd + 2, (uint8_t *) pmp, szParamLen);
|
||||
|
||||
bEasyFraming = pnd->bEasyFraming;
|
||||
// FIXME: Save and restore bEasyFraming
|
||||
// bEasyFraming = nfc_device_get_property_bool (pnd, NP_EASY_FRAMING, &bEasyFraming);
|
||||
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, true) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
return false;
|
||||
}
|
||||
// Fire the mifare command
|
||||
if (!nfc_initiator_transceive_bytes (pnd, abtCmd, 2 + szParamLen, abtRx, &szRx, 0)) {
|
||||
if (pnd->iLastError == EINVRXFRAM) {
|
||||
// "Invalid received frame" AKA EINVRXFRAM, usual means we are
|
||||
int res;
|
||||
if ((res = nfc_initiator_transceive_bytes (pnd, abtCmd, 2 + szParamLen, abtRx, &szRx, -1)) < 0) {
|
||||
if (res == NFC_ERFTRANS) {
|
||||
// "Invalid received frame", usual means we are
|
||||
// authenticated on a sector but the requested MIFARE cmd (read, write)
|
||||
// is not permitted by current acces bytes;
|
||||
// So there is nothing to do here.
|
||||
} else {
|
||||
nfc_perror (pnd, "nfc_initiator_transceive_bytes");
|
||||
}
|
||||
nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, bEasyFraming);
|
||||
// XXX nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, bEasyFraming);
|
||||
return false;
|
||||
}
|
||||
/* XXX
|
||||
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, bEasyFraming) < 0) {
|
||||
nfc_perror (pnd, "nfc_device_set_property_bool");
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
// When we have executed a read command, copy the received bytes into the param
|
||||
if (mc == MC_READ) {
|
||||
|
|
|
|||
|
|
@ -356,7 +356,7 @@ main (int argc, char *argv[])
|
|||
|
||||
signal (SIGINT, stop_emulation);
|
||||
|
||||
printf ("Connected to NFC device: %s\n", pnd->acName);
|
||||
printf ("Connected to NFC device: %s\n", nfc_device_get_name(pnd));
|
||||
printf ("Emulating NDEF tag now, please touch it with a second NFC device\n");
|
||||
|
||||
if (0 != nfc_emulate_target (pnd, &emulator)) { // contains already nfc_target_init() call
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ main (int argc, const char *argv[])
|
|||
}
|
||||
nfc_initiator_init (pnd);
|
||||
|
||||
printf ("Connected to NFC device: %s\n", pnd->acName);
|
||||
printf ("Connected to NFC device: %s\n", nfc_device_get_name (pnd));
|
||||
|
||||
nfc_modulation nm;
|
||||
|
||||
|
|
|
|||
|
|
@ -554,7 +554,7 @@ main (int argc, const char *argv[])
|
|||
// Disable ISO14443-4 switching in order to read devices that emulate Mifare Classic with ISO14443-4 compliance.
|
||||
nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, false);
|
||||
|
||||
printf ("Connected to NFC reader: %s\n", pnd->acName);
|
||||
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)) {
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ main (int argc, char *argv[])
|
|||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf ("Connected to NFC reader: %s\n\n", pnd->acName);
|
||||
printf ("Connected to NFC reader: %s\n", nfc_device_get_name (pnd));
|
||||
|
||||
// Send the 7 bits request command specified in ISO 14443A (0x26)
|
||||
if (!transmit_bits (abtReqa, 7)) {
|
||||
|
|
|
|||
|
|
@ -219,7 +219,7 @@ main (int argc, const char *argv[])
|
|||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf ("Connected to NFC device: %s\n", pnd->acName);
|
||||
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)) {
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ main(int argc, char *argv[])
|
|||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
fprintf (message_stream, "Connected to NFC device: %s\n", pnd->acName);
|
||||
fprintf (message_stream, "Connected to NFC device: %s\n", nfc_device_get_name (pnd));
|
||||
|
||||
nfc_modulation nm = {
|
||||
.nmt = NMT_FELICA,
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ main (int argc, char *argv[])
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf ("Connected to the NFC reader device: %s\n", pndInitiator->acName);
|
||||
printf ("Connected to the NFC reader device: %s\n", nfc_device_get_name (pndInitiator));
|
||||
|
||||
if (nfc_initiator_init (pndInitiator) < 0) {
|
||||
printf ("Error: fail initializing initiator\n");
|
||||
|
|
@ -352,7 +352,7 @@ main (int argc, char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf ("Connected to the NFC emulator device: %s\n", pndTarget->acName);
|
||||
printf ("Connected to the NFC emulator device: %s\n", nfc_device_get_name (pndTarget));
|
||||
|
||||
if (!nfc_target_init (pndTarget, &ntEmulatedTarget, abtCapdu, &szCapduLen)) {
|
||||
ERR ("%s", "Initialization of NFC emulator failed");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue