Path: blob/master/src/java.smartcardio/share/classes/javax/smartcardio/Card.java
41153 views
/*1* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.smartcardio;2627import java.nio.ByteBuffer;2829/**30* A Smart Card with which a connection has been established. Card objects31* are obtained by calling {@link CardTerminal#connect CardTerminal.connect()}.32*33* @see CardTerminal34*35* @since 1.636* @author Andreas Sterbenz37* @author JSR 268 Expert Group38*/39public abstract class Card {4041/**42* Constructs a new Card object.43*44* <p>This constructor is called by subclasses only. Application should45* call the {@linkplain CardTerminal#connect CardTerminal.connect()}46* method to obtain a Card47* object.48*/49protected Card() {50// empty51}5253/**54* Returns the ATR of this card.55*56* @return the ATR of this card.57*/58public abstract ATR getATR();5960/**61* Returns the protocol in use for this card.62*63* @return the protocol in use for this card, for example "T=0" or "T=1"64*/65public abstract String getProtocol();6667/**68* Returns the CardChannel for the basic logical channel. The basic69* logical channel has a channel number of 0.70*71* @return the CardChannel for the basic logical channel72* @throws SecurityException if a SecurityManager exists and the73* caller does not have the required74* {@linkplain CardPermission permission}75* @throws IllegalStateException if this card object has been disposed of76* via the {@linkplain #disconnect disconnect()} method77*/78public abstract CardChannel getBasicChannel();7980/**81* Opens a new logical channel to the card and returns it. The channel is82* opened by issuing a <code>MANAGE CHANNEL</code> command that should use83* the format <code>[00 70 00 00 01]</code>.84*85* @return the logical channel which has been opened86* @throws SecurityException if a SecurityManager exists and the87* caller does not have the required88* {@linkplain CardPermission permission}89* @throws CardException is a new logical channel could not be opened90* @throws IllegalStateException if this card object has been disposed of91* via the {@linkplain #disconnect disconnect()} method92*/93public abstract CardChannel openLogicalChannel() throws CardException;9495/**96* Requests exclusive access to this card.97*98* <p>Once a thread has invoked <code>beginExclusive</code>, only this99* thread is allowed to communicate with this card until it calls100* <code>endExclusive</code>. Other threads attempting communication101* will receive a CardException.102*103* <p>Applications have to ensure that exclusive access is correctly104* released. This can be achieved by executing105* the <code>beginExclusive()</code> and <code>endExclusive</code> calls106* in a <code>try ... finally</code> block.107*108* @throws SecurityException if a SecurityManager exists and the109* caller does not have the required110* {@linkplain CardPermission permission}111* @throws CardException if exclusive access has already been set112* or if exclusive access could not be established113* @throws IllegalStateException if this card object has been disposed of114* via the {@linkplain #disconnect disconnect()} method115*/116public abstract void beginExclusive() throws CardException;117118/**119* Releases the exclusive access previously established using120* <code>beginExclusive</code>.121*122* @throws SecurityException if a SecurityManager exists and the123* caller does not have the required124* {@linkplain CardPermission permission}125* @throws IllegalStateException if the active Thread does not currently have126* exclusive access to this card or127* if this card object has been disposed of128* via the {@linkplain #disconnect disconnect()} method129* @throws CardException if the operation failed130*/131public abstract void endExclusive() throws CardException;132133/**134* Transmits a control command to the terminal device.135*136* <p>This can be used to, for example, control terminal functions like137* a built-in PIN pad or biometrics.138*139* @param controlCode the control code of the command140* @param command the command data141* @return the response from the terminal device142*143* @throws SecurityException if a SecurityManager exists and the144* caller does not have the required145* {@linkplain CardPermission permission}146* @throws NullPointerException if command is null147* @throws CardException if the card operation failed148* @throws IllegalStateException if this card object has been disposed of149* via the {@linkplain #disconnect disconnect()} method150*/151public abstract byte[] transmitControlCommand(int controlCode,152byte[] command) throws CardException;153154/**155* Disconnects the connection with this card. After this method returns,156* calling methods on this object or in CardChannels associated with this157* object that require interaction with the card will raise an158* IllegalStateException.159*160* @param reset whether to reset the card after disconnecting.161*162* @throws CardException if the card operation failed163* @throws SecurityException if a SecurityManager exists and the164* caller does not have the required165* {@linkplain CardPermission permission}166*/167public abstract void disconnect(boolean reset) throws CardException;168169}170171172