We can now use an nfc_dep_info_t to specify DEP info as initiator.
This commit is contained in:
parent
ddb8fe9b1f
commit
602787bd03
5 changed files with 61 additions and 36 deletions
|
@ -62,7 +62,7 @@ main (int argc, const char *argv[])
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if(!nfc_initiator_select_dep_target (pnd, NM_PASSIVE_DEP, NULL, 0, NULL, 0, NULL, 0, &nti)) {
|
||||
if(!nfc_initiator_select_dep_target (pnd, NM_PASSIVE_DEP, NULL, &nti)) {
|
||||
nfc_perror(pnd, "nfc_initiator_select_dep_target");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
|
|
@ -78,9 +78,7 @@ extern "C" {
|
|||
const size_t szTargetTypes, const byte_t btPollNr, const byte_t btPeriod,
|
||||
nfc_target_t * pntTargets, size_t * pszTargetFound);
|
||||
NFC_EXPORT bool nfc_initiator_select_dep_target (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
|
||||
const byte_t * pbtPidData, const size_t szPidDataLen,
|
||||
const byte_t * pbtNFCID3i, const size_t szNFCID3iDataLen,
|
||||
const byte_t * pbtGbData, const size_t szGbDataLen,
|
||||
const nfc_dep_info_t * pndiInitiator,
|
||||
nfc_target_info_t * pti);
|
||||
NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device_t * pnd);
|
||||
NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen,
|
||||
|
|
|
@ -821,10 +821,33 @@ pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, const bool b
|
|||
}
|
||||
|
||||
bool
|
||||
pn53x_initiator_select_dep_target (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
|
||||
const byte_t * pbtPidData, const size_t szPidDataLen, const byte_t * pbtNFCID3i,
|
||||
const size_t szNFCID3iDataLen, const byte_t * pbtGbData, const size_t szGbDataLen,
|
||||
nfc_target_info_t * pnti)
|
||||
pn53x_initiator_select_dep_target(nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
|
||||
const nfc_dep_info_t * pndiInitiator,
|
||||
nfc_target_info_t * pnti)
|
||||
{
|
||||
if (pndiInitiator) {
|
||||
return pn53x_InJumpForDEP (pnd, nmInitModulation, NULL, 0, pndiInitiator->abtNFCID3, pndiInitiator->abtGB, pndiInitiator->szGB, pnti);
|
||||
} else {
|
||||
return pn53x_InJumpForDEP (pnd, nmInitModulation, NULL, 0, NULL, NULL, 0, pnti);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Wrapper for InJumpForDEP command
|
||||
* @param nmInitModulation 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 szPassiveInitiatorData size of pbtPassiveInitiatorData content
|
||||
* @param pbtNFCID3i NFCID3 of the initiator
|
||||
* @param pbtGB General Bytes
|
||||
* @param szGB count of General Bytes
|
||||
* @param[out] pnti nfc_target_info_t which will be filled by this function
|
||||
*/
|
||||
bool
|
||||
pn53x_InJumpForDEP (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
|
||||
const byte_t * pbtPassiveInitiatorData, const size_t szPassiveInitiatorData,
|
||||
const byte_t * pbtNFCID3i,
|
||||
const byte_t * pbtGB, const size_t szGB,
|
||||
nfc_target_info_t * pnti)
|
||||
{
|
||||
byte_t abtRx[MAX_FRAME_LEN];
|
||||
size_t szRxLen;
|
||||
|
@ -836,28 +859,29 @@ pn53x_initiator_select_dep_target (nfc_device_t * pnd, const nfc_modulation_t nm
|
|||
if (nmInitModulation == NM_ACTIVE_DEP) {
|
||||
abtCmd[2] = 0x01; /* active DEP */
|
||||
}
|
||||
// FIXME Baud rate in D.E.P. mode is hard-wired as 106kbps
|
||||
abtCmd[3] = 0x00; /* baud rate = 106kbps */
|
||||
|
||||
offset = 5;
|
||||
if (pbtPidData && nmInitModulation != NM_ACTIVE_DEP) { /* can't have passive initiator data when using active mode */
|
||||
if (pbtPassiveInitiatorData && (nmInitModulation != NM_ACTIVE_DEP)) { /* can't have passive initiator data when using active mode */
|
||||
abtCmd[4] |= 0x01;
|
||||
memcpy (abtCmd + offset, pbtPidData, szPidDataLen);
|
||||
offset += szPidDataLen;
|
||||
memcpy (abtCmd + offset, pbtPassiveInitiatorData, szPassiveInitiatorData);
|
||||
offset += szPassiveInitiatorData;
|
||||
}
|
||||
|
||||
if (pbtNFCID3i) {
|
||||
abtCmd[4] |= 0x02;
|
||||
memcpy (abtCmd + offset, pbtNFCID3i, szNFCID3iDataLen);
|
||||
offset += szNFCID3iDataLen;
|
||||
memcpy (abtCmd + offset, pbtNFCID3i, 10);
|
||||
offset += 10;
|
||||
}
|
||||
|
||||
if (pbtGbData) {
|
||||
if (szGB && pbtGB) {
|
||||
abtCmd[4] |= 0x04;
|
||||
memcpy (abtCmd + offset, pbtGbData, szGbDataLen);
|
||||
offset += szGbDataLen;
|
||||
memcpy (abtCmd + offset, pbtGB, szGB);
|
||||
offset += szGB;
|
||||
}
|
||||
// Try to find a target, call the transceive callback function of the current device
|
||||
if (!pn53x_transceive (pnd, abtCmd, 5 + szPidDataLen + szNFCID3iDataLen + szGbDataLen, abtRx, &szRxLen))
|
||||
if (!pn53x_transceive (pnd, abtCmd, 5 + szPassiveInitiatorData + 10 + szGB, abtRx, &szRxLen))
|
||||
return false;
|
||||
|
||||
// Make sure one target has been found, the PN53X returns 0x00 if none was available
|
||||
|
@ -873,7 +897,7 @@ pn53x_initiator_select_dep_target (nfc_device_t * pnd, const nfc_modulation_t nm
|
|||
pnti->ndi.btTO = abtRx[15];
|
||||
pnti->ndi.btPP = abtRx[16];
|
||||
if(szRxLen > 17) {
|
||||
pnti->ndi.szGB = szRxLen - 17;
|
||||
pnti->ndi.szGB = szRxLen - 17; // FIXME This computation is not applicable to all PN53x chips
|
||||
memcpy (pnti->ndi.abtGB, abtRx + 17, pnti->ndi.szGB);
|
||||
} else {
|
||||
pnti->ndi.szGB = 0;
|
||||
|
|
|
@ -110,11 +110,10 @@ bool pn53x_decode_target_data (const byte_t * pbtRawData, size_t szDataLen, n
|
|||
|
||||
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);
|
||||
|
||||
// NFC device as Initiator functions
|
||||
bool pn53x_initiator_select_dep_target (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
|
||||
const byte_t * pbtPidData, const size_t szPidDataLen,
|
||||
const byte_t * pbtNFCID3i, const size_t szNFCID3iDataLen,
|
||||
const byte_t * pbtGbData, const size_t szGbDataLen,
|
||||
const nfc_dep_info_t * pndiInitiator,
|
||||
nfc_target_info_t * pnti);
|
||||
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,
|
||||
|
@ -144,6 +143,11 @@ 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_InJumpForDEP (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation,
|
||||
const byte_t * pbtPassiveInitiatorData, const size_t szPassiveInitiatorData,
|
||||
const byte_t * pbtNFCID3i,
|
||||
const byte_t * pbtGB, const size_t szGB,
|
||||
nfc_target_info_t * pnti);
|
||||
bool pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm,
|
||||
const byte_t * pbtMifareParams,
|
||||
const byte_t * pbtFeliCaParams,
|
||||
|
|
29
libnfc/nfc.c
29
libnfc/nfc.c
|
@ -289,7 +289,7 @@ nfc_initiator_select_passive_target (nfc_device_t * pnd,
|
|||
// Make sure we are dealing with a active device
|
||||
if (!pnd->bActive)
|
||||
return false;
|
||||
// TODO Put this in a function
|
||||
// TODO Put this in a function: this part is defined by ISO14443-3 (UID and Cascade levels)
|
||||
switch (nmInitModulation) {
|
||||
case NM_ISO14443A_106:
|
||||
switch (szInitDataLen) {
|
||||
|
@ -456,26 +456,21 @@ nfc_initiator_poll_targets (nfc_device_t * pnd,
|
|||
*
|
||||
* @param pnd \a nfc_device_t struct pointer that represent currently used device
|
||||
* @param nmInitModulation desired modulation (\a NM_ACTIVE_DEP or \a NM_PASSIVE_DEP for active, respectively passive mode)
|
||||
* @param pbtPidData passive initiator data, 4 or 5 bytes long, (optional, only for \a NM_PASSIVE_DEP, can be \c NULL)
|
||||
* @param szPidDataLen size of \a pbtPidData
|
||||
* @param pbtNFCID3i the NFCID3, 10 bytes long, of the initiator (optional, can be \c NULL)
|
||||
* @param szNFCID3iDataLen size of \a pbtNFCID3i
|
||||
* @param pbtGbData generic data of the initiator, max 48 bytes long, (optional, can be \c NULL)
|
||||
* @param szGbDataLen size of \a pbtGbData
|
||||
* @param ndiInitiator \a nfc_dep_info_t struct that contains NFCID3 and General Bytes to set to the initiator device
|
||||
* @param[out] pnti is a \a nfc_target_info_t struct pointer where target information will be put.
|
||||
*
|
||||
* The NFC device will try to find an available D.E.P. target. The standards (ISO18092 and ECMA-340) describe the modulation that can be used for reader to passive communications.
|
||||
* The NFC device will try to find an available D.E.P. target. The standards
|
||||
* (ISO18092 and ECMA-340) describe the modulation that can be used for reader
|
||||
* to passive communications.
|
||||
*
|
||||
* @note \a nfc_dep_info_t will be returned when the target was acquired successfully.
|
||||
*/
|
||||
bool
|
||||
nfc_initiator_select_dep_target (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation, const byte_t * pbtPidData,
|
||||
const size_t szPidDataLen, const byte_t * pbtNFCID3i, const size_t szNFCID3iDataLen,
|
||||
const byte_t * pbtGbData, const size_t szGbDataLen, nfc_target_info_t * pnti)
|
||||
nfc_initiator_select_dep_target (nfc_device_t * pnd, const nfc_modulation_t nmInitModulation, const nfc_dep_info_t * pndiInitiator, nfc_target_info_t * pnti)
|
||||
{
|
||||
pnd->iLastError = 0;
|
||||
|
||||
return pn53x_initiator_select_dep_target (pnd, nmInitModulation, pbtPidData, szPidDataLen, pbtNFCID3i,
|
||||
szNFCID3iDataLen, pbtGbData, szGbDataLen, pnti);
|
||||
return pn53x_initiator_select_dep_target (pnd, nmInitModulation, pndiInitiator, pnti);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -483,8 +478,12 @@ nfc_initiator_select_dep_target (nfc_device_t * pnd, const nfc_modulation_t nmIn
|
|||
* @return Returns \c true if action was successfully performed; otherwise returns \c false.
|
||||
* @param pnd \a nfc_device_t struct pointer that represents currently used device
|
||||
*
|
||||
* After selecting and communicating with a passive tag, this function could be used to deactivate and release the tag.
|
||||
*This is very useful when there are multiple tags available in the field. It is possible to use the \fn nfc_initiator_select_passive_target() function to select the first available tag, test it for the available features and support, deselect it and skip to the next tag until the correct tag is found.
|
||||
* After selecting and communicating with a passive tag, this function could be
|
||||
* used to deactivate and release the tag. This is very useful when there are
|
||||
* multiple tags available in the field. It is possible to use the \fn
|
||||
* nfc_initiator_select_passive_target() function to select the first available
|
||||
* tag, test it for the available features and support, deselect it and skip to
|
||||
* the next tag until the correct tag is found.
|
||||
*/
|
||||
bool
|
||||
nfc_initiator_deselect_target (nfc_device_t * pnd)
|
||||
|
|
Loading…
Add table
Reference in a new issue