Implement mifare_ultralight_write() using macros.

Update issue 58
I can't reproduce this bug, but saw that the mifare_ultralight_write() was
implemented in an old-school way.  I updated the code so that you should have
better traces when compiling the library in debug mode and running:

romain@marvin ~/Projects/libfreefare % cutter -n test_mifare_ultralight_write test
===> 0000   30 07                                            |0.              |
<=== 0000   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
===> 0000   a2 07 12 34 56 78                                |...4Vx          |
===> 0000   30 07                                            |0.              |
<=== 0000   12 34 56 78 00 00 00 00 00 00 00 00 00 00 00 00  |.4Vx............|
===> 0000   a2 07 aa 55 00 ff                                |...U..          |
===> 0000   30 07                                            |0.              |
<=== 0000   aa 55 00 ff 00 00 00 00 00 00 00 00 00 00 00 00  |.U..............|
===> 0000   a2 07 00 00 00 00                                |......          |
===> 0000   30 07                                            |0.              |
<=== 0000   00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  |................|
.

Finished in 0,548238 seconds (total: 0,069079 seconds)

1 test(s), 12 assertion(s), 0 failure(s), 0 error(s), 0 pending(s), 0 omission(s), 0 notification(s)
100% passed
This commit is contained in:
Romain Tartiere 2011-04-05 21:05:27 +00:00
parent b6cbeb2e20
commit 573fc1b778

View file

@ -221,16 +221,14 @@ mifare_ultralight_write (MifareTag tag, const MifareUltralightPageNumber page, c
ASSERT_MIFARE_ULTRALIGHT (tag);
ASSERT_VALID_PAGE (tag, page, true);
uint8_t cmd[6];
cmd[0] = 0xA2;
cmd[1] = page;
memcpy (cmd + 2, data, sizeof (MifareUltralightPage));
BUFFER_INIT (cmd, 6);
BUFFER_INIT (res, 1);
size_t n;
if (!(nfc_initiator_transceive_bytes (tag->device, cmd, sizeof (cmd), NULL, &n))) {
errno = EIO;
return -1;
}
BUFFER_APPEND (cmd, 0xA2);
BUFFER_APPEND (cmd, page);
BUFFER_APPEND_BYTES (cmd, data, sizeof (MifareUltralightPage));
ULTRALIGHT_TRANSCEIVE (tag, cmd, res);
/* Invalidate page in cache */
MIFARE_ULTRALIGHT(tag)->cached_pages[page] = 0;