wizzomafizzo / mrext

Collection of extensions and utilities for the MiSTer system.
GNU General Public License v3.0
171 stars 11 forks source link

Error using ACR122U-A9 #37

Open starkninja opened 1 year ago

starkninja commented 1 year ago

nfc.sh throws a repeated errors when ACR122U-A9 is connected

after "opened connection : ACS / ACR122U PICC Int..." message "error during poll: error polling: inp..." beeping sound repeats until script is stopped

looking for output logs so that i can view the full messages. connected NFC reader seems to have inconsistent status (light off/red/green) but error loops regardless of status indicator.

Error screenshot: MisterNFC Error

USB Reader: NFC USB Reader

wizzomafizzo commented 1 year ago

Hi mate. Looks to be the right card reader, matches up with mine. Though it's interesting, my one has zero status light output on mister, although the status light works as expected on a PC.

I'll need to get the full log file from you and see that rest of that error line. Are you familiar with copying a file from mister of SSH? You will need to make the error happen again and then, without turning off the mister, copy the file /tmp/nfc.log to your computer and upload it here

If you're not sure I will find some instructions

starkninja commented 1 year ago

I did my own research on SSH and got access to the log. Thanks for taking a look!

/tmp# cat nfc.log
2023/08/18 23:49:50 INFO starting nfc service
2023/08/18 23:49:50 ERROR error loading database: empty csv file given
2023/08/18 23:49:50 INFO opened connection: ACS / ACR122U PICC Interface acr122_usb:001:005
2023/08/18 23:49:50 INFO polling for 20 times with 300ms delay
2023/08/18 23:49:50 ERROR error during poll: error polling: input / output error

That last line repeats on every poll, and then when stopping...

2023/08/18 23:50:09 INFO stopping nfc service
2023/08/18 23:50:09 ERROR error accepting connection: accept unix /tmp/nfc.sock: use of closed network connection

And just to test, I connected the NFC reader to a different USB port to make sure that was not the issue. It correctly identified the port switch: 2023/08/19 00:49:16 INFO opened connection: ACS / ACR122U PICC Interface acr122_usb:001:008

A few other bits of information:

wizzomafizzo commented 1 year ago

Recently I put out a new release of the app. Has there been any improvement?

I don't think it will fix the issue but may help make troubleshooting easier

It would also be good to try this reader on a PC if you can. To make sure it's definitely not faulty or anything

starkninja commented 1 year ago

Here is the log from the most recent release:

2023/08/21 15:57:55 INFO starting nfc service
2023/08/21 15:57:55 INFO no database file found, skipping
2023/08/21 15:57:55 ERROR error watching database: no such file or directory
2023/08/21 15:57:56 INFO opened connection: ACS / ACR122U PICC Interface acr122_usb:001:007
2023/08/21 15:57:56 INFO polling for 20 times with 300ms delay
2023/08/21 15:57:56 ERROR error during poll: input / output error
2023/08/21 15:57:56 ERROR fatal IO error, device was unplugged, exiting...

The last 4 lines then repeat every poll.

It would also be good to try this reader on a PC if you can. To make sure it's definitely not faulty or anything

It took trying a few apps to find one that detected the reader, but it seems to be working: image

Also looks ok in Device Manager: image

docbobo commented 1 year ago

Though it's interesting, my one has zero status light output on mister, although the status light works as expected on a PC.

Totally unrelated to the general topic of this issue, but I just stumbled across the following libnfc issue when wondering about the ACR122U status light myself. So mostly an FYI.

https://github.com/nfc-tools/libnfc/issues/524

ernie76 commented 1 year ago

I have the same problem. The reader don't scan anythings. Her are the log file:

/tmp# cat nfc.log
1970/01/01 01:00:47 INFO starting nfc service
1970/01/01 01:00:47 INFO loaded 0 entries from database
1970/01/01 01:00:47 INFO opened connection: ACS / ACR122U PICC Interface acr122_usb:001:004
1970/01/01 01:00:47 INFO polling for 20 times with 300ms delay
2023/08/22 13:02:30 INFO stopping nfc service
2023/08/22 13:02:30 ERROR error accepting connection: accept unix /tmp/nfc.sock: use of closed network connection
2023/08/22 13:02:38 INFO starting nfc service
2023/08/22 13:02:38 INFO loaded 0 entries from database
2023/08/22 13:02:38 INFO opened connection: ACS / ACR122U PICC Interface acr122_usb:001:004
2023/08/22 13:02:38 INFO polling for 20 times with 300ms delay
2023/08/22 13:05:11 INFO stopping nfc service
2023/08/22 13:05:11 ERROR error accepting connection: accept unix /tmp/nfc.sock: use of closed network connection
2023/08/22 13:05:31 INFO starting nfc service
2023/08/22 13:05:31 INFO loaded 0 entries from database
2023/08/22 13:05:32 INFO opened connection: ACS / ACR122U PICC Interface acr122_usb:001:004
2023/08/22 13:05:32 INFO polling for 20 times with 300ms delay
2023/08/22 13:06:15 INFO stopping nfc service
2023/08/22 13:06:15 ERROR error accepting connection: accept unix /tmp/nfc.sock: use of closed network connection
2023/08/22 13:06:34 INFO starting nfc service
2023/08/22 13:06:34 INFO loaded 0 entries from database
2023/08/22 13:06:35 INFO opened connection: ACS / ACR122U PICC Interface acr122_usb:001:007
2023/08/22 13:06:35 INFO polling for 20 times with 300ms delay
wizzomafizzo commented 1 year ago

It took trying a few apps to find one that detected the reader, but it seems to be working: image

Also looks ok in Device Manager: image

At the moment these Mifare card aren't compatible with the script. You'll need to use some of the NTAG cards mentioned in the readme. We'll support them eventually, but it's not quite as straightforward. I'll try get them working soon

So, that's one thing. You'll have to either wait a bit until I've added support, or get some NTAG cards to test, otherwise it definitely won't work for sure. I'm still unsure about the error. I have Mifare cards too but I get an "RF transmission error" not an IO error

Though it's interesting, my one has zero status light output on mister, although the status light works as expected on a PC.

Totally unrelated to the general topic of this issue, but I just stumbled across the following libnfc issue when wondering about the ACR122U status light myself. So mostly an FYI.

nfc-tools/libnfc#524

Thanks for the link! We're already using a custom version of libnfc so it may not be such a big deal to add this in

I have the same problem. The reader don't scan anythings. Her are the log file:

2023/08/22 13:06:34 INFO starting nfc service 2023/08/22 13:06:34 INFO loaded 0 entries from database 2023/08/22 13:06:35 INFO opened connection: ACS / ACR122U PICC Interface acr122_usb:001:007 2023/08/22 13:06:35 INFO polling for 20 times with 300ms delay

To me this looks like it's working fine! Is there anything in particular that's happening which makes you think it's not working? The script and reader won't really do anything until you try to scan a card with some valid data on it

ernie76 commented 1 year ago

I try to scan a Lego Dimension Figur, but nothing happens. Lego Dimensions figur are NTAG213.

wizzomafizzo commented 1 year ago

I've been investigating this with some other affected people. There's a couple things going on:

starkninja commented 1 year ago

thanks for the follow up. the price i paid makes more sense if it's a clone. i can send it your way if that would help

wizzomafizzo commented 1 year ago

Hi everyone. The script has just been updated with support for Mifare tags. This won't fix issues with the incompatible scanner but I think it'll get things working for some of you. Please give it a shot!

doccaz commented 1 year ago

So, I got one of these clones, and it also doesn't work. I opened it up and it has a blob chip, which was not a good sign. Anyway, I found this issue at the nfc-tools project about it: https://github.com/nfc-tools/libnfc/issues/576#issuecomment-706361288

Apparently, it will work if the usb_altinterface call is removed from the startup in libnfc. Maybe add a flag for a clone that would do that? Maybe there is something to distinguish the clone from the original USB-wise? For example, mine shows iSerial as 0.

