View Source LibNFC (LibNFC v0.1.0)
This package provides a NIF binding to libnfc and some Elixir boilerplate for convenient & more idiomatic use.
Status
This library was designed to detect and track the presence of ISO/IEC 14443 Type A passive NFC targets from an Elixir application. Its original use-case was a Raspberry-based music box controlled by cheap passive NFC tags detectable by a PN532 NFC HAT. The adaptation of libnfc functions as well as design of the surrounding Elixir API is so far limited to support this use-case, yet extending the library for other NFC modulations should be relatively straightforward.
- ✅ Listing & opening NFC devices
- ✅ ISO 14333 Type A passive target selecting & tracking
Not implemented:
- Other modulations
- Initiator API: Polling, writing, transceiving
- Target API
Dependencies
- libnfc
- make
- working C11 compiler, e.g. gcc
Installing libnfc from source
On Debian and derived Linux systems:
sudo apt-get install build-essentials automake autoconf
sudo apt-get install libusb-dev
git clone https://github.com/nfc-tools/libnfc
cd libnfc
autoreconf -vis
./configure --prefix=/usr --sysconfdir=/etc
make -j4
sudo make install
Visit libnfc for details.
Installation
def deps do
[
{:libnfc_ex, "~> 0.1.0"}
]
end
Usage
{:ok, device} = LibNFC.open()
{:ok, target_info} =
LibNFC.initiator_select_passive_target(device)
IO.puts("Target #{LibNFC.Utils.uid_hex(target_info["uid"])} in range")
Summary
Types
Reference of opened NFC device.
Short identifier for types of NFC targets. Defines both modulation & baud rate.
Map of data received from NFC target.
Functions
Tries to select a passive target with a given modulation.
Checks whether a previously selected target is still present.
Lists NFC devices controlled by operating system.
Opens the default NFC device.
Opens a specific NFC device identified by a "connstring".
Returns version of linked libnfc library.
Types
@type device() :: reference() | :mock
Reference of opened NFC device.
@type modulation() :: atom()
Short identifier for types of NFC targets. Defines both modulation & baud rate.
See nfc_baud_rate
and nfc_modulation_type
in nfc_types.h
.
Known types
:iso14443a
->NMT_ISO14443A
,NBR_106
Map of data received from NFC target.
Structure is determined by NFC target type.
See nfc_target_info
union in nfc_types.h
.
Functions
initiator_select_passive_target(open_device, modulation \\ :iso14443a)
View Source (since 0.1.0)@spec initiator_select_passive_target(device(), modulation()) :: nil | {:ok, target_info()} | :error
Tries to select a passive target with a given modulation.
Checks whether a previously selected target is still present.
@spec list_devices() :: [String.t()]
Lists NFC devices controlled by operating system.
@spec open() :: [device()]
Opens the default NFC device.
Opens a specific NFC device identified by a "connstring".
@spec version() :: String.t()
Returns version of linked libnfc library.