From 5b9ae7ee512ee4d7feddbdf4d7a740b5fb114bda Mon Sep 17 00:00:00 2001 From: Benjamin DELPY Date: Sun, 12 Feb 2023 19:37:04 +0100 Subject: [PATCH] pn53x initiator set registers for ISO14443B-2 ST SRx Modification to set PN53X_REG_CIU_TxAuto, PN53X_REG_CIU_CWGsP & PN53X_REG_CIU_ModGsP registers values before init. Avoids a dummy scan in B mode before --- examples/nfc-st25tb.c | 55 ++++++++++++++++++------------------------- libnfc/chips/pn53x.c | 8 +++++++ utils/nfc-list.c | 2 +- 3 files changed, 32 insertions(+), 33 deletions(-) diff --git a/examples/nfc-st25tb.c b/examples/nfc-st25tb.c index bcca55b..7eb5dee 100644 --- a/examples/nfc-st25tb.c +++ b/examples/nfc-st25tb.c @@ -50,7 +50,7 @@ * * Tested with * - ST25TB512-AC - (BE/Brussels/STIB ; AliExpress ones) - * - ST25TB512-AT - (FR/Lille/Ilevia ; FR/Reims/Citura) + * - ST25TB512-AT - (FR/Lille/Ilevia ; FR/Reims/Citura ; FR/Dijon/Divia ; FR/Strasbourg/CTS) * - SRT512 - legacy - (FR/Bordeaux/TBM) * - SRI512 - legacy - (anonymous vending machine) */ @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) nfc_context *context = NULL; nfc_device *pnd = NULL; nfc_target nt = {0}; - nfc_modulation nm = {NMT_ISO14443B, NBR_106}; + nfc_modulation nm = {NMT_ISO14443B2SR, NBR_106}; const st_data * stcurrent; int opt, res; bool bIsBlock = false, bIsRead = false, bIsWrite = false, bIsBadCli = false; @@ -205,45 +205,35 @@ int main(int argc, char *argv[]) { printf("Reader : %s - via %s\n ...wait for card...\n", nfc_device_get_name(pnd), nfc_device_get_connstring(pnd)); - res = nfc_initiator_list_passive_targets(pnd, nm, &nt, 1); - if(res == 0) // we don't really wanted a NMT_ISO14443B + if (nfc_initiator_select_passive_target(pnd, nm, NULL, 0, &nt) > 0) { - nm.nmt = NMT_ISO14443B2SR; // we want a NMT_ISO14443B2SR, but needed to ask for NMT_ISO14443B before - if (nfc_initiator_select_passive_target(pnd, nm, NULL, 0, &nt) > 0) + stcurrent = get_info(&nt, true); + if(stcurrent) { - stcurrent = get_info(&nt, true); - if(stcurrent) - { - printf("\n"); + printf("\n"); - if(bIsBlock && (bIsRead || bIsWrite)) + if(bIsBlock && (bIsRead || bIsWrite)) + { + if(bIsRead) { - if(bIsRead) - { - get_block_at(pnd, blockNumber, NULL, 0, true); - } - - if(bIsWrite) - { - set_block_at_confirmed(pnd, blockNumber, data, cbData, true); - } + get_block_at(pnd, blockNumber, NULL, 0, true); } - else if(!bIsRead && !bIsWrite && !bIsBlock) + + if(bIsWrite) { - for(i = 0; i < stcurrent->nbNormalBlock; i++) - { - get_block_at(pnd, i, NULL, 0, true); - } - display_system_info(pnd, stcurrent); + set_block_at_confirmed(pnd, blockNumber, data, cbData, true); } } + else if(!bIsRead && !bIsWrite && !bIsBlock) + { + for(i = 0; i < stcurrent->nbNormalBlock; i++) + { + get_block_at(pnd, i, NULL, 0, true); + } + display_system_info(pnd, stcurrent); + } } } - else if(res > 0) - { - printf("ERROR - We got a NMT_ISO14443B ?\n"); - } - else printf("ERROR - nfc_initiator_list_passive_targets: %i\n", res); } else printf("ERROR - nfc_initiator_init: %i\n", res); @@ -606,4 +596,5 @@ void print_hex(const uint8_t *pbtData, const size_t szBytes) { printf("%02hhx ", pbtData[szPos]); } -} \ No newline at end of file +} + diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index d2b9396..e5d9d94 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -1155,6 +1155,14 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd, uint8_t abtRx[1]; uint8_t *pbtInitData = (uint8_t *) "\x0b"; size_t szInitData = 1; + + if ((res = pn53x_write_register(pnd, PN53X_REG_CIU_TxAuto, 0xef, 0x07)) < 0) // Initial RFOn, Tx2 RFAutoEn, Tx1 RFAutoEn + return res; + if ((res = pn53x_write_register(pnd, PN53X_REG_CIU_CWGsP, 0x3f, 0x3f)) < 0) // Conductance of the P-Driver + return res; + if ((res = pn53x_write_register(pnd, PN53X_REG_CIU_ModGsP, 0x3f, 0x12)) < 0) // Driver P-output conductance for the time of modulation + return res; + // 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 diff --git a/utils/nfc-list.c b/utils/nfc-list.c index 53dcf61..bb6aaef 100644 --- a/utils/nfc-list.c +++ b/utils/nfc-list.c @@ -113,7 +113,7 @@ main(int argc, const char *argv[]) exit(EXIT_FAILURE); } // Force TypeB for all derivatives of B - if (mask & 0xf0) + if (mask & 0xd0) mask |= 0x08; } else { ERR("%s is not supported option.", argv[arg]);