Class CardChannel
- Since:
- 1.6
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclose()Closes this CardChannel.abstract CardgetCard()Returns the Card this channel is associated with.abstract intReturns the channel number of this CardChannel.abstract inttransmit(ByteBuffer command, ByteBuffer response) Transmits the command APDU stored in the command ByteBuffer and receives the response APDU in the response ByteBuffer.abstract ResponseAPDUtransmit(CommandAPDU command) Transmits the specified command APDU to the Smart Card and returns the response APDU.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Constructor Details
-
CardChannel
protected CardChannel()Constructs a new CardChannel object.This constructor is called by subclasses only. Application should call the Card.getBasicChannel() and Card.openLogicalChannel() methods to obtain a CardChannel object.
-
-
Method Details
-
getCard
Returns the Card this channel is associated with.- Returns:
- the Card this channel is associated with
-
getChannelNumber
public abstract int getChannelNumber()Returns the channel number of this CardChannel. A channel number of 0 indicates the basic logical channel.- Returns:
- the channel number of this CardChannel.
- Throws:
IllegalStateException- if this channel has been closed or if the corresponding Card has been disconnected.
-
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 CHANNELAPDUs. 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 aGET RESPONSEcommand usingSW2as theLefield. This process is repeated as long as an SW1 of61is 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.
- Parameters:
command- the command APDU- Returns:
- the response APDU received from the card
- Throws:
IllegalStateException- if this channel has been closed or if the corresponding Card has been disconnected.IllegalArgumentException- if the APDU encodes aMANAGE CHANNELcommandNullPointerException- if command is nullCardException- if the card operation failed
-
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 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 using the Card.openLogicalChannel() and CardChannel.close() methods.See transmit() for a discussion of the handling of response APDUs with the SW1 values
61or6C.- 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:
IllegalStateException- 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, ifresponsemay not have sufficient space to receive the response APDU or if the APDU encodes aMANAGE CHANNELcommandCardException- if the card operation failed
-
close
Closes this CardChannel. The logical channel is closed by issuing aMANAGE CHANNELcommand that should use the format[xx 70 80 0n]wherenis the channel number of this channel andxxis theCLAbyte 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).- Throws:
CardException- if the card operation failedIllegalStateException- if this CardChannel represents a connection the basic logical channel
-