Skip to content

Comments

Fix cardversion format#28

Open
Jan21493 wants to merge 4 commits intowaza-ari:mainfrom
Jan21493:fix-cardversion-format
Open

Fix cardversion format#28
Jan21493 wants to merge 4 commits intowaza-ari:mainfrom
Jan21493:fix-cardversion-format

Conversation

@Jan21493
Copy link

@Jan21493 Jan21493 commented Jan 21, 2026

I found two errors in the code:

  • There was a 'copy&pase' error in CardVersion class, in def repr so hardware_minor_version was used twice and not hardware_major_version.hardware_minor_version
  • The calculation for memory size was wrong (far too high). I did some research in official documents from NFC that were open for public use and have added links, hints, examples and the correct formula in the code itself. I'm not sure if that is the best way, but might help others to verify information. It's difficult to put that information into this PR and I'm not familiar to contribute to the documentation for this project. In short: the formula 1 << (self.hardware_storage_size - 1) was wrong and needs to be changed to 1 << (self.hardware_storage_size >> 1). Only bits 1-7 (and not 0) are used as exponent. The original formula has used "(size // 2)" as the exponent.

The second fix is including MIFARE Ultralight, DESFire Families and NTAGs as well. I know that the current library has problems to fetch this information, e.g. Ultralight Cards and NTAG 2xx do not support ISO 7816 APDU wrapping and return 7 byte only (the first block), but I hope that the library might be extended to support those cards as well as tags that are ISO compliant. I've done some modifications, but they are in an early state. I've read that some DESFire EV2 and EV3 cards may have small memory sizes, so I've included the full formula.

I would like that the scope of the library might cover the cards/tags in the future with a simple verification of the length of the input, e.g. "if len(data) < 8: return" in init and repr, but I haven't included such lines in the my first PR to this library.

I've done all tests as described and the code has passed these tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant