Reputation: 81
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)
Upvotes: 5
Views: 2331
Reputation: 81
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 >_<)Upvotes: 3
Reputation: 6116
I think the following method needs a card present in the reader also, but just for your information I posted it here to say that we there is another method for terminal controlling commands:
Quoted from 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
Upvotes: 1