Skip to content
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

NFC: FeliCa Protocol Expose Read Block API and Allow Specifying Service #4074

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

Conversation

zinongli
Copy link
Contributor

@zinongli zinongli commented Jan 20, 2025

What's new

  • A brief background for the jargons: one FeliCa tag hosts multiple Systems, each System hosts multiple Services, each Service has its own Blocks. I'll skip Area here as it's not relevant. Currently, FeliCa protocol is implemented in this way (as far as I can tell from reading lib/nfc/protocol/felica/): always select the first system on the list, always request service FELICA_SERVICE_RO_ACCESS, and always read these few blocks.
  • To be fair, one could definitely use the internal functions in felica_poller_i.c to read all sorts of things. For example, for Suica, one could read travel history and tap logs by reading the blocks from their corresponding services, by inputing the corresponding service code to felica_poller_prepare_tx_buffer(). The only problem is, it's internal, so not available to external apps.
  • This situation forbids the full potential of the FeliCa reading utility Flipper has. In this PR I exposed the read_block function and allowed service code selection mainly for the reason that I'm trying to implement a Suica parser using FeliCa poller. Because I intend to do that in an external app (Metroflip), exposing the API is the only way as of now.
  • Also, I left the native NFC app as it is. Only moving the macro outside of read_block() into where read_block() is used by felica poller.
  • Lastly, the current FeliCa workflow of the native NFC app could be improved by allowing users to manually input the service code they are looking for and iterate through all blocks until either status flag reaches non-zero. This PR's change could allow that to happen. But whether it is a good thing to have is a topic for another PR.

Verification

  • I currently have a working version of Metroflip that can read raw Suica travel history and tap logs by requesting the correct service codes. You can build that app with this PR's firmware and read a Suica card. It should show a reading like this:
    Screenshot-20250119-190813

Checklist (For Reviewer)

  • PR has description of feature/bug or link to Confluence/Jira task
  • Description contains actions to verify feature/bugfix
  • I've built this code, uploaded it to the device and verified feature/bugfix

@zinongli
Copy link
Contributor Author

  • Lastly, the current FeliCa workflow of the native NFC app could be improved by allowing users to manually input the service code they are looking for and iterate through all blocks until either status flag reaches non-zero. This PR's change could allow that to happen. But whether it is a good thing to have is a topic for another PR.

Just to add a bit more context, a lot of FeliCa cards have well documented service codes useful for user to select and to read the data in their cards. Allowing user or apps to request the service they need would be a nice thing to have.

@zinongli
Copy link
Contributor Author

Are there any changes needed? I'm happy to work with any expectations you have about Felica's impelmentation. Or if this PR overlaps with what's already been worked on I can accommodate too.

If testing is needed I have two cards at hand. And both iOS and Andoird have Felica emulation with Mobile Suica so that's another way to test. It all works on my end with this PR. I've also run unit tests and it passes that too.

image

@RebornedBrain
Copy link
Contributor

Hi, @zinongli thanks for your contribution, I saw your changes and it looks fine for me, I will ask QA to take a look on that.

@zinongli
Copy link
Contributor Author

Thanks a lot! Sounds great! Sorry for being pushy back then.

@Astrrra
Copy link
Member

Astrrra commented Feb 20, 2025

Hi! Trying to read a card with the version of Metroflip you've provided (Suica branch of your fork) results in a crash, is that intended?
image

@Astrrra Astrrra self-assigned this Feb 20, 2025
@zinongli
Copy link
Contributor Author

zinongli commented Feb 20, 2025

Hi @Astrrra ! Thanks for testing! I believe that branch was outdated as I progress through the development of Metroflip. There were definitely bugs in the poller callback that I fixed later. I tested myself and found my most recent branch of Metroflip works more consistently. Would you mind trying out this branch?
https://github.com/zinongli/Metroflip/tree/0.5%2Bload%2Bsuica

@zinongli
Copy link
Contributor Author

zinongli commented Feb 20, 2025

Also, if you don't mind sharing, what card are you testing with? Because I could try to look up the correct service code for easier testing.

One alternative way to test this PR without using Metroflip is changing this macro to the service code we want and read with native NFC app.

For example, here I read a Suica whose service code should be 0x090F. I read with the OFW (or this PR), and I will get this from block reading:

original

The SFs here are not 0x00 since the first block, suggesting the blocks weren't successfully read.

However, if I set this macro to be (0x090FU), the service code corresponding to travel history for Suica, and reflash the firmware, read the Suica card again, I will see this after reading with native NFC app:

sui1
sui2

The status flag being zero, suggesting the reading was successful. And the content displayed here are the specific blocks read.

If you don't mind sharing the card you are testing with I can try and see if I can find a service code that work for you.

@Astrrra
Copy link
Member

Astrrra commented Feb 21, 2025

すごい!Tested on the other branch, works with all the cards I've tried (suica, pasmo, icoca), thanks!

btw, the UI looks super nice :D

@zinongli
Copy link
Contributor Author

Awesome! And thanks! Haha

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.

3 participants