Commit graph

2181 commits

Author SHA1 Message Date
Philippe Teuwen
4769392157 Fix cppcheck style: scope of variable can be reduced
Fix the following cppcheck warnings:
[libnfc/drivers/pn532_uart.c:492]: (style) The scope of the variable 'res' can be reduced
[libnfc/chips/pn53x.c:320]: (style) The scope of the variable 'res' can be reduced
[libnfc/chips/pn53x.c:616]: (style) The scope of the variable 'res' can be reduced
[libnfc/nfc.c:356]: (style) The scope of the variable '_device_found' can be reduced
[utils/nfc-mfclassic.c:178]: (style) The scope of the variable 'key_index' can be reduced
2013-03-06 00:35:36 +01:00
Philippe Teuwen
3f5a3fd58f nfc-read-forum-tag3 & nfc-relay-picc: remove unused variable
Fix cppcheck warnings
[utils/nfc-read-forum-tag3.c:281]: (style) Variable 'len' is assigned a value that is never used
[utils/nfc-relay-picc.c:392]: (style) Variable 'res' is assigned a value that is never used
2013-03-06 00:30:38 +01:00
Philippe Teuwen
4822bb3e42 Fix bug introduced in some signal traps where context was not declared 2013-03-05 23:58:35 +01:00
Philippe Teuwen
03bc30f116 Fix "Possible null pointer dereference" error 2013-03-05 23:56:38 +01:00
Philippe Teuwen
e55efd6db0 examples/utils: add nfc_exit() to signal traps
and one missing nfc_abort_command()
2013-03-05 22:50:37 +01:00
Philippe Teuwen
73b5c9d0af nfc_init() return rather than exit on malloc error, examples fixed accordingly 2013-03-05 22:24:59 +01:00
Philippe Teuwen
ae6062e5ba nfc_context_new(): replace err() by return, problem still in nfc_init()!!
Not a good idea to call exit() from a library...
Problem is now moved to
void nfc_init() calling exit()
This requires a change in API to return error rather than exiting...
2013-03-05 20:03:19 +01:00
Philippe Teuwen
09ef2e3927 nfc_device_new(): replace err() by return
Not a good idea to call exit() from a library...
2013-03-05 19:58:32 +01:00
Philippe Teuwen
bece73faaf Error conditions in utils & examples: fix leaks, unify style (see details)
* in main():
** errx()/err()/return -> exit()
** return values -> EXIT_SUCCESS & EXIT_FAILURE

* out of main:
** err()/errx()/exit() -> return
** change retval from size_t to int to allow returning errors
** don't use EXIT_SUCCESS / EXIT_FAILURE as retvals

* add nfc_close() & nfc_exit() to exit() on errors
* add missing fclose() on errors
* add missing test if (pnd == NULL)
* unify style if (pnd == / != NULL)
* remove goto's
* few related fixes
* remove if(pnd!=NULL) test on nfc_close() calls
2013-03-05 19:44:59 +01:00
Philippe Teuwen
232930c3d5 Fix resource leaks detected by cppcheck
[examples/pn53x-tamashell.c:94]: (error) Resource leak: input
[utils/nfc-mfultralight.c:264]: (error) Resource leak: pfDump
2013-03-04 01:06:16 +01:00
Ludovic Rousseau
1de1832562 Add lintian options
More options for more warnings or mode details.
2013-03-03 18:49:39 +01:00
Philippe Teuwen
b0f216b3b2 spi driver: remove compilation warnings
spi_posix.c:141:1: warning: no previous prototype for 'bit_reversal' [-Wmissing-prototypes]
=> set bit_reversal() static

