From 676477e20cc86ca1220d0877c388f4e34cb7f562 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Thu, 30 Jun 2011 17:05:59 +0000 Subject: [PATCH] rework the way to determine which command is needed to send/receive a frame as target. --- libnfc/chips/pn53x.c | 62 +++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 42290ea..1b84dfd 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -1684,16 +1684,29 @@ pn53x_target_receive_bytes (nfc_device_t * pnd, byte_t * pbtRx, size_t * pszRx) { byte_t abtCmd[1]; + // XXX I think this is not a clean way to provide some kind of "EasyFraming" + // but at the moment I have no more better than this if (pnd->bEasyFraming) { - if ((CHIP_DATA (pnd)->current_target->nm.nmt == NMT_DEP) || // If DEP mode - ((CHIP_DATA(pnd)->type == PN532) && (pnd->bAutoIso14443_4) && - (CHIP_DATA (pnd)->current_target->nm.nmt == NMT_ISO14443A) && (CHIP_DATA (pnd)->current_target->nti.nai.btSak & SAK_ISO14443_4_COMPLIANT)) // If ISO14443-4 PICC emulation - ) { - abtCmd[0] = TgGetData; - } else { - // TODO Support EasyFraming for other cases by software - pnd->iLastError = ENOTIMPL; - return false; + switch (CHIP_DATA (pnd)->current_target->nm.nmt) { + case NMT_DEP: + abtCmd[0] = TgGetData; + break; + case NMT_ISO14443A: + if (CHIP_DATA (pnd)->current_target->nti.nai.btSak & SAK_ISO14443_4_COMPLIANT) { + // We are dealing with a ISO/IEC 14443-4 compliant target + if ((CHIP_DATA(pnd)->type == PN532) && (pnd->bAutoIso14443_4)) { + // We are using ISO/IEC 14443-4 PICC emulation capability from the PN532 + abtCmd[0] = TgGetData; + break; + } else { + // TODO Support EasyFraming for other cases by software + pnd->iLastError = ENOTIMPL; + return false; + } + } + default: + abtCmd[0] = TgGetInitiatorCommand; + break; } } else { abtCmd[0] = TgGetInitiatorCommand; @@ -1762,16 +1775,29 @@ pn53x_target_send_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t if (!pnd->bPar) return false; + // XXX I think this is not a clean way to provide some kind of "EasyFraming" + // but at the moment I have no more better than this if (pnd->bEasyFraming) { - if ((CHIP_DATA (pnd)->current_target->nm.nmt == NMT_DEP) || // If DEP mode - ((CHIP_DATA(pnd)->type == PN532) && (pnd->bAutoIso14443_4) && - (CHIP_DATA (pnd)->current_target->nm.nmt == NMT_ISO14443A) && (CHIP_DATA (pnd)->current_target->nti.nai.btSak & SAK_ISO14443_4_COMPLIANT)) // If ISO14443-4 PICC emulation - ) { - abtCmd[0] = TgSetData; - } else { - // TODO Support EasyFraming for other cases by software - pnd->iLastError = ENOTIMPL; - return false; + switch (CHIP_DATA (pnd)->current_target->nm.nmt) { + case NMT_DEP: + abtCmd[0] = TgSetData; + break; + case NMT_ISO14443A: + if (CHIP_DATA (pnd)->current_target->nti.nai.btSak & SAK_ISO14443_4_COMPLIANT) { + // We are dealing with a ISO/IEC 14443-4 compliant target + if ((CHIP_DATA(pnd)->type == PN532) && (pnd->bAutoIso14443_4)) { + // We are using ISO/IEC 14443-4 PICC emulation capability from the PN532 + abtCmd[0] = TgSetData; + break; + } else { + // TODO Support EasyFraming for other cases by software + pnd->iLastError = ENOTIMPL; + return false; + } + } + default: + abtCmd[0] = TgResponseToInitiator; + break; } } else { abtCmd[0] = TgResponseToInitiator;