Commit Graph
100 Commits
Author SHA1 Message Date
Romain Tartiere 769eef20f7 Merge r520-546 from trunk. 2010-08-18 14:32:01 +00:00
Romain Tartiere f797d737d3 Fix build on Microsoft Windows. 2010-08-16 17:43:48 +00:00
Romain Tartiere 08eb21aa9d Second part of error handling.
- Define two sets of DE<FOOBAR> macros: the first one for 'generic' errors
  which could be encountered regardless of the NFC device the library is acting
  with (0xX000), and ont set for device-dependant errors (0x0X00).
- Make some more functions accept a nfc_device_t* as first argument to have
  access to the iLastError;
- Reset errors when entering public API functions;
- Save errors when applicable;
- Distinguish system-level errors (e.g. I/O error) and operational errors (the
  PCD returns an unexpected value);
- Minor tweaks.

Update issue 65
Status: Feedback

New review:
Owner: rconty@il4p.fr
Cc: rtartiere@il4p.fr
Summary: Review the error-handling code.
Branch: /branches/libnfc-error-handling

For this development, a strong emphasis has been set on making changes that
will not go through our way on the way to libnfc-1.6+.  For this reason, some
constructs are not natural (e.g. error codes defined in two different places),
please keep this in mind when reviewing.
2010-08-15 14:08:29 +00:00
Romain Tartiere 8a75f5b45e Fix wrong comment 2010-08-15 12:42:40 +00:00
Romain Tartiere 655fdb569a Fix nfc_initiator_mifare_cmd() in examples.
In r509, a direct call to pn53x_transceive() was changed into a call to nfc_initiator_transceive_dep_bytes() which is part of the public API. The command to send was updated accordingly, but the code that extracts the response have not.

Update issue 98
This should fix the problem: because the response was not the expected length, the actual card data was not copied to the buffer, so it was always the same 16 uninitialized bytes that where returned for any block.

PR:		Issue 98
Submitted by:	zamby.ing
Pointy hat to:  me
2010-08-13 19:53:13 +00:00
Romain Tartiere fab08a3951 Fix doxygen comment: the string SHALL NOT be freed (it's const BTW).
Or maybe I would rather have removed the const and called strdup(3)?

New issue
Summary: Sync code and comments
Owner: rconty@il4p.fr
Status: New
Romuald, can you please review this changeset and fix the code if I corrected
the wrong way (i.e. the comment was Okay and the code bogus while I fixed the
comment thinking the cod was right).

Thanks!
2010-08-13 19:10:31 +00:00
Romain Tartiere d7e0b926ac Rename the only test of the regression test suite to a more explicit name.
- While here, add assertions, enhance slightly the code and decrease the number of loop turns.
2010-08-13 18:34:30 +00:00
Romain Tartiere 57b775bae2 Always ACK on transmission.
New issue
Summary: Make sending ACK on message transmission skipable.
Owner: rtartiere@il4p.fr
Cc: rtartiere@il4p.fr
Status: New
I guess that for performance reasons, some advance users would prefer to skip
sending the non-mandatory ACK on data transmission.  They may also perform a
quicker check of the ACK returned by the chip after sending the command and
before receiving the response (not sure about this one).

It will probably be a ./configure option disabled by default that allows some "shortcuts" to perform NFC hacking.
2010-08-13 16:02:18 +00:00
Romain Tartiere f4bc39bf41 Mostly revert r521.
It was obviously an April joke: iErrorCode which was renamed iPICCError is
indeed a PCD Error, so I renamed it to iLastError since communications errors are
also to handle at the device driver level (read chip level), although I guess
that some errors would be common to distinct devices.
PICC error are irrelevant because they can either be transmission error
detection (in which case the libnfc should retry the transmission) or
application-level errors the libnfc cannot be aware of.
2010-08-13 09:02:20 +00:00
Romain Tartiere 0502401a29 Minor tweaks.
- Rename the nfc_device_t's struct iErrorCode member to iPICCError (We are
    likely to have both PICC and PCD errors fields to avoid unneeded complexity
    at some point);
  - Make the PN53x error descriptions static;
  - Enhance some comments here and there.
2010-08-13 08:31:16 +00:00
Romain Tartiere b289784359 Merge r511-519 from trunk. 2010-08-11 16:59:09 +00:00
Romain Tartiere 9cc31f6aad Add a regression test directory. 2010-08-11 16:36:35 +00:00
Romain Tartiere caa594eba8 Remove deprecated code.
Reported by:	rconty@il4p.fr
2010-08-11 09:46:14 +00:00
Romain Tartiere f237d44339 Take care of 16-blocks-long sectors of Mifare Classic 4K in the nfc-mfclassic example's blocks counting routine. 2010-08-11 09:26:22 +00:00
Romain Tartiere ca6b768a67 Fix build on Microsoft Windows. 2010-08-10 21:45:30 +00:00
Romain Tartiere 4a5347e5ae Merge r512 from trunk. 2010-08-10 21:41:42 +00:00
Romain Tartiere 3ec0b9376c Make Mifare example use only the libnfc public API. 2010-08-10 21:36:57 +00:00
Romain Tartiere dfb82f8893 Merge r499-510 from trunk. 2010-08-10 21:14:13 +00:00
Romain Tartiere bda739eb8f Hey! r509 also fixed that! 2010-08-10 21:02:26 +00:00
Romain Tartiere eece496351 Use nfc_initiator_transceive_dep_bytes() instead of pn53x_transceive() in example. 2010-08-10 21:00:08 +00:00
Romain Tartiere fd0efd4a62 Fix build on Microsoft Windows.
Windows users: I hate you in secret.
2010-08-10 19:50:29 +00:00
Romain Tartiere 8fef257d16 Also use pn53x_transceive_callback() in the arygon driver.
While here, remove unneeded header in pn532_uart.c.
2010-08-08 15:25:06 +00:00
Romain Tartiere d7c16d6d1a Factorise UART-relative macros definitions. 2010-08-08 09:34:18 +00:00
Romain Tartiere 8e5d235cd2 Implement pn53x_InRelease().
I used it for some experiments and guess that it should be part of the API.
2010-08-06 07:29:57 +00:00
Romain Tartiere d77c25224a After a bazillion tests, make the Debian-5-year-outdated-and-buggy autotools happy with some weird m4 syntax and hope it will not fail on a much more recent autolol suite. 2010-07-31 15:37:27 +00:00
Romain Tartiere d0357cf3aa Merge r486-498 from trunk. 2010-07-31 14:23:33 +00:00
Romain Tartiere 79aeaa6287 Factorise code.
Avoid redundant code in PN53x usb and uart drivers.  Since it makes sense to
report errors at the nfc_device_t level, pass it directly to
pn53x_transceive().

Programs using the libnfc MAY use pn53x_transceive() to communicate with a NFC
device, and SHALL not use anymore pnd->pdc->transceive().  Code in the library
itself SHOULD avoid calling pnd->pdc->transceive(), so such construct have been
updated accordingly.
2010-07-31 14:20:15 +00:00
Romain Tartiere 301d692e8a Flag references to deprecated usage of pn53x_transceive().
New issue
Summary: pn53x_transceive() workaround reverences in examples/nfc-poll.c comments
Status: New
Owner: rconty@il4p.fr
Cc: rtartiere@il4p.fr
The source code of nfc-poll has references to no using pn53x_transceive() for
the status-byte workaround reason in a comment.  However this function is not
called in the code.  While I guess that's some comment that should have been
removed and have never reached the svn repo, I prefer to be sure that it can be
removed.  The comments where introduced at the same time of the file, at r353.
2010-07-31 14:02:46 +00:00
Romain Tartiere b60d045537 Remove another deprecated test that '^#ifdef' did not matched for previous commit. 2010-07-31 13:46:32 +00:00
Romain Tartiere cd53efb038 Enforce ISO C conformance about empty files.
ISO C forbids empty source files.  Instead of compiling possibly empty source
files depending on the compiler parameters, only compile required files to
build the library as requested at the ./configure stage.

Windows users (and more precisely non-autotools users), you may have to update
whatever you use to build the libnfc to fit your needs.  The Makefile shipped
in the windows directory compiles all drivers as it is written so you should
not notice any difference, but if you don't use _that_ makefile, then you will
have to do some adjustment.

For now, keep the defines in CFLAGS just in case.  Planned for removal in circa
one week.

While here, pet `./configure` output (--help format and summary).
2010-07-31 13:21:56 +00:00
Romain Tartiere bb06d45a05 Really silent down gcc with -Wextra. 2010-07-31 12:57:02 +00:00
Romain Tartiere 93494aad24 Fix serial string for FreeBSD.
I am sure we don't have /dev/ttyUSB*, and since I use /dev/cuau0 with a
cross-over cable to connect 2 machines and have a serial console, I guess
"/dev/cuau" is the SERIAL_STRING that's expected to work for me.  A quick test
would be cool however, but I don't own a serial NFC device.
2010-07-31 10:13:18 +00:00
Romain Tartiere d498fcd48e Comment all commands that return a status code in the list. Found a typo at that occasion so s/0x93/0x92/. 2010-07-31 09:50:04 +00:00
Romain Tartiere fb6d9d2d20 Yes we can... remove all those pnd->pdc->transceive() from nfc.c.
Within the ongoing effort to improve the NFC devices abstraction, and now that
pn53x_transceive() does not fail when it reads a response that has no
status-code, do not call directly pnd->pdc->transceive() from nfc.c.  In a
mid-term future this will be changed again, and calling pn53x_transceive() from
nfc.c will be forbiden, in favor of colling some pnd->transceive() function,
but that's another part of the story.

Of course, it changes the API one more and it's not going to be the last time
in this branch.
2010-07-31 09:40:29 +00:00
Romain Tartiere 705e037b12 Only report status error for commands that provide it in pn53x_transceive().
This is the first step for improving abstraction in libnfc.
2010-07-31 09:19:22 +00:00
Romain Tartiere 36ee32f81a Merge r478-485 from trunk. 2010-07-30 16:34:12 +00:00
Romain Tartiere daa178b18f Enhance error handeling.
- New API functions: nfc_strerror(), nfc_strerror_r() and nfc_perror();
  - Drivers now have a reference to chips callback methods;
  - Rename -pn53x_err2string to pn53x_strerror and add it to pn53x_callbacks_list.
2010-07-29 14:16:11 +00:00
Romain Tartiere 30e715cff0 Merge r470-477 from trunk. 2010-07-29 10:59:52 +00:00
Romain Tartiere 740b5b430d libnfc-error-handling: Remove boring debug stuff. 2010-07-29 10:53:14 +00:00
Romain Tartiere f01b73ab32 Move usb_reset(3) call.
As the documentation states, and as reported in isssue 81 (fixed in r421),
usb_reset()'s argument is invalid after the call and so usb_close(3) must be
called before usb_reset(3).
2010-07-29 10:47:53 +00:00
Romain Tartiere 9984e1bdcb Start of work on error handling. 2010-07-26 12:41:46 +00:00
Romain Tartiere af584bd474 Fix packet length checksum computation.
The doc says LCS (aka abtTx[4]) must be set so that the lower byte of LCS+LEN
(aka abtTx[3]) is 0x00.  This has not to be related to the USB buffer size, so
that we can adjust it without breaking down the libnfc.
2010-07-25 16:31:53 +00:00
Romain Tartiere 7f9f907bc2 Silent down compiler. 2010-07-24 18:54:50 +00:00
Romain Tartiere e6d079d87a Fix a regression introduced at r461.
This prevents the ATR_REQ from being processed and some tags detection fails in
libfreefare.
2010-07-24 17:20:48 +00:00
Romain Tartiere 4ff66d125f Fix a regression introduced at r458.
Both abtInit and szInitLen are initialised using pbtInitData and szInitDataLen,
so we must use them when calling pn53x_InListPassiveTarget().
2010-07-24 16:30:44 +00:00
Romain Tartiere 7945dd18fa Enhance 'make indent'.
- Complete indent(1)'s arguments list;
  - Ensure files to be indented have no local edit;
  - Hide indent command-line details.  Since everything is static, no need for V=1 support.
