- All Implemented Interfaces:
ApduLayer,MessageLayer
It is used to exchange APDUs with a Smart Card. A CardChannel object can be obtained by
calling the method Card.getBasicChannel() or Card.openLogicalChannel().
- Author:
- gematik
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this card channel.getCard()Returns the Card this channel is associated with.intReturns the channel number of this CardChannel.doublegetTime()Returns execution time of previous command-response pair.voidreset()Resets this card channel.byte[]send(byte[] command) Sends given message and returns the corresponding response.send(CommandApdu apdu) Sends given command APDU.toString()ReturnsStringrepresentation.inttransmit(ByteBuffer command, ByteBuffer response) Transmits the command APDU stored in the commandByteBufferand receives the response APDU in the responseByteBuffer.transmit(CommandAPDU command) Transmits the specified command APDU to the Smart Card and returns the response APDU.
-
Method Details
-
send
public byte[] send(byte[] command) Sends given message and returns the corresponding response.The CLA byte of the command APDU is automatically adjusted to match the channel number of this card channel.
Note that this method cannot be used to transmit
MANAGE CHANNELAPDUs. Logical channels should be managed by usingThis method is used by the implementation of
send(CommandApdu). The purpose of this method is to provide a transparent channel. E.g., if aCommandApduis constructed from octet string'00 B0 8102 00 0003'(i.e., READ BINARY with ShortFileIdentifier=1 and offset=2 and Ne=3, ISO-case 2E (extended)), thensend(CommandApdu)converts thatCommandApduto'00 B0 8102 03'(i.e., ISO-case 2S (short)).- Specified by:
sendin interfaceMessageLayer- Parameters:
command- command APDU- Returns:
- corresponding response APDU
- Throws:
IllegalArgumentException- ifapduencodes aMANAGE CHANNELcommandIllegalStateException- if- this channel has been
closed - the corresponding
Cardhas beendisconnected
- this channel has been
- See Also:
-
send
Sends given command APDU.The CLA byte of the command APDU is automatically adjusted to match the channel number of this card channel.
Note that this method cannot be used to transmit
MANAGE CHANNELAPDUs. Logical channels should be managed by usingE.g. if a
CommandApduis constructed from octet string'00 B0 8102 00 0003'(i.e READ BINARY with ShortFileIdentifier=1 and offset=2 and Ne=3, ISO-case 2E (extended)), then this method converts thatCommandApduto'00 B0 8102 03'(i.e. ISO-case 2S (short)). Thus, if the intention is to send an ISO-case 2E methodsend(byte[])has to be used.- Specified by:
sendin interfaceApduLayer- Parameters:
apdu- command APDU to be sent- Returns:
- corresponding
ResponseApdu - Throws:
IllegalArgumentException- ifapduencodes aMANAGE CHANNELcommandIllegalStateException- if- this channel has been
closed - the corresponding
Cardhas beendisconnected
- this channel has been
- See Also:
-
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 card channel.
Note that this method cannot be used to transmit
MANAGE CHANNELAPDUs. Logical channels should be managed by usingImplementations 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 aGET RESPONSEcommand usingSW2as theLefield. This process is repeated as long as anSW1of61is 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 usingXXas theLefield.
The ResponseAPDU returned by this method is the result after this processing has been performed.
- Specified by:
transmitin classCardChannel- Parameters:
command- the command APDU- Returns:
- the response APDU received from the card
- Throws:
IllegalStateException- if- this channel has been
closed - the corresponding
Cardhas beendisconnected
- this channel has been
IllegalArgumentException- if the APDU encodes aMANAGE CHANNELcommandNullPointerException- if command is null
- if the response APDU has an SW1 of
-
transmit
Transmits the command APDU stored in the commandByteBufferand receives the response APDU in the responseByteBuffer.The command buffer must contain a valid command APDU data starting at
command.position()and the APDU must becommand.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 CHANNELAPDUs. Logical channels should be managed by usingSee
transmit(CommandAPDU)for a discussion of the handling of response APDUs in case of protocol "T=0".- Specified by:
transmitin classCardChannel- Parameters:
command- the buffer containing the command APDUresponse- the buffer that shall receive the response APDU from the card- Returns:
- the length of the received response APDU
- Throws:
IllegalArgumentException- ifcommandandresponseare the same objectresponsemay not have sufficient space to receive the response APDUcommandencodes aMANAGE CHANNELcommand
IllegalStateException- if- this channel has been
closed - the corresponding
Cardhas beendisconnected
- this channel has been
NullPointerException- if command or response is nullReadOnlyBufferException- if the response buffer is read-only
-
close
Closes this card channel.The logical channel is closed by issuing a
MANAGE CHANNELcommand that use the format[xx 70 80 00]xxis theCLAbyte that encodes this logical channel. After this method returns, calling other methods in this class will raise anIllegalStateException.Note that the basic logical channel cannot be closed using this method. It can be closed by calling
Card.disconnect(boolean).- Specified by:
closein classCardChannel- Throws:
CardException- if the card operation failedIllegalStateException- if this CardChannel represents a connection the basic logical channel
-
reset
Resets this card channel.- Throws:
CardException- if the card operation failedIllegalStateException- if- this channel has been
closed - the corresponding
Cardhas beendisconnected
- this channel has been
-
getCard
Returns the Card this channel is associated with.- Specified by:
getCardin classCardChannel- Returns:
- the Card this channel is associated with
-
getChannelNumber
public int getChannelNumber()Returns the channel number of this CardChannel.A channel number of 0 indicates the basic logical channel.
- Specified by:
getChannelNumberin classCardChannel- Returns:
- the channel number of this CardChannel
- Throws:
IllegalStateException- if- this channel has been
closed - if the corresponding Card has been
disconnected
- this channel has been
-
getTime
public double getTime()Returns execution time of previous command-response pair.- Specified by:
getTimein interfaceMessageLayer- Returns:
- execution time in seconds of previous command-response pair
-
toString
ReturnsStringrepresentation.
-