Replace nfc_target_info_t with nfc_target_t in API function, we now have a coherent struct to handle nfc_target_t, use it!

This commit is contained in:
Romuald Conty
2010-10-14 11:44:43 +00:00
parent 6f3fbcb6bf
commit af88da1a9c
10 changed files with 76 additions and 85 deletions

View File

@@ -482,7 +482,7 @@ bool
pn53x_initiator_select_passive_target (nfc_device_t * pnd,
const nfc_modulation_t nm,
const byte_t * pbtInitData, const size_t szInitData,
nfc_target_info_t * pnti)
nfc_target_t * pnt)
{
size_t szTargetsData;
byte_t abtTargetsData[MAX_FRAME_LEN];
@@ -496,9 +496,10 @@ pn53x_initiator_select_passive_target (nfc_device_t * pnd,
return false;
// Is a tag info struct available
if (pnti) {
if (pnt) {
pnt->nm = nm;
// Fill the tag info struct with the values corresponding to this init modulation
if (!pn53x_decode_target_data (abtTargetsData + 1, szTargetsData - 1, pnd->nc, nm.nmt, pnti)) {
if (!pn53x_decode_target_data (abtTargetsData + 1, szTargetsData - 1, pnd->nc, nm.nmt, &(pnt->nti))) {
return false;
}
}
@@ -876,12 +877,12 @@ 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_dep_mode_t ndm,
const nfc_dep_info_t * pndiInitiator,
nfc_target_info_t * pnti)
nfc_target_t * pnt)
{
if (pndiInitiator) {
return pn53x_InJumpForDEP (pnd, ndm, NULL, 0, pndiInitiator->abtNFCID3, pndiInitiator->abtGB, pndiInitiator->szGB, pnti);
return pn53x_InJumpForDEP (pnd, ndm, NULL, 0, pndiInitiator->abtNFCID3, pndiInitiator->abtGB, pndiInitiator->szGB, pnt);
} else {
return pn53x_InJumpForDEP (pnd, ndm, NULL, 0, NULL, NULL, 0, pnti);
return pn53x_InJumpForDEP (pnd, ndm, NULL, 0, NULL, NULL, 0, pnt);
}
}
@@ -893,7 +894,7 @@ pn53x_initiator_select_dep_target(nfc_device_t * pnd, const nfc_dep_mode_t ndm,
* @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
* @param[out] pnt \a nfc_target_t which will be filled by this function
*/
bool
pn53x_InJumpForDEP (nfc_device_t * pnd,
@@ -901,7 +902,7 @@ pn53x_InJumpForDEP (nfc_device_t * pnd,
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_t * pnt)
{
byte_t abtRx[MAX_FRAME_LEN];
size_t szRx;
@@ -941,19 +942,21 @@ pn53x_InJumpForDEP (nfc_device_t * pnd,
if (abtRx[1] != 1)
return false;
// Is a target info struct available
if (pnti) {
memcpy (pnti->ndi.abtNFCID3, abtRx + 2, 10);
pnti->ndi.btDID = abtRx[12];
pnti->ndi.btBS = abtRx[13];
pnti->ndi.btBR = abtRx[14];
pnti->ndi.btTO = abtRx[15];
pnti->ndi.btPP = abtRx[16];
// Is a target struct available
if (pnt) {
pnt->nm.nmt = NMT_DEP;
pnt->nm.nmt = NBR_UNDEFINED;
memcpy (pnt->nti.ndi.abtNFCID3, abtRx + 2, 10);
pnt->nti.ndi.btDID = abtRx[12];
pnt->nti.ndi.btBS = abtRx[13];
pnt->nti.ndi.btBR = abtRx[14];
pnt->nti.ndi.btTO = abtRx[15];
pnt->nti.ndi.btPP = abtRx[16];
if(szRx > 17) {
pnti->ndi.szGB = szRx - 17;
memcpy (pnti->ndi.abtGB, abtRx + 17, pnti->ndi.szGB);
pnt->nti.ndi.szGB = szRx - 17;
memcpy (pnt->nti.ndi.abtGB, abtRx + 17, pnt->nti.ndi.szGB);
} else {
pnti->ndi.szGB = 0;
pnt->nti.ndi.szGB = 0;
}
}
return true;

View File

@@ -168,9 +168,9 @@ bool pn53x_wrap_frame (const byte_t * pbtTx, const size_t szTxBits, const byt
size_t * pszFrameBits);
bool pn53x_unwrap_frame (const byte_t * pbtFrame, const size_t szFrameBits, byte_t * pbtRx, size_t * pszRxBits,
byte_t * pbtRxPar);
bool pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData, nfc_chip_t nc, nfc_modulation_type_t nmt,
bool pn53x_decode_target_data (const byte_t * pbtRawData, size_t szRawData,
nfc_chip_t nc, nfc_modulation_type_t nmt,
nfc_target_info_t * pnti);
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);
@@ -178,14 +178,14 @@ bool pn53x_configure (nfc_device_t * pnd, const nfc_device_option_t ndo, cons
bool pn53x_initiator_select_passive_target (nfc_device_t * pnd,
const nfc_modulation_t nm,
const byte_t * pbtInitData, const size_t szInitData,
nfc_target_info_t * pnti);
nfc_target_t * pnt);
bool pn53x_initiator_poll_targets (nfc_device_t * pnd,
const nfc_modulation_t * pnmModulations, const size_t szModulations,
const byte_t btPollNr, const byte_t btPeriod,
nfc_target_t * pntTargets, size_t * pszTargetFound);
bool pn53x_initiator_select_dep_target (nfc_device_t * pnd, nfc_dep_mode_t ndm,
const nfc_dep_info_t * pndiInitiator,
nfc_target_info_t * pnti);
nfc_target_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,
byte_t * pbtRxPar);
@@ -218,7 +218,7 @@ bool pn53x_InJumpForDEP (nfc_device_t * pnd, nfc_dep_mode_t ndm,
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_t * pnt);
bool pn53x_TgInitAsTarget (nfc_device_t * pnd, nfc_target_mode_t ntm,
const byte_t * pbtMifareParams,
const byte_t * pbtFeliCaParams,

View File

@@ -268,23 +268,18 @@ nfc_initiator_init (nfc_device_t * pnd)
* @param nm desired modulation
* @param pbtInitData optional initiator data used for Felica, ISO14443B, Topaz polling or to select a specific UID in ISO14443A.
* @param szInitData length of initiator data \a pbtInitData.
* @param[out] pnti \a nfc_target_info_t struct pointer which will filled if available
* @param[out] pnt \a nfc_target_t struct pointer which will filled if available
*
* The NFC device will try to find one available passive tag or emulated tag.
*
* The chip needs to know with what kind of tag it is dealing with, therefore
* the initial modulation and speed (106, 212 or 424 kbps) should be supplied.
*
* @note For every initial modulation type there is a different collection of
* information returned (in nfc_target_info_t pointer pti) They all fit in the
* data-type which is called nfc_target_info_t. This is a union which contains
* the tag information that belongs to the according initial modulation type.
*/
bool
nfc_initiator_select_passive_target (nfc_device_t * pnd,
const nfc_modulation_t nm,
const byte_t * pbtInitData, const size_t szInitData,
nfc_target_info_t * pnti)
nfc_target_t * pnt)
{
byte_t abtInit[MAX_FRAME_LEN];
size_t szInit;
@@ -326,7 +321,7 @@ nfc_initiator_select_passive_target (nfc_device_t * pnd,
break;
}
return pn53x_initiator_select_passive_target (pnd, nm, abtInit, szInit, pnti);
return pn53x_initiator_select_passive_target (pnd, nm, abtInit, szInit, pnt);
}
/**
@@ -335,8 +330,8 @@ nfc_initiator_select_passive_target (nfc_device_t * pnd,
*
* @param pnd \a nfc_device_t struct pointer that represent currently used device
* @param nm desired modulation
* @param[out] anti array of \a nfc_target_info_t that will be filled with targets info
* @param szTargets size of \a anti (will be the max targets listed)
* @param[out] ant array of \a nfc_target_t that will be filled with targets info
* @param szTargets size of \a ant (will be the max targets listed)
* @param[out] pszTargetFound pointer where target found counter will be stored
*
* The NFC device will try to find the available passive tags. Some NFC devices
@@ -345,19 +340,13 @@ nfc_initiator_select_passive_target (nfc_device_t * pnd,
* communications. The chip needs to know with what kind of tag it is dealing
* with, therefore the initial modulation and speed (106, 212 or 424 kbps)
* should be supplied.
*
* @note For every initial modulation type there is a different collection of
* information returned (in \a nfc_target_info_t array \e anti) They all fit in
* the data-type which is called nfc_target_info_t. This is a union which
* contains the tag information that belongs to the according initial
* modulation type.
*/
bool
nfc_initiator_list_passive_targets (nfc_device_t * pnd,
const nfc_modulation_t nm,
nfc_target_info_t anti[], const size_t szTargets, size_t * pszTargetFound)
nfc_target_t ant[], const size_t szTargets, size_t * pszTargetFound)
{
nfc_target_info_t nti;
nfc_target_t nt;
size_t szTargetFound = 0;
byte_t *pbtInitData = NULL;
size_t szInitDataLen = 0;
@@ -385,11 +374,11 @@ nfc_initiator_list_passive_targets (nfc_device_t * pnd,
break;
}
while (nfc_initiator_select_passive_target (pnd, nm, pbtInitData, szInitDataLen, &nti)) {
while (nfc_initiator_select_passive_target (pnd, nm, pbtInitData, szInitDataLen, &nt)) {
nfc_initiator_deselect_target (pnd);
if (szTargets > szTargetFound) {
memcpy (&(anti[szTargetFound]), &nti, sizeof (nfc_target_info_t));
memcpy (&(ant[szTargetFound]), &nt, sizeof (nfc_target_t));
} else {
break;
}
@@ -436,7 +425,7 @@ nfc_initiator_poll_targets (nfc_device_t * pnd,
* @param pnd \a nfc_device_t struct pointer that represent currently used device
* @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode)
* @param ndiInitiator pointer \a nfc_dep_info_t struct that contains \e NFCID3 and \e General \e Bytes to set to the initiator device (optionnal, can be \e NULL)
* @param[out] pnti is a \a nfc_target_info_t struct pointer where target information will be put.
* @param[out] pnt is a \a nfc_target_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
@@ -445,11 +434,11 @@ nfc_initiator_poll_targets (nfc_device_t * pnd,
* @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_dep_mode_t ndm, const nfc_dep_info_t * pndiInitiator, nfc_target_info_t * pnti)
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)
{
pnd->iLastError = 0;
return pn53x_initiator_select_dep_target (pnd, ndm, pndiInitiator, pnti);
return pn53x_initiator_select_dep_target (pnd, ndm, pndiInitiator, pnt);
}
/**