From adba90684dfce4b6134e9b9f0019a1f6391aeb79 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 13 Oct 2010 19:59:39 +0000 Subject: [PATCH] introduce nfc_dep_mode_t type instead of bool in nfc_initiator_select_dep_target() --- examples/nfc-dep-initiator.c | 2 +- include/nfc/nfc-types.h | 11 ++++++++++- libnfc/chips/pn53x.c | 13 +++++++------ libnfc/chips/pn53x.h | 4 ++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/examples/nfc-dep-initiator.c b/examples/nfc-dep-initiator.c index 039f7c2..b21f83c 100644 --- a/examples/nfc-dep-initiator.c +++ b/examples/nfc-dep-initiator.c @@ -62,7 +62,7 @@ main (int argc, const char *argv[]) return EXIT_FAILURE; } - if(!nfc_initiator_select_dep_target (pnd, false, NULL, &nti)) { + if(!nfc_initiator_select_dep_target (pnd, NDM_PASSIVE, NULL, &nti)) { nfc_perror(pnd, "nfc_initiator_select_dep_target"); return EXIT_FAILURE; } diff --git a/include/nfc/nfc-types.h b/include/nfc/nfc-types.h index 51d7628..b8c41e7 100644 --- a/include/nfc/nfc-types.h +++ b/include/nfc/nfc-types.h @@ -167,7 +167,7 @@ typedef enum { /** * @struct nfc_dep_info_t - * @brief NFC tag information in D.E.P. (Data Exchange Protocol) see ISO/IEC 18092 + * @brief NFC target information in D.E.P. (Data Exchange Protocol) see ISO/IEC 18092 (NFCIP-1) */ typedef struct { /** NFCID3 */ @@ -187,6 +187,15 @@ typedef struct { size_t szGB; } nfc_dep_info_t; +/** + * @enum nfc_dep_mode_t + * @brief NFC D.E.P. (Data Exchange Protocol) active/passive mode + */ +typedef enum { + NDM_PASSIVE, + NDM_ACTIVE, +} nfc_dep_mode_t; + /** * @struct nfc_iso14443a_info_t * @brief NFC ISO14443A tag (MIFARE) information diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index e93c428..7c42ab4 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -868,14 +868,14 @@ pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool b } bool -pn53x_initiator_select_dep_target(nfc_device_t * pnd, const bool bActiveDep, +pn53x_initiator_select_dep_target(nfc_device_t * pnd, const nfc_dep_mode_t ndm, const nfc_dep_info_t * pndiInitiator, nfc_target_info_t * pnti) { if (pndiInitiator) { - return pn53x_InJumpForDEP (pnd, bActiveDep, NULL, 0, pndiInitiator->abtNFCID3, pndiInitiator->abtGB, pndiInitiator->szGB, pnti); + return pn53x_InJumpForDEP (pnd, ndm, NULL, 0, pndiInitiator->abtNFCID3, pndiInitiator->abtGB, pndiInitiator->szGB, pnti); } else { - return pn53x_InJumpForDEP (pnd, bActiveDep, NULL, 0, NULL, NULL, 0, pnti); + return pn53x_InJumpForDEP (pnd, ndm, NULL, 0, NULL, NULL, 0, pnti); } } @@ -890,7 +890,8 @@ pn53x_initiator_select_dep_target(nfc_device_t * pnd, const bool bActiveDep, * @param[out] pnti nfc_target_info_t which will be filled by this function */ bool -pn53x_InJumpForDEP (nfc_device_t * pnd, const bool bActiveDep, +pn53x_InJumpForDEP (nfc_device_t * pnd, + const nfc_dep_mode_t ndm, const byte_t * pbtPassiveInitiatorData, const size_t szPassiveInitiatorData, const byte_t * pbtNFCID3i, const byte_t * pbtGB, const size_t szGB, @@ -903,13 +904,13 @@ pn53x_InJumpForDEP (nfc_device_t * pnd, const bool bActiveDep, memcpy (abtCmd, pncmd_initiator_jump_for_dep, sizeof (pncmd_initiator_jump_for_dep)); - abtCmd[2] = (bActiveDep) ? 0x01 : 0x00; + abtCmd[2] = (ndm == NDM_ACTIVE) ? 0x01 : 0x00; // FIXME Baud rate in D.E.P. mode is hard-wired as 106kbps abtCmd[3] = 0x00; /* baud rate = 106kbps */ offset = 5; - if (pbtPassiveInitiatorData && !bActiveDep) { /* can't have passive initiator data when using active mode */ + if (pbtPassiveInitiatorData && (ndm == NDM_PASSIVE)) { /* can't have passive initiator data when using active mode */ abtCmd[4] |= 0x01; memcpy (abtCmd + offset, pbtPassiveInitiatorData, szPassiveInitiatorData); offset += szPassiveInitiatorData; diff --git a/libnfc/chips/pn53x.h b/libnfc/chips/pn53x.h index 9df0c75..9990d8f 100644 --- a/libnfc/chips/pn53x.h +++ b/libnfc/chips/pn53x.h @@ -183,7 +183,7 @@ bool pn53x_initiator_poll_targets (nfc_device_t * pnd, const nfc_modulation_t * pnmModulations, const size_t szModulations, const byte_t btPollNr, const byte_t btPeriod, nfc_target_t * pntTargets, size_t * pszTargetFound); -bool pn53x_initiator_select_dep_target (nfc_device_t * pnd, const bool bActiveDep, +bool pn53x_initiator_select_dep_target (nfc_device_t * pnd, nfc_dep_mode_t ndm, const nfc_dep_info_t * pndiInitiator, nfc_target_info_t * pnti); bool pn53x_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits, @@ -214,7 +214,7 @@ bool pn53x_InRelease (nfc_device_t * pnd, const uint8_t ui8Target); bool pn53x_InAutoPoll (nfc_device_t * pnd, const pn53x_target_type_t * ppttTargetTypes, const size_t szTargetTypes, const byte_t btPollNr, const byte_t btPeriod, nfc_target_t * pntTargets, size_t * pszTargetFound); -bool pn53x_InJumpForDEP (nfc_device_t * pnd, const bool bActiveDep, +bool pn53x_InJumpForDEP (nfc_device_t * pnd, nfc_dep_mode_t ndm, const byte_t * pbtPassiveInitiatorData, const size_t szPassiveInitiatorData, const byte_t * pbtNFCID3i, const byte_t * pbtGB, const size_t szGB,