clausecker / nfc Goto Github PK
View Code? Open in Web Editor NEWGo bindings for the libnfc
Home Page: https://pkg.go.dev/github.com/clausecker/nfc/v2
License: GNU Lesser General Public License v3.0
Go bindings for the libnfc
Home Page: https://pkg.go.dev/github.com/clausecker/nfc/v2
License: GNU Lesser General Public License v3.0
This is a Go wrapper for the libnfc. You need the following libnfc version to use this code: versions <= 2.0.2 need libnfc version 1.7.0 or 1.7.1 version >= 2.1.0 need libnfc version 1.8.0 or later Due to an unfortunate ABI breakage, libnfc version 1.7.2 cannot be used with this wrapper. The code has not been thoroughly tested yet. Please report any errors to the project. The API is considered stable as of version 2.0 and will probably not change in incompatible ways in the near future. Version 2.0.2 and earlier of this wrapper have been developed before the advent of Go modules. For this reason, they use a weird homecooked scheme for their versioning involving the 2.0 and latest directories. These can safely be ignored for new developments. Using Go modules, only version 2.1.0 and later are available. To use this library, install libnfc version 1.8.0 or newer and import github.com/clausecker/nfc/v2 into your project. Pkg-config is used to find libnfc automatically. If this does not work, you can compile with tag nopkgconfig or no_pkgconfig to instruct the package to instead simply link with -lnfc. You'll then have to manually set things up for suitable -I... and -L... options to be supplied so the header files and library are found. This project uses go modules for versioning and tries its best to follow the usual guidelines for interface stability. Copyright (c) 2014--2020, 2024 Robert Clausecker <[email protected]> This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 3. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Should be wrapped as
func (*Device) InitiatorDeselectTarget() error
I installed the library using go get
go get github.com/fuzxxl/nfc
I'm receiving a build error that would indicate that I possibly installed the library incorrectly.
../github.com/fuzxxl/nfc/2.0/nfc/nfc.go:206: undefined: context
I tried downloading the root project directly into my GOPATH but am still experiencing the same behavior. Can you advise? I'm sure it's something dumb that I'm overlooking.
This is more of support question than an issue, but how would you manage multithreading with libnfc? Even with mutexes it seems the Target struct can't be reused in a different thread (ex: InitiatorTargetIsPresent return err Invalid Argument).
The current implementations of Target.Marshall() do not check the supplied data for invariants. It won't crash because Go checks boundaries, but the code panics if an array is too long.
This needs to be improved.
Device.InitiatorSelectPassiveTarget
is not usedReference: http://www.libnfc.org/api/group__initiator.html#gacbe0fa197206cac99c83ed0152174811
The dev version is not working, but I can purpose a PR for a fix in 2.0 if needed :)
I am trying to cross compile a simple go program.
package main
import (
"fmt"
"github.com/fuzxxl/nfc/2.0/nfc"
)
func main() {
fmt.Println(nfc.Version())
devices, err := nfc.ListDevices()
if err != nil {
fmt.Print(err)
return
}
for _, d := range devices {
fmt.Printf("found device %s", d)
}
}
I am cross compiling it with the following command.
GOOS=linux GOARCH=arm go build -a -v github.com/fuzxxl/nfc/2.0/nfc
I am using the golang:1.7.5
docker image (based on debian wheezy) for compilation. I encounter the following compiler error.
../../fuzxxl/nfc/2.0/nfc/nfc.go:206: undefined: context
It is clear that etc.go
has type context struct
defined in the nfc package. This error occurs only during cross compilation. Is there something that I am missing?
When InfiniteSelect == false, nfc_initiator_select_passive_target return 0 when no tag was found, but Device.InitiatorSelectPassiveTarget always calls unmarshallTarget.
Example in https://github.com/nfc-tools/libnfc/blob/master/utils/nfc-mfclassic.c
if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) <= 0) {
printf("Error: no tag was found\n");
nfc_close(pnd);
nfc_exit(context);
exit(EXIT_FAILURE);
}
This code use <= 0 for error checking.
func main() {
dev, _ := nfc.Open("")
defer dev.Close()
dev.InitiatorInit()
dev.SetPropertyBool(nfc.InfiniteSelect, false)
dev.SetPropertyBool(nfc.AutoISO14443_4, false)
fmt.Printf("NFC reader: %s opened\n", dev)
dev.InitiatorSelectPassiveTarget(nmMifare, nil) // panic when no tag was present
}
all version include latest
See https://gist.github.com/messinm/7086bfce591bf6f1d554
Running under Ubuntu 14.04 64-bit, libnfc 1.7.0
mifare target gives the following from printing Target received from InitiatorListPassiveTargets:
ISO/IEC 14443A (106 kbps) target:
ATQA (SENS_RES): 00 04
Fingerprinting based on MIFARE type Identification Procedure:
Then attempting marshalling to ISO14443aTarget, I get the following:
Atqa =[0 4]
Sak =8
UIDLen =33091718999965696
UID =[112 70 188 32 255 0 0 0 0 0]
Note that 33091718999965696 = 0x7590BE3C000000, so it appears that the UIDLen field actually contains the UID.
Am I doing something wrong in the marshalling code? Or is this a bug in Go NFC lib or libnfc?
This is more of a documentation issue than a bug. It's not at all clear how you actually select a target once you've listed them.
I can get a Target enumerated from Device#InitiatorListPassiveTargets(), but how do I select it?
error libnfc.driver.acr122_usb Invalid RDR_to_PC_DataBlock frame
panic: input / output error
I've tried a number of approaches, none of which seem to work, and I can't find any documentation or examples for this.
Thanks.
src/github.com/fuzxxl/nfc/1.0/nfc/nfc.go:205: undefined: context
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.