Move hardware polling function in pn53x.c/h.
This commit is contained in:
parent
41b1455f04
commit
ae04479968
3 changed files with 64 additions and 51 deletions
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "pn53x.h"
|
||||
#include "../mirror-subr.h"
|
||||
|
@ -336,3 +337,61 @@ pn53x_InRelease(nfc_device_t* pnd, const uint8_t ui8Target)
|
|||
|
||||
return(pn53x_transceive(pnd,abtCmd,sizeof(abtCmd),NULL,NULL));
|
||||
}
|
||||
|
||||
bool
|
||||
pn53x_InAutoPoll(const 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)
|
||||
{
|
||||
size_t szTxInAutoPoll, n, szRxLen;
|
||||
byte_t abtRx[256];
|
||||
bool res;
|
||||
byte_t *pbtTxInAutoPoll;
|
||||
|
||||
if(pnd->nc == NC_PN531) {
|
||||
// TODO This function is not supported by pn531 (set errno = ENOSUPP or similar)
|
||||
return false;
|
||||
}
|
||||
|
||||
// InAutoPoll frame looks like this { 0xd4, 0x60, 0x0f, 0x01, 0x00 } => { direction, command, pollnr, period, types... }
|
||||
szTxInAutoPoll = 4 + szTargetTypes;
|
||||
pbtTxInAutoPoll = malloc( szTxInAutoPoll );
|
||||
pbtTxInAutoPoll[0] = 0xd4;
|
||||
pbtTxInAutoPoll[1] = 0x60;
|
||||
pbtTxInAutoPoll[2] = btPollNr;
|
||||
pbtTxInAutoPoll[3] = btPeriod;
|
||||
for(n=0; n<szTargetTypes; n++) {
|
||||
pbtTxInAutoPoll[4+n] = pnttTargetTypes[n];
|
||||
}
|
||||
|
||||
szRxLen = 256;
|
||||
res = pnd->pdc->transceive(pnd->nds, pbtTxInAutoPoll, szTxInAutoPoll, abtRx, &szRxLen);
|
||||
|
||||
if((szRxLen == 0)||(res == false)) {
|
||||
return false;
|
||||
} else {
|
||||
*pszTargetFound = abtRx[0];
|
||||
if( *pszTargetFound ) {
|
||||
uint8_t ln;
|
||||
byte_t* pbt = abtRx + 1;
|
||||
/* 1st target */
|
||||
// Target type
|
||||
pntTargets[0].ntt = *(pbt++);
|
||||
// AutoPollTargetData length
|
||||
ln = *(pbt++);
|
||||
pn53x_decode_target_data(pbt, ln, pnd->nc, pntTargets[0].ntt, &(pntTargets[0].nti));
|
||||
pbt += ln;
|
||||
|
||||
if(abtRx[0] > 1) {
|
||||
/* 2nd target */
|
||||
// Target type
|
||||
pntTargets[1].ntt = *(pbt++);
|
||||
// AutoPollTargetData length
|
||||
ln = *(pbt++);
|
||||
pn53x_decode_target_data(pbt, ln, pnd->nc, pntTargets[1].ntt, &(pntTargets[1].nti));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ bool pn53x_decode_target_data(const byte_t* pbtRawData, size_t szDataLen, nfc_ch
|
|||
bool pn53x_InListPassiveTarget(const 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(const nfc_device_t* pnd, const uint8_t ui8Target);
|
||||
bool pn53x_InRelease(nfc_device_t* pnd, const uint8_t ui8Target);
|
||||
bool pn53x_InAutoPoll(const 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);
|
||||
|
||||
#endif // __NFC_CHIPS_PN53X_H__
|
||||
|
||||
|
|
55
libnfc/nfc.c
55
libnfc/nfc.c
|
@ -438,7 +438,7 @@ nfc_initiator_select_passive_target(const nfc_device_t* pnd,
|
|||
|
||||
// Make sure we are dealing with a active device
|
||||
if (!pnd->bActive) return false;
|
||||
|
||||
// TODO Put this in a function
|
||||
switch(nmInitModulation)
|
||||
{
|
||||
case NM_ISO14443A_106:
|
||||
|
@ -485,7 +485,8 @@ nfc_initiator_select_passive_target(const nfc_device_t* pnd,
|
|||
{
|
||||
case NM_ISO14443A_106:
|
||||
if(!pn53x_decode_target_data(abtTargetsData+1, szTargetsData-1, pnd->nc, NTT_GENERIC_PASSIVE_106, pnti)) return false;
|
||||
|
||||
// TODO this should be handled by pn53x_decode_target_data()
|
||||
|
||||
// Strip CT (Cascade Tag) to retrieve and store the _real_ UID
|
||||
// (e.g. 0x8801020304050607 is in fact 0x01020304050607)
|
||||
if ((pnti->nai.szUidLen == 8) && (pnti->nai.abtUid[0] == 0x88)) {
|
||||
|
@ -651,55 +652,7 @@ nfc_initiator_poll_targets(const nfc_device_t* pnd,
|
|||
const byte_t btPollNr, const byte_t btPeriod,
|
||||
nfc_target_t* pntTargets, size_t* pszTargetFound)
|
||||
{
|
||||
size_t szTxInAutoPoll, n, szRxLen;
|
||||
byte_t abtRx[256];
|
||||
bool res;
|
||||
byte_t *pbtTxInAutoPoll;
|
||||
if(pnd->nc == NC_PN531) {
|
||||
// errno = ENOSUPP
|
||||
return false;
|
||||
}
|
||||
// byte_t abtInAutoPoll[] = { 0xd4, 0x60, 0x0f, 0x01, 0x00 };
|
||||
szTxInAutoPoll = 4 + szTargetTypes;
|
||||
pbtTxInAutoPoll = malloc( szTxInAutoPoll );
|
||||
pbtTxInAutoPoll[0] = 0xd4;
|
||||
pbtTxInAutoPoll[1] = 0x60;
|
||||
pbtTxInAutoPoll[2] = btPollNr;
|
||||
pbtTxInAutoPoll[3] = btPeriod;
|
||||
for(n=0; n<szTargetTypes; n++) {
|
||||
pbtTxInAutoPoll[4+n] = pnttTargetTypes[n];
|
||||
}
|
||||
|
||||
szRxLen = 256;
|
||||
res = pnd->pdc->transceive(pnd->nds, pbtTxInAutoPoll, szTxInAutoPoll, abtRx, &szRxLen);
|
||||
|
||||
if((szRxLen == 0)||(res == false)) {
|
||||
DBG("pnd->pdc->tranceive() failed: szRxLen=%ld, res=%d", (unsigned long) szRxLen, res);
|
||||
return false;
|
||||
} else {
|
||||
*pszTargetFound = abtRx[0];
|
||||
if( *pszTargetFound ) {
|
||||
uint8_t ln;
|
||||
byte_t* pbt = abtRx + 1;
|
||||
/* 1st target */
|
||||
// Target type
|
||||
pntTargets[0].ntt = *(pbt++);
|
||||
// AutoPollTargetData length
|
||||
ln = *(pbt++);
|
||||
pn53x_decode_target_data(pbt, ln, pnd->nc, pntTargets[0].ntt, &(pntTargets[0].nti));
|
||||
pbt += ln;
|
||||
|
||||
if(abtRx[0] > 1) {
|
||||
/* 2nd target */
|
||||
// Target type
|
||||
pntTargets[1].ntt = *(pbt++);
|
||||
// AutoPollTargetData length
|
||||
ln = *(pbt++);
|
||||
pn53x_decode_target_data(pbt, ln, pnd->nc, pntTargets[1].ntt, &(pntTargets[1].nti));
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return pn53x_InAutoPoll(pnd, pnttTargetTypes, szTargetTypes, btPollNr, btPeriod, pntTargets, pszTargetFound);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue