Top Description Fields Constructors Methods
sun.security.smartcardio

pack-priv final Class ChannelImpl

extends CardChannel
Class Inheritance
Imports
java.nio.*, java.security.AccessController, .PrivilegedAction, javax.smartcardio.*

CardChannel implementation.
Author
Andreas Sterbenz
Since
1.6

Field Summary

Modifier and TypeField and Description
private static final byte[]
private final CardImpl
private final int
private volatile boolean
private static final int
private static final boolean
private static final boolean
private static final boolean

Constructor Summary

AccessConstructor and Description
pack-priv
ChannelImpl(CardImpl card, int channel)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
private static void
public void
close()

Implements abstract javax.smartcardio.CardChannel.close.

Closes this CardChannel.

private byte[]
concat(byte[] b1, byte[] b2, int n2)

private byte[]
doTransmit(byte[] command)

private static boolean
getBooleanProperty(String name, boolean def)

public Card
getCard()

Implements abstract javax.smartcardio.CardChannel.getCard.

Returns the Card this channel is associated with.

public int
getChannelNumber()

Implements abstract javax.smartcardio.CardChannel.getChannelNumber.

Returns the channel number of this CardChannel.

private static int
getSW(byte[] res)

private static boolean
isOK(byte[] res)

private void
setChannel(byte[] com)

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public ResponseAPDU
transmit(CommandAPDU
the command APDU
command
)

Implements abstract javax.smartcardio.CardChannel.transmit.

Transmits the specified command APDU to the Smart Card and returns the response APDU.

public int
transmit(ByteBuffer
the buffer containing the command APDU
command
,
ByteBuffer
the buffer that shall receive the response APDU from the card
response
)

Implements abstract javax.smartcardio.CardChannel.transmit.

Transmits the command APDU stored in the command ByteBuffer and receives the response APDU in the response ByteBuffer.

Field Detail

B0back to summary
private static final byte[] B0
cardback to summary
private final CardImpl card
channelback to summary
private final int channel
isClosedback to summary
private volatile boolean isClosed
RESPONSE_ITERATIONSback to summary
private static final int RESPONSE_ITERATIONS
t0GetResponseback to summary
private static final boolean t0GetResponse
t1GetResponseback to summary
private static final boolean t1GetResponse
t1StripLeback to summary
private static final boolean t1StripLe

Constructor Detail

ChannelImplback to summary
pack-priv ChannelImpl(CardImpl card, int channel)

Method Detail

checkClosedback to summary
pack-priv void checkClosed()
checkManageChannelback to summary
private static void checkManageChannel(byte[] b)
closeback to summary
public void close() throws CardException

Implements abstract javax.smartcardio.CardChannel.close.

Doc from javax.smartcardio.CardChannel.close.

Closes this CardChannel. The logical channel is closed by issuing a MANAGE CHANNEL command that should use the format [xx 70 80 0n] where n is the channel number of this channel and xx is the CLA byte that encodes this logical channel and has all other bits set to 0. After this method returns, calling other methods in this class will raise an IllegalStateException.

Note that the basic logical channel cannot be closed using this method. It can be closed by calling Card#disconnect.

Exceptions
CardException:
if the card operation failed
concatback to summary
private byte[] concat(byte[] b1, byte[] b2, int n2)
doTransmitback to summary
private byte[] doTransmit(byte[] command) throws CardException
getBooleanPropertyback to summary
private static boolean getBooleanProperty(String name, boolean def)
getCardback to summary
public Card getCard()

Implements abstract javax.smartcardio.CardChannel.getCard.

Doc from javax.smartcardio.CardChannel.getCard.

Returns the Card this channel is associated with.

Returns:Card

the Card this channel is associated with

getChannelNumberback to summary
public int getChannelNumber()

Implements abstract javax.smartcardio.CardChannel.getChannelNumber.

Doc from javax.smartcardio.CardChannel.getChannelNumber.

Returns the channel number of this CardChannel. A channel number of 0 indicates the basic logical channel.

Returns:int

the channel number of this CardChannel.

getSWback to summary
private static int getSW(byte[] res) throws CardException
isOKback to summary
private static boolean isOK(byte[] res) throws CardException
setChannelback to summary
private void setChannel(byte[] com)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

transmitback to summary
public ResponseAPDU transmit(CommandAPDU command) throws CardException

Implements abstract javax.smartcardio.CardChannel.transmit.

Doc from javax.smartcardio.CardChannel.transmit.

Transmits the specified command APDU to the Smart Card and returns the response APDU.

The CLA byte of the command APDU is automatically adjusted to match the channel number of this CardChannel.

Note that this method cannot be used to transmit MANAGE CHANNEL APDUs. Logical channels should be managed using the Card#openLogicalChannel and CardChannel.close() methods.

Implementations should transparently handle artifacts of the transmission protocol. For example, when using the T=0 protocol, the following processing should occur as described in ISO/IEC 7816-4:

  • if the response APDU has an SW1 of 61, the implementation should issue a GET RESPONSE command using SW2 as the Lefield. This process is repeated as long as an SW1 of 61 is received. The response body of these exchanges is concatenated to form the final response body.

  • if the response APDU is 6C XX, the implementation should reissue the command using XX as the Le field.

The ResponseAPDU returned by this method is the result after this processing has been performed.

Parameters
command:CommandAPDU

the command APDU

Returns:ResponseAPDU

the response APDU received from the card

Exceptions
CardException:
if the card operation failed
transmitback to summary
public int transmit(ByteBuffer command, ByteBuffer response) throws CardException

Implements abstract javax.smartcardio.CardChannel.transmit.

Doc from javax.smartcardio.CardChannel.transmit.

Transmits the command APDU stored in the command ByteBuffer and receives the response APDU in the response ByteBuffer.

The command buffer must contain valid command APDU data starting at command.position() and the APDU must be command.remaining() bytes long. Upon return, the command buffer's position will be equal to its limit; its limit will not have changed. The output buffer will have received the response APDU bytes. Its position will have advanced by the number of bytes received, which is also the return value of this method.

The CLA byte of the command APDU is automatically adjusted to match the channel number of this CardChannel.

Note that this method cannot be used to transmit MANAGE CHANNEL APDUs. Logical channels should be managed using the Card#openLogicalChannel and CardChannel.close() methods.

See transmit() for a discussion of the handling of response APDUs with the SW1 values 61 or 6C.

Parameters
command:ByteBuffer

the buffer containing the command APDU

response:ByteBuffer

the buffer that shall receive the response APDU from the card

Returns:int

the length of the received response APDU

Exceptions
CardException:
if the card operation failed