2010-07-21 22:32:02 +00:00
Romain Tartiere 67fb1330f8 Rework the indent target.
- Check indent is present at ./configure stage;
  - If gindent(1) is installed, use it instead of indent(1);
2010-07-21 13:09:48 +00:00
Romain Tartiere d8f12035fc Add missing carriage return at EOF (yes, I have nothing better to do ATM). 2010-06-26 21:56:32 +00:00
Romain Tartiere 9941191cfc Fix build when configured with --enable-debug. 2010-04-28 12:55:00 +00:00
Romain Tartiere 16786c61e3 Remove bitutils I reverted instead of removing in r412. 2010-04-26 13:20:57 +00:00
Romain Tartiere b28abd77b0 Merge the libnfc-less-bitutils-more-ponies branch into trunk. 2010-04-26 13:13:13 +00:00
Romain Tartiere 00af8b7ae1 Fix ${DRIVERS_SOURCES} modifications. 2010-04-26 13:05:21 +00:00
Romain Tartiere 204130477e (libnfc-less-bitutils-more-ponies) MFT 2010-04-17 13:45:00 +00:00
Romain Tartiere be3f152d3c Fix a few more warnings. 2010-04-17 13:42:08 +00:00
Romain Tartiere 086e24c407 (libnfc-less-bitutils-more-ponies) Fix build on windows:
- do not depends on byte swapping functions / macros;
  - add basic err.h functionalities.
