From 9a7ffc38a157f9fcd512f503d999ca742180a8b9 Mon Sep 17 00:00:00 2001 From: Emanuele Bertoldi Date: Mon, 26 Jul 2010 08:55:43 +0000 Subject: [PATCH] Small improvements to nfc-sam stuff. --- examples/nfc-sam.1 | 2 ++ examples/nfc-sam.c | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/examples/nfc-sam.1 b/examples/nfc-sam.1 index 45d3350..c2de2c4 100644 --- a/examples/nfc-sam.1 +++ b/examples/nfc-sam.1 @@ -7,6 +7,8 @@ nfc-sam \- NFC SAM comunication command line tool based on libnfc .B nfc-sam utility attempts to test a simple connection with a SAM (Secure Access Module) in several modes. +To run this utility you must have a SAM (like the NXP's P5CN072 chip) successfully connected to your NFC chip. + .SH BUGS Please report any bugs on the .B libnfc diff --git a/examples/nfc-sam.c b/examples/nfc-sam.c index a94f003..7290596 100644 --- a/examples/nfc-sam.c +++ b/examples/nfc-sam.c @@ -56,7 +56,12 @@ bool sam_connection(nfc_device_t* pnd, int mode) int size = sizeof(pncmd_sam_config)-((mode == VIRTUAL_CARD_MODE) ? 0 : 1); pncmd_sam_config[2] = mode; - return pnd->pdc->transceive(pnd->nds,pncmd_sam_config,size,abtRx,&szRxLen); + if (!pnd->pdc->transceive(pnd->nds,pncmd_sam_config,size,abtRx,&szRxLen)) { + ERR("%s %d", "Unable to execute SAMConfiguration command with mode byte:", mode); + return false; + } + + return true; } void wait_one_minute() @@ -91,8 +96,8 @@ int main(int argc, const char* argv[]) pnd = nfc_connect(NULL); if (pnd == NULL) { - ERR("%s", "Unable to connect to NFC device."); - return EXIT_FAILURE; + ERR("%s", "Unable to connect to NFC device."); + return EXIT_FAILURE; } printf("Connected to NFC reader: %s\n",pnd->acName); @@ -109,8 +114,8 @@ int main(int argc, const char* argv[]) int mode = input-'0'+1; printf("\n"); if (mode < VIRTUAL_CARD_MODE || mode > DUAL_CARD_MODE) { - ERR("%s", "Invalid selection."); - return EXIT_FAILURE; + ERR("%s", "Invalid selection."); + return EXIT_FAILURE; } // Connect with the SAM @@ -162,17 +167,18 @@ int main(int argc, const char* argv[]) byte_t abtRx[MAX_FRAME_LEN]; size_t szRxLen; - // FIXME: it does not work as expected... + // FIXME: it does not work as expected...Probably the issue is in "nfc_target_init" + // which doesn't provide a way to set custom data for SENS_RES, NFCID1, SEL_RES, etc. if (!nfc_target_init(pnd,abtRx,&szRxLen)) return EXIT_FAILURE; - + printf("Now both the NFC reader and SAM are readable for 1 minute from an external reader.\n"); wait_one_minute(); } break; } - // Disconnect from the SAM. + // Disconnect from the SAM sam_connection(pnd, NORMAL_MODE); // Disconnect from NFC device