Search in sources :

Example 6 with SlotStatusType

use of iso.std.iso_iec._24727.tech.schema.SlotStatusType 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 7 with SlotStatusType

use of iso.std.iso_iec._24727.tech.schema.SlotStatusType in project open-ecard by ecsec.

the class AndroidMarshaller method parseSlotStatusType.

private SlotStatusType parseSlotStatusType(XmlPullParser parser) throws XmlPullParserException, IOException {
    SlotStatusType slotStatusType = new SlotStatusType();
    int eventType;
    do {
        parser.next();
        eventType = parser.getEventType();
        if (eventType == XmlPullParser.START_TAG) {
            if (parser.getName().equals("Index")) {
                slotStatusType.setIndex(new BigInteger(parser.nextText()));
            } else if (parser.getName().equals("CardAvailable")) {
                slotStatusType.setCardAvailable(Boolean.valueOf(parser.nextText()));
            } else if (parser.getName().equals("ATRorATS")) {
                slotStatusType.setATRorATS(StringUtils.toByteArray(parser.nextText()));
            }
        }
    } while (!(eventType == XmlPullParser.END_TAG && parser.getName().equals("SlotStatus")));
    return slotStatusType;
}
Also used : BigInteger(java.math.BigInteger) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType)

Example 8 with SlotStatusType

use of iso.std.iso_iec._24727.tech.schema.SlotStatusType in project open-ecard by ecsec.

the class ListTokens method getUnknownCards.

private List<TokenInfoType> getUnknownCards(List<ConnectionHandleType> knownHandles) {
    ArrayList<TokenInfoType> result = new ArrayList<>();
    List<byte[]> ifdCtxs = ctx.getIfdCtx();
    for (byte[] ifdCtx : ifdCtxs) {
        try {
            // get all IFD names
            GetStatus gs = new GetStatus();
            gs.setContextHandle(ifdCtx);
            GetStatusResponse gsr = (GetStatusResponse) dispatcher.safeDeliver(gs);
            WSHelper.checkResult(gsr);
            for (IFDStatusType istatus : gsr.getIFDStatus()) {
                for (SlotStatusType sstatus : istatus.getSlotStatus()) // check if name is already in the list of known cards
                if (sstatus.isCardAvailable() && !isInHandleList(istatus.getIFDName(), knownHandles)) {
                    TokenInfoType ti = new TokenInfoType();
                    org.openecard.ws.chipgateway.ConnectionHandleType conHandle;
                    conHandle = new org.openecard.ws.chipgateway.ConnectionHandleType();
                    conHandle.setCardType(ECardConstants.UNKNOWN_CARD);
                    ti.setConnectionHandle(conHandle);
                    // add to handle list
                    result.add(ti);
                }
            }
        } catch (WSHelper.WSException ex) {
            LOG.warn("Failed to retrieve status info from IFD. Skipping unknown card entries.");
        }
    }
    return result;
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) WSHelper(org.openecard.common.WSHelper) GetStatusResponse(iso.std.iso_iec._24727.tech.schema.GetStatusResponse) ArrayList(java.util.ArrayList) TokenInfoType(org.openecard.ws.chipgateway.TokenInfoType) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType) GetStatus(iso.std.iso_iec._24727.tech.schema.GetStatus)

Example 9 with SlotStatusType

use of iso.std.iso_iec._24727.tech.schema.SlotStatusType in project open-ecard by ecsec.

the class EventWatcher method clone.

@Nonnull
private static SlotStatusType clone(@Nonnull SlotStatusType orig) {
    SlotStatusType slot = new SlotStatusType();
    slot.setCardAvailable(orig.isCardAvailable());
    slot.setIndex(orig.getIndex());
    byte[] atr = orig.getATRorATS();
    if (atr != null) {
        slot.setATRorATS(atr.clone());
    }
    return slot;
}
Also used : SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType) Nonnull(javax.annotation.Nonnull)

Example 10 with SlotStatusType

use of iso.std.iso_iec._24727.tech.schema.SlotStatusType in project open-ecard by ecsec.

the class EventWatcher method updateState.

private void updateState(TerminalWatcher.StateChangeEvent event) {
    String name = event.getTerminal();
    if (event.getState() == TerminalWatcher.EventType.TERMINAL_ADDED) {
        currentState.add(createEmptyState(name));
    } else {
        Iterator<IFDStatusType> it = currentState.iterator();
        while (it.hasNext()) {
            IFDStatusType next = it.next();
            SlotStatusType slot = next.getSlotStatus().get(0);
            if (next.getIFDName().equals(name)) {
                switch(event.getState()) {
                    case CARD_INSERTED:
                        try {
                            SingleThreadChannel ch = cm.openMasterChannel(name);
                            slot.setCardAvailable(true);
                            slot.setATRorATS(ch.getChannel().getCard().getATR().getBytes());
                        } catch (NoSuchTerminal | SCIOException ex) {
                            LOG.error("Failed to open master channel for terminal '" + name + "'.", ex);
                            slot.setCardAvailable(false);
                            cm.closeMasterChannel(name);
                        }
                        break;
                    case CARD_REMOVED:
                        cm.closeMasterChannel(name);
                        slot.setCardAvailable(false);
                        break;
                    case TERMINAL_REMOVED:
                        // just in case
                        slot.setCardAvailable(false);
                        next.setConnected(false);
                        break;
                }
                // no need to look any further
                break;
            }
        }
    }
}
Also used : NoSuchTerminal(org.openecard.common.ifd.scio.NoSuchTerminal) SingleThreadChannel(org.openecard.ifd.scio.wrapper.SingleThreadChannel) SCIOException(org.openecard.common.ifd.scio.SCIOException) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType)

Aggregations

SlotStatusType (iso.std.iso_iec._24727.tech.schema.SlotStatusType)12 IFDStatusType (iso.std.iso_iec._24727.tech.schema.IFDStatusType)9 BigInteger (java.math.BigInteger)4 Nonnull (javax.annotation.Nonnull)4 SCIOException (org.openecard.common.ifd.scio.SCIOException)4 ArrayList (java.util.ArrayList)3 NoSuchTerminal (org.openecard.common.ifd.scio.NoSuchTerminal)3 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)2 SingleThreadChannel (org.openecard.ifd.scio.wrapper.SingleThreadChannel)2 ChannelHandleType (iso.std.iso_iec._24727.tech.schema.ChannelHandleType)1 GetStatus (iso.std.iso_iec._24727.tech.schema.GetStatus)1 GetStatusResponse (iso.std.iso_iec._24727.tech.schema.GetStatusResponse)1 IFDCapabilitiesType (iso.std.iso_iec._24727.tech.schema.IFDCapabilitiesType)1 WaitResponse (iso.std.iso_iec._24727.tech.schema.WaitResponse)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ExecutionException (java.util.concurrent.ExecutionException)1 FutureTask (java.util.concurrent.FutureTask)1 Result (oasis.names.tc.dss._1_0.core.schema.Result)1