Skip to content

Commit c6fdd19

Browse files
author
Your Name
committed
Merge remote-tracking branch 'origin/master' into libusb10
2 parents 3a009d0 + 1f77bce commit c6fdd19

File tree

5 files changed

+58
-36
lines changed

5 files changed

+58
-36
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,17 @@ file per device in a nfc/devices.d directory:
102102
printf 'name = "My first device"\nconnstring = "pn532_uart:/dev/ttyACM0"\n' | sudo tee /etc/nfc/devices.d/first.conf
103103
printf 'name = "My second device"\nconnstring = "pn532_uart:/dev/ttyACM1"\n' | sudo tee /etc/nfc/devices.d/second.conf
104104

105+
Environment Variables
106+
=====================
107+
You can override certain configuration options at runtime using the following environment variables:
108+
+ `LIBNFC_DEFAULT_DEVICE=<connstring>`: `LIBNFC_DEFAULT_DEVICE=pn532_uart:/dev/ttyACM0` will use pn532 on /dev/ttyACM0 as default device
109+
+ `LIBNFC_DEVICE=<connstring>` will ignore all devices in the config files and use only the one defined in the variable
110+
+ `LIBNFC_AUTO_SCAN=<true|false>` overrides `allow_autoscan` option in the config file
111+
+ `LIBNFC_INTRUSIVE_SCAN=<true|false>` overrides `allow_intrusive_scan` option in the config file
112+
+ `LIBNFC_LOG_LEVEL=<0|1|2|3>` overrides `log_level` option in the config file
113+
114+
To obtain the connstring of a recognized device, you can use `nfc-scan-device`: `LIBNFC_AUTO_SCAN=true nfc-scan-device` will show the names & connstrings of all found devices.
115+
105116
How to report bugs
106117
==================
107118

examples/nfc-st25tb.c

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
*
5151
* Tested with
5252
* - ST25TB512-AC - (BE/Brussels/STIB ; AliExpress ones)
53-
* - ST25TB512-AT - (FR/Lille/Ilevia ; FR/Reims/Citura)
53+
* - ST25TB512-AT - (FR/Lille/Ilevia ; FR/Reims/Citura ; FR/Dijon/Divia ; FR/Strasbourg/CTS)
5454
* - SRT512 - legacy - (FR/Bordeaux/TBM)
5555
* - SRI512 - legacy - (anonymous vending machine)
5656
*/
@@ -94,7 +94,7 @@ int main(int argc, char *argv[])
9494
nfc_context *context = NULL;
9595
nfc_device *pnd = NULL;
9696
nfc_target nt = {0};
97-
nfc_modulation nm = {NMT_ISO14443B, NBR_106};
97+
nfc_modulation nm = {NMT_ISO14443B2SR, NBR_106};
9898
const st_data * stcurrent;
9999
int opt, res;
100100
bool bIsBlock = false, bIsRead = false, bIsWrite = false, bIsBadCli = false;
@@ -205,45 +205,35 @@ int main(int argc, char *argv[])
205205
{
206206
printf("Reader : %s - via %s\n ...wait for card...\n", nfc_device_get_name(pnd), nfc_device_get_connstring(pnd));
207207

208-
res = nfc_initiator_list_passive_targets(pnd, nm, &nt, 1);
209-
if(res == 0) // we don't really wanted a NMT_ISO14443B
208+
if (nfc_initiator_select_passive_target(pnd, nm, NULL, 0, &nt) > 0)
210209
{
211-
nm.nmt = NMT_ISO14443B2SR; // we want a NMT_ISO14443B2SR, but needed to ask for NMT_ISO14443B before
212-
if (nfc_initiator_select_passive_target(pnd, nm, NULL, 0, &nt) > 0)
210+
stcurrent = get_info(&nt, true);
211+
if(stcurrent)
213212
{
214-
stcurrent = get_info(&nt, true);
215-
if(stcurrent)
216-
{
217-
printf("\n");
213+
printf("\n");
218214

219-
if(bIsBlock && (bIsRead || bIsWrite))
215+
if(bIsBlock && (bIsRead || bIsWrite))
216+
{
217+
if(bIsRead)
220218
{
221-
if(bIsRead)
222-
{
223-
get_block_at(pnd, blockNumber, NULL, 0, true);
224-
}
225-
226-
if(bIsWrite)
227-
{
228-
set_block_at_confirmed(pnd, blockNumber, data, cbData, true);
229-
}
219+
get_block_at(pnd, blockNumber, NULL, 0, true);
230220
}
231-
else if(!bIsRead && !bIsWrite && !bIsBlock)
221+
222+
if(bIsWrite)
223+
{
224+
set_block_at_confirmed(pnd, blockNumber, data, cbData, true);
225+
}
226+
}
227+
else if(!bIsRead && !bIsWrite && !bIsBlock)
228+
{
229+
for(i = 0; i < stcurrent->nbNormalBlock; i++)
232230
{
233-
for(i = 0; i < stcurrent->nbNormalBlock; i++)
234-
{
235-
get_block_at(pnd, i, NULL, 0, true);
236-
}
237-
display_system_info(pnd, stcurrent);
231+
get_block_at(pnd, i, NULL, 0, true);
238232
}
233+
display_system_info(pnd, stcurrent);
239234
}
240235
}
241236
}
242-
else if(res > 0)
243-
{
244-
printf("ERROR - We got a NMT_ISO14443B ?\n");
245-
}
246-
else printf("ERROR - nfc_initiator_list_passive_targets: %i\n", res);
247237
}
248238
else printf("ERROR - nfc_initiator_init: %i\n", res);
249239

@@ -606,4 +596,5 @@ void print_hex(const uint8_t *pbtData, const size_t szBytes)
606596
{
607597
printf("%02hhx ", pbtData[szPos]);
608598
}
609-
}
599+
}
600+

