Support different baud rates for nfc_initiator_select_dep_target()
This commit is contained in:
parent
2f267f5463
commit
60c9da598a
5 changed files with 68 additions and 26 deletions
|
@ -62,7 +62,7 @@ main (int argc, const char *argv[])
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!nfc_initiator_select_dep_target (pnd, NDM_PASSIVE, NULL, &nt)) {
|
if(!nfc_initiator_select_dep_target (pnd, NDM_PASSIVE, NBR_106, NULL, &nt)) {
|
||||||
nfc_perror(pnd, "nfc_initiator_select_dep_target");
|
nfc_perror(pnd, "nfc_initiator_select_dep_target");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,8 @@ extern "C" {
|
||||||
NFC_EXPORT bool nfc_initiator_poll_targets (nfc_device_t * pnd, const nfc_modulation_t * pnmTargetTypes,
|
NFC_EXPORT bool nfc_initiator_poll_targets (nfc_device_t * pnd, const nfc_modulation_t * pnmTargetTypes,
|
||||||
const size_t szTargetTypes, const byte_t btPollNr, const byte_t btPeriod,
|
const size_t szTargetTypes, const byte_t btPollNr, const byte_t btPeriod,
|
||||||
nfc_target_t * pntTargets, size_t * pszTargetFound);
|
nfc_target_t * pntTargets, size_t * pszTargetFound);
|
||||||
NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device_t * pnd, const nfc_dep_mode_t ndm,
|
NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device_t * pnd,
|
||||||
|
const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr,
|
||||||
const nfc_dep_info_t * pndiInitiator,
|
const nfc_dep_info_t * pndiInitiator,
|
||||||
nfc_target_t * pnt);
|
nfc_target_t * pnt);
|
||||||
NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device_t * pnd);
|
NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device_t * pnd);
|
||||||
|
|
|
@ -875,33 +875,50 @@ pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool b
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
pn53x_initiator_select_dep_target(nfc_device_t * pnd, const nfc_dep_mode_t ndm,
|
pn53x_initiator_select_dep_target(nfc_device_t * pnd,
|
||||||
|
const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr,
|
||||||
const nfc_dep_info_t * pndiInitiator,
|
const nfc_dep_info_t * pndiInitiator,
|
||||||
nfc_target_t * pnt)
|
nfc_target_t * pnt)
|
||||||
{
|
{
|
||||||
|
const byte_t abtPassiveInitiatorData[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 }; // Only for 212/424 kpbs: First 4 bytes shall be set like this according to NFCIP-1, last byte is TSN (Time Slot Number)
|
||||||
|
const byte_t * pbtPassiveInitiatorData = NULL;
|
||||||
|
|
||||||
|
switch (nbr) {
|
||||||
|
case NBR_212:
|
||||||
|
case NBR_424:
|
||||||
|
// Only use this predefined bytes array when we are at 212/424kbps
|
||||||
|
pbtPassiveInitiatorData = abtPassiveInitiatorData;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Nothing to do
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (pndiInitiator) {
|
if (pndiInitiator) {
|
||||||
return pn53x_InJumpForDEP (pnd, ndm, NULL, 0, pndiInitiator->abtNFCID3, pndiInitiator->abtGB, pndiInitiator->szGB, pnt);
|
return pn53x_InJumpForDEP (pnd, ndm, nbr, pbtPassiveInitiatorData, pndiInitiator->abtNFCID3, pndiInitiator->abtGB, pndiInitiator->szGB, pnt);
|
||||||
} else {
|
} else {
|
||||||
return pn53x_InJumpForDEP (pnd, ndm, NULL, 0, NULL, NULL, 0, pnt);
|
return pn53x_InJumpForDEP (pnd, ndm, nbr, pbtPassiveInitiatorData, NULL, NULL, 0, pnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Wrapper for InJumpForDEP command
|
* @brief Wrapper for InJumpForDEP command
|
||||||
* @param pmInitModulation desired initial modulation
|
* @param pmInitModulation desired initial modulation
|
||||||
* @param pbtPassiveInitiatorData NFCID1 at 106kbps (see NFCIP-1: 11.2.1.26) or Polling Request Frame's payload at 212/424kbps (see NFCIP-1: 11.2.2.5)
|
* @param pbtPassiveInitiatorData NFCID1 (4 bytes) at 106kbps (optionnal, see NFCIP-1: 11.2.1.26) or Polling Request Frame's payload (5 bytes) at 212/424kbps (mandatory, see NFCIP-1: 11.2.2.5)
|
||||||
* @param szPassiveInitiatorData size of pbtPassiveInitiatorData content
|
* @param szPassiveInitiatorData size of pbtPassiveInitiatorData content
|
||||||
* @param pbtNFCID3i NFCID3 of the initiator
|
* @param pbtNFCID3i NFCID3 of the initiator
|
||||||
* @param pbtGB General Bytes
|
* @param pbtGBi General Bytes of the initiator
|
||||||
* @param szGB count of General Bytes
|
* @param szGBi count of General Bytes
|
||||||
* @param[out] pnt \a nfc_target_t which will be filled by this function
|
* @param[out] pnt \a nfc_target_t which will be filled by this function
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
pn53x_InJumpForDEP (nfc_device_t * pnd,
|
pn53x_InJumpForDEP (nfc_device_t * pnd,
|
||||||
const nfc_dep_mode_t ndm,
|
const nfc_dep_mode_t ndm,
|
||||||
const byte_t * pbtPassiveInitiatorData, const size_t szPassiveInitiatorData,
|
const nfc_baud_rate_t nbr,
|
||||||
|
const byte_t * pbtPassiveInitiatorData,
|
||||||
const byte_t * pbtNFCID3i,
|
const byte_t * pbtNFCID3i,
|
||||||
const byte_t * pbtGB, const size_t szGB,
|
const byte_t * pbtGBi, const size_t szGBi,
|
||||||
nfc_target_t * pnt)
|
nfc_target_t * pnt)
|
||||||
{
|
{
|
||||||
byte_t abtRx[MAX_FRAME_LEN];
|
byte_t abtRx[MAX_FRAME_LEN];
|
||||||
|
@ -911,16 +928,36 @@ pn53x_InJumpForDEP (nfc_device_t * pnd,
|
||||||
|
|
||||||
memcpy (abtCmd, pncmd_initiator_jump_for_dep, sizeof (pncmd_initiator_jump_for_dep));
|
memcpy (abtCmd, pncmd_initiator_jump_for_dep, sizeof (pncmd_initiator_jump_for_dep));
|
||||||
|
|
||||||
|
offset = 5; // 2 bytes for command, 1 byte for DEP mode (Active/Passive), 1 byte for baud rate, 1 byte for following parameters flag
|
||||||
abtCmd[2] = (ndm == NDM_ACTIVE) ? 0x01 : 0x00;
|
abtCmd[2] = (ndm == NDM_ACTIVE) ? 0x01 : 0x00;
|
||||||
|
|
||||||
// FIXME Baud rate in D.E.P. mode is hard-wired as 106kbps
|
// FIXME Baud rate in D.E.P. mode is hard-wired as 106kbps
|
||||||
abtCmd[3] = 0x00; /* baud rate = 106kbps */
|
switch (nbr) {
|
||||||
|
case NBR_106:
|
||||||
|
abtCmd[3] = 0x00; // baud rate is 106 kbps
|
||||||
|
break;
|
||||||
|
case NBR_212:
|
||||||
|
abtCmd[3] = 0x01; // baud rate is 212 kbps
|
||||||
|
break;
|
||||||
|
case NBR_424:
|
||||||
|
abtCmd[3] = 0x02; // baud rate is 424 kbps
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
offset = 5;
|
|
||||||
if (pbtPassiveInitiatorData && (ndm == NDM_PASSIVE)) { /* can't have passive initiator data when using active mode */
|
if (pbtPassiveInitiatorData && (ndm == NDM_PASSIVE)) { /* can't have passive initiator data when using active mode */
|
||||||
abtCmd[4] |= 0x01;
|
switch (nbr) {
|
||||||
memcpy (abtCmd + offset, pbtPassiveInitiatorData, szPassiveInitiatorData);
|
case NBR_106:
|
||||||
offset += szPassiveInitiatorData;
|
abtCmd[4] |= 0x01;
|
||||||
|
memcpy (abtCmd + offset, pbtPassiveInitiatorData, 4);
|
||||||
|
offset += 4;
|
||||||
|
break;
|
||||||
|
case NBR_212:
|
||||||
|
case NBR_424:
|
||||||
|
abtCmd[4] |= 0x01;
|
||||||
|
memcpy (abtCmd + offset, pbtPassiveInitiatorData, 5);
|
||||||
|
offset += 5;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pbtNFCID3i) {
|
if (pbtNFCID3i) {
|
||||||
|
@ -929,13 +966,13 @@ pn53x_InJumpForDEP (nfc_device_t * pnd,
|
||||||
offset += 10;
|
offset += 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (szGB && pbtGB) {
|
if (szGBi && pbtGBi) {
|
||||||
abtCmd[4] |= 0x04;
|
abtCmd[4] |= 0x04;
|
||||||
memcpy (abtCmd + offset, pbtGB, szGB);
|
memcpy (abtCmd + offset, pbtGBi, szGBi);
|
||||||
offset += szGB;
|
offset += szGBi;
|
||||||
}
|
}
|
||||||
// Try to find a target, call the transceive callback function of the current device
|
// Try to find a target, call the transceive callback function of the current device
|
||||||
if (!pn53x_transceive (pnd, abtCmd, 5 + szPassiveInitiatorData + 10 + szGB, abtRx, &szRx))
|
if (!pn53x_transceive (pnd, abtCmd, offset, abtRx, &szRx))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Make sure one target has been found, the PN53X returns 0x00 if none was available
|
// Make sure one target has been found, the PN53X returns 0x00 if none was available
|
||||||
|
@ -945,7 +982,7 @@ pn53x_InJumpForDEP (nfc_device_t * pnd,
|
||||||
// Is a target struct available
|
// Is a target struct available
|
||||||
if (pnt) {
|
if (pnt) {
|
||||||
pnt->nm.nmt = NMT_DEP;
|
pnt->nm.nmt = NMT_DEP;
|
||||||
pnt->nm.nmt = NBR_UNDEFINED;
|
pnt->nm.nbr = nbr;
|
||||||
memcpy (pnt->nti.ndi.abtNFCID3, abtRx + 2, 10);
|
memcpy (pnt->nti.ndi.abtNFCID3, abtRx + 2, 10);
|
||||||
pnt->nti.ndi.btDID = abtRx[12];
|
pnt->nti.ndi.btDID = abtRx[12];
|
||||||
pnt->nti.ndi.btBS = abtRx[13];
|
pnt->nti.ndi.btBS = abtRx[13];
|
||||||
|
|
|
@ -183,9 +183,10 @@ bool pn53x_initiator_poll_targets (nfc_device_t * pnd,
|
||||||
const nfc_modulation_t * pnmModulations, const size_t szModulations,
|
const nfc_modulation_t * pnmModulations, const size_t szModulations,
|
||||||
const byte_t btPollNr, const byte_t btPeriod,
|
const byte_t btPollNr, const byte_t btPeriod,
|
||||||
nfc_target_t * pntTargets, size_t * pszTargetFound);
|
nfc_target_t * pntTargets, size_t * pszTargetFound);
|
||||||
bool pn53x_initiator_select_dep_target (nfc_device_t * pnd, nfc_dep_mode_t ndm,
|
bool pn53x_initiator_select_dep_target (nfc_device_t * pnd,
|
||||||
|
const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr,
|
||||||
const nfc_dep_info_t * pndiInitiator,
|
const nfc_dep_info_t * pndiInitiator,
|
||||||
nfc_target_t * pnti);
|
nfc_target_t * pnt);
|
||||||
bool pn53x_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits,
|
bool pn53x_initiator_transceive_bits (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxBits,
|
||||||
const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits,
|
const byte_t * pbtTxPar, byte_t * pbtRx, size_t * pszRxBits,
|
||||||
byte_t * pbtRxPar);
|
byte_t * pbtRxPar);
|
||||||
|
@ -214,8 +215,9 @@ bool pn53x_InRelease (nfc_device_t * pnd, const uint8_t ui8Target);
|
||||||
bool pn53x_InAutoPoll (nfc_device_t * pnd, const pn53x_target_type_t * ppttTargetTypes, const size_t szTargetTypes,
|
bool pn53x_InAutoPoll (nfc_device_t * pnd, const pn53x_target_type_t * ppttTargetTypes, const size_t szTargetTypes,
|
||||||
const byte_t btPollNr, const byte_t btPeriod, nfc_target_t * pntTargets,
|
const byte_t btPollNr, const byte_t btPeriod, nfc_target_t * pntTargets,
|
||||||
size_t * pszTargetFound);
|
size_t * pszTargetFound);
|
||||||
bool pn53x_InJumpForDEP (nfc_device_t * pnd, nfc_dep_mode_t ndm,
|
bool pn53x_InJumpForDEP (nfc_device_t * pnd,
|
||||||
const byte_t * pbtPassiveInitiatorData, const size_t szPassiveInitiatorData,
|
const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr,
|
||||||
|
const byte_t * pbtPassiveInitiatorData,
|
||||||
const byte_t * pbtNFCID3i,
|
const byte_t * pbtNFCID3i,
|
||||||
const byte_t * pbtGB, const size_t szGB,
|
const byte_t * pbtGB, const size_t szGB,
|
||||||
nfc_target_t * pnt);
|
nfc_target_t * pnt);
|
||||||
|
|
|
@ -434,11 +434,13 @@ nfc_initiator_poll_targets (nfc_device_t * pnd,
|
||||||
* @note \a nfc_dep_info_t will be returned when the target was acquired successfully.
|
* @note \a nfc_dep_info_t will be returned when the target was acquired successfully.
|
||||||
*/
|
*/
|
||||||
bool
|
bool
|
||||||
nfc_initiator_select_dep_target (nfc_device_t * pnd, const nfc_dep_mode_t ndm, const nfc_dep_info_t * pndiInitiator, nfc_target_t * pnt)
|
nfc_initiator_select_dep_target (nfc_device_t * pnd,
|
||||||
|
const nfc_dep_mode_t ndm, const nfc_baud_rate_t nbr,
|
||||||
|
const nfc_dep_info_t * pndiInitiator, nfc_target_t * pnt)
|
||||||
{
|
{
|
||||||
pnd->iLastError = 0;
|
pnd->iLastError = 0;
|
||||||
|
|
||||||
return pn53x_initiator_select_dep_target (pnd, ndm, pndiInitiator, pnt);
|
return pn53x_initiator_select_dep_target (pnd, ndm, nbr, pndiInitiator, pnt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue