Compare commits

..

347 Commits

Author SHA1 Message Date
28ce753431 Document environment variables in README.md 2023-06-23 07:55:29 +00:00
80ef76fdda Fixes error libnfc.driver.acr122_usb Invalid RDR_to_PC_DataBlock frame 2023-05-27 18:12:06 +00:00
Philippe Teuwen
42de50f2b7
Merge pull request #688 from gentilkiwi/master
pn53x initiator set registers for ISO14443B-2 ST SRx
2023-02-13 21:00:49 +01:00
Benjamin DELPY
5b9ae7ee51 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
2023-02-12 19:37:04 +01:00
Romain Tartière
3df7f25f11
Merge pull request #655 from Ujjwal0501/patch-1 2021-09-19 20:28:20 -10:00
Ujjwal Kumar
16671bd0a3
fix: Typo in configuration commands 2021-09-20 11:33:57 +05:30
Romain Tartière
6d0e8a5d9b
Merge pull request #652 from xanderio/fix-freebsd
Fix builds on FreeBSD
2021-08-14 07:25:45 -10:00
Alexander Sieg
a884a45ab1 Fix builds on FreeBSD
Without this patch the cmake config assume that every UNIX system that
is not APPLE is automatically a linux system. This however causes
problems on FreeBSD and properly on other BSD systems.

We now explicitly check if the CMAKE_SYSTEM_NAME is set to Linux.
2021-08-14 12:07:59 +02:00
Philippe Teuwen
c8185c9eca
Merge pull request #639 from rstular/fix-atqa-comparison
Fix - assignment instead of comparison (PCSC driver)
2021-08-05 09:12:47 +02:00
Philippe Teuwen
56f6bd4fbb
Merge pull request #649 from linkclau/master
Include unistd.h (required because of usleep())
2021-08-05 09:12:11 +02:00
Claudius Link
1b8c244e38 Include unistd.h (required because of usleep()) 2021-08-04 23:02:32 +02:00
Philippe Teuwen
fb290be070
Merge pull request #645 from gentilkiwi/master
Add nfc-st25b example
2021-07-10 20:05:43 +02:00
Benjamin DELPY
a9cb26b28f
Fix, lib Win32 again 2021-06-13 22:24:32 +02:00
Benjamin DELPY
c924e5e00c
Fix contrib code for Win32 example 2021-06-13 22:14:52 +02:00
Benjamin DELPY
ba14d10e79
Add utils lib dep 2021-06-13 21:49:05 +02:00
Benjamin DELPY
9a94f20050
Some cast for Windows platform build 2021-06-13 21:19:57 +02:00
Benjamin DELPY
180fbabfe1
Add nfc-st25b example
This new example allows to operate on some ISO-14443-B ST25TB* and legacy SR* cards (read, write, info)
2021-06-13 20:00:52 +02:00
Dave T
1dc9dcb664
Make README.md more helpful for newcommer, remove ref to missing INSTALL (#636) 2021-06-09 14:40:25 +02:00
rstular
1f4d2fb3d4
Fix - assignment instead of comparison (PCSC driver) 2021-05-12 18:23:53 +02:00
Ludovic Rousseau
2b5ad9ce0b
README.md: fix URL of pcsc-lite
The project moved from .alioth.debian.org to .apdu.fr
2021-01-22 13:08:21 +01:00
Philippe Teuwen
7ebf9b92d6
Merge pull request #626 from aviallon/fix-typo-pcsc
Fix typo in variable name in pcsc.c
2020-11-02 13:24:33 +01:00
Antoine Viallon
3af2e14acc
Fix typo in variable name in pcsc.c 2020-11-02 12:30:59 +01:00
Adam Laurie
b5180a6a70
Merge pull request #624 from FeitianSmartcardReader/master
Modify code to add compatibility of readers
2020-10-24 15:28:25 +01:00
Feitian Technologies
0cd314c514
Modify code to add compatibility of readers
Follow the NXP  Contactless card IC rules to be compatible with Feitian new and old R502 reader.
2020-10-20 14:29:15 +08:00
Philippe Teuwen
c3f739dea3
Merge pull request #622 from timgates42/bugfix_typo_mechanism
docs: fix simple typo, mecanism -> mechanism
2020-10-11 16:33:51 +02:00
Tim Gates
126cf9c1be
docs: fix simple typo, mecanism -> mechanism
There is a small typo in contrib/win32/libnfc/buses/uart.c, libnfc/drivers/acr122_usb.c, libnfc/drivers/acr122s.c, libnfc/drivers/arygon.c, libnfc/drivers/pn532_uart.c, libnfc/drivers/pn53x_usb.c.

Should read `mechanism` rather than `mecanism`.
2020-10-11 07:43:16 +11:00
Philippe Teuwen
d9a04a54ff document RC_FILE_TYPE 2020-07-11 15:12:57 +02:00
Philippe Teuwen
cc4311acab
Merge pull request #611 from gelotus/msvc
windows compiling with native tools and clang, macos catalina compiling, added travis ci build tests
2020-07-11 15:12:13 +02:00
Unknown
e37d24e691 Merge branch 'msvc2' into msvc 2020-07-08 13:38:46 +02:00
Unknown
1077228fbd style 2020-07-08 13:26:45 +02:00
Unknown
5c09dc180a forget to add linux clang cmake 2020-07-08 13:24:26 +02:00
Unknown
d5fcd08d41 remove unused packages 2020-07-08 13:14:13 +02:00
Unknown
f56bbabf6c easy reading condition 2020-07-08 13:06:45 +02:00
Unknown
9cece8b55d add cr 2020-07-08 13:06:03 +02:00
Unknown
7ad18a2120 some cleanings 2020-07-07 19:41:07 +02:00
WangYi
e21fab3685 Example and util compile fine. 2020-07-05 00:55:23 +02:00
WangYi
82f23c411d Make it compile under MSVC2017. 2020-07-05 00:54:54 +02:00
Adam Laurie
66d3560608
Merge pull request #609 from gelotus/fix-4k
Fix 4k - [@gelotus]
(we can re-introduce support for other card types later as long as we adhere to the principal that we don't write unless requested to)
2020-07-04 18:20:34 +01:00
Philippe Teuwen
fc51c8662b
Merge pull request #610 from iceman1001/master
chg: make version printing obey verbose flag
2020-07-01 21:48:47 +02:00
iceman1001
db081ed12d chg: make version printing obey verbose flag 2020-07-01 21:28:02 +02:00
Unknown
6fb61d3c1e error handling 2020-06-30 17:19:24 +02:00
Unknown
f2677da74c too many different clone tags, let the user to chose action
too many different clone tags, let the user to chose action
2020-06-30 16:18:47 +02:00
Unknown
0bf4cec661 remove direct write check 2020-06-30 14:52:07 +02:00
Adam Laurie
0de55961c4
Merge pull request #608 from gelotus/nfc-mfclassic
Improve support for gen2 and gen3 tags
thanks @gelotus
2020-06-28 14:20:32 +01:00
Unknown
c8fcaea8ab no need to differentiate routines 2020-06-27 16:17:15 +02:00
Unknown
6921e57fb8 correct typo 2020-06-27 13:33:04 +02:00
Unknown
01bc5693d9 another hardcode value 2020-06-26 19:08:04 +02:00
Unknown
db957aabdf adds write condition check in unlock_card() 2020-06-26 18:29:01 +02:00
Unknown
f7b9b0eafa remove unused stuff for block 0 writing 2020-06-26 13:36:18 +02:00
Unknown
709ef8381f reinit for retrieving new uid after block 0 write 2020-06-26 13:34:50 +02:00
Unknown
3c55b8746b swap 0 block write and other blocks write
when writing to gen2 and possible on gen3, it writes first block 3 wich is the trailing sector before writing to block 0, so the last write to block 0 fails because authenticate to old keyset
2020-06-26 01:50:11 +02:00
Unknown
02f0f6b290 add verbose case
add verbose case
2020-06-26 01:28:57 +02:00
Unknown
7a5e654309 hardcoded values 2020-06-25 23:56:38 +02:00
Unknown
2b21d87e8e add gen2 desc to help
add gen2 desc to help
2020-06-25 23:45:17 +02:00
Unknown
4e922e8194 sends lib log to /dev/null in posix and added option (v) to reactivate
There in an error handling and messaging inside
2020-06-25 23:32:03 +02:00
Unknown
3f4b7a037a add rewrite support for gen2 tags with W command
add rewrite support for gen2 tags with W command
2020-06-25 23:10:06 +02:00
Unknown
dd96571f88 no need to loop, only one block 2020-06-25 19:49:04 +02:00
Unknown
5a87f1f3db Splitting block 0 writing and other block writing, not needed anymore 2020-06-25 19:29:38 +02:00
Adam Laurie
7b6ff73c4b only test DirectWrite write if we need to. only write block 0 if specifically requested to. 2020-06-25 17:45:20 +02:00
Adam Laurie
e560689f60 restore original block count logic and add debuggers for block0 2020-06-25 17:44:20 +02:00
Adam Laurie
a28a537610 partial fix of nfc-mfclassic which only writes first sector of each block and not sector 1,2,3 unles 'unlocked' write - debuggers still in! 2020-06-25 17:43:19 +02:00
Philippe Teuwen
4b7791f845
Merge pull request #605 from ffontaine/master
autotools: make example build optional
2020-06-24 16:18:29 +02:00
Philippe Teuwen
1f6f75af38
Merge pull request #606 from FeitianSmartcardReader/master
Add length check when work with Feitian OEM R502
2020-06-22 11:20:50 +02:00
hongbin@ftsafe.com
435e2ffc81 Add length check to have compatible with R502
improve the code, to have compatible with OEM R502 firmware.
2020-06-22 14:33:15 +08:00
Fabrice Fontaine
874d9605aa autotools: make example build optional
This patch makes example build optional for autotools build system.

In order to keep the former behavior, example build is enabled by default.

Signed-off-by: Samuel Martin <s.martin49@gmail.com>
[Retrieved (and slightly updated to remove CMakeLists.txt) from:
https://git.buildroot.net/buildroot/tree/package/libnfc/0001-build-systems-make-example-build-optional.patch]
Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2020-06-21 23:38:44 +02:00
Philippe Teuwen
53eccd4be4
Merge pull request #603 from FeitianSmartcardReader/master
Update pcsc.c
2020-05-27 19:15:22 +02:00
Feitian Technologies
b02f94d7da
Update pcsc.c
1. Fix bug for Mifare card, before do authentication, need to load PIN/password first
2. Fix bug when to get card ATS
2020-05-28 00:54:20 +08:00
Philippe Teuwen
f02ff51449 Prepare 1.8.0 version 2020-05-22 12:20:17 +02:00
Philippe Teuwen
5c3c468a6a Restore nfc_modulation_type order of v1.7.1 2020-05-22 12:20:17 +02:00
Ludovic Rousseau
63cf0acb0b pcsc: remove unused function pcsc_initiator_deselect_target
pcsc.c:763:12: warning: ‘pcsc_initiator_deselect_target’ defined but not used [-Wunused-function]
 static int pcsc_initiator_deselect_target(struct nfc_device *pnd)
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2020-05-22 10:13:52 +02:00
Ludovic Rousseau
5294c0290f Fix compiler warnings: no previous prototype
Local function should be declared static.

Fix:
pcsc.c:107:1: warning: no previous prototype for ‘pcsc_get_scardcontext’ [-Wmissing-prototypes]
 pcsc_get_scardcontext(void)
 ^~~~~~~~~~~~~~~~~~~~~
pcsc.c:119:1: warning: no previous prototype for ‘pcsc_free_scardcontext’ [-Wmissing-prototypes]
 pcsc_free_scardcontext(void)
 ^~~~~~~~~~~~~~~~~~~~~~
pcsc.c:135:5: warning: no previous prototype for ‘pcsc_transmit’ [-Wmissing-prototypes]
 int pcsc_transmit(struct nfc_device *pnd, const uint8_t *tx, const size_t tx_len, uint8_t *rx, size_t *rx_len)
     ^~~~~~~~~~~~~
pcsc.c:160:5: warning: no previous prototype for ‘pcsc_get_status’ [-Wmissing-prototypes]
 int pcsc_get_status(struct nfc_device *pnd, int *target_present, uint8_t *atr, size_t *atr_len)
     ^~~~~~~~~~~~~~~
pcsc.c:178:5: warning: no previous prototype for ‘pcsc_reconnect’ [-Wmissing-prototypes]
 int pcsc_reconnect(struct nfc_device *pnd, DWORD share_mode, DWORD protocol, DWORD disposition)
     ^~~~~~~~~~~~~~
pcsc.c:194:9: warning: no previous prototype for ‘pcsc_get_icc_type’ [-Wmissing-prototypes]
 uint8_t pcsc_get_icc_type(const struct nfc_device *pnd)
         ^~~~~~~~~~~~~~~~~
pcsc.c:203:6: warning: no previous prototype for ‘is_pcsc_reader_vendor’ [-Wmissing-prototypes]
 bool is_pcsc_reader_vendor(const struct nfc_device *pnd, const char *target_vendor_name)
      ^~~~~~~~~~~~~~~~~~~~~
pcsc.c:219:5: warning: no previous prototype for ‘pcsc_get_atqa’ [-Wmissing-prototypes]
 int pcsc_get_atqa(struct nfc_device *pnd, uint8_t *atqa, size_t atqa_len)
     ^~~~~~~~~~~~~
pcsc.c:245:5: warning: no previous prototype for ‘pcsc_get_ats’ [-Wmissing-prototypes]
 int pcsc_get_ats(struct nfc_device *pnd, uint8_t *ats, size_t ats_len)
     ^~~~~~~~~~~~
[...]
2020-05-22 10:11:52 +02:00
Ludovic Rousseau
fa78e8b883 Doxygen: unset DOT_FONTNAME
Fix warning:
warning: doxygen no longer ships with the FreeSans font.
You may want to clear or change DOT_FONTNAME.
Otherwise you run the risk that the wrong font is being used for dot generated graphs.
2020-05-22 10:02:37 +02:00
Ludovic Rousseau
357ae384af Doxygen: update Doxyfile.in to version 1.8.13
Fix warnings:
warning: Tag `SYMBOL_CACHE_SIZE' at line 299 of file `./Doxyfile' has become obsolete.
         To avoid this warning please remove this line from your configuration file or upgrade it using "doxygen -u"
warning: Tag `SHOW_DIRECTORIES' at line 487 of file `./Doxyfile' has become obsolete.
         To avoid this warning please remove this line from your configuration file or upgrade it using "doxygen -u"
warning: Tag `HTML_ALIGN_MEMBERS' at line 823 of file `./Doxyfile' has become obsolete.
         To avoid this warning please remove this line from your configuration file or upgrade it using "doxygen -u"
warning: Tag `USE_INLINE_TREES' at line 976 of file `./Doxyfile' has become obsolete.
         To avoid this warning please remove this line from your configuration file or upgrade it using "doxygen -u"
warning: Tag `XML_SCHEMA' at line 1169 of file `./Doxyfile' has become obsolete.
         To avoid this warning please remove this line from your configuration file or upgrade it using "doxygen -u"
warning: Tag `XML_DTD' at line 1175 of file `./Doxyfile' has become obsolete.
         To avoid this warning please remove this line from your configuration file or upgrade it using "doxygen -u"
2020-05-22 09:58:44 +02:00
Ludovic Rousseau
c8692aa239 Fix compiler warning: no previous prototype
nfc-mfclassic.c:623:6: warning: no previous prototype for ‘is_directwrite’ [-Wmissing-prototypes]
 bool is_directwrite(void)
      ^~~~~~~~~~~~~~
2020-05-22 09:51:14 +02:00
Ludovic Rousseau
91d7c5d32f Fix compiler warning: old-style function definition
nfc-mfclassic.c:623:6: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
 bool is_directwrite()
      ^~~~~~~~~~~~~~
nfc-mfclassic.c: In function ‘is_directwrite’:
nfc-mfclassic.c:623:6: warning: old-style function definition [-Wold-style-definition]
2020-05-22 09:50:26 +02:00
Philippe Teuwen
4525cd1c32 make style 2020-05-21 15:06:17 +02:00
Philippe Teuwen
f52d04e0a7 remove warnings 2020-05-21 15:05:48 +02:00
Philippe Teuwen
5a059db901 remove warnings 2020-05-21 14:50:30 +02:00
Philippe Teuwen
730f705c0d pcsc.c: fix error and remove warnings 2020-05-21 14:42:45 +02:00
Philippe Teuwen
6b4f6249bd rework README 2020-05-21 14:27:13 +02:00
Philippe Teuwen
d29b3170d9 update changelog 2020-05-21 14:14:43 +02:00
Adam Laurie
4a2c764961 Prepare 1.7.2 version 2020-05-21 12:05:38 +01:00
Adam Laurie
020f5317a6
Merge pull request #601 from h3xx/fix-typo
Fix typo
2020-05-21 11:40:22 +01:00
Philippe Teuwen
675c30eb93
Merge pull request #600 from FeitianSmartcardReader/master
Modify pcsc.c to have support for Mifare classic and Ultralight card
2020-05-14 12:49:43 +02:00
Feitian Technologies
beb8fdd759
Update pcsc.c
Remove call pcsc_get_vendor_name, get the vendor name from struct nfc_device
2020-05-14 11:08:23 +08:00
Dan Church
6f41ea3ad3
Fix typo
Introduced in #598
2020-05-13 09:05:27 -05:00
hongbin@ftsafe.com
8352c80679 Modify pcsc.c to have support for Mifare classic and Ultralight card
Modify pcsc.c and mifare.c files.
1. add code into pcsc.c to have support Mifare classic card.
2. The PCSC reader has SW value, add response data length for PCSC
reader
2020-05-13 12:15:28 +08:00
Adam Laurie
66176016ed bring nfc-list man page up to date 2020-05-12 16:52:47 +01:00
Adam Laurie
f1bb27d1af
Merge pull request #598 from h3xx/add-check-libnfc-nci
Add check for Libnfc-NCI before enabling pn71xx
thanks @h3xx
2020-05-12 12:36:55 +01:00
Adam Laurie
c884f36b94
Merge pull request #597 from nfc-tools/iclass
Iclass from Adam
2020-05-11 20:23:24 +01:00
Dan Church
17e615e8b1
Add check for Libnfc-NCI before enabling pn71xx
If the user specifically requests the driver, throw an error if it
cannot find libnfc-nci.

Also use the value from pkg-config to determine the library name,
instead of hard-coding it.
2020-05-11 13:45:53 -05:00
Philippe Teuwen
a07d879496 rework NMT_END_ENUM 2020-05-11 20:00:04 +02:00
Philippe Teuwen
10f880374c nfc-list bitfield 2020-05-11 19:55:44 +02:00
Philippe Teuwen
96568a1023 fix nfc-list for types B 2020-05-11 19:46:46 +02:00
Adam Laurie
dcc52cd4d5 updates as per @goedox comments 2020-05-11 18:04:57 +01:00
Adam Laurie
19a51dc2bd first cut iClass support - get nfc-list to see UID 2020-05-11 11:45:28 +01:00
Adam Laurie
61e93c1cdf
Merge pull request #591 from FeitianSmartcardReader/master
Update readme and add Feitian R502 and bR500 support into pcsc driver
2020-05-05 11:27:19 +01:00
hongbin@ftsafe.com
cbc4e7b5c4 Update readme and add Feitian R502 and bR500 support into pcsc driver
1. Modify pcsc.c code, add R502 and bR500 support into PCSC driver
2. Update readme, tell user how to build with pcsc driver
3. Add FAQ for bR500 and R502 in readme
2020-04-09 11:29:11 +08:00
Adam Laurie
692038ceaf
Merge pull request #561 from jpwidera/master
Added check for USB alternate settings
2020-04-05 14:37:22 +01:00
Adam Laurie
f3f588671c
Merge pull request #559 from frankmorgner/pcsc
Added driver for contactless PC/SC readers
(tested as far as it can see my PC/SC readers but could not open - needs debugging!)
2020-04-04 19:11:56 +01:00
Adam Laurie
fbae17186b
Merge branch 'master' into pcsc 2020-04-04 18:35:27 +01:00
Adam Laurie
004eff8e96
Merge pull request #544 from kraj/kraj/musl
usbbus: Include stdint.h for uintX_t
2020-04-04 18:31:26 +01:00
Adam Laurie
7908d405dd
Merge pull request #539 from rstular/patch-2
Updated function declaration in utils/nfc-mfultralight.c
2020-04-04 18:25:39 +01:00
Adam Laurie
ff4e1efa7b
Merge branch 'master' into patch-2 2020-04-04 18:24:40 +01:00
Adam Laurie
c34c446831
Merge pull request #520 from stawiski/master
Fixed format warnings.
2020-04-04 18:16:17 +01:00
Adam Laurie
54ba7359ce
Merge branch 'master' into master 2020-04-04 18:15:56 +01:00
Adam Laurie
fba969472d
Merge pull request #469 from jgeslin/master
Adding pn71xx NXP's NFC Controllers through Linux Libnfc-nci
(note I have only tested this does not break build etc. as I do not have a reader with this chipset)
2020-04-04 18:06:13 +01:00
Adam Laurie
a85f003d91
Merge pull request #451 from hph86/3_verbose_rats_cmd
Add RATS support indicator to nfc-mfclassic
2020-04-04 17:39:46 +01:00
Adam Laurie
8a1e14901d
Merge pull request #590 from AdamLaurie/master
add debugging for high level config requests
2020-04-04 17:18:46 +01:00
Adam Laurie
2a6a8e6e29 add debugging for high level config requests 2020-04-04 15:10:02 +01:00
jpwidera
07f918283b Fixed missing whitespaces 2019-09-05 22:33:33 +02:00
jpwidera
6e035c33f3 Re-enabled claim
If there are alternative interfaces, claim interface 0. Otherwise skip this step.
2019-09-05 22:32:03 +02:00
jpwidera
a77a2a8497 Removed USB alternate setting.
Quick and dirty fix for https://github.com/nfc-tools/libnfc/issues/535
2019-09-05 21:59:46 +02:00
Frank Morgner
6f793da1c1 cleanup 2019-09-03 22:44:44 +02:00
Frank Morgner
8e7a8e1b61 cmake: fixed pcsc requirement for acr122_pcsc 2019-09-03 15:51:38 +02:00
Frank Morgner
959a992a81 added PC/SC driver to cmake 2019-09-03 15:50:28 +02:00
Frank Morgner
75e5e23c81 Added driver for contactless PC/SC readers
- only initiator mode is supported
- properties are choosen as they are available via PC/SC, the rest of
the defaults are chosen to be compatible with Mifare DESFire
- This commit allows reading Mifare DESFire via PC/SC with libfreefare
2019-09-03 14:54:13 +02:00
Philippe Teuwen
f8b28523d7
Merge pull request #554 from quantum-x/master-UL-4K-DirectWrite-OneTimeWrite
Adding extended Magic Card support
2019-08-21 19:22:24 +03:00
quantum-x
ad695d0a18
Update .travis.yml 2019-08-21 10:06:19 +02:00
Philippe Teuwen
454a8c4d70 remove libcutter from travis as it's not available anymore in the repos 2019-08-19 19:48:16 +02:00
quantum-x
fbdbe6eff3
Update nfc-mfclassic.c
Adding support for extended Magic cards:
 - DirectWrite cards
 - One Time Write cards

Direct Write cards support modification of B0 directly, without any unlock codes. When we are attempting to detect if a card is 'magic', we will attempt to modify B0 directly as an initial check.

One Time Write cards support modification of B0 directly, one time only. They do not respond to magic commands, but have a fixed UID coming out of the factory. We now detect this UID, and if so, deem the card 'magic'.
2019-08-19 19:07:18 +02:00
quantum-x
c109d37783
Update nfc-mfultralight.c
Adding support for "DirectWrite" Ultralight tags.
 - The latest generation of "Magic" Ultralight tags support DirectWrite to B0.
 - Several versions of these cards are bricked if the older 'unlock' command is issued to the card.
 - To avoid this, when detecting if a card is magic, we attempt to modify B0 directly. If this fails, we proceed with an unlock command.
2019-08-19 19:04:52 +02:00
Philippe Teuwen
141907e127
Merge pull request #549 from admo/cmake_config_h
Generate config.h into build instead source directory.
2019-07-19 14:38:47 +02:00
Adam Oleksy
48d5f6b666 Generate config.h into build instead source directory. 2019-07-19 14:34:17 +02:00
Philippe Teuwen
a4af2be66c Fix PN533 hardcoded ednpoints table 2019-07-17 22:29:09 +02:00
Khem Raj
91f7db5b4d usbbus: Include stdint.h for uintX_t
stdint.h is needed for uintX_t typedefs which are
used to replace u_intX_t in libusb API headers in the cmake files

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2019-05-20 23:50:49 -07:00
rstular
ebb13d8965
Updated function declaration in utils/nfc-mfultralight.c
Updated a function declaration in utils/nfc-mfultralight.c to match the new style of C function declarations.
2019-04-29 09:49:09 +02:00
rstular
c42e2502d4 Fixed a typo in examples/nfc-emulate-uid.1 2019-04-28 13:25:43 -10:00
Romain Tartière
c59219905c Do outsource builds on CI
This helps figurig-out missing -I more easily.
2019-02-08 07:29:42 -10:00
Romain Tartière
ae56188005 Fix outsource build with the autotools 2019-02-08 07:25:55 -10:00
Romain Tartière
a9e4c915f2 Add missing INCLUDES
CC       pn53x-tamashell.o
    pn53x-tamashell.c:48:12: fatal error: 'readline/readline.h' file not found
    #  include <readline/readline.h>
    	   ^~~~~~~~~~~~~~~~~~~~~
    1 error generated.
2019-02-05 08:16:59 -10:00
Mikolaj Stawiski
793d5adde6 Fixed format warnings. 2018-11-25 13:48:04 +11:00
Emmanuel Dreyfus
7ca85a02de Fix typos 2018-11-19 19:16:26 +01:00
Emmanuel Dreyfus
85100c0aae Prefer hardcoded PN533 descriptors to the real ones
PN533 easily corrupts its USB descriptors. We know that and we
already try to detect and even repair them.

However there are situations where lower software layers get
confused before libnfc can help. On Windows, libusb may set
dev->config to NULL, but we can also have a non NULL dev->config
referencing corrupted data.

In order to get more robust, let us replace the Windows libusb
specific (dev->config == NULL) test by an inconditionnal use of
hardcoded descriptors when they are available.
2018-11-19 19:16:26 +01:00
Romuald Conty
ddfe2e648a
Merge pull request #517 from manu0401/timeout1
Add missing timeout
2018-11-13 11:31:54 +01:00
Emmanuel Dreyfus
2418d946a3 Add missing timeout
Add a tiemout in pn53x_initiator_select_passive_target()
so that we do not get stuck forever when pn533 misses a toggle
bit change.
2018-11-12 14:46:31 +00:00
Philippe Teuwen
b5641f8562
Merge pull request #513 from Stean/master
Add undocumented option -s to nfc-relay-picc help
2018-11-07 12:19:08 +01:00
Stean
f93169feb4 Add undocumented option -s to nfc-relay-picc man page 2018-11-04 21:30:35 +01:00
Stean
c52cdb10c8 Add undocumented option -s to usage listing 2018-11-04 21:22:46 +01:00
Markus Werle
4ae4cc86f8
Merge pull request #450 from hph86/2_fix_typo
Fix typo in nfc-mfclassic
2018-10-02 12:32:45 +02:00
Markus Werle
980513f4d1
Merge pull request #506 from nfc-tools/fix-cmake-module-path
fix CMAKE_MODULE_PATH for libnfc as a submodule
2018-10-02 12:22:41 +02:00
Markus Werle
d11db46ddd
fix CMAKE_MODULE_PATH for libnfc as a submodule
This fixes #496
2018-10-02 12:14:29 +02:00
Philippe Teuwen
a9af1927e6
Merge pull request #504 from AdamLaurie/master
Fix handling of NTAG OTP and LOCK bytes
2018-09-18 16:36:13 +02:00
Adam Laurie
25ee3a2f76 Add OTP/Capability Bytes handling to NTAG 2018-09-18 11:14:08 +01:00
Adam Laurie
3ba065f00b Remove redundant EV1 types and rely on NTAG types instead 2018-09-17 21:40:48 +01:00
Adam Laurie
40b54a10d7 Fix NTAG OTP and LOCK BYTES (Dynamic LOCK also applies to MF0UL21). Fix MF0UL21 sizing issue. 2018-09-17 16:58:49 +01:00
Adam Laurie
2229b9ed69 Merge remote-tracking branch 'upstream/master' 2018-09-17 14:40:34 +01:00
Adam Laurie
4c914e67e5 Fix handling of NTAG OTP and LOCK bytes 2018-09-17 14:37:09 +01:00
Philippe Teuwen
7c9a2a8062
Merge pull request #503 from AdamLaurie/master
Add support for Ultralight NTAG213/215/216
2018-09-16 22:37:51 +02:00
Adam Laurie
62f27c1c58 Add support for Ultralight NTAG213/215/216 2018-09-15 16:19:35 +01:00
Hanno Heinrichs
7a0a469c8a add more verbosity to RATS handling 2017-09-17 21:04:33 +02:00
Hanno Heinrichs
df4f9c0fbd fix typo 2017-09-17 21:02:50 +02:00
Hanno Heinrichs
e4ca7f45d2 remove redundant blanks 2017-09-17 21:01:12 +02:00
Philippe Teuwen
216145fba5 Merge pull request #440 from rocco8620/patch-1
Wrong variable names
2017-09-03 22:10:44 +02:00
rocco8620
2b96c9f3c5 Wrong variable names
Wrong variable names (missing dots) on line 269, 270, 271
2017-09-03 21:53:17 +02:00
Romain Tartière
2869ae2eb8 Merge pull request #420 from hramrach/master
nfc-poll: print "Waiting for card removing..." before waiting for card removal
2017-07-19 15:02:43 +02:00
Michal Suchanek
f9417586c0 nfc-poll: print "Waiting for card removing..." before waiting 2017-07-14 16:19:26 +02:00
Philippe Teuwen
14f48d0122 Fix mem leak 2017-05-18 10:40:46 +02:00
Philippe Teuwen
00700bc66d Make Travis happy 2017-05-17 15:56:41 +02:00
Philippe Teuwen
dcdbff0705 New NFC modulation type NMT_BARCODE 2017-05-17 13:58:16 +02:00
Philippe Teuwen
9f1a68530a nfc-barcode: add options -r & -n 2017-05-16 14:35:58 +02:00
Philippe Teuwen
9f4290b61b Add nfc-barcode 2017-05-16 13:22:30 +02:00
Philippe Teuwen
c9ac17c9f5 Fix USB descriptors in SCL3711, NXP_PN533 and ASK LoGO also when corrupted by received data
The problem occurs in the following succession of events:

* Emit commands returning an answer larger than 16 bytes
* Re-enumerate USB devices without power cycle, e.g. a warm reboot of the PC

The bug can be reproduced for testing purposes with usbreset.c from
https://askubuntu.com/questions/645/how-do-you-reset-a-usb-device-from-the-command-line#661

$ lsusb|grep NFC
Bus 001 Device 010: ID 04e6:5591 SCM Microsystems, Inc. SCL3711-NFC&RW
$ sudo ./usbreset /dev/bus/usb/001/010
Resetting USB device /dev/bus/usb/001/010
Reset successful
$ echo -e "4a 01 00\n423000" |pn53x-tamashell
$ sudo ./usbreset /dev/bus/usb/001/010
Resetting USB device /dev/bus/usb/001/010
Error in ioctl: No such device
$ lsusb|grep NFC
... device disappeared

In the example above, reading 4 pages of a MFUL corrupted one single byte.
The entire buffer can be corrupted e.g. with fast-reading a MFUL EV1:
$ echo -e "4a 01 00\n423a0013"|pn53x-tamashell
2017-04-20 09:06:47 +02:00
Philippe Teuwen
1bf542b9e2 cosmetic 2017-04-20 09:06:41 +02:00
Philippe Teuwen
767abe50e2 PN533: Abuse the overflow bug to restore USB descriptors in one go 2017-04-20 08:35:46 +02:00
Philippe Teuwen
38164c49ef Fix USB descriptors in SCL3711, NXP_PN533 and ASK LoGO if needed when closing device
The problem occurs in the following succession of events:

* Emit commands larger than 17 bytes
* Re-enumerate USB devices without power cycle, e.g. a warm reboot of the PC

The bug can be reproduced for testing purposes with usbreset.c from
https://askubuntu.com/questions/645/how-do-you-reset-a-usb-device-from-the-command-line#661

$ lsusb|grep NFC
Bus 001 Device 010: ID 04e6:5591 SCM Microsystems, Inc. SCL3711-NFC&RW
$ sudo ./usbreset /dev/bus/usb/001/010
Resetting USB device /dev/bus/usb/001/010
Reset successful
$ echo 06000000000000000000000000000000000000 |pn53x-tamashell
$ sudo ./usbreset /dev/bus/usb/001/010
Resetting USB device /dev/bus/usb/001/010
Error in ioctl: No such device
$ lsusb|grep NFC
... device disappeared
2017-04-20 01:46:32 +02:00
Philippe Teuwen
c958b2c25d Enable missing USB desc workaround for NXP_PN533 too 2017-04-19 20:24:55 +02:00
Emmanuel Dreyfus
a06bfe50a5 Workaround missing USB config
After a DESfire operation SCL3711 will sometimes enter a state where
libusb-0.x is unable to fill config field in struct usb_device. The
USB device has to be power-cycled to restore a sane state.

This introduce a work around, by using hardcoded values for endpoints
and packet size when they are unavailable.
2017-04-19 19:46:14 +02:00
Philippe Teuwen
6235a8a26b Update example script to support PCard 2017-04-16 00:05:21 +02:00
Philippe Teuwen
b59f8fb3b4 Add more missing files 2017-04-04 13:31:39 +02:00
Philippe Teuwen
fead8d6849 Add missing files to autotools release process 2017-04-04 11:10:46 +02:00
Philippe Teuwen
e41a42cf96 nfc-mfultralight: avoid compilation warning 2017-04-01 01:03:41 +02:00
Philippe Teuwen
024fca9cb7 make style 2017-04-01 00:46:12 +02:00
Philippe Teuwen
3ec9ecf800 nfc-mfultralight: fix support for MF0UL21 2017-04-01 00:25:14 +02:00
Philippe Teuwen
560f6a6413 nfc-mfultralight: better parameters checks 2017-03-31 23:21:17 +02:00
Philippe Teuwen
abae2bb17b Merge remote-tracking branch 'adam/master'
* adam/master:
  allow partial writes. tidy up usage.
  vary expected dump size based on tag type
  read extra mf-ul EV1 blocks
  show EV1 auth PACK (tag/reader trust secret)
  show EV1 storage size
  add EV1 password auth to nfc-mfultralight
2017-03-31 23:00:15 +02:00
Philippe Teuwen
f2457d0559 Add pn53x-* to CMakeLists 2017-03-31 22:46:11 +02:00
Adam Laurie
a9f3e3a2ac allow partial writes. tidy up usage. 2017-03-23 18:19:59 +00:00
Adam Laurie
963eb074ec vary expected dump size based on tag type 2017-03-23 16:42:10 +00:00
Adam Laurie
c04dd91e98 read extra mf-ul EV1 blocks 2017-03-23 16:04:02 +00:00
Adam Laurie
fe04b85678 show EV1 auth PACK (tag/reader trust secret) 2017-03-23 12:03:34 +00:00
Adam Laurie
3f8bb59f1e show EV1 storage size 2017-03-23 11:05:00 +00:00
Adam Laurie
ca96e50e9b add EV1 password auth to nfc-mfultralight 2017-03-22 23:05:48 +00:00
Philippe Teuwen
32bb627108 Fix typo in drivers blacklist, thanks Godfrey Chung 2017-03-07 10:49:25 +01:00
Philippe Teuwen
86ce8dff52 Test Travis builds 2017-03-03 18:41:13 +01:00
Philippe Teuwen
b65674a8e3 Some systems (e.g. glibc < 2.17) require librt to get clock_gettime -> CMAKE 2017-03-02 23:42:36 +01:00
Philippe Teuwen
2d2a664f6c Some systems (e.g. glibc < 2.17) require librt to get clock_gettime 2017-03-02 22:03:22 +01:00
Philippe Teuwen
9ccfba2125 Update changelog & authors 2017-03-02 16:00:51 +01:00
Philippe Teuwen
787382f4d5 Merge pull request #394 from lab-401/master-4k-magic
Adding support for 4K magic cards
2017-03-02 15:01:05 +01:00
Philippe Teuwen
b7ae7cb5fd Merge remote-tracking branch 'adam/master'
* adam/master:
  Tidier fix for incorrect block write/count as per @doegox
  Fix number of blocks written. Fix number of written blocks reported.
2017-03-01 18:51:35 +01:00
Simon Yorkston
6c44c20ffc Adding support for 4K magic cards 2017-03-01 18:41:16 +01:00
Philippe Teuwen
c51caf424a nfc-mfultralight: fix failed read reporting and add failed pages count 2017-02-27 17:22:42 +01:00
Adam Laurie
e119296680 Tidier fix for incorrect block write/count as per @doegox 2017-02-19 12:42:30 +00:00
Philippe Teuwen
bf31594410 conf: close file 2017-02-18 22:20:15 +01:00
Philippe Teuwen
04ef5ca902 Reduce variables scopes 2017-02-18 22:20:15 +01:00
Philippe Teuwen
2033519b0c Add asserts to tell static analyzer we know what we're doing...
nfc.c:1244:19: warning: Dereference of undefined pointer value
  for (int i = 0; nmt[i]; i++) {
                  ^~~~~~
nfc.c:1256:23: warning: Dereference of undefined pointer value
      for (int j = 0; nbr[j]; j++) {
                      ^~~~~~
2017-02-18 18:08:27 +01:00
Philippe Teuwen
f2c264d4ae pn53x: avoid warning about uninitialized value (false positive)
pn53x.c:1746:15: warning: Function call argument is an uninitialized value
    *cycles = __pn53x_get_timer(pnd, pbtTxRaw[szTx + 1]);
              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2017-02-18 17:29:57 +01:00
Philippe Teuwen
05220537ea i2c: fix struct initialization
pn532_i2c.c:125:57: warning: missing field 'tv_nsec' initializer [-Wmissing-field-initializers]
        struct timespec transaction_start, bus_free_time = { 0 };
                                                               ^
pn532_i2c.c:153:57: warning: missing field 'tv_nsec' initializer [-Wmissing-field-initializers]
        struct timespec transaction_start, bus_free_time = { 0 };
2017-02-18 17:23:22 +01:00
Philippe Teuwen
c815c7a059 nfc-mfultralight: remove dead assignment
nfc-mfultralight.c:274:7: warning: Value stored to 'bFailure' is never read
      bFailure = false;
      ^          ~~~~~
2017-02-18 17:17:53 +01:00
Philippe Teuwen
9a749e1a66 arygon: remove unused variable
arygon.c:94:22: warning: unused variable 'arygon_error_incomplete_command' [-Wunused-const-variable]
static const uint8_t arygon_error_incomplete_command[] = "FF0C0000\x0d\x0a";
                     ^
2017-02-18 17:17:33 +01:00
Philippe Teuwen
e4df2f3334 astyle 2017-02-18 13:05:59 +01:00
Philippe Teuwen
f184407cc5 Makefile: fix option for recent astyle 2017-02-18 13:05:45 +01:00
Philippe Teuwen
e8d44f1ee8 typo 2017-02-18 13:05:02 +01:00
Philippe Teuwen
4e4438435d Update README about pn533_usb 2017-02-18 01:59:27 +01:00
Philippe Teuwen
02c06c8e28 Update ChangeLog 2017-02-18 01:51:59 +01:00
Philippe Teuwen
047379406e Merge pull request #392 from jaasuarezvi/patch-1
Update README.md
2017-02-18 00:15:01 +01:00
Philippe Teuwen
be1b897617 Merge pull request #308 from AxisRay/master
Bugfix:function setenv() and unsetenv() are invalid on windows AND no variable prefix set for WIN32 in CMakeLists
2017-02-17 12:24:38 +01:00
Philippe Teuwen
15c31aecdb Merge pull request #362 from snowy13/master
Raspberry Pi 3 Conf Sample
2017-02-17 12:15:48 +01:00
Philippe Teuwen
ff37cdb2be Replace deprecated readdir_r by readdir
This reverts 262555d5, 7fb53873 and a0b859b2
2017-02-17 12:10:33 +01:00
Philippe Teuwen
99a7d9aa35 Merge pull request #387 from ChristophGr/master
allow to cross-compile 32 and 64 bit versions of the library for windows
2017-02-17 11:45:55 +01:00
Philippe Teuwen
c5e8adc169 mfclassic: avoid hardcoded offsets & sizes 2017-02-17 11:31:13 +01:00
Philippe Teuwen
646ab57ace fix typo 2017-02-17 10:31:25 +01:00
Philippe Teuwen
db4433f116 CMake: set policy CMP0045 2017-02-17 10:28:53 +01:00
Philippe Teuwen
7e3a7a6d05 Merge pull request #366 from oliv3r/master
Improve logging and allow building of debian packages
2017-02-17 10:15:27 +01:00
Philippe Teuwen
732a282190 Merge branch 'master' into master 2017-02-17 10:15:04 +01:00
Philippe Teuwen
d808802b16 typos 2017-02-17 10:11:34 +01:00
Philippe Teuwen
b86b7efb10 Fix number of blocks written
A strange move changed the way written pages are bound in commit ed62b01a.
As a result the last 3 blocks weren't written anymore.
2017-02-17 09:56:35 +01:00
Philippe Teuwen
11bcf05a75 Fix typo. Fix issue #377 2017-02-16 23:12:38 +01:00
Emmanuel Dreyfus
e26fe912fd NetBSD serial ports 2017-02-16 23:08:41 +01:00
Emmanuel Dreyfus
20a1b978f3 NetBSD definition for CCID ioctl 2017-02-16 23:08:36 +01:00
Philippe Teuwen
968f59a988 Remove unneeded test, fix issue #376 2017-02-16 23:05:02 +01:00
Philippe Teuwen
e50b18848f Remove spurious mirror_uint8_ts declaration, fix issue #375 2017-02-16 23:00:37 +01:00
Philippe Teuwen
372bf37eec Blacklist pn533_usb to fix issue #391 2017-02-16 22:32:16 +01:00
Philippe Teuwen
295c70911a Restrict MFC Mini detection according to AN10833 2017-02-16 22:31:10 +01:00
Philippe Teuwen
f16aeda9d0 Merge pull request #380 from llorephie/patch-2
Update README.md
2017-02-16 22:21:21 +01:00
Jairo Andres Suarez
7991c7d60c Update README.md 2017-02-14 18:47:27 -05:00
Adam Laurie
84c3e8a3ba Fix number of blocks written. Fix number of written blocks reported. 2017-01-30 21:47:06 +00:00
Christoph Gritschenberger
11a2da2811 allow to cross-compile 32 and 64 bit versions of the library for windows 2017-01-25 18:44:44 +01:00
jgeslin
f9f03fa7fa Debug dedicated implementation removed 2017-01-12 09:53:40 +01:00
Romuald Conty
8e5ec4acf3 Merge pull request #383 from centromere/patch-2
Fix typo in nfc.c
2016-12-11 16:46:36 +01:00
Romuald Conty
e0c72b782f Merge pull request #382 from centromere/patch-1
Fix typo in nfc.h
2016-12-11 16:46:04 +01:00
Romuald Conty
3592a60c1d Merge pull request #381 from llorephie/patch-1
Update Makefile.am
2016-12-11 16:45:22 +01:00
John Galt
9c7b9eda8c Fix typo in nfc.c 2016-12-07 07:22:27 -05:00
John Galt
b38597f1e0 Fix typo in nfc.h 2016-12-07 06:17:04 -05:00
Romuald Conty
e9a750fc00 Merge pull request #379 from oliv3r/Errata_on_i2c_timing
drivers: pn532_i2c: Errata on i2c timing
2016-12-06 17:58:30 +01:00
Maxim Martyanov
e32cc068ec Update README.md
README-Windows.txt => README-Windows.md
2016-12-06 20:44:31 +04:00
Maxim Martyanov
b29332a309 Update Makefile.am
README-Windows.txt -> README-Windows.md
2016-12-06 20:43:08 +04:00
Olliver Schinagl
e946f7a97a drivers: pn532_i2c: Errata on i2c timing
The datasheet is wrong for the pn532_i2c. After having constant issues
with the device failing to respond on the bus and after contacting NXP
about this, it turns out 1.3 ms is too tight. The official timing spec
is unknown for now, but we tested 4 and 5 ms without problems. Thus we
have choosen 5 ms as a safe delay.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-12-06 11:40:56 +01:00
Romuald Conty
b2a9cce037 Merge pull request #367 from oliv3r/respect_pn532_i2c_timing
Respect pn532 i2c timing
2016-12-05 22:12:52 +01:00
Romuald Conty
c3b3f64224 Merge pull request #372 from timzi/fix-cmakelists
Fixed file name "README" in cmakelists.txt
2016-12-05 22:10:33 +01:00
Romuald Conty
a07a496234 Merge pull request #378 from BourgeoisLab/patch-1
Match nfc.h
2016-12-05 19:50:49 +01:00
Frédéric Bourgeois
65477eea5e Match nfc.h
Synchronized with nfc.h with all API functions
2016-12-05 13:11:45 +01:00
timzi
a625d6a02d Fixed file name "README" in cmakelists.txt 2016-11-20 20:32:25 +03:00
Olliver Schinagl
d960673681 drivers: pn532_i2c: Add retry on error mechanism
Currently, we very occasionally can EXNIO errors from pn532_i2c_write() ->
i2c_write() -> write(). This may happen about once every 30 seconds.
Based from the kernel sources, EXNIO happens if the chip no longer
responds to its own address.

To make sure we do not loose any sent packets, we retry to send
PN532_SEND_RETRIES number of times. Since we miss 1 every 30 or so
seconds, doing 1 retry should be fine.

This might be considered a hack as the failure may be some other timing
related issue.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-10-24 13:05:42 +02:00
Olliver Schinagl
8f8f780c2b drivers: pn532_i2c: Respect proper timing specifications
The pn532 user manual states that after a i2c stop condition and before a i2c
start condition there should be a delay of minimally 1.3 milliseconds.
This is probably a limitation of the i2c peripheral or the firmware. In
any case, each i2c_read and i2c_write creates the packets which are
complemented with start/stop markers. It is thus required to take care
of timing in these two functions.

We solve this by wrapping the lower i2c_read and i2c_write functions for
the pn532, as this requirement is not for all chips.

Currently, we keep time using local variable, and thus the code is not
thread-safe. With libnfc being single threaded and only one instances of
libnfc can open a bus anyway, this is not yet a problem.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-10-24 12:02:58 +02:00
Olliver Schinagl
b953002f8f drivers: pn532_i2c: Clarify preamble and start byte
The pn532 documentation differs slightly from the included ascii art
documentation on how a packet looks like. The preamble was omitted
however the postamble is mentioned. This patch adds the Preamble to the
ascii frame documentation.

The code later refers incorrectly to the start byte as the preamble.
This variable was renamed to more descriptively state that it is the
preambe and the start bytes.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-10-24 12:00:36 +02:00
Olliver Schinagl
512be89700 busses: i2c: improve logging
Currently we only inform the user with the error logging mechanism that
we received a different number of bytes than expected.

Thus in case of an error, we say that we sent/received -1 bytes. However
-1 indicates an error and errno is set to indicate the error state.

This patch extends the logging to also print the actual error.

Additionally the same debugging printing was added to read, which is now
silently returned to the caller.

Signed-off-by: Olliver Schinagl <o.schinagl@ultimaker.com>
2016-10-21 14:20:51 +02:00
Olliver Schinagl
61b42396d9 CMake: allow building of debian packages
This patch allows for using the CMakefile to generate debian packages.
While CPack is far from perfect for generating debian packages, it is a
minimal change and quite helpful for quick deployment on debian based
systems.

Signed-off-by: Olliver Schinagl <o.schinagl@ultimaker.com>
2016-10-21 14:20:51 +02:00
Jeremy
4a10d0f21b Cosmetics changes 2016-10-10 17:36:55 +02:00
Jeremy
7eae55e929 Adding pn71xx NXP's NFC Controllers through Linux Libnfc-nci 2016-10-06 17:40:48 +02:00
Jim Anastassiou
0d3d5c13ff Add R-Pi 3 conf sample.
There have been changes to the Raspberry Pi 3's usage of serial ports with the addition of a Bluetooth LE module.
This configuration uses the mini UART without disabling any devices except for the linux serial console.
2016-08-19 19:22:06 -04:00
Jim Anastassiou
27ed3acc1a Update pn532_uart_on_rpi_3.conf.sample 2016-08-19 18:38:19 -04:00
Jim Anastassiou
35cc69dffb Rename pn532_uart_on_rpi3.conf.sample to pn532_uart_on_rpi_3.conf.sample 2016-08-19 18:37:04 -04:00
Jim Anastassiou
4076046a66 Create pn532_uart_on_rpi3.conf.sample 2016-08-19 18:36:48 -04:00
Romuald Conty
659f5f407f Merge pull request #357 from yerzhanm/patch-1
added support for ACR1222U-C1
2016-06-24 02:49:29 +02:00
yerzhanm
41d694013c added support for ACR1222U-C1
added ACR1222U-C1 ACS ACR1222 1SAM PICC Reader in supported devices
2016-06-23 18:20:39 +06:00
Romuald Conty
403650a0fc Merge pull request #350 from oliv3r/master
Allow mfultralight and mfc tools to work also with specific UID's
2016-05-15 11:48:39 +02:00
Olliver Schinagl
a4bc1b9f6c nfc-mfultralight: also set failure state on uid write error
Currently, we return false, and after turning set the bFailure state.
This is of course not possible.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-05-13 14:44:07 +02:00
Olliver Schinagl
ed62b01a0f nfc-mfultralight: write uiBlocks, as we read
We use a variable, uiBlocks, to determine how many blocks to read/write.
Reading is actually done via a hardcoded 0xF value however.

Additionally, make uiblocks a const, as we use it as a constant and
change the page variable to uint32_t for consistency sake.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-05-13 14:44:07 +02:00
Olliver Schinagl
4b8871fd8f nfc-mfultralight: Remove whitespaces
Clean up some stray unintended whitespaces. This patch does not
introduce any binary changes.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-05-11 09:38:39 +02:00
Olliver Schinagl
ecd0e59b5c nfc-mfultralight: Add option to specify UID
When several tags are in range, nfc-mfultralight uses the lowest ID it
finds by default. This patch adds some code from nfc-list that lists the
tags in range whenever an operation is performed (r/w). Further more it
adds the --with-uid <UID> option to force reading/writing of a specific
tag.

The UID can be up to 10 bytes long and can be optionally separated by
colons or hyphens (MAC address style).

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-05-11 09:38:39 +02:00
Olliver Schinagl
7b1ff70a52 nfc-mfultralight: Show help when no arguments are supplied
For some reason, 0cece94778 changed the argc count check to only show
the help if argc is 0. Obviously, argc is never zero, as the first
argument in argv is always the binary itself. Revert that and show usage
if there is no arguments supplied to the binary.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-05-11 09:38:39 +02:00
Olliver Schinagl
e1a25a8203 nfc-mfclassic: Add option to specify key
The nfc-mfclassic utility will pick a seemingly random (the libnfc
default which seems to be the lowest UID). With the new (u|U) options
it is now possible to force a UID and thus write a specific tag, which
can be very useful if there are more then one tag visible.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-05-11 09:38:39 +02:00
Olliver Schinagl
898f3a4d2f nfc-mfclassic: check argc < 4 only once
Currently the check on argc is done twice, once in each if branch. This
is silly and we can just check once and fail right away.

Signed-off-by: Olliver Schinagl <oliver@schinagl.nl>
2016-05-11 09:38:39 +02:00
Romuald Conty
83b70d6326 Merge pull request #349 from frankmorgner/foreign
tell Automake that we will not follow GNU Standards
2016-05-03 11:15:47 +02:00
Frank Morgner
7d4352dc98 tell Automake that we will not follow GNU Standards
NEWS and README are mandatory for autoconf. Fixes problem introduced in
b1a81b385ddabb704b4cea64fda56abb9928c3c3

closes https://github.com/nfc-tools/libnfc/pull/346
fixes https://github.com/nfc-tools/libnfc/issues/347
2016-05-03 10:53:55 +02:00
Romuald Conty
e23f8a9f9c Merge pull request #345 from quantum-x/ultralight-gen-2
Adding support for UL Gen 2 Badges
2016-04-09 11:25:11 +02:00
Simon Yorkston
e37de54e18 Updated to remove bugs
- For cards that aren’t magic, system will refuse to attempt writing
to block 0  / 1

 - Tested on Gen 1 & Gen 2 cards:

Gen 1
$ ./nfc-mfultralight w ul-test.dmp --full
NFC device: SCM Micro / SCL3711-NFC&RW opened
Found MIFARE Ultralight card with UID: 044e075ad42184
Writing 16 pages |................|
Done, 16 of 16 pages written (0 pages skipped).

Gen 2
$ ./nfc-mfultralight w ul-test.dmp --full
NFC device: SCM Micro / SCL3711-NFC&RW opened
Found MIFARE Ultralight card with UID: 044e075ad42184
Writing 16 pages |................|
Done, 16 of 16 pages written (0 pages skipped).

Non-magic
$ ./nfc-mfultralight w ul-test.dmp --full
NFC device: SCM Micro / SCL3711-NFC&RW opened
Found MIFARE Ultralight card with UID: 044e075ad42184
Writing 16 pages |
Unable to unlock card - are you sure the card is magic?
$
2016-04-09 03:42:01 +10:00
Romuald Conty
e8e1826eeb Merge pull request #344 from hiddewie/markdown2
Actual Markdown for the README and HACKING files
2016-04-08 18:53:05 +02:00
Simon Yorkston
8de7ce3899 Adding support for UL Gen 2 Badges 2016-04-09 01:32:14 +10:00
Hidde Wieringa
1f68888020
Added Markdown to HACKING file 2016-04-08 11:02:40 +02:00
Hidde Wieringa
291f70edee
Updated README-Windows for Markdown 2016-04-08 10:56:12 +02:00
Hidde Wieringa
62159a33ef
Added more Markdown formatting to README 2016-04-08 10:52:25 +02:00
Romuald Conty
d63e624b09 Merge pull request #341 from hiddewie/markdown
Changed a few README Markdown files to the .md extension so GitHub interprets it as Markdown
2016-04-07 20:09:46 +02:00
Hidde Wieringa
b1a81b385d
Changed a few README Markdown files to the .md extension so GitHub
interprets it as Markdown
2016-04-07 13:52:12 +02:00
Romuald Conty
bc8bb8de89 Merge pull request #315 from xantares/travis
Add travis config file
2016-03-19 12:44:59 +01:00
Romuald Conty
c228396c2d Merge pull request #337 from surr/typo
Fix improper pnd->name initialization
2016-03-19 12:43:32 +01:00
Alexander Inyukhin
10398b6bd9 А typo leads to improper pnd->name initialization
A for loop condition is always false so pnd->name
is not initialized. This results in garbage when
printing device name.
2016-03-19 08:08:38 +03:00
Romuald Conty
24979c65cc Merge pull request #327 from paulmenzel/fix-typo-in-readme
README: Fix typo in *is a registered*
2015-12-04 14:12:42 +01:00
Paul Menzel
c7f386dbcf README: Fix typo in *is a registered* 2015-12-04 13:59:59 +01:00
Romuald Conty
42d455c4e7 Merge pull request #325 from quantum-x/master
Extends nfc-mfultralight functionality (Magic cards, unattended mode)
2015-11-19 00:02:04 +01:00
Simon Yorkston
619b476028 Cleaned non-magic exit 2015-11-18 23:11:59 +01:00
Simon Yorkston
0cece94778 Adds --check-magic flag to nfc-mfultralight 2015-11-18 23:03:36 +01:00
Simon Yorkston
3aa2d46588 Added automatic mode to nfc-mfultralight 2015-11-18 08:56:48 +01:00
Romuald Conty
73c2ef8582 Merge pull request #323 from bhack/SCL3712
Add SCM_SCL3712 support
2015-11-04 20:34:21 +01:00
bhack
1d4720671e Add SCM_SCL3712 support 2015-11-04 20:15:56 +01:00
Romuald Conty
2046fb9461 Merge pull request #322 from quantum-x/quantum-x-unlockbehavior
Unlock read/write magic card fallback
2015-11-04 02:03:02 +01:00
quantum-x
758cb0cc05 Update nfc-mfclassic.c 2015-11-03 18:52:39 +01:00
quantum-x
c71d7267ac Update nfc-mfclassic.c
Tweaking back the unlocked_read / write_block_zero after magic2 card discovered
2015-11-03 18:48:22 +01:00
quantum-x
20f22b97e7 Updating nesting typo 2015-11-03 18:39:03 +01:00
quantum-x
b5684c1755 Removing typo
Removing typo
2015-11-03 18:33:53 +01:00
quantum-x
87c6053d6f Updating nfc-mfclassic.c
Modifying behavior relating to magic cards.
If a user has a 'magic2' card (IE, direct-write, not a 'fully magic' card) - we'll warn them that they don't need to use the W / R modes, and then proceed with the unlock operation, instead of exiting.
2015-11-03 18:11:51 +01:00
xantares
e7feb6587d Add travis config file 2015-09-01 09:33:06 +02:00
Romuald Conty
48c271e49d Merge pull request #314 from xantares/patch-3
CMake: use options() to disable examples and utils
2015-09-01 09:13:45 +02:00
Romuald Conty
53edc32a21 Merge pull request #313 from xantares/patch-2
CMake: use options() function
2015-09-01 09:13:13 +02:00
Romuald Conty
4193bb4873 Merge pull request #312 from xantares/patch-1
set default cmake build type
2015-09-01 09:12:43 +02:00
xantares
b7f620fdab options to disable samples 2015-09-01 08:58:35 +02:00
xantares
141e99959e use options 2015-09-01 08:57:11 +02:00
xantares
5d2052e77f set default cmake build type 2015-09-01 08:55:53 +02:00
Romuald Conty
555f9ce4cf Fixes #286: udev rule was executed to early 2015-08-19 11:50:52 +02:00
Romuald Conty
792e3d9cbd Do not include extra header in nfc.h
Fixes #310
2015-08-19 11:47:22 +02:00
Romuald Conty
13fee61e87 Fix typo
Closes #309
2015-08-19 11:44:23 +02:00
Ray Lee
09ce2233ce Bugfix:Set variable "prefix" for WIN32 2015-08-16 18:22:15 +08:00
Ray Lee
e72fe468a4 Bugfix:function setenv()and unsetenv()
The original setenv() and unsetenv() function is invalid,I have rewrited to fix.
2015-08-16 16:34:35 +08:00
Romuald Conty
738970c135 Merge pull request #304 from xaqq/drop_pcre
Drop PCRE dependency.
2015-08-04 10:14:01 +02:00
Romuald Conty
c55bbec50d Merge pull request #306 from Mincka/master
Fix nfc-poll card removing check
2015-08-03 17:43:54 +02:00
Julien Ehrhart
7ae5a0c333 Fix nfc-poll card removing check (should be done only if a target has been found). 2015-08-02 16:16:19 +00:00
xaqq
17ed36a7a5 Drop PCRE dependency.
The config file is now manually parsed instead of using regex.
While this is less beautifull, it allows us to drop PCRE
as a dependency on Windows.
2015-07-22 15:47:36 +02:00
Romuald Conty
6be73720fa Merge pull request #301 from xantares/patch-1
CMake: fix drivers include
2015-06-23 06:43:26 +02:00
xantares
59f6c5de54 fix drivers include
```
cc1: warning: /home/xantares/projects/libnfc/drivers: No such file or directory [-Wmissing-include-dirs]
```
2015-06-22 20:47:04 +02:00
Philippe Teuwen
49dde9c28c Merge branch 'nfc_get_supported_baud_rate_proposal'
* nfc_get_supported_baud_rate_proposal:
  nfc_get_supported_baud_rate() proposal to reverse API
2015-06-18 22:07:09 +02:00
Romuald Conty
7f23f1f84d Merge pull request #297 from mativait/master
export iso14443b* symbols
2015-06-09 14:39:07 +02:00
Philippe Teuwen
04a51df796 nfc_get_supported_baud_rate() proposal to reverse API
cf issue #298
nfc_get_supported_baud_rate() would be the one for "initiator mode"
and we add nfc_get_supported_baud_rate_target_mode()
2015-06-08 11:34:16 +02:00
Mati Vait
68094b4f6d export iso14443b* symbol 2015-05-27 23:01:48 +03:00
Romuald Conty
fecc19de4c Merge pull request #296 from cyberbobs/master
Fix nfc_initiator_poll_target without tag on PN532
2015-05-26 11:17:28 +02:00
Boris Moiseev
11a4e3cd7f Fix nfc_initiator_poll_target without tag on PN532
When there is no tag on PN532 reader, the library
incorrectly processed call result and returned
NFC_ECHIP (chip error) instead of 0 (no targets
found).
2015-05-25 17:22:25 +03:00
Romuald Conty
af8fe86b0d Git: ignore generated files 2015-05-18 20:43:32 +02:00
Romuald Conty
d028bc725d Fix comparison when nfc_initiator_target_is_present() with a specified target 2015-05-18 20:43:10 +02:00
Romuald Conty
22078a8509 Documentation: fix str_nfc_target() explanation 2015-05-18 20:08:33 +02:00
xantares
ef74d81a8b Added config files 2015-04-30 15:34:08 +02:00
Dario Carluccio
e96061e44b nfc-mfsetuid: allow to write complete Block0, instead of only UID
Fixes #282
2015-04-30 14:45:05 +02:00
Romuald Conty
33ce39ff71 nfc-relay-picc: fix wrong open mode for file descriptor
Fixes #280
2015-04-30 14:33:59 +02:00
Romuald Conty
8fbedb87f5 Update links from googlecode to github. 2015-04-30 14:19:03 +02:00
Romuald Conty
c31f8bd9be Doc: minor documentation fixes 2015-04-28 19:22:16 +02:00
Romuald Conty
0f77565a3c Fix cmake soversion (doesn't match autotools)
Thanks to Julien Schueller
2015-04-15 17:19:42 +02:00
Romuald Conty
1fe7c00e48 Git: ignore utils/nfc-jewel 2015-04-15 17:13:54 +02:00
Romuald Conty
fce491c829 README: add a section to help to configure libnfc 2015-04-15 17:11:11 +02:00
Romuald Conty
f82aa75072 Merge remote-tracking branch 'socram8888/cygfix' 2015-04-14 17:16:20 +02:00
Romuald Conty
eeb226aceb Merge pull request #290 from neffs/master
Use more serial devices on Mac OS X
2015-04-07 11:01:07 +02:00
David Kreitschmann
1785ac14c2 Use more serial devices on Mac OS X
Some USB-serial adapters just use tty.usbserial or tty.usbmodem as a
device name. (e.g.
Prolific).  Currently part of a patch for homebrew here:
https://github.com/Homebrew/homebrew/blob/master/Library/Formula/libnfc.
rb
2015-04-04 22:37:03 +02:00
Marcos Vives Del Sol
4e823d8db0 Use TIOCINQ instead of FIONREAD in Cygwin 2015-02-22 20:41:59 +01:00
Marcos Vives Del Sol
92c5bd864b Added Windows-specific files to .gitignore 2015-02-22 13:29:07 +01:00
Marcos Vives Del Sol
5a08fcf2bc Fix "undefined reference"s 2015-02-22 13:27:13 +01:00
Marcos Vives Del Sol
9d82d598f0 Fix "missing return" compiler warnings 2015-02-21 23:04:06 +01:00
Marcos Vives Del Sol
b6a8745838 Fix compilation under Cygwin 2015-02-21 22:57:36 +01:00
Adam Laurie
b978c45a11 tolerate errors when writing as well as reading 2014-05-25 16:39:47 +01:00
Philippe Teuwen
bb9babbeda Fix out-of-bounds access in nfc-mfultralight unveiled by coverity scan:
*** CID 1090333:  Out-of-bounds access  (OVERRUN)
2014-04-14 23:29:18 +02:00
Philippe Teuwen
bd92f74a58 Update ChangeLog 2014-03-12 00:38:46 +01:00
Philippe Teuwen
9a254712b5 nfc_initiator_select_passive_target(): validate modulation and baud rate 2014-03-12 00:28:39 +01:00
Philippe Teuwen
e57dc8a746 Better list of supported modulations & baud rates
* Extend supported baud rates for TypeA
* Extend supported modulations B->BI,B2SR,B2CT
* Use InPSL only on TypeA
* Add mode to nfc_get_supported_baud_rate() (API change!)
* Fix supported baud rates for BI,B2SR,B2CT
* Remove supported modulations as target for ASK LoGO

Before:

$ nfc-scan-device -v
3 NFC device(s) found:
- ACS / ACR122U PICC Interface:
    acr122_usb:002:024
chip: PN532 v1.4
initator mode modulations: ISO/IEC 14443A (106 kbps), FeliCa (424 kbps, 212 kbps), ISO/IEC 14443-4B (106 kbps), Innovision Jewel (106 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
target mode modulations: ISO/IEC 14443A (106 kbps), FeliCa (424 kbps, 212 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
- SCM Micro / SCL3711-NFC&RW:
    pn53x_usb:002:028
chip: PN533 v2.7
initator mode modulations: ISO/IEC 14443A (106 kbps), FeliCa (424 kbps, 212 kbps), ISO/IEC 14443-4B (847 kbps, 424 kbps, 212 kbps, 106 kbps), Innovision Jewel (106 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
target mode modulations: ISO/IEC 14443A (106 kbps), FeliCa (424 kbps, 212 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
- ASK / LoGO:
    pn53x_usb:002:023
chip: PN533 v2.7
initator mode modulations: ISO/IEC 14443A (106 kbps), FeliCa (424 kbps, 212 kbps), ISO/IEC 14443-4B (847 kbps, 424 kbps, 212 kbps, 106 kbps), Innovision Jewel (106 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
target mode modulations: ISO/IEC 14443A (106 kbps), FeliCa (424 kbps, 212 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)

After:

$ nfc-scan-device -v
3 NFC device(s) found:
- ACS / ACR122U PICC Interface:
    acr122_usb:002:024
chip: PN532 v1.4
initator mode modulations: ISO/IEC 14443A (424 kbps, 212 kbps, 106 kbps), FeliCa (424 kbps, 212 kbps), ISO/IEC 14443-4B (106 kbps), ISO/IEC 14443-4B' (106 kbps), ISO/IEC 14443-2B ST SRx (106 kbps), ISO/IEC 14443-2B ASK CTx (106 kbps), Innovision Jewel (106 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
target mode modulations: ISO/IEC 14443A (424 kbps, 212 kbps, 106 kbps), FeliCa (424 kbps, 212 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
- SCM Micro / SCL3711-NFC&RW:
    pn53x_usb:002:025
chip: PN533 v2.7
initator mode modulations: ISO/IEC 14443A (847 kbps, 424 kbps, 212 kbps, 106 kbps), FeliCa (424 kbps, 212 kbps), ISO/IEC 14443-4B (847 kbps, 424 kbps, 212 kbps, 106 kbps), ISO/IEC 14443-4B' (106 kbps), ISO/IEC 14443-2B ST SRx (106 kbps), ISO/IEC 14443-2B ASK CTx (106 kbps), Innovision Jewel (106 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
target mode modulations: ISO/IEC 14443A (424 kbps, 212 kbps, 106 kbps), FeliCa (424 kbps, 212 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
- ASK / LoGO:
    pn53x_usb:002:023
chip: PN533 v2.7
initator mode modulations: ISO/IEC 14443A (847 kbps, 424 kbps, 212 kbps, 106 kbps), FeliCa (424 kbps, 212 kbps), ISO/IEC 14443-4B (847 kbps, 424 kbps, 212 kbps, 106 kbps), ISO/IEC 14443-4B' (106 kbps), ISO/IEC 14443-2B ST SRx (106 kbps), ISO/IEC 14443-2B ASK CTx (106 kbps), Innovision Jewel (106 kbps), D.E.P. (424 kbps, 212 kbps, 106 kbps)
target mode modulations:
2014-03-12 00:00:08 +01:00
Philippe Teuwen
89fc6a723e make style 2014-03-11 00:25:33 +01:00
Philippe Teuwen
ddde2dd8f2 initiator_select_passive_target(): now supports all speeds for ISO14443-4A tags 2014-03-11 00:13:26 +01:00
Philippe Teuwen
108de27c1b Fix typo baud<>bauds thanks to Polluks 2014-03-05 17:48:55 +01:00
Philippe Teuwen
6b74323369 target_is_present(): remove unreachable code 2014-03-04 01:47:42 +01:00
Philippe Teuwen
6ab3c368b8 nfc-emulate-uid: remove unreachable code and add proper cleaning when interrupted 2014-03-04 01:41:01 +01:00
Philippe Teuwen
db4fae9c2c Remove unreachable statements
As seen with clang -Wunreachable-code
2014-03-04 01:39:12 +01:00
Philippe Teuwen
7adad098c3 Document -Wunreachable-code in HACKING file 2014-03-04 01:38:44 +01:00
119 changed files with 8665 additions and 2032 deletions

86
.gitignore vendored
View File

@ -1,16 +1,21 @@
**/.deps/
**/.libs/
**/Makefile
**/Makefile.in
*.exe
*.la
*.lo
*.o
*~ *~
.vs/
CMakeSettings.json
Doxyfile Doxyfile
INSTALL INSTALL
Makefile
Makefile.in
aclocal.m4 aclocal.m4
ar-lib ar-lib
autom4te.cache/ autom4te.cache/
build build
cmake/Makefile compile
cmake/Makefile.in
cmake/modules/Makefile
cmake/modules/Makefile.in
config.guess config.guess
config.h config.h
config.h.in config.h.in
@ -18,24 +23,8 @@ config.log
config.status config.status
config.sub config.sub
configure configure
contrib/Makefile
contrib/Makefile.in
contrib/devd/Makefile
contrib/devd/Makefile.in
contrib/udev/Makefile
contrib/udev/Makefile.in
contrib/win32/Makefile
contrib/win32/Makefile.in
contrib/win32/sys/Makefile
contrib/win32/sys/Makefile.in
debian/ debian/
depcomp depcomp
examples/*.o
examples/.deps/
examples/.libs/
examples/Makefile
examples/Makefile.in
examples/doc/.deps/
examples/nfc-anticol examples/nfc-anticol
examples/nfc-dep-initiator examples/nfc-dep-initiator
examples/nfc-dep-target examples/nfc-dep-target
@ -48,44 +37,10 @@ examples/nfc-relay
examples/pn53x-diagnose examples/pn53x-diagnose
examples/pn53x-sam examples/pn53x-sam
examples/pn53x-tamashell examples/pn53x-tamashell
examples/pn53x-tamashell-scripts/Makefile
examples/pn53x-tamashell-scripts/Makefile.in
examples/quick_start_example1 examples/quick_start_example1
examples/quick_start_example2 examples/quick_start_example2
include/Makefile
include/Makefile.in
include/nfc/Makefile
include/nfc/Makefile.in
install-sh install-sh
libnfc.pc libnfc.pc
libnfc/*.lo
libnfc/*.o
libnfc/.deps/
libnfc/.libs/
libnfc/Makefile
libnfc/Makefile.in
libnfc/buses/*.la
libnfc/buses/*.lo
libnfc/buses/*.o
libnfc/buses/.deps/
libnfc/buses/.libs/
libnfc/buses/Makefile
libnfc/buses/Makefile.in
libnfc/chips/*.la
libnfc/chips/*.lo
libnfc/chips/*.o
libnfc/chips/.deps/
libnfc/chips/.libs/
libnfc/chips/Makefile
libnfc/chips/Makefile.in
libnfc/drivers/*.la
libnfc/drivers/*.lo
libnfc/drivers/*.o
libnfc/drivers/.deps/
libnfc/drivers/.libs/
libnfc/drivers/Makefile
libnfc/drivers/Makefile.in
libnfc/libnfc.la
libtool libtool
ltmain.sh ltmain.sh
m4/libtool.m4 m4/libtool.m4
@ -95,21 +50,12 @@ m4/ltversion.m4
m4/lt~obsolete.m4 m4/lt~obsolete.m4
missing missing
stamp-h1 stamp-h1
test/*.la test-driver
test/*.lo test/run-test.sh.log
test/*.o test/run-test.sh.trs
test/.deps/ test/test-suite.log
test/.libs/
test/Makefile
test/Makefile.in
utils/*.la
utils/*.lo
utils/*.o
utils/.deps/
utils/.libs/
utils/Makefile
utils/Makefile.in
utils/nfc-emulate-forum-tag4 utils/nfc-emulate-forum-tag4
utils/nfc-jewel
utils/nfc-list utils/nfc-list
utils/nfc-mfclassic utils/nfc-mfclassic
utils/nfc-mfultralight utils/nfc-mfultralight

81
.travis.yml Normal file
View File

@ -0,0 +1,81 @@
language: c
matrix:
include:
- os: windows
compiler:
- clang
before_install:
- mkdir build && cd build && wget "https://sourceforge.net/projects/libusb-win32/files/libusb-win32-releases/1.2.6.0/libusb-win32-bin-1.2.6.0.zip" && 7z x libusb-win32-bin-1.2.6.0.zip -o"$PROGRAMFILES" && mv "$PROGRAMFILES/libusb-win32-bin-1.2.6.0" "$PROGRAMFILES/libusb-win32"
install:
choco install doxygen.install ninja
script:
cmake -GNinja .. && cmake --build .
- os: linux
dist: bionic
compiler:
- clang
addons:
apt:
packages:
- libusb-dev
- doxygen
- cmake
script:
- mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX=~/.local .. && make -j2 && make install
- os: linux
dist: bionic
compiler:
- clang
addons:
apt:
packages:
- libusb-dev
- doxygen
script:
- autoreconf -vfi && mkdir build && cd build && ../configure --prefix=$HOME/.local/ && make -j2 && make install
- os: linux
dist: bionic
compiler:
- gcc
addons:
apt:
packages:
- libusb-dev
- doxygen
- cmake
script:
- mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX=~/.local .. && make -j2 && make install
- os: linux
dist: bionic
compiler:
- gcc
addons:
apt:
packages:
- libusb-dev
- doxygen
script:
- autoreconf -vfi && mkdir build && cd build && ../configure --prefix=$HOME/.local/ && make -j2 && make install
- os: osx
osx_image: xcode12
compiler:
- clang
before_install:
- brew install doxygen libusb-compat
script:
- mkdir build && cd build && cmake -DCMAKE_INSTALL_PREFIX=~/.local .. && make -j2 && make install
- os: osx
osx_image: xcode12
compiler:
- clang
before_install:
- brew install doxygen libusb-compat m4
script:
- autoreconf -vfi && mkdir build && cd build && ../configure --prefix=$HOME/.local/ && make -j2 && make install

26
AUTHORS
View File

@ -2,22 +2,48 @@
Adam Laurie <adam@algroup.co.uk> Adam Laurie <adam@algroup.co.uk>
Ahti Legonkov <ahti.legonkov@gmail.com> Ahti Legonkov <ahti.legonkov@gmail.com>
Alex Lian <alian@alum.mit.edu> Alex Lian <alian@alum.mit.edu>
Alexander Inyukhin <shurick@sectorb.msk.ru>
Anugrah Redja Kusuma <anugrah.redja@gmail.com> Anugrah Redja Kusuma <anugrah.redja@gmail.com>
Audrey Diacre <adiacre@il4p.fr> Audrey Diacre <adiacre@il4p.fr>
Boris Moiseev <cyberbobs@gmail.com>
Christoph Gritschenberger <christoph.gritschenberger@gmail.com>
Dario Carluccio <dario.carluccio@gmail.com>
David Kreitschmann <david@kreitschmann.de>
Emanuele Bertoldi <emanuele.bertoldi@gmail.com> Emanuele Bertoldi <emanuele.bertoldi@gmail.com>
Emmanuel Dreyfus <manu@netbsd.org>
Eugeny Boger <eugenyboger@gmail.com> Eugeny Boger <eugenyboger@gmail.com>
Francois Kooman <fkooman@tuxed.net> Francois Kooman <fkooman@tuxed.net>
Frank Morgner <frankmorgner@gmail.com>
Frédéric Bourgeois <bourgeoislab@gmail.com>
Hidde Wieringa <hidde@hiddewieringa.nl>
Jairo Andres Suarez <andres4005@gmail.com>
Jiapeng Li <gapleehit@gmail.com> Jiapeng Li <gapleehit@gmail.com>
Jim Anastassiou <jim.anastassiou@gmail.com>
John Galt <centromere@users.noreply.github.com>
Julien Ehrhart <julien.ehrhart@live.com>
Julien Schueller <julien.schueller@gmail.com> Julien Schueller <julien.schueller@gmail.com>
Laurent Latil <laurent@latil.nom.fr> Laurent Latil <laurent@latil.nom.fr>
Ludovic Rousseau <ludovic.rousseau@gmail.com> Ludovic Rousseau <ludovic.rousseau@gmail.com>
Marcello Morena <marcello.morena@gmail.com> Marcello Morena <marcello.morena@gmail.com>
Marcos Vives Del Sol <socram8888@gmail.com>
Mati Vait <mativait@gmail.com>
Maxim Martyanov <llorephie@gmail.com>
Mike Auty <mike.auty@gmail.com> Mike Auty <mike.auty@gmail.com>
Nobuhiro Iwamatsu <iwamatsu@nigauri.org> Nobuhiro Iwamatsu <iwamatsu@nigauri.org>
Olliver Schinagl <oliver@schinagl.nl>
Paul Menzel <paul.menzel@giantmonkey.de>
Peter Meerwald <pmeerw@pmeerw.net> Peter Meerwald <pmeerw@pmeerw.net>
Philippe Teuwen <yobibe@gmail.com> Philippe Teuwen <yobibe@gmail.com>
Pim 't Hart <pimmeyproductions@gmail.com> Pim 't Hart <pimmeyproductions@gmail.com>
Ray Lee <rayleesky@outlook.com>
Roel Verdult <roel@libnfc.org> Roel Verdult <roel@libnfc.org>
Romain Tartiere <romain.tartiere@gmail.com> Romain Tartiere <romain.tartiere@gmail.com>
Romuald Conty <romuald@libnfc.org> Romuald Conty <romuald@libnfc.org>
Simon Yorkston <simon.yorkston@gmail.com>
bhack <s.fabri@email.it>
lego <lego@debian-fresh.prx> lego <lego@debian-fresh.prx>
quantum-x <simon.yorkston@gmail.com>
timzi <developers@make-gadget.ru>
xantares <xantares09@hotmail.com>
xaqq <kapp.arno@gmail.com>
yerzhanm <yerzhan.mukhamejan@gmail.com>

View File

@ -1,8 +1,14 @@
PROJECT(libnfc C) cmake_minimum_required (VERSION 2.6)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
if (NOT DEFINED CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release CACHE STRING "Build type")
endif ()
project (libnfc C)
SET(VERSION_MAJOR "1") SET(VERSION_MAJOR "1")
SET(VERSION_MINOR "7") SET(VERSION_MINOR "8")
SET(VERSION_PATCH "1") SET(VERSION_PATCH "0")
SET(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") SET(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
@ -12,29 +18,33 @@ SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
# config.h # config.h
IF(WIN32) IF(WIN32)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_windows.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h) SET(LIBNFC_SYSCONFDIR "./config" CACHE PATH "libnfc configuration directory")
SET(LIBNFC_SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/config" CACHE PATH "libnfc configuration directory") CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_windows.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32)
IF(NOT MINGW)
SET(CMAKE_C_FLAGS "-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE ${CMAKE_C_FLAGS}")
ENDIF(NOT MINGW)
ELSE(WIN32) ELSE(WIN32)
SET(_XOPEN_SOURCE 600) SET(_XOPEN_SOURCE 600)
SET(SYSCONFDIR "/etc" CACHE PATH "System configuration directory") SET(SYSCONFDIR "/etc" CACHE PATH "System configuration directory")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_posix.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config_posix.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
ENDIF(WIN32) ENDIF(WIN32)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
ADD_DEFINITIONS("-DHAVE_CONFIG_H") ADD_DEFINITIONS("-DHAVE_CONFIG_H")
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include)
# make it easy to locate CMake modules for finding libraries # make it easy to locate CMake modules for finding libraries
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules/") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules/")
# Options # Options
SET(LIBNFC_LOG ON CACHE BOOL "Enable log facility (errors, warning, info and debug messages)") option (LIBNFC_LOG "Enable log facility (errors, warning, info and debug messages)" ON)
IF(LIBNFC_LOG) IF(LIBNFC_LOG)
ADD_DEFINITIONS(-DLOG) ADD_DEFINITIONS(-DLOG)
ENDIF(LIBNFC_LOG) ENDIF(LIBNFC_LOG)
SET(LIBNFC_ENVVARS ON CACHE BOOL "Enable envvars facility") option (LIBNFC_ENVVARS "Enable envvars facility" ON)
IF(LIBNFC_ENVVARS) IF(LIBNFC_ENVVARS)
ADD_DEFINITIONS(-DENVVARS) ADD_DEFINITIONS(-DENVVARS)
ENDIF(LIBNFC_ENVVARS) ENDIF(LIBNFC_ENVVARS)
@ -49,11 +59,17 @@ ELSE(LIBNFC_DEBUG_MODE)
SET(WIN32_MODE "release") SET(WIN32_MODE "release")
ENDIF(LIBNFC_DEBUG_MODE) ENDIF(LIBNFC_DEBUG_MODE)
SET(LIBNFC_CONFFILES_MODE ON CACHE BOOL "Enable configuration files") option (LIBNFC_CONFFILES_MODE "Enable configuration files" ON)
IF(LIBNFC_CONFFILES_MODE) IF(LIBNFC_CONFFILES_MODE)
ADD_DEFINITIONS(-DCONFFILES) ADD_DEFINITIONS(-DCONFFILES)
ENDIF(LIBNFC_CONFFILES_MODE) ENDIF(LIBNFC_CONFFILES_MODE)
option (BUILD_EXAMPLES "build examples ON/OFF" ON)
option (BUILD_UTILS "build utils ON/OFF" ON)
option (BUILD_DEBPKG "build debian package ON/OFF" OFF)
# Doxygen # Doxygen
SET(builddir "${CMAKE_BINARY_DIR}") SET(builddir "${CMAKE_BINARY_DIR}")
SET(top_srcdir "${CMAKE_SOURCE_DIR}") SET(top_srcdir "${CMAKE_SOURCE_DIR}")
@ -87,12 +103,34 @@ ENDIF(CMAKE_COMPILER_IS_GNUCC)
ADD_DEFINITIONS(-Du_int8_t=uint8_t -Du_int16_t=uint16_t) ADD_DEFINITIONS(-Du_int8_t=uint8_t -Du_int16_t=uint16_t)
IF(MINGW) IF(MINGW)
# force MinGW-w64 in 32bit mode IF (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
SET(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}") # force MinGW-w64 in 32bit mode
SET(CMAKE_MODULE_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}") SET(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
SET(CMAKE_SHARED_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}") SET(CMAKE_MODULE_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}")
SET(CMAKE_EXE_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_EXE_LINKER_FLAGS}") SET(CMAKE_SHARED_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}")
SET(CMAKE_RC_FLAGS "--target=pe-i386 --output-format=coff ${CMAKE_RC_FLAGS}") SET(CMAKE_EXE_LINKER_FLAGS "-m32 -Wl,--enable-stdcall-fixup ${CMAKE_EXE_LINKER_FLAGS}")
SET(CMAKE_RC_FLAGS "--target=pe-i386 --output-format=coff ${CMAKE_RC_FLAGS}")
ELSE(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
IF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
# force MinGW-w64 in 32bit mode
MESSAGE("Building 32-bit Windows DLL")
#SET(CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
#SET(CMAKE_MODULE_LINKER_FLAGS "--Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}")
#SET(CMAKE_SHARED_LINKER_FLAGS "--Wl,--enable-stdcall-fixup ${CMAKE_SHARED_LINKER_FLAGS}")
#SET(CMAKE_EXE_LINKER_FLAGS "--Wl,--enable-stdcall-fixup ${CMAKE_EXE_LINKER_FLAGS}")
SET(CMAKE_RC_FLAGS "--target=pe-i386 --output-format=coff ${CMAKE_RC_FLAGS}")
ELSEIF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
MESSAGE("Building 64-bit Windows DLL")
SET(CMAKE_RC_FLAGS "--target=pe-x86-64 --output-format=coff ${CMAKE_RC_FLAGS}")
ELSE(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
MESSAGE(FATAL_ERROR "Unknown Processor: ${CMAKE_SYSTEM_PROCESSOR}")
ENDIF(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
ENDIF(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
FIND_PROGRAM(DLLTOOL dlltool CMAKE_FIND_ROOT_PATH_BOTH)
IF (NOT DLLTOOL)
MESSAGE(FATAL_ERROR "Could not find dlltool command")
ENDIF (NOT DLLTOOL)
ENDIF(MINGW) ENDIF(MINGW)
IF(NOT WIN32) IF(NOT WIN32)
@ -103,26 +141,39 @@ IF(NOT WIN32)
IF(LIBNFC_DRIVER_PN53X_USB) IF(LIBNFC_DRIVER_PN53X_USB)
SET(PKG_REQ ${PKG_REQ} "libusb") SET(PKG_REQ ${PKG_REQ} "libusb")
ENDIF(LIBNFC_DRIVER_PN53X_USB) ENDIF(LIBNFC_DRIVER_PN53X_USB)
IF(LIBNFC_DRIVER_ACR122) IF(LIBNFC_DRIVER_ACR122_USB)
SET(PKG_REQ ${PKG_REQ} "libusb")
ENDIF(LIBNFC_DRIVER_ACR122_USB)
IF(LIBNFC_DRIVER_PCSC)
SET(PKG_REQ ${PKG_REQ} "libpcsclite") SET(PKG_REQ ${PKG_REQ} "libpcsclite")
ENDIF(LIBNFC_DRIVER_ACR122) ENDIF(LIBNFC_DRIVER_PCSC)
IF(LIBNFC_DRIVER_ACR122_PCSC)
SET(PKG_REQ ${PKG_REQ} "libpcsclite")
ENDIF(LIBNFC_DRIVER_ACR122_PCSC)
# CMake lists are separated by a semi colon, replace with colon # CMake lists are separated by a semi colon, replace with colon
STRING(REPLACE ";" "," PKG_CONFIG_REQUIRES "${PKG_REQ}") STRING(REPLACE ";" "," PKG_CONFIG_REQUIRES "${PKG_REQ}")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libnfc.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libnfc.pc @ONLY) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libnfc.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libnfc.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libnfc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libnfc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
ENDIF(NOT WIN32) ENDIF(NOT WIN32)
# Require PCRE for Win32
IF (WIN32)
FIND_PACKAGE(PCRE REQUIRED)
IF(PCRE_INCLUDE_DIRS)
INCLUDE_DIRECTORIES(${PCRE_INCLUDE_DIRS})
LINK_DIRECTORIES(${PCRE_LIBRARY_DIRS})
ENDIF(PCRE_INCLUDE_DIRS)
ENDIF(WIN32)
INCLUDE(LibnfcDrivers) INCLUDE(LibnfcDrivers)
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
IF(I2C_REQUIRED)
# Inspired from http://cmake.3232098.n2.nabble.com/RFC-cmake-analog-to-AC-SEARCH-LIBS-td7585423.html
INCLUDE (CheckFunctionExists)
INCLUDE (CheckLibraryExists)
CHECK_FUNCTION_EXISTS (clock_gettime HAVE_CLOCK_GETTIME)
IF (NOT HAVE_CLOCK_GETTIME)
CHECK_LIBRARY_EXISTS (rt clock_gettime "" HAVE_CLOCK_GETTIME_IN_RT)
IF (HAVE_CLOCK_GETTIME_IN_RT)
SET(LIBRT_FOUND TRUE)
SET(LIBRT_LIBRARIES "rt")
ENDIF (HAVE_CLOCK_GETTIME_IN_RT)
ENDIF (NOT HAVE_CLOCK_GETTIME)
ENDIF(I2C_REQUIRED)
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
IF(PCSC_INCLUDE_DIRS) IF(PCSC_INCLUDE_DIRS)
INCLUDE_DIRECTORIES(${PCSC_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${PCSC_INCLUDE_DIRS})
LINK_DIRECTORIES(${PCSC_LIBRARY_DIRS}) LINK_DIRECTORIES(${PCSC_LIBRARY_DIRS})
@ -137,36 +188,117 @@ ENDIF(LIBUSB_INCLUDE_DIRS)
# version.rc for Windows # version.rc for Windows
IF(WIN32) IF(WIN32)
# Date for filling in rc file information # Date for filling in rc file information
MACRO (GET_CURRENT_YEAR RESULT) IF (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
EXECUTE_PROCESS(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT}) MACRO (GET_CURRENT_YEAR RESULT)
STRING(REGEX REPLACE "\n" "" ${RESULT} ${${RESULT}}) EXECUTE_PROCESS(COMMAND "cmd" " /C date /T" OUTPUT_VARIABLE ${RESULT})
STRING(REGEX REPLACE ".*(..)/(..)/(....).*" "\\3" ${RESULT} ${${RESULT}}) STRING(REGEX REPLACE "\n" "" ${RESULT} ${${RESULT}})
ENDMACRO (GET_CURRENT_YEAR) STRING(REGEX REPLACE ".*(..)/(..)/(....).*" "\\3" ${RESULT} ${${RESULT}})
ENDMACRO (GET_CURRENT_YEAR)
ELSE(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
MACRO (GET_CURRENT_YEAR RESULT)
EXECUTE_PROCESS(COMMAND "date" "+%Y" OUTPUT_VARIABLE ${RESULT})
STRING(REGEX REPLACE "\n" "" ${RESULT} ${${RESULT}})
ENDMACRO (GET_CURRENT_YEAR)
ENDIF(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
GET_CURRENT_YEAR(CURRENT_YEAR) GET_CURRENT_YEAR(CURRENT_YEAR)
MESSAGE("Year for copyright is " ${CURRENT_YEAR}) MESSAGE("Year for copyright is " ${CURRENT_YEAR})
SET(prefix ${CMAKE_INSTALL_PREFIX})
SET(RC_COMMENT "${PACKAGE_NAME} library") SET(RC_COMMENT "${PACKAGE_NAME} library")
SET(RC_INTERNAL_NAME "${PACKAGE_NAME} ${WIN32_MODE}") SET(RC_INTERNAL_NAME "${PACKAGE_NAME} ${WIN32_MODE}")
SET(RC_ORIGINAL_NAME ${PACKAGE_NAME}.dll) SET(RC_ORIGINAL_NAME ${PACKAGE_NAME}.dll)
SET(RC_FILE_TYPE VFT_DLL) # RC_FILE_TYPE: VFT_DLL
SET(RC_FILE_TYPE 0x00000002L)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/windows/libnfc.rc @ONLY) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/windows/libnfc.rc @ONLY)
ENDIF(WIN32) ENDIF(WIN32)
ADD_SUBDIRECTORY(libnfc) ADD_SUBDIRECTORY(libnfc)
ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(utils)
ADD_SUBDIRECTORY(examples) if (BUILD_UTILS)
add_subdirectory (utils)
endif ()
if (BUILD_EXAMPLES)
add_subdirectory (examples)
endif ()
if (NOT MSVC)
# config script install path
if ( NOT DEFINED LIBNFC_CMAKE_CONFIG_DIR )
set ( LIBNFC_CMAKE_CONFIG_DIR lib${LIB_SUFFIX}/cmake/libnfc )
endif ()
set ( LIBNFC_INCLUDE_DIR ${includedir} )
set ( LIBNFC_INCLUDE_DIRS ${LIBNFC_INCLUDE_DIR} )
list ( APPEND LIBNFC_INCLUDE_DIRS ${LIBUSB_INCLUDE_DIRS} )
set ( LIBNFC_LIBRARY nfc )
set ( LIBNFC_LIBRARIES ${LIBNFC_LIBRARY} )
list ( APPEND LIBNFC_LIBRARIES ${LIBUSB_LIBRARIES} )
set ( LIBNFC_LIBRARY_DIRS ${libdir} )
set ( LIBNFC_ROOT_DIR ${prefix} )
set ( LIBNFC_VERSION_STRING ${VERSION} )
set ( LIBNFC_VERSION_MAJOR ${VERSION_MAJOR} )
set ( LIBNFC_VERSION_MINOR ${VERSION_MINOR} )
set ( LIBNFC_VERSION_PATCH ${VERSION_PATCH} )
set ( LIBNFC_USE_FILE ${CMAKE_INSTALL_PREFIX}/${LIBNFC_CMAKE_CONFIG_DIR}/UseLibNFC.cmake )
if(CMAKE_VERSION VERSION_LESS 2.8.8)
configure_file ( cmake/LibNFCConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/LibNFCConfig.cmake @ONLY )
configure_file ( cmake/LibNFCConfigVersion.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/LibNFCConfigVersion.cmake @ONLY )
else ()
include(CMakePackageConfigHelpers)
configure_package_config_file (
cmake/LibNFCConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/LibNFCConfig.cmake
INSTALL_DESTINATION ${LIBNFC_CMAKE_CONFIG_DIR}
PATH_VARS
LIBNFC_USE_FILE
LIBNFC_ROOT_DIR
LIBNFC_INCLUDE_DIR
LIBNFC_INCLUDE_DIRS
LIBNFC_LIBRARY_DIRS
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
write_basic_package_version_file (
LibNFCConfigVersion.cmake
VERSION ${LIBNFC_VERSION_STRING}
COMPATIBILITY AnyNewerVersion
)
endif ()
install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/LibNFCConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/LibNFCConfigVersion.cmake
cmake/UseLibNFC.cmake
DESTINATION ${LIBNFC_CMAKE_CONFIG_DIR}
)
endif ()
# Binary Package # Binary Package
IF(WIN32) IF(WIN32)
SET(CPACK_GENERATOR "ZIP") SET(CPACK_GENERATOR "ZIP")
ELSE(WIN32) ELSE(WIN32)
SET(CPACK_GENERATOR "TBZ2") SET(CPACK_GENERATOR "TBZ2")
IF(BUILD_DEBPKG)
SET(CPACK_GENERATOR "DEB")
ENDIF(BUILD_DEBPKG)
ENDIF(WIN32) ENDIF(WIN32)
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Near Field Communication (NFC) library") SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Near Field Communication (NFC) library")
SET(CPACK_PACKAGE_VENDOR "Roel Verdult") SET(CPACK_PACKAGE_VENDOR "Roel Verdult")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") SET(CPACK_PACKAGE_CONTACT "Roel Verdult <roel@libnfc.org>")
#Readme file
IF(WIN32)
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README-Windows.md")
ELSE(WIN32)
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
ENDIF(WIN32)
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "libnfc") SET(CPACK_PACKAGE_INSTALL_DIRECTORY "libnfc")
SET(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}) SET(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})

View File

@ -1,5 +1,88 @@
May 22, 2020 - 1.8.0
--------------------
Fixes:
- Restore nfc_modulation_type enum order to keep compatibility with libnfc 1.7.1
Changes:
- Bump revision due to changes in API introduced in v1.7.2
- Bump library version to 6.0.0
May 21, 2020 - 1.7.2 (avoid using it, incompatible with 1.7.1)
--------------------
Fixes:
- Remove unreachable code
- nfc_emulate_uid: cleaner exit on interrupt
- Fix reporting of modulations and baud rates by nfc-scan-device -v
- Fix out-of-bounds access in nfc-mfultralight
- Several Cygwin compilation fixes
- Fix comparison when nfc_initiator_target_is_present() with a specified target
- Fix nfc_initiator_poll_target without tag on PN532
- Export iso14443b* symbols
- Fix udev rule which was executed too early
- Fix improper device name initialization
- Fix setenv()/unsetenv() for Windows
- Fix win32/nfc.def according to nfc.h
- Fix missing timeout in pn53x_initiator_select_passive_target()
- nfc-mfclassic: fix option to tolerate write errors
- nfc-poll: fix card removing check
- nfc-relay-picc: fix wrong open mode for file descriptor
Improvements:
- Allow ISO14443A to be used at higher baud rates
- nfc_initiator_select_passive_target() now checks against
reported modulations and baud rates for current device
- More serial devices on MAC OS X
- Add section to README to help to configure libnfc
- Various cmake improvements
- Drop PCRE dependency on Windows
- Remove deprecated readdir_r
- Markdown conversion of the text files
- Use hardcoded PN533 descriptors to be more robust on Windows
- Add support for SCL3712
- Add support for ACR1222U-C1
- Add support for NetBSD
- Add support for PN532 on RPi3 UART
- Add support for cross-compilation of 32b & 64b versions of the library for Windows
- Add pn533_usb to the kernel modules blacklist
- Add support for pn71xx NXP's NFC Controllers through Linux Libnfc-nci (untested)
- Add support for contactless PC/SC readers (only as initiator)
- Add support for Feitian R502 and bR500 into pcsc driver
- Add support for HID iClass (Picopass) support (nfc-iclass tool in external nfc-tools repo)
- Allows for sending empty data in nfc_initiator_transceive_bits
- driver i2c: respect proper timing specifications
- driver i2c: add retry on error mechanism
- nfc-mfclassic: improvements fo magic cards
- nfc-mfclassic: add option to specify UID
- nfc-mfclassic/nfc-mfsetuid: add support for new gen (1b) of magic 4K cards
- nfc-mfclassic: Add RATS support indicator
- nfc-mfsetuid: allow to write complete Block0, instead of only UID
- nfc-mfultralight: add automatic modes and --check-magic
- nfc-mfultralight: add support for magic gen2 cards
- nfc-mfultralight: add option to specify UID
- nfc-mfultralight: add support for Ultralight NTAG213/215/216
- nfc-barcode: new command to read and decode NFC Barcodes (Tag-Talks-First)
Changes:
- nfc_device_get_supported_baud_rate() takes now a "mode" parameter
- New nfc_device_get_supported_baud_rate_target_mode()
- New NFC modulation type NMT_BARCODE and nfc_barcode_info struct to support Thinfilm NFC Barcode protocol
- New NFC modulation type NMT_ISO14443BICLASS and NMT_ISO14443BICLASS struct to support HID iClass (Picopass)
- pn53x_transceive() is now part of public API
Special thanks to:
- Jim Anastassiou, Frédéric Bourgeois, Dario Carluccio, Emmanuel Dreyfus,
Julien Ehrhart, S. Fabri, John Galt, Christoph Gritschenberger,
Alexander Inyukhin, Arnaud Kapp, David Kreitschmann, Adam Laurie, Ray Lee,
Maxim Martyanov, Paul Menzel, Boris Moiseev, Yerzhan Mukhamejan,
Olliver Shinagl, Jairo Andres Suarez, Mati Vait, Marcos Vives Del Sol,
Hidde Wieringa, Simon Yorkston, timzi, usk-johnny-s, xantares, Hanno
Heinrichs, jgeslin, Mikolaj Stawiski, rstular, Khem Raj, Frank Morgner, jpwidera,
Feitian Technologies
Feb 24, 2014 - 1.7.1 Feb 24, 2014 - 1.7.1
------------------ --------------------
Fixes: Fixes:
- Fix several issues reported by Coverity Scan - Fix several issues reported by Coverity Scan

File diff suppressed because it is too large Load Diff

54
HACKING
View File

@ -1,54 +0,0 @@
Hello hackers!
General remarks about contributing
----------------------------------
Contributions to the libnfc are welcome!
Here are some directions to get you started:
1. Follow style conventions
The source code of the library trend to follow some conventions so that it
is consistent in style and thus easier to read.
Look around and respect the same style.
Don't use tabs. Increment unit is two spaces.
Don't leave dandling spaces or tabs at EOL.
Helper script to get some uniformity in the style:
$ make style
If you use vim see the "Vim: How to prevent trailing whitespaces"
http://www.carbon-project.org/Vim__How_to_prevent_trailing_whitespaces.html
2. Chase warnings: no warning should be introduced by your changes
Depending what you touch, you can check with:
2.1 When using autotools
$ autoreconf -Wall -vis
2.2 When compiling
2.2.1 Using extra flags:
$ export CFLAGS="-Wall -g -O2 -Wextra -pipe -funsigned-char -fstrict-aliasing \
-Wchar-subscripts -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wunused \
-Wuninitialized -Wpointer-arith -Wredundant-decls -Winline -Wformat \
-Wformat-security -Wswitch-enum -Winit-self -Wmissing-include-dirs \
-Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition \
-Wbad-function-cast -Wnested-externs -Wmissing-declarations"
$ ./configure
$ make clean
$ make
2.2.2 Using clang:
$ scan-build ./configure
$ make clean
$ scan-build make
2.2.3 Using cppcheck (v1.58 or higher):
$ make cppcheck
2.3 When Debianizing
$ lintian --info --display-info --display-experimental *deb
or (shorter version)
$ lintian -iIE *deb
3. Preserve cross-platform compatility
The source code should remain compilable across various platforms,
including some you probably cannot test alone so keep it in mind.
Supported platforms:
- Linux
- FreeBSD
- Mac OS X
- Windows with Mingw

68
HACKING.md Normal file
View File

@ -0,0 +1,68 @@
Hello hackers!
General remarks about contributing
----------------------------------
Contributions to the libnfc are welcome!
Here are some directions to get you started:
1. Follow style conventions
The source code of the library trend to follow some conventions so that it
is consistent in style and thus easier to read.
Look around and respect the same style.
Don't use tabs. Increment unit is two spaces.
Don't leave dandling spaces or tabs at EOL.
Helper script to get some uniformity in the style:
$ make style
If you use vim see the [Vim: How to prevent trailing whitespaces](http://www.carbon-project.org/Vim__How_to_prevent_trailing_whitespaces.html).
2. Chase warnings: no warning should be introduced by your changes
Depending what you touch, you can check with:
2.1 When using autotools
$ autoreconf -Wall -vis
2.2 When compiling
2.2.1 Using extra flags:
$ export CFLAGS="-Wall -g -O2 -Wextra -pipe -funsigned-char -fstrict-aliasing \
-Wchar-subscripts -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wunused \
-Wuninitialized -Wpointer-arith -Wredundant-decls -Winline -Wformat \
-Wformat-security -Wswitch-enum -Winit-self -Wmissing-include-dirs \
-Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition \
-Wbad-function-cast -Wnested-externs -Wmissing-declarations"
$ ./configure
$ make clean
$ make
2.2.2 Using clang:
You can use same CFLAGS but also `-Wunreachable-code`
$ scan-build ./configure
$ make clean
$ scan-build make
2.2.3 Using `cppcheck` (v1.58 or higher):
$ make cppcheck
2.3 When Debianizing
$ lintian --info --display-info --display-experimental *deb
or (shorter version)
$ lintian -iIE *deb
3. Preserve cross-platform compatibility
The source code should remain compilable across various platforms,
including some you probably cannot test alone so keep it in mind.
Supported platforms:
- Linux
- FreeBSD
- Mac OS X
- Windows with MinGW

View File

@ -2,7 +2,13 @@ ACLOCAL_AMFLAGS = -I m4
AM_CFLAGS = $(LIBNFC_CFLAGS) AM_CFLAGS = $(LIBNFC_CFLAGS)
SUBDIRS = libnfc utils examples include contrib cmake test SUBDIRS = libnfc utils
if EXAMPLE_ENABLED
SUBDIRS += examples
endif
SUBDIRS += include contrib cmake test
pkgconfigdir = $(libdir)/pkgconfig pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = libnfc.pc pkgconfig_DATA = libnfc.pc
@ -10,8 +16,12 @@ pkgconfig_DATA = libnfc.pc
EXTRA_DIST = \ EXTRA_DIST = \
CMakeLists.txt \ CMakeLists.txt \
Doxyfile \ Doxyfile \
README-Windows.txt \ HACKING.md \
libnfc.conf.sample NEWS.md \
README.md \
README-Windows.md \
libnfc.conf.sample \
mingw-cross-compile.sh
CLEANFILES = Doxygen.log coverage.info libnfc.pc CLEANFILES = Doxygen.log coverage.info libnfc.pc
@ -34,7 +44,7 @@ style:
find . -name "*.[ch]" -exec astyle --formatted --mode=c --suffix=none \ find . -name "*.[ch]" -exec astyle --formatted --mode=c --suffix=none \
--indent=spaces=2 --indent-switches --indent-preprocessor \ --indent=spaces=2 --indent-switches --indent-preprocessor \
--keep-one-line-blocks --max-instatement-indent=60 \ --keep-one-line-blocks --max-instatement-indent=60 \
--brackets=linux --pad-oper --unpad-paren --pad-header \ --style=linux --pad-oper --unpad-paren --pad-header \
--align-pointer=name {} \; --align-pointer=name {} \;
cppcheck: cppcheck:

View File

@ -1,3 +1,24 @@
New in 1.8.0:
API Changes:
- Restore nfc_modulation_type enum order to keep compatibility with libnfc 1.7.1
- Bump library version to 6.0.0
New in 1.7.2:
Drivers:
* New driver for pn71xx NXP's NFC Controllers through Linux Libnfc-nci (untested)
* New driver for contactless PC/SC readers (only as initiator)
API Changes:
* nfc_device_get_supported_baud_rate() now takes also "mode" as argument
* New nfc_device_get_supported_baud_rate_target_mode()
* New NFC modulation type NMT_BARCODE and nfc_barcode_info struct to support Thinfilm NFC Barcode protocol
* New NFC modulation type NMT_ISO14443BICLASS and NMT_ISO14443BICLASS struct to support HID iClass (Picopass)
* pn53x_transceive() is now part of public API
New in 1.7.1: New in 1.7.1:
API Changes: API Changes:

166
README
View File

@ -1,166 +0,0 @@
*-
* Free/Libre Near Field Communication (NFC) library
*
* Libnfc historical contributors:
* Copyright (C) 2009 Roel Verdult
* Copyright (C) 2009-2013 Romuald Conty
* Copyright (C) 2010-2012 Romain Tartière
* Copyright (C) 2010-2013 Philippe Teuwen
* Copyright (C) 2012-2013 Ludovic Rousseau
* Additional contributors:
* See AUTHORS file
-*
General Information
===================
libnfc is a library which allows userspace application access to NFC devices.
The official web site is:
http://www.nfc-tools.org/
The official forum site is:
http://www.libnfc.org/community/
The official development site is:
http://libnfc.googlecode.com/
Important note: this file covers POSIX systems, for Windows please read README-Windows.txt
Requirements
============
Some NFC drivers depend on third party software:
* pn53x_usb & acr122_usb:
- libusb-0.1 http://libusb.sf.net
* acr122_pcsc:
- pcsc-lite http://pcsclite.alioth.debian.org/
The regression test suite depends on the cutter framework:
http://cutter.sf.net
Installation
============
See the file 'INSTALL' for configure, build and install details.
Additionnally, you may need to grant permissions to your user to drive your device.
Under GNU/Linux systems, if you use udev, you could use the provided udev rules.
e.g. under Debian, Ubuntu, etc.
sudo cp contrib/udev/42-pn53x.rules /lib/udev/rules.d/
Under FreeBSD, if you use devd, there is also a rules file: contrib/devd/pn53x.conf.
How to report bugs
==================
To report a bug, visit http://code.google.com/p/libnfc/issues/list and fill
out a bug report form.
If you have questions, remarks, we encourage you to post this in the developers
community:
http://www.libnfc.org/community
Please make sure to include:
* The version of libnfc
* Information about your system. For instance:
- What operating system and version
- For Linux, what version of the C library
And anything else you think is relevant.
* A trace with debug activated.
Reproduce the bug with debug, e.g. if it was:
$ nfc-list -v
run it as:
$ LIBNFC_LOG_LEVEL=3 nfc-list -v
* How to reproduce the bug.
Please include a short test program that exhibits the behavior.
As a last resort, you can also provide a pointer to a larger piece
of software that can be downloaded.
* If the bug was a crash, the exact text that was printed out
when the crash occured.
* Further information such as stack traces may be useful, but
is not necessary.
Patches
=======
Patches can be posted to http://code.google.com/p/libnfc/issues/list or
can be sent directly to libnfc's developers:
http://nfc-tools.org/index.php?title=Contact
If the patch fixes a bug, it is usually a good idea to include
all the information described in "How to Report Bugs".
Building
========
It should be as simple as running these two commands:
./configure
make
Troubleshooting
===============
Touchatag/ACR122:
-----------------
If your Touchatag or ACR122 device fails being detected by libnfc, make sure
that PCSC-lite daemon (pcscd) is installed and is running.
If your Touchatag or ACR122 device fails being detected by PCSC-lite daemon
(pcsc_scan doesn't see anything) then try removing the bogus firmware detection
of libccid: edit libccid_Info.plist configuration file (usually
/etc/libccid_Info.plist) and locate "<key>ifdDriverOptions</key>", turn
"<string>0x0000</string>" value into 0x0004 to allow bogus devices and restart
pcscd daemon.
ACR122:
-------
Using an ACR122 device with libnfc and without tag (e.g. to use NFCIP modes or
card emulation) needs yet another PCSC-lite tweak: You need to allow usage of
CCID Exchange command. To do this, edit libccid_Info.plist configuration file
(usually /etc/libccid_Info.plist) and locate "<key>ifdDriverOptions</key>",
turn "<string>0x0000</string>" value into 0x0001 to allow CCID exchange or
0x0005 to allow CCID exchange and bogus devices (cf previous remark) and
restart pcscd daemon.
Warning: if you use ACS CCID drivers (acsccid), configuration file is located
in something like: /usr/lib/pcsc/drivers/ifd-acsccid.bundle/Contents/Info.plist
SCL3711:
--------
Libnfc cannot be used concurrently with the PCSC proprietary driver of SCL3711.
Two possible solutions:
* Either you don't install SCL3711 driver at all
* Or you stop the PCSC daemon when you want to use libnfc-based tools
PN533 USB device on Linux >= 3.1:
---------------------------------
Since Linux kernel version 3.1, two kernel-modules must not be loaded in order
to use libnfc : "nfc" and "pn533".
To prevent kernel from loading automatically these modules, you can blacklist
them in a modprobe conf file. This file is provided within libnfc archive:
sudo cp contrib/linux/blacklist-libnfc.conf /etc/modprobe.d/blacklist-libnfc.conf
Proprietary Notes
=================
FeliCa is s registered trademark of the Sony Corporation.
MIFARE is a trademark of NXP Semiconductors.
Jewel Topaz is a trademark of Innovision Research & Technology.
All other trademarks are the property of their respective owners.

View File

@ -1,16 +1,16 @@
*- *-
* Free/Libre Near Field Communication (NFC) library * Free/Libre Near Field Communication (NFC) library
* *
* Libnfc historical contributors: * Libnfc historical contributors:
* Copyright (C) 2009 Roel Verdult * Copyright (C) 2009 Roel Verdult
* Copyright (C) 2009-2013 Romuald Conty * Copyright (C) 2009-2013 Romuald Conty
* Copyright (C) 2010-2012 Romain Tartière * Copyright (C) 2010-2012 Romain Tartière
* Copyright (C) 2010-2013 Philippe Teuwen * Copyright (C) 2010-2013 Philippe Teuwen
* Copyright (C) 2012-2013 Ludovic Rousseau * Copyright (C) 2012-2013 Ludovic Rousseau
* Additional contributors of Windows-specific parts: * Additional contributors of Windows-specific parts:
* Copyright (C) 2010 Glenn Ergeerts * Copyright (C) 2010 Glenn Ergeerts
* Copyright (C) 2013 Alex Lian * Copyright (C) 2013 Alex Lian
-* -*
Requirements Requirements
============ ============
@ -18,7 +18,6 @@ Requirements
- MinGW-w64 compiler toolchain [1] - MinGW-w64 compiler toolchain [1]
- LibUsb-Win32 1.2.5.0 (or greater) [2] - LibUsb-Win32 1.2.5.0 (or greater) [2]
- CMake 2.8 [3] - CMake 2.8 [3]
- PCRE for Windows [4]
This was tested on Windows 7 64 bit, but should work on Windows Vista and This was tested on Windows 7 64 bit, but should work on Windows Vista and
Windows XP and 32 bit as well. Windows XP and 32 bit as well.
@ -34,13 +33,15 @@ is an example of how to generate a distribution with the above mentioned
requirements fulfilled (it is assumed the CMake binaries are in the system requirements fulfilled (it is assumed the CMake binaries are in the system
path, this is optional during installation of CMake): path, this is optional during installation of CMake):
- Add the following directories to your PATH : c:\MinGW64\bin;c:\MinGW64\x86_64-w64-mingw32\lib32;c:\MinGW64\x86_64-w64-mingw32\include - Add the following directories to your PATH:
c:\MinGW64\bin;c:\MinGW64\x86_64-w64-mingw32\lib32;c:\MinGW64\x86_64-w64-mingw32\include
- Now it is possible to run CMake and mingw32-make: - Now it is possible to run CMake and mingw32-make:
C:\dev\libnfc-read-only> mkdir ..\libnfc-build C:\dev\libnfc-read-only> mkdir ..\libnfc-build
C:\dev\libnfc-read-only> cd ..\libnfc-build C:\dev\libnfc-read-only> cd ..\libnfc-build
C:\dev\libnfc-build> cmake-gui . C:\dev\libnfc-build> cmake-gui .
Now you can configure the build. Press "Configure", specify "MinGW32 Makefiles" Now you can configure the build. Press "Configure", specify "MinGW32 Makefiles"
and then you have the opportunity to set some configuration variables. If you and then you have the opportunity to set some configuration variables. If you
@ -48,12 +49,12 @@ don't want a Debug build change the variable CMAKE_BUILD_TYPE to "Release".
If a non-GUI solution is preferred one can use: If a non-GUI solution is preferred one can use:
C:\dev\libnfc-build> cmake -G "MinGW Makefiles" C:\dev\libnfc-build> cmake -G "MinGW Makefiles"
-DCMAKE_BUILD_TYPE=Release ..\libnfc-read-only -DCMAKE_BUILD_TYPE=Release ..\libnfc-read-only
Now run mingw32-make to build: Now run mingw32-make to build:
C:\dev\libnfc-read-only\bin> mingw32-make C:\dev\libnfc-read-only\bin> mingw32-make
The build will create a shared library for Windows (nfc.dll) to link your applications against. It will compile The build will create a shared library for Windows (nfc.dll) to link your applications against. It will compile
the tools against this shared library. the tools against this shared library.
@ -63,6 +64,7 @@ References
[1] the easiest way is to use the TDM-GCC installer. [1] the easiest way is to use the TDM-GCC installer.
Make sure to select MinGW-w64 in the installer, the regular MinGW does not contain headers for PCSC. Make sure to select MinGW-w64 in the installer, the regular MinGW does not contain headers for PCSC.
http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/tdm64-gcc-4.5.1.exe/download http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Installer/tdm64-gcc-4.5.1.exe/download
[2] http://sourceforge.net/projects/libusb-win32/files/ [2] http://sourceforge.net/projects/libusb-win32/files/
[3] http://www.cmake.org [3] http://www.cmake.org
[4] http://gnuwin32.sourceforge.net/packages/pcre.htm

250
README.md Normal file
View File

@ -0,0 +1,250 @@
```
*-
* Free/Libre Near Field Communication (NFC) library
*
* Libnfc historical contributors:
* Copyright (C) 2009 Roel Verdult
* Copyright (C) 2009-2015 Romuald Conty
* Copyright (C) 2010-2012 Romain Tartière
* Copyright (C) 2010-2013 Philippe Teuwen
* Copyright (C) 2012-2013 Ludovic Rousseau
* Additional contributors:
* See AUTHORS file
-*
```
General Information
===================
libnfc is a library which allows userspace application access to NFC devices.
The official web site is:
http://www.nfc-tools.org/
The official forum site is:
http://www.libnfc.org/community/
The official development site is:
https://github.com/nfc-tools/libnfc
Important note: this file covers POSIX systems, for Windows please read README-Windows.md
Requirements
============
Some NFC drivers depend on third party software:
* pn53x_usb & acr122_usb:
- libusb-0.1 http://libusb.sf.net
* acr122_pcsc:
- pcsc-lite https://pcsclite.apdu.fr/
- pcsc:
- Support build with pcsc driver, which can be using all compatible readers, Feitian R502 and bR500 already passed the test.
The regression test suite depends on the cutter framework:
http://cutter.sf.net
Building
========
Note: If working directly from a git clone of the repository, some of the files need to be generated first. To do this run
`autoreconf -vis`
Alternatively use a .tar.bz2 version of a packaged release (which already contains ./configure):
https://github.com/nfc-tools/libnfc/releases/
The build should be as simple as running these commands:
./configure
make
To build with specific driver(s), see option `--with-drivers=...` detailed in `./configure --help`.
Installation
============
make install
You may need to grant permissions to your user to drive your device.
Under GNU/Linux systems, if you use udev, you could use the provided udev rules.
e.g. under Debian, Ubuntu, etc.
sudo cp contrib/udev/93-pn53x.rules /lib/udev/rules.d/
Under FreeBSD, if you use devd, there is also a rules file: contrib/devd/pn53x.conf.
Configuration
=============
In order to change the default behavior of the library, the libnfc uses a
configuration file located in sysconfdir (as provided to ./configure).
A sample commented file is available in sources: libnfc.conf.sample
If you have compiled using:
./configure --prefix=/usr --sysconfdir=/etc
you can make configuration directory and copy the sample file:
sudo mkdir /etc/nfc
sudo cp libnfc.conf.sample /etc/nfc/libnfc.conf
To configure multiple devices, you can either modify libnfc.conf or create a
file per device in a nfc/devices.d directory:
sudo mkdir -p /etc/nfc/devices.d
printf 'name = "My first device"\nconnstring = "pn532_uart:/dev/ttyACM0"\n' | sudo tee /etc/nfc/devices.d/first.conf
printf 'name = "My second device"\nconnstring = "pn532_uart:/dev/ttyACM1"\n' | sudo tee /etc/nfc/devices.d/second.conf
Environment Variables
=====================
You can override certain configuration options at runtime using the following environment variables:
+ `LIBNFC_DEFAULT_DEVICE=<connstring>`: `LIBNFC_DEFAULT_DEVICE=pn532_uart:/dev/ttyACM0` will use pn532 on /dev/ttyACM0 as default device
+ `LIBNFC_DEVICE=<connstring>` will ignore all devices in the config files and use only the one defined in the variable
+ `LIBNFC_AUTO_SCAN=<true|false>` overrides `allow_autoscan` option in the config file
+ `LIBNFC_INTRUSIVE_SCAN=<true|false>` overrides `allow_intrusive_scan` option in the config file
+ `LIBNFC_LOG_LEVEL=<0|1|2|3>` overrides `log_level` option in the config file
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.
How to report bugs
==================
To report a bug, visit https://github.com/nfc-tools/libnfc/issues and fill
out a bug report form.
If you have questions, remarks, we encourage you to post this in the developers
community:
http://www.libnfc.org/community
Please make sure to include:
* The version of libnfc
* Information about your system. For instance:
- What operating system and version
- For Linux, what version of the C library
And anything else you think is relevant.
* A trace with debug activated.
Reproduce the bug with debug, e.g. if it was:
$ nfc-list -v
run it as:
$ LIBNFC_LOG_LEVEL=3 nfc-list -v
* How to reproduce the bug.
Please include a short test program that exhibits the behavior.
As a last resort, you can also provide a pointer to a larger piece
of software that can be downloaded.
* If the bug was a crash, the exact text that was printed out
when the crash occured.
* Further information such as stack traces may be useful, but
is not necessary.
Patches
=======
Patches can be posted to https://github.com/nfc-tools/libnfc/issues
If the patch fixes a bug, it is usually a good idea to include
all the information described in "How to Report Bugs".
Troubleshooting
===============
Touchatag/ACR122:
-----------------
If your Touchatag or ACR122 device fails being detected by libnfc, make sure
that PCSC-lite daemon (`pcscd`) is installed and is running.
If your Touchatag or ACR122 device fails being detected by PCSC-lite daemon
(`pcsc_scan` doesn't see anything) then try removing the bogus firmware detection
of libccid: edit libccid_Info.plist configuration file (usually
`/etc/libccid_Info.plist`) and locate `<key>ifdDriverOptions</key>`, turn
`<string>0x0000</string>` value into `0x0004` to allow bogus devices and restart
pcscd daemon.
ACR122:
-------
Using an ACR122 device with libnfc and without tag (e.g. to use NFCIP modes or
card emulation) needs yet another PCSC-lite tweak: You need to allow usage of
CCID Exchange command. To do this, edit `libccid_Info.plist` configuration file
(usually `/etc/libccid_Info.plist`) and locate `<key>ifdDriverOptions</key>`,
turn `<string>0x0000</string>` value into `0x0001` to allow CCID exchange or
`0x0005` to allow CCID exchange and bogus devices (cf previous remark) and
restart pcscd daemon.
Warning: if you use ACS CCID drivers (acsccid), configuration file is located
in something like: `/usr/lib/pcsc/drivers/ifd-acsccid.bundle/Contents/Info.plist`
SCL3711:
--------
Libnfc cannot be used concurrently with the PCSC proprietary driver of SCL3711.
Two possible solutions:
* Either you don't install SCL3711 driver at all
* Or you stop the PCSC daemon when you want to use libnfc-based tools
PN533 USB device on Linux >= 3.1:
---------------------------------
Since Linux kernel version 3.1, a few kernel-modules must not be loaded in order
to use libnfc : "nfc", "pn533" and "pn533_usb".
To prevent kernel from loading automatically these modules, you can blacklist
them in a modprobe conf file. This file is provided within libnfc archive:
sudo cp contrib/linux/blacklist-libnfc.conf /etc/modprobe.d/blacklist-libnfc.conf
FEITIAN bR500 and R502:
-----------------------
Libnfc can work with PCSC proprietary driver of bR500 and R502, which is already available on most Linux setups.
To activate the PCSC support: `./configure --with-drivers=pcsc`.
Readers known to work:
- Feitian bR500
- Feitian R502 Dual interface reader
- Feitian R502 CL(Contactless) reader
These readers are support by CCID since v1.4.25, make sure your CCID driver version higher or equal to 1.4.25.
On MacOS, you can check your CCID version with the following command, and if required, you can install latest CCID driver from [https://github.com/martinpaljak/osx-ccid-installer/releases](https://github.com/martinpaljak/osx-ccid-installer/releases)
```
grep -A 1 CFBundleShortVersionString /usr/local/libexec/SmartCardServices/drivers/ifd-ccid.bundle/Contents/Info.plist
```
On Linux, you can check your CCID version with the following command, and if required, you can install latest CCID driver from [https://ccid.apdu.fr/](https://ccid.apdu.fr/)
```
grep -A 1 CFBundleShortVersionString /usr/lib/pcsc/drivers/ifd-ccid.bundle/Contents/Info.plist
```
Proprietary Notes
=================
FeliCa is a registered trademark of the Sony Corporation.
MIFARE is a trademark of NXP Semiconductors.
Jewel Topaz is a trademark of Innovision Research & Technology.
All other trademarks are the property of their respective owners.

View File

@ -6,6 +6,6 @@ SET(bundle "${CMAKE_INSTALL_PREFIX}/bin/nfc-list@CMAKE_EXECUTABLE_SUFFIX@")
# set other_libs to a list of additional libs that cannot be reached by dependency analysis # set other_libs to a list of additional libs that cannot be reached by dependency analysis
SET(other_libs "") SET(other_libs "")
SET(dirs "@LIBUSB_LIBRARY_DIR@" "@PCRE_BIN_DIRS@") SET(dirs "@LIBUSB_LIBRARY_DIR@")
fixup_bundle("${bundle}" "${other_libs}" "${dirs}") fixup_bundle("${bundle}" "${other_libs}" "${dirs}")

View File

@ -0,0 +1,34 @@
# -*- cmake -*-
# Use the following variables to compile and link against LibNFC:
# LIBNFC_FOUND - True if LibNFC was found on your system
# LIBNFC_USE_FILE - The file making LibNFC usable
# LIBNFC_DEFINITIONS - Definitions needed to build with LibNFC
# LIBNFC_INCLUDE_DIR - Directory where nfc/nfc.h can be found
# LIBNFC_INCLUDE_DIRS - List of directories of LibNFC and it's dependencies
# LIBNFC_LIBRARY - LibNFC library location
# LIBNFC_LIBRARIES - List of libraries to link against LibNFC library
# LIBNFC_LIBRARY_DIRS - List of directories containing LibNFC' libraries
# LIBNFC_ROOT_DIR - The base directory of LibNFC
# LIBNFC_VERSION_STRING - A human-readable string containing the version
# LIBNFC_VERSION_MAJOR - The major version of LibNFC
# LIBNFC_VERSION_MINOR - The minor version of LibNFC
# LIBNFC_VERSION_PATCH - The patch version of LibNFC
set ( LIBNFC_FOUND 1 )
set ( LIBNFC_USE_FILE "@LIBNFC_USE_FILE@" )
set ( LIBNFC_DEFINITIONS "@LIBNFC_DEFINITIONS@" )
set ( LIBNFC_INCLUDE_DIR "@LIBNFC_INCLUDE_DIR@" )
set ( LIBNFC_INCLUDE_DIRS "@LIBNFC_INCLUDE_DIRS@" )
set ( LIBNFC_LIBRARY "@LIBNFC_LIBRARY@" )
set ( LIBNFC_LIBRARIES "@LIBNFC_LIBRARIES@" )
set ( LIBNFC_LIBRARY_DIRS "@LIBNFC_LIBRARY_DIRS@" )
set ( LIBNFC_ROOT_DIR "@LIBNFC_ROOT_DIR@" )
set ( LIBNFC_VERSION_STRING "@LIBNFC_VERSION_STRING@" )
set ( LIBNFC_VERSION_MAJOR "@LIBNFC_VERSION_MAJOR@" )
set ( LIBNFC_VERSION_MINOR "@LIBNFC_VERSION_MINOR@" )
set ( LIBNFC_VERSION_PATCH "@LIBNFC_VERSION_PATCH@" )

View File

@ -0,0 +1,31 @@
# This is a basic version file for the Config-mode of find_package().
# It is used by write_basic_package_version_file() as input file for configure_file()
# to create a version-file which can be installed along a config.cmake file.
#
# The created file sets PACKAGE_VERSION_EXACT if the current version string and
# the requested version string are exactly the same and it sets
# PACKAGE_VERSION_COMPATIBLE if the current version is >= requested version.
# The variable CVF_VERSION must be set before calling configure_file().
set(PACKAGE_VERSION "@LIBNFC_VERSION_STRING@")
if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" )
set(PACKAGE_VERSION_COMPATIBLE FALSE)
else()
set(PACKAGE_VERSION_COMPATIBLE TRUE)
if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}")
set(PACKAGE_VERSION_EXACT TRUE)
endif()
endif()
# if the installed or the using project don't have CMAKE_SIZEOF_VOID_P set, ignore it:
if("${CMAKE_SIZEOF_VOID_P}" STREQUAL "" OR "8" STREQUAL "")
return()
endif()
# check that the installed version has the same 32/64bit-ness as the one which is currently searching:
if(NOT "${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
math(EXPR installedBits "8 * 8")
set(PACKAGE_VERSION "${PACKAGE_VERSION} (${installedBits}bit)")
set(PACKAGE_VERSION_UNSUITABLE TRUE)
endif()

View File

@ -3,4 +3,7 @@ SUBDIRS = modules
EXTRA_DIST = \ EXTRA_DIST = \
FixBundle.cmake.in \ FixBundle.cmake.in \
config_posix.h.cmake \ config_posix.h.cmake \
config_windows.h.cmake config_windows.h.cmake \
LibNFCConfig.cmake.in \
LibNFCConfigVersion.cmake.in \
UseLibNFC.cmake

5
cmake/UseLibNFC.cmake Normal file
View File

@ -0,0 +1,5 @@
# -*- cmake -*-
add_definitions ( ${LIBNFC_DEFINITIONS} )
include_directories ( ${LIBNFC_INCLUDE_DIRS} )
link_directories ( ${LIBNFC_LIBRARY_DIRS} )

View File

@ -26,9 +26,15 @@ ENDIF(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
IF(NOT LIBUSB_FOUND) IF(NOT LIBUSB_FOUND)
IF(WIN32) IF(WIN32)
FIND_PATH(LIBUSB_INCLUDE_DIRS lusb0_usb.h "$ENV{ProgramFiles}/LibUSB-Win32/include" NO_SYSTEM_ENVIRONMENT_PATH) IF(MINGW)
FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb PATHS "$ENV{ProgramFiles}/LibUSB-Win32/lib/gcc") FIND_PATH(LIBUSB_INCLUDE_DIRS lusb0_usb.h "${CMAKE_CURRENT_BINARY_DIR}/LibUSB-Win32/include" NO_SYSTEM_ENVIRONMENT_PATH)
SET(LIBUSB_LIBRARY_DIR "$ENV{ProgramFiles}/LibUSB-Win32/bin/x86/") FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb PATHS "${CMAKE_CURRENT_BINARY_DIR}/LibUSB-Win32/lib/gcc")
SET(LIBUSB_LIBRARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/LibUSB-Win32/bin/x86/")
ELSE(MINGW)
FIND_PATH(LIBUSB_INCLUDE_DIRS lusb0_usb.h "$ENV{ProgramW6432}/libusb-win32/include" NO_SYSTEM_ENVIRONMENT_PATH)
FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb PATHS "$ENV{ProgramW6432}/libusb-win32/lib/msvc_x64")
SET(LIBUSB_LIBRARY_DIR "$ENV{ProgramW6432}/libusb-win32/bin/amd64/")
ENDIF(MINGW)
# Must fix up variable to avoid backslashes during packaging # Must fix up variable to avoid backslashes during packaging
STRING(REGEX REPLACE "\\\\" "/" LIBUSB_LIBRARY_DIR ${LIBUSB_LIBRARY_DIR}) STRING(REGEX REPLACE "\\\\" "/" LIBUSB_LIBRARY_DIR ${LIBUSB_LIBRARY_DIR})
ELSE(WIN32) ELSE(WIN32)

View File

@ -1,42 +0,0 @@
# This CMake script wants to use pcre functionality needed for windows
# compilation. However, since PCRE isn't really a default install location
# there isn't much to search.
#
# Operating Systems Supported:
# - Windows (requires MinGW)
# Tested with Windows XP/Windows 7
#
# This should work for both 32 bit and 64 bit systems.
#
# Author: A. Lian <alex.lian@gmail.com>
#
IF(WIN32)
IF(NOT PCRE_FOUND)
FIND_PATH(PCRE_INCLUDE_DIRS regex.h)
FIND_LIBRARY(PCRE_LIBRARIES NAMES PCRE pcre)
FIND_PATH(PCRE_BIN_DIRS pcre3.dll)
IF(PCRE_INCLUDE_DIRS AND PCRE_LIBRARIES AND PCRE_BIN_DIRS)
SET(PCRE_FOUND TRUE)
ENDIF(PCRE_INCLUDE_DIRS AND PCRE_LIBRARIES AND PCRE_BIN_DIRS)
ENDIF(NOT PCRE_FOUND)
IF(PCRE_FOUND)
IF(NOT PCRE_FIND_QUIETLY)
MESSAGE(STATUS "Found PCRE: ${PCRE_LIBRARIES} ${PCRE_INCLUDE_DIRS} ${PCRE_BIN_DIRS}")
ENDIF (NOT PCRE_FIND_QUIETLY)
ELSE(PCRE_FOUND)
IF(PCRE_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find PCRE")
ENDIF(PCRE_FIND_REQUIRED)
ENDIF(PCRE_FOUND)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE DEFAULT_MSG
PCRE_LIBRARIES
PCRE_INCLUDE_DIRS
PCRE_BIN_DIRS
)
ENDIF(WIN32)

View File

@ -1,17 +1,24 @@
SET(LIBNFC_DRIVER_PCSC OFF CACHE BOOL "Enable PC/SC reader support (Depends on PC/SC)")
SET(LIBNFC_DRIVER_ACR122_PCSC OFF CACHE BOOL "Enable ACR122 support (Depends on PC/SC)") SET(LIBNFC_DRIVER_ACR122_PCSC OFF CACHE BOOL "Enable ACR122 support (Depends on PC/SC)")
SET(LIBNFC_DRIVER_ACR122_USB ON CACHE BOOL "Enable ACR122 support (Direct USB connection)") SET(LIBNFC_DRIVER_ACR122_USB ON CACHE BOOL "Enable ACR122 support (Direct USB connection)")
SET(LIBNFC_DRIVER_ACR122S ON CACHE BOOL "Enable ACR122S support (Use serial port)") SET(LIBNFC_DRIVER_ACR122S ON CACHE BOOL "Enable ACR122S support (Use serial port)")
SET(LIBNFC_DRIVER_ARYGON ON CACHE BOOL "Enable ARYGON support (Use serial port)") SET(LIBNFC_DRIVER_ARYGON ON CACHE BOOL "Enable ARYGON support (Use serial port)")
IF(WIN32) IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
SET(LIBNFC_DRIVER_PN532_I2C OFF CACHE BOOL "Enable PN532 I2C support (Use I2C bus)")
SET(LIBNFC_DRIVER_PN532_SPI OFF CACHE BOOL "Enable PN532 SPI support (Use SPI bus)")
ELSE(WIN32)
SET(LIBNFC_DRIVER_PN532_I2C ON CACHE BOOL "Enable PN532 I2C support (Use I2C bus)") SET(LIBNFC_DRIVER_PN532_I2C ON CACHE BOOL "Enable PN532 I2C support (Use I2C bus)")
SET(LIBNFC_DRIVER_PN532_SPI ON CACHE BOOL "Enable PN532 SPI support (Use SPI bus)") SET(LIBNFC_DRIVER_PN532_SPI ON CACHE BOOL "Enable PN532 SPI support (Use SPI bus)")
ENDIF(WIN32) ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
SET(LIBNFC_DRIVER_PN532_I2C OFF CACHE BOOL "Enable PN532 I2C support (Use I2C bus)")
SET(LIBNFC_DRIVER_PN532_SPI OFF CACHE BOOL "Enable PN532 SPI support (Use SPI bus)")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
SET(LIBNFC_DRIVER_PN532_UART ON CACHE BOOL "Enable PN532 UART support (Use serial port)") SET(LIBNFC_DRIVER_PN532_UART ON CACHE BOOL "Enable PN532 UART support (Use serial port)")
SET(LIBNFC_DRIVER_PN53X_USB ON CACHE BOOL "Enable PN531 and PN531 USB support (Depends on libusb)") SET(LIBNFC_DRIVER_PN53X_USB ON CACHE BOOL "Enable PN531 and PN531 USB support (Depends on libusb)")
IF(LIBNFC_DRIVER_PCSC)
FIND_PACKAGE(PCSC REQUIRED)
ADD_DEFINITIONS("-DDRIVER_PCSC_ENABLED")
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/pcsc")
ENDIF(LIBNFC_DRIVER_PCSC)
IF(LIBNFC_DRIVER_ACR122_PCSC) IF(LIBNFC_DRIVER_ACR122_PCSC)
FIND_PACKAGE(PCSC REQUIRED) FIND_PACKAGE(PCSC REQUIRED)
ADD_DEFINITIONS("-DDRIVER_ACR122_PCSC_ENABLED") ADD_DEFINITIONS("-DDRIVER_ACR122_PCSC_ENABLED")
@ -61,4 +68,11 @@ IF(LIBNFC_DRIVER_PN53X_USB)
SET(USB_REQUIRED TRUE) SET(USB_REQUIRED TRUE)
ENDIF(LIBNFC_DRIVER_PN53X_USB) ENDIF(LIBNFC_DRIVER_PN53X_USB)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/drivers) IF(LIBNFC_DRIVER_ACR122_USB)
FIND_PACKAGE(LIBUSB REQUIRED)
ADD_DEFINITIONS("-DDRIVER_ACR122_USB_ENABLED")
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/acr122_usb")
SET(USB_REQUIRED TRUE)
ENDIF(LIBNFC_DRIVER_ACR122_USB)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/libnfc/drivers)

View File

@ -2,6 +2,5 @@ EXTRA_DIST = \
COPYING-CMAKE-SCRIPTS \ COPYING-CMAKE-SCRIPTS \
FindLIBUSB.cmake \ FindLIBUSB.cmake \
FindPCSC.cmake \ FindPCSC.cmake \
FindPCRE.cmake \
UseDoxygen.cmake \ UseDoxygen.cmake \
LibnfcDrivers.cmake LibnfcDrivers.cmake

View File

@ -91,8 +91,7 @@ if(DOXYGEN_FOUND AND DOXYFILE_IN)
configure_file(${DOXYFILE_IN} Doxyfile ESCAPE_QUOTES IMMEDIATE @ONLY) configure_file(${DOXYFILE_IN} Doxyfile ESCAPE_QUOTES IMMEDIATE @ONLY)
get_target_property(DOC_TARGET doc TYPE) if(NOT TARGET doc)
if(NOT DOC_TARGET)
add_custom_target(doc) add_custom_target(doc)
endif() endif()

View File

@ -1,7 +1,7 @@
# General init # General init
# /!\ Don't forget to update 'CMakeLists.txt' too /!\ # /!\ Don't forget to update 'CMakeLists.txt' too /!\
AC_INIT([libnfc],[1.7.1],[nfc-tools@googlegroups.com]) AC_INIT([libnfc],[1.8.0],[nfc-tools@googlegroups.com])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
@ -13,7 +13,7 @@ if test x"$GIT_REVISION" != x""; then
AC_DEFINE_UNQUOTED([GIT_REVISION], ["$GIT_REVISION"], [GIT revision]) AC_DEFINE_UNQUOTED([GIT_REVISION], ["$GIT_REVISION"], [GIT revision])
fi fi
AM_INIT_AUTOMAKE(subdir-objects dist-bzip2 no-dist-gzip) AM_INIT_AUTOMAKE(subdir-objects dist-bzip2 no-dist-gzip foreign)
m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
@ -47,6 +47,7 @@ AC_HEADER_STDBOOL
AC_CHECK_HEADERS([fcntl.h limits.h stdio.h stdlib.h stdint.h stddef.h stdbool.h sys/ioctl.h sys/param.h sys/time.h termios.h]) AC_CHECK_HEADERS([fcntl.h limits.h stdio.h stdlib.h stdint.h stddef.h stdbool.h sys/ioctl.h sys/param.h sys/time.h termios.h])
AC_CHECK_HEADERS([linux/spi/spidev.h], [spi_available="yes"]) AC_CHECK_HEADERS([linux/spi/spidev.h], [spi_available="yes"])
AC_CHECK_HEADERS([linux/i2c-dev.h], [i2c_available="yes"]) AC_CHECK_HEADERS([linux/i2c-dev.h], [i2c_available="yes"])
AC_CHECK_HEADERS([linux_nfc_api.h], [nfc_nci_available="yes"])
AC_CHECK_FUNCS([memmove memset select strdup strerror strstr strtol usleep], AC_CHECK_FUNCS([memmove memset select strdup strerror strstr strtol usleep],
[AC_DEFINE([_XOPEN_SOURCE], [600], [Enable POSIX extensions if present])]) [AC_DEFINE([_XOPEN_SOURCE], [600], [Enable POSIX extensions if present])])
@ -125,6 +126,20 @@ AM_CONDITIONAL(SPI_ENABLED, [test x"$spi_required" = x"yes"])
# Enable I2C if # Enable I2C if
AM_CONDITIONAL(I2C_ENABLED, [test x"$i2c_required" = x"yes"]) AM_CONDITIONAL(I2C_ENABLED, [test x"$i2c_required" = x"yes"])
if test x"$i2c_required" = x"yes"
then
AC_SEARCH_LIBS([clock_gettime], [rt])
fi
# Enable Libnfc-NCI if required
if test x"$nfc_nci_required" = x"yes"
then
PKG_CHECK_MODULES([LIBNFC_NCI], [libnfc-nci],
[AC_MSG_NOTICE([libnfc-nci present])],
[AC_MSG_ERROR([libnfc-nci not present but required for some drivers configuration])]
)
CFLAGS="$CFLAGS $LIBNFC_NCI_CFLAGS"
fi
# Documentation (default: no) # Documentation (default: no)
AC_ARG_ENABLE([doc],AS_HELP_STRING([--enable-doc],[Enable documentation generation.]),[enable_doc=$enableval],[enable_doc="no"]) AC_ARG_ENABLE([doc],AS_HELP_STRING([--enable-doc],[Enable documentation generation.]),[enable_doc=$enableval],[enable_doc="no"])
@ -142,6 +157,14 @@ then
fi fi
AM_CONDITIONAL(DOC_ENABLED, [test x"$enable_doc" = xyes]) AM_CONDITIONAL(DOC_ENABLED, [test x"$enable_doc" = xyes])
# Example build (default: yes)
AC_ARG_ENABLE([example],AS_HELP_STRING([--enable-example],[Enable example build.]),[enable_example=$enableval],[enable_example="yes"])
AC_MSG_CHECKING(for example build)
AC_MSG_RESULT($enable_example)
AM_CONDITIONAL(EXAMPLE_ENABLED, [test x"$enable_example" = xyes])
# Dependencies # Dependencies
PKG_CONFIG_REQUIRES="" PKG_CONFIG_REQUIRES=""
@ -160,7 +183,10 @@ if test x$ac_cv_with_cutter = xyes -a x$ac_cv_use_cutter = xno; then
fi fi
AM_CONDITIONAL([WITH_CUTTER], [test "$ac_cv_use_cutter" != "no"]) AM_CONDITIONAL([WITH_CUTTER], [test "$ac_cv_use_cutter" != "no"])
if test x"$enable_example" = "xyes"
then
AC_CHECK_READLINE AC_CHECK_READLINE
fi
# Help us to write great code ;-) # Help us to write great code ;-)
CFLAGS="$CFLAGS -Wall -pedantic -Wextra" CFLAGS="$CFLAGS -Wall -pedantic -Wextra"

View File

@ -1,4 +1,7 @@
EXTRA_DIST = \ EXTRA_DIST = \
pn532_via_uart2usb.conf.sample \ arygon.conf.sample \
arygon.conf.sample \ pn532_i2c_on_rpi.conf.sample \
pn532_uart_on_rpi.conf.sample pn532_spi_on_rpi.conf.sample \
pn532_uart_on_rpi_3.conf.sample \
pn532_uart_on_rpi.conf.sample \
pn532_via_uart2usb.conf.sample

View File

@ -0,0 +1,22 @@
## Typical configuration file for PN532 device on R-Pi 3 connected using miniUART
## Note: Changes have been made to R-Pi 3 with the addition of Bluetooth LE
## The UART is now being used by the BLE module. Instead of disabling it, you can
## use the PN532 device with the "mini UART", which is still hijacked by the linux kernel
## as a serial console
##
## Tested recipe with PN532 breakout from Adafruit
##
## To enable uart on GPIO, add this line to bottom of /boot/config.txt
## enable_uart=1
##
## Stop and disable serial console:
## $ sudo systemctl stop serial-getty@ttyS0.service
## $ sudo systemctl disable serial-getty@ttyS0.service
##
## Remove console from /boot/cmdline.txt by removing:
## console=serial0,115200 Save and reboot for changes to take effect.
##
name = "PN532 board via UART"
connstring = pn532_uart:/dev/ttyS0
allow_intrusive_scan = true

View File

@ -1,2 +1,3 @@
blacklist nfc blacklist nfc
blacklist pn533 blacklist pn533
blacklist pn533_usb

View File

@ -11,6 +11,7 @@ ATTRS{idVendor}=="054c", ATTRS{idProduct}=="0193", MODE="0664", GROUP="plugdev"
# PN533 # PN533
ATTRS{idVendor}=="04cc", ATTRS{idProduct}=="2533", MODE="0664", GROUP="plugdev" ATTRS{idVendor}=="04cc", ATTRS{idProduct}=="2533", MODE="0664", GROUP="plugdev"
ATTRS{idVendor}=="04e6", ATTRS{idProduct}=="5591", MODE="0664", GROUP="plugdev" ATTRS{idVendor}=="04e6", ATTRS{idProduct}=="5591", MODE="0664", GROUP="plugdev"
ATTRS{idVendor}=="04e6", ATTRS{idProduct}=="5594", MODE="0664", GROUP="plugdev"
ATTRS{idVendor}=="1fd3", ATTRS{idProduct}=="0608", MODE="0664", GROUP="plugdev" ATTRS{idVendor}=="1fd3", ATTRS{idProduct}=="0608", MODE="0664", GROUP="plugdev"
ATTRS{idVendor}=="054c", ATTRS{idProduct}=="02e1", MODE="0664", GROUP="plugdev" ATTRS{idVendor}=="054c", ATTRS{idProduct}=="02e1", MODE="0664", GROUP="plugdev"

View File

@ -1,2 +1,2 @@
EXTRA_DIST = \ EXTRA_DIST = \
42-pn53x.rules 93-pn53x.rules

870
contrib/win32/dirent.h Normal file
View File

@ -0,0 +1,870 @@
/*
* Dirent interface for Microsoft Visual Studio
*
* Copyright (C) 2006-2012 Toni Ronkko
* This file is part of dirent. Dirent may be freely distributed
* under the MIT license. For all details and documentation, see
* https://github.com/tronkko/dirent
*/
#ifndef DIRENT_H
#define DIRENT_H
/*
* Include windows.h without Windows Sockets 1.1 to prevent conflicts with
* Windows Sockets 2.0.
*/
#ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <stdio.h>
#include <stdarg.h>
#include <wchar.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
/* Indicates that d_type field is available in dirent structure */
#define _DIRENT_HAVE_D_TYPE
/* Indicates that d_namlen field is available in dirent structure */
#define _DIRENT_HAVE_D_NAMLEN
/* Entries missing from MSVC 6.0 */
#if !defined(FILE_ATTRIBUTE_DEVICE)
# define FILE_ATTRIBUTE_DEVICE 0x40
#endif
/* File type and permission flags for stat(), general mask */
#if !defined(S_IFMT)
# define S_IFMT _S_IFMT
#endif
/* Directory bit */
#if !defined(S_IFDIR)
# define S_IFDIR _S_IFDIR
#endif
/* Character device bit */
#if !defined(S_IFCHR)
# define S_IFCHR _S_IFCHR
#endif
/* Pipe bit */
#if !defined(S_IFFIFO)
# define S_IFFIFO _S_IFFIFO
#endif
/* Regular file bit */
#if !defined(S_IFREG)
# define S_IFREG _S_IFREG
#endif
/* Read permission */
#if !defined(S_IREAD)
# define S_IREAD _S_IREAD
#endif
/* Write permission */
#if !defined(S_IWRITE)
# define S_IWRITE _S_IWRITE
#endif
/* Execute permission */
#if !defined(S_IEXEC)
# define S_IEXEC _S_IEXEC
#endif
/* Pipe */
#if !defined(S_IFIFO)
# define S_IFIFO _S_IFIFO
#endif
/* Block device */
#if !defined(S_IFBLK)
# define S_IFBLK 0
#endif
/* Link */
#if !defined(S_IFLNK)
# define S_IFLNK 0
#endif
/* Socket */
#if !defined(S_IFSOCK)
# define S_IFSOCK 0
#endif
/* Read user permission */
#if !defined(S_IRUSR)
# define S_IRUSR S_IREAD
#endif
/* Write user permission */
#if !defined(S_IWUSR)
# define S_IWUSR S_IWRITE
#endif
/* Execute user permission */
#if !defined(S_IXUSR)
# define S_IXUSR 0
#endif
/* Read group permission */
#if !defined(S_IRGRP)
# define S_IRGRP 0
#endif
/* Write group permission */
#if !defined(S_IWGRP)
# define S_IWGRP 0
#endif
/* Execute group permission */
#if !defined(S_IXGRP)
# define S_IXGRP 0
#endif
/* Read others permission */
#if !defined(S_IROTH)
# define S_IROTH 0
#endif
/* Write others permission */
#if !defined(S_IWOTH)
# define S_IWOTH 0
#endif
/* Execute others permission */
#if !defined(S_IXOTH)
# define S_IXOTH 0
#endif
/* Maximum length of file name */
#if !defined(PATH_MAX)
# define PATH_MAX MAX_PATH
#endif
#if !defined(FILENAME_MAX)
# define FILENAME_MAX MAX_PATH
#endif
#if !defined(NAME_MAX)
# define NAME_MAX FILENAME_MAX
#endif
/* File type flags for d_type */
#define DT_UNKNOWN 0
#define DT_REG S_IFREG
#define DT_DIR S_IFDIR
#define DT_FIFO S_IFIFO
#define DT_SOCK S_IFSOCK
#define DT_CHR S_IFCHR
#define DT_BLK S_IFBLK
#define DT_LNK S_IFLNK
/* Macros for converting between st_mode and d_type */
#define IFTODT(mode) ((mode) & S_IFMT)
#define DTTOIF(type) (type)
/*
* File type macros. Note that block devices, sockets and links cannot be
* distinguished on Windows and the macros S_ISBLK, S_ISSOCK and S_ISLNK are
* only defined for compatibility. These macros should always return false
* on Windows.
*/
#if !defined(S_ISFIFO)
# define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO)
#endif
#if !defined(S_ISDIR)
# define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
#endif
#if !defined(S_ISREG)
# define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
#endif
#if !defined(S_ISLNK)
# define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
#endif
#if !defined(S_ISSOCK)
# define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK)
#endif
#if !defined(S_ISCHR)
# define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR)
#endif
#if !defined(S_ISBLK)
# define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
#endif
/* Return the exact length of the file name without zero terminator */
#define _D_EXACT_NAMLEN(p) ((p)->d_namlen)
/* Return the maximum size of a file name */
#define _D_ALLOC_NAMLEN(p) ((PATH_MAX)+1)
#ifdef __cplusplus
extern "C" {
#endif
/* Wide-character version */
struct _wdirent {
/* Always zero */
long d_ino;
/* File position within stream */
long d_off;
/* Structure size */
unsigned short d_reclen;
/* Length of name without \0 */
size_t d_namlen;
/* File type */
int d_type;
/* File name */
wchar_t d_name[PATH_MAX+1];
};
typedef struct _wdirent _wdirent;
struct _WDIR {
/* Current directory entry */
struct _wdirent ent;
/* Private file data */
WIN32_FIND_DATAW data;
/* True if data is valid */
int cached;
/* Win32 search handle */
HANDLE handle;
/* Initial directory name */
wchar_t *patt;
};
typedef struct _WDIR _WDIR;
/* Multi-byte character version */
struct dirent {
/* Always zero */
long d_ino;
/* File position within stream */
long d_off;
/* Structure size */
unsigned short d_reclen;
/* Length of name without \0 */
size_t d_namlen;
/* File type */
int d_type;
/* File name */
char d_name[PATH_MAX+1];
};
typedef struct dirent dirent;
struct DIR {
struct dirent ent;
struct _WDIR *wdirp;
};
typedef struct DIR DIR;
/* Dirent functions */
static DIR *opendir (const char *dirname);
static _WDIR *_wopendir (const wchar_t *dirname);
static struct dirent *readdir (DIR *dirp);
static int readdir_r(
DIR *dirp, struct dirent *entry, struct dirent **result);
static int closedir (DIR *dirp);
static int _wclosedir (_WDIR *dirp);
/* For compatibility with Symbian */
#define wdirent _wdirent
#define WDIR _WDIR
#define wopendir _wopendir
#define wreaddir _wreaddir
#define wclosedir _wclosedir
#define wrewinddir _wrewinddir
/* Internal utility functions */
static WIN32_FIND_DATAW *dirent_first (_WDIR *dirp);
static WIN32_FIND_DATAW *dirent_next (_WDIR *dirp);
static int dirent_mbstowcs_s(
size_t *pReturnValue,
wchar_t *wcstr,
size_t sizeInWords,
const char *mbstr,
size_t count);
static int dirent_wcstombs_s(
size_t *pReturnValue,
char *mbstr,
size_t sizeInBytes,
const wchar_t *wcstr,
size_t count);
static void dirent_set_errno (int error);
/*
* Open directory stream DIRNAME for read and return a pointer to the
* internal working area that is used to retrieve individual directory
* entries.
*/
static _WDIR*
_wopendir(
const wchar_t *dirname)
{
_WDIR *dirp = NULL;
int error;
/* Must have directory name */
if (dirname == NULL || dirname[0] == '\0') {
dirent_set_errno (ENOENT);
return NULL;
}
/* Allocate new _WDIR structure */
dirp = (_WDIR*) malloc (sizeof (struct _WDIR));
if (dirp != NULL) {
DWORD n;
/* Reset _WDIR structure */
dirp->handle = INVALID_HANDLE_VALUE;
dirp->patt = NULL;
dirp->cached = 0;
/* Compute the length of full path plus zero terminator
*
* Note that on WinRT there's no way to convert relative paths
* into absolute paths, so just assume it is an absolute path.
*/
# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
n = wcslen(dirname);
# else
n = GetFullPathNameW (dirname, 0, NULL, NULL);
# endif
/* Allocate room for absolute directory name and search pattern */
dirp->patt = (wchar_t*) malloc (sizeof (wchar_t) * n + 16);
if (dirp->patt) {
/*
* Convert relative directory name to an absolute one. This
* allows rewinddir() to function correctly even when current
* working directory is changed between opendir() and rewinddir().
*
* Note that on WinRT there's no way to convert relative paths
* into absolute paths, so just assume it is an absolute path.
*/
# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
wcsncpy_s(dirp->patt, n+1, dirname, n);
# else
n = GetFullPathNameW (dirname, n, dirp->patt, NULL);
# endif
if (n > 0) {
wchar_t *p;
/* Append search pattern \* to the directory name */
p = dirp->patt + n;
if (dirp->patt < p) {
switch (p[-1]) {
case '\\':
case '/':
case ':':
/* Directory ends in path separator, e.g. c:\temp\ */
/*NOP*/;
break;
default:
/* Directory name doesn't end in path separator */
*p++ = '\\';
}
}
*p++ = '*';
*p = '\0';
/* Open directory stream and retrieve the first entry */
if (dirent_first (dirp)) {
/* Directory stream opened successfully */
error = 0;
} else {
/* Cannot retrieve first entry */
error = 1;
dirent_set_errno (ENOENT);
}
} else {
/* Cannot retrieve full path name */
dirent_set_errno (ENOENT);
error = 1;
}
} else {
/* Cannot allocate memory for search pattern */
error = 1;
}
} else {
/* Cannot allocate _WDIR structure */
error = 1;
}
/* Clean up in case of error */
if (error && dirp) {
_wclosedir (dirp);
dirp = NULL;
}
return dirp;
}
/*
* Close directory stream opened by opendir() function. This invalidates the
* DIR structure as well as any directory entry read previously by
* _wreaddir().
*/
static int
_wclosedir(
_WDIR *dirp)
{
int ok;
if (dirp) {
/* Release search handle */
if (dirp->handle != INVALID_HANDLE_VALUE) {
FindClose (dirp->handle);
dirp->handle = INVALID_HANDLE_VALUE;
}
/* Release search pattern */
if (dirp->patt) {
free (dirp->patt);
dirp->patt = NULL;
}
/* Release directory structure */
free (dirp);
ok = /*success*/0;
} else {
/* Invalid directory stream */
dirent_set_errno (EBADF);
ok = /*failure*/-1;
}
return ok;
}
/* Get first directory entry (internal) */
static WIN32_FIND_DATAW*
dirent_first(
_WDIR *dirp)
{
WIN32_FIND_DATAW *datap;
/* Open directory and retrieve the first entry */
dirp->handle = FindFirstFileExW(
dirp->patt, FindExInfoStandard, &dirp->data,
FindExSearchNameMatch, NULL, 0);
if (dirp->handle != INVALID_HANDLE_VALUE) {
/* a directory entry is now waiting in memory */
datap = &dirp->data;
dirp->cached = 1;
} else {
/* Failed to re-open directory: no directory entry in memory */
dirp->cached = 0;
datap = NULL;
}
return datap;
}
/*
* Get next directory entry (internal).
*
* Returns
*/
static WIN32_FIND_DATAW*
dirent_next(
_WDIR *dirp)
{
WIN32_FIND_DATAW *p;
/* Get next directory entry */
if (dirp->cached != 0) {
/* A valid directory entry already in memory */
p = &dirp->data;
dirp->cached = 0;
} else if (dirp->handle != INVALID_HANDLE_VALUE) {
/* Get the next directory entry from stream */
if (FindNextFileW (dirp->handle, &dirp->data) != FALSE) {
/* Got a file */
p = &dirp->data;
} else {
/* The very last entry has been processed or an error occurred */
FindClose (dirp->handle);
dirp->handle = INVALID_HANDLE_VALUE;
p = NULL;
}
} else {
/* End of directory stream reached */
p = NULL;
}
return p;
}
/*
* Open directory stream using plain old C-string.
*/
static DIR*
opendir(
const char *dirname)
{
struct DIR *dirp;
int error;
/* Must have directory name */
if (dirname == NULL || dirname[0] == '\0') {
dirent_set_errno (ENOENT);
return NULL;
}
/* Allocate memory for DIR structure */
dirp = (DIR*) malloc (sizeof (struct DIR));
if (dirp) {
wchar_t wname[PATH_MAX + 1];
size_t n;
/* Convert directory name to wide-character string */
error = dirent_mbstowcs_s(
&n, wname, PATH_MAX + 1, dirname, PATH_MAX + 1);
if (!error) {
/* Open directory stream using wide-character name */
dirp->wdirp = _wopendir (wname);
if (dirp->wdirp) {
/* Directory stream opened */
error = 0;
} else {
/* Failed to open directory stream */
error = 1;
}
} else {
/*
* Cannot convert file name to wide-character string. This
* occurs if the string contains invalid multi-byte sequences or
* the output buffer is too small to contain the resulting
* string.
*/
error = 1;
}
} else {
/* Cannot allocate DIR structure */
error = 1;
}
/* Clean up in case of error */
if (error && dirp) {
free (dirp);
dirp = NULL;
}
return dirp;
}
/*
* Read next directory entry.
*/
static struct dirent*
readdir(
DIR *dirp)
{
struct dirent *entry;
/*
* Read directory entry to buffer. We can safely ignore the return value
* as entry will be set to NULL in case of error.
*/
(void) readdir_r (dirp, &dirp->ent, &entry);
/* Return pointer to statically allocated directory entry */
return entry;
}
/*
* Read next directory entry into called-allocated buffer.
*
* Returns zero on success. If the end of directory stream is reached, then
* sets result to NULL and returns zero.
*/
static int
readdir_r(
DIR *dirp,
struct dirent *entry,
struct dirent **result)
{
WIN32_FIND_DATAW *datap;
/* Read next directory entry */
datap = dirent_next (dirp->wdirp);
if (datap) {
size_t n;
int error;
/* Attempt to convert file name to multi-byte string */
error = dirent_wcstombs_s(
&n, entry->d_name, PATH_MAX + 1, datap->cFileName, PATH_MAX + 1);
/*
* If the file name cannot be represented by a multi-byte string,
* then attempt to use old 8+3 file name. This allows traditional
* Unix-code to access some file names despite of unicode
* characters, although file names may seem unfamiliar to the user.
*
* Be ware that the code below cannot come up with a short file
* name unless the file system provides one. At least
* VirtualBox shared folders fail to do this.
*/
if (error && datap->cAlternateFileName[0] != '\0') {
error = dirent_wcstombs_s(
&n, entry->d_name, PATH_MAX + 1,
datap->cAlternateFileName, PATH_MAX + 1);
}
if (!error) {
DWORD attr;
/* Length of file name excluding zero terminator */
entry->d_namlen = n - 1;
/* File attributes */
attr = datap->dwFileAttributes;
if ((attr & FILE_ATTRIBUTE_DEVICE) != 0) {
entry->d_type = DT_CHR;
} else if ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0) {
entry->d_type = DT_DIR;
} else {
entry->d_type = DT_REG;
}
/* Reset dummy fields */
entry->d_ino = 0;
entry->d_off = 0;
entry->d_reclen = sizeof (struct dirent);
} else {
/*
* Cannot convert file name to multi-byte string so construct
* an erroneous directory entry and return that. Note that
* we cannot return NULL as that would stop the processing
* of directory entries completely.
*/
entry->d_name[0] = '?';
entry->d_name[1] = '\0';
entry->d_namlen = 1;
entry->d_type = DT_UNKNOWN;
entry->d_ino = 0;
entry->d_off = -1;
entry->d_reclen = 0;
}
/* Return pointer to directory entry */
*result = entry;
} else {
/* No more directory entries */
*result = NULL;
}
return /*OK*/0;
}
/*
* Close directory stream.
*/
static int
closedir(
DIR *dirp)
{
int ok;
if (dirp) {
/* Close wide-character directory stream */
ok = _wclosedir (dirp->wdirp);
dirp->wdirp = NULL;
/* Release multi-byte character version */
free (dirp);
} else {
/* Invalid directory stream */
dirent_set_errno (EBADF);
ok = /*failure*/-1;
}
return ok;
}
/* Convert multi-byte string to wide character string */
static int
dirent_mbstowcs_s(
size_t *pReturnValue,
wchar_t *wcstr,
size_t sizeInWords,
const char *mbstr,
size_t count)
{
int error;
#if defined(_MSC_VER) && _MSC_VER >= 1400
/* Microsoft Visual Studio 2005 or later */
error = mbstowcs_s (pReturnValue, wcstr, sizeInWords, mbstr, count);
#else
/* Older Visual Studio or non-Microsoft compiler */
size_t n;
/* Convert to wide-character string (or count characters) */
n = mbstowcs (wcstr, mbstr, sizeInWords);
if (!wcstr || n < count) {
/* Zero-terminate output buffer */
if (wcstr && sizeInWords) {
if (n >= sizeInWords) {
n = sizeInWords - 1;
}
wcstr[n] = 0;
}
/* Length of resulting multi-byte string WITH zero terminator */
if (pReturnValue) {
*pReturnValue = n + 1;
}
/* Success */
error = 0;
} else {
/* Could not convert string */
error = 1;
}
#endif
return error;
}
/* Convert wide-character string to multi-byte string */
static int
dirent_wcstombs_s(
size_t *pReturnValue,
char *mbstr,
size_t sizeInBytes, /* max size of mbstr */
const wchar_t *wcstr,
size_t count)
{
int error;
#if defined(_MSC_VER) && _MSC_VER >= 1400
/* Microsoft Visual Studio 2005 or later */
error = wcstombs_s (pReturnValue, mbstr, sizeInBytes, wcstr, count);
#else
/* Older Visual Studio or non-Microsoft compiler */
size_t n;
/* Convert to multi-byte string (or count the number of bytes needed) */
n = wcstombs (mbstr, wcstr, sizeInBytes);
if (!mbstr || n < count) {
/* Zero-terminate output buffer */
if (mbstr && sizeInBytes) {
if (n >= sizeInBytes) {
n = sizeInBytes - 1;
}
mbstr[n] = '\0';
}
/* Length of resulting multi-bytes string WITH zero-terminator */
if (pReturnValue) {
*pReturnValue = n + 1;
}
/* Success */
error = 0;
} else {
/* Cannot convert string */
error = 1;
}
#endif
return error;
}
/* Set errno variable */
static void
dirent_set_errno(
int error)
{
#if defined(_MSC_VER) && _MSC_VER >= 1400
/* Microsoft Visual Studio 2005 and later */
_set_errno (error);
#else
/* Non-Microsoft compiler or older Microsoft compiler */
errno = error;
#endif
}
#ifdef __cplusplus
}
#endif
#endif /*DIRENT_H*/

106
contrib/win32/getopt.c Normal file
View File

@ -0,0 +1,106 @@
#include "getopt.h" // make sure you construct the header file as dictated above
/*
* Copyright (c) 1987, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <string.h>
#include <stdio.h>
int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */
optopt, /* character checked for validity */
optreset; /* reset getopt */
char *optarg; /* argument associated with option */
#define BADCH (int)'?'
#define BADARG (int)':'
#define EMSG ""
/*
* getopt --
* Parse argc/argv argument vector.
*/
int getopt(int nargc, char * const nargv[], const char *ostr)
{
static char *place = EMSG; /* option letter processing */
const char *oli; /* option letter list index */
if (optreset || !*place) { /* update scanning pointer */
optreset = 0;
if (optind >= nargc || *(place = nargv[optind]) != '-') {
place = EMSG;
return (-1);
}
if (place[1] && *++place == '-') { /* found "--" */
++optind;
place = EMSG;
return (-1);
}
} /* option letter okay? */
if ((optopt = (int)*place++) == (int)':' ||
!(oli = strchr(ostr, optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
if (optopt == (int)'-')
return (-1);
if (!*place)
++optind;
if (opterr && *ostr != ':')
(void)printf("illegal option -- %c\n", optopt);
return (BADCH);
}
if (*++oli != ':') { /* don't need argument */
optarg = NULL;
if (!*place)
++optind;
}
else { /* need an argument */
if (*place) /* no white space */
optarg = place;
else if (nargc <= ++optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
if (opterr)
(void)printf("option requires an argument -- %c\n", optopt);
return (BADCH);
}
else /* white space */
optarg = nargv[optind];
place = EMSG;
++optind;
}
return (optopt); /* dump back option letter */
}

13
contrib/win32/getopt.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef GETOPT_H
#define GETOPT_H
extern int opterr; /* if error message should be printed */
extern int optind; /* index into parent argv vector */
extern int optopt; /* character checked for validity */
extern int optreset; /* reset getopt */
extern char *optarg; /* argument associated with option */
int getopt(int nargc, char * const nargv[], const char *ostr);
#endif

View File

@ -123,7 +123,7 @@ uart_set_speed(serial_port sp, const uint32_t uiPortSpeed)
{ {
struct serial_port_windows *spw; struct serial_port_windows *spw;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Serial port speed requested to be set to %d bauds.", uiPortSpeed); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Serial port speed requested to be set to %d baud.", uiPortSpeed);
// Set port speed (Input and Output) // Set port speed (Input and Output)
switch (uiPortSpeed) { switch (uiPortSpeed) {
case 9600: case 9600:
@ -135,7 +135,7 @@ uart_set_speed(serial_port sp, const uint32_t uiPortSpeed)
case 460800: case 460800:
break; break;
default: default:
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to set serial port speed to %d bauds. Speed value must be one of these constants: 9600 (default), 19200, 38400, 57600, 115200, 230400 or 460800.", uiPortSpeed); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to set serial port speed to %d baud. Speed value must be one of these constants: 9600 (default), 19200, 38400, 57600, 115200, 230400 or 460800.", uiPortSpeed);
return; return;
}; };
spw = (struct serial_port_windows *) sp; spw = (struct serial_port_windows *) sp;
@ -183,7 +183,7 @@ uart_receive(serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p, i
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Timeouts are set to %lu ms", timeout_ms); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Timeouts are set to %lu ms", timeout_ms);
// TODO Enhance the reception method // TODO Enhance the reception method
// - According to MSDN, it could be better to implement nfc_abort_command() mecanism using Cancello() // - According to MSDN, it could be better to implement nfc_abort_command() mechanism using Cancello()
volatile bool *abort_flag_p = (volatile bool *)abort_p; volatile bool *abort_flag_p = (volatile bool *)abort_p;
do { do {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "ReadFile"); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "ReadFile");

View File

@ -4,9 +4,10 @@ VERSION 1.7
EXPORTS EXPORTS
nfc_init nfc_init
nfc_exit nfc_exit
nfc_register_driver
nfc_open nfc_open
nfc_close nfc_close
nfc_abbort_command nfc_abort_command
nfc_list_devices nfc_list_devices
nfc_idle nfc_idle
nfc_initiator_init nfc_initiator_init
@ -17,7 +18,6 @@ EXPORTS
nfc_initiator_select_dep_target nfc_initiator_select_dep_target
nfc_initiator_poll_dep_target nfc_initiator_poll_dep_target
nfc_initiator_deselect_target nfc_initiator_deselect_target
nfc_initiator_poll_targets
nfc_initiator_transceive_bytes nfc_initiator_transceive_bytes
nfc_initiator_transceive_bits nfc_initiator_transceive_bits
nfc_initiator_transceive_bytes_timed nfc_initiator_transceive_bytes_timed
@ -36,13 +36,22 @@ EXPORTS
nfc_device_get_connstring nfc_device_get_connstring
nfc_device_get_supported_modulation nfc_device_get_supported_modulation
nfc_device_get_supported_baud_rate nfc_device_get_supported_baud_rate
nfc_device_get_supported_baud_rate_target_mode
nfc_device_set_property_int nfc_device_set_property_int
nfc_device_set_property_bool nfc_device_set_property_bool
nfc_emulate_target
iso14443a_crc iso14443a_crc
iso14443a_crc_append iso14443a_crc_append
iso14443b_crc
iso14443b_crc_append
iso14443a_locate_historical_bytes iso14443a_locate_historical_bytes
nfc_free
nfc_version nfc_version
nfc_device_get_information_about nfc_device_get_information_about
str_nfc_modulation_type str_nfc_modulation_type
str_nfc_baud_rate str_nfc_baud_rate
str_nfc_target str_nfc_target
pn53x_transceive
pn532_SAMConfiguration
pn53x_read_register
pn53x_write_register

View File

@ -0,0 +1,57 @@
LIBRARY nfc
VERSION 1.7
EXPORTS
nfc_init
nfc_exit
nfc_register_driver
nfc_open
nfc_close
nfc_abort_command
nfc_list_devices
nfc_idle
nfc_initiator_init
nfc_initiator_init_secure_element
nfc_initiator_select_passive_target
nfc_initiator_list_passive_targets
nfc_initiator_poll_target
nfc_initiator_select_dep_target
nfc_initiator_poll_dep_target
nfc_initiator_deselect_target
nfc_initiator_transceive_bytes
nfc_initiator_transceive_bits
nfc_initiator_transceive_bytes_timed
nfc_initiator_transceive_bits_timed
nfc_initiator_target_is_present
nfc_target_init
nfc_target_send_bytes
nfc_target_receive_bytes
nfc_target_send_bits
nfc_target_receive_bits
nfc_strerror
nfc_strerror_r
nfc_perror
nfc_device_get_last_error
nfc_device_get_name
nfc_device_get_connstring
nfc_device_get_supported_modulation
nfc_device_get_supported_baud_rate
nfc_device_get_supported_baud_rate_target_mode
nfc_device_set_property_int
nfc_device_set_property_bool
nfc_emulate_target
iso14443a_crc
iso14443a_crc_append
iso14443b_crc
iso14443b_crc_append
iso14443a_locate_historical_bytes
nfc_free
nfc_version
nfc_device_get_information_about
str_nfc_modulation_type
str_nfc_baud_rate
str_nfc_target
pn53x_transceive
pn532_SAMConfiguration
pn53x_read_register
pn53x_write_register

View File

@ -34,21 +34,24 @@
// Handle platform specific includes // Handle platform specific includes
#include "contrib/windows.h" #include "contrib/windows.h"
//There is no setenv()and unsetenv() in windows,but we can use putenv() instead.
int setenv(const char *name, const char *value, int overwrite) int setenv(const char *name, const char *value, int overwrite)
{ {
int exists = GetEnvironmentVariableA(name, NULL, 0); char *env = getenv(name);
if ((exists && overwrite) || (!exists)) { if ((env && overwrite) || (!env)) {
if (!SetEnvironmentVariableA(name, value)) { char *str[32];
// Set errno here correctly strcpy(str, name);
return -1; strcat(str, "=");
} strcat(str, value);
return 0; return putenv(str);
} }
// Exists and overwrite is 0.
return -1; return -1;
} }
void unsetenv(const char *name) void unsetenv(const char *name)
{ {
SetEnvironmentVariableA(name, NULL); char *str[32];
strcpy(str, name);
strcat(str, "=");
putenv(str);
} }

View File

@ -1,15 +1,9 @@
#include "windows.h"
1 VERSIONINFO 1 VERSIONINFO
FILEVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,0 FILEVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,0
PRODUCTVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,0 PRODUCTVERSION @VERSION_MAJOR@,@VERSION_MINOR@,@VERSION_PATCH@,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG FILEFLAGS 0x0L
FILEFLAGS VS_FF_DEBUG|VS_FF_PRERELEASE FILEOS 0x00040004L
#else
FILEFLAGS 0L
#endif
FILEOS VOS_NT_WINDOWS32
FILETYPE @RC_FILE_TYPE@ FILETYPE @RC_FILE_TYPE@
FILESUBTYPE 0x0L FILESUBTYPE 0x0L
BEGIN BEGIN

View File

@ -48,7 +48,9 @@
# define ENOTSUP WSAEOPNOTSUPP # define ENOTSUP WSAEOPNOTSUPP
# define ECONNABORTED WSAECONNABORTED # define ECONNABORTED WSAECONNABORTED
# else # else
#ifndef _MSC_VER
# define snprintf sprintf_s # define snprintf sprintf_s
#endif
# define strdup _strdup # define strdup _strdup
# endif # endif

View File

@ -8,6 +8,10 @@ SET(EXAMPLES-SOURCES
nfc-mfsetuid nfc-mfsetuid
nfc-poll nfc-poll
nfc-relay nfc-relay
nfc-st25tb
pn53x-diagnose
pn53x-sam
pn53x-tamashell
) )
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libnfc) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libnfc)
@ -20,9 +24,15 @@ FOREACH(source ${EXAMPLES-SOURCES})
SET(RC_COMMENT "${PACKAGE_NAME} example") SET(RC_COMMENT "${PACKAGE_NAME} example")
SET(RC_INTERNAL_NAME ${source}) SET(RC_INTERNAL_NAME ${source})
SET(RC_ORIGINAL_NAME ${source}.exe) SET(RC_ORIGINAL_NAME ${source}.exe)
SET(RC_FILE_TYPE VFT_APP) # RC_FILE_TYPE: VFT_APP
SET(RC_FILE_TYPE 0x00000001L)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/../windows/${source}.rc @ONLY) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/../windows/${source}.rc @ONLY)
LIST(APPEND TARGETS ${CMAKE_CURRENT_BINARY_DIR}/../windows/${source}.rc) LIST(APPEND TARGETS ${CMAKE_CURRENT_BINARY_DIR}/../windows/${source}.rc)
IF(${source} MATCHES "nfc-st25tb")
LIST(APPEND TARGETS ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/getopt.c)
ENDIF()
ENDIF(WIN32) ENDIF(WIN32)
ADD_EXECUTABLE(${source} ${TARGETS}) ADD_EXECUTABLE(${source} ${TARGETS})

View File

@ -10,6 +10,7 @@ bin_PROGRAMS = \
nfc-mfsetuid \ nfc-mfsetuid \
nfc-poll \ nfc-poll \
nfc-relay \ nfc-relay \
nfc-st25tb \
pn53x-diagnose \ pn53x-diagnose \
pn53x-sam pn53x-sam
@ -63,6 +64,9 @@ nfc_mfsetuid_SOURCES = nfc-mfsetuid.c
nfc_mfsetuid_LDADD = $(top_builddir)/libnfc/libnfc.la \ nfc_mfsetuid_LDADD = $(top_builddir)/libnfc/libnfc.la \
$(top_builddir)/utils/libnfcutils.la $(top_builddir)/utils/libnfcutils.la
nfc_st25tb_SOURCES = nfc-st25tb.c
nfc_st25tb_LDADD = $(top_builddir)/libnfc/libnfc.la
pn53x_diagnose_SOURCES = pn53x-diagnose.c pn53x_diagnose_SOURCES = pn53x-diagnose.c
pn53x_diagnose_LDADD = $(top_builddir)/libnfc/libnfc.la \ pn53x_diagnose_LDADD = $(top_builddir)/libnfc/libnfc.la \
$(top_builddir)/utils/libnfcutils.la $(top_builddir)/utils/libnfcutils.la
@ -74,6 +78,7 @@ pn53x_sam_LDADD = $(top_builddir)/libnfc/libnfc.la \
pn53x_tamashell_SOURCES = pn53x-tamashell.c pn53x_tamashell_SOURCES = pn53x-tamashell.c
pn53x_tamashell_LDADD = $(top_builddir)/libnfc/libnfc.la \ pn53x_tamashell_LDADD = $(top_builddir)/libnfc/libnfc.la \
$(top_builddir)/utils/libnfcutils.la $(top_builddir)/utils/libnfcutils.la
pn53x_tamashell_CFLAGS = @READLINE_INCLUDES@ -I$(top_srcdir)
pn53x_tamashell_LDFLAGS = @READLINE_LIBS@ pn53x_tamashell_LDFLAGS = @READLINE_LIBS@
quick_start_example1_SOURCES = doc/quick_start_example1.c quick_start_example1_SOURCES = doc/quick_start_example1.c

View File

@ -23,7 +23,7 @@ Please report any bugs on the
.B libnfc .B libnfc
issue tracker at: issue tracker at:
.br .br
.BR http://code.google.com/p/libnfc/issues .BR https://github.com/nfc-tools/libnfc/issues
.SH LICENCE .SH LICENCE
.B libnfc .B libnfc
is licensed under the GNU Lesser General Public License (LGPL), version 3. is licensed under the GNU Lesser General Public License (LGPL), version 3.

View File

@ -18,7 +18,7 @@ Please report any bugs on the
.B libnfc .B libnfc
issue tracker at: issue tracker at:
.br .br
.BR http://code.google.com/p/libnfc/issues .BR https://github.com/nfc-tools/libnfc/issues
.SH LICENCE .SH LICENCE
.B libnfc .B libnfc
is licensed under the GNU Lesser General Public License (LGPL), version 3. is licensed under the GNU Lesser General Public License (LGPL), version 3.

View File

@ -18,7 +18,7 @@ Please report any bugs on the
.B libnfc .B libnfc
issue tracker at: issue tracker at:
.br .br
.BR http://code.google.com/p/libnfc/issues .BR https://github.com/nfc-tools/libnfc/issues
.SH LICENCE .SH LICENCE
.B libnfc .B libnfc
is licensed under the GNU Lesser General Public License (LGPL), version 3. is licensed under the GNU Lesser General Public License (LGPL), version 3.

View File

@ -35,7 +35,7 @@ bug, this problem is due to ACR122's internal MCU in front of NFC chip (PN532).
Please report any bugs on the Please report any bugs on the
.Em libnfc .Em libnfc
issue tracker at: issue tracker at:
.Em http://code.google.com/p/libnfc/issues .Em https://github.com/nfc-tools/libnfc/issues
.Sh LICENCE .Sh LICENCE
.Em libnfc .Em libnfc
is licensed under the GNU Lesser General Public License (LGPL), version 3. is licensed under the GNU Lesser General Public License (LGPL), version 3.

View File

@ -39,7 +39,7 @@ Please report any bugs on the
.B libnfc .B libnfc
issue tracker at: issue tracker at:
.br .br
.BR http://code.google.com/p/libnfc/issues .BR https://github.com/nfc-tools/libnfc/issues
.SH LICENCE .SH LICENCE
.B libnfc .B libnfc
is licensed under the GNU Lesser General Public License (LGPL), version 3. is licensed under the GNU Lesser General Public License (LGPL), version 3.

View File

@ -266,9 +266,9 @@ main(int argc, char *argv[])
}, },
.nti = { .nti = {
.nai = { .nai = {
abtAtqa = { 0x03, 0x44 }, .abtAtqa = { 0x03, 0x44 },
abtUid = { 0x08, 0xab, 0xcd, 0xef }, .abtUid = { 0x08, 0xab, 0xcd, 0xef },
btSak = 0x20, .btSak = 0x20,
.szUidLen = 4, .szUidLen = 4,
.abtAts = { 0x75, 0x77, 0x81, 0x02, 0x80 }, .abtAts = { 0x75, 0x77, 0x81, 0x02, 0x80 },
.szAtsLen = 5, .szAtsLen = 5,

View File

@ -14,7 +14,7 @@ fully customized UID but only of "random" UIDs, which always start with 0x08.
The nfc-emulate-uid tool demonstrates that this can still be done using The nfc-emulate-uid tool demonstrates that this can still be done using
transmission of raw frames, and the desired UID can be optionally specified. transmission of raw frames, and the desired UID can be optionally specified.
This makes it a serious thread for security systems that rely only on the This makes it a serious threat for security systems that rely only on the
uniqueness of the UID. uniqueness of the UID.
Unfortunately, this example can't directly start in fully customisable Unfortunately, this example can't directly start in fully customisable
@ -54,7 +54,7 @@ Please report any bugs on the
.B libnfc .B libnfc
issue tracker at: issue tracker at:
.br .br
.BR http://code.google.com/p/libnfc/issues .BR https://github.com/nfc-tools/libnfc/issues
.SH LICENCE .SH LICENCE
.B libnfc .B libnfc
is licensed under the GNU Lesser General Public License (LGPL), version 3. is licensed under the GNU Lesser General Public License (LGPL), version 3.

View File

@ -79,7 +79,10 @@ intr_hdlr(int sig)
if (pnd != NULL) { if (pnd != NULL) {
printf("\nAborting current command...\n"); printf("\nAborting current command...\n");
nfc_abort_command(pnd); nfc_abort_command(pnd);
nfc_close(pnd);
} }
nfc_exit(context);
exit(EXIT_SUCCESS);
} }
static void static void
@ -237,7 +240,4 @@ main(int argc, char *argv[])
} }
} }
} }
nfc_close(pnd);
nfc_exit(context);
exit(EXIT_SUCCESS);
} }

View File

@ -24,7 +24,7 @@ Please report any bugs on the
.B libnfc .B libnfc
issue tracker at: issue tracker at:
.br .br
.BR http://code.google.com/p/libnfc/issues .BR https://github.com/nfc-tools/libnfc/issues
.SH LICENCE .SH LICENCE
.B libnfc .B libnfc
is licensed under the GNU Lesser General Public License (LGPL), version 3. is licensed under the GNU Lesser General Public License (LGPL), version 3.

View File

@ -10,6 +10,7 @@
* See AUTHORS file for a more comprehensive list of contributors. * See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file: * Additional contributors of this file:
* Copyright (C) 2011 Adam Laurie * Copyright (C) 2011 Adam Laurie
* Copyright (C) 2014 Dario Carluccio
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -140,12 +141,13 @@ transmit_bytes(const uint8_t *pbtTx, const size_t szTx)
static void static void
print_usage(char *argv[]) print_usage(char *argv[])
{ {
printf("Usage: %s [OPTIONS] [UID]\n", argv[0]); printf("Usage: %s [OPTIONS] [UID|BLOCK0]\n", argv[0]);
printf("Options:\n"); printf("Options:\n");
printf("\t-h\tHelp. Print this message.\n"); printf("\t-h\tHelp. Print this message.\n");
printf("\t-f\tFormat. Delete all data (set to 0xFF) and reset ACLs to default.\n"); printf("\t-f\tFormat. Delete all data (set to 0xFF) and reset ACLs to default.\n");
printf("\t-q\tQuiet mode. Suppress output of READER and CARD data (improves timing).\n"); printf("\t-q\tQuiet mode. Suppress output of READER and CARD data (improves timing).\n");
printf("\n\tSpecify UID (4 HEX bytes) to set UID, or leave blank for default '01234567'.\n"); printf("\n\tSpecify UID (4 HEX bytes) to set UID, or leave blank for default '01234567'.\n");
printf("\n\tSpecify BLOCK0 (16 HEX bytes) to set content of Block0. CRC (Byte 4) is recalculated an overwritten'.\n");
printf("\tThis utility can be used to recover cards that have been damaged by writing bad\n"); printf("\tThis utility can be used to recover cards that have been damaged by writing bad\n");
printf("\tdata (e.g. wrong BCC), thus making them non-selectable by most tools/readers.\n"); printf("\tdata (e.g. wrong BCC), thus making them non-selectable by most tools/readers.\n");
printf("\n\t*** Note: this utility only works with special Mifare 1K cards (Chinese clones).\n\n"); printf("\n\t*** Note: this utility only works with special Mifare 1K cards (Chinese clones).\n\n");
@ -177,6 +179,14 @@ main(int argc, char *argv[])
} }
abtData[4] = abtData[0] ^ abtData[1] ^ abtData[2] ^ abtData[3]; abtData[4] = abtData[0] ^ abtData[1] ^ abtData[2] ^ abtData[3];
iso14443a_crc_append(abtData, 16); iso14443a_crc_append(abtData, 16);
} else if (strlen(argv[arg]) == 32) {
for (i = 0 ; i < 16 ; ++i) {
memcpy(tmp, argv[arg] + i * 2, 2);
sscanf(tmp, "%02x", &c);
abtData[i] = (char) c;
}
abtData[4] = abtData[0] ^ abtData[1] ^ abtData[2] ^ abtData[3];
iso14443a_crc_append(abtData, 16);
} else { } else {
ERR("%s is not supported option.", argv[arg]); ERR("%s is not supported option.", argv[arg]);
print_usage(argv); print_usage(argv);
@ -355,13 +365,23 @@ main(int argc, char *argv[])
// now reset UID // now reset UID
iso14443a_crc_append(abtHalt, 2); iso14443a_crc_append(abtHalt, 2);
transmit_bytes(abtHalt, 4); transmit_bytes(abtHalt, 4);
transmit_bits(abtUnlock1, 7);
if (format) { if (!transmit_bits(abtUnlock1, 7)) {
transmit_bytes(abtWipe, 1); printf("Warning: Unlock command [1/2]: failed / not acknowledged.\n");
transmit_bytes(abtHalt, 4); } else {
transmit_bits(abtUnlock1, 7); if (format) {
transmit_bytes(abtWipe, 1);
transmit_bytes(abtHalt, 4);
transmit_bits(abtUnlock1, 7);
}
if (transmit_bytes(abtUnlock2, 1)) {
printf("Card unlocked\n");
} else {
printf("Warning: Unlock command [2/2]: failed / not acknowledged.\n");
}
} }
transmit_bytes(abtUnlock2, 1);
transmit_bytes(abtWrite, 4); transmit_bytes(abtWrite, 4);
transmit_bytes(abtData, 18); transmit_bytes(abtData, 18);
if (format) { if (format) {

View File

@ -42,7 +42,7 @@ Please report any bugs on the
.B libnfc .B libnfc
issue tracker at: issue tracker at:
.br .br
.BR http://code.google.com/p/libnfc/issues .BR https://github.com/nfc-tools/libnfc/issues
.SH LICENCE .SH LICENCE
.B libnfc .B libnfc
is licensed under the GNU Lesser General Public License (LGPL), version 3. is licensed under the GNU Lesser General Public License (LGPL), version 3.

View File

@ -9,6 +9,7 @@
* Copyright (C) 2012-2013 Ludovic Rousseau * Copyright (C) 2012-2013 Ludovic Rousseau
* See AUTHORS file for a more comprehensive list of contributors. * See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file: * Additional contributors of this file:
* Copyright (C) 2020 Adam Laurie
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
@ -101,14 +102,15 @@ main(int argc, const char *argv[])
const uint8_t uiPollNr = 20; const uint8_t uiPollNr = 20;
const uint8_t uiPeriod = 2; const uint8_t uiPeriod = 2;
const nfc_modulation nmModulations[5] = { const nfc_modulation nmModulations[6] = {
{ .nmt = NMT_ISO14443A, .nbr = NBR_106 }, { .nmt = NMT_ISO14443A, .nbr = NBR_106 },
{ .nmt = NMT_ISO14443B, .nbr = NBR_106 }, { .nmt = NMT_ISO14443B, .nbr = NBR_106 },
{ .nmt = NMT_FELICA, .nbr = NBR_212 }, { .nmt = NMT_FELICA, .nbr = NBR_212 },
{ .nmt = NMT_FELICA, .nbr = NBR_424 }, { .nmt = NMT_FELICA, .nbr = NBR_424 },
{ .nmt = NMT_JEWEL, .nbr = NBR_106 }, { .nmt = NMT_JEWEL, .nbr = NBR_106 },
{ .nmt = NMT_ISO14443BICLASS, .nbr = NBR_106 },
}; };
const size_t szModulations = 5; const size_t szModulations = 6;
nfc_target nt; nfc_target nt;
int res = 0; int res = 0;
@ -145,15 +147,15 @@ main(int argc, const char *argv[])
if (res > 0) { if (res > 0) {
print_nfc_target(&nt, verbose); print_nfc_target(&nt, verbose);
printf("Waiting for card removing...");
fflush(stdout);
while (0 == nfc_initiator_target_is_present(pnd, NULL)) {}
nfc_perror(pnd, "nfc_initiator_target_is_present");
printf("done.\n");
} else { } else {
printf("No target found.\n"); printf("No target found.\n");
} }
printf("Waiting for card removing...");
while (0 == nfc_initiator_target_is_present(pnd, NULL)) {}
nfc_perror(pnd, "nfc_initiator_target_is_present");
printf("done.\n");
nfc_close(pnd); nfc_close(pnd);
nfc_exit(context); nfc_exit(context);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);

View File

@ -22,7 +22,7 @@ Please report any bugs on the
.B libnfc .B libnfc
issue tracker at: issue tracker at:
.br .br
.BR http://code.google.com/p/libnfc/issues .BR https://github.com/nfc-tools/libnfc/issues
.SH LICENCE .SH LICENCE
.B libnfc .B libnfc
is licensed under the GNU Lesser General Public License (LGPL), version 3. is licensed under the GNU Lesser General Public License (LGPL), version 3.

600
examples/nfc-st25tb.c Normal file
View File

@ -0,0 +1,600 @@
/*-
* Free/Libre Near Field Communication (NFC) library
*
* Libnfc historical contributors:
* Copyright (C) 2009 Roel Verdult
* Copyright (C) 2009-2013 Romuald Conty
* Copyright (C) 2010-2012 Romain Tartière
* Copyright (C) 2010-2013 Philippe Teuwen
* Copyright (C) 2012-2013 Ludovic Rousseau
* See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1) Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2 )Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Note that this license only applies on the examples, NFC library itself is under LGPL
*
*/
/**
* @file nfc-st25tb.c
* @brief Tool to operate on ISO-14443-B ST25TB* and legacy SR* cards
*/
/* Benjamin DELPY `gentilkiwi`
* https://blog.gentilkiwi.com
* benjamin@gentilkiwi.com
* Licence : https://creativecommons.org/licenses/by/4.0/
* Rely on : libnfc - https://github.com/nfc-tools/libnfc
*
* $ gcc -Wall -lnfc -o nfc-st25tb nfc-st25tb.c
* $ ./nfc-st25tb -h
*
* Tested with
* - ST25TB512-AC - (BE/Brussels/STIB ; AliExpress ones)
* - ST25TB512-AT - (FR/Lille/Ilevia ; FR/Reims/Citura ; FR/Dijon/Divia ; FR/Strasbourg/CTS)
* - SRT512 - legacy - (FR/Bordeaux/TBM)
* - SRI512 - legacy - (anonymous vending machine)
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif // HAVE_CONFIG_H
#include <unistd.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <nfc/nfc.h>
#if defined(WIN32) /* mingw compiler */
#include <getopt.h>
#endif
#define ST25TB_SR_BLOCK_MAX_SIZE ((uint8_t) 4) // for static arrays
typedef void(*get_info_specific) (uint8_t * systemArea);
typedef struct _st_data {
uint8_t chipId;
bool bIsLegacy;
const char *szName;
const char *szDatasheetUrl;
uint8_t blockSize;
uint8_t nbNormalBlock;
uint8_t bnSystem;
get_info_specific pfnGetInfo;
} st_data;
bool get_block_at(nfc_device *pnd, uint8_t block, uint8_t *data, uint8_t cbData, bool bPrintIt);
bool set_block_at(nfc_device *pnd, uint8_t block, uint8_t *data, uint8_t cbData, bool bPrintIt);
bool set_block_at_confirmed(nfc_device *pnd, uint8_t block, uint8_t *data, uint8_t cbData, bool bPrintIt);
const st_data * get_info(const nfc_target *pnt, bool bPrintIt);
void display_system_info(nfc_device *pnd, const st_data * stdata);
void print_hex(const uint8_t *pbtData, const size_t szBytes);
int main(int argc, char *argv[])
{
nfc_context *context = NULL;
nfc_device *pnd = NULL;
nfc_target nt = {0};
nfc_modulation nm = {NMT_ISO14443B2SR, NBR_106};
const st_data * stcurrent;
int opt, res;
bool bIsBlock = false, bIsRead = false, bIsWrite = false, bIsBadCli = false;
uint8_t i, blockNumber = 0, data[ST25TB_SR_BLOCK_MAX_SIZE] = {0xff, 0xff, 0xff, 0xff}; // just in case...
size_t cbData = 0;
while(!bIsBadCli && ((opt = getopt(argc, argv, ":hib:rw:")) != -1))
{
switch(opt)
{
case 'i':
break;
case 'b':
if(optarg)
{
bIsBlock = true;
blockNumber = strtoul(optarg, NULL, 0);
}
else bIsBadCli = true;
break;
case 'r':
bIsRead = true;
break;
case 'w':
if(optarg)
{
cbData = strlen(optarg);
if((cbData == (2*2)) || ((cbData == (4*2))))
{
cbData >>= 1;
if(cbData == 2) // sr176
{
res = sscanf(optarg, "%02hhx%02hhx", data, data + 1);
}
else // all others
{
res = sscanf(optarg, "%02hhx%02hhx%02hhx%02hhx", data, data + 1, data + 2, data + 3);
}
if(res == (int) cbData)
{
bIsWrite = true;
}
}
if(!bIsWrite)
{
bIsBadCli = true;
}
}
break;
default: // includes -h
bIsBadCli = true;
}
}
if(!bIsBadCli)
{
if(bIsBlock && (bIsRead || bIsWrite))
{
if(bIsRead && bIsWrite)
{
printf("|mode : read then write\n");
}
else if(bIsRead)
{
printf("|mode : read\n");
}
else if(bIsWrite)
{
printf("|mode : write\n");
}
printf("|blk num: 0x%02hhx\n", blockNumber);
if(bIsWrite)
{
printf("|data : ");
print_hex(data, cbData);
printf("\n");
}
}
else if(!bIsRead && !bIsWrite && !bIsBlock)
{
printf("|mode : info\n");
}
else bIsBadCli = true;
}
if(!bIsBadCli)
{
nfc_init(&context);
if(context)
{
pnd = nfc_open(context, NULL);
if(pnd)
{
res = nfc_initiator_init(pnd);
if(res == NFC_SUCCESS)
{
printf("Reader : %s - via %s\n ...wait for card...\n", nfc_device_get_name(pnd), nfc_device_get_connstring(pnd));
if (nfc_initiator_select_passive_target(pnd, nm, NULL, 0, &nt) > 0)
{
stcurrent = get_info(&nt, true);
if(stcurrent)
{
printf("\n");
if(bIsBlock && (bIsRead || bIsWrite))
{
if(bIsRead)
{
get_block_at(pnd, blockNumber, NULL, 0, true);
}
if(bIsWrite)
{
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 printf("ERROR - nfc_initiator_init: %i\n", res);
nfc_close(pnd);
}
else printf("ERROR - nfc_open\n");
nfc_exit(context);
}
else printf("ERROR - nfc_init\n");
}
else
{
printf(
"Usage:\n"
" %s [-i]\n"
" %s -b N -r\n"
" %s -b N [-r] -w ABCD[EF01]\n %s -h\n"
"Options:\n"
" -i (default) information mode - will try to dump the tag content and display informations\n"
" -b N specify block number to operate on (tag dependent), needed for read (-r) and write (-w) modes\n"
" -r read mode - will try to read block (specified with -b N parameter)\n"
" -w ABCD[EF01] write mode - will try to write specicied data (2 or 4 bytes depending on tag) to block (specified with -b N parameter)\n"
" -h this help\n"
"Examples:\n"
" %s -i\n"
" Display all tag informations\n"
" %s -b 0x0e -r\n"
" Read block 0x0e (14) of the tag\n"
" %s -b 0x0d -w 0123abcd\n"
" Write block 0x0d (13) of the tag with hexadecimal value '01 23 ab cd'\n"
" %s -b 0x0c -r -w 0123abcd\n"
" Read, then write block 0x0c (12) of the tag with hexadecimal value '01 23 ab cd'\n"
"Warnings:\n"
" Be careful with: system area, counters & otp, bytes order.\n"
, argv[0], argv[0], argv[0], argv[0], argv[0], argv[0], argv[0], argv[0]);
}
return 0;
}
bool get_block_at(nfc_device *pnd, uint8_t block, uint8_t *data, uint8_t cbData, bool bPrintIt)
{
bool bRet = false;
uint8_t tx[2] = {0x08, block}, rx[ST25TB_SR_BLOCK_MAX_SIZE]; // 4 is the maximum, SR176 (only 2) will fit
int res;
res = nfc_initiator_transceive_bytes(pnd, tx, sizeof(tx), rx, sizeof(rx), 0);
if((res == 2) || (res == 4))
{
if(data)
{
if(cbData == res)
{
memcpy(data, rx, res);
bRet = true;
}
else printf("ERROR - We got %i bytes for a %hhu buffer size?\n", res, cbData);
}
else bRet = true;
if(bPrintIt)
{
printf("[0x%02hhx] ", block);
print_hex(rx, res);
printf("\n");
}
}
else if(res > 0)
{
printf("ERROR - We got %i bytes?\n", res);
}
else printf("ERROR - nfc_initiator_transceive_bytes(get): %i\n", res);
return bRet;
}
bool set_block_at(nfc_device *pnd, uint8_t block, uint8_t *data, uint8_t cbData, bool bPrintIt)
{
bool bRet = false;
uint8_t tx[2 + ST25TB_SR_BLOCK_MAX_SIZE] = {0x09, block}; // 4 is the maximum, SR176 (only 2) will fit
int res;
if(cbData <= ST25TB_SR_BLOCK_MAX_SIZE)
{
memcpy(tx + 2, data, cbData);
if(bPrintIt)
{
printf(">0x%02hhx> ", block);
print_hex(data, cbData);
printf("\n");
}
res = nfc_initiator_transceive_bytes(pnd, tx, 2 + cbData, NULL, 0, 0);
if(res == NFC_ERFTRANS) // ? :')
{
bRet = true;
}
else printf("ERROR - nfc_initiator_transceive_bytes(set): %i\n", res);
}
else printf("ERROR - Wanted to write %hhu bytes, but maximum is %hhu\n", cbData, ST25TB_SR_BLOCK_MAX_SIZE);
return bRet;
}
bool set_block_at_confirmed(nfc_device *pnd, uint8_t block, uint8_t *data, uint8_t cbData, bool bPrintIt)
{
bool bRet = false;
uint8_t buffer[ST25TB_SR_BLOCK_MAX_SIZE]; // maximum size will be checked in set_block_at
if(set_block_at(pnd, block, data, cbData, bPrintIt))
{
if(get_block_at(pnd, block, buffer, cbData, bPrintIt))
{
if(memcmp(data, buffer, cbData) == 0)
{
bRet = true;
}
else if(bPrintIt)
{
printf("WARNING - not same value readed after write\n");
}
}
}
return bRet;
}
void get_info_st25tb512(uint8_t * systemArea)
{
uint8_t b, i;
b = ((*(uint32_t *) systemArea) >> 15) & 1;
printf(" | ST reserved : ");
for(i = 0; i < 15; i++)
{
printf("%hhu", (uint8_t) (((*(uint32_t *) systemArea) >> i) & 1));
}
printf("\n | b15 : %hhu - %sOTP (?)\n | OTP_Lock_Reg : ", b, b ? "not " : "");
for(i = 16; i < 32; i++)
{
printf("%hhu", (uint8_t) (((*(uint32_t *) systemArea) >> i) & 1));
}
printf("\n");
for(i = 16; i < 32; i++)
{
if(!(((*(uint32_t *) systemArea) >> i) & 1))
{
printf(" block 0x%02hhx is write protected\n", ((uint8_t) (i - 16)));
}
}
}
void get_info_st25tb2k_4k(uint8_t * systemArea)
{
uint8_t b, i;
b = ((*(uint32_t *) systemArea) >> 15) & 1;
printf(" | ST reserved : ");
for(i = 0; i < 15; i++)
{
printf("%hhu", (uint8_t) (((*(uint32_t *) systemArea) >> i) & 1));
}
printf("\n | b15 : %hhu - %sOTP (?)\n | OTP_Lock_RegU: ", b, b ? "not " : "");
for(i = 16; i < 24; i++)
{
printf("%hhu", (uint8_t) (((*(uint32_t *) systemArea) >> i) & 1));
}
printf("\n | OTP_Lock_Reg : ");
for(i = 24; i < 32; i++)
{
printf("%hhu", (uint8_t) (((*(uint32_t *) systemArea) >> i) & 1));
}
printf("\n");
if(!(((*(uint32_t *) systemArea) >> 24) & 1))
{
printf(" blocks 0x07 and 0x08 are write protected\n");
}
for(i = 25; i < 32; i++)
{
if(!(((*(uint32_t *) systemArea) >> i) & 1))
{
printf(" block 0x%02hhx is write protected\n", ((uint8_t) (i - 16)));
}
}
}
void get_info_sr176_legacy(uint8_t * systemArea)
{
uint8_t i;
printf(" | Fixed Chip_ID: 0x%1x\n | ST reserved : ", systemArea[0] & 0x0f);
for(i = 4; i < 8; i++)
{
printf("%hhu", (uint8_t) (((*(uint16_t *) systemArea) >> i) & 1));
}
printf("\n | OTP_Lock_Reg : ");
for(i = 8; i < 16; i++)
{
printf("%hhu", (uint8_t) (((*(uint16_t *) systemArea) >> i) & 1));
}
printf("\n");
for(i = 8; i < 16; i++)
{
if(((*(uint16_t *) systemArea) >> i) & 1)
{
printf(" blocks 0x%02hhx and 0x%02hhx are write protected\n", (uint8_t) ((i - 8) * 2), (uint8_t) (((i - 8) * 2) + 1));
}
}
}
void get_info_sri_srt_512_legacy(uint8_t * systemArea)
{
uint8_t b, i;
b = ((*(uint32_t *) systemArea) >> 15) & 1;
printf(" | Fixed Chip_ID: 0x%02hhx\n | ST reserved : ", systemArea[0]);
for(i = 8; i < 15; i++)
{
printf("%hhu", (uint8_t) (((*(uint32_t *) systemArea) >> i) & 1));
}
printf("\n | b15 : %hhu - %sOTP (?)\n | OTP_Lock_Reg : ", b, b ? "not " : "");
for(i = 16; i < 32; i++)
{
printf("%hhu", (uint8_t) (((*(uint32_t *) systemArea) >> i) & 1));
}
printf("\n");
for(i = 16; i < 32; i++)
{
if(!(((*(uint32_t *) systemArea) >> i) & 1))
{
printf(" block 0x%02hhx is write protected\n", (uint8_t) (i - 16));
}
}
}
void get_info_sri2k_4k_srix4k_srix512_legacy(uint8_t * systemArea)
{
uint8_t i;
printf(" | Fixed Chip_ID: 0x%02hhx\n | ST reserved : ", systemArea[0]);
for(i = 8; i < 24; i++)
{
printf("%hhu", (uint8_t) (((*(uint32_t *) systemArea) >> i) & 1));
}
printf("\n | OTP_Lock_Reg : ");
for(i = 24; i < 32; i++)
{
printf("%hhu", (uint8_t) (((*(uint32_t *) systemArea) >> i) & 1));
}
printf("\n");
if(!(((*(uint32_t *) systemArea) >> 24) & 1))
{
printf(" blocks 0x07 and 0x08 are write protected\n");
}
for(i = 25; i < 32; i++)
{
if(!(((*(uint32_t *) systemArea) >> i) & 1))
{
printf(" block 0x%02hhx is write protected\n", (uint8_t) (i - 16));
}
}
}
const st_data STRefs[] = {
{0x1b, false, "ST25TB512-AC", "https://www.st.com/resource/en/datasheet/st25tb512-ac.pdf", 4, 16, 255, get_info_st25tb512},
{0x33, false, "ST25TB512-AT", "https://www.st.com/resource/en/datasheet/st25tb512-at.pdf", 4, 16, 255, get_info_st25tb512},
{0x3f, false, "ST25TB02K", "https://www.st.com/resource/en/datasheet/st25tb02k.pdf", 4, 64, 255, get_info_st25tb2k_4k},
{0x1f, false, "ST25TB04K", "https://www.st.com/resource/en/datasheet/st25tb04k.pdf", 4, 128, 255, get_info_st25tb2k_4k},
};
const st_data STRefs_legacy[] = {
{ 0, true, "SRI4K(s)", NULL, 4, 128, 255, NULL},
{ 2, true, "SR176", "https://www.st.com/resource/en/datasheet/sr176.pdf", 2, 15, 15, get_info_sr176_legacy},
{ 3, true, "SRIX4K", NULL, 4, 128, 255, get_info_sri2k_4k_srix4k_srix512_legacy},
{ 4, true, "SRIX512", "https://www.st.com/resource/en/datasheet/srix512.pdf", 4, 16, 255, get_info_sri2k_4k_srix4k_srix512_legacy},
{ 6, true, "SRI512", "https://www.st.com/resource/en/datasheet/sri512.pdf", 4, 16, 255, get_info_sri_srt_512_legacy},
{ 7, true, "SRI4K", "https://www.st.com/resource/en/datasheet/sri4k.pdf", 4, 128, 255, get_info_sri2k_4k_srix4k_srix512_legacy},
{12, true, "SRT512", "https://www.st.com/resource/en/datasheet/srt512.pdf", 4, 16, 255, get_info_sri_srt_512_legacy},
{15, true, "SRI2K", "https://www.st.com/resource/en/datasheet/sri2k.pdf", 4, 64, 255, get_info_sri2k_4k_srix4k_srix512_legacy},
};
const st_data * get_info(const nfc_target *pnt, bool bPrintIt)
{
const st_data *currentData = NULL;
const uint8_t *p;
uint8_t chipId, i;
if(pnt->nm.nmt == NMT_ISO14443B2SR)
{
printf("Target : %s (%s)\nUID : ", str_nfc_modulation_type(pnt->nm.nmt), str_nfc_baud_rate(pnt->nm.nbr));
print_hex(pnt->nti.nsi.abtUID, sizeof(pnt->nti.nsi.abtUID));
printf("\n");
p = pnt->nti.nsi.abtUID;
if(p[7] == 0xd0) // ST25TB* / SR*
{
chipId = p[5];
printf("Manuf : 0x%02hhx - %s\n", p[6], (p[6] == 0x02) ? "STMicroelectronics" : "other");
for(i = 0; i < (sizeof(STRefs) / sizeof(STRefs[0])); i++)
{
if(chipId == STRefs[i].chipId)
{
currentData = &STRefs[i];
break;
}
}
if(!currentData)
{
chipId >>= 2;
for(i = 0; i < (sizeof(STRefs_legacy) / sizeof(STRefs_legacy[0])); i++)
{
if(chipId == STRefs_legacy[i].chipId)
{
currentData = &STRefs_legacy[i];
break;
}
}
}
if(bPrintIt && currentData)
{
printf("ChipId : 0x%02hhx - %s%s\nSerial : 0x", currentData->chipId, currentData->szName, currentData->bIsLegacy ? " (legacy)" : "");
if(currentData->bIsLegacy)
{
printf("%1hhx", (uint8_t) (p[5] & 0x03));
}
printf("%02hhx%02hhx%02hhx%02hhx%02hhx\n|blk sz : %hhu bits\n|nb blks: %hhu\n|sys idx: %hhu\n", p[4], p[3], p[2], p[1], p[0], (uint8_t) (currentData->blockSize * 8), currentData->nbNormalBlock, currentData->bnSystem);
}
}
else printf("WARNI - Last byte of UID isn\'t 0xd0, but 0x%02hhx (not ST25TB / SR series?)\n", p[7]);
}
else printf("ERROR - not a NMT_ISO14443B2SR ?\n");
return currentData;
}
void display_system_info(nfc_device *pnd, const st_data * stdata)
{
uint8_t systemArea[ST25TB_SR_BLOCK_MAX_SIZE];
if(get_block_at(pnd, stdata->bnSystem, systemArea, stdata->blockSize, true))
{
if(stdata->pfnGetInfo)
{
stdata->pfnGetInfo(systemArea);
}
}
}
void print_hex(const uint8_t *pbtData, const size_t szBytes)
{
size_t szPos;
for (szPos = 0; szPos < szBytes; szPos++)
{
printf("%02hhx ", pbtData[szPos]);
}
}

View File

@ -13,7 +13,7 @@ Please report any bugs on the
.B libnfc .B libnfc
issue tracker at: issue tracker at:
.br .br
.BR http://code.google.com/p/libnfc/issues .BR https://github.com/nfc-tools/libnfc/issues
.SH LICENCE .SH LICENCE
.B libnfc .B libnfc
is licensed under the GNU Lesser General Public License (LGPL), version 3. is licensed under the GNU Lesser General Public License (LGPL), version 3.

View File

@ -19,7 +19,7 @@ Please report any bugs on the
.B libnfc .B libnfc
issue tracker at: issue tracker at:
.br .br
.BR http://code.google.com/p/libnfc/issues .BR https://github.com/nfc-tools/libnfc/issues
.SH LICENCE .SH LICENCE
.B libnfc .B libnfc
is licensed under the GNU Lesser General Public License (LGPL), version 3. is licensed under the GNU Lesser General Public License (LGPL), version 3.

View File

@ -1,8 +1,10 @@
#!/bin/sh #!/bin/sh
#DEBUG='//;'
cat << EOF | \ cat << EOF | \
pn53x-tamashell |\ pn53x-tamashell |\
awk '\ awk $DEBUG'\
/^> #.*:/{ /^> #.*:/{
sub(/^> #/,"") sub(/^> #/,"")
n=$0 n=$0
@ -21,27 +23,33 @@ cat << EOF | \
# Select one typeB target # Select one typeB target
4A010300 4A010300
# SELECT AID "1TIC.ICA"
4001 00a4 0400 08 315449432e494341
# Select ICC file # Select ICC file
4001 80a4 0800 04 3f00 0002 4001 00a4 0000 02 3f00
4001 00a4 0000 02 0002
#ICC: #ICC:
4001 80b2 0104 1d 4001 00b2 0104 1d
# Select Holder file # Select Holder file
4001 80a4 0800 04 3f00 3f1c 4001 00a4 0000 02 3f1c
#Holder1: #Holder1:
4001 80b2 0104 1d 4001 00b2 0104 1d
#Holder2: #Holder2:
4001 80b2 0204 1d 4001 00b2 0204 1d
# Select EnvHol file # Select EnvHol file
4001 00a4 0800 04 2000 2001 4001 00a4 0000 00
4001 00a4 0000 02 2000
4001 00a4 0000 02 2001
#EnvHol1: #EnvHol1:
4001 00b2 0104 1d 4001 00b2 0104 1d
#EnvHol2: #EnvHol2:
4001 00b2 0204 1d 4001 00b2 0204 1d
# Select EvLog file # Select EvLog file
4001 00a4 0800 04 2000 2010 4001 00a4 0000 02 2010
#EvLog1: #EvLog1:
4001 00b2 0104 1d 4001 00b2 0104 1d
#EvLog2: #EvLog2:
@ -50,12 +58,12 @@ cat << EOF | \
4001 00b2 0304 1d 4001 00b2 0304 1d
# Select ConList file # Select ConList file
4001 00a4 0800 04 2000 2050 4001 00a4 0000 02 2050
#ConList: #ConList:
4001 00b2 0104 1d 4001 00b2 0104 1d
# Select Contra file # Select Contra file
4001 00a4 0800 04 2000 2020 4001 00a4 0000 02 2020
#Contra1: #Contra1:
4001 00b2 0104 1d 4001 00b2 0104 1d
#Contra2: #Contra2:
@ -82,17 +90,19 @@ cat << EOF | \
4001 00b2 0c04 1d 4001 00b2 0c04 1d
# Select Counter file # Select Counter file
4001 00a4 0800 04 2000 2069 4001 00a4 0000 02 2069
#Counter: #Counter:
4001 00b2 0104 1d 4001 00b2 0104 1d
# Select LoadLog file # Select LoadLog file
4001 00a4 0800 04 1000 1014 4001 00a4 0000 00
4001 00a4 0000 02 1000
4001 00a4 0000 02 1014
#LoadLog: #LoadLog:
4001 00b2 0104 1d 4001 00b2 0104 1d
# Select Purcha file # Select Purcha file
4001 00a4 08 0004 1000 1015 4001 00a4 0000 02 1015
#Purcha1: #Purcha1:
4001 00b2 0104 1d 4001 00b2 0104 1d
#Purcha2: #Purcha2:
@ -101,7 +111,9 @@ cat << EOF | \
4001 00b2 0304 1d 4001 00b2 0304 1d
# Select SpecEv file # Select SpecEv file
4001 00a4 08 0004 2000 2040 4001 00a4 0000 00
4001 00a4 0000 02 2000
4001 00a4 0000 02 2040
#SpecEv1: #SpecEv1:
4001 00b2 0104 1d 4001 00b2 0104 1d
#SpecEv2: #SpecEv2:

View File

@ -68,7 +68,7 @@ Please report any bugs on the
.B libnfc .B libnfc
issue tracker at: issue tracker at:
.br .br
.BR http://code.google.com/p/libnfc/issues .BR https://github.com/nfc-tools/libnfc/issues
.SH LICENCE .SH LICENCE
.B libnfc .B libnfc
is licensed under the GNU Lesser General Public License (LGPL), version 3. is licensed under the GNU Lesser General Public License (LGPL), version 3.

View File

@ -9,6 +9,7 @@
* Copyright (C) 2012-2013 Ludovic Rousseau * Copyright (C) 2012-2013 Ludovic Rousseau
* See AUTHORS file for a more comprehensive list of contributors. * See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file: * Additional contributors of this file:
* Copyright (C) 2020 Adam Laurie
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the * under the terms of the GNU Lesser General Public License as published by the
@ -234,6 +235,14 @@ typedef struct {
uint8_t abtAtr[33]; uint8_t abtAtr[33];
} nfc_iso14443bi_info; } nfc_iso14443bi_info;
/**
* @struct nfc_iso14443biclass_info
* @brief NFC ISO14443BiClass tag information
*/
typedef struct {
uint8_t abtUID[8];
} nfc_iso14443biclass_info;
/** /**
* @struct nfc_iso14443b2sr_info * @struct nfc_iso14443b2sr_info
* @brief NFC ISO14443-2B ST SRx tag information * @brief NFC ISO14443-2B ST SRx tag information
@ -261,6 +270,15 @@ typedef struct {
uint8_t btId[4]; uint8_t btId[4];
} nfc_jewel_info; } nfc_jewel_info;
/**
* @struct nfc_barcode_info
* @brief Thinfilm NFC Barcode information
*/
typedef struct {
size_t szDataLen;
uint8_t abtData[32];
} nfc_barcode_info;
/** /**
* @union nfc_target_info * @union nfc_target_info
* @brief Union between all kind of tags information structures. * @brief Union between all kind of tags information structures.
@ -274,6 +292,8 @@ typedef union {
nfc_iso14443b2ct_info nci; nfc_iso14443b2ct_info nci;
nfc_jewel_info nji; nfc_jewel_info nji;
nfc_dep_info ndi; nfc_dep_info ndi;
nfc_barcode_info nti; // "t" for Thinfilm, "b" already used
nfc_iso14443biclass_info nhi; // hid iclass / picopass - nii already used
} nfc_target_info; } nfc_target_info;
/** /**
@ -301,6 +321,9 @@ typedef enum {
NMT_ISO14443B2CT, // ISO14443-2B ASK CTx NMT_ISO14443B2CT, // ISO14443-2B ASK CTx
NMT_FELICA, NMT_FELICA,
NMT_DEP, NMT_DEP,
NMT_BARCODE, // Thinfilm NFC Barcode
NMT_ISO14443BICLASS, // HID iClass 14443B mode
NMT_END_ENUM = NMT_ISO14443BICLASS, // dummy for sizing - always should alias last
} nfc_modulation_type; } nfc_modulation_type;
/** /**

View File

@ -28,14 +28,12 @@
* @file nfc.h * @file nfc.h
* @brief libnfc interface * @brief libnfc interface
* *
* Provide all usefull functions (API) to handle NFC devices. * Provide all useful functions (API) to handle NFC devices.
*/ */
#ifndef _LIBNFC_H_ #ifndef _LIBNFC_H_
# define _LIBNFC_H_ # define _LIBNFC_H_
# include <sys/time.h>
# include <stdint.h> # include <stdint.h>
# include <stdbool.h> # include <stdbool.h>
@ -127,6 +125,7 @@ NFC_EXPORT const char *nfc_device_get_name(nfc_device *pnd);
NFC_EXPORT const char *nfc_device_get_connstring(nfc_device *pnd); NFC_EXPORT const char *nfc_device_get_connstring(nfc_device *pnd);
NFC_EXPORT int nfc_device_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt); NFC_EXPORT int nfc_device_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt);
NFC_EXPORT int nfc_device_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br); NFC_EXPORT int nfc_device_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br);
NFC_EXPORT int nfc_device_get_supported_baud_rate_target_mode(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br);
/* Properties accessors */ /* Properties accessors */
NFC_EXPORT int nfc_device_set_property_int(nfc_device *pnd, const nfc_property property, const int value); NFC_EXPORT int nfc_device_set_property_int(nfc_device *pnd, const nfc_property property, const int value);

View File

@ -5,6 +5,9 @@ IF(WIN32)
# Add in the rc for version information in the dll # Add in the rc for version information in the dll
LIST(APPEND WINDOWS_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/../windows/libnfc.rc) LIST(APPEND WINDOWS_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/../windows/libnfc.rc)
IF (NOT MINGW)
LIST(APPEND WINDOWS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/nfc_msvc.def)
ENDIF()
ENDIF(WIN32) ENDIF(WIN32)
# Library's chips # Library's chips
@ -26,37 +29,27 @@ IF(UART_REQUIRED)
ENDIF(UART_REQUIRED) ENDIF(UART_REQUIRED)
IF(I2C_REQUIRED) IF(I2C_REQUIRED)
IF(WIN32) IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# Windows is not supported at the moment
#LIST(APPEND BUSES_SOURCES ../contrib/win32/libnfc/buses/i2c)
MESSAGE( FATAL_ERROR "I2C not (yet) supported under Windows!" )
ELSE(WIN32)
LIST(APPEND BUSES_SOURCES buses/i2c) LIST(APPEND BUSES_SOURCES buses/i2c)
ENDIF(WIN32) ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# Only Linux is supported at the moment
#LIST(APPEND BUSES_SOURCES ../contrib/win32/libnfc/buses/i2c)
MESSAGE( FATAL_ERROR "I2C is only (yet) supported in Linux!" )
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
ENDIF(I2C_REQUIRED) ENDIF(I2C_REQUIRED)
IF(SPI_REQUIRED) IF(SPI_REQUIRED)
IF(WIN32) IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# Windows is not supported at the moment
#LIST(APPEND BUSES_SOURCES ../contrib/win32/libnfc/buses/spi)
MESSAGE( FATAL_ERROR "SPI not (yet) supported under Windows!" )
ELSE(WIN32)
LIST(APPEND BUSES_SOURCES buses/spi) LIST(APPEND BUSES_SOURCES buses/spi)
ENDIF(WIN32) ELSE(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
# Only Linux is supported at the moment
#LIST(APPEND BUSES_SOURCES ../contrib/win32/libnfc/buses/spi)
MESSAGE( FATAL_ERROR "SPI is only (yet) supported in Linux!" )
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
ENDIF(SPI_REQUIRED) ENDIF(SPI_REQUIRED)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/buses) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/buses)
IF(WIN32)
# Windows now requires regex, so we utilize PCRE
# since Windows doesn't get the benefit of finding in CMake
# it has to be added manually
IF(PCRE_FOUND)
INCLUDE_DIRECTORIES(${PCRE_INCLUDE_DIRS})
LINK_DIRECTORIES(${PCRE_LIBRARY_DIRS})
ENDIF(PCRE_FOUND)
ENDIF(WIN32)
IF(PCSC_FOUND) IF(PCSC_FOUND)
INCLUDE_DIRECTORIES(${PCSC_INCLUDE_DIRS}) INCLUDE_DIRECTORIES(${PCSC_INCLUDE_DIRS})
LINK_DIRECTORIES(${PCSC_LIBRARY_DIRS}) LINK_DIRECTORIES(${PCSC_LIBRARY_DIRS})
@ -73,7 +66,9 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
IF(LIBNFC_LOG) IF(LIBNFC_LOG)
IF(WIN32) IF(WIN32)
SET(CMAKE_C_FLAGS "-fgnu89-inline ${CMAKE_C_FLAGS}") IF(MINGW)
SET(CMAKE_C_FLAGS "-fgnu89-inline ${CMAKE_C_FLAGS}")
ENDIF(MINGW)
LIST(APPEND LIBRARY_SOURCES log ../contrib/win32/libnfc/log-internal) LIST(APPEND LIBRARY_SOURCES log ../contrib/win32/libnfc/log-internal)
ELSE(WIN32) ELSE(WIN32)
LIST(APPEND LIBRARY_SOURCES log log-internal) LIST(APPEND LIBRARY_SOURCES log log-internal)
@ -89,21 +84,25 @@ IF(LIBUSB_FOUND)
TARGET_LINK_LIBRARIES(nfc ${LIBUSB_LIBRARIES}) TARGET_LINK_LIBRARIES(nfc ${LIBUSB_LIBRARIES})
ENDIF(LIBUSB_FOUND) ENDIF(LIBUSB_FOUND)
SET_TARGET_PROPERTIES(nfc PROPERTIES SOVERSION 0) IF(LIBRT_FOUND)
TARGET_LINK_LIBRARIES(nfc ${LIBRT_LIBRARIES})
ENDIF(LIBRT_FOUND)
SET_TARGET_PROPERTIES(nfc PROPERTIES SOVERSION 6 VERSION 6.0.0)
IF(WIN32) IF(WIN32)
# Libraries that are windows specific # Libraries that are windows specific
TARGET_LINK_LIBRARIES(nfc wsock32) TARGET_LINK_LIBRARIES(nfc wsock32)
IF(PCRE_FOUND) IF(MINGW)
TARGET_LINK_LIBRARIES(nfc ${PCRE_LIBRARIES}) ADD_CUSTOM_COMMAND(
ENDIF(PCRE_FOUND) OUTPUT libnfc.lib
COMMAND ${DLLTOOL} -d ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/nfc.def -l ${CMAKE_CURRENT_BINARY_DIR}/libnfc.lib ${CMAKE_CURRENT_BINARY_DIR}/libnfc.dll
ADD_CUSTOM_COMMAND( DEPENDS nfc ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/nfc.def
OUTPUT libnfc.lib )
COMMAND dlltool -d ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/nfc.def -l ${CMAKE_CURRENT_BINARY_DIR}/libnfc.lib ${CMAKE_CURRENT_BINARY_DIR}/libnfc.dll ADD_CUSTOM_TARGET(win32lib ALL DEPENDS libnfc.lib)
DEPENDS nfc ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/nfc.def ELSE()
) ADD_LIBRARY(win32lib ALIAS nfc)
ADD_CUSTOM_TARGET(win32lib ALL DEPENDS libnfc.lib) ENDIF()
# On Windows the shared (runtime) library should be either in the same # On Windows the shared (runtime) library should be either in the same
# directory as the excutables or in the path, we add it to same directory # directory as the excutables or in the path, we add it to same directory

View File

@ -22,7 +22,7 @@ libnfc_la_SOURCES = \
nfc-internal.h \ nfc-internal.h \
target-subr.h target-subr.h
libnfc_la_LDFLAGS = -no-undefined -version-info 5:1:0 -export-symbols-regex '^nfc_|^iso14443a_|^str_nfc_|pn53x_transceive|pn532_SAMConfiguration|pn53x_read_register|pn53x_write_register' libnfc_la_LDFLAGS = -no-undefined -version-info 6:0:0 -export-symbols-regex '^nfc_|^iso14443a_|^iso14443b_|^str_nfc_|pn53x_transceive|pn532_SAMConfiguration|pn53x_read_register|pn53x_write_register'
libnfc_la_CFLAGS = @DRIVERS_CFLAGS@ libnfc_la_CFLAGS = @DRIVERS_CFLAGS@
libnfc_la_LIBADD = \ libnfc_la_LIBADD = \
$(top_builddir)/libnfc/chips/libnfcchips.la \ $(top_builddir)/libnfc/chips/libnfcchips.la \
@ -44,4 +44,5 @@ if WITH_LOG
endif endif
EXTRA_DIST = \ EXTRA_DIST = \
CMakeLists.txt CMakeLists.txt \
additional-pages.dox

View File

@ -135,6 +135,8 @@ i2c_read(i2c_device id, uint8_t *pbtRx, const size_t szRx)
if (recCount < 0) { if (recCount < 0) {
res = NFC_EIO; res = NFC_EIO;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR,
"Error: read only %d bytes (%d expected) (%s).", (int)recCount, (int) szRx, strerror(errno));
} else { } else {
if (recCount < (ssize_t)szRx) { if (recCount < (ssize_t)szRx) {
res = NFC_EINVARG; res = NFC_EINVARG;
@ -167,7 +169,7 @@ i2c_write(i2c_device id, const uint8_t *pbtTx, const size_t szTx)
return NFC_SUCCESS; return NFC_SUCCESS;
} else { } else {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR,
"Error: wrote only %d bytes (%d expected).", (int)writeCount, (int) szTx); "Error: wrote only %d bytes (%d expected) (%s).", (int)writeCount, (int) szTx, strerror(errno));
return NFC_EIO; return NFC_EIO;
} }
} }
@ -189,29 +191,27 @@ i2c_list_ports(void)
size_t szRes = 1; size_t szRes = 1;
res[0] = NULL; res[0] = NULL;
DIR *dir; DIR *pdDir;
if ((dir = opendir("/dev")) == NULL) { if ((pdDir = opendir("/dev")) == NULL) {
perror("opendir error: /dev"); perror("opendir error: /dev");
return res; return res;
} }
struct dirent entry; struct dirent *pdDirEnt;
struct dirent *result; while ((pdDirEnt = readdir(pdDir)) != NULL) {
while ((readdir_r(dir, &entry, &result) == 0) && (result != NULL)) {
const char **p = i2c_ports_device_radix; const char **p = i2c_ports_device_radix;
while (*p) { while (*p) {
if (!strncmp(entry.d_name, *p, strlen(*p))) { if (!strncmp(pdDirEnt->d_name, *p, strlen(*p))) {
char **res2 = realloc(res, (szRes + 1) * sizeof(char *)); char **res2 = realloc(res, (szRes + 1) * sizeof(char *));
if (!res2) { if (!res2) {
perror("malloc"); perror("malloc");
goto oom; goto oom;
} }
res = res2; res = res2;
if (!(res[szRes - 1] = malloc(6 + strlen(entry.d_name)))) { if (!(res[szRes - 1] = malloc(6 + strlen(pdDirEnt->d_name)))) {
perror("malloc"); perror("malloc");
goto oom; goto oom;
} }
sprintf(res[szRes - 1], "/dev/%s", entry.d_name); sprintf(res[szRes - 1], "/dev/%s", pdDirEnt->d_name);
szRes++; szRes++;
res[szRes - 1] = NULL; res[szRes - 1] = NULL;
@ -220,7 +220,7 @@ i2c_list_ports(void)
} }
} }
oom: oom:
closedir(dir); closedir(pdDir);
return res; return res;
} }

View File

@ -196,7 +196,7 @@ spi_send_receive(spi_port sp, const uint8_t *pbtTx, const size_t szTx, uint8_t *
struct spi_ioc_transfer tr_send = { struct spi_ioc_transfer tr_send = {
.tx_buf = (unsigned long) pbtTx, .tx_buf = (unsigned long) pbtTx,
.rx_buf = 0, .rx_buf = 0,
.len = szTx , .len = szTx,
.delay_usecs = 0, .delay_usecs = 0,
.speed_hz = 0, .speed_hz = 0,
.bits_per_word = 0, .bits_per_word = 0,
@ -283,10 +283,7 @@ spi_list_ports(void)
DIR *pdDir = opendir("/dev"); DIR *pdDir = opendir("/dev");
struct dirent *pdDirEnt; struct dirent *pdDirEnt;
struct dirent entry; while ((pdDirEnt = readdir(pdDir)) != NULL) {
struct dirent *result;
while ((readdir_r(pdDir, &entry, &result) == 0) && (result != NULL)) {
pdDirEnt = &entry;
#if !defined(__APPLE__) #if !defined(__APPLE__)
if (!isdigit(pdDirEnt->d_name[strlen(pdDirEnt->d_name) - 1])) if (!isdigit(pdDirEnt->d_name[strlen(pdDirEnt->d_name) - 1]))
continue; continue;

View File

@ -74,15 +74,24 @@
#endif #endif
# if defined(__APPLE__) # if defined(__APPLE__)
const char *serial_ports_device_radix[] = { "tty.SLAB_USBtoUART", "tty.usbserial-", NULL }; const char *serial_ports_device_radix[] = { "tty.SLAB_USBtoUART", "tty.usbserial", "tty.usbmodem", NULL };
# elif defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__FreeBSD_kernel__) # elif defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__FreeBSD_kernel__)
const char *serial_ports_device_radix[] = { "cuaU", "cuau", NULL }; const char *serial_ports_device_radix[] = { "cuaU", "cuau", NULL };
# elif defined (__linux__) # elif defined (__NetBSD__)
const char *serial_ports_device_radix[] = { "tty0", "ttyC", "ttyS", "ttyU", "ttyY", NULL };
# elif defined (__linux__) || defined (__CYGWIN__)
const char *serial_ports_device_radix[] = { "ttyUSB", "ttyS", "ttyACM", "ttyAMA", "ttyO", NULL }; const char *serial_ports_device_radix[] = { "ttyUSB", "ttyS", "ttyACM", "ttyAMA", "ttyO", NULL };
# else # else
# error "Can't determine serial string for your system" # error "Can't determine serial string for your system"
# endif # endif
// As of 2015/Feb/22, Cygwin does not handle FIONREAD on physical serial devices.
// We'll use TIOCINQ instead which is pretty much the same.
#ifdef __CYGWIN__
# include <sys/termios.h>
# define FIONREAD TIOCINQ
#endif
// Work-around to claim uart interface using the c_iflag (software input processing) from the termios struct // Work-around to claim uart interface using the c_iflag (software input processing) from the termios struct
# define CCLAIMED 0x80000000 # define CCLAIMED 0x80000000
@ -179,7 +188,7 @@ uart_flush_input(serial_port sp, bool wait)
void void
uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) uart_set_speed(serial_port sp, const uint32_t uiPortSpeed)
{ {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Serial port speed requested to be set to %d bauds.", uiPortSpeed); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Serial port speed requested to be set to %d baud.", uiPortSpeed);
// Portability note: on some systems, B9600 != 9600 so we have to do // Portability note: on some systems, B9600 != 9600 so we have to do
// uint32_t <=> speed_t associations by hand. // uint32_t <=> speed_t associations by hand.
@ -215,7 +224,7 @@ uart_set_speed(serial_port sp, const uint32_t uiPortSpeed)
break; break;
# endif # endif
default: default:
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to set serial port speed to %d bauds. Speed value must be one of those defined in termios(3).", log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to set serial port speed to %d baud. Speed value must be one of those defined in termios(3).",
uiPortSpeed); uiPortSpeed);
return; return;
}; };
@ -385,32 +394,31 @@ uart_list_ports(void)
size_t szRes = 1; size_t szRes = 1;
res[0] = NULL; res[0] = NULL;
DIR *dir; DIR *pdDir;
if ((dir = opendir("/dev")) == NULL) { if ((pdDir = opendir("/dev")) == NULL) {
perror("opendir error: /dev"); perror("opendir error: /dev");
return res; return res;
} }
struct dirent entry; struct dirent *pdDirEnt;
struct dirent *result; while ((pdDirEnt = readdir(pdDir)) != NULL) {
while ((readdir_r(dir, &entry, &result) == 0) && (result != NULL)) {
#if !defined(__APPLE__) #if !defined(__APPLE__)
if (!isdigit(entry.d_name[strlen(entry.d_name) - 1])) if (!isdigit(pdDirEnt->d_name[strlen(pdDirEnt->d_name) - 1]))
continue; continue;
#endif #endif
const char **p = serial_ports_device_radix; const char **p = serial_ports_device_radix;
while (*p) { while (*p) {
if (!strncmp(entry.d_name, *p, strlen(*p))) { if (!strncmp(pdDirEnt->d_name, *p, strlen(*p))) {
char **res2 = realloc(res, (szRes + 1) * sizeof(char *)); char **res2 = realloc(res, (szRes + 1) * sizeof(char *));
if (!res2) { if (!res2) {
perror("malloc"); perror("malloc");
goto oom; goto oom;
} }
res = res2; res = res2;
if (!(res[szRes - 1] = malloc(6 + strlen(entry.d_name)))) { if (!(res[szRes - 1] = malloc(6 + strlen(pdDirEnt->d_name)))) {
perror("malloc"); perror("malloc");
goto oom; goto oom;
} }
sprintf(res[szRes - 1], "/dev/%s", entry.d_name); sprintf(res[szRes - 1], "/dev/%s", pdDirEnt->d_name);
szRes++; szRes++;
res[szRes - 1] = NULL; res[szRes - 1] = NULL;
@ -419,7 +427,7 @@ uart_list_ports(void)
} }
} }
oom: oom:
closedir(dir); closedir(pdDir);
return res; return res;
} }

View File

@ -33,7 +33,9 @@
#ifndef __NFC_BUS_UART_H__ #ifndef __NFC_BUS_UART_H__
# define __NFC_BUS_UART_H__ # define __NFC_BUS_UART_H__
#if !defined(_MSC_VER)
# include <sys/time.h> # include <sys/time.h>
#endif
# include <stdio.h> # include <stdio.h>
# include <string.h> # include <string.h>

View File

@ -35,6 +35,7 @@
#ifndef _WIN32 #ifndef _WIN32
// Under POSIX system, we use libusb (>= 0.1.12) // Under POSIX system, we use libusb (>= 0.1.12)
#include <stdint.h>
#include <usb.h> #include <usb.h>
#define USB_TIMEDOUT ETIMEDOUT #define USB_TIMEDOUT ETIMEDOUT
#define _usb_strerror( X ) strerror(-X) #define _usb_strerror( X ) strerror(-X)

View File

@ -81,32 +81,38 @@
#define TgGetTargetStatus 0x8A #define TgGetTargetStatus 0x8A
/** @note PN53x's normal frame: /** @note PN53x's normal frame:
* See the PN532 (firmware) user manual, section 6.2.1.1: Normal information
* frame, figure 13. Normal information frame, page 28 rev. 02 - 2007-11-07.
* *
* .-- Start * .-- Preamble
* | .-- Packet length * | .-- Start
* | | .-- Length checksum * | | .-- Packet length
* | | | .-- Direction (D4 Host to PN, D5 PN to Host) * | | | .-- Length checksum
* | | | | .-- Code * | | | | .-- Direction (D4 Host to PN, D5 PN to Host)
* | | | | | .-- Packet checksum * | | | | | .-- Code
* | | | | | | .-- Postamble * | | | | | | .-- Packet checksum
* V | | | | | | * | | | | | | | .-- Postamble
* ----- V V V V V V * | V | | | | | |
* 00 FF 02 FE D4 02 2A 00 * V ----- V V V V V V
* 00 00 FF 02 FE D4 02 2A 00
*/ */
/** @note PN53x's extended frame: /** @note PN53x's extended frame:
* See the PN532 (firmware) user manual, section 6.2.1.2: Extended information
* frame, figure 14. Normal information frame, page 29 rev. 02 - 2007-11-07.
* *
* .-- Start * .-- Preamble
* | .-- Fixed to FF to enable extended frame * | .-- Start
* | | .-- Packet length * | | .-- Fixed to FF to enable extended frame
* | | | .-- Length checksum * | | | .-- Packet length
* | | | | .-- Direction (D4 Host to PN, D5 PN to Host) * | | | | .-- Length checksum
* | | | | | .-- Code * | | | | | .-- Direction (D4 Host to PN, D5 PN to Host)
* | | | | | | .-- Packet checksum * | | | | | | .-- Code
* | | | | | | | .-- Postamble * | | | | | | | .-- Packet checksum
* V V V | | | | | * | | | | | | | | .-- Postamble
* ----- ----- ----- V V V V V * | V V V | | | | |
* 00 FF FF FF 00 02 FE D4 02 2A 00 * V ----- ----- ----- V V V V V
* 00 00 FF FF FF 00 02 FE D4 02 2A 00
*/ */
/** /**

View File

@ -9,6 +9,7 @@
* Copyright (C) 2012-2013 Ludovic Rousseau * Copyright (C) 2012-2013 Ludovic Rousseau
* See AUTHORS file for a more comprehensive list of contributors. * See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file: * Additional contributors of this file:
* Copyright (C) 2020 Adam Laurie
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the * under the terms of the GNU Lesser General Public License as published by the
@ -52,10 +53,12 @@
const uint8_t pn53x_ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 }; const uint8_t pn53x_ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 };
const uint8_t pn53x_nack_frame[] = { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 }; const uint8_t pn53x_nack_frame[] = { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 };
static const uint8_t pn53x_error_frame[] = { 0x00, 0x00, 0xff, 0x01, 0xff, 0x7f, 0x81, 0x00 }; static const uint8_t pn53x_error_frame[] = { 0x00, 0x00, 0xff, 0x01, 0xff, 0x7f, 0x81, 0x00 };
const nfc_baud_rate pn53x_iso14443a_supported_baud_rates[] = { NBR_106, 0 }; const nfc_baud_rate pn532_iso14443a_supported_baud_rates[] = { NBR_424, NBR_212, NBR_106, 0 };
const nfc_baud_rate pn533_iso14443a_supported_baud_rates[] = { NBR_847, NBR_424, NBR_212, NBR_106, 0 };
const nfc_baud_rate pn53x_felica_supported_baud_rates[] = { NBR_424, NBR_212, 0 }; const nfc_baud_rate pn53x_felica_supported_baud_rates[] = { NBR_424, NBR_212, 0 };
const nfc_baud_rate pn53x_dep_supported_baud_rates[] = { NBR_424, NBR_212, NBR_106, 0 }; const nfc_baud_rate pn53x_dep_supported_baud_rates[] = { NBR_424, NBR_212, NBR_106, 0 };
const nfc_baud_rate pn53x_jewel_supported_baud_rates[] = { NBR_106, 0 }; const nfc_baud_rate pn53x_jewel_supported_baud_rates[] = { NBR_106, 0 };
const nfc_baud_rate pn53x_barcode_supported_baud_rates[] = { NBR_106, 0 };
const nfc_baud_rate pn532_iso14443b_supported_baud_rates[] = { NBR_106, 0 }; const nfc_baud_rate pn532_iso14443b_supported_baud_rates[] = { NBR_106, 0 };
const nfc_baud_rate pn533_iso14443b_supported_baud_rates[] = { NBR_847, NBR_424, NBR_212, NBR_106, 0 }; const nfc_baud_rate pn533_iso14443b_supported_baud_rates[] = { NBR_847, NBR_424, NBR_212, NBR_106, 0 };
const nfc_modulation_type pn53x_supported_modulation_as_target[] = {NMT_ISO14443A, NMT_FELICA, NMT_DEP, 0}; const nfc_modulation_type pn53x_supported_modulation_as_target[] = {NMT_ISO14443A, NMT_FELICA, NMT_DEP, 0};
@ -83,7 +86,7 @@ pn53x_init(struct nfc_device *pnd)
} }
if (!CHIP_DATA(pnd)->supported_modulation_as_initiator) { if (!CHIP_DATA(pnd)->supported_modulation_as_initiator) {
CHIP_DATA(pnd)->supported_modulation_as_initiator = malloc(sizeof(nfc_modulation_type) * 9); CHIP_DATA(pnd)->supported_modulation_as_initiator = malloc(sizeof(nfc_modulation_type) * (NMT_END_ENUM + 1));
if (! CHIP_DATA(pnd)->supported_modulation_as_initiator) if (! CHIP_DATA(pnd)->supported_modulation_as_initiator)
return NFC_ESOFT; return NFC_ESOFT;
int nbSupportedModulation = 0; int nbSupportedModulation = 0;
@ -96,10 +99,20 @@ pn53x_init(struct nfc_device *pnd)
if (pnd->btSupportByte & SUPPORT_ISO14443B) { if (pnd->btSupportByte & SUPPORT_ISO14443B) {
CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_ISO14443B; CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_ISO14443B;
nbSupportedModulation++; nbSupportedModulation++;
CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_ISO14443BI;
nbSupportedModulation++;
CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_ISO14443B2SR;
nbSupportedModulation++;
CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_ISO14443B2CT;
nbSupportedModulation++;
CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_ISO14443BICLASS;
nbSupportedModulation++;
} }
if (CHIP_DATA(pnd)->type != PN531) { if (CHIP_DATA(pnd)->type != PN531) {
CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_JEWEL; CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_JEWEL;
nbSupportedModulation++; nbSupportedModulation++;
CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_BARCODE;
nbSupportedModulation++;
} }
CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_DEP; CHIP_DATA(pnd)->supported_modulation_as_initiator[nbSupportedModulation] = NMT_DEP;
nbSupportedModulation++; nbSupportedModulation++;
@ -364,7 +377,6 @@ int
pn53x_wrap_frame(const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar, pn53x_wrap_frame(const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbtTxPar,
uint8_t *pbtFrame) uint8_t *pbtFrame)
{ {
uint8_t btFrame;
uint8_t btData; uint8_t btData;
uint32_t uiBitPos; uint32_t uiBitPos;
uint32_t uiDataPos = 0; uint32_t uiDataPos = 0;
@ -391,7 +403,7 @@ pn53x_wrap_frame(const uint8_t *pbtTx, const size_t szTxBits, const uint8_t *pbt
// air-bytes = mirror(buffer-byte) + mirror(buffer-byte) + mirror(buffer-byte) + .. // air-bytes = mirror(buffer-byte) + mirror(buffer-byte) + mirror(buffer-byte) + ..
while (true) { while (true) {
// Reset the temporary frame byte; // Reset the temporary frame byte;
btFrame = 0; uint8_t btFrame = 0;
for (uiBitPos = 0; uiBitPos < 8; uiBitPos++) { for (uiBitPos = 0; uiBitPos < 8; uiBitPos++) {
// Copy as much data that fits in the frame byte // Copy as much data that fits in the frame byte
@ -566,6 +578,12 @@ pn53x_decode_target_data(const uint8_t *pbtRawData, size_t szRawData, pn53x_type
memcpy(pnti->nsi.abtUID, pbtRawData, 8); memcpy(pnti->nsi.abtUID, pbtRawData, 8);
break; break;
case NMT_ISO14443BICLASS:
// Store the UID
for (uint8_t i = 0 ; i < 8 ; ++i)
pnti->nhi.abtUID[7 - i] = pbtRawData[i];
break;
case NMT_ISO14443B2CT: case NMT_ISO14443B2CT:
// Store UID LSB // Store UID LSB
memcpy(pnti->nci.abtUID, pbtRawData, 2); memcpy(pnti->nci.abtUID, pbtRawData, 2);
@ -604,10 +622,13 @@ pn53x_decode_target_data(const uint8_t *pbtRawData, size_t szRawData, pn53x_type
pbtRawData += 2; pbtRawData += 2;
memcpy(pnti->nji.btId, pbtRawData, 4); memcpy(pnti->nji.btId, pbtRawData, 4);
break; break;
// Should not happend... case NMT_BARCODE:
pnti->nti.szDataLen = szRawData;
memcpy(pnti->nti.abtData, pbtRawData, szRawData);
break;
// Should not happend...
case NMT_DEP: case NMT_DEP:
return NFC_ECHIP; return NFC_ECHIP;
break;
} }
return NFC_SUCCESS; return NFC_SUCCESS;
} }
@ -820,12 +841,10 @@ pn53x_set_property_int(struct nfc_device *pnd, const nfc_property property, cons
case NP_TIMEOUT_ATR: case NP_TIMEOUT_ATR:
CHIP_DATA(pnd)->timeout_atr = value; CHIP_DATA(pnd)->timeout_atr = value;
return pn53x_RFConfiguration__Various_timings(pnd, pn53x_int_to_timeout(CHIP_DATA(pnd)->timeout_atr), pn53x_int_to_timeout(CHIP_DATA(pnd)->timeout_communication)); return pn53x_RFConfiguration__Various_timings(pnd, pn53x_int_to_timeout(CHIP_DATA(pnd)->timeout_atr), pn53x_int_to_timeout(CHIP_DATA(pnd)->timeout_communication));
break;
case NP_TIMEOUT_COM: case NP_TIMEOUT_COM:
CHIP_DATA(pnd)->timeout_communication = value; CHIP_DATA(pnd)->timeout_communication = value;
return pn53x_RFConfiguration__Various_timings(pnd, pn53x_int_to_timeout(CHIP_DATA(pnd)->timeout_atr), pn53x_int_to_timeout(CHIP_DATA(pnd)->timeout_communication)); return pn53x_RFConfiguration__Various_timings(pnd, pn53x_int_to_timeout(CHIP_DATA(pnd)->timeout_atr), pn53x_int_to_timeout(CHIP_DATA(pnd)->timeout_communication));
break; // Following properties are invalid (not integer)
// Following properties are invalid (not integer)
case NP_HANDLE_CRC: case NP_HANDLE_CRC:
case NP_HANDLE_PARITY: case NP_HANDLE_PARITY:
case NP_ACTIVATE_FIELD: case NP_ACTIVATE_FIELD:
@ -863,7 +882,6 @@ pn53x_set_property_bool(struct nfc_device *pnd, const nfc_property property, con
return res; return res;
pnd->bCrc = bEnable; pnd->bCrc = bEnable;
return NFC_SUCCESS; return NFC_SUCCESS;
break;
case NP_HANDLE_PARITY: case NP_HANDLE_PARITY:
// Handle parity bit by PN53X chip or parse it as data bit // Handle parity bit by PN53X chip or parse it as data bit
@ -875,21 +893,17 @@ pn53x_set_property_bool(struct nfc_device *pnd, const nfc_property property, con
return res; return res;
pnd->bPar = bEnable; pnd->bPar = bEnable;
return NFC_SUCCESS; return NFC_SUCCESS;
break;
case NP_EASY_FRAMING: case NP_EASY_FRAMING:
pnd->bEasyFraming = bEnable; pnd->bEasyFraming = bEnable;
return NFC_SUCCESS; return NFC_SUCCESS;
break;
case NP_ACTIVATE_FIELD: case NP_ACTIVATE_FIELD:
return pn53x_RFConfiguration__RF_field(pnd, bEnable); return pn53x_RFConfiguration__RF_field(pnd, bEnable);
break;
case NP_ACTIVATE_CRYPTO1: case NP_ACTIVATE_CRYPTO1:
btValue = (bEnable) ? SYMBOL_MF_CRYPTO1_ON : 0x00; btValue = (bEnable) ? SYMBOL_MF_CRYPTO1_ON : 0x00;
return pn53x_write_register(pnd, PN53X_REG_CIU_Status2, SYMBOL_MF_CRYPTO1_ON, btValue); return pn53x_write_register(pnd, PN53X_REG_CIU_Status2, SYMBOL_MF_CRYPTO1_ON, btValue);
break;
case NP_INFINITE_SELECT: case NP_INFINITE_SELECT:
// TODO Made some research around this point: // TODO Made some research around this point:
@ -901,17 +915,14 @@ pn53x_set_property_bool(struct nfc_device *pnd, const nfc_property property, con
(bEnable) ? 0xff : 0x01, // MxRtyPSL, default: 0x01 (bEnable) ? 0xff : 0x01, // MxRtyPSL, default: 0x01
(bEnable) ? 0xff : 0x02 // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531) (bEnable) ? 0xff : 0x02 // MxRtyPassiveActivation, default: 0xff (0x00 leads to problems with PN531)
); );
break;
case NP_ACCEPT_INVALID_FRAMES: case NP_ACCEPT_INVALID_FRAMES:
btValue = (bEnable) ? SYMBOL_RX_NO_ERROR : 0x00; btValue = (bEnable) ? SYMBOL_RX_NO_ERROR : 0x00;
return pn53x_write_register(pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_NO_ERROR, btValue); return pn53x_write_register(pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_NO_ERROR, btValue);
break;
case NP_ACCEPT_MULTIPLE_FRAMES: case NP_ACCEPT_MULTIPLE_FRAMES:
btValue = (bEnable) ? SYMBOL_RX_MULTIPLE : 0x00; btValue = (bEnable) ? SYMBOL_RX_MULTIPLE : 0x00;
return pn53x_write_register(pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_MULTIPLE, btValue); return pn53x_write_register(pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_MULTIPLE, btValue);
break;
case NP_AUTO_ISO14443_4: case NP_AUTO_ISO14443_4:
if (bEnable == pnd->bAutoIso14443_4) if (bEnable == pnd->bAutoIso14443_4)
@ -919,7 +930,6 @@ pn53x_set_property_bool(struct nfc_device *pnd, const nfc_property property, con
return NFC_SUCCESS; return NFC_SUCCESS;
pnd->bAutoIso14443_4 = bEnable; pnd->bAutoIso14443_4 = bEnable;
return pn53x_set_parameters(pnd, PARAM_AUTO_RATS, bEnable); return pn53x_set_parameters(pnd, PARAM_AUTO_RATS, bEnable);
break;
case NP_FORCE_ISO14443_A: case NP_FORCE_ISO14443_A:
if (!bEnable) { if (!bEnable) {
@ -935,7 +945,6 @@ pn53x_set_property_bool(struct nfc_device *pnd, const nfc_property property, con
} }
// Set the PN53X to force 100% ASK Modified miller decoding (default for 14443A cards) // Set the PN53X to force 100% ASK Modified miller decoding (default for 14443A cards)
return pn53x_write_register(pnd, PN53X_REG_CIU_TxAuto, SYMBOL_FORCE_100_ASK, 0x40); return pn53x_write_register(pnd, PN53X_REG_CIU_TxAuto, SYMBOL_FORCE_100_ASK, 0x40);
break;
case NP_FORCE_ISO14443_B: case NP_FORCE_ISO14443_B:
if (!bEnable) { if (!bEnable) {
@ -947,7 +956,6 @@ pn53x_set_property_bool(struct nfc_device *pnd, const nfc_property property, con
return res; return res;
} }
return pn53x_write_register(pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_FRAMING, 0x03); return pn53x_write_register(pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_FRAMING, 0x03);
break;
case NP_FORCE_SPEED_106: case NP_FORCE_SPEED_106:
if (!bEnable) { if (!bEnable) {
@ -959,13 +967,11 @@ pn53x_set_property_bool(struct nfc_device *pnd, const nfc_property property, con
return res; return res;
} }
return pn53x_write_register(pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_SPEED, 0x00); return pn53x_write_register(pnd, PN53X_REG_CIU_RxMode, SYMBOL_RX_SPEED, 0x00);
break; // Following properties are invalid (not boolean)
// Following properties are invalid (not boolean)
case NP_TIMEOUT_COMMAND: case NP_TIMEOUT_COMMAND:
case NP_TIMEOUT_ATR: case NP_TIMEOUT_ATR:
case NP_TIMEOUT_COM: case NP_TIMEOUT_COM:
return NFC_EINVARG; return NFC_EINVARG;
break;
} }
return NFC_EINVARG; return NFC_EINVARG;
@ -1051,6 +1057,56 @@ pn53x_initiator_init(struct nfc_device *pnd)
return NFC_SUCCESS; return NFC_SUCCESS;
} }
// iclass requires special modulation settings
void pn53x_initiator_init_iclass_modulation(struct nfc_device *pnd)
{
// send a bunch of low level commands reverse engineered from a working iClass reader
// original device was using a PN512
//
// // TxModeReg - Defines the data rate and framing during transmission.
//// set bit 4 for target mode? - RxWaitRF Set to logic 1, the counter for RxWait starts only if an external RF field is detected in Target mode for NFCIP-1 or in Card Communication mode
//pn512_write_register(0x12, "\x03", 1, false);
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TxMode, 0x03);
//
// // RxModeReg - Defines the data rate and framing during reception.
//pn512_write_register(0x13, "\x03", 1, false);
// addy changed to set bit 3 - RxNoErr (put data in fifo before flagging read end)
//pn512_write_register(0x13, "\x0B", 1, false);
pn53x_WriteRegister(pnd, PN53X_REG_CIU_RxMode, 0x0B);
// ManualRCVReg - Allows manual fine tuning of the internal receiver.
//pn512_write_register(0x1d, "\x10", 1, false);
pn53x_WriteRegister(pnd, PN53X_REG_CIU_ManualRCV, 0x10);
// RFCfgReg - Configures the receiver gain and RF level detector sensitivity.
//pn512_write_register(0x26, "\x70", 1, false);
pn53x_WriteRegister(pnd, PN53X_REG_CIU_RFCfg, 0x70);
// GsNOffReg - Selects the conductance for the N-driver of the antenna driver pins TX1 and TX2 when the driver is switched off.
//pn512_write_register(0x23, "\x88", 1, false);
pn53x_WriteRegister(pnd, PN53X_REG_CIU_GsNOFF, 0x88);
// GsNOnReg - Selects the conductance for the N-driver of the antenna driver pins TX1 and TX2 when the driver is switched on.
//pn512_write_register(0x27, "\xf8", 1, false);
pn53x_WriteRegister(pnd, PN53X_REG_CIU_GsNOn, 0xf8);
// CWGsPReg - Defines the conductance of the P-driver during times of no modulation.
//pn512_write_register(0x28, "\x3f", 1, false);
pn53x_WriteRegister(pnd, PN53X_REG_CIU_CWGsP, 0x3f);
// ModGsPReg - Defines the driver P-output conductance during modulation.
//pn512_write_register(0x29, "\x10", 1, false);
pn53x_WriteRegister(pnd, PN53X_REG_CIU_ModGsP, 0x10);
// TReloadReg (MSB) - Describes the MSB of the 16-bit long timer reload value.
//pn512_write_register(0x2c, "\x69", 1, false);
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TReloadVal_hi, 0x69);
// TReloadReg (LSB) - Describes the LSB of the 16-bit long timer reload value.
//pn512_write_register(0x2d, "\xf0", 1, false);
pn53x_WriteRegister(pnd, PN53X_REG_CIU_TReloadVal_lo, 0xf0);
}
int int
pn532_initiator_init_secure_element(struct nfc_device *pnd) pn532_initiator_init_secure_element(struct nfc_device *pnd)
{ {
@ -1068,8 +1124,9 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
size_t szTargetsData = sizeof(abtTargetsData); size_t szTargetsData = sizeof(abtTargetsData);
int res = 0; int res = 0;
nfc_target nttmp; nfc_target nttmp;
memset(&nttmp, 0x00, sizeof(nfc_target));
if (nm.nmt == NMT_ISO14443BI || nm.nmt == NMT_ISO14443B2SR || nm.nmt == NMT_ISO14443B2CT) { if (nm.nmt == NMT_ISO14443BI || nm.nmt == NMT_ISO14443B2SR || nm.nmt == NMT_ISO14443B2CT || nm.nmt == NMT_ISO14443BICLASS) {
if (CHIP_DATA(pnd)->type == RCS360) { if (CHIP_DATA(pnd)->type == RCS360) {
// TODO add support for RC-S360, at the moment it refuses to send raw frames without a first select // TODO add support for RC-S360, at the moment it refuses to send raw frames without a first select
pnd->last_error = NFC_ENOTIMPL; pnd->last_error = NFC_ENOTIMPL;
@ -1096,6 +1153,16 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
size_t szInitiateLen = 2; size_t szInitiateLen = 2;
uint8_t abtSelect[] = { 0x0e, 0x00 }; uint8_t abtSelect[] = { 0x0e, 0x00 };
uint8_t abtRx[1]; 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 // Getting random Chip_ID
if ((res = pn53x_initiator_transceive_bytes(pnd, abtInitiate, szInitiateLen, abtRx, sizeof(abtRx), timeout)) < 0) { 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 if ((res == NFC_ERFTRANS) && (CHIP_DATA(pnd)->last_status_byte == 0x01)) { // Chip timeout
@ -1108,9 +1175,18 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
return res; return res;
} }
szTargetsData = (size_t)res; szTargetsData = (size_t)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) { } else if (nm.nmt == NMT_ISO14443B2CT) {
// Some work to do before getting the UID... // Some work to do before getting the UID...
const uint8_t abtReqt[] = { 0x10 }; const uint8_t abtReqt[] = { 0x10 };
uint8_t *pbtInitData = (uint8_t *) "\x9F\xFF\xFF";
size_t szInitData = 3;
// Getting product code / fab code & store it in output buffer after the serial nr we'll obtain later // 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 = 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 if ((res == NFC_ERFTRANS) && (CHIP_DATA(pnd)->last_status_byte == 0x01)) { // Chip timeout
@ -1119,16 +1195,13 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
return res; return res;
} }
szTargetsData = (size_t)res; szTargetsData = (size_t)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
if ((res = pn53x_initiator_transceive_bytes(pnd, pbtInitData, szInitData, abtTargetsData, sizeof(abtTargetsData), timeout)) < 0) { continue;
if ((res == NFC_ERFTRANS) && (CHIP_DATA(pnd)->last_status_byte == 0x01)) { // Chip timeout } else
continue; return res;
} else }
return res; szTargetsData = (size_t)res;
}
szTargetsData = (size_t)res;
if (nm.nmt == NMT_ISO14443B2CT) {
if (szTargetsData != 2) if (szTargetsData != 2)
return 0; // Target is not ISO14443B2CT return 0; // Target is not ISO14443B2CT
uint8_t abtRead[] = { 0xC4 }; // Reading UID_MSB (Read address 4) uint8_t abtRead[] = { 0xC4 }; // Reading UID_MSB (Read address 4)
@ -1136,7 +1209,49 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
return res; return res;
} }
szTargetsData = 6; // u16 UID_LSB, u8 prod code, u8 fab code, u16 UID_MSB szTargetsData = 6; // u16 UID_LSB, u8 prod code, u8 fab code, u16 UID_MSB
} else if (nm.nmt == NMT_ISO14443BICLASS) {
pn53x_initiator_init_iclass_modulation(pnd);
//
// Some work to do before getting the UID...
// send ICLASS_ACTIVATE_ALL command - will get timeout as we don't expect response
uint8_t abtReqt[] = { 0x0a }; // iClass ACTIVATE_ALL
uint8_t abtAnticol[11];
if (pn53x_initiator_transceive_bytes(pnd, abtReqt, sizeof(abtReqt), NULL, 0, timeout) < 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "got expected timeout on iClass activate all");
//if ((res == NFC_ERFTRANS) && (CHIP_DATA(pnd)->last_status_byte == 0x01)) { // Chip timeout
// continue;
//} else
// return res;
}
// do select - returned anticol contains 'handle' for tag if present
abtReqt[0] = 0x0c; // iClass SELECT
abtAnticol[0] = 0x81; // iClass ANTICOL
if ((res = pn53x_initiator_transceive_bytes(pnd, abtReqt, sizeof(abtReqt), &abtAnticol[1], sizeof(abtAnticol) - 1, timeout)) < 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "timeout on iClass anticol");
return res;
}
// write back anticol handle to get UID
if ((res = pn53x_initiator_transceive_bytes(pnd, abtAnticol, 9, abtTargetsData, 10, timeout)) < 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "timeout on iClass get UID");
return res;
}
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "iClass raw UID: %02x %02x %02x %02x %02x %02x %02x %02x", abtTargetsData[0], abtTargetsData[1], abtTargetsData[2], abtTargetsData[3], abtTargetsData[4], abtTargetsData[5], abtTargetsData[6], abtTargetsData[7]);
szTargetsData = 8;
nttmp.nm = nm;
if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData, CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) {
return res;
}
} else {
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;
} }
nttmp.nm = nm; nttmp.nm = nm;
if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData, CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) { if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData, CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) {
return res; return res;
@ -1156,10 +1271,90 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
} while (pnd->bInfiniteSelect); } while (pnd->bInfiniteSelect);
if (! found) if (! found)
return 0; return 0;
} else { } else if (nm.nmt == NMT_BARCODE) {
if (CHIP_DATA(pnd)->type == RCS360) {
// TODO add support for RC-S360, at the moment it refuses to send raw frames without a first select
pnd->last_error = NFC_ENOTIMPL;
return pnd->last_error;
}
// No native support in InListPassiveTarget so we do discovery by hand
// We turn RF field off first for a better detection rate but this doesn't work well with ASK LoGO
if ((! CHIP_DATA(pnd)->progressive_field) && (res = nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, false)) < 0) {
return res;
}
if ((res = nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, false)) < 0) {
return res;
}
if ((res = nfc_device_set_property_bool(pnd, NP_HANDLE_PARITY, false)) < 0) {
return res;
}
bool found = false;
do {
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
uint8_t abtRxPar[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
if ((res = nfc_initiator_transceive_bits(pnd, NULL, 0, NULL, abtRx, sizeof(abtRx), abtRxPar)) < 0) {
if ((res == NFC_ERFTRANS) || (res == NFC_ECHIP)) { // Broken reception
continue;
} else {
nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, true);
nfc_device_set_property_bool(pnd, NP_HANDLE_PARITY, true);
return res;
}
}
// Shuffle bits to produce NFC Barcode bitstream
uint8_t uRemainder;
size_t szPos;
size_t szBytes = res / 8;
size_t off = 0;
uint8_t i;
memset(abtTargetsData, 0x00, sizeof(abtTargetsData));
// Reinject S bit
abtTargetsData[off / 8] |= 1 << (7 - (off % 8));
off++;
for (szPos = 0; szPos < szBytes; szPos++) {
for (i = 0; i < 8; i++) {
abtTargetsData[off / 8] |= ((abtRx[szPos] >> i) & 1) << (7 - (off % 8));
off++;
}
abtTargetsData[off / 8] |= abtRxPar[szPos] << (7 - (off % 8));
off++;
}
uRemainder = res % 8;
for (i = 0; i < uRemainder; i++) {
abtTargetsData[off / 8] |= ((abtRx[szPos] >> i) & 1) << (7 - (off % 8));
off++;
}
if (off % 128 != 0) {
// NFC Barcode seems incomplete
continue;
}
szTargetsData = (size_t)off / 8;
// validate CRC
uint8_t pbtCrc[2];
iso14443a_crc(abtTargetsData, szTargetsData - 2, pbtCrc);
if ((pbtCrc[1] != abtTargetsData[szTargetsData - 2]) || (pbtCrc[0] != abtTargetsData[szTargetsData - 1])) {
continue;
}
nttmp.nm = nm;
if ((res = pn53x_decode_target_data(abtTargetsData, szTargetsData, CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) {
return res;
}
found = true;
break;
} while (pnd->bInfiniteSelect);
if (! found) {
return 0;
}
} else {
const pn53x_modulation pm = pn53x_nm_to_pm(nm); const pn53x_modulation pm = pn53x_nm_to_pm(nm);
if (PM_UNDEFINED == pm) { if ((PM_UNDEFINED == pm) || (NBR_UNDEFINED == nm.nbr)) {
pnd->last_error = NFC_EINVARG; pnd->last_error = NFC_EINVARG;
return pnd->last_error; return pnd->last_error;
} }
@ -1174,6 +1369,14 @@ pn53x_initiator_select_passive_target_ext(struct nfc_device *pnd,
if ((res = pn53x_decode_target_data(abtTargetsData + 1, szTargetsData - 1, CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) { if ((res = pn53x_decode_target_data(abtTargetsData + 1, szTargetsData - 1, CHIP_DATA(pnd)->type, nm.nmt, &(nttmp.nti))) < 0) {
return res; return res;
} }
if ((nm.nmt == NMT_ISO14443A) && (nm.nbr != NBR_106)) {
uint8_t pncmd_inpsl[4] = { InPSL, 0x01 };
pncmd_inpsl[2] = nm.nbr - 1;
pncmd_inpsl[3] = nm.nbr - 1;
if ((res = pn53x_transceive(pnd, pncmd_inpsl, sizeof(pncmd_inpsl), NULL, 0, 0)) < 0) {
return res;
}
}
} }
if (pn53x_current_target_new(pnd, &nttmp) == NULL) { if (pn53x_current_target_new(pnd, &nttmp) == NULL) {
pnd->last_error = NFC_ESOFT; pnd->last_error = NFC_ESOFT;
@ -1192,7 +1395,7 @@ pn53x_initiator_select_passive_target(struct nfc_device *pnd,
const uint8_t *pbtInitData, const size_t szInitData, const uint8_t *pbtInitData, const size_t szInitData,
nfc_target *pnt) nfc_target *pnt)
{ {
return pn53x_initiator_select_passive_target_ext(pnd, nm, pbtInitData, szInitData, pnt, 0); return pn53x_initiator_select_passive_target_ext(pnd, nm, pbtInitData, szInitData, pnt, 300);
} }
int int
@ -1222,26 +1425,28 @@ pn53x_initiator_poll_target(struct nfc_device *pnd,
szTargetTypes++; szTargetTypes++;
} }
nfc_target ntTargets[2]; nfc_target ntTargets[2];
memset(ntTargets, 0x00, sizeof(nfc_target) * 2);
if ((res = pn53x_InAutoPoll(pnd, apttTargetTypes, szTargetTypes, uiPollNr, uiPeriod, ntTargets, 0)) < 0) if ((res = pn53x_InAutoPoll(pnd, apttTargetTypes, szTargetTypes, uiPollNr, uiPeriod, ntTargets, 0)) < 0)
return res; return res;
switch (res) { switch (res) {
case 0:
return pnd->last_error = NFC_SUCCESS;
break;
case 1: case 1:
*pnt = ntTargets[0]; *pnt = ntTargets[0];
if (pn53x_current_target_new(pnd, pnt) == NULL) { if (pn53x_current_target_new(pnd, pnt) == NULL) {
return pnd->last_error = NFC_ESOFT; return pnd->last_error = NFC_ESOFT;
} }
return res; return res;
break;
case 2: case 2:
*pnt = ntTargets[1]; // We keep the selected one *pnt = ntTargets[1]; // We keep the selected one
if (pn53x_current_target_new(pnd, pnt) == NULL) { if (pn53x_current_target_new(pnd, pnt) == NULL) {
return pnd->last_error = NFC_ESOFT; return pnd->last_error = NFC_ESOFT;
} }
return res; return res;
break;
default: default:
return NFC_ECHIP; return NFC_ECHIP;
break;
} }
} else { } else {
bool bInfiniteSelect = pnd->bInfiniteSelect; bool bInfiniteSelect = pnd->bInfiniteSelect;
@ -1303,7 +1508,6 @@ pn53x_initiator_select_dep_target(struct nfc_device *pnd,
case NBR_847: case NBR_847:
case NBR_UNDEFINED: case NBR_UNDEFINED:
return NFC_EINVARG; return NFC_EINVARG;
break;
} }
pn53x_current_target_free(pnd); pn53x_current_target_free(pnd);
@ -1334,7 +1538,7 @@ pn53x_initiator_transceive_bits(struct nfc_device *pnd, const uint8_t *pbtTx, co
uint8_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN] = { InCommunicateThru }; uint8_t abtCmd[PN53x_EXTENDED_FRAME__DATA_MAX_LEN] = { InCommunicateThru };
// Check if we should prepare the parity bits ourself // Check if we should prepare the parity bits ourself
if (!pnd->bPar) { if ((!pnd->bPar) && (szTxBits > 0)) {
// Convert data with parity to a frame // Convert data with parity to a frame
if ((res = pn53x_wrap_frame(pbtTx, szTxBits, pbtTxPar, abtCmd + 1)) < 0) if ((res = pn53x_wrap_frame(pbtTx, szTxBits, pbtTxPar, abtCmd + 1)) < 0)
return res; return res;
@ -1466,9 +1670,8 @@ static void __pn53x_init_timer(struct nfc_device *pnd, const uint32_t max_cycles
static uint32_t __pn53x_get_timer(struct nfc_device *pnd, const uint8_t last_cmd_byte) static uint32_t __pn53x_get_timer(struct nfc_device *pnd, const uint8_t last_cmd_byte)
{ {
uint8_t parity;
uint8_t counter_hi, counter_lo; uint8_t counter_hi, counter_lo;
uint16_t counter, u16cycles; uint16_t counter;
uint32_t u32cycles; uint32_t u32cycles;
size_t off = 0; size_t off = 0;
if (CHIP_DATA(pnd)->type == PN533) { if (CHIP_DATA(pnd)->type == PN533) {
@ -1496,6 +1699,8 @@ static uint32_t __pn53x_get_timer(struct nfc_device *pnd, const uint8_t last_cmd
// counter saturated // counter saturated
u32cycles = 0xFFFFFFFF; u32cycles = 0xFFFFFFFF;
} else { } else {
uint8_t parity;
uint16_t u16cycles;
u16cycles = 0xFFFF - counter; u16cycles = 0xFFFF - counter;
u32cycles = u16cycles; u32cycles = u16cycles;
u32cycles *= (CHIP_DATA(pnd)->timer_prescaler * 2 + 1); u32cycles *= (CHIP_DATA(pnd)->timer_prescaler * 2 + 1);
@ -1733,7 +1938,7 @@ pn53x_initiator_transceive_bytes_timed(struct nfc_device *pnd, const uint8_t *pb
if (pnd->bCrc) { if (pnd->bCrc) {
// We've to compute CRC ourselves to know last byte actually sent // We've to compute CRC ourselves to know last byte actually sent
uint8_t *pbtTxRaw; uint8_t *pbtTxRaw;
pbtTxRaw = (uint8_t *) malloc(szTx + 2); pbtTxRaw = (uint8_t *) calloc(szTx + 2, 1);
if (!pbtTxRaw) if (!pbtTxRaw)
return NFC_ESOFT; return NFC_ESOFT;
memcpy(pbtTxRaw, pbtTx, szTx); memcpy(pbtTxRaw, pbtTx, szTx);
@ -1846,6 +2051,40 @@ static int pn53x_ISO14443A_Jewel_is_present(struct nfc_device *pnd)
return ret; return ret;
} }
static int pn53x_ISO14443A_Barcode_is_present(struct nfc_device *pnd)
{
int ret;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping Barcode");
// We turn RF field off first for a better detection rate but this doesn't work well with ASK LoGO
if ((! CHIP_DATA(pnd)->progressive_field) && (ret = nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, false)) < 0) {
return ret;
}
if ((ret = nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, false)) < 0)
return ret;
if ((ret = nfc_device_set_property_bool(pnd, NP_HANDLE_PARITY, false)) < 0)
return ret;
int failures = 0;
while (failures < 3) {
if ((! CHIP_DATA(pnd)->progressive_field) && (ret = nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, false)) < 0) {
return ret;
}
uint8_t abtRx[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
uint8_t abtRxPar[PN53x_EXTENDED_FRAME__DATA_MAX_LEN];
if (nfc_initiator_transceive_bits(pnd, NULL, 0, NULL, abtRx, sizeof(abtRx), abtRxPar) < 1) {
failures++;
} else {
nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, true);
nfc_device_set_property_bool(pnd, NP_HANDLE_PARITY, true);
return NFC_SUCCESS;
}
}
nfc_device_set_property_bool(pnd, NP_HANDLE_CRC, true);
nfc_device_set_property_bool(pnd, NP_HANDLE_PARITY, true);
return NFC_ETGRELEASED;
}
static int pn53x_ISO14443A_MFUL_is_present(struct nfc_device *pnd) static int pn53x_ISO14443A_MFUL_is_present(struct nfc_device *pnd)
{ {
int ret; int ret;
@ -2016,6 +2255,29 @@ static int pn53x_ISO14443B_SR_is_present(struct nfc_device *pnd)
return ret; return ret;
} }
static int pn53x_ISO14443B_ICLASS_is_present(struct nfc_device *pnd)
{
int timeout = 300;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping B iClass");
pn53x_initiator_init_iclass_modulation(pnd);
//
// Some work to do before getting the UID...
// send ICLASS_ACTIVATE_ALL command - will get timeout as we don't expect response
uint8_t abtReqt[] = { 0x0a }; // iClass ACTIVATE_ALL
uint8_t abtAnticol[11];
if (pn53x_initiator_transceive_bytes(pnd, abtReqt, sizeof(abtReqt), NULL, 0, timeout) < 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "got expected timeout on iClass activate all");
}
// do select - returned anticol contains 'handle' for tag if present
abtReqt[0] = 0x0c; // iClass SELECT
abtAnticol[0] = 0x81; // iClass ANTICOL
if (pn53x_initiator_transceive_bytes(pnd, abtReqt, sizeof(abtReqt), &abtAnticol[1], sizeof(abtAnticol) - 1, timeout) < 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "timeout on iClass anticol");
return NFC_ETGRELEASED;;
}
return NFC_SUCCESS;
}
static int pn53x_ISO14443B_CT_is_present(struct nfc_device *pnd) static int pn53x_ISO14443B_CT_is_present(struct nfc_device *pnd)
{ {
int ret; int ret;
@ -2056,7 +2318,7 @@ pn53x_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt)
} }
// Ping target // Ping target
int ret; int ret = NFC_EDEVNOTSUPP;
switch (CHIP_DATA(pnd)->current_target->nm.nmt) { switch (CHIP_DATA(pnd)->current_target->nm.nmt) {
case NMT_ISO14443A: case NMT_ISO14443A:
if (CHIP_DATA(pnd)->current_target->nti.nai.btSak & 0x20) { if (CHIP_DATA(pnd)->current_target->nti.nai.btSak & 0x20) {
@ -2081,6 +2343,9 @@ pn53x_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt)
case NMT_JEWEL: case NMT_JEWEL:
ret = pn53x_ISO14443A_Jewel_is_present(pnd); ret = pn53x_ISO14443A_Jewel_is_present(pnd);
break; break;
case NMT_BARCODE:
ret = pn53x_ISO14443A_Barcode_is_present(pnd);
break;
case NMT_ISO14443B: case NMT_ISO14443B:
ret = pn53x_ISO14443B_4_is_present(pnd); ret = pn53x_ISO14443B_4_is_present(pnd);
break; break;
@ -2093,9 +2358,8 @@ pn53x_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt)
case NMT_ISO14443B2CT: case NMT_ISO14443B2CT:
ret = pn53x_ISO14443B_CT_is_present(pnd); ret = pn53x_ISO14443B_CT_is_present(pnd);
break; break;
default: case NMT_ISO14443BICLASS:
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): card type not supported"); ret = pn53x_ISO14443B_ICLASS_is_present(pnd);
ret = NFC_EDEVNOTSUPP;
break; break;
} }
if (ret == NFC_ETGRELEASED) if (ret == NFC_ETGRELEASED)
@ -2147,10 +2411,11 @@ pn53x_target_init(struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const
case NMT_ISO14443BI: case NMT_ISO14443BI:
case NMT_ISO14443B2SR: case NMT_ISO14443B2SR:
case NMT_ISO14443B2CT: case NMT_ISO14443B2CT:
case NMT_ISO14443BICLASS:
case NMT_JEWEL: case NMT_JEWEL:
case NMT_BARCODE:
pnd->last_error = NFC_EDEVNOTSUPP; pnd->last_error = NFC_EDEVNOTSUPP;
return pnd->last_error; return pnd->last_error;
break;
} }
// Let the PN53X be activated by the RF level detector from power down mode // Let the PN53X be activated by the RF level detector from power down mode
@ -2249,10 +2514,11 @@ pn53x_target_init(struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const
case NMT_ISO14443BI: case NMT_ISO14443BI:
case NMT_ISO14443B2SR: case NMT_ISO14443B2SR:
case NMT_ISO14443B2CT: case NMT_ISO14443B2CT:
case NMT_ISO14443BICLASS:
case NMT_JEWEL: case NMT_JEWEL:
case NMT_BARCODE:
pnd->last_error = NFC_EDEVNOTSUPP; pnd->last_error = NFC_EDEVNOTSUPP;
return pnd->last_error; return pnd->last_error;
break;
} }
bool targetActivated = false; bool targetActivated = false;
@ -2397,12 +2663,15 @@ pn53x_target_receive_bytes(struct nfc_device *pnd, uint8_t *pbtRx, const size_t
return pnd->last_error; return pnd->last_error;
} }
} }
// NO BREAK abtCmd[0] = TgGetInitiatorCommand;
break;
case NMT_JEWEL: case NMT_JEWEL:
case NMT_BARCODE:
case NMT_ISO14443B: case NMT_ISO14443B:
case NMT_ISO14443BI: case NMT_ISO14443BI:
case NMT_ISO14443B2SR: case NMT_ISO14443B2SR:
case NMT_ISO14443B2CT: case NMT_ISO14443B2CT:
case NMT_ISO14443BICLASS:
case NMT_FELICA: case NMT_FELICA:
abtCmd[0] = TgGetInitiatorCommand; abtCmd[0] = TgGetInitiatorCommand;
break; break;
@ -2502,12 +2771,15 @@ pn53x_target_send_bytes(struct nfc_device *pnd, const uint8_t *pbtTx, const size
return pnd->last_error; return pnd->last_error;
} }
} }
// NO BREAK abtCmd[0] = TgResponseToInitiator;
break;
case NMT_JEWEL: case NMT_JEWEL:
case NMT_BARCODE:
case NMT_ISO14443B: case NMT_ISO14443B:
case NMT_ISO14443BI: case NMT_ISO14443BI:
case NMT_ISO14443B2SR: case NMT_ISO14443B2SR:
case NMT_ISO14443B2CT: case NMT_ISO14443B2CT:
case NMT_ISO14443BICLASS:
case NMT_FELICA: case NMT_FELICA:
abtCmd[0] = TgResponseToInitiator; abtCmd[0] = TgResponseToInitiator;
break; break;
@ -2720,6 +2992,7 @@ pn53x_InListPassiveTarget(struct nfc_device *pnd,
} }
break; break;
case PM_JEWEL_106: case PM_JEWEL_106:
case PM_BARCODE_106:
if (CHIP_DATA(pnd)->type == PN531) { if (CHIP_DATA(pnd)->type == PN531) {
// These modulations are not supported by pn531 // These modulations are not supported by pn531
pnd->last_error = NFC_EDEVNOTSUPP; pnd->last_error = NFC_EDEVNOTSUPP;
@ -2911,7 +3184,6 @@ pn53x_InJumpForDEP(struct nfc_device *pnd,
case NBR_UNDEFINED: case NBR_UNDEFINED:
pnd->last_error = NFC_EINVARG; pnd->last_error = NFC_EINVARG;
return pnd->last_error; return pnd->last_error;
break;
} }
if (pbtNFCID3i) { if (pbtNFCID3i) {
@ -3128,22 +3400,18 @@ pn53x_nm_to_pm(const nfc_modulation nm)
switch (nm.nmt) { switch (nm.nmt) {
case NMT_ISO14443A: case NMT_ISO14443A:
return PM_ISO14443A_106; return PM_ISO14443A_106;
break;
case NMT_ISO14443B: case NMT_ISO14443B:
case NMT_ISO14443BICLASS:
switch (nm.nbr) { switch (nm.nbr) {
case NBR_106: case NBR_106:
return PM_ISO14443B_106; return PM_ISO14443B_106;
break;
case NBR_212: case NBR_212:
return PM_ISO14443B_212; return PM_ISO14443B_212;
break;
case NBR_424: case NBR_424:
return PM_ISO14443B_424; return PM_ISO14443B_424;
break;
case NBR_847: case NBR_847:
return PM_ISO14443B_847; return PM_ISO14443B_847;
break;
case NBR_UNDEFINED: case NBR_UNDEFINED:
// Nothing to do... // Nothing to do...
break; break;
@ -3152,16 +3420,16 @@ pn53x_nm_to_pm(const nfc_modulation nm)
case NMT_JEWEL: case NMT_JEWEL:
return PM_JEWEL_106; return PM_JEWEL_106;
break;
case NMT_BARCODE:
return PM_BARCODE_106;
case NMT_FELICA: case NMT_FELICA:
switch (nm.nbr) { switch (nm.nbr) {
case NBR_212: case NBR_212:
return PM_FELICA_212; return PM_FELICA_212;
break;
case NBR_424: case NBR_424:
return PM_FELICA_424; return PM_FELICA_424;
break;
case NBR_106: case NBR_106:
case NBR_847: case NBR_847:
case NBR_UNDEFINED: case NBR_UNDEFINED:
@ -3194,36 +3462,31 @@ pn53x_ptt_to_nm(const pn53x_target_type ptt)
case PTT_MIFARE: case PTT_MIFARE:
case PTT_ISO14443_4A_106: case PTT_ISO14443_4A_106:
return (const nfc_modulation) { .nmt = NMT_ISO14443A, .nbr = NBR_106 }; return (const nfc_modulation) { .nmt = NMT_ISO14443A, .nbr = NBR_106 };
break;
case PTT_ISO14443_4B_106: case PTT_ISO14443_4B_106:
case PTT_ISO14443_4B_TCL_106: case PTT_ISO14443_4B_TCL_106:
return (const nfc_modulation) { .nmt = NMT_ISO14443B, .nbr = NBR_106 }; return (const nfc_modulation) { .nmt = NMT_ISO14443B, .nbr = NBR_106 };
break;
case PTT_JEWEL_106: case PTT_JEWEL_106:
return (const nfc_modulation) { .nmt = NMT_JEWEL, .nbr = NBR_106 }; return (const nfc_modulation) { .nmt = NMT_JEWEL, .nbr = NBR_106 };
break;
case PTT_FELICA_212: case PTT_FELICA_212:
return (const nfc_modulation) { .nmt = NMT_FELICA, .nbr = NBR_212 }; return (const nfc_modulation) { .nmt = NMT_FELICA, .nbr = NBR_212 };
break;
case PTT_FELICA_424: case PTT_FELICA_424:
return (const nfc_modulation) { .nmt = NMT_FELICA, .nbr = NBR_424 }; return (const nfc_modulation) { .nmt = NMT_FELICA, .nbr = NBR_424 };
break;
case PTT_DEP_PASSIVE_106: case PTT_DEP_PASSIVE_106:
case PTT_DEP_ACTIVE_106: case PTT_DEP_ACTIVE_106:
return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_106 }; return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_106 };
break;
case PTT_DEP_PASSIVE_212: case PTT_DEP_PASSIVE_212:
case PTT_DEP_ACTIVE_212: case PTT_DEP_ACTIVE_212:
return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_212 }; return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_212 };
break;
case PTT_DEP_PASSIVE_424: case PTT_DEP_PASSIVE_424:
case PTT_DEP_ACTIVE_424: case PTT_DEP_ACTIVE_424:
return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_424 }; return (const nfc_modulation) { .nmt = NMT_DEP, .nbr = NBR_424 };
break;
} }
// We should never be here, this line silent compilation warning // We should never be here, this line silent compilation warning
return (const nfc_modulation) { .nmt = NMT_ISO14443A, .nbr = NBR_106 }; return (const nfc_modulation) { .nmt = NMT_ISO14443A, .nbr = NBR_106 };
@ -3235,14 +3498,14 @@ pn53x_nm_to_ptt(const nfc_modulation nm)
switch (nm.nmt) { switch (nm.nmt) {
case NMT_ISO14443A: case NMT_ISO14443A:
return PTT_MIFARE; return PTT_MIFARE;
// return PTT_ISO14443_4A_106; // return PTT_ISO14443_4A_106;
break;
case NMT_ISO14443B: case NMT_ISO14443B:
case NMT_ISO14443BICLASS:
switch (nm.nbr) { switch (nm.nbr) {
case NBR_106: case NBR_106:
return PTT_ISO14443_4B_106; return PTT_ISO14443_4B_106;
break;
case NBR_UNDEFINED: case NBR_UNDEFINED:
case NBR_212: case NBR_212:
case NBR_424: case NBR_424:
@ -3254,16 +3517,15 @@ pn53x_nm_to_ptt(const nfc_modulation nm)
case NMT_JEWEL: case NMT_JEWEL:
return PTT_JEWEL_106; return PTT_JEWEL_106;
break;
case NMT_FELICA: case NMT_FELICA:
switch (nm.nbr) { switch (nm.nbr) {
case NBR_212: case NBR_212:
return PTT_FELICA_212; return PTT_FELICA_212;
break;
case NBR_424: case NBR_424:
return PTT_FELICA_424; return PTT_FELICA_424;
break;
case NBR_UNDEFINED: case NBR_UNDEFINED:
case NBR_106: case NBR_106:
case NBR_847: case NBR_847:
@ -3275,6 +3537,7 @@ pn53x_nm_to_ptt(const nfc_modulation nm)
case NMT_ISO14443BI: case NMT_ISO14443BI:
case NMT_ISO14443B2SR: case NMT_ISO14443B2SR:
case NMT_ISO14443B2CT: case NMT_ISO14443B2CT:
case NMT_BARCODE:
case NMT_DEP: case NMT_DEP:
// Nothing to do... // Nothing to do...
break; break;
@ -3299,19 +3562,21 @@ pn53x_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_m
} }
int int
pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br) pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br)
{ {
switch (nmt) { switch (nmt) {
case NMT_FELICA: case NMT_FELICA:
*supported_br = (nfc_baud_rate *)pn53x_felica_supported_baud_rates; *supported_br = (nfc_baud_rate *)pn53x_felica_supported_baud_rates;
break; break;
case NMT_ISO14443A: case NMT_ISO14443A: {
*supported_br = (nfc_baud_rate *)pn53x_iso14443a_supported_baud_rates; if ((CHIP_DATA(pnd)->type != PN533) || (mode == N_TARGET)) {
break; *supported_br = (nfc_baud_rate *)pn532_iso14443a_supported_baud_rates;
case NMT_ISO14443B: } else {
case NMT_ISO14443BI: *supported_br = (nfc_baud_rate *)pn533_iso14443a_supported_baud_rates;
case NMT_ISO14443B2SR: }
case NMT_ISO14443B2CT: { }
break;
case NMT_ISO14443B: {
if ((CHIP_DATA(pnd)->type != PN533)) { if ((CHIP_DATA(pnd)->type != PN533)) {
*supported_br = (nfc_baud_rate *)pn532_iso14443b_supported_baud_rates; *supported_br = (nfc_baud_rate *)pn532_iso14443b_supported_baud_rates;
} else { } else {
@ -3319,9 +3584,18 @@ pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, co
} }
} }
break; break;
case NMT_ISO14443BI:
case NMT_ISO14443B2SR:
case NMT_ISO14443B2CT:
case NMT_ISO14443BICLASS:
*supported_br = (nfc_baud_rate *)pn532_iso14443b_supported_baud_rates;
break;
case NMT_JEWEL: case NMT_JEWEL:
*supported_br = (nfc_baud_rate *)pn53x_jewel_supported_baud_rates; *supported_br = (nfc_baud_rate *)pn53x_jewel_supported_baud_rates;
break; break;
case NMT_BARCODE:
*supported_br = (nfc_baud_rate *)pn53x_barcode_supported_baud_rates;
break;
case NMT_DEP: case NMT_DEP:
*supported_br = (nfc_baud_rate *)pn53x_dep_supported_baud_rates; *supported_br = (nfc_baud_rate *)pn53x_dep_supported_baud_rates;
break; break;
@ -3434,7 +3708,6 @@ pn53x_get_information_about(nfc_device *pnd, char **pbuf)
free(*pbuf); free(*pbuf);
return res; return res;
} }
for (int i = 0; nmt[i]; i++) { for (int i = 0; nmt[i]; i++) {
if ((res = snprintf(buf, buflen, "%s%s (", (i == 0) ? "" : ", ", str_nfc_modulation_type(nmt[i]))) < 0) { if ((res = snprintf(buf, buflen, "%s%s (", (i == 0) ? "" : ", ", str_nfc_modulation_type(nmt[i]))) < 0) {
free(*pbuf); free(*pbuf);
@ -3447,7 +3720,7 @@ pn53x_get_information_about(nfc_device *pnd, char **pbuf)
} }
buflen -= res; buflen -= res;
const nfc_baud_rate *nbr; const nfc_baud_rate *nbr;
if ((res = nfc_device_get_supported_baud_rate(pnd, nmt[i], &nbr)) < 0) { if ((res = nfc_device_get_supported_baud_rate_target_mode(pnd, nmt[i], &nbr)) < 0) {
free(*pbuf); free(*pbuf);
return res; return res;
} }
@ -3576,6 +3849,9 @@ pn53x_data_new(struct nfc_device *pnd, const struct pn53x_io *io)
CHIP_DATA(pnd)->supported_modulation_as_target = NULL; CHIP_DATA(pnd)->supported_modulation_as_target = NULL;
// Set default progressive field flag
CHIP_DATA(pnd)->progressive_field = false;
return pnd->chip_data; return pnd->chip_data;
} }

View File

@ -9,6 +9,7 @@
* Copyright (C) 2012-2013 Ludovic Rousseau * Copyright (C) 2012-2013 Ludovic Rousseau
* See AUTHORS file for a more comprehensive list of contributors. * See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file: * Additional contributors of this file:
* Copyright (C) 2020 Adam Laurie
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the * under the terms of the GNU Lesser General Public License as published by the
@ -210,6 +211,7 @@ struct pn53x_data {
/** Supported modulation type */ /** Supported modulation type */
nfc_modulation_type *supported_modulation_as_initiator; nfc_modulation_type *supported_modulation_as_initiator;
nfc_modulation_type *supported_modulation_as_target; nfc_modulation_type *supported_modulation_as_target;
bool progressive_field;
}; };
#define CHIP_DATA(pnd) ((struct pn53x_data*)(pnd->chip_data)) #define CHIP_DATA(pnd) ((struct pn53x_data*)(pnd->chip_data))
@ -231,6 +233,8 @@ typedef enum {
PM_ISO14443B_106 = 0x03, PM_ISO14443B_106 = 0x03,
/** Jewel Topaz (Innovision Research & Development) (Not supported by PN531) */ /** Jewel Topaz (Innovision Research & Development) (Not supported by PN531) */
PM_JEWEL_106 = 0x04, PM_JEWEL_106 = 0x04,
/** Thinfilm NFC Barcode (Not supported by PN531) */
PM_BARCODE_106 = 0x05,
/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */ /** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */
PM_ISO14443B_212 = 0x06, PM_ISO14443B_212 = 0x06,
/** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */ /** ISO14443-B http://en.wikipedia.org/wiki/ISO/IEC_14443 (Not supported by PN531 nor PN532) */
@ -319,6 +323,7 @@ int pn53x_idle(struct nfc_device *pnd);
// NFC device as Initiator functions // NFC device as Initiator functions
int pn53x_initiator_init(struct nfc_device *pnd); int pn53x_initiator_init(struct nfc_device *pnd);
void pn53x_initiator_init_iclass_modulation(struct nfc_device *pnd);
int pn532_initiator_init_secure_element(struct nfc_device *pnd); int pn532_initiator_init_secure_element(struct nfc_device *pnd);
int pn53x_initiator_select_passive_target(struct nfc_device *pnd, int pn53x_initiator_select_passive_target(struct nfc_device *pnd,
const nfc_modulation nm, const nfc_modulation nm,
@ -392,7 +397,7 @@ int pn53x_check_ack_frame(struct nfc_device *pnd, const uint8_t *pbtRxFrame,
int pn53x_check_error_frame(struct nfc_device *pnd, const uint8_t *pbtRxFrame, const size_t szRxFrameLen); int pn53x_check_error_frame(struct nfc_device *pnd, const uint8_t *pbtRxFrame, const size_t szRxFrameLen);
int pn53x_build_frame(uint8_t *pbtFrame, size_t *pszFrame, const uint8_t *pbtData, const size_t szData); int pn53x_build_frame(uint8_t *pbtFrame, size_t *pszFrame, const uint8_t *pbtData, const size_t szData);
int pn53x_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt); int pn53x_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt);
int pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br); int pn53x_get_supported_baud_rate(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br);
int pn53x_get_information_about(nfc_device *pnd, char **pbuf); int pn53x_get_information_about(nfc_device *pnd, char **pbuf);
void *pn53x_data_new(struct nfc_device *pnd, const struct pn53x_io *io); void *pn53x_data_new(struct nfc_device *pnd, const struct pn53x_io *io);

View File

@ -33,9 +33,9 @@
#ifdef CONFFILES #ifdef CONFFILES
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h>
#include <dirent.h> #include <dirent.h>
#include <string.h> #include <string.h>
#include <regex.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <nfc/nfc.h> #include <nfc/nfc.h>
@ -56,30 +56,129 @@
#define LIBNFC_CONFFILE LIBNFC_SYSCONFDIR"/libnfc.conf" #define LIBNFC_CONFFILE LIBNFC_SYSCONFDIR"/libnfc.conf"
#define LIBNFC_DEVICECONFDIR LIBNFC_SYSCONFDIR"/devices.d" #define LIBNFC_DEVICECONFDIR LIBNFC_SYSCONFDIR"/devices.d"
static bool static int
conf_parse_file(const char *filename, void (*conf_keyvalue)(void *data, const char *key, const char *value), void *data) escaped_value(const char line[BUFSIZ], int i, char **value)
{
if (line[i] != '"')
goto FAIL;
i++;
if (line[i] == 0 || line[i] == '\n')
goto FAIL;
int c = 0;
while (line[i] && line[i] != '"') {
i++;
c++;
}
if (line[i] != '"')
goto FAIL;
*value = malloc(c + 1);
if (!*value)
goto FAIL;
memset(*value, 0, c + 1);
memcpy(*value, &line[i - c], c);
i++;
while (line[i] && isspace(line[i]))
i++;
if (line[i] != 0 && line[i] != '\n')
goto FAIL;
return 0;
FAIL:
free(*value);
*value = NULL;
return -1;
}
static int
non_escaped_value(const char line[BUFSIZ], int i, char **value)
{
int c = 0;
while (line[i] && !isspace(line[i])) {
i++;
c++;
}
*value = malloc(c + 1);
if (!*value)
goto FAIL;
memset(*value, 0, c + 1);
memcpy(*value, &line[i - c], c);
i++;
while (line[i] && isspace(line[i]))
i++;
if (line[i] != 0)
goto FAIL;
return 0;
FAIL:
free(*value);
*value = NULL;
return -1;
}
static int
parse_line(const char line[BUFSIZ], char **key, char **value)
{
*key = NULL;
*value = NULL;
int i = 0;
int c = 0;
// optional initial spaces
while (isspace(line[i]))
i++;
if (line[i] == 0 || line[i] == '\n')
return -1;
// key
while (isalnum(line[i]) || line[i] == '_' || line[i] == '.') {
i++;
c++;
}
if (c == 0 || line[i] == 0 || line[i] == '\n') // key is empty
return -1;
*key = malloc(c + 1);
if (!*key)
return -1;
memset(*key, 0, c + 1);
memcpy(*key, &line[i - c], c);
// space before '='
while (isspace(line[i]))
i++;
if (line[i] != '=')
return -1;
i++;
if (line[i] == 0 || line[i] == '\n')
return -1;
// space after '='
while (isspace(line[i]))
i++;
if (line[i] == 0 || line[i] == '\n')
return -1;
if (escaped_value(line, i, value) == 0)
return 0;
else if (non_escaped_value(line, i, value) == 0)
return 0;
// Extracting key or value failed
free(*key);
*key = NULL;
free(*value);
*value = NULL;
return -1;
}
static void
conf_parse_file(const char *filename,
void (*conf_keyvalue)(void *data, const char *key, const char *value),
void *data)
{ {
FILE *f = fopen(filename, "r"); FILE *f = fopen(filename, "r");
if (!f) { if (!f) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "Unable to open file: %s", filename); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "Unable to open file: %s", filename);
return false; return;
} }
char line[BUFSIZ]; char line[BUFSIZ];
const char *str_regex = "^[[:space:]]*([[:alnum:]_.]+)[[:space:]]*=[[:space:]]*(\"(.+)\"|([^[:space:]]+))[[:space:]]*$";
regex_t preg;
if (regcomp(&preg, str_regex, REG_EXTENDED | REG_NOTEOL) != 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Regular expression used for configuration file parsing is not valid.");
fclose(f);
return false;
}
size_t nmatch = preg.re_nsub + 1;
regmatch_t *pmatch = malloc(sizeof(*pmatch) * nmatch);
if (!pmatch) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Not enough memory: malloc failed.");
regfree(&preg);
fclose(f);
return false;
}
int lineno = 0; int lineno = 0;
while (fgets(line, BUFSIZ, f) != NULL) { while (fgets(line, BUFSIZ, f) != NULL) {
@ -89,30 +188,22 @@ conf_parse_file(const char *filename, void (*conf_keyvalue)(void *data, const ch
case '\n': case '\n':
break; break;
default: { default: {
int match; char *key;
if ((match = regexec(&preg, line, nmatch, pmatch, 0)) == 0) { char *value;
const size_t key_size = pmatch[1].rm_eo - pmatch[1].rm_so; if (parse_line(line, &key, &value) == 0) {
const off_t value_pmatch = pmatch[3].rm_eo != -1 ? 3 : 4;
const size_t value_size = pmatch[value_pmatch].rm_eo - pmatch[value_pmatch].rm_so;
char key[key_size + 1];
char value[value_size + 1];
strncpy(key, line + (pmatch[1].rm_so), key_size);
key[key_size] = '\0';
strncpy(value, line + (pmatch[value_pmatch].rm_so), value_size);
value[value_size] = '\0';
conf_keyvalue(data, key, value); conf_keyvalue(data, key, value);
free(key);
free(value);
} else { } else {
free(key);
free(value);
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Parse error on line #%d: %s", lineno, line); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Parse error on line #%d: %s", lineno, line);
} }
} }
break;
} }
} }
free(pmatch);
regfree(&preg);
fclose(f); fclose(f);
return false; return;
} }
static void static void
@ -177,14 +268,8 @@ conf_devices_load(const char *dirname, nfc_context *context)
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open directory: %s", dirname); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open directory: %s", dirname);
} else { } else {
struct dirent *de; struct dirent *de;
#ifdef WIN32
while ((de = readdir(d)) != NULL) { while ((de = readdir(d)) != NULL) {
#else // FIXME add a way to sort devices
struct dirent entry;
struct dirent *result;
while ((readdir_r(d, &entry, &result) == 0) && (result != NULL)) {
de = &entry;
#endif
if (de->d_name[0] != '.') { if (de->d_name[0] != '.') {
const size_t filename_len = strlen(de->d_name); const size_t filename_len = strlen(de->d_name);
const size_t extension_len = strlen(".conf"); const size_t extension_len = strlen(".conf");

View File

@ -7,6 +7,10 @@ libnfcdrivers_la_SOURCES =
libnfcdrivers_la_CFLAGS = @DRIVERS_CFLAGS@ -I$(top_srcdir)/libnfc -I$(top_srcdir)/libnfc/buses libnfcdrivers_la_CFLAGS = @DRIVERS_CFLAGS@ -I$(top_srcdir)/libnfc -I$(top_srcdir)/libnfc/buses
libnfcdrivers_la_LIBADD = libnfcdrivers_la_LIBADD =
if DRIVER_PCSC_ENABLED
libnfcdrivers_la_SOURCES += pcsc.c pcsc.h
endif
if DRIVER_ACR122_PCSC_ENABLED if DRIVER_ACR122_PCSC_ENABLED
libnfcdrivers_la_SOURCES += acr122_pcsc.c acr122_pcsc.h libnfcdrivers_la_SOURCES += acr122_pcsc.c acr122_pcsc.h
endif endif
@ -39,6 +43,11 @@ if DRIVER_PN532_I2C_ENABLED
libnfcdrivers_la_SOURCES += pn532_i2c.c pn532_i2c.h libnfcdrivers_la_SOURCES += pn532_i2c.c pn532_i2c.h
endif endif
if DRIVER_PN71XX_ENABLED
libnfcdrivers_la_LIBADD += @LIBNFC_NCI_LIBS@
libnfcdrivers_la_SOURCES += pn71xx.c pn71xx.h
endif
if PCSC_ENABLED if PCSC_ENABLED
libnfcdrivers_la_CFLAGS += @libpcsclite_CFLAGS@ libnfcdrivers_la_CFLAGS += @libpcsclite_CFLAGS@
libnfcdrivers_la_LIBADD += @libpcsclite_LIBS@ libnfcdrivers_la_LIBADD += @libpcsclite_LIBS@

View File

@ -59,7 +59,7 @@
# define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE SCARD_CTL_CODE(3500) # define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE SCARD_CTL_CODE(3500)
#elif defined(__APPLE__) #elif defined(__APPLE__)
# define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE (((0x31) << 16) | ((3500) << 2)) # define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE (((0x31) << 16) | ((3500) << 2))
#elif defined (__FreeBSD__) || defined (__OpenBSD__) #elif defined (__FreeBSD__) || defined (__OpenBSD__) || defined (__NetBSD__)
# define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE (((0x31) << 16) | ((3500) << 2)) # define IOCTL_CCID_ESCAPE_SCARD_CTL_CODE (((0x31) << 16) | ((3500) << 2))
#elif defined (__linux__) #elif defined (__linux__)
# include <reader.h> # include <reader.h>
@ -93,7 +93,7 @@ const struct pn53x_io acr122_pcsc_io;
// Prototypes // Prototypes
char *acr122_pcsc_firmware(nfc_device *pnd); char *acr122_pcsc_firmware(nfc_device *pnd);
const char *supported_devices[] = { static const char *supported_devices[] = {
"ACS ACR122", // ACR122U & Touchatag, last version "ACS ACR122", // ACR122U & Touchatag, last version
"ACS ACR 38U-CCID", // Touchatag, early version "ACS ACR 38U-CCID", // Touchatag, early version
"ACS ACR38U-CCID", // Touchatag, early version, under MacOSX "ACS ACR38U-CCID", // Touchatag, early version, under MacOSX
@ -400,15 +400,14 @@ acr122_pcsc_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szData, int
{ {
// FIXME: timeout is not handled // FIXME: timeout is not handled
(void) timeout; (void) timeout;
int len; int len;
uint8_t abtRxCmd[5] = { 0xFF, 0xC0, 0x00, 0x00 };
if (DRIVER_DATA(pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_T0) { if (DRIVER_DATA(pnd)->ioCard.dwProtocol == SCARD_PROTOCOL_T0) {
/* /*
* Retrieve the PN532 response. * Retrieve the PN532 response.
*/ */
DWORD dwRxLen = sizeof(DRIVER_DATA(pnd)->abtRx); DWORD dwRxLen = sizeof(DRIVER_DATA(pnd)->abtRx);
uint8_t abtRxCmd[5] = { 0xFF, 0xC0, 0x00, 0x00 };
abtRxCmd[4] = DRIVER_DATA(pnd)->abtRx[1]; abtRxCmd[4] = DRIVER_DATA(pnd)->abtRx[1];
if (SCardTransmit(DRIVER_DATA(pnd)->hCard, &(DRIVER_DATA(pnd)->ioCard), abtRxCmd, sizeof(abtRxCmd), NULL, DRIVER_DATA(pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) { if (SCardTransmit(DRIVER_DATA(pnd)->hCard, &(DRIVER_DATA(pnd)->ioCard), abtRxCmd, sizeof(abtRxCmd), NULL, DRIVER_DATA(pnd)->abtRx, &dwRxLen) != SCARD_S_SUCCESS) {
pnd->last_error = NFC_EIO; pnd->last_error = NFC_EIO;

View File

@ -60,7 +60,9 @@ Thanks to d18c7db and Okko for example code
#include <sys/select.h> #include <sys/select.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#ifdef _MSC_VER
#include <sys/types.h>
#endif
#include <nfc/nfc.h> #include <nfc/nfc.h>
#include "nfc-internal.h" #include "nfc-internal.h"
@ -262,6 +264,7 @@ struct acr122_usb_supported_device {
const struct acr122_usb_supported_device acr122_usb_supported_devices[] = { const struct acr122_usb_supported_device acr122_usb_supported_devices[] = {
{ 0x072F, 0x2200, "ACS ACR122" }, { 0x072F, 0x2200, "ACS ACR122" },
{ 0x072F, 0x90CC, "Touchatag" }, { 0x072F, 0x90CC, "Touchatag" },
{ 0x072F, 0x2214, "ACS ACR1222" },
}; };
// Find transfer endpoints for bulk transfers // Find transfer endpoints for bulk transfers
@ -330,7 +333,10 @@ acr122_usb_scan(const nfc_context *context, nfc_connstring connstrings[], const
// acr122_usb_get_usb_device_name (dev, udev, pnddDevices[device_found].acDevice, sizeof (pnddDevices[device_found].acDevice)); // acr122_usb_get_usb_device_name (dev, udev, pnddDevices[device_found].acDevice, sizeof (pnddDevices[device_found].acDevice));
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "device found: Bus %s Device %s Name %s", bus->dirname, dev->filename, acr122_usb_supported_devices[n].name); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "device found: Bus %s Device %s Name %s", bus->dirname, dev->filename, acr122_usb_supported_devices[n].name);
usb_close(udev); usb_close(udev);
snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", ACR122_USB_DRIVER_NAME, bus->dirname, dev->filename); if (snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", ACR122_USB_DRIVER_NAME, bus->dirname, dev->filename) >= (int)sizeof(nfc_connstring)) {
// truncation occurred, skipping that one
continue;
}
device_found++; device_found++;
// Test if we reach the maximum "wanted" devices // Test if we reach the maximum "wanted" devices
if (device_found == connstrings_len) { if (device_found == connstrings_len) {
@ -426,12 +432,15 @@ acr122_usb_open(const nfc_context *context, const nfc_connstring connstring)
goto free_mem; goto free_mem;
} }
res = usb_set_altinterface(data.pudh, 0); // Check if there are more than 0 alternative interfaces and claim the first one
if (res < 0) { if (dev->config->interface->altsetting->bAlternateSetting > 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to set alternate setting on USB interface (%s)", _usb_strerror(res)); res = usb_set_altinterface(data.pudh, 0);
usb_close(data.pudh); if (res < 0) {
// we failed to use the specified device log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to set alternate setting on USB interface (%s)", _usb_strerror(res));
goto free_mem; usb_close(data.pudh);
// we failed to use the specified device
goto free_mem;
}
} }
// Allocate memory for the device info and specification, fill it and return the info // Allocate memory for the device info and specification, fill it and return the info
@ -589,7 +598,7 @@ read:
if (timeout == USB_INFINITE_TIMEOUT) { if (timeout == USB_INFINITE_TIMEOUT) {
usb_timeout = USB_TIMEOUT_PER_PASS; usb_timeout = USB_TIMEOUT_PER_PASS;
} else { } else {
// A user-provided timeout is set, we have to cut it in multiple chunk to be able to keep an nfc_abort_command() mecanism // A user-provided timeout is set, we have to cut it in multiple chunk to be able to keep an nfc_abort_command() mechanism
remaining_time -= USB_TIMEOUT_PER_PASS; remaining_time -= USB_TIMEOUT_PER_PASS;
if (remaining_time <= 0) { if (remaining_time <= 0) {
pnd->last_error = NFC_ETIMEOUT; pnd->last_error = NFC_ETIMEOUT;
@ -603,6 +612,7 @@ read:
uint8_t attempted_response = RDR_to_PC_DataBlock; uint8_t attempted_response = RDR_to_PC_DataBlock;
size_t len; size_t len;
int error, status;
if (res == NFC_ETIMEOUT) { if (res == NFC_ETIMEOUT) {
if (DRIVER_DATA(pnd)->abort_flag) { if (DRIVER_DATA(pnd)->abort_flag) {
@ -614,7 +624,7 @@ read:
goto read; goto read;
} }
} }
if (res < 12) { if (res < 10) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Invalid RDR_to_PC_DataBlock frame"); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Invalid RDR_to_PC_DataBlock frame");
// try to interrupt current device state // try to interrupt current device state
acr122_usb_ack(pnd); acr122_usb_ack(pnd);
@ -629,6 +639,16 @@ read:
offset++; offset++;
len = abtRxBuf[offset++]; len = abtRxBuf[offset++];
status = abtRxBuf[7];
error = abtRxBuf[8];
if (len == 0 && error == 0xFE) { // ICC_MUTE; XXX check for more errors
// Do not check status; my ACR122U seemingly has status=0 in this case,
// even though the spec says it should have had bmCommandStatus=1
// and bmICCStatus=1.
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Command timed out");
pnd->last_error = NFC_ETIMEOUT;
return pnd->last_error;
}
if (!((len > 1) && (abtRxBuf[10] == 0xd5))) { // In case we didn't get an immediate answer: if (!((len > 1) && (abtRxBuf[10] == 0xd5))) { // In case we didn't get an immediate answer:
if (len != 2) { if (len != 2) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Wrong reply"); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Wrong reply");
@ -657,7 +677,7 @@ read:
goto read; // FIXME May cause some trouble on Touchatag, right ? goto read; // FIXME May cause some trouble on Touchatag, right ?
} }
} }
if (res < 12) { if (res < 10) {
// try to interrupt current device state // try to interrupt current device state
acr122_usb_ack(pnd); acr122_usb_ack(pnd);
pnd->last_error = NFC_EIO; pnd->last_error = NFC_EIO;

View File

@ -422,7 +422,7 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz
while ((acPort = acPorts[iDevice++])) { while ((acPort = acPorts[iDevice++])) {
sp = uart_open(acPort); sp = uart_open(acPort);
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Trying to find ACR122S device on serial port: %s at %d bauds.", acPort, ACR122S_DEFAULT_SPEED); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Trying to find ACR122S device on serial port: %s at %d baud.", acPort, ACR122S_DEFAULT_SPEED);
if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) { if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) {
// We need to flush input to be sure first reply does not comes from older byte transceive // We need to flush input to be sure first reply does not comes from older byte transceive
@ -527,7 +527,7 @@ acr122s_close(nfc_device *pnd)
uart_close(DRIVER_DATA(pnd)->port); uart_close(DRIVER_DATA(pnd)->port);
#ifndef WIN32 #ifndef WIN32
// Release file descriptors used for abort mecanism // Release file descriptors used for abort mechanism
close(DRIVER_DATA(pnd)->abort_fds[0]); close(DRIVER_DATA(pnd)->abort_fds[0]);
close(DRIVER_DATA(pnd)->abort_fds[1]); close(DRIVER_DATA(pnd)->abort_fds[1]);
#endif #endif
@ -562,7 +562,7 @@ acr122s_open(const nfc_context *context, const nfc_connstring connstring)
} }
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG,
"Attempt to connect to: %s at %d bauds.", ndd.port, ndd.speed); "Attempt to connect to: %s at %d baud.", ndd.port, ndd.speed);
sp = uart_open(ndd.port); sp = uart_open(ndd.port);
if (sp == INVALID_SERIAL_PORT) { if (sp == INVALID_SERIAL_PORT) {

View File

@ -91,7 +91,6 @@ struct arygon_data {
// ARYGON frames // ARYGON frames
static const uint8_t arygon_error_none[] = "FF000000\x0d\x0a"; static const uint8_t arygon_error_none[] = "FF000000\x0d\x0a";
static const uint8_t arygon_error_incomplete_command[] = "FF0C0000\x0d\x0a";
static const uint8_t arygon_error_unknown_mode[] = "FF060000\x0d\x0a"; static const uint8_t arygon_error_unknown_mode[] = "FF060000\x0d\x0a";
// Prototypes // Prototypes
@ -109,7 +108,7 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size
while ((acPort = acPorts[iDevice++])) { while ((acPort = acPorts[iDevice++])) {
sp = uart_open(acPort); sp = uart_open(acPort);
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Trying to find ARYGON device on serial port: %s at %d bauds.", acPort, ARYGON_DEFAULT_SPEED); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Trying to find ARYGON device on serial port: %s at %d baud.", acPort, ARYGON_DEFAULT_SPEED);
if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) { if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) {
// We need to flush input to be sure first reply does not comes from older byte transceive // We need to flush input to be sure first reply does not comes from older byte transceive
@ -159,7 +158,7 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size
} }
#ifndef WIN32 #ifndef WIN32
// pipe-based abort mecanism // pipe-based abort mechanism
if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) { if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) {
uart_close(DRIVER_DATA(pnd)->port); uart_close(DRIVER_DATA(pnd)->port);
pn53x_data_free(pnd); pn53x_data_free(pnd);
@ -212,7 +211,7 @@ arygon_close_step2(nfc_device *pnd)
uart_close(DRIVER_DATA(pnd)->port); uart_close(DRIVER_DATA(pnd)->port);
#ifndef WIN32 #ifndef WIN32
// Release file descriptors used for abort mecanism // Release file descriptors used for abort mechanism
close(DRIVER_DATA(pnd)->iAbortFds[0]); close(DRIVER_DATA(pnd)->iAbortFds[0]);
close(DRIVER_DATA(pnd)->iAbortFds[1]); close(DRIVER_DATA(pnd)->iAbortFds[1]);
#endif #endif
@ -253,7 +252,7 @@ arygon_open(const nfc_context *context, const nfc_connstring connstring)
serial_port sp; serial_port sp;
nfc_device *pnd = NULL; nfc_device *pnd = NULL;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Attempt to open: %s at %d bauds.", ndd.port, ndd.speed); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Attempt to open: %s at %d baud.", ndd.port, ndd.speed);
sp = uart_open(ndd.port); sp = uart_open(ndd.port);
if (sp == INVALID_SERIAL_PORT) if (sp == INVALID_SERIAL_PORT)
@ -305,7 +304,7 @@ arygon_open(const nfc_context *context, const nfc_connstring connstring)
pnd->driver = &arygon_driver; pnd->driver = &arygon_driver;
#ifndef WIN32 #ifndef WIN32
// pipe-based abort mecanism // pipe-based abort mechanism
if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) { if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) {
uart_close(DRIVER_DATA(pnd)->port); uart_close(DRIVER_DATA(pnd)->port);
pn53x_data_free(pnd); pn53x_data_free(pnd);

1080
libnfc/drivers/pcsc.c Normal file

File diff suppressed because it is too large Load Diff

35
libnfc/drivers/pcsc.h Normal file
View File

@ -0,0 +1,35 @@
/*-
* Free/Libre Near Field Communication (NFC) library
*
* Libnfc historical contributors:
* Copyright (C) 2019 Frank Morgner
* See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file:
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
/**
* @file pcsc.h
* @brief Driver for non-ACR122 devices (behind PC/SC daemon)
*/
#ifndef __NFC_DRIVER_PCSC_H__
#define __NFC_DRIVER_PCSC_H__
#include <nfc/nfc-types.h>
extern const struct nfc_driver pcsc_driver;
#endif // ! __NFC_DRIVER_PCSC_H__

View File

@ -59,6 +59,13 @@
// I2C address of the PN532 chip. // I2C address of the PN532 chip.
#define PN532_I2C_ADDR 0x24 #define PN532_I2C_ADDR 0x24
/*
* When sending lots of data, the pn532 occasionally fails to respond in time.
* Since it happens so rarely, lets try to fix it by re-sending the data. This
* define allows for fine tuning the number of retries.
*/
#define PN532_SEND_RETRIES 3
// Internal data structs // Internal data structs
const struct pn53x_io pn532_i2c_io; const struct pn53x_io pn532_i2c_io;
@ -67,13 +74,9 @@ struct pn532_i2c_data {
volatile bool abort_flag; volatile bool abort_flag;
}; };
/* Delay for the loop waiting for READY frame (in ms) */ /* preamble and start bytes, see pn532-internal.h for details */
#define PN532_RDY_LOOP_DELAY 90 const uint8_t pn53x_preamble_and_start[] = { 0x00, 0x00, 0xff };
#define PN53X_PREAMBLE_AND_START_LEN (sizeof(pn53x_preamble_and_start) / sizeof(pn53x_preamble_and_start[0]))
const struct timespec rdyDelay = {
.tv_sec = 0,
.tv_nsec = PN532_RDY_LOOP_DELAY * 1000 * 1000
};
/* Private Functions Prototypes */ /* Private Functions Prototypes */
@ -96,6 +99,70 @@ static size_t pn532_i2c_scan(const nfc_context *context, nfc_connstring connstri
#define DRIVER_DATA(pnd) ((struct pn532_i2c_data*)(pnd->driver_data)) #define DRIVER_DATA(pnd) ((struct pn532_i2c_data*)(pnd->driver_data))
/*
* Bus free time (in ms) between a STOP condition and START condition. See
* tBuf in the PN532 data sheet, section 12.25: Timing for the I2C interface,
* table 320. I2C timing specification, page 211, rev. 3.2 - 2007-12-07.
*/
#define PN532_BUS_FREE_TIME 5
static struct timespec __transaction_stop;
/**
* @brief Wrapper around i2c_read to ensure proper timing by respecting the
* minimal free bus time between a STOP condition and a START condition.
*
* @note This is not thread safe, but since libnfc is single threaded
* this should be okay.
*
* @param id I2C device
* @param buf pointer on buffer used to store data
* @param len length of the buffer
* @return length (in bytes) of read data, or driver error code (negative value)
*/
static ssize_t pn532_i2c_read(const i2c_device id,
uint8_t *buf, const size_t len)
{
struct timespec transaction_start, bus_free_time = { 0, 0 };
ssize_t ret;
clock_gettime(CLOCK_MONOTONIC, &transaction_start);
bus_free_time.tv_nsec = (PN532_BUS_FREE_TIME * 1000 * 1000) -
(transaction_start.tv_nsec - __transaction_stop.tv_nsec);
nanosleep(&bus_free_time, NULL);
ret = i2c_read(id, buf, len);
clock_gettime(CLOCK_MONOTONIC, &__transaction_stop);
return ret;
}
/**
* @brief Wrapper around i2c_write to ensure proper timing by respecting the
* minimal free bus time between a STOP condition and a START condition.
*
* @note This is not thread safe, but since libnfc is single threaded
* this should be okay.
*
* @param id I2C device
* @param buf pointer on buffer containing data
* @param len length of the buffer
* @return NFC_SUCCESS on success, otherwise driver error code
*/
static ssize_t pn532_i2c_write(const i2c_device id,
const uint8_t *buf, const size_t len)
{
struct timespec transaction_start, bus_free_time = { 0, 0 };
ssize_t ret;
clock_gettime(CLOCK_MONOTONIC, &transaction_start);
bus_free_time.tv_nsec = (PN532_BUS_FREE_TIME * 1000 * 1000) -
(transaction_start.tv_nsec - __transaction_stop.tv_nsec);
nanosleep(&bus_free_time, NULL);
ret = i2c_write(id, buf, len);
clock_gettime(CLOCK_MONOTONIC, &__transaction_stop);
return ret;
}
/** /**
* @brief Scan all available I2C buses to find PN532 devices. * @brief Scan all available I2C buses to find PN532 devices.
* *
@ -308,6 +375,7 @@ static int
pn532_i2c_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout) pn532_i2c_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int timeout)
{ {
int res = 0; int res = 0;
uint8_t retries;
// Discard any existing data ? // Discard any existing data ?
@ -334,15 +402,22 @@ pn532_i2c_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int
break; break;
}; };
uint8_t abtFrame[PN532_BUFFER_LEN] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff" uint8_t abtFrame[PN532_BUFFER_LEN];
size_t szFrame = 0; size_t szFrame = 0;
memcpy(abtFrame, pn53x_preamble_and_start, PN53X_PREAMBLE_AND_START_LEN); // Every packet must start with the preamble and start bytes.
if ((res = pn53x_build_frame(abtFrame, &szFrame, pbtData, szData)) < 0) { if ((res = pn53x_build_frame(abtFrame, &szFrame, pbtData, szData)) < 0) {
pnd->last_error = res; pnd->last_error = res;
return pnd->last_error; return pnd->last_error;
} }
res = i2c_write(DRIVER_DATA(pnd)->dev, abtFrame, szFrame); for (retries = PN532_SEND_RETRIES; retries > 0; retries--) {
res = pn532_i2c_write(DRIVER_DATA(pnd)->dev, abtFrame, szFrame);
if (res >= 0)
break;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Failed to transmit data. Retries left: %d.", retries - 1);
}
if (res < 0) { if (res < 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)"); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)");
@ -400,10 +475,7 @@ pn532_i2c_wait_rdyframe(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLe
} }
do { do {
// Wait a little bit before reading int recCount = pn532_i2c_read(DRIVER_DATA(pnd)->dev, i2cRx, szDataLen + 1);
nanosleep(&rdyDelay, (struct timespec *) NULL);
int recCount = i2c_read(DRIVER_DATA(pnd)->dev, i2cRx, szDataLen + 1);
if (DRIVER_DATA(pnd)->abort_flag) { if (DRIVER_DATA(pnd)->abort_flag) {
// Reset abort flag // Reset abort flag
@ -477,9 +549,7 @@ pn532_i2c_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int
goto error; goto error;
} }
const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff }; if (0 != (memcmp(frameBuf, pn53x_preamble_and_start, PN53X_PREAMBLE_AND_START_LEN))) {
if (0 != (memcmp(frameBuf, pn53x_preamble, 3))) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch"); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch");
pnd->last_error = NFC_EIO; pnd->last_error = NFC_EIO;
goto error; goto error;
@ -572,7 +642,7 @@ error:
int int
pn532_i2c_ack(nfc_device *pnd) pn532_i2c_ack(nfc_device *pnd)
{ {
return i2c_write(DRIVER_DATA(pnd)->dev, pn53x_ack_frame, sizeof(pn53x_ack_frame)); return pn532_i2c_write(DRIVER_DATA(pnd)->dev, pn53x_ack_frame, sizeof(pn53x_ack_frame));
} }
/** /**

View File

@ -433,7 +433,7 @@ pn532_spi_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int
goto error; goto error;
} }
pnd->last_error = spi_send_receive(DRIVER_DATA(pnd)->port, &pn532_spi_cmd_dataread, 1, abtRxBuf , 4, true); pnd->last_error = spi_send_receive(DRIVER_DATA(pnd)->port, &pn532_spi_cmd_dataread, 1, abtRxBuf, 4, true);
if (pnd->last_error < 0) { if (pnd->last_error < 0) {
goto error; goto error;

View File

@ -82,7 +82,7 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const
while ((acPort = acPorts[iDevice++])) { while ((acPort = acPorts[iDevice++])) {
sp = uart_open(acPort); sp = uart_open(acPort);
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Trying to find PN532 device on serial port: %s at %d bauds.", acPort, PN532_UART_DEFAULT_SPEED); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Trying to find PN532 device on serial port: %s at %d baud.", acPort, PN532_UART_DEFAULT_SPEED);
if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) { if ((sp != INVALID_SERIAL_PORT) && (sp != CLAIMED_SERIAL_PORT)) {
// We need to flush input to be sure first reply does not comes from older byte transceive // We need to flush input to be sure first reply does not comes from older byte transceive
@ -136,7 +136,7 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const
CHIP_DATA(pnd)->power_mode = LOWVBAT; CHIP_DATA(pnd)->power_mode = LOWVBAT;
#ifndef WIN32 #ifndef WIN32
// pipe-based abort mecanism // pipe-based abort mechanism
if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) { if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) {
uart_close(DRIVER_DATA(pnd)->port); uart_close(DRIVER_DATA(pnd)->port);
pn53x_data_free(pnd); pn53x_data_free(pnd);
@ -191,7 +191,7 @@ pn532_uart_close(nfc_device *pnd)
uart_close(DRIVER_DATA(pnd)->port); uart_close(DRIVER_DATA(pnd)->port);
#ifndef WIN32 #ifndef WIN32
// Release file descriptors used for abort mecanism // Release file descriptors used for abort mechanism
close(DRIVER_DATA(pnd)->iAbortFds[0]); close(DRIVER_DATA(pnd)->iAbortFds[0]);
close(DRIVER_DATA(pnd)->iAbortFds[1]); close(DRIVER_DATA(pnd)->iAbortFds[1]);
#endif #endif
@ -225,7 +225,7 @@ pn532_uart_open(const nfc_context *context, const nfc_connstring connstring)
serial_port sp; serial_port sp;
nfc_device *pnd = NULL; nfc_device *pnd = NULL;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Attempt to open: %s at %d bauds.", ndd.port, ndd.speed); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Attempt to open: %s at %d baud.", ndd.port, ndd.speed);
sp = uart_open(ndd.port); sp = uart_open(ndd.port);
if (sp == INVALID_SERIAL_PORT) if (sp == INVALID_SERIAL_PORT)
@ -277,7 +277,7 @@ pn532_uart_open(const nfc_context *context, const nfc_connstring connstring)
pnd->driver = &pn532_uart_driver; pnd->driver = &pn532_uart_driver;
#ifndef WIN32 #ifndef WIN32
// pipe-based abort mecanism // pipe-based abort mechanism
if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) { if (pipe(DRIVER_DATA(pnd)->iAbortFds) < 0) {
uart_close(DRIVER_DATA(pnd)->port); uart_close(DRIVER_DATA(pnd)->port);
pn53x_data_free(pnd); pn53x_data_free(pnd);

View File

@ -5,7 +5,7 @@
* Copyright (C) 2009 Roel Verdult * Copyright (C) 2009 Roel Verdult
* Copyright (C) 2009-2013 Romuald Conty * Copyright (C) 2009-2013 Romuald Conty
* Copyright (C) 2010-2012 Romain Tartière * Copyright (C) 2010-2012 Romain Tartière
* Copyright (C) 2010-2013 Philippe Teuwen * Copyright (C) 2010-2017 Philippe Teuwen
* Copyright (C) 2012-2013 Ludovic Rousseau * Copyright (C) 2012-2013 Ludovic Rousseau
* See AUTHORS file for a more comprehensive list of contributors. * See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file: * Additional contributors of this file:
@ -43,7 +43,9 @@ Thanks to d18c7db and Okko for example code
#include <sys/select.h> #include <sys/select.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#ifdef _MSC_VER
#include <sys/types.h>
#endif
#include <nfc/nfc.h> #include <nfc/nfc.h>
#include "nfc-internal.h" #include "nfc-internal.h"
@ -60,6 +62,8 @@ Thanks to d18c7db and Okko for example code
#define DRIVER_DATA(pnd) ((struct pn53x_usb_data*)(pnd->driver_data)) #define DRIVER_DATA(pnd) ((struct pn53x_usb_data*)(pnd->driver_data))
const nfc_modulation_type no_target_support[] = {0};
typedef enum { typedef enum {
UNKNOWN, UNKNOWN,
NXP_PN531, NXP_PN531,
@ -67,6 +71,7 @@ typedef enum {
NXP_PN533, NXP_PN533,
ASK_LOGO, ASK_LOGO,
SCM_SCL3711, SCM_SCL3711,
SCM_SCL3712,
SONY_RCS360 SONY_RCS360
} pn53x_usb_model; } pn53x_usb_model;
@ -78,6 +83,7 @@ struct pn53x_usb_data {
uint32_t uiEndPointOut; uint32_t uiEndPointOut;
uint32_t uiMaxPacketSize; uint32_t uiMaxPacketSize;
volatile bool abort_flag; volatile bool abort_flag;
bool possibly_corrupted_usbdesc;
}; };
// Internal io struct // Internal io struct
@ -121,17 +127,105 @@ struct pn53x_usb_supported_device {
uint16_t product_id; uint16_t product_id;
pn53x_usb_model model; pn53x_usb_model model;
const char *name; const char *name;
/* hardcoded known values for buggy hardware whose configuration vanishes */
uint32_t uiEndPointIn;
uint32_t uiEndPointOut;
uint32_t uiMaxPacketSize;
}; };
const struct pn53x_usb_supported_device pn53x_usb_supported_devices[] = { const struct pn53x_usb_supported_device pn53x_usb_supported_devices[] = {
{ 0x04CC, 0x0531, NXP_PN531, "Philips / PN531" }, { 0x04CC, 0x0531, NXP_PN531, "Philips / PN531", 0x84, 0x04, 0x40 },
{ 0x04CC, 0x2533, NXP_PN533, "NXP / PN533" }, { 0x04CC, 0x2533, NXP_PN533, "NXP / PN533", 0x84, 0x04, 0x40 },
{ 0x04E6, 0x5591, SCM_SCL3711, "SCM Micro / SCL3711-NFC&RW" }, { 0x04E6, 0x5591, SCM_SCL3711, "SCM Micro / SCL3711-NFC&RW", 0x84, 0x04, 0x40 },
{ 0x054c, 0x0193, SONY_PN531, "Sony / PN531" }, { 0x04E6, 0x5594, SCM_SCL3712, "SCM Micro / SCL3712-NFC&RW", 0, 0, 0 }, // to check on real device
{ 0x1FD3, 0x0608, ASK_LOGO, "ASK / LoGO" }, { 0x054c, 0x0193, SONY_PN531, "Sony / PN531", 0x84, 0x04, 0x40 },
{ 0x054C, 0x02E1, SONY_RCS360, "Sony / FeliCa S360 [PaSoRi]" } { 0x1FD3, 0x0608, ASK_LOGO, "ASK / LoGO", 0x84, 0x04, 0x40 },
{ 0x054C, 0x02E1, SONY_RCS360, "Sony / FeliCa S360 [PaSoRi]", 0x84, 0x04, 0x40 }
}; };
// PN533 USB descriptors backup buffers
const uint8_t btXramUsbDesc_scl3711[] = {
0x09, 0x02, 0x20, 0x00, 0x01, 0x01, 0x00, 0x80, 0x32, 0x09, 0x04, 0x00,
0x00, 0x02, 0xff, 0xff, 0xff, 0x00, 0x07, 0x05, 0x04, 0x02, 0x40, 0x00,
0x04, 0x07, 0x05, 0x84, 0x02, 0x40, 0x00, 0x04, 0x1e, 0x03, 0x53, 0x00,
0x43, 0x00, 0x4c, 0x00, 0x33, 0x00, 0x37, 0x00, 0x31, 0x00, 0x31, 0x00,
0x2d, 0x00, 0x4e, 0x00, 0x46, 0x00, 0x43, 0x00, 0x26, 0x00, 0x52, 0x00,
0x57,
};
const uint8_t btXramUsbDesc_nxppn533[] = {
0x09, 0x02, 0x20, 0x00, 0x01, 0x01, 0x00, 0x80, 0x32, 0x09, 0x04, 0x00,
0x00, 0x02, 0xff, 0xff, 0xff, 0x00, 0x07, 0x05, 0x04, 0x02, 0x40, 0x00,
0x04, 0x07, 0x05, 0x84, 0x02, 0x40, 0x00, 0x04, 0x0c, 0x03, 0x50, 0x00,
0x4e, 0x00, 0x35, 0x00, 0x33, 0x00, 0x33, 0x00, 0x04, 0x03, 0x09, 0x04,
0x08, 0x03, 0x4e, 0x00, 0x58, 0x00, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
};
const uint8_t btXramUsbDesc_asklogo[] = {
0x09, 0x02, 0x20, 0x00, 0x01, 0x01, 0x00, 0x80, 0x96, 0x09, 0x04, 0x00,
0x00, 0x02, 0xff, 0xff, 0xff, 0x00, 0x07, 0x05, 0x04, 0x02, 0x40, 0x00,
0x04, 0x07, 0x05, 0x84, 0x02, 0x40, 0x00, 0x04, 0x0a, 0x03, 0x4c, 0x00,
0x6f, 0x00, 0x47, 0x00, 0x4f, 0x00, 0x04, 0x03, 0x09, 0x04, 0x08, 0x03,
0x41, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00,
};
static void pn533_fix_usbdesc(nfc_device *pnd)
{
// PN533 USB descriptors may have been corrupted by large commands/responses
// so they need to be restored before closing usb connection.
// cf PN5331B3HNC270 Release Note
uint32_t szXramUsbDesc = 0;
uint8_t *btXramUsbDesc = NULL;
if (DRIVER_DATA(pnd)->model == NXP_PN533) {
btXramUsbDesc = (uint8_t *)btXramUsbDesc_nxppn533;
szXramUsbDesc = sizeof(btXramUsbDesc_nxppn533);
} else if (DRIVER_DATA(pnd)->model == SCM_SCL3711) {
btXramUsbDesc = (uint8_t *)btXramUsbDesc_scl3711;
szXramUsbDesc = sizeof(btXramUsbDesc_scl3711);
} else if (DRIVER_DATA(pnd)->model == ASK_LOGO) {
btXramUsbDesc = (uint8_t *)btXramUsbDesc_asklogo;
szXramUsbDesc = sizeof(btXramUsbDesc_asklogo);
}
#define MAXSZXRAMUSBDESC 61
if ((szXramUsbDesc == 0) || (MAXSZXRAMUSBDESC > 61))
return;
#if 0
// Debug routine to check if corruption occurred:
// Don't read more regs at once or it will trigger the bug and corrupt what we're busy reading!
uint8_t abtCmdRR[] = { ReadRegister, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
uint8_t nRRreg = ((sizeof(abtCmdRR) - 1) / 2);
uint8_t abtRxRR[1 + nRRreg];
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "%s", "Checking USB descriptors corruption in XRAM");
for (uint8_t i = 0x19, j = 0; i < 0x19 + szXramUsbDesc;) {
for (uint8_t k = 0; k < nRRreg; k++) {
abtCmdRR[(2 * k) + 2] = i++;
}
if (pn53x_transceive(pnd, abtCmdRR, sizeof(abtCmdRR), abtRxRR, sizeof(abtRxRR), -1) < 0) {
return; // void
}
for (int k = 0; (k < nRRreg) && (j < szXramUsbDesc); k++) {
//printf("0x%02x, ", abtRxRR[1 + k]);
if (btXramUsbDesc[j] != abtRxRR[1 + k])
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "XRAM corruption @ addr 0x00%02X: got %02x, expected %02x", 0x0019 + (j - 1), abtRxRR[1 + k], btXramUsbDesc[j]);
j++;
}
}
#endif
// Abuse the overflow bug to restore USB descriptors in one go
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "%s", "Fixing USB descriptors corruption");
uint8_t abtCmdWR[19 + MAXSZXRAMUSBDESC] = { GetFirmwareVersion };
for (uint8_t i = 0; i < szXramUsbDesc; i++) {
abtCmdWR[i + 19] = btXramUsbDesc[i];
}
size_t szCmdWR = sizeof(abtCmdWR);
uint8_t abtRxWR[4];
if (pn53x_transceive(pnd, abtCmdWR, szCmdWR, abtRxWR, sizeof(abtRxWR), -1) < 0) {
return; // void
}
DRIVER_DATA(pnd)->possibly_corrupted_usbdesc = false;
}
static pn53x_usb_model static pn53x_usb_model
pn53x_usb_get_device_model(uint16_t vendor_id, uint16_t product_id) pn53x_usb_get_device_model(uint16_t vendor_id, uint16_t product_id)
{ {
@ -144,6 +238,25 @@ pn53x_usb_get_device_model(uint16_t vendor_id, uint16_t product_id)
return UNKNOWN; return UNKNOWN;
} }
static bool
pn53x_usb_get_end_points_default(struct usb_device *dev, struct pn53x_usb_data *data)
{
for (size_t n = 0; n < sizeof(pn53x_usb_supported_devices) / sizeof(struct pn53x_usb_supported_device); n++) {
if ((dev->descriptor.idVendor == pn53x_usb_supported_devices[n].vendor_id) &&
(dev->descriptor.idProduct == pn53x_usb_supported_devices[n].product_id)) {
if (pn53x_usb_supported_devices[n].uiMaxPacketSize != 0) {
data->uiEndPointIn = pn53x_usb_supported_devices[n].uiEndPointIn;
data->uiEndPointOut = pn53x_usb_supported_devices[n].uiEndPointOut;
data->uiMaxPacketSize = pn53x_usb_supported_devices[n].uiMaxPacketSize;
return true;
}
}
}
return false;
}
int pn53x_usb_ack(nfc_device *pnd); int pn53x_usb_ack(nfc_device *pnd);
// Find transfer endpoints for bulk transfers // Find transfer endpoints for bulk transfers
@ -194,14 +307,20 @@ pn53x_usb_scan(const nfc_context *context, nfc_connstring connstrings[], const s
if ((pn53x_usb_supported_devices[n].vendor_id == dev->descriptor.idVendor) && if ((pn53x_usb_supported_devices[n].vendor_id == dev->descriptor.idVendor) &&
(pn53x_usb_supported_devices[n].product_id == dev->descriptor.idProduct)) { (pn53x_usb_supported_devices[n].product_id == dev->descriptor.idProduct)) {
// Make sure there are 2 endpoints available // Make sure there are 2 endpoints available
// with libusb-win32 we got some null pointers so be robust before looking at endpoints: // libusb-win32 may return a NULL dev->config,
if (dev->config == NULL || dev->config->interface == NULL || dev->config->interface->altsetting == NULL) { // or the descriptors may be corrupted, hence
// Nope, we maybe want the next one, let's try to find another // let us assume we will use hardcoded defaults
continue; // from pn53x_usb_supported_devices if available.
} // otherwise get data from the descriptors.
if (dev->config->interface->altsetting->bNumEndpoints < 2) { if (pn53x_usb_supported_devices[n].uiMaxPacketSize == 0) {
// Nope, we maybe want the next one, let's try to find another if (dev->config->interface == NULL || dev->config->interface->altsetting == NULL) {
continue; // Nope, we maybe want the next one, let's try to find another
continue;
}
if (dev->config->interface->altsetting->bNumEndpoints < 2) {
// Nope, we maybe want the next one, let's try to find another
continue;
}
} }
usb_dev_handle *udev = usb_open(dev); usb_dev_handle *udev = usb_open(dev);
@ -220,7 +339,10 @@ pn53x_usb_scan(const nfc_context *context, nfc_connstring connstrings[], const s
// pn53x_usb_get_usb_device_name (dev, udev, pnddDevices[device_found].acDevice, sizeof (pnddDevices[device_found].acDevice)); // pn53x_usb_get_usb_device_name (dev, udev, pnddDevices[device_found].acDevice, sizeof (pnddDevices[device_found].acDevice));
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "device found: Bus %s Device %s", bus->dirname, dev->filename); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "device found: Bus %s Device %s", bus->dirname, dev->filename);
usb_close(udev); usb_close(udev);
snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", PN53X_USB_DRIVER_NAME, bus->dirname, dev->filename); if (snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", PN53X_USB_DRIVER_NAME, bus->dirname, dev->filename) >= (int)sizeof(nfc_connstring)) {
// truncation occurred, skipping that one
continue;
}
device_found++; device_found++;
// Test if we reach the maximum "wanted" devices // Test if we reach the maximum "wanted" devices
if (device_found == connstrings_len) { if (device_found == connstrings_len) {
@ -282,6 +404,7 @@ pn53x_usb_open(const nfc_context *context, const nfc_connstring connstring)
.pudh = NULL, .pudh = NULL,
.uiEndPointIn = 0, .uiEndPointIn = 0,
.uiEndPointOut = 0, .uiEndPointOut = 0,
.possibly_corrupted_usbdesc = false,
}; };
struct usb_bus *bus; struct usb_bus *bus;
struct usb_device *dev; struct usb_device *dev;
@ -303,8 +426,16 @@ pn53x_usb_open(const nfc_context *context, const nfc_connstring connstring)
// Open the USB device // Open the USB device
if ((data.pudh = usb_open(dev)) == NULL) if ((data.pudh = usb_open(dev)) == NULL)
continue; continue;
// Retrieve end points
pn53x_usb_get_end_points(dev, &data); //To retrieve real USB endpoints configuration:
//pn53x_usb_get_end_points(dev, &data);
//printf("DEBUG ENDPOINTS In:0x%x Out:0x%x Size:0x%x\n", data.uiEndPointIn, data.uiEndPointOut, data.uiMaxPacketSize);
// Retrieve end points, using hardcoded defaults if available
// or using the descriptors otherwise.
if (pn53x_usb_get_end_points_default(dev, &data) == false) {
pn53x_usb_get_end_points(dev, &data);
}
// Set configuration // Set configuration
int res = usb_set_configuration(data.pudh, 1); int res = usb_set_configuration(data.pudh, 1);
if (res < 0) { if (res < 0) {
@ -347,11 +478,13 @@ pn53x_usb_open(const nfc_context *context, const nfc_connstring connstring)
} }
switch (DRIVER_DATA(pnd)->model) { switch (DRIVER_DATA(pnd)->model) {
// empirical tuning // empirical tuning
case ASK_LOGO: case ASK_LOGO:
CHIP_DATA(pnd)->timer_correction = 50; CHIP_DATA(pnd)->timer_correction = 50;
CHIP_DATA(pnd)->progressive_field = true;
break; break;
case SCM_SCL3711: case SCM_SCL3711:
case SCM_SCL3712:
case NXP_PN533: case NXP_PN533:
CHIP_DATA(pnd)->timer_correction = 46; CHIP_DATA(pnd)->timer_correction = 46;
break; break;
@ -405,6 +538,9 @@ pn53x_usb_close(nfc_device *pnd)
pn53x_write_register(pnd, PN53X_SFR_P3, 0xFF, _BV(P30) | _BV(P31) | _BV(P32) | _BV(P33) | _BV(P35)); pn53x_write_register(pnd, PN53X_SFR_P3, 0xFF, _BV(P30) | _BV(P31) | _BV(P32) | _BV(P33) | _BV(P35));
} }
if (DRIVER_DATA(pnd)->possibly_corrupted_usbdesc)
pn533_fix_usbdesc(pnd);
pn53x_idle(pnd); pn53x_idle(pnd);
int res; int res;
@ -433,6 +569,7 @@ pn53x_usb_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, con
return pnd->last_error; return pnd->last_error;
} }
DRIVER_DATA(pnd)->possibly_corrupted_usbdesc |= szData > 17;
if ((res = pn53x_usb_bulk_write(DRIVER_DATA(pnd), abtFrame, szFrame, timeout)) < 0) { if ((res = pn53x_usb_bulk_write(DRIVER_DATA(pnd), abtFrame, szFrame, timeout)) < 0) {
pnd->last_error = res; pnd->last_error = res;
return pnd->last_error; return pnd->last_error;
@ -452,8 +589,8 @@ pn53x_usb_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, con
// For some reasons (eg. send another command while a previous one is // For some reasons (eg. send another command while a previous one is
// running), the PN533 sometimes directly replies the response packet // running), the PN533 sometimes directly replies the response packet
// instead of ACK frame, so we send a NACK frame to force PN533 to resend // instead of ACK frame, so we send a NACK frame to force PN533 to resend
// response packet. With this hack, the nextly executed function (ie. // response packet. With this hack, the next executed function (ie.
// pn53x_usb_receive()) will be able to retreive the correct response // pn53x_usb_receive()) will be able to retrieve the correct response
// packet. // packet.
// FIXME Sony reader is also affected by this bug but NACK is not supported // FIXME Sony reader is also affected by this bug but NACK is not supported
if ((res = pn53x_usb_bulk_write(DRIVER_DATA(pnd), (uint8_t *)pn53x_nack_frame, sizeof(pn53x_nack_frame), timeout)) < 0) { if ((res = pn53x_usb_bulk_write(DRIVER_DATA(pnd), (uint8_t *)pn53x_nack_frame, sizeof(pn53x_nack_frame), timeout)) < 0) {
@ -463,7 +600,6 @@ pn53x_usb_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, con
return pnd->last_error; return pnd->last_error;
} }
} }
return NFC_SUCCESS; return NFC_SUCCESS;
} }
@ -487,7 +623,7 @@ read:
if (timeout == USB_INFINITE_TIMEOUT) { if (timeout == USB_INFINITE_TIMEOUT) {
usb_timeout = USB_TIMEOUT_PER_PASS; usb_timeout = USB_TIMEOUT_PER_PASS;
} else { } else {
// A user-provided timeout is set, we have to cut it in multiple chunk to be able to keep an nfc_abort_command() mecanism // A user-provided timeout is set, we have to cut it in multiple chunk to be able to keep an nfc_abort_command() mechanism
remaining_time -= USB_TIMEOUT_PER_PASS; remaining_time -= USB_TIMEOUT_PER_PASS;
if (remaining_time <= 0) { if (remaining_time <= 0) {
pnd->last_error = NFC_ETIMEOUT; pnd->last_error = NFC_ETIMEOUT;
@ -601,6 +737,7 @@ read:
} }
// The PN53x command is done and we successfully received the reply // The PN53x command is done and we successfully received the reply
pnd->last_error = 0; pnd->last_error = 0;
DRIVER_DATA(pnd)->possibly_corrupted_usbdesc |= len > 16;
return len; return len;
} }
@ -664,6 +801,8 @@ pn53x_usb_init(nfc_device *pnd)
/* ie. Switch LED1 on and turn off progressive field */ /* ie. Switch LED1 on and turn off progressive field */
pn53x_write_register(pnd, PN53X_SFR_P3, 0xFF, _BV(P30) | _BV(P31) | _BV(P33) | _BV(P35)); pn53x_write_register(pnd, PN53X_SFR_P3, 0xFF, _BV(P30) | _BV(P31) | _BV(P33) | _BV(P35));
} }
if (DRIVER_DATA(pnd)->possibly_corrupted_usbdesc)
pn533_fix_usbdesc(pnd);
return NFC_SUCCESS; return NFC_SUCCESS;
} }
@ -680,7 +819,7 @@ pn53x_usb_set_property_bool(nfc_device *pnd, const nfc_property property, const
if (NP_ACTIVATE_FIELD == property) { if (NP_ACTIVATE_FIELD == property) {
/* Switch on/off LED2 and Progressive Field GPIO according to ACTIVATE_FIELD option */ /* Switch on/off LED2 and Progressive Field GPIO according to ACTIVATE_FIELD option */
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Switch progressive field %s", bEnable ? "On" : "Off"); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Switch progressive field %s", bEnable ? "On" : "Off");
if ((res = pn53x_write_register(pnd, PN53X_SFR_P3, _BV(P31) | _BV(P34), bEnable ? _BV(P34) : _BV(P31))) < 0) if (pn53x_write_register(pnd, PN53X_SFR_P3, _BV(P31) | _BV(P34), bEnable ? _BV(P34) : _BV(P31)) < 0)
return NFC_ECHIP; return NFC_ECHIP;
} }
break; break;
@ -691,6 +830,13 @@ pn53x_usb_set_property_bool(nfc_device *pnd, const nfc_property property, const
return res; return res;
} }
break; break;
case SCM_SCL3712:
if (NP_ACTIVATE_FIELD == property) {
// Switch on/off LED according to ACTIVATE_FIELD option
if ((res = pn53x_write_register(pnd, PN53X_SFR_P3, _BV(P32), bEnable ? 0 : _BV(P32))) < 0)
return res;
}
break;
case NXP_PN531: case NXP_PN531:
case NXP_PN533: case NXP_PN533:
case SONY_PN531: case SONY_PN531:
@ -709,6 +855,16 @@ pn53x_usb_abort_command(nfc_device *pnd)
return NFC_SUCCESS; return NFC_SUCCESS;
} }
static int
pn53x_usb_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt)
{
if ((DRIVER_DATA(pnd)->model != ASK_LOGO) || (mode != N_TARGET))
return pn53x_get_supported_modulation(pnd, mode, supported_mt);
else // ASK_LOGO has no N_TARGET support
*supported_mt = no_target_support;
return NFC_SUCCESS;
}
const struct pn53x_io pn53x_usb_io = { const struct pn53x_io pn53x_usb_io = {
.send = pn53x_usb_send, .send = pn53x_usb_send,
.receive = pn53x_usb_receive, .receive = pn53x_usb_receive,
@ -742,7 +898,7 @@ const struct nfc_driver pn53x_usb_driver = {
.device_set_property_bool = pn53x_usb_set_property_bool, .device_set_property_bool = pn53x_usb_set_property_bool,
.device_set_property_int = pn53x_set_property_int, .device_set_property_int = pn53x_set_property_int,
.get_supported_modulation = pn53x_get_supported_modulation, .get_supported_modulation = pn53x_usb_get_supported_modulation,
.get_supported_baud_rate = pn53x_get_supported_baud_rate, .get_supported_baud_rate = pn53x_get_supported_baud_rate,
.device_get_information_about = pn53x_get_information_about, .device_get_information_about = pn53x_get_information_about,

589
libnfc/drivers/pn71xx.c Normal file
View File

@ -0,0 +1,589 @@
/**
* @file pn71xx.h
* @brief Driver for PN71XX using libnfc-nci library
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif // HAVE_CONFIG_H
#include "pn71xx.h"
#include <stdio.h>
#include <inttypes.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <nfc/nfc.h>
#include "drivers.h"
#include "nfc-internal.h"
#include "linux_nfc_api.h"
#define PN71XX_DRIVER_NAME "pn71xx"
#define LOG_CATEGORY "libnfc.driver.pn71xx"
#define LOG_GROUP NFC_LOG_GROUP_DRIVER
const nfc_modulation_type pn71xx_supported_modulation_as_target[] = {NMT_ISO14443A, NMT_FELICA, NMT_ISO14443B, NMT_ISO14443BI, NMT_ISO14443B2SR, NMT_ISO14443B2CT, NMT_JEWEL, NMT_DEP, 0};
const nfc_modulation_type pn71xx_supported_modulation_as_initiator[] = {NMT_ISO14443A, NMT_FELICA, NMT_ISO14443B, NMT_ISO14443BI, NMT_ISO14443B2SR, NMT_ISO14443B2CT, NMT_JEWEL, NMT_DEP, 0};
const nfc_baud_rate pn71xx_iso14443a_supported_baud_rates[] = { NBR_847, NBR_424, NBR_212, NBR_106, 0 };
const nfc_baud_rate pn71xx_felica_supported_baud_rates[] = { NBR_424, NBR_212, 0 };
const nfc_baud_rate pn71xx_dep_supported_baud_rates[] = { NBR_424, NBR_212, NBR_106, 0 };
const nfc_baud_rate pn71xx_jewel_supported_baud_rates[] = { NBR_847, NBR_424, NBR_212, NBR_106, 0 };
const nfc_baud_rate pn71xx_iso14443b_supported_baud_rates[] = { NBR_847, NBR_424, NBR_212, NBR_106, 0 };
static nfcTagCallback_t TagCB;
static nfc_tag_info_t *TagInfo = NULL;
static void onTagArrival(nfc_tag_info_t *pTagInfo);
static void onTagDeparture(void);
/** ------------------------------------------------------------------------ */
/** ------------------------------------------------------------------------ */
/**
* @brief Initialize libnfc_nci library to verify presence of PN71xx device.
*
* @param context NFC context.
* @param connstrings array of 'nfc_connstring' buffer (allocated by caller). It is used to store the
* connection info strings of devices found.
* @param connstrings_len length of the connstrings array.
* @return number of devices found.
*/
static size_t
pn71xx_scan(const nfc_context *context, nfc_connstring connstrings[], const size_t connstrings_len)
{
size_t device_found = 0;
if ((context == NULL) || (connstrings_len == 0)) return 0;
if (nfcManager_doInitialize() == 0) {
nfc_connstring connstring = "pn71xx";
memcpy(connstrings[device_found++], connstring, sizeof(nfc_connstring));
}
return device_found;
}
/**
* @brief Close connection to PN71xx by stopping the discovery loop and deinitializing the libnfc_nci library.
*
* @param pnd pointer on the device to close.
*/
static void
pn71xx_close(nfc_device *pnd)
{
nfcManager_disableDiscovery();
nfcManager_deregisterTagCallback();
nfcManager_doDeinitialize();
nfc_device_free(pnd);
pnd = NULL;
}
/**
* @brief Open a connection to PN71xx, starting the discovery loop for tag detection.
*
* @param context NFC context.
* @param connstring connection info to the device
* @return pointer to the device, or NULL in case of error.
*/
static nfc_device *
pn71xx_open(const nfc_context *context, const nfc_connstring connstring)
{
nfc_device *pnd;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "open: %s", connstring);
pnd = nfc_device_new(context, connstring);
if (!pnd) {
perror("malloc");
return NULL;
}
pnd->driver = &pn71xx_driver;
strcpy(pnd->name, "pn71xx-device");
strcpy(pnd->connstring, connstring);
TagCB.onTagArrival = onTagArrival;
TagCB.onTagDeparture = onTagDeparture;
nfcManager_registerTagCallback(&TagCB);
nfcManager_enableDiscovery(DEFAULT_NFA_TECH_MASK, 1, 0, 0);
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "wait 1 seconds for polling");
sleep(1);
return pnd;
}
/** ------------------------------------------------------------------------ */
/** ------------------------------------------------------------------------ */
static bool IsTechnology(nfc_tag_info_t *TagInfo, nfc_modulation_type nmt)
{
switch (nmt) {
case NMT_ISO14443A:
if (TagInfo->technology == TARGET_TYPE_ISO14443_4
|| TagInfo->technology == TARGET_TYPE_ISO14443_3A
|| TagInfo->technology == TARGET_TYPE_MIFARE_CLASSIC
|| TagInfo->technology == TARGET_TYPE_MIFARE_UL)
return true;
break;
case NMT_ISO14443B:
case NMT_ISO14443BI:
case NMT_ISO14443B2SR:
case NMT_ISO14443B2CT:
if (TagInfo->technology == TARGET_TYPE_ISO14443_3B)
return true;
break;
case NMT_FELICA:
if (TagInfo->technology == TARGET_TYPE_FELICA)
return true;
break;
case NMT_JEWEL:
if (TagInfo->technology == TARGET_TYPE_ISO14443_3A
&& TagInfo->protocol == NFA_PROTOCOL_T1T)
return true;
break;
default:
return false;
}
return false;
}
static void BufferPrintBytes(char *buffer, unsigned int buflen, const uint8_t *data, unsigned int datalen)
{
int cx = 0;
for (unsigned int i = 0x00; i < datalen; i++) {
cx += snprintf(buffer + cx, buflen - cx, "%02X ", data[i]);
}
}
static void PrintTagInfo(nfc_tag_info_t *TagInfo)
{
switch (TagInfo->technology) {
case TARGET_TYPE_UNKNOWN: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type Unknown'");
}
break;
case TARGET_TYPE_ISO14443_3A: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 3A'");
}
break;
case TARGET_TYPE_ISO14443_3B: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 3B'");
}
break;
case TARGET_TYPE_ISO14443_4: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type 4A'");
}
break;
case TARGET_TYPE_FELICA: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type F'");
}
break;
case TARGET_TYPE_ISO15693: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type V'");
}
break;
case TARGET_TYPE_NDEF: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type NDEF'");
}
break;
case TARGET_TYPE_NDEF_FORMATABLE: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type Formatable'");
}
break;
case TARGET_TYPE_MIFARE_CLASSIC: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A - Mifare Classic'");
}
break;
case TARGET_TYPE_MIFARE_UL: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A - Mifare Ul'");
}
break;
case TARGET_TYPE_KOVIO_BARCODE: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A - Kovio Barcode'");
}
break;
case TARGET_TYPE_ISO14443_3A_3B: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type A/B'");
}
break;
default: {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "'Type %d (Unknown or not supported)'\n", TagInfo->technology);
}
break;
}
/*32 is max UID len (Kovio tags)*/
if ((0x00 != TagInfo->uid_length) && (32 >= TagInfo->uid_length)) {
char buffer [100];
int cx = 0;
if (4 == TagInfo->uid_length || 7 == TagInfo->uid_length || 10 == TagInfo->uid_length) {
cx += snprintf(buffer + cx, sizeof(buffer) - cx, "NFCID1 : \t'");
} else if (8 == TagInfo->uid_length) {
cx += snprintf(buffer + cx, sizeof(buffer) - cx, "NFCID2 : \t'");
} else {
cx += snprintf(buffer + cx, sizeof(buffer) - cx, "UID : \t'");
}
BufferPrintBytes(buffer + cx, sizeof(buffer) - cx, (unsigned char *) TagInfo->uid, TagInfo->uid_length);
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s'", buffer);
}
}
/** ------------------------------------------------------------------------ */
/** ------------------------------------------------------------------------ */
static void onTagArrival(nfc_tag_info_t *pTagInfo)
{
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "tag found");
TagInfo = malloc(sizeof(nfc_tag_info_t));
memcpy(TagInfo, pTagInfo, sizeof(nfc_tag_info_t));
PrintTagInfo(TagInfo);
}
static void onTagDeparture(void)
{
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "tag lost");
free(TagInfo);
TagInfo = NULL;
}
static int
pn71xx_initiator_init(struct nfc_device *pnd)
{
if (pnd == NULL) return NFC_EIO;
return NFC_SUCCESS;
}
static int
pn71xx_initiator_select_passive_target(struct nfc_device *pnd,
const nfc_modulation nm,
const uint8_t *pbtInitData, const size_t szInitData,
nfc_target *pnt)
{
if (pnd == NULL) return NFC_EIO;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "select_passive_target");
if (TagInfo) {
nfc_target nttmp;
memset(&nttmp, 0x00, sizeof(nfc_target));
nttmp.nm = nm;
void *uidPtr = NULL;
unsigned int maxLen = 0;
switch (nm.nmt) {
case NMT_ISO14443A:
if (IsTechnology(TagInfo, nm.nmt)) {
maxLen = 10;
uidPtr = nttmp.nti.nai.abtUid;
if (TagInfo->technology == TARGET_TYPE_MIFARE_CLASSIC) {
nttmp.nti.nai.btSak = 0x08;
} else {
// make hardcoded desfire for freefare lib check
nttmp.nti.nai.btSak = 0x20;
nttmp.nti.nai.szAtsLen = 5;
memcpy(nttmp.nti.nai.abtAts, "\x75\x77\x81\x02", 4);
}
}
break;
case NMT_ISO14443B:
if (IsTechnology(TagInfo, nm.nmt)) {
maxLen = 4;
uidPtr = nttmp.nti.nbi.abtPupi;
}
break;
case NMT_ISO14443BI:
if (IsTechnology(TagInfo, nm.nmt)) {
maxLen = 4;
uidPtr = nttmp.nti.nii.abtDIV;
}
break;
case NMT_ISO14443B2SR:
if (IsTechnology(TagInfo, nm.nmt)) {
maxLen = 8;
uidPtr = nttmp.nti.nsi.abtUID;
}
break;
case NMT_ISO14443B2CT:
if (IsTechnology(TagInfo, nm.nmt)) {
maxLen = 4;
uidPtr = nttmp.nti.nci.abtUID;
}
break;
case NMT_FELICA:
if (IsTechnology(TagInfo, nm.nmt)) {
maxLen = 8;
uidPtr = nttmp.nti.nfi.abtId;
}
break;
case NMT_JEWEL:
if (IsTechnology(TagInfo, nm.nmt)) {
maxLen = 4;
uidPtr = nttmp.nti.nji.btId;
}
break;
default:
return 0;
}
if (uidPtr && TagInfo->uid_length) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target found");
int len = TagInfo->uid_length > maxLen ? maxLen : TagInfo->uid_length;
memcpy(uidPtr, TagInfo->uid, len);
if (nm.nmt == NMT_ISO14443A)
nttmp.nti.nai.szUidLen = len;
// Is a tag info struct available
if (pnt) {
memcpy(pnt, &nttmp, sizeof(nfc_target));
}
return 1;
}
}
return 0;
}
static int
pn71xx_initiator_deselect_target(struct nfc_device *pnd)
{
if (pnd == NULL) return NFC_EIO;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "deselect_passive_target");
return NFC_SUCCESS;
}
static int
pn71xx_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx, uint8_t *pbtRx,
const size_t szRx, int timeout)
{
if (pnd == NULL) return NFC_EIO;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "transceive_bytes timeout=%d", timeout);
if (!TagInfo) return NFC_EINVARG;
char buffer[500];
BufferPrintBytes(buffer, sizeof(buffer), pbtTx, szTx);
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "===> %s", buffer);
int received = nfcTag_transceive(TagInfo->handle, (uint8_t *) pbtTx, szTx, pbtRx, szRx, 500);
if (received <= 0)
return NFC_EIO;
BufferPrintBytes(buffer, sizeof(buffer), pbtRx, received);
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "<=== %s", buffer);
return received;
}
static int
pn71xx_initiator_poll_target(struct nfc_device *pnd,
const nfc_modulation *pnmModulations, const size_t szModulations,
const uint8_t uiPollNr, const uint8_t uiPeriod,
nfc_target *pnt)
{
static int periodFactor = 150000;
int period = uiPeriod * periodFactor;
if (pnd == NULL) return 0;
for (int j = 0; j < uiPollNr; j++) {
for (unsigned int i = 0; i < szModulations; i++) {
const nfc_modulation nm = pnmModulations[i];
nfc_target nt;
int res = pn71xx_initiator_select_passive_target(pnd, nm, 0, 0, &nt);
if (res > 0 && pnt) {
memcpy(pnt, &nt, sizeof(nfc_target));
return res;
}
}
usleep(period);
}
return 0;
}
static int
pn71xx_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt)
{
if ((pnd == NULL) || (pnt == NULL)) return 1;
return !TagInfo;
}
/** ------------------------------------------------------------------------ */
/** ------------------------------------------------------------------------ */
static int
pn71xx_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt)
{
if (pnd == NULL) return NFC_EIO;
switch (mode) {
case N_TARGET:
*supported_mt = (nfc_modulation_type *)pn71xx_supported_modulation_as_target;
break;
case N_INITIATOR:
*supported_mt = (nfc_modulation_type *)pn71xx_supported_modulation_as_initiator;
break;
default:
return NFC_EINVARG;
}
return NFC_SUCCESS;
}
static int
pn71xx_get_supported_baud_rate(nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br)
{
if (pnd == NULL) return NFC_EIO;
if (mode) {}
switch (nmt) {
case NMT_FELICA:
*supported_br = (nfc_baud_rate *)pn71xx_felica_supported_baud_rates;
break;
case NMT_ISO14443A:
*supported_br = (nfc_baud_rate *)pn71xx_iso14443a_supported_baud_rates;
break;
case NMT_ISO14443B:
case NMT_ISO14443BI:
case NMT_ISO14443B2SR:
case NMT_ISO14443B2CT:
*supported_br = (nfc_baud_rate *)pn71xx_iso14443b_supported_baud_rates;
break;
case NMT_JEWEL:
*supported_br = (nfc_baud_rate *)pn71xx_jewel_supported_baud_rates;
break;
case NMT_DEP:
*supported_br = (nfc_baud_rate *)pn71xx_dep_supported_baud_rates;
break;
default:
return NFC_EINVARG;
}
return NFC_SUCCESS;
}
/** ------------------------------------------------------------------------ */
/** ------------------------------------------------------------------------ */
static int
pn71xx_set_property_bool(struct nfc_device *pnd, const nfc_property property, const bool bEnable)
{
if (pnd == NULL) return NFC_EIO;
return NFC_SUCCESS;
}
static int
pn71xx_set_property_int(struct nfc_device *pnd, const nfc_property property, const int value)
{
if (pnd == NULL) return NFC_EIO;
return NFC_SUCCESS;
}
static int
pn71xx_get_information_about(nfc_device *pnd, char **pbuf)
{
static const char *info = "PN71XX nfc driver using libnfc-nci userspace library";
size_t buflen = strlen(info) + 1;
if (pnd == NULL) return NFC_EIO;
*pbuf = malloc(buflen);
memcpy(*pbuf, info, buflen);
return buflen;
}
/**
* @brief Abort any pending operation
*
* @param pnd pointer on the NFC device.
* @return NFC_SUCCESS
*/
static int
pn71xx_abort_command(nfc_device *pnd)
{
if (pnd == NULL) return NFC_EIO;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "abort_command");
return NFC_SUCCESS;
}
static int
pn71xx_idle(struct nfc_device *pnd)
{
if (pnd == NULL) return NFC_EIO;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "idle");
return NFC_SUCCESS;
}
static int
pn71xx_PowerDown(struct nfc_device *pnd)
{
if (pnd == NULL) return NFC_EIO;
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "PowerDown");
return NFC_SUCCESS;
}
/** ------------------------------------------------------------------------ */
/** ------------------------------------------------------------------------ */
const struct nfc_driver pn71xx_driver = {
.name = PN71XX_DRIVER_NAME,
.scan_type = NOT_INTRUSIVE,
.scan = pn71xx_scan,
.open = pn71xx_open,
.close = pn71xx_close,
.strerror = NULL,
.initiator_init = pn71xx_initiator_init,
.initiator_init_secure_element = NULL,
.initiator_select_passive_target = pn71xx_initiator_select_passive_target,
.initiator_poll_target = pn71xx_initiator_poll_target,
.initiator_select_dep_target = NULL,
.initiator_deselect_target = pn71xx_initiator_deselect_target,
.initiator_transceive_bytes = pn71xx_initiator_transceive_bytes,
.initiator_transceive_bits = NULL,
.initiator_transceive_bytes_timed = NULL,
.initiator_transceive_bits_timed = NULL,
.initiator_target_is_present = pn71xx_initiator_target_is_present,
.target_init = NULL,
.target_send_bytes = NULL,
.target_receive_bytes = NULL,
.target_send_bits = NULL,
.target_receive_bits = NULL,
.device_set_property_bool = pn71xx_set_property_bool,
.device_set_property_int = pn71xx_set_property_int,
.get_supported_modulation = pn71xx_get_supported_modulation,
.get_supported_baud_rate = pn71xx_get_supported_baud_rate,
.device_get_information_about = pn71xx_get_information_about,
.abort_command = pn71xx_abort_command,
.idle = pn71xx_idle,
.powerdown = pn71xx_PowerDown,
};

14
libnfc/drivers/pn71xx.h Normal file
View File

@ -0,0 +1,14 @@
/**
* @file pn71xx.h
* @brief Driver for PN71XX using libnfc-nci library
*/
#ifndef __NFC_DRIVER_PN71XX_H__
#define __NFC_DRIVER_PN71XX_H__
#include <nfc/nfc-types.h>
/* Reference to the driver structure */
extern const struct nfc_driver pn71xx_driver;
#endif // ! __NFC_DRIVER_7120_H__

View File

@ -47,10 +47,10 @@
void void
iso14443a_crc(uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc) iso14443a_crc(uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc)
{ {
uint8_t bt;
uint32_t wCrc = 0x6363; uint32_t wCrc = 0x6363;
do { do {
uint8_t bt;
bt = *pbtData++; bt = *pbtData++;
bt = (bt ^ (uint8_t)(wCrc & 0x00FF)); bt = (bt ^ (uint8_t)(wCrc & 0x00FF));
bt = (bt ^ (bt << 4)); bt = (bt ^ (bt << 4));
@ -78,10 +78,10 @@ iso14443a_crc_append(uint8_t *pbtData, size_t szLen)
void void
iso14443b_crc(uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc) iso14443b_crc(uint8_t *pbtData, size_t szLen, uint8_t *pbtCrc)
{ {
uint8_t bt;
uint32_t wCrc = 0xFFFF; uint32_t wCrc = 0xFFFF;
do { do {
uint8_t bt;
bt = *pbtData++; bt = *pbtData++;
bt = (bt ^ (uint8_t)(wCrc & 0x00FF)); bt = (bt ^ (uint8_t)(wCrc & 0x00FF));
bt = (bt ^ (bt << 4)); bt = (bt ^ (bt << 4));

View File

@ -39,6 +39,5 @@
uint8_t mirror(uint8_t bt); uint8_t mirror(uint8_t bt);
uint32_t mirror32(uint32_t ui32Bits); uint32_t mirror32(uint32_t ui32Bits);
uint64_t mirror64(uint64_t ui64Bits); uint64_t mirror64(uint64_t ui64Bits);
void mirror_uint8_ts(uint8_t *pbts, size_t szLen);
#endif // _LIBNFC_MIRROR_SUBR_H_ #endif // _LIBNFC_MIRROR_SUBR_H_

View File

@ -9,6 +9,7 @@
* Copyright (C) 2012-2013 Ludovic Rousseau * Copyright (C) 2012-2013 Ludovic Rousseau
* See AUTHORS file for a more comprehensive list of contributors. * See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file: * Additional contributors of this file:
* Copyright (C) 2020 Adam Laurie
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the * under the terms of the GNU Lesser General Public License as published by the
@ -169,38 +170,27 @@ void
prepare_initiator_data(const nfc_modulation nm, uint8_t **ppbtInitiatorData, size_t *pszInitiatorData) prepare_initiator_data(const nfc_modulation nm, uint8_t **ppbtInitiatorData, size_t *pszInitiatorData)
{ {
switch (nm.nmt) { switch (nm.nmt) {
case NMT_ISO14443B: { case NMT_ISO14443B:
// Application Family Identifier (AFI) must equals 0x00 in order to wakeup all ISO14443-B PICCs (see ISO/IEC 14443-3) // Application Family Identifier (AFI) must equals 0x00 in order to wakeup all ISO14443-B PICCs (see ISO/IEC 14443-3)
*ppbtInitiatorData = (uint8_t *) "\x00"; *ppbtInitiatorData = (uint8_t *) "\x00";
*pszInitiatorData = 1; *pszInitiatorData = 1;
} break;
break; case NMT_ISO14443BI:
case NMT_ISO14443BI: {
// APGEN // APGEN
*ppbtInitiatorData = (uint8_t *) "\x01\x0b\x3f\x80"; *ppbtInitiatorData = (uint8_t *) "\x01\x0b\x3f\x80";
*pszInitiatorData = 4; *pszInitiatorData = 4;
} break;
break; case NMT_FELICA:
case NMT_ISO14443B2SR: {
// Get_UID
*ppbtInitiatorData = (uint8_t *) "\x0b";
*pszInitiatorData = 1;
}
break;
case NMT_ISO14443B2CT: {
// SELECT-ALL
*ppbtInitiatorData = (uint8_t *) "\x9F\xFF\xFF";
*pszInitiatorData = 3;
}
break;
case NMT_FELICA: {
// polling payload must be present (see ISO/IEC 18092 11.2.2.5) // polling payload must be present (see ISO/IEC 18092 11.2.2.5)
*ppbtInitiatorData = (uint8_t *) "\x00\xff\xff\x01\x00"; *ppbtInitiatorData = (uint8_t *) "\x00\xff\xff\x01\x00";
*pszInitiatorData = 5; *pszInitiatorData = 5;
} break;
break;
case NMT_ISO14443A: case NMT_ISO14443A:
case NMT_ISO14443B2CT:
case NMT_ISO14443B2SR:
case NMT_ISO14443BICLASS:
case NMT_JEWEL: case NMT_JEWEL:
case NMT_BARCODE:
case NMT_DEP: case NMT_DEP:
*ppbtInitiatorData = NULL; *ppbtInitiatorData = NULL;
*pszInitiatorData = 0; *pszInitiatorData = 0;
@ -242,7 +232,6 @@ connstring_decode(const nfc_connstring connstring, const char *driver_name, cons
int res = sscanf(connstring, format, param0, param1, param2); int res = sscanf(connstring, format, param0, param1, param2);
if (res < 1 || ((0 != strcmp(param0, driver_name)) && if (res < 1 || ((0 != strcmp(param0, driver_name)) &&
(bus_name != NULL) &&
(0 != strcmp(param0, bus_name)))) { (0 != strcmp(param0, bus_name)))) {
// Driver name does not match. // Driver name does not match.
res = 0; res = 0;

View File

@ -34,7 +34,9 @@
#include <stdbool.h> #include <stdbool.h>
#include <err.h> #include <err.h>
#if !defined(_MSC_VER)
# include <sys/time.h> # include <sys/time.h>
#endif
#include "nfc/nfc.h" #include "nfc/nfc.h"
@ -148,7 +150,7 @@ struct nfc_driver {
int (*device_set_property_bool)(struct nfc_device *pnd, const nfc_property property, const bool bEnable); int (*device_set_property_bool)(struct nfc_device *pnd, const nfc_property property, const bool bEnable);
int (*device_set_property_int)(struct nfc_device *pnd, const nfc_property property, const int value); int (*device_set_property_int)(struct nfc_device *pnd, const nfc_property property, const int value);
int (*get_supported_modulation)(struct nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt); int (*get_supported_modulation)(struct nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type **const supported_mt);
int (*get_supported_baud_rate)(struct nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br); int (*get_supported_baud_rate)(struct nfc_device *pnd, const nfc_mode mode, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br);
int (*device_get_information_about)(struct nfc_device *pnd, char **buf); int (*device_get_information_about)(struct nfc_device *pnd, char **buf);
int (*abort_command)(struct nfc_device *pnd); int (*abort_command)(struct nfc_device *pnd);

View File

@ -9,6 +9,7 @@
* Copyright (C) 2012-2013 Ludovic Rousseau * Copyright (C) 2012-2013 Ludovic Rousseau
* See AUTHORS file for a more comprehensive list of contributors. * See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file: * Additional contributors of this file:
* Copyright (C) 2020 Adam Laurie
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the * under the terms of the GNU Lesser General Public License as published by the
@ -79,6 +80,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include <assert.h>
#include <nfc/nfc.h> #include <nfc/nfc.h>
@ -86,6 +88,10 @@
#include "target-subr.h" #include "target-subr.h"
#include "drivers.h" #include "drivers.h"
#if defined (DRIVER_PCSC_ENABLED)
# include "drivers/pcsc.h"
#endif /* DRIVER_PCSC_ENABLED */
#if defined (DRIVER_ACR122_PCSC_ENABLED) #if defined (DRIVER_ACR122_PCSC_ENABLED)
# include "drivers/acr122_pcsc.h" # include "drivers/acr122_pcsc.h"
#endif /* DRIVER_ACR122_PCSC_ENABLED */ #endif /* DRIVER_ACR122_PCSC_ENABLED */
@ -118,6 +124,10 @@
# include "drivers/pn532_i2c.h" # include "drivers/pn532_i2c.h"
#endif /* DRIVER_PN532_I2C_ENABLED */ #endif /* DRIVER_PN532_I2C_ENABLED */
#if defined (DRIVER_PN71XX_ENABLED)
# include "drivers/pn71xx.h"
#endif /* DRIVER_PN71XX_ENABLED */
#define LOG_CATEGORY "libnfc.general" #define LOG_CATEGORY "libnfc.general"
#define LOG_GROUP NFC_LOG_GROUP_GENERAL #define LOG_GROUP NFC_LOG_GROUP_GENERAL
@ -129,12 +139,34 @@ struct nfc_driver_list {
const struct nfc_driver_list *nfc_drivers = NULL; const struct nfc_driver_list *nfc_drivers = NULL;
// descritions for debugging
const char *nfc_property_name[] = {
"NP_TIMEOUT_COMMAND",
"NP_TIMEOUT_ATR",
"NP_TIMEOUT_COM",
"NP_HANDLE_CRC",
"NP_HANDLE_PARITY",
"NP_ACTIVATE_FIELD",
"NP_ACTIVATE_CRYPTO1",
"NP_INFINITE_SELECT",
"NP_ACCEPT_INVALID_FRAMES",
"NP_ACCEPT_MULTIPLE_FRAMES",
"NP_AUTO_ISO14443_4",
"NP_EASY_FRAMING",
"NP_FORCE_ISO14443_A",
"NP_FORCE_ISO14443_B",
"NP_FORCE_SPEED_106"
};
static void static void
nfc_drivers_init(void) nfc_drivers_init(void)
{ {
#if defined (DRIVER_PN53X_USB_ENABLED) #if defined (DRIVER_PN53X_USB_ENABLED)
nfc_register_driver(&pn53x_usb_driver); nfc_register_driver(&pn53x_usb_driver);
#endif /* DRIVER_PN53X_USB_ENABLED */ #endif /* DRIVER_PN53X_USB_ENABLED */
#if defined (DRIVER_PCSC_ENABLED)
nfc_register_driver(&pcsc_driver);
#endif /* DRIVER_ACR122_PCSC_ENABLED */
#if defined (DRIVER_ACR122_PCSC_ENABLED) #if defined (DRIVER_ACR122_PCSC_ENABLED)
nfc_register_driver(&acr122_pcsc_driver); nfc_register_driver(&acr122_pcsc_driver);
#endif /* DRIVER_ACR122_PCSC_ENABLED */ #endif /* DRIVER_ACR122_PCSC_ENABLED */
@ -156,8 +188,13 @@ nfc_drivers_init(void)
#if defined (DRIVER_ARYGON_ENABLED) #if defined (DRIVER_ARYGON_ENABLED)
nfc_register_driver(&arygon_driver); nfc_register_driver(&arygon_driver);
#endif /* DRIVER_ARYGON_ENABLED */ #endif /* DRIVER_ARYGON_ENABLED */
#if defined (DRIVER_PN71XX_ENABLED)
nfc_register_driver(&pn71xx_driver);
#endif /* DRIVER_PN71XX_ENABLED */
} }
static int
nfc_device_validate_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation *nm);
/** @ingroup lib /** @ingroup lib
* @brief Register an NFC device driver with libnfc. * @brief Register an NFC device driver with libnfc.
@ -169,8 +206,10 @@ nfc_drivers_init(void)
int int
nfc_register_driver(const struct nfc_driver *ndr) nfc_register_driver(const struct nfc_driver *ndr)
{ {
if (!ndr) if (!ndr) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "nfc_register_driver returning NFC_EINVARG");
return NFC_EINVARG; return NFC_EINVARG;
}
struct nfc_driver_list *pndl = (struct nfc_driver_list *)malloc(sizeof(struct nfc_driver_list)); struct nfc_driver_list *pndl = (struct nfc_driver_list *)malloc(sizeof(struct nfc_driver_list));
if (!pndl) if (!pndl)
@ -274,7 +313,7 @@ nfc_open(nfc_context *context, const nfc_connstring connstring)
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open \"%s\".", ncs); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to open \"%s\".", ncs);
return NULL; return NULL;
} }
for (uint32_t i = 0; i > context->user_defined_device_count; i++) { for (uint32_t i = 0; i < context->user_defined_device_count; i++) {
if (strcmp(ncs, context->user_defined_devices[i].connstring) == 0) { if (strcmp(ncs, context->user_defined_devices[i].connstring) == 0) {
// This is a device sets by user, we use the device name given by user // This is a device sets by user, we use the device name given by user
strcpy(pnd->name, context->user_defined_devices[i].name); strcpy(pnd->name, context->user_defined_devices[i].name);
@ -386,7 +425,7 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
pndl = pndl->next; pndl = pndl->next;
} }
} else if (context->user_defined_device_count == 0) { } else if (context->user_defined_device_count == 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "Warning: %s" , "user must specify device(s) manually when autoscan is disabled"); log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "Warning: %s", "user must specify device(s) manually when autoscan is disabled");
} }
return device_found; return device_found;
@ -406,6 +445,7 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
int int
nfc_device_set_property_int(nfc_device *pnd, const nfc_property property, const int value) nfc_device_set_property_int(nfc_device *pnd, const nfc_property property, const int value)
{ {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "set_property_int %s %s", nfc_property_name[property], value ? "True" : "False");
HAL(device_set_property_int, pnd, property, value); HAL(device_set_property_int, pnd, property, value);
} }
@ -425,6 +465,7 @@ nfc_device_set_property_int(nfc_device *pnd, const nfc_property property, const
int int
nfc_device_set_property_bool(nfc_device *pnd, const nfc_property property, const bool bEnable) nfc_device_set_property_bool(nfc_device *pnd, const nfc_property property, const bool bEnable)
{ {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "set_property_bool %s %s", nfc_property_name[property], bEnable ? "True" : "False");
HAL(device_set_property_bool, pnd, property, bEnable); HAL(device_set_property_bool, pnd, property, bEnable);
} }
@ -480,13 +521,13 @@ nfc_initiator_init(nfc_device *pnd)
} }
/** @ingroup initiator /** @ingroup initiator
* @brief Initialize NFC device as initiator with its secure element initiator (reader) * @brief Initialize NFC device as initiator with its secure element as target (reader)
* @return Returns 0 on success, otherwise returns libnfc's error code (negative value) * @return Returns 0 on success, otherwise returns libnfc's error code (negative value)
* @param pnd \a nfc_device struct pointer that represent currently used device * @param pnd \a nfc_device struct pointer that represent currently used device
* *
* The NFC device is configured to function as secure element reader. * The NFC device is configured to function as secure element reader.
* After initialization it can be used to communicate with the secure element. * After initialization it can be used to communicate with the secure element.
* @note RF field is desactvated in order to some power * @note RF field is deactivated in order to save some power
*/ */
int int
nfc_initiator_init_secure_element(nfc_device *pnd) nfc_initiator_init_secure_element(nfc_device *pnd)
@ -524,21 +565,30 @@ nfc_initiator_select_passive_target(nfc_device *pnd,
nfc_target *pnt) nfc_target *pnt)
{ {
uint8_t *abtInit = NULL; uint8_t *abtInit = NULL;
uint8_t abtTmpInit[MAX(12, szInitData)]; uint8_t maxAbt = MAX(12, szInitData);
uint8_t *abtTmpInit = malloc(sizeof(uint8_t) * maxAbt);
size_t szInit = 0; size_t szInit = 0;
int res;
if ((res = nfc_device_validate_modulation(pnd, N_INITIATOR, &nm)) != NFC_SUCCESS) {
free(abtTmpInit);
return res;
}
if (szInitData == 0) { if (szInitData == 0) {
// Provide default values, if any // Provide default values, if any
prepare_initiator_data(nm, &abtInit, &szInit); prepare_initiator_data(nm, &abtInit, &szInit);
free(abtTmpInit);
} else if (nm.nmt == NMT_ISO14443A) { } else if (nm.nmt == NMT_ISO14443A) {
abtInit = abtTmpInit; abtInit = abtTmpInit;
iso14443_cascade_uid(pbtInitData, szInitData, abtInit, &szInit); iso14443_cascade_uid(pbtInitData, szInitData, abtInit, &szInit);
} else { } else {
abtInit = abtTmpInit; abtInit = abtTmpInit;
memcpy(abtInit, pbtInitData, szInitData); memcpy(abtInit, pbtInitData, szInitData);
free(abtTmpInit);
szInit = szInitData; szInit = szInitData;
} }
HAL(initiator_select_passive_target, pnd, nm, abtInit, szInit, pnt); HAL(initiator_select_passive_target, pnd, nm, abtInit, szInit, pnt);
free(abtTmpInit);
} }
/** @ingroup initiator /** @ingroup initiator
@ -596,9 +646,10 @@ nfc_initiator_list_passive_targets(nfc_device *pnd,
break; break;
} }
nfc_initiator_deselect_target(pnd); nfc_initiator_deselect_target(pnd);
// deselect has no effect on FeliCa and Jewel cards so we'll stop after one... // deselect has no effect on FeliCa, Jewel and Thinfilm cards so we'll stop after one...
// ISO/IEC 14443 B' cards are polled at 100% probability so it's not possible to detect correctly two cards at the same time // ISO/IEC 14443 B' cards are polled at 100% probability so it's not possible to detect correctly two cards at the same time
if ((nm.nmt == NMT_FELICA) || (nm.nmt == NMT_JEWEL) || (nm.nmt == NMT_ISO14443BI) || (nm.nmt == NMT_ISO14443B2SR) || (nm.nmt == NMT_ISO14443B2CT)) { if ((nm.nmt == NMT_FELICA) || (nm.nmt == NMT_JEWEL) || (nm.nmt == NMT_BARCODE) ||
(nm.nmt == NMT_ISO14443BI) || (nm.nmt == NMT_ISO14443B2SR) || (nm.nmt == NMT_ISO14443B2CT)) {
break; break;
} }
} }
@ -640,7 +691,7 @@ nfc_initiator_poll_target(nfc_device *pnd,
* @param pnd \a nfc_device struct pointer that represent currently used device * @param pnd \a nfc_device struct pointer that represent currently used device
* @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode) * @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode)
* @param nbr desired baud rate * @param nbr desired baud rate
* @param ndiInitiator pointer \a nfc_dep_info struct that contains \e NFCID3 and \e General \e Bytes to set to the initiator device (optionnal, can be \e NULL) * @param pndiInitiator pointer \a nfc_dep_info struct that contains \e NFCID3 and \e General \e Bytes to set to the initiator device (optionnal, can be \e NULL)
* @param[out] pnt is a \a nfc_target struct pointer where target information will be put. * @param[out] pnt is a \a nfc_target struct pointer where target information will be put.
* @param timeout in milliseconds * @param timeout in milliseconds
* *
@ -668,7 +719,7 @@ nfc_initiator_select_dep_target(nfc_device *pnd,
* @param pnd \a nfc_device struct pointer that represent currently used device * @param pnd \a nfc_device struct pointer that represent currently used device
* @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode) * @param ndm desired D.E.P. mode (\a NDM_ACTIVE or \a NDM_PASSIVE for active, respectively passive mode)
* @param nbr desired baud rate * @param nbr desired baud rate
* @param ndiInitiator pointer \a nfc_dep_info struct that contains \e NFCID3 and \e General \e Bytes to set to the initiator device (optionnal, can be \e NULL) * @param pndiInitiator pointer \a nfc_dep_info struct that contains \e NFCID3 and \e General \e Bytes to set to the initiator device (optionnal, can be \e NULL)
* @param[out] pnt is a \a nfc_target struct pointer where target information will be put. * @param[out] pnt is a \a nfc_target struct pointer where target information will be put.
* @param timeout in milliseconds * @param timeout in milliseconds
* *
@ -967,7 +1018,7 @@ nfc_target_init(nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t s
* @param pnd \a nfc_device struct pointer that represent currently used device * @param pnd \a nfc_device struct pointer that represent currently used device
* *
* This function switch the device in idle mode. * This function switch the device in idle mode.
* In initiator mode, the RF field is turned off and the device is set to low power mode (if avaible); * In initiator mode, the RF field is turned off and the device is set to low power mode (if available);
* In target mode, the emulation is stoped (no target available from external initiator) and the device is set to low power mode (if avaible). * In target mode, the emulation is stoped (no target available from external initiator) and the device is set to low power mode (if avaible).
*/ */
int int
@ -1193,7 +1244,7 @@ nfc_device_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const
} }
/** @ingroup data /** @ingroup data
* @brief Get supported baud rates. * @brief Get supported baud rates (initiator mode).
* @return Returns 0 on success, otherwise returns libnfc's error code (negative value) * @return Returns 0 on success, otherwise returns libnfc's error code (negative value)
* @param pnd \a nfc_device struct pointer that represent currently used device * @param pnd \a nfc_device struct pointer that represent currently used device
* @param nmt \a nfc_modulation_type. * @param nmt \a nfc_modulation_type.
@ -1203,7 +1254,63 @@ nfc_device_get_supported_modulation(nfc_device *pnd, const nfc_mode mode, const
int int
nfc_device_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br) nfc_device_get_supported_baud_rate(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br)
{ {
HAL(get_supported_baud_rate, pnd, nmt, supported_br); HAL(get_supported_baud_rate, pnd, N_INITIATOR, nmt, supported_br);
}
/** @ingroup data
* @brief Get supported baud rates for target mode.
* @return Returns 0 on success, otherwise returns libnfc's error code (negative value)
* @param pnd \a nfc_device struct pointer that represent currently used device
* @param nmt \a nfc_modulation_type.
* @param supported_br pointer of \a nfc_baud_rate array.
*
*/
int
nfc_device_get_supported_baud_rate_target_mode(nfc_device *pnd, const nfc_modulation_type nmt, const nfc_baud_rate **const supported_br)
{
HAL(get_supported_baud_rate, pnd, N_TARGET, nmt, supported_br);
}
/** @ingroup data
* @brief Validate combination of modulation and baud rate on the currently used device.
* @return Returns 0 on success, otherwise returns libnfc's error code (negative value)
* @param pnd \a nfc_device struct pointer that represent currently used device
* @param mode \a nfc_mode.
* @param nm \a nfc_modulation.
*
*/
static int
nfc_device_validate_modulation(nfc_device *pnd, const nfc_mode mode, const nfc_modulation *nm)
{
int res;
const nfc_modulation_type *nmt = NULL;
if ((res = nfc_device_get_supported_modulation(pnd, mode, &nmt)) < 0) {
return res;
}
assert(nmt != NULL);
for (int i = 0; nmt[i]; i++) {
if (nmt[i] == nm->nmt) {
const nfc_baud_rate *nbr = NULL;
if (mode == N_INITIATOR) {
if ((res = nfc_device_get_supported_baud_rate(pnd, nmt[i], &nbr)) < 0) {
return res;
}
} else {
if ((res = nfc_device_get_supported_baud_rate_target_mode(pnd, nmt[i], &nbr)) < 0) {
return res;
}
}
assert(nbr != NULL);
for (int j = 0; nbr[j]; j++) {
if (nbr[j] == nm->nbr)
return NFC_SUCCESS;
}
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "nfc_device_validate_modulation returning NFC_EINVARG");
return NFC_EINVARG;
}
}
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "nfc_device_validate_modulation returning NFC_EINVARG");
return NFC_EINVARG;
} }
/* Misc. functions */ /* Misc. functions */
@ -1252,7 +1359,7 @@ nfc_device_get_information_about(nfc_device *pnd, char **buf)
/** @ingroup string-converter /** @ingroup string-converter
* @brief Convert \a nfc_baud_rate value to string * @brief Convert \a nfc_baud_rate value to string
* @return Returns nfc baud rate * @return Returns nfc baud rate
* @param \a nfc_baud_rate to convert * @param nbr \a nfc_baud_rate to convert
*/ */
const char * const char *
str_nfc_baud_rate(const nfc_baud_rate nbr) str_nfc_baud_rate(const nfc_baud_rate nbr)
@ -1260,28 +1367,23 @@ str_nfc_baud_rate(const nfc_baud_rate nbr)
switch (nbr) { switch (nbr) {
case NBR_UNDEFINED: case NBR_UNDEFINED:
return "undefined baud rate"; return "undefined baud rate";
break;
case NBR_106: case NBR_106:
return "106 kbps"; return "106 kbps";
break;
case NBR_212: case NBR_212:
return "212 kbps"; return "212 kbps";
break;
case NBR_424: case NBR_424:
return "424 kbps"; return "424 kbps";
break;
case NBR_847: case NBR_847:
return "847 kbps"; return "847 kbps";
break;
} }
// Should never go there..
return ""; return "???";
} }
/** @ingroup string-converter /** @ingroup string-converter
* @brief Convert \a nfc_modulation_type value to string * @brief Convert \a nfc_modulation_type value to string
* @return Returns nfc modulation type * @return Returns nfc modulation type
* @param \a nfc_modulation_type to convert * @param nmt \a nfc_modulation_type to convert
*/ */
const char * const char *
str_nfc_modulation_type(const nfc_modulation_type nmt) str_nfc_modulation_type(const nfc_modulation_type nmt)
@ -1289,38 +1391,35 @@ str_nfc_modulation_type(const nfc_modulation_type nmt)
switch (nmt) { switch (nmt) {
case NMT_ISO14443A: case NMT_ISO14443A:
return "ISO/IEC 14443A"; return "ISO/IEC 14443A";
break;
case NMT_ISO14443B: case NMT_ISO14443B:
return "ISO/IEC 14443-4B"; return "ISO/IEC 14443-4B";
break;
case NMT_ISO14443BI: case NMT_ISO14443BI:
return "ISO/IEC 14443-4B'"; return "ISO/IEC 14443-4B'";
break; case NMT_ISO14443BICLASS:
return "ISO/IEC 14443-2B-3B iClass (Picopass)";
case NMT_ISO14443B2CT: case NMT_ISO14443B2CT:
return "ISO/IEC 14443-2B ASK CTx"; return "ISO/IEC 14443-2B ASK CTx";
break;
case NMT_ISO14443B2SR: case NMT_ISO14443B2SR:
return "ISO/IEC 14443-2B ST SRx"; return "ISO/IEC 14443-2B ST SRx";
break;
case NMT_FELICA: case NMT_FELICA:
return "FeliCa"; return "FeliCa";
break;
case NMT_JEWEL: case NMT_JEWEL:
return "Innovision Jewel"; return "Innovision Jewel";
break; case NMT_BARCODE:
return "Thinfilm NFC Barcode";
case NMT_DEP: case NMT_DEP:
return "D.E.P."; return "D.E.P.";
break;
} }
// Should never go there..
return ""; return "???";
} }
/** @ingroup string-converter /** @ingroup string-converter
* @brief Convert \a nfc_modulation_type value to string * @brief Convert \a nfc_target content to string
* @return Upon successful return, this function returns the number of characters printed (excluding the null byte used to end output to strings), otherwise returns libnfc's error code (negative value) * @return Upon successful return, this function returns the number of characters printed (excluding the null byte used to end output to strings), otherwise returns libnfc's error code (negative value)
* @param nt \a nfc_target struct to print * @param pnt \a nfc_target struct pointer to print
* @param buf pointer where string will be allocated, then nfc target information printed * @param buf pointer where string will be allocated, then nfc target information printed
* @param verbose false for essential, true for detailed, human-readable, information
* *
* @warning *buf must be freed using nfc_free() * @warning *buf must be freed using nfc_free()
*/ */

View File

@ -9,6 +9,7 @@
* Copyright (C) 2012-2013 Ludovic Rousseau * Copyright (C) 2012-2013 Ludovic Rousseau
* See AUTHORS file for a more comprehensive list of contributors. * See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file: * Additional contributors of this file:
* Copyright (C) 2020 Adam Laurie
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the * under the terms of the GNU Lesser General Public License as published by the
@ -498,6 +499,22 @@ snprint_nfc_jewel_info(char *dst, size_t size, const nfc_jewel_info *pnji, bool
snprint_hex(dst + off, size - off, pnji->btId, 4); snprint_hex(dst + off, size - off, pnji->btId, 4);
} }
void
snprint_nfc_barcode_info(char *dst, size_t size, const nfc_barcode_info *pnti, bool verbose)
{
(void) verbose;
int off = 0;
off += snprintf(dst + off, size - off, " Size (bits): %lu\n", (unsigned long)(pnti->szDataLen * 8));
off += snprintf(dst + off, size - off, " Content: ");
for (uint8_t i = 0; i < pnti->szDataLen; i++) {
off += snprintf(dst + off, size - off, "%02X", pnti->abtData[i]);
if ((i % 8 == 7) && (i < (pnti->szDataLen - 1))) {
off += snprintf(dst + off, size - off, "\n ");
}
}
snprintf(dst + off, size - off, "\n");
}
#define PI_ISO14443_4_SUPPORTED 0x01 #define PI_ISO14443_4_SUPPORTED 0x01
#define PI_NAD_SUPPORTED 0x01 #define PI_NAD_SUPPORTED 0x01
#define PI_CID_SUPPORTED 0x02 #define PI_CID_SUPPORTED 0x02
@ -593,6 +610,15 @@ snprint_nfc_iso14443b2sr_info(char *dst, size_t size, const nfc_iso14443b2sr_inf
snprint_hex(dst + off, size - off, pnsi->abtUID, 8); snprint_hex(dst + off, size - off, pnsi->abtUID, 8);
} }
void
snprint_nfc_iso14443biclass_info(char *dst, size_t size, const nfc_iso14443biclass_info *pnic, bool verbose)
{
(void) verbose;
int off = 0;
off += snprintf(dst + off, size - off, " UID: ");
snprint_hex(dst + off, size - off, pnic->abtUID, 8);
}
void void
snprint_nfc_iso14443b2ct_info(char *dst, size_t size, const nfc_iso14443b2ct_info *pnci, bool verbose) snprint_nfc_iso14443b2ct_info(char *dst, size_t size, const nfc_iso14443b2ct_info *pnci, bool verbose)
{ {
@ -637,6 +663,9 @@ snprint_nfc_target(char *dst, size_t size, const nfc_target *pnt, bool verbose)
case NMT_JEWEL: case NMT_JEWEL:
snprint_nfc_jewel_info(dst + off, size - off, &pnt->nti.nji, verbose); snprint_nfc_jewel_info(dst + off, size - off, &pnt->nti.nji, verbose);
break; break;
case NMT_BARCODE:
snprint_nfc_barcode_info(dst + off, size - off, &pnt->nti.nti, verbose);
break;
case NMT_FELICA: case NMT_FELICA:
snprint_nfc_felica_info(dst + off, size - off, &pnt->nti.nfi, verbose); snprint_nfc_felica_info(dst + off, size - off, &pnt->nti.nfi, verbose);
break; break;
@ -649,6 +678,9 @@ snprint_nfc_target(char *dst, size_t size, const nfc_target *pnt, bool verbose)
case NMT_ISO14443B2SR: case NMT_ISO14443B2SR:
snprint_nfc_iso14443b2sr_info(dst + off, size - off, &pnt->nti.nsi, verbose); snprint_nfc_iso14443b2sr_info(dst + off, size - off, &pnt->nti.nsi, verbose);
break; break;
case NMT_ISO14443BICLASS:
snprint_nfc_iso14443biclass_info(dst + off, size - off, &pnt->nti.nhi, verbose);
break;
case NMT_ISO14443B2CT: case NMT_ISO14443B2CT:
snprint_nfc_iso14443b2ct_info(dst + off, size - off, &pnt->nti.nci, verbose); snprint_nfc_iso14443b2ct_info(dst + off, size - off, &pnt->nti.nci, verbose);
break; break;

View File

@ -9,6 +9,7 @@
* Copyright (C) 2012-2013 Ludovic Rousseau * Copyright (C) 2012-2013 Ludovic Rousseau
* See AUTHORS file for a more comprehensive list of contributors. * See AUTHORS file for a more comprehensive list of contributors.
* Additional contributors of this file: * Additional contributors of this file:
* Copyright (C) 2020 Adam Laurie
* *
* This program is free software: you can redistribute it and/or modify it * This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the * under the terms of the GNU Lesser General Public License as published by the
@ -37,9 +38,11 @@ void snprint_nfc_iso14443a_info(char *dst, size_t size, const nfc_iso14443a_i
void snprint_nfc_iso14443b_info(char *dst, size_t size, const nfc_iso14443b_info *pnbi, bool verbose); void snprint_nfc_iso14443b_info(char *dst, size_t size, const nfc_iso14443b_info *pnbi, bool verbose);
void snprint_nfc_iso14443bi_info(char *dst, size_t size, const nfc_iso14443bi_info *pnii, bool verbose); void snprint_nfc_iso14443bi_info(char *dst, size_t size, const nfc_iso14443bi_info *pnii, bool verbose);
void snprint_nfc_iso14443b2sr_info(char *dst, size_t size, const nfc_iso14443b2sr_info *pnsi, bool verbose); void snprint_nfc_iso14443b2sr_info(char *dst, size_t size, const nfc_iso14443b2sr_info *pnsi, bool verbose);
void snprint_nfc_iso14443biclass_info(char *dst, size_t size, const nfc_iso14443biclass_info *pnic, bool verbose);
void snprint_nfc_iso14443b2ct_info(char *dst, size_t size, const nfc_iso14443b2ct_info *pnci, bool verbose); void snprint_nfc_iso14443b2ct_info(char *dst, size_t size, const nfc_iso14443b2ct_info *pnci, bool verbose);
void snprint_nfc_felica_info(char *dst, size_t size, const nfc_felica_info *pnfi, bool verbose); void snprint_nfc_felica_info(char *dst, size_t size, const nfc_felica_info *pnfi, bool verbose);
void snprint_nfc_jewel_info(char *dst, size_t size, const nfc_jewel_info *pnji, bool verbose); void snprint_nfc_jewel_info(char *dst, size_t size, const nfc_jewel_info *pnji, bool verbose);
void snprint_nfc_barcode_info(char *dst, size_t size, const nfc_barcode_info *pnti, bool verbose);
void snprint_nfc_dep_info(char *dst, size_t size, const nfc_dep_info *pndi, bool verbose); void snprint_nfc_dep_info(char *dst, size_t size, const nfc_dep_info *pndi, bool verbose);
void snprint_nfc_target(char *dst, size_t size, const nfc_target *pnt, bool verbose); void snprint_nfc_target(char *dst, size_t size, const nfc_target *pnt, bool verbose);

View File

@ -4,7 +4,8 @@ AC_DEFUN([LIBNFC_ARG_WITH_DRIVERS],
[ [
AC_MSG_CHECKING(which drivers to build) AC_MSG_CHECKING(which drivers to build)
AC_ARG_WITH(drivers, AC_ARG_WITH(drivers,
AS_HELP_STRING([--with-drivers=DRIVERS], [Use a custom driver set, where DRIVERS is a coma-separated list of drivers to build support for. Available drivers are: 'acr122_pcsc', 'acr122_usb', 'acr122s', 'arygon', 'pn532_i2c', 'pn532_spi', 'pn532_uart' and 'pn53x_usb'. Default drivers set is 'acr122_usb,acr122s,arygon,pn532_i2c,pn532_spi,pn532_uart,pn53x_usb'. The special driver set 'all' compile all available drivers.]), AS_HELP_STRING([--with-drivers=DRIVERS], [Use a custom driver set, where DRIVERS is a coma-separated list of drivers to build support for. Available drivers are: 'acr122_pcsc', 'acr122_usb', 'acr122s', 'arygon', 'pcsc', 'pn532_i2c', 'pn532_spi', 'pn532_uart', 'pn53x_usb' and 'pn71xx'. Default drivers set is 'acr122_usb,acr122s,arygon,pn532_i2c,pn532_spi,pn532_uart,pn53x_usb'. The special driver set 'all' compile all available drivers.]),
[ case "${withval}" in [ case "${withval}" in
yes | no) yes | no)
dnl ignore calls without any arguments dnl ignore calls without any arguments
@ -36,7 +37,8 @@ AC_DEFUN([LIBNFC_ARG_WITH_DRIVERS],
fi fi
;; ;;
all) all)
DRIVER_BUILD_LIST="acr122_pcsc acr122_usb acr122s arygon pn53x_usb pn532_uart" DRIVER_BUILD_LIST="acr122_pcsc acr122_usb acr122s arygon pn53x_usb pn532_uart pcsc"
if test x"$spi_available" = x"yes" if test x"$spi_available" = x"yes"
then then
DRIVER_BUILD_LIST="$DRIVER_BUILD_LIST pn532_spi" DRIVER_BUILD_LIST="$DRIVER_BUILD_LIST pn532_spi"
@ -45,11 +47,16 @@ AC_DEFUN([LIBNFC_ARG_WITH_DRIVERS],
then then
DRIVER_BUILD_LIST="$DRIVER_BUILD_LIST pn532_i2c" DRIVER_BUILD_LIST="$DRIVER_BUILD_LIST pn532_i2c"
fi fi
if test x"$nfc_nci_available" = x"yes"
then
DRIVER_BUILD_LIST="$DRIVER_BUILD_LIST pn71xx"
fi
;; ;;
esac esac
DRIVERS_CFLAGS="" DRIVERS_CFLAGS=""
driver_pcsc_enabled="no"
driver_acr122_pcsc_enabled="no" driver_acr122_pcsc_enabled="no"
driver_acr122_usb_enabled="no" driver_acr122_usb_enabled="no"
driver_acr122s_enabled="no" driver_acr122s_enabled="no"
@ -58,10 +65,16 @@ AC_DEFUN([LIBNFC_ARG_WITH_DRIVERS],
driver_pn532_uart_enabled="no" driver_pn532_uart_enabled="no"
driver_pn532_spi_enabled="no" driver_pn532_spi_enabled="no"
driver_pn532_i2c_enabled="no" driver_pn532_i2c_enabled="no"
driver_pn71xx_enabled="no"
for driver in ${DRIVER_BUILD_LIST} for driver in ${DRIVER_BUILD_LIST}
do do
case "${driver}" in case "${driver}" in
pcsc)
pcsc_required="yes"
driver_pcsc_enabled="yes"
DRIVERS_CFLAGS="$DRIVERS_CFLAGS -DDRIVER_PCSC_ENABLED"
;;
acr122_pcsc) acr122_pcsc)
pcsc_required="yes" pcsc_required="yes"
driver_acr122_pcsc_enabled="yes" driver_acr122_pcsc_enabled="yes"
@ -102,6 +115,11 @@ AC_DEFUN([LIBNFC_ARG_WITH_DRIVERS],
driver_pn532_i2c_enabled="yes" driver_pn532_i2c_enabled="yes"
DRIVERS_CFLAGS="$DRIVERS_CFLAGS -DDRIVER_PN532_I2C_ENABLED" DRIVERS_CFLAGS="$DRIVERS_CFLAGS -DDRIVER_PN532_I2C_ENABLED"
;; ;;
pn71xx)
nfc_nci_required="yes"
driver_pn71xx_enabled="yes"
DRIVERS_CFLAGS="$DRIVERS_CFLAGS -DDRIVER_PN71XX_ENABLED"
;;
*) *)
AC_MSG_ERROR([Unknow driver: $driver]) AC_MSG_ERROR([Unknow driver: $driver])
;; ;;
@ -109,6 +127,7 @@ AC_DEFUN([LIBNFC_ARG_WITH_DRIVERS],
done done
AC_SUBST(DRIVERS_CFLAGS) AC_SUBST(DRIVERS_CFLAGS)
AM_CONDITIONAL(DRIVER_ACR122_PCSC_ENABLED, [test x"$driver_acr122_pcsc_enabled" = xyes]) AM_CONDITIONAL(DRIVER_ACR122_PCSC_ENABLED, [test x"$driver_acr122_pcsc_enabled" = xyes])
AM_CONDITIONAL(DRIVER_PCSC_ENABLED, [test x"$driver_pcsc_enabled" = xyes])
AM_CONDITIONAL(DRIVER_ACR122_USB_ENABLED, [test x"$driver_acr122_usb_enabled" = xyes]) AM_CONDITIONAL(DRIVER_ACR122_USB_ENABLED, [test x"$driver_acr122_usb_enabled" = xyes])
AM_CONDITIONAL(DRIVER_ACR122S_ENABLED, [test x"$driver_acr122s_enabled" = xyes]) AM_CONDITIONAL(DRIVER_ACR122S_ENABLED, [test x"$driver_acr122s_enabled" = xyes])
AM_CONDITIONAL(DRIVER_PN53X_USB_ENABLED, [test x"$driver_pn53x_usb_enabled" = xyes]) AM_CONDITIONAL(DRIVER_PN53X_USB_ENABLED, [test x"$driver_pn53x_usb_enabled" = xyes])
@ -116,11 +135,13 @@ AC_DEFUN([LIBNFC_ARG_WITH_DRIVERS],
AM_CONDITIONAL(DRIVER_PN532_UART_ENABLED, [test x"$driver_pn532_uart_enabled" = xyes]) AM_CONDITIONAL(DRIVER_PN532_UART_ENABLED, [test x"$driver_pn532_uart_enabled" = xyes])
AM_CONDITIONAL(DRIVER_PN532_SPI_ENABLED, [test x"$driver_pn532_spi_enabled" = xyes]) AM_CONDITIONAL(DRIVER_PN532_SPI_ENABLED, [test x"$driver_pn532_spi_enabled" = xyes])
AM_CONDITIONAL(DRIVER_PN532_I2C_ENABLED, [test x"$driver_pn532_i2c_enabled" = xyes]) AM_CONDITIONAL(DRIVER_PN532_I2C_ENABLED, [test x"$driver_pn532_i2c_enabled" = xyes])
AM_CONDITIONAL(DRIVER_PN71XX_ENABLED, [test x"$driver_pn71xx_enabled" = xyes])
]) ])
AC_DEFUN([LIBNFC_DRIVERS_SUMMARY],[ AC_DEFUN([LIBNFC_DRIVERS_SUMMARY],[
echo echo
echo "Selected drivers:" echo "Selected drivers:"
echo " pcsc............. $driver_pcsc_enabled"
echo " acr122_pcsc...... $driver_acr122_pcsc_enabled" echo " acr122_pcsc...... $driver_acr122_pcsc_enabled"
echo " acr122_usb....... $driver_acr122_usb_enabled" echo " acr122_usb....... $driver_acr122_usb_enabled"
echo " acr122s.......... $driver_acr122s_enabled" echo " acr122s.......... $driver_acr122s_enabled"
@ -129,4 +150,5 @@ echo " pn53x_usb........ $driver_pn53x_usb_enabled"
echo " pn532_uart....... $driver_pn532_uart_enabled" echo " pn532_uart....... $driver_pn532_uart_enabled"
echo " pn532_spi....... $driver_pn532_spi_enabled" echo " pn532_spi....... $driver_pn532_spi_enabled"
echo " pn532_i2c........ $driver_pn532_i2c_enabled" echo " pn532_i2c........ $driver_pn532_i2c_enabled"
echo " pn71xx........... $driver_pn71xx_enabled"
]) ])

34
mingw-cross-compile.sh Normal file
View File

@ -0,0 +1,34 @@
#!/bin/sh
PROJECT_DIR=$(readlink -e $(dirname $0))
cd "$PROJECT_DIR"
WITH_USB=1
LIBUSB_WIN32_BIN_VERSION="1.2.6.0"
LIBUSB_WIN32_BIN_ARCHIVE="libusb-win32-bin-$LIBUSB_WIN32_BIN_VERSION.zip"
LIBUSB_WIN32_BIN_URL="http://freefr.dl.sourceforge.net/project/libusb-win32/libusb-win32-releases/$LIBUSB_WIN32_BIN_VERSION/$LIBUSB_WIN32_BIN_ARCHIVE"
LIBUSB_WIN32_BIN_DIR="libusb-win32-bin-$LIBUSB_WIN32_BIN_VERSION"
if [ "$WITH_USB" = "1" ]; then
if [ ! -d $LIBUSB_WIN32_BIN_DIR ]; then
wget -c $LIBUSB_WIN32_BIN_URL
unzip $LIBUSB_WIN32_BIN_ARCHIVE
fi
fi
rm -rf build
mkdir build
cd build
case $1 in
32*)
mingw32-cmake .. -DLIBUSB_INCLUDE_DIRS="$PROJECT_DIR"/libusb-win32-bin-1.2.6.0/include -DLIBUSB_LIBRARIES="$PROJECT_DIR"/libusb-win32-bin-1.2.6.0/bin/x86/libusb0_x86.dll -DLIBNFC_ROOT_DIR=$PWD/.. -DLIBNFC_SYSCONFDIR='C:\\Program Files (x86)\\libnfc\\config'
mingw32-make;;
64*)
mingw64-cmake .. -DLIBUSB_INCLUDE_DIRS="$PROJECT_DIR"/libusb-win32-bin-1.2.6.0/include -DLIBUSB_LIBRARIES="$PROJECT_DIR"/libusb-win32-bin-1.2.6.0/bin/amd64/libusb0.dll -DLIBNFC_ROOT_DIR=.. -DLIBNFC_SYSCONFDIR='C:\\Program Files\\libnfc\\config'
mingw64-make;;
*)
echo "specify whether to build 32-bit or 64-bit version by supplying 32 or 64 as parameter";;
esac

View File

@ -1,91 +0,0 @@
#!/bin/sh
WITH_USB=1
LIBUSB_WIN32_BIN_VERSION="1.2.6.0"
LIBUSB_WIN32_BIN_ARCHIVE="libusb-win32-bin-$LIBUSB_WIN32_BIN_VERSION.zip"
LIBUSB_WIN32_BIN_URL="http://freefr.dl.sourceforge.net/project/libusb-win32/libusb-win32-releases/$LIBUSB_WIN32_BIN_VERSION/$LIBUSB_WIN32_BIN_ARCHIVE"
LIBUSB_WIN32_BIN_DIR="libusb-win32-bin-$LIBUSB_WIN32_BIN_VERSION"
if [ "$WITH_USB" = "1" ]; then
if [ ! -d $LIBUSB_WIN32_BIN_DIR ]; then
wget -c $LIBUSB_WIN32_BIN_URL
unzip $LIBUSB_WIN32_BIN_ARCHIVE
fi
fi
MINGW="${MINGW:=i686-w64-mingw32}"
MINGW_DIR="/usr/$MINGW"
# Use MinGW binaries before others
#export PATH=$MINGW_DIR/bin:$PATH
# Set CPATH to MinGW include files
export CPATH=$MINGW_DIR/include
export LD_LIBRARY_PATH=$MINGW_DIR/lib
export LD_RUN_PATH=$MINGW_DIR/lib
# Force pkg-config to search in cross environement directory
export PKG_CONFIG_LIBDIR=$MINGW_DIR/lib/pkgconfig
# Stop compilation on first error
export CFLAGS="-Wfatal-errors"
# Include default MinGW include directory, and libnfc's win32 files
export CFLAGS="$CFLAGS -I$MINGW_DIR/include -I$PWD/contrib/win32"
if [ "$MINGW" = "i686-w64-mingw32" ]; then
# mingw-64 includes winscard.a and winscard.h
#
# It is not enough to set libpcsclite_LIBS to "-lwinscard", because it is
# forgotten when libnfc is created with libtool. That's why we are setting
# LIBS.
export LIBS="-lwinscard"
echo "MinGW-w64 ships all requirements libnfc."
echo "Unfortunately the MinGW-w64 header are currently"
echo "buggy. Also, Libtool doesn't support MinGW-w64"
echo "very well."
echo ""
echo "Warning ________________________________________"
echo "You will only be able to compile libnfc.dll, but"
echo "none of the executables (see utils and examples)."
echo ""
# You can fix winbase.h by adding the following lines:
# #include <basetsd.h>
# #include <windef.h>
# But the problem with Libtool remains.
else
if [ -z "$libpcsclite_LIBS$libpcsclite_CFLAGS" ]; then
echo "Error __________________________________________"
echo "You need to get the PC/SC library from a Windows"
echo "machine and the appropriate header files. Then"
echo "specify libpcsclite_LIBS=.../WinScard.dll and"
echo "libpcsclite_CFLAGS=-I..."
fi
exit 1
fi
## Configure to cross-compile using mingw32msvc
if [ "$WITH_USB" = "1" ]; then
# with direct-USB drivers (use libusb-win32)
DRIVERS="all"
else
# with UART divers only (can be tested under wine)
DRIVERS="pn532_uart,arygon"
fi
if [ ! -x configure ]; then
autoreconf -is
fi
./configure --target=$MINGW --host=$MINGW \
--with-drivers=$DRIVERS \
--with-libusb-win32=$PWD/$LIBUSB_WIN32_BIN_DIR \
$*
if [ "$MINGW" = "i686-w64-mingw32" ]; then
# due to the buggy headers from MINGW-64 we always add "contrib/windows.h",
# otherwise some windows types won't be available.
echo "#include \"contrib/windows.h\"" >> config.h
fi

View File

@ -45,7 +45,7 @@ test_register_endianness_la_LIBADD = $(top_builddir)/libnfc/libnfc.la
echo-cutter: echo-cutter:
@echo $(CUTTER) @echo $(CUTTER)
EXTRA_DIST = run-test.sh
CLEANFILES = *.gcno CLEANFILES = *.gcno
endif endif
EXTRA_DIST = run-test.sh

View File

@ -45,7 +45,7 @@ test_access_storm(void)
.nbr = NBR_106, .nbr = NBR_106,
}; };
res = nfc_initiator_list_passive_targets(device, nm, ant, MAX_TARGET_COUNT); res = nfc_initiator_list_passive_targets(device, nm, ant, MAX_TARGET_COUNT);
cut_assert_operator_int(res, >= , 0, cut_message("nfc_initiator_list_passive_targets")); cut_assert_operator_int(res, >=, 0, cut_message("nfc_initiator_list_passive_targets"));
nfc_close(device); nfc_close(device);
} }

View File

@ -86,18 +86,18 @@ target_thread(void *arg)
uint8_t abtRx[1024]; uint8_t abtRx[1024];
int res = nfc_target_init(device, &nt, abtRx, sizeof(abtRx), 0); int res = nfc_target_init(device, &nt, abtRx, sizeof(abtRx), 0);
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500); res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
const uint8_t abtAttRx[] = "Hello DEP target!"; const uint8_t abtAttRx[] = "Hello DEP target!";
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data")); cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
if (res <= 0) { thread_res = -1; return (void *) thread_res; } if (res <= 0) { thread_res = -1; return (void *) thread_res; }
const uint8_t abtTx[] = "Hello DEP initiator!"; const uint8_t abtTx[] = "Hello DEP initiator!";
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500); res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
if (res <= 0) { thread_res = -1; return (void *) thread_res; } if (res <= 0) { thread_res = -1; return (void *) thread_res; }
return (void *) thread_res; return (void *) thread_res;
@ -125,7 +125,7 @@ initiator_thread(void *arg)
// Active mode // Active mode
printf("=========== INITIATOR %s (Active mode / %s Kbps) =========\n", nfc_device_get_name(device), str_nfc_baud_rate(nbr)); printf("=========== INITIATOR %s (Active mode / %s Kbps) =========\n", nfc_device_get_name(device), str_nfc_baud_rate(nbr));
res = nfc_initiator_select_dep_target(device, NDM_ACTIVE, nbr, NULL, &nt, 1000); res = nfc_initiator_select_dep_target(device, NDM_ACTIVE, nbr, NULL, &nt, 1000);
cut_assert_operator_int(res, > , 0, cut_message("Can't select any DEP target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't select any DEP target: %s", nfc_strerror(device)));
cut_assert_equal_int(NMT_DEP, nt.nm.nmt, cut_message("Invalid target modulation")); cut_assert_equal_int(NMT_DEP, nt.nm.nmt, cut_message("Invalid target modulation"));
cut_assert_equal_int(nbr, nt.nm.nbr, cut_message("Invalid target baud rate")); cut_assert_equal_int(nbr, nt.nm.nbr, cut_message("Invalid target baud rate"));
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3")); cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
@ -136,13 +136,13 @@ initiator_thread(void *arg)
const uint8_t abtTx[] = "Hello DEP target!"; const uint8_t abtTx[] = "Hello DEP target!";
uint8_t abtRx[1024]; uint8_t abtRx[1024];
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000); res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000);
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >=, 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
const uint8_t abtAttRx[] = "Hello DEP initiator!"; const uint8_t abtAttRx[] = "Hello DEP initiator!";
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data (as initiator)")); cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data (as initiator)"));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
res = nfc_initiator_deselect_target(device); res = nfc_initiator_deselect_target(device);
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >=, 0, cut_message("Can't deselect target: %s", nfc_strerror(device)));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
return (void *) thread_res; return (void *) thread_res;

View File

@ -86,12 +86,12 @@ target_thread(void *arg)
uint8_t abtRx[1024]; uint8_t abtRx[1024];
size_t szRx = sizeof(abtRx); size_t szRx = sizeof(abtRx);
int res = nfc_target_init(device, &nt, abtRx, szRx, 0); int res = nfc_target_init(device, &nt, abtRx, szRx, 0);
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
// First pass // First pass
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500); res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
const uint8_t abtAttRx[] = "Hello DEP target!"; const uint8_t abtAttRx[] = "Hello DEP target!";
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data")); cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
@ -99,40 +99,40 @@ target_thread(void *arg)
const uint8_t abtTx[] = "Hello DEP initiator!"; const uint8_t abtTx[] = "Hello DEP initiator!";
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500); res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
if (res <= 0) { thread_res = -1; return (void *) thread_res; } if (res <= 0) { thread_res = -1; return (void *) thread_res; }
// Second pass // Second pass
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500); res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data")); cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
if (res <= 0) { thread_res = -1; return (void *) thread_res; } if (res <= 0) { thread_res = -1; return (void *) thread_res; }
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500); res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
if (res <= 0) { thread_res = -1; return (void *) thread_res; } if (res <= 0) { thread_res = -1; return (void *) thread_res; }
// Third pass // Third pass
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500); res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data")); cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
if (res <= 0) { thread_res = -1; return (void *) thread_res; } if (res <= 0) { thread_res = -1; return (void *) thread_res; }
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500); res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
if (res <= 0) { thread_res = -1; return (void *) thread_res; } if (res <= 0) { thread_res = -1; return (void *) thread_res; }
// Fourth pass // Fourth pass
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500); res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data")); cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
if (res <= 0) { thread_res = -1; return (void *) thread_res; } if (res <= 0) { thread_res = -1; return (void *) thread_res; }
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500); res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
if (res <= 0) { thread_res = -1; return (void *) thread_res; } if (res <= 0) { thread_res = -1; return (void *) thread_res; }
return (void *) thread_res; return (void *) thread_res;
@ -160,7 +160,7 @@ initiator_thread(void *arg)
// Passive mode / 106Kbps // Passive mode / 106Kbps
printf("=========== INITIATOR %s (Passive mode / 106Kbps) =========\n", nfc_device_get_name(device)); printf("=========== INITIATOR %s (Passive mode / 106Kbps) =========\n", nfc_device_get_name(device));
res = nfc_initiator_select_dep_target(device, NDM_PASSIVE, NBR_106, NULL, &nt, 5000); res = nfc_initiator_select_dep_target(device, NDM_PASSIVE, NBR_106, NULL, &nt, 5000);
cut_assert_operator_int(res, > , 0, cut_message("Can't select any DEP target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't select any DEP target: %s", nfc_strerror(device)));
cut_assert_equal_int(NMT_DEP, nt.nm.nmt, cut_message("Invalid target modulation")); cut_assert_equal_int(NMT_DEP, nt.nm.nmt, cut_message("Invalid target modulation"));
cut_assert_equal_int(NBR_106, nt.nm.nbr, cut_message("Invalid target baud rate")); cut_assert_equal_int(NBR_106, nt.nm.nbr, cut_message("Invalid target baud rate"));
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3")); cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
@ -171,20 +171,20 @@ initiator_thread(void *arg)
const uint8_t abtTx[] = "Hello DEP target!"; const uint8_t abtTx[] = "Hello DEP target!";
uint8_t abtRx[1024]; uint8_t abtRx[1024];
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 500); res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 500);
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >=, 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
const uint8_t abtAttRx[] = "Hello DEP initiator!"; const uint8_t abtAttRx[] = "Hello DEP initiator!";
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data")); cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
res = nfc_initiator_deselect_target(device); res = nfc_initiator_deselect_target(device);
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >=, 0, cut_message("Can't deselect target: %s", nfc_strerror(device)));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
// Passive mode / 212Kbps (second pass) // Passive mode / 212Kbps (second pass)
printf("=========== INITIATOR %s (Passive mode / 212Kbps) =========\n", nfc_device_get_name(device)); printf("=========== INITIATOR %s (Passive mode / 212Kbps) =========\n", nfc_device_get_name(device));
res = nfc_initiator_select_dep_target(device, NDM_PASSIVE, NBR_212, NULL, &nt, 1000); res = nfc_initiator_select_dep_target(device, NDM_PASSIVE, NBR_212, NULL, &nt, 1000);
cut_assert_operator_int(res, > , 0, cut_message("Can't select any DEP target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't select any DEP target: %s", nfc_strerror(device)));
cut_assert_equal_int(NMT_DEP, nt.nm.nmt, cut_message("Invalid target modulation")); cut_assert_equal_int(NMT_DEP, nt.nm.nmt, cut_message("Invalid target modulation"));
cut_assert_equal_int(NBR_212, nt.nm.nbr, cut_message("Invalid target baud rate")); cut_assert_equal_int(NBR_212, nt.nm.nbr, cut_message("Invalid target baud rate"));
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3")); cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
@ -193,19 +193,19 @@ initiator_thread(void *arg)
if (res <= 0) { thread_res = -1; return (void *) thread_res; } if (res <= 0) { thread_res = -1; return (void *) thread_res; }
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 1000); res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 1000);
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >=, 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data")); cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
res = nfc_initiator_deselect_target(device); res = nfc_initiator_deselect_target(device);
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >=, 0, cut_message("Can't deselect target: %s", nfc_strerror(device)));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
// Passive mode / 212Kbps // Passive mode / 212Kbps
printf("=========== INITIATOR %s (Passive mode / 212Kbps, second pass) =========\n", nfc_device_get_name(device)); printf("=========== INITIATOR %s (Passive mode / 212Kbps, second pass) =========\n", nfc_device_get_name(device));
res = nfc_initiator_select_dep_target(device, NDM_PASSIVE, NBR_212, NULL, &nt, 1000); res = nfc_initiator_select_dep_target(device, NDM_PASSIVE, NBR_212, NULL, &nt, 1000);
cut_assert_operator_int(res, > , 0, cut_message("Can't select any DEP target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't select any DEP target: %s", nfc_strerror(device)));
cut_assert_equal_int(NMT_DEP, nt.nm.nmt, cut_message("Invalid target modulation")); cut_assert_equal_int(NMT_DEP, nt.nm.nmt, cut_message("Invalid target modulation"));
cut_assert_equal_int(NBR_212, nt.nm.nbr, cut_message("Invalid target baud rate")); cut_assert_equal_int(NBR_212, nt.nm.nbr, cut_message("Invalid target baud rate"));
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3")); cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
@ -214,19 +214,19 @@ initiator_thread(void *arg)
if (res <= 0) { thread_res = -1; return (void *) thread_res; } if (res <= 0) { thread_res = -1; return (void *) thread_res; }
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000); res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000);
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >=, 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data")); cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
res = nfc_initiator_deselect_target(device); res = nfc_initiator_deselect_target(device);
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >=, 0, cut_message("Can't deselect target: %s", nfc_strerror(device)));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
// Passive mode / 424Kbps // Passive mode / 424Kbps
printf("=========== INITIATOR %s (Passive mode / 424Kbps) =========\n", nfc_device_get_name(device)); printf("=========== INITIATOR %s (Passive mode / 424Kbps) =========\n", nfc_device_get_name(device));
res = nfc_initiator_select_dep_target(device, NDM_PASSIVE, NBR_424, NULL, &nt, 1000); res = nfc_initiator_select_dep_target(device, NDM_PASSIVE, NBR_424, NULL, &nt, 1000);
cut_assert_operator_int(res, > , 0, cut_message("Can't select any DEP target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't select any DEP target: %s", nfc_strerror(device)));
cut_assert_equal_int(NMT_DEP, nt.nm.nmt, cut_message("Invalid target modulation")); cut_assert_equal_int(NMT_DEP, nt.nm.nmt, cut_message("Invalid target modulation"));
cut_assert_equal_int(NBR_424, nt.nm.nbr, cut_message("Invalid target baud rate")); cut_assert_equal_int(NBR_424, nt.nm.nbr, cut_message("Invalid target baud rate"));
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3")); cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
@ -235,13 +235,13 @@ initiator_thread(void *arg)
if (res <= 0) { thread_res = -1; return (void *) thread_res; } if (res <= 0) { thread_res = -1; return (void *) thread_res; }
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000); res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 5000);
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >=, 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data")); cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
res = nfc_initiator_deselect_target(device); res = nfc_initiator_deselect_target(device);
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >=, 0, cut_message("Can't deselect target: %s", nfc_strerror(device)));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
return (void *) thread_res; return (void *) thread_res;

View File

@ -66,7 +66,7 @@ target_thread(void *arg)
// 1) nfc_target_init should take target in idle mode // 1) nfc_target_init should take target in idle mode
int res = nfc_target_init(device, &nt, abtRx, sizeof(abtRx), 500); int res = nfc_target_init(device, &nt, abtRx, sizeof(abtRx), 500);
cut_assert_operator_int(res, >= , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >=, 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
// 2) act as target // 2) act as target
@ -92,11 +92,11 @@ target_thread(void *arg)
}; };
sleep(6); sleep(6);
res = nfc_target_init(device, &nt1, abtRx, sizeof(abtRx), 0); res = nfc_target_init(device, &nt1, abtRx, sizeof(abtRx), 0);
cut_assert_operator_int(res, > , 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't initialize NFC device as target: %s", nfc_strerror(device)));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500); res = nfc_target_receive_bytes(device, abtRx, sizeof(abtRx), 500);
cut_assert_operator_int(res, > , 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't receive bytes from initiator: %s", nfc_strerror(device)));
const uint8_t abtAttRx[] = "Hello DEP target!"; const uint8_t abtAttRx[] = "Hello DEP target!";
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data")); cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
@ -104,7 +104,7 @@ target_thread(void *arg)
const uint8_t abtTx[] = "Hello DEP initiator!"; const uint8_t abtTx[] = "Hello DEP initiator!";
res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500); res = nfc_target_send_bytes(device, abtTx, sizeof(abtTx), 500);
cut_assert_operator_int(res, > , 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't send bytes to initiator: %s", nfc_strerror(device)));
if (res <= 0) { thread_res = -1; return (void *) thread_res; } if (res <= 0) { thread_res = -1; return (void *) thread_res; }
// 3) idle mode // 3) idle mode
@ -144,7 +144,7 @@ initiator_thread(void *arg)
// Passive mode / 106Kbps // Passive mode / 106Kbps
printf("=========== INITIATOR %s (Passive mode / 106Kbps) =========\n", nfc_device_get_name(device)); printf("=========== INITIATOR %s (Passive mode / 106Kbps) =========\n", nfc_device_get_name(device));
res = nfc_initiator_poll_dep_target(device, NDM_PASSIVE, NBR_106, NULL, &nt1, 5000); res = nfc_initiator_poll_dep_target(device, NDM_PASSIVE, NBR_106, NULL, &nt1, 5000);
cut_assert_operator_int(res, > , 0, cut_message("Can't select any DEP target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >, 0, cut_message("Can't select any DEP target: %s", nfc_strerror(device)));
cut_assert_equal_int(NMT_DEP, nt1.nm.nmt, cut_message("Invalid target modulation")); cut_assert_equal_int(NMT_DEP, nt1.nm.nmt, cut_message("Invalid target modulation"));
cut_assert_equal_int(NBR_106, nt1.nm.nbr, cut_message("Invalid target baud rate")); cut_assert_equal_int(NBR_106, nt1.nm.nbr, cut_message("Invalid target baud rate"));
cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt1.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3")); cut_assert_equal_memory("\x11\x22\x33\x44\x55\x66\x77\x88\x99\xAA", 10, nt1.nti.ndi.abtNFCID3, 10, cut_message("Invalid target NFCID3"));
@ -155,14 +155,14 @@ initiator_thread(void *arg)
const uint8_t abtTx[] = "Hello DEP target!"; const uint8_t abtTx[] = "Hello DEP target!";
uint8_t abtRx[1024]; uint8_t abtRx[1024];
res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 500); res = nfc_initiator_transceive_bytes(device, abtTx, sizeof(abtTx), abtRx, sizeof(abtRx), 500);
cut_assert_operator_int(res, >= , 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >=, 0, cut_message("Can't transceive bytes to target: %s", nfc_strerror(device)));
const uint8_t abtAttRx[] = "Hello DEP initiator!"; const uint8_t abtAttRx[] = "Hello DEP initiator!";
cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data")); cut_assert_equal_memory(abtAttRx, sizeof(abtAttRx), abtRx, res, cut_message("Invalid received data"));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
res = nfc_initiator_deselect_target(device); res = nfc_initiator_deselect_target(device);
cut_assert_operator_int(res, >= , 0, cut_message("Can't deselect target: %s", nfc_strerror(device))); cut_assert_operator_int(res, >=, 0, cut_message("Can't deselect target: %s", nfc_strerror(device)));
if (res < 0) { thread_res = -1; return (void *) thread_res; } if (res < 0) { thread_res = -1; return (void *) thread_res; }
// 3) As other device should be in idle mode, nfc_initiator_poll_dep_target should return 0 // 3) As other device should be in idle mode, nfc_initiator_poll_dep_target should return 0

View File

@ -1,4 +1,5 @@
SET(UTILS-SOURCES SET(UTILS-SOURCES
nfc-barcode
nfc-emulate-forum-tag4 nfc-emulate-forum-tag4
nfc-jewel nfc-jewel
nfc-list nfc-list
@ -22,7 +23,8 @@ FOREACH(source ${UTILS-SOURCES})
SET(RC_COMMENT "${PACKAGE_NAME} utility") SET(RC_COMMENT "${PACKAGE_NAME} utility")
SET(RC_INTERNAL_NAME ${source}) SET(RC_INTERNAL_NAME ${source})
SET(RC_ORIGINAL_NAME ${source}.exe) SET(RC_ORIGINAL_NAME ${source}.exe)
SET(RC_FILE_TYPE VFT_APP) # RC_FILE_TYPE: VFT_APP
SET(RC_FILE_TYPE 0x00000001L)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/../windows/${source}.rc @ONLY) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/version.rc.in ${CMAKE_CURRENT_BINARY_DIR}/../windows/${source}.rc @ONLY)
LIST(APPEND TARGETS ${CMAKE_CURRENT_BINARY_DIR}/../windows/${source}.rc) LIST(APPEND TARGETS ${CMAKE_CURRENT_BINARY_DIR}/../windows/${source}.rc)
ENDIF(WIN32) ENDIF(WIN32)
@ -40,6 +42,9 @@ FOREACH(source ${UTILS-SOURCES})
LIST(APPEND TARGETS ../contrib/win32/stdlib) LIST(APPEND TARGETS ../contrib/win32/stdlib)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32)
ENDIF(${source} MATCHES "nfc-scan-device") ENDIF(${source} MATCHES "nfc-scan-device")
IF(${source} MATCHES "nfc-read-forum-tag3")
LIST(APPEND TARGETS ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/getopt.c)
ENDIF()
ENDIF(WIN32) ENDIF(WIN32)
ADD_EXECUTABLE(${source} ${TARGETS}) ADD_EXECUTABLE(${source} ${TARGETS})

Some files were not shown because too many files have changed in this diff Show More