libnfc/chips/pn53x.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,6 +1155,14 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
11551155
uint8_t abtRx[1];
11561156
uint8_t *pbtInitData = (uint8_t *) "\x0b";
11571157
size_t szInitData = 1;
1158+
1159+
if ((res = pn53x_write_register(pnd, PN53X_REG_CIU_TxAuto, 0xef, 0x07)) < 0) // Initial RFOn, Tx2 RFAutoEn, Tx1 RFAutoEn
1160+
return res;
1161+
if ((res = pn53x_write_register(pnd, PN53X_REG_CIU_CWGsP, 0x3f, 0x3f)) < 0) // Conductance of the P-Driver
1162+
return res;
1163+
if ((res = pn53x_write_register(pnd, PN53X_REG_CIU_ModGsP, 0x3f, 0x12)) < 0) // Driver P-output conductance for the time of modulation
1164+
return res;
1165+
11581166
// Getting random Chip_ID
11591167
if ((res = pn53x_initiator_transceive_bytes(pnd, abtInitiate, szInitiateLen, abtRx, sizeof(abtRx), timeout)) < 0) {
11601168
if ((res == NFC_ERFTRANS) && (CHIP_DATA(pnd)->last_status_byte == 0x01)) { // Chip timeout

libnfc/drivers/acr122_usb.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ acr122_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, co
580580

581581
uint8_t attempted_response = RDR_to_PC_DataBlock;
582582
size_t len;
583+
int error, status;
583584

584585
if (res == NFC_ETIMEOUT) {
585586
if (DRIVER_DATA(pnd)->abort_flag) {
@@ -591,7 +592,7 @@ acr122_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, co
591592
goto read;
592593
}
593594
}
594-
if (res < 12) {
595+
if (res < 10) {
595596
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Invalid RDR_to_PC_DataBlock frame");
596597
// try to interrupt current device state
597598
acr122_usb_ack(pnd);
@@ -606,6 +607,17 @@ acr122_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, co
606607
offset++;
607608

608609
len = abtRxBuf[offset++];
610+
status = abtRxBuf[7];
611+
error = abtRxBuf[8];
612+
if (len == 0 && error == 0xFE) { // ICC_MUTE; XXX check for more errors
613+
// Do not check status; my ACR122U seemingly has status=0 in this case,
614+
// even though the spec says it should have had bmCommandStatus=1
615+
// and bmICCStatus=1.
616+
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Command timed out");
617+
pnd->last_error = NFC_ETIMEOUT;
618+
return pnd->last_error;
619+
}
620+
609621
if (!((len > 1) && (abtRxBuf[10] == 0xd5))) { // In case we didn't get an immediate answer:
610622
if (len != 2) {
611623
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Wrong reply");
@@ -652,7 +664,7 @@ acr122_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, co
652664
goto read; // FIXME May cause some trouble on Touchatag, right ?
653665
}
654666
}
655-
if (res < 12) {
667+
if (res < 10) {
656668
// try to interrupt current device state
657669
acr122_usb_ack(pnd);
658670
pnd->last_error = NFC_EIO;
@@ -701,7 +713,7 @@ acr122_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, co
701713

702714
// Skip CCID remaining bytes
703715
offset += 2; // bSlot and bSeq are not used
704-
offset += 2; // XXX bStatus and bError should maybe checked ?
716+
offset += 2; // bStatus and bError is partially checked
705717
offset += 1; // bRFU should be 0x00
706718

707719
// TFI + PD0 (CC+1)

utils/nfc-list.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ main(int argc, const char *argv[])
113113
exit(EXIT_FAILURE);
114114
}
115115
// Force TypeB for all derivatives of B
116-
if (mask & 0xf0)
116+
if (mask & 0xd0)
117117
mask |= 0x08;
118118
} else {
119119
ERR("%s is not supported option.", argv[arg]);

0 commit comments

Comments
 (0)