rename nfc_disconnect() function to nfc_close().

This commit is contained in:
Audrey Diacre 2012-01-17 14:52:39 +00:00
parent 9d3ca39a44
commit 9eb37b3eee
35 changed files with 80 additions and 80 deletions

View file

@ -52,6 +52,6 @@ main (int argc, const char *argv[])
} }
} }
// Disconnect from NFC device // Disconnect from NFC device
nfc_disconnect (pnd); nfc_close (pnd);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -183,7 +183,7 @@ main (int argc, char *argv[])
// Send the 7 bits request command specified in ISO 14443A (0x26) // Send the 7 bits request command specified in ISO 14443A (0x26)
if (!transmit_bits (abtReqa, 7)) { if (!transmit_bits (abtReqa, 7)) {
printf ("Error: No tag available\n"); printf ("Error: No tag available\n");
nfc_disconnect (pnd); nfc_close (pnd);
return 1; return 1;
} }
memcpy (abtAtqa, abtRx, 2); memcpy (abtAtqa, abtRx, 2);
@ -312,6 +312,6 @@ main (int argc, char *argv[])
print_hex (abtAts, szAts); print_hex (abtAts, szAts);
} }
nfc_disconnect (pnd); nfc_close (pnd);
return 0; return 0;
} }

View file

@ -107,6 +107,6 @@ main (int argc, const char *argv[])
} }
error: error:
nfc_disconnect (pnd); nfc_close (pnd);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -139,6 +139,6 @@ main (int argc, const char *argv[])
printf("Data sent.\n"); printf("Data sent.\n");
error: error:
nfc_disconnect (pnd); nfc_close (pnd);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -196,13 +196,13 @@ main(int argc, char *argv[])
goto error; goto error;
} }
nfc_disconnect(pnd); nfc_close(pnd);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
error: error:
if (pnd) { if (pnd) {
nfc_perror (pnd, argv[0]); nfc_perror (pnd, argv[0]);
nfc_disconnect (pnd); nfc_close (pnd);
} }
} }

View file

@ -65,7 +65,7 @@ intr_hdlr (void)
{ {
printf ("\nQuitting...\n"); printf ("\nQuitting...\n");
if (pnd != NULL) { if (pnd != NULL) {
nfc_disconnect(pnd); nfc_close(pnd);
} }
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -265,7 +265,7 @@ main (int argc, char *argv[])
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
nfc_disconnect(pnd); nfc_close(pnd);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }

View file

@ -216,10 +216,10 @@ main (int argc, char *argv[])
} }
} }
} }
nfc_disconnect (pnd); nfc_close (pnd);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
error: error:
nfc_disconnect (pnd); nfc_close (pnd);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }

View file

@ -119,7 +119,7 @@ main (int argc, const char *argv[])
printf ("NFC device will poll during %ld ms (%u pollings of %lu ms for %zd modulations)\n", (unsigned long) uiPollNr * szModulations * uiPeriod * 150, uiPollNr, (unsigned long) uiPeriod * 150, szModulations); printf ("NFC device will poll during %ld ms (%u pollings of %lu ms for %zd modulations)\n", (unsigned long) uiPollNr * szModulations * uiPeriod * 150, uiPollNr, (unsigned long) uiPeriod * 150, szModulations);
if ((res = nfc_initiator_poll_target (pnd, nmModulations, szModulations, uiPollNr, uiPeriod, &nt)) < 0) { if ((res = nfc_initiator_poll_target (pnd, nmModulations, szModulations, uiPollNr, uiPeriod, &nt)) < 0) {
nfc_perror (pnd, "nfc_initiator_poll_target"); nfc_perror (pnd, "nfc_initiator_poll_target");
nfc_disconnect (pnd); nfc_close (pnd);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -128,6 +128,6 @@ main (int argc, const char *argv[])
} else { } else {
printf ("No target found.\n"); printf ("No target found.\n");
} }
nfc_disconnect (pnd); nfc_close (pnd);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }

View file

