From 8d27768097d7731b7d9fa1188dd198f126c6b5e8 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Wed, 9 Mar 2011 13:31:12 +0000 Subject: [PATCH] Implement abort in the nfc-emulate-forum-tag4 example. --- examples/nfc-emulate-forum-tag4.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/examples/nfc-emulate-forum-tag4.c b/examples/nfc-emulate-forum-tag4.c index e8368da..b64f57b 100644 --- a/examples/nfc-emulate-forum-tag4.c +++ b/examples/nfc-emulate-forum-tag4.c @@ -54,6 +54,7 @@ # include "config.h" #endif // HAVE_CONFIG_H +#include #include #include #include @@ -73,6 +74,15 @@ static bool quiet_output = false; #define SYMBOL_PARAM_fISO14443_4_PICC 0x20 +void stop_emulation (int sig) +{ + (void) sig; + if (pnd) + nfc_abort_command (pnd); + else + exit (EXIT_FAILURE); +} + bool send_bytes (const byte_t * pbtTx, const size_t szTx) { // Show transmitted command @@ -117,6 +127,8 @@ main (void) return EXIT_FAILURE; } + signal (SIGINT, stop_emulation); + printf ("Connected to NFC device: %s\n", pnd->acName); printf ("Emulating NDEF tag now, please touch it with a second NFC device\n"); @@ -129,14 +141,19 @@ main (void) .nai = { .abtAtqa = { 0x00, 0x04 }, .abtUid = { 0x08, 0x00, 0xb0, 0x0b }, - .btSak = 0x20, .szUidLen = 4, - .szAtsLen = 0, + .btSak = 0x20, + .abtAts = { 0x75, 0x33, 0x92, 0x03 }, /* Not used by PN532 */ + .szAtsLen = 4, }, }, }; + print_nfc_iso14443a_info (nt.nti.nai, true); if (!nfc_target_init (pnd, &nt, abtRx, &szRx)) { + if (pnd->iLastError == DEABORT) { + errx (EXIT_SUCCESS, "Operation canceld by keystroke."); + } nfc_perror (pnd, "nfc_target_init"); ERR("Could not come out of auto-emulation, no command was received"); return EXIT_FAILURE;