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

HCE like feature for simulating NFC card #43

Open
prodigy7 opened this issue Jul 10, 2018 · 2 comments
Open

HCE like feature for simulating NFC card #43

prodigy7 opened this issue Jul 10, 2018 · 2 comments
Assignees
Labels

Comments

@prodigy7
Copy link

Hi,

is it possible, simulate a nfc card with that library and when yes, how?

Regards

@pokusew pokusew self-assigned this Jul 12, 2018
@pokusew
Copy link
Owner

pokusew commented Jul 13, 2018

Hi @prodigy7,

yes, that's perfectly possible to do using this library 🎉, but it depends on whether your card reader supports card emulation mode (it acts like a NFC card/tag).

To be precise, with nfc-pcsc you can do everything you could do with standard system C++ PC/SC API. It means if you reader has a feature XXX, you can most likely use it with nfc-pcsc. 🙂

However, the way, how to achieve that, differs from reader to reader.
You'll have to send special APDU commands to enable and control the card emulation mode using reader.transmit(data, responseMaxLength) method.

But before you can call reader.trasmit method, you have to connect to the reader This is done automatically when a NFC card/tag is attached, but because there is no tag present on the reader, you have to do it manually and you have to use CONNECT_MODE_DIRECT.

Thus, you have to call reader.connect(CONNECT_MODE_DIRECT) (you can see an example usage in the LED example).

Note! By default standard system PCSC driver doesn't allow to send any commands in direct mode (i.e. without any card present). You'll have to setup a few things depending on your OS.
Please see this comment with the further explanation and the step-by-step guide or this FAQ in the README.

I think, that's all from nfc-pcsc's side. The other side are the actual APDU commands you'll need. You can usually find them in the reader's API and technical docs.

For example, to use card emulation mode on ACR122U USB NFC reader you could follow the steps described in this StackOverflow answer.

  • the ACR122U API itself does not support card emulation, but the PN532 NFC controller chip inside it can do it (and even much more, e.g. Peer-to-Peer)
  • note that, to communicate directly with the PN532 chip, you have to use the Direct Transmit APDU command as described in section 6.1 of ACR122U API docs and wrap the native PN532 commands into it – the StackOverflow answer already contains correctly wrapped commands

Finally, I must admit, I have never tried this. But I believe it is perfectly possible and doable. I  hope my answer gave you some useful information and thoughts how to implement the card emulation using nfc-pcsc. 🙂

Thank you very much for your interesting question. 👍

Feel free to contact me, if you encounter any problems or need any help.
Also let me know if you make it work. It'd be great to include it to the nfc-pcsc examples. I'm sure other people would be interested too. 👀


PS Don't forget to star ⭐️ my library, if you find it useful. 😃 Thanks.

@prodigy7
Copy link
Author

Wow! That is really detailed answere! Thank you very much for any detail and your time, you've spend answering my question!
I'll try it next time and when I get usable results, I'll report or contribute!

Maybe a second questions: Its possible, using nfc-pcsc also in electron. Is it also possible, use it in android? My idea is, writing a app which simulates a card. For that I would use NativeScript which could also include that lib. Question is: Does this lib supports android or does android a complete own api so I've to use other nfc libs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants