jdk/src/java.smartcardio/share/classes/javax/smartcardio/Card.java
author darcy
Thu, 16 Apr 2015 10:44:23 -0700
changeset 29928 6ad7fd5f4746
parent 25859 3317bb8137f4
permissions -rw-r--r--
8077915: Fix doclint issues in javax.smartcardio Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29928
6ad7fd5f4746 8077915: Fix doclint issues in javax.smartcardio
darcy
parents: 25859
diff changeset
     2
 * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.smartcardio;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * A Smart Card with which a connection has been established. Card objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * are obtained by calling {@link CardTerminal#connect CardTerminal.connect()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * @see CardTerminal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @since   1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author  Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author  JSR 268 Expert Group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public abstract class Card {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * Constructs a new Card object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * <p>This constructor is called by subclasses only. Application should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * call the {@linkplain CardTerminal#connect CardTerminal.connect()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * method to obtain a Card
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    protected Card() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        // empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Returns the ATR of this card.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * @return the ATR of this card.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public abstract ATR getATR();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Returns the protocol in use for this card.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * @return the protocol in use for this card, for example "T=0" or "T=1"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    public abstract String getProtocol();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Returns the CardChannel for the basic logical channel. The basic
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * logical channel has a channel number of 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *
29928
6ad7fd5f4746 8077915: Fix doclint issues in javax.smartcardio
darcy
parents: 25859
diff changeset
    72
     * @return the CardChannel for the basic logical channel
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @throws SecurityException if a SecurityManager exists and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *   caller does not have the required
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *   {@linkplain CardPermission permission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @throws IllegalStateException if this card object has been disposed of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *   via the {@linkplain #disconnect disconnect()} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public abstract CardChannel getBasicChannel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Opens a new logical channel to the card and returns it. The channel is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * opened by issuing a <code>MANAGE CHANNEL</code> command that should use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * the format <code>[00 70 00 00 01]</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *
29928
6ad7fd5f4746 8077915: Fix doclint issues in javax.smartcardio
darcy
parents: 25859
diff changeset
    86
     * @return the logical channel which has been opened
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @throws SecurityException if a SecurityManager exists and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *   caller does not have the required
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *   {@linkplain CardPermission permission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @throws CardException is a new logical channel could not be opened
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @throws IllegalStateException if this card object has been disposed of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *   via the {@linkplain #disconnect disconnect()} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public abstract CardChannel openLogicalChannel() throws CardException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * Requests exclusive access to this card.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * <p>Once a thread has invoked <code>beginExclusive</code>, only this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * thread is allowed to communicate with this card until it calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * <code>endExclusive</code>. Other threads attempting communication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * will receive a CardException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * <p>Applications have to ensure that exclusive access is correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * released. This can be achieved by executing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * the <code>beginExclusive()</code> and <code>endExclusive</code> calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * in a <code>try ... finally</code> block.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @throws SecurityException if a SecurityManager exists and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *   caller does not have the required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *   {@linkplain CardPermission permission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @throws CardException if exclusive access has already been set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *   or if exclusive access could not be established
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @throws IllegalStateException if this card object has been disposed of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *   via the {@linkplain #disconnect disconnect()} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public abstract void beginExclusive() throws CardException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Releases the exclusive access previously established using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * <code>beginExclusive</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @throws SecurityException if a SecurityManager exists and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *   caller does not have the required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *   {@linkplain CardPermission permission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @throws IllegalStateException if the active Thread does not currently have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *   exclusive access to this card or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *   if this card object has been disposed of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *   via the {@linkplain #disconnect disconnect()} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @throws CardException if the operation failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    public abstract void endExclusive() throws CardException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * Transmits a control command to the terminal device.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * <p>This can be used to, for example, control terminal functions like
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * a built-in PIN pad or biometrics.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param controlCode the control code of the command
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param command the command data
29928
6ad7fd5f4746 8077915: Fix doclint issues in javax.smartcardio
darcy
parents: 25859
diff changeset
   142
     * @return the response from the terminal device
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @throws SecurityException if a SecurityManager exists and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *   caller does not have the required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *   {@linkplain CardPermission permission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @throws NullPointerException if command is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @throws CardException if the card operation failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @throws IllegalStateException if this card object has been disposed of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *   via the {@linkplain #disconnect disconnect()} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public abstract byte[] transmitControlCommand(int controlCode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            byte[] command) throws CardException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * Disconnects the connection with this card. After this method returns,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * calling methods on this object or in CardChannels associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * object that require interaction with the card will raise an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * IllegalStateException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @param reset whether to reset the card after disconnecting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @throws CardException if the card operation failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @throws SecurityException if a SecurityManager exists and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *   caller does not have the required
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *   {@linkplain CardPermission permission}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public abstract void disconnect(boolean reset) throws CardException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
}