diff --git a/libnfc/chips/rc522-internal.h b/libnfc/chips/rc522-internal.h
index 4e9186b..7d2923c 100644
--- a/libnfc/chips/rc522-internal.h
+++ b/libnfc/chips/rc522-internal.h
@@ -1,110 +1,110 @@
-
-
-#ifndef __NFC_CHIPS_RC522_INTERNAL_H__
-#define __NFC_CHIPS_RC522_INTERNAL_H__
-
-#define RC522_FIFO_SIZE 64
-
-#define RC522_REG_CommandReg 0x01
-#define RC522_REG_CommandReg_RcvOff (1 << 5)
-#define RC522_REG_CommandReg_PowerDown (1 << 4)
-
-#define RC522_REG_ComlEnReg 0x02
-
-#define RC522_REG_DivlEnReg 0x03
-
-#define RC522_REG_ComIrqReg 0x04
-
-#define RC522_REG_DivIrqReg 0x05
-
-#define RC522_REG_ErrorReg 0x06
-
-#define RC522_REG_Status1Reg 0x07
-
-#define RC522_REG_Status2Reg 0x08
-#define RC522_REG_Status2Reg_MFCrypto1On (1 << 3)
-
-#define RC522_REG_FIFODataReg 0x09
-
-#define RC522_REG_FIFOLevelReg 0x0A
-
-#define RC522_REG_WaterLevelReg 0x0B
-
-#define RC522_REG_ControlReg 0x0C
-
-#define RC522_REG_BitFramingReg 0x0D
-
-#define RC522_REG_CollReg 0x0E
-
-#define RC522_REG_ModeReg 0x11
-
-#define RC522_REG_TxModeReg 0x12
-#define RC522_REG_TxModeReg_TxCRCEn (1 << 7)
-#define RC522_REG_TxModeReg_TxSpeed_106k (0 << 4)
-#define RC522_REG_TxModeReg_TxSpeed_212k (1 << 4)
-#define RC522_REG_TxModeReg_TxSpeed_424k (2 << 4)
-#define RC522_REG_TxModeReg_TxSpeed_847k (3 << 4)
-#define RC522_REG_TxModeReg_TxSpeed_MASK (7 << 4)
-
-#define RC522_REG_RxModeReg 0x13
-#define RC522_REG_RxModeReg_RxCRCEn (1 << 7)
-#define RC522_REG_RxModeReg_RxSpeed_106k (0 << 4)
-#define RC522_REG_RxModeReg_RxSpeed_212k (1 << 4)
-#define RC522_REG_RxModeReg_RxSpeed_424k (2 << 4)
-#define RC522_REG_RxModeReg_RxSpeed_847k (3 << 4)
-#define RC522_REG_RxModeReg_RxSpeed_MASK (7 << 4)
-
-#define RC522_REG_TxControlReg 0x14
-#define RC522_REG_TxControlReg_Tx2RFEn (1 << 1)
-#define RC522_REG_TxControlReg_Tx1RFEn (1 << 0)
-
-#define RC522_REG_TxASKReg 0x15
-
-#define RC522_REG_TxSelReg 0x16
-
-#define RC522_REG_RxSelReg 0x17
-
-#define RC522_REG_RxThresholdReg 0x18
-
-#define RC522_REG_DemodReg 0x19
-
-#define RC522_REG_MfTxReg 0x1C
-
-#define RC522_REG_MfRxReg 0x1D
-#define RC522_REG_MfRxReg_ParityDisable (1 << 4)
-
-#define RC522_REG_SerialSpeedReg 0x1F
-#define RC522_REG_CRCResultReg 0x21
-#define RC522_REG_ModWidthReg 0x24
-#define RC522_REG_RFCfgReg 0x26
-#define RC522_REG_GsNReg 0x27
-#define RC522_REG_CWGsPReg 0x28
-#define RC522_REG_ModGsPReg 0x29
-#define RC522_REG_TModeReg 0x2A
-#define RC522_REG_TPrescalerReg 0x2B
-#define RC522_REG_TReloadReg 0x2C
-#define RC522_REG_TCounterValReg 0x2E
-#define RC522_REG_TestSel1Reg 0x31
-#define RC522_REG_TestSel2Reg 0x32
-#define RC522_REG_TestPinEnReg 0x33
-#define RC522_REG_TestPinValueReg 0x34
-#define RC522_REG_TestBusReg 0x35
-#define RC522_REG_AutoTestReg 0x36
-#define RC522_REG_VersionReg 0x37
-#define RC522_REG_AnalogTestReg 0x38
-#define RC522_REG_TestDAC1Reg 0x39
-#define RC522_REG_TestDAC2Reg 0x3A
-#define RC522_REG_TestADCReg 0x3B
-
-#define RC522_CMD_Idle 0x0
-#define RC522_CMD_Mem 0x1
-#define RC522_CMD_GenerateRandomId 0x2
-#define RC522_CMD_CalcCRC 0x3
-#define RC522_CMD_Transmit 0x4
-#define RC522_CMD_NoCmdChange 0x7
-#define RC522_CMD_Receive 0x8
-#define RC522_CMD_Transceive 0xC
-#define RC522_CMD_MFAuthent 0xE
-#define RC522_CMD_SoftReset 0xF
-
-#endif
+
+
+#ifndef __NFC_CHIPS_RC522_INTERNAL_H__
+#define __NFC_CHIPS_RC522_INTERNAL_H__
+
+#define RC522_FIFO_SIZE 64
+
+#define RC522_REG_CommandReg 0x01
+#define RC522_REG_CommandReg_RcvOff (1 << 5)
+#define RC522_REG_CommandReg_PowerDown (1 << 4)
+
+#define RC522_REG_ComlEnReg 0x02
+
+#define RC522_REG_DivlEnReg 0x03
+
+#define RC522_REG_ComIrqReg 0x04
+
+#define RC522_REG_DivIrqReg 0x05
+
+#define RC522_REG_ErrorReg 0x06
+
+#define RC522_REG_Status1Reg 0x07
+
+#define RC522_REG_Status2Reg 0x08
+#define RC522_REG_Status2Reg_MFCrypto1On (1 << 3)
+
+#define RC522_REG_FIFODataReg 0x09
+
+#define RC522_REG_FIFOLevelReg 0x0A
+
+#define RC522_REG_WaterLevelReg 0x0B
+
+#define RC522_REG_ControlReg 0x0C
+
+#define RC522_REG_BitFramingReg 0x0D
+
+#define RC522_REG_CollReg 0x0E
+
+#define RC522_REG_ModeReg 0x11
+
+#define RC522_REG_TxModeReg 0x12
+#define RC522_REG_TxModeReg_TxCRCEn (1 << 7)
+#define RC522_REG_TxModeReg_TxSpeed_106k (0 << 4)
+#define RC522_REG_TxModeReg_TxSpeed_212k (1 << 4)
+#define RC522_REG_TxModeReg_TxSpeed_424k (2 << 4)
+#define RC522_REG_TxModeReg_TxSpeed_847k (3 << 4)
+#define RC522_REG_TxModeReg_TxSpeed_MASK (7 << 4)
+
+#define RC522_REG_RxModeReg 0x13
+#define RC522_REG_RxModeReg_RxCRCEn (1 << 7)
+#define RC522_REG_RxModeReg_RxSpeed_106k (0 << 4)
+#define RC522_REG_RxModeReg_RxSpeed_212k (1 << 4)
+#define RC522_REG_RxModeReg_RxSpeed_424k (2 << 4)
+#define RC522_REG_RxModeReg_RxSpeed_847k (3 << 4)
+#define RC522_REG_RxModeReg_RxSpeed_MASK (7 << 4)
+
+#define RC522_REG_TxControlReg 0x14
+#define RC522_REG_TxControlReg_Tx2RFEn (1 << 1)
+#define RC522_REG_TxControlReg_Tx1RFEn (1 << 0)
+
+#define RC522_REG_TxASKReg 0x15
+
+#define RC522_REG_TxSelReg 0x16
+
+#define RC522_REG_RxSelReg 0x17
+
+#define RC522_REG_RxThresholdReg 0x18
+
+#define RC522_REG_DemodReg 0x19
+
+#define RC522_REG_MfTxReg 0x1C
+
+#define RC522_REG_MfRxReg 0x1D
+#define RC522_REG_MfRxReg_ParityDisable (1 << 4)
+
+#define RC522_REG_SerialSpeedReg 0x1F
+#define RC522_REG_CRCResultReg 0x21
+#define RC522_REG_ModWidthReg 0x24
+#define RC522_REG_RFCfgReg 0x26
+#define RC522_REG_GsNReg 0x27
+#define RC522_REG_CWGsPReg 0x28
+#define RC522_REG_ModGsPReg 0x29
+#define RC522_REG_TModeReg 0x2A
+#define RC522_REG_TPrescalerReg 0x2B
+#define RC522_REG_TReloadReg 0x2C
+#define RC522_REG_TCounterValReg 0x2E
+#define RC522_REG_TestSel1Reg 0x31
+#define RC522_REG_TestSel2Reg 0x32
+#define RC522_REG_TestPinEnReg 0x33
+#define RC522_REG_TestPinValueReg 0x34
+#define RC522_REG_TestBusReg 0x35
+#define RC522_REG_AutoTestReg 0x36
+#define RC522_REG_VersionReg 0x37
+#define RC522_REG_AnalogTestReg 0x38
+#define RC522_REG_TestDAC1Reg 0x39
+#define RC522_REG_TestDAC2Reg 0x3A
+#define RC522_REG_TestADCReg 0x3B
+
+#define RC522_CMD_Idle 0x0
+#define RC522_CMD_Mem 0x1
+#define RC522_CMD_GenerateRandomId 0x2
+#define RC522_CMD_CalcCRC 0x3
+#define RC522_CMD_Transmit 0x4
+#define RC522_CMD_NoCmdChange 0x7
+#define RC522_CMD_Receive 0x8
+#define RC522_CMD_Transceive 0xC
+#define RC522_CMD_MFAuthent 0xE
+#define RC522_CMD_SoftReset 0xF
+
+#endif
diff --git a/libnfc/chips/rc522.c b/libnfc/chips/rc522.c
index 7a6539e..ca195c5 100644
--- a/libnfc/chips/rc522.c
+++ b/libnfc/chips/rc522.c
@@ -1,241 +1,241 @@
-/*-
- * Free/Libre Near Field Communication (NFC) library
- *
- * 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
- * Free Software Foundation, either version 3 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see
- *
- */
-
-#include
-
-#include "rc522.h"
-#include "rc522-internal.h"
-
-#include "nfc/nfc.h"
-#include "nfc-internal.h"
-
-#define LOG_CATEGORY "libnfc.chip.rc522"
-#define LOG_GROUP NFC_LOG_GROUP_CHIP
-
-#define RC522_TIMEOUT 5
-
-const nfc_modulation_type rc522_initiator_modulation[] = { NMT_ISO14443A, 0 };
-const nfc_modulation_type rc522_target_modulation[] = { 0 };
-
-const nfc_baud_rate rc522_iso14443a_supported_baud_rates[] = { NBR_847, NBR_424, NBR_212, NBR_106, 0 };
-
-struct rc522_chip_data {
- const struct rc522_io * io;
-};
-
-#define CHIP_DATA(x) ((struct rc522_chip_data *) (x)->chip_data)
-
-int rc522_data_new(struct nfc_device * pnd, const struct rc522_io * io) {
- pnd->chip_data = malloc(sizeof(struct rc522_chip_data));
- if (!pnd->chip_data) {
- perror("malloc");
- return NFC_ESOFT;
- }
-
- CHIP_DATA(pnd)->io = io;
- return NFC_SUCCESS;
-}
-
-int rc522_read_reg(struct nfc_device * pnd, uint8_t reg) {
- uint8_t val;
-
- int ret = CHIP_DATA(pnd)->io->read(pnd, reg, &val, 1);
- if (ret < 0) {
- return ret;
- }
-
- return val;
-}
-
-int rc522_write_reg(struct nfc_device * pnd, uint8_t reg, uint8_t val, uint8_t mask) {
- if (mask != 0xFF) {
- int oldval = rc522_read_reg(pnd, reg);
- if (oldval < 0) {
- return oldval;
- }
-
- val = (val & mask) | (oldval & ~mask);
- }
-
- return CHIP_DATA(pnd)->io->write(pnd, reg, &val, 1);
-}
-
-int rc522_set_baud_rate(struct nfc_device * pnd, nfc_baud_rate speed) {
- uint8_t txVal, rxVal;
- int ret;
-
- switch (speed) {
- case NBR_106:
- txVal = RC522_REG_TxModeReg_TxSpeed_106k;
- rxVal = RC522_REG_RxModeReg_RxSpeed_106k;
- break;
-
- case NBR_212:
- txVal = RC522_REG_TxModeReg_TxSpeed_212k;
- rxVal = RC522_REG_RxModeReg_RxSpeed_212k;
- break;
-
- case NBR_424:
- txVal = RC522_REG_TxModeReg_TxSpeed_424k;
- rxVal = RC522_REG_RxModeReg_RxSpeed_424k;
- break;
-
- case NBR_847:
- txVal = RC522_REG_TxModeReg_TxSpeed_847k;
- rxVal = RC522_REG_RxModeReg_RxSpeed_847k;
- break;
-
- default:
- return NFC_EINVARG;
- }
-
- return
- rc522_write_reg(pnd, RC522_REG_TxModeReg, txVal, RC522_REG_TxModeReg_TxSpeed_MASK) ||
- rc522_write_reg(pnd, RC522_REG_RxModeReg, rxVal, RC522_REG_RxModeReg_RxSpeed_MASK);
-}
-
-int rc522_initiator_select_passive_target_ext(struct nfc_device * pnd, const nfc_modulation nm, const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt, int timeout)
-{
- int ret;
-
- if (nm.nmt != NMT_ISO14443A) {
- return NFC_EINVARG;
- }
-
- ret = rc522_set_baud_rate(pnd, nm.nbr);
- if (ret < 0) {
- return ret;
- }
-
- // TODO
- return NFC_ENOTIMPL;
-}
-
-int rc522_get_supported_modulation(struct nfc_device * pnd, const nfc_mode mode, const nfc_modulation_type ** const supported_mt) {
- switch (mode) {
- case N_INITIATOR:
- *supported_mt = rc522_initiator_modulation;
- break;
-
- case N_TARGET:
- *supported_mt = rc522_target_modulation;
- break;
-
- default:
- return NFC_EINVARG;
- }
-
- return NFC_SUCCESS;
-}
-
-int rc522_get_supported_baud_rate(struct nfc_device * pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate ** const supported_br) {
- switch (mode) {
- case N_INITIATOR:
- switch (nmt) {
- case NMT_ISO14443A:
- *supported_br = rc522_iso14443a_supported_baud_rates;
- break;
-
- default:
- return NFC_EINVARG;
- }
- break;
-
- case N_TARGET:
- default:
- return NFC_EINVARG;
- }
-
- return NFC_SUCCESS;
-}
-
-int rc522_set_property_bool(struct nfc_device * pnd, const nfc_property property, const bool enable) {
- int ret;
-
- switch (property) {
- case NP_HANDLE_CRC:
- if (pnd->bCrc == enable) {
- return NFC_SUCCESS;
- }
-
- ret = rc522_write_reg(pnd, RC522_REG_TxModeReg, enable ? ~0 : 0, RC522_REG_TxModeReg_TxCRCEn) ||
- rc522_write_reg(pnd, RC522_REG_RxModeReg, enable ? ~0 : 0, RC522_REG_RxModeReg_RxCRCEn);
- if (ret) {
- return ret;
- }
-
- pnd->bCrc = enable;
- return NFC_SUCCESS;
-
- case NP_HANDLE_PARITY:
- if (pnd->bPar == enable) {
- return NFC_SUCCESS;
- }
-
- ret = rc522_write_reg(pnd, RC522_REG_MfRxReg, enable ? 0 : ~0, RC522_REG_MfRxReg_ParityDisable);
- if (ret) {
- return ret;
- }
-
- pnd->bPar = enable;
- return NFC_SUCCESS;
-
- case NP_EASY_FRAMING:
- pnd->bEasyFraming = enable;
- return NFC_SUCCESS;
-
- case NP_ACTIVATE_FIELD:
- return rc522_write_reg(pnd, RC522_REG_TxControlReg, enable ? ~0 : 0, RC522_REG_TxControlReg_Tx2RFEn | RC522_REG_TxControlReg_Tx1RFEn);
-
- case NP_ACTIVATE_CRYPTO1:
- return rc522_write_reg(pnd, RC522_REG_Status2Reg, enable ? ~0 : 0, RC522_REG_Status2Reg_MFCrypto1On);
-
- case NP_FORCE_ISO14443_A:
- // ISO14443-A is the only mode supported by MFRC522
- return NFC_SUCCESS;
-
- case NP_FORCE_SPEED_106:
- if (!enable) {
- return NFC_SUCCESS;
- }
-
- return rc522_set_baud_rate(pnd, NBR_106);
-
- case NP_AUTO_ISO14443_4:
- case NP_ACCEPT_INVALID_FRAMES:
- case NP_INFINITE_SELECT:
- case NP_FORCE_ISO14443_B:
- case NP_TIMEOUT_COMMAND:
- case NP_TIMEOUT_ATR:
- case NP_TIMEOUT_COM:
- return NFC_EINVARG;
- }
-
- return NFC_EINVARG;
-}
-
-int rc522_set_property_int(struct nfc_device * pnd, const nfc_property property, const int value) {
- // TODO
- return NFC_ENOTIMPL;
-}
-
-int rc522_idle(struct nfc_device * pnd) {
- // Set idle and disable RX demodulator to save energy
- return rc522_write_reg(pnd, RC522_REG_CommandReg, RC522_CMD_Idle | RC522_REG_CommandReg_PowerDown, 0xFF);
-}
-
+/*-
+ * Free/Libre Near Field Communication (NFC) library
+ *
+ * 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
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see
+ *
+ */
+
+#include
+
+#include "rc522.h"
+#include "rc522-internal.h"
+
+#include "nfc/nfc.h"
+#include "nfc-internal.h"
+
+#define LOG_CATEGORY "libnfc.chip.rc522"
+#define LOG_GROUP NFC_LOG_GROUP_CHIP
+
+#define RC522_TIMEOUT 5
+
+const nfc_modulation_type rc522_initiator_modulation[] = { NMT_ISO14443A, 0 };
+const nfc_modulation_type rc522_target_modulation[] = { 0 };
+
+const nfc_baud_rate rc522_iso14443a_supported_baud_rates[] = { NBR_847, NBR_424, NBR_212, NBR_106, 0 };
+
+struct rc522_chip_data {
+ const struct rc522_io * io;
+};
+
+#define CHIP_DATA(x) ((struct rc522_chip_data *) (x)->chip_data)
+
+int rc522_data_new(struct nfc_device * pnd, const struct rc522_io * io) {
+ pnd->chip_data = malloc(sizeof(struct rc522_chip_data));
+ if (!pnd->chip_data) {
+ perror("malloc");
+ return NFC_ESOFT;
+ }
+
+ CHIP_DATA(pnd)->io = io;
+ return NFC_SUCCESS;
+}
+
+int rc522_read_reg(struct nfc_device * pnd, uint8_t reg) {
+ uint8_t val;
+
+ int ret = CHIP_DATA(pnd)->io->read(pnd, reg, &val, 1);
+ if (ret < 0) {
+ return ret;
+ }
+
+ return val;
+}
+
+int rc522_write_reg(struct nfc_device * pnd, uint8_t reg, uint8_t val, uint8_t mask) {
+ if (mask != 0xFF) {
+ int oldval = rc522_read_reg(pnd, reg);
+ if (oldval < 0) {
+ return oldval;
+ }
+
+ val = (val & mask) | (oldval & ~mask);
+ }
+
+ return CHIP_DATA(pnd)->io->write(pnd, reg, &val, 1);
+}
+
+int rc522_set_baud_rate(struct nfc_device * pnd, nfc_baud_rate speed) {
+ uint8_t txVal, rxVal;
+ int ret;
+
+ switch (speed) {
+ case NBR_106:
+ txVal = RC522_REG_TxModeReg_TxSpeed_106k;
+ rxVal = RC522_REG_RxModeReg_RxSpeed_106k;
+ break;
+
+ case NBR_212:
+ txVal = RC522_REG_TxModeReg_TxSpeed_212k;
+ rxVal = RC522_REG_RxModeReg_RxSpeed_212k;
+ break;
+
+ case NBR_424:
+ txVal = RC522_REG_TxModeReg_TxSpeed_424k;
+ rxVal = RC522_REG_RxModeReg_RxSpeed_424k;
+ break;
+
+ case NBR_847:
+ txVal = RC522_REG_TxModeReg_TxSpeed_847k;
+ rxVal = RC522_REG_RxModeReg_RxSpeed_847k;
+ break;
+
+ default:
+ return NFC_EINVARG;
+ }
+
+ return
+ rc522_write_reg(pnd, RC522_REG_TxModeReg, txVal, RC522_REG_TxModeReg_TxSpeed_MASK) ||
+ rc522_write_reg(pnd, RC522_REG_RxModeReg, rxVal, RC522_REG_RxModeReg_RxSpeed_MASK);
+}
+
+int rc522_initiator_select_passive_target_ext(struct nfc_device * pnd, const nfc_modulation nm, const uint8_t * pbtInitData, const size_t szInitData, nfc_target * pnt, int timeout)
+{
+ int ret;
+
+ if (nm.nmt != NMT_ISO14443A) {
+ return NFC_EINVARG;
+ }
+
+ ret = rc522_set_baud_rate(pnd, nm.nbr);
+ if (ret < 0) {
+ return ret;
+ }
+
+ // TODO
+ return NFC_ENOTIMPL;
+}
+
+int rc522_get_supported_modulation(struct nfc_device * pnd, const nfc_mode mode, const nfc_modulation_type ** const supported_mt) {
+ switch (mode) {
+ case N_INITIATOR:
+ *supported_mt = rc522_initiator_modulation;
+ break;
+
+ case N_TARGET:
+ *supported_mt = rc522_target_modulation;
+ break;
+
+ default:
+ return NFC_EINVARG;
+ }
+
+ return NFC_SUCCESS;
+}
+
+int rc522_get_supported_baud_rate(struct nfc_device * pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate ** const supported_br) {
+ switch (mode) {
+ case N_INITIATOR:
+ switch (nmt) {
+ case NMT_ISO14443A:
+ *supported_br = rc522_iso14443a_supported_baud_rates;
+ break;
+
+ default:
+ return NFC_EINVARG;
+ }
+ break;
+
+ case N_TARGET:
+ default:
+ return NFC_EINVARG;
+ }
+
+ return NFC_SUCCESS;
+}
+
+int rc522_set_property_bool(struct nfc_device * pnd, const nfc_property property, const bool enable) {
+ int ret;
+
+ switch (property) {
+ case NP_HANDLE_CRC:
+ if (pnd->bCrc == enable) {
+ return NFC_SUCCESS;
+ }
+
+ ret = rc522_write_reg(pnd, RC522_REG_TxModeReg, enable ? ~0 : 0, RC522_REG_TxModeReg_TxCRCEn) ||
+ rc522_write_reg(pnd, RC522_REG_RxModeReg, enable ? ~0 : 0, RC522_REG_RxModeReg_RxCRCEn);
+ if (ret) {
+ return ret;
+ }
+
+ pnd->bCrc = enable;
+ return NFC_SUCCESS;
+
+ case NP_HANDLE_PARITY:
+ if (pnd->bPar == enable) {
+ return NFC_SUCCESS;
+ }
+
+ ret = rc522_write_reg(pnd, RC522_REG_MfRxReg, enable ? 0 : ~0, RC522_REG_MfRxReg_ParityDisable);
+ if (ret) {
+ return ret;
+ }
+
+ pnd->bPar = enable;
+ return NFC_SUCCESS;
+
+ case NP_EASY_FRAMING:
+ pnd->bEasyFraming = enable;
+ return NFC_SUCCESS;
+
+ case NP_ACTIVATE_FIELD:
+ return rc522_write_reg(pnd, RC522_REG_TxControlReg, enable ? ~0 : 0, RC522_REG_TxControlReg_Tx2RFEn | RC522_REG_TxControlReg_Tx1RFEn);
+
+ case NP_ACTIVATE_CRYPTO1:
+ return rc522_write_reg(pnd, RC522_REG_Status2Reg, enable ? ~0 : 0, RC522_REG_Status2Reg_MFCrypto1On);
+
+ case NP_FORCE_ISO14443_A:
+ // ISO14443-A is the only mode supported by MFRC522
+ return NFC_SUCCESS;
+
+ case NP_FORCE_SPEED_106:
+ if (!enable) {
+ return NFC_SUCCESS;
+ }
+
+ return rc522_set_baud_rate(pnd, NBR_106);
+
+ case NP_AUTO_ISO14443_4:
+ case NP_ACCEPT_INVALID_FRAMES:
+ case NP_INFINITE_SELECT:
+ case NP_FORCE_ISO14443_B:
+ case NP_TIMEOUT_COMMAND:
+ case NP_TIMEOUT_ATR:
+ case NP_TIMEOUT_COM:
+ return NFC_EINVARG;
+ }
+
+ return NFC_EINVARG;
+}
+
+int rc522_set_property_int(struct nfc_device * pnd, const nfc_property property, const int value) {
+ // TODO
+ return NFC_ENOTIMPL;
+}
+
+int rc522_idle(struct nfc_device * pnd) {
+ // Set idle and disable RX demodulator to save energy
+ return rc522_write_reg(pnd, RC522_REG_CommandReg, RC522_CMD_Idle | RC522_REG_CommandReg_PowerDown, 0xFF);
+}
+
diff --git a/libnfc/chips/rc522.h b/libnfc/chips/rc522.h
index 41153d2..4a2a90a 100644
--- a/libnfc/chips/rc522.h
+++ b/libnfc/chips/rc522.h
@@ -1,35 +1,37 @@
-/*-
- * Free/Libre Near Field Communication (NFC) library
- *
- * 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
- * Free Software Foundation, either version 3 of the License, or (at your
- * option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program. If not, see
- *
- */
-
-#ifndef __NFC_CHIPS_RC522_H__
-#define __NFC_CHIPS_RC522_H__
-
-#include
-#include
-
-struct rc522_io {
- int (*read)(struct nfc_device * pnd, uint8_t reg, uint8_t * data, size_t size);
- int (*write)(struct nfc_device * pnd, uint8_t reg, const uint8_t * data, size_t size);
-};
-
-int rc522_data_new(struct nfc_device * pnd, const struct rc522_io * io);
-int rc522_get_supported_modulation(nfc_device * pnd, const nfc_mode mode, const nfc_modulation_type ** const supported_mt);
-int rc522_get_supported_baud_rate(nfc_device * pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate ** const supported_br);
-int rc522_set_property_bool(struct nfc_device * pnd, const nfc_property property, const bool enable);
-
-#endif
+/*-
+ * Free/Libre Near Field Communication (NFC) library
+ *
+ * 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
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see
+ *
+ */
+
+#ifndef __NFC_CHIPS_RC522_H__
+#define __NFC_CHIPS_RC522_H__
+
+#include
+#include
+
+struct rc522_io {
+ int (*read)(struct nfc_device * pnd, uint8_t reg, uint8_t * data, size_t size);
+ int (*write)(struct nfc_device * pnd, uint8_t reg, const uint8_t * data, size_t size);
+};
+
+int rc522_data_new(struct nfc_device * pnd, const struct rc522_io * io);
+int rc522_get_supported_modulation(nfc_device * pnd, const nfc_mode mode, const nfc_modulation_type ** const supported_mt);
+int rc522_get_supported_baud_rate(nfc_device * pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate ** const supported_br);
+int rc522_set_property_bool(struct nfc_device * pnd, const nfc_property property, const bool enable);
+int rc522_set_property_int(struct nfc_device * pnd, const nfc_property property, const int value);
+int rc522_idle(struct nfc_device * pnd);
+
+#endif