I am using the javax.smartcardio
package for developing smart card related applications. I want to send Pseudo ADPU commands to set my reader's LED / LCD status.
I found that the only method to send APDU commands to reader/card is CardChannel::transmit
, but it must be run on card present .
Is it possible to send Pseudo-APDU commands while card is not present in the reader? what about the APDU commands? (Using Java)
Found a solution from sample of card-emul in SDK for PC/SC
in http://www.springcard.com. Here is my code:
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;
}
}
}
I think the points are:
DIRECT
protocol to get the 'card'Card::transmitControlCommand
method with the code got from CONTROL_CODE function (copied from the sample code, not sure what the theory is >_<)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With