Code Monkey home page Code Monkey logo

nfc's Introduction

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.

nfc's People

Contributors

clausecker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nfc's Issues

Help with cross compiling for Raspberry Pi

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?

Initiator Target Selection?

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?

  1. There is no Select() method on the Target interface
  2. There IS a Device#InitiatorSelectPassiveTarget(), but there is no documentation on what the meaning of the second parameter initData is. What is supposed to be passed there? Simply passing a []byte{0} results in the following error:

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.

undefined: context

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.

Device.InitiatorSelectPassiveTarget panic when InfiniteSelect == false and no tag was found

Problem

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.

How to reproduce

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
}

Affected version

all version include latest

ISO14443aTarget marshalling problem?

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

  • UID size: single
  • bit frame anticollision supported
    UID (NFCID1): 3c be 90 75
    SAK (SEL_RES): 08
  • Not compliant with ISO/IEC 14443-4
  • Not compliant with ISO/IEC 18092

Fingerprinting based on MIFARE type Identification Procedure:

  • MIFARE Classic 1K
  • MIFARE Plus (4 Byte UID or 4 Byte RID) 2K, Security level 1
  • SmartMX with MIFARE 1K emulation
    Other possible matches based on ATQA & SAK values:

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.