Skip to content

Add custom read/write helpers for MIFARE Classic tags #217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

albertoboccolini
Copy link

This PR introduces two new utility methods for interacting with MIFARE Classic NFC tags:

  • readDataFromTag to read an arbitrary number of bytes from a specified sector/block, skipping trailer blocks automatically.
  • writeDataToTag to write a list of bytes starting from a given sector and block, safely avoiding trailer blocks and padding incomplete blocks with zeros.

They simplify working with MIFARE Classic tags by handling sector authentication, block calculation, and trailer block skipping. Useful for reading or writing multiple bytes without managing low-level NFC logic manually.

@albertoboccolini
Copy link
Author

Hi, I'm interested in contributing to this project because I used this library in a project to interact with MiFare Classic tags. I had some difficulty accessing sectors and blocks at a low level, and after seeing that others had similar issues, I thought of implementing some user-friendly methods. This is my first official contribution, so I'm not sure if my approach is entirely correct. I'm open to suggestions and improvements. When you have a moment, could you please review my code? @Harry-Chen

@Harry-Chen
Copy link
Contributor

Thanks! I did have similar plans before, but the issue is that tags might have different keys for different sectors. So I prefer leaving the readBlock API to users.

@albertoboccolini
Copy link
Author

You're right, hardcoding a single key for the whole operation limits the real use cases. The idea behind these methods was to provide a high-level function for those dealing with uniformly keyed tags, but we could extend it by adding a Map<int, String> sectorKeysA parameter (and optionally sectorKeysB) to support different keys per sector. Let me know if you think it's worth the PR!

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.

2 participants