Search in sources :

Example 6 with SCIOTerminal

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

the class IFD method getStatus.

@Override
public GetStatusResponse getStatus(GetStatus parameters) {
    GetStatusResponse response;
    // you thought of a different IFD obviously
    if (!ByteUtils.compare(ctxHandle, parameters.getContextHandle())) {
        String msg = "Invalid context handle specified.";
        Result r = WSHelper.makeResultError(ECardConstants.Minor.IFD.INVALID_CONTEXT_HANDLE, msg);
        response = WSHelper.makeResponse(GetStatusResponse.class, r);
        return response;
    }
    // get specific ifd or all if no specific one is requested
    List<SCIOTerminal> ifds = new LinkedList<>();
    try {
        String requestedIfd = parameters.getIFDName();
        if (requestedIfd != null) {
            try {
                SCIOTerminal t = cm.getTerminals().getTerminal(requestedIfd);
                ifds.add(t);
            } catch (NoSuchTerminal ex) {
                String msg = "The requested IFD name does not exist.";
                LOG.warn(msg, ex);
                String minor = ECardConstants.Minor.IFD.Terminal.UNKNOWN_IFD;
                Result r = WSHelper.makeResult(ECardConstants.Major.ERROR, minor, msg);
                response = WSHelper.makeResponse(GetStatusResponse.class, r);
                return response;
            }
        } else {
            ifds.addAll(cm.getTerminals().list());
        }
    } catch (SCIOException ex) {
        String msg = "Failed to get list with the terminals.";
        LOG.warn(msg, ex);
        response = WSHelper.makeResponse(GetStatusResponse.class, WSHelper.makeResultUnknownError(msg));
        return response;
    }
    // request status for each ifd
    ArrayList<IFDStatusType> status = new ArrayList<>(ifds.size());
    for (SCIOTerminal ifd : ifds) {
        TerminalInfo info;
        try {
            SingleThreadChannel channel = cm.openMasterChannel(ifd.getName());
            info = new TerminalInfo(cm, channel);
        } catch (NoSuchTerminal | SCIOException ex) {
            // continue without a channel
            info = new TerminalInfo(cm, ifd);
        }
        try {
            IFDStatusType s = info.getStatus();
            status.add(s);
        } catch (SCIOException ex) {
            if (ex.getCode() != SCIOErrorCode.SCARD_W_UNPOWERED_CARD && ex.getCode() != SCIOErrorCode.SCARD_W_UNRESPONSIVE_CARD && ex.getCode() != SCIOErrorCode.SCARD_W_UNSUPPORTED_CARD && ex.getCode() != SCIOErrorCode.SCARD_E_PROTO_MISMATCH) {
                String msg = String.format("Failed to determine status of terminal '%s'.", ifd.getName());
                LOG.warn(msg, ex);
                Result r = WSHelper.makeResultUnknownError(msg);
                response = WSHelper.makeResponse(GetStatusResponse.class, r);
                return response;
            } else {
                // fall througth if there is a card which can not be connected
                LOG.info("Ignoring failed status request from terminal.", ex);
            }
        }
    }
    // everything worked out well
    response = WSHelper.makeResponse(GetStatusResponse.class, WSHelper.makeResultOK());
    response.getIFDStatus().addAll(status);
    return response;
}
Also used : NoSuchTerminal(org.openecard.common.ifd.scio.NoSuchTerminal) GetStatusResponse(iso.std.iso_iec._24727.tech.schema.GetStatusResponse) SCIOException(org.openecard.common.ifd.scio.SCIOException) SingleThreadChannel(org.openecard.ifd.scio.wrapper.SingleThreadChannel) SCIOTerminal(org.openecard.common.ifd.scio.SCIOTerminal) ArrayList(java.util.ArrayList) TerminalInfo(org.openecard.ifd.scio.wrapper.TerminalInfo) LinkedList(java.util.LinkedList) Result(oasis.names.tc.dss._1_0.core.schema.Result) IFDStatusType(iso.std.iso_iec._24727.tech.schema.IFDStatusType)

Aggregations

SCIOTerminal (org.openecard.common.ifd.scio.SCIOTerminal)6 SCIOException (org.openecard.common.ifd.scio.SCIOException)4 Result (oasis.names.tc.dss._1_0.core.schema.Result)3 ArrayList (java.util.ArrayList)2 NoSuchTerminal (org.openecard.common.ifd.scio.NoSuchTerminal)2 SCIOErrorCode (org.openecard.common.ifd.scio.SCIOErrorCode)2 SingleThreadChannel (org.openecard.ifd.scio.wrapper.SingleThreadChannel)2 TerminalInfo (org.openecard.ifd.scio.wrapper.TerminalInfo)2 BioSensorCapabilityType (iso.std.iso_iec._24727.tech.schema.BioSensorCapabilityType)1 DisplayCapabilityType (iso.std.iso_iec._24727.tech.schema.DisplayCapabilityType)1 GetIFDCapabilitiesResponse (iso.std.iso_iec._24727.tech.schema.GetIFDCapabilitiesResponse)1 GetStatusResponse (iso.std.iso_iec._24727.tech.schema.GetStatusResponse)1 IFDCapabilitiesType (iso.std.iso_iec._24727.tech.schema.IFDCapabilitiesType)1 IFDStatusType (iso.std.iso_iec._24727.tech.schema.IFDStatusType)1 KeyPadCapabilityType (iso.std.iso_iec._24727.tech.schema.KeyPadCapabilityType)1 ListIFDsResponse (iso.std.iso_iec._24727.tech.schema.ListIFDsResponse)1 SlotCapabilityType (iso.std.iso_iec._24727.tech.schema.SlotCapabilityType)1 LinkedList (java.util.LinkedList)1 CardException (javax.smartcardio.CardException)1 CardTerminal (javax.smartcardio.CardTerminal)1