是否可以在卡不存在时发送伪 APDU 命令?

Is it possible to send Pseudo-APDU commands while card is not present?

我正在使用 javax.smartcardio 包来开发与智能卡相关的应用程序。我想发送伪 ADPU 命令来设置我的 reader 的 LED/LCD 状态。

我发现将 APDU 命令发送到 reader/card 的唯一方法是 CardChannel::transmit,但它必须是存在卡上的 运行。

是否可以在 reader 中不存在卡时发送伪 APDU 命令? APDU命令怎么样? (使用 Java)

我认为以下方法也需要 reader 中的卡片,但仅供参考,我将其张贴在这里是为了说明我们还有另一种终端控制命令的方法:

引自here:

transmitControlCommand:

public abstract byte[] transmitControlCommand(int controlCode,byte[] command) throws CardException

Transmits a control command to the terminal device. This can be used to, for example, control terminal functions like a built-in PIN pad or biometrics.

Parameters:

controlCode - the control code of the command

command - the command data

Throws:

SecurityException - if a SecurityManager exists and the caller does not have the required permission

NullPointerException - if command is null

CardException - if the card operation failed

IllegalStateException - if this card object has been disposed of via the disconnect() method

http://www.springcard.comSDK for PC/SC 中找到了 card-emul 示例的解决方案。这是我的代码:

import java.util.List;

import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.TerminalFactory;

public class TestPcsc {

    public static void main( String[] args ) throws CardException {

        TerminalFactory tf = TerminalFactory.getDefault();
        List< CardTerminal > terminals = tf.terminals().list();
        CardTerminal cardTerminal = (CardTerminal) terminals.get( 0 );

        byte[] command = { (byte) 0xE0, (byte) 0x00, (byte) 0x00, (byte) 0x29, (byte) 0x01, (byte) 0x00 };
        cardTerminal.connect( "DIRECT" ).transmitControlCommand( CONTROL_CODE(), command );

    }

    public static int CONTROL_CODE() {

        String osName = System.getProperty( "os.name" ).toLowerCase();
        if ( osName.indexOf( "windows" ) > -1 ) {
            /* Value used by both MS' CCID driver and SpringCard's CCID driver */
            return (0x31 << 16 | 3500 << 2);
        }
        else {
            /* Value used by PCSC-Lite */
            return 0x42000000 + 1;
        }

    }

}

我认为的要点是:

  1. 使用DIRECT协议获取'card'
  2. 使用Card::transmitControlCommand方法和从CONTROL_CODE函数中得到的代码(复制自示例代码,不确定理论是什么>_<)