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.
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>
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>
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>
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>
- 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?
$
* 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