@ -147,7 +147,7 @@ main (int argc, char *argv[])
if ((szReaderRxBits = nfc_target_init (pndTag, &nt, abtReaderRx, sizeof (abtReaderRx), 0)) < 0) { if ((szReaderRxBits = nfc_target_init (pndTag, &nt, abtReaderRx, sizeof (abtReaderRx), 0)) < 0) {
ERR ("%s", "Initialization of NFC emulator failed"); ERR ("%s", "Initialization of NFC emulator failed");
nfc_disconnect (pndTag); nfc_close (pndTag);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
printf ("%s", "Configuring emulator settings..."); printf ("%s", "Configuring emulator settings...");
@ -215,7 +215,7 @@ main (int argc, char *argv[])
} }
} }
nfc_disconnect (pndTag); nfc_close (pndTag);
nfc_disconnect (pndReader); nfc_close (pndReader);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }

View file

@ -190,7 +190,7 @@ main (int argc, const char *argv[])
pn53x_SAMConfiguration (pnd, PSM_NORMAL, 0); pn53x_SAMConfiguration (pnd, PSM_NORMAL, 0);
// Disconnect from NFC device // Disconnect from NFC device
nfc_disconnect (pnd); nfc_close (pnd);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }

View file

@ -197,6 +197,6 @@ int main(int argc, const char* argv[])
if (input != NULL) { if (input != NULL) {
fclose(input); fclose(input);
} }
nfc_disconnect(pnd); nfc_close(pnd);
return 1; return 1;
} }

View file

@ -65,7 +65,7 @@ extern "C" {
/* NFC Device/Hardware manipulation */ /* NFC Device/Hardware manipulation */
NFC_EXPORT bool nfc_get_default_device (nfc_connstring *connstring); NFC_EXPORT bool nfc_get_default_device (nfc_connstring *connstring);
NFC_EXPORT nfc_device *nfc_connect (const nfc_connstring connstring); NFC_EXPORT nfc_device *nfc_connect (const nfc_connstring connstring);
NFC_EXPORT void nfc_disconnect (nfc_device *pnd); NFC_EXPORT void nfc_close (nfc_device *pnd);
NFC_EXPORT int nfc_abort_command (nfc_device *pnd); NFC_EXPORT int nfc_abort_command (nfc_device *pnd);
NFC_EXPORT size_t nfc_list_devices (nfc_connstring connstrings[], size_t connstrings_len); NFC_EXPORT size_t nfc_list_devices (nfc_connstring connstrings[], size_t connstrings_len);
NFC_EXPORT int nfc_idle (nfc_device *pnd); NFC_EXPORT int nfc_idle (nfc_device *pnd);

View file

@ -301,7 +301,7 @@ error:
} }
void void
acr122_disconnect (nfc_device *pnd) acr122_close (nfc_device *pnd)
{ {
SCardDisconnect (DRIVER_DATA (pnd)->hCard, SCARD_LEAVE_CARD); SCardDisconnect (DRIVER_DATA (pnd)->hCard, SCARD_LEAVE_CARD);
acr122_free_scardcontext (); acr122_free_scardcontext ();
@ -467,7 +467,7 @@ const struct nfc_driver acr122_driver = {
.name = ACR122_DRIVER_NAME, .name = ACR122_DRIVER_NAME,
.probe = acr122_probe, .probe = acr122_probe,
.connect = acr122_connect, .connect = acr122_connect,
.disconnect = acr122_disconnect, .close = acr122_close,
.strerror = pn53x_strerror, .strerror = pn53x_strerror,
.initiator_init = pn53x_initiator_init, .initiator_init = pn53x_initiator_init,

View file

@ -32,7 +32,7 @@ bool acr122_probe (nfc_connstring connstrings[], size_t connstrings_len, size
nfc_device *acr122_connect (const nfc_connstring connstring); nfc_device *acr122_connect (const nfc_connstring connstring);
int acr122_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout); int acr122_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
int acr122_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout); int acr122_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
void acr122_disconnect (nfc_device *pnd); void acr122_close (nfc_device *pnd);
extern const struct nfc_driver acr122_driver; extern const struct nfc_driver acr122_driver;

View file

@ -270,7 +270,7 @@ arygon_connect (const nfc_connstring connstring)
// Check communication using "Reset TAMA" command // Check communication using "Reset TAMA" command
if (arygon_reset_tama(pnd) < 0) { if (arygon_reset_tama(pnd) < 0) {
arygon_disconnect (pnd); arygon_close (pnd);
return NULL; return NULL;
} }
@ -286,7 +286,7 @@ arygon_connect (const nfc_connstring connstring)
} }
void void
arygon_disconnect (nfc_device *pnd) arygon_close (nfc_device *pnd)
{ {
// Release UART port // Release UART port
uart_close (DRIVER_DATA (pnd)->port); uart_close (DRIVER_DATA (pnd)->port);
@ -561,7 +561,7 @@ const struct nfc_driver arygon_driver = {
.name = ARYGON_DRIVER_NAME, .name = ARYGON_DRIVER_NAME,
.probe = arygon_probe, .probe = arygon_probe,
.connect = arygon_connect, .connect = arygon_connect,
.disconnect = arygon_disconnect, .close = arygon_close,
.strerror = pn53x_strerror, .strerror = pn53x_strerror,
.initiator_init = pn53x_initiator_init, .initiator_init = pn53x_initiator_init,

View file

@ -33,7 +33,7 @@
bool arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound); bool arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
nfc_device *arygon_connect (const nfc_connstring connstring); nfc_device *arygon_connect (const nfc_connstring connstring);
void arygon_disconnect (nfc_device *pnd); void arygon_close (nfc_device *pnd);
int arygon_tama_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout); int arygon_tama_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
int arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDat, int timeouta); int arygon_tama_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szDat, int timeouta);

