master moved from 71eda315c70c to 827d9792dd13
5 new revisions:
Revision: 81e1dd715d1d
Author: Philippe Teuwen <
yob...@gmail.com>
Date: Fri Jan 31 22:19:04 2014 UTC
Log: nfc_initiator_target_is_present(): Fix error type in case no
target is...
http://code.google.com/p/libnfc/source/detail?r=81e1dd715d1d
Revision: e11c5254af89
Author: Philippe Teuwen <
yob...@gmail.com>
Date: Fri Jan 31 22:53:29 2014 UTC
Log: nfc_initiator_select_passive_target(): save current target info
also f...
http://code.google.com/p/libnfc/source/detail?r=e11c5254af89
Revision: 510228b6e08d
Author: Philippe Teuwen <
yob...@gmail.com>
Date: Fri Jan 31 23:56:08 2014 UTC
Log: nfc_initiator_select_passive_target(): save current target info
even i...
http://code.google.com/p/libnfc/source/detail?r=510228b6e08d
Revision: 69c4d0768a97
Author: Philippe Teuwen <
yob...@gmail.com>
Date: Sat Feb 1 01:01:10 2014 UTC
Log: nfc_initiator_select_passive_target(): grant NP_INFINITE_SELECT
also f...
http://code.google.com/p/libnfc/source/detail?r=69c4d0768a97
Revision: 827d9792dd13
Author: Philippe Teuwen <
yob...@gmail.com>
Date: Sat Feb 1 01:32:57 2014 UTC
Log: Save & restore NP_INFINITE_SELECT status when changing it
internally
http://code.google.com/p/libnfc/source/detail?r=827d9792dd13
==============================================================================
Revision: 81e1dd715d1d
Author: Philippe Teuwen <
yob...@gmail.com>
Date: Fri Jan 31 22:19:04 2014 UTC
Log: nfc_initiator_target_is_present(): Fix error type in case no
target is selected yet
http://code.google.com/p/libnfc/source/detail?r=81e1dd715d1d
Modified:
/libnfc/chips/pn53x.c
=======================================
--- /libnfc/chips/pn53x.c Fri Jan 31 21:33:05 2014 UTC
+++ /libnfc/chips/pn53x.c Fri Jan 31 22:19:04 2014 UTC
@@ -1893,7 +1893,7 @@
// only if pnt is provided but it's not intuitive that
// nfc_initiator_select_passive_target(pnt=NULL) +
target_is_present(pnt=NULL) fails
// Maybe we should have an internal copy of nt, no matter if a pnt was
provided
- return pnd->last_error = NFC_ETGRELEASED;
+ return pnd->last_error = NFC_EINVARG;
}
// Check if the argument target nt is equals to current saved target
==============================================================================
Revision: e11c5254af89
Author: Philippe Teuwen <
yob...@gmail.com>
Date: Fri Jan 31 22:53:29 2014 UTC
Log: nfc_initiator_select_passive_target(): save current target info
also for ISO14443B*
http://code.google.com/p/libnfc/source/detail?r=e11c5254af89
Modified:
/libnfc/chips/pn53x.c
=======================================
--- /libnfc/chips/pn53x.c Fri Jan 31 22:19:04 2014 UTC
+++ /libnfc/chips/pn53x.c Fri Jan 31 22:53:29 2014 UTC
@@ -1127,6 +1127,10 @@
if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData,
CHIP_DATA(pnd)->type, nm.nmt, &(pnt->nti))) < 0) {
return res;
}
+ if (pn53x_current_target_new(pnd, pnt) == NULL) {
+ pnd->last_error = NFC_ESOFT;
+ return pnd->last_error;
+ }
}
if (nm.nmt == NMT_ISO14443BI) {
// Select tag
==============================================================================
Revision: 510228b6e08d
Author: Philippe Teuwen <
yob...@gmail.com>
Date: Fri Jan 31 23:56:08 2014 UTC
Log: nfc_initiator_select_passive_target(): save current target info
even if pnt=NULL
http://code.google.com/p/libnfc/source/detail?r=510228b6e08d
Modified:
/libnfc/chips/pn53x.c
=======================================
--- /libnfc/chips/pn53x.c Fri Jan 31 22:53:29 2014 UTC
+++ /libnfc/chips/pn53x.c Fri Jan 31 23:56:08 2014 UTC
@@ -1066,6 +1066,7 @@
uint8_t abtTargetsData[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
size_t szTargetsData = sizeof(abtTargetsData);
int res = 0;
+ nfc_target nttmp;
if (nm.nmt == NMT_ISO14443BI || nm.nmt == NMT_ISO14443B2SR || nm.nmt ==
NMT_ISO14443B2CT) {
if (CHIP_DATA(pnd)->type == RCS360) {
@@ -1121,16 +1122,9 @@
}
szTargetsData = 6; // u16 UID_LSB, u8 prod code, u8 fab code, u16
UID_MSB
}
- if (pnt) {
- pnt->nm = nm;
- // Fill the tag info struct with the values corresponding to this
init modulation
- if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData,
CHIP_DATA(pnd)->type, nm.nmt, &(pnt->nti))) < 0) {
- return res;
- }
- if (pn53x_current_target_new(pnd, pnt) == NULL) {
- pnd->last_error = NFC_ESOFT;
- return pnd->last_error;
- }
+ nttmp.nm = nm;
+ if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData,
CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) {
+ return res;
}
if (nm.nmt == NMT_ISO14443BI) {
// Select tag
@@ -1142,32 +1136,32 @@
}
szTargetsData = (size_t)res;
}
- return abtTargetsData[0];
- } // else:
+ } else {
- const pn53x_modulation pm = pn53x_nm_to_pm(nm);
- if (PM_UNDEFINED == pm) {
- pnd->last_error = NFC_EINVARG;
- return pnd->last_error;
- }
+ const pn53x_modulation pm = pn53x_nm_to_pm(nm);
+ if (PM_UNDEFINED == pm) {
+ pnd->last_error = NFC_EINVARG;
+ return pnd->last_error;
+ }
- if ((res = pn53x_InListPassiveTarget(pnd, pm, 1, pbtInitData,
szInitData, abtTargetsData, &szTargetsData, timeout)) <= 0)
- return res;
+ if ((res = pn53x_InListPassiveTarget(pnd, pm, 1, pbtInitData,
szInitData, abtTargetsData, &szTargetsData, timeout)) <= 0)
+ return res;
- if (szTargetsData <= 1) // For Coverity to know szTargetsData is always
> 1 if res > 0
- return 0;
+ if (szTargetsData <= 1) // For Coverity to know szTargetsData is
always > 1 if res > 0
+ return 0;
+ nttmp.nm = nm;
+ if ((res = pn53x_decode_target_data(abtTargetsData + 1, szTargetsData
- 1, CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) {
+ return res;
+ }
+ }
+ if (pn53x_current_target_new(pnd, &nttmp) == NULL) {
+ pnd->last_error = NFC_ESOFT;
+ return pnd->last_error;
+ }
// Is a tag info struct available
if (pnt) {
- pnt->nm = nm;
- // Fill the tag info struct with the values corresponding to this init
modulation
- if ((res = pn53x_decode_target_data(abtTargetsData + 1, szTargetsData
- 1, CHIP_DATA(pnd)->type, nm.nmt, &(pnt->nti))) < 0) {
- return res;
- }
- if (pn53x_current_target_new(pnd, pnt) == NULL) {
- pnd->last_error = NFC_ESOFT;
- return pnd->last_error;
- }
+ memcpy(pnt, &nttmp, sizeof(nfc_target));
}
return abtTargetsData[0];
}
@@ -1893,10 +1887,6 @@
// Check if there is a saved target
if (CHIP_DATA(pnd)->current_target == NULL) {
log_put(LOG_GROUP, LOG_CATEGORY,
NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): no saved target");
-// TODO pnt is optional for select_passive_target() and internal nt struct
is saved
-// only if pnt is provided but it's not intuitive that
-// nfc_initiator_select_passive_target(pnt=NULL) +
target_is_present(pnt=NULL) fails
-// Maybe we should have an internal copy of nt, no matter if a pnt was
provided
return pnd->last_error = NFC_EINVARG;
}
==============================================================================
Revision: 69c4d0768a97
Author: Philippe Teuwen <
yob...@gmail.com>
Date: Sat Feb 1 01:01:10 2014 UTC
Log: nfc_initiator_select_passive_target(): grant NP_INFINITE_SELECT
also for ISO14443B*
http://code.google.com/p/libnfc/source/detail?r=69c4d0768a97
Modified:
/libnfc/chips/pn53x.c
/libnfc/nfc-device.c
/libnfc/nfc-internal.h
=======================================
--- /libnfc/chips/pn53x.c Fri Jan 31 23:56:08 2014 UTC
+++ /libnfc/chips/pn53x.c Sat Feb 1 01:01:10 2014 UTC
@@ -895,6 +895,7 @@
// TODO Made some research around this point:
// timings could be tweak better than this, and maybe we can tweak
timings
// to "gain" a sort-of hardware polling (ie. like PN532 does)
+ pnd->bInfiniteSelect = bEnable;
return pn53x_RFConfiguration__MaxRetries(pnd,
(bEnable) ? 0xff :
0x00, // MxRtyATR, default: active = 0xff, passive = 0x02
(bEnable) ? 0xff :
0x01, // MxRtyPSL, default: 0x01
@@ -1084,58 +1085,77 @@
if ((res = nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, true)) <
0) {
return res;
}
- pnd->bEasyFraming = false;
- if (nm.nmt == NMT_ISO14443B2SR) {
- // Some work to do before getting the UID...
- uint8_t abtInitiate[] = "\x06\x00";
- size_t szInitiateLen = 2;
- uint8_t abtSelect[] = { 0x0e, 0x00 };
- uint8_t abtRx[1];
- // Getting random Chip_ID
- if ((res = pn53x_initiator_transceive_bytes(pnd, abtInitiate,
szInitiateLen, abtRx, sizeof(abtRx), timeout)) < 0) {
- return res;
+ if ((res = nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, false))
< 0) {
+ return res;
+ }
+ bool found = false;
+ do {
+ if (nm.nmt == NMT_ISO14443B2SR) {
+ // Some work to do before getting the UID...
+ uint8_t abtInitiate[] = "\x06\x00";
+ size_t szInitiateLen = 2;
+ uint8_t abtSelect[] = { 0x0e, 0x00 };
+ uint8_t abtRx[1];
+ // Getting random Chip_ID
+ if ((res = pn53x_initiator_transceive_bytes(pnd, abtInitiate,
szInitiateLen, abtRx, sizeof(abtRx), timeout)) < 0) {
+ if ((res == NFC_ERFTRANS) && (CHIP_DATA(pnd)->last_status_byte
== 0x01)) { // Chip timeout
+ continue;
+ } else
+ return res;
+ }
+ abtSelect[1] = abtRx[0];
+ if ((res = pn53x_initiator_transceive_bytes(pnd, abtSelect,
sizeof(abtSelect), abtRx, sizeof(abtRx), timeout)) < 0) {
+ return res;
+ }
+ szTargetsData = (size_t)res;
+ } else if (nm.nmt == NMT_ISO14443B2CT) {
+ // Some work to do before getting the UID...
+ const uint8_t abtReqt[] = { 0x10 };
+ // Getting product code / fab code & store it in output buffer
after the serial nr we'll obtain later
+ if ((res = pn53x_initiator_transceive_bytes(pnd, abtReqt,
sizeof(abtReqt), abtTargetsData + 2, sizeof(abtTargetsData) - 2, timeout))
< 0) {
+ if ((res == NFC_ERFTRANS) && (CHIP_DATA(pnd)->last_status_byte
== 0x01)) { // Chip timeout
+ continue;
+ } else
+ return res;
+ }
+ szTargetsData = (size_t)res;
}
- abtSelect[1] = abtRx[0];
- if ((res = pn53x_initiator_transceive_bytes(pnd, abtSelect,
sizeof(abtSelect), abtRx, sizeof(abtRx), timeout)) < 0) {
- return res;
+
+ if ((res = pn53x_initiator_transceive_bytes(pnd, pbtInitData,
szInitData, abtTargetsData, sizeof(abtTargetsData), timeout)) < 0) {
+ if ((res == NFC_ERFTRANS) && (CHIP_DATA(pnd)->last_status_byte ==
0x01)) { // Chip timeout
+ continue;
+ } else
+ return res;
}
szTargetsData = (size_t)res;
- } else if (nm.nmt == NMT_ISO14443B2CT) {
- // Some work to do before getting the UID...
- const uint8_t abtReqt[] = { 0x10 };
- // Getting product code / fab code & store it in output buffer after
the serial nr we'll obtain later
- if ((res = pn53x_initiator_transceive_bytes(pnd, abtReqt,
sizeof(abtReqt), abtTargetsData + 2, sizeof(abtTargetsData) - 2, timeout))
< 0) {
- return res;
+ if (nm.nmt == NMT_ISO14443B2CT) {
+ if (szTargetsData != 2)
+ return 0; // Target is not ISO14443B2CT
+ uint8_t abtRead[] = { 0xC4 }; // Reading UID_MSB (Read address 4)
+ if ((res = pn53x_initiator_transceive_bytes(pnd, abtRead,
sizeof(abtRead), abtTargetsData + 4, sizeof(abtTargetsData) - 4, timeout))
< 0) {
+ return res;
+ }
+ szTargetsData = 6; // u16 UID_LSB, u8 prod code, u8 fab code, u16
UID_MSB
}
- szTargetsData = (size_t)res;
- }
- if ((res = pn53x_initiator_transceive_bytes(pnd, pbtInitData,
szInitData, abtTargetsData, sizeof(abtTargetsData), timeout)) < 0) {
- return res;
- }
- szTargetsData = (size_t)res;
- if (nm.nmt == NMT_ISO14443B2CT) {
- if (szTargetsData != 2)
- return 0; // Target is not ISO14443B2CT
- uint8_t abtRead[] = { 0xC4 }; // Reading UID_MSB (Read address 4)
- if ((res = pn53x_initiator_transceive_bytes(pnd, abtRead,
sizeof(abtRead), abtTargetsData + 4, sizeof(abtTargetsData) - 4, timeout))
< 0) {
+ nttmp.nm = nm;
+ if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData,
CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) {
return res;
}
- szTargetsData = 6; // u16 UID_LSB, u8 prod code, u8 fab code, u16
UID_MSB
- }
- nttmp.nm = nm;
- if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData,
CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) {
- return res;
- }
- if (nm.nmt == NMT_ISO14443BI) {
- // Select tag
- uint8_t abtAttrib[6];
- memcpy(abtAttrib, abtTargetsData, sizeof(abtAttrib));
- abtAttrib[1] = 0x0f; // ATTRIB
- if ((res = pn53x_initiator_transceive_bytes(pnd, abtAttrib,
sizeof(abtAttrib), NULL, 0, timeout)) < 0) {
- return res;
+ if (nm.nmt == NMT_ISO14443BI) {
+ // Select tag
+ uint8_t abtAttrib[6];
+ memcpy(abtAttrib, abtTargetsData, sizeof(abtAttrib));
+ abtAttrib[1] = 0x0f; // ATTRIB
+ if ((res = pn53x_initiator_transceive_bytes(pnd, abtAttrib,
sizeof(abtAttrib), NULL, 0, timeout)) < 0) {
+ return res;
+ }
+ szTargetsData = (size_t)res;
}
- szTargetsData = (size_t)res;
- }
+ found = true;
+ break;
+ } while (pnd->bInfiniteSelect);
+ if (! found)
+ return 0;
} else {
const pn53x_modulation pm = pn53x_nm_to_pm(nm);
=======================================
--- /libnfc/nfc-device.c Wed Jul 17 11:57:56 2013 UTC
+++ /libnfc/nfc-device.c Sat Feb 1 01:01:10 2014 UTC
@@ -57,6 +57,7 @@
res->bCrc = false;
res->bPar = false;
res->bEasyFraming = false;
+ res->bInfiniteSelect = false;
res->bAutoIso14443_4 = false;
res->last_error = 0;
memcpy(res->connstring, connstring, sizeof(res->connstring));
=======================================
--- /libnfc/nfc-internal.h Wed Jul 17 11:57:56 2013 UTC
+++ /libnfc/nfc-internal.h Sat Feb 1 01:01:10 2014 UTC
@@ -203,6 +203,8 @@
bool bPar;
/** Should the chip handle frames encapsulation and chaining */
bool bEasyFraming;
+ /** Should the chip try forever on select? */
+ bool bInfiniteSelect;
/** Should the chip switch automatically activate ISO14443-4 when
selecting tags supporting it? */
bool bAutoIso14443_4;
==============================================================================
Revision: 827d9792dd13
Author: Philippe Teuwen <
yob...@gmail.com>
Date: Sat Feb 1 01:32:57 2014 UTC
Log: Save & restore NP_INFINITE_SELECT status when changing it
internally
http://code.google.com/p/libnfc/source/detail?r=827d9792dd13
Modified:
/libnfc/chips/pn53x.c
/libnfc/nfc.c
=======================================
--- /libnfc/chips/pn53x.c Sat Feb 1 01:01:10 2014 UTC
+++ /libnfc/chips/pn53x.c Sat Feb 1 01:32:57 2014 UTC
@@ -1244,6 +1244,8 @@
break;
}
} else {
+ bool bInfiniteSelect = pnd->bInfiniteSelect;
+ int result = 0;
if ((res = pn53x_set_property_bool(pnd, NP_INFINITE_SELECT, true)) < 0)
return res;
// FIXME It does not support DEP targets
@@ -1257,16 +1259,23 @@
if ((res = pn53x_initiator_select_passive_target_ext(pnd,
pnmModulations[n], pbtInitiatorData, szInitiatorData, pnt, timeout_ms)) <
0) {
if (pnd->last_error != NFC_ETIMEOUT) {
- return pnd->last_error;
+ result = pnd->last_error;
+ goto end;
}
} else {
- return res;
+ result = res;
+ goto end;
}
}
}
} while (uiPollNr == 0xff); // uiPollNr==0xff means infinite polling
// We reach this point when each listing give no result, we simply
have to return 0
- return 0;
+end:
+ if (! bInfiniteSelect) {
+ if ((res = pn53x_set_property_bool(pnd, NP_INFINITE_SELECT, false))
< 0)
+ return res;
+ }
+ return result;
}
return NFC_ECHIP;
}
@@ -1822,7 +1831,7 @@
ret = pn53x_Diagnose06(pnd);
} else {
// Limitation: re-select will lose authentication of already
authenticated sector
- // Limitation: NP_INFINITE_SELECT will be left as FALSE (we cannot
restore as we don't know what was the original state)
+ bool bInfiniteSelect = pnd->bInfiniteSelect;
uint8_t pbtInitiatorData[12];
size_t szInitiatorData = 0;
iso14443_cascade_uid(CHIP_DATA(pnd)->current_target->nti.nai.abtUid,
CHIP_DATA(pnd)->current_target->nti.nai.szUidLen, pbtInitiatorData,
&szInitiatorData);
@@ -1833,6 +1842,11 @@
} else if ((ret == 0) || (ret == NFC_ETIMEOUT)) {
ret = NFC_ETGRELEASED;
}
+ if (bInfiniteSelect) {
+ int ret2;
+ if ((ret2 = pn53x_set_property_bool(pnd, NP_INFINITE_SELECT, true))
< 0)
+ return ret2;
+ }
}
return ret;
}
=======================================
--- /libnfc/nfc.c Mon Jan 27 15:07:24 2014 UTC
+++ /libnfc/nfc.c Sat Feb 1 01:32:57 2014 UTC
@@ -573,6 +573,7 @@
pnd->last_error = 0;
// Let the reader only try once to find a tag
+ bool bInfiniteSelect = pnd->bInfiniteSelect;
if ((res = nfc_device_set_property_bool(pnd, NP_INFINITE_SELECT, false))
< 0) {
return res;
}
@@ -603,6 +604,11 @@
break;
}
}
+ if (bInfiniteSelect) {
+ if ((res = nfc_device_set_property_bool(pnd, NP_INFINITE_SELECT,
true)) < 0) {
+ return res;
+ }
+ }
return szTargetFound;
}
@@ -684,18 +690,30 @@
const int period = 300;
int remaining_time = timeout;
int res;
+ int result = 0;
+ bool bInfiniteSelect = pnd->bInfiniteSelect;
if ((res = nfc_device_set_property_bool(pnd, NP_INFINITE_SELECT, true))
< 0)
return res;
while (remaining_time > 0) {
if ((res = nfc_initiator_select_dep_target(pnd, ndm, nbr,
pndiInitiator, pnt, period)) < 0) {
- if (res != NFC_ETIMEOUT)
- return res;
+ if (res != NFC_ETIMEOUT) {
+ result = res;
+ goto end;
+ }
}
- if (res == 1)
+ if (res == 1) {
+ result = res;
+ goto end;
+ }
+ remaining_time -= period;
+ }
+end:
+ if (! bInfiniteSelect) {
+ if ((res = nfc_device_set_property_bool(pnd, NP_INFINITE_SELECT,
false)) < 0) {
return res;
- remaining_time -= period;
+ }
}
- return 0;
+ return result;
}
/** @ingroup initiator