简体   繁体   中英

JavaSmartCardIO- How to handle timeout exception of PC/SC connection?

When card reader connect to card and send command, in case the time to send command and receive response is, is system notify timeout exception automatically ?
If so, What is timeout value of PC/SC ?
Or I must define that value?

Well, there are two methods available useful to handle exceptions when there is no card available in the reader:

boolean sun.security.smartcardio.TerminalImpl.waitForCardAbsent ( long timeout ) throws CardException [virtual]

Waits until a card is absent in this terminal or the timeout expires. If the method returns due to an expired timeout, it returns false. Otherwise it return true.

If no card is present in this terminal when this method is called, it returns immediately.

Parameters: timeout if positive, block for up to timeout milliseconds; if zero, block indefinitely; must not be negative

Returns: false if the method returns due to an expired timeout, true otherwise.

Exceptions: IllegalArgumentException if timeout is negative , CardException if the operation failed

Implements javax.smartcardio.CardTerminal .

Definition at line 136 of file TerminalImpl.java .

boolean sun.security.smartcardio.TerminalImpl.waitForCardPresent (long timeout) throws CardException [virtual]

Waits until a card is present in this terminal or the timeout expires. If the method returns due to an expired timeout, it returns false. Otherwise it return true.

If a card is present in this terminal when this method is called, it returns immediately.

Parameters: timeout if positive, block for up to timeout milliseconds; if zero, block indefinitely; must not be negative

Returns: false if the method returns due to an expired timeout, true otherwise.

Exceptions: IllegalArgumentException if timeout is negative , CardException if the operation failed Implements javax.smartcardio.CardTerminal .

Definition at line 132 of file TerminalImpl.java .


For card's response timeout, you should first check your reader manual. some smart card readers have some additional features other than sending APDU commands to the card. This commands called "Pseudo APDU". For example I have an ACR38 contact smart card reader and I found the following in its manual:

(From here page 14) 在此输入图像描述


Finally if you didn't found anything useful in your reader's manual, I think you have two options:

  • Implementing a timeout method in your multi-threaded java program that is executing always and calculate the time after sending each command and check to see if the response time is greater that a specific value or not. In cases that the time is greater than your specific value, it call the disconnect method and reconnect it and then you can handle it in such a way.
  • Engaging with PCSC/CCID library functions to control this timeout.

Check the following links, I think you can find something useful there to aim your goal:

http://www.openscdp.org/ocf/api/de/cardcontact/opencard/terminal/smartcardio/PCSCIOControl.html

http://ludovic.rousseau.free.fr/softwares/pcsc-perl/PCSC.html

https://github.com/credentials/smartcardjs/blob/master/ext/scuba/acr122provider/src/net/sourceforge/scuba/smartcards/ACR122TerminalFactorySpi.java

http://myacr38.blogspot.com/2007/05/program.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM