Search in sources :

Example 1 with IFDStatusType

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

the class IfdEventManager method wait.

@Nonnull
protected List<IFDStatusType> wait(@Nonnull List<IFDStatusType> lastKnown) throws WSException {
    Wait wait = new Wait();
    wait.setContextHandle(ctx);
    wait.getIFDStatus().addAll(lastKnown);
    WaitResponse resp = env.getIFD().wait(wait);
    WSHelper.checkResult(resp);
    List<IFDStatusType> result = resp.getIFDEvent();
    return result;
}
Also used : IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) Wait(iso.std.iso_iec._24727.tech.schema.Wait) WaitResponse(iso.std.iso_iec._24727.tech.schema.WaitResponse) Nonnull(javax.annotation.Nonnull)

Example 2 with IFDStatusType

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

the class IfdEventRunner method ifdStatus.

@Nonnull
private List<IFDStatusType> ifdStatus() throws WSException {
    LOG.debug("Requesting terminal names.");
    ListIFDs listReq = new ListIFDs();
    listReq.setContextHandle(ctxHandle);
    ListIFDsResponse ifds = env.getIFD().listIFDs(listReq);
    WSHelper.checkResult(ifds);
    LOG.debug("Requesting status for all terminals found.");
    ArrayList<IFDStatusType> result = new ArrayList<>();
    for (String ifd : ifds.getIFDName()) {
        GetStatus status = new GetStatus();
        status.setContextHandle(ctxHandle);
        status.setIFDName(ifd);
        GetStatusResponse statusResponse = env.getIFD().getStatus(status);
        try {
            WSHelper.checkResult(statusResponse);
            result.addAll(statusResponse.getIFDStatus());
        } catch (WSException ex) {
            String msg = "Failed to request status from terminal, assuming no card present.";
            LOG.error(msg, ex);
            IFDStatusType is = new IFDStatusType();
            is.setIFDName(ifd);
            result.add(is);
        }
    }
    return result;
}
Also used : ListIFDs(iso.std.iso_iec._24727.tech.schema.ListIFDs) ListIFDsResponse(iso.std.iso_iec._24727.tech.schema.ListIFDsResponse) GetStatusResponse(iso.std.iso_iec._24727.tech.schema.GetStatusResponse) ArrayList(java.util.ArrayList) WSException(org.openecard.common.WSHelper.WSException) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) GetStatus(iso.std.iso_iec._24727.tech.schema.GetStatus) Nonnull(javax.annotation.Nonnull)

Example 3 with IFDStatusType

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

the class IfdEventRunner method fireEvents.

private void fireEvents(@Nonnull List<IFDStatusType> diff) {
    for (IFDStatusType term : diff) {
        String ifdName = term.getIFDName();
        // find out if the terminal is new, or only a slot got updated
        IFDStatusType oldTerm = getCorresponding(ifdName, currentState);
        boolean terminalAdded = oldTerm == null;
        IFDCapabilitiesType slotCapabilities = getCapabilities(ifdName);
        if (terminalAdded) {
            // TERMINAL ADDED
            // make copy of term
            oldTerm = new IFDStatusType();
            oldTerm.setIFDName(ifdName);
            oldTerm.setConnected(true);
            // add to current list
            currentState.add(oldTerm);
            // create event
            ConnectionHandleType h = makeConnectionHandle(ifdName, null, slotCapabilities);
            LOG.debug("Found a terminal added event ({}).", ifdName);
            env.getEventDispatcher().notify(EventType.TERMINAL_ADDED, new IfdEventObject(h));
        }
        // check each slot
        for (SlotStatusType slot : term.getSlotStatus()) {
            SlotStatusType oldSlot = getCorresponding(slot.getIndex(), oldTerm.getSlotStatus());
            boolean cardPresent = slot.isCardAvailable();
            boolean cardWasPresent = oldSlot != null && oldSlot.isCardAvailable();
            if (cardPresent && !cardWasPresent) {
                // CARD INSERTED
                // copy slot and add to list
                SlotStatusType newSlot = oldSlot;
                if (newSlot == null) {
                    newSlot = new SlotStatusType();
                    oldTerm.getSlotStatus().add(newSlot);
                }
                newSlot.setIndex(slot.getIndex());
                newSlot.setCardAvailable(true);
                newSlot.setATRorATS(slot.getATRorATS());
                // create event
                LOG.debug("Found a card insert event ({}).", ifdName);
                LOG.info("Card with ATR={} inserted.", ByteUtils.toHexString(slot.getATRorATS()));
                ConnectionHandleType handle = makeUnknownCardHandle(ifdName, newSlot, slotCapabilities);
                env.getEventDispatcher().notify(EventType.CARD_INSERTED, new IfdEventObject(handle));
                try {
                    SingleThreadChannel ch = cm.openMasterChannel(ifdName);
                    if (evtManager.isRecognize()) {
                        String proto = ch.getChannel().getCard().getProtocol().toUri();
                        evtManager.threadPool.submit(new Recognizer(env, handle, proto));
                    }
                } catch (NoSuchTerminal | SCIOException ex) {
                    LOG.error("Failed to connect card, nevertheless sending CARD_INSERTED event.", ex);
                }
            } else if (!terminalAdded && !cardPresent && cardWasPresent) {
                // this makes only sense when the terminal was already there
                // CARD REMOVED
                // remove slot entry
                BigInteger idx = oldSlot.getIndex();
                Iterator<SlotStatusType> it = oldTerm.getSlotStatus().iterator();
                while (it.hasNext()) {
                    SlotStatusType next = it.next();
                    if (idx.equals(next.getIndex())) {
                        it.remove();
                        break;
                    }
                }
                LOG.debug("Found a card removed event ({}).", ifdName);
                ConnectionHandleType h = makeConnectionHandle(ifdName, idx, slotCapabilities);
                env.getEventDispatcher().notify(EventType.CARD_REMOVED, new IfdEventObject(h));
            }
        }
        // terminal removed event comes after card removed events
        boolean terminalPresent = term.isConnected();
        if (!terminalPresent) {
            // TERMINAL REMOVED
            Iterator<IFDStatusType> it = currentState.iterator();
            while (it.hasNext()) {
                IFDStatusType toDel = it.next();
                if (toDel.getIFDName().equals(term.getIFDName())) {
                    it.remove();
                }
            }
            ConnectionHandleType h = makeConnectionHandle(ifdName, null, slotCapabilities);
            LOG.debug("Found a terminal removed event ({}).", ifdName);
            env.getEventDispatcher().notify(EventType.TERMINAL_REMOVED, new IfdEventObject(h));
        }
    }
}
Also used : ConnectionHandleType(iso.std.iso_iec._24727.tech.schema.ConnectionHandleType) NoSuchTerminal(org.openecard.common.ifd.scio.NoSuchTerminal) SingleThreadChannel(org.openecard.ifd.scio.wrapper.SingleThreadChannel) SCIOException(org.openecard.common.ifd.scio.SCIOException) IFDCapabilitiesType(iso.std.iso_iec._24727.tech.schema.IFDCapabilitiesType) Iterator(java.util.Iterator) BigInteger(java.math.BigInteger) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType) IfdEventObject(org.openecard.common.event.IfdEventObject)

Example 4 with IFDStatusType

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

the class EventWatcher method convert.

@Nonnull
private IFDStatusType convert(@Nonnull TerminalState next) {
    IFDStatusType result = new IFDStatusType();
    result.setIFDName(next.getName());
    result.setConnected(true);
    SlotStatusType slot = new SlotStatusType();
    result.getSlotStatus().add(slot);
    slot.setIndex(BigInteger.ZERO);
    slot.setCardAvailable(next.isCardPresent());
    return result;
}
Also used : IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType) Nonnull(javax.annotation.Nonnull)

Example 5 with IFDStatusType

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

the class EventWatcher method clone.

@Nonnull
private static IFDStatusType clone(@Nonnull IFDStatusType orig) {
    IFDStatusType newStat = new IFDStatusType();
    newStat.setIFDName(orig.getIFDName());
    newStat.setConnected(orig.isConnected());
    for (SlotStatusType next : orig.getSlotStatus()) {
        newStat.getSlotStatus().add(clone(next));
    }
    return newStat;
}
Also used : IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType) SlotStatusType(iso.std.iso_iec._24727.tech.schema.SlotStatusType) Nonnull(javax.annotation.Nonnull)

Aggregations

IFDStatusType (iso.std.iso_iec._24727.tech.schema.IFDStatusType)16 SlotStatusType (iso.std.iso_iec._24727.tech.schema.SlotStatusType)9 ArrayList (java.util.ArrayList)7 Nonnull (javax.annotation.Nonnull)6 SCIOException (org.openecard.common.ifd.scio.SCIOException)5 GetStatusResponse (iso.std.iso_iec._24727.tech.schema.GetStatusResponse)4 NoSuchTerminal (org.openecard.common.ifd.scio.NoSuchTerminal)4 GetStatus (iso.std.iso_iec._24727.tech.schema.GetStatus)3 BigInteger (java.math.BigInteger)3 LinkedList (java.util.LinkedList)3 Result (oasis.names.tc.dss._1_0.core.schema.Result)3 SingleThreadChannel (org.openecard.ifd.scio.wrapper.SingleThreadChannel)3 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)2 WaitResponse (iso.std.iso_iec._24727.tech.schema.WaitResponse)2 List (java.util.List)2 CancelResponse (iso.std.iso_iec._24727.tech.schema.CancelResponse)1 ChannelHandleType (iso.std.iso_iec._24727.tech.schema.ChannelHandleType)1 RecognitionInfo (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo)1 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)1 EstablishContextResponse (iso.std.iso_iec._24727.tech.schema.EstablishContextResponse)1