From 2608b3dc55e66b3d1119afb10e84eee5d2c8719d Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Wed, 2 Mar 2011 15:18:06 +0000 Subject: [PATCH] smart merge of r906 into trunk (Thanks to marko259 from libnfc forum). --- libnfc/chips/pn53x.c | 28 ++++++++++++++++++++++------ libnfc/drivers/arygon.c | 1 - 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 6493f90..e494405 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -62,6 +62,12 @@ pn53x_target_type_t pn53x_nm_to_ptt (const nfc_modulation_t nm); bool pn53x_init(nfc_device_t * pnd) { + // GetFirmwareVersion command is used to set PN53x chips type (PN531, PN532 or PN533) + char abtFirmwareText[18]; + if (!pn53x_get_firmware_version (pnd, abtFirmwareText)) { + return false; + } + // CRC handling is enabled by default pnd->bCrc = true; // Parity handling is enabled by default @@ -79,11 +85,6 @@ pn53x_init(nfc_device_t * pnd) return false; } - char abtFirmwareText[18]; - if (!pn53x_get_firmware_version (pnd, abtFirmwareText)) { - return false; - } - // Add the firmware revision to the device name char *pcName; pcName = strdup (pnd->acName); @@ -762,7 +763,22 @@ pn53x_get_firmware_version (nfc_device_t * pnd, char abtFirmwareText[18]) if (!pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), abtFw, &szFwLen, false)) { // Failed to get firmware revision??, whatever...let's disconnect and clean up and return err // FIXME: Wtf? - // pnd->pdc->disconnect (pnd); + return false; + } + // Determine which version of chip it is: PN531 will return only 2 bytes, while others return 4 bytes and have the first to tell the version IC + if (szFwLen == 2) { + ((struct pn53x_data*)(pnd->chip_data))->type = PN531; + } else if (szFwLen == 4) { + if (abtFw[0] == 0x32) { // PN532 version IC + ((struct pn53x_data*)(pnd->chip_data))->type = PN532; + } else if (abtFw[0] == 0x33) { // PN532 version IC + ((struct pn53x_data*)(pnd->chip_data))->type = PN533; + } else { + // Unknown version IC + return false; + } + } else { + // Unknown chip return false; } // Convert firmware info in text, PN531 gives 2 bytes info, but PN532 and PN533 gives 4 diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index b73e9a8..4326201 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -189,7 +189,6 @@ arygon_connect (const nfc_device_desc_t * pndd) arygon_firmware((nfc_device_spec_t) sp, acFirmware); snprintf (pnd->acName, DEVICE_NAME_LENGTH - 1, "%s %s (%s)", pndd->acDevice, acFirmware, pndd->pcPort); pnd->acName[DEVICE_NAME_LENGTH - 1] = '\0'; - pnd->nc = NC_PN532; pnd->nds = (nfc_device_spec_t) sp; pnd->bActive = true;