View file

@ -250,7 +250,7 @@ pn532_uart_connect (const nfc_connstring connstring)
// Check communication using "Diagnose" command, with "Communication test" (0x00) // Check communication using "Diagnose" command, with "Communication test" (0x00)
if (pn53x_check_communication (pnd) < 0) { if (pn53x_check_communication (pnd) < 0) {
nfc_perror (pnd, "pn53x_check_communication"); nfc_perror (pnd, "pn53x_check_communication");
pn532_uart_disconnect (pnd); pn532_uart_close (pnd);
return NULL; return NULL;
} }
@ -259,7 +259,7 @@ pn532_uart_connect (const nfc_connstring connstring)
} }
void void
pn532_uart_disconnect (nfc_device *pnd) pn532_uart_close (nfc_device *pnd)
{ {
// Release UART port // Release UART port
uart_close (DRIVER_DATA(pnd)->port); uart_close (DRIVER_DATA(pnd)->port);
@ -504,7 +504,7 @@ const struct nfc_driver pn532_uart_driver = {
.name = PN532_UART_DRIVER_NAME, .name = PN532_UART_DRIVER_NAME,
.probe = pn532_uart_probe, .probe = pn532_uart_probe,
.connect = pn532_uart_connect, .connect = pn532_uart_connect,
.disconnect = pn532_uart_disconnect, .close = pn532_uart_close,
.strerror = pn53x_strerror, .strerror = pn53x_strerror,
.initiator_init = pn53x_initiator_init, .initiator_init = pn53x_initiator_init,

View file

@ -32,7 +32,7 @@
bool pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound); bool pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound);
nfc_device *pn532_uart_connect (const nfc_connstring connstring); nfc_device *pn532_uart_connect (const nfc_connstring connstring);
void pn532_uart_disconnect (nfc_device *pnd); void pn532_uart_close (nfc_device *pnd);
int pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout); int pn532_uart_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
int pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout); int pn532_uart_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);

View file

