libnfc

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2023 License: LGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package libnfc provides a CommandDriver implementation which allows to use libnfc devices (readers etc.) to read and update Type 4 Tags.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoDevicesDetected         = errors.New("no nfc devices detected")
	ErrRequestedDeviceNotPresent = errors.New("requested nfc device not present")
	ErrNoTargetsDetected         = errors.New("no targets detected.")
)

Common errors

Functions

This section is empty.

Types

type Driver

type Driver struct {
	Modulation   nfc.Modulation // The modulation to use
	DeviceNumber int            // The libnfc devices number to choose
	// contains filtered or unexported fields
}

Driver implements the CommandDriver interface allowing `Device` to use any libnfc-supported hardware to communicate with a real NFC Tag.

For this driver to work, libnfc needs to be correctly installed and configured in the system (it should be able to detect any plugged-in readers and poll the desired Targets (that is, detect the tags with which we want to interact with).

func (*Driver) Close

func (driver *Driver) Close()

Close shuts down the driver correctly by closing the device that was used.

func (*Driver) Initialize

func (driver *Driver) Initialize() error

Initialize performs the necessary operations to make sure that the driver is in conditions to TransceiveBytes.

For the Driver this involves detecting available nfc devices, selecting one and setting it up as an Initiator, using it to scan for targets and selecting the first target available (or fail). This means that for initialization to work, the NFC device needs to be visible to the reader already, as otherwise there is no target to work with.

It returns an error when some step fails.

func (*Driver) String

func (driver *Driver) String() string

String returns some information extracted from libnfc about the NFC device and the target that was selected. It should be used after calling Initialize().

func (*Driver) TransceiveBytes

func (driver *Driver) TransceiveBytes(tx []byte, rxLen int) ([]byte, error)

TransceiveBytes is used to send and receive bytes from the libnfc device. It receives a byte slice to send, and an expected maximum length to receive. It returns the received data or an error when something fails.

Notes

Bugs

  • Driver Modulation is hardcoded and cannot be specified by the user.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL