001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.io.j2me.apdu;
028:
029: /**
030: * This class represents a handle for APDU connection.
031: */
032: public class Handle {
033:
034: /** Slot number. */
035: int slot;
036: /** Logical channel number. */
037: public int channel;
038: /** Slot object. */
039: Slot cardSlot;
040: /** Is this connection opened? */
041: boolean opened;
042: /** FCI received from selected application. */
043: byte[] FCI;
044:
045: /**
046: * Unique identifier of card session (period of time between card
047: * power up and powerdown) during which the connection was created.
048: */
049: public int cardSessionId;
050:
051: /**
052: * Unique identifier of Handle instance.
053: * It is used for debugging purposes.
054: */
055: int handleInstance;
056:
057: /**
058: * Counter for handleInstance generation.
059: * It is used for debugging purposes.
060: */
061: private static int instanceNo = 1;
062:
063: /**
064: * Creates a new handle with specified parameters.
065: * @param slot slot number
066: * @param channel channel number
067: */
068: Handle(int slot, int channel) {
069:
070: this .slot = slot;
071: this .channel = channel;
072: this .cardSlot = APDUManager.slots[slot];
073: this .FCI = cardSlot.FCI;
074: this .opened = true;
075: this .cardSessionId = cardSlot.cardSessionId;
076: this .handleInstance = instanceNo++;
077: }
078:
079: /**
080: * Returns ATR of the card.
081: * @return ATR.
082: */
083: public byte[] getATR() {
084: return APDUManager.getATR(slot);
085: }
086:
087: /**
088: * Returns FCI of the selected application.
089: * @return FCI.
090: */
091: public byte[] getFCI() {
092: if (FCI != null && opened && cardSlot.powered
093: && cardSessionId == cardSlot.cardSessionId) {
094: int len = FCI.length;
095: byte[] result = new byte[len];
096: System.arraycopy(FCI, 0, result, 0, len);
097: return result;
098: }
099: return null;
100: }
101:
102: /**
103: * Returns current cardSessionId of the slot.
104: * @return cardSessionId.
105: */
106: public int getCardSessionId() {
107: return cardSlot.cardSessionId;
108: }
109:
110: }
|