@ -479,7 +479,7 @@ error:
} }
void void
pn53x_usb_disconnect (nfc_device *pnd) pn53x_usb_close (nfc_device *pnd)
{ {
pn53x_usb_ack (pnd); pn53x_usb_ack (pnd);
@ -794,7 +794,7 @@ const struct nfc_driver pn53x_usb_driver = {
.name = PN53X_USB_DRIVER_NAME, .name = PN53X_USB_DRIVER_NAME,
.probe = pn53x_usb_probe, .probe = pn53x_usb_probe,
.connect = pn53x_usb_connect, .connect = pn53x_usb_connect,
.disconnect = pn53x_usb_disconnect, .close = pn53x_usb_close,
.strerror = pn53x_strerror, .strerror = pn53x_strerror,
.initiator_init = pn53x_initiator_init, .initiator_init = pn53x_initiator_init,

View file

@ -33,7 +33,7 @@ bool pn53x_usb_probe (nfc_connstring connstrings[], size_t connstrings_len, s
nfc_device *pn53x_usb_connect (const nfc_connstring connstring); nfc_device *pn53x_usb_connect (const nfc_connstring connstring);
int pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout); int pn53x_usb_send (nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout);
int pn53x_usb_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout); int pn53x_usb_receive (nfc_device *pnd, uint8_t *pbtData, const size_t szData, int timeout);
void pn53x_usb_disconnect (nfc_device *pnd); void pn53x_usb_close (nfc_device *pnd);
extern const struct nfc_driver pn53x_usb_driver; extern const struct nfc_driver pn53x_usb_driver;

View file

@ -129,7 +129,7 @@ struct nfc_driver {
const char *name; const char *name;
bool (*probe)(nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound); bool (*probe)(nfc_connstring connstrings[], size_t connstrings_len, size_t * pszDeviceFound);
struct nfc_device *(*connect) (const nfc_connstring connstring); struct nfc_device *(*connect) (const nfc_connstring connstring);
void (*disconnect) (struct nfc_device *pnd); void (*close) (struct nfc_device *pnd);
const char *(*strerror) (const struct nfc_device *pnd); const char *(*strerror) (const struct nfc_device *pnd);
int (*initiator_init) (struct nfc_device *pnd); int (*initiator_init) (struct nfc_device *pnd);

View file

@ -156,19 +156,19 @@ nfc_connect (const nfc_connstring connstring)
} }
/** /**
* @brief Disconnect from a NFC device * @brief Close from a NFC device
* @param pnd \a nfc_device struct pointer that represent currently used device * @param pnd \a nfc_device struct pointer that represent currently used device
* *
* Initiator's selected tag is disconnected and the device, including allocated \a nfc_device struct, is released. * Initiator's selected tag is closed and the device, including allocated \a nfc_device struct, is released.
*/ */
void void
nfc_disconnect (nfc_device *pnd) nfc_close (nfc_device *pnd)
{ {
if (pnd) { if (pnd) {
// Go in idle mode // Go in idle mode
nfc_idle (pnd); nfc_idle (pnd);
// Disconnect, clean up and release the device // Disconnect, clean up and release the device
pnd->driver->disconnect (pnd); pnd->driver->close (pnd);
log_fini (); log_fini ();
} }

View file

@ -44,7 +44,7 @@ test_access_storm (void)
res = nfc_initiator_list_passive_targets(device, nm, ant, MAX_TARGET_COUNT); res = nfc_initiator_list_passive_targets(device, nm, ant, MAX_TARGET_COUNT);
cut_assert_operator_int (res, >=, 0, cut_message ("nfc_initiator_list_passive_targets")); cut_assert_operator_int (res, >=, 0, cut_message ("nfc_initiator_list_passive_targets"));
nfc_disconnect (device); nfc_close (device);
} }
n--; n--;

View file

@ -41,8 +41,8 @@ cut_setup (void)
void void
cut_teardown (void) cut_teardown (void)
{ {
nfc_disconnect (devices[TARGET]); nfc_close (devices[TARGET]);
nfc_disconnect (devices[INITIATOR]); nfc_close (devices[INITIATOR]);
} }
struct thread_data { struct thread_data {

View file

@ -40,8 +40,8 @@ cut_setup (void)
void void
cut_teardown (void) cut_teardown (void)
{ {
nfc_disconnect (devices[TARGET]); nfc_close (devices[TARGET]);
nfc_disconnect (devices[INITIATOR]); nfc_close (devices[INITIATOR]);
} }
struct thread_data { struct thread_data {

View file

@ -38,8 +38,8 @@ cut_setup (void)
void void
cut_teardown (void) cut_teardown (void)
{ {
nfc_disconnect (second_device); nfc_close (second_device);
nfc_disconnect (first_device); nfc_close (first_device);
} }
struct thread_data { struct thread_data {

View file

@ -41,5 +41,5 @@ test_register_endianness (void)
cut_assert_equal_int (0, res, cut_message ("read register value")); cut_assert_equal_int (0, res, cut_message ("read register value"));
cut_assert_equal_uint (0x55, value, cut_message ("check register value")); cut_assert_equal_uint (0x55, value, cut_message ("check register value"));
nfc_disconnect (device); nfc_close (device);
} }

View file

@ -32,5 +32,5 @@ test_register_endianness (void)
res = pn53x_read_register (device, 0xFFF0, &value); res = pn53x_read_register (device, 0xFFF0, &value);
cut_assert_equal_int (0, res, cut_message ("read register 0xFFF0")); cut_assert_equal_int (0, res, cut_message ("read register 0xFFF0"));
nfc_disconnect (device); nfc_close (device);
} }

View file

@ -363,7 +363,7 @@ main (int argc, char *argv[])
nfc_perror (pnd, "nfc_emulate_target"); nfc_perror (pnd, "nfc_emulate_target");
} }
nfc_disconnect(pnd); nfc_close(pnd);
if (argc == 3) { if (argc == 3) {
if (!(ndef_message_save (argv[2], &nfcforum_tag4_data))) { if (!(ndef_message_save (argv[2], &nfcforum_tag4_data))) {

View file

@ -247,7 +247,7 @@ main (int argc, const char *argv[])
printf("\n"); printf("\n");
} }
} }
nfc_disconnect (pnd); nfc_close (pnd);
} }
return 0; return 0;

