nfc_properties replace now nfc_options and nfc_configure is replaced by nfc_device_set_property_bool which returns error code.
This commit is contained in:
parent
c181cb35ec
commit
a615d969fd
20 changed files with 292 additions and 298 deletions
|
|
@ -643,143 +643,6 @@ pn53x_get_firmware_version (nfc_device *pnd, char abtFirmwareText[22])
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
pn53x_configure (nfc_device *pnd, const nfc_device_option ndo, const bool bEnable)
|
||||
{
|
||||
uint8_t btValue;
|
||||
switch (ndo) {
|
||||
case NDO_HANDLE_CRC:
|
||||
// Enable or disable automatic receiving/sending of CRC bytes
|
||||
if (bEnable == pnd->bCrc) {
|
||||
// Nothing to do
|
||||
return true;
|
||||
}
|
||||
// TX and RX are both represented by the symbol 0x80
|
||||
btValue = (bEnable) ? 0x80 : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_CRC_ENABLE, btValue))
|
||||
return false;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_CRC_ENABLE, btValue))
|
||||
return false;
|
||||
pnd->bCrc = bEnable;
|
||||
break;
|
||||
|
||||
case NDO_HANDLE_PARITY:
|
||||
// Handle parity bit by PN53X chip or parse it as data bit
|
||||
if (bEnable == pnd->bPar)
|
||||
// Nothing to do
|
||||
return true;
|
||||
btValue = (bEnable) ? 0x00 : SYMBOL_PARITY_DISABLE;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_ManualRCV, SYMBOL_PARITY_DISABLE, btValue))
|
||||
return false;
|
||||
pnd->bPar = bEnable;
|
||||
break;
|
||||
|
||||
case NDO_EASY_FRAMING:
|
||||
pnd->bEasyFraming = bEnable;
|
||||
break;
|
||||
|
||||
case NDO_ACTIVATE_FIELD:
|
||||
{
|
||||
return pn53x_RFConfiguration__RF_field (pnd, bEnable);
|
||||
}
|
||||
break;
|
||||
|
||||
case NDO_ACTIVATE_CRYPTO1:
|
||||
btValue = (bEnable) ? SYMBOL_MF_CRYPTO1_ON : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_Status2, SYMBOL_MF_CRYPTO1_ON, btValue))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case NDO_INFINITE_SELECT:
|
||||
{
|
||||
// TODO Made some research around this point:
|
||||
// timings could be tweak better than this, and maybe we can tweak timings
|
||||
// to "gain" a sort-of hardware polling (ie. like PN532 does)
|
||||
return pn53x_RFConfiguration__MaxRetries (pnd,
|
||||
(bEnable) ? 0xff : 0x00, // MxRtyATR, default: active = 0xff, passive = 0x02
|
||||
(bEnable) ? 0xff : 0x00, // MxRtyPSL, default: 0x01
|
||||
(bEnable) ? 0xff : 0x02 // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531)
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case NDO_ACCEPT_INVALID_FRAMES:
|
||||
btValue = (bEnable) ? SYMBOL_RX_NO_ERROR : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_NO_ERROR, btValue))
|
||||
return false;
|
||||
break;
|
||||
|
||||
case NDO_ACCEPT_MULTIPLE_FRAMES:
|
||||
btValue = (bEnable) ? SYMBOL_RX_MULTIPLE : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_MULTIPLE, btValue))
|
||||
return false;
|
||||
return true;
|
||||
break;
|
||||
|
||||
case NDO_AUTO_ISO14443_4:
|
||||
if (bEnable == pnd->bAutoIso14443_4)
|
||||
// Nothing to do
|
||||
return true;
|
||||
pnd->bAutoIso14443_4 = bEnable;
|
||||
return pn53x_set_parameters (pnd, PARAM_AUTO_RATS, bEnable);
|
||||
break;
|
||||
|
||||
case NDO_FORCE_ISO14443_A:
|
||||
if(!bEnable) {
|
||||
// Nothing to do
|
||||
return true;
|
||||
}
|
||||
// Force pn53x to be in ISO14443-A mode
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_FRAMING, 0x00)) {
|
||||
return false;
|
||||
}
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_FRAMING, 0x00)) {
|
||||
return false;
|
||||
}
|
||||
// Set the PN53X to force 100% ASK Modified miller decoding (default for 14443A cards)
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxAuto, SYMBOL_FORCE_100_ASK, 0x40))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
break;
|
||||
|
||||
case NDO_FORCE_ISO14443_B:
|
||||
if(!bEnable) {
|
||||
// Nothing to do
|
||||
return true;
|
||||
}
|
||||
// Force pn53x to be in ISO14443-B mode
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_FRAMING, 0x03)) {
|
||||
return false;
|
||||
}
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_FRAMING, 0x03)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
break;
|
||||
|
||||
case NDO_FORCE_SPEED_106:
|
||||
if(!bEnable) {
|
||||
// Nothing to do
|
||||
return true;
|
||||
}
|
||||
// Force pn53x to be at 106 kbps
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_SPEED, 0x00)) {
|
||||
return false;
|
||||
}
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_SPEED, 0x00)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
|
||||
// When we reach this, the configuration is completed and successful
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t
|
||||
pn53x_int_to_timeout (const int ms)
|
||||
{
|
||||
|
|
@ -816,6 +679,143 @@ pn53x_set_property_int (nfc_device *pnd, const nfc_property property, const int
|
|||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
pn53x_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable)
|
||||
{
|
||||
uint8_t btValue;
|
||||
switch (property) {
|
||||
case NP_HANDLE_CRC:
|
||||
// Enable or disable automatic receiving/sending of CRC bytes
|
||||
if (bEnable == pnd->bCrc) {
|
||||
// Nothing to do
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
// TX and RX are both represented by the symbol 0x80
|
||||
btValue = (bEnable) ? 0x80 : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_CRC_ENABLE, btValue))
|
||||
return NFC_DEVICE_ERROR;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_CRC_ENABLE, btValue))
|
||||
return NFC_DEVICE_ERROR;
|
||||
pnd->bCrc = bEnable;
|
||||
break;
|
||||
|
||||
case NP_HANDLE_PARITY:
|
||||
// Handle parity bit by PN53X chip or parse it as data bit
|
||||
if (bEnable == pnd->bPar)
|
||||
// Nothing to do
|
||||
return NFC_SUCCESS;
|
||||
btValue = (bEnable) ? 0x00 : SYMBOL_PARITY_DISABLE;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_ManualRCV, SYMBOL_PARITY_DISABLE, btValue))
|
||||
return NFC_DEVICE_ERROR;
|
||||
pnd->bPar = bEnable;
|
||||
break;
|
||||
|
||||
case NP_EASY_FRAMING:
|
||||
pnd->bEasyFraming = bEnable;
|
||||
break;
|
||||
|
||||
case NP_ACTIVATE_FIELD:
|
||||
{
|
||||
return pn53x_RFConfiguration__RF_field (pnd, bEnable);
|
||||
}
|
||||
break;
|
||||
|
||||
case NP_ACTIVATE_CRYPTO1:
|
||||
btValue = (bEnable) ? SYMBOL_MF_CRYPTO1_ON : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_Status2, SYMBOL_MF_CRYPTO1_ON, btValue))
|
||||
return NFC_DEVICE_ERROR;
|
||||
break;
|
||||
|
||||
case NP_INFINITE_SELECT:
|
||||
{
|
||||
// TODO Made some research around this point:
|
||||
// timings could be tweak better than this, and maybe we can tweak timings
|
||||
// to "gain" a sort-of hardware polling (ie. like PN532 does)
|
||||
return pn53x_RFConfiguration__MaxRetries (pnd,
|
||||
(bEnable) ? 0xff : 0x00, // MxRtyATR, default: active = 0xff, passive = 0x02
|
||||
(bEnable) ? 0xff : 0x00, // MxRtyPSL, default: 0x01
|
||||
(bEnable) ? 0xff : 0x02 // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531)
|
||||
);
|
||||
}
|
||||
break;
|
||||
|
||||
case NP_ACCEPT_INVALID_FRAMES:
|
||||
btValue = (bEnable) ? SYMBOL_RX_NO_ERROR : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_NO_ERROR, btValue))
|
||||
return NFC_DEVICE_ERROR;
|
||||
break;
|
||||
|
||||
case NP_ACCEPT_MULTIPLE_FRAMES:
|
||||
btValue = (bEnable) ? SYMBOL_RX_MULTIPLE : 0x00;
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_MULTIPLE, btValue))
|
||||
return NFC_DEVICE_ERROR;
|
||||
return NFC_SUCCESS;
|
||||
break;
|
||||
|
||||
case NP_AUTO_ISO14443_4:
|
||||
if (bEnable == pnd->bAutoIso14443_4)
|
||||
// Nothing to do
|
||||
return NFC_SUCCESS;
|
||||
pnd->bAutoIso14443_4 = bEnable;
|
||||
return pn53x_set_parameters (pnd, PARAM_AUTO_RATS, bEnable);
|
||||
break;
|
||||
|
||||
case NP_FORCE_ISO14443_A:
|
||||
if(!bEnable) {
|
||||
// Nothing to do
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
// Force pn53x to be in ISO14443-A mode
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_FRAMING, 0x00)) {
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_FRAMING, 0x00)) {
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
// Set the PN53X to force 100% ASK Modified miller decoding (default for 14443A cards)
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxAuto, SYMBOL_FORCE_100_ASK, 0x40))
|
||||
return NFC_DEVICE_ERROR;
|
||||
|
||||
return NFC_SUCCESS;
|
||||
break;
|
||||
|
||||
case NP_FORCE_ISO14443_B:
|
||||
if(!bEnable) {
|
||||
// Nothing to do
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
// Force pn53x to be in ISO14443-B mode
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_FRAMING, 0x03)) {
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_FRAMING, 0x03)) {
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
return NFC_SUCCESS;
|
||||
break;
|
||||
|
||||
case NP_FORCE_SPEED_106:
|
||||
if(!bEnable) {
|
||||
// Nothing to do
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
// Force pn53x to be at 106 kbps
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_TxMode, SYMBOL_TX_SPEED, 0x00)) {
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
if (!pn53x_write_register (pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_SPEED, 0x00)) {
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
return NFC_SUCCESS;
|
||||
break;
|
||||
}
|
||||
|
||||
// When we reach this, the configuration is completed and successful
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
bool
|
||||
pn53x_idle (nfc_device *pnd)
|
||||
{
|
||||
|
|
@ -840,7 +840,7 @@ pn53x_idle (nfc_device *pnd)
|
|||
return false;
|
||||
}
|
||||
// Disable RF field to avoid heating
|
||||
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, false)) {
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, false) < 0) {
|
||||
return false;
|
||||
}
|
||||
if (CHIP_DATA (pnd)->type == PN532) {
|
||||
|
|
@ -908,13 +908,13 @@ pn53x_initiator_select_passive_target_ext (nfc_device *pnd,
|
|||
return false;
|
||||
}
|
||||
// No native support in InListPassiveTarget so we do discovery by hand
|
||||
if (!nfc_configure (pnd, NDO_FORCE_ISO14443_B, true)) {
|
||||
if (nfc_device_set_property_bool (pnd, NP_FORCE_ISO14443_B, true) < 0) {
|
||||
return false;
|
||||
}
|
||||
if (!nfc_configure (pnd, NDO_FORCE_SPEED_106, true)) {
|
||||
if (nfc_device_set_property_bool (pnd, NP_FORCE_SPEED_106, true) < 0) {
|
||||
return false;
|
||||
}
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_CRC, true)) {
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, true) < 0) {
|
||||
return false;
|
||||
}
|
||||
pnd->bEasyFraming = false;
|
||||
|
|
@ -1051,7 +1051,7 @@ pn53x_initiator_poll_target (nfc_device *pnd,
|
|||
break;
|
||||
}
|
||||
} else {
|
||||
pn53x_configure (pnd, NDO_INFINITE_SELECT, true);
|
||||
pn53x_set_property_bool (pnd, NP_INFINITE_SELECT, true);
|
||||
// FIXME It does not support DEP targets
|
||||
do {
|
||||
for (size_t p=0; p<uiPollNr; p++) {
|
||||
|
|
@ -1527,7 +1527,7 @@ pn53x_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t *psz
|
|||
pn53x_set_parameters (pnd, PARAM_AUTO_ATR_RES, false);
|
||||
if (CHIP_DATA(pnd)->type == PN532) { // We have a PN532
|
||||
if ((pnt->nti.nai.btSak & SAK_ISO14443_4_COMPLIANT) && (pnd->bAutoIso14443_4)) {
|
||||
// We have a ISO14443-4 tag to emulate and NDO_AUTO_14443_4A option is enabled
|
||||
// We have a ISO14443-4 tag to emulate and NP_AUTO_14443_4A option is enabled
|
||||
ptm |= PTM_ISO14443_4_PICC_ONLY; // We add ISO14443-4 restriction
|
||||
pn53x_set_parameters (pnd, PARAM_14443_4_PICC, true);
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -276,8 +276,8 @@ bool pn53x_decode_target_data (const uint8_t *pbtRawData, size_t szRawData,
|
|||
bool pn53x_read_register (nfc_device *pnd, uint16_t ui16Reg, uint8_t *ui8Value);
|
||||
bool pn53x_write_register (nfc_device *pnd, uint16_t ui16Reg, uint8_t ui8SymbolMask, uint8_t ui8Value);
|
||||
bool pn53x_get_firmware_version (nfc_device *pnd, char abtFirmwareText[22]);
|
||||
bool pn53x_configure (nfc_device *pnd, const nfc_device_option ndo, const bool bEnable);
|
||||
int pn53x_set_property_int (nfc_device *pnd, const nfc_property property, const int value);
|
||||
int pn53x_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable);
|
||||
|
||||
bool pn53x_check_communication (nfc_device *pnd);
|
||||
bool pn53x_idle (nfc_device *pnd);
|
||||
|
|
|
|||
|
|
@ -487,7 +487,7 @@ const struct nfc_driver_t acr122_driver = {
|
|||
.target_send_bits = pn53x_target_send_bits,
|
||||
.target_receive_bits = pn53x_target_receive_bits,
|
||||
|
||||
.configure = pn53x_configure,
|
||||
.device_set_property_bool = pn53x_set_property_bool,
|
||||
.device_set_property_int = pn53x_set_property_int,
|
||||
|
||||
.abort_command = NULL, // FIXME: abort is not supported in this driver
|
||||
|
|
|
|||
|
|
@ -579,7 +579,7 @@ const struct nfc_driver_t arygon_driver = {
|
|||
.target_send_bits = pn53x_target_send_bits,
|
||||
.target_receive_bits = pn53x_target_receive_bits,
|
||||
|
||||
.configure = pn53x_configure,
|
||||
.device_set_property_bool = pn53x_set_property_bool,
|
||||
.device_set_property_int = pn53x_set_property_int,
|
||||
|
||||
.abort_command = arygon_abort_command,
|
||||
|
|
|
|||
|
|
@ -525,7 +525,7 @@ const struct nfc_driver_t pn532_uart_driver = {
|
|||
.target_send_bits = pn53x_target_send_bits,
|
||||
.target_receive_bits = pn53x_target_receive_bits,
|
||||
|
||||
.configure = pn53x_configure,
|
||||
.device_set_property_bool = pn53x_set_property_bool,
|
||||
.device_set_property_int = pn53x_set_property_int,
|
||||
|
||||
.abort_command = pn532_uart_abort_command,
|
||||
|
|
|
|||
|
|
@ -751,32 +751,32 @@ On ASK LoGO hardware:
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
pn53x_usb_configure (nfc_device *pnd, const nfc_device_option ndo, const bool bEnable)
|
||||
int
|
||||
pn53x_usb_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable)
|
||||
{
|
||||
if (!pn53x_configure (pnd, ndo, bEnable))
|
||||
return false;
|
||||
if (!pn53x_set_property_bool (pnd, property, bEnable))
|
||||
return NFC_DEVICE_ERROR;
|
||||
|
||||
switch (DRIVER_DATA (pnd)->model) {
|
||||
case ASK_LOGO:
|
||||
if (NDO_ACTIVATE_FIELD == ndo) {
|
||||
if (NP_ACTIVATE_FIELD == property) {
|
||||
/* Switch on/off LED2 and Progressive Field GPIO according to ACTIVATE_FIELD option */
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Switch progressive field %s", bEnable ? "On" : "Off");
|
||||
if (!pn53x_write_register (pnd, PN53X_SFR_P3, _BV(P31) | _BV(P34), bEnable ? _BV (P34) : _BV (P31)))
|
||||
return false;
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
break;
|
||||
case SCM_SCL3711:
|
||||
if (NDO_ACTIVATE_FIELD == ndo) {
|
||||
if (NP_ACTIVATE_FIELD == property) {
|
||||
// Switch on/off LED according to ACTIVATE_FIELD option
|
||||
if (!pn53x_write_register (pnd, PN53X_SFR_P3, _BV (P32), bEnable ? 0 : _BV (P32)))
|
||||
return false;
|
||||
return NFC_DEVICE_ERROR;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
@ -814,7 +814,7 @@ const struct nfc_driver_t pn53x_usb_driver = {
|
|||
.target_send_bits = pn53x_target_send_bits,
|
||||
.target_receive_bits = pn53x_target_receive_bits,
|
||||
|
||||
.configure = pn53x_usb_configure,
|
||||
.device_set_property_bool = pn53x_usb_set_property_bool,
|
||||
.device_set_property_int = pn53x_set_property_int,
|
||||
|
||||
.abort_command = pn53x_usb_abort_command,
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ struct nfc_driver_t {
|
|||
bool (*target_send_bits) (nfc_device *pnd, const uint8_t * pbtTx, const size_t szTxBits, const uint8_t * pbtTxPar);
|
||||
bool (*target_receive_bits) (nfc_device *pnd, uint8_t * pbtRx, size_t * pszRxBits, uint8_t * pbtRxPar);
|
||||
|
||||
bool (*configure) (nfc_device *pnd, const nfc_device_option ndo, const bool bEnable);
|
||||
int (*device_set_property_bool) (nfc_device *pnd, const nfc_property property, const bool bEnable);
|
||||
int (*device_set_property_int) (nfc_device *pnd, const nfc_property property, const int value);
|
||||
|
||||
bool (*abort_command) (nfc_device *pnd);
|
||||
|
|
|
|||
133
libnfc/nfc.c
133
libnfc/nfc.c
|
|
@ -203,24 +203,6 @@ nfc_list_devices (nfc_connstring connstrings[] , size_t szDevices, size_t *pszDe
|
|||
log_fini ();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Configure advanced NFC device settings
|
||||
* @return Returns \c true if action was successfully performed; otherwise returns \c false.
|
||||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||
* @param ndo \a nfc_device_option struct that contains option to set to device
|
||||
* @param bEnable boolean to activate/disactivate the option
|
||||
*
|
||||
* Configures parameters and registers that control for example timing,
|
||||
* modulation, frame and error handling. There are different categories for
|
||||
* configuring the \e PN53X chip features (handle, activate, infinite and
|
||||
* accept).
|
||||
*/
|
||||
bool
|
||||
nfc_configure (nfc_device *pnd, const nfc_device_option ndo, const bool bEnable)
|
||||
{
|
||||
HAL (configure, pnd, ndo, bEnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set a device's integer-property value
|
||||
* @return Returns 0 on success, otherwise returns libnfc's error code (negative value)
|
||||
|
|
@ -238,6 +220,25 @@ nfc_device_set_property_int (nfc_device *pnd, const nfc_property property, const
|
|||
HAL (device_set_property_int, pnd, property, value);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Set a device's boolean-property value
|
||||
* @return Returns 0 on success, otherwise returns libnfc's error code (negative value)
|
||||
* @param pnd \a nfc_device struct pointer that represent currently used device
|
||||
* @param property \a nfc_property which will be set
|
||||
* @param bEnable boolean to activate/disactivate the property
|
||||
*
|
||||
* Configures parameters and registers that control for example timing,
|
||||
* modulation, frame and error handling. There are different categories for
|
||||
* configuring the \e PN53X chip features (handle, activate, infinite and
|
||||
* accept).
|
||||
*/
|
||||
int
|
||||
nfc_device_set_property_bool (nfc_device *pnd, const nfc_property property, const bool bEnable)
|
||||
{
|
||||
HAL (device_set_property_bool, pnd, property, bEnable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Initialize NFC device as initiator (reader)
|
||||
* @return Returns \c true if action was successfully performed; otherwise returns \c false.
|
||||
|
|
@ -246,55 +247,55 @@ nfc_device_set_property_int (nfc_device *pnd, const nfc_property property, const
|
|||
* The NFC device is configured to function as RFID reader.
|
||||
* After initialization it can be used to communicate to passive RFID tags and active NFC devices.
|
||||
* The reader will act as initiator to communicate peer 2 peer (NFCIP) to other active NFC devices.
|
||||
* - Crc is handled by the device (NDO_HANDLE_CRC = true)
|
||||
* - Parity is handled the device (NDO_HANDLE_PARITY = true)
|
||||
* - Cryto1 cipher is disabled (NDO_ACTIVATE_CRYPTO1 = false)
|
||||
* - Easy framing is enabled (NDO_EASY_FRAMING = true)
|
||||
* - Auto-switching in ISO14443-4 mode is enabled (NDO_AUTO_ISO14443_4 = true)
|
||||
* - Invalid frames are not accepted (NDO_ACCEPT_INVALID_FRAMES = false)
|
||||
* - Multiple frames are not accepted (NDO_ACCEPT_MULTIPLE_FRAMES = false)
|
||||
* - 14443-A mode is activated (NDO_FORCE_ISO14443_A = true)
|
||||
* - speed is set to 106 kbps (NDO_FORCE_SPEED_106 = true)
|
||||
* - Let the device try forever to find a target (NDO_INFINITE_SELECT = true)
|
||||
* - Crc is handled by the device (NP_HANDLE_CRC = true)
|
||||
* - Parity is handled the device (NP_HANDLE_PARITY = true)
|
||||
* - Cryto1 cipher is disabled (NP_ACTIVATE_CRYPTO1 = false)
|
||||
* - Easy framing is enabled (NP_EASY_FRAMING = true)
|
||||
* - Auto-switching in ISO14443-4 mode is enabled (NP_AUTO_ISO14443_4 = true)
|
||||
* - Invalid frames are not accepted (NP_ACCEPT_INVALID_FRAMES = false)
|
||||
* - Multiple frames are not accepted (NP_ACCEPT_MULTIPLE_FRAMES = false)
|
||||
* - 14443-A mode is activated (NP_FORCE_ISO14443_A = true)
|
||||
* - speed is set to 106 kbps (NP_FORCE_SPEED_106 = true)
|
||||
* - Let the device try forever to find a target (NP_INFINITE_SELECT = true)
|
||||
* - RF field is shortly dropped (if it was enabled) then activated again
|
||||
*/
|
||||
bool
|
||||
nfc_initiator_init (nfc_device *pnd)
|
||||
{
|
||||
// Drop the field for a while
|
||||
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, false) < 0)
|
||||
return false;
|
||||
// Enable field so more power consuming cards can power themselves up
|
||||
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, true) < 0)
|
||||
return false;
|
||||
// Let the device try forever to find a target/tag
|
||||
if (!nfc_configure (pnd, NDO_INFINITE_SELECT, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, true) < 0)
|
||||
return false;
|
||||
// Activate auto ISO14443-4 switching by default
|
||||
if (!nfc_configure (pnd, NDO_AUTO_ISO14443_4, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, true) < 0)
|
||||
return false;
|
||||
// Force 14443-A mode
|
||||
if (!nfc_configure (pnd, NDO_FORCE_ISO14443_A, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_FORCE_ISO14443_A, true) < 0)
|
||||
return false;
|
||||
// Force speed at 106kbps
|
||||
if (!nfc_configure (pnd, NDO_FORCE_SPEED_106, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_FORCE_SPEED_106, true) < 0)
|
||||
return false;
|
||||
// Disallow invalid frame
|
||||
if (!nfc_configure (pnd, NDO_ACCEPT_INVALID_FRAMES, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACCEPT_INVALID_FRAMES, false) < 0)
|
||||
return false;
|
||||
// Disallow multiple frames
|
||||
if (!nfc_configure (pnd, NDO_ACCEPT_MULTIPLE_FRAMES, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACCEPT_MULTIPLE_FRAMES, false) < 0)
|
||||
return false;
|
||||
// Make sure we reset the CRC and parity to chip handling.
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_CRC, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, true) < 0)
|
||||
return false;
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_PARITY, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_PARITY, true) < 0)
|
||||
return false;
|
||||
// Activate "easy framing" feature by default
|
||||
if (!nfc_configure (pnd, NDO_EASY_FRAMING, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, true) < 0)
|
||||
return false;
|
||||
// Deactivate the CRYPTO1 cipher, it may could cause problems when still active
|
||||
if (!nfc_configure (pnd, NDO_ACTIVATE_CRYPTO1, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACTIVATE_CRYPTO1, false) < 0)
|
||||
return false;
|
||||
|
||||
HAL (initiator_init, pnd);
|
||||
|
|
@ -373,7 +374,7 @@ nfc_initiator_list_passive_targets (nfc_device *pnd,
|
|||
pnd->iLastError = 0;
|
||||
|
||||
// Let the reader only try once to find a tag
|
||||
if (!nfc_configure (pnd, NDO_INFINITE_SELECT, false)) {
|
||||
if (nfc_device_set_property_bool (pnd, NP_INFINITE_SELECT, false) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -486,14 +487,14 @@ nfc_initiator_deselect_target (nfc_device *pnd)
|
|||
* If timeout is not a null pointer, it specifies the maximum interval to wait for the function to be executed.
|
||||
* If timeout is a null pointer, the function blocks indefinitely (until an error is raised or function is completed).
|
||||
*
|
||||
* If \a NDO_EASY_FRAMING option is disabled the frames will sent and received in raw mode: \e PN53x will not handle input neither output data.
|
||||
* If \a NP_EASY_FRAMING option is disabled the frames will sent and received in raw mode: \e PN53x will not handle input neither output data.
|
||||
*
|
||||
* The parity bits are handled by the \e PN53x chip. The CRC can be generated automatically or handled manually.
|
||||
* Using this function, frames can be communicated very fast via the NFC initiator to the tag.
|
||||
*
|
||||
* Tests show that on average this way of communicating is much faster than using the regular driver/middle-ware (often supplied by manufacturers).
|
||||
*
|
||||
* @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value).
|
||||
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
|
||||
*/
|
||||
bool
|
||||
nfc_initiator_transceive_bytes (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx,
|
||||
|
|
@ -550,7 +551,7 @@ nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size
|
|||
*
|
||||
* This function is similar to nfc_initiator_transceive_bytes() with the following differences:
|
||||
* - A precise cycles counter will indicate the number of cycles between emission & reception of frames.
|
||||
* - It only supports mode with \a NDO_EASY_FRAMING option disabled.
|
||||
* - It only supports mode with \a NP_EASY_FRAMING option disabled.
|
||||
* - Overall communication with the host is heavier and slower.
|
||||
*
|
||||
* Timer control:
|
||||
|
|
@ -561,8 +562,8 @@ nfc_initiator_transceive_bits (nfc_device *pnd, const uint8_t *pbtTx, const size
|
|||
* - If you need to count more cycles, set *cycles to the maximum you expect but don't forget
|
||||
* you'll loose in precision and it'll take more time before timeout, so don't abuse!
|
||||
*
|
||||
* @warning The configuration option \a NDO_EASY_FRAMING must be set to \c false.
|
||||
* @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value).
|
||||
* @warning The configuration option \a NP_EASY_FRAMING must be set to \c false.
|
||||
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
|
||||
*/
|
||||
bool
|
||||
nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx,
|
||||
|
|
@ -577,7 +578,7 @@ nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, con
|
|||
*
|
||||
* This function is similar to nfc_initiator_transceive_bits() with the following differences:
|
||||
* - A precise cycles counter will indicate the number of cycles between emission & reception of frames.
|
||||
* - It only supports mode with \a NDO_EASY_FRAMING option disabled and CRC must be handled manually.
|
||||
* - It only supports mode with \a NP_EASY_FRAMING option disabled and CRC must be handled manually.
|
||||
* - Overall communication with the host is heavier and slower.
|
||||
*
|
||||
* Timer control:
|
||||
|
|
@ -588,9 +589,9 @@ nfc_initiator_transceive_bytes_timed (nfc_device *pnd, const uint8_t *pbtTx, con
|
|||
* - If you need to count more cycles, set *cycles to the maximum you expect but don't forget
|
||||
* you'll loose in precision and it'll take more time before timeout, so don't abuse!
|
||||
*
|
||||
* @warning The configuration option \a NDO_EASY_FRAMING must be set to \c false.
|
||||
* @warning The configuration option \a NDO_HANDLE_CRC must be set to \c false.
|
||||
* @warning The configuration option \a NDO_HANDLE_PARITY must be set to \c true (the default value).
|
||||
* @warning The configuration option \a NP_EASY_FRAMING must be set to \c false.
|
||||
* @warning The configuration option \a NP_HANDLE_CRC must be set to \c false.
|
||||
* @warning The configuration option \a NP_HANDLE_PARITY must be set to \c true (the default value).
|
||||
*/
|
||||
bool
|
||||
nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
|
||||
|
|
@ -615,13 +616,13 @@ nfc_initiator_transceive_bits_timed (nfc_device *pnd, const uint8_t *pbtTx, cons
|
|||
*
|
||||
* This function initializes NFC device in \e target mode in order to emulate a
|
||||
* tag using the specified \a nfc_target_mode_t.
|
||||
* - Crc is handled by the device (NDO_HANDLE_CRC = true)
|
||||
* - Parity is handled the device (NDO_HANDLE_PARITY = true)
|
||||
* - Cryto1 cipher is disabled (NDO_ACTIVATE_CRYPTO1 = false)
|
||||
* - Auto-switching in ISO14443-4 mode is enabled (NDO_AUTO_ISO14443_4 = true)
|
||||
* - Easy framing is disabled (NDO_EASY_FRAMING = false)
|
||||
* - Invalid frames are not accepted (NDO_ACCEPT_INVALID_FRAMES = false)
|
||||
* - Multiple frames are not accepted (NDO_ACCEPT_MULTIPLE_FRAMES = false)
|
||||
* - Crc is handled by the device (NP_HANDLE_CRC = true)
|
||||
* - Parity is handled the device (NP_HANDLE_PARITY = true)
|
||||
* - Cryto1 cipher is disabled (NP_ACTIVATE_CRYPTO1 = false)
|
||||
* - Auto-switching in ISO14443-4 mode is enabled (NP_AUTO_ISO14443_4 = true)
|
||||
* - Easy framing is disabled (NP_EASY_FRAMING = false)
|
||||
* - Invalid frames are not accepted (NP_ACCEPT_INVALID_FRAMES = false)
|
||||
* - Multiple frames are not accepted (NP_ACCEPT_MULTIPLE_FRAMES = false)
|
||||
* - RF field is dropped
|
||||
*
|
||||
* @warning Be aware that this function will wait (hang) until a command is
|
||||
|
|
@ -633,27 +634,27 @@ bool
|
|||
nfc_target_init (nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, size_t * pszRx)
|
||||
{
|
||||
// Disallow invalid frame
|
||||
if (!nfc_configure (pnd, NDO_ACCEPT_INVALID_FRAMES, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACCEPT_INVALID_FRAMES, false) < 0)
|
||||
return false;
|
||||
// Disallow multiple frames
|
||||
if (!nfc_configure (pnd, NDO_ACCEPT_MULTIPLE_FRAMES, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACCEPT_MULTIPLE_FRAMES, false) < 0)
|
||||
return false;
|
||||
// Make sure we reset the CRC and parity to chip handling.
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_CRC, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_CRC, true) < 0)
|
||||
return false;
|
||||
if (!nfc_configure (pnd, NDO_HANDLE_PARITY, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_HANDLE_PARITY, true) < 0)
|
||||
return false;
|
||||
// Activate auto ISO14443-4 switching by default
|
||||
if (!nfc_configure (pnd, NDO_AUTO_ISO14443_4, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_AUTO_ISO14443_4, true) < 0)
|
||||
return false;
|
||||
// Activate "easy framing" feature by default
|
||||
if (!nfc_configure (pnd, NDO_EASY_FRAMING, true))
|
||||
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, true) < 0)
|
||||
return false;
|
||||
// Deactivate the CRYPTO1 cipher, it may could cause problems when still active
|
||||
if (!nfc_configure (pnd, NDO_ACTIVATE_CRYPTO1, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACTIVATE_CRYPTO1, false) < 0)
|
||||
return false;
|
||||
// Drop explicitely the field
|
||||
if (!nfc_configure (pnd, NDO_ACTIVATE_FIELD, false))
|
||||
if (nfc_device_set_property_bool (pnd, NP_ACTIVATE_FIELD, false) < 0)
|
||||
return false;
|
||||
|
||||
HAL (target_init, pnd, pnt, pbtRx, pszRx);
|
||||
|
|
@ -754,7 +755,7 @@ nfc_target_send_bits (nfc_device *pnd, const uint8_t *pbtTx, const size_t szTxBi
|
|||
* the messages that are stored in the FIFO buffer of the \e PN53x chip. It
|
||||
* does not require to send any frame and thereby could be used to snoop frames
|
||||
* that are transmitted by a nearby \e initiator. @note Check out the
|
||||
* NDO_ACCEPT_MULTIPLE_FRAMES configuration option to avoid losing transmitted
|
||||
* NP_ACCEPT_MULTIPLE_FRAMES configuration option to avoid losing transmitted
|
||||
* frames.
|
||||
*/
|
||||
bool
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue