0

as I wrote in the title, I'm trying to use card emulation using my Nexus S, Cyanogenmod 10.1.3 and the ACS Acr122 usb reader. I found this article http://nelenkov.blogspot.it/2012/10/emulating-pki-smart-card-with-cm91.html and the github with the source code https://github.com/nelenkov/virtual-pki-card. I followed the instructions and it happened a strange thing. While the smartphone is on the reader the connection starts and stops repeatedly thus the demo doesn't work and the client raises this exception:

Exception in thread "main" java.lang.RuntimeException: javax.smartcardio.CardException: connect() failed
    at org.nick.sepkiclient.Main.main(Main.java:105)
Caused by: javax.smartcardio.CardException: connect() failed
    at sun.security.smartcardio.TerminalImpl.connect(Unknown Source)
    at org.nick.sepkiclient.Main.waitForCard(Main.java:166)
    at org.nick.sepkiclient.Main.main(Main.java:48)
Caused by: sun.security.smartcardio.PCSCException: SCARD_E_READER_UNAVAILABLE
    at sun.security.smartcardio.PCSC.SCardStatus(Native Method)
    at sun.security.smartcardio.CardImpl.<init>(Unknown Source)
    ... 3 more

Do you have any idea on how to fix that? Thanks

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
michoprogrammer
  • 1,159
  • 2
  • 18
  • 45

1 Answers1

0

Unfortunately, the ACR 122U NFC reader is not really useable as a smartcard reader. Eventhough it uses PC/SC (CCID) to connect the reader to a PC, most versions of the ACR 122U require you to use reader specific commands and tunnel them over PC/SC. See this question for further information on the tunneling procedure and on available commands.

Community
  • 1
  • 1
Michael Roland
  • 39,663
  • 10
  • 99
  • 206
  • Actually the reader is the ACR 122 not the ACR 122U. I use it for reading smartcard, tag and P2P communication with android devices. The problem right now is that I can't use the card emulation and I don't know why. =/ – michoprogrammer Dec 06 '13 at 09:06
  • According to the [ACS website](http://www.acs.com.hk/en/product-lines/6/contactless-readers/) there is no such thing as a "ACR 122" (i.e. without any letter behind the digits). As you said your reader is using USB it can either be ACR 122U or ACR 122T (same thing, different package). Just to get you right: Are you using the ACR 122x attached to the phone to emulate a card or are you using the ACR 122x to read the card emulated through CM's software card emulation facility? – Michael Roland Dec 06 '13 at 09:53
  • The second one! I'm trying to read the card emulated through CM using the example app that you can find here https://github.com/nelenkov/virtual-pki-card . About the ACR name using this simple code "....terminals.list().get(0).getName()..." I obtain this "ACS ACR122 0", then I though that my ACR was not the ACR 122U, but whatever... :-) – michoprogrammer Dec 06 '13 at 10:04
  • Then we are back with the problem I described above. Nikolay's example for the reader side requires a standard-compiant PC/SC reader -- which ACR 122x is **not**. But if you already used that device for reading contactless cards and tags you should already have some code to work on that implements the direct communication with the NFC chip in that reader. – Michael Roland Dec 06 '13 at 10:13
  • When I use my other libraries to read tag mifare ultrilight with the ACR122x, or for the p2p communication between the ACR122x and an android device (not with CM) it works correctly. When I use this code here https://github.com/nelenkov/virtual-pki-card, the app seems to work correctly, the client side seems to run without any problem, but when I put the smartphone on the reader, the reader it starts making noise and the client raises the exception wrote above and then crashes. – michoprogrammer Dec 06 '13 at 10:48
  • If you have only one smartcard reader connected to your PC, I would be interested in what happens if you replace line 48 (`Card card = waitForCard(terminals);`) with `CardTerminal terminal = terminals.list().get(0); terminal.waitForCardPresent(0); Card card = terminal.connect("*");` With the ACR 122U I have this immediately returns a `Card` object even if no card is placed on the reader, but as your reader seemed to block before, there migth be some differences... – Michael Roland Dec 06 '13 at 13:42
  • I replaced the line as you said and the result is the same. It seems that CM cannot establish a communication channel and when I put the device on, the ACR122x starts trying to establish a connection but it can't and it starts a infinity loop of "trying to connect". It is very strange.. – michoprogrammer Dec 06 '13 at 13:56
  • So the program only passes that line as soon as you put your phone on the reader, right? – Michael Roland Dec 06 '13 at 14:07
  • Btw. are you using Windows and if yes, what version? – Michael Roland Dec 06 '13 at 14:10
  • Also could you give a link to what application you successfully use the reader with for P2P communication or for reading MF UL tags? – Michael Roland Dec 06 '13 at 14:14
  • I set some breakpoint and I can confirm you that during the execution it arrives at the line "Card card = terminal.connect("*");" and it waits. After I put the phone on the ACR122x, the exception is raised. – michoprogrammer Dec 06 '13 at 14:16
  • I'm using Windows 8 pro, with Eclipse Standard/SDKVersion: Kepler Service Release 1. The working library is https://github.com/grundid/nfctools but the purpose of this library is different from card emulation. – michoprogrammer Dec 06 '13 at 14:18
  • No I'm running java 64bit versione – michoprogrammer Dec 06 '13 at 15:11
  • Then I would strongly suggest that you try with a 32-bit version. There are some known issues with smartcardio on the 64-bit version of Oracle Java. – Michael Roland Dec 06 '13 at 15:31
  • That's really odd. I looked through the nfctools library and it seems it uses the same procedure to connect to the reader. – Michael Roland Dec 06 '13 at 16:16
  • But the connection procedure it's always the same, I think that probably there is a problem using CM. I really appreciate your help man ^^ – michoprogrammer Dec 06 '13 at 16:18
  • Well once the program passes `terminal.waitForCardPresent(0);` the `Card card = terminal.connect("*");` should succeed **without** waiting for an actual card (i.e. the reader is supposed to show a dummy card to the PC/SC driver). – Michael Roland Dec 06 '13 at 17:18
  • Always the same problem: `Exception in thread "main" java.lang.RuntimeException: javax.smartcardio.CardException: connect() failed` – michoprogrammer Dec 09 '13 at 09:37