Skip to content

Commit

Permalink
pn53x initiator set registers for ISO14443B-2 ST SRx
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gentilkiwi committed Feb 12, 2023
1 parent 3df7f25 commit 5b9ae7e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 33 deletions.
55 changes: 23 additions & 32 deletions examples/nfc-st25tb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
set_block_at_confirmed(pnd, blockNumber, data, cbData, true);
}
}
else if(!bIsRead && !bIsWrite && !bIsBlock)
{
for(i = 0; i < stcurrent->nbNormalBlock; i++)
{
for(i = 0; i < stcurrent->nbNormalBlock; i++)
{
get_block_at(pnd, i, NULL, 0, true);
}
display_system_info(pnd, stcurrent);
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);

Expand Down Expand Up @@ -606,4 +596,5 @@ void print_hex(const uint8_t *pbtData, const size_t szBytes)
{
printf("%02hhx ", pbtData[szPos]);
}
}
}

8 changes: 8 additions & 0 deletions libnfc/chips/pn53x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion utils/nfc-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

1 comment on commit 5b9ae7e

@bubanstix
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

Please sign in to comment.