From 1e9c390dfa5f01eb7cea6304991134a29e17f1f2 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Fri, 8 Oct 2010 20:25:34 +0000 Subject: [PATCH] Improve DEP info struct: add more info, and InJumpDEP now fill fully this struct. --- examples/Makefile.am | 6 ++++-- examples/nfc-utils.c | 15 +++++++++++++++ examples/nfc-utils.h | 1 + examples/nfcip-initiator.c | 15 ++++++++++----- include/nfc/nfc-types.h | 20 ++++++++++++++++---- libnfc/chips/pn53x.c | 16 ++++++++++++---- 6 files changed, 58 insertions(+), 15 deletions(-) diff --git a/examples/Makefile.am b/examples/Makefile.am index 8dc9abf..fede8fb 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -59,10 +59,12 @@ nfc_emulate_uid_LDADD = $(top_builddir)/libnfc/libnfc.la \ libnfcutils.la nfcip_target_SOURCES = nfcip-target.c -nfcip_target_LDADD = $(top_builddir)/libnfc/libnfc.la +nfcip_target_LDADD = $(top_builddir)/libnfc/libnfc.la \ + libnfcutils.la nfcip_initiator_SOURCES = nfcip-initiator.c -nfcip_initiator_LDADD = $(top_builddir)/libnfc/libnfc.la +nfcip_initiator_LDADD = $(top_builddir)/libnfc/libnfc.la \ + libnfcutils.la pn53x_diagnose_SOURCES = pn53x-diagnose.c pn53x_diagnose_LDADD = $(top_builddir)/libnfc/libnfc.la \ diff --git a/examples/nfc-utils.c b/examples/nfc-utils.c index b943002..166f978 100644 --- a/examples/nfc-utils.c +++ b/examples/nfc-utils.c @@ -197,6 +197,21 @@ print_nfc_iso14443b_info (const nfc_iso14443b_info_t nbi) } } +void +print_nfc_dep_info (const nfc_dep_info_t ndi) +{ + printf (" NFCID3: "); + print_hex (ndi.abtNFCID3, 10); + printf (" BS: %02x\n", ndi.btBS); + printf (" BR: %02x\n", ndi.btBR); + printf (" TO: %02x\n", ndi.btTO); + printf (" PP: %02x\n", ndi.btPP); + if (ndi.szGB) { + printf ("General Bytes: "); + print_hex (ndi.abtGB, ndi.szGB); + } +} + /** * @brief Tries to parse arguments to find device descriptions. * @return Returns the list of found device descriptions. diff --git a/examples/nfc-utils.h b/examples/nfc-utils.h index 7b7fe9f..46472f3 100644 --- a/examples/nfc-utils.h +++ b/examples/nfc-utils.h @@ -38,6 +38,7 @@ void print_nfc_iso14443a_info (const nfc_iso14443a_info_t nai); void print_nfc_iso14443b_info (const nfc_iso14443b_info_t nbi); void print_nfc_felica_info (const nfc_felica_info_t nfi); void print_nfc_jewel_info (const nfc_jewel_info_t nji); +void print_nfc_dep_info (const nfc_dep_info_t ndi); nfc_device_desc_t *parse_device_desc (int argc, const char *argv[], size_t * szFound); diff --git a/examples/nfcip-initiator.c b/examples/nfcip-initiator.c index 34e6773..d15a304 100644 --- a/examples/nfcip-initiator.c +++ b/examples/nfcip-initiator.c @@ -29,18 +29,21 @@ #include #include #include + #include +#include "nfc-utils.h" + #define MAX_FRAME_LEN 264 int main (int argc, const char *argv[]) { nfc_device_t *pnd; - nfc_target_info_t ti; + nfc_target_info_t nti; byte_t abtRx[MAX_FRAME_LEN]; size_t szRx; - byte_t send[] = "Hello World!"; + byte_t abtTx[] = "Hello World!"; if (argc > 1) { printf ("Usage: %s\n", argv[0]); @@ -58,13 +61,15 @@ main (int argc, const char *argv[]) return EXIT_FAILURE; } - if(!nfc_initiator_select_dep_target (pnd, NM_PASSIVE_DEP, NULL, 0, NULL, 0, NULL, 0, &ti)) { + if(!nfc_initiator_select_dep_target (pnd, NM_PASSIVE_DEP, NULL, 0, NULL, 0, NULL, 0, &nti)) { nfc_perror(pnd, "nfc_initiator_select_dep_target"); return EXIT_FAILURE; } + printf( "This D.E.P. target have been found:\n" ); + print_nfc_dep_info (nti.ndi); - printf ("Sending: %s\n", send); - if (!nfc_initiator_transceive_bytes (pnd, send, strlen ((char *) send), abtRx, &szRx)) { + printf ("Sending: %s\n", abtTx); + if (!nfc_initiator_transceive_bytes (pnd, abtTx, sizeof(abtTx), abtRx, &szRx)) { nfc_perror(pnd, "nfc_initiator_transceive_bytes"); return EXIT_FAILURE; } diff --git a/include/nfc/nfc-types.h b/include/nfc/nfc-types.h index 783117f..39cb7a3 100644 --- a/include/nfc/nfc-types.h +++ b/include/nfc/nfc-types.h @@ -2,6 +2,7 @@ * Public platform independent Near Field Communication (NFC) library * * Copyright (C) 2009, Roel Verdult + * Copyright (C) 2009, Romain Tartière, Romuald Conty * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by the @@ -193,13 +194,24 @@ typedef enum { /** * @struct nfc_dep_info_t - * @brief NFC tag information in Data Exchange Protocol + * @brief NFC tag information in D.E.P. (Data Exchange Protocol) see ISO/IEC 18092 */ typedef struct { - byte_t NFCID3i[10]; +/** NFCID3 */ + byte_t abtNFCID3[10]; +/** DID */ byte_t btDID; - byte_t btBSt; - byte_t btBRt; +/** Supported send-bit rate */ + byte_t btBS; +/** Supported receive-bit rate */ + byte_t btBR; +/** Timeout value */ + byte_t btTO; +/** PP Parameters */ + byte_t btPP; +/** General Bytes */ + byte_t abtGB[48]; + size_t szGB; } nfc_dep_info_t; /** diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 2310d7a..67b0817 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -805,7 +805,7 @@ pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool b // Nothing to do return true; } - // Force pn53x to be in ISO1444-A mode + // Force pn53x to be in ISO14443-A mode if (!pn53x_set_reg (pnd, REG_CIU_TX_MODE, SYMBOL_TX_FRAMING, 0x00)) { return false; } @@ -866,10 +866,18 @@ pn53x_initiator_select_dep_target (nfc_device_t * pnd, const nfc_modulation_t nm // Is a target info struct available if (pnti) { - memcpy (pnti->ndi.NFCID3i, abtRx + 2, 10); + memcpy (pnti->ndi.abtNFCID3, abtRx + 2, 10); pnti->ndi.btDID = abtRx[12]; - pnti->ndi.btBSt = abtRx[13]; - pnti->ndi.btBRt = abtRx[14]; + pnti->ndi.btBS = abtRx[13]; + pnti->ndi.btBR = abtRx[14]; + pnti->ndi.btTO = abtRx[15]; + pnti->ndi.btPP = abtRx[16]; + if(szRxLen > 17) { + pnti->ndi.szGB = szRxLen - 17; + memcpy (pnti->ndi.abtGB, abtRx + 17, pnti->ndi.szGB); + } else { + pnti->ndi.szGB = 0; + } } return true; }