Split pn53x_target_init() into TgInitAsTarget command wrapper and the "logical" part
This commit is contained in:
parent
33e42f389a
commit
b53b623c38
2 changed files with 60 additions and 46 deletions
|
@ -910,46 +910,23 @@ pn53x_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, cons
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
pn53x_target_init (nfc_device_t * pnd, nfc_target_mode_t tm, byte_t * pbtRx, size_t * pszRxLen)
|
pn53x_target_init (nfc_device_t * pnd, nfc_target_mode_t ntm, byte_t * pbtRx, size_t * pszRxLen)
|
||||||
{
|
{
|
||||||
byte_t abtRx[MAX_FRAME_LEN];
|
|
||||||
size_t szRxLen;
|
|
||||||
// Save the current configuration settings
|
// Save the current configuration settings
|
||||||
bool bCrc = pnd->bCrc;
|
bool bCrc = pnd->bCrc;
|
||||||
bool bPar = pnd->bPar;
|
bool bPar = pnd->bPar;
|
||||||
byte_t abtCmd[sizeof (pncmd_target_init)];
|
|
||||||
|
|
||||||
memcpy (abtCmd, pncmd_target_init, sizeof (pncmd_target_init));
|
|
||||||
|
|
||||||
// Clear the target init struct, reset to all zeros
|
|
||||||
memset (abtCmd + 2, 0x00, 37);
|
|
||||||
|
|
||||||
// Store the target mode in the initialization params
|
|
||||||
abtCmd[2] = tm;
|
|
||||||
|
|
||||||
// Set ATQA (SENS_RES)
|
|
||||||
abtCmd[3] = 0x04;
|
|
||||||
abtCmd[4] = 0x00;
|
|
||||||
|
|
||||||
// Set SAK (SEL_RES)
|
|
||||||
abtCmd[8] = 0x20;
|
|
||||||
|
|
||||||
// Set UID
|
|
||||||
abtCmd[5] = 0x00;
|
|
||||||
abtCmd[6] = 0xb0;
|
|
||||||
abtCmd[7] = 0x0b;
|
|
||||||
|
|
||||||
// Configure the target corresponding to the requested mode
|
// Configure the target corresponding to the requested mode
|
||||||
switch(tm)
|
switch(ntm)
|
||||||
{
|
{
|
||||||
case NTM_PASSIVE:
|
case NTM_PASSIVE:
|
||||||
pn53x_set_parameters(pnd,0);
|
pn53x_set_parameters(pnd, 0);
|
||||||
pn53x_configure(pnd,NDO_EASY_FRAMING,false);
|
pn53x_configure(pnd, NDO_EASY_FRAMING, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NTM_DEP:
|
case NTM_DEP:
|
||||||
pn53x_set_parameters(pnd,SYMBOL_PARAM_fAutomaticATR_RES);
|
pn53x_set_parameters(pnd, SYMBOL_PARAM_fAutomaticATR_RES);
|
||||||
pn53x_configure(pnd,NDO_EASY_FRAMING,true);
|
pn53x_configure(pnd, NDO_EASY_FRAMING, true);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NTM_PICC:
|
case NTM_PICC:
|
||||||
|
@ -958,8 +935,8 @@ pn53x_target_init (nfc_device_t * pnd, nfc_target_mode_t tm, byte_t * pbtRx, siz
|
||||||
pnd->iLastError = DENOTSUP;
|
pnd->iLastError = DENOTSUP;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
pn53x_set_parameters(pnd,SYMBOL_PARAM_fISO14443_4_PICC);
|
pn53x_set_parameters(pnd, SYMBOL_PARAM_fISO14443_4_PICC);
|
||||||
pn53x_configure(pnd,NDO_EASY_FRAMING,false);
|
pn53x_configure(pnd, NDO_EASY_FRAMING, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -977,6 +954,46 @@ pn53x_target_init (nfc_device_t * pnd, nfc_target_mode_t tm, byte_t * pbtRx, siz
|
||||||
if (!pn53x_set_reg (pnd, REG_CIU_TX_AUTO, SYMBOL_INITIAL_RF_ON, 0x04))
|
if (!pn53x_set_reg (pnd, REG_CIU_TX_AUTO, SYMBOL_INITIAL_RF_ON, 0x04))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
if(!pn53x_TgInitAsTarget(pnd, ntm, pbtRx, pszRxLen)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore the CRC & parity setting to the original value (if needed)
|
||||||
|
if (!bCrc)
|
||||||
|
pn53x_configure ((nfc_device_t *) pnd, NDO_HANDLE_CRC, false);
|
||||||
|
if (!bPar)
|
||||||
|
pn53x_configure ((nfc_device_t *) pnd, NDO_HANDLE_PARITY, false);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm, byte_t * pbtRx, size_t * pszRxLen)
|
||||||
|
{
|
||||||
|
byte_t abtRx[MAX_FRAME_LEN];
|
||||||
|
size_t szRxLen;
|
||||||
|
byte_t abtCmd[sizeof (pncmd_target_init)];
|
||||||
|
|
||||||
|
memcpy (abtCmd, pncmd_target_init, sizeof (pncmd_target_init));
|
||||||
|
|
||||||
|
// Clear the target init struct, reset to all zeros
|
||||||
|
memset (abtCmd + 2, 0x00, 37);
|
||||||
|
|
||||||
|
// Store the target mode in the initialization params
|
||||||
|
abtCmd[2] = ntm;
|
||||||
|
|
||||||
|
// Set ATQA (SENS_RES)
|
||||||
|
abtCmd[3] = 0x04;
|
||||||
|
abtCmd[4] = 0x00;
|
||||||
|
|
||||||
|
// Set SAK (SEL_RES)
|
||||||
|
abtCmd[8] = 0x20;
|
||||||
|
|
||||||
|
// Set UID
|
||||||
|
abtCmd[5] = 0x00;
|
||||||
|
abtCmd[6] = 0xb0;
|
||||||
|
abtCmd[7] = 0x0b;
|
||||||
|
|
||||||
// Request the initialization as a target
|
// Request the initialization as a target
|
||||||
szRxLen = MAX_FRAME_LEN;
|
szRxLen = MAX_FRAME_LEN;
|
||||||
if (!pn53x_transceive (pnd, abtCmd, 39, abtRx, &szRxLen))
|
if (!pn53x_transceive (pnd, abtCmd, 39, abtRx, &szRxLen))
|
||||||
|
@ -988,12 +1005,6 @@ pn53x_target_init (nfc_device_t * pnd, nfc_target_mode_t tm, byte_t * pbtRx, siz
|
||||||
// Copy the received bytes
|
// Copy the received bytes
|
||||||
memcpy (pbtRx, abtRx + 1, *pszRxLen);
|
memcpy (pbtRx, abtRx + 1, *pszRxLen);
|
||||||
|
|
||||||
// Restore the CRC & parity setting to the original value (if needed)
|
|
||||||
if (!bCrc)
|
|
||||||
pn53x_configure ((nfc_device_t *) pnd, NDO_HANDLE_CRC, false);
|
|
||||||
if (!bPar)
|
|
||||||
pn53x_configure ((nfc_device_t *) pnd, NDO_HANDLE_PARITY, false);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,15 +110,6 @@ bool pn53x_unwrap_frame (const byte_t * pbtFrame, const size_t szFrameBits, b
|
||||||
bool pn53x_decode_target_data (const byte_t * pbtRawData, size_t szDataLen, nfc_chip_t nc, nfc_target_type_t ntt,
|
bool pn53x_decode_target_data (const byte_t * pbtRawData, size_t szDataLen, nfc_chip_t nc, nfc_target_type_t ntt,
|
||||||
nfc_target_info_t * pnti);
|
nfc_target_info_t * pnti);
|
||||||
|
|
||||||
bool pn53x_InListPassiveTarget (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
|
|
||||||
const byte_t szMaxTargets, const byte_t * pbtInitiatorData,
|
|
||||||
const size_t szInitiatorDataLen, byte_t * pbtTargetsData, size_t * pszTargetsData);
|
|
||||||
bool pn53x_InDeselect (nfc_device_t * pnd, const uint8_t ui8Target);
|
|
||||||
bool pn53x_InRelease (nfc_device_t * pnd, const uint8_t ui8Target);
|
|
||||||
bool pn53x_InAutoPoll (nfc_device_t * pnd, const nfc_target_type_t * pnttTargetTypes, const size_t szTargetTypes,
|
|
||||||
const byte_t btPollNr, const byte_t btPeriod, nfc_target_t * pntTargets,
|
|
||||||
size_t * pszTargetFound);
|
|
||||||
|
|
||||||
bool pn53x_get_firmware_version (nfc_device_t * pnd);
|
bool pn53x_get_firmware_version (nfc_device_t * pnd);
|
||||||
bool pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable);
|
bool pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool bEnable);
|
||||||
bool pn53x_initiator_select_dep_target (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
|
bool pn53x_initiator_select_dep_target (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
|
||||||
|
@ -145,4 +136,16 @@ static const struct chip_callbacks pn53x_callbacks_list = {
|
||||||
pn53x_strerror
|
pn53x_strerror
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// C wrappers for PN53x commands
|
||||||
|
bool pn53x_InListPassiveTarget (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
|
||||||
|
const byte_t szMaxTargets, const byte_t * pbtInitiatorData,
|
||||||
|
const size_t szInitiatorDataLen, byte_t * pbtTargetsData, size_t * pszTargetsData);
|
||||||
|
bool pn53x_InDeselect (nfc_device_t * pnd, const uint8_t ui8Target);
|
||||||
|
bool pn53x_InRelease (nfc_device_t * pnd, const uint8_t ui8Target);
|
||||||
|
bool pn53x_InAutoPoll (nfc_device_t * pnd, const nfc_target_type_t * pnttTargetTypes, const size_t szTargetTypes,
|
||||||
|
const byte_t btPollNr, const byte_t btPeriod, nfc_target_t * pntTargets,
|
||||||
|
size_t * pszTargetFound);
|
||||||
|
bool pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t tm, byte_t * pbtRx, size_t * pszRxLen);
|
||||||
|
|
||||||
|
|
||||||
#endif // __NFC_CHIPS_PN53X_H__
|
#endif // __NFC_CHIPS_PN53X_H__
|
||||||
|
|
Loading…
Add table
Reference in a new issue