PCSC4Java  0.2
Library PCSC for Java language.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
fr.redbilled.pcscforjava.CardChannel Class Reference

List of all members.

Public Member Functions

abstract Card getCard ()
abstract int getChannelNumber ()
abstract ResponseAPDU transmit (CommandAPDU command, boolean bAutoGetResp, boolean bAutoReissue) throws CardException
abstract int transmit (ByteBuffer command, boolean bAutoGetResp, boolean bAutoReissue, ByteBuffer response) throws CardException
abstract void close () throws CardException

Protected Member Functions

 CardChannel ()

Detailed Description

A logical channel connection to a Smart Card. 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}.

See also:
Card
CommandAPDU
ResponseAPDU
Since:
1.6
Author:
Andreas Sterbenz
JSR 268 Expert Group

Definition at line 44 of file CardChannel.java.


Constructor & Destructor Documentation

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.

Definition at line 54 of file CardChannel.java.


Member Function Documentation

abstract void fr.redbilled.pcscforjava.CardChannel.close ( ) throws CardException [pure virtual]

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:
CardExceptionif the card operation failed
IllegalStateExceptionif this CardChannel represents a connection the basic logical channel

Returns the Card this channel is associated with.

Returns:
the Card this channel is associated with

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

Returns:
the channel number of this CardChannel.
Exceptions:
IllegalStateExceptionif this channel has been close closed} or if the corresponding Card has been Card::disconnect disconnected}.
abstract ResponseAPDU fr.redbilled.pcscforjava.CardChannel.transmit ( CommandAPDU  command,
boolean  bAutoGetResp,
boolean  bAutoReissue 
) throws CardException [pure virtual]

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 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.

If the parameters are setted to true then the ResponseAPDU returned by this method is the result after this processing has been performed.

Parameters:
commandthe command APDU
bAutoGetRespindicates if the automatic get response must be performed or not.
bAutoReissueindicates if the automatic reissue must be performed or not.
Returns:
the response APDU received from the card
Exceptions:
IllegalStateExceptionif this channel has been close closed} or if the corresponding Card has been Card::disconnect disconnected}.
IllegalArgumentExceptionif the APDU encodes a MANAGE CHANNEL command
NullPointerExceptionif command is null
CardExceptionif the card operation failed
abstract int fr.redbilled.pcscforjava.CardChannel.transmit ( ByteBuffer  command,
boolean  bAutoGetResp,
boolean  bAutoReissue,
ByteBuffer  response 
) throws CardException [pure virtual]

Transmits the command APDU stored in the command ByteBuffer and receives the reponse 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 CardChannel.close()} methods.

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

Parameters:
commandthe buffer containing the command APDU
bAutoGetRespindicates if the automatic get response must be performed or not.
bAutoReissueindicates if the automatic reissue must be performed or not.
responsethe buffer that shall receive the response APDU from the card
Returns:
the length of the received response APDU
Exceptions:
IllegalStateExceptionif this channel has been close closed} or if the corresponding Card has been Card::disconnect disconnected}.
NullPointerExceptionif command or response is null
ReadOnlyBufferExceptionif the response buffer is read-only
IllegalArgumentExceptionif 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 command
CardExceptionif the card operation failed

The documentation for this class was generated from the following file: