We can now use an nfc_dep_info_t to specify DEP info as initiator.

This commit is contained in:
Romuald Conty 2010-10-11 14:49:08 +00:00
parent ddb8fe9b1f
commit 602787bd03
5 changed files with 61 additions and 36 deletions

View file

@ -62,7 +62,7 @@ main (int argc, const char *argv[])
return EXIT_FAILURE; 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"); nfc_perror(pnd, "nfc_initiator_select_dep_target");
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View file

@ -78,9 +78,7 @@ extern "C" {
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_modulation_t nmInitModulation, 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 nfc_dep_info_t * pndiInitiator,
const byte_t * pbtNFCID3i, const size_t szNFCID3iDataLen,
const byte_t * pbtGbData, const size_t szGbDataLen,
nfc_target_info_t * pti); nfc_target_info_t * pti);
NFC_EXPORT bool nfc_initiator_deselect_target (nfc_device_t * pnd); 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, NFC_EXPORT bool nfc_initiator_transceive_bytes (nfc_device_t * pnd, const byte_t * pbtTx, const size_t szTxLen,

View file

@ -822,8 +822,31 @@ 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_modulation_t nmInitModulation, 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 nfc_dep_info_t * pndiInitiator,
const size_t szNFCID3iDataLen, const byte_t * pbtGbData, const size_t szGbDataLen, 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) nfc_target_info_t * pnti)
{ {
byte_t abtRx[MAX_FRAME_LEN]; byte_t abtRx[MAX_FRAME_LEN];
@ -836,28 +859,29 @@ pn53x_initiator_select_dep_target (nfc_device_t * pnd, const nfc_modulation_t nm
if (nmInitModulation == NM_ACTIVE_DEP) { if (nmInitModulation == NM_ACTIVE_DEP) {
abtCmd[2] = 0x01; /* 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 */ abtCmd[3] = 0x00; /* baud rate = 106kbps */
offset = 5; 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; abtCmd[4] |= 0x01;
memcpy (abtCmd + offset, pbtPidData, szPidDataLen); memcpy (abtCmd + offset, pbtPassiveInitiatorData, szPassiveInitiatorData);
offset += szPidDataLen; offset += szPassiveInitiatorData;
} }
if (pbtNFCID3i) { if (pbtNFCID3i) {
abtCmd[4] |= 0x02; abtCmd[4] |= 0x02;
memcpy (abtCmd + offset, pbtNFCID3i, szNFCID3iDataLen); memcpy (abtCmd + offset, pbtNFCID3i, 10);
offset += szNFCID3iDataLen; offset += 10;
} }
if (pbtGbData) { if (szGB && pbtGB) {
abtCmd[4] |= 0x04; abtCmd[4] |= 0x04;
memcpy (abtCmd + offset, pbtGbData, szGbDataLen); memcpy (abtCmd + offset, pbtGB, szGB);
offset += szGbDataLen; offset += szGB;
} }
// 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 + szPidDataLen + szNFCID3iDataLen + szGbDataLen, abtRx, &szRxLen)) if (!pn53x_transceive (pnd, abtCmd, 5 + szPassiveInitiatorData + 10 + szGB, abtRx, &szRxLen))
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
@ -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.btTO = abtRx[15];
pnti->ndi.btPP = abtRx[16]; pnti->ndi.btPP = abtRx[16];
if(szRxLen > 17) { 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); memcpy (pnti->ndi.abtGB, abtRx + 17, pnti->ndi.szGB);
} else { } else {
pnti->ndi.szGB = 0; pnti->ndi.szGB = 0;

View file

@ -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_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);
// NFC device as Initiator functions // NFC device as Initiator functions
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,
const byte_t * pbtPidData, const size_t szPidDataLen, const nfc_dep_info_t * pndiInitiator,
const byte_t * pbtNFCID3i, const size_t szNFCID3iDataLen,
const byte_t * pbtGbData, const size_t szGbDataLen,
nfc_target_info_t * pnti); nfc_target_info_t * pnti);
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,
@ -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, 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, 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, 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, bool pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm,
const byte_t * pbtMifareParams, const byte_t * pbtMifareParams,
const byte_t * pbtFeliCaParams, const byte_t * pbtFeliCaParams,

View file

@ -289,7 +289,7 @@ nfc_initiator_select_passive_target (nfc_device_t * pnd,
// Make sure we are dealing with a active device // Make sure we are dealing with a active device
if (!pnd->bActive) if (!pnd->bActive)
return false; 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) { switch (nmInitModulation) {
case NM_ISO14443A_106: case NM_ISO14443A_106:
switch (szInitDataLen) { 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 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 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 ndiInitiator \a nfc_dep_info_t struct that contains NFCID3 and General Bytes to set to the initiator device
* @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[out] pnti is a \a nfc_target_info_t struct pointer where target information will be put. * @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. * @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_modulation_t nmInitModulation, const byte_t * pbtPidData, 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)
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)
{ {
pnd->iLastError = 0; pnd->iLastError = 0;
return pn53x_initiator_select_dep_target (pnd, nmInitModulation, pbtPidData, szPidDataLen, pbtNFCID3i, return pn53x_initiator_select_dep_target (pnd, nmInitModulation, pndiInitiator, pnti);
szNFCID3iDataLen, pbtGbData, szGbDataLen, 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. * @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 * @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. * After selecting and communicating with a passive tag, this function could be
*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. * 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 bool
nfc_initiator_deselect_target (nfc_device_t * pnd) nfc_initiator_deselect_target (nfc_device_t * pnd)