libnfc/examples
Benjamin Delpy 3f0101bd3f Fix nfc_initiator_select_passive_target target count on PN53x when not using InListPassiveTarget
When using `pn53x` chip with target not compatible with `InListPassiveTarget` (like `NMT_ISO14443BICLASS`, `NMT_ISO14443B2CT` & `NMT_ISO14443B2SR` by eg.), the logic behind `nfc_initiator_select_passive_target` to return target count seems to be buggy

`nfc_initiator_select_passive_target`:
> Returns:
> Returns selected passive target count on success, otherwise returns libnfc's error code (negative value)

In `pn53x_initiator_select_passive_target_ext`, the return value in success is always `abtTargetsData[0]`. This is correct when using `InListPassiveTarget` as the first byte is `NbTg`, but it can be problematic for other cases.

- Example with a Mifare:
```
gentilkiwi@pi5:~/libnfc-dev $ ./utils/nfc-list -t 1
NFC device: Elechouse NFC Module V3 (SPI) opened

## End of function 'pn53x_initiator_select_passive_target_ext'...
##  abtTargetsData content is : 01 01 00 04 08 04 1a da 74 44
##  return will be:           0x01 (?)

1 ISO14443A passive target(s) found:
ISO/IEC 14443A (106 kbps) target:
    ATQA (SENS_RES): 00  04
       UID (NFCID1): 1a  da  74  44
      SAK (SEL_RES): 08
```

- Example with 2x ST25TB:
```
gentilkiwi@pi5:~/libnfc-dev $ ./utils/nfc-list -t 32
NFC device: Elechouse NFC Module V3 (SPI) opened

## End of function 'pn53x_initiator_select_passive_target_ext'...
##  abtTargetsData content is : 35 a5 f2 a4 68 1f 02 d0
##  return will be:           0x35 (?)

1 ISO14443B-2 ST SRx passive target(s) found:
ISO/IEC 14443-2B ST SRx (106 kbps) target:
                UID: 35  a5  f2  a4  68  1f  02  d0
```
```
gentilkiwi@pi5:~/libnfc-dev $ ./utils/nfc-list -t 32
NFC device: Elechouse NFC Module V3 (SPI) opened

## End of function 'pn53x_initiator_select_passive_target_ext'...
##  abtTargetsData content is : 00 92 f0 a4 68 1f 02 d0
##  return will be:           0x00 (?)

0 ISO14443B-2 ST SRx passive target(s) found.
```

The proposed PR will fix the target count to 1 when not using `InListPassiveTarget`, since current versions of target initialisation do not support for more.

- Results:

```
gentilkiwi@pi5:~/libnfc-dev $ ./utils/nfc-list -t 32
NFC device: Elechouse NFC Module V3 (SPI) opened
1 ISO14443B-2 ST SRx passive target(s) found:
ISO/IEC 14443-2B ST SRx (106 kbps) target:
                UID: 00  92  f0  a4  68  1f  02  d0

gentilkiwi@pi5:~/libnfc-dev $ ./examples/nfc-st25tb
|mode   : info
Reader  : Elechouse NFC Module V3 (SPI) - via pn532_spi:/dev/spidev0.0:500000
  ...wait for card...
Target  : ISO/IEC 14443-2B ST SRx (106 kbps)
UID     : 00 92 f0 a4 68 1f 02 d0
Manuf   : 0x02 - STMicroelectronics
ChipId  : 0x1f - ST25TB04K
Serial  : 0x68a4f09200
|blk sz : 32 bits
|nb blks: 128
|sys idx: 255
```

(also checked for non-regression with `InListPassiveTarget`, including multiples `A` targets)
2024-07-28 12:36:49 +02:00
..
doc Add missing \n in a printf() 2013-08-31 17:59:24 +02:00
pn53x-tamashell-scripts Update example script to support PCard 2017-04-16 00:05:21 +02:00
CMakeLists.txt Fix, lib Win32 again 2021-06-13 22:24:32 +02:00
Makefile.am Fix contrib code for Win32 example 2021-06-13 22:14:52 +02:00
nfc-anticol.1 Update links from googlecode to github. 2015-04-30 14:19:03 +02:00
nfc-anticol.c Adding link to AUTHORS in the copyright headers 2013-07-17 13:57:56 +02:00
nfc-dep-initiator.1 Update links from googlecode to github. 2015-04-30 14:19:03 +02:00
nfc-dep-initiator.c Adding link to AUTHORS in the copyright headers 2013-07-17 13:57:56 +02:00
nfc-dep-target.1 Update links from googlecode to github. 2015-04-30 14:19:03 +02:00
nfc-dep-target.c Adding link to AUTHORS in the copyright headers 2013-07-17 13:57:56 +02:00
nfc-emulate-forum-tag2.1 Update links from googlecode to github. 2015-04-30 14:19:03 +02:00
nfc-emulate-forum-tag2.c Adding link to AUTHORS in the copyright headers 2013-07-17 13:57:56 +02:00
nfc-emulate-tag.1 Update links from googlecode to github. 2015-04-30 14:19:03 +02:00
nfc-emulate-tag.c Wrong variable names 2017-09-03 21:53:17 +02:00
nfc-emulate-uid.1 Fixed a typo in examples/nfc-emulate-uid.1 2019-04-28 13:25:43 -10:00
nfc-emulate-uid.c nfc-emulate-uid: remove unreachable code and add proper cleaning when interrupted 2014-03-04 01:41:01 +01:00
nfc-mfsetuid.1 Update links from googlecode to github. 2015-04-30 14:19:03 +02:00
nfc-mfsetuid.c make style 2017-04-01 00:46:12 +02:00
nfc-poll.1 Update links from googlecode to github. 2015-04-30 14:19:03 +02:00
nfc-poll.c first cut iClass support - get nfc-list to see UID 2020-05-11 11:45:28 +01:00
nfc-relay.1 Update links from googlecode to github. 2015-04-30 14:19:03 +02:00
nfc-relay.c Adding link to AUTHORS in the copyright headers 2013-07-17 13:57:56 +02:00
nfc-st25tb.c Fix nfc_initiator_select_passive_target target count on PN53x when not using InListPassiveTarget 2024-07-28 12:36:49 +02:00
pn53x-diagnose.1 Update links from googlecode to github. 2015-04-30 14:19:03 +02:00
pn53x-diagnose.c Adding link to AUTHORS in the copyright headers 2013-07-17 13:57:56 +02:00
pn53x-sam.1 Update links from googlecode to github. 2015-04-30 14:19:03 +02:00
pn53x-sam.c pn53x-sam: fix truncated stdio return value 2013-09-22 02:38:17 +02:00
pn53x-tamashell.1 Update links from googlecode to github. 2015-04-30 14:19:03 +02:00
pn53x-tamashell.c Adding link to AUTHORS in the copyright headers 2013-07-17 13:57:56 +02:00