You can see this by calling "lsusb -vv -d 072f:2200".

wizzomafizzo commented 1 year ago

Wow nice find!! Let me put a test build together later today

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: Erico Mendonca @.> Sent: Wednesday, September 13, 2023 10:45:27 AM To: wizzomafizzo/mrext @.> Cc: Callan Barrett @.>; Comment @.> Subject: Re: [wizzomafizzo/mrext] Error using ACR122U-A9 (Issue #37)

So, I got one of these clones, and it also doesn't work. I opened it up and it has a blob chip, which was not a good sign. Anyway, I found this issue at the nfc-tools project about it: nfc-tools/libnfc#576 (comment)https://github.com/nfc-tools/libnfc/issues/576#issuecomment-706361288

Apparently, it will work if the usb_altinterface call is removed from the startup in libnfc. Maybe add a flag for a clone that would do that? Maybe there is something to distinguish the clone from the original USB-wise? For example, mine shows iSerial as 0.

You can see this by calling "lsusb -vv -d 072f:2200".

— Reply to this email directly, view it on GitHubhttps://github.com/wizzomafizzo/mrext/issues/37#issuecomment-1716860557, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AADMA3U4FI5NPHL2USCZYFDX2EM4PANCNFSM6AAAAAA3UUEI6Y. You are receiving this because you commented.Message ID: @.***>

wizzomafizzo commented 1 year ago
Bus 001 Device 006: ID 072f:2200 Advanced Card Systems, Ltd ACR122U
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x072f Advanced Card Systems, Ltd
  idProduct          0x2200 ACR122U
  bcdDevice            2.14
  iManufacturer           1 ACS
  iProduct                2 ACR122U PICC Interface
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x005d
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              200mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass        11 Chip/SmartCard
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
      ChipCard Interface Descriptor:
        bLength                54
        bDescriptorType        33
        bcdCCID              1.00
        nMaxSlotIndex           0
        bVoltageSupport         7  5.0V 3.0V 1.8V 
        dwProtocols             2  T=1
        dwDefaultClock       4000
        dwMaxiumumClock      4000
        bNumClockSupported      0
        dwDataRate          10752 bps
        dwMaxDataRate      250000 bps
        bNumDataRatesSupp.      0
        dwMaxIFSD             256
        dwSyncProtocols  00000000 
        dwMechanical     00000000 
        dwFeatures       00020040
          Auto parameter negotiation made by CCID
          Short APDU level exchange
        dwMaxCCIDMsgLen       271
        bClassGetResponse      00
        bClassEnvelope         00
        wlcdLayout           none
        bPINSupport             0 
        bMaxCCIDBusySlots       1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              50
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               1
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0002
  (Bus Powered)
  Remote Wakeup Enabled

Let me know if anything here is different!

wizzomafizzo commented 1 year ago

I've applied the patch shown in the linked issue. Please give it a shot and let me know if it's changed anything for you

My genuine reader appears to be working fine still, will need more testing but we may not even need to detect

nfc.zip

ernie76 commented 1 year ago

the new nfc.sh is not working with my reader :(

doccaz commented 1 year ago

Let me know if anything here is different!

Here is mine:

Bus 001 Device 006: ID 072f:2200 Advanced Card Systems, Ltd ACR122U
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               1.10
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0         8
  idVendor           0x072f Advanced Card Systems, Ltd
  idProduct          0x2200 ACR122U
  bcdDevice            2.07
  iManufacturer           1 ACS
  iProduct                2 ACR122U PICC Interface
  iSerial                 0 
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x005d
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              200mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass        11 Chip/SmartCard
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
      ChipCard Interface Descriptor:
        bLength                54
        bDescriptorType        33
        bcdCCID              1.00
        nMaxSlotIndex           0
        bVoltageSupport         7  5.0V 3.0V 1.8V 
        dwProtocols             2  T=1
        dwDefaultClock       4000
        dwMaxiumumClock      4000
        bNumClockSupported      0
        dwDataRate          10752 bps
        dwMaxDataRate      250000 bps
        bNumDataRatesSupp.      0
        dwMaxIFSD             256
        dwSyncProtocols  00000000 
        dwMechanical     00000000 
        dwFeatures       00020040
          Auto parameter negotiation made by CCID
          Short APDU level exchange
        dwMaxCCIDMsgLen       271
        bClassGetResponse      00
        bClassEnvelope         00
        wlcdLayout           none
        bPINSupport             0 
        bMaxCCIDBusySlots       1
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval               2
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0040  1x 64 bytes
        bInterval               0
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0000
  (Bus Powered)

It appears to be identical to yours, except for the bcdDevice field.

Unfortunately, the patched binary did not work for me. Still got the same I/O error.

doccaz commented 12 months ago

Looking again at the issues on the original project, it appears that this reader has many, many problems with different proposed solutions: https://github.com/nfc-tools/libnfc/issues/646 https://github.com/nfc-tools/libnfc/issues/691 https://github.com/nfc-tools/libnfc/pull/678

I'll look into getting it to work with my Linux machine first, if I find out something relevant, I'll report back.

wizzomafizzo commented 12 months ago

https://github.com/nfc-tools/libnfc/pull/678

Not sure if this helps at all but I am actually using a fork of libnfc that includes this patch. You can see here:

https://github.com/wizzomafizzo/mrext/blob/f7aad9a78573463ab2193d04acfeaec4e2794553/scripts/armbuild/Dockerfile#L24

I thought this was necessary to get my ACR122U working in the first place. I have tested since then using the official repo (which is many commits ahead of that fork) and it does work but it would continuously error out when I tried to poll the device. That was awkward to handle so I left the fork for now

Anyway just something to keep in mind

wizzomafizzo commented 12 months ago

And here is an example of building the NFC script with a patch:

https://github.com/wizzomafizzo/mrext/compare/main...fix-clone-reader

doccaz commented 11 months ago

And here is an example of building the NFC script with a patch:

main...fix-clone-reader

Interesting, I got it to work with this version, but it's acting a bit weird. Basically, it'll fail like before with I/O errors (and beep every few seconds), BUT if I place a card on top of the reader, it initializes the reader, reads the card, and launches the game. If I remove the card... another closed connection, IO error, and beep.

BTW, I got your Dockerfile, but I had to add "linux-libc-dev" to the apt-get install line so it could finish compiling libnfc. I then logged in to the container, cloned your repository, and compiled nfc.sh.

doccaz commented 11 months ago

I was in process of compiling libnfc with debug, when I remembered to check the udev messages. Whenever there was an error on nfc.sh, I got quite a few unbind/remove messages on "udevadm monitor". Looking at dmesg, I noticed that there is a regular USB reset happening:

[ 5166.856201] usb 1-1.5: reset full-speed USB device number 8 using dwc2

Well, device 1-1 in this case is the USB hub plugged into the DE-10, according to "lsusb -t". Mine is the generic AliExpress 7-port hub board with the official MiSTer design.

I then plugged a USB voltage monitor on the MiSTer to check the reader's current usage. It stays at around 20mA on standby, and around 80mA when nfc.sh starts the service. Voltage was around 4.93V, which I found low.

I started pulling USB devices out, like my MT32pi, the Bluetooth dongle, and the keyboard, leaving only the Wifi and the reader. The voltage went up to almost exactly 5.0V, but the resets still occur.

Looking at my USB voltage meter (which is also a datalogger), I see this:

IMG_20231003_221010581

... the reader is pulling in peaks of 200mA (or more) and the USB voltage is going down to as much as 4.9V. So that appears to be the cause of the resets: this cheap clone reader consumes too much current. I'll try with a separate powered hub next to see what happens.

doccaz commented 11 months ago

And plugging the reader to a computer, I can see that 200mA is its standby current after initializing the reader, going up to 400mA when reading a card. So, there is your problem...