public abstract class CardChannel extends Object
Modifier | Constructor | Description |
---|---|---|
protected |
Constructs a new CardChannel object. |
Modifier and Type | Method | Description |
---|---|---|
abstract void |
close() |
Closes this CardChannel. |
abstract Card |
getCard() |
Returns the Card this channel is associated with. |
abstract int |
getChannelNumber() |
Returns the channel number of this CardChannel. |
abstract int |
transmit |
Transmits the command APDU stored in the command ByteBuffer and receives the response APDU in the response ByteBuffer. |
abstract ResponseAPDU |
transmit |
Transmits the specified command APDU to the Smart Card and returns the response APDU. |
protected CardChannel()
This constructor is called by subclasses only. Application should call the Card.getBasicChannel() and Card.openLogicalChannel() methods to obtain a CardChannel object.
public abstract Card getCard()
public abstract int getChannelNumber()
IllegalStateException
- if this channel has been closed or if the corresponding Card has been disconnected.public abstract ResponseAPDU transmit(CommandAPDU command) throws CardException
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 Le
field. 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.
command
- the command APDUIllegalStateException
- if this channel has been closed or if the corresponding Card has been disconnected.IllegalArgumentException
- if the APDU encodes a MANAGE CHANNEL
commandNullPointerException
- if command is nullCardException
- if the card operation failedpublic abstract int transmit(ByteBuffer command, ByteBuffer response) throws CardException
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
.
command
- the buffer containing the command APDUresponse
- the buffer that shall receive the response APDU from the cardIllegalStateException
- if this channel has been closed or if the corresponding Card has been disconnected.NullPointerException
- if command or response is nullReadOnlyBufferException
- if the response buffer is read-onlyIllegalArgumentException
- if command and response are the same object, if response
may not have sufficient space to receive the response APDU or if the APDU encodes a MANAGE CHANNEL
commandCardException
- if the card operation failedpublic abstract void close() throws CardException
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(boolean)
.
CardException
- if the card operation failedIllegalStateException
- if this CardChannel represents a connection the basic logical channel
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.smartcardio/javax/smartcardio/CardChannel.html