2010-04-16 22:38:45 +00:00
Romain Tartiere 3e8e1c8844 Fix build on Windows (using cmake and nmake). 2010-04-16 20:39:56 +00:00
Romain Tartiere 3820c34f28 (libnfc-less-bitutils-more-ponies) MFT 2010-04-16 19:27:49 +00:00
Romain Tartiere 0e6719908b (libnfc-less-bitutils-more-ponies) Update CMakeLists.txt. 2010-04-16 17:42:00 +00:00
Romain Tartiere 3dccc218df Enable drivers in cmake again (disabled implicitly in r375). 2010-04-16 17:35:00 +00:00
Romain Tartiere 39761badb7 Fix cmake breakage introduced in r360:
undefined reference to `print_nfc_iso14443a_info'
2010-04-16 17:20:22 +00:00
Romain Tartiere 5e452dbb13 Fix cmake breakage introduced in r352:
error: 'for' loop initial declaration used outside C99 mode
2010-04-16 17:10:08 +00:00
Romain Tartiere 10baef235f (libnfc-less-bitutils-more-ponies) Get rid of bitutils.[hc] (part 1).
- New API function append_iso14443a_crc();
  - Add a PRINT_HEX macro for driver debugging (replaces print_hex function from bitutils.c);
  - Move bit-mirroring related functions to libnfc/mirror-subr.[hc];
  - Move iso14443 related functions to libnfc/iso14443-subr.c;
  - Move libnfc/bitutils.c hex-dumping code to examples/nfc-utils.c;
  - Replace calls to swap_endian32() and swap_endian64() functions with calls to bswap32() and bswap64 provided by endian.h.

And while I am here:
  - Fix the DBG macro so that it does not throw warning at compile time.
2010-04-16 16:38:57 +00:00
Romain Tartiere 5302930b09 Avoid using a 'comma pasting' GNU extension (non-portable, reported my clang).
This is not a 'complete' fix since the DBG macro is still using it; but more globally, this file should not be part of the libnfc installed files.  We should rely on error codes and maybe some logging mechanism (e.g. syslog() on POSIX compliant systems and RegisterEventSource() / ReportEvent() on Windows).
2010-04-16 14:50:48 +00:00
Romain Tartiere 0b301d8ff6 Add missing documentation lines. 2010-04-16 13:00:33 +00:00
Romain Tartiere 7b65174856 Remove deprecated DEBUG_CFLAGS. 2010-04-16 12:58:29 +00:00
Romain Tartiere 4dbeff47db Fix warnings on 32bit systems:
- format '%ld' expects type 'long int', but argument 2 has type 'unsigned int';
  - format '%ld' expects type 'long int', but argument 2 has type 'size_t'.

Tested on FreeBSD arm.
2010-04-15 23:11:36 +00:00
Romain Tartiere ae99d155b5 Make nfc-list rely on the libnfcutils.a convenience library and call nfc_initiator_select_tag(). 2010-04-09 22:08:17 +00:00
Romain Tartiere b8630c4230 Fix various warnings:
- format '%d' expects type 'int', but argument 2 has type 'long unsigned int';
  - format '%d' expects type 'int', but argument 2 has type 'size_t';
  - unused variable 'nti';
  - unused parameter 'argc'.
2010-04-09 22:03:52 +00:00
Romain Tartiere ee3715e267 Add convenience library infrastructure and move the print_nfc_iso14443a_info() function away from bitutils. 2010-04-09 21:57:03 +00:00
Romain Tartiere 5473befa13 Fix a brunch of -Wextra warnings:
- 'static' is not at beginning of declaration;
  - unused parameter;
  - comparison between signed and unsigned.
2010-04-07 15:08:04 +00:00
Romain Tartiere c7d77d7664 Rearrange source code. 2010-04-07 14:37:19 +00:00
Romain Tartiere c4c7fa236a Attempt to be able to compile using manual makefile AND with CMake (missing parts from r332) 2010-04-06 17:55:12 +00:00
Romain Tartiere 09d2fff619 Add another missing CMakeLists.txt in autotooled tarball. 2010-04-03 12:06:50 +00:00
Romain Tartiere 22d4ea3207 Add missing CMakeLists.txt in autotooled tarball. 2010-04-03 12:03:24 +00:00
Romain Tartiere 667ba72dbd Strip CT (Cascade Tag) from UIDs in nfc_initiator_select_tag(). 2010-03-30 16:05:01 +00:00
Romain Tartiere f20a681315 Prevent the Windows installer from installing manual pages. 2010-03-23 10:00:48 +00:00
Romain Tartiere f372104163 Fix build on Windows when using CMake (Tested on Windows XP SP3 with WinSDK 7) 2010-03-22 20:34:02 +00:00
Romain Tartiere b3b3f47876 - Sync libnfc version in CMake with the one in the autotools;
- Only add gcc-specific options when using gcc.
2010-03-22 20:28:30 +00:00
Romain Tartiere e223b93d91 The obsolete function usleep(3) also needs _XOPEN_SOURCE >= 500. 2010-02-20 13:01:43 +00:00
Romain Tartiere b67dbe668b Honour ctype(3) caveats section. 2010-02-17 14:36:33 +00:00
Romain Tartiere 9bafef8d88 Include pn53x.conf in libnfc tarballs since pn53x.rules is in it too. 2010-02-16 14:09:35 +00:00
Romain Tartiere 219d5657e8 Add devd(8) rules to change USB devices permissions when they are plugged-in on FreeBSD. 2010-02-16 14:06:56 +00:00
Romain Tartiere 386597af6e Define _NETBSD_SOURCE that makes a few more serial speeds defined in termios.h. 2010-02-10 13:46:12 +00:00
Romain Tartiere 0d395733af Fix indent after last commit. 2010-02-10 11:23:38 +00:00
Romain Tartiere c8c03fe2e0 Do not add libusb to PKG_CONFIG_REQUIRES unless it is located using this method. Fix build failure for software detecting libnfc using pkg-config on FreeBSD (at least) when libusb is part of the system. 2010-02-10 11:23:01 +00:00
Romain Tartiere 1e0272d006 Make configure fail if pkg-config cannot be found. 2010-02-08 19:43:25 +00:00
Romain Tartiere 3914cf7eac Fix build on NetBSD. 2010-02-08 19:40:41 +00:00
Romain Tartiere 10183ffd22 ATM, there is no particular reason to keep O_NDELAY in open(2) flags (not defined by POSIX, BTW), but a particular reason to suppress it: it breaks build on FreeBSD. 2010-01-28 15:46:55 +00:00
Romain Tartiere 19672806d2 Fix some more cc warnings. 2010-01-28 15:42:50 +00:00
Romain Tartiere 4669279589 Add missing header. Fix build at least on FreeBSD 7.2.
Reported by:	tinderbox
2010-01-28 14:32:23 +00:00
Romain Tartiere 7d20198520 Tweak the libusb detection.
1. Try to use pkg-config to locate libusb;
  2. Try with libusb-config if not found;
  3. Try to locate headers and lib if still not found.

This would hopefully prevent build failures in some very particular cases, such as cross compiling libnfc on a FreeBSD version for another FreeBSD version that does not use the same libusb.

http://www.freebsd.org/cgi/query-pr.cgi?pr=ports/142836

Reported by:	Dmitry Marakasov
2010-01-28 13:56:04 +00:00
Romain Tartiere e92de4d49e Ensure UART file descriptors are valid before using them in uart_close ().
The uart_open() function may call uart_close() with a 'serial_port' structure with an invalid member 'fd' if the port was not opened successfully.  The call to uart_close() was kept for consistency with the rest of the function because uart_close() is also in charge of freeing 'serial_port'.
2010-01-15 10:38:50 +00:00
Romain Tartiere 3f8068b760 Include "config.h" at the beginning of all source code, remove it from headers.
While here distinguish licence comments using the /*- special comment delimiter.
2010-01-15 10:18:11 +00:00
Romain Tartiere 31597117a2 Update the ChangeLog entry of FreeBSD support (libnfc has not been run on a "today current" -CURRENT FreeBSD system. It's smooth on -STABLE BTW).
While here, fix a typo and adjust style for consistency.
2010-01-06 10:24:49 +00:00
Romain Tartiere 73448612af Increase _XOPEN_SOURCE to 600.
The snprintf() function conforms to C99.  On FreeBSD, sys/cdefs.h instruct us that _XOPEN_SOURCE == 500 defines _POSIX_C_SOURCE as 199506 which in turn defines __ISO_C_VISIBLE as 1990.  600 is the minimal _XOPEN_SOURCE value we can use to allow us using C99 functions.

Reported by:	tinderbox
2009-12-23 12:01:40 +00:00
Romain Tartiere e0fab1c9a7 Add stdlib.h header where applicable (where we call malloc() / free()).
Reported by:	tinderbox
2009-12-23 11:56:56 +00:00
Romain Tartiere aa7d7171c8 Sync libnfc.pc includedir with the rest of the project source files.
When I introduced headers separation (aka includes-revamp branch), the libnfc source code includes have been changed from '#include "../xx/nfc*.h"' to '#include <nfc/nfc*>' (when compiling, the source include dir (src/include) has precedence over '${prefix}/include').  For the sake of consistency, update libnfc.pc includedir so that compiling third party code using '#include <nfc/nfc*>' just works (tm).  This provides much more consistent headers since they are usually referred relative to the includedir (exceptions are e.g. glib, gtk, xorg... quite bigger than libnfc I could say).
2009-12-22 21:02:19 +00:00
Romain Tartiere 61a0aba66e Make use of the new AM_SILENT_RULES macro of automake 1.11 if possible.
We can see warnings again!
2009-12-16 23:16:21 +00:00
Romain Tartiere 462d986633 Free memory allocated by pick_device() once we are connected to the device in nfc_connect(). 2009-12-16 23:14:31 +00:00
Romain Tartiere 86dac7a4bb Do not call drivers' connect() function if pick_device() returns NULL. 2009-12-03 02:08:40 +00:00