View file

@ -562,7 +562,7 @@ main (int argc, const char *argv[])
// Try to find a MIFARE Classic tag // Try to find a MIFARE Classic tag
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) { if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) {
printf ("Error: no tag was found\n"); printf ("Error: no tag was found\n");
nfc_disconnect (pnd); nfc_close (pnd);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
// Test if we are dealing with a MIFARE compatible tag // Test if we are dealing with a MIFARE compatible tag
@ -618,7 +618,7 @@ main (int argc, const char *argv[])
write_card (unlock); write_card (unlock);
} }
nfc_disconnect (pnd); nfc_close (pnd);
break; break;
case ACTION_EXTRACT:{ case ACTION_EXTRACT:{

View file

@ -212,7 +212,7 @@ main (int argc, char *argv[])
// Send the 7 bits request command specified in ISO 14443A (0x26) // Send the 7 bits request command specified in ISO 14443A (0x26)
if (!transmit_bits (abtReqa, 7)) { if (!transmit_bits (abtReqa, 7)) {
printf ("Error: No tag available\n"); printf ("Error: No tag available\n");
nfc_disconnect (pnd); nfc_close (pnd);
return 1; return 1;
} }
memcpy (abtAtqa, abtRx, 2); memcpy (abtAtqa, abtRx, 2);
@ -350,6 +350,6 @@ main (int argc, char *argv[])
} }
nfc_disconnect (pnd); nfc_close (pnd);
return 0; return 0;
} }

View file

@ -227,14 +227,14 @@ main (int argc, const char *argv[])
// Try to find a MIFARE Ultralight tag // Try to find a MIFARE Ultralight tag
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) { if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) {
ERR ("no tag was found\n"); ERR ("no tag was found\n");
nfc_disconnect (pnd); nfc_close (pnd);
return 1; return 1;
} }
// Test if we are dealing with a MIFARE compatible tag // Test if we are dealing with a MIFARE compatible tag
if (nt.nti.nai.abtAtqa[1] != 0x44) { if (nt.nti.nai.abtAtqa[1] != 0x44) {
ERR ("tag is not a MIFARE Ultralight card\n"); ERR ("tag is not a MIFARE Ultralight card\n");
nfc_disconnect (pnd); nfc_close (pnd);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// Get the info from the current tag // Get the info from the current tag
@ -265,7 +265,7 @@ main (int argc, const char *argv[])
write_card (); write_card ();
} }
nfc_disconnect (pnd); nfc_close (pnd);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -313,7 +313,7 @@ main(int argc, char *argv[])
error: error:
fclose (ndef_stream); fclose (ndef_stream);
if (pnd) { if (pnd) {
nfc_disconnect (pnd); nfc_close (pnd);
} }
exit (error); exit (error);
} }

View file

