Commit graph

266 commits

Author SHA1 Message Date
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
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
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
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
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
Philippe Teuwen
04ef5ca902 Reduce variables scopes 2017-02-18 22:20:15 +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
e4df2f3334 astyle 2017-02-18 13:05:59 +01:00
Philippe Teuwen
c5e8adc169 mfclassic: avoid hardcoded offsets & sizes 2017-02-17 11:31:13 +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
295c70911a Restrict MFC Mini detection according to AN10833 2017-02-16 22:31:10 +01: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
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
Simon Yorkston
8de7ce3899 Adding support for UL Gen 2 Badges 2016-04-09 01:32:14 +10: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
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
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
Marcos Vives Del Sol
5a08fcf2bc Fix "undefined reference"s 2015-02-22 13:27:13 +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
db4fae9c2c Remove unreachable statements
As seen with clang -Wunreachable-code
2014-03-04 01:39:12 +01:00
Philippe Teuwen
a7649da2b0 nfc-read-forum-tag3: add -q and document -o - 2014-02-18 00:22:24 +01:00
Philippe Teuwen
2aa4b99b7b nfc-read-forum-tag3: full parsing of NDEF Attribute Block 2014-02-17 23:57:59 +01:00
Pim 't Hart
73c84c214d nfc-read-forum-tag3: fix incomplete NDEF retrieval and size of output file 2014-02-17 23:09:15 +01:00
Philippe Teuwen
491db20d54 nfc-jewel: remove extraneous parentheses to silence warning 2014-02-11 23:23:42 +01:00
Philippe Teuwen
766ed55c79 nfc-jewel: fix out-of-bounds array access
Defect(s) Reported-by: Coverity Scan
** CID 1169884:  Out-of-bounds read  (OVERRUN)
/utils/nfc-jewel.c: 186 in write_card()
2014-02-07 23:09:40 +01:00
Pim 't Hart
ef81f06344 Adding nfc-jewel util 2014-02-03 00:04:08 +01:00
Philippe Teuwen
7a30e35496 nfc-mfclassic: update help & man page 2014-01-28 00:22:33 +01:00
Philippe Teuwen
4817a6e5c9 make style 2013-12-02 22:55:10 +01:00
Philippe Teuwen
b8e0eec91d nfc-mfclassic: initialize always bFormatCard 2013-11-12 00:43:25 +01:00
Adam Laurie
250068462b add format/wipe command to nfc-mfclassic 2013-11-11 22:03:09 +00:00
Philippe Teuwen
117b58f501 nfc-read-forum-tag3: avoid passing large struct as parameter
Problem reported by Coverity:
CID 1090334 (#1 of 1): Big parameter passed by value (PASS_BY_VALUE)
  pass_by_value: Passing parameter nt of type nfc_target const (size 291 bytes) by value.
2013-09-22 18:32:47 +02:00
Philippe Teuwen
cedbefb880 nfc-relay-picc: sleep() expects unsigned int
This avoids Coverity being unhappy that only lower bound was defined, well I hope

lower_bounds: Checking lower bounds of signed scalar "waiting_time" by "waiting_time > 0".
CID 1090343 (#1 of 1): Untrusted value as argument (TAINTED_SCALAR)
  tainted_data: Passing tainted variable "waiting_time" to a tainted sink.
  sleep(waiting_time);
2013-09-22 03:00:58 +02:00
Philippe Teuwen
61884967ea nfc-mfclassic: verify return of nfc_initiator_select_passive_target()
Problem reported by Coverity:
CID 1090323 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_initiator_select_passive_target(pnd, nmMifare, nt.nti.nai.abtUid, nt.nti.nai.szUidLen, NULL)".
2013-09-22 02:45:23 +02:00
Philippe Teuwen
a4f466df06 Verify return of nfc_device_set_property_bool()
Problem reported by Coverity:
CID 1090325 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(pnd, NP_AUTO_ISO14443_4, false)".
2013-09-22 02:41:11 +02:00
Philippe Teuwen
679897d0a1 nfc-emulate-forum-tag4: fix TOCTOU
Hopefully fix TOCTOU by calling fopen() before stat()

At least this should prevent Coverity to complain about it:
CID 1090346 (#1 of 1): Time of check time of use (TOCTOU)
  fs_check_call: Calling function "stat(char const *, struct stat *)" to perform check on "filename".
  toctou: Calling function "fopen(char const * restrict, char const * restrict)" that uses "filename" after a check function. This can cause a time-of-check, time-of-use race condition.

Note that it seems pretty hard to avoid completely:
https://en.wikipedia.org/wiki/Time_of_check_to_time_of_use#Preventing_TOCTTOU
2013-09-22 02:29:07 +02:00
Philippe Teuwen
feb5f37aa3 nfc-read-forum-tag3: remove redundant error
switch case was redundant as getopt was already telling the issue:

  nfc-read-forum-tag3: option requires an argument -- 'o'
  Option -o requires an argument.

This fixes also a problem reported by Coverity about missing break:

CID 1090330 (#1 of 1): Missing break in switch (MISSING_BREAK)
  unterminated_case: This case (value 63) is not terminated by a 'break' statement.
2013-09-22 02:14:08 +02:00
Philippe Teuwen
d9b531f50f Verify return of nfc_device_set_property_bool()
Problem reported by Coverity
CID 1090319 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, nt.nti.nai.btSak & 0x20)".
CID 1090320 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(dev, NP_HANDLE_CRC, false)".
CID 1090324 (#1 of 2): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, true)".
CID 1090325 (#1 of 1): Unchecked return value (CHECKED_RETURN)
  unchecked_value: No check of the return value of "nfc_device_set_property_bool(pnd, NP_AUTO_ISO14443_4, false)".
2013-09-22 01:31:45 +02:00
Ludovic Rousseau
107b4ece8b Fix use after free bug
nfc_exit(context); was called 2 times

CID 1090348 (#1 of 1): Use after free (USE_AFTER_FREE)53. deref_arg:
Calling "nfc_exit(nfc_context *)" dereferences freed pointer "context".
(The dereference is assumed on the basis of the 'nonnull' parameter
attribute.)
2013-09-19 20:38:56 +02:00
Philippe Teuwen
ad9694cf00 nfc-list: New option to choose which technologies to poll for
This is useful especially against chips emulating several types
at once (e.g. PN53x, PN544 etc)
2013-09-09 15:58:07 +02:00
Peter Meerwald
34bf7b3089 nfs-list: drop outdated examples superseeded by connection string
Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
2013-09-03 16:30:43 +02:00
Philippe Teuwen
a2a335e3d4 make style 2013-08-31 17:35:41 +02:00
Adam Laurie
07c54cd91b allow setting of UID for special 'chinese' ultralight cards 2013-08-31 16:15:27 +01:00
Philippe Teuwen
bb5b712a74 Adding link to AUTHORS in the copyright headers 2013-07-17 13:57:56 +02:00
Philippe Teuwen
2db4a0e7e4 make style
new version of astyle, better separation of XOR
2013-07-03 00:16:15 +02:00
Philippe Teuwen
7638e9ea87 mifare_classic_block_manufacturer: clearer struct members
Fixes issue 250
2013-06-13 20:14:22 +02:00
Philippe Teuwen
0841a94c65 nfc-mfclassic: allow option f for read operation too 2013-04-09 23:42:55 +02:00
Romuald Conty
e6ab66037d Better support for some special chinese cards
Fixes issue 190
2013-04-05 11:29:31 +02:00
Philippe Teuwen
e70a3314bf Update ChangeLog & make style 2013-03-12 17:07:09 +01:00
Philippe Teuwen
20e51e9752 nfc-mfclassic: add option to allow using keyfile from another card 2013-03-12 15:39:57 +01:00
Philippe Teuwen
16161e1a68 nfc-mfclassic: detect 2K MFP via RATS 2013-03-12 14:15:04 +01:00
Philippe Teuwen
56ea2e65dc nfc-mfclassic: use smaller files for cards < 4k 2013-03-12 10:56:57 +01:00
Philippe Teuwen
94617366a7 nfc-mfclassic: abort if expected UID is not matching real card 2013-03-12 10:56:20 +01:00
Philippe Teuwen
bb7b05681e nfc-mfclassic: fix reporting of processed blocks number 2013-03-12 10:55:45 +01:00
Philippe Teuwen
bf164220ee Unify copyright notices & update authors lists 2013-03-10 16:15:23 +01:00
Alex Lian
7b917f9a8b Windows: Clean up all compiler warnings and link warnings
- Fixed the suppression of the auto-fixup for linking against MS built libs
- Fixed all the formatting warnings by shifting to inttypes.h specifiers
- shifted to %lu for DWORD printf
2013-03-07 09:37:36 +01:00
Alex Lian
c72846e3c6 Convert by value passing of nfc_target to pointer for str_nfc_target and nfc_initiator_target_is_present
This becomes more consistent with all other pass by pointer of most structures.
Additionally, this should lessen stack memory usage, as building strings with str_nfc_target would push the target (283 bytes) plus then a copy of the info objects (up to 275) onto the stack as it dives into the sprintf functions.

Lastly, this makes my attempt at a .NET wrapper easier, as I can make passing by pointer work, but passing by value seems to bomb on the interop right now.
2013-03-07 09:16:33 +01:00
Philippe Teuwen
1d5f9956fb Fix cppcheck warning "buffer may not be null-terminated after call to strncpy()" 2013-03-06 12:38:59 +01:00
Philippe Teuwen
f0d5896140 Fix cppcheck style: "The scope of the variable can be reduced" 2013-03-06 11:02:47 +01:00
Philippe Teuwen
d577fda412 Fix cppcheck warning "scanf without field width limits can crash with huge input data"
Fix following warnings:
[examples/pn53x-tamashell.c:162]: (warning) scanf without field width limits can crash with huge input data
[libnfc/drivers/acr122_pcsc.c:261]: (warning) scanf without field width limits can crash with huge input data
[libnfc/drivers/acr122s.c:441]: (warning) scanf without field width limits can crash with huge input data
[libnfc/drivers/arygon.c:210]: (warning) scanf without field width limits can crash with huge input data
[libnfc/drivers/arygon.c:522]: (warning) scanf without field width limits can crash with huge input data
[libnfc/drivers/pn532_uart.c:187]: (warning) scanf without field width limits can crash with huge input data
[utils/nfc-relay-picc.c:176]: (warning) scanf without field width limits can crash with huge input data
2013-03-06 00:52:08 +01:00
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
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
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
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
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
Romuald Conty
2506ee35f6 Fixes invalid example in nfc-scan-device manpage 2013-03-01 17:07:40 +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
Romuald Conty
1e16795341 'make style' and align some #preprocessor directives 2013-02-19 00:43:20 +01:00