clausecker / nfc

Go bindings for the libnfc
https://pkg.go.dev/github.com/clausecker/nfc/v2
GNU Lesser General Public License v3.0
101 stars 20 forks source link

Initiator Target Selection? #5

Closed wildattire closed 9 years ago

wildattire commented 9 years ago

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.

wildattire commented 9 years ago

As a followup to this, it looks like InitiatorListPassiveTargets() is somehow calling the same underlying function as InitiatorSelectPassiveTarget(), but with different results:

InitiatorListPassiveTargets(): debug libnfc.chip.pn53x InListPassiveTarget debug libnfc.chip.pn53x No timeout debug libnfc.driver.acr122_usb TX: 6f 09 00 00 00 00 00 00 00 00 ff 00 00 00 04 d4 4a 01 00 debug libnfc.driver.acr122_usb RX: 80 05 00 00 00 00 00 00 81 00 d5 4b 00 90 00

InitiatorSelectPassiveTarget(): debug libnfc.chip.pn53x InListPassiveTarget debug libnfc.chip.pn53x No timeout debug libnfc.driver.acr122_usb TX: 6f 09 00 00 00 00 00 00 00 00 ff 00 00 00 04 d4 4a 01 00 debug libnfc.driver.acr122_usb RX: 80 00 00 00 00 00 00 00 fe 00 error libnfc.driver.acr122_usb Invalid RDR_to_PC_DataBlock frame debug libnfc.driver.acr122_usb ACR122 Abort

So I thought maybe I shouldn't be listing before calling InitiatorSelectPassiveTarget(), but then I get a different error "Error 1", which is documented neither in the go wrapper nor libnfc:

debug libnfc.chip.pn53x InListPassiveTarget debug libnfc.chip.pn53x No timeout debug libnfc.driver.acr122_usb TX: 6f 09 00 00 00 00 00 00 00 00 ff 00 00 00 04 d4 4a 01 00 debug libnfc.driver.acr122_usb RX: 80 0e 00 00 00 00 00 00 81 00 d5 4b 01 01 00 04 08 04 64 2d f5 6f 90 00 panic: Error 1

Is there any known way of successfully selecting a target using this wrapper?

clausecker commented 9 years ago

The wrapper just wraps the corresponding libnfc calls. In general, just do what you would do in C. Have a look at the examples shipped with the libnfc for more details. I have to admit, I never actually used this wrapper to talk with NFC tags directly, I used it as a stepping stone to wrap the libfreefare.

Please feel free to complain (and reopen this) if you think the API is insufficient or unusually hard to use. Maybe I'm going to find time to translate some of the examples as well.

clausecker commented 9 years ago

As a followup to this, it looks like InitiatorListPassiveTargets() is somehow calling the same underlying function as InitiatorSelectPassiveTarget(), but with different results:

How do you get this impression? I don't remember how the libnfc implements nfc_initiator_list_passive_targets, but it might very well be possible that they call nfc_initiator_select_passive_target internally. I haven't checked.