Commit graph

573 commits

Author SHA1 Message Date
Romain Tartiere
bef4ec342f Don't keep unsupported tags selected.
Currently, when the libfreefare finds a NFC target, it checks whether it's a
supported one looking at it's ATQA.

If the target's ATQA is not in the supported ATQA list, the target was not
deselected.  While this is buggy, it allowed to detect 2 tags with colliding
ATQA on a single NFC device and still have the ATQA of each tag (on ATQA
collision, the ATQA is set to 0x0000 by the NFC chip, but as the tag is not
deselected, it will have a second chance to tell it's ATQA when it will be idle
again):

 computer             PCD                   PICC1   PICC2
    |                  |             ATQA:  0x1234  0x6789
    |                  |                      |       |
    |- InListTargets ->|                      |       |
    |                  |------ REQA ----->(===============)
    |                  |<---- ATQA 1234 ------|       |      } Both reply
    |                  |<---- ATQA 6789 --------------|      } simultaneously
    |                  |                      S       |
    |                  | // Collision detected PICC1 only is selected because
    |                  | // only a single tag was wanted.  It's ATQA is set
    |                  | // to 0x0000.
    |<-- ATQA 0x0000 --|                      S       |
    | // Unsuported ATQA, skipped             S       |
    |                  |                      S       |
    | // DESELECT IS MISSING HERE!            S       |
    |                  |                      S       |
    |- InListTargets ->|                      S       |
    |                  |------ REQA ----->(===============)
    |                  |<---- ATQA 6789 --------------S // PICC1 won't reply
    |<-- ATQA 0x6789 --|                      |       S // it is still selected
    | // Supported, deselect it               |       S
    |--- InDeselect -->|                      |       S
    |                  |-------- HALT --------------->X
    |                  |                      |       X
    |- InListTargets ->|                      |       X
    |                  |------ REQA ----->(===============)
    |                  |<---- ATQA 1234 ------S       X // PICC2 won't reply
    |<-- ATQA 0x1234 --|                      S       X // it is deselected
    | // Supported, deselect it               S       X
    |--- InDeselect -->|                      S       X
    |                  |-------- HALT ------->X       X
    |                  |                      X       X
    |--- InDeselect -->|                      X       X
    |                  |------ REQA ----->(===============)
    |                  |                      X       X // No reply
    |                  |                      X       X

                                          Tag timeline legend:
                                            | - Target idle
                                            S - Target selected
                                            X - Target deselected

Since PN53x devices can only known about 2 tags simultaneously, presenting 3
targets to the NFC device caused an infinite loop.

This commit prevents this infinite loop to occur, and will be completed later
by another commit for not relying on the ATQA to determine targets type.
2010-08-04 12:08:38 +00:00
Romain Tartiere
88a4cbbe53 Use a lower-level communication with Mifare DESFire targets.
Instead of uting nfc_initiator_transceive_dep_bytes() to transmit commands,
prepend an ISO-14443-4 header to it and send it using
nfc_initiator_transceive_bytes().  In case of WTX reply, handle it, and then
extract relevant information from the data returned by the PICC.

This prevents failure that happen with ISO-14443-4 compliant targets when using
a PN531-based NFC-device, and allows using the libfreefare with Mifare DESFire
targets on such devices.
2010-07-29 09:48:08 +00:00
Romain Tartiere
02897e1b69 Add debug capabilities for Mifare Classic and Mifare UltraLight targets. 2010-07-29 08:14:16 +00:00
Romain Tartiere
28b6ab7196 Move buffer macros to freefare_internal.h.
While here, tweak <libutil.h> include.
2010-07-29 07:58:25 +00:00
Romain Tartiere
b7d8f0e790 Add my Vim snippets as contrib. 2010-07-29 07:14:11 +00:00
Romain Tartiere
2ac6527164 Always define -DWITH_DEBUG if compiling WITH_DEBUG. 2010-07-29 06:31:37 +00:00
Romain Tartiere
cc50ebc4df Fix $Id$ vcs keywords.
- Add a new svn-keywords target to fix missing properties;
  - Add a new svn-keywords-check target to locate files lacking $Id$ statement.
2010-07-29 06:25:57 +00:00
Romain Tartiere
61a5ff4e4a Reintroduce the possibility to hexdump(3) PCD <=> PICC transmissions.
Not a hack this time:
  - Use the hexdump(3) function of the system if it exists;
  - Build the subpart of FreeBSD's libutil if not (contrib);
  - Do this only if configured --with-debug.

The Mifare Classic / Ultralight code will be eventually changed to also provide this functionality.
2010-07-29 06:11:27 +00:00
Romain Tartiere
1f1db8692b Fix svn:keyword (I'll commit something to handle this automagically in ~2 commits). 2010-07-29 05:58:04 +00:00
Romuald Conty
9ff14c416d mifare-classic-write-ndef now use newly introduced public keys and AID. 2010-07-28 10:23:56 +00:00
Romuald Conty
87034e29a9 Add (and export) NFC Forum AID. 2010-07-28 10:18:28 +00:00
Romuald Conty
a70688222b Add (and export) AID administration codes (provided by MAD document - AN10787) 2010-07-28 10:15:58 +00:00
Romuald Conty
985cb0b349 Export NFC Forum public key for MIFARE Classic. 2010-07-28 10:12:11 +00:00
Romuald Conty
8026f33170 Add NFC Forum public key for MIFARE Classic. 2010-07-28 10:06:42 +00:00
Romain Tartiere
6631491dec change sectors keys THEN write application data.
This should avoid failure in some advanced use cases and when the example will be able to add user-provided data without data-loss.

Suggested by:	Romuald Conty <rconty@il4p.fr>
2010-07-27 14:03:20 +00:00
Romain Tartiere
0ada18e508 Fix sector counts.
Submitted by:	Romuald Conty <rconty@il4p.fr>
Pointy hat to:	me
2010-07-27 13:54:09 +00:00
Romain Tartiere
21fa85ca1d Only search keys of existing sectors. 2010-07-27 13:37:57 +00:00
Romain Tartiere
9872a1b087 Rename DESFIRE_4K to DESFIRE.
The code can work with virtually any size of DESFire (since the operating
system embedded in the card handle almost everything), so there is no need for
us to distinguish cards of different sizes.
2010-07-27 08:44:12 +00:00
Romain Tartiere
eca3c540ad Remove the FreeBSD hexdump(3) code.
It was used for easing up development but is not needed anymore.
2010-07-27 08:35:15 +00:00
Romain Tartiere
f5a95b1c57 Rename MC_STORE to MC_RESTORE.
It's easy now that the macro is defined in the libfreefare's code and not the libnfc's one.
2010-07-27 08:17:48 +00:00
Romain Tartiere
5779d6f945 Merge the freefare-desfire branch into trunk. 2010-07-26 21:48:18 +00:00
Romain Tartiere
3f6a142b57 Enhance the mifare-classic-write-ndef example.
- Use the new mifare_application_alloc() and mad_application_write API;
  - Deal with writing over multiple sectors with different keys.
2010-07-26 20:27:21 +00:00
Romain Tartiere
9ba6d198b8 Merge r487 from the libfreefare-desfire branch. 2010-07-26 20:21:02 +00:00
Romain Tartiere
f425ae30c6 Merge r486 from the libfreefare-desfire branch. 2010-07-26 20:20:22 +00:00
Romain Tartiere
7a08464e14 Add missing APIs from the documentation. 2010-07-26 18:27:56 +00:00
Romain Tartiere
5d62cee7d7 Merge r489 from the libfreefare-desfire branch. 2010-07-26 14:12:32 +00:00
Romain Tartiere
d186bfbaa3 Update after libnfc API change. 2010-07-21 11:41:58 +00:00
Romuald Conty
cae581eded constify mad related functions when applicable. 2010-07-20 07:47:58 +00:00
Romuald Conty
2668b48232 Minor mad man page fix. 2010-07-20 07:39:46 +00:00
Romuald Conty
4230d2b378 Add missing config.h include in mifare-classic-format example. Fix Issue 34. 2010-07-07 07:25:16 +00:00
Romain Tartiere
381598951a s/MifareSectorNumber/MifareClassicSectorNumber/ in man pages. 2010-07-03 10:08:48 +00:00
Romain Tartiere
42f2729404 Add TODO file. 2010-07-03 10:06:34 +00:00
Romain Tartiere
63008fd7c5 Add another implementation node. 2010-07-03 10:04:50 +00:00
Romain Tartiere
dbd3682174 New API functions mad_application_read(), mad_application_write(). 2010-07-03 10:04:06 +00:00
Romain Tartiere
9e5820b89e Allow mifare-classic-format to be run non-interactively. 2010-07-03 09:14:32 +00:00
Romain Tartiere
6cbb9f4f9d Add a fast-format feature in the mifare-classic-format utility to only erase MAD. 2010-07-03 09:09:26 +00:00
Romain Tartiere
163df002f2 Rename MifareSectorNumber to MifareClassicSectorNumber. 2010-07-03 06:31:28 +00:00
Romain Tartiere
8afbf4fe69 Add missing parentheses. 2010-07-03 06:28:35 +00:00
Romain Tartiere
4417a13f9f Don't assume a Mifare Classic Sector Number will always fit in a byte (currently it's a uint8_t but it exposes some problems). 2010-07-03 06:24:29 +00:00
Romain Tartiere
825d59e938 Sync mifare_classic_format_sector() prototype in freefare.h with the code. 2010-07-03 06:09:34 +00:00
Romain Tartiere
163ce56cc0 Refactoring Blocks vs. Sectors.
- mifare_classic_format_sector() now wants a sector instead of a block (the name was really disturbing);
  - New public API functions for Block <=> Sector conversions.
2010-07-01 23:19:45 +00:00
Romain Tartiere
cc5de33a56 Rename the test_mifare_classic_application unit test to test_mifare_application. 2010-07-01 21:57:49 +00:00
Romain Tartiere
f83918ee41 Fix MAD manipulation for Mifare Classic 4K.
- Allocate large blocks on Mifare Classic 4K in unit tests;
  - Constraints sector number in mad_set_aid();
  - Fix location of AID storage in mad_set_aid() (wrong variable name and offset, ECOPYPASTETOOFAST);
  - New API function mad_sector_reserved();
  - Use mad_sector_reserved() to avoid trying to use reserved sectors.
2010-07-01 21:44:40 +00:00
Romain Tartiere
541292505a Make mifare_application_alloc() accept size in bytes.
Fixes issue 31.
2010-07-01 17:05:44 +00:00
Romain Tartiere
92ae6036d2 Add unit tests for mad_read() and mad_write(). 2010-07-01 14:10:09 +00:00
Romain Tartiere
db0dd52339 Make the MAD read public key public (Rename it to insist on it's public nature). 2010-07-01 14:08:59 +00:00
Romain Tartiere
4a1415ed01 s/blocks/sectors/ 2010-07-01 13:25:14 +00:00
Romain Tartiere
0e1aded982 Document the mifare_tag_type enum. 2010-07-01 12:32:03 +00:00
Romain Tartiere
06e61a89d5 Remove clueless omitted test. 2010-07-01 11:00:25 +00:00
Romain Tartiere
829e28cfda Complete unit tests coverage of freefare.c.
The freefare_get_tag_friendly_name() function was not tested.  Call it from both supported cards unit tests suites.
2010-07-01 10:57:59 +00:00