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
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.
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.
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 :)
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?
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?
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).
src/github.com/fuzxxl/nfc/1.0/nfc/nfc.go:205: undefined: context
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
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.
Should be wrapped as
func (*Device) InitiatorDeselectTarget() error
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.