Search in sources :

Example 1 with SCIOATR

use of org.openecard.common.ifd.scio.SCIOATR 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 2 with SCIOATR

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

the class NFCCard method getATR.

@Override
public SCIOATR getATR() {
    // build ATR according to PCSCv2-3, Sec. 3.1.3.2.3.1
    if (histBytes == null) {
        return new SCIOATR(new byte[0]);
    } else {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        // Initial Header
        out.write(0x3B);
        // T0
        out.write(0x80 | (histBytes.length & 0xF));
        // TD1
        out.write(0x80);
        // TD2
        out.write(0x01);
        // ISO14443A: The historical bytes from ATS response.
        // ISO14443B: 1-4=Application Data from ATQB, 5-7=Protocol Info Byte from ATQB, 8=Higher nibble = MBLI from ATTRIB command Lower nibble (RFU) = 0
        // TODO: check that the HiLayerResponse matches the requirements for ISO14443B
        out.write(histBytes, 0, histBytes.length);
        // TCK: Exclusive-OR of bytes T0 to Tk
        byte[] preATR = out.toByteArray();
        byte chkSum = 0;
        for (int i = 1; i < preATR.length; i++) {
            chkSum ^= preATR[i];
        }
        out.write(chkSum);
        byte[] atr = out.toByteArray();
        return new SCIOATR(atr);
    }
}
Also used : SCIOATR(org.openecard.common.ifd.scio.SCIOATR) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

SCIOATR (org.openecard.common.ifd.scio.SCIOATR)2 IFDStatusType (iso.std.iso_iec._24727.tech.schema.IFDStatusType)1 SlotStatusType (iso.std.iso_iec._24727.tech.schema.SlotStatusType)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Nonnull (javax.annotation.Nonnull)1 NoSuchTerminal (org.openecard.common.ifd.scio.NoSuchTerminal)1 SCIOException (org.openecard.common.ifd.scio.SCIOException)1