@ -230,7 +230,7 @@ main (int argc, char *argv[])
if (nfc_initiator_init (pndInitiator) < 0) { if (nfc_initiator_init (pndInitiator) < 0) {
printf ("Error: fail initializing initiator\n"); printf ("Error: fail initializing initiator\n");
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -241,7 +241,7 @@ main (int argc, char *argv[])
}; };
if (nfc_initiator_select_passive_target (pndInitiator, nm, NULL, 0, &ntRealTarget) < 0) { if (nfc_initiator_select_passive_target (pndInitiator, nm, NULL, 0, &ntRealTarget) < 0) {
printf ("Error: no tag was found\n"); printf ("Error: no tag was found\n");
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -250,22 +250,22 @@ main (int argc, char *argv[])
if (initiator_only_mode) { if (initiator_only_mode) {
if (print_hex_fd4(ntRealTarget.nti.nai.abtUid, ntRealTarget.nti.nai.szUidLen, "UID") != EXIT_SUCCESS) { if (print_hex_fd4(ntRealTarget.nti.nai.abtUid, ntRealTarget.nti.nai.szUidLen, "UID") != EXIT_SUCCESS) {
fprintf (stderr, "Error while printing UID to FD4\n"); fprintf (stderr, "Error while printing UID to FD4\n");
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (print_hex_fd4(ntRealTarget.nti.nai.abtAtqa, 2, "ATQA") != EXIT_SUCCESS) { if (print_hex_fd4(ntRealTarget.nti.nai.abtAtqa, 2, "ATQA") != EXIT_SUCCESS) {
fprintf (stderr, "Error while printing ATQA to FD4\n"); fprintf (stderr, "Error while printing ATQA to FD4\n");
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (print_hex_fd4(&(ntRealTarget.nti.nai.btSak), 1, "SAK") != EXIT_SUCCESS) { if (print_hex_fd4(&(ntRealTarget.nti.nai.btSak), 1, "SAK") != EXIT_SUCCESS) {
fprintf (stderr, "Error while printing SAK to FD4\n"); fprintf (stderr, "Error while printing SAK to FD4\n");
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (print_hex_fd4(ntRealTarget.nti.nai.abtAts, ntRealTarget.nti.nai.szAtsLen, "ATS") != EXIT_SUCCESS) { if (print_hex_fd4(ntRealTarget.nti.nai.abtAts, ntRealTarget.nti.nai.szAtsLen, "ATS") != EXIT_SUCCESS) {
fprintf (stderr, "Error while printing ATS to FD4\n"); fprintf (stderr, "Error while printing ATS to FD4\n");
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -288,22 +288,22 @@ main (int argc, char *argv[])
size_t foo; size_t foo;
if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtUid, &(ntEmulatedTarget.nti.nai.szUidLen), "UID") != EXIT_SUCCESS) { if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtUid, &(ntEmulatedTarget.nti.nai.szUidLen), "UID") != EXIT_SUCCESS) {
fprintf (stderr, "Error while scanning UID from FD3\n"); fprintf (stderr, "Error while scanning UID from FD3\n");
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAtqa, &foo, "ATQA") != EXIT_SUCCESS) { if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAtqa, &foo, "ATQA") != EXIT_SUCCESS) {
fprintf (stderr, "Error while scanning ATQA from FD3\n"); fprintf (stderr, "Error while scanning ATQA from FD3\n");
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (scan_hex_fd3(&(ntEmulatedTarget.nti.nai.btSak), &foo, "SAK") != EXIT_SUCCESS) { if (scan_hex_fd3(&(ntEmulatedTarget.nti.nai.btSak), &foo, "SAK") != EXIT_SUCCESS) {
fprintf (stderr, "Error while scanning SAK from FD3\n"); fprintf (stderr, "Error while scanning SAK from FD3\n");
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAts, &(ntEmulatedTarget.nti.nai.szAtsLen), "ATS") != EXIT_SUCCESS) { if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAts, &(ntEmulatedTarget.nti.nai.szAtsLen), "ATS") != EXIT_SUCCESS) {
fprintf (stderr, "Error while scanning ATS from FD3\n"); fprintf (stderr, "Error while scanning ATS from FD3\n");
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else { } else {
@ -346,7 +346,7 @@ main (int argc, char *argv[])
if (pndTarget == NULL) { if (pndTarget == NULL) {
printf ("Error connecting NFC emulator device\n"); printf ("Error connecting NFC emulator device\n");
if (!target_only_mode) { if (!target_only_mode) {
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
} }
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -357,9 +357,9 @@ main (int argc, char *argv[])
if (nfc_target_init (pndTarget, &ntEmulatedTarget, abtCapdu, szCapduLen, 0) < 0) { if (nfc_target_init (pndTarget, &ntEmulatedTarget, abtCapdu, szCapduLen, 0) < 0) {
ERR ("%s", "Initialization of NFC emulator failed"); ERR ("%s", "Initialization of NFC emulator failed");
if (!target_only_mode) { if (!target_only_mode) {
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
} }
nfc_disconnect (pndTarget); nfc_close (pndTarget);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
printf ("%s\n", "Done, relaying frames now!"); printf ("%s\n", "Done, relaying frames now!");
@ -374,23 +374,23 @@ main (int argc, char *argv[])
if ((res = nfc_target_receive_bytes(pndTarget, abtCapdu, sizeof (abtCapdu), 0)) < 0) { if ((res = nfc_target_receive_bytes(pndTarget, abtCapdu, sizeof (abtCapdu), 0)) < 0) {
nfc_perror (pndTarget, "nfc_target_receive_bytes"); nfc_perror (pndTarget, "nfc_target_receive_bytes");
if (!target_only_mode) { if (!target_only_mode) {
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
} }
nfc_disconnect (pndTarget); nfc_close (pndTarget);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
szCapduLen = (size_t) res; szCapduLen = (size_t) res;
if (target_only_mode) { if (target_only_mode) {
if (print_hex_fd4(abtCapdu, szCapduLen, "C-APDU") != EXIT_SUCCESS) { if (print_hex_fd4(abtCapdu, szCapduLen, "C-APDU") != EXIT_SUCCESS) {
fprintf (stderr, "Error while printing C-APDU to FD4\n"); fprintf (stderr, "Error while printing C-APDU to FD4\n");
nfc_disconnect (pndTarget); nfc_close (pndTarget);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
} else { } else {
if (scan_hex_fd3(abtCapdu, &szCapduLen, "C-APDU") != EXIT_SUCCESS) { if (scan_hex_fd3(abtCapdu, &szCapduLen, "C-APDU") != EXIT_SUCCESS) {
fprintf (stderr, "Error while scanning C-APDU from FD3\n"); fprintf (stderr, "Error while scanning C-APDU from FD3\n");
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -407,7 +407,7 @@ main (int argc, char *argv[])
} 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");
nfc_disconnect (pndTarget); nfc_close (pndTarget);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
ret = true; ret = true;
@ -430,17 +430,17 @@ main (int argc, char *argv[])
if (nfc_target_send_bytes(pndTarget, abtRapdu, szRapduLen, 0) < 0) { if (nfc_target_send_bytes(pndTarget, abtRapdu, szRapduLen, 0) < 0) {
nfc_perror (pndTarget, "nfc_target_send_bytes"); nfc_perror (pndTarget, "nfc_target_send_bytes");
if (!target_only_mode) { if (!target_only_mode) {
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
} }
if (!initiator_only_mode) { if (!initiator_only_mode) {
nfc_disconnect (pndTarget); nfc_close (pndTarget);
} }
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else { } else {
if (print_hex_fd4(abtRapdu, szRapduLen, "R-APDU") != EXIT_SUCCESS) { if (print_hex_fd4(abtRapdu, szRapduLen, "R-APDU") != EXIT_SUCCESS) {
fprintf (stderr, "Error while printing R-APDU to FD4\n"); fprintf (stderr, "Error while printing R-APDU to FD4\n");
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -448,10 +448,10 @@ main (int argc, char *argv[])
} }
if (!target_only_mode) { if (!target_only_mode) {
nfc_disconnect (pndInitiator); nfc_close (pndInitiator);
} }
if (!initiator_only_mode) { if (!initiator_only_mode) {
nfc_disconnect (pndTarget); nfc_close (pndTarget);
} }
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }