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;
}
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;
}
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;
}
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;
}
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;
}
}
}
}
Aggregations