pn532_spi.c:258:48: warning: unused parameter 'timeout' [-Wunused-parameter]
=> remove timeout in pn532_spi_read_spi_status() params
2013-03-03 16:24:10 +01:00
Philippe Teuwen
cd98a4ac87 make style 2013-03-03 16:14:58 +01:00
Philippe Teuwen
2ac7963076 Merge branch 'master' into pn532_spi 2013-03-03 16:10:11 +01:00
Philippe Teuwen
9a20430bfc Prepare release 1.7.0 RC6 2013-03-03 15:34:35 +01:00
Philippe Teuwen
d143eba7ad Edit ChangeLog 2013-03-03 01:04:01 +01:00
Philippe Teuwen
b68a37b835 Replace usb_set_debug() in utils by new group in LIBNFC_LOG_LEVEL
To use it: (NFC_LOG_PRIORITY_DEBUG * 2 ^ NFC_LOG_GROUP_LIBUSB)
LIBUSB_LOG_LEVEL=12288
2013-03-02 23:43:37 +01:00
Philippe Teuwen
b1448f6785 nfc-mfclassic: add option to tolerate RW errors & other enhancements
Reconciliate read & write operations.
Add option to tolerate or not RW failures.
Print success/failure for each block as ACL is per block.
2013-03-02 22:29:10 +01:00
Philippe Teuwen
ddd7cabda8 Edit HACKING & introduce clang (thanks Ludovic!) 2013-03-02 19:46:17 +01:00
Philippe Teuwen
2334adc8bd Fix compilation warnings: values never read
Fixes:
pn53x.c:523:11: warning: Value stored to 'pbtRawData' is never read
          pbtRawData += szRawData - 8;
          ^             ~~~~~~~~~~~~~
pn53x.c:544:7: warning: Value stored to 'pbtRawData' is never read
      pbtRawData += 2;
      ^             ~
pn53x.c:532:7: warning: Value stored to 'pbtRawData' is never read
      pbtRawData += 8;
      ^             ~
pn53x.c:3085:3: warning: Value stored to 'buflen' is never read
  buflen -= res;
  ^         ~~~
pn53x.c:3080:3: warning: Value stored to 'buf' is never read
  buf += res;
  ^      ~~~
target-subr.c:466:7: warning: Value stored to 'dst' is never read
      dst += sprintf(dst, "* Unknown card, sorry\n");
      ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
target-subr.c:480:3: warning: Value stored to 'dst' is never read
  dst += sprint_hex(dst, nfi.abtSysCode, 2);
  ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
target-subr.c:490:3: warning: Value stored to 'dst' is never read
  dst += sprint_hex(dst, nji.btId, 4);
  ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
target-subr.c:546:7: warning: Value stored to 'dst' is never read
      dst += sprintf(dst, "\n");
      ^      ~~~~~~~~~~~~~~~~~~
target-subr.c:571:5: warning: Value stored to 'dst' is never read
    dst += sprint_hex(dst, nii.abtAtr, nii.szAtrLen);
    ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
target-subr.c:580:3: warning: Value stored to 'dst' is never read
  dst += sprint_hex(dst, nsi.abtUID, 8);
  ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
target-subr.c:593:3: warning: Value stored to 'dst' is never read
  dst += sprintf(dst, "           Fab Code: %02X\n", nci.btFabCode);
  ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
target-subr.c:608:5: warning: Value stored to 'dst' is never read
    dst += sprint_hex(dst, ndi.abtGB, ndi.szGB);
    ^      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2013-03-02 19:39:20 +01:00
Philippe Teuwen
70b0dffca7 acr122_usb: fix compiler warnings & check return value
acr122_usb.c:570:3: warning: Null pointer passed as an argument to a 'nonnull' parameter
  memcpy(DRIVER_DATA(pnd)->apdu_frame.apdu_payload, data, data_len);
  ^                                                 ~~~~
acr122_usb.c:738:3: warning: Value stored to 'offset' is never read
  offset += len;
  ^         ~~~
acr122_usb.c:753:3: warning: Value stored to 'res' is never read
  res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char *) & (DRIVER_DATA(pnd)->tama_frame), res, 1000);
  ^     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2013-03-02 19:25:36 +01:00
Ludovic Rousseau
bd8a9fe96e Remove dead code
The local variable bFailure is set before a return.

nfc-mfclassic.c:319:11: warning: Value stored to 'bFailure' is never read
          bFailure = true;
          ^          ~~~~
2013-03-02 13:24:12 +01:00
Philippe Teuwen
f07d784b8b make style 2013-03-02 13:17:57 +01:00
Ludovic Rousseau
999631588d closedir() only if opendir() succeeds
Fix compiler warning:
conf.c:186:3: warning: Null pointer passed as an argument to a 'nonnull' parameter
  closedir(d);
  ^        ~
2013-03-02 13:11:30 +01:00
Ludovic Rousseau
aee56b9255 Initialize variables
Fix compiler warnings and potential bug

