Search in sources :

Example 11 with SCIOException

use of org.openecard.common.ifd.scio.SCIOException in project open-ecard by ecsec.

the class TerminalInfo method getStatus.

@Nonnull
public IFDStatusType getStatus() throws SCIOException {
    IFDStatusType status = new IFDStatusType();
    status.setIFDName(getName());
    status.setConnected(true);
    // set slot status type
    SlotStatusType stype = new SlotStatusType();
    status.getSlotStatus().add(stype);
    boolean cardPresent = isCardPresent();
    stype.setCardAvailable(cardPresent);
    stype.setIndex(BigInteger.ZERO);
    // get card status and stuff
    if (isConnected()) {
        SCIOATR atr = channel.getChannel().getCard().getATR();
        stype.setATRorATS(atr.getBytes());
    } else if (cardPresent) {
        // not connected, but card is present
        try {
            SingleThreadChannel ch = cm.openMasterChannel(getName());
            SCIOATR atr = ch.getChannel().getCard().getATR();
            stype.setATRorATS(atr.getBytes());
        } catch (NoSuchTerminal ex) {
            String msg = "Failed to connect card as terminal disappeared.";
            throw new SCIOException(msg, SCIOErrorCode.SCARD_E_UNKNOWN_READER, ex);
        }
    }
    // ifd status completely constructed
    return status;
}
Also used : NoSuchTerminal(org.openecard.common.ifd.scio.NoSuchTerminal) SCIOException(org.openecard.common.ifd.scio.SCIOException) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) SCIOATR(org.openecard.common.ifd.scio.SCIOATR) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType) Nonnull(javax.annotation.Nonnull)

Example 12 with SCIOException

use of org.openecard.common.ifd.scio.SCIOException in project open-ecard by ecsec.

the class PCSCTerminals method list.

public List<SCIOTerminal> list(State state, boolean firstTry) throws SCIOException {
    LOG.trace("Entering list().");
    try {
        CardTerminals.State scState = convertState(state);
        // get terminals with the specified state from the SmartcardIO
        List<CardTerminal> scList = terminals.list(scState);
        ArrayList<SCIOTerminal> list = convertTerminals(scList);
        LOG.trace("Leaving list().");
        return Collections.unmodifiableList(list);
    } catch (CardException ex) {
        SCIOErrorCode code = getCode(ex);
        if (code == SCIOErrorCode.SCARD_E_NO_READERS_AVAILABLE) {
            LOG.debug("No reader available exception.");
            return Collections.emptyList();
        } else if (code == SCIOErrorCode.SCARD_E_NO_SERVICE || code == SCIOErrorCode.SCARD_E_SERVICE_STOPPED) {
            if (firstTry) {
                LOG.debug("No service available exception, reloading PCSC and trying again.");
                reloadFactory();
                return list(state, false);
            } else {
                LOG.debug("No service available exception, returning empty list.");
                return Collections.emptyList();
            }
        }
        String msg = "Failed to retrieve list from terminals instance.";
        LOG.error(msg, ex);
        throw new SCIOException(msg, code, ex);
    }
}
Also used : SCIOException(org.openecard.common.ifd.scio.SCIOException) SCIOTerminal(org.openecard.common.ifd.scio.SCIOTerminal) SCIOErrorCode(org.openecard.common.ifd.scio.SCIOErrorCode) CardTerminals(javax.smartcardio.CardTerminals) CardTerminal(javax.smartcardio.CardTerminal) CardException(javax.smartcardio.CardException)

Example 13 with SCIOException

use of org.openecard.common.ifd.scio.SCIOException in project open-ecard by ecsec.

the class NFCCardTerminal method connect.

@Override
public synchronized SCIOCard connect(SCIOProtocol protocol) throws SCIOException, IllegalStateException {
    if (nfcCard == null || nfcCard.isodep == null) {
        String msg = "No tag present.";
        LOG.warn(msg);
        throw new SCIOException(msg, SCIOErrorCode.SCARD_E_NO_SMARTCARD);
    }
    try {
        if (!nfcCard.isodep.isConnected()) {
            nfcCard.isodep.connect();
            // start thread which is monitoring the availability of the card
            Thread nfcAvailableTask = new Thread(new NFCCardMonitoring((this)));
            nfcAvailableTask.start();
        }
    } catch (IOException e) {
        nfcCard = null;
        String msg = "No connection can be established.";
        LOG.warn(msg, e);
        // TODO: check if error code is correct
        throw new SCIOException(msg, SCIOErrorCode.SCARD_E_NO_SMARTCARD, e);
    }
    return nfcCard;
}
Also used : SCIOException(org.openecard.common.ifd.scio.SCIOException) IOException(java.io.IOException) SCIOException(org.openecard.common.ifd.scio.SCIOException)

Example 14 with SCIOException

use of org.openecard.common.ifd.scio.SCIOException in project open-ecard by ecsec.

the class NFCFactory method setNFCTag.

/**
 * Set the nfc tag in the nfc card terminal.
 *
 * @param tag
 * @param timeout current timeout for transceive(byte[]) in milliseconds.
 */
public static void setNFCTag(Tag tag, int timeout) {
    IsoDep isoDepTag = IsoDep.get(tag);
    isoDepTag.setTimeout(timeout);
    try {
        // standard nfc terminal
        terminals.getIntegratedNfcTerminal().setTag(isoDepTag, timeout);
    } catch (SCIOException ex) {
        LOG.warn(ex.getMessage(), ex);
    }
}
Also used : IsoDep(android.nfc.tech.IsoDep) SCIOException(org.openecard.common.ifd.scio.SCIOException)

Example 15 with SCIOException

use of org.openecard.common.ifd.scio.SCIOException in project open-ecard by ecsec.

the class PCSCChannel method transmit.

@Override
public CardResponseAPDU transmit(byte[] command) throws SCIOException {
    try {
        CommandAPDU convertCommand = new CommandAPDU(command);
        ResponseAPDU response = channel.transmit(convertCommand);
        return new CardResponseAPDU(response.getBytes());
    } catch (CardException ex) {
        String msg = "Failed to transmit APDU to the card in terminal '%s'.";
        throw new SCIOException(String.format(msg, card.getTerminal().getName()), getCode(ex), ex);
    }
}
Also used : SCIOException(org.openecard.common.ifd.scio.SCIOException) ResponseAPDU(javax.smartcardio.ResponseAPDU) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU) CardException(javax.smartcardio.CardException) CardCommandAPDU(org.openecard.common.apdu.common.CardCommandAPDU) CommandAPDU(javax.smartcardio.CommandAPDU) CardResponseAPDU(org.openecard.common.apdu.common.CardResponseAPDU)

Aggregations

SCIOException (org.openecard.common.ifd.scio.SCIOException)19 Result (oasis.names.tc.dss._1_0.core.schema.Result)10 SingleThreadChannel (org.openecard.ifd.scio.wrapper.SingleThreadChannel)10 NoSuchTerminal (org.openecard.common.ifd.scio.NoSuchTerminal)7 ExecutionException (java.util.concurrent.ExecutionException)6 IFDStatusType (iso.std.iso_iec._24727.tech.schema.IFDStatusType)5 ThreadTerminateException (org.openecard.common.ThreadTerminateException)5 NoSuchChannel (org.openecard.ifd.scio.wrapper.NoSuchChannel)5 SlotStatusType (iso.std.iso_iec._24727.tech.schema.SlotStatusType)4 SCIOTerminal (org.openecard.common.ifd.scio.SCIOTerminal)4 BigInteger (java.math.BigInteger)3 ArrayList (java.util.ArrayList)3 LinkedList (java.util.LinkedList)3 BeginTransactionResponse (iso.std.iso_iec._24727.tech.schema.BeginTransactionResponse)2 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)2 IFDCapabilitiesType (iso.std.iso_iec._24727.tech.schema.IFDCapabilitiesType)2 CardException (javax.smartcardio.CardException)2 SCIOErrorCode (org.openecard.common.ifd.scio.SCIOErrorCode)2 TerminalInfo (org.openecard.ifd.scio.wrapper.TerminalInfo)2 IsoDep (android.nfc.tech.IsoDep)1