From 25e2dbec954cc804a710453aaa15a8fa59d3f509 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Mon, 9 May 2011 14:22:12 +0000 Subject: [PATCH] chips/pn53x: set ui8LastCommand in chip layer instead of driver layer. --- libnfc/chips/pn53x.c | 15 ++++++++++----- libnfc/drivers/arygon.c | 1 - libnfc/drivers/pn532_uart.c | 1 - libnfc/drivers/pn53x_usb.c | 1 - 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index 30d48da..e831cbc 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -119,12 +119,15 @@ pn53x_transceive (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTx, b } // Call the send/receice callback functions of the current driver - if (!CHIP_DATA(pnd)->io->send (pnd, pbtTx, szTx)) + if (!CHIP_DATA (pnd)->io->send (pnd, pbtTx, szTx)) return false; + // Command is sent, we store the command + CHIP_DATA (pnd)->ui8LastCommand = pbtTx[0]; + // Handle power mode for PN532 - if ((CHIP_DATA(pnd)->type == PN532) && (TgInitAsTarget == pbtTx[0])) { // PN532 automatically goes into PowerDown mode when TgInitAsTarget command will be sent - CHIP_DATA(pnd)->power_mode = POWERDOWN; + if ((CHIP_DATA (pnd)->type == PN532) && (TgInitAsTarget == pbtTx[0])) { // PN532 automatically goes into PowerDown mode when TgInitAsTarget command will be sent + CHIP_DATA (pnd)->power_mode = POWERDOWN; } int res = CHIP_DATA(pnd)->io->receive (pnd, pbtRx, *pszRx); @@ -443,7 +446,6 @@ bool pn53x_read_register (nfc_device_t * pnd, uint16_t ui16Reg, uint8_t * ui8Value) { byte_t abtCmd[] = { ReadRegister, ui16Reg >> 8, ui16Reg & 0xff }; - byte_t abtRegValue[2]; size_t szRegValue = sizeof (abtRegValue); @@ -475,11 +477,14 @@ pn53x_write_register (nfc_device_t * pnd, const uint16_t ui16Reg, const uint8_t if (!pn53x_read_register (pnd, ui16Reg, &ui8Current)) return false; abtCmd[3] = ((ui8Value & ui8SymbolMask) | (ui8Current & (~ui8SymbolMask))); - return (abtCmd[3] != ui8Current) ? pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL) : true; + if (abtCmd[3] != ui8Current) { + return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL); + } } else { abtCmd[3] = ui8Value; return pn53x_transceive (pnd, abtCmd, sizeof (abtCmd), NULL, NULL); } + return true; } bool diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index 1726628..13b314d 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -230,7 +230,6 @@ arygon_tama_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szDat { byte_t abtFrame[ARYGON_TX_BUFFER_LEN] = { DEV_ARYGON_PROTOCOL_TAMA, 0x00, 0x00, 0xff }; // Every packet must start with "0x32 0x00 0x00 0xff" - CHIP_DATA (pnd)->ui8LastCommand = pbtData[0]; size_t szFrame = 0; if (szData > PN53x_NORMAL_FRAME__DATA_MAX_LEN) { // ARYGON Reader with PN532 equipped does not support extended frame (bug in ARYGON firmware?) diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 763c277..591dada 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -241,7 +241,6 @@ pn532_uart_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData }; byte_t abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" - CHIP_DATA (pnd)->ui8LastCommand = pbtData[0]; size_t szFrame = 0; if (!pn53x_build_frame (abtFrame, &szFrame, pbtData, szData)) { diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index 6716947..ec3576f 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -368,7 +368,6 @@ bool pn53x_usb_send (nfc_device_t * pnd, const byte_t * pbtData, const size_t szData) { byte_t abtFrame[PN53X_USB_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" - CHIP_DATA (pnd)->ui8LastCommand = pbtData[0]; size_t szFrame = 0; pn53x_build_frame (abtFrame, &szFrame, pbtData, szData);