pn53x.c:1526:19: warning: The right operand of '<' is a garbage value
    for (i = 0; i < sz; i++) {
                  ^ ~~
pn53x.c:1621:19: warning: The right operand of '<' is a garbage value
    for (i = 0; i < sz; i++) {
                  ^ ~~
2013-03-02 13:09:23 +01:00
Philippe Teuwen
abf54c7598 Debian: remove non-exported symbol 2013-03-02 12:55:43 +01:00
Philippe Teuwen
ae571941c5 usbbus: make usb_initialized static 2013-03-02 12:43:15 +01:00
Philippe Teuwen
1f0b0e5b81 Fix zealous double free 2013-03-02 12:26:24 +01:00
Ludovic Rousseau
e7290de83b Fix compiler warning
nfc.c:121: warning: function declaration isn't a prototype
nfc.c: In function 'nfc_drivers_init':
nfc.c:121: warning: old-style function definition
2013-03-02 11:30:24 +01:00
Romuald Conty
3aadb45988 Ease diff between both libusb based drivers: acr122_usb and pn53x_usb 2013-03-02 10:59:37 +01:00
Philippe Teuwen
b2b1d2a2a2 make style 2013-03-02 02:52:07 +01:00
Philippe Teuwen
a6c405a5d5 malloc/free: some more cleaning & checking malloc errors 2013-03-02 02:51:33 +01:00
Philippe Teuwen
0708279215 malloc/free: some cleaning & checking malloc errors 2013-03-02 02:25:13 +01:00
Philippe Teuwen
35b08dc5cc Add new symbols from usbbus.c 2013-03-02 01:39:59 +01:00
Philippe Teuwen
d7e7abb061 Fix mem leak in config file parser (opendir)
This fixes the following leaks:

==30517== 32,808 bytes in 1 blocks are definitely lost in loss record 11 of 12
==30517==    at 0x4C28BED: malloc (vg_replace_malloc.c:263)
==30517==    by 0x50F4B2A: __alloc_dir (opendir.c:186)
==30517==    by 0x4E34998: conf_devices_load.constprop.1 (in /usr/lib/x86_64-linux-gnu/libnfc.so.4.0.0)
==30517==    by 0x4E36350: nfc_context_new (in /usr/lib/x86_64-linux-gnu/libnfc.so.4.0.0)
==30517==    by 0x4E34D98: nfc_init (in /usr/lib/x86_64-linux-gnu/libnfc.so.4.0.0)
2013-03-02 01:21:13 +01:00
Philippe Teuwen
3d9ebb5044 Fix mem leak in config file parser
This fixes the following leaks:

==18690== 256 bytes in 1 blocks are definitely lost in loss record 75 of 100
==18690==    at 0x4C28BED: malloc (vg_replace_malloc.c:263)
==18690==    by 0x511613F: regcomp (regcomp.c:487)
==18690==    by 0x4E34313: conf_parse_file (in /usr/lib/x86_64-linux-gnu/libnfc.so.4.0.0)
==18690==    by 0x4E349F5: conf_devices_load.constprop.1 (in /usr/lib/x86_64-linux-gnu/libnfc.so.4.0.0)
==18690==    by 0x4E362C0: nfc_context_new (in /usr/lib/x86_64-linux-gnu/libnfc.so.4.0.0)
==18690==    by 0x4E34D08: nfc_init (in /usr/lib/x86_64-linux-gnu/libnfc.so.4.0.0)
==18690==
==18690== 32,068 (224 direct, 31,844 indirect) bytes in 1 blocks are definitely lost in loss record 98 of 100
==18690==    at 0x4C28BED: malloc (vg_replace_malloc.c:263)
==18690==    by 0x4C28D6F: realloc (vg_replace_malloc.c:632)
==18690==    by 0x5115DF3: re_compile_internal (regcomp.c:760)
==18690==    by 0x51161AB: regcomp (regcomp.c:506)
==18690==    by 0x4E34313: conf_parse_file (in /usr/lib/x86_64-linux-gnu/libnfc.so.4.0.0)
==18690==    by 0x4E349F5: conf_devices_load.constprop.1 (in /usr/lib/x86_64-linux-gnu/libnfc.so.4.0.0)
==18690==    by 0x4E362C0: nfc_context_new (in /usr/lib/x86_64-linux-gnu/libnfc.so.4.0.0)
==18690==    by 0x4E34D08: nfc_init (in /usr/lib/x86_64-linux-gnu/libnfc.so.4.0.0)
2013-03-02 01:09:47 +01:00
Philippe Teuwen
9dcf7378b6 Fix mem leak with libusb by introducing buses/usbbus.c
Now call only once usb_init(); usb_find_busses(); usb_find_devices()
instead of multiple calls in several scan() then open()

This fixes the following leaks:

==1159== 8 bytes in 1 blocks are definitely lost in loss record 9 of 102
==1159==    at 0x4C28BED: malloc (vg_replace_malloc.c:263)
==1159==    by 0x53D9931: usb_parse_configuration (in /lib/x86_64-linux-gnu/libusb-0.1.so.4.4.4)
==1159==    by 0x53DB8B1: usb_os_find_devices (in /lib/x86_64-linux-gnu/libusb-0.1.so.4.4.4)
==1159==    by 0x53D8FDC: usb_find_devices (in /lib/x86_64-linux-gnu/libusb-0.1.so.4.4.4)
==1159==    by 0x4E41D79: pn53x_usb_scan (in /usr/lib/x86_64-linux-gnu/libnfc.so.4.0.0)
==1159==
==1159== 8 bytes in 1 blocks are definitely lost in loss record 10 of 102
==1159==    at 0x4C28BED: malloc (vg_replace_malloc.c:263)
==1159==    by 0x53D9931: usb_parse_configuration (in /lib/x86_64-linux-gnu/libusb-0.1.so.4.4.4)
==1159==    by 0x53DB8B1: usb_os_find_devices (in /lib/x86_64-linux-gnu/libusb-0.1.so.4.4.4)
==1159==    by 0x53D8FDC: usb_find_devices (in /lib/x86_64-linux-gnu/libusb-0.1.so.4.4.4)
==1159==    by 0x4E42CC7: pn53x_usb_open (in /usr/lib/x86_64-linux-gnu/libnfc.so.4.0.0)
==1159==    by 0x4E351E6: nfc_open (in /usr/lib/x86_64-linux-gnu/libnfc.so.4.0.0)
2013-03-02 01:08:07 +01:00
Romuald Conty
59227c3dd3 Adds missing version.rc.in file in tarball (for Windows users) 2013-03-01 17:11:16 +01:00
Romuald Conty
2506ee35f6 Fixes invalid example in nfc-scan-device manpage 2013-03-01 17:07:40 +01:00
Romuald Conty
3e87abe88a Uses new email for bugs, reports, etc. 2013-03-01 17:07:40 +01:00
Romuald Conty
e070decd3c Updates ChangeLog with recent fixes 2013-03-01 17:07:22 +01:00
Romuald Conty
3dd58e872a Missing release date in ChangeLog 2013-03-01 17:07:22 +01:00
Eugeny Boger
d9fd9155ea Adding a SPI driver for pn532
The driver seems to work well.
I tested it on Linux with i.mx233-based board using hardware SPI.
I tried to modify the build files as well, but it's probably a little messy.
I'm not sure whether it will work on other *nix OSes,
so it's probably better to limit the driver to Linux only using build system.
2013-02-28 23:24:42 +01:00
Philippe Teuwen
a0ebd8ba15 Fix warning in tests: Variable might get clobbered by 'longjmp' or 'vfork' 2013-02-22 22:30:44 +01:00
Philippe Teuwen
7e3549819e Split --disable-conf into --disable-conffiles & --disable-envvars 2013-02-22 21:53:16 +01:00
Ahti Legonkov
fd6d4db5b7 Make it possible to disable conf.
Now the configure script has --disable-conf command-line argument
that can be used to turn off environment variables and use of
configuration files.
2013-02-22 21:09:46 +01:00
Philippe Teuwen
72b10c5d9b Fix warnings: ignoring return value of 'pipe' & discarding const qualifier 2013-02-21 23:20:28 +01:00
Philippe Teuwen
24e1edd858 make style 2013-02-21 22:39:39 +01:00
Philippe Teuwen
5ced93fcbf Makefile.am: move header files from noinst_HEADERS to _SOURCES
Ensures proper recompilation when a header file is edited.
cf https://www.gnu.org/software/automake/manual/html_node/Headers.html
2013-02-21 22:37:20 +01:00
Philippe Teuwen
7af127ac0d pn53x-tamashell: allow larger commands up to full extended frame (264 bytes)
It was arbitrarily limited to MAX_FRAME_LEN-10 probably because of bug in LOG_HEX() fixed in previous commit
2013-02-21 22:36:23 +01:00