i was wondering if there is a way to access smart cards via a PCSC reader.
I was unable to find any lib or bindings to do so (here’s a list samples in different languages [1]).
Maybe there is a different way to accomplish the task, or there has never been a use case for erlang centric applications.
A while back I wrote a library which interfaces with libnfc compatible card readers:
It uses a NIF under the hood to do the device IO. It is quote limited at the moment though, it has only been used to read Mifare NFC cards. But it maybe could get you started.
I’ve just recently had reason to put together a proper libpcsc binding for Erlang:
If you’re still looking, let me know what you think. Also includes some conveniences like ISO7816 command and response chaining support in an “APDU transform” so you can just send a long data field or get a long reply back.
I don’t use Elixir a lot myself, so I’m not sure how the API will look from that side, but I’m happy to try to improve it.
$ ./_build/default/bin/blog
Hello world!
escript: exception error: undefined function pcsc_card_db:list_readers/0
in function escript:run/2 (escript.erl, line 750)
in call from escript:start/1 (escript.erl, line 277)
in call from init:start_em/1
in call from init:do_boot/3
My code does not find the pcsc functions. I guess it is trivial to fix once you know Erlang a bit more.
With the {escript_incl_apps, [pcsc]} the error changes from undefined function to noproc. The library should now be packaged properly with the escript.
The noproc error occurs in this case, because the pcsc application is not started. So I tried adding it in the apps declaration {apps, [pcsc, blog]} ← works only for shell so far.
When I run rebar3 shell I still get an error because my architectures don’t match, and the NIF can’t load the C code. I’ll try to get around this, but maybe this already solves your problem.
Edit:
I got it working in the shell on a different machine
This makes the rebar3 shell command work. However, packaging a NIF with an escript seems to be more complicated [1], [2]. The shell example should be enough as a proof of concept though, as the packaging/release method is up to the user.
Is it possible in principle to use those NFC libraries to exchange information between 2 NFC enabled mobile phones ? As an example use it between customer and merchant to get payment